diff options
Diffstat (limited to 'jerry-core/parser')
30 files changed, 2144 insertions, 2848 deletions
diff --git a/jerry-core/parser/js/byte-code.c b/jerry-core/parser/js/byte-code.c index 682d950c..9aee6903 100644 --- a/jerry-core/parser/js/byte-code.c +++ b/jerry-core/parser/js/byte-code.c @@ -16,11 +16,9 @@ #include "js-parser-internal.h" /* These two checks only checks the compiler, they have no effect on the code. */ -JERRY_STATIC_ASSERT (sizeof (cbc_uint8_arguments_t) == 16, - sizeof_cbc_uint8_arguments_t_must_be_16_byte_long); +JERRY_STATIC_ASSERT (sizeof (cbc_uint8_arguments_t) == 16, sizeof_cbc_uint8_arguments_t_must_be_16_byte_long); -JERRY_STATIC_ASSERT (sizeof (cbc_uint16_arguments_t) == 24, - sizeof_cbc_uint16_arguments_t_must_be_24_byte_long); +JERRY_STATIC_ASSERT (sizeof (cbc_uint16_arguments_t) == 24, sizeof_cbc_uint16_arguments_t_must_be_24_byte_long); JERRY_STATIC_ASSERT (offsetof (cbc_uint8_arguments_t, script_value) == offsetof (cbc_uint16_arguments_t, script_value), script_value_in_cbc_uint8_arguments_and_cbc_uint16_arguments_must_be_in_the_same_offset); @@ -29,10 +27,8 @@ JERRY_STATIC_ASSERT (offsetof (cbc_uint8_arguments_t, script_value) == offsetof * The reason of these two static asserts to notify the developer to increase the JERRY_SNAPSHOT_VERSION * whenever new bytecodes are introduced or existing ones have been deleted. */ -JERRY_STATIC_ASSERT (CBC_END == 238, - number_of_cbc_opcodes_changed); -JERRY_STATIC_ASSERT (CBC_EXT_END == 148, - number_of_cbc_ext_opcodes_changed); +JERRY_STATIC_ASSERT (CBC_END == 238, number_of_cbc_opcodes_changed); +JERRY_STATIC_ASSERT (CBC_EXT_END == 148, number_of_cbc_ext_opcodes_changed); #if JERRY_PARSER || JERRY_PARSER_DUMP_BYTE_CODE @@ -49,24 +45,17 @@ JERRY_STATIC_ASSERT (CBC_EXT_END == 148, /** * Compact bytecode definition */ -#define CBC_OPCODE(arg1, arg2, arg3, arg4) \ - ((arg2) | (((arg3) + CBC_STACK_ADJUST_BASE) << CBC_STACK_ADJUST_SHIFT)), +#define CBC_OPCODE(arg1, arg2, arg3, arg4) ((arg2) | (((arg3) + CBC_STACK_ADJUST_BASE) << CBC_STACK_ADJUST_SHIFT)), /** * Flags of the opcodes. */ -const uint8_t cbc_flags[] JERRY_ATTR_CONST_DATA = -{ - CBC_OPCODE_LIST -}; +const uint8_t cbc_flags[] JERRY_ATTR_CONST_DATA = { CBC_OPCODE_LIST }; /** * Flags of the extended opcodes. */ -const uint8_t cbc_ext_flags[] = -{ - CBC_EXT_OPCODE_LIST -}; +const uint8_t cbc_ext_flags[] = { CBC_EXT_OPCODE_LIST }; #undef CBC_OPCODE @@ -79,18 +68,12 @@ const uint8_t cbc_ext_flags[] = /** * Names of the opcodes. */ -const char * const cbc_names[] = -{ - CBC_OPCODE_LIST -}; +const char* const cbc_names[] = { CBC_OPCODE_LIST }; /** * Names of the extended opcodes. */ -const char * const cbc_ext_names[] = -{ - CBC_EXT_OPCODE_LIST -}; +const char* const cbc_ext_names[] = { CBC_EXT_OPCODE_LIST }; #undef CBC_OPCODE diff --git a/jerry-core/parser/js/byte-code.h b/jerry-core/parser/js/byte-code.h index 682052bb..09b0a78c 100644 --- a/jerry-core/parser/js/byte-code.h +++ b/jerry-core/parser/js/byte-code.h @@ -45,20 +45,19 @@ * three bits for each instruction between -4 and 3 * (except for call / construct opcodes). */ -#define CBC_STACK_ADJUST_BASE 4 -#define CBC_STACK_ADJUST_SHIFT 5 -#define CBC_STACK_ADJUST_VALUE(value) \ - (((value) >> CBC_STACK_ADJUST_SHIFT) - CBC_STACK_ADJUST_BASE) +#define CBC_STACK_ADJUST_BASE 4 +#define CBC_STACK_ADJUST_SHIFT 5 +#define CBC_STACK_ADJUST_VALUE(value) (((value) >> CBC_STACK_ADJUST_SHIFT) - CBC_STACK_ADJUST_BASE) -#define CBC_NO_FLAG 0x00u -#define CBC_HAS_LITERAL_ARG 0x01u -#define CBC_HAS_LITERAL_ARG2 0x02u -#define CBC_HAS_BYTE_ARG 0x04u -#define CBC_HAS_BRANCH_ARG 0x08u +#define CBC_NO_FLAG 0x00u +#define CBC_HAS_LITERAL_ARG 0x01u +#define CBC_HAS_LITERAL_ARG2 0x02u +#define CBC_HAS_BYTE_ARG 0x04u +#define CBC_HAS_BRANCH_ARG 0x08u /* These flags are shared */ -#define CBC_FORWARD_BRANCH_ARG 0x10u -#define CBC_POP_STACK_BYTE_ARG 0x10u +#define CBC_FORWARD_BRANCH_ARG 0x10u +#define CBC_POP_STACK_BYTE_ARG 0x10u #define CBC_ARG_TYPES (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2 | CBC_HAS_BYTE_ARG | CBC_HAS_BRANCH_ARG) @@ -68,9 +67,9 @@ /** * CBC_NO_RESULT_OPERATION for ext opcodes */ -#define CBC_EXT_NO_RESULT_OPERATION(opcode) \ +#define CBC_EXT_NO_RESULT_OPERATION(opcode) \ ((opcode) >= PARSER_TO_EXT_OPCODE (CBC_EXT_ASSIGN_SUPER) \ - && (opcode) <= PARSER_TO_EXT_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK)) + && (opcode) <= PARSER_TO_EXT_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK)) #else /* !JERRY_ESNEXT */ /** * CBC_NO_RESULT_OPERATION for ext opcodes @@ -79,46 +78,52 @@ #endif /* JERRY_ESNEXT */ /* Debug macro. */ -#define CBC_ARGS_EQ(op, types) \ - ((cbc_flags[op] & CBC_ARG_TYPES) == (types)) +#define CBC_ARGS_EQ(op, types) ((cbc_flags[op] & CBC_ARG_TYPES) == (types)) /* Debug macro. */ -#define CBC_SAME_ARGS(op1, op2) \ - (CBC_EXT_NO_RESULT_OPERATION (op1) ? ((cbc_ext_flags[PARSER_GET_EXT_OPCODE (op1)] & CBC_ARG_TYPES) \ - == (cbc_ext_flags[PARSER_GET_EXT_OPCODE (op2)] & CBC_ARG_TYPES)) \ +#define CBC_SAME_ARGS(op1, op2) \ + (CBC_EXT_NO_RESULT_OPERATION (op1) ? ((cbc_ext_flags[PARSER_GET_EXT_OPCODE (op1)] & CBC_ARG_TYPES) \ + == (cbc_ext_flags[PARSER_GET_EXT_OPCODE (op2)] & CBC_ARG_TYPES)) \ : ((cbc_flags[op1] & CBC_ARG_TYPES) == (cbc_flags[op2] & CBC_ARG_TYPES))) -#define CBC_UNARY_OPERATION(name, group) \ - CBC_OPCODE (name, CBC_NO_FLAG, 0, \ - (VM_OC_ ## group) | VM_OC_GET_STACK | VM_OC_PUT_STACK) \ - CBC_OPCODE (name ## _LITERAL, CBC_HAS_LITERAL_ARG, 1, \ - (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) - -#define CBC_BINARY_OPERATION(name, group) \ - CBC_OPCODE (name, CBC_NO_FLAG, -1, \ - (VM_OC_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ - CBC_OPCODE (name ## _RIGHT_LITERAL, CBC_HAS_LITERAL_ARG, 0, \ - (VM_OC_ ## group) | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (name ## _TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \ - (VM_OC_ ## group) | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) - -#define CBC_UNARY_LVALUE_OPERATION(name, group) \ - CBC_OPCODE (name, CBC_NO_FLAG, -2, \ - (VM_OC_PROP_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE) \ - CBC_OPCODE (name ## _PUSH_RESULT, CBC_NO_FLAG, -1, \ - (VM_OC_PROP_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ - CBC_OPCODE (name ## _BLOCK, CBC_NO_FLAG, -2, \ - (VM_OC_PROP_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (name ## _IDENT, CBC_HAS_LITERAL_ARG, 0, \ - (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ - CBC_OPCODE (name ## _IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 1, \ - (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ - CBC_OPCODE (name ## _IDENT_BLOCK, CBC_HAS_LITERAL_ARG, 0, \ - (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) +#define CBC_UNARY_OPERATION(name, group) \ + CBC_OPCODE (name, CBC_NO_FLAG, 0, (VM_OC_##group) | VM_OC_GET_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_LITERAL, CBC_HAS_LITERAL_ARG, 1, (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) + +#define CBC_BINARY_OPERATION(name, group) \ + CBC_OPCODE (name, CBC_NO_FLAG, -1, (VM_OC_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_RIGHT_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + (VM_OC_##group) | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_TWO_LITERALS, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + (VM_OC_##group) | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) + +#define CBC_UNARY_LVALUE_OPERATION(name, group) \ + CBC_OPCODE (name, CBC_NO_FLAG, -2, (VM_OC_PROP_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (name##_PUSH_RESULT, \ + CBC_NO_FLAG, \ + -1, \ + (VM_OC_PROP_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_BLOCK, \ + CBC_NO_FLAG, \ + -2, \ + (VM_OC_PROP_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (name##_IDENT, CBC_HAS_LITERAL_ARG, 0, (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ + CBC_OPCODE (name##_IDENT_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_IDENT_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) #define CBC_UNARY_LVALUE_WITH_IDENT 3 -#define CBC_BINARY_WITH_LITERAL 1 +#define CBC_BINARY_WITH_LITERAL 1 #define CBC_BINARY_WITH_TWO_LITERALS 2 /** @@ -161,30 +166,21 @@ * The offset bytes are encoded in higher to lower order. */ -#define CBC_FORWARD_BRANCH(name, stack, vm_oc) \ - CBC_OPCODE (name, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, \ - (vm_oc) | VM_OC_GET_BRANCH) \ - CBC_OPCODE (name ## _2, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, \ - (vm_oc) | VM_OC_GET_BRANCH) \ - CBC_OPCODE (name ## _3, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, \ - (vm_oc) | VM_OC_GET_BRANCH) +#define CBC_FORWARD_BRANCH(name, stack, vm_oc) \ + CBC_OPCODE (name, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH) \ + CBC_OPCODE (name##_2, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH) \ + CBC_OPCODE (name##_3, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH) -#define CBC_BACKWARD_BRANCH(name, stack, vm_oc) \ - CBC_OPCODE (name, CBC_HAS_BRANCH_ARG, stack, \ - (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \ - CBC_OPCODE (name ## _2, CBC_HAS_BRANCH_ARG, stack, \ - (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \ - CBC_OPCODE (name ## _3, CBC_HAS_BRANCH_ARG, stack, \ - (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) +#define CBC_BACKWARD_BRANCH(name, stack, vm_oc) \ + CBC_OPCODE (name, CBC_HAS_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \ + CBC_OPCODE (name##_2, CBC_HAS_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \ + CBC_OPCODE (name##_3, CBC_HAS_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) -#define CBC_BRANCH_OFFSET_LENGTH(opcode) \ - ((opcode) & 0x3) +#define CBC_BRANCH_OFFSET_LENGTH(opcode) ((opcode) &0x3) -#define CBC_BRANCH_IS_BACKWARD(flags) \ - (!((flags) & CBC_FORWARD_BRANCH_ARG)) +#define CBC_BRANCH_IS_BACKWARD(flags) (!((flags) &CBC_FORWARD_BRANCH_ARG)) -#define CBC_BRANCH_IS_FORWARD(flags) \ - ((flags) & CBC_FORWARD_BRANCH_ARG) +#define CBC_BRANCH_IS_FORWARD(flags) ((flags) &CBC_FORWARD_BRANCH_ARG) /* Stack consumption of opcodes with context. */ @@ -218,600 +214,491 @@ /** * Opcode definitions. */ -#define CBC_OPCODE_LIST \ - /* Branch opcodes first. Some other opcodes are mixed. */ \ - CBC_OPCODE (CBC_EXT_OPCODE, CBC_NO_FLAG, 0, \ - VM_OC_NONE) \ - CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD, 0, \ - VM_OC_JUMP) \ - CBC_OPCODE (CBC_POP, CBC_NO_FLAG, -1, \ - VM_OC_POP) \ - CBC_BACKWARD_BRANCH (CBC_JUMP_BACKWARD, 0, \ - VM_OC_JUMP) \ - CBC_OPCODE (CBC_POP_BLOCK, CBC_NO_FLAG, -1, \ - VM_OC_POP_BLOCK | VM_OC_PUT_BLOCK) \ - CBC_FORWARD_BRANCH (CBC_BRANCH_IF_TRUE_FORWARD, -1, \ - VM_OC_BRANCH_IF_TRUE) \ - CBC_OPCODE (CBC_THROW, CBC_NO_FLAG, -1, \ - VM_OC_THROW | VM_OC_GET_STACK) \ - CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_TRUE_BACKWARD, -1, \ - VM_OC_BRANCH_IF_TRUE) \ - CBC_OPCODE (CBC_CONTEXT_END, CBC_NO_FLAG, 0, \ - VM_OC_CONTEXT_END) \ - CBC_FORWARD_BRANCH (CBC_BRANCH_IF_FALSE_FORWARD, -1, \ - VM_OC_BRANCH_IF_FALSE) \ - CBC_OPCODE (CBC_CREATE_OBJECT, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_OBJECT | VM_OC_PUT_STACK) \ - CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_FALSE_BACKWARD, -1, \ - VM_OC_BRANCH_IF_FALSE) \ - CBC_OPCODE (CBC_SET_PROPERTY, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \ - CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD_EXIT_CONTEXT, 0, \ - VM_OC_JUMP_AND_EXIT_CONTEXT) \ - CBC_OPCODE (CBC_CREATE_ARRAY, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_ARRAY | VM_OC_PUT_STACK) \ - CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_TRUE, -1, \ - VM_OC_BRANCH_IF_LOGICAL_TRUE) \ - CBC_OPCODE (CBC_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_APPEND_ARRAY) \ - CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_FALSE, -1, \ - VM_OC_BRANCH_IF_LOGICAL_FALSE) \ - CBC_OPCODE (CBC_PUSH_ELISION, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_ELISON | VM_OC_PUT_STACK) \ - CBC_FORWARD_BRANCH (CBC_BRANCH_IF_STRICT_EQUAL, -1, \ - VM_OC_BRANCH_IF_STRICT_EQUAL) \ - CBC_OPCODE (CBC_PUSH_NULL, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_NULL | VM_OC_PUT_STACK) \ - CBC_FORWARD_BRANCH (CBC_BLOCK_CREATE_CONTEXT, \ - PARSER_BLOCK_CONTEXT_STACK_ALLOCATION, VM_OC_BLOCK_CREATE_CONTEXT) \ - \ - /* Basic opcodes. Note: These 4 opcodes must me in this order */ \ - CBC_OPCODE (CBC_PUSH_LITERAL, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_PUSH | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_PUSH_TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 2, \ - VM_OC_PUSH_TWO | VM_OC_GET_LITERAL_LITERAL) \ - CBC_OPCODE (CBC_PUSH_THIS_LITERAL, CBC_HAS_LITERAL_ARG, 2, \ - VM_OC_PUSH_TWO | VM_OC_GET_THIS_LITERAL) \ - CBC_OPCODE (CBC_PUSH_THREE_LITERALS, CBC_HAS_LITERAL_ARG2, 3, \ - VM_OC_PUSH_THREE | VM_OC_GET_LITERAL_LITERAL) \ - CBC_OPCODE (CBC_PUSH_UNDEFINED, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_UNDEFINED | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_TRUE, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_TRUE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_FALSE, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_FALSE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_THIS, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_THIS | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_NUMBER_0, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_0 | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_NUMBER_POS_BYTE, CBC_HAS_BYTE_ARG, 1, \ - VM_OC_PUSH_POS_BYTE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_NUMBER_NEG_BYTE, CBC_HAS_BYTE_ARG, 1, \ - VM_OC_PUSH_NEG_BYTE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_0, CBC_HAS_LITERAL_ARG, 2, \ - VM_OC_PUSH_LIT_0 | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE, CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, 2, \ - VM_OC_PUSH_LIT_POS_BYTE | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE, CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, 2, \ - VM_OC_PUSH_LIT_NEG_BYTE | VM_OC_GET_LITERAL) \ - /* Note: These 4 opcodes must me in this order */ \ - CBC_OPCODE (CBC_PUSH_PROP, CBC_NO_FLAG, -1, \ - VM_OC_PROP_GET | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_PROP_GET | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \ - VM_OC_PROP_GET | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_PROP_GET | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_IDENT_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \ - VM_OC_IDENT_REFERENCE | VM_OC_PUT_STACK) \ - /* Note: These 4 opcodes must me in this order */ \ - CBC_OPCODE (CBC_PUSH_PROP_REFERENCE, CBC_NO_FLAG, 1, \ - VM_OC_PROP_REFERENCE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_PROP_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 2, \ - VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 3, \ - VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \ - VM_OC_PROP_REFERENCE | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_NEW | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_NEW0, CBC_NO_FLAG, 0, \ - VM_OC_NEW | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_NEW1, CBC_NO_FLAG, -1, \ - VM_OC_NEW | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EVAL, CBC_NO_FLAG, 0, \ - VM_OC_EVAL) \ - CBC_OPCODE (CBC_CHECK_VAR, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CHECK_VAR) \ - CBC_OPCODE (CBC_CHECK_LET, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CHECK_LET) \ - CBC_OPCODE (CBC_CREATE_VAR, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CREATE_BINDING) \ - CBC_OPCODE (CBC_CREATE_LET, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CREATE_BINDING) \ - CBC_OPCODE (CBC_CREATE_CONST, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CREATE_BINDING) \ - CBC_OPCODE (CBC_CREATE_LOCAL, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CREATE_BINDING) \ - CBC_OPCODE (CBC_INIT_ARG_OR_CATCH, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_INIT_BINDING) \ - CBC_OPCODE (CBC_INIT_LET, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_INIT_BINDING) \ - CBC_OPCODE (CBC_INIT_CONST, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_INIT_BINDING) \ - CBC_OPCODE (CBC_INIT_ARG_OR_FUNC, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_INIT_ARG_OR_FUNC) \ - CBC_OPCODE (CBC_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_VAR_EVAL) \ - CBC_OPCODE (CBC_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_VAR_EVAL) \ - CBC_OPCODE (CBC_SET_VAR_FUNC, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ - CBC_OPCODE (CBC_SET_BYTECODE_PTR, CBC_NO_FLAG, 0, \ - VM_OC_SET_BYTECODE_PTR) \ - CBC_OPCODE (CBC_RETURN, CBC_NO_FLAG, -1, \ - VM_OC_RETURN | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_RETURN_FUNCTION_END, CBC_NO_FLAG, 0, \ - VM_OC_RETURN_FUNCTION_END) \ - CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_RETURN | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_SET_LITERAL_PROPERTY, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ - CBC_OPCODE (CBC_COPY_TO_GLOBAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_COPY_TO_GLOBAL | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_BREAKPOINT_ENABLED, CBC_NO_FLAG, 0, \ - VM_OC_BREAKPOINT_ENABLED) \ - CBC_OPCODE (CBC_BREAKPOINT_DISABLED, CBC_NO_FLAG, 0, \ - VM_OC_BREAKPOINT_DISABLED) \ - \ - /* Unary opcodes. */ \ - CBC_UNARY_OPERATION (CBC_PLUS, \ - PLUS) \ - CBC_UNARY_OPERATION (CBC_NEGATE, \ - MINUS) \ - CBC_UNARY_OPERATION (CBC_LOGICAL_NOT, \ - NOT) \ - CBC_UNARY_OPERATION (CBC_BIT_NOT, \ - BIT_NOT) \ - CBC_UNARY_OPERATION (CBC_VOID, \ - VOID) \ - CBC_OPCODE (CBC_TYPEOF, CBC_NO_FLAG, 0, \ - VM_OC_TYPEOF | VM_OC_GET_STACK | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_TYPEOF_IDENT, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_TYPEOF_IDENT | VM_OC_PUT_STACK) \ - \ - /* Binary opcodes. */ \ - CBC_BINARY_OPERATION (CBC_BIT_OR, \ - BIT_OR) \ - CBC_BINARY_OPERATION (CBC_BIT_XOR, \ - BIT_XOR) \ - CBC_BINARY_OPERATION (CBC_BIT_AND, \ - BIT_AND) \ - CBC_BINARY_OPERATION (CBC_EQUAL, \ - EQUAL) \ - CBC_BINARY_OPERATION (CBC_NOT_EQUAL, \ - NOT_EQUAL) \ - CBC_BINARY_OPERATION (CBC_STRICT_EQUAL, \ - STRICT_EQUAL) \ - CBC_BINARY_OPERATION (CBC_STRICT_NOT_EQUAL, \ - STRICT_NOT_EQUAL) \ - CBC_BINARY_OPERATION (CBC_LESS, \ - LESS) \ - CBC_BINARY_OPERATION (CBC_GREATER, \ - GREATER) \ - CBC_BINARY_OPERATION (CBC_LESS_EQUAL, \ - LESS_EQUAL) \ - CBC_BINARY_OPERATION (CBC_GREATER_EQUAL, \ - GREATER_EQUAL) \ - CBC_BINARY_OPERATION (CBC_IN, \ - IN) \ - CBC_BINARY_OPERATION (CBC_INSTANCEOF, \ - INSTANCEOF) \ - CBC_BINARY_OPERATION (CBC_LEFT_SHIFT, \ - LEFT_SHIFT) \ - CBC_BINARY_OPERATION (CBC_RIGHT_SHIFT, \ - RIGHT_SHIFT) \ - CBC_BINARY_OPERATION (CBC_UNS_RIGHT_SHIFT, \ - UNS_RIGHT_SHIFT) \ - CBC_BINARY_OPERATION (CBC_ADD, \ - ADD) \ - CBC_BINARY_OPERATION (CBC_SUBTRACT, \ - SUB) \ - CBC_BINARY_OPERATION (CBC_MULTIPLY, \ - MUL) \ - CBC_BINARY_OPERATION (CBC_DIVIDE, \ - DIV) \ - CBC_BINARY_OPERATION (CBC_MODULO, \ - MOD) \ - CBC_BINARY_OPERATION (CBC_EXPONENTIATION, \ - EXP) \ - \ - /* Unary lvalue opcodes. */ \ - CBC_OPCODE (CBC_DELETE_PUSH_RESULT, CBC_NO_FLAG, -1, \ - VM_OC_PROP_DELETE | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_DELETE_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_DELETE | VM_OC_PUT_STACK) \ - CBC_UNARY_LVALUE_OPERATION (CBC_PRE_INCR, \ - PRE_INCR) \ - CBC_UNARY_LVALUE_OPERATION (CBC_PRE_DECR, \ - PRE_DECR) \ - CBC_UNARY_LVALUE_OPERATION (CBC_POST_INCR, \ - POST_INCR) \ - CBC_UNARY_LVALUE_OPERATION (CBC_POST_DECR, \ - POST_DECR) \ - \ - /* Call opcodes. */ \ - CBC_OPCODE (CBC_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL_PROP_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, -2, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL0, CBC_NO_FLAG, -1, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL0_PUSH_RESULT, CBC_NO_FLAG, 0, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL0_BLOCK, CBC_NO_FLAG, -1, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL0_PROP, CBC_NO_FLAG, -3, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL0_PROP_PUSH_RESULT, CBC_NO_FLAG, -2, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL0_PROP_BLOCK, CBC_NO_FLAG, -3, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL1, CBC_NO_FLAG, -2, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL1_PUSH_RESULT, CBC_NO_FLAG, -1, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL1_BLOCK, CBC_NO_FLAG, -2, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL1_PROP, CBC_NO_FLAG, -4, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL1_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL1_PROP_BLOCK, CBC_NO_FLAG, -4, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL2, CBC_NO_FLAG, -3, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL2_PUSH_RESULT, CBC_NO_FLAG, -2, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL2_BLOCK, CBC_NO_FLAG, -3, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_CALL2_PROP, CBC_NO_FLAG, -4, \ - VM_OC_CALL) \ - CBC_OPCODE (CBC_CALL2_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, \ - VM_OC_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_CALL2_PROP_BLOCK, CBC_NO_FLAG, -4, \ - VM_OC_CALL | VM_OC_PUT_BLOCK) \ - \ - /* Binary assignment opcodes. */ \ - CBC_OPCODE (CBC_ASSIGN, CBC_NO_FLAG, -3, \ - VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE) \ - CBC_OPCODE (CBC_ASSIGN_PUSH_RESULT, CBC_NO_FLAG, -2, \ - VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_ASSIGN_BLOCK, CBC_NO_FLAG, -3, \ - VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_ASSIGN_SET_IDENT, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \ - CBC_OPCODE (CBC_ASSIGN_SET_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_ASSIGN_SET_IDENT_BLOCK, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ - CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \ - VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_BLOCK, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL, CBC_HAS_LITERAL_ARG, -2, \ - VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \ - CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_PUSH_RESULT, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_BLOCK, CBC_HAS_LITERAL_ARG, -2, \ - VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \ - CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_BLOCK, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_MOV_IDENT, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_MOV_IDENT | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \ - CBC_OPCODE (CBC_ASSIGN_LET_CONST, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_ASSIGN_LET_CONST | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_ASSIGN_LET_CONST_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_ASSIGN_LET_CONST | VM_OC_GET_LITERAL) \ - \ - /* Last opcode (not a real opcode). */ \ - CBC_OPCODE (CBC_END, CBC_NO_FLAG, 0, \ - VM_OC_NONE) +#define CBC_OPCODE_LIST \ + /* Branch opcodes first. Some other opcodes are mixed. */ \ + CBC_OPCODE (CBC_EXT_OPCODE, CBC_NO_FLAG, 0, VM_OC_NONE) \ + CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD, 0, VM_OC_JUMP) \ + CBC_OPCODE (CBC_POP, CBC_NO_FLAG, -1, VM_OC_POP) \ + CBC_BACKWARD_BRANCH (CBC_JUMP_BACKWARD, 0, VM_OC_JUMP) \ + CBC_OPCODE (CBC_POP_BLOCK, CBC_NO_FLAG, -1, VM_OC_POP_BLOCK | VM_OC_PUT_BLOCK) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_TRUE_FORWARD, -1, VM_OC_BRANCH_IF_TRUE) \ + CBC_OPCODE (CBC_THROW, CBC_NO_FLAG, -1, VM_OC_THROW | VM_OC_GET_STACK) \ + CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_TRUE_BACKWARD, -1, VM_OC_BRANCH_IF_TRUE) \ + CBC_OPCODE (CBC_CONTEXT_END, CBC_NO_FLAG, 0, VM_OC_CONTEXT_END) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_FALSE_FORWARD, -1, VM_OC_BRANCH_IF_FALSE) \ + CBC_OPCODE (CBC_CREATE_OBJECT, CBC_NO_FLAG, 1, VM_OC_PUSH_OBJECT | VM_OC_PUT_STACK) \ + CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_FALSE_BACKWARD, -1, VM_OC_BRANCH_IF_FALSE) \ + CBC_OPCODE (CBC_SET_PROPERTY, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \ + CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD_EXIT_CONTEXT, 0, VM_OC_JUMP_AND_EXIT_CONTEXT) \ + CBC_OPCODE (CBC_CREATE_ARRAY, CBC_NO_FLAG, 1, VM_OC_PUSH_ARRAY | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_TRUE, -1, VM_OC_BRANCH_IF_LOGICAL_TRUE) \ + CBC_OPCODE (CBC_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_APPEND_ARRAY) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_FALSE, -1, VM_OC_BRANCH_IF_LOGICAL_FALSE) \ + CBC_OPCODE (CBC_PUSH_ELISION, CBC_NO_FLAG, 1, VM_OC_PUSH_ELISON | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_STRICT_EQUAL, -1, VM_OC_BRANCH_IF_STRICT_EQUAL) \ + CBC_OPCODE (CBC_PUSH_NULL, CBC_NO_FLAG, 1, VM_OC_PUSH_NULL | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_BLOCK_CREATE_CONTEXT, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION, VM_OC_BLOCK_CREATE_CONTEXT) \ + \ + /* Basic opcodes. Note: These 4 opcodes must me in this order */ \ + CBC_OPCODE (CBC_PUSH_LITERAL, CBC_HAS_LITERAL_ARG, 1, VM_OC_PUSH | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_PUSH_TWO_LITERALS, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 2, \ + VM_OC_PUSH_TWO | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_PUSH_THIS_LITERAL, CBC_HAS_LITERAL_ARG, 2, VM_OC_PUSH_TWO | VM_OC_GET_THIS_LITERAL) \ + CBC_OPCODE (CBC_PUSH_THREE_LITERALS, CBC_HAS_LITERAL_ARG2, 3, VM_OC_PUSH_THREE | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_PUSH_UNDEFINED, CBC_NO_FLAG, 1, VM_OC_PUSH_UNDEFINED | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_TRUE, CBC_NO_FLAG, 1, VM_OC_PUSH_TRUE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_FALSE, CBC_NO_FLAG, 1, VM_OC_PUSH_FALSE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_THIS, CBC_NO_FLAG, 1, VM_OC_PUSH_THIS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_NUMBER_0, CBC_NO_FLAG, 1, VM_OC_PUSH_0 | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_NUMBER_POS_BYTE, CBC_HAS_BYTE_ARG, 1, VM_OC_PUSH_POS_BYTE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_NUMBER_NEG_BYTE, CBC_HAS_BYTE_ARG, 1, VM_OC_PUSH_NEG_BYTE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_0, CBC_HAS_LITERAL_ARG, 2, VM_OC_PUSH_LIT_0 | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, \ + 2, \ + VM_OC_PUSH_LIT_POS_BYTE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, \ + 2, \ + VM_OC_PUSH_LIT_NEG_BYTE | VM_OC_GET_LITERAL) \ + /* Note: These 4 opcodes must me in this order */ \ + CBC_OPCODE (CBC_PUSH_PROP, CBC_NO_FLAG, -1, VM_OC_PROP_GET | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_PROP_GET | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_PROP_GET | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_PROP_GET | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_IDENT_REFERENCE, CBC_HAS_LITERAL_ARG, 3, VM_OC_IDENT_REFERENCE | VM_OC_PUT_STACK) \ + /* Note: These 4 opcodes must me in this order */ \ + CBC_OPCODE (CBC_PUSH_PROP_REFERENCE, CBC_NO_FLAG, 1, VM_OC_PROP_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 2, \ + VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 3, \ + VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 3, \ + VM_OC_PROP_REFERENCE | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_NEW | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_NEW0, CBC_NO_FLAG, 0, VM_OC_NEW | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_NEW1, CBC_NO_FLAG, -1, VM_OC_NEW | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EVAL, CBC_NO_FLAG, 0, VM_OC_EVAL) \ + CBC_OPCODE (CBC_CHECK_VAR, CBC_HAS_LITERAL_ARG, 0, VM_OC_CHECK_VAR) \ + CBC_OPCODE (CBC_CHECK_LET, CBC_HAS_LITERAL_ARG, 0, VM_OC_CHECK_LET) \ + CBC_OPCODE (CBC_CREATE_VAR, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_CREATE_LET, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_CREATE_CONST, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_CREATE_LOCAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_INIT_ARG_OR_CATCH, CBC_HAS_LITERAL_ARG, -1, VM_OC_INIT_BINDING) \ + CBC_OPCODE (CBC_INIT_LET, CBC_HAS_LITERAL_ARG, -1, VM_OC_INIT_BINDING) \ + CBC_OPCODE (CBC_INIT_CONST, CBC_HAS_LITERAL_ARG, -1, VM_OC_INIT_BINDING) \ + CBC_OPCODE (CBC_INIT_ARG_OR_FUNC, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_INIT_ARG_OR_FUNC) \ + CBC_OPCODE (CBC_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_VAR_EVAL) \ + CBC_OPCODE (CBC_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_VAR_EVAL) \ + CBC_OPCODE (CBC_SET_VAR_FUNC, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_SET_BYTECODE_PTR, CBC_NO_FLAG, 0, VM_OC_SET_BYTECODE_PTR) \ + CBC_OPCODE (CBC_RETURN, CBC_NO_FLAG, -1, VM_OC_RETURN | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_RETURN_FUNCTION_END, CBC_NO_FLAG, 0, VM_OC_RETURN_FUNCTION_END) \ + CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_RETURN | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_SET_LITERAL_PROPERTY, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_COPY_TO_GLOBAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COPY_TO_GLOBAL | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_BREAKPOINT_ENABLED, CBC_NO_FLAG, 0, VM_OC_BREAKPOINT_ENABLED) \ + CBC_OPCODE (CBC_BREAKPOINT_DISABLED, CBC_NO_FLAG, 0, VM_OC_BREAKPOINT_DISABLED) \ + \ + /* Unary opcodes. */ \ + CBC_UNARY_OPERATION (CBC_PLUS, PLUS) \ + CBC_UNARY_OPERATION (CBC_NEGATE, MINUS) \ + CBC_UNARY_OPERATION (CBC_LOGICAL_NOT, NOT) \ + CBC_UNARY_OPERATION (CBC_BIT_NOT, BIT_NOT) \ + CBC_UNARY_OPERATION (CBC_VOID, VOID) \ + CBC_OPCODE (CBC_TYPEOF, CBC_NO_FLAG, 0, VM_OC_TYPEOF | VM_OC_GET_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_TYPEOF_IDENT, CBC_HAS_LITERAL_ARG, 1, VM_OC_TYPEOF_IDENT | VM_OC_PUT_STACK) \ + \ + /* Binary opcodes. */ \ + CBC_BINARY_OPERATION (CBC_BIT_OR, BIT_OR) \ + CBC_BINARY_OPERATION (CBC_BIT_XOR, BIT_XOR) \ + CBC_BINARY_OPERATION (CBC_BIT_AND, BIT_AND) \ + CBC_BINARY_OPERATION (CBC_EQUAL, EQUAL) \ + CBC_BINARY_OPERATION (CBC_NOT_EQUAL, NOT_EQUAL) \ + CBC_BINARY_OPERATION (CBC_STRICT_EQUAL, STRICT_EQUAL) \ + CBC_BINARY_OPERATION (CBC_STRICT_NOT_EQUAL, STRICT_NOT_EQUAL) \ + CBC_BINARY_OPERATION (CBC_LESS, LESS) \ + CBC_BINARY_OPERATION (CBC_GREATER, GREATER) \ + CBC_BINARY_OPERATION (CBC_LESS_EQUAL, LESS_EQUAL) \ + CBC_BINARY_OPERATION (CBC_GREATER_EQUAL, GREATER_EQUAL) \ + CBC_BINARY_OPERATION (CBC_IN, IN) \ + CBC_BINARY_OPERATION (CBC_INSTANCEOF, INSTANCEOF) \ + CBC_BINARY_OPERATION (CBC_LEFT_SHIFT, LEFT_SHIFT) \ + CBC_BINARY_OPERATION (CBC_RIGHT_SHIFT, RIGHT_SHIFT) \ + CBC_BINARY_OPERATION (CBC_UNS_RIGHT_SHIFT, UNS_RIGHT_SHIFT) \ + CBC_BINARY_OPERATION (CBC_ADD, ADD) \ + CBC_BINARY_OPERATION (CBC_SUBTRACT, SUB) \ + CBC_BINARY_OPERATION (CBC_MULTIPLY, MUL) \ + CBC_BINARY_OPERATION (CBC_DIVIDE, DIV) \ + CBC_BINARY_OPERATION (CBC_MODULO, MOD) \ + CBC_BINARY_OPERATION (CBC_EXPONENTIATION, EXP) \ + \ + /* Unary lvalue opcodes. */ \ + CBC_OPCODE (CBC_DELETE_PUSH_RESULT, CBC_NO_FLAG, -1, VM_OC_PROP_DELETE | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_DELETE_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 1, VM_OC_DELETE | VM_OC_PUT_STACK) \ + CBC_UNARY_LVALUE_OPERATION (CBC_PRE_INCR, PRE_INCR) \ + CBC_UNARY_LVALUE_OPERATION (CBC_PRE_DECR, PRE_DECR) \ + CBC_UNARY_LVALUE_OPERATION (CBC_POST_INCR, POST_INCR) \ + CBC_UNARY_LVALUE_OPERATION (CBC_POST_DECR, POST_DECR) \ + \ + /* Call opcodes. */ \ + CBC_OPCODE (CBC_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL_PROP_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, -2, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL0, CBC_NO_FLAG, -1, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL0_PUSH_RESULT, CBC_NO_FLAG, 0, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL0_BLOCK, CBC_NO_FLAG, -1, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL0_PROP, CBC_NO_FLAG, -3, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL0_PROP_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL0_PROP_BLOCK, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL1, CBC_NO_FLAG, -2, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL1_PUSH_RESULT, CBC_NO_FLAG, -1, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL1_BLOCK, CBC_NO_FLAG, -2, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL1_PROP, CBC_NO_FLAG, -4, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL1_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL1_PROP_BLOCK, CBC_NO_FLAG, -4, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL2, CBC_NO_FLAG, -3, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL2_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL2_BLOCK, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL2_PROP, CBC_NO_FLAG, -4, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL2_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL2_PROP_BLOCK, CBC_NO_FLAG, -4, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + \ + /* Binary assignment opcodes. */ \ + CBC_OPCODE (CBC_ASSIGN, CBC_NO_FLAG, -3, VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_ASSIGN_PUSH_RESULT, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_BLOCK, \ + CBC_NO_FLAG, \ + -3, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_SET_IDENT, CBC_HAS_LITERAL_ARG, -1, VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_ASSIGN_SET_IDENT_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_SET_IDENT_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_BLOCK, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + -2, \ + VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + -2, \ + VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_MOV_IDENT, CBC_HAS_LITERAL_ARG, -1, VM_OC_MOV_IDENT | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_ASSIGN_LET_CONST, CBC_HAS_LITERAL_ARG, -1, VM_OC_ASSIGN_LET_CONST | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_ASSIGN_LET_CONST_LITERAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN_LET_CONST | VM_OC_GET_LITERAL) \ + \ + /* Last opcode (not a real opcode). */ \ + CBC_OPCODE (CBC_END, CBC_NO_FLAG, 0, VM_OC_NONE) /* All EXT branches are statement block end * marks, so they are always forward branches. */ -#define CBC_EXT_OPCODE_LIST \ - /* Branch opcodes first. Some other opcodes are mixed. */ \ - CBC_OPCODE (CBC_EXT_NOP, CBC_NO_FLAG, 0, \ - VM_OC_NONE) \ - CBC_FORWARD_BRANCH (CBC_EXT_WITH_CREATE_CONTEXT, \ - -1 + PARSER_WITH_CONTEXT_STACK_ALLOCATION, VM_OC_WITH) \ - CBC_OPCODE (CBC_EXT_FOR_IN_GET_NEXT, CBC_NO_FLAG, 1, \ - VM_OC_FOR_IN_GET_NEXT | VM_OC_PUT_STACK) \ - CBC_FORWARD_BRANCH (CBC_EXT_FOR_IN_INIT, \ - -1 + PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_IN_INIT) \ - CBC_OPCODE (CBC_EXT_SET_GETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ - CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_IN_HAS_NEXT, 0, \ - VM_OC_FOR_IN_HAS_NEXT) \ - CBC_OPCODE (CBC_EXT_FOR_OF_GET_NEXT, CBC_NO_FLAG, 1, \ - VM_OC_FOR_OF_GET_NEXT | VM_OC_PUT_STACK) \ - CBC_FORWARD_BRANCH (CBC_EXT_FOR_OF_INIT, \ - -1 + PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_OF_INIT) \ - CBC_OPCODE (CBC_EXT_PUSH_NAMED_FUNC_EXPRESSION, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \ - VM_OC_PUSH_NAMED_FUNC_EXPR | VM_OC_GET_LITERAL_LITERAL) \ - CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_OF_HAS_NEXT, 0, \ - VM_OC_FOR_OF_HAS_NEXT) \ - CBC_OPCODE (CBC_EXT_CLONE_CONTEXT, CBC_NO_FLAG, 0, \ - VM_OC_CLONE_CONTEXT) \ - CBC_FORWARD_BRANCH (CBC_EXT_FOR_AWAIT_OF_INIT, \ - -1 + PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_AWAIT_OF_INIT) \ - CBC_OPCODE (CBC_EXT_CLONE_FULL_CONTEXT, CBC_NO_FLAG, 0, \ - VM_OC_CLONE_CONTEXT) \ - CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_AWAIT_OF_HAS_NEXT, 0, \ - VM_OC_FOR_AWAIT_OF_HAS_NEXT) \ - CBC_OPCODE (CBC_EXT_SET_SETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ - CBC_FORWARD_BRANCH (CBC_EXT_TRY_CREATE_CONTEXT, PARSER_TRY_CONTEXT_STACK_ALLOCATION, \ - VM_OC_TRY) \ - CBC_OPCODE (CBC_EXT_TRY_CREATE_ENV, CBC_NO_FLAG, 0, \ - VM_OC_BLOCK_CREATE_CONTEXT) \ - CBC_FORWARD_BRANCH (CBC_EXT_CATCH, 1, \ - VM_OC_CATCH) \ - CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, \ - VM_OC_RESOLVE_BASE_FOR_CALL) \ - CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION, \ - VM_OC_FINALLY) \ - CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP, CBC_NO_FLAG, 0, \ - VM_OC_INITIALIZER_PUSH_PROP) \ - CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, \ - VM_OC_DEFAULT_INITIALIZER) \ - CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, \ - VM_OC_ERROR) \ - CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_IF_NULLISH, -1, \ - VM_OC_BRANCH_IF_NULLISH) \ - \ - /* Basic opcodes. */ \ - CBC_OPCODE (CBC_EXT_CREATE_ARGUMENTS, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_CREATE_ARGUMENTS) \ - CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_EXT_VAR_EVAL) \ - CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_EXT_VAR_EVAL) \ - CBC_OPCODE (CBC_EXT_COPY_FROM_ARG, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_COPY_FROM_ARG) \ - CBC_OPCODE (CBC_EXT_PUSH_REST_OBJECT, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_REST_OBJECT) \ - CBC_OPCODE (CBC_EXT_MODULE_IMPORT, CBC_NO_FLAG, 0, \ - VM_OC_MODULE_IMPORT) \ - CBC_OPCODE (CBC_EXT_MODULE_IMPORT_META, CBC_NO_FLAG, 1, \ - VM_OC_MODULE_IMPORT_META) \ - CBC_OPCODE (CBC_EXT_STRING_CONCAT, CBC_NO_FLAG, -1, \ - VM_OC_STRING_CONCAT | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_STRING_CONCAT | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_STRING_CONCAT_TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \ - VM_OC_STRING_CONCAT | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_GET_TAGGED_TEMPLATE_LITERAL, CBC_HAS_BYTE_ARG, 1, \ - VM_OC_GET_TEMPLATE_OBJECT | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \ - VM_OC_THROW_REFERENCE_ERROR) \ - CBC_OPCODE (CBC_EXT_THROW_ASSIGN_CONST_ERROR, CBC_NO_FLAG, 0, \ - VM_OC_THROW_CONST_ERROR) \ - CBC_OPCODE (CBC_EXT_REQUIRE_OBJECT_COERCIBLE, CBC_NO_FLAG, 0, \ - VM_OC_REQUIRE_OBJECT_COERCIBLE) \ - CBC_OPCODE (CBC_EXT_COPY_DATA_PROPERTIES, CBC_NO_FLAG, -1, \ - VM_OC_COPY_DATA_PROPERTIES) \ - CBC_OPCODE (CBC_EXT_SET_FUNCTION_NAME, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_SET_FUNCTION_NAME | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_SET_CLASS_NAME, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_SET_FUNCTION_NAME) \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_FUNCTION_NAME, CBC_NO_FLAG, 0, \ - VM_OC_SET_FUNCTION_NAME) \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER_NAME, CBC_NO_FLAG, 0, \ - VM_OC_SET_FUNCTION_NAME) \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER_NAME, CBC_NO_FLAG, 0, \ - VM_OC_SET_FUNCTION_NAME) \ - \ - /* Computed / class property related opcodes. */ \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, CBC_NO_FLAG, -2, \ - VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER, CBC_NO_FLAG, -2, \ - VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ - CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER, CBC_NO_FLAG, -2, \ - VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY, CBC_HAS_LITERAL_ARG, -1, \ - VM_OC_SET_PROPERTY | VM_OC_GET_STACK_LITERAL) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_PROPERTY, CBC_NO_FLAG, -2, \ - VM_OC_SET_COMPUTED_PROPERTY | VM_OC_GET_STACK_STACK) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_GETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_SET_GETTER | VM_OC_GET_LITERAL_LITERAL) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_SETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \ - VM_OC_SET_SETTER | VM_OC_GET_LITERAL_LITERAL) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_GETTER, CBC_NO_FLAG, -2, \ - VM_OC_SET_GETTER | VM_OC_GET_STACK_STACK) \ - CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_SETTER, CBC_NO_FLAG, -2, \ - VM_OC_SET_SETTER | VM_OC_GET_STACK_STACK) \ - CBC_OPCODE (CBC_EXT_SET__PROTO__, CBC_NO_FLAG, -1, \ - VM_OC_SET__PROTO__ | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_PUSH_STATIC_FIELD_FUNC, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_ADD_COMPUTED_FIELD, CBC_NO_FLAG, -1, \ - VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_ADD_STATIC_COMPUTED_FIELD, CBC_NO_FLAG, -1, \ - VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \ - \ - /* Class related opcodes. */ \ - CBC_OPCODE (CBC_EXT_PUSH_NAMED_CLASS_ENV, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_PUSH_CLASS_ENVIRONMENT) \ - CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_INIT_CLASS, CBC_NO_FLAG, 0, \ - VM_OC_INIT_CLASS | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_FINALIZE_NAMED_CLASS, CBC_HAS_LITERAL_ARG, -2, \ - VM_OC_FINALIZE_CLASS) \ - CBC_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS, CBC_NO_FLAG, -2, \ - VM_OC_FINALIZE_CLASS) \ - CBC_OPCODE (CBC_EXT_SET_FIELD_INIT, CBC_HAS_LITERAL_ARG, 0, \ - VM_OC_SET_FIELD_INIT | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_RUN_FIELD_INIT, CBC_NO_FLAG, 0, \ - VM_OC_RUN_FIELD_INIT) \ - CBC_OPCODE (CBC_EXT_RUN_STATIC_FIELD_INIT, CBC_NO_FLAG, -1, \ - VM_OC_RUN_STATIC_FIELD_INIT) \ - CBC_OPCODE (CBC_EXT_SET_NEXT_COMPUTED_FIELD, CBC_NO_FLAG, -1, \ - VM_OC_SET_NEXT_COMPUTED_FIELD | VM_OC_PUT_REFERENCE) \ - CBC_OPCODE (CBC_EXT_PUSH_SUPER, CBC_NO_FLAG, 1, \ - VM_OC_NONE) \ - CBC_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_SUPER_CONSTRUCTOR) \ - CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP, CBC_NO_FLAG, 0, \ - VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE, CBC_NO_FLAG, 2, \ - VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \ - VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE, CBC_NO_FLAG, 1, \ - VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE, CBC_HAS_LITERAL_ARG, 2, \ - VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT, CBC_NO_FLAG, 0, \ - VM_OC_SET_HOME_OBJECT) \ - CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED, CBC_NO_FLAG, 0, \ - VM_OC_SET_HOME_OBJECT) \ - CBC_OPCODE (CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, 1, \ - VM_OC_OBJECT_LITERAL_HOME_ENV) \ - CBC_OPCODE (CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, -1, \ - VM_OC_OBJECT_LITERAL_HOME_ENV) \ - CBC_OPCODE (CBC_EXT_RESOLVE_LEXICAL_THIS, CBC_NO_FLAG, 1, \ - VM_OC_RESOLVE_LEXICAL_THIS | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_LOCAL_EVAL, CBC_HAS_BYTE_ARG, 0, \ - VM_OC_LOCAL_EVAL) \ - CBC_OPCODE (CBC_EXT_ASSIGN_SUPER, CBC_NO_FLAG, -3, \ - VM_OC_ASSIGN_SUPER) \ - CBC_OPCODE (CBC_EXT_ASSIGN_SUPER_PUSH_RESULT, CBC_NO_FLAG, -2, \ - VM_OC_ASSIGN_SUPER | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_ASSIGN_SUPER_BLOCK, CBC_NO_FLAG, -3, \ - VM_OC_ASSIGN_SUPER | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_EXT_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_SUPER_CALL) \ - CBC_OPCODE (CBC_EXT_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_SUPER_CALL) \ - CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \ - \ - /* Spread / rest operation related opcodes. */ \ - CBC_OPCODE (CBC_EXT_SPREAD_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_SPREAD_ARGUMENTS) \ - CBC_OPCODE (CBC_EXT_SPREAD_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_SPREAD_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \ - VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, \ - VM_OC_SPREAD_ARGUMENTS) \ - CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, -2, \ - VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ - CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, \ - VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \ - CBC_OPCODE (CBC_EXT_PUSH_SPREAD_ELEMENT, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_SPREAD_ELEMENT) \ - CBC_OPCODE (CBC_EXT_SPREAD_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_APPEND_ARRAY) \ - CBC_OPCODE (CBC_EXT_REST_INITIALIZER, CBC_NO_FLAG, 1, \ - VM_OC_REST_INITIALIZER) \ - CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_LITERAL) \ - CBC_OPCODE (CBC_EXT_SPREAD_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, \ - VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ - \ - /* Iterator related opcodes. */ \ - CBC_OPCODE (CBC_EXT_ITERATOR_CONTEXT_CREATE, CBC_NO_FLAG, PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION, \ - VM_OC_ITERATOR_CONTEXT_CREATE) \ - CBC_OPCODE (CBC_EXT_ITERATOR_CONTEXT_END, CBC_NO_FLAG, -PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION, \ - VM_OC_ITERATOR_CONTEXT_END) \ - CBC_OPCODE (CBC_EXT_ITERATOR_STEP, CBC_NO_FLAG, 1, \ - VM_OC_ITERATOR_STEP) \ - \ - /* Object initializer related opcodes. */ \ - CBC_OPCODE (CBC_EXT_OBJ_INIT_CONTEXT_CREATE, CBC_NO_FLAG, PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION, \ - VM_OC_OBJ_INIT_CONTEXT_CREATE) \ - CBC_OPCODE (CBC_EXT_OBJ_INIT_REST_CONTEXT_CREATE, CBC_NO_FLAG, PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION, \ - VM_OC_OBJ_INIT_CONTEXT_CREATE) \ - CBC_OPCODE (CBC_EXT_OBJ_INIT_PUSH_REST, CBC_NO_FLAG, 1, \ - VM_OC_OBJ_INIT_PUSH_REST) \ - CBC_OPCODE (CBC_EXT_OBJ_INIT_CONTEXT_END, CBC_NO_FLAG, -PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION, \ - VM_OC_OBJ_INIT_CONTEXT_END) \ - CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_NAME, CBC_NO_FLAG, 0, \ - VM_OC_INITIALIZER_PUSH_NAME | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_NAME_LITERAL, CBC_HAS_LITERAL_ARG, 1, \ - VM_OC_INITIALIZER_PUSH_NAME | VM_OC_GET_LITERAL) \ - \ - /* Executable object related opcodes. */ \ - CBC_OPCODE (CBC_EXT_CREATE_GENERATOR, CBC_NO_FLAG, 1, \ - VM_OC_CREATE_GENERATOR) \ - CBC_OPCODE (CBC_EXT_YIELD, CBC_NO_FLAG, 0, \ - VM_OC_YIELD) \ - CBC_OPCODE (CBC_EXT_YIELD_ITERATOR, CBC_NO_FLAG, 0, \ - VM_OC_YIELD) \ - CBC_OPCODE (CBC_EXT_ASYNC_YIELD, CBC_NO_FLAG, 0, \ - VM_OC_ASYNC_YIELD) \ - CBC_OPCODE (CBC_EXT_ASYNC_YIELD_ITERATOR, CBC_NO_FLAG, 0, \ - VM_OC_ASYNC_YIELD_ITERATOR) \ - CBC_OPCODE (CBC_EXT_AWAIT, CBC_NO_FLAG, 0, \ - VM_OC_AWAIT) \ - CBC_OPCODE (CBC_EXT_GENERATOR_AWAIT, CBC_NO_FLAG, 0, \ - VM_OC_GENERATOR_AWAIT) \ - CBC_OPCODE (CBC_EXT_ASYNC_EXIT, CBC_NO_FLAG, 0, \ - VM_OC_ASYNC_EXIT) \ - CBC_OPCODE (CBC_EXT_RETURN, CBC_NO_FLAG, -1, \ - VM_OC_EXT_RETURN | VM_OC_GET_STACK) \ - CBC_OPCODE (CBC_EXT_RETURN_UNDEFINED, CBC_NO_FLAG, 0, \ - VM_OC_EXT_RETURN) \ - CBC_OPCODE (CBC_EXT_PUSH_NEW_TARGET, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_NEW_TARGET | VM_OC_PUT_STACK) \ - \ - /* Last opcode (not a real opcode). */ \ - CBC_OPCODE (CBC_EXT_END, CBC_NO_FLAG, 0, \ - VM_OC_NONE) - -#define CBC_MAXIMUM_BYTE_VALUE 255 +#define CBC_EXT_OPCODE_LIST \ + /* Branch opcodes first. Some other opcodes are mixed. */ \ + CBC_OPCODE (CBC_EXT_NOP, CBC_NO_FLAG, 0, VM_OC_NONE) \ + CBC_FORWARD_BRANCH (CBC_EXT_WITH_CREATE_CONTEXT, -1 + PARSER_WITH_CONTEXT_STACK_ALLOCATION, VM_OC_WITH) \ + CBC_OPCODE (CBC_EXT_FOR_IN_GET_NEXT, CBC_NO_FLAG, 1, VM_OC_FOR_IN_GET_NEXT | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_EXT_FOR_IN_INIT, -1 + PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_IN_INIT) \ + CBC_OPCODE (CBC_EXT_SET_GETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ + CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_IN_HAS_NEXT, 0, VM_OC_FOR_IN_HAS_NEXT) \ + CBC_OPCODE (CBC_EXT_FOR_OF_GET_NEXT, CBC_NO_FLAG, 1, VM_OC_FOR_OF_GET_NEXT | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_EXT_FOR_OF_INIT, -1 + PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_OF_INIT) \ + CBC_OPCODE (CBC_EXT_PUSH_NAMED_FUNC_EXPRESSION, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_PUSH_NAMED_FUNC_EXPR | VM_OC_GET_LITERAL_LITERAL) \ + CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_OF_HAS_NEXT, 0, VM_OC_FOR_OF_HAS_NEXT) \ + CBC_OPCODE (CBC_EXT_CLONE_CONTEXT, CBC_NO_FLAG, 0, VM_OC_CLONE_CONTEXT) \ + CBC_FORWARD_BRANCH (CBC_EXT_FOR_AWAIT_OF_INIT, \ + -1 + PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION, \ + VM_OC_FOR_AWAIT_OF_INIT) \ + CBC_OPCODE (CBC_EXT_CLONE_FULL_CONTEXT, CBC_NO_FLAG, 0, VM_OC_CLONE_CONTEXT) \ + CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_AWAIT_OF_HAS_NEXT, 0, VM_OC_FOR_AWAIT_OF_HAS_NEXT) \ + CBC_OPCODE (CBC_EXT_SET_SETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ + CBC_FORWARD_BRANCH (CBC_EXT_TRY_CREATE_CONTEXT, PARSER_TRY_CONTEXT_STACK_ALLOCATION, VM_OC_TRY) \ + CBC_OPCODE (CBC_EXT_TRY_CREATE_ENV, CBC_NO_FLAG, 0, VM_OC_BLOCK_CREATE_CONTEXT) \ + CBC_FORWARD_BRANCH (CBC_EXT_CATCH, 1, VM_OC_CATCH) \ + CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, VM_OC_RESOLVE_BASE_FOR_CALL) \ + CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION, VM_OC_FINALLY) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP, CBC_NO_FLAG, 0, VM_OC_INITIALIZER_PUSH_PROP) \ + CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, VM_OC_DEFAULT_INITIALIZER) \ + CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, VM_OC_ERROR) \ + CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_IF_NULLISH, -1, VM_OC_BRANCH_IF_NULLISH) \ + \ + /* Basic opcodes. */ \ + CBC_OPCODE (CBC_EXT_CREATE_ARGUMENTS, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_ARGUMENTS) \ + CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_EXT_VAR_EVAL) \ + CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_EXT_VAR_EVAL) \ + CBC_OPCODE (CBC_EXT_COPY_FROM_ARG, CBC_HAS_LITERAL_ARG, 0, VM_OC_COPY_FROM_ARG) \ + CBC_OPCODE (CBC_EXT_PUSH_REST_OBJECT, CBC_NO_FLAG, 1, VM_OC_PUSH_REST_OBJECT) \ + CBC_OPCODE (CBC_EXT_MODULE_IMPORT, CBC_NO_FLAG, 0, VM_OC_MODULE_IMPORT) \ + CBC_OPCODE (CBC_EXT_MODULE_IMPORT_META, CBC_NO_FLAG, 1, VM_OC_MODULE_IMPORT_META) \ + CBC_OPCODE (CBC_EXT_STRING_CONCAT, CBC_NO_FLAG, -1, VM_OC_STRING_CONCAT | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_STRING_CONCAT | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_STRING_CONCAT_TWO_LITERALS, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_STRING_CONCAT | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_GET_TAGGED_TEMPLATE_LITERAL, CBC_HAS_BYTE_ARG, 1, VM_OC_GET_TEMPLATE_OBJECT | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, VM_OC_THROW_REFERENCE_ERROR) \ + CBC_OPCODE (CBC_EXT_THROW_ASSIGN_CONST_ERROR, CBC_NO_FLAG, 0, VM_OC_THROW_CONST_ERROR) \ + CBC_OPCODE (CBC_EXT_REQUIRE_OBJECT_COERCIBLE, CBC_NO_FLAG, 0, VM_OC_REQUIRE_OBJECT_COERCIBLE) \ + CBC_OPCODE (CBC_EXT_COPY_DATA_PROPERTIES, CBC_NO_FLAG, -1, VM_OC_COPY_DATA_PROPERTIES) \ + CBC_OPCODE (CBC_EXT_SET_FUNCTION_NAME, CBC_HAS_LITERAL_ARG, 0, VM_OC_SET_FUNCTION_NAME | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_CLASS_NAME, CBC_HAS_LITERAL_ARG, 0, VM_OC_SET_FUNCTION_NAME) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_FUNCTION_NAME, CBC_NO_FLAG, 0, VM_OC_SET_FUNCTION_NAME) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER_NAME, CBC_NO_FLAG, 0, VM_OC_SET_FUNCTION_NAME) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER_NAME, CBC_NO_FLAG, 0, VM_OC_SET_FUNCTION_NAME) \ + \ + /* Computed / class property related opcodes. */ \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY, CBC_HAS_LITERAL_ARG, -1, VM_OC_SET_PROPERTY | VM_OC_GET_STACK_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY_LITERAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_PROPERTY, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_COMPUTED_PROPERTY | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_GETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_GETTER | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_SETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_SETTER | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_GETTER, CBC_NO_FLAG, -2, VM_OC_SET_GETTER | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_SETTER, CBC_NO_FLAG, -2, VM_OC_SET_SETTER | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET__PROTO__, CBC_NO_FLAG, -1, VM_OC_SET__PROTO__ | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_STATIC_FIELD_FUNC, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_ADD_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_ADD_STATIC_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \ + \ + /* Class related opcodes. */ \ + CBC_OPCODE (CBC_EXT_PUSH_NAMED_CLASS_ENV, CBC_HAS_LITERAL_ARG, 1, VM_OC_PUSH_CLASS_ENVIRONMENT) \ + CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR, CBC_NO_FLAG, 1, VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE, CBC_NO_FLAG, 1, VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_INIT_CLASS, CBC_NO_FLAG, 0, VM_OC_INIT_CLASS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_FINALIZE_NAMED_CLASS, CBC_HAS_LITERAL_ARG, -2, VM_OC_FINALIZE_CLASS) \ + CBC_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS, CBC_NO_FLAG, -2, VM_OC_FINALIZE_CLASS) \ + CBC_OPCODE (CBC_EXT_SET_FIELD_INIT, CBC_HAS_LITERAL_ARG, 0, VM_OC_SET_FIELD_INIT | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_RUN_FIELD_INIT, CBC_NO_FLAG, 0, VM_OC_RUN_FIELD_INIT) \ + CBC_OPCODE (CBC_EXT_RUN_STATIC_FIELD_INIT, CBC_NO_FLAG, -1, VM_OC_RUN_STATIC_FIELD_INIT) \ + CBC_OPCODE (CBC_EXT_SET_NEXT_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_SET_NEXT_COMPUTED_FIELD | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER, CBC_NO_FLAG, 1, VM_OC_NONE) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR, CBC_NO_FLAG, 1, VM_OC_PUSH_SUPER_CONSTRUCTOR) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP, CBC_NO_FLAG, 0, VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE, CBC_NO_FLAG, 2, VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE, CBC_NO_FLAG, 1, VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 2, \ + VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT, CBC_NO_FLAG, 0, VM_OC_SET_HOME_OBJECT) \ + CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED, CBC_NO_FLAG, 0, VM_OC_SET_HOME_OBJECT) \ + CBC_OPCODE (CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, 1, VM_OC_OBJECT_LITERAL_HOME_ENV) \ + CBC_OPCODE (CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, -1, VM_OC_OBJECT_LITERAL_HOME_ENV) \ + CBC_OPCODE (CBC_EXT_RESOLVE_LEXICAL_THIS, CBC_NO_FLAG, 1, VM_OC_RESOLVE_LEXICAL_THIS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_LOCAL_EVAL, CBC_HAS_BYTE_ARG, 0, VM_OC_LOCAL_EVAL) \ + CBC_OPCODE (CBC_EXT_ASSIGN_SUPER, CBC_NO_FLAG, -3, VM_OC_ASSIGN_SUPER) \ + CBC_OPCODE (CBC_EXT_ASSIGN_SUPER_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_ASSIGN_SUPER | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_ASSIGN_SUPER_BLOCK, CBC_NO_FLAG, -3, VM_OC_ASSIGN_SUPER | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL) \ + CBC_OPCODE (CBC_EXT_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL) \ + CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_PUSH_RESULT, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + 0, \ + VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \ + \ + /* Spread / rest operation related opcodes. */ \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SPREAD_ARGUMENTS) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PUSH_RESULT, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + 0, \ + VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, VM_OC_SPREAD_ARGUMENTS) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_PUSH_RESULT, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + -2, \ + VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + -3, \ + VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_PUSH_SPREAD_ELEMENT, CBC_NO_FLAG, 1, VM_OC_PUSH_SPREAD_ELEMENT) \ + CBC_OPCODE (CBC_EXT_SPREAD_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_APPEND_ARRAY) \ + CBC_OPCODE (CBC_EXT_REST_INITIALIZER, CBC_NO_FLAG, 1, VM_OC_REST_INITIALIZER) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SPREAD_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ + \ + /* Iterator related opcodes. */ \ + CBC_OPCODE (CBC_EXT_ITERATOR_CONTEXT_CREATE, \ + CBC_NO_FLAG, \ + PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION, \ + VM_OC_ITERATOR_CONTEXT_CREATE) \ + CBC_OPCODE (CBC_EXT_ITERATOR_CONTEXT_END, \ + CBC_NO_FLAG, \ + -PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION, \ + VM_OC_ITERATOR_CONTEXT_END) \ + CBC_OPCODE (CBC_EXT_ITERATOR_STEP, CBC_NO_FLAG, 1, VM_OC_ITERATOR_STEP) \ + \ + /* Object initializer related opcodes. */ \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_CONTEXT_CREATE, \ + CBC_NO_FLAG, \ + PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION, \ + VM_OC_OBJ_INIT_CONTEXT_CREATE) \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_REST_CONTEXT_CREATE, \ + CBC_NO_FLAG, \ + PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION, \ + VM_OC_OBJ_INIT_CONTEXT_CREATE) \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_PUSH_REST, CBC_NO_FLAG, 1, VM_OC_OBJ_INIT_PUSH_REST) \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_CONTEXT_END, \ + CBC_NO_FLAG, \ + -PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION, \ + VM_OC_OBJ_INIT_CONTEXT_END) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_NAME, CBC_NO_FLAG, 0, VM_OC_INITIALIZER_PUSH_NAME | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_NAME_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_INITIALIZER_PUSH_NAME | VM_OC_GET_LITERAL) \ + \ + /* Executable object related opcodes. */ \ + CBC_OPCODE (CBC_EXT_CREATE_GENERATOR, CBC_NO_FLAG, 1, VM_OC_CREATE_GENERATOR) \ + CBC_OPCODE (CBC_EXT_YIELD, CBC_NO_FLAG, 0, VM_OC_YIELD) \ + CBC_OPCODE (CBC_EXT_YIELD_ITERATOR, CBC_NO_FLAG, 0, VM_OC_YIELD) \ + CBC_OPCODE (CBC_EXT_ASYNC_YIELD, CBC_NO_FLAG, 0, VM_OC_ASYNC_YIELD) \ + CBC_OPCODE (CBC_EXT_ASYNC_YIELD_ITERATOR, CBC_NO_FLAG, 0, VM_OC_ASYNC_YIELD_ITERATOR) \ + CBC_OPCODE (CBC_EXT_AWAIT, CBC_NO_FLAG, 0, VM_OC_AWAIT) \ + CBC_OPCODE (CBC_EXT_GENERATOR_AWAIT, CBC_NO_FLAG, 0, VM_OC_GENERATOR_AWAIT) \ + CBC_OPCODE (CBC_EXT_ASYNC_EXIT, CBC_NO_FLAG, 0, VM_OC_ASYNC_EXIT) \ + CBC_OPCODE (CBC_EXT_RETURN, CBC_NO_FLAG, -1, VM_OC_EXT_RETURN | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_RETURN_UNDEFINED, CBC_NO_FLAG, 0, VM_OC_EXT_RETURN) \ + CBC_OPCODE (CBC_EXT_PUSH_NEW_TARGET, CBC_NO_FLAG, 1, VM_OC_PUSH_NEW_TARGET | VM_OC_PUT_STACK) \ + \ + /* Last opcode (not a real opcode). */ \ + CBC_OPCODE (CBC_EXT_END, CBC_NO_FLAG, 0, VM_OC_NONE) + +#define CBC_MAXIMUM_BYTE_VALUE 255 #define CBC_MAXIMUM_SMALL_VALUE 510 -#define CBC_MAXIMUM_FULL_VALUE 32767 +#define CBC_MAXIMUM_FULL_VALUE 32767 #define CBC_PUSH_NUMBER_BYTE_RANGE_END 256 -#define CBC_HIGHEST_BIT_MASK 0x80 +#define CBC_HIGHEST_BIT_MASK 0x80 #define CBC_LOWER_SEVEN_BIT_MASK 0x7f /** @@ -849,14 +736,14 @@ */ typedef struct { - ecma_compiled_code_t header; /**< compiled code header */ - uint8_t stack_limit; /**< maximum number of values stored on the stack */ - uint8_t argument_end; /**< number of arguments expected by the function */ - ecma_value_t script_value; /**< script value */ - uint8_t register_end; /**< end position of the register group */ - uint8_t ident_end; /**< end position of the identifier group */ - uint8_t const_literal_end; /**< end position of the const literal group */ - uint8_t literal_end; /**< end position of the literal group */ + ecma_compiled_code_t header; /**< compiled code header */ + uint8_t stack_limit; /**< maximum number of values stored on the stack */ + uint8_t argument_end; /**< number of arguments expected by the function */ + ecma_value_t script_value; /**< script value */ + uint8_t register_end; /**< end position of the register group */ + uint8_t ident_end; /**< end position of the identifier group */ + uint8_t const_literal_end; /**< end position of the const literal group */ + uint8_t literal_end; /**< end position of the literal group */ } cbc_uint8_arguments_t; /** @@ -864,15 +751,15 @@ typedef struct */ typedef struct { - ecma_compiled_code_t header; /**< compiled code header */ - uint16_t stack_limit; /**< maximum number of values stored on the stack */ - ecma_value_t script_value; /**< script value */ - uint16_t argument_end; /**< number of arguments expected by the function */ - uint16_t register_end; /**< end position of the register group */ - uint16_t ident_end; /**< end position of the identifier group */ - uint16_t const_literal_end; /**< end position of the const literal group */ - uint16_t literal_end; /**< end position of the literal group */ - uint16_t padding; /**< an unused value */ + ecma_compiled_code_t header; /**< compiled code header */ + uint16_t stack_limit; /**< maximum number of values stored on the stack */ + ecma_value_t script_value; /**< script value */ + uint16_t argument_end; /**< number of arguments expected by the function */ + uint16_t register_end; /**< end position of the register group */ + uint16_t ident_end; /**< end position of the identifier group */ + uint16_t const_literal_end; /**< end position of the const literal group */ + uint16_t literal_end; /**< end position of the literal group */ + uint16_t padding; /**< an unused value */ } cbc_uint16_arguments_t; /** @@ -951,38 +838,32 @@ typedef enum /** * Compute function type bits in code flags. */ -#define CBC_FUNCTION_TO_TYPE_BITS(name) \ - ((name) << CBC_FUNCTION_TYPE_SHIFT) +#define CBC_FUNCTION_TO_TYPE_BITS(name) ((name) << CBC_FUNCTION_TYPE_SHIFT) /** * Get function type from code flags. */ -#define CBC_FUNCTION_GET_TYPE(flags) \ - ((uint16_t) ((flags) >> CBC_FUNCTION_TYPE_SHIFT)) +#define CBC_FUNCTION_GET_TYPE(flags) ((uint16_t) ((flags) >> CBC_FUNCTION_TYPE_SHIFT)) /** * Checks whether the byte code is a function or a regular expression. */ -#define CBC_IS_FUNCTION(flags) \ - ((flags) >= (CBC_FUNCTION_NORMAL << CBC_FUNCTION_TYPE_SHIFT)) +#define CBC_IS_FUNCTION(flags) ((flags) >= (CBC_FUNCTION_NORMAL << CBC_FUNCTION_TYPE_SHIFT)) /** * Checks whether the function can be constructed with new operator. */ -#define CBC_FUNCTION_IS_CONSTRUCTABLE(flags) \ - ((flags) < (CBC_FUNCTION_GENERATOR << CBC_FUNCTION_TYPE_SHIFT)) +#define CBC_FUNCTION_IS_CONSTRUCTABLE(flags) ((flags) < (CBC_FUNCTION_GENERATOR << CBC_FUNCTION_TYPE_SHIFT)) /** * Checks whether the function has prototype property. */ -#define CBC_FUNCTION_HAS_PROTOTYPE(flags) \ - ((flags) < (CBC_FUNCTION_ACCESSOR << CBC_FUNCTION_TYPE_SHIFT)) +#define CBC_FUNCTION_HAS_PROTOTYPE(flags) ((flags) < (CBC_FUNCTION_ACCESSOR << CBC_FUNCTION_TYPE_SHIFT)) /** * Checks whether the function is an arrow function. */ -#define CBC_FUNCTION_IS_ARROW(flags) \ - ((flags) >= (CBC_FUNCTION_ARROW << CBC_FUNCTION_TYPE_SHIFT)) +#define CBC_FUNCTION_IS_ARROW(flags) ((flags) >= (CBC_FUNCTION_ARROW << CBC_FUNCTION_TYPE_SHIFT)) /** * Compact byte code extended status flags. @@ -1020,20 +901,19 @@ typedef enum /** * Sets the type of a script using the user_value. */ -#define CBC_SCRIPT_SET_TYPE(script_p, user_value, ref_count) \ - do \ - { \ - (script_p)->refs_and_type = (ref_count); \ - if ((user_value) != ECMA_VALUE_EMPTY) \ - { \ - (script_p)->refs_and_type |= CBC_SCRIPT_HAS_USER_VALUE; \ - if (ecma_is_value_object (user_value)) \ - { \ +#define CBC_SCRIPT_SET_TYPE(script_p, user_value, ref_count) \ + do \ + { \ + (script_p)->refs_and_type = (ref_count); \ + if ((user_value) != ECMA_VALUE_EMPTY) \ + { \ + (script_p)->refs_and_type |= CBC_SCRIPT_HAS_USER_VALUE; \ + if (ecma_is_value_object (user_value)) \ + { \ (script_p)->refs_and_type |= CBC_SCRIPT_USER_VALUE_IS_OBJECT; \ - } \ - } \ - } \ - while (false) + } \ + } \ + } while (false) /** * Shared script data. @@ -1063,20 +943,19 @@ typedef struct /** * Get user value. */ -#define CBC_SCRIPT_GET_USER_VALUE(script_p) \ - (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[0]) +#define CBC_SCRIPT_GET_USER_VALUE(script_p) (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[0]) /** * Get function arguments. */ #define CBC_SCRIPT_GET_FUNCTION_ARGUMENTS(script_p, type) \ - (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[((type) & CBC_SCRIPT_HAS_USER_VALUE) ? 1 : 0]) + (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[((type) &CBC_SCRIPT_HAS_USER_VALUE) ? 1 : 0]) /** * Get import.meta object. */ #define CBC_SCRIPT_GET_IMPORT_META(script_p, type) \ - (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[((type) & CBC_SCRIPT_HAS_USER_VALUE) ? 1 : 0]) + (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[((type) &CBC_SCRIPT_HAS_USER_VALUE) ? 1 : 0]) #define CBC_OPCODE(arg1, arg2, arg3, arg4) arg1, @@ -1085,7 +964,7 @@ typedef struct */ typedef enum { - CBC_OPCODE_LIST /**< list of opcodes */ + CBC_OPCODE_LIST /**< list of opcodes */ } cbc_opcode_t; /** @@ -1093,7 +972,7 @@ typedef enum */ typedef enum { - CBC_EXT_OPCODE_LIST /**< list extended opcodes */ + CBC_EXT_OPCODE_LIST /**< list extended opcodes */ } cbc_ext_opcode_t; #undef CBC_OPCODE @@ -1109,8 +988,8 @@ extern const uint8_t cbc_ext_flags[]; /** * Opcode names for debugging. */ -extern const char * const cbc_names[]; -extern const char * const cbc_ext_names[]; +extern const char *const cbc_names[]; +extern const char *const cbc_ext_names[]; #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ diff --git a/jerry-core/parser/js/common.c b/jerry-core/parser/js/common.c index cf241a12..53b0a7f1 100644 --- a/jerry-core/parser/js/common.c +++ b/jerry-core/parser/js/common.c @@ -14,10 +14,12 @@ */ #include "common.h" -#include "ecma-helpers.h" -#include "ecma-extended-info.h" + #include "ecma-big-uint.h" #include "ecma-bigint.h" +#include "ecma-extended-info.h" +#include "ecma-helpers.h" + #include "js-parser-internal.h" #include "lit-char-helpers.h" @@ -39,16 +41,14 @@ void util_free_literal (lexer_literal_t *literal_p) /**< literal */ { - if (literal_p->type == LEXER_IDENT_LITERAL - || literal_p->type == LEXER_STRING_LITERAL) + if (literal_p->type == LEXER_IDENT_LITERAL || literal_p->type == LEXER_STRING_LITERAL) { if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR)) { jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length); } } - else if ((literal_p->type == LEXER_FUNCTION_LITERAL) - || (literal_p->type == LEXER_REGEXP_LITERAL)) + else if ((literal_p->type == LEXER_FUNCTION_LITERAL) || (literal_p->type == LEXER_REGEXP_LITERAL)) { ecma_bytecode_deref (literal_p->u.bytecode_p); } @@ -262,12 +262,12 @@ util_print_literal_value (ecma_compiled_code_t *compiled_code_p, /**< compiled c JERRY_DEBUG_MSG (")"); } /* util_print_literal_value */ -#define PARSER_READ_IDENTIFIER_INDEX(name) \ - name = *byte_code_p++; \ - if (name >= encoding_limit) \ - { \ +#define PARSER_READ_IDENTIFIER_INDEX(name) \ + name = *byte_code_p++; \ + if (name >= encoding_limit) \ + { \ name = (uint16_t) (((name << 8) | byte_code_p[0]) - encoding_delta); \ - byte_code_p++; \ + byte_code_p++; \ } /** @@ -311,8 +311,7 @@ util_print_cbc (ecma_compiled_code_t *compiled_code_p) /**< compiled code */ literal_end = args->literal_end; } - JERRY_DEBUG_MSG ("\nByte code dump:\n\n Maximum stack depth: %d\n Flags: [", - (int) (stack_limit + register_end)); + JERRY_DEBUG_MSG ("\nByte code dump:\n\n Maximum stack depth: %d\n Flags: [", (int) (stack_limit + register_end)); if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING)) { @@ -509,13 +508,11 @@ util_print_cbc (ecma_compiled_code_t *compiled_code_p) /**< compiled code */ if (flags & CBC_HAS_BYTE_ARG) { - if (opcode == CBC_PUSH_NUMBER_POS_BYTE - || opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) + if (opcode == CBC_PUSH_NUMBER_POS_BYTE || opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) { JERRY_DEBUG_MSG (" number:%d", (int) *byte_code_p + 1); } - else if (opcode == CBC_PUSH_NUMBER_NEG_BYTE - || opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) + else if (opcode == CBC_PUSH_NUMBER_NEG_BYTE || opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) { JERRY_DEBUG_MSG (" number:%d", -((int) *byte_code_p + 1)); } @@ -528,15 +525,14 @@ util_print_cbc (ecma_compiled_code_t *compiled_code_p) /**< compiled code */ if (flags & CBC_HAS_BRANCH_ARG) { - size_t branch_offset_length = (opcode != CBC_EXT_OPCODE ? CBC_BRANCH_OFFSET_LENGTH (opcode) - : CBC_BRANCH_OFFSET_LENGTH (ext_opcode)); + size_t branch_offset_length = + (opcode != CBC_EXT_OPCODE ? CBC_BRANCH_OFFSET_LENGTH (opcode) : CBC_BRANCH_OFFSET_LENGTH (ext_opcode)); size_t offset = 0; do { offset = (offset << 8) | *byte_code_p++; - } - while (--branch_offset_length > 0); + } while (--branch_offset_length > 0); JERRY_DEBUG_MSG (" offset:%d(->%d)", (int) offset, diff --git a/jerry-core/parser/js/common.h b/jerry-core/parser/js/common.h index 05775f04..00f3b6ed 100644 --- a/jerry-core/parser/js/common.h +++ b/jerry-core/parser/js/common.h @@ -16,11 +16,11 @@ #ifndef COMMON_H #define COMMON_H +#include <inttypes.h> +#include <setjmp.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <inttypes.h> -#include <setjmp.h> /** \addtogroup parser Parser * @{ @@ -32,9 +32,10 @@ * @{ */ -#include "config.h" #include "ecma-globals.h" #include "ecma-regexp-object.h" + +#include "config.h" #include "jmem.h" /* Immediate management. */ @@ -48,15 +49,15 @@ typedef enum { /* The LEXER_IS_IDENT_OR_STRING macro must be updated if the order is changed. */ - LEXER_IDENT_LITERAL = 0, /**< identifier literal */ - LEXER_STRING_LITERAL = 1, /**< string literal */ - LEXER_NUMBER_LITERAL = 2, /**< number literal */ - LEXER_FUNCTION_LITERAL = 3, /**< function literal */ - LEXER_REGEXP_LITERAL = 4, /**< regexp literal */ - LEXER_UNUSED_LITERAL = 5, /**< unused literal, can only be - used by the byte code generator. */ - LEXER_NEW_IDENT_LITERAL = 6, /**< new local variable, can only be - used by the byte code generator. */ + LEXER_IDENT_LITERAL = 0, /**< identifier literal */ + LEXER_STRING_LITERAL = 1, /**< string literal */ + LEXER_NUMBER_LITERAL = 2, /**< number literal */ + LEXER_FUNCTION_LITERAL = 3, /**< function literal */ + LEXER_REGEXP_LITERAL = 4, /**< regexp literal */ + LEXER_UNUSED_LITERAL = 5, /**< unused literal, can only be + used by the byte code generator. */ + LEXER_NEW_IDENT_LITERAL = 6, /**< new local variable, can only be + used by the byte code generator. */ } lexer_literal_type_t; /** @@ -96,10 +97,10 @@ typedef struct { union { - ecma_value_t value; /**< literal value (not processed by the parser) */ - const uint8_t *char_p; /**< character value */ - ecma_compiled_code_t *bytecode_p; /**< compiled function or regexp pointer */ - uint32_t source_data; /**< encoded source literal */ + ecma_value_t value; /**< literal value (not processed by the parser) */ + const uint8_t *char_p; /**< character value */ + ecma_compiled_code_t *bytecode_p; /**< compiled function or regexp pointer */ + uint32_t source_data; /**< encoded source literal */ } u; #if JERRY_PARSER_DUMP_BYTE_CODE @@ -108,12 +109,12 @@ typedef struct union #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ { - prop_length_t length; /**< length of ident / string literal */ - uint16_t index; /**< real index during post processing */ + prop_length_t length; /**< length of ident / string literal */ + uint16_t index; /**< real index during post processing */ } prop; - uint8_t type; /**< type of the literal */ - uint8_t status_flags; /**< status flags */ + uint8_t type; /**< type of the literal */ + uint8_t status_flags; /**< status flags */ } lexer_literal_t; void util_free_literal (lexer_literal_t *literal_p); @@ -122,26 +123,36 @@ void util_free_literal (lexer_literal_t *literal_p); void util_print_literal (lexer_literal_t *); #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ +/** + * Source code line counter type. + */ +typedef uint32_t parser_line_counter_t; + +/** + * Source code as character data. + */ +typedef struct +{ + const uint8_t *source_p; /**< valid UTF-8 source code */ + size_t source_size; /**< size of the source code */ +} parser_source_char_t; + /* TRY/CATCH block */ -#define PARSER_TRY_CONTEXT(context_name) \ - jmp_buf context_name +#define PARSER_TRY_CONTEXT(context_name) jmp_buf context_name -#define PARSER_THROW(context_name) \ - longjmp (context_name, 1); +#define PARSER_THROW(context_name) longjmp (context_name, 1); #define PARSER_TRY(context_name) \ - { \ - if (!setjmp (context_name)) \ - { \ - -#define PARSER_CATCH \ - } \ - else \ + { \ + if (!setjmp (context_name)) \ { - +#define PARSER_CATCH \ + } \ + else \ + { #define PARSER_TRY_END \ - } \ + } \ } /** diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index e0c7220b..b38c19d3 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -15,12 +15,13 @@ #include "ecma-alloc.h" #include "ecma-bigint.h" -#include "ecma-helpers.h" #include "ecma-function-object.h" +#include "ecma-helpers.h" #include "ecma-literal-storage.h" + +#include "jcontext.h" #include "js-parser-internal.h" #include "lit-char-helpers.h" -#include "jcontext.h" #if JERRY_PARSER @@ -40,7 +41,7 @@ JERRY_STATIC_ASSERT (LEXER_NUMBER_BINARY > LEXER_NUMBER_OCTAL, /** * Check whether the UTF-8 intermediate is an octet or not */ -#define IS_UTF8_INTERMEDIATE_OCTET(byte) (((byte) & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_2_BYTE_CODE_POINT_MIN) +#define IS_UTF8_INTERMEDIATE_OCTET(byte) (((byte) &LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_2_BYTE_CODE_POINT_MIN) /** * Align column to the next tab position. @@ -87,8 +88,7 @@ lexer_hex_to_code_point (const uint8_t *source_p, /**< current source position * return UINT32_MAX; } } - } - while (--length > 0); + } while (--length > 0); return result; } /* lexer_hex_to_code_point */ @@ -140,8 +140,7 @@ lexer_hex_in_braces_to_code_point (const uint8_t *source_p, /**< current source return UINT32_MAX; } length++; - } - while (*source_p != LIT_CHAR_RIGHT_BRACE); + } while (*source_p != LIT_CHAR_RIGHT_BRACE); *length_p = length; return result; @@ -214,9 +213,9 @@ lexer_unchecked_hex_to_character (const uint8_t **source_p) /**< [in, out] curre */ typedef enum { - LEXER_SKIP_SPACES, /**< skip spaces mode */ - LEXER_SKIP_SINGLE_LINE_COMMENT, /**< parse single line comment */ - LEXER_SKIP_MULTI_LINE_COMMENT, /**< parse multi line comment */ + LEXER_SKIP_SPACES, /**< skip spaces mode */ + LEXER_SKIP_SINGLE_LINE_COMMENT, /**< parse single line comment */ + LEXER_SKIP_MULTI_LINE_COMMENT, /**< parse multi line comment */ } skip_mode_t; /** @@ -251,8 +250,7 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */ { case LIT_CHAR_CR: { - if (context_p->source_p + 1 < source_end_p - && context_p->source_p[1] == LIT_CHAR_LF) + if (context_p->source_p + 1 < source_end_p && context_p->source_p[1] == LIT_CHAR_LF) { context_p->source_p++; } @@ -290,8 +288,7 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */ case LIT_CHAR_SLASH: { - if (mode == LEXER_SKIP_SPACES - && context_p->source_p + 1 < source_end_p) + if (mode == LEXER_SKIP_SPACES && context_p->source_p + 1 < source_end_p) { if (context_p->source_p[1] == LIT_CHAR_SLASH) { @@ -316,8 +313,7 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */ case LIT_CHAR_ASTERISK: { - if (mode == LEXER_SKIP_MULTI_LINE_COMMENT - && context_p->source_p + 1 < source_end_p + if (mode == LEXER_SKIP_MULTI_LINE_COMMENT && context_p->source_p + 1 < source_end_p && context_p->source_p[1] == LIT_CHAR_SLASH) { mode = LEXER_SKIP_SPACES; @@ -330,8 +326,7 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */ case 0xc2: { - if (context_p->source_p + 1 < source_end_p - && context_p->source_p[1] == 0xa0) + if (context_p->source_p + 1 < source_end_p && context_p->source_p[1] == 0xa0) { /* Codepoint \u00A0 */ context_p->source_p += 2; @@ -363,9 +358,7 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */ case 0xef: { - if (context_p->source_p + 2 < source_end_p - && context_p->source_p[1] == 0xbb - && context_p->source_p[2] == 0xbf) + if (context_p->source_p + 2 < source_end_p && context_p->source_p[1] == 0xbb && context_p->source_p[2] == 0xbf) { /* Codepoint \uFEFF */ context_p->source_p += 3; @@ -388,8 +381,7 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */ context_p->source_p++; - if (context_p->source_p < source_end_p - && !IS_UTF8_INTERMEDIATE_OCTET (context_p->source_p[0])) + if (context_p->source_p < source_end_p && !IS_UTF8_INTERMEDIATE_OCTET (context_p->source_p[0])) { context_p->column++; } @@ -406,8 +398,7 @@ lexer_skip_empty_statements (parser_context_t *context_p) /**< context */ { lexer_skip_spaces (context_p); - while (context_p->source_p < context_p->source_end_p - && *context_p->source_p == LIT_CHAR_SEMICOLON) + while (context_p->source_p < context_p->source_end_p && *context_p->source_p == LIT_CHAR_SEMICOLON) { lexer_consume_next_character (context_p); lexer_skip_spaces (context_p); @@ -423,14 +414,13 @@ lexer_skip_empty_statements (parser_context_t *context_p) /**< context */ * Checks whether the keyword has escape sequences. */ #define LEXER_CHECK_INVALID_KEYWORD(ident_start_p, buffer_p) \ - (JERRY_UNLIKELY ((ident_start_p) == (buffer_p)) \ + (JERRY_UNLIKELY ((ident_start_p) == (buffer_p)) \ && !(context_p->global_status_flags & ECMA_PARSE_INTERNAL_PRE_SCANNING)) -#else /* !JERRY_ESNEXT */ +#else /* !JERRY_ESNEXT */ /** * Checks whether the keyword has escape sequences. */ -#define LEXER_CHECK_INVALID_KEYWORD(ident_start_p, buffer_p) \ - (JERRY_UNLIKELY ((ident_start_p) == (buffer_p))) +#define LEXER_CHECK_INVALID_KEYWORD(ident_start_p, buffer_p) (JERRY_UNLIKELY ((ident_start_p) == (buffer_p))) #endif /* JERRY_ESNEXT */ /** @@ -439,14 +429,17 @@ lexer_skip_empty_statements (parser_context_t *context_p) /**< context */ typedef struct { const uint8_t *keyword_p; /**< keyword string */ - lexer_token_type_t type; /**< keyword token type */ + lexer_token_type_t type; /**< keyword token type */ } keyword_string_t; /** * @{ * Keyword defines */ -#define LEXER_KEYWORD(name, type) { (const uint8_t *) (name), (type) } +#define LEXER_KEYWORD(name, type) \ + { \ + (const uint8_t *) (name), (type) \ + } #define LEXER_KEYWORD_LIST_LENGTH(name) (const uint8_t) (sizeof ((name)) / sizeof ((name)[0])) /** @} */ @@ -463,8 +456,7 @@ typedef struct /** * Keywords with 2 characters. */ -static const keyword_string_t keywords_with_length_2[] = -{ +static const keyword_string_t keywords_with_length_2[] = { LEXER_KEYWORD ("do", LEXER_KEYW_DO), LEXER_KEYWORD ("if", LEXER_KEYW_IF), LEXER_KEYWORD ("in", LEXER_KEYW_IN), @@ -473,86 +465,62 @@ static const keyword_string_t keywords_with_length_2[] = /** * Keywords with 3 characters. */ -static const keyword_string_t keywords_with_length_3[] = -{ - LEXER_KEYWORD ("for", LEXER_KEYW_FOR), - LEXER_KEYWORD ("let", LEXER_KEYW_LET), - LEXER_KEYWORD ("new", LEXER_KEYW_NEW), - LEXER_KEYWORD ("try", LEXER_KEYW_TRY), - LEXER_KEYWORD ("var", LEXER_KEYW_VAR), +static const keyword_string_t keywords_with_length_3[] = { + LEXER_KEYWORD ("for", LEXER_KEYW_FOR), LEXER_KEYWORD ("let", LEXER_KEYW_LET), LEXER_KEYWORD ("new", LEXER_KEYW_NEW), + LEXER_KEYWORD ("try", LEXER_KEYW_TRY), LEXER_KEYWORD ("var", LEXER_KEYW_VAR), }; /** * Keywords with 4 characters. */ -static const keyword_string_t keywords_with_length_4[] = -{ - LEXER_KEYWORD ("case", LEXER_KEYW_CASE), - LEXER_KEYWORD ("else", LEXER_KEYW_ELSE), - LEXER_KEYWORD ("enum", LEXER_KEYW_ENUM), - LEXER_KEYWORD ("eval", LEXER_KEYW_EVAL), +static const keyword_string_t keywords_with_length_4[] = { + LEXER_KEYWORD ("case", LEXER_KEYW_CASE), LEXER_KEYWORD ("else", LEXER_KEYW_ELSE), + LEXER_KEYWORD ("enum", LEXER_KEYW_ENUM), LEXER_KEYWORD ("eval", LEXER_KEYW_EVAL), #if JERRY_MODULE_SYSTEM LEXER_KEYWORD ("meta", LEXER_KEYW_META), #endif /* JERRY_MODULE_SYSTEM */ - LEXER_KEYWORD ("null", LEXER_LIT_NULL), - LEXER_KEYWORD ("this", LEXER_KEYW_THIS), - LEXER_KEYWORD ("true", LEXER_LIT_TRUE), - LEXER_KEYWORD ("void", LEXER_KEYW_VOID), + LEXER_KEYWORD ("null", LEXER_LIT_NULL), LEXER_KEYWORD ("this", LEXER_KEYW_THIS), + LEXER_KEYWORD ("true", LEXER_LIT_TRUE), LEXER_KEYWORD ("void", LEXER_KEYW_VOID), LEXER_KEYWORD ("with", LEXER_KEYW_WITH), }; /** * Keywords with 5 characters. */ -static const keyword_string_t keywords_with_length_5[] = -{ +static const keyword_string_t keywords_with_length_5[] = { #if JERRY_ESNEXT - LEXER_KEYWORD ("async", LEXER_KEYW_ASYNC), - LEXER_KEYWORD ("await", LEXER_KEYW_AWAIT), + LEXER_KEYWORD ("async", LEXER_KEYW_ASYNC), LEXER_KEYWORD ("await", LEXER_KEYW_AWAIT), #endif /* JERRY_ESNEXT */ - LEXER_KEYWORD ("break", LEXER_KEYW_BREAK), - LEXER_KEYWORD ("catch", LEXER_KEYW_CATCH), - LEXER_KEYWORD ("class", LEXER_KEYW_CLASS), - LEXER_KEYWORD ("const", LEXER_KEYW_CONST), - LEXER_KEYWORD ("false", LEXER_LIT_FALSE), - LEXER_KEYWORD ("super", LEXER_KEYW_SUPER), - LEXER_KEYWORD ("throw", LEXER_KEYW_THROW), - LEXER_KEYWORD ("while", LEXER_KEYW_WHILE), + LEXER_KEYWORD ("break", LEXER_KEYW_BREAK), LEXER_KEYWORD ("catch", LEXER_KEYW_CATCH), + LEXER_KEYWORD ("class", LEXER_KEYW_CLASS), LEXER_KEYWORD ("const", LEXER_KEYW_CONST), + LEXER_KEYWORD ("false", LEXER_LIT_FALSE), LEXER_KEYWORD ("super", LEXER_KEYW_SUPER), + LEXER_KEYWORD ("throw", LEXER_KEYW_THROW), LEXER_KEYWORD ("while", LEXER_KEYW_WHILE), LEXER_KEYWORD ("yield", LEXER_KEYW_YIELD), }; /** * Keywords with 6 characters. */ -static const keyword_string_t keywords_with_length_6[] = -{ - LEXER_KEYWORD ("delete", LEXER_KEYW_DELETE), - LEXER_KEYWORD ("export", LEXER_KEYW_EXPORT), - LEXER_KEYWORD ("import", LEXER_KEYW_IMPORT), - LEXER_KEYWORD ("public", LEXER_KEYW_PUBLIC), - LEXER_KEYWORD ("return", LEXER_KEYW_RETURN), - LEXER_KEYWORD ("static", LEXER_KEYW_STATIC), - LEXER_KEYWORD ("switch", LEXER_KEYW_SWITCH), - LEXER_KEYWORD ("typeof", LEXER_KEYW_TYPEOF), +static const keyword_string_t keywords_with_length_6[] = { + LEXER_KEYWORD ("delete", LEXER_KEYW_DELETE), LEXER_KEYWORD ("export", LEXER_KEYW_EXPORT), + LEXER_KEYWORD ("import", LEXER_KEYW_IMPORT), LEXER_KEYWORD ("public", LEXER_KEYW_PUBLIC), + LEXER_KEYWORD ("return", LEXER_KEYW_RETURN), LEXER_KEYWORD ("static", LEXER_KEYW_STATIC), + LEXER_KEYWORD ("switch", LEXER_KEYW_SWITCH), LEXER_KEYWORD ("typeof", LEXER_KEYW_TYPEOF), }; /** * Keywords with 7 characters. */ -static const keyword_string_t keywords_with_length_7[] = -{ - LEXER_KEYWORD ("default", LEXER_KEYW_DEFAULT), - LEXER_KEYWORD ("extends", LEXER_KEYW_EXTENDS), - LEXER_KEYWORD ("finally", LEXER_KEYW_FINALLY), - LEXER_KEYWORD ("package", LEXER_KEYW_PACKAGE), +static const keyword_string_t keywords_with_length_7[] = { + LEXER_KEYWORD ("default", LEXER_KEYW_DEFAULT), LEXER_KEYWORD ("extends", LEXER_KEYW_EXTENDS), + LEXER_KEYWORD ("finally", LEXER_KEYW_FINALLY), LEXER_KEYWORD ("package", LEXER_KEYW_PACKAGE), LEXER_KEYWORD ("private", LEXER_KEYW_PRIVATE), }; /** * Keywords with 8 characters. */ -static const keyword_string_t keywords_with_length_8[] = -{ +static const keyword_string_t keywords_with_length_8[] = { LEXER_KEYWORD ("continue", LEXER_KEYW_CONTINUE), LEXER_KEYWORD ("debugger", LEXER_KEYW_DEBUGGER), LEXER_KEYWORD ("function", LEXER_KEYW_FUNCTION), @@ -561,8 +529,7 @@ static const keyword_string_t keywords_with_length_8[] = /** * Keywords with 9 characters. */ -static const keyword_string_t keywords_with_length_9[] = -{ +static const keyword_string_t keywords_with_length_9[] = { LEXER_KEYWORD ("arguments", LEXER_KEYW_ARGUMENTS), LEXER_KEYWORD ("interface", LEXER_KEYW_INTERFACE), LEXER_KEYWORD ("protected", LEXER_KEYW_PROTECTED), @@ -571,8 +538,7 @@ static const keyword_string_t keywords_with_length_9[] = /** * Keywords with 10 characters. */ -static const keyword_string_t keywords_with_length_10[] = -{ +static const keyword_string_t keywords_with_length_10[] = { LEXER_KEYWORD ("implements", LEXER_KEYW_IMPLEMENTS), LEXER_KEYWORD ("instanceof", LEXER_KEYW_INSTANCEOF), }; @@ -580,36 +546,24 @@ static const keyword_string_t keywords_with_length_10[] = /** * List of the keyword groups. */ -static const keyword_string_t * const keyword_strings_list[] = -{ - keywords_with_length_2, - keywords_with_length_3, - keywords_with_length_4, - keywords_with_length_5, - keywords_with_length_6, - keywords_with_length_7, - keywords_with_length_8, - keywords_with_length_9, - keywords_with_length_10 -}; +static const keyword_string_t *const keyword_strings_list[] = { keywords_with_length_2, keywords_with_length_3, + keywords_with_length_4, keywords_with_length_5, + keywords_with_length_6, keywords_with_length_7, + keywords_with_length_8, keywords_with_length_9, + keywords_with_length_10 }; JERRY_STATIC_ASSERT (sizeof (keyword_strings_list) / sizeof (const keyword_string_t *) - == (LEXER_KEYWORD_MAX_LENGTH - LEXER_KEYWORD_MIN_LENGTH) + 1, + == (LEXER_KEYWORD_MAX_LENGTH - LEXER_KEYWORD_MIN_LENGTH) + 1, keyword_strings_list_size_must_equal_to_keyword_max_length_difference); /** * List of the keyword groups length. */ -static const uint8_t keyword_lengths_list[] = -{ - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_2), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_3), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_4), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_5), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_6), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_7), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_8), - LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_9), +static const uint8_t keyword_lengths_list[] = { + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_2), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_3), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_4), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_5), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_6), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_7), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_8), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_9), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_10) }; @@ -717,9 +671,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ status_flags &= (uint32_t) ~LEXER_LIT_LOCATION_IS_ASCII; #if JERRY_ESNEXT - utf8_length = lit_read_code_point_from_utf8 (source_p, - (lit_utf8_size_t) (source_end_p - source_p), - &code_point); + utf8_length = lit_read_code_point_from_utf8 (source_p, (lit_utf8_size_t) (source_end_p - source_p), &code_point); decoded_length = utf8_length; /* Only ES2015+ supports code points outside of the basic plane which can be part of an identifier. */ @@ -727,14 +679,11 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ && source_p + 3 < source_end_p) { lit_code_point_t low_surrogate; - lit_read_code_point_from_utf8 (source_p + 3, - (lit_utf8_size_t) (source_end_p - (source_p + 3)), - &low_surrogate); + lit_read_code_point_from_utf8 (source_p + 3, (lit_utf8_size_t) (source_end_p - (source_p + 3)), &low_surrogate); if (low_surrogate >= LIT_UTF16_LOW_SURROGATE_MIN && low_surrogate <= LIT_UTF16_LOW_SURROGATE_MAX) { - code_point = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) code_point, - (ecma_char_t) low_surrogate); + code_point = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) code_point, (ecma_char_t) low_surrogate); utf8_length = 2 * 3; decoded_length = 2 * 3; char_count = 2; @@ -751,9 +700,8 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ #else /* !JERRY_ESNEXT */ if (code_point < LIT_UTF8_4_BYTE_MARKER) { - utf8_length = lit_read_code_point_from_utf8 (source_p, - (lit_utf8_size_t) (source_end_p - source_p), - &code_point); + utf8_length = + lit_read_code_point_from_utf8 (source_p, (lit_utf8_size_t) (source_end_p - source_p), &code_point); decoded_length = utf8_length; } else @@ -790,8 +738,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ source_p += utf8_length; length += decoded_length; PARSER_PLUS_EQUAL_LC (column, char_count); - } - while (source_p < source_end_p); + } while (source_p < source_end_p); JERRY_ASSERT (length > 0); @@ -928,8 +875,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ } middle = (start + end) / 2; - } - while (start < end); + } while (start < end); } context_p->source_p = source_p; @@ -1000,8 +946,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ if (*source_p == LIT_CHAR_CR) { source_p++; - if (source_p < source_end_p - && *source_p == LIT_CHAR_LF) + if (source_p < source_end_p && *source_p == LIT_CHAR_LF) { #if JERRY_ESNEXT raw_length_adjust--; @@ -1041,8 +986,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - if (*source_p == LIT_CHAR_0 - && source_p + 1 < source_end_p + if (*source_p == LIT_CHAR_0 && source_p + 1 < source_end_p && (*(source_p + 1) < LIT_CHAR_0 || *(source_p + 1) > LIT_CHAR_9)) { source_p++; @@ -1060,7 +1004,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ { parser_raise_error (context_p, PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE); } -#endif +#endif /* JERRY_ESNEXT */ if (context_p->status_flags & PARSER_IS_STRICT) { @@ -1121,9 +1065,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ lit_code_point_t code_point = UINT32_MAX; #if JERRY_ESNEXT - if (source_p + 4 <= source_end_p - && source_p[0] == LIT_CHAR_LOWERCASE_U - && source_p[1] == LIT_CHAR_LEFT_BRACE) + if (source_p + 4 <= source_end_p && source_p[0] == LIT_CHAR_LOWERCASE_U && source_p[1] == LIT_CHAR_LEFT_BRACE) { code_point = lexer_hex_in_braces_to_code_point (source_p + 2, source_end_p, &escape_length); escape_length--; @@ -1154,10 +1096,8 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ } } #if JERRY_ESNEXT - else if (str_end_character == LIT_CHAR_GRAVE_ACCENT && - source_p[0] == LIT_CHAR_DOLLAR_SIGN && - source_p + 1 < source_end_p && - source_p[1] == LIT_CHAR_LEFT_BRACE) + else if (str_end_character == LIT_CHAR_GRAVE_ACCENT && source_p[0] == LIT_CHAR_DOLLAR_SIGN + && source_p + 1 < source_end_p && source_p[1] == LIT_CHAR_LEFT_BRACE) { raw_length_adjust--; source_p++; @@ -1206,8 +1146,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ status_flags = LEXER_LIT_LOCATION_HAS_ESCAPE; source_p++; length++; - if (source_p < source_end_p - && *source_p == LIT_CHAR_LF) + if (source_p < source_end_p && *source_p == LIT_CHAR_LF) { source_p++; raw_length_adjust--; @@ -1241,8 +1180,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ column++; length++; - while (source_p < source_end_p - && IS_UTF8_INTERMEDIATE_OCTET (*source_p)) + while (source_p < source_end_p && IS_UTF8_INTERMEDIATE_OCTET (*source_p)) { source_p++; length++; @@ -1262,8 +1200,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ } #if JERRY_ESNEXT - context_p->token.type = ((str_end_character != LIT_CHAR_GRAVE_ACCENT) ? LEXER_LITERAL - : LEXER_TEMPLATE_LITERAL); + context_p->token.type = ((str_end_character != LIT_CHAR_GRAVE_ACCENT) ? LEXER_LITERAL : LEXER_TEMPLATE_LITERAL); #else /* !JERRY_ESNEXT */ context_p->token.type = LEXER_LITERAL; #endif /* JERRY_ESNEXT */ @@ -1295,9 +1232,7 @@ lexer_check_numbers (parser_context_t *context_p, /**< context */ #endif /* !JERRY_ESNEXT */ while (true) { - while (*source_p < source_end_p - && *source_p[0] >= LIT_CHAR_0 - && *source_p[0] <= digit_max) + while (*source_p < source_end_p && *source_p[0] >= LIT_CHAR_0 && *source_p[0] <= digit_max) { *source_p += 1; } @@ -1305,10 +1240,7 @@ lexer_check_numbers (parser_context_t *context_p, /**< context */ if (*source_p != source_end_p && *source_p[0] == LIT_CHAR_UNDERSCORE) { *source_p += 1; - if (is_legacy - || *source_p == source_end_p - || *source_p[0] == LIT_CHAR_UNDERSCORE - || *source_p[0] > digit_max + if (is_legacy || *source_p == source_end_p || *source_p[0] == LIT_CHAR_UNDERSCORE || *source_p[0] > digit_max || *source_p[0] < LIT_CHAR_0) { parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); @@ -1341,8 +1273,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ context_p->token.lit_location.type = LEXER_NUMBER_LITERAL; context_p->token.lit_location.status_flags = LEXER_LIT_LOCATION_IS_ASCII; - if (source_p[0] == LIT_CHAR_0 - && source_p + 1 < source_end_p) + if (source_p[0] == LIT_CHAR_0 && source_p + 1 < source_end_p) { #if JERRY_ESNEXT if (source_p[1] == LIT_CHAR_UNDERSCORE) @@ -1355,8 +1286,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ context_p->token.extra_value = LEXER_NUMBER_HEXADECIMAL; source_p += 2; - if (source_p >= source_end_p - || !lit_char_is_hex_digit (source_p[0])) + if (source_p >= source_end_p || !lit_char_is_hex_digit (source_p[0])) { parser_raise_error (context_p, PARSER_ERR_INVALID_HEX_DIGIT); } @@ -1374,9 +1304,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ } } #endif /* JERRY_ESNEXT */ - } - while (source_p < source_end_p - && lit_char_is_hex_digit (source_p[0])); + } while (source_p < source_end_p && lit_char_is_hex_digit (source_p[0])); } #if JERRY_ESNEXT else if (LEXER_TO_ASCII_LOWERCASE (source_p[1]) == LIT_CHAR_LOWERCASE_O) @@ -1384,8 +1312,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ context_p->token.extra_value = LEXER_NUMBER_OCTAL; source_p += 2; - if (source_p >= source_end_p - || !lit_char_is_octal_digit (source_p[0])) + if (source_p >= source_end_p || !lit_char_is_octal_digit (source_p[0])) { parser_raise_error (context_p, PARSER_ERR_INVALID_OCTAL_DIGIT); } @@ -1393,8 +1320,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_7, false); } #endif /* JERRY_ESNEXT */ - else if (source_p[1] >= LIT_CHAR_0 - && source_p[1] <= LIT_CHAR_9) + else if (source_p[1] >= LIT_CHAR_0 && source_p[1] <= LIT_CHAR_9) { context_p->token.extra_value = LEXER_NUMBER_OCTAL; #if JERRY_BUILTIN_BIGINT @@ -1408,9 +1334,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_7, true); - if (source_p < source_end_p - && source_p[0] >= LIT_CHAR_8 - && source_p[0] <= LIT_CHAR_9) + if (source_p < source_end_p && source_p[0] >= LIT_CHAR_8 && source_p[0] <= LIT_CHAR_9) { #if JERRY_ESNEXT lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_9, true); @@ -1426,8 +1350,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ context_p->token.extra_value = LEXER_NUMBER_BINARY; source_p += 2; - if (source_p >= source_end_p - || !lit_char_is_binary_digit (source_p[0])) + if (source_p >= source_end_p || !lit_char_is_binary_digit (source_p[0])) { parser_raise_error (context_p, PARSER_ERR_INVALID_BIN_DIGIT); } @@ -1438,16 +1361,12 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ if (source_p < source_end_p && source_p[0] == LIT_CHAR_UNDERSCORE) { source_p++; - if (source_p == source_end_p - || source_p[0] > LIT_CHAR_9 - || source_p[0] < LIT_CHAR_0) + if (source_p == source_end_p || source_p[0] > LIT_CHAR_9 || source_p[0] < LIT_CHAR_0) { parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); } } - } - while (source_p < source_end_p - && lit_char_is_binary_digit (source_p[0])); + } while (source_p < source_end_p && lit_char_is_binary_digit (source_p[0])); } #endif /* JERRY_ESNEXT */ else @@ -1464,8 +1383,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ if (can_be_float) { - if (source_p < source_end_p - && source_p[0] == LIT_CHAR_DOT) + if (source_p < source_end_p && source_p[0] == LIT_CHAR_DOT) { source_p++; #if JERRY_BUILTIN_BIGINT @@ -1481,23 +1399,19 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_9, false); } - if (source_p < source_end_p - && LEXER_TO_ASCII_LOWERCASE (source_p[0]) == LIT_CHAR_LOWERCASE_E) + if (source_p < source_end_p && LEXER_TO_ASCII_LOWERCASE (source_p[0]) == LIT_CHAR_LOWERCASE_E) { source_p++; #if JERRY_BUILTIN_BIGINT can_be_bigint = false; #endif /* JERRY_BUILTIN_BIGINT */ - if (source_p < source_end_p - && (source_p[0] == LIT_CHAR_PLUS || source_p[0] == LIT_CHAR_MINUS)) + if (source_p < source_end_p && (source_p[0] == LIT_CHAR_PLUS || source_p[0] == LIT_CHAR_MINUS)) { source_p++; } - if (source_p >= source_end_p - || source_p[0] < LIT_CHAR_0 - || source_p[0] > LIT_CHAR_9) + if (source_p >= source_end_p || source_p[0] < LIT_CHAR_0 || source_p[0] > LIT_CHAR_9) { parser_raise_error (context_p, PARSER_ERR_MISSING_EXPONENT); } @@ -1541,11 +1455,11 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ * @param type1 type */ #define LEXER_TYPE_A_TOKEN(char1, type1) \ - case (uint8_t) (char1): \ - { \ - context_p->token.type = (type1); \ - length = 1; \ - break; \ + case (uint8_t) (char1): \ + { \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ } /** @@ -1556,19 +1470,19 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ * @param char2 second character * @param type2 type of the second character */ -#define LEXER_TYPE_B_TOKEN(char1, type1, char2, type2) \ - case (uint8_t) (char1): \ - { \ +#define LEXER_TYPE_B_TOKEN(char1, type1, char2, type2) \ + case (uint8_t) (char1): \ + { \ if (length >= 2 && context_p->source_p[1] == (uint8_t) (char2)) \ - { \ - context_p->token.type = (type2); \ - length = 2; \ - break; \ - } \ - \ - context_p->token.type = (type1); \ - length = 1; \ - break; \ + { \ + context_p->token.type = (type2); \ + length = 2; \ + break; \ + } \ + \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ } /** @@ -1582,28 +1496,28 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ * @param type3 type of the third character */ #define LEXER_TYPE_C_TOKEN(char1, type1, char2, type2, char3, type3) \ - case (uint8_t) (char1): \ - { \ - if (length >= 2) \ - { \ - if (context_p->source_p[1] == (uint8_t) (char2)) \ - { \ - context_p->token.type = (type2); \ - length = 2; \ - break; \ - } \ - \ - if (context_p->source_p[1] == (uint8_t) (char3)) \ - { \ - context_p->token.type = (type3); \ - length = 2; \ - break; \ - } \ - } \ - \ - context_p->token.type = (type1); \ - length = 1; \ - break; \ + case (uint8_t) (char1): \ + { \ + if (length >= 2) \ + { \ + if (context_p->source_p[1] == (uint8_t) (char2)) \ + { \ + context_p->token.type = (type2); \ + length = 2; \ + break; \ + } \ + \ + if (context_p->source_p[1] == (uint8_t) (char3)) \ + { \ + context_p->token.type = (type3); \ + length = 2; \ + break; \ + } \ + } \ + \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ } /** @@ -1656,17 +1570,14 @@ lexer_next_token (parser_context_t *context_p) /**< context */ case (uint8_t) LIT_CHAR_DOT: { - if (length >= 2 - && (context_p->source_p[1] >= LIT_CHAR_0 && context_p->source_p[1] <= LIT_CHAR_9)) + if (length >= 2 && (context_p->source_p[1] >= LIT_CHAR_0 && context_p->source_p[1] <= LIT_CHAR_9)) { lexer_parse_number (context_p); return; } #if JERRY_ESNEXT - if (length >= 3 - && context_p->source_p[1] == LIT_CHAR_DOT - && context_p->source_p[2] == LIT_CHAR_DOT) + if (length >= 3 && context_p->source_p[1] == LIT_CHAR_DOT && context_p->source_p[2] == LIT_CHAR_DOT) { context_p->token.type = LEXER_THREE_DOTS; length = 3; @@ -1812,10 +1723,13 @@ lexer_next_token (parser_context_t *context_p) /**< context */ break; } - LEXER_TYPE_C_TOKEN (LIT_CHAR_PLUS, LEXER_ADD, LIT_CHAR_EQUALS, - LEXER_ASSIGN_ADD, LIT_CHAR_PLUS, LEXER_INCREASE) - LEXER_TYPE_C_TOKEN (LIT_CHAR_MINUS, LEXER_SUBTRACT, LIT_CHAR_EQUALS, - LEXER_ASSIGN_SUBTRACT, LIT_CHAR_MINUS, LEXER_DECREASE) + LEXER_TYPE_C_TOKEN (LIT_CHAR_PLUS, LEXER_ADD, LIT_CHAR_EQUALS, LEXER_ASSIGN_ADD, LIT_CHAR_PLUS, LEXER_INCREASE) + LEXER_TYPE_C_TOKEN (LIT_CHAR_MINUS, + LEXER_SUBTRACT, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_SUBTRACT, + LIT_CHAR_MINUS, + LEXER_DECREASE) case (uint8_t) LIT_CHAR_ASTERISK: { @@ -1850,20 +1764,25 @@ lexer_next_token (parser_context_t *context_p) /**< context */ break; } - LEXER_TYPE_B_TOKEN (LIT_CHAR_SLASH, LEXER_DIVIDE, LIT_CHAR_EQUALS, - LEXER_ASSIGN_DIVIDE) - LEXER_TYPE_B_TOKEN (LIT_CHAR_PERCENT, LEXER_MODULO, LIT_CHAR_EQUALS, - LEXER_ASSIGN_MODULO) + LEXER_TYPE_B_TOKEN (LIT_CHAR_SLASH, LEXER_DIVIDE, LIT_CHAR_EQUALS, LEXER_ASSIGN_DIVIDE) + LEXER_TYPE_B_TOKEN (LIT_CHAR_PERCENT, LEXER_MODULO, LIT_CHAR_EQUALS, LEXER_ASSIGN_MODULO) - LEXER_TYPE_C_TOKEN (LIT_CHAR_AMPERSAND, LEXER_BIT_AND, LIT_CHAR_EQUALS, - LEXER_ASSIGN_BIT_AND, LIT_CHAR_AMPERSAND, LEXER_LOGICAL_AND) - LEXER_TYPE_C_TOKEN (LIT_CHAR_VLINE, LEXER_BIT_OR, LIT_CHAR_EQUALS, - LEXER_ASSIGN_BIT_OR, LIT_CHAR_VLINE, LEXER_LOGICAL_OR) + LEXER_TYPE_C_TOKEN (LIT_CHAR_AMPERSAND, + LEXER_BIT_AND, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_BIT_AND, + LIT_CHAR_AMPERSAND, + LEXER_LOGICAL_AND) + LEXER_TYPE_C_TOKEN (LIT_CHAR_VLINE, + LEXER_BIT_OR, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_BIT_OR, + LIT_CHAR_VLINE, + LEXER_LOGICAL_OR) - LEXER_TYPE_B_TOKEN (LIT_CHAR_CIRCUMFLEX, LEXER_BIT_XOR, LIT_CHAR_EQUALS, - LEXER_ASSIGN_BIT_XOR) + LEXER_TYPE_B_TOKEN (LIT_CHAR_CIRCUMFLEX, LEXER_BIT_XOR, LIT_CHAR_EQUALS, LEXER_ASSIGN_BIT_XOR) - LEXER_TYPE_A_TOKEN (LIT_CHAR_TILDE, LEXER_BIT_NOT); + LEXER_TYPE_A_TOKEN (LIT_CHAR_TILDE, LEXER_BIT_NOT); case (uint8_t) (LIT_CHAR_QUESTION): { #if JERRY_ESNEXT @@ -1882,7 +1801,7 @@ lexer_next_token (parser_context_t *context_p) /**< context */ break; } - LEXER_TYPE_A_TOKEN (LIT_CHAR_COLON, LEXER_COLON); + LEXER_TYPE_A_TOKEN (LIT_CHAR_COLON, LEXER_COLON); case LIT_CHAR_SINGLE_QUOTE: case LIT_CHAR_DOUBLE_QUOTE: @@ -1925,8 +1844,7 @@ lexer_check_next_character (parser_context_t *context_p, /**< context */ context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); } - return (context_p->source_p < context_p->source_end_p - && context_p->source_p[0] == (uint8_t) character); + return (context_p->source_p < context_p->source_end_p && context_p->source_p[0] == (uint8_t) character); } /* lexer_check_next_character */ /** @@ -1947,8 +1865,7 @@ lexer_check_next_characters (parser_context_t *context_p, /**< context */ } return (context_p->source_p < context_p->source_end_p - && (context_p->source_p[0] == (uint8_t) character1 - || context_p->source_p[0] == (uint8_t) character2)); + && (context_p->source_p[0] == (uint8_t) character1 || context_p->source_p[0] == (uint8_t) character2)); } /* lexer_check_next_characters */ /** @@ -2004,8 +1921,7 @@ lexer_check_post_primary_exp (parser_context_t *context_p) /**< context */ case LIT_CHAR_PLUS: case LIT_CHAR_MINUS: { - return (!(context_p->token.flags & LEXER_WAS_NEWLINE) - && context_p->source_p + 1 < context_p->source_end_p + return (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->source_p + 1 < context_p->source_end_p && context_p->source_p[1] == context_p->source_p[0]); } #if JERRY_ESNEXT @@ -2036,8 +1952,7 @@ lexer_check_arrow (parser_context_t *context_p) /**< context */ context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); } - return (!(context_p->token.flags & LEXER_WAS_NEWLINE) - && context_p->source_p + 2 <= context_p->source_end_p + return (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->source_p + 2 <= context_p->source_end_p && context_p->source_p[0] == (uint8_t) LIT_CHAR_EQUALS && context_p->source_p[1] == (uint8_t) LIT_CHAR_GREATER_THAN); } /* lexer_check_arrow */ @@ -2067,8 +1982,7 @@ lexer_check_arrow_param (parser_context_t *context_p) /**< context */ return false; } - return (context_p->source_p + 1 >= context_p->source_end_p - || context_p->source_p[1] != LIT_CHAR_EQUALS); + return (context_p->source_p + 1 >= context_p->source_end_p || context_p->source_p[1] != LIT_CHAR_EQUALS); } /* lexer_check_arrow_param */ /** @@ -2117,8 +2031,7 @@ lexer_consume_generator (parser_context_t *context_p) /**< context */ context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); } - if (context_p->source_p >= context_p->source_end_p - || context_p->source_p[0] != LIT_CHAR_ASTERISK + if (context_p->source_p >= context_p->source_end_p || context_p->source_p[0] != LIT_CHAR_ASTERISK || (context_p->source_p + 1 < context_p->source_end_p && (context_p->source_p[1] == LIT_CHAR_EQUALS || context_p->source_p[1] == LIT_CHAR_ASTERISK))) { @@ -2144,8 +2057,7 @@ lexer_consume_assign (parser_context_t *context_p) /**< context */ context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); } - if (context_p->source_p >= context_p->source_end_p - || context_p->source_p[0] != LIT_CHAR_EQUALS + if (context_p->source_p >= context_p->source_end_p || context_p->source_p[0] != LIT_CHAR_EQUALS || (context_p->source_p + 1 < context_p->source_end_p && (context_p->source_p[1] == LIT_CHAR_EQUALS || context_p->source_p[1] == LIT_CHAR_GREATER_THAN))) { @@ -2168,8 +2080,7 @@ lexer_update_await_yield (parser_context_t *context_p, /**< context */ { if (status_flags & PARSER_IS_GENERATOR_FUNCTION) { - if (context_p->token.type == LEXER_LITERAL - && context_p->token.keyword_type == LEXER_KEYW_YIELD) + if (context_p->token.type == LEXER_LITERAL && context_p->token.keyword_type == LEXER_KEYW_YIELD) { context_p->token.type = LEXER_KEYW_YIELD; } @@ -2188,8 +2099,7 @@ lexer_update_await_yield (parser_context_t *context_p, /**< context */ { if (status_flags & PARSER_IS_ASYNC_FUNCTION) { - if (context_p->token.type == LEXER_LITERAL - && context_p->token.keyword_type == LEXER_KEYW_AWAIT) + if (context_p->token.type == LEXER_LITERAL && context_p->token.keyword_type == LEXER_KEYW_AWAIT) { context_p->token.type = LEXER_KEYW_AWAIT; } @@ -2224,8 +2134,7 @@ lexer_convert_ident_to_cesu8 (uint8_t *destination_p, /**< destination string */ if (*source_p == LIT_CHAR_BACKSLASH) { source_p += 2; - destination_p += lit_code_point_to_cesu8_bytes (destination_p, - lexer_unchecked_hex_to_character (&source_p)); + destination_p += lit_code_point_to_cesu8_bytes (destination_p, lexer_unchecked_hex_to_character (&source_p)); continue; } @@ -2241,8 +2150,7 @@ lexer_convert_ident_to_cesu8 (uint8_t *destination_p, /**< destination string */ #endif /* JERRY_ESNEXT */ *destination_p++ = *source_p++; - } - while (destination_p < destination_end_p); + } while (destination_p < destination_end_p); } /* lexer_convert_ident_to_cesu8 */ /** @@ -2379,8 +2287,7 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */ if (*source_p == LIT_CHAR_LOWERCASE_X || *source_p == LIT_CHAR_LOWERCASE_U) { source_p++; - destination_p += lit_code_point_to_cesu8_bytes (destination_p, - lexer_unchecked_hex_to_character (&source_p)); + destination_p += lit_code_point_to_cesu8_bytes (destination_p, lexer_unchecked_hex_to_character (&source_p)); continue; } @@ -2429,8 +2336,7 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT else if (str_end_character == LIT_CHAR_GRAVE_ACCENT) { - if (source_p[0] == LIT_CHAR_DOLLAR_SIGN - && source_p[1] == LIT_CHAR_LEFT_BRACE) + if (source_p[0] == LIT_CHAR_DOLLAR_SIGN && source_p[1] == LIT_CHAR_LEFT_BRACE) { source_p++; JERRY_ASSERT (source_p < context_p->source_end_p); @@ -2440,8 +2346,7 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */ { *destination_p++ = LIT_CHAR_LF; source_p++; - if (*source_p != str_end_character - && *source_p == LIT_CHAR_LF) + if (*source_p != str_end_character && *source_p == LIT_CHAR_LF) { source_p++; } @@ -2463,8 +2368,8 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */ if (*source_p >= LIT_UTF8_4_BYTE_MARKER) { /* Processing 4 byte unicode sequence (even if it is - * after a backslash). Always converted to two 3 byte - * long sequence. */ + * after a backslash). Always converted to two 3 byte + * long sequence. */ lit_four_byte_utf8_char_to_cesu8 (destination_p, source_p); destination_p += 6; @@ -2475,7 +2380,7 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */ *destination_p++ = *source_p++; /* There is no need to check the source_end_p - * since the string is terminated by a quotation mark. */ + * since the string is terminated by a quotation mark. */ while (IS_UTF8_INTERMEDIATE_OCTET (*source_p)) { *destination_p++ = *source_p++; @@ -2518,10 +2423,8 @@ lexer_construct_literal_object (parser_context_t *context_p, /**< context */ { uint8_t local_byte_array[LEXER_MAX_LITERAL_LOCAL_BUFFER_SIZE]; - const uint8_t *char_p = lexer_convert_literal_to_chars (context_p, - lit_location_p, - local_byte_array, - LEXER_STRING_NO_OPTS); + const uint8_t *char_p = + lexer_convert_literal_to_chars (context_p, lit_location_p, local_byte_array, LEXER_STRING_NO_OPTS); size_t length = lit_location_p->length; parser_list_iterator_t literal_iterator; @@ -2534,8 +2437,7 @@ lexer_construct_literal_object (parser_context_t *context_p, /**< context */ literal_type = LEXER_IDENT_LITERAL; } - JERRY_ASSERT (literal_type == LEXER_IDENT_LITERAL - || literal_type == LEXER_STRING_LITERAL); + JERRY_ASSERT (literal_type == LEXER_IDENT_LITERAL || literal_type == LEXER_STRING_LITERAL); JERRY_ASSERT (literal_type != LEXER_IDENT_LITERAL || length <= PARSER_MAXIMUM_IDENT_LENGTH); JERRY_ASSERT (literal_type != LEXER_STRING_LITERAL || length <= PARSER_MAXIMUM_STRING_LENGTH); @@ -2544,8 +2446,7 @@ lexer_construct_literal_object (parser_context_t *context_p, /**< context */ while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) { - if (literal_p->type == literal_type - && literal_p->prop.length == length + if (literal_p->type == literal_type && literal_p->prop.length == length && memcmp (literal_p->u.char_p, char_p, length) == 0) { context_p->lit_object.literal_p = literal_p; @@ -2656,11 +2557,9 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ if (context_p->token.extra_value < LEXER_NUMBER_OCTAL) { #if JERRY_ESNEXT - num = ecma_utf8_string_to_number (context_p->token.lit_location.char_p, - length, - ECMA_CONVERSION_ALLOW_UNDERSCORE); -#else - num = ecma_utf8_string_to_number (context_p->token.lit_location.char_p, length, 0); + num = ecma_utf8_string_to_number (context_p->token.lit_location.char_p, length, ECMA_CONVERSION_ALLOW_UNDERSCORE); +#else /* !JERRY_ESNEXT */ + num = ecma_utf8_string_to_number (context_p->token.lit_location.char_p, length, 0); #endif /* JERRY_ESNEXT */ } else @@ -2691,17 +2590,14 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ src_p++; } num = num * multiplier + (ecma_number_t) (*(++src_p) - LIT_CHAR_0); - } - while (src_p < src_end_p); + } while (src_p < src_end_p); } if (is_expr) { int32_t int_num = (int32_t) num; - if (int_num == num - && int_num <= CBC_PUSH_NUMBER_BYTE_RANGE_END - && (int_num != 0 || !is_negative_number)) + if (int_num == num && int_num <= CBC_PUSH_NUMBER_BYTE_RANGE_END && (int_num != 0 || !is_negative_number)) { context_p->lit_object.index = (uint16_t) int_num; return true; @@ -2718,8 +2614,7 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ } else { - uint32_t options = (ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR - | ECMA_BIGINT_PARSE_DISALLOW_MEMORY_ERROR + uint32_t options = (ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR | ECMA_BIGINT_PARSE_DISALLOW_MEMORY_ERROR | ECMA_BIGINT_PARSE_ALLOW_UNDERSCORE); if (is_negative_number) @@ -2728,9 +2623,8 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ } JERRY_ASSERT (length >= 2); - lit_value = ecma_bigint_parse_string (context_p->token.lit_location.char_p, - (lit_utf8_size_t) (length - 1), - options); + lit_value = + ecma_bigint_parse_string (context_p->token.lit_location.char_p, (lit_utf8_size_t) (length - 1), options); JERRY_ASSERT (lit_value != ECMA_VALUE_FALSE && !ECMA_IS_VALUE_ERROR (lit_value)); @@ -2747,8 +2641,7 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) { - if (literal_p->type == LEXER_NUMBER_LITERAL - && literal_p->u.value == lit_value) + if (literal_p->type == LEXER_NUMBER_LITERAL && literal_p->u.value == lit_value) { context_p->lit_object.literal_p = literal_p; context_p->lit_object.index = (uint16_t) literal_index; @@ -2787,8 +2680,7 @@ lexer_convert_push_number_to_push_literal (parser_context_t *context_p) /**< con ecma_integer_value_t value; bool two_literals = context_p->last_cbc_opcode >= CBC_PUSH_LITERAL_PUSH_NUMBER_0; - if (context_p->last_cbc_opcode == CBC_PUSH_NUMBER_0 - || context_p->last_cbc_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_0) + if (context_p->last_cbc_opcode == CBC_PUSH_NUMBER_0 || context_p->last_cbc_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_0) { value = 0; } @@ -2816,8 +2708,7 @@ lexer_convert_push_number_to_push_literal (parser_context_t *context_p) /**< con while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) { - if (literal_p->type == LEXER_NUMBER_LITERAL - && literal_p->u.value == lit_value) + if (literal_p->type == LEXER_NUMBER_LITERAL && literal_p->u.value == lit_value) { if (two_literals) { @@ -2922,8 +2813,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ uint16_t current_flags; lit_utf8_size_t length; - JERRY_ASSERT (context_p->token.type == LEXER_DIVIDE - || context_p->token.type == LEXER_ASSIGN_DIVIDE); + JERRY_ASSERT (context_p->token.type == LEXER_DIVIDE || context_p->token.type == LEXER_ASSIGN_DIVIDE); if (context_p->token.type == LEXER_ASSIGN_DIVIDE) { @@ -2951,8 +2841,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ case LIT_CHAR_LF: case LEXER_NEWLINE_LS_PS_BYTE_1: { - if (source_p[0] != LEXER_NEWLINE_LS_PS_BYTE_1 - || LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) + if (source_p[0] != LEXER_NEWLINE_LS_PS_BYTE_1 || LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) { parser_raise_error (context_p, PARSER_ERR_NEWLINE_NOT_ALLOWED); } @@ -2961,7 +2850,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ case LIT_CHAR_TAB: { column = align_column_to_tab (column); - /* Subtract -1 because column is increased below. */ + /* Subtract -1 because column is increased below. */ column--; break; } @@ -2993,8 +2882,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ source_p++; column++; - while (source_p < source_end_p - && IS_UTF8_INTERMEDIATE_OCTET (source_p[0])) + while (source_p < source_end_p && IS_UTF8_INTERMEDIATE_OCTET (source_p[0])) { source_p++; } @@ -3119,8 +3007,7 @@ void lexer_expect_identifier (parser_context_t *context_p, /**< context */ uint8_t literal_type) /**< literal type */ { - JERRY_ASSERT (literal_type == LEXER_STRING_LITERAL - || literal_type == LEXER_IDENT_LITERAL + JERRY_ASSERT (literal_type == LEXER_STRING_LITERAL || literal_type == LEXER_IDENT_LITERAL || literal_type == LEXER_NEW_IDENT_LITERAL); lexer_skip_spaces (context_p); @@ -3129,19 +3016,17 @@ lexer_expect_identifier (parser_context_t *context_p, /**< context */ context_p->token.column = context_p->column; if (context_p->source_p < context_p->source_end_p - && lexer_parse_identifier (context_p, (literal_type != LEXER_STRING_LITERAL ? LEXER_PARSE_CHECK_KEYWORDS - : LEXER_PARSE_NO_OPTS))) + && lexer_parse_identifier ( + context_p, + (literal_type != LEXER_STRING_LITERAL ? LEXER_PARSE_CHECK_KEYWORDS : LEXER_PARSE_NO_OPTS))) { if (context_p->token.type == LEXER_LITERAL) { JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL); - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - literal_type); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, literal_type); - if (literal_type != LEXER_STRING_LITERAL - && (context_p->status_flags & PARSER_IS_STRICT)) + if (literal_type != LEXER_STRING_LITERAL && (context_p->status_flags & PARSER_IS_STRICT)) { if (context_p->token.keyword_type == LEXER_KEYW_EVAL) { @@ -3200,8 +3085,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ context_p->token.column = context_p->column; bool create_literal_object = false; - JERRY_ASSERT ((ident_opts & LEXER_OBJ_IDENT_CLASS_IDENTIFIER) - || !(ident_opts & LEXER_OBJ_IDENT_CLASS_NO_STATIC)); + JERRY_ASSERT ((ident_opts & LEXER_OBJ_IDENT_CLASS_IDENTIFIER) || !(ident_opts & LEXER_OBJ_IDENT_CLASS_NO_STATIC)); #if JERRY_FUNCTION_TO_STRING if (ident_opts & LEXER_OBJ_IDENT_SET_FUNCTION_START) @@ -3219,10 +3103,8 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ if (context_p->source_p < context_p->source_end_p #if JERRY_ESNEXT - && context_p->source_p[0] != LIT_CHAR_COMMA - && context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE - && context_p->source_p[0] != LIT_CHAR_LEFT_PAREN - && context_p->source_p[0] != LIT_CHAR_SEMICOLON + && context_p->source_p[0] != LIT_CHAR_COMMA && context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE + && context_p->source_p[0] != LIT_CHAR_LEFT_PAREN && context_p->source_p[0] != LIT_CHAR_SEMICOLON && context_p->source_p[0] != LIT_CHAR_EQUALS #endif /* JERRY_ESNEXT */ && context_p->source_p[0] != LIT_CHAR_COLON) @@ -3307,8 +3189,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ case LIT_CHAR_DOT: { if ((ident_opts & ((uint32_t) ~(LEXER_OBJ_IDENT_OBJECT_PATTERN | LEXER_OBJ_IDENT_SET_FUNCTION_START))) - || context_p->source_p + 2 >= context_p->source_end_p - || context_p->source_p[1] != LIT_CHAR_DOT + || context_p->source_p + 2 >= context_p->source_end_p || context_p->source_p[1] != LIT_CHAR_DOT || context_p->source_p[2] != LIT_CHAR_DOT) { break; @@ -3341,9 +3222,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ char_p++; } - if (char_p < context_p->source_end_p - && char_p[0] >= LIT_CHAR_0 - && char_p[0] <= LIT_CHAR_9) + if (char_p < context_p->source_end_p && char_p[0] >= LIT_CHAR_0 && char_p[0] <= LIT_CHAR_9) { lexer_parse_number (context_p); @@ -3367,9 +3246,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - LEXER_STRING_LITERAL); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); return; } @@ -3389,8 +3266,7 @@ lexer_scan_identifier (parser_context_t *context_p) /**< context */ context_p->token.line = context_p->line; context_p->token.column = context_p->column; - if (context_p->source_p < context_p->source_end_p - && lexer_parse_identifier (context_p, LEXER_PARSE_NO_OPTS)) + if (context_p->source_p < context_p->source_end_p && lexer_parse_identifier (context_p, LEXER_PARSE_NO_OPTS)) { return true; } @@ -3407,18 +3283,15 @@ void lexer_check_property_modifier (parser_context_t *context_p) /**< context */ { JERRY_ASSERT (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)); - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); lexer_skip_spaces (context_p); context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); if (context_p->source_p >= context_p->source_end_p #if JERRY_ESNEXT - || context_p->source_p[0] == LIT_CHAR_COMMA - || context_p->source_p[0] == LIT_CHAR_RIGHT_BRACE - || context_p->source_p[0] == LIT_CHAR_LEFT_PAREN - || context_p->source_p[0] == LIT_CHAR_EQUALS + || context_p->source_p[0] == LIT_CHAR_COMMA || context_p->source_p[0] == LIT_CHAR_RIGHT_BRACE + || context_p->source_p[0] == LIT_CHAR_LEFT_PAREN || context_p->source_p[0] == LIT_CHAR_EQUALS #endif /* JERRY_ESNEXT */ || context_p->source_p[0] == LIT_CHAR_COLON) { @@ -3500,10 +3373,8 @@ lexer_compare_identifier_to_chars (const uint8_t *left_p, /**< left identifier * { return false; } - } - while (--escape_size > 0); - } - while (size > 0); + } while (--escape_size > 0); + } while (size > 0); return true; } /* lexer_compare_identifier_to_chars */ @@ -3592,8 +3463,7 @@ bool lexer_current_is_literal (parser_context_t *context_p, /**< context */ const lexer_lit_location_t *right_ident_p) /**< identifier */ { - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); lexer_lit_location_t *left_ident_p = &context_p->token.lit_location; @@ -3623,8 +3493,7 @@ lexer_current_is_literal (parser_context_t *context_p, /**< context */ extern inline bool JERRY_ATTR_ALWAYS_INLINE lexer_string_is_use_strict (parser_context_t *context_p) /**< context */ { - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_STRING_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL); return (context_p->token.lit_location.length == 10 && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE) @@ -3639,13 +3508,10 @@ lexer_string_is_use_strict (parser_context_t *context_p) /**< context */ extern inline bool JERRY_ATTR_ALWAYS_INLINE lexer_string_is_directive (parser_context_t *context_p) /**< context */ { - return (context_p->token.type == LEXER_SEMICOLON - || context_p->token.type == LEXER_RIGHT_BRACE + return (context_p->token.type == LEXER_SEMICOLON || context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_EOS - || ((context_p->token.flags & LEXER_WAS_NEWLINE) - && !LEXER_IS_BINARY_OP_TOKEN (context_p->token.type) - && context_p->token.type != LEXER_LEFT_PAREN - && context_p->token.type != LEXER_LEFT_SQUARE + || ((context_p->token.flags & LEXER_WAS_NEWLINE) && !LEXER_IS_BINARY_OP_TOKEN (context_p->token.type) + && context_p->token.type != LEXER_LEFT_PAREN && context_p->token.type != LEXER_LEFT_SQUARE && context_p->token.type != LEXER_DOT)); } /* lexer_string_is_directive */ @@ -3665,8 +3531,7 @@ lexer_token_is_identifier (parser_context_t *context_p, /**< context */ size_t identifier_length) /**< identifier length */ { /* Checking has_escape is unnecessary because memcmp will fail if escape sequences are present. */ - return (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL + return (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL && context_p->token.lit_location.length == identifier_length && memcmp (context_p->token.lit_location.char_p, identifier_p, identifier_length) == 0); } /* lexer_token_is_identifier */ @@ -3699,8 +3564,7 @@ lexer_token_is_let (parser_context_t *context_p) /**< context */ extern inline bool JERRY_ATTR_ALWAYS_INLINE lexer_token_is_async (parser_context_t *context_p) /**< context */ { - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL - || context_p->token.type == LEXER_TEMPLATE_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL || context_p->token.type == LEXER_TEMPLATE_LITERAL); return (context_p->token.keyword_type == LEXER_KEYW_ASYNC && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)); diff --git a/jerry-core/parser/js/js-lexer.h b/jerry-core/parser/js/js-lexer.h index 8f2a5e84..d959cd7d 100644 --- a/jerry-core/parser/js/js-lexer.h +++ b/jerry-core/parser/js/js-lexer.h @@ -18,6 +18,8 @@ #include "ecma-globals.h" +#include "common.h" + /** \addtogroup parser Parser * @{ * @@ -33,44 +35,42 @@ */ typedef enum { - LEXER_EOS, /**< end of source */ + LEXER_EOS, /**< end of source */ /* Primary expressions */ - LEXER_LITERAL, /**< literal token */ - LEXER_KEYW_THIS, /**< this */ - LEXER_LIT_TRUE, /**< true (not a keyword!) */ - LEXER_LIT_FALSE, /**< false (not a keyword!) */ - LEXER_LIT_NULL, /**< null (not a keyword!) */ + LEXER_LITERAL, /**< literal token */ + LEXER_KEYW_THIS, /**< this */ + LEXER_LIT_TRUE, /**< true (not a keyword!) */ + LEXER_LIT_FALSE, /**< false (not a keyword!) */ + LEXER_LIT_NULL, /**< null (not a keyword!) */ #if JERRY_ESNEXT - LEXER_TEMPLATE_LITERAL, /**< multi segment template literal */ - LEXER_THREE_DOTS, /**< ... (rest or spread operator) */ + LEXER_TEMPLATE_LITERAL, /**< multi segment template literal */ + LEXER_THREE_DOTS, /**< ... (rest or spread operator) */ #endif /* JERRY_ESNEXT */ - /* Unary operators - * IMPORTANT: update CBC_UNARY_OP_TOKEN_TO_OPCODE and - * CBC_UNARY_LVALUE_OP_TOKEN_TO_OPCODE after changes. */ -#define LEXER_IS_UNARY_OP_TOKEN(token_type) \ - ((token_type) >= LEXER_PLUS && (token_type) <= LEXER_DECREASE) -#define LEXER_IS_UNARY_LVALUE_OP_TOKEN(token_type) \ - ((token_type) >= LEXER_KEYW_DELETE && (token_type) <= LEXER_DECREASE) - - LEXER_PLUS, /**< "+" */ - LEXER_NEGATE, /**< "-" */ - LEXER_LOGICAL_NOT, /**< "!" */ - LEXER_BIT_NOT, /**< "~" */ - LEXER_KEYW_VOID, /**< void */ - LEXER_KEYW_TYPEOF, /**< typeof */ +/* Unary operators + * IMPORTANT: update CBC_UNARY_OP_TOKEN_TO_OPCODE and + * CBC_UNARY_LVALUE_OP_TOKEN_TO_OPCODE after changes. */ +#define LEXER_IS_UNARY_OP_TOKEN(token_type) ((token_type) >= LEXER_PLUS && (token_type) <= LEXER_DECREASE) +#define LEXER_IS_UNARY_LVALUE_OP_TOKEN(token_type) ((token_type) >= LEXER_KEYW_DELETE && (token_type) <= LEXER_DECREASE) + + LEXER_PLUS, /**< "+" */ + LEXER_NEGATE, /**< "-" */ + LEXER_LOGICAL_NOT, /**< "!" */ + LEXER_BIT_NOT, /**< "~" */ + LEXER_KEYW_VOID, /**< void */ + LEXER_KEYW_TYPEOF, /**< typeof */ #if JERRY_ESNEXT - LEXER_KEYW_AWAIT, /**< await */ + LEXER_KEYW_AWAIT, /**< await */ #endif /* JERRY_ESNEXT */ - LEXER_KEYW_DELETE, /**< delete */ - LEXER_INCREASE, /**< "++" */ - LEXER_DECREASE, /**< "--" */ - - /* Binary operators - * IMPORTANT: update CBC_BINARY_OP_TOKEN_TO_OPCODE, - * CBC_BINARY_LVALUE_OP_TOKEN_TO_OPCODE and - * parser_binary_precedence_table after changes. */ + LEXER_KEYW_DELETE, /**< delete */ + LEXER_INCREASE, /**< "++" */ + LEXER_DECREASE, /**< "--" */ + +/* Binary operators + * IMPORTANT: update CBC_BINARY_OP_TOKEN_TO_OPCODE, + * CBC_BINARY_LVALUE_OP_TOKEN_TO_OPCODE and + * parser_binary_precedence_table after changes. */ /** * Index of first binary operation opcode. */ @@ -103,136 +103,136 @@ typedef enum #define LEXER_IS_BINARY_NON_LVALUE_OP_TOKEN(token_type) \ ((token_type) >= LEXER_QUESTION_MARK && (token_type) <= LEXER_LAST_BINARY_OP) - LEXER_ASSIGN, /**< "=" (prec: 3) */ - LEXER_ASSIGN_ADD, /**< "+=" (prec: 3) */ - LEXER_ASSIGN_SUBTRACT, /**< "-=" (prec: 3) */ - LEXER_ASSIGN_MULTIPLY, /**< "*=" (prec: 3) */ - LEXER_ASSIGN_DIVIDE, /**< "/=" (prec: 3) */ - LEXER_ASSIGN_MODULO, /**< "%=" (prec: 3) */ + LEXER_ASSIGN, /**< "=" (prec: 3) */ + LEXER_ASSIGN_ADD, /**< "+=" (prec: 3) */ + LEXER_ASSIGN_SUBTRACT, /**< "-=" (prec: 3) */ + LEXER_ASSIGN_MULTIPLY, /**< "*=" (prec: 3) */ + LEXER_ASSIGN_DIVIDE, /**< "/=" (prec: 3) */ + LEXER_ASSIGN_MODULO, /**< "%=" (prec: 3) */ #if JERRY_ESNEXT - LEXER_ASSIGN_EXPONENTIATION, /**< "**=" (prec: 3) */ + LEXER_ASSIGN_EXPONENTIATION, /**< "**=" (prec: 3) */ #endif /* JERRY_ESNEXT */ - LEXER_ASSIGN_LEFT_SHIFT, /**< "<<=" (prec: 3) */ - LEXER_ASSIGN_RIGHT_SHIFT, /**< ">>=" (prec: 3) */ - LEXER_ASSIGN_UNS_RIGHT_SHIFT, /**< ">>>=" (prec: 3) */ - LEXER_ASSIGN_BIT_AND, /**< "&=" (prec: 3) */ - LEXER_ASSIGN_BIT_OR, /**< "|=" (prec: 3) */ - LEXER_ASSIGN_BIT_XOR, /**< "^=" (prec: 3) */ - LEXER_QUESTION_MARK, /**< "?" (prec: 4) */ + LEXER_ASSIGN_LEFT_SHIFT, /**< "<<=" (prec: 3) */ + LEXER_ASSIGN_RIGHT_SHIFT, /**< ">>=" (prec: 3) */ + LEXER_ASSIGN_UNS_RIGHT_SHIFT, /**< ">>>=" (prec: 3) */ + LEXER_ASSIGN_BIT_AND, /**< "&=" (prec: 3) */ + LEXER_ASSIGN_BIT_OR, /**< "|=" (prec: 3) */ + LEXER_ASSIGN_BIT_XOR, /**< "^=" (prec: 3) */ + LEXER_QUESTION_MARK, /**< "?" (prec: 4) */ #if JERRY_ESNEXT - LEXER_NULLISH_COALESCING, /**< "??" (prec: 5) */ + LEXER_NULLISH_COALESCING, /**< "??" (prec: 5) */ #endif /* JERRY_ESNEXT */ - LEXER_LOGICAL_OR, /**< "||" (prec: 6) */ - LEXER_LOGICAL_AND, /**< "&&" (prec: 7) */ - LEXER_BIT_OR, /**< "|" (prec: 8) */ - LEXER_BIT_XOR, /**< "^" (prec: 9) */ - LEXER_BIT_AND, /**< "&" (prec: 10) */ - LEXER_EQUAL, /**< "==" (prec: 11) */ - LEXER_NOT_EQUAL, /**< "!=" (prec: 11) */ - LEXER_STRICT_EQUAL, /**< "===" (prec: 11) */ - LEXER_STRICT_NOT_EQUAL, /**< "!==" (prec: 11) */ - LEXER_LESS, /**< "<" (prec: 12) */ - LEXER_GREATER, /**< ">" (prec: 12) */ - LEXER_LESS_EQUAL, /**< "<=" (prec: 12) */ - LEXER_GREATER_EQUAL, /**< ">=" (prec: 12) */ - LEXER_KEYW_IN, /**< in (prec: 12) */ - LEXER_KEYW_INSTANCEOF, /**< instanceof (prec: 12) */ - LEXER_LEFT_SHIFT, /**< "<<" (prec: 13) */ - LEXER_RIGHT_SHIFT, /**< ">>" (prec: 13) */ - LEXER_UNS_RIGHT_SHIFT, /**< ">>>" (prec: 13) */ - LEXER_ADD, /**< "+" (prec: 14) */ - LEXER_SUBTRACT, /**< "-" (prec: 14) */ - LEXER_MULTIPLY, /**< "*" (prec: 15) */ - LEXER_DIVIDE, /**< "/" (prec: 15) */ - LEXER_MODULO, /**< "%" (prec: 15) */ + LEXER_LOGICAL_OR, /**< "||" (prec: 6) */ + LEXER_LOGICAL_AND, /**< "&&" (prec: 7) */ + LEXER_BIT_OR, /**< "|" (prec: 8) */ + LEXER_BIT_XOR, /**< "^" (prec: 9) */ + LEXER_BIT_AND, /**< "&" (prec: 10) */ + LEXER_EQUAL, /**< "==" (prec: 11) */ + LEXER_NOT_EQUAL, /**< "!=" (prec: 11) */ + LEXER_STRICT_EQUAL, /**< "===" (prec: 11) */ + LEXER_STRICT_NOT_EQUAL, /**< "!==" (prec: 11) */ + LEXER_LESS, /**< "<" (prec: 12) */ + LEXER_GREATER, /**< ">" (prec: 12) */ + LEXER_LESS_EQUAL, /**< "<=" (prec: 12) */ + LEXER_GREATER_EQUAL, /**< ">=" (prec: 12) */ + LEXER_KEYW_IN, /**< in (prec: 12) */ + LEXER_KEYW_INSTANCEOF, /**< instanceof (prec: 12) */ + LEXER_LEFT_SHIFT, /**< "<<" (prec: 13) */ + LEXER_RIGHT_SHIFT, /**< ">>" (prec: 13) */ + LEXER_UNS_RIGHT_SHIFT, /**< ">>>" (prec: 13) */ + LEXER_ADD, /**< "+" (prec: 14) */ + LEXER_SUBTRACT, /**< "-" (prec: 14) */ + LEXER_MULTIPLY, /**< "*" (prec: 15) */ + LEXER_DIVIDE, /**< "/" (prec: 15) */ + LEXER_MODULO, /**< "%" (prec: 15) */ #if JERRY_ESNEXT - LEXER_EXPONENTIATION, /**< "**" (prec: 16) */ + LEXER_EXPONENTIATION, /**< "**" (prec: 16) */ #endif /* JERRY_ESNEXT */ - LEXER_LEFT_BRACE, /**< "{" */ - LEXER_LEFT_PAREN, /**< "(" */ - LEXER_LEFT_SQUARE, /**< "[" */ - LEXER_RIGHT_BRACE, /**< "}" */ - LEXER_RIGHT_PAREN, /**< ")" */ - LEXER_RIGHT_SQUARE, /**< "]" */ - LEXER_DOT, /**< "." */ - LEXER_SEMICOLON, /**< ";" */ - LEXER_COLON, /**< ":" */ - LEXER_COMMA, /**< "," */ + LEXER_LEFT_BRACE, /**< "{" */ + LEXER_LEFT_PAREN, /**< "(" */ + LEXER_LEFT_SQUARE, /**< "[" */ + LEXER_RIGHT_BRACE, /**< "}" */ + LEXER_RIGHT_PAREN, /**< ")" */ + LEXER_RIGHT_SQUARE, /**< "]" */ + LEXER_DOT, /**< "." */ + LEXER_SEMICOLON, /**< ";" */ + LEXER_COLON, /**< ":" */ + LEXER_COMMA, /**< "," */ #if JERRY_ESNEXT - LEXER_ARROW, /**< "=>" */ + LEXER_ARROW, /**< "=>" */ #endif /* JERRY_ESNEXT */ - LEXER_KEYW_BREAK, /**< break */ - LEXER_KEYW_DO, /**< do */ - LEXER_KEYW_CASE, /**< case */ - LEXER_KEYW_ELSE, /**< else */ - LEXER_KEYW_NEW, /**< new */ - LEXER_KEYW_VAR, /**< var */ - LEXER_KEYW_CATCH, /**< catch */ - LEXER_KEYW_FINALLY, /**< finally */ - LEXER_KEYW_RETURN, /**< return */ - LEXER_KEYW_CONTINUE, /**< continue */ - LEXER_KEYW_FOR, /**< for */ - LEXER_KEYW_SWITCH, /**< switch */ - LEXER_KEYW_WHILE, /**< while */ - LEXER_KEYW_DEBUGGER, /**< debugger */ - LEXER_KEYW_FUNCTION, /**< function */ - LEXER_KEYW_WITH, /**< with */ - LEXER_KEYW_DEFAULT, /**< default */ - LEXER_KEYW_IF, /**< if */ - LEXER_KEYW_THROW, /**< throw */ - LEXER_KEYW_TRY, /**< try */ - - LEXER_KEYW_CLASS, /**< class */ - LEXER_KEYW_EXTENDS, /**< extends */ - LEXER_KEYW_SUPER, /**< super */ - LEXER_KEYW_CONST, /**< const */ - LEXER_KEYW_EXPORT, /**< export */ - LEXER_KEYW_IMPORT, /**< import */ - LEXER_KEYW_ENUM, /**< enum */ + LEXER_KEYW_BREAK, /**< break */ + LEXER_KEYW_DO, /**< do */ + LEXER_KEYW_CASE, /**< case */ + LEXER_KEYW_ELSE, /**< else */ + LEXER_KEYW_NEW, /**< new */ + LEXER_KEYW_VAR, /**< var */ + LEXER_KEYW_CATCH, /**< catch */ + LEXER_KEYW_FINALLY, /**< finally */ + LEXER_KEYW_RETURN, /**< return */ + LEXER_KEYW_CONTINUE, /**< continue */ + LEXER_KEYW_FOR, /**< for */ + LEXER_KEYW_SWITCH, /**< switch */ + LEXER_KEYW_WHILE, /**< while */ + LEXER_KEYW_DEBUGGER, /**< debugger */ + LEXER_KEYW_FUNCTION, /**< function */ + LEXER_KEYW_WITH, /**< with */ + LEXER_KEYW_DEFAULT, /**< default */ + LEXER_KEYW_IF, /**< if */ + LEXER_KEYW_THROW, /**< throw */ + LEXER_KEYW_TRY, /**< try */ + + LEXER_KEYW_CLASS, /**< class */ + LEXER_KEYW_EXTENDS, /**< extends */ + LEXER_KEYW_SUPER, /**< super */ + LEXER_KEYW_CONST, /**< const */ + LEXER_KEYW_EXPORT, /**< export */ + LEXER_KEYW_IMPORT, /**< import */ + LEXER_KEYW_ENUM, /**< enum */ #define LEXER_FIRST_NON_RESERVED_KEYWORD LEXER_EXPRESSION_START /* These are virtual tokens. */ - LEXER_EXPRESSION_START, /**< expression start */ - LEXER_PROPERTY_GETTER, /**< property getter function */ - LEXER_PROPERTY_SETTER, /**< property setter function */ - LEXER_COMMA_SEP_LIST, /**< comma separated bracketed expression list */ + LEXER_EXPRESSION_START, /**< expression start */ + LEXER_PROPERTY_GETTER, /**< property getter function */ + LEXER_PROPERTY_SETTER, /**< property setter function */ + LEXER_COMMA_SEP_LIST, /**< comma separated bracketed expression list */ #if JERRY_ESNEXT - LEXER_ASSIGN_GROUP_EXPR, /**< indetifier for the assignment is located in a group expression */ - LEXER_ASSIGN_CONST, /**< a const binding is reassigned */ - LEXER_INVALID_PATTERN, /**< special value for invalid destructuring pattern */ + LEXER_ASSIGN_GROUP_EXPR, /**< indetifier for the assignment is located in a group expression */ + LEXER_ASSIGN_CONST, /**< a const binding is reassigned */ + LEXER_INVALID_PATTERN, /**< special value for invalid destructuring pattern */ #endif /* JERRY_ESNEXT */ - /* Keywords which are not keyword tokens. */ +/* Keywords which are not keyword tokens. */ #if JERRY_ESNEXT - LEXER_KEYW_ASYNC, /**< async */ + LEXER_KEYW_ASYNC, /**< async */ #endif /* JERRY_ESNEXT */ #if JERRY_MODULE_SYSTEM - LEXER_KEYW_META, /**< meta */ + LEXER_KEYW_META, /**< meta */ #endif /* JERRY_MODULE_SYSTEM */ - /* Keywords which cannot be assigned in strict mode. */ +/* Keywords which cannot be assigned in strict mode. */ #define LEXER_FIRST_NON_STRICT_ARGUMENTS LEXER_KEYW_EVAL - LEXER_KEYW_EVAL, /**< eval */ - LEXER_KEYW_ARGUMENTS, /**< arguments */ + LEXER_KEYW_EVAL, /**< eval */ + LEXER_KEYW_ARGUMENTS, /**< arguments */ - /* Future strict reserved words: these keywords - * must form a group after non-reserved keywords. */ +/* Future strict reserved words: these keywords + * must form a group after non-reserved keywords. */ #define LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD LEXER_KEYW_IMPLEMENTS - LEXER_KEYW_IMPLEMENTS, /**< implements */ - LEXER_KEYW_PRIVATE, /**< private */ - LEXER_KEYW_PUBLIC, /**< public */ - LEXER_KEYW_INTERFACE, /**< interface */ - LEXER_KEYW_PACKAGE, /**< package */ - LEXER_KEYW_PROTECTED, /**< protected */ + LEXER_KEYW_IMPLEMENTS, /**< implements */ + LEXER_KEYW_PRIVATE, /**< private */ + LEXER_KEYW_PUBLIC, /**< public */ + LEXER_KEYW_INTERFACE, /**< interface */ + LEXER_KEYW_PACKAGE, /**< package */ + LEXER_KEYW_PROTECTED, /**< protected */ /* Context dependent future strict reserved words: * See also: ECMA-262 v6, 11.6.2.1 */ - LEXER_KEYW_LET, /**< let */ - LEXER_KEYW_YIELD, /**< yield */ - LEXER_KEYW_STATIC, /**< static */ + LEXER_KEYW_LET, /**< let */ + LEXER_KEYW_YIELD, /**< yield */ + LEXER_KEYW_STATIC, /**< static */ } lexer_token_type_t; #define LEXER_NEWLINE_LS_PS_BYTE_1 0xe2 @@ -245,17 +245,14 @@ typedef enum #define LEXER_IS_RIGHT_BRACKET(type) \ ((type) == LEXER_RIGHT_BRACE || (type) == LEXER_RIGHT_PAREN || (type) == LEXER_RIGHT_SQUARE) -#define LEXER_UNARY_OP_TOKEN_TO_OPCODE(token_type) \ - ((((token_type) - LEXER_PLUS) * 2) + CBC_PLUS) +#define LEXER_UNARY_OP_TOKEN_TO_OPCODE(token_type) ((((token_type) -LEXER_PLUS) * 2) + CBC_PLUS) -#define LEXER_UNARY_LVALUE_OP_TOKEN_TO_OPCODE(token_type) \ - ((((token_type) - LEXER_INCREASE) * 6) + CBC_PRE_INCR) +#define LEXER_UNARY_LVALUE_OP_TOKEN_TO_OPCODE(token_type) ((((token_type) -LEXER_INCREASE) * 6) + CBC_PRE_INCR) -#define LEXER_BINARY_OP_TOKEN_TO_OPCODE(token_type) \ - ((uint16_t) ((((token_type) - LEXER_BIT_OR) * 3) + CBC_BIT_OR)) +#define LEXER_BINARY_OP_TOKEN_TO_OPCODE(token_type) ((uint16_t) ((((token_type) -LEXER_BIT_OR) * 3) + CBC_BIT_OR)) #define LEXER_BINARY_LVALUE_OP_TOKEN_TO_OPCODE(token_type) \ - ((cbc_opcode_t) ((((token_type) - LEXER_ASSIGN_ADD) * 2) + CBC_ASSIGN_ADD)) + ((cbc_opcode_t) ((((token_type) -LEXER_ASSIGN_ADD) * 2) + CBC_ASSIGN_ADD)) /** * Maximum local buffer size for identifiers which contains escape sequences. @@ -267,8 +264,8 @@ typedef enum */ typedef enum { - LEXER_WAS_NEWLINE = (1u << 0), /**< newline was seen */ - LEXER_NO_SKIP_SPACES = (1u << 1) /**< ignore skip spaces */ + LEXER_WAS_NEWLINE = (1u << 0), /**< newline was seen */ + LEXER_NO_SKIP_SPACES = (1u << 1) /**< ignore skip spaces */ } lexer_newline_flags_t; /** @@ -276,15 +273,15 @@ typedef enum */ typedef enum { - LEXER_OBJ_IDENT_NO_OPTS = 0, /**< no options */ - LEXER_OBJ_IDENT_ONLY_IDENTIFIERS = (1u << 0), /**< only identifiers are accepted */ - LEXER_OBJ_IDENT_CLASS_IDENTIFIER = (1u << 1), /**< expect identifier inside a class body */ - LEXER_OBJ_IDENT_CLASS_NO_STATIC = (1u << 2), /**< static keyword was not present before the identifier */ - LEXER_OBJ_IDENT_OBJECT_PATTERN = (1u << 3), /**< parse "get"/"set" as string literal in object pattern */ + LEXER_OBJ_IDENT_NO_OPTS = 0, /**< no options */ + LEXER_OBJ_IDENT_ONLY_IDENTIFIERS = (1u << 0), /**< only identifiers are accepted */ + LEXER_OBJ_IDENT_CLASS_IDENTIFIER = (1u << 1), /**< expect identifier inside a class body */ + LEXER_OBJ_IDENT_CLASS_NO_STATIC = (1u << 2), /**< static keyword was not present before the identifier */ + LEXER_OBJ_IDENT_OBJECT_PATTERN = (1u << 3), /**< parse "get"/"set" as string literal in object pattern */ #if JERRY_FUNCTION_TO_STRING LEXER_OBJ_IDENT_SET_FUNCTION_START = (1u << 4), /**< set function start */ #else /* !JERRY_FUNCTION_TO_STRING */ - LEXER_OBJ_IDENT_SET_FUNCTION_START = 0, /**< set function start (disabled) */ + LEXER_OBJ_IDENT_SET_FUNCTION_START = 0, /**< set function start (disabled) */ #endif /* JERRY_FUNCTION_TO_STRING */ } lexer_obj_ident_opts_t; @@ -293,8 +290,8 @@ typedef enum */ typedef enum { - LEXER_STRING_NO_OPTS = (1u << 0), /**< no options */ - LEXER_STRING_RAW = (1u << 1), /**< raw string ECMAScript v6, 11.8.6.1: TVR */ + LEXER_STRING_NO_OPTS = (1u << 0), /**< no options */ + LEXER_STRING_RAW = (1u << 1), /**< raw string ECMAScript v6, 11.8.6.1: TVR */ } lexer_string_options_t; /** @@ -302,12 +299,12 @@ typedef enum */ typedef enum { - LEXER_NUMBER_DECIMAL, /**< decimal number */ - LEXER_NUMBER_HEXADECIMAL, /**< hexadecimal number */ - LEXER_NUMBER_OCTAL, /**< octal number */ - LEXER_NUMBER_BINARY, /**< binary number */ + LEXER_NUMBER_DECIMAL, /**< decimal number */ + LEXER_NUMBER_HEXADECIMAL, /**< hexadecimal number */ + LEXER_NUMBER_OCTAL, /**< octal number */ + LEXER_NUMBER_BINARY, /**< binary number */ #if JERRY_BUILTIN_BIGINT - LEXER_NUMBER_BIGINT, /**< bigint number */ + LEXER_NUMBER_BIGINT, /**< bigint number */ #endif /* JERRY_BUILTIN_BIGINT */ } lexer_number_type_t; @@ -316,9 +313,9 @@ typedef enum **/ typedef enum { - LEXER_LIT_LOCATION_NO_OPTS = 0, /**< no options */ + LEXER_LIT_LOCATION_NO_OPTS = 0, /**< no options */ LEXER_LIT_LOCATION_HAS_ESCAPE = (1 << 0), /**< binding has escape */ - LEXER_LIT_LOCATION_IS_ASCII = (1 << 1), /**< all characters are ascii characters */ + LEXER_LIT_LOCATION_IS_ASCII = (1 << 1), /**< all characters are ascii characters */ } lexer_lit_location_flags_t; /** @@ -326,10 +323,10 @@ typedef enum */ typedef struct { - const uint8_t *char_p; /**< start of identifier or string token */ - prop_length_t length; /**< length or index of a literal */ - uint8_t type; /**< type of the current literal */ - uint8_t status_flags; /**< any combination of lexer_lit_location_flags_t status bits */ + const uint8_t *char_p; /**< start of identifier or string token */ + prop_length_t length; /**< length or index of a literal */ + uint8_t type; /**< type of the current literal */ + uint8_t status_flags; /**< any combination of lexer_lit_location_flags_t status bits */ } lexer_lit_location_t; /** @@ -337,13 +334,13 @@ typedef struct */ typedef struct { - uint8_t type; /**< token type */ - uint8_t keyword_type; /**< keyword type for identifiers */ - uint8_t extra_value; /**< helper value for different purposes */ - uint8_t flags; /**< flag bits for the current token */ - parser_line_counter_t line; /**< token start line */ - parser_line_counter_t column; /**< token start column */ - lexer_lit_location_t lit_location; /**< extra data for character literals */ + uint8_t type; /**< token type */ + uint8_t keyword_type; /**< keyword type for identifiers */ + uint8_t extra_value; /**< helper value for different purposes */ + uint8_t flags; /**< flag bits for the current token */ + parser_line_counter_t line; /**< token start line */ + parser_line_counter_t column; /**< token start column */ + lexer_lit_location_t lit_location; /**< extra data for character literals */ } lexer_token_t; /** @@ -351,8 +348,8 @@ typedef struct */ typedef struct { - lexer_literal_t *literal_p; /**< pointer to the literal object */ - uint16_t index; /**< literal index */ + lexer_literal_t *literal_p; /**< pointer to the literal object */ + uint16_t index; /**< literal index */ } lexer_lit_object_t; /** diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index 87d53ca7..9250fa57 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -16,11 +16,11 @@ #include "js-parser-internal.h" #if JERRY_PARSER -#include "jcontext.h" - #include "ecma-helpers.h" -#include "lit-char-helpers.h" + +#include "jcontext.h" #include "js-parser-tagged-template-literal.h" +#include "lit-char-helpers.h" /** \addtogroup parser Parser * @{ @@ -58,8 +58,7 @@ * See also: * lexer_token_type_t */ -static const uint8_t parser_binary_precedence_table[] = -{ +static const uint8_t parser_binary_precedence_table[] = { 3, /**< "=" */ 3, /**< "+=" */ 3, /**< "-=" */ @@ -125,8 +124,7 @@ parser_push_result (parser_context_t *context_p) /**< context */ { JERRY_ASSERT (CBC_SAME_ARGS (context_p->last_cbc_opcode, context_p->last_cbc_opcode + 1)); - if ((context_p->last_cbc_opcode == CBC_POST_INCR - || context_p->last_cbc_opcode == CBC_POST_DECR) + if ((context_p->last_cbc_opcode == CBC_POST_INCR || context_p->last_cbc_opcode == CBC_POST_DECR) && context_p->stack_depth >= context_p->stack_limit) { /* Stack limit is increased for CBC_POST_INCR_PUSH_RESULT @@ -181,10 +179,10 @@ parser_check_invalid_new_target (parser_context_t *context_p, /**< parser contex { /* Make sure that the call side is a post/pre increment or an assignment expression. * There should be no other ways the "new.target" expression should be here. */ - JERRY_ASSERT ((opcode >= CBC_PRE_INCR && opcode <= CBC_POST_DECR) - || (opcode == CBC_ASSIGN - && (context_p->token.type == LEXER_ASSIGN - || LEXER_IS_BINARY_LVALUE_OP_TOKEN (context_p->token.type)))); + JERRY_ASSERT ( + (opcode >= CBC_PRE_INCR && opcode <= CBC_POST_DECR) + || (opcode == CBC_ASSIGN + && (context_p->token.type == LEXER_ASSIGN || LEXER_IS_BINARY_LVALUE_OP_TOKEN (context_p->token.type)))); parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_NOT_ALLOWED); } @@ -396,11 +394,11 @@ parser_parse_array_literal (parser_context_t *context_p) /**< context */ */ typedef enum { - PARSER_OBJECT_PROPERTY_START, /**< marks the start of the property list */ - PARSER_OBJECT_PROPERTY_VALUE, /**< value property */ - PARSER_OBJECT_PROPERTY_GETTER, /**< getter property */ - PARSER_OBJECT_PROPERTY_SETTER, /**< setter property */ - PARSER_OBJECT_PROPERTY_BOTH_ACCESSORS, /**< both getter and setter properties are set */ + PARSER_OBJECT_PROPERTY_START, /**< marks the start of the property list */ + PARSER_OBJECT_PROPERTY_VALUE, /**< value property */ + PARSER_OBJECT_PROPERTY_GETTER, /**< getter property */ + PARSER_OBJECT_PROPERTY_SETTER, /**< setter property */ + PARSER_OBJECT_PROPERTY_BOTH_ACCESSORS, /**< both getter and setter properties are set */ } parser_object_literal_item_types_t; /** @@ -455,21 +453,18 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */ if (current_item_index == item_index) { - if (item_type == PARSER_OBJECT_PROPERTY_VALUE - && *current_item_type_p == PARSER_OBJECT_PROPERTY_VALUE + if (item_type == PARSER_OBJECT_PROPERTY_VALUE && *current_item_type_p == PARSER_OBJECT_PROPERTY_VALUE && !(context_p->status_flags & PARSER_IS_STRICT)) { return; } - if (item_type == PARSER_OBJECT_PROPERTY_GETTER - && *current_item_type_p == PARSER_OBJECT_PROPERTY_SETTER) + if (item_type == PARSER_OBJECT_PROPERTY_GETTER && *current_item_type_p == PARSER_OBJECT_PROPERTY_SETTER) { break; } - if (item_type == PARSER_OBJECT_PROPERTY_SETTER - && *current_item_type_p == PARSER_OBJECT_PROPERTY_GETTER) + if (item_type == PARSER_OBJECT_PROPERTY_SETTER && *current_item_type_p == PARSER_OBJECT_PROPERTY_GETTER) { break; } @@ -491,21 +486,19 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT /** Forward definition of parse array initializer. */ -static void -parser_parse_array_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); +static void parser_parse_array_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); /** Forward definition of parse object initializer. */ -static void -parser_parse_object_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); +static void parser_parse_object_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); /** * Class literal parsing options. */ typedef enum { - PARSER_CLASS_LITERAL_NO_OPTS = 0, /**< no options are provided */ - PARSER_CLASS_LITERAL_CTOR_PRESENT = (1 << 0), /**< class constructor is present */ - PARSER_CLASS_LITERAL_HERTIAGE_PRESENT = (1 << 1), /**< class heritage is present */ + PARSER_CLASS_LITERAL_NO_OPTS = 0, /**< no options are provided */ + PARSER_CLASS_LITERAL_CTOR_PRESENT = (1 << 0), /**< class constructor is present */ + PARSER_CLASS_LITERAL_HERTIAGE_PRESENT = (1 << 1), /**< class heritage is present */ } parser_class_literal_opts_t; /** @@ -561,9 +554,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ lexer_skip_empty_statements (context_p); } - lexer_expect_object_literal_id (context_p, (LEXER_OBJ_IDENT_CLASS_IDENTIFIER - | LEXER_OBJ_IDENT_SET_FUNCTION_START - | (is_static ? 0 : LEXER_OBJ_IDENT_CLASS_NO_STATIC))); + lexer_expect_object_literal_id (context_p, + (LEXER_OBJ_IDENT_CLASS_IDENTIFIER | LEXER_OBJ_IDENT_SET_FUNCTION_START + | (is_static ? 0 : LEXER_OBJ_IDENT_CLASS_NO_STATIC))); if (context_p->token.type == LEXER_RIGHT_BRACE) { @@ -590,10 +583,8 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ parser_raise_error (context_p, PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS); } - uint32_t constructor_status_flags = (PARSER_FUNCTION_CLOSURE - | PARSER_ALLOW_SUPER - | PARSER_CLASS_CONSTRUCTOR - | PARSER_LEXICAL_ENV_NEEDED); + uint32_t constructor_status_flags = + (PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER | PARSER_CLASS_CONSTRUCTOR | PARSER_LEXICAL_ENV_NEEDED); if (opts & PARSER_CLASS_LITERAL_HERTIAGE_PRESENT) { @@ -645,9 +636,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ function_literal_index = lexer_construct_function_object (context_p, accessor_status_flags); - parser_emit_cbc_literal (context_p, - CBC_PUSH_LITERAL, - literal_index); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, literal_index); JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); @@ -682,8 +671,8 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ if (is_computed) { - parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME - : CBC_EXT_SET_COMPUTED_SETTER_NAME); + parser_emit_cbc_ext (context_p, + is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME : CBC_EXT_SET_COMPUTED_SETTER_NAME); parser_emit_cbc_ext (context_p, opcode); } else @@ -780,8 +769,8 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ } else { - parser_emit_cbc_ext (context_p, (is_static ? CBC_EXT_ADD_STATIC_COMPUTED_FIELD - : CBC_EXT_ADD_COMPUTED_FIELD)); + parser_emit_cbc_ext (context_p, + (is_static ? CBC_EXT_ADD_STATIC_COMPUTED_FIELD : CBC_EXT_ADD_COMPUTED_FIELD)); } } @@ -839,9 +828,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ { JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL || context_p->token.lit_location.type == LEXER_STRING_LITERAL); - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - LEXER_STRING_LITERAL); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); } else { @@ -853,15 +840,12 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */ uint16_t literal_index = context_p->lit_object.index; uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags | PARSER_IS_METHOD); - parser_emit_cbc_literal (context_p, - CBC_PUSH_LITERAL, - function_literal_index); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); if (is_computed) { parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME); - parser_emit_cbc_ext (context_p, is_static ? CBC_EXT_SET_STATIC_COMPUTED_PROPERTY - : CBC_EXT_SET_COMPUTED_PROPERTY); + parser_emit_cbc_ext (context_p, is_static ? CBC_EXT_SET_STATIC_COMPUTED_PROPERTY : CBC_EXT_SET_COMPUTED_PROPERTY); is_static = false; continue; } @@ -952,8 +936,7 @@ parser_parse_class (parser_context_t *context_p, /**< context */ { /* Class statement must contain an identifier. */ lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); if (context_p->next_scanner_info_p->source_p == context_p->source_p) { @@ -1055,8 +1038,7 @@ parser_parse_class (parser_context_t *context_p, /**< context */ if (class_ident_index < PARSER_REGISTER_START) { - opcode = (scanner_literal_is_created (context_p, class_ident_index) ? CBC_ASSIGN_LET_CONST - : CBC_INIT_LET); + opcode = (scanner_literal_is_created (context_p, class_ident_index) ? CBC_ASSIGN_LET_CONST : CBC_INIT_LET); } parser_emit_cbc_literal (context_p, (uint16_t) opcode, class_ident_index); @@ -1085,13 +1067,10 @@ parser_parse_object_method (parser_context_t *context_p) /**< context */ { context_p->source_p--; context_p->column--; - uint16_t function_literal_index = lexer_construct_function_object (context_p, (PARSER_FUNCTION_CLOSURE - | PARSER_ALLOW_SUPER - | PARSER_IS_METHOD)); + uint16_t function_literal_index = + lexer_construct_function_object (context_p, (PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER | PARSER_IS_METHOD)); - parser_emit_cbc_literal (context_p, - CBC_PUSH_LITERAL, - function_literal_index); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); context_p->last_cbc.literal_type = LEXER_FUNCTION_LITERAL; @@ -1127,9 +1106,7 @@ parser_reparse_as_common_identifier (parser_context_t *context_p, /**< context * JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL); - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - LEXER_IDENT_LITERAL); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); } /* parser_reparse_as_common_identifier */ #endif /* JERRY_ESNEXT */ @@ -1217,8 +1194,7 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ if (is_computed) { - opcode = ((opcode == CBC_EXT_SET_GETTER) ? CBC_EXT_SET_COMPUTED_GETTER - : CBC_EXT_SET_COMPUTED_SETTER); + opcode = ((opcode == CBC_EXT_SET_GETTER) ? CBC_EXT_SET_COMPUTED_GETTER : CBC_EXT_SET_COMPUTED_SETTER); } #else /* !JERRY_ESNEXT */ parser_append_object_literal_item (context_p, literal_index, item_type); @@ -1233,17 +1209,15 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ } #endif /* JERRY_ESNEXT */ - parser_emit_cbc_literal (context_p, - CBC_PUSH_LITERAL, - literal_index); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, literal_index); JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); #if JERRY_ESNEXT if (is_computed) { - parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME - : CBC_EXT_SET_COMPUTED_SETTER_NAME); + parser_emit_cbc_ext (context_p, + is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME : CBC_EXT_SET_COMPUTED_SETTER_NAME); if (has_super_env) { @@ -1261,8 +1235,7 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; context_p->last_cbc.value = function_literal_index; parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED); - parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER - : CBC_EXT_SET_COMPUTED_SETTER); + parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER : CBC_EXT_SET_COMPUTED_SETTER); } else #endif /* JERRY_ESNEXT */ @@ -1366,9 +1339,7 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags); - parser_emit_cbc_literal (context_p, - CBC_PUSH_LITERAL, - function_literal_index); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); @@ -1426,9 +1397,7 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ parser_line_counter_t start_line = context_p->token.line; parser_line_counter_t start_column = context_p->token.column; #else /* !JERRY_ESNEXT */ - parser_append_object_literal_item (context_p, - literal_index, - PARSER_OBJECT_PROPERTY_VALUE); + parser_append_object_literal_item (context_p, literal_index, PARSER_OBJECT_PROPERTY_VALUE); #endif /* JERRY_ESNEXT */ lexer_next_token (context_p); @@ -1453,8 +1422,7 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ break; } - if ((context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_COMMA) - && !is_proto) + if ((context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_COMMA) && !is_proto) { parser_reparse_as_common_identifier (context_p, start_line, start_column); parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); @@ -1565,9 +1533,8 @@ parser_parse_function_expression (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT uint32_t parent_status_flags = context_p->status_flags; - context_p->status_flags &= (uint32_t) ~(PARSER_IS_ASYNC_FUNCTION - | PARSER_IS_GENERATOR_FUNCTION - | PARSER_DISALLOW_AWAIT_YIELD); + context_p->status_flags &= + (uint32_t) ~(PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD); if (status_flags & PARSER_IS_ASYNC_FUNCTION) { @@ -1587,8 +1554,7 @@ parser_parse_function_expression (parser_context_t *context_p, /**< context */ { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); } @@ -1664,9 +1630,7 @@ parser_parse_function_expression (parser_context_t *context_p, /**< context */ } else { - parser_emit_cbc_literal (context_p, - CBC_PUSH_LITERAL, - function_literal_index); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); if (function_name_index != -1) { @@ -1693,9 +1657,7 @@ parser_parse_template_literal (parser_context_t *context_p) /**< context */ { is_empty_head = false; - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - context_p->token.lit_location.type); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); } @@ -1730,9 +1692,7 @@ parser_parse_template_literal (parser_context_t *context_p) /**< context */ if (is_empty_head || context_p->token.lit_location.length > 0) { - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - context_p->token.lit_location.type); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) { @@ -1773,9 +1733,7 @@ parser_parse_template_literal (parser_context_t *context_p) /**< context */ if (context_p->token.lit_location.length > 0) { - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - context_p->token.lit_location.type); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); parser_emit_cbc_ext_literal_from_token (context_p, CBC_EXT_STRING_CONCAT_RIGHT_LITERAL); } @@ -1855,8 +1813,7 @@ parser_parse_tagged_template_literal (parser_context_t *context_p) /**< context static inline bool JERRY_ATTR_ALWAYS_INLINE parser_is_assignment_expr (parser_context_t *context_p) { - return (context_p->stack_top_uint8 == LEXER_EXPRESSION_START - || context_p->stack_top_uint8 == LEXER_LEFT_PAREN + return (context_p->stack_top_uint8 == LEXER_EXPRESSION_START || context_p->stack_top_uint8 == LEXER_LEFT_PAREN || context_p->stack_top_uint8 == LEXER_COMMA_SEP_LIST || LEXER_IS_BINARY_LVALUE_OP_TOKEN (context_p->stack_top_uint8)); } /* parser_is_assignment_expr */ @@ -1879,8 +1836,7 @@ parser_check_assignment_expr (parser_context_t *context_p) static inline bool JERRY_ATTR_ALWAYS_INLINE parser_abort_parsing_after_assignment_expression (parser_context_t *context_p) { - return (context_p->token.type != LEXER_RIGHT_PAREN - && context_p->token.type != LEXER_COMMA); + return (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_COMMA); } /* parser_abort_parsing_after_assignment_expression */ #endif /* JERRY_ESNEXT */ @@ -1968,8 +1924,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ } - else if (new_was_seen - || (*grouping_level_p == PARSE_EXPR_LEFT_HAND_SIDE) + else if (new_was_seen || (*grouping_level_p == PARSE_EXPR_LEFT_HAND_SIDE) || !LEXER_IS_UNARY_OP_TOKEN (context_p->token.type)) { break; @@ -2006,9 +1961,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ context_p->function_start_p = context_p->token.lit_location.char_p; #endif /* JERRY_FUNCTION_TO_STRING */ - uint32_t arrow_status_flags = (PARSER_IS_FUNCTION - | PARSER_IS_ARROW_FUNCTION - | (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD)); + uint32_t arrow_status_flags = + (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD)); if (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_ASYNC) { @@ -2023,18 +1977,14 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ if (context_p->token.type == LEXER_KEYW_FUNCTION) { - uint32_t status_flags = (PARSER_FUNCTION_CLOSURE - | PARSER_IS_FUNC_EXPRESSION - | PARSER_IS_ASYNC_FUNCTION + uint32_t status_flags = (PARSER_FUNCTION_CLOSURE | PARSER_IS_FUNC_EXPRESSION | PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD); parser_parse_function_expression (context_p, status_flags); break; } - arrow_status_flags = (PARSER_IS_FUNCTION - | PARSER_IS_ARROW_FUNCTION - | PARSER_IS_ASYNC_FUNCTION - | PARSER_DISALLOW_AWAIT_YIELD); + arrow_status_flags = + (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD); } parser_check_assignment_expr (context_p); @@ -2047,9 +1997,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ if (type == LEXER_IDENT_LITERAL || type == LEXER_STRING_LITERAL) { - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - context_p->token.lit_location.type); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); } else if (type == LEXER_NUMBER_LITERAL) { @@ -2071,9 +2019,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ } #endif /* JERRY_BUILTIN_BIGINT */ parser_stack_pop_uint8 (context_p); - } - while (context_p->stack_top_uint8 == LEXER_PLUS - || context_p->stack_top_uint8 == LEXER_NEGATE); + } while (context_p->stack_top_uint8 == LEXER_PLUS || context_p->stack_top_uint8 == LEXER_NEGATE); } if (lexer_construct_number_object (context_p, true, is_negative_number)) @@ -2272,9 +2218,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ context_p->function_start_p = context_p->source_p - 1; #endif /* JERRY_FUNCTION_TO_STRING */ - uint32_t arrow_status_flags = (PARSER_IS_FUNCTION - | PARSER_IS_ARROW_FUNCTION - | (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD)); + uint32_t arrow_status_flags = + (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD)); parser_parse_function_expression (context_p, arrow_status_flags); return parser_abort_parsing_after_assignment_expression (context_p); } @@ -2291,8 +2236,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ parser_check_assignment_expr (context_p); lexer_next_token (context_p); - cbc_ext_opcode_t opcode = ((context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) ? CBC_EXT_ASYNC_YIELD - : CBC_EXT_YIELD); + cbc_ext_opcode_t opcode = + ((context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) ? CBC_EXT_ASYNC_YIELD : CBC_EXT_YIELD); if (!lexer_check_yield_no_arg (context_p)) { if (context_p->token.type == LEXER_MULTIPLY) @@ -2311,8 +2256,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ parser_emit_cbc_ext (context_p, opcode); - return (context_p->token.type != LEXER_RIGHT_PAREN - && context_p->token.type != LEXER_COMMA); + return (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_COMMA); } #endif /* JERRY_ESNEXT */ #if JERRY_MODULE_SYSTEM @@ -2324,8 +2268,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL || context_p->token.keyword_type != LEXER_KEYW_META || (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) { @@ -2368,8 +2311,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ default: { bool is_left_hand_side = (*grouping_level_p == PARSE_EXPR_LEFT_HAND_SIDE); - parser_raise_error (context_p, (is_left_hand_side ? PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED - : PARSER_ERR_UNEXPECTED_END)); + parser_raise_error (context_p, + (is_left_hand_side ? PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED : PARSER_ERR_UNEXPECTED_END)); break; } } @@ -2404,8 +2347,7 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */ if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) { - JERRY_ASSERT (CBC_ARGS_EQ (CBC_PUSH_PROP_LITERAL_LITERAL, - CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + JERRY_ASSERT (CBC_ARGS_EQ (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); context_p->last_cbc_opcode = CBC_PUSH_PROP_LITERAL_LITERAL; context_p->last_cbc.value = context_p->lit_object.index; } @@ -2739,8 +2681,7 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */ if (!LEXER_IS_UNARY_OP_TOKEN (token)) { #if JERRY_ESNEXT - if (context_p->token.type == LEXER_EXPONENTIATION - && last_unary_token != LEXER_INCREASE + if (context_p->token.type == LEXER_EXPONENTIATION && last_unary_token != LEXER_INCREASE && last_unary_token != LEXER_DECREASE) { parser_raise_error (context_p, PARSER_ERR_INVALID_EXPONENTIATION); @@ -2771,8 +2712,8 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT else if (JERRY_UNLIKELY (token == LEXER_KEYW_AWAIT)) { - cbc_ext_opcode_t opcode = ((context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) ? CBC_EXT_GENERATOR_AWAIT - : CBC_EXT_AWAIT); + cbc_ext_opcode_t opcode = + ((context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) ? CBC_EXT_GENERATOR_AWAIT : CBC_EXT_AWAIT); parser_emit_cbc_ext (context_p, opcode); } #endif /* JERRY_ESNEXT */ @@ -2950,7 +2891,7 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**< #endif /* JERRY_ESNEXT */ else { - /* Invalid LeftHandSide expression. */ //3820, 3815 + /* Invalid LeftHandSide expression. */ // 3820, 3815 #if JERRY_ESNEXT parser_check_invalid_new_target (context_p, CBC_ASSIGN); parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT); @@ -3051,8 +2992,7 @@ parser_append_binary_token (parser_context_t *context_p) /**< context */ parser_emit_cbc (context_p, CBC_PUSH_PROP_REFERENCE); } } - else if (context_p->token.type == LEXER_LOGICAL_OR - || context_p->token.type == LEXER_LOGICAL_AND) + else if (context_p->token.type == LEXER_LOGICAL_OR || context_p->token.type == LEXER_LOGICAL_AND) { parser_branch_t branch; uint16_t opcode = CBC_BRANCH_IF_LOGICAL_TRUE; @@ -3134,13 +3074,9 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */ if (cbc_flags[opcode] & CBC_HAS_LITERAL_ARG) { - JERRY_ASSERT (opcode == CBC_ASSIGN_SET_IDENT - || opcode == CBC_ASSIGN_PROP_LITERAL - || opcode == CBC_ASSIGN_PROP_THIS_LITERAL - || opcode == CBC_ASSIGN_LET_CONST - || opcode == CBC_INIT_ARG_OR_CATCH - || opcode == CBC_INIT_LET - || opcode == CBC_INIT_CONST); + JERRY_ASSERT (opcode == CBC_ASSIGN_SET_IDENT || opcode == CBC_ASSIGN_PROP_LITERAL + || opcode == CBC_ASSIGN_PROP_THIS_LITERAL || opcode == CBC_ASSIGN_LET_CONST + || opcode == CBC_INIT_ARG_OR_CATCH || opcode == CBC_INIT_LET || opcode == CBC_INIT_CONST); index = parser_stack_pop_uint16 (context_p); } @@ -3181,11 +3117,9 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL - && opcode == CBC_ASSIGN_SET_IDENT) + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL && opcode == CBC_ASSIGN_SET_IDENT) { - JERRY_ASSERT (CBC_ARGS_EQ (CBC_ASSIGN_LITERAL_SET_IDENT, - CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + JERRY_ASSERT (CBC_ARGS_EQ (CBC_ASSIGN_LITERAL_SET_IDENT, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); context_p->last_cbc.value = index; context_p->last_cbc_opcode = CBC_ASSIGN_LITERAL_SET_IDENT; @@ -3194,8 +3128,7 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */ parser_emit_cbc_literal (context_p, (uint16_t) opcode, index); - if (opcode == CBC_ASSIGN_PROP_THIS_LITERAL - && (context_p->stack_depth >= context_p->stack_limit)) + if (opcode == CBC_ASSIGN_PROP_THIS_LITERAL && (context_p->stack_depth >= context_p->stack_limit)) { /* Stack limit is increased for VM_OC_ASSIGN_PROP_THIS. Needed by vm.c. */ JERRY_ASSERT (context_p->stack_depth == context_p->stack_limit); @@ -3250,8 +3183,7 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */ } else if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) { - JERRY_ASSERT (CBC_ARGS_EQ (opcode + CBC_BINARY_WITH_TWO_LITERALS, - CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + JERRY_ASSERT (CBC_ARGS_EQ (opcode + CBC_BINARY_WITH_TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); context_p->last_cbc_opcode = (uint16_t) (opcode + CBC_BINARY_WITH_TWO_LITERALS); continue; } @@ -3298,8 +3230,7 @@ parser_pattern_get_target (parser_context_t *context_p, /**< context */ scanner_location_t start_location; if (context_p->next_scanner_info_p->source_p != context_p->source_p - || context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED - || (flags & PARSER_PATTERN_REST_ELEMENT)) + || context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED || (flags & PARSER_PATTERN_REST_ELEMENT)) { /* Found invalid pattern, push null value to fake the rhs target. */ parser_emit_cbc (context_p, CBC_PUSH_NULL); @@ -3398,8 +3329,7 @@ parser_pattern_form_assignment (parser_context_t *context_p, /**< context */ uint16_t name_index = PARSER_INVALID_LITERAL_INDEX; if ((flags & PARSER_PATTERN_BINDING) - || (context_p->last_cbc_opcode == CBC_PUSH_LITERAL - && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)) + || (context_p->last_cbc_opcode == CBC_PUSH_LITERAL && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)) { name_index = context_p->lit_object.index; } @@ -3463,13 +3393,10 @@ parser_pattern_process_nested_pattern (parser_context_t *context_p, /**< context { JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE || context_p->token.type == LEXER_LEFT_SQUARE); - parser_pattern_flags_t options = (PARSER_PATTERN_NESTED_PATTERN - | PARSER_PATTERN_TARGET_ON_STACK - | (flags & (PARSER_PATTERN_BINDING - | PARSER_PATTERN_LET - | PARSER_PATTERN_CONST - | PARSER_PATTERN_LOCAL - | PARSER_PATTERN_ARGUMENTS))); + parser_pattern_flags_t options = (PARSER_PATTERN_NESTED_PATTERN | PARSER_PATTERN_TARGET_ON_STACK + | (flags + & (PARSER_PATTERN_BINDING | PARSER_PATTERN_LET | PARSER_PATTERN_CONST + | PARSER_PATTERN_LOCAL | PARSER_PATTERN_ARGUMENTS))); JERRY_ASSERT (context_p->next_scanner_info_p->source_p != context_p->source_p || context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER @@ -3551,8 +3478,7 @@ parser_pattern_process_assignment (parser_context_t *context_p, /**< context */ lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); - if (flags & (PARSER_PATTERN_LET | PARSER_PATTERN_CONST) - && context_p->token.keyword_type == LEXER_KEYW_LET) + if (flags & (PARSER_PATTERN_LET | PARSER_PATTERN_CONST) && context_p->token.keyword_type == LEXER_KEYW_LET) { parser_raise_error (context_p, PARSER_ERR_LEXICAL_LET_BINDING); } @@ -3578,8 +3504,7 @@ parser_pattern_process_assignment (parser_context_t *context_p, /**< context */ parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); lexer_next_token (context_p); - if (context_p->token.type != end_type - && context_p->token.type != LEXER_ASSIGN + if (context_p->token.type != end_type && context_p->token.type != LEXER_ASSIGN && context_p->token.type != LEXER_COMMA) { parser_raise_error (context_p, PARSER_ERR_ILLEGAL_PROPERTY_IN_DECLARATION); @@ -3722,8 +3647,8 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */ if (context_p->token.type == LEXER_RIGHT_SQUARE) { prop_index = PARSER_PATTERN_RHS_NO_LIT; - push_prop_opcode = ((flags & PARSER_PATTERN_HAS_REST_ELEMENT) ? CBC_EXT_INITIALIZER_PUSH_NAME - : CBC_EXT_INITIALIZER_PUSH_PROP); + push_prop_opcode = + ((flags & PARSER_PATTERN_HAS_REST_ELEMENT) ? CBC_EXT_INITIALIZER_PUSH_NAME : CBC_EXT_INITIALIZER_PUSH_PROP); } else if (flags & PARSER_PATTERN_HAS_REST_ELEMENT) { @@ -3745,14 +3670,12 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */ } else { - if (push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_NAME - || push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_PROP) + if (push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_NAME || push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_PROP) { parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); } - if (context_p->token.type != LEXER_RIGHT_BRACE - && context_p->token.type != LEXER_ASSIGN + if (context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_ASSIGN && context_p->token.type != LEXER_COMMA) { parser_raise_error (context_p, PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED); @@ -3776,8 +3699,7 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */ parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); lexer_next_token (context_p); - JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE - || context_p->token.type == LEXER_ASSIGN + JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_ASSIGN || context_p->token.type == LEXER_COMMA); parser_pattern_form_assignment (context_p, flags, push_prop_opcode, prop_index, start_line); @@ -3798,8 +3720,8 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */ if (flags & PARSER_PATTERN_HAS_REST_ELEMENT) { - PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, (PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION - - PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION)); + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, + (PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION - PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION)); } parser_emit_cbc_ext (context_p, CBC_EXT_OBJ_INIT_CONTEXT_END); @@ -3963,8 +3885,7 @@ parser_process_group_expression (parser_context_t *context_p, /**< context */ if (JERRY_UNLIKELY (context_p->token.type == LEXER_ASSIGN && PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL - && parser_is_assignment_expr (context_p) - && *grouping_level_p != PARSE_EXPR_LEFT_HAND_SIDE)) + && parser_is_assignment_expr (context_p) && *grouping_level_p != PARSE_EXPR_LEFT_HAND_SIDE)) { parser_stack_push_uint8 (context_p, LEXER_ASSIGN_GROUP_EXPR); } @@ -4007,8 +3928,7 @@ parser_parse_expression_statement (parser_context_t *context_p, /**< context */ } } /* parser_parse_expression_statement */ -JERRY_STATIC_ASSERT (PARSE_EXPR_LEFT_HAND_SIDE == 0x1, - value_of_parse_expr_left_hand_side_must_be_1); +JERRY_STATIC_ASSERT (PARSE_EXPR_LEFT_HAND_SIDE == 0x1, value_of_parse_expr_left_hand_side_must_be_1); /** * Parse expression. @@ -4037,7 +3957,7 @@ parser_parse_expression (parser_context_t *context_p, /**< context */ while (true) { -process_unary_expression: + process_unary_expression: parser_process_unary_expression (context_p, grouping_level); if (JERRY_LIKELY (grouping_level != PARSE_EXPR_LEFT_HAND_SIDE)) @@ -4078,8 +3998,7 @@ process_unary_expression: parser_process_binary_opcodes (context_p, min_prec_treshold); } if (context_p->token.type == LEXER_RIGHT_PAREN - && (context_p->stack_top_uint8 == LEXER_LEFT_PAREN - || context_p->stack_top_uint8 == LEXER_COMMA_SEP_LIST)) + && (context_p->stack_top_uint8 == LEXER_LEFT_PAREN || context_p->stack_top_uint8 == LEXER_COMMA_SEP_LIST)) { parser_process_group_expression (context_p, &grouping_level); continue; diff --git a/jerry-core/parser/js/js-parser-internal.h b/jerry-core/parser/js/js-parser-internal.h index 352ea611..b8a3e7e0 100644 --- a/jerry-core/parser/js/js-parser-internal.h +++ b/jerry-core/parser/js/js-parser-internal.h @@ -16,17 +16,16 @@ #ifndef JS_PARSER_INTERNAL_H #define JS_PARSER_INTERNAL_H -#include "common.h" +#include "ecma-module.h" #include "byte-code.h" +#include "common.h" #include "debugger.h" -#include "js-parser.h" -#include "js-parser-limits.h" #include "js-lexer.h" +#include "js-parser-limits.h" +#include "js-parser.h" #include "js-scanner.h" -#include "ecma-module.h" - /** \addtogroup parser Parser * @{ * @@ -42,47 +41,47 @@ */ typedef enum { - PARSER_IS_STRICT = (1u << 0), /**< strict mode code */ - PARSER_IS_FUNCTION = (1u << 1), /**< function body is parsed */ - PARSER_IS_CLOSURE = (1u << 2), /**< function body is encapsulated in {} block */ - PARSER_IS_FUNC_EXPRESSION = (1u << 3), /**< a function expression is parsed */ - PARSER_IS_PROPERTY_GETTER = (1u << 4), /**< a property getter function is parsed */ - PARSER_IS_PROPERTY_SETTER = (1u << 5), /**< a property setter function is parsed */ - PARSER_HAS_NON_STRICT_ARG = (1u << 6), /**< the function has arguments which - * are not supported in strict mode */ - PARSER_ARGUMENTS_NEEDED = (1u << 7), /**< arguments object must be created */ - PARSER_LEXICAL_ENV_NEEDED = (1u << 8), /**< lexical environment object must be created */ - PARSER_INSIDE_WITH = (1u << 9), /**< code block is inside a with statement */ - PARSER_NO_END_LABEL = (1u << 10), /**< return instruction must be inserted - * after the last byte code */ + PARSER_IS_STRICT = (1u << 0), /**< strict mode code */ + PARSER_IS_FUNCTION = (1u << 1), /**< function body is parsed */ + PARSER_IS_CLOSURE = (1u << 2), /**< function body is encapsulated in {} block */ + PARSER_IS_FUNC_EXPRESSION = (1u << 3), /**< a function expression is parsed */ + PARSER_IS_PROPERTY_GETTER = (1u << 4), /**< a property getter function is parsed */ + PARSER_IS_PROPERTY_SETTER = (1u << 5), /**< a property setter function is parsed */ + PARSER_HAS_NON_STRICT_ARG = (1u << 6), /**< the function has arguments which + * are not supported in strict mode */ + PARSER_ARGUMENTS_NEEDED = (1u << 7), /**< arguments object must be created */ + PARSER_LEXICAL_ENV_NEEDED = (1u << 8), /**< lexical environment object must be created */ + PARSER_INSIDE_WITH = (1u << 9), /**< code block is inside a with statement */ + PARSER_NO_END_LABEL = (1u << 10), /**< return instruction must be inserted + * after the last byte code */ PARSER_DEBUGGER_BREAKPOINT_APPENDED = (1u << 11), /**< pending (unsent) breakpoint * info is available */ #if JERRY_ESNEXT - PARSER_LEXICAL_BLOCK_NEEDED = (1u << 12), /**< global script: needs a lexical environment for let and const - * function: needs a lexical environment for arguments */ - PARSER_IS_ARROW_FUNCTION = (1u << 13), /**< an arrow function is parsed */ - PARSER_IS_GENERATOR_FUNCTION = (1u << 14), /**< a generator function is parsed */ - PARSER_IS_ASYNC_FUNCTION = (1u << 15), /**< an async function is parsed */ - PARSER_DISALLOW_AWAIT_YIELD = (1u << 16), /**< throw SyntaxError for await / yield keywords */ + PARSER_LEXICAL_BLOCK_NEEDED = (1u << 12), /**< global script: needs a lexical environment for let and const + * function: needs a lexical environment for arguments */ + PARSER_IS_ARROW_FUNCTION = (1u << 13), /**< an arrow function is parsed */ + PARSER_IS_GENERATOR_FUNCTION = (1u << 14), /**< a generator function is parsed */ + PARSER_IS_ASYNC_FUNCTION = (1u << 15), /**< an async function is parsed */ + PARSER_DISALLOW_AWAIT_YIELD = (1u << 16), /**< throw SyntaxError for await / yield keywords */ PARSER_FUNCTION_IS_PARSING_ARGS = (1u << 17), /**< set when parsing function arguments */ PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT = (1u << 18), /**< function has complex (ES2015+) argument definition */ PARSER_FUNCTION_HAS_REST_PARAM = (1u << 19), /**< function has rest parameter */ - PARSER_CLASS_CONSTRUCTOR = (1u << 20), /**< a class constructor is parsed - * Note: PARSER_ALLOW_SUPER must be present */ + PARSER_CLASS_CONSTRUCTOR = (1u << 20), /**< a class constructor is parsed + * Note: PARSER_ALLOW_SUPER must be present */ /* These four status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */ - PARSER_ALLOW_SUPER = (1u << 21), /**< allow super property access */ - PARSER_ALLOW_SUPER_CALL = (1u << 22), /**< allow super constructor call - * Note: PARSER_CLASS_CONSTRUCTOR must be present */ - PARSER_INSIDE_CLASS_FIELD = (1u << 23), /**< a class field is being parsed */ - PARSER_ALLOW_NEW_TARGET = (1u << 24), /**< allow new.target parsing in the current context */ - PARSER_IS_METHOD = (1u << 25), /**< method is parsed */ + PARSER_ALLOW_SUPER = (1u << 21), /**< allow super property access */ + PARSER_ALLOW_SUPER_CALL = (1u << 22), /**< allow super constructor call + * Note: PARSER_CLASS_CONSTRUCTOR must be present */ + PARSER_INSIDE_CLASS_FIELD = (1u << 23), /**< a class field is being parsed */ + PARSER_ALLOW_NEW_TARGET = (1u << 24), /**< allow new.target parsing in the current context */ + PARSER_IS_METHOD = (1u << 25), /**< method is parsed */ #endif /* JERRY_ESNEXT */ #if JERRY_MODULE_SYSTEM - PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 26), /**< parsing a function or class default export */ - PARSER_MODULE_STORE_IDENT = (1u << 27), /**< store identifier of the current export statement */ + PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 26), /**< parsing a function or class default export */ + PARSER_MODULE_STORE_IDENT = (1u << 27), /**< store identifier of the current export statement */ #endif /* JERRY_MODULE_SYSTEM */ - PARSER_HAS_LATE_LIT_INIT = (1u << 30), /**< there are identifier or string literals which construction - * is postponed after the local parser data is freed */ + PARSER_HAS_LATE_LIT_INIT = (1u << 30), /**< there are identifier or string literals which construction + * is postponed after the local parser data is freed */ #ifndef JERRY_NDEBUG PARSER_SCANNING_SUCCESSFUL = PARSER_HAS_LATE_LIT_INIT, /**< scanning process was successful */ #endif /* !JERRY_NDEBUG */ @@ -93,12 +92,12 @@ typedef enum */ typedef enum { - PARSE_EXPR = 0, /**< parse an expression without any special flags */ - PARSE_EXPR_LEFT_HAND_SIDE = (1u << 0), /**< parse a left-hand-side expression */ - PARSE_EXPR_NO_PUSH_RESULT = (1u << 1), /**< do not push the result of the expression onto the stack */ - PARSE_EXPR_NO_COMMA = (1u << 2), /**< do not parse comma operator */ - PARSE_EXPR_HAS_LITERAL = (1u << 3), /**< a primary literal is provided by a - * CBC_PUSH_LITERAL instruction */ + PARSE_EXPR = 0, /**< parse an expression without any special flags */ + PARSE_EXPR_LEFT_HAND_SIDE = (1u << 0), /**< parse a left-hand-side expression */ + PARSE_EXPR_NO_PUSH_RESULT = (1u << 1), /**< do not push the result of the expression onto the stack */ + PARSE_EXPR_NO_COMMA = (1u << 2), /**< do not parse comma operator */ + PARSE_EXPR_HAS_LITERAL = (1u << 3), /**< a primary literal is provided by a + * CBC_PUSH_LITERAL instruction */ } parser_expression_flags_t; /** @@ -106,17 +105,17 @@ typedef enum */ typedef enum { - PARSER_PATTERN_NO_OPTS = 0, /**< parse the expression after '=' */ - PARSER_PATTERN_BINDING = (1u << 0), /**< parse BindingPattern */ - PARSER_PATTERN_TARGET_ON_STACK = (1u << 1), /**< assignment target is the topmost element on the stack */ - PARSER_PATTERN_TARGET_DEFAULT = (1u << 2), /**< perform default value comparison for assignment target */ - PARSER_PATTERN_NESTED_PATTERN = (1u << 3), /**< parse pattern inside a pattern */ - PARSER_PATTERN_LET = (1u << 4), /**< pattern is a let declaration */ - PARSER_PATTERN_CONST = (1u << 5), /**< pattern is a const declaration */ - PARSER_PATTERN_LOCAL = (1u << 6), /**< pattern is a local (catch parameter) declaration */ - PARSER_PATTERN_REST_ELEMENT = (1u << 7), /**< parse rest array / object element */ + PARSER_PATTERN_NO_OPTS = 0, /**< parse the expression after '=' */ + PARSER_PATTERN_BINDING = (1u << 0), /**< parse BindingPattern */ + PARSER_PATTERN_TARGET_ON_STACK = (1u << 1), /**< assignment target is the topmost element on the stack */ + PARSER_PATTERN_TARGET_DEFAULT = (1u << 2), /**< perform default value comparison for assignment target */ + PARSER_PATTERN_NESTED_PATTERN = (1u << 3), /**< parse pattern inside a pattern */ + PARSER_PATTERN_LET = (1u << 4), /**< pattern is a let declaration */ + PARSER_PATTERN_CONST = (1u << 5), /**< pattern is a const declaration */ + PARSER_PATTERN_LOCAL = (1u << 6), /**< pattern is a local (catch parameter) declaration */ + PARSER_PATTERN_REST_ELEMENT = (1u << 7), /**< parse rest array / object element */ PARSER_PATTERN_HAS_REST_ELEMENT = (1u << 8), /**< object literal rest element will be present */ - PARSER_PATTERN_ARGUMENTS = (1u << 9), /**< parse arguments binding */ + PARSER_PATTERN_ARGUMENTS = (1u << 9), /**< parse arguments binding */ } parser_pattern_flags_t; /** @@ -124,10 +123,10 @@ typedef enum */ typedef enum { - PARSER_CHECK_BLOCK_CONTEXT, /**< check block context */ + PARSER_CHECK_BLOCK_CONTEXT, /**< check block context */ #if JERRY_ESNEXT - PARSER_CHECK_GLOBAL_CONTEXT, /**< check global context */ - PARSER_CHECK_FUNCTION_CONTEXT, /**< check function context */ + PARSER_CHECK_GLOBAL_CONTEXT, /**< check global context */ + PARSER_CHECK_FUNCTION_CONTEXT, /**< check function context */ #endif /* JERRY_ESNEXT */ } parser_check_context_type_t; @@ -138,10 +137,10 @@ typedef enum */ typedef enum { - PARSER_CLASS_FIELD_END = (1u << 0), /**< last class field */ - PARSER_CLASS_FIELD_NORMAL = (1u << 1), /**< normal (non-computed) class field */ - PARSER_CLASS_FIELD_INITIALIZED = (1u << 2), /**< class field is initialized */ - PARSER_CLASS_FIELD_STATIC = (1u << 3), /**< static class field */ + PARSER_CLASS_FIELD_END = (1u << 0), /**< last class field */ + PARSER_CLASS_FIELD_NORMAL = (1u << 1), /**< normal (non-computed) class field */ + PARSER_CLASS_FIELD_INITIALIZED = (1u << 2), /**< class field is initialized */ + PARSER_CLASS_FIELD_STATIC = (1u << 3), /**< static class field */ } parser_class_field_type_t; #endif /* JERRY_ESNEXT */ @@ -172,8 +171,7 @@ typedef enum /** * Offset of PARSER_ALLOW_SUPER */ -#define PARSER_SAVED_FLAGS_OFFSET \ - JERRY_LOG2 (PARSER_ALLOW_SUPER) +#define PARSER_SAVED_FLAGS_OFFSET JERRY_LOG2 (PARSER_ALLOW_SUPER) /** * Mask of saved flags @@ -184,26 +182,23 @@ typedef enum /** * Get class option bits from parser_general_flags_t */ -#define PARSER_SAVE_STATUS_FLAGS(opts) \ - ((uint16_t) (((opts) >> PARSER_SAVED_FLAGS_OFFSET) & PARSER_SAVED_FLAGS_MASK)) +#define PARSER_SAVE_STATUS_FLAGS(opts) ((uint16_t) (((opts) >> PARSER_SAVED_FLAGS_OFFSET) & PARSER_SAVED_FLAGS_MASK)) /** * Mask for get class option bits from ecma_parse_opts_t */ -#define PARSER_RESTORE_STATUS_FLAGS_MASK \ - (((ECMA_PARSE_ALLOW_NEW_TARGET << 1) - 1) - (ECMA_PARSE_ALLOW_SUPER - 1)) +#define PARSER_RESTORE_STATUS_FLAGS_MASK (((ECMA_PARSE_ALLOW_NEW_TARGET << 1) - 1) - (ECMA_PARSE_ALLOW_SUPER - 1)) /** * Shift for get class option bits from ecma_parse_opts_t */ -#define PARSER_RESTORE_STATUS_FLAGS_SHIFT \ - (JERRY_LOG2 (PARSER_ALLOW_SUPER) - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)) +#define PARSER_RESTORE_STATUS_FLAGS_SHIFT (JERRY_LOG2 (PARSER_ALLOW_SUPER) - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)) /** * Get class option bits from ecma_parse_opts_t */ #define PARSER_RESTORE_STATUS_FLAGS(opts) \ - (((opts) & PARSER_RESTORE_STATUS_FLAGS_MASK) << PARSER_RESTORE_STATUS_FLAGS_SHIFT) + (((opts) &PARSER_RESTORE_STATUS_FLAGS_MASK) << PARSER_RESTORE_STATUS_FLAGS_SHIFT) /** * All flags that affect exotic arguments object creation. @@ -214,8 +209,7 @@ typedef enum /** * Get the corresponding eval flag for a ecma_parse_opts_t flag */ -#define PARSER_GET_EVAL_FLAG(type) \ - ((type) >> JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)) +#define PARSER_GET_EVAL_FLAG(type) ((type) >> JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)) /** * Check non-generator async functions @@ -228,63 +222,54 @@ typedef enum /** * All flags that affect exotic arguments object creation. */ -#define PARSER_ARGUMENTS_RELATED_FLAGS \ - (PARSER_ARGUMENTS_NEEDED | PARSER_IS_STRICT) +#define PARSER_ARGUMENTS_RELATED_FLAGS (PARSER_ARGUMENTS_NEEDED | PARSER_IS_STRICT) #endif /* JERRY_ESNEXT */ /* Checks whether unmapped arguments are needed. */ #define PARSER_NEEDS_MAPPED_ARGUMENTS(status_flags) \ - (((status_flags) & PARSER_ARGUMENTS_RELATED_FLAGS) == PARSER_ARGUMENTS_NEEDED) + (((status_flags) &PARSER_ARGUMENTS_RELATED_FLAGS) == PARSER_ARGUMENTS_NEEDED) /* The maximum of PARSER_CBC_STREAM_PAGE_SIZE is 127. */ -#define PARSER_CBC_STREAM_PAGE_SIZE \ - ((uint32_t) (64 - sizeof (void *))) +#define PARSER_CBC_STREAM_PAGE_SIZE ((uint32_t) (64 - sizeof (void *))) /* Defines the size of the max page. */ -#define PARSER_STACK_PAGE_SIZE \ - ((uint32_t) (((sizeof (void *) > 4) ? 128 : 64) - sizeof (void *))) +#define PARSER_STACK_PAGE_SIZE ((uint32_t) (((sizeof (void *) > 4) ? 128 : 64) - sizeof (void *))) /* Avoid compiler warnings for += operations. */ -#define PARSER_PLUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) + (value)) +#define PARSER_PLUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) + (value)) #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)) +#define PARSER_PLUS_EQUAL_LC(base, value) (base) = (parser_line_counter_t) ((base) + (value)) /** * Argument for a compact-byte code. */ typedef struct { - uint16_t literal_index; /**< literal index argument */ - uint16_t value; /**< other argument (second literal or byte). */ - uint16_t third_literal_index; /**< literal index argument */ - uint8_t literal_type; /**< last literal type */ - uint8_t literal_keyword_type; /**< last literal keyword type */ + uint16_t literal_index; /**< literal index argument */ + uint16_t value; /**< other argument (second literal or byte). */ + uint16_t third_literal_index; /**< literal index argument */ + uint8_t literal_type; /**< last literal type */ + uint8_t literal_keyword_type; /**< last literal keyword type */ } cbc_argument_t; /* Useful parser macros. */ #define PARSER_CBC_UNAVAILABLE CBC_EXT_OPCODE -#define PARSER_TO_EXT_OPCODE(opcode) ((uint16_t) ((opcode) + 256)) -#define PARSER_GET_EXT_OPCODE(opcode) ((opcode) - 256) +#define PARSER_TO_EXT_OPCODE(opcode) ((uint16_t) ((opcode) + 256)) +#define PARSER_GET_EXT_OPCODE(opcode) ((opcode) -256) #define PARSER_IS_BASIC_OPCODE(opcode) ((opcode) < 256) #define PARSER_IS_PUSH_LITERAL(opcode) \ - ((opcode) == CBC_PUSH_LITERAL \ - || (opcode) == CBC_PUSH_TWO_LITERALS \ - || (opcode) == CBC_PUSH_THREE_LITERALS) + ((opcode) == CBC_PUSH_LITERAL || (opcode) == CBC_PUSH_TWO_LITERALS || (opcode) == CBC_PUSH_THREE_LITERALS) #define PARSER_IS_PUSH_NUMBER(opcode) \ - ((opcode) >= CBC_PUSH_NUMBER_0 \ - && (opcode) <= CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) + ((opcode) >= CBC_PUSH_NUMBER_0 && (opcode) <= CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) -#define PARSER_IS_MUTABLE_PUSH_LITERAL(opcode) \ - ((opcode) >= CBC_PUSH_LITERAL && (opcode) <= CBC_PUSH_THIS_LITERAL) +#define PARSER_IS_MUTABLE_PUSH_LITERAL(opcode) ((opcode) >= CBC_PUSH_LITERAL && (opcode) <= CBC_PUSH_THIS_LITERAL) -#define PARSER_IS_PUSH_LITERALS_WITH_THIS(opcode) \ - ((opcode) >= CBC_PUSH_LITERAL && (opcode) <= CBC_PUSH_THREE_LITERALS) +#define PARSER_IS_PUSH_LITERALS_WITH_THIS(opcode) ((opcode) >= CBC_PUSH_LITERAL && (opcode) <= CBC_PUSH_THREE_LITERALS) -#define PARSER_IS_PUSH_PROP(opcode) \ - ((opcode) >= CBC_PUSH_PROP && (opcode) <= CBC_PUSH_PROP_THIS_LITERAL) +#define PARSER_IS_PUSH_PROP(opcode) ((opcode) >= CBC_PUSH_PROP && (opcode) <= CBC_PUSH_PROP_THIS_LITERAL) #define PARSER_IS_PUSH_PROP_LITERAL(opcode) \ ((opcode) >= CBC_PUSH_PROP_LITERAL && (opcode) <= CBC_PUSH_PROP_THIS_LITERAL) @@ -305,21 +290,17 @@ typedef struct ((lexer_literal_t *) parser_list_get (&context_p->literal_pool, (literal_index))) #define PARSER_TO_BINARY_OPERATION_WITH_RESULT(opcode) \ - (PARSER_TO_EXT_OPCODE(opcode) - CBC_ASSIGN_ADD + CBC_EXT_ASSIGN_ADD_PUSH_RESULT) + (PARSER_TO_EXT_OPCODE (opcode) - CBC_ASSIGN_ADD + CBC_EXT_ASSIGN_ADD_PUSH_RESULT) #define PARSER_TO_BINARY_OPERATION_WITH_BLOCK(opcode) \ - ((uint16_t) (PARSER_TO_EXT_OPCODE(opcode) - CBC_ASSIGN_ADD + CBC_EXT_ASSIGN_ADD_BLOCK)) + ((uint16_t) (PARSER_TO_EXT_OPCODE (opcode) - CBC_ASSIGN_ADD + CBC_EXT_ASSIGN_ADD_BLOCK)) -#define PARSER_GET_FLAGS(op) \ - (PARSER_IS_BASIC_OPCODE (op) ? cbc_flags[(op)] : cbc_ext_flags[PARSER_GET_EXT_OPCODE (op)]) +#define PARSER_GET_FLAGS(op) (PARSER_IS_BASIC_OPCODE (op) ? cbc_flags[(op)] : cbc_ext_flags[PARSER_GET_EXT_OPCODE (op)]) #define PARSER_OPCODE_IS_RETURN(op) \ - ((op) == CBC_RETURN \ - || (op) == CBC_RETURN_FUNCTION_END \ - || (op) == CBC_RETURN_WITH_LITERAL) + ((op) == CBC_RETURN || (op) == CBC_RETURN_FUNCTION_END || (op) == CBC_RETURN_WITH_LITERAL) -#define PARSER_ARGS_EQ(op, types) \ - ((PARSER_GET_FLAGS (op) & CBC_ARG_TYPES) == (types)) +#define PARSER_ARGS_EQ(op, types) ((PARSER_GET_FLAGS (op) & CBC_ARG_TYPES) == (types)) /** * All data allocated by the parser is @@ -327,8 +308,8 @@ typedef struct */ typedef struct parser_mem_page_t { - struct parser_mem_page_t *next_p; /**< next page */ - uint8_t bytes[]; /**< memory bytes, C99 flexible array member */ + struct parser_mem_page_t *next_p; /**< next page */ + uint8_t bytes[]; /**< memory bytes, C99 flexible array member */ } parser_mem_page_t; /** @@ -336,9 +317,9 @@ typedef struct parser_mem_page_t */ typedef struct { - parser_mem_page_t *first_p; /**< first allocated page */ - parser_mem_page_t *last_p; /**< last allocated page */ - uint32_t last_position; /**< position of the last allocated byte */ + parser_mem_page_t *first_p; /**< first allocated page */ + parser_mem_page_t *last_p; /**< last allocated page */ + uint32_t last_position; /**< position of the last allocated byte */ } parser_mem_data_t; /** @@ -346,10 +327,10 @@ typedef struct */ typedef struct { - parser_mem_data_t data; /**< storage space */ - uint32_t page_size; /**< size of each page */ - uint32_t item_size; /**< size of each item */ - uint32_t item_count; /**< number of items on each page */ + parser_mem_data_t data; /**< storage space */ + uint32_t page_size; /**< size of each page */ + uint32_t item_size; /**< size of each item */ + uint32_t item_count; /**< number of items on each page */ } parser_list_t; /** @@ -357,9 +338,9 @@ typedef struct */ typedef struct { - parser_list_t *list_p; /**< parser list */ - parser_mem_page_t *current_p; /**< currently processed page */ - size_t current_position; /**< current position on the page */ + parser_list_t *list_p; /**< parser list */ + parser_mem_page_t *current_p; /**< currently processed page */ + size_t current_position; /**< current position on the page */ } parser_list_iterator_t; /** @@ -367,8 +348,8 @@ typedef struct */ typedef struct { - parser_mem_data_t data; /**< storage space */ - parser_mem_page_t *free_page_p; /**< space for fast allocation */ + parser_mem_data_t data; /**< storage space */ + parser_mem_page_t *free_page_p; /**< space for fast allocation */ } parser_stack_t; /** @@ -376,8 +357,8 @@ typedef struct */ typedef struct { - parser_mem_page_t *current_p; /**< currently processed page */ - size_t current_position; /**< current position on the page */ + parser_mem_page_t *current_p; /**< currently processed page */ + size_t current_position; /**< current position on the page */ } parser_stack_iterator_t; /** @@ -385,8 +366,8 @@ typedef struct */ typedef struct { - parser_mem_page_t *page_p; /**< branch location page */ - uint32_t offset; /**< branch location offset */ + parser_mem_page_t *page_p; /**< branch location page */ + uint32_t offset; /**< branch location offset */ } parser_branch_t; /** @@ -394,8 +375,8 @@ typedef struct */ typedef struct parser_branch_node_t { - struct parser_branch_node_t *next_p; /**< next linked list node */ - parser_branch_t branch; /**< branch */ + struct parser_branch_node_t *next_p; /**< next linked list node */ + parser_branch_t branch; /**< branch */ } parser_branch_node_t; /** @@ -403,8 +384,8 @@ typedef struct parser_branch_node_t */ typedef struct { - uint16_t map_from; /**< original literal index */ - uint16_t map_to; /**< encoded register or literal index and flags */ + uint16_t map_from; /**< original literal index */ + uint16_t map_to; /**< encoded register or literal index and flags */ } parser_scope_stack_t; /** @@ -477,14 +458,13 @@ typedef struct scanner_context_t scanner_context_t; */ typedef struct { - uint32_t value; /**< line or offset of the breakpoint */ + uint32_t value; /**< line or offset of the breakpoint */ } parser_breakpoint_info_t; /** * Maximum number of breakpoint info. */ -#define PARSER_MAX_BREAKPOINT_INFO_COUNT \ - (JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE / sizeof (parser_breakpoint_info_t)) +#define PARSER_MAX_BREAKPOINT_INFO_COUNT (JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE / sizeof (parser_breakpoint_info_t)) #endif /* JERRY_DEBUGGER */ @@ -492,10 +472,10 @@ typedef struct typedef struct { - parser_mem_page_t *last_page_p; /**< last page of line info data */ - uint32_t byte_code_position; /**< last byte code position */ - parser_line_counter_t line; /**< last line */ - parser_line_counter_t column; /**< last column */ + parser_mem_page_t *last_page_p; /**< last page of line info data */ + uint32_t byte_code_position; /**< last byte code position */ + parser_line_counter_t line; /**< last line */ + parser_line_counter_t column; /**< last column */ } parser_line_info_data_t; #endif /* JERRY_LINE_INFO */ @@ -507,43 +487,43 @@ typedef struct typedef struct parser_saved_context_t { /* Parser members. */ - uint32_t status_flags; /**< parsing options */ - uint16_t stack_depth; /**< current stack depth */ - uint16_t stack_limit; /**< maximum stack depth */ + uint32_t status_flags; /**< parsing options */ + uint16_t stack_depth; /**< current stack depth */ + uint16_t stack_limit; /**< maximum stack depth */ struct parser_saved_context_t *prev_context_p; /**< last saved context */ - parser_stack_iterator_t last_statement; /**< last statement position */ + parser_stack_iterator_t last_statement; /**< last statement position */ /* Literal types */ - uint16_t argument_count; /**< number of function arguments */ + uint16_t argument_count; /**< number of function arguments */ #if JERRY_ESNEXT - uint16_t argument_length; /**< length property of arguments */ + uint16_t argument_length; /**< length property of arguments */ #endif /* JERRY_ESNEXT */ - uint16_t register_count; /**< number of registers */ - uint16_t literal_count; /**< number of literals */ + uint16_t register_count; /**< number of registers */ + uint16_t literal_count; /**< number of literals */ /* Memory storage members. */ - parser_mem_data_t byte_code; /**< byte code buffer */ - uint32_t byte_code_size; /**< byte code size for branches */ - parser_mem_data_t literal_pool_data; /**< literal list */ - parser_scope_stack_t *scope_stack_p; /**< scope stack */ - uint16_t scope_stack_size; /**< size of scope stack */ - uint16_t scope_stack_top; /**< preserved top of scope stack */ - uint16_t scope_stack_reg_top; /**< preserved top register of scope stack */ + parser_mem_data_t byte_code; /**< byte code buffer */ + uint32_t byte_code_size; /**< byte code size for branches */ + parser_mem_data_t literal_pool_data; /**< literal list */ + parser_scope_stack_t *scope_stack_p; /**< scope stack */ + uint16_t scope_stack_size; /**< size of scope stack */ + uint16_t scope_stack_top; /**< preserved top of scope stack */ + uint16_t scope_stack_reg_top; /**< preserved top register of scope stack */ #if JERRY_ESNEXT - uint16_t scope_stack_global_end; /**< end of global declarations of a function */ - ecma_value_t tagged_template_literal_cp; /**< compessed pointer to the tagged template literal collection */ + uint16_t scope_stack_global_end; /**< end of global declarations of a function */ + ecma_value_t tagged_template_literal_cp; /**< compessed pointer to the tagged template literal collection */ #endif /* JERRY_ESNEXT */ #ifndef JERRY_NDEBUG - uint16_t context_stack_depth; /**< current context stack depth */ + uint16_t context_stack_depth; /**< current context stack depth */ #endif /* !JERRY_NDEBUG */ #if JERRY_LINE_INFO - parser_line_info_data_t *line_info_p; /**< line info data */ + parser_line_info_data_t *line_info_p; /**< line info data */ #endif /* JERRY_LINE_INFO */ #if JERRY_FUNCTION_TO_STRING - const uint8_t *function_start_p; /**< start position of the current function */ + const uint8_t *function_start_p; /**< start position of the current function */ #endif /* JERRY_FUNCTION_TO_STRING */ } parser_saved_context_t; @@ -552,104 +532,104 @@ typedef struct parser_saved_context_t */ typedef struct { - PARSER_TRY_CONTEXT (try_buffer); /**< try_buffer */ - parser_error_t error; /**< error code */ + PARSER_TRY_CONTEXT (try_buffer); /**< try_buffer */ + parser_error_t error; /**< error code */ /** Union for rarely used members. */ union { - void *allocated_buffer_p; /**< dinamically allocated buffer - * which needs to be freed on error */ - scanner_context_t *scanner_context_p; /**< scanner context for the pre-scanner */ + void *allocated_buffer_p; /**< dinamically allocated buffer + * which needs to be freed on error */ + scanner_context_t *scanner_context_p; /**< scanner context for the pre-scanner */ } u; - uint32_t allocated_buffer_size; /**< size of the dinamically allocated buffer */ + uint32_t allocated_buffer_size; /**< size of the dinamically allocated buffer */ /* Parser members. */ - uint32_t status_flags; /**< status flags */ - uint32_t global_status_flags; /**< global status flags */ - uint16_t stack_depth; /**< current stack depth */ - uint16_t stack_limit; /**< maximum stack depth */ - const jerry_parse_options_t *options_p; /**< parse options */ - parser_saved_context_t *last_context_p; /**< last saved context */ - parser_stack_iterator_t last_statement; /**< last statement position */ - cbc_script_t *script_p; /**< current script */ - const uint8_t *source_start_p; /**< source start */ - lit_utf8_size_t source_size; /**< source size */ - const uint8_t *arguments_start_p; /**< function argument list start */ - lit_utf8_size_t arguments_size; /**< function argument list size */ - ecma_value_t script_value; /**< current script as value */ - ecma_value_t argument_list; /**< current argument list as value */ - ecma_value_t user_value; /**< current user value */ + uint32_t status_flags; /**< status flags */ + uint32_t global_status_flags; /**< global status flags */ + uint16_t stack_depth; /**< current stack depth */ + uint16_t stack_limit; /**< maximum stack depth */ + const jerry_parse_options_t *options_p; /**< parse options */ + parser_saved_context_t *last_context_p; /**< last saved context */ + parser_stack_iterator_t last_statement; /**< last statement position */ + cbc_script_t *script_p; /**< current script */ + const uint8_t *source_start_p; /**< source start */ + lit_utf8_size_t source_size; /**< source size */ + const uint8_t *arguments_start_p; /**< function argument list start */ + lit_utf8_size_t arguments_size; /**< function argument list size */ + ecma_value_t script_value; /**< current script as value */ + ecma_value_t argument_list; /**< current argument list as value */ + ecma_value_t user_value; /**< current user value */ #if JERRY_MODULE_SYSTEM - ecma_module_names_t *module_names_p; /**< import / export names that is being processed */ - lexer_literal_t *module_identifier_lit_p; /**< the literal for the identifier of the current element */ + ecma_module_names_t *module_names_p; /**< import / export names that is being processed */ + lexer_literal_t *module_identifier_lit_p; /**< the literal for the identifier of the current element */ #endif /* JERRY_MODULE_SYSTEM */ /* Lexer members. */ - lexer_token_t token; /**< current token */ - lexer_lit_object_t lit_object; /**< current literal object */ - const uint8_t *source_p; /**< next source byte */ - const uint8_t *source_end_p; /**< last source byte */ - parser_line_counter_t line; /**< current line */ - parser_line_counter_t column; /**< current column */ + lexer_token_t token; /**< current token */ + lexer_lit_object_t lit_object; /**< current literal object */ + const uint8_t *source_p; /**< next source byte */ + const uint8_t *source_end_p; /**< last source byte */ + parser_line_counter_t line; /**< current line */ + parser_line_counter_t column; /**< current column */ /* Scanner members. */ - scanner_info_t *next_scanner_info_p; /**< next scanner info block */ - scanner_info_t *active_scanner_info_p; /**< currently active scanner info block */ - scanner_info_t *skipped_scanner_info_p; /**< next scanner info block */ + scanner_info_t *next_scanner_info_p; /**< next scanner info block */ + scanner_info_t *active_scanner_info_p; /**< currently active scanner info block */ + scanner_info_t *skipped_scanner_info_p; /**< next scanner info block */ scanner_info_t *skipped_scanner_info_end_p; /**< currently active scanner info block */ /* Compact byte code members. */ - cbc_argument_t last_cbc; /**< argument of the last cbc */ - uint16_t last_cbc_opcode; /**< opcode of the last cbc */ + cbc_argument_t last_cbc; /**< argument of the last cbc */ + uint16_t last_cbc_opcode; /**< opcode of the last cbc */ /* Literal types */ - uint16_t argument_count; /**< number of function arguments */ + uint16_t argument_count; /**< number of function arguments */ #if JERRY_ESNEXT - uint16_t argument_length; /**< length property of arguments */ + uint16_t argument_length; /**< length property of arguments */ #endif /* JERRY_ESNEXT */ - uint16_t register_count; /**< number of registers */ - uint16_t literal_count; /**< number of literals */ + uint16_t register_count; /**< number of registers */ + uint16_t literal_count; /**< number of literals */ /* Memory storage members. */ - parser_mem_data_t byte_code; /**< byte code buffer */ - uint32_t byte_code_size; /**< current byte code size for branches */ - parser_list_t literal_pool; /**< literal list */ - parser_mem_data_t stack; /**< storage space */ - parser_scope_stack_t *scope_stack_p; /**< scope stack */ - parser_mem_page_t *free_page_p; /**< space for fast allocation */ - uint16_t scope_stack_size; /**< size of scope stack */ - uint16_t scope_stack_top; /**< current top of scope stack */ - uint16_t scope_stack_reg_top; /**< current top register of scope stack */ + parser_mem_data_t byte_code; /**< byte code buffer */ + uint32_t byte_code_size; /**< current byte code size for branches */ + parser_list_t literal_pool; /**< literal list */ + parser_mem_data_t stack; /**< storage space */ + parser_scope_stack_t *scope_stack_p; /**< scope stack */ + parser_mem_page_t *free_page_p; /**< space for fast allocation */ + uint16_t scope_stack_size; /**< size of scope stack */ + uint16_t scope_stack_top; /**< current top of scope stack */ + uint16_t scope_stack_reg_top; /**< current top register of scope stack */ #if JERRY_ESNEXT - uint16_t scope_stack_global_end; /**< end of global declarations of a function */ - ecma_value_t tagged_template_literal_cp; /**< compessed pointer to the tagged template literal collection */ + uint16_t scope_stack_global_end; /**< end of global declarations of a function */ + ecma_value_t tagged_template_literal_cp; /**< compessed pointer to the tagged template literal collection */ #endif /* JERRY_ESNEXT */ - uint8_t stack_top_uint8; /**< top byte stored on the stack */ + uint8_t stack_top_uint8; /**< top byte stored on the stack */ #ifndef JERRY_NDEBUG /* Variables for debugging / logging. */ - uint16_t context_stack_depth; /**< current context stack depth */ + uint16_t context_stack_depth; /**< current context stack depth */ #endif /* !JERRY_NDEBUG */ #if JERRY_PARSER_DUMP_BYTE_CODE - int is_show_opcodes; /**< show opcodes */ - uint32_t total_byte_code_size; /**< total byte code size */ + int is_show_opcodes; /**< show opcodes */ + uint32_t total_byte_code_size; /**< total byte code size */ #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ #if JERRY_DEBUGGER parser_breakpoint_info_t breakpoint_info[PARSER_MAX_BREAKPOINT_INFO_COUNT]; /**< breakpoint info list */ - uint16_t breakpoint_info_count; /**< current breakpoint index */ + uint16_t breakpoint_info_count; /**< current breakpoint index */ parser_line_counter_t last_breakpoint_line; /**< last line where breakpoint has been inserted */ #endif /* JERRY_DEBUGGER */ #if JERRY_LINE_INFO - parser_line_info_data_t *line_info_p; /**< line info data */ + parser_line_info_data_t *line_info_p; /**< line info data */ #endif /* JERRY_LINE_INFO */ #if JERRY_FUNCTION_TO_STRING - const uint8_t *function_start_p; /**< start position of the function which will be parsed */ - const uint8_t *function_end_p; /**< end position of the current function */ + const uint8_t *function_start_p; /**< start position of the function which will be parsed */ + const uint8_t *function_end_p; /**< end position of the current function */ #endif /* JERRY_FUNCTION_TO_STRING */ } parser_context_t; @@ -727,14 +707,14 @@ void parser_stack_iterator_write (parser_stack_iterator_t *iterator, const void void parser_flush_cbc (parser_context_t *context_p); void parser_emit_cbc (parser_context_t *context_p, uint16_t opcode); void parser_emit_cbc_literal (parser_context_t *context_p, uint16_t opcode, uint16_t literal_index); -void parser_emit_cbc_literal_value (parser_context_t *context_p, uint16_t opcode, uint16_t literal_index, - uint16_t value); +void +parser_emit_cbc_literal_value (parser_context_t *context_p, uint16_t opcode, uint16_t literal_index, uint16_t value); void parser_emit_cbc_literal_from_token (parser_context_t *context_p, uint16_t opcode); void parser_emit_cbc_call (parser_context_t *context_p, uint16_t opcode, size_t call_arguments); void parser_emit_cbc_push_number (parser_context_t *context_p, bool is_negative_number); void parser_emit_cbc_forward_branch (parser_context_t *context_p, uint16_t opcode, parser_branch_t *branch_p); -parser_branch_node_t *parser_emit_cbc_forward_branch_item (parser_context_t *context_p, uint16_t opcode, - parser_branch_node_t *next_p); +parser_branch_node_t * +parser_emit_cbc_forward_branch_item (parser_context_t *context_p, uint16_t opcode, parser_branch_node_t *next_p); void parser_emit_cbc_backward_branch (parser_context_t *context_p, uint16_t opcode, uint32_t offset); ecma_string_t *parser_new_ecma_string_from_literal (lexer_literal_t *literal_p); void parser_set_branch_to_current_position (parser_context_t *context_p, parser_branch_t *branch_p); @@ -742,8 +722,7 @@ void parser_set_breaks_to_current_position (parser_context_t *context_p, parser_ void parser_set_continues_to_current_position (parser_context_t *context_p, parser_branch_node_t *current_p); /* Convenience macros. */ -#define parser_emit_cbc_ext(context_p, opcode) \ - parser_emit_cbc ((context_p), PARSER_TO_EXT_OPCODE (opcode)) +#define parser_emit_cbc_ext(context_p, opcode) parser_emit_cbc ((context_p), PARSER_TO_EXT_OPCODE (opcode)) #define parser_emit_cbc_ext_literal(context_p, opcode, literal_index) \ parser_emit_cbc_literal ((context_p), PARSER_TO_EXT_OPCODE (opcode), (literal_index)) #define parser_emit_cbc_ext_literal_from_token(context_p, opcode) \ @@ -772,8 +751,7 @@ void parser_reverse_class_fields (parser_context_t *context_p, size_t fields_siz void lexer_next_token (parser_context_t *context_p); bool lexer_check_next_character (parser_context_t *context_p, lit_utf8_byte_t character); -bool lexer_check_next_characters (parser_context_t *context_p, lit_utf8_byte_t character1, - lit_utf8_byte_t character2); +bool lexer_check_next_characters (parser_context_t *context_p, lit_utf8_byte_t character1, lit_utf8_byte_t character2); uint8_t lexer_consume_next_character (parser_context_t *context_p); bool lexer_check_post_primary_exp (parser_context_t *context_p); #if JERRY_ESNEXT @@ -791,25 +769,28 @@ bool lexer_scan_identifier (parser_context_t *context_p); void lexer_check_property_modifier (parser_context_t *context_p); void lexer_convert_ident_to_cesu8 (uint8_t *destination_p, const uint8_t *source_p, prop_length_t length); -const uint8_t *lexer_convert_literal_to_chars (parser_context_t *context_p, const lexer_lit_location_t *literal_p, - uint8_t *local_byte_array_p, lexer_string_options_t opts); +const uint8_t *lexer_convert_literal_to_chars (parser_context_t *context_p, + const lexer_lit_location_t *literal_p, + uint8_t *local_byte_array_p, + lexer_string_options_t opts); void lexer_expect_object_literal_id (parser_context_t *context_p, uint32_t ident_opts); lexer_literal_t *lexer_construct_unused_literal (parser_context_t *context_p); -void lexer_construct_literal_object (parser_context_t *context_p, const lexer_lit_location_t *lit_location_p, +void lexer_construct_literal_object (parser_context_t *context_p, + const lexer_lit_location_t *lit_location_p, uint8_t literal_type); bool lexer_construct_number_object (parser_context_t *context_p, bool is_expr, bool is_negative_number); void lexer_convert_push_number_to_push_literal (parser_context_t *context_p); uint16_t lexer_construct_function_object (parser_context_t *context_p, uint32_t extra_status_flags); void lexer_construct_regexp_object (parser_context_t *context_p, bool parse_only); bool lexer_compare_identifier_to_string (const lexer_lit_location_t *left_p, const uint8_t *right_p, size_t size); -bool lexer_compare_identifiers (parser_context_t *context_p, const lexer_lit_location_t *left_p, +bool lexer_compare_identifiers (parser_context_t *context_p, + const lexer_lit_location_t *left_p, const lexer_lit_location_t *right_p); bool lexer_current_is_literal (parser_context_t *context_p, const lexer_lit_location_t *right_ident_p); bool lexer_string_is_use_strict (parser_context_t *context_p); bool lexer_string_is_directive (parser_context_t *context_p); #if JERRY_ESNEXT -bool lexer_token_is_identifier (parser_context_t *context_p, const char *identifier_p, - size_t identifier_length); +bool lexer_token_is_identifier (parser_context_t *context_p, const char *identifier_p, size_t identifier_length); bool lexer_token_is_let (parser_context_t *context_p); bool lexer_token_is_async (parser_context_t *context_p); #endif /* JERRY_ESNEXT */ @@ -900,9 +881,8 @@ void parser_module_set_default (parser_context_t *context_p); bool parser_module_check_duplicate_import (parser_context_t *context_p, ecma_string_t *local_name_p); bool parser_module_check_duplicate_export (parser_context_t *context_p, ecma_string_t *export_name_p); void parser_module_append_export_name (parser_context_t *context_p); -void parser_module_add_names_to_node (parser_context_t *context_p, - ecma_string_t *imex_name_p, - ecma_string_t *local_name_p); +void +parser_module_add_names_to_node (parser_context_t *context_p, ecma_string_t *imex_name_p, ecma_string_t *local_name_p); #endif /* JERRY_MODULE_SYSTEM */ @@ -915,8 +895,7 @@ void parser_module_add_names_to_node (parser_context_t *context_p, #if JERRY_LINE_INFO void parser_line_info_free (parser_line_info_data_t *line_info_p); -void parser_line_info_append (parser_context_t *context_p, - parser_line_counter_t line, parser_line_counter_t column); +void parser_line_info_append (parser_context_t *context_p, parser_line_counter_t line, parser_line_counter_t column); uint8_t *parser_line_info_generate (parser_context_t *context_p); #endif /* JERRY_LINE_INFO */ @@ -931,10 +910,14 @@ ecma_compiled_code_t *parser_parse_function (parser_context_t *context_p, uint32 #if JERRY_ESNEXT ecma_compiled_code_t *parser_parse_arrow_function (parser_context_t *context_p, uint32_t status_flags); ecma_compiled_code_t *parser_parse_class_fields (parser_context_t *context_p); -void parser_set_function_name (parser_context_t *context_p, uint16_t function_literal_index, uint16_t name_index, +void parser_set_function_name (parser_context_t *context_p, + uint16_t function_literal_index, + uint16_t name_index, uint32_t status_flags); -void parser_compiled_code_set_function_name (parser_context_t *context_p, ecma_compiled_code_t *bytecode_p, - uint16_t name_index, uint32_t status_flags); +void parser_compiled_code_set_function_name (parser_context_t *context_p, + ecma_compiled_code_t *bytecode_p, + uint16_t name_index, + uint32_t status_flags); uint16_t parser_check_anonymous_function_declaration (parser_context_t *context_p); #endif /* JERRY_ESNEXT */ diff --git a/jerry-core/parser/js/js-parser-line-info-create.c b/jerry-core/parser/js/js-parser-line-info-create.c index 90eca632..e26b13ed 100644 --- a/jerry-core/parser/js/js-parser-line-info-create.c +++ b/jerry-core/parser/js/js-parser-line-info-create.c @@ -14,6 +14,7 @@ */ #include "ecma-line-info.h" + #include "js-parser-internal.h" #if JERRY_PARSER @@ -100,20 +101,17 @@ /** * Page size of line info pages excluding the first one. */ -#define PARSER_LINE_INFO_PAGE_SIZE \ - (sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE) +#define PARSER_LINE_INFO_PAGE_SIZE (sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE) /** * Page size of the first line info page. */ -#define PARSER_LINE_INFO_FIRST_PAGE_SIZE \ - (sizeof (parser_line_info_data_t) + PARSER_LINE_INFO_PAGE_SIZE) +#define PARSER_LINE_INFO_FIRST_PAGE_SIZE (sizeof (parser_line_info_data_t) + PARSER_LINE_INFO_PAGE_SIZE) /** * Get memory data of the first page. */ -#define PARSER_LINE_INFO_GET_FIRST_PAGE(line_info_p) \ - (((parser_mem_page_t *) ((line_info_p) + 1))) +#define PARSER_LINE_INFO_GET_FIRST_PAGE(line_info_p) (((parser_mem_page_t *) ((line_info_p) + 1))) /** * Free line info temporary data collected during parsing. @@ -160,8 +158,7 @@ parser_line_info_encode_vlq (uint8_t *buffer_p, /**< target buffer */ { current_value >>= ECMA_LINE_INFO_VLQ_SHIFT; length++; - } - while (current_value > 0); + } while (current_value > 0); buffer_p += length; @@ -169,8 +166,7 @@ parser_line_info_encode_vlq (uint8_t *buffer_p, /**< target buffer */ { *(--buffer_p) = (uint8_t) (value | ECMA_LINE_INFO_VLQ_CONTINUE); value >>= ECMA_LINE_INFO_VLQ_SHIFT; - } - while (value > 0); + } while (value > 0); buffer_p[length - 1] &= ECMA_LINE_INFO_VLQ_MASK; return length; @@ -529,8 +525,7 @@ parser_line_info_generate (parser_context_t *context_p) /**< context */ stream_prev_column = ECMA_LINE_INFO_COLUMN_DEFAULT; stream_size = 0; stream_value_count = 0; - } - while (iterator.current_page_p != NULL); + } while (iterator.current_page_p != NULL); value = (stream_prev_line != stream_current_line); diff --git a/jerry-core/parser/js/js-parser-mem.c b/jerry-core/parser/js/js-parser-mem.c index 38fe55bf..14f87c2c 100644 --- a/jerry-core/parser/js/js-parser-mem.c +++ b/jerry-core/parser/js/js-parser-mem.c @@ -97,8 +97,7 @@ parser_free_allocated_buffer (parser_context_t *context_p) /**< context */ { if (context_p->u.allocated_buffer_p != NULL) { - parser_free_local (context_p->u.allocated_buffer_p, - context_p->allocated_buffer_size); + parser_free_local (context_p->u.allocated_buffer_p, context_p->allocated_buffer_size); context_p->u.allocated_buffer_p = NULL; } } /* parser_free_allocated_buffer */ @@ -156,8 +155,7 @@ parser_cbc_stream_init (parser_mem_data_t *data_p) /**< memory manager */ void parser_cbc_stream_free (parser_mem_data_t *data_p) /**< memory manager */ { - parser_data_free (data_p, - sizeof (parser_mem_page_t *) + PARSER_CBC_STREAM_PAGE_SIZE); + parser_data_free (data_p, sizeof (parser_mem_page_t *) + PARSER_CBC_STREAM_PAGE_SIZE); } /* parser_cbc_stream_free */ /** @@ -210,8 +208,7 @@ parser_list_init (parser_list_t *list_p, /**< parser list */ void parser_list_free (parser_list_t *list_p) /**< parser list */ { - parser_data_free (&list_p->data, - (uint32_t) (sizeof (parser_mem_page_t *) + list_p->page_size)); + parser_data_free (&list_p->data, (uint32_t) (sizeof (parser_mem_page_t *) + list_p->page_size)); } /* parser_list_free */ /** @@ -280,8 +277,7 @@ parser_list_get (parser_list_t *list_p, /**< parser list */ } JERRY_ASSERT (page_p != NULL); - JERRY_ASSERT (page_p != list_p->data.last_p - || (index * list_p->item_size < list_p->data.last_position)); + JERRY_ASSERT (page_p != list_p->data.last_p || (index * list_p->item_size < list_p->data.last_position)); return page_p->bytes + (index * list_p->item_size); } /* parser_list_get */ @@ -353,13 +349,11 @@ parser_stack_init (parser_context_t *context_p) /**< context */ void parser_stack_free (parser_context_t *context_p) /**< context */ { - parser_data_free (&context_p->stack, - sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + parser_data_free (&context_p->stack, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); if (context_p->free_page_p != NULL) { - parser_free (context_p->free_page_p, - sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + parser_free (context_p->free_page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); } } /* parser_stack_free */ @@ -375,8 +369,7 @@ parser_stack_push_uint8 (parser_context_t *context_p, /**< context */ /* This assert might trigger false positive valgrind errors, when * parser_stack_push() pushes not fully initialized structures. * More precisely when the last byte of the structure is uninitialized. */ - JERRY_ASSERT (page_p == NULL - || context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + JERRY_ASSERT (page_p == NULL || context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); if (context_p->stack.last_position >= PARSER_STACK_PAGE_SIZE) { @@ -408,8 +401,7 @@ parser_stack_pop_uint8 (parser_context_t *context_p) /**< context */ { parser_mem_page_t *page_p = context_p->stack.first_p; - JERRY_ASSERT (page_p != NULL - && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); context_p->stack.last_position--; @@ -424,8 +416,7 @@ parser_stack_pop_uint8 (parser_context_t *context_p) /**< context */ } else { - parser_free (page_p, - sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + parser_free (page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); } page_p = context_p->stack.first_p; @@ -445,8 +436,7 @@ parser_stack_change_last_uint8 (parser_context_t *context_p, /**< context */ { parser_mem_page_t *page_p = context_p->stack.first_p; - JERRY_ASSERT (page_p != NULL - && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); page_p->bytes[context_p->stack.last_position - 1] = new_value; context_p->stack_top_uint8 = new_value; @@ -483,8 +473,7 @@ parser_stack_push_uint16 (parser_context_t *context_p, /**< context */ { parser_mem_page_t *page_p = context_p->stack.first_p; - JERRY_ASSERT (page_p != NULL - && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); page_p->bytes[context_p->stack.last_position++] = (uint8_t) (uint16_value >> 8); page_p->bytes[context_p->stack.last_position++] = (uint8_t) uint16_value; @@ -511,8 +500,7 @@ parser_stack_pop_uint16 (parser_context_t *context_p) /**< context */ { parser_mem_page_t *page_p = context_p->stack.first_p; - JERRY_ASSERT (page_p != NULL - && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); value |= ((uint32_t) page_p->bytes[context_p->stack.last_position - 2]) << 8; context_p->stack_top_uint8 = page_p->bytes[context_p->stack.last_position - 3]; @@ -551,9 +539,7 @@ parser_stack_push (parser_context_t *context_p, /**< context */ fragment_length = length; } - memcpy (context_p->stack.first_p->bytes + context_p->stack.last_position, - bytes_p, - fragment_length); + memcpy (context_p->stack.first_p->bytes + context_p->stack.last_position, bytes_p, fragment_length); if (fragment_length == length) { @@ -636,8 +622,7 @@ parser_stack_pop (parser_context_t *context_p, /**< context */ } else { - parser_free (page_p, - sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + parser_free (page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); } } /* parser_stack_pop */ @@ -698,21 +683,15 @@ parser_stack_iterator_read (parser_stack_iterator_t *iterator, /**< iterator */ if (length <= iterator->current_position) { - memcpy (bytes_p, - iterator->current_p->bytes + iterator->current_position - length, - length); + memcpy (bytes_p, iterator->current_p->bytes + iterator->current_position - length, length); } else { JERRY_ASSERT (iterator->current_p->next_p != NULL); length -= iterator->current_position; - memcpy (bytes_p + length, - iterator->current_p->bytes, - iterator->current_position); - memcpy (bytes_p, - iterator->current_p->next_p->bytes + PARSER_STACK_PAGE_SIZE - length, - length); + memcpy (bytes_p + length, iterator->current_p->bytes, iterator->current_position); + memcpy (bytes_p, iterator->current_p->next_p->bytes + PARSER_STACK_PAGE_SIZE - length, length); } } /* parser_stack_iterator_read */ @@ -730,21 +709,15 @@ parser_stack_iterator_write (parser_stack_iterator_t *iterator, /**< iterator */ if (length <= iterator->current_position) { - memcpy (iterator->current_p->bytes + iterator->current_position - length, - bytes_p, - length); + memcpy (iterator->current_p->bytes + iterator->current_position - length, bytes_p, length); } else { JERRY_ASSERT (iterator->current_p->next_p != NULL); length -= iterator->current_position; - memcpy (iterator->current_p->bytes, - bytes_p + length, - iterator->current_position); - memcpy (iterator->current_p->next_p->bytes + PARSER_STACK_PAGE_SIZE - length, - bytes_p, - length); + memcpy (iterator->current_p->bytes, bytes_p + length, iterator->current_position); + memcpy (iterator->current_p->next_p->bytes + PARSER_STACK_PAGE_SIZE - length, bytes_p, length); } } /* parser_stack_iterator_write */ diff --git a/jerry-core/parser/js/js-parser-module.c b/jerry-core/parser/js/js-parser-module.c index 3a7189e4..465f8122 100644 --- a/jerry-core/parser/js/js-parser-module.c +++ b/jerry-core/parser/js/js-parser-module.c @@ -16,8 +16,6 @@ #include "js-parser-internal.h" #if JERRY_MODULE_SYSTEM -#include "jcontext.h" - #include "ecma-function-object.h" #include "ecma-gc.h" #include "ecma-globals.h" @@ -25,13 +23,15 @@ #include "ecma-lex-env.h" #include "ecma-module.h" +#include "jcontext.h" + /** * Description of "*default*" literal string. */ -const lexer_lit_location_t lexer_default_literal = -{ - (const uint8_t *) "*default*", 9, LEXER_IDENT_LITERAL, LEXER_LIT_LOCATION_IS_ASCII -}; +const lexer_lit_location_t lexer_default_literal = { (const uint8_t *) "*default*", + 9, + LEXER_IDENT_LITERAL, + LEXER_LIT_LOCATION_IS_ASCII }; /** * Check for duplicated imported binding names. @@ -89,7 +89,7 @@ parser_module_append_export_name (parser_context_t *context_p) /**< parser conte } context_p->module_identifier_lit_p = context_p->lit_object.literal_p; - ecma_string_t *name_p = parser_new_ecma_string_from_literal (context_p->lit_object.literal_p); + ecma_string_t *name_p = parser_new_ecma_string_from_literal (context_p->lit_object.literal_p); if (parser_module_check_duplicate_export (context_p, name_p)) { @@ -97,9 +97,7 @@ parser_module_append_export_name (parser_context_t *context_p) /**< parser conte parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER); } - parser_module_add_names_to_node (context_p, - name_p, - name_p); + parser_module_add_names_to_node (context_p, name_p, name_p); ecma_deref_ecma_string (name_p); } /* parser_module_append_export_name */ @@ -167,8 +165,7 @@ parser_module_add_names_to_node (parser_context_t *context_p, /**< parser contex ecma_string_t *imex_name_p, /**< import/export name */ ecma_string_t *local_name_p) /**< local name */ { - ecma_module_names_t *new_name_p = (ecma_module_names_t *) parser_malloc (context_p, - sizeof (ecma_module_names_t)); + ecma_module_names_t *new_name_p = (ecma_module_names_t *) parser_malloc (context_p, sizeof (ecma_module_names_t)); new_name_p->next_p = context_p->module_names_p; context_p->module_names_p = new_name_p; @@ -209,8 +206,7 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont } /* 15.2.3.1 The referenced binding cannot be a reserved word. */ - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL || context_p->token.keyword_type >= LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); @@ -221,8 +217,7 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); - if (!has_module_specifier - && !scanner_literal_exists (context_p, context_p->lit_object.index)) + if (!has_module_specifier && !scanner_literal_exists (context_p, context_p->lit_object.index)) { parser_raise_error (context_p, PARSER_ERR_EXPORT_NOT_DEFINED); } @@ -235,8 +230,7 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); } @@ -271,8 +265,7 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont ecma_deref_ecma_string (local_name_p); ecma_deref_ecma_string (export_name_p); - if (context_p->token.type != LEXER_COMMA - && context_p->token.type != LEXER_RIGHT_BRACE) + if (context_p->token.type != LEXER_COMMA && context_p->token.type != LEXER_RIGHT_BRACE) { parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED); } @@ -305,8 +298,7 @@ parser_module_parse_import_clause (parser_context_t *context_p) /**< parser cont break; } - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); } @@ -330,8 +322,7 @@ parser_module_parse_import_clause (parser_context_t *context_p) /**< parser cont { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); } @@ -372,8 +363,7 @@ parser_module_parse_import_clause (parser_context_t *context_p) /**< parser cont ecma_deref_ecma_string (local_name_p); ecma_deref_ecma_string (import_name_p); - if (context_p->token.type != LEXER_COMMA - && (context_p->token.type != LEXER_RIGHT_BRACE)) + if (context_p->token.type != LEXER_COMMA && (context_p->token.type != LEXER_RIGHT_BRACE)) { parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED); } @@ -395,10 +385,8 @@ parser_module_parse_import_clause (parser_context_t *context_p) /**< parser cont void parser_module_check_request_place (parser_context_t *context_p) /**< parser context */ { - if (context_p->last_context_p != NULL - || context_p->stack_top_uint8 != 0 - || (context_p->status_flags & PARSER_IS_FUNCTION) - || (context_p->global_status_flags & ECMA_PARSE_EVAL) + if (context_p->last_context_p != NULL || context_p->stack_top_uint8 != 0 + || (context_p->status_flags & PARSER_IS_FUNCTION) || (context_p->global_status_flags & ECMA_PARSE_EVAL) || (context_p->global_status_flags & ECMA_PARSE_MODULE) == 0) { parser_raise_error (context_p, PARSER_ERR_MODULE_UNEXPECTED); @@ -440,8 +428,7 @@ void parser_module_handle_module_specifier (parser_context_t *context_p, /**< parser context */ ecma_module_node_t **node_list_p) /**< target node list */ { - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_STRING_LITERAL + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_STRING_LITERAL || context_p->token.lit_location.length == 0) { parser_raise_error (context_p, PARSER_ERR_STRING_EXPECTED); diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c index e648960c..ce0a51bc 100644 --- a/jerry-core/parser/js/js-parser-statm.c +++ b/jerry-core/parser/js/js-parser-statm.c @@ -16,9 +16,9 @@ #include "js-parser-internal.h" #if JERRY_PARSER -#include "jcontext.h" - #include "ecma-helpers.h" + +#include "jcontext.h" #include "lit-char-helpers.h" /** \addtogroup parser Parser @@ -83,8 +83,7 @@ typedef enum * Parser statement attributes. * Note: the order of the attributes must be keep in sync with parser_statement_type_t */ -static const uint8_t parser_statement_flags[] = -{ +static const uint8_t parser_statement_flags[] = { /* PARSER_STATEMENT_START */ PARSER_STATM_HAS_BLOCK, /* PARSER_STATEMENT_BLOCK, */ @@ -135,8 +134,8 @@ static const uint8_t parser_statement_flags[] = */ typedef struct { - uint16_t scope_stack_top; /**< preserved top of scope stack */ - uint16_t scope_stack_reg_top; /**< preserved top register of scope stack */ + uint16_t scope_stack_top; /**< preserved top of scope stack */ + uint16_t scope_stack_reg_top; /**< preserved top register of scope stack */ } parser_block_statement_t; /** @@ -144,7 +143,7 @@ typedef struct */ typedef struct { - parser_branch_t branch; /**< branch to the end */ + parser_branch_t branch; /**< branch to the end */ } parser_block_context_t; #endif /* !JERRY_ESNEXT */ @@ -154,7 +153,7 @@ typedef struct */ typedef struct { - parser_branch_node_t *branch_list_p; /**< list of breaks and continues targeting this statement */ + parser_branch_node_t *branch_list_p; /**< list of breaks and continues targeting this statement */ } parser_loop_statement_t; /** @@ -162,8 +161,8 @@ typedef struct */ typedef struct { - lexer_lit_location_t label_ident; /**< name of the label */ - parser_branch_node_t *break_list_p; /**< list of breaks targeting this label */ + lexer_lit_location_t label_ident; /**< name of the label */ + parser_branch_node_t *break_list_p; /**< list of breaks targeting this label */ } parser_label_statement_t; /** @@ -171,7 +170,7 @@ typedef struct */ typedef struct { - parser_branch_t branch; /**< branch to the end */ + parser_branch_t branch; /**< branch to the end */ } parser_if_else_statement_t; /** @@ -179,8 +178,8 @@ typedef struct */ typedef struct { - parser_branch_t default_branch; /**< branch to the default case */ - parser_branch_node_t *branch_list_p; /**< branches of case statements */ + parser_branch_t default_branch; /**< branch to the default case */ + parser_branch_node_t *branch_list_p; /**< branches of case statements */ } parser_switch_statement_t; /** @@ -188,7 +187,7 @@ typedef struct */ typedef struct { - uint32_t start_offset; /**< start byte code offset */ + uint32_t start_offset; /**< start byte code offset */ } parser_do_while_statement_t; /** @@ -196,9 +195,9 @@ typedef struct */ typedef struct { - parser_branch_t branch; /**< branch to the end */ - scanner_location_t condition_location; /**< condition part */ - uint32_t start_offset; /**< start byte code offset */ + parser_branch_t branch; /**< branch to the end */ + scanner_location_t condition_location; /**< condition part */ + uint32_t start_offset; /**< start byte code offset */ } parser_while_statement_t; /** @@ -206,10 +205,10 @@ typedef struct */ typedef struct { - parser_branch_t branch; /**< branch to the end */ - scanner_location_t condition_location; /**< condition part */ + parser_branch_t branch; /**< branch to the end */ + scanner_location_t condition_location; /**< condition part */ scanner_location_t expression_location; /**< expression part */ - uint32_t start_offset; /**< start byte code offset */ + uint32_t start_offset; /**< start byte code offset */ } parser_for_statement_t; /** @@ -217,8 +216,8 @@ typedef struct */ typedef struct { - parser_branch_t branch; /**< branch to the end */ - uint32_t start_offset; /**< start byte code offset */ + parser_branch_t branch; /**< branch to the end */ + uint32_t start_offset; /**< start byte code offset */ } parser_for_in_of_statement_t; /** @@ -226,7 +225,7 @@ typedef struct */ typedef struct { - parser_branch_t branch; /**< branch to the end */ + parser_branch_t branch; /**< branch to the end */ } parser_with_statement_t; /** @@ -234,9 +233,9 @@ typedef struct */ typedef enum { - parser_try_block, /**< try block */ - parser_catch_block, /**< catch block */ - parser_finally_block, /**< finally block */ + parser_try_block, /**< try block */ + parser_catch_block, /**< catch block */ + parser_finally_block, /**< finally block */ } parser_try_block_type_t; /** @@ -244,10 +243,10 @@ typedef enum */ typedef struct { - parser_try_block_type_t type; /**< current block type */ - uint16_t scope_stack_top; /**< current top of scope stack */ - uint16_t scope_stack_reg_top; /**< current top register of scope stack */ - parser_branch_t branch; /**< branch to the end of the current block */ + parser_try_block_type_t type; /**< current block type */ + uint16_t scope_stack_top; /**< current top of scope stack */ + uint16_t scope_stack_reg_top; /**< current top register of scope stack */ + parser_branch_t branch; /**< branch to the end of the current block */ } parser_try_statement_t; /** @@ -259,8 +258,7 @@ typedef struct static inline size_t parser_statement_length (uint8_t type) /**< type of statement */ { - static const uint8_t statement_lengths[] = - { + static const uint8_t statement_lengths[] = { /* PARSER_STATEMENT_BLOCK */ 1, #if JERRY_ESNEXT @@ -357,9 +355,7 @@ parser_push_block_context (parser_context_t *context_p, /**< context */ PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); #endif /* !JERRY_NDEBUG */ - parser_emit_cbc_forward_branch (context_p, - CBC_BLOCK_CREATE_CONTEXT, - &block_context.branch); + parser_emit_cbc_forward_branch (context_p, CBC_BLOCK_CREATE_CONTEXT, &block_context.branch); parser_stack_push (context_p, &block_context, sizeof (parser_block_context_t)); is_context_needed = true; } @@ -427,8 +423,7 @@ parser_pop_block_context (parser_context_t *context_p) /**< context */ static void parser_validate_lexical_context (parser_context_t *context_p) /**< context */ { - JERRY_ASSERT (context_p->token.type == LEXER_KEYW_LET - || context_p->token.type == LEXER_KEYW_CONST + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_LET || context_p->token.type == LEXER_KEYW_CONST || context_p->token.type == LEXER_KEYW_CLASS); if (parser_statement_flags[context_p->stack_top_uint8] & PARSER_STATM_SINGLE_STATM) @@ -444,8 +439,7 @@ parser_validate_lexical_context (parser_context_t *context_p) /**< context */ static void parser_parse_var_statement (parser_context_t *context_p) /**< context */ { - JERRY_ASSERT (context_p->token.type == LEXER_KEYW_VAR - || context_p->token.type == LEXER_KEYW_LET + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_VAR || context_p->token.type == LEXER_KEYW_LET || context_p->token.type == LEXER_KEYW_CONST); #if JERRY_ESNEXT @@ -494,8 +488,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */ #endif /* JERRY_MODULE_SYSTEM */ #if JERRY_ESNEXT - if (declaration_type != LEXER_KEYW_VAR - && context_p->token.keyword_type == LEXER_KEYW_LET) + if (declaration_type != LEXER_KEYW_VAR && context_p->token.keyword_type == LEXER_KEYW_LET) { parser_raise_error (context_p, PARSER_ERR_LEXICAL_LET_BINDING); } @@ -548,8 +541,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */ parser_set_function_name (context_p, function_literal_index, index, 0); } - if (declaration_type != LEXER_KEYW_VAR - && (index < PARSER_REGISTER_START)) + if (declaration_type != LEXER_KEYW_VAR && (index < PARSER_REGISTER_START)) { opcode = CBC_INIT_LET; @@ -576,8 +568,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */ if (index < PARSER_REGISTER_START) { - opcode = (scanner_literal_is_created (context_p, index) ? CBC_ASSIGN_LET_CONST - : CBC_INIT_LET); + opcode = (scanner_literal_is_created (context_p, index) ? CBC_ASSIGN_LET_CONST : CBC_INIT_LET); } parser_emit_cbc_literal (context_p, (uint16_t) opcode, index); @@ -616,8 +607,7 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */ parser_raise_error (context_p, PARSER_ERR_LEXICAL_SINGLE_STATEMENT); } - if (context_p->stack_top_uint8 == PARSER_STATEMENT_IF - || context_p->stack_top_uint8 == PARSER_STATEMENT_ELSE) + if (context_p->stack_top_uint8 == PARSER_STATEMENT_IF || context_p->stack_top_uint8 == PARSER_STATEMENT_ELSE) { /* There must be a parser error later if this check fails. */ if (context_p->next_scanner_info_p->source_p == context_p->source_p) @@ -682,8 +672,7 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */ #endif /* JERRY_ESNEXT */ lexer_expect_identifier (context_p, LEXER_NEW_IDENT_LITERAL); - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); #if JERRY_ESNEXT if (context_p->next_scanner_info_p->source_p == context_p->source_p @@ -758,8 +747,7 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */ while (stack_p < scope_stack_p) { - if (literal_index == stack_p->map_from - && (stack_p->map_to & PARSER_SCOPE_STACK_NO_FUNCTION_COPY)) + if (literal_index == stack_p->map_from && (stack_p->map_to & PARSER_SCOPE_STACK_NO_FUNCTION_COPY)) { copy_value = false; break; @@ -778,13 +766,9 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */ JERRY_ASSERT (!(stack_p->map_to & PARSER_SCOPE_STACK_NO_FUNCTION_COPY)); uint16_t map_to = scanner_decode_map_to (stack_p); - uint16_t opcode = ((map_to >= PARSER_REGISTER_START) ? CBC_ASSIGN_LITERAL_SET_IDENT - : CBC_COPY_TO_GLOBAL); + uint16_t opcode = ((map_to >= PARSER_REGISTER_START) ? CBC_ASSIGN_LITERAL_SET_IDENT : CBC_COPY_TO_GLOBAL); - parser_emit_cbc_literal_value (context_p, - opcode, - scanner_decode_map_to (scope_stack_p), - map_to); + parser_emit_cbc_literal_value (context_p, opcode, scanner_decode_map_to (scope_stack_p), map_to); break; } stack_p++; @@ -833,9 +817,7 @@ parser_parse_if_statement_start (parser_context_t *context_p) /**< context */ parser_parse_enclosed_expr (context_p); - parser_emit_cbc_forward_branch (context_p, - CBC_BRANCH_IF_FALSE_FORWARD, - &if_statement.branch); + parser_emit_cbc_forward_branch (context_p, CBC_BRANCH_IF_FALSE_FORWARD, &if_statement.branch); parser_stack_push (context_p, &if_statement, sizeof (parser_if_else_statement_t)); parser_stack_push_uint8 (context_p, PARSER_STATEMENT_IF); @@ -873,9 +855,7 @@ parser_parse_if_statement_end (parser_context_t *context_p) /**< context */ parser_stack_iterator_skip (&iterator, 1); parser_stack_iterator_read (&iterator, &if_statement, sizeof (parser_if_else_statement_t)); - parser_emit_cbc_forward_branch (context_p, - CBC_JUMP_FORWARD, - &else_statement.branch); + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &else_statement.branch); parser_set_branch_to_current_position (context_p, &if_statement.branch); @@ -907,9 +887,7 @@ parser_parse_with_statement_start (parser_context_t *context_p) /**< context */ uint8_t inside_with = (context_p->status_flags & PARSER_INSIDE_WITH) != 0; context_p->status_flags |= PARSER_INSIDE_WITH; - parser_emit_cbc_ext_forward_branch (context_p, - CBC_EXT_WITH_CREATE_CONTEXT, - &with_statement.branch); + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_WITH_CREATE_CONTEXT, &with_statement.branch); parser_stack_push (context_p, &with_statement, sizeof (parser_with_statement_t)); parser_stack_push_uint8 (context_p, inside_with); @@ -1128,8 +1106,7 @@ static uint16_t parser_check_left_hand_side_expression (parser_context_t *context_p, /**< context */ uint16_t opcode) /**< opcode to check */ { - if (opcode == CBC_PUSH_LITERAL - && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + if (opcode == CBC_PUSH_LITERAL && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) { context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; return CBC_ASSIGN_SET_IDENT; @@ -1197,8 +1174,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ if (context_p->token.type != LEXER_LEFT_PAREN) { #if JERRY_ESNEXT - if (context_p->token.type == LEXER_LITERAL - && context_p->token.keyword_type == LEXER_KEYW_AWAIT + if (context_p->token.type == LEXER_LITERAL && context_p->token.keyword_type == LEXER_KEYW_AWAIT && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) { parser_raise_error (context_p, PARSER_ERR_FOR_AWAIT_NO_ASYNC); @@ -1227,8 +1203,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ uint8_t token_type = LEXER_EOS; bool has_context = false; - if (context_p->token.type == LEXER_KEYW_VAR - || context_p->token.type == LEXER_KEYW_LET + if (context_p->token.type == LEXER_KEYW_VAR || context_p->token.type == LEXER_KEYW_LET || context_p->token.type == LEXER_KEYW_CONST) { token_type = context_p->token.type; @@ -1299,8 +1274,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ #ifndef JERRY_NDEBUG PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, - is_for_in ? PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION - : PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION); + is_for_in ? PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION : PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION); #endif /* !JERRY_NDEBUG */ cbc_ext_opcode_t init_opcode = CBC_EXT_FOR_IN_INIT; @@ -1359,8 +1333,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ #if JERRY_ESNEXT if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE)) { - parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT - : CBC_EXT_FOR_OF_GET_NEXT); + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING | PARSER_PATTERN_TARGET_ON_STACK); @@ -1399,8 +1372,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); #if JERRY_ESNEXT - if (context_p->token.keyword_type == LEXER_KEYW_LET - && token_type != LEXER_KEYW_VAR) + if (context_p->token.keyword_type == LEXER_KEYW_LET && token_type != LEXER_KEYW_VAR) { parser_raise_error (context_p, PARSER_ERR_LEXICAL_LET_BINDING); } @@ -1429,12 +1401,10 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ parser_set_branch_to_current_position (context_p, &branch); } - parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT - : CBC_EXT_FOR_OF_GET_NEXT); + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); #if JERRY_ESNEXT #ifndef JERRY_NDEBUG - if (literal_index < PARSER_REGISTER_START - && has_context + if (literal_index < PARSER_REGISTER_START && has_context && !scanner_literal_is_created (context_p, literal_index)) { context_p->global_status_flags |= ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR; @@ -1456,8 +1426,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ && context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS && (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_DESTRUCTURING_FOR)) { - parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT - : CBC_EXT_FOR_OF_GET_NEXT); + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); uint32_t flags = PARSER_PATTERN_TARGET_ON_STACK; @@ -1484,13 +1453,11 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ opcode = context_p->last_cbc_opcode; /* The CBC_EXT_FOR_IN_CREATE_CONTEXT flushed the opcode combiner. */ - JERRY_ASSERT (opcode != CBC_PUSH_TWO_LITERALS - && opcode != CBC_PUSH_THREE_LITERALS); + JERRY_ASSERT (opcode != CBC_PUSH_TWO_LITERALS && opcode != CBC_PUSH_THREE_LITERALS); opcode = parser_check_left_hand_side_expression (context_p, opcode); - parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT - : CBC_EXT_FOR_OF_GET_NEXT); + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); parser_flush_cbc (context_p); context_p->last_cbc_opcode = opcode; @@ -1690,7 +1657,7 @@ parser_parse_for_statement_end (parser_context_t *context_p) /**< context */ { has_block_context = true; } -#endif +#endif /* JERRY_ESNEXT */ scanner_get_location (&location, context_p); current_token = context_p->token; @@ -1706,7 +1673,7 @@ parser_parse_for_statement_end (parser_context_t *context_p) /**< context */ { parser_emit_cbc_ext (context_p, CBC_EXT_CLONE_FULL_CONTEXT); } -#endif +#endif /* JERRY_ESNEXT */ if (context_p->token.type != LEXER_RIGHT_PAREN) { @@ -1762,7 +1729,7 @@ parser_parse_for_statement_end (parser_context_t *context_p) /**< context */ { parser_pop_block_context (context_p); } -#endif +#endif /* JERRY_ESNEXT */ /* Calling scanner_seek is unnecessary because all * info blocks inside the for statement should be processed. */ @@ -1853,8 +1820,7 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context * case_info_p = case_info_p->next_p; /* The last letter of case and default is 'e' and 't' respectively. */ - JERRY_ASSERT (context_p->source_p[-1] == LIT_CHAR_LOWERCASE_E - || context_p->source_p[-1] == LIT_CHAR_LOWERCASE_T); + JERRY_ASSERT (context_p->source_p[-1] == LIT_CHAR_LOWERCASE_E || context_p->source_p[-1] == LIT_CHAR_LOWERCASE_T); bool is_default = context_p->source_p[-1] == LIT_CHAR_LOWERCASE_T; lexer_next_token (context_p); @@ -1911,8 +1877,7 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context * } case_branches_p = new_case_p; - } - while (case_info_p != NULL); + } while (case_info_p != NULL); JERRY_ASSERT (switch_case_was_found || default_case_was_found); @@ -2001,8 +1966,7 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */ { JERRY_ASSERT (try_statement.type == parser_try_block); - if (context_p->token.type != LEXER_KEYW_CATCH - && context_p->token.type != LEXER_KEYW_FINALLY) + if (context_p->token.type != LEXER_KEYW_CATCH && context_p->token.type != LEXER_KEYW_FINALLY) { parser_raise_error (context_p, PARSER_ERR_CATCH_FINALLY_EXPECTED); } @@ -2021,9 +1985,7 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); try_statement.type = parser_catch_block; - parser_emit_cbc_ext_forward_branch (context_p, - CBC_EXT_CATCH, - &try_statement.branch); + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_CATCH, &try_statement.branch); try_statement.scope_stack_top = context_p->scope_stack_top; try_statement.scope_stack_reg_top = context_p->scope_stack_reg_top; @@ -2052,9 +2014,7 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */ #if JERRY_ESNEXT if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE)) { - parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING - | PARSER_PATTERN_TARGET_ON_STACK - | PARSER_PATTERN_LET); + parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING | PARSER_PATTERN_TARGET_ON_STACK | PARSER_PATTERN_LET); parser_parse_initializer_by_next_char (context_p, flags); } @@ -2071,7 +2031,7 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */ (literal_index >= PARSER_REGISTER_START) ? CBC_ASSIGN_SET_IDENT : CBC_ASSIGN_LET_CONST, literal_index); #else /* !JERRY_ESNEXT */ - parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, context_p->lit_object.index); + parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, context_p->lit_object.index); #endif /* JERRY_ESNEXT */ lexer_next_token (context_p); @@ -2124,9 +2084,7 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */ #endif /* !JERRY_NDEBUG */ try_statement.type = parser_finally_block; - parser_emit_cbc_ext_forward_branch (context_p, - CBC_EXT_FINALLY, - &try_statement.branch); + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_FINALLY, &try_statement.branch); #if JERRY_ESNEXT if (context_p->next_scanner_info_p->source_p == context_p->source_p) @@ -2234,8 +2192,7 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); parser_stack_iterator_init (context_p, &iterator); - if (!(context_p->token.flags & LEXER_WAS_NEWLINE) - && context_p->token.type == LEXER_LITERAL + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { /* The label with the same name is searched on the stack. */ @@ -2261,9 +2218,8 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */ if (lexer_current_is_literal (context_p, &label_statement.label_ident)) { - label_statement.break_list_p = parser_emit_cbc_forward_branch_item (context_p, - (uint16_t) opcode, - label_statement.break_list_p); + label_statement.break_list_p = + parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, label_statement.break_list_p); parser_stack_iterator_write (&iterator, &label_statement, sizeof (parser_label_statement_t)); lexer_next_token (context_p); return; @@ -2297,9 +2253,7 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */ parser_stack_iterator_skip (&iterator, 1); parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); - loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, - (uint16_t) opcode, - loop.branch_list_p); + loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, loop.branch_list_p); parser_stack_iterator_write (&iterator, &loop, sizeof (parser_loop_statement_t)); return; } @@ -2320,8 +2274,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); parser_stack_iterator_init (context_p, &iterator); - if (!(context_p->token.flags & LEXER_WAS_NEWLINE) - && context_p->token.type == LEXER_LITERAL + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { parser_stack_iterator_t loop_iterator; @@ -2352,9 +2305,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ parser_stack_iterator_skip (&loop_iterator, 1); parser_stack_iterator_read (&loop_iterator, &loop, sizeof (parser_loop_statement_t)); - loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, - (uint16_t) opcode, - loop.branch_list_p); + loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, loop.branch_list_p); loop.branch_list_p->branch.offset |= CBC_HIGHEST_BIT_MASK; parser_stack_iterator_write (&loop_iterator, &loop, sizeof (parser_loop_statement_t)); lexer_next_token (context_p); @@ -2370,8 +2321,8 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ } #if JERRY_ESNEXT - const bool is_private_scope = (type == PARSER_STATEMENT_PRIVATE_SCOPE - || type == PARSER_STATEMENT_PRIVATE_CONTEXT); + const bool is_private_scope = + (type == PARSER_STATEMENT_PRIVATE_SCOPE || type == PARSER_STATEMENT_PRIVATE_CONTEXT); #else /* !JERRY_ESNEXT */ const bool is_private_scope = false; #endif /* !JERRY_ESNEXT */ @@ -2404,9 +2355,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ parser_stack_iterator_skip (&iterator, 1); parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); - loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, - (uint16_t) opcode, - loop.branch_list_p); + loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, loop.branch_list_p); loop.branch_list_p->branch.offset |= CBC_HIGHEST_BIT_MASK; parser_stack_iterator_write (&iterator, &loop, sizeof (parser_loop_statement_t)); return; @@ -2448,11 +2397,9 @@ parser_parse_import_statement (parser_context_t *context_p) /**< parser context lexer_next_token (context_p); /* Check for a ModuleSpecifier*/ - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_STRING_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_STRING_LITERAL) { - if (!(context_p->token.type == LEXER_LEFT_BRACE - || context_p->token.type == LEXER_MULTIPLY + if (!(context_p->token.type == LEXER_LEFT_BRACE || context_p->token.type == LEXER_MULTIPLY || (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL))) { parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED); @@ -2482,8 +2429,7 @@ parser_parse_import_statement (parser_context_t *context_p) /**< parser context if (context_p->token.type == LEXER_COMMA) { lexer_next_token (context_p); - if (context_p->token.type != LEXER_MULTIPLY - && context_p->token.type != LEXER_LEFT_BRACE) + if (context_p->token.type != LEXER_MULTIPLY && context_p->token.type != LEXER_LEFT_BRACE) { parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_MULTIPLY_EXPECTED); } @@ -2571,8 +2517,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); - if (context_p->token.type == LEXER_LITERAL - && lexer_token_is_async (context_p) + if (context_p->token.type == LEXER_LITERAL && lexer_token_is_async (context_p) && context_p->next_scanner_info_p->source_p == context_p->source_p && context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION) { @@ -2626,9 +2571,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */ parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER); } - parser_module_add_names_to_node (context_p, - export_name_p, - name_p); + parser_module_add_names_to_node (context_p, export_name_p, name_p); ecma_deref_ecma_string (name_p); ecma_deref_ecma_string (export_name_p); break; @@ -2645,8 +2588,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); } @@ -2799,8 +2741,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ } #endif /* JERRY_DEBUGGER */ - while (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + while (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) { lexer_lit_location_t lit_location; parser_strict_mode_type_t strict_mode = PARSER_USE_STRICT_NOT_FOUND; @@ -2866,8 +2807,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ #if JERRY_ESNEXT - if (strict_mode != PARSER_USE_STRICT_NOT_FOUND - && (context_p->status_flags & PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT)) + if (strict_mode != PARSER_USE_STRICT_NOT_FOUND && (context_p->status_flags & PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT)) { parser_raise_error (context_p, PARSER_ERR_USE_STRICT_NOT_ALLOWED); } @@ -2880,8 +2820,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ /* The last directive prologue can be the result of the script. */ if (!(context_p->status_flags & PARSER_IS_FUNCTION) - && (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_STRING_LITERAL)) + && (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_STRING_LITERAL)) { lexer_construct_literal_object (context_p, &lit_location, LEXER_STRING_LITERAL); parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); @@ -2891,14 +2830,12 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ } } - if (context_p->status_flags & PARSER_IS_STRICT - && context_p->status_flags & PARSER_HAS_NON_STRICT_ARG) + if (context_p->status_flags & PARSER_IS_STRICT && context_p->status_flags & PARSER_HAS_NON_STRICT_ARG) { parser_raise_error (context_p, PARSER_ERR_NON_STRICT_ARG_DEFINITION); } - while (context_p->token.type != LEXER_EOS - || context_p->stack_top_uint8 != PARSER_STATEMENT_START) + while (context_p->token.type != LEXER_EOS || context_p->stack_top_uint8 != PARSER_STATEMENT_START) { #ifndef JERRY_NDEBUG JERRY_ASSERT (context_p->stack_depth == context_p->context_stack_depth); @@ -2911,16 +2848,11 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ #if JERRY_DEBUGGER if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED - && context_p->token.line != context_p->last_breakpoint_line - && context_p->token.type != LEXER_SEMICOLON - && context_p->token.type != LEXER_LEFT_BRACE - && context_p->token.type != LEXER_RIGHT_BRACE - && context_p->token.type != LEXER_KEYW_VAR - && context_p->token.type != LEXER_KEYW_LET - && context_p->token.type != LEXER_KEYW_CONST - && context_p->token.type != LEXER_KEYW_FUNCTION - && context_p->token.type != LEXER_KEYW_CASE - && context_p->token.type != LEXER_KEYW_DEFAULT) + && context_p->token.line != context_p->last_breakpoint_line && context_p->token.type != LEXER_SEMICOLON + && context_p->token.type != LEXER_LEFT_BRACE && context_p->token.type != LEXER_RIGHT_BRACE + && context_p->token.type != LEXER_KEYW_VAR && context_p->token.type != LEXER_KEYW_LET + && context_p->token.type != LEXER_KEYW_CONST && context_p->token.type != LEXER_KEYW_FUNCTION + && context_p->token.type != LEXER_KEYW_CASE && context_p->token.type != LEXER_KEYW_DEFAULT) { parser_emit_cbc (context_p, CBC_BREAKPOINT_DISABLED); parser_flush_cbc (context_p); @@ -2932,14 +2864,10 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ #endif /* JERRY_DEBUGGER */ #if JERRY_LINE_INFO - if (context_p->token.type != LEXER_SEMICOLON - && context_p->token.type != LEXER_LEFT_BRACE - && context_p->token.type != LEXER_RIGHT_BRACE - && context_p->token.type != LEXER_KEYW_VAR - && context_p->token.type != LEXER_KEYW_LET - && context_p->token.type != LEXER_KEYW_CONST - && context_p->token.type != LEXER_KEYW_FUNCTION - && context_p->token.type != LEXER_KEYW_CASE + if (context_p->token.type != LEXER_SEMICOLON && context_p->token.type != LEXER_LEFT_BRACE + && context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_KEYW_VAR + && context_p->token.type != LEXER_KEYW_LET && context_p->token.type != LEXER_KEYW_CONST + && context_p->token.type != LEXER_KEYW_FUNCTION && context_p->token.type != LEXER_KEYW_CASE && context_p->token.type != LEXER_KEYW_DEFAULT) { parser_line_info_append (context_p, context_p->token.line, context_p->token.column); @@ -3088,9 +3016,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ #endif /* !JERRY_NDEBUG */ try_statement.type = parser_try_block; - parser_emit_cbc_ext_forward_branch (context_p, - CBC_EXT_TRY_CREATE_CONTEXT, - &try_statement.branch); + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_TRY_CREATE_CONTEXT, &try_statement.branch); #if JERRY_ESNEXT try_statement.scope_stack_top = context_p->scope_stack_top; @@ -3161,10 +3087,8 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); - if ((context_p->token.flags & LEXER_WAS_NEWLINE) - || context_p->token.type == LEXER_SEMICOLON - || context_p->token.type == LEXER_EOS - || context_p->token.type == LEXER_RIGHT_BRACE) + if ((context_p->token.flags & LEXER_WAS_NEWLINE) || context_p->token.type == LEXER_SEMICOLON + || context_p->token.type == LEXER_EOS || context_p->token.type == LEXER_RIGHT_BRACE) { #if JERRY_ESNEXT if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) @@ -3382,13 +3306,12 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ { lexer_next_token (context_p); } - else if (context_p->token.type != LEXER_EOS - && !(context_p->token.flags & LEXER_WAS_NEWLINE)) + else if (context_p->token.type != LEXER_EOS && !(context_p->token.flags & LEXER_WAS_NEWLINE)) { parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); } -consume_last_statement: + consume_last_statement: while (true) { switch (context_p->stack_top_uint8) diff --git a/jerry-core/parser/js/js-parser-tagged-template-literal.c b/jerry-core/parser/js/js-parser-tagged-template-literal.c index 560a3e58..24c4aa2f 100644 --- a/jerry-core/parser/js/js-parser-tagged-template-literal.c +++ b/jerry-core/parser/js/js-parser-tagged-template-literal.c @@ -14,13 +14,15 @@ */ #include "js-parser-tagged-template-literal.h" -#include "js-lexer.h" + #include "ecma-array-object.h" #include "ecma-builtin-helpers.h" #include "ecma-gc.h" #include "ecma-helpers.h" #include "ecma-objects.h" +#include "js-lexer.h" + /* \addtogroup parser Parser * @{ * @@ -58,15 +60,13 @@ parser_tagged_template_literal_append_strings (parser_context_t *context_p, /**< } uint8_t local_byte_array[LEXER_MAX_LITERAL_LOCAL_BUFFER_SIZE]; - const uint8_t *source_p = lexer_convert_literal_to_chars (context_p, - &context_p->token.lit_location, - local_byte_array, - LEXER_STRING_NO_OPTS); + const uint8_t *source_p = + lexer_convert_literal_to_chars (context_p, &context_p->token.lit_location, local_byte_array, LEXER_STRING_NO_OPTS); ecma_string_t *raw_str_p; - ecma_string_t *cooked_str_p = ((lit_loc_p->status_flags & LEXER_FLAG_ASCII) - ? ecma_new_ecma_string_from_ascii (source_p, lit_loc_p->length) - : ecma_new_ecma_string_from_utf8 (source_p, lit_loc_p->length)); + ecma_string_t *cooked_str_p = + ((lit_loc_p->status_flags & LEXER_FLAG_ASCII) ? ecma_new_ecma_string_from_ascii (source_p, lit_loc_p->length) + : ecma_new_ecma_string_from_utf8 (source_p, lit_loc_p->length)); parser_free_allocated_buffer (context_p); @@ -74,14 +74,12 @@ parser_tagged_template_literal_append_strings (parser_context_t *context_p, /**< { context_p->source_p = context_p->token.lit_location.char_p - 1; lexer_parse_string (context_p, LEXER_STRING_RAW); - source_p = lexer_convert_literal_to_chars (context_p, - &context_p->token.lit_location, - local_byte_array, - LEXER_STRING_RAW); - - raw_str_p = ((lit_loc_p->status_flags & LEXER_FLAG_ASCII) - ? ecma_new_ecma_string_from_ascii (source_p, lit_loc_p->length) - : ecma_new_ecma_string_from_utf8 (source_p, lit_loc_p->length)); + source_p = + lexer_convert_literal_to_chars (context_p, &context_p->token.lit_location, local_byte_array, LEXER_STRING_RAW); + + raw_str_p = + ((lit_loc_p->status_flags & LEXER_FLAG_ASCII) ? ecma_new_ecma_string_from_ascii (source_p, lit_loc_p->length) + : ecma_new_ecma_string_from_utf8 (source_p, lit_loc_p->length)); parser_free_allocated_buffer (context_p); } diff --git a/jerry-core/parser/js/js-parser-tagged-template-literal.h b/jerry-core/parser/js/js-parser-tagged-template-literal.h index 2149e523..338c209b 100644 --- a/jerry-core/parser/js/js-parser-tagged-template-literal.h +++ b/jerry-core/parser/js/js-parser-tagged-template-literal.h @@ -26,20 +26,20 @@ * @{ */ -#include "common.h" #include "ecma-globals.h" + +#include "common.h" #include "js-parser-internal.h" #if JERRY_ESNEXT -ecma_object_t * -parser_new_tagged_template_literal (ecma_object_t **raw_strings_p); +ecma_object_t *parser_new_tagged_template_literal (ecma_object_t **raw_strings_p); -void -parser_tagged_template_literal_append_strings (parser_context_t *context_p, ecma_object_t *template_obj_p, - ecma_object_t *raw_strings_p, uint32_t prop_index); +void parser_tagged_template_literal_append_strings (parser_context_t *context_p, + ecma_object_t *template_obj_p, + ecma_object_t *raw_strings_p, + uint32_t prop_index); -void -parser_tagged_template_literal_finalize (ecma_object_t *template_obj_p, ecma_object_t *raw_strings_p); +void parser_tagged_template_literal_finalize (ecma_object_t *template_obj_p, ecma_object_t *raw_strings_p); #endif /* JERRY_ESNEXT */ #endif /* ECMA_TAGGED_TEMPLATE_LITERAL_H */ diff --git a/jerry-core/parser/js/js-parser-util.c b/jerry-core/parser/js/js-parser-util.c index a019e046..8a65dae4 100644 --- a/jerry-core/parser/js/js-parser-util.c +++ b/jerry-core/parser/js/js-parser-util.c @@ -13,9 +13,10 @@ * limitations under the License. */ -#include "js-parser-internal.h" #include "ecma-helpers.h" +#include "js-parser-internal.h" + #if JERRY_PARSER #if JERRY_LINE_INFO @@ -79,11 +80,11 @@ parser_emit_two_bytes (parser_context_t *context_p, /**< context */ * @param context_p parser context * @param byte byte */ -#define PARSER_APPEND_TO_BYTE_CODE(context_p, byte) \ +#define PARSER_APPEND_TO_BYTE_CODE(context_p, byte) \ if ((context_p)->byte_code.last_position >= PARSER_CBC_STREAM_PAGE_SIZE) \ - { \ - parser_cbc_stream_alloc_page ((context_p), &(context_p)->byte_code); \ - } \ + { \ + parser_cbc_stream_alloc_page ((context_p), &(context_p)->byte_code); \ + } \ (context_p)->byte_code.last_p->bytes[(context_p)->byte_code.last_position++] = (uint8_t) (byte) #if JERRY_PARSER_DUMP_BYTE_CODE @@ -177,16 +178,14 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */ } JERRY_ASSERT ((flags >> CBC_STACK_ADJUST_SHIFT) >= CBC_STACK_ADJUST_BASE - || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); + || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, CBC_STACK_ADJUST_VALUE (flags)); if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) { uint16_t literal_index = context_p->last_cbc.literal_index; - parser_emit_two_bytes (context_p, - (uint8_t) (literal_index & 0xff), - (uint8_t) (literal_index >> 8)); + parser_emit_two_bytes (context_p, (uint8_t) (literal_index & 0xff), (uint8_t) (literal_index >> 8)); context_p->byte_code_size += 2; } @@ -194,18 +193,14 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */ { uint16_t literal_index = context_p->last_cbc.value; - parser_emit_two_bytes (context_p, - (uint8_t) (literal_index & 0xff), - (uint8_t) (literal_index >> 8)); + parser_emit_two_bytes (context_p, (uint8_t) (literal_index & 0xff), (uint8_t) (literal_index >> 8)); context_p->byte_code_size += 2; if (!(flags & CBC_HAS_LITERAL_ARG)) { literal_index = context_p->last_cbc.third_literal_index; - parser_emit_two_bytes (context_p, - (uint8_t) (literal_index & 0xff), - (uint8_t) (literal_index >> 8)); + parser_emit_two_bytes (context_p, (uint8_t) (literal_index & 0xff), (uint8_t) (literal_index >> 8)); context_p->byte_code_size += 2; } } @@ -251,13 +246,11 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */ if (flags & CBC_HAS_BYTE_ARG) { - if (last_opcode == CBC_PUSH_NUMBER_POS_BYTE - || last_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) + if (last_opcode == CBC_PUSH_NUMBER_POS_BYTE || last_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) { JERRY_DEBUG_MSG (" number:%d", (int) context_p->last_cbc.value + 1); } - else if (last_opcode == CBC_PUSH_NUMBER_NEG_BYTE - || last_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) + else if (last_opcode == CBC_PUSH_NUMBER_NEG_BYTE || last_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) { JERRY_DEBUG_MSG (" number:%d", -((int) context_p->last_cbc.value + 1)); } @@ -434,15 +427,13 @@ parser_emit_cbc_push_number (parser_context_t *context_p, /**< context */ if (lit_value == PARSER_INVALID_LITERAL_INDEX) { - opcode = (is_negative_number ? CBC_PUSH_NUMBER_NEG_BYTE - : CBC_PUSH_NUMBER_POS_BYTE); + opcode = (is_negative_number ? CBC_PUSH_NUMBER_NEG_BYTE : CBC_PUSH_NUMBER_POS_BYTE); JERRY_ASSERT (CBC_STACK_ADJUST_VALUE (PARSER_GET_FLAGS (opcode)) == 1); } else { - opcode = (is_negative_number ? CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE - : CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE); + opcode = (is_negative_number ? CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE : CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE); JERRY_ASSERT (CBC_STACK_ADJUST_VALUE (PARSER_GET_FLAGS (opcode)) == 2); context_p->last_cbc.literal_index = lit_value; @@ -494,7 +485,7 @@ parser_emit_cbc_forward_branch (parser_context_t *context_p, /**< context */ /* Branch opcodes never push anything onto the stack. */ JERRY_ASSERT ((flags >> CBC_STACK_ADJUST_SHIFT) >= CBC_STACK_ADJUST_BASE - || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); + || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, CBC_STACK_ADJUST_VALUE (flags)); #if JERRY_PARSER_DUMP_BYTE_CODE @@ -606,7 +597,7 @@ parser_emit_cbc_backward_branch (parser_context_t *context_p, /**< context */ /* Branch opcodes never push anything onto the stack. */ JERRY_ASSERT ((flags >> CBC_STACK_ADJUST_SHIFT) >= CBC_STACK_ADJUST_BASE - || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); + || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, CBC_STACK_ADJUST_VALUE (flags)); #if JERRY_PARSER_DUMP_BYTE_CODE @@ -673,7 +664,7 @@ parser_new_ecma_string_from_literal (lexer_literal_t *literal_p) /**< literal */ } return new_string; -} /* parser_new_ecma_string_from_literal */ +} /* parser_new_ecma_string_from_literal */ /** * Set a branch to the current byte code position @@ -815,8 +806,7 @@ parser_reverse_class_fields (parser_context_t *context_p, /**< context */ has_fields = true; context_p->stack_top_uint8 = class_field_type; } - } - while (current_p < data_end_p); + } while (current_p < data_end_p); parser_stack_iterator_init (context_p, &iterator); current_p = data_end_p; @@ -845,8 +835,7 @@ parser_reverse_class_fields (parser_context_t *context_p, /**< context */ current_p[-1] |= PARSER_CLASS_FIELD_END; } current_p -= info_size; - } - while (current_p > data_p); + } while (current_p > data_p); } else { @@ -872,8 +861,7 @@ parser_reverse_class_fields (parser_context_t *context_p, /**< context */ parser_stack_iterator_write (&iterator, current_p, info_size); parser_stack_iterator_skip (&iterator, info_size); } - } - while (current_p > data_p); + } while (current_p > data_p); } parser_free (data_p, fields_size); diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index f29a1027..2ba45777 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -13,12 +13,13 @@ * limitations under the License. */ -#include "debugger.h" #include "ecma-exceptions.h" #include "ecma-extended-info.h" #include "ecma-helpers.h" #include "ecma-literal-storage.h" #include "ecma-module.h" + +#include "debugger.h" #include "jcontext.h" #include "js-parser-internal.h" @@ -28,8 +29,7 @@ JERRY_STATIC_ASSERT ((int) ECMA_PARSE_STRICT_MODE == (int) PARSER_IS_STRICT, ecma_parse_strict_mode_must_be_equal_to_parser_is_strict); #if JERRY_ESNEXT -JERRY_STATIC_ASSERT (PARSER_SAVE_STATUS_FLAGS (PARSER_ALLOW_SUPER) == 0x1, - incorrect_saving_of_ecma_parse_allow_super); +JERRY_STATIC_ASSERT (PARSER_SAVE_STATUS_FLAGS (PARSER_ALLOW_SUPER) == 0x1, incorrect_saving_of_ecma_parse_allow_super); JERRY_STATIC_ASSERT (PARSER_RESTORE_STATUS_FLAGS (ECMA_PARSE_ALLOW_SUPER) == PARSER_ALLOW_SUPER, incorrect_restoring_of_ecma_parse_allow_super); @@ -113,8 +113,7 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */ const uint8_t *char_p = literal_p->u.char_p; uint32_t status_flags = context_p->status_flags; - if ((literal_p->status_flags & LEXER_FLAG_SOURCE_PTR) - && literal_p->prop.length < 0xfff) + if ((literal_p->status_flags & LEXER_FLAG_SOURCE_PTR) && literal_p->prop.length < 0xfff) { size_t bytes_to_end = (size_t) (context_p->source_end_p - char_p); @@ -243,8 +242,7 @@ parser_init_literal_pool (parser_context_t *context_p, /**< context */ { JERRY_ASSERT (literal_p->prop.index >= context_p->register_count); - ECMA_SET_INTERNAL_VALUE_POINTER (literal_pool_p[literal_p->prop.index], - literal_p->u.bytecode_p); + ECMA_SET_INTERNAL_VALUE_POINTER (literal_pool_p[literal_p->prop.index], literal_p->u.bytecode_p); break; } default: @@ -417,17 +415,14 @@ parse_update_branches (parser_context_t *context_p, /**< context */ { target_distance = (target_distance << 8) | *bytes_p; bytes_p++; - } - while (--length > 0); + } while (--length > 0); if (CBC_BRANCH_IS_FORWARD (flags)) { /* Branch target was not set. */ JERRY_ASSERT (target_distance > 0); - target_distance = parser_update_forward_branch (page_p, - offset + target_distance, - bytes_copied_before_jump); + target_distance = parser_update_forward_branch (page_p, offset + target_distance, bytes_copied_before_jump); } else { @@ -444,9 +439,8 @@ parse_update_branches (parser_context_t *context_p, /**< context */ } else { - target_distance = parser_update_backward_branch (prev_page_p, - target_distance - offset, - bytes_copied_before_jump); + target_distance = + parser_update_backward_branch (prev_page_p, target_distance - offset, bytes_copied_before_jump); } } @@ -456,8 +450,7 @@ parse_update_branches (parser_context_t *context_p, /**< context */ bytes_p--; *bytes_p = (uint8_t) (target_distance & 0xff); target_distance >>= 8; - } - while (--branch_argument_length > 0); + } while (--branch_argument_length > 0); } offset++; @@ -541,13 +534,14 @@ parser_append_breakpoint_info (parser_context_t *context_p, /**< context */ * @param page_p page * @param offset offset */ -#define PARSER_NEXT_BYTE(page_p, offset) \ - do { \ +#define PARSER_NEXT_BYTE(page_p, offset) \ + do \ + { \ if (++(offset) >= PARSER_CBC_STREAM_PAGE_SIZE) \ - { \ - offset = 0; \ - page_p = page_p->next_p; \ - } \ + { \ + offset = 0; \ + page_p = page_p->next_p; \ + } \ } while (0) /** @@ -558,14 +552,15 @@ parser_append_breakpoint_info (parser_context_t *context_p, /**< context */ * @param real_offset real offset */ #define PARSER_NEXT_BYTE_UPDATE(page_p, offset, real_offset) \ - do { \ - page_p->bytes[offset] = real_offset; \ - if (++(offset) >= PARSER_CBC_STREAM_PAGE_SIZE) \ - { \ - offset = 0; \ - real_offset = 0; \ - page_p = page_p->next_p; \ - } \ + do \ + { \ + page_p->bytes[offset] = real_offset; \ + if (++(offset) >= PARSER_CBC_STREAM_PAGE_SIZE) \ + { \ + offset = 0; \ + real_offset = 0; \ + page_p = page_p->next_p; \ + } \ } while (0) /** @@ -672,8 +667,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ context_p->last_breakpoint_line = context_p->token.line; } - if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) - && context_p->breakpoint_info_count > 0) + if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) && context_p->breakpoint_info_count > 0) { parser_send_breakpoints (context_p, JERRY_DEBUGGER_BREAKPOINT_LIST); JERRY_ASSERT (context_p->breakpoint_info_count == 0); @@ -847,8 +841,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ PARSER_NEXT_BYTE (page_p, offset); } - if (last_opcode == (cbc_opcode_t) (CBC_JUMP_FORWARD + PARSER_MAX_BRANCH_LENGTH - 1) - && prefix_zero + if (last_opcode == (cbc_opcode_t) (CBC_JUMP_FORWARD + PARSER_MAX_BRANCH_LENGTH - 1) && prefix_zero && page_p->bytes[offset] == PARSER_MAX_BRANCH_LENGTH + 1) { /* Uncoditional jumps which jump right after the instruction @@ -869,8 +862,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ } } - if (!(context_p->status_flags & PARSER_NO_END_LABEL) - || !(PARSER_OPCODE_IS_RETURN (last_opcode))) + if (!(context_p->status_flags & PARSER_NO_END_LABEL) || !(PARSER_OPCODE_IS_RETURN (last_opcode))) { context_p->status_flags &= (uint32_t) ~PARSER_NO_END_LABEL; @@ -887,8 +879,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ needs_uint16_arguments = false; total_size = sizeof (cbc_uint8_arguments_t); - if (context_p->stack_limit > CBC_MAXIMUM_BYTE_VALUE - || context_p->register_count > CBC_MAXIMUM_BYTE_VALUE + if (context_p->stack_limit > CBC_MAXIMUM_BYTE_VALUE || context_p->register_count > CBC_MAXIMUM_BYTE_VALUE || context_p->literal_count > CBC_MAXIMUM_BYTE_VALUE) { needs_uint16_arguments = true; @@ -943,8 +934,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ if (function_start_p < start_p || function_start_p >= start_p + context_p->source_size) { - JERRY_ASSERT (context_p->arguments_start_p != NULL - && function_start_p >= context_p->arguments_start_p + JERRY_ASSERT (context_p->arguments_start_p != NULL && function_start_p >= context_p->arguments_start_p && function_start_p < context_p->arguments_start_p + context_p->arguments_size); start_p = context_p->arguments_start_p; @@ -1039,8 +1029,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ compiled_code_p->status_flags |= CBC_CODE_FLAGS_STRICT_MODE; } - if ((context_p->status_flags & PARSER_ARGUMENTS_NEEDED) - && PARSER_NEEDS_MAPPED_ARGUMENTS (context_p->status_flags)) + if ((context_p->status_flags & PARSER_ARGUMENTS_NEEDED) && PARSER_NEEDS_MAPPED_ARGUMENTS (context_p->status_flags)) { compiled_code_p->status_flags |= CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED; } @@ -1118,8 +1107,8 @@ parser_post_processing (parser_context_t *context_p) /**< context */ page_p = context_p->byte_code.first_p; offset = 0; real_offset = 0; - uint8_t last_register_index = (uint8_t) JERRY_MIN (context_p->register_count, - (PARSER_MAXIMUM_NUMBER_OF_REGISTERS - 1)); + uint8_t last_register_index = + (uint8_t) JERRY_MIN (context_p->register_count, (PARSER_MAXIMUM_NUMBER_OF_REGISTERS - 1)); while (page_p != last_page_p || offset < last_position) { @@ -1142,8 +1131,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ do { PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); - } - while (--counter > 0); + } while (--counter > 0); continue; } @@ -1178,8 +1166,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ } /* Only literal and call arguments can be combined. */ - JERRY_ASSERT (!(flags & CBC_HAS_BRANCH_ARG) - || !(flags & (CBC_HAS_BYTE_ARG | CBC_HAS_LITERAL_ARG))); + JERRY_ASSERT (!(flags & CBC_HAS_BRANCH_ARG) || !(flags & (CBC_HAS_BYTE_ARG | CBC_HAS_LITERAL_ARG))); while (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) { @@ -1267,8 +1254,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ } #if JERRY_DEBUGGER - if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) - && context_p->breakpoint_info_count > 0) + if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) && context_p->breakpoint_info_count > 0) { parser_send_breakpoints (context_p, JERRY_DEBUGGER_BREAKPOINT_OFFSET_LIST); JERRY_ASSERT (context_p->breakpoint_info_count == 0); @@ -1307,8 +1293,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator))) { - if ((literal_p->status_flags & LEXER_FLAG_LATE_INIT) - && literal_p->prop.index >= register_count) + if ((literal_p->status_flags & LEXER_FLAG_LATE_INIT) && literal_p->prop.index >= register_count) { uint32_t source_data = literal_p->u.source_data; const uint8_t *char_p = context_p->source_end_p - (source_data & 0xfffff); @@ -1550,10 +1535,8 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */ parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_REST_OBJECT); } - uint32_t flags = (PARSER_PATTERN_BINDING - | PARSER_PATTERN_TARGET_ON_STACK - | PARSER_PATTERN_LOCAL - | PARSER_PATTERN_ARGUMENTS); + uint32_t flags = + (PARSER_PATTERN_BINDING | PARSER_PATTERN_TARGET_ON_STACK | PARSER_PATTERN_LOCAL | PARSER_PATTERN_ARGUMENTS); if (context_p->next_scanner_info_p->source_p == context_p->source_p) { @@ -1602,8 +1585,8 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */ { if (context_p->token.type != end_type) { - parser_error_t error = ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED - : PARSER_ERR_IDENTIFIER_EXPECTED); + parser_error_t error = + ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED : PARSER_ERR_IDENTIFIER_EXPECTED); parser_raise_error (context_p, error); } @@ -1620,15 +1603,12 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); } - lexer_construct_literal_object (context_p, - &context_p->token.lit_location, - LEXER_IDENT_LITERAL); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); if (context_p->token.keyword_type >= LEXER_FIRST_NON_STRICT_ARGUMENTS) { @@ -1749,8 +1729,8 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */ { if (context_p->token.type != end_type) { - parser_error_t error = ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED - : PARSER_ERR_IDENTIFIER_EXPECTED); + parser_error_t error = + ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED : PARSER_ERR_IDENTIFIER_EXPECTED); parser_raise_error (context_p, error); } @@ -1863,8 +1843,7 @@ parser_parse_source (void *source_p, /**< source code */ context.argument_list = ECMA_VALUE_EMPTY; - if (context.options_p != NULL - && (context.options_p->options & JERRY_PARSE_HAS_ARGUMENT_LIST)) + if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_ARGUMENT_LIST)) { context.argument_list = context.options_p->argument_list; } @@ -1935,8 +1914,7 @@ parser_parse_source (void *source_p, /**< source code */ context.user_value = ECMA_VALUE_EMPTY; - if ((context.global_status_flags & ECMA_PARSE_EVAL) - && JERRY_CONTEXT (vm_top_context_p) != NULL) + if ((context.global_status_flags & ECMA_PARSE_EVAL) && JERRY_CONTEXT (vm_top_context_p) != NULL) { const ecma_compiled_code_t *bytecode_header_p = JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p; @@ -1944,7 +1922,8 @@ parser_parse_source (void *source_p, /**< source code */ if (JERRY_LIKELY (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))) { #endif /* JERRY_SNAPSHOT_EXEC */ - ecma_value_t parent_script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value;; + ecma_value_t parent_script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value; + ; cbc_script_t *parent_script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, parent_script_value); if (parent_script_p->refs_and_type & CBC_SCRIPT_HAS_USER_VALUE) @@ -1955,8 +1934,7 @@ parser_parse_source (void *source_p, /**< source code */ } #endif /* JERRY_SNAPSHOT_EXEC */ } - else if (context.options_p != NULL - && (context.options_p->options & JERRY_PARSE_HAS_USER_VALUE)) + else if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_USER_VALUE)) { context.user_value = context.options_p->user_value; } @@ -1964,8 +1942,7 @@ parser_parse_source (void *source_p, /**< source code */ #if JERRY_RESOURCE_NAME ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); - if (context.options_p != NULL - && (context.options_p->options & JERRY_PARSE_HAS_RESOURCE)) + if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_RESOURCE)) { JERRY_ASSERT (ecma_is_value_string (context.options_p->resource_name)); @@ -2034,9 +2011,7 @@ parser_parse_source (void *source_p, /**< source code */ if (context.is_show_opcodes) { - JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", - (context.arguments_start_p == NULL) ? "Script" - : "Function"); + JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", (context.arguments_start_p == NULL) ? "Script" : "Function"); } #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ @@ -2195,10 +2170,8 @@ parser_parse_source (void *source_p, /**< source code */ parser_list_free (&context.literal_pool); /* When parsing is successful, only the dummy value can be remained on the stack. */ - JERRY_ASSERT (context.stack_top_uint8 == CBC_MAXIMUM_BYTE_VALUE - && context.stack.last_position == 1 - && context.stack.first_p != NULL - && context.stack.first_p->next_p == NULL + JERRY_ASSERT (context.stack_top_uint8 == CBC_MAXIMUM_BYTE_VALUE && context.stack.last_position == 1 + && context.stack.first_p != NULL && context.stack.first_p->next_p == NULL && context.stack.last_p == NULL); JERRY_ASSERT (context.arguments_start_p != NULL || !(context.status_flags & PARSER_ARGUMENTS_NEEDED)); @@ -2260,8 +2233,7 @@ parser_parse_source (void *source_p, /**< source code */ if (context.is_show_opcodes) { JERRY_DEBUG_MSG ("\n%s parsing successfully completed. Total byte code size: %d bytes\n", - (context.arguments_start_p == NULL) ? "Script" - : "Function", + (context.arguments_start_p == NULL) ? "Script" : "Function", (int) context.total_byte_code_size); } #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ @@ -2282,7 +2254,7 @@ parser_parse_source (void *source_p, /**< source code */ { ecma_module_release_module_names (context.module_names_p); } -#endif +#endif /* JERRY_MODULE_SYSTEM */ compiled_code_p = NULL; parser_free_literals (&context.literal_pool); @@ -2312,9 +2284,7 @@ parser_parse_source (void *source_p, /**< source code */ #if JERRY_PARSER_DUMP_BYTE_CODE if (context.is_show_opcodes) { - JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", - (context.arguments_start_p == NULL) ? "Script" - : "Function"); + JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", (context.arguments_start_p == NULL) ? "Script" : "Function"); } #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ @@ -2356,8 +2326,8 @@ parser_parse_source (void *source_p, /**< source code */ if (context.error == PARSER_ERR_INVALID_REGEXP) { ecma_value_t error = jcontext_take_exception (); - ecma_property_t *prop_p = ecma_find_named_property (ecma_get_object_from_value (error), - ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE)); + ecma_property_t *prop_p = + ecma_find_named_property (ecma_get_object_from_value (error), ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE)); ecma_free_value (error); JERRY_ASSERT (prop_p); err_str_p = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (prop_p)->value); @@ -2405,8 +2375,7 @@ parser_save_context (parser_context_t *context_p, /**< context */ JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); #if JERRY_DEBUGGER - if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) - && context_p->breakpoint_info_count > 0) + if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) && context_p->breakpoint_info_count > 0) { parser_send_breakpoints (context_p, JERRY_DEBUGGER_BREAKPOINT_LIST); context_p->breakpoint_info_count = 0; @@ -2575,8 +2544,7 @@ parser_parse_function (parser_context_t *context_p, /**< context */ { #if JERRY_ESNEXT JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", - (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) ? "Class constructor" - : "Function"); + (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) ? "Class constructor" : "Function"); #else /* !JERRY_ESNEXT */ JERRY_DEBUG_MSG ("\n--- Function parsing start ---\n\n"); #endif /* JERRY_ESNEXT */ @@ -2602,14 +2570,12 @@ parser_parse_function (parser_context_t *context_p, /**< context */ parser_parse_function_arguments (context_p, LEXER_RIGHT_PAREN); lexer_next_token (context_p); - if ((context_p->status_flags & PARSER_IS_PROPERTY_GETTER) - && context_p->argument_count != 0) + if ((context_p->status_flags & PARSER_IS_PROPERTY_GETTER) && context_p->argument_count != 0) { parser_raise_error (context_p, PARSER_ERR_NO_ARGUMENTS_EXPECTED); } - if ((context_p->status_flags & PARSER_IS_PROPERTY_SETTER) - && context_p->argument_count != 1) + if ((context_p->status_flags & PARSER_IS_PROPERTY_SETTER) && context_p->argument_count != 1) { parser_raise_error (context_p, PARSER_ERR_ONE_ARGUMENT_EXPECTED); } @@ -2623,8 +2589,7 @@ parser_parse_function (parser_context_t *context_p, /**< context */ #endif /* JERRY_ESNEXT */ #if JERRY_PARSER_DUMP_BYTE_CODE - if (context_p->is_show_opcodes - && (context_p->status_flags & PARSER_HAS_NON_STRICT_ARG)) + if (context_p->is_show_opcodes && (context_p->status_flags & PARSER_HAS_NON_STRICT_ARG)) { JERRY_DEBUG_MSG (" Note: legacy (non-strict) argument definition\n\n"); } @@ -2644,8 +2609,7 @@ parser_parse_function (parser_context_t *context_p, /**< context */ { #if JERRY_ESNEXT JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", - (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) ? "Class constructor" - : "Function"); + (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) ? "Class constructor" : "Function"); #else /* !JERRY_ESNEXT */ JERRY_DEBUG_MSG ("\n--- Function parsing end ---\n\n"); #endif /* JERRY_ESNEXT */ @@ -2675,9 +2639,8 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */ JERRY_ASSERT (status_flags & PARSER_IS_ARROW_FUNCTION); parser_save_context (context_p, &saved_context); context_p->status_flags |= status_flags; - context_p->status_flags |= saved_context.status_flags & (PARSER_ALLOW_NEW_TARGET - | PARSER_ALLOW_SUPER - | PARSER_ALLOW_SUPER_CALL); + context_p->status_flags |= + saved_context.status_flags & (PARSER_ALLOW_NEW_TARGET | PARSER_ALLOW_SUPER | PARSER_ALLOW_SUPER_CALL); #if JERRY_PARSER_DUMP_BYTE_CODE if (context_p->is_show_opcodes) @@ -2721,8 +2684,7 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */ } else { - if (context_p->status_flags & PARSER_IS_STRICT - && context_p->status_flags & PARSER_HAS_NON_STRICT_ARG) + if (context_p->status_flags & PARSER_IS_STRICT && context_p->status_flags & PARSER_HAS_NON_STRICT_ARG) { parser_raise_error (context_p, PARSER_ERR_NON_STRICT_ARG_DEFINITION); } @@ -2774,11 +2736,8 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */ uint32_t extra_status_flags = context_p->status_flags & PARSER_INSIDE_WITH; parser_save_context (context_p, &saved_context); - context_p->status_flags |= (PARSER_IS_FUNCTION - | PARSER_ALLOW_SUPER - | PARSER_INSIDE_CLASS_FIELD - | PARSER_ALLOW_NEW_TARGET - | extra_status_flags); + context_p->status_flags |= (PARSER_IS_FUNCTION | PARSER_ALLOW_SUPER | PARSER_INSIDE_CLASS_FIELD + | PARSER_ALLOW_NEW_TARGET | extra_status_flags); #if JERRY_PARSER_DUMP_BYTE_CODE if (context_p->is_show_opcodes) @@ -2804,7 +2763,7 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */ uint8_t class_field_type = context_p->stack_top_uint8; parser_stack_pop_uint8 (context_p); - scanner_range_t range = {0}; + scanner_range_t range = { 0 }; if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED) { @@ -2893,8 +2852,7 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */ parser_emit_cbc_ext (context_p, CBC_EXT_SET_NEXT_COMPUTED_FIELD); } - } - while (!(context_p->stack_top_uint8 & PARSER_CLASS_FIELD_END)); + } while (!(context_p->stack_top_uint8 & PARSER_CLASS_FIELD_END)); if (!first_computed_class_field) { @@ -2968,8 +2926,8 @@ parser_check_anonymous_function_declaration (parser_context_t *context_p) /**< c const ecma_compiled_code_t *bytecode_p; bytecode_p = (const ecma_compiled_code_t *) (PARSER_GET_LITERAL (literal_index)->u.bytecode_p); - bool is_anon = ecma_is_value_magic_string (*ecma_compiled_code_resolve_function_name (bytecode_p), - LIT_MAGIC_STRING__EMPTY); + bool is_anon = + ecma_is_value_magic_string (*ecma_compiled_code_resolve_function_name (bytecode_p), LIT_MAGIC_STRING__EMPTY); return (is_anon ? literal_index : PARSER_NAMED_FUNCTION); } /* parser_check_anonymous_function_declaration */ @@ -3015,8 +2973,7 @@ parser_compiled_code_set_function_name (parser_context_t *context_p, /**< contex { scope_stack_p--; - if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC - && scanner_decode_map_to (scope_stack_p) == name_index) + if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC && scanner_decode_map_to (scope_stack_p) == name_index) { name_index = scope_stack_p->map_from; break; @@ -3042,9 +2999,8 @@ parser_compiled_code_set_function_name (parser_context_t *context_p, /**< contex memcpy (name_buffer_p + 4, name_lit_p->u.char_p, name_lit_p->prop.length); } - *func_name_start_p = ecma_find_or_create_literal_string (name_buffer_p, - name_length, - (status_flags & LEXER_FLAG_ASCII) != 0); + *func_name_start_p = + ecma_find_or_create_literal_string (name_buffer_p, name_length, (status_flags & LEXER_FLAG_ASCII) != 0); if (name_buffer_p != name_lit_p->u.char_p) { @@ -3092,8 +3048,8 @@ parser_raise_error (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT if (saved_context_p->tagged_template_literal_cp != JMEM_CP_NULL) { - ecma_collection_t *collection = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, - saved_context_p->tagged_template_literal_cp); + ecma_collection_t *collection = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, saved_context_p->tagged_template_literal_cp); ecma_collection_free_template_literal (collection); } #endif /* JERRY_ESNEXT */ @@ -3108,8 +3064,8 @@ parser_raise_error (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT if (context_p->tagged_template_literal_cp != JMEM_CP_NULL) { - ecma_collection_t *collection = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, - context_p->tagged_template_literal_cp); + ecma_collection_t *collection = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, context_p->tagged_template_literal_cp); ecma_collection_free_template_literal (collection); } #endif /* JERRY_ESNEXT */ @@ -3138,9 +3094,7 @@ parser_parse_script (void *source_p, /**< source code */ const jerry_parse_options_t *options_p) /**< additional configuration options */ { #if JERRY_PARSER - ecma_compiled_code_t *bytecode_p = parser_parse_source (source_p, - parse_opts, - options_p); + ecma_compiled_code_t *bytecode_p = parser_parse_source (source_p, parse_opts, options_p); if (JERRY_UNLIKELY (bytecode_p == NULL)) { diff --git a/jerry-core/parser/js/js-parser.h b/jerry-core/parser/js/js-parser.h index 0972b841..6274cb5f 100644 --- a/jerry-core/parser/js/js-parser.h +++ b/jerry-core/parser/js/js-parser.h @@ -33,179 +33,164 @@ */ typedef enum { - PARSER_ERR_NO_ERROR, /**< no error */ + PARSER_ERR_NO_ERROR, /**< no error */ - PARSER_ERR_OUT_OF_MEMORY, /**< out of memory */ - PARSER_ERR_LITERAL_LIMIT_REACHED, /**< maximum number of literals reached */ - PARSER_ERR_SCOPE_STACK_LIMIT_REACHED, /**< maximum depth of scope stack reached */ - PARSER_ERR_ARGUMENT_LIMIT_REACHED, /**< maximum number of function arguments reached */ - PARSER_ERR_STACK_LIMIT_REACHED, /**< maximum function stack size reached */ + PARSER_ERR_OUT_OF_MEMORY, /**< out of memory */ + PARSER_ERR_LITERAL_LIMIT_REACHED, /**< maximum number of literals reached */ + PARSER_ERR_SCOPE_STACK_LIMIT_REACHED, /**< maximum depth of scope stack reached */ + PARSER_ERR_ARGUMENT_LIMIT_REACHED, /**< maximum number of function arguments reached */ + PARSER_ERR_STACK_LIMIT_REACHED, /**< maximum function stack size reached */ - PARSER_ERR_INVALID_CHARACTER, /**< unexpected character */ - PARSER_ERR_INVALID_OCTAL_DIGIT, /**< invalid octal digit */ - PARSER_ERR_INVALID_HEX_DIGIT, /**< invalid hexadecimal digit */ + PARSER_ERR_INVALID_CHARACTER, /**< unexpected character */ + PARSER_ERR_INVALID_OCTAL_DIGIT, /**< invalid octal digit */ + PARSER_ERR_INVALID_HEX_DIGIT, /**< invalid hexadecimal digit */ #if JERRY_ESNEXT - PARSER_ERR_INVALID_BIN_DIGIT, /**< invalid binary digit */ + PARSER_ERR_INVALID_BIN_DIGIT, /**< invalid binary digit */ #endif /* JERRY_ESNEXT */ - PARSER_ERR_INVALID_ESCAPE_SEQUENCE, /**< invalid escape sequence */ - PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE, /**< invalid unicode escape sequence */ - PARSER_ERR_INVALID_IDENTIFIER_START, /**< character cannot be start of an identifier */ - PARSER_ERR_INVALID_IDENTIFIER_PART, /**< character cannot be part of an identifier */ - PARSER_ERR_INVALID_KEYWORD, /**< escape sequences are not allowed in keywords */ - - PARSER_ERR_INVALID_NUMBER, /**< invalid number literal */ - PARSER_ERR_MISSING_EXPONENT, /**< missing exponent */ - PARSER_ERR_IDENTIFIER_AFTER_NUMBER, /**< identifier start after number */ - PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER, /**< invalid use of underscore in number */ + PARSER_ERR_INVALID_ESCAPE_SEQUENCE, /**< invalid escape sequence */ + PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE, /**< invalid unicode escape sequence */ + PARSER_ERR_INVALID_IDENTIFIER_START, /**< character cannot be start of an identifier */ + PARSER_ERR_INVALID_IDENTIFIER_PART, /**< character cannot be part of an identifier */ + PARSER_ERR_INVALID_KEYWORD, /**< escape sequences are not allowed in keywords */ + + PARSER_ERR_INVALID_NUMBER, /**< invalid number literal */ + PARSER_ERR_MISSING_EXPONENT, /**< missing exponent */ + PARSER_ERR_IDENTIFIER_AFTER_NUMBER, /**< identifier start after number */ + PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER, /**< invalid use of underscore in number */ #if JERRY_BUILTIN_BIGINT - PARSER_ERR_INVALID_BIGINT, /**< number is not a valid BigInt */ + PARSER_ERR_INVALID_BIGINT, /**< number is not a valid BigInt */ #endif /* JERRY_BUILTIN_BIGINT */ - PARSER_ERR_INVALID_REGEXP, /**< invalid regular expression */ - PARSER_ERR_UNKNOWN_REGEXP_FLAG, /**< unknown regexp flag */ - PARSER_ERR_DUPLICATED_REGEXP_FLAG, /**< duplicated regexp flag */ - PARSER_ERR_UNSUPPORTED_REGEXP, /**< regular expression is not supported */ + PARSER_ERR_INVALID_REGEXP, /**< invalid regular expression */ + PARSER_ERR_UNKNOWN_REGEXP_FLAG, /**< unknown regexp flag */ + PARSER_ERR_DUPLICATED_REGEXP_FLAG, /**< duplicated regexp flag */ + PARSER_ERR_UNSUPPORTED_REGEXP, /**< regular expression is not supported */ - PARSER_ERR_IDENTIFIER_TOO_LONG, /**< too long identifier */ - PARSER_ERR_STRING_TOO_LONG, /**< too long string literal */ - PARSER_ERR_NUMBER_TOO_LONG, /**< too long number literal */ - PARSER_ERR_REGEXP_TOO_LONG, /**< too long regexp literal */ + PARSER_ERR_IDENTIFIER_TOO_LONG, /**< too long identifier */ + PARSER_ERR_STRING_TOO_LONG, /**< too long string literal */ + PARSER_ERR_NUMBER_TOO_LONG, /**< too long number literal */ + PARSER_ERR_REGEXP_TOO_LONG, /**< too long regexp literal */ - PARSER_ERR_UNTERMINATED_MULTILINE_COMMENT, /**< unterminated multiline comment */ - PARSER_ERR_UNTERMINATED_STRING, /**< unterminated string literal */ - PARSER_ERR_UNTERMINATED_REGEXP, /**< unterminated regexp literal */ + PARSER_ERR_UNTERMINATED_MULTILINE_COMMENT, /**< unterminated multiline comment */ + PARSER_ERR_UNTERMINATED_STRING, /**< unterminated string literal */ + PARSER_ERR_UNTERMINATED_REGEXP, /**< unterminated regexp literal */ - PARSER_ERR_NEWLINE_NOT_ALLOWED, /**< newline is not allowed */ - PARSER_ERR_OCTAL_NUMBER_NOT_ALLOWED, /**< octal numbers are not allowed in strict mode */ - PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED, /**< octal escape sequences are not allowed in strict mode */ + PARSER_ERR_NEWLINE_NOT_ALLOWED, /**< newline is not allowed */ + PARSER_ERR_OCTAL_NUMBER_NOT_ALLOWED, /**< octal numbers are not allowed in strict mode */ + PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED, /**< octal escape sequences are not allowed in strict mode */ #if JERRY_ESNEXT - PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE, /**< octal escape sequences are not allowed in template strings */ + PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE, /**< octal escape sequences are not allowed in template strings */ #endif /* JERRY_ESNEXT */ - PARSER_ERR_STRICT_IDENT_NOT_ALLOWED, /**< identifier name is reserved in strict mode */ - PARSER_ERR_EVAL_NOT_ALLOWED, /**< eval is not allowed here in strict mode */ - PARSER_ERR_ARGUMENTS_NOT_ALLOWED, /**< arguments is not allowed here in strict mode */ + PARSER_ERR_STRICT_IDENT_NOT_ALLOWED, /**< identifier name is reserved in strict mode */ + PARSER_ERR_EVAL_NOT_ALLOWED, /**< eval is not allowed here in strict mode */ + PARSER_ERR_ARGUMENTS_NOT_ALLOWED, /**< arguments is not allowed here in strict mode */ #if JERRY_ESNEXT - PARSER_ERR_USE_STRICT_NOT_ALLOWED, /**< use strict directive is not allowed */ - PARSER_ERR_YIELD_NOT_ALLOWED, /**< yield expression is not allowed */ - PARSER_ERR_AWAIT_NOT_ALLOWED, /**< await expression is not allowed */ - PARSER_ERR_FOR_IN_OF_DECLARATION, /**< variable declaration in for-in or for-of loop */ - PARSER_ERR_FOR_AWAIT_NO_ASYNC, /**< for-await-of is only allowed inside async functions */ - PARSER_ERR_FOR_AWAIT_NO_OF, /**< only 'of' form is allowed for for-await loops */ - PARSER_ERR_DUPLICATED_PROTO, /**< duplicated __proto__ fields are not allowed */ - PARSER_ERR_INVALID_LHS_ASSIGNMENT, /**< invalid LeftHandSide in assignment */ - PARSER_ERR_INVALID_LHS_POSTFIX_OP, /**< invalid LeftHandSide expression in postfix operation */ - PARSER_ERR_INVALID_LHS_PREFIX_OP, /**< invalid LeftHandSide expression in prefix operation */ - PARSER_ERR_INVALID_LHS_FOR_LOOP, /**< invalid LeftHandSide in for-loop */ + PARSER_ERR_USE_STRICT_NOT_ALLOWED, /**< use strict directive is not allowed */ + PARSER_ERR_YIELD_NOT_ALLOWED, /**< yield expression is not allowed */ + PARSER_ERR_AWAIT_NOT_ALLOWED, /**< await expression is not allowed */ + PARSER_ERR_FOR_IN_OF_DECLARATION, /**< variable declaration in for-in or for-of loop */ + PARSER_ERR_FOR_AWAIT_NO_ASYNC, /**< for-await-of is only allowed inside async functions */ + PARSER_ERR_FOR_AWAIT_NO_OF, /**< only 'of' form is allowed for for-await loops */ + PARSER_ERR_DUPLICATED_PROTO, /**< duplicated __proto__ fields are not allowed */ + PARSER_ERR_INVALID_LHS_ASSIGNMENT, /**< invalid LeftHandSide in assignment */ + PARSER_ERR_INVALID_LHS_POSTFIX_OP, /**< invalid LeftHandSide expression in postfix operation */ + PARSER_ERR_INVALID_LHS_PREFIX_OP, /**< invalid LeftHandSide expression in prefix operation */ + PARSER_ERR_INVALID_LHS_FOR_LOOP, /**< invalid LeftHandSide in for-loop */ #endif /* JERRY_ESNEXT */ - PARSER_ERR_DELETE_IDENT_NOT_ALLOWED, /**< identifier delete is not allowed in strict mode */ - PARSER_ERR_EVAL_CANNOT_ASSIGNED, /**< eval cannot be assigned in strict mode */ - PARSER_ERR_ARGUMENTS_CANNOT_ASSIGNED, /**< arguments cannot be assigned in strict mode */ - PARSER_ERR_WITH_NOT_ALLOWED, /**< with statement is not allowed in strict mode */ - PARSER_ERR_MULTIPLE_DEFAULTS_NOT_ALLOWED, /**< multiple default cases are not allowed */ - PARSER_ERR_DEFAULT_NOT_IN_SWITCH, /**< default statement is not in switch block */ - PARSER_ERR_CASE_NOT_IN_SWITCH, /**< case statement is not in switch block */ - - PARSER_ERR_LEFT_PAREN_EXPECTED, /**< left paren expected */ - PARSER_ERR_LEFT_BRACE_EXPECTED, /**< left brace expected */ - PARSER_ERR_RIGHT_PAREN_EXPECTED, /**< right paren expected */ - PARSER_ERR_RIGHT_SQUARE_EXPECTED, /**< right square expected */ - - PARSER_ERR_UNEXPECTED_END, /**< unexpected end of input */ - PARSER_ERR_COLON_EXPECTED, /**< colon expected */ - PARSER_ERR_COLON_FOR_CONDITIONAL_EXPECTED, /**< colon expected for conditional expression */ - PARSER_ERR_SEMICOLON_EXPECTED, /**< semicolon expected */ - PARSER_ERR_IN_EXPECTED, /**< in keyword expected */ - PARSER_ERR_WHILE_EXPECTED, /**< while expected for do-while loop */ - PARSER_ERR_CATCH_FINALLY_EXPECTED, /**< catch or finally expected */ - PARSER_ERR_ARRAY_ITEM_SEPARATOR_EXPECTED, /**< array item separator expected */ - PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED, /**< object item separator expected */ - PARSER_ERR_IDENTIFIER_EXPECTED, /**< identifier expected */ - PARSER_ERR_EXPRESSION_EXPECTED, /**< expression expected */ - PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED, /**< left-hand-side expression expected */ - PARSER_ERR_STATEMENT_EXPECTED, /**< statement expected */ - PARSER_ERR_PROPERTY_IDENTIFIER_EXPECTED, /**< property identifier expected */ - PARSER_ERR_ARGUMENT_LIST_EXPECTED, /**< argument list expected */ - PARSER_ERR_NO_ARGUMENTS_EXPECTED, /**< property getters must have no arguments */ - PARSER_ERR_ONE_ARGUMENT_EXPECTED, /**< property setters must have one argument */ - - PARSER_ERR_INVALID_EXPRESSION, /**< invalid expression */ - PARSER_ERR_INVALID_SWITCH, /**< invalid switch body */ - PARSER_ERR_INVALID_BREAK, /**< break must be inside a loop or switch */ - PARSER_ERR_INVALID_BREAK_LABEL, /**< break target not found */ - PARSER_ERR_INVALID_CONTINUE, /**< continue must be inside a loop */ - PARSER_ERR_INVALID_CONTINUE_LABEL, /**< continue target not found */ - PARSER_ERR_INVALID_RETURN, /**< return must be inside a function */ - PARSER_ERR_INVALID_RIGHT_SQUARE, /**< right square must terminate a block */ - PARSER_ERR_DUPLICATED_LABEL, /**< duplicated label */ - PARSER_ERR_OBJECT_PROPERTY_REDEFINED, /**< property of object literal redefined */ + PARSER_ERR_DELETE_IDENT_NOT_ALLOWED, /**< identifier delete is not allowed in strict mode */ + PARSER_ERR_EVAL_CANNOT_ASSIGNED, /**< eval cannot be assigned in strict mode */ + PARSER_ERR_ARGUMENTS_CANNOT_ASSIGNED, /**< arguments cannot be assigned in strict mode */ + PARSER_ERR_WITH_NOT_ALLOWED, /**< with statement is not allowed in strict mode */ + PARSER_ERR_MULTIPLE_DEFAULTS_NOT_ALLOWED, /**< multiple default cases are not allowed */ + PARSER_ERR_DEFAULT_NOT_IN_SWITCH, /**< default statement is not in switch block */ + PARSER_ERR_CASE_NOT_IN_SWITCH, /**< case statement is not in switch block */ + + PARSER_ERR_LEFT_PAREN_EXPECTED, /**< left paren expected */ + PARSER_ERR_LEFT_BRACE_EXPECTED, /**< left brace expected */ + PARSER_ERR_RIGHT_PAREN_EXPECTED, /**< right paren expected */ + PARSER_ERR_RIGHT_SQUARE_EXPECTED, /**< right square expected */ + + PARSER_ERR_UNEXPECTED_END, /**< unexpected end of input */ + PARSER_ERR_COLON_EXPECTED, /**< colon expected */ + PARSER_ERR_COLON_FOR_CONDITIONAL_EXPECTED, /**< colon expected for conditional expression */ + PARSER_ERR_SEMICOLON_EXPECTED, /**< semicolon expected */ + PARSER_ERR_IN_EXPECTED, /**< in keyword expected */ + PARSER_ERR_WHILE_EXPECTED, /**< while expected for do-while loop */ + PARSER_ERR_CATCH_FINALLY_EXPECTED, /**< catch or finally expected */ + PARSER_ERR_ARRAY_ITEM_SEPARATOR_EXPECTED, /**< array item separator expected */ + PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED, /**< object item separator expected */ + PARSER_ERR_IDENTIFIER_EXPECTED, /**< identifier expected */ + PARSER_ERR_EXPRESSION_EXPECTED, /**< expression expected */ + PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED, /**< left-hand-side expression expected */ + PARSER_ERR_STATEMENT_EXPECTED, /**< statement expected */ + PARSER_ERR_PROPERTY_IDENTIFIER_EXPECTED, /**< property identifier expected */ + PARSER_ERR_ARGUMENT_LIST_EXPECTED, /**< argument list expected */ + PARSER_ERR_NO_ARGUMENTS_EXPECTED, /**< property getters must have no arguments */ + PARSER_ERR_ONE_ARGUMENT_EXPECTED, /**< property setters must have one argument */ + + PARSER_ERR_INVALID_EXPRESSION, /**< invalid expression */ + PARSER_ERR_INVALID_SWITCH, /**< invalid switch body */ + PARSER_ERR_INVALID_BREAK, /**< break must be inside a loop or switch */ + PARSER_ERR_INVALID_BREAK_LABEL, /**< break target not found */ + PARSER_ERR_INVALID_CONTINUE, /**< continue must be inside a loop */ + PARSER_ERR_INVALID_CONTINUE_LABEL, /**< continue target not found */ + PARSER_ERR_INVALID_RETURN, /**< return must be inside a function */ + PARSER_ERR_INVALID_RIGHT_SQUARE, /**< right square must terminate a block */ + PARSER_ERR_DUPLICATED_LABEL, /**< duplicated label */ + PARSER_ERR_OBJECT_PROPERTY_REDEFINED, /**< property of object literal redefined */ #if JERRY_ESNEXT - PARSER_ERR_VARIABLE_REDECLARED, /**< a variable redeclared */ - PARSER_ERR_LEXICAL_SINGLE_STATEMENT, /**< lexical declaration in single statement context */ - PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK, /**< labelled functions are only allowed inside blocks */ - PARSER_ERR_LEXICAL_LET_BINDING, /**< let binding cannot be declared in let/const */ - PARSER_ERR_MISSING_ASSIGN_AFTER_CONST, /**< an assignment is required after a const declaration */ - - PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS, /**< multiple class constructor */ - PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, /**< class constructor cannot be an accessor */ - PARSER_ERR_INVALID_CLASS_CONSTRUCTOR, /**< class constructor cannot be a generator or async function */ - PARSER_ERR_CLASS_STATIC_PROTOTYPE, /**< static method name 'prototype' is not allowed */ - PARSER_ERR_UNEXPECTED_SUPER_KEYWORD, /**< unexpected super keyword */ - PARSER_ERR_TOO_MANY_CLASS_FIELDS, /**< too many computed class fields */ - PARSER_ERR_ARGUMENTS_IN_CLASS_FIELD, /**< arguments is not allowed in class fields */ - - PARSER_ERR_RIGHT_BRACE_EXPECTED, /**< right brace expected */ - PARSER_ERR_OF_EXPECTED, /**< of keyword expected */ - - PARSER_ERR_ASSIGNMENT_EXPECTED, /**< assignment expression expected */ - PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER, /**< formal parameter after rest parameter */ - PARSER_ERR_SETTER_REST_PARAMETER, /**< setter rest parameter */ - PARSER_ERR_REST_PARAMETER_DEFAULT_INITIALIZER, /**< rest parameter default initializer */ - PARSER_ERR_DUPLICATED_ARGUMENT_NAMES, /**< duplicated argument names */ - PARSER_ERR_INVALID_DESTRUCTURING_PATTERN, /**< invalid destructuring pattern */ - PARSER_ERR_ILLEGAL_PROPERTY_IN_DECLARATION, /**< illegal property in declaration context */ - PARSER_ERR_INVALID_EXPONENTIATION, /**< left operand of ** operator cannot be unary expression */ - PARSER_ERR_INVALID_NULLISH_COALESCING, /**< Cannot chain nullish with logical AND or OR. */ - PARSER_ERR_NEW_TARGET_EXPECTED, /**< expected new.target expression */ - PARSER_ERR_NEW_TARGET_NOT_ALLOWED, /**< new.target is not allowed in the given context */ + PARSER_ERR_VARIABLE_REDECLARED, /**< a variable redeclared */ + PARSER_ERR_LEXICAL_SINGLE_STATEMENT, /**< lexical declaration in single statement context */ + PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK, /**< labelled functions are only allowed inside blocks */ + PARSER_ERR_LEXICAL_LET_BINDING, /**< let binding cannot be declared in let/const */ + PARSER_ERR_MISSING_ASSIGN_AFTER_CONST, /**< an assignment is required after a const declaration */ + + PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS, /**< multiple class constructor */ + PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, /**< class constructor cannot be an accessor */ + PARSER_ERR_INVALID_CLASS_CONSTRUCTOR, /**< class constructor cannot be a generator or async function */ + PARSER_ERR_CLASS_STATIC_PROTOTYPE, /**< static method name 'prototype' is not allowed */ + PARSER_ERR_UNEXPECTED_SUPER_KEYWORD, /**< unexpected super keyword */ + PARSER_ERR_TOO_MANY_CLASS_FIELDS, /**< too many computed class fields */ + PARSER_ERR_ARGUMENTS_IN_CLASS_FIELD, /**< arguments is not allowed in class fields */ + + PARSER_ERR_RIGHT_BRACE_EXPECTED, /**< right brace expected */ + PARSER_ERR_OF_EXPECTED, /**< of keyword expected */ + + PARSER_ERR_ASSIGNMENT_EXPECTED, /**< assignment expression expected */ + PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER, /**< formal parameter after rest parameter */ + PARSER_ERR_SETTER_REST_PARAMETER, /**< setter rest parameter */ + PARSER_ERR_REST_PARAMETER_DEFAULT_INITIALIZER, /**< rest parameter default initializer */ + PARSER_ERR_DUPLICATED_ARGUMENT_NAMES, /**< duplicated argument names */ + PARSER_ERR_INVALID_DESTRUCTURING_PATTERN, /**< invalid destructuring pattern */ + PARSER_ERR_ILLEGAL_PROPERTY_IN_DECLARATION, /**< illegal property in declaration context */ + PARSER_ERR_INVALID_EXPONENTIATION, /**< left operand of ** operator cannot be unary expression */ + PARSER_ERR_INVALID_NULLISH_COALESCING, /**< Cannot chain nullish with logical AND or OR. */ + PARSER_ERR_NEW_TARGET_EXPECTED, /**< expected new.target expression */ + PARSER_ERR_NEW_TARGET_NOT_ALLOWED, /**< new.target is not allowed in the given context */ #endif /* JERRY_ESNEXT */ #if JERRY_MODULE_SYSTEM - PARSER_ERR_FILE_NOT_FOUND, /**< file not found*/ - PARSER_ERR_FROM_EXPECTED, /**< from expected */ - PARSER_ERR_FROM_COMMA_EXPECTED, /**< from or comma expected */ - PARSER_ERR_AS_EXPECTED, /**< as expected */ - PARSER_ERR_STRING_EXPECTED, /**< string literal expected */ - PARSER_ERR_MODULE_UNEXPECTED, /**< unexpected import or export statement */ - PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED, /**< left brace or multiply or literal expected */ - PARSER_ERR_LEFT_BRACE_MULTIPLY_EXPECTED, /**< left brace or multiply expected */ - PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED, /**< right brace or comma expected */ - PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER, /**< duplicated export identifier name */ - PARSER_ERR_DUPLICATED_IMPORT_BINDING, /**< duplicated import binding name */ - PARSER_ERR_EXPORT_NOT_DEFINED, /**< export is not defined in module */ - PARSER_ERR_IMPORT_AFTER_NEW, /**< module import call is not allowed after new */ - PARSER_ERR_META_EXPECTED, /**< meta keyword expected */ - PARSER_ERR_IMPORT_META_REQUIRE_MODULE, /**< cannot use 'import.meta' outside a module */ + PARSER_ERR_FILE_NOT_FOUND, /**< file not found*/ + PARSER_ERR_FROM_EXPECTED, /**< from expected */ + PARSER_ERR_FROM_COMMA_EXPECTED, /**< from or comma expected */ + PARSER_ERR_AS_EXPECTED, /**< as expected */ + PARSER_ERR_STRING_EXPECTED, /**< string literal expected */ + PARSER_ERR_MODULE_UNEXPECTED, /**< unexpected import or export statement */ + PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED, /**< left brace or multiply or literal expected */ + PARSER_ERR_LEFT_BRACE_MULTIPLY_EXPECTED, /**< left brace or multiply expected */ + PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED, /**< right brace or comma expected */ + PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER, /**< duplicated export identifier name */ + PARSER_ERR_DUPLICATED_IMPORT_BINDING, /**< duplicated import binding name */ + PARSER_ERR_EXPORT_NOT_DEFINED, /**< export is not defined in module */ + PARSER_ERR_IMPORT_AFTER_NEW, /**< module import call is not allowed after new */ + PARSER_ERR_META_EXPECTED, /**< meta keyword expected */ + PARSER_ERR_IMPORT_META_REQUIRE_MODULE, /**< cannot use 'import.meta' outside a module */ #endif /* JERRY_MODULE_SYSTEM */ - PARSER_ERR_NON_STRICT_ARG_DEFINITION /**< non-strict argument definition */ + PARSER_ERR_NON_STRICT_ARG_DEFINITION /**< non-strict argument definition */ } parser_error_t; -/** - * Source code line counter type. - */ -typedef uint32_t parser_line_counter_t; - -/** - * Source code as character data. - */ -typedef struct -{ - const uint8_t *source_p; /**< valid UTF-8 source code */ - size_t source_size; /**< size of the source code */ -} parser_source_char_t; - /* Note: source must be a valid UTF-8 string */ -ecma_compiled_code_t * -parser_parse_script (void *source_p, uint32_t parse_opts, const jerry_parse_options_t *options_p); +ecma_compiled_code_t *parser_parse_script (void *source_p, uint32_t parse_opts, const jerry_parse_options_t *options_p); #if JERRY_ERROR_MESSAGES const char *parser_error_to_string (parser_error_t); diff --git a/jerry-core/parser/js/js-scanner-internal.h b/jerry-core/parser/js/js-scanner-internal.h index ba488857..d4117fbe 100644 --- a/jerry-core/parser/js/js-scanner-internal.h +++ b/jerry-core/parser/js/js-scanner-internal.h @@ -31,22 +31,22 @@ */ typedef enum { - SCAN_MODE_PRIMARY_EXPRESSION, /**< scanning primary expression */ - SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW, /**< scanning primary expression after new */ - SCAN_MODE_POST_PRIMARY_EXPRESSION, /**< scanning post primary expression */ - SCAN_MODE_PRIMARY_EXPRESSION_END, /**< scanning primary expression end */ - SCAN_MODE_STATEMENT, /**< scanning statement */ - SCAN_MODE_STATEMENT_OR_TERMINATOR, /**< scanning statement or statement end */ - SCAN_MODE_STATEMENT_END, /**< scanning statement end */ - SCAN_MODE_VAR_STATEMENT, /**< scanning var statement */ - SCAN_MODE_PROPERTY_NAME, /**< scanning property name */ - SCAN_MODE_FUNCTION_ARGUMENTS, /**< scanning function arguments */ + SCAN_MODE_PRIMARY_EXPRESSION, /**< scanning primary expression */ + SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW, /**< scanning primary expression after new */ + SCAN_MODE_POST_PRIMARY_EXPRESSION, /**< scanning post primary expression */ + SCAN_MODE_PRIMARY_EXPRESSION_END, /**< scanning primary expression end */ + SCAN_MODE_STATEMENT, /**< scanning statement */ + SCAN_MODE_STATEMENT_OR_TERMINATOR, /**< scanning statement or statement end */ + SCAN_MODE_STATEMENT_END, /**< scanning statement end */ + SCAN_MODE_VAR_STATEMENT, /**< scanning var statement */ + SCAN_MODE_PROPERTY_NAME, /**< scanning property name */ + SCAN_MODE_FUNCTION_ARGUMENTS, /**< scanning function arguments */ #if JERRY_ESNEXT - SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS, /**< continue scanning function arguments */ - SCAN_MODE_BINDING, /**< array or object binding */ - SCAN_MODE_CLASS_DECLARATION, /**< scanning class declaration */ - SCAN_MODE_CLASS_BODY, /**< scanning class body */ - SCAN_MODE_CLASS_BODY_NO_SCAN, /**< scanning class body without calling lexer_scan_identifier */ + SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS, /**< continue scanning function arguments */ + SCAN_MODE_BINDING, /**< array or object binding */ + SCAN_MODE_CLASS_DECLARATION, /**< scanning class declaration */ + SCAN_MODE_CLASS_BODY, /**< scanning class body */ + SCAN_MODE_CLASS_BODY_NO_SCAN, /**< scanning class body without calling lexer_scan_identifier */ #endif /* JERRY_ESNEXT */ } scan_modes_t; @@ -55,72 +55,72 @@ typedef enum */ typedef enum { - SCAN_STACK_SCRIPT, /**< script */ - SCAN_STACK_SCRIPT_FUNCTION, /**< script is a function body */ - SCAN_STACK_BLOCK_STATEMENT, /**< block statement group */ - SCAN_STACK_FUNCTION_STATEMENT, /**< function statement */ - SCAN_STACK_FUNCTION_EXPRESSION, /**< function expression */ - SCAN_STACK_FUNCTION_PROPERTY, /**< function expression in an object literal */ + SCAN_STACK_SCRIPT, /**< script */ + SCAN_STACK_SCRIPT_FUNCTION, /**< script is a function body */ + SCAN_STACK_BLOCK_STATEMENT, /**< block statement group */ + SCAN_STACK_FUNCTION_STATEMENT, /**< function statement */ + SCAN_STACK_FUNCTION_EXPRESSION, /**< function expression */ + SCAN_STACK_FUNCTION_PROPERTY, /**< function expression in an object literal */ #if JERRY_ESNEXT - SCAN_STACK_FUNCTION_ARROW, /**< arrow function expression */ + SCAN_STACK_FUNCTION_ARROW, /**< arrow function expression */ #endif /* JERRY_ESNEXT */ - SCAN_STACK_SWITCH_BLOCK, /**< block part of "switch" statement */ - SCAN_STACK_IF_STATEMENT, /**< statement part of "if" statements */ - SCAN_STACK_WITH_STATEMENT, /**< statement part of "with" statements */ - SCAN_STACK_WITH_EXPRESSION, /**< expression part of "with" statements */ - SCAN_STACK_DO_STATEMENT, /**< statement part of "do" statements */ - SCAN_STACK_DO_EXPRESSION, /**< expression part of "do" statements */ - SCAN_STACK_WHILE_EXPRESSION, /**< expression part of "while" iterator */ - SCAN_STACK_PAREN_EXPRESSION, /**< expression in brackets */ - SCAN_STACK_STATEMENT_WITH_EXPR, /**< statement which starts with expression enclosed in brackets */ + SCAN_STACK_SWITCH_BLOCK, /**< block part of "switch" statement */ + SCAN_STACK_IF_STATEMENT, /**< statement part of "if" statements */ + SCAN_STACK_WITH_STATEMENT, /**< statement part of "with" statements */ + SCAN_STACK_WITH_EXPRESSION, /**< expression part of "with" statements */ + SCAN_STACK_DO_STATEMENT, /**< statement part of "do" statements */ + SCAN_STACK_DO_EXPRESSION, /**< expression part of "do" statements */ + SCAN_STACK_WHILE_EXPRESSION, /**< expression part of "while" iterator */ + SCAN_STACK_PAREN_EXPRESSION, /**< expression in brackets */ + SCAN_STACK_STATEMENT_WITH_EXPR, /**< statement which starts with expression enclosed in brackets */ #if JERRY_ESNEXT - SCAN_STACK_BINDING_INIT, /**< post processing after a single initializer */ - SCAN_STACK_BINDING_LIST_INIT, /**< post processing after an initializer list */ - SCAN_STACK_LET, /**< let statement */ - SCAN_STACK_CONST, /**< const statement */ + SCAN_STACK_BINDING_INIT, /**< post processing after a single initializer */ + SCAN_STACK_BINDING_LIST_INIT, /**< post processing after an initializer list */ + SCAN_STACK_LET, /**< let statement */ + SCAN_STACK_CONST, /**< const statement */ #endif /* JERRY_ESNEXT */ /* The SCANNER_IS_FOR_START macro needs to be updated when the following constants are reordered. */ - SCAN_STACK_VAR, /**< var statement */ - SCAN_STACK_FOR_VAR_START, /**< start of "for" iterator with var statement */ + SCAN_STACK_VAR, /**< var statement */ + SCAN_STACK_FOR_VAR_START, /**< start of "for" iterator with var statement */ #if JERRY_ESNEXT - SCAN_STACK_FOR_LET_START, /**< start of "for" iterator with let statement */ - SCAN_STACK_FOR_CONST_START, /**< start of "for" iterator with const statement */ + SCAN_STACK_FOR_LET_START, /**< start of "for" iterator with let statement */ + SCAN_STACK_FOR_CONST_START, /**< start of "for" iterator with const statement */ #endif /* JERRY_ESNEXT */ - SCAN_STACK_FOR_START, /**< start of "for" iterator */ - SCAN_STACK_FOR_CONDITION, /**< condition part of "for" iterator */ - SCAN_STACK_FOR_EXPRESSION, /**< expression part of "for" iterator */ - SCAN_STACK_SWITCH_EXPRESSION, /**< expression part of "switch" statement */ - SCAN_STACK_CASE_STATEMENT, /**< case statement inside a switch statement */ - SCAN_STACK_COLON_EXPRESSION, /**< expression between a question mark and colon */ - SCAN_STACK_TRY_STATEMENT, /**< try statement */ - SCAN_STACK_CATCH_STATEMENT, /**< catch statement */ - SCAN_STACK_ARRAY_LITERAL, /**< array literal or destructuring assignment or binding */ - SCAN_STACK_OBJECT_LITERAL, /**< object literal group */ - SCAN_STACK_PROPERTY_ACCESSOR, /**< property accessor in square brackets */ + SCAN_STACK_FOR_START, /**< start of "for" iterator */ + SCAN_STACK_FOR_CONDITION, /**< condition part of "for" iterator */ + SCAN_STACK_FOR_EXPRESSION, /**< expression part of "for" iterator */ + SCAN_STACK_SWITCH_EXPRESSION, /**< expression part of "switch" statement */ + SCAN_STACK_CASE_STATEMENT, /**< case statement inside a switch statement */ + SCAN_STACK_COLON_EXPRESSION, /**< expression between a question mark and colon */ + SCAN_STACK_TRY_STATEMENT, /**< try statement */ + SCAN_STACK_CATCH_STATEMENT, /**< catch statement */ + SCAN_STACK_ARRAY_LITERAL, /**< array literal or destructuring assignment or binding */ + SCAN_STACK_OBJECT_LITERAL, /**< object literal group */ + SCAN_STACK_PROPERTY_ACCESSOR, /**< property accessor in square brackets */ #if JERRY_ESNEXT /* These four must be in this order. */ - SCAN_STACK_COMPUTED_PROPERTY, /**< computed property name */ - SCAN_STACK_COMPUTED_GENERATOR, /**< computed generator function */ - SCAN_STACK_COMPUTED_ASYNC, /**< computed async function */ - SCAN_STACK_COMPUTED_ASYNC_GENERATOR, /**< computed async function */ - SCAN_STACK_TEMPLATE_STRING, /**< template string */ - SCAN_STACK_TAGGED_TEMPLATE_LITERAL, /**< tagged template literal */ - SCAN_STACK_PRIVATE_BLOCK_EARLY, /**< private block for single statements (force early declarations) */ - SCAN_STACK_PRIVATE_BLOCK, /**< private block for single statements */ - SCAN_STACK_ARROW_ARGUMENTS, /**< might be arguments of an arrow function */ - SCAN_STACK_ARROW_EXPRESSION, /**< expression body of an arrow function */ - SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR, /**< explicit class constructor */ - SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR, /**< implicit class constructor */ - SCAN_STACK_CLASS_STATEMENT, /**< class statement */ - SCAN_STACK_CLASS_EXPRESSION, /**< class expression */ - SCAN_STACK_CLASS_EXTENDS, /**< class extends expression */ - SCAN_STACK_CLASS_FIELD_INITIALIZER, /**< class field initializer */ - SCAN_STACK_FUNCTION_PARAMETERS, /**< function parameter initializer */ - SCAN_STACK_FOR_START_PATTERN, /**< possible assignment pattern for "for" iterator */ - SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */ + SCAN_STACK_COMPUTED_PROPERTY, /**< computed property name */ + SCAN_STACK_COMPUTED_GENERATOR, /**< computed generator function */ + SCAN_STACK_COMPUTED_ASYNC, /**< computed async function */ + SCAN_STACK_COMPUTED_ASYNC_GENERATOR, /**< computed async function */ + SCAN_STACK_TEMPLATE_STRING, /**< template string */ + SCAN_STACK_TAGGED_TEMPLATE_LITERAL, /**< tagged template literal */ + SCAN_STACK_PRIVATE_BLOCK_EARLY, /**< private block for single statements (force early declarations) */ + SCAN_STACK_PRIVATE_BLOCK, /**< private block for single statements */ + SCAN_STACK_ARROW_ARGUMENTS, /**< might be arguments of an arrow function */ + SCAN_STACK_ARROW_EXPRESSION, /**< expression body of an arrow function */ + SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR, /**< explicit class constructor */ + SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR, /**< implicit class constructor */ + SCAN_STACK_CLASS_STATEMENT, /**< class statement */ + SCAN_STACK_CLASS_EXPRESSION, /**< class expression */ + SCAN_STACK_CLASS_EXTENDS, /**< class extends expression */ + SCAN_STACK_CLASS_FIELD_INITIALIZER, /**< class field initializer */ + SCAN_STACK_FUNCTION_PARAMETERS, /**< function parameter initializer */ + SCAN_STACK_FOR_START_PATTERN, /**< possible assignment pattern for "for" iterator */ + SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */ #endif /* JERRY_ESNEXT */ #if JERRY_MODULE_SYSTEM - SCAN_STACK_EXPORT_DEFAULT, /**< scan primary expression after export default */ + SCAN_STACK_EXPORT_DEFAULT, /**< scan primary expression after export default */ #endif /* JERRY_MODULE_SYSTEM */ } scan_stack_modes_t; @@ -141,8 +141,7 @@ typedef enum /** * Checks whether the stack top is a for statement start. */ -#define SCANNER_IS_FOR_START(stack_top) \ - ((stack_top) >= SCAN_STACK_FOR_VAR_START && (stack_top) <= SCAN_STACK_FOR_START) +#define SCANNER_IS_FOR_START(stack_top) ((stack_top) >= SCAN_STACK_FOR_VAR_START && (stack_top) <= SCAN_STACK_FOR_START) /** * Generic descriptor which stores only the start position. @@ -329,8 +328,7 @@ typedef enum /** * Setting the generator and async properties of literal pool status flags. */ -#define SCANNER_FROM_COMPUTED_TO_LITERAL_POOL(mode) \ - (((mode) - SCAN_STACK_COMPUTED_PROPERTY) << 10) +#define SCANNER_FROM_COMPUTED_TO_LITERAL_POOL(mode) (((mode) -SCAN_STACK_COMPUTED_PROPERTY) << 10) #if JERRY_ESNEXT @@ -395,33 +393,39 @@ void scanner_free (void *ptr, size_t size); size_t scanner_get_stream_size (scanner_info_t *info_p, size_t size); scanner_info_t *scanner_insert_info (parser_context_t *context_p, const uint8_t *source_p, size_t size); -scanner_info_t *scanner_insert_info_before (parser_context_t *context_p, const uint8_t *source_p, - scanner_info_t *start_info_p, size_t size); -scanner_literal_pool_t *scanner_push_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p, - uint16_t status_flags); +scanner_info_t *scanner_insert_info_before (parser_context_t *context_p, + const uint8_t *source_p, + scanner_info_t *start_info_p, + size_t size); +scanner_literal_pool_t * +scanner_push_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p, uint16_t status_flags); void scanner_pop_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p); #if JERRY_ESNEXT void scanner_filter_arguments (parser_context_t *context_p, scanner_context_t *scanner_context_p); void scanner_construct_global_block (parser_context_t *context_p, scanner_context_t *scanner_context_p); #endif /* JERRY_ESNEXT */ -lexer_lit_location_t *scanner_add_custom_literal (parser_context_t *context_p, scanner_literal_pool_t *literal_pool_p, +lexer_lit_location_t *scanner_add_custom_literal (parser_context_t *context_p, + scanner_literal_pool_t *literal_pool_p, const lexer_lit_location_t *literal_location_p); lexer_lit_location_t *scanner_add_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p); void scanner_add_reference (parser_context_t *context_p, scanner_context_t *scanner_context_p); lexer_lit_location_t *scanner_append_argument (parser_context_t *context_p, scanner_context_t *scanner_context_p); #if JERRY_ESNEXT -void scanner_detect_invalid_var (parser_context_t *context_p, scanner_context_t *scanner_context_p, +void scanner_detect_invalid_var (parser_context_t *context_p, + scanner_context_t *scanner_context_p, lexer_lit_location_t *var_literal_p); void scanner_detect_invalid_let (parser_context_t *context_p, lexer_lit_location_t *let_literal_p); #endif /* JERRY_ESNEXT */ void scanner_detect_eval_call (parser_context_t *context_p, scanner_context_t *scanner_context_p); #if JERRY_ESNEXT -lexer_lit_location_t *scanner_push_class_declaration (parser_context_t *context_p, - scanner_context_t *scanner_context_p, uint8_t stack_mode); +lexer_lit_location_t * +scanner_push_class_declaration (parser_context_t *context_p, scanner_context_t *scanner_context_p, uint8_t stack_mode); void scanner_push_class_field_initializer (parser_context_t *context_p, scanner_context_t *scanner_context_p); -void scanner_push_destructuring_pattern (parser_context_t *context_p, scanner_context_t *scanner_context_p, - uint8_t binding_type, bool is_nested); +void scanner_push_destructuring_pattern (parser_context_t *context_p, + scanner_context_t *scanner_context_p, + uint8_t binding_type, + bool is_nested); void scanner_pop_binding_list (scanner_context_t *scanner_context_p); void scanner_append_hole (parser_context_t *context_p, scanner_context_t *scanner_context_p); #endif /* JERRY_ESNEXT */ @@ -431,8 +435,8 @@ void scanner_append_hole (parser_context_t *context_p, scanner_context_t *scanne #if JERRY_ESNEXT void scanner_add_async_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p); void scanner_check_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p); -void scanner_scan_simple_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p, - const uint8_t *source_p); +void +scanner_scan_simple_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p, const uint8_t *source_p); void scanner_check_arrow_arg (parser_context_t *context_p, scanner_context_t *scanner_context_p); bool scanner_check_async_function (parser_context_t *context_p, scanner_context_t *scanner_context_p); void scanner_check_function_after_if (parser_context_t *context_p, scanner_context_t *scanner_context_p); diff --git a/jerry-core/parser/js/js-scanner-ops.c b/jerry-core/parser/js/js-scanner-ops.c index 2996e5bd..046ef011 100644 --- a/jerry-core/parser/js/js-scanner-ops.c +++ b/jerry-core/parser/js/js-scanner-ops.c @@ -45,9 +45,8 @@ scanner_add_async_literal (parser_context_t *context_p, /**< context */ parser_stack_pop_uint8 (context_p); parser_stack_pop (context_p, &async_literal, sizeof (lexer_lit_location_t)); - lexer_lit_location_t *lit_location_p = scanner_add_custom_literal (context_p, - scanner_context_p->active_literal_pool_p, - &async_literal); + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &async_literal); lit_location_p->type |= SCANNER_LITERAL_IS_USED; @@ -91,8 +90,7 @@ scanner_check_arrow (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_ARROW - || (context_p->token.flags & LEXER_WAS_NEWLINE)) + if (context_p->token.type != LEXER_ARROW || (context_p->token.flags & LEXER_WAS_NEWLINE)) { if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) { @@ -115,9 +113,8 @@ scanner_check_arrow (parser_context_t *context_p, /**< context */ bool is_async_arrow = (status_flags & SCANNER_LITERAL_POOL_MAY_ASYNC_ARROW) != 0; status_flags |= SCANNER_LITERAL_POOL_ARROW_FLAGS; - status_flags &= (uint16_t) ~(SCANNER_LITERAL_POOL_IN_WITH - | SCANNER_LITERAL_POOL_GENERATOR - | SCANNER_LITERAL_POOL_ASYNC); + status_flags &= + (uint16_t) ~(SCANNER_LITERAL_POOL_IN_WITH | SCANNER_LITERAL_POOL_GENERATOR | SCANNER_LITERAL_POOL_ASYNC); context_p->status_flags &= (uint32_t) ~(PARSER_IS_GENERATOR_FUNCTION | PARSER_IS_ASYNC_FUNCTION); @@ -301,8 +298,7 @@ scanner_check_async_function (parser_context_t *context_p, /**< context */ return true; } - if (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { if (!lexer_check_arrow (context_p)) { @@ -322,9 +318,8 @@ scanner_check_async_function (parser_context_t *context_p, /**< context */ } } - lexer_lit_location_t *lit_location_p = scanner_add_custom_literal (context_p, - scanner_context_p->active_literal_pool_p, - &async_literal); + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &async_literal); lit_location_p->type |= SCANNER_LITERAL_IS_USED; if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) @@ -369,8 +364,7 @@ scanner_check_import_meta (parser_context_t *context_p) /**< context */ { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL || context_p->token.keyword_type != LEXER_KEYW_META || (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) { @@ -421,8 +415,7 @@ scanner_scan_bracket (parser_context_t *context_p, /**< context */ #endif /* JERRY_ESNEXT */ depth++; lexer_next_token (context_p); - } - while (context_p->token.type == LEXER_LEFT_PAREN); + } while (context_p->token.type == LEXER_LEFT_PAREN); scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; @@ -526,8 +519,7 @@ scanner_scan_bracket (parser_context_t *context_p, /**< context */ } #if JERRY_ESNEXT - if (JERRY_UNLIKELY (scanner_context_p->async_source_p != NULL) - && (arrow_source_p == NULL || depth > 0)) + if (JERRY_UNLIKELY (scanner_context_p->async_source_p != NULL) && (arrow_source_p == NULL || depth > 0)) { scanner_context_p->async_source_p = NULL; } @@ -599,13 +591,11 @@ scanner_check_directives (parser_context_t *context_p, /**< context */ { scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; - while (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + while (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) { bool is_use_strict = false; - if (lexer_string_is_use_strict (context_p) - && !(context_p->status_flags & PARSER_IS_STRICT)) + if (lexer_string_is_use_strict (context_p) && !(context_p->status_flags & PARSER_IS_STRICT)) { is_use_strict = true; context_p->status_flags |= PARSER_IS_STRICT; diff --git a/jerry-core/parser/js/js-scanner-util.c b/jerry-core/parser/js/js-scanner-util.c index ac2ecce5..bd501dae 100644 --- a/jerry-core/parser/js/js-scanner-util.c +++ b/jerry-core/parser/js/js-scanner-util.c @@ -15,6 +15,7 @@ #include "ecma-helpers.h" #include "ecma-lex-env.h" + #include "jcontext.h" #include "js-parser-internal.h" #include "js-scanner-internal.h" @@ -40,11 +41,9 @@ JERRY_STATIC_ASSERT (PARSER_MAXIMUM_NUMBER_OF_LITERALS + PARSER_MAXIMUM_NUMBER_O JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG & SCANNER_LITERAL_IS_LOCAL) == 0, is_arrow_arg_binding_flag_must_not_use_local_flags); -JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_LET & SCANNER_LITERAL_IS_LOCAL) != 0, - is_let_flag_must_use_local_flags); +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_LET & SCANNER_LITERAL_IS_LOCAL) != 0, is_let_flag_must_use_local_flags); -JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_CONST & SCANNER_LITERAL_IS_LOCAL) != 0, - is_const_flag_must_use_local_flags); +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_CONST & SCANNER_LITERAL_IS_LOCAL) != 0, is_const_flag_must_use_local_flags); JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_FUNC_DECLARATION & SCANNER_LITERAL_IS_LOCAL) != 0, is_func_declaration_flag_must_use_local_flags); @@ -400,8 +399,7 @@ scanner_scope_find_lexical_declaration (parser_context_t *context_p, /**< contex ecma_string_t *name_p; uint32_t flags = context_p->global_status_flags; - if (!(flags & ECMA_PARSE_EVAL) - || (!(flags & ECMA_PARSE_DIRECT_EVAL) && (context_p->status_flags & PARSER_IS_STRICT))) + if (!(flags & ECMA_PARSE_EVAL) || (!(flags & ECMA_PARSE_DIRECT_EVAL) && (context_p->status_flags & PARSER_IS_STRICT))) { return false; } @@ -487,9 +485,8 @@ scanner_push_literal_pool (parser_context_t *context_p, /**< context */ status_flags |= SCANNER_LITERAL_POOL_NO_ARGUMENTS; #if JERRY_ESNEXT - const uint16_t copied_flags = (SCANNER_LITERAL_POOL_IN_WITH - | SCANNER_LITERAL_POOL_GENERATOR - | SCANNER_LITERAL_POOL_ASYNC); + const uint16_t copied_flags = + (SCANNER_LITERAL_POOL_IN_WITH | SCANNER_LITERAL_POOL_GENERATOR | SCANNER_LITERAL_POOL_ASYNC); #else /* !JERRY_ESNEXT */ const uint16_t copied_flags = SCANNER_LITERAL_POOL_IN_WITH; #endif /* JERRY_ESNEXT */ @@ -535,8 +532,7 @@ scanner_push_literal_pool (parser_context_t *context_p, /**< context */ return literal_pool_p; } /* scanner_push_literal_pool */ -JERRY_STATIC_ASSERT (PARSER_MAXIMUM_IDENT_LENGTH <= UINT8_MAX, - maximum_ident_length_must_fit_in_a_byte); +JERRY_STATIC_ASSERT (PARSER_MAXIMUM_IDENT_LENGTH <= UINT8_MAX, maximum_ident_length_must_fit_in_a_byte); /** * Checks whether a literal is equal to "arguments". @@ -782,8 +778,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */ || ((type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_ARG)) && (status_flags & SCANNER_LITERAL_POOL_FUNCTION))) { - JERRY_ASSERT ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) - || !(literal_p->type & SCANNER_LITERAL_IS_ARG)); + JERRY_ASSERT ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) || !(literal_p->type & SCANNER_LITERAL_IS_ARG)); if (literal_p->length == 0) { @@ -852,9 +847,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */ if (prev_literal_pool_p != NULL && literal_p->length > 0) { /* Propagate literal to upper level. */ - lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p, - prev_literal_pool_p, - literal_p); + lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p, prev_literal_pool_p, literal_p); uint8_t extended_type = literal_location_p->type; #if JERRY_ESNEXT @@ -878,8 +871,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */ const uint8_t mask = (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_LOCAL); - if ((type & SCANNER_LITERAL_IS_ARG) - || (literal_location_p->type & mask) == SCANNER_LITERAL_IS_LET + if ((type & SCANNER_LITERAL_IS_ARG) || (literal_location_p->type & mask) == SCANNER_LITERAL_IS_LET || (literal_location_p->type & mask) == SCANNER_LITERAL_IS_CONST) { /* Clears the SCANNER_LITERAL_IS_VAR and SCANNER_LITERAL_IS_FUNC flags @@ -1071,8 +1063,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */ { type = (uint8_t) (type + 1); - JERRY_ASSERT (type == SCANNER_STREAM_TYPE_ARG_VAR - || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR); + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_ARG_VAR || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR); } #endif /* JERRY_ESNEXT */ } @@ -1263,9 +1254,8 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */ } uint8_t type = literal_p->type; - const uint8_t mask = (SCANNER_LITERAL_IS_ARG - | SCANNER_LITERAL_IS_DESTRUCTURED_ARG - | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG); + const uint8_t mask = + (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG); if ((type & mask) != SCANNER_LITERAL_IS_ARG) { @@ -1333,9 +1323,7 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */ else if (prev_literal_pool_p != NULL) { /* Propagate literal to upper level. */ - lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p, - prev_literal_pool_p, - literal_p); + lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p, prev_literal_pool_p, literal_p); type |= SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_IS_USED; literal_location_p->type |= type; } @@ -1441,7 +1429,7 @@ scanner_add_custom_literal (parser_context_t *context_p, /**< context */ * * @return pointer to the literal */ -extern inline lexer_lit_location_t * JERRY_ATTR_ALWAYS_INLINE +extern inline lexer_lit_location_t *JERRY_ATTR_ALWAYS_INLINE scanner_add_literal (parser_context_t *context_p, /**< context */ scanner_context_t *scanner_context_p) /**< scanner context */ { @@ -1460,9 +1448,8 @@ extern inline void JERRY_ATTR_ALWAYS_INLINE scanner_add_reference (parser_context_t *context_p, /**< context */ scanner_context_t *scanner_context_p) /**< scanner context */ { - lexer_lit_location_t *lit_location_p = scanner_add_custom_literal (context_p, - scanner_context_p->active_literal_pool_p, - &context_p->token.lit_location); + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &context_p->token.lit_location); #if JERRY_ESNEXT lit_location_p->type |= SCANNER_LITERAL_IS_USED; #endif /* JERRY_ESNEXT */ @@ -1555,8 +1542,7 @@ void scanner_detect_eval_call (parser_context_t *context_p, /**< context */ scanner_context_t *scanner_context_p) /**< scanner context */ { - if (context_p->token.keyword_type == LEXER_KEYW_EVAL - && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + if (context_p->token.keyword_type == LEXER_KEYW_EVAL && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) { #if JERRY_ESNEXT const uint16_t flags = (uint16_t) (SCANNER_LITERAL_POOL_CAN_EVAL | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE); @@ -1608,12 +1594,10 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */ { while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) { - if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) - && !(literal_p->type & SCANNER_LITERAL_IS_ARG) + if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) && !(literal_p->type & SCANNER_LITERAL_IS_ARG) && !((literal_p->type & SCANNER_LITERAL_IS_FUNC) && (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)) - && (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL - && literal_p->length == length) + && (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL && literal_p->length == length) { if (JERRY_LIKELY (!(literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) { @@ -1635,8 +1619,7 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */ { while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) { - if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) - && !(literal_p->type & SCANNER_LITERAL_IS_ARG) + if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) && !(literal_p->type & SCANNER_LITERAL_IS_ARG) && !((literal_p->type & SCANNER_LITERAL_IS_FUNC) && (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)) && (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL @@ -1662,9 +1645,7 @@ void scanner_detect_invalid_let (parser_context_t *context_p, /**< context */ lexer_lit_location_t *let_literal_p) /**< let literal */ { - if (let_literal_p->type & (SCANNER_LITERAL_IS_ARG - | SCANNER_LITERAL_IS_VAR - | SCANNER_LITERAL_IS_LOCAL)) + if (let_literal_p->type & (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_LOCAL)) { scanner_raise_redeclaration_error (context_p); } @@ -1698,8 +1679,8 @@ scanner_push_class_declaration (parser_context_t *context_p, /**< context */ parser_stack_push_uint8 (context_p, stack_mode); lexer_next_token (context_p); - bool class_has_name = (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + bool class_has_name = + (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); if (class_has_name) { @@ -1737,9 +1718,8 @@ scanner_push_class_declaration (parser_context_t *context_p, /**< context */ else if (is_export_default) { lexer_lit_location_t *name_literal_p; - name_literal_p = scanner_add_custom_literal (context_p, - scanner_context_p->active_literal_pool_p->prev_p, - &lexer_default_literal); + name_literal_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p->prev_p, &lexer_default_literal); name_literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG; scanner_context_p->active_literal_pool_p->no_declarations++; @@ -1889,8 +1869,7 @@ scanner_reverse_info_list (parser_context_t *context_p) /**< context */ last_scanner_info_p = scanner_info_p; scanner_info_p = next_scanner_info_p; - } - while (scanner_info_p->type != SCANNER_TYPE_END); + } while (scanner_info_p->type != SCANNER_TYPE_END); context_p->next_scanner_info_p->next_p = scanner_info_p; context_p->next_scanner_info_p = last_scanner_info_p; @@ -1959,13 +1938,12 @@ scanner_cleanup (parser_context_t *context_p) /**< context */ default: { #if JERRY_ESNEXT - JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS - || scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS - || scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR - || scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION - || scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED - || scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION - || scanner_info_p->type == SCANNER_TYPE_EXPORT_MODULE_SPECIFIER); + JERRY_ASSERT ( + scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS || scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS + || scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR + || scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION || scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED + || scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION + || scanner_info_p->type == SCANNER_TYPE_EXPORT_MODULE_SPECIFIER); #else /* !JERRY_ESNEXT */ JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS); #endif /* JERRY_ESNEXT */ @@ -2000,8 +1978,8 @@ scanner_is_context_needed (parser_context_t *context_p, /**< context */ JERRY_ASSERT ((check_type == PARSER_CHECK_BLOCK_CONTEXT ? info_p->type == SCANNER_TYPE_BLOCK : info_p->type == SCANNER_TYPE_FUNCTION)); - uint32_t scope_stack_reg_top = (check_type != PARSER_CHECK_GLOBAL_CONTEXT ? context_p->scope_stack_reg_top - : 1); /* block result */ + uint32_t scope_stack_reg_top = + (check_type != PARSER_CHECK_GLOBAL_CONTEXT ? context_p->scope_stack_reg_top : 1); /* block result */ #else /* !JERRY_ESNEXT */ JERRY_ASSERT (check_type == PARSER_CHECK_BLOCK_CONTEXT); JERRY_ASSERT (info_p->type == SCANNER_TYPE_BLOCK); @@ -2026,8 +2004,7 @@ scanner_is_context_needed (parser_context_t *context_p, /**< context */ if (JERRY_UNLIKELY (SCANNER_STREAM_TYPE_IS_ARGUMENTS (type))) { - if ((data & SCANNER_STREAM_NO_REG) - || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + if ((data & SCANNER_STREAM_NO_REG) || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) { return true; } @@ -2041,48 +2018,37 @@ scanner_is_context_needed (parser_context_t *context_p, /**< context */ #ifndef JERRY_NDEBUG if (check_type == PARSER_CHECK_BLOCK_CONTEXT) { - JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR - || type == SCANNER_STREAM_TYPE_LET - || type == SCANNER_STREAM_TYPE_CONST - || type == SCANNER_STREAM_TYPE_LOCAL + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_LET + || type == SCANNER_STREAM_TYPE_CONST || type == SCANNER_STREAM_TYPE_LOCAL || type == SCANNER_STREAM_TYPE_FUNC); } else if (check_type == PARSER_CHECK_GLOBAL_CONTEXT) { #if JERRY_MODULE_SYSTEM const bool is_import = (type == SCANNER_STREAM_TYPE_IMPORT); -#else +#else /* !JERRY_MODULE_SYSTEM */ const bool is_import = true; #endif /* JERRY_MODULE_SYSTEM */ /* FIXME: a private declarative lexical environment should always be present * for modules. Remove SCANNER_STREAM_TYPE_IMPORT after it is implemented. */ - JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR - || type == SCANNER_STREAM_TYPE_LET - || type == SCANNER_STREAM_TYPE_CONST - || type == SCANNER_STREAM_TYPE_FUNC - || is_import); + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_LET + || type == SCANNER_STREAM_TYPE_CONST || type == SCANNER_STREAM_TYPE_FUNC || is_import); /* Only let/const can be stored in registers */ JERRY_ASSERT ((data & SCANNER_STREAM_NO_REG) || (type == SCANNER_STREAM_TYPE_FUNC && (context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL)) - || type == SCANNER_STREAM_TYPE_LET - || type == SCANNER_STREAM_TYPE_CONST); + || type == SCANNER_STREAM_TYPE_LET || type == SCANNER_STREAM_TYPE_CONST); } else { JERRY_ASSERT (check_type == PARSER_CHECK_FUNCTION_CONTEXT); - JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR - || type == SCANNER_STREAM_TYPE_LET - || type == SCANNER_STREAM_TYPE_CONST - || type == SCANNER_STREAM_TYPE_LOCAL - || type == SCANNER_STREAM_TYPE_ARG - || type == SCANNER_STREAM_TYPE_ARG_VAR - || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG - || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR - || type == SCANNER_STREAM_TYPE_ARG_FUNC - || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_LET + || type == SCANNER_STREAM_TYPE_CONST || type == SCANNER_STREAM_TYPE_LOCAL + || type == SCANNER_STREAM_TYPE_ARG || type == SCANNER_STREAM_TYPE_ARG_VAR + || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR + || type == SCANNER_STREAM_TYPE_ARG_FUNC || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC || type == SCANNER_STREAM_TYPE_FUNC); } #endif /* !JERRY_NDEBUG */ @@ -2116,24 +2082,21 @@ scanner_is_context_needed (parser_context_t *context_p, /**< context */ if (JERRY_UNLIKELY (check_type == PARSER_CHECK_GLOBAL_CONTEXT) && (type == SCANNER_STREAM_TYPE_VAR - || (type == SCANNER_STREAM_TYPE_FUNC && !(context_p->global_status_flags & ECMA_PARSE_EVAL)) - || is_import)) + || (type == SCANNER_STREAM_TYPE_FUNC && !(context_p->global_status_flags & ECMA_PARSE_EVAL)) || is_import)) { continue; } if (JERRY_UNLIKELY (check_type == PARSER_CHECK_FUNCTION_CONTEXT)) { - if (SCANNER_STREAM_TYPE_IS_ARG_FUNC (type) - || type == SCANNER_STREAM_TYPE_ARG_VAR + if (SCANNER_STREAM_TYPE_IS_ARG_FUNC (type) || type == SCANNER_STREAM_TYPE_ARG_VAR || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR) { /* The return value is true, if the variable is stored in the lexical environment * or all registers have already been used for function arguments. This can be * inprecise in the latter case, but this is a very rare corner case. A more * sophisticated check would require to decode the literal. */ - if ((data & SCANNER_STREAM_NO_REG) - || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + if ((data & SCANNER_STREAM_NO_REG) || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) { return true; } @@ -2147,8 +2110,7 @@ scanner_is_context_needed (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - if ((data & SCANNER_STREAM_NO_REG) - || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + if ((data & SCANNER_STREAM_NO_REG) || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) { return true; } @@ -2202,10 +2164,10 @@ scanner_try_scan_new_target (parser_context_t *context_p) /**< parser/scanner co /** * Description of "arguments" literal string. */ -const lexer_lit_location_t lexer_arguments_literal = -{ - (const uint8_t *) "arguments", 9, LEXER_IDENT_LITERAL, LEXER_LIT_LOCATION_IS_ASCII -}; +const lexer_lit_location_t lexer_arguments_literal = { (const uint8_t *) "arguments", + 9, + LEXER_IDENT_LITERAL, + LEXER_LIT_LOCATION_IS_ASCII }; /** * Create an unused literal. @@ -2247,8 +2209,7 @@ scanner_check_variables (parser_context_t *context_p) /**< context */ uint32_t type = next_data_p[0] & SCANNER_STREAM_TYPE_MASK; const uint8_t *data_p = next_data_p; - JERRY_ASSERT (type != SCANNER_STREAM_TYPE_HOLE - && !SCANNER_STREAM_TYPE_IS_ARG (type) + JERRY_ASSERT (type != SCANNER_STREAM_TYPE_HOLE && !SCANNER_STREAM_TYPE_IS_ARG (type) && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type)); JERRY_ASSERT (data_p[0] & SCANNER_STREAM_NO_REG); @@ -2280,8 +2241,8 @@ scanner_check_variables (parser_context_t *context_p) /**< context */ literal.length = data_p[1]; literal.type = LEXER_IDENT_LITERAL; - literal.status_flags = ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE - : LEXER_LIT_LOCATION_NO_OPTS); + literal.status_flags = + ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE : LEXER_LIT_LOCATION_NO_OPTS); lexer_construct_literal_object (context_p, &literal, LEXER_NEW_IDENT_LITERAL); literal.char_p += data_p[1]; @@ -2374,8 +2335,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ const uint8_t *data_p = next_data_p; JERRY_ASSERT ((option_flags & (SCANNER_CREATE_VARS_IS_FUNCTION_BODY | SCANNER_CREATE_VARS_IS_FUNCTION_ARGS)) - || (type != SCANNER_STREAM_TYPE_HOLE - && !SCANNER_STREAM_TYPE_IS_ARG (type) + || (type != SCANNER_STREAM_TYPE_HOLE && !SCANNER_STREAM_TYPE_IS_ARG (type) && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type))); #if JERRY_MODULE_SYSTEM @@ -2394,8 +2354,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ uint8_t mask = SCANNER_FUNCTION_ARGUMENTS_NEEDED | SCANNER_FUNCTION_HAS_COMPLEX_ARGUMENT; - if (!(context_p->status_flags & PARSER_IS_STRICT) - && (info_u8_arg & mask) == SCANNER_FUNCTION_ARGUMENTS_NEEDED) + if (!(context_p->status_flags & PARSER_IS_STRICT) && (info_u8_arg & mask) == SCANNER_FUNCTION_ARGUMENTS_NEEDED) { scanner_create_unused_literal (context_p, LEXER_FLAG_FUNCTION_ARGUMENT); } @@ -2430,8 +2389,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ uint16_t map_to; - if (!(data_p[0] & SCANNER_STREAM_NO_REG) - && scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + if (!(data_p[0] & SCANNER_STREAM_NO_REG) && scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) { map_to = (uint16_t) (PARSER_REGISTER_START + scope_stack_reg_top); @@ -2531,8 +2489,8 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ { literal.length = data_p[1]; literal.type = LEXER_IDENT_LITERAL; - literal.status_flags = ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE - : LEXER_LIT_LOCATION_NO_OPTS); + literal.status_flags = + ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE : LEXER_LIT_LOCATION_NO_OPTS); /* Literal must be exists. */ lexer_construct_literal_object (context_p, &literal, LEXER_IDENT_LITERAL); @@ -2548,8 +2506,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ continue; } } - else if ((option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_ARGS) - && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type)) + else if ((option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_ARGS) && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type)) { /* Function arguments must come first. */ break; @@ -2557,8 +2514,8 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ literal.length = data_p[1]; literal.type = LEXER_IDENT_LITERAL; - literal.status_flags = ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE - : LEXER_LIT_LOCATION_NO_OPTS); + literal.status_flags = + ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE : LEXER_LIT_LOCATION_NO_OPTS); lexer_construct_literal_object (context_p, &literal, LEXER_NEW_IDENT_LITERAL); literal.char_p += data_p[1]; @@ -2625,8 +2582,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ uint16_t map_to; uint16_t func_init_opcode = CBC_INIT_ARG_OR_FUNC; - if (!(data_p[0] & SCANNER_STREAM_NO_REG) - && scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + if (!(data_p[0] & SCANNER_STREAM_NO_REG) && scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) { map_to = (uint16_t) (PARSER_REGISTER_START + scope_stack_reg_top); @@ -2736,8 +2692,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ } default: { - JERRY_ASSERT (type == SCANNER_STREAM_TYPE_LOCAL - || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_LOCAL || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC); @@ -2746,8 +2701,7 @@ scanner_create_variables (parser_context_t *context_p, /**< context */ } } #else /* !JERRY_ESNEXT */ - uint16_t opcode = ((option_flags & SCANNER_CREATE_VARS_IS_SCRIPT) ? CBC_CREATE_VAR_EVAL - : CBC_CREATE_VAR); + uint16_t opcode = ((option_flags & SCANNER_CREATE_VARS_IS_SCRIPT) ? CBC_CREATE_VAR_EVAL : CBC_CREATE_VAR); #endif /* JERRY_ESNEXT */ parser_emit_cbc_literal (context_p, opcode, map_to); @@ -2932,9 +2886,8 @@ scanner_save_literal (parser_context_t *context_p, /**< context */ /* Registers must be found in the scope stack. */ JERRY_ASSERT (scope_stack_p > context_p->scope_stack_p); scope_stack_p--; - } - while (scope_stack_p->map_from == PARSER_SCOPE_STACK_FUNC - || literal_index != (scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK)); + } while (scope_stack_p->map_from == PARSER_SCOPE_STACK_FUNC + || literal_index != (scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK)); literal_index = scope_stack_p->map_from; PARSER_GET_LITERAL (literal_index)->status_flags |= LEXER_FLAG_USED; @@ -2967,9 +2920,8 @@ scanner_literal_is_const_reg (parser_context_t *context_p, /**< context */ /* Registers must be found in the scope stack. */ JERRY_ASSERT (scope_stack_p > context_p->scope_stack_p); scope_stack_p--; - } - while (scope_stack_p->map_from == PARSER_SCOPE_STACK_FUNC - || literal_index != (scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK)); + } while (scope_stack_p->map_from == PARSER_SCOPE_STACK_FUNC + || literal_index != (scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK)); return (scope_stack_p->map_to & PARSER_SCOPE_STACK_IS_CONST_REG) != 0; } /* scanner_literal_is_const_reg */ @@ -2992,8 +2944,7 @@ scanner_literal_is_created (parser_context_t *context_p, /**< context */ /* These literals must be found in the scope stack. */ JERRY_ASSERT (scope_stack_p > context_p->scope_stack_p); scope_stack_p--; - } - while (literal_index != scope_stack_p->map_from); + } while (literal_index != scope_stack_p->map_from); JERRY_ASSERT ((scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK) == 0); @@ -3015,8 +2966,7 @@ scanner_literal_exists (parser_context_t *context_p, /**< context */ while (scope_stack_p-- > context_p->scope_stack_p) { - if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC - && scanner_decode_map_to (scope_stack_p) == literal_index) + if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC && scanner_decode_map_to (scope_stack_p) == literal_index) { return true; } diff --git a/jerry-core/parser/js/js-scanner.c b/jerry-core/parser/js/js-scanner.c index 0a552432..e1f14021 100644 --- a/jerry-core/parser/js/js-scanner.c +++ b/jerry-core/parser/js/js-scanner.c @@ -44,24 +44,22 @@ typedef enum */ #if JERRY_ESNEXT #define SCANNER_IDENTIFIER_IS_OF() (lexer_token_is_identifier (context_p, "of", 2)) -#else +#else /* !JERRY_ESNEXT */ #define SCANNER_IDENTIFIER_IS_OF() (false) #endif /* JERRY_ESNEXT */ #if JERRY_ESNEXT JERRY_STATIC_ASSERT (SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_GENERATOR) - == SCAN_STACK_COMPUTED_GENERATOR, + == SCAN_STACK_COMPUTED_GENERATOR, scanner_invalid_conversion_from_literal_pool_generator_to_computed_generator); -JERRY_STATIC_ASSERT (SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_ASYNC) - == SCAN_STACK_COMPUTED_ASYNC, +JERRY_STATIC_ASSERT (SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_ASYNC) == SCAN_STACK_COMPUTED_ASYNC, scanner_invalid_conversion_from_literal_pool_async_to_computed_async); JERRY_STATIC_ASSERT (SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_GENERATOR) - == SCANNER_LITERAL_POOL_GENERATOR, + == SCANNER_LITERAL_POOL_GENERATOR, scanner_invalid_conversion_from_computed_generator_to_literal_pool_generator); -JERRY_STATIC_ASSERT (SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_ASYNC) - == SCANNER_LITERAL_POOL_ASYNC, +JERRY_STATIC_ASSERT (SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_ASYNC) == SCANNER_LITERAL_POOL_ASYNC, scanner_invalid_conversion_from_computed_async_to_literal_pool_async); #endif /* JERRY_ESNEXT */ @@ -121,8 +119,7 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { #if JERRY_MODULE_SYSTEM if (is_export_default) @@ -198,8 +195,7 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */ #if JERRY_ESNEXT const uint8_t *source_p = context_p->source_p; - if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL - && lexer_check_arrow (context_p)) + if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL && lexer_check_arrow (context_p)) { scanner_scan_simple_arrow (context_p, scanner_context_p, source_p); return SCAN_KEEP_TOKEN; @@ -372,8 +368,7 @@ scanner_scan_post_primary_expression (parser_context_t *context_p, /**< context { lexer_scan_identifier (context_p); - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -434,8 +429,7 @@ scanner_scan_post_primary_expression (parser_context_t *context_p, /**< context } } - if (LEXER_IS_BINARY_OP_TOKEN (type) - && (type != LEXER_KEYW_IN || !SCANNER_IS_FOR_START (stack_top))) + if (LEXER_IS_BINARY_OP_TOKEN (type) && (type != LEXER_KEYW_IN || !SCANNER_IS_FOR_START (stack_top))) { scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; return true; @@ -629,8 +623,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL || context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL - || context_p->stack_top_uint8 == SCAN_STACK_LET - || context_p->stack_top_uint8 == SCAN_STACK_CONST + || context_p->stack_top_uint8 == SCAN_STACK_LET || context_p->stack_top_uint8 == SCAN_STACK_CONST || context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START || context_p->stack_top_uint8 == SCAN_STACK_FOR_CONST_START || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS @@ -660,8 +653,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL || context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL - || context_p->stack_top_uint8 == SCAN_STACK_LET - || context_p->stack_top_uint8 == SCAN_STACK_CONST + || context_p->stack_top_uint8 == SCAN_STACK_LET || context_p->stack_top_uint8 == SCAN_STACK_CONST || context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START || context_p->stack_top_uint8 == SCAN_STACK_FOR_CONST_START || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS @@ -773,9 +765,8 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); scanner_for_info_t *for_info_p; - for_info_p = (scanner_for_info_t *) scanner_insert_info (context_p, - for_statement.u.source_p, - sizeof (scanner_for_info_t)); + for_info_p = + (scanner_for_info_t *) scanner_insert_info (context_p, for_statement.u.source_p, sizeof (scanner_for_info_t)); for_info_p->info.type = SCANNER_TYPE_FOR; scanner_get_location (&for_info_p->expression_location, context_p); @@ -841,17 +832,15 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * parser_stack_push_uint8 (context_p, SCAN_STACK_SWITCH_BLOCK); scanner_switch_info_t *switch_info_p; - switch_info_p = (scanner_switch_info_t *) scanner_insert_info (context_p, - context_p->source_p, - sizeof (scanner_switch_info_t)); + switch_info_p = + (scanner_switch_info_t *) scanner_insert_info (context_p, context_p->source_p, sizeof (scanner_switch_info_t)); switch_info_p->info.type = SCANNER_TYPE_SWITCH; switch_info_p->case_p = NULL; scanner_context_p->active_switch_statement.last_case_p = &switch_info_p->case_p; lexer_next_token (context_p); - if (context_p->token.type != LEXER_RIGHT_BRACE - && context_p->token.type != LEXER_KEYW_CASE + if (context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_KEYW_CASE && context_p->token.type != LEXER_KEYW_DEFAULT) { break; @@ -978,10 +967,8 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * #if JERRY_ESNEXT if ((stack_top == SCAN_STACK_ARRAY_LITERAL || stack_top == SCAN_STACK_OBJECT_LITERAL) && (binding_type == SCANNER_BINDING_NONE || binding_type == SCANNER_BINDING_ARROW_ARG) - && context_p->token.type != LEXER_EOS - && context_p->token.type != LEXER_COMMA - && context_p->token.type != LEXER_RIGHT_BRACE - && context_p->token.type != LEXER_RIGHT_SQUARE) + && context_p->token.type != LEXER_EOS && context_p->token.type != LEXER_COMMA + && context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_RIGHT_SQUARE) { object_literal_flags |= SCANNER_LITERAL_NO_DESTRUCTURING; } @@ -1066,8 +1053,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * return SCAN_KEEP_TOKEN; } - if (stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR - || stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) + if (stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR || stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) { JERRY_ASSERT (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME); @@ -1086,8 +1072,8 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * return SCAN_NEXT_TOKEN; } - scanner_context_p->mode = (context_p->token.type != LEXER_SEMICOLON ? SCAN_MODE_CLASS_BODY_NO_SCAN - : SCAN_MODE_CLASS_BODY); + scanner_context_p->mode = + (context_p->token.type != LEXER_SEMICOLON ? SCAN_MODE_CLASS_BODY_NO_SCAN : SCAN_MODE_CLASS_BODY); return SCAN_KEEP_TOKEN; } @@ -1130,8 +1116,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PROPERTY); - uint16_t status_flags = (uint16_t) (SCANNER_LITERAL_POOL_FUNCTION - | SCANNER_LITERAL_POOL_GENERATOR + uint16_t status_flags = (uint16_t) (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_GENERATOR | SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (stack_top)); scanner_push_literal_pool (context_p, scanner_context_p, status_flags); @@ -1271,8 +1256,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * { parser_stack_pop_uint8 (context_p); - if (type != LEXER_RIGHT_PAREN - && (type != LEXER_EOS || context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION)) + if (type != LEXER_RIGHT_PAREN && (type != LEXER_EOS || context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION)) { break; } @@ -1471,8 +1455,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ type = (lexer_token_type_t) context_p->token.type; - if (type != LEXER_LEFT_SQUARE - && type != LEXER_LEFT_BRACE + if (type != LEXER_LEFT_SQUARE && type != LEXER_LEFT_BRACE && (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)) { scanner_info_t *info_p = scanner_insert_info (context_p, source_p, sizeof (scanner_info_t)); @@ -1498,8 +1481,8 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ return_type = SCAN_NEXT_TOKEN; } - stack_mode = ((context_p->token.type == LEXER_KEYW_CONST) ? SCAN_STACK_FOR_CONST_START - : SCAN_STACK_FOR_LET_START); + stack_mode = + ((context_p->token.type == LEXER_KEYW_CONST) ? SCAN_STACK_FOR_CONST_START : SCAN_STACK_FOR_LET_START); break; } #endif /* JERRY_ESNEXT */ @@ -1538,10 +1521,8 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ { lexer_next_token (context_p); - if (!(context_p->token.flags & LEXER_WAS_NEWLINE) - && context_p->token.type != LEXER_SEMICOLON - && context_p->token.type != LEXER_EOS - && context_p->token.type != LEXER_RIGHT_BRACE) + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type != LEXER_SEMICOLON + && context_p->token.type != LEXER_EOS && context_p->token.type != LEXER_RIGHT_BRACE) { scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; return SCAN_KEEP_TOKEN; @@ -1556,8 +1537,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); scanner_context_p->mode = SCAN_MODE_STATEMENT_END; - if (!(context_p->token.flags & LEXER_WAS_NEWLINE) - && context_p->token.type == LEXER_LITERAL + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { return SCAN_NEXT_TOKEN; @@ -1625,8 +1605,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1654,7 +1633,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ literal_p->type |= SCANNER_LITERAL_IS_LOCAL_FUNC; scanner_context_p->status_flags &= (uint16_t) ~SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION; -#else +#else /* !JERRY_ESNEXT */ literal_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC; uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; @@ -1721,16 +1700,14 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ scanner_context_p->mode = SCAN_MODE_STATEMENT_END; - if (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) { return SCAN_NEXT_TOKEN; } bool parse_imports = true; - if (context_p->token.type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); @@ -1761,8 +1738,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1780,8 +1756,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ while (context_p->token.type != LEXER_RIGHT_BRACE) { - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1799,8 +1774,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1810,9 +1784,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); - if (literal_p->type & (SCANNER_LITERAL_IS_ARG - | SCANNER_LITERAL_IS_VAR - | SCANNER_LITERAL_IS_LOCAL)) + if (literal_p->type & (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_LOCAL)) { context_p->source_p = source_p; scanner_raise_redeclaration_error (context_p); @@ -1853,8 +1825,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type != LEXER_STRING_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type != LEXER_STRING_LITERAL) { scanner_raise_error (context_p); } @@ -1888,8 +1859,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1904,8 +1874,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) { scanner_raise_error (context_p); } @@ -1922,8 +1891,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ while (context_p->token.type != LEXER_RIGHT_BRACE) { - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1934,8 +1902,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ { lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -1966,8 +1933,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ lexer_next_token (context_p); - if (context_p->token.type != LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) { scanner_raise_error (context_p); } @@ -1999,8 +1965,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; - if (type == LEXER_LITERAL - && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + if (type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { if (JERRY_UNLIKELY (lexer_check_next_character (context_p, LIT_CHAR_COLON))) { @@ -2029,8 +1994,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ type = (lexer_token_type_t) context_p->token.type; - if (type == LEXER_LEFT_SQUARE - || type == LEXER_LEFT_BRACE + if (type == LEXER_LEFT_SQUARE || type == LEXER_LEFT_BRACE || (type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)) { scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; @@ -2041,9 +2005,8 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */ scanner_info_t *info_p = scanner_insert_info (context_p, source_p, sizeof (scanner_info_t)); info_p->type = SCANNER_TYPE_LET_EXPRESSION; - lexer_lit_location_t *lit_location_p = scanner_add_custom_literal (context_p, - scanner_context_p->active_literal_pool_p, - &let_literal); + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &let_literal); lit_location_p->type |= SCANNER_LITERAL_IS_USED; if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) @@ -2180,8 +2143,8 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */ } #if JERRY_ESNEXT - bool has_super_reference = (scanner_context_p->active_literal_pool_p->status_flags - & SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE) != 0; + bool has_super_reference = + (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE) != 0; #endif /* JERRY_ESNEXT */ scanner_pop_literal_pool (context_p, scanner_context_p); parser_stack_pop_uint8 (context_p); @@ -2244,8 +2207,7 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */ { parser_stack_pop_uint8 (context_p); - if (type == LEXER_KEYW_ELSE - && (terminator_found || (context_p->token.flags & LEXER_WAS_NEWLINE))) + if (type == LEXER_KEYW_ELSE && (terminator_found || (context_p->token.flags & LEXER_WAS_NEWLINE))) { #if JERRY_ESNEXT scanner_check_function_after_if (context_p, scanner_context_p); @@ -2277,8 +2239,7 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */ { parser_stack_pop_uint8 (context_p); - if (type != LEXER_KEYW_WHILE - || (!terminator_found && !(context_p->token.flags & LEXER_WAS_NEWLINE))) + if (type != LEXER_KEYW_WHILE || (!terminator_found && !(context_p->token.flags & LEXER_WAS_NEWLINE))) { scanner_raise_error (context_p); } @@ -2328,9 +2289,8 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */ case SCAN_STACK_EXPORT_DEFAULT: { parser_stack_pop_uint8 (context_p); - lexer_lit_location_t *location_p = scanner_add_custom_literal (context_p, - scanner_context_p->active_literal_pool_p, - &lexer_default_literal); + lexer_lit_location_t *location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &lexer_default_literal); location_p->type |= SCANNER_LITERAL_IS_VAR; continue; } @@ -2432,8 +2392,7 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */ } #endif /* JERRY_ESNEXT */ - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -2519,9 +2478,8 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ context_p->source_p = context_p->source_start_p; context_p->source_end_p = context_p->source_start_p + context_p->source_size; - uint16_t status_flags = (SCANNER_LITERAL_POOL_FUNCTION - | SCANNER_LITERAL_POOL_NO_ARGUMENTS - | SCANNER_LITERAL_POOL_CAN_EVAL); + uint16_t status_flags = + (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_NO_ARGUMENTS | SCANNER_LITERAL_POOL_CAN_EVAL); if (context_p->status_flags & PARSER_IS_STRICT) { @@ -2576,9 +2534,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ { case SCAN_MODE_PRIMARY_EXPRESSION: { - if (type == LEXER_ADD - || type == LEXER_SUBTRACT - || LEXER_IS_UNARY_OP_TOKEN (type)) + if (type == LEXER_ADD || type == LEXER_SUBTRACT || LEXER_IS_UNARY_OP_TOKEN (type)) { break; } @@ -2654,8 +2610,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ bool identifier_found = false; - if (context_p->token.type == LEXER_LITERAL - && LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type) + if (context_p->token.type == LEXER_LITERAL && LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type) && lexer_compare_literal_to_string (context_p, "constructor", 11)) { if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) @@ -2677,8 +2632,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ uint16_t literal_pool_flags = SCANNER_LITERAL_POOL_FUNCTION; - if (lexer_token_is_identifier (context_p, "get", 3) - || lexer_token_is_identifier (context_p, "set", 3)) + if (lexer_token_is_identifier (context_p, "get", 3) || lexer_token_is_identifier (context_p, "set", 3)) { lexer_scan_identifier (context_p); identifier_found = true; @@ -2771,8 +2725,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ continue; } - if (context_p->token.type != LEXER_RIGHT_BRACE - && !(context_p->token.flags & LEXER_WAS_NEWLINE)) + if (context_p->token.type != LEXER_RIGHT_BRACE && !(context_p->token.flags & LEXER_WAS_NEWLINE)) { scanner_raise_error (context_p); } @@ -2861,8 +2814,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ } #endif /* JERRY_ESNEXT */ - if (type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -2952,8 +2904,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ JERRY_ASSERT (!(scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT)); #endif /* JERRY_MODULE_SYSTEM */ - if (context_p->token.type != LEXER_SEMICOLON - && context_p->token.type != LEXER_KEYW_IN + if (context_p->token.type != LEXER_SEMICOLON && context_p->token.type != LEXER_KEYW_IN && !SCANNER_IDENTIFIER_IS_OF ()) { scanner_raise_error (context_p); @@ -2979,10 +2930,8 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ } case SCAN_MODE_FUNCTION_ARGUMENTS: { - JERRY_ASSERT (stack_top == SCAN_STACK_SCRIPT_FUNCTION - || stack_top == SCAN_STACK_FUNCTION_STATEMENT - || stack_top == SCAN_STACK_FUNCTION_EXPRESSION - || stack_top == SCAN_STACK_FUNCTION_PROPERTY); + JERRY_ASSERT (stack_top == SCAN_STACK_SCRIPT_FUNCTION || stack_top == SCAN_STACK_FUNCTION_STATEMENT + || stack_top == SCAN_STACK_FUNCTION_EXPRESSION || stack_top == SCAN_STACK_FUNCTION_PROPERTY); scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p; @@ -3028,8 +2977,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ break; } - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -3043,8 +2991,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ } lexer_next_token (context_p); - } - while (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS); + } while (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS); if (argument_literal_p == NULL) { @@ -3093,8 +3040,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ { while (true) { - if (context_p->token.type != LEXER_LITERAL - || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) { scanner_raise_error (context_p); } @@ -3191,8 +3137,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ if (context_p->token.type == LEXER_PROPERTY_GETTER #if JERRY_ESNEXT - || context_p->token.type == LEXER_KEYW_ASYNC - || context_p->token.type == LEXER_MULTIPLY + || context_p->token.type == LEXER_KEYW_ASYNC || context_p->token.type == LEXER_MULTIPLY #endif /* JERRY_ESNEXT */ || context_p->token.type == LEXER_PROPERTY_SETTER) { @@ -3260,8 +3205,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ } if (is_ident - && (context_p->token.type == LEXER_COMMA - || context_p->token.type == LEXER_RIGHT_BRACE + && (context_p->token.type == LEXER_COMMA || context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_ASSIGN)) { context_p->source_p = context_p->token.lit_location.char_p; @@ -3444,9 +3388,8 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ lexer_next_token (context_p); } -scan_completed: - if (context_p->stack_top_uint8 != SCAN_STACK_SCRIPT - && context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION) + scan_completed: + if (context_p->stack_top_uint8 != SCAN_STACK_SCRIPT && context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION) { scanner_raise_error (context_p); } @@ -3532,8 +3475,8 @@ scan_completed: if (context_p->is_show_opcodes) { scanner_info_t *info_p = context_p->next_scanner_info_p; - const uint8_t *source_start_p = (context_p->arguments_start_p == NULL ? context_p->source_start_p - : context_p->arguments_start_p); + const uint8_t *source_start_p = + (context_p->arguments_start_p == NULL ? context_p->source_start_p : context_p->arguments_start_p); while (info_p->type != SCANNER_TYPE_END) { @@ -3558,9 +3501,7 @@ scan_completed: { data_p = (const uint8_t *) (info_p + 1); - JERRY_DEBUG_MSG (" FUNCTION: flags: 0x%x declarations: %d", - (int) info_p->u8_arg, - (int) info_p->u16_arg); + JERRY_DEBUG_MSG (" FUNCTION: flags: 0x%x declarations: %d", (int) info_p->u8_arg, (int) info_p->u16_arg); } else { @@ -3601,8 +3542,7 @@ scan_completed: #else /* !JERRY_ESNEXT */ case SCANNER_STREAM_TYPE_ARGUMENTS: { - JERRY_DEBUG_MSG (" ARGUMENTS%s\n", - (data_p[0] & SCANNER_STREAM_NO_REG) ? " *" : ""); + JERRY_DEBUG_MSG (" ARGUMENTS%s\n", (data_p[0] & SCANNER_STREAM_NO_REG) ? " *" : ""); data_p++; continue; } @@ -3765,8 +3705,7 @@ scan_completed: #endif /* JERRY_ESNEXT */ case SCANNER_TYPE_SWITCH: { - JERRY_DEBUG_MSG (" SWITCH: source:%d\n", - (int) (info_p->source_p - source_start_p)); + JERRY_DEBUG_MSG (" SWITCH: source:%d\n", (int) (info_p->source_p - source_start_p)); scanner_case_info_t *current_case_p = ((scanner_switch_info_t *) info_p)->case_p; @@ -3801,8 +3740,7 @@ scan_completed: } case SCANNER_TYPE_CLASS_CONSTRUCTOR: { - JERRY_DEBUG_MSG (" CLASS_CONSTRUCTOR: source:%d\n", - (int) (info_p->source_p - source_start_p)); + JERRY_DEBUG_MSG (" CLASS_CONSTRUCTOR: source:%d\n", (int) (info_p->source_p - source_start_p)); print_location = false; break; } @@ -3814,20 +3752,17 @@ scan_completed: } case SCANNER_TYPE_LET_EXPRESSION: { - JERRY_DEBUG_MSG (" LET_EXPRESSION: source:%d\n", - (int) (info_p->source_p - source_start_p)); + JERRY_DEBUG_MSG (" LET_EXPRESSION: source:%d\n", (int) (info_p->source_p - source_start_p)); break; } case SCANNER_TYPE_ERR_REDECLARED: { - JERRY_DEBUG_MSG (" ERR_REDECLARED: source:%d\n", - (int) (info_p->source_p - source_start_p)); + JERRY_DEBUG_MSG (" ERR_REDECLARED: source:%d\n", (int) (info_p->source_p - source_start_p)); break; } case SCANNER_TYPE_ERR_ASYNC_FUNCTION: { - JERRY_DEBUG_MSG (" ERR_ASYNC_FUNCTION: source:%d\n", - (int) (info_p->source_p - source_start_p)); + JERRY_DEBUG_MSG (" ERR_ASYNC_FUNCTION: source:%d\n", (int) (info_p->source_p - source_start_p)); break; } case SCANNER_TYPE_LITERAL_FLAGS: @@ -3840,8 +3775,7 @@ scan_completed: } case SCANNER_TYPE_EXPORT_MODULE_SPECIFIER: { - JERRY_DEBUG_MSG (" EXPORT_WITH_MODULE_SPECIFIER: source:%d\n", - (int) (info_p->source_p - source_start_p)); + JERRY_DEBUG_MSG (" EXPORT_WITH_MODULE_SPECIFIER: source:%d\n", (int) (info_p->source_p - source_start_p)); print_location = false; break; } diff --git a/jerry-core/parser/js/js-scanner.h b/jerry-core/parser/js/js-scanner.h index 4f538e63..9513d099 100644 --- a/jerry-core/parser/js/js-scanner.h +++ b/jerry-core/parser/js/js-scanner.h @@ -229,18 +229,17 @@ typedef enum /** * Checks whether the decoded type represents a function argument. */ -#define SCANNER_STREAM_TYPE_IS_ARG(type) ((type) == SCANNER_STREAM_TYPE_ARG) +#define SCANNER_STREAM_TYPE_IS_ARG(type) ((type) == SCANNER_STREAM_TYPE_ARG) /** * Checks whether the decoded type represents both a function argument and a function declaration. */ -#define SCANNER_STREAM_TYPE_IS_ARG_FUNC(type) ((type) == SCANNER_STREAM_TYPE_ARG_FUNC) +#define SCANNER_STREAM_TYPE_IS_ARG_FUNC(type) ((type) == SCANNER_STREAM_TYPE_ARG_FUNC) /** * Checks whether the decoded type represents an arguments declaration */ -#define SCANNER_STREAM_TYPE_IS_ARGUMENTS(type) \ - ((type) == SCANNER_STREAM_TYPE_ARGUMENTS) +#define SCANNER_STREAM_TYPE_IS_ARGUMENTS(type) ((type) == SCANNER_STREAM_TYPE_ARGUMENTS) #endif /* JERRY_ESNEXT */ diff --git a/jerry-core/parser/regexp/re-bytecode.c b/jerry-core/parser/regexp/re-bytecode.c index fe30029f..82b62ee6 100644 --- a/jerry-core/parser/regexp/re-bytecode.c +++ b/jerry-core/parser/regexp/re-bytecode.c @@ -13,10 +13,12 @@ * limitations under the License. */ +#include "re-bytecode.h" + #include "ecma-globals.h" #include "ecma-regexp-object.h" + #include "lit-strings.h" -#include "re-bytecode.h" #if JERRY_BUILTIN_REGEXP @@ -155,7 +157,7 @@ re_encode_u16 (uint8_t *dest_p, /**< destination */ */ static void re_encode_u32 (uint8_t *dest_p, /**< destination */ - const uint32_t value) /**< value */ + const uint32_t value) /**< value */ { *dest_p++ = (uint8_t) ((value >> 24) & 0xFF); *dest_p++ = (uint8_t) ((value >> 16) & 0xFF); @@ -368,7 +370,7 @@ re_get_bytecode_offset (const uint8_t *start_p, /**< bytecode start pointer */ void re_dump_bytecode (re_compiler_ctx_t *re_ctx_p) /**< RegExp bytecode context */ { - static const char escape_chars[] = {'d', 'D', 'w', 'W', 's', 'S'}; + static const char escape_chars[] = { 'd', 'D', 'w', 'W', 's', 'S' }; re_compiled_code_t *compiled_code_p = (re_compiled_code_t *) re_ctx_p->bytecode_start_p; JERRY_DEBUG_MSG ("Flags: 0x%x ", compiled_code_p->header.status_flags); diff --git a/jerry-core/parser/regexp/re-bytecode.h b/jerry-core/parser/regexp/re-bytecode.h index 942f6fdc..07028d6d 100644 --- a/jerry-core/parser/regexp/re-bytecode.h +++ b/jerry-core/parser/regexp/re-bytecode.h @@ -16,11 +16,12 @@ #ifndef RE_BYTECODE_H #define RE_BYTECODE_H -#if JERRY_BUILTIN_REGEXP - #include "ecma-globals.h" + #include "re-compiler-context.h" +#if JERRY_BUILTIN_REGEXP + /** \addtogroup parser Parser * @{ * @@ -32,8 +33,8 @@ */ /** - * Size of the RegExp bytecode cache - */ + * Size of the RegExp bytecode cache + */ #define RE_CACHE_SIZE 8u /** @@ -51,42 +52,42 @@ */ typedef enum { - RE_OP_EOF, /**< end of pattern */ + RE_OP_EOF, /**< end of pattern */ - RE_OP_ALTERNATIVE_START, /**< start of alternatives */ - RE_OP_ALTERNATIVE_NEXT, /**< next alternative */ - RE_OP_NO_ALTERNATIVE, /**< no alternative */ + RE_OP_ALTERNATIVE_START, /**< start of alternatives */ + RE_OP_ALTERNATIVE_NEXT, /**< next alternative */ + RE_OP_NO_ALTERNATIVE, /**< no alternative */ - RE_OP_CAPTURING_GROUP_START, /**< start of a capturing group */ - RE_OP_NON_CAPTURING_GROUP_START, /**< start of a non-capturing group */ + RE_OP_CAPTURING_GROUP_START, /**< start of a capturing group */ + RE_OP_NON_CAPTURING_GROUP_START, /**< start of a non-capturing group */ - RE_OP_GREEDY_CAPTURING_GROUP_END, /**< end of a greedy capturing group */ - RE_OP_GREEDY_NON_CAPTURING_GROUP_END, /**< end of a greedy non-capturing group */ - RE_OP_LAZY_CAPTURING_GROUP_END, /**< end of a lazy capturing group */ - RE_OP_LAZY_NON_CAPTURING_GROUP_END, /**< end of a lazy non-capturing group */ + RE_OP_GREEDY_CAPTURING_GROUP_END, /**< end of a greedy capturing group */ + RE_OP_GREEDY_NON_CAPTURING_GROUP_END, /**< end of a greedy non-capturing group */ + RE_OP_LAZY_CAPTURING_GROUP_END, /**< end of a lazy capturing group */ + RE_OP_LAZY_NON_CAPTURING_GROUP_END, /**< end of a lazy non-capturing group */ - RE_OP_GREEDY_ITERATOR, /**< greedy iterator */ - RE_OP_LAZY_ITERATOR, /**< lazy iterator */ - RE_OP_ITERATOR_END, /*** end of an iterator */ + RE_OP_GREEDY_ITERATOR, /**< greedy iterator */ + RE_OP_LAZY_ITERATOR, /**< lazy iterator */ + RE_OP_ITERATOR_END, /*** end of an iterator */ - RE_OP_BACKREFERENCE, /**< backreference */ + RE_OP_BACKREFERENCE, /**< backreference */ - RE_OP_ASSERT_LINE_START, /**< line start assertion */ - RE_OP_ASSERT_LINE_END, /**< line end assertion */ - RE_OP_ASSERT_WORD_BOUNDARY, /**< word boundary assertion */ - RE_OP_ASSERT_NOT_WORD_BOUNDARY, /**< not word boundary assertion */ - RE_OP_ASSERT_LOOKAHEAD_POS, /**< positive lookahead assertion */ - RE_OP_ASSERT_LOOKAHEAD_NEG, /**< negative lookahead assertion */ - RE_OP_ASSERT_END, /**< end of an assertion */ + RE_OP_ASSERT_LINE_START, /**< line start assertion */ + RE_OP_ASSERT_LINE_END, /**< line end assertion */ + RE_OP_ASSERT_WORD_BOUNDARY, /**< word boundary assertion */ + RE_OP_ASSERT_NOT_WORD_BOUNDARY, /**< not word boundary assertion */ + RE_OP_ASSERT_LOOKAHEAD_POS, /**< positive lookahead assertion */ + RE_OP_ASSERT_LOOKAHEAD_NEG, /**< negative lookahead assertion */ + RE_OP_ASSERT_END, /**< end of an assertion */ - RE_OP_CLASS_ESCAPE, /**< class escape */ - RE_OP_CHAR_CLASS, /**< character class */ + RE_OP_CLASS_ESCAPE, /**< class escape */ + RE_OP_CHAR_CLASS, /**< character class */ #if JERRY_ESNEXT - RE_OP_UNICODE_PERIOD, /**< period in full unicode mode */ + RE_OP_UNICODE_PERIOD, /**< period in full unicode mode */ #endif /* JERRY_ESNEXT */ - RE_OP_PERIOD, /**< period in non-unicode mode */ - RE_OP_CHAR, /**< any code point */ - RE_OP_BYTE, /**< 1-byte utf8 character */ + RE_OP_PERIOD, /**< period in non-unicode mode */ + RE_OP_CHAR, /**< any code point */ + RE_OP_BYTE, /**< 1-byte utf8 character */ } re_opcode_t; /** @@ -94,10 +95,10 @@ typedef enum */ typedef struct { - ecma_compiled_code_t header; /**< compiled code header */ - uint32_t captures_count; /**< number of capturing groups */ - uint32_t non_captures_count; /**< number of non-capturing groups */ - ecma_value_t source; /**< original RegExp pattern */ + ecma_compiled_code_t header; /**< compiled code header */ + uint32_t captures_count; /**< number of capturing groups */ + uint32_t non_captures_count; /**< number of non-capturing groups */ + ecma_value_t source; /**< original RegExp pattern */ } re_compiled_code_t; void re_initialize_regexp_bytecode (re_compiler_ctx_t *re_ctx_p); @@ -110,7 +111,7 @@ void re_append_value (re_compiler_ctx_t *re_ctx_p, const uint32_t value); void re_insert_opcode (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const re_opcode_t opcode); void re_insert_byte (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const uint8_t byte); -void re_insert_char (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const lit_code_point_t cp); +void re_insert_char (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const lit_code_point_t cp); void re_insert_value (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const uint32_t value); re_opcode_t re_get_opcode (const uint8_t **bc_p); diff --git a/jerry-core/parser/regexp/re-compiler-context.h b/jerry-core/parser/regexp/re-compiler-context.h index 72089106..b7dbb029 100644 --- a/jerry-core/parser/regexp/re-compiler-context.h +++ b/jerry-core/parser/regexp/re-compiler-context.h @@ -16,10 +16,10 @@ #ifndef RE_COMPILER_CONTEXT_H #define RE_COMPILER_CONTEXT_H -#if JERRY_BUILTIN_REGEXP - #include "re-token.h" +#if JERRY_BUILTIN_REGEXP + /** \addtogroup parser Parser * @{ * @@ -36,18 +36,18 @@ typedef struct { const lit_utf8_byte_t *input_start_p; /**< start of input pattern */ - const lit_utf8_byte_t *input_curr_p; /**< current position in input pattern */ - const lit_utf8_byte_t *input_end_p; /**< end of input pattern */ + const lit_utf8_byte_t *input_curr_p; /**< current position in input pattern */ + const lit_utf8_byte_t *input_end_p; /**< end of input pattern */ - uint8_t *bytecode_start_p; /**< start of bytecode block */ - size_t bytecode_size; /**< size of bytecode */ + uint8_t *bytecode_start_p; /**< start of bytecode block */ + size_t bytecode_size; /**< size of bytecode */ - uint32_t captures_count; /**< number of capture groups */ - uint32_t non_captures_count; /**< number of non-capture groups */ + uint32_t captures_count; /**< number of capture groups */ + uint32_t non_captures_count; /**< number of non-capture groups */ - int groups_count; /**< number of groups */ - uint16_t flags; /**< RegExp flags */ - re_token_t token; /**< current token */ + int groups_count; /**< number of groups */ + uint16_t flags; /**< RegExp flags */ + re_token_t token; /**< current token */ } re_compiler_ctx_t; /** diff --git a/jerry-core/parser/regexp/re-compiler.c b/jerry-core/parser/regexp/re-compiler.c index 4073e60c..a495616b 100644 --- a/jerry-core/parser/regexp/re-compiler.c +++ b/jerry-core/parser/regexp/re-compiler.c @@ -13,15 +13,17 @@ * limitations under the License. */ +#include "re-compiler.h" + #include "ecma-exceptions.h" #include "ecma-helpers.h" #include "ecma-regexp-object.h" -#include "lit-char-helpers.h" + #include "jcontext.h" -#include "jrt-libc-includes.h" #include "jmem.h" +#include "jrt-libc-includes.h" +#include "lit-char-helpers.h" #include "re-bytecode.h" -#include "re-compiler.h" #include "re-compiler-context.h" #include "re-parser.h" @@ -140,9 +142,8 @@ re_compile_bytecode (ecma_string_t *pattern_str_p, /**< pattern */ /* Align bytecode size to JMEM_ALIGNMENT so that it can be stored in the bytecode header. */ const uint32_t final_size = JERRY_ALIGNUP (re_ctx.bytecode_size, JMEM_ALIGNMENT); - re_compiled_code_t *re_compiled_code_p = (re_compiled_code_t *) jmem_heap_realloc_block (re_ctx.bytecode_start_p, - re_ctx.bytecode_size, - final_size); + re_compiled_code_t *re_compiled_code_p = + (re_compiled_code_t *) jmem_heap_realloc_block (re_ctx.bytecode_start_p, re_ctx.bytecode_size, final_size); /* Bytecoded will be inserted into the cache and returned to the caller, so refcount is implicitly set to 2. */ re_compiled_code_p->header.refs = 2; diff --git a/jerry-core/parser/regexp/re-compiler.h b/jerry-core/parser/regexp/re-compiler.h index 06602c59..ace781ef 100644 --- a/jerry-core/parser/regexp/re-compiler.h +++ b/jerry-core/parser/regexp/re-compiler.h @@ -16,11 +16,12 @@ #ifndef RE_COMPILER_H #define RE_COMPILER_H -#if JERRY_BUILTIN_REGEXP - #include "ecma-globals.h" + #include "re-bytecode.h" +#if JERRY_BUILTIN_REGEXP + /** \addtogroup parser Parser * @{ * @@ -31,8 +32,7 @@ * @{ */ -re_compiled_code_t * -re_compile_bytecode (ecma_string_t *pattern_str_p, uint16_t flags); +re_compiled_code_t *re_compile_bytecode (ecma_string_t *pattern_str_p, uint16_t flags); void re_cache_gc (void); diff --git a/jerry-core/parser/regexp/re-parser.c b/jerry-core/parser/regexp/re-parser.c index ac362c19..cd12aa56 100644 --- a/jerry-core/parser/regexp/re-parser.c +++ b/jerry-core/parser/regexp/re-parser.c @@ -13,13 +13,15 @@ * limitations under the License. */ +#include "re-parser.h" + #include "ecma-exceptions.h" #include "ecma-globals.h" + #include "jcontext.h" #include "jrt-libc-includes.h" #include "lit-char-helpers.h" #include "re-compiler.h" -#include "re-parser.h" #if JERRY_BUILTIN_REGEXP @@ -42,7 +44,7 @@ static re_opcode_t re_get_group_start_opcode (bool is_capturing) /**< is capturing group */ { return (is_capturing) ? RE_OP_CAPTURING_GROUP_START : RE_OP_NON_CAPTURING_GROUP_START; -} /* re_get_group_start_opcode*/ +} /* re_get_group_start_opcode */ /** * Get the end opcode for the current group. @@ -91,9 +93,7 @@ re_insert_into_group (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context if (qmin == 0) { - re_insert_value (re_ctx_p, - group_start_offset, - re_bytecode_size (re_ctx_p) - group_start_offset); + re_insert_value (re_ctx_p, group_start_offset, re_bytecode_size (re_ctx_p) - group_start_offset); } re_insert_value (re_ctx_p, group_start_offset, qmin); @@ -174,8 +174,7 @@ re_insert_assertion_lookahead (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler static void re_parse_lazy_char (re_compiler_ctx_t *re_ctx_p) /**< RegExp parser context */ { - if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p - && *re_ctx_p->input_curr_p == LIT_CHAR_QUESTION) + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && *re_ctx_p->input_curr_p == LIT_CHAR_QUESTION) { re_ctx_p->input_curr_p++; re_ctx_p->token.greedy = false; @@ -198,14 +197,12 @@ re_parse_octal (re_compiler_ctx_t *re_ctx_p) /**< RegExp parser context */ uint32_t value = (uint32_t) (*re_ctx_p->input_curr_p++) - LIT_CHAR_0; - if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p - && lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) { value = value * 8 + (*re_ctx_p->input_curr_p++) - LIT_CHAR_0; } - if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p - && lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) { const uint32_t new_value = value * 8 + (*re_ctx_p->input_curr_p) - LIT_CHAR_0; @@ -381,9 +378,7 @@ re_count_groups (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ } case LIT_CHAR_LEFT_PAREN: { - if (curr_p < re_ctx_p->input_end_p - && *curr_p != LIT_CHAR_QUESTION - && !is_char_class) + if (curr_p < re_ctx_p->input_end_p && *curr_p != LIT_CHAR_QUESTION && !is_char_class) { re_ctx_p->groups_count++; } @@ -403,20 +398,10 @@ re_count_groups (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ static bool re_is_syntax_char (lit_code_point_t cp) /**< code point */ { - return (cp == LIT_CHAR_CIRCUMFLEX - || cp == LIT_CHAR_DOLLAR_SIGN - || cp == LIT_CHAR_BACKSLASH - || cp == LIT_CHAR_DOT - || cp == LIT_CHAR_ASTERISK - || cp == LIT_CHAR_PLUS - || cp == LIT_CHAR_QUESTION - || cp == LIT_CHAR_LEFT_PAREN - || cp == LIT_CHAR_RIGHT_PAREN - || cp == LIT_CHAR_LEFT_SQUARE - || cp == LIT_CHAR_RIGHT_SQUARE - || cp == LIT_CHAR_LEFT_BRACE - || cp == LIT_CHAR_RIGHT_BRACE - || cp == LIT_CHAR_VLINE); + return (cp == LIT_CHAR_CIRCUMFLEX || cp == LIT_CHAR_DOLLAR_SIGN || cp == LIT_CHAR_BACKSLASH || cp == LIT_CHAR_DOT + || cp == LIT_CHAR_ASTERISK || cp == LIT_CHAR_PLUS || cp == LIT_CHAR_QUESTION || cp == LIT_CHAR_LEFT_PAREN + || cp == LIT_CHAR_RIGHT_PAREN || cp == LIT_CHAR_LEFT_SQUARE || cp == LIT_CHAR_RIGHT_SQUARE + || cp == LIT_CHAR_LEFT_BRACE || cp == LIT_CHAR_RIGHT_BRACE || cp == LIT_CHAR_VLINE); } /* re_is_syntax_char */ #endif /* JERRY_ESNEXT */ @@ -589,17 +574,15 @@ re_parse_char_escape (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context re_ctx_p->input_curr_p += 4; #if JERRY_ESNEXT - if (re_ctx_p->flags & RE_FLAG_UNICODE - && lit_is_code_point_utf16_high_surrogate (re_ctx_p->token.value) - && re_ctx_p->input_curr_p + 6 <= re_ctx_p->input_end_p - && re_ctx_p->input_curr_p[0] == '\\' + if (re_ctx_p->flags & RE_FLAG_UNICODE && lit_is_code_point_utf16_high_surrogate (re_ctx_p->token.value) + && re_ctx_p->input_curr_p + 6 <= re_ctx_p->input_end_p && re_ctx_p->input_curr_p[0] == '\\' && re_ctx_p->input_curr_p[1] == 'u') { hex_value = lit_char_hex_lookup (re_ctx_p->input_curr_p + 2, re_ctx_p->input_end_p, 4); if (lit_is_code_point_utf16_low_surrogate (hex_value)) { - re_ctx_p->token.value = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) re_ctx_p->token.value, - (ecma_char_t) hex_value); + re_ctx_p->token.value = + lit_convert_surrogate_pair_to_code_point ((ecma_char_t) re_ctx_p->token.value, (ecma_char_t) hex_value); re_ctx_p->input_curr_p += 6; } } @@ -611,8 +594,7 @@ re_parse_char_escape (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context #if JERRY_ESNEXT if (re_ctx_p->flags & RE_FLAG_UNICODE) { - if (re_ctx_p->input_curr_p + 1 < re_ctx_p->input_end_p - && re_ctx_p->input_curr_p[0] == LIT_CHAR_LEFT_BRACE + if (re_ctx_p->input_curr_p + 1 < re_ctx_p->input_end_p && re_ctx_p->input_curr_p[0] == LIT_CHAR_LEFT_BRACE && lit_char_is_hex_digit (re_ctx_p->input_curr_p[1])) { lit_code_point_t cp = lit_char_hex_to_int (re_ctx_p->input_curr_p[1]); @@ -648,9 +630,7 @@ re_parse_char_escape (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context { #if JERRY_ESNEXT /* Must be '/', or one of SyntaxCharacter */ - if (re_ctx_p->flags & RE_FLAG_UNICODE - && ch != LIT_CHAR_SLASH - && !re_is_syntax_char (ch)) + if (re_ctx_p->flags & RE_FLAG_UNICODE && ch != LIT_CHAR_SLASH && !re_is_syntax_char (ch)) { return ecma_raise_syntax_error (ECMA_ERR_MSG ("Invalid escape")); } @@ -863,8 +843,7 @@ re_parse_next_token (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context * re_ctx_p->token.value = ch; #if JERRY_ESNEXT - if (re_ctx_p->flags & RE_FLAG_UNICODE - && lit_is_code_point_utf16_high_surrogate (ch) + if (re_ctx_p->flags & RE_FLAG_UNICODE && lit_is_code_point_utf16_high_surrogate (ch) && re_ctx_p->input_curr_p < re_ctx_p->input_end_p) { const ecma_char_t next = lit_cesu8_peek_next (re_ctx_p->input_curr_p); @@ -908,8 +887,8 @@ re_class_add_range (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ */ static void re_class_add_char (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ - uint32_t class_offset, /**< character class bytecode offset*/ - lit_code_point_t cp) /**< code point */ + uint32_t class_offset, /**< character class bytecode offset*/ + lit_code_point_t cp) /**< code point */ { if (re_ctx_p->flags & RE_FLAG_IGNORE_CASE) { @@ -935,7 +914,7 @@ re_class_add_char (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ static ecma_value_t re_parse_char_class (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ { - static const uint8_t escape_flags[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20}; + static const uint8_t escape_flags[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20 }; const uint32_t class_offset = re_bytecode_size (re_ctx_p); uint8_t found_escape_flags = 0; @@ -1002,13 +981,12 @@ re_parse_char_class (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context * current = LIT_CHAR_MINUS; } #endif /* JERRY_ESNEXT */ - else if ((re_ctx_p->flags & RE_FLAG_UNICODE) == 0 - && *re_ctx_p->input_curr_p == LIT_CHAR_LOWERCASE_C + else if ((re_ctx_p->flags & RE_FLAG_UNICODE) == 0 && *re_ctx_p->input_curr_p == LIT_CHAR_LOWERCASE_C && re_ctx_p->input_curr_p + 1 < re_ctx_p->input_end_p && (lit_char_is_decimal_digit (*(re_ctx_p->input_curr_p + 1)) || *(re_ctx_p->input_curr_p + 1) == LIT_CHAR_UNDERSCORE)) { - current = ((uint8_t) *(re_ctx_p->input_curr_p + 1) % 32); + current = ((uint8_t) * (re_ctx_p->input_curr_p + 1) % 32); re_ctx_p->input_curr_p += 2; } else @@ -1081,8 +1059,7 @@ re_parse_char_class (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context * continue; } - if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p - && *re_ctx_p->input_curr_p == LIT_CHAR_MINUS) + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && *re_ctx_p->input_curr_p == LIT_CHAR_MINUS) { re_ctx_p->input_curr_p++; start = current; @@ -1215,8 +1192,9 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context case RE_TOK_ALTERNATIVE: { re_insert_value (re_ctx_p, alternative_offset, re_bytecode_size (re_ctx_p) - alternative_offset); - re_insert_opcode (re_ctx_p, alternative_offset, first_alternative ? RE_OP_ALTERNATIVE_START - : RE_OP_ALTERNATIVE_NEXT); + re_insert_opcode (re_ctx_p, + alternative_offset, + first_alternative ? RE_OP_ALTERNATIVE_START : RE_OP_ALTERNATIVE_NEXT); alternative_offset = re_bytecode_size (re_ctx_p); first_alternative = false; diff --git a/jerry-core/parser/regexp/re-parser.h b/jerry-core/parser/regexp/re-parser.h index 0c0ccfc9..0c28edc3 100644 --- a/jerry-core/parser/regexp/re-parser.h +++ b/jerry-core/parser/regexp/re-parser.h @@ -16,10 +16,10 @@ #ifndef RE_PARSER_H #define RE_PARSER_H -#if JERRY_BUILTIN_REGEXP - #include "re-compiler-context.h" +#if JERRY_BUILTIN_REGEXP + /** \addtogroup parser Parser * @{ * diff --git a/jerry-core/parser/regexp/re-token.h b/jerry-core/parser/regexp/re-token.h index a1df1c33..ad3b5dfe 100644 --- a/jerry-core/parser/regexp/re-token.h +++ b/jerry-core/parser/regexp/re-token.h @@ -16,6 +16,8 @@ #ifndef RE_TOKEN_H #define RE_TOKEN_H +#include "ecma-globals.h" + #if JERRY_BUILTIN_REGEXP /** \addtogroup parser Parser @@ -33,21 +35,21 @@ */ typedef enum { - RE_TOK_EOF, /**< EOF */ - RE_TOK_BACKREFERENCE, /**< "\[0..9]" */ - RE_TOK_ALTERNATIVE, /**< "|" */ - RE_TOK_ASSERT_START, /**< "^" */ - RE_TOK_ASSERT_END, /**< "$" */ - RE_TOK_PERIOD, /**< "." */ - RE_TOK_START_CAPTURE_GROUP, /**< "(" */ - RE_TOK_START_NON_CAPTURE_GROUP, /**< "(?:" */ - RE_TOK_END_GROUP, /**< ")" */ - RE_TOK_ASSERT_LOOKAHEAD, /**< "(?=" */ - RE_TOK_ASSERT_WORD_BOUNDARY, /**< "\b" */ - RE_TOK_ASSERT_NOT_WORD_BOUNDARY, /**< "\B" */ - RE_TOK_CLASS_ESCAPE, /**< "\d \D \w \W \s \S" */ - RE_TOK_CHAR_CLASS, /**< "[ ]" */ - RE_TOK_CHAR, /**< any character */ + RE_TOK_EOF, /**< EOF */ + RE_TOK_BACKREFERENCE, /**< "\[0..9]" */ + RE_TOK_ALTERNATIVE, /**< "|" */ + RE_TOK_ASSERT_START, /**< "^" */ + RE_TOK_ASSERT_END, /**< "$" */ + RE_TOK_PERIOD, /**< "." */ + RE_TOK_START_CAPTURE_GROUP, /**< "(" */ + RE_TOK_START_NON_CAPTURE_GROUP, /**< "(?:" */ + RE_TOK_END_GROUP, /**< ")" */ + RE_TOK_ASSERT_LOOKAHEAD, /**< "(?=" */ + RE_TOK_ASSERT_WORD_BOUNDARY, /**< "\b" */ + RE_TOK_ASSERT_NOT_WORD_BOUNDARY, /**< "\B" */ + RE_TOK_CLASS_ESCAPE, /**< "\d \D \w \W \s \S" */ + RE_TOK_CHAR_CLASS, /**< "[ ]" */ + RE_TOK_CHAR, /**< any character */ } re_token_type_t; /** @@ -55,11 +57,11 @@ typedef enum */ typedef struct { - uint32_t value; /**< value of the token */ - uint32_t qmin; /**< minimum number of token iterations */ - uint32_t qmax; /**< maximum number of token iterations */ - re_token_type_t type; /**< type of the token */ - bool greedy; /**< type of iteration */ + uint32_t value; /**< value of the token */ + uint32_t qmin; /**< minimum number of token iterations */ + uint32_t qmax; /**< maximum number of token iterations */ + re_token_type_t type; /**< type of the token */ + bool greedy; /**< type of iteration */ } re_token_t; /** |