Skip to content

Commit 791ef80

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

File tree

1 file changed

+2
-83
lines changed

1 file changed

+2
-83
lines changed

jerry-core/parser/js/parser.cpp

Lines changed: 2 additions & 83 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
@@ -91,25 +65,6 @@ static void process_keyword_names (void);
9165
static void skip_braces (void);
9266
static void skip_parens (void);
9367

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-
11368
static bool
11469
token_is (token_type tt)
11570
{
@@ -260,8 +215,6 @@ parse_property_name_and_value (void)
260215
static void
261216
parse_property_assignment (void)
262217
{
263-
STACK_DECLARE_USAGE (nestings);
264-
265218
if (token_is (TOK_NAME))
266219
{
267220
bool is_setter;
@@ -278,7 +231,7 @@ parse_property_assignment (void)
278231
{
279232
parse_property_name_and_value ();
280233

281-
goto cleanup;
234+
return;
282235
}
283236

284237
const token temp = tok;
@@ -290,7 +243,7 @@ parse_property_assignment (void)
290243

291244
parse_property_name_and_value ();
292245

293-
goto cleanup;
246+
return;
294247
}
295248

296249
const operand name = parse_property_name ();
@@ -309,9 +262,7 @@ parse_property_assignment (void)
309262

310263
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
311264

312-
push_nesting (NESTING_FUNCTION);
313265
parse_source_element_list (false);
314-
pop_nesting (NESTING_FUNCTION);
315266

316267
jsp_label_restore_set (masked_label_set_p);
317268

@@ -334,9 +285,6 @@ parse_property_assignment (void)
334285
{
335286
parse_property_name_and_value ();
336287
}
337-
338-
cleanup:
339-
STACK_CHECK_USAGE (nestings);
340288
}
341289

342290
/** Parse list of identifiers, assigment expressions or properties, splitted by comma.
@@ -509,7 +457,6 @@ static void
509457
parse_function_declaration (void)
510458
{
511459
STACK_DECLARE_USAGE (scopes);
512-
STACK_DECLARE_USAGE (nestings);
513460

514461
assert_keyword (KW_FUNCTION);
515462

@@ -531,9 +478,7 @@ parse_function_declaration (void)
531478

532479
skip_newlines ();
533480

534-
push_nesting (NESTING_FUNCTION);
535481
parse_source_element_list (false);
536-
pop_nesting (NESTING_FUNCTION);
537482

538483
next_token_must_be (TOK_CLOSE_BRACE);
539484

@@ -547,7 +492,6 @@ parse_function_declaration (void)
547492
jsp_label_restore_set (masked_label_set_p);
548493

549494
STACK_CHECK_USAGE (scopes);
550-
STACK_CHECK_USAGE (nestings);
551495
}
552496

553497
/* function_expression
@@ -556,8 +500,6 @@ parse_function_declaration (void)
556500
static operand
557501
parse_function_expression (void)
558502
{
559-
STACK_DECLARE_USAGE (nestings)
560-
561503
assert_keyword (KW_FUNCTION);
562504

563505
operand res;
@@ -583,9 +525,7 @@ parse_function_expression (void)
583525

584526
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
585527

586-
push_nesting (NESTING_FUNCTION);
587528
parse_source_element_list (false);
588-
pop_nesting (NESTING_FUNCTION);
589529

590530
jsp_label_restore_set (masked_label_set_p);
591531

@@ -595,8 +535,6 @@ parse_function_expression (void)
595535
dump_ret ();
596536
rewrite_function_end (VARG_FUNC_EXPR);
597537

598-
STACK_CHECK_USAGE (nestings);
599-
600538
return res;
601539
}
602540

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

16991637
// Parse body
17001638
skip_newlines ();
1701-
push_nesting (NESTING_ITERATIONAL);
17021639
parse_statement (NULL);
1703-
pop_nesting (NESTING_ITERATIONAL);
17041640

17051641
const locus end_loc = tok.loc;
17061642

@@ -1916,9 +1852,7 @@ parse_do_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (f
19161852
dumper_set_next_interation_target ();
19171853

19181854
skip_newlines ();
1919-
push_nesting (NESTING_ITERATIONAL);
19201855
parse_statement (NULL);
1921-
pop_nesting (NESTING_ITERATIONAL);
19221856

19231857
jsp_label_setup_continue_target (outermost_stmt_label_p,
19241858
serializer_get_current_opcode_counter ());
@@ -1947,9 +1881,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
19471881
dumper_set_next_interation_target ();
19481882

19491883
skip_newlines ();
1950-
push_nesting (NESTING_ITERATIONAL);
19511884
parse_statement (NULL);
1952-
pop_nesting (NESTING_ITERATIONAL);
19531885

19541886
jsp_label_setup_continue_target (outermost_stmt_label_p,
19551887
serializer_get_current_opcode_counter ());
@@ -1979,15 +1911,13 @@ parse_with_statement (void)
19791911
const operand expr = parse_expression_inside_parens ();
19801912

19811913
jsp_label_raise_nested_jumpable_border ();
1982-
push_nesting (NESTING_WITH);
19831914

19841915
opcode_counter_t with_begin_oc = dump_with_for_rewrite (expr);
19851916
skip_newlines ();
19861917
parse_statement (NULL);
19871918
rewrite_with (with_begin_oc);
19881919
dump_with_end ();
19891920

1990-
pop_nesting (NESTING_WITH);
19911921
jsp_label_remove_nested_jumpable_border ();
19921922
}
19931923

@@ -2067,7 +1997,6 @@ parse_switch_statement (void)
20671997
JSP_LABEL_TYPE_UNNAMED_BREAKS,
20681998
TOKEN_EMPTY_INITIALIZER);
20691999

2070-
push_nesting (NESTING_SWITCH);
20712000
// Second, parse case clauses' bodies and rewrite jumps
20722001
skip_newlines ();
20732002
while (is_keyword (KW_CASE) || is_keyword (KW_DEFAULT))
@@ -2102,7 +2031,6 @@ parse_switch_statement (void)
21022031
}
21032032
current_token_must_be (TOK_CLOSE_BRACE);
21042033
skip_token ();
2105-
pop_nesting (NESTING_SWITCH);
21062034

21072035
jsp_label_rewrite_jumps_and_pop (&label,
21082036
serializer_get_current_opcode_counter ());
@@ -2161,7 +2089,6 @@ parse_try_statement (void)
21612089
assert_keyword (KW_TRY);
21622090

21632091
jsp_label_raise_nested_jumpable_border ();
2164-
push_nesting (NESTING_TRY);
21652092

21662093
dump_try_for_rewrite ();
21672094

@@ -2198,7 +2125,6 @@ parse_try_statement (void)
21982125

21992126
dump_end_try_catch_finally ();
22002127

2201-
pop_nesting (NESTING_TRY);
22022128
jsp_label_remove_nested_jumpable_border ();
22032129
}
22042130

@@ -2383,11 +2309,6 @@ parse_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
23832309
{
23842310
bool is_break = is_keyword (KW_BREAK);
23852311

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

23932314
jsp_label_t *label_p;
@@ -2882,7 +2803,6 @@ parser_init (const char *source, size_t source_size, bool show_opcodes)
28822803
dumper_init ();
28832804
syntax_init ();
28842805

2885-
STACK_INIT (nestings);
28862806
STACK_INIT (scopes);
28872807

28882808
jsp_label_init ();
@@ -2893,7 +2813,6 @@ parser_free (void)
28932813
{
28942814
jsp_label_finalize ();
28952815

2896-
STACK_FREE (nestings);
28972816
STACK_FREE (scopes);
28982817

28992818
syntax_free ();

0 commit comments

Comments
 (0)