1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* This file parses java source code and issues a tree node image
28 suitable for code generation (byte code and targeted CPU assembly
31 The grammar conforms to the Java grammar described in "The Java(TM)
32 Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
33 1996, ISBN 0-201-63451-1"
35 The following modifications were brought to the original grammar:
37 method_body: added the rule '| block SC_TK'
38 static_initializer: added the rule 'static block SC_TK'.
40 Note: All the extra rules described above should go away when the
41 empty_statement rule will work.
43 statement_nsi: 'nsi' should be read no_short_if.
45 Some rules have been modified to support JDK1.1 inner classes
46 definitions and other extensions. */
57 #include "java-tree.h"
71 #define DIR_SEPARATOR '/'
74 /* Local function prototypes */
75 static char *java_accstring_lookup PARAMS ((int));
76 static void classitf_redefinition_error PARAMS ((const char *,tree, tree, tree));
77 static void variable_redefinition_error PARAMS ((tree, tree, tree, int));
78 static tree create_class PARAMS ((int, tree, tree, tree));
79 static tree create_interface PARAMS ((int, tree, tree));
80 static void end_class_declaration PARAMS ((int));
81 static tree find_field PARAMS ((tree, tree));
82 static tree lookup_field_wrapper PARAMS ((tree, tree));
83 static int duplicate_declaration_error_p PARAMS ((tree, tree, tree));
84 static void register_fields PARAMS ((int, tree, tree));
85 static tree parser_qualified_classname PARAMS ((tree));
86 static int parser_check_super PARAMS ((tree, tree, tree));
87 static int parser_check_super_interface PARAMS ((tree, tree, tree));
88 static void check_modifiers_consistency PARAMS ((int));
89 static tree lookup_cl PARAMS ((tree));
90 static tree lookup_java_method2 PARAMS ((tree, tree, int));
91 static tree method_header PARAMS ((int, tree, tree, tree));
92 static void fix_method_argument_names PARAMS ((tree ,tree));
93 static tree method_declarator PARAMS ((tree, tree));
94 static void parse_warning_context PARAMS ((tree cl, const char *msg, ...))
96 static void issue_warning_error_from_context PARAMS ((tree, const char *msg, va_list))
97 ATTRIBUTE_PRINTF (2, 0);
98 static void parse_ctor_invocation_error PARAMS ((void));
99 static tree parse_jdk1_1_error PARAMS ((const char *));
100 static void complete_class_report_errors PARAMS ((jdep *));
101 static int process_imports PARAMS ((void));
102 static void read_import_dir PARAMS ((tree));
103 static int find_in_imports_on_demand PARAMS ((tree));
104 static void find_in_imports PARAMS ((tree));
105 static void check_static_final_variable_assignment_flag PARAMS ((tree));
106 static void reset_static_final_variable_assignment_flag PARAMS ((tree));
107 static void check_final_variable_local_assignment_flag PARAMS ((tree, tree));
108 static void reset_final_variable_local_assignment_flag PARAMS ((tree));
109 static int check_final_variable_indirect_assignment PARAMS ((tree));
110 static void check_final_variable_global_assignment_flag PARAMS ((tree));
111 static void check_inner_class_access PARAMS ((tree, tree, tree));
112 static int check_pkg_class_access PARAMS ((tree, tree));
113 static void register_package PARAMS ((tree));
114 static tree resolve_package PARAMS ((tree, tree *));
115 static tree lookup_package_type PARAMS ((const char *, int));
116 static tree lookup_package_type_and_set_next PARAMS ((const char *, int, tree *));
117 static tree resolve_class PARAMS ((tree, tree, tree, tree));
118 static void declare_local_variables PARAMS ((int, tree, tree));
119 static void source_start_java_method PARAMS ((tree));
120 static void source_end_java_method PARAMS ((void));
121 static void expand_start_java_method PARAMS ((tree));
122 static tree find_name_in_single_imports PARAMS ((tree));
123 static void check_abstract_method_header PARAMS ((tree));
124 static tree lookup_java_interface_method2 PARAMS ((tree, tree));
125 static tree resolve_expression_name PARAMS ((tree, tree *));
126 static tree maybe_create_class_interface_decl PARAMS ((tree, tree, tree, tree));
127 static int check_class_interface_creation PARAMS ((int, int, tree,
129 static tree patch_method_invocation PARAMS ((tree, tree, tree,
131 static int breakdown_qualified PARAMS ((tree *, tree *, tree));
132 static tree resolve_and_layout PARAMS ((tree, tree));
133 static tree qualify_and_find PARAMS ((tree, tree, tree));
134 static tree resolve_no_layout PARAMS ((tree, tree));
135 static int invocation_mode PARAMS ((tree, int));
136 static tree find_applicable_accessible_methods_list PARAMS ((int, tree,
138 static void search_applicable_methods_list PARAMS ((int, tree, tree, tree,
140 static tree find_most_specific_methods_list PARAMS ((tree));
141 static int argument_types_convertible PARAMS ((tree, tree));
142 static tree patch_invoke PARAMS ((tree, tree, tree));
143 static int maybe_use_access_method PARAMS ((int, tree *, tree *));
144 static tree lookup_method_invoke PARAMS ((int, tree, tree, tree, tree));
145 static tree register_incomplete_type PARAMS ((int, tree, tree, tree));
146 static tree obtain_incomplete_type PARAMS ((tree));
147 static tree java_complete_lhs PARAMS ((tree));
148 static tree java_complete_tree PARAMS ((tree));
149 static tree maybe_generate_pre_expand_clinit PARAMS ((tree));
150 static int analyze_clinit_body PARAMS ((tree));
151 static int maybe_yank_clinit PARAMS ((tree));
152 static void java_complete_expand_method PARAMS ((tree));
153 static int unresolved_type_p PARAMS ((tree, tree *));
154 static void create_jdep_list PARAMS ((struct parser_ctxt *));
155 static tree build_expr_block PARAMS ((tree, tree));
156 static tree enter_block PARAMS ((void));
157 static tree enter_a_block PARAMS ((tree));
158 static tree exit_block PARAMS ((void));
159 static tree lookup_name_in_blocks PARAMS ((tree));
160 static void maybe_absorb_scoping_blocks PARAMS ((void));
161 static tree build_method_invocation PARAMS ((tree, tree));
162 static tree build_new_invocation PARAMS ((tree, tree));
163 static tree build_assignment PARAMS ((int, int, tree, tree));
164 static tree build_binop PARAMS ((enum tree_code, int, tree, tree));
165 static int check_final_assignment PARAMS ((tree ,tree));
166 static tree patch_assignment PARAMS ((tree, tree, tree ));
167 static tree patch_binop PARAMS ((tree, tree, tree));
168 static tree build_unaryop PARAMS ((int, int, tree));
169 static tree build_incdec PARAMS ((int, int, tree, int));
170 static tree patch_unaryop PARAMS ((tree, tree));
171 static tree build_cast PARAMS ((int, tree, tree));
172 static tree build_null_of_type PARAMS ((tree));
173 static tree patch_cast PARAMS ((tree, tree));
174 static int valid_ref_assignconv_cast_p PARAMS ((tree, tree, int));
175 static int valid_builtin_assignconv_identity_widening_p PARAMS ((tree, tree));
176 static int valid_cast_to_p PARAMS ((tree, tree));
177 static int valid_method_invocation_conversion_p PARAMS ((tree, tree));
178 static tree try_builtin_assignconv PARAMS ((tree, tree, tree));
179 static tree try_reference_assignconv PARAMS ((tree, tree));
180 static tree build_unresolved_array_type PARAMS ((tree));
181 static tree build_array_from_name PARAMS ((tree, tree, tree, tree *));
182 static tree build_array_ref PARAMS ((int, tree, tree));
183 static tree patch_array_ref PARAMS ((tree));
184 static tree make_qualified_name PARAMS ((tree, tree, int));
185 static tree merge_qualified_name PARAMS ((tree, tree));
186 static tree make_qualified_primary PARAMS ((tree, tree, int));
187 static int resolve_qualified_expression_name PARAMS ((tree, tree *,
189 static void qualify_ambiguous_name PARAMS ((tree));
190 static tree resolve_field_access PARAMS ((tree, tree *, tree *));
191 static tree build_newarray_node PARAMS ((tree, tree, int));
192 static tree patch_newarray PARAMS ((tree));
193 static tree resolve_type_during_patch PARAMS ((tree));
194 static tree build_this PARAMS ((int));
195 static tree build_wfl_wrap PARAMS ((tree, int));
196 static tree build_return PARAMS ((int, tree));
197 static tree patch_return PARAMS ((tree));
198 static tree maybe_access_field PARAMS ((tree, tree, tree));
199 static int complete_function_arguments PARAMS ((tree));
200 static int check_for_static_method_reference PARAMS ((tree, tree, tree,
202 static int not_accessible_p PARAMS ((tree, tree, int));
203 static void check_deprecation PARAMS ((tree, tree));
204 static int class_in_current_package PARAMS ((tree));
205 static tree build_if_else_statement PARAMS ((int, tree, tree, tree));
206 static tree patch_if_else_statement PARAMS ((tree));
207 static tree add_stmt_to_compound PARAMS ((tree, tree, tree));
208 static tree add_stmt_to_block PARAMS ((tree, tree, tree));
209 static tree patch_exit_expr PARAMS ((tree));
210 static tree build_labeled_block PARAMS ((int, tree));
211 static tree finish_labeled_statement PARAMS ((tree, tree));
212 static tree build_bc_statement PARAMS ((int, int, tree));
213 static tree patch_bc_statement PARAMS ((tree));
214 static tree patch_loop_statement PARAMS ((tree));
215 static tree build_new_loop PARAMS ((tree));
216 static tree build_loop_body PARAMS ((int, tree, int));
217 static tree finish_loop_body PARAMS ((int, tree, tree, int));
218 static tree build_debugable_stmt PARAMS ((int, tree));
219 static tree finish_for_loop PARAMS ((int, tree, tree, tree));
220 static tree patch_switch_statement PARAMS ((tree));
221 static tree string_constant_concatenation PARAMS ((tree, tree));
222 static tree build_string_concatenation PARAMS ((tree, tree));
223 static tree patch_string_cst PARAMS ((tree));
224 static tree patch_string PARAMS ((tree));
225 static tree build_try_statement PARAMS ((int, tree, tree));
226 static tree build_try_finally_statement PARAMS ((int, tree, tree));
227 static tree patch_try_statement PARAMS ((tree));
228 static tree patch_synchronized_statement PARAMS ((tree, tree));
229 static tree patch_throw_statement PARAMS ((tree, tree));
230 static void check_thrown_exceptions PARAMS ((int, tree));
231 static int check_thrown_exceptions_do PARAMS ((tree));
232 static void purge_unchecked_exceptions PARAMS ((tree));
233 static void check_throws_clauses PARAMS ((tree, tree, tree));
234 static void finish_method_declaration PARAMS ((tree));
235 static tree build_super_invocation PARAMS ((tree));
236 static int verify_constructor_circularity PARAMS ((tree, tree));
237 static char *constructor_circularity_msg PARAMS ((tree, tree));
238 static tree build_this_super_qualified_invocation PARAMS ((int, tree, tree,
240 static const char *get_printable_method_name PARAMS ((tree));
241 static tree patch_conditional_expr PARAMS ((tree, tree, tree));
242 static tree generate_finit PARAMS ((tree));
243 static void add_instance_initializer PARAMS ((tree));
244 static void fix_constructors PARAMS ((tree));
245 static tree build_alias_initializer_parameter_list PARAMS ((int, tree,
247 static void craft_constructor PARAMS ((tree, tree));
248 static int verify_constructor_super PARAMS ((tree));
249 static tree create_artificial_method PARAMS ((tree, int, tree, tree, tree));
250 static void start_artificial_method_body PARAMS ((tree));
251 static void end_artificial_method_body PARAMS ((tree));
252 static int check_method_redefinition PARAMS ((tree, tree));
253 static int reset_method_name PARAMS ((tree));
254 static int check_method_types_complete PARAMS ((tree));
255 static void java_check_regular_methods PARAMS ((tree));
256 static void java_check_abstract_methods PARAMS ((tree));
257 static tree maybe_build_primttype_type_ref PARAMS ((tree, tree));
258 static void unreachable_stmt_error PARAMS ((tree));
259 static tree find_expr_with_wfl PARAMS ((tree));
260 static void missing_return_error PARAMS ((tree));
261 static tree build_new_array_init PARAMS ((int, tree));
262 static tree patch_new_array_init PARAMS ((tree, tree));
263 static tree maybe_build_array_element_wfl PARAMS ((tree));
264 static int array_constructor_check_entry PARAMS ((tree, tree));
265 static const char *purify_type_name PARAMS ((const char *));
266 static tree fold_constant_for_init PARAMS ((tree, tree));
267 static tree strip_out_static_field_access_decl PARAMS ((tree));
268 static jdeplist *reverse_jdep_list PARAMS ((struct parser_ctxt *));
269 static void static_ref_err PARAMS ((tree, tree, tree));
270 static void parser_add_interface PARAMS ((tree, tree, tree));
271 static void add_superinterfaces PARAMS ((tree, tree));
272 static tree jdep_resolve_class PARAMS ((jdep *));
273 static int note_possible_classname PARAMS ((const char *, int));
274 static void java_complete_expand_classes PARAMS ((void));
275 static void java_complete_expand_class PARAMS ((tree));
276 static void java_complete_expand_methods PARAMS ((tree));
277 static tree cut_identifier_in_qualified PARAMS ((tree));
278 static tree java_stabilize_reference PARAMS ((tree));
279 static tree do_unary_numeric_promotion PARAMS ((tree));
280 static char * operator_string PARAMS ((tree));
281 static tree do_merge_string_cste PARAMS ((tree, const char *, int, int));
282 static tree merge_string_cste PARAMS ((tree, tree, int));
283 static tree java_refold PARAMS ((tree));
284 static int java_decl_equiv PARAMS ((tree, tree));
285 static int binop_compound_p PARAMS ((enum tree_code));
286 static tree search_loop PARAMS ((tree));
287 static int labeled_block_contains_loop_p PARAMS ((tree, tree));
288 static int check_abstract_method_definitions PARAMS ((int, tree, tree));
289 static void java_check_abstract_method_definitions PARAMS ((tree));
290 static void java_debug_context_do PARAMS ((int));
291 static void java_parser_context_push_initialized_field PARAMS ((void));
292 static void java_parser_context_pop_initialized_field PARAMS ((void));
293 static tree reorder_static_initialized PARAMS ((tree));
294 static void java_parser_context_suspend PARAMS ((void));
295 static void java_parser_context_resume PARAMS ((void));
296 static int pop_current_osb PARAMS ((struct parser_ctxt *));
298 /* JDK 1.1 work. FIXME */
300 static tree maybe_make_nested_class_name PARAMS ((tree));
301 static void make_nested_class_name PARAMS ((tree));
302 static void set_nested_class_simple_name_value PARAMS ((tree, int));
303 static void link_nested_class_to_enclosing PARAMS ((void));
304 static tree find_as_inner_class PARAMS ((tree, tree, tree));
305 static tree find_as_inner_class_do PARAMS ((tree, tree));
306 static int check_inner_class_redefinition PARAMS ((tree, tree));
308 static tree build_thisn_assign PARAMS ((void));
309 static tree build_current_thisn PARAMS ((tree));
310 static tree build_access_to_thisn PARAMS ((tree, tree, int));
311 static tree maybe_build_thisn_access_method PARAMS ((tree));
313 static tree build_outer_field_access PARAMS ((tree, tree));
314 static tree build_outer_field_access_methods PARAMS ((tree));
315 static tree build_outer_field_access_expr PARAMS ((int, tree, tree,
317 static tree build_outer_method_access_method PARAMS ((tree));
318 static tree build_new_access_id PARAMS ((void));
319 static tree build_outer_field_access_method PARAMS ((tree, tree, tree,
322 static int outer_field_access_p PARAMS ((tree, tree));
323 static int outer_field_expanded_access_p PARAMS ((tree, tree *,
325 static tree outer_field_access_fix PARAMS ((tree, tree, tree));
326 static tree build_incomplete_class_ref PARAMS ((int, tree));
327 static tree patch_incomplete_class_ref PARAMS ((tree));
328 static tree create_anonymous_class PARAMS ((int, tree));
329 static void patch_anonymous_class PARAMS ((tree, tree, tree));
330 static void add_inner_class_fields PARAMS ((tree, tree));
332 static tree build_dot_class_method PARAMS ((tree));
333 static tree build_dot_class_method_invocation PARAMS ((tree));
334 static void create_new_parser_context PARAMS ((int));
335 static void mark_parser_ctxt PARAMS ((void *));
337 /* Number of error found so far. */
338 int java_error_count;
339 /* Number of warning found so far. */
340 int java_warning_count;
341 /* Tell when not to fold, when doing xrefs */
343 /* Cyclic inheritance report, as it can be set by layout_class */
344 const char *cyclic_inheritance_report;
346 /* Tell when we're within an instance initializer */
347 static int in_instance_initializer;
349 /* The current parser context */
350 struct parser_ctxt *ctxp;
352 /* List of things that were analyzed for which code will be generated */
353 static struct parser_ctxt *ctxp_for_generation = NULL;
355 /* binop_lookup maps token to tree_code. It is used where binary
356 operations are involved and required by the parser. RDIV_EXPR
357 covers both integral/floating point division. The code is changed
358 once the type of both operator is worked out. */
360 static enum tree_code binop_lookup[19] =
362 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
363 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
364 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
365 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
366 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
368 #define BINOP_LOOKUP(VALUE) \
369 binop_lookup [((VALUE) - PLUS_TK) % ARRAY_SIZE (binop_lookup)]
371 /* This is the end index for binary operators that can also be used
372 in compound assignements. */
373 #define BINOP_COMPOUND_CANDIDATES 11
375 /* The "$L" identifier we use to create labels. */
376 static tree label_id = NULL_TREE;
378 /* The "StringBuffer" identifier used for the String `+' operator. */
379 static tree wfl_string_buffer = NULL_TREE;
381 /* The "append" identifier used for String `+' operator. */
382 static tree wfl_append = NULL_TREE;
384 /* The "toString" identifier used for String `+' operator. */
385 static tree wfl_to_string = NULL_TREE;
387 /* The "java.lang" import qualified name. */
388 static tree java_lang_id = NULL_TREE;
390 /* The generated `inst$' identifier used for generated enclosing
391 instance/field access functions. */
392 static tree inst_id = NULL_TREE;
394 /* The "java.lang.Cloneable" qualified name. */
395 static tree java_lang_cloneable = NULL_TREE;
397 /* The "java.io.Serializable" qualified name. */
398 static tree java_io_serializable = NULL_TREE;
400 /* Context and flag for static blocks */
401 static tree current_static_block = NULL_TREE;
403 /* The generated `write_parm_value$' identifier. */
406 /* The list of all packages we've seen so far */
407 static tree package_list = NULL_TREE;
409 /* Hold THIS for the scope of the current public method decl. */
410 static tree current_this;
412 /* Hold a list of catch clauses list. The first element of this list is
413 the list of the catch clauses of the currently analysed try block. */
414 static tree currently_caught_type_list;
416 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
417 line and point it out. */
418 /* Should point out the one that don't fit. ASCII/unicode, going
421 #define check_modifiers(__message, __value, __mask) do { \
422 if ((__value) & ~(__mask)) \
424 int i, remainder = (__value) & ~(__mask); \
425 for (i = 0; i <= 10; i++) \
426 if ((1 << i) & remainder) \
427 parse_error_context (ctxp->modifier_ctx [i], (__message), \
428 java_accstring_lookup (1 << i)); \
450 /* Things defined here have to match the order of what's in the
451 binop_lookup table. */
453 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
454 %token LS_TK SRS_TK ZRS_TK
455 %token AND_TK XOR_TK OR_TK
456 %token BOOL_AND_TK BOOL_OR_TK
457 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
459 /* This maps to the same binop_lookup entry than the token above */
461 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
463 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
464 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
467 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
469 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
470 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
471 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
472 %token PAD_TK ABSTRACT_TK MODIFIER_TK
475 /* Keep those two in order, too */
476 %token DECR_TK INCR_TK
478 /* From now one, things can be in any order */
480 %token DEFAULT_TK IF_TK THROW_TK
481 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
482 %token THROWS_TK BREAK_TK IMPORT_TK
483 %token ELSE_TK INSTANCEOF_TK RETURN_TK
484 %token VOID_TK CATCH_TK INTERFACE_TK
485 %token CASE_TK EXTENDS_TK FINALLY_TK
486 %token SUPER_TK WHILE_TK CLASS_TK
487 %token SWITCH_TK CONST_TK TRY_TK
488 %token FOR_TK NEW_TK CONTINUE_TK
489 %token GOTO_TK PACKAGE_TK THIS_TK
491 %token BYTE_TK SHORT_TK INT_TK LONG_TK
492 %token CHAR_TK INTEGRAL_TK
494 %token FLOAT_TK DOUBLE_TK FP_TK
498 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
500 %token ASSIGN_ANY_TK ASSIGN_TK
501 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
503 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
504 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
506 %type <value> modifiers MODIFIER_TK final synchronized
508 %type <node> super ID_TK identifier
509 %type <node> name simple_name qualified_name
510 %type <node> type_declaration compilation_unit
511 field_declaration method_declaration extends_interfaces
512 interfaces interface_type_list
513 class_member_declaration
514 import_declarations package_declaration
515 type_declarations interface_body
516 interface_member_declaration constant_declaration
517 interface_member_declarations interface_type
518 abstract_method_declaration interface_type_list
519 %type <node> class_body_declaration class_member_declaration
520 static_initializer constructor_declaration block
521 %type <node> class_body_declarations constructor_header
522 %type <node> class_or_interface_type class_type class_type_list
523 constructor_declarator explicit_constructor_invocation
524 %type <node> dim_expr dim_exprs this_or_super throws
526 %type <node> variable_declarator_id variable_declarator
527 variable_declarators variable_initializer
528 variable_initializers constructor_body
531 %type <node> class_body block_end constructor_block_end
532 %type <node> statement statement_without_trailing_substatement
533 labeled_statement if_then_statement label_decl
534 if_then_else_statement while_statement for_statement
535 statement_nsi labeled_statement_nsi do_statement
536 if_then_else_statement_nsi while_statement_nsi
537 for_statement_nsi statement_expression_list for_init
538 for_update statement_expression expression_statement
539 primary_no_new_array expression primary
540 array_creation_expression array_type
541 class_instance_creation_expression field_access
542 method_invocation array_access something_dot_new
543 argument_list postfix_expression while_expression
544 post_increment_expression post_decrement_expression
545 unary_expression_not_plus_minus unary_expression
546 pre_increment_expression pre_decrement_expression
547 unary_expression_not_plus_minus cast_expression
548 multiplicative_expression additive_expression
549 shift_expression relational_expression
550 equality_expression and_expression
551 exclusive_or_expression inclusive_or_expression
552 conditional_and_expression conditional_or_expression
553 conditional_expression assignment_expression
554 left_hand_side assignment for_header for_begin
555 constant_expression do_statement_begin empty_statement
556 switch_statement synchronized_statement throw_statement
557 try_statement switch_expression switch_block
558 catches catch_clause catch_clause_parameter finally
559 anonymous_class_creation
560 %type <node> return_statement break_statement continue_statement
562 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
563 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
564 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
565 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
566 %type <operator> ASSIGN_ANY_TK assignment_operator
567 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
568 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
569 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
570 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
571 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
572 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
573 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
574 %type <operator> NEW_TK
576 %type <node> method_body
578 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
579 STRING_LIT_TK NULL_TK VOID_TK
581 %type <node> IF_TK WHILE_TK FOR_TK
583 %type <node> formal_parameter_list formal_parameter
584 method_declarator method_header
586 %type <node> primitive_type reference_type type
587 BOOLEAN_TK INTEGRAL_TK FP_TK
589 /* Added or modified JDK 1.1 rule types */
590 %type <node> type_literals
593 /* 19.2 Production from 2.3: The Syntactic Grammar */
596 /* Register static variables with the garbage
598 ggc_add_tree_root (&label_id, 1);
599 ggc_add_tree_root (&wfl_string_buffer, 1);
600 ggc_add_tree_root (&wfl_append, 1);
601 ggc_add_tree_root (&wfl_to_string, 1);
602 ggc_add_tree_root (&java_lang_id, 1);
603 ggc_add_tree_root (&inst_id, 1);
604 ggc_add_tree_root (&java_lang_cloneable, 1);
605 ggc_add_tree_root (&java_io_serializable, 1);
606 ggc_add_tree_root (¤t_static_block, 1);
607 ggc_add_tree_root (&wpv_id, 1);
608 ggc_add_tree_root (&package_list, 1);
609 ggc_add_tree_root (¤t_this, 1);
610 ggc_add_tree_root (¤tly_caught_type_list, 1);
611 ggc_add_root (&ctxp, 1,
612 sizeof (struct parser_ctxt *),
614 ggc_add_root (&ctxp_for_generation, 1,
615 sizeof (struct parser_ctxt *),
622 /* 19.3 Productions from 3: Lexical structure */
632 /* 19.4 Productions from 4: Types, Values and Variables */
645 class_or_interface_type
649 class_or_interface_type:
654 class_or_interface_type /* Default rule */
658 class_or_interface_type
664 int osb = pop_current_osb (ctxp);
665 tree t = build_java_array_type (($1), -1);
666 CLASS_LOADED_P (t) = 1;
668 t = build_unresolved_array_type (t);
673 int osb = pop_current_osb (ctxp);
676 t = build_unresolved_array_type (t);
681 /* 19.5 Productions from 6: Names */
683 simple_name /* Default rule */
684 | qualified_name /* Default rule */
688 identifier /* Default rule */
692 name DOT_TK identifier
693 { $$ = make_qualified_name ($1, $3, $2.location); }
700 /* 19.6: Production from 7: Packages */
703 | package_declaration
704 | import_declarations
706 | package_declaration import_declarations
707 | package_declaration type_declarations
708 | import_declarations type_declarations
709 | package_declaration import_declarations type_declarations
717 | import_declarations import_declaration
725 | type_declarations type_declaration
729 PACKAGE_TK name SC_TK
731 ctxp->package = EXPR_WFL_NODE ($2);
732 register_package (ctxp->package);
735 {yyerror ("Missing name"); RECOVER;}
736 | PACKAGE_TK name error
737 {yyerror ("';' expected"); RECOVER;}
741 single_type_import_declaration
742 | type_import_on_demand_declaration
745 single_type_import_declaration:
748 tree name = EXPR_WFL_NODE ($2), last_name;
749 int i = IDENTIFIER_LENGTH (name)-1;
750 const char *last = &IDENTIFIER_POINTER (name)[i];
751 while (last != IDENTIFIER_POINTER (name))
757 last_name = get_identifier (++last);
758 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
760 tree err = find_name_in_single_imports (last_name);
761 if (err && err != name)
763 ($2, "Ambiguous class: `%s' and `%s'",
764 IDENTIFIER_POINTER (name),
765 IDENTIFIER_POINTER (err));
767 REGISTER_IMPORT ($2, last_name);
770 REGISTER_IMPORT ($2, last_name);
773 {yyerror ("Missing name"); RECOVER;}
774 | IMPORT_TK name error
775 {yyerror ("';' expected"); RECOVER;}
778 type_import_on_demand_declaration:
779 IMPORT_TK name DOT_TK MULT_TK SC_TK
781 tree name = EXPR_WFL_NODE ($2);
782 /* Don't import java.lang.* twice. */
783 if (name != java_lang_id)
785 read_import_dir ($2);
786 ctxp->import_demand_list =
787 chainon (ctxp->import_demand_list,
788 build_tree_list ($2, NULL_TREE));
791 | IMPORT_TK name DOT_TK error
792 {yyerror ("'*' expected"); RECOVER;}
793 | IMPORT_TK name DOT_TK MULT_TK error
794 {yyerror ("';' expected"); RECOVER;}
799 { end_class_declaration (0); }
800 | interface_declaration
801 { end_class_declaration (0); }
806 yyerror ("Class or interface declaration expected");
810 /* 19.7 Shortened from the original:
811 modifiers: modifier | modifiers modifier
812 modifier: any of public... */
818 | modifiers MODIFIER_TK
823 (ctxp->modifier_ctx [$2], "Modifier `%s' declared twice",
824 java_accstring_lookup (acc));
832 /* 19.8.1 Production from $8.1: Class Declaration */
834 modifiers CLASS_TK identifier super interfaces
835 { create_class ($1, $3, $4, $5); }
837 | CLASS_TK identifier super interfaces
838 { create_class (0, $2, $3, $4); }
840 | modifiers CLASS_TK error
841 {yyerror ("Missing class name"); RECOVER;}
843 {yyerror ("Missing class name"); RECOVER;}
844 | CLASS_TK identifier error
846 if (!ctxp->class_err) yyerror ("'{' expected");
849 | modifiers CLASS_TK identifier error
850 {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
855 | EXTENDS_TK class_type
857 | EXTENDS_TK class_type error
858 {yyerror ("'{' expected"); ctxp->class_err=1;}
860 {yyerror ("Missing super class name"); ctxp->class_err=1;}
865 | IMPLEMENTS_TK interface_type_list
867 | IMPLEMENTS_TK error
870 yyerror ("Missing interface name");
877 ctxp->interface_number = 1;
878 $$ = build_tree_list ($1, NULL_TREE);
880 | interface_type_list C_TK interface_type
882 ctxp->interface_number++;
883 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
885 | interface_type_list C_TK error
886 {yyerror ("Missing interface name"); RECOVER;}
892 /* Store the location of the `}' when doing xrefs */
894 DECL_END_SOURCE_LINE (GET_CPC ()) =
895 EXPR_WFL_ADD_COL ($2.location, 1);
898 | OCB_TK class_body_declarations CCB_TK
900 /* Store the location of the `}' when doing xrefs */
902 DECL_END_SOURCE_LINE (GET_CPC ()) =
903 EXPR_WFL_ADD_COL ($3.location, 1);
908 class_body_declarations:
909 class_body_declaration
910 | class_body_declarations class_body_declaration
913 class_body_declaration:
914 class_member_declaration
916 | constructor_declaration
917 | block /* Added, JDK1.1, instance initializer */
919 TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
920 SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
924 class_member_declaration:
927 | class_declaration /* Added, JDK1.1 inner classes */
928 { end_class_declaration (1); }
929 | interface_declaration /* Added, JDK1.1 inner interfaces */
930 { end_class_declaration (1); }
934 /* 19.8.2 Productions from 8.3: Field Declarations */
936 type variable_declarators SC_TK
937 { register_fields (0, $1, $2); }
938 | modifiers type variable_declarators SC_TK
941 ("Illegal modifier `%s' for field declaration",
942 $1, FIELD_MODIFIERS);
943 check_modifiers_consistency ($1);
944 register_fields ($1, $2, $3);
948 variable_declarators:
949 /* Should we use build_decl_list () instead ? FIXME */
950 variable_declarator /* Default rule */
951 | variable_declarators C_TK variable_declarator
952 { $$ = chainon ($1, $3); }
953 | variable_declarators C_TK error
954 {yyerror ("Missing term"); RECOVER;}
958 variable_declarator_id
959 { $$ = build_tree_list ($1, NULL_TREE); }
960 | variable_declarator_id ASSIGN_TK variable_initializer
962 if (java_error_count)
965 ($1, build_assignment ($2.token, $2.location, $1, $3));
967 | variable_declarator_id ASSIGN_TK error
969 yyerror ("Missing variable initializer");
970 $$ = build_tree_list ($1, NULL_TREE);
973 | variable_declarator_id ASSIGN_TK variable_initializer error
975 yyerror ("';' expected");
976 $$ = build_tree_list ($1, NULL_TREE);
981 variable_declarator_id:
983 | variable_declarator_id OSB_TK CSB_TK
984 { $$ = build_unresolved_array_type ($1); }
986 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
987 | variable_declarator_id OSB_TK error
989 tree node = java_lval.node;
990 if (node && (TREE_CODE (node) == INTEGER_CST
991 || TREE_CODE (node) == EXPR_WITH_FILE_LOCATION))
992 yyerror ("Can't specify array dimension in a declaration");
994 yyerror ("']' expected");
997 | variable_declarator_id CSB_TK error
998 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
1001 variable_initializer:
1006 /* 19.8.3 Productions from 8.4: Method Declarations */
1010 current_function_decl = $1;
1011 if (current_function_decl
1012 && TREE_CODE (current_function_decl) == FUNCTION_DECL)
1013 source_start_java_method (current_function_decl);
1015 current_function_decl = NULL_TREE;
1018 { finish_method_declaration ($3); }
1019 | method_header error
1020 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
1024 type method_declarator throws
1025 { $$ = method_header (0, $1, $2, $3); }
1026 | VOID_TK method_declarator throws
1027 { $$ = method_header (0, void_type_node, $2, $3); }
1028 | modifiers type method_declarator throws
1029 { $$ = method_header ($1, $2, $3, $4); }
1030 | modifiers VOID_TK method_declarator throws
1031 { $$ = method_header ($1, void_type_node, $3, $4); }
1034 yyerror ("Invalid method declaration, method name required");
1037 | modifiers type error
1040 {yyerror ("Identifier expected"); RECOVER;}
1041 | modifiers VOID_TK error
1042 {yyerror ("Identifier expected"); RECOVER;}
1045 yyerror ("Invalid method declaration, return type required");
1051 identifier OP_TK CP_TK
1053 ctxp->formal_parameter_number = 0;
1054 $$ = method_declarator ($1, NULL_TREE);
1056 | identifier OP_TK formal_parameter_list CP_TK
1057 { $$ = method_declarator ($1, $3); }
1058 | method_declarator OSB_TK CSB_TK
1060 EXPR_WFL_LINECOL (wfl_operator) = $2.location;
1062 build_unresolved_array_type (TREE_PURPOSE ($1));
1063 parse_warning_context
1065 "Discouraged form of returned type specification");
1067 | identifier OP_TK error
1068 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1069 | method_declarator OSB_TK error
1070 {yyerror ("']' expected"); RECOVER;}
1073 formal_parameter_list:
1076 ctxp->formal_parameter_number = 1;
1078 | formal_parameter_list C_TK formal_parameter
1080 ctxp->formal_parameter_number += 1;
1081 $$ = chainon ($1, $3);
1083 | formal_parameter_list C_TK error
1084 { yyerror ("Missing formal parameter term"); RECOVER; }
1088 type variable_declarator_id
1090 $$ = build_tree_list ($2, $1);
1092 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1094 $$ = build_tree_list ($3, $2);
1095 ARG_FINAL_P ($$) = 1;
1099 yyerror ("Missing identifier"); RECOVER;
1104 yyerror ("Missing identifier"); RECOVER;
1112 check_modifiers ("Illegal modifier `%s'. Only `final' was expected here",
1114 if ($1 != ACC_FINAL)
1115 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1121 | THROWS_TK class_type_list
1124 {yyerror ("Missing class type term"); RECOVER;}
1129 { $$ = build_tree_list ($1, $1); }
1130 | class_type_list C_TK class_type
1131 { $$ = tree_cons ($3, $3, $1); }
1132 | class_type_list C_TK error
1133 {yyerror ("Missing class type term"); RECOVER;}
1138 | SC_TK { $$ = NULL_TREE; }
1141 /* 19.8.4 Productions from 8.5: Static Initializers */
1145 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1146 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1147 current_static_block = NULL_TREE;
1151 static: /* Test lval.sub_token here */
1154 check_modifiers ("Illegal modifier `%s' for static initializer", $1, ACC_STATIC);
1155 /* Can't have a static initializer in an innerclass */
1156 if ($1 | ACC_STATIC &&
1157 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1159 (MODIFIER_WFL (STATIC_TK),
1160 "Can't define static initializer in class `%s'. Static initializer can only be defined in top-level classes",
1161 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1162 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1166 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1167 constructor_declaration:
1170 current_function_decl = $1;
1171 source_start_java_method (current_function_decl);
1174 { finish_method_declaration ($3); }
1178 constructor_declarator throws
1179 { $$ = method_header (0, NULL_TREE, $1, $2); }
1180 | modifiers constructor_declarator throws
1181 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1184 constructor_declarator:
1185 simple_name OP_TK CP_TK
1187 ctxp->formal_parameter_number = 0;
1188 $$ = method_declarator ($1, NULL_TREE);
1190 | simple_name OP_TK formal_parameter_list CP_TK
1191 { $$ = method_declarator ($1, $3); }
1195 /* Unlike regular method, we always need a complete (empty)
1196 body so we can safely perform all the required code
1197 addition (super invocation and field initialization) */
1198 block_begin constructor_block_end
1200 BLOCK_EXPR_BODY ($2) = empty_stmt_node;
1203 | block_begin explicit_constructor_invocation constructor_block_end
1205 | block_begin block_statements constructor_block_end
1207 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1211 constructor_block_end:
1215 /* Error recovery for that rule moved down expression_statement: rule. */
1216 explicit_constructor_invocation:
1217 this_or_super OP_TK CP_TK SC_TK
1219 $$ = build_method_invocation ($1, NULL_TREE);
1220 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1221 $$ = java_method_add_stmt (current_function_decl, $$);
1223 | this_or_super OP_TK argument_list CP_TK SC_TK
1225 $$ = build_method_invocation ($1, $3);
1226 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1227 $$ = java_method_add_stmt (current_function_decl, $$);
1229 /* Added, JDK1.1 inner classes. Modified because the rule
1230 'primary' couldn't work. */
1231 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1232 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1233 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1234 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1237 this_or_super: /* Added, simplifies error diagnostics */
1240 tree wfl = build_wfl_node (this_identifier_node);
1241 EXPR_WFL_LINECOL (wfl) = $1.location;
1246 tree wfl = build_wfl_node (super_identifier_node);
1247 EXPR_WFL_LINECOL (wfl) = $1.location;
1252 /* 19.9 Productions from 9: Interfaces */
1253 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1254 interface_declaration:
1255 INTERFACE_TK identifier
1256 { create_interface (0, $2, NULL_TREE); }
1258 | modifiers INTERFACE_TK identifier
1259 { create_interface ($1, $3, NULL_TREE); }
1261 | INTERFACE_TK identifier extends_interfaces
1262 { create_interface (0, $2, $3); }
1264 | modifiers INTERFACE_TK identifier extends_interfaces
1265 { create_interface ($1, $3, $4); }
1267 | INTERFACE_TK identifier error
1268 {yyerror ("'{' expected"); RECOVER;}
1269 | modifiers INTERFACE_TK identifier error
1270 {yyerror ("'{' expected"); RECOVER;}
1274 EXTENDS_TK interface_type
1276 ctxp->interface_number = 1;
1277 $$ = build_tree_list ($2, NULL_TREE);
1279 | extends_interfaces C_TK interface_type
1281 ctxp->interface_number++;
1282 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1285 {yyerror ("Invalid interface type"); RECOVER;}
1286 | extends_interfaces C_TK error
1287 {yyerror ("Missing term"); RECOVER;}
1293 | OCB_TK interface_member_declarations CCB_TK
1297 interface_member_declarations:
1298 interface_member_declaration
1299 | interface_member_declarations interface_member_declaration
1302 interface_member_declaration:
1303 constant_declaration
1304 | abstract_method_declaration
1305 | class_declaration /* Added, JDK1.1 inner classes */
1306 { end_class_declaration (1); }
1307 | interface_declaration /* Added, JDK1.1 inner interfaces */
1308 { end_class_declaration (1); }
1311 constant_declaration:
1315 abstract_method_declaration:
1318 check_abstract_method_header ($1);
1319 current_function_decl = NULL_TREE; /* FIXME ? */
1321 | method_header error
1322 {yyerror ("';' expected"); RECOVER;}
1325 /* 19.10 Productions from 10: Arrays */
1328 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1329 | OCB_TK variable_initializers CCB_TK
1330 { $$ = build_new_array_init ($1.location, $2); }
1331 | OCB_TK variable_initializers C_TK CCB_TK
1332 { $$ = build_new_array_init ($1.location, $2); }
1335 variable_initializers:
1336 variable_initializer
1338 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1341 | variable_initializers C_TK variable_initializer
1343 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1345 | variable_initializers C_TK error
1346 {yyerror ("Missing term"); RECOVER;}
1349 /* 19.11 Production from 14: Blocks and Statements */
1353 /* Store the location of the `}' when doing xrefs */
1354 if (current_function_decl && flag_emit_xref)
1355 DECL_END_SOURCE_LINE (current_function_decl) =
1356 EXPR_WFL_ADD_COL ($2.location, 1);
1357 $$ = empty_stmt_node;
1359 | block_begin block_statements block_end
1371 maybe_absorb_scoping_blocks ();
1372 /* Store the location of the `}' when doing xrefs */
1373 if (current_function_decl && flag_emit_xref)
1374 DECL_END_SOURCE_LINE (current_function_decl) =
1375 EXPR_WFL_ADD_COL ($1.location, 1);
1377 if (!BLOCK_SUBBLOCKS ($$))
1378 BLOCK_SUBBLOCKS ($$) = empty_stmt_node;
1384 | block_statements block_statement
1388 local_variable_declaration_statement
1390 { java_method_add_stmt (current_function_decl, $1); }
1391 | class_declaration /* Added, JDK1.1 local classes */
1393 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1394 end_class_declaration (1);
1398 local_variable_declaration_statement:
1399 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1402 local_variable_declaration:
1403 type variable_declarators
1404 { declare_local_variables (0, $1, $2); }
1405 | final type variable_declarators /* Added, JDK1.1 final locals */
1406 { declare_local_variables ($1, $2, $3); }
1410 statement_without_trailing_substatement
1413 | if_then_else_statement
1416 { $$ = exit_block (); }
1420 statement_without_trailing_substatement
1421 | labeled_statement_nsi
1422 | if_then_else_statement_nsi
1423 | while_statement_nsi
1425 { $$ = exit_block (); }
1428 statement_without_trailing_substatement:
1431 | expression_statement
1435 | continue_statement
1437 | synchronized_statement
1445 if (flag_extraneous_semicolon)
1447 EXPR_WFL_SET_LINECOL (wfl_operator, lineno, -1);
1448 parse_warning_context (wfl_operator, "An empty declaration is a deprecated feature that should not be used");
1450 $$ = empty_stmt_node;
1455 identifier REL_CL_TK
1457 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1458 EXPR_WFL_NODE ($1));
1460 push_labeled_block ($$);
1461 PUSH_LABELED_BLOCK ($$);
1466 label_decl statement
1467 { $$ = finish_labeled_statement ($1, $2); }
1469 {yyerror ("':' expected"); RECOVER;}
1472 labeled_statement_nsi:
1473 label_decl statement_nsi
1474 { $$ = finish_labeled_statement ($1, $2); }
1477 /* We concentrate here a bunch of error handling rules that we couldn't write
1478 earlier, because expression_statement catches a missing ';'. */
1479 expression_statement:
1480 statement_expression SC_TK
1482 /* We have a statement. Generate a WFL around it so
1484 $$ = build_expr_wfl ($1, input_filename, lineno, 0);
1485 /* We know we have a statement, so set the debug
1486 info to be eventually generate here. */
1487 $$ = JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1491 YYNOT_TWICE yyerror ("Invalid expression statement");
1492 DRECOVER (expr_stmt);
1496 YYNOT_TWICE yyerror ("Invalid expression statement");
1497 DRECOVER (expr_stmt);
1501 YYNOT_TWICE yyerror ("Invalid expression statement");
1502 DRECOVER (expr_stmt);
1504 | this_or_super OP_TK error
1505 {yyerror ("')' expected"); RECOVER;}
1506 | this_or_super OP_TK CP_TK error
1508 parse_ctor_invocation_error ();
1511 | this_or_super OP_TK argument_list error
1512 {yyerror ("')' expected"); RECOVER;}
1513 | this_or_super OP_TK argument_list CP_TK error
1515 parse_ctor_invocation_error ();
1518 | name DOT_TK SUPER_TK error
1519 {yyerror ("'(' expected"); RECOVER;}
1520 | name DOT_TK SUPER_TK OP_TK error
1521 {yyerror ("')' expected"); RECOVER;}
1522 | name DOT_TK SUPER_TK OP_TK argument_list error
1523 {yyerror ("')' expected"); RECOVER;}
1524 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1525 {yyerror ("';' expected"); RECOVER;}
1526 | name DOT_TK SUPER_TK OP_TK CP_TK error
1527 {yyerror ("';' expected"); RECOVER;}
1530 statement_expression:
1532 | pre_increment_expression
1533 | pre_decrement_expression
1534 | post_increment_expression
1535 | post_decrement_expression
1537 | class_instance_creation_expression
1541 IF_TK OP_TK expression CP_TK statement
1543 $$ = build_if_else_statement ($2.location, $3,
1547 {yyerror ("'(' expected"); RECOVER;}
1549 {yyerror ("Missing term"); RECOVER;}
1550 | IF_TK OP_TK expression error
1551 {yyerror ("')' expected"); RECOVER;}
1554 if_then_else_statement:
1555 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1556 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1559 if_then_else_statement_nsi:
1560 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1561 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1571 /* Make into "proper list" of COMPOUND_EXPRs.
1572 I.e. make the last statment also have its own
1574 maybe_absorb_scoping_blocks ();
1575 TREE_OPERAND ($1, 1) = exit_block ();
1576 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1581 SWITCH_TK OP_TK expression CP_TK
1583 $$ = build (SWITCH_EXPR, NULL_TREE, $3, NULL_TREE);
1584 EXPR_WFL_LINECOL ($$) = $2.location;
1587 {yyerror ("'(' expected"); RECOVER;}
1588 | SWITCH_TK OP_TK error
1589 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1590 | SWITCH_TK OP_TK expression CP_TK error
1591 {yyerror ("'{' expected"); RECOVER;}
1594 /* Default assignment is there to avoid type node on switch_block
1600 | OCB_TK switch_labels CCB_TK
1602 | OCB_TK switch_block_statement_groups CCB_TK
1604 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1608 switch_block_statement_groups:
1609 switch_block_statement_group
1610 | switch_block_statement_groups switch_block_statement_group
1613 switch_block_statement_group:
1614 switch_labels block_statements
1619 | switch_labels switch_label
1623 CASE_TK constant_expression REL_CL_TK
1625 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1626 EXPR_WFL_LINECOL (lab) = $1.location;
1627 java_method_add_stmt (current_function_decl, lab);
1629 | DEFAULT_TK REL_CL_TK
1631 tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
1632 EXPR_WFL_LINECOL (lab) = $1.location;
1633 java_method_add_stmt (current_function_decl, lab);
1636 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1637 | CASE_TK constant_expression error
1638 {yyerror ("':' expected"); RECOVER;}
1640 {yyerror ("':' expected"); RECOVER;}
1644 WHILE_TK OP_TK expression CP_TK
1646 tree body = build_loop_body ($2.location, $3, 0);
1647 $$ = build_new_loop (body);
1652 while_expression statement
1653 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1655 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1656 | WHILE_TK OP_TK error
1657 {yyerror ("Missing term and ')' expected"); RECOVER;}
1658 | WHILE_TK OP_TK expression error
1659 {yyerror ("')' expected"); RECOVER;}
1662 while_statement_nsi:
1663 while_expression statement_nsi
1664 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1670 tree body = build_loop_body (0, NULL_TREE, 1);
1671 $$ = build_new_loop (body);
1673 /* Need error handing here. FIXME */
1677 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1678 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1682 for_begin SC_TK expression SC_TK for_update CP_TK statement
1684 if (TREE_CODE_CLASS (TREE_CODE ($3)) == 'c')
1685 $3 = build_wfl_node ($3);
1686 $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1688 | for_begin SC_TK SC_TK for_update CP_TK statement
1690 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1691 /* We have not condition, so we get rid of the EXIT_EXPR */
1692 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1695 | for_begin SC_TK error
1696 {yyerror ("Invalid control expression"); RECOVER;}
1697 | for_begin SC_TK expression SC_TK error
1698 {yyerror ("Invalid update expression"); RECOVER;}
1699 | for_begin SC_TK SC_TK error
1700 {yyerror ("Invalid update expression"); RECOVER;}
1704 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1705 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1706 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1708 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1709 /* We have not condition, so we get rid of the EXIT_EXPR */
1710 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1718 /* This scope defined for local variable that may be
1719 defined within the scope of the for loop */
1723 {yyerror ("'(' expected"); DRECOVER(for_1);}
1724 | FOR_TK OP_TK error
1725 {yyerror ("Invalid init statement"); RECOVER;}
1731 /* We now declare the loop body. The loop is
1732 declared as a for loop. */
1733 tree body = build_loop_body (0, NULL_TREE, 0);
1734 $$ = build_new_loop (body);
1735 FOR_LOOP_P ($$) = 1;
1736 /* The loop is added to the current block the for
1737 statement is defined within */
1738 java_method_add_stmt (current_function_decl, $$);
1741 for_init: /* Can be empty */
1742 { $$ = empty_stmt_node; }
1743 | statement_expression_list
1745 /* Init statement recorded within the previously
1746 defined block scope */
1747 $$ = java_method_add_stmt (current_function_decl, $1);
1749 | local_variable_declaration
1751 /* Local variable are recorded within the previously
1752 defined block scope */
1755 | statement_expression_list error
1756 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1759 for_update: /* Can be empty */
1760 {$$ = empty_stmt_node;}
1761 | statement_expression_list
1762 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1765 statement_expression_list:
1766 statement_expression
1767 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1768 | statement_expression_list C_TK statement_expression
1769 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1770 | statement_expression_list C_TK error
1771 {yyerror ("Missing term"); RECOVER;}
1776 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1777 | BREAK_TK identifier SC_TK
1778 { $$ = build_bc_statement ($1.location, 1, $2); }
1780 {yyerror ("Missing term"); RECOVER;}
1781 | BREAK_TK identifier error
1782 {yyerror ("';' expected"); RECOVER;}
1787 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1788 | CONTINUE_TK identifier SC_TK
1789 { $$ = build_bc_statement ($1.location, 0, $2); }
1791 {yyerror ("Missing term"); RECOVER;}
1792 | CONTINUE_TK identifier error
1793 {yyerror ("';' expected"); RECOVER;}
1798 { $$ = build_return ($1.location, NULL_TREE); }
1799 | RETURN_TK expression SC_TK
1800 { $$ = build_return ($1.location, $2); }
1802 {yyerror ("Missing term"); RECOVER;}
1803 | RETURN_TK expression error
1804 {yyerror ("';' expected"); RECOVER;}
1808 THROW_TK expression SC_TK
1810 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1811 EXPR_WFL_LINECOL ($$) = $1.location;
1814 {yyerror ("Missing term"); RECOVER;}
1815 | THROW_TK expression error
1816 {yyerror ("';' expected"); RECOVER;}
1819 synchronized_statement:
1820 synchronized OP_TK expression CP_TK block
1822 $$ = build (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1823 EXPR_WFL_LINECOL ($$) =
1824 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1826 | synchronized OP_TK expression CP_TK error
1827 {yyerror ("'{' expected"); RECOVER;}
1828 | synchronized error
1829 {yyerror ("'(' expected"); RECOVER;}
1830 | synchronized OP_TK error CP_TK
1831 {yyerror ("Missing term"); RECOVER;}
1832 | synchronized OP_TK error
1833 {yyerror ("Missing term"); RECOVER;}
1840 "Illegal modifier `%s'. Only `synchronized' was expected here",
1841 $1, ACC_SYNCHRONIZED);
1842 if ($1 != ACC_SYNCHRONIZED)
1843 MODIFIER_WFL (SYNCHRONIZED_TK) =
1844 build_wfl_node (NULL_TREE);
1849 TRY_TK block catches
1850 { $$ = build_try_statement ($1.location, $2, $3); }
1851 | TRY_TK block finally
1852 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1853 | TRY_TK block catches finally
1854 { $$ = build_try_finally_statement
1855 ($1.location, build_try_statement ($1.location,
1859 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1864 | catches catch_clause
1866 TREE_CHAIN ($2) = $1;
1872 catch_clause_parameter block
1874 java_method_add_stmt (current_function_decl, $2);
1879 catch_clause_parameter:
1880 CATCH_TK OP_TK formal_parameter CP_TK
1882 /* We add a block to define a scope for
1883 formal_parameter (CCBP). The formal parameter is
1884 declared initialized by the appropriate function
1886 tree ccpb = enter_block ();
1887 tree init = build_assignment (ASSIGN_TK, $2.location,
1889 soft_exceptioninfo_call_node);
1890 declare_local_variables (0, TREE_VALUE ($3),
1891 build_tree_list (TREE_PURPOSE ($3),
1893 $$ = build1 (CATCH_EXPR, NULL_TREE, ccpb);
1894 EXPR_WFL_LINECOL ($$) = $1.location;
1897 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1898 | CATCH_TK OP_TK error
1900 yyerror ("Missing term or ')' expected");
1901 RECOVER; $$ = NULL_TREE;
1903 | CATCH_TK OP_TK error CP_TK /* That's for () */
1904 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1911 {yyerror ("'{' expected"); RECOVER; }
1914 /* 19.12 Production from 15: Expressions */
1916 primary_no_new_array
1917 | array_creation_expression
1920 primary_no_new_array:
1923 { $$ = build_this ($1.location); }
1924 | OP_TK expression CP_TK
1926 | class_instance_creation_expression
1931 /* Added, JDK1.1 inner classes. Documentation is wrong
1932 refering to a 'ClassName' (class_name) rule that doesn't
1933 exist. Used name: instead. */
1934 | name DOT_TK THIS_TK
1936 tree wfl = build_wfl_node (this_identifier_node);
1937 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
1939 | OP_TK expression error
1940 {yyerror ("')' expected"); RECOVER;}
1942 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1943 | primitive_type DOT_TK error
1944 {yyerror ("'class' expected" ); RECOVER;}
1945 | VOID_TK DOT_TK error
1946 {yyerror ("'class' expected" ); RECOVER;}
1950 name DOT_TK CLASS_TK
1951 { $$ = build_incomplete_class_ref ($2.location, $1); }
1952 | array_type DOT_TK CLASS_TK
1953 { $$ = build_incomplete_class_ref ($2.location, $1); }
1954 | primitive_type DOT_TK CLASS_TK
1955 { $$ = build_class_ref ($1); }
1956 | VOID_TK DOT_TK CLASS_TK
1957 { $$ = build_class_ref (void_type_node); }
1960 class_instance_creation_expression:
1961 NEW_TK class_type OP_TK argument_list CP_TK
1962 { $$ = build_new_invocation ($2, $4); }
1963 | NEW_TK class_type OP_TK CP_TK
1964 { $$ = build_new_invocation ($2, NULL_TREE); }
1965 | anonymous_class_creation
1966 /* Added, JDK1.1 inner classes, modified to use name or
1967 primary instead of primary solely which couldn't work in
1969 | something_dot_new identifier OP_TK CP_TK
1971 tree ctor = build_new_invocation ($2, NULL_TREE);
1972 $$ = make_qualified_primary ($1, ctor,
1973 EXPR_WFL_LINECOL ($1));
1975 | something_dot_new identifier OP_TK CP_TK class_body
1976 | something_dot_new identifier OP_TK argument_list CP_TK
1978 tree ctor = build_new_invocation ($2, $4);
1979 $$ = make_qualified_primary ($1, ctor,
1980 EXPR_WFL_LINECOL ($1));
1982 | something_dot_new identifier OP_TK argument_list CP_TK class_body
1983 | NEW_TK error SC_TK
1984 {yyerror ("'(' expected"); DRECOVER(new_1);}
1985 | NEW_TK class_type error
1986 {yyerror ("'(' expected"); RECOVER;}
1987 | NEW_TK class_type OP_TK error
1988 {yyerror ("')' or term expected"); RECOVER;}
1989 | NEW_TK class_type OP_TK argument_list error
1990 {yyerror ("')' expected"); RECOVER;}
1991 | something_dot_new error
1992 {YYERROR_NOW; yyerror ("Identifier expected"); RECOVER;}
1993 | something_dot_new identifier error
1994 {yyerror ("'(' expected"); RECOVER;}
1997 /* Created after JDK1.1 rules originally added to
1998 class_instance_creation_expression, but modified to use
1999 'class_type' instead of 'TypeName' (type_name) which is mentionned
2000 in the documentation but doesn't exist. */
2002 anonymous_class_creation:
2003 NEW_TK class_type OP_TK argument_list CP_TK
2004 { create_anonymous_class ($1.location, $2); }
2007 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2008 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2010 end_class_declaration (1);
2012 /* Now we can craft the new expression */
2013 $$ = build_new_invocation (id, $4);
2015 /* Note that we can't possibly be here if
2016 `class_type' is an interface (in which case the
2017 anonymous class extends Object and implements
2018 `class_type', hence its constructor can't have
2021 /* Otherwise, the innerclass must feature a
2022 constructor matching `argument_list'. Anonymous
2023 classes are a bit special: it's impossible to
2024 define constructor for them, hence constructors
2025 must be generated following the hints provided by
2026 the `new' expression. Whether a super constructor
2027 of that nature exists or not is to be verified
2028 later on in verify_constructor_super.
2030 It's during the expansion of a `new' statement
2031 refering to an anonymous class that a ctor will
2032 be generated for the anonymous class, with the
2036 | NEW_TK class_type OP_TK CP_TK
2037 { create_anonymous_class ($1.location, $2); }
2040 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2041 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2043 end_class_declaration (1);
2045 /* Now we can craft the new expression. The
2046 statement doesn't need to be remember so that a
2047 constructor can be generated, since its signature
2048 is already known. */
2049 $$ = build_new_invocation (id, NULL_TREE);
2053 something_dot_new: /* Added, not part of the specs. */
2056 | primary DOT_TK NEW_TK
2063 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2064 ctxp->formal_parameter_number = 1;
2066 | argument_list C_TK expression
2068 ctxp->formal_parameter_number += 1;
2069 $$ = tree_cons (NULL_TREE, $3, $1);
2071 | argument_list C_TK error
2072 {yyerror ("Missing term"); RECOVER;}
2075 array_creation_expression:
2076 NEW_TK primitive_type dim_exprs
2077 { $$ = build_newarray_node ($2, $3, 0); }
2078 | NEW_TK class_or_interface_type dim_exprs
2079 { $$ = build_newarray_node ($2, $3, 0); }
2080 | NEW_TK primitive_type dim_exprs dims
2081 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2082 | NEW_TK class_or_interface_type dim_exprs dims
2083 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2084 /* Added, JDK1.1 anonymous array. Initial documentation rule
2086 | NEW_TK class_or_interface_type dims array_initializer
2089 int osb = pop_current_osb (ctxp);
2091 obstack_1grow (&temporary_obstack, '[');
2092 sig = obstack_finish (&temporary_obstack);
2093 $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2094 $2, get_identifier (sig), $4);
2096 | NEW_TK primitive_type dims array_initializer
2098 int osb = pop_current_osb (ctxp);
2101 type = build_java_array_type (type, -1);
2102 $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2103 build_pointer_type (type), NULL_TREE, $4);
2105 | NEW_TK error CSB_TK
2106 {yyerror ("'[' expected"); DRECOVER ("]");}
2107 | NEW_TK error OSB_TK
2108 {yyerror ("']' expected"); RECOVER;}
2113 { $$ = build_tree_list (NULL_TREE, $1); }
2114 | dim_exprs dim_expr
2115 { $$ = tree_cons (NULL_TREE, $2, $$); }
2119 OSB_TK expression CSB_TK
2121 if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2123 $2 = build_wfl_node ($2);
2124 TREE_TYPE ($2) = NULL_TREE;
2126 EXPR_WFL_LINECOL ($2) = $1.location;
2129 | OSB_TK expression error
2130 {yyerror ("']' expected"); RECOVER;}
2133 yyerror ("Missing term");
2134 yyerror ("']' expected");
2143 /* If not initialized, allocate memory for the osb
2145 if (!ctxp->osb_limit)
2147 allocate = ctxp->osb_limit = 32;
2148 ctxp->osb_depth = -1;
2150 /* If capacity overflown, reallocate a bigger chunk */
2151 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2152 allocate = ctxp->osb_limit << 1;
2156 allocate *= sizeof (int);
2157 if (ctxp->osb_number)
2158 ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
2161 ctxp->osb_number = (int *)xmalloc (allocate);
2164 CURRENT_OSB (ctxp) = 1;
2166 | dims OSB_TK CSB_TK
2167 { CURRENT_OSB (ctxp)++; }
2169 { yyerror ("']' expected"); RECOVER;}
2173 primary DOT_TK identifier
2174 { $$ = make_qualified_primary ($1, $3, $2.location); }
2175 /* FIXME - REWRITE TO:
2176 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2177 | SUPER_TK DOT_TK identifier
2179 tree super_wfl = build_wfl_node (super_identifier_node);
2180 EXPR_WFL_LINECOL (super_wfl) = $1.location;
2181 $$ = make_qualified_name (super_wfl, $3, $2.location);
2184 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2189 { $$ = build_method_invocation ($1, NULL_TREE); }
2190 | name OP_TK argument_list CP_TK
2191 { $$ = build_method_invocation ($1, $3); }
2192 | primary DOT_TK identifier OP_TK CP_TK
2194 if (TREE_CODE ($1) == THIS_EXPR)
2195 $$ = build_this_super_qualified_invocation
2196 (1, $3, NULL_TREE, 0, $2.location);
2199 tree invok = build_method_invocation ($3, NULL_TREE);
2200 $$ = make_qualified_primary ($1, invok, $2.location);
2203 | primary DOT_TK identifier OP_TK argument_list CP_TK
2205 if (TREE_CODE ($1) == THIS_EXPR)
2206 $$ = build_this_super_qualified_invocation
2207 (1, $3, $5, 0, $2.location);
2210 tree invok = build_method_invocation ($3, $5);
2211 $$ = make_qualified_primary ($1, invok, $2.location);
2214 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2216 $$ = build_this_super_qualified_invocation
2217 (0, $3, NULL_TREE, $1.location, $2.location);
2219 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2221 $$ = build_this_super_qualified_invocation
2222 (0, $3, $5, $1.location, $2.location);
2224 /* Screws up thing. I let it here until I'm convinced it can
2226 | primary DOT_TK error
2227 {yyerror ("'(' expected"); DRECOVER(bad);} */
2228 | SUPER_TK DOT_TK error CP_TK
2229 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2230 | SUPER_TK DOT_TK error DOT_TK
2231 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2235 name OSB_TK expression CSB_TK
2236 { $$ = build_array_ref ($2.location, $1, $3); }
2237 | primary_no_new_array OSB_TK expression CSB_TK
2238 { $$ = build_array_ref ($2.location, $1, $3); }
2241 yyerror ("Missing term and ']' expected");
2242 DRECOVER(array_access);
2244 | name OSB_TK expression error
2246 yyerror ("']' expected");
2247 DRECOVER(array_access);
2249 | primary_no_new_array OSB_TK error
2251 yyerror ("Missing term and ']' expected");
2252 DRECOVER(array_access);
2254 | primary_no_new_array OSB_TK expression error
2256 yyerror ("']' expected");
2257 DRECOVER(array_access);
2264 | post_increment_expression
2265 | post_decrement_expression
2268 post_increment_expression:
2269 postfix_expression INCR_TK
2270 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2273 post_decrement_expression:
2274 postfix_expression DECR_TK
2275 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2279 pre_increment_expression
2280 | pre_decrement_expression
2281 | PLUS_TK unary_expression
2282 {$$ = build_unaryop ($1.token, $1.location, $2); }
2283 | MINUS_TK unary_expression
2284 {$$ = build_unaryop ($1.token, $1.location, $2); }
2285 | unary_expression_not_plus_minus
2287 {yyerror ("Missing term"); RECOVER}
2289 {yyerror ("Missing term"); RECOVER}
2292 pre_increment_expression:
2293 INCR_TK unary_expression
2294 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2296 {yyerror ("Missing term"); RECOVER}
2299 pre_decrement_expression:
2300 DECR_TK unary_expression
2301 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2303 {yyerror ("Missing term"); RECOVER}
2306 unary_expression_not_plus_minus:
2308 | NOT_TK unary_expression
2309 {$$ = build_unaryop ($1.token, $1.location, $2); }
2310 | NEG_TK unary_expression
2311 {$$ = build_unaryop ($1.token, $1.location, $2); }
2314 {yyerror ("Missing term"); RECOVER}
2316 {yyerror ("Missing term"); RECOVER}
2319 cast_expression: /* Error handling here is potentially weak */
2320 OP_TK primitive_type dims CP_TK unary_expression
2323 int osb = pop_current_osb (ctxp);
2325 type = build_java_array_type (type, -1);
2326 $$ = build_cast ($1.location, type, $5);
2328 | OP_TK primitive_type CP_TK unary_expression
2329 { $$ = build_cast ($1.location, $2, $4); }
2330 | OP_TK expression CP_TK unary_expression_not_plus_minus
2331 { $$ = build_cast ($1.location, $2, $4); }
2332 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2335 int osb = pop_current_osb (ctxp);
2337 obstack_1grow (&temporary_obstack, '[');
2338 obstack_grow0 (&temporary_obstack,
2339 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2340 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2341 ptr = obstack_finish (&temporary_obstack);
2342 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2343 $$ = build_cast ($1.location, $2, $5);
2345 | OP_TK primitive_type OSB_TK error
2346 {yyerror ("']' expected, invalid type expression");}
2349 YYNOT_TWICE yyerror ("Invalid type expression"); RECOVER;
2352 | OP_TK primitive_type dims CP_TK error
2353 {yyerror ("Missing term"); RECOVER;}
2354 | OP_TK primitive_type CP_TK error
2355 {yyerror ("Missing term"); RECOVER;}
2356 | OP_TK name dims CP_TK error
2357 {yyerror ("Missing term"); RECOVER;}
2360 multiplicative_expression:
2362 | multiplicative_expression MULT_TK unary_expression
2364 $$ = build_binop (BINOP_LOOKUP ($2.token),
2365 $2.location, $1, $3);
2367 | multiplicative_expression DIV_TK unary_expression
2369 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2372 | multiplicative_expression REM_TK unary_expression
2374 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2377 | multiplicative_expression MULT_TK error
2378 {yyerror ("Missing term"); RECOVER;}
2379 | multiplicative_expression DIV_TK error
2380 {yyerror ("Missing term"); RECOVER;}
2381 | multiplicative_expression REM_TK error
2382 {yyerror ("Missing term"); RECOVER;}
2385 additive_expression:
2386 multiplicative_expression
2387 | additive_expression PLUS_TK multiplicative_expression
2389 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2392 | additive_expression MINUS_TK multiplicative_expression
2394 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2397 | additive_expression PLUS_TK error
2398 {yyerror ("Missing term"); RECOVER;}
2399 | additive_expression MINUS_TK error
2400 {yyerror ("Missing term"); RECOVER;}
2405 | shift_expression LS_TK additive_expression
2407 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2410 | shift_expression SRS_TK additive_expression
2412 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2415 | shift_expression ZRS_TK additive_expression
2417 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2420 | shift_expression LS_TK error
2421 {yyerror ("Missing term"); RECOVER;}
2422 | shift_expression SRS_TK error
2423 {yyerror ("Missing term"); RECOVER;}
2424 | shift_expression ZRS_TK error
2425 {yyerror ("Missing term"); RECOVER;}
2428 relational_expression:
2430 | relational_expression LT_TK shift_expression
2432 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2435 | relational_expression GT_TK shift_expression
2437 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2440 | relational_expression LTE_TK shift_expression
2442 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2445 | relational_expression GTE_TK shift_expression
2447 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2450 | relational_expression INSTANCEOF_TK reference_type
2451 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2452 | relational_expression LT_TK error
2453 {yyerror ("Missing term"); RECOVER;}
2454 | relational_expression GT_TK error
2455 {yyerror ("Missing term"); RECOVER;}
2456 | relational_expression LTE_TK error
2457 {yyerror ("Missing term"); RECOVER;}
2458 | relational_expression GTE_TK error
2459 {yyerror ("Missing term"); RECOVER;}
2460 | relational_expression INSTANCEOF_TK error
2461 {yyerror ("Invalid reference type"); RECOVER;}
2464 equality_expression:
2465 relational_expression
2466 | equality_expression EQ_TK relational_expression
2468 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2471 | equality_expression NEQ_TK relational_expression
2473 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2476 | equality_expression EQ_TK error
2477 {yyerror ("Missing term"); RECOVER;}
2478 | equality_expression NEQ_TK error
2479 {yyerror ("Missing term"); RECOVER;}
2484 | and_expression AND_TK equality_expression
2486 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2489 | and_expression AND_TK error
2490 {yyerror ("Missing term"); RECOVER;}
2493 exclusive_or_expression:
2495 | exclusive_or_expression XOR_TK and_expression
2497 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2500 | exclusive_or_expression XOR_TK error
2501 {yyerror ("Missing term"); RECOVER;}
2504 inclusive_or_expression:
2505 exclusive_or_expression
2506 | inclusive_or_expression OR_TK exclusive_or_expression
2508 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2511 | inclusive_or_expression OR_TK error
2512 {yyerror ("Missing term"); RECOVER;}
2515 conditional_and_expression:
2516 inclusive_or_expression
2517 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2519 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2522 | conditional_and_expression BOOL_AND_TK error
2523 {yyerror ("Missing term"); RECOVER;}
2526 conditional_or_expression:
2527 conditional_and_expression
2528 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2530 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2533 | conditional_or_expression BOOL_OR_TK error
2534 {yyerror ("Missing term"); RECOVER;}
2537 conditional_expression: /* Error handling here is weak */
2538 conditional_or_expression
2539 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2541 $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2542 EXPR_WFL_LINECOL ($$) = $2.location;
2544 | conditional_or_expression REL_QM_TK REL_CL_TK error
2547 yyerror ("Missing term");
2550 | conditional_or_expression REL_QM_TK error
2551 {yyerror ("Missing term"); DRECOVER (2);}
2552 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2553 {yyerror ("Missing term"); DRECOVER (3);}
2556 assignment_expression:
2557 conditional_expression
2562 left_hand_side assignment_operator assignment_expression
2563 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2564 | left_hand_side assignment_operator error
2566 YYNOT_TWICE yyerror ("Missing term");
2577 assignment_operator:
2583 assignment_expression
2586 constant_expression:
2592 /* Helper function to retrieve an OSB count. Should be used when the
2593 `dims:' rule is being used. */
2596 pop_current_osb (ctxp)
2597 struct parser_ctxt *ctxp;
2601 if (ctxp->osb_depth < 0)
2602 fatal ("osb stack underflow");
2604 to_return = CURRENT_OSB (ctxp);
2612 /* This section of the code deal with save/restoring parser contexts.
2613 Add mode documentation here. FIXME */
2615 /* Helper function. Create a new parser context. With
2616 COPY_FROM_PREVIOUS set to a non zero value, content of the previous
2617 context is copied, otherwise, the new context is zeroed. The newly
2618 created context becomes the current one. */
2621 create_new_parser_context (copy_from_previous)
2622 int copy_from_previous;
2624 struct parser_ctxt *new;
2626 new = (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2627 if (copy_from_previous)
2629 memcpy ((PTR)new, (PTR)ctxp, sizeof (struct parser_ctxt));
2630 new->saved_data_ctx = 1;
2633 memset ((PTR) new, 0, sizeof (struct parser_ctxt));
2639 /* Create a new parser context and make it the current one. */
2642 java_push_parser_context ()
2644 create_new_parser_context (0);
2647 ctxp->incomplete_class = ctxp->next->incomplete_class;
2648 ctxp->gclass_list = ctxp->next->gclass_list;
2653 java_pop_parser_context (generate)
2657 struct parser_ctxt *toFree, *next;
2666 next->incomplete_class = ctxp->incomplete_class;
2667 next->gclass_list = ctxp->gclass_list;
2668 lineno = ctxp->lineno;
2669 current_class = ctxp->class_type;
2672 /* If the old and new lexers differ, then free the old one. */
2673 if (ctxp->lexer && next && ctxp->lexer != next->lexer)
2674 java_destroy_lexer (ctxp->lexer);
2676 /* Set the single import class file flag to 0 for the current list
2677 of imported things */
2678 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2679 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 0;
2681 /* And restore those of the previous context */
2682 if ((ctxp = next)) /* Assignment is really meant here */
2683 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2684 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
2686 /* If we pushed a context to parse a class intended to be generated,
2687 we keep it so we can remember the class. What we could actually
2688 do is to just update a list of class names. */
2691 toFree->next = ctxp_for_generation;
2692 ctxp_for_generation = toFree;
2698 /* Create a parser context for the use of saving some global
2702 java_parser_context_save_global ()
2706 java_push_parser_context ();
2707 ctxp->saved_data_ctx = 1;
2710 /* If this context already stores data, create a new one suitable
2711 for data storage. */
2712 else if (ctxp->saved_data)
2713 create_new_parser_context (1);
2715 ctxp->lineno = lineno;
2716 ctxp->class_type = current_class;
2717 ctxp->filename = input_filename;
2718 ctxp->function_decl = current_function_decl;
2719 ctxp->saved_data = 1;
2722 /* Restore some global variables from the previous context. Make the
2723 previous context the current one. */
2726 java_parser_context_restore_global ()
2728 lineno = ctxp->lineno;
2729 current_class = ctxp->class_type;
2730 input_filename = ctxp->filename;
2734 BUILD_FILENAME_IDENTIFIER_NODE (s, input_filename);
2735 EXPR_WFL_FILENAME_NODE (wfl_operator) = s;
2737 current_function_decl = ctxp->function_decl;
2738 ctxp->saved_data = 0;
2739 if (ctxp->saved_data_ctx)
2740 java_pop_parser_context (0);
2743 /* Suspend vital data for the current class/function being parsed so
2744 that an other class can be parsed. Used to let local/anonymous
2745 classes be parsed. */
2748 java_parser_context_suspend ()
2750 /* This makes debugging through java_debug_context easier */
2751 static const char *name = "<inner buffer context>";
2753 /* Duplicate the previous context, use it to save the globals we're
2755 create_new_parser_context (1);
2756 ctxp->function_decl = current_function_decl;
2757 ctxp->class_type = current_class;
2759 /* Then create a new context which inherits all data from the
2760 previous one. This will be the new current context */
2761 create_new_parser_context (1);
2763 /* Help debugging */
2764 ctxp->next->filename = name;
2767 /* Resume vital data for the current class/function being parsed so
2768 that an other class can be parsed. Used to let local/anonymous
2769 classes be parsed. The trick is the data storing file position
2770 informations must be restored to their current value, so parsing
2771 can resume as if no context was ever saved. */
2774 java_parser_context_resume ()
2776 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2777 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2778 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2780 /* We need to inherit the list of classes to complete/generate */
2781 restored->incomplete_class = old->incomplete_class;
2782 restored->gclass_list = old->gclass_list;
2783 restored->classd_list = old->classd_list;
2784 restored->class_list = old->class_list;
2786 /* Restore the current class and function from the saver */
2787 current_class = saver->class_type;
2788 current_function_decl = saver->function_decl;
2790 /* Retrive the restored context */
2793 /* Re-installed the data for the parsing to carry on */
2794 bcopy (&old->marker_begining, &ctxp->marker_begining,
2795 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2797 /* Buffer context can now be discarded */
2802 /* Add a new anchor node to which all statement(s) initializing static
2803 and non static initialized upon declaration field(s) will be
2807 java_parser_context_push_initialized_field ()
2811 node = build_tree_list (NULL_TREE, NULL_TREE);
2812 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2813 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2815 node = build_tree_list (NULL_TREE, NULL_TREE);
2816 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2817 CPC_INITIALIZER_LIST (ctxp) = node;
2819 node = build_tree_list (NULL_TREE, NULL_TREE);
2820 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2821 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2824 /* Pop the lists of initialized field. If this lists aren't empty,
2825 remember them so we can use it to create and populate the finit$
2826 or <clinit> functions. */
2829 java_parser_context_pop_initialized_field ()
2832 tree class_type = TREE_TYPE (GET_CPC ());
2834 if (CPC_INITIALIZER_LIST (ctxp))
2836 stmts = CPC_INITIALIZER_STMT (ctxp);
2837 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2838 if (stmts && !java_error_count)
2839 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2842 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2844 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2845 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2846 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2847 /* Keep initialization in order to enforce 8.5 */
2848 if (stmts && !java_error_count)
2849 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2852 /* JDK 1.1 instance initializers */
2853 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2855 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2856 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2857 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2858 if (stmts && !java_error_count)
2859 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2864 reorder_static_initialized (list)
2867 /* We have to keep things in order. The alias initializer have to
2868 come first, then the initialized regular field, in reverse to
2869 keep them in lexical order. */
2870 tree marker, previous = NULL_TREE;
2871 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2872 if (TREE_CODE (marker) == TREE_LIST
2873 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2876 /* No static initialized, the list is fine as is */
2878 list = TREE_CHAIN (marker);
2880 /* No marker? reverse the whole list */
2882 list = nreverse (list);
2884 /* Otherwise, reverse what's after the marker and the new reordered
2885 sublist will replace the marker. */
2888 TREE_CHAIN (previous) = NULL_TREE;
2889 list = nreverse (list);
2890 list = chainon (TREE_CHAIN (marker), list);
2895 /* Helper functions to dump the parser context stack. */
2897 #define TAB_CONTEXT(C) \
2898 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2901 java_debug_context_do (tab)
2904 struct parser_ctxt *copy = ctxp;
2908 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2910 fprintf (stderr, "filename: %s\n", copy->filename);
2912 fprintf (stderr, "lineno: %d\n", copy->lineno);
2914 fprintf (stderr, "package: %s\n",
2916 IDENTIFIER_POINTER (copy->package) : "<none>"));
2918 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2920 fprintf (stderr, "saved data: %d\n", copy->saved_data);
2926 /* Dump the stacked up parser contexts. Intended to be called from a
2930 java_debug_context ()
2932 java_debug_context_do (0);
2937 /* Flag for the error report routine to issue the error the first time
2938 it's called (overriding the default behavior which is to drop the
2939 first invocation and honor the second one, taking advantage of a
2941 static int force_error = 0;
2943 /* Reporting an constructor invocation error. */
2945 parse_ctor_invocation_error ()
2947 if (DECL_CONSTRUCTOR_P (current_function_decl))
2948 yyerror ("Constructor invocation must be first thing in a constructor");
2950 yyerror ("Only constructors can invoke constructors");
2953 /* Reporting JDK1.1 features not implemented. */
2956 parse_jdk1_1_error (msg)
2959 sorry (": `%s' JDK1.1(TM) feature", msg);
2961 return empty_stmt_node;
2964 static int do_warning = 0;
2971 static int prev_lineno;
2972 static const char *prev_msg;
2975 char *remainder, *code_from_source;
2976 extern struct obstack temporary_obstack;
2978 if (!force_error && prev_lineno == lineno)
2981 /* Save current error location but report latter, when the context is
2983 if (ctxp->java_error_flag == 0)
2985 ctxp->java_error_flag = 1;
2987 /* Do something to use the previous line if we're reaching the
2988 end of the file... */
2989 #ifdef VERBOSE_SKELETON
2990 printf ("* Error detected (%s)\n", (msg ? msg : "(null)"));
2995 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2996 if (!force_error && msg == prev_msg && prev_lineno == elc.line)
2999 ctxp->java_error_flag = 0;
3001 java_warning_count++;
3005 if (elc.col == 0 && msg && msg[1] == ';')
3007 elc.col = ctxp->p_line->char_col-1;
3008 elc.line = ctxp->p_line->lineno;
3011 save_lineno = lineno;
3012 prev_lineno = lineno = elc.line;
3015 code_from_source = java_get_line_col (ctxp->filename, elc.line, elc.col);
3016 obstack_grow0 (&temporary_obstack,
3017 code_from_source, strlen (code_from_source));
3018 remainder = obstack_finish (&temporary_obstack);
3020 warning ("%s.\n%s", msg, remainder);
3022 error ("%s.\n%s", msg, remainder);
3024 /* This allow us to cheaply avoid an extra 'Invalid expression
3025 statement' error report when errors have been already reported on
3026 the same line. This occurs when we report an error but don't have
3027 a synchronization point other than ';', which
3028 expression_statement is the only one to take care of. */
3029 ctxp->prevent_ese = lineno = save_lineno;
3033 issue_warning_error_from_context (cl, msg, ap)
3038 const char *saved, *saved_input_filename;
3040 vsprintf (buffer, msg, ap);
3043 ctxp->elc.line = EXPR_WFL_LINENO (cl);
3044 ctxp->elc.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 :
3045 (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
3047 /* We have a CL, that's a good reason for using it if it contains data */
3048 saved = ctxp->filename;
3049 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3050 ctxp->filename = EXPR_WFL_FILENAME (cl);
3051 saved_input_filename = input_filename;
3052 input_filename = ctxp->filename;
3054 java_error (buffer);
3055 ctxp->filename = saved;
3056 input_filename = saved_input_filename;
3060 /* Issue an error message at a current source line CL */
3063 parse_error_context VPARAMS ((tree cl, const char *msg, ...))
3065 #ifndef ANSI_PROTOTYPES
3072 #ifndef ANSI_PROTOTYPES
3073 cl = va_arg (ap, tree);
3074 msg = va_arg (ap, const char *);
3076 issue_warning_error_from_context (cl, msg, ap);
3080 /* Issue a warning at a current source line CL */
3083 parse_warning_context VPARAMS ((tree cl, const char *msg, ...))
3085 #ifndef ANSI_PROTOTYPES
3092 #ifndef ANSI_PROTOTYPES
3093 cl = va_arg (ap, tree);
3094 msg = va_arg (ap, const char *);
3097 force_error = do_warning = 1;
3098 issue_warning_error_from_context (cl, msg, ap);
3099 do_warning = force_error = 0;
3104 find_expr_with_wfl (node)
3112 switch (TREE_CODE (node))
3115 node = BLOCK_EXPR_BODY (node);
3119 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3122 node = TREE_OPERAND (node, 1);
3126 node = TREE_OPERAND (node, 0);
3129 case LABELED_BLOCK_EXPR:
3130 node = TREE_OPERAND (node, 1);
3134 code = TREE_CODE_CLASS (TREE_CODE (node));
3135 if (((code == '1') || (code == '2') || (code == 'e'))
3136 && EXPR_WFL_LINECOL (node))
3144 /* Issue a missing return statement error. Uses METHOD to figure the
3145 last line of the method the error occurs in. */
3148 missing_return_error (method)
3151 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
3152 parse_error_context (wfl_operator, "Missing return statement");
3155 /* Issue an unreachable statement error. From NODE, find the next
3156 statement to report appropriately. */
3158 unreachable_stmt_error (node)
3161 /* Browse node to find the next expression node that has a WFL. Use
3162 the location to report the error */
3163 if (TREE_CODE (node) == COMPOUND_EXPR)
3164 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3166 node = find_expr_with_wfl (node);
3170 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3171 parse_error_context (wfl_operator, "Unreachable statement");
3174 fatal ("Can't get valid statement - unreachable_stmt_error");
3178 java_report_errors ()
3180 if (java_error_count)
3181 fprintf (stderr, "%d error%s",
3182 java_error_count, (java_error_count == 1 ? "" : "s"));
3183 if (java_warning_count)
3184 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3185 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3186 if (java_error_count || java_warning_count)
3187 putc ('\n', stderr);
3188 return java_error_count;
3192 java_accstring_lookup (flags)
3195 static char buffer [80];
3196 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3198 /* Access modifier looked-up first for easier report on forbidden
3200 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3201 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3202 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3203 if (flags & ACC_STATIC) COPY_RETURN ("static");
3204 if (flags & ACC_FINAL) COPY_RETURN ("final");
3205 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3206 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3207 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3208 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3209 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3210 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3217 /* Issuing error messages upon redefinition of classes, interfaces or
3221 classitf_redefinition_error (context, id, decl, cl)
3222 const char *context;
3225 parse_error_context (cl, "%s `%s' already defined in %s:%d",
3226 context, IDENTIFIER_POINTER (id),
3227 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3228 /* Here we should point out where its redefined. It's a unicode. FIXME */
3232 variable_redefinition_error (context, name, type, line)
3233 tree context, name, type;
3236 const char *type_name;
3238 /* Figure a proper name for type. We might haven't resolved it */
3239 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3240 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3242 type_name = lang_printable_name (type, 0);
3244 parse_error_context (context,
3245 "Variable `%s' is already defined in this method and was declared `%s %s' at line %d",
3246 IDENTIFIER_POINTER (name),
3247 type_name, IDENTIFIER_POINTER (name), line);
3251 build_array_from_name (type, type_wfl, name, ret_name)
3252 tree type, type_wfl, name, *ret_name;
3257 /* Eventually get more dims */
3258 string = IDENTIFIER_POINTER (name);
3259 while (string [more_dims] == '[')
3262 /* If we have, then craft a new type for this variable */
3265 name = get_identifier (&string [more_dims]);
3267 /* If we have a pointer, use its type */
3268 if (TREE_CODE (type) == POINTER_TYPE)
3269 type = TREE_TYPE (type);
3271 /* Building the first dimension of a primitive type uses this
3273 if (JPRIMITIVE_TYPE_P (type))
3275 type = build_java_array_type (type, -1);
3276 CLASS_LOADED_P (type) = 1;
3279 /* Otherwise, if we have a WFL for this type, use it (the type
3280 is already an array on an unresolved type, and we just keep
3281 on adding dimensions) */
3285 /* Add all the dimensions */
3287 type = build_unresolved_array_type (type);
3289 /* The type may have been incomplete in the first place */
3291 type = obtain_incomplete_type (type);
3299 /* Build something that the type identifier resolver will identify as
3300 being an array to an unresolved type. TYPE_WFL is a WFL on a
3304 build_unresolved_array_type (type_or_wfl)
3309 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3310 just create a array type */
3311 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3313 tree type = build_java_array_type (type_or_wfl, -1);
3314 CLASS_LOADED_P (type) = CLASS_LOADED_P (type_or_wfl);
3318 obstack_1grow (&temporary_obstack, '[');
3319 obstack_grow0 (&temporary_obstack,
3320 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3321 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3322 ptr = obstack_finish (&temporary_obstack);
3323 EXPR_WFL_NODE (type_or_wfl) = get_identifier (ptr);
3328 parser_add_interface (class_decl, interface_decl, wfl)
3329 tree class_decl, interface_decl, wfl;
3331 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3332 parse_error_context (wfl, "Interface `%s' repeated",
3333 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3336 /* Bulk of common class/interface checks. Return 1 if an error was
3337 encountered. TAG is 0 for a class, 1 for an interface. */
3340 check_class_interface_creation (is_interface, flags, raw_name, qualified_name, decl, cl)
3341 int is_interface, flags;
3342 tree raw_name, qualified_name, decl, cl;
3345 int sca = 0; /* Static class allowed */
3346 int icaf = 0; /* Inner class allowed flags */
3347 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3350 fprintf (stderr, " %s%s %s",
3351 (CPC_INNER_P () ? "inner" : ""),
3352 (is_interface ? "interface" : "class"),
3353 IDENTIFIER_POINTER (qualified_name));
3355 /* Scope of an interface/class type name:
3356 - Can't be imported by a single type import
3357 - Can't already exists in the package */
3358 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3359 && (node = find_name_in_single_imports (raw_name))