@@ -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,54 @@ 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
+ * current token should at the beginning of the scope when the routine is called
182
+ */
183
+ static void
184
+ jsp_skip_braces (token_type brace_type) /* *< type of the opening brace */
185
+ {
186
+ current_token_must_be (brace_type);
187
+
188
+ token_type closing_bracket_type;
189
+
190
+ if (brace_type == TOK_OPEN_PAREN)
191
+ {
192
+ closing_bracket_type = TOK_CLOSE_PAREN;
193
+ }
194
+ else if (brace_type == TOK_OPEN_BRACE)
195
+ {
196
+ closing_bracket_type = TOK_CLOSE_BRACE;
197
+ }
198
+ else
199
+ {
200
+ JERRY_ASSERT (brace_type == TOK_OPEN_SQUARE);
201
+ closing_bracket_type = TOK_CLOSE_SQUARE;
202
+ }
203
+
204
+ skip_newlines ();
205
+
206
+ while (!token_is (closing_bracket_type)
207
+ && !token_is (TOK_EOF))
208
+ {
209
+ if (token_is (TOK_OPEN_PAREN)
210
+ || token_is (TOK_OPEN_BRACE)
211
+ || token_is (TOK_OPEN_SQUARE))
212
+ {
213
+ jsp_skip_braces (tok.type );
214
+ }
215
+
216
+ skip_newlines ();
217
+ }
218
+
219
+ current_token_must_be (closing_bracket_type);
220
+ } /* jsp_skip_braces */
221
+
176
222
/* property_name
177
223
: Identifier
178
224
| Keyword
@@ -1964,7 +2010,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
1964
2010
1965
2011
token_after_newlines_must_be (TOK_OPEN_PAREN);
1966
2012
const locus cond_loc = tok.loc ;
1967
- skip_parens ( );
2013
+ jsp_skip_braces (TOK_OPEN_PAREN );
1968
2014
1969
2015
dump_jump_to_end_for_rewrite ();
1970
2016
@@ -2020,7 +2066,7 @@ skip_case_clause_body (void)
2020
2066
{
2021
2067
if (token_is (TOK_OPEN_BRACE))
2022
2068
{
2023
- skip_braces ( );
2069
+ jsp_skip_braces (TOK_OPEN_BRACE );
2024
2070
}
2025
2071
skip_newlines ();
2026
2072
}
@@ -2565,73 +2611,13 @@ skip_optional_name_and_parens (void)
2565
2611
}
2566
2612
}
2567
2613
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
2614
static void
2589
2615
skip_function (void )
2590
2616
{
2591
2617
skip_newlines ();
2592
2618
skip_optional_name_and_parens ();
2593
2619
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
- }
2620
+ jsp_skip_braces (TOK_OPEN_BRACE);
2635
2621
}
2636
2622
2637
2623
static bool
@@ -2670,15 +2656,15 @@ preparse_var_decls (void)
2670
2656
}
2671
2657
else if (token_is (TOK_OPEN_BRACE))
2672
2658
{
2673
- skip_braces ( );
2659
+ jsp_skip_braces (TOK_OPEN_BRACE );
2674
2660
}
2675
2661
else if (token_is (TOK_OPEN_SQUARE))
2676
2662
{
2677
- skip_squares ( );
2663
+ jsp_skip_braces (TOK_OPEN_SQUARE );
2678
2664
}
2679
2665
else if (token_is (TOK_OPEN_PAREN))
2680
2666
{
2681
- skip_parens ( );
2667
+ jsp_skip_braces (TOK_OPEN_PAREN );
2682
2668
}
2683
2669
skip_token ();
2684
2670
}
@@ -2739,7 +2725,7 @@ preparse_scope (bool is_global)
2739
2725
}
2740
2726
else if (token_is (TOK_OPEN_BRACE))
2741
2727
{
2742
- skip_braces ( );
2728
+ jsp_skip_braces (TOK_OPEN_BRACE );
2743
2729
}
2744
2730
else
2745
2731
{
0 commit comments