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
@@ -68,18 +42,6 @@ STATIC_STACK (scopes, scopes_tree)
68
42
#define EMIT_SORRY (MESSAGE ) PARSE_SORRY(MESSAGE, tok.loc)
69
43
#define EMIT_ERROR_VARG (MESSAGE, ...) PARSE_ERROR_VARG(MESSAGE, tok.loc, __VA_ARGS__)
70
44
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
-
83
45
#define OPCODE_IS (OP, ID ) (OP.op_idx == __op__idx_##ID)
84
46
85
47
static operand parse_expression (bool );
@@ -91,25 +53,6 @@ static void process_keyword_names (void);
91
53
static void skip_braces (void );
92
54
static void skip_parens (void );
93
55
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
56
static bool
114
57
token_is (token_type tt)
115
58
{
@@ -260,8 +203,6 @@ parse_property_name_and_value (void)
260
203
static void
261
204
parse_property_assignment (void )
262
205
{
263
- STACK_DECLARE_USAGE (nestings);
264
-
265
206
if (token_is (TOK_NAME))
266
207
{
267
208
bool is_setter;
@@ -278,7 +219,7 @@ parse_property_assignment (void)
278
219
{
279
220
parse_property_name_and_value ();
280
221
281
- goto cleanup ;
222
+ return ;
282
223
}
283
224
284
225
const token temp = tok;
@@ -290,7 +231,7 @@ parse_property_assignment (void)
290
231
291
232
parse_property_name_and_value ();
292
233
293
- goto cleanup ;
234
+ return ;
294
235
}
295
236
296
237
const operand name = parse_property_name ();
@@ -309,9 +250,7 @@ parse_property_assignment (void)
309
250
310
251
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
311
252
312
- push_nesting (NESTING_FUNCTION);
313
253
parse_source_element_list (false );
314
- pop_nesting (NESTING_FUNCTION);
315
254
316
255
jsp_label_restore_set (masked_label_set_p);
317
256
@@ -334,9 +273,6 @@ parse_property_assignment (void)
334
273
{
335
274
parse_property_name_and_value ();
336
275
}
337
-
338
- cleanup:
339
- STACK_CHECK_USAGE (nestings);
340
276
}
341
277
342
278
/* * Parse list of identifiers, assigment expressions or properties, splitted by comma.
@@ -509,7 +445,6 @@ static void
509
445
parse_function_declaration (void )
510
446
{
511
447
STACK_DECLARE_USAGE (scopes);
512
- STACK_DECLARE_USAGE (nestings);
513
448
514
449
assert_keyword (KW_FUNCTION);
515
450
@@ -531,9 +466,7 @@ parse_function_declaration (void)
531
466
532
467
skip_newlines ();
533
468
534
- push_nesting (NESTING_FUNCTION);
535
469
parse_source_element_list (false );
536
- pop_nesting (NESTING_FUNCTION);
537
470
538
471
next_token_must_be (TOK_CLOSE_BRACE);
539
472
@@ -547,7 +480,6 @@ parse_function_declaration (void)
547
480
jsp_label_restore_set (masked_label_set_p);
548
481
549
482
STACK_CHECK_USAGE (scopes);
550
- STACK_CHECK_USAGE (nestings);
551
483
}
552
484
553
485
/* function_expression
@@ -556,8 +488,6 @@ parse_function_declaration (void)
556
488
static operand
557
489
parse_function_expression (void )
558
490
{
559
- STACK_DECLARE_USAGE (nestings)
560
-
561
491
assert_keyword (KW_FUNCTION);
562
492
563
493
operand res;
@@ -583,9 +513,7 @@ parse_function_expression (void)
583
513
584
514
jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
585
515
586
- push_nesting (NESTING_FUNCTION);
587
516
parse_source_element_list (false );
588
- pop_nesting (NESTING_FUNCTION);
589
517
590
518
jsp_label_restore_set (masked_label_set_p);
591
519
@@ -595,8 +523,6 @@ parse_function_expression (void)
595
523
dump_ret ();
596
524
rewrite_function_end (VARG_FUNC_EXPR);
597
525
598
- STACK_CHECK_USAGE (nestings);
599
-
600
526
return res;
601
527
}
602
528
@@ -1698,9 +1624,7 @@ parse_plain_for (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
1698
1624
1699
1625
// Parse body
1700
1626
skip_newlines ();
1701
- push_nesting (NESTING_ITERATIONAL);
1702
1627
parse_statement (NULL );
1703
- pop_nesting (NESTING_ITERATIONAL);
1704
1628
1705
1629
const locus end_loc = tok.loc ;
1706
1630
@@ -1916,9 +1840,7 @@ parse_do_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (f
1916
1840
dumper_set_next_interation_target ();
1917
1841
1918
1842
skip_newlines ();
1919
- push_nesting (NESTING_ITERATIONAL);
1920
1843
parse_statement (NULL );
1921
- pop_nesting (NESTING_ITERATIONAL);
1922
1844
1923
1845
jsp_label_setup_continue_target (outermost_stmt_label_p,
1924
1846
serializer_get_current_opcode_counter ());
@@ -1947,9 +1869,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
1947
1869
dumper_set_next_interation_target ();
1948
1870
1949
1871
skip_newlines ();
1950
- push_nesting (NESTING_ITERATIONAL);
1951
1872
parse_statement (NULL );
1952
- pop_nesting (NESTING_ITERATIONAL);
1953
1873
1954
1874
jsp_label_setup_continue_target (outermost_stmt_label_p,
1955
1875
serializer_get_current_opcode_counter ());
@@ -1979,15 +1899,13 @@ parse_with_statement (void)
1979
1899
const operand expr = parse_expression_inside_parens ();
1980
1900
1981
1901
jsp_label_raise_nested_jumpable_border ();
1982
- push_nesting (NESTING_WITH);
1983
1902
1984
1903
opcode_counter_t with_begin_oc = dump_with_for_rewrite (expr);
1985
1904
skip_newlines ();
1986
1905
parse_statement (NULL );
1987
1906
rewrite_with (with_begin_oc);
1988
1907
dump_with_end ();
1989
1908
1990
- pop_nesting (NESTING_WITH);
1991
1909
jsp_label_remove_nested_jumpable_border ();
1992
1910
}
1993
1911
@@ -2067,7 +1985,6 @@ parse_switch_statement (void)
2067
1985
JSP_LABEL_TYPE_UNNAMED_BREAKS,
2068
1986
TOKEN_EMPTY_INITIALIZER);
2069
1987
2070
- push_nesting (NESTING_SWITCH);
2071
1988
// Second, parse case clauses' bodies and rewrite jumps
2072
1989
skip_newlines ();
2073
1990
while (is_keyword (KW_CASE) || is_keyword (KW_DEFAULT))
@@ -2102,7 +2019,6 @@ parse_switch_statement (void)
2102
2019
}
2103
2020
current_token_must_be (TOK_CLOSE_BRACE);
2104
2021
skip_token ();
2105
- pop_nesting (NESTING_SWITCH);
2106
2022
2107
2023
jsp_label_rewrite_jumps_and_pop (&label,
2108
2024
serializer_get_current_opcode_counter ());
@@ -2161,7 +2077,6 @@ parse_try_statement (void)
2161
2077
assert_keyword (KW_TRY);
2162
2078
2163
2079
jsp_label_raise_nested_jumpable_border ();
2164
- push_nesting (NESTING_TRY);
2165
2080
2166
2081
dump_try_for_rewrite ();
2167
2082
@@ -2198,7 +2113,6 @@ parse_try_statement (void)
2198
2113
2199
2114
dump_end_try_catch_finally ();
2200
2115
2201
- pop_nesting (NESTING_TRY);
2202
2116
jsp_label_remove_nested_jumpable_border ();
2203
2117
}
2204
2118
@@ -2383,11 +2297,6 @@ parse_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
2383
2297
{
2384
2298
bool is_break = is_keyword (KW_BREAK);
2385
2299
2386
- if (STACK_SIZE (nestings) == 0 )
2387
- {
2388
- EMIT_ERROR (" Shall be inside a nesting" );
2389
- }
2390
-
2391
2300
skip_token ();
2392
2301
2393
2302
jsp_label_t *label_p;
@@ -2882,7 +2791,6 @@ parser_init (const char *source, size_t source_size, bool show_opcodes)
2882
2791
dumper_init ();
2883
2792
syntax_init ();
2884
2793
2885
- STACK_INIT (nestings);
2886
2794
STACK_INIT (scopes);
2887
2795
2888
2796
jsp_label_init ();
@@ -2893,7 +2801,6 @@ parser_free (void)
2893
2801
{
2894
2802
jsp_label_finalize ();
2895
2803
2896
- STACK_FREE (nestings);
2897
2804
STACK_FREE (scopes);
2898
2805
2899
2806
syntax_free ();
0 commit comments