Skip to content

Commit 2270db9

Browse files
Removing 'nestings' from parser.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent d99d779 commit 2270db9

File tree

1 file changed

+2
-95
lines changed

1 file changed

+2
-95
lines changed

jerry-core/parser/js/parser.cpp

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,8 @@
3030
#include "opcodes-dumper.h"
3131
#include "serializer.h"
3232

33-
/**
34-
* Nesting types
35-
*
36-
* Note:
37-
* Nesting is an element, describing classes of syntax blocks, handled by parser.
38-
*
39-
* Nestings are pushed to the nestings stack upon entering them, and popped upon leaving.
40-
*
41-
* The top-most nesting, if any, describes the inner-most syntax block of specified type,
42-
* currently reached by parser.
43-
*/
44-
typedef enum
45-
{
46-
NESTING_ITERATIONAL, /**< an iterational (for, for-in, while, do-while) statement */
47-
NESTING_SWITCH, /**< switch-case block */
48-
NESTING_FUNCTION, /**< function */
49-
NESTING_TRY, /**< try-catch-finally block */
50-
NESTING_WITH /**< with block */
51-
} nesting_t;
52-
5333
static token tok;
5434

55-
enum
56-
{
57-
nestings_global_size
58-
};
59-
STATIC_STACK (nestings, nesting_t)
60-
6135
enum
6236
{
6337
scopes_global_size
@@ -68,18 +42,6 @@ STATIC_STACK (scopes, scopes_tree)
6842
#define EMIT_SORRY(MESSAGE) PARSE_SORRY(MESSAGE, tok.loc)
6943
#define EMIT_ERROR_VARG(MESSAGE, ...) PARSE_ERROR_VARG(MESSAGE, tok.loc, __VA_ARGS__)
7044

71-
#define NESTING_TO_STRING(I) (I == NESTING_FUNCTION \
72-
? "function" \
73-
: I == NESTING_ITERATIONAL \
74-
? "iterational" \
75-
: I == NESTING_SWITCH \
76-
? "switch" \
77-
: I == NESTING_TRY \
78-
? "try" \
79-
: I == NESTING_WITH \
80-
? "with" \
81-
: "unknown")
82-
8345
#define OPCODE_IS(OP, ID) (OP.op_idx == __op__idx_##ID)
8446

8547
static operand parse_expression (bool);
@@ -91,25 +53,6 @@ static void process_keyword_names (void);
9153
static void skip_braces (void);
9254
static void skip_parens (void);
9355

94-
/**
95-
* Push a nesting to the nesting stack, so setting new current nesting
96-
*/
97-
static void
98-
push_nesting (nesting_t nesting_type) /**< type of new nesting */
99-
{
100-
STACK_PUSH (nestings, nesting_type);
101-
} /* push_nesting */
102-
103-
/**
104-
* Restore nesting from nestings stack
105-
*/
106-
static void
107-
pop_nesting (nesting_t nesting_type) /**< type of current nesting */
108-
{
109-
JERRY_ASSERT (STACK_HEAD (nestings, 1) == nesting_type);
110-
STACK_DROP (nestings, 1);
111-
} /* pop_nesting */
112-
11356
static bool
11457
token_is (token_type tt)
11558
{
@@ -260,8 +203,6 @@ parse_property_name_and_value (void)
260203
static void
261204
parse_property_assignment (void)
262205
{
263-
STACK_DECLARE_USAGE (nestings);
264-
265206
if (token_is (TOK_NAME))
266207
{
267208
bool is_setter;
@@ -278,7 +219,7 @@ parse_property_assignment (void)
278219
{
279220
parse_property_name_and_value ();
280221

281-
goto cleanup;
222+
return;
282223
}
283224

284225
const token temp = tok;
@@ -290,7 +231,7 @@ parse_property_assignment (void)
290231

291232
parse_property_name_and_value ();
292233

293-
goto cleanup;
234+
return;
294235
}
295236

296237
const operand name = parse_property_name ();
@@ -309,9 +250,7 @@ parse_property_assignment (void)
309250

310251
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
311252

312-
push_nesting (NESTING_FUNCTION);
313253
parse_source_element_list (false);
314-
pop_nesting (NESTING_FUNCTION);
315254

316255
jsp_label_restore_set (masked_label_set_p);
317256

@@ -334,9 +273,6 @@ parse_property_assignment (void)
334273
{
335274
parse_property_name_and_value ();
336275
}
337-
338-
cleanup:
339-
STACK_CHECK_USAGE (nestings);
340276
}
341277

342278
/** Parse list of identifiers, assigment expressions or properties, splitted by comma.
@@ -509,7 +445,6 @@ static void
509445
parse_function_declaration (void)
510446
{
511447
STACK_DECLARE_USAGE (scopes);
512-
STACK_DECLARE_USAGE (nestings);
513448

514449
assert_keyword (KW_FUNCTION);
515450

@@ -531,9 +466,7 @@ parse_function_declaration (void)
531466

532467
skip_newlines ();
533468

534-
push_nesting (NESTING_FUNCTION);
535469
parse_source_element_list (false);
536-
pop_nesting (NESTING_FUNCTION);
537470

538471
next_token_must_be (TOK_CLOSE_BRACE);
539472

@@ -547,7 +480,6 @@ parse_function_declaration (void)
547480
jsp_label_restore_set (masked_label_set_p);
548481

549482
STACK_CHECK_USAGE (scopes);
550-
STACK_CHECK_USAGE (nestings);
551483
}
552484

553485
/* function_expression
@@ -556,8 +488,6 @@ parse_function_declaration (void)
556488
static operand
557489
parse_function_expression (void)
558490
{
559-
STACK_DECLARE_USAGE (nestings)
560-
561491
assert_keyword (KW_FUNCTION);
562492

563493
operand res;
@@ -583,9 +513,7 @@ parse_function_expression (void)
583513

584514
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
585515

586-
push_nesting (NESTING_FUNCTION);
587516
parse_source_element_list (false);
588-
pop_nesting (NESTING_FUNCTION);
589517

590518
jsp_label_restore_set (masked_label_set_p);
591519

@@ -595,8 +523,6 @@ parse_function_expression (void)
595523
dump_ret ();
596524
rewrite_function_end (VARG_FUNC_EXPR);
597525

598-
STACK_CHECK_USAGE (nestings);
599-
600526
return res;
601527
}
602528

@@ -1698,9 +1624,7 @@ parse_plain_for (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
16981624

16991625
// Parse body
17001626
skip_newlines ();
1701-
push_nesting (NESTING_ITERATIONAL);
17021627
parse_statement (NULL);
1703-
pop_nesting (NESTING_ITERATIONAL);
17041628

17051629
const locus end_loc = tok.loc;
17061630

@@ -1916,9 +1840,7 @@ parse_do_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (f
19161840
dumper_set_next_interation_target ();
19171841

19181842
skip_newlines ();
1919-
push_nesting (NESTING_ITERATIONAL);
19201843
parse_statement (NULL);
1921-
pop_nesting (NESTING_ITERATIONAL);
19221844

19231845
jsp_label_setup_continue_target (outermost_stmt_label_p,
19241846
serializer_get_current_opcode_counter ());
@@ -1947,9 +1869,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
19471869
dumper_set_next_interation_target ();
19481870

19491871
skip_newlines ();
1950-
push_nesting (NESTING_ITERATIONAL);
19511872
parse_statement (NULL);
1952-
pop_nesting (NESTING_ITERATIONAL);
19531873

19541874
jsp_label_setup_continue_target (outermost_stmt_label_p,
19551875
serializer_get_current_opcode_counter ());
@@ -1979,15 +1899,13 @@ parse_with_statement (void)
19791899
const operand expr = parse_expression_inside_parens ();
19801900

19811901
jsp_label_raise_nested_jumpable_border ();
1982-
push_nesting (NESTING_WITH);
19831902

19841903
opcode_counter_t with_begin_oc = dump_with_for_rewrite (expr);
19851904
skip_newlines ();
19861905
parse_statement (NULL);
19871906
rewrite_with (with_begin_oc);
19881907
dump_with_end ();
19891908

1990-
pop_nesting (NESTING_WITH);
19911909
jsp_label_remove_nested_jumpable_border ();
19921910
}
19931911

@@ -2067,7 +1985,6 @@ parse_switch_statement (void)
20671985
JSP_LABEL_TYPE_UNNAMED_BREAKS,
20681986
TOKEN_EMPTY_INITIALIZER);
20691987

2070-
push_nesting (NESTING_SWITCH);
20711988
// Second, parse case clauses' bodies and rewrite jumps
20721989
skip_newlines ();
20731990
while (is_keyword (KW_CASE) || is_keyword (KW_DEFAULT))
@@ -2102,7 +2019,6 @@ parse_switch_statement (void)
21022019
}
21032020
current_token_must_be (TOK_CLOSE_BRACE);
21042021
skip_token ();
2105-
pop_nesting (NESTING_SWITCH);
21062022

21072023
jsp_label_rewrite_jumps_and_pop (&label,
21082024
serializer_get_current_opcode_counter ());
@@ -2161,7 +2077,6 @@ parse_try_statement (void)
21612077
assert_keyword (KW_TRY);
21622078

21632079
jsp_label_raise_nested_jumpable_border ();
2164-
push_nesting (NESTING_TRY);
21652080

21662081
dump_try_for_rewrite ();
21672082

@@ -2198,7 +2113,6 @@ parse_try_statement (void)
21982113

21992114
dump_end_try_catch_finally ();
22002115

2201-
pop_nesting (NESTING_TRY);
22022116
jsp_label_remove_nested_jumpable_border ();
22032117
}
22042118

@@ -2383,11 +2297,6 @@ parse_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
23832297
{
23842298
bool is_break = is_keyword (KW_BREAK);
23852299

2386-
if (STACK_SIZE (nestings) == 0)
2387-
{
2388-
EMIT_ERROR ("Shall be inside a nesting");
2389-
}
2390-
23912300
skip_token ();
23922301

23932302
jsp_label_t *label_p;
@@ -2882,7 +2791,6 @@ parser_init (const char *source, size_t source_size, bool show_opcodes)
28822791
dumper_init ();
28832792
syntax_init ();
28842793

2885-
STACK_INIT (nestings);
28862794
STACK_INIT (scopes);
28872795

28882796
jsp_label_init ();
@@ -2893,7 +2801,6 @@ parser_free (void)
28932801
{
28942802
jsp_label_finalize ();
28952803

2896-
STACK_FREE (nestings);
28972804
STACK_FREE (scopes);
28982805

28992806
syntax_free ();

0 commit comments

Comments
 (0)