@@ -67,8 +67,6 @@ static void parse_statement (jsp_label_t *outermost_stmt_label_p);
67
67
static operand parse_assignment_expression (bool );
68
68
static void parse_source_element_list (bool );
69
69
static operand parse_argument_list (varg_list_type, operand, uint8_t *, operand *);
70
- static void skip_braces (void );
71
- static void skip_parens (void );
72
70
73
71
static bool
74
72
token_is (token_type tt)
@@ -173,6 +171,55 @@ is_strict_mode (void)
173
171
return scopes_tree_strict_mode (STACK_TOP (scopes));
174
172
}
175
173
174
+ /* *
175
+ * Skip block, defined with braces of specified type
176
+ *
177
+ * Note:
178
+ * Missing corresponding brace is considered a syntax error
179
+ *
180
+ * Note:
181
+ * Opening brace of the block to skip should be set as current
182
+ * token when the routine is called
183
+ */
184
+ static void
185
+ jsp_skip_braces (token_type brace_type) /* *< type of the opening brace */
186
+ {
187
+ current_token_must_be (brace_type);
188
+
189
+ token_type closing_bracket_type;
190
+
191
+ if (brace_type == TOK_OPEN_PAREN)
192
+ {
193
+ closing_bracket_type = TOK_CLOSE_PAREN;
194
+ }
195
+ else if (brace_type == TOK_OPEN_BRACE)
196
+ {
197
+ closing_bracket_type = TOK_CLOSE_BRACE;
198
+ }
199
+ else
200
+ {
201
+ JERRY_ASSERT (brace_type == TOK_OPEN_SQUARE);
202
+ closing_bracket_type = TOK_CLOSE_SQUARE;
203
+ }
204
+
205
+ skip_newlines ();
206
+
207
+ while (!token_is (closing_bracket_type)
208
+ && !token_is (TOK_EOF))
209
+ {
210
+ if (token_is (TOK_OPEN_PAREN)
211
+ || token_is (TOK_OPEN_BRACE)
212
+ || token_is (TOK_OPEN_SQUARE))
213
+ {
214
+ jsp_skip_braces (tok.type );
215
+ }
216
+
217
+ skip_newlines ();
218
+ }
219
+
220
+ current_token_must_be (closing_bracket_type);
221
+ } /* jsp_skip_braces */
222
+
176
223
/* property_name
177
224
: Identifier
178
225
| Keyword
@@ -1964,7 +2011,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
1964
2011
1965
2012
token_after_newlines_must_be (TOK_OPEN_PAREN);
1966
2013
const locus cond_loc = tok.loc ;
1967
- skip_parens ( );
2014
+ jsp_skip_braces (TOK_OPEN_PAREN );
1968
2015
1969
2016
dump_jump_to_end_for_rewrite ();
1970
2017
@@ -2020,7 +2067,7 @@ skip_case_clause_body (void)
2020
2067
{
2021
2068
if (token_is (TOK_OPEN_BRACE))
2022
2069
{
2023
- skip_braces ( );
2070
+ jsp_skip_braces (TOK_OPEN_BRACE );
2024
2071
}
2025
2072
skip_newlines ();
2026
2073
}
@@ -2565,73 +2612,13 @@ skip_optional_name_and_parens (void)
2565
2612
}
2566
2613
}
2567
2614
2568
- static void
2569
- skip_braces (void )
2570
- {
2571
- current_token_must_be (TOK_OPEN_BRACE);
2572
-
2573
- uint8_t nesting_level = 1 ;
2574
- while (nesting_level > 0 )
2575
- {
2576
- skip_newlines ();
2577
- if (token_is (TOK_OPEN_BRACE))
2578
- {
2579
- nesting_level++;
2580
- }
2581
- else if (token_is (TOK_CLOSE_BRACE))
2582
- {
2583
- nesting_level--;
2584
- }
2585
- }
2586
- }
2587
-
2588
2615
static void
2589
2616
skip_function (void )
2590
2617
{
2591
2618
skip_newlines ();
2592
2619
skip_optional_name_and_parens ();
2593
2620
skip_newlines ();
2594
- skip_braces ();
2595
- }
2596
-
2597
- static void
2598
- skip_squares (void )
2599
- {
2600
- current_token_must_be (TOK_OPEN_SQUARE);
2601
-
2602
- uint8_t nesting_level = 1 ;
2603
- while (nesting_level > 0 )
2604
- {
2605
- skip_newlines ();
2606
- if (token_is (TOK_OPEN_SQUARE))
2607
- {
2608
- nesting_level++;
2609
- }
2610
- else if (token_is (TOK_CLOSE_SQUARE))
2611
- {
2612
- nesting_level--;
2613
- }
2614
- }
2615
- }
2616
-
2617
- static void
2618
- skip_parens (void )
2619
- {
2620
- current_token_must_be (TOK_OPEN_PAREN);
2621
-
2622
- uint8_t nesting_level = 1 ;
2623
- while (nesting_level > 0 )
2624
- {
2625
- skip_newlines ();
2626
- if (token_is (TOK_OPEN_PAREN))
2627
- {
2628
- nesting_level++;
2629
- }
2630
- else if (token_is (TOK_CLOSE_PAREN))
2631
- {
2632
- nesting_level--;
2633
- }
2634
- }
2621
+ jsp_skip_braces (TOK_OPEN_BRACE);
2635
2622
}
2636
2623
2637
2624
static bool
@@ -2670,15 +2657,15 @@ preparse_var_decls (void)
2670
2657
}
2671
2658
else if (token_is (TOK_OPEN_BRACE))
2672
2659
{
2673
- skip_braces ( );
2660
+ jsp_skip_braces (TOK_OPEN_BRACE );
2674
2661
}
2675
2662
else if (token_is (TOK_OPEN_SQUARE))
2676
2663
{
2677
- skip_squares ( );
2664
+ jsp_skip_braces (TOK_OPEN_SQUARE );
2678
2665
}
2679
2666
else if (token_is (TOK_OPEN_PAREN))
2680
2667
{
2681
- skip_parens ( );
2668
+ jsp_skip_braces (TOK_OPEN_PAREN );
2682
2669
}
2683
2670
skip_token ();
2684
2671
}
@@ -2739,7 +2726,7 @@ preparse_scope (bool is_global)
2739
2726
}
2740
2727
else if (token_is (TOK_OPEN_BRACE))
2741
2728
{
2742
- skip_braces ( );
2729
+ jsp_skip_braces (TOK_OPEN_BRACE );
2743
2730
}
2744
2731
else
2745
2732
{
0 commit comments