1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci * 3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci * You may obtain a copy of the License at 6425bb815Sopenharmony_ci * 7425bb815Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci * 9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci * limitations under the License. 14425bb815Sopenharmony_ci */ 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_ci#include "jcontext.h" 17425bb815Sopenharmony_ci#include "js-parser-internal.h" 18425bb815Sopenharmony_ci#include "js-scanner-internal.h" 19425bb815Sopenharmony_ci#include "lit-char-helpers.h" 20425bb815Sopenharmony_ci 21425bb815Sopenharmony_ci#if ENABLED (JERRY_PARSER) 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ci/** \addtogroup parser Parser 24425bb815Sopenharmony_ci * @{ 25425bb815Sopenharmony_ci * 26425bb815Sopenharmony_ci * \addtogroup jsparser JavaScript 27425bb815Sopenharmony_ci * @{ 28425bb815Sopenharmony_ci * 29425bb815Sopenharmony_ci * \addtogroup jsparser_scanner Scanner 30425bb815Sopenharmony_ci * @{ 31425bb815Sopenharmony_ci */ 32425bb815Sopenharmony_ci 33425bb815Sopenharmony_ci/** 34425bb815Sopenharmony_ci * Scan return types. 35425bb815Sopenharmony_ci */ 36425bb815Sopenharmony_citypedef enum 37425bb815Sopenharmony_ci{ 38425bb815Sopenharmony_ci SCAN_NEXT_TOKEN, /**< get next token after return */ 39425bb815Sopenharmony_ci SCAN_KEEP_TOKEN, /**< keep the current token after return */ 40425bb815Sopenharmony_ci} scan_return_types_t; 41425bb815Sopenharmony_ci 42425bb815Sopenharmony_ci/** 43425bb815Sopenharmony_ci * Checks whether token type is "of". 44425bb815Sopenharmony_ci */ 45425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 46425bb815Sopenharmony_ci#define SCANNER_IDENTIFIER_IS_OF() (lexer_token_is_identifier (context_p, "of", 2)) 47425bb815Sopenharmony_ci#else 48425bb815Sopenharmony_ci#define SCANNER_IDENTIFIER_IS_OF() (false) 49425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 50425bb815Sopenharmony_ci 51425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 52425bb815Sopenharmony_ci 53425bb815Sopenharmony_ciJERRY_STATIC_ASSERT (SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_GENERATOR) 54425bb815Sopenharmony_ci == SCAN_STACK_COMPUTED_GENERATOR, 55425bb815Sopenharmony_ci scanner_invalid_conversion_from_literal_pool_generator_to_computed_generator); 56425bb815Sopenharmony_ciJERRY_STATIC_ASSERT (SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_ASYNC) 57425bb815Sopenharmony_ci == SCAN_STACK_COMPUTED_ASYNC, 58425bb815Sopenharmony_ci scanner_invalid_conversion_from_literal_pool_async_to_computed_async); 59425bb815Sopenharmony_ci 60425bb815Sopenharmony_ciJERRY_STATIC_ASSERT (SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_GENERATOR) 61425bb815Sopenharmony_ci == SCANNER_LITERAL_POOL_GENERATOR, 62425bb815Sopenharmony_ci scanner_invalid_conversion_from_computed_generator_to_literal_pool_generator); 63425bb815Sopenharmony_ciJERRY_STATIC_ASSERT (SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_ASYNC) 64425bb815Sopenharmony_ci == SCANNER_LITERAL_POOL_ASYNC, 65425bb815Sopenharmony_ci scanner_invalid_conversion_from_computed_async_to_literal_pool_async); 66425bb815Sopenharmony_ci 67425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 68425bb815Sopenharmony_ci 69425bb815Sopenharmony_ci/** 70425bb815Sopenharmony_ci * Scan primary expression. 71425bb815Sopenharmony_ci * 72425bb815Sopenharmony_ci * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing 73425bb815Sopenharmony_ci */ 74425bb815Sopenharmony_cistatic scan_return_types_t 75425bb815Sopenharmony_ciscanner_scan_primary_expression (parser_context_t *context_p, /**< context */ 76425bb815Sopenharmony_ci scanner_context_t *scanner_context_p, /* scanner context */ 77425bb815Sopenharmony_ci lexer_token_type_t type, /**< current token type */ 78425bb815Sopenharmony_ci scan_stack_modes_t stack_top) /**< current stack top */ 79425bb815Sopenharmony_ci{ 80425bb815Sopenharmony_ci switch (type) 81425bb815Sopenharmony_ci { 82425bb815Sopenharmony_ci case LEXER_KEYW_NEW: 83425bb815Sopenharmony_ci { 84425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW; 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 87425bb815Sopenharmony_ci if (scanner_try_scan_new_target (context_p)) 88425bb815Sopenharmony_ci { 89425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 90425bb815Sopenharmony_ci } 91425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 92425bb815Sopenharmony_ci break; 93425bb815Sopenharmony_ci } 94425bb815Sopenharmony_ci case LEXER_DIVIDE: 95425bb815Sopenharmony_ci case LEXER_ASSIGN_DIVIDE: 96425bb815Sopenharmony_ci { 97425bb815Sopenharmony_ci lexer_construct_regexp_object (context_p, true); 98425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 99425bb815Sopenharmony_ci break; 100425bb815Sopenharmony_ci } 101425bb815Sopenharmony_ci case LEXER_KEYW_FUNCTION: 102425bb815Sopenharmony_ci { 103425bb815Sopenharmony_ci uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; 104425bb815Sopenharmony_ci 105425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 106425bb815Sopenharmony_ci if (scanner_context_p->async_source_p != NULL) 107425bb815Sopenharmony_ci { 108425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_ASYNC; 109425bb815Sopenharmony_ci } 110425bb815Sopenharmony_ci 111425bb815Sopenharmony_ci if (lexer_consume_generator (context_p)) 112425bb815Sopenharmony_ci { 113425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_GENERATOR; 114425bb815Sopenharmony_ci } 115425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 116425bb815Sopenharmony_ci 117425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, scanner_context_p, status_flags); 118425bb815Sopenharmony_ci 119425bb815Sopenharmony_ci lexer_next_token (context_p); 120425bb815Sopenharmony_ci 121425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LITERAL 122425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 123425bb815Sopenharmony_ci { 124425bb815Sopenharmony_ci lexer_next_token (context_p); 125425bb815Sopenharmony_ci } 126425bb815Sopenharmony_ci 127425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_EXPRESSION); 128425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; 129425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 130425bb815Sopenharmony_ci } 131425bb815Sopenharmony_ci case LEXER_LEFT_PAREN: 132425bb815Sopenharmony_ci { 133425bb815Sopenharmony_ci scanner_scan_bracket (context_p, scanner_context_p); 134425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 135425bb815Sopenharmony_ci } 136425bb815Sopenharmony_ci case LEXER_LEFT_SQUARE: 137425bb815Sopenharmony_ci { 138425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 139425bb815Sopenharmony_ci scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_NONE, false); 140425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 141425bb815Sopenharmony_ci 142425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); 143425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 144425bb815Sopenharmony_ci break; 145425bb815Sopenharmony_ci } 146425bb815Sopenharmony_ci case LEXER_LEFT_BRACE: 147425bb815Sopenharmony_ci { 148425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 149425bb815Sopenharmony_ci scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_NONE, false); 150425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 151425bb815Sopenharmony_ci 152425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); 153425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; 154425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 155425bb815Sopenharmony_ci } 156425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 157425bb815Sopenharmony_ci case LEXER_TEMPLATE_LITERAL: 158425bb815Sopenharmony_ci { 159425bb815Sopenharmony_ci if (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) 160425bb815Sopenharmony_ci { 161425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_TEMPLATE_STRING); 162425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 163425bb815Sopenharmony_ci break; 164425bb815Sopenharmony_ci } 165425bb815Sopenharmony_ci 166425bb815Sopenharmony_ci /* The string is a normal string literal. */ 167425bb815Sopenharmony_ci /* FALLTHRU */ 168425bb815Sopenharmony_ci } 169425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 170425bb815Sopenharmony_ci case LEXER_LITERAL: 171425bb815Sopenharmony_ci { 172425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 173425bb815Sopenharmony_ci const uint8_t *source_p = context_p->source_p; 174425bb815Sopenharmony_ci 175425bb815Sopenharmony_ci if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL 176425bb815Sopenharmony_ci && lexer_check_arrow (context_p)) 177425bb815Sopenharmony_ci { 178425bb815Sopenharmony_ci scanner_scan_simple_arrow (context_p, scanner_context_p, source_p); 179425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 180425bb815Sopenharmony_ci } 181425bb815Sopenharmony_ci else if (JERRY_UNLIKELY (lexer_token_is_async (context_p))) 182425bb815Sopenharmony_ci { 183425bb815Sopenharmony_ci scanner_context_p->async_source_p = source_p; 184425bb815Sopenharmony_ci scanner_check_async_function (context_p, scanner_context_p); 185425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 186425bb815Sopenharmony_ci } 187425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 188425bb815Sopenharmony_ci 189425bb815Sopenharmony_ci if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 190425bb815Sopenharmony_ci { 191425bb815Sopenharmony_ci scanner_add_reference (context_p, scanner_context_p); 192425bb815Sopenharmony_ci } 193425bb815Sopenharmony_ci /* FALLTHRU */ 194425bb815Sopenharmony_ci } 195425bb815Sopenharmony_ci case LEXER_KEYW_THIS: 196425bb815Sopenharmony_ci case LEXER_KEYW_SUPER: 197425bb815Sopenharmony_ci case LEXER_LIT_TRUE: 198425bb815Sopenharmony_ci case LEXER_LIT_FALSE: 199425bb815Sopenharmony_ci case LEXER_LIT_NULL: 200425bb815Sopenharmony_ci { 201425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 202425bb815Sopenharmony_ci break; 203425bb815Sopenharmony_ci } 204425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 205425bb815Sopenharmony_ci case LEXER_KEYW_CLASS: 206425bb815Sopenharmony_ci { 207425bb815Sopenharmony_ci scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_EXPRESSION); 208425bb815Sopenharmony_ci 209425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 210425bb815Sopenharmony_ci { 211425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 212425bb815Sopenharmony_ci } 213425bb815Sopenharmony_ci break; 214425bb815Sopenharmony_ci } 215425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 216425bb815Sopenharmony_ci case LEXER_RIGHT_SQUARE: 217425bb815Sopenharmony_ci { 218425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_ARRAY_LITERAL) 219425bb815Sopenharmony_ci { 220425bb815Sopenharmony_ci scanner_raise_error (context_p); 221425bb815Sopenharmony_ci } 222425bb815Sopenharmony_ci 223425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 224425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 225425bb815Sopenharmony_ci } 226425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 227425bb815Sopenharmony_ci case LEXER_THREE_DOTS: 228425bb815Sopenharmony_ci { 229425bb815Sopenharmony_ci /* Elision or spread arguments */ 230425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_PAREN_EXPRESSION && stack_top != SCAN_STACK_ARRAY_LITERAL) 231425bb815Sopenharmony_ci { 232425bb815Sopenharmony_ci scanner_raise_error (context_p); 233425bb815Sopenharmony_ci } 234425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 235425bb815Sopenharmony_ci break; 236425bb815Sopenharmony_ci } 237425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 238425bb815Sopenharmony_ci case LEXER_COMMA: 239425bb815Sopenharmony_ci { 240425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_ARRAY_LITERAL) 241425bb815Sopenharmony_ci { 242425bb815Sopenharmony_ci scanner_raise_error (context_p); 243425bb815Sopenharmony_ci } 244425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 245425bb815Sopenharmony_ci 246425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 247425bb815Sopenharmony_ci if (scanner_context_p->binding_type != SCANNER_BINDING_NONE) 248425bb815Sopenharmony_ci { 249425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_BINDING; 250425bb815Sopenharmony_ci } 251425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 252425bb815Sopenharmony_ci break; 253425bb815Sopenharmony_ci } 254425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 255425bb815Sopenharmony_ci case LEXER_KEYW_YIELD: 256425bb815Sopenharmony_ci { 257425bb815Sopenharmony_ci lexer_next_token (context_p); 258425bb815Sopenharmony_ci 259425bb815Sopenharmony_ci if (lexer_check_yield_no_arg (context_p)) 260425bb815Sopenharmony_ci { 261425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 262425bb815Sopenharmony_ci } 263425bb815Sopenharmony_ci 264425bb815Sopenharmony_ci if (context_p->token.type == LEXER_MULTIPLY) 265425bb815Sopenharmony_ci { 266425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 267425bb815Sopenharmony_ci } 268425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 269425bb815Sopenharmony_ci } 270425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 271425bb815Sopenharmony_ci case LEXER_RIGHT_PAREN: 272425bb815Sopenharmony_ci { 273425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_PAREN_EXPRESSION) 274425bb815Sopenharmony_ci { 275425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 276425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 277425bb815Sopenharmony_ci break; 278425bb815Sopenharmony_ci } 279425bb815Sopenharmony_ci /* FALLTHRU */ 280425bb815Sopenharmony_ci } 281425bb815Sopenharmony_ci default: 282425bb815Sopenharmony_ci { 283425bb815Sopenharmony_ci scanner_raise_error (context_p); 284425bb815Sopenharmony_ci } 285425bb815Sopenharmony_ci } 286425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 287425bb815Sopenharmony_ci} /* scanner_scan_primary_expression */ 288425bb815Sopenharmony_ci 289425bb815Sopenharmony_ci/** 290425bb815Sopenharmony_ci * Scan the tokens after the primary expression. 291425bb815Sopenharmony_ci * 292425bb815Sopenharmony_ci * @return true for break, false for fall through 293425bb815Sopenharmony_ci */ 294425bb815Sopenharmony_cistatic bool 295425bb815Sopenharmony_ciscanner_scan_post_primary_expression (parser_context_t *context_p, /**< context */ 296425bb815Sopenharmony_ci scanner_context_t *scanner_context_p, /**< scanner context */ 297425bb815Sopenharmony_ci lexer_token_type_t type, /**< current token type */ 298425bb815Sopenharmony_ci scan_stack_modes_t stack_top) /**< current stack top */ 299425bb815Sopenharmony_ci{ 300425bb815Sopenharmony_ci switch (type) 301425bb815Sopenharmony_ci { 302425bb815Sopenharmony_ci case LEXER_DOT: 303425bb815Sopenharmony_ci { 304425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 305425bb815Sopenharmony_ci 306425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 307425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 308425bb815Sopenharmony_ci { 309425bb815Sopenharmony_ci scanner_raise_error (context_p); 310425bb815Sopenharmony_ci } 311425bb815Sopenharmony_ci 312425bb815Sopenharmony_ci return true; 313425bb815Sopenharmony_ci } 314425bb815Sopenharmony_ci case LEXER_LEFT_PAREN: 315425bb815Sopenharmony_ci { 316425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_EXPRESSION); 317425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 318425bb815Sopenharmony_ci return true; 319425bb815Sopenharmony_ci } 320425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 321425bb815Sopenharmony_ci case LEXER_TEMPLATE_LITERAL: 322425bb815Sopenharmony_ci { 323425bb815Sopenharmony_ci if (JERRY_UNLIKELY (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT)) 324425bb815Sopenharmony_ci { 325425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 326425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_TAGGED_TEMPLATE_LITERAL); 327425bb815Sopenharmony_ci } 328425bb815Sopenharmony_ci return true; 329425bb815Sopenharmony_ci } 330425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 331425bb815Sopenharmony_ci case LEXER_LEFT_SQUARE: 332425bb815Sopenharmony_ci { 333425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_PROPERTY_ACCESSOR); 334425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 335425bb815Sopenharmony_ci return true; 336425bb815Sopenharmony_ci } 337425bb815Sopenharmony_ci case LEXER_INCREASE: 338425bb815Sopenharmony_ci case LEXER_DECREASE: 339425bb815Sopenharmony_ci { 340425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 341425bb815Sopenharmony_ci 342425bb815Sopenharmony_ci if (context_p->token.flags & LEXER_WAS_NEWLINE) 343425bb815Sopenharmony_ci { 344425bb815Sopenharmony_ci return false; 345425bb815Sopenharmony_ci } 346425bb815Sopenharmony_ci 347425bb815Sopenharmony_ci lexer_next_token (context_p); 348425bb815Sopenharmony_ci type = (lexer_token_type_t) context_p->token.type; 349425bb815Sopenharmony_ci 350425bb815Sopenharmony_ci if (type != LEXER_QUESTION_MARK) 351425bb815Sopenharmony_ci { 352425bb815Sopenharmony_ci break; 353425bb815Sopenharmony_ci } 354425bb815Sopenharmony_ci /* FALLTHRU */ 355425bb815Sopenharmony_ci } 356425bb815Sopenharmony_ci case LEXER_QUESTION_MARK: 357425bb815Sopenharmony_ci { 358425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_COLON_EXPRESSION); 359425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 360425bb815Sopenharmony_ci return true; 361425bb815Sopenharmony_ci } 362425bb815Sopenharmony_ci default: 363425bb815Sopenharmony_ci { 364425bb815Sopenharmony_ci break; 365425bb815Sopenharmony_ci } 366425bb815Sopenharmony_ci } 367425bb815Sopenharmony_ci 368425bb815Sopenharmony_ci if (LEXER_IS_BINARY_OP_TOKEN (type) 369425bb815Sopenharmony_ci && (type != LEXER_KEYW_IN || !SCANNER_IS_FOR_START (stack_top))) 370425bb815Sopenharmony_ci { 371425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 372425bb815Sopenharmony_ci return true; 373425bb815Sopenharmony_ci } 374425bb815Sopenharmony_ci 375425bb815Sopenharmony_ci return false; 376425bb815Sopenharmony_ci} /* scanner_scan_post_primary_expression */ 377425bb815Sopenharmony_ci 378425bb815Sopenharmony_ci/** 379425bb815Sopenharmony_ci * Scan the tokens after the primary expression. 380425bb815Sopenharmony_ci * 381425bb815Sopenharmony_ci * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing 382425bb815Sopenharmony_ci */ 383425bb815Sopenharmony_cistatic scan_return_types_t 384425bb815Sopenharmony_ciscanner_scan_primary_expression_end (parser_context_t *context_p, /**< context */ 385425bb815Sopenharmony_ci scanner_context_t *scanner_context_p, /**< scanner context */ 386425bb815Sopenharmony_ci lexer_token_type_t type, /**< current token type */ 387425bb815Sopenharmony_ci scan_stack_modes_t stack_top) /**< current stack top */ 388425bb815Sopenharmony_ci{ 389425bb815Sopenharmony_ci if (type == LEXER_COMMA) 390425bb815Sopenharmony_ci { 391425bb815Sopenharmony_ci switch (stack_top) 392425bb815Sopenharmony_ci { 393425bb815Sopenharmony_ci case SCAN_STACK_VAR: 394425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 395425bb815Sopenharmony_ci case SCAN_STACK_LET: 396425bb815Sopenharmony_ci case SCAN_STACK_CONST: 397425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 398425bb815Sopenharmony_ci case SCAN_STACK_FOR_VAR_START: 399425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 400425bb815Sopenharmony_ci case SCAN_STACK_FOR_LET_START: 401425bb815Sopenharmony_ci case SCAN_STACK_FOR_CONST_START: 402425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 403425bb815Sopenharmony_ci { 404425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 405425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 406425bb815Sopenharmony_ci } 407425bb815Sopenharmony_ci case SCAN_STACK_COLON_EXPRESSION: 408425bb815Sopenharmony_ci { 409425bb815Sopenharmony_ci scanner_raise_error (context_p); 410425bb815Sopenharmony_ci break; 411425bb815Sopenharmony_ci } 412425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 413425bb815Sopenharmony_ci case SCAN_STACK_BINDING_INIT: 414425bb815Sopenharmony_ci case SCAN_STACK_BINDING_LIST_INIT: 415425bb815Sopenharmony_ci { 416425bb815Sopenharmony_ci break; 417425bb815Sopenharmony_ci } 418425bb815Sopenharmony_ci case SCAN_STACK_ARROW_ARGUMENTS: 419425bb815Sopenharmony_ci { 420425bb815Sopenharmony_ci lexer_next_token (context_p); 421425bb815Sopenharmony_ci scanner_check_arrow_arg (context_p, scanner_context_p); 422425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 423425bb815Sopenharmony_ci } 424425bb815Sopenharmony_ci case SCAN_STACK_ARROW_EXPRESSION: 425425bb815Sopenharmony_ci { 426425bb815Sopenharmony_ci break; 427425bb815Sopenharmony_ci } 428425bb815Sopenharmony_ci case SCAN_STACK_FUNCTION_PARAMETERS: 429425bb815Sopenharmony_ci { 430425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS; 431425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 432425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 433425bb815Sopenharmony_ci } 434425bb815Sopenharmony_ci case SCAN_STACK_ARRAY_LITERAL: 435425bb815Sopenharmony_ci { 436425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 437425bb815Sopenharmony_ci 438425bb815Sopenharmony_ci if (scanner_context_p->binding_type != SCANNER_BINDING_NONE) 439425bb815Sopenharmony_ci { 440425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_BINDING; 441425bb815Sopenharmony_ci } 442425bb815Sopenharmony_ci 443425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 444425bb815Sopenharmony_ci } 445425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 446425bb815Sopenharmony_ci case SCAN_STACK_OBJECT_LITERAL: 447425bb815Sopenharmony_ci { 448425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; 449425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 450425bb815Sopenharmony_ci } 451425bb815Sopenharmony_ci default: 452425bb815Sopenharmony_ci { 453425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 454425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 455425bb815Sopenharmony_ci } 456425bb815Sopenharmony_ci } 457425bb815Sopenharmony_ci } 458425bb815Sopenharmony_ci 459425bb815Sopenharmony_ci switch (stack_top) 460425bb815Sopenharmony_ci { 461425bb815Sopenharmony_ci case SCAN_STACK_WITH_EXPRESSION: 462425bb815Sopenharmony_ci { 463425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 464425bb815Sopenharmony_ci { 465425bb815Sopenharmony_ci break; 466425bb815Sopenharmony_ci } 467425bb815Sopenharmony_ci 468425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 469425bb815Sopenharmony_ci 470425bb815Sopenharmony_ci uint16_t status_flags = scanner_context_p->active_literal_pool_p->status_flags; 471425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, (status_flags & SCANNER_LITERAL_POOL_IN_WITH) ? 1 : 0); 472425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_WITH_STATEMENT); 473425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_IN_WITH; 474425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p->status_flags = status_flags; 475425bb815Sopenharmony_ci 476425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 477425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 478425bb815Sopenharmony_ci } 479425bb815Sopenharmony_ci case SCAN_STACK_DO_EXPRESSION: 480425bb815Sopenharmony_ci { 481425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 482425bb815Sopenharmony_ci { 483425bb815Sopenharmony_ci break; 484425bb815Sopenharmony_ci } 485425bb815Sopenharmony_ci 486425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 487425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 488425bb815Sopenharmony_ci } 489425bb815Sopenharmony_ci case SCAN_STACK_WHILE_EXPRESSION: 490425bb815Sopenharmony_ci { 491425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 492425bb815Sopenharmony_ci { 493425bb815Sopenharmony_ci break; 494425bb815Sopenharmony_ci } 495425bb815Sopenharmony_ci 496425bb815Sopenharmony_ci scanner_source_start_t source_start; 497425bb815Sopenharmony_ci 498425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 499425bb815Sopenharmony_ci parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); 500425bb815Sopenharmony_ci 501425bb815Sopenharmony_ci scanner_location_info_t *location_info_p; 502425bb815Sopenharmony_ci location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, 503425bb815Sopenharmony_ci source_start.source_p, 504425bb815Sopenharmony_ci sizeof (scanner_location_info_t)); 505425bb815Sopenharmony_ci location_info_p->info.type = SCANNER_TYPE_WHILE; 506425bb815Sopenharmony_ci 507425bb815Sopenharmony_ci scanner_get_location (&location_info_p->location, context_p); 508425bb815Sopenharmony_ci 509425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 510425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 511425bb815Sopenharmony_ci } 512425bb815Sopenharmony_ci case SCAN_STACK_PAREN_EXPRESSION: 513425bb815Sopenharmony_ci { 514425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 515425bb815Sopenharmony_ci { 516425bb815Sopenharmony_ci break; 517425bb815Sopenharmony_ci } 518425bb815Sopenharmony_ci 519425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 520425bb815Sopenharmony_ci 521425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 522425bb815Sopenharmony_ci if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) 523425bb815Sopenharmony_ci { 524425bb815Sopenharmony_ci scanner_add_async_literal (context_p, scanner_context_p); 525425bb815Sopenharmony_ci } 526425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 527425bb815Sopenharmony_ci 528425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 529425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 530425bb815Sopenharmony_ci } 531425bb815Sopenharmony_ci case SCAN_STACK_STATEMENT_WITH_EXPR: 532425bb815Sopenharmony_ci { 533425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 534425bb815Sopenharmony_ci { 535425bb815Sopenharmony_ci break; 536425bb815Sopenharmony_ci } 537425bb815Sopenharmony_ci 538425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 539425bb815Sopenharmony_ci 540425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 541425bb815Sopenharmony_ci if (context_p->stack_top_uint8 == SCAN_STACK_IF_STATEMENT) 542425bb815Sopenharmony_ci { 543425bb815Sopenharmony_ci scanner_check_function_after_if (context_p, scanner_context_p); 544425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 545425bb815Sopenharmony_ci } 546425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 547425bb815Sopenharmony_ci 548425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 549425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 550425bb815Sopenharmony_ci } 551425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 552425bb815Sopenharmony_ci case SCAN_STACK_BINDING_LIST_INIT: 553425bb815Sopenharmony_ci { 554425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 555425bb815Sopenharmony_ci 556425bb815Sopenharmony_ci JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL 557425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL 558425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_LET 559425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_CONST 560425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START 561425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FOR_CONST_START 562425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS 563425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_ARROW_ARGUMENTS); 564425bb815Sopenharmony_ci 565425bb815Sopenharmony_ci scanner_binding_item_t *item_p = scanner_context_p->active_binding_list_p->items_p; 566425bb815Sopenharmony_ci 567425bb815Sopenharmony_ci while (item_p != NULL) 568425bb815Sopenharmony_ci { 569425bb815Sopenharmony_ci if (item_p->literal_p->type & SCANNER_LITERAL_IS_USED) 570425bb815Sopenharmony_ci { 571425bb815Sopenharmony_ci item_p->literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 572425bb815Sopenharmony_ci } 573425bb815Sopenharmony_ci item_p = item_p->next_p; 574425bb815Sopenharmony_ci } 575425bb815Sopenharmony_ci 576425bb815Sopenharmony_ci scanner_pop_binding_list (scanner_context_p); 577425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 578425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 579425bb815Sopenharmony_ci } 580425bb815Sopenharmony_ci case SCAN_STACK_BINDING_INIT: 581425bb815Sopenharmony_ci { 582425bb815Sopenharmony_ci scanner_binding_literal_t binding_literal; 583425bb815Sopenharmony_ci 584425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 585425bb815Sopenharmony_ci parser_stack_pop (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); 586425bb815Sopenharmony_ci 587425bb815Sopenharmony_ci JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL 588425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL 589425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_LET 590425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_CONST 591425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START 592425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FOR_CONST_START 593425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS 594425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_ARROW_ARGUMENTS); 595425bb815Sopenharmony_ci 596425bb815Sopenharmony_ci JERRY_ASSERT ((stack_top != SCAN_STACK_ARRAY_LITERAL && stack_top != SCAN_STACK_OBJECT_LITERAL) 597425bb815Sopenharmony_ci || SCANNER_NEEDS_BINDING_LIST (scanner_context_p->binding_type)); 598425bb815Sopenharmony_ci 599425bb815Sopenharmony_ci if (binding_literal.literal_p->type & SCANNER_LITERAL_IS_USED) 600425bb815Sopenharmony_ci { 601425bb815Sopenharmony_ci binding_literal.literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 602425bb815Sopenharmony_ci } 603425bb815Sopenharmony_ci 604425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 605425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 606425bb815Sopenharmony_ci } 607425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 608425bb815Sopenharmony_ci case SCAN_STACK_VAR: 609425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 610425bb815Sopenharmony_ci case SCAN_STACK_LET: 611425bb815Sopenharmony_ci case SCAN_STACK_CONST: 612425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 613425bb815Sopenharmony_ci { 614425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 615425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; 616425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 617425bb815Sopenharmony_ci 618425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 619425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 620425bb815Sopenharmony_ci } 621425bb815Sopenharmony_ci case SCAN_STACK_FOR_VAR_START: 622425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 623425bb815Sopenharmony_ci case SCAN_STACK_FOR_LET_START: 624425bb815Sopenharmony_ci case SCAN_STACK_FOR_CONST_START: 625425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 626425bb815Sopenharmony_ci case SCAN_STACK_FOR_START: 627425bb815Sopenharmony_ci { 628425bb815Sopenharmony_ci if (type == LEXER_KEYW_IN || SCANNER_IDENTIFIER_IS_OF ()) 629425bb815Sopenharmony_ci { 630425bb815Sopenharmony_ci scanner_for_statement_t for_statement; 631425bb815Sopenharmony_ci 632425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 633425bb815Sopenharmony_ci parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); 634425bb815Sopenharmony_ci 635425bb815Sopenharmony_ci scanner_location_info_t *location_info; 636425bb815Sopenharmony_ci location_info = (scanner_location_info_t *) scanner_insert_info (context_p, 637425bb815Sopenharmony_ci for_statement.u.source_p, 638425bb815Sopenharmony_ci sizeof (scanner_location_info_t)); 639425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 640425bb815Sopenharmony_ci location_info->info.type = (type == LEXER_KEYW_IN) ? SCANNER_TYPE_FOR_IN : SCANNER_TYPE_FOR_OF; 641425bb815Sopenharmony_ci 642425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_FOR_LET_START || stack_top == SCAN_STACK_FOR_CONST_START) 643425bb815Sopenharmony_ci { 644425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_PRIVATE_BLOCK_EARLY); 645425bb815Sopenharmony_ci } 646425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 647425bb815Sopenharmony_ci location_info->info.type = SCANNER_TYPE_FOR_IN; 648425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 649425bb815Sopenharmony_ci 650425bb815Sopenharmony_ci scanner_get_location (&location_info->location, context_p); 651425bb815Sopenharmony_ci 652425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_STATEMENT_WITH_EXPR); 653425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 654425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 655425bb815Sopenharmony_ci } 656425bb815Sopenharmony_ci 657425bb815Sopenharmony_ci if (type != LEXER_SEMICOLON) 658425bb815Sopenharmony_ci { 659425bb815Sopenharmony_ci break; 660425bb815Sopenharmony_ci } 661425bb815Sopenharmony_ci 662425bb815Sopenharmony_ci scanner_for_statement_t for_statement; 663425bb815Sopenharmony_ci 664425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 665425bb815Sopenharmony_ci parser_stack_pop (context_p, NULL, sizeof (scanner_for_statement_t)); 666425bb815Sopenharmony_ci 667425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 668425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_FOR_LET_START || stack_top == SCAN_STACK_FOR_CONST_START) 669425bb815Sopenharmony_ci { 670425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_PRIVATE_BLOCK); 671425bb815Sopenharmony_ci } 672425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 673425bb815Sopenharmony_ci 674425bb815Sopenharmony_ci for_statement.u.source_p = context_p->source_p; 675425bb815Sopenharmony_ci parser_stack_push (context_p, &for_statement, sizeof (scanner_for_statement_t)); 676425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FOR_CONDITION); 677425bb815Sopenharmony_ci 678425bb815Sopenharmony_ci lexer_next_token (context_p); 679425bb815Sopenharmony_ci 680425bb815Sopenharmony_ci if (context_p->token.type != LEXER_SEMICOLON) 681425bb815Sopenharmony_ci { 682425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 683425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 684425bb815Sopenharmony_ci } 685425bb815Sopenharmony_ci 686425bb815Sopenharmony_ci type = LEXER_SEMICOLON; 687425bb815Sopenharmony_ci /* FALLTHRU */ 688425bb815Sopenharmony_ci } 689425bb815Sopenharmony_ci case SCAN_STACK_FOR_CONDITION: 690425bb815Sopenharmony_ci { 691425bb815Sopenharmony_ci if (type != LEXER_SEMICOLON) 692425bb815Sopenharmony_ci { 693425bb815Sopenharmony_ci break; 694425bb815Sopenharmony_ci } 695425bb815Sopenharmony_ci 696425bb815Sopenharmony_ci scanner_for_statement_t for_statement; 697425bb815Sopenharmony_ci 698425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 699425bb815Sopenharmony_ci parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); 700425bb815Sopenharmony_ci 701425bb815Sopenharmony_ci scanner_for_info_t *for_info_p; 702425bb815Sopenharmony_ci for_info_p = (scanner_for_info_t *) scanner_insert_info (context_p, 703425bb815Sopenharmony_ci for_statement.u.source_p, 704425bb815Sopenharmony_ci sizeof (scanner_for_info_t)); 705425bb815Sopenharmony_ci for_info_p->info.type = SCANNER_TYPE_FOR; 706425bb815Sopenharmony_ci 707425bb815Sopenharmony_ci scanner_get_location (&for_info_p->expression_location, context_p); 708425bb815Sopenharmony_ci for_info_p->end_location.source_p = NULL; 709425bb815Sopenharmony_ci 710425bb815Sopenharmony_ci for_statement.u.for_info_p = for_info_p; 711425bb815Sopenharmony_ci 712425bb815Sopenharmony_ci parser_stack_push (context_p, &for_statement, sizeof (scanner_for_statement_t)); 713425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FOR_EXPRESSION); 714425bb815Sopenharmony_ci 715425bb815Sopenharmony_ci lexer_next_token (context_p); 716425bb815Sopenharmony_ci 717425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_PAREN) 718425bb815Sopenharmony_ci { 719425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 720425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 721425bb815Sopenharmony_ci } 722425bb815Sopenharmony_ci 723425bb815Sopenharmony_ci type = LEXER_RIGHT_PAREN; 724425bb815Sopenharmony_ci /* FALLTHRU */ 725425bb815Sopenharmony_ci } 726425bb815Sopenharmony_ci case SCAN_STACK_FOR_EXPRESSION: 727425bb815Sopenharmony_ci { 728425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 729425bb815Sopenharmony_ci { 730425bb815Sopenharmony_ci break; 731425bb815Sopenharmony_ci } 732425bb815Sopenharmony_ci 733425bb815Sopenharmony_ci scanner_for_statement_t for_statement; 734425bb815Sopenharmony_ci 735425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 736425bb815Sopenharmony_ci parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); 737425bb815Sopenharmony_ci 738425bb815Sopenharmony_ci scanner_get_location (&for_statement.u.for_info_p->end_location, context_p); 739425bb815Sopenharmony_ci 740425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 741425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 742425bb815Sopenharmony_ci } 743425bb815Sopenharmony_ci case SCAN_STACK_SWITCH_EXPRESSION: 744425bb815Sopenharmony_ci { 745425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 746425bb815Sopenharmony_ci { 747425bb815Sopenharmony_ci break; 748425bb815Sopenharmony_ci } 749425bb815Sopenharmony_ci 750425bb815Sopenharmony_ci lexer_next_token (context_p); 751425bb815Sopenharmony_ci 752425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_BRACE) 753425bb815Sopenharmony_ci { 754425bb815Sopenharmony_ci break; 755425bb815Sopenharmony_ci } 756425bb815Sopenharmony_ci 757425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 758425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p; 759425bb815Sopenharmony_ci literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK); 760425bb815Sopenharmony_ci literal_pool_p->source_p = context_p->source_p - 1; 761425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 762425bb815Sopenharmony_ci 763425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 764425bb815Sopenharmony_ci 765425bb815Sopenharmony_ci scanner_switch_statement_t switch_statement = scanner_context_p->active_switch_statement; 766425bb815Sopenharmony_ci parser_stack_push (context_p, &switch_statement, sizeof (scanner_switch_statement_t)); 767425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_SWITCH_BLOCK); 768425bb815Sopenharmony_ci 769425bb815Sopenharmony_ci scanner_switch_info_t *switch_info_p; 770425bb815Sopenharmony_ci switch_info_p = (scanner_switch_info_t *) scanner_insert_info (context_p, 771425bb815Sopenharmony_ci context_p->source_p, 772425bb815Sopenharmony_ci sizeof (scanner_switch_info_t)); 773425bb815Sopenharmony_ci switch_info_p->info.type = SCANNER_TYPE_SWITCH; 774425bb815Sopenharmony_ci switch_info_p->case_p = NULL; 775425bb815Sopenharmony_ci scanner_context_p->active_switch_statement.last_case_p = &switch_info_p->case_p; 776425bb815Sopenharmony_ci 777425bb815Sopenharmony_ci lexer_next_token (context_p); 778425bb815Sopenharmony_ci 779425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_BRACE 780425bb815Sopenharmony_ci && context_p->token.type != LEXER_KEYW_CASE 781425bb815Sopenharmony_ci && context_p->token.type != LEXER_KEYW_DEFAULT) 782425bb815Sopenharmony_ci { 783425bb815Sopenharmony_ci break; 784425bb815Sopenharmony_ci } 785425bb815Sopenharmony_ci 786425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 787425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 788425bb815Sopenharmony_ci } 789425bb815Sopenharmony_ci case SCAN_STACK_CASE_STATEMENT: 790425bb815Sopenharmony_ci { 791425bb815Sopenharmony_ci if (type != LEXER_COLON) 792425bb815Sopenharmony_ci { 793425bb815Sopenharmony_ci break; 794425bb815Sopenharmony_ci } 795425bb815Sopenharmony_ci 796425bb815Sopenharmony_ci scanner_source_start_t source_start; 797425bb815Sopenharmony_ci 798425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 799425bb815Sopenharmony_ci parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); 800425bb815Sopenharmony_ci 801425bb815Sopenharmony_ci scanner_location_info_t *location_info_p; 802425bb815Sopenharmony_ci location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, 803425bb815Sopenharmony_ci source_start.source_p, 804425bb815Sopenharmony_ci sizeof (scanner_location_info_t)); 805425bb815Sopenharmony_ci location_info_p->info.type = SCANNER_TYPE_CASE; 806425bb815Sopenharmony_ci 807425bb815Sopenharmony_ci scanner_get_location (&location_info_p->location, context_p); 808425bb815Sopenharmony_ci 809425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 810425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 811425bb815Sopenharmony_ci } 812425bb815Sopenharmony_ci case SCAN_STACK_COLON_EXPRESSION: 813425bb815Sopenharmony_ci { 814425bb815Sopenharmony_ci if (type != LEXER_COLON) 815425bb815Sopenharmony_ci { 816425bb815Sopenharmony_ci break; 817425bb815Sopenharmony_ci } 818425bb815Sopenharmony_ci 819425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 820425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 821425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 822425bb815Sopenharmony_ci } 823425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 824425bb815Sopenharmony_ci case SCAN_STACK_ARRAY_LITERAL: 825425bb815Sopenharmony_ci case SCAN_STACK_OBJECT_LITERAL: 826425bb815Sopenharmony_ci { 827425bb815Sopenharmony_ci if (((stack_top == SCAN_STACK_ARRAY_LITERAL) && (type != LEXER_RIGHT_SQUARE)) 828425bb815Sopenharmony_ci || ((stack_top == SCAN_STACK_OBJECT_LITERAL) && (type != LEXER_RIGHT_BRACE))) 829425bb815Sopenharmony_ci { 830425bb815Sopenharmony_ci break; 831425bb815Sopenharmony_ci } 832425bb815Sopenharmony_ci 833425bb815Sopenharmony_ci scanner_source_start_t source_start; 834425bb815Sopenharmony_ci uint8_t binding_type = scanner_context_p->binding_type; 835425bb815Sopenharmony_ci 836425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 837425bb815Sopenharmony_ci scanner_context_p->binding_type = context_p->stack_top_uint8; 838425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 839425bb815Sopenharmony_ci parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); 840425bb815Sopenharmony_ci 841425bb815Sopenharmony_ci lexer_next_token (context_p); 842425bb815Sopenharmony_ci 843425bb815Sopenharmony_ci if (binding_type == SCANNER_BINDING_CATCH && context_p->stack_top_uint8 == SCAN_STACK_CATCH_STATEMENT) 844425bb815Sopenharmony_ci { 845425bb815Sopenharmony_ci scanner_pop_binding_list (scanner_context_p); 846425bb815Sopenharmony_ci 847425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_PAREN) 848425bb815Sopenharmony_ci { 849425bb815Sopenharmony_ci scanner_raise_error (context_p); 850425bb815Sopenharmony_ci } 851425bb815Sopenharmony_ci 852425bb815Sopenharmony_ci lexer_next_token (context_p); 853425bb815Sopenharmony_ci 854425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_BRACE) 855425bb815Sopenharmony_ci { 856425bb815Sopenharmony_ci scanner_raise_error (context_p); 857425bb815Sopenharmony_ci } 858425bb815Sopenharmony_ci 859425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 860425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 861425bb815Sopenharmony_ci } 862425bb815Sopenharmony_ci 863425bb815Sopenharmony_ci if (context_p->token.type != LEXER_ASSIGN) 864425bb815Sopenharmony_ci { 865425bb815Sopenharmony_ci if (SCANNER_NEEDS_BINDING_LIST (binding_type)) 866425bb815Sopenharmony_ci { 867425bb815Sopenharmony_ci scanner_pop_binding_list (scanner_context_p); 868425bb815Sopenharmony_ci } 869425bb815Sopenharmony_ci 870425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 871425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 872425bb815Sopenharmony_ci } 873425bb815Sopenharmony_ci 874425bb815Sopenharmony_ci scanner_location_info_t *location_info_p; 875425bb815Sopenharmony_ci location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, 876425bb815Sopenharmony_ci source_start.source_p, 877425bb815Sopenharmony_ci sizeof (scanner_location_info_t)); 878425bb815Sopenharmony_ci location_info_p->info.type = SCANNER_TYPE_INITIALIZER; 879425bb815Sopenharmony_ci scanner_get_location (&location_info_p->location, context_p); 880425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 881425bb815Sopenharmony_ci 882425bb815Sopenharmony_ci if (SCANNER_NEEDS_BINDING_LIST (binding_type)) 883425bb815Sopenharmony_ci { 884425bb815Sopenharmony_ci scanner_binding_item_t *item_p = scanner_context_p->active_binding_list_p->items_p; 885425bb815Sopenharmony_ci 886425bb815Sopenharmony_ci while (item_p != NULL) 887425bb815Sopenharmony_ci { 888425bb815Sopenharmony_ci item_p->literal_p->type &= (uint8_t) ~SCANNER_LITERAL_IS_USED; 889425bb815Sopenharmony_ci item_p = item_p->next_p; 890425bb815Sopenharmony_ci } 891425bb815Sopenharmony_ci 892425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_LIST_INIT); 893425bb815Sopenharmony_ci } 894425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 895425bb815Sopenharmony_ci } 896425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 897425bb815Sopenharmony_ci case SCAN_STACK_ARRAY_LITERAL: 898425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 899425bb815Sopenharmony_ci case SCAN_STACK_PROPERTY_ACCESSOR: 900425bb815Sopenharmony_ci { 901425bb815Sopenharmony_ci if (type != LEXER_RIGHT_SQUARE) 902425bb815Sopenharmony_ci { 903425bb815Sopenharmony_ci break; 904425bb815Sopenharmony_ci } 905425bb815Sopenharmony_ci 906425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 907425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 908425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 909425bb815Sopenharmony_ci } 910425bb815Sopenharmony_ci#if !ENABLED (JERRY_ES2015) 911425bb815Sopenharmony_ci case SCAN_STACK_OBJECT_LITERAL: 912425bb815Sopenharmony_ci { 913425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 914425bb815Sopenharmony_ci { 915425bb815Sopenharmony_ci break; 916425bb815Sopenharmony_ci } 917425bb815Sopenharmony_ci 918425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 919425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 920425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 921425bb815Sopenharmony_ci } 922425bb815Sopenharmony_ci#endif /* !ENABLED (JERRY_ES2015) */ 923425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 924425bb815Sopenharmony_ci case SCAN_STACK_COMPUTED_PROPERTY: 925425bb815Sopenharmony_ci { 926425bb815Sopenharmony_ci if (type != LEXER_RIGHT_SQUARE) 927425bb815Sopenharmony_ci { 928425bb815Sopenharmony_ci break; 929425bb815Sopenharmony_ci } 930425bb815Sopenharmony_ci 931425bb815Sopenharmony_ci lexer_next_token (context_p); 932425bb815Sopenharmony_ci 933425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 934425bb815Sopenharmony_ci stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; 935425bb815Sopenharmony_ci 936425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_FUNCTION_PROPERTY) 937425bb815Sopenharmony_ci { 938425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION); 939425bb815Sopenharmony_ci 940425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; 941425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 942425bb815Sopenharmony_ci } 943425bb815Sopenharmony_ci 944425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL); 945425bb815Sopenharmony_ci 946425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_PAREN) 947425bb815Sopenharmony_ci { 948425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION); 949425bb815Sopenharmony_ci 950425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); 951425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; 952425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 953425bb815Sopenharmony_ci } 954425bb815Sopenharmony_ci 955425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COLON) 956425bb815Sopenharmony_ci { 957425bb815Sopenharmony_ci scanner_raise_error (context_p); 958425bb815Sopenharmony_ci } 959425bb815Sopenharmony_ci 960425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 961425bb815Sopenharmony_ci 962425bb815Sopenharmony_ci if (scanner_context_p->binding_type != SCANNER_BINDING_NONE) 963425bb815Sopenharmony_ci { 964425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_BINDING; 965425bb815Sopenharmony_ci } 966425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 967425bb815Sopenharmony_ci } 968425bb815Sopenharmony_ci case SCAN_STACK_COMPUTED_GENERATOR: 969425bb815Sopenharmony_ci case SCAN_STACK_COMPUTED_ASYNC: 970425bb815Sopenharmony_ci case SCAN_STACK_COMPUTED_ASYNC_GENERATOR: 971425bb815Sopenharmony_ci { 972425bb815Sopenharmony_ci if (type != LEXER_RIGHT_SQUARE) 973425bb815Sopenharmony_ci { 974425bb815Sopenharmony_ci break; 975425bb815Sopenharmony_ci } 976425bb815Sopenharmony_ci 977425bb815Sopenharmony_ci lexer_next_token (context_p); 978425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 979425bb815Sopenharmony_ci 980425bb815Sopenharmony_ci JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL 981425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PROPERTY); 982425bb815Sopenharmony_ci 983425bb815Sopenharmony_ci uint16_t status_flags = (uint16_t) (SCANNER_LITERAL_POOL_FUNCTION 984425bb815Sopenharmony_ci | SCANNER_LITERAL_POOL_GENERATOR 985425bb815Sopenharmony_ci | SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (stack_top)); 986425bb815Sopenharmony_ci 987425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, scanner_context_p, status_flags); 988425bb815Sopenharmony_ci 989425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; 990425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 991425bb815Sopenharmony_ci } 992425bb815Sopenharmony_ci case SCAN_STACK_TEMPLATE_STRING: 993425bb815Sopenharmony_ci case SCAN_STACK_TAGGED_TEMPLATE_LITERAL: 994425bb815Sopenharmony_ci { 995425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 996425bb815Sopenharmony_ci { 997425bb815Sopenharmony_ci break; 998425bb815Sopenharmony_ci } 999425bb815Sopenharmony_ci 1000425bb815Sopenharmony_ci context_p->source_p--; 1001425bb815Sopenharmony_ci context_p->column--; 1002425bb815Sopenharmony_ci lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); 1003425bb815Sopenharmony_ci 1004425bb815Sopenharmony_ci if (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) 1005425bb815Sopenharmony_ci { 1006425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1007425bb815Sopenharmony_ci } 1008425bb815Sopenharmony_ci else 1009425bb815Sopenharmony_ci { 1010425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1011425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 1012425bb815Sopenharmony_ci } 1013425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1014425bb815Sopenharmony_ci } 1015425bb815Sopenharmony_ci case SCAN_STACK_ARROW_ARGUMENTS: 1016425bb815Sopenharmony_ci { 1017425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN) 1018425bb815Sopenharmony_ci { 1019425bb815Sopenharmony_ci break; 1020425bb815Sopenharmony_ci } 1021425bb815Sopenharmony_ci 1022425bb815Sopenharmony_ci scanner_check_arrow (context_p, scanner_context_p); 1023425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1024425bb815Sopenharmony_ci } 1025425bb815Sopenharmony_ci case SCAN_STACK_ARROW_EXPRESSION: 1026425bb815Sopenharmony_ci { 1027425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 1028425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1029425bb815Sopenharmony_ci lexer_update_await_yield (context_p, context_p->status_flags); 1030425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 1031425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1032425bb815Sopenharmony_ci } 1033425bb815Sopenharmony_ci case SCAN_STACK_CLASS_EXTENDS: 1034425bb815Sopenharmony_ci { 1035425bb815Sopenharmony_ci if (type != LEXER_LEFT_BRACE) 1036425bb815Sopenharmony_ci { 1037425bb815Sopenharmony_ci break; 1038425bb815Sopenharmony_ci } 1039425bb815Sopenharmony_ci 1040425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_CLASS_METHOD; 1041425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1042425bb815Sopenharmony_ci 1043425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1044425bb815Sopenharmony_ci } 1045425bb815Sopenharmony_ci case SCAN_STACK_FUNCTION_PARAMETERS: 1046425bb815Sopenharmony_ci { 1047425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1048425bb815Sopenharmony_ci 1049425bb815Sopenharmony_ci if (type != LEXER_RIGHT_PAREN 1050425bb815Sopenharmony_ci && (type != LEXER_EOS || context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION)) 1051425bb815Sopenharmony_ci { 1052425bb815Sopenharmony_ci break; 1053425bb815Sopenharmony_ci } 1054425bb815Sopenharmony_ci 1055425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS; 1056425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1057425bb815Sopenharmony_ci } 1058425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1059425bb815Sopenharmony_ci default: 1060425bb815Sopenharmony_ci { 1061425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1062425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1063425bb815Sopenharmony_ci } 1064425bb815Sopenharmony_ci } 1065425bb815Sopenharmony_ci 1066425bb815Sopenharmony_ci scanner_raise_error (context_p); 1067425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1068425bb815Sopenharmony_ci} /* scanner_scan_primary_expression_end */ 1069425bb815Sopenharmony_ci 1070425bb815Sopenharmony_ci/** 1071425bb815Sopenharmony_ci * Scan statements. 1072425bb815Sopenharmony_ci * 1073425bb815Sopenharmony_ci * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing 1074425bb815Sopenharmony_ci */ 1075425bb815Sopenharmony_cistatic scan_return_types_t 1076425bb815Sopenharmony_ciscanner_scan_statement (parser_context_t *context_p, /**< context */ 1077425bb815Sopenharmony_ci scanner_context_t *scanner_context_p, /**< scanner context */ 1078425bb815Sopenharmony_ci lexer_token_type_t type, /**< current token type */ 1079425bb815Sopenharmony_ci scan_stack_modes_t stack_top) /**< current stack top */ 1080425bb815Sopenharmony_ci{ 1081425bb815Sopenharmony_ci switch (type) 1082425bb815Sopenharmony_ci { 1083425bb815Sopenharmony_ci case LEXER_SEMICOLON: 1084425bb815Sopenharmony_ci { 1085425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1086425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1087425bb815Sopenharmony_ci } 1088425bb815Sopenharmony_ci case LEXER_LEFT_BRACE: 1089425bb815Sopenharmony_ci { 1090425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1091425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p; 1092425bb815Sopenharmony_ci literal_pool_p = scanner_push_literal_pool (context_p, 1093425bb815Sopenharmony_ci scanner_context_p, 1094425bb815Sopenharmony_ci SCANNER_LITERAL_POOL_BLOCK); 1095425bb815Sopenharmony_ci literal_pool_p->source_p = context_p->source_p; 1096425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1097425bb815Sopenharmony_ci 1098425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 1099425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT); 1100425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1101425bb815Sopenharmony_ci } 1102425bb815Sopenharmony_ci case LEXER_KEYW_DO: 1103425bb815Sopenharmony_ci { 1104425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 1105425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_DO_STATEMENT); 1106425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1107425bb815Sopenharmony_ci } 1108425bb815Sopenharmony_ci case LEXER_KEYW_TRY: 1109425bb815Sopenharmony_ci { 1110425bb815Sopenharmony_ci lexer_next_token (context_p); 1111425bb815Sopenharmony_ci 1112425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_BRACE) 1113425bb815Sopenharmony_ci { 1114425bb815Sopenharmony_ci scanner_raise_error (context_p); 1115425bb815Sopenharmony_ci } 1116425bb815Sopenharmony_ci 1117425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1118425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p; 1119425bb815Sopenharmony_ci literal_pool_p = scanner_push_literal_pool (context_p, 1120425bb815Sopenharmony_ci scanner_context_p, 1121425bb815Sopenharmony_ci SCANNER_LITERAL_POOL_BLOCK); 1122425bb815Sopenharmony_ci literal_pool_p->source_p = context_p->source_p; 1123425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1124425bb815Sopenharmony_ci 1125425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 1126425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_TRY_STATEMENT); 1127425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1128425bb815Sopenharmony_ci } 1129425bb815Sopenharmony_ci case LEXER_KEYW_DEBUGGER: 1130425bb815Sopenharmony_ci { 1131425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1132425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1133425bb815Sopenharmony_ci } 1134425bb815Sopenharmony_ci case LEXER_KEYW_IF: 1135425bb815Sopenharmony_ci case LEXER_KEYW_WITH: 1136425bb815Sopenharmony_ci case LEXER_KEYW_SWITCH: 1137425bb815Sopenharmony_ci { 1138425bb815Sopenharmony_ci lexer_next_token (context_p); 1139425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_PAREN) 1140425bb815Sopenharmony_ci { 1141425bb815Sopenharmony_ci scanner_raise_error (context_p); 1142425bb815Sopenharmony_ci } 1143425bb815Sopenharmony_ci 1144425bb815Sopenharmony_ci uint8_t mode = SCAN_STACK_STATEMENT_WITH_EXPR; 1145425bb815Sopenharmony_ci 1146425bb815Sopenharmony_ci if (type == LEXER_KEYW_IF) 1147425bb815Sopenharmony_ci { 1148425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_IF_STATEMENT); 1149425bb815Sopenharmony_ci } 1150425bb815Sopenharmony_ci else if (type == LEXER_KEYW_WITH) 1151425bb815Sopenharmony_ci { 1152425bb815Sopenharmony_ci mode = SCAN_STACK_WITH_EXPRESSION; 1153425bb815Sopenharmony_ci } 1154425bb815Sopenharmony_ci else if (type == LEXER_KEYW_SWITCH) 1155425bb815Sopenharmony_ci { 1156425bb815Sopenharmony_ci mode = SCAN_STACK_SWITCH_EXPRESSION; 1157425bb815Sopenharmony_ci } 1158425bb815Sopenharmony_ci 1159425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1160425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, mode); 1161425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1162425bb815Sopenharmony_ci } 1163425bb815Sopenharmony_ci case LEXER_KEYW_WHILE: 1164425bb815Sopenharmony_ci { 1165425bb815Sopenharmony_ci lexer_next_token (context_p); 1166425bb815Sopenharmony_ci 1167425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_PAREN) 1168425bb815Sopenharmony_ci { 1169425bb815Sopenharmony_ci scanner_raise_error (context_p); 1170425bb815Sopenharmony_ci } 1171425bb815Sopenharmony_ci 1172425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1173425bb815Sopenharmony_ci 1174425bb815Sopenharmony_ci scanner_source_start_t source_start; 1175425bb815Sopenharmony_ci source_start.source_p = context_p->source_p; 1176425bb815Sopenharmony_ci 1177425bb815Sopenharmony_ci parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t)); 1178425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_WHILE_EXPRESSION); 1179425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1180425bb815Sopenharmony_ci } 1181425bb815Sopenharmony_ci case LEXER_KEYW_FOR: 1182425bb815Sopenharmony_ci { 1183425bb815Sopenharmony_ci lexer_next_token (context_p); 1184425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_PAREN) 1185425bb815Sopenharmony_ci { 1186425bb815Sopenharmony_ci scanner_raise_error (context_p); 1187425bb815Sopenharmony_ci } 1188425bb815Sopenharmony_ci 1189425bb815Sopenharmony_ci scanner_for_statement_t for_statement; 1190425bb815Sopenharmony_ci for_statement.u.source_p = context_p->source_p; 1191425bb815Sopenharmony_ci uint8_t stack_mode = SCAN_STACK_FOR_START; 1192425bb815Sopenharmony_ci scan_return_types_t return_type = SCAN_KEEP_TOKEN; 1193425bb815Sopenharmony_ci 1194425bb815Sopenharmony_ci lexer_next_token (context_p); 1195425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1196425bb815Sopenharmony_ci 1197425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1198425bb815Sopenharmony_ci const uint8_t *source_p = context_p->source_p; 1199425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1200425bb815Sopenharmony_ci 1201425bb815Sopenharmony_ci switch (context_p->token.type) 1202425bb815Sopenharmony_ci { 1203425bb815Sopenharmony_ci case LEXER_SEMICOLON: 1204425bb815Sopenharmony_ci { 1205425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 1206425bb815Sopenharmony_ci break; 1207425bb815Sopenharmony_ci } 1208425bb815Sopenharmony_ci case LEXER_KEYW_VAR: 1209425bb815Sopenharmony_ci { 1210425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1211425bb815Sopenharmony_ci stack_mode = SCAN_STACK_FOR_VAR_START; 1212425bb815Sopenharmony_ci return_type = SCAN_NEXT_TOKEN; 1213425bb815Sopenharmony_ci break; 1214425bb815Sopenharmony_ci } 1215425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1216425bb815Sopenharmony_ci case LEXER_LITERAL: 1217425bb815Sopenharmony_ci { 1218425bb815Sopenharmony_ci if (!lexer_token_is_let (context_p)) 1219425bb815Sopenharmony_ci { 1220425bb815Sopenharmony_ci break; 1221425bb815Sopenharmony_ci } 1222425bb815Sopenharmony_ci 1223425bb815Sopenharmony_ci parser_line_counter_t line = context_p->line; 1224425bb815Sopenharmony_ci parser_line_counter_t column = context_p->column; 1225425bb815Sopenharmony_ci 1226425bb815Sopenharmony_ci if (lexer_check_arrow (context_p)) 1227425bb815Sopenharmony_ci { 1228425bb815Sopenharmony_ci context_p->source_p = source_p; 1229425bb815Sopenharmony_ci context_p->line = line; 1230425bb815Sopenharmony_ci context_p->column = column; 1231425bb815Sopenharmony_ci context_p->token.flags &= (uint8_t) ~LEXER_NO_SKIP_SPACES; 1232425bb815Sopenharmony_ci break; 1233425bb815Sopenharmony_ci } 1234425bb815Sopenharmony_ci 1235425bb815Sopenharmony_ci lexer_next_token (context_p); 1236425bb815Sopenharmony_ci 1237425bb815Sopenharmony_ci type = (lexer_token_type_t) context_p->token.type; 1238425bb815Sopenharmony_ci 1239425bb815Sopenharmony_ci if (type != LEXER_LEFT_SQUARE 1240425bb815Sopenharmony_ci && type != LEXER_LEFT_BRACE 1241425bb815Sopenharmony_ci && (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)) 1242425bb815Sopenharmony_ci { 1243425bb815Sopenharmony_ci scanner_info_t *info_p = scanner_insert_info (context_p, source_p, sizeof (scanner_info_t)); 1244425bb815Sopenharmony_ci info_p->type = SCANNER_TYPE_LET_EXPRESSION; 1245425bb815Sopenharmony_ci 1246425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 1247425bb815Sopenharmony_ci break; 1248425bb815Sopenharmony_ci } 1249425bb815Sopenharmony_ci 1250425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1251425bb815Sopenharmony_ci /* FALLTHRU */ 1252425bb815Sopenharmony_ci } 1253425bb815Sopenharmony_ci case LEXER_KEYW_LET: 1254425bb815Sopenharmony_ci case LEXER_KEYW_CONST: 1255425bb815Sopenharmony_ci { 1256425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p; 1257425bb815Sopenharmony_ci literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK); 1258425bb815Sopenharmony_ci literal_pool_p->source_p = source_p; 1259425bb815Sopenharmony_ci 1260425bb815Sopenharmony_ci if (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION) 1261425bb815Sopenharmony_ci { 1262425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1263425bb815Sopenharmony_ci return_type = SCAN_NEXT_TOKEN; 1264425bb815Sopenharmony_ci } 1265425bb815Sopenharmony_ci 1266425bb815Sopenharmony_ci stack_mode = ((context_p->token.type == LEXER_KEYW_CONST) ? SCAN_STACK_FOR_CONST_START 1267425bb815Sopenharmony_ci : SCAN_STACK_FOR_LET_START); 1268425bb815Sopenharmony_ci break; 1269425bb815Sopenharmony_ci } 1270425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1271425bb815Sopenharmony_ci } 1272425bb815Sopenharmony_ci 1273425bb815Sopenharmony_ci parser_stack_push (context_p, &for_statement, sizeof (scanner_for_statement_t)); 1274425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, stack_mode); 1275425bb815Sopenharmony_ci return return_type; 1276425bb815Sopenharmony_ci } 1277425bb815Sopenharmony_ci case LEXER_KEYW_VAR: 1278425bb815Sopenharmony_ci { 1279425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1280425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_VAR); 1281425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1282425bb815Sopenharmony_ci } 1283425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1284425bb815Sopenharmony_ci case LEXER_KEYW_LET: 1285425bb815Sopenharmony_ci { 1286425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1287425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_LET); 1288425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1289425bb815Sopenharmony_ci } 1290425bb815Sopenharmony_ci case LEXER_KEYW_CONST: 1291425bb815Sopenharmony_ci { 1292425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1293425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_CONST); 1294425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1295425bb815Sopenharmony_ci } 1296425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1297425bb815Sopenharmony_ci case LEXER_KEYW_THROW: 1298425bb815Sopenharmony_ci { 1299425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1300425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1301425bb815Sopenharmony_ci } 1302425bb815Sopenharmony_ci case LEXER_KEYW_RETURN: 1303425bb815Sopenharmony_ci { 1304425bb815Sopenharmony_ci lexer_next_token (context_p); 1305425bb815Sopenharmony_ci 1306425bb815Sopenharmony_ci if (!(context_p->token.flags & LEXER_WAS_NEWLINE) 1307425bb815Sopenharmony_ci && context_p->token.type != LEXER_SEMICOLON 1308425bb815Sopenharmony_ci && context_p->token.type != LEXER_EOS 1309425bb815Sopenharmony_ci && context_p->token.type != LEXER_RIGHT_BRACE) 1310425bb815Sopenharmony_ci { 1311425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1312425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1313425bb815Sopenharmony_ci } 1314425bb815Sopenharmony_ci 1315425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1316425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1317425bb815Sopenharmony_ci } 1318425bb815Sopenharmony_ci case LEXER_KEYW_BREAK: 1319425bb815Sopenharmony_ci case LEXER_KEYW_CONTINUE: 1320425bb815Sopenharmony_ci { 1321425bb815Sopenharmony_ci lexer_next_token (context_p); 1322425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1323425bb815Sopenharmony_ci 1324425bb815Sopenharmony_ci if (!(context_p->token.flags & LEXER_WAS_NEWLINE) 1325425bb815Sopenharmony_ci && context_p->token.type == LEXER_LITERAL 1326425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1327425bb815Sopenharmony_ci { 1328425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1329425bb815Sopenharmony_ci } 1330425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1331425bb815Sopenharmony_ci } 1332425bb815Sopenharmony_ci case LEXER_KEYW_CASE: 1333425bb815Sopenharmony_ci case LEXER_KEYW_DEFAULT: 1334425bb815Sopenharmony_ci { 1335425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_SWITCH_BLOCK) 1336425bb815Sopenharmony_ci { 1337425bb815Sopenharmony_ci scanner_raise_error (context_p); 1338425bb815Sopenharmony_ci } 1339425bb815Sopenharmony_ci 1340425bb815Sopenharmony_ci scanner_case_info_t *case_info_p; 1341425bb815Sopenharmony_ci case_info_p = (scanner_case_info_t *) scanner_malloc (context_p, sizeof (scanner_case_info_t)); 1342425bb815Sopenharmony_ci 1343425bb815Sopenharmony_ci *(scanner_context_p->active_switch_statement.last_case_p) = case_info_p; 1344425bb815Sopenharmony_ci scanner_context_p->active_switch_statement.last_case_p = &case_info_p->next_p; 1345425bb815Sopenharmony_ci 1346425bb815Sopenharmony_ci case_info_p->next_p = NULL; 1347425bb815Sopenharmony_ci scanner_get_location (&case_info_p->location, context_p); 1348425bb815Sopenharmony_ci 1349425bb815Sopenharmony_ci if (type == LEXER_KEYW_DEFAULT) 1350425bb815Sopenharmony_ci { 1351425bb815Sopenharmony_ci lexer_next_token (context_p); 1352425bb815Sopenharmony_ci 1353425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COLON) 1354425bb815Sopenharmony_ci { 1355425bb815Sopenharmony_ci scanner_raise_error (context_p); 1356425bb815Sopenharmony_ci } 1357425bb815Sopenharmony_ci 1358425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 1359425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1360425bb815Sopenharmony_ci } 1361425bb815Sopenharmony_ci 1362425bb815Sopenharmony_ci scanner_source_start_t source_start; 1363425bb815Sopenharmony_ci source_start.source_p = context_p->source_p; 1364425bb815Sopenharmony_ci 1365425bb815Sopenharmony_ci parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t)); 1366425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_CASE_STATEMENT); 1367425bb815Sopenharmony_ci 1368425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1369425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1370425bb815Sopenharmony_ci } 1371425bb815Sopenharmony_ci case LEXER_KEYW_FUNCTION: 1372425bb815Sopenharmony_ci { 1373425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1374425bb815Sopenharmony_ci uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_FUNCTION_STATEMENT; 1375425bb815Sopenharmony_ci 1376425bb815Sopenharmony_ci if (scanner_context_p->async_source_p != NULL) 1377425bb815Sopenharmony_ci { 1378425bb815Sopenharmony_ci scanner_context_p->status_flags |= SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION; 1379425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_ASYNC; 1380425bb815Sopenharmony_ci } 1381425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1382425bb815Sopenharmony_ci 1383425bb815Sopenharmony_ci lexer_next_token (context_p); 1384425bb815Sopenharmony_ci 1385425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1386425bb815Sopenharmony_ci if (context_p->token.type == LEXER_MULTIPLY) 1387425bb815Sopenharmony_ci { 1388425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_GENERATOR; 1389425bb815Sopenharmony_ci lexer_next_token (context_p); 1390425bb815Sopenharmony_ci } 1391425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1392425bb815Sopenharmony_ci 1393425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1394425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 1395425bb815Sopenharmony_ci { 1396425bb815Sopenharmony_ci scanner_raise_error (context_p); 1397425bb815Sopenharmony_ci } 1398425bb815Sopenharmony_ci 1399425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); 1400425bb815Sopenharmony_ci 1401425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1402425bb815Sopenharmony_ci const uint8_t mask = (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LOCAL); 1403425bb815Sopenharmony_ci 1404425bb815Sopenharmony_ci if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) 1405425bb815Sopenharmony_ci && (literal_p->type & mask) != (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG) 1406425bb815Sopenharmony_ci && (literal_p->type & mask) != (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION)) 1407425bb815Sopenharmony_ci { 1408425bb815Sopenharmony_ci scanner_raise_redeclaration_error (context_p); 1409425bb815Sopenharmony_ci } 1410425bb815Sopenharmony_ci 1411425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION; 1412425bb815Sopenharmony_ci 1413425bb815Sopenharmony_ci scanner_context_p->status_flags &= (uint16_t) ~SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION; 1414425bb815Sopenharmony_ci#else 1415425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC; 1416425bb815Sopenharmony_ci 1417425bb815Sopenharmony_ci uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; 1418425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1419425bb815Sopenharmony_ci 1420425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, scanner_context_p, status_flags); 1421425bb815Sopenharmony_ci 1422425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; 1423425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_STATEMENT); 1424425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1425425bb815Sopenharmony_ci } 1426425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1427425bb815Sopenharmony_ci case LEXER_KEYW_CLASS: 1428425bb815Sopenharmony_ci { 1429425bb815Sopenharmony_ci scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT); 1430425bb815Sopenharmony_ci 1431425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 1432425bb815Sopenharmony_ci { 1433425bb815Sopenharmony_ci scanner_raise_error (context_p); 1434425bb815Sopenharmony_ci } 1435425bb815Sopenharmony_ci 1436425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); 1437425bb815Sopenharmony_ci 1438425bb815Sopenharmony_ci scanner_detect_invalid_let (context_p, literal_p); 1439425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LET; 1440425bb815Sopenharmony_ci 1441425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 1442425bb815Sopenharmony_ci if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT) 1443425bb815Sopenharmony_ci { 1444425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_NO_REG; 1445425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; 1446425bb815Sopenharmony_ci } 1447425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 1448425bb815Sopenharmony_ci 1449425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1450425bb815Sopenharmony_ci } 1451425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1452425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 1453425bb815Sopenharmony_ci case LEXER_KEYW_IMPORT: 1454425bb815Sopenharmony_ci { 1455425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_SCRIPT) 1456425bb815Sopenharmony_ci { 1457425bb815Sopenharmony_ci scanner_raise_error (context_p); 1458425bb815Sopenharmony_ci } 1459425bb815Sopenharmony_ci 1460425bb815Sopenharmony_ci context_p->global_status_flags |= ECMA_PARSE_MODULE; 1461425bb815Sopenharmony_ci 1462425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1463425bb815Sopenharmony_ci lexer_next_token (context_p); 1464425bb815Sopenharmony_ci 1465425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LITERAL 1466425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_STRING_LITERAL) 1467425bb815Sopenharmony_ci { 1468425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1469425bb815Sopenharmony_ci } 1470425bb815Sopenharmony_ci 1471425bb815Sopenharmony_ci bool parse_imports = true; 1472425bb815Sopenharmony_ci 1473425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LITERAL 1474425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1475425bb815Sopenharmony_ci { 1476425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); 1477425bb815Sopenharmony_ci 1478425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1479425bb815Sopenharmony_ci scanner_detect_invalid_let (context_p, literal_p); 1480425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_NO_REG; 1481425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 1482425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_NO_REG; 1483425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1484425bb815Sopenharmony_ci 1485425bb815Sopenharmony_ci lexer_next_token (context_p); 1486425bb815Sopenharmony_ci 1487425bb815Sopenharmony_ci if (context_p->token.type == LEXER_COMMA) 1488425bb815Sopenharmony_ci { 1489425bb815Sopenharmony_ci lexer_next_token (context_p); 1490425bb815Sopenharmony_ci } 1491425bb815Sopenharmony_ci else 1492425bb815Sopenharmony_ci { 1493425bb815Sopenharmony_ci parse_imports = false; 1494425bb815Sopenharmony_ci } 1495425bb815Sopenharmony_ci } 1496425bb815Sopenharmony_ci 1497425bb815Sopenharmony_ci if (parse_imports) 1498425bb815Sopenharmony_ci { 1499425bb815Sopenharmony_ci if (context_p->token.type == LEXER_MULTIPLY) 1500425bb815Sopenharmony_ci { 1501425bb815Sopenharmony_ci lexer_next_token (context_p); 1502425bb815Sopenharmony_ci if (!lexer_token_is_identifier (context_p, "as", 2)) 1503425bb815Sopenharmony_ci { 1504425bb815Sopenharmony_ci scanner_raise_error (context_p); 1505425bb815Sopenharmony_ci } 1506425bb815Sopenharmony_ci 1507425bb815Sopenharmony_ci lexer_next_token (context_p); 1508425bb815Sopenharmony_ci 1509425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1510425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1511425bb815Sopenharmony_ci { 1512425bb815Sopenharmony_ci scanner_raise_error (context_p); 1513425bb815Sopenharmony_ci } 1514425bb815Sopenharmony_ci 1515425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); 1516425bb815Sopenharmony_ci 1517425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1518425bb815Sopenharmony_ci scanner_detect_invalid_let (context_p, literal_p); 1519425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_NO_REG; 1520425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 1521425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_NO_REG; 1522425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1523425bb815Sopenharmony_ci 1524425bb815Sopenharmony_ci lexer_next_token (context_p); 1525425bb815Sopenharmony_ci } 1526425bb815Sopenharmony_ci else if (context_p->token.type == LEXER_LEFT_BRACE) 1527425bb815Sopenharmony_ci { 1528425bb815Sopenharmony_ci lexer_next_token (context_p); 1529425bb815Sopenharmony_ci 1530425bb815Sopenharmony_ci while (context_p->token.type != LEXER_RIGHT_BRACE) 1531425bb815Sopenharmony_ci { 1532425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1533425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 1534425bb815Sopenharmony_ci { 1535425bb815Sopenharmony_ci scanner_raise_error (context_p); 1536425bb815Sopenharmony_ci } 1537425bb815Sopenharmony_ci 1538425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1539425bb815Sopenharmony_ci const uint8_t *source_p = context_p->source_p; 1540425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1541425bb815Sopenharmony_ci 1542425bb815Sopenharmony_ci if (lexer_check_next_character (context_p, LIT_CHAR_LOWERCASE_A)) 1543425bb815Sopenharmony_ci { 1544425bb815Sopenharmony_ci lexer_next_token (context_p); 1545425bb815Sopenharmony_ci 1546425bb815Sopenharmony_ci if (!lexer_token_is_identifier (context_p, "as", 2)) 1547425bb815Sopenharmony_ci { 1548425bb815Sopenharmony_ci scanner_raise_error (context_p); 1549425bb815Sopenharmony_ci } 1550425bb815Sopenharmony_ci 1551425bb815Sopenharmony_ci lexer_next_token (context_p); 1552425bb815Sopenharmony_ci 1553425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1554425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1555425bb815Sopenharmony_ci { 1556425bb815Sopenharmony_ci scanner_raise_error (context_p); 1557425bb815Sopenharmony_ci } 1558425bb815Sopenharmony_ci 1559425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1560425bb815Sopenharmony_ci source_p = context_p->source_p; 1561425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1562425bb815Sopenharmony_ci } 1563425bb815Sopenharmony_ci 1564425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); 1565425bb815Sopenharmony_ci 1566425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1567425bb815Sopenharmony_ci if (literal_p->type & (SCANNER_LITERAL_IS_ARG 1568425bb815Sopenharmony_ci | SCANNER_LITERAL_IS_VAR 1569425bb815Sopenharmony_ci | SCANNER_LITERAL_IS_LOCAL)) 1570425bb815Sopenharmony_ci { 1571425bb815Sopenharmony_ci context_p->source_p = source_p; 1572425bb815Sopenharmony_ci scanner_raise_redeclaration_error (context_p); 1573425bb815Sopenharmony_ci } 1574425bb815Sopenharmony_ci 1575425bb815Sopenharmony_ci if (literal_p->type & SCANNER_LITERAL_IS_FUNC) 1576425bb815Sopenharmony_ci { 1577425bb815Sopenharmony_ci literal_p->type &= (uint8_t) ~SCANNER_LITERAL_IS_FUNC; 1578425bb815Sopenharmony_ci } 1579425bb815Sopenharmony_ci 1580425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_NO_REG; 1581425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 1582425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_NO_REG; 1583425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1584425bb815Sopenharmony_ci 1585425bb815Sopenharmony_ci lexer_next_token (context_p); 1586425bb815Sopenharmony_ci 1587425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_BRACE) 1588425bb815Sopenharmony_ci { 1589425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COMMA) 1590425bb815Sopenharmony_ci { 1591425bb815Sopenharmony_ci scanner_raise_error (context_p); 1592425bb815Sopenharmony_ci } 1593425bb815Sopenharmony_ci 1594425bb815Sopenharmony_ci lexer_next_token (context_p); 1595425bb815Sopenharmony_ci } 1596425bb815Sopenharmony_ci } 1597425bb815Sopenharmony_ci 1598425bb815Sopenharmony_ci lexer_next_token (context_p); 1599425bb815Sopenharmony_ci } 1600425bb815Sopenharmony_ci else 1601425bb815Sopenharmony_ci { 1602425bb815Sopenharmony_ci scanner_raise_error (context_p); 1603425bb815Sopenharmony_ci } 1604425bb815Sopenharmony_ci } 1605425bb815Sopenharmony_ci 1606425bb815Sopenharmony_ci if (!lexer_token_is_identifier (context_p, "from", 4)) 1607425bb815Sopenharmony_ci { 1608425bb815Sopenharmony_ci scanner_raise_error (context_p); 1609425bb815Sopenharmony_ci } 1610425bb815Sopenharmony_ci 1611425bb815Sopenharmony_ci lexer_next_token (context_p); 1612425bb815Sopenharmony_ci 1613425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1614425bb815Sopenharmony_ci && context_p->token.lit_location.type != LEXER_STRING_LITERAL) 1615425bb815Sopenharmony_ci { 1616425bb815Sopenharmony_ci scanner_raise_error (context_p); 1617425bb815Sopenharmony_ci } 1618425bb815Sopenharmony_ci 1619425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1620425bb815Sopenharmony_ci } 1621425bb815Sopenharmony_ci case LEXER_KEYW_EXPORT: 1622425bb815Sopenharmony_ci { 1623425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_SCRIPT) 1624425bb815Sopenharmony_ci { 1625425bb815Sopenharmony_ci scanner_raise_error (context_p); 1626425bb815Sopenharmony_ci } 1627425bb815Sopenharmony_ci 1628425bb815Sopenharmony_ci context_p->global_status_flags |= ECMA_PARSE_MODULE; 1629425bb815Sopenharmony_ci 1630425bb815Sopenharmony_ci lexer_next_token (context_p); 1631425bb815Sopenharmony_ci 1632425bb815Sopenharmony_ci if (context_p->token.type == LEXER_KEYW_DEFAULT) 1633425bb815Sopenharmony_ci { 1634425bb815Sopenharmony_ci lexer_next_token (context_p); 1635425bb815Sopenharmony_ci 1636425bb815Sopenharmony_ci if (context_p->token.type == LEXER_KEYW_FUNCTION) 1637425bb815Sopenharmony_ci { 1638425bb815Sopenharmony_ci lexer_next_token (context_p); 1639425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LITERAL 1640425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1641425bb815Sopenharmony_ci { 1642425bb815Sopenharmony_ci lexer_lit_location_t *location_p = scanner_add_literal (context_p, scanner_context_p); 1643425bb815Sopenharmony_ci 1644425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1645425bb815Sopenharmony_ci if (location_p->type & SCANNER_LITERAL_IS_LOCAL 1646425bb815Sopenharmony_ci && !(location_p->type & SCANNER_LITERAL_IS_FUNC)) 1647425bb815Sopenharmony_ci { 1648425bb815Sopenharmony_ci scanner_raise_redeclaration_error (context_p); 1649425bb815Sopenharmony_ci } 1650425bb815Sopenharmony_ci location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET; 1651425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 1652425bb815Sopenharmony_ci location_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC; 1653425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1654425bb815Sopenharmony_ci 1655425bb815Sopenharmony_ci lexer_next_token (context_p); 1656425bb815Sopenharmony_ci } 1657425bb815Sopenharmony_ci else 1658425bb815Sopenharmony_ci { 1659425bb815Sopenharmony_ci lexer_lit_location_t *location_p; 1660425bb815Sopenharmony_ci location_p = scanner_add_custom_literal (context_p, 1661425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p, 1662425bb815Sopenharmony_ci &lexer_default_literal); 1663425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1664425bb815Sopenharmony_ci location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET; 1665425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 1666425bb815Sopenharmony_ci location_p->type |= SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC; 1667425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1668425bb815Sopenharmony_ci } 1669425bb815Sopenharmony_ci 1670425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION); 1671425bb815Sopenharmony_ci 1672425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_STATEMENT); 1673425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; 1674425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1675425bb815Sopenharmony_ci } 1676425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1677425bb815Sopenharmony_ci if (context_p->token.type == LEXER_KEYW_CLASS) 1678425bb815Sopenharmony_ci { 1679425bb815Sopenharmony_ci scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT); 1680425bb815Sopenharmony_ci 1681425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1682425bb815Sopenharmony_ci { 1683425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); 1684425bb815Sopenharmony_ci 1685425bb815Sopenharmony_ci scanner_detect_invalid_let (context_p, literal_p); 1686425bb815Sopenharmony_ci 1687425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG; 1688425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1689425bb815Sopenharmony_ci } 1690425bb815Sopenharmony_ci 1691425bb815Sopenharmony_ci lexer_lit_location_t *literal_p; 1692425bb815Sopenharmony_ci literal_p = scanner_add_custom_literal (context_p, 1693425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p, 1694425bb815Sopenharmony_ci &lexer_default_literal); 1695425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG; 1696425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1697425bb815Sopenharmony_ci } 1698425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1699425bb815Sopenharmony_ci 1700425bb815Sopenharmony_ci /* Assignment expression. */ 1701425bb815Sopenharmony_ci lexer_lit_location_t *location_p; 1702425bb815Sopenharmony_ci location_p = scanner_add_custom_literal (context_p, 1703425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p, 1704425bb815Sopenharmony_ci &lexer_default_literal); 1705425bb815Sopenharmony_ci location_p->type |= SCANNER_LITERAL_IS_VAR; 1706425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1707425bb815Sopenharmony_ci 1708425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 1709425bb815Sopenharmony_ci { 1710425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1711425bb815Sopenharmony_ci } 1712425bb815Sopenharmony_ci 1713425bb815Sopenharmony_ci location_p = scanner_add_literal (context_p, scanner_context_p); 1714425bb815Sopenharmony_ci location_p->type |= SCANNER_LITERAL_IS_VAR; 1715425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 1716425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1717425bb815Sopenharmony_ci } 1718425bb815Sopenharmony_ci 1719425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_END; 1720425bb815Sopenharmony_ci 1721425bb815Sopenharmony_ci if (context_p->token.type == LEXER_MULTIPLY) 1722425bb815Sopenharmony_ci { 1723425bb815Sopenharmony_ci lexer_next_token (context_p); 1724425bb815Sopenharmony_ci if (!lexer_token_is_identifier (context_p, "from", 4)) 1725425bb815Sopenharmony_ci { 1726425bb815Sopenharmony_ci scanner_raise_error (context_p); 1727425bb815Sopenharmony_ci } 1728425bb815Sopenharmony_ci 1729425bb815Sopenharmony_ci lexer_next_token (context_p); 1730425bb815Sopenharmony_ci 1731425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1732425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_STRING_LITERAL) 1733425bb815Sopenharmony_ci { 1734425bb815Sopenharmony_ci scanner_raise_error (context_p); 1735425bb815Sopenharmony_ci } 1736425bb815Sopenharmony_ci 1737425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1738425bb815Sopenharmony_ci } 1739425bb815Sopenharmony_ci 1740425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_BRACE) 1741425bb815Sopenharmony_ci { 1742425bb815Sopenharmony_ci lexer_next_token (context_p); 1743425bb815Sopenharmony_ci 1744425bb815Sopenharmony_ci while (context_p->token.type != LEXER_RIGHT_BRACE) 1745425bb815Sopenharmony_ci { 1746425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1747425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 1748425bb815Sopenharmony_ci { 1749425bb815Sopenharmony_ci scanner_raise_error (context_p); 1750425bb815Sopenharmony_ci } 1751425bb815Sopenharmony_ci 1752425bb815Sopenharmony_ci lexer_next_token (context_p); 1753425bb815Sopenharmony_ci 1754425bb815Sopenharmony_ci if (lexer_token_is_identifier (context_p, "as", 2)) 1755425bb815Sopenharmony_ci { 1756425bb815Sopenharmony_ci lexer_next_token (context_p); 1757425bb815Sopenharmony_ci 1758425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1759425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1760425bb815Sopenharmony_ci { 1761425bb815Sopenharmony_ci scanner_raise_error (context_p); 1762425bb815Sopenharmony_ci } 1763425bb815Sopenharmony_ci 1764425bb815Sopenharmony_ci lexer_next_token (context_p); 1765425bb815Sopenharmony_ci } 1766425bb815Sopenharmony_ci 1767425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_BRACE) 1768425bb815Sopenharmony_ci { 1769425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COMMA) 1770425bb815Sopenharmony_ci { 1771425bb815Sopenharmony_ci scanner_raise_error (context_p); 1772425bb815Sopenharmony_ci } 1773425bb815Sopenharmony_ci 1774425bb815Sopenharmony_ci lexer_next_token (context_p); 1775425bb815Sopenharmony_ci } 1776425bb815Sopenharmony_ci } 1777425bb815Sopenharmony_ci 1778425bb815Sopenharmony_ci lexer_next_token (context_p); 1779425bb815Sopenharmony_ci 1780425bb815Sopenharmony_ci if (!lexer_token_is_identifier (context_p, "from", 4)) 1781425bb815Sopenharmony_ci { 1782425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1783425bb815Sopenharmony_ci } 1784425bb815Sopenharmony_ci 1785425bb815Sopenharmony_ci lexer_next_token (context_p); 1786425bb815Sopenharmony_ci 1787425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 1788425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_STRING_LITERAL) 1789425bb815Sopenharmony_ci { 1790425bb815Sopenharmony_ci scanner_raise_error (context_p); 1791425bb815Sopenharmony_ci } 1792425bb815Sopenharmony_ci 1793425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1794425bb815Sopenharmony_ci } 1795425bb815Sopenharmony_ci 1796425bb815Sopenharmony_ci switch (context_p->token.type) 1797425bb815Sopenharmony_ci { 1798425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1799425bb815Sopenharmony_ci case LEXER_KEYW_CLASS: 1800425bb815Sopenharmony_ci case LEXER_KEYW_LET: 1801425bb815Sopenharmony_ci case LEXER_KEYW_CONST: 1802425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1803425bb815Sopenharmony_ci case LEXER_KEYW_VAR: 1804425bb815Sopenharmony_ci { 1805425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_IN_EXPORT; 1806425bb815Sopenharmony_ci break; 1807425bb815Sopenharmony_ci } 1808425bb815Sopenharmony_ci } 1809425bb815Sopenharmony_ci 1810425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 1811425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1812425bb815Sopenharmony_ci } 1813425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 1814425bb815Sopenharmony_ci default: 1815425bb815Sopenharmony_ci { 1816425bb815Sopenharmony_ci break; 1817425bb815Sopenharmony_ci } 1818425bb815Sopenharmony_ci } 1819425bb815Sopenharmony_ci 1820425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 1821425bb815Sopenharmony_ci 1822425bb815Sopenharmony_ci if (type == LEXER_LITERAL 1823425bb815Sopenharmony_ci && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) 1824425bb815Sopenharmony_ci { 1825425bb815Sopenharmony_ci if (JERRY_UNLIKELY (lexer_check_next_character (context_p, LIT_CHAR_COLON))) 1826425bb815Sopenharmony_ci { 1827425bb815Sopenharmony_ci lexer_consume_next_character (context_p); 1828425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 1829425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1830425bb815Sopenharmony_ci } 1831425bb815Sopenharmony_ci 1832425bb815Sopenharmony_ci JERRY_ASSERT (context_p->token.flags & LEXER_NO_SKIP_SPACES); 1833425bb815Sopenharmony_ci 1834425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1835425bb815Sopenharmony_ci /* The colon needs to be checked first because the parser also checks 1836425bb815Sopenharmony_ci * it first, and this check skips the spaces which affects source_p. */ 1837425bb815Sopenharmony_ci if (JERRY_UNLIKELY (lexer_check_arrow (context_p))) 1838425bb815Sopenharmony_ci { 1839425bb815Sopenharmony_ci scanner_scan_simple_arrow (context_p, scanner_context_p, context_p->source_p); 1840425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1841425bb815Sopenharmony_ci } 1842425bb815Sopenharmony_ci 1843425bb815Sopenharmony_ci if (JERRY_UNLIKELY (lexer_token_is_let (context_p))) 1844425bb815Sopenharmony_ci { 1845425bb815Sopenharmony_ci lexer_lit_location_t let_literal = context_p->token.lit_location; 1846425bb815Sopenharmony_ci const uint8_t *source_p = context_p->source_p; 1847425bb815Sopenharmony_ci 1848425bb815Sopenharmony_ci lexer_next_token (context_p); 1849425bb815Sopenharmony_ci 1850425bb815Sopenharmony_ci type = (lexer_token_type_t) context_p->token.type; 1851425bb815Sopenharmony_ci 1852425bb815Sopenharmony_ci if (type == LEXER_LEFT_SQUARE 1853425bb815Sopenharmony_ci || type == LEXER_LEFT_BRACE 1854425bb815Sopenharmony_ci || (type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)) 1855425bb815Sopenharmony_ci { 1856425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; 1857425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_LET); 1858425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1859425bb815Sopenharmony_ci } 1860425bb815Sopenharmony_ci 1861425bb815Sopenharmony_ci scanner_info_t *info_p = scanner_insert_info (context_p, source_p, sizeof (scanner_info_t)); 1862425bb815Sopenharmony_ci info_p->type = SCANNER_TYPE_LET_EXPRESSION; 1863425bb815Sopenharmony_ci 1864425bb815Sopenharmony_ci lexer_lit_location_t *lit_location_p = scanner_add_custom_literal (context_p, 1865425bb815Sopenharmony_ci scanner_context_p->active_literal_pool_p, 1866425bb815Sopenharmony_ci &let_literal); 1867425bb815Sopenharmony_ci lit_location_p->type |= SCANNER_LITERAL_IS_USED; 1868425bb815Sopenharmony_ci 1869425bb815Sopenharmony_ci if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) 1870425bb815Sopenharmony_ci { 1871425bb815Sopenharmony_ci lit_location_p->type |= SCANNER_LITERAL_NO_REG; 1872425bb815Sopenharmony_ci } 1873425bb815Sopenharmony_ci 1874425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 1875425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1876425bb815Sopenharmony_ci } 1877425bb815Sopenharmony_ci 1878425bb815Sopenharmony_ci if (JERRY_UNLIKELY (lexer_token_is_async (context_p))) 1879425bb815Sopenharmony_ci { 1880425bb815Sopenharmony_ci scanner_context_p->async_source_p = context_p->source_p; 1881425bb815Sopenharmony_ci 1882425bb815Sopenharmony_ci if (scanner_check_async_function (context_p, scanner_context_p)) 1883425bb815Sopenharmony_ci { 1884425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 1885425bb815Sopenharmony_ci } 1886425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1887425bb815Sopenharmony_ci } 1888425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1889425bb815Sopenharmony_ci 1890425bb815Sopenharmony_ci scanner_add_reference (context_p, scanner_context_p); 1891425bb815Sopenharmony_ci 1892425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 1893425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1894425bb815Sopenharmony_ci } 1895425bb815Sopenharmony_ci 1896425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1897425bb815Sopenharmony_ci} /* scanner_scan_statement */ 1898425bb815Sopenharmony_ci 1899425bb815Sopenharmony_ci/** 1900425bb815Sopenharmony_ci * Scan statement terminator. 1901425bb815Sopenharmony_ci * 1902425bb815Sopenharmony_ci * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing 1903425bb815Sopenharmony_ci */ 1904425bb815Sopenharmony_cistatic scan_return_types_t 1905425bb815Sopenharmony_ciscanner_scan_statement_end (parser_context_t *context_p, /**< context */ 1906425bb815Sopenharmony_ci scanner_context_t *scanner_context_p, /**< scanner context */ 1907425bb815Sopenharmony_ci lexer_token_type_t type) /**< current token type */ 1908425bb815Sopenharmony_ci{ 1909425bb815Sopenharmony_ci bool terminator_found = false; 1910425bb815Sopenharmony_ci 1911425bb815Sopenharmony_ci if (type == LEXER_SEMICOLON) 1912425bb815Sopenharmony_ci { 1913425bb815Sopenharmony_ci lexer_next_token (context_p); 1914425bb815Sopenharmony_ci terminator_found = true; 1915425bb815Sopenharmony_ci } 1916425bb815Sopenharmony_ci 1917425bb815Sopenharmony_ci while (true) 1918425bb815Sopenharmony_ci { 1919425bb815Sopenharmony_ci type = (lexer_token_type_t) context_p->token.type; 1920425bb815Sopenharmony_ci 1921425bb815Sopenharmony_ci switch (context_p->stack_top_uint8) 1922425bb815Sopenharmony_ci { 1923425bb815Sopenharmony_ci case SCAN_STACK_SCRIPT: 1924425bb815Sopenharmony_ci case SCAN_STACK_SCRIPT_FUNCTION: 1925425bb815Sopenharmony_ci { 1926425bb815Sopenharmony_ci if (type == LEXER_EOS) 1927425bb815Sopenharmony_ci { 1928425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1929425bb815Sopenharmony_ci } 1930425bb815Sopenharmony_ci break; 1931425bb815Sopenharmony_ci } 1932425bb815Sopenharmony_ci case SCAN_STACK_BLOCK_STATEMENT: 1933425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1934425bb815Sopenharmony_ci case SCAN_STACK_CLASS_STATEMENT: 1935425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1936425bb815Sopenharmony_ci case SCAN_STACK_FUNCTION_STATEMENT: 1937425bb815Sopenharmony_ci { 1938425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 1939425bb815Sopenharmony_ci { 1940425bb815Sopenharmony_ci break; 1941425bb815Sopenharmony_ci } 1942425bb815Sopenharmony_ci 1943425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1944425bb815Sopenharmony_ci if (context_p->stack_top_uint8 != SCAN_STACK_CLASS_STATEMENT) 1945425bb815Sopenharmony_ci { 1946425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 1947425bb815Sopenharmony_ci } 1948425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 1949425bb815Sopenharmony_ci if (context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_STATEMENT) 1950425bb815Sopenharmony_ci { 1951425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 1952425bb815Sopenharmony_ci } 1953425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1954425bb815Sopenharmony_ci 1955425bb815Sopenharmony_ci terminator_found = true; 1956425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1957425bb815Sopenharmony_ci lexer_next_token (context_p); 1958425bb815Sopenharmony_ci continue; 1959425bb815Sopenharmony_ci } 1960425bb815Sopenharmony_ci case SCAN_STACK_FUNCTION_EXPRESSION: 1961425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1962425bb815Sopenharmony_ci case SCAN_STACK_FUNCTION_ARROW: 1963425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1964425bb815Sopenharmony_ci { 1965425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 1966425bb815Sopenharmony_ci { 1967425bb815Sopenharmony_ci break; 1968425bb815Sopenharmony_ci } 1969425bb815Sopenharmony_ci 1970425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 1971425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1972425bb815Sopenharmony_ci if (context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_ARROW) 1973425bb815Sopenharmony_ci { 1974425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 1975425bb815Sopenharmony_ci } 1976425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 1977425bb815Sopenharmony_ci 1978425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 1979425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1980425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 1981425bb815Sopenharmony_ci } 1982425bb815Sopenharmony_ci case SCAN_STACK_FUNCTION_PROPERTY: 1983425bb815Sopenharmony_ci { 1984425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 1985425bb815Sopenharmony_ci { 1986425bb815Sopenharmony_ci break; 1987425bb815Sopenharmony_ci } 1988425bb815Sopenharmony_ci 1989425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 1990425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 1991425bb815Sopenharmony_ci 1992425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 1993425bb815Sopenharmony_ci if (context_p->stack_top_uint8 == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR 1994425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) 1995425bb815Sopenharmony_ci { 1996425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_CLASS_METHOD; 1997425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 1998425bb815Sopenharmony_ci } 1999425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2000425bb815Sopenharmony_ci 2001425bb815Sopenharmony_ci JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL); 2002425bb815Sopenharmony_ci 2003425bb815Sopenharmony_ci lexer_next_token (context_p); 2004425bb815Sopenharmony_ci 2005425bb815Sopenharmony_ci if (context_p->token.type == LEXER_RIGHT_BRACE) 2006425bb815Sopenharmony_ci { 2007425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 2008425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 2009425bb815Sopenharmony_ci } 2010425bb815Sopenharmony_ci 2011425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COMMA) 2012425bb815Sopenharmony_ci { 2013425bb815Sopenharmony_ci scanner_raise_error (context_p); 2014425bb815Sopenharmony_ci } 2015425bb815Sopenharmony_ci 2016425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; 2017425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 2018425bb815Sopenharmony_ci } 2019425bb815Sopenharmony_ci case SCAN_STACK_SWITCH_BLOCK: 2020425bb815Sopenharmony_ci { 2021425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 2022425bb815Sopenharmony_ci { 2023425bb815Sopenharmony_ci break; 2024425bb815Sopenharmony_ci } 2025425bb815Sopenharmony_ci 2026425bb815Sopenharmony_ci scanner_switch_statement_t switch_statement; 2027425bb815Sopenharmony_ci 2028425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2029425bb815Sopenharmony_ci parser_stack_pop (context_p, &switch_statement, sizeof (scanner_switch_statement_t)); 2030425bb815Sopenharmony_ci 2031425bb815Sopenharmony_ci scanner_context_p->active_switch_statement = switch_statement; 2032425bb815Sopenharmony_ci 2033425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2034425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 2035425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2036425bb815Sopenharmony_ci 2037425bb815Sopenharmony_ci terminator_found = true; 2038425bb815Sopenharmony_ci lexer_next_token (context_p); 2039425bb815Sopenharmony_ci continue; 2040425bb815Sopenharmony_ci } 2041425bb815Sopenharmony_ci case SCAN_STACK_IF_STATEMENT: 2042425bb815Sopenharmony_ci { 2043425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2044425bb815Sopenharmony_ci 2045425bb815Sopenharmony_ci if (type == LEXER_KEYW_ELSE 2046425bb815Sopenharmony_ci && (terminator_found || (context_p->token.flags & LEXER_WAS_NEWLINE))) 2047425bb815Sopenharmony_ci { 2048425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2049425bb815Sopenharmony_ci scanner_check_function_after_if (context_p, scanner_context_p); 2050425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 2051425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 2052425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 2053425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 2054425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2055425bb815Sopenharmony_ci } 2056425bb815Sopenharmony_ci continue; 2057425bb815Sopenharmony_ci } 2058425bb815Sopenharmony_ci case SCAN_STACK_WITH_STATEMENT: 2059425bb815Sopenharmony_ci { 2060425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; 2061425bb815Sopenharmony_ci 2062425bb815Sopenharmony_ci JERRY_ASSERT (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH); 2063425bb815Sopenharmony_ci 2064425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2065425bb815Sopenharmony_ci 2066425bb815Sopenharmony_ci if (context_p->stack_top_uint8 == 0) 2067425bb815Sopenharmony_ci { 2068425bb815Sopenharmony_ci literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_WITH; 2069425bb815Sopenharmony_ci } 2070425bb815Sopenharmony_ci 2071425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2072425bb815Sopenharmony_ci continue; 2073425bb815Sopenharmony_ci } 2074425bb815Sopenharmony_ci case SCAN_STACK_DO_STATEMENT: 2075425bb815Sopenharmony_ci { 2076425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2077425bb815Sopenharmony_ci 2078425bb815Sopenharmony_ci if (type != LEXER_KEYW_WHILE 2079425bb815Sopenharmony_ci || (!terminator_found && !(context_p->token.flags & LEXER_WAS_NEWLINE))) 2080425bb815Sopenharmony_ci { 2081425bb815Sopenharmony_ci scanner_raise_error (context_p); 2082425bb815Sopenharmony_ci } 2083425bb815Sopenharmony_ci 2084425bb815Sopenharmony_ci lexer_next_token (context_p); 2085425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_PAREN) 2086425bb815Sopenharmony_ci { 2087425bb815Sopenharmony_ci scanner_raise_error (context_p); 2088425bb815Sopenharmony_ci } 2089425bb815Sopenharmony_ci 2090425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_DO_EXPRESSION); 2091425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; 2092425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 2093425bb815Sopenharmony_ci } 2094425bb815Sopenharmony_ci case SCAN_STACK_DO_EXPRESSION: 2095425bb815Sopenharmony_ci { 2096425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2097425bb815Sopenharmony_ci terminator_found = true; 2098425bb815Sopenharmony_ci continue; 2099425bb815Sopenharmony_ci } 2100425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2101425bb815Sopenharmony_ci case SCAN_STACK_PRIVATE_BLOCK_EARLY: 2102425bb815Sopenharmony_ci { 2103425bb815Sopenharmony_ci parser_list_iterator_t literal_iterator; 2104425bb815Sopenharmony_ci lexer_lit_location_t *literal_p; 2105425bb815Sopenharmony_ci 2106425bb815Sopenharmony_ci parser_list_iterator_init (&scanner_context_p->active_literal_pool_p->literal_pool, &literal_iterator); 2107425bb815Sopenharmony_ci 2108425bb815Sopenharmony_ci while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) 2109425bb815Sopenharmony_ci { 2110425bb815Sopenharmony_ci if ((literal_p->type & (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)) 2111425bb815Sopenharmony_ci && (literal_p->type & SCANNER_LITERAL_IS_USED)) 2112425bb815Sopenharmony_ci { 2113425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 2114425bb815Sopenharmony_ci } 2115425bb815Sopenharmony_ci } 2116425bb815Sopenharmony_ci /* FALLTHRU */ 2117425bb815Sopenharmony_ci } 2118425bb815Sopenharmony_ci case SCAN_STACK_PRIVATE_BLOCK: 2119425bb815Sopenharmony_ci { 2120425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2121425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 2122425bb815Sopenharmony_ci continue; 2123425bb815Sopenharmony_ci } 2124425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2125425bb815Sopenharmony_ci default: 2126425bb815Sopenharmony_ci { 2127425bb815Sopenharmony_ci JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_TRY_STATEMENT 2128425bb815Sopenharmony_ci || context_p->stack_top_uint8 == SCAN_STACK_CATCH_STATEMENT); 2129425bb815Sopenharmony_ci 2130425bb815Sopenharmony_ci if (type != LEXER_RIGHT_BRACE) 2131425bb815Sopenharmony_ci { 2132425bb815Sopenharmony_ci break; 2133425bb815Sopenharmony_ci } 2134425bb815Sopenharmony_ci 2135425bb815Sopenharmony_ci uint8_t stack_top = context_p->stack_top_uint8; 2136425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2137425bb815Sopenharmony_ci lexer_next_token (context_p); 2138425bb815Sopenharmony_ci 2139425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2140425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 2141425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 2142425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_CATCH_STATEMENT) 2143425bb815Sopenharmony_ci { 2144425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, scanner_context_p); 2145425bb815Sopenharmony_ci } 2146425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2147425bb815Sopenharmony_ci 2148425bb815Sopenharmony_ci /* A finally statement is optional after a try or catch statement. */ 2149425bb815Sopenharmony_ci if (context_p->token.type == LEXER_KEYW_FINALLY) 2150425bb815Sopenharmony_ci { 2151425bb815Sopenharmony_ci lexer_next_token (context_p); 2152425bb815Sopenharmony_ci 2153425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_BRACE) 2154425bb815Sopenharmony_ci { 2155425bb815Sopenharmony_ci scanner_raise_error (context_p); 2156425bb815Sopenharmony_ci } 2157425bb815Sopenharmony_ci 2158425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2159425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p; 2160425bb815Sopenharmony_ci literal_pool_p = scanner_push_literal_pool (context_p, 2161425bb815Sopenharmony_ci scanner_context_p, 2162425bb815Sopenharmony_ci SCANNER_LITERAL_POOL_BLOCK); 2163425bb815Sopenharmony_ci literal_pool_p->source_p = context_p->source_p; 2164425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2165425bb815Sopenharmony_ci 2166425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT); 2167425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 2168425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 2169425bb815Sopenharmony_ci } 2170425bb815Sopenharmony_ci 2171425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_CATCH_STATEMENT) 2172425bb815Sopenharmony_ci { 2173425bb815Sopenharmony_ci terminator_found = true; 2174425bb815Sopenharmony_ci continue; 2175425bb815Sopenharmony_ci } 2176425bb815Sopenharmony_ci 2177425bb815Sopenharmony_ci /* A catch statement must be present after a try statement unless a finally is provided. */ 2178425bb815Sopenharmony_ci if (context_p->token.type != LEXER_KEYW_CATCH) 2179425bb815Sopenharmony_ci { 2180425bb815Sopenharmony_ci scanner_raise_error (context_p); 2181425bb815Sopenharmony_ci } 2182425bb815Sopenharmony_ci 2183425bb815Sopenharmony_ci lexer_next_token (context_p); 2184425bb815Sopenharmony_ci 2185425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_PAREN) 2186425bb815Sopenharmony_ci { 2187425bb815Sopenharmony_ci scanner_raise_error (context_p); 2188425bb815Sopenharmony_ci } 2189425bb815Sopenharmony_ci 2190425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p; 2191425bb815Sopenharmony_ci literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK); 2192425bb815Sopenharmony_ci literal_pool_p->source_p = context_p->source_p; 2193425bb815Sopenharmony_ci 2194425bb815Sopenharmony_ci lexer_next_token (context_p); 2195425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_CATCH_STATEMENT); 2196425bb815Sopenharmony_ci 2197425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2198425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE) 2199425bb815Sopenharmony_ci { 2200425bb815Sopenharmony_ci scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_CATCH, false); 2201425bb815Sopenharmony_ci 2202425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE) 2203425bb815Sopenharmony_ci { 2204425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); 2205425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_BINDING; 2206425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 2207425bb815Sopenharmony_ci } 2208425bb815Sopenharmony_ci 2209425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); 2210425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; 2211425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 2212425bb815Sopenharmony_ci } 2213425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2214425bb815Sopenharmony_ci 2215425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 2216425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 2217425bb815Sopenharmony_ci { 2218425bb815Sopenharmony_ci scanner_raise_error (context_p); 2219425bb815Sopenharmony_ci } 2220425bb815Sopenharmony_ci 2221425bb815Sopenharmony_ci lexer_lit_location_t *lit_location_p = scanner_add_literal (context_p, scanner_context_p); 2222425bb815Sopenharmony_ci lit_location_p->type |= SCANNER_LITERAL_IS_LOCAL; 2223425bb815Sopenharmony_ci 2224425bb815Sopenharmony_ci lexer_next_token (context_p); 2225425bb815Sopenharmony_ci 2226425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_PAREN) 2227425bb815Sopenharmony_ci { 2228425bb815Sopenharmony_ci scanner_raise_error (context_p); 2229425bb815Sopenharmony_ci } 2230425bb815Sopenharmony_ci 2231425bb815Sopenharmony_ci lexer_next_token (context_p); 2232425bb815Sopenharmony_ci 2233425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_BRACE) 2234425bb815Sopenharmony_ci { 2235425bb815Sopenharmony_ci scanner_raise_error (context_p); 2236425bb815Sopenharmony_ci } 2237425bb815Sopenharmony_ci 2238425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; 2239425bb815Sopenharmony_ci return SCAN_NEXT_TOKEN; 2240425bb815Sopenharmony_ci } 2241425bb815Sopenharmony_ci } 2242425bb815Sopenharmony_ci 2243425bb815Sopenharmony_ci if (!terminator_found && !(context_p->token.flags & LEXER_WAS_NEWLINE)) 2244425bb815Sopenharmony_ci { 2245425bb815Sopenharmony_ci scanner_raise_error (context_p); 2246425bb815Sopenharmony_ci } 2247425bb815Sopenharmony_ci 2248425bb815Sopenharmony_ci scanner_context_p->mode = SCAN_MODE_STATEMENT; 2249425bb815Sopenharmony_ci return SCAN_KEEP_TOKEN; 2250425bb815Sopenharmony_ci } 2251425bb815Sopenharmony_ci} /* scanner_scan_statement_end */ 2252425bb815Sopenharmony_ci 2253425bb815Sopenharmony_ci#if defined(JERRY_FOR_IAR_CONFIG) 2254425bb815Sopenharmony_ci// IAR 8.20.2 generates incorrect code for this function. 2255425bb815Sopenharmony_ci// When the function is compiled with 'High:Balanced' optimization level. 2256425bb815Sopenharmony_ci// In the line context_p->source_end_p = source_end_p 2257425bb815Sopenharmony_ci// IAR assumes that source_end_p is in R5 register, but 2258425bb815Sopenharmony_ci// the compiled doesn't initialize it since the function start. 2259425bb815Sopenharmony_ci// The workaround is to compile this function without optimizations. 2260425bb815Sopenharmony_ci#pragma optimize=none 2261425bb815Sopenharmony_ci#endif 2262425bb815Sopenharmony_ci/** 2263425bb815Sopenharmony_ci * Scan the whole source code. 2264425bb815Sopenharmony_ci */ 2265425bb815Sopenharmony_civoid JERRY_ATTR_NOINLINE 2266425bb815Sopenharmony_ciscanner_scan_all (parser_context_t *context_p, /**< context */ 2267425bb815Sopenharmony_ci const uint8_t *arg_list_p, /**< function argument list */ 2268425bb815Sopenharmony_ci const uint8_t *arg_list_end_p, /**< end of argument list */ 2269425bb815Sopenharmony_ci const uint8_t *source_p, /**< valid UTF-8 source code */ 2270425bb815Sopenharmony_ci const uint8_t *source_end_p) /**< end of source code */ 2271425bb815Sopenharmony_ci{ 2272425bb815Sopenharmony_ci scanner_context_t scanner_context; 2273425bb815Sopenharmony_ci 2274425bb815Sopenharmony_ci#if ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) 2275425bb815Sopenharmony_ci if (context_p->is_show_opcodes) 2276425bb815Sopenharmony_ci { 2277425bb815Sopenharmony_ci JERRY_DEBUG_MSG ("\n--- Scanning start ---\n\n"); 2278425bb815Sopenharmony_ci } 2279425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */ 2280425bb815Sopenharmony_ci 2281425bb815Sopenharmony_ci scanner_context.context_status_flags = context_p->status_flags; 2282425bb815Sopenharmony_ci scanner_context.status_flags = SCANNER_CONTEXT_NO_FLAGS; 2283425bb815Sopenharmony_ci#if ENABLED (JERRY_DEBUGGER) 2284425bb815Sopenharmony_ci if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) 2285425bb815Sopenharmony_ci { 2286425bb815Sopenharmony_ci scanner_context.status_flags |= SCANNER_CONTEXT_DEBUGGER_ENABLED; 2287425bb815Sopenharmony_ci } 2288425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_DEBUGGER) */ 2289425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2290425bb815Sopenharmony_ci scanner_context.binding_type = SCANNER_BINDING_NONE; 2291425bb815Sopenharmony_ci scanner_context.active_binding_list_p = NULL; 2292425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2293425bb815Sopenharmony_ci scanner_context.active_literal_pool_p = NULL; 2294425bb815Sopenharmony_ci scanner_context.active_switch_statement.last_case_p = NULL; 2295425bb815Sopenharmony_ci scanner_context.end_arguments_p = NULL; 2296425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2297425bb815Sopenharmony_ci scanner_context.async_source_p = NULL; 2298425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2299425bb815Sopenharmony_ci 2300425bb815Sopenharmony_ci /* This assignment must be here because of Apple compilers. */ 2301425bb815Sopenharmony_ci context_p->u.scanner_context_p = &scanner_context; 2302425bb815Sopenharmony_ci 2303425bb815Sopenharmony_ci parser_stack_init (context_p); 2304425bb815Sopenharmony_ci 2305425bb815Sopenharmony_ci PARSER_TRY (context_p->try_buffer) 2306425bb815Sopenharmony_ci { 2307425bb815Sopenharmony_ci context_p->line = 1; 2308425bb815Sopenharmony_ci context_p->column = 1; 2309425bb815Sopenharmony_ci 2310425bb815Sopenharmony_ci if (arg_list_p == NULL) 2311425bb815Sopenharmony_ci { 2312425bb815Sopenharmony_ci context_p->source_p = source_p; 2313425bb815Sopenharmony_ci context_p->source_end_p = source_end_p; 2314425bb815Sopenharmony_ci 2315425bb815Sopenharmony_ci uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION_WITHOUT_ARGUMENTS | SCANNER_LITERAL_POOL_CAN_EVAL; 2316425bb815Sopenharmony_ci 2317425bb815Sopenharmony_ci if (context_p->status_flags & PARSER_IS_STRICT) 2318425bb815Sopenharmony_ci { 2319425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_IS_STRICT; 2320425bb815Sopenharmony_ci } 2321425bb815Sopenharmony_ci 2322425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, &scanner_context, status_flags); 2323425bb815Sopenharmony_ci literal_pool_p->source_p = source_p; 2324425bb815Sopenharmony_ci 2325425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_SCRIPT); 2326425bb815Sopenharmony_ci 2327425bb815Sopenharmony_ci lexer_next_token (context_p); 2328425bb815Sopenharmony_ci scanner_check_directives (context_p, &scanner_context); 2329425bb815Sopenharmony_ci } 2330425bb815Sopenharmony_ci else 2331425bb815Sopenharmony_ci { 2332425bb815Sopenharmony_ci context_p->source_p = arg_list_p; 2333425bb815Sopenharmony_ci context_p->source_end_p = arg_list_end_p; 2334425bb815Sopenharmony_ci 2335425bb815Sopenharmony_ci uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; 2336425bb815Sopenharmony_ci 2337425bb815Sopenharmony_ci if (context_p->status_flags & PARSER_IS_STRICT) 2338425bb815Sopenharmony_ci { 2339425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_IS_STRICT; 2340425bb815Sopenharmony_ci } 2341425bb815Sopenharmony_ci 2342425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2343425bb815Sopenharmony_ci if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) 2344425bb815Sopenharmony_ci { 2345425bb815Sopenharmony_ci status_flags |= SCANNER_LITERAL_POOL_GENERATOR; 2346425bb815Sopenharmony_ci } 2347425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2348425bb815Sopenharmony_ci 2349425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, &scanner_context, status_flags); 2350425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; 2351425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_SCRIPT_FUNCTION); 2352425bb815Sopenharmony_ci 2353425bb815Sopenharmony_ci /* Faking the first token. */ 2354425bb815Sopenharmony_ci context_p->token.type = LEXER_LEFT_PAREN; 2355425bb815Sopenharmony_ci } 2356425bb815Sopenharmony_ci 2357425bb815Sopenharmony_ci while (true) 2358425bb815Sopenharmony_ci { 2359425bb815Sopenharmony_ci lexer_token_type_t type = (lexer_token_type_t) context_p->token.type; 2360425bb815Sopenharmony_ci scan_stack_modes_t stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; 2361425bb815Sopenharmony_ci 2362425bb815Sopenharmony_ci switch (scanner_context.mode) 2363425bb815Sopenharmony_ci { 2364425bb815Sopenharmony_ci case SCAN_MODE_PRIMARY_EXPRESSION: 2365425bb815Sopenharmony_ci { 2366425bb815Sopenharmony_ci if (type == LEXER_ADD 2367425bb815Sopenharmony_ci || type == LEXER_SUBTRACT 2368425bb815Sopenharmony_ci || LEXER_IS_UNARY_OP_TOKEN (type)) 2369425bb815Sopenharmony_ci { 2370425bb815Sopenharmony_ci break; 2371425bb815Sopenharmony_ci } 2372425bb815Sopenharmony_ci /* FALLTHRU */ 2373425bb815Sopenharmony_ci } 2374425bb815Sopenharmony_ci case SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW: 2375425bb815Sopenharmony_ci { 2376425bb815Sopenharmony_ci if (scanner_scan_primary_expression (context_p, &scanner_context, type, stack_top) != SCAN_NEXT_TOKEN) 2377425bb815Sopenharmony_ci { 2378425bb815Sopenharmony_ci continue; 2379425bb815Sopenharmony_ci } 2380425bb815Sopenharmony_ci break; 2381425bb815Sopenharmony_ci } 2382425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2383425bb815Sopenharmony_ci case SCAN_MODE_CLASS_DECLARATION: 2384425bb815Sopenharmony_ci { 2385425bb815Sopenharmony_ci if (context_p->token.type == LEXER_KEYW_EXTENDS) 2386425bb815Sopenharmony_ci { 2387425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_EXTENDS); 2388425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2389425bb815Sopenharmony_ci break; 2390425bb815Sopenharmony_ci } 2391425bb815Sopenharmony_ci else if (context_p->token.type != LEXER_LEFT_BRACE) 2392425bb815Sopenharmony_ci { 2393425bb815Sopenharmony_ci scanner_raise_error (context_p); 2394425bb815Sopenharmony_ci } 2395425bb815Sopenharmony_ci 2396425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_CLASS_METHOD; 2397425bb815Sopenharmony_ci /* FALLTHRU */ 2398425bb815Sopenharmony_ci } 2399425bb815Sopenharmony_ci case SCAN_MODE_CLASS_METHOD: 2400425bb815Sopenharmony_ci { 2401425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR 2402425bb815Sopenharmony_ci || stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR); 2403425bb815Sopenharmony_ci 2404425bb815Sopenharmony_ci lexer_skip_empty_statements (context_p); 2405425bb815Sopenharmony_ci 2406425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2407425bb815Sopenharmony_ci 2408425bb815Sopenharmony_ci if (context_p->token.type == LEXER_RIGHT_BRACE) 2409425bb815Sopenharmony_ci { 2410425bb815Sopenharmony_ci scanner_source_start_t source_start; 2411425bb815Sopenharmony_ci 2412425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2413425bb815Sopenharmony_ci 2414425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) 2415425bb815Sopenharmony_ci { 2416425bb815Sopenharmony_ci parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); 2417425bb815Sopenharmony_ci } 2418425bb815Sopenharmony_ci 2419425bb815Sopenharmony_ci stack_top = context_p->stack_top_uint8; 2420425bb815Sopenharmony_ci 2421425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_CLASS_STATEMENT || stack_top == SCAN_STACK_CLASS_EXPRESSION); 2422425bb815Sopenharmony_ci 2423425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_CLASS_STATEMENT) 2424425bb815Sopenharmony_ci { 2425425bb815Sopenharmony_ci /* The token is kept to disallow consuming a semicolon after it. */ 2426425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_STATEMENT_END; 2427425bb815Sopenharmony_ci continue; 2428425bb815Sopenharmony_ci } 2429425bb815Sopenharmony_ci 2430425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 2431425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2432425bb815Sopenharmony_ci break; 2433425bb815Sopenharmony_ci } 2434425bb815Sopenharmony_ci 2435425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LITERAL 2436425bb815Sopenharmony_ci && LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type) 2437425bb815Sopenharmony_ci && lexer_compare_literal_to_string (context_p, "constructor", 11)) 2438425bb815Sopenharmony_ci { 2439425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) 2440425bb815Sopenharmony_ci { 2441425bb815Sopenharmony_ci scanner_source_start_t source_start; 2442425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2443425bb815Sopenharmony_ci parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); 2444425bb815Sopenharmony_ci 2445425bb815Sopenharmony_ci scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t)); 2446425bb815Sopenharmony_ci info_p->type = SCANNER_TYPE_CLASS_CONSTRUCTOR; 2447425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR); 2448425bb815Sopenharmony_ci } 2449425bb815Sopenharmony_ci } 2450425bb815Sopenharmony_ci 2451425bb815Sopenharmony_ci if (lexer_token_is_identifier (context_p, "static", 6)) 2452425bb815Sopenharmony_ci { 2453425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2454425bb815Sopenharmony_ci } 2455425bb815Sopenharmony_ci 2456425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); 2457425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; 2458425bb815Sopenharmony_ci 2459425bb815Sopenharmony_ci uint16_t literal_pool_flags = SCANNER_LITERAL_POOL_FUNCTION; 2460425bb815Sopenharmony_ci 2461425bb815Sopenharmony_ci if (lexer_token_is_identifier (context_p, "get", 3) 2462425bb815Sopenharmony_ci || lexer_token_is_identifier (context_p, "set", 3)) 2463425bb815Sopenharmony_ci { 2464425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2465425bb815Sopenharmony_ci 2466425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_PAREN) 2467425bb815Sopenharmony_ci { 2468425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); 2469425bb815Sopenharmony_ci continue; 2470425bb815Sopenharmony_ci } 2471425bb815Sopenharmony_ci } 2472425bb815Sopenharmony_ci else if (lexer_token_is_identifier (context_p, "async", 5)) 2473425bb815Sopenharmony_ci { 2474425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2475425bb815Sopenharmony_ci 2476425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_PAREN) 2477425bb815Sopenharmony_ci { 2478425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); 2479425bb815Sopenharmony_ci continue; 2480425bb815Sopenharmony_ci } 2481425bb815Sopenharmony_ci 2482425bb815Sopenharmony_ci literal_pool_flags |= SCANNER_LITERAL_POOL_ASYNC; 2483425bb815Sopenharmony_ci 2484425bb815Sopenharmony_ci if (context_p->token.type == LEXER_MULTIPLY) 2485425bb815Sopenharmony_ci { 2486425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2487425bb815Sopenharmony_ci literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; 2488425bb815Sopenharmony_ci } 2489425bb815Sopenharmony_ci } 2490425bb815Sopenharmony_ci else if (context_p->token.type == LEXER_MULTIPLY) 2491425bb815Sopenharmony_ci { 2492425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2493425bb815Sopenharmony_ci literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; 2494425bb815Sopenharmony_ci } 2495425bb815Sopenharmony_ci 2496425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE) 2497425bb815Sopenharmony_ci { 2498425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (literal_pool_flags)); 2499425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2500425bb815Sopenharmony_ci break; 2501425bb815Sopenharmony_ci } 2502425bb815Sopenharmony_ci 2503425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL) 2504425bb815Sopenharmony_ci { 2505425bb815Sopenharmony_ci scanner_raise_error (context_p); 2506425bb815Sopenharmony_ci } 2507425bb815Sopenharmony_ci 2508425bb815Sopenharmony_ci if (literal_pool_flags & SCANNER_LITERAL_POOL_GENERATOR) 2509425bb815Sopenharmony_ci { 2510425bb815Sopenharmony_ci context_p->status_flags |= PARSER_IS_GENERATOR_FUNCTION; 2511425bb815Sopenharmony_ci } 2512425bb815Sopenharmony_ci 2513425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, &scanner_context, literal_pool_flags); 2514425bb815Sopenharmony_ci lexer_next_token (context_p); 2515425bb815Sopenharmony_ci continue; 2516425bb815Sopenharmony_ci } 2517425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2518425bb815Sopenharmony_ci case SCAN_MODE_POST_PRIMARY_EXPRESSION: 2519425bb815Sopenharmony_ci { 2520425bb815Sopenharmony_ci if (scanner_scan_post_primary_expression (context_p, &scanner_context, type, stack_top)) 2521425bb815Sopenharmony_ci { 2522425bb815Sopenharmony_ci break; 2523425bb815Sopenharmony_ci } 2524425bb815Sopenharmony_ci type = (lexer_token_type_t) context_p->token.type; 2525425bb815Sopenharmony_ci /* FALLTHRU */ 2526425bb815Sopenharmony_ci } 2527425bb815Sopenharmony_ci case SCAN_MODE_PRIMARY_EXPRESSION_END: 2528425bb815Sopenharmony_ci { 2529425bb815Sopenharmony_ci if (scanner_scan_primary_expression_end (context_p, &scanner_context, type, stack_top) != SCAN_NEXT_TOKEN) 2530425bb815Sopenharmony_ci { 2531425bb815Sopenharmony_ci continue; 2532425bb815Sopenharmony_ci } 2533425bb815Sopenharmony_ci break; 2534425bb815Sopenharmony_ci } 2535425bb815Sopenharmony_ci case SCAN_MODE_STATEMENT_OR_TERMINATOR: 2536425bb815Sopenharmony_ci { 2537425bb815Sopenharmony_ci if (type == LEXER_RIGHT_BRACE || type == LEXER_EOS) 2538425bb815Sopenharmony_ci { 2539425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_STATEMENT_END; 2540425bb815Sopenharmony_ci continue; 2541425bb815Sopenharmony_ci } 2542425bb815Sopenharmony_ci /* FALLTHRU */ 2543425bb815Sopenharmony_ci } 2544425bb815Sopenharmony_ci case SCAN_MODE_STATEMENT: 2545425bb815Sopenharmony_ci { 2546425bb815Sopenharmony_ci if (scanner_scan_statement (context_p, &scanner_context, type, stack_top) != SCAN_NEXT_TOKEN) 2547425bb815Sopenharmony_ci { 2548425bb815Sopenharmony_ci continue; 2549425bb815Sopenharmony_ci } 2550425bb815Sopenharmony_ci break; 2551425bb815Sopenharmony_ci } 2552425bb815Sopenharmony_ci case SCAN_MODE_STATEMENT_END: 2553425bb815Sopenharmony_ci { 2554425bb815Sopenharmony_ci if (scanner_scan_statement_end (context_p, &scanner_context, type) != SCAN_NEXT_TOKEN) 2555425bb815Sopenharmony_ci { 2556425bb815Sopenharmony_ci continue; 2557425bb815Sopenharmony_ci } 2558425bb815Sopenharmony_ci 2559425bb815Sopenharmony_ci if (context_p->token.type == LEXER_EOS) 2560425bb815Sopenharmony_ci { 2561425bb815Sopenharmony_ci goto scan_completed; 2562425bb815Sopenharmony_ci } 2563425bb815Sopenharmony_ci 2564425bb815Sopenharmony_ci break; 2565425bb815Sopenharmony_ci } 2566425bb815Sopenharmony_ci case SCAN_MODE_VAR_STATEMENT: 2567425bb815Sopenharmony_ci { 2568425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2569425bb815Sopenharmony_ci if (type == LEXER_LEFT_SQUARE || type == LEXER_LEFT_BRACE) 2570425bb815Sopenharmony_ci { 2571425bb815Sopenharmony_ci uint8_t binding_type = SCANNER_BINDING_VAR; 2572425bb815Sopenharmony_ci 2573425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_FOR_LET_START) 2574425bb815Sopenharmony_ci { 2575425bb815Sopenharmony_ci binding_type = SCANNER_BINDING_LET; 2576425bb815Sopenharmony_ci } 2577425bb815Sopenharmony_ci else if (stack_top == SCAN_STACK_CONST || stack_top == SCAN_STACK_FOR_CONST_START) 2578425bb815Sopenharmony_ci { 2579425bb815Sopenharmony_ci binding_type = SCANNER_BINDING_CONST; 2580425bb815Sopenharmony_ci } 2581425bb815Sopenharmony_ci 2582425bb815Sopenharmony_ci scanner_push_destructuring_pattern (context_p, &scanner_context, binding_type, false); 2583425bb815Sopenharmony_ci 2584425bb815Sopenharmony_ci if (type == LEXER_LEFT_SQUARE) 2585425bb815Sopenharmony_ci { 2586425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); 2587425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_BINDING; 2588425bb815Sopenharmony_ci break; 2589425bb815Sopenharmony_ci } 2590425bb815Sopenharmony_ci 2591425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); 2592425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PROPERTY_NAME; 2593425bb815Sopenharmony_ci continue; 2594425bb815Sopenharmony_ci } 2595425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2596425bb815Sopenharmony_ci 2597425bb815Sopenharmony_ci if (type != LEXER_LITERAL 2598425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 2599425bb815Sopenharmony_ci { 2600425bb815Sopenharmony_ci scanner_raise_error (context_p); 2601425bb815Sopenharmony_ci } 2602425bb815Sopenharmony_ci 2603425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, &scanner_context); 2604425bb815Sopenharmony_ci 2605425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2606425bb815Sopenharmony_ci if (stack_top != SCAN_STACK_VAR && stack_top != SCAN_STACK_FOR_VAR_START) 2607425bb815Sopenharmony_ci { 2608425bb815Sopenharmony_ci scanner_detect_invalid_let (context_p, literal_p); 2609425bb815Sopenharmony_ci 2610425bb815Sopenharmony_ci if (stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_FOR_LET_START) 2611425bb815Sopenharmony_ci { 2612425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LET; 2613425bb815Sopenharmony_ci } 2614425bb815Sopenharmony_ci else 2615425bb815Sopenharmony_ci { 2616425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_CONST || stack_top == SCAN_STACK_FOR_CONST_START); 2617425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_CONST; 2618425bb815Sopenharmony_ci } 2619425bb815Sopenharmony_ci 2620425bb815Sopenharmony_ci lexer_next_token (context_p); 2621425bb815Sopenharmony_ci 2622425bb815Sopenharmony_ci if (literal_p->type & SCANNER_LITERAL_IS_USED) 2623425bb815Sopenharmony_ci { 2624425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 2625425bb815Sopenharmony_ci } 2626425bb815Sopenharmony_ci else if (context_p->token.type == LEXER_ASSIGN) 2627425bb815Sopenharmony_ci { 2628425bb815Sopenharmony_ci scanner_binding_literal_t binding_literal; 2629425bb815Sopenharmony_ci binding_literal.literal_p = literal_p; 2630425bb815Sopenharmony_ci 2631425bb815Sopenharmony_ci parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); 2632425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); 2633425bb815Sopenharmony_ci } 2634425bb815Sopenharmony_ci } 2635425bb815Sopenharmony_ci else 2636425bb815Sopenharmony_ci { 2637425bb815Sopenharmony_ci if (!(literal_p->type & SCANNER_LITERAL_IS_VAR)) 2638425bb815Sopenharmony_ci { 2639425bb815Sopenharmony_ci scanner_detect_invalid_var (context_p, &scanner_context, literal_p); 2640425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR; 2641425bb815Sopenharmony_ci 2642425bb815Sopenharmony_ci if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) 2643425bb815Sopenharmony_ci { 2644425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_NO_REG; 2645425bb815Sopenharmony_ci } 2646425bb815Sopenharmony_ci } 2647425bb815Sopenharmony_ci 2648425bb815Sopenharmony_ci lexer_next_token (context_p); 2649425bb815Sopenharmony_ci } 2650425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 2651425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR; 2652425bb815Sopenharmony_ci 2653425bb815Sopenharmony_ci if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) 2654425bb815Sopenharmony_ci { 2655425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_NO_REG; 2656425bb815Sopenharmony_ci } 2657425bb815Sopenharmony_ci 2658425bb815Sopenharmony_ci lexer_next_token (context_p); 2659425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2660425bb815Sopenharmony_ci 2661425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 2662425bb815Sopenharmony_ci if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT) 2663425bb815Sopenharmony_ci { 2664425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_NO_REG; 2665425bb815Sopenharmony_ci } 2666425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 2667425bb815Sopenharmony_ci 2668425bb815Sopenharmony_ci switch (context_p->token.type) 2669425bb815Sopenharmony_ci { 2670425bb815Sopenharmony_ci case LEXER_ASSIGN: 2671425bb815Sopenharmony_ci { 2672425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2673425bb815Sopenharmony_ci /* FALLTHRU */ 2674425bb815Sopenharmony_ci } 2675425bb815Sopenharmony_ci case LEXER_COMMA: 2676425bb815Sopenharmony_ci { 2677425bb815Sopenharmony_ci lexer_next_token (context_p); 2678425bb815Sopenharmony_ci continue; 2679425bb815Sopenharmony_ci } 2680425bb815Sopenharmony_ci } 2681425bb815Sopenharmony_ci 2682425bb815Sopenharmony_ci if (SCANNER_IS_FOR_START (stack_top)) 2683425bb815Sopenharmony_ci { 2684425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 2685425bb815Sopenharmony_ci JERRY_ASSERT (!(scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT)); 2686425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 2687425bb815Sopenharmony_ci 2688425bb815Sopenharmony_ci if (context_p->token.type != LEXER_SEMICOLON 2689425bb815Sopenharmony_ci && context_p->token.type != LEXER_KEYW_IN 2690425bb815Sopenharmony_ci && !SCANNER_IDENTIFIER_IS_OF ()) 2691425bb815Sopenharmony_ci { 2692425bb815Sopenharmony_ci scanner_raise_error (context_p); 2693425bb815Sopenharmony_ci } 2694425bb815Sopenharmony_ci 2695425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 2696425bb815Sopenharmony_ci continue; 2697425bb815Sopenharmony_ci } 2698425bb815Sopenharmony_ci 2699425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2700425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_VAR || stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_CONST); 2701425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 2702425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_VAR); 2703425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2704425bb815Sopenharmony_ci 2705425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 2706425bb815Sopenharmony_ci scanner_context.active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; 2707425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 2708425bb815Sopenharmony_ci 2709425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_STATEMENT_END; 2710425bb815Sopenharmony_ci parser_stack_pop_uint8 (context_p); 2711425bb815Sopenharmony_ci continue; 2712425bb815Sopenharmony_ci } 2713425bb815Sopenharmony_ci case SCAN_MODE_FUNCTION_ARGUMENTS: 2714425bb815Sopenharmony_ci { 2715425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_SCRIPT_FUNCTION 2716425bb815Sopenharmony_ci || stack_top == SCAN_STACK_FUNCTION_STATEMENT 2717425bb815Sopenharmony_ci || stack_top == SCAN_STACK_FUNCTION_EXPRESSION 2718425bb815Sopenharmony_ci || stack_top == SCAN_STACK_FUNCTION_PROPERTY); 2719425bb815Sopenharmony_ci 2720425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p; 2721425bb815Sopenharmony_ci 2722425bb815Sopenharmony_ci JERRY_ASSERT (literal_pool_p != NULL && (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)); 2723425bb815Sopenharmony_ci 2724425bb815Sopenharmony_ci literal_pool_p->source_p = context_p->source_p; 2725425bb815Sopenharmony_ci 2726425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2727425bb815Sopenharmony_ci if (JERRY_UNLIKELY (scanner_context.async_source_p != NULL)) 2728425bb815Sopenharmony_ci { 2729425bb815Sopenharmony_ci literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ASYNC; 2730425bb815Sopenharmony_ci literal_pool_p->source_p = scanner_context.async_source_p; 2731425bb815Sopenharmony_ci scanner_context.async_source_p = NULL; 2732425bb815Sopenharmony_ci } 2733425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2734425bb815Sopenharmony_ci 2735425bb815Sopenharmony_ci if (type != LEXER_LEFT_PAREN) 2736425bb815Sopenharmony_ci { 2737425bb815Sopenharmony_ci scanner_raise_error (context_p); 2738425bb815Sopenharmony_ci } 2739425bb815Sopenharmony_ci lexer_next_token (context_p); 2740425bb815Sopenharmony_ci 2741425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2742425bb815Sopenharmony_ci /* FALLTHRU */ 2743425bb815Sopenharmony_ci } 2744425bb815Sopenharmony_ci case SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS: 2745425bb815Sopenharmony_ci { 2746425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2747425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS) 2748425bb815Sopenharmony_ci { 2749425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2750425bb815Sopenharmony_ci lexer_lit_location_t *argument_literal_p; 2751425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2752425bb815Sopenharmony_ci 2753425bb815Sopenharmony_ci while (true) 2754425bb815Sopenharmony_ci { 2755425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2756425bb815Sopenharmony_ci if (context_p->token.type == LEXER_THREE_DOTS) 2757425bb815Sopenharmony_ci { 2758425bb815Sopenharmony_ci scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_UNMAPPED; 2759425bb815Sopenharmony_ci 2760425bb815Sopenharmony_ci lexer_next_token (context_p); 2761425bb815Sopenharmony_ci } 2762425bb815Sopenharmony_ci 2763425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE) 2764425bb815Sopenharmony_ci { 2765425bb815Sopenharmony_ci argument_literal_p = NULL; 2766425bb815Sopenharmony_ci break; 2767425bb815Sopenharmony_ci } 2768425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2769425bb815Sopenharmony_ci 2770425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL 2771425bb815Sopenharmony_ci || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 2772425bb815Sopenharmony_ci { 2773425bb815Sopenharmony_ci scanner_raise_error (context_p); 2774425bb815Sopenharmony_ci } 2775425bb815Sopenharmony_ci 2776425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2777425bb815Sopenharmony_ci argument_literal_p = scanner_append_argument (context_p, &scanner_context); 2778425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */ 2779425bb815Sopenharmony_ci scanner_append_argument (context_p, &scanner_context); 2780425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2781425bb815Sopenharmony_ci 2782425bb815Sopenharmony_ci lexer_next_token (context_p); 2783425bb815Sopenharmony_ci 2784425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COMMA) 2785425bb815Sopenharmony_ci { 2786425bb815Sopenharmony_ci break; 2787425bb815Sopenharmony_ci } 2788425bb815Sopenharmony_ci lexer_next_token (context_p); 2789425bb815Sopenharmony_ci } 2790425bb815Sopenharmony_ci 2791425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2792425bb815Sopenharmony_ci if (argument_literal_p == NULL) 2793425bb815Sopenharmony_ci { 2794425bb815Sopenharmony_ci scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_UNMAPPED; 2795425bb815Sopenharmony_ci 2796425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PARAMETERS); 2797425bb815Sopenharmony_ci scanner_append_hole (context_p, &scanner_context); 2798425bb815Sopenharmony_ci scanner_push_destructuring_pattern (context_p, &scanner_context, SCANNER_BINDING_ARG, false); 2799425bb815Sopenharmony_ci 2800425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE) 2801425bb815Sopenharmony_ci { 2802425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); 2803425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_BINDING; 2804425bb815Sopenharmony_ci break; 2805425bb815Sopenharmony_ci } 2806425bb815Sopenharmony_ci 2807425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); 2808425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PROPERTY_NAME; 2809425bb815Sopenharmony_ci continue; 2810425bb815Sopenharmony_ci } 2811425bb815Sopenharmony_ci 2812425bb815Sopenharmony_ci if (context_p->token.type == LEXER_ASSIGN) 2813425bb815Sopenharmony_ci { 2814425bb815Sopenharmony_ci scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_UNMAPPED; 2815425bb815Sopenharmony_ci 2816425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PARAMETERS); 2817425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2818425bb815Sopenharmony_ci 2819425bb815Sopenharmony_ci if (argument_literal_p->type & SCANNER_LITERAL_IS_USED) 2820425bb815Sopenharmony_ci { 2821425bb815Sopenharmony_ci JERRY_ASSERT (argument_literal_p->type & SCANNER_LITERAL_EARLY_CREATE); 2822425bb815Sopenharmony_ci break; 2823425bb815Sopenharmony_ci } 2824425bb815Sopenharmony_ci 2825425bb815Sopenharmony_ci scanner_binding_literal_t binding_literal; 2826425bb815Sopenharmony_ci binding_literal.literal_p = argument_literal_p; 2827425bb815Sopenharmony_ci 2828425bb815Sopenharmony_ci parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); 2829425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); 2830425bb815Sopenharmony_ci break; 2831425bb815Sopenharmony_ci } 2832425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2833425bb815Sopenharmony_ci } 2834425bb815Sopenharmony_ci 2835425bb815Sopenharmony_ci if (context_p->token.type == LEXER_EOS && stack_top == SCAN_STACK_SCRIPT_FUNCTION) 2836425bb815Sopenharmony_ci { 2837425bb815Sopenharmony_ci /* End of argument parsing. */ 2838425bb815Sopenharmony_ci scanner_info_t *scanner_info_p = (scanner_info_t *) scanner_malloc (context_p, sizeof (scanner_info_t)); 2839425bb815Sopenharmony_ci scanner_info_p->next_p = context_p->next_scanner_info_p; 2840425bb815Sopenharmony_ci scanner_info_p->source_p = NULL; 2841425bb815Sopenharmony_ci scanner_info_p->type = SCANNER_TYPE_END_ARGUMENTS; 2842425bb815Sopenharmony_ci scanner_context.end_arguments_p = scanner_info_p; 2843425bb815Sopenharmony_ci 2844425bb815Sopenharmony_ci context_p->next_scanner_info_p = scanner_info_p; 2845425bb815Sopenharmony_ci context_p->source_p = source_p; 2846425bb815Sopenharmony_ci context_p->source_end_p = source_end_p; 2847425bb815Sopenharmony_ci context_p->line = 1; 2848425bb815Sopenharmony_ci context_p->column = 1; 2849425bb815Sopenharmony_ci 2850425bb815Sopenharmony_ci scanner_filter_arguments (context_p, &scanner_context); 2851425bb815Sopenharmony_ci lexer_next_token (context_p); 2852425bb815Sopenharmony_ci scanner_check_directives (context_p, &scanner_context); 2853425bb815Sopenharmony_ci continue; 2854425bb815Sopenharmony_ci } 2855425bb815Sopenharmony_ci 2856425bb815Sopenharmony_ci if (context_p->token.type != LEXER_RIGHT_PAREN) 2857425bb815Sopenharmony_ci { 2858425bb815Sopenharmony_ci scanner_raise_error (context_p); 2859425bb815Sopenharmony_ci } 2860425bb815Sopenharmony_ci 2861425bb815Sopenharmony_ci lexer_next_token (context_p); 2862425bb815Sopenharmony_ci 2863425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LEFT_BRACE) 2864425bb815Sopenharmony_ci { 2865425bb815Sopenharmony_ci scanner_raise_error (context_p); 2866425bb815Sopenharmony_ci } 2867425bb815Sopenharmony_ci 2868425bb815Sopenharmony_ci scanner_filter_arguments (context_p, &scanner_context); 2869425bb815Sopenharmony_ci lexer_next_token (context_p); 2870425bb815Sopenharmony_ci scanner_check_directives (context_p, &scanner_context); 2871425bb815Sopenharmony_ci continue; 2872425bb815Sopenharmony_ci } 2873425bb815Sopenharmony_ci case SCAN_MODE_PROPERTY_NAME: 2874425bb815Sopenharmony_ci { 2875425bb815Sopenharmony_ci JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL); 2876425bb815Sopenharmony_ci 2877425bb815Sopenharmony_ci if (lexer_scan_identifier (context_p)) 2878425bb815Sopenharmony_ci { 2879425bb815Sopenharmony_ci lexer_check_property_modifier (context_p); 2880425bb815Sopenharmony_ci } 2881425bb815Sopenharmony_ci 2882425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2883425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE) 2884425bb815Sopenharmony_ci { 2885425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_COMPUTED_PROPERTY); 2886425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2887425bb815Sopenharmony_ci break; 2888425bb815Sopenharmony_ci } 2889425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2890425bb815Sopenharmony_ci 2891425bb815Sopenharmony_ci if (context_p->token.type == LEXER_RIGHT_BRACE) 2892425bb815Sopenharmony_ci { 2893425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 2894425bb815Sopenharmony_ci continue; 2895425bb815Sopenharmony_ci } 2896425bb815Sopenharmony_ci 2897425bb815Sopenharmony_ci if (context_p->token.type == LEXER_PROPERTY_GETTER 2898425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2899425bb815Sopenharmony_ci || context_p->token.type == LEXER_KEYW_ASYNC 2900425bb815Sopenharmony_ci || context_p->token.type == LEXER_MULTIPLY 2901425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2902425bb815Sopenharmony_ci || context_p->token.type == LEXER_PROPERTY_SETTER) 2903425bb815Sopenharmony_ci { 2904425bb815Sopenharmony_ci uint16_t literal_pool_flags = SCANNER_LITERAL_POOL_FUNCTION; 2905425bb815Sopenharmony_ci 2906425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2907425bb815Sopenharmony_ci if (context_p->token.type == LEXER_MULTIPLY) 2908425bb815Sopenharmony_ci { 2909425bb815Sopenharmony_ci literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; 2910425bb815Sopenharmony_ci } 2911425bb815Sopenharmony_ci else if (context_p->token.type == LEXER_KEYW_ASYNC) 2912425bb815Sopenharmony_ci { 2913425bb815Sopenharmony_ci literal_pool_flags |= SCANNER_LITERAL_POOL_ASYNC; 2914425bb815Sopenharmony_ci 2915425bb815Sopenharmony_ci if (lexer_consume_generator (context_p)) 2916425bb815Sopenharmony_ci { 2917425bb815Sopenharmony_ci literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; 2918425bb815Sopenharmony_ci } 2919425bb815Sopenharmony_ci } 2920425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2921425bb815Sopenharmony_ci 2922425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); 2923425bb815Sopenharmony_ci lexer_scan_identifier (context_p); 2924425bb815Sopenharmony_ci 2925425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2926425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_SQUARE) 2927425bb815Sopenharmony_ci { 2928425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (literal_pool_flags)); 2929425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2930425bb815Sopenharmony_ci break; 2931425bb815Sopenharmony_ci } 2932425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2933425bb815Sopenharmony_ci 2934425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL) 2935425bb815Sopenharmony_ci { 2936425bb815Sopenharmony_ci scanner_raise_error (context_p); 2937425bb815Sopenharmony_ci } 2938425bb815Sopenharmony_ci 2939425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, &scanner_context, literal_pool_flags); 2940425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; 2941425bb815Sopenharmony_ci break; 2942425bb815Sopenharmony_ci } 2943425bb815Sopenharmony_ci 2944425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL) 2945425bb815Sopenharmony_ci { 2946425bb815Sopenharmony_ci scanner_raise_error (context_p); 2947425bb815Sopenharmony_ci } 2948425bb815Sopenharmony_ci 2949425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2950425bb815Sopenharmony_ci parser_line_counter_t start_line = context_p->token.line; 2951425bb815Sopenharmony_ci parser_line_counter_t start_column = context_p->token.column; 2952425bb815Sopenharmony_ci bool is_ident = (context_p->token.lit_location.type == LEXER_IDENT_LITERAL); 2953425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 2954425bb815Sopenharmony_ci 2955425bb815Sopenharmony_ci lexer_next_token (context_p); 2956425bb815Sopenharmony_ci 2957425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 2958425bb815Sopenharmony_ci if (context_p->token.type == LEXER_LEFT_PAREN) 2959425bb815Sopenharmony_ci { 2960425bb815Sopenharmony_ci scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); 2961425bb815Sopenharmony_ci 2962425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); 2963425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; 2964425bb815Sopenharmony_ci continue; 2965425bb815Sopenharmony_ci } 2966425bb815Sopenharmony_ci 2967425bb815Sopenharmony_ci if (is_ident 2968425bb815Sopenharmony_ci && (context_p->token.type == LEXER_COMMA 2969425bb815Sopenharmony_ci || context_p->token.type == LEXER_RIGHT_BRACE 2970425bb815Sopenharmony_ci || context_p->token.type == LEXER_ASSIGN)) 2971425bb815Sopenharmony_ci { 2972425bb815Sopenharmony_ci context_p->source_p = context_p->token.lit_location.char_p; 2973425bb815Sopenharmony_ci context_p->line = start_line; 2974425bb815Sopenharmony_ci context_p->column = start_column; 2975425bb815Sopenharmony_ci 2976425bb815Sopenharmony_ci lexer_next_token (context_p); 2977425bb815Sopenharmony_ci 2978425bb815Sopenharmony_ci JERRY_ASSERT (context_p->token.type != LEXER_LITERAL 2979425bb815Sopenharmony_ci || context_p->token.lit_location.type == LEXER_IDENT_LITERAL); 2980425bb815Sopenharmony_ci 2981425bb815Sopenharmony_ci if (context_p->token.type != LEXER_LITERAL) 2982425bb815Sopenharmony_ci { 2983425bb815Sopenharmony_ci scanner_raise_error (context_p); 2984425bb815Sopenharmony_ci } 2985425bb815Sopenharmony_ci 2986425bb815Sopenharmony_ci if (scanner_context.binding_type != SCANNER_BINDING_NONE) 2987425bb815Sopenharmony_ci { 2988425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_BINDING; 2989425bb815Sopenharmony_ci continue; 2990425bb815Sopenharmony_ci } 2991425bb815Sopenharmony_ci 2992425bb815Sopenharmony_ci scanner_add_reference (context_p, &scanner_context); 2993425bb815Sopenharmony_ci 2994425bb815Sopenharmony_ci lexer_next_token (context_p); 2995425bb815Sopenharmony_ci 2996425bb815Sopenharmony_ci if (context_p->token.type == LEXER_ASSIGN) 2997425bb815Sopenharmony_ci { 2998425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 2999425bb815Sopenharmony_ci break; 3000425bb815Sopenharmony_ci } 3001425bb815Sopenharmony_ci 3002425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION_END; 3003425bb815Sopenharmony_ci continue; 3004425bb815Sopenharmony_ci } 3005425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3006425bb815Sopenharmony_ci 3007425bb815Sopenharmony_ci if (context_p->token.type != LEXER_COLON) 3008425bb815Sopenharmony_ci { 3009425bb815Sopenharmony_ci scanner_raise_error (context_p); 3010425bb815Sopenharmony_ci } 3011425bb815Sopenharmony_ci 3012425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 3013425bb815Sopenharmony_ci 3014425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3015425bb815Sopenharmony_ci if (scanner_context.binding_type != SCANNER_BINDING_NONE) 3016425bb815Sopenharmony_ci { 3017425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_BINDING; 3018425bb815Sopenharmony_ci } 3019425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3020425bb815Sopenharmony_ci break; 3021425bb815Sopenharmony_ci } 3022425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3023425bb815Sopenharmony_ci case SCAN_MODE_BINDING: 3024425bb815Sopenharmony_ci { 3025425bb815Sopenharmony_ci JERRY_ASSERT (scanner_context.binding_type == SCANNER_BINDING_VAR 3026425bb815Sopenharmony_ci || scanner_context.binding_type == SCANNER_BINDING_LET 3027425bb815Sopenharmony_ci || scanner_context.binding_type == SCANNER_BINDING_CATCH 3028425bb815Sopenharmony_ci || scanner_context.binding_type == SCANNER_BINDING_CONST 3029425bb815Sopenharmony_ci || scanner_context.binding_type == SCANNER_BINDING_ARG 3030425bb815Sopenharmony_ci || scanner_context.binding_type == SCANNER_BINDING_ARROW_ARG); 3031425bb815Sopenharmony_ci 3032425bb815Sopenharmony_ci if (type == LEXER_THREE_DOTS) 3033425bb815Sopenharmony_ci { 3034425bb815Sopenharmony_ci lexer_next_token (context_p); 3035425bb815Sopenharmony_ci type = (lexer_token_type_t) context_p->token.type; 3036425bb815Sopenharmony_ci } 3037425bb815Sopenharmony_ci 3038425bb815Sopenharmony_ci if (type == LEXER_LEFT_SQUARE || type == LEXER_LEFT_BRACE) 3039425bb815Sopenharmony_ci { 3040425bb815Sopenharmony_ci scanner_push_destructuring_pattern (context_p, &scanner_context, scanner_context.binding_type, true); 3041425bb815Sopenharmony_ci 3042425bb815Sopenharmony_ci if (type == LEXER_LEFT_SQUARE) 3043425bb815Sopenharmony_ci { 3044425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); 3045425bb815Sopenharmony_ci break; 3046425bb815Sopenharmony_ci } 3047425bb815Sopenharmony_ci 3048425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); 3049425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PROPERTY_NAME; 3050425bb815Sopenharmony_ci continue; 3051425bb815Sopenharmony_ci } 3052425bb815Sopenharmony_ci 3053425bb815Sopenharmony_ci if (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) 3054425bb815Sopenharmony_ci { 3055425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 3056425bb815Sopenharmony_ci continue; 3057425bb815Sopenharmony_ci } 3058425bb815Sopenharmony_ci 3059425bb815Sopenharmony_ci lexer_lit_location_t *literal_p = scanner_add_literal (context_p, &scanner_context); 3060425bb815Sopenharmony_ci 3061425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; 3062425bb815Sopenharmony_ci 3063425bb815Sopenharmony_ci if (scanner_context.binding_type == SCANNER_BINDING_VAR) 3064425bb815Sopenharmony_ci { 3065425bb815Sopenharmony_ci if (!(literal_p->type & SCANNER_LITERAL_IS_VAR)) 3066425bb815Sopenharmony_ci { 3067425bb815Sopenharmony_ci scanner_detect_invalid_var (context_p, &scanner_context, literal_p); 3068425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_VAR; 3069425bb815Sopenharmony_ci 3070425bb815Sopenharmony_ci if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) 3071425bb815Sopenharmony_ci { 3072425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_NO_REG; 3073425bb815Sopenharmony_ci } 3074425bb815Sopenharmony_ci } 3075425bb815Sopenharmony_ci break; 3076425bb815Sopenharmony_ci } 3077425bb815Sopenharmony_ci 3078425bb815Sopenharmony_ci if (scanner_context.binding_type == SCANNER_BINDING_ARROW_ARG) 3079425bb815Sopenharmony_ci { 3080425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG; 3081425bb815Sopenharmony_ci 3082425bb815Sopenharmony_ci if (literal_p->type & SCANNER_LITERAL_IS_USED) 3083425bb815Sopenharmony_ci { 3084425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 3085425bb815Sopenharmony_ci break; 3086425bb815Sopenharmony_ci } 3087425bb815Sopenharmony_ci } 3088425bb815Sopenharmony_ci else 3089425bb815Sopenharmony_ci { 3090425bb815Sopenharmony_ci scanner_detect_invalid_let (context_p, literal_p); 3091425bb815Sopenharmony_ci 3092425bb815Sopenharmony_ci if (scanner_context.binding_type <= SCANNER_BINDING_CATCH) 3093425bb815Sopenharmony_ci { 3094425bb815Sopenharmony_ci JERRY_ASSERT ((scanner_context.binding_type == SCANNER_BINDING_LET) 3095425bb815Sopenharmony_ci || (scanner_context.binding_type == SCANNER_BINDING_CATCH)); 3096425bb815Sopenharmony_ci 3097425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_LET; 3098425bb815Sopenharmony_ci } 3099425bb815Sopenharmony_ci else 3100425bb815Sopenharmony_ci { 3101425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_CONST; 3102425bb815Sopenharmony_ci 3103425bb815Sopenharmony_ci if (scanner_context.binding_type == SCANNER_BINDING_ARG) 3104425bb815Sopenharmony_ci { 3105425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_IS_ARG; 3106425bb815Sopenharmony_ci 3107425bb815Sopenharmony_ci if (literal_p->type & SCANNER_LITERAL_IS_USED) 3108425bb815Sopenharmony_ci { 3109425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 3110425bb815Sopenharmony_ci break; 3111425bb815Sopenharmony_ci } 3112425bb815Sopenharmony_ci } 3113425bb815Sopenharmony_ci } 3114425bb815Sopenharmony_ci 3115425bb815Sopenharmony_ci if (literal_p->type & SCANNER_LITERAL_IS_USED) 3116425bb815Sopenharmony_ci { 3117425bb815Sopenharmony_ci literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; 3118425bb815Sopenharmony_ci break; 3119425bb815Sopenharmony_ci } 3120425bb815Sopenharmony_ci } 3121425bb815Sopenharmony_ci 3122425bb815Sopenharmony_ci scanner_binding_item_t *binding_item_p; 3123425bb815Sopenharmony_ci binding_item_p = (scanner_binding_item_t *) scanner_malloc (context_p, sizeof (scanner_binding_item_t)); 3124425bb815Sopenharmony_ci 3125425bb815Sopenharmony_ci binding_item_p->next_p = scanner_context.active_binding_list_p->items_p; 3126425bb815Sopenharmony_ci binding_item_p->literal_p = literal_p; 3127425bb815Sopenharmony_ci 3128425bb815Sopenharmony_ci scanner_context.active_binding_list_p->items_p = binding_item_p; 3129425bb815Sopenharmony_ci 3130425bb815Sopenharmony_ci lexer_next_token (context_p); 3131425bb815Sopenharmony_ci if (context_p->token.type != LEXER_ASSIGN) 3132425bb815Sopenharmony_ci { 3133425bb815Sopenharmony_ci continue; 3134425bb815Sopenharmony_ci } 3135425bb815Sopenharmony_ci 3136425bb815Sopenharmony_ci scanner_binding_literal_t binding_literal; 3137425bb815Sopenharmony_ci binding_literal.literal_p = literal_p; 3138425bb815Sopenharmony_ci 3139425bb815Sopenharmony_ci parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); 3140425bb815Sopenharmony_ci parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); 3141425bb815Sopenharmony_ci 3142425bb815Sopenharmony_ci scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; 3143425bb815Sopenharmony_ci break; 3144425bb815Sopenharmony_ci } 3145425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3146425bb815Sopenharmony_ci } 3147425bb815Sopenharmony_ci 3148425bb815Sopenharmony_ci lexer_next_token (context_p); 3149425bb815Sopenharmony_ci } 3150425bb815Sopenharmony_ci 3151425bb815Sopenharmony_ciscan_completed: 3152425bb815Sopenharmony_ci if (context_p->stack_top_uint8 != SCAN_STACK_SCRIPT 3153425bb815Sopenharmony_ci && context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION) 3154425bb815Sopenharmony_ci { 3155425bb815Sopenharmony_ci scanner_raise_error (context_p); 3156425bb815Sopenharmony_ci } 3157425bb815Sopenharmony_ci 3158425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, &scanner_context); 3159425bb815Sopenharmony_ci 3160425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3161425bb815Sopenharmony_ci JERRY_ASSERT (scanner_context.active_binding_list_p == NULL); 3162425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3163425bb815Sopenharmony_ci JERRY_ASSERT (scanner_context.active_literal_pool_p == NULL); 3164425bb815Sopenharmony_ci 3165425bb815Sopenharmony_ci#ifndef JERRY_NDEBUG 3166425bb815Sopenharmony_ci scanner_context.context_status_flags |= PARSER_SCANNING_SUCCESSFUL; 3167425bb815Sopenharmony_ci#endif /* !JERRY_NDEBUG */ 3168425bb815Sopenharmony_ci } 3169425bb815Sopenharmony_ci PARSER_CATCH 3170425bb815Sopenharmony_ci { 3171425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3172425bb815Sopenharmony_ci while (scanner_context.active_binding_list_p != NULL) 3173425bb815Sopenharmony_ci { 3174425bb815Sopenharmony_ci scanner_pop_binding_list (&scanner_context); 3175425bb815Sopenharmony_ci } 3176425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3177425bb815Sopenharmony_ci 3178425bb815Sopenharmony_ci if (JERRY_UNLIKELY (context_p->error != PARSER_ERR_OUT_OF_MEMORY)) 3179425bb815Sopenharmony_ci { 3180425bb815Sopenharmony_ci /* Ignore the errors thrown by the lexer. */ 3181425bb815Sopenharmony_ci context_p->error = PARSER_ERR_NO_ERROR; 3182425bb815Sopenharmony_ci 3183425bb815Sopenharmony_ci /* The following code may allocate memory, so it is enclosed in a try/catch. */ 3184425bb815Sopenharmony_ci PARSER_TRY (context_p->try_buffer) 3185425bb815Sopenharmony_ci { 3186425bb815Sopenharmony_ci #if ENABLED (JERRY_ES2015) 3187425bb815Sopenharmony_ci if (scanner_context.status_flags & SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION) 3188425bb815Sopenharmony_ci { 3189425bb815Sopenharmony_ci JERRY_ASSERT (scanner_context.async_source_p != NULL); 3190425bb815Sopenharmony_ci 3191425bb815Sopenharmony_ci scanner_info_t *info_p; 3192425bb815Sopenharmony_ci info_p = scanner_insert_info (context_p, scanner_context.async_source_p, sizeof (scanner_info_t)); 3193425bb815Sopenharmony_ci info_p->type = SCANNER_TYPE_ERR_ASYNC_FUNCTION; 3194425bb815Sopenharmony_ci } 3195425bb815Sopenharmony_ci #endif /* ENABLED (JERRY_ES2015) */ 3196425bb815Sopenharmony_ci 3197425bb815Sopenharmony_ci while (scanner_context.active_literal_pool_p != NULL) 3198425bb815Sopenharmony_ci { 3199425bb815Sopenharmony_ci scanner_pop_literal_pool (context_p, &scanner_context); 3200425bb815Sopenharmony_ci } 3201425bb815Sopenharmony_ci } 3202425bb815Sopenharmony_ci PARSER_CATCH 3203425bb815Sopenharmony_ci { 3204425bb815Sopenharmony_ci JERRY_ASSERT (context_p->error == PARSER_ERR_OUT_OF_MEMORY); 3205425bb815Sopenharmony_ci } 3206425bb815Sopenharmony_ci PARSER_TRY_END 3207425bb815Sopenharmony_ci } 3208425bb815Sopenharmony_ci 3209425bb815Sopenharmony_ci JERRY_ASSERT (context_p->error == PARSER_ERR_NO_ERROR || context_p->error == PARSER_ERR_OUT_OF_MEMORY); 3210425bb815Sopenharmony_ci 3211425bb815Sopenharmony_ci if (context_p->error == PARSER_ERR_OUT_OF_MEMORY) 3212425bb815Sopenharmony_ci { 3213425bb815Sopenharmony_ci while (scanner_context.active_literal_pool_p != NULL) 3214425bb815Sopenharmony_ci { 3215425bb815Sopenharmony_ci scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p; 3216425bb815Sopenharmony_ci 3217425bb815Sopenharmony_ci scanner_context.active_literal_pool_p = literal_pool_p->prev_p; 3218425bb815Sopenharmony_ci 3219425bb815Sopenharmony_ci parser_list_free (&literal_pool_p->literal_pool); 3220425bb815Sopenharmony_ci scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t)); 3221425bb815Sopenharmony_ci } 3222425bb815Sopenharmony_ci 3223425bb815Sopenharmony_ci parser_stack_free (context_p); 3224425bb815Sopenharmony_ci return; 3225425bb815Sopenharmony_ci } 3226425bb815Sopenharmony_ci } 3227425bb815Sopenharmony_ci PARSER_TRY_END 3228425bb815Sopenharmony_ci 3229425bb815Sopenharmony_ci context_p->status_flags = scanner_context.context_status_flags; 3230425bb815Sopenharmony_ci scanner_reverse_info_list (context_p); 3231425bb815Sopenharmony_ci 3232425bb815Sopenharmony_ci#if ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) 3233425bb815Sopenharmony_ci if (context_p->is_show_opcodes) 3234425bb815Sopenharmony_ci { 3235425bb815Sopenharmony_ci scanner_info_t *info_p = context_p->next_scanner_info_p; 3236425bb815Sopenharmony_ci const uint8_t *source_start_p = (arg_list_p == NULL) ? source_p : arg_list_p; 3237425bb815Sopenharmony_ci 3238425bb815Sopenharmony_ci while (info_p->type != SCANNER_TYPE_END) 3239425bb815Sopenharmony_ci { 3240425bb815Sopenharmony_ci const char *name_p = NULL; 3241425bb815Sopenharmony_ci bool print_location = false; 3242425bb815Sopenharmony_ci 3243425bb815Sopenharmony_ci switch (info_p->type) 3244425bb815Sopenharmony_ci { 3245425bb815Sopenharmony_ci case SCANNER_TYPE_END_ARGUMENTS: 3246425bb815Sopenharmony_ci { 3247425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" END_ARGUMENTS\n"); 3248425bb815Sopenharmony_ci source_start_p = source_p; 3249425bb815Sopenharmony_ci break; 3250425bb815Sopenharmony_ci } 3251425bb815Sopenharmony_ci case SCANNER_TYPE_FUNCTION: 3252425bb815Sopenharmony_ci case SCANNER_TYPE_BLOCK: 3253425bb815Sopenharmony_ci { 3254425bb815Sopenharmony_ci const uint8_t *prev_source_p = info_p->source_p - 1; 3255425bb815Sopenharmony_ci const uint8_t *data_p; 3256425bb815Sopenharmony_ci 3257425bb815Sopenharmony_ci if (info_p->type == SCANNER_TYPE_FUNCTION) 3258425bb815Sopenharmony_ci { 3259425bb815Sopenharmony_ci data_p = (const uint8_t *) (info_p + 1); 3260425bb815Sopenharmony_ci 3261425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" FUNCTION: flags: 0x%x declarations: %d", 3262425bb815Sopenharmony_ci (int) info_p->u8_arg, 3263425bb815Sopenharmony_ci (int) info_p->u16_arg); 3264425bb815Sopenharmony_ci } 3265425bb815Sopenharmony_ci else 3266425bb815Sopenharmony_ci { 3267425bb815Sopenharmony_ci data_p = (const uint8_t *) (info_p + 1); 3268425bb815Sopenharmony_ci 3269425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" BLOCK:"); 3270425bb815Sopenharmony_ci } 3271425bb815Sopenharmony_ci 3272425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" source:%d\n", (int) (info_p->source_p - source_start_p)); 3273425bb815Sopenharmony_ci 3274425bb815Sopenharmony_ci while (data_p[0] != SCANNER_STREAM_TYPE_END) 3275425bb815Sopenharmony_ci { 3276425bb815Sopenharmony_ci switch (data_p[0] & SCANNER_STREAM_TYPE_MASK) 3277425bb815Sopenharmony_ci { 3278425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_VAR: 3279425bb815Sopenharmony_ci { 3280425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" VAR "); 3281425bb815Sopenharmony_ci break; 3282425bb815Sopenharmony_ci } 3283425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3284425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_LET: 3285425bb815Sopenharmony_ci { 3286425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" LET "); 3287425bb815Sopenharmony_ci break; 3288425bb815Sopenharmony_ci } 3289425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_CONST: 3290425bb815Sopenharmony_ci { 3291425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" CONST "); 3292425bb815Sopenharmony_ci break; 3293425bb815Sopenharmony_ci } 3294425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_LOCAL: 3295425bb815Sopenharmony_ci { 3296425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" LOCAL "); 3297425bb815Sopenharmony_ci break; 3298425bb815Sopenharmony_ci } 3299425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3300425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 3301425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_IMPORT: 3302425bb815Sopenharmony_ci { 3303425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" IMPORT "); 3304425bb815Sopenharmony_ci break; 3305425bb815Sopenharmony_ci } 3306425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 3307425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_ARG: 3308425bb815Sopenharmony_ci { 3309425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" ARG "); 3310425bb815Sopenharmony_ci break; 3311425bb815Sopenharmony_ci } 3312425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3313425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_ARG_VAR: 3314425bb815Sopenharmony_ci { 3315425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" ARG_VAR "); 3316425bb815Sopenharmony_ci break; 3317425bb815Sopenharmony_ci } 3318425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG: 3319425bb815Sopenharmony_ci { 3320425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" DESTRUCTURED_ARG "); 3321425bb815Sopenharmony_ci break; 3322425bb815Sopenharmony_ci } 3323425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR: 3324425bb815Sopenharmony_ci { 3325425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" DESTRUCTURED_ARG_VAR "); 3326425bb815Sopenharmony_ci break; 3327425bb815Sopenharmony_ci } 3328425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3329425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_ARG_FUNC: 3330425bb815Sopenharmony_ci { 3331425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" ARG_FUNC "); 3332425bb815Sopenharmony_ci break; 3333425bb815Sopenharmony_ci } 3334425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3335425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC: 3336425bb815Sopenharmony_ci { 3337425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" DESTRUCTURED_ARG_FUNC "); 3338425bb815Sopenharmony_ci break; 3339425bb815Sopenharmony_ci } 3340425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3341425bb815Sopenharmony_ci case SCANNER_STREAM_TYPE_FUNC: 3342425bb815Sopenharmony_ci { 3343425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" FUNC "); 3344425bb815Sopenharmony_ci break; 3345425bb815Sopenharmony_ci } 3346425bb815Sopenharmony_ci default: 3347425bb815Sopenharmony_ci { 3348425bb815Sopenharmony_ci JERRY_ASSERT ((data_p[0] & SCANNER_STREAM_TYPE_MASK) == SCANNER_STREAM_TYPE_HOLE); 3349425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" HOLE\n"); 3350425bb815Sopenharmony_ci data_p++; 3351425bb815Sopenharmony_ci continue; 3352425bb815Sopenharmony_ci } 3353425bb815Sopenharmony_ci } 3354425bb815Sopenharmony_ci 3355425bb815Sopenharmony_ci size_t length; 3356425bb815Sopenharmony_ci 3357425bb815Sopenharmony_ci if (!(data_p[0] & SCANNER_STREAM_UINT16_DIFF)) 3358425bb815Sopenharmony_ci { 3359425bb815Sopenharmony_ci if (data_p[2] != 0) 3360425bb815Sopenharmony_ci { 3361425bb815Sopenharmony_ci prev_source_p += data_p[2]; 3362425bb815Sopenharmony_ci length = 2 + 1; 3363425bb815Sopenharmony_ci } 3364425bb815Sopenharmony_ci else 3365425bb815Sopenharmony_ci { 3366425bb815Sopenharmony_ci memcpy (&prev_source_p, data_p + 2 + 1, sizeof (const uint8_t *)); 3367425bb815Sopenharmony_ci length = 2 + 1 + sizeof (const uint8_t *); 3368425bb815Sopenharmony_ci } 3369425bb815Sopenharmony_ci } 3370425bb815Sopenharmony_ci else 3371425bb815Sopenharmony_ci { 3372425bb815Sopenharmony_ci int32_t diff = ((int32_t) data_p[2]) | ((int32_t) data_p[3]) << 8; 3373425bb815Sopenharmony_ci 3374425bb815Sopenharmony_ci if (diff <= UINT8_MAX) 3375425bb815Sopenharmony_ci { 3376425bb815Sopenharmony_ci diff = -diff; 3377425bb815Sopenharmony_ci } 3378425bb815Sopenharmony_ci 3379425bb815Sopenharmony_ci prev_source_p += diff; 3380425bb815Sopenharmony_ci length = 2 + 2; 3381425bb815Sopenharmony_ci } 3382425bb815Sopenharmony_ci 3383425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3384425bb815Sopenharmony_ci if (data_p[0] & SCANNER_STREAM_EARLY_CREATE) 3385425bb815Sopenharmony_ci { 3386425bb815Sopenharmony_ci JERRY_ASSERT (data_p[0] & SCANNER_STREAM_NO_REG); 3387425bb815Sopenharmony_ci JERRY_DEBUG_MSG ("*"); 3388425bb815Sopenharmony_ci } 3389425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3390425bb815Sopenharmony_ci 3391425bb815Sopenharmony_ci if (data_p[0] & SCANNER_STREAM_NO_REG) 3392425bb815Sopenharmony_ci { 3393425bb815Sopenharmony_ci JERRY_DEBUG_MSG ("* "); 3394425bb815Sopenharmony_ci } 3395425bb815Sopenharmony_ci 3396425bb815Sopenharmony_ci JERRY_DEBUG_MSG ("'%.*s'\n", data_p[1], (char *) prev_source_p); 3397425bb815Sopenharmony_ci prev_source_p += data_p[1]; 3398425bb815Sopenharmony_ci data_p += length; 3399425bb815Sopenharmony_ci } 3400425bb815Sopenharmony_ci break; 3401425bb815Sopenharmony_ci } 3402425bb815Sopenharmony_ci case SCANNER_TYPE_WHILE: 3403425bb815Sopenharmony_ci { 3404425bb815Sopenharmony_ci name_p = "WHILE"; 3405425bb815Sopenharmony_ci print_location = true; 3406425bb815Sopenharmony_ci break; 3407425bb815Sopenharmony_ci } 3408425bb815Sopenharmony_ci case SCANNER_TYPE_FOR: 3409425bb815Sopenharmony_ci { 3410425bb815Sopenharmony_ci scanner_for_info_t *for_info_p = (scanner_for_info_t *) info_p; 3411425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" FOR: source:%d expression:%d[%d:%d] end:%d[%d:%d]\n", 3412425bb815Sopenharmony_ci (int) (for_info_p->info.source_p - source_start_p), 3413425bb815Sopenharmony_ci (int) (for_info_p->expression_location.source_p - source_start_p), 3414425bb815Sopenharmony_ci (int) for_info_p->expression_location.line, 3415425bb815Sopenharmony_ci (int) for_info_p->expression_location.column, 3416425bb815Sopenharmony_ci (int) (for_info_p->end_location.source_p - source_start_p), 3417425bb815Sopenharmony_ci (int) for_info_p->end_location.line, 3418425bb815Sopenharmony_ci (int) for_info_p->end_location.column); 3419425bb815Sopenharmony_ci break; 3420425bb815Sopenharmony_ci } 3421425bb815Sopenharmony_ci case SCANNER_TYPE_FOR_IN: 3422425bb815Sopenharmony_ci { 3423425bb815Sopenharmony_ci name_p = "FOR-IN"; 3424425bb815Sopenharmony_ci print_location = true; 3425425bb815Sopenharmony_ci break; 3426425bb815Sopenharmony_ci } 3427425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3428425bb815Sopenharmony_ci case SCANNER_TYPE_FOR_OF: 3429425bb815Sopenharmony_ci { 3430425bb815Sopenharmony_ci name_p = "FOR-OF"; 3431425bb815Sopenharmony_ci print_location = true; 3432425bb815Sopenharmony_ci break; 3433425bb815Sopenharmony_ci } 3434425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3435425bb815Sopenharmony_ci case SCANNER_TYPE_SWITCH: 3436425bb815Sopenharmony_ci { 3437425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" SWITCH: source:%d\n", 3438425bb815Sopenharmony_ci (int) (info_p->source_p - source_start_p)); 3439425bb815Sopenharmony_ci 3440425bb815Sopenharmony_ci scanner_case_info_t *current_case_p = ((scanner_switch_info_t *) info_p)->case_p; 3441425bb815Sopenharmony_ci 3442425bb815Sopenharmony_ci while (current_case_p != NULL) 3443425bb815Sopenharmony_ci { 3444425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" CASE: location:%d[%d:%d]\n", 3445425bb815Sopenharmony_ci (int) (current_case_p->location.source_p - source_start_p), 3446425bb815Sopenharmony_ci (int) current_case_p->location.line, 3447425bb815Sopenharmony_ci (int) current_case_p->location.column); 3448425bb815Sopenharmony_ci 3449425bb815Sopenharmony_ci current_case_p = current_case_p->next_p; 3450425bb815Sopenharmony_ci } 3451425bb815Sopenharmony_ci break; 3452425bb815Sopenharmony_ci } 3453425bb815Sopenharmony_ci case SCANNER_TYPE_CASE: 3454425bb815Sopenharmony_ci { 3455425bb815Sopenharmony_ci name_p = "CASE"; 3456425bb815Sopenharmony_ci print_location = true; 3457425bb815Sopenharmony_ci break; 3458425bb815Sopenharmony_ci } 3459425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 3460425bb815Sopenharmony_ci case SCANNER_TYPE_INITIALIZER: 3461425bb815Sopenharmony_ci { 3462425bb815Sopenharmony_ci name_p = "INITIALIZER"; 3463425bb815Sopenharmony_ci print_location = true; 3464425bb815Sopenharmony_ci break; 3465425bb815Sopenharmony_ci } 3466425bb815Sopenharmony_ci case SCANNER_TYPE_CLASS_CONSTRUCTOR: 3467425bb815Sopenharmony_ci { 3468425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" CLASS-CONSTRUCTOR: source:%d\n", 3469425bb815Sopenharmony_ci (int) (info_p->source_p - source_start_p)); 3470425bb815Sopenharmony_ci print_location = false; 3471425bb815Sopenharmony_ci break; 3472425bb815Sopenharmony_ci } 3473425bb815Sopenharmony_ci case SCANNER_TYPE_LET_EXPRESSION: 3474425bb815Sopenharmony_ci { 3475425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" LET_EXPRESSION: source:%d\n", 3476425bb815Sopenharmony_ci (int) (info_p->source_p - source_start_p)); 3477425bb815Sopenharmony_ci break; 3478425bb815Sopenharmony_ci } 3479425bb815Sopenharmony_ci case SCANNER_TYPE_ERR_REDECLARED: 3480425bb815Sopenharmony_ci { 3481425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" ERR_REDECLARED: source:%d\n", 3482425bb815Sopenharmony_ci (int) (info_p->source_p - source_start_p)); 3483425bb815Sopenharmony_ci break; 3484425bb815Sopenharmony_ci } 3485425bb815Sopenharmony_ci case SCANNER_TYPE_ERR_ASYNC_FUNCTION: 3486425bb815Sopenharmony_ci { 3487425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" ERR_ASYNC_FUNCTION: source:%d\n", 3488425bb815Sopenharmony_ci (int) (info_p->source_p - source_start_p)); 3489425bb815Sopenharmony_ci break; 3490425bb815Sopenharmony_ci } 3491425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 3492425bb815Sopenharmony_ci } 3493425bb815Sopenharmony_ci 3494425bb815Sopenharmony_ci if (print_location) 3495425bb815Sopenharmony_ci { 3496425bb815Sopenharmony_ci scanner_location_info_t *location_info_p = (scanner_location_info_t *) info_p; 3497425bb815Sopenharmony_ci JERRY_DEBUG_MSG (" %s: source:%d location:%d[%d:%d]\n", 3498425bb815Sopenharmony_ci name_p, 3499425bb815Sopenharmony_ci (int) (location_info_p->info.source_p - source_start_p), 3500425bb815Sopenharmony_ci (int) (location_info_p->location.source_p - source_start_p), 3501425bb815Sopenharmony_ci (int) location_info_p->location.line, 3502425bb815Sopenharmony_ci (int) location_info_p->location.column); 3503425bb815Sopenharmony_ci } 3504425bb815Sopenharmony_ci 3505425bb815Sopenharmony_ci info_p = info_p->next_p; 3506425bb815Sopenharmony_ci } 3507425bb815Sopenharmony_ci 3508425bb815Sopenharmony_ci JERRY_DEBUG_MSG ("\n--- Scanning end ---\n\n"); 3509425bb815Sopenharmony_ci } 3510425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */ 3511425bb815Sopenharmony_ci 3512425bb815Sopenharmony_ci parser_stack_free (context_p); 3513425bb815Sopenharmony_ci} /* scanner_scan_all */ 3514425bb815Sopenharmony_ci 3515425bb815Sopenharmony_ci/** 3516425bb815Sopenharmony_ci * @} 3517425bb815Sopenharmony_ci * @} 3518425bb815Sopenharmony_ci * @} 3519425bb815Sopenharmony_ci */ 3520425bb815Sopenharmony_ci 3521425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_PARSER) */ 3522