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
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);
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_outer_method_access_method (tree);
330 static tree build_new_access_id (void);
332 static int nested_field_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");
1039 | modifiers type error
1041 yyerror ("Identifier expected");
1046 yyerror ("Identifier expected");
1049 | modifiers VOID_TK error
1051 yyerror ("Identifier expected");
1056 yyerror ("Invalid method declaration, return type required");
1062 identifier OP_TK CP_TK
1064 ctxp->formal_parameter_number = 0;
1065 $$ = method_declarator ($1, NULL_TREE);
1067 | identifier OP_TK formal_parameter_list CP_TK
1068 { $$ = method_declarator ($1, $3); }
1069 | method_declarator OSB_TK CSB_TK
1071 SET_EXPR_LOCATION_FROM_TOKEN (wfl_operator, $2);
1073 build_unresolved_array_type (TREE_PURPOSE ($1));
1074 parse_warning_context
1076 "Discouraged form of returned type specification");
1078 | identifier OP_TK error
1079 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1080 | method_declarator OSB_TK error
1081 {yyerror ("']' expected"); RECOVER;}
1084 formal_parameter_list:
1087 ctxp->formal_parameter_number = 1;
1089 | formal_parameter_list C_TK formal_parameter
1091 ctxp->formal_parameter_number += 1;
1092 $$ = chainon ($1, $3);
1094 | formal_parameter_list C_TK error
1095 { yyerror ("Missing formal parameter term"); RECOVER; }
1099 type variable_declarator_id
1101 $$ = build_tree_list ($2, $1);
1103 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1105 $$ = build_tree_list ($3, $2);
1106 ARG_FINAL_P ($$) = 1;
1110 yyerror ("Missing identifier"); RECOVER;
1115 yyerror ("Missing identifier"); RECOVER;
1123 check_modifiers ("Illegal modifier %qs. Only %<final%> was expected here",
1125 if ($1 != ACC_FINAL)
1126 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1132 | THROWS_TK class_type_list
1135 {yyerror ("Missing class type term"); RECOVER;}
1140 { $$ = build_tree_list ($1, $1); }
1141 | class_type_list C_TK class_type
1142 { $$ = tree_cons ($3, $3, $1); }
1143 | class_type_list C_TK error
1144 {yyerror ("Missing class type term"); RECOVER;}
1149 | SC_TK { $$ = NULL_TREE; }
1152 /* 19.8.4 Productions from 8.5: Static Initializers */
1156 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1157 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1158 current_static_block = NULL_TREE;
1162 static: /* Test lval.sub_token here */
1165 check_modifiers ("Illegal modifier %qs for static initializer", $1, ACC_STATIC);
1166 /* Can't have a static initializer in an innerclass */
1167 if ($1 | ACC_STATIC &&
1168 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1170 (MODIFIER_WFL (STATIC_TK),
1171 "Can't define static initializer in class %qs. Static initializer can only be defined in top-level classes",
1172 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1173 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1177 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1178 constructor_declaration:
1181 current_function_decl = $1;
1182 source_start_java_method (current_function_decl);
1185 { finish_method_declaration ($3); }
1189 constructor_declarator throws
1190 { $$ = method_header (0, NULL_TREE, $1, $2); }
1191 | modifiers constructor_declarator throws
1192 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1195 constructor_declarator:
1196 simple_name OP_TK CP_TK
1198 ctxp->formal_parameter_number = 0;
1199 $$ = method_declarator ($1, NULL_TREE);
1201 | simple_name OP_TK formal_parameter_list CP_TK
1202 { $$ = method_declarator ($1, $3); }
1206 /* Unlike regular method, we always need a complete (empty)
1207 body so we can safely perform all the required code
1208 addition (super invocation and field initialization) */
1209 block_begin constructor_block_end
1211 BLOCK_EXPR_BODY ($2) = build_java_empty_stmt ();
1214 | block_begin explicit_constructor_invocation constructor_block_end
1216 | block_begin block_statements constructor_block_end
1218 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1222 constructor_block_end:
1226 /* Error recovery for that rule moved down expression_statement: rule. */
1227 explicit_constructor_invocation:
1228 this_or_super OP_TK CP_TK SC_TK
1230 $$ = build_method_invocation ($1, NULL_TREE);
1231 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1232 $$ = java_method_add_stmt (current_function_decl, $$);
1234 | this_or_super OP_TK argument_list CP_TK SC_TK
1236 $$ = build_method_invocation ($1, $3);
1237 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1238 $$ = java_method_add_stmt (current_function_decl, $$);
1240 /* Added, JDK1.1 inner classes. Modified because the rule
1241 'primary' couldn't work. */
1242 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1243 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1244 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1245 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1248 this_or_super: /* Added, simplifies error diagnostics */
1251 tree wfl = build_wfl_node (this_identifier_node);
1252 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1257 tree wfl = build_wfl_node (super_identifier_node);
1258 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1263 /* 19.9 Productions from 9: Interfaces */
1264 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1265 interface_declaration:
1266 INTERFACE_TK identifier
1267 { create_interface (0, $2, NULL_TREE); }
1270 | modifiers INTERFACE_TK identifier
1271 { create_interface ($1, $3, NULL_TREE); }
1274 | INTERFACE_TK identifier extends_interfaces
1275 { create_interface (0, $2, $3); }
1278 | modifiers INTERFACE_TK identifier extends_interfaces
1279 { create_interface ($1, $3, $4); }
1282 | INTERFACE_TK identifier error
1283 { yyerror ("'{' expected"); RECOVER; }
1284 | modifiers INTERFACE_TK identifier error
1285 { yyerror ("'{' expected"); RECOVER; }
1289 EXTENDS_TK interface_type
1291 ctxp->interface_number = 1;
1292 $$ = build_tree_list ($2, NULL_TREE);
1294 | extends_interfaces C_TK interface_type
1296 ctxp->interface_number++;
1297 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1300 {yyerror ("Invalid interface type"); RECOVER;}
1301 | extends_interfaces C_TK error
1302 {yyerror ("Missing term"); RECOVER;}
1308 | OCB_TK interface_member_declarations CCB_TK
1312 interface_member_declarations:
1313 interface_member_declaration
1314 | interface_member_declarations interface_member_declaration
1317 interface_member_declaration:
1318 constant_declaration
1319 | abstract_method_declaration
1320 | class_declaration /* Added, JDK1.1 inner classes */
1321 { end_class_declaration (1); }
1322 | interface_declaration /* Added, JDK1.1 inner interfaces */
1323 { end_class_declaration (1); }
1327 constant_declaration:
1331 abstract_method_declaration:
1334 check_abstract_method_header ($1);
1335 current_function_decl = NULL_TREE; /* FIXME ? */
1337 | method_header error
1338 {yyerror ("';' expected"); RECOVER;}
1341 /* 19.10 Productions from 10: Arrays */
1344 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1345 | OCB_TK C_TK CCB_TK
1346 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1347 | OCB_TK variable_initializers CCB_TK
1348 { $$ = build_new_array_init ($1.location, $2); }
1349 | OCB_TK variable_initializers C_TK CCB_TK
1350 { $$ = build_new_array_init ($1.location, $2); }
1353 variable_initializers:
1354 variable_initializer
1356 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1359 | variable_initializers C_TK variable_initializer
1361 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1363 | variable_initializers C_TK error
1364 {yyerror ("Missing term"); RECOVER;}
1367 /* 19.11 Production from 14: Blocks and Statements */
1369 block_begin block_end
1371 | block_begin block_statements block_end
1383 maybe_absorb_scoping_blocks ();
1385 if (!BLOCK_SUBBLOCKS ($$))
1386 BLOCK_SUBBLOCKS ($$) = build_java_empty_stmt ();
1392 | block_statements block_statement
1396 local_variable_declaration_statement
1398 { java_method_add_stmt (current_function_decl, $1); }
1399 | class_declaration /* Added, JDK1.1 local classes */
1401 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1402 end_class_declaration (1);
1406 local_variable_declaration_statement:
1407 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1410 local_variable_declaration:
1411 type variable_declarators
1412 { declare_local_variables (0, $1, $2); }
1413 | final type variable_declarators /* Added, JDK1.1 final locals */
1414 { declare_local_variables ($1, $2, $3); }
1418 statement_without_trailing_substatement
1421 | if_then_else_statement
1424 { $$ = exit_block (); }
1428 statement_without_trailing_substatement
1429 | labeled_statement_nsi
1430 | if_then_else_statement_nsi
1431 | while_statement_nsi
1433 { $$ = exit_block (); }
1436 statement_without_trailing_substatement:
1439 | expression_statement
1443 | continue_statement
1445 | synchronized_statement
1454 if (flag_extraneous_semicolon
1455 && ! current_static_block
1456 && (! current_function_decl ||
1457 /* Verify we're not in a inner class declaration */
1458 (GET_CPC () != TYPE_NAME
1459 (DECL_CONTEXT (current_function_decl)))))
1462 #ifdef USE_MAPPED_LOCATION
1463 SET_EXPR_LOCATION (wfl_operator, input_location);
1465 EXPR_WFL_SET_LINECOL (wfl_operator, input_line, -1);
1467 parse_warning_context (wfl_operator, "An empty declaration is a deprecated feature that should not be used");
1469 $$ = build_java_empty_stmt ();
1474 identifier REL_CL_TK
1476 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1477 EXPR_WFL_NODE ($1));
1479 push_labeled_block ($$);
1480 PUSH_LABELED_BLOCK ($$);
1485 label_decl statement
1486 { $$ = finish_labeled_statement ($1, $2); }
1488 {yyerror ("':' expected"); RECOVER;}
1491 labeled_statement_nsi:
1492 label_decl statement_nsi
1493 { $$ = finish_labeled_statement ($1, $2); }
1496 /* We concentrate here a bunch of error handling rules that we couldn't write
1497 earlier, because expression_statement catches a missing ';'. */
1498 expression_statement:
1499 statement_expression SC_TK
1501 /* We have a statement. Generate a WFL around it so
1503 #ifdef USE_MAPPED_LOCATION
1504 $$ = expr_add_location ($1, input_location, 1);
1506 $$ = build_expr_wfl ($1, input_filename, input_line, 0);
1507 JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1509 /* We know we have a statement, so set the debug
1510 info to be eventually generate here. */
1514 YYNOT_TWICE yyerror ("Invalid expression statement");
1515 DRECOVER (expr_stmt);
1519 YYNOT_TWICE yyerror ("Invalid expression statement");
1520 DRECOVER (expr_stmt);
1524 YYNOT_TWICE yyerror ("Invalid expression statement");
1525 DRECOVER (expr_stmt);
1527 | this_or_super OP_TK error
1528 {yyerror ("')' expected"); RECOVER;}
1529 | this_or_super OP_TK CP_TK error
1531 parse_ctor_invocation_error ();
1534 | this_or_super OP_TK argument_list error
1535 {yyerror ("')' expected"); RECOVER;}
1536 | this_or_super OP_TK argument_list CP_TK error
1538 parse_ctor_invocation_error ();
1541 | name DOT_TK SUPER_TK error
1542 {yyerror ("'(' expected"); RECOVER;}
1543 | name DOT_TK SUPER_TK OP_TK error
1544 {yyerror ("')' expected"); RECOVER;}
1545 | name DOT_TK SUPER_TK OP_TK argument_list error
1546 {yyerror ("')' expected"); RECOVER;}
1547 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1548 {yyerror ("';' expected"); RECOVER;}
1549 | name DOT_TK SUPER_TK OP_TK CP_TK error
1550 {yyerror ("';' expected"); RECOVER;}
1553 statement_expression:
1555 | pre_increment_expression
1556 | pre_decrement_expression
1557 | post_increment_expression
1558 | post_decrement_expression
1560 | class_instance_creation_expression
1564 IF_TK OP_TK expression CP_TK statement
1566 $$ = build_if_else_statement ($2.location, $3,
1570 {yyerror ("'(' expected"); RECOVER;}
1572 {yyerror ("Missing term"); RECOVER;}
1573 | IF_TK OP_TK expression error
1574 {yyerror ("')' expected"); RECOVER;}
1577 if_then_else_statement:
1578 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1579 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1582 if_then_else_statement_nsi:
1583 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1584 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1594 /* Make into "proper list" of COMPOUND_EXPRs.
1595 I.e. make the last statement also have its own
1597 maybe_absorb_scoping_blocks ();
1598 TREE_OPERAND ($1, 1) = exit_block ();
1599 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1604 SWITCH_TK OP_TK expression CP_TK
1606 $$ = build3 (SWITCH_EXPR, NULL_TREE, $3,
1607 NULL_TREE, NULL_TREE);
1608 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
1611 {yyerror ("'(' expected"); RECOVER;}
1612 | SWITCH_TK OP_TK error
1613 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1614 | SWITCH_TK OP_TK expression CP_TK error
1615 {yyerror ("'{' expected"); RECOVER;}
1618 /* Default assignment is there to avoid type node on switch_block
1624 | OCB_TK switch_labels CCB_TK
1626 | OCB_TK switch_block_statement_groups CCB_TK
1628 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1632 switch_block_statement_groups:
1633 switch_block_statement_group
1634 | switch_block_statement_groups switch_block_statement_group
1637 switch_block_statement_group:
1638 switch_labels block_statements
1643 | switch_labels switch_label
1647 CASE_TK constant_expression REL_CL_TK
1649 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1650 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1651 java_method_add_stmt (current_function_decl, lab);
1653 | DEFAULT_TK REL_CL_TK
1655 tree lab = make_node (DEFAULT_EXPR);
1656 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1657 java_method_add_stmt (current_function_decl, lab);
1660 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1661 | CASE_TK constant_expression error
1662 {yyerror ("':' expected"); RECOVER;}
1664 {yyerror ("':' expected"); RECOVER;}
1668 WHILE_TK OP_TK expression CP_TK
1670 tree body = build_loop_body ($2.location, $3, 0);
1671 $$ = build_new_loop (body);
1676 while_expression statement
1677 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1679 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1680 | WHILE_TK OP_TK error
1681 {yyerror ("Missing term and ')' expected"); RECOVER;}
1682 | WHILE_TK OP_TK expression error
1683 {yyerror ("')' expected"); RECOVER;}
1686 while_statement_nsi:
1687 while_expression statement_nsi
1688 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1694 tree body = build_loop_body (0, NULL_TREE, 1);
1695 $$ = build_new_loop (body);
1697 /* Need error handing here. FIXME */
1701 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1702 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1706 for_begin SC_TK expression SC_TK for_update CP_TK statement
1708 if (CONSTANT_CLASS_P ($3))
1709 $3 = build_wfl_node ($3);
1710 $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1712 | for_begin SC_TK SC_TK for_update CP_TK statement
1714 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1715 /* We have not condition, so we get rid of the EXIT_EXPR */
1716 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1717 build_java_empty_stmt ();
1719 | for_begin SC_TK error
1720 {yyerror ("Invalid control expression"); RECOVER;}
1721 | for_begin SC_TK expression SC_TK error
1722 {yyerror ("Invalid update expression"); RECOVER;}
1723 | for_begin SC_TK SC_TK error
1724 {yyerror ("Invalid update expression"); RECOVER;}
1728 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1729 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1730 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1732 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1733 /* We have not condition, so we get rid of the EXIT_EXPR */
1734 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1735 build_java_empty_stmt ();
1742 /* This scope defined for local variable that may be
1743 defined within the scope of the for loop */
1747 {yyerror ("'(' expected"); DRECOVER(for_1);}
1748 | FOR_TK OP_TK error
1749 {yyerror ("Invalid init statement"); RECOVER;}
1755 /* We now declare the loop body. The loop is
1756 declared as a for loop. */
1757 tree body = build_loop_body (0, NULL_TREE, 0);
1758 $$ = build_new_loop (body);
1759 FOR_LOOP_P ($$) = 1;
1760 /* The loop is added to the current block the for
1761 statement is defined within */
1762 java_method_add_stmt (current_function_decl, $$);
1765 for_init: /* Can be empty */
1766 { $$ = build_java_empty_stmt (); }
1767 | statement_expression_list
1769 /* Init statement recorded within the previously
1770 defined block scope */
1771 $$ = java_method_add_stmt (current_function_decl, $1);
1773 | local_variable_declaration
1775 /* Local variable are recorded within the previously
1776 defined block scope */
1779 | statement_expression_list error
1780 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1783 for_update: /* Can be empty */
1784 {$$ = build_java_empty_stmt ();}
1785 | statement_expression_list
1786 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1789 statement_expression_list:
1790 statement_expression
1791 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1792 | statement_expression_list C_TK statement_expression
1793 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1794 | statement_expression_list C_TK error
1795 {yyerror ("Missing term"); RECOVER;}
1800 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1801 | BREAK_TK identifier SC_TK
1802 { $$ = build_bc_statement ($1.location, 1, $2); }
1804 {yyerror ("Missing term"); RECOVER;}
1805 | BREAK_TK identifier error
1806 {yyerror ("';' expected"); RECOVER;}
1811 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1812 | CONTINUE_TK identifier SC_TK
1813 { $$ = build_bc_statement ($1.location, 0, $2); }
1815 {yyerror ("Missing term"); RECOVER;}
1816 | CONTINUE_TK identifier error
1817 {yyerror ("';' expected"); RECOVER;}
1822 { $$ = build_return ($1.location, NULL_TREE); }
1823 | RETURN_TK expression SC_TK
1824 { $$ = build_return ($1.location, $2); }
1826 {yyerror ("Missing term"); RECOVER;}
1827 | RETURN_TK expression error
1828 {yyerror ("';' expected"); RECOVER;}
1832 THROW_TK expression SC_TK
1834 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1835 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1838 {yyerror ("Missing term"); RECOVER;}
1839 | THROW_TK expression error
1840 {yyerror ("';' expected"); RECOVER;}
1844 ASSERT_TK expression REL_CL_TK expression SC_TK
1846 $$ = build_assertion ($1.location, $2, $4);
1848 | ASSERT_TK expression SC_TK
1850 $$ = build_assertion ($1.location, $2, NULL_TREE);
1853 {yyerror ("Missing term"); RECOVER;}
1854 | ASSERT_TK expression error
1855 {yyerror ("';' expected"); RECOVER;}
1858 synchronized_statement:
1859 synchronized OP_TK expression CP_TK block
1861 $$ = build2 (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1862 EXPR_WFL_LINECOL ($$) =
1863 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1865 | synchronized OP_TK expression CP_TK error
1866 {yyerror ("'{' expected"); RECOVER;}
1867 | synchronized error
1868 {yyerror ("'(' expected"); RECOVER;}
1869 | synchronized OP_TK error CP_TK
1870 {yyerror ("Missing term"); RECOVER;}
1871 | synchronized OP_TK error
1872 {yyerror ("Missing term"); RECOVER;}
1879 "Illegal modifier %qs. Only %<synchronized%> was expected here",
1880 $1, ACC_SYNCHRONIZED);
1881 if ($1 != ACC_SYNCHRONIZED)
1882 MODIFIER_WFL (SYNCHRONIZED_TK) =
1883 build_wfl_node (NULL_TREE);
1888 TRY_TK block catches
1889 { $$ = build_try_statement ($1.location, $2, $3); }
1890 | TRY_TK block finally
1891 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1892 | TRY_TK block catches finally
1893 { $$ = build_try_finally_statement
1894 ($1.location, build_try_statement ($1.location,
1898 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1903 | catches catch_clause
1905 TREE_CHAIN ($2) = $1;
1911 catch_clause_parameter block
1913 java_method_add_stmt (current_function_decl, $2);
1919 catch_clause_parameter:
1920 CATCH_TK OP_TK formal_parameter CP_TK
1922 /* We add a block to define a scope for
1923 formal_parameter (CCBP). The formal parameter is
1924 declared initialized by the appropriate function
1930 ccpb = enter_block ();
1931 init = build_assignment
1932 (ASSIGN_TK, $2.location, TREE_PURPOSE ($3),
1933 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
1934 declare_local_variables (0, TREE_VALUE ($3),
1936 (TREE_PURPOSE ($3), init));
1937 $$ = build1 (JAVA_CATCH_EXPR, NULL_TREE, ccpb);
1938 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1942 $$ = error_mark_node;
1946 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1947 | CATCH_TK OP_TK error
1949 yyerror ("Missing term or ')' expected");
1950 RECOVER; $$ = NULL_TREE;
1952 | CATCH_TK OP_TK error CP_TK /* That's for () */
1953 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1960 {yyerror ("'{' expected"); RECOVER; }
1963 /* 19.12 Production from 15: Expressions */
1965 primary_no_new_array
1966 | array_creation_uninitialized
1967 | array_creation_initialized
1970 primary_no_new_array:
1973 { $$ = build_this ($1.location); }
1974 | OP_TK expression CP_TK
1976 | class_instance_creation_expression
1981 /* Added, JDK1.1 inner classes. Documentation is wrong
1982 referring to a 'ClassName' (class_name) rule that doesn't
1983 exist. Used name: instead. */
1984 | name DOT_TK THIS_TK
1986 tree wfl = build_wfl_node (this_identifier_node);
1987 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
1989 | OP_TK expression error
1990 {yyerror ("')' expected"); RECOVER;}
1992 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1993 | primitive_type DOT_TK error
1994 {yyerror ("'class' expected" ); RECOVER;}
1995 | VOID_TK DOT_TK error
1996 {yyerror ("'class' expected" ); RECOVER;}
2000 name DOT_TK CLASS_TK
2001 { $$ = build_incomplete_class_ref ($2.location, $1); }
2002 | array_type DOT_TK CLASS_TK
2003 { $$ = build_incomplete_class_ref ($2.location, $1); }
2004 | primitive_type DOT_TK CLASS_TK
2005 { $$ = build_incomplete_class_ref ($2.location, $1); }
2006 | VOID_TK DOT_TK CLASS_TK
2008 $$ = build_incomplete_class_ref ($2.location,
2013 class_instance_creation_expression:
2014 NEW_TK class_type OP_TK argument_list CP_TK
2015 { $$ = build_new_invocation ($2, $4); }
2016 | NEW_TK class_type OP_TK CP_TK
2017 { $$ = build_new_invocation ($2, NULL_TREE); }
2018 | anonymous_class_creation
2019 /* Added, JDK1.1 inner classes, modified to use name or
2020 primary instead of primary solely which couldn't work in
2022 | something_dot_new identifier OP_TK CP_TK
2024 tree ctor = build_new_invocation ($2, NULL_TREE);
2025 $$ = make_qualified_primary ($1, ctor,
2026 EXPR_WFL_LINECOL ($1));
2028 | something_dot_new identifier OP_TK CP_TK class_body
2029 | something_dot_new identifier OP_TK argument_list CP_TK
2031 tree ctor = build_new_invocation ($2, $4);
2032 $$ = make_qualified_primary ($1, ctor,
2033 EXPR_WFL_LINECOL ($1));
2035 | something_dot_new identifier OP_TK argument_list CP_TK class_body
2036 | NEW_TK error SC_TK
2037 {$$ = NULL_TREE; yyerror ("'(' expected"); DRECOVER(new_1);}
2038 | NEW_TK class_type error
2039 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2040 | NEW_TK class_type OP_TK error
2041 {$$ = NULL_TREE; yyerror ("')' or term expected"); RECOVER;}
2042 | NEW_TK class_type OP_TK argument_list error
2043 {$$ = NULL_TREE; yyerror ("')' expected"); RECOVER;}
2044 | something_dot_new error
2048 yyerror ("Identifier expected");
2051 | something_dot_new identifier error
2052 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2055 /* Created after JDK1.1 rules originally added to
2056 class_instance_creation_expression, but modified to use
2057 'class_type' instead of 'TypeName' (type_name) which is mentioned
2058 in the documentation but doesn't exist. */
2060 anonymous_class_creation:
2061 NEW_TK class_type OP_TK argument_list CP_TK
2062 { create_anonymous_class ($2); }
2065 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2066 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2068 end_class_declaration (1);
2070 /* Now we can craft the new expression */
2071 $$ = build_new_invocation (id, $4);
2073 /* Note that we can't possibly be here if
2074 `class_type' is an interface (in which case the
2075 anonymous class extends Object and implements
2076 `class_type', hence its constructor can't have
2079 /* Otherwise, the innerclass must feature a
2080 constructor matching `argument_list'. Anonymous
2081 classes are a bit special: it's impossible to
2082 define constructor for them, hence constructors
2083 must be generated following the hints provided by
2084 the `new' expression. Whether a super constructor
2085 of that nature exists or not is to be verified
2086 later on in get_constructor_super.
2088 It's during the expansion of a `new' statement
2089 referring to an anonymous class that a ctor will
2090 be generated for the anonymous class, with the
2094 | NEW_TK class_type OP_TK CP_TK
2095 { create_anonymous_class ($2); }
2098 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2099 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2101 end_class_declaration (1);
2103 /* Now we can craft the new expression. The
2104 statement doesn't need to be remember so that a
2105 constructor can be generated, since its signature
2106 is already known. */
2107 $$ = build_new_invocation (id, NULL_TREE);
2111 something_dot_new: /* Added, not part of the specs. */
2114 | primary DOT_TK NEW_TK
2121 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2122 ctxp->formal_parameter_number = 1;
2124 | argument_list C_TK expression
2126 ctxp->formal_parameter_number += 1;
2127 $$ = tree_cons (NULL_TREE, $3, $1);
2129 | argument_list C_TK error
2130 {yyerror ("Missing term"); RECOVER;}
2133 array_creation_uninitialized:
2134 NEW_TK primitive_type dim_exprs
2135 { $$ = build_newarray_node ($2, $3, 0); }
2136 | NEW_TK class_or_interface_type dim_exprs
2137 { $$ = build_newarray_node ($2, $3, 0); }
2138 | NEW_TK primitive_type dim_exprs dims
2139 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2140 | NEW_TK class_or_interface_type dim_exprs dims
2141 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2142 | NEW_TK error CSB_TK
2143 {yyerror ("'[' expected"); DRECOVER ("]");}
2144 | NEW_TK error OSB_TK
2145 {yyerror ("']' expected"); RECOVER;}
2148 array_creation_initialized:
2149 /* Added, JDK1.1 anonymous array. Initial documentation rule
2151 NEW_TK class_or_interface_type dims array_initializer
2154 int osb = pop_current_osb (ctxp);
2156 obstack_grow (&temporary_obstack, "[]", 2);
2157 obstack_1grow (&temporary_obstack, '\0');
2158 sig = obstack_finish (&temporary_obstack);
2159 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2160 $2, get_identifier (sig), $4);
2162 | NEW_TK primitive_type dims array_initializer
2164 int osb = pop_current_osb (ctxp);
2167 type = build_java_array_type (type, -1);
2168 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2169 build_pointer_type (type), NULL_TREE, $4);
2171 | NEW_TK error CSB_TK
2172 {yyerror ("'[' expected"); DRECOVER ("]");}
2173 | NEW_TK error OSB_TK
2174 {yyerror ("']' expected"); RECOVER;}
2179 { $$ = build_tree_list (NULL_TREE, $1); }
2180 | dim_exprs dim_expr
2181 { $$ = tree_cons (NULL_TREE, $2, $$); }
2185 OSB_TK expression CSB_TK
2187 if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2189 $2 = build_wfl_node ($2);
2190 TREE_TYPE ($2) = NULL_TREE;
2192 EXPR_WFL_LINECOL ($2) = $1.location;
2195 | OSB_TK expression error
2196 {yyerror ("']' expected"); RECOVER;}
2199 yyerror ("Missing term");
2200 yyerror ("']' expected");
2209 /* If not initialized, allocate memory for the osb
2211 if (!ctxp->osb_limit)
2213 allocate = ctxp->osb_limit = 32;
2214 ctxp->osb_depth = -1;
2216 /* If capacity overflown, reallocate a bigger chunk */
2217 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2218 allocate = ctxp->osb_limit << 1;
2222 allocate *= sizeof (int);
2223 if (ctxp->osb_number)
2224 ctxp->osb_number = xrealloc (ctxp->osb_number,
2227 ctxp->osb_number = xmalloc (allocate);
2230 CURRENT_OSB (ctxp) = 1;
2232 | dims OSB_TK CSB_TK
2233 { CURRENT_OSB (ctxp)++; }
2235 { yyerror ("']' expected"); RECOVER;}
2239 primary DOT_TK identifier
2240 { $$ = make_qualified_primary ($1, $3, $2.location); }
2241 /* FIXME - REWRITE TO:
2242 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2243 | SUPER_TK DOT_TK identifier
2245 tree super_wfl = build_wfl_node (super_identifier_node);
2246 SET_EXPR_LOCATION_FROM_TOKEN (super_wfl, $1);
2247 $$ = make_qualified_name (super_wfl, $3, $2.location);
2250 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2255 { $$ = build_method_invocation ($1, NULL_TREE); }
2256 | name OP_TK argument_list CP_TK
2257 { $$ = build_method_invocation ($1, $3); }
2258 | primary DOT_TK identifier OP_TK CP_TK
2260 if (TREE_CODE ($1) == THIS_EXPR)
2261 $$ = build_this_super_qualified_invocation
2262 (1, $3, NULL_TREE, 0, $2.location);
2265 tree invok = build_method_invocation ($3, NULL_TREE);
2266 $$ = make_qualified_primary ($1, invok, $2.location);
2269 | primary DOT_TK identifier OP_TK argument_list CP_TK
2271 if (TREE_CODE ($1) == THIS_EXPR)
2272 $$ = build_this_super_qualified_invocation
2273 (1, $3, $5, 0, $2.location);
2276 tree invok = build_method_invocation ($3, $5);
2277 $$ = make_qualified_primary ($1, invok, $2.location);
2280 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2282 $$ = build_this_super_qualified_invocation
2283 (0, $3, NULL_TREE, $1.location, $2.location);
2285 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2287 $$ = build_this_super_qualified_invocation
2288 (0, $3, $5, $1.location, $2.location);
2290 /* Screws up thing. I let it here until I'm convinced it can
2292 | primary DOT_TK error
2293 {yyerror ("'(' expected"); DRECOVER(bad);} */
2294 | SUPER_TK DOT_TK error CP_TK
2295 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2296 | SUPER_TK DOT_TK error DOT_TK
2297 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2301 name OSB_TK expression CSB_TK
2302 { $$ = build_array_ref ($2.location, $1, $3); }
2303 | primary_no_new_array OSB_TK expression CSB_TK
2304 { $$ = build_array_ref ($2.location, $1, $3); }
2305 | array_creation_initialized OSB_TK expression CSB_TK
2306 { $$ = build_array_ref ($2.location, $1, $3); }
2309 yyerror ("Missing term and ']' expected");
2310 DRECOVER(array_access);
2312 | name OSB_TK expression error
2314 yyerror ("']' expected");
2315 DRECOVER(array_access);
2317 | primary_no_new_array OSB_TK error
2319 yyerror ("Missing term and ']' expected");
2320 DRECOVER(array_access);
2322 | primary_no_new_array OSB_TK expression error
2324 yyerror ("']' expected");
2325 DRECOVER(array_access);
2327 | array_creation_initialized OSB_TK error
2329 yyerror ("Missing term and ']' expected");
2330 DRECOVER(array_access);
2332 | array_creation_initialized OSB_TK expression error
2334 yyerror ("']' expected");
2335 DRECOVER(array_access);
2342 | post_increment_expression
2343 | post_decrement_expression
2346 post_increment_expression:
2347 postfix_expression INCR_TK
2348 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2351 post_decrement_expression:
2352 postfix_expression DECR_TK
2353 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2356 trap_overflow_corner_case:
2357 pre_increment_expression
2358 | pre_decrement_expression
2359 | PLUS_TK unary_expression
2360 {$$ = build_unaryop ($1.token, $1.location, $2); }
2361 | unary_expression_not_plus_minus
2363 {yyerror ("Missing term"); RECOVER}
2367 trap_overflow_corner_case
2370 error_if_numeric_overflow ($1);
2373 | MINUS_TK trap_overflow_corner_case
2374 {$$ = build_unaryop ($1.token, $1.location, $2); }
2376 {yyerror ("Missing term"); RECOVER}
2379 pre_increment_expression:
2380 INCR_TK unary_expression
2381 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2383 {yyerror ("Missing term"); RECOVER}
2386 pre_decrement_expression:
2387 DECR_TK unary_expression
2388 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2390 {yyerror ("Missing term"); RECOVER}
2393 unary_expression_not_plus_minus:
2395 | NOT_TK unary_expression
2396 {$$ = build_unaryop ($1.token, $1.location, $2); }
2397 | NEG_TK unary_expression
2398 {$$ = build_unaryop ($1.token, $1.location, $2); }
2401 {yyerror ("Missing term"); RECOVER}
2403 {yyerror ("Missing term"); RECOVER}
2406 cast_expression: /* Error handling here is potentially weak */
2407 OP_TK primitive_type dims CP_TK unary_expression
2410 int osb = pop_current_osb (ctxp);
2412 type = build_java_array_type (type, -1);
2413 $$ = build_cast ($1.location, type, $5);
2415 | OP_TK primitive_type CP_TK unary_expression
2416 { $$ = build_cast ($1.location, $2, $4); }
2417 | OP_TK expression CP_TK unary_expression_not_plus_minus
2418 { $$ = build_cast ($1.location, $2, $4); }
2419 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2422 int osb = pop_current_osb (ctxp);
2423 obstack_grow (&temporary_obstack,
2424 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2425 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2427 obstack_grow (&temporary_obstack, "[]", 2);
2428 obstack_1grow (&temporary_obstack, '\0');
2429 ptr = obstack_finish (&temporary_obstack);
2430 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2431 $$ = build_cast ($1.location, $2, $5);
2433 | OP_TK primitive_type OSB_TK error
2434 {yyerror ("']' expected, invalid type expression");}
2437 YYNOT_TWICE yyerror ("Invalid type expression"); RECOVER;
2440 | OP_TK primitive_type dims CP_TK error
2441 {yyerror ("Missing term"); RECOVER;}
2442 | OP_TK primitive_type CP_TK error
2443 {yyerror ("Missing term"); RECOVER;}
2444 | OP_TK name dims CP_TK error
2445 {yyerror ("Missing term"); RECOVER;}
2448 multiplicative_expression:
2450 | multiplicative_expression MULT_TK unary_expression
2452 $$ = build_binop (BINOP_LOOKUP ($2.token),
2453 $2.location, $1, $3);
2455 | multiplicative_expression DIV_TK unary_expression
2457 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2460 | multiplicative_expression REM_TK unary_expression
2462 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2465 | multiplicative_expression MULT_TK error
2466 {yyerror ("Missing term"); RECOVER;}
2467 | multiplicative_expression DIV_TK error
2468 {yyerror ("Missing term"); RECOVER;}
2469 | multiplicative_expression REM_TK error
2470 {yyerror ("Missing term"); RECOVER;}
2473 additive_expression:
2474 multiplicative_expression
2475 | additive_expression PLUS_TK multiplicative_expression
2477 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2480 | additive_expression MINUS_TK multiplicative_expression
2482 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2485 | additive_expression PLUS_TK error
2486 {yyerror ("Missing term"); RECOVER;}
2487 | additive_expression MINUS_TK error
2488 {yyerror ("Missing term"); RECOVER;}
2493 | shift_expression LS_TK additive_expression
2495 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2498 | shift_expression SRS_TK additive_expression
2500 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2503 | shift_expression ZRS_TK additive_expression
2505 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2508 | shift_expression LS_TK error
2509 {yyerror ("Missing term"); RECOVER;}
2510 | shift_expression SRS_TK error
2511 {yyerror ("Missing term"); RECOVER;}
2512 | shift_expression ZRS_TK error
2513 {yyerror ("Missing term"); RECOVER;}
2516 relational_expression:
2518 | relational_expression LT_TK shift_expression
2520 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2523 | relational_expression GT_TK shift_expression
2525 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2528 | relational_expression LTE_TK shift_expression
2530 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2533 | relational_expression GTE_TK shift_expression
2535 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2538 | relational_expression INSTANCEOF_TK reference_type
2539 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2540 | relational_expression LT_TK error
2541 {yyerror ("Missing term"); RECOVER;}
2542 | relational_expression GT_TK error
2543 {yyerror ("Missing term"); RECOVER;}
2544 | relational_expression LTE_TK error
2545 {yyerror ("Missing term"); RECOVER;}
2546 | relational_expression GTE_TK error
2547 {yyerror ("Missing term"); RECOVER;}
2548 | relational_expression INSTANCEOF_TK error
2549 {yyerror ("Invalid reference type"); RECOVER;}
2552 equality_expression:
2553 relational_expression
2554 | equality_expression EQ_TK relational_expression
2556 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2559 | equality_expression NEQ_TK relational_expression
2561 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2564 | equality_expression EQ_TK error
2565 {yyerror ("Missing term"); RECOVER;}
2566 | equality_expression NEQ_TK error
2567 {yyerror ("Missing term"); RECOVER;}
2572 | and_expression AND_TK equality_expression
2574 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2577 | and_expression AND_TK error
2578 {yyerror ("Missing term"); RECOVER;}
2581 exclusive_or_expression:
2583 | exclusive_or_expression XOR_TK and_expression
2585 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2588 | exclusive_or_expression XOR_TK error
2589 {yyerror ("Missing term"); RECOVER;}
2592 inclusive_or_expression:
2593 exclusive_or_expression
2594 | inclusive_or_expression OR_TK exclusive_or_expression
2596 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2599 | inclusive_or_expression OR_TK error
2600 {yyerror ("Missing term"); RECOVER;}
2603 conditional_and_expression:
2604 inclusive_or_expression
2605 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2607 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2610 | conditional_and_expression BOOL_AND_TK error
2611 {yyerror ("Missing term"); RECOVER;}
2614 conditional_or_expression:
2615 conditional_and_expression
2616 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2618 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2621 | conditional_or_expression BOOL_OR_TK error
2622 {yyerror ("Missing term"); RECOVER;}
2625 conditional_expression: /* Error handling here is weak */
2626 conditional_or_expression
2627 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2629 $$ = build3 (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2630 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
2632 | conditional_or_expression REL_QM_TK REL_CL_TK error
2635 yyerror ("Missing term");
2638 | conditional_or_expression REL_QM_TK error
2639 {yyerror ("Missing term"); DRECOVER (2);}
2640 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2641 {yyerror ("Missing term"); DRECOVER (3);}
2644 assignment_expression:
2645 conditional_expression
2650 left_hand_side assignment_operator assignment_expression
2651 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2652 | left_hand_side assignment_operator error
2654 YYNOT_TWICE yyerror ("Missing term");
2665 assignment_operator:
2671 assignment_expression
2674 constant_expression:
2680 /* Helper function to retrieve an OSB count. Should be used when the
2681 `dims:' rule is being used. */
2684 pop_current_osb (struct parser_ctxt *ctxp)
2688 if (ctxp->osb_depth < 0)
2691 to_return = CURRENT_OSB (ctxp);
2699 /* This section of the code deal with save/restoring parser contexts.
2700 Add mode documentation here. FIXME */
2702 /* Helper function. Create a new parser context. With
2703 COPY_FROM_PREVIOUS set to a nonzero value, content of the previous
2704 context is copied, otherwise, the new context is zeroed. The newly
2705 created context becomes the current one. */
2708 create_new_parser_context (int copy_from_previous)
2710 struct parser_ctxt *new;
2712 new = ggc_alloc (sizeof (struct parser_ctxt));
2713 if (copy_from_previous)
2715 memcpy (new, ctxp, sizeof (struct parser_ctxt));
2716 /* This flag, indicating the context saves global values,
2717 should only be set by java_parser_context_save_global. */
2718 new->saved_data_ctx = 0;
2721 memset (new, 0, sizeof (struct parser_ctxt));
2727 /* Create a new parser context and make it the current one. */
2730 java_push_parser_context (void)
2732 create_new_parser_context (0);
2736 java_pop_parser_context (int generate)
2739 struct parser_ctxt *next;
2747 input_location = ctxp->save_location;
2748 current_class = ctxp->class_type;
2751 /* If the old and new lexers differ, then free the old one. */
2752 if (ctxp->lexer && next && ctxp->lexer != next->lexer)
2753 java_destroy_lexer (ctxp->lexer);
2755 /* Set the single import class file flag to 0 for the current list
2756 of imported things */
2757 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2758 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 0;
2760 /* If we pushed a context to parse a class intended to be generated,
2761 we keep it so we can remember the class. What we could actually
2762 do is to just update a list of class names. */
2765 if (ctxp_for_generation_last == NULL)
2766 ctxp_for_generation = ctxp;
2768 ctxp_for_generation_last->next = ctxp;
2770 ctxp_for_generation_last = ctxp;
2773 /* And restore those of the previous context */
2774 if ((ctxp = next)) /* Assignment is really meant here */
2775 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2776 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 1;
2779 /* Create a parser context for the use of saving some global
2783 java_parser_context_save_global (void)
2787 java_push_parser_context ();
2788 ctxp->saved_data_ctx = 1;
2791 /* If this context already stores data, create a new one suitable
2792 for data storage. */
2793 else if (ctxp->saved_data)
2795 create_new_parser_context (1);
2796 ctxp->saved_data_ctx = 1;
2799 ctxp->save_location = input_location;
2800 ctxp->class_type = current_class;
2801 ctxp->function_decl = current_function_decl;
2802 ctxp->saved_data = 1;
2805 /* Restore some global variables from the previous context. Make the
2806 previous context the current one. */
2809 java_parser_context_restore_global (void)
2811 input_location = ctxp->save_location;
2812 current_class = ctxp->class_type;
2814 #ifdef USE_MAPPED_LOCATION
2815 SET_EXPR_LOCATION (wfl_operator, ctxp->save_location);
2817 EXPR_WFL_FILENAME_NODE (wfl_operator) = get_identifier (input_filename);
2819 current_function_decl = ctxp->function_decl;
2820 ctxp->saved_data = 0;
2821 if (ctxp->saved_data_ctx)
2822 java_pop_parser_context (0);
2825 /* Suspend vital data for the current class/function being parsed so
2826 that an other class can be parsed. Used to let local/anonymous
2827 classes be parsed. */
2830 java_parser_context_suspend (void)
2832 /* This makes debugging through java_debug_context easier */
2833 static const char *const name = "<inner buffer context>";
2835 /* Duplicate the previous context, use it to save the globals we're
2837 create_new_parser_context (1);
2838 ctxp->function_decl = current_function_decl;
2839 ctxp->class_type = current_class;
2841 /* Then create a new context which inherits all data from the
2842 previous one. This will be the new current context */
2843 create_new_parser_context (1);
2845 /* Help debugging */
2846 ctxp->next->filename = name;
2849 /* Resume vital data for the current class/function being parsed so
2850 that an other class can be parsed. Used to let local/anonymous
2851 classes be parsed. The trick is the data storing file position
2852 informations must be restored to their current value, so parsing
2853 can resume as if no context was ever saved. */
2856 java_parser_context_resume (void)
2858 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2859 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2860 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2862 /* We need to inherit the list of classes to complete/generate */
2863 restored->classd_list = old->classd_list;
2864 restored->class_list = old->class_list;
2866 /* Restore the current class and function from the saver */
2867 current_class = saver->class_type;
2868 current_function_decl = saver->function_decl;
2870 /* Retrieve the restored context */
2873 /* Re-installed the data for the parsing to carry on */
2874 memcpy (&ctxp->marker_begining, &old->marker_begining,
2875 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2878 /* Add a new anchor node to which all statement(s) initializing static
2879 and non static initialized upon declaration field(s) will be
2883 java_parser_context_push_initialized_field (void)
2887 node = build_tree_list (NULL_TREE, NULL_TREE);
2888 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2889 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2891 node = build_tree_list (NULL_TREE, NULL_TREE);
2892 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2893 CPC_INITIALIZER_LIST (ctxp) = node;
2895 node = build_tree_list (NULL_TREE, NULL_TREE);
2896 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2897 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2900 /* Pop the lists of initialized field. If this lists aren't empty,
2901 remember them so we can use it to create and populate the finit$
2902 or <clinit> functions. */
2905 java_parser_context_pop_initialized_field (void)
2908 tree class_type = TREE_TYPE (GET_CPC ());
2910 if (CPC_INITIALIZER_LIST (ctxp))
2912 stmts = CPC_INITIALIZER_STMT (ctxp);
2913 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2914 if (stmts && !java_error_count)
2915 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2918 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2920 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2921 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2922 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2923 /* Keep initialization in order to enforce 8.5 */
2924 if (stmts && !java_error_count)
2925 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2928 /* JDK 1.1 instance initializers */
2929 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2931 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2932 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2933 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2934 if (stmts && !java_error_count)
2935 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2940 reorder_static_initialized (tree list)
2942 /* We have to keep things in order. The alias initializer have to
2943 come first, then the initialized regular field, in reverse to
2944 keep them in lexical order. */
2945 tree marker, previous = NULL_TREE;
2946 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2947 if (TREE_CODE (marker) == TREE_LIST
2948 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2951 /* No static initialized, the list is fine as is */
2953 list = TREE_CHAIN (marker);
2955 /* No marker? reverse the whole list */
2957 list = nreverse (list);
2959 /* Otherwise, reverse what's after the marker and the new reordered
2960 sublist will replace the marker. */
2963 TREE_CHAIN (previous) = NULL_TREE;
2964 list = nreverse (list);
2965 list = chainon (TREE_CHAIN (marker), list);
2970 /* Helper functions to dump the parser context stack. */
2972 #define TAB_CONTEXT(C) \
2973 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2976 java_debug_context_do (int tab)
2978 struct parser_ctxt *copy = ctxp;
2982 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2984 fprintf (stderr, "filename: %s\n", copy->filename);
2986 fprintf (stderr, "package: %s\n",
2988 IDENTIFIER_POINTER (copy->package) : "<none>"));
2990 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2992 fprintf (stderr, "saved data: %d\n", copy->saved_data);
2998 /* Dump the stacked up parser contexts. Intended to be called from a
3002 java_debug_context (void)
3004 java_debug_context_do (0);
3009 /* Flag for the error report routine to issue the error the first time
3010 it's called (overriding the default behavior which is to drop the
3011 first invocation and honor the second one, taking advantage of a
3013 static int force_error = 0;
3015 /* Reporting an constructor invocation error. */
3017 parse_ctor_invocation_error (void)
3019 if (DECL_CONSTRUCTOR_P (current_function_decl))
3020 yyerror ("Constructor invocation must be first thing in a constructor");
3022 yyerror ("Only constructors can invoke constructors");
3025 /* Reporting JDK1.1 features not implemented. */
3028 parse_jdk1_1_error (const char *msg)
3030 sorry (": %qs JDK1.1(TM) feature", msg);
3032 return build_java_empty_stmt ();
3035 static int do_warning = 0;
3038 yyerror (const char *msgid)
3040 #ifdef USE_MAPPED_LOCATION
3041 static source_location elc;
3042 expanded_location xloc = expand_location (input_location);
3043 int current_line = xloc.line;
3047 int current_line = input_line;
3049 static int prev_lineno;
3050 static const char *prev_msg;
3052 char *remainder, *code_from_source;
3054 if (!force_error && prev_lineno == current_line)
3056 #ifndef USE_MAPPED_LOCATION
3057 current_line = ctxp->lexer->token_start.line;
3060 /* Save current error location but report latter, when the context is
3062 if (ctxp->java_error_flag == 0)
3064 ctxp->java_error_flag = 1;
3065 #ifdef USE_MAPPED_LOCATION
3066 elc = input_location;
3068 elc = ctxp->lexer->token_start;
3070 /* Do something to use the previous line if we're reaching the
3071 end of the file... */
3072 #ifdef VERBOSE_SKELETON
3073 printf ("* Error detected (%s)\n", (msgid ? msgid : "(null)"));
3078 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
3079 if (!force_error && msgid == prev_msg && prev_lineno == current_line)
3082 ctxp->java_error_flag = 0;
3084 java_warning_count++;
3089 if (elc.col == 0 && msgid && msgid[1] == ';')
3090 elc = ctxp->prev_line_end;
3095 #ifdef USE_MAPPED_LOCATION
3096 prev_lineno = current_line;
3097 code_from_source = java_get_line_col (xloc.file, current_line, xloc.column);
3099 save_lineno = input_line;
3100 prev_lineno = input_line = current_line;
3101 code_from_source = java_get_line_col (input_filename, current_line,
3102 ctxp->lexer->token_start.col);
3106 obstack_grow0 (&temporary_obstack,
3107 code_from_source, strlen (code_from_source));
3108 remainder = obstack_finish (&temporary_obstack);
3110 warning (0, "%s.\n%s", msgid, remainder);
3112 error ("%s.\n%s", msgid, remainder);
3114 /* This allow us to cheaply avoid an extra 'Invalid expression
3115 statement' error report when errors have been already reported on
3116 the same line. This occurs when we report an error but don't have
3117 a synchronization point other than ';', which
3118 expression_statement is the only one to take care of. */
3119 #ifndef USE_MAPPED_LOCATION
3120 input_line = save_lineno;
3122 ctxp->prevent_ese = input_line;
3126 issue_warning_error_from_context (
3127 #ifdef USE_MAPPED_LOCATION
3132 const char *gmsgid, va_list *ap)
3134 #ifdef USE_MAPPED_LOCATION
3135 source_location saved_location = input_location;
3136 expanded_location xloc = expand_location (cl);
3138 java_lc save_lc = ctxp->lexer->token_start;
3139 const char *saved = ctxp->filename, *saved_input_filename;
3144 text.err_no = errno;
3146 text.format_spec = gmsgid;
3147 pp_format (global_dc->printer, &text);
3148 pp_output_formatted_text (global_dc->printer);
3149 strncpy (buffer, pp_formatted_text (global_dc->printer), sizeof (buffer) - 1);
3150 buffer[sizeof (buffer) - 1] = '\0';
3151 pp_clear_output_area (global_dc->printer);
3155 #ifdef USE_MAPPED_LOCATION
3156 if (xloc.file != NULL)
3158 ctxp->filename = xloc.file;
3159 input_location = cl;
3162 ctxp->lexer->token_start.line = EXPR_WFL_LINENO (cl);
3163 ctxp->lexer->token_start.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1
3164 : EXPR_WFL_COLNO (cl) == 0xffe ? -2
3165 : EXPR_WFL_COLNO (cl));
3167 /* We have a CL, that's a good reason for using it if it contains data */
3168 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3169 ctxp->filename = EXPR_WFL_FILENAME (cl);
3170 saved_input_filename = input_filename;
3171 input_filename = ctxp->filename;
3174 java_error (buffer);
3175 #ifdef USE_MAPPED_LOCATION
3176 input_location = saved_location;
3178 ctxp->filename = saved;
3179 input_filename = saved_input_filename;
3180 ctxp->lexer->token_start = save_lc;
3185 /* Issue an error message at a current source line CL.
3186 FUTURE/FIXME: change cl to be a source_location. */
3189 parse_error_context (tree cl, const char *gmsgid, ...)
3192 va_start (ap, gmsgid);
3193 #ifdef USE_MAPPED_LOCATION
3194 issue_warning_error_from_context (EXPR_LOCATION (cl), gmsgid, &ap);
3196 issue_warning_error_from_context (cl, gmsgid, &ap);
3201 /* Issue a warning at a current source line CL.
3202 FUTURE/FIXME: change cl to be a source_location. */
3205 parse_warning_context (tree cl, const char *gmsgid, ...)
3208 va_start (ap, gmsgid);
3211 #ifdef USE_MAPPED_LOCATION
3212 issue_warning_error_from_context (EXPR_LOCATION (cl), gmsgid, &ap);
3214 issue_warning_error_from_context (cl, gmsgid, &ap);
3221 find_expr_with_wfl (tree node)
3225 enum tree_code_class code;
3228 switch (TREE_CODE (node))
3231 node = BLOCK_EXPR_BODY (node);
3235 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3238 node = TREE_OPERAND (node, 1);
3242 node = TREE_OPERAND (node, 0);
3245 case LABELED_BLOCK_EXPR:
3246 node = LABELED_BLOCK_BODY (node);
3250 code = TREE_CODE_CLASS (TREE_CODE (node));
3251 if (((code == tcc_unary) || (code == tcc_binary)
3252 || (code == tcc_expression))
3253 && EXPR_WFL_LINECOL (node))
3261 /* Issue a missing return statement error. Uses METHOD to figure the
3262 last line of the method the error occurs in. */
3265 missing_return_error (tree method)
3267 #ifdef USE_MAPPED_LOCATION
3268 SET_EXPR_LOCATION (wfl_operator, DECL_FUNCTION_LAST_LINE (method));
3270 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_FUNCTION_LAST_LINE (method), -2);
3272 parse_error_context (wfl_operator, "Missing return statement");
3275 /* Issue an unreachable statement error. From NODE, find the next
3276 statement to report appropriately. */
3278 unreachable_stmt_error (tree node)
3280 /* Browse node to find the next expression node that has a WFL. Use
3281 the location to report the error */
3282 if (TREE_CODE (node) == COMPOUND_EXPR)
3283 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3285 node = find_expr_with_wfl (node);
3289 #ifdef USE_MAPPED_LOCATION
3290 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
3292 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3294 parse_error_context (wfl_operator, "Unreachable statement");
3301 not_accessible_field_error (tree wfl, tree decl)
3304 (wfl, "Can't access %s field %<%s.%s%> from %qs",
3305 accessibility_string (get_access_flags_from_decl (decl)),
3306 GET_TYPE_NAME (DECL_CONTEXT (decl)),
3307 IDENTIFIER_POINTER (DECL_NAME (decl)),
3308 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
3313 java_report_errors (void)
3315 if (java_error_count)
3316 fprintf (stderr, "%d error%s",
3317 java_error_count, (java_error_count == 1 ? "" : "s"));
3318 if (java_warning_count)
3319 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3320 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3321 if (java_error_count || java_warning_count)
3322 putc ('\n', stderr);
3323 return java_error_count;
3327 java_accstring_lookup (int flags)
3329 static char buffer [80];
3330 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3332 /* Access modifier looked-up first for easier report on forbidden
3334 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3335 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3336 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3337 if (flags & ACC_STATIC) COPY_RETURN ("static");
3338 if (flags & ACC_FINAL) COPY_RETURN ("final");
3339 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3340 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3341 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3342 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3343 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3344 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3351 /* Returns a string denoting the accessibility of a class or a member as
3352 indicated by FLAGS. We need a separate function from
3353 java_accstring_lookup, as the latter can return spurious "static", etc.
3354 if package-private access is defined (in which case none of the
3355 relevant access control bits in FLAGS is set). */
3358 accessibility_string (int flags)
3360 if (flags & ACC_PRIVATE) return "private";
3361 if (flags & ACC_PROTECTED) return "protected";
3362 if (flags & ACC_PUBLIC) return "public";
3364 return "package-private";
3367 /* Issuing error messages upon redefinition of classes, interfaces or
3371 classitf_redefinition_error (const char *context, tree id, tree decl, tree cl)
3373 parse_error_context (cl, "%s %qs already defined in %s:%d",
3374 context, IDENTIFIER_POINTER (id),
3375 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3376 /* Here we should point out where its redefined. It's a unicode. FIXME */
3380 variable_redefinition_error (tree context, tree name, tree type, int line)
3382 const char *type_name;
3384 /* Figure a proper name for type. We might haven't resolved it */
3385 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3386 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3388 type_name = lang_printable_name (type, 0);
3390 parse_error_context (context,
3391 "Variable %qs is already defined in this method and was declared %<%s %s%> at line %d",
3392 IDENTIFIER_POINTER (name),
3393 type_name, IDENTIFIER_POINTER (name), line);
3396 /* If ANAME is terminated with `[]', it indicates an array. This
3397 function returns the number of `[]' found and if this number is
3398 greater than zero, it extracts the array type name and places it in
3399 the node pointed to by TRIMMED unless TRIMMED is null. */
3402 build_type_name_from_array_name (tree aname, tree *trimmed)
3404 const char *name = IDENTIFIER_POINTER (aname);
3405 int len = IDENTIFIER_LENGTH (aname);
3408 STRING_STRIP_BRACKETS (name, len, array_dims);
3410 if (array_dims && trimmed)
3411 *trimmed = get_identifier_with_length (name, len);
3417 build_array_from_name (tree type, tree type_wfl, tree name, tree *ret_name)
3421 /* Eventually get more dims */
3422 more_dims = build_type_name_from_array_name (name, &name);
3424 /* If we have, then craft a new type for this variable */
3429 /* If we have a pointer, use its type */
3430 if (TREE_CODE (type) == POINTER_TYPE)
3431 type = TREE_TYPE (type);
3433 /* Building the first dimension of a primitive type uses this
3435 if (JPRIMITIVE_TYPE_P (type))
3437 type = build_java_array_type (type, -1);
3440 /* Otherwise, if we have a WFL for this type, use it (the type
3441 is already an array on an unresolved type, and we just keep
3442 on adding dimensions) */
3446 more_dims += build_type_name_from_array_name (TYPE_NAME (save),
3450 /* Add all the dimensions */
3452 type = build_unresolved_array_type (type);
3454 /* The type may have been incomplete in the first place */
3456 type = obtain_incomplete_type (type);
3464 /* Build something that the type identifier resolver will identify as
3465 being an array to an unresolved type. TYPE_WFL is a WFL on a
3469 build_unresolved_array_type (tree type_or_wfl)
3474 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3475 just create a array type */
3476 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3477 return build_java_array_type (type_or_wfl, -1);
3479 obstack_grow (&temporary_obstack,
3480 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3481 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3482 obstack_grow0 (&temporary_obstack, "[]", 2);
3483 ptr = obstack_finish (&temporary_obstack);
3484 #ifdef USE_MAPPED_LOCATION
3485 wfl = build_expr_wfl (get_identifier (ptr), EXPR_LOCATION (type_or_wfl));
3487 wfl = build_expr_wfl (get_identifier (ptr),
3488 EXPR_WFL_FILENAME (type_or_wfl),
3489 EXPR_WFL_LINENO (type_or_wfl),
3490 EXPR_WFL_COLNO (type_or_wfl));
3492 /* Re-install the existing qualifications so that the type can be
3493 resolved properly. */
3494 EXPR_WFL_QUALIFICATION (wfl) = EXPR_WFL_QUALIFICATION (type_or_wfl);
3499 parser_add_interface (tree class_decl, tree interface_decl, tree wfl)
3501 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3502 parse_error_context (wfl, "Interface %qs repeated",
3503 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3506 /* Bulk of common class/interface checks. Return 1 if an error was
3507 encountered. TAG is 0 for a class, 1 for an interface. */
3510 check_class_interface_creation (int is_interface, int flags, tree raw_name,
3511 tree qualified_name, tree decl, tree cl)
3514 int sca = 0; /* Static class allowed */
3515 int icaf = 0; /* Inner class allowed flags */
3516 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3519 fprintf (stderr, " %s%s %s",
3520 (CPC_INNER_P () ? "inner" : ""),
3521 (is_interface ? "interface" : "class"),
3522 IDENTIFIER_POINTER (qualified_name));
3524 /* Scope of an interface/class type name:
3525 - Can't be imported by a single type import
3526 - Can't already exists in the package */
3527 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3528 && (node = find_name_in_single_imports (raw_name))
3532 (cl, "%s name %qs clashes with imported type %qs",
3533 (is_interface ? "Interface" : "Class"),
3534 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
3537 if (decl && CLASS_COMPLETE_P (decl))
3539 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
3540 qualified_name, decl, cl);
3544 if (check_inner_class_redefinition (raw_name, cl))
3547 /* If public, file name should match class/interface name, except
3548 when dealing with an inner class */
3549 if (!CPC_INNER_P () && (flags & ACC_PUBLIC ))
3551 const char *fname = input_filename;
3554 for (f = fname + strlen (fname);
3555 f != fname && ! IS_DIR_SEPARATOR (*f);
3558 if (IS_DIR_SEPARATOR (*f))
3560 if (strncmp (IDENTIFIER_POINTER (raw_name),
3561 f , IDENTIFIER_LENGTH (raw_name)) ||
3562 f [IDENTIFIER_LENGTH (raw_name)] != '.')
3564 (cl, "Public %s %qs must be defined in a file called %<%s.java%>",
3565 (is_interface ? "interface" : "class"),
3566 IDENTIFIER_POINTER (qualified_name),
3567 IDENTIFIER_POINTER (raw_name));
3570 /* Static classes can be declared only in top level classes. Note:
3571 once static, a inner class is a top level class. */
3572 if (flags & ACC_STATIC)
3574 /* Catch the specific error of declaring an class inner class
3575 with no toplevel enclosing class. Prevent check_modifiers from
3576 complaining a second time */
3577 if (CPC_INNER_P () && !TOPLEVEL_CLASS_DECL_P (GET_CPC()))
3579 parse_error_context (cl, "Inner class %qs can't be static. Static classes can only occur in interfaces and top-level classes",
3580 IDENTIFIER_POINTER (qualified_name));
3583 /* Else, in the context of a top-level class declaration, let
3584 `check_modifiers' do its job, otherwise, give it a go */
3586 sca = (GET_CPC_LIST () ? ACC_STATIC : 0);
3589 /* Inner classes can be declared private or protected
3590 within their enclosing classes. */
3593 /* A class which is local to a block can't be public, private,
3594 protected or static. But it is created final, so allow this
3596 if (current_function_decl)
3597 icaf = sca = uaaf = ACC_FINAL;
3600 check_modifiers_consistency (flags);
3601 icaf = ACC_PROTECTED;
3602 if (! CLASS_INTERFACE (GET_CPC ()))
3603 icaf |= ACC_PRIVATE;
3610 uaaf = INTERFACE_INNER_MODIFIERS;
3612 uaaf = INTERFACE_MODIFIERS;
3614 check_modifiers ("Illegal modifier %qs for interface declaration",
3618 check_modifiers ((current_function_decl ?
3619 "Illegal modifier %qs for local class declaration" :
3620 "Illegal modifier %qs for class declaration"),
3621 flags, uaaf|sca|icaf);
3625 /* Construct a nested class name. If the final component starts with
3626 a digit, return true. Otherwise return false. */
3628 make_nested_class_name (tree cpc_list)
3635 make_nested_class_name (TREE_CHAIN (cpc_list));
3637 /* Pick the qualified name when dealing with the first upmost
3639 name = (TREE_CHAIN (cpc_list)
3640 ? TREE_PURPOSE (cpc_list) : DECL_NAME (TREE_VALUE (cpc_list)));
3641 obstack_grow (&temporary_obstack,
3642 IDENTIFIER_POINTER (name), IDENTIFIER_LENGTH (name));
3643 obstack_1grow (&temporary_obstack, '$');
3645 return ISDIGIT (IDENTIFIER_POINTER (name)[0]);
3648 /* Can't redefine a class already defined in an earlier scope. */
3651 check_inner_class_redefinition (tree raw_name, tree cl)
3655 for (scope_list = GET_CPC_LIST (); scope_list;
3656 scope_list = GET_NEXT_ENCLOSING_CPC (scope_list))
3657 if (raw_name == GET_CPC_UN_NODE (scope_list))
3660 (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",
3661 IDENTIFIER_POINTER (raw_name));
3667 /* Tries to find a decl for CLASS_TYPE within ENCLOSING. May return an
3668 invisible/non-accessible matching decl when an accessible one could not be
3669 found, in order to give a better error message when accessibility is
3673 resolve_inner_class (tree context, tree cl, tree enclosing, tree class_type)
3675 tree local_super = NULL_TREE;
3676 tree candidate = NULL_TREE;
3678 /* This hash table is used to register the classes we're going
3679 through when searching the current class as an inner class, in
3680 order to detect circular references. */
3681 htab_t circularity_hash = htab_create (20, htab_hash_pointer, htab_eq_pointer,
3688 *htab_find_slot (circularity_hash, enclosing, INSERT) = enclosing;
3690 if ((decl = find_as_inner_class (enclosing, class_type, cl)))
3692 if (inner_class_accessible (decl, context))
3698 if (candidate == NULL_TREE)
3702 /* Now go to the upper classes, bail out if necessary. We will
3703 analyze the returned SUPER and act accordingly (see
3704 do_resolve_class). */
3705 if (JPRIMITIVE_TYPE_P (TREE_TYPE (enclosing))
3706 || TREE_TYPE (enclosing) == void_type_node)
3708 parse_error_context (cl, "Qualifier must be a reference");
3709 enclosing = NULL_TREE;
3712 local_super = CLASSTYPE_SUPER (TREE_TYPE (enclosing));
3713 if (!local_super || local_super == object_type_node)
3716 if (TREE_CODE (local_super) == POINTER_TYPE)
3717 local_super = do_resolve_class (NULL, NULL, local_super, NULL, NULL);
3719 local_super = TYPE_NAME (local_super);
3721 /* We may not have checked for circular inheritance yet, so do so
3722 here to prevent an infinite loop. */
3723 if (htab_find (circularity_hash, local_super) != NULL)
3726 cl = lookup_cl (enclosing);
3729 (cl, "Cyclic inheritance involving %s",
3730 IDENTIFIER_POINTER (DECL_NAME (enclosing)));
3731 enclosing = NULL_TREE;
3734 enclosing = local_super;
3737 htab_delete (circularity_hash);
3739 /* We failed, but we might have found a matching class that wasn't
3740 accessible. Return that to get a better error message. */
3744 /* Within ENCLOSING, find a decl for NAME and return it. NAME can be
3748 find_as_inner_class (tree enclosing, tree name, tree cl)
3750 tree qual, to_return;
3754 name = TYPE_NAME (name);
3756 /* First search: within the scope of `enclosing', search for name */
3757 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3758 qual = EXPR_WFL_QUALIFICATION (cl);
3760 qual = build_tree_list (cl, NULL_TREE);
3762 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3764 if ((to_return = find_as_inner_class_do (qual, enclosing)))
3767 /* We're dealing with a qualified name. Try to resolve thing until
3768 we get something that is an enclosing class. */
3769 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3771 tree acc = NULL_TREE, decl = NULL_TREE, ptr;
3773 for (qual = EXPR_WFL_QUALIFICATION (cl); qual && !decl;
3774 qual = TREE_CHAIN (qual))
3776 acc = merge_qualified_name (acc,
3777 EXPR_WFL_NODE (TREE_PURPOSE (qual)));
3778 BUILD_PTR_FROM_NAME (ptr, acc);
3779 decl = do_resolve_class (NULL_TREE, NULL_TREE, ptr, NULL_TREE, cl);
3782 /* A NULL qual and a decl means that the search ended
3783 successfully?!? We have to do something then. FIXME */
3788 qual = EXPR_WFL_QUALIFICATION (cl);
3790 /* Otherwise, create a qual for the other part of the resolution. */
3792 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3794 return find_as_inner_class_do (qual, enclosing);
3797 /* We go inside the list of sub classes and try to find a way
3801 find_as_inner_class_do (tree qual, tree enclosing)
3806 for (; qual && enclosing; qual = TREE_CHAIN (qual))
3808 tree name_to_match = EXPR_WFL_NODE (TREE_PURPOSE (qual));
3809 tree next_enclosing = NULL_TREE;
3812 for (inner_list = DECL_INNER_CLASS_LIST (enclosing);
3813 inner_list; inner_list = TREE_CHAIN (inner_list))
3815 if (TREE_VALUE (inner_list) == name_to_match)
3817 next_enclosing = TREE_PURPOSE (inner_list);
3821 enclosing = next_enclosing;
3824 return (!qual && enclosing ? enclosing : NULL_TREE);
3828 link_nested_class_to_enclosing (void)
3830 if (GET_ENCLOSING_CPC ())
3832 tree enclosing = GET_ENCLOSING_CPC_CONTEXT ();
3833 DECL_INNER_CLASS_LIST (enclosing) =
3834 tree_cons (GET_CPC (), GET_CPC_UN (),
3835 DECL_INNER_CLASS_LIST (enclosing));
3840 maybe_make_nested_class_name (tree name)
3842 tree id = NULL_TREE;
3846 /* If we're in a function, we must append a number to create the
3847 nested class name. However, we don't do this if the class we
3848 are constructing is anonymous, because in that case we'll
3849 already have a number as the class name. */
3850 if (! make_nested_class_name (GET_CPC_LIST ())
3851 && current_function_decl != NULL_TREE
3852 && ! ISDIGIT (IDENTIFIER_POINTER (name)[0]))
3855 sprintf (buf, "%d", anonymous_class_counter);
3856 ++anonymous_class_counter;
3857 obstack_grow (&temporary_obstack, buf, strlen (buf));
3858 obstack_1grow (&temporary_obstack, '$');
3860 obstack_grow0 (&temporary_obstack,
3861 IDENTIFIER_POINTER (name),
3862 IDENTIFIER_LENGTH (name));
3863 id = get_identifier (obstack_finish (&temporary_obstack));
3865 QUALIFIED_P (id) = 1;
3870 /* If DECL is NULL, create and push a new DECL, record the current
3871 line CL and do other maintenance things. */
3874 maybe_create_class_interface_decl (tree decl, tree raw_name,
3875 tree qualified_name, tree cl)
3878 decl = push_class (make_class (), qualified_name);
3880 /* Take care of the file and line business */
3881 #ifdef USE_MAPPED_LOCATION
3882 DECL_SOURCE_LOCATION (decl) = EXPR_LOCATION (cl);
3884 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
3885 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
3887 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
3888 CLASS_PARSED_P (TREE_TYPE (decl)) = 1;
3889 #ifdef USE_MAPPED_LOCATION
3891 tree tmp = maybe_get_identifier (EXPR_FILENAME (cl));
3892 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3893 tmp && IS_A_COMMAND_LINE_FILENAME_P (tmp);
3896 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3897 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
3900 PUSH_CPC (decl, raw_name);
3901 DECL_CONTEXT (decl) = GET_ENCLOSING_CPC_CONTEXT ();
3903 /* Link the declaration to the already seen ones */
3904 TREE_CHAIN (decl) = ctxp->class_list;
3905 ctxp->class_list = decl;
3907 /* Create a new nodes in the global lists */
3908 gclass_list = tree_cons (NULL_TREE, decl, gclass_list);
3909 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
3911 /* Install a new dependency list element */
3912 create_jdep_list (ctxp);
3914 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
3915 IDENTIFIER_POINTER (qualified_name)));
3920 add_superinterfaces (tree decl, tree interface_list)
3923 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3924 takes care of ensuring that:
3925 - This is an accessible interface type,
3926 - Circularity detection.
3927 parser_add_interface is then called. If present but not defined,
3928 the check operation is delayed until the super interface gets
3930 for (node = interface_list; node; node = TREE_CHAIN (node))
3932 tree current = TREE_PURPOSE (node);
3933 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
3934 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
3936 if (!parser_check_super_interface (idecl, decl, current))
3937 parser_add_interface (decl, idecl, current);
3940 register_incomplete_type (JDEP_INTERFACE,
3941 current, decl, NULL_TREE);
3945 /* Create an interface in pass1 and return its decl. Return the
3946 interface's decl in pass 2. */
3949 create_interface (int flags, tree id, tree super)
3951 tree raw_name = EXPR_WFL_NODE (id);
3952 tree q_name = parser_qualified_classname (raw_name);
3953 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
3955 /* Certain syntax errors are making SUPER be like ID. Avoid this
3957 if (ctxp->class_err && id == super)
3960 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
3962 /* Basic checks: scope, redefinition, modifiers */
3963 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
3969 /* Suspend the current parsing context if we're parsing an inner
3973 java_parser_context_suspend ();
3974 /* Interface members are public. */
3975 if (CLASS_INTERFACE (GET_CPC ()))
3976 flags |= ACC_PUBLIC;
3979 /* Push a new context for (static) initialized upon declaration fields */
3980 java_parser_context_push_initialized_field ();
3982 /* Interface modifiers check
3983 - public/abstract allowed (already done at that point)
3984 - abstract is obsolete (comes first, it's a warning, or should be)
3985 - Can't use twice the same (checked in the modifier rule) */
3986 if ((flags & ACC_ABSTRACT) && flag_redundant)
3987 parse_warning_context
3988 (MODIFIER_WFL (ABSTRACT_TK),
3989 "Redundant use of %<abstract%> modifier. Interface %qs is implicitly abstract", IDENTIFIER_POINTER (raw_name));
3991 /* Create a new decl if DECL is NULL, otherwise fix it */
3992 decl = maybe_create_class_interface_decl (decl, raw_name, q_name, id);
3994 /* Interfaces are always abstract. */
3995 flags |= ACC_ABSTRACT;
3997 /* Inner interfaces are always static. */
3998 if (INNER_CLASS_DECL_P (decl))
3999 flags |= ACC_STATIC;
4001 /* Set super info and mark the class a complete */
4002 set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
4003 object_type_node, ctxp->interface_number);
4004 ctxp->interface_number = 0;
4005 CLASS_COMPLETE_P (decl) = 1;
4006 add_superinterfaces (decl, super);
4008 /* Eventually sets the @deprecated tag flag */
4009 CHECK_DEPRECATED (decl);
4014 /* Patch anonymous class CLASS, by either extending or implementing
4018 patch_anonymous_class (tree type_decl, tree class_decl, tree wfl)
4020 tree class = TREE_TYPE (class_decl);
4021 tree type = TREE_TYPE (type_decl);
4022 tree binfo = TYPE_BINFO (class);
4024 /* If it's an interface, implement it */
4025 if (CLASS_INTERFACE (type_decl))
4027 if (parser_check_super_interface (type_decl, class_decl, wfl))
4030 if (!VEC_space (tree, BINFO_BASE_BINFOS (binfo), 1))
4032 /* Extend the binfo - by reallocating and copying it. */
4037 new_binfo = make_tree_binfo ((BINFO_N_BASE_BINFOS (binfo) + 1) * 2);
4038 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
4039 BINFO_BASE_APPEND (new_binfo, base_binfo);
4040 CLASS_HAS_SUPER_FLAG (new_binfo) = CLASS_HAS_SUPER_FLAG (binfo);
4041 BINFO_VTABLE (new_binfo) = BINFO_VTABLE (binfo);
4042 TYPE_BINFO (class) = new_binfo;
4045 /* And add the interface */
4046 parser_add_interface (class_decl, type_decl, wfl);
4048 /* Otherwise, it's a type we want to extend */
4051 if (parser_check_super (type_decl, class_decl, wfl))
4053 BINFO_TYPE (BINFO_BASE_BINFO (binfo, 0)) = type;
4057 /* Create an anonymous class which extends/implements TYPE_NAME, and return
4061 create_anonymous_class (tree type_name)
4064 tree super = NULL_TREE, itf = NULL_TREE;
4065 tree id, type_decl, class;
4067 /* The unqualified name of the anonymous class. It's just a number. */
4068 sprintf (buffer, "%d", anonymous_class_counter++);
4069 id = build_wfl_node (get_identifier (buffer));
4070 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL (type_name);
4072 /* We know about the type to extend/implement. We go ahead */
4073 if ((type_decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (type_name))))
4075 /* Create a class which either implements on extends the designated
4076 class. The class bears an inaccessible name. */
4077 if (CLASS_INTERFACE (type_decl))
4079 /* It's OK to modify it here. It's been already used and
4080 shouldn't be reused */
4081 ctxp->interface_number = 1;
4082 /* Interfaces should presented as a list of WFLs */
4083 itf = build_tree_list (type_name, NULL_TREE);
4089 class = create_class (ACC_FINAL, id, super, itf);
4091 /* We didn't know anything about the stuff. We register a dependence. */
4093 register_incomplete_type (JDEP_ANONYMOUS, type_name, class, NULL_TREE);
4095 ANONYMOUS_CLASS_P (TREE_TYPE (class)) = 1;
4099 /* Create a class in pass1 and return its decl. Return class
4100 interface's decl in pass 2. */
4103 create_class (int flags, tree id, tree super, tree interfaces)
4105 tree raw_name = EXPR_WFL_NODE (id);
4106 tree class_id, decl;
4107 tree super_decl_type;
4109 /* Certain syntax errors are making SUPER be like ID. Avoid this
4111 if (ctxp->class_err && id == super)
4114 class_id = parser_qualified_classname (raw_name);
4115 decl = IDENTIFIER_CLASS_VALUE (class_id);
4116 EXPR_WFL_NODE (id) = class_id;
4118 /* Basic check: scope, redefinition, modifiers */
4119 if (check_class_interface_creation (0, flags, raw_name, class_id, decl, id))
4125 /* Suspend the current parsing context if we're parsing an inner
4126 class or an anonymous class. */
4129 java_parser_context_suspend ();
4130 /* Interface members are public. */
4131 if (CLASS_INTERFACE (GET_CPC ()))
4132 flags |= ACC_PUBLIC;
4135 /* Push a new context for (static) initialized upon declaration fields */
4136 java_parser_context_push_initialized_field ();
4138 /* Class modifier check:
4139 - Allowed modifier (already done at that point)
4140 - abstract AND final forbidden
4141 - Public classes defined in the correct file */
4142 if ((flags & ACC_ABSTRACT) && (flags & ACC_FINAL))
4144 (id, "Class %qs can't be declared both abstract and final",
4145 IDENTIFIER_POINTER (raw_name));
4147 /* Create a new decl if DECL is NULL, otherwise fix it */
4148 decl = maybe_create_class_interface_decl (decl, raw_name, class_id, id);
4150 /* If SUPER exists, use it, otherwise use Object */
4153 /* java.lang.Object can't extend anything. */
4154 if (TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_id)) == object_type_node)
4156 parse_error_context (id, "%<java.lang.Object%> can't extend anything");
4161 register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
4163 else if (TREE_TYPE (decl) != object_type_node)
4164 super_decl_type = object_type_node;
4165 /* We're defining java.lang.Object */
4167 super_decl_type = NULL_TREE;
4169 /* A class nested in an interface is implicitly static. */
4170 if (INNER_CLASS_DECL_P (decl)
4171 && CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (DECL_CONTEXT (decl)))))
4173 flags |= ACC_STATIC;
4176 /* Set super info and mark the class as complete. */
4177 set_super_info (flags, TREE_TYPE (decl), super_decl_type,
4178 ctxp->interface_number);
4179 ctxp->interface_number = 0;
4180 CLASS_COMPLETE_P (decl) = 1;
4181 add_superinterfaces (decl, interfaces);
4183 /* TYPE_VFIELD' is a compiler-generated field used to point to
4184 virtual function tables. In gcj, every class has a common base
4185 virtual function table in java.lang.object. */
4186 TYPE_VFIELD (TREE_TYPE (decl)) = TYPE_VFIELD (object_type_node);
4188 /* We keep the compilation unit imports in the class so that
4189 they can be used later to resolve type dependencies that
4190 aren't necessary to solve now. */
4191 TYPE_IMPORT_LIST (TREE_TYPE (decl)) = ctxp->import_list;
4192 TYPE_IMPORT_DEMAND_LIST (TREE_TYPE (decl)) = ctxp->import_demand_list;
4194 /* Add the private this$<n> field, Replicate final locals still in
4195 scope as private final fields mangled like val$<local_name>.
4196 This does not occur for top level (static) inner classes. */
4197 if (PURE_INNER_CLASS_DECL_P (decl))
4198 add_inner_class_fields (decl, current_function_decl);
4200 /* Eventually sets the @deprecated tag flag */
4201 CHECK_DEPRECATED (decl);
4203 /* Reset the anonymous class counter when declaring non inner classes */
4204 if (!INNER_CLASS_DECL_P (decl))
4205 anonymous_class_counter = 1;
4210 /* End a class declaration: register the statements used to create
4211 finit$ and <clinit>, pop the current class and resume the prior
4212 parser context if necessary. */
4215 end_class_declaration (int resume)
4217 /* If an error occurred, context weren't pushed and won't need to be
4218 popped by a resume. */
4219 int no_error_occurred = ctxp->next && GET_CPC () != error_mark_node;
4221 if (GET_CPC () != error_mark_node)
4222 dump_java_tree (TDI_class, GET_CPC ());
4224 java_parser_context_pop_initialized_field ();
4226 if (resume && no_error_occurred)
4227 java_parser_context_resume ();
4229 /* We're ending a class declaration, this is a good time to reset
4230 the interface cout. Note that might have been already done in
4231 create_interface, but if at that time an inner class was being
4232 dealt with, the interface count was reset in a context created
4233 for the sake of handling inner classes declaration. */
4234 ctxp->interface_number = 0;
4238 add_inner_class_fields (tree class_decl, tree fct_decl)
4240 tree block, marker, f;
4242 f = add_field (TREE_TYPE (class_decl),
4243 build_current_thisn (TREE_TYPE (class_decl)),
4244 build_pointer_type (TREE_TYPE (DECL_CONTEXT (class_decl))),
4246 FIELD_THISN (f) = 1;
4251 for (block = GET_CURRENT_BLOCK (fct_decl);
4252 block && TREE_CODE (block) == BLOCK; block = BLOCK_SUPERCONTEXT (block))
4255 for (decl = BLOCK_EXPR_DECLS (block); decl; decl = TREE_CHAIN (decl))
4258 tree wfl, init, list;
4260 /* Avoid non final arguments. */
4261 if (!LOCAL_FINAL_P (decl))
4264 MANGLE_OUTER_LOCAL_VARIABLE_NAME (name, DECL_NAME (decl));
4265 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID (pname, DECL_NAME (decl));
4266 wfl = build_wfl_node (name);
4267 init = build_wfl_node (pname);
4268 /* Build an initialization for the field: it will be
4269 initialized by a parameter added to finit$, bearing a
4270 mangled name of the field itself (param$<n>.) The
4271 parameter is provided to finit$ by the constructor
4272 invoking it (hence the constructor will also feature a
4273 hidden parameter, set to the value of the outer context
4274 local at the time the inner class is created.)
4276 Note: we take into account all possible locals that can
4277 be accessed by the inner class. It's actually not trivial
4278 to minimize these aliases down to the ones really
4279 used. One way to do that would be to expand all regular
4280 methods first, then finit$ to get a picture of what's
4281 used. It works with the exception that we would have to
4282 go back on all constructor invoked in regular methods to
4283 have their invocation reworked (to include the right amount
4284 of alias initializer parameters.)
4286 The only real way around, I think, is a first pass to
4287 identify locals really used in the inner class. We leave
4288 the flag FIELD_LOCAL_ALIAS_USED around for that future
4291 On the other hand, it only affect local inner classes,
4292 whose constructors (and finit$ call) will be featuring
4293 unnecessary arguments. It's easy for a developer to keep
4294 this number of parameter down by using the `final'
4295 keyword only when necessary. For the time being, we can
4296 issue a warning on unnecessary finals. FIXME */
4297 init = build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (wfl),
4300 /* Register the field. The TREE_LIST holding the part
4301 initialized/initializer will be marked ARG_FINAL_P so
4302 that the created field can be marked
4303 FIELD_LOCAL_ALIAS. */
4304 list = build_tree_list (wfl, init);
4305 ARG_FINAL_P (list) = 1;
4306 register_fields (ACC_PRIVATE | ACC_FINAL, TREE_TYPE (decl), list);
4310 if (!CPC_INITIALIZER_STMT (ctxp))
4313 /* If we ever registered an alias field, insert and marker to
4314 remember where the list ends. The second part of the list (the one
4315 featuring initialized fields) so it can be later reversed to
4316 enforce 8.5. The marker will be removed during that operation. */
4317 marker = build_tree_list (NULL_TREE, NULL_TREE);
4318 TREE_CHAIN (marker) = CPC_INITIALIZER_STMT (ctxp);
4319 SET_CPC_INITIALIZER_STMT (ctxp, marker);
4322 /* Can't use lookup_field () since we don't want to load the class and
4323 can't set the CLASS_LOADED_P flag */
4326 find_field (tree class, tree name)
4329 for (decl = TYPE_FIELDS (class); decl; decl = TREE_CHAIN (decl))
4331 if (DECL_NAME (decl) == name)
4337 /* Wrap around lookup_field that doesn't potentially upset the value
4341 lookup_field_wrapper (tree class, tree name)
4344 tree decl = NULL_TREE;
4345 java_parser_context_save_global ();
4347 /* Last chance: if we're within the context of an inner class, we
4348 might be trying to access a local variable defined in an outer
4349 context. We try to look for it now. */
4350 if (INNER_CLASS_TYPE_P (class) && TREE_CODE (name) == IDENTIFIER_NODE)
4353 MANGLE_OUTER_LOCAL_VARIABLE_NAME (new_name, name);
4354 decl = lookup_field (&type, new_name);
4355 if (decl && decl != error_mark_node)
4356 FIELD_LOCAL_ALIAS_USED (decl) = 1;
4358 if (!decl || decl == error_mark_node)
4361 decl = lookup_field (&type, name);
4364 /* If the field still hasn't been found, try the next enclosing context. */
4365 if (!decl && INNER_CLASS_TYPE_P (class))
4367 tree outer_type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class)));
4368 decl = lookup_field_wrapper (outer_type, name);
4371 java_parser_context_restore_global ();
4372 return decl == error_mark_node ? NULL : decl;
4375 /* Find duplicate field within the same class declarations and report
4376 the error. Returns 1 if a duplicated field was found, 0
4380 duplicate_declaration_error_p (tree new_field_name, tree new_type, tree cl)
4382 /* This might be modified to work with method decl as well */
4383 tree decl = find_field (TREE_TYPE (GET_CPC ()), new_field_name);
4386 char *t1 = xstrdup (purify_type_name
4387 ((TREE_CODE (new_type) == POINTER_TYPE
4388 && TREE_TYPE (new_type) == NULL_TREE) ?
4389 IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
4390 lang_printable_name (new_type, 1)));
4391 /* The type may not have been completed by the time we report
4393 char *t2 = xstrdup (purify_type_name
4394 ((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
4395 && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
4396 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
4397 lang_printable_name (TREE_TYPE (decl), 1)));
4399 (cl, "Duplicate variable declaration: %<%s %s%> was %<%s %s%> (%s:%d)",
4400 t1, IDENTIFIER_POINTER (new_field_name),
4401 t2, IDENTIFIER_POINTER (DECL_NAME (decl)),
4402 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
4410 /* Field registration routine. If TYPE doesn't exist, field
4411 declarations are linked to the undefined TYPE dependency list, to
4412 be later resolved in java_complete_class () */
4415 register_fields (int flags, tree type, tree variable_list)
4417 tree current, saved_type;
4418 tree class_type = NULL_TREE;
4419 location_t saved_location = input_location;
4421 tree wfl = NULL_TREE;
4424 class_type = TREE_TYPE (GET_CPC ());
4426 if (!class_type || class_type == error_mark_node)
4429 /* If we're adding fields to interfaces, those fields are public,
4431 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
4433 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK),
4434 flags, ACC_PUBLIC, "interface field(s)");
4435 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (STATIC_TK),
4436 flags, ACC_STATIC, "interface field(s)");
4437 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (FINAL_TK),
4438 flags, ACC_FINAL, "interface field(s)");
4439 check_modifiers ("Illegal interface member modifier %qs", flags,
4440 INTERFACE_FIELD_MODIFIERS);
4441 flags |= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
4444 /* Obtain a suitable type for resolution, if necessary */
4445 SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
4447 /* If TYPE is fully resolved and we don't have a reference, make one */
4448 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4450 for (current = variable_list, saved_type = type; current;
4451 current = TREE_CHAIN (current), type = saved_type)
4455 tree cl = TREE_PURPOSE (current);
4456 tree init = TREE_VALUE (current);
4457 tree current_name = EXPR_WFL_NODE (cl);
4459 /* Can't declare non-final static fields in inner classes */
4460 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (class_type)
4461 && !(flags & ACC_FINAL))
4463 (cl, "Field %qs can't be static in inner class %qs unless it is final",
4464 IDENTIFIER_POINTER (EXPR_WFL_NODE (cl)),
4465 lang_printable_name (class_type, 0));
4467 /* Process NAME, as it may specify extra dimension(s) for it */
4468 type = build_array_from_name (type, wfl, current_name, ¤t_name);
4470 /* Type adjustment. We may have just readjusted TYPE because
4471 the variable specified more dimensions. Make sure we have
4472 a reference if we can and don't have one already. Also
4473 change the name if we have an init. */
4474 if (type != saved_type)
4476 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4478 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
4481 real_type = GET_REAL_TYPE (type);
4482 /* Check for redeclarations */
4483 if (duplicate_declaration_error_p (current_name, real_type, cl))
4486 /* Set input_line to the line the field was found and create a
4487 declaration for it. Eventually sets the @deprecated tag flag. */
4488 #ifdef USE_MAPPED_LOCATION
4489 input_location = EXPR_LOCATION (cl);
4491 input_line = EXPR_WFL_LINENO (cl);
4493 field_decl = add_field (class_type, current_name, real_type, flags);
4494 CHECK_DEPRECATED_NO_RESET (field_decl);
4496 /* If the field denotes a final instance variable, then we
4497 allocate a LANG_DECL_SPECIFIC part to keep track of its
4498 initialization. We also mark whether the field was
4499 initialized upon its declaration. We don't do that if the
4500 created field is an alias to a final local. */
4501 if (!ARG_FINAL_P (current) && (flags & ACC_FINAL))
4503 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (field_decl);
4504 DECL_FIELD_FINAL_WFL (field_decl) = cl;
4507 /* If the couple initializer/initialized is marked ARG_FINAL_P,
4508 we mark the created field FIELD_LOCAL_ALIAS, so that we can
4509 hide parameters to this inner class finit$ and
4510 constructors. It also means that the field isn't final per
4512 if (ARG_FINAL_P (current))
4514 FIELD_LOCAL_ALIAS (field_decl) = 1;
4515 FIELD_FINAL (field_decl) = 0;
4518 /* Check if we must chain. */
4520 register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
4522 /* If we have an initialization value tied to the field */
4525 /* The field is declared static */
4526 if (flags & ACC_STATIC)
4528 /* We include the field and its initialization part into
4529 a list used to generate <clinit>. After <clinit> is
4530 walked, field initializations will be processed and
4531 fields initialized with known constants will be taken
4532 out of <clinit> and have their DECL_INITIAL set
4534 TREE_CHAIN (init) = CPC_STATIC_INITIALIZER_STMT (ctxp);
4535 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, init);
4536 if (TREE_OPERAND (init, 1)
4537 && TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
4538 TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
4540 /* A non-static field declared with an immediate initialization is
4541 to be initialized in <init>, if any. This field is remembered
4542 to be processed at the time of the generation of <init>. */
4545 TREE_CHAIN (init) = CPC_INITIALIZER_STMT (ctxp);
4546 SET_CPC_INITIALIZER_STMT (ctxp, init);
4548 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
4549 DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
4554 input_location = saved_location;
4557 /* Generate finit$, using the list of initialized fields to populate
4558 its body. finit$'s parameter(s) list is adjusted to include the
4559 one(s) used to initialized the field(s) caching outer context
4563 generate_finit (tree class_type)
4566 tree list = TYPE_FINIT_STMT_LIST (class_type);
4567 tree mdecl, current, parms;
4569 parms = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
4570 class_type, NULL_TREE,
4572 CRAFTED_PARAM_LIST_FIXUP (parms);
4573 mdecl = create_artificial_method (class_type, ACC_PRIVATE, void_type_node,
4574 finit_identifier_node, parms);
4575 fix_method_argument_names (parms, mdecl);
4576 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4578 DECL_FUNCTION_NAP (mdecl) = count;
4579 start_artificial_method_body (mdecl);
4581 for (current = list; current; current = TREE_CHAIN (current))
4582 java_method_add_stmt (mdecl,
4583 build_debugable_stmt (EXPR_WFL_LINECOL (current),
4585 end_artificial_method_body (mdecl);
4589 /* Generate a function to run the instance initialization code. The
4590 private method is called `instinit$'. Unless we're dealing with an
4591 anonymous class, we determine whether all ctors of CLASS_TYPE
4592 declare a checked exception in their `throws' clause in order to
4593 see whether it's necessary to encapsulate the instance initializer
4594 statements in a try/catch/rethrow sequence. */
4597 generate_instinit (tree class_type)
4600 tree compound = NULL_TREE;
4601 tree parms = tree_cons (this_identifier_node,
4602 build_pointer_type (class_type), end_params_node);
4603 tree mdecl = create_artificial_method (class_type, ACC_PRIVATE,
4605 instinit_identifier_node, parms);
4607 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4610 /* Gather all the statements in a compound */
4611 for (current = TYPE_II_STMT_LIST (class_type);
4612 current; current = TREE_CHAIN (current))
4613 compound = add_stmt_to_compound (compound, NULL_TREE, current);
4615 /* We need to encapsulate COMPOUND by a try/catch statement to
4616 rethrow exceptions that might occur in the instance initializer.
4617 We do that only if all ctors of CLASS_TYPE are set to catch a
4618 checked exception. This doesn't apply to anonymous classes (since
4619 they don't have declared ctors.) */
4620 if (!ANONYMOUS_CLASS_P (class_type) &&
4621 ctors_unchecked_throws_clause_p (class_type))
4623 compound = encapsulate_with_try_catch (0, exception_type_node, compound,
4624 build1 (THROW_EXPR, NULL_TREE,
4625 build_wfl_node (wpv_id)));
4626 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (NULL_TREE,
4627 exception_type_node);
4630 start_artificial_method_body (mdecl);
4631 java_method_add_stmt (mdecl, compound);
4632 end_artificial_method_body (mdecl);
4639 build_instinit_invocation (tree class_type)
4641 tree to_return = NULL_TREE;
4643 if (TYPE_II_STMT_LIST (class_type))
4645 tree parm = build_tree_list (NULL_TREE,
4646 build_wfl_node (this_identifier_node));
4648 build_method_invocation (build_wfl_node (instinit_identifier_node),
4654 /* Shared across method_declarator and method_header to remember the
4655 patch stage that was reached during the declaration of the method.
4656 A method DECL is built differently is there is no patch
4657 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
4658 pending on the currently defined method. */
4660 static int patch_stage;
4662 /* Check the method declaration and add the method to its current
4663 class. If the argument list is known to contain incomplete types,
4664 the method is partially added and the registration will be resume
4665 once the method arguments resolved. If TYPE is NULL, we're dealing
4666 with a constructor. */
4669 method_header (int flags, tree type, tree mdecl, tree throws)
4671 tree type_wfl = NULL_TREE;
4672 tree meth_name = NULL_TREE;
4673 tree current, orig_arg, this_class = NULL;
4675 location_t saved_location;
4676 int constructor_ok = 0, must_chain;
4679 if (mdecl == error_mark_node)
4680 return error_mark_node;
4681 meth = TREE_VALUE (mdecl);
4682 id = TREE_PURPOSE (mdecl);
4684 check_modifiers_consistency (flags);
4687 this_class = TREE_TYPE (GET_CPC ());
4689 if (!this_class || this_class == error_mark_node)
4692 /* There are some forbidden modifiers for an abstract method and its
4693 class must be abstract as well. */
4694 if (type && (flags & ACC_ABSTRACT))
4696 ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
4697 ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
4698 ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
4699 ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
4700 ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED, id, "Synchronized");
4701 ABSTRACT_CHECK (flags, ACC_STRICT, id, "Strictfp");
4702 if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
4703 && !CLASS_INTERFACE (TYPE_NAME (this_class)))
4706 "Class %qs must be declared abstract to define abstract method %qs",
4707 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())),
4708 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4711 /* A native method can't be strictfp. */
4712 if ((flags & ACC_NATIVE) && (flags & ACC_STRICT))
4713 parse_error_context (id, "native method %qs can't be strictfp",
4714 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4715 /* No such thing as a transient or volatile method. */
4716 if ((flags & ACC_TRANSIENT))
4717 parse_error_context (id, "method %qs can't be transient",
4718 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4719 if ((flags & ACC_VOLATILE))
4720 parse_error_context (id, "method %qs can't be volatile",
4721 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4723 /* Things to be checked when declaring a constructor */
4726 int ec = java_error_count;
4727 /* 8.6: Constructor declarations: we might be trying to define a
4728 method without specifying a return type. */
4729 if (EXPR_WFL_NODE (id) != GET_CPC_UN ())
4731 (id, "Invalid method declaration, return type required");
4732 /* 8.6.3: Constructor modifiers */
4735 JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
4736 JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
4737 JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
4738 JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
4739 JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
4740 JCONSTRUCTOR_CHECK (flags, ACC_STRICT, id, "strictfp");
4742 /* If we found error here, we don't consider it's OK to tread
4743 the method definition as a constructor, for the rest of this
4745 if (ec == java_error_count)
4749 /* Method declared within the scope of an interface are implicitly
4750 abstract and public. Conflicts with other erroneously provided
4751 modifiers are checked right after. */
4753 if (CLASS_INTERFACE (TYPE_NAME (this_class)))
4755 /* If FLAGS isn't set because of a modifier, turn the
4756 corresponding modifier WFL to NULL so we issue a warning on
4757 the obsolete use of the modifier */
4758 if (!(flags & ACC_PUBLIC))
4759 MODIFIER_WFL (PUBLIC_TK) = NULL;
4760 if (!(flags & ACC_ABSTRACT))
4761 MODIFIER_WFL (ABSTRACT_TK) = NULL;
4762 flags |= ACC_PUBLIC;
4763 flags |= ACC_ABSTRACT;
4766 /* Inner class can't declare static methods */
4767 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (this_class))
4770 (id, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
4771 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)),
4772 lang_printable_name (this_class, 0));
4775 /* Modifiers context reset moved up, so abstract method declaration
4776 modifiers can be later checked. */
4778 /* Set constructor returned type to void and method name to <init>,
4779 unless we found an error identifier the constructor (in which
4780 case we retain the original name) */
4783 type = void_type_node;
4785 meth_name = init_identifier_node;
4788 meth_name = EXPR_WFL_NODE (id);
4790 /* Do the returned type resolution and registration if necessary */
4791 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
4794 type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
4795 EXPR_WFL_NODE (id) = meth_name;
4796 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4800 patch_stage = JDEP_METHOD_RETURN;
4801 register_incomplete_type (patch_stage, type_wfl, id, type);
4802 TREE_TYPE (meth) = GET_REAL_TYPE (type);
4805 TREE_TYPE (meth) = type;
4807 saved_location = input_location;
4808 /* When defining an abstract or interface method, the curly
4809 bracket at level 1 doesn't exist because there is no function
4811 #ifdef USE_MAPPED_LOCATION
4812 input_location = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 :
4813 EXPR_LOCATION (id));
4815 input_line = (ctxp->first_ccb_indent1 ? (int) ctxp->first_ccb_indent1 :
4816 EXPR_WFL_LINENO (id));
4819 /* Remember the original argument list */
4820 orig_arg = TYPE_ARG_TYPES (meth);
4822 if (patch_stage) /* includes ret type and/or all args */
4825 meth = add_method_1 (this_class, flags, meth_name, meth);
4826 /* Patch for the return type */
4827 if (patch_stage == JDEP_METHOD_RETURN)
4829 jdep = CLASSD_LAST (ctxp->classd_list);
4830 JDEP_GET_PATCH (jdep) = &TREE_TYPE (TREE_TYPE (meth));
4832 /* This is the stop JDEP. METH allows the function's signature
4834 register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
4837 meth = add_method (this_class, flags, meth_name,
4838 build_java_signature (meth));
4840 /* Remember final parameters */
4841 MARK_FINAL_PARMS (meth, orig_arg);
4843 /* Fix the method argument list so we have the argument name
4845 fix_method_argument_names (orig_arg, meth);
4847 /* Register the parameter number and re-install the current line
4849 DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
4850 input_location = saved_location;
4852 /* Register exception specified by the `throws' keyword for
4853 resolution and set the method decl appropriate field to the list.
4854 Note: the grammar ensures that what we get here are class
4858 throws = nreverse (throws);
4859 for (current = throws; current; current = TREE_CHAIN (current))
4861 register_incomplete_type (JDEP_EXCEPTION, TREE_VALUE (current),
4862 NULL_TREE, NULL_TREE);
4863 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
4864 &TREE_VALUE (current);
4866 DECL_FUNCTION_THROWS (meth) = throws;
4869 if (TREE_TYPE (GET_CPC ()) != object_type_node)
4870 DECL_FUNCTION_WFL (meth) = id;
4872 /* Set the flag if we correctly processed a constructor */
4875 DECL_CONSTRUCTOR_P (meth) = 1;
4876 /* Compute and store the number of artificial parameters declared
4877 for this constructor */
4878 for (count = 0, current = TYPE_FIELDS (this_class); current;
4879 current = TREE_CHAIN (current))
4880 if (FIELD_LOCAL_ALIAS (current))
4882 DECL_FUNCTION_NAP (meth) = count;
4885 /* Eventually set the @deprecated tag flag */
4886 CHECK_DEPRECATED (meth);
4892 fix_method_argument_names (tree orig_arg, tree meth)
4894 tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
4895 if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
4897 TREE_PURPOSE (arg) = this_identifier_node;
4898 arg = TREE_CHAIN (arg);
4900 while (orig_arg != end_params_node)
4902 TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
4903 orig_arg = TREE_CHAIN (orig_arg);
4904 arg = TREE_CHAIN (arg);
4908 /* Complete the method declaration with METHOD_BODY. */
4911 finish_method_declaration (tree method_body)
4915 if (!current_function_decl)
4918 flags = get_access_flags_from_decl (current_function_decl);
4920 /* 8.4.5 Method Body */
4921 if ((flags & ACC_ABSTRACT || flags & ACC_NATIVE) && method_body)
4923 tree name = DECL_NAME (current_function_decl);
4924 parse_error_context (DECL_FUNCTION_WFL (current_function_decl),
4925 "%s method %qs can't have a body defined",
4926 (METHOD_NATIVE (current_function_decl) ?
4927 "Native" : "Abstract"),
4928 IDENTIFIER_POINTER (name));
4929 method_body = NULL_TREE;
4931 else if (!(flags & ACC_ABSTRACT) && !(flags & ACC_NATIVE) && !method_body)
4933 tree name = DECL_NAME (current_function_decl);
4935 (DECL_FUNCTION_WFL (current_function_decl),
4936 "Non native and non abstract method %qs must have a body defined",
4937 IDENTIFIER_POINTER (name));
4938 method_body = NULL_TREE;
4941 if (flag_emit_class_files && method_body
4942 && TREE_CODE (method_body) == NOP_EXPR
4943 && TREE_TYPE (current_function_decl)
4944 && TREE_TYPE (TREE_TYPE (current_function_decl)) == void_type_node)
4945 method_body = build1 (RETURN_EXPR, void_type_node, NULL);
4947 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
4948 maybe_absorb_scoping_blocks ();
4949 /* Exit function's body */
4951 /* Merge last line of the function with first line, directly in the
4952 function decl. It will be used to emit correct debug info. */
4953 DECL_FUNCTION_LAST_LINE (current_function_decl) = ctxp->last_ccb_indent1;
4955 /* Since function's argument's list are shared, reset the
4956 ARG_FINAL_P parameter that might have been set on some of this
4957 function parameters. */
4958 UNMARK_FINAL_PARMS (current_function_decl);
4960 /* So we don't have an irrelevant function declaration context for
4961 the next static block we'll see. */
4962 current_function_decl = NULL_TREE;
4965 /* Build a an error message for constructor circularity errors. */
4968 constructor_circularity_msg (tree from, tree to)
4970 static char string [4096];
4971 char *t = xstrdup (lang_printable_name (from, 2));
4972 sprintf (string, "'%s' invokes '%s'", t, lang_printable_name (to, 2));
4977 /* Verify a circular call to METH. Return 1 if an error is found, 0
4980 static GTY(()) tree vcc_list;
4982 verify_constructor_circularity (tree meth, tree current)
4986 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
4988 if (TREE_VALUE (c) == meth)
4994 vcc_list = nreverse (vcc_list);
4995 for (liste = vcc_list; liste; liste = TREE_CHAIN (liste))
4998 (TREE_PURPOSE (TREE_PURPOSE (liste)), "%s",
4999 constructor_circularity_msg
5000 (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste))));
5004 t = xstrdup (lang_printable_name (meth, 2));
5005 parse_error_context (TREE_PURPOSE (c),
5006 "%s: recursive invocation of constructor %qs",
5007 constructor_circularity_msg (current, meth), t);
5009 vcc_list = NULL_TREE;
5013 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
5015 vcc_list = tree_cons (c, current, vcc_list);
5016 if (verify_constructor_circularity (meth, TREE_VALUE (c)))
5018 vcc_list = TREE_CHAIN (vcc_list);
5023 /* Check modifiers that can be declared but exclusively */
5026 check_modifiers_consistency (int flags)
5029 tree cl = NULL_TREE;
5031 THIS_MODIFIER_ONLY (flags, ACC_PUBLIC, PUBLIC_TK, acc_count, cl);
5032 THIS_MODIFIER_ONLY (flags, ACC_PRIVATE, PRIVATE_TK, acc_count, cl);
5033 THIS_MODIFIER_ONLY (flags, ACC_PROTECTED, PROTECTED_TK, acc_count, cl);
5036 (cl, "Inconsistent member declaration. At most one of %<public%>, %<private%>, or %<protected%> may be specified");
5040 THIS_MODIFIER_ONLY (flags, ACC_FINAL, FINAL_TK, acc_count, cl);
5041 THIS_MODIFIER_ONLY (flags, ACC_VOLATILE, VOLATILE_TK, acc_count, cl);
5043 parse_error_context (cl,
5044 "Inconsistent member declaration. At most one of %<final%> or %<volatile%> may be specified");
5047 /* Check the methode header METH for abstract specifics features */
5050 check_abstract_method_header (tree meth)
5052 int flags = get_access_flags_from_decl (meth);
5054 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (ABSTRACT_TK), flags,
5055 ACC_ABSTRACT, "abstract method",
5056 IDENTIFIER_POINTER (DECL_NAME (meth)));
5057 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (PUBLIC_TK), flags,
5058 ACC_PUBLIC, "abstract method",
5059 IDENTIFIER_POINTER (DECL_NAME (meth)));
5061 check_modifiers ("Illegal modifier %qs for interface method",
5062 flags, INTERFACE_METHOD_MODIFIERS);
5065 /* Create a FUNCTION_TYPE node and start augmenting it with the
5066 declared function arguments. Arguments type that can't be resolved
5067 are left as they are, but the returned node is marked as containing
5068 incomplete types. */
5071 method_declarator (tree id, tree list)
5073 tree arg_types = NULL_TREE, current, node;
5074 tree meth = make_node (FUNCTION_TYPE);
5077 patch_stage = JDEP_NO_PATCH;
5079 if (GET_CPC () == error_mark_node)
5080 return error_mark_node;
5082 /* If we're dealing with an inner class constructor, we hide the
5083 this$<n> decl in the name field of its parameter declaration. We
5084 also might have to hide the outer context local alias
5085 initializers. Not done when the class is a toplevel class. */
5086 if (PURE_INNER_CLASS_DECL_P (GET_CPC ())
5087 && EXPR_WFL_NODE (id) == GET_CPC_UN ())
5089 tree aliases_list, type, thisn;
5090 /* First the aliases, linked to the regular parameters */
5092 build_alias_initializer_parameter_list (AIPL_FUNCTION_DECLARATION,
5093 TREE_TYPE (GET_CPC ()),
5095 list = chainon (nreverse (aliases_list), list);
5098 type = TREE_TYPE (DECL_CONTEXT (GET_CPC ()));
5099 thisn = build_current_thisn (TREE_TYPE (GET_CPC ()));
5100 list = tree_cons (build_wfl_node (thisn), build_pointer_type (type),
5104 for (current = list; current; current = TREE_CHAIN (current))
5107 tree wfl_name = TREE_PURPOSE (current);
5108 tree type = TREE_VALUE (current);
5109 tree name = EXPR_WFL_NODE (wfl_name);
5110 tree already, arg_node;
5111 tree type_wfl = NULL_TREE;
5114 /* Obtain a suitable type for resolution, if necessary */
5115 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
5117 /* Process NAME, as it may specify extra dimension(s) for it */
5118 type = build_array_from_name (type, type_wfl, name, &name);
5119 EXPR_WFL_NODE (wfl_name) = name;
5121 real_type = GET_REAL_TYPE (type);
5122 if (TREE_CODE (real_type) == RECORD_TYPE)
5124 real_type = promote_type (real_type);
5125 if (TREE_CODE (type) == TREE_LIST)
5126 TREE_PURPOSE (type) = real_type;
5129 /* Check redefinition */
5130 for (already = arg_types; already; already = TREE_CHAIN (already))
5131 if (TREE_PURPOSE (already) == name)
5134 (wfl_name, "Variable %qs is used more than once in the argument list of method %qs",
5135 IDENTIFIER_POINTER (name),
5136 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
5140 /* If we've an incomplete argument type, we know there is a location
5141 to patch when the type get resolved, later. */
5145 patch_stage = JDEP_METHOD;
5146 type = register_incomplete_type (patch_stage,
5147 type_wfl, wfl_name, type);
5148 jdep = CLASSD_LAST (ctxp->classd_list);
5149 JDEP_MISC (jdep) = id;
5152 /* The argument node: a name and a (possibly) incomplete type. */
5153 arg_node = build_tree_list (name, real_type);
5154 /* Remember arguments declared final. */
5155 ARG_FINAL_P (arg_node) = ARG_FINAL_P (current);
5158 JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
5159 TREE_CHAIN (arg_node) = arg_types;
5160 arg_types = arg_node;
5162 TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
5163 node = build_tree_list (id, meth);
5168 unresolved_type_p (tree wfl, tree *returned)
5170 if (TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION)
5174 tree decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (wfl));
5175 if (decl && current_class && (decl == TYPE_NAME (current_class)))
5176 *returned = TREE_TYPE (decl);
5177 else if (GET_CPC_UN () == EXPR_WFL_NODE (wfl))
5178 *returned = TREE_TYPE (GET_CPC ());
5180 *returned = NULL_TREE;
5189 /* From NAME, build a qualified identifier node using the
5190 qualification from the current package definition. */
5193 parser_qualified_classname (tree name)
5195 tree nested_class_name;
5197 if ((nested_class_name = maybe_make_nested_class_name (name)))
5198 return nested_class_name;
5201 return merge_qualified_name (ctxp->package, name);
5206 /* Called once the type a interface extends is resolved. Returns 0 if
5207 everything is OK. */
5210 parser_check_super_interface (tree super_decl, tree this_decl, tree this_wfl)
5212 tree super_type = TREE_TYPE (super_decl);
5214 /* Has to be an interface */
5215 if (!CLASS_INTERFACE (super_decl))
5218 (this_wfl, "%s %qs can't implement/extend %s %qs",
5219 (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (this_decl))) ?
5220 "Interface" : "Class"),
5221 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5222 (TYPE_ARRAY_P (super_type) ? "array" : "class"),
5223 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5227 /* Check top-level interface access. Inner classes are subject to member
5228 access rules (6.6.1). */
5229 if (! INNER_CLASS_P (super_type)
5230 && check_pkg_class_access (DECL_NAME (super_decl),
5231 NULL_TREE, true, this_decl))
5234 SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
5235 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5236 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
5240 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
5241 0 if everything is OK. */
5244 parser_check_super (tree super_decl, tree this_decl, tree wfl)
5246 tree super_type = TREE_TYPE (super_decl);
5248 /* SUPER should be a CLASS (neither an array nor an interface) */
5249 if (TYPE_ARRAY_P (super_type) || CLASS_INTERFACE (TYPE_NAME (super_type)))
5252 (wfl, "Class %qs can't subclass %s %qs",
5253 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5254 (CLASS_INTERFACE (TYPE_NAME (super_type)) ? "interface" : "array"),
5255 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5259 if (CLASS_FINAL (TYPE_NAME (super_type)))
5261 parse_error_context (wfl, "Can't subclass final classes: %s",
5262 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5266 /* Check top-level class scope. Inner classes are subject to member access
5268 if (! INNER_CLASS_P (super_type)
5269 && (check_pkg_class_access (DECL_NAME (super_decl), wfl, true, NULL_TREE)))
5272 SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
5273 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5274 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
5278 /* Create a new dependency list and link it (in a LIFO manner) to the
5279 CTXP list of type dependency list. */
5282 create_jdep_list (struct parser_ctxt *ctxp)
5284 jdeplist *new = xmalloc (sizeof (jdeplist));
5285 new->first = new->last = NULL;
5286 new->next = ctxp->classd_list;
5287 ctxp->classd_list = new;
5291 reverse_jdep_list (struct parser_ctxt *ctxp)
5293 jdeplist *prev = NULL, *current, *next;
5294 for (current = ctxp->classd_list; current; current = next)
5296 next = current->next;
5297 current->next = prev;
5303 /* Create a fake pointer based on the ID stored in
5304 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
5305 registered again. */
5308 obtain_incomplete_type (tree type_name)
5310 tree ptr = NULL_TREE, name;
5312 if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
5313 name = EXPR_WFL_NODE (type_name);
5314 else if (INCOMPLETE_TYPE_P (type_name))
5315 name = TYPE_NAME (type_name);
5319 /* Workaround from build_pointer_type for incomplete types. */
5320 BUILD_PTR_FROM_NAME (ptr, name);
5321 TYPE_MODE (ptr) = ptr_mode;
5327 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
5328 non NULL instead of computing a new fake type based on WFL. The new
5329 dependency is inserted in the current type dependency list, in FIFO
5333 register_incomplete_type (int kind, tree wfl, tree decl, tree ptr)
5335 jdep *new = xmalloc (sizeof (jdep));
5337 if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
5338 ptr = obtain_incomplete_type (wfl);
5340 JDEP_KIND (new) = kind;
5341 JDEP_DECL (new) = decl;
5342 JDEP_TO_RESOLVE (new) = ptr;
5343 JDEP_WFL (new) = wfl;
5344 JDEP_CHAIN (new) = NULL;
5345 JDEP_MISC (new) = NULL_TREE;
5346 /* For some dependencies, set the enclosing class of the current
5347 class to be the enclosing context */
5348 if ((kind == JDEP_INTERFACE || kind == JDEP_ANONYMOUS || kind == JDEP_SUPER)
5349 && GET_ENCLOSING_CPC ())
5350 JDEP_ENCLOSING (new) = TREE_VALUE (GET_ENCLOSING_CPC ());
5352 JDEP_ENCLOSING (new) = GET_CPC ();
5353 JDEP_GET_PATCH (new) = (tree *)NULL;
5355 JDEP_INSERT (ctxp->classd_list, new);
5360 /* This checks for circular references with innerclasses. We start
5361 from SOURCE and should never reach TARGET. Extended/implemented
5362 types in SOURCE have their enclosing context checked not to reach
5363 TARGET. When the last enclosing context of SOURCE is reached, its
5364 extended/implemented types are also checked not to reach TARGET.
5365 In case of error, WFL of the offending type is returned; NULL_TREE
5369 check_inner_circular_reference (tree source, tree target)
5375 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (source), i, base_binfo); i++)
5379 /* We can end up with a NULL_TREE or an incomplete type here if
5380 we encountered previous type resolution errors. It's safe to
5381 simply ignore these cases. */
5382 su = BINFO_TYPE (base_binfo);
5383 if (INCOMPLETE_TYPE_P (su))
5386 if (inherits_from_p (su, target))
5387 return lookup_cl (TYPE_NAME (su));
5389 for (ctx = DECL_CONTEXT (TYPE_NAME (su)); ctx; ctx = DECL_CONTEXT (ctx))
5391 /* An enclosing context shouldn't be TARGET */
5392 if (ctx == TYPE_NAME (target))
5393 return lookup_cl (TYPE_NAME (su));
5395 /* When we reach the enclosing last context, start a check
5396 on it, with the same target */
5397 if (! DECL_CONTEXT (ctx) &&
5398 (cl = check_inner_circular_reference (TREE_TYPE (ctx), target)))
5405 /* Explore TYPE's `extends' clause member(s) and return the WFL of the
5406 offending type if a circularity is detected. NULL_TREE is returned
5407 otherwise. TYPE can be an interface or a class. */
5410 check_circular_reference (tree type)
5415 if (!BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
5418 if (! CLASS_INTERFACE (TYPE_NAME (type)))
5420 if (inherits_from_p (CLASSTYPE_SUPER (type), type))
5421 return lookup_cl (TYPE_NAME (type));
5425 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (type), i, base_binfo); i++)
5427 if (BINFO_TYPE (base_binfo) != object_type_node
5428 && interface_of_p (type, BINFO_TYPE (base_binfo)))
5429 return lookup_cl (TYPE_NAME (BINFO_TYPE (base_binfo)));
5435 java_check_circular_reference (void)
5438 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5440 tree type = TREE_TYPE (current);
5443 cl = check_circular_reference (type);
5445 cl = check_inner_circular_reference (type, type);
5447 parse_error_context (cl, "Cyclic class inheritance%s",
5448 (cyclic_inheritance_report ?
5449 cyclic_inheritance_report : ""));
5453 /* Augment the parameter list PARM with parameters crafted to
5454 initialize outer context locals aliases. Through ARTIFICIAL, a
5455 count is kept of the number of crafted parameters. MODE governs
5456 what eventually gets created: something suitable for a function
5457 creation or a function invocation, either the constructor or
5461 build_alias_initializer_parameter_list (int mode, tree class_type, tree parm,
5465 tree additional_parms = NULL_TREE;
5467 for (field = TYPE_FIELDS (class_type); field; field = TREE_CHAIN (field))
5468 if (FIELD_LOCAL_ALIAS (field))
5470 const char *buffer = IDENTIFIER_POINTER (DECL_NAME (field));
5471 tree purpose = NULL_TREE, value = NULL_TREE, name = NULL_TREE;
5476 case AIPL_FUNCTION_DECLARATION:
5477 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (mangled_id,
5479 purpose = build_wfl_node (mangled_id);
5480 if (TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
5481 value = build_wfl_node (TYPE_NAME (TREE_TYPE (field)));
5483 value = TREE_TYPE (field);
5486 case AIPL_FUNCTION_CREATION:
5487 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (purpose,
5489 value = TREE_TYPE (field);
5492 case AIPL_FUNCTION_FINIT_INVOCATION:
5493 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (mangled_id,
5495 /* Now, this is wrong. purpose should always be the NAME
5496 of something and value its matching value (decl, type,
5497 etc...) FIXME -- but there is a lot to fix. */
5499 /* When invoked for this kind of operation, we already
5500 know whether a field is used or not. */
5501 purpose = TREE_TYPE (field);
5502 value = build_wfl_node (mangled_id);
5505 case AIPL_FUNCTION_CTOR_INVOCATION:
5506 /* There are two case: the constructor invocation happens
5507 outside the local inner, in which case, locales from the outer
5508 context are directly used.
5510 Otherwise, we fold to using the alias directly. */
5511 if (class_type == current_class)
5515 name = get_identifier (&buffer[4]);
5516 value = IDENTIFIER_LOCAL_VALUE (name);
5520 additional_parms = tree_cons (purpose, value, additional_parms);
5524 if (additional_parms)
5526 if (ANONYMOUS_CLASS_P (class_type)
5527 && mode == AIPL_FUNCTION_CTOR_INVOCATION)
5528 additional_parms = nreverse (additional_parms);
5529 parm = chainon (additional_parms, parm);
5535 /* Craft a constructor for CLASS_DECL -- what we should do when none
5536 where found. ARGS is non NULL when a special signature must be
5537 enforced. This is the case for anonymous classes. */
5540 craft_constructor (tree class_decl, tree args)
5542 tree class_type = TREE_TYPE (class_decl);
5543 tree parm = NULL_TREE;
5544 /* Inherit access flags for the constructor from its enclosing class. */
5545 int valid_ctor_flags = ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE;
5546 int flags = (get_access_flags_from_decl (class_decl) & valid_ctor_flags);
5547 int i = 0, artificial = 0;
5548 tree decl, ctor_name;
5551 ctor_name = init_identifier_node;
5553 /* If we're dealing with an inner class constructor, we hide the
5554 this$<n> decl in the name field of its parameter declaration. */
5555 if (PURE_INNER_CLASS_TYPE_P (class_type))
5557 tree type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_type)));
5558 parm = tree_cons (build_current_thisn (class_type),
5559 build_pointer_type (type), parm);
5561 /* Some more arguments to be hidden here. The values of the local
5562 variables of the outer context that the inner class needs to see. */
5563 parm = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
5568 /* Then if there are any args to be enforced, enforce them now */
5569 for (; args && args != end_params_node; args = TREE_CHAIN (args))
5571 /* If we see a `void *', we need to change it to Object. */
5572 if (TREE_VALUE (args) == TREE_TYPE (null_pointer_node))
5573 TREE_VALUE (args) = object_ptr_type_node;
5575 sprintf (buffer, "parm%d", i++);
5576 parm = tree_cons (get_identifier (buffer), TREE_VALUE (args), parm);
5579 CRAFTED_PARAM_LIST_FIXUP (parm);
5580 decl = create_artificial_method (class_type, flags, void_type_node,
5582 fix_method_argument_names (parm, decl);
5583 /* Now, mark the artificial parameters. */
5584 DECL_FUNCTION_NAP (decl) = artificial;
5585 DECL_FUNCTION_SYNTHETIC_CTOR (decl) = DECL_CONSTRUCTOR_P (decl) = 1;
5586 DECL_INLINE (decl) = 1;
5591 /* Fix the constructors. This will be called right after circular
5592 references have been checked. It is necessary to fix constructors
5593 early even if no code generation will take place for that class:
5594 some generated constructor might be required by the class whose
5595 compilation triggered this one to be simply loaded. */
5598 java_fix_constructors (void)
5602 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5604 tree class_type = TREE_TYPE (current);
5608 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
5611 output_class = current_class = class_type;
5612 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
5614 if (DECL_CONSTRUCTOR_P (decl))
5616 fix_constructors (decl);
5621 /* Anonymous class constructor can't be generated that early. */
5622 if (!saw_ctor && !ANONYMOUS_CLASS_P (class_type))
5623 craft_constructor (current, NULL_TREE);
5627 /* safe_layout_class just makes sure that we can load a class without
5628 disrupting the current_class, input_file, input_line, etc, information
5629 about the class processed currently. */
5632 safe_layout_class (tree class)
5634 tree save_current_class = current_class;
5635 location_t save_location = input_location;
5637 layout_class (class);
5639 current_class = save_current_class;
5640 input_location = save_location;
5644 jdep_resolve_class (jdep *dep)
5648 if (JDEP_RESOLVED_P (dep))
5649 decl = JDEP_RESOLVED_DECL (dep);
5652 decl = resolve_class (JDEP_ENCLOSING (dep), JDEP_TO_RESOLVE (dep),
5653 JDEP_DECL (dep), JDEP_WFL (dep));
5654 JDEP_RESOLVED (dep, decl);
5655 /* If there is no WFL, that's ok. We generate this warning
5657 if (decl && JDEP_WFL (dep) != NULL_TREE)
5658 check_deprecation (JDEP_WFL (dep), decl);
5662 complete_class_report_errors (dep);
5663 else if (INNER_CLASS_DECL_P (decl))
5665 tree inner = TREE_TYPE (decl);
5666 if (! CLASS_LOADED_P (inner))
5668 safe_layout_class (inner);
5669 if (TYPE_SIZE (inner) == error_mark_node)
5670 TYPE_SIZE (inner) = NULL_TREE;
5672 check_inner_class_access (decl, JDEP_ENCLOSING (dep), JDEP_WFL (dep));
5677 /* Complete unsatisfied class declaration and their dependencies */
5680 java_complete_class (void)
5687 /* Process imports */
5690 /* Reverse things so we have the right order */
5691 ctxp->class_list = nreverse (ctxp->class_list);
5692 ctxp->classd_list = reverse_jdep_list (ctxp);
5694 for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
5696 cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
5700 for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
5703 if (!(decl = jdep_resolve_class (dep)))
5706 /* Now it's time to patch */
5707 switch (JDEP_KIND (dep))
5710 /* Simply patch super */
5711 if (parser_check_super (decl, JDEP_DECL (dep), JDEP_WFL (dep)))
5713 BINFO_TYPE (BINFO_BASE_BINFO
5714 (TYPE_BINFO (TREE_TYPE (JDEP_DECL (dep))), 0))
5720 /* We do part of the job done in add_field */
5721 tree field_decl = JDEP_DECL (dep);
5722 tree field_type = TREE_TYPE (decl);
5723 if (TREE_CODE (field_type) == RECORD_TYPE)
5724 field_type = promote_type (field_type);
5725 TREE_TYPE (field_decl) = field_type;
5726 DECL_ALIGN (field_decl) = 0;
5727 DECL_USER_ALIGN (field_decl) = 0;
5728 layout_decl (field_decl, 0);
5729 SOURCE_FRONTEND_DEBUG
5730 (("Completed field/var decl '%s' with '%s'",
5731 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
5732 IDENTIFIER_POINTER (DECL_NAME (decl))));
5735 case JDEP_METHOD: /* We start patching a method */
5736 case JDEP_METHOD_RETURN:
5742 type = TREE_TYPE(decl);
5743 if (TREE_CODE (type) == RECORD_TYPE)
5744 type = promote_type (type);
5745 JDEP_APPLY_PATCH (dep, type);
5746 SOURCE_FRONTEND_DEBUG
5747 (((JDEP_KIND (dep) == JDEP_METHOD_RETURN ?
5748 "Completing fct '%s' with ret type '%s'":
5749 "Completing arg '%s' with type '%s'"),
5750 IDENTIFIER_POINTER (EXPR_WFL_NODE
5751 (JDEP_DECL_WFL (dep))),
5752 IDENTIFIER_POINTER (DECL_NAME (decl))));
5756 dep = JDEP_CHAIN (dep);
5757 if (JDEP_KIND (dep) == JDEP_METHOD_END)
5760 decl = jdep_resolve_class (dep);
5764 tree mdecl = JDEP_DECL (dep), signature;
5765 /* Recompute and reset the signature, check first that
5766 all types are now defined. If they're not,
5767 don't build the signature. */
5768 if (check_method_types_complete (mdecl))
5770 signature = build_java_signature (TREE_TYPE (mdecl));
5771 set_java_signature (TREE_TYPE (mdecl), signature);
5778 case JDEP_INTERFACE:
5779 if (parser_check_super_interface (decl, JDEP_DECL (dep),
5782 parser_add_interface (JDEP_DECL (dep), decl, JDEP_WFL (dep));
5787 type = TREE_TYPE(decl);
5788 if (TREE_CODE (type) == RECORD_TYPE)
5789 type = promote_type (type);
5790 JDEP_APPLY_PATCH (dep, type);
5794 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5795 SOURCE_FRONTEND_DEBUG
5796 (("Completing a random type dependency on a '%s' node",
5797 tree_code_name [TREE_CODE (JDEP_DECL (dep))]));
5800 case JDEP_EXCEPTION:
5801 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5802 SOURCE_FRONTEND_DEBUG
5803 (("Completing '%s' 'throws' argument node",
5804 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
5807 case JDEP_ANONYMOUS:
5808 patch_anonymous_class (decl, JDEP_DECL (dep), JDEP_WFL (dep));
5819 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
5823 resolve_class (tree enclosing, tree class_type, tree decl, tree cl)
5825 tree tname = TYPE_NAME (class_type);
5826 tree resolved_type = TREE_TYPE (class_type);
5828 tree resolved_type_decl;
5830 if (resolved_type != NULL_TREE)
5832 tree resolved_type_decl = TYPE_NAME (resolved_type);
5833 if (resolved_type_decl == NULL_TREE
5834 || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
5836 resolved_type_decl = build_decl (TYPE_DECL,
5837 TYPE_NAME (class_type),
5840 return resolved_type_decl;
5843 /* 1- Check to see if we have an array. If true, find what we really
5845 if ((array_dims = build_type_name_from_array_name (tname,
5846 &TYPE_NAME (class_type))))
5847 WFL_STRIP_BRACKET (cl, cl);
5849 /* 2- Resolve the bare type */
5850 if (!(resolved_type_decl = do_resolve_class (enclosing, NULL_TREE, class_type,
5853 resolved_type = TREE_TYPE (resolved_type_decl);
5855 /* 3- If we have an array, reconstruct the array down to its nesting */
5858 for (; array_dims; array_dims--)
5859 resolved_type = build_java_array_type (resolved_type, -1);
5860 resolved_type_decl = TYPE_NAME (resolved_type);
5862 TREE_TYPE (class_type) = resolved_type;
5863 return resolved_type_decl;
5866 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
5867 are used to report error messages; CL must either be NULL_TREE or a
5868 WFL wrapping a class. Do not try to replace TYPE_NAME (class_type)
5869 by a variable, since it is changed by find_in_imports{_on_demand}
5870 and (but it doesn't really matter) qualify_and_find. */
5873 do_resolve_class (tree enclosing, tree import_type, tree class_type, tree decl,
5876 tree new_class_decl = NULL_TREE;
5877 tree saved_enclosing_type = enclosing ? TREE_TYPE (enclosing) : NULL_TREE;
5878 tree candidate = NULL_TREE;
5881 if (QUALIFIED_P (TYPE_NAME (class_type)))
5883 /* If the type name is of the form `Q . Id', then Q is either a
5884 package name or a class name. First we try to find Q as a
5885 class and then treat Id as a member type. If we can't find Q
5886 as a class then we fall through. */
5887 tree q, left, left_type, right;
5888 if (split_qualified_name (&left, &right, TYPE_NAME (class_type)) == 0)
5890 BUILD_PTR_FROM_NAME (left_type, left);
5891 q = do_resolve_class (enclosing, import_type, left_type, decl, cl);
5895 saved_enclosing_type = TREE_TYPE (q);
5896 BUILD_PTR_FROM_NAME (class_type, right);
5903 tree context = enclosing;
5905 /* 0- Search in the current class as an inner class.
5906 Maybe some code here should be added to load the class or
5907 something, at least if the class isn't an inner class and ended
5908 being loaded from class file. FIXME. */
5911 new_class_decl = resolve_inner_class (context, cl, enclosing, class_type);
5915 if (inner_class_accessible (new_class_decl, context))
5918 if (candidate == NULL_TREE)
5919 candidate = new_class_decl;
5920 new_class_decl = NULL_TREE;
5923 /* Now that we've looked through all superclasses, try the enclosing
5925 enclosing = DECL_CONTEXT (enclosing);
5929 return new_class_decl;
5932 /* 1- Check for the type in single imports. Look at enclosing classes and,
5933 if we're laying out a superclass, at the import list for the subclass.
5934 This will change TYPE_NAME() if something relevant is found. */
5935 if (import_type && TYPE_IMPORT_LIST (import_type))
5936 find_in_imports (import_type, class_type);
5937 find_in_imports (saved_enclosing_type, class_type);
5939 /* 2- And check for the type in the current compilation unit */
5940 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5942 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)))
5943 load_class (TYPE_NAME (class_type), 0);
5944 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5947 /* 3- Search according to the current package definition */
5948 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5950 if ((new_class_decl = qualify_and_find (class_type, ctxp->package,
5951 TYPE_NAME (class_type))))
5952 return new_class_decl;
5955 /* 4- Check the import on demands. Don't allow bar.baz to be
5956 imported from foo.* */
5957 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5960 && TYPE_IMPORT_DEMAND_LIST (import_type)
5961 && find_in_imports_on_demand (import_type, class_type))
5963 if (find_in_imports_on_demand (saved_enclosing_type, class_type))
5967 /* If found in find_in_imports_on_demand, the type has already been
5969 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5970 return new_class_decl;
5972 /* 5- Check another compilation unit that bears the name of type */
5973 load_class (TYPE_NAME (class_type), 0);
5976 cl = lookup_cl (decl);
5978 /* If we don't have a value for CL, then we're being called recursively.
5979 We can't check package access just yet, but it will be taken care of
5983 if (check_pkg_class_access (TYPE_NAME (class_type), cl, true, NULL_TREE))
5987 /* 6- Last call for a resolution */
5988 decl_result = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5990 /* The final lookup might have registered a.b.c into a.b$c If we
5991 failed at the first lookup, progressively change the name if
5992 applicable and use the matching DECL instead. */
5993 if (!decl_result && QUALIFIED_P (TYPE_NAME (class_type)))
5996 tree name = TYPE_NAME (class_type);
5997 char *namebuffer = alloca (IDENTIFIER_LENGTH (name) + 1);
5999 strcpy (namebuffer, IDENTIFIER_POINTER (name));
6003 /* Reach the last '.', and if applicable, replace it by a `$' and
6004 see if this exists as a type. */
6005 if ((separator = strrchr (namebuffer, '.')))
6008 name = get_identifier (namebuffer);
6009 decl_result = IDENTIFIER_CLASS_VALUE (name);
6011 } while (!decl_result && separator);
6020 qualify_and_find (tree class_type, tree package, tree name)
6022 tree new_qualified = merge_qualified_name (package, name);
6023 tree new_class_decl;
6025 if (!IDENTIFIER_CLASS_VALUE (new_qualified))
6026 load_class (new_qualified, 0);
6027 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (new_qualified)))
6029 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)))
6030 load_class (TREE_TYPE (new_class_decl), 0);
6031 TYPE_NAME (class_type) = new_qualified;
6032 return IDENTIFIER_CLASS_VALUE (new_qualified);
6037 /* Resolve NAME and lay it out (if not done and if not the current
6038 parsed class). Return a decl node. This function is meant to be
6039 called when type resolution is necessary during the walk pass. */
6042 resolve_and_layout (tree something, tree cl)
6044 tree decl, decl_type;
6046 /* Don't do that on the current class */
6047 if (something == current_class)
6048 return TYPE_NAME (current_class);
6050 /* Don't do anything for void and other primitive types */
6051 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
6054 /* Pointer types can be reall pointer types or fake pointers. When
6055 finding a real pointer, recheck for primitive types */
6056 if (TREE_CODE (something) == POINTER_TYPE)
6058 if (TREE_TYPE (something))
6060 something = TREE_TYPE (something);
6061 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
6065 something = TYPE_NAME (something);
6068 /* Don't do anything for arrays of primitive types */
6069 if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
6070 && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
6073 /* Something might be a WFL */
6074 if (TREE_CODE (something) == EXPR_WITH_FILE_LOCATION)
6075 something = EXPR_WFL_NODE (something);
6077 /* Otherwise, if something is not and IDENTIFIER_NODE, it can be a a
6078 TYPE_DECL or a real TYPE */
6079 else if (TREE_CODE (something) != IDENTIFIER_NODE)
6080 something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
6081 DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
6083 if (!(decl = resolve_no_layout (something, cl)))
6086 /* Resolve and layout if necessary */
6087 decl_type = TREE_TYPE (decl);
6088 layout_class_methods (decl_type);
6090 if (CLASS_FROM_SOURCE_P (decl_type))
6091 java_check_methods (decl);
6092 /* Layout the type if necessary */
6093 if (decl_type != current_class && !CLASS_LOADED_P (decl_type))
6094 safe_layout_class (decl_type);
6099 /* Resolve a class, returns its decl but doesn't perform any
6100 layout. The current parsing context is saved and restored */
6103 resolve_no_layout (tree name, tree cl)
6106 BUILD_PTR_FROM_NAME (ptr, name);
6107 java_parser_context_save_global ();
6108 decl = resolve_class (TYPE_NAME (current_class), ptr, NULL_TREE, cl);
6109 java_parser_context_restore_global ();
6114 /* Called when reporting errors. Skip the '[]'s in a complex array
6115 type description that failed to be resolved. purify_type_name can't
6116 use an identifier tree. */
6119 purify_type_name (const char *name)
6121 int len = strlen (name);
6124 STRING_STRIP_BRACKETS (name, len, bracket_found);
6127 char *stripped_name = xmemdup (name, len, len+1);
6128 stripped_name [len] = '\0';
6129 return stripped_name;
6134 /* The type CURRENT refers to can't be found. We print error messages. */
6137 complete_class_report_errors (jdep *dep)
6141 if (!JDEP_WFL (dep))
6144 name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
6145 switch (JDEP_KIND (dep))
6149 (JDEP_WFL (dep), "Superclass %qs of class %qs not found",
6150 purify_type_name (name),
6151 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6155 (JDEP_WFL (dep), "Type %qs not found in declaration of field %qs",
6156 purify_type_name (name),
6157 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6159 case JDEP_METHOD: /* Covers arguments */
6161 (JDEP_WFL (dep), "Type %qs not found in the declaration of the argument %qs of method %qs",
6162 purify_type_name (name),
6163 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
6164 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
6166 case JDEP_METHOD_RETURN: /* Covers return type */
6168 (JDEP_WFL (dep), "Type %qs not found in the declaration of the return type of method %qs",
6169 purify_type_name (name),
6170 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
6172 case JDEP_INTERFACE:
6174 (JDEP_WFL (dep), "Superinterface %qs of %s %qs not found",
6175 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
6176 (CLASS_OR_INTERFACE (JDEP_DECL (dep), "class", "interface")),
6177 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6181 (JDEP_WFL (dep), "Type %qs not found in the declaration of the local variable %qs",
6182 purify_type_name (IDENTIFIER_POINTER
6183 (EXPR_WFL_NODE (JDEP_WFL (dep)))),
6184 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6186 case JDEP_EXCEPTION: /* As specified by `throws' */
6188 (JDEP_WFL (dep), "Class %qs not found in %<throws%>",
6189 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
6192 /* Fix for -Wall. Just break doing nothing. The error will be
6198 /* Return a static string containing the DECL prototype string. If
6199 DECL is a constructor, use the class name instead of the form
6203 get_printable_method_name (tree decl)
6205 const char *to_return;
6206 tree name = NULL_TREE;
6208 if (DECL_CONSTRUCTOR_P (decl))
6210 name = DECL_NAME (decl);
6211 DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
6214 to_return = lang_printable_name (decl, 2);
6215 if (DECL_CONSTRUCTOR_P (decl))
6216 DECL_NAME (decl) = name;
6221 /* Track method being redefined inside the same class. As a side
6222 effect, set DECL_NAME to an IDENTIFIER (prior entering this
6223 function it's a FWL, so we can track errors more accurately.) */
6226 check_method_redefinition (tree class, tree method)
6230 /* There's no need to verify <clinit> and finit$ and instinit$ */
6231 if (DECL_CLINIT_P (method)
6232 || DECL_FINIT_P (method) || DECL_INSTINIT_P (method))
6235 sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
6236 for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
6238 if (redef == method)
6240 if (DECL_NAME (redef) == DECL_NAME (method)
6241 && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef))
6242 && !DECL_ARTIFICIAL (method))
6245 (DECL_FUNCTION_WFL (method), "Duplicate %s declaration %qs",
6246 (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
6247 get_printable_method_name (redef));
6254 /* Return 1 if check went ok, 0 otherwise. */
6256 check_abstract_method_definitions (int do_interface, tree class_decl,
6259 tree class = TREE_TYPE (class_decl);
6260 tree method, end_type;
6263 end_type = (do_interface ? object_type_node : type);
6264 for (method = TYPE_METHODS (type); method; method = TREE_CHAIN (method))
6266 tree other_super, other_method, method_sig, method_name;
6268 int end_type_reached = 0;
6270 if (!METHOD_ABSTRACT (method) || METHOD_FINAL (method))
6273 /* Now verify that somewhere in between TYPE and CLASS,
6274 abstract method METHOD gets a non abstract definition
6275 that is inherited by CLASS. */
6277 method_sig = build_java_signature (TREE_TYPE (method));
6278 method_name = DECL_NAME (method);
6279 if (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION)
6280 method_name = EXPR_WFL_NODE (method_name);
6282 other_super = class;
6284 if (other_super == end_type)
6285 end_type_reached = 1;
6288 for (other_method = TYPE_METHODS (other_super); other_method;
6289 other_method = TREE_CHAIN (other_method))
6291 tree s = build_java_signature (TREE_TYPE (other_method));
6292 tree other_name = DECL_NAME (other_method);
6294 if (TREE_CODE (other_name) == EXPR_WITH_FILE_LOCATION)
6295 other_name = EXPR_WFL_NODE (other_name);
6296 if (!DECL_CLINIT_P (other_method)
6297 && !DECL_CONSTRUCTOR_P (other_method)
6298 && method_name == other_name
6300 && !METHOD_ABSTRACT (other_method))
6306 other_super = CLASSTYPE_SUPER (other_super);
6307 } while (!end_type_reached);
6309 /* Report that abstract METHOD didn't find an implementation
6310 that CLASS can use. */
6313 char *t = xstrdup (lang_printable_name
6314 (TREE_TYPE (TREE_TYPE (method)), 0));
6315 tree ccn = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
6318 (lookup_cl (class_decl),
6319 "Class %qs doesn't define the abstract method %<%s %s%> from %s %<%s%>. This method must be defined or %s %qs must be declared abstract",
6320 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
6321 t, lang_printable_name (method, 2),
6322 (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))) ?
6323 "interface" : "class"),
6324 IDENTIFIER_POINTER (ccn),
6325 (CLASS_INTERFACE (class_decl) ? "interface" : "class"),
6326 IDENTIFIER_POINTER (DECL_NAME (class_decl)));
6332 if (ok && do_interface)
6334 /* Check for implemented interfaces. */
6339 ok && BINFO_BASE_ITERATE (TYPE_BINFO (type), i, base_binfo);
6341 ok = check_abstract_method_definitions (1, class_decl,
6342 BINFO_TYPE (base_binfo));
6348 /* Check that CLASS_DECL somehow implements all inherited abstract
6352 java_check_abstract_method_definitions (tree class_decl)
6354 tree class = TREE_TYPE (class_decl);
6355 tree super, base_binfo;
6358 if (CLASS_ABSTRACT (class_decl))
6361 /* Check for inherited types */
6364 super = CLASSTYPE_SUPER (super);
6365 check_abstract_method_definitions (0, class_decl, super);
6366 } while (super != object_type_node);
6368 /* Check for implemented interfaces. */
6369 for (i = 1; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6370 check_abstract_method_definitions (1, class_decl, BINFO_TYPE (base_binfo));
6373 /* Check all the types method DECL uses and return 1 if all of them
6374 are now complete, 0 otherwise. This is used to check whether its
6375 safe to build a method signature or not. */
6378 check_method_types_complete (tree decl)
6380 tree type = TREE_TYPE (decl);
6383 if (!INCOMPLETE_TYPE_P (TREE_TYPE (type)))
6386 args = TYPE_ARG_TYPES (type);
6387 if (TREE_CODE (type) == METHOD_TYPE)
6388 args = TREE_CHAIN (args);
6389 for (; args != end_params_node; args = TREE_CHAIN (args))
6390 if (INCOMPLETE_TYPE_P (TREE_VALUE (args)))
6396 /* Visible interface to check methods contained in CLASS_DECL */
6399 java_check_methods (tree class_decl)
6401 if (CLASS_METHOD_CHECKED_P (TREE_TYPE (class_decl)))
6404 if (CLASS_INTERFACE (class_decl))
6405 java_check_abstract_methods (class_decl);
6407 java_check_regular_methods (class_decl);
6409 CLASS_METHOD_CHECKED_P (TREE_TYPE (class_decl)) = 1;
6412 /* Like not_accessible_p, but doesn't refer to the current class at
6415 hack_is_accessible_p (tree member, tree from_where)
6417 int flags = get_access_flags_from_decl (member);
6419 if (from_where == DECL_CONTEXT (member)
6420 || (flags & ACC_PUBLIC))
6423 if ((flags & ACC_PROTECTED))
6425 if (inherits_from_p (from_where, DECL_CONTEXT (member)))
6429 if ((flags & ACC_PRIVATE))
6432 /* Package private, or protected. */
6433 return in_same_package (TYPE_NAME (from_where),
6434 TYPE_NAME (DECL_CONTEXT (member)));
6437 /* Check all the methods of CLASS_DECL. Methods are first completed
6438 then checked according to regular method existence rules. If no
6439 constructor for CLASS_DECL were encountered, then build its
6442 java_check_regular_methods (tree class_decl)
6444 int saw_constructor = ANONYMOUS_CLASS_P (TREE_TYPE (class_decl));
6446 tree class = TREE_TYPE (class_decl);
6447 tree found = NULL_TREE;
6450 /* It is not necessary to check methods defined in java.lang.Object */
6451 if (class == object_type_node)
6454 if (!TYPE_NVIRTUALS (class))
6455 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6457 /* Should take interfaces into account. FIXME */
6458 for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
6461 tree method_wfl = DECL_FUNCTION_WFL (method);
6464 /* Check for redefinitions */
6465 if (check_method_redefinition (class, method))
6468 /* We verify things thrown by the method. They must inherit from
6469 java.lang.Throwable. */
6470 for (mthrows = DECL_FUNCTION_THROWS (method);
6471 mthrows; mthrows = TREE_CHAIN (mthrows))
6473 if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
6475 (TREE_PURPOSE (mthrows), "Class %qs in %<throws%> clause must be a subclass of class %<java.lang.Throwable%>",
6477 (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
6480 /* If we see one constructor a mark so we don't generate the
6481 default one. Also skip other verifications: constructors
6482 can't be inherited hence hidden or overridden. */
6483 if (DECL_CONSTRUCTOR_P (method))
6485 saw_constructor = 1;
6489 sig = build_java_argument_signature (TREE_TYPE (method));
6490 found = lookup_argument_method_generic (class, DECL_NAME (method), sig,
6491 SEARCH_SUPER | SEARCH_INTERFACE);
6493 /* Inner class can't declare static methods */
6494 if (METHOD_STATIC (method) && !TOPLEVEL_CLASS_DECL_P (class_decl))
6496 char *t = xstrdup (lang_printable_name (class, 0));
6498 (method_wfl, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
6499 lang_printable_name (method, 2), t);
6503 /* Nothing overrides or it's a private method. */
6506 if (METHOD_PRIVATE (found))
6512 /* If `found' is declared in an interface, make sure the
6513 modifier matches. */
6514 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
6515 && clinit_identifier_node != DECL_NAME (found)
6516 && !METHOD_PUBLIC (method))
6518 tree found_decl = TYPE_NAME (DECL_CONTEXT (found));
6519 parse_error_context (method_wfl, "Class %qs must override %qs with a public method in order to implement interface %qs",
6520 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
6521 lang_printable_name (method, 2),
6522 IDENTIFIER_POINTER (DECL_NAME (found_decl)));
6525 /* Can't override a method with the same name and different return
6527 if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
6530 (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 2));
6533 "Method %qs was defined with return type %qs in class %qs",
6534 lang_printable_name (found, 2), t,
6536 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6540 aflags = get_access_flags_from_decl (found);
6542 /* Can't override final. Can't override static. */
6543 if (METHOD_FINAL (found) || METHOD_STATIC (found))
6545 /* Static *can* override static */
6546 if (METHOD_STATIC (found) && METHOD_STATIC (method))
6550 "%s methods can't be overridden. Method %qs is %s in class %qs",
6551 (METHOD_FINAL (found) ? "Final" : "Static"),
6552 lang_printable_name (found, 2),
6553 (METHOD_FINAL (found) ? "final" : "static"),
6555 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6559 /* Static method can't override instance method. */
6560 if (METHOD_STATIC (method))
6564 "Instance methods can't be overridden by a static method. Method %qs is an instance method in class %qs",
6565 lang_printable_name (found, 2),
6567 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6571 /* - Overriding/hiding public must be public
6572 - Overriding/hiding protected must be protected or public
6573 - If the overridden or hidden method has default (package)
6574 access, then the overriding or hiding method must not be
6575 private; otherwise, a compile-time error occurs. If
6576 `found' belongs to an interface, things have been already
6578 if (!CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
6579 && ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method))
6580 || (METHOD_PROTECTED (found)
6581 && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
6582 || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
6583 && METHOD_PRIVATE (method))))
6587 "Methods can't be overridden to be more private. Method %qs is not %s in class %qs", lang_printable_name (method, 2),
6588 (METHOD_PUBLIC (method) ? "public" :
6589 (METHOD_PRIVATE (method) ? "private" : "protected")),
6590 IDENTIFIER_POINTER (DECL_NAME
6591 (TYPE_NAME (DECL_CONTEXT (found)))));
6595 /* Check this method against all the other implementations it
6596 overrides. Here we only check the class hierarchy; the rest
6597 of the checking is done later. If this method is just a
6598 Miranda method, we can skip the check. */
6599 if (! METHOD_INVISIBLE (method))
6600 check_concrete_throws_clauses (class, method, DECL_NAME (method), sig);
6603 /* The above throws clause check only looked at superclasses. Now
6604 we must also make sure that all methods declared in interfaces
6605 have compatible throws clauses. FIXME: there are more efficient
6606 ways to organize this checking; we should implement one. */
6607 check_interface_throws_clauses (class, class);
6609 if (!TYPE_NVIRTUALS (class))
6610 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6612 /* Search for inherited abstract method not yet implemented in this
6614 java_check_abstract_method_definitions (class_decl);
6616 if (!saw_constructor)
6620 /* Check to make sure that all the methods in all the interfaces
6621 implemented by CLASS_DECL are compatible with the concrete
6622 implementations available in CHECK_CLASS_DECL. */
6624 check_interface_throws_clauses (tree check_class_decl, tree class_decl)
6626 for (; class_decl != NULL_TREE; class_decl = CLASSTYPE_SUPER (class_decl))
6630 if (! CLASS_LOADED_P (class_decl))
6632 if (CLASS_FROM_SOURCE_P (class_decl))
6633 safe_layout_class (class_decl);
6635 load_class (class_decl, 1);
6638 for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (class_decl)) - 1; i > 0; --i)
6641 = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (class_decl), i));
6644 for (iface_method = TYPE_METHODS (interface);
6645 iface_method != NULL_TREE;
6646 iface_method = TREE_CHAIN (iface_method))
6650 /* First look for a concrete method implemented or
6651 inherited by this class. No need to search
6652 interfaces here, since we're already looking through
6654 sig = build_java_argument_signature (TREE_TYPE (iface_method));
6656 = lookup_argument_method_generic (check_class_decl,
6657 DECL_NAME (iface_method),
6658 sig, SEARCH_VISIBLE);
6659 /* If we don't find an implementation, that is ok. Any
6660 potential errors from that are diagnosed elsewhere.
6661 Also, multiple inheritance with conflicting throws
6662 clauses is fine in the absence of a concrete
6664 if (method != NULL_TREE && !METHOD_ABSTRACT (method)
6665 && !METHOD_INVISIBLE (iface_method))
6667 tree method_wfl = DECL_FUNCTION_WFL (method);
6668 check_throws_clauses (method, method_wfl, iface_method);
6672 /* Now check superinterfaces. */
6673 check_interface_throws_clauses (check_class_decl, interface);
6678 /* Check throws clauses of a method against the clauses of all the
6679 methods it overrides. We do this by searching up the class
6680 hierarchy, examining all matching accessible methods. */
6682 check_concrete_throws_clauses (tree class, tree self_method,
6683 tree name, tree signature)
6685 tree method = lookup_argument_method_generic (class, name, signature,
6686 SEARCH_SUPER | SEARCH_VISIBLE);
6687 while (method != NULL_TREE)
6689 if (! METHOD_INVISIBLE (method) && hack_is_accessible_p (method, class))
6690 check_throws_clauses (self_method, DECL_FUNCTION_WFL (self_method),
6693 method = lookup_argument_method_generic (DECL_CONTEXT (method),
6695 SEARCH_SUPER | SEARCH_VISIBLE);
6699 /* Generate an error if the `throws' clause of METHOD (if any) is
6700 incompatible with the `throws' clause of FOUND (if any). */
6702 check_throws_clauses (tree method, tree method_wfl, tree found)
6706 for (mthrows = DECL_FUNCTION_THROWS (method);
6707 mthrows; mthrows = TREE_CHAIN (mthrows))
6711 /* We don't verify unchecked expressions */
6712 if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
6714 /* Checked expression must be compatible */
6715 for (fthrows = DECL_FUNCTION_THROWS (found);
6716 fthrows; fthrows = TREE_CHAIN (fthrows))
6718 if (inherits_from_p (TREE_VALUE (mthrows), TREE_VALUE (fthrows)))
6724 (method_wfl, "Invalid checked exception class %qs in %<throws%> clause. The exception must be a subclass of an exception thrown by %qs from class %qs",
6725 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))),
6726 lang_printable_name (found, 2),
6728 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6733 /* Check abstract method of interface INTERFACE */
6735 java_check_abstract_methods (tree interface_decl)
6739 tree interface = TREE_TYPE (interface_decl);
6742 for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
6744 /* 2- Check for double definition inside the defining interface */
6745 if (check_method_redefinition (interface, method))
6748 /* 3- Overriding is OK as far as we preserve the return type. */
6749 found = lookup_java_interface_method2 (interface, method);
6753 t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 2));
6755 (DECL_FUNCTION_WFL (found),
6756 "Method %qs was defined with return type %qs in class %qs",
6757 lang_printable_name (found, 2), t,
6759 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6765 /* 4- Inherited methods can't differ by their returned types */
6766 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (interface), i, base_binfo); i++)
6768 tree sub_interface_method, sub_interface;
6770 sub_interface = BINFO_TYPE (base_binfo);
6771 for (sub_interface_method = TYPE_METHODS (sub_interface);
6772 sub_interface_method;
6773 sub_interface_method = TREE_CHAIN (sub_interface_method))
6775 found = lookup_java_interface_method2 (interface,
6776 sub_interface_method);
6777 if (found && (found != sub_interface_method))
6780 (lookup_cl (sub_interface_method),
6781 "Interface %qs inherits method %qs from interface %qs. This method is redefined with a different return type in interface %qs",
6782 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
6783 lang_printable_name (found, 2),
6785 (DECL_NAME (TYPE_NAME
6786 (DECL_CONTEXT (sub_interface_method)))),
6788 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6794 /* Lookup methods in interfaces using their name and partial
6795 signature. Return a matching method only if their types differ. */
6798 lookup_java_interface_method2 (tree class, tree method_decl)
6804 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6806 if ((BINFO_TYPE (base_binfo) != object_type_node)
6808 lookup_java_method2 (BINFO_TYPE (base_binfo), method_decl, 1)))
6811 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6813 to_return = lookup_java_interface_method2
6814 (BINFO_TYPE (base_binfo), method_decl);
6822 /* Lookup method using their name and partial signature. Return a
6823 matching method only if their types differ. */
6826 lookup_java_method2 (tree clas, tree method_decl, int do_interface)
6828 tree method, method_signature, method_name, method_type, name;
6830 method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
6831 name = DECL_NAME (method_decl);
6832 method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6833 EXPR_WFL_NODE (name) : name);
6834 method_type = TREE_TYPE (TREE_TYPE (method_decl));
6836 while (clas != NULL_TREE)
6838 for (method = TYPE_METHODS (clas);
6839 method != NULL_TREE; method = TREE_CHAIN (method))
6841 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
6842 tree name = DECL_NAME (method);
6843 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6844 EXPR_WFL_NODE (name) : name) == method_name
6845 && method_sig == method_signature
6846 && TREE_TYPE (TREE_TYPE (method)) != method_type)
6849 clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
6854 /* Return the line that matches DECL line number, and try its best to
6855 position the column number. Used during error reports.
6856 FUTURE/FIXME: return source_location instead of node. */
6858 static GTY(()) tree cl_v;
6860 lookup_cl (tree decl)
6862 #ifndef USE_MAPPED_LOCATION
6869 if (cl_v == NULL_TREE)
6871 cl_v = build_unknown_wfl (NULL_TREE);
6874 #ifdef USE_MAPPED_LOCATION
6875 SET_EXPR_LOCATION (cl_v, DECL_SOURCE_LOCATION (decl));
6877 EXPR_WFL_FILENAME_NODE (cl_v) = get_identifier (DECL_SOURCE_FILE (decl));
6878 EXPR_WFL_SET_LINECOL (cl_v, DECL_SOURCE_LINE (decl), -1);
6880 line = java_get_line_col (EXPR_WFL_FILENAME (cl_v),
6881 EXPR_WFL_LINENO (cl_v), EXPR_WFL_COLNO (cl_v));
6883 found = strstr ((const char *)line,
6884 (const char *)IDENTIFIER_POINTER (DECL_NAME (decl)));
6886 EXPR_WFL_SET_LINECOL (cl_v, EXPR_WFL_LINENO (cl_v), found - line);
6892 /* Look for a simple name in the single-type import list */
6895 find_name_in_single_imports (tree name)
6899 for (node = ctxp->import_list; node; node = TREE_CHAIN (node))
6900 if (TREE_VALUE (node) == name)
6901 return (EXPR_WFL_NODE (TREE_PURPOSE (node)));
6906 /* Process all single-type import. */
6909 process_imports (void)
6914 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
6916 tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import));
6917 char *original_name;
6919 /* Don't load twice something already defined. */
6920 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6923 original_name = xmemdup (IDENTIFIER_POINTER (to_be_found),
6924 IDENTIFIER_LENGTH (to_be_found),
6925 IDENTIFIER_LENGTH (to_be_found) + 1);
6931 QUALIFIED_P (to_be_found) = 1;
6932 load_class (to_be_found, 0);
6934 check_pkg_class_access (to_be_found, TREE_PURPOSE (import), true, NULL_TREE);
6936 /* We found it, we can bail out */
6937 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6939 check_deprecation (TREE_PURPOSE (import),
6940 IDENTIFIER_CLASS_VALUE (to_be_found));
6944 /* We haven't found it. Maybe we're trying to access an
6945 inner class. The only way for us to know is to try again
6946 after having dropped a qualifier. If we can't break it further,
6947 we have an error. */
6948 if (split_qualified_name (&left, NULL, to_be_found))
6953 if (!IDENTIFIER_CLASS_VALUE (to_be_found))
6955 parse_error_context (TREE_PURPOSE (import),
6956 "Class or interface %qs not found in import",
6961 free (original_name);
6968 /* Possibly find and mark a class imported by a single-type import
6972 find_in_imports (tree enclosing_type, tree class_type)
6975 if (enclosing_type && TYPE_IMPORT_LIST (enclosing_type))
6976 import = TYPE_IMPORT_LIST (enclosing_type);
6978 import = ctxp->import_list;
6982 if (TREE_VALUE (import) == TYPE_NAME (class_type))
6984 TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
6985 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
6988 import = TREE_CHAIN (import);
6993 note_possible_classname (const char *name, int len)
6996 if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
6998 else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
7002 node = ident_subst (name, len, "", '/', '.', "");
7003 IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
7004 QUALIFIED_P (node) = strchr (name, '/') ? 1 : 0;
7008 /* Read a import directory, gathering potential match for further type
7009 references. Indifferently reads a filesystem or a ZIP archive
7013 read_import_dir (tree wfl)
7015 tree package_id = EXPR_WFL_NODE (wfl);
7016 const char *package_name = IDENTIFIER_POINTER (package_id);
7017 int package_length = IDENTIFIER_LENGTH (package_id);
7019 JCF *saved_jcf = current_jcf;
7024 struct buffer filename[1];
7026 if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
7028 IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
7030 BUFFER_INIT (filename);
7031 buffer_grow (filename, package_length + 100);
7033 for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
7035 const char *entry_name = jcf_path_name (entry);
7036 int entry_length = strlen (entry_name);
7037 if (jcf_path_is_zipfile (entry))
7040 buffer_grow (filename, entry_length);
7041 memcpy (filename->data, entry_name, entry_length - 1);
7042 filename->data[entry_length-1] = '\0';
7043 zipf = opendir_in_zip ((const char *) filename->data, jcf_path_is_system (entry));
7045 error ("malformed .zip archive in CLASSPATH: %s", entry_name);
7048 ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
7049 BUFFER_RESET (filename);
7050 for (k = 0; k < package_length; k++)
7052 char ch = package_name[k];
7053 *filename->ptr++ = ch == '.' ? '/' : ch;
7055 *filename->ptr++ = '/';
7057 for (k = 0; k < zipf->count; k++, zipd = ZIPDIR_NEXT (zipd))
7059 const char *current_entry = ZIPDIR_FILENAME (zipd);
7060 int current_entry_len = zipd->filename_length;
7062 if (current_entry_len >= BUFFER_LENGTH (filename)
7063 && strncmp ((const char *) filename->data, current_entry,
7064 BUFFER_LENGTH (filename)) != 0)
7066 found |= note_possible_classname (current_entry,
7073 BUFFER_RESET (filename);
7074 buffer_grow (filename, entry_length + package_length + 4);
7075 strcpy ((char *) filename->data, entry_name);
7076 filename->ptr = filename->data + entry_length;
7077 for (k = 0; k < package_length; k++)
7079 char ch = package_name[k];
7080 *filename->ptr++ = ch == '.' ? '/' : ch;
7082 *filename->ptr = '\0';
7084 dirp = opendir ((const char *) filename->data);
7087 *filename->ptr++ = '/';
7092 struct dirent *direntp = readdir (dirp);
7095 d_name = direntp->d_name;
7096 len = strlen (direntp->d_name);
7097 buffer_grow (filename, len+1);
7098 strcpy ((char *) filename->ptr, d_name);
7099 found |= note_possible_classname ((const char *) filename->data + entry_length,
7100 package_length+len+1);
7107 free (filename->data);
7109 /* Here we should have a unified way of retrieving an entry, to be
7113 static int first = 1;
7116 error ("Can't find default package %qs. Check the CLASSPATH environment variable and the access to the archives", package_name);
7121 parse_error_context (wfl, "Package %qs not found in import",
7123 current_jcf = saved_jcf;
7126 current_jcf = saved_jcf;
7129 /* Possibly find a type in the import on demands specified
7130 types. Returns 1 if an error occurred, 0 otherwise. Run through the
7131 entire list, to detected potential double definitions. */
7134 find_in_imports_on_demand (tree enclosing_type, tree class_type)
7136 tree class_type_name = TYPE_NAME (class_type);
7137 tree cl = NULL_TREE;
7138 int seen_once = -1; /* -1 when not set, 1 if seen once, >1 otherwise. */
7139 int to_return = -1; /* -1 when not set, 0 or 1 otherwise */
7143 if (enclosing_type && TYPE_IMPORT_DEMAND_LIST (enclosing_type))
7144 import = TYPE_IMPORT_DEMAND_LIST (enclosing_type);
7146 import = ctxp->import_demand_list;
7148 for (; import; import = TREE_CHAIN (import))
7150 location_t saved_location = input_location;
7152 const char *id_name;
7153 tree decl, type_name_copy;
7155 obstack_grow (&temporary_obstack,
7156 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
7157 IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
7158 obstack_1grow (&temporary_obstack, '.');
7159 obstack_grow0 (&temporary_obstack,
7160 IDENTIFIER_POINTER (class_type_name),
7161 IDENTIFIER_LENGTH (class_type_name));
7162 id_name = obstack_finish (&temporary_obstack);
7164 if (! (node = maybe_get_identifier (id_name)))
7167 /* Setup input_line so that it refers to the line of the import (in
7168 case we parse a class file and encounter errors */
7169 #ifdef USE_MAPPED_LOCATION
7170 input_location = EXPR_LOCATION (TREE_PURPOSE (import));
7172 input_line = EXPR_WFL_LINENO (TREE_PURPOSE (import));
7175 type_name_copy = TYPE_NAME (class_type);
7176 TYPE_NAME (class_type) = node;
7177 QUALIFIED_P (node) = 1;
7178 decl = IDENTIFIER_CLASS_VALUE (node);
7180 /* If there is no DECL set for the class or if the class isn't
7181 loaded and not seen in source yet, then load */
7182 if (!decl || ! CLASS_LOADED_P (TREE_TYPE (decl)))
7184 load_class (node, 0);
7185 decl = IDENTIFIER_CLASS_VALUE (node);
7187 if (decl && ! INNER_CLASS_P (TREE_TYPE (decl)))
7188 access_check = check_pkg_class_access (node, TREE_PURPOSE (import),
7191 /* 6.6.1: Inner classes are subject to member access rules. */
7194 input_location = saved_location;
7196 /* If the loaded class is not accessible or couldn't be loaded,
7197 we restore the original TYPE_NAME and process the next
7199 if (access_check || !decl)
7201 TYPE_NAME (class_type) = type_name_copy;
7205 /* If the loaded class is accessible, we keep a tab on it to
7206 detect and report multiple inclusions. */
7207 if (IS_A_CLASSFILE_NAME (node))
7211 cl = TREE_PURPOSE (import);
7214 else if (seen_once >= 0)
7216 tree location = (cl ? cl : TREE_PURPOSE (import));
7217 tree package = (cl ? EXPR_WFL_NODE (cl) :
7218 EXPR_WFL_NODE (TREE_PURPOSE (import)));
7222 "Type %qs also potentially defined in package %qs",
7223 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
7224 IDENTIFIER_POINTER (package));
7227 to_return = access_check;
7233 return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
7237 resolve_package (tree pkg, tree *next, tree *type_name)
7240 tree decl = NULL_TREE;
7241 *type_name = NULL_TREE;
7243 /* The trick is to determine when the package name stops and were
7244 the name of something contained in the package starts. Then we
7245 return a fully qualified name of what we want to get. */
7247 *next = EXPR_WFL_QUALIFICATION (pkg);
7249 /* Try to progressively construct a type name */
7250 if (TREE_CODE (pkg) == EXPR_WITH_FILE_LOCATION)
7251 for (current = EXPR_WFL_QUALIFICATION (pkg);
7252 current; current = TREE_CHAIN (current))
7254 /* If we don't have what we're expecting, exit now. TYPE_NAME
7255 will be null and the error caught later. */
7256 if (TREE_CODE (QUAL_WFL (current)) != EXPR_WITH_FILE_LOCATION)
7259 merge_qualified_name (*type_name, EXPR_WFL_NODE (QUAL_WFL (current)));
7260 if ((decl = resolve_no_layout (*type_name, NULL_TREE)))
7262 /* resolve_package should be used in a loop, hence we
7263 point at this one to naturally process the next one at
7264 the next iteration. */
7272 /* Check accessibility of inner class DECL, from the context ENCLOSING_DECL,
7273 according to member access rules. */
7276 inner_class_accessible (tree decl, tree enclosing_decl)
7278 tree enclosing_decl_type;
7280 enclosing_decl_type = TREE_TYPE (enclosing_decl);
7282 if (CLASS_PRIVATE (decl))
7284 /* Access is permitted only within the body of the top-level
7285 class in which DECL is declared. */
7286 tree top_level = decl;
7287 while (DECL_CONTEXT (top_level))
7288 top_level = DECL_CONTEXT (top_level);
7289 while (DECL_CONTEXT (enclosing_decl))
7290 enclosing_decl = DECL_CONTEXT (enclosing_decl);
7291 if (top_level == enclosing_decl)
7294 else if (CLASS_PROTECTED (decl))
7297 /* Access is permitted from within the same package... */
7298 if (in_same_package (decl, enclosing_decl))
7301 /* ... or from within the body of a subtype of the context in which
7302 DECL is declared. */
7303 decl_context = DECL_CONTEXT (decl);
7304 while (enclosing_decl)
7306 if (CLASS_INTERFACE (decl))
7308 if (interface_of_p (TREE_TYPE (decl_context),
7309 enclosing_decl_type))
7314 /* Eww. The order of the arguments is different!! */
7315 if (inherits_from_p (enclosing_decl_type,
7316 TREE_TYPE (decl_context)))
7319 enclosing_decl = DECL_CONTEXT (enclosing_decl);
7322 else if (! CLASS_PUBLIC (decl))
7324 /* Access is permitted only from within the same package as DECL. */
7325 if (in_same_package (decl, enclosing_decl))
7329 /* Class is public. */
7335 /* Check accessibility of inner classes according to member access rules.
7336 DECL is the inner class, ENCLOSING_DECL is the class from which the
7337 access is being attempted. */
7340 check_inner_class_access (tree decl, tree enclosing_decl, tree cl)
7344 /* We don't issue an error message when CL is null. CL can be null
7345 as a result of processing a JDEP crafted by source_start_java_method
7346 for the purpose of patching its parm decl. But the error would
7347 have been already trapped when fixing the method's signature.
7348 DECL can also be NULL in case of earlier errors. */
7352 if (inner_class_accessible (decl, enclosing_decl))
7355 if (CLASS_PRIVATE (decl))
7357 else if (CLASS_PROTECTED (decl))
7358 access = "protected";
7360 access = "non-public";
7362 parse_error_context (cl, "Nested %s %s is %s; cannot be accessed from here",
7363 (CLASS_INTERFACE (decl) ? "interface" : "class"),
7364 lang_printable_name (decl, 2), access);
7367 /* Accessibility check for top-level classes. If CLASS_NAME is in a
7368 foreign package, it must be PUBLIC. Return 0 if no access
7369 violations were found, 1 otherwise. If VERBOSE is true and an error
7370 was found, it is reported and accounted for. If CL is NULL then
7371 look it up with THIS_DECL. */
7374 check_pkg_class_access (tree class_name, tree cl, bool verbose, tree this_decl)
7378 if (!IDENTIFIER_CLASS_VALUE (class_name))
7381 if (!(type = TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_name))))
7384 if (!CLASS_PUBLIC (TYPE_NAME (type)))
7386 /* Access to a private class within the same package is
7389 split_qualified_name (&l, &r, class_name);
7390 if (!QUALIFIED_P (class_name) && !ctxp->package)
7391 /* Both in the empty package. */
7393 if (l == ctxp->package)
7394 /* Both in the same package. */
7399 (cl == NULL ? lookup_cl (this_decl): cl,
7400 "Can't access %s %qs. Only public classes and interfaces in other packages can be accessed",
7401 (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
7402 IDENTIFIER_POINTER (class_name));
7408 /* Local variable declaration. */
7411 declare_local_variables (int modifier, tree type, tree vlist)
7413 tree decl, current, saved_type;
7414 tree type_wfl = NULL_TREE;
7418 /* Push a new block if statements were seen between the last time we
7419 pushed a block and now. Keep a count of blocks to close */
7420 if (BLOCK_EXPR_BODY (GET_CURRENT_BLOCK (current_function_decl)))
7422 tree b = enter_block ();
7423 BLOCK_IS_IMPLICIT (b) = 1;
7429 for (i = 0; i < ARRAY_SIZE (ctxp->modifier_ctx); i++)
7430 if (1 << i & modifier)
7432 if (modifier == ACC_FINAL)
7437 (ctxp->modifier_ctx [i],
7438 "Only %<final%> is allowed as a local variables modifier");
7443 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
7444 hold the TYPE value if a new incomplete has to be created (as
7445 opposed to being found already existing and reused). */
7446 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
7448 /* If TYPE is fully resolved and we don't have a reference, make one */
7449 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
7451 /* Go through all the declared variables */
7452 for (current = vlist, saved_type = type; current;
7453 current = TREE_CHAIN (current), type = saved_type)
7455 tree other, real_type;
7456 tree wfl = TREE_PURPOSE (current);
7457 tree name = EXPR_WFL_NODE (wfl);
7458 tree init = TREE_VALUE (current);
7460 /* Process NAME, as it may specify extra dimension(s) for it */
7461 type = build_array_from_name (type, type_wfl, name, &name);
7463 /* Variable redefinition check */
7464 if ((other = lookup_name_in_blocks (name)))
7466 variable_redefinition_error (wfl, name, TREE_TYPE (other),
7467 DECL_SOURCE_LINE (other));
7471 /* Type adjustment. We may have just readjusted TYPE because
7472 the variable specified more dimensions. Make sure we have
7473 a reference if we can and don't have one already. */
7474 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
7476 real_type = GET_REAL_TYPE (type);
7477 /* Never layout this decl. This will be done when its scope
7479 decl = build_decl (VAR_DECL, name, real_type);
7480 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
7481 DECL_FINAL (decl) = final_p;
7482 BLOCK_CHAIN_DECL (decl);
7484 /* Don't try to use an INIT statement when an error was found */
7485 if (init && java_error_count)
7488 /* Remember it if this is an initialized-upon-declaration final
7490 if (init && final_p)
7492 DECL_LOCAL_FINAL_IUD (decl) = 1;
7495 /* Add the initialization function to the current function's code */
7498 /* Name might have been readjusted */
7499 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = name;
7500 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
7501 java_method_add_stmt (current_function_decl,
7502 build_debugable_stmt (EXPR_WFL_LINECOL (init),
7506 /* Setup dependency the type of the decl */
7510 register_incomplete_type (JDEP_VARIABLE, type_wfl, decl, type);
7511 dep = CLASSD_LAST (ctxp->classd_list);
7512 JDEP_GET_PATCH (dep) = &TREE_TYPE (decl);
7515 SOURCE_FRONTEND_DEBUG (("Defined locals"));
7518 /* Called during parsing. Build decls from argument list. */
7521 source_start_java_method (tree fndecl)
7530 current_function_decl = fndecl;
7532 /* New scope for the function */
7534 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
7535 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
7537 tree type = TREE_VALUE (tem);
7538 tree name = TREE_PURPOSE (tem);
7540 /* If type is incomplete. Create an incomplete decl and ask for
7541 the decl to be patched later */
7542 if (INCOMPLETE_TYPE_P (type))
7545 tree real_type = GET_REAL_TYPE (type);
7546 parm_decl = build_decl (PARM_DECL, name, real_type);
7547 type = obtain_incomplete_type (type);
7548 register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
7549 jdep = CLASSD_LAST (ctxp->classd_list);
7550 JDEP_MISC (jdep) = name;
7551 JDEP_GET_PATCH (jdep) = &TREE_TYPE (parm_decl);
7554 parm_decl = build_decl (PARM_DECL, name, type);
7556 /* Remember if a local variable was declared final (via its
7557 TREE_LIST of type/name.) Set DECL_FINAL accordingly. */
7558 if (ARG_FINAL_P (tem))
7560 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (parm_decl);
7561 DECL_FINAL (parm_decl) = 1;
7564 BLOCK_CHAIN_DECL (parm_decl);
7566 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
7567 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) =
7569 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
7570 DECL_MAX_LOCALS (current_function_decl) = i;
7573 /* Called during parsing. Creates an artificial method declaration. */
7576 create_artificial_method (tree class, int flags, tree type,
7577 tree name, tree args)
7580 location_t save_location = input_location;
7582 input_location = DECL_SOURCE_LOCATION (TYPE_NAME (class));
7583 mdecl = make_node (FUNCTION_TYPE);
7584 TREE_TYPE (mdecl) = type;
7585 TYPE_ARG_TYPES (mdecl) = args;
7586 /* We used to compute the signature of MDECL here and then use
7587 add_method(), but that failed because our caller might modify
7588 the type of the returned method, which trashes the cache in
7589 get_type_from_signature(). */
7590 mdecl = add_method_1 (class, flags, name, mdecl);
7591 input_location = save_location;
7592 DECL_ARTIFICIAL (mdecl) = 1;
7596 /* Starts the body if an artificial method. */
7599 start_artificial_method_body (tree mdecl)
7601 #ifdef USE_MAPPED_LOCATION
7602 DECL_SOURCE_LOCATION (mdecl) = ctxp->file_start_location;
7603 DECL_FUNCTION_LAST_LINE (mdecl) = ctxp->file_start_location;
7605 DECL_SOURCE_LINE (mdecl) = 1;
7606 DECL_FUNCTION_LAST_LINE (mdecl) = 1;
7608 source_start_java_method (mdecl);
7613 end_artificial_method_body (tree mdecl)
7615 /* exit_block modifies DECL_FUNCTION_BODY (current_function_decl).
7616 It has to be evaluated first. (if mdecl is current_function_decl,
7617 we have an undefined behavior if no temporary variable is used.) */
7618 tree b = exit_block ();
7619 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = b;
7623 /* Dump a tree of some kind. This is a convenience wrapper for the
7624 dump_* functions in tree-dump.c. */
7626 dump_java_tree (enum tree_dump_index phase, tree t)
7631 stream = dump_begin (phase, &flags);
7635 dump_node (t, flags, stream);
7636 dump_end (phase, stream);
7640 /* Terminate a function and expand its body. */
7643 source_end_java_method (void)
7645 tree fndecl = current_function_decl;
7650 java_parser_context_save_global ();
7651 #ifdef USE_MAPPED_LOCATION
7652 input_location = ctxp->last_ccb_indent1;
7654 input_line = ctxp->last_ccb_indent1;
7657 /* Turn function bodies with only a NOP expr null, so they don't get
7658 generated at all and we won't get warnings when using the -W
7660 if (IS_EMPTY_STMT (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))))
7661 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) = NULL_TREE;
7663 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))
7664 && ! flag_emit_class_files)
7665 finish_method (fndecl);
7667 current_function_decl = NULL_TREE;
7668 java_parser_context_restore_global ();
7669 current_function_decl = NULL_TREE;
7672 /* Record EXPR in the current function block. Complements compound
7673 expression second operand if necessary. */
7676 java_method_add_stmt (tree fndecl, tree expr)
7678 if (!GET_CURRENT_BLOCK (fndecl))
7680 return add_stmt_to_block (GET_CURRENT_BLOCK (fndecl), NULL_TREE, expr);
7684 add_stmt_to_block (tree b, tree type, tree stmt)
7686 tree body = BLOCK_EXPR_BODY (b), c;
7688 if (java_error_count)
7691 if ((c = add_stmt_to_compound (body, type, stmt)) == body)
7694 BLOCK_EXPR_BODY (b) = c;
7695 TREE_SIDE_EFFECTS (c) = 1;
7699 /* Lays out the methods for the classes seen so far. */
7702 java_layout_seen_class_methods (void)
7704 tree previous_list = all_class_list;
7705 tree end = NULL_TREE;
7710 for (current = previous_list;
7711 current != end; current = TREE_CHAIN (current))
7713 tree decl = TREE_VALUE (current);
7714 tree cls = TREE_TYPE (decl);
7716 input_location = DECL_SOURCE_LOCATION (decl);
7718 if (! CLASS_LOADED_P (cls))
7719 load_class (cls, 0);
7721 layout_class_methods (cls);
7724 /* Note that new classes might have been added while laying out
7725 methods, changing the value of all_class_list. */
7727 if (previous_list != all_class_list)
7729 end = previous_list;
7730 previous_list = all_class_list;
7737 static GTY(()) tree stop_reordering;
7739 java_reorder_fields (void)
7743 for (current = gclass_list; current; current = TREE_CHAIN (current))
7745 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
7747 if (current_class == stop_reordering)
7750 /* Reverse the fields, but leave the dummy field in front.
7751 Fields are already ordered for Object and Class */
7752 if (TYPE_FIELDS (current_class) && current_class != object_type_node
7753 && current_class != class_type_node)
7755 /* If the dummy field is there, reverse the right fields and
7756 just layout the type for proper fields offset */
7757 if (!DECL_NAME (TYPE_FIELDS (current_class)))
7759 tree fields = TYPE_FIELDS (current_class);
7760 TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
7761 TYPE_SIZE (current_class) = NULL_TREE;
7763 /* We don't have a dummy field, we need to layout the class,
7764 after having reversed the fields */
7767 TYPE_FIELDS (current_class) =
7768 nreverse (TYPE_FIELDS (current_class));
7769 TYPE_SIZE (current_class) = NULL_TREE;
7773 /* There are cases were gclass_list will be empty. */
7775 stop_reordering = TREE_TYPE (TREE_VALUE (gclass_list));
7778 /* Layout the methods of all classes loaded in one way or another.
7779 Check methods of source parsed classes. Then reorder the
7780 fields and layout the classes or the type of all source parsed
7784 java_layout_classes (void)
7787 int save_error_count = java_error_count;
7789 /* Layout the methods of all classes seen so far */
7790 java_layout_seen_class_methods ();
7791 java_parse_abort_on_error ();
7792 all_class_list = NULL_TREE;
7794 /* Then check the methods of all parsed classes */
7795 for (current = gclass_list; current; current = TREE_CHAIN (current))
7796 if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
7797 java_check_methods (TREE_VALUE (current));
7798 java_parse_abort_on_error ();
7800 for (current = gclass_list; current; current = TREE_CHAIN (current))
7802 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
7803 layout_class (current_class);
7805 /* Error reported by the caller */
7806 if (java_error_count)
7810 /* We might have reloaded classes durign the process of laying out
7811 classes for code generation. We must layout the methods of those
7812 late additions, as constructor checks might use them */
7813 java_layout_seen_class_methods ();
7814 java_parse_abort_on_error ();
7817 /* Expand methods in the current set of classes remembered for
7821 java_complete_expand_classes (void)
7825 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
7826 if (!INNER_CLASS_DECL_P (current))
7827 java_complete_expand_class (current);
7830 /* Expand the methods found in OUTER, starting first by OUTER's inner
7834 java_complete_expand_class (tree outer)
7838 /* We need to go after all inner classes and start expanding them,
7839 starting with most nested ones. We have to do that because nested
7840 classes might add functions to outer classes */
7842 for (inner_list = DECL_INNER_CLASS_LIST (outer);
7843 inner_list; inner_list = TREE_CHAIN (inner_list))
7844 java_complete_expand_class (TREE_PURPOSE (inner_list));
7846 java_complete_expand_methods (outer);
7849 /* Expand methods registered in CLASS_DECL. The general idea is that
7850 we expand regular methods first. This allows us get an estimate on
7851 how outer context local alias fields are really used so we can add
7852 to the constructor just enough code to initialize them properly (it
7853 also lets us generate finit$ correctly.) Then we expand the
7854 constructors and then <clinit>. */
7857 java_complete_expand_methods (tree class_decl)
7859 tree clinit, decl, first_decl;
7861 output_class = current_class = TREE_TYPE (class_decl);
7863 /* Pre-expand <clinit> to figure whether we really need it or
7864 not. If we do need it, we pre-expand the static fields so they're
7865 ready to be used somewhere else. <clinit> will be fully expanded
7866 after we processed the constructors. */
7867 first_decl = TYPE_METHODS (current_class);
7868 clinit = maybe_generate_pre_expand_clinit (current_class);
7870 /* Then generate finit$ (if we need to) because constructors will
7872 if (TYPE_FINIT_STMT_LIST (current_class))
7873 java_complete_expand_method (generate_finit (current_class));
7875 /* Then generate instinit$ (if we need to) because constructors will
7877 if (TYPE_II_STMT_LIST (current_class))
7878 java_complete_expand_method (generate_instinit (current_class));
7880 /* Now do the constructors */
7881 for (decl = first_decl ; !java_error_count && decl; decl = TREE_CHAIN (decl))
7883 if (!DECL_CONSTRUCTOR_P (decl))
7885 java_complete_expand_method (decl);
7888 /* First, do the ordinary methods. */
7889 for (decl = first_decl; decl; decl = TREE_CHAIN (decl))
7891 /* Ctors aren't part of this batch. */
7892 if (DECL_CONSTRUCTOR_P (decl) || DECL_CLINIT_P (decl))
7895 /* Skip abstract or native methods -- but do handle native
7896 methods when generating JNI stubs. */
7897 if (METHOD_ABSTRACT (decl) || (! flag_jni && METHOD_NATIVE (decl)))
7899 DECL_FUNCTION_BODY (decl) = NULL_TREE;
7903 if (METHOD_NATIVE (decl))
7906 current_function_decl = decl;
7907 body = build_jni_stub (decl);
7908 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl)) = body;
7911 java_complete_expand_method (decl);
7914 /* If there is indeed a <clinit>, fully expand it now */
7917 /* Prevent the use of `this' inside <clinit> */
7918 ctxp->explicit_constructor_p = 1;
7919 java_complete_expand_method (clinit);
7920 ctxp->explicit_constructor_p = 0;
7923 /* We might have generated a class$ that we now want to expand */
7924 if (TYPE_DOT_CLASS (current_class))
7925 java_complete_expand_method (TYPE_DOT_CLASS (current_class));
7927 /* Now verify constructor circularity (stop after the first one we
7929 if (!CLASS_INTERFACE (class_decl))
7930 for (decl = TYPE_METHODS (current_class); decl; decl = TREE_CHAIN (decl))
7931 if (DECL_CONSTRUCTOR_P (decl)
7932 && verify_constructor_circularity (decl, decl))
7936 /* Attempt to create <clinit>. Pre-expand static fields so they can be
7937 safely used in some other methods/constructors. */
7940 maybe_generate_pre_expand_clinit (tree class_type)
7942 tree current, mdecl;
7944 if (!TYPE_CLINIT_STMT_LIST (class_type))
7947 /* Go through all static fields and pre expand them */
7948 for (current = TYPE_FIELDS (class_type); current;
7949 current = TREE_CHAIN (current))
7950 if (FIELD_STATIC (current))
7951 build_field_ref (NULL_TREE, class_type, DECL_NAME (current));
7953 /* Then build the <clinit> method */
7954 mdecl = create_artificial_method (class_type, ACC_STATIC, void_type_node,
7955 clinit_identifier_node, end_params_node);
7956 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
7958 start_artificial_method_body (mdecl);
7960 /* We process the list of assignment we produced as the result of
7961 the declaration of initialized static field and add them as
7962 statement to the <clinit> method. */
7963 for (current = TYPE_CLINIT_STMT_LIST (class_type); current;
7964 current = TREE_CHAIN (current))
7966 tree stmt = current;
7967 /* We build the assignment expression that will initialize the
7968 field to its value. There are strict rules on static
7969 initializers (8.5). FIXME */
7970 if (TREE_CODE (stmt) != BLOCK && !IS_EMPTY_STMT (stmt))
7971 stmt = build_debugable_stmt (EXPR_WFL_LINECOL (stmt), stmt);
7972 java_method_add_stmt (mdecl, stmt);
7975 end_artificial_method_body (mdecl);
7977 /* Now we want to place <clinit> as the last method (because we need
7978 it at least for interface so that it doesn't interfere with the
7979 dispatch table based lookup. */
7980 if (TREE_CHAIN (TYPE_METHODS (class_type)))
7982 current = TREE_CHAIN (TYPE_METHODS (class_type));
7983 TYPE_METHODS (class_type) = current;
7985 while (TREE_CHAIN (current))
7986 current = TREE_CHAIN (current);
7988 TREE_CHAIN (current) = mdecl;
7989 TREE_CHAIN (mdecl) = NULL_TREE;
7995 /* Analyzes a method body and look for something that isn't a
7996 MODIFY_EXPR with a constant value. */
7999 analyze_clinit_body (tree this_class, tree bbody)
8002 switch (TREE_CODE (bbody))
8005 bbody = BLOCK_EXPR_BODY (bbody);
8008 case EXPR_WITH_FILE_LOCATION:
8009 bbody = EXPR_WFL_NODE (bbody);
8013 if (analyze_clinit_body (this_class, TREE_OPERAND (bbody, 0)))
8015 bbody = TREE_OPERAND (bbody, 1);
8019 /* If we're generating to class file and we're dealing with an
8020 array initialization, we return 1 to keep <clinit> */
8021 if (TREE_CODE (TREE_OPERAND (bbody, 1)) == NEW_ARRAY_INIT
8022 && flag_emit_class_files)
8025 /* There are a few cases where we're required to keep
8027 - If this is an assignment whose operand is not constant,
8028 - If this is an assignment to a non-initialized field,
8029 - If this field is not a member of the current class.
8031 return (! TREE_CONSTANT (TREE_OPERAND (bbody, 1))
8032 || ! DECL_INITIAL (TREE_OPERAND (bbody, 0))
8033 || DECL_CONTEXT (TREE_OPERAND (bbody, 0)) != this_class);
8042 /* See whether we could get rid of <clinit>. Criteria are: all static
8043 final fields have constant initial values and the body of <clinit>
8044 is empty. Return 1 if <clinit> was discarded, 0 otherwise. */
8047 maybe_yank_clinit (tree mdecl)
8052 if (!DECL_CLINIT_P (mdecl))
8055 /* If the body isn't empty, then we keep <clinit>. Note that if
8056 we're emitting classfiles, this isn't enough not to rule it
8058 fbody = DECL_FUNCTION_BODY (mdecl);
8059 bbody = BLOCK_EXPR_BODY (fbody);
8060 if (bbody && bbody != error_mark_node)
8061 bbody = BLOCK_EXPR_BODY (bbody);
8064 if (bbody && ! flag_emit_class_files && !IS_EMPTY_STMT (bbody))
8067 type = DECL_CONTEXT (mdecl);
8068 current = TYPE_FIELDS (type);
8070 for (current = (current ? TREE_CHAIN (current) : current);
8071 current; current = TREE_CHAIN (current))
8075 /* We're not interested in non-static fields. */
8076 if (!FIELD_STATIC (current))
8079 /* Nor in fields without initializers. */
8080 f_init = DECL_INITIAL (current);
8081 if (f_init == NULL_TREE)
8084 /* Anything that isn't String or a basic type is ruled out -- or
8085 if we know how to deal with it (when doing things natively) we
8086 should generated an empty <clinit> so that SUID are computed
8088 if (! JSTRING_TYPE_P (TREE_TYPE (current))
8089 && ! JNUMERIC_TYPE_P (TREE_TYPE (current)))
8092 if (! FIELD_FINAL (current) || ! TREE_CONSTANT (f_init))
8096 /* Now we analyze the method body and look for something that
8097 isn't a MODIFY_EXPR */
8098 if (bbody && !IS_EMPTY_STMT (bbody) && analyze_clinit_body (type, bbody))
8101 /* Get rid of <clinit> in the class' list of methods */
8102 if (TYPE_METHODS (type) == mdecl)
8103 TYPE_METHODS (type) = TREE_CHAIN (mdecl);
8105 for (current = TYPE_METHODS (type); current;
8106 current = TREE_CHAIN (current))
8107 if (TREE_CHAIN (current) == mdecl)
8109 TREE_CHAIN (current) = TREE_CHAIN (mdecl);
8116 /* Install the argument from MDECL. Suitable to completion and
8117 expansion of mdecl's body. */
8120 start_complete_expand_method (tree mdecl)
8124 pushlevel (1); /* Prepare for a parameter push */
8125 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
8126 DECL_ARGUMENTS (mdecl) = tem;
8128 for (; tem; tem = TREE_CHAIN (tem))
8130 /* TREE_CHAIN (tem) will change after pushdecl. */
8131 tree next = TREE_CHAIN (tem);
8132 tree type = TREE_TYPE (tem);
8133 if (targetm.calls.promote_prototypes (type)
8134 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
8135 && INTEGRAL_TYPE_P (type))
8136 type = integer_type_node;
8137 DECL_ARG_TYPE (tem) = type;
8138 layout_decl (tem, 0);
8140 /* Re-install the next so that the list is kept and the loop
8142 TREE_CHAIN (tem) = next;
8144 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
8145 input_location = DECL_SOURCE_LOCATION (mdecl);
8146 build_result_decl (mdecl);
8150 /* Complete and expand a method. */
8153 java_complete_expand_method (tree mdecl)
8155 tree fbody, block_body, exception_copy;
8157 current_function_decl = mdecl;
8158 /* Fix constructors before expanding them */
8159 if (DECL_CONSTRUCTOR_P (mdecl))
8160 fix_constructors (mdecl);
8162 /* Expand functions that have a body */
8163 if (!DECL_FUNCTION_BODY (mdecl))
8166 fbody = DECL_FUNCTION_BODY (mdecl);
8167 block_body = BLOCK_EXPR_BODY (fbody);
8168 exception_copy = NULL_TREE;
8170 current_function_decl = mdecl;
8173 fprintf (stderr, " [%s.",
8174 lang_printable_name (DECL_CONTEXT (mdecl), 0));
8175 announce_function (mdecl);
8177 fprintf (stderr, "]");
8179 /* Prepare the function for tree completion */
8180 start_complete_expand_method (mdecl);
8182 /* Install the current this */
8183 current_this = (!METHOD_STATIC (mdecl) ?
8184 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl)) : NULL_TREE);
8186 /* Install exceptions thrown with `throws' */
8187 PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
8189 if (block_body != NULL_TREE)
8191 block_body = java_complete_tree (block_body);
8193 /* Before we check initialization, attached all class initialization
8194 variable to the block_body */
8195 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (mdecl),
8196 attach_init_test_initialization_flags, block_body);
8198 if (! METHOD_NATIVE (mdecl))
8200 check_for_initialization (block_body, mdecl);
8202 /* Go through all the flags marking the initialization of
8203 static variables and see whether they're definitively
8204 assigned, in which case the type is remembered as
8205 definitively initialized in MDECL. */
8206 if (STATIC_CLASS_INIT_OPT_P ())
8208 /* Always register the context as properly initialized in
8209 MDECL. This used with caution helps removing extra
8210 initialization of self. */
8211 if (METHOD_STATIC (mdecl))
8214 (DECL_FUNCTION_INITIALIZED_CLASS_TABLE (mdecl),
8215 DECL_CONTEXT (mdecl), INSERT)) = DECL_CONTEXT (mdecl);
8219 ctxp->explicit_constructor_p = 0;
8222 BLOCK_EXPR_BODY (fbody) = block_body;
8224 /* If we saw a return but couldn't evaluate it properly, we'll have
8225 an error_mark_node here. */
8226 if (block_body != error_mark_node
8227 && (block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
8228 && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE)
8229 missing_return_error (current_function_decl);
8231 /* See if we can get rid of <clinit> if MDECL happens to be <clinit> */
8232 maybe_yank_clinit (mdecl);
8234 /* Pop the current level, with special measures if we found errors. */
8235 if (java_error_count)
8236 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
8239 /* Pop the exceptions and sanity check */
8241 if (currently_caught_type_list)
8245 /* For with each class for which there's code to generate. */
8248 java_expand_method_bodies (tree class)
8251 for (decl = TYPE_METHODS (class); decl; decl = TREE_CHAIN (decl))
8255 if (! DECL_FUNCTION_BODY (decl))
8258 current_function_decl = decl;
8260 block = BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl));
8262 /* Save the function body for gimplify and inlining. */
8263 DECL_SAVED_TREE (decl) = block;
8265 /* It's time to assign the variable flagging static class
8266 initialization based on which classes invoked static methods
8267 are definitely initializing. This should be flagged. */
8268 if (STATIC_CLASS_INIT_OPT_P ())
8270 tree list = DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (decl);
8271 for (; list != NULL_TREE; list = TREE_CHAIN (list))
8273 /* Executed for each statement calling a static function.
8274 LIST is a TREE_LIST whose PURPOSE is the called function
8275 and VALUE is a compound whose second operand can be patched
8276 with static class initialization flag assignments. */
8278 tree called_method = TREE_PURPOSE (list);
8279 tree compound = TREE_VALUE (list);
8280 tree assignment_compound_list
8281 = build_tree_list (called_method, NULL);
8283 /* For each class definitely initialized in
8284 CALLED_METHOD, fill ASSIGNMENT_COMPOUND with
8285 assignment to the class initialization flag. */
8286 htab_traverse (DECL_FUNCTION_INITIALIZED_CLASS_TABLE (called_method),
8287 emit_test_initialization,
8288 assignment_compound_list);
8290 if (TREE_VALUE (assignment_compound_list))
8291 TREE_OPERAND (compound, 1)
8292 = TREE_VALUE (assignment_compound_list);
8296 /* Expand the function body. */
8297 source_end_java_method ();
8303 /* This section of the code deals with accessing enclosing context
8304 fields either directly by using the relevant access to this$<n> or
8305 by invoking an access method crafted for that purpose. */
8307 /* Build the necessary access across nested class boundaries.
8308 This routine could be optimized to cache previous result
8309 (decl, current_class and returned access). When an access method
8310 needs to be generated, it always takes the form of a read. It might
8311 be later turned into a write by calling nested_field_access_fix. */
8314 build_nested_field_access (tree id, tree decl)
8316 tree access = NULL_TREE;
8317 tree ctx = NULL_TREE;
8318 tree decl_ctx = DECL_CONTEXT (decl);
8319 bool is_static = FIELD_STATIC (decl);
8321 if (DECL_CONTEXT (TYPE_NAME (current_class)))
8322 ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
8324 /* For non-static fields, if the immediate enclosing context of the
8325 current class is the field decl's class or inherits from it,
8326 build the access as `this$<n>.<field>'. Note that we will break
8327 the `private' barrier if we're not emitting bytecodes. */
8330 && (ctx == decl_ctx || inherits_from_p (ctx, decl_ctx))
8331 && (!FIELD_PRIVATE (decl) || !flag_emit_class_files))
8333 tree thisn = build_current_thisn (current_class);
8334 access = make_qualified_primary (build_wfl_node (thisn),
8335 id, EXPR_WFL_LINECOL (id));
8337 /* Otherwise, generate and use accessor methods for the field as
8341 int lc = EXPR_WFL_LINECOL (id);
8343 /* Now we chain the required number of calls to the access$0 to
8344 get a hold to the enclosing instance we need for a non-static
8345 field, and then we build the field access. */
8347 access = build_access_to_thisn (current_class, decl_ctx, lc);
8349 /* If the field is private and we're generating bytecode, then
8350 we generate an access method. */
8351 if (FIELD_PRIVATE (decl) && flag_emit_class_files)
8353 tree name = build_nested_field_access_methods (decl);
8354 access = build_nested_field_access_expr (lc, decl_ctx,
8355 name, access, NULL_TREE);
8357 /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'
8358 for non-static fields.
8359 Once again we break the `private' access rule from a foreign
8363 tree class_name = DECL_NAME (TYPE_NAME (decl_ctx));
8365 = make_qualified_primary (build_wfl_node (class_name), id, lc);
8368 access = make_qualified_primary (access, id, lc);
8371 return resolve_expression_name (access, NULL);
8374 /* Return a nonzero value if DECL describes a field access across nested
8375 class boundaries. That is, DECL is in a class that either encloses,
8376 is enclosed by or shares a common enclosing class with, the class
8380 nested_field_access_p (tree type, tree decl)
8382 bool is_static = false;
8383 tree decl_type = DECL_CONTEXT (decl);
8384 tree type_root, decl_type_root;
8386 if (decl_type == type
8387 || (TREE_CODE (decl) != FIELD_DECL && TREE_CODE (decl) != VAR_DECL))
8390 if (!INNER_CLASS_TYPE_P (type)
8391 && !(TREE_CODE (decl_type) == RECORD_TYPE
8392 && INNER_CLASS_TYPE_P (decl_type)))
8395 is_static = FIELD_STATIC (decl);
8397 /* If TYPE extends the declaration context of the non-static
8398 field we're trying to access, then this isn't a nested field
8399 access we need to worry about. */
8400 if (!is_static && inherits_from_p (type, decl_type))
8403 for (type_root = type;
8404 DECL_CONTEXT (TYPE_NAME (type_root));
8405 type_root = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type_root))))
8407 if (type_root == decl_type)
8411 if (TREE_CODE (decl_type) == RECORD_TYPE
8412 && INNER_CLASS_TYPE_P (decl_type))
8414 for (decl_type_root = decl_type;
8415 DECL_CONTEXT (TYPE_NAME (decl_type_root));
8417 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (decl_type_root))))
8419 if (decl_type_root == type)
8424 decl_type_root = decl_type;
8426 if (type_root == decl_type_root)
8429 /* Before we give up, see whether it is a non-static field
8430 inherited from the enclosing context we are considering. */
8431 if (!DECL_CONTEXT (TYPE_NAME (type_root))
8433 && inherits_from_p (type_root, decl_type))
8439 /* Return a nonzero value if NODE represents a cross-nested-class
8440 access that has already been expanded. As a side effect, it returns
8441 the name of the field being accessed and the argument passed to the
8442 access function, suitable for a regeneration of the access method
8443 call if necessary. */
8446 nested_field_expanded_access_p (tree node, tree *name, tree *arg_type,
8451 if (TREE_CODE (node) != CALL_EXPR)
8454 /* Well, GCJ generates slightly different tree nodes when compiling
8455 to native or bytecodes. It's the case for function calls. */
8457 if (flag_emit_class_files
8458 && TREE_CODE (node) == CALL_EXPR
8459 && NESTED_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (TREE_OPERAND (node, 0))))
8461 else if (!flag_emit_class_files)
8463 node = TREE_OPERAND (node, 0);
8465 if (node && TREE_OPERAND (node, 0)
8466 && TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR)
8468 node = TREE_OPERAND (node, 0);
8469 if (TREE_OPERAND (node, 0)
8470 && TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL
8471 && (NESTED_FIELD_ACCESS_IDENTIFIER_P
8472 (DECL_NAME (TREE_OPERAND (node, 0)))))
8477 if (identified && name && arg_type && arg)
8479 tree argument = TREE_OPERAND (node, 1);
8480 *name = DECL_NAME (TREE_OPERAND (node, 0));
8482 /* The accessors for static fields do not take in a this$<n> argument,
8483 so we take the class name from the accessor's context instead. */
8486 *arg_type = TREE_TYPE (TREE_TYPE (TREE_VALUE (argument)));
8487 *arg = TREE_VALUE (argument);
8491 *arg_type = DECL_CONTEXT (TREE_OPERAND (node, 0));
8498 /* Detect in NODE cross-nested-class field read access and
8499 transform it into a write with RHS as an argument. This function
8500 is called from the java_complete_lhs when an assignment to a LHS can
8504 nested_field_access_fix (tree wfl, tree node, tree rhs)
8506 tree name, arg_type, arg;
8508 if (nested_field_expanded_access_p (node, &name, &arg_type, &arg))
8510 node = build_nested_field_access_expr (EXPR_WFL_LINECOL (wfl),
8511 arg_type, name, arg, rhs);
8512 return java_complete_tree (node);
8517 /* Construct the expression that calls an access method:
8518 <type>.access$<n>(<arg1> [, <arg2>]);
8520 ARG2 can be NULL and will be omitted in that case. It will denote a
8524 build_nested_field_access_expr (int lc, tree type, tree access_method_name,
8525 tree arg1, tree arg2)
8527 tree args, cn, access;
8530 args = build_tree_list (NULL_TREE, arg1);
8537 args = tree_cons (NULL_TREE, arg2, args);
8539 args = build_tree_list (NULL_TREE, arg2);
8543 = build_method_invocation (build_wfl_node (access_method_name), args);
8544 cn = build_wfl_node (DECL_NAME (TYPE_NAME (type)));
8546 return make_qualified_primary (cn, access, lc);
8549 /* Build the name of a synthetic accessor used to access class members
8550 across nested class boundaries. */
8553 build_new_access_id (void)
8555 static int access_n_counter = 1;
8558 sprintf (buffer, "access$%d", access_n_counter++);
8559 return get_identifier (buffer);
8562 /* Create the static access functions for the cross-nested-class field DECL.
8564 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$) {
8568 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$,
8569 TREE_TYPE (<field>) value$) {
8570 return inst$.field = value$;
8572 For static fields, these methods are generated without the instance
8574 We should have a usage flag on the DECL so we can lazily turn the ones
8575 we're using for code generation. FIXME.
8579 build_nested_field_access_methods (tree decl)
8581 tree id, args, stmt, mdecl, class_name = NULL_TREE;
8582 bool is_static = FIELD_STATIC (decl);
8584 if (FIELD_NESTED_ACCESS_P (decl))
8585 return FIELD_NESTED_ACCESS (decl);
8587 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
8589 /* Create the identifier and a function named after it. */
8590 id = build_new_access_id ();
8592 /* The identifier is marked as bearing the name of a generated write
8593 access function for outer field accessed from inner classes. */
8594 NESTED_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
8596 /* Create the read access. */
8599 args = build_tree_list (inst_id,
8600 build_pointer_type (DECL_CONTEXT (decl)));
8601 TREE_CHAIN (args) = end_params_node;
8602 stmt = make_qualified_primary (build_wfl_node (inst_id),
8603 build_wfl_node (DECL_NAME (decl)), 0);
8607 args = end_params_node;
8608 class_name = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
8609 stmt = make_qualified_primary (build_wfl_node (class_name),
8610 build_wfl_node (DECL_NAME (decl)), 0);
8612 stmt = build_return (0, stmt);
8613 mdecl = build_nested_field_access_method (DECL_CONTEXT (decl),
8614 TREE_TYPE (decl), id, args, stmt);
8615 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
8617 /* Create the write access method. No write access for final variable */
8618 if (!FIELD_FINAL (decl))
8622 args = build_tree_list (inst_id,
8623 build_pointer_type (DECL_CONTEXT (decl)));
8624 TREE_CHAIN (args) = build_tree_list (wpv_id, TREE_TYPE (decl));
8625 TREE_CHAIN (TREE_CHAIN (args)) = end_params_node;
8626 stmt = make_qualified_primary (build_wfl_node (inst_id),
8627 build_wfl_node (DECL_NAME (decl)),
8632 args = build_tree_list (wpv_id, TREE_TYPE (decl));
8633 TREE_CHAIN (args) = end_params_node;
8634 stmt = make_qualified_primary (build_wfl_node (class_name),
8635 build_wfl_node (DECL_NAME (decl)),
8638 stmt = build_return (0, build_assignment (ASSIGN_TK, 0, stmt,
8639 build_wfl_node (wpv_id)));
8640 mdecl = build_nested_field_access_method (DECL_CONTEXT (decl),
8641 TREE_TYPE (decl), id,
8644 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
8646 /* Return the access name */
8647 return FIELD_NESTED_ACCESS (decl) = id;
8650 /* Build a field access method NAME. */
8653 build_nested_field_access_method (tree class, tree type, tree name,
8654 tree args, tree body)
8656 tree saved_current_function_decl, mdecl;
8658 /* Create the method */
8659 mdecl = create_artificial_method (class, ACC_STATIC, type, name, args);
8660 fix_method_argument_names (args, mdecl);
8661 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8663 /* Attach the method body. */
8664 saved_current_function_decl = current_function_decl;
8665 start_artificial_method_body (mdecl);
8666 java_method_add_stmt (mdecl, body);
8667 end_artificial_method_body (mdecl);
8668 current_function_decl = saved_current_function_decl;
8674 /* This section deals with building access function necessary for
8675 certain kinds of method invocation from inner classes. */
8678 build_outer_method_access_method (tree decl)
8680 tree saved_current_function_decl, mdecl;
8681 tree args = NULL_TREE, call_args = NULL_TREE;
8682 tree carg, id, body, class;
8684 int parm_id_count = 0;
8686 /* Test this abort with an access to a private field */
8687 if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "access$"))
8690 /* Check the cache first */
8691 if (DECL_FUNCTION_INNER_ACCESS (decl))
8692 return DECL_FUNCTION_INNER_ACCESS (decl);
8694 class = DECL_CONTEXT (decl);
8696 /* Obtain an access identifier and mark it */
8697 id = build_new_access_id ();
8698 NESTED_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
8700 carg = TYPE_ARG_TYPES (TREE_TYPE (decl));
8701 /* Create the arguments, as much as the original */
8702 for (; carg && carg != end_params_node;
8703 carg = TREE_CHAIN (carg))
8705 sprintf (buffer, "write_parm_value$%d", parm_id_count++);
8706 args = chainon (args, build_tree_list (get_identifier (buffer),
8707 TREE_VALUE (carg)));
8709 args = chainon (args, end_params_node);
8711 /* Create the method */
8712 mdecl = create_artificial_method (class, ACC_STATIC,
8713 TREE_TYPE (TREE_TYPE (decl)), id, args);
8714 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8715 /* There is a potential bug here. We should be able to use
8716 fix_method_argument_names, but then arg names get mixed up and
8717 eventually a constructor will have its this$0 altered and the
8718 outer context won't be assignment properly. The testcase is
8720 TYPE_ARG_TYPES (TREE_TYPE (mdecl)) = args;
8722 /* Attach the method body. */
8723 saved_current_function_decl = current_function_decl;
8724 start_artificial_method_body (mdecl);
8726 /* The actual method invocation uses the same args. When invoking a
8727 static methods that way, we don't want to skip the first
8730 if (!METHOD_STATIC (decl))
8731 carg = TREE_CHAIN (carg);
8732 for (; carg && carg != end_params_node; carg = TREE_CHAIN (carg))
8733 call_args = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (carg)),
8736 body = build_method_invocation (build_wfl_node (DECL_NAME (decl)),
8738 if (!METHOD_STATIC (decl))
8739 body = make_qualified_primary (build_wfl_node (TREE_PURPOSE (args)),
8741 if (TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
8742 body = build_return (0, body);
8743 java_method_add_stmt (mdecl,body);
8744 end_artificial_method_body (mdecl);
8745 current_function_decl = saved_current_function_decl;
8747 /* Back tag the access function so it know what it accesses */
8748 DECL_FUNCTION_ACCESS_DECL (decl) = mdecl;
8750 /* Tag the current method so it knows it has an access generated */
8751 return DECL_FUNCTION_INNER_ACCESS (decl) = mdecl;
8755 /* This section of the code deals with building expressions to access
8756 the enclosing instance of an inner class. The enclosing instance is
8757 kept in a generated field called this$<n>, with <n> being the
8758 inner class nesting level (starting from 0.) */
8760 /* Build an access to a given this$<n>, always chaining access call to
8761 others. Access methods to this$<n> are build on the fly if
8762 necessary. This CAN'T be used to solely access this$<n-1> from
8763 this$<n> (which alway yield to special cases and optimization, see
8764 for example build_nested_field_access). */
8767 build_access_to_thisn (tree from, tree to, int lc)
8769 tree access = NULL_TREE;
8771 while (from != to && PURE_INNER_CLASS_TYPE_P (from))
8775 access = build_current_thisn (from);
8776 access = build_wfl_node (access);
8780 tree access0_wfl, cn;
8782 maybe_build_thisn_access_method (from);
8783 access0_wfl = build_wfl_node (access0_identifier_node);
8784 cn = build_wfl_node (DECL_NAME (TYPE_NAME (from)));
8785 EXPR_WFL_LINECOL (access0_wfl) = lc;
8786 access = build_tree_list (NULL_TREE, access);
8787 access = build_method_invocation (access0_wfl, access);
8788 access = make_qualified_primary (cn, access, lc);
8791 /* If FROM isn't an inner class, that's fine, we've done enough.
8792 What we're looking for can be accessed from there. */
8793 from = DECL_CONTEXT (TYPE_NAME (from));
8796 from = TREE_TYPE (from);
8801 /* Build an access function to the this$<n> local to TYPE. NULL_TREE
8802 is returned if nothing needs to be generated. Otherwise, the method
8803 generated and a method decl is returned.
8805 NOTE: These generated methods should be declared in a class file
8806 attribute so that they can't be referred to directly. */
8809 maybe_build_thisn_access_method (tree type)
8811 tree mdecl, args, stmt, rtype;
8812 tree saved_current_function_decl;
8814 /* If TYPE is a top-level class, no access method is required.
8815 If there already is such an access method, bail out. */
8816 if (CLASS_ACCESS0_GENERATED_P (type) || !PURE_INNER_CLASS_TYPE_P (type))
8819 /* We generate the method. The method looks like:
8820 static <outer_of_type> access$0 (<type> inst$) { return inst$.this$<n>; }
8822 args = build_tree_list (inst_id, build_pointer_type (type));
8823 TREE_CHAIN (args) = end_params_node;
8824 rtype = build_pointer_type (TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))));
8825 mdecl = create_artificial_method (type, ACC_STATIC, rtype,
8826 access0_identifier_node, args);
8827 fix_method_argument_names (args, mdecl);
8828 layout_class_method (type, NULL_TREE, mdecl, NULL_TREE);
8829 stmt = build_current_thisn (type);
8830 stmt = make_qualified_primary (build_wfl_node (inst_id),
8831 build_wfl_node (stmt), 0);
8832 stmt = build_return (0, stmt);
8834 saved_current_function_decl = current_function_decl;
8835 start_artificial_method_body (mdecl);
8836 java_method_add_stmt (mdecl, stmt);
8837 end_artificial_method_body (mdecl);
8838 current_function_decl = saved_current_function_decl;
8840 CLASS_ACCESS0_GENERATED_P (type) = 1;
8845 /* Craft an correctly numbered `this$<n>'string. this$0 is used for
8846 the first level of innerclassing. this$1 for the next one, etc...
8847 This function can be invoked with TYPE to NULL, available and then
8848 has to count the parser context. */
8850 static GTY(()) tree saved_thisn;
8851 static GTY(()) tree saved_type;
8854 build_current_thisn (tree type)
8856 static int saved_i = -1;
8857 static int saved_type_i = 0;
8864 if (type == saved_type)
8868 for (i = -1, decl = DECL_CONTEXT (TYPE_NAME (type));
8869 decl; decl = DECL_CONTEXT (decl), i++)
8877 i = list_length (GET_CPC_LIST ())-2;
8882 sprintf (buffer, "this$%d", i);
8884 saved_thisn = get_identifier (buffer);
8888 /* Return the assignment to the hidden enclosing context `this$<n>'
8889 by the second incoming parameter to the innerclass constructor. The
8890 form used is `this.this$<n> = this$<n>;'. */
8893 build_thisn_assign (void)
8895 if (current_class && PURE_INNER_CLASS_TYPE_P (current_class))
8897 tree thisn = build_current_thisn (current_class);
8898 tree lhs = make_qualified_primary (build_wfl_node (this_identifier_node),
8899 build_wfl_node (thisn), 0);
8900 tree rhs = build_wfl_node (thisn);
8901 #ifdef USE_MAPPED_LOCATION
8902 SET_EXPR_LOCATION (lhs, input_location);
8904 EXPR_WFL_SET_LINECOL (lhs, input_line, 0);
8906 return build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (lhs), lhs, rhs);
8912 /* Building the synthetic `class$' used to implement the `.class' 1.1
8913 extension for non primitive types. This method looks like:
8915 static Class class$(String type) throws NoClassDefFoundError
8917 try {return (java.lang.Class.forName (String));}
8918 catch (ClassNotFoundException e) {
8919 throw new NoClassDefFoundError(e.getMessage());}
8922 static GTY(()) tree get_message_wfl;
8923 static GTY(()) tree type_parm_wfl;
8926 build_dot_class_method (tree class)
8928 #define BWF(S) build_wfl_node (get_identifier ((S)))
8929 #ifdef USE_MAPPED_LOCATION
8930 #define MQN(X,Y) make_qualified_name ((X), (Y), UNKNOWN_LOCATION)
8932 #define MQN(X,Y) make_qualified_name ((X), (Y), 0)
8934 tree args, tmp, saved_current_function_decl, mdecl, qual_name;
8935 tree stmt, throw_stmt;
8937 if (!get_message_wfl)
8939 get_message_wfl = build_wfl_node (get_identifier ("getMessage"));
8940 type_parm_wfl = build_wfl_node (get_identifier ("type$"));
8943 /* Build the arguments */
8944 args = build_tree_list (get_identifier ("type$"),
8945 build_pointer_type (string_type_node));
8946 TREE_CHAIN (args) = end_params_node;
8948 /* Build the qualified name java.lang.Class.forName */
8949 tmp = MQN (MQN (MQN (BWF ("java"),
8950 BWF ("lang")), BWF ("Class")), BWF ("forName"));
8952 /* Create the "class$" function */
8953 mdecl = create_artificial_method (class, ACC_STATIC,
8954 build_pointer_type (class_type_node),
8955 classdollar_identifier_node, args);
8956 qual_name = MQN (MQN (BWF ("java"), BWF ("lang")),
8957 BWF ("NoClassDefFoundError"));
8958 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (NULL_TREE, qual_name);
8959 register_incomplete_type (JDEP_EXCEPTION, qual_name, NULL_TREE, NULL_TREE);
8960 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
8961 &TREE_VALUE (DECL_FUNCTION_THROWS (mdecl));
8963 /* We start by building the try block. We need to build:
8964 return (java.lang.Class.forName (type)); */
8965 stmt = build_method_invocation (tmp,
8966 build_tree_list (NULL_TREE, type_parm_wfl));
8967 stmt = build_return (0, stmt);
8969 /* Now onto the catch block. We start by building the expression
8970 throwing a new exception: throw new NoClassDefFoundError (_.getMessage) */
8971 #ifdef USE_MAPPED_LOCATION
8972 throw_stmt = make_qualified_name (build_wfl_node (wpv_id),
8973 get_message_wfl, UNKNOWN_LOCATION);
8975 throw_stmt = make_qualified_name (build_wfl_node (wpv_id),
8976 get_message_wfl, 0);
8978 throw_stmt = build_method_invocation (throw_stmt, NULL_TREE);
8980 /* Build new NoClassDefFoundError (_.getMessage) */
8981 throw_stmt = build_new_invocation
8982 (build_wfl_node (get_identifier ("NoClassDefFoundError")),
8983 build_tree_list (build_pointer_type (string_type_node), throw_stmt));
8985 /* Build the throw, (it's too early to use BUILD_THROW) */
8986 throw_stmt = build1 (THROW_EXPR, NULL_TREE, throw_stmt);
8988 /* Encapsulate STMT in a try block. The catch clause executes THROW_STMT */
8989 qual_name = MQN (MQN (BWF ("java"), BWF ("lang")),
8990 BWF ("ClassNotFoundException"));
8991 stmt = encapsulate_with_try_catch (0, qual_name, stmt, throw_stmt);
8993 fix_method_argument_names (args, mdecl);
8994 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8995 saved_current_function_decl = current_function_decl;
8996 start_artificial_method_body (mdecl);
8997 java_method_add_stmt (mdecl, stmt);
8998 end_artificial_method_body (mdecl);
8999 current_function_decl = saved_current_function_decl;
9000 TYPE_DOT_CLASS (class) = mdecl;
9006 build_dot_class_method_invocation (tree this_class, tree type)
9008 tree dot_class_method = TYPE_DOT_CLASS (this_class);
9011 if (TYPE_ARRAY_P (type))
9012 sig_id = build_java_signature (type);
9014 sig_id = DECL_NAME (TYPE_NAME (type));
9016 /* Ensure that the proper name separator is used */
9017 sig_id = unmangle_classname (IDENTIFIER_POINTER (sig_id),
9018 IDENTIFIER_LENGTH (sig_id));
9020 s = build_string (IDENTIFIER_LENGTH (sig_id),
9021 IDENTIFIER_POINTER (sig_id));
9022 t = build_method_invocation (build_wfl_node (DECL_NAME (dot_class_method)),
9023 build_tree_list (NULL_TREE, s));
9024 if (DECL_CONTEXT (dot_class_method) != this_class)
9026 tree class_name = DECL_NAME (TYPE_NAME (DECL_CONTEXT (dot_class_method)));
9027 t = make_qualified_primary (build_wfl_node (class_name), t, 0);
9032 /* This section of the code deals with constructor. */
9034 /* Craft a body for default constructor. Patch existing constructor
9035 bodies with call to super() and field initialization statements if
9039 fix_constructors (tree mdecl)
9041 tree iii; /* Instance Initializer Invocation */
9042 tree *bodyp = &DECL_FUNCTION_BODY (mdecl);
9043 tree thisn_assign, compound = NULL_TREE;
9044 tree class_type = DECL_CONTEXT (mdecl);
9046 if (DECL_FIXED_CONSTRUCTOR_P (mdecl))
9048 DECL_FIXED_CONSTRUCTOR_P (mdecl) = 1;
9052 /* It is an error for the compiler to generate a default
9053 constructor if the superclass doesn't have a constructor that
9054 takes no argument, or the same args for an anonymous class */
9055 tree sdecl = get_constructor_super (mdecl);
9056 if (sdecl == NULL_TREE)
9058 tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (class_type));
9059 tree save = DECL_NAME (mdecl);
9060 const char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
9061 DECL_NAME (mdecl) = DECL_NAME (sclass_decl);
9063 (lookup_cl (TYPE_NAME (class_type)),
9064 "No constructor matching %qs found in class %qs",
9065 lang_printable_name (mdecl, 2), n);
9066 DECL_NAME (mdecl) = save;
9069 if (ANONYMOUS_CLASS_P (class_type))
9071 /* Copy throws clause from the super constructor. */
9072 tree throws = DECL_FUNCTION_THROWS (sdecl);
9073 DECL_FUNCTION_THROWS (mdecl) = copy_list (throws);
9076 /* The constructor body must be crafted by hand. It's the
9077 constructor we defined when we realize we didn't have the
9078 CLASSNAME() constructor */
9079 start_artificial_method_body (mdecl);
9081 /* Insert an assignment to the this$<n> hidden field, if
9083 if ((thisn_assign = build_thisn_assign ()))
9084 java_method_add_stmt (mdecl, thisn_assign);
9086 /* We don't generate a super constructor invocation if we're
9087 compiling java.lang.Object. build_super_invocation takes care
9089 java_method_add_stmt (mdecl, build_super_invocation (mdecl));
9092 if ((iii = build_instinit_invocation (class_type)))
9093 java_method_add_stmt (mdecl, iii);
9095 end_artificial_method_body (mdecl);
9097 /* Search for an explicit constructor invocation */
9101 int invokes_this = 0;
9102 tree main_block = BLOCK_EXPR_BODY (*bodyp);
9107 switch (TREE_CODE (body))
9110 found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
9111 if (CALL_THIS_CONSTRUCTOR_P (body))
9115 case EXPR_WITH_FILE_LOCATION:
9116 bodyp = &TREE_OPERAND (body, 0);
9119 bodyp = &BLOCK_EXPR_BODY (body);
9127 /* Generate the assignment to this$<n>, if necessary */
9128 if ((thisn_assign = build_thisn_assign ()))
9129 compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
9131 /* The constructor is missing an invocation of super() */
9133 compound = add_stmt_to_compound (compound, NULL_TREE,
9134 build_super_invocation (mdecl));
9135 /* Explicit super() invocation should take place before the
9136 instance initializer blocks. */
9139 compound = add_stmt_to_compound (compound, NULL_TREE, *bodyp);
9140 *bodyp = build_java_empty_stmt ();
9143 DECL_INIT_CALLS_THIS (mdecl) = invokes_this;
9145 /* Insert the instance initializer block right after. */
9146 if (!invokes_this && (iii = build_instinit_invocation (class_type)))
9147 compound = add_stmt_to_compound (compound, NULL_TREE, iii);
9149 /* Fix the constructor main block if we're adding extra stmts */
9152 compound = add_stmt_to_compound (compound, NULL_TREE,
9153 BLOCK_EXPR_BODY (main_block));
9154 BLOCK_EXPR_BODY (main_block) = compound;
9159 /* Browse constructors in the super class, searching for a constructor
9160 that doesn't take any argument. Return the constructor if one is found,
9161 NULL_TREE otherwise. If the current class is an anonymous inner class,
9162 look for something that has the same signature. */
9164 get_constructor_super (tree mdecl)
9166 tree class = CLASSTYPE_SUPER (current_class);
9167 int super_inner = PURE_INNER_CLASS_TYPE_P (class);
9173 if (ANONYMOUS_CLASS_P (current_class))
9175 tree mdecl_arg_type;
9176 SKIP_THIS_AND_ARTIFICIAL_PARMS (mdecl_arg_type, mdecl);
9177 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
9178 if (DECL_CONSTRUCTOR_P (sdecl))
9181 tree arg_type = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
9183 arg_type = TREE_CHAIN (arg_type);
9184 for (m_arg_type = mdecl_arg_type;
9185 (arg_type != end_params_node
9186 && m_arg_type != end_params_node);
9187 arg_type = TREE_CHAIN (arg_type),
9188 m_arg_type = TREE_CHAIN (m_arg_type))
9189 if (!valid_method_invocation_conversion_p
9190 (TREE_VALUE (arg_type),
9191 TREE_VALUE (m_arg_type)))
9194 if (arg_type == end_params_node && m_arg_type == end_params_node)
9200 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
9202 tree arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
9204 arg = TREE_CHAIN (arg);
9205 if (DECL_CONSTRUCTOR_P (sdecl) && arg == end_params_node)
9212 /* Generate code for all context remembered for code generation. */
9214 static GTY(()) tree reversed_class_list;
9216 java_expand_classes (void)
9218 int save_error_count = 0;
9219 static struct parser_ctxt *cur_ctxp = NULL;
9220 location_t save_location;
9222 java_parse_abort_on_error ();
9223 if (!(ctxp = ctxp_for_generation))
9225 java_layout_classes ();
9226 java_parse_abort_on_error ();
9227 save_location = input_location;
9229 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9232 for (current = cur_ctxp->class_list;
9234 current = TREE_CHAIN (current))
9235 gen_indirect_dispatch_tables (TREE_TYPE (current));
9238 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9241 input_location = ctxp->file_start_location;
9242 lang_init_source (2); /* Error msgs have method prototypes */
9243 java_complete_expand_classes (); /* Complete and expand classes */
9244 java_parse_abort_on_error ();
9246 input_location = save_location;
9248 /* Find anonymous classes and expand their constructor. This extra pass is
9249 necessary because the constructor itself is only generated when the
9250 method in which it is defined is expanded. */
9251 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9255 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9257 output_class = current_class = TREE_TYPE (current);
9258 if (ANONYMOUS_CLASS_P (current_class))
9261 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9263 if (DECL_CONSTRUCTOR_P (d))
9265 java_complete_expand_method (d);
9266 break; /* There is only one constructor. */
9273 /* Expanding the constructors of anonymous classes generates access
9274 methods. Scan all the methods looking for null DECL_RESULTs --
9275 this will be the case if a method hasn't been expanded. */
9276 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9280 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9283 output_class = current_class = TREE_TYPE (current);
9284 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9286 if (DECL_RESULT (d) == NULL_TREE)
9287 java_complete_expand_method (d);
9292 /* ??? Instead of all this we could iterate around the list of
9293 classes until there were no more un-expanded methods. It would
9294 take a little longer -- one pass over the whole list of methods
9295 -- but it would be simpler. Like this: */
9298 int something_changed;
9302 something_changed = 0;
9303 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9307 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9310 output_class = current_class = TREE_TYPE (current);
9311 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9313 if (DECL_RESULT (d) == NULL_TREE)
9315 something_changed = 1;
9316 java_complete_expand_method (d);
9322 while (something_changed);
9326 /* If we've found error at that stage, don't try to generate
9327 anything, unless we're checking the syntax only
9328 (but not using -fsyntax-only for the purpose of generating
9330 if (java_error_count
9331 && (!flag_syntax_only && !flag_emit_class_files))
9334 /* Now things are stable, go for generation of the class data. */
9336 /* We pessimistically marked all methods and fields external until
9337 we knew what set of classes we were planning to compile. Now mark
9338 those that will be generated locally as not external. */
9339 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9343 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9344 java_mark_class_local (TREE_TYPE (current));
9347 /* Compile the classes. */
9348 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9351 reversed_class_list = NULL;
9355 /* We write out the classes in reverse order. This ensures that
9356 inner classes are written before their containing classes,
9357 which is important for parallel builds. Otherwise, the
9358 class file for the outer class may be found, but the class
9359 file for the inner class may not be present. In that
9360 situation, the compiler cannot fall back to the original
9361 source, having already read the outer class, so we must
9362 prevent that situation. */
9363 for (current = ctxp->class_list;
9365 current = TREE_CHAIN (current))
9367 = tree_cons (NULL_TREE, current, reversed_class_list);
9369 for (current = reversed_class_list;
9371 current = TREE_CHAIN (current))
9373 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
9374 if (flag_emit_class_files)
9375 write_classfile (current_class);
9376 else if (! flag_syntax_only)
9377 java_expand_method_bodies (current_class);
9383 java_finish_classes (void)
9385 static struct parser_ctxt *cur_ctxp = NULL;
9386 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9390 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9392 output_class = current_class = TREE_TYPE (current);
9398 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
9399 a tree list node containing RIGHT. Fore coming RIGHTs will be
9400 chained to this hook. LOCATION contains the location of the
9401 separating `.' operator. */
9404 make_qualified_primary (tree primary, tree right, int location)
9408 if (TREE_CODE (primary) != EXPR_WITH_FILE_LOCATION)
9409 wfl = build_wfl_wrap (primary, location);
9413 /* If wfl wasn't qualified, we build a first anchor */
9414 if (!EXPR_WFL_QUALIFICATION (wfl))
9415 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (wfl, NULL_TREE);
9418 /* And chain them */
9419 EXPR_WFL_LINECOL (right) = location;
9420 chainon (EXPR_WFL_QUALIFICATION (wfl), build_tree_list (right, NULL_TREE));
9421 PRIMARY_P (wfl) = 1;
9425 /* Simple merge of two name separated by a `.' */
9428 merge_qualified_name (tree left, tree right)
9431 if (!left && !right)
9440 obstack_grow (&temporary_obstack, IDENTIFIER_POINTER (left),
9441 IDENTIFIER_LENGTH (left));
9442 obstack_1grow (&temporary_obstack, '.');
9443 obstack_grow0 (&temporary_obstack, IDENTIFIER_POINTER (right),
9444 IDENTIFIER_LENGTH (right));
9445 node = get_identifier (obstack_base (&temporary_obstack));
9446 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
9447 QUALIFIED_P (node) = 1;
9451 /* Merge the two parts of a qualified name into LEFT. Set the
9452 location information of the resulting node to LOCATION, usually
9453 inherited from the location information of the `.' operator. */
9456 make_qualified_name (tree left, tree right,
9457 #ifdef USE_MAPPED_LOCATION
9458 source_location location
9464 #ifdef USE_COMPONENT_REF
9465 tree node = build3 (COMPONENT_REF, NULL_TREE, left, right, NULL_TREE);
9466 SET_EXPR_LOCATION (node, location);
9469 tree left_id = EXPR_WFL_NODE (left);
9470 tree right_id = EXPR_WFL_NODE (right);
9473 merge = merge_qualified_name (left_id, right_id);
9475 /* Left wasn't qualified and is now qualified */
9476 #ifdef USE_MAPPED_LOCATION
9477 if (!QUALIFIED_P (left_id))
9479 tree wfl = build_expr_wfl (left_id, EXPR_LOCATION (left));
9480 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
9483 wfl = build_expr_wfl (right_id, location);
9485 if (!QUALIFIED_P (left_id))
9487 tree wfl = build_expr_wfl (left_id, ctxp->filename, 0, 0);
9488 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (left);
9489 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
9492 wfl = build_expr_wfl (right_id, ctxp->filename, 0, 0);
9493 EXPR_WFL_LINECOL (wfl) = location;
9495 chainon (EXPR_WFL_QUALIFICATION (left), build_tree_list (wfl, NULL_TREE));
9496 EXPR_WFL_NODE (left) = merge;
9501 /* Extract the last identifier component of the qualified in WFL. The
9502 last identifier is removed from the linked list */
9505 cut_identifier_in_qualified (tree wfl)
9508 tree previous = NULL_TREE;
9509 for (q = EXPR_WFL_QUALIFICATION (wfl); ; previous = q, q = TREE_CHAIN (q))
9510 if (!TREE_CHAIN (q))
9513 /* Operating on a non qualified qualified WFL. */
9516 TREE_CHAIN (previous) = NULL_TREE;
9517 return TREE_PURPOSE (q);
9521 /* Resolve the expression name NAME. Return its decl. */
9524 resolve_expression_name (tree id, tree *orig)
9526 tree name = EXPR_WFL_NODE (id);
9529 /* 6.5.5.1: Simple expression names */
9530 if (!PRIMARY_P (id) && !QUALIFIED_P (name))
9532 /* 15.13.1: NAME can appear within the scope of a local variable
9534 if ((decl = IDENTIFIER_LOCAL_VALUE (name)))
9537 /* 15.13.1: NAME can appear within a class declaration */
9540 decl = lookup_field_wrapper (current_class, name);
9543 tree access = NULL_TREE;
9544 int fs = FIELD_STATIC (decl);
9546 /* If we're accessing an outer scope local alias, make
9547 sure we change the name of the field we're going to
9549 if (FIELD_LOCAL_ALIAS_USED (decl))
9550 name = DECL_NAME (decl);
9552 check_deprecation (id, decl);
9554 /* Instance variable (8.3.1.1) can't appear within
9555 static method, static initializer or initializer for
9556 a static variable. */
9557 if (!fs && METHOD_STATIC (current_function_decl))
9559 static_ref_err (id, name, current_class);
9560 return error_mark_node;
9562 /* Instance variables can't appear as an argument of
9563 an explicit constructor invocation */
9564 if (!fs && ctxp->explicit_constructor_p
9565 && !enclosing_context_p (DECL_CONTEXT (decl), current_class))
9568 (id, "Can't reference %qs before the superclass constructor has been called", IDENTIFIER_POINTER (name));
9569 return error_mark_node;
9572 /* If we're processing an inner class and we're trying
9573 to access a field belonging to an outer class, build
9574 the access to the field. */
9575 if (nested_field_access_p (current_class, decl))
9577 if (!fs && CLASS_STATIC (TYPE_NAME (current_class)))
9579 static_ref_err (id, DECL_NAME (decl), current_class);
9580 return error_mark_node;
9582 access = build_nested_field_access (id, decl);
9588 /* Otherwise build what it takes to access the field */
9589 access = build_field_ref ((fs ? NULL_TREE : current_this),
9590 DECL_CONTEXT (decl), name);
9592 access = maybe_build_class_init_for_field (decl, access);
9593 /* We may be asked to save the real field access node */
9596 /* Last check: can we access the field? */
9597 if (not_accessible_p (current_class, decl, NULL_TREE, 0))
9599 not_accessible_field_error (id, decl);
9600 return error_mark_node;
9602 /* And we return what we got */
9605 /* Fall down to error report on undefined variable */
9608 /* 6.5.5.2 Qualified Expression Names */
9613 qualify_ambiguous_name (id);
9614 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
9615 /* 15.10.2: Accessing Superclass Members using super */
9616 return resolve_field_access (id, orig, NULL);
9619 /* We've got an error here */
9620 if (INNER_CLASS_TYPE_P (current_class))
9621 parse_error_context (id,
9622 "Local variable %qs can't be accessed from within the inner class %qs unless it is declared final",
9623 IDENTIFIER_POINTER (name),
9624 IDENTIFIER_POINTER (DECL_NAME
9625 (TYPE_NAME (current_class))));
9627 parse_error_context (id, "Undefined variable %qs",
9628 IDENTIFIER_POINTER (name));
9630 return error_mark_node;
9634 static_ref_err (tree wfl, tree field_id, tree class_type)
9638 "Can't make a static reference to nonstatic variable %qs in class %qs",
9639 IDENTIFIER_POINTER (field_id),
9640 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class_type))));
9643 /* 15.10.1 Field Access Using a Primary and/or Expression Name.
9644 We return something suitable to generate the field access. We also
9645 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
9646 recipient's address can be null. */
9649 resolve_field_access (tree qual_wfl, tree *field_decl, tree *field_type)
9653 tree decl = NULL_TREE, where_found, type_found;
9655 if (resolve_qualified_expression_name (qual_wfl, &decl,
9656 &where_found, &type_found))
9657 return error_mark_node;
9659 /* Resolve the LENGTH field of an array here */
9660 if (DECL_P (decl) && DECL_NAME (decl) == length_identifier_node
9661 && type_found && TYPE_ARRAY_P (type_found)
9662 && ! flag_emit_class_files)
9664 tree length = build_java_array_length_access (where_found);
9667 /* In case we're dealing with a static array, we need to
9668 initialize its class before the array length can be fetched. */
9669 if (TREE_CODE (where_found) == VAR_DECL && FIELD_STATIC (where_found))
9671 build_static_field_ref (where_found);
9672 field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
9675 /* We might have been trying to resolve field.method(). In which
9676 case, the resolution is over and decl is the answer */
9677 else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
9679 else if (JDECL_P (decl))
9682 type_found = DECL_CONTEXT (decl);
9683 is_static = FIELD_STATIC (decl);
9684 field_ref = build_field_ref ((is_static ?
9685 NULL_TREE : where_found),
9686 type_found, DECL_NAME (decl));
9687 if (field_ref == error_mark_node)
9688 return error_mark_node;
9690 field_ref = maybe_build_class_init_for_field (decl, field_ref);
9692 /* If we're looking at a static field, we may need to generate a
9693 class initialization for it. This can happen when the access
9694 looks like `field.ref', where `field' is a static field in an
9695 interface we implement. */
9696 if (!flag_emit_class_files
9697 && TREE_CODE (where_found) == VAR_DECL
9698 && FIELD_STATIC (where_found))
9700 build_static_field_ref (where_found);
9701 field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
9710 *field_type = (QUAL_DECL_TYPE (decl) ?
9711 QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
9715 /* If NODE is an access to a static field, strip out the class
9716 initialization part and return the field decl, otherwise, return
9720 extract_field_decl (tree node)
9722 if (TREE_CODE (node) == COMPOUND_EXPR)
9724 tree op1 = TREE_OPERAND (node, 1);
9725 if (TREE_CODE (op1) == COMPOUND_EXPR)
9727 tree call = TREE_OPERAND (op1, 0);
9728 if (TREE_CODE (call) == CALL_EXPR
9729 && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
9730 && (TREE_OPERAND (TREE_OPERAND (call, 0), 0)
9731 == soft_initclass_node))
9732 return TREE_OPERAND (op1, 1);
9734 else if (JDECL_P (op1))
9740 /* 6.5.5.2: Qualified Expression Names */
9743 resolve_qualified_expression_name (tree wfl, tree *found_decl,
9744 tree *where_found, tree *type_found)
9746 int from_type = 0; /* Field search initiated from a type */
9747 int from_super = 0, from_cast = 0, from_qualified_this = 0;
9748 int previous_call_static = 0;
9750 tree decl = NULL_TREE, type = NULL_TREE, q;
9751 /* For certain for of inner class instantiation */
9752 tree saved_current, saved_this;
9753 #define RESTORE_THIS_AND_CURRENT_CLASS \
9754 { current_class = saved_current; current_this = saved_this;}
9756 *type_found = *where_found = NULL_TREE;
9758 for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
9760 tree qual_wfl = QUAL_WFL (q);
9761 tree ret_decl; /* for EH checking */
9762 #ifdef USE_MAPPED_LOCATION
9763 source_location location; /* for EH checking */
9765 int location; /* for EH checking */
9768 /* 15.10.1 Field Access Using a Primary */
9769 switch (TREE_CODE (qual_wfl))
9772 case NEW_CLASS_EXPR:
9773 /* If the access to the function call is a non static field,
9774 build the code to access it. */
9775 if (JDECL_P (decl) && !FIELD_STATIC (decl))
9777 decl = maybe_access_field (decl, *where_found,
9778 DECL_CONTEXT (decl));
9779 if (decl == error_mark_node)
9783 /* And code for the function call */
9784 if (complete_function_arguments (qual_wfl))
9787 /* We might have to setup a new current class and a new this
9788 for the search of an inner class, relative to the type of
9789 a expression resolved as `decl'. The current values are
9790 saved and restored shortly after */
9791 saved_current = current_class;
9792 saved_this = current_this;
9794 && (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
9795 || from_qualified_this))
9797 /* If we still have `from_qualified_this', we have the form
9798 <T>.this.f() and we need to build <T>.this */
9799 if (from_qualified_this)
9801 decl = build_access_to_thisn (current_class, type, 0);
9802 decl = java_complete_tree (decl);
9803 type = TREE_TYPE (TREE_TYPE (decl));
9805 current_class = type;
9806 current_this = decl;
9807 from_qualified_this = 0;
9810 if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
9811 CALL_USING_SUPER (qual_wfl) = 1;
9812 #ifdef USE_MAPPED_LOCATION
9813 location = (TREE_CODE (qual_wfl) == CALL_EXPR
9814 ? EXPR_LOCATION (TREE_OPERAND (qual_wfl, 0))
9815 : UNKNOWN_LOCATION);
9817 location = (TREE_CODE (qual_wfl) == CALL_EXPR ?
9818 EXPR_WFL_LINECOL (TREE_OPERAND (qual_wfl, 0)) : 0);
9820 *where_found = patch_method_invocation (qual_wfl, decl, type,
9822 &is_static, &ret_decl);
9824 if (*where_found == error_mark_node)
9826 RESTORE_THIS_AND_CURRENT_CLASS;
9829 *type_found = type = QUAL_DECL_TYPE (*where_found);
9831 *where_found = force_evaluation_order (*where_found);
9833 /* If we're creating an inner class instance, check for that
9834 an enclosing instance is in scope */
9835 if (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
9836 && INNER_ENCLOSING_SCOPE_CHECK (type))
9839 (qual_wfl, "No enclosing instance for inner class %qs is in scope%s",
9840 lang_printable_name (type, 0),
9841 (!current_this ? "" :
9842 "; an explicit one must be provided when creating this inner class"));
9843 RESTORE_THIS_AND_CURRENT_CLASS;
9847 /* In case we had to change then to resolve a inner class
9848 instantiation using a primary qualified by a `new' */
9849 RESTORE_THIS_AND_CURRENT_CLASS;
9851 #ifdef USE_MAPPED_LOCATION
9852 if (location != UNKNOWN_LOCATION)
9857 tree arguments = NULL_TREE;
9858 if (TREE_CODE (qual_wfl) == CALL_EXPR
9859 && TREE_OPERAND (qual_wfl, 1) != NULL_TREE)
9860 arguments = TREE_VALUE (TREE_OPERAND (qual_wfl, 1));
9861 check_thrown_exceptions (location, ret_decl, arguments);
9864 /* If the previous call was static and this one is too,
9865 build a compound expression to hold the two (because in
9866 that case, previous function calls aren't transported as
9867 forcoming function's argument. */
9868 if (previous_call_static && is_static)
9870 /* We must set CAN_COMPLETE_NORMALLY for the first call
9871 since it is done nowhere else. */
9872 CAN_COMPLETE_NORMALLY (decl) = 1;
9873 decl = build2 (COMPOUND_EXPR, TREE_TYPE (*where_found),
9874 decl, *where_found);
9875 TREE_SIDE_EFFECTS (decl) = 1;
9879 previous_call_static = is_static;
9880 decl = *where_found;
9885 case NEW_ARRAY_EXPR:
9886 case NEW_ANONYMOUS_ARRAY_EXPR:
9887 *where_found = decl = java_complete_tree (qual_wfl);
9888 if (decl == error_mark_node)
9890 *type_found = type = QUAL_DECL_TYPE (decl);
9894 *where_found = decl = java_complete_tree (qual_wfl);
9895 if (decl == error_mark_node)
9897 *type_found = type = QUAL_DECL_TYPE (decl);
9901 case CONDITIONAL_EXPR:
9904 *where_found = decl = java_complete_tree (qual_wfl);
9905 if (decl == error_mark_node)
9907 *type_found = type = QUAL_DECL_TYPE (decl);
9911 /* If the access to the function call is a non static field,
9912 build the code to access it. */
9913 if (JDECL_P (decl) && !FIELD_STATIC (decl))
9915 decl = maybe_access_field (decl, *where_found, type);
9916 if (decl == error_mark_node)
9919 /* And code for the array reference expression */
9920 decl = java_complete_tree (qual_wfl);
9921 if (decl == error_mark_node)
9923 type = QUAL_DECL_TYPE (decl);
9927 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
9929 if ((type = patch_string (decl)))
9931 *where_found = QUAL_RESOLUTION (q) = decl;
9932 *type_found = type = TREE_TYPE (decl);
9936 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
9938 *where_found = QUAL_RESOLUTION (q) = decl;
9939 *type_found = type = TREE_TYPE (decl);
9943 /* Fix for -Wall Just go to the next statement. Don't
9948 /* If we fall here, we weren't processing a (static) function call. */
9949 previous_call_static = 0;
9951 /* It can be the keyword THIS */
9952 if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
9953 && EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
9958 (wfl, "Keyword %<this%> used outside allowed context");
9961 if (ctxp->explicit_constructor_p
9962 && type == current_class)
9964 parse_error_context (wfl, "Can't reference %<this%> before the superclass constructor has been called");
9967 /* We have to generate code for intermediate access */
9968 if (!from_type || TREE_TYPE (TREE_TYPE (current_this)) == type)
9970 *where_found = decl = current_this;
9971 *type_found = type = QUAL_DECL_TYPE (decl);
9973 /* We're trying to access the this from somewhere else. Make sure
9974 it's allowed before doing so. */
9977 if (!enclosing_context_p (type, current_class))
9979 char *p = xstrdup (lang_printable_name (type, 0));
9980 parse_error_context (qual_wfl, "Can't use variable %<%s.this%>: type %qs isn't an outer type of type %qs",
9982 lang_printable_name (current_class, 0));
9986 from_qualified_this = 1;
9987 /* If there's nothing else after that, we need to
9988 produce something now, otherwise, the section of the
9989 code that needs to produce <T>.this will generate
9990 what is necessary. */
9991 if (!TREE_CHAIN (q))
9993 decl = build_access_to_thisn (current_class, type, 0);
9994 *where_found = decl = java_complete_tree (decl);
9995 *type_found = type = TREE_TYPE (decl);
10003 /* 15.10.2 Accessing Superclass Members using SUPER */
10004 if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
10005 && EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
10008 /* Check on the restricted use of SUPER */
10009 if (METHOD_STATIC (current_function_decl)
10010 || current_class == object_type_node)
10012 parse_error_context
10013 (wfl, "Keyword %<super%> used outside allowed context");
10016 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
10017 node = build_cast (EXPR_WFL_LINECOL (qual_wfl),
10018 CLASSTYPE_SUPER (current_class),
10019 build_this (EXPR_WFL_LINECOL (qual_wfl)));
10020 *where_found = decl = java_complete_tree (node);
10021 if (decl == error_mark_node)
10023 *type_found = type = QUAL_DECL_TYPE (decl);
10024 from_super = from_type = 1;
10028 /* 15.13.1: Can't search for field name in packages, so we
10029 assume a variable/class name was meant. */
10030 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
10033 if ((decl = resolve_package (wfl, &q, &name)))
10036 *where_found = decl;
10038 check_pkg_class_access (DECL_NAME (decl), qual_wfl, true, NULL);
10040 /* We want to be absolutely sure that the class is laid
10041 out. We're going to search something inside it. */
10042 *type_found = type = TREE_TYPE (decl);
10043 layout_class (type);
10046 /* Fix them all the way down, if any are left. */
10049 list = TREE_CHAIN (q);
10052 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (list)) = 0;
10053 list = TREE_CHAIN (list);
10059 if (from_super || from_cast)
10060 parse_error_context
10061 ((from_cast ? qual_wfl : wfl),
10062 "No variable %qs defined in class %qs",
10063 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10064 lang_printable_name (type, 0));
10066 parse_error_context
10067 (qual_wfl, "Undefined variable or class name: %qs",
10068 IDENTIFIER_POINTER (name));
10073 /* We have a type name. It's been already resolved when the
10074 expression was qualified. */
10075 else if (RESOLVE_TYPE_NAME_P (qual_wfl) && QUAL_RESOLUTION (q))
10077 decl = QUAL_RESOLUTION (q);
10079 /* Sneak preview. If next we see a `new', we're facing a
10080 qualification which resulted in a type being selected
10081 instead of a field. Report the error. */
10083 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR)
10085 parse_error_context (qual_wfl, "Undefined variable %qs",
10086 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10090 check_pkg_class_access (DECL_NAME (decl), qual_wfl, true, NULL);
10092 check_deprecation (qual_wfl, decl);
10094 type = TREE_TYPE (decl);
10097 /* We resolve an expression name */
10100 tree field_decl = NULL_TREE;
10102 /* If there exists an early resolution, use it. That occurs
10103 only once and we know that there are more things to
10104 come. Don't do that when processing something after SUPER
10105 (we need more thing to be put in place below */
10106 if (!from_super && QUAL_RESOLUTION (q))
10108 decl = QUAL_RESOLUTION (q);
10111 if (TREE_CODE (decl) == FIELD_DECL
10112 || TREE_CODE (decl) == VAR_DECL)
10114 if (TREE_CODE (decl) == FIELD_DECL
10115 && !FIELD_STATIC (decl))
10118 *where_found = current_this;
10121 static_ref_err (qual_wfl, DECL_NAME (decl),
10128 *where_found = TREE_TYPE (decl);
10129 if (TREE_CODE (*where_found) == POINTER_TYPE)
10130 *where_found = TREE_TYPE (*where_found);
10132 if (nested_field_access_p (current_class, decl))
10133 decl = build_nested_field_access (qual_wfl, decl);
10137 *where_found = TREE_TYPE (decl);
10138 if (TREE_CODE (*where_found) == POINTER_TYPE)
10139 *where_found = TREE_TYPE (*where_found);
10144 /* Report and error if we're using a numerical literal as a
10145 qualifier. It can only be an INTEGER_CST. */
10146 else if (TREE_CODE (qual_wfl) == INTEGER_CST)
10148 parse_error_context
10149 (wfl, "Can't use type %qs as a qualifier",
10150 lang_printable_name (TREE_TYPE (qual_wfl), 0));
10154 /* We have to search for a field, knowing the type of its
10155 container. The flag FROM_TYPE indicates that we resolved
10156 the last member of the expression as a type name, which
10157 means that for the resolution of this field, we'll look
10158 for other errors than if it was resolved as a member of
10163 tree field_decl_type; /* For layout */
10165 if (!from_type && !JREFERENCE_TYPE_P (type))
10167 parse_error_context
10168 (qual_wfl, "Attempt to reference field %qs in %<%s %s%>",
10169 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10170 lang_printable_name (type, 0),
10171 IDENTIFIER_POINTER (DECL_NAME (decl)));
10175 field_decl = lookup_field_wrapper (type,
10176 EXPR_WFL_NODE (qual_wfl));
10178 /* Maybe what we're trying to access to is an inner
10179 class, only if decl is a TYPE_DECL. */
10180 if (!field_decl && TREE_CODE (decl) == TYPE_DECL)
10182 tree ptr, inner_decl;
10184 BUILD_PTR_FROM_NAME (ptr, EXPR_WFL_NODE (qual_wfl));
10185 inner_decl = resolve_class (decl, ptr, NULL_TREE, qual_wfl);
10188 check_inner_class_access (inner_decl, decl, qual_wfl);
10189 type = TREE_TYPE (inner_decl);
10196 if (field_decl == NULL_TREE)
10198 parse_error_context
10199 (qual_wfl, "No variable %qs defined in type %qs",
10200 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10201 GET_TYPE_NAME (type));
10204 if (field_decl == error_mark_node)
10207 /* Layout the type of field_decl, since we may need
10208 it. Don't do primitive types or loaded classes. The
10209 situation of non primitive arrays may not handled
10210 properly here. FIXME */
10211 if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
10212 field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
10214 field_decl_type = TREE_TYPE (field_decl);
10215 if (!JPRIMITIVE_TYPE_P (field_decl_type)
10216 && !CLASS_LOADED_P (field_decl_type)
10217 && !TYPE_ARRAY_P (field_decl_type))
10218 resolve_and_layout (field_decl_type, NULL_TREE);
10220 /* Check on accessibility here */
10221 if (not_accessible_p (current_class, field_decl,
10222 *type_found, from_super))
10223 return not_accessible_field_error (qual_wfl,field_decl);
10224 check_deprecation (qual_wfl, field_decl);
10226 /* There are things to check when fields are accessed
10227 from type. There are no restrictions on a static
10228 declaration of the field when it is accessed from an
10230 is_static = FIELD_STATIC (field_decl);
10231 if (!from_super && from_type
10232 && !TYPE_INTERFACE_P (type)
10234 && (current_function_decl
10235 && METHOD_STATIC (current_function_decl)))
10237 static_ref_err (qual_wfl, EXPR_WFL_NODE (qual_wfl), type);
10240 from_cast = from_super = 0;
10242 /* If it's an access from a type but isn't static, we
10243 make it relative to `this'. */
10244 if (!is_static && from_type)
10245 decl = current_this;
10247 /* If we need to generate something to get a proper
10248 handle on what this field is accessed from, do it
10252 decl = maybe_access_field (decl, *where_found, *type_found);
10253 if (decl == error_mark_node)
10257 /* We want to keep the location where we found it, and the
10259 *where_found = decl;
10260 *type_found = type;
10262 /* Generate the correct expression for field access from
10264 if (from_qualified_this)
10267 = build_nested_field_access (qual_wfl, field_decl);
10268 from_qualified_this = 0;
10271 /* If needed, generate accessors for static field access. */
10273 && FIELD_PRIVATE (field_decl)
10274 && flag_emit_class_files
10275 && nested_field_access_p (current_class, field_decl))
10276 field_decl = build_nested_field_access (qual_wfl, field_decl);
10278 /* This is the decl found and eventually the next one to
10283 type = QUAL_DECL_TYPE (decl);
10285 /* Sneak preview. If decl is qualified by a `new', report
10286 the error here to be accurate on the peculiar construct */
10288 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR
10289 && !JREFERENCE_TYPE_P (type))
10291 parse_error_context (qual_wfl, "Attempt to reference field %<new%> in a %qs",
10292 lang_printable_name (type, 0));
10296 /* `q' might have changed due to a after package resolution
10297 re-qualification */
10301 *found_decl = decl;
10305 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
10306 can't be accessed from REFERENCE (a record type). If MEMBER
10307 features a protected access, we then use WHERE which, if non null,
10308 holds the type of MEMBER's access that is checked against
10309 6.6.2.1. This function should be used when decl is a field or a
10313 not_accessible_p (tree reference, tree member, tree where, int from_super)
10315 int access_flag = get_access_flags_from_decl (member);
10316 bool is_static = false;
10318 if (TREE_CODE (member) == FIELD_DECL ||
10319 TREE_CODE (member) == VAR_DECL)
10320 is_static = FIELD_STATIC (member);
10322 is_static = METHOD_STATIC (member);
10324 /* Access always granted for members declared public */
10325 if (access_flag & ACC_PUBLIC)
10328 /* Check access on protected members */
10329 if (access_flag & ACC_PROTECTED)
10331 /* Access granted if it occurs from within the package
10332 containing the class in which the protected member is
10334 if (class_in_current_package (DECL_CONTEXT (member)))
10337 /* If accessed with the form `super.member', then access is granted */
10341 /* If WHERE is active, access was made through a qualifier. For
10342 non-static members, access is granted if the type of the qualifier
10343 is or is a sublass of the type the access is made from (6.6.2.1.) */
10344 if (where && !is_static)
10348 if (inherits_from_p (where, reference))
10350 if (INNER_CLASS_TYPE_P (reference))
10351 reference = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (reference)));
10358 /* Otherwise, access is granted if occurring from within the class
10359 where member is declared, or a subclass of it. */
10362 if (inherits_from_p (reference, DECL_CONTEXT (member)))
10364 if (INNER_CLASS_TYPE_P (reference))
10365 reference = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (reference)));
10372 /* Check access on private members. Access is granted only if it
10373 occurs from within the class in which it is declared -- that does
10374 it for innerclasses too. */
10375 if (access_flag & ACC_PRIVATE)
10377 if (reference == DECL_CONTEXT (member) ||
10378 common_enclosing_context_p (DECL_CONTEXT (member), reference))
10383 /* Default access is permitted only when occurring from within the
10384 package in which the context (MEMBER) is declared. */
10385 return !class_in_current_package (DECL_CONTEXT (member));
10388 /* Test deprecated decl access. */
10390 check_deprecation (tree wfl, tree decl)
10395 if (! warn_deprecated)
10398 /* We want to look at the element type of arrays here, so we strip
10399 all surrounding array types. */
10400 if (TYPE_ARRAY_P (TREE_TYPE (decl)))
10402 elt = TREE_TYPE (decl);
10403 while (TYPE_ARRAY_P (elt))
10404 elt = TYPE_ARRAY_ELEMENT (elt);
10405 /* We'll end up with a pointer type, so we use TREE_TYPE to go
10407 decl = TYPE_NAME (TREE_TYPE (elt));
10409 file = DECL_SOURCE_FILE (decl);
10411 /* Complain if the field is deprecated and the file it was defined
10412 in isn't compiled at the same time the file which contains its
10414 if (DECL_DEPRECATED (decl)
10415 && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
10418 switch (TREE_CODE (decl))
10420 case FUNCTION_DECL:
10428 parse_warning_context (wfl, "The class %qs has been deprecated",
10429 IDENTIFIER_POINTER (DECL_NAME (decl)));
10434 /* Don't issue a message if the context as been deprecated as a
10436 if (! CLASS_DEPRECATED (TYPE_NAME (DECL_CONTEXT (decl))))
10437 parse_warning_context
10438 (wfl, "The %s %qs in class %qs has been deprecated",
10439 the, lang_printable_name (decl, 0),
10440 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
10444 /* Returns 1 if class was declared in the current package, 0 otherwise */
10446 static GTY(()) tree cicp_cache;
10448 class_in_current_package (tree class)
10450 int qualified_flag;
10453 if (cicp_cache == class)
10456 qualified_flag = QUALIFIED_P (DECL_NAME (TYPE_NAME (class)));
10458 /* If the current package is empty and the name of CLASS is
10459 qualified, class isn't in the current package. If there is a
10460 current package and the name of the CLASS is not qualified, class
10461 isn't in the current package */
10462 if ((!ctxp->package && qualified_flag) || (ctxp->package && !qualified_flag))
10465 /* If there is not package and the name of CLASS isn't qualified,
10466 they belong to the same unnamed package */
10467 if (!ctxp->package && !qualified_flag)
10470 /* Compare the left part of the name of CLASS with the package name */
10471 split_qualified_name (&left, NULL, DECL_NAME (TYPE_NAME (class)));
10472 if (ctxp->package == left)
10474 cicp_cache = class;
10480 /* This function may generate code to access DECL from WHERE. This is
10481 done only if certain conditions meet. */
10484 maybe_access_field (tree decl, tree where, tree type)
10486 if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
10487 && !FIELD_STATIC (decl))
10488 decl = build_field_ref (where ? where : current_this,
10489 (type ? type : DECL_CONTEXT (decl)),
10494 /* Build a method invocation, by patching PATCH. If non NULL
10495 and according to the situation, PRIMARY and WHERE may be
10496 used. IS_STATIC is set to 1 if the invoked function is static. */
10499 patch_method_invocation (tree patch, tree primary, tree where, int from_super,
10500 int *is_static, tree *ret_decl)
10502 tree wfl = TREE_OPERAND (patch, 0);
10503 tree args = TREE_OPERAND (patch, 1);
10504 tree name = EXPR_WFL_NODE (wfl);
10506 int is_static_flag = 0;
10507 int is_super_init = 0;
10508 tree this_arg = NULL_TREE;
10509 int is_array_clone_call = 0;
10511 /* Should be overridden if everything goes well. Otherwise, if
10512 something fails, it should keep this value. It stop the
10513 evaluation of a bogus assignment. See java_complete_tree,
10514 MODIFY_EXPR: for the reasons why we sometimes want to keep on
10515 evaluating an assignment */
10516 TREE_TYPE (patch) = error_mark_node;
10518 /* Since lookup functions are messing with line numbers, save the
10520 java_parser_context_save_global ();
10522 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
10524 /* Resolution of qualified name, excluding constructors */
10525 if (QUALIFIED_P (name) && !CALL_CONSTRUCTOR_P (patch))
10527 tree identifier, identifier_wfl, type, resolved;
10528 /* Extract the last IDENTIFIER of the qualified
10529 expression. This is a wfl and we will use it's location
10530 data during error report. */
10531 identifier_wfl = cut_identifier_in_qualified (wfl);
10532 identifier = EXPR_WFL_NODE (identifier_wfl);
10534 /* Given the context, IDENTIFIER is syntactically qualified
10535 as a MethodName. We need to qualify what's before */
10536 qualify_ambiguous_name (wfl);
10537 resolved = resolve_field_access (wfl, NULL, NULL);
10539 if (TREE_CODE (resolved) == VAR_DECL && FIELD_STATIC (resolved)
10540 && FIELD_FINAL (resolved)
10541 && !inherits_from_p (DECL_CONTEXT (resolved), current_class)
10542 && !flag_emit_class_files)
10543 resolved = build_class_init (DECL_CONTEXT (resolved), resolved);
10545 if (resolved == error_mark_node)
10546 PATCH_METHOD_RETURN_ERROR ();
10548 type = GET_SKIP_TYPE (resolved);
10549 resolve_and_layout (type, NULL_TREE);
10551 if (JPRIMITIVE_TYPE_P (type))
10553 parse_error_context
10555 "Can't invoke a method on primitive type %qs",
10556 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
10557 PATCH_METHOD_RETURN_ERROR ();
10560 list = lookup_method_invoke (0, identifier_wfl, type, identifier, args);
10561 args = nreverse (args);
10563 /* We're resolving a call from a type */
10564 if (TREE_CODE (resolved) == TYPE_DECL)
10566 if (CLASS_INTERFACE (resolved))
10568 parse_error_context
10570 "Can't make static reference to method %qs in interface %qs",
10571 IDENTIFIER_POINTER (identifier),
10572 IDENTIFIER_POINTER (name));
10573 PATCH_METHOD_RETURN_ERROR ();
10575 if (list && !METHOD_STATIC (list))
10577 char *fct_name = xstrdup (lang_printable_name (list, 2));
10578 parse_error_context
10580 "Can't make static reference to method %<%s %s%> in class %qs",
10581 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
10582 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
10584 PATCH_METHOD_RETURN_ERROR ();
10588 this_arg = primary = resolved;
10590 if (TYPE_ARRAY_P (type) && identifier == get_identifier ("clone"))
10591 is_array_clone_call = 1;
10593 /* IDENTIFIER_WFL will be used to report any problem further */
10594 wfl = identifier_wfl;
10596 /* Resolution of simple names, names generated after a primary: or
10600 tree class_to_search = NULL_TREE;
10601 int lc; /* Looking for Constructor */
10603 /* We search constructor in their target class */
10604 if (CALL_CONSTRUCTOR_P (patch))
10606 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10607 class_to_search = EXPR_WFL_NODE (wfl);
10608 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
10609 this_identifier_node)
10610 class_to_search = NULL_TREE;
10611 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
10612 super_identifier_node)
10615 if (CLASSTYPE_SUPER (current_class))
10617 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
10620 parse_error_context (wfl, "Can't invoke super constructor on java.lang.Object");
10621 PATCH_METHOD_RETURN_ERROR ();
10625 /* Class to search is NULL if we're searching the current one */
10626 if (class_to_search)
10628 class_to_search = resolve_and_layout (class_to_search, wfl);
10630 if (!class_to_search)
10632 parse_error_context
10633 (wfl, "Class %qs not found in type declaration",
10634 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10635 PATCH_METHOD_RETURN_ERROR ();
10638 /* Can't instantiate an abstract class, but we can
10639 invoke it's constructor. It's use within the `new'
10640 context is denied here. */
10641 if (CLASS_ABSTRACT (class_to_search)
10642 && TREE_CODE (patch) == NEW_CLASS_EXPR)
10644 parse_error_context
10645 (wfl, "Class %qs is an abstract class. It can't be instantiated",
10646 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10647 PATCH_METHOD_RETURN_ERROR ();
10650 class_to_search = TREE_TYPE (class_to_search);
10653 class_to_search = current_class;
10656 /* This is a regular search in the local class, unless an
10657 alternate class is specified. */
10660 if (where != NULL_TREE)
10661 class_to_search = where;
10662 else if (QUALIFIED_P (name))
10663 class_to_search = current_class;
10666 class_to_search = current_class;
10670 if (has_method (class_to_search, name))
10672 if (! INNER_CLASS_TYPE_P (class_to_search))
10674 parse_error_context (wfl,
10675 "No method named %qs in scope",
10676 IDENTIFIER_POINTER (name));
10677 PATCH_METHOD_RETURN_ERROR ();
10680 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_to_search)));
10686 /* NAME is a simple identifier or comes from a primary. Search
10687 in the class whose declaration contain the method being
10689 resolve_and_layout (class_to_search, NULL_TREE);
10691 list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
10692 /* Don't continue if no method were found, as the next statement
10693 can't be executed then. */
10695 PATCH_METHOD_RETURN_ERROR ();
10697 if (TYPE_ARRAY_P (class_to_search)
10698 && DECL_NAME (list) == get_identifier ("clone"))
10699 is_array_clone_call = 1;
10701 /* Check for static reference if non static methods */
10702 if (check_for_static_method_reference (wfl, patch, list,
10703 class_to_search, primary))
10704 PATCH_METHOD_RETURN_ERROR ();
10706 /* Check for inner classes creation from illegal contexts */
10707 if (lc && (INNER_CLASS_TYPE_P (class_to_search)
10708 && !CLASS_STATIC (TYPE_NAME (class_to_search)))
10709 && INNER_ENCLOSING_SCOPE_CHECK (class_to_search)
10710 && !DECL_INIT_P (current_function_decl))
10712 parse_error_context
10713 (wfl, "No enclosing instance for inner class %qs is in scope%s",
10714 lang_printable_name (class_to_search, 0),
10715 (!current_this ? "" :
10716 "; an explicit one must be provided when creating this inner class"));
10717 PATCH_METHOD_RETURN_ERROR ();
10720 /* Non static methods are called with the current object extra
10721 argument. If patch a `new TYPE()', the argument is the value
10722 returned by the object allocator. If method is resolved as a
10723 primary, use the primary otherwise use the current THIS. */
10724 args = nreverse (args);
10725 if (TREE_CODE (patch) != NEW_CLASS_EXPR)
10727 this_arg = primary ? primary : current_this;
10729 /* If we're using an access method, things are different.
10730 There are two family of cases:
10732 1) We're not generating bytecodes:
10734 - LIST is non static. It's invocation is transformed from
10735 x(a1,...,an) into this$<n>.x(a1,....an).
10736 - LIST is static. It's invocation is transformed from
10737 x(a1,...,an) into TYPE_OF(this$<n>).x(a1,....an)
10739 2) We're generating bytecodes:
10741 - LIST is non static. It's invocation is transformed from
10742 x(a1,....,an) into access$<n>(this$<n>,a1,...,an).
10743 - LIST is static. It's invocation is transformed from
10744 x(a1,....,an) into TYPE_OF(this$<n>).x(a1,....an).
10746 Of course, this$<n> can be arbitrarily complex, ranging from
10747 this$0 (the immediate outer context) to
10748 access$0(access$0(...(this$0))).
10750 maybe_use_access_method returns a nonzero value if the
10751 this_arg has to be moved into the (then generated) stub
10752 argument list. In the meantime, the selected function
10753 might have be replaced by a generated stub. */
10755 maybe_use_access_method (is_super_init, &list, &this_arg))
10757 args = tree_cons (NULL_TREE, this_arg, args);
10758 this_arg = NULL_TREE; /* So it doesn't get chained twice */
10763 /* Merge point of all resolution schemes. If we have nothing, this
10764 is an error, already signaled */
10766 PATCH_METHOD_RETURN_ERROR ();
10768 /* Check accessibility, position the is_static flag, build and
10770 if (not_accessible_p (DECL_CONTEXT (current_function_decl), list,
10771 (primary ? TREE_TYPE (TREE_TYPE (primary)) :
10772 NULL_TREE), from_super)
10773 /* Calls to clone() on array types are permitted as a special-case. */
10774 && !is_array_clone_call)
10776 const char *const fct_name = IDENTIFIER_POINTER (DECL_NAME (list));
10777 const char *const access =
10778 accessibility_string (get_access_flags_from_decl (list));
10779 const char *const klass =
10780 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list))));
10781 const char *const refklass =
10782 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class)));
10783 const char *const what = (DECL_CONSTRUCTOR_P (list)
10784 ? "constructor" : "method");
10785 parse_error_context (wfl,
10786 "Can't access %s %s %<%s.%s%> from %qs",
10787 access, what, klass, fct_name, refklass);
10788 PATCH_METHOD_RETURN_ERROR ();
10791 /* Deprecation check: check whether the method being invoked or the
10792 instance-being-created's type are deprecated. */
10793 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10794 check_deprecation (wfl, TYPE_NAME (DECL_CONTEXT (list)));
10795 check_deprecation (wfl, list);
10797 /* If invoking a innerclass constructor, there are hidden parameters
10799 if (TREE_CODE (patch) == NEW_CLASS_EXPR
10800 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
10802 /* And make sure we add the accessed local variables to be saved
10803 in field aliases. */
10804 args = build_alias_initializer_parameter_list
10805 (AIPL_FUNCTION_CTOR_INVOCATION, DECL_CONTEXT (list), args, NULL);
10807 /* Secretly pass the current_this/primary as a second argument */
10808 if (primary || current_this)
10811 tree this_type = (current_this ?
10812 TREE_TYPE (TREE_TYPE (current_this)) : NULL_TREE);
10813 /* Method's (list) enclosing context */
10814 tree mec = DECL_CONTEXT (TYPE_NAME (DECL_CONTEXT (list)));
10815 /* If we have a primary, use it. */
10817 extra_arg = primary;
10818 /* The current `this' is an inner class but isn't a direct
10819 enclosing context for the inner class we're trying to
10820 create. Build an access to the proper enclosing context
10822 else if (current_this && PURE_INNER_CLASS_TYPE_P (this_type)
10823 && this_type != TREE_TYPE (mec))
10826 extra_arg = build_access_to_thisn (current_class,
10827 TREE_TYPE (mec), 0);
10828 extra_arg = java_complete_tree (extra_arg);
10830 /* Otherwise, just use the current `this' as an enclosing
10833 extra_arg = current_this;
10834 args = tree_cons (NULL_TREE, extra_arg, args);
10837 args = tree_cons (NULL_TREE, integer_zero_node, args);
10840 /* This handles the situation where a constructor invocation needs
10841 to have an enclosing context passed as a second parameter (the
10842 constructor is one of an inner class). */
10843 if ((is_super_init ||
10844 (TREE_CODE (patch) == CALL_EXPR && name == this_identifier_node))
10845 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
10847 tree dest = TYPE_NAME (DECL_CONTEXT (list));
10849 build_access_to_thisn (current_class, DECL_CONTEXT (dest), 0);
10850 extra_arg = java_complete_tree (extra_arg);
10851 args = tree_cons (NULL_TREE, extra_arg, args);
10854 is_static_flag = METHOD_STATIC (list);
10855 if (! is_static_flag && this_arg != NULL_TREE)
10856 args = tree_cons (NULL_TREE, this_arg, args);
10858 /* In the context of an explicit constructor invocation, we can't
10859 invoke any method relying on `this'. Exceptions are: we're
10860 invoking a static function, primary exists and is not the current
10861 this, we're creating a new object. */
10862 if (ctxp->explicit_constructor_p
10864 && (!primary || primary == current_this)
10865 && (TREE_CODE (patch) != NEW_CLASS_EXPR))
10867 parse_error_context (wfl, "Can't reference %<this%> before the superclass constructor has been called");
10868 PATCH_METHOD_RETURN_ERROR ();
10870 java_parser_context_restore_global ();
10872 *is_static = is_static_flag;
10873 /* Sometimes, we want the decl of the selected method. Such as for
10877 patch = patch_invoke (patch, list, args);
10879 /* Now is a good time to insert the call to finit$ */
10880 if (is_super_init && CLASS_HAS_FINIT_P (current_class))
10882 tree finit_parms, finit_call;
10884 /* Prepare to pass hidden parameters to finit$, if any. */
10885 finit_parms = build_alias_initializer_parameter_list
10886 (AIPL_FUNCTION_FINIT_INVOCATION, current_class, NULL_TREE, NULL);
10889 build_method_invocation (build_wfl_node (finit_identifier_node),
10892 /* Generate the code used to initialize fields declared with an
10893 initialization statement and build a compound statement along
10894 with the super constructor invocation. */
10895 CAN_COMPLETE_NORMALLY (patch) = 1;
10896 patch = build2 (COMPOUND_EXPR, void_type_node, patch,
10897 java_complete_tree (finit_call));
10902 /* Check that we're not trying to do a static reference to a method in
10903 non static method. Return 1 if it's the case, 0 otherwise. */
10906 check_for_static_method_reference (tree wfl, tree node, tree method,
10907 tree where, tree primary)
10909 if (METHOD_STATIC (current_function_decl)
10910 && !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
10912 char *fct_name = xstrdup (lang_printable_name (method, 0));
10913 parse_error_context
10914 (wfl, "Can't make static reference to method %<%s %s%> in class %qs",
10915 lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
10916 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (where))));
10923 /* Fix the invocation of *MDECL if necessary in the case of a
10924 invocation from an inner class. *THIS_ARG might be modified
10925 appropriately and an alternative access to *MDECL might be
10929 maybe_use_access_method (int is_super_init, tree *mdecl, tree *this_arg)
10932 tree md = *mdecl, ta = *this_arg;
10934 int non_static_context = !METHOD_STATIC (md);
10937 || DECL_CONTEXT (md) == current_class
10938 || !PURE_INNER_CLASS_TYPE_P (current_class)
10939 || DECL_FINIT_P (md)
10940 || DECL_INSTINIT_P (md))
10943 /* If we're calling a method found in an enclosing class, generate
10944 what it takes to retrieve the right this. Don't do that if we're
10945 invoking a static method. Note that if MD's type is unrelated to
10946 CURRENT_CLASS, then the current this can be used. */
10948 if (non_static_context
10949 && !inherits_from_p (current_class, DECL_CONTEXT (md)))
10951 ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
10952 if (inherits_from_p (ctx, DECL_CONTEXT (md)))
10954 ta = build_current_thisn (current_class);
10955 ta = build_wfl_node (ta);
10962 maybe_build_thisn_access_method (type);
10963 if (inherits_from_p (type, DECL_CONTEXT (md)))
10965 ta = build_access_to_thisn (ctx, type, 0);
10968 type = (DECL_CONTEXT (TYPE_NAME (type)) ?
10969 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))) : NULL_TREE);
10972 ta = java_complete_tree (ta);
10975 /* We might have to use an access method to get to MD. We can
10976 break the method access rule as far as we're not generating
10978 if (METHOD_PRIVATE (md) && flag_emit_class_files)
10980 md = build_outer_method_access_method (md);
10987 /* Returning a nonzero value indicates we were doing a non static
10988 method invocation that is now a static invocation. It will have
10989 callee displace `this' to insert it in the regular argument
10991 return (non_static_context && to_return);
10994 /* Patch an invoke expression METHOD and ARGS, based on its invocation
10998 patch_invoke (tree patch, tree method, tree args)
11001 tree original_call, t, ta;
11002 tree check = NULL_TREE;
11004 /* Last step for args: convert build-in types. If we're dealing with
11005 a new TYPE() type call, the first argument to the constructor
11006 isn't found in the incoming argument list, but delivered by
11008 t = TYPE_ARG_TYPES (TREE_TYPE (method));
11009 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
11010 t = TREE_CHAIN (t);
11011 for (ta = args; t != end_params_node && ta;
11012 t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
11013 if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
11014 TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
11015 TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
11017 /* Resolve unresolved returned type issues */
11018 t = TREE_TYPE (TREE_TYPE (method));
11019 if (TREE_CODE (t) == POINTER_TYPE && !CLASS_LOADED_P (TREE_TYPE (t)))
11020 resolve_and_layout (TREE_TYPE (t), NULL);
11022 if (flag_emit_class_files)
11026 switch (invocation_mode (method, CALL_USING_SUPER (patch)))
11028 case INVOKE_VIRTUAL:
11029 dtable = invoke_build_dtable (0, args);
11030 func = build_invokevirtual (dtable, method);
11033 case INVOKE_NONVIRTUAL:
11034 /* If the object for the method call is null, we throw an
11035 exception. We don't do this if the object is the current
11036 method's `this'. In other cases we just rely on an
11037 optimization pass to eliminate redundant checks. */
11038 if (TREE_VALUE (args) != current_this)
11040 /* We use a save_expr here to make sure we only evaluate
11041 the new `self' expression once. */
11042 tree save_arg = save_expr (TREE_VALUE (args));
11043 TREE_VALUE (args) = save_arg;
11044 check = java_check_reference (save_arg, 1);
11046 /* Fall through. */
11049 case INVOKE_STATIC:
11051 tree signature = build_java_signature (TREE_TYPE (method));
11052 func = build_known_method_ref (method, TREE_TYPE (method),
11053 DECL_CONTEXT (method),
11058 case INVOKE_INTERFACE:
11059 dtable = invoke_build_dtable (1, args);
11060 func = build_invokeinterface (dtable, method);
11067 /* Ensure self_type is initialized, (invokestatic). FIXME */
11068 func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
11071 TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
11072 TREE_OPERAND (patch, 0) = func;
11073 TREE_OPERAND (patch, 1) = args;
11074 patch = check_for_builtin (method, patch);
11075 original_call = patch;
11077 /* We're processing a `new TYPE ()' form. New is called and its
11078 returned value is the first argument to the constructor. We build
11079 a COMPOUND_EXPR and use saved expression so that the overall NEW
11080 expression value is a pointer to a newly created and initialized
11082 if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
11084 tree class = DECL_CONTEXT (method);
11085 tree c1, saved_new, new;
11088 if (flag_emit_class_files)
11090 TREE_TYPE (patch) = build_pointer_type (class);
11093 if (!TYPE_SIZE (class))
11094 safe_layout_class (class);
11096 (class_has_finalize_method (class) ? alloc_object_node
11097 : alloc_no_finalizer_node);
11098 new = build3 (CALL_EXPR, promote_type (class),
11099 build_address_of (alloc_node),
11100 build_tree_list (NULL_TREE, build_class_ref (class)),
11102 saved_new = save_expr (new);
11103 c1 = build_tree_list (NULL_TREE, saved_new);
11104 TREE_CHAIN (c1) = TREE_OPERAND (original_call, 1);
11105 TREE_OPERAND (original_call, 1) = c1;
11106 TREE_SET_CODE (original_call, CALL_EXPR);
11107 patch = build2 (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new);
11110 /* If CHECK is set, then we are building a check to see if the object
11112 if (check != NULL_TREE)
11114 /* We have to call force_evaluation_order now because creating a
11115 COMPOUND_EXPR wraps the arg list in a way that makes it
11116 unrecognizable by force_evaluation_order later. Yuk. */
11117 patch = build2 (COMPOUND_EXPR, TREE_TYPE (patch), check,
11118 force_evaluation_order (patch));
11119 TREE_SIDE_EFFECTS (patch) = 1;
11122 /* In order to be able to modify PATCH later, we SAVE_EXPR it and
11123 put it as the first expression of a COMPOUND_EXPR. The second
11124 expression being an empty statement to be later patched if
11125 necessary. We remember a TREE_LIST (the PURPOSE is the method,
11126 the VALUE is the compound) in a hashtable and return a
11127 COMPOUND_EXPR built so that the result of the evaluation of the
11128 original PATCH node is returned. */
11129 if (STATIC_CLASS_INIT_OPT_P ()
11130 && current_function_decl && METHOD_STATIC (method))
11133 tree fndecl = current_function_decl;
11134 /* We have to call force_evaluation_order now because creating a
11135 COMPOUND_EXPR wraps the arg list in a way that makes it
11136 unrecognizable by force_evaluation_order later. Yuk. */
11137 tree save = force_evaluation_order (patch);
11138 tree type = TREE_TYPE (patch);
11140 patch = build2 (COMPOUND_EXPR, type, save, build_java_empty_stmt ());
11141 list = tree_cons (method, patch,
11142 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl));
11144 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl) = list;
11146 patch = build2 (COMPOUND_EXPR, type, patch, save);
11153 invocation_mode (tree method, int super)
11155 int access = get_access_flags_from_decl (method);
11158 return INVOKE_SUPER;
11160 if (access & ACC_STATIC)
11161 return INVOKE_STATIC;
11163 /* We have to look for a constructor before we handle nonvirtual
11164 calls; otherwise the constructor will look nonvirtual. */
11165 if (DECL_CONSTRUCTOR_P (method))
11166 return INVOKE_STATIC;
11168 if (access & ACC_PRIVATE)
11169 return INVOKE_NONVIRTUAL;
11171 /* Binary compatibility: just because it's final today, that doesn't
11172 mean it'll be final tomorrow. */
11173 if (! flag_indirect_dispatch
11174 || DECL_CONTEXT (method) == object_type_node)
11176 if (access & ACC_FINAL)
11177 return INVOKE_NONVIRTUAL;
11179 if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
11180 return INVOKE_NONVIRTUAL;
11183 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
11184 return INVOKE_INTERFACE;
11186 return INVOKE_VIRTUAL;
11189 /* Retrieve a refined list of matching methods. It covers the step
11190 15.11.2 (Compile-Time Step 2) */
11193 lookup_method_invoke (int lc, tree cl, tree class, tree name, tree arg_list)
11195 tree atl = end_params_node; /* Arg Type List */
11196 tree method, signature, list, node;
11197 const char *candidates; /* Used for error report */
11200 /* Fix the arguments */
11201 for (node = arg_list; node; node = TREE_CHAIN (node))
11203 tree current_arg = TREE_TYPE (TREE_VALUE (node));
11204 /* Non primitive type may have to be resolved */
11205 if (!JPRIMITIVE_TYPE_P (current_arg))
11206 resolve_and_layout (current_arg, NULL_TREE);
11208 if (TREE_CODE (current_arg) == RECORD_TYPE)
11209 current_arg = promote_type (current_arg);
11210 atl = tree_cons (NULL_TREE, current_arg, atl);
11213 /* Presto. If we're dealing with an anonymous class and a
11214 constructor call, generate the right constructor now, since we
11215 know the arguments' types. */
11217 if (lc && ANONYMOUS_CLASS_P (class))
11219 tree mdecl = craft_constructor (TYPE_NAME (class), atl);
11220 /* The anonymous class may have already been laid out, so make sure
11221 the new constructor is laid out here. */
11222 layout_class_method (class, CLASSTYPE_SUPER (class), mdecl, NULL_TREE);
11225 /* Find all candidates and then refine the list, searching for the
11226 most specific method. */
11227 list = find_applicable_accessible_methods_list (lc, class, name, atl);
11228 list = find_most_specific_methods_list (list);
11229 if (list && !TREE_CHAIN (list))
11230 return TREE_VALUE (list);
11232 /* Issue an error. List candidates if any. Candidates are listed
11233 only if accessible (non accessible methods may end-up here for
11234 the sake of a better error report). */
11239 obstack_grow (&temporary_obstack, ". Candidates are:\n", 18);
11240 for (current = list; current; current = TREE_CHAIN (current))
11242 tree cm = TREE_VALUE (current);
11243 char string [4096];
11244 if (!cm || not_accessible_p (class, cm, NULL_TREE, 0))
11247 (string, " '%s' in '%s'%s",
11248 get_printable_method_name (cm),
11249 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
11250 (TREE_CHAIN (current) ? "\n" : ""));
11251 obstack_grow (&temporary_obstack, string, strlen (string));
11253 obstack_1grow (&temporary_obstack, '\0');
11254 candidates = obstack_finish (&temporary_obstack);
11256 /* Issue the error message */
11257 method = make_node (FUNCTION_TYPE);
11258 TYPE_ARG_TYPES (method) = atl;
11259 signature = build_java_argument_signature (method);
11260 dup = xstrdup (lang_printable_name (class, 0));
11261 parse_error_context (cl, "Can't find %s %<%s(%s)%> in type %qs%s",
11262 (lc ? "constructor" : "method"),
11263 (lc ? dup : IDENTIFIER_POINTER (name)),
11264 IDENTIFIER_POINTER (signature), dup,
11265 (candidates ? candidates : ""));
11270 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
11271 when we're looking for a constructor. */
11274 find_applicable_accessible_methods_list (int lc, tree class, tree name,
11277 static htab_t searched_classes;
11278 static int search_not_done = 0;
11279 tree list = NULL_TREE, all_list = NULL_TREE;
11283 /* Check the hash table to determine if this class has been searched
11285 if (searched_classes)
11287 if (htab_find (searched_classes, class) != NULL)
11292 searched_classes = htab_create (10, htab_hash_pointer,
11293 htab_eq_pointer, NULL);
11297 *htab_find_slot (searched_classes, class, INSERT) = class;
11299 if (!CLASS_LOADED_P (class))
11301 load_class (class, 1);
11302 safe_layout_class (class);
11305 /* Search interfaces */
11306 if (TREE_CODE (TYPE_NAME (class)) == TYPE_DECL
11307 && CLASS_INTERFACE (TYPE_NAME (class)))
11309 search_applicable_methods_list (lc, TYPE_METHODS (class),
11310 name, arglist, &list, &all_list);
11311 for (i = 1; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
11313 tree t = BINFO_TYPE (base_binfo);
11316 rlist = find_applicable_accessible_methods_list (lc, t, name,
11318 list = chainon (rlist, list);
11321 /* Search classes */
11324 search_applicable_methods_list (lc, TYPE_METHODS (class),
11325 name, arglist, &list, &all_list);
11327 /* When looking finit$, class$ or instinit$, we turn LC to 1 so
11328 that we only search in class. Note that we should have found
11329 something at this point. */
11330 if (ID_FINIT_P (name) || ID_CLASSDOLLAR_P (name) || ID_INSTINIT_P (name))
11337 /* We must search all interfaces of this class */
11341 BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
11343 tree t = BINFO_TYPE (base_binfo);
11344 if (t != object_type_node)
11347 = find_applicable_accessible_methods_list (lc, t,
11349 list = chainon (rlist, list);
11354 /* Search superclass */
11355 if (!lc && CLASSTYPE_SUPER (class) != NULL_TREE)
11358 class = CLASSTYPE_SUPER (class);
11359 rlist = find_applicable_accessible_methods_list (lc, class,
11361 list = chainon (rlist, list);
11367 /* We're done. Reset the searched classes list and finally search
11368 java.lang.Object if it wasn't searched already. */
11369 if (!search_not_done)
11372 && TYPE_METHODS (object_type_node)
11373 && htab_find (searched_classes, object_type_node) == NULL)
11375 search_applicable_methods_list (lc,
11376 TYPE_METHODS (object_type_node),
11377 name, arglist, &list, &all_list);
11379 htab_delete (searched_classes);
11380 searched_classes = NULL;
11383 /* Either return the list obtained or all selected (but
11384 inaccessible) methods for better error report. */
11385 return (!list ? all_list : list);
11388 /* Effectively search for the appropriate method in method */
11391 search_applicable_methods_list (int lc, tree method, tree name, tree arglist,
11392 tree *list, tree *all_list)
11394 for (; method; method = TREE_CHAIN (method))
11396 /* When dealing with constructor, stop here, otherwise search
11398 if (lc && !DECL_CONSTRUCTOR_P (method))
11400 else if (!lc && (DECL_CONSTRUCTOR_P (method)
11401 || (DECL_NAME (method) != name)))
11404 if (argument_types_convertible (method, arglist))
11406 /* Retain accessible methods only */
11407 if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
11408 method, NULL_TREE, 0))
11409 *list = tree_cons (NULL_TREE, method, *list);
11411 /* Also retain all selected method here */
11412 *all_list = tree_cons (NULL_TREE, method, *list);
11417 /* 15.11.2.2 Choose the Most Specific Method */
11420 find_most_specific_methods_list (tree list)
11423 int abstract, candidates;
11424 tree current, new_list = NULL_TREE;
11425 for (current = list; current; current = TREE_CHAIN (current))
11428 DECL_SPECIFIC_COUNT (TREE_VALUE (current)) = 0;
11430 for (method = list; method; method = TREE_CHAIN (method))
11432 tree method_v, current_v;
11433 /* Don't test a method against itself */
11434 if (method == current)
11437 method_v = TREE_VALUE (method);
11438 current_v = TREE_VALUE (current);
11440 /* Compare arguments and location where methods where declared */
11441 if (argument_types_convertible (method_v, current_v))
11443 if (valid_method_invocation_conversion_p
11444 (DECL_CONTEXT (method_v), DECL_CONTEXT (current_v)))
11446 int v = (DECL_SPECIFIC_COUNT (current_v) += 1);
11447 max = (v > max ? v : max);
11453 /* Review the list and select the maximally specific methods */
11454 for (current = list, abstract = -1, candidates = -1;
11455 current; current = TREE_CHAIN (current))
11456 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
11458 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
11459 abstract += (METHOD_ABSTRACT (TREE_VALUE (current)) ? 1 : 0);
11463 /* If we have several and they're all abstract, just pick the
11465 if (candidates > 0 && candidates == abstract)
11467 /* FIXME: merge the throws clauses. There is no convenient way
11468 to do this in gcj right now, since ideally we'd like to
11469 introduce a new METHOD_DECL here, but that is really not
11471 new_list = nreverse (new_list);
11472 TREE_CHAIN (new_list) = NULL_TREE;
11476 /* We have several (we couldn't find a most specific), all but one
11477 are abstract, we pick the only non abstract one. */
11478 if (candidates > 0 && (candidates == abstract+1))
11480 for (current = new_list; current; current = TREE_CHAIN (current))
11481 if (!METHOD_ABSTRACT (TREE_VALUE (current)))
11483 TREE_CHAIN (current) = NULL_TREE;
11484 new_list = current;
11488 /* If we can't find one, lower expectations and try to gather multiple
11489 maximally specific methods */
11490 while (!new_list && max)
11494 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
11495 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
11502 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
11503 converted by method invocation conversion (5.3) to the type of the
11504 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
11505 to change less often than M1. */
11507 static GTY(()) tree m2_arg_value;
11508 static GTY(()) tree m2_arg_cache;
11511 argument_types_convertible (tree m1, tree m2_or_arglist)
11513 tree m1_arg, m2_arg;
11515 SKIP_THIS_AND_ARTIFICIAL_PARMS (m1_arg, m1)
11517 if (m2_arg_value == m2_or_arglist)
11518 m2_arg = m2_arg_cache;
11521 /* M2_OR_ARGLIST can be a function DECL or a raw list of
11523 if (m2_or_arglist && TREE_CODE (m2_or_arglist) == FUNCTION_DECL)
11525 m2_arg = TYPE_ARG_TYPES (TREE_TYPE (m2_or_arglist));
11526 if (!METHOD_STATIC (m2_or_arglist))
11527 m2_arg = TREE_CHAIN (m2_arg);
11530 m2_arg = m2_or_arglist;
11532 m2_arg_value = m2_or_arglist;
11533 m2_arg_cache = m2_arg;
11536 while (m1_arg != end_params_node && m2_arg != end_params_node)
11538 resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
11539 if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
11540 TREE_VALUE (m2_arg)))
11542 m1_arg = TREE_CHAIN (m1_arg);
11543 m2_arg = TREE_CHAIN (m2_arg);
11545 return m1_arg == end_params_node && m2_arg == end_params_node;
11548 /* Qualification routines */
11550 /* Given a name x.y.z, look up x locally. If it's found, save the
11551 decl. If it's not found, mark the name as RESOLVE_PACKAGE_NAME_P,
11552 so that we later try and load the appropriate classes. */
11554 qualify_ambiguous_name (tree id)
11558 /* We inspect the first item of the qualification list. As a sanity
11559 check, make sure that it is an identfier node. */
11560 tree qual = EXPR_WFL_QUALIFICATION (id);
11561 tree qual_wfl = QUAL_WFL (qual);
11563 if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
11566 name = EXPR_WFL_NODE (qual_wfl);
11568 /* If we don't have an identifier, or we have a 'this' or 'super',
11569 then field access processing is all we need : there is nothing
11571 if (!name || TREE_CODE (name) != IDENTIFIER_NODE ||
11572 name == this_identifier_node ||
11573 name == super_identifier_node)
11576 /* If name appears within the scope of a local variable declaration
11577 or parameter declaration, or is a field within an enclosing
11578 class, then it is an expression name. Save the decl and let
11579 resolve_field_access do it's work. */
11580 if ((decl = IDENTIFIER_LOCAL_VALUE (name)) ||
11581 (decl = lookup_field_wrapper (current_class, name)))
11583 QUAL_RESOLUTION (qual) = decl;
11587 /* If name is a known class name (either declared or imported), mark
11588 us as a type name. */
11589 if ((decl = resolve_and_layout (name, NULL_TREE)))
11591 RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
11592 QUAL_RESOLUTION (qual) = decl;
11595 /* Check here that NAME isn't declared by more than one
11596 type-import-on-demand declaration of the compilation unit
11597 containing NAME. FIXME */
11599 /* We couldn't find a declaration for the name. Assume for now that
11600 we have a qualified class name that needs to be loaded from an
11601 external class file. */
11603 RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
11605 /* Propagate the qualification across other components of the
11607 for (qual = TREE_CHAIN (qual); qual;
11608 qual_wfl = QUAL_WFL (qual), qual = TREE_CHAIN (qual))
11610 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
11611 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
11614 /* Store the global qualification for the ambiguous part of ID back
11616 if (RESOLVE_TYPE_NAME_P (qual_wfl))
11617 RESOLVE_TYPE_NAME_P (id) = 1;
11618 else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
11619 RESOLVE_PACKAGE_NAME_P (id) = 1;
11622 /* Patch tree nodes in a function body. When a BLOCK is found, push
11623 local variable decls if present.
11624 Same as java_complete_lhs, but does resolve static finals to values. */
11627 java_complete_tree (tree node)
11629 node = java_complete_lhs (node);
11630 if (JDECL_P (node) && CLASS_FINAL_VARIABLE_P (node)
11631 && DECL_INITIAL (node) != NULL_TREE)
11633 tree value = fold_constant_for_init (node, node);
11634 if (value != NULL_TREE)
11641 java_stabilize_reference (tree node)
11643 if (TREE_CODE (node) == COMPOUND_EXPR)
11645 tree op0 = TREE_OPERAND (node, 0);
11646 tree op1 = TREE_OPERAND (node, 1);
11647 TREE_OPERAND (node, 0) = save_expr (op0);
11648 TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
11651 return stabilize_reference (node);
11654 /* Patch tree nodes in a function body. When a BLOCK is found, push
11655 local variable decls if present.
11656 Same as java_complete_tree, but does not resolve static finals to values. */
11659 java_complete_lhs (tree node)
11661 tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
11664 /* CONVERT_EXPR always has its type set, even though it needs to be
11666 if (TREE_TYPE (node) && TREE_CODE (node) != CONVERT_EXPR)
11669 /* The switch block implements cases processing container nodes
11670 first. Contained nodes are always written back. Leaves come
11671 next and return a value. */
11672 switch (TREE_CODE (node))
11676 /* 1- Block section.
11677 Set the local values on decl names so we can identify them
11678 faster when they're referenced. At that stage, identifiers
11679 are legal so we don't check for declaration errors. */
11680 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
11682 DECL_CONTEXT (cn) = current_function_decl;
11683 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
11685 if (BLOCK_EXPR_BODY (node) == NULL_TREE)
11686 CAN_COMPLETE_NORMALLY (node) = 1;
11689 tree stmt = BLOCK_EXPR_BODY (node);
11691 int error_seen = 0;
11692 if (TREE_CODE (stmt) == COMPOUND_EXPR)
11694 /* Re-order from (((A; B); C); ...; Z) to
11695 (A; (B; (C ; (...; Z)))).
11696 This makes it easier to scan the statements left-to-right
11697 without using recursion (which might overflow the stack
11698 if the block has many statements. */
11701 tree left = TREE_OPERAND (stmt, 0);
11702 if (TREE_CODE (left) != COMPOUND_EXPR)
11704 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
11705 TREE_OPERAND (left, 1) = stmt;
11708 BLOCK_EXPR_BODY (node) = stmt;
11711 /* Now do the actual complete, without deep recursion for
11713 ptr = &BLOCK_EXPR_BODY (node);
11714 while (TREE_CODE (*ptr) == COMPOUND_EXPR
11715 && !IS_EMPTY_STMT (TREE_OPERAND (*ptr, 1)))
11717 tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
11718 tree *next = &TREE_OPERAND (*ptr, 1);
11719 TREE_OPERAND (*ptr, 0) = cur;
11720 if (IS_EMPTY_STMT (cur))
11722 /* Optimization; makes it easier to detect empty bodies.
11723 Most useful for <clinit> with all-constant initializer. */
11727 if (TREE_CODE (cur) == ERROR_MARK)
11729 else if (! CAN_COMPLETE_NORMALLY (cur))
11734 if (TREE_CODE (wfl_op2) == BLOCK)
11735 wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
11736 else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
11737 wfl_op2 = TREE_OPERAND (wfl_op2, 0);
11741 if (TREE_CODE (wfl_op2) != CASE_EXPR
11742 && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
11743 unreachable_stmt_error (*ptr);
11745 if (TREE_TYPE (*ptr) == NULL_TREE)
11746 TREE_TYPE (*ptr) = void_type_node;
11749 *ptr = java_complete_tree (*ptr);
11751 if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
11752 return error_mark_node;
11753 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
11755 /* Turn local bindings to null */
11756 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
11757 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = NULL_TREE;
11759 TREE_TYPE (node) = void_type_node;
11762 /* 2- They are expressions but ultimately deal with statements */
11765 wfl_op1 = TREE_OPERAND (node, 0);
11766 COMPLETE_CHECK_OP_0 (node);
11767 /* 14.19 A throw statement cannot complete normally. */
11768 CAN_COMPLETE_NORMALLY (node) = 0;
11769 return patch_throw_statement (node, wfl_op1);
11771 case SYNCHRONIZED_EXPR:
11772 wfl_op1 = TREE_OPERAND (node, 0);
11773 return patch_synchronized_statement (node, wfl_op1);
11776 return patch_try_statement (node);
11778 case TRY_FINALLY_EXPR:
11779 COMPLETE_CHECK_OP_0 (node);
11780 COMPLETE_CHECK_OP_1 (node);
11781 if (IS_EMPTY_STMT (TREE_OPERAND (node, 0)))
11782 /* Reduce try/finally nodes with an empty try block. */
11783 return TREE_OPERAND (node, 1);
11784 if (IS_EMPTY_STMT (TREE_OPERAND (node, 1)))
11785 /* Likewise for an empty finally block. */
11786 return TREE_OPERAND (node, 0);
11787 CAN_COMPLETE_NORMALLY (node)
11788 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
11789 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
11790 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
11793 case LABELED_BLOCK_EXPR:
11794 PUSH_LABELED_BLOCK (node);
11795 if (LABELED_BLOCK_BODY (node))
11796 COMPLETE_CHECK_OP_1 (node);
11797 TREE_TYPE (node) = void_type_node;
11798 POP_LABELED_BLOCK ();
11800 if (IS_EMPTY_STMT (LABELED_BLOCK_BODY (node)))
11802 LABELED_BLOCK_BODY (node) = NULL_TREE;
11803 CAN_COMPLETE_NORMALLY (node) = 1;
11805 else if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
11806 CAN_COMPLETE_NORMALLY (node) = 1;
11809 case EXIT_BLOCK_EXPR:
11810 return patch_bc_statement (node);
11813 cn = java_complete_tree (TREE_OPERAND (node, 0));
11814 if (cn == error_mark_node)
11817 /* First, the case expression must be constant. Values of final
11818 fields are accepted. */
11819 nn = fold_constant_for_init (cn, NULL_TREE);
11820 if (nn != NULL_TREE)
11824 if ((TREE_CODE (cn) == COMPOUND_EXPR
11825 || TREE_CODE (cn) == COMPONENT_REF)
11826 && JDECL_P (TREE_OPERAND (cn, 1))
11827 && FIELD_FINAL (TREE_OPERAND (cn, 1))
11828 && DECL_INITIAL (TREE_OPERAND (cn, 1)))
11830 cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
11831 TREE_OPERAND (cn, 1));
11833 /* Accept final locals too. */
11834 else if (TREE_CODE (cn) == VAR_DECL && DECL_FINAL (cn)
11835 && DECL_INITIAL (cn))
11836 cn = fold_constant_for_init (DECL_INITIAL (cn), cn);
11838 if (!TREE_CONSTANT (cn))
11840 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11841 parse_error_context (node, "Constant expression required");
11842 return error_mark_node;
11845 nn = ctxp->current_loop;
11847 /* It must be assignable to the type of the switch expression. */
11848 if (!try_builtin_assignconv (NULL_TREE,
11849 TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
11851 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11852 parse_error_context
11854 "Incompatible type for case. Can't convert %qs to %<int%>",
11855 lang_printable_name (TREE_TYPE (cn), 0));
11856 return error_mark_node;
11859 cn = fold (convert (int_type_node, cn));
11860 TREE_CONSTANT_OVERFLOW (cn) = 0;
11861 CAN_COMPLETE_NORMALLY (cn) = 1;
11863 /* Save the label on a list so that we can later check for
11865 case_label_list = tree_cons (node, cn, case_label_list);
11867 /* Multiple instance of a case label bearing the same value is
11868 checked later. The case expression is all right so far. */
11869 if (TREE_CODE (cn) == VAR_DECL)
11870 cn = DECL_INITIAL (cn);
11871 TREE_OPERAND (node, 0) = cn;
11872 TREE_TYPE (node) = void_type_node;
11873 CAN_COMPLETE_NORMALLY (node) = 1;
11874 TREE_SIDE_EFFECTS (node) = 1;
11878 nn = ctxp->current_loop;
11879 /* Only one default label is allowed per switch statement */
11880 if (SWITCH_HAS_DEFAULT (nn))
11882 #ifdef USE_MAPPED_LOCATION
11883 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
11885 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11887 parse_error_context (wfl_operator,
11888 "Duplicate case label: %<default%>");
11889 return error_mark_node;
11892 SWITCH_HAS_DEFAULT (nn) = 1;
11893 TREE_TYPE (node) = void_type_node;
11894 TREE_SIDE_EFFECTS (node) = 1;
11895 CAN_COMPLETE_NORMALLY (node) = 1;
11901 /* Check whether the loop was enclosed in a labeled
11902 statement. If not, create one, insert the loop in it and
11904 nn = patch_loop_statement (node);
11906 /* Anyways, walk the body of the loop */
11907 if (TREE_CODE (node) == LOOP_EXPR)
11908 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11909 /* Switch statement: walk the switch expression and the cases */
11911 node = patch_switch_statement (node);
11913 if (node == error_mark_node || TREE_OPERAND (node, 0) == error_mark_node)
11914 nn = error_mark_node;
11917 TREE_TYPE (nn) = TREE_TYPE (node) = void_type_node;
11918 /* If we returned something different, that's because we
11919 inserted a label. Pop the label too. */
11922 if (CAN_COMPLETE_NORMALLY (node))
11923 CAN_COMPLETE_NORMALLY (nn) = 1;
11924 POP_LABELED_BLOCK ();
11931 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11932 return patch_exit_expr (node);
11936 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11937 if (TREE_OPERAND (node, 0) == error_mark_node)
11938 return error_mark_node;
11939 /* then-else branches */
11940 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
11941 if (TREE_OPERAND (node, 1) == error_mark_node)
11942 return error_mark_node;
11944 /* This is a special case due to build_assertion(). When
11945 assertions are disabled we build a COND_EXPR in which
11946 Operand 1 is the body of the assertion. If that happens to
11947 be a string concatenation we'll need to patch it here. */
11948 tree patched = patch_string (TREE_OPERAND (node, 1));
11950 TREE_OPERAND (node, 1) = patched;
11952 TREE_OPERAND (node, 2) = java_complete_tree (TREE_OPERAND (node, 2));
11953 if (TREE_OPERAND (node, 2) == error_mark_node)
11954 return error_mark_node;
11955 return patch_if_else_statement (node);
11958 case CONDITIONAL_EXPR:
11960 wfl_op1 = TREE_OPERAND (node, 0);
11961 COMPLETE_CHECK_OP_0 (node);
11962 wfl_op2 = TREE_OPERAND (node, 1);
11963 COMPLETE_CHECK_OP_1 (node);
11964 wfl_op3 = TREE_OPERAND (node, 2);
11965 COMPLETE_CHECK_OP_2 (node);
11966 return patch_conditional_expr (node, wfl_op1, wfl_op2);
11968 /* 3- Expression section */
11969 case COMPOUND_EXPR:
11970 wfl_op2 = TREE_OPERAND (node, 1);
11971 TREE_OPERAND (node, 0) = nn =
11972 java_complete_tree (TREE_OPERAND (node, 0));
11973 if (IS_EMPTY_STMT (wfl_op2))
11974 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
11977 if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
11979 /* An unreachable condition in a do-while statement
11980 is *not* (technically) an unreachable statement. */
11982 if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
11983 nn = EXPR_WFL_NODE (nn);
11984 /* NN can be NULL_TREE exactly when UPDATE is, in
11985 finish_for_loop. */
11986 if (nn != NULL_TREE && TREE_CODE (nn) != EXIT_EXPR)
11988 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
11989 if (SUPPRESS_UNREACHABLE_ERROR (nn))
11991 /* Perhaps this warning should have an
11992 associated flag. The code being compiled is
11993 pedantically correct, but useless. */
11994 parse_warning_context (wfl_operator,
11995 "Unreachable statement");
11998 parse_error_context (wfl_operator,
11999 "Unreachable statement");
12002 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
12003 if (TREE_OPERAND (node, 1) == error_mark_node)
12004 return error_mark_node;
12005 /* Even though we might allow the case where the first
12006 operand doesn't return normally, we still should compute
12007 CAN_COMPLETE_NORMALLY correctly. */
12008 CAN_COMPLETE_NORMALLY (node)
12009 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
12010 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
12012 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
12016 /* CAN_COMPLETE_NORMALLY (node) = 0; */
12017 return patch_return (node);
12019 case EXPR_WITH_FILE_LOCATION:
12020 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
12021 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
12023 node = resolve_expression_name (node, NULL);
12024 if (node == error_mark_node)
12026 CAN_COMPLETE_NORMALLY (node) = 1;
12031 location_t save_location = input_location;
12032 #ifdef USE_MAPPED_LOCATION
12033 input_location = EXPR_LOCATION (node);
12034 if (input_location == UNKNOWN_LOCATION)
12035 input_location = save_location;
12037 input_line = EXPR_WFL_LINENO (node);
12039 body = java_complete_tree (EXPR_WFL_NODE (node));
12040 input_location = save_location;
12041 EXPR_WFL_NODE (node) = body;
12042 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
12043 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
12044 if (IS_EMPTY_STMT (body) || TREE_CONSTANT (body))
12046 /* Makes it easier to constant fold, detect empty bodies. */
12049 if (body == error_mark_node)
12051 /* Its important for the evaluation of assignment that
12052 this mark on the TREE_TYPE is propagated. */
12053 TREE_TYPE (node) = error_mark_node;
12054 return error_mark_node;
12057 TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
12062 case NEW_ARRAY_EXPR:
12063 /* Patch all the dimensions */
12065 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
12067 int location = EXPR_WFL_LINECOL (TREE_VALUE (cn));
12068 tree dim = convert (int_type_node,
12069 java_complete_tree (TREE_VALUE (cn)));
12070 if (dim == error_mark_node)
12077 TREE_VALUE (cn) = dim;
12078 /* Setup the location of the current dimension, for
12079 later error report. */
12080 #ifdef USE_MAPPED_LOCATION
12081 TREE_PURPOSE (cn) = expr_add_location (NULL_TREE, location, 0);
12083 TREE_PURPOSE (cn) =
12084 build_expr_wfl (NULL_TREE, input_filename, 0, 0);
12085 EXPR_WFL_LINECOL (TREE_PURPOSE (cn)) = location;
12089 /* They complete the array creation expression, if no errors
12091 CAN_COMPLETE_NORMALLY (node) = 1;
12092 return (flag ? error_mark_node
12093 : force_evaluation_order (patch_newarray (node)));
12095 case NEW_ANONYMOUS_ARRAY_EXPR:
12096 /* Create the array type if necessary. */
12097 if (ANONYMOUS_ARRAY_DIMS_SIG (node))
12099 tree type = ANONYMOUS_ARRAY_BASE_TYPE (node);
12100 if (!(type = resolve_type_during_patch (type)))
12101 return error_mark_node;
12102 type = build_array_from_name (type, NULL_TREE,
12103 ANONYMOUS_ARRAY_DIMS_SIG (node), NULL);
12104 ANONYMOUS_ARRAY_BASE_TYPE (node) = build_pointer_type (type);
12106 node = patch_new_array_init (ANONYMOUS_ARRAY_BASE_TYPE (node),
12107 ANONYMOUS_ARRAY_INITIALIZER (node));
12108 if (node == error_mark_node)
12109 return error_mark_node;
12110 CAN_COMPLETE_NORMALLY (node) = 1;
12113 case NEW_CLASS_EXPR:
12115 /* Complete function's argument(s) first */
12116 if (complete_function_arguments (node))
12117 return error_mark_node;
12120 tree decl, wfl = TREE_OPERAND (node, 0);
12121 int in_this = CALL_THIS_CONSTRUCTOR_P (node);
12122 int from_super = (EXPR_WFL_NODE (TREE_OPERAND (node, 0)) ==
12123 super_identifier_node);
12125 #ifdef USE_MAPPED_LOCATION
12126 source_location location = EXPR_LOCATION (node);
12128 int location = EXPR_WFL_LINECOL (node);
12131 node = patch_method_invocation (node, NULL_TREE, NULL_TREE,
12132 from_super, 0, &decl);
12133 if (node == error_mark_node)
12134 return error_mark_node;
12136 if (TREE_CODE (node) == CALL_EXPR
12137 && TREE_OPERAND (node, 1) != NULL_TREE)
12138 arguments = TREE_VALUE (TREE_OPERAND (node, 1));
12140 arguments = NULL_TREE;
12141 check_thrown_exceptions (location, decl, arguments);
12142 /* If we call this(...), register signature and positions */
12144 DECL_CONSTRUCTOR_CALLS (current_function_decl) =
12145 tree_cons (wfl, decl,
12146 DECL_CONSTRUCTOR_CALLS (current_function_decl));
12147 CAN_COMPLETE_NORMALLY (node) = 1;
12148 return force_evaluation_order (node);
12152 /* Save potential wfls */
12153 wfl_op1 = TREE_OPERAND (node, 0);
12154 TREE_OPERAND (node, 0) = nn = java_complete_lhs (wfl_op1);
12156 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node)
12157 && TREE_CODE (nn) == VAR_DECL && TREE_STATIC (nn)
12158 && DECL_INITIAL (nn) != NULL_TREE)
12162 value = fold_constant_for_init (nn, nn);
12164 /* When we have a primitype type, or a string and we're not
12165 emitting a class file, we actually don't want to generate
12166 anything for the assignment. */
12167 if (value != NULL_TREE &&
12168 (JPRIMITIVE_TYPE_P (TREE_TYPE (value)) ||
12169 (TREE_TYPE (value) == string_ptr_type_node &&
12170 ! flag_emit_class_files)))
12172 /* Prepare node for patch_assignment */
12173 TREE_OPERAND (node, 1) = value;
12174 /* Call patch assignment to verify the assignment */
12175 if (patch_assignment (node, wfl_op1) == error_mark_node)
12176 return error_mark_node;
12177 /* Set DECL_INITIAL properly (a conversion might have
12178 been decided by patch_assignment) and return the
12179 empty statement. */
12182 tree patched = patch_string (TREE_OPERAND (node, 1));
12184 DECL_INITIAL (nn) = patched;
12186 DECL_INITIAL (nn) = TREE_OPERAND (node, 1);
12187 DECL_FIELD_FINAL_IUD (nn) = 1;
12188 return build_java_empty_stmt ();
12191 if (! flag_emit_class_files)
12192 DECL_INITIAL (nn) = NULL_TREE;
12194 wfl_op2 = TREE_OPERAND (node, 1);
12196 if (TREE_OPERAND (node, 0) == error_mark_node)
12197 return error_mark_node;
12199 flag = COMPOUND_ASSIGN_P (wfl_op2);
12202 /* This might break when accessing outer field from inner
12203 class. TESTME, FIXME */
12204 tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0));
12206 /* Hand stabilize the lhs on both places */
12207 TREE_OPERAND (node, 0) = lvalue;
12208 TREE_OPERAND (TREE_OPERAND (node, 1), 0) =
12209 (flag_emit_class_files ? lvalue : save_expr (lvalue));
12211 /* 15.25.2.a: Left hand is not an array access. FIXME */
12212 /* Now complete the RHS. We write it back later on. */
12213 nn = java_complete_tree (TREE_OPERAND (node, 1));
12215 if ((cn = patch_string (nn)))
12218 /* The last part of the rewrite for E1 op= E2 is to have
12219 E1 = (T)(E1 op E2), with T being the type of E1. */
12220 nn = java_complete_tree (build_cast (EXPR_WFL_LINECOL (wfl_op2),
12221 TREE_TYPE (lvalue), nn));
12223 /* If the assignment is compound and has reference type,
12224 then ensure the LHS has type String and nothing else. */
12225 if (JREFERENCE_TYPE_P (TREE_TYPE (lvalue))
12226 && ! JSTRING_TYPE_P (TREE_TYPE (lvalue)))
12227 parse_error_context (wfl_op2,
12228 "Incompatible type for %<+=%>. Can't convert %qs to %<java.lang.String%>",
12229 lang_printable_name (TREE_TYPE (lvalue), 0));
12231 /* 15.25.2.b: Left hand is an array access. FIXME */
12234 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
12235 function to complete this RHS. Note that a NEW_ARRAY_INIT
12236 might have been already fully expanded if created as a result
12237 of processing an anonymous array initializer. We avoid doing
12238 the operation twice by testing whether the node already bears
12240 else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT && !TREE_TYPE (wfl_op2))
12241 nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
12242 TREE_OPERAND (node, 1));
12243 /* Otherwise we simply complete the RHS */
12245 nn = java_complete_tree (TREE_OPERAND (node, 1));
12247 if (nn == error_mark_node)
12248 return error_mark_node;
12250 /* Write back the RHS as we evaluated it. */
12251 TREE_OPERAND (node, 1) = nn;
12253 /* In case we're handling = with a String as a RHS, we need to
12254 produce a String out of the RHS (it might still be a
12255 STRING_CST or a StringBuffer at this stage */
12256 if ((nn = patch_string (TREE_OPERAND (node, 1))))
12257 TREE_OPERAND (node, 1) = nn;
12259 if ((nn = nested_field_access_fix (wfl_op1, TREE_OPERAND (node, 0),
12260 TREE_OPERAND (node, 1))))
12262 /* We return error_mark_node if nested_field_access_fix
12263 detects we write into a final. */
12264 if (nn == error_mark_node)
12265 return error_mark_node;
12270 node = patch_assignment (node, wfl_op1);
12271 if (node == error_mark_node)
12272 return error_mark_node;
12273 /* Reorganize the tree if necessary. */
12274 if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node))
12275 || JSTRING_P (TREE_TYPE (node))))
12276 node = java_refold (node);
12279 /* Seek to set DECL_INITIAL to a proper value, since it might have
12280 undergone a conversion in patch_assignment. We do that only when
12281 it's necessary to have DECL_INITIAL properly set. */
12282 nn = TREE_OPERAND (node, 0);
12283 if (TREE_CODE (nn) == VAR_DECL
12284 && DECL_INITIAL (nn) && CONSTANT_VALUE_P (DECL_INITIAL (nn))
12285 && FIELD_STATIC (nn) && FIELD_FINAL (nn)
12286 && (JPRIMITIVE_TYPE_P (TREE_TYPE (nn))
12287 || TREE_TYPE (nn) == string_ptr_type_node))
12288 DECL_INITIAL (nn) = TREE_OPERAND (node, 1);
12290 CAN_COMPLETE_NORMALLY (node) = 1;
12302 case TRUNC_MOD_EXPR:
12303 case TRUNC_DIV_EXPR:
12305 case TRUTH_ANDIF_EXPR:
12306 case TRUTH_ORIF_EXPR:
12313 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
12314 knows how to handle those cases. */
12315 wfl_op1 = TREE_OPERAND (node, 0);
12316 wfl_op2 = TREE_OPERAND (node, 1);
12318 CAN_COMPLETE_NORMALLY (node) = 1;
12319 /* Don't complete string nodes if dealing with the PLUS operand. */
12320 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
12322 nn = java_complete_tree (wfl_op1);
12323 if (nn == error_mark_node)
12324 return error_mark_node;
12326 TREE_OPERAND (node, 0) = nn;
12328 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
12330 nn = java_complete_tree (wfl_op2);
12331 if (nn == error_mark_node)
12332 return error_mark_node;
12334 TREE_OPERAND (node, 1) = nn;
12336 return patch_binop (node, wfl_op1, wfl_op2, 0);
12338 case INSTANCEOF_EXPR:
12339 wfl_op1 = TREE_OPERAND (node, 0);
12340 COMPLETE_CHECK_OP_0 (node);
12341 return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1), 0);
12343 case UNARY_PLUS_EXPR:
12345 case TRUTH_NOT_EXPR:
12347 case PREDECREMENT_EXPR:
12348 case PREINCREMENT_EXPR:
12349 case POSTDECREMENT_EXPR:
12350 case POSTINCREMENT_EXPR:
12352 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
12353 how to handle those cases. */
12354 wfl_op1 = TREE_OPERAND (node, 0);
12355 CAN_COMPLETE_NORMALLY (node) = 1;
12356 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
12357 if (TREE_OPERAND (node, 0) == error_mark_node)
12358 return error_mark_node;
12359 node = patch_unaryop (node, wfl_op1);
12360 CAN_COMPLETE_NORMALLY (node) = 1;
12364 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
12365 how to handle those cases. */
12366 wfl_op1 = TREE_OPERAND (node, 0);
12367 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
12368 if (TREE_OPERAND (node, 0) == error_mark_node)
12369 return error_mark_node;
12370 if (!flag_emit_class_files)
12371 TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
12372 /* The same applies to wfl_op2 */
12373 wfl_op2 = TREE_OPERAND (node, 1);
12374 TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
12375 if (TREE_OPERAND (node, 1) == error_mark_node)
12376 return error_mark_node;
12377 if (!flag_emit_class_files)
12378 TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
12379 return patch_array_ref (node);
12384 case COMPONENT_REF:
12385 /* The first step in the re-write of qualified name handling. FIXME.
12386 So far, this is only to support PRIMTYPE.class ->
12389 tree prim_class = TREE_OPERAND (node, 0);
12390 tree name = TREE_OPERAND (node, 1);
12393 gcc_assert (TREE_CODE (prim_class) == NOP_EXPR);
12394 prim_class = java_complete_tree (TREE_TYPE (prim_class));
12395 gcc_assert (TREE_CODE (prim_class) == RECORD_TYPE);
12396 field = lookup_field_wrapper (prim_class, name);
12398 if (field == NULL_TREE)
12400 error ("missing static field %qs", IDENTIFIER_POINTER (name));
12401 return error_mark_node;
12403 if (! FIELD_STATIC (field))
12405 error ("not a static field %qs", IDENTIFIER_POINTER (name));
12406 return error_mark_node;
12413 /* Can't use THIS in a static environment */
12416 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12417 parse_error_context (wfl_operator,
12418 "Keyword %<this%> used outside allowed context");
12419 TREE_TYPE (node) = error_mark_node;
12420 return error_mark_node;
12422 if (ctxp->explicit_constructor_p)
12424 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12425 parse_error_context
12426 (wfl_operator, "Can't reference %<this%> or %<super%> before the superclass constructor has been called");
12427 TREE_TYPE (node) = error_mark_node;
12428 return error_mark_node;
12430 return current_this;
12432 case CLASS_LITERAL:
12433 CAN_COMPLETE_NORMALLY (node) = 1;
12434 node = patch_incomplete_class_ref (node);
12435 if (node == error_mark_node)
12436 return error_mark_node;
12440 CAN_COMPLETE_NORMALLY (node) = 1;
12441 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
12442 and it's time to turn it into the appropriate String object */
12443 if ((nn = patch_string (node)))
12446 internal_error ("No case for %s", tree_code_name [TREE_CODE (node)]);
12451 /* Complete function call's argument. Return a nonzero value is an
12452 error was found. */
12455 complete_function_arguments (tree node)
12460 ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
12461 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
12463 tree wfl = TREE_VALUE (cn), parm, temp;
12464 parm = java_complete_tree (wfl);
12466 if (parm == error_mark_node)
12471 /* If we have a string literal that we haven't transformed yet or a
12472 crafted string buffer, as a result of the use of the String
12473 `+' operator. Build `parm.toString()' and expand it. */
12474 if ((temp = patch_string (parm)))
12477 TREE_VALUE (cn) = parm;
12479 ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
12483 /* Sometimes (for loops and variable initialized during their
12484 declaration), we want to wrap a statement around a WFL and turn it
12488 build_debugable_stmt (int location, tree stmt)
12490 if (TREE_CODE (stmt) != EXPR_WITH_FILE_LOCATION)
12492 #ifdef USE_MAPPED_LOCATION
12493 stmt = expr_add_location (stmt, location, 1);
12495 stmt = build_expr_wfl (stmt, input_filename, 0, 0);
12496 EXPR_WFL_LINECOL (stmt) = location;
12497 JAVA_MAYBE_GENERATE_DEBUG_INFO (stmt);
12504 build_expr_block (tree body, tree decls)
12506 tree node = make_node (BLOCK);
12507 BLOCK_EXPR_DECLS (node) = decls;
12508 BLOCK_EXPR_BODY (node) = body;
12510 TREE_TYPE (node) = TREE_TYPE (body);
12511 TREE_SIDE_EFFECTS (node) = 1;
12515 /* Create a new function block and link it appropriately to current
12516 function block chain */
12521 tree b = build_expr_block (NULL_TREE, NULL_TREE);
12523 /* Link block B supercontext to the previous block. The current
12524 function DECL is used as supercontext when enter_a_block is called
12525 for the first time for a given function. The current function body
12526 (DECL_FUNCTION_BODY) is set to be block B. */
12528 tree fndecl = current_function_decl;
12531 BLOCK_SUPERCONTEXT (b) = current_static_block;
12532 current_static_block = b;
12535 else if (!DECL_FUNCTION_BODY (fndecl))
12537 BLOCK_SUPERCONTEXT (b) = fndecl;
12538 DECL_FUNCTION_BODY (fndecl) = b;
12542 BLOCK_SUPERCONTEXT (b) = DECL_FUNCTION_BODY (fndecl);
12543 DECL_FUNCTION_BODY (fndecl) = b;
12548 /* Exit a block by changing the current function body
12549 (DECL_FUNCTION_BODY) to the current block super context, only if
12550 the block being exited isn't the method's top level one. */
12556 if (current_function_decl)
12558 b = DECL_FUNCTION_BODY (current_function_decl);
12559 if (BLOCK_SUPERCONTEXT (b) != current_function_decl)
12560 DECL_FUNCTION_BODY (current_function_decl) = BLOCK_SUPERCONTEXT (b);
12564 b = current_static_block;
12566 if (BLOCK_SUPERCONTEXT (b))
12567 current_static_block = BLOCK_SUPERCONTEXT (b);
12572 /* Lookup for NAME in the nested function's blocks, all the way up to
12573 the current toplevel one. It complies with Java's local variable
12577 lookup_name_in_blocks (tree name)
12579 tree b = GET_CURRENT_BLOCK (current_function_decl);
12581 while (b != current_function_decl)
12585 /* Paranoid sanity check. To be removed */
12586 if (TREE_CODE (b) != BLOCK)
12589 for (current = BLOCK_EXPR_DECLS (b); current;
12590 current = TREE_CHAIN (current))
12591 if (DECL_NAME (current) == name)
12593 b = BLOCK_SUPERCONTEXT (b);
12599 maybe_absorb_scoping_blocks (void)
12601 while (BLOCK_IS_IMPLICIT (GET_CURRENT_BLOCK (current_function_decl)))
12603 tree b = exit_block ();
12604 java_method_add_stmt (current_function_decl, b);
12605 SOURCE_FRONTEND_DEBUG (("Absorbing scoping block at line %d", input_line));
12610 /* This section of the source is reserved to build_* functions that
12611 are building incomplete tree nodes and the patch_* functions that
12612 are completing them. */
12614 /* Wrap a non WFL node around a WFL. */
12617 build_wfl_wrap (tree node, int location)
12619 tree wfl, node_to_insert = node;
12621 /* We want to process THIS . xxx symbolically, to keep it consistent
12622 with the way we're processing SUPER. A THIS from a primary as a
12623 different form than a SUPER. Turn THIS into something symbolic */
12624 if (TREE_CODE (node) == THIS_EXPR)
12625 node_to_insert = wfl = build_wfl_node (this_identifier_node);
12627 #ifdef USE_MAPPED_LOCATION
12628 wfl = build_unknown_wfl (NULL_TREE);
12630 SET_EXPR_LOCATION (wfl, location);
12632 wfl = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
12634 EXPR_WFL_LINECOL (wfl) = location;
12636 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (node_to_insert, NULL_TREE);
12640 /* Build a super() constructor invocation. Returns an empty statement if
12641 we're currently dealing with the class java.lang.Object. */
12644 build_super_invocation (tree mdecl)
12646 if (DECL_CONTEXT (mdecl) == object_type_node)
12647 return build_java_empty_stmt ();
12650 tree super_wfl = build_wfl_node (super_identifier_node);
12651 tree a = NULL_TREE, t;
12653 /* This is called after parsing is done, so the parser context
12654 won't be accurate. Set location info from current_class decl. */
12655 tree class_wfl = lookup_cl (TYPE_NAME (current_class));
12656 EXPR_WFL_LINECOL (super_wfl) = EXPR_WFL_LINECOL (class_wfl);
12658 /* If we're dealing with an anonymous class, pass the arguments
12659 of the crafted constructor along. */
12660 if (ANONYMOUS_CLASS_P (DECL_CONTEXT (mdecl)))
12662 SKIP_THIS_AND_ARTIFICIAL_PARMS (t, mdecl);
12663 for (; t != end_params_node; t = TREE_CHAIN (t))
12664 a = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (t)), a);
12666 return build_method_invocation (super_wfl, a);
12670 /* Build a SUPER/THIS qualified method invocation. */
12673 build_this_super_qualified_invocation (int use_this, tree name, tree args,
12674 int lloc, int rloc)
12678 build_wfl_node (use_this ? this_identifier_node : super_identifier_node);
12679 EXPR_WFL_LINECOL (wfl) = lloc;
12680 invok = build_method_invocation (name, args);
12681 return make_qualified_primary (wfl, invok, rloc);
12684 /* Build an incomplete CALL_EXPR node. */
12687 build_method_invocation (tree name, tree args)
12689 tree call = build3 (CALL_EXPR, NULL_TREE, name, args, NULL_TREE);
12690 TREE_SIDE_EFFECTS (call) = 1;
12691 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
12695 /* Build an incomplete new xxx(...) node. */
12698 build_new_invocation (tree name, tree args)
12700 tree call = build3 (NEW_CLASS_EXPR, NULL_TREE, name, args, NULL_TREE);
12701 TREE_SIDE_EFFECTS (call) = 1;
12702 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
12706 /* Build an incomplete assignment expression. */
12709 build_assignment (int op, int op_location, tree lhs, tree rhs)
12712 /* Build the corresponding binop if we deal with a Compound
12713 Assignment operator. Mark the binop sub-tree as part of a
12714 Compound Assignment expression */
12715 if (op != ASSIGN_TK)
12717 rhs = build_binop (BINOP_LOOKUP (op), op_location, lhs, rhs);
12718 COMPOUND_ASSIGN_P (rhs) = 1;
12720 assignment = build2 (MODIFY_EXPR, NULL_TREE, lhs, rhs);
12721 TREE_SIDE_EFFECTS (assignment) = 1;
12722 EXPR_WFL_LINECOL (assignment) = op_location;
12726 /* Print an INTEGER_CST node as decimal in a static buffer, and return
12727 the buffer. This is used only for string conversion. */
12729 string_convert_int_cst (tree node)
12731 /* Long.MIN_VALUE is -9223372036854775808, 20 characters. */
12732 static char buffer[21];
12734 unsigned HOST_WIDE_INT lo = TREE_INT_CST_LOW (node);
12735 unsigned HOST_WIDE_INT hi = TREE_INT_CST_HIGH (node);
12736 char *p = buffer + sizeof (buffer);
12739 unsigned HOST_WIDE_INT hibit = (((unsigned HOST_WIDE_INT) 1)
12740 << (HOST_BITS_PER_WIDE_INT - 1));
12744 /* If negative, note the fact and negate the value. */
12754 /* Divide by 10 until there are no bits left. */
12757 unsigned HOST_WIDE_INT acc = 0;
12758 unsigned HOST_WIDE_INT outhi = 0, outlo = 0;
12761 /* Use long division to compute the result and the remainder. */
12762 for (i = 0; i < 2 * HOST_BITS_PER_WIDE_INT; ++i)
12764 /* Shift a bit into accumulator. */
12769 /* Shift the value. */
12775 /* Shift the correct bit into the result. */
12777 if ((outlo & hibit))
12787 /* '0' == 060 in Java, but might not be here (think EBCDIC). */
12788 *--p = '\060' + acc;
12796 *--p = '\055'; /* '-' == 055 in Java, but might not be here. */
12801 /* Print an INTEGER_CST node in a static buffer, and return the
12802 buffer. This is used only for error handling. */
12804 print_int_node (tree node)
12806 static char buffer [80];
12807 if (TREE_CONSTANT_OVERFLOW (node))
12808 sprintf (buffer, "<overflow>");
12810 if (TREE_INT_CST_HIGH (node) == 0)
12811 sprintf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
12812 TREE_INT_CST_LOW (node));
12813 else if (TREE_INT_CST_HIGH (node) == -1
12814 && TREE_INT_CST_LOW (node) != 0)
12815 sprintf (buffer, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
12816 -TREE_INT_CST_LOW (node));
12818 sprintf (buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
12819 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
12825 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
12828 /* 15.25 Assignment operators. */
12831 patch_assignment (tree node, tree wfl_op1)
12833 tree rhs = TREE_OPERAND (node, 1);
12834 tree lvalue = TREE_OPERAND (node, 0), llvalue;
12835 tree lhs_type = NULL_TREE, rhs_type, new_rhs = NULL_TREE;
12836 int error_found = 0;
12837 int lvalue_from_array = 0;
12840 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12842 /* Lhs can be a named variable */
12843 if (JDECL_P (lvalue))
12845 lhs_type = TREE_TYPE (lvalue);
12847 /* Or Lhs can be an array access. */
12848 else if (TREE_CODE (lvalue) == ARRAY_REF)
12850 lhs_type = TREE_TYPE (lvalue);
12851 lvalue_from_array = 1;
12853 /* Or a field access */
12854 else if (TREE_CODE (lvalue) == COMPONENT_REF)
12855 lhs_type = TREE_TYPE (lvalue);
12856 /* Or a function return slot */
12857 else if (TREE_CODE (lvalue) == RESULT_DECL)
12859 /* If the return type is an integral type, then we create the
12860 RESULT_DECL with a promoted type, but we need to do these
12861 checks against the unpromoted type to ensure type safety. So
12862 here we look at the real type, not the type of the decl we
12864 lhs_type = TREE_TYPE (TREE_TYPE (current_function_decl));
12867 /* Otherwise, we might want to try to write into an optimized static
12868 final, this is an of a different nature, reported further on. */
12869 else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
12870 && resolve_expression_name (wfl_op1, &llvalue))
12872 lhs_type = TREE_TYPE (lvalue);
12876 parse_error_context (wfl_op1, "Invalid left hand side of assignment");
12880 rhs_type = TREE_TYPE (rhs);
12882 /* 5.1 Try the assignment conversion for builtin type. */
12883 new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
12885 /* 5.2 If it failed, try a reference conversion */
12887 new_rhs = try_reference_assignconv (lhs_type, rhs);
12889 /* 15.25.2 If we have a compound assignment, convert RHS into the
12891 else if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
12892 new_rhs = convert (lhs_type, rhs);
12894 /* Explicit cast required. This is an error */
12897 char *t1 = xstrdup (lang_printable_name (TREE_TYPE (rhs), 0));
12898 char *t2 = xstrdup (lang_printable_name (lhs_type, 0));
12900 char operation [32]; /* Max size known */
12902 /* If the assignment is part of a declaration, we use the WFL of
12903 the declared variable to point out the error and call it a
12904 declaration problem. If the assignment is a genuine =
12905 operator, we call is a operator `=' problem, otherwise we
12906 call it an assignment problem. In both of these last cases,
12907 we use the WFL of the operator to indicate the error. */
12909 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node))
12912 strcpy (operation, "declaration");
12916 wfl = wfl_operator;
12917 if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
12918 strcpy (operation, "assignment");
12919 else if (is_return)
12920 strcpy (operation, "'return'");
12922 strcpy (operation, "'='");
12925 if (!valid_cast_to_p (rhs_type, lhs_type))
12926 parse_error_context
12927 (wfl, "Incompatible type for %s. Can't convert %qs to %qs",
12928 operation, t1, t2);
12930 parse_error_context (wfl, "Incompatible type for %s. Explicit cast needed to convert %qs to %qs",
12931 operation, t1, t2);
12932 free (t1); free (t2);
12937 return error_mark_node;
12939 /* If we're processing a `return' statement, promote the actual type
12940 to the promoted type. */
12942 new_rhs = convert (TREE_TYPE (lvalue), new_rhs);
12944 /* 10.10: Array Store Exception runtime check */
12945 if (!flag_emit_class_files
12946 && lvalue_from_array
12947 && JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type)))
12949 tree array, store_check, base, index_expr;
12951 /* Save RHS so that it doesn't get re-evaluated by the store check. */
12952 new_rhs = save_expr (new_rhs);
12954 /* Get the INDIRECT_REF. */
12955 array = TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0);
12956 /* Get the array pointer expr. */
12957 array = TREE_OPERAND (array, 0);
12958 store_check = build_java_arraystore_check (array, new_rhs);
12960 index_expr = TREE_OPERAND (lvalue, 1);
12962 if (TREE_CODE (index_expr) == COMPOUND_EXPR)
12964 /* A COMPOUND_EXPR here is a bounds check. The bounds check must
12965 happen before the store check, so prepare to insert the store
12966 check within the second operand of the existing COMPOUND_EXPR. */
12972 index_expr = TREE_OPERAND (base, 1);
12973 TREE_OPERAND (base, 1) = build2 (COMPOUND_EXPR, TREE_TYPE (index_expr),
12974 store_check, index_expr);
12977 /* Final locals can be used as case values in switch
12978 statement. Prepare them for this eventuality. */
12979 if (TREE_CODE (lvalue) == VAR_DECL
12980 && DECL_FINAL (lvalue)
12981 && TREE_CONSTANT (new_rhs)
12982 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (lvalue))
12983 && JINTEGRAL_TYPE_P (TREE_TYPE (lvalue))
12986 TREE_CONSTANT (lvalue) = 1;
12987 TREE_INVARIANT (lvalue) = 1;
12988 DECL_INITIAL (lvalue) = new_rhs;
12991 /* Copy the rhs if it's a reference. */
12992 if (! flag_check_references && ! flag_emit_class_files && optimize > 0)
12994 switch (TREE_CODE (new_rhs))
12998 case COMPONENT_REF:
12999 /* Transform a = foo.bar
13000 into a = ({int tmp; tmp = foo.bar;}).
13001 We need to ensure that if a read from memory fails
13002 because of a NullPointerException, a destination variable
13003 will remain unchanged. An explicit temporary does what
13006 If flag_check_references is set, this is unnecessary
13007 because we'll check each reference before doing any
13008 reads. If optimize is not set the result will never be
13009 written to a stack slot that contains the LHS. */
13011 tree tmp = build_decl (VAR_DECL, get_identifier ("<tmp>"),
13012 TREE_TYPE (new_rhs));
13013 tree block = make_node (BLOCK);
13015 = build2 (MODIFY_EXPR, TREE_TYPE (new_rhs), tmp, fold (new_rhs));
13016 DECL_CONTEXT (tmp) = current_function_decl;
13017 TREE_TYPE (block) = TREE_TYPE (new_rhs);
13018 BLOCK_VARS (block) = tmp;
13019 BLOCK_EXPR_BODY (block) = assignment;
13020 TREE_SIDE_EFFECTS (block) = 1;
13029 TREE_OPERAND (node, 0) = lvalue;
13030 TREE_OPERAND (node, 1) = new_rhs;
13031 TREE_TYPE (node) = lhs_type;
13035 /* Check that type SOURCE can be cast into type DEST. If the cast
13036 can't occur at all, return NULL; otherwise, return a possibly
13040 try_reference_assignconv (tree lhs_type, tree rhs)
13042 tree new_rhs = NULL_TREE;
13043 tree rhs_type = TREE_TYPE (rhs);
13045 if (!JPRIMITIVE_TYPE_P (rhs_type) && JREFERENCE_TYPE_P (lhs_type))
13047 /* `null' may be assigned to any reference type */
13048 if (rhs == null_pointer_node)
13049 new_rhs = null_pointer_node;
13050 /* Try the reference assignment conversion */
13051 else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
13053 /* This is a magic assignment that we process differently */
13054 else if (TREE_CODE (rhs) == JAVA_EXC_OBJ_EXPR)
13060 /* Check that RHS can be converted into LHS_TYPE by the assignment
13061 conversion (5.2), for the cases of RHS being a builtin type. Return
13062 NULL_TREE if the conversion fails or if because RHS isn't of a
13063 builtin type. Return a converted RHS if the conversion is possible. */
13066 try_builtin_assignconv (tree wfl_op1, tree lhs_type, tree rhs)
13068 tree new_rhs = NULL_TREE;
13069 tree rhs_type = TREE_TYPE (rhs);
13071 /* Handle boolean specially. */
13072 if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
13073 || TREE_CODE (lhs_type) == BOOLEAN_TYPE)
13075 if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
13076 && TREE_CODE (lhs_type) == BOOLEAN_TYPE)
13080 /* 5.1.1 Try Identity Conversion,
13081 5.1.2 Try Widening Primitive Conversion */
13082 else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
13083 new_rhs = convert (lhs_type, rhs);
13085 /* Try a narrowing primitive conversion (5.1.3):
13086 - expression is a constant expression of type byte, short, char,
13088 - variable is byte, short or char AND
13089 - The value of the expression is representable in the type of the
13091 else if ((rhs_type == byte_type_node || rhs_type == short_type_node
13092 || rhs_type == char_type_node || rhs_type == int_type_node)
13093 && TREE_CONSTANT (rhs)
13094 && (lhs_type == byte_type_node || lhs_type == char_type_node
13095 || lhs_type == short_type_node))
13097 if (int_fits_type_p (rhs, lhs_type))
13098 new_rhs = convert (lhs_type, rhs);
13099 else if (wfl_op1) /* Might be called with a NULL */
13100 parse_warning_context
13102 "Constant expression %qs too wide for narrowing primitive conversion to %qs",
13103 print_int_node (rhs), lang_printable_name (lhs_type, 0));
13104 /* Reported a warning that will turn into an error further
13105 down, so we don't return */
13111 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
13112 conversion (5.1.1) or widening primitive conversion (5.1.2). Return
13113 0 is the conversion test fails. This implements parts the method
13114 invocation conversion (5.3). */
13117 valid_builtin_assignconv_identity_widening_p (tree lhs_type, tree rhs_type)
13119 /* 5.1.1: This is the identity conversion part. */
13120 if (lhs_type == rhs_type)
13123 /* Reject non primitive types and boolean conversions. */
13124 if (!JNUMERIC_TYPE_P (lhs_type) || !JNUMERIC_TYPE_P (rhs_type))
13127 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
13128 than a char can't be converted into a char. Short can't too, but
13129 the < test below takes care of that */
13130 if (lhs_type == char_type_node && rhs_type == byte_type_node)
13133 /* Accept all promoted type here. Note, we can't use <= in the test
13134 below, because we still need to bounce out assignments of short
13135 to char and the likes */
13136 if (lhs_type == int_type_node
13137 && (rhs_type == promoted_byte_type_node
13138 || rhs_type == promoted_short_type_node
13139 || rhs_type == promoted_char_type_node
13140 || rhs_type == promoted_boolean_type_node))
13143 /* From here, an integral is widened if its precision is smaller
13144 than the precision of the LHS or if the LHS is a floating point
13145 type, or the RHS is a float and the RHS a double. */
13146 if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type)
13147 && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
13148 || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
13149 || (rhs_type == float_type_node && lhs_type == double_type_node))
13155 /* Check that something of SOURCE type can be assigned or cast to
13156 something of DEST type at runtime. Return 1 if the operation is
13157 valid, 0 otherwise. If CAST is set to 1, we're treating the case
13158 were SOURCE is cast into DEST, which borrows a lot of the
13159 assignment check. */
13162 valid_ref_assignconv_cast_p (tree source, tree dest, int cast)
13164 /* SOURCE or DEST might be null if not from a declared entity. */
13165 if (!source || !dest)
13167 if (JNULLP_TYPE_P (source))
13169 if (TREE_CODE (source) == POINTER_TYPE)
13170 source = TREE_TYPE (source);
13171 if (TREE_CODE (dest) == POINTER_TYPE)
13172 dest = TREE_TYPE (dest);
13174 /* If source and dest are being compiled from bytecode, they may need to
13176 if (CLASS_P (source) && !CLASS_LOADED_P (source))
13178 load_class (source, 1);
13179 safe_layout_class (source);
13181 if (CLASS_P (dest) && !CLASS_LOADED_P (dest))
13183 load_class (dest, 1);
13184 safe_layout_class (dest);
13187 /* Case where SOURCE is a class type */
13188 if (TYPE_CLASS_P (source))
13190 if (TYPE_CLASS_P (dest))
13191 return (source == dest
13192 || inherits_from_p (source, dest)
13193 || (cast && inherits_from_p (dest, source)));
13194 if (TYPE_INTERFACE_P (dest))
13196 /* If doing a cast and SOURCE is final, the operation is
13197 always correct a compile time (because even if SOURCE
13198 does not implement DEST, a subclass of SOURCE might). */
13199 if (cast && !CLASS_FINAL (TYPE_NAME (source)))
13201 /* Otherwise, SOURCE must implement DEST */
13202 return interface_of_p (dest, source);
13204 /* DEST is an array, cast permitted if SOURCE is of Object type */
13205 return (cast && source == object_type_node ? 1 : 0);
13207 if (TYPE_INTERFACE_P (source))
13209 if (TYPE_CLASS_P (dest))
13211 /* If not casting, DEST must be the Object type */
13213 return dest == object_type_node;
13214 /* We're doing a cast. The cast is always valid is class
13215 DEST is not final, otherwise, DEST must implement SOURCE */
13216 else if (!CLASS_FINAL (TYPE_NAME (dest)))
13219 return interface_of_p (source, dest);
13221 if (TYPE_INTERFACE_P (dest))
13223 /* If doing a cast, then if SOURCE and DEST contain method
13224 with the same signature but different return type, then
13225 this is a (compile time) error */
13228 tree method_source, method_dest;
13232 for (method_source = TYPE_METHODS (source); method_source;
13233 method_source = TREE_CHAIN (method_source))
13236 build_java_argument_signature (TREE_TYPE (method_source));
13237 source_type = TREE_TYPE (TREE_TYPE (method_source));
13238 source_name = DECL_NAME (method_source);
13239 for (method_dest = TYPE_METHODS (dest);
13240 method_dest; method_dest = TREE_CHAIN (method_dest))
13242 build_java_argument_signature (TREE_TYPE (method_dest))
13243 && source_name == DECL_NAME (method_dest)
13244 && source_type != TREE_TYPE (TREE_TYPE (method_dest)))
13250 return source == dest || interface_of_p (dest, source);
13256 && (DECL_NAME (TYPE_NAME (source))
13257 == java_lang_cloneable_identifier_node
13258 || (DECL_NAME (TYPE_NAME (source))
13259 == java_io_serializable_identifier_node)));
13262 if (TYPE_ARRAY_P (source))
13264 if (TYPE_CLASS_P (dest))
13265 return dest == object_type_node;
13266 /* Can't cast an array to an interface unless the interface is
13267 java.lang.Cloneable or java.io.Serializable. */
13268 if (TYPE_INTERFACE_P (dest))
13269 return (DECL_NAME (TYPE_NAME (dest))
13270 == java_lang_cloneable_identifier_node
13271 || (DECL_NAME (TYPE_NAME (dest))
13272 == java_io_serializable_identifier_node));
13275 tree source_element_type = TYPE_ARRAY_ELEMENT (source);
13276 tree dest_element_type = TYPE_ARRAY_ELEMENT (dest);
13278 /* In case of severe errors, they turn out null */
13279 if (!dest_element_type || !source_element_type)
13281 if (source_element_type == dest_element_type)
13283 return valid_ref_assignconv_cast_p (source_element_type,
13284 dest_element_type, cast);
13292 valid_cast_to_p (tree source, tree dest)
13294 if (TREE_CODE (source) == POINTER_TYPE)
13295 source = TREE_TYPE (source);
13296 if (TREE_CODE (dest) == POINTER_TYPE)
13297 dest = TREE_TYPE (dest);
13299 if (TREE_CODE (source) == RECORD_TYPE && TREE_CODE (dest) == RECORD_TYPE)
13300 return valid_ref_assignconv_cast_p (source, dest, 1);
13302 else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
13305 else if (TREE_CODE (source) == BOOLEAN_TYPE
13306 && TREE_CODE (dest) == BOOLEAN_TYPE)
13313 do_unary_numeric_promotion (tree arg)
13315 tree type = TREE_TYPE (arg);
13316 if ((TREE_CODE (type) == INTEGER_TYPE && TYPE_PRECISION (type) < 32)
13317 || TREE_CODE (type) == CHAR_TYPE)
13318 arg = convert (int_type_node, arg);
13322 /* Return a nonzero value if SOURCE can be converted into DEST using
13323 the method invocation conversion rule (5.3). */
13325 valid_method_invocation_conversion_p (tree dest, tree source)
13327 return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
13328 && valid_builtin_assignconv_identity_widening_p (dest, source))
13329 || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
13330 && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
13331 && valid_ref_assignconv_cast_p (source, dest, 0)));
13334 /* Build an incomplete binop expression. */
13337 build_binop (enum tree_code op, int op_location, tree op1, tree op2)
13339 tree binop = build2 (op, NULL_TREE, op1, op2);
13340 TREE_SIDE_EFFECTS (binop) = 1;
13341 /* Store the location of the operator, for better error report. The
13342 string of the operator will be rebuild based on the OP value. */
13343 EXPR_WFL_LINECOL (binop) = op_location;
13347 /* Build the string of the operator retained by NODE. If NODE is part
13348 of a compound expression, add an '=' at the end of the string. This
13349 function is called when an error needs to be reported on an
13350 operator. The string is returned as a pointer to a static character
13354 operator_string (tree node)
13356 #define BUILD_OPERATOR_STRING(S) \
13358 sprintf (buffer, "%s%s", S, (COMPOUND_ASSIGN_P (node) ? "=" : "")); \
13362 static char buffer [10];
13363 switch (TREE_CODE (node))
13365 case MULT_EXPR: BUILD_OPERATOR_STRING ("*");
13366 case RDIV_EXPR: BUILD_OPERATOR_STRING ("/");
13367 case TRUNC_MOD_EXPR: BUILD_OPERATOR_STRING ("%");
13368 case PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
13369 case MINUS_EXPR: BUILD_OPERATOR_STRING ("-");
13370 case LSHIFT_EXPR: BUILD_OPERATOR_STRING ("<<");
13371 case RSHIFT_EXPR: BUILD_OPERATOR_STRING (">>");
13372 case URSHIFT_EXPR: BUILD_OPERATOR_STRING (">>>");
13373 case BIT_AND_EXPR: BUILD_OPERATOR_STRING ("&");
13374 case BIT_XOR_EXPR: BUILD_OPERATOR_STRING ("^");
13375 case BIT_IOR_EXPR: BUILD_OPERATOR_STRING ("|");
13376 case TRUTH_ANDIF_EXPR: BUILD_OPERATOR_STRING ("&&");
13377 case TRUTH_ORIF_EXPR: BUILD_OPERATOR_STRING ("||");
13378 case EQ_EXPR: BUILD_OPERATOR_STRING ("==");
13379 case NE_EXPR: BUILD_OPERATOR_STRING ("!=");
13380 case GT_EXPR: BUILD_OPERATOR_STRING (">");
13381 case GE_EXPR: BUILD_OPERATOR_STRING (">=");
13382 case LT_EXPR: BUILD_OPERATOR_STRING ("<");
13383 case LE_EXPR: BUILD_OPERATOR_STRING ("<=");
13384 case UNARY_PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
13385 case NEGATE_EXPR: BUILD_OPERATOR_STRING ("-");
13386 case TRUTH_NOT_EXPR: BUILD_OPERATOR_STRING ("!");
13387 case BIT_NOT_EXPR: BUILD_OPERATOR_STRING ("~");
13388 case PREINCREMENT_EXPR: /* Fall through */
13389 case POSTINCREMENT_EXPR: BUILD_OPERATOR_STRING ("++");
13390 case PREDECREMENT_EXPR: /* Fall through */
13391 case POSTDECREMENT_EXPR: BUILD_OPERATOR_STRING ("--");
13393 internal_error ("unregistered operator %s",
13394 tree_code_name [TREE_CODE (node)]);
13397 #undef BUILD_OPERATOR_STRING
13400 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
13403 java_decl_equiv (tree var_acc1, tree var_acc2)
13405 if (JDECL_P (var_acc1))
13406 return (var_acc1 == var_acc2);
13408 return (TREE_CODE (var_acc1) == COMPONENT_REF
13409 && TREE_CODE (var_acc2) == COMPONENT_REF
13410 && TREE_OPERAND (TREE_OPERAND (var_acc1, 0), 0)
13411 == TREE_OPERAND (TREE_OPERAND (var_acc2, 0), 0)
13412 && TREE_OPERAND (var_acc1, 1) == TREE_OPERAND (var_acc2, 1));
13415 /* Return a nonzero value if CODE is one of the operators that can be
13416 used in conjunction with the `=' operator in a compound assignment. */
13419 binop_compound_p (enum tree_code code)
13422 for (i = 0; i < BINOP_COMPOUND_CANDIDATES; i++)
13423 if (binop_lookup [i] == code)
13426 return i < BINOP_COMPOUND_CANDIDATES;
13429 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
13432 java_refold (tree t)
13434 tree c, b, ns, decl;
13436 if (TREE_CODE (t) != MODIFY_EXPR)
13439 c = TREE_OPERAND (t, 1);
13440 if (! (c && TREE_CODE (c) == COMPOUND_EXPR
13441 && TREE_CODE (TREE_OPERAND (c, 0)) == MODIFY_EXPR
13442 && binop_compound_p (TREE_CODE (TREE_OPERAND (c, 1)))))
13445 /* Now the left branch of the binary operator. */
13446 b = TREE_OPERAND (TREE_OPERAND (c, 1), 0);
13447 if (! (b && TREE_CODE (b) == NOP_EXPR
13448 && TREE_CODE (TREE_OPERAND (b, 0)) == SAVE_EXPR))
13451 ns = TREE_OPERAND (TREE_OPERAND (b, 0), 0);
13452 if (! (ns && TREE_CODE (ns) == NOP_EXPR
13453 && TREE_CODE (TREE_OPERAND (ns, 0)) == SAVE_EXPR))
13456 decl = TREE_OPERAND (TREE_OPERAND (ns, 0), 0);
13457 if ((JDECL_P (decl) || TREE_CODE (decl) == COMPONENT_REF)
13458 /* It's got to be the an equivalent decl */
13459 && java_decl_equiv (decl, TREE_OPERAND (TREE_OPERAND (c, 0), 0)))
13461 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
13462 TREE_OPERAND (TREE_OPERAND (c, 1), 0) = TREE_OPERAND (ns, 0);
13463 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
13464 TREE_OPERAND (t, 1) = TREE_OPERAND (c, 1);
13465 /* Change the right part of the BINOP_EXPR */
13466 TREE_OPERAND (TREE_OPERAND (t, 1), 1) = TREE_OPERAND (c, 0);
13472 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
13473 errors but we modify NODE so that it contains the type computed
13474 according to the expression, when it's fixed. Otherwise, we write
13475 error_mark_node as the type. It allows us to further the analysis
13476 of remaining nodes and detects more errors in certain cases. */
13479 patch_binop (tree node, tree wfl_op1, tree wfl_op2, int folding)
13481 tree op1 = TREE_OPERAND (node, 0);
13482 tree op2 = TREE_OPERAND (node, 1);
13483 tree op1_type = TREE_TYPE (op1);
13484 tree op2_type = TREE_TYPE (op2);
13485 tree prom_type = NULL_TREE, cn;
13486 enum tree_code code = TREE_CODE (node);
13488 /* If 1, tell the routine that we have to return error_mark_node
13489 after checking for the initialization of the RHS */
13490 int error_found = 0;
13492 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13494 /* If either op<n>_type are NULL, this might be early signs of an
13495 error situation, unless it's too early to tell (in case we're
13496 handling a `+', `==', `!=' or `instanceof'.) We want to set op<n>_type
13497 correctly so the error can be later on reported accurately. */
13498 if (! (code == PLUS_EXPR || code == NE_EXPR
13499 || code == EQ_EXPR || code == INSTANCEOF_EXPR))
13504 n = java_complete_tree (op1);
13505 op1_type = TREE_TYPE (n);
13509 n = java_complete_tree (op2);
13510 op2_type = TREE_TYPE (n);
13516 /* 15.16 Multiplicative operators */
13517 case MULT_EXPR: /* 15.16.1 Multiplication Operator * */
13518 case RDIV_EXPR: /* 15.16.2 Division Operator / */
13519 case TRUNC_DIV_EXPR: /* 15.16.2 Integral type Division Operator / */
13520 case TRUNC_MOD_EXPR: /* 15.16.3 Remainder operator % */
13521 if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
13523 if (!JNUMERIC_TYPE_P (op1_type))
13524 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13525 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13526 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13527 TREE_TYPE (node) = error_mark_node;
13531 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13533 /* Detect integral division by zero */
13534 if ((code == RDIV_EXPR || code == TRUNC_MOD_EXPR)
13535 && TREE_CODE (prom_type) == INTEGER_TYPE
13536 && (op2 == integer_zero_node || op2 == long_zero_node ||
13537 (TREE_CODE (op2) == INTEGER_CST &&
13538 ! TREE_INT_CST_LOW (op2) && ! TREE_INT_CST_HIGH (op2))))
13540 parse_warning_context
13542 "Evaluating this expression will result in an arithmetic exception being thrown");
13543 TREE_CONSTANT (node) = 0;
13544 TREE_INVARIANT (node) = 0;
13547 /* Change the division operator if necessary */
13548 if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
13549 TREE_SET_CODE (node, TRUNC_DIV_EXPR);
13551 /* Before divisions as is disappear, try to simplify and bail if
13552 applicable, otherwise we won't perform even simple
13553 simplifications like (1-1)/3. We can't do that with floating
13554 point number, folds can't handle them at this stage. */
13555 if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2)
13556 && JINTEGRAL_TYPE_P (op1) && JINTEGRAL_TYPE_P (op2))
13558 TREE_TYPE (node) = prom_type;
13559 node = fold (node);
13560 if (TREE_CODE (node) != code)
13564 if (TREE_CODE (prom_type) == INTEGER_TYPE
13565 && flag_use_divide_subroutine
13566 && ! flag_emit_class_files
13567 && (code == RDIV_EXPR || code == TRUNC_MOD_EXPR))
13568 return build_java_soft_divmod (TREE_CODE (node), prom_type, op1, op2);
13570 /* This one is more complicated. FLOATs are processed by a
13571 function call to soft_fmod. Duplicate the value of the
13572 COMPOUND_ASSIGN_P flag. */
13573 if (code == TRUNC_MOD_EXPR)
13575 tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
13576 COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
13581 /* 15.17 Additive Operators */
13582 case PLUS_EXPR: /* 15.17.1 String Concatenation Operator + */
13584 /* Operation is valid if either one argument is a string
13585 constant, a String object or a StringBuffer crafted for the
13586 purpose of the a previous usage of the String concatenation
13589 if (TREE_CODE (op1) == STRING_CST
13590 || TREE_CODE (op2) == STRING_CST
13591 || JSTRING_TYPE_P (op1_type)
13592 || JSTRING_TYPE_P (op2_type)
13593 || IS_CRAFTED_STRING_BUFFER_P (op1)
13594 || IS_CRAFTED_STRING_BUFFER_P (op2))
13595 return build_string_concatenation (op1, op2);
13597 case MINUS_EXPR: /* 15.17.2 Additive Operators (+ and -) for
13599 if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
13601 if (!JNUMERIC_TYPE_P (op1_type))
13602 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13603 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13604 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13605 TREE_TYPE (node) = error_mark_node;
13609 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13612 /* 15.18 Shift Operators */
13616 if (!JINTEGRAL_TYPE_P (op1_type) || !JINTEGRAL_TYPE_P (op2_type))
13618 if (!JINTEGRAL_TYPE_P (op1_type))
13619 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
13622 if (JNUMERIC_TYPE_P (op2_type))
13623 parse_error_context (wfl_operator,
13624 "Incompatible type for %qs. Explicit cast needed to convert shift distance from %qs to integral",
13625 operator_string (node),
13626 lang_printable_name (op2_type, 0));
13628 parse_error_context (wfl_operator,
13629 "Incompatible type for %qs. Can't convert shift distance from %qs to integral",
13630 operator_string (node),
13631 lang_printable_name (op2_type, 0));
13633 TREE_TYPE (node) = error_mark_node;
13638 /* Unary numeric promotion (5.6.1) is performed on each operand
13640 op1 = do_unary_numeric_promotion (op1);
13641 op2 = do_unary_numeric_promotion (op2);
13643 /* If the right hand side is of type `long', first cast it to
13645 if (TREE_TYPE (op2) == long_type_node)
13646 op2 = build1 (CONVERT_EXPR, int_type_node, op2);
13648 /* The type of the shift expression is the type of the promoted
13649 type of the left-hand operand */
13650 prom_type = TREE_TYPE (op1);
13652 /* Shift int only up to 0x1f and long up to 0x3f */
13653 if (prom_type == int_type_node)
13654 op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
13655 build_int_cst (NULL_TREE, 0x1f)));
13657 op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
13658 build_int_cst (NULL_TREE, 0x3f)));
13660 /* The >>> operator is a >> operating on unsigned quantities */
13661 if (code == URSHIFT_EXPR && (folding || ! flag_emit_class_files))
13664 tree utype = java_unsigned_type (prom_type);
13665 op1 = convert (utype, op1);
13667 to_return = fold_build2 (RSHIFT_EXPR, utype, op1, op2);
13668 to_return = convert (prom_type, to_return);
13669 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
13670 COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
13671 TREE_SIDE_EFFECTS (to_return)
13672 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13677 /* 15.19.1 Type Comparison Operator instanceof */
13678 case INSTANCEOF_EXPR:
13680 TREE_TYPE (node) = boolean_type_node;
13682 /* OP1_TYPE might be NULL when OP1 is a string constant. */
13683 if ((cn = patch_string (op1)))
13686 op1_type = TREE_TYPE (op1);
13688 if (op1_type == NULL_TREE)
13691 if (!(op2_type = resolve_type_during_patch (op2)))
13692 return error_mark_node;
13694 /* The first operand must be a reference type or the null type */
13695 if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
13696 error_found = 1; /* Error reported further below */
13698 /* The second operand must be a reference type */
13699 if (!JREFERENCE_TYPE_P (op2_type))
13701 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
13702 parse_error_context
13703 (wfl_operator, "Invalid argument %qs for %<instanceof%>",
13704 lang_printable_name (op2_type, 0));
13708 if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
13710 /* If the first operand is null, the result is always false */
13711 if (op1 == null_pointer_node)
13712 return boolean_false_node;
13713 else if (flag_emit_class_files)
13715 TREE_OPERAND (node, 1) = op2_type;
13716 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
13719 /* Otherwise we have to invoke instance of to figure it out */
13721 return build_instanceof (op1, op2_type);
13723 /* There is no way the expression operand can be an instance of
13724 the type operand. This is a compile time error. */
13727 char *t1 = xstrdup (lang_printable_name (op1_type, 0));
13728 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
13729 parse_error_context
13730 (wfl_operator, "Impossible for %qs to be instance of %qs",
13731 t1, lang_printable_name (op2_type, 0));
13738 /* 15.21 Bitwise and Logical Operators */
13742 if (JINTEGRAL_TYPE_P (op1_type) && JINTEGRAL_TYPE_P (op2_type))
13743 /* Binary numeric promotion is performed on both operand and the
13744 expression retain that type */
13745 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13747 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE
13748 && TREE_CODE (op1_type) == BOOLEAN_TYPE)
13749 /* The type of the bitwise operator expression is BOOLEAN */
13750 prom_type = boolean_type_node;
13753 if (!JINTEGRAL_TYPE_P (op1_type))
13754 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
13755 if (!JINTEGRAL_TYPE_P (op2_type) && (op1_type != op2_type))
13756 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op2_type);
13757 TREE_TYPE (node) = error_mark_node;
13759 /* Insert a break here if adding thing before the switch's
13760 break for this case */
13764 /* 15.22 Conditional-And Operator */
13765 case TRUTH_ANDIF_EXPR:
13766 /* 15.23 Conditional-Or Operator */
13767 case TRUTH_ORIF_EXPR:
13768 /* Operands must be of BOOLEAN type */
13769 if (TREE_CODE (op1_type) != BOOLEAN_TYPE ||
13770 TREE_CODE (op2_type) != BOOLEAN_TYPE)
13772 if (TREE_CODE (op1_type) != BOOLEAN_TYPE)
13773 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op1_type);
13774 if (TREE_CODE (op2_type) != BOOLEAN_TYPE && (op1_type != op2_type))
13775 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op2_type);
13776 TREE_TYPE (node) = boolean_type_node;
13780 else if (integer_zerop (op1))
13782 return code == TRUTH_ANDIF_EXPR ? op1 : op2;
13784 else if (integer_onep (op1))
13786 return code == TRUTH_ANDIF_EXPR ? op2 : op1;
13788 /* The type of the conditional operators is BOOLEAN */
13789 prom_type = boolean_type_node;
13792 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
13797 /* The type of each of the operands must be a primitive numeric
13799 if (!JNUMERIC_TYPE_P (op1_type) || ! JNUMERIC_TYPE_P (op2_type))
13801 if (!JNUMERIC_TYPE_P (op1_type))
13802 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13803 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13804 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13805 TREE_TYPE (node) = boolean_type_node;
13809 /* Binary numeric promotion is performed on the operands */
13810 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13811 /* The type of the relation expression is always BOOLEAN */
13812 prom_type = boolean_type_node;
13815 /* 15.20 Equality Operator */
13818 /* It's time for us to patch the strings. */
13819 if ((cn = patch_string (op1)))
13822 op1_type = TREE_TYPE (op1);
13824 if ((cn = patch_string (op2)))
13827 op2_type = TREE_TYPE (op2);
13830 /* 15.20.1 Numerical Equality Operators == and != */
13831 /* Binary numeric promotion is performed on the operands */
13832 if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
13833 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13835 /* 15.20.2 Boolean Equality Operators == and != */
13836 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE &&
13837 TREE_CODE (op2_type) == BOOLEAN_TYPE)
13838 ; /* Nothing to do here */
13840 /* 15.20.3 Reference Equality Operators == and != */
13841 /* Types have to be either references or the null type. If
13842 they're references, it must be possible to convert either
13843 type to the other by casting conversion. */
13844 else if ((op1 == null_pointer_node && op2 == null_pointer_node)
13845 || (op1 == null_pointer_node && JREFERENCE_TYPE_P (op2_type))
13846 || (JREFERENCE_TYPE_P (op1_type) && op2 == null_pointer_node)
13847 || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
13848 && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
13849 || valid_ref_assignconv_cast_p (op2_type,
13851 ; /* Nothing to do here */
13853 /* Else we have an error figure what can't be converted into
13854 what and report the error */
13858 t1 = xstrdup (lang_printable_name (op1_type, 0));
13859 parse_error_context
13861 "Incompatible type for %qs. Can't convert %qs to %qs",
13862 operator_string (node), t1,
13863 lang_printable_name (op2_type, 0));
13865 TREE_TYPE (node) = boolean_type_node;
13869 prom_type = boolean_type_node;
13876 return error_mark_node;
13878 TREE_OPERAND (node, 0) = op1;
13879 TREE_OPERAND (node, 1) = op2;
13880 TREE_TYPE (node) = prom_type;
13881 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13883 /* fold does not respect side-effect order as required for Java but not C.
13884 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
13887 if (flag_emit_class_files ? (TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
13888 : ! TREE_SIDE_EFFECTS (node))
13889 node = fold (node);
13893 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
13894 zero value, the value of CSTE comes after the valude of STRING */
13897 do_merge_string_cste (tree cste, const char *string, int string_len, int after)
13899 const char *old = TREE_STRING_POINTER (cste);
13900 int old_len = TREE_STRING_LENGTH (cste);
13901 int len = old_len + string_len;
13902 char *new = alloca (len+1);
13906 memcpy (new, string, string_len);
13907 memcpy (&new [string_len], old, old_len);
13911 memcpy (new, old, old_len);
13912 memcpy (&new [old_len], string, string_len);
13915 return build_string (len, new);
13918 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
13919 new STRING_CST on success, NULL_TREE on failure. */
13922 merge_string_cste (tree op1, tree op2, int after)
13924 /* Handle two string constants right away. */
13925 if (TREE_CODE (op2) == STRING_CST)
13926 return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
13927 TREE_STRING_LENGTH (op2), after);
13929 /* Reasonable integer constant can be treated right away. */
13930 if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
13932 static const char *const boolean_true = "true";
13933 static const char *const boolean_false = "false";
13934 static const char *const null_pointer = "null";
13936 const char *string;
13938 if (op2 == boolean_true_node)
13939 string = boolean_true;
13940 else if (op2 == boolean_false_node)
13941 string = boolean_false;
13942 else if (op2 == null_pointer_node
13943 || (integer_zerop (op2)
13944 && TREE_CODE (TREE_TYPE (op2)) == POINTER_TYPE))
13945 /* FIXME: null is not a compile-time constant, so it is only safe to
13946 merge if the overall expression is non-constant. However, this
13947 code always merges without checking the overall expression. */
13948 string = null_pointer;
13949 else if (TREE_TYPE (op2) == char_type_node)
13951 /* Convert the character into UTF-8. */
13952 unsigned int c = (unsigned int) TREE_INT_CST_LOW (op2);
13953 unsigned char *p = (unsigned char *) ch;
13954 if (0x01 <= c && c <= 0x7f)
13955 *p++ = (unsigned char) c;
13956 else if (c < 0x7ff)
13958 *p++ = (unsigned char) (c >> 6 | 0xc0);
13959 *p++ = (unsigned char) ((c & 0x3f) | 0x80);
13963 *p++ = (unsigned char) (c >> 12 | 0xe0);
13964 *p++ = (unsigned char) (((c >> 6) & 0x3f) | 0x80);
13965 *p++ = (unsigned char) ((c & 0x3f) | 0x80);
13972 string = string_convert_int_cst (op2);
13974 return do_merge_string_cste (op1, string, strlen (string), after);
13979 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
13980 has to be a STRING_CST and the other part must be a STRING_CST or a
13981 INTEGRAL constant. Return a new STRING_CST if the operation
13982 succeed, NULL_TREE otherwise.
13984 If the case we want to optimize for space, we might want to return
13985 NULL_TREE for each invocation of this routine. FIXME */
13988 string_constant_concatenation (tree op1, tree op2)
13990 if (TREE_CODE (op1) == STRING_CST || (TREE_CODE (op2) == STRING_CST))
13995 string = (TREE_CODE (op1) == STRING_CST ? op1 : op2);
13996 rest = (string == op1 ? op2 : op1);
13997 invert = (string == op1 ? 0 : 1 );
13999 /* Walk REST, only if it looks reasonable */
14000 if (TREE_CODE (rest) != STRING_CST
14001 && !IS_CRAFTED_STRING_BUFFER_P (rest)
14002 && !JSTRING_TYPE_P (TREE_TYPE (rest))
14003 && TREE_CODE (rest) == EXPR_WITH_FILE_LOCATION)
14005 rest = java_complete_tree (rest);
14006 if (rest == error_mark_node)
14007 return error_mark_node;
14008 rest = fold (rest);
14010 return merge_string_cste (string, rest, invert);
14015 /* Implement the `+' operator. Does static optimization if possible,
14016 otherwise create (if necessary) and append elements to a
14017 StringBuffer. The StringBuffer will be carried around until it is
14018 used for a function call or an assignment. Then toString() will be
14019 called on it to turn it into a String object. */
14022 build_string_concatenation (tree op1, tree op2)
14025 int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
14027 /* Try to do some static optimization */
14028 if ((result = string_constant_concatenation (op1, op2)))
14031 /* Discard empty strings on either side of the expression */
14032 if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
14037 else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
14040 /* If operands are string constant, turn then into object references */
14041 if (TREE_CODE (op1) == STRING_CST)
14042 op1 = patch_string_cst (op1);
14043 if (op2 && TREE_CODE (op2) == STRING_CST)
14044 op2 = patch_string_cst (op2);
14046 /* If either one of the constant is null and the other non null
14047 operand is a String constant, return it. */
14048 if ((TREE_CODE (op1) == STRING_CST) && !op2)
14051 /* If OP1 isn't already a StringBuffer, create and
14052 initialize a new one */
14053 if (!IS_CRAFTED_STRING_BUFFER_P (op1))
14055 /* Two solutions here:
14056 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
14057 2) OP1 is something else, we call new StringBuffer().append(OP1). */
14058 if (TREE_CONSTANT (op1) && JSTRING_TYPE_P (TREE_TYPE (op1)))
14059 op1 = BUILD_STRING_BUFFER (op1);
14062 tree aNew = BUILD_STRING_BUFFER (NULL_TREE);
14063 op1 = make_qualified_primary (aNew, BUILD_APPEND (op1), 0);
14069 /* OP1 is no longer the last node holding a crafted StringBuffer */
14070 IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
14071 /* Create a node for `{new...,xxx}.append (op2)' */
14072 op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
14075 /* Mark the last node holding a crafted StringBuffer */
14076 IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
14078 TREE_SIDE_EFFECTS (op1) = side_effects;
14082 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
14083 StringBuffer. If no string were found to be patched, return
14087 patch_string (tree node)
14089 if (node == error_mark_node)
14090 return error_mark_node;
14091 if (TREE_CODE (node) == STRING_CST)
14092 return patch_string_cst (node);
14093 else if (IS_CRAFTED_STRING_BUFFER_P (node))
14095 int saved = ctxp->explicit_constructor_p;
14096 tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
14098 /* Temporary disable forbid the use of `this'. */
14099 ctxp->explicit_constructor_p = 0;
14100 ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
14101 /* String concatenation arguments must be evaluated in order too. */
14102 ret = force_evaluation_order (ret);
14103 /* Restore it at its previous value */
14104 ctxp->explicit_constructor_p = saved;
14110 /* Build the internal representation of a string constant. */
14113 patch_string_cst (tree node)
14116 if (! flag_emit_class_files)
14118 node = get_identifier (TREE_STRING_POINTER (node));
14119 location = alloc_name_constant (CONSTANT_String, node);
14120 node = build_ref_from_constant_pool (location);
14122 TREE_CONSTANT (node) = 1;
14123 TREE_INVARIANT (node) = 1;
14125 /* ??? Guessing that the class file code can't handle casts. */
14126 if (! flag_emit_class_files)
14127 node = convert (string_ptr_type_node, node);
14129 TREE_TYPE (node) = string_ptr_type_node;
14134 /* Build an incomplete unary operator expression. */
14137 build_unaryop (int op_token, int op_location, tree op1)
14143 case PLUS_TK: op = UNARY_PLUS_EXPR; break;
14144 case MINUS_TK: op = NEGATE_EXPR; break;
14145 case NEG_TK: op = TRUTH_NOT_EXPR; break;
14146 case NOT_TK: op = BIT_NOT_EXPR; break;
14150 unaryop = build1 (op, NULL_TREE, op1);
14151 TREE_SIDE_EFFECTS (unaryop) = 1;
14152 /* Store the location of the operator, for better error report. The
14153 string of the operator will be rebuild based on the OP value. */
14154 EXPR_WFL_LINECOL (unaryop) = op_location;
14158 /* Special case for the ++/-- operators, since they require an extra
14159 argument to build, which is set to NULL and patched
14160 later. IS_POST_P is 1 if the operator, 0 otherwise. */
14163 build_incdec (int op_token, int op_location, tree op1, int is_post_p)
14165 static const enum tree_code lookup [2][2] =
14167 { PREDECREMENT_EXPR, PREINCREMENT_EXPR, },
14168 { POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, },
14170 tree node = build2 (lookup [is_post_p][(op_token - DECR_TK)],
14171 NULL_TREE, op1, NULL_TREE);
14172 TREE_SIDE_EFFECTS (node) = 1;
14173 /* Store the location of the operator, for better error report. The
14174 string of the operator will be rebuild based on the OP value. */
14175 EXPR_WFL_LINECOL (node) = op_location;
14179 /* Build an incomplete cast operator, based on the use of the
14180 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
14181 set. java_complete_tree is trained to walk a CONVERT_EXPR even
14182 though its type is already set. */
14185 build_cast (int location, tree type, tree exp)
14187 tree node = build1 (CONVERT_EXPR, type, exp);
14188 EXPR_WFL_LINECOL (node) = location;
14192 /* Build an incomplete class reference operator. */
14194 build_incomplete_class_ref (int location, tree class_name)
14196 tree node = build1 (CLASS_LITERAL, NULL_TREE, class_name);
14197 tree class_decl = GET_CPC ();
14198 tree this_class = TREE_TYPE (class_decl);
14200 /* Generate the synthetic static method `class$'. (Previously we
14201 deferred this, causing different method tables to be emitted
14202 for native code and bytecode.) */
14203 if (!TYPE_DOT_CLASS (this_class)
14204 && !JPRIMITIVE_TYPE_P (class_name)
14205 && !(TREE_CODE (class_name) == VOID_TYPE))
14207 tree cpc_list = GET_CPC_LIST();
14208 tree cpc = cpc_list;
14211 /* For inner classes, add a 'class$' method to their outermost
14212 context, creating it if necessary. */
14214 while (GET_NEXT_ENCLOSING_CPC(cpc))
14215 cpc = GET_NEXT_ENCLOSING_CPC(cpc);
14216 class_decl = TREE_VALUE (cpc);
14218 target_class = TREE_TYPE (class_decl);
14220 if (CLASS_INTERFACE (TYPE_NAME (target_class)))
14222 /* For interfaces, adding a static 'class$' method directly
14223 is illegal. So create an inner class to contain the new
14224 method. Empirically this matches the behavior of javac. */
14226 /* We want the generated inner class inside the outermost class. */
14227 GET_CPC_LIST() = cpc;
14228 t = build_wfl_node (DECL_NAME (TYPE_NAME (object_type_node)));
14229 inner = create_anonymous_class (t);
14230 target_class = TREE_TYPE (inner);
14231 end_class_declaration (1);
14232 GET_CPC_LIST() = cpc_list;
14235 if (TYPE_DOT_CLASS (target_class) == NULL_TREE)
14236 build_dot_class_method (target_class);
14238 if (this_class != target_class)
14239 TYPE_DOT_CLASS (this_class) = TYPE_DOT_CLASS (target_class);
14242 EXPR_WFL_LINECOL (node) = location;
14246 /* Complete an incomplete class reference operator. */
14248 patch_incomplete_class_ref (tree node)
14250 tree type = TREE_OPERAND (node, 0);
14253 if (!(ref_type = resolve_type_during_patch (type)))
14254 return error_mark_node;
14256 /* If we're not emitting class files and we know ref_type is a
14257 compiled class, build a direct reference. */
14258 if ((! flag_emit_class_files && is_compiled_class (ref_type))
14259 || JPRIMITIVE_TYPE_P (ref_type)
14260 || TREE_CODE (ref_type) == VOID_TYPE)
14262 tree dot = build_class_ref (ref_type);
14263 /* A class referenced by `foo.class' is initialized. */
14264 if (!flag_emit_class_files)
14265 dot = build_class_init (ref_type, dot);
14266 return java_complete_tree (dot);
14269 /* If we're emitting class files and we have to deal with non
14270 primitive types, we invoke the synthetic static method `class$'. */
14271 ref_type = build_dot_class_method_invocation (current_class, ref_type);
14272 return java_complete_tree (ref_type);
14275 /* 15.14 Unary operators. We return error_mark_node in case of error,
14276 but preserve the type of NODE if the type is fixed. */
14279 patch_unaryop (tree node, tree wfl_op)
14281 tree op = TREE_OPERAND (node, 0);
14282 tree op_type = TREE_TYPE (op);
14283 tree prom_type = NULL_TREE, value, decl;
14284 int nested_field_flag = 0;
14285 int code = TREE_CODE (node);
14286 int error_found = 0;
14288 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14292 /* 15.13.2 Postfix Increment Operator ++ */
14293 case POSTINCREMENT_EXPR:
14294 /* 15.13.3 Postfix Increment Operator -- */
14295 case POSTDECREMENT_EXPR:
14296 /* 15.14.1 Prefix Increment Operator ++ */
14297 case PREINCREMENT_EXPR:
14298 /* 15.14.2 Prefix Decrement Operator -- */
14299 case PREDECREMENT_EXPR:
14300 op = decl = extract_field_decl (op);
14302 = nested_field_expanded_access_p (op, NULL, NULL, NULL);
14303 /* We might be trying to change an outer field accessed using
14305 if (nested_field_flag)
14307 /* Retrieve the decl of the field we're trying to access. We
14308 do that by first retrieving the function we would call to
14309 access the field. It has been already verified that this
14310 field isn't final */
14311 if (flag_emit_class_files)
14312 decl = TREE_OPERAND (op, 0);
14314 decl = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (op, 0), 0), 0);
14315 decl = DECL_FUNCTION_ACCESS_DECL (decl);
14317 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
14318 else if (!JDECL_P (decl)
14319 && TREE_CODE (decl) != COMPONENT_REF
14320 && !(flag_emit_class_files && TREE_CODE (decl) == ARRAY_REF)
14321 && TREE_CODE (decl) != INDIRECT_REF
14322 && !(TREE_CODE (decl) == COMPOUND_EXPR
14323 && TREE_OPERAND (decl, 1)
14324 && (TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)))
14326 TREE_TYPE (node) = error_mark_node;
14330 /* From now on, we know that op if a variable and that it has a
14331 valid wfl. We use wfl_op to locate errors related to the
14333 if (!JNUMERIC_TYPE_P (op_type))
14335 parse_error_context
14336 (wfl_op, "Invalid argument type %qs to %qs",
14337 lang_printable_name (op_type, 0), operator_string (node));
14338 TREE_TYPE (node) = error_mark_node;
14343 /* Before the addition, binary numeric promotion is performed on
14344 both operands, if really necessary */
14345 if (JINTEGRAL_TYPE_P (op_type))
14347 value = build_int_cst (op_type, 1);
14348 TREE_TYPE (node) = op_type;
14352 value = build_int_cst (NULL_TREE, 1);
14354 binary_numeric_promotion (op_type,
14355 TREE_TYPE (value), &op, &value);
14358 /* We remember we might be accessing an outer field */
14359 if (nested_field_flag)
14361 /* We re-generate an access to the field */
14362 value = build2 (PLUS_EXPR, TREE_TYPE (op),
14363 build_nested_field_access (wfl_op, decl), value);
14365 /* And we patch the original access$() into a write
14366 with plus_op as a rhs */
14367 return nested_field_access_fix (node, op, value);
14370 /* And write back into the node. */
14371 TREE_OPERAND (node, 0) = op;
14372 TREE_OPERAND (node, 1) = value;
14373 /* Convert the overall back into its original type, if
14374 necessary, and return */
14375 if (JINTEGRAL_TYPE_P (op_type))
14376 return fold (node);
14378 return fold (convert (op_type, node));
14382 /* 15.14.3 Unary Plus Operator + */
14383 case UNARY_PLUS_EXPR:
14384 /* 15.14.4 Unary Minus Operator - */
14386 if (!JNUMERIC_TYPE_P (op_type))
14388 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op_type);
14389 TREE_TYPE (node) = error_mark_node;
14392 /* Unary numeric promotion is performed on operand */
14395 op = do_unary_numeric_promotion (op);
14396 prom_type = TREE_TYPE (op);
14397 if (code == UNARY_PLUS_EXPR)
14402 /* 15.14.5 Bitwise Complement Operator ~ */
14404 if (!JINTEGRAL_TYPE_P (op_type))
14406 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op_type);
14407 TREE_TYPE (node) = error_mark_node;
14412 op = do_unary_numeric_promotion (op);
14413 prom_type = TREE_TYPE (op);
14417 /* 15.14.6 Logical Complement Operator ! */
14418 case TRUTH_NOT_EXPR:
14419 if (TREE_CODE (op_type) != BOOLEAN_TYPE)
14421 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
14422 /* But the type is known. We will report an error if further
14423 attempt of a assignment is made with this rhs */
14424 TREE_TYPE (node) = boolean_type_node;
14428 prom_type = boolean_type_node;
14431 /* 15.15 Cast Expression */
14433 value = patch_cast (node, wfl_operator);
14434 if (value == error_mark_node)
14436 /* If this cast is part of an assignment, we tell the code
14437 that deals with it not to complain about a mismatch,
14438 because things have been cast, anyways */
14439 TREE_TYPE (node) = error_mark_node;
14444 value = fold (value);
14450 /* This can only happen when the type is already known. */
14451 gcc_assert (TREE_TYPE (node) != NULL_TREE);
14452 prom_type = TREE_TYPE (node);
14457 return error_mark_node;
14459 /* There are cases where node has been replaced by something else
14460 and we don't end up returning here: UNARY_PLUS_EXPR,
14461 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
14462 TREE_OPERAND (node, 0) = fold (op);
14463 TREE_TYPE (node) = prom_type;
14464 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
14465 return fold (node);
14468 /* Generic type resolution that sometimes takes place during node
14469 patching. Returned the resolved type or generate an error
14470 message. Return the resolved type or NULL_TREE. */
14473 resolve_type_during_patch (tree type)
14475 if (unresolved_type_p (type, NULL))
14477 tree type_decl = resolve_and_layout (EXPR_WFL_NODE (type), type);
14480 parse_error_context (type,
14481 "Class %qs not found in type declaration",
14482 IDENTIFIER_POINTER (EXPR_WFL_NODE (type)));
14486 check_deprecation (type, type_decl);
14488 return TREE_TYPE (type_decl);
14493 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
14494 found. Otherwise NODE or something meant to replace it is returned. */
14497 patch_cast (tree node, tree wfl_op)
14499 tree op = TREE_OPERAND (node, 0);
14500 tree cast_type = TREE_TYPE (node);
14501 tree patched, op_type;
14504 /* Some string patching might be necessary at this stage */
14505 if ((patched = patch_string (op)))
14506 TREE_OPERAND (node, 0) = op = patched;
14507 op_type = TREE_TYPE (op);
14509 /* First resolve OP_TYPE if unresolved */
14510 if (!(cast_type = resolve_type_during_patch (cast_type)))
14511 return error_mark_node;
14513 /* Check on cast that are proven correct at compile time */
14514 if (JNUMERIC_TYPE_P (cast_type) && JNUMERIC_TYPE_P (op_type))
14517 if (cast_type == op_type)
14520 /* A narrowing conversion from a floating-point number to an
14521 integral type requires special handling (5.1.3). */
14522 if (JFLOAT_TYPE_P (op_type) && JINTEGRAL_TYPE_P (cast_type))
14523 if (cast_type != long_type_node)
14524 op = convert (integer_type_node, op);
14526 /* Try widening/narrowing conversion. Potentially, things need
14527 to be worked out in gcc so we implement the extreme cases
14528 correctly. fold_convert() needs to be fixed. */
14529 return convert (cast_type, op);
14532 /* It's also valid to cast a boolean into a boolean */
14533 if (op_type == boolean_type_node && cast_type == boolean_type_node)
14536 /* null can be casted to references */
14537 if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
14538 return build_null_of_type (cast_type);
14540 /* The remaining legal casts involve conversion between reference
14541 types. Check for their compile time correctness. */
14542 if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type)
14543 && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
14545 TREE_TYPE (node) = promote_type (cast_type);
14546 /* Now, the case can be determined correct at compile time if
14547 OP_TYPE can be converted into CAST_TYPE by assignment
14548 conversion (5.2) */
14550 if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
14552 TREE_SET_CODE (node, NOP_EXPR);
14556 if (flag_emit_class_files)
14558 TREE_SET_CODE (node, CONVERT_EXPR);
14562 /* The cast requires a run-time check */
14563 return build3 (CALL_EXPR, promote_type (cast_type),
14564 build_address_of (soft_checkcast_node),
14565 tree_cons (NULL_TREE, build_class_ref (cast_type),
14566 build_tree_list (NULL_TREE, op)),
14570 /* Any other casts are proven incorrect at compile time */
14571 t1 = xstrdup (lang_printable_name (op_type, 0));
14572 parse_error_context (wfl_op, "Invalid cast from %qs to %qs",
14573 t1, lang_printable_name (cast_type, 0));
14575 return error_mark_node;
14578 /* Build a null constant and give it the type TYPE. */
14581 build_null_of_type (tree type)
14583 tree node = build_int_cst (promote_type (type), 0);
14587 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
14588 a list of indices. */
14590 build_array_ref (int location, tree array, tree index)
14592 tree node = build4 (ARRAY_REF, NULL_TREE, array, index,
14593 NULL_TREE, NULL_TREE);
14594 EXPR_WFL_LINECOL (node) = location;
14598 /* 15.12 Array Access Expression */
14601 patch_array_ref (tree node)
14603 tree array = TREE_OPERAND (node, 0);
14604 tree array_type = TREE_TYPE (array);
14605 tree index = TREE_OPERAND (node, 1);
14606 tree index_type = TREE_TYPE (index);
14607 int error_found = 0;
14609 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14611 if (TREE_CODE (array_type) == POINTER_TYPE)
14612 array_type = TREE_TYPE (array_type);
14614 /* The array reference must be an array */
14615 if (!TYPE_ARRAY_P (array_type))
14617 parse_error_context
14619 "%<[]%> can only be applied to arrays. It can't be applied to %qs",
14620 lang_printable_name (array_type, 0));
14621 TREE_TYPE (node) = error_mark_node;
14625 /* The array index undergoes unary numeric promotion. The promoted
14626 type must be int */
14627 index = do_unary_numeric_promotion (index);
14628 if (TREE_TYPE (index) != int_type_node)
14630 if (valid_cast_to_p (index_type, int_type_node))
14631 parse_error_context (wfl_operator,
14632 "Incompatible type for %<[]%>. Explicit cast needed to convert %qs to %<int%>",
14633 lang_printable_name (index_type, 0));
14635 parse_error_context (wfl_operator,
14636 "Incompatible type for %<[]%>. Can't convert %qs to %<int%>",
14637 lang_printable_name (index_type, 0));
14638 TREE_TYPE (node) = error_mark_node;
14643 return error_mark_node;
14645 array_type = TYPE_ARRAY_ELEMENT (array_type);
14647 if (flag_emit_class_files)
14649 TREE_OPERAND (node, 0) = array;
14650 TREE_OPERAND (node, 1) = index;
14653 node = build_java_arrayaccess (array, array_type, index);
14654 TREE_TYPE (node) = array_type;
14658 /* 15.9 Array Creation Expressions */
14661 build_newarray_node (tree type, tree dims, int extra_dims)
14663 tree node = build3 (NEW_ARRAY_EXPR, NULL_TREE, type,
14665 build_int_cst (NULL_TREE, extra_dims));
14670 patch_newarray (tree node)
14672 tree type = TREE_OPERAND (node, 0);
14673 tree dims = TREE_OPERAND (node, 1);
14674 tree cdim, array_type;
14675 int error_found = 0;
14677 int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
14679 /* Dimension types are verified. It's better for the types to be
14680 verified in order. */
14681 for (cdim = dims, ndims = 0; cdim; cdim = TREE_CHAIN (cdim), ndims++ )
14684 tree dim = TREE_VALUE (cdim);
14686 /* Dim might have been saved during its evaluation */
14687 dim = (TREE_CODE (dim) == SAVE_EXPR ? TREE_OPERAND (dim, 0) : dim);
14689 /* The type of each specified dimension must be an integral type. */
14690 if (!JINTEGRAL_TYPE_P (TREE_TYPE (dim)))
14693 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
14694 promoted type must be int. */
14697 dim = do_unary_numeric_promotion (dim);
14698 if (TREE_TYPE (dim) != int_type_node)
14702 /* Report errors on types here */
14705 parse_error_context
14706 (TREE_PURPOSE (cdim),
14707 "Incompatible type for dimension in array creation expression. %s convert %qs to %<int%>",
14708 (valid_cast_to_p (TREE_TYPE (dim), int_type_node) ?
14709 "Explicit cast needed to" : "Can't"),
14710 lang_printable_name (TREE_TYPE (dim), 0));
14714 TREE_PURPOSE (cdim) = NULL_TREE;
14717 /* Resolve array base type if unresolved */
14718 if (!(type = resolve_type_during_patch (type)))
14723 /* We don't want further evaluation of this bogus array creation
14725 TREE_TYPE (node) = error_mark_node;
14726 return error_mark_node;
14729 /* Set array_type to the actual (promoted) array type of the result. */
14730 if (TREE_CODE (type) == RECORD_TYPE)
14731 type = build_pointer_type (type);
14732 while (--xdims >= 0)
14734 type = promote_type (build_java_array_type (type, -1));
14736 dims = nreverse (dims);
14738 for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
14742 = build_java_array_type (type,
14743 TREE_CODE (cdim) == INTEGER_CST
14744 ? (HOST_WIDE_INT) TREE_INT_CST_LOW (cdim)
14746 array_type = promote_type (array_type);
14748 dims = nreverse (dims);
14750 /* The node is transformed into a function call. Things are done
14751 differently according to the number of dimensions. If the number
14752 of dimension is equal to 1, then the nature of the base type
14753 (primitive or not) matters. */
14755 return build_new_array (type, TREE_VALUE (dims));
14757 /* Can't reuse what's already written in expr.c because it uses the
14758 JVM stack representation. Provide a build_multianewarray. FIXME */
14759 return build3 (CALL_EXPR, array_type,
14760 build_address_of (soft_multianewarray_node),
14761 tree_cons (NULL_TREE,
14762 build_class_ref (TREE_TYPE (array_type)),
14763 tree_cons (NULL_TREE,
14764 build_int_cst (NULL_TREE, ndims),
14769 /* 10.6 Array initializer. */
14771 /* Build a wfl for array element that don't have one, so we can
14772 pin-point errors. */
14775 maybe_build_array_element_wfl (tree node)
14777 if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
14779 /* FIXME - old code used "prev_lc.line" and "elc.prev_col */
14780 return build_expr_wfl (NULL_TREE,
14781 #ifdef USE_MAPPED_LOCATION
14785 ctxp->lexer->token_start.line,
14786 ctxp->lexer->token_start.col
14794 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
14795 identification of initialized arrays easier to detect during walk
14799 build_new_array_init (int location, tree values)
14801 tree constructor = build_constructor_from_list (NULL_TREE,
14802 nreverse (values));
14803 tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
14804 EXPR_WFL_LINECOL (to_return) = location;
14808 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
14809 occurred. Otherwise return NODE after having set its type
14813 patch_new_array_init (tree type, tree node)
14815 int error_seen = 0;
14817 unsigned HOST_WIDE_INT length;
14818 constructor_elt *current;
14819 int all_constant = 1;
14820 tree init = TREE_OPERAND (node, 0);
14822 if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
14824 parse_error_context (node,
14825 "Invalid array initializer for non-array type %qs",
14826 lang_printable_name (type, 1));
14827 return error_mark_node;
14829 type = TREE_TYPE (type);
14830 element_type = TYPE_ARRAY_ELEMENT (type);
14833 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init),
14837 tree elt = current->value;
14838 if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
14840 error_seen |= array_constructor_check_entry (element_type, current);
14841 elt = current->value;
14842 /* When compiling to native code, STRING_CST is converted to
14843 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
14844 if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
14849 current->value = patch_new_array_init (element_type, elt);
14850 current->index = NULL_TREE;
14853 if (elt && TREE_CODE (elt) == TREE_LIST
14854 && TREE_VALUE (elt) == error_mark_node)
14859 return error_mark_node;
14861 /* Create a new type. We can't reuse the one we have here by
14862 patching its dimension because it originally is of dimension -1
14863 hence reused by gcc. This would prevent triangular arrays. */
14864 type = build_java_array_type (element_type, length);
14865 TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
14866 TREE_TYPE (node) = promote_type (type);
14867 TREE_CONSTANT (init) = all_constant;
14868 TREE_INVARIANT (init) = all_constant;
14869 TREE_CONSTANT (node) = all_constant;
14870 TREE_INVARIANT (node) = all_constant;
14874 /* Verify that one entry of the initializer element list can be
14875 assigned to the array base type. Report 1 if an error occurred, 0
14879 array_constructor_check_entry (tree type, constructor_elt *entry)
14881 char *array_type_string = NULL; /* For error reports */
14882 tree value, type_value, new_value, wfl_value, patched;
14883 int error_seen = 0;
14885 new_value = NULL_TREE;
14886 wfl_value = entry->value;
14888 value = java_complete_tree (entry->value);
14889 /* patch_string return error_mark_node if arg is error_mark_node */
14890 if ((patched = patch_string (value)))
14892 if (value == error_mark_node)
14895 type_value = TREE_TYPE (value);
14897 /* At anytime, try_builtin_assignconv can report a warning on
14898 constant overflow during narrowing. */
14899 SET_WFL_OPERATOR (wfl_operator, entry->index, wfl_value);
14900 new_value = try_builtin_assignconv (wfl_operator, type, value);
14901 if (!new_value && (new_value = try_reference_assignconv (type, value)))
14902 type_value = promote_type (type);
14904 /* Check and report errors */
14907 const char *const msg = (!valid_cast_to_p (type_value, type) ?
14908 "Can't" : "Explicit cast needed to");
14909 if (!array_type_string)
14910 array_type_string = xstrdup (lang_printable_name (type, 1));
14911 parse_error_context
14912 (wfl_operator, "Incompatible type for array. %s convert %qs to %qs",
14913 msg, lang_printable_name (type_value, 1), array_type_string);
14918 entry->value = new_value;
14920 if (array_type_string)
14921 free (array_type_string);
14923 entry->index = NULL_TREE;
14928 build_this (int location)
14930 tree node = build_wfl_node (this_identifier_node);
14931 TREE_SET_CODE (node, THIS_EXPR);
14932 EXPR_WFL_LINECOL (node) = location;
14936 /* 14.15 The return statement. It builds a modify expression that
14937 assigns the returned value to the RESULT_DECL that hold the value
14941 build_return (int location, tree op)
14943 tree node = build1 (RETURN_EXPR, NULL_TREE, op);
14944 EXPR_WFL_LINECOL (node) = location;
14945 node = build_debugable_stmt (location, node);
14950 patch_return (tree node)
14952 tree return_exp = TREE_OPERAND (node, 0);
14953 tree meth = current_function_decl;
14954 tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
14955 int error_found = 0;
14957 TREE_TYPE (node) = error_mark_node;
14958 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14960 /* It's invalid to have a return value within a function that is
14961 declared with the keyword void or that is a constructor */
14962 if (return_exp && (mtype == void_type_node || DECL_CONSTRUCTOR_P (meth)))
14965 /* It's invalid to use a return statement in a static block */
14966 if (DECL_CLINIT_P (current_function_decl))
14969 /* It's invalid to have a no return value within a function that
14970 isn't declared with the keyword `void' */
14971 if (!return_exp && (mtype != void_type_node && !DECL_CONSTRUCTOR_P (meth)))
14974 if (DECL_INSTINIT_P (current_function_decl))
14979 if (DECL_INSTINIT_P (current_function_decl))
14980 parse_error_context (wfl_operator,
14981 "%<return%> inside instance initializer");
14983 else if (DECL_CLINIT_P (current_function_decl))
14984 parse_error_context (wfl_operator,
14985 "%<return%> inside static initializer");
14987 else if (!DECL_CONSTRUCTOR_P (meth))
14989 char *t = xstrdup (lang_printable_name (mtype, 0));
14990 parse_error_context (wfl_operator,
14991 "%<return%> with%s value from %<%s %s%>",
14992 (error_found == 1 ? "" : "out"),
14993 t, lang_printable_name (meth, 2));
14997 parse_error_context (wfl_operator,
14998 "%<return%> with value from constructor %qs",
14999 lang_printable_name (meth, 2));
15000 return error_mark_node;
15003 /* If we have a return_exp, build a modify expression and expand
15004 it. Note: at that point, the assignment is declared valid, but we
15005 may want to carry some more hacks */
15008 tree exp = java_complete_tree (return_exp);
15009 tree modify, patched;
15011 if ((patched = patch_string (exp)))
15014 modify = build2 (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
15015 EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
15016 modify = java_complete_tree (modify);
15018 if (modify != error_mark_node)
15020 TREE_SIDE_EFFECTS (modify) = 1;
15021 TREE_OPERAND (node, 0) = modify;
15024 return error_mark_node;
15026 TREE_TYPE (node) = void_type_node;
15027 TREE_SIDE_EFFECTS (node) = 1;
15031 /* 14.8 The if Statement */
15034 build_if_else_statement (int location, tree expression, tree if_body,
15039 else_body = build_java_empty_stmt ();
15040 node = build3 (COND_EXPR, NULL_TREE, expression, if_body, else_body);
15041 EXPR_WFL_LINECOL (node) = location;
15042 node = build_debugable_stmt (location, node);
15047 patch_if_else_statement (tree node)
15049 tree expression = TREE_OPERAND (node, 0);
15050 int can_complete_normally
15051 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
15052 | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2)));
15054 TREE_TYPE (node) = error_mark_node;
15055 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15057 /* The type of expression must be boolean */
15058 if (TREE_TYPE (expression) != boolean_type_node
15059 && TREE_TYPE (expression) != promoted_boolean_type_node)
15061 parse_error_context
15063 "Incompatible type for %<if%>. Can't convert %qs to %<boolean%>",
15064 lang_printable_name (TREE_TYPE (expression), 0));
15065 return error_mark_node;
15068 TREE_TYPE (node) = void_type_node;
15069 TREE_SIDE_EFFECTS (node) = 1;
15070 CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
15074 /* 14.6 Labeled Statements */
15076 /* Action taken when a labeled statement is parsed. a new
15077 LABELED_BLOCK_EXPR is created. No statement is attached to the
15078 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
15081 build_labeled_block (int location, tree label)
15084 tree label_decl, node;
15085 if (label == NULL_TREE || label == continue_identifier_node)
15086 label_name = label;
15089 label_name = merge_qualified_name (label_id, label);
15090 /* Issue an error if we try to reuse a label that was previously
15092 if (IDENTIFIER_LOCAL_VALUE (label_name))
15094 EXPR_WFL_LINECOL (wfl_operator) = location;
15095 parse_error_context (wfl_operator,
15096 "Declaration of %qs shadows a previous label declaration",
15097 IDENTIFIER_POINTER (label));
15098 EXPR_WFL_LINECOL (wfl_operator) =
15099 EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
15100 parse_error_context (wfl_operator,
15101 "This is the location of the previous declaration of label %qs",
15102 IDENTIFIER_POINTER (label));
15103 java_error_count--;
15107 label_decl = create_label_decl (label_name);
15108 node = build2 (LABELED_BLOCK_EXPR, NULL_TREE, label_decl, NULL_TREE);
15109 EXPR_WFL_LINECOL (node) = location;
15110 TREE_SIDE_EFFECTS (node) = 1;
15114 /* A labeled statement LBE is attached a statement. */
15117 finish_labeled_statement (tree lbe, /* Labeled block expr */
15120 /* In anyways, tie the loop to its statement */
15121 LABELED_BLOCK_BODY (lbe) = statement;
15122 pop_labeled_block ();
15123 POP_LABELED_BLOCK ();
15127 /* 14.10, 14.11, 14.12 Loop Statements */
15129 /* Create an empty LOOP_EXPR and make it the last in the nested loop
15133 build_new_loop (tree loop_body)
15135 tree loop = build1 (LOOP_EXPR, NULL_TREE, loop_body);
15136 TREE_SIDE_EFFECTS (loop) = 1;
15141 /* Create a loop body according to the following structure:
15143 COMPOUND_EXPR (loop main body)
15144 EXIT_EXPR (this order is for while/for loops.
15145 LABELED_BLOCK_EXPR the order is reversed for do loops)
15146 LABEL_DECL (a continue occurring here branches at the
15147 BODY end of this labeled block)
15150 REVERSED, if nonzero, tells that the loop condition expr comes
15151 after the body, like in the do-while loop.
15153 To obtain a loop, the loop body structure described above is
15154 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
15157 LABEL_DECL (use this label to exit the loop)
15159 <structure described above> */
15162 build_loop_body (int location, tree condition, int reversed)
15164 tree first, second, body;
15166 condition = build1 (EXIT_EXPR, NULL_TREE, condition); /* Force walk */
15167 EXPR_WFL_LINECOL (condition) = location; /* For accurate error report */
15168 condition = build_debugable_stmt (location, condition);
15169 TREE_SIDE_EFFECTS (condition) = 1;
15171 body = build_labeled_block (0, continue_identifier_node);
15172 first = (reversed ? body : condition);
15173 second = (reversed ? condition : body);
15174 return build2 (COMPOUND_EXPR, NULL_TREE,
15175 build2 (COMPOUND_EXPR, NULL_TREE, first, second),
15176 build_java_empty_stmt ());
15179 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
15180 their order) on the current loop. Unlink the current loop from the
15184 finish_loop_body (int location, tree condition, tree body, int reversed)
15186 tree to_return = ctxp->current_loop;
15187 tree loop_body = LOOP_EXPR_BODY (to_return);
15190 tree cnode = LOOP_EXPR_BODY_CONDITION_EXPR (loop_body, reversed);
15191 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
15192 The real EXIT_EXPR is one operand further. */
15193 EXPR_WFL_LINECOL (cnode) = location;
15194 if (TREE_CODE (cnode) == EXPR_WITH_FILE_LOCATION)
15196 cnode = EXPR_WFL_NODE (cnode);
15197 /* This one is for accurate error reports */
15198 EXPR_WFL_LINECOL (cnode) = location;
15200 TREE_OPERAND (cnode, 0) = condition;
15202 LOOP_EXPR_BODY_BODY_EXPR (loop_body, reversed) = body;
15207 /* Tailored version of finish_loop_body for FOR loops, when FOR
15208 loops feature the condition part */
15211 finish_for_loop (int location, tree condition, tree update, tree body)
15213 /* Put the condition and the loop body in place */
15214 tree loop = finish_loop_body (location, condition, body, 0);
15215 /* LOOP is the current loop which has been now popped of the loop
15216 stack. Mark the update block as reachable and install it. We do
15217 this because the (current interpretation of the) JLS requires
15218 that the update expression be considered reachable even if the
15219 for loop's body doesn't complete normally. */
15220 if (update != NULL_TREE && !IS_EMPTY_STMT (update))
15223 if (TREE_CODE (up2) == EXPR_WITH_FILE_LOCATION)
15224 up2 = EXPR_WFL_NODE (up2);
15225 /* It is possible for the update expression to be an
15226 EXPR_WFL_NODE wrapping nothing. */
15227 if (up2 != NULL_TREE && !IS_EMPTY_STMT (up2))
15229 /* Try to detect constraint violations. These would be
15230 programming errors somewhere. */
15231 if (! EXPR_P (up2) || TREE_CODE (up2) == LOOP_EXPR)
15233 SUPPRESS_UNREACHABLE_ERROR (up2) = 1;
15236 LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
15240 /* Try to find the loop a block might be related to. This comprises
15241 the case where the LOOP_EXPR is found as the second operand of a
15242 COMPOUND_EXPR, because the loop happens to have an initialization
15243 part, then expressed as the first operand of the COMPOUND_EXPR. If
15244 the search finds something, 1 is returned. Otherwise, 0 is
15245 returned. The search is assumed to start from a
15246 LABELED_BLOCK_EXPR's block. */
15249 search_loop (tree statement)
15251 if (TREE_CODE (statement) == LOOP_EXPR)
15254 if (TREE_CODE (statement) == BLOCK)
15255 statement = BLOCK_SUBBLOCKS (statement);
15259 if (statement && TREE_CODE (statement) == COMPOUND_EXPR)
15260 while (statement && TREE_CODE (statement) == COMPOUND_EXPR)
15261 statement = TREE_OPERAND (statement, 1);
15263 return (TREE_CODE (statement) == LOOP_EXPR
15264 && FOR_LOOP_P (statement) ? statement : NULL_TREE);
15267 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
15268 returned otherwise. */
15271 labeled_block_contains_loop_p (tree block, tree loop)
15276 if (LABELED_BLOCK_BODY (block) == loop)
15279 if (FOR_LOOP_P (loop) && search_loop (LABELED_BLOCK_BODY (block)) == loop)
15285 /* If the loop isn't surrounded by a labeled statement, create one and
15286 insert LOOP as its body. */
15289 patch_loop_statement (tree loop)
15293 TREE_TYPE (loop) = void_type_node;
15294 if (labeled_block_contains_loop_p (ctxp->current_labeled_block, loop))
15297 loop_label = build_labeled_block (0, NULL_TREE);
15298 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
15299 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
15300 LABELED_BLOCK_BODY (loop_label) = loop;
15301 PUSH_LABELED_BLOCK (loop_label);
15305 /* 14.13, 14.14: break and continue Statements */
15307 /* Build a break or a continue statement. a null NAME indicates an
15308 unlabeled break/continue statement. */
15311 build_bc_statement (int location, int is_break, tree name)
15313 tree break_continue, label_block_expr = NULL_TREE;
15317 if (!(label_block_expr = IDENTIFIER_LOCAL_VALUE
15318 (merge_qualified_name (label_id, EXPR_WFL_NODE (name)))))
15319 /* Null means that we don't have a target for this named
15320 break/continue. In this case, we make the target to be the
15321 label name, so that the error can be reported accurately in
15322 patch_bc_statement. */
15323 label_block_expr = EXPR_WFL_NODE (name);
15325 /* Unlabeled break/continue will be handled during the
15326 break/continue patch operation */
15327 break_continue = build1 (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr);
15329 IS_BREAK_STMT_P (break_continue) = is_break;
15330 TREE_SIDE_EFFECTS (break_continue) = 1;
15331 EXPR_WFL_LINECOL (break_continue) = location;
15332 break_continue = build_debugable_stmt (location, break_continue);
15333 return break_continue;
15336 /* Verification of a break/continue statement. */
15339 patch_bc_statement (tree node)
15341 tree bc_label = EXIT_BLOCK_LABELED_BLOCK (node), target_stmt;
15342 tree labeled_block = ctxp->current_labeled_block;
15343 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15345 /* Having an identifier here means that the target is unknown. */
15346 if (bc_label != NULL_TREE && TREE_CODE (bc_label) == IDENTIFIER_NODE)
15348 parse_error_context (wfl_operator, "No label definition found for %qs",
15349 IDENTIFIER_POINTER (bc_label));
15350 return error_mark_node;
15352 if (! IS_BREAK_STMT_P (node))
15354 /* It's a continue statement. */
15355 for (;; labeled_block = TREE_CHAIN (labeled_block))
15357 if (labeled_block == NULL_TREE)
15359 if (bc_label == NULL_TREE)
15360 parse_error_context (wfl_operator,
15361 "%<continue%> must be in loop");
15363 parse_error_context
15364 (wfl_operator, "continue label %qs does not name a loop",
15365 IDENTIFIER_POINTER (bc_label));
15366 return error_mark_node;
15368 if ((DECL_NAME (LABELED_BLOCK_LABEL (labeled_block))
15369 == continue_identifier_node)
15370 && (bc_label == NULL_TREE
15371 || TREE_CHAIN (labeled_block) == bc_label))
15373 bc_label = labeled_block;
15378 else if (!bc_label)
15380 for (;; labeled_block = TREE_CHAIN (labeled_block))
15382 if (labeled_block == NULL_TREE)
15384 parse_error_context (wfl_operator,
15385 "%<break%> must be in loop or switch");
15386 return error_mark_node;
15388 target_stmt = LABELED_BLOCK_BODY (labeled_block);
15389 if (TREE_CODE (target_stmt) == SWITCH_EXPR
15390 || search_loop (target_stmt))
15392 bc_label = labeled_block;
15398 EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
15399 CAN_COMPLETE_NORMALLY (bc_label) = 1;
15401 /* Our break/continue don't return values. */
15402 TREE_TYPE (node) = void_type_node;
15403 /* Encapsulate the break within a compound statement so that it's
15404 expanded all the times by expand_expr (and not clobbered
15405 sometimes, like after a if statement) */
15406 node = add_stmt_to_compound (NULL_TREE, void_type_node, node);
15407 TREE_SIDE_EFFECTS (node) = 1;
15411 /* Process the exit expression belonging to a loop. Its type must be
15415 patch_exit_expr (tree node)
15417 tree expression = TREE_OPERAND (node, 0);
15418 TREE_TYPE (node) = error_mark_node;
15419 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15421 /* The type of expression must be boolean */
15422 if (TREE_TYPE (expression) != boolean_type_node)
15424 parse_error_context
15426 "Incompatible type for loop conditional. Can't convert %qs to %<boolean%>",
15427 lang_printable_name (TREE_TYPE (expression), 0));
15428 return error_mark_node;
15430 /* Now we know things are allright, invert the condition, fold and
15432 TREE_OPERAND (node, 0) =
15433 fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
15435 if (! integer_zerop (TREE_OPERAND (node, 0))
15436 && ctxp->current_loop != NULL_TREE
15437 && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
15438 CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
15439 if (! integer_onep (TREE_OPERAND (node, 0)))
15440 CAN_COMPLETE_NORMALLY (node) = 1;
15443 TREE_TYPE (node) = void_type_node;
15447 /* 14.9 Switch statement */
15450 patch_switch_statement (tree node)
15452 tree se = TREE_OPERAND (node, 0), se_type;
15455 /* Complete the switch expression */
15456 se = TREE_OPERAND (node, 0) = java_complete_tree (se);
15457 se_type = TREE_TYPE (se);
15458 /* The type of the switch expression must be char, byte, short or
15460 if (! JINTEGRAL_TYPE_P (se_type) || se_type == long_type_node)
15462 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15463 parse_error_context (wfl_operator,
15464 "Incompatible type for %<switch%>. Can't convert %qs to %<int%>",
15465 lang_printable_name (se_type, 0));
15466 /* This is what java_complete_tree will check */
15467 TREE_OPERAND (node, 0) = error_mark_node;
15468 return error_mark_node;
15471 /* Save and restore the outer case label list. */
15472 save = case_label_list;
15473 case_label_list = NULL_TREE;
15475 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
15477 /* See if we've found a duplicate label. We can't leave this until
15478 code generation, because in `--syntax-only' and `-C' modes we
15479 don't do ordinary code generation. */
15480 for (iter = case_label_list; iter != NULL_TREE; iter = TREE_CHAIN (iter))
15482 HOST_WIDE_INT val = TREE_INT_CST_LOW (TREE_VALUE (iter));
15484 for (subiter = TREE_CHAIN (iter);
15485 subiter != NULL_TREE;
15486 subiter = TREE_CHAIN (subiter))
15488 HOST_WIDE_INT subval = TREE_INT_CST_LOW (TREE_VALUE (subiter));
15491 EXPR_WFL_LINECOL (wfl_operator)
15492 = EXPR_WFL_LINECOL (TREE_PURPOSE (iter));
15493 /* The case_label_list is in reverse order, so print the
15494 outer label first. */
15495 parse_error_context (wfl_operator, "duplicate case label: %<"
15496 HOST_WIDE_INT_PRINT_DEC "%>", subval);
15497 EXPR_WFL_LINECOL (wfl_operator)
15498 = EXPR_WFL_LINECOL (TREE_PURPOSE (subiter));
15499 parse_error_context (wfl_operator, "original label is here");
15506 case_label_list = save;
15508 /* Ready to return */
15509 if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
15511 TREE_TYPE (node) = error_mark_node;
15512 return error_mark_node;
15514 TREE_TYPE (node) = void_type_node;
15515 TREE_SIDE_EFFECTS (node) = 1;
15516 CAN_COMPLETE_NORMALLY (node)
15517 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
15518 || ! SWITCH_HAS_DEFAULT (node);
15524 /* Build an assertion expression for `assert CONDITION : VALUE'; VALUE
15525 might be NULL_TREE. */
15528 #ifdef USE_MAPPED_LOCATION
15529 source_location location,
15533 tree condition, tree value)
15536 tree klass = GET_CPC ();
15538 if (! enable_assertions (klass))
15540 condition = build2 (TRUTH_ANDIF_EXPR, NULL_TREE,
15541 boolean_false_node, condition);
15542 if (value == NULL_TREE)
15543 value = build_java_empty_stmt ();
15544 return build_if_else_statement (location, condition,
15548 if (! CLASS_USES_ASSERTIONS (klass))
15550 tree field, classdollar, id, call;
15551 tree class_type = TREE_TYPE (klass);
15553 field = add_field (class_type,
15554 get_identifier ("$assertionsDisabled"),
15556 ACC_PRIVATE | ACC_STATIC | ACC_FINAL);
15557 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (field);
15558 FIELD_SYNTHETIC (field) = 1;
15560 classdollar = build_incomplete_class_ref (location, class_type);
15562 /* Call CLASS.desiredAssertionStatus(). */
15563 id = build_wfl_node (get_identifier ("desiredAssertionStatus"));
15564 call = build3 (CALL_EXPR, NULL_TREE, id, NULL_TREE, NULL_TREE);
15565 call = make_qualified_primary (classdollar, call, location);
15566 TREE_SIDE_EFFECTS (call) = 1;
15568 /* Invert to obtain !CLASS.desiredAssertionStatus(). This may
15569 seem odd, but we do it to generate code identical to that of
15571 call = build1 (TRUTH_NOT_EXPR, NULL_TREE, call);
15572 TREE_SIDE_EFFECTS (call) = 1;
15573 DECL_INITIAL (field) = call;
15575 /* Record the initializer in the initializer statement list. */
15576 call = build2 (MODIFY_EXPR, NULL_TREE, field, call);
15577 TREE_CHAIN (call) = CPC_STATIC_INITIALIZER_STMT (ctxp);
15578 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, call);
15579 MODIFY_EXPR_FROM_INITIALIZATION_P (call) = 1;
15581 CLASS_USES_ASSERTIONS (klass) = 1;
15584 if (value != NULL_TREE)
15585 value = tree_cons (NULL_TREE, value, NULL_TREE);
15587 node = build_wfl_node (get_identifier ("java"));
15588 node = make_qualified_name (node, build_wfl_node (get_identifier ("lang")),
15590 node = make_qualified_name (node, build_wfl_node (get_identifier ("AssertionError")),
15593 node = build3 (NEW_CLASS_EXPR, NULL_TREE, node, value, NULL_TREE);
15594 TREE_SIDE_EFFECTS (node) = 1;
15595 /* It is too early to use BUILD_THROW. */
15596 node = build1 (THROW_EXPR, NULL_TREE, node);
15597 TREE_SIDE_EFFECTS (node) = 1;
15599 /* We invert the condition; if we just put NODE as the `else' part
15600 then we generate weird-looking bytecode. */
15601 condition = build1 (TRUTH_NOT_EXPR, NULL_TREE, condition);
15602 /* Check $assertionsDisabled. */
15604 = build2 (TRUTH_ANDIF_EXPR, NULL_TREE,
15605 build1 (TRUTH_NOT_EXPR, NULL_TREE,
15606 build_wfl_node (get_identifier ("$assertionsDisabled"))),
15608 node = build_if_else_statement (location, condition, node, NULL_TREE);
15612 /* 14.18 The try/catch statements */
15614 /* Encapsulate TRY_STMTS' in a try catch sequence. The catch clause
15615 catches TYPE and executes CATCH_STMTS. */
15618 encapsulate_with_try_catch (int location, tree type_or_name, tree try_stmts,
15621 tree try_block, catch_clause_param, catch_block, catch;
15623 /* First build a try block */
15624 try_block = build_expr_block (try_stmts, NULL_TREE);
15626 /* Build a catch block: we need a catch clause parameter */
15627 if (TREE_CODE (type_or_name) == EXPR_WITH_FILE_LOCATION)
15629 tree catch_type = obtain_incomplete_type (type_or_name);
15631 catch_clause_param = build_decl (VAR_DECL, wpv_id, catch_type);
15632 register_incomplete_type (JDEP_VARIABLE, type_or_name,
15633 catch_clause_param, catch_type);
15634 dep = CLASSD_LAST (ctxp->classd_list);
15635 JDEP_GET_PATCH (dep) = &TREE_TYPE (catch_clause_param);
15638 catch_clause_param = build_decl (VAR_DECL, wpv_id,
15639 build_pointer_type (type_or_name));
15642 catch_block = build_expr_block (NULL_TREE, catch_clause_param);
15644 /* Initialize the variable and store in the block */
15645 catch = build2 (MODIFY_EXPR, NULL_TREE, catch_clause_param,
15646 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
15647 add_stmt_to_block (catch_block, NULL_TREE, catch);
15649 /* Add the catch statements */
15650 add_stmt_to_block (catch_block, NULL_TREE, catch_stmts);
15652 /* Now we can build a JAVA_CATCH_EXPR */
15653 catch_block = build1 (JAVA_CATCH_EXPR, NULL_TREE, catch_block);
15655 return build_try_statement (location, try_block, catch_block);
15659 build_try_statement (int location, tree try_block, tree catches)
15661 tree node = build2 (TRY_EXPR, NULL_TREE, try_block, catches);
15662 EXPR_WFL_LINECOL (node) = location;
15667 build_try_finally_statement (int location, tree try_block, tree finally)
15669 tree node = build2 (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
15670 EXPR_WFL_LINECOL (node) = location;
15675 patch_try_statement (tree node)
15677 int error_found = 0;
15678 tree try = TREE_OPERAND (node, 0);
15679 /* Exception handlers are considered in left to right order */
15680 tree catch = nreverse (TREE_OPERAND (node, 1));
15681 tree current, caught_type_list = NULL_TREE;
15683 /* Check catch clauses, if any. Every time we find an error, we try
15684 to process the next catch clause. We process the catch clause before
15685 the try block so that when processing the try block we can check thrown
15686 exceptions against the caught type list. */
15687 for (current = catch; current; current = TREE_CHAIN (current))
15689 tree carg_decl, carg_type;
15690 tree sub_current, catch_block, catch_clause;
15693 /* At this point, the structure of the catch clause is
15694 JAVA_CATCH_EXPR (catch node)
15695 BLOCK (with the decl of the parameter)
15697 MODIFY_EXPR (assignment of the catch parameter)
15698 BLOCK (catch clause block)
15700 catch_clause = TREE_OPERAND (current, 0);
15701 carg_decl = BLOCK_EXPR_DECLS (catch_clause);
15702 carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
15704 /* Catch clauses can't have more than one parameter declared,
15705 but it's already enforced by the grammar. Make sure that the
15706 only parameter of the clause statement in of class Throwable
15707 or a subclass of Throwable, but that was done earlier. The
15708 catch clause parameter type has also been resolved. */
15710 /* Just make sure that the catch clause parameter type inherits
15711 from java.lang.Throwable */
15712 if (!inherits_from_p (carg_type, throwable_type_node))
15714 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
15715 parse_error_context (wfl_operator,
15716 "Can't catch class %qs. Catch clause parameter type must be a subclass of class %<java.lang.Throwable%>",
15717 lang_printable_name (carg_type, 0));
15722 /* Partial check for unreachable catch statement: The catch
15723 clause is reachable iff is no earlier catch block A in
15724 the try statement such that the type of the catch
15725 clause's parameter is the same as or a subclass of the
15726 type of A's parameter */
15728 for (sub_current = catch;
15729 sub_current != current; sub_current = TREE_CHAIN (sub_current))
15731 tree sub_catch_clause, decl;
15732 sub_catch_clause = TREE_OPERAND (sub_current, 0);
15733 decl = BLOCK_EXPR_DECLS (sub_catch_clause);
15735 if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
15737 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
15738 parse_error_context
15740 "%<catch%> not reached because of the catch clause at line %d",
15741 EXPR_WFL_LINENO (sub_current));
15742 unreachable = error_found = 1;
15746 /* Complete the catch clause block */
15747 catch_block = java_complete_tree (TREE_OPERAND (current, 0));
15748 if (catch_block == error_mark_node)
15753 if (CAN_COMPLETE_NORMALLY (catch_block))
15754 CAN_COMPLETE_NORMALLY (node) = 1;
15755 TREE_OPERAND (current, 0) = catch_block;
15760 /* Things to do here: the exception must be thrown */
15762 /* Link this type to the caught type list */
15763 caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
15766 PUSH_EXCEPTIONS (caught_type_list);
15767 if ((try = java_complete_tree (try)) == error_mark_node)
15769 if (CAN_COMPLETE_NORMALLY (try))
15770 CAN_COMPLETE_NORMALLY (node) = 1;
15773 /* Verification ends here */
15775 return error_mark_node;
15777 TREE_OPERAND (node, 0) = try;
15778 TREE_OPERAND (node, 1) = catch;
15779 TREE_TYPE (node) = void_type_node;
15783 /* 14.17 The synchronized Statement */
15786 patch_synchronized_statement (tree node, tree wfl_op1)
15788 tree expr = java_complete_tree (TREE_OPERAND (node, 0));
15789 tree block = TREE_OPERAND (node, 1);
15791 tree tmp, enter, exit, expr_decl, assignment;
15793 if (expr == error_mark_node)
15795 block = java_complete_tree (block);
15799 /* We might be trying to synchronize on a STRING_CST */
15800 if ((tmp = patch_string (expr)))
15803 /* The TYPE of expr must be a reference type */
15804 if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
15806 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15807 parse_error_context (wfl_operator, "Incompatible type for %<synchronized%>. Can't convert %qs to %<java.lang.Object%>",
15808 lang_printable_name (TREE_TYPE (expr), 0));
15809 return error_mark_node;
15812 /* Generate a try-finally for the synchronized statement, except
15813 that the handler that catches all throw exception calls
15814 _Jv_MonitorExit and then rethrow the exception.
15815 The synchronized statement is then implemented as:
15818 _Jv_MonitorEnter (expression)
15820 _Jv_MonitorExit (expression)
15824 e = _Jv_exception_info ();
15825 _Jv_MonitorExit (expression)
15829 expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
15830 BUILD_MONITOR_ENTER (enter, expr_decl);
15831 BUILD_MONITOR_EXIT (exit, expr_decl);
15832 CAN_COMPLETE_NORMALLY (enter) = 1;
15833 CAN_COMPLETE_NORMALLY (exit) = 1;
15834 assignment = build2 (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
15835 TREE_SIDE_EFFECTS (assignment) = 1;
15836 node = build2 (COMPOUND_EXPR, NULL_TREE,
15837 build2 (COMPOUND_EXPR, NULL_TREE, assignment, enter),
15838 build2 (TRY_FINALLY_EXPR, NULL_TREE, block, exit));
15839 node = build_expr_block (node, expr_decl);
15841 return java_complete_tree (node);
15844 /* 14.16 The throw Statement */
15847 patch_throw_statement (tree node, tree wfl_op1)
15849 tree expr = TREE_OPERAND (node, 0);
15850 tree type = TREE_TYPE (expr);
15851 int unchecked_ok = 0, tryblock_throws_ok = 0;
15853 /* Thrown expression must be assignable to java.lang.Throwable */
15854 if (!try_reference_assignconv (throwable_type_node, expr))
15856 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15857 parse_error_context (wfl_operator,
15858 "Can't throw %qs; it must be a subclass of class %<java.lang.Throwable%>",
15859 lang_printable_name (type, 0));
15860 /* If the thrown expression was a reference, we further the
15861 compile-time check. */
15862 if (!JREFERENCE_TYPE_P (type))
15863 return error_mark_node;
15866 /* At least one of the following must be true */
15868 /* The type of the throw expression is a not checked exception,
15869 i.e. is a unchecked expression. */
15870 unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
15872 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15873 /* An instance can't throw a checked exception unless that exception
15874 is explicitly declared in the `throws' clause of each
15875 constructor. This doesn't apply to anonymous classes, since they
15876 don't have declared constructors. */
15878 && DECL_INSTINIT_P (current_function_decl)
15879 && !ANONYMOUS_CLASS_P (current_class))
15882 for (current = TYPE_METHODS (current_class); current;
15883 current = TREE_CHAIN (current))
15884 if (DECL_CONSTRUCTOR_P (current)
15885 && !check_thrown_exceptions_do (TREE_TYPE (expr)))
15887 parse_error_context (wfl_operator, "Checked exception %qs can't be thrown in instance initializer (not all declared constructor are declaring it in their %<throws%> clause)",
15888 lang_printable_name (TREE_TYPE (expr), 0));
15889 return error_mark_node;
15893 /* Throw is contained in a try statement and at least one catch
15894 clause can receive the thrown expression or the current method is
15895 declared to throw such an exception. Or, the throw statement is
15896 contained in a method or constructor declaration and the type of
15897 the Expression is assignable to at least one type listed in the
15898 throws clause the declaration. */
15900 tryblock_throws_ok = check_thrown_exceptions_do (TREE_TYPE (expr));
15901 if (!(unchecked_ok || tryblock_throws_ok))
15903 /* If there is a surrounding try block that has no matching
15904 clatch clause, report it first. A surrounding try block exits
15905 only if there is something after the list of checked
15906 exception thrown by the current function (if any). */
15907 if (IN_TRY_BLOCK_P ())
15908 parse_error_context (wfl_operator, "Checked exception %qs can't be caught by any of the catch clause(s) of the surrounding %<try%> block",
15909 lang_printable_name (type, 0));
15910 /* If we have no surrounding try statement and the method doesn't have
15911 any throws, report it now. FIXME */
15913 /* We report that the exception can't be throw from a try block
15914 in all circumstances but when the `throw' is inside a static
15916 else if (!EXCEPTIONS_P (currently_caught_type_list)
15917 && !tryblock_throws_ok)
15919 if (DECL_CLINIT_P (current_function_decl))
15920 parse_error_context (wfl_operator,
15921 "Checked exception %qs can't be thrown in initializer",
15922 lang_printable_name (type, 0));
15924 parse_error_context (wfl_operator,
15925 "Checked exception %qs isn't thrown from a %<try%> block",
15926 lang_printable_name (type, 0));
15928 /* Otherwise, the current method doesn't have the appropriate
15929 throws declaration */
15931 parse_error_context (wfl_operator, "Checked exception %qs doesn't match any of current method's %<throws%> declaration(s)",
15932 lang_printable_name (type, 0));
15933 return error_mark_node;
15936 if (! flag_emit_class_files)
15937 BUILD_THROW (node, expr);
15942 /* Add EXCEPTION to the throws clause of MDECL. If MDECL already throws
15943 a super-class of EXCEPTION, keep the superclass instead. If MDECL already
15944 throws a sub-class of EXCEPTION, replace the sub-class with EXCEPTION. */
15946 add_exception_to_throws (tree mdecl, tree exception)
15950 /* Ignore unchecked exceptions. */
15951 if (IS_UNCHECKED_EXCEPTION_P (exception))
15954 for (mthrows = DECL_FUNCTION_THROWS (mdecl);
15955 mthrows; mthrows = TREE_CHAIN (mthrows))
15957 if (inherits_from_p (exception, TREE_VALUE (mthrows)))
15959 if (inherits_from_p (TREE_VALUE (mthrows), exception))
15961 TREE_VALUE (mthrows) = exception;
15966 mthrows = DECL_FUNCTION_THROWS (mdecl);
15967 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (mthrows, exception);
15970 /* Check that exception said to be thrown by method DECL can be
15971 effectively caught from where DECL is invoked. THIS_EXPR is the
15972 expression that computes `this' for the method call. */
15974 check_thrown_exceptions (
15975 #ifdef USE_MAPPED_LOCATION
15976 source_location location,
15981 tree decl, tree this_expr)
15984 int is_array_call = 0;
15986 /* Skip check within generated methods, such as access$<n>. */
15987 if (NESTED_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (current_function_decl)))
15990 if (this_expr != NULL_TREE
15991 && TREE_CODE (TREE_TYPE (this_expr)) == POINTER_TYPE
15992 && TYPE_ARRAY_P (TREE_TYPE (TREE_TYPE (this_expr))))
15995 /* For all the unchecked exceptions thrown by DECL. */
15996 for (throws = DECL_FUNCTION_THROWS (decl); throws;
15997 throws = TREE_CHAIN (throws))
15998 if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
16000 /* Suppress errors about cloning arrays. */
16001 if (is_array_call && DECL_NAME (decl) == get_identifier ("clone"))
16004 #ifdef USE_MAPPED_LOCATION
16005 SET_EXPR_LOCATION (wfl_operator, location);
16007 EXPR_WFL_LINECOL (wfl_operator) = location;
16009 if (ANONYMOUS_CLASS_P (DECL_CONTEXT (current_function_decl))
16010 && (DECL_FINIT_P (current_function_decl)
16011 || DECL_INIT_P (current_function_decl)
16012 || DECL_CONSTRUCTOR_P (current_function_decl)))
16014 /* Add "throws" to the initializer's exception list */
16015 tree exception = TREE_VALUE (throws);
16016 add_exception_to_throws (current_function_decl, exception);
16018 else if (DECL_FINIT_P (current_function_decl))
16020 parse_error_context
16021 (wfl_operator, "Exception %qs can't be thrown in initializer",
16022 lang_printable_name (TREE_VALUE (throws), 0));
16026 parse_error_context
16027 (wfl_operator, "Exception %qs must be caught, or it must be declared in the %<throws%> clause of %qs",
16028 lang_printable_name (TREE_VALUE (throws), 0),
16029 (DECL_INIT_P (current_function_decl) ?
16030 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))) :
16031 IDENTIFIER_POINTER (DECL_NAME (current_function_decl))));
16036 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
16037 try-catch blocks, OR is listed in the `throws' clause of the
16041 check_thrown_exceptions_do (tree exception)
16043 tree list = currently_caught_type_list;
16044 resolve_and_layout (exception, NULL_TREE);
16045 /* First, all the nested try-catch-finally at that stage. The
16046 last element contains `throws' clause exceptions, if any. */
16047 if (IS_UNCHECKED_EXCEPTION_P (exception))
16052 for (caught = TREE_VALUE (list); caught; caught = TREE_CHAIN (caught))
16053 if (valid_ref_assignconv_cast_p (exception, TREE_VALUE (caught), 0))
16055 list = TREE_CHAIN (list);
16060 /* This function goes over all of CLASS_TYPE ctors and checks whether
16061 each of them features at least one unchecked exception in its
16062 `throws' clause. If it's the case, it returns `true', `false'
16066 ctors_unchecked_throws_clause_p (tree class_type)
16070 for (current = TYPE_METHODS (class_type); current;
16071 current = TREE_CHAIN (current))
16073 bool ctu = false; /* Ctor Throws Unchecked */
16074 if (DECL_CONSTRUCTOR_P (current))
16077 for (throws = DECL_FUNCTION_THROWS (current); throws && !ctu;
16078 throws = TREE_CHAIN (throws))
16079 if (inherits_from_p (TREE_VALUE (throws), exception_type_node))
16082 /* We return false as we found one ctor that is unfit. */
16083 if (!ctu && DECL_CONSTRUCTOR_P (current))
16086 /* All ctors feature at least one unchecked exception in their
16087 `throws' clause. */
16091 /* 15.24 Conditional Operator ?: */
16094 patch_conditional_expr (tree node, tree wfl_cond, tree wfl_op1)
16096 tree cond = TREE_OPERAND (node, 0);
16097 tree op1 = TREE_OPERAND (node, 1);
16098 tree op2 = TREE_OPERAND (node, 2);
16099 tree resulting_type = NULL_TREE;
16100 tree t1, t2, patched;
16101 int error_found = 0;
16103 /* The condition and operands of ?: might be StringBuffers crafted
16104 as a result of a string concatenation. Obtain decent ones here. */
16105 if ((patched = patch_string (cond)))
16106 TREE_OPERAND (node, 0) = cond = patched;
16107 if ((patched = patch_string (op1)))
16108 TREE_OPERAND (node, 1) = op1 = patched;
16109 if ((patched = patch_string (op2)))
16110 TREE_OPERAND (node, 2) = op2 = patched;
16112 t1 = TREE_TYPE (op1);
16113 t2 = TREE_TYPE (op2);
16115 /* The first expression must be a boolean */
16116 if (TREE_TYPE (cond) != boolean_type_node)
16118 SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
16119 parse_error_context (wfl_operator,
16120 "Incompatible type for %<?:%>. Can't convert %qs to %<boolean%>",
16121 lang_printable_name (TREE_TYPE (cond), 0));
16125 /* Second and third can be numeric, boolean (i.e. primitive),
16126 references or null. Anything else results in an error */
16127 if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
16128 || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node)
16129 && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
16130 || (t1 == boolean_type_node && t2 == boolean_type_node)))
16133 /* Determine the type of the conditional expression. Same types are
16134 easy to deal with */
16136 resulting_type = t1;
16138 /* There are different rules for numeric types */
16139 else if (JNUMERIC_TYPE_P (t1))
16141 /* if byte/short found, the resulting type is short */
16142 if ((t1 == byte_type_node && t2 == short_type_node)
16143 || (t1 == short_type_node && t2 == byte_type_node))
16144 resulting_type = short_type_node;
16146 /* If t1 is a constant int and t2 is of type byte, short or char
16147 and t1's value fits in t2, then the resulting type is t2 */
16148 else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
16149 && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
16150 resulting_type = t2;
16152 /* If t2 is a constant int and t1 is of type byte, short or char
16153 and t2's value fits in t1, then the resulting type is t1 */
16154 else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
16155 && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
16156 resulting_type = t1;
16158 /* Otherwise, binary numeric promotion is applied and the
16159 resulting type is the promoted type of operand 1 and 2 */
16161 resulting_type = binary_numeric_promotion (t1, t2,
16162 &TREE_OPERAND (node, 1),
16163 &TREE_OPERAND (node, 2));
16166 /* Cases of a reference and a null type */
16167 else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
16168 resulting_type = t1;
16170 else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
16171 resulting_type = t2;
16173 /* Last case: different reference types. If a type can be converted
16174 into the other one by assignment conversion, the latter
16175 determines the type of the expression */
16176 else if ((resulting_type = try_reference_assignconv (t1, op2)))
16177 resulting_type = promote_type (t1);
16179 else if ((resulting_type = try_reference_assignconv (t2, op1)))
16180 resulting_type = promote_type (t2);
16182 /* If we don't have any resulting type, we're in trouble */
16183 if (!resulting_type)
16185 char *t = xstrdup (lang_printable_name (t1, 0));
16186 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
16187 parse_error_context (wfl_operator,
16188 "Incompatible type for %<?:%>. Can't convert %qs to %qs",
16189 t, lang_printable_name (t2, 0));
16196 TREE_TYPE (node) = error_mark_node;
16197 return error_mark_node;
16200 TREE_TYPE (node) = resulting_type;
16201 TREE_SET_CODE (node, COND_EXPR);
16202 CAN_COMPLETE_NORMALLY (node) = 1;
16206 /* Wrap EXPR with code to initialize DECL's class, if appropriate. */
16209 maybe_build_class_init_for_field (tree decl, tree expr)
16211 tree clas = DECL_CONTEXT (decl);
16212 if (flag_emit_class_files)
16215 if (TREE_CODE (decl) == VAR_DECL && FIELD_STATIC (decl)
16216 && FIELD_FINAL (decl))
16218 tree init = DECL_INITIAL (decl);
16219 if (init != NULL_TREE)
16220 init = fold_constant_for_init (init, decl);
16221 if (init != NULL_TREE && CONSTANT_VALUE_P (init))
16225 return build_class_init (clas, expr);
16228 /* Try to constant fold NODE.
16229 If NODE is not a constant expression, return NULL_EXPR.
16230 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
16233 fold_constant_for_init (tree node, tree context)
16235 tree op0, op1, val;
16236 enum tree_code code = TREE_CODE (node);
16241 if (node == null_pointer_node)
16250 case TRUNC_MOD_EXPR:
16258 case TRUTH_ANDIF_EXPR:
16259 case TRUTH_ORIF_EXPR:
16266 op0 = TREE_OPERAND (node, 0);
16267 op1 = TREE_OPERAND (node, 1);
16268 val = fold_constant_for_init (op0, context);
16269 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16271 TREE_OPERAND (node, 0) = val;
16272 val = fold_constant_for_init (op1, context);
16273 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16275 TREE_OPERAND (node, 1) = val;
16276 return patch_binop (node, op0, op1, 1);
16278 case UNARY_PLUS_EXPR:
16280 case TRUTH_NOT_EXPR:
16284 op0 = TREE_OPERAND (node, 0);
16285 val = fold_constant_for_init (op0, context);
16286 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16288 TREE_OPERAND (node, 0) = val;
16289 val = patch_unaryop (node, op0);
16290 if (! TREE_CONSTANT (val))
16297 val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
16298 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16300 TREE_OPERAND (node, 0) = val;
16301 val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
16302 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16304 TREE_OPERAND (node, 1) = val;
16305 val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
16306 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16308 TREE_OPERAND (node, 2) = val;
16309 return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 2)
16310 : TREE_OPERAND (node, 1);
16314 if (! FIELD_FINAL (node)
16315 || DECL_INITIAL (node) == NULL_TREE)
16317 val = DECL_INITIAL (node);
16318 /* Guard against infinite recursion. */
16319 DECL_INITIAL (node) = NULL_TREE;
16320 val = fold_constant_for_init (val, node);
16321 if (val != NULL_TREE && TREE_CODE (val) != STRING_CST)
16322 val = try_builtin_assignconv (NULL_TREE, TREE_TYPE (node), val);
16323 DECL_INITIAL (node) = val;
16326 case EXPR_WITH_FILE_LOCATION:
16327 /* Compare java_complete_tree and resolve_expression_name. */
16328 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
16329 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
16331 tree name = EXPR_WFL_NODE (node);
16333 if (PRIMARY_P (node))
16335 else if (! QUALIFIED_P (name))
16337 decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
16338 if (decl == NULL_TREE
16339 || (! FIELD_STATIC (decl) && ! FIELD_FINAL (decl)))
16341 return fold_constant_for_init (decl, decl);
16345 tree r = NULL_TREE;
16346 /* Install the proper context for the field resolution. */
16347 tree saved_current_class = current_class;
16348 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
16349 current_class = DECL_CONTEXT (context);
16350 qualify_ambiguous_name (node);
16351 r = resolve_field_access (node, &decl, NULL);
16352 /* Restore prior context. */
16353 current_class = saved_current_class;
16354 if (r != error_mark_node && decl != NULL_TREE)
16355 return fold_constant_for_init (decl, decl);
16361 op0 = TREE_OPERAND (node, 0);
16362 val = fold_constant_for_init (op0, context);
16363 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16365 TREE_OPERAND (node, 0) = val;
16369 #ifdef USE_COMPONENT_REF
16371 case COMPONENT_REF:
16380 #ifdef USE_COMPONENT_REF
16381 /* Context is 'T' for TypeName, 'P' for PackageName,
16382 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
16385 resolve_simple_name (tree name, int context)
16390 resolve_qualified_name (tree name, int context)
16396 init_src_parse (void)
16398 /* Sanity check; we've been bit by this before. */
16399 if (ARRAY_SIZE (ctxp->modifier_ctx) != MODIFIER_TK - PUBLIC_TK)
16405 /* This section deals with the functions that are called when tables
16406 recording class initialization information are traversed. */
16408 /* This function is called for each class that is known definitely
16409 initialized when a given static method was called. This function
16410 augments a compound expression (INFO) storing all assignment to
16411 initialized static class flags if a flag already existed, otherwise
16412 a new one is created. */
16415 emit_test_initialization (void **entry_p, void *info)
16417 tree l = (tree) info;
16419 tree key = (tree) *entry_p;
16421 htab_t cf_ht = DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl);
16423 /* If we haven't found a flag and we're dealing with self registered
16424 with current_function_decl, then don't do anything. Self is
16425 always added as definitely initialized but this information is
16426 valid only if used outside the current function. */
16427 if (current_function_decl == TREE_PURPOSE (l)
16428 && java_treetreehash_find (cf_ht, key) == NULL)
16431 ite = java_treetreehash_new (cf_ht, key);
16433 /* If we don't have a variable, create one and install it. */
16438 decl = build_decl (VAR_DECL, NULL_TREE, boolean_type_node);
16439 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
16440 LOCAL_CLASS_INITIALIZATION_FLAG (decl) = 1;
16441 DECL_CONTEXT (decl) = current_function_decl;
16442 DECL_INITIAL (decl) = boolean_true_node;
16443 /* Don't emit any symbolic debugging info for this decl. */
16444 DECL_IGNORED_P (decl) = 1;
16446 /* The trick is to find the right context for it. */
16447 block = BLOCK_SUBBLOCKS (GET_CURRENT_BLOCK (current_function_decl));
16448 TREE_CHAIN (decl) = BLOCK_EXPR_DECLS (block);
16449 BLOCK_EXPR_DECLS (block) = decl;
16455 /* Now simply augment the compound that holds all the assignments
16456 pertaining to this method invocation. */
16457 init = build2 (MODIFY_EXPR, boolean_type_node, decl, boolean_true_node);
16458 TREE_SIDE_EFFECTS (init) = 1;
16459 TREE_VALUE (l) = add_stmt_to_compound (TREE_VALUE (l), void_type_node, init);
16460 TREE_SIDE_EFFECTS (TREE_VALUE (l)) = 1;
16465 #ifdef __XGETTEXT__
16466 /* Depending on the version of Bison used to compile this grammar,
16467 it may issue generic diagnostics spelled "syntax error" or
16468 "parse error". To prevent this from changing the translation
16469 template randomly, we list all the variants of this particular
16470 diagnostic here. Translators: there is no fine distinction
16471 between diagnostics with "syntax error" in them, and diagnostics
16472 with "parse error" in them. It's okay to give them both the same
16474 const char d1[] = N_("syntax error");
16475 const char d2[] = N_("parse error");
16476 const char d3[] = N_("syntax error; also virtual memory exhausted");
16477 const char d4[] = N_("parse error; also virtual memory exhausted");
16478 const char d5[] = N_("syntax error: cannot back up");
16479 const char d6[] = N_("parse error: cannot back up");
16482 #include "gt-java-parse.h"
16483 #include "gtype-java.h"