30
30
#include " opcodes-dumper.h"
31
31
#include " serializer.h"
32
32
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
-
53
33
static token tok;
54
34
55
- enum
56
- {
57
- nestings_global_size
58
- };
59
- STATIC_STACK (nestings, nesting_t )
60
-
61
35
enum
62
36
{
63
37
scopes_global_size
@@ -91,25 +65,6 @@ static void process_keyword_names (void);
91
65
static void skip_braces (void );
92
66
static void skip_parens (void );
93
67
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
-
113
68
static bool
114
69
token_is (token_type tt)
115
70
{
@@ -260,8 +215,6 @@ parse_property_name_and_value (void)
260
215
static void
261
216
parse_property_assignment (void )
262
217
{
263
- STACK_DECLARE_USAGE (nestings);
264
-
265
218
if (token_is (TOK_NAME))
266
219
{
267
220
bool is_setter;
@@ -278,7 +231,7 @@ parse_property_assignment (void)
278
231
{
279
232
parse_property_name_and_value ();
280
233
281
- goto cleanup ;
234
+ return ;
282
235
}
283
236
284
237
const token temp = tok;
@@ -290,7 +243,7 @@ parse_property_assignment (void)
290
243
291
244
parse_property_name_and_value ();
292
245
293
- goto cleanup ;
246
+ return ;
294
247
}
295
248
296
249
const operand name = parse_property_name ();
@@ -309,9 +262,7 @@ parse_property_assignment (void)
309
262
310
263
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
311
264
312
- push_nesting (NESTING_FUNCTION);
313
265
parse_source_element_list (false );
314
- pop_nesting (NESTING_FUNCTION);
315
266
316
267
jsp_label_restore_set (masked_label_set_p);
317
268
@@ -334,9 +285,6 @@ parse_property_assignment (void)
334
285
{
335
286
parse_property_name_and_value ();
336
287
}
337
-
338
- cleanup:
339
- STACK_CHECK_USAGE (nestings);
340
288
}
341
289
342
290
/* * Parse list of identifiers, assigment expressions or properties, splitted by comma.
@@ -509,7 +457,6 @@ static void
509
457
parse_function_declaration (void )
510
458
{
511
459
STACK_DECLARE_USAGE (scopes);
512
- STACK_DECLARE_USAGE (nestings);
513
460
514
461
assert_keyword (KW_FUNCTION);
515
462
@@ -531,9 +478,7 @@ parse_function_declaration (void)
531
478
532
479
skip_newlines ();
533
480
534
- push_nesting (NESTING_FUNCTION);
535
481
parse_source_element_list (false );
536
- pop_nesting (NESTING_FUNCTION);
537
482
538
483
next_token_must_be (TOK_CLOSE_BRACE);
539
484
@@ -547,7 +492,6 @@ parse_function_declaration (void)
547
492
jsp_label_restore_set (masked_label_set_p);
548
493
549
494
STACK_CHECK_USAGE (scopes);
550
- STACK_CHECK_USAGE (nestings);
551
495
}
552
496
553
497
/* function_expression
@@ -556,8 +500,6 @@ parse_function_declaration (void)
556
500
static operand
557
501
parse_function_expression (void )
558
502
{
559
- STACK_DECLARE_USAGE (nestings)
560
-
561
503
assert_keyword (KW_FUNCTION);
562
504
563
505
operand res;
@@ -583,9 +525,7 @@ parse_function_expression (void)
583
525
584
526
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
585
527
586
- push_nesting (NESTING_FUNCTION);
587
528
parse_source_element_list (false );
588
- pop_nesting (NESTING_FUNCTION);
589
529
590
530
jsp_label_restore_set (masked_label_set_p);
591
531
@@ -595,8 +535,6 @@ parse_function_expression (void)
595
535
dump_ret ();
596
536
rewrite_function_end (VARG_FUNC_EXPR);
597
537
598
- STACK_CHECK_USAGE (nestings);
599
-
600
538
return res;
601
539
}
602
540
@@ -1698,9 +1636,7 @@ parse_plain_for (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
1698
1636
1699
1637
// Parse body
1700
1638
skip_newlines ();
1701
- push_nesting (NESTING_ITERATIONAL);
1702
1639
parse_statement (NULL );
1703
- pop_nesting (NESTING_ITERATIONAL);
1704
1640
1705
1641
const locus end_loc = tok.loc ;
1706
1642
@@ -1916,9 +1852,7 @@ parse_do_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (f
1916
1852
dumper_set_next_interation_target ();
1917
1853
1918
1854
skip_newlines ();
1919
- push_nesting (NESTING_ITERATIONAL);
1920
1855
parse_statement (NULL );
1921
- pop_nesting (NESTING_ITERATIONAL);
1922
1856
1923
1857
jsp_label_setup_continue_target (outermost_stmt_label_p,
1924
1858
serializer_get_current_opcode_counter ());
@@ -1947,9 +1881,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
1947
1881
dumper_set_next_interation_target ();
1948
1882
1949
1883
skip_newlines ();
1950
- push_nesting (NESTING_ITERATIONAL);
1951
1884
parse_statement (NULL );
1952
- pop_nesting (NESTING_ITERATIONAL);
1953
1885
1954
1886
jsp_label_setup_continue_target (outermost_stmt_label_p,
1955
1887
serializer_get_current_opcode_counter ());
@@ -1979,15 +1911,13 @@ parse_with_statement (void)
1979
1911
const operand expr = parse_expression_inside_parens ();
1980
1912
1981
1913
jsp_label_raise_nested_jumpable_border ();
1982
- push_nesting (NESTING_WITH);
1983
1914
1984
1915
opcode_counter_t with_begin_oc = dump_with_for_rewrite (expr);
1985
1916
skip_newlines ();
1986
1917
parse_statement (NULL );
1987
1918
rewrite_with (with_begin_oc);
1988
1919
dump_with_end ();
1989
1920
1990
- pop_nesting (NESTING_WITH);
1991
1921
jsp_label_remove_nested_jumpable_border ();
1992
1922
}
1993
1923
@@ -2067,7 +1997,6 @@ parse_switch_statement (void)
2067
1997
JSP_LABEL_TYPE_UNNAMED_BREAKS,
2068
1998
TOKEN_EMPTY_INITIALIZER);
2069
1999
2070
- push_nesting (NESTING_SWITCH);
2071
2000
// Second, parse case clauses' bodies and rewrite jumps
2072
2001
skip_newlines ();
2073
2002
while (is_keyword (KW_CASE) || is_keyword (KW_DEFAULT))
@@ -2102,7 +2031,6 @@ parse_switch_statement (void)
2102
2031
}
2103
2032
current_token_must_be (TOK_CLOSE_BRACE);
2104
2033
skip_token ();
2105
- pop_nesting (NESTING_SWITCH);
2106
2034
2107
2035
jsp_label_rewrite_jumps_and_pop (&label,
2108
2036
serializer_get_current_opcode_counter ());
@@ -2161,7 +2089,6 @@ parse_try_statement (void)
2161
2089
assert_keyword (KW_TRY);
2162
2090
2163
2091
jsp_label_raise_nested_jumpable_border ();
2164
- push_nesting (NESTING_TRY);
2165
2092
2166
2093
dump_try_for_rewrite ();
2167
2094
@@ -2198,7 +2125,6 @@ parse_try_statement (void)
2198
2125
2199
2126
dump_end_try_catch_finally ();
2200
2127
2201
- pop_nesting (NESTING_TRY);
2202
2128
jsp_label_remove_nested_jumpable_border ();
2203
2129
}
2204
2130
@@ -2383,11 +2309,6 @@ parse_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
2383
2309
{
2384
2310
bool is_break = is_keyword (KW_BREAK);
2385
2311
2386
- if (STACK_SIZE (nestings) == 0 )
2387
- {
2388
- EMIT_ERROR (" Shall be inside a nesting" );
2389
- }
2390
-
2391
2312
skip_token ();
2392
2313
2393
2314
jsp_label_t *label_p;
@@ -2882,7 +2803,6 @@ parser_init (const char *source, size_t source_size, bool show_opcodes)
2882
2803
dumper_init ();
2883
2804
syntax_init ();
2884
2805
2885
- STACK_INIT (nestings);
2886
2806
STACK_INIT (scopes);
2887
2807
2888
2808
jsp_label_init ();
@@ -2893,7 +2813,6 @@ parser_free (void)
2893
2813
{
2894
2814
jsp_label_finalize ();
2895
2815
2896
- STACK_FREE (nestings);
2897
2816
STACK_FREE (scopes);
2898
2817
2899
2818
syntax_free ();
0 commit comments