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, 2001, 2002, 2003, 2004, 2005, 2006
4 Free Software Foundation, Inc.
5 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to
21 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
24 Java and all Java-based marks are trademarks or registered trademarks
25 of Sun Microsystems, Inc. in the United States and other countries.
26 The Free Software Foundation is independent of Sun Microsystems, Inc. */
28 /* This file parses java source code and issues a tree node image
29 suitable for code generation (byte code and targeted CPU assembly
32 The grammar conforms to the Java grammar described in "The Java(TM)
33 Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
34 1996, ISBN 0-201-63451-1"
36 The following modifications were brought to the original grammar:
38 method_body: added the rule '| block SC_TK'
39 static_initializer: added the rule 'static block SC_TK'.
41 Note: All the extra rules described above should go away when the
42 empty_statement rule will work.
44 statement_nsi: 'nsi' should be read no_short_if.
46 Some rules have been modified to support JDK1.1 inner classes
47 definitions and other extensions. */
52 #include "coretypes.h"
60 #include "pretty-print.h"
61 #include "diagnostic.h"
63 #include "java-tree.h"
74 #include "tree-inline.h"
75 #include "tree-dump.h"
79 /* Local function prototypes */
80 static char *java_accstring_lookup (int);
81 static const char *accessibility_string (int);
82 static void classitf_redefinition_error (const char *,tree, tree, tree);
83 static void variable_redefinition_error (tree, tree, tree, int);
84 static tree create_class (int, tree, tree, tree);
85 static tree create_interface (int, tree, tree);
86 static void end_class_declaration (int);
87 static tree find_field (tree, tree);
88 static tree lookup_field_wrapper (tree, tree);
89 static int duplicate_declaration_error_p (tree, tree, tree);
90 static void register_fields (int, tree, tree);
91 static tree parser_qualified_classname (tree);
92 static int parser_check_super (tree, tree, tree);
93 static int parser_check_super_interface (tree, tree, tree);
94 static void check_modifiers_consistency (int);
95 static tree lookup_cl (tree);
96 static tree lookup_java_method2 (tree, tree, int);
97 static tree method_header (int, tree, tree, tree);
98 static void fix_method_argument_names (tree ,tree);
99 static tree method_declarator (tree, tree);
100 static void parse_warning_context (tree cl, const char *gmsgid, ...) ATTRIBUTE_GCC_DIAG(2,3);
101 #ifdef USE_MAPPED_LOCATION
102 static void issue_warning_error_from_context
103 (source_location, const char *gmsgid, va_list *);
105 static void issue_warning_error_from_context
106 (tree, const char *gmsgid, va_list *);
108 static void parse_ctor_invocation_error (void);
109 static tree parse_jdk1_1_error (const char *);
110 static void complete_class_report_errors (jdep *);
111 static int process_imports (void);
112 static void read_import_dir (tree);
113 static int find_in_imports_on_demand (tree, tree);
114 static void find_in_imports (tree, tree);
115 static bool inner_class_accessible (tree, tree);
116 static void check_inner_class_access (tree, tree, tree);
117 static int check_pkg_class_access (tree, tree, bool, tree);
118 static tree resolve_package (tree, tree *, tree *);
119 static tree resolve_class (tree, tree, tree, tree);
120 static void declare_local_variables (int, tree, tree);
121 static void dump_java_tree (enum tree_dump_index, tree);
122 static void source_start_java_method (tree);
123 static void source_end_java_method (void);
124 static tree find_name_in_single_imports (tree);
125 static void check_abstract_method_header (tree);
126 static tree lookup_java_interface_method2 (tree, tree);
127 static tree resolve_expression_name (tree, tree *);
128 static tree maybe_create_class_interface_decl (tree, tree, tree, tree);
129 static int check_class_interface_creation (int, int, tree, tree, tree, tree);
130 static tree patch_method_invocation (tree, tree, tree, int, int *, tree *);
131 static tree resolve_and_layout (tree, tree);
132 static tree qualify_and_find (tree, tree, tree);
133 static tree resolve_no_layout (tree, tree);
134 static int invocation_mode (tree, int);
135 static tree find_applicable_accessible_methods_list (int, tree, tree, tree);
136 static void search_applicable_methods_list (int, tree, tree, tree, tree *, tree *);
137 static tree find_most_specific_methods_list (tree, tree);
138 static int argument_types_convertible (tree, tree);
139 static tree patch_invoke (tree, tree, tree);
140 static int maybe_use_access_method (int, tree *, tree *);
141 static tree lookup_method_invoke (int, tree, tree, tree, tree);
142 static tree register_incomplete_type (int, tree, tree, tree);
143 static tree check_inner_circular_reference (tree, tree);
144 static tree check_circular_reference (tree);
145 static tree obtain_incomplete_type (tree);
146 static tree java_complete_lhs (tree);
147 static tree java_complete_tree (tree);
148 static tree maybe_generate_pre_expand_clinit (tree);
149 static int analyze_clinit_body (tree, tree);
150 static int maybe_yank_clinit (tree);
151 static void start_complete_expand_method (tree);
152 static void java_complete_expand_method (tree);
153 static void java_expand_method_bodies (tree);
154 static int unresolved_type_p (tree, tree *);
155 static void create_jdep_list (struct parser_ctxt *);
156 static tree build_expr_block (tree, tree);
157 static tree enter_block (void);
158 static tree exit_block (void);
159 static tree lookup_name_in_blocks (tree);
160 static void maybe_absorb_scoping_blocks (void);
161 static tree build_method_invocation (tree, tree);
162 static tree build_new_invocation (tree, tree);
163 static tree build_assignment (int, int, tree, tree);
164 static tree build_binop (enum tree_code, int, tree, tree);
165 static tree patch_assignment (tree, tree);
166 static tree patch_binop (tree, tree, tree, int);
167 static tree build_unaryop (int, int, tree);
168 static tree build_incdec (int, int, tree, int);
169 static tree patch_unaryop (tree, tree);
170 static tree build_cast (int, tree, tree);
171 static tree build_null_of_type (tree);
172 static tree patch_cast (tree, tree);
173 static int valid_ref_assignconv_cast_p (tree, tree, int);
174 static int valid_builtin_assignconv_identity_widening_p (tree, tree);
175 static int valid_cast_to_p (tree, tree);
176 static int valid_method_invocation_conversion_p (tree, tree);
177 static tree try_builtin_assignconv (tree, tree, tree);
178 static tree try_reference_assignconv (tree, tree);
179 static tree build_unresolved_array_type (tree);
180 static int build_type_name_from_array_name (tree, tree *);
181 static tree build_array_from_name (tree, tree, tree, tree *);
182 static tree build_array_ref (int, tree, tree);
183 static tree patch_array_ref (tree);
184 #ifdef USE_MAPPED_LOCATION
185 static tree make_qualified_name (tree, tree, source_location);
187 static tree make_qualified_name (tree, tree, int);
189 static tree merge_qualified_name (tree, tree);
190 static tree make_qualified_primary (tree, tree, int);
191 static int resolve_qualified_expression_name (tree, tree *, tree *, tree *);
192 static void qualify_ambiguous_name (tree);
193 static tree resolve_field_access (tree, tree *, tree *);
194 static tree build_newarray_node (tree, tree, int);
195 static tree patch_newarray (tree);
196 static tree resolve_type_during_patch (tree);
197 static tree build_this (int);
198 static tree build_wfl_wrap (tree, int);
199 static tree build_return (int, tree);
200 static tree patch_return (tree);
201 static tree maybe_access_field (tree, tree, tree);
202 static int complete_function_arguments (tree);
203 static int check_for_static_method_reference (tree, tree, tree, tree, tree);
204 static int not_accessible_p (tree, tree, tree, int);
205 static void check_deprecation (tree, tree);
206 static int class_in_current_package (tree);
207 static tree build_if_else_statement (int, tree, tree, tree);
208 static tree patch_if_else_statement (tree);
209 static tree add_stmt_to_block (tree, tree, tree);
210 static tree patch_exit_expr (tree);
211 static tree build_labeled_block (int, tree);
212 static tree finish_labeled_statement (tree, tree);
213 static tree build_bc_statement (int, int, tree);
214 static tree patch_bc_statement (tree);
215 static tree patch_loop_statement (tree);
216 static tree build_new_loop (tree);
217 static tree build_loop_body (int, tree, int);
218 static tree finish_loop_body (int, tree, tree, int);
219 static tree build_debugable_stmt (int, tree);
220 static tree finish_for_loop (int, tree, tree, tree);
221 static tree patch_switch_statement (tree);
222 static tree string_constant_concatenation (tree, tree);
223 static tree build_string_concatenation (tree, tree);
224 static tree patch_string_cst (tree);
225 static tree patch_string (tree);
226 static tree encapsulate_with_try_catch (int, tree, tree, tree);
227 #ifdef USE_MAPPED_LOCATION
228 static tree build_assertion (source_location, tree, tree);
230 static tree build_assertion (int, tree, tree);
232 static tree build_try_statement (int, tree, tree);
233 static tree build_try_finally_statement (int, tree, tree);
234 static tree patch_try_statement (tree);
235 static tree patch_synchronized_statement (tree, tree);
236 static tree patch_throw_statement (tree, tree);
237 static void add_exception_to_throws (tree, tree);
238 #ifdef USE_MAPPED_LOCATION
239 static void check_thrown_exceptions (source_location, tree, tree);
241 static void check_thrown_exceptions (int, tree, tree);
243 static int check_thrown_exceptions_do (tree);
244 static bool ctors_unchecked_throws_clause_p (tree);
245 static void check_concrete_throws_clauses (tree, tree, tree, tree);
246 static void check_throws_clauses (tree, tree, tree);
247 static void finish_method_declaration (tree);
248 static tree build_super_invocation (tree);
249 static int verify_constructor_circularity (tree, tree);
250 static char *constructor_circularity_msg (tree, tree);
251 static tree build_this_super_qualified_invocation (int, tree, tree, int, int);
252 static const char *get_printable_method_name (tree);
253 static tree patch_conditional_expr (tree, tree, tree);
254 static tree generate_finit (tree);
255 static tree generate_instinit (tree);
256 static tree build_instinit_invocation (tree);
257 static void fix_constructors (tree);
258 static tree build_alias_initializer_parameter_list (int, tree, tree, int *);
259 static tree craft_constructor (tree, tree);
260 static tree get_constructor_super (tree);
261 static tree create_artificial_method (tree, int, tree, tree, tree);
262 static void start_artificial_method_body (tree);
263 static void end_artificial_method_body (tree);
264 static int check_method_redefinition (tree, tree);
265 static int check_method_types_complete (tree);
266 static bool hack_is_accessible_p (tree, tree);
267 static void java_check_regular_methods (tree);
268 static void check_interface_throws_clauses (tree, tree);
269 static void java_check_abstract_methods (tree);
270 static void unreachable_stmt_error (tree);
271 static int not_accessible_field_error (tree, tree);
272 static tree find_expr_with_wfl (tree);
273 static void missing_return_error (tree);
274 static tree build_new_array_init (int, tree);
275 static tree patch_new_array_init (tree, tree);
276 static tree maybe_build_array_element_wfl (tree);
277 static int array_constructor_check_entry (tree, constructor_elt *);
278 static const char *purify_type_name (const char *);
279 static tree fold_constant_for_init (tree, tree);
280 static jdeplist *reverse_jdep_list (struct parser_ctxt *);
281 static void static_ref_err (tree, tree, tree);
282 static void parser_add_interface (tree, tree, tree);
283 static void add_superinterfaces (tree, tree);
284 static tree jdep_resolve_class (jdep *);
285 static int note_possible_classname (const char *, int);
286 static void java_complete_expand_classes (void);
287 static void java_complete_expand_class (tree);
288 static void java_complete_expand_methods (tree);
289 static tree cut_identifier_in_qualified (tree);
290 static tree java_stabilize_reference (tree);
291 static tree do_unary_numeric_promotion (tree);
292 static char * operator_string (tree);
293 static tree do_merge_string_cste (tree, const char *, int, int);
294 static tree merge_string_cste (tree, tree, int);
295 static tree java_refold (tree);
296 static int java_decl_equiv (tree, tree);
297 static int binop_compound_p (enum tree_code);
298 static tree search_loop (tree);
299 static int labeled_block_contains_loop_p (tree, tree);
300 static int check_abstract_method_definitions (int, tree, tree);
301 static void java_check_abstract_method_definitions (tree);
302 static void java_debug_context_do (int);
303 static void java_parser_context_push_initialized_field (void);
304 static void java_parser_context_pop_initialized_field (void);
305 static tree reorder_static_initialized (tree);
306 static void java_parser_context_suspend (void);
307 static void java_parser_context_resume (void);
308 static int pop_current_osb (struct parser_ctxt *);
310 /* JDK 1.1 work. FIXME */
312 static tree maybe_make_nested_class_name (tree);
313 static int make_nested_class_name (tree);
314 static void link_nested_class_to_enclosing (void);
315 static tree resolve_inner_class (tree, tree, tree, tree);
316 static tree find_as_inner_class (tree, tree, tree);
317 static tree find_as_inner_class_do (tree, tree);
318 static int check_inner_class_redefinition (tree, tree);
320 static tree build_thisn_assign (void);
321 static tree build_current_thisn (tree);
322 static tree build_access_to_thisn (tree, tree, int);
323 static tree maybe_build_thisn_access_method (tree);
325 static tree build_nested_field_access (tree, tree);
326 static tree build_nested_field_access_methods (tree);
327 static tree build_nested_field_access_method (tree, tree, tree, tree, tree);
328 static tree build_nested_field_access_expr (int, tree, tree, tree, tree);
329 static tree build_nested_method_access_method (tree);
330 static tree build_new_access_id (void);
332 static int nested_member_access_p (tree, tree);
333 static int nested_field_expanded_access_p (tree, tree *, tree *, tree *);
334 static tree nested_field_access_fix (tree, tree, tree);
336 static tree build_incomplete_class_ref (int, tree);
337 static tree patch_incomplete_class_ref (tree);
338 static tree create_anonymous_class (tree);
339 static void patch_anonymous_class (tree, tree, tree);
340 static void add_inner_class_fields (tree, tree);
342 static tree build_dot_class_method (tree);
343 static tree build_dot_class_method_invocation (tree, tree);
344 static void create_new_parser_context (int);
345 static tree maybe_build_class_init_for_field (tree, tree);
347 static int emit_test_initialization (void **, void *);
349 static char *string_convert_int_cst (tree);
351 /* Number of error found so far. */
352 int java_error_count;
353 /* Number of warning found so far. */
354 int java_warning_count;
355 /* Cyclic inheritance report, as it can be set by layout_class */
356 const char *cyclic_inheritance_report;
358 /* The current parser context */
359 struct parser_ctxt *ctxp;
361 /* List of things that were analyzed for which code will be generated */
362 struct parser_ctxt *ctxp_for_generation = NULL;
363 struct parser_ctxt *ctxp_for_generation_last = NULL;
365 /* binop_lookup maps token to tree_code. It is used where binary
366 operations are involved and required by the parser. RDIV_EXPR
367 covers both integral/floating point division. The code is changed
368 once the type of both operator is worked out. */
370 static const enum tree_code binop_lookup[19] =
372 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
373 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
374 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
375 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
376 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
378 #define BINOP_LOOKUP(VALUE) \
379 binop_lookup [((VALUE) - PLUS_TK) % ARRAY_SIZE (binop_lookup)]
381 /* This is the end index for binary operators that can also be used
382 in compound assignments. */
383 #define BINOP_COMPOUND_CANDIDATES 11
385 /* The "$L" identifier we use to create labels. */
386 static GTY(()) tree label_id;
388 /* The "StringBuffer" identifier used for the String `+' operator. */
389 static GTY(()) tree wfl_string_buffer;
391 /* The "append" identifier used for String `+' operator. */
392 static GTY(()) tree wfl_append;
394 /* The "toString" identifier used for String `+' operator. */
395 static GTY(()) tree wfl_to_string;
397 /* The "java.lang" import qualified name. */
398 static GTY(()) tree java_lang_id;
400 /* The generated `inst$' identifier used for generated enclosing
401 instance/field access functions. */
402 static GTY(()) tree inst_id;
404 /* Context and flag for static blocks */
405 static GTY(()) tree current_static_block;
407 /* The generated `write_parm_value$' identifier. */
408 static GTY(()) tree wpv_id;
410 /* Hold THIS for the scope of the current method decl. */
411 static GTY(()) tree current_this;
413 /* Hold a list of catch clauses list. The first element of this list is
414 the list of the catch clauses of the currently analyzed try block. */
415 static GTY(()) tree currently_caught_type_list;
417 /* This holds a linked list of all the case labels for the current
418 switch statement. It is only used when checking to see if there
419 are duplicate labels. FIXME: probably this should just be attached
420 to the switch itself; then it could be referenced via
421 `ctxp->current_loop'. */
422 static GTY(()) tree case_label_list;
424 /* Anonymous class counter. Will be reset to 1 every time a non
425 anonymous class gets created. */
426 static int anonymous_class_counter = 1;
428 static GTY(()) tree src_parse_roots[1];
430 /* All classes seen from source code */
431 #define gclass_list src_parse_roots[0]
433 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
434 line and point it out. */
435 /* Should point out the one that don't fit. ASCII/unicode, going
438 #define check_modifiers(__message, __value, __mask) do { \
439 if ((__value) & ~(__mask)) \
441 size_t i, remainder = (__value) & ~(__mask); \
442 for (i = 0; i < ARRAY_SIZE (ctxp->modifier_ctx); i++) \
443 if ((1 << i) & remainder) \
444 parse_error_context (ctxp->modifier_ctx [i], (__message), \
445 java_accstring_lookup (1 << i)); \
456 #ifdef USE_MAPPED_LOCATION
457 source_location location;
466 #ifdef USE_MAPPED_LOCATION
467 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
468 SET_EXPR_LOCATION(EXPR, (TOKEN).location)
470 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
471 (EXPR_WFL_LINECOL (EXPR) = (TOKEN).location)
479 /* Things defined here have to match the order of what's in the
480 binop_lookup table. */
482 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
483 %token LS_TK SRS_TK ZRS_TK
484 %token AND_TK XOR_TK OR_TK
485 %token BOOL_AND_TK BOOL_OR_TK
486 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
488 /* This maps to the same binop_lookup entry than the token above */
490 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
492 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
493 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
496 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
498 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
499 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
500 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
501 %token PAD_TK ABSTRACT_TK STRICT_TK
504 /* Keep those two in order, too */
505 %token DECR_TK INCR_TK
507 /* From now one, things can be in any order */
509 %token DEFAULT_TK IF_TK THROW_TK
510 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
511 %token THROWS_TK BREAK_TK IMPORT_TK
512 %token ELSE_TK INSTANCEOF_TK RETURN_TK
513 %token VOID_TK CATCH_TK INTERFACE_TK
514 %token CASE_TK EXTENDS_TK FINALLY_TK
515 %token SUPER_TK WHILE_TK CLASS_TK
516 %token SWITCH_TK CONST_TK TRY_TK
517 %token FOR_TK NEW_TK CONTINUE_TK
518 %token GOTO_TK PACKAGE_TK THIS_TK
521 %token BYTE_TK SHORT_TK INT_TK LONG_TK
522 %token CHAR_TK INTEGRAL_TK
524 %token FLOAT_TK DOUBLE_TK FP_TK
528 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
530 %token ASSIGN_ANY_TK ASSIGN_TK
531 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
533 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
534 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
536 %type <value> modifiers MODIFIER_TK final synchronized
538 %type <node> super ID_TK identifier
539 %type <node> name simple_name qualified_name
540 %type <node> type_declaration compilation_unit
541 field_declaration method_declaration extends_interfaces
542 interfaces interface_type_list
543 import_declarations package_declaration
544 type_declarations interface_body
545 interface_member_declaration constant_declaration
546 interface_member_declarations interface_type
547 abstract_method_declaration
548 %type <node> class_body_declaration class_member_declaration
549 static_initializer constructor_declaration block
550 %type <node> class_body_declarations constructor_header
551 %type <node> class_or_interface_type class_type class_type_list
552 constructor_declarator explicit_constructor_invocation
553 %type <node> dim_expr dim_exprs this_or_super throws
555 %type <node> variable_declarator_id variable_declarator
556 variable_declarators variable_initializer
557 variable_initializers constructor_body
560 %type <node> class_body block_end constructor_block_end
561 %type <node> statement statement_without_trailing_substatement
562 labeled_statement if_then_statement label_decl
563 if_then_else_statement while_statement for_statement
564 statement_nsi labeled_statement_nsi do_statement
565 if_then_else_statement_nsi while_statement_nsi
566 for_statement_nsi statement_expression_list for_init
567 for_update statement_expression expression_statement
568 primary_no_new_array expression primary array_type
569 array_creation_initialized array_creation_uninitialized
570 class_instance_creation_expression field_access
571 method_invocation array_access something_dot_new
572 argument_list postfix_expression while_expression
573 post_increment_expression post_decrement_expression
574 unary_expression_not_plus_minus unary_expression
575 pre_increment_expression pre_decrement_expression
577 multiplicative_expression additive_expression
578 shift_expression relational_expression
579 equality_expression and_expression
580 exclusive_or_expression inclusive_or_expression
581 conditional_and_expression conditional_or_expression
582 conditional_expression assignment_expression
583 left_hand_side assignment for_header for_begin
584 constant_expression do_statement_begin empty_statement
585 switch_statement synchronized_statement throw_statement
586 try_statement assert_statement
587 switch_expression switch_block
588 catches catch_clause catch_clause_parameter finally
589 anonymous_class_creation trap_overflow_corner_case
590 %type <node> return_statement break_statement continue_statement
592 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
593 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
594 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
595 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
596 %type <operator> ASSIGN_ANY_TK assignment_operator
597 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
598 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
599 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
600 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
601 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
602 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
603 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
604 %type <operator> NEW_TK ASSERT_TK
606 %type <node> method_body
608 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
609 STRING_LIT_TK NULL_TK VOID_TK
611 %type <node> IF_TK WHILE_TK FOR_TK
613 %type <node> formal_parameter_list formal_parameter
614 method_declarator method_header
616 %type <node> primitive_type reference_type type
617 BOOLEAN_TK INTEGRAL_TK FP_TK
619 /* Added or modified JDK 1.1 rule types */
620 %type <node> type_literals
623 /* 19.2 Production from 2.3: The Syntactic Grammar */
624 goal: compilation_unit
628 /* 19.3 Productions from 3: Lexical structure */
638 /* 19.4 Productions from 4: Types, Values and Variables */
651 class_or_interface_type
655 class_or_interface_type:
660 class_or_interface_type /* Default rule */
664 class_or_interface_type
670 int osb = pop_current_osb (ctxp);
671 tree t = build_java_array_type (($1), -1);
673 t = build_unresolved_array_type (t);
678 int osb = pop_current_osb (ctxp);
681 t = build_unresolved_array_type (t);
686 /* 19.5 Productions from 6: Names */
688 simple_name /* Default rule */
689 | qualified_name /* Default rule */
693 identifier /* Default rule */
697 name DOT_TK identifier
698 { $$ = make_qualified_name ($1, $3, $2.location); }
705 /* 19.6: Production from 7: Packages */
708 | package_declaration
709 | import_declarations
711 | package_declaration import_declarations
712 | package_declaration type_declarations
713 | import_declarations type_declarations
714 | package_declaration import_declarations type_declarations
722 | import_declarations import_declaration
730 | type_declarations type_declaration
734 PACKAGE_TK name SC_TK
736 ctxp->package = EXPR_WFL_NODE ($2);
739 {yyerror ("Missing name"); RECOVER;}
740 | PACKAGE_TK name error
741 {yyerror ("';' expected"); RECOVER;}
745 single_type_import_declaration
746 | type_import_on_demand_declaration
749 single_type_import_declaration:
752 tree name = EXPR_WFL_NODE ($2), last_name;
753 int i = IDENTIFIER_LENGTH (name)-1;
754 const char *last = &IDENTIFIER_POINTER (name)[i];
755 while (last != IDENTIFIER_POINTER (name))
761 last_name = get_identifier (++last);
762 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
764 tree err = find_name_in_single_imports (last_name);
765 if (err && err != name)
767 ($2, "Ambiguous class: %qs and %qs",
768 IDENTIFIER_POINTER (name),
769 IDENTIFIER_POINTER (err));
771 REGISTER_IMPORT ($2, last_name);
774 REGISTER_IMPORT ($2, last_name);
777 {yyerror ("Missing name"); RECOVER;}
778 | IMPORT_TK name error
779 {yyerror ("';' expected"); RECOVER;}
782 type_import_on_demand_declaration:
783 IMPORT_TK name DOT_TK MULT_TK SC_TK
785 tree name = EXPR_WFL_NODE ($2);
787 /* Search for duplicates. */
788 for (it = ctxp->import_demand_list; it; it = TREE_CHAIN (it))
789 if (EXPR_WFL_NODE (TREE_PURPOSE (it)) == name)
791 /* Don't import the same thing more than once, just ignore
792 duplicates (7.5.2) */
795 read_import_dir ($2);
796 ctxp->import_demand_list =
797 chainon (ctxp->import_demand_list,
798 build_tree_list ($2, NULL_TREE));
801 | IMPORT_TK name DOT_TK error
802 {yyerror ("'*' expected"); RECOVER;}
803 | IMPORT_TK name DOT_TK MULT_TK error
804 {yyerror ("';' expected"); RECOVER;}
809 { end_class_declaration (0); }
810 | interface_declaration
811 { end_class_declaration (0); }
816 yyerror ("Class or interface declaration expected");
820 /* 19.7 Shortened from the original:
821 modifiers: modifier | modifiers modifier
822 modifier: any of public... */
828 | modifiers MODIFIER_TK
833 (ctxp->modifier_ctx [$2], "Modifier %qs declared twice",
834 java_accstring_lookup (acc));
842 /* 19.8.1 Production from $8.1: Class Declaration */
844 modifiers CLASS_TK identifier super interfaces
845 { create_class ($1, $3, $4, $5); }
848 | CLASS_TK identifier super interfaces
849 { create_class (0, $2, $3, $4); }
852 | modifiers CLASS_TK error
853 { yyerror ("Missing class name"); RECOVER; }
855 { yyerror ("Missing class name"); RECOVER; }
856 | CLASS_TK identifier error
858 if (!ctxp->class_err) yyerror ("'{' expected");
861 | modifiers CLASS_TK identifier error
862 { if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER; }
867 | EXTENDS_TK class_type
869 | EXTENDS_TK class_type error
870 {yyerror ("'{' expected"); ctxp->class_err=1;}
872 {yyerror ("Missing super class name"); ctxp->class_err=1;}
877 | IMPLEMENTS_TK interface_type_list
879 | IMPLEMENTS_TK error
882 yyerror ("Missing interface name");
889 ctxp->interface_number = 1;
890 $$ = build_tree_list ($1, NULL_TREE);
892 | interface_type_list C_TK interface_type
894 ctxp->interface_number++;
895 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
897 | interface_type_list C_TK error
898 {yyerror ("Missing interface name"); RECOVER;}
906 | OCB_TK class_body_declarations CCB_TK
912 class_body_declarations:
913 class_body_declaration
914 | class_body_declarations class_body_declaration
917 class_body_declaration:
918 class_member_declaration
920 | constructor_declaration
921 | block /* Added, JDK1.1, instance initializer */
923 if (!IS_EMPTY_STMT ($1))
925 TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
926 SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
931 class_member_declaration:
934 | class_declaration /* Added, JDK1.1 inner classes */
935 { end_class_declaration (1); }
936 | interface_declaration /* Added, JDK1.1 inner interfaces */
937 { end_class_declaration (1); }
941 /* 19.8.2 Productions from 8.3: Field Declarations */
943 type variable_declarators SC_TK
944 { register_fields (0, $1, $2); }
945 | modifiers type variable_declarators SC_TK
948 ("Illegal modifier %qs for field declaration",
949 $1, FIELD_MODIFIERS);
950 check_modifiers_consistency ($1);
951 register_fields ($1, $2, $3);
955 variable_declarators:
956 /* Should we use build_decl_list () instead ? FIXME */
957 variable_declarator /* Default rule */
958 | variable_declarators C_TK variable_declarator
959 { $$ = chainon ($1, $3); }
960 | variable_declarators C_TK error
961 {yyerror ("Missing term"); RECOVER;}
965 variable_declarator_id
966 { $$ = build_tree_list ($1, NULL_TREE); }
967 | variable_declarator_id ASSIGN_TK variable_initializer
969 if (java_error_count)
972 ($1, build_assignment ($2.token, $2.location, $1, $3));
974 | variable_declarator_id ASSIGN_TK error
976 yyerror ("Missing variable initializer");
977 $$ = build_tree_list ($1, NULL_TREE);
980 | variable_declarator_id ASSIGN_TK variable_initializer error
982 yyerror ("';' expected");
983 $$ = build_tree_list ($1, NULL_TREE);
988 variable_declarator_id:
990 | variable_declarator_id OSB_TK CSB_TK
991 { $$ = build_unresolved_array_type ($1); }
993 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
994 | variable_declarator_id OSB_TK error
996 yyerror ("']' expected");
999 | variable_declarator_id CSB_TK error
1000 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
1003 variable_initializer:
1008 /* 19.8.3 Productions from 8.4: Method Declarations */
1012 current_function_decl = $1;
1013 if (current_function_decl
1014 && TREE_CODE (current_function_decl) == FUNCTION_DECL)
1015 source_start_java_method (current_function_decl);
1017 current_function_decl = NULL_TREE;
1020 { finish_method_declaration ($3); }
1021 | method_header error
1022 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
1026 type method_declarator throws
1027 { $$ = method_header (0, $1, $2, $3); }
1028 | VOID_TK method_declarator throws
1029 { $$ = method_header (0, void_type_node, $2, $3); }
1030 | modifiers type method_declarator throws
1031 { $$ = method_header ($1, $2, $3, $4); }
1032 | modifiers VOID_TK method_declarator throws
1033 { $$ = method_header ($1, void_type_node, $3, $4); }
1036 yyerror ("Invalid method declaration, method name required");
1040 | modifiers type error
1042 yyerror ("Identifier expected");
1048 yyerror ("Identifier expected");
1052 | modifiers VOID_TK error
1054 yyerror ("Identifier expected");
1060 yyerror ("Invalid method declaration, return type required");
1067 identifier OP_TK CP_TK
1069 ctxp->formal_parameter_number = 0;
1070 $$ = method_declarator ($1, NULL_TREE);
1072 | identifier OP_TK formal_parameter_list CP_TK
1073 { $$ = method_declarator ($1, $3); }
1074 | method_declarator OSB_TK CSB_TK
1076 SET_EXPR_LOCATION_FROM_TOKEN (wfl_operator, $2);
1078 build_unresolved_array_type (TREE_PURPOSE ($1));
1079 parse_warning_context
1081 "Discouraged form of returned type specification");
1083 | identifier OP_TK error
1084 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1085 | method_declarator OSB_TK error
1086 {yyerror ("']' expected"); RECOVER;}
1089 formal_parameter_list:
1092 ctxp->formal_parameter_number = 1;
1094 | formal_parameter_list C_TK formal_parameter
1096 ctxp->formal_parameter_number += 1;
1097 $$ = chainon ($1, $3);
1099 | formal_parameter_list C_TK error
1100 { yyerror ("Missing formal parameter term"); RECOVER; }
1104 type variable_declarator_id
1106 $$ = build_tree_list ($2, $1);
1108 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1110 $$ = build_tree_list ($3, $2);
1111 ARG_FINAL_P ($$) = 1;
1115 yyerror ("Missing identifier"); RECOVER;
1120 yyerror ("Missing identifier"); RECOVER;
1128 check_modifiers ("Illegal modifier %qs. Only %<final%> was expected here",
1130 if ($1 != ACC_FINAL)
1131 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1137 | THROWS_TK class_type_list
1140 {yyerror ("Missing class type term"); RECOVER;}
1145 { $$ = build_tree_list ($1, $1); }
1146 | class_type_list C_TK class_type
1147 { $$ = tree_cons ($3, $3, $1); }
1148 | class_type_list C_TK error
1149 {yyerror ("Missing class type term"); RECOVER;}
1154 | SC_TK { $$ = NULL_TREE; }
1157 /* 19.8.4 Productions from 8.5: Static Initializers */
1161 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1162 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1163 current_static_block = NULL_TREE;
1167 static: /* Test lval.sub_token here */
1170 check_modifiers ("Illegal modifier %qs for static initializer", $1, ACC_STATIC);
1171 /* Can't have a static initializer in an innerclass */
1172 if ($1 | ACC_STATIC &&
1173 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1175 (MODIFIER_WFL (STATIC_TK),
1176 "Can't define static initializer in class %qs. Static initializer can only be defined in top-level classes",
1177 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1178 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1182 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1183 constructor_declaration:
1186 current_function_decl = $1;
1187 source_start_java_method (current_function_decl);
1190 { finish_method_declaration ($3); }
1194 constructor_declarator throws
1195 { $$ = method_header (0, NULL_TREE, $1, $2); }
1196 | modifiers constructor_declarator throws
1197 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1200 constructor_declarator:
1201 simple_name OP_TK CP_TK
1203 ctxp->formal_parameter_number = 0;
1204 $$ = method_declarator ($1, NULL_TREE);
1206 | simple_name OP_TK formal_parameter_list CP_TK
1207 { $$ = method_declarator ($1, $3); }
1211 /* Unlike regular method, we always need a complete (empty)
1212 body so we can safely perform all the required code
1213 addition (super invocation and field initialization) */
1214 block_begin constructor_block_end
1216 BLOCK_EXPR_BODY ($2) = build_java_empty_stmt ();
1219 | block_begin explicit_constructor_invocation constructor_block_end
1221 | block_begin block_statements constructor_block_end
1223 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1227 constructor_block_end:
1231 /* Error recovery for that rule moved down expression_statement: rule. */
1232 explicit_constructor_invocation:
1233 this_or_super OP_TK CP_TK SC_TK
1235 $$ = build_method_invocation ($1, NULL_TREE);
1236 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1237 $$ = java_method_add_stmt (current_function_decl, $$);
1239 | this_or_super OP_TK argument_list CP_TK SC_TK
1241 $$ = build_method_invocation ($1, $3);
1242 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1243 $$ = java_method_add_stmt (current_function_decl, $$);
1245 /* Added, JDK1.1 inner classes. Modified because the rule
1246 'primary' couldn't work. */
1247 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1248 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1249 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1250 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1253 this_or_super: /* Added, simplifies error diagnostics */
1256 tree wfl = build_wfl_node (this_identifier_node);
1257 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1262 tree wfl = build_wfl_node (super_identifier_node);
1263 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1268 /* 19.9 Productions from 9: Interfaces */
1269 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1270 interface_declaration:
1271 INTERFACE_TK identifier
1272 { create_interface (0, $2, NULL_TREE); }
1275 | modifiers INTERFACE_TK identifier
1276 { create_interface ($1, $3, NULL_TREE); }
1279 | INTERFACE_TK identifier extends_interfaces
1280 { create_interface (0, $2, $3); }
1283 | modifiers INTERFACE_TK identifier extends_interfaces
1284 { create_interface ($1, $3, $4); }
1287 | INTERFACE_TK identifier error
1288 { yyerror ("'{' expected"); RECOVER; }
1289 | modifiers INTERFACE_TK identifier error
1290 { yyerror ("'{' expected"); RECOVER; }
1294 EXTENDS_TK interface_type
1296 ctxp->interface_number = 1;
1297 $$ = build_tree_list ($2, NULL_TREE);
1299 | extends_interfaces C_TK interface_type
1301 ctxp->interface_number++;
1302 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1305 {yyerror ("Invalid interface type"); RECOVER;}
1306 | extends_interfaces C_TK error
1307 {yyerror ("Missing term"); RECOVER;}
1313 | OCB_TK interface_member_declarations CCB_TK
1317 interface_member_declarations:
1318 interface_member_declaration
1319 | interface_member_declarations interface_member_declaration
1322 interface_member_declaration:
1323 constant_declaration
1324 | abstract_method_declaration
1325 | class_declaration /* Added, JDK1.1 inner classes */
1326 { end_class_declaration (1); }
1327 | interface_declaration /* Added, JDK1.1 inner interfaces */
1328 { end_class_declaration (1); }
1332 constant_declaration:
1336 abstract_method_declaration:
1339 check_abstract_method_header ($1);
1340 current_function_decl = NULL_TREE; /* FIXME ? */
1342 | method_header error
1343 {yyerror ("';' expected"); RECOVER;}
1346 /* 19.10 Productions from 10: Arrays */
1349 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1350 | OCB_TK C_TK CCB_TK
1351 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1352 | OCB_TK variable_initializers CCB_TK
1353 { $$ = build_new_array_init ($1.location, $2); }
1354 | OCB_TK variable_initializers C_TK CCB_TK
1355 { $$ = build_new_array_init ($1.location, $2); }
1358 variable_initializers:
1359 variable_initializer
1361 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1364 | variable_initializers C_TK variable_initializer
1366 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1368 | variable_initializers C_TK error
1369 {yyerror ("Missing term"); RECOVER;}
1372 /* 19.11 Production from 14: Blocks and Statements */
1374 block_begin block_end
1376 | block_begin block_statements block_end
1388 maybe_absorb_scoping_blocks ();
1390 if (!BLOCK_SUBBLOCKS ($$))
1391 BLOCK_SUBBLOCKS ($$) = build_java_empty_stmt ();
1397 | block_statements block_statement
1401 local_variable_declaration_statement
1403 { java_method_add_stmt (current_function_decl, $1); }
1404 | class_declaration /* Added, JDK1.1 local classes */
1406 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1407 end_class_declaration (1);
1411 local_variable_declaration_statement:
1412 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1415 local_variable_declaration:
1416 type variable_declarators
1417 { declare_local_variables (0, $1, $2); }
1418 | final type variable_declarators /* Added, JDK1.1 final locals */
1419 { declare_local_variables ($1, $2, $3); }
1423 statement_without_trailing_substatement
1426 | if_then_else_statement
1429 { $$ = exit_block (); }
1433 statement_without_trailing_substatement
1434 | labeled_statement_nsi
1435 | if_then_else_statement_nsi
1436 | while_statement_nsi
1438 { $$ = exit_block (); }
1441 statement_without_trailing_substatement:
1444 | expression_statement
1448 | continue_statement
1450 | synchronized_statement
1459 if (flag_extraneous_semicolon
1460 && ! current_static_block
1461 && (! current_function_decl ||
1462 /* Verify we're not in a inner class declaration */
1463 (GET_CPC () != TYPE_NAME
1464 (DECL_CONTEXT (current_function_decl)))))
1467 #ifdef USE_MAPPED_LOCATION
1468 SET_EXPR_LOCATION (wfl_operator, input_location);
1470 EXPR_WFL_SET_LINECOL (wfl_operator, input_line, -1);
1472 parse_warning_context (wfl_operator, "An empty declaration is a deprecated feature that should not be used");
1474 $$ = build_java_empty_stmt ();
1479 identifier REL_CL_TK
1481 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1482 EXPR_WFL_NODE ($1));
1484 push_labeled_block ($$);
1485 PUSH_LABELED_BLOCK ($$);
1490 label_decl statement
1491 { $$ = finish_labeled_statement ($1, $2); }
1493 {yyerror ("':' expected"); RECOVER;}
1496 labeled_statement_nsi:
1497 label_decl statement_nsi
1498 { $$ = finish_labeled_statement ($1, $2); }
1501 /* We concentrate here a bunch of error handling rules that we couldn't write
1502 earlier, because expression_statement catches a missing ';'. */
1503 expression_statement:
1504 statement_expression SC_TK
1506 /* We have a statement. Generate a WFL around it so
1508 #ifdef USE_MAPPED_LOCATION
1509 $$ = expr_add_location ($1, input_location, 1);
1511 $$ = build_expr_wfl ($1, input_filename, input_line, 0);
1512 JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1514 /* We know we have a statement, so set the debug
1515 info to be eventually generate here. */
1519 YYNOT_TWICE yyerror ("Invalid expression statement");
1520 DRECOVER (expr_stmt);
1524 YYNOT_TWICE yyerror ("Invalid expression statement");
1525 DRECOVER (expr_stmt);
1529 YYNOT_TWICE yyerror ("Invalid expression statement");
1530 DRECOVER (expr_stmt);
1532 | this_or_super OP_TK error
1533 {yyerror ("')' expected"); RECOVER;}
1534 | this_or_super OP_TK CP_TK error
1536 parse_ctor_invocation_error ();
1539 | this_or_super OP_TK argument_list error
1540 {yyerror ("')' expected"); RECOVER;}
1541 | this_or_super OP_TK argument_list CP_TK error
1543 parse_ctor_invocation_error ();
1546 | name DOT_TK SUPER_TK error
1547 {yyerror ("'(' expected"); RECOVER;}
1548 | name DOT_TK SUPER_TK OP_TK error
1549 {yyerror ("')' expected"); RECOVER;}
1550 | name DOT_TK SUPER_TK OP_TK argument_list error
1551 {yyerror ("')' expected"); RECOVER;}
1552 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1553 {yyerror ("';' expected"); RECOVER;}
1554 | name DOT_TK SUPER_TK OP_TK CP_TK error
1555 {yyerror ("';' expected"); RECOVER;}
1558 statement_expression:
1560 | pre_increment_expression
1561 | pre_decrement_expression
1562 | post_increment_expression
1563 | post_decrement_expression
1565 | class_instance_creation_expression
1569 IF_TK OP_TK expression CP_TK statement
1571 $$ = build_if_else_statement ($2.location, $3,
1575 {yyerror ("'(' expected"); RECOVER;}
1577 {yyerror ("Missing term"); RECOVER;}
1578 | IF_TK OP_TK expression error
1579 {yyerror ("')' expected"); RECOVER;}
1582 if_then_else_statement:
1583 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1584 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1587 if_then_else_statement_nsi:
1588 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1589 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1599 /* Make into "proper list" of COMPOUND_EXPRs.
1600 I.e. make the last statement also have its own
1602 maybe_absorb_scoping_blocks ();
1603 TREE_OPERAND ($1, 1) = exit_block ();
1604 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1609 SWITCH_TK OP_TK expression CP_TK
1611 $$ = build3 (SWITCH_EXPR, NULL_TREE, $3,
1612 NULL_TREE, NULL_TREE);
1613 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
1616 {yyerror ("'(' expected"); RECOVER;}
1617 | SWITCH_TK OP_TK error
1618 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1619 | SWITCH_TK OP_TK expression CP_TK error
1620 {yyerror ("'{' expected"); RECOVER;}
1623 /* Default assignment is there to avoid type node on switch_block
1629 | OCB_TK switch_labels CCB_TK
1631 | OCB_TK switch_block_statement_groups CCB_TK
1633 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1637 switch_block_statement_groups:
1638 switch_block_statement_group
1639 | switch_block_statement_groups switch_block_statement_group
1642 switch_block_statement_group:
1643 switch_labels block_statements
1648 | switch_labels switch_label
1652 CASE_TK constant_expression REL_CL_TK
1654 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1655 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1656 java_method_add_stmt (current_function_decl, lab);
1658 | DEFAULT_TK REL_CL_TK
1660 tree lab = make_node (DEFAULT_EXPR);
1661 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1662 java_method_add_stmt (current_function_decl, lab);
1665 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1666 | CASE_TK constant_expression error
1667 {yyerror ("':' expected"); RECOVER;}
1669 {yyerror ("':' expected"); RECOVER;}
1673 WHILE_TK OP_TK expression CP_TK
1675 tree body = build_loop_body ($2.location, $3, 0);
1676 $$ = build_new_loop (body);
1681 while_expression statement
1682 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1684 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1685 | WHILE_TK OP_TK error
1686 {yyerror ("Missing term and ')' expected"); RECOVER;}
1687 | WHILE_TK OP_TK expression error
1688 {yyerror ("')' expected"); RECOVER;}
1691 while_statement_nsi:
1692 while_expression statement_nsi
1693 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1699 tree body = build_loop_body (0, NULL_TREE, 1);
1700 $$ = build_new_loop (body);
1702 /* Need error handing here. FIXME */
1706 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1707 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1711 for_begin SC_TK expression SC_TK for_update CP_TK statement
1713 if (CONSTANT_CLASS_P ($3))
1714 $3 = build_wfl_node ($3);
1715 $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1717 | for_begin SC_TK SC_TK for_update CP_TK statement
1719 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1720 /* We have not condition, so we get rid of the EXIT_EXPR */
1721 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1722 build_java_empty_stmt ();
1724 | for_begin SC_TK error
1725 {yyerror ("Invalid control expression"); RECOVER;}
1726 | for_begin SC_TK expression SC_TK error
1727 {yyerror ("Invalid update expression"); RECOVER;}
1728 | for_begin SC_TK SC_TK error
1729 {yyerror ("Invalid update expression"); RECOVER;}
1733 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1734 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1735 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1737 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1738 /* We have not condition, so we get rid of the EXIT_EXPR */
1739 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1740 build_java_empty_stmt ();
1747 /* This scope defined for local variable that may be
1748 defined within the scope of the for loop */
1752 {yyerror ("'(' expected"); DRECOVER(for_1);}
1753 | FOR_TK OP_TK error
1754 {yyerror ("Invalid init statement"); RECOVER;}
1760 /* We now declare the loop body. The loop is
1761 declared as a for loop. */
1762 tree body = build_loop_body (0, NULL_TREE, 0);
1763 $$ = build_new_loop (body);
1764 FOR_LOOP_P ($$) = 1;
1765 /* The loop is added to the current block the for
1766 statement is defined within */
1767 java_method_add_stmt (current_function_decl, $$);
1770 for_init: /* Can be empty */
1771 { $$ = build_java_empty_stmt (); }
1772 | statement_expression_list
1774 /* Init statement recorded within the previously
1775 defined block scope */
1776 $$ = java_method_add_stmt (current_function_decl, $1);
1778 | local_variable_declaration
1780 /* Local variable are recorded within the previously
1781 defined block scope */
1784 | statement_expression_list error
1785 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1788 for_update: /* Can be empty */
1789 {$$ = build_java_empty_stmt ();}
1790 | statement_expression_list
1791 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1794 statement_expression_list:
1795 statement_expression
1796 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1797 | statement_expression_list C_TK statement_expression
1798 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1799 | statement_expression_list C_TK error
1800 {yyerror ("Missing term"); RECOVER;}
1805 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1806 | BREAK_TK identifier SC_TK
1807 { $$ = build_bc_statement ($1.location, 1, $2); }
1809 {yyerror ("Missing term"); RECOVER;}
1810 | BREAK_TK identifier error
1811 {yyerror ("';' expected"); RECOVER;}
1816 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1817 | CONTINUE_TK identifier SC_TK
1818 { $$ = build_bc_statement ($1.location, 0, $2); }
1820 {yyerror ("Missing term"); RECOVER;}
1821 | CONTINUE_TK identifier error
1822 {yyerror ("';' expected"); RECOVER;}
1827 { $$ = build_return ($1.location, NULL_TREE); }
1828 | RETURN_TK expression SC_TK
1829 { $$ = build_return ($1.location, $2); }
1831 {yyerror ("Missing term"); RECOVER;}
1832 | RETURN_TK expression error
1833 {yyerror ("';' expected"); RECOVER;}
1837 THROW_TK expression SC_TK
1839 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1840 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1843 {yyerror ("Missing term"); RECOVER;}
1844 | THROW_TK expression error
1845 {yyerror ("';' expected"); RECOVER;}
1849 ASSERT_TK expression REL_CL_TK expression SC_TK
1851 $$ = build_assertion ($1.location, $2, $4);
1853 | ASSERT_TK expression SC_TK
1855 $$ = build_assertion ($1.location, $2, NULL_TREE);
1858 {yyerror ("Missing term"); RECOVER;}
1859 | ASSERT_TK expression error
1860 {yyerror ("';' expected"); RECOVER;}
1863 synchronized_statement:
1864 synchronized OP_TK expression CP_TK block
1866 $$ = build2 (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1867 EXPR_WFL_LINECOL ($$) =
1868 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1870 | synchronized OP_TK expression CP_TK error
1871 {yyerror ("'{' expected"); RECOVER;}
1872 | synchronized error
1873 {yyerror ("'(' expected"); RECOVER;}
1874 | synchronized OP_TK error CP_TK
1875 {yyerror ("Missing term"); RECOVER;}
1876 | synchronized OP_TK error
1877 {yyerror ("Missing term"); RECOVER;}
1884 "Illegal modifier %qs. Only %<synchronized%> was expected here",
1885 $1, ACC_SYNCHRONIZED);
1886 if ($1 != ACC_SYNCHRONIZED)
1887 MODIFIER_WFL (SYNCHRONIZED_TK) =
1888 build_wfl_node (NULL_TREE);
1893 TRY_TK block catches
1894 { $$ = build_try_statement ($1.location, $2, $3); }
1895 | TRY_TK block finally
1896 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1897 | TRY_TK block catches finally
1898 { $$ = build_try_finally_statement
1899 ($1.location, build_try_statement ($1.location,
1903 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1908 | catches catch_clause
1910 TREE_CHAIN ($2) = $1;
1916 catch_clause_parameter block
1918 java_method_add_stmt (current_function_decl, $2);
1924 catch_clause_parameter:
1925 CATCH_TK OP_TK formal_parameter CP_TK
1927 /* We add a block to define a scope for
1928 formal_parameter (CCBP). The formal parameter is
1929 declared initialized by the appropriate function
1935 ccpb = enter_block ();
1936 init = build_assignment
1937 (ASSIGN_TK, $2.location, TREE_PURPOSE ($3),
1938 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
1939 declare_local_variables (0, TREE_VALUE ($3),
1941 (TREE_PURPOSE ($3), init));
1942 $$ = build1 (JAVA_CATCH_EXPR, NULL_TREE, ccpb);
1943 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1947 $$ = error_mark_node;
1951 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1952 | CATCH_TK OP_TK error
1954 yyerror ("Missing term or ')' expected");
1955 RECOVER; $$ = NULL_TREE;
1957 | CATCH_TK OP_TK error CP_TK /* That's for () */
1958 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1965 {yyerror ("'{' expected"); RECOVER; }
1968 /* 19.12 Production from 15: Expressions */
1970 primary_no_new_array
1971 | array_creation_uninitialized
1972 | array_creation_initialized
1975 primary_no_new_array:
1978 { $$ = build_this ($1.location); }
1979 | OP_TK expression CP_TK
1981 | class_instance_creation_expression
1986 /* Added, JDK1.1 inner classes. Documentation is wrong
1987 referring to a 'ClassName' (class_name) rule that doesn't
1988 exist. Used name: instead. */
1989 | name DOT_TK THIS_TK
1991 tree wfl = build_wfl_node (this_identifier_node);
1992 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
1994 | OP_TK expression error
1995 {yyerror ("')' expected"); RECOVER;}
1997 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1998 | primitive_type DOT_TK error
1999 {yyerror ("'class' expected" ); RECOVER;}
2000 | VOID_TK DOT_TK error
2001 {yyerror ("'class' expected" ); RECOVER;}
2005 name DOT_TK CLASS_TK
2006 { $$ = build_incomplete_class_ref ($2.location, $1); }
2007 | array_type DOT_TK CLASS_TK
2008 { $$ = build_incomplete_class_ref ($2.location, $1); }
2009 | primitive_type DOT_TK CLASS_TK
2010 { $$ = build_incomplete_class_ref ($2.location, $1); }
2011 | VOID_TK DOT_TK CLASS_TK
2013 $$ = build_incomplete_class_ref ($2.location,
2018 class_instance_creation_expression:
2019 NEW_TK class_type OP_TK argument_list CP_TK
2020 { $$ = build_new_invocation ($2, $4); }
2021 | NEW_TK class_type OP_TK CP_TK
2022 { $$ = build_new_invocation ($2, NULL_TREE); }
2023 | anonymous_class_creation
2024 /* Added, JDK1.1 inner classes, modified to use name or
2025 primary instead of primary solely which couldn't work in
2027 | something_dot_new identifier OP_TK CP_TK
2029 tree ctor = build_new_invocation ($2, NULL_TREE);
2030 $$ = make_qualified_primary ($1, ctor,
2031 EXPR_WFL_LINECOL ($1));
2033 | something_dot_new identifier OP_TK CP_TK class_body
2034 | something_dot_new identifier OP_TK argument_list CP_TK
2036 tree ctor = build_new_invocation ($2, $4);
2037 $$ = make_qualified_primary ($1, ctor,
2038 EXPR_WFL_LINECOL ($1));
2040 | something_dot_new identifier OP_TK argument_list CP_TK class_body
2041 | NEW_TK error SC_TK
2042 {$$ = NULL_TREE; yyerror ("'(' expected"); DRECOVER(new_1);}
2043 | NEW_TK class_type error
2044 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2045 | NEW_TK class_type OP_TK error
2046 {$$ = NULL_TREE; yyerror ("')' or term expected"); RECOVER;}
2047 | NEW_TK class_type OP_TK argument_list error
2048 {$$ = NULL_TREE; yyerror ("')' expected"); RECOVER;}
2049 | something_dot_new error
2053 yyerror ("Identifier expected");
2056 | something_dot_new identifier error
2057 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2060 /* Created after JDK1.1 rules originally added to
2061 class_instance_creation_expression, but modified to use
2062 'class_type' instead of 'TypeName' (type_name) which is mentioned
2063 in the documentation but doesn't exist. */
2065 anonymous_class_creation:
2066 NEW_TK class_type OP_TK argument_list CP_TK
2067 { create_anonymous_class ($2); }
2070 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2071 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2073 end_class_declaration (1);
2075 /* Now we can craft the new expression */
2076 $$ = build_new_invocation (id, $4);
2078 /* Note that we can't possibly be here if
2079 `class_type' is an interface (in which case the
2080 anonymous class extends Object and implements
2081 `class_type', hence its constructor can't have
2084 /* Otherwise, the innerclass must feature a
2085 constructor matching `argument_list'. Anonymous
2086 classes are a bit special: it's impossible to
2087 define constructor for them, hence constructors
2088 must be generated following the hints provided by
2089 the `new' expression. Whether a super constructor
2090 of that nature exists or not is to be verified
2091 later on in get_constructor_super.
2093 It's during the expansion of a `new' statement
2094 referring to an anonymous class that a ctor will
2095 be generated for the anonymous class, with the
2099 | NEW_TK class_type OP_TK CP_TK
2100 { create_anonymous_class ($2); }
2103 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2104 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2106 end_class_declaration (1);
2108 /* Now we can craft the new expression. The
2109 statement doesn't need to be remember so that a
2110 constructor can be generated, since its signature
2111 is already known. */
2112 $$ = build_new_invocation (id, NULL_TREE);
2116 something_dot_new: /* Added, not part of the specs. */
2119 | primary DOT_TK NEW_TK
2126 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2127 ctxp->formal_parameter_number = 1;
2129 | argument_list C_TK expression
2131 ctxp->formal_parameter_number += 1;
2132 $$ = tree_cons (NULL_TREE, $3, $1);
2134 | argument_list C_TK error
2135 {yyerror ("Missing term"); RECOVER;}
2138 array_creation_uninitialized:
2139 NEW_TK primitive_type dim_exprs
2140 { $$ = build_newarray_node ($2, $3, 0); }
2141 | NEW_TK class_or_interface_type dim_exprs
2142 { $$ = build_newarray_node ($2, $3, 0); }
2143 | NEW_TK primitive_type dim_exprs dims
2144 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2145 | NEW_TK class_or_interface_type dim_exprs dims
2146 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2147 | NEW_TK error CSB_TK
2148 {yyerror ("'[' expected"); DRECOVER ("]");}
2149 | NEW_TK error OSB_TK
2150 {yyerror ("']' expected"); RECOVER;}
2153 array_creation_initialized:
2154 /* Added, JDK1.1 anonymous array. Initial documentation rule
2156 NEW_TK class_or_interface_type dims array_initializer
2159 int osb = pop_current_osb (ctxp);
2161 obstack_grow (&temporary_obstack, "[]", 2);
2162 obstack_1grow (&temporary_obstack, '\0');
2163 sig = obstack_finish (&temporary_obstack);
2164 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2165 $2, get_identifier (sig), $4);
2167 | NEW_TK primitive_type dims array_initializer
2169 int osb = pop_current_osb (ctxp);
2172 type = build_java_array_type (type, -1);
2173 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2174 build_pointer_type (type), NULL_TREE, $4);
2176 | NEW_TK error CSB_TK
2177 {yyerror ("'[' expected"); DRECOVER ("]");}
2178 | NEW_TK error OSB_TK
2179 {yyerror ("']' expected"); RECOVER;}
2184 { $$ = build_tree_list (NULL_TREE, $1); }
2185 | dim_exprs dim_expr
2186 { $$ = tree_cons (NULL_TREE, $2, $$); }
2190 OSB_TK expression CSB_TK
2192 if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2194 $2 = build_wfl_node ($2);
2195 TREE_TYPE ($2) = NULL_TREE;
2197 EXPR_WFL_LINECOL ($2) = $1.location;
2200 | OSB_TK expression error
2201 {yyerror ("']' expected"); RECOVER;}
2204 yyerror ("Missing term");
2205 yyerror ("']' expected");
2214 /* If not initialized, allocate memory for the osb
2216 if (!ctxp->osb_limit)
2218 allocate = ctxp->osb_limit = 32;
2219 ctxp->osb_depth = -1;
2221 /* If capacity overflown, reallocate a bigger chunk */
2222 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2223 allocate = ctxp->osb_limit << 1;
2227 allocate *= sizeof (int);
2228 if (ctxp->osb_number)
2229 ctxp->osb_number = xrealloc (ctxp->osb_number,
2232 ctxp->osb_number = xmalloc (allocate);
2235 CURRENT_OSB (ctxp) = 1;
2237 | dims OSB_TK CSB_TK
2238 { CURRENT_OSB (ctxp)++; }
2240 { yyerror ("']' expected"); RECOVER;}
2244 primary DOT_TK identifier
2245 { $$ = make_qualified_primary ($1, $3, $2.location); }
2246 /* FIXME - REWRITE TO:
2247 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2248 | SUPER_TK DOT_TK identifier
2250 tree super_wfl = build_wfl_node (super_identifier_node);
2251 SET_EXPR_LOCATION_FROM_TOKEN (super_wfl, $1);
2252 $$ = make_qualified_name (super_wfl, $3, $2.location);
2255 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2260 { $$ = build_method_invocation ($1, NULL_TREE); }
2261 | name OP_TK argument_list CP_TK
2262 { $$ = build_method_invocation ($1, $3); }
2263 | primary DOT_TK identifier OP_TK CP_TK
2265 if (TREE_CODE ($1) == THIS_EXPR)
2266 $$ = build_this_super_qualified_invocation
2267 (1, $3, NULL_TREE, 0, $2.location);
2270 tree invok = build_method_invocation ($3, NULL_TREE);
2271 $$ = make_qualified_primary ($1, invok, $2.location);
2274 | primary DOT_TK identifier OP_TK argument_list CP_TK
2276 if (TREE_CODE ($1) == THIS_EXPR)
2277 $$ = build_this_super_qualified_invocation
2278 (1, $3, $5, 0, $2.location);
2281 tree invok = build_method_invocation ($3, $5);
2282 $$ = make_qualified_primary ($1, invok, $2.location);
2285 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2287 $$ = build_this_super_qualified_invocation
2288 (0, $3, NULL_TREE, $1.location, $2.location);
2290 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2292 $$ = build_this_super_qualified_invocation
2293 (0, $3, $5, $1.location, $2.location);
2295 /* Screws up thing. I let it here until I'm convinced it can
2297 | primary DOT_TK error
2298 {yyerror ("'(' expected"); DRECOVER(bad);} */
2299 | SUPER_TK DOT_TK error CP_TK
2300 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2301 | SUPER_TK DOT_TK error DOT_TK
2302 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2306 name OSB_TK expression CSB_TK
2307 { $$ = build_array_ref ($2.location, $1, $3); }
2308 | primary_no_new_array OSB_TK expression CSB_TK
2309 { $$ = build_array_ref ($2.location, $1, $3); }
2310 | array_creation_initialized OSB_TK expression CSB_TK
2311 { $$ = build_array_ref ($2.location, $1, $3); }
2314 yyerror ("Missing term and ']' expected");
2315 DRECOVER(array_access);
2317 | name OSB_TK expression error
2319 yyerror ("']' expected");
2320 DRECOVER(array_access);
2322 | primary_no_new_array OSB_TK error
2324 yyerror ("Missing term and ']' expected");
2325 DRECOVER(array_access);
2327 | primary_no_new_array OSB_TK expression error
2329 yyerror ("']' expected");
2330 DRECOVER(array_access);
2332 | array_creation_initialized OSB_TK error
2334 yyerror ("Missing term and ']' expected");
2335 DRECOVER(array_access);
2337 | array_creation_initialized OSB_TK expression error
2339 yyerror ("']' expected");
2340 DRECOVER(array_access);
2347 | post_increment_expression
2348 | post_decrement_expression
2351 post_increment_expression:
2352 postfix_expression INCR_TK
2353 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2356 post_decrement_expression:
2357 postfix_expression DECR_TK
2358 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2361 trap_overflow_corner_case:
2362 pre_increment_expression
2363 | pre_decrement_expression
2364 | PLUS_TK unary_expression
2365 {$$ = build_unaryop ($1.token, $1.location, $2); }
2366 | unary_expression_not_plus_minus
2368 {yyerror ("Missing term"); RECOVER}
2372 trap_overflow_corner_case
2375 error_if_numeric_overflow ($1);
2378 | MINUS_TK trap_overflow_corner_case
2379 {$$ = build_unaryop ($1.token, $1.location, $2); }
2381 {yyerror ("Missing term"); RECOVER}
2384 pre_increment_expression:
2385 INCR_TK unary_expression
2386 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2388 {yyerror ("Missing term"); RECOVER}
2391 pre_decrement_expression:
2392 DECR_TK unary_expression
2393 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2395 {yyerror ("Missing term"); RECOVER}
2398 unary_expression_not_plus_minus:
2400 | NOT_TK unary_expression
2401 {$$ = build_unaryop ($1.token, $1.location, $2); }
2402 | NEG_TK unary_expression
2403 {$$ = build_unaryop ($1.token, $1.location, $2); }
2406 {yyerror ("Missing term"); RECOVER}
2408 {yyerror ("Missing term"); RECOVER}
2411 cast_expression: /* Error handling here is potentially weak */
2412 OP_TK primitive_type dims CP_TK unary_expression
2415 int osb = pop_current_osb (ctxp);
2417 type = build_java_array_type (type, -1);
2418 $$ = build_cast ($1.location, type, $5);
2420 | OP_TK primitive_type CP_TK unary_expression
2421 { $$ = build_cast ($1.location, $2, $4); }
2422 | OP_TK expression CP_TK unary_expression_not_plus_minus
2423 { $$ = build_cast ($1.location, $2, $4); }
2424 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2427 int osb = pop_current_osb (ctxp);
2428 obstack_grow (&temporary_obstack,
2429 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2430 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2432 obstack_grow (&temporary_obstack, "[]", 2);
2433 obstack_1grow (&temporary_obstack, '\0');
2434 ptr = obstack_finish (&temporary_obstack);
2435 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2436 $$ = build_cast ($1.location, $2, $5);
2438 | OP_TK primitive_type OSB_TK error
2439 {yyerror ("']' expected, invalid type expression");}
2442 YYNOT_TWICE yyerror ("Invalid type expression"); RECOVER;
2445 | OP_TK primitive_type dims CP_TK error
2446 {yyerror ("Missing term"); RECOVER;}
2447 | OP_TK primitive_type CP_TK error
2448 {yyerror ("Missing term"); RECOVER;}
2449 | OP_TK name dims CP_TK error
2450 {yyerror ("Missing term"); RECOVER;}
2453 multiplicative_expression:
2455 | multiplicative_expression MULT_TK unary_expression
2457 $$ = build_binop (BINOP_LOOKUP ($2.token),
2458 $2.location, $1, $3);
2460 | multiplicative_expression DIV_TK unary_expression
2462 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2465 | multiplicative_expression REM_TK unary_expression
2467 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2470 | multiplicative_expression MULT_TK error
2471 {yyerror ("Missing term"); RECOVER;}
2472 | multiplicative_expression DIV_TK error
2473 {yyerror ("Missing term"); RECOVER;}
2474 | multiplicative_expression REM_TK error
2475 {yyerror ("Missing term"); RECOVER;}
2478 additive_expression:
2479 multiplicative_expression
2480 | additive_expression PLUS_TK multiplicative_expression
2482 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2485 | additive_expression MINUS_TK multiplicative_expression
2487 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2490 | additive_expression PLUS_TK error
2491 {yyerror ("Missing term"); RECOVER;}
2492 | additive_expression MINUS_TK error
2493 {yyerror ("Missing term"); RECOVER;}
2498 | shift_expression LS_TK additive_expression
2500 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2503 | shift_expression SRS_TK additive_expression
2505 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2508 | shift_expression ZRS_TK additive_expression
2510 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2513 | shift_expression LS_TK error
2514 {yyerror ("Missing term"); RECOVER;}
2515 | shift_expression SRS_TK error
2516 {yyerror ("Missing term"); RECOVER;}
2517 | shift_expression ZRS_TK error
2518 {yyerror ("Missing term"); RECOVER;}
2521 relational_expression:
2523 | relational_expression LT_TK shift_expression
2525 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2528 | relational_expression GT_TK shift_expression
2530 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2533 | relational_expression LTE_TK shift_expression
2535 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2538 | relational_expression GTE_TK shift_expression
2540 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2543 | relational_expression INSTANCEOF_TK reference_type
2544 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2545 | relational_expression LT_TK error
2546 {yyerror ("Missing term"); RECOVER;}
2547 | relational_expression GT_TK error
2548 {yyerror ("Missing term"); RECOVER;}
2549 | relational_expression LTE_TK error
2550 {yyerror ("Missing term"); RECOVER;}
2551 | relational_expression GTE_TK error
2552 {yyerror ("Missing term"); RECOVER;}
2553 | relational_expression INSTANCEOF_TK error
2554 {yyerror ("Invalid reference type"); RECOVER;}
2557 equality_expression:
2558 relational_expression
2559 | equality_expression EQ_TK relational_expression
2561 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2564 | equality_expression NEQ_TK relational_expression
2566 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2569 | equality_expression EQ_TK error
2570 {yyerror ("Missing term"); RECOVER;}
2571 | equality_expression NEQ_TK error
2572 {yyerror ("Missing term"); RECOVER;}
2577 | and_expression AND_TK equality_expression
2579 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2582 | and_expression AND_TK error
2583 {yyerror ("Missing term"); RECOVER;}
2586 exclusive_or_expression:
2588 | exclusive_or_expression XOR_TK and_expression
2590 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2593 | exclusive_or_expression XOR_TK error
2594 {yyerror ("Missing term"); RECOVER;}
2597 inclusive_or_expression:
2598 exclusive_or_expression
2599 | inclusive_or_expression OR_TK exclusive_or_expression
2601 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2604 | inclusive_or_expression OR_TK error
2605 {yyerror ("Missing term"); RECOVER;}
2608 conditional_and_expression:
2609 inclusive_or_expression
2610 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2612 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2615 | conditional_and_expression BOOL_AND_TK error
2616 {yyerror ("Missing term"); RECOVER;}
2619 conditional_or_expression:
2620 conditional_and_expression
2621 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2623 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2626 | conditional_or_expression BOOL_OR_TK error
2627 {yyerror ("Missing term"); RECOVER;}
2630 conditional_expression: /* Error handling here is weak */
2631 conditional_or_expression
2632 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2634 $$ = build3 (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2635 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
2637 | conditional_or_expression REL_QM_TK REL_CL_TK error
2640 yyerror ("Missing term");
2643 | conditional_or_expression REL_QM_TK error
2644 {yyerror ("Missing term"); DRECOVER (2);}
2645 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2646 {yyerror ("Missing term"); DRECOVER (3);}
2649 assignment_expression:
2650 conditional_expression
2655 left_hand_side assignment_operator assignment_expression
2656 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2657 | left_hand_side assignment_operator error
2659 YYNOT_TWICE yyerror ("Missing term");
2670 assignment_operator:
2676 assignment_expression
2679 constant_expression:
2685 /* Helper function to retrieve an OSB count. Should be used when the
2686 `dims:' rule is being used. */
2689 pop_current_osb (struct parser_ctxt *ctxp)
2693 if (ctxp->osb_depth < 0)
2696 to_return = CURRENT_OSB (ctxp);
2704 /* This section of the code deal with save/restoring parser contexts.
2705 Add mode documentation here. FIXME */
2707 /* Helper function. Create a new parser context. With
2708 COPY_FROM_PREVIOUS set to a nonzero value, content of the previous
2709 context is copied, otherwise, the new context is zeroed. The newly
2710 created context becomes the current one. */
2713 create_new_parser_context (int copy_from_previous)
2715 struct parser_ctxt *new;
2717 new = ggc_alloc (sizeof (struct parser_ctxt));
2718 if (copy_from_previous)
2720 memcpy (new, ctxp, sizeof (struct parser_ctxt));
2721 /* This flag, indicating the context saves global values,
2722 should only be set by java_parser_context_save_global. */
2723 new->saved_data_ctx = 0;
2726 memset (new, 0, sizeof (struct parser_ctxt));
2732 /* Create a new parser context and make it the current one. */
2735 java_push_parser_context (void)
2737 create_new_parser_context (0);
2741 java_pop_parser_context (int generate)
2744 struct parser_ctxt *next;
2752 input_location = ctxp->save_location;
2753 current_class = ctxp->class_type;
2756 /* If the old and new lexers differ, then free the old one. */
2757 if (ctxp->lexer && next && ctxp->lexer != next->lexer)
2758 java_destroy_lexer (ctxp->lexer);
2760 /* Set the single import class file flag to 0 for the current list
2761 of imported things */
2762 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2763 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 0;
2765 /* If we pushed a context to parse a class intended to be generated,
2766 we keep it so we can remember the class. What we could actually
2767 do is to just update a list of class names. */
2770 if (ctxp_for_generation_last == NULL)
2771 ctxp_for_generation = ctxp;
2773 ctxp_for_generation_last->next = ctxp;
2775 ctxp_for_generation_last = ctxp;
2778 /* And restore those of the previous context */
2779 if ((ctxp = next)) /* Assignment is really meant here */
2780 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2781 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 1;
2784 /* Create a parser context for the use of saving some global
2788 java_parser_context_save_global (void)
2792 java_push_parser_context ();
2793 ctxp->saved_data_ctx = 1;
2796 /* If this context already stores data, create a new one suitable
2797 for data storage. */
2798 else if (ctxp->saved_data)
2800 create_new_parser_context (1);
2801 ctxp->saved_data_ctx = 1;
2804 ctxp->save_location = input_location;
2805 ctxp->class_type = current_class;
2806 ctxp->function_decl = current_function_decl;
2807 ctxp->saved_data = 1;
2810 /* Restore some global variables from the previous context. Make the
2811 previous context the current one. */
2814 java_parser_context_restore_global (void)
2816 input_location = ctxp->save_location;
2817 current_class = ctxp->class_type;
2819 #ifdef USE_MAPPED_LOCATION
2820 SET_EXPR_LOCATION (wfl_operator, ctxp->save_location);
2822 EXPR_WFL_FILENAME_NODE (wfl_operator) = get_identifier (input_filename);
2824 current_function_decl = ctxp->function_decl;
2825 ctxp->saved_data = 0;
2826 if (ctxp->saved_data_ctx)
2827 java_pop_parser_context (0);
2830 /* Suspend vital data for the current class/function being parsed so
2831 that an other class can be parsed. Used to let local/anonymous
2832 classes be parsed. */
2835 java_parser_context_suspend (void)
2837 /* This makes debugging through java_debug_context easier */
2838 static const char *const name = "<inner buffer context>";
2840 /* Duplicate the previous context, use it to save the globals we're
2842 create_new_parser_context (1);
2843 ctxp->function_decl = current_function_decl;
2844 ctxp->class_type = current_class;
2846 /* Then create a new context which inherits all data from the
2847 previous one. This will be the new current context */
2848 create_new_parser_context (1);
2850 /* Help debugging */
2851 ctxp->next->filename = name;
2854 /* Resume vital data for the current class/function being parsed so
2855 that an other class can be parsed. Used to let local/anonymous
2856 classes be parsed. The trick is the data storing file position
2857 informations must be restored to their current value, so parsing
2858 can resume as if no context was ever saved. */
2861 java_parser_context_resume (void)
2863 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2864 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2865 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2867 /* We need to inherit the list of classes to complete/generate */
2868 restored->classd_list = old->classd_list;
2869 restored->class_list = old->class_list;
2871 /* Restore the current class and function from the saver */
2872 current_class = saver->class_type;
2873 current_function_decl = saver->function_decl;
2875 /* Retrieve the restored context */
2878 /* Re-installed the data for the parsing to carry on */
2879 memcpy (&ctxp->marker_begining, &old->marker_begining,
2880 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2883 /* Add a new anchor node to which all statement(s) initializing static
2884 and non static initialized upon declaration field(s) will be
2888 java_parser_context_push_initialized_field (void)
2892 node = build_tree_list (NULL_TREE, NULL_TREE);
2893 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2894 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2896 node = build_tree_list (NULL_TREE, NULL_TREE);
2897 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2898 CPC_INITIALIZER_LIST (ctxp) = node;
2900 node = build_tree_list (NULL_TREE, NULL_TREE);
2901 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2902 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2905 /* Pop the lists of initialized field. If this lists aren't empty,
2906 remember them so we can use it to create and populate the finit$
2907 or <clinit> functions. */
2910 java_parser_context_pop_initialized_field (void)
2913 tree class_type = TREE_TYPE (GET_CPC ());
2915 if (CPC_INITIALIZER_LIST (ctxp))
2917 stmts = CPC_INITIALIZER_STMT (ctxp);
2918 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2919 if (stmts && !java_error_count)
2920 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2923 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2925 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2926 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2927 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2928 /* Keep initialization in order to enforce 8.5 */
2929 if (stmts && !java_error_count)
2930 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2933 /* JDK 1.1 instance initializers */
2934 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2936 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2937 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2938 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2939 if (stmts && !java_error_count)
2940 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2945 reorder_static_initialized (tree list)
2947 /* We have to keep things in order. The alias initializer have to
2948 come first, then the initialized regular field, in reverse to
2949 keep them in lexical order. */
2950 tree marker, previous = NULL_TREE;
2951 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2952 if (TREE_CODE (marker) == TREE_LIST
2953 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2956 /* No static initialized, the list is fine as is */
2958 list = TREE_CHAIN (marker);
2960 /* No marker? reverse the whole list */
2962 list = nreverse (list);
2964 /* Otherwise, reverse what's after the marker and the new reordered
2965 sublist will replace the marker. */
2968 TREE_CHAIN (previous) = NULL_TREE;
2969 list = nreverse (list);
2970 list = chainon (TREE_CHAIN (marker), list);
2975 /* Helper functions to dump the parser context stack. */
2977 #define TAB_CONTEXT(C) \
2978 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2981 java_debug_context_do (int tab)
2983 struct parser_ctxt *copy = ctxp;
2987 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2989 fprintf (stderr, "filename: %s\n", copy->filename);
2991 fprintf (stderr, "package: %s\n",
2993 IDENTIFIER_POINTER (copy->package) : "<none>"));
2995 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2997 fprintf (stderr, "saved data: %d\n", copy->saved_data);
3003 /* Dump the stacked up parser contexts. Intended to be called from a
3007 java_debug_context (void)
3009 java_debug_context_do (0);
3014 /* Flag for the error report routine to issue the error the first time
3015 it's called (overriding the default behavior which is to drop the
3016 first invocation and honor the second one, taking advantage of a
3018 static int force_error = 0;
3020 /* Reporting an constructor invocation error. */
3022 parse_ctor_invocation_error (void)
3024 if (DECL_CONSTRUCTOR_P (current_function_decl))
3025 yyerror ("Constructor invocation must be first thing in a constructor");
3027 yyerror ("Only constructors can invoke constructors");
3030 /* Reporting JDK1.1 features not implemented. */
3033 parse_jdk1_1_error (const char *msg)
3035 sorry (": %qs JDK1.1(TM) feature", msg);
3037 return build_java_empty_stmt ();
3040 static int do_warning = 0;
3043 yyerror (const char *msgid)
3045 #ifdef USE_MAPPED_LOCATION
3046 static source_location elc;
3047 expanded_location xloc = expand_location (input_location);
3048 int current_line = xloc.line;
3052 int current_line = input_line;
3054 static int prev_lineno;
3055 static const char *prev_msg;
3057 char *remainder, *code_from_source;
3059 if (!force_error && prev_lineno == current_line)
3061 #ifndef USE_MAPPED_LOCATION
3062 current_line = ctxp->lexer->token_start.line;
3065 /* Save current error location but report latter, when the context is
3067 if (ctxp->java_error_flag == 0)
3069 ctxp->java_error_flag = 1;
3070 #ifdef USE_MAPPED_LOCATION
3071 elc = input_location;
3073 elc = ctxp->lexer->token_start;
3075 /* Do something to use the previous line if we're reaching the
3076 end of the file... */
3077 #ifdef VERBOSE_SKELETON
3078 printf ("* Error detected (%s)\n", (msgid ? msgid : "(null)"));
3083 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
3084 if (!force_error && msgid == prev_msg && prev_lineno == current_line)
3087 ctxp->java_error_flag = 0;
3089 java_warning_count++;
3094 if (elc.col == 0 && msgid && msgid[1] == ';')
3095 elc = ctxp->prev_line_end;
3100 #ifdef USE_MAPPED_LOCATION
3101 prev_lineno = current_line;
3102 code_from_source = java_get_line_col (xloc.file, current_line, xloc.column);
3104 save_lineno = input_line;
3105 prev_lineno = input_line = current_line;
3106 code_from_source = java_get_line_col (input_filename, current_line,
3107 ctxp->lexer->token_start.col);
3111 obstack_grow0 (&temporary_obstack,
3112 code_from_source, strlen (code_from_source));
3113 remainder = obstack_finish (&temporary_obstack);
3115 warning (0, "%s.\n%s", msgid, remainder);
3117 error ("%s.\n%s", msgid, remainder);
3119 /* This allow us to cheaply avoid an extra 'Invalid expression
3120 statement' error report when errors have been already reported on
3121 the same line. This occurs when we report an error but don't have
3122 a synchronization point other than ';', which
3123 expression_statement is the only one to take care of. */
3124 #ifndef USE_MAPPED_LOCATION
3125 input_line = save_lineno;
3127 ctxp->prevent_ese = input_line;
3131 issue_warning_error_from_context (
3132 #ifdef USE_MAPPED_LOCATION
3137 const char *gmsgid, va_list *ap)
3139 #ifdef USE_MAPPED_LOCATION
3140 source_location saved_location = input_location;
3141 expanded_location xloc = expand_location (cl);
3143 java_lc save_lc = ctxp->lexer->token_start;
3144 const char *saved = ctxp->filename, *saved_input_filename;
3149 text.err_no = errno;
3151 text.format_spec = gmsgid;
3152 pp_format (global_dc->printer, &text);
3153 pp_output_formatted_text (global_dc->printer);
3154 strncpy (buffer, pp_formatted_text (global_dc->printer), sizeof (buffer) - 1);
3155 buffer[sizeof (buffer) - 1] = '\0';
3156 pp_clear_output_area (global_dc->printer);
3160 #ifdef USE_MAPPED_LOCATION
3161 if (xloc.file != NULL)
3163 ctxp->filename = xloc.file;
3164 input_location = cl;
3167 ctxp->lexer->token_start.line = EXPR_WFL_LINENO (cl);
3168 ctxp->lexer->token_start.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1
3169 : EXPR_WFL_COLNO (cl) == 0xffe ? -2
3170 : EXPR_WFL_COLNO (cl));
3172 /* We have a CL, that's a good reason for using it if it contains data */
3173 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3174 ctxp->filename = EXPR_WFL_FILENAME (cl);
3175 saved_input_filename = input_filename;
3176 input_filename = ctxp->filename;
3179 java_error (buffer);
3180 #ifdef USE_MAPPED_LOCATION
3181 input_location = saved_location;
3183 ctxp->filename = saved;
3184 input_filename = saved_input_filename;
3185 ctxp->lexer->token_start = save_lc;
3190 /* Issue an error message at a current source line CL.
3191 FUTURE/FIXME: change cl to be a source_location. */
3194 parse_error_context (tree cl, const char *gmsgid, ...)
3197 va_start (ap, gmsgid);
3198 #ifdef USE_MAPPED_LOCATION
3199 issue_warning_error_from_context (EXPR_LOCATION (cl), gmsgid, &ap);
3201 issue_warning_error_from_context (cl, gmsgid, &ap);
3206 /* Issue a warning at a current source line CL.
3207 FUTURE/FIXME: change cl to be a source_location. */
3210 parse_warning_context (tree cl, const char *gmsgid, ...)
3213 va_start (ap, gmsgid);
3216 #ifdef USE_MAPPED_LOCATION
3217 issue_warning_error_from_context (EXPR_LOCATION (cl), gmsgid, &ap);
3219 issue_warning_error_from_context (cl, gmsgid, &ap);
3226 find_expr_with_wfl (tree node)
3230 enum tree_code_class code;
3233 switch (TREE_CODE (node))
3236 node = BLOCK_EXPR_BODY (node);
3240 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3243 node = TREE_OPERAND (node, 1);
3247 node = TREE_OPERAND (node, 0);
3250 case LABELED_BLOCK_EXPR:
3251 node = LABELED_BLOCK_BODY (node);
3255 code = TREE_CODE_CLASS (TREE_CODE (node));
3256 if (((code == tcc_unary) || (code == tcc_binary)
3257 || (code == tcc_expression))
3258 && EXPR_WFL_LINECOL (node))
3266 /* Issue a missing return statement error. Uses METHOD to figure the
3267 last line of the method the error occurs in. */
3270 missing_return_error (tree method)
3272 #ifdef USE_MAPPED_LOCATION
3273 SET_EXPR_LOCATION (wfl_operator, DECL_FUNCTION_LAST_LINE (method));
3275 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_FUNCTION_LAST_LINE (method), -2);
3277 parse_error_context (wfl_operator, "Missing return statement");
3280 /* Issue an unreachable statement error. From NODE, find the next
3281 statement to report appropriately. */
3283 unreachable_stmt_error (tree node)
3285 /* Browse node to find the next expression node that has a WFL. Use
3286 the location to report the error */
3287 if (TREE_CODE (node) == COMPOUND_EXPR)
3288 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3290 node = find_expr_with_wfl (node);
3294 #ifdef USE_MAPPED_LOCATION
3295 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
3297 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3299 parse_error_context (wfl_operator, "Unreachable statement");
3306 not_accessible_field_error (tree wfl, tree decl)
3309 (wfl, "Can't access %s field %<%s.%s%> from %qs",
3310 accessibility_string (get_access_flags_from_decl (decl)),
3311 GET_TYPE_NAME (DECL_CONTEXT (decl)),
3312 IDENTIFIER_POINTER (DECL_NAME (decl)),
3313 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
3318 java_report_errors (void)
3320 if (java_error_count)
3321 fprintf (stderr, "%d error%s",
3322 java_error_count, (java_error_count == 1 ? "" : "s"));
3323 if (java_warning_count)
3324 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3325 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3326 if (java_error_count || java_warning_count)
3327 putc ('\n', stderr);
3328 return java_error_count;
3332 java_accstring_lookup (int flags)
3334 static char buffer [80];
3335 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3337 /* Access modifier looked-up first for easier report on forbidden
3339 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3340 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3341 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3342 if (flags & ACC_STATIC) COPY_RETURN ("static");
3343 if (flags & ACC_FINAL) COPY_RETURN ("final");
3344 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3345 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3346 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3347 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3348 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3349 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3356 /* Returns a string denoting the accessibility of a class or a member as
3357 indicated by FLAGS. We need a separate function from
3358 java_accstring_lookup, as the latter can return spurious "static", etc.
3359 if package-private access is defined (in which case none of the
3360 relevant access control bits in FLAGS is set). */
3363 accessibility_string (int flags)
3365 if (flags & ACC_PRIVATE) return "private";
3366 if (flags & ACC_PROTECTED) return "protected";
3367 if (flags & ACC_PUBLIC) return "public";
3369 return "package-private";
3372 /* Issuing error messages upon redefinition of classes, interfaces or
3376 classitf_redefinition_error (const char *context, tree id, tree decl, tree cl)
3378 parse_error_context (cl, "%s %qs already defined in %s:%d",
3379 context, IDENTIFIER_POINTER (id),
3380 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3381 /* Here we should point out where its redefined. It's a unicode. FIXME */
3385 variable_redefinition_error (tree context, tree name, tree type, int line)
3387 const char *type_name;
3389 /* Figure a proper name for type. We might haven't resolved it */
3390 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3391 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3393 type_name = lang_printable_name (type, 0);
3395 parse_error_context (context,
3396 "Variable %qs is already defined in this method and was declared %<%s %s%> at line %d",
3397 IDENTIFIER_POINTER (name),
3398 type_name, IDENTIFIER_POINTER (name), line);
3401 /* If ANAME is terminated with `[]', it indicates an array. This
3402 function returns the number of `[]' found and if this number is
3403 greater than zero, it extracts the array type name and places it in
3404 the node pointed to by TRIMMED unless TRIMMED is null. */
3407 build_type_name_from_array_name (tree aname, tree *trimmed)
3409 const char *name = IDENTIFIER_POINTER (aname);
3410 int len = IDENTIFIER_LENGTH (aname);
3413 STRING_STRIP_BRACKETS (name, len, array_dims);
3415 if (array_dims && trimmed)
3416 *trimmed = get_identifier_with_length (name, len);
3422 build_array_from_name (tree type, tree type_wfl, tree name, tree *ret_name)
3426 /* Eventually get more dims */
3427 more_dims = build_type_name_from_array_name (name, &name);
3429 /* If we have, then craft a new type for this variable */
3434 /* If we have a pointer, use its type */
3435 if (TREE_CODE (type) == POINTER_TYPE)
3436 type = TREE_TYPE (type);
3438 /* Building the first dimension of a primitive type uses this
3440 if (JPRIMITIVE_TYPE_P (type))
3442 type = build_java_array_type (type, -1);
3445 /* Otherwise, if we have a WFL for this type, use it (the type
3446 is already an array on an unresolved type, and we just keep
3447 on adding dimensions) */
3451 more_dims += build_type_name_from_array_name (TYPE_NAME (save),
3455 /* Add all the dimensions */
3457 type = build_unresolved_array_type (type);
3459 /* The type may have been incomplete in the first place */
3461 type = obtain_incomplete_type (type);
3469 /* Build something that the type identifier resolver will identify as
3470 being an array to an unresolved type. TYPE_WFL is a WFL on a
3474 build_unresolved_array_type (tree type_or_wfl)
3479 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3480 just create a array type */
3481 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3482 return build_java_array_type (type_or_wfl, -1);
3484 obstack_grow (&temporary_obstack,
3485 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3486 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3487 obstack_grow0 (&temporary_obstack, "[]", 2);
3488 ptr = obstack_finish (&temporary_obstack);
3489 #ifdef USE_MAPPED_LOCATION
3490 wfl = build_expr_wfl (get_identifier (ptr), EXPR_LOCATION (type_or_wfl));
3492 wfl = build_expr_wfl (get_identifier (ptr),
3493 EXPR_WFL_FILENAME (type_or_wfl),
3494 EXPR_WFL_LINENO (type_or_wfl),
3495 EXPR_WFL_COLNO (type_or_wfl));
3497 /* Re-install the existing qualifications so that the type can be
3498 resolved properly. */
3499 EXPR_WFL_QUALIFICATION (wfl) = EXPR_WFL_QUALIFICATION (type_or_wfl);
3504 parser_add_interface (tree class_decl, tree interface_decl, tree wfl)
3506 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3507 parse_error_context (wfl, "Interface %qs repeated",
3508 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3511 /* Bulk of common class/interface checks. Return 1 if an error was
3512 encountered. TAG is 0 for a class, 1 for an interface. */
3515 check_class_interface_creation (int is_interface, int flags, tree raw_name,
3516 tree qualified_name, tree decl, tree cl)
3519 int sca = 0; /* Static class allowed */
3520 int icaf = 0; /* Inner class allowed flags */
3521 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3524 fprintf (stderr, " %s%s %s",
3525 (CPC_INNER_P () ? "inner" : ""),
3526 (is_interface ? "interface" : "class"),
3527 IDENTIFIER_POINTER (qualified_name));
3529 /* Scope of an interface/class type name:
3530 - Can't be imported by a single type import
3531 - Can't already exists in the package */
3532 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3533 && (node = find_name_in_single_imports (raw_name))
3537 (cl, "%s name %qs clashes with imported type %qs",
3538 (is_interface ? "Interface" : "Class"),
3539 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
3542 if (decl && CLASS_COMPLETE_P (decl))
3544 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
3545 qualified_name, decl, cl);
3549 if (check_inner_class_redefinition (raw_name, cl))
3552 /* If public, file name should match class/interface name, except
3553 when dealing with an inner class */
3554 if (!CPC_INNER_P () && (flags & ACC_PUBLIC ))
3556 const char *fname = input_filename;
3559 for (f = fname + strlen (fname);
3560 f != fname && ! IS_DIR_SEPARATOR (*f);
3563 if (IS_DIR_SEPARATOR (*f))
3565 if (strncmp (IDENTIFIER_POINTER (raw_name),
3566 f , IDENTIFIER_LENGTH (raw_name)) ||
3567 f [IDENTIFIER_LENGTH (raw_name)] != '.')
3569 (cl, "Public %s %qs must be defined in a file called %<%s.java%>",
3570 (is_interface ? "interface" : "class"),
3571 IDENTIFIER_POINTER (qualified_name),
3572 IDENTIFIER_POINTER (raw_name));
3575 /* Static classes can be declared only in top level classes. Note:
3576 once static, a inner class is a top level class. */
3577 if (flags & ACC_STATIC)
3579 /* Catch the specific error of declaring an class inner class
3580 with no toplevel enclosing class. Prevent check_modifiers from
3581 complaining a second time */
3582 if (CPC_INNER_P () && !TOPLEVEL_CLASS_DECL_P (GET_CPC()))
3584 parse_error_context (cl, "Inner class %qs can't be static. Static classes can only occur in interfaces and top-level classes",
3585 IDENTIFIER_POINTER (qualified_name));
3588 /* Else, in the context of a top-level class declaration, let
3589 `check_modifiers' do its job, otherwise, give it a go */
3591 sca = (GET_CPC_LIST () ? ACC_STATIC : 0);
3594 /* Inner classes can be declared private or protected
3595 within their enclosing classes. */
3598 /* A class which is local to a block can't be public, private,
3599 protected or static. But it is created final, so allow this
3601 if (current_function_decl)
3602 icaf = sca = uaaf = ACC_FINAL;
3605 check_modifiers_consistency (flags);
3606 icaf = ACC_PROTECTED;
3607 if (! CLASS_INTERFACE (GET_CPC ()))
3608 icaf |= ACC_PRIVATE;
3615 uaaf = INTERFACE_INNER_MODIFIERS;
3617 uaaf = INTERFACE_MODIFIERS;
3619 check_modifiers ("Illegal modifier %qs for interface declaration",
3623 check_modifiers ((current_function_decl ?
3624 "Illegal modifier %qs for local class declaration" :
3625 "Illegal modifier %qs for class declaration"),
3626 flags, uaaf|sca|icaf);
3630 /* Construct a nested class name. If the final component starts with
3631 a digit, return true. Otherwise return false. */
3633 make_nested_class_name (tree cpc_list)
3640 make_nested_class_name (TREE_CHAIN (cpc_list));
3642 /* Pick the qualified name when dealing with the first upmost
3644 name = (TREE_CHAIN (cpc_list)
3645 ? TREE_PURPOSE (cpc_list) : DECL_NAME (TREE_VALUE (cpc_list)));
3646 obstack_grow (&temporary_obstack,
3647 IDENTIFIER_POINTER (name), IDENTIFIER_LENGTH (name));
3648 obstack_1grow (&temporary_obstack, '$');
3650 return ISDIGIT (IDENTIFIER_POINTER (name)[0]);
3653 /* Can't redefine a class already defined in an earlier scope. */
3656 check_inner_class_redefinition (tree raw_name, tree cl)
3660 for (scope_list = GET_CPC_LIST (); scope_list;
3661 scope_list = GET_NEXT_ENCLOSING_CPC (scope_list))
3662 if (raw_name == GET_CPC_UN_NODE (scope_list))
3665 (cl, "The class name %qs is already defined in this scope. An inner class may not have the same simple name as any of its enclosing classes",
3666 IDENTIFIER_POINTER (raw_name));
3672 /* Tries to find a decl for CLASS_TYPE within ENCLOSING. May return an
3673 invisible/non-accessible matching decl when an accessible one could not be
3674 found, in order to give a better error message when accessibility is
3678 resolve_inner_class (tree context, tree cl, tree enclosing, tree class_type)
3680 tree local_super = NULL_TREE;
3681 tree candidate = NULL_TREE;
3683 /* This hash table is used to register the classes we're going
3684 through when searching the current class as an inner class, in
3685 order to detect circular references. */
3686 htab_t circularity_hash = htab_create (20, htab_hash_pointer, htab_eq_pointer,
3693 *htab_find_slot (circularity_hash, enclosing, INSERT) = enclosing;
3695 if ((decl = find_as_inner_class (enclosing, class_type, cl)))
3697 if (inner_class_accessible (decl, context))
3703 if (candidate == NULL_TREE)
3707 /* Now go to the upper classes, bail out if necessary. We will
3708 analyze the returned SUPER and act accordingly (see
3709 do_resolve_class). */
3710 if (JPRIMITIVE_TYPE_P (TREE_TYPE (enclosing))
3711 || TREE_TYPE (enclosing) == void_type_node)
3713 parse_error_context (cl, "Qualifier must be a reference");
3714 enclosing = NULL_TREE;
3717 local_super = CLASSTYPE_SUPER (TREE_TYPE (enclosing));
3718 if (!local_super || local_super == object_type_node)
3721 if (TREE_CODE (local_super) == POINTER_TYPE)
3722 local_super = do_resolve_class (NULL, NULL, local_super, NULL, NULL);
3724 local_super = TYPE_NAME (local_super);
3726 /* We may not have checked for circular inheritance yet, so do so
3727 here to prevent an infinite loop. */
3728 if (htab_find (circularity_hash, local_super) != NULL)
3731 cl = lookup_cl (enclosing);
3734 (cl, "Cyclic inheritance involving %s",
3735 IDENTIFIER_POINTER (DECL_NAME (enclosing)));
3736 enclosing = NULL_TREE;
3739 enclosing = local_super;
3742 htab_delete (circularity_hash);
3744 /* We failed, but we might have found a matching class that wasn't
3745 accessible. Return that to get a better error message. */
3749 /* Within ENCLOSING, find a decl for NAME and return it. NAME can be
3753 find_as_inner_class (tree enclosing, tree name, tree cl)
3755 tree qual, to_return;
3759 name = TYPE_NAME (name);
3761 /* First search: within the scope of `enclosing', search for name */
3762 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3763 qual = EXPR_WFL_QUALIFICATION (cl);
3765 qual = build_tree_list (cl, NULL_TREE);
3767 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3769 if ((to_return = find_as_inner_class_do (qual, enclosing)))
3772 /* We're dealing with a qualified name. Try to resolve thing until
3773 we get something that is an enclosing class. */
3774 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3776 tree acc = NULL_TREE, decl = NULL_TREE, ptr;
3778 for (qual = EXPR_WFL_QUALIFICATION (cl); qual && !decl;
3779 qual = TREE_CHAIN (qual))
3781 acc = merge_qualified_name (acc,
3782 EXPR_WFL_NODE (TREE_PURPOSE (qual)));
3783 BUILD_PTR_FROM_NAME (ptr, acc);
3784 decl = do_resolve_class (NULL_TREE, NULL_TREE, ptr, NULL_TREE, cl);
3787 /* A NULL qual and a decl means that the search ended
3788 successfully?!? We have to do something then. FIXME */
3793 qual = EXPR_WFL_QUALIFICATION (cl);
3795 /* Otherwise, create a qual for the other part of the resolution. */
3797 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3799 return find_as_inner_class_do (qual, enclosing);
3802 /* We go inside the list of sub classes and try to find a way
3806 find_as_inner_class_do (tree qual, tree enclosing)
3811 for (; qual && enclosing; qual = TREE_CHAIN (qual))
3813 tree name_to_match = EXPR_WFL_NODE (TREE_PURPOSE (qual));
3814 tree next_enclosing = NULL_TREE;
3817 for (inner_list = DECL_INNER_CLASS_LIST (enclosing);
3818 inner_list; inner_list = TREE_CHAIN (inner_list))
3820 if (TREE_VALUE (inner_list) == name_to_match)
3822 next_enclosing = TREE_PURPOSE (inner_list);
3826 enclosing = next_enclosing;
3829 return (!qual && enclosing ? enclosing : NULL_TREE);
3833 link_nested_class_to_enclosing (void)
3835 if (GET_ENCLOSING_CPC ())
3837 tree enclosing = GET_ENCLOSING_CPC_CONTEXT ();
3838 DECL_INNER_CLASS_LIST (enclosing) =
3839 tree_cons (GET_CPC (), GET_CPC_UN (),
3840 DECL_INNER_CLASS_LIST (enclosing));
3845 maybe_make_nested_class_name (tree name)
3847 tree id = NULL_TREE;
3851 /* If we're in a function, we must append a number to create the
3852 nested class name. However, we don't do this if the class we
3853 are constructing is anonymous, because in that case we'll
3854 already have a number as the class name. */
3855 if (! make_nested_class_name (GET_CPC_LIST ())
3856 && current_function_decl != NULL_TREE
3857 && ! ISDIGIT (IDENTIFIER_POINTER (name)[0]))
3860 sprintf (buf, "%d", anonymous_class_counter);
3861 ++anonymous_class_counter;
3862 obstack_grow (&temporary_obstack, buf, strlen (buf));
3863 obstack_1grow (&temporary_obstack, '$');
3865 obstack_grow0 (&temporary_obstack,
3866 IDENTIFIER_POINTER (name),
3867 IDENTIFIER_LENGTH (name));
3868 id = get_identifier (obstack_finish (&temporary_obstack));
3870 QUALIFIED_P (id) = 1;
3875 /* If DECL is NULL, create and push a new DECL, record the current
3876 line CL and do other maintenance things. */
3879 maybe_create_class_interface_decl (tree decl, tree raw_name,
3880 tree qualified_name, tree cl)
3883 decl = push_class (make_class (), qualified_name);
3885 /* Take care of the file and line business */
3886 #ifdef USE_MAPPED_LOCATION
3887 DECL_SOURCE_LOCATION (decl) = EXPR_LOCATION (cl);
3889 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
3890 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
3892 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
3893 CLASS_PARSED_P (TREE_TYPE (decl)) = 1;
3894 #ifdef USE_MAPPED_LOCATION
3896 tree tmp = maybe_get_identifier (EXPR_FILENAME (cl));
3897 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3898 tmp && IS_A_COMMAND_LINE_FILENAME_P (tmp);
3901 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3902 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
3905 PUSH_CPC (decl, raw_name);
3906 DECL_CONTEXT (decl) = GET_ENCLOSING_CPC_CONTEXT ();
3908 /* Link the declaration to the already seen ones */
3909 TREE_CHAIN (decl) = ctxp->class_list;
3910 ctxp->class_list = decl;
3912 /* Create a new nodes in the global lists */
3913 gclass_list = tree_cons (NULL_TREE, decl, gclass_list);
3914 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
3916 /* Install a new dependency list element */
3917 create_jdep_list (ctxp);
3919 /* We keep the compilation unit imports in the class so that
3920 they can be used later to resolve type dependencies that
3921 aren't necessary to solve now. */
3922 TYPE_IMPORT_LIST (TREE_TYPE (decl)) = ctxp->import_list;
3923 TYPE_IMPORT_DEMAND_LIST (TREE_TYPE (decl)) = ctxp->import_demand_list;
3925 TYPE_PACKAGE (TREE_TYPE (decl)) = ctxp->package;
3927 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
3928 IDENTIFIER_POINTER (qualified_name)));
3933 add_superinterfaces (tree decl, tree interface_list)
3936 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3937 takes care of ensuring that:
3938 - This is an accessible interface type,
3939 - Circularity detection.
3940 parser_add_interface is then called. If present but not defined,
3941 the check operation is delayed until the super interface gets
3943 for (node = interface_list; node; node = TREE_CHAIN (node))
3945 tree current = TREE_PURPOSE (node);
3946 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
3947 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
3949 if (!parser_check_super_interface (idecl, decl, current))
3950 parser_add_interface (decl, idecl, current);
3953 register_incomplete_type (JDEP_INTERFACE,
3954 current, decl, NULL_TREE);
3958 /* Create an interface in pass1 and return its decl. Return the
3959 interface's decl in pass 2. */
3962 create_interface (int flags, tree id, tree super)
3964 tree raw_name = EXPR_WFL_NODE (id);
3965 tree q_name = parser_qualified_classname (raw_name);
3966 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
3968 /* Certain syntax errors are making SUPER be like ID. Avoid this
3970 if (ctxp->class_err && id == super)
3973 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
3975 /* Basic checks: scope, redefinition, modifiers */
3976 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
3982 /* Suspend the current parsing context if we're parsing an inner
3986 java_parser_context_suspend ();
3987 /* Interface members are public. */
3988 if (CLASS_INTERFACE (GET_CPC ()))
3989 flags |= ACC_PUBLIC;
3992 /* Push a new context for (static) initialized upon declaration fields */
3993 java_parser_context_push_initialized_field ();