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
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, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, 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"
75 #include "tree-inline.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 *msgid, ...);
101 #ifdef USE_MAPPED_LOCATION
102 static void issue_warning_error_from_context
103 (source_location, const char *msgid, va_list *);
105 static void issue_warning_error_from_context
106 (tree, const char *msgid, 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 void check_inner_class_access (tree, tree, tree);
116 static int check_pkg_class_access (tree, tree, bool, tree);
117 static void register_package (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);
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 #ifdef USE_MAPPED_LOCATION
238 static void check_thrown_exceptions (source_location, tree, tree);
240 static void check_thrown_exceptions (int, tree, tree);
242 static int check_thrown_exceptions_do (tree);
243 static void purge_unchecked_exceptions (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 int verify_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, tree);
278 static const char *purify_type_name (const char *);
279 static tree fold_constant_for_init (tree, tree);
280 static tree strip_out_static_field_access_decl (tree);
281 static jdeplist *reverse_jdep_list (struct parser_ctxt *);
282 static void static_ref_err (tree, tree, tree);
283 static void parser_add_interface (tree, tree, tree);
284 static void add_superinterfaces (tree, tree);
285 static tree jdep_resolve_class (jdep *);
286 static int note_possible_classname (const char *, int);
287 static void java_complete_expand_classes (void);
288 static void java_complete_expand_class (tree);
289 static void java_complete_expand_methods (tree);
290 static tree cut_identifier_in_qualified (tree);
291 static tree java_stabilize_reference (tree);
292 static tree do_unary_numeric_promotion (tree);
293 static char * operator_string (tree);
294 static tree do_merge_string_cste (tree, const char *, int, int);
295 static tree merge_string_cste (tree, tree, int);
296 static tree java_refold (tree);
297 static int java_decl_equiv (tree, tree);
298 static int binop_compound_p (enum tree_code);
299 static tree search_loop (tree);
300 static int labeled_block_contains_loop_p (tree, tree);
301 static int check_abstract_method_definitions (int, tree, tree);
302 static void java_check_abstract_method_definitions (tree);
303 static void java_debug_context_do (int);
304 static void java_parser_context_push_initialized_field (void);
305 static void java_parser_context_pop_initialized_field (void);
306 static tree reorder_static_initialized (tree);
307 static void java_parser_context_suspend (void);
308 static void java_parser_context_resume (void);
309 static int pop_current_osb (struct parser_ctxt *);
311 /* JDK 1.1 work. FIXME */
313 static tree maybe_make_nested_class_name (tree);
314 static int make_nested_class_name (tree);
315 static void link_nested_class_to_enclosing (void);
316 static tree resolve_inner_class (htab_t, tree, tree *, tree *, tree);
317 static tree find_as_inner_class (tree, tree, tree);
318 static tree find_as_inner_class_do (tree, tree);
319 static int check_inner_class_redefinition (tree, tree);
321 static tree build_thisn_assign (void);
322 static tree build_current_thisn (tree);
323 static tree build_access_to_thisn (tree, tree, int);
324 static tree maybe_build_thisn_access_method (tree);
326 static tree build_outer_field_access (tree, tree);
327 static tree build_outer_field_access_methods (tree);
328 static tree build_outer_field_access_expr (int, tree, tree,
330 static tree build_outer_method_access_method (tree);
331 static tree build_new_access_id (void);
332 static tree build_outer_field_access_method (tree, tree, tree,
335 static int outer_field_access_p (tree, tree);
336 static int outer_field_expanded_access_p (tree, tree *,
338 static tree outer_field_access_fix (tree, tree, tree);
339 static tree build_incomplete_class_ref (int, tree);
340 static tree patch_incomplete_class_ref (tree);
341 static tree create_anonymous_class (tree);
342 static void patch_anonymous_class (tree, tree, tree);
343 static void add_inner_class_fields (tree, tree);
345 static tree build_dot_class_method (tree);
346 static tree build_dot_class_method_invocation (tree, tree);
347 static void create_new_parser_context (int);
348 static tree maybe_build_class_init_for_field (tree, tree);
350 static int emit_test_initialization (void **, void *);
352 static char *string_convert_int_cst (tree);
354 /* Number of error found so far. */
355 int java_error_count;
356 /* Number of warning found so far. */
357 int java_warning_count;
358 /* Tell when not to fold, when doing xrefs */
360 /* Cyclic inheritance report, as it can be set by layout_class */
361 const char *cyclic_inheritance_report;
363 /* The current parser context */
364 struct parser_ctxt *ctxp;
366 /* List of things that were analyzed for which code will be generated */
367 struct parser_ctxt *ctxp_for_generation = NULL;
369 /* binop_lookup maps token to tree_code. It is used where binary
370 operations are involved and required by the parser. RDIV_EXPR
371 covers both integral/floating point division. The code is changed
372 once the type of both operator is worked out. */
374 static const enum tree_code binop_lookup[19] =
376 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
377 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
378 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
379 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
380 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
382 #define BINOP_LOOKUP(VALUE) \
383 binop_lookup [((VALUE) - PLUS_TK) % ARRAY_SIZE (binop_lookup)]
385 /* This is the end index for binary operators that can also be used
386 in compound assignments. */
387 #define BINOP_COMPOUND_CANDIDATES 11
389 /* The "$L" identifier we use to create labels. */
390 static GTY(()) tree label_id;
392 /* The "StringBuffer" identifier used for the String `+' operator. */
393 static GTY(()) tree wfl_string_buffer;
395 /* The "append" identifier used for String `+' operator. */
396 static GTY(()) tree wfl_append;
398 /* The "toString" identifier used for String `+' operator. */
399 static GTY(()) tree wfl_to_string;
401 /* The "java.lang" import qualified name. */
402 static GTY(()) tree java_lang_id;
404 /* The generated `inst$' identifier used for generated enclosing
405 instance/field access functions. */
406 static GTY(()) tree inst_id;
408 /* Context and flag for static blocks */
409 static GTY(()) tree current_static_block;
411 /* The generated `write_parm_value$' identifier. */
412 static GTY(()) tree wpv_id;
414 /* The list of all packages we've seen so far */
415 static GTY(()) tree package_list;
417 /* Hold THIS for the scope of the current method decl. */
418 static GTY(()) tree current_this;
420 /* Hold a list of catch clauses list. The first element of this list is
421 the list of the catch clauses of the currently analyzed try block. */
422 static GTY(()) tree currently_caught_type_list;
424 /* This holds a linked list of all the case labels for the current
425 switch statement. It is only used when checking to see if there
426 are duplicate labels. FIXME: probably this should just be attached
427 to the switch itself; then it could be referenced via
428 `ctxp->current_loop'. */
429 static GTY(()) tree case_label_list;
431 /* Anonymous class counter. Will be reset to 1 every time a non
432 anonymous class gets created. */
433 static int anonymous_class_counter = 1;
435 static GTY(()) tree src_parse_roots[1];
437 /* All classes seen from source code */
438 #define gclass_list src_parse_roots[0]
440 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
441 line and point it out. */
442 /* Should point out the one that don't fit. ASCII/unicode, going
445 #define check_modifiers(__message, __value, __mask) do { \
446 if ((__value) & ~(__mask)) \
448 size_t i, remainder = (__value) & ~(__mask); \
449 for (i = 0; i < ARRAY_SIZE (ctxp->modifier_ctx); i++) \
450 if ((1 << i) & remainder) \
451 parse_error_context (ctxp->modifier_ctx [i], (__message), \
452 java_accstring_lookup (1 << i)); \
463 #ifdef USE_MAPPED_LOCATION
464 source_location location;
473 #ifdef USE_MAPPED_LOCATION
474 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
475 SET_EXPR_LOCATION(EXPR, (TOKEN).location)
477 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
478 (EXPR_WFL_LINECOL (EXPR) = (TOKEN).location)
486 /* Things defined here have to match the order of what's in the
487 binop_lookup table. */
489 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
490 %token LS_TK SRS_TK ZRS_TK
491 %token AND_TK XOR_TK OR_TK
492 %token BOOL_AND_TK BOOL_OR_TK
493 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
495 /* This maps to the same binop_lookup entry than the token above */
497 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
499 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
500 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
503 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
505 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
506 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
507 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
508 %token PAD_TK ABSTRACT_TK STRICT_TK
511 /* Keep those two in order, too */
512 %token DECR_TK INCR_TK
514 /* From now one, things can be in any order */
516 %token DEFAULT_TK IF_TK THROW_TK
517 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
518 %token THROWS_TK BREAK_TK IMPORT_TK
519 %token ELSE_TK INSTANCEOF_TK RETURN_TK
520 %token VOID_TK CATCH_TK INTERFACE_TK
521 %token CASE_TK EXTENDS_TK FINALLY_TK
522 %token SUPER_TK WHILE_TK CLASS_TK
523 %token SWITCH_TK CONST_TK TRY_TK
524 %token FOR_TK NEW_TK CONTINUE_TK
525 %token GOTO_TK PACKAGE_TK THIS_TK
528 %token BYTE_TK SHORT_TK INT_TK LONG_TK
529 %token CHAR_TK INTEGRAL_TK
531 %token FLOAT_TK DOUBLE_TK FP_TK
535 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
537 %token ASSIGN_ANY_TK ASSIGN_TK
538 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
540 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
541 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
543 %type <value> modifiers MODIFIER_TK final synchronized
545 %type <node> super ID_TK identifier
546 %type <node> name simple_name qualified_name
547 %type <node> type_declaration compilation_unit
548 field_declaration method_declaration extends_interfaces
549 interfaces interface_type_list
550 import_declarations package_declaration
551 type_declarations interface_body
552 interface_member_declaration constant_declaration
553 interface_member_declarations interface_type
554 abstract_method_declaration
555 %type <node> class_body_declaration class_member_declaration
556 static_initializer constructor_declaration block
557 %type <node> class_body_declarations constructor_header
558 %type <node> class_or_interface_type class_type class_type_list
559 constructor_declarator explicit_constructor_invocation
560 %type <node> dim_expr dim_exprs this_or_super throws
562 %type <node> variable_declarator_id variable_declarator
563 variable_declarators variable_initializer
564 variable_initializers constructor_body
567 %type <node> class_body block_end constructor_block_end
568 %type <node> statement statement_without_trailing_substatement
569 labeled_statement if_then_statement label_decl
570 if_then_else_statement while_statement for_statement
571 statement_nsi labeled_statement_nsi do_statement
572 if_then_else_statement_nsi while_statement_nsi
573 for_statement_nsi statement_expression_list for_init
574 for_update statement_expression expression_statement
575 primary_no_new_array expression primary array_type
576 array_creation_initialized array_creation_uninitialized
577 class_instance_creation_expression field_access
578 method_invocation array_access something_dot_new
579 argument_list postfix_expression while_expression
580 post_increment_expression post_decrement_expression
581 unary_expression_not_plus_minus unary_expression
582 pre_increment_expression pre_decrement_expression
584 multiplicative_expression additive_expression
585 shift_expression relational_expression
586 equality_expression and_expression
587 exclusive_or_expression inclusive_or_expression
588 conditional_and_expression conditional_or_expression
589 conditional_expression assignment_expression
590 left_hand_side assignment for_header for_begin
591 constant_expression do_statement_begin empty_statement
592 switch_statement synchronized_statement throw_statement
593 try_statement assert_statement
594 switch_expression switch_block
595 catches catch_clause catch_clause_parameter finally
596 anonymous_class_creation trap_overflow_corner_case
597 %type <node> return_statement break_statement continue_statement
599 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
600 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
601 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
602 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
603 %type <operator> ASSIGN_ANY_TK assignment_operator
604 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
605 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
606 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
607 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
608 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
609 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
610 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
611 %type <operator> NEW_TK ASSERT_TK
613 %type <node> method_body
615 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
616 STRING_LIT_TK NULL_TK VOID_TK
618 %type <node> IF_TK WHILE_TK FOR_TK
620 %type <node> formal_parameter_list formal_parameter
621 method_declarator method_header
623 %type <node> primitive_type reference_type type
624 BOOLEAN_TK INTEGRAL_TK FP_TK
626 /* Added or modified JDK 1.1 rule types */
627 %type <node> type_literals
630 /* 19.2 Production from 2.3: The Syntactic Grammar */
631 goal: compilation_unit
635 /* 19.3 Productions from 3: Lexical structure */
645 /* 19.4 Productions from 4: Types, Values and Variables */
658 class_or_interface_type
662 class_or_interface_type:
667 class_or_interface_type /* Default rule */
671 class_or_interface_type
677 int osb = pop_current_osb (ctxp);
678 tree t = build_java_array_type (($1), -1);
680 t = build_unresolved_array_type (t);
685 int osb = pop_current_osb (ctxp);
688 t = build_unresolved_array_type (t);
693 /* 19.5 Productions from 6: Names */
695 simple_name /* Default rule */
696 | qualified_name /* Default rule */
700 identifier /* Default rule */
704 name DOT_TK identifier
705 { $$ = make_qualified_name ($1, $3, $2.location); }
712 /* 19.6: Production from 7: Packages */
715 | package_declaration
716 | import_declarations
718 | package_declaration import_declarations
719 | package_declaration type_declarations
720 | import_declarations type_declarations
721 | package_declaration import_declarations type_declarations
729 | import_declarations import_declaration
737 | type_declarations type_declaration
741 PACKAGE_TK name SC_TK
743 ctxp->package = EXPR_WFL_NODE ($2);
744 register_package (ctxp->package);
747 {yyerror ("Missing name"); RECOVER;}
748 | PACKAGE_TK name error
749 {yyerror ("';' expected"); RECOVER;}
753 single_type_import_declaration
754 | type_import_on_demand_declaration
757 single_type_import_declaration:
760 tree name = EXPR_WFL_NODE ($2), last_name;
761 int i = IDENTIFIER_LENGTH (name)-1;
762 const char *last = &IDENTIFIER_POINTER (name)[i];
763 while (last != IDENTIFIER_POINTER (name))
769 last_name = get_identifier (++last);
770 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
772 tree err = find_name_in_single_imports (last_name);
773 if (err && err != name)
775 ($2, "Ambiguous class: %qs and %qs",
776 IDENTIFIER_POINTER (name),
777 IDENTIFIER_POINTER (err));
779 REGISTER_IMPORT ($2, last_name);
782 REGISTER_IMPORT ($2, last_name);
785 {yyerror ("Missing name"); RECOVER;}
786 | IMPORT_TK name error
787 {yyerror ("';' expected"); RECOVER;}
790 type_import_on_demand_declaration:
791 IMPORT_TK name DOT_TK MULT_TK SC_TK
793 tree name = EXPR_WFL_NODE ($2);
795 /* Search for duplicates. */
796 for (it = ctxp->import_demand_list; it; it = TREE_CHAIN (it))
797 if (EXPR_WFL_NODE (TREE_PURPOSE (it)) == name)
799 /* Don't import the same thing more than once, just ignore
800 duplicates (7.5.2) */
803 read_import_dir ($2);
804 ctxp->import_demand_list =
805 chainon (ctxp->import_demand_list,
806 build_tree_list ($2, NULL_TREE));
809 | IMPORT_TK name DOT_TK error
810 {yyerror ("'*' expected"); RECOVER;}
811 | IMPORT_TK name DOT_TK MULT_TK error
812 {yyerror ("';' expected"); RECOVER;}
817 { end_class_declaration (0); }
818 | interface_declaration
819 { end_class_declaration (0); }
824 yyerror ("Class or interface declaration expected");
828 /* 19.7 Shortened from the original:
829 modifiers: modifier | modifiers modifier
830 modifier: any of public... */
836 | modifiers MODIFIER_TK
841 (ctxp->modifier_ctx [$2], "Modifier %qs declared twice",
842 java_accstring_lookup (acc));
850 /* 19.8.1 Production from $8.1: Class Declaration */
852 modifiers CLASS_TK identifier super interfaces
853 { create_class ($1, $3, $4, $5); }
856 | CLASS_TK identifier super interfaces
857 { create_class (0, $2, $3, $4); }
860 | modifiers CLASS_TK error
861 { yyerror ("Missing class name"); RECOVER; }
863 { yyerror ("Missing class name"); RECOVER; }
864 | CLASS_TK identifier error
866 if (!ctxp->class_err) yyerror ("'{' expected");
869 | modifiers CLASS_TK identifier error
870 { if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER; }
875 | EXTENDS_TK class_type
877 | EXTENDS_TK class_type error
878 {yyerror ("'{' expected"); ctxp->class_err=1;}
880 {yyerror ("Missing super class name"); ctxp->class_err=1;}
885 | IMPLEMENTS_TK interface_type_list
887 | IMPLEMENTS_TK error
890 yyerror ("Missing interface name");
897 ctxp->interface_number = 1;
898 $$ = build_tree_list ($1, NULL_TREE);
900 | interface_type_list C_TK interface_type
902 ctxp->interface_number++;
903 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
905 | interface_type_list C_TK error
906 {yyerror ("Missing interface name"); RECOVER;}
912 /* Store the location of the `}' when doing xrefs */
914 DECL_END_SOURCE_LINE (GET_CPC ()) = $2.location;
917 | OCB_TK class_body_declarations CCB_TK
919 /* Store the location of the `}' when doing xrefs */
921 DECL_END_SOURCE_LINE (GET_CPC ()) = $3.location;
926 class_body_declarations:
927 class_body_declaration
928 | class_body_declarations class_body_declaration
931 class_body_declaration:
932 class_member_declaration
934 | constructor_declaration
935 | block /* Added, JDK1.1, instance initializer */
937 if (!IS_EMPTY_STMT ($1))
939 TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
940 SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
945 class_member_declaration:
948 | class_declaration /* Added, JDK1.1 inner classes */
949 { end_class_declaration (1); }
950 | interface_declaration /* Added, JDK1.1 inner interfaces */
951 { end_class_declaration (1); }
955 /* 19.8.2 Productions from 8.3: Field Declarations */
957 type variable_declarators SC_TK
958 { register_fields (0, $1, $2); }
959 | modifiers type variable_declarators SC_TK
962 ("Illegal modifier %qs for field declaration",
963 $1, FIELD_MODIFIERS);
964 check_modifiers_consistency ($1);
965 register_fields ($1, $2, $3);
969 variable_declarators:
970 /* Should we use build_decl_list () instead ? FIXME */
971 variable_declarator /* Default rule */
972 | variable_declarators C_TK variable_declarator
973 { $$ = chainon ($1, $3); }
974 | variable_declarators C_TK error
975 {yyerror ("Missing term"); RECOVER;}
979 variable_declarator_id
980 { $$ = build_tree_list ($1, NULL_TREE); }
981 | variable_declarator_id ASSIGN_TK variable_initializer
983 if (java_error_count)
986 ($1, build_assignment ($2.token, $2.location, $1, $3));
988 | variable_declarator_id ASSIGN_TK error
990 yyerror ("Missing variable initializer");
991 $$ = build_tree_list ($1, NULL_TREE);
994 | variable_declarator_id ASSIGN_TK variable_initializer error
996 yyerror ("';' expected");
997 $$ = build_tree_list ($1, NULL_TREE);
1002 variable_declarator_id:
1004 | variable_declarator_id OSB_TK CSB_TK
1005 { $$ = build_unresolved_array_type ($1); }
1007 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
1008 | variable_declarator_id OSB_TK error
1010 yyerror ("']' expected");
1013 | variable_declarator_id CSB_TK error
1014 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
1017 variable_initializer:
1022 /* 19.8.3 Productions from 8.4: Method Declarations */
1026 current_function_decl = $1;
1027 if (current_function_decl
1028 && TREE_CODE (current_function_decl) == FUNCTION_DECL)
1029 source_start_java_method (current_function_decl);
1031 current_function_decl = NULL_TREE;
1034 { finish_method_declaration ($3); }
1035 | method_header error
1036 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
1040 type method_declarator throws
1041 { $$ = method_header (0, $1, $2, $3); }
1042 | VOID_TK method_declarator throws
1043 { $$ = method_header (0, void_type_node, $2, $3); }
1044 | modifiers type method_declarator throws
1045 { $$ = method_header ($1, $2, $3, $4); }
1046 | modifiers VOID_TK method_declarator throws
1047 { $$ = method_header ($1, void_type_node, $3, $4); }
1050 yyerror ("Invalid method declaration, method name required");
1053 | modifiers type error
1055 yyerror ("Identifier expected");
1060 yyerror ("Identifier expected");
1063 | modifiers VOID_TK error
1065 yyerror ("Identifier expected");
1070 yyerror ("Invalid method declaration, return type required");
1076 identifier OP_TK CP_TK
1078 ctxp->formal_parameter_number = 0;
1079 $$ = method_declarator ($1, NULL_TREE);
1081 | identifier OP_TK formal_parameter_list CP_TK
1082 { $$ = method_declarator ($1, $3); }
1083 | method_declarator OSB_TK CSB_TK
1085 SET_EXPR_LOCATION_FROM_TOKEN (wfl_operator, $2);
1087 build_unresolved_array_type (TREE_PURPOSE ($1));
1088 parse_warning_context
1090 "Discouraged form of returned type specification");
1092 | identifier OP_TK error
1093 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1094 | method_declarator OSB_TK error
1095 {yyerror ("']' expected"); RECOVER;}
1098 formal_parameter_list:
1101 ctxp->formal_parameter_number = 1;
1103 | formal_parameter_list C_TK formal_parameter
1105 ctxp->formal_parameter_number += 1;
1106 $$ = chainon ($1, $3);
1108 | formal_parameter_list C_TK error
1109 { yyerror ("Missing formal parameter term"); RECOVER; }
1113 type variable_declarator_id
1115 $$ = build_tree_list ($2, $1);
1117 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1119 $$ = build_tree_list ($3, $2);
1120 ARG_FINAL_P ($$) = 1;
1124 yyerror ("Missing identifier"); RECOVER;
1129 yyerror ("Missing identifier"); RECOVER;
1137 check_modifiers ("Illegal modifier %qs. Only %<final%> was expected here",
1139 if ($1 != ACC_FINAL)
1140 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1146 | THROWS_TK class_type_list
1149 {yyerror ("Missing class type term"); RECOVER;}
1154 { $$ = build_tree_list ($1, $1); }
1155 | class_type_list C_TK class_type
1156 { $$ = tree_cons ($3, $3, $1); }
1157 | class_type_list C_TK error
1158 {yyerror ("Missing class type term"); RECOVER;}
1163 | SC_TK { $$ = NULL_TREE; }
1166 /* 19.8.4 Productions from 8.5: Static Initializers */
1170 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1171 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1172 current_static_block = NULL_TREE;
1176 static: /* Test lval.sub_token here */
1179 check_modifiers ("Illegal modifier %qs for static initializer", $1, ACC_STATIC);
1180 /* Can't have a static initializer in an innerclass */
1181 if ($1 | ACC_STATIC &&
1182 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1184 (MODIFIER_WFL (STATIC_TK),
1185 "Can't define static initializer in class %qs. Static initializer can only be defined in top-level classes",
1186 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1187 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1191 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1192 constructor_declaration:
1195 current_function_decl = $1;
1196 source_start_java_method (current_function_decl);
1199 { finish_method_declaration ($3); }
1203 constructor_declarator throws
1204 { $$ = method_header (0, NULL_TREE, $1, $2); }
1205 | modifiers constructor_declarator throws
1206 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1209 constructor_declarator:
1210 simple_name OP_TK CP_TK
1212 ctxp->formal_parameter_number = 0;
1213 $$ = method_declarator ($1, NULL_TREE);
1215 | simple_name OP_TK formal_parameter_list CP_TK
1216 { $$ = method_declarator ($1, $3); }
1220 /* Unlike regular method, we always need a complete (empty)
1221 body so we can safely perform all the required code
1222 addition (super invocation and field initialization) */
1223 block_begin constructor_block_end
1225 BLOCK_EXPR_BODY ($2) = build_java_empty_stmt ();
1228 | block_begin explicit_constructor_invocation constructor_block_end
1230 | block_begin block_statements constructor_block_end
1232 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1236 constructor_block_end:
1240 /* Error recovery for that rule moved down expression_statement: rule. */
1241 explicit_constructor_invocation:
1242 this_or_super OP_TK CP_TK SC_TK
1244 $$ = build_method_invocation ($1, NULL_TREE);
1245 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1246 $$ = java_method_add_stmt (current_function_decl, $$);
1248 | this_or_super OP_TK argument_list CP_TK SC_TK
1250 $$ = build_method_invocation ($1, $3);
1251 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1252 $$ = java_method_add_stmt (current_function_decl, $$);
1254 /* Added, JDK1.1 inner classes. Modified because the rule
1255 'primary' couldn't work. */
1256 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1257 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1258 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1259 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1262 this_or_super: /* Added, simplifies error diagnostics */
1265 tree wfl = build_wfl_node (this_identifier_node);
1266 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1271 tree wfl = build_wfl_node (super_identifier_node);
1272 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1277 /* 19.9 Productions from 9: Interfaces */
1278 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1279 interface_declaration:
1280 INTERFACE_TK identifier
1281 { create_interface (0, $2, NULL_TREE); }
1284 | modifiers INTERFACE_TK identifier
1285 { create_interface ($1, $3, NULL_TREE); }
1288 | INTERFACE_TK identifier extends_interfaces
1289 { create_interface (0, $2, $3); }
1292 | modifiers INTERFACE_TK identifier extends_interfaces
1293 { create_interface ($1, $3, $4); }
1296 | INTERFACE_TK identifier error
1297 { yyerror ("'{' expected"); RECOVER; }
1298 | modifiers INTERFACE_TK identifier error
1299 { yyerror ("'{' expected"); RECOVER; }
1303 EXTENDS_TK interface_type
1305 ctxp->interface_number = 1;
1306 $$ = build_tree_list ($2, NULL_TREE);
1308 | extends_interfaces C_TK interface_type
1310 ctxp->interface_number++;
1311 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1314 {yyerror ("Invalid interface type"); RECOVER;}
1315 | extends_interfaces C_TK error
1316 {yyerror ("Missing term"); RECOVER;}
1322 | OCB_TK interface_member_declarations CCB_TK
1326 interface_member_declarations:
1327 interface_member_declaration
1328 | interface_member_declarations interface_member_declaration
1331 interface_member_declaration:
1332 constant_declaration
1333 | abstract_method_declaration
1334 | class_declaration /* Added, JDK1.1 inner classes */
1335 { end_class_declaration (1); }
1336 | interface_declaration /* Added, JDK1.1 inner interfaces */
1337 { end_class_declaration (1); }
1340 constant_declaration:
1344 abstract_method_declaration:
1347 check_abstract_method_header ($1);
1348 current_function_decl = NULL_TREE; /* FIXME ? */
1350 | method_header error
1351 {yyerror ("';' expected"); RECOVER;}
1354 /* 19.10 Productions from 10: Arrays */
1357 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1358 | OCB_TK C_TK CCB_TK
1359 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1360 | OCB_TK variable_initializers CCB_TK
1361 { $$ = build_new_array_init ($1.location, $2); }
1362 | OCB_TK variable_initializers C_TK CCB_TK
1363 { $$ = build_new_array_init ($1.location, $2); }
1366 variable_initializers:
1367 variable_initializer
1369 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1372 | variable_initializers C_TK variable_initializer
1374 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1376 | variable_initializers C_TK error
1377 {yyerror ("Missing term"); RECOVER;}
1380 /* 19.11 Production from 14: Blocks and Statements */
1382 block_begin block_end
1384 | block_begin block_statements block_end
1396 maybe_absorb_scoping_blocks ();
1397 /* Store the location of the `}' when doing xrefs */
1398 if (current_function_decl && flag_emit_xref)
1399 DECL_END_SOURCE_LINE (current_function_decl) = $1.location;
1401 if (!BLOCK_SUBBLOCKS ($$))
1402 BLOCK_SUBBLOCKS ($$) = build_java_empty_stmt ();
1408 | block_statements block_statement
1412 local_variable_declaration_statement
1414 { java_method_add_stmt (current_function_decl, $1); }
1415 | class_declaration /* Added, JDK1.1 local classes */
1417 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1418 end_class_declaration (1);
1422 local_variable_declaration_statement:
1423 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1426 local_variable_declaration:
1427 type variable_declarators
1428 { declare_local_variables (0, $1, $2); }
1429 | final type variable_declarators /* Added, JDK1.1 final locals */
1430 { declare_local_variables ($1, $2, $3); }
1434 statement_without_trailing_substatement
1437 | if_then_else_statement
1440 { $$ = exit_block (); }
1444 statement_without_trailing_substatement
1445 | labeled_statement_nsi
1446 | if_then_else_statement_nsi
1447 | while_statement_nsi
1449 { $$ = exit_block (); }
1452 statement_without_trailing_substatement:
1455 | expression_statement
1459 | continue_statement
1461 | synchronized_statement
1470 if (flag_extraneous_semicolon
1471 && ! current_static_block
1472 && (! current_function_decl ||
1473 /* Verify we're not in a inner class declaration */
1474 (GET_CPC () != TYPE_NAME
1475 (DECL_CONTEXT (current_function_decl)))))
1478 #ifdef USE_MAPPED_LOCATION
1479 SET_EXPR_LOCATION (wfl_operator, input_location);
1481 EXPR_WFL_SET_LINECOL (wfl_operator, input_line, -1);
1483 parse_warning_context (wfl_operator, "An empty declaration is a deprecated feature that should not be used");
1485 $$ = build_java_empty_stmt ();
1490 identifier REL_CL_TK
1492 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1493 EXPR_WFL_NODE ($1));
1495 push_labeled_block ($$);
1496 PUSH_LABELED_BLOCK ($$);
1501 label_decl statement
1502 { $$ = finish_labeled_statement ($1, $2); }
1504 {yyerror ("':' expected"); RECOVER;}
1507 labeled_statement_nsi:
1508 label_decl statement_nsi
1509 { $$ = finish_labeled_statement ($1, $2); }
1512 /* We concentrate here a bunch of error handling rules that we couldn't write
1513 earlier, because expression_statement catches a missing ';'. */
1514 expression_statement:
1515 statement_expression SC_TK
1517 /* We have a statement. Generate a WFL around it so
1519 #ifdef USE_MAPPED_LOCATION
1520 $$ = expr_add_location ($1, input_location, 1);
1522 $$ = build_expr_wfl ($1, input_filename, input_line, 0);
1523 JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1525 /* We know we have a statement, so set the debug
1526 info to be eventually generate here. */
1530 YYNOT_TWICE yyerror ("Invalid expression statement");
1531 DRECOVER (expr_stmt);
1535 YYNOT_TWICE yyerror ("Invalid expression statement");
1536 DRECOVER (expr_stmt);
1540 YYNOT_TWICE yyerror ("Invalid expression statement");
1541 DRECOVER (expr_stmt);
1543 | this_or_super OP_TK error
1544 {yyerror ("')' expected"); RECOVER;}
1545 | this_or_super OP_TK CP_TK error
1547 parse_ctor_invocation_error ();
1550 | this_or_super OP_TK argument_list error
1551 {yyerror ("')' expected"); RECOVER;}
1552 | this_or_super OP_TK argument_list CP_TK error
1554 parse_ctor_invocation_error ();
1557 | name DOT_TK SUPER_TK error
1558 {yyerror ("'(' expected"); RECOVER;}
1559 | name DOT_TK SUPER_TK OP_TK error
1560 {yyerror ("')' expected"); RECOVER;}
1561 | name DOT_TK SUPER_TK OP_TK argument_list error
1562 {yyerror ("')' expected"); RECOVER;}
1563 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1564 {yyerror ("';' expected"); RECOVER;}
1565 | name DOT_TK SUPER_TK OP_TK CP_TK error
1566 {yyerror ("';' expected"); RECOVER;}
1569 statement_expression:
1571 | pre_increment_expression
1572 | pre_decrement_expression
1573 | post_increment_expression
1574 | post_decrement_expression
1576 | class_instance_creation_expression
1580 IF_TK OP_TK expression CP_TK statement
1582 $$ = build_if_else_statement ($2.location, $3,
1586 {yyerror ("'(' expected"); RECOVER;}
1588 {yyerror ("Missing term"); RECOVER;}
1589 | IF_TK OP_TK expression error
1590 {yyerror ("')' expected"); RECOVER;}
1593 if_then_else_statement:
1594 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1595 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1598 if_then_else_statement_nsi:
1599 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1600 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1610 /* Make into "proper list" of COMPOUND_EXPRs.
1611 I.e. make the last statement also have its own
1613 maybe_absorb_scoping_blocks ();
1614 TREE_OPERAND ($1, 1) = exit_block ();
1615 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1620 SWITCH_TK OP_TK expression CP_TK
1622 $$ = build3 (SWITCH_EXPR, NULL_TREE, $3,
1623 NULL_TREE, NULL_TREE);
1624 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
1627 {yyerror ("'(' expected"); RECOVER;}
1628 | SWITCH_TK OP_TK error
1629 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1630 | SWITCH_TK OP_TK expression CP_TK error
1631 {yyerror ("'{' expected"); RECOVER;}
1634 /* Default assignment is there to avoid type node on switch_block
1640 | OCB_TK switch_labels CCB_TK
1642 | OCB_TK switch_block_statement_groups CCB_TK
1644 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1648 switch_block_statement_groups:
1649 switch_block_statement_group
1650 | switch_block_statement_groups switch_block_statement_group
1653 switch_block_statement_group:
1654 switch_labels block_statements
1659 | switch_labels switch_label
1663 CASE_TK constant_expression REL_CL_TK
1665 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1666 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1667 java_method_add_stmt (current_function_decl, lab);
1669 | DEFAULT_TK REL_CL_TK
1671 tree lab = make_node (DEFAULT_EXPR);
1672 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1673 java_method_add_stmt (current_function_decl, lab);
1676 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1677 | CASE_TK constant_expression error
1678 {yyerror ("':' expected"); RECOVER;}
1680 {yyerror ("':' expected"); RECOVER;}
1684 WHILE_TK OP_TK expression CP_TK
1686 tree body = build_loop_body ($2.location, $3, 0);
1687 $$ = build_new_loop (body);
1692 while_expression statement
1693 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1695 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1696 | WHILE_TK OP_TK error
1697 {yyerror ("Missing term and ')' expected"); RECOVER;}
1698 | WHILE_TK OP_TK expression error
1699 {yyerror ("')' expected"); RECOVER;}
1702 while_statement_nsi:
1703 while_expression statement_nsi
1704 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1710 tree body = build_loop_body (0, NULL_TREE, 1);
1711 $$ = build_new_loop (body);
1713 /* Need error handing here. FIXME */
1717 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1718 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1722 for_begin SC_TK expression SC_TK for_update CP_TK statement
1724 if (CONSTANT_CLASS_P ($3))
1725 $3 = build_wfl_node ($3);
1726 $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1728 | for_begin SC_TK SC_TK for_update CP_TK statement
1730 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1731 /* We have not condition, so we get rid of the EXIT_EXPR */
1732 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1733 build_java_empty_stmt ();
1735 | for_begin SC_TK error
1736 {yyerror ("Invalid control expression"); RECOVER;}
1737 | for_begin SC_TK expression SC_TK error
1738 {yyerror ("Invalid update expression"); RECOVER;}
1739 | for_begin SC_TK SC_TK error
1740 {yyerror ("Invalid update expression"); RECOVER;}
1744 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1745 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1746 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1748 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1749 /* We have not condition, so we get rid of the EXIT_EXPR */
1750 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1751 build_java_empty_stmt ();
1758 /* This scope defined for local variable that may be
1759 defined within the scope of the for loop */
1763 {yyerror ("'(' expected"); DRECOVER(for_1);}
1764 | FOR_TK OP_TK error
1765 {yyerror ("Invalid init statement"); RECOVER;}
1771 /* We now declare the loop body. The loop is
1772 declared as a for loop. */
1773 tree body = build_loop_body (0, NULL_TREE, 0);
1774 $$ = build_new_loop (body);
1775 FOR_LOOP_P ($$) = 1;
1776 /* The loop is added to the current block the for
1777 statement is defined within */
1778 java_method_add_stmt (current_function_decl, $$);
1781 for_init: /* Can be empty */
1782 { $$ = build_java_empty_stmt (); }
1783 | statement_expression_list
1785 /* Init statement recorded within the previously
1786 defined block scope */
1787 $$ = java_method_add_stmt (current_function_decl, $1);
1789 | local_variable_declaration
1791 /* Local variable are recorded within the previously
1792 defined block scope */
1795 | statement_expression_list error
1796 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1799 for_update: /* Can be empty */
1800 {$$ = build_java_empty_stmt ();}
1801 | statement_expression_list
1802 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1805 statement_expression_list:
1806 statement_expression
1807 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1808 | statement_expression_list C_TK statement_expression
1809 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1810 | statement_expression_list C_TK error
1811 {yyerror ("Missing term"); RECOVER;}
1816 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1817 | BREAK_TK identifier SC_TK
1818 { $$ = build_bc_statement ($1.location, 1, $2); }
1820 {yyerror ("Missing term"); RECOVER;}
1821 | BREAK_TK identifier error
1822 {yyerror ("';' expected"); RECOVER;}
1827 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1828 | CONTINUE_TK identifier SC_TK
1829 { $$ = build_bc_statement ($1.location, 0, $2); }
1831 {yyerror ("Missing term"); RECOVER;}
1832 | CONTINUE_TK identifier error
1833 {yyerror ("';' expected"); RECOVER;}
1838 { $$ = build_return ($1.location, NULL_TREE); }
1839 | RETURN_TK expression SC_TK
1840 { $$ = build_return ($1.location, $2); }
1842 {yyerror ("Missing term"); RECOVER;}
1843 | RETURN_TK expression error
1844 {yyerror ("';' expected"); RECOVER;}
1848 THROW_TK expression SC_TK
1850 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1851 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1854 {yyerror ("Missing term"); RECOVER;}
1855 | THROW_TK expression error
1856 {yyerror ("';' expected"); RECOVER;}
1860 ASSERT_TK expression REL_CL_TK expression SC_TK
1862 $$ = build_assertion ($1.location, $2, $4);
1864 | ASSERT_TK expression SC_TK
1866 $$ = build_assertion ($1.location, $2, NULL_TREE);
1869 {yyerror ("Missing term"); RECOVER;}
1870 | ASSERT_TK expression error
1871 {yyerror ("';' expected"); RECOVER;}
1874 synchronized_statement:
1875 synchronized OP_TK expression CP_TK block
1877 $$ = build2 (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1878 EXPR_WFL_LINECOL ($$) =
1879 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1881 | synchronized OP_TK expression CP_TK error
1882 {yyerror ("'{' expected"); RECOVER;}
1883 | synchronized error
1884 {yyerror ("'(' expected"); RECOVER;}
1885 | synchronized OP_TK error CP_TK
1886 {yyerror ("Missing term"); RECOVER;}
1887 | synchronized OP_TK error
1888 {yyerror ("Missing term"); RECOVER;}
1895 "Illegal modifier %qs. Only %<synchronized%> was expected here",
1896 $1, ACC_SYNCHRONIZED);
1897 if ($1 != ACC_SYNCHRONIZED)
1898 MODIFIER_WFL (SYNCHRONIZED_TK) =
1899 build_wfl_node (NULL_TREE);
1904 TRY_TK block catches
1905 { $$ = build_try_statement ($1.location, $2, $3); }
1906 | TRY_TK block finally
1907 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1908 | TRY_TK block catches finally
1909 { $$ = build_try_finally_statement
1910 ($1.location, build_try_statement ($1.location,
1914 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1919 | catches catch_clause
1921 TREE_CHAIN ($2) = $1;
1927 catch_clause_parameter block
1929 java_method_add_stmt (current_function_decl, $2);
1935 catch_clause_parameter:
1936 CATCH_TK OP_TK formal_parameter CP_TK
1938 /* We add a block to define a scope for
1939 formal_parameter (CCBP). The formal parameter is
1940 declared initialized by the appropriate function
1946 ccpb = enter_block ();
1947 init = build_assignment
1948 (ASSIGN_TK, $2.location, TREE_PURPOSE ($3),
1949 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
1950 declare_local_variables (0, TREE_VALUE ($3),
1952 (TREE_PURPOSE ($3), init));
1953 $$ = build1 (JAVA_CATCH_EXPR, NULL_TREE, ccpb);
1954 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1958 $$ = error_mark_node;
1962 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1963 | CATCH_TK OP_TK error
1965 yyerror ("Missing term or ')' expected");
1966 RECOVER; $$ = NULL_TREE;
1968 | CATCH_TK OP_TK error CP_TK /* That's for () */
1969 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1976 {yyerror ("'{' expected"); RECOVER; }
1979 /* 19.12 Production from 15: Expressions */
1981 primary_no_new_array
1982 | array_creation_uninitialized
1983 | array_creation_initialized
1986 primary_no_new_array:
1989 { $$ = build_this ($1.location); }
1990 | OP_TK expression CP_TK
1992 | class_instance_creation_expression
1997 /* Added, JDK1.1 inner classes. Documentation is wrong
1998 referring to a 'ClassName' (class_name) rule that doesn't
1999 exist. Used name: instead. */
2000 | name DOT_TK THIS_TK
2002 tree wfl = build_wfl_node (this_identifier_node);
2003 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
2005 | OP_TK expression error
2006 {yyerror ("')' expected"); RECOVER;}
2008 {yyerror ("'class' or 'this' expected" ); RECOVER;}
2009 | primitive_type DOT_TK error
2010 {yyerror ("'class' expected" ); RECOVER;}
2011 | VOID_TK DOT_TK error
2012 {yyerror ("'class' expected" ); RECOVER;}
2016 name DOT_TK CLASS_TK
2017 { $$ = build_incomplete_class_ref ($2.location, $1); }
2018 | array_type DOT_TK CLASS_TK
2019 { $$ = build_incomplete_class_ref ($2.location, $1); }
2020 | primitive_type DOT_TK CLASS_TK
2021 { $$ = build_incomplete_class_ref ($2.location, $1); }
2022 | VOID_TK DOT_TK CLASS_TK
2024 $$ = build_incomplete_class_ref ($2.location,
2029 class_instance_creation_expression:
2030 NEW_TK class_type OP_TK argument_list CP_TK
2031 { $$ = build_new_invocation ($2, $4); }
2032 | NEW_TK class_type OP_TK CP_TK
2033 { $$ = build_new_invocation ($2, NULL_TREE); }
2034 | anonymous_class_creation
2035 /* Added, JDK1.1 inner classes, modified to use name or
2036 primary instead of primary solely which couldn't work in
2038 | something_dot_new identifier OP_TK CP_TK
2040 tree ctor = build_new_invocation ($2, NULL_TREE);
2041 $$ = make_qualified_primary ($1, ctor,
2042 EXPR_WFL_LINECOL ($1));
2044 | something_dot_new identifier OP_TK CP_TK class_body
2045 | something_dot_new identifier OP_TK argument_list CP_TK
2047 tree ctor = build_new_invocation ($2, $4);
2048 $$ = make_qualified_primary ($1, ctor,
2049 EXPR_WFL_LINECOL ($1));
2051 | something_dot_new identifier OP_TK argument_list CP_TK class_body
2052 | NEW_TK error SC_TK
2053 {$$ = NULL_TREE; yyerror ("'(' expected"); DRECOVER(new_1);}
2054 | NEW_TK class_type error
2055 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2056 | NEW_TK class_type OP_TK error
2057 {$$ = NULL_TREE; yyerror ("')' or term expected"); RECOVER;}
2058 | NEW_TK class_type OP_TK argument_list error
2059 {$$ = NULL_TREE; yyerror ("')' expected"); RECOVER;}
2060 | something_dot_new error
2064 yyerror ("Identifier expected");
2067 | something_dot_new identifier error
2068 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2071 /* Created after JDK1.1 rules originally added to
2072 class_instance_creation_expression, but modified to use
2073 'class_type' instead of 'TypeName' (type_name) which is mentioned
2074 in the documentation but doesn't exist. */
2076 anonymous_class_creation:
2077 NEW_TK class_type OP_TK argument_list CP_TK
2078 { create_anonymous_class ($2); }
2081 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2082 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2084 end_class_declaration (1);
2086 /* Now we can craft the new expression */
2087 $$ = build_new_invocation (id, $4);
2089 /* Note that we can't possibly be here if
2090 `class_type' is an interface (in which case the
2091 anonymous class extends Object and implements
2092 `class_type', hence its constructor can't have
2095 /* Otherwise, the innerclass must feature a
2096 constructor matching `argument_list'. Anonymous
2097 classes are a bit special: it's impossible to
2098 define constructor for them, hence constructors
2099 must be generated following the hints provided by
2100 the `new' expression. Whether a super constructor
2101 of that nature exists or not is to be verified
2102 later on in verify_constructor_super.
2104 It's during the expansion of a `new' statement
2105 referring to an anonymous class that a ctor will
2106 be generated for the anonymous class, with the
2110 | NEW_TK class_type OP_TK CP_TK
2111 { create_anonymous_class ($2); }
2114 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2115 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2117 end_class_declaration (1);
2119 /* Now we can craft the new expression. The
2120 statement doesn't need to be remember so that a
2121 constructor can be generated, since its signature
2122 is already known. */
2123 $$ = build_new_invocation (id, NULL_TREE);
2127 something_dot_new: /* Added, not part of the specs. */
2130 | primary DOT_TK NEW_TK
2137 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2138 ctxp->formal_parameter_number = 1;
2140 | argument_list C_TK expression
2142 ctxp->formal_parameter_number += 1;
2143 $$ = tree_cons (NULL_TREE, $3, $1);
2145 | argument_list C_TK error
2146 {yyerror ("Missing term"); RECOVER;}
2149 array_creation_uninitialized:
2150 NEW_TK primitive_type dim_exprs
2151 { $$ = build_newarray_node ($2, $3, 0); }
2152 | NEW_TK class_or_interface_type dim_exprs
2153 { $$ = build_newarray_node ($2, $3, 0); }
2154 | NEW_TK primitive_type dim_exprs dims
2155 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2156 | NEW_TK class_or_interface_type dim_exprs dims
2157 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2158 | NEW_TK error CSB_TK
2159 {yyerror ("'[' expected"); DRECOVER ("]");}
2160 | NEW_TK error OSB_TK
2161 {yyerror ("']' expected"); RECOVER;}
2164 array_creation_initialized:
2165 /* Added, JDK1.1 anonymous array. Initial documentation rule
2167 NEW_TK class_or_interface_type dims array_initializer
2170 int osb = pop_current_osb (ctxp);
2172 obstack_grow (&temporary_obstack, "[]", 2);
2173 obstack_1grow (&temporary_obstack, '\0');
2174 sig = obstack_finish (&temporary_obstack);
2175 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2176 $2, get_identifier (sig), $4);
2178 | NEW_TK primitive_type dims array_initializer
2180 int osb = pop_current_osb (ctxp);
2183 type = build_java_array_type (type, -1);
2184 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2185 build_pointer_type (type), NULL_TREE, $4);
2187 | NEW_TK error CSB_TK
2188 {yyerror ("'[' expected"); DRECOVER ("]");}
2189 | NEW_TK error OSB_TK
2190 {yyerror ("']' expected"); RECOVER;}
2195 { $$ = build_tree_list (NULL_TREE, $1); }
2196 | dim_exprs dim_expr
2197 { $$ = tree_cons (NULL_TREE, $2, $$); }
2201 OSB_TK expression CSB_TK
2203 if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2205 $2 = build_wfl_node ($2);
2206 TREE_TYPE ($2) = NULL_TREE;
2208 EXPR_WFL_LINECOL ($2) = $1.location;
2211 | OSB_TK expression error
2212 {yyerror ("']' expected"); RECOVER;}
2215 yyerror ("Missing term");
2216 yyerror ("']' expected");
2225 /* If not initialized, allocate memory for the osb
2227 if (!ctxp->osb_limit)
2229 allocate = ctxp->osb_limit = 32;
2230 ctxp->osb_depth = -1;
2232 /* If capacity overflown, reallocate a bigger chunk */
2233 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2234 allocate = ctxp->osb_limit << 1;
2238 allocate *= sizeof (int);
2239 if (ctxp->osb_number)
2240 ctxp->osb_number = xrealloc (ctxp->osb_number,
2243 ctxp->osb_number = xmalloc (allocate);
2246 CURRENT_OSB (ctxp) = 1;
2248 | dims OSB_TK CSB_TK
2249 { CURRENT_OSB (ctxp)++; }
2251 { yyerror ("']' expected"); RECOVER;}
2255 primary DOT_TK identifier
2256 { $$ = make_qualified_primary ($1, $3, $2.location); }
2257 /* FIXME - REWRITE TO:
2258 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2259 | SUPER_TK DOT_TK identifier
2261 tree super_wfl = build_wfl_node (super_identifier_node);
2262 SET_EXPR_LOCATION_FROM_TOKEN (super_wfl, $1);
2263 $$ = make_qualified_name (super_wfl, $3, $2.location);
2266 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2271 { $$ = build_method_invocation ($1, NULL_TREE); }
2272 | name OP_TK argument_list CP_TK
2273 { $$ = build_method_invocation ($1, $3); }
2274 | primary DOT_TK identifier OP_TK CP_TK
2276 if (TREE_CODE ($1) == THIS_EXPR)
2277 $$ = build_this_super_qualified_invocation
2278 (1, $3, NULL_TREE, 0, $2.location);
2281 tree invok = build_method_invocation ($3, NULL_TREE);
2282 $$ = make_qualified_primary ($1, invok, $2.location);
2285 | primary DOT_TK identifier OP_TK argument_list CP_TK
2287 if (TREE_CODE ($1) == THIS_EXPR)
2288 $$ = build_this_super_qualified_invocation
2289 (1, $3, $5, 0, $2.location);
2292 tree invok = build_method_invocation ($3, $5);
2293 $$ = make_qualified_primary ($1, invok, $2.location);
2296 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2298 $$ = build_this_super_qualified_invocation
2299 (0, $3, NULL_TREE, $1.location, $2.location);
2301 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2303 $$ = build_this_super_qualified_invocation
2304 (0, $3, $5, $1.location, $2.location);
2306 /* Screws up thing. I let it here until I'm convinced it can
2308 | primary DOT_TK error
2309 {yyerror ("'(' expected"); DRECOVER(bad);} */
2310 | SUPER_TK DOT_TK error CP_TK
2311 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2312 | SUPER_TK DOT_TK error DOT_TK
2313 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2317 name OSB_TK expression CSB_TK
2318 { $$ = build_array_ref ($2.location, $1, $3); }
2319 | primary_no_new_array OSB_TK expression CSB_TK
2320 { $$ = build_array_ref ($2.location, $1, $3); }
2321 | array_creation_initialized OSB_TK expression CSB_TK
2322 { $$ = build_array_ref ($2.location, $1, $3); }
2325 yyerror ("Missing term and ']' expected");
2326 DRECOVER(array_access);
2328 | name OSB_TK expression error
2330 yyerror ("']' expected");
2331 DRECOVER(array_access);
2333 | primary_no_new_array OSB_TK error
2335 yyerror ("Missing term and ']' expected");
2336 DRECOVER(array_access);
2338 | primary_no_new_array OSB_TK expression error
2340 yyerror ("']' expected");
2341 DRECOVER(array_access);
2343 | array_creation_initialized OSB_TK error
2345 yyerror ("Missing term and ']' expected");
2346 DRECOVER(array_access);
2348 | array_creation_initialized OSB_TK expression error
2350 yyerror ("']' expected");
2351 DRECOVER(array_access);
2358 | post_increment_expression
2359 | post_decrement_expression
2362 post_increment_expression:
2363 postfix_expression INCR_TK
2364 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2367 post_decrement_expression:
2368 postfix_expression DECR_TK
2369 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2372 trap_overflow_corner_case:
2373 pre_increment_expression
2374 | pre_decrement_expression
2375 | PLUS_TK unary_expression
2376 {$$ = build_unaryop ($1.token, $1.location, $2); }
2377 | unary_expression_not_plus_minus
2379 {yyerror ("Missing term"); RECOVER}
2383 trap_overflow_corner_case
2386 error_if_numeric_overflow ($1);
2389 | MINUS_TK trap_overflow_corner_case
2390 {$$ = build_unaryop ($1.token, $1.location, $2); }
2392 {yyerror ("Missing term"); RECOVER}
2395 pre_increment_expression:
2396 INCR_TK unary_expression
2397 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2399 {yyerror ("Missing term"); RECOVER}
2402 pre_decrement_expression:
2403 DECR_TK unary_expression
2404 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2406 {yyerror ("Missing term"); RECOVER}
2409 unary_expression_not_plus_minus:
2411 | NOT_TK unary_expression
2412 {$$ = build_unaryop ($1.token, $1.location, $2); }
2413 | NEG_TK unary_expression
2414 {$$ = build_unaryop ($1.token, $1.location, $2); }
2417 {yyerror ("Missing term"); RECOVER}
2419 {yyerror ("Missing term"); RECOVER}
2422 cast_expression: /* Error handling here is potentially weak */
2423 OP_TK primitive_type dims CP_TK unary_expression
2426 int osb = pop_current_osb (ctxp);
2428 type = build_java_array_type (type, -1);
2429 $$ = build_cast ($1.location, type, $5);
2431 | OP_TK primitive_type CP_TK unary_expression
2432 { $$ = build_cast ($1.location, $2, $4); }
2433 | OP_TK expression CP_TK unary_expression_not_plus_minus
2434 { $$ = build_cast ($1.location, $2, $4); }
2435 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2438 int osb = pop_current_osb (ctxp);
2439 obstack_grow (&temporary_obstack,
2440 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2441 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2443 obstack_grow (&temporary_obstack, "[]", 2);
2444 obstack_1grow (&temporary_obstack, '\0');
2445 ptr = obstack_finish (&temporary_obstack);
2446 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2447 $$ = build_cast ($1.location, $2, $5);
2449 | OP_TK primitive_type OSB_TK error
2450 {yyerror ("']' expected, invalid type expression");}
2453 YYNOT_TWICE yyerror ("Invalid type expression"); RECOVER;
2456 | OP_TK primitive_type dims CP_TK error
2457 {yyerror ("Missing term"); RECOVER;}
2458 | OP_TK primitive_type CP_TK error
2459 {yyerror ("Missing term"); RECOVER;}
2460 | OP_TK name dims CP_TK error
2461 {yyerror ("Missing term"); RECOVER;}
2464 multiplicative_expression:
2466 | multiplicative_expression MULT_TK unary_expression
2468 $$ = build_binop (BINOP_LOOKUP ($2.token),
2469 $2.location, $1, $3);
2471 | multiplicative_expression DIV_TK unary_expression
2473 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2476 | multiplicative_expression REM_TK unary_expression
2478 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2481 | multiplicative_expression MULT_TK error
2482 {yyerror ("Missing term"); RECOVER;}
2483 | multiplicative_expression DIV_TK error
2484 {yyerror ("Missing term"); RECOVER;}
2485 | multiplicative_expression REM_TK error
2486 {yyerror ("Missing term"); RECOVER;}
2489 additive_expression:
2490 multiplicative_expression
2491 | additive_expression PLUS_TK multiplicative_expression
2493 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2496 | additive_expression MINUS_TK multiplicative_expression
2498 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2501 | additive_expression PLUS_TK error
2502 {yyerror ("Missing term"); RECOVER;}
2503 | additive_expression MINUS_TK error
2504 {yyerror ("Missing term"); RECOVER;}
2509 | shift_expression LS_TK additive_expression
2511 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2514 | shift_expression SRS_TK additive_expression
2516 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2519 | shift_expression ZRS_TK additive_expression
2521 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2524 | shift_expression LS_TK error
2525 {yyerror ("Missing term"); RECOVER;}
2526 | shift_expression SRS_TK error
2527 {yyerror ("Missing term"); RECOVER;}
2528 | shift_expression ZRS_TK error
2529 {yyerror ("Missing term"); RECOVER;}
2532 relational_expression:
2534 | relational_expression LT_TK shift_expression
2536 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2539 | relational_expression GT_TK shift_expression
2541 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2544 | relational_expression LTE_TK shift_expression
2546 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2549 | relational_expression GTE_TK shift_expression
2551 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2554 | relational_expression INSTANCEOF_TK reference_type
2555 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2556 | relational_expression LT_TK error
2557 {yyerror ("Missing term"); RECOVER;}
2558 | relational_expression GT_TK error
2559 {yyerror ("Missing term"); RECOVER;}
2560 | relational_expression LTE_TK error
2561 {yyerror ("Missing term"); RECOVER;}
2562 | relational_expression GTE_TK error
2563 {yyerror ("Missing term"); RECOVER;}
2564 | relational_expression INSTANCEOF_TK error
2565 {yyerror ("Invalid reference type"); RECOVER;}
2568 equality_expression:
2569 relational_expression
2570 | equality_expression EQ_TK relational_expression
2572 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2575 | equality_expression NEQ_TK relational_expression
2577 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2580 | equality_expression EQ_TK error
2581 {yyerror ("Missing term"); RECOVER;}
2582 | equality_expression NEQ_TK error
2583 {yyerror ("Missing term"); RECOVER;}
2588 | and_expression AND_TK equality_expression
2590 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2593 | and_expression AND_TK error
2594 {yyerror ("Missing term"); RECOVER;}
2597 exclusive_or_expression:
2599 | exclusive_or_expression XOR_TK and_expression
2601 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2604 | exclusive_or_expression XOR_TK error
2605 {yyerror ("Missing term"); RECOVER;}
2608 inclusive_or_expression:
2609 exclusive_or_expression
2610 | inclusive_or_expression OR_TK exclusive_or_expression
2612 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2615 | inclusive_or_expression OR_TK error
2616 {yyerror ("Missing term"); RECOVER;}
2619 conditional_and_expression:
2620 inclusive_or_expression
2621 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2623 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2626 | conditional_and_expression BOOL_AND_TK error
2627 {yyerror ("Missing term"); RECOVER;}
2630 conditional_or_expression:
2631 conditional_and_expression
2632 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2634 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2637 | conditional_or_expression BOOL_OR_TK error
2638 {yyerror ("Missing term"); RECOVER;}
2641 conditional_expression: /* Error handling here is weak */
2642 conditional_or_expression
2643 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2645 $$ = build3 (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2646 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
2648 | conditional_or_expression REL_QM_TK REL_CL_TK error
2651 yyerror ("Missing term");
2654 | conditional_or_expression REL_QM_TK error
2655 {yyerror ("Missing term"); DRECOVER (2);}
2656 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2657 {yyerror ("Missing term"); DRECOVER (3);}
2660 assignment_expression:
2661 conditional_expression
2666 left_hand_side assignment_operator assignment_expression
2667 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2668 | left_hand_side assignment_operator error
2670 YYNOT_TWICE yyerror ("Missing term");
2681 assignment_operator:
2687 assignment_expression
2690 constant_expression:
2696 /* Helper function to retrieve an OSB count. Should be used when the
2697 `dims:' rule is being used. */
2700 pop_current_osb (struct parser_ctxt *ctxp)
2704 if (ctxp->osb_depth < 0)
2707 to_return = CURRENT_OSB (ctxp);
2715 /* This section of the code deal with save/restoring parser contexts.
2716 Add mode documentation here. FIXME */
2718 /* Helper function. Create a new parser context. With
2719 COPY_FROM_PREVIOUS set to a nonzero value, content of the previous
2720 context is copied, otherwise, the new context is zeroed. The newly
2721 created context becomes the current one. */
2724 create_new_parser_context (int copy_from_previous)
2726 struct parser_ctxt *new;
2728 new = ggc_alloc (sizeof (struct parser_ctxt));
2729 if (copy_from_previous)
2731 memcpy (new, ctxp, sizeof (struct parser_ctxt));
2732 /* This flag, indicating the context saves global values,
2733 should only be set by java_parser_context_save_global. */
2734 new->saved_data_ctx = 0;
2737 memset (new, 0, sizeof (struct parser_ctxt));
2743 /* Create a new parser context and make it the current one. */
2746 java_push_parser_context (void)
2748 create_new_parser_context (0);
2752 java_pop_parser_context (int generate)
2755 struct parser_ctxt *next;
2763 input_location = ctxp->save_location;
2764 current_class = ctxp->class_type;
2767 /* If the old and new lexers differ, then free the old one. */
2768 if (ctxp->lexer && next && ctxp->lexer != next->lexer)
2769 java_destroy_lexer (ctxp->lexer);
2771 /* Set the single import class file flag to 0 for the current list
2772 of imported things */
2773 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2774 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 0;
2776 /* If we pushed a context to parse a class intended to be generated,
2777 we keep it so we can remember the class. What we could actually
2778 do is to just update a list of class names. */
2781 ctxp->next = ctxp_for_generation;
2782 ctxp_for_generation = ctxp;
2785 /* And restore those of the previous context */
2786 if ((ctxp = next)) /* Assignment is really meant here */
2787 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2788 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 1;
2791 /* Create a parser context for the use of saving some global
2795 java_parser_context_save_global (void)
2799 java_push_parser_context ();
2800 ctxp->saved_data_ctx = 1;
2803 /* If this context already stores data, create a new one suitable
2804 for data storage. */
2805 else if (ctxp->saved_data)
2807 create_new_parser_context (1);
2808 ctxp->saved_data_ctx = 1;
2811 ctxp->save_location = input_location;
2812 ctxp->class_type = current_class;
2813 ctxp->function_decl = current_function_decl;
2814 ctxp->saved_data = 1;
2817 /* Restore some global variables from the previous context. Make the
2818 previous context the current one. */
2821 java_parser_context_restore_global (void)
2823 input_location = ctxp->save_location;
2824 current_class = ctxp->class_type;
2826 #ifdef USE_MAPPED_LOCATION
2827 SET_EXPR_LOCATION (wfl_operator, ctxp->save_location);
2829 EXPR_WFL_FILENAME_NODE (wfl_operator) = get_identifier (input_filename);
2831 current_function_decl = ctxp->function_decl;
2832 ctxp->saved_data = 0;
2833 if (ctxp->saved_data_ctx)
2834 java_pop_parser_context (0);
2837 /* Suspend vital data for the current class/function being parsed so
2838 that an other class can be parsed. Used to let local/anonymous
2839 classes be parsed. */
2842 java_parser_context_suspend (void)
2844 /* This makes debugging through java_debug_context easier */
2845 static const char *const name = "<inner buffer context>";
2847 /* Duplicate the previous context, use it to save the globals we're
2849 create_new_parser_context (1);
2850 ctxp->function_decl = current_function_decl;
2851 ctxp->class_type = current_class;
2853 /* Then create a new context which inherits all data from the
2854 previous one. This will be the new current context */
2855 create_new_parser_context (1);
2857 /* Help debugging */
2858 ctxp->next->filename = name;
2861 /* Resume vital data for the current class/function being parsed so
2862 that an other class can be parsed. Used to let local/anonymous
2863 classes be parsed. The trick is the data storing file position
2864 informations must be restored to their current value, so parsing
2865 can resume as if no context was ever saved. */
2868 java_parser_context_resume (void)
2870 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2871 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2872 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2874 /* We need to inherit the list of classes to complete/generate */
2875 restored->classd_list = old->classd_list;
2876 restored->class_list = old->class_list;
2878 /* Restore the current class and function from the saver */
2879 current_class = saver->class_type;
2880 current_function_decl = saver->function_decl;
2882 /* Retrieve the restored context */
2885 /* Re-installed the data for the parsing to carry on */
2886 memcpy (&ctxp->marker_begining, &old->marker_begining,
2887 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2890 /* Add a new anchor node to which all statement(s) initializing static
2891 and non static initialized upon declaration field(s) will be
2895 java_parser_context_push_initialized_field (void)
2899 node = build_tree_list (NULL_TREE, NULL_TREE);
2900 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2901 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2903 node = build_tree_list (NULL_TREE, NULL_TREE);
2904 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2905 CPC_INITIALIZER_LIST (ctxp) = node;
2907 node = build_tree_list (NULL_TREE, NULL_TREE);
2908 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2909 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2912 /* Pop the lists of initialized field. If this lists aren't empty,
2913 remember them so we can use it to create and populate the finit$
2914 or <clinit> functions. */
2917 java_parser_context_pop_initialized_field (void)
2920 tree class_type = TREE_TYPE (GET_CPC ());
2922 if (CPC_INITIALIZER_LIST (ctxp))
2924 stmts = CPC_INITIALIZER_STMT (ctxp);
2925 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2926 if (stmts && !java_error_count)
2927 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2930 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2932 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2933 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2934 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2935 /* Keep initialization in order to enforce 8.5 */
2936 if (stmts && !java_error_count)
2937 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2940 /* JDK 1.1 instance initializers */
2941 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2943 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2944 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2945 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2946 if (stmts && !java_error_count)
2947 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2952 reorder_static_initialized (tree list)
2954 /* We have to keep things in order. The alias initializer have to
2955 come first, then the initialized regular field, in reverse to
2956 keep them in lexical order. */
2957 tree marker, previous = NULL_TREE;
2958 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2959 if (TREE_CODE (marker) == TREE_LIST
2960 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2963 /* No static initialized, the list is fine as is */
2965 list = TREE_CHAIN (marker);
2967 /* No marker? reverse the whole list */
2969 list = nreverse (list);
2971 /* Otherwise, reverse what's after the marker and the new reordered
2972 sublist will replace the marker. */
2975 TREE_CHAIN (previous) = NULL_TREE;
2976 list = nreverse (list);
2977 list = chainon (TREE_CHAIN (marker), list);
2982 /* Helper functions to dump the parser context stack. */
2984 #define TAB_CONTEXT(C) \
2985 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2988 java_debug_context_do (int tab)
2990 struct parser_ctxt *copy = ctxp;
2994 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2996 fprintf (stderr, "filename: %s\n", copy->filename);
2998 fprintf (stderr, "package: %s\n",
3000 IDENTIFIER_POINTER (copy->package) : "<none>"));
3002 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
3004 fprintf (stderr, "saved data: %d\n", copy->saved_data);
3010 /* Dump the stacked up parser contexts. Intended to be called from a
3014 java_debug_context (void)
3016 java_debug_context_do (0);
3021 /* Flag for the error report routine to issue the error the first time
3022 it's called (overriding the default behavior which is to drop the
3023 first invocation and honor the second one, taking advantage of a
3025 static int force_error = 0;
3027 /* Reporting an constructor invocation error. */
3029 parse_ctor_invocation_error (void)
3031 if (DECL_CONSTRUCTOR_P (current_function_decl))
3032 yyerror ("Constructor invocation must be first thing in a constructor");
3034 yyerror ("Only constructors can invoke constructors");
3037 /* Reporting JDK1.1 features not implemented. */
3040 parse_jdk1_1_error (const char *msg)
3042 sorry (": %qs JDK1.1(TM) feature", msg);
3044 return build_java_empty_stmt ();
3047 static int do_warning = 0;
3050 yyerror (const char *msgid)
3052 #ifdef USE_MAPPED_LOCATION
3053 static source_location elc;
3054 expanded_location xloc = expand_location (input_location);
3055 int current_line = xloc.line;
3059 int current_line = input_line;
3061 static int prev_lineno;
3062 static const char *prev_msg;
3064 char *remainder, *code_from_source;
3066 if (!force_error && prev_lineno == current_line)
3068 #ifndef USE_MAPPED_LOCATION
3069 current_line = ctxp->lexer->token_start.line;
3072 /* Save current error location but report latter, when the context is
3074 if (ctxp->java_error_flag == 0)
3076 ctxp->java_error_flag = 1;
3077 #ifdef USE_MAPPED_LOCATION
3078 elc = input_location;
3080 elc = ctxp->lexer->token_start;
3082 /* Do something to use the previous line if we're reaching the
3083 end of the file... */
3084 #ifdef VERBOSE_SKELETON
3085 printf ("* Error detected (%s)\n", (msgid ? msgid : "(null)"));
3090 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
3091 if (!force_error && msgid == prev_msg && prev_lineno == current_line)
3094 ctxp->java_error_flag = 0;
3096 java_warning_count++;
3101 if (elc.col == 0 && msgid && msgid[1] == ';')
3102 elc = ctxp->prev_line_end;
3107 #ifdef USE_MAPPED_LOCATION
3108 prev_lineno = current_line;
3109 code_from_source = java_get_line_col (xloc.file, current_line, xloc.column);
3111 save_lineno = input_line;
3112 prev_lineno = input_line = current_line;
3113 code_from_source = java_get_line_col (input_filename, current_line,
3114 ctxp->lexer->token_start.col);
3118 obstack_grow0 (&temporary_obstack,
3119 code_from_source, strlen (code_from_source));
3120 remainder = obstack_finish (&temporary_obstack);
3122 warning ("%s.\n%s", msgid, remainder);
3124 error ("%s.\n%s", msgid, remainder);
3126 /* This allow us to cheaply avoid an extra 'Invalid expression
3127 statement' error report when errors have been already reported on
3128 the same line. This occurs when we report an error but don't have
3129 a synchronization point other than ';', which
3130 expression_statement is the only one to take care of. */
3131 #ifndef USE_MAPPED_LOCATION
3132 input_line = save_lineno;
3134 ctxp->prevent_ese = input_line;
3138 issue_warning_error_from_context (
3139 #ifdef USE_MAPPED_LOCATION
3144 const char *msgid, va_list *ap)
3146 #ifdef USE_MAPPED_LOCATION
3147 source_location saved_location = input_location;
3148 expanded_location xloc = expand_location (cl);
3150 java_lc save_lc = ctxp->lexer->token_start;
3151 const char *saved = ctxp->filename, *saved_input_filename;
3156 text.err_no = errno;
3158 text.format_spec = msgid;
3159 pp_format_text (global_dc->printer, &text);
3160 strncpy (buffer, pp_formatted_text (global_dc->printer), sizeof (buffer) - 1);
3161 buffer[sizeof (buffer) - 1] = '\0';
3162 pp_clear_output_area (global_dc->printer);
3166 #ifdef USE_MAPPED_LOCATION
3167 if (xloc.file != NULL)
3169 ctxp->filename = xloc.file;
3170 input_location = cl;
3173 ctxp->lexer->token_start.line = EXPR_WFL_LINENO (cl);
3174 ctxp->lexer->token_start.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1
3175 : EXPR_WFL_COLNO (cl) == 0xffe ? -2
3176 : EXPR_WFL_COLNO (cl));
3178 /* We have a CL, that's a good reason for using it if it contains data */
3179 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3180 ctxp->filename = EXPR_WFL_FILENAME (cl);
3181 saved_input_filename = input_filename;
3182 input_filename = ctxp->filename;
3185 java_error (buffer);
3186 #ifdef USE_MAPPED_LOCATION
3187 input_location = saved_location;
3189 ctxp->filename = saved;
3190 input_filename = saved_input_filename;
3191 ctxp->lexer->token_start = save_lc;
3196 /* Issue an error message at a current source line CL.
3197 FUTURE/FIXME: change cl to be a source_location. */
3200 parse_error_context (tree cl, const char *msgid, ...)
3203 va_start (ap, msgid);
3204 #ifdef USE_MAPPED_LOCATION
3205 issue_warning_error_from_context (EXPR_LOCATION (cl), msgid, &ap);
3207 issue_warning_error_from_context (cl, msgid, &ap);
3212 /* Issue a warning at a current source line CL.
3213 FUTURE/FIXME: change cl to be a source_location. */
3216 parse_warning_context (tree cl, const char *msgid, ...)
3219 va_start (ap, msgid);
3222 #ifdef USE_MAPPED_LOCATION
3223 issue_warning_error_from_context (EXPR_LOCATION (cl), msgid, &ap);
3225 issue_warning_error_from_context (cl, msgid, &ap);
3232 find_expr_with_wfl (tree node)
3236 enum tree_code_class code;
3239 switch (TREE_CODE (node))
3242 node = BLOCK_EXPR_BODY (node);
3246 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3249 node = TREE_OPERAND (node, 1);
3253 node = TREE_OPERAND (node, 0);
3256 case LABELED_BLOCK_EXPR:
3257 node = LABELED_BLOCK_BODY (node);
3261 code = TREE_CODE_CLASS (TREE_CODE (node));
3262 if (((code == tcc_unary) || (code == tcc_binary)
3263 || (code == tcc_expression))
3264 && EXPR_WFL_LINECOL (node))
3272 /* Issue a missing return statement error. Uses METHOD to figure the
3273 last line of the method the error occurs in. */
3276 missing_return_error (tree method)
3278 #ifdef USE_MAPPED_LOCATION
3279 SET_EXPR_LOCATION (wfl_operator, DECL_FUNCTION_LAST_LINE (method));
3281 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_FUNCTION_LAST_LINE (method), -2);
3283 parse_error_context (wfl_operator, "Missing return statement");
3286 /* Issue an unreachable statement error. From NODE, find the next
3287 statement to report appropriately. */
3289 unreachable_stmt_error (tree node)
3291 /* Browse node to find the next expression node that has a WFL. Use
3292 the location to report the error */
3293 if (TREE_CODE (node) == COMPOUND_EXPR)
3294 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3296 node = find_expr_with_wfl (node);
3300 #ifdef USE_MAPPED_LOCATION
3301 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
3303 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3305 parse_error_context (wfl_operator, "Unreachable statement");
3312 not_accessible_field_error (tree wfl, tree decl)
3315 (wfl, "Can't access %s field %<%s.%s%> from %qs",
3316 accessibility_string (get_access_flags_from_decl (decl)),
3317 GET_TYPE_NAME (DECL_CONTEXT (decl)),
3318 IDENTIFIER_POINTER (DECL_NAME (decl)),
3319 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
3324 java_report_errors (void)
3326 if (java_error_count)
3327 fprintf (stderr, "%d error%s",
3328 java_error_count, (java_error_count == 1 ? "" : "s"));
3329 if (java_warning_count)
3330 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3331 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3332 if (java_error_count || java_warning_count)
3333 putc ('\n', stderr);
3334 return java_error_count;
3338 java_accstring_lookup (int flags)
3340 static char buffer [80];
3341 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3343 /* Access modifier looked-up first for easier report on forbidden
3345 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3346 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3347 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3348 if (flags & ACC_STATIC) COPY_RETURN ("static");
3349 if (flags & ACC_FINAL) COPY_RETURN ("final");
3350 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3351 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3352 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3353 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3354 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3355 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3362 /* Returns a string denoting the accessibility of a class or a member as
3363 indicated by FLAGS. We need a separate function from
3364 java_accstring_lookup, as the latter can return spurious "static", etc.
3365 if package-private access is defined (in which case none of the
3366 relevant access control bits in FLAGS is set). */
3369 accessibility_string (int flags)
3371 if (flags & ACC_PRIVATE) return "private";
3372 if (flags & ACC_PROTECTED) return "protected";
3373 if (flags & ACC_PUBLIC) return "public";
3375 return "package-private";
3378 /* Issuing error messages upon redefinition of classes, interfaces or
3382 classitf_redefinition_error (const char *context, tree id, tree decl, tree cl)
3384 parse_error_context (cl, "%s %qs already defined in %s:%d",
3385 context, IDENTIFIER_POINTER (id),
3386 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3387 /* Here we should point out where its redefined. It's a unicode. FIXME */
3391 variable_redefinition_error (tree context, tree name, tree type, int line)
3393 const char *type_name;
3395 /* Figure a proper name for type. We might haven't resolved it */
3396 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3397 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3399 type_name = lang_printable_name (type, 0);
3401 parse_error_context (context,
3402 "Variable %qs is already defined in this method and was declared %<%s %s%> at line %d",
3403 IDENTIFIER_POINTER (name),
3404 type_name, IDENTIFIER_POINTER (name), line);
3407 /* If ANAME is terminated with `[]', it indicates an array. This
3408 function returns the number of `[]' found and if this number is
3409 greater than zero, it extracts the array type name and places it in
3410 the node pointed to by TRIMMED unless TRIMMED is null. */
3413 build_type_name_from_array_name (tree aname, tree *trimmed)
3415 const char *name = IDENTIFIER_POINTER (aname);
3416 int len = IDENTIFIER_LENGTH (aname);
3419 STRING_STRIP_BRACKETS (name, len, array_dims);
3421 if (array_dims && trimmed)
3422 *trimmed = get_identifier_with_length (name, len);
3428 build_array_from_name (tree type, tree type_wfl, tree name, tree *ret_name)
3432 /* Eventually get more dims */
3433 more_dims = build_type_name_from_array_name (name, &name);
3435 /* If we have, then craft a new type for this variable */
3440 /* If we have a pointer, use its type */
3441 if (TREE_CODE (type) == POINTER_TYPE)
3442 type = TREE_TYPE (type);
3444 /* Building the first dimension of a primitive type uses this
3446 if (JPRIMITIVE_TYPE_P (type))
3448 type = build_java_array_type (type, -1);
3451 /* Otherwise, if we have a WFL for this type, use it (the type
3452 is already an array on an unresolved type, and we just keep
3453 on adding dimensions) */
3457 more_dims += build_type_name_from_array_name (TYPE_NAME (save),
3461 /* Add all the dimensions */
3463 type = build_unresolved_array_type (type);
3465 /* The type may have been incomplete in the first place */
3467 type = obtain_incomplete_type (type);
3475 /* Build something that the type identifier resolver will identify as
3476 being an array to an unresolved type. TYPE_WFL is a WFL on a
3480 build_unresolved_array_type (tree type_or_wfl)
3485 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3486 just create a array type */
3487 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3488 return build_java_array_type (type_or_wfl, -1);
3490 obstack_grow (&temporary_obstack,
3491 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3492 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3493 obstack_grow0 (&temporary_obstack, "[]", 2);
3494 ptr = obstack_finish (&temporary_obstack);
3495 #ifdef USE_MAPPED_LOCATION
3496 wfl = build_expr_wfl (get_identifier (ptr), EXPR_LOCATION (type_or_wfl));
3498 wfl = build_expr_wfl (get_identifier (ptr),
3499 EXPR_WFL_FILENAME (type_or_wfl),
3500 EXPR_WFL_LINENO (type_or_wfl),
3501 EXPR_WFL_COLNO (type_or_wfl));
3503 /* Re-install the existing qualifications so that the type can be
3504 resolved properly. */
3505 EXPR_WFL_QUALIFICATION (wfl) = EXPR_WFL_QUALIFICATION (type_or_wfl);
3510 parser_add_interface (tree class_decl, tree interface_decl, tree wfl)
3512 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3513 parse_error_context (wfl, "Interface %qs repeated",
3514 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3517 /* Bulk of common class/interface checks. Return 1 if an error was
3518 encountered. TAG is 0 for a class, 1 for an interface. */
3521 check_class_interface_creation (int is_interface, int flags, tree raw_name,
3522 tree qualified_name, tree decl, tree cl)
3525 int sca = 0; /* Static class allowed */
3526 int icaf = 0; /* Inner class allowed flags */
3527 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3530 fprintf (stderr, " %s%s %s",
3531 (CPC_INNER_P () ? "inner" : ""),
3532 (is_interface ? "interface" : "class"),
3533 IDENTIFIER_POINTER (qualified_name));
3535 /* Scope of an interface/class type name:
3536 - Can't be imported by a single type import
3537 - Can't already exists in the package */
3538 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3539 && (node = find_name_in_single_imports (raw_name))
3543 (cl, "%s name %qs clashes with imported type %qs",
3544 (is_interface ? "Interface" : "Class"),
3545 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
3548 if (decl && CLASS_COMPLETE_P (decl))
3550 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
3551 qualified_name, decl, cl);
3555 if (check_inner_class_redefinition (raw_name, cl))
3558 /* If public, file name should match class/interface name, except
3559 when dealing with an inner class */
3560 if (!CPC_INNER_P () && (flags & ACC_PUBLIC ))
3562 const char *fname = input_filename;
3565 for (f = fname + strlen (fname);
3566 f != fname && ! IS_DIR_SEPARATOR (*f);
3569 if (IS_DIR_SEPARATOR (*f))
3571 if (strncmp (IDENTIFIER_POINTER (raw_name),
3572 f , IDENTIFIER_LENGTH (raw_name)) ||
3573 f [IDENTIFIER_LENGTH (raw_name)] != '.')
3575 (cl, "Public %s %qs must be defined in a file called %<%s.java%>",
3576 (is_interface ? "interface" : "class"),
3577 IDENTIFIER_POINTER (qualified_name),
3578 IDENTIFIER_POINTER (raw_name));
3581 /* Static classes can be declared only in top level classes. Note:
3582 once static, a inner class is a top level class. */
3583 if (flags & ACC_STATIC)
3585 /* Catch the specific error of declaring an class inner class
3586 with no toplevel enclosing class. Prevent check_modifiers from
3587 complaining a second time */
3588 if (CPC_INNER_P () && !TOPLEVEL_CLASS_DECL_P (GET_CPC()))
3590 parse_error_context (cl, "Inner class %qs can't be static. Static classes can only occur in interfaces and top-level classes",
3591 IDENTIFIER_POINTER (qualified_name));
3594 /* Else, in the context of a top-level class declaration, let
3595 `check_modifiers' do its job, otherwise, give it a go */
3597 sca = (GET_CPC_LIST () ? ACC_STATIC : 0);
3600 /* Inner classes can be declared private or protected
3601 within their enclosing classes. */
3604 /* A class which is local to a block can't be public, private,
3605 protected or static. But it is created final, so allow this
3607 if (current_function_decl)
3608 icaf = sca = uaaf = ACC_FINAL;
3611 check_modifiers_consistency (flags);
3612 icaf = ACC_PROTECTED;
3613 if (! CLASS_INTERFACE (GET_CPC ()))
3614 icaf |= ACC_PRIVATE;
3621 uaaf = INTERFACE_INNER_MODIFIERS;
3623 uaaf = INTERFACE_MODIFIERS;
3625 check_modifiers ("Illegal modifier %qs for interface declaration",
3629 check_modifiers ((current_function_decl ?
3630 "Illegal modifier %qs for local class declaration" :
3631 "Illegal modifier %qs for class declaration"),
3632 flags, uaaf|sca|icaf);
3636 /* Construct a nested class name. If the final component starts with
3637 a digit, return true. Otherwise return false. */
3639 make_nested_class_name (tree cpc_list)
3646 make_nested_class_name (TREE_CHAIN (cpc_list));
3648 /* Pick the qualified name when dealing with the first upmost
3650 name = (TREE_CHAIN (cpc_list)
3651 ? TREE_PURPOSE (cpc_list) : DECL_NAME (TREE_VALUE (cpc_list)));
3652 obstack_grow (&temporary_obstack,
3653 IDENTIFIER_POINTER (name), IDENTIFIER_LENGTH (name));
3654 obstack_1grow (&temporary_obstack, '$');
3656 return ISDIGIT (IDENTIFIER_POINTER (name)[0]);
3659 /* Can't redefine a class already defined in an earlier scope. */
3662 check_inner_class_redefinition (tree raw_name, tree cl)
3666 for (scope_list = GET_CPC_LIST (); scope_list;
3667 scope_list = GET_NEXT_ENCLOSING_CPC (scope_list))
3668 if (raw_name == GET_CPC_UN_NODE (scope_list))
3671 (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",
3672 IDENTIFIER_POINTER (raw_name));
3678 /* Tries to find a decl for CLASS_TYPE within ENCLOSING. If we fail,
3679 we remember ENCLOSING and SUPER. */
3682 resolve_inner_class (htab_t circularity_hash, tree cl, tree *enclosing,
3683 tree *super, tree class_type)
3685 tree local_enclosing = *enclosing;
3686 tree local_super = NULL_TREE;
3688 while (local_enclosing)
3690 tree intermediate, decl;
3692 *htab_find_slot (circularity_hash, local_enclosing, INSERT) =
3695 if ((decl = find_as_inner_class (local_enclosing, class_type, cl)))
3698 intermediate = local_enclosing;
3699 /* Explore enclosing contexts. */
3700 while (INNER_CLASS_DECL_P (intermediate))
3702 intermediate = DECL_CONTEXT (intermediate);
3703 if ((decl = find_as_inner_class (intermediate, class_type, cl)))
3707 /* Now go to the upper classes, bail out if necessary. We will
3708 analyze the returned SUPER and act accordingly (see
3709 do_resolve_class). */
3710 if (JPRIMITIVE_TYPE_P (TREE_TYPE (local_enclosing))
3711 || TREE_TYPE (local_enclosing) == void_type_node)
3713 parse_error_context (cl, "Qualifier must be a reference");
3714 local_enclosing = NULL_TREE;
3717 local_super = CLASSTYPE_SUPER (TREE_TYPE (local_enclosing));
3718 if (!local_super || local_super == object_type_node)
3721 if (TREE_CODE (local_super) == POINTER_TYPE)
3722 local_super = do_resolve_class (NULL, local_super, NULL, NULL);
3724 local_super = TYPE_NAME (local_super);
3726 /* We may not have checked for circular inheritance yet, so do so
3727 here to prevent an infinite loop. */
3728 if (htab_find (circularity_hash, local_super) != NULL)
3731 cl = lookup_cl (local_enclosing);
3734 (cl, "Cyclic inheritance involving %s",
3735 IDENTIFIER_POINTER (DECL_NAME (local_enclosing)));
3736 local_enclosing = NULL_TREE;
3739 local_enclosing = local_super;
3742 /* We failed. Return LOCAL_SUPER and LOCAL_ENCLOSING. */
3743 *super = local_super;
3744 *enclosing = local_enclosing;
3749 /* Within ENCLOSING, find a decl for NAME and return it. NAME can be
3753 find_as_inner_class (tree enclosing, tree name, tree cl)
3755 tree qual, to_return;
3759 name = TYPE_NAME (name);
3761 /* First search: within the scope of `enclosing', search for name */
3762 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3763 qual = EXPR_WFL_QUALIFICATION (cl);
3765 qual = build_tree_list (cl, NULL_TREE);
3767 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3769 if ((to_return = find_as_inner_class_do (qual, enclosing)))
3772 /* We're dealing with a qualified name. Try to resolve thing until
3773 we get something that is an enclosing class. */
3774 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3776 tree acc = NULL_TREE, decl = NULL_TREE, ptr;
3778 for (qual = EXPR_WFL_QUALIFICATION (cl); qual && !decl;
3779 qual = TREE_CHAIN (qual))
3781 acc = merge_qualified_name (acc,
3782 EXPR_WFL_NODE (TREE_PURPOSE (qual)));
3783 BUILD_PTR_FROM_NAME (ptr, acc);
3784 decl = do_resolve_class (NULL_TREE, ptr, NULL_TREE, cl);
3787 /* A NULL qual and a decl means that the search ended
3788 successfully?!? We have to do something then. FIXME */
3793 qual = EXPR_WFL_QUALIFICATION (cl);
3795 /* Otherwise, create a qual for the other part of the resolution. */
3797 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3799 return find_as_inner_class_do (qual, enclosing);
3802 /* We go inside the list of sub classes and try to find a way
3806 find_as_inner_class_do (tree qual, tree enclosing)
3811 for (; qual && enclosing; qual = TREE_CHAIN (qual))
3813 tree name_to_match = EXPR_WFL_NODE (TREE_PURPOSE (qual));
3814 tree next_enclosing = NULL_TREE;
3817 for (inner_list = DECL_INNER_CLASS_LIST (enclosing);
3818 inner_list; inner_list = TREE_CHAIN (inner_list))
3820 if (TREE_VALUE (inner_list) == name_to_match)
3822 next_enclosing = TREE_PURPOSE (inner_list);
3826 enclosing = next_enclosing;
3829 return (!qual && enclosing ? enclosing : NULL_TREE);
3833 link_nested_class_to_enclosing (void)
3835 if (GET_ENCLOSING_CPC ())
3837 tree enclosing = GET_ENCLOSING_CPC_CONTEXT ();
3838 DECL_INNER_CLASS_LIST (enclosing) =
3839 tree_cons (GET_CPC (), GET_CPC_UN (),
3840 DECL_INNER_CLASS_LIST (enclosing));
3845 maybe_make_nested_class_name (tree name)
3847 tree id = NULL_TREE;
3851 /* If we're in a function, we must append a number to create the
3852 nested class name. However, we don't do this if the class we
3853 are constructing is anonymous, because in that case we'll
3854 already have a number as the class name. */
3855 if (! make_nested_class_name (GET_CPC_LIST ())
3856 && current_function_decl != NULL_TREE
3857 && ! ISDIGIT (IDENTIFIER_POINTER (name)[0]))
3860 sprintf (buf, "%d", anonymous_class_counter);
3861 ++anonymous_class_counter;
3862 obstack_grow (&temporary_obstack, buf, strlen (buf));
3863 obstack_1grow (&temporary_obstack, '$');
3865 obstack_grow0 (&temporary_obstack,
3866 IDENTIFIER_POINTER (name),
3867 IDENTIFIER_LENGTH (name));
3868 id = get_identifier (obstack_finish (&temporary_obstack));
3870 QUALIFIED_P (id) = 1;
3875 /* If DECL is NULL, create and push a new DECL, record the current
3876 line CL and do other maintenance things. */
3879 maybe_create_class_interface_decl (tree decl, tree raw_name,
3880 tree qualified_name, tree cl)
3883 decl = push_class (make_class (), qualified_name);
3885 /* Take care of the file and line business */
3886 #ifdef USE_MAPPED_LOCATION
3887 DECL_SOURCE_LOCATION (decl) = EXPR_LOCATION (cl);
3889 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
3890 /* If we're emitting xrefs, store the line/col number information */
3892 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (cl);
3894 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
3896 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
3897 CLASS_PARSED_P (TREE_TYPE (decl)) = 1;
3898 #ifdef USE_MAPPED_LOCATION
3900 tree tmp = maybe_get_identifier (EXPR_FILENAME (cl));
3901 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3902 tmp && IS_A_COMMAND_LINE_FILENAME_P (tmp);
3905 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3906 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
3909 PUSH_CPC (decl, raw_name);
3910 DECL_CONTEXT (decl) = GET_ENCLOSING_CPC_CONTEXT ();
3912 /* Link the declaration to the already seen ones */
3913 TREE_CHAIN (decl) = ctxp->class_list;
3914 ctxp->class_list = decl;
3916 /* Create a new nodes in the global lists */
3917 gclass_list = tree_cons (NULL_TREE, decl, gclass_list);
3918 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
3920 /* Install a new dependency list element */
3921 create_jdep_list (ctxp);
3923 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
3924 IDENTIFIER_POINTER (qualified_name)));
3929 add_superinterfaces (tree decl, tree interface_list)
3932 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3933 takes care of ensuring that:
3934 - This is an accessible interface type,
3935 - Circularity detection.
3936 parser_add_interface is then called. If present but not defined,
3937 the check operation is delayed until the super interface gets
3939 for (node = interface_list; node; node = TREE_CHAIN (node))
3941 tree current = TREE_PURPOSE (node);
3942 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
3943 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
3945 if (!parser_check_super_interface (idecl, decl, current))
3946 parser_add_interface (decl, idecl, current);
3949 register_incomplete_type (JDEP_INTERFACE,
3950 current, decl, NULL_TREE);
3954 /* Create an interface in pass1 and return its decl. Return the
3955 interface's decl in pass 2. */
3958 create_interface (int flags, tree id, tree super)
3960 tree raw_name = EXPR_WFL_NODE (id);
3961 tree q_name = parser_qualified_classname (raw_name);
3962 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
3964 /* Certain syntax errors are making SUPER be like ID. Avoid this
3966 if (ctxp->class_err && id == super)
3969 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
3971 /* Basic checks: scope, redefinition, modifiers */
3972 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
3978 /* Suspend the current parsing context if we're parsing an inner
3982 java_parser_context_suspend ();
3983 /* Interface members are public. */
3984 if (CLASS_INTERFACE (GET_CPC ()))
3985 flags |= ACC_PUBLIC;
3988 /* Push a new context for (static) initialized upon declaration fields */
3989 java_parser_context_push_initialized_field ();
3991 /* Interface modifiers check
3992 - public/abstract allowed (already done at that point)
3993 - abstract is obsolete (comes first, it's a warning, or should be)
3994 - Can't use twice the same (checked in the modifier rule) */
3995 if ((flags & ACC_ABSTRACT) && flag_redundant)
3996 parse_warning_context
3997 (MODIFIER_WFL (ABSTRACT_TK),
3998 "Redundant use of %<abstract%> modifier. Interface %qs is implicitly abstract", IDENTIFIER_POINTER (raw_name));
4000 /* Create a new decl if DECL is NULL, otherwise fix it */
4001 decl = maybe_create_class_interface_decl (decl, raw_name, q_name, id);
4003 /* Interfaces are always abstract. */
4004 flags |= ACC_ABSTRACT;
4006 /* Inner interfaces are always static. */
4007 if (INNER_CLASS_DECL_P (decl))
4008 flags |= ACC_STATIC;
4010 /* Set super info and mark the class a complete */
4011 set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
4012 object_type_node, ctxp->interface_number);
4013 ctxp->interface_number = 0;
4014 CLASS_COMPLETE_P (decl) = 1;
4015 add_superinterfaces (decl, super);
4017 /* Eventually sets the @deprecated tag flag */
4018 CHECK_DEPRECATED (decl);
4023 /* Patch anonymous class CLASS, by either extending or implementing
4027 patch_anonymous_class (tree type_decl, tree class_decl, tree wfl)
4029 tree class = TREE_TYPE (class_decl);
4030 tree type = TREE_TYPE (type_decl);
4031 tree binfo = TYPE_BINFO (class);
4033 /* If it's an interface, implement it */
4034 if (CLASS_INTERFACE (type_decl))
4036 if (parser_check_super_interface (type_decl, class_decl, wfl))
4039 if (!VEC_space (tree, BINFO_BASE_BINFOS (binfo), 1))
4041 /* Extend the binfo - by reallocating and copying it. */
4046 new_binfo = make_tree_binfo ((BINFO_N_BASE_BINFOS (binfo) + 1) * 2);
4047 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
4048 BINFO_BASE_APPEND (new_binfo, base_binfo);
4049 CLASS_HAS_SUPER_FLAG (new_binfo) = CLASS_HAS_SUPER_FLAG (binfo);
4050 BINFO_VTABLE (new_binfo) = BINFO_VTABLE (binfo);
4051 TYPE_BINFO (class) = new_binfo;
4054 /* And add the interface */
4055 parser_add_interface (class_decl, type_decl, wfl);
4057 /* Otherwise, it's a type we want to extend */
4060 if (parser_check_super (type_decl, class_decl, wfl))
4062 BINFO_TYPE (BINFO_BASE_BINFO (binfo, 0)) = type;
4066 /* Create an anonymous class which extends/implements TYPE_NAME, and return
4070 create_anonymous_class (tree type_name)
4073 tree super = NULL_TREE, itf = NULL_TREE;
4074 tree id, type_decl, class;
4076 /* The unqualified name of the anonymous class. It's just a number. */
4077 sprintf (buffer, "%d", anonymous_class_counter++);
4078 id = build_wfl_node (get_identifier (buffer));
4079 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL (type_name);
4081 /* We know about the type to extend/implement. We go ahead */
4082 if ((type_decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (type_name))))
4084 /* Create a class which either implements on extends the designated
4085 class. The class bears an inaccessible name. */
4086 if (CLASS_INTERFACE (type_decl))
4088 /* It's OK to modify it here. It's been already used and
4089 shouldn't be reused */
4090 ctxp->interface_number = 1;
4091 /* Interfaces should presented as a list of WFLs */
4092 itf = build_tree_list (type_name, NULL_TREE);
4098 class = create_class (ACC_FINAL, id, super, itf);
4100 /* We didn't know anything about the stuff. We register a dependence. */
4102 register_incomplete_type (JDEP_ANONYMOUS, type_name, class, NULL_TREE);
4104 ANONYMOUS_CLASS_P (TREE_TYPE (class)) = 1;
4108 /* Create a class in pass1 and return its decl. Return class
4109 interface's decl in pass 2. */
4112 create_class (int flags, tree id, tree super, tree interfaces)
4114 tree raw_name = EXPR_WFL_NODE (id);
4115 tree class_id, decl;
4116 tree super_decl_type;
4118 /* Certain syntax errors are making SUPER be like ID. Avoid this
4120 if (ctxp->class_err && id == super)
4123 class_id = parser_qualified_classname (raw_name);
4124 decl = IDENTIFIER_CLASS_VALUE (class_id);
4125 EXPR_WFL_NODE (id) = class_id;
4127 /* Basic check: scope, redefinition, modifiers */
4128 if (check_class_interface_creation (0, flags, raw_name, class_id, decl, id))
4134 /* Suspend the current parsing context if we're parsing an inner
4135 class or an anonymous class. */
4138 java_parser_context_suspend ();
4139 /* Interface members are public. */
4140 if (CLASS_INTERFACE (GET_CPC ()))
4141 flags |= ACC_PUBLIC;
4144 /* Push a new context for (static) initialized upon declaration fields */
4145 java_parser_context_push_initialized_field ();
4147 /* Class modifier check:
4148 - Allowed modifier (already done at that point)
4149 - abstract AND final forbidden
4150 - Public classes defined in the correct file */
4151 if ((flags & ACC_ABSTRACT) && (flags & ACC_FINAL))
4153 (id, "Class %qs can't be declared both abstract and final",
4154 IDENTIFIER_POINTER (raw_name));
4156 /* Create a new decl if DECL is NULL, otherwise fix it */
4157 decl = maybe_create_class_interface_decl (decl, raw_name, class_id, id);
4159 /* If SUPER exists, use it, otherwise use Object */
4162 /* java.lang.Object can't extend anything. */
4163 if (TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_id)) == object_type_node)
4165 parse_error_context (id, "%<java.lang.Object%> can't extend anything");
4170 register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
4172 else if (TREE_TYPE (decl) != object_type_node)
4173 super_decl_type = object_type_node;
4174 /* We're defining java.lang.Object */
4176 super_decl_type = NULL_TREE;
4178 /* A class nested in an interface is implicitly static. */
4179 if (INNER_CLASS_DECL_P (decl)
4180 && CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (DECL_CONTEXT (decl)))))
4182 flags |= ACC_STATIC;
4185 /* Set super info and mark the class as complete. */
4186 set_super_info (flags, TREE_TYPE (decl), super_decl_type,
4187 ctxp->interface_number);
4188 ctxp->interface_number = 0;
4189 CLASS_COMPLETE_P (decl) = 1;
4190 add_superinterfaces (decl, interfaces);
4192 /* TYPE_VFIELD' is a compiler-generated field used to point to
4193 virtual function tables. In gcj, every class has a common base
4194 virtual function table in java.lang.object. */
4195 TYPE_VFIELD (TREE_TYPE (decl)) = TYPE_VFIELD (object_type_node);
4197 /* Add the private this$<n> field, Replicate final locals still in
4198 scope as private final fields mangled like val$<local_name>.
4199 This does not occur for top level (static) inner classes. */
4200 if (PURE_INNER_CLASS_DECL_P (decl))
4201 add_inner_class_fields (decl, current_function_decl);
4203 /* If doing xref, store the location at which the inherited class
4204 (if any) was seen. */
4205 if (flag_emit_xref && super)
4206 DECL_INHERITED_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (super);
4208 /* Eventually sets the @deprecated tag flag */
4209 CHECK_DEPRECATED (decl);
4211 /* Reset the anonymous class counter when declaring non inner classes */
4212 if (!INNER_CLASS_DECL_P (decl))
4213 anonymous_class_counter = 1;
4218 /* End a class declaration: register the statements used to create
4219 finit$ and <clinit>, pop the current class and resume the prior
4220 parser context if necessary. */
4223 end_class_declaration (int resume)
4225 /* If an error occurred, context weren't pushed and won't need to be
4226 popped by a resume. */
4227 int no_error_occurred = ctxp->next && GET_CPC () != error_mark_node;
4229 if (GET_CPC () != error_mark_node)
4230 dump_java_tree (TDI_class, GET_CPC ());
4232 java_parser_context_pop_initialized_field ();
4234 if (resume && no_error_occurred)
4235 java_parser_context_resume ();
4237 /* We're ending a class declaration, this is a good time to reset
4238 the interface cout. Note that might have been already done in
4239 create_interface, but if at that time an inner class was being
4240 dealt with, the interface count was reset in a context created
4241 for the sake of handling inner classes declaration. */
4242 ctxp->interface_number = 0;
4246 add_inner_class_fields (tree class_decl, tree fct_decl)
4248 tree block, marker, f;
4250 f = add_field (TREE_TYPE (class_decl),
4251 build_current_thisn (TREE_TYPE (class_decl)),
4252 build_pointer_type (TREE_TYPE (DECL_CONTEXT (class_decl))),
4254 FIELD_THISN (f) = 1;
4259 for (block = GET_CURRENT_BLOCK (fct_decl);
4260 block && TREE_CODE (block) == BLOCK; block = BLOCK_SUPERCONTEXT (block))
4263 for (decl = BLOCK_EXPR_DECLS (block); decl; decl = TREE_CHAIN (decl))
4266 tree wfl, init, list;
4268 /* Avoid non final arguments. */
4269 if (!LOCAL_FINAL_P (decl))
4272 MANGLE_OUTER_LOCAL_VARIABLE_NAME (name, DECL_NAME (decl));
4273 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID (pname, DECL_NAME (decl));
4274 wfl = build_wfl_node (name);
4275 init = build_wfl_node (pname);
4276 /* Build an initialization for the field: it will be
4277 initialized by a parameter added to finit$, bearing a
4278 mangled name of the field itself (param$<n>.) The
4279 parameter is provided to finit$ by the constructor
4280 invoking it (hence the constructor will also feature a
4281 hidden parameter, set to the value of the outer context
4282 local at the time the inner class is created.)
4284 Note: we take into account all possible locals that can
4285 be accessed by the inner class. It's actually not trivial
4286 to minimize these aliases down to the ones really
4287 used. One way to do that would be to expand all regular
4288 methods first, then finit$ to get a picture of what's
4289 used. It works with the exception that we would have to
4290 go back on all constructor invoked in regular methods to
4291 have their invocation reworked (to include the right amount
4292 of alias initializer parameters.)
4294 The only real way around, I think, is a first pass to
4295 identify locals really used in the inner class. We leave
4296 the flag FIELD_LOCAL_ALIAS_USED around for that future
4299 On the other hand, it only affect local inner classes,
4300 whose constructors (and finit$ call) will be featuring
4301 unnecessary arguments. It's easy for a developer to keep
4302 this number of parameter down by using the `final'
4303 keyword only when necessary. For the time being, we can
4304 issue a warning on unnecessary finals. FIXME */
4305 init = build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (wfl),
4308 /* Register the field. The TREE_LIST holding the part
4309 initialized/initializer will be marked ARG_FINAL_P so
4310 that the created field can be marked
4311 FIELD_LOCAL_ALIAS. */
4312 list = build_tree_list (wfl, init);
4313 ARG_FINAL_P (list) = 1;
4314 register_fields (ACC_PRIVATE | ACC_FINAL, TREE_TYPE (decl), list);
4318 if (!CPC_INITIALIZER_STMT (ctxp))
4321 /* If we ever registered an alias field, insert and marker to
4322 remember where the list ends. The second part of the list (the one
4323 featuring initialized fields) so it can be later reversed to
4324 enforce 8.5. The marker will be removed during that operation. */
4325 marker = build_tree_list (NULL_TREE, NULL_TREE);
4326 TREE_CHAIN (marker) = CPC_INITIALIZER_STMT (ctxp);
4327 SET_CPC_INITIALIZER_STMT (ctxp, marker);
4330 /* Can't use lookup_field () since we don't want to load the class and
4331 can't set the CLASS_LOADED_P flag */
4334 find_field (tree class, tree name)
4337 for (decl = TYPE_FIELDS (class); decl; decl = TREE_CHAIN (decl))
4339 if (DECL_NAME (decl) == name)
4345 /* Wrap around lookup_field that doesn't potentially upset the value
4349 lookup_field_wrapper (tree class, tree name)
4352 tree decl = NULL_TREE;
4353 java_parser_context_save_global ();
4355 /* Last chance: if we're within the context of an inner class, we
4356 might be trying to access a local variable defined in an outer
4357 context. We try to look for it now. */
4358 if (INNER_CLASS_TYPE_P (class) && TREE_CODE (name) == IDENTIFIER_NODE)
4361 MANGLE_OUTER_LOCAL_VARIABLE_NAME (new_name, name);
4362 decl = lookup_field (&type, new_name);
4363 if (decl && decl != error_mark_node)
4364 FIELD_LOCAL_ALIAS_USED (decl) = 1;
4366 if (!decl || decl == error_mark_node)
4369 decl = lookup_field (&type, name);
4372 /* If the field still hasn't been found, try the next enclosing context. */
4373 if (!decl && INNER_CLASS_TYPE_P (class))
4375 tree outer_type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class)));
4376 decl = lookup_field_wrapper (outer_type, name);
4379 java_parser_context_restore_global ();
4380 return decl == error_mark_node ? NULL : decl;
4383 /* Find duplicate field within the same class declarations and report
4384 the error. Returns 1 if a duplicated field was found, 0
4388 duplicate_declaration_error_p (tree new_field_name, tree new_type, tree cl)
4390 /* This might be modified to work with method decl as well */
4391 tree decl = find_field (TREE_TYPE (GET_CPC ()), new_field_name);
4394 char *t1 = xstrdup (purify_type_name
4395 ((TREE_CODE (new_type) == POINTER_TYPE
4396 && TREE_TYPE (new_type) == NULL_TREE) ?
4397 IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
4398 lang_printable_name (new_type, 1)));
4399 /* The type may not have been completed by the time we report
4401 char *t2 = xstrdup (purify_type_name
4402 ((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
4403 && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
4404 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
4405 lang_printable_name (TREE_TYPE (decl), 1)));
4407 (cl, "Duplicate variable declaration: %<%s %s%> was %<%s %s%> (%s:%d)",
4408 t1, IDENTIFIER_POINTER (new_field_name),
4409 t2, IDENTIFIER_POINTER (DECL_NAME (decl)),
4410 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
4418 /* Field registration routine. If TYPE doesn't exist, field
4419 declarations are linked to the undefined TYPE dependency list, to
4420 be later resolved in java_complete_class () */
4423 register_fields (int flags, tree type, tree variable_list)
4425 tree current, saved_type;
4426 tree class_type = NULL_TREE;
4427 location_t saved_location = input_location;
4429 tree wfl = NULL_TREE;
4432 class_type = TREE_TYPE (GET_CPC ());
4434 if (!class_type || class_type == error_mark_node)
4437 /* If we're adding fields to interfaces, those fields are public,
4439 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
4441 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK),
4442 flags, ACC_PUBLIC, "interface field(s)");
4443 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (STATIC_TK),
4444 flags, ACC_STATIC, "interface field(s)");
4445 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (FINAL_TK),
4446 flags, ACC_FINAL, "interface field(s)");
4447 check_modifiers ("Illegal interface member modifier %qs", flags,
4448 INTERFACE_FIELD_MODIFIERS);
4449 flags |= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
4452 /* Obtain a suitable type for resolution, if necessary */
4453 SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
4455 /* If TYPE is fully resolved and we don't have a reference, make one */
4456 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4458 for (current = variable_list, saved_type = type; current;
4459 current = TREE_CHAIN (current), type = saved_type)
4463 tree cl = TREE_PURPOSE (current);
4464 tree init = TREE_VALUE (current);
4465 tree current_name = EXPR_WFL_NODE (cl);
4467 /* Can't declare non-final static fields in inner classes */
4468 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (class_type)
4469 && !(flags & ACC_FINAL))
4471 (cl, "Field %qs can't be static in inner class %qs unless it is final",
4472 IDENTIFIER_POINTER (EXPR_WFL_NODE (cl)),
4473 lang_printable_name (class_type, 0));
4475 /* Process NAME, as it may specify extra dimension(s) for it */
4476 type = build_array_from_name (type, wfl, current_name, ¤t_name);
4478 /* Type adjustment. We may have just readjusted TYPE because
4479 the variable specified more dimensions. Make sure we have
4480 a reference if we can and don't have one already. Also
4481 change the name if we have an init. */
4482 if (type != saved_type)
4484 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4486 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
4489 real_type = GET_REAL_TYPE (type);
4490 /* Check for redeclarations */
4491 if (duplicate_declaration_error_p (current_name, real_type, cl))
4494 /* Set input_line to the line the field was found and create a
4495 declaration for it. Eventually sets the @deprecated tag flag. */
4496 #ifdef USE_MAPPED_LOCATION
4497 input_location = EXPR_LOCATION (cl);
4500 input_line = EXPR_WFL_LINECOL (cl);
4502 input_line = EXPR_WFL_LINENO (cl);
4504 field_decl = add_field (class_type, current_name, real_type, flags);
4505 CHECK_DEPRECATED_NO_RESET (field_decl);
4507 /* If the field denotes a final instance variable, then we
4508 allocate a LANG_DECL_SPECIFIC part to keep track of its
4509 initialization. We also mark whether the field was
4510 initialized upon its declaration. We don't do that if the
4511 created field is an alias to a final local. */
4512 if (!ARG_FINAL_P (current) && (flags & ACC_FINAL))
4514 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (field_decl);
4515 DECL_FIELD_FINAL_WFL (field_decl) = cl;
4518 /* If the couple initializer/initialized is marked ARG_FINAL_P,
4519 we mark the created field FIELD_LOCAL_ALIAS, so that we can
4520 hide parameters to this inner class finit$ and
4521 constructors. It also means that the field isn't final per
4523 if (ARG_FINAL_P (current))
4525 FIELD_LOCAL_ALIAS (field_decl) = 1;
4526 FIELD_FINAL (field_decl) = 0;
4529 /* Check if we must chain. */
4531 register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
4533 /* If we have an initialization value tied to the field */
4536 /* The field is declared static */
4537 if (flags & ACC_STATIC)
4539 /* We include the field and its initialization part into
4540 a list used to generate <clinit>. After <clinit> is
4541 walked, field initializations will be processed and
4542 fields initialized with known constants will be taken
4543 out of <clinit> and have their DECL_INITIAL set
4545 TREE_CHAIN (init) = CPC_STATIC_INITIALIZER_STMT (ctxp);
4546 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, init);
4547 if (TREE_OPERAND (init, 1)
4548 && TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
4549 TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
4551 /* A non-static field declared with an immediate initialization is
4552 to be initialized in <init>, if any. This field is remembered
4553 to be processed at the time of the generation of <init>. */
4556 TREE_CHAIN (init) = CPC_INITIALIZER_STMT (ctxp);
4557 SET_CPC_INITIALIZER_STMT (ctxp, init);
4559 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
4560 DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
4565 input_location = saved_location;
4568 /* Generate finit$, using the list of initialized fields to populate
4569 its body. finit$'s parameter(s) list is adjusted to include the
4570 one(s) used to initialized the field(s) caching outer context
4574 generate_finit (tree class_type)
4577 tree list = TYPE_FINIT_STMT_LIST (class_type);
4578 tree mdecl, current, parms;
4580 parms = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
4581 class_type, NULL_TREE,
4583 CRAFTED_PARAM_LIST_FIXUP (parms);
4584 mdecl = create_artificial_method (class_type, ACC_PRIVATE, void_type_node,
4585 finit_identifier_node, parms);
4586 fix_method_argument_names (parms, mdecl);
4587 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4589 DECL_FUNCTION_NAP (mdecl) = count;
4590 start_artificial_method_body (mdecl);
4592 for (current = list; current; current = TREE_CHAIN (current))
4593 java_method_add_stmt (mdecl,
4594 build_debugable_stmt (EXPR_WFL_LINECOL (current),
4596 end_artificial_method_body (mdecl);
4600 /* Generate a function to run the instance initialization code. The
4601 private method is called `instinit$'. Unless we're dealing with an
4602 anonymous class, we determine whether all ctors of CLASS_TYPE
4603 declare a checked exception in their `throws' clause in order to
4604 see whether it's necessary to encapsulate the instance initializer
4605 statements in a try/catch/rethrow sequence. */
4608 generate_instinit (tree class_type)
4611 tree compound = NULL_TREE;
4612 tree parms = tree_cons (this_identifier_node,
4613 build_pointer_type (class_type), end_params_node);
4614 tree mdecl = create_artificial_method (class_type, ACC_PRIVATE,
4616 instinit_identifier_node, parms);
4618 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4621 /* Gather all the statements in a compound */
4622 for (current = TYPE_II_STMT_LIST (class_type);
4623 current; current = TREE_CHAIN (current))
4624 compound = add_stmt_to_compound (compound, NULL_TREE, current);
4626 /* We need to encapsulate COMPOUND by a try/catch statement to
4627 rethrow exceptions that might occur in the instance initializer.
4628 We do that only if all ctors of CLASS_TYPE are set to catch a
4629 checked exception. This doesn't apply to anonymous classes (since
4630 they don't have declared ctors.) */
4631 if (!ANONYMOUS_CLASS_P (class_type) &&
4632 ctors_unchecked_throws_clause_p (class_type))
4634 compound = encapsulate_with_try_catch (0, exception_type_node, compound,
4635 build1 (THROW_EXPR, NULL_TREE,
4636 build_wfl_node (wpv_id)));
4637 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (NULL_TREE,
4638 exception_type_node);
4641 start_artificial_method_body (mdecl);
4642 java_method_add_stmt (mdecl, compound);
4643 end_artificial_method_body (mdecl);
4650 build_instinit_invocation (tree class_type)
4652 tree to_return = NULL_TREE;
4654 if (TYPE_II_STMT_LIST (class_type))
4656 tree parm = build_tree_list (NULL_TREE,
4657 build_wfl_node (this_identifier_node));
4659 build_method_invocation (build_wfl_node (instinit_identifier_node),
4665 /* Shared across method_declarator and method_header to remember the
4666 patch stage that was reached during the declaration of the method.
4667 A method DECL is built differently is there is no patch
4668 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
4669 pending on the currently defined method. */
4671 static int patch_stage;
4673 /* Check the method declaration and add the method to its current
4674 class. If the argument list is known to contain incomplete types,
4675 the method is partially added and the registration will be resume
4676 once the method arguments resolved. If TYPE is NULL, we're dealing
4677 with a constructor. */
4680 method_header (int flags, tree type, tree mdecl, tree throws)
4682 tree type_wfl = NULL_TREE;
4683 tree meth_name = NULL_TREE;
4684 tree current, orig_arg, this_class = NULL;
4686 location_t saved_location;
4687 int constructor_ok = 0, must_chain;
4690 if (mdecl == error_mark_node)
4691 return error_mark_node;
4692 meth = TREE_VALUE (mdecl);
4693 id = TREE_PURPOSE (mdecl);
4695 check_modifiers_consistency (flags);
4698 this_class = TREE_TYPE (GET_CPC ());
4700 if (!this_class || this_class == error_mark_node)
4703 /* There are some forbidden modifiers for an abstract method and its
4704 class must be abstract as well. */
4705 if (type && (flags & ACC_ABSTRACT))
4707 ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
4708 ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
4709 ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
4710 ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
4711 ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED, id, "Synchronized");
4712 ABSTRACT_CHECK (flags, ACC_STRICT, id, "Strictfp");
4713 if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
4714 && !CLASS_INTERFACE (TYPE_NAME (this_class)))
4717 "Class %qs must be declared abstract to define abstract method %qs",
4718 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())),
4719 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4722 /* A native method can't be strictfp. */
4723 if ((flags & ACC_NATIVE) && (flags & ACC_STRICT))
4724 parse_error_context (id, "native method %qs can't be strictfp",
4725 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4726 /* No such thing as a transient or volatile method. */
4727 if ((flags & ACC_TRANSIENT))
4728 parse_error_context (id, "method %qs can't be transient",
4729 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4730 if ((flags & ACC_VOLATILE))
4731 parse_error_context (id, "method %qs can't be volatile",
4732 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4734 /* Things to be checked when declaring a constructor */
4737 int ec = java_error_count;
4738 /* 8.6: Constructor declarations: we might be trying to define a
4739 method without specifying a return type. */
4740 if (EXPR_WFL_NODE (id) != GET_CPC_UN ())
4742 (id, "Invalid method declaration, return type required");
4743 /* 8.6.3: Constructor modifiers */
4746 JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
4747 JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
4748 JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
4749 JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
4750 JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
4751 JCONSTRUCTOR_CHECK (flags, ACC_STRICT, id, "strictfp");
4753 /* If we found error here, we don't consider it's OK to tread
4754 the method definition as a constructor, for the rest of this
4756 if (ec == java_error_count)
4760 /* Method declared within the scope of an interface are implicitly
4761 abstract and public. Conflicts with other erroneously provided
4762 modifiers are checked right after. */
4764 if (CLASS_INTERFACE (TYPE_NAME (this_class)))
4766 /* If FLAGS isn't set because of a modifier, turn the
4767 corresponding modifier WFL to NULL so we issue a warning on
4768 the obsolete use of the modifier */
4769 if (!(flags & ACC_PUBLIC))
4770 MODIFIER_WFL (PUBLIC_TK) = NULL;
4771 if (!(flags & ACC_ABSTRACT))
4772 MODIFIER_WFL (ABSTRACT_TK) = NULL;
4773 flags |= ACC_PUBLIC;
4774 flags |= ACC_ABSTRACT;
4777 /* Inner class can't declare static methods */
4778 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (this_class))
4781 (id, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
4782 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)),
4783 lang_printable_name (this_class, 0));
4786 /* Modifiers context reset moved up, so abstract method declaration
4787 modifiers can be later checked. */
4789 /* Set constructor returned type to void and method name to <init>,
4790 unless we found an error identifier the constructor (in which
4791 case we retain the original name) */
4794 type = void_type_node;
4796 meth_name = init_identifier_node;
4799 meth_name = EXPR_WFL_NODE (id);
4801 /* Do the returned type resolution and registration if necessary */
4802 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
4805 type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
4806 EXPR_WFL_NODE (id) = meth_name;
4807 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4811 patch_stage = JDEP_METHOD_RETURN;
4812 register_incomplete_type (patch_stage, type_wfl, id, type);
4813 TREE_TYPE (meth) = GET_REAL_TYPE (type);
4816 TREE_TYPE (meth) = type;
4818 saved_location = input_location;
4819 /* When defining an abstract or interface method, the curly
4820 bracket at level 1 doesn't exist because there is no function
4822 #ifdef USE_MAPPED_LOCATION
4823 input_location = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 :
4824 EXPR_LOCATION (id));
4826 input_line = (ctxp->first_ccb_indent1 ? (int) ctxp->first_ccb_indent1 :
4827 EXPR_WFL_LINENO (id));
4830 /* Remember the original argument list */
4831 orig_arg = TYPE_ARG_TYPES (meth);
4833 if (patch_stage) /* includes ret type and/or all args */
4836 meth = add_method_1 (this_class, flags, meth_name, meth);
4837 /* Patch for the return type */
4838 if (patch_stage == JDEP_METHOD_RETURN)
4840 jdep = CLASSD_LAST (ctxp->classd_list);
4841 JDEP_GET_PATCH (jdep) = &TREE_TYPE (TREE_TYPE (meth));
4843 /* This is the stop JDEP. METH allows the function's signature
4845 register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
4848 meth = add_method (this_class, flags, meth_name,
4849 build_java_signature (meth));
4851 /* Remember final parameters */
4852 MARK_FINAL_PARMS (meth, orig_arg);
4854 /* Fix the method argument list so we have the argument name
4856 fix_method_argument_names (orig_arg, meth);
4858 /* Register the parameter number and re-install the current line
4860 DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
4861 input_location = saved_location;
4863 /* Register exception specified by the `throws' keyword for
4864 resolution and set the method decl appropriate field to the list.
4865 Note: the grammar ensures that what we get here are class
4869 throws = nreverse (throws);
4870 for (current = throws; current; current = TREE_CHAIN (current))
4872 register_incomplete_type (JDEP_EXCEPTION, TREE_VALUE (current),
4873 NULL_TREE, NULL_TREE);
4874 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
4875 &TREE_VALUE (current);
4877 DECL_FUNCTION_THROWS (meth) = throws;
4880 if (TREE_TYPE (GET_CPC ()) != object_type_node)
4881 DECL_FUNCTION_WFL (meth) = id;
4883 /* Set the flag if we correctly processed a constructor */
4886 DECL_CONSTRUCTOR_P (meth) = 1;
4887 /* Compute and store the number of artificial parameters declared
4888 for this constructor */
4889 for (count = 0, current = TYPE_FIELDS (this_class); current;
4890 current = TREE_CHAIN (current))
4891 if (FIELD_LOCAL_ALIAS (current))
4893 DECL_FUNCTION_NAP (meth) = count;
4896 /* Eventually set the @deprecated tag flag */
4897 CHECK_DEPRECATED (meth);
4899 /* If doing xref, store column and line number information instead
4900 of the line number only. */
4903 #ifdef USE_MAPPED_LOCATION
4904 DECL_SOURCE_LOCATION (meth) = EXPR_LOCATION (id);
4906 DECL_SOURCE_LINE (meth) = EXPR_WFL_LINECOL (id);
4914 fix_method_argument_names (tree orig_arg, tree meth)
4916 tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
4917 if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
4919 TREE_PURPOSE (arg) = this_identifier_node;
4920 arg = TREE_CHAIN (arg);
4922 while (orig_arg != end_params_node)
4924 TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
4925 orig_arg = TREE_CHAIN (orig_arg);
4926 arg = TREE_CHAIN (arg);
4930 /* Complete the method declaration with METHOD_BODY. */
4933 finish_method_declaration (tree method_body)
4937 if (!current_function_decl)
4940 flags = get_access_flags_from_decl (current_function_decl);
4942 /* 8.4.5 Method Body */
4943 if ((flags & ACC_ABSTRACT || flags & ACC_NATIVE) && method_body)
4945 tree name = DECL_NAME (current_function_decl);
4946 parse_error_context (DECL_FUNCTION_WFL (current_function_decl),
4947 "%s method %qs can't have a body defined",
4948 (METHOD_NATIVE (current_function_decl) ?
4949 "Native" : "Abstract"),
4950 IDENTIFIER_POINTER (name));
4951 method_body = NULL_TREE;
4953 else if (!(flags & ACC_ABSTRACT) && !(flags & ACC_NATIVE) && !method_body)
4955 tree name = DECL_NAME (current_function_decl);
4957 (DECL_FUNCTION_WFL (current_function_decl),
4958 "Non native and non abstract method %qs must have a body defined",
4959 IDENTIFIER_POINTER (name));
4960 method_body = NULL_TREE;
4963 if (flag_emit_class_files && method_body
4964 && TREE_CODE (method_body) == NOP_EXPR
4965 && TREE_TYPE (current_function_decl)
4966 && TREE_TYPE (TREE_TYPE (current_function_decl)) == void_type_node)
4967 method_body = build1 (RETURN_EXPR, void_type_node, NULL);
4969 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
4970 maybe_absorb_scoping_blocks ();
4971 /* Exit function's body */
4973 /* Merge last line of the function with first line, directly in the
4974 function decl. It will be used to emit correct debug info. */
4975 if (!flag_emit_xref)
4976 DECL_FUNCTION_LAST_LINE (current_function_decl) = ctxp->last_ccb_indent1;
4978 /* Since function's argument's list are shared, reset the
4979 ARG_FINAL_P parameter that might have been set on some of this
4980 function parameters. */
4981 UNMARK_FINAL_PARMS (current_function_decl);
4983 /* So we don't have an irrelevant function declaration context for
4984 the next static block we'll see. */
4985 current_function_decl = NULL_TREE;
4988 /* Build a an error message for constructor circularity errors. */
4991 constructor_circularity_msg (tree from, tree to)
4993 static char string [4096];
4994 char *t = xstrdup (lang_printable_name (from, 2));
4995 sprintf (string, "'%s' invokes '%s'", t, lang_printable_name (to, 2));
5000 /* Verify a circular call to METH. Return 1 if an error is found, 0
5003 static GTY(()) tree vcc_list;
5005 verify_constructor_circularity (tree meth, tree current)
5009 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
5011 if (TREE_VALUE (c) == meth)
5017 vcc_list = nreverse (vcc_list);
5018 for (liste = vcc_list; liste; liste = TREE_CHAIN (liste))
5021 (TREE_PURPOSE (TREE_PURPOSE (liste)), "%s",
5022 constructor_circularity_msg
5023 (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste))));
5027 t = xstrdup (lang_printable_name (meth, 2));
5028 parse_error_context (TREE_PURPOSE (c),
5029 "%s: recursive invocation of constructor %qs",
5030 constructor_circularity_msg (current, meth), t);
5032 vcc_list = NULL_TREE;
5036 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
5038 vcc_list = tree_cons (c, current, vcc_list);
5039 if (verify_constructor_circularity (meth, TREE_VALUE (c)))
5041 vcc_list = TREE_CHAIN (vcc_list);
5046 /* Check modifiers that can be declared but exclusively */
5049 check_modifiers_consistency (int flags)
5052 tree cl = NULL_TREE;
5054 THIS_MODIFIER_ONLY (flags, ACC_PUBLIC, PUBLIC_TK, acc_count, cl);
5055 THIS_MODIFIER_ONLY (flags, ACC_PRIVATE, PRIVATE_TK, acc_count, cl);
5056 THIS_MODIFIER_ONLY (flags, ACC_PROTECTED, PROTECTED_TK, acc_count, cl);
5059 (cl, "Inconsistent member declaration. At most one of %<public%>, %<private%>, or %<protected%> may be specified");
5063 THIS_MODIFIER_ONLY (flags, ACC_FINAL, FINAL_TK, acc_count, cl);
5064 THIS_MODIFIER_ONLY (flags, ACC_VOLATILE, VOLATILE_TK, acc_count, cl);
5066 parse_error_context (cl,
5067 "Inconsistent member declaration. At most one of %<final%> or %<volatile%> may be specified");
5070 /* Check the methode header METH for abstract specifics features */
5073 check_abstract_method_header (tree meth)
5075 int flags = get_access_flags_from_decl (meth);
5077 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (ABSTRACT_TK), flags,
5078 ACC_ABSTRACT, "abstract method",
5079 IDENTIFIER_POINTER (DECL_NAME (meth)));
5080 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (PUBLIC_TK), flags,
5081 ACC_PUBLIC, "abstract method",
5082 IDENTIFIER_POINTER (DECL_NAME (meth)));
5084 check_modifiers ("Illegal modifier %qs for interface method",
5085 flags, INTERFACE_METHOD_MODIFIERS);
5088 /* Create a FUNCTION_TYPE node and start augmenting it with the
5089 declared function arguments. Arguments type that can't be resolved
5090 are left as they are, but the returned node is marked as containing
5091 incomplete types. */
5094 method_declarator (tree id, tree list)
5096 tree arg_types = NULL_TREE, current, node;
5097 tree meth = make_node (FUNCTION_TYPE);
5100 patch_stage = JDEP_NO_PATCH;
5102 if (GET_CPC () == error_mark_node)
5103 return error_mark_node;
5105 /* If we're dealing with an inner class constructor, we hide the
5106 this$<n> decl in the name field of its parameter declaration. We
5107 also might have to hide the outer context local alias
5108 initializers. Not done when the class is a toplevel class. */
5109 if (PURE_INNER_CLASS_DECL_P (GET_CPC ())
5110 && EXPR_WFL_NODE (id) == GET_CPC_UN ())
5112 tree aliases_list, type, thisn;
5113 /* First the aliases, linked to the regular parameters */
5115 build_alias_initializer_parameter_list (AIPL_FUNCTION_DECLARATION,
5116 TREE_TYPE (GET_CPC ()),
5118 list = chainon (nreverse (aliases_list), list);
5121 type = TREE_TYPE (DECL_CONTEXT (GET_CPC ()));
5122 thisn = build_current_thisn (TREE_TYPE (GET_CPC ()));
5123 list = tree_cons (build_wfl_node (thisn), build_pointer_type (type),
5127 for (current = list; current; current = TREE_CHAIN (current))
5130 tree wfl_name = TREE_PURPOSE (current);
5131 tree type = TREE_VALUE (current);
5132 tree name = EXPR_WFL_NODE (wfl_name);
5133 tree already, arg_node;
5134 tree type_wfl = NULL_TREE;
5137 /* Obtain a suitable type for resolution, if necessary */
5138 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
5140 /* Process NAME, as it may specify extra dimension(s) for it */
5141 type = build_array_from_name (type, type_wfl, name, &name);
5142 EXPR_WFL_NODE (wfl_name) = name;
5144 real_type = GET_REAL_TYPE (type);
5145 if (TREE_CODE (real_type) == RECORD_TYPE)
5147 real_type = promote_type (real_type);
5148 if (TREE_CODE (type) == TREE_LIST)
5149 TREE_PURPOSE (type) = real_type;
5152 /* Check redefinition */
5153 for (already = arg_types; already; already = TREE_CHAIN (already))
5154 if (TREE_PURPOSE (already) == name)
5157 (wfl_name, "Variable %qs is used more than once in the argument list of method %qs",
5158 IDENTIFIER_POINTER (name),
5159 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
5163 /* If we've an incomplete argument type, we know there is a location
5164 to patch when the type get resolved, later. */
5168 patch_stage = JDEP_METHOD;
5169 type = register_incomplete_type (patch_stage,
5170 type_wfl, wfl_name, type);
5171 jdep = CLASSD_LAST (ctxp->classd_list);
5172 JDEP_MISC (jdep) = id;
5175 /* The argument node: a name and a (possibly) incomplete type. */
5176 arg_node = build_tree_list (name, real_type);
5177 /* Remember arguments declared final. */
5178 ARG_FINAL_P (arg_node) = ARG_FINAL_P (current);
5181 JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
5182 TREE_CHAIN (arg_node) = arg_types;
5183 arg_types = arg_node;
5185 TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
5186 node = build_tree_list (id, meth);
5191 unresolved_type_p (tree wfl, tree *returned)
5193 if (TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION)
5197 tree decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (wfl));
5198 if (decl && current_class && (decl == TYPE_NAME (current_class)))
5199 *returned = TREE_TYPE (decl);
5200 else if (GET_CPC_UN () == EXPR_WFL_NODE (wfl))
5201 *returned = TREE_TYPE (GET_CPC ());
5203 *returned = NULL_TREE;
5212 /* From NAME, build a qualified identifier node using the
5213 qualification from the current package definition. */
5216 parser_qualified_classname (tree name)
5218 tree nested_class_name;
5220 if ((nested_class_name = maybe_make_nested_class_name (name)))
5221 return nested_class_name;
5224 return merge_qualified_name (ctxp->package, name);
5229 /* Called once the type a interface extends is resolved. Returns 0 if
5230 everything is OK. */
5233 parser_check_super_interface (tree super_decl, tree this_decl, tree this_wfl)
5235 tree super_type = TREE_TYPE (super_decl);
5237 /* Has to be an interface */
5238 if (!CLASS_INTERFACE (super_decl))
5241 (this_wfl, "%s %qs can't implement/extend %s %qs",
5242 (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (this_decl))) ?
5243 "Interface" : "Class"),
5244 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5245 (TYPE_ARRAY_P (super_type) ? "array" : "class"),
5246 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5250 /* Check top-level interface access. Inner classes are subject to member
5251 access rules (6.6.1). */
5252 if (! INNER_CLASS_P (super_type)
5253 && check_pkg_class_access (DECL_NAME (super_decl),
5254 NULL_TREE, true, this_decl))
5257 SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
5258 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5259 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
5263 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
5264 0 if everything is OK. */
5267 parser_check_super (tree super_decl, tree this_decl, tree wfl)
5269 tree super_type = TREE_TYPE (super_decl);
5271 /* SUPER should be a CLASS (neither an array nor an interface) */
5272 if (TYPE_ARRAY_P (super_type) || CLASS_INTERFACE (TYPE_NAME (super_type)))
5275 (wfl, "Class %qs can't subclass %s %qs",
5276 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5277 (CLASS_INTERFACE (TYPE_NAME (super_type)) ? "interface" : "array"),
5278 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5282 if (CLASS_FINAL (TYPE_NAME (super_type)))
5284 parse_error_context (wfl, "Can't subclass final classes: %s",
5285 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5289 /* Check top-level class scope. Inner classes are subject to member access
5291 if (! INNER_CLASS_P (super_type)
5292 && (check_pkg_class_access (DECL_NAME (super_decl), wfl, true, NULL_TREE)))
5295 SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
5296 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5297 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
5301 /* Create a new dependency list and link it (in a LIFO manner) to the
5302 CTXP list of type dependency list. */
5305 create_jdep_list (struct parser_ctxt *ctxp)
5307 jdeplist *new = xmalloc (sizeof (jdeplist));
5308 new->first = new->last = NULL;
5309 new->next = ctxp->classd_list;
5310 ctxp->classd_list = new;
5314 reverse_jdep_list (struct parser_ctxt *ctxp)
5316 jdeplist *prev = NULL, *current, *next;
5317 for (current = ctxp->classd_list; current; current = next)
5319 next = current->next;
5320 current->next = prev;
5326 /* Create a fake pointer based on the ID stored in
5327 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
5328 registered again. */
5331 obtain_incomplete_type (tree type_name)
5333 tree ptr = NULL_TREE, name;
5335 if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
5336 name = EXPR_WFL_NODE (type_name);
5337 else if (INCOMPLETE_TYPE_P (type_name))
5338 name = TYPE_NAME (type_name);
5342 /* Workaround from build_pointer_type for incomplete types. */
5343 BUILD_PTR_FROM_NAME (ptr, name);
5344 TYPE_MODE (ptr) = ptr_mode;
5350 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
5351 non NULL instead of computing a new fake type based on WFL. The new
5352 dependency is inserted in the current type dependency list, in FIFO
5356 register_incomplete_type (int kind, tree wfl, tree decl, tree ptr)
5358 jdep *new = xmalloc (sizeof (jdep));
5360 if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
5361 ptr = obtain_incomplete_type (wfl);
5363 JDEP_KIND (new) = kind;
5364 JDEP_DECL (new) = decl;
5365 JDEP_TO_RESOLVE (new) = ptr;
5366 JDEP_WFL (new) = wfl;
5367 JDEP_CHAIN (new) = NULL;
5368 JDEP_MISC (new) = NULL_TREE;
5369 /* For some dependencies, set the enclosing class of the current
5370 class to be the enclosing context */
5371 if ((kind == JDEP_INTERFACE || kind == JDEP_ANONYMOUS || kind == JDEP_SUPER)
5372 && GET_ENCLOSING_CPC ())
5373 JDEP_ENCLOSING (new) = TREE_VALUE (GET_ENCLOSING_CPC ());
5375 JDEP_ENCLOSING (new) = GET_CPC ();
5376 JDEP_GET_PATCH (new) = (tree *)NULL;
5378 JDEP_INSERT (ctxp->classd_list, new);
5383 /* This checks for circular references with innerclasses. We start
5384 from SOURCE and should never reach TARGET. Extended/implemented
5385 types in SOURCE have their enclosing context checked not to reach
5386 TARGET. When the last enclosing context of SOURCE is reached, its
5387 extended/implemented types are also checked not to reach TARGET.
5388 In case of error, WFL of the offending type is returned; NULL_TREE
5392 check_inner_circular_reference (tree source, tree target)
5398 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (source), i, base_binfo); i++)
5402 /* We can end up with a NULL_TREE or an incomplete type here if
5403 we encountered previous type resolution errors. It's safe to
5404 simply ignore these cases. */
5405 su = BINFO_TYPE (base_binfo);
5406 if (INCOMPLETE_TYPE_P (su))
5409 if (inherits_from_p (su, target))
5410 return lookup_cl (TYPE_NAME (su));
5412 for (ctx = DECL_CONTEXT (TYPE_NAME (su)); ctx; ctx = DECL_CONTEXT (ctx))
5414 /* An enclosing context shouldn't be TARGET */
5415 if (ctx == TYPE_NAME (target))
5416 return lookup_cl (TYPE_NAME (su));
5418 /* When we reach the enclosing last context, start a check
5419 on it, with the same target */
5420 if (! DECL_CONTEXT (ctx) &&
5421 (cl = check_inner_circular_reference (TREE_TYPE (ctx), target)))
5428 /* Explore TYPE's `extends' clause member(s) and return the WFL of the
5429 offending type if a circularity is detected. NULL_TREE is returned
5430 otherwise. TYPE can be an interface or a class. */
5433 check_circular_reference (tree type)
5438 if (!BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
5441 if (! CLASS_INTERFACE (TYPE_NAME (type)))
5443 if (inherits_from_p (CLASSTYPE_SUPER (type), type))
5444 return lookup_cl (TYPE_NAME (type));
5448 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (type), i, base_binfo); i++)
5450 if (BINFO_TYPE (base_binfo) != object_type_node
5451 && interface_of_p (type, BINFO_TYPE (base_binfo)))
5452 return lookup_cl (TYPE_NAME (BINFO_TYPE (base_binfo)));
5458 java_check_circular_reference (void)
5461 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5463 tree type = TREE_TYPE (current);
5466 cl = check_circular_reference (type);
5468 cl = check_inner_circular_reference (type, type);
5470 parse_error_context (cl, "Cyclic class inheritance%s",
5471 (cyclic_inheritance_report ?
5472 cyclic_inheritance_report : ""));
5476 /* Augment the parameter list PARM with parameters crafted to
5477 initialize outer context locals aliases. Through ARTIFICIAL, a
5478 count is kept of the number of crafted parameters. MODE governs
5479 what eventually gets created: something suitable for a function
5480 creation or a function invocation, either the constructor or
5484 build_alias_initializer_parameter_list (int mode, tree class_type, tree parm,
5488 tree additional_parms = NULL_TREE;
5490 for (field = TYPE_FIELDS (class_type); field; field = TREE_CHAIN (field))
5491 if (FIELD_LOCAL_ALIAS (field))
5493 const char *buffer = IDENTIFIER_POINTER (DECL_NAME (field));
5494 tree purpose = NULL_TREE, value = NULL_TREE, name = NULL_TREE;
5499 case AIPL_FUNCTION_DECLARATION:
5500 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (mangled_id,
5502 purpose = build_wfl_node (mangled_id);
5503 if (TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
5504 value = build_wfl_node (TYPE_NAME (TREE_TYPE (field)));
5506 value = TREE_TYPE (field);
5509 case AIPL_FUNCTION_CREATION:
5510 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (purpose,
5512 value = TREE_TYPE (field);
5515 case AIPL_FUNCTION_FINIT_INVOCATION:
5516 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (mangled_id,
5518 /* Now, this is wrong. purpose should always be the NAME
5519 of something and value its matching value (decl, type,
5520 etc...) FIXME -- but there is a lot to fix. */
5522 /* When invoked for this kind of operation, we already
5523 know whether a field is used or not. */
5524 purpose = TREE_TYPE (field);
5525 value = build_wfl_node (mangled_id);
5528 case AIPL_FUNCTION_CTOR_INVOCATION:
5529 /* There are two case: the constructor invocation happens
5530 outside the local inner, in which case, locales from the outer
5531 context are directly used.
5533 Otherwise, we fold to using the alias directly. */
5534 if (class_type == current_class)
5538 name = get_identifier (&buffer[4]);
5539 value = IDENTIFIER_LOCAL_VALUE (name);
5543 additional_parms = tree_cons (purpose, value, additional_parms);
5547 if (additional_parms)
5549 if (ANONYMOUS_CLASS_P (class_type)
5550 && mode == AIPL_FUNCTION_CTOR_INVOCATION)
5551 additional_parms = nreverse (additional_parms);
5552 parm = chainon (additional_parms, parm);
5558 /* Craft a constructor for CLASS_DECL -- what we should do when none
5559 where found. ARGS is non NULL when a special signature must be
5560 enforced. This is the case for anonymous classes. */
5563 craft_constructor (tree class_decl, tree args)
5565 tree class_type = TREE_TYPE (class_decl);
5566 tree parm = NULL_TREE;
5567 /* Inherit access flags for the constructor from its enclosing class. */
5568 int valid_ctor_flags = ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE;
5569 int flags = (get_access_flags_from_decl (class_decl) & valid_ctor_flags);
5570 int i = 0, artificial = 0;
5571 tree decl, ctor_name;
5574 ctor_name = init_identifier_node;
5576 /* If we're dealing with an inner class constructor, we hide the
5577 this$<n> decl in the name field of its parameter declaration. */
5578 if (PURE_INNER_CLASS_TYPE_P (class_type))
5580 tree type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_type)));
5581 parm = tree_cons (build_current_thisn (class_type),
5582 build_pointer_type (type), parm);
5584 /* Some more arguments to be hidden here. The values of the local
5585 variables of the outer context that the inner class needs to see. */
5586 parm = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
5591 /* Then if there are any args to be enforced, enforce them now */
5592 for (; args && args != end_params_node; args = TREE_CHAIN (args))
5594 /* If we see a `void *', we need to change it to Object. */
5595 if (TREE_VALUE (args) == TREE_TYPE (null_pointer_node))
5596 TREE_VALUE (args) = object_ptr_type_node;
5598 sprintf (buffer, "parm%d", i++);
5599 parm = tree_cons (get_identifier (buffer), TREE_VALUE (args), parm);
5602 CRAFTED_PARAM_LIST_FIXUP (parm);
5603 decl = create_artificial_method (class_type, flags, void_type_node,
5605 fix_method_argument_names (parm, decl);
5606 /* Now, mark the artificial parameters. */
5607 DECL_FUNCTION_NAP (decl) = artificial;
5608 DECL_FUNCTION_SYNTHETIC_CTOR (decl) = DECL_CONSTRUCTOR_P (decl) = 1;
5609 DECL_INLINE (decl) = 1;
5614 /* Fix the constructors. This will be called right after circular
5615 references have been checked. It is necessary to fix constructors
5616 early even if no code generation will take place for that class:
5617 some generated constructor might be required by the class whose
5618 compilation triggered this one to be simply loaded. */
5621 java_fix_constructors (void)
5625 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5627 tree class_type = TREE_TYPE (current);
5631 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
5634 output_class = current_class = class_type;
5635 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
5637 if (DECL_CONSTRUCTOR_P (decl))
5639 fix_constructors (decl);
5644 /* Anonymous class constructor can't be generated that early. */
5645 if (!saw_ctor && !ANONYMOUS_CLASS_P (class_type))
5646 craft_constructor (current, NULL_TREE);
5650 /* safe_layout_class just makes sure that we can load a class without
5651 disrupting the current_class, input_file, input_line, etc, information
5652 about the class processed currently. */
5655 safe_layout_class (tree class)
5657 tree save_current_class = current_class;
5658 location_t save_location = input_location;
5660 layout_class (class);
5662 current_class = save_current_class;
5663 input_location = save_location;
5667 jdep_resolve_class (jdep *dep)
5671 if (JDEP_RESOLVED_P (dep))
5672 decl = JDEP_RESOLVED_DECL (dep);
5675 decl = resolve_class (JDEP_ENCLOSING (dep), JDEP_TO_RESOLVE (dep),
5676 JDEP_DECL (dep), JDEP_WFL (dep));
5677 JDEP_RESOLVED (dep, decl);
5678 /* If there is no WFL, that's ok. We generate this warning
5680 if (decl && JDEP_WFL (dep) != NULL_TREE)
5681 check_deprecation (JDEP_WFL (dep), decl);
5685 complete_class_report_errors (dep);
5686 else if (INNER_CLASS_DECL_P (decl))
5688 tree inner = TREE_TYPE (decl);
5689 if (! CLASS_LOADED_P (inner))
5691 safe_layout_class (inner);
5692 if (TYPE_SIZE (inner) == error_mark_node)
5693 TYPE_SIZE (inner) = NULL_TREE;
5695 check_inner_class_access (decl, JDEP_ENCLOSING (dep), JDEP_WFL (dep));
5700 /* Complete unsatisfied class declaration and their dependencies */
5703 java_complete_class (void)
5710 /* Process imports */
5713 /* Reverse things so we have the right order */
5714 ctxp->class_list = nreverse (ctxp->class_list);
5715 ctxp->classd_list = reverse_jdep_list (ctxp);
5717 for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
5719 cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
5723 /* We keep the compilation unit imports in the class so that
5724 they can be used later to resolve type dependencies that
5725 aren't necessary to solve now. */
5726 TYPE_IMPORT_LIST (TREE_TYPE (cclass)) = ctxp->import_list;
5727 TYPE_IMPORT_DEMAND_LIST (TREE_TYPE (cclass)) = ctxp->import_demand_list;
5729 for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
5732 if (!(decl = jdep_resolve_class (dep)))
5735 /* Now it's time to patch */
5736 switch (JDEP_KIND (dep))
5739 /* Simply patch super */
5740 if (parser_check_super (decl, JDEP_DECL (dep), JDEP_WFL (dep)))
5742 BINFO_TYPE (BINFO_BASE_BINFO
5743 (TYPE_BINFO (TREE_TYPE (JDEP_DECL (dep))), 0))
5749 /* We do part of the job done in add_field */
5750 tree field_decl = JDEP_DECL (dep);
5751 tree field_type = TREE_TYPE (decl);
5752 if (TREE_CODE (field_type) == RECORD_TYPE)
5753 field_type = promote_type (field_type);
5754 TREE_TYPE (field_decl) = field_type;
5755 DECL_ALIGN (field_decl) = 0;
5756 DECL_USER_ALIGN (field_decl) = 0;
5757 layout_decl (field_decl, 0);
5758 SOURCE_FRONTEND_DEBUG
5759 (("Completed field/var decl '%s' with '%s'",
5760 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
5761 IDENTIFIER_POINTER (DECL_NAME (decl))));
5764 case JDEP_METHOD: /* We start patching a method */
5765 case JDEP_METHOD_RETURN:
5771 type = TREE_TYPE(decl);
5772 if (TREE_CODE (type) == RECORD_TYPE)
5773 type = promote_type (type);
5774 JDEP_APPLY_PATCH (dep, type);
5775 SOURCE_FRONTEND_DEBUG
5776 (((JDEP_KIND (dep) == JDEP_METHOD_RETURN ?
5777 "Completing fct '%s' with ret type '%s'":
5778 "Completing arg '%s' with type '%s'"),
5779 IDENTIFIER_POINTER (EXPR_WFL_NODE
5780 (JDEP_DECL_WFL (dep))),
5781 IDENTIFIER_POINTER (DECL_NAME (decl))));
5785 dep = JDEP_CHAIN (dep);
5786 if (JDEP_KIND (dep) == JDEP_METHOD_END)
5789 decl = jdep_resolve_class (dep);
5793 tree mdecl = JDEP_DECL (dep), signature;
5794 /* Recompute and reset the signature, check first that
5795 all types are now defined. If they're not,
5796 don't build the signature. */
5797 if (check_method_types_complete (mdecl))
5799 signature = build_java_signature (TREE_TYPE (mdecl));
5800 set_java_signature (TREE_TYPE (mdecl), signature);
5807 case JDEP_INTERFACE:
5808 if (parser_check_super_interface (decl, JDEP_DECL (dep),
5811 parser_add_interface (JDEP_DECL (dep), decl, JDEP_WFL (dep));
5816 type = TREE_TYPE(decl);
5817 if (TREE_CODE (type) == RECORD_TYPE)
5818 type = promote_type (type);
5819 JDEP_APPLY_PATCH (dep, type);
5823 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5824 SOURCE_FRONTEND_DEBUG
5825 (("Completing a random type dependency on a '%s' node",
5826 tree_code_name [TREE_CODE (JDEP_DECL (dep))]));
5829 case JDEP_EXCEPTION:
5830 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5831 SOURCE_FRONTEND_DEBUG
5832 (("Completing '%s' 'throws' argument node",
5833 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
5836 case JDEP_ANONYMOUS:
5837 patch_anonymous_class (decl, JDEP_DECL (dep), JDEP_WFL (dep));
5848 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
5852 resolve_class (tree enclosing, tree class_type, tree decl, tree cl)
5854 tree tname = TYPE_NAME (class_type);
5855 tree resolved_type = TREE_TYPE (class_type);
5857 tree resolved_type_decl;
5859 if (resolved_type != NULL_TREE)
5861 tree resolved_type_decl = TYPE_NAME (resolved_type);
5862 if (resolved_type_decl == NULL_TREE
5863 || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
5865 resolved_type_decl = build_decl (TYPE_DECL,
5866 TYPE_NAME (class_type),
5869 return resolved_type_decl;
5872 /* 1- Check to see if we have an array. If true, find what we really
5874 if ((array_dims = build_type_name_from_array_name (tname,
5875 &TYPE_NAME (class_type))))
5876 WFL_STRIP_BRACKET (cl, cl);
5878 /* 2- Resolve the bare type */
5879 if (!(resolved_type_decl = do_resolve_class (enclosing, class_type,
5882 resolved_type = TREE_TYPE (resolved_type_decl);
5884 /* 3- If we have an array, reconstruct the array down to its nesting */
5887 for (; array_dims; array_dims--)
5888 resolved_type = build_java_array_type (resolved_type, -1);
5889 resolved_type_decl = TYPE_NAME (resolved_type);
5891 TREE_TYPE (class_type) = resolved_type;
5892 return resolved_type_decl;
5895 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
5896 are used to report error messages; CL must either be NULL_TREE or a
5897 WFL wrapping a class. Do not try to replace TYPE_NAME (class_type)
5898 by a variable, since it is changed by find_in_imports{_on_demand}
5899 and (but it doesn't really matter) qualify_and_find. */
5902 do_resolve_class (tree enclosing, tree class_type, tree decl, tree cl)
5904 tree new_class_decl = NULL_TREE, super = NULL_TREE;
5905 tree saved_enclosing_type = enclosing ? TREE_TYPE (enclosing) : NULL_TREE;
5907 htab_t circularity_hash;
5909 if (QUALIFIED_P (TYPE_NAME (class_type)))
5911 /* If the type name is of the form `Q . Id', then Q is either a
5912 package name or a class name. First we try to find Q as a
5913 class and then treat Id as a member type. If we can't find Q
5914 as a class then we fall through. */
5915 tree q, left, left_type, right;
5916 if (split_qualified_name (&left, &right, TYPE_NAME (class_type)) == 0)
5918 BUILD_PTR_FROM_NAME (left_type, left);
5919 q = do_resolve_class (enclosing, left_type, decl, cl);
5923 saved_enclosing_type = TREE_TYPE (q);
5924 BUILD_PTR_FROM_NAME (class_type, right);
5931 /* This hash table is used to register the classes we're going
5932 through when searching the current class as an inner class, in
5933 order to detect circular references. Remember to free it before
5934 returning the section 0- of this function. */
5935 circularity_hash = htab_create (20, htab_hash_pointer, htab_eq_pointer,
5938 /* 0- Search in the current class as an inner class.
5939 Maybe some code here should be added to load the class or
5940 something, at least if the class isn't an inner class and ended
5941 being loaded from class file. FIXME. */
5944 new_class_decl = resolve_inner_class (circularity_hash, cl, &enclosing,
5945 &super, class_type);
5949 /* If we haven't found anything because SUPER reached Object and
5950 ENCLOSING happens to be an innerclass, try the enclosing context. */
5951 if ((!super || super == object_type_node) &&
5952 enclosing && INNER_CLASS_DECL_P (enclosing))
5953 enclosing = DECL_CONTEXT (enclosing);
5955 enclosing = NULL_TREE;
5958 htab_delete (circularity_hash);
5961 return new_class_decl;
5964 /* 1- Check for the type in single imports. This will change
5965 TYPE_NAME() if something relevant is found */
5966 find_in_imports (saved_enclosing_type, class_type);
5968 /* 2- And check for the type in the current compilation unit */
5969 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5971 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)))
5972 load_class (TYPE_NAME (class_type), 0);
5973 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5976 /* 3- Search according to the current package definition */
5977 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5979 if ((new_class_decl = qualify_and_find (class_type, ctxp->package,
5980 TYPE_NAME (class_type))))
5981 return new_class_decl;
5984 /* 4- Check the import on demands. Don't allow bar.baz to be
5985 imported from foo.* */
5986 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5987 if (find_in_imports_on_demand (saved_enclosing_type, class_type))
5990 /* If found in find_in_imports_on_demand, the type has already been
5992 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5993 return new_class_decl;
5995 /* 5- Try with a name qualified with the package name we've seen so far */
5996 if (!QUALIFIED_P (TYPE_NAME (class_type)))
6000 /* If there is a current package (ctxp->package), it's the first
6001 element of package_list and we can skip it. */
6002 for (package = (ctxp->package ?
6003 TREE_CHAIN (package_list) : package_list);
6004 package; package = TREE_CHAIN (package))
6005 if ((new_class_decl = qualify_and_find (class_type,
6006 TREE_PURPOSE (package),
6007 TYPE_NAME (class_type))))
6008 return new_class_decl;
6011 /* 5- Check another compilation unit that bears the name of type */
6012 load_class (TYPE_NAME (class_type), 0);
6015 cl = lookup_cl (decl);
6017 /* If we don't have a value for CL, then we're being called recursively.
6018 We can't check package access just yet, but it will be taken care of
6022 if (check_pkg_class_access (TYPE_NAME (class_type), cl, true, NULL_TREE))
6026 /* 6- Last call for a resolution */
6027 decl_result = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
6029 /* The final lookup might have registered a.b.c into a.b$c If we
6030 failed at the first lookup, progressively change the name if
6031 applicable and use the matching DECL instead. */
6032 if (!decl_result && QUALIFIED_P (TYPE_NAME (class_type)))
6035 tree name = TYPE_NAME (class_type);
6036 char *namebuffer = alloca (IDENTIFIER_LENGTH (name) + 1);
6038 strcpy (namebuffer, IDENTIFIER_POINTER (name));
6042 /* Reach the last '.', and if applicable, replace it by a `$' and
6043 see if this exists as a type. */
6044 if ((separator = strrchr (namebuffer, '.')))
6047 name = get_identifier (namebuffer);
6048 decl_result = IDENTIFIER_CLASS_VALUE (name);
6050 } while (!decl_result && separator);
6056 qualify_and_find (tree class_type, tree package, tree name)
6058 tree new_qualified = merge_qualified_name (package, name);
6059 tree new_class_decl;
6061 if (!IDENTIFIER_CLASS_VALUE (new_qualified))
6062 load_class (new_qualified, 0);
6063 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (new_qualified)))
6065 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)))
6066 load_class (TREE_TYPE (new_class_decl), 0);
6067 TYPE_NAME (class_type) = new_qualified;
6068 return IDENTIFIER_CLASS_VALUE (new_qualified);
6073 /* Resolve NAME and lay it out (if not done and if not the current
6074 parsed class). Return a decl node. This function is meant to be
6075 called when type resolution is necessary during the walk pass. */
6078 resolve_and_layout (tree something, tree cl)
6080 tree decl, decl_type;
6082 /* Don't do that on the current class */
6083 if (something == current_class)
6084 return TYPE_NAME (current_class);
6086 /* Don't do anything for void and other primitive types */
6087 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
6090 /* Pointer types can be reall pointer types or fake pointers. When
6091 finding a real pointer, recheck for primitive types */
6092 if (TREE_CODE (something) == POINTER_TYPE)
6094 if (TREE_TYPE (something))
6096 something = TREE_TYPE (something);
6097 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
6101 something = TYPE_NAME (something);
6104 /* Don't do anything for arrays of primitive types */
6105 if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
6106 && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
6109 /* Something might be a WFL */
6110 if (TREE_CODE (something) == EXPR_WITH_FILE_LOCATION)
6111 something = EXPR_WFL_NODE (something);
6113 /* Otherwise, if something is not and IDENTIFIER_NODE, it can be a a
6114 TYPE_DECL or a real TYPE */
6115 else if (TREE_CODE (something) != IDENTIFIER_NODE)
6116 something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
6117 DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
6119 if (!(decl = resolve_no_layout (something, cl)))
6122 /* Resolve and layout if necessary */
6123 decl_type = TREE_TYPE (decl);
6124 layout_class_methods (decl_type);
6126 if (CLASS_FROM_SOURCE_P (decl_type))
6127 java_check_methods (decl);
6128 /* Layout the type if necessary */
6129 if (decl_type != current_class && !CLASS_LOADED_P (decl_type))
6130 safe_layout_class (decl_type);
6135 /* Resolve a class, returns its decl but doesn't perform any
6136 layout. The current parsing context is saved and restored */
6139 resolve_no_layout (tree name, tree cl)
6142 BUILD_PTR_FROM_NAME (ptr, name);
6143 java_parser_context_save_global ();
6144 decl = resolve_class (TYPE_NAME (current_class), ptr, NULL_TREE, cl);
6145 java_parser_context_restore_global ();
6150 /* Called when reporting errors. Skip the '[]'s in a complex array
6151 type description that failed to be resolved. purify_type_name can't
6152 use an identifier tree. */
6155 purify_type_name (const char *name)
6157 int len = strlen (name);
6160 STRING_STRIP_BRACKETS (name, len, bracket_found);
6163 char *stripped_name = xmemdup (name, len, len+1);
6164 stripped_name [len] = '\0';
6165 return stripped_name;
6170 /* The type CURRENT refers to can't be found. We print error messages. */
6173 complete_class_report_errors (jdep *dep)
6177 if (!JDEP_WFL (dep))
6180 name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
6181 switch (JDEP_KIND (dep))
6185 (JDEP_WFL (dep), "Superclass %qs of class %qs not found",
6186 purify_type_name (name),
6187 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6191 (JDEP_WFL (dep), "Type %qs not found in declaration of field %qs",
6192 purify_type_name (name),
6193 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6195 case JDEP_METHOD: /* Covers arguments */
6197 (JDEP_WFL (dep), "Type %qs not found in the declaration of the argument %qs of method %qs",
6198 purify_type_name (name),
6199 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
6200 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
6202 case JDEP_METHOD_RETURN: /* Covers return type */
6204 (JDEP_WFL (dep), "Type %qs not found in the declaration of the return type of method %qs",
6205 purify_type_name (name),
6206 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
6208 case JDEP_INTERFACE:
6210 (JDEP_WFL (dep), "Superinterface %qs of %s %qs not found",
6211 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
6212 (CLASS_OR_INTERFACE (JDEP_DECL (dep), "class", "interface")),
6213 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6217 (JDEP_WFL (dep), "Type %qs not found in the declaration of the local variable %qs",
6218 purify_type_name (IDENTIFIER_POINTER
6219 (EXPR_WFL_NODE (JDEP_WFL (dep)))),
6220 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6222 case JDEP_EXCEPTION: /* As specified by `throws' */
6224 (JDEP_WFL (dep), "Class %qs not found in %<throws%>",
6225 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
6228 /* Fix for -Wall. Just break doing nothing. The error will be
6234 /* Return a static string containing the DECL prototype string. If
6235 DECL is a constructor, use the class name instead of the form
6239 get_printable_method_name (tree decl)
6241 const char *to_return;
6242 tree name = NULL_TREE;
6244 if (DECL_CONSTRUCTOR_P (decl))
6246 name = DECL_NAME (decl);
6247 DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
6250 to_return = lang_printable_name (decl, 2);
6251 if (DECL_CONSTRUCTOR_P (decl))
6252 DECL_NAME (decl) = name;
6257 /* Track method being redefined inside the same class. As a side
6258 effect, set DECL_NAME to an IDENTIFIER (prior entering this
6259 function it's a FWL, so we can track errors more accurately.) */
6262 check_method_redefinition (tree class, tree method)
6266 /* There's no need to verify <clinit> and finit$ and instinit$ */
6267 if (DECL_CLINIT_P (method)
6268 || DECL_FINIT_P (method) || DECL_INSTINIT_P (method))
6271 sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
6272 for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
6274 if (redef == method)
6276 if (DECL_NAME (redef) == DECL_NAME (method)
6277 && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef))
6278 && !DECL_ARTIFICIAL (method))
6281 (DECL_FUNCTION_WFL (method), "Duplicate %s declaration %qs",
6282 (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
6283 get_printable_method_name (redef));
6290 /* Return 1 if check went ok, 0 otherwise. */
6292 check_abstract_method_definitions (int do_interface, tree class_decl,
6295 tree class = TREE_TYPE (class_decl);
6296 tree method, end_type;
6299 end_type = (do_interface ? object_type_node : type);
6300 for (method = TYPE_METHODS (type); method; method = TREE_CHAIN (method))
6302 tree other_super, other_method, method_sig, method_name;
6304 int end_type_reached = 0;
6306 if (!METHOD_ABSTRACT (method) || METHOD_FINAL (method))
6309 /* Now verify that somewhere in between TYPE and CLASS,
6310 abstract method METHOD gets a non abstract definition
6311 that is inherited by CLASS. */
6313 method_sig = build_java_signature (TREE_TYPE (method));
6314 method_name = DECL_NAME (method);
6315 if (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION)
6316 method_name = EXPR_WFL_NODE (method_name);
6318 other_super = class;
6320 if (other_super == end_type)
6321 end_type_reached = 1;
6324 for (other_method = TYPE_METHODS (other_super); other_method;
6325 other_method = TREE_CHAIN (other_method))
6327 tree s = build_java_signature (TREE_TYPE (other_method));
6328 tree other_name = DECL_NAME (other_method);
6330 if (TREE_CODE (other_name) == EXPR_WITH_FILE_LOCATION)
6331 other_name = EXPR_WFL_NODE (other_name);
6332 if (!DECL_CLINIT_P (other_method)
6333 && !DECL_CONSTRUCTOR_P (other_method)
6334 && method_name == other_name
6336 && !METHOD_ABSTRACT (other_method))
6342 other_super = CLASSTYPE_SUPER (other_super);
6343 } while (!end_type_reached);
6345 /* Report that abstract METHOD didn't find an implementation
6346 that CLASS can use. */
6349 char *t = xstrdup (lang_printable_name
6350 (TREE_TYPE (TREE_TYPE (method)), 0));
6351 tree ccn = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
6354 (lookup_cl (class_decl),
6355 "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",
6356 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
6357 t, lang_printable_name (method, 2),
6358 (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))) ?
6359 "interface" : "class"),
6360 IDENTIFIER_POINTER (ccn),
6361 (CLASS_INTERFACE (class_decl) ? "interface" : "class"),
6362 IDENTIFIER_POINTER (DECL_NAME (class_decl)));
6368 if (ok && do_interface)
6370 /* Check for implemented interfaces. */
6375 ok && BINFO_BASE_ITERATE (TYPE_BINFO (type), i, base_binfo);
6377 ok = check_abstract_method_definitions (1, class_decl,
6378 BINFO_TYPE (base_binfo));
6384 /* Check that CLASS_DECL somehow implements all inherited abstract
6388 java_check_abstract_method_definitions (tree class_decl)
6390 tree class = TREE_TYPE (class_decl);
6391 tree super, base_binfo;
6394 if (CLASS_ABSTRACT (class_decl))
6397 /* Check for inherited types */
6400 super = CLASSTYPE_SUPER (super);
6401 check_abstract_method_definitions (0, class_decl, super);
6402 } while (super != object_type_node);
6404 /* Check for implemented interfaces. */
6405 for (i = 1; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6406 check_abstract_method_definitions (1, class_decl, BINFO_TYPE (base_binfo));
6409 /* Check all the types method DECL uses and return 1 if all of them
6410 are now complete, 0 otherwise. This is used to check whether its
6411 safe to build a method signature or not. */
6414 check_method_types_complete (tree decl)
6416 tree type = TREE_TYPE (decl);
6419 if (!INCOMPLETE_TYPE_P (TREE_TYPE (type)))
6422 args = TYPE_ARG_TYPES (type);
6423 if (TREE_CODE (type) == METHOD_TYPE)
6424 args = TREE_CHAIN (args);
6425 for (; args != end_params_node; args = TREE_CHAIN (args))
6426 if (INCOMPLETE_TYPE_P (TREE_VALUE (args)))
6432 /* Visible interface to check methods contained in CLASS_DECL */
6435 java_check_methods (tree class_decl)
6437 if (CLASS_METHOD_CHECKED_P (TREE_TYPE (class_decl)))
6440 if (CLASS_INTERFACE (class_decl))
6441 java_check_abstract_methods (class_decl);
6443 java_check_regular_methods (class_decl);
6445 CLASS_METHOD_CHECKED_P (TREE_TYPE (class_decl)) = 1;
6448 /* Like not_accessible_p, but doesn't refer to the current class at
6451 hack_is_accessible_p (tree member, tree from_where)
6453 int flags = get_access_flags_from_decl (member);
6455 if (from_where == DECL_CONTEXT (member)
6456 || (flags & ACC_PUBLIC))
6459 if ((flags & ACC_PROTECTED))
6461 if (inherits_from_p (from_where, DECL_CONTEXT (member)))
6465 if ((flags & ACC_PRIVATE))
6468 /* Package private, or protected. */
6469 return in_same_package (TYPE_NAME (from_where),
6470 TYPE_NAME (DECL_CONTEXT (member)));
6473 /* Check all the methods of CLASS_DECL. Methods are first completed
6474 then checked according to regular method existence rules. If no
6475 constructor for CLASS_DECL were encountered, then build its
6478 java_check_regular_methods (tree class_decl)
6480 int saw_constructor = ANONYMOUS_CLASS_P (TREE_TYPE (class_decl));
6482 tree class = TREE_TYPE (class_decl);
6483 tree found = NULL_TREE;
6486 /* It is not necessary to check methods defined in java.lang.Object */
6487 if (class == object_type_node)
6490 if (!TYPE_NVIRTUALS (class))
6491 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6493 /* Should take interfaces into account. FIXME */
6494 for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
6497 tree method_wfl = DECL_FUNCTION_WFL (method);
6500 /* Check for redefinitions */
6501 if (check_method_redefinition (class, method))
6504 /* We verify things thrown by the method. They must inherit from
6505 java.lang.Throwable. */
6506 for (mthrows = DECL_FUNCTION_THROWS (method);
6507 mthrows; mthrows = TREE_CHAIN (mthrows))
6509 if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
6511 (TREE_PURPOSE (mthrows), "Class %qs in %<throws%> clause must be a subclass of class %<java.lang.Throwable%>",
6513 (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
6516 /* If we see one constructor a mark so we don't generate the
6517 default one. Also skip other verifications: constructors
6518 can't be inherited hence hidden or overridden. */
6519 if (DECL_CONSTRUCTOR_P (method))
6521 saw_constructor = 1;
6525 sig = build_java_argument_signature (TREE_TYPE (method));
6526 found = lookup_argument_method_generic (class, DECL_NAME (method), sig,
6527 SEARCH_SUPER | SEARCH_INTERFACE);
6529 /* Inner class can't declare static methods */
6530 if (METHOD_STATIC (method) && !TOPLEVEL_CLASS_DECL_P (class_decl))
6532 char *t = xstrdup (lang_printable_name (class, 0));
6534 (method_wfl, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
6535 lang_printable_name (method, 2), t);
6539 /* Nothing overrides or it's a private method. */
6542 if (METHOD_PRIVATE (found))
6548 /* If `found' is declared in an interface, make sure the
6549 modifier matches. */
6550 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
6551 && clinit_identifier_node != DECL_NAME (found)
6552 && !METHOD_PUBLIC (method))
6554 tree found_decl = TYPE_NAME (DECL_CONTEXT (found));
6555 parse_error_context (method_wfl, "Class %qs must override %qs with a public method in order to implement interface %qs",
6556 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
6557 lang_printable_name (method, 2),
6558 IDENTIFIER_POINTER (DECL_NAME (found_decl)));
6561 /* Can't override a method with the same name and different return
6563 if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
6566 (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 2));
6569 "Method %qs was defined with return type %qs in class %qs",
6570 lang_printable_name (found, 2), t,
6572 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6576 aflags = get_access_flags_from_decl (found);
6578 /* Can't override final. Can't override static. */
6579 if (METHOD_FINAL (found) || METHOD_STATIC (found))
6581 /* Static *can* override static */
6582 if (METHOD_STATIC (found) && METHOD_STATIC (method))
6586 "%s methods can't be overridden. Method %qs is %s in class %qs",
6587 (METHOD_FINAL (found) ? "Final" : "Static"),
6588 lang_printable_name (found, 2),
6589 (METHOD_FINAL (found) ? "final" : "static"),
6591 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6595 /* Static method can't override instance method. */
6596 if (METHOD_STATIC (method))
6600 "Instance methods can't be overridden by a static method. Method %qs is an instance method in class %qs",
6601 lang_printable_name (found, 2),
6603 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6607 /* - Overriding/hiding public must be public
6608 - Overriding/hiding protected must be protected or public
6609 - If the overridden or hidden method has default (package)
6610 access, then the overriding or hiding method must not be
6611 private; otherwise, a compile-time error occurs. If
6612 `found' belongs to an interface, things have been already
6614 if (!CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
6615 && ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method))
6616 || (METHOD_PROTECTED (found)
6617 && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
6618 || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
6619 && METHOD_PRIVATE (method))))
6623 "Methods can't be overridden to be more private. Method %qs is not %s in class %qs", lang_printable_name (method, 2),
6624 (METHOD_PUBLIC (method) ? "public" :
6625 (METHOD_PRIVATE (method) ? "private" : "protected")),
6626 IDENTIFIER_POINTER (DECL_NAME
6627 (TYPE_NAME (DECL_CONTEXT (found)))));
6631 /* Check this method against all the other implementations it
6632 overrides. Here we only check the class hierarchy; the rest
6633 of the checking is done later. If this method is just a
6634 Miranda method, we can skip the check. */
6635 if (! METHOD_INVISIBLE (method))
6636 check_concrete_throws_clauses (class, method, DECL_NAME (method), sig);
6639 /* The above throws clause check only looked at superclasses. Now
6640 we must also make sure that all methods declared in interfaces
6641 have compatible throws clauses. FIXME: there are more efficient
6642 ways to organize this checking; we should implement one. */
6643 check_interface_throws_clauses (class, class);
6645 if (!TYPE_NVIRTUALS (class))
6646 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6648 /* Search for inherited abstract method not yet implemented in this
6650 java_check_abstract_method_definitions (class_decl);
6652 if (!saw_constructor)
6656 /* Check to make sure that all the methods in all the interfaces
6657 implemented by CLASS_DECL are compatible with the concrete
6658 implementations available in CHECK_CLASS_DECL. */
6660 check_interface_throws_clauses (tree check_class_decl, tree class_decl)
6662 for (; class_decl != NULL_TREE; class_decl = CLASSTYPE_SUPER (class_decl))
6666 if (! CLASS_LOADED_P (class_decl))
6668 if (CLASS_FROM_SOURCE_P (class_decl))
6669 safe_layout_class (class_decl);
6671 load_class (class_decl, 1);
6674 for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (class_decl)) - 1; i > 0; --i)
6677 = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (class_decl), i));
6680 for (iface_method = TYPE_METHODS (interface);
6681 iface_method != NULL_TREE;
6682 iface_method = TREE_CHAIN (iface_method))
6686 /* First look for a concrete method implemented or
6687 inherited by this class. No need to search
6688 interfaces here, since we're already looking through
6690 sig = build_java_argument_signature (TREE_TYPE (iface_method));
6692 = lookup_argument_method_generic (check_class_decl,
6693 DECL_NAME (iface_method),
6694 sig, SEARCH_VISIBLE);
6695 /* If we don't find an implementation, that is ok. Any
6696 potential errors from that are diagnosed elsewhere.
6697 Also, multiple inheritance with conflicting throws
6698 clauses is fine in the absence of a concrete
6700 if (method != NULL_TREE && !METHOD_ABSTRACT (method)
6701 && !METHOD_INVISIBLE (iface_method))
6703 tree method_wfl = DECL_FUNCTION_WFL (method);
6704 check_throws_clauses (method, method_wfl, iface_method);
6708 /* Now check superinterfaces. */
6709 check_interface_throws_clauses (check_class_decl, interface);
6714 /* Check throws clauses of a method against the clauses of all the
6715 methods it overrides. We do this by searching up the class
6716 hierarchy, examining all matching accessible methods. */
6718 check_concrete_throws_clauses (tree class, tree self_method,
6719 tree name, tree signature)
6721 tree method = lookup_argument_method_generic (class, name, signature,
6722 SEARCH_SUPER | SEARCH_VISIBLE);
6723 while (method != NULL_TREE)
6725 if (! METHOD_INVISIBLE (method) && hack_is_accessible_p (method, class))
6726 check_throws_clauses (self_method, DECL_FUNCTION_WFL (self_method),
6729 method = lookup_argument_method_generic (DECL_CONTEXT (method),
6731 SEARCH_SUPER | SEARCH_VISIBLE);
6735 /* Generate an error if the `throws' clause of METHOD (if any) is
6736 incompatible with the `throws' clause of FOUND (if any). */
6738 check_throws_clauses (tree method, tree method_wfl, tree found)
6742 /* Can't check these things with class loaded from bytecode. FIXME */
6743 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (found)))
6746 for (mthrows = DECL_FUNCTION_THROWS (method);
6747 mthrows; mthrows = TREE_CHAIN (mthrows))
6751 /* We don't verify unchecked expressions */
6752 if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
6754 /* Checked expression must be compatible */
6755 for (fthrows = DECL_FUNCTION_THROWS (found);
6756 fthrows; fthrows = TREE_CHAIN (fthrows))
6758 if (inherits_from_p (TREE_VALUE (mthrows), TREE_VALUE (fthrows)))
6764 (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",
6765 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))),
6766 lang_printable_name (found, 2),
6768 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6773 /* Check abstract method of interface INTERFACE */
6775 java_check_abstract_methods (tree interface_decl)
6779 tree interface = TREE_TYPE (interface_decl);
6782 for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
6784 /* 2- Check for double definition inside the defining interface */
6785 if (check_method_redefinition (interface, method))
6788 /* 3- Overriding is OK as far as we preserve the return type. */
6789 found = lookup_java_interface_method2 (interface, method);
6793 t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 2));
6795 (DECL_FUNCTION_WFL (found),
6796 "Method %qs was defined with return type %qs in class %qs",
6797 lang_printable_name (found, 2), t,
6799 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6805 /* 4- Inherited methods can't differ by their returned types */
6806 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (interface), i, base_binfo); i++)
6808 tree sub_interface_method, sub_interface;
6810 sub_interface = BINFO_TYPE (base_binfo);
6811 for (sub_interface_method = TYPE_METHODS (sub_interface);
6812 sub_interface_method;
6813 sub_interface_method = TREE_CHAIN (sub_interface_method))
6815 found = lookup_java_interface_method2 (interface,
6816 sub_interface_method);
6817 if (found && (found != sub_interface_method))
6820 (lookup_cl (sub_interface_method),
6821 "Interface %qs inherits method %qs from interface %qs. This method is redefined with a different return type in interface %qs",
6822 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
6823 lang_printable_name (found, 2),
6825 (DECL_NAME (TYPE_NAME
6826 (DECL_CONTEXT (sub_interface_method)))),
6828 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6834 /* Lookup methods in interfaces using their name and partial
6835 signature. Return a matching method only if their types differ. */
6838 lookup_java_interface_method2 (tree class, tree method_decl)
6844 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6846 if ((BINFO_TYPE (base_binfo) != object_type_node)
6848 lookup_java_method2 (BINFO_TYPE (base_binfo), method_decl, 1)))
6851 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6853 to_return = lookup_java_interface_method2
6854 (BINFO_TYPE (base_binfo), method_decl);
6862 /* Lookup method using their name and partial signature. Return a
6863 matching method only if their types differ. */
6866 lookup_java_method2 (tree clas, tree method_decl, int do_interface)
6868 tree method, method_signature, method_name, method_type, name;
6870 method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
6871 name = DECL_NAME (method_decl);
6872 method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6873 EXPR_WFL_NODE (name) : name);
6874 method_type = TREE_TYPE (TREE_TYPE (method_decl));
6876 while (clas != NULL_TREE)
6878 for (method = TYPE_METHODS (clas);
6879 method != NULL_TREE; method = TREE_CHAIN (method))
6881 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
6882 tree name = DECL_NAME (method);
6883 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6884 EXPR_WFL_NODE (name) : name) == method_name
6885 && method_sig == method_signature
6886 && TREE_TYPE (TREE_TYPE (method)) != method_type)
6889 clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
6894 /* Return the line that matches DECL line number, and try its best to
6895 position the column number. Used during error reports.
6896 FUTURE/FIXME: return source_location instead of node. */
6898 static GTY(()) tree cl_v;
6900 lookup_cl (tree decl)
6902 #ifndef USE_MAPPED_LOCATION
6909 if (cl_v == NULL_TREE)
6911 cl_v = build_unknown_wfl (NULL_TREE);
6914 #ifdef USE_MAPPED_LOCATION
6915 SET_EXPR_LOCATION (cl_v, DECL_SOURCE_LOCATION (decl));
6917 EXPR_WFL_FILENAME_NODE (cl_v) = get_identifier (DECL_SOURCE_FILE (decl));
6918 EXPR_WFL_SET_LINECOL (cl_v, DECL_SOURCE_LINE (decl), -1);
6920 line = java_get_line_col (EXPR_WFL_FILENAME (cl_v),
6921 EXPR_WFL_LINENO (cl_v), EXPR_WFL_COLNO (cl_v));
6923 found = strstr ((const char *)line,
6924 (const char *)IDENTIFIER_POINTER (DECL_NAME (decl)));
6926 EXPR_WFL_SET_LINECOL (cl_v, EXPR_WFL_LINENO (cl_v), found - line);
6932 /* Look for a simple name in the single-type import list */
6935 find_name_in_single_imports (tree name)
6939 for (node = ctxp->import_list; node; node = TREE_CHAIN (node))
6940 if (TREE_VALUE (node) == name)
6941 return (EXPR_WFL_NODE (TREE_PURPOSE (node)));
6946 /* Process all single-type import. */
6949 process_imports (void)
6954 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
6956 tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import));
6957 char *original_name;
6959 original_name = xmemdup (IDENTIFIER_POINTER (to_be_found),
6960 IDENTIFIER_LENGTH (to_be_found),
6961 IDENTIFIER_LENGTH (to_be_found) + 1);
6963 /* Don't load twice something already defined. */
6964 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6971 QUALIFIED_P (to_be_found) = 1;
6972 load_class (to_be_found, 0);
6974 check_pkg_class_access (to_be_found, TREE_PURPOSE (import), true, NULL_TREE);
6976 /* We found it, we can bail out */
6977 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6979 check_deprecation (TREE_PURPOSE (import),
6980 IDENTIFIER_CLASS_VALUE (to_be_found));
6984 /* We haven't found it. Maybe we're trying to access an
6985 inner class. The only way for us to know is to try again
6986 after having dropped a qualifier. If we can't break it further,
6987 we have an error. */
6988 if (split_qualified_name (&left, NULL, to_be_found))
6993 if (!IDENTIFIER_CLASS_VALUE (to_be_found))
6995 parse_error_context (TREE_PURPOSE (import),
6996 "Class or interface %qs not found in import",
7001 free (original_name);
7008 /* Possibly find and mark a class imported by a single-type import
7012 find_in_imports (tree enclosing_type, tree class_type)
7014 tree import = (enclosing_type ? TYPE_IMPORT_LIST (enclosing_type) :
7018 if (TREE_VALUE (import) == TYPE_NAME (class_type))
7020 TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
7021 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
7024 import = TREE_CHAIN (import);
7029 note_possible_classname (const char *name, int len)
7032 if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
7034 else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
7038 node = ident_subst (name, len, "", '/', '.', "");
7039 IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
7040 QUALIFIED_P (node) = strchr (name, '/') ? 1 : 0;
7044 /* Read a import directory, gathering potential match for further type
7045 references. Indifferently reads a filesystem or a ZIP archive
7049 read_import_dir (tree wfl)
7051 tree package_id = EXPR_WFL_NODE (wfl);
7052 const char *package_name = IDENTIFIER_POINTER (package_id);
7053 int package_length = IDENTIFIER_LENGTH (package_id);
7055 JCF *saved_jcf = current_jcf;
7060 struct buffer filename[1];
7062 if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
7064 IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
7066 BUFFER_INIT (filename);
7067 buffer_grow (filename, package_length + 100);
7069 for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
7071 const char *entry_name = jcf_path_name (entry);
7072 int entry_length = strlen (entry_name);
7073 if (jcf_path_is_zipfile (entry))
7076 buffer_grow (filename, entry_length);
7077 memcpy (filename->data, entry_name, entry_length - 1);
7078 filename->data[entry_length-1] = '\0';
7079 zipf = opendir_in_zip ((const char *) filename->data, jcf_path_is_system (entry));
7081 error ("malformed .zip archive in CLASSPATH: %s", entry_name);
7084 ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
7085 BUFFER_RESET (filename);
7086 for (k = 0; k < package_length; k++)
7088 char ch = package_name[k];
7089 *filename->ptr++ = ch == '.' ? '/' : ch;
7091 *filename->ptr++ = '/';
7093 for (k = 0; k < zipf->count; k++, zipd = ZIPDIR_NEXT (zipd))
7095 const char *current_entry = ZIPDIR_FILENAME (zipd);
7096 int current_entry_len = zipd->filename_length;
7098 if (current_entry_len >= BUFFER_LENGTH (filename)
7099 && strncmp ((const char *) filename->data, current_entry,
7100 BUFFER_LENGTH (filename)) != 0)
7102 found |= note_possible_classname (current_entry,
7109 BUFFER_RESET (filename);
7110 buffer_grow (filename, entry_length + package_length + 4);
7111 strcpy ((char *) filename->data, entry_name);
7112 filename->ptr = filename->data + entry_length;
7113 for (k = 0; k < package_length; k++)
7115 char ch = package_name[k];
7116 *filename->ptr++ = ch == '.' ? '/' : ch;
7118 *filename->ptr = '\0';
7120 dirp = opendir ((const char *) filename->data);
7123 *filename->ptr++ = '/';
7128 struct dirent *direntp = readdir (dirp);
7131 d_name = direntp->d_name;
7132 len = strlen (direntp->d_name);
7133 buffer_grow (filename, len+1);
7134 strcpy ((char *) filename->ptr, d_name);
7135 found |= note_possible_classname ((const char *) filename->data + entry_length,
7136 package_length+len+1);
7143 free (filename->data);
7145 /* Here we should have a unified way of retrieving an entry, to be
7149 static int first = 1;
7152 error ("Can't find default package %qs. Check the CLASSPATH environment variable and the access to the archives", package_name);
7157 parse_error_context (wfl, "Package %qs not found in import",
7159 current_jcf = saved_jcf;
7162 current_jcf = saved_jcf;
7165 /* Possibly find a type in the import on demands specified
7166 types. Returns 1 if an error occurred, 0 otherwise. Run through the
7167 entire list, to detected potential double definitions. */
7170 find_in_imports_on_demand (tree enclosing_type, tree class_type)
7172 tree class_type_name = TYPE_NAME (class_type);
7173 tree import = (enclosing_type ? TYPE_IMPORT_DEMAND_LIST (enclosing_type) :
7174 ctxp->import_demand_list);
7175 tree cl = NULL_TREE;
7176 int seen_once = -1; /* -1 when not set, 1 if seen once, >1 otherwise. */
7177 int to_return = -1; /* -1 when not set, 0 or 1 otherwise */
7180 for (; import; import = TREE_CHAIN (import))
7182 location_t saved_location = input_location;
7184 const char *id_name;
7185 tree decl, type_name_copy;
7187 obstack_grow (&temporary_obstack,
7188 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
7189 IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
7190 obstack_1grow (&temporary_obstack, '.');
7191 obstack_grow0 (&temporary_obstack,
7192 IDENTIFIER_POINTER (class_type_name),
7193 IDENTIFIER_LENGTH (class_type_name));
7194 id_name = obstack_finish (&temporary_obstack);
7196 if (! (node = maybe_get_identifier (id_name)))
7199 /* Setup input_line so that it refers to the line of the import (in
7200 case we parse a class file and encounter errors */
7201 #ifdef USE_MAPPED_LOCATION
7202 input_location = EXPR_LOCATION (TREE_PURPOSE (import));
7204 input_line = EXPR_WFL_LINENO (TREE_PURPOSE (import));
7207 type_name_copy = TYPE_NAME (class_type);
7208 TYPE_NAME (class_type) = node;
7209 QUALIFIED_P (node) = 1;
7210 decl = IDENTIFIER_CLASS_VALUE (node);
7212 /* If there is no DECL set for the class or if the class isn't
7213 loaded and not seen in source yet, then load */
7214 if (!decl || ! CLASS_LOADED_P (TREE_TYPE (decl)))
7216 load_class (node, 0);
7217 decl = IDENTIFIER_CLASS_VALUE (node);
7219 if (decl && ! INNER_CLASS_P (TREE_TYPE (decl)))
7220 access_check = check_pkg_class_access (node, TREE_PURPOSE (import),
7223 /* 6.6.1: Inner classes are subject to member access rules. */
7226 input_location = saved_location;
7228 /* If the loaded class is not accessible or couldn't be loaded,
7229 we restore the original TYPE_NAME and process the next
7231 if (access_check || !decl)
7233 TYPE_NAME (class_type) = type_name_copy;
7237 /* If the loaded class is accessible, we keep a tab on it to
7238 detect and report multiple inclusions. */
7239 if (IS_A_CLASSFILE_NAME (node))
7243 cl = TREE_PURPOSE (import);
7246 else if (seen_once >= 0)
7248 tree location = (cl ? cl : TREE_PURPOSE (import));
7249 tree package = (cl ? EXPR_WFL_NODE (cl) :
7250 EXPR_WFL_NODE (TREE_PURPOSE (import)));
7254 "Type %qs also potentially defined in package %qs",
7255 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
7256 IDENTIFIER_POINTER (package));
7259 to_return = access_check;
7265 return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
7268 /* Add package NAME to the list of packages encountered so far. To
7269 speed up class lookup in do_resolve_class, we make sure a
7270 particular package is added only once. */
7273 register_package (tree name)
7279 pht = htab_create (50, htab_hash_pointer, htab_eq_pointer, NULL);
7281 e = htab_find_slot (pht, name, INSERT);
7284 package_list = chainon (package_list, build_tree_list (name, NULL));
7290 resolve_package (tree pkg, tree *next, tree *type_name)
7293 tree decl = NULL_TREE;
7294 *type_name = NULL_TREE;
7296 /* The trick is to determine when the package name stops and were
7297 the name of something contained in the package starts. Then we
7298 return a fully qualified name of what we want to get. */
7300 *next = EXPR_WFL_QUALIFICATION (pkg);
7302 /* Try to progressively construct a type name */
7303 if (TREE_CODE (pkg) == EXPR_WITH_FILE_LOCATION)
7304 for (current = EXPR_WFL_QUALIFICATION (pkg);
7305 current; current = TREE_CHAIN (current))
7307 /* If we don't have what we're expecting, exit now. TYPE_NAME
7308 will be null and the error caught later. */
7309 if (TREE_CODE (QUAL_WFL (current)) != EXPR_WITH_FILE_LOCATION)
7312 merge_qualified_name (*type_name, EXPR_WFL_NODE (QUAL_WFL (current)));
7313 if ((decl = resolve_no_layout (*type_name, NULL_TREE)))
7315 /* resolve_package should be used in a loop, hence we
7316 point at this one to naturally process the next one at
7317 the next iteration. */
7326 /* Check accessibility of inner classes according to member access rules.
7327 DECL is the inner class, ENCLOSING_DECL is the class from which the
7328 access is being attempted. */
7331 check_inner_class_access (tree decl, tree enclosing_decl, tree cl)
7334 tree enclosing_decl_type;
7336 /* We don't issue an error message when CL is null. CL can be null
7337 as a result of processing a JDEP crafted by source_start_java_method
7338 for the purpose of patching its parm decl. But the error would
7339 have been already trapped when fixing the method's signature.
7340 DECL can also be NULL in case of earlier errors. */
7344 enclosing_decl_type = TREE_TYPE (enclosing_decl);
7346 if (CLASS_PRIVATE (decl))
7348 /* Access is permitted only within the body of the top-level
7349 class in which DECL is declared. */
7350 tree top_level = decl;
7351 while (DECL_CONTEXT (top_level))
7352 top_level = DECL_CONTEXT (top_level);
7353 while (DECL_CONTEXT (enclosing_decl))
7354 enclosing_decl = DECL_CONTEXT (enclosing_decl);
7355 if (top_level == enclosing_decl)
7359 else if (CLASS_PROTECTED (decl))
7362 /* Access is permitted from within the same package... */
7363 if (in_same_package (decl, enclosing_decl))
7366 /* ... or from within the body of a subtype of the context in which
7367 DECL is declared. */
7368 decl_context = DECL_CONTEXT (decl);
7369 while (enclosing_decl)
7371 if (CLASS_INTERFACE (decl))
7373 if (interface_of_p (TREE_TYPE (decl_context),
7374 enclosing_decl_type))
7379 /* Eww. The order of the arguments is different!! */
7380 if (inherits_from_p (enclosing_decl_type,
7381 TREE_TYPE (decl_context)))
7384 enclosing_decl = DECL_CONTEXT (enclosing_decl);
7386 access = "protected";
7388 else if (! CLASS_PUBLIC (decl))
7390 /* Access is permitted only from within the same package as DECL. */
7391 if (in_same_package (decl, enclosing_decl))
7393 access = "non-public";
7396 /* Class is public. */
7399 parse_error_context (cl, "Nested %s %s is %s; cannot be accessed from here",
7400 (CLASS_INTERFACE (decl) ? "interface" : "class"),
7401 lang_printable_name (decl, 2), access);
7404 /* Accessibility check for top-level classes. If CLASS_NAME is in a
7405 foreign package, it must be PUBLIC. Return 0 if no access
7406 violations were found, 1 otherwise. If VERBOSE is true and an error
7407 was found, it is reported and accounted for. If CL is NULL then
7408 look it up with THIS_DECL. */
7411 check_pkg_class_access (tree class_name, tree cl, bool verbose, tree this_decl)
7415 if (!IDENTIFIER_CLASS_VALUE (class_name))
7418 if (!(type = TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_name))))
7421 if (!CLASS_PUBLIC (TYPE_NAME (type)))
7423 /* Access to a private class within the same package is
7426 split_qualified_name (&l, &r, class_name);
7427 if (!QUALIFIED_P (class_name) && !ctxp->package)
7428 /* Both in the empty package. */
7430 if (l == ctxp->package)
7431 /* Both in the same package. */
7436 (cl == NULL ? lookup_cl (this_decl): cl,
7437 "Can't access %s %qs. Only public classes and interfaces in other packages can be accessed",
7438 (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
7439 IDENTIFIER_POINTER (class_name));
7445 /* Local variable declaration. */
7448 declare_local_variables (int modifier, tree type, tree vlist)
7450 tree decl, current, saved_type;
7451 tree type_wfl = NULL_TREE;
7455 /* Push a new block if statements were seen between the last time we
7456 pushed a block and now. Keep a count of blocks to close */
7457 if (BLOCK_EXPR_BODY (GET_CURRENT_BLOCK (current_function_decl)))
7459 tree b = enter_block ();
7460 BLOCK_IS_IMPLICIT (b) = 1;
7466 for (i = 0; i < ARRAY_SIZE (ctxp->modifier_ctx); i++)
7467 if (1 << i & modifier)
7469 if (modifier == ACC_FINAL)
7474 (ctxp->modifier_ctx [i],
7475 "Only %<final%> is allowed as a local variables modifier");
7480 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
7481 hold the TYPE value if a new incomplete has to be created (as
7482 opposed to being found already existing and reused). */
7483 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
7485 /* If TYPE is fully resolved and we don't have a reference, make one */
7486 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
7488 /* Go through all the declared variables */
7489 for (current = vlist, saved_type = type; current;
7490 current = TREE_CHAIN (current), type = saved_type)
7492 tree other, real_type;
7493 tree wfl = TREE_PURPOSE (current);
7494 tree name = EXPR_WFL_NODE (wfl);
7495 tree init = TREE_VALUE (current);
7497 /* Process NAME, as it may specify extra dimension(s) for it */
7498 type = build_array_from_name (type, type_wfl, name, &name);
7500 /* Variable redefinition check */
7501 if ((other = lookup_name_in_blocks (name)))
7503 variable_redefinition_error (wfl, name, TREE_TYPE (other),
7504 DECL_SOURCE_LINE (other));
7508 /* Type adjustment. We may have just readjusted TYPE because
7509 the variable specified more dimensions. Make sure we have
7510 a reference if we can and don't have one already. */
7511 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
7513 real_type = GET_REAL_TYPE (type);
7514 /* Never layout this decl. This will be done when its scope
7516 decl = build_decl (VAR_DECL, name, real_type);
7517 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
7518 DECL_FINAL (decl) = final_p;
7519 BLOCK_CHAIN_DECL (decl);
7521 /* If doing xreferencing, replace the line number with the WFL
7523 #ifdef USE_MAPPED_LOCATION
7525 DECL_SOURCE_LOCATION (decl) = EXPR_LOCATION (wfl);
7528 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (wfl);
7531 /* Don't try to use an INIT statement when an error was found */
7532 if (init && java_error_count)
7535 /* Remember it if this is an initialized-upon-declaration final
7537 if (init && final_p)
7539 DECL_LOCAL_FINAL_IUD (decl) = 1;
7542 /* Add the initialization function to the current function's code */
7545 /* Name might have been readjusted */
7546 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = name;
7547 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
7548 java_method_add_stmt (current_function_decl,
7549 build_debugable_stmt (EXPR_WFL_LINECOL (init),
7553 /* Setup dependency the type of the decl */
7557 register_incomplete_type (JDEP_VARIABLE, type_wfl, decl, type);
7558 dep = CLASSD_LAST (ctxp->classd_list);
7559 JDEP_GET_PATCH (dep) = &TREE_TYPE (decl);
7562 SOURCE_FRONTEND_DEBUG (("Defined locals"));
7565 /* Called during parsing. Build decls from argument list. */
7568 source_start_java_method (tree fndecl)
7577 current_function_decl = fndecl;
7579 /* New scope for the function */
7581 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
7582 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
7584 tree type = TREE_VALUE (tem);
7585 tree name = TREE_PURPOSE (tem);
7587 /* If type is incomplete. Create an incomplete decl and ask for
7588 the decl to be patched later */
7589 if (INCOMPLETE_TYPE_P (type))
7592 tree real_type = GET_REAL_TYPE (type);
7593 parm_decl = build_decl (PARM_DECL, name, real_type);
7594 type = obtain_incomplete_type (type);
7595 register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
7596 jdep = CLASSD_LAST (ctxp->classd_list);
7597 JDEP_MISC (jdep) = name;
7598 JDEP_GET_PATCH (jdep) = &TREE_TYPE (parm_decl);
7601 parm_decl = build_decl (PARM_DECL, name, type);
7603 /* Remember if a local variable was declared final (via its
7604 TREE_LIST of type/name.) Set DECL_FINAL accordingly. */
7605 if (ARG_FINAL_P (tem))
7607 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (parm_decl);
7608 DECL_FINAL (parm_decl) = 1;
7611 BLOCK_CHAIN_DECL (parm_decl);
7613 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
7614 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) =
7616 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
7617 DECL_MAX_LOCALS (current_function_decl) = i;
7620 /* Called during parsing. Creates an artificial method declaration. */
7623 create_artificial_method (tree class, int flags, tree type,
7624 tree name, tree args)
7627 location_t save_location = input_location;
7629 input_location = DECL_SOURCE_LOCATION (TYPE_NAME (class));
7630 mdecl = make_node (FUNCTION_TYPE);
7631 TREE_TYPE (mdecl) = type;
7632 TYPE_ARG_TYPES (mdecl) = args;
7633 /* We used to compute the signature of MDECL here and then use
7634 add_method(), but that failed because our caller might modify
7635 the type of the returned method, which trashes the cache in
7636 get_type_from_signature(). */
7637 mdecl = add_method_1 (class, flags, name, mdecl);
7638 input_location = save_location;
7639 DECL_ARTIFICIAL (mdecl) = 1;
7643 /* Starts the body if an artificial method. */
7646 start_artificial_method_body (tree mdecl)
7648 #ifdef USE_MAPPED_LOCATION
7649 DECL_SOURCE_LOCATION (mdecl) = ctxp->file_start_location;
7650 DECL_FUNCTION_LAST_LINE (mdecl) = ctxp->file_start_location;
7652 DECL_SOURCE_LINE (mdecl) = 1;
7653 DECL_FUNCTION_LAST_LINE (mdecl) = 1;
7655 source_start_java_method (mdecl);
7660 end_artificial_method_body (tree mdecl)
7662 /* exit_block modifies DECL_FUNCTION_BODY (current_function_decl).
7663 It has to be evaluated first. (if mdecl is current_function_decl,
7664 we have an undefined behavior if no temporary variable is used.) */
7665 tree b = exit_block ();
7666 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = b;
7670 /* Dump a tree of some kind. This is a convenience wrapper for the
7671 dump_* functions in tree-dump.c. */
7673 dump_java_tree (enum tree_dump_index phase, tree t)
7678 stream = dump_begin (phase, &flags);
7682 dump_node (t, flags, stream);
7683 dump_end (phase, stream);
7687 /* Terminate a function and expand its body. */
7690 source_end_java_method (void)
7692 tree fndecl = current_function_decl;
7697 java_parser_context_save_global ();
7698 #ifdef USE_MAPPED_LOCATION
7699 input_location = ctxp->last_ccb_indent1;
7701 input_line = ctxp->last_ccb_indent1;
7704 /* Turn function bodies with only a NOP expr null, so they don't get
7705 generated at all and we won't get warnings when using the -W
7707 if (IS_EMPTY_STMT (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))))
7708 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) = NULL_TREE;
7710 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))
7711 && ! flag_emit_class_files
7712 && ! flag_emit_xref)
7713 finish_method (fndecl);
7715 current_function_decl = NULL_TREE;
7716 java_parser_context_restore_global ();
7717 current_function_decl = NULL_TREE;
7720 /* Record EXPR in the current function block. Complements compound
7721 expression second operand if necessary. */
7724 java_method_add_stmt (tree fndecl, tree expr)
7726 if (!GET_CURRENT_BLOCK (fndecl))
7728 return add_stmt_to_block (GET_CURRENT_BLOCK (fndecl), NULL_TREE, expr);
7732 add_stmt_to_block (tree b, tree type, tree stmt)
7734 tree body = BLOCK_EXPR_BODY (b), c;
7736 if (java_error_count)
7739 if ((c = add_stmt_to_compound (body, type, stmt)) == body)
7742 BLOCK_EXPR_BODY (b) = c;
7743 TREE_SIDE_EFFECTS (c) = 1;
7747 /* Lays out the methods for the classes seen so far. */
7750 java_layout_seen_class_methods (void)
7752 tree previous_list = all_class_list;
7753 tree end = NULL_TREE;
7758 for (current = previous_list;
7759 current != end; current = TREE_CHAIN (current))
7761 tree decl = TREE_VALUE (current);
7762 tree cls = TREE_TYPE (decl);
7764 input_location = DECL_SOURCE_LOCATION (decl);
7766 if (! CLASS_LOADED_P (cls))
7767 load_class (cls, 0);
7769 layout_class_methods (cls);
7772 /* Note that new classes might have been added while laying out
7773 methods, changing the value of all_class_list. */
7775 if (previous_list != all_class_list)
7777 end = previous_list;
7778 previous_list = all_class_list;
7785 static GTY(()) tree stop_reordering;
7787 java_reorder_fields (void)
7791 for (current = gclass_list; current; current = TREE_CHAIN (current))
7793 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
7795 if (current_class == stop_reordering)
7798 /* Reverse the fields, but leave the dummy field in front.
7799 Fields are already ordered for Object and Class */
7800 if (TYPE_FIELDS (current_class) && current_class != object_type_node
7801 && current_class != class_type_node)
7803 /* If the dummy field is there, reverse the right fields and
7804 just layout the type for proper fields offset */
7805 if (!DECL_NAME (TYPE_FIELDS (current_class)))
7807 tree fields = TYPE_FIELDS (current_class);
7808 TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
7809 TYPE_SIZE (current_class) = NULL_TREE;
7811 /* We don't have a dummy field, we need to layout the class,
7812 after having reversed the fields */
7815 TYPE_FIELDS (current_class) =
7816 nreverse (TYPE_FIELDS (current_class));
7817 TYPE_SIZE (current_class) = NULL_TREE;
7821 /* There are cases were gclass_list will be empty. */
7823 stop_reordering = TREE_TYPE (TREE_VALUE (gclass_list));
7826 /* Layout the methods of all classes loaded in one way or another.
7827 Check methods of source parsed classes. Then reorder the
7828 fields and layout the classes or the type of all source parsed
7832 java_layout_classes (void)
7835 int save_error_count = java_error_count;
7837 /* Layout the methods of all classes seen so far */
7838 java_layout_seen_class_methods ();
7839 java_parse_abort_on_error ();
7840 all_class_list = NULL_TREE;
7842 /* Then check the methods of all parsed classes */
7843 for (current = gclass_list; current; current = TREE_CHAIN (current))
7844 if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
7845 java_check_methods (TREE_VALUE (current));
7846 java_parse_abort_on_error ();
7848 for (current = gclass_list; current; current = TREE_CHAIN (current))
7850 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
7851 layout_class (current_class);
7853 /* Error reported by the caller */
7854 if (java_error_count)
7858 /* We might have reloaded classes durign the process of laying out
7859 classes for code generation. We must layout the methods of those
7860 late additions, as constructor checks might use them */
7861 java_layout_seen_class_methods ();
7862 java_parse_abort_on_error ();
7865 /* Expand methods in the current set of classes remembered for
7869 java_complete_expand_classes (void)
7873 do_not_fold = flag_emit_xref;
7875 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
7876 if (!INNER_CLASS_DECL_P (current))
7877 java_complete_expand_class (current);
7880 /* Expand the methods found in OUTER, starting first by OUTER's inner
7884 java_complete_expand_class (tree outer)
7888 /* We need to go after all inner classes and start expanding them,
7889 starting with most nested ones. We have to do that because nested
7890 classes might add functions to outer classes */
7892 for (inner_list = DECL_INNER_CLASS_LIST (outer);
7893 inner_list; inner_list = TREE_CHAIN (inner_list))
7894 java_complete_expand_class (TREE_PURPOSE (inner_list));
7896 java_complete_expand_methods (outer);
7899 /* Expand methods registered in CLASS_DECL. The general idea is that
7900 we expand regular methods first. This allows us get an estimate on
7901 how outer context local alias fields are really used so we can add
7902 to the constructor just enough code to initialize them properly (it
7903 also lets us generate finit$ correctly.) Then we expand the
7904 constructors and then <clinit>. */
7907 java_complete_expand_methods (tree class_decl)
7909 tree clinit, decl, first_decl;
7911 output_class = current_class = TREE_TYPE (class_decl);
7913 /* Pre-expand <clinit> to figure whether we really need it or
7914 not. If we do need it, we pre-expand the static fields so they're
7915 ready to be used somewhere else. <clinit> will be fully expanded
7916 after we processed the constructors. */
7917 first_decl = TYPE_METHODS (current_class);
7918 clinit = maybe_generate_pre_expand_clinit (current_class);
7920 /* Then generate finit$ (if we need to) because constructors will
7922 if (TYPE_FINIT_STMT_LIST (current_class))
7923 java_complete_expand_method (generate_finit (current_class));
7925 /* Then generate instinit$ (if we need to) because constructors will
7927 if (TYPE_II_STMT_LIST (current_class))
7928 java_complete_expand_method (generate_instinit (current_class));
7930 /* Now do the constructors */
7931 for (decl = first_decl ; !java_error_count && decl; decl = TREE_CHAIN (decl))
7933 if (!DECL_CONSTRUCTOR_P (decl))
7935 java_complete_expand_method (decl);
7938 /* First, do the ordinary methods. */
7939 for (decl = first_decl; decl; decl = TREE_CHAIN (decl))
7941 /* Ctors aren't part of this batch. */
7942 if (DECL_CONSTRUCTOR_P (decl) || DECL_CLINIT_P (decl))
7945 /* Skip abstract or native methods -- but do handle native
7946 methods when generating JNI stubs. */
7947 if (METHOD_ABSTRACT (decl) || (! flag_jni && METHOD_NATIVE (decl)))
7949 DECL_FUNCTION_BODY (decl) = NULL_TREE;
7953 if (METHOD_NATIVE (decl))
7956 current_function_decl = decl;
7957 body = build_jni_stub (decl);
7958 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl)) = body;
7961 java_complete_expand_method (decl);
7964 /* If there is indeed a <clinit>, fully expand it now */
7967 /* Prevent the use of `this' inside <clinit> */
7968 ctxp->explicit_constructor_p = 1;
7969 java_complete_expand_method (clinit);
7970 ctxp->explicit_constructor_p = 0;
7973 /* We might have generated a class$ that we now want to expand */
7974 if (TYPE_DOT_CLASS (current_class))
7975 java_complete_expand_method (TYPE_DOT_CLASS (current_class));
7977 /* Now verify constructor circularity (stop after the first one we
7979 if (!CLASS_INTERFACE (class_decl))
7980 for (decl = TYPE_METHODS (current_class); decl; decl = TREE_CHAIN (decl))
7981 if (DECL_CONSTRUCTOR_P (decl)
7982 && verify_constructor_circularity (decl, decl))
7986 /* Attempt to create <clinit>. Pre-expand static fields so they can be
7987 safely used in some other methods/constructors. */
7990 maybe_generate_pre_expand_clinit (tree class_type)
7992 tree current, mdecl;
7994 if (!TYPE_CLINIT_STMT_LIST (class_type))
7997 /* Go through all static fields and pre expand them */
7998 for (current = TYPE_FIELDS (class_type); current;
7999 current = TREE_CHAIN (current))
8000 if (FIELD_STATIC (current))
8001 build_field_ref (NULL_TREE, class_type, DECL_NAME (current));
8003 /* Then build the <clinit> method */
8004 mdecl = create_artificial_method (class_type, ACC_STATIC, void_type_node,
8005 clinit_identifier_node, end_params_node);
8006 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
8008 start_artificial_method_body (mdecl);
8010 /* We process the list of assignment we produced as the result of
8011 the declaration of initialized static field and add them as
8012 statement to the <clinit> method. */
8013 for (current = TYPE_CLINIT_STMT_LIST (class_type); current;
8014 current = TREE_CHAIN (current))
8016 tree stmt = current;
8017 /* We build the assignment expression that will initialize the
8018 field to its value. There are strict rules on static
8019 initializers (8.5). FIXME */
8020 if (TREE_CODE (stmt) != BLOCK && !IS_EMPTY_STMT (stmt))
8021 stmt = build_debugable_stmt (EXPR_WFL_LINECOL (stmt), stmt);
8022 java_method_add_stmt (mdecl, stmt);
8025 end_artificial_method_body (mdecl);
8027 /* Now we want to place <clinit> as the last method (because we need
8028 it at least for interface so that it doesn't interfere with the
8029 dispatch table based lookup. */
8030 if (TREE_CHAIN (TYPE_METHODS (class_type)))
8032 current = TREE_CHAIN (TYPE_METHODS (class_type));
8033 TYPE_METHODS (class_type) = current;
8035 while (TREE_CHAIN (current))
8036 current = TREE_CHAIN (current);
8038 TREE_CHAIN (current) = mdecl;
8039 TREE_CHAIN (mdecl) = NULL_TREE;
8045 /* Analyzes a method body and look for something that isn't a
8046 MODIFY_EXPR with a constant value. */
8049 analyze_clinit_body (tree this_class, tree bbody)
8052 switch (TREE_CODE (bbody))
8055 bbody = BLOCK_EXPR_BODY (bbody);
8058 case EXPR_WITH_FILE_LOCATION:
8059 bbody = EXPR_WFL_NODE (bbody);
8063 if (analyze_clinit_body (this_class, TREE_OPERAND (bbody, 0)))
8065 bbody = TREE_OPERAND (bbody, 1);
8069 /* If we're generating to class file and we're dealing with an
8070 array initialization, we return 1 to keep <clinit> */
8071 if (TREE_CODE (TREE_OPERAND (bbody, 1)) == NEW_ARRAY_INIT
8072 && flag_emit_class_files)
8075 /* There are a few cases where we're required to keep
8077 - If this is an assignment whose operand is not constant,
8078 - If this is an assignment to a non-initialized field,
8079 - If this field is not a member of the current class.
8081 return (! TREE_CONSTANT (TREE_OPERAND (bbody, 1))
8082 || ! DECL_INITIAL (TREE_OPERAND (bbody, 0))
8083 || DECL_CONTEXT (TREE_OPERAND (bbody, 0)) != this_class);
8092 /* See whether we could get rid of <clinit>. Criteria are: all static
8093 final fields have constant initial values and the body of <clinit>
8094 is empty. Return 1 if <clinit> was discarded, 0 otherwise. */
8097 maybe_yank_clinit (tree mdecl)
8102 if (!DECL_CLINIT_P (mdecl))
8105 /* If the body isn't empty, then we keep <clinit>. Note that if
8106 we're emitting classfiles, this isn't enough not to rule it
8108 fbody = DECL_FUNCTION_BODY (mdecl);
8109 bbody = BLOCK_EXPR_BODY (fbody);
8110 if (bbody && bbody != error_mark_node)
8111 bbody = BLOCK_EXPR_BODY (bbody);
8114 if (bbody && ! flag_emit_class_files && !IS_EMPTY_STMT (bbody))
8117 type = DECL_CONTEXT (mdecl);
8118 current = TYPE_FIELDS (type);
8120 for (current = (current ? TREE_CHAIN (current) : current);
8121 current; current = TREE_CHAIN (current))
8125 /* We're not interested in non-static fields. */
8126 if (!FIELD_STATIC (current))
8129 /* Nor in fields without initializers. */
8130 f_init = DECL_INITIAL (current);
8131 if (f_init == NULL_TREE)
8134 /* Anything that isn't String or a basic type is ruled out -- or
8135 if we know how to deal with it (when doing things natively) we
8136 should generated an empty <clinit> so that SUID are computed
8138 if (! JSTRING_TYPE_P (TREE_TYPE (current))
8139 && ! JNUMERIC_TYPE_P (TREE_TYPE (current)))
8142 if (! FIELD_FINAL (current) || ! TREE_CONSTANT (f_init))
8146 /* Now we analyze the method body and look for something that
8147 isn't a MODIFY_EXPR */
8148 if (!IS_EMPTY_STMT (bbody) && analyze_clinit_body (type, bbody))
8151 /* Get rid of <clinit> in the class' list of methods */
8152 if (TYPE_METHODS (type) == mdecl)
8153 TYPE_METHODS (type) = TREE_CHAIN (mdecl);
8155 for (current = TYPE_METHODS (type); current;
8156 current = TREE_CHAIN (current))
8157 if (TREE_CHAIN (current) == mdecl)
8159 TREE_CHAIN (current) = TREE_CHAIN (mdecl);
8166 /* Install the argument from MDECL. Suitable to completion and
8167 expansion of mdecl's body. */
8170 start_complete_expand_method (tree mdecl)
8174 pushlevel (1); /* Prepare for a parameter push */
8175 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
8176 DECL_ARGUMENTS (mdecl) = tem;
8178 for (; tem; tem = TREE_CHAIN (tem))
8180 /* TREE_CHAIN (tem) will change after pushdecl. */
8181 tree next = TREE_CHAIN (tem);
8182 tree type = TREE_TYPE (tem);
8183 if (targetm.calls.promote_prototypes (type)
8184 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
8185 && INTEGRAL_TYPE_P (type))
8186 type = integer_type_node;
8187 DECL_ARG_TYPE (tem) = type;
8188 layout_decl (tem, 0);
8190 /* Re-install the next so that the list is kept and the loop
8192 TREE_CHAIN (tem) = next;
8194 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
8195 input_location = DECL_SOURCE_LOCATION (mdecl);
8196 build_result_decl (mdecl);
8200 /* Complete and expand a method. */
8203 java_complete_expand_method (tree mdecl)
8205 tree fbody, block_body, exception_copy;
8207 current_function_decl = mdecl;
8208 /* Fix constructors before expanding them */
8209 if (DECL_CONSTRUCTOR_P (mdecl))
8210 fix_constructors (mdecl);
8212 /* Expand functions that have a body */
8213 if (!DECL_FUNCTION_BODY (mdecl))
8216 fbody = DECL_FUNCTION_BODY (mdecl);
8217 block_body = BLOCK_EXPR_BODY (fbody);
8218 exception_copy = NULL_TREE;
8220 current_function_decl = mdecl;
8223 fprintf (stderr, " [%s.",
8224 lang_printable_name (DECL_CONTEXT (mdecl), 0));
8225 announce_function (mdecl);
8227 fprintf (stderr, "]");
8229 /* Prepare the function for tree completion */
8230 start_complete_expand_method (mdecl);
8232 /* Install the current this */
8233 current_this = (!METHOD_STATIC (mdecl) ?
8234 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl)) : NULL_TREE);
8236 /* Purge the `throws' list of unchecked exceptions (we save a copy
8237 of the list and re-install it later.) */
8238 exception_copy = copy_list (DECL_FUNCTION_THROWS (mdecl));
8239 purge_unchecked_exceptions (mdecl);
8241 /* Install exceptions thrown with `throws' */
8242 PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
8244 if (block_body != NULL_TREE)
8246 block_body = java_complete_tree (block_body);
8248 /* Before we check initialization, attached all class initialization
8249 variable to the block_body */
8250 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (mdecl),
8251 attach_init_test_initialization_flags, block_body);
8253 if (! flag_emit_xref && ! METHOD_NATIVE (mdecl))
8255 check_for_initialization (block_body, mdecl);
8257 /* Go through all the flags marking the initialization of
8258 static variables and see whether they're definitively
8259 assigned, in which case the type is remembered as
8260 definitively initialized in MDECL. */
8261 if (STATIC_CLASS_INIT_OPT_P ())
8263 /* Always register the context as properly initialized in
8264 MDECL. This used with caution helps removing extra
8265 initialization of self. */
8266 if (METHOD_STATIC (mdecl))
8269 (DECL_FUNCTION_INITIALIZED_CLASS_TABLE (mdecl),
8270 DECL_CONTEXT (mdecl), INSERT)) = DECL_CONTEXT (mdecl);
8274 ctxp->explicit_constructor_p = 0;
8277 BLOCK_EXPR_BODY (fbody) = block_body;
8279 /* If we saw a return but couldn't evaluate it properly, we'll have
8280 an error_mark_node here. */
8281 if (block_body != error_mark_node
8282 && (block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
8283 && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE
8285 missing_return_error (current_function_decl);
8287 /* See if we can get rid of <clinit> if MDECL happens to be <clinit> */
8288 maybe_yank_clinit (mdecl);
8290 /* Pop the current level, with special measures if we found errors. */
8291 if (java_error_count)
8292 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
8295 /* Pop the exceptions and sanity check */
8297 if (currently_caught_type_list)
8300 /* Restore the copy of the list of exceptions if emitting xrefs. */
8301 DECL_FUNCTION_THROWS (mdecl) = exception_copy;
8304 /* For with each class for which there's code to generate. */
8307 java_expand_method_bodies (tree class)
8310 for (decl = TYPE_METHODS (class); decl; decl = TREE_CHAIN (decl))
8314 if (! DECL_FUNCTION_BODY (decl))
8317 current_function_decl = decl;
8319 block = BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl));
8321 /* Save the function body for gimplify and inlining. */
8322 DECL_SAVED_TREE (decl) = block;
8324 /* It's time to assign the variable flagging static class
8325 initialization based on which classes invoked static methods
8326 are definitely initializing. This should be flagged. */
8327 if (STATIC_CLASS_INIT_OPT_P ())
8329 tree list = DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (decl);
8330 for (; list != NULL_TREE; list = TREE_CHAIN (list))
8332 /* Executed for each statement calling a static function.
8333 LIST is a TREE_LIST whose PURPOSE is the called function
8334 and VALUE is a compound whose second operand can be patched
8335 with static class initialization flag assignments. */
8337 tree called_method = TREE_PURPOSE (list);
8338 tree compound = TREE_VALUE (list);
8339 tree assignment_compound_list
8340 = build_tree_list (called_method, NULL);
8342 /* For each class definitely initialized in
8343 CALLED_METHOD, fill ASSIGNMENT_COMPOUND with
8344 assignment to the class initialization flag. */
8345 htab_traverse (DECL_FUNCTION_INITIALIZED_CLASS_TABLE (called_method),
8346 emit_test_initialization,
8347 assignment_compound_list);
8349 if (TREE_VALUE (assignment_compound_list))
8350 TREE_OPERAND (compound, 1)
8351 = TREE_VALUE (assignment_compound_list);
8355 /* Expand the function body. */
8356 source_end_java_method ();
8362 /* This section of the code deals with accessing enclosing context
8363 fields either directly by using the relevant access to this$<n> or
8364 by invoking an access method crafted for that purpose. */
8366 /* Build the necessary access from an inner class to an outer
8367 class. This routine could be optimized to cache previous result
8368 (decl, current_class and returned access). When an access method
8369 needs to be generated, it always takes the form of a read. It might
8370 be later turned into a write by calling outer_field_access_fix. */
8373 build_outer_field_access (tree id, tree decl)
8375 tree access = NULL_TREE;
8376 tree ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
8377 tree decl_ctx = DECL_CONTEXT (decl);
8379 /* If the immediate enclosing context of the current class is the
8380 field decl's class or inherits from it; build the access as
8381 `this$<n>.<field>'. Note that we will break the `private' barrier
8382 if we're not emitting bytecodes. */
8383 if ((ctx == decl_ctx || inherits_from_p (ctx, decl_ctx))
8384 && (!FIELD_PRIVATE (decl) || !flag_emit_class_files ))
8386 tree thisn = build_current_thisn (current_class);
8387 access = make_qualified_primary (build_wfl_node (thisn),
8388 id, EXPR_WFL_LINECOL (id));
8390 /* Otherwise, generate access methods to outer this and access the
8391 field (either using an access method or by direct access.) */
8394 int lc = EXPR_WFL_LINECOL (id);
8396 /* Now we chain the required number of calls to the access$0 to
8397 get a hold to the enclosing instance we need, and then we
8398 build the field access. */
8399 access = build_access_to_thisn (current_class, decl_ctx, lc);
8401 /* If the field is private and we're generating bytecode, then
8402 we generate an access method */
8403 if (FIELD_PRIVATE (decl) && flag_emit_class_files )
8405 tree name = build_outer_field_access_methods (decl);
8406 access = build_outer_field_access_expr (lc, decl_ctx,
8407 name, access, NULL_TREE);
8409 /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'.
8410 Once again we break the `private' access rule from a foreign
8413 access = make_qualified_primary (access, id, lc);
8415 return resolve_expression_name (access, NULL);
8418 /* Return a nonzero value if NODE describes an outer field inner
8422 outer_field_access_p (tree type, tree decl)
8424 if (!INNER_CLASS_TYPE_P (type)
8425 || TREE_CODE (decl) != FIELD_DECL
8426 || DECL_CONTEXT (decl) == type)
8429 /* If the inner class extends the declaration context of the field
8430 we're trying to access, then this isn't an outer field access */
8431 if (inherits_from_p (type, DECL_CONTEXT (decl)))
8434 for (type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))); ;
8435 type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))))
8437 if (type == DECL_CONTEXT (decl))
8440 if (!DECL_CONTEXT (TYPE_NAME (type)))
8442 /* Before we give up, see whether the field is inherited from
8443 the enclosing context we're considering. */
8444 if (inherits_from_p (type, DECL_CONTEXT (decl)))
8453 /* Return a nonzero value if NODE represents an outer field inner
8454 access that was been already expanded. As a side effect, it returns
8455 the name of the field being accessed and the argument passed to the
8456 access function, suitable for a regeneration of the access method
8457 call if necessary. */
8460 outer_field_expanded_access_p (tree node, tree *name, tree *arg_type,
8465 if (TREE_CODE (node) != CALL_EXPR)
8468 /* Well, gcj generates slightly different tree nodes when compiling
8469 to native or bytecodes. It's the case for function calls. */
8471 if (flag_emit_class_files
8472 && TREE_CODE (node) == CALL_EXPR
8473 && OUTER_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (TREE_OPERAND (node, 0))))
8475 else if (!flag_emit_class_files)
8477 node = TREE_OPERAND (node, 0);
8479 if (node && TREE_OPERAND (node, 0)
8480 && TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR)
8482 node = TREE_OPERAND (node, 0);
8483 if (TREE_OPERAND (node, 0)
8484 && TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL
8485 && (OUTER_FIELD_ACCESS_IDENTIFIER_P
8486 (DECL_NAME (TREE_OPERAND (node, 0)))))
8491 if (identified && name && arg_type && arg)
8493 tree argument = TREE_OPERAND (node, 1);
8494 *name = DECL_NAME (TREE_OPERAND (node, 0));
8495 *arg_type = TREE_TYPE (TREE_TYPE (TREE_VALUE (argument)));
8496 *arg = TREE_VALUE (argument);
8501 /* Detect in NODE an outer field read access from an inner class and
8502 transform it into a write with RHS as an argument. This function is
8503 called from the java_complete_lhs when an assignment to a LHS can
8507 outer_field_access_fix (tree wfl, tree node, tree rhs)
8509 tree name, arg_type, arg;
8511 if (outer_field_expanded_access_p (node, &name, &arg_type, &arg))
8513 node = build_outer_field_access_expr (EXPR_WFL_LINECOL (wfl),
8514 arg_type, name, arg, rhs);
8515 return java_complete_tree (node);
8520 /* Construct the expression that calls an access method:
8521 <type>.access$<n>(<arg1> [, <arg2>]);
8523 ARG2 can be NULL and will be omitted in that case. It will denote a
8527 build_outer_field_access_expr (int lc, tree type, tree access_method_name,
8528 tree arg1, tree arg2)
8530 tree args, cn, access;
8532 args = arg1 ? arg1 :
8533 build_wfl_node (build_current_thisn (current_class));
8534 args = build_tree_list (NULL_TREE, args);
8537 args = tree_cons (NULL_TREE, arg2, args);
8539 access = build_method_invocation (build_wfl_node (access_method_name), args);
8540 cn = build_wfl_node (DECL_NAME (TYPE_NAME (type)));
8541 return make_qualified_primary (cn, access, lc);
8545 build_new_access_id (void)
8547 static int access_n_counter = 1;
8550 sprintf (buffer, "access$%d", access_n_counter++);
8551 return get_identifier (buffer);
8554 /* Create the static access functions for the outer field DECL. We define a
8556 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$) {
8560 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$,
8561 TREE_TYPE (<field>) value$) {
8562 return inst$.field = value$;
8564 We should have a usage flags on the DECL so we can lazily turn the ones
8565 we're using for code generation. FIXME.
8569 build_outer_field_access_methods (tree decl)
8571 tree id, args, stmt, mdecl;
8573 if (FIELD_INNER_ACCESS_P (decl))
8574 return FIELD_INNER_ACCESS (decl);
8576 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
8578 /* Create the identifier and a function named after it. */
8579 id = build_new_access_id ();
8581 /* The identifier is marked as bearing the name of a generated write
8582 access function for outer field accessed from inner classes. */
8583 OUTER_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
8585 /* Create the read access */
8586 args = build_tree_list (inst_id, build_pointer_type (DECL_CONTEXT (decl)));
8587 TREE_CHAIN (args) = end_params_node;
8588 stmt = make_qualified_primary (build_wfl_node (inst_id),
8589 build_wfl_node (DECL_NAME (decl)), 0);
8590 stmt = build_return (0, stmt);
8591 mdecl = build_outer_field_access_method (DECL_CONTEXT (decl),
8592 TREE_TYPE (decl), id, args, stmt);
8593 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
8595 /* Create the write access method. No write access for final variable */
8596 if (!FIELD_FINAL (decl))
8598 args = build_tree_list (inst_id,
8599 build_pointer_type (DECL_CONTEXT (decl)));
8600 TREE_CHAIN (args) = build_tree_list (wpv_id, TREE_TYPE (decl));
8601 TREE_CHAIN (TREE_CHAIN (args)) = end_params_node;
8602 stmt = make_qualified_primary (build_wfl_node (inst_id),
8603 build_wfl_node (DECL_NAME (decl)), 0);
8604 stmt = build_return (0, build_assignment (ASSIGN_TK, 0, stmt,
8605 build_wfl_node (wpv_id)));
8606 mdecl = build_outer_field_access_method (DECL_CONTEXT (decl),
8607 TREE_TYPE (decl), id,
8610 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
8612 /* Return the access name */
8613 return FIELD_INNER_ACCESS (decl) = id;
8616 /* Build an field access method NAME. */
8619 build_outer_field_access_method (tree class, tree type, tree name,
8620 tree args, tree body)
8622 tree saved_current_function_decl, mdecl;
8624 /* Create the method */
8625 mdecl = create_artificial_method (class, ACC_STATIC, type, name, args);
8626 fix_method_argument_names (args, mdecl);
8627 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8629 /* Attach the method body. */
8630 saved_current_function_decl = current_function_decl;
8631 start_artificial_method_body (mdecl);
8632 java_method_add_stmt (mdecl, body);
8633 end_artificial_method_body (mdecl);
8634 current_function_decl = saved_current_function_decl;
8640 /* This section deals with building access function necessary for
8641 certain kinds of method invocation from inner classes. */
8644 build_outer_method_access_method (tree decl)
8646 tree saved_current_function_decl, mdecl;
8647 tree args = NULL_TREE, call_args = NULL_TREE;
8648 tree carg, id, body, class;
8650 int parm_id_count = 0;
8652 /* Test this abort with an access to a private field */
8653 if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "access$"))
8656 /* Check the cache first */
8657 if (DECL_FUNCTION_INNER_ACCESS (decl))
8658 return DECL_FUNCTION_INNER_ACCESS (decl);
8660 class = DECL_CONTEXT (decl);
8662 /* Obtain an access identifier and mark it */
8663 id = build_new_access_id ();
8664 OUTER_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
8666 carg = TYPE_ARG_TYPES (TREE_TYPE (decl));
8667 /* Create the arguments, as much as the original */
8668 for (; carg && carg != end_params_node;
8669 carg = TREE_CHAIN (carg))
8671 sprintf (buffer, "write_parm_value$%d", parm_id_count++);
8672 args = chainon (args, build_tree_list (get_identifier (buffer),
8673 TREE_VALUE (carg)));
8675 args = chainon (args, end_params_node);
8677 /* Create the method */
8678 mdecl = create_artificial_method (class, ACC_STATIC,
8679 TREE_TYPE (TREE_TYPE (decl)), id, args);
8680 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8681 /* There is a potential bug here. We should be able to use
8682 fix_method_argument_names, but then arg names get mixed up and
8683 eventually a constructor will have its this$0 altered and the
8684 outer context won't be assignment properly. The testcase is
8686 TYPE_ARG_TYPES (TREE_TYPE (mdecl)) = args;
8688 /* Attach the method body. */
8689 saved_current_function_decl = current_function_decl;
8690 start_artificial_method_body (mdecl);
8692 /* The actual method invocation uses the same args. When invoking a
8693 static methods that way, we don't want to skip the first
8696 if (!METHOD_STATIC (decl))
8697 carg = TREE_CHAIN (carg);
8698 for (; carg && carg != end_params_node; carg = TREE_CHAIN (carg))
8699 call_args = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (carg)),
8702 body = build_method_invocation (build_wfl_node (DECL_NAME (decl)),
8704 if (!METHOD_STATIC (decl))
8705 body = make_qualified_primary (build_wfl_node (TREE_PURPOSE (args)),
8707 if (TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
8708 body = build_return (0, body);
8709 java_method_add_stmt (mdecl,body);
8710 end_artificial_method_body (mdecl);
8711 current_function_decl = saved_current_function_decl;
8713 /* Back tag the access function so it know what it accesses */
8714 DECL_FUNCTION_ACCESS_DECL (decl) = mdecl;
8716 /* Tag the current method so it knows it has an access generated */
8717 return DECL_FUNCTION_INNER_ACCESS (decl) = mdecl;
8721 /* This section of the code deals with building expressions to access
8722 the enclosing instance of an inner class. The enclosing instance is
8723 kept in a generated field called this$<n>, with <n> being the
8724 inner class nesting level (starting from 0.) */
8726 /* Build an access to a given this$<n>, always chaining access call to
8727 others. Access methods to this$<n> are build on the fly if
8728 necessary. This CAN'T be used to solely access this$<n-1> from
8729 this$<n> (which alway yield to special cases and optimization, see
8730 for example build_outer_field_access). */
8733 build_access_to_thisn (tree from, tree to, int lc)
8735 tree access = NULL_TREE;
8737 while (from != to && PURE_INNER_CLASS_TYPE_P (from))
8741 access = build_current_thisn (from);
8742 access = build_wfl_node (access);
8746 tree access0_wfl, cn;
8748 maybe_build_thisn_access_method (from);
8749 access0_wfl = build_wfl_node (access0_identifier_node);
8750 cn = build_wfl_node (DECL_NAME (TYPE_NAME (from)));
8751 EXPR_WFL_LINECOL (access0_wfl) = lc;
8752 access = build_tree_list (NULL_TREE, access);
8753 access = build_method_invocation (access0_wfl, access);
8754 access = make_qualified_primary (cn, access, lc);
8757 /* If FROM isn't an inner class, that's fine, we've done enough.
8758 What we're looking for can be accessed from there. */
8759 from = DECL_CONTEXT (TYPE_NAME (from));
8762 from = TREE_TYPE (from);
8767 /* Build an access function to the this$<n> local to TYPE. NULL_TREE
8768 is returned if nothing needs to be generated. Otherwise, the method
8769 generated and a method decl is returned.
8771 NOTE: These generated methods should be declared in a class file
8772 attribute so that they can't be referred to directly. */
8775 maybe_build_thisn_access_method (tree type)
8777 tree mdecl, args, stmt, rtype;
8778 tree saved_current_function_decl;
8780 /* If TYPE is a top-level class, no access method is required.
8781 If there already is such an access method, bail out. */
8782 if (CLASS_ACCESS0_GENERATED_P (type) || !PURE_INNER_CLASS_TYPE_P (type))
8785 /* We generate the method. The method looks like:
8786 static <outer_of_type> access$0 (<type> inst$) { return inst$.this$<n>; }
8788 args = build_tree_list (inst_id, build_pointer_type (type));
8789 TREE_CHAIN (args) = end_params_node;
8790 rtype = build_pointer_type (TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))));
8791 mdecl = create_artificial_method (type, ACC_STATIC, rtype,
8792 access0_identifier_node, args);
8793 fix_method_argument_names (args, mdecl);
8794 layout_class_method (type, NULL_TREE, mdecl, NULL_TREE);
8795 stmt = build_current_thisn (type);
8796 stmt = make_qualified_primary (build_wfl_node (inst_id),
8797 build_wfl_node (stmt), 0);
8798 stmt = build_return (0, stmt);
8800 saved_current_function_decl = current_function_decl;
8801 start_artificial_method_body (mdecl);
8802 java_method_add_stmt (mdecl, stmt);
8803 end_artificial_method_body (mdecl);
8804 current_function_decl = saved_current_function_decl;
8806 CLASS_ACCESS0_GENERATED_P (type) = 1;
8811 /* Craft an correctly numbered `this$<n>'string. this$0 is used for
8812 the first level of innerclassing. this$1 for the next one, etc...
8813 This function can be invoked with TYPE to NULL, available and then
8814 has to count the parser context. */
8816 static GTY(()) tree saved_thisn;
8817 static GTY(()) tree saved_type;
8820 build_current_thisn (tree type)
8822 static int saved_i = -1;
8823 static int saved_type_i = 0;
8830 if (type == saved_type)
8834 for (i = -1, decl = DECL_CONTEXT (TYPE_NAME (type));
8835 decl; decl = DECL_CONTEXT (decl), i++)
8843 i = list_length (GET_CPC_LIST ())-2;
8848 sprintf (buffer, "this$%d", i);
8850 saved_thisn = get_identifier (buffer);
8854 /* Return the assignment to the hidden enclosing context `this$<n>'
8855 by the second incoming parameter to the innerclass constructor. The
8856 form used is `this.this$<n> = this$<n>;'. */
8859 build_thisn_assign (void)
8861 if (current_class && PURE_INNER_CLASS_TYPE_P (current_class))
8863 tree thisn = build_current_thisn (current_class);
8864 tree lhs = make_qualified_primary (build_wfl_node (this_identifier_node),
8865 build_wfl_node (thisn), 0);
8866 tree rhs = build_wfl_node (thisn);
8867 #ifdef USE_MAPPED_LOCATION
8868 SET_EXPR_LOCATION (lhs, input_location);
8870 EXPR_WFL_SET_LINECOL (lhs, input_line, 0);
8872 return build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (lhs), lhs, rhs);
8878 /* Building the synthetic `class$' used to implement the `.class' 1.1
8879 extension for non primitive types. This method looks like:
8881 static Class class$(String type) throws NoClassDefFoundError
8883 try {return (java.lang.Class.forName (String));}
8884 catch (ClassNotFoundException e) {
8885 throw new NoClassDefFoundError(e.getMessage());}
8888 static GTY(()) tree get_message_wfl;
8889 static GTY(()) tree type_parm_wfl;
8892 build_dot_class_method (tree class)
8894 #define BWF(S) build_wfl_node (get_identifier ((S)))
8895 #ifdef USE_MAPPED_LOCATION
8896 #define MQN(X,Y) make_qualified_name ((X), (Y), UNKNOWN_LOCATION)
8898 #define MQN(X,Y) make_qualified_name ((X), (Y), 0)
8900 tree args, tmp, saved_current_function_decl, mdecl, qual_name;
8901 tree stmt, throw_stmt;
8903 if (!get_message_wfl)
8905 get_message_wfl = build_wfl_node (get_identifier ("getMessage"));
8906 type_parm_wfl = build_wfl_node (get_identifier ("type$"));
8909 /* Build the arguments */
8910 args = build_tree_list (get_identifier ("type$"),
8911 build_pointer_type (string_type_node));
8912 TREE_CHAIN (args) = end_params_node;
8914 /* Build the qualified name java.lang.Class.forName */
8915 tmp = MQN (MQN (MQN (BWF ("java"),
8916 BWF ("lang")), BWF ("Class")), BWF ("forName"));
8918 /* Create the "class$" function */
8919 mdecl = create_artificial_method (class, ACC_STATIC,
8920 build_pointer_type (class_type_node),
8921 classdollar_identifier_node, args);
8922 qual_name = MQN (MQN (BWF ("java"), BWF ("lang")),
8923 BWF ("NoClassDefFoundError"));
8924 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (NULL_TREE, qual_name);
8925 register_incomplete_type (JDEP_EXCEPTION, qual_name, NULL_TREE, NULL_TREE);
8926 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
8927 &TREE_VALUE (DECL_FUNCTION_THROWS (mdecl));
8929 /* We start by building the try block. We need to build:
8930 return (java.lang.Class.forName (type)); */
8931 stmt = build_method_invocation (tmp,
8932 build_tree_list (NULL_TREE, type_parm_wfl));
8933 stmt = build_return (0, stmt);
8935 /* Now onto the catch block. We start by building the expression
8936 throwing a new exception: throw new NoClassDefFoundError (_.getMessage) */
8937 #ifdef USE_MAPPED_LOCATION
8938 throw_stmt = make_qualified_name (build_wfl_node (wpv_id),
8939 get_message_wfl, UNKNOWN_LOCATION);
8941 throw_stmt = make_qualified_name (build_wfl_node (wpv_id),
8942 get_message_wfl, 0);
8944 throw_stmt = build_method_invocation (throw_stmt, NULL_TREE);
8946 /* Build new NoClassDefFoundError (_.getMessage) */
8947 throw_stmt = build_new_invocation
8948 (build_wfl_node (get_identifier ("NoClassDefFoundError")),
8949 build_tree_list (build_pointer_type (string_type_node), throw_stmt));
8951 /* Build the throw, (it's too early to use BUILD_THROW) */
8952 throw_stmt = build1 (THROW_EXPR, NULL_TREE, throw_stmt);
8954 /* Encapsulate STMT in a try block. The catch clause executes THROW_STMT */
8955 qual_name = MQN (MQN (BWF ("java"), BWF ("lang")),
8956 BWF ("ClassNotFoundException"));
8957 stmt = encapsulate_with_try_catch (0, qual_name, stmt, throw_stmt);
8959 fix_method_argument_names (args, mdecl);
8960 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8961 saved_current_function_decl = current_function_decl;
8962 start_artificial_method_body (mdecl);
8963 java_method_add_stmt (mdecl, stmt);
8964 end_artificial_method_body (mdecl);
8965 current_function_decl = saved_current_function_decl;
8966 TYPE_DOT_CLASS (class) = mdecl;
8972 build_dot_class_method_invocation (tree this_class, tree type)
8974 tree dot_class_method = TYPE_DOT_CLASS (this_class);
8977 if (TYPE_ARRAY_P (type))
8978 sig_id = build_java_signature (type);
8980 sig_id = DECL_NAME (TYPE_NAME (type));
8982 /* Ensure that the proper name separator is used */
8983 sig_id = unmangle_classname (IDENTIFIER_POINTER (sig_id),
8984 IDENTIFIER_LENGTH (sig_id));
8986 s = build_string (IDENTIFIER_LENGTH (sig_id),
8987 IDENTIFIER_POINTER (sig_id));
8988 t = build_method_invocation (build_wfl_node (DECL_NAME (dot_class_method)),
8989 build_tree_list (NULL_TREE, s));
8990 if (DECL_CONTEXT (dot_class_method) != this_class)
8992 tree class_name = DECL_NAME (TYPE_NAME (DECL_CONTEXT (dot_class_method)));
8993 t = make_qualified_primary (build_wfl_node (class_name), t, 0);
8998 /* This section of the code deals with constructor. */
9000 /* Craft a body for default constructor. Patch existing constructor
9001 bodies with call to super() and field initialization statements if
9005 fix_constructors (tree mdecl)
9007 tree iii; /* Instance Initializer Invocation */
9008 tree *bodyp = &DECL_FUNCTION_BODY (mdecl);
9009 tree thisn_assign, compound = NULL_TREE;
9010 tree class_type = DECL_CONTEXT (mdecl);
9012 if (DECL_FIXED_CONSTRUCTOR_P (mdecl))
9014 DECL_FIXED_CONSTRUCTOR_P (mdecl) = 1;
9018 /* It is an error for the compiler to generate a default
9019 constructor if the superclass doesn't have a constructor that
9020 takes no argument, or the same args for an anonymous class */
9021 if (verify_constructor_super (mdecl))
9023 tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (class_type));
9024 tree save = DECL_NAME (mdecl);
9025 const char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
9026 DECL_NAME (mdecl) = DECL_NAME (sclass_decl);
9028 (lookup_cl (TYPE_NAME (class_type)),
9029 "No constructor matching %qs found in class %qs",
9030 lang_printable_name (mdecl, 2), n);
9031 DECL_NAME (mdecl) = save;
9034 /* The constructor body must be crafted by hand. It's the
9035 constructor we defined when we realize we didn't have the
9036 CLASSNAME() constructor */
9037 start_artificial_method_body (mdecl);
9039 /* Insert an assignment to the this$<n> hidden field, if
9041 if ((thisn_assign = build_thisn_assign ()))
9042 java_method_add_stmt (mdecl, thisn_assign);
9044 /* We don't generate a super constructor invocation if we're
9045 compiling java.lang.Object. build_super_invocation takes care
9047 java_method_add_stmt (mdecl, build_super_invocation (mdecl));
9050 if ((iii = build_instinit_invocation (class_type)))
9051 java_method_add_stmt (mdecl, iii);
9053 end_artificial_method_body (mdecl);
9055 /* Search for an explicit constructor invocation */
9059 int invokes_this = 0;
9060 tree main_block = BLOCK_EXPR_BODY (*bodyp);
9065 switch (TREE_CODE (body))
9068 found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
9069 if (CALL_THIS_CONSTRUCTOR_P (body))
9073 case EXPR_WITH_FILE_LOCATION:
9074 bodyp = &TREE_OPERAND (body, 0);
9077 bodyp = &BLOCK_EXPR_BODY (body);
9085 /* Generate the assignment to this$<n>, if necessary */
9086 if ((thisn_assign = build_thisn_assign ()))
9087 compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
9089 /* The constructor is missing an invocation of super() */
9091 compound = add_stmt_to_compound (compound, NULL_TREE,
9092 build_super_invocation (mdecl));
9093 /* Explicit super() invocation should take place before the
9094 instance initializer blocks. */
9097 compound = add_stmt_to_compound (compound, NULL_TREE, *bodyp);
9098 *bodyp = build_java_empty_stmt ();
9101 DECL_INIT_CALLS_THIS (mdecl) = invokes_this;
9103 /* Insert the instance initializer block right after. */
9104 if (!invokes_this && (iii = build_instinit_invocation (class_type)))
9105 compound = add_stmt_to_compound (compound, NULL_TREE, iii);
9107 /* Fix the constructor main block if we're adding extra stmts */
9110 compound = add_stmt_to_compound (compound, NULL_TREE,
9111 BLOCK_EXPR_BODY (main_block));
9112 BLOCK_EXPR_BODY (main_block) = compound;
9117 /* Browse constructors in the super class, searching for a constructor
9118 that doesn't take any argument. Return 0 if one is found, 1
9119 otherwise. If the current class is an anonymous inner class, look
9120 for something that has the same signature. */
9123 verify_constructor_super (tree mdecl)
9125 tree class = CLASSTYPE_SUPER (current_class);
9126 int super_inner = PURE_INNER_CLASS_TYPE_P (class);
9132 if (ANONYMOUS_CLASS_P (current_class))
9134 tree mdecl_arg_type;
9135 SKIP_THIS_AND_ARTIFICIAL_PARMS (mdecl_arg_type, mdecl);
9136 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
9137 if (DECL_CONSTRUCTOR_P (sdecl))
9140 tree arg_type = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
9142 arg_type = TREE_CHAIN (arg_type);
9143 for (m_arg_type = mdecl_arg_type;
9144 (arg_type != end_params_node
9145 && m_arg_type != end_params_node);
9146 arg_type = TREE_CHAIN (arg_type),
9147 m_arg_type = TREE_CHAIN (m_arg_type))
9148 if (!valid_method_invocation_conversion_p
9149 (TREE_VALUE (arg_type),
9150 TREE_VALUE (m_arg_type)))
9153 if (arg_type == end_params_node && m_arg_type == end_params_node)
9159 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
9161 tree arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
9163 arg = TREE_CHAIN (arg);
9164 if (DECL_CONSTRUCTOR_P (sdecl) && arg == end_params_node)
9171 /* Generate code for all context remembered for code generation. */
9173 static GTY(()) tree reversed_class_list;
9175 java_expand_classes (void)
9177 int save_error_count = 0;
9178 static struct parser_ctxt *cur_ctxp = NULL;
9179 location_t save_location;
9181 java_parse_abort_on_error ();
9182 if (!(ctxp = ctxp_for_generation))
9184 java_layout_classes ();
9185 java_parse_abort_on_error ();
9186 save_location = input_location;
9188 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9191 for (current = cur_ctxp->class_list;
9193 current = TREE_CHAIN (current))
9194 gen_indirect_dispatch_tables (TREE_TYPE (current));
9197 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9200 input_location = ctxp->file_start_location;
9201 lang_init_source (2); /* Error msgs have method prototypes */
9202 java_complete_expand_classes (); /* Complete and expand classes */
9203 java_parse_abort_on_error ();
9205 input_location = save_location;
9207 /* Find anonymous classes and expand their constructor. This extra pass is
9208 necessary because the constructor itself is only generated when the
9209 method in which it is defined is expanded. */
9210 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9214 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9216 output_class = current_class = TREE_TYPE (current);
9217 if (ANONYMOUS_CLASS_P (current_class))
9220 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9222 if (DECL_CONSTRUCTOR_P (d))
9224 java_complete_expand_method (d);
9225 break; /* There is only one constructor. */
9232 /* Expanding the constructors of anonymous classes generates access
9233 methods. Scan all the methods looking for null DECL_RESULTs --
9234 this will be the case if a method hasn't been expanded. */
9235 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9239 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9242 output_class = current_class = TREE_TYPE (current);
9243 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9245 if (DECL_RESULT (d) == NULL_TREE)
9246 java_complete_expand_method (d);
9251 /* ??? Instead of all this we could iterate around the list of
9252 classes until there were no more un-expanded methods. It would
9253 take a little longer -- one pass over the whole list of methods
9254 -- but it would be simpler. Like this: */
9257 int something_changed;
9261 something_changed = 0;
9262 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9266 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9269 output_class = current_class = TREE_TYPE (current);
9270 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9272 if (DECL_RESULT (d) == NULL_TREE)
9274 something_changed = 1;
9275 java_complete_expand_method (d);
9281 while (something_changed);
9285 /* If we've found error at that stage, don't try to generate
9286 anything, unless we're emitting xrefs or checking the syntax only
9287 (but not using -fsyntax-only for the purpose of generating
9289 if (java_error_count && !flag_emit_xref
9290 && (!flag_syntax_only && !flag_emit_class_files))
9293 /* Now things are stable, go for generation of the class data. */
9295 /* We pessimistically marked all methods and fields external until
9296 we knew what set of classes we were planning to compile. Now mark
9297 those that will be generated locally as not external. */
9298 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9302 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9303 java_mark_class_local (TREE_TYPE (current));
9306 /* Compile the classes. */
9307 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9310 reversed_class_list = NULL;
9314 /* We write out the classes in reverse order. This ensures that
9315 inner classes are written before their containing classes,
9316 which is important for parallel builds. Otherwise, the
9317 class file for the outer class may be found, but the class
9318 file for the inner class may not be present. In that
9319 situation, the compiler cannot fall back to the original
9320 source, having already read the outer class, so we must
9321 prevent that situation. */
9322 for (current = ctxp->class_list;
9324 current = TREE_CHAIN (current))
9326 = tree_cons (NULL_TREE, current, reversed_class_list);
9328 for (current = reversed_class_list;
9330 current = TREE_CHAIN (current))
9332 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
9333 if (flag_emit_class_files)
9334 write_classfile (current_class);
9336 expand_xref (current_class);
9337 else if (! flag_syntax_only)
9338 java_expand_method_bodies (current_class);
9344 java_finish_classes (void)
9346 static struct parser_ctxt *cur_ctxp = NULL;
9347 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9351 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9353 output_class = current_class = TREE_TYPE (current);
9359 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
9360 a tree list node containing RIGHT. Fore coming RIGHTs will be
9361 chained to this hook. LOCATION contains the location of the
9362 separating `.' operator. */
9365 make_qualified_primary (tree primary, tree right, int location)
9369 if (TREE_CODE (primary) != EXPR_WITH_FILE_LOCATION)
9370 wfl = build_wfl_wrap (primary, location);
9374 /* If wfl wasn't qualified, we build a first anchor */
9375 if (!EXPR_WFL_QUALIFICATION (wfl))
9376 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (wfl, NULL_TREE);
9379 /* And chain them */
9380 EXPR_WFL_LINECOL (right) = location;
9381 chainon (EXPR_WFL_QUALIFICATION (wfl), build_tree_list (right, NULL_TREE));
9382 PRIMARY_P (wfl) = 1;
9386 /* Simple merge of two name separated by a `.' */
9389 merge_qualified_name (tree left, tree right)
9392 if (!left && !right)
9401 obstack_grow (&temporary_obstack, IDENTIFIER_POINTER (left),
9402 IDENTIFIER_LENGTH (left));
9403 obstack_1grow (&temporary_obstack, '.');
9404 obstack_grow0 (&temporary_obstack, IDENTIFIER_POINTER (right),
9405 IDENTIFIER_LENGTH (right));
9406 node = get_identifier (obstack_base (&temporary_obstack));
9407 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
9408 QUALIFIED_P (node) = 1;
9412 /* Merge the two parts of a qualified name into LEFT. Set the
9413 location information of the resulting node to LOCATION, usually
9414 inherited from the location information of the `.' operator. */
9417 make_qualified_name (tree left, tree right,
9418 #ifdef USE_MAPPED_LOCATION
9419 source_location location
9425 #ifdef USE_COMPONENT_REF
9426 tree node = build3 (COMPONENT_REF, NULL_TREE, left, right, NULL_TREE);
9427 SET_EXPR_LOCATION (node, location);
9430 tree left_id = EXPR_WFL_NODE (left);
9431 tree right_id = EXPR_WFL_NODE (right);
9434 merge = merge_qualified_name (left_id, right_id);
9436 /* Left wasn't qualified and is now qualified */
9437 #ifdef USE_MAPPED_LOCATION
9438 if (!QUALIFIED_P (left_id))
9440 tree wfl = build_expr_wfl (left_id, EXPR_LOCATION (left));
9441 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
9444 wfl = build_expr_wfl (right_id, location);
9446 if (!QUALIFIED_P (left_id))
9448 tree wfl = build_expr_wfl (left_id, ctxp->filename, 0, 0);
9449 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (left);
9450 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
9453 wfl = build_expr_wfl (right_id, ctxp->filename, 0, 0);
9454 EXPR_WFL_LINECOL (wfl) = location;
9456 chainon (EXPR_WFL_QUALIFICATION (left), build_tree_list (wfl, NULL_TREE));
9457 EXPR_WFL_NODE (left) = merge;
9462 /* Extract the last identifier component of the qualified in WFL. The
9463 last identifier is removed from the linked list */
9466 cut_identifier_in_qualified (tree wfl)
9469 tree previous = NULL_TREE;
9470 for (q = EXPR_WFL_QUALIFICATION (wfl); ; previous = q, q = TREE_CHAIN (q))
9471 if (!TREE_CHAIN (q))
9474 /* Operating on a non qualified qualified WFL. */
9477 TREE_CHAIN (previous) = NULL_TREE;
9478 return TREE_PURPOSE (q);
9482 /* Resolve the expression name NAME. Return its decl. */
9485 resolve_expression_name (tree id, tree *orig)
9487 tree name = EXPR_WFL_NODE (id);
9490 /* 6.5.5.1: Simple expression names */
9491 if (!PRIMARY_P (id) && !QUALIFIED_P (name))
9493 /* 15.13.1: NAME can appear within the scope of a local variable
9495 if ((decl = IDENTIFIER_LOCAL_VALUE (name)))
9498 /* 15.13.1: NAME can appear within a class declaration */
9501 decl = lookup_field_wrapper (current_class, name);
9504 tree access = NULL_TREE;
9505 int fs = FIELD_STATIC (decl);
9507 /* If we're accessing an outer scope local alias, make
9508 sure we change the name of the field we're going to
9510 if (FIELD_LOCAL_ALIAS_USED (decl))
9511 name = DECL_NAME (decl);
9513 check_deprecation (id, decl);
9515 /* Instance variable (8.3.1.1) can't appear within
9516 static method, static initializer or initializer for
9517 a static variable. */
9518 if (!fs && METHOD_STATIC (current_function_decl))
9520 static_ref_err (id, name, current_class);
9521 return error_mark_node;
9523 /* Instance variables can't appear as an argument of
9524 an explicit constructor invocation */
9525 if (!fs && ctxp->explicit_constructor_p
9526 && !enclosing_context_p (DECL_CONTEXT (decl), current_class))
9529 (id, "Can't reference %qs before the superclass constructor has been called", IDENTIFIER_POINTER (name));
9530 return error_mark_node;
9533 /* If we're processing an inner class and we're trying
9534 to access a field belonging to an outer class, build
9535 the access to the field */
9536 if (!fs && outer_field_access_p (current_class, decl))
9538 if (CLASS_STATIC (TYPE_NAME (current_class)))
9540 static_ref_err (id, DECL_NAME (decl), current_class);
9541 return error_mark_node;
9543 access = build_outer_field_access (id, decl);
9549 /* Otherwise build what it takes to access the field */
9550 access = build_field_ref ((fs ? NULL_TREE : current_this),
9551 DECL_CONTEXT (decl), name);
9553 access = maybe_build_class_init_for_field (decl, access);
9554 /* We may be asked to save the real field access node */
9557 /* Last check: can we access the field? */
9558 if (not_accessible_p (current_class, decl, NULL_TREE, 0))
9560 not_accessible_field_error (id, decl);
9561 return error_mark_node;
9563 /* And we return what we got */
9566 /* Fall down to error report on undefined variable */
9569 /* 6.5.5.2 Qualified Expression Names */
9574 qualify_ambiguous_name (id);
9575 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
9576 /* 15.10.2: Accessing Superclass Members using super */
9577 return resolve_field_access (id, orig, NULL);
9580 /* We've got an error here */
9581 if (INNER_CLASS_TYPE_P (current_class))
9582 parse_error_context (id,
9583 "Local variable %qs can't be accessed from within the inner class %qs unless it is declared final",
9584 IDENTIFIER_POINTER (name),
9585 IDENTIFIER_POINTER (DECL_NAME
9586 (TYPE_NAME (current_class))));
9588 parse_error_context (id, "Undefined variable %qs",
9589 IDENTIFIER_POINTER (name));
9591 return error_mark_node;
9595 static_ref_err (tree wfl, tree field_id, tree class_type)
9599 "Can't make a static reference to nonstatic variable %qs in class %qs",
9600 IDENTIFIER_POINTER (field_id),
9601 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class_type))));
9604 /* 15.10.1 Field Access Using a Primary and/or Expression Name.
9605 We return something suitable to generate the field access. We also
9606 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
9607 recipient's address can be null. */
9610 resolve_field_access (tree qual_wfl, tree *field_decl, tree *field_type)
9614 tree decl = NULL_TREE, where_found, type_found;
9616 if (resolve_qualified_expression_name (qual_wfl, &decl,
9617 &where_found, &type_found))
9618 return error_mark_node;
9620 /* Resolve the LENGTH field of an array here */
9621 if (DECL_P (decl) && DECL_NAME (decl) == length_identifier_node
9622 && type_found && TYPE_ARRAY_P (type_found)
9623 && ! flag_emit_class_files && ! flag_emit_xref)
9625 tree length = build_java_array_length_access (where_found);
9628 /* In case we're dealing with a static array, we need to
9629 initialize its class before the array length can be fetched.
9630 It's also a good time to create a DECL_RTL for the field if
9631 none already exists, otherwise if the field was declared in a
9632 class found in an external file and hasn't been (and won't
9633 be) accessed for its value, none will be created. */
9634 if (TREE_CODE (where_found) == VAR_DECL && FIELD_STATIC (where_found))
9636 build_static_field_ref (where_found);
9637 field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
9640 /* We might have been trying to resolve field.method(). In which
9641 case, the resolution is over and decl is the answer */
9642 else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
9644 else if (JDECL_P (decl))
9647 type_found = DECL_CONTEXT (decl);
9648 is_static = FIELD_STATIC (decl);
9649 field_ref = build_field_ref ((is_static && !flag_emit_xref?
9650 NULL_TREE : where_found),
9651 type_found, DECL_NAME (decl));
9652 if (field_ref == error_mark_node)
9653 return error_mark_node;
9655 field_ref = maybe_build_class_init_for_field (decl, field_ref);
9657 /* If we're looking at a static field, we may need to generate a
9658 class initialization for it. This can happen when the access
9659 looks like `field.ref', where `field' is a static field in an
9660 interface we implement. */
9661 if (!flag_emit_class_files
9663 && TREE_CODE (where_found) == VAR_DECL
9664 && FIELD_STATIC (where_found))
9666 build_static_field_ref (where_found);
9667 field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
9676 *field_type = (QUAL_DECL_TYPE (decl) ?
9677 QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
9681 /* If NODE is an access to f static field, strip out the class
9682 initialization part and return the field decl, otherwise, return
9686 strip_out_static_field_access_decl (tree node)
9688 if (TREE_CODE (node) == COMPOUND_EXPR)
9690 tree op1 = TREE_OPERAND (node, 1);
9691 if (TREE_CODE (op1) == COMPOUND_EXPR)
9693 tree call = TREE_OPERAND (op1, 0);
9694 if (TREE_CODE (call) == CALL_EXPR
9695 && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
9696 && (TREE_OPERAND (TREE_OPERAND (call, 0), 0)
9697 == soft_initclass_node))
9698 return TREE_OPERAND (op1, 1);
9700 else if (JDECL_P (op1))
9706 /* 6.5.5.2: Qualified Expression Names */
9709 resolve_qualified_expression_name (tree wfl, tree *found_decl,
9710 tree *where_found, tree *type_found)
9712 int from_type = 0; /* Field search initiated from a type */
9713 int from_super = 0, from_cast = 0, from_qualified_this = 0;
9714 int previous_call_static = 0;
9716 tree decl = NULL_TREE, type = NULL_TREE, q;
9717 /* For certain for of inner class instantiation */
9718 tree saved_current, saved_this;
9719 #define RESTORE_THIS_AND_CURRENT_CLASS \
9720 { current_class = saved_current; current_this = saved_this;}
9722 *type_found = *where_found = NULL_TREE;
9724 for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
9726 tree qual_wfl = QUAL_WFL (q);
9727 tree ret_decl; /* for EH checking */
9728 #ifdef USE_MAPPED_LOCATION
9729 source_location location; /* for EH checking */
9731 int location; /* for EH checking */
9734 /* 15.10.1 Field Access Using a Primary */
9735 switch (TREE_CODE (qual_wfl))
9738 case NEW_CLASS_EXPR:
9739 /* If the access to the function call is a non static field,
9740 build the code to access it. */
9741 if (JDECL_P (decl) && !FIELD_STATIC (decl))
9743 decl = maybe_access_field (decl, *where_found,
9744 DECL_CONTEXT (decl));
9745 if (decl == error_mark_node)
9749 /* And code for the function call */
9750 if (complete_function_arguments (qual_wfl))
9753 /* We might have to setup a new current class and a new this
9754 for the search of an inner class, relative to the type of
9755 a expression resolved as `decl'. The current values are
9756 saved and restored shortly after */
9757 saved_current = current_class;
9758 saved_this = current_this;
9760 && (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
9761 || from_qualified_this))
9763 /* If we still have `from_qualified_this', we have the form
9764 <T>.this.f() and we need to build <T>.this */
9765 if (from_qualified_this)
9767 decl = build_access_to_thisn (current_class, type, 0);
9768 decl = java_complete_tree (decl);
9769 type = TREE_TYPE (TREE_TYPE (decl));
9771 current_class = type;
9772 current_this = decl;
9773 from_qualified_this = 0;
9776 if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
9777 CALL_USING_SUPER (qual_wfl) = 1;
9778 #ifdef USE_MAPPED_LOCATION
9779 location = (TREE_CODE (qual_wfl) == CALL_EXPR
9780 ? EXPR_LOCATION (TREE_OPERAND (qual_wfl, 0))
9781 : UNKNOWN_LOCATION);
9783 location = (TREE_CODE (qual_wfl) == CALL_EXPR ?
9784 EXPR_WFL_LINECOL (TREE_OPERAND (qual_wfl, 0)) : 0);
9786 *where_found = patch_method_invocation (qual_wfl, decl, type,
9788 &is_static, &ret_decl);
9790 if (*where_found == error_mark_node)
9792 RESTORE_THIS_AND_CURRENT_CLASS;
9795 *type_found = type = QUAL_DECL_TYPE (*where_found);
9797 *where_found = force_evaluation_order (*where_found);
9799 /* If we're creating an inner class instance, check for that
9800 an enclosing instance is in scope */
9801 if (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
9802 && INNER_ENCLOSING_SCOPE_CHECK (type))
9805 (qual_wfl, "No enclosing instance for inner class %qs is in scope%s",
9806 lang_printable_name (type, 0),
9807 (!current_this ? "" :
9808 "; an explicit one must be provided when creating this inner class"));
9809 RESTORE_THIS_AND_CURRENT_CLASS;
9813 /* In case we had to change then to resolve a inner class
9814 instantiation using a primary qualified by a `new' */
9815 RESTORE_THIS_AND_CURRENT_CLASS;
9817 #ifdef USE_MAPPED_LOCATION
9818 if (location != UNKNOWN_LOCATION)
9823 tree arguments = NULL_TREE;
9824 if (TREE_CODE (qual_wfl) == CALL_EXPR
9825 && TREE_OPERAND (qual_wfl, 1) != NULL_TREE)
9826 arguments = TREE_VALUE (TREE_OPERAND (qual_wfl, 1));
9827 check_thrown_exceptions (location, ret_decl, arguments);
9830 /* If the previous call was static and this one is too,
9831 build a compound expression to hold the two (because in
9832 that case, previous function calls aren't transported as
9833 forcoming function's argument. */
9834 if (previous_call_static && is_static)
9836 /* We must set CAN_COMPLETE_NORMALLY for the first call
9837 since it is done nowhere else. */
9838 CAN_COMPLETE_NORMALLY (decl) = 1;
9839 decl = build2 (COMPOUND_EXPR, TREE_TYPE (*where_found),
9840 decl, *where_found);
9841 TREE_SIDE_EFFECTS (decl) = 1;
9845 previous_call_static = is_static;
9846 decl = *where_found;
9851 case NEW_ARRAY_EXPR:
9852 case NEW_ANONYMOUS_ARRAY_EXPR:
9853 *where_found = decl = java_complete_tree (qual_wfl);
9854 if (decl == error_mark_node)
9856 *type_found = type = QUAL_DECL_TYPE (decl);
9860 *where_found = decl = java_complete_tree (qual_wfl);
9861 if (decl == error_mark_node)
9863 *type_found = type = QUAL_DECL_TYPE (decl);
9867 case CONDITIONAL_EXPR:
9870 *where_found = decl = java_complete_tree (qual_wfl);
9871 if (decl == error_mark_node)
9873 *type_found = type = QUAL_DECL_TYPE (decl);
9877 /* If the access to the function call is a non static field,
9878 build the code to access it. */
9879 if (JDECL_P (decl) && !FIELD_STATIC (decl))
9881 decl = maybe_access_field (decl, *where_found, type);
9882 if (decl == error_mark_node)
9885 /* And code for the array reference expression */
9886 decl = java_complete_tree (qual_wfl);
9887 if (decl == error_mark_node)
9889 type = QUAL_DECL_TYPE (decl);
9893 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
9895 if ((type = patch_string (decl)))
9897 *where_found = QUAL_RESOLUTION (q) = decl;
9898 *type_found = type = TREE_TYPE (decl);
9902 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
9904 *where_found = QUAL_RESOLUTION (q) = decl;
9905 *type_found = type = TREE_TYPE (decl);
9909 /* Fix for -Wall Just go to the next statement. Don't
9914 /* If we fall here, we weren't processing a (static) function call. */
9915 previous_call_static = 0;
9917 /* It can be the keyword THIS */
9918 if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
9919 && EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
9924 (wfl, "Keyword %<this%> used outside allowed context");
9927 if (ctxp->explicit_constructor_p
9928 && type == current_class)
9930 parse_error_context (wfl, "Can't reference %<this%> before the superclass constructor has been called");
9933 /* We have to generate code for intermediate access */
9934 if (!from_type || TREE_TYPE (TREE_TYPE (current_this)) == type)
9936 *where_found = decl = current_this;
9937 *type_found = type = QUAL_DECL_TYPE (decl);
9939 /* We're trying to access the this from somewhere else. Make sure
9940 it's allowed before doing so. */
9943 if (!enclosing_context_p (type, current_class))
9945 char *p = xstrdup (lang_printable_name (type, 0));
9946 parse_error_context (qual_wfl, "Can't use variable %<%s.this%>: type %qs isn't an outer type of type %qs",
9948 lang_printable_name (current_class, 0));
9952 from_qualified_this = 1;
9953 /* If there's nothing else after that, we need to
9954 produce something now, otherwise, the section of the
9955 code that needs to produce <T>.this will generate
9956 what is necessary. */
9957 if (!TREE_CHAIN (q))
9959 decl = build_access_to_thisn (current_class, type, 0);
9960 *where_found = decl = java_complete_tree (decl);
9961 *type_found = type = TREE_TYPE (decl);
9969 /* 15.10.2 Accessing Superclass Members using SUPER */
9970 if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
9971 && EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
9974 /* Check on the restricted use of SUPER */
9975 if (METHOD_STATIC (current_function_decl)
9976 || current_class == object_type_node)
9979 (wfl, "Keyword %<super%> used outside allowed context");
9982 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
9983 node = build_cast (EXPR_WFL_LINECOL (qual_wfl),
9984 CLASSTYPE_SUPER (current_class),
9985 build_this (EXPR_WFL_LINECOL (qual_wfl)));
9986 *where_found = decl = java_complete_tree (node);
9987 if (decl == error_mark_node)
9989 *type_found = type = QUAL_DECL_TYPE (decl);
9990 from_super = from_type = 1;
9994 /* 15.13.1: Can't search for field name in packages, so we
9995 assume a variable/class name was meant. */
9996 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
9999 if ((decl = resolve_package (wfl, &q, &name)))
10002 *where_found = decl;
10004 check_pkg_class_access (DECL_NAME (decl), qual_wfl, true, NULL);
10006 /* We want to be absolutely sure that the class is laid
10007 out. We're going to search something inside it. */
10008 *type_found = type = TREE_TYPE (decl);
10009 layout_class (type);
10012 /* Fix them all the way down, if any are left. */
10015 list = TREE_CHAIN (q);
10018 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (list)) = 0;
10019 list = TREE_CHAIN (list);
10025 if (from_super || from_cast)
10026 parse_error_context
10027 ((from_cast ? qual_wfl : wfl),
10028 "No variable %qs defined in class %qs",
10029 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10030 lang_printable_name (type, 0));
10032 parse_error_context
10033 (qual_wfl, "Undefined variable or class name: %qs",
10034 IDENTIFIER_POINTER (name));
10039 /* We have a type name. It's been already resolved when the
10040 expression was qualified. */
10041 else if (RESOLVE_TYPE_NAME_P (qual_wfl) && QUAL_RESOLUTION (q))
10043 decl = QUAL_RESOLUTION (q);
10045 /* Sneak preview. If next we see a `new', we're facing a
10046 qualification which resulted in a type being selected
10047 instead of a field. Report the error. */
10049 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR)
10051 parse_error_context (qual_wfl, "Undefined variable %qs",
10052 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10056 check_pkg_class_access (DECL_NAME (decl), qual_wfl, true, NULL);
10058 check_deprecation (qual_wfl, decl);
10060 type = TREE_TYPE (decl);
10063 /* We resolve an expression name */
10066 tree field_decl = NULL_TREE;
10068 /* If there exists an early resolution, use it. That occurs
10069 only once and we know that there are more things to
10070 come. Don't do that when processing something after SUPER
10071 (we need more thing to be put in place below */
10072 if (!from_super && QUAL_RESOLUTION (q))
10074 decl = QUAL_RESOLUTION (q);
10077 if (TREE_CODE (decl) == FIELD_DECL && !FIELD_STATIC (decl))
10080 *where_found = current_this;
10083 static_ref_err (qual_wfl, DECL_NAME (decl),
10087 if (outer_field_access_p (current_class, decl))
10088 decl = build_outer_field_access (qual_wfl, decl);
10092 *where_found = TREE_TYPE (decl);
10093 if (TREE_CODE (*where_found) == POINTER_TYPE)
10094 *where_found = TREE_TYPE (*where_found);
10099 /* Report and error if we're using a numerical literal as a
10100 qualifier. It can only be an INTEGER_CST. */
10101 else if (TREE_CODE (qual_wfl) == INTEGER_CST)
10103 parse_error_context
10104 (wfl, "Can't use type %qs as a qualifier",
10105 lang_printable_name (TREE_TYPE (qual_wfl), 0));
10109 /* We have to search for a field, knowing the type of its
10110 container. The flag FROM_TYPE indicates that we resolved
10111 the last member of the expression as a type name, which
10112 means that for the resolution of this field, we'll look
10113 for other errors than if it was resolved as a member of
10118 tree field_decl_type; /* For layout */
10120 if (!from_type && !JREFERENCE_TYPE_P (type))
10122 parse_error_context
10123 (qual_wfl, "Attempt to reference field %qs in %<%s %s%>",
10124 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10125 lang_printable_name (type, 0),
10126 IDENTIFIER_POINTER (DECL_NAME (decl)));
10130 field_decl = lookup_field_wrapper (type,
10131 EXPR_WFL_NODE (qual_wfl));
10133 /* Maybe what we're trying to access to is an inner
10134 class, only if decl is a TYPE_DECL. */
10135 if (!field_decl && TREE_CODE (decl) == TYPE_DECL)
10137 tree ptr, inner_decl;
10139 BUILD_PTR_FROM_NAME (ptr, EXPR_WFL_NODE (qual_wfl));
10140 inner_decl = resolve_class (decl, ptr, NULL_TREE, qual_wfl);
10143 check_inner_class_access (inner_decl, decl, qual_wfl);
10144 type = TREE_TYPE (inner_decl);
10151 if (field_decl == NULL_TREE)
10153 parse_error_context
10154 (qual_wfl, "No variable %qs defined in type %qs",
10155 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10156 GET_TYPE_NAME (type));
10159 if (field_decl == error_mark_node)
10162 /* Layout the type of field_decl, since we may need
10163 it. Don't do primitive types or loaded classes. The
10164 situation of non primitive arrays may not handled
10165 properly here. FIXME */
10166 if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
10167 field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
10169 field_decl_type = TREE_TYPE (field_decl);
10170 if (!JPRIMITIVE_TYPE_P (field_decl_type)
10171 && !CLASS_LOADED_P (field_decl_type)
10172 && !TYPE_ARRAY_P (field_decl_type))
10173 resolve_and_layout (field_decl_type, NULL_TREE);
10175 /* Check on accessibility here */
10176 if (not_accessible_p (current_class, field_decl,
10177 *type_found, from_super))
10178 return not_accessible_field_error (qual_wfl,field_decl);
10179 check_deprecation (qual_wfl, field_decl);
10181 /* There are things to check when fields are accessed
10182 from type. There are no restrictions on a static
10183 declaration of the field when it is accessed from an
10185 is_static = FIELD_STATIC (field_decl);
10186 if (!from_super && from_type
10187 && !TYPE_INTERFACE_P (type)
10189 && (current_function_decl
10190 && METHOD_STATIC (current_function_decl)))
10192 static_ref_err (qual_wfl, EXPR_WFL_NODE (qual_wfl), type);
10195 from_cast = from_super = 0;
10197 /* It's an access from a type but it isn't static, we
10198 make it relative to `this'. */
10199 if (!is_static && from_type)
10200 decl = current_this;
10202 /* If we need to generate something to get a proper
10203 handle on what this field is accessed from, do it
10207 decl = maybe_access_field (decl, *where_found, *type_found);
10208 if (decl == error_mark_node)
10212 /* We want to keep the location were found it, and the type
10214 *where_found = decl;
10215 *type_found = type;
10217 /* Generate the correct expression for field access from
10219 if (from_qualified_this)
10221 field_decl = build_outer_field_access (qual_wfl, field_decl);
10222 from_qualified_this = 0;
10225 /* This is the decl found and eventually the next one to
10230 type = QUAL_DECL_TYPE (decl);
10232 /* Sneak preview. If decl is qualified by a `new', report
10233 the error here to be accurate on the peculiar construct */
10235 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR
10236 && !JREFERENCE_TYPE_P (type))
10238 parse_error_context (qual_wfl, "Attempt to reference field %<new%> in a %qs",
10239 lang_printable_name (type, 0));
10243 /* `q' might have changed due to a after package resolution
10244 re-qualification */
10248 *found_decl = decl;
10252 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
10253 can't be accessed from REFERENCE (a record type). If MEMBER
10254 features a protected access, we then use WHERE which, if non null,
10255 holds the type of MEMBER's access that is checked against
10256 6.6.2.1. This function should be used when decl is a field or a
10260 not_accessible_p (tree reference, tree member, tree where, int from_super)
10262 int access_flag = get_access_flags_from_decl (member);
10263 bool is_static = false;
10265 if (TREE_CODE (member) == FIELD_DECL ||
10266 TREE_CODE (member) == VAR_DECL)
10267 is_static = FIELD_STATIC (member);
10269 is_static = METHOD_STATIC (member);
10271 /* Access always granted for members declared public */
10272 if (access_flag & ACC_PUBLIC)
10275 /* Check access on protected members */
10276 if (access_flag & ACC_PROTECTED)
10278 /* Access granted if it occurs from within the package
10279 containing the class in which the protected member is
10281 if (class_in_current_package (DECL_CONTEXT (member)))
10284 /* If accessed with the form `super.member', then access is granted */
10288 /* If WHERE is active, access was made through a qualifier. For
10289 non-static members, access is granted if the type of the qualifier
10290 is or is a sublass of the type the access is made from (6.6.2.1.) */
10291 if (where && !is_static)
10295 if (inherits_from_p (where, reference))
10297 if (INNER_CLASS_TYPE_P (reference))
10298 reference = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (reference)));
10305 /* Otherwise, access is granted if occurring from within the class
10306 where member is declared, or a subclass of it. */
10309 if (inherits_from_p (reference, DECL_CONTEXT (member)))
10311 if (INNER_CLASS_TYPE_P (reference))
10312 reference = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (reference)));
10319 /* Check access on private members. Access is granted only if it
10320 occurs from within the class in which it is declared -- that does
10321 it for innerclasses too. */
10322 if (access_flag & ACC_PRIVATE)
10324 if (reference == DECL_CONTEXT (member) ||
10325 common_enclosing_context_p (DECL_CONTEXT (member), reference))
10330 /* Default access is permitted only when occurring from within the
10331 package in which the context (MEMBER) is declared. */
10332 return !class_in_current_package (DECL_CONTEXT (member));
10335 /* Test deprecated decl access. */
10337 check_deprecation (tree wfl, tree decl)
10342 if (! warn_deprecated)
10345 /* We want to look at the element type of arrays here, so we strip
10346 all surrounding array types. */
10347 if (TYPE_ARRAY_P (TREE_TYPE (decl)))
10349 elt = TREE_TYPE (decl);
10350 while (TYPE_ARRAY_P (elt))
10351 elt = TYPE_ARRAY_ELEMENT (elt);
10352 /* We'll end up with a pointer type, so we use TREE_TYPE to go
10354 decl = TYPE_NAME (TREE_TYPE (elt));
10356 file = DECL_SOURCE_FILE (decl);
10358 /* Complain if the field is deprecated and the file it was defined
10359 in isn't compiled at the same time the file which contains its
10361 if (DECL_DEPRECATED (decl)
10362 && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
10365 switch (TREE_CODE (decl))
10367 case FUNCTION_DECL:
10375 parse_warning_context (wfl, "The class %qs has been deprecated",
10376 IDENTIFIER_POINTER (DECL_NAME (decl)));
10381 /* Don't issue a message if the context as been deprecated as a
10383 if (! CLASS_DEPRECATED (TYPE_NAME (DECL_CONTEXT (decl))))
10384 parse_warning_context
10385 (wfl, "The %s %qs in class %qs has been deprecated",
10386 the, lang_printable_name (decl, 0),
10387 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
10391 /* Returns 1 if class was declared in the current package, 0 otherwise */
10393 static GTY(()) tree cicp_cache;
10395 class_in_current_package (tree class)
10397 int qualified_flag;
10400 if (cicp_cache == class)
10403 qualified_flag = QUALIFIED_P (DECL_NAME (TYPE_NAME (class)));
10405 /* If the current package is empty and the name of CLASS is
10406 qualified, class isn't in the current package. If there is a
10407 current package and the name of the CLASS is not qualified, class
10408 isn't in the current package */
10409 if ((!ctxp->package && qualified_flag) || (ctxp->package && !qualified_flag))
10412 /* If there is not package and the name of CLASS isn't qualified,
10413 they belong to the same unnamed package */
10414 if (!ctxp->package && !qualified_flag)
10417 /* Compare the left part of the name of CLASS with the package name */
10418 split_qualified_name (&left, NULL, DECL_NAME (TYPE_NAME (class)));
10419 if (ctxp->package == left)
10421 cicp_cache = class;
10427 /* This function may generate code to access DECL from WHERE. This is
10428 done only if certain conditions meet. */
10431 maybe_access_field (tree decl, tree where, tree type)
10433 if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
10434 && !FIELD_STATIC (decl))
10435 decl = build_field_ref (where ? where : current_this,
10436 (type ? type : DECL_CONTEXT (decl)),
10441 /* Build a method invocation, by patching PATCH. If non NULL
10442 and according to the situation, PRIMARY and WHERE may be
10443 used. IS_STATIC is set to 1 if the invoked function is static. */
10446 patch_method_invocation (tree patch, tree primary, tree where, int from_super,
10447 int *is_static, tree *ret_decl)
10449 tree wfl = TREE_OPERAND (patch, 0);
10450 tree args = TREE_OPERAND (patch, 1);
10451 tree name = EXPR_WFL_NODE (wfl);
10453 int is_static_flag = 0;
10454 int is_super_init = 0;
10455 tree this_arg = NULL_TREE;
10456 int is_array_clone_call = 0;
10458 /* Should be overridden if everything goes well. Otherwise, if
10459 something fails, it should keep this value. It stop the
10460 evaluation of a bogus assignment. See java_complete_tree,
10461 MODIFY_EXPR: for the reasons why we sometimes want to keep on
10462 evaluating an assignment */
10463 TREE_TYPE (patch) = error_mark_node;
10465 /* Since lookup functions are messing with line numbers, save the
10467 java_parser_context_save_global ();
10469 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
10471 /* Resolution of qualified name, excluding constructors */
10472 if (QUALIFIED_P (name) && !CALL_CONSTRUCTOR_P (patch))
10474 tree identifier, identifier_wfl, type, resolved;
10475 /* Extract the last IDENTIFIER of the qualified
10476 expression. This is a wfl and we will use it's location
10477 data during error report. */
10478 identifier_wfl = cut_identifier_in_qualified (wfl);
10479 identifier = EXPR_WFL_NODE (identifier_wfl);
10481 /* Given the context, IDENTIFIER is syntactically qualified
10482 as a MethodName. We need to qualify what's before */
10483 qualify_ambiguous_name (wfl);
10484 resolved = resolve_field_access (wfl, NULL, NULL);
10486 if (TREE_CODE (resolved) == VAR_DECL && FIELD_STATIC (resolved)
10487 && FIELD_FINAL (resolved)
10488 && !inherits_from_p (DECL_CONTEXT (resolved), current_class)
10489 && !flag_emit_class_files && !flag_emit_xref)
10490 resolved = build_class_init (DECL_CONTEXT (resolved), resolved);
10492 if (resolved == error_mark_node)
10493 PATCH_METHOD_RETURN_ERROR ();
10495 type = GET_SKIP_TYPE (resolved);
10496 resolve_and_layout (type, NULL_TREE);
10498 if (JPRIMITIVE_TYPE_P (type))
10500 parse_error_context
10502 "Can't invoke a method on primitive type %qs",
10503 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
10504 PATCH_METHOD_RETURN_ERROR ();
10507 list = lookup_method_invoke (0, identifier_wfl, type, identifier, args);
10508 args = nreverse (args);
10510 /* We're resolving a call from a type */
10511 if (TREE_CODE (resolved) == TYPE_DECL)
10513 if (CLASS_INTERFACE (resolved))
10515 parse_error_context
10517 "Can't make static reference to method %qs in interface %qs",
10518 IDENTIFIER_POINTER (identifier),
10519 IDENTIFIER_POINTER (name));
10520 PATCH_METHOD_RETURN_ERROR ();
10522 if (list && !METHOD_STATIC (list))
10524 char *fct_name = xstrdup (lang_printable_name (list, 2));
10525 parse_error_context
10527 "Can't make static reference to method %<%s %s%> in class %qs",
10528 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
10529 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
10531 PATCH_METHOD_RETURN_ERROR ();
10535 this_arg = primary = resolved;
10537 if (TYPE_ARRAY_P (type) && identifier == get_identifier ("clone"))
10538 is_array_clone_call = 1;
10540 /* IDENTIFIER_WFL will be used to report any problem further */
10541 wfl = identifier_wfl;
10543 /* Resolution of simple names, names generated after a primary: or
10547 tree class_to_search = NULL_TREE;
10548 int lc; /* Looking for Constructor */
10550 /* We search constructor in their target class */
10551 if (CALL_CONSTRUCTOR_P (patch))
10553 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10554 class_to_search = EXPR_WFL_NODE (wfl);
10555 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
10556 this_identifier_node)
10557 class_to_search = NULL_TREE;
10558 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
10559 super_identifier_node)
10562 if (CLASSTYPE_SUPER (current_class))
10564 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
10567 parse_error_context (wfl, "Can't invoke super constructor on java.lang.Object");
10568 PATCH_METHOD_RETURN_ERROR ();
10572 /* Class to search is NULL if we're searching the current one */
10573 if (class_to_search)
10575 class_to_search = resolve_and_layout (class_to_search, wfl);
10577 if (!class_to_search)
10579 parse_error_context
10580 (wfl, "Class %qs not found in type declaration",
10581 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10582 PATCH_METHOD_RETURN_ERROR ();
10585 /* Can't instantiate an abstract class, but we can
10586 invoke it's constructor. It's use within the `new'
10587 context is denied here. */
10588 if (CLASS_ABSTRACT (class_to_search)
10589 && TREE_CODE (patch) == NEW_CLASS_EXPR)
10591 parse_error_context
10592 (wfl, "Class %qs is an abstract class. It can't be instantiated",
10593 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10594 PATCH_METHOD_RETURN_ERROR ();
10597 class_to_search = TREE_TYPE (class_to_search);
10600 class_to_search = current_class;
10603 /* This is a regular search in the local class, unless an
10604 alternate class is specified. */
10607 if (where != NULL_TREE)
10608 class_to_search = where;
10609 else if (QUALIFIED_P (name))
10610 class_to_search = current_class;
10613 class_to_search = current_class;
10617 if (has_method (class_to_search, name))
10619 if (! INNER_CLASS_TYPE_P (class_to_search))
10621 parse_error_context (wfl,
10622 "No method named %qs in scope",
10623 IDENTIFIER_POINTER (name));
10624 PATCH_METHOD_RETURN_ERROR ();
10627 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_to_search)));
10633 /* NAME is a simple identifier or comes from a primary. Search
10634 in the class whose declaration contain the method being
10636 resolve_and_layout (class_to_search, NULL_TREE);
10638 list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
10639 /* Don't continue if no method were found, as the next statement
10640 can't be executed then. */
10642 PATCH_METHOD_RETURN_ERROR ();
10644 if (TYPE_ARRAY_P (class_to_search)
10645 && DECL_NAME (list) == get_identifier ("clone"))
10646 is_array_clone_call = 1;
10648 /* Check for static reference if non static methods */
10649 if (check_for_static_method_reference (wfl, patch, list,
10650 class_to_search, primary))
10651 PATCH_METHOD_RETURN_ERROR ();
10653 /* Check for inner classes creation from illegal contexts */
10654 if (lc && (INNER_CLASS_TYPE_P (class_to_search)
10655 && !CLASS_STATIC (TYPE_NAME (class_to_search)))
10656 && INNER_ENCLOSING_SCOPE_CHECK (class_to_search)
10657 && !DECL_INIT_P (current_function_decl))
10659 parse_error_context
10660 (wfl, "No enclosing instance for inner class %qs is in scope%s",
10661 lang_printable_name (class_to_search, 0),
10662 (!current_this ? "" :
10663 "; an explicit one must be provided when creating this inner class"));
10664 PATCH_METHOD_RETURN_ERROR ();
10667 /* Non static methods are called with the current object extra
10668 argument. If patch a `new TYPE()', the argument is the value
10669 returned by the object allocator. If method is resolved as a
10670 primary, use the primary otherwise use the current THIS. */
10671 args = nreverse (args);
10672 if (TREE_CODE (patch) != NEW_CLASS_EXPR)
10674 this_arg = primary ? primary : current_this;
10676 /* If we're using an access method, things are different.
10677 There are two family of cases:
10679 1) We're not generating bytecodes:
10681 - LIST is non static. It's invocation is transformed from
10682 x(a1,...,an) into this$<n>.x(a1,....an).
10683 - LIST is static. It's invocation is transformed from
10684 x(a1,...,an) into TYPE_OF(this$<n>).x(a1,....an)
10686 2) We're generating bytecodes:
10688 - LIST is non static. It's invocation is transformed from
10689 x(a1,....,an) into access$<n>(this$<n>,a1,...,an).
10690 - LIST is static. It's invocation is transformed from
10691 x(a1,....,an) into TYPE_OF(this$<n>).x(a1,....an).
10693 Of course, this$<n> can be arbitrarily complex, ranging from
10694 this$0 (the immediate outer context) to
10695 access$0(access$0(...(this$0))).
10697 maybe_use_access_method returns a nonzero value if the
10698 this_arg has to be moved into the (then generated) stub
10699 argument list. In the meantime, the selected function
10700 might have be replaced by a generated stub. */
10702 maybe_use_access_method (is_super_init, &list, &this_arg))
10704 args = tree_cons (NULL_TREE, this_arg, args);
10705 this_arg = NULL_TREE; /* So it doesn't get chained twice */
10710 /* Merge point of all resolution schemes. If we have nothing, this
10711 is an error, already signaled */
10713 PATCH_METHOD_RETURN_ERROR ();
10715 /* Check accessibility, position the is_static flag, build and
10717 if (not_accessible_p (DECL_CONTEXT (current_function_decl), list,
10718 (primary ? TREE_TYPE (TREE_TYPE (primary)) :
10719 NULL_TREE), from_super)
10720 /* Calls to clone() on array types are permitted as a special-case. */
10721 && !is_array_clone_call)
10723 const char *const fct_name = IDENTIFIER_POINTER (DECL_NAME (list));
10724 const char *const access =
10725 accessibility_string (get_access_flags_from_decl (list));
10726 const char *const klass =
10727 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list))));
10728 const char *const refklass =
10729 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class)));
10730 const char *const what = (DECL_CONSTRUCTOR_P (list)
10731 ? "constructor" : "method");
10732 parse_error_context (wfl,
10733 "Can't access %s %s %<%s.%s%> from %qs",
10734 access, what, klass, fct_name, refklass);
10735 PATCH_METHOD_RETURN_ERROR ();
10738 /* Deprecation check: check whether the method being invoked or the
10739 instance-being-created's type are deprecated. */
10740 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10741 check_deprecation (wfl, TYPE_NAME (DECL_CONTEXT (list)));
10742 check_deprecation (wfl, list);
10744 /* If invoking a innerclass constructor, there are hidden parameters
10746 if (TREE_CODE (patch) == NEW_CLASS_EXPR
10747 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
10749 /* And make sure we add the accessed local variables to be saved
10750 in field aliases. */
10751 args = build_alias_initializer_parameter_list
10752 (AIPL_FUNCTION_CTOR_INVOCATION, DECL_CONTEXT (list), args, NULL);
10754 /* Secretly pass the current_this/primary as a second argument */
10755 if (primary || current_this)
10758 tree this_type = (current_this ?
10759 TREE_TYPE (TREE_TYPE (current_this)) : NULL_TREE);
10760 /* Method's (list) enclosing context */
10761 tree mec = DECL_CONTEXT (TYPE_NAME (DECL_CONTEXT (list)));
10762 /* If we have a primary, use it. */
10764 extra_arg = primary;
10765 /* The current `this' is an inner class but isn't a direct
10766 enclosing context for the inner class we're trying to
10767 create. Build an access to the proper enclosing context
10769 else if (current_this && PURE_INNER_CLASS_TYPE_P (this_type)
10770 && this_type != TREE_TYPE (mec))
10773 extra_arg = build_access_to_thisn (current_class,
10774 TREE_TYPE (mec), 0);
10775 extra_arg = java_complete_tree (extra_arg);
10777 /* Otherwise, just use the current `this' as an enclosing
10780 extra_arg = current_this;
10781 args = tree_cons (NULL_TREE, extra_arg, args);
10784 args = tree_cons (NULL_TREE, integer_zero_node, args);
10787 /* This handles the situation where a constructor invocation needs
10788 to have an enclosing context passed as a second parameter (the
10789 constructor is one of an inner class). */
10790 if ((is_super_init ||
10791 (TREE_CODE (patch) == CALL_EXPR && name == this_identifier_node))
10792 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
10794 tree dest = TYPE_NAME (DECL_CONTEXT (list));
10796 build_access_to_thisn (current_class, DECL_CONTEXT (dest), 0);
10797 extra_arg = java_complete_tree (extra_arg);
10798 args = tree_cons (NULL_TREE, extra_arg, args);
10801 is_static_flag = METHOD_STATIC (list);
10802 if (! is_static_flag && this_arg != NULL_TREE)
10803 args = tree_cons (NULL_TREE, this_arg, args);
10805 /* In the context of an explicit constructor invocation, we can't
10806 invoke any method relying on `this'. Exceptions are: we're
10807 invoking a static function, primary exists and is not the current
10808 this, we're creating a new object. */
10809 if (ctxp->explicit_constructor_p
10811 && (!primary || primary == current_this)
10812 && (TREE_CODE (patch) != NEW_CLASS_EXPR))
10814 parse_error_context (wfl, "Can't reference %<this%> before the superclass constructor has been called");
10815 PATCH_METHOD_RETURN_ERROR ();
10817 java_parser_context_restore_global ();
10819 *is_static = is_static_flag;
10820 /* Sometimes, we want the decl of the selected method. Such as for
10824 patch = patch_invoke (patch, list, args);
10826 /* Now is a good time to insert the call to finit$ */
10827 if (is_super_init && CLASS_HAS_FINIT_P (current_class))
10829 tree finit_parms, finit_call;
10831 /* Prepare to pass hidden parameters to finit$, if any. */
10832 finit_parms = build_alias_initializer_parameter_list
10833 (AIPL_FUNCTION_FINIT_INVOCATION, current_class, NULL_TREE, NULL);
10836 build_method_invocation (build_wfl_node (finit_identifier_node),
10839 /* Generate the code used to initialize fields declared with an
10840 initialization statement and build a compound statement along
10841 with the super constructor invocation. */
10842 CAN_COMPLETE_NORMALLY (patch) = 1;
10843 patch = build2 (COMPOUND_EXPR, void_type_node, patch,
10844 java_complete_tree (finit_call));
10849 /* Check that we're not trying to do a static reference to a method in
10850 non static method. Return 1 if it's the case, 0 otherwise. */
10853 check_for_static_method_reference (tree wfl, tree node, tree method,
10854 tree where, tree primary)
10856 if (METHOD_STATIC (current_function_decl)
10857 && !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
10859 char *fct_name = xstrdup (lang_printable_name (method, 0));
10860 parse_error_context
10861 (wfl, "Can't make static reference to method %<%s %s%> in class %qs",
10862 lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
10863 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (where))));
10870 /* Fix the invocation of *MDECL if necessary in the case of a
10871 invocation from an inner class. *THIS_ARG might be modified
10872 appropriately and an alternative access to *MDECL might be
10876 maybe_use_access_method (int is_super_init, tree *mdecl, tree *this_arg)
10879 tree md = *mdecl, ta = *this_arg;
10881 int non_static_context = !METHOD_STATIC (md);
10884 || DECL_CONTEXT (md) == current_class
10885 || !PURE_INNER_CLASS_TYPE_P (current_class)
10886 || DECL_FINIT_P (md)
10887 || DECL_INSTINIT_P (md))
10890 /* If we're calling a method found in an enclosing class, generate
10891 what it takes to retrieve the right this. Don't do that if we're
10892 invoking a static method. Note that if MD's type is unrelated to
10893 CURRENT_CLASS, then the current this can be used. */
10895 if (non_static_context && DECL_CONTEXT (md) != object_type_node)
10897 ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
10898 if (inherits_from_p (ctx, DECL_CONTEXT (md)))
10900 ta = build_current_thisn (current_class);
10901 ta = build_wfl_node (ta);
10908 maybe_build_thisn_access_method (type);
10909 if (inherits_from_p (type, DECL_CONTEXT (md)))
10911 ta = build_access_to_thisn (ctx, type, 0);
10914 type = (DECL_CONTEXT (TYPE_NAME (type)) ?
10915 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))) : NULL_TREE);
10918 ta = java_complete_tree (ta);
10921 /* We might have to use an access method to get to MD. We can
10922 break the method access rule as far as we're not generating
10924 if (METHOD_PRIVATE (md) && flag_emit_class_files)
10926 md = build_outer_method_access_method (md);
10933 /* Returning a nonzero value indicates we were doing a non static
10934 method invocation that is now a static invocation. It will have
10935 callee displace `this' to insert it in the regular argument
10937 return (non_static_context && to_return);
10940 /* Patch an invoke expression METHOD and ARGS, based on its invocation
10944 patch_invoke (tree patch, tree method, tree args)
10947 tree original_call, t, ta;
10948 tree check = NULL_TREE;
10950 /* Last step for args: convert build-in types. If we're dealing with
10951 a new TYPE() type call, the first argument to the constructor
10952 isn't found in the incoming argument list, but delivered by
10954 t = TYPE_ARG_TYPES (TREE_TYPE (method));
10955 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10956 t = TREE_CHAIN (t);
10957 for (ta = args; t != end_params_node && ta;
10958 t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
10959 if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
10960 TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
10961 TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
10963 /* Resolve unresolved returned type issues */
10964 t = TREE_TYPE (TREE_TYPE (method));
10965 if (TREE_CODE (t) == POINTER_TYPE && !CLASS_LOADED_P (TREE_TYPE (t)))
10966 resolve_and_layout (TREE_TYPE (t), NULL);
10968 if (flag_emit_class_files || flag_emit_xref)
10972 switch (invocation_mode (method, CALL_USING_SUPER (patch)))
10974 case INVOKE_VIRTUAL:
10975 dtable = invoke_build_dtable (0, args);
10976 func = build_invokevirtual (dtable, method);
10979 case INVOKE_NONVIRTUAL:
10980 /* If the object for the method call is null, we throw an
10981 exception. We don't do this if the object is the current
10982 method's `this'. In other cases we just rely on an
10983 optimization pass to eliminate redundant checks. */
10984 if (TREE_VALUE (args) != current_this)
10986 /* We use a save_expr here to make sure we only evaluate
10987 the new `self' expression once. */
10988 tree save_arg = save_expr (TREE_VALUE (args));
10989 TREE_VALUE (args) = save_arg;
10990 check = java_check_reference (save_arg, 1);
10992 /* Fall through. */
10995 case INVOKE_STATIC:
10997 tree signature = build_java_signature (TREE_TYPE (method));
10998 func = build_known_method_ref (method, TREE_TYPE (method),
10999 DECL_CONTEXT (method),
11004 case INVOKE_INTERFACE:
11005 dtable = invoke_build_dtable (1, args);
11006 func = build_invokeinterface (dtable, method);
11013 /* Ensure self_type is initialized, (invokestatic). FIXME */
11014 func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
11017 TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
11018 TREE_OPERAND (patch, 0) = func;
11019 TREE_OPERAND (patch, 1) = args;
11020 patch = check_for_builtin (method, patch);
11021 original_call = patch;
11023 /* We're processing a `new TYPE ()' form. New is called and its
11024 returned value is the first argument to the constructor. We build
11025 a COMPOUND_EXPR and use saved expression so that the overall NEW
11026 expression value is a pointer to a newly created and initialized
11028 if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
11030 tree class = DECL_CONTEXT (method);
11031 tree c1, saved_new, new;
11034 if (flag_emit_class_files || flag_emit_xref)
11036 TREE_TYPE (patch) = build_pointer_type (class);
11039 if (!TYPE_SIZE (class))
11040 safe_layout_class (class);
11042 (class_has_finalize_method (class) ? alloc_object_node
11043 : alloc_no_finalizer_node);
11044 new = build3 (CALL_EXPR, promote_type (class),
11045 build_address_of (alloc_node),
11046 build_tree_list (NULL_TREE, build_class_ref (class)),
11048 saved_new = save_expr (new);
11049 c1 = build_tree_list (NULL_TREE, saved_new);
11050 TREE_CHAIN (c1) = TREE_OPERAND (original_call, 1);
11051 TREE_OPERAND (original_call, 1) = c1;
11052 TREE_SET_CODE (original_call, CALL_EXPR);
11053 patch = build2 (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new);
11056 /* If CHECK is set, then we are building a check to see if the object
11058 if (check != NULL_TREE)
11060 /* We have to call force_evaluation_order now because creating a
11061 COMPOUND_EXPR wraps the arg list in a way that makes it
11062 unrecognizable by force_evaluation_order later. Yuk. */
11063 patch = build2 (COMPOUND_EXPR, TREE_TYPE (patch), check,
11064 force_evaluation_order (patch));
11065 TREE_SIDE_EFFECTS (patch) = 1;
11068 /* In order to be able to modify PATCH later, we SAVE_EXPR it and
11069 put it as the first expression of a COMPOUND_EXPR. The second
11070 expression being an empty statement to be later patched if
11071 necessary. We remember a TREE_LIST (the PURPOSE is the method,
11072 the VALUE is the compound) in a hashtable and return a
11073 COMPOUND_EXPR built so that the result of the evaluation of the
11074 original PATCH node is returned. */
11075 if (STATIC_CLASS_INIT_OPT_P ()
11076 && current_function_decl && METHOD_STATIC (method))
11079 tree fndecl = current_function_decl;
11080 /* We have to call force_evaluation_order now because creating a
11081 COMPOUND_EXPR wraps the arg list in a way that makes it
11082 unrecognizable by force_evaluation_order later. Yuk. */
11083 tree save = force_evaluation_order (patch);
11084 tree type = TREE_TYPE (patch);
11086 patch = build2 (COMPOUND_EXPR, type, save, build_java_empty_stmt ());
11087 list = tree_cons (method, patch,
11088 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl));
11090 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl) = list;
11092 patch = build2 (COMPOUND_EXPR, type, patch, save);
11099 invocation_mode (tree method, int super)
11101 int access = get_access_flags_from_decl (method);
11104 return INVOKE_SUPER;
11106 if (access & ACC_STATIC)
11107 return INVOKE_STATIC;
11109 /* We have to look for a constructor before we handle nonvirtual
11110 calls; otherwise the constructor will look nonvirtual. */
11111 if (DECL_CONSTRUCTOR_P (method))
11112 return INVOKE_STATIC;
11114 if (access & ACC_PRIVATE)
11115 return INVOKE_NONVIRTUAL;
11117 /* Binary compatibility: just because it's final today, that doesn't
11118 mean it'll be final tomorrow. */
11119 if (! flag_indirect_dispatch
11120 || DECL_CONTEXT (method) == object_type_node)
11122 if (access & ACC_FINAL)
11123 return INVOKE_NONVIRTUAL;
11125 if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
11126 return INVOKE_NONVIRTUAL;
11129 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
11130 return INVOKE_INTERFACE;
11132 return INVOKE_VIRTUAL;
11135 /* Retrieve a refined list of matching methods. It covers the step
11136 15.11.2 (Compile-Time Step 2) */
11139 lookup_method_invoke (int lc, tree cl, tree class, tree name, tree arg_list)
11141 tree atl = end_params_node; /* Arg Type List */
11142 tree method, signature, list, node;
11143 const char *candidates; /* Used for error report */
11146 /* Fix the arguments */
11147 for (node = arg_list; node; node = TREE_CHAIN (node))
11149 tree current_arg = TREE_TYPE (TREE_VALUE (node));
11150 /* Non primitive type may have to be resolved */
11151 if (!JPRIMITIVE_TYPE_P (current_arg))
11152 resolve_and_layout (current_arg, NULL_TREE);
11154 if (TREE_CODE (current_arg) == RECORD_TYPE)
11155 current_arg = promote_type (current_arg);
11156 atl = tree_cons (NULL_TREE, current_arg, atl);
11159 /* Presto. If we're dealing with an anonymous class and a
11160 constructor call, generate the right constructor now, since we
11161 know the arguments' types. */
11163 if (lc && ANONYMOUS_CLASS_P (class))
11165 tree mdecl = craft_constructor (TYPE_NAME (class), atl);
11166 /* The anonymous class may have already been laid out, so make sure
11167 the new constructor is laid out here. */
11168 layout_class_method (class, CLASSTYPE_SUPER (class), mdecl, NULL_TREE);
11171 /* Find all candidates and then refine the list, searching for the
11172 most specific method. */
11173 list = find_applicable_accessible_methods_list (lc, class, name, atl);
11174 list = find_most_specific_methods_list (list);
11175 if (list && !TREE_CHAIN (list))
11176 return TREE_VALUE (list);
11178 /* Issue an error. List candidates if any. Candidates are listed
11179 only if accessible (non accessible methods may end-up here for
11180 the sake of a better error report). */
11185 obstack_grow (&temporary_obstack, ". Candidates are:\n", 18);
11186 for (current = list; current; current = TREE_CHAIN (current))
11188 tree cm = TREE_VALUE (current);
11189 char string [4096];
11190 if (!cm || not_accessible_p (class, cm, NULL_TREE, 0))
11193 (string, " '%s' in '%s'%s",
11194 get_printable_method_name (cm),
11195 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
11196 (TREE_CHAIN (current) ? "\n" : ""));
11197 obstack_grow (&temporary_obstack, string, strlen (string));
11199 obstack_1grow (&temporary_obstack, '\0');
11200 candidates = obstack_finish (&temporary_obstack);
11202 /* Issue the error message */
11203 method = make_node (FUNCTION_TYPE);
11204 TYPE_ARG_TYPES (method) = atl;
11205 signature = build_java_argument_signature (method);
11206 dup = xstrdup (lang_printable_name (class, 0));
11207 parse_error_context (cl, "Can't find %s %<%s(%s)%> in type %qs%s",
11208 (lc ? "constructor" : "method"),
11209 (lc ? dup : IDENTIFIER_POINTER (name)),
11210 IDENTIFIER_POINTER (signature), dup,
11211 (candidates ? candidates : ""));
11216 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
11217 when we're looking for a constructor. */
11220 find_applicable_accessible_methods_list (int lc, tree class, tree name,
11223 static htab_t searched_classes;
11224 static int search_not_done = 0;
11225 tree list = NULL_TREE, all_list = NULL_TREE;
11229 /* Check the hash table to determine if this class has been searched
11231 if (searched_classes)
11233 if (htab_find (searched_classes, class) != NULL)
11238 searched_classes = htab_create (10, htab_hash_pointer,
11239 htab_eq_pointer, NULL);
11243 *htab_find_slot (searched_classes, class, INSERT) = class;
11245 if (!CLASS_LOADED_P (class))
11247 load_class (class, 1);
11248 safe_layout_class (class);
11251 /* Search interfaces */
11252 if (TREE_CODE (TYPE_NAME (class)) == TYPE_DECL
11253 && CLASS_INTERFACE (TYPE_NAME (class)))
11255 search_applicable_methods_list (lc, TYPE_METHODS (class),
11256 name, arglist, &list, &all_list);
11257 for (i = 1; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
11259 tree t = BINFO_TYPE (base_binfo);
11262 rlist = find_applicable_accessible_methods_list (lc, t, name,
11264 list = chainon (rlist, list);
11267 /* Search classes */
11270 search_applicable_methods_list (lc, TYPE_METHODS (class),
11271 name, arglist, &list, &all_list);
11273 /* When looking finit$, class$ or instinit$, we turn LC to 1 so
11274 that we only search in class. Note that we should have found
11275 something at this point. */
11276 if (ID_FINIT_P (name) || ID_CLASSDOLLAR_P (name) || ID_INSTINIT_P (name))
11283 /* We must search all interfaces of this class */
11287 BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
11289 tree t = BINFO_TYPE (base_binfo);
11290 if (t != object_type_node)
11293 = find_applicable_accessible_methods_list (lc, t,
11295 list = chainon (rlist, list);
11300 /* Search superclass */
11301 if (!lc && CLASSTYPE_SUPER (class) != NULL_TREE)
11304 class = CLASSTYPE_SUPER (class);
11305 rlist = find_applicable_accessible_methods_list (lc, class,
11307 list = chainon (rlist, list);
11313 /* We're done. Reset the searched classes list and finally search
11314 java.lang.Object if it wasn't searched already. */
11315 if (!search_not_done)
11318 && TYPE_METHODS (object_type_node)
11319 && htab_find (searched_classes, object_type_node) == NULL)
11321 search_applicable_methods_list (lc,
11322 TYPE_METHODS (object_type_node),
11323 name, arglist, &list, &all_list);
11325 htab_delete (searched_classes);
11326 searched_classes = NULL;
11329 /* Either return the list obtained or all selected (but
11330 inaccessible) methods for better error report. */
11331 return (!list ? all_list : list);
11334 /* Effectively search for the appropriate method in method */
11337 search_applicable_methods_list (int lc, tree method, tree name, tree arglist,
11338 tree *list, tree *all_list)
11340 for (; method; method = TREE_CHAIN (method))
11342 /* When dealing with constructor, stop here, otherwise search
11344 if (lc && !DECL_CONSTRUCTOR_P (method))
11346 else if (!lc && (DECL_CONSTRUCTOR_P (method)
11347 || (DECL_NAME (method) != name)))
11350 if (argument_types_convertible (method, arglist))
11352 /* Retain accessible methods only */
11353 if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
11354 method, NULL_TREE, 0))
11355 *list = tree_cons (NULL_TREE, method, *list);
11357 /* Also retain all selected method here */
11358 *all_list = tree_cons (NULL_TREE, method, *list);
11363 /* 15.11.2.2 Choose the Most Specific Method */
11366 find_most_specific_methods_list (tree list)
11369 int abstract, candidates;
11370 tree current, new_list = NULL_TREE;
11371 for (current = list; current; current = TREE_CHAIN (current))
11374 DECL_SPECIFIC_COUNT (TREE_VALUE (current)) = 0;
11376 for (method = list; method; method = TREE_CHAIN (method))
11378 tree method_v, current_v;
11379 /* Don't test a method against itself */
11380 if (method == current)
11383 method_v = TREE_VALUE (method);
11384 current_v = TREE_VALUE (current);
11386 /* Compare arguments and location where methods where declared */
11387 if (argument_types_convertible (method_v, current_v))
11389 if (valid_method_invocation_conversion_p
11390 (DECL_CONTEXT (method_v), DECL_CONTEXT (current_v))
11391 || (INNER_CLASS_TYPE_P (DECL_CONTEXT (current_v))
11392 && enclosing_context_p (DECL_CONTEXT (method_v),
11393 DECL_CONTEXT (current_v))))
11395 int v = (DECL_SPECIFIC_COUNT (current_v) +=
11396 (INNER_CLASS_TYPE_P (DECL_CONTEXT (current_v)) ? 2 : 1));
11397 max = (v > max ? v : max);
11403 /* Review the list and select the maximally specific methods */
11404 for (current = list, abstract = -1, candidates = -1;
11405 current; current = TREE_CHAIN (current))
11406 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
11408 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
11409 abstract += (METHOD_ABSTRACT (TREE_VALUE (current)) ? 1 : 0);
11413 /* If we have several and they're all abstract, just pick the
11415 if (candidates > 0 && candidates == abstract)
11417 /* FIXME: merge the throws clauses. There is no convenient way
11418 to do this in gcj right now, since ideally we'd like to
11419 introduce a new METHOD_DECL here, but that is really not
11421 new_list = nreverse (new_list);
11422 TREE_CHAIN (new_list) = NULL_TREE;
11426 /* We have several (we couldn't find a most specific), all but one
11427 are abstract, we pick the only non abstract one. */
11428 if (candidates > 0 && (candidates == abstract+1))
11430 for (current = new_list; current; current = TREE_CHAIN (current))
11431 if (!METHOD_ABSTRACT (TREE_VALUE (current)))
11433 TREE_CHAIN (current) = NULL_TREE;
11434 new_list = current;
11438 /* If we can't find one, lower expectations and try to gather multiple
11439 maximally specific methods */
11440 while (!new_list && max)
11444 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
11445 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
11452 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
11453 converted by method invocation conversion (5.3) to the type of the
11454 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
11455 to change less often than M1. */
11457 static GTY(()) tree m2_arg_value;
11458 static GTY(()) tree m2_arg_cache;
11461 argument_types_convertible (tree m1, tree m2_or_arglist)
11463 tree m1_arg, m2_arg;
11465 SKIP_THIS_AND_ARTIFICIAL_PARMS (m1_arg, m1)
11467 if (m2_arg_value == m2_or_arglist)
11468 m2_arg = m2_arg_cache;
11471 /* M2_OR_ARGLIST can be a function DECL or a raw list of
11473 if (m2_or_arglist && TREE_CODE (m2_or_arglist) == FUNCTION_DECL)
11475 m2_arg = TYPE_ARG_TYPES (TREE_TYPE (m2_or_arglist));
11476 if (!METHOD_STATIC (m2_or_arglist))
11477 m2_arg = TREE_CHAIN (m2_arg);
11480 m2_arg = m2_or_arglist;
11482 m2_arg_value = m2_or_arglist;
11483 m2_arg_cache = m2_arg;
11486 while (m1_arg != end_params_node && m2_arg != end_params_node)
11488 resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
11489 if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
11490 TREE_VALUE (m2_arg)))
11492 m1_arg = TREE_CHAIN (m1_arg);
11493 m2_arg = TREE_CHAIN (m2_arg);
11495 return m1_arg == end_params_node && m2_arg == end_params_node;
11498 /* Qualification routines */
11500 /* Given a name x.y.z, look up x locally. If it's found, save the
11501 decl. If it's not found, mark the name as RESOLVE_PACKAGE_NAME_P,
11502 so that we later try and load the appropriate classes. */
11504 qualify_ambiguous_name (tree id)
11508 /* We inspect the first item of the qualification list. As a sanity
11509 check, make sure that it is an identfier node. */
11510 tree qual = EXPR_WFL_QUALIFICATION (id);
11511 tree qual_wfl = QUAL_WFL (qual);
11513 if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
11516 name = EXPR_WFL_NODE (qual_wfl);
11518 /* If we don't have an identifier, or we have a 'this' or 'super',
11519 then field access processing is all we need : there is nothing
11521 if (!name || TREE_CODE (name) != IDENTIFIER_NODE ||
11522 name == this_identifier_node ||
11523 name == super_identifier_node)
11526 /* If name appears within the scope of a local variable declaration
11527 or parameter declaration, or is a field within an enclosing
11528 class, then it is an expression name. Save the decl and let
11529 resolve_field_access do it's work. */
11530 if ((decl = IDENTIFIER_LOCAL_VALUE (name)) ||
11531 (decl = lookup_field_wrapper (current_class, name)))
11533 QUAL_RESOLUTION (qual) = decl;
11537 /* If name is a known class name (either declared or imported), mark
11538 us as a type name. */
11539 if ((decl = resolve_and_layout (name, NULL_TREE)))
11541 RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
11542 QUAL_RESOLUTION (qual) = decl;
11545 /* Check here that NAME isn't declared by more than one
11546 type-import-on-demand declaration of the compilation unit
11547 containing NAME. FIXME */
11549 /* We couldn't find a declaration for the name. Assume for now that
11550 we have a qualified class name that needs to be loaded from an
11551 external class file. */
11553 RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
11555 /* Propagate the qualification across other components of the
11557 for (qual = TREE_CHAIN (qual); qual;
11558 qual_wfl = QUAL_WFL (qual), qual = TREE_CHAIN (qual))
11560 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
11561 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
11564 /* Store the global qualification for the ambiguous part of ID back
11566 if (RESOLVE_TYPE_NAME_P (qual_wfl))
11567 RESOLVE_TYPE_NAME_P (id) = 1;
11568 else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
11569 RESOLVE_PACKAGE_NAME_P (id) = 1;
11572 /* Patch tree nodes in a function body. When a BLOCK is found, push
11573 local variable decls if present.
11574 Same as java_complete_lhs, but does resolve static finals to values. */
11577 java_complete_tree (tree node)
11579 node = java_complete_lhs (node);
11580 if (JDECL_P (node) && CLASS_FINAL_VARIABLE_P (node)
11581 && DECL_INITIAL (node) != NULL_TREE
11582 && !flag_emit_xref)
11584 tree value = fold_constant_for_init (node, node);
11585 if (value != NULL_TREE)
11592 java_stabilize_reference (tree node)
11594 if (TREE_CODE (node) == COMPOUND_EXPR)
11596 tree op0 = TREE_OPERAND (node, 0);
11597 tree op1 = TREE_OPERAND (node, 1);
11598 TREE_OPERAND (node, 0) = save_expr (op0);
11599 TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
11602 return stabilize_reference (node);
11605 /* Patch tree nodes in a function body. When a BLOCK is found, push
11606 local variable decls if present.
11607 Same as java_complete_tree, but does not resolve static finals to values. */
11610 java_complete_lhs (tree node)
11612 tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
11615 /* CONVERT_EXPR always has its type set, even though it needs to be
11617 if (TREE_TYPE (node) && TREE_CODE (node) != CONVERT_EXPR)
11620 /* The switch block implements cases processing container nodes
11621 first. Contained nodes are always written back. Leaves come
11622 next and return a value. */
11623 switch (TREE_CODE (node))
11627 /* 1- Block section.
11628 Set the local values on decl names so we can identify them
11629 faster when they're referenced. At that stage, identifiers
11630 are legal so we don't check for declaration errors. */
11631 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
11633 DECL_CONTEXT (cn) = current_function_decl;
11634 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
11636 if (BLOCK_EXPR_BODY (node) == NULL_TREE)
11637 CAN_COMPLETE_NORMALLY (node) = 1;
11640 tree stmt = BLOCK_EXPR_BODY (node);
11642 int error_seen = 0;
11643 if (TREE_CODE (stmt) == COMPOUND_EXPR)
11645 /* Re-order from (((A; B); C); ...; Z) to
11646 (A; (B; (C ; (...; Z)))).
11647 This makes it easier to scan the statements left-to-right
11648 without using recursion (which might overflow the stack
11649 if the block has many statements. */
11652 tree left = TREE_OPERAND (stmt, 0);
11653 if (TREE_CODE (left) != COMPOUND_EXPR)
11655 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
11656 TREE_OPERAND (left, 1) = stmt;
11659 BLOCK_EXPR_BODY (node) = stmt;
11662 /* Now do the actual complete, without deep recursion for
11664 ptr = &BLOCK_EXPR_BODY (node);
11665 while (TREE_CODE (*ptr) == COMPOUND_EXPR
11666 && !IS_EMPTY_STMT (TREE_OPERAND (*ptr, 1)))
11668 tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
11669 tree *next = &TREE_OPERAND (*ptr, 1);
11670 TREE_OPERAND (*ptr, 0) = cur;
11671 if (IS_EMPTY_STMT (cur))
11673 /* Optimization; makes it easier to detect empty bodies.
11674 Most useful for <clinit> with all-constant initializer. */
11678 if (TREE_CODE (cur) == ERROR_MARK)
11680 else if (! CAN_COMPLETE_NORMALLY (cur))
11685 if (TREE_CODE (wfl_op2) == BLOCK)
11686 wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
11687 else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
11688 wfl_op2 = TREE_OPERAND (wfl_op2, 0);
11692 if (TREE_CODE (wfl_op2) != CASE_EXPR
11693 && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
11694 unreachable_stmt_error (*ptr);
11696 if (TREE_TYPE (*ptr) == NULL_TREE)
11697 TREE_TYPE (*ptr) = void_type_node;
11700 *ptr = java_complete_tree (*ptr);
11702 if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
11703 return error_mark_node;
11704 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
11706 /* Turn local bindings to null */
11707 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
11708 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = NULL_TREE;
11710 TREE_TYPE (node) = void_type_node;
11713 /* 2- They are expressions but ultimately deal with statements */
11716 wfl_op1 = TREE_OPERAND (node, 0);
11717 COMPLETE_CHECK_OP_0 (node);
11718 /* 14.19 A throw statement cannot complete normally. */
11719 CAN_COMPLETE_NORMALLY (node) = 0;
11720 return patch_throw_statement (node, wfl_op1);
11722 case SYNCHRONIZED_EXPR:
11723 wfl_op1 = TREE_OPERAND (node, 0);
11724 return patch_synchronized_statement (node, wfl_op1);
11727 return patch_try_statement (node);
11729 case TRY_FINALLY_EXPR:
11730 COMPLETE_CHECK_OP_0 (node);
11731 COMPLETE_CHECK_OP_1 (node);
11732 if (IS_EMPTY_STMT (TREE_OPERAND (node, 0)))
11733 /* Reduce try/finally nodes with an empty try block. */
11734 return TREE_OPERAND (node, 1);
11735 if (IS_EMPTY_STMT (TREE_OPERAND (node, 1)))
11736 /* Likewise for an empty finally block. */
11737 return TREE_OPERAND (node, 0);
11738 CAN_COMPLETE_NORMALLY (node)
11739 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
11740 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
11741 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
11744 case LABELED_BLOCK_EXPR:
11745 PUSH_LABELED_BLOCK (node);
11746 if (LABELED_BLOCK_BODY (node))
11747 COMPLETE_CHECK_OP_1 (node);
11748 TREE_TYPE (node) = void_type_node;
11749 POP_LABELED_BLOCK ();
11751 if (IS_EMPTY_STMT (LABELED_BLOCK_BODY (node)))
11753 LABELED_BLOCK_BODY (node) = NULL_TREE;
11754 CAN_COMPLETE_NORMALLY (node) = 1;
11756 else if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
11757 CAN_COMPLETE_NORMALLY (node) = 1;
11760 case EXIT_BLOCK_EXPR:
11761 return patch_bc_statement (node);
11764 cn = java_complete_tree (TREE_OPERAND (node, 0));
11765 if (cn == error_mark_node)
11768 /* First, the case expression must be constant. Values of final
11769 fields are accepted. */
11771 if ((TREE_CODE (cn) == COMPOUND_EXPR || TREE_CODE (cn) == COMPONENT_REF)
11772 && JDECL_P (TREE_OPERAND (cn, 1))
11773 && FIELD_FINAL (TREE_OPERAND (cn, 1))
11774 && DECL_INITIAL (TREE_OPERAND (cn, 1)))
11776 cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
11777 TREE_OPERAND (cn, 1));
11779 /* Accept final locals too. */
11780 else if (TREE_CODE (cn) == VAR_DECL && DECL_FINAL (cn)
11781 && DECL_INITIAL (cn))
11782 cn = fold_constant_for_init (DECL_INITIAL (cn), cn);
11784 if (!TREE_CONSTANT (cn) && !flag_emit_xref)
11786 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11787 parse_error_context (node, "Constant expression required");
11788 return error_mark_node;
11791 nn = ctxp->current_loop;
11793 /* It must be assignable to the type of the switch expression. */
11794 if (!try_builtin_assignconv (NULL_TREE,
11795 TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
11797 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11798 parse_error_context
11800 "Incompatible type for case. Can't convert %qs to %<int%>",
11801 lang_printable_name (TREE_TYPE (cn), 0));
11802 return error_mark_node;
11805 cn = fold (convert (int_type_node, cn));
11806 TREE_CONSTANT_OVERFLOW (cn) = 0;
11807 CAN_COMPLETE_NORMALLY (cn) = 1;
11809 /* Save the label on a list so that we can later check for
11811 case_label_list = tree_cons (node, cn, case_label_list);
11813 /* Multiple instance of a case label bearing the same value is
11814 checked later. The case expression is all right so far. */
11815 if (TREE_CODE (cn) == VAR_DECL)
11816 cn = DECL_INITIAL (cn);
11817 TREE_OPERAND (node, 0) = cn;
11818 TREE_TYPE (node) = void_type_node;
11819 CAN_COMPLETE_NORMALLY (node) = 1;
11820 TREE_SIDE_EFFECTS (node) = 1;
11824 nn = ctxp->current_loop;
11825 /* Only one default label is allowed per switch statement */
11826 if (SWITCH_HAS_DEFAULT (nn))
11828 #ifdef USE_MAPPED_LOCATION
11829 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
11831 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11833 parse_error_context (wfl_operator,
11834 "Duplicate case label: %<default%>");
11835 return error_mark_node;
11838 SWITCH_HAS_DEFAULT (nn) = 1;
11839 TREE_TYPE (node) = void_type_node;
11840 TREE_SIDE_EFFECTS (node) = 1;
11841 CAN_COMPLETE_NORMALLY (node) = 1;
11847 /* Check whether the loop was enclosed in a labeled
11848 statement. If not, create one, insert the loop in it and
11850 nn = patch_loop_statement (node);
11852 /* Anyways, walk the body of the loop */
11853 if (TREE_CODE (node) == LOOP_EXPR)
11854 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11855 /* Switch statement: walk the switch expression and the cases */
11857 node = patch_switch_statement (node);
11859 if (node == error_mark_node || TREE_OPERAND (node, 0) == error_mark_node)
11860 nn = error_mark_node;
11863 TREE_TYPE (nn) = TREE_TYPE (node) = void_type_node;
11864 /* If we returned something different, that's because we
11865 inserted a label. Pop the label too. */
11868 if (CAN_COMPLETE_NORMALLY (node))
11869 CAN_COMPLETE_NORMALLY (nn) = 1;
11870 POP_LABELED_BLOCK ();
11877 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11878 return patch_exit_expr (node);
11882 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11883 if (TREE_OPERAND (node, 0) == error_mark_node)
11884 return error_mark_node;
11885 /* then-else branches */
11886 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
11887 if (TREE_OPERAND (node, 1) == error_mark_node)
11888 return error_mark_node;
11890 /* This is a special case due to build_assertion(). When
11891 assertions are disabled we build a COND_EXPR in which
11892 Operand 1 is the body of the assertion. If that happens to
11893 be a string concatenation we'll need to patch it here. */
11894 tree patched = patch_string (TREE_OPERAND (node, 1));
11896 TREE_OPERAND (node, 1) = patched;
11898 TREE_OPERAND (node, 2) = java_complete_tree (TREE_OPERAND (node, 2));
11899 if (TREE_OPERAND (node, 2) == error_mark_node)
11900 return error_mark_node;
11901 return patch_if_else_statement (node);
11904 case CONDITIONAL_EXPR:
11906 wfl_op1 = TREE_OPERAND (node, 0);
11907 COMPLETE_CHECK_OP_0 (node);
11908 wfl_op2 = TREE_OPERAND (node, 1);
11909 COMPLETE_CHECK_OP_1 (node);
11910 wfl_op3 = TREE_OPERAND (node, 2);
11911 COMPLETE_CHECK_OP_2 (node);
11912 return patch_conditional_expr (node, wfl_op1, wfl_op2);
11914 /* 3- Expression section */
11915 case COMPOUND_EXPR:
11916 wfl_op2 = TREE_OPERAND (node, 1);
11917 TREE_OPERAND (node, 0) = nn =
11918 java_complete_tree (TREE_OPERAND (node, 0));
11919 if (IS_EMPTY_STMT (wfl_op2))
11920 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
11923 if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
11925 /* An unreachable condition in a do-while statement
11926 is *not* (technically) an unreachable statement. */
11928 if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
11929 nn = EXPR_WFL_NODE (nn);
11930 /* NN can be NULL_TREE exactly when UPDATE is, in
11931 finish_for_loop. */
11932 if (nn != NULL_TREE && TREE_CODE (nn) != EXIT_EXPR)
11934 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
11935 if (SUPPRESS_UNREACHABLE_ERROR (nn))
11937 /* Perhaps this warning should have an
11938 associated flag. The code being compiled is
11939 pedantically correct, but useless. */
11940 parse_warning_context (wfl_operator,
11941 "Unreachable statement");
11944 parse_error_context (wfl_operator,
11945 "Unreachable statement");
11948 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
11949 if (TREE_OPERAND (node, 1) == error_mark_node)
11950 return error_mark_node;
11951 /* Even though we might allow the case where the first
11952 operand doesn't return normally, we still should compute
11953 CAN_COMPLETE_NORMALLY correctly. */
11954 CAN_COMPLETE_NORMALLY (node)
11955 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
11956 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
11958 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
11962 /* CAN_COMPLETE_NORMALLY (node) = 0; */
11963 return patch_return (node);
11965 case EXPR_WITH_FILE_LOCATION:
11966 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
11967 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
11970 node = resolve_expression_name (node, NULL);
11971 if (node == error_mark_node)
11973 /* Keep line number information somewhere were it doesn't
11974 disrupt the completion process. */
11975 if (flag_emit_xref && TREE_CODE (node) != CALL_EXPR)
11977 EXPR_WFL_NODE (wfl) = TREE_OPERAND (node, 1);
11978 TREE_OPERAND (node, 1) = wfl;
11980 CAN_COMPLETE_NORMALLY (node) = 1;
11985 location_t save_location = input_location;
11986 #ifdef USE_MAPPED_LOCATION
11987 input_location = EXPR_LOCATION (node);
11988 if (input_location == UNKNOWN_LOCATION)
11989 input_location = save_location;
11991 input_line = EXPR_WFL_LINENO (node);
11993 body = java_complete_tree (EXPR_WFL_NODE (node));
11994 input_location = save_location;
11995 EXPR_WFL_NODE (node) = body;
11996 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
11997 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
11998 if (IS_EMPTY_STMT (body) || TREE_CONSTANT (body))
12000 /* Makes it easier to constant fold, detect empty bodies. */
12003 if (body == error_mark_node)
12005 /* Its important for the evaluation of assignment that
12006 this mark on the TREE_TYPE is propagated. */
12007 TREE_TYPE (node) = error_mark_node;
12008 return error_mark_node;
12011 TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
12016 case NEW_ARRAY_EXPR:
12017 /* Patch all the dimensions */
12019 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
12021 int location = EXPR_WFL_LINECOL (TREE_VALUE (cn));
12022 tree dim = convert (int_type_node,
12023 java_complete_tree (TREE_VALUE (cn)));
12024 if (dim == error_mark_node)
12031 TREE_VALUE (cn) = dim;
12032 /* Setup the location of the current dimension, for
12033 later error report. */
12034 #ifdef USE_MAPPED_LOCATION
12035 TREE_PURPOSE (cn) = expr_add_location (NULL_TREE, location, 0);
12037 TREE_PURPOSE (cn) =
12038 build_expr_wfl (NULL_TREE, input_filename, 0, 0);
12039 EXPR_WFL_LINECOL (TREE_PURPOSE (cn)) = location;
12043 /* They complete the array creation expression, if no errors
12045 CAN_COMPLETE_NORMALLY (node) = 1;
12046 return (flag ? error_mark_node
12047 : force_evaluation_order (patch_newarray (node)));
12049 case NEW_ANONYMOUS_ARRAY_EXPR:
12050 /* Create the array type if necessary. */
12051 if (ANONYMOUS_ARRAY_DIMS_SIG (node))
12053 tree type = ANONYMOUS_ARRAY_BASE_TYPE (node);
12054 if (!(type = resolve_type_during_patch (type)))
12055 return error_mark_node;
12056 type = build_array_from_name (type, NULL_TREE,
12057 ANONYMOUS_ARRAY_DIMS_SIG (node), NULL);
12058 ANONYMOUS_ARRAY_BASE_TYPE (node) = build_pointer_type (type);
12060 node = patch_new_array_init (ANONYMOUS_ARRAY_BASE_TYPE (node),
12061 ANONYMOUS_ARRAY_INITIALIZER (node));
12062 if (node == error_mark_node)
12063 return error_mark_node;
12064 CAN_COMPLETE_NORMALLY (node) = 1;
12067 case NEW_CLASS_EXPR:
12069 /* Complete function's argument(s) first */
12070 if (complete_function_arguments (node))
12071 return error_mark_node;
12074 tree decl, wfl = TREE_OPERAND (node, 0);
12075 int in_this = CALL_THIS_CONSTRUCTOR_P (node);
12076 int from_super = (EXPR_WFL_NODE (TREE_OPERAND (node, 0)) ==
12077 super_identifier_node);
12079 #ifdef USE_MAPPED_LOCATION
12080 source_location location = EXPR_LOCATION (node);
12082 int location = EXPR_WFL_LINECOL (node);
12085 node = patch_method_invocation (node, NULL_TREE, NULL_TREE,
12086 from_super, 0, &decl);
12087 if (node == error_mark_node)
12088 return error_mark_node;
12090 if (TREE_CODE (node) == CALL_EXPR
12091 && TREE_OPERAND (node, 1) != NULL_TREE)
12092 arguments = TREE_VALUE (TREE_OPERAND (node, 1));
12094 arguments = NULL_TREE;
12095 check_thrown_exceptions (location, decl, arguments);
12096 /* If we call this(...), register signature and positions */
12098 DECL_CONSTRUCTOR_CALLS (current_function_decl) =
12099 tree_cons (wfl, decl,
12100 DECL_CONSTRUCTOR_CALLS (current_function_decl));
12101 CAN_COMPLETE_NORMALLY (node) = 1;
12102 return force_evaluation_order (node);
12106 /* Save potential wfls */
12107 wfl_op1 = TREE_OPERAND (node, 0);
12108 TREE_OPERAND (node, 0) = nn = java_complete_lhs (wfl_op1);
12110 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node)
12111 && TREE_CODE (nn) == VAR_DECL && TREE_STATIC (nn)
12112 && DECL_INITIAL (nn) != NULL_TREE)
12116 value = fold_constant_for_init (nn, nn);
12118 /* When we have a primitype type, or a string and we're not
12119 emitting a class file, we actually don't want to generate
12120 anything for the assignment. */
12121 if (value != NULL_TREE &&
12122 (JPRIMITIVE_TYPE_P (TREE_TYPE (value)) ||
12123 (TREE_TYPE (value) == string_ptr_type_node &&
12124 ! flag_emit_class_files)))
12126 /* Prepare node for patch_assignment */
12127 TREE_OPERAND (node, 1) = value;
12128 /* Call patch assignment to verify the assignment */
12129 if (patch_assignment (node, wfl_op1) == error_mark_node)
12130 return error_mark_node;
12131 /* Set DECL_INITIAL properly (a conversion might have
12132 been decided by patch_assignment) and return the
12133 empty statement. */
12136 tree patched = patch_string (TREE_OPERAND (node, 1));
12138 DECL_INITIAL (nn) = patched;
12140 DECL_INITIAL (nn) = TREE_OPERAND (node, 1);
12141 DECL_FIELD_FINAL_IUD (nn) = 1;
12142 return build_java_empty_stmt ();
12145 if (! flag_emit_class_files)
12146 DECL_INITIAL (nn) = NULL_TREE;
12148 wfl_op2 = TREE_OPERAND (node, 1);
12150 if (TREE_OPERAND (node, 0) == error_mark_node)
12151 return error_mark_node;
12153 flag = COMPOUND_ASSIGN_P (wfl_op2);
12156 /* This might break when accessing outer field from inner
12157 class. TESTME, FIXME */
12158 tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0));
12160 /* Hand stabilize the lhs on both places */
12161 TREE_OPERAND (node, 0) = lvalue;
12162 TREE_OPERAND (TREE_OPERAND (node, 1), 0) =
12163 (flag_emit_class_files ? lvalue : save_expr (lvalue));
12165 /* 15.25.2.a: Left hand is not an array access. FIXME */
12166 /* Now complete the RHS. We write it back later on. */
12167 nn = java_complete_tree (TREE_OPERAND (node, 1));
12169 if ((cn = patch_string (nn)))
12172 /* The last part of the rewrite for E1 op= E2 is to have
12173 E1 = (T)(E1 op E2), with T being the type of E1. */
12174 nn = java_complete_tree (build_cast (EXPR_WFL_LINECOL (wfl_op2),
12175 TREE_TYPE (lvalue), nn));
12177 /* If the assignment is compound and has reference type,
12178 then ensure the LHS has type String and nothing else. */
12179 if (JREFERENCE_TYPE_P (TREE_TYPE (lvalue))
12180 && ! JSTRING_TYPE_P (TREE_TYPE (lvalue)))
12181 parse_error_context (wfl_op2,
12182 "Incompatible type for %<+=%>. Can't convert %qs to %<java.lang.String%>",
12183 lang_printable_name (TREE_TYPE (lvalue), 0));
12185 /* 15.25.2.b: Left hand is an array access. FIXME */
12188 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
12189 function to complete this RHS. Note that a NEW_ARRAY_INIT
12190 might have been already fully expanded if created as a result
12191 of processing an anonymous array initializer. We avoid doing
12192 the operation twice by testing whether the node already bears
12194 else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT && !TREE_TYPE (wfl_op2))
12195 nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
12196 TREE_OPERAND (node, 1));
12197 /* Otherwise we simply complete the RHS */
12199 nn = java_complete_tree (TREE_OPERAND (node, 1));
12201 if (nn == error_mark_node)
12202 return error_mark_node;
12204 /* Write back the RHS as we evaluated it. */
12205 TREE_OPERAND (node, 1) = nn;
12207 /* In case we're handling = with a String as a RHS, we need to
12208 produce a String out of the RHS (it might still be a
12209 STRING_CST or a StringBuffer at this stage */
12210 if ((nn = patch_string (TREE_OPERAND (node, 1))))
12211 TREE_OPERAND (node, 1) = nn;
12213 if ((nn = outer_field_access_fix (wfl_op1, TREE_OPERAND (node, 0),
12214 TREE_OPERAND (node, 1))))
12216 /* We return error_mark_node if outer_field_access_fix
12217 detects we write into a final. */
12218 if (nn == error_mark_node)
12219 return error_mark_node;
12224 node = patch_assignment (node, wfl_op1);
12225 if (node == error_mark_node)
12226 return error_mark_node;
12227 /* Reorganize the tree if necessary. */
12228 if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node))
12229 || JSTRING_P (TREE_TYPE (node))))
12230 node = java_refold (node);
12233 /* Seek to set DECL_INITIAL to a proper value, since it might have
12234 undergone a conversion in patch_assignment. We do that only when
12235 it's necessary to have DECL_INITIAL properly set. */
12236 nn = TREE_OPERAND (node, 0);
12237 if (TREE_CODE (nn) == VAR_DECL
12238 && DECL_INITIAL (nn) && CONSTANT_VALUE_P (DECL_INITIAL (nn))
12239 && FIELD_STATIC (nn) && FIELD_FINAL (nn)
12240 && (JPRIMITIVE_TYPE_P (TREE_TYPE (nn))
12241 || TREE_TYPE (nn) == string_ptr_type_node))
12242 DECL_INITIAL (nn) = TREE_OPERAND (node, 1);
12244 CAN_COMPLETE_NORMALLY (node) = 1;
12256 case TRUNC_MOD_EXPR:
12257 case TRUNC_DIV_EXPR:
12259 case TRUTH_ANDIF_EXPR:
12260 case TRUTH_ORIF_EXPR:
12267 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
12268 knows how to handle those cases. */
12269 wfl_op1 = TREE_OPERAND (node, 0);
12270 wfl_op2 = TREE_OPERAND (node, 1);
12272 CAN_COMPLETE_NORMALLY (node) = 1;
12273 /* Don't complete string nodes if dealing with the PLUS operand. */
12274 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
12276 nn = java_complete_tree (wfl_op1);
12277 if (nn == error_mark_node)
12278 return error_mark_node;
12280 TREE_OPERAND (node, 0) = nn;
12282 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
12284 nn = java_complete_tree (wfl_op2);
12285 if (nn == error_mark_node)
12286 return error_mark_node;
12288 TREE_OPERAND (node, 1) = nn;
12290 return patch_binop (node, wfl_op1, wfl_op2);
12292 case INSTANCEOF_EXPR:
12293 wfl_op1 = TREE_OPERAND (node, 0);
12294 COMPLETE_CHECK_OP_0 (node);
12295 if (flag_emit_xref)
12297 TREE_TYPE (node) = boolean_type_node;
12300 return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
12302 case UNARY_PLUS_EXPR:
12304 case TRUTH_NOT_EXPR:
12306 case PREDECREMENT_EXPR:
12307 case PREINCREMENT_EXPR:
12308 case POSTDECREMENT_EXPR:
12309 case POSTINCREMENT_EXPR:
12311 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
12312 how to handle those cases. */
12313 wfl_op1 = TREE_OPERAND (node, 0);
12314 CAN_COMPLETE_NORMALLY (node) = 1;
12315 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
12316 if (TREE_OPERAND (node, 0) == error_mark_node)
12317 return error_mark_node;
12318 node = patch_unaryop (node, wfl_op1);
12319 CAN_COMPLETE_NORMALLY (node) = 1;
12323 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
12324 how to handle those cases. */
12325 wfl_op1 = TREE_OPERAND (node, 0);
12326 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
12327 if (TREE_OPERAND (node, 0) == error_mark_node)
12328 return error_mark_node;
12329 if (!flag_emit_class_files && !flag_emit_xref)
12330 TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
12331 /* The same applies to wfl_op2 */
12332 wfl_op2 = TREE_OPERAND (node, 1);
12333 TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
12334 if (TREE_OPERAND (node, 1) == error_mark_node)
12335 return error_mark_node;
12336 if (!flag_emit_class_files && !flag_emit_xref)
12337 TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
12338 return patch_array_ref (node);
12343 case COMPONENT_REF:
12344 /* The first step in the re-write of qualified name handling. FIXME.
12345 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
12346 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
12347 if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
12349 tree name = TREE_OPERAND (node, 1);
12350 tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
12351 if (field == NULL_TREE)
12353 error ("missing static field %qs", IDENTIFIER_POINTER (name));
12354 return error_mark_node;
12356 if (! FIELD_STATIC (field))
12358 error ("not a static field %qs", IDENTIFIER_POINTER (name));
12359 return error_mark_node;
12368 /* Can't use THIS in a static environment */
12371 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12372 parse_error_context (wfl_operator,
12373 "Keyword %<this%> used outside allowed context");
12374 TREE_TYPE (node) = error_mark_node;
12375 return error_mark_node;
12377 if (ctxp->explicit_constructor_p)
12379 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12380 parse_error_context
12381 (wfl_operator, "Can't reference %<this%> or %<super%> before the superclass constructor has been called");
12382 TREE_TYPE (node) = error_mark_node;
12383 return error_mark_node;
12385 return current_this;
12387 case CLASS_LITERAL:
12388 CAN_COMPLETE_NORMALLY (node) = 1;
12389 node = patch_incomplete_class_ref (node);
12390 if (node == error_mark_node)
12391 return error_mark_node;
12395 CAN_COMPLETE_NORMALLY (node) = 1;
12396 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
12397 and it's time to turn it into the appropriate String object */
12398 if ((nn = patch_string (node)))
12401 internal_error ("No case for %s", tree_code_name [TREE_CODE (node)]);
12406 /* Complete function call's argument. Return a nonzero value is an
12407 error was found. */
12410 complete_function_arguments (tree node)
12415 ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
12416 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
12418 tree wfl = TREE_VALUE (cn), parm, temp;
12419 parm = java_complete_tree (wfl);
12421 if (parm == error_mark_node)
12426 /* If we have a string literal that we haven't transformed yet or a
12427 crafted string buffer, as a result of the use of the String
12428 `+' operator. Build `parm.toString()' and expand it. */
12429 if ((temp = patch_string (parm)))
12432 TREE_VALUE (cn) = parm;
12434 ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
12438 /* Sometimes (for loops and variable initialized during their
12439 declaration), we want to wrap a statement around a WFL and turn it
12443 build_debugable_stmt (int location, tree stmt)
12445 if (TREE_CODE (stmt) != EXPR_WITH_FILE_LOCATION)
12447 #ifdef USE_MAPPED_LOCATION
12448 stmt = expr_add_location (stmt, location, 1);
12450 stmt = build_expr_wfl (stmt, input_filename, 0, 0);
12451 EXPR_WFL_LINECOL (stmt) = location;
12452 JAVA_MAYBE_GENERATE_DEBUG_INFO (stmt);
12459 build_expr_block (tree body, tree decls)
12461 tree node = make_node (BLOCK);
12462 BLOCK_EXPR_DECLS (node) = decls;
12463 BLOCK_EXPR_BODY (node) = body;
12465 TREE_TYPE (node) = TREE_TYPE (body);
12466 TREE_SIDE_EFFECTS (node) = 1;
12470 /* Create a new function block and link it appropriately to current
12471 function block chain */
12476 tree b = build_expr_block (NULL_TREE, NULL_TREE);
12478 /* Link block B supercontext to the previous block. The current
12479 function DECL is used as supercontext when enter_a_block is called
12480 for the first time for a given function. The current function body
12481 (DECL_FUNCTION_BODY) is set to be block B. */
12483 tree fndecl = current_function_decl;
12486 BLOCK_SUPERCONTEXT (b) = current_static_block;
12487 current_static_block = b;
12490 else if (!DECL_FUNCTION_BODY (fndecl))
12492 BLOCK_SUPERCONTEXT (b) = fndecl;
12493 DECL_FUNCTION_BODY (fndecl) = b;
12497 BLOCK_SUPERCONTEXT (b) = DECL_FUNCTION_BODY (fndecl);
12498 DECL_FUNCTION_BODY (fndecl) = b;
12503 /* Exit a block by changing the current function body
12504 (DECL_FUNCTION_BODY) to the current block super context, only if
12505 the block being exited isn't the method's top level one. */
12511 if (current_function_decl)
12513 b = DECL_FUNCTION_BODY (current_function_decl);
12514 if (BLOCK_SUPERCONTEXT (b) != current_function_decl)
12515 DECL_FUNCTION_BODY (current_function_decl) = BLOCK_SUPERCONTEXT (b);
12519 b = current_static_block;
12521 if (BLOCK_SUPERCONTEXT (b))
12522 current_static_block = BLOCK_SUPERCONTEXT (b);
12527 /* Lookup for NAME in the nested function's blocks, all the way up to
12528 the current toplevel one. It complies with Java's local variable
12532 lookup_name_in_blocks (tree name)
12534 tree b = GET_CURRENT_BLOCK (current_function_decl);
12536 while (b != current_function_decl)
12540 /* Paranoid sanity check. To be removed */
12541 if (TREE_CODE (b) != BLOCK)
12544 for (current = BLOCK_EXPR_DECLS (b); current;
12545 current = TREE_CHAIN (current))
12546 if (DECL_NAME (current) == name)
12548 b = BLOCK_SUPERCONTEXT (b);
12554 maybe_absorb_scoping_blocks (void)
12556 while (BLOCK_IS_IMPLICIT (GET_CURRENT_BLOCK (current_function_decl)))
12558 tree b = exit_block ();
12559 java_method_add_stmt (current_function_decl, b);
12560 SOURCE_FRONTEND_DEBUG (("Absorbing scoping block at line %d", input_line));
12565 /* This section of the source is reserved to build_* functions that
12566 are building incomplete tree nodes and the patch_* functions that
12567 are completing them. */
12569 /* Wrap a non WFL node around a WFL. */
12572 build_wfl_wrap (tree node, int location)
12574 tree wfl, node_to_insert = node;
12576 /* We want to process THIS . xxx symbolically, to keep it consistent
12577 with the way we're processing SUPER. A THIS from a primary as a
12578 different form than a SUPER. Turn THIS into something symbolic */
12579 if (TREE_CODE (node) == THIS_EXPR)
12580 node_to_insert = wfl = build_wfl_node (this_identifier_node);
12582 #ifdef USE_MAPPED_LOCATION
12583 wfl = build_unknown_wfl (NULL_TREE);
12585 SET_EXPR_LOCATION (wfl, location);
12587 wfl = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
12589 EXPR_WFL_LINECOL (wfl) = location;
12591 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (node_to_insert, NULL_TREE);
12595 /* Build a super() constructor invocation. Returns an empty statement if
12596 we're currently dealing with the class java.lang.Object. */
12599 build_super_invocation (tree mdecl)
12601 if (DECL_CONTEXT (mdecl) == object_type_node)
12602 return build_java_empty_stmt ();
12605 tree super_wfl = build_wfl_node (super_identifier_node);
12606 tree a = NULL_TREE, t;
12608 /* This is called after parsing is done, so the parser context
12609 won't be accurate. Set location info from current_class decl. */
12610 tree class_wfl = lookup_cl (TYPE_NAME (current_class));
12611 EXPR_WFL_LINECOL (super_wfl) = EXPR_WFL_LINECOL (class_wfl);
12613 /* If we're dealing with an anonymous class, pass the arguments
12614 of the crafted constructor along. */
12615 if (ANONYMOUS_CLASS_P (DECL_CONTEXT (mdecl)))
12617 SKIP_THIS_AND_ARTIFICIAL_PARMS (t, mdecl);
12618 for (; t != end_params_node; t = TREE_CHAIN (t))
12619 a = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (t)), a);
12621 return build_method_invocation (super_wfl, a);
12625 /* Build a SUPER/THIS qualified method invocation. */
12628 build_this_super_qualified_invocation (int use_this, tree name, tree args,
12629 int lloc, int rloc)
12633 build_wfl_node (use_this ? this_identifier_node : super_identifier_node);
12634 EXPR_WFL_LINECOL (wfl) = lloc;
12635 invok = build_method_invocation (name, args);
12636 return make_qualified_primary (wfl, invok, rloc);
12639 /* Build an incomplete CALL_EXPR node. */
12642 build_method_invocation (tree name, tree args)
12644 tree call = build3 (CALL_EXPR, NULL_TREE, name, args, NULL_TREE);
12645 TREE_SIDE_EFFECTS (call) = 1;
12646 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
12650 /* Build an incomplete new xxx(...) node. */
12653 build_new_invocation (tree name, tree args)
12655 tree call = build3 (NEW_CLASS_EXPR, NULL_TREE, name, args, NULL_TREE);
12656 TREE_SIDE_EFFECTS (call) = 1;
12657 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
12661 /* Build an incomplete assignment expression. */
12664 build_assignment (int op, int op_location, tree lhs, tree rhs)
12667 /* Build the corresponding binop if we deal with a Compound
12668 Assignment operator. Mark the binop sub-tree as part of a
12669 Compound Assignment expression */
12670 if (op != ASSIGN_TK)
12672 rhs = build_binop (BINOP_LOOKUP (op), op_location, lhs, rhs);
12673 COMPOUND_ASSIGN_P (rhs) = 1;
12675 assignment = build2 (MODIFY_EXPR, NULL_TREE, lhs, rhs);
12676 TREE_SIDE_EFFECTS (assignment) = 1;
12677 EXPR_WFL_LINECOL (assignment) = op_location;
12681 /* Print an INTEGER_CST node as decimal in a static buffer, and return
12682 the buffer. This is used only for string conversion. */
12684 string_convert_int_cst (tree node)
12686 /* Long.MIN_VALUE is -9223372036854775808, 20 characters. */
12687 static char buffer[21];
12689 unsigned HOST_WIDE_INT lo = TREE_INT_CST_LOW (node);
12690 unsigned HOST_WIDE_INT hi = TREE_INT_CST_HIGH (node);
12691 char *p = buffer + sizeof (buffer);
12694 unsigned HOST_WIDE_INT hibit = (((unsigned HOST_WIDE_INT) 1)
12695 << (HOST_BITS_PER_WIDE_INT - 1));
12699 /* If negative, note the fact and negate the value. */
12709 /* Divide by 10 until there are no bits left. */
12712 unsigned HOST_WIDE_INT acc = 0;
12713 unsigned HOST_WIDE_INT outhi = 0, outlo = 0;
12716 /* Use long division to compute the result and the remainder. */
12717 for (i = 0; i < 2 * HOST_BITS_PER_WIDE_INT; ++i)
12719 /* Shift a bit into accumulator. */
12724 /* Shift the value. */
12730 /* Shift the correct bit into the result. */
12732 if ((outlo & hibit))
12742 /* '0' == 060 in Java, but might not be here (think EBCDIC). */
12743 *--p = '\060' + acc;
12751 *--p = '\055'; /* '-' == 055 in Java, but might not be here. */
12756 /* Print an INTEGER_CST node in a static buffer, and return the
12757 buffer. This is used only for error handling. */
12759 print_int_node (tree node)
12761 static char buffer [80];
12762 if (TREE_CONSTANT_OVERFLOW (node))
12763 sprintf (buffer, "<overflow>");
12765 if (TREE_INT_CST_HIGH (node) == 0)
12766 sprintf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
12767 TREE_INT_CST_LOW (node));
12768 else if (TREE_INT_CST_HIGH (node) == -1
12769 && TREE_INT_CST_LOW (node) != 0)
12770 sprintf (buffer, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
12771 -TREE_INT_CST_LOW (node));
12773 sprintf (buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
12774 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
12780 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
12783 /* 15.25 Assignment operators. */
12786 patch_assignment (tree node, tree wfl_op1)
12788 tree rhs = TREE_OPERAND (node, 1);
12789 tree lvalue = TREE_OPERAND (node, 0), llvalue;
12790 tree lhs_type = NULL_TREE, rhs_type, new_rhs = NULL_TREE;
12791 int error_found = 0;
12792 int lvalue_from_array = 0;
12795 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12797 /* Lhs can be a named variable */
12798 if (JDECL_P (lvalue))
12800 lhs_type = TREE_TYPE (lvalue);
12802 /* Or Lhs can be an array access. */
12803 else if (TREE_CODE (lvalue) == ARRAY_REF)
12805 lhs_type = TREE_TYPE (lvalue);
12806 lvalue_from_array = 1;
12808 /* Or a field access */
12809 else if (TREE_CODE (lvalue) == COMPONENT_REF)
12810 lhs_type = TREE_TYPE (lvalue);
12811 /* Or a function return slot */
12812 else if (TREE_CODE (lvalue) == RESULT_DECL)
12814 /* If the return type is an integral type, then we create the
12815 RESULT_DECL with a promoted type, but we need to do these
12816 checks against the unpromoted type to ensure type safety. So
12817 here we look at the real type, not the type of the decl we
12819 lhs_type = TREE_TYPE (TREE_TYPE (current_function_decl));
12822 /* Otherwise, we might want to try to write into an optimized static
12823 final, this is an of a different nature, reported further on. */
12824 else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
12825 && resolve_expression_name (wfl_op1, &llvalue))
12827 lhs_type = TREE_TYPE (lvalue);
12831 parse_error_context (wfl_op1, "Invalid left hand side of assignment");
12835 rhs_type = TREE_TYPE (rhs);
12837 /* 5.1 Try the assignment conversion for builtin type. */
12838 new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
12840 /* 5.2 If it failed, try a reference conversion */
12842 new_rhs = try_reference_assignconv (lhs_type, rhs);
12844 /* 15.25.2 If we have a compound assignment, convert RHS into the
12846 else if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
12847 new_rhs = convert (lhs_type, rhs);
12849 /* Explicit cast required. This is an error */
12852 char *t1 = xstrdup (lang_printable_name (TREE_TYPE (rhs), 0));
12853 char *t2 = xstrdup (lang_printable_name (lhs_type, 0));
12855 char operation [32]; /* Max size known */
12857 /* If the assignment is part of a declaration, we use the WFL of
12858 the declared variable to point out the error and call it a
12859 declaration problem. If the assignment is a genuine =
12860 operator, we call is a operator `=' problem, otherwise we
12861 call it an assignment problem. In both of these last cases,
12862 we use the WFL of the operator to indicate the error. */
12864 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node))
12867 strcpy (operation, "declaration");
12871 wfl = wfl_operator;
12872 if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
12873 strcpy (operation, "assignment");
12874 else if (is_return)
12875 strcpy (operation, "'return'");
12877 strcpy (operation, "'='");
12880 if (!valid_cast_to_p (rhs_type, lhs_type))
12881 parse_error_context
12882 (wfl, "Incompatible type for %s. Can't convert %qs to %qs",
12883 operation, t1, t2);
12885 parse_error_context (wfl, "Incompatible type for %s. Explicit cast needed to convert %qs to %qs",
12886 operation, t1, t2);
12887 free (t1); free (t2);
12892 return error_mark_node;
12894 /* If we're processing a `return' statement, promote the actual type
12895 to the promoted type. */
12897 new_rhs = convert (TREE_TYPE (lvalue), new_rhs);
12899 /* 10.10: Array Store Exception runtime check */
12900 if (!flag_emit_class_files
12902 && lvalue_from_array
12903 && JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type)))
12905 tree array, store_check, base, index_expr;
12907 /* Save RHS so that it doesn't get re-evaluated by the store check. */
12908 new_rhs = save_expr (new_rhs);
12910 /* Get the INDIRECT_REF. */
12911 array = TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0);
12912 /* Get the array pointer expr. */
12913 array = TREE_OPERAND (array, 0);
12914 store_check = build_java_arraystore_check (array, new_rhs);
12916 index_expr = TREE_OPERAND (lvalue, 1);
12918 if (TREE_CODE (index_expr) == COMPOUND_EXPR)
12920 /* A COMPOUND_EXPR here is a bounds check. The bounds check must
12921 happen before the store check, so prepare to insert the store
12922 check within the second operand of the existing COMPOUND_EXPR. */
12928 index_expr = TREE_OPERAND (base, 1);
12929 TREE_OPERAND (base, 1) = build2 (COMPOUND_EXPR, TREE_TYPE (index_expr),
12930 store_check, index_expr);
12933 /* Final locals can be used as case values in switch
12934 statement. Prepare them for this eventuality. */
12935 if (TREE_CODE (lvalue) == VAR_DECL
12936 && DECL_FINAL (lvalue)
12937 && TREE_CONSTANT (new_rhs)
12938 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (lvalue))
12939 && JINTEGRAL_TYPE_P (TREE_TYPE (lvalue))
12942 TREE_CONSTANT (lvalue) = 1;
12943 TREE_INVARIANT (lvalue) = 1;
12944 DECL_INITIAL (lvalue) = new_rhs;
12947 /* Copy the rhs if it's a reference. */
12948 if (! flag_check_references && ! flag_emit_class_files && optimize > 0)
12950 switch (TREE_CODE (new_rhs))
12954 case COMPONENT_REF:
12955 /* Transform a = foo.bar
12956 into a = ({int tmp; tmp = foo.bar;}).
12957 We need to ensure that if a read from memory fails
12958 because of a NullPointerException, a destination variable
12959 will remain unchanged. An explicit temporary does what
12962 If flag_check_references is set, this is unnecessary
12963 because we'll check each reference before doing any
12964 reads. If optimize is not set the result will never be
12965 written to a stack slot that contains the LHS. */
12967 tree tmp = build_decl (VAR_DECL, get_identifier ("<tmp>"),
12968 TREE_TYPE (new_rhs));
12969 tree block = make_node (BLOCK);
12971 = build2 (MODIFY_EXPR, TREE_TYPE (new_rhs), tmp, fold (new_rhs));
12972 DECL_CONTEXT (tmp) = current_function_decl;
12973 TREE_TYPE (block) = TREE_TYPE (new_rhs);
12974 BLOCK_VARS (block) = tmp;
12975 BLOCK_EXPR_BODY (block) = assignment;
12976 TREE_SIDE_EFFECTS (block) = 1;
12985 TREE_OPERAND (node, 0) = lvalue;
12986 TREE_OPERAND (node, 1) = new_rhs;
12987 TREE_TYPE (node) = lhs_type;
12991 /* Check that type SOURCE can be cast into type DEST. If the cast
12992 can't occur at all, return NULL; otherwise, return a possibly
12996 try_reference_assignconv (tree lhs_type, tree rhs)
12998 tree new_rhs = NULL_TREE;
12999 tree rhs_type = TREE_TYPE (rhs);
13001 if (!JPRIMITIVE_TYPE_P (rhs_type) && JREFERENCE_TYPE_P (lhs_type))
13003 /* `null' may be assigned to any reference type */
13004 if (rhs == null_pointer_node)
13005 new_rhs = null_pointer_node;
13006 /* Try the reference assignment conversion */
13007 else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
13009 /* This is a magic assignment that we process differently */
13010 else if (TREE_CODE (rhs) == JAVA_EXC_OBJ_EXPR)
13016 /* Check that RHS can be converted into LHS_TYPE by the assignment
13017 conversion (5.2), for the cases of RHS being a builtin type. Return
13018 NULL_TREE if the conversion fails or if because RHS isn't of a
13019 builtin type. Return a converted RHS if the conversion is possible. */
13022 try_builtin_assignconv (tree wfl_op1, tree lhs_type, tree rhs)
13024 tree new_rhs = NULL_TREE;
13025 tree rhs_type = TREE_TYPE (rhs);
13027 /* Handle boolean specially. */
13028 if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
13029 || TREE_CODE (lhs_type) == BOOLEAN_TYPE)
13031 if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
13032 && TREE_CODE (lhs_type) == BOOLEAN_TYPE)
13036 /* 5.1.1 Try Identity Conversion,
13037 5.1.2 Try Widening Primitive Conversion */
13038 else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
13039 new_rhs = convert (lhs_type, rhs);
13041 /* Try a narrowing primitive conversion (5.1.3):
13042 - expression is a constant expression of type byte, short, char,
13044 - variable is byte, short or char AND
13045 - The value of the expression is representable in the type of the
13047 else if ((rhs_type == byte_type_node || rhs_type == short_type_node
13048 || rhs_type == char_type_node || rhs_type == int_type_node)
13049 && TREE_CONSTANT (rhs)
13050 && (lhs_type == byte_type_node || lhs_type == char_type_node
13051 || lhs_type == short_type_node))
13053 if (int_fits_type_p (rhs, lhs_type))
13054 new_rhs = convert (lhs_type, rhs);
13055 else if (wfl_op1) /* Might be called with a NULL */
13056 parse_warning_context
13058 "Constant expression %qs too wide for narrowing primitive conversion to %qs",
13059 print_int_node (rhs), lang_printable_name (lhs_type, 0));
13060 /* Reported a warning that will turn into an error further
13061 down, so we don't return */
13067 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
13068 conversion (5.1.1) or widening primitive conversion (5.1.2). Return
13069 0 is the conversion test fails. This implements parts the method
13070 invocation conversion (5.3). */
13073 valid_builtin_assignconv_identity_widening_p (tree lhs_type, tree rhs_type)
13075 /* 5.1.1: This is the identity conversion part. */
13076 if (lhs_type == rhs_type)
13079 /* Reject non primitive types and boolean conversions. */
13080 if (!JNUMERIC_TYPE_P (lhs_type) || !JNUMERIC_TYPE_P (rhs_type))
13083 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
13084 than a char can't be converted into a char. Short can't too, but
13085 the < test below takes care of that */
13086 if (lhs_type == char_type_node && rhs_type == byte_type_node)
13089 /* Accept all promoted type here. Note, we can't use <= in the test
13090 below, because we still need to bounce out assignments of short
13091 to char and the likes */
13092 if (lhs_type == int_type_node
13093 && (rhs_type == promoted_byte_type_node
13094 || rhs_type == promoted_short_type_node
13095 || rhs_type == promoted_char_type_node
13096 || rhs_type == promoted_boolean_type_node))
13099 /* From here, an integral is widened if its precision is smaller
13100 than the precision of the LHS or if the LHS is a floating point
13101 type, or the RHS is a float and the RHS a double. */
13102 if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type)
13103 && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
13104 || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
13105 || (rhs_type == float_type_node && lhs_type == double_type_node))
13111 /* Check that something of SOURCE type can be assigned or cast to
13112 something of DEST type at runtime. Return 1 if the operation is
13113 valid, 0 otherwise. If CAST is set to 1, we're treating the case
13114 were SOURCE is cast into DEST, which borrows a lot of the
13115 assignment check. */
13118 valid_ref_assignconv_cast_p (tree source, tree dest, int cast)
13120 /* SOURCE or DEST might be null if not from a declared entity. */
13121 if (!source || !dest)
13123 if (JNULLP_TYPE_P (source))
13125 if (TREE_CODE (source) == POINTER_TYPE)
13126 source = TREE_TYPE (source);
13127 if (TREE_CODE (dest) == POINTER_TYPE)
13128 dest = TREE_TYPE (dest);
13130 /* If source and dest are being compiled from bytecode, they may need to
13132 if (CLASS_P (source) && !CLASS_LOADED_P (source))
13134 load_class (source, 1);
13135 safe_layout_class (source);
13137 if (CLASS_P (dest) && !CLASS_LOADED_P (dest))
13139 load_class (dest, 1);
13140 safe_layout_class (dest);
13143 /* Case where SOURCE is a class type */
13144 if (TYPE_CLASS_P (source))
13146 if (TYPE_CLASS_P (dest))
13147 return (source == dest
13148 || inherits_from_p (source, dest)
13149 || (cast && inherits_from_p (dest, source)));
13150 if (TYPE_INTERFACE_P (dest))
13152 /* If doing a cast and SOURCE is final, the operation is
13153 always correct a compile time (because even if SOURCE
13154 does not implement DEST, a subclass of SOURCE might). */
13155 if (cast && !CLASS_FINAL (TYPE_NAME (source)))
13157 /* Otherwise, SOURCE must implement DEST */
13158 return interface_of_p (dest, source);
13160 /* DEST is an array, cast permitted if SOURCE is of Object type */
13161 return (cast && source == object_type_node ? 1 : 0);
13163 if (TYPE_INTERFACE_P (source))
13165 if (TYPE_CLASS_P (dest))
13167 /* If not casting, DEST must be the Object type */
13169 return dest == object_type_node;
13170 /* We're doing a cast. The cast is always valid is class
13171 DEST is not final, otherwise, DEST must implement SOURCE */
13172 else if (!CLASS_FINAL (TYPE_NAME (dest)))
13175 return interface_of_p (source, dest);
13177 if (TYPE_INTERFACE_P (dest))
13179 /* If doing a cast, then if SOURCE and DEST contain method
13180 with the same signature but different return type, then
13181 this is a (compile time) error */
13184 tree method_source, method_dest;
13188 for (method_source = TYPE_METHODS (source); method_source;
13189 method_source = TREE_CHAIN (method_source))
13192 build_java_argument_signature (TREE_TYPE (method_source));
13193 source_type = TREE_TYPE (TREE_TYPE (method_source));
13194 source_name = DECL_NAME (method_source);
13195 for (method_dest = TYPE_METHODS (dest);
13196 method_dest; method_dest = TREE_CHAIN (method_dest))
13198 build_java_argument_signature (TREE_TYPE (method_dest))
13199 && source_name == DECL_NAME (method_dest)
13200 && source_type != TREE_TYPE (TREE_TYPE (method_dest)))
13206 return source == dest || interface_of_p (dest, source);
13212 && (DECL_NAME (TYPE_NAME (source))
13213 == java_lang_cloneable_identifier_node
13214 || (DECL_NAME (TYPE_NAME (source))
13215 == java_io_serializable_identifier_node)));
13218 if (TYPE_ARRAY_P (source))
13220 if (TYPE_CLASS_P (dest))
13221 return dest == object_type_node;
13222 /* Can't cast an array to an interface unless the interface is
13223 java.lang.Cloneable or java.io.Serializable. */
13224 if (TYPE_INTERFACE_P (dest))
13225 return (DECL_NAME (TYPE_NAME (dest))
13226 == java_lang_cloneable_identifier_node
13227 || (DECL_NAME (TYPE_NAME (dest))
13228 == java_io_serializable_identifier_node));
13231 tree source_element_type = TYPE_ARRAY_ELEMENT (source);
13232 tree dest_element_type = TYPE_ARRAY_ELEMENT (dest);
13234 /* In case of severe errors, they turn out null */
13235 if (!dest_element_type || !source_element_type)
13237 if (source_element_type == dest_element_type)
13239 return valid_ref_assignconv_cast_p (source_element_type,
13240 dest_element_type, cast);
13248 valid_cast_to_p (tree source, tree dest)
13250 if (TREE_CODE (source) == POINTER_TYPE)
13251 source = TREE_TYPE (source);
13252 if (TREE_CODE (dest) == POINTER_TYPE)
13253 dest = TREE_TYPE (dest);
13255 if (TREE_CODE (source) == RECORD_TYPE && TREE_CODE (dest) == RECORD_TYPE)
13256 return valid_ref_assignconv_cast_p (source, dest, 1);
13258 else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
13261 else if (TREE_CODE (source) == BOOLEAN_TYPE
13262 && TREE_CODE (dest) == BOOLEAN_TYPE)
13269 do_unary_numeric_promotion (tree arg)
13271 tree type = TREE_TYPE (arg);
13272 if ((TREE_CODE (type) == INTEGER_TYPE && TYPE_PRECISION (type) < 32)
13273 || TREE_CODE (type) == CHAR_TYPE)
13274 arg = convert (int_type_node, arg);
13278 /* Return a nonzero value if SOURCE can be converted into DEST using
13279 the method invocation conversion rule (5.3). */
13281 valid_method_invocation_conversion_p (tree dest, tree source)
13283 return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
13284 && valid_builtin_assignconv_identity_widening_p (dest, source))
13285 || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
13286 && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
13287 && valid_ref_assignconv_cast_p (source, dest, 0)));
13290 /* Build an incomplete binop expression. */
13293 build_binop (enum tree_code op, int op_location, tree op1, tree op2)
13295 tree binop = build2 (op, NULL_TREE, op1, op2);
13296 TREE_SIDE_EFFECTS (binop) = 1;
13297 /* Store the location of the operator, for better error report. The
13298 string of the operator will be rebuild based on the OP value. */
13299 EXPR_WFL_LINECOL (binop) = op_location;
13303 /* Build the string of the operator retained by NODE. If NODE is part
13304 of a compound expression, add an '=' at the end of the string. This
13305 function is called when an error needs to be reported on an
13306 operator. The string is returned as a pointer to a static character
13310 operator_string (tree node)
13312 #define BUILD_OPERATOR_STRING(S) \
13314 sprintf (buffer, "%s%s", S, (COMPOUND_ASSIGN_P (node) ? "=" : "")); \
13318 static char buffer [10];
13319 switch (TREE_CODE (node))
13321 case MULT_EXPR: BUILD_OPERATOR_STRING ("*");
13322 case RDIV_EXPR: BUILD_OPERATOR_STRING ("/");
13323 case TRUNC_MOD_EXPR: BUILD_OPERATOR_STRING ("%");
13324 case PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
13325 case MINUS_EXPR: BUILD_OPERATOR_STRING ("-");
13326 case LSHIFT_EXPR: BUILD_OPERATOR_STRING ("<<");
13327 case RSHIFT_EXPR: BUILD_OPERATOR_STRING (">>");
13328 case URSHIFT_EXPR: BUILD_OPERATOR_STRING (">>>");
13329 case BIT_AND_EXPR: BUILD_OPERATOR_STRING ("&");
13330 case BIT_XOR_EXPR: BUILD_OPERATOR_STRING ("^");
13331 case BIT_IOR_EXPR: BUILD_OPERATOR_STRING ("|");
13332 case TRUTH_ANDIF_EXPR: BUILD_OPERATOR_STRING ("&&");
13333 case TRUTH_ORIF_EXPR: BUILD_OPERATOR_STRING ("||");
13334 case EQ_EXPR: BUILD_OPERATOR_STRING ("==");
13335 case NE_EXPR: BUILD_OPERATOR_STRING ("!=");
13336 case GT_EXPR: BUILD_OPERATOR_STRING (">");
13337 case GE_EXPR: BUILD_OPERATOR_STRING (">=");
13338 case LT_EXPR: BUILD_OPERATOR_STRING ("<");
13339 case LE_EXPR: BUILD_OPERATOR_STRING ("<=");
13340 case UNARY_PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
13341 case NEGATE_EXPR: BUILD_OPERATOR_STRING ("-");
13342 case TRUTH_NOT_EXPR: BUILD_OPERATOR_STRING ("!");
13343 case BIT_NOT_EXPR: BUILD_OPERATOR_STRING ("~");
13344 case PREINCREMENT_EXPR: /* Fall through */
13345 case POSTINCREMENT_EXPR: BUILD_OPERATOR_STRING ("++");
13346 case PREDECREMENT_EXPR: /* Fall through */
13347 case POSTDECREMENT_EXPR: BUILD_OPERATOR_STRING ("--");
13349 internal_error ("unregistered operator %s",
13350 tree_code_name [TREE_CODE (node)]);
13353 #undef BUILD_OPERATOR_STRING
13356 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
13359 java_decl_equiv (tree var_acc1, tree var_acc2)
13361 if (JDECL_P (var_acc1))
13362 return (var_acc1 == var_acc2);
13364 return (TREE_CODE (var_acc1) == COMPONENT_REF
13365 && TREE_CODE (var_acc2) == COMPONENT_REF
13366 && TREE_OPERAND (TREE_OPERAND (var_acc1, 0), 0)
13367 == TREE_OPERAND (TREE_OPERAND (var_acc2, 0), 0)
13368 && TREE_OPERAND (var_acc1, 1) == TREE_OPERAND (var_acc2, 1));
13371 /* Return a nonzero value if CODE is one of the operators that can be
13372 used in conjunction with the `=' operator in a compound assignment. */
13375 binop_compound_p (enum tree_code code)
13378 for (i = 0; i < BINOP_COMPOUND_CANDIDATES; i++)
13379 if (binop_lookup [i] == code)
13382 return i < BINOP_COMPOUND_CANDIDATES;
13385 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
13388 java_refold (tree t)
13390 tree c, b, ns, decl;
13392 if (TREE_CODE (t) != MODIFY_EXPR)
13395 c = TREE_OPERAND (t, 1);
13396 if (! (c && TREE_CODE (c) == COMPOUND_EXPR
13397 && TREE_CODE (TREE_OPERAND (c, 0)) == MODIFY_EXPR
13398 && binop_compound_p (TREE_CODE (TREE_OPERAND (c, 1)))))
13401 /* Now the left branch of the binary operator. */
13402 b = TREE_OPERAND (TREE_OPERAND (c, 1), 0);
13403 if (! (b && TREE_CODE (b) == NOP_EXPR
13404 && TREE_CODE (TREE_OPERAND (b, 0)) == SAVE_EXPR))
13407 ns = TREE_OPERAND (TREE_OPERAND (b, 0), 0);
13408 if (! (ns && TREE_CODE (ns) == NOP_EXPR
13409 && TREE_CODE (TREE_OPERAND (ns, 0)) == SAVE_EXPR))
13412 decl = TREE_OPERAND (TREE_OPERAND (ns, 0), 0);
13413 if ((JDECL_P (decl) || TREE_CODE (decl) == COMPONENT_REF)
13414 /* It's got to be the an equivalent decl */
13415 && java_decl_equiv (decl, TREE_OPERAND (TREE_OPERAND (c, 0), 0)))
13417 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
13418 TREE_OPERAND (TREE_OPERAND (c, 1), 0) = TREE_OPERAND (ns, 0);
13419 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
13420 TREE_OPERAND (t, 1) = TREE_OPERAND (c, 1);
13421 /* Change the right part of the BINOP_EXPR */
13422 TREE_OPERAND (TREE_OPERAND (t, 1), 1) = TREE_OPERAND (c, 0);
13428 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
13429 errors but we modify NODE so that it contains the type computed
13430 according to the expression, when it's fixed. Otherwise, we write
13431 error_mark_node as the type. It allows us to further the analysis
13432 of remaining nodes and detects more errors in certain cases. */
13435 patch_binop (tree node, tree wfl_op1, tree wfl_op2)
13437 tree op1 = TREE_OPERAND (node, 0);
13438 tree op2 = TREE_OPERAND (node, 1);
13439 tree op1_type = TREE_TYPE (op1);
13440 tree op2_type = TREE_TYPE (op2);
13441 tree prom_type = NULL_TREE, cn;
13442 enum tree_code code = TREE_CODE (node);
13444 /* If 1, tell the routine that we have to return error_mark_node
13445 after checking for the initialization of the RHS */
13446 int error_found = 0;
13448 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13450 /* If either op<n>_type are NULL, this might be early signs of an
13451 error situation, unless it's too early to tell (in case we're
13452 handling a `+', `==', `!=' or `instanceof'.) We want to set op<n>_type
13453 correctly so the error can be later on reported accurately. */
13454 if (! (code == PLUS_EXPR || code == NE_EXPR
13455 || code == EQ_EXPR || code == INSTANCEOF_EXPR))
13460 n = java_complete_tree (op1);
13461 op1_type = TREE_TYPE (n);
13465 n = java_complete_tree (op2);
13466 op2_type = TREE_TYPE (n);
13472 /* 15.16 Multiplicative operators */
13473 case MULT_EXPR: /* 15.16.1 Multiplication Operator * */
13474 case RDIV_EXPR: /* 15.16.2 Division Operator / */
13475 case TRUNC_DIV_EXPR: /* 15.16.2 Integral type Division Operator / */
13476 case TRUNC_MOD_EXPR: /* 15.16.3 Remainder operator % */
13477 if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
13479 if (!JNUMERIC_TYPE_P (op1_type))
13480 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13481 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13482 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13483 TREE_TYPE (node) = error_mark_node;
13487 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13489 /* Detect integral division by zero */
13490 if ((code == RDIV_EXPR || code == TRUNC_MOD_EXPR)
13491 && TREE_CODE (prom_type) == INTEGER_TYPE
13492 && (op2 == integer_zero_node || op2 == long_zero_node ||
13493 (TREE_CODE (op2) == INTEGER_CST &&
13494 ! TREE_INT_CST_LOW (op2) && ! TREE_INT_CST_HIGH (op2))))
13496 parse_warning_context
13498 "Evaluating this expression will result in an arithmetic exception being thrown");
13499 TREE_CONSTANT (node) = 0;
13500 TREE_INVARIANT (node) = 0;
13503 /* Change the division operator if necessary */
13504 if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
13505 TREE_SET_CODE (node, TRUNC_DIV_EXPR);
13507 /* Before divisions as is disappear, try to simplify and bail if
13508 applicable, otherwise we won't perform even simple
13509 simplifications like (1-1)/3. We can't do that with floating
13510 point number, folds can't handle them at this stage. */
13511 if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2)
13512 && JINTEGRAL_TYPE_P (op1) && JINTEGRAL_TYPE_P (op2))
13514 TREE_TYPE (node) = prom_type;
13515 node = fold (node);
13516 if (TREE_CODE (node) != code)
13520 if (TREE_CODE (prom_type) == INTEGER_TYPE
13521 && flag_use_divide_subroutine
13522 && ! flag_emit_class_files
13523 && (code == RDIV_EXPR || code == TRUNC_MOD_EXPR))
13524 return build_java_soft_divmod (TREE_CODE (node), prom_type, op1, op2);
13526 /* This one is more complicated. FLOATs are processed by a
13527 function call to soft_fmod. Duplicate the value of the
13528 COMPOUND_ASSIGN_P flag. */
13529 if (code == TRUNC_MOD_EXPR)
13531 tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
13532 COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
13537 /* 15.17 Additive Operators */
13538 case PLUS_EXPR: /* 15.17.1 String Concatenation Operator + */
13540 /* Operation is valid if either one argument is a string
13541 constant, a String object or a StringBuffer crafted for the
13542 purpose of the a previous usage of the String concatenation
13545 if (TREE_CODE (op1) == STRING_CST
13546 || TREE_CODE (op2) == STRING_CST
13547 || JSTRING_TYPE_P (op1_type)
13548 || JSTRING_TYPE_P (op2_type)
13549 || IS_CRAFTED_STRING_BUFFER_P (op1)
13550 || IS_CRAFTED_STRING_BUFFER_P (op2))
13551 return build_string_concatenation (op1, op2);
13553 case MINUS_EXPR: /* 15.17.2 Additive Operators (+ and -) for
13555 if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
13557 if (!JNUMERIC_TYPE_P (op1_type))
13558 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13559 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13560 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13561 TREE_TYPE (node) = error_mark_node;
13565 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13568 /* 15.18 Shift Operators */
13572 if (!JINTEGRAL_TYPE_P (op1_type) || !JINTEGRAL_TYPE_P (op2_type))
13574 if (!JINTEGRAL_TYPE_P (op1_type))
13575 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
13578 if (JNUMERIC_TYPE_P (op2_type))
13579 parse_error_context (wfl_operator,
13580 "Incompatible type for %qs. Explicit cast needed to convert shift distance from %qs to integral",
13581 operator_string (node),
13582 lang_printable_name (op2_type, 0));
13584 parse_error_context (wfl_operator,
13585 "Incompatible type for %qs. Can't convert shift distance from %qs to integral",
13586 operator_string (node),
13587 lang_printable_name (op2_type, 0));
13589 TREE_TYPE (node) = error_mark_node;
13594 /* Unary numeric promotion (5.6.1) is performed on each operand
13596 op1 = do_unary_numeric_promotion (op1);
13597 op2 = do_unary_numeric_promotion (op2);
13599 /* If the right hand side is of type `long', first cast it to
13601 if (TREE_TYPE (op2) == long_type_node)
13602 op2 = build1 (CONVERT_EXPR, int_type_node, op2);
13604 /* The type of the shift expression is the type of the promoted
13605 type of the left-hand operand */
13606 prom_type = TREE_TYPE (op1);
13608 /* Shift int only up to 0x1f and long up to 0x3f */
13609 if (prom_type == int_type_node)
13610 op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
13611 build_int_cst (NULL_TREE, 0x1f)));
13613 op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
13614 build_int_cst (NULL_TREE, 0x3f)));
13616 /* The >>> operator is a >> operating on unsigned quantities */
13617 if (code == URSHIFT_EXPR && ! flag_emit_class_files)
13620 tree utype = java_unsigned_type (prom_type);
13621 op1 = convert (utype, op1);
13622 TREE_SET_CODE (node, RSHIFT_EXPR);
13623 TREE_OPERAND (node, 0) = op1;
13624 TREE_OPERAND (node, 1) = op2;
13625 TREE_TYPE (node) = utype;
13626 to_return = convert (prom_type, node);
13627 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
13628 COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
13629 TREE_SIDE_EFFECTS (to_return)
13630 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13635 /* 15.19.1 Type Comparison Operator instanceof */
13636 case INSTANCEOF_EXPR:
13638 TREE_TYPE (node) = boolean_type_node;
13640 /* OP1_TYPE might be NULL when OP1 is a string constant. */
13641 if ((cn = patch_string (op1)))
13644 op1_type = TREE_TYPE (op1);
13646 if (op1_type == NULL_TREE)
13649 if (!(op2_type = resolve_type_during_patch (op2)))
13650 return error_mark_node;
13652 /* The first operand must be a reference type or the null type */
13653 if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
13654 error_found = 1; /* Error reported further below */
13656 /* The second operand must be a reference type */
13657 if (!JREFERENCE_TYPE_P (op2_type))
13659 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
13660 parse_error_context
13661 (wfl_operator, "Invalid argument %qs for %<instanceof%>",
13662 lang_printable_name (op2_type, 0));
13666 if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
13668 /* If the first operand is null, the result is always false */
13669 if (op1 == null_pointer_node)
13670 return boolean_false_node;
13671 else if (flag_emit_class_files)
13673 TREE_OPERAND (node, 1) = op2_type;
13674 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
13677 /* Otherwise we have to invoke instance of to figure it out */
13679 return build_instanceof (op1, op2_type);
13681 /* There is no way the expression operand can be an instance of
13682 the type operand. This is a compile time error. */
13685 char *t1 = xstrdup (lang_printable_name (op1_type, 0));
13686 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
13687 parse_error_context
13688 (wfl_operator, "Impossible for %qs to be instance of %qs",
13689 t1, lang_printable_name (op2_type, 0));
13696 /* 15.21 Bitwise and Logical Operators */
13700 if (JINTEGRAL_TYPE_P (op1_type) && JINTEGRAL_TYPE_P (op2_type))
13701 /* Binary numeric promotion is performed on both operand and the
13702 expression retain that type */
13703 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13705 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE
13706 && TREE_CODE (op1_type) == BOOLEAN_TYPE)
13707 /* The type of the bitwise operator expression is BOOLEAN */
13708 prom_type = boolean_type_node;
13711 if (!JINTEGRAL_TYPE_P (op1_type))
13712 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
13713 if (!JINTEGRAL_TYPE_P (op2_type) && (op1_type != op2_type))
13714 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op2_type);
13715 TREE_TYPE (node) = error_mark_node;
13717 /* Insert a break here if adding thing before the switch's
13718 break for this case */
13722 /* 15.22 Conditional-And Operator */
13723 case TRUTH_ANDIF_EXPR:
13724 /* 15.23 Conditional-Or Operator */
13725 case TRUTH_ORIF_EXPR:
13726 /* Operands must be of BOOLEAN type */
13727 if (TREE_CODE (op1_type) != BOOLEAN_TYPE ||
13728 TREE_CODE (op2_type) != BOOLEAN_TYPE)
13730 if (TREE_CODE (op1_type) != BOOLEAN_TYPE)
13731 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op1_type);
13732 if (TREE_CODE (op2_type) != BOOLEAN_TYPE && (op1_type != op2_type))
13733 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op2_type);
13734 TREE_TYPE (node) = boolean_type_node;
13738 else if (integer_zerop (op1))
13740 return code == TRUTH_ANDIF_EXPR ? op1 : op2;
13742 else if (integer_onep (op1))
13744 return code == TRUTH_ANDIF_EXPR ? op2 : op1;
13746 /* The type of the conditional operators is BOOLEAN */
13747 prom_type = boolean_type_node;
13750 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
13755 /* The type of each of the operands must be a primitive numeric
13757 if (!JNUMERIC_TYPE_P (op1_type) || ! JNUMERIC_TYPE_P (op2_type))
13759 if (!JNUMERIC_TYPE_P (op1_type))
13760 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13761 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13762 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13763 TREE_TYPE (node) = boolean_type_node;
13767 /* Binary numeric promotion is performed on the operands */
13768 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13769 /* The type of the relation expression is always BOOLEAN */
13770 prom_type = boolean_type_node;
13773 /* 15.20 Equality Operator */
13776 /* It's time for us to patch the strings. */
13777 if ((cn = patch_string (op1)))
13780 op1_type = TREE_TYPE (op1);
13782 if ((cn = patch_string (op2)))
13785 op2_type = TREE_TYPE (op2);
13788 /* 15.20.1 Numerical Equality Operators == and != */
13789 /* Binary numeric promotion is performed on the operands */
13790 if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
13791 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13793 /* 15.20.2 Boolean Equality Operators == and != */
13794 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE &&
13795 TREE_CODE (op2_type) == BOOLEAN_TYPE)
13796 ; /* Nothing to do here */
13798 /* 15.20.3 Reference Equality Operators == and != */
13799 /* Types have to be either references or the null type. If
13800 they're references, it must be possible to convert either
13801 type to the other by casting conversion. */
13802 else if (op1 == null_pointer_node || op2 == null_pointer_node
13803 || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
13804 && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
13805 || valid_ref_assignconv_cast_p (op2_type,
13807 ; /* Nothing to do here */
13809 /* Else we have an error figure what can't be converted into
13810 what and report the error */
13814 t1 = xstrdup (lang_printable_name (op1_type, 0));
13815 parse_error_context
13817 "Incompatible type for %qs. Can't convert %qs to %qs",
13818 operator_string (node), t1,
13819 lang_printable_name (op2_type, 0));
13821 TREE_TYPE (node) = boolean_type_node;
13825 prom_type = boolean_type_node;
13832 return error_mark_node;
13834 TREE_OPERAND (node, 0) = op1;
13835 TREE_OPERAND (node, 1) = op2;
13836 TREE_TYPE (node) = prom_type;
13837 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13839 if (flag_emit_xref)
13842 /* fold does not respect side-effect order as required for Java but not C.
13843 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
13846 if (flag_emit_class_files ? (TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
13847 : ! TREE_SIDE_EFFECTS (node))
13848 node = fold (node);
13852 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
13853 zero value, the value of CSTE comes after the valude of STRING */
13856 do_merge_string_cste (tree cste, const char *string, int string_len, int after)
13858 const char *old = TREE_STRING_POINTER (cste);
13859 int old_len = TREE_STRING_LENGTH (cste);
13860 int len = old_len + string_len;
13861 char *new = alloca (len+1);
13865 memcpy (new, string, string_len);
13866 memcpy (&new [string_len], old, old_len);
13870 memcpy (new, old, old_len);
13871 memcpy (&new [old_len], string, string_len);
13874 return build_string (len, new);
13877 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
13878 new STRING_CST on success, NULL_TREE on failure. */
13881 merge_string_cste (tree op1, tree op2, int after)
13883 /* Handle two string constants right away. */
13884 if (TREE_CODE (op2) == STRING_CST)
13885 return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
13886 TREE_STRING_LENGTH (op2), after);
13888 /* Reasonable integer constant can be treated right away. */
13889 if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
13891 static const char *const boolean_true = "true";
13892 static const char *const boolean_false = "false";
13893 static const char *const null_pointer = "null";
13895 const char *string;
13897 if (op2 == boolean_true_node)
13898 string = boolean_true;
13899 else if (op2 == boolean_false_node)
13900 string = boolean_false;
13901 else if (op2 == null_pointer_node
13902 || (integer_zerop (op2)
13903 && TREE_CODE (TREE_TYPE (op2)) == POINTER_TYPE))
13904 /* FIXME: null is not a compile-time constant, so it is only safe to
13905 merge if the overall expression is non-constant. However, this
13906 code always merges without checking the overall expression. */
13907 string = null_pointer;
13908 else if (TREE_TYPE (op2) == char_type_node)
13910 /* Convert the character into UTF-8. */
13911 unsigned int c = (unsigned int) TREE_INT_CST_LOW (op2);
13912 unsigned char *p = (unsigned char *) ch;
13913 if (0x01 <= c && c <= 0x7f)
13914 *p++ = (unsigned char) c;
13915 else if (c < 0x7ff)
13917 *p++ = (unsigned char) (c >> 6 | 0xc0);
13918 *p++ = (unsigned char) ((c & 0x3f) | 0x80);
13922 *p++ = (unsigned char) (c >> 12 | 0xe0);
13923 *p++ = (unsigned char) (((c >> 6) & 0x3f) | 0x80);
13924 *p++ = (unsigned char) ((c & 0x3f) | 0x80);
13931 string = string_convert_int_cst (op2);
13933 return do_merge_string_cste (op1, string, strlen (string), after);
13938 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
13939 has to be a STRING_CST and the other part must be a STRING_CST or a
13940 INTEGRAL constant. Return a new STRING_CST if the operation
13941 succeed, NULL_TREE otherwise.
13943 If the case we want to optimize for space, we might want to return
13944 NULL_TREE for each invocation of this routine. FIXME */
13947 string_constant_concatenation (tree op1, tree op2)
13949 if (TREE_CODE (op1) == STRING_CST || (TREE_CODE (op2) == STRING_CST))
13954 string = (TREE_CODE (op1) == STRING_CST ? op1 : op2);
13955 rest = (string == op1 ? op2 : op1);
13956 invert = (string == op1 ? 0 : 1 );
13958 /* Walk REST, only if it looks reasonable */
13959 if (TREE_CODE (rest) != STRING_CST
13960 && !IS_CRAFTED_STRING_BUFFER_P (rest)
13961 && !JSTRING_TYPE_P (TREE_TYPE (rest))
13962 && TREE_CODE (rest) == EXPR_WITH_FILE_LOCATION)
13964 rest = java_complete_tree (rest);
13965 if (rest == error_mark_node)
13966 return error_mark_node;
13967 rest = fold (rest);
13969 return merge_string_cste (string, rest, invert);
13974 /* Implement the `+' operator. Does static optimization if possible,
13975 otherwise create (if necessary) and append elements to a
13976 StringBuffer. The StringBuffer will be carried around until it is
13977 used for a function call or an assignment. Then toString() will be
13978 called on it to turn it into a String object. */
13981 build_string_concatenation (tree op1, tree op2)
13984 int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13986 if (flag_emit_xref)
13987 return build2 (PLUS_EXPR, string_type_node, op1, op2);
13989 /* Try to do some static optimization */
13990 if ((result = string_constant_concatenation (op1, op2)))
13993 /* Discard empty strings on either side of the expression */
13994 if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
13999 else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
14002 /* If operands are string constant, turn then into object references */
14003 if (TREE_CODE (op1) == STRING_CST)
14004 op1 = patch_string_cst (op1);
14005 if (op2 && TREE_CODE (op2) == STRING_CST)
14006 op2 = patch_string_cst (op2);
14008 /* If either one of the constant is null and the other non null
14009 operand is a String constant, return it. */
14010 if ((TREE_CODE (op1) == STRING_CST) && !op2)
14013 /* If OP1 isn't already a StringBuffer, create and
14014 initialize a new one */
14015 if (!IS_CRAFTED_STRING_BUFFER_P (op1))
14017 /* Two solutions here:
14018 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
14019 2) OP1 is something else, we call new StringBuffer().append(OP1). */
14020 if (TREE_CONSTANT (op1) && JSTRING_TYPE_P (TREE_TYPE (op1)))
14021 op1 = BUILD_STRING_BUFFER (op1);
14024 tree aNew = BUILD_STRING_BUFFER (NULL_TREE);
14025 op1 = make_qualified_primary (aNew, BUILD_APPEND (op1), 0);
14031 /* OP1 is no longer the last node holding a crafted StringBuffer */
14032 IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
14033 /* Create a node for `{new...,xxx}.append (op2)' */
14035 op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
14038 /* Mark the last node holding a crafted StringBuffer */
14039 IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
14041 TREE_SIDE_EFFECTS (op1) = side_effects;
14045 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
14046 StringBuffer. If no string were found to be patched, return
14050 patch_string (tree node)
14052 if (node == error_mark_node)
14053 return error_mark_node;
14054 if (TREE_CODE (node) == STRING_CST)
14055 return patch_string_cst (node);
14056 else if (IS_CRAFTED_STRING_BUFFER_P (node))
14058 int saved = ctxp->explicit_constructor_p;
14059 tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
14061 /* Temporary disable forbid the use of `this'. */
14062 ctxp->explicit_constructor_p = 0;
14063 ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
14064 /* String concatenation arguments must be evaluated in order too. */
14065 ret = force_evaluation_order (ret);
14066 /* Restore it at its previous value */
14067 ctxp->explicit_constructor_p = saved;
14073 /* Build the internal representation of a string constant. */
14076 patch_string_cst (tree node)
14079 if (! flag_emit_class_files)
14081 node = get_identifier (TREE_STRING_POINTER (node));
14082 location = alloc_name_constant (CONSTANT_String, node);
14083 node = build_ref_from_constant_pool (location);
14085 TREE_CONSTANT (node) = 1;
14086 TREE_INVARIANT (node) = 1;
14088 /* ??? Guessing that the class file code can't handle casts. */
14089 if (! flag_emit_class_files)
14090 node = convert (string_ptr_type_node, node);
14092 TREE_TYPE (node) = string_ptr_type_node;
14097 /* Build an incomplete unary operator expression. */
14100 build_unaryop (int op_token, int op_location, tree op1)
14106 case PLUS_TK: op = UNARY_PLUS_EXPR; break;
14107 case MINUS_TK: op = NEGATE_EXPR; break;
14108 case NEG_TK: op = TRUTH_NOT_EXPR; break;
14109 case NOT_TK: op = BIT_NOT_EXPR; break;
14113 unaryop = build1 (op, NULL_TREE, op1);
14114 TREE_SIDE_EFFECTS (unaryop) = 1;
14115 /* Store the location of the operator, for better error report. The
14116 string of the operator will be rebuild based on the OP value. */
14117 EXPR_WFL_LINECOL (unaryop) = op_location;
14121 /* Special case for the ++/-- operators, since they require an extra
14122 argument to build, which is set to NULL and patched
14123 later. IS_POST_P is 1 if the operator, 0 otherwise. */
14126 build_incdec (int op_token, int op_location, tree op1, int is_post_p)
14128 static const enum tree_code lookup [2][2] =
14130 { PREDECREMENT_EXPR, PREINCREMENT_EXPR, },
14131 { POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, },
14133 tree node = build2 (lookup [is_post_p][(op_token - DECR_TK)],
14134 NULL_TREE, op1, NULL_TREE);
14135 TREE_SIDE_EFFECTS (node) = 1;
14136 /* Store the location of the operator, for better error report. The
14137 string of the operator will be rebuild based on the OP value. */
14138 EXPR_WFL_LINECOL (node) = op_location;
14142 /* Build an incomplete cast operator, based on the use of the
14143 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
14144 set. java_complete_tree is trained to walk a CONVERT_EXPR even
14145 though its type is already set. */
14148 build_cast (int location, tree type, tree exp)
14150 tree node = build1 (CONVERT_EXPR, type, exp);
14151 EXPR_WFL_LINECOL (node) = location;
14155 /* Build an incomplete class reference operator. */
14157 build_incomplete_class_ref (int location, tree class_name)
14159 tree node = build1 (CLASS_LITERAL, NULL_TREE, class_name);
14160 tree class_decl = GET_CPC ();
14161 tree this_class = TREE_TYPE (class_decl);
14163 /* Generate the synthetic static method `class$'. (Previously we
14164 deferred this, causing different method tables to be emitted
14165 for native code and bytecode.) */
14166 if (!TYPE_DOT_CLASS (this_class)
14167 && !JPRIMITIVE_TYPE_P (class_name)
14168 && !(TREE_CODE (class_name) == VOID_TYPE))
14170 tree cpc_list = GET_CPC_LIST();
14171 tree cpc = cpc_list;
14174 /* For inner classes, add a 'class$' method to their outermost
14175 context, creating it if necessary. */
14177 while (GET_NEXT_ENCLOSING_CPC(cpc))
14178 cpc = GET_NEXT_ENCLOSING_CPC(cpc);
14179 class_decl = TREE_VALUE (cpc);
14181 target_class = TREE_TYPE (class_decl);
14183 if (CLASS_INTERFACE (TYPE_NAME (target_class)))
14185 /* For interfaces, adding a static 'class$' method directly
14186 is illegal. So create an inner class to contain the new
14187 method. Empirically this matches the behavior of javac. */
14189 /* We want the generated inner class inside the outermost class. */
14190 GET_CPC_LIST() = cpc;
14191 t = build_wfl_node (DECL_NAME (TYPE_NAME (object_type_node)));
14192 inner = create_anonymous_class (t);
14193 target_class = TREE_TYPE (inner);
14194 end_class_declaration (1);
14195 GET_CPC_LIST() = cpc_list;
14198 if (TYPE_DOT_CLASS (target_class) == NULL_TREE)
14199 build_dot_class_method (target_class);
14201 if (this_class != target_class)
14202 TYPE_DOT_CLASS (this_class) = TYPE_DOT_CLASS (target_class);
14205 EXPR_WFL_LINECOL (node) = location;
14209 /* Complete an incomplete class reference operator. */
14211 patch_incomplete_class_ref (tree node)
14213 tree type = TREE_OPERAND (node, 0);
14216 if (!(ref_type = resolve_type_during_patch (type)))
14217 return error_mark_node;
14219 /* If we're not emitting class files and we know ref_type is a
14220 compiled class, build a direct reference. */
14221 if ((! flag_emit_class_files && is_compiled_class (ref_type))
14222 || JPRIMITIVE_TYPE_P (ref_type)
14223 || TREE_CODE (ref_type) == VOID_TYPE)
14225 tree dot = build_class_ref (ref_type);
14226 /* A class referenced by `foo.class' is initialized. */
14227 if (!flag_emit_class_files)
14228 dot = build_class_init (ref_type, dot);
14229 return java_complete_tree (dot);
14232 /* If we're emitting class files and we have to deal with non
14233 primitive types, we invoke the synthetic static method `class$'. */
14234 ref_type = build_dot_class_method_invocation (current_class, ref_type);
14235 return java_complete_tree (ref_type);
14238 /* 15.14 Unary operators. We return error_mark_node in case of error,
14239 but preserve the type of NODE if the type is fixed. */
14242 patch_unaryop (tree node, tree wfl_op)
14244 tree op = TREE_OPERAND (node, 0);
14245 tree op_type = TREE_TYPE (op);
14246 tree prom_type = NULL_TREE, value, decl;
14247 int outer_field_flag = 0;
14248 int code = TREE_CODE (node);
14249 int error_found = 0;
14251 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14255 /* 15.13.2 Postfix Increment Operator ++ */
14256 case POSTINCREMENT_EXPR:
14257 /* 15.13.3 Postfix Increment Operator -- */
14258 case POSTDECREMENT_EXPR:
14259 /* 15.14.1 Prefix Increment Operator ++ */
14260 case PREINCREMENT_EXPR:
14261 /* 15.14.2 Prefix Decrement Operator -- */
14262 case PREDECREMENT_EXPR:
14263 op = decl = strip_out_static_field_access_decl (op);
14264 outer_field_flag = outer_field_expanded_access_p (op, NULL, NULL, NULL);
14265 /* We might be trying to change an outer field accessed using
14267 if (outer_field_flag)
14269 /* Retrieve the decl of the field we're trying to access. We
14270 do that by first retrieving the function we would call to
14271 access the field. It has been already verified that this
14272 field isn't final */
14273 if (flag_emit_class_files)
14274 decl = TREE_OPERAND (op, 0);
14276 decl = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (op, 0), 0), 0);
14277 decl = DECL_FUNCTION_ACCESS_DECL (decl);
14279 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
14280 else if (!JDECL_P (decl)
14281 && TREE_CODE (decl) != COMPONENT_REF
14282 && !(flag_emit_class_files && TREE_CODE (decl) == ARRAY_REF)
14283 && TREE_CODE (decl) != INDIRECT_REF
14284 && !(TREE_CODE (decl) == COMPOUND_EXPR
14285 && TREE_OPERAND (decl, 1)
14286 && (TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)))
14288 TREE_TYPE (node) = error_mark_node;
14292 /* From now on, we know that op if a variable and that it has a
14293 valid wfl. We use wfl_op to locate errors related to the
14295 if (!JNUMERIC_TYPE_P (op_type))
14297 parse_error_context
14298 (wfl_op, "Invalid argument type %qs to %qs",
14299 lang_printable_name (op_type, 0), operator_string (node));
14300 TREE_TYPE (node) = error_mark_node;
14305 /* Before the addition, binary numeric promotion is performed on
14306 both operands, if really necessary */
14307 if (JINTEGRAL_TYPE_P (op_type))
14309 value = build_int_cst (op_type, 1);
14310 TREE_TYPE (node) = op_type;
14314 value = build_int_cst (NULL_TREE, 1);
14316 binary_numeric_promotion (op_type,
14317 TREE_TYPE (value), &op, &value);
14320 /* We remember we might be accessing an outer field */
14321 if (outer_field_flag)
14323 /* We re-generate an access to the field */
14324 value = build2 (PLUS_EXPR, TREE_TYPE (op),
14325 build_outer_field_access (wfl_op, decl), value);
14327 /* And we patch the original access$() into a write
14328 with plus_op as a rhs */
14329 return outer_field_access_fix (node, op, value);
14332 /* And write back into the node. */
14333 TREE_OPERAND (node, 0) = op;
14334 TREE_OPERAND (node, 1) = value;
14335 /* Convert the overall back into its original type, if
14336 necessary, and return */
14337 if (JINTEGRAL_TYPE_P (op_type))
14338 return fold (node);
14340 return fold (convert (op_type, node));
14344 /* 15.14.3 Unary Plus Operator + */
14345 case UNARY_PLUS_EXPR:
14346 /* 15.14.4 Unary Minus Operator - */
14348 if (!JNUMERIC_TYPE_P (op_type))
14350 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op_type);
14351 TREE_TYPE (node) = error_mark_node;
14354 /* Unary numeric promotion is performed on operand */
14357 op = do_unary_numeric_promotion (op);
14358 prom_type = TREE_TYPE (op);
14359 if (code == UNARY_PLUS_EXPR)
14364 /* 15.14.5 Bitwise Complement Operator ~ */
14366 if (!JINTEGRAL_TYPE_P (op_type))
14368 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op_type);
14369 TREE_TYPE (node) = error_mark_node;
14374 op = do_unary_numeric_promotion (op);
14375 prom_type = TREE_TYPE (op);
14379 /* 15.14.6 Logical Complement Operator ! */
14380 case TRUTH_NOT_EXPR:
14381 if (TREE_CODE (op_type) != BOOLEAN_TYPE)
14383 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
14384 /* But the type is known. We will report an error if further
14385 attempt of a assignment is made with this rhs */
14386 TREE_TYPE (node) = boolean_type_node;
14390 prom_type = boolean_type_node;
14393 /* 15.15 Cast Expression */
14395 value = patch_cast (node, wfl_operator);
14396 if (value == error_mark_node)
14398 /* If this cast is part of an assignment, we tell the code
14399 that deals with it not to complain about a mismatch,
14400 because things have been cast, anyways */
14401 TREE_TYPE (node) = error_mark_node;
14406 value = fold (value);
14413 return error_mark_node;
14415 /* There are cases where node has been replaced by something else
14416 and we don't end up returning here: UNARY_PLUS_EXPR,
14417 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
14418 TREE_OPERAND (node, 0) = fold (op);
14419 TREE_TYPE (node) = prom_type;
14420 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
14421 return fold (node);
14424 /* Generic type resolution that sometimes takes place during node
14425 patching. Returned the resolved type or generate an error
14426 message. Return the resolved type or NULL_TREE. */
14429 resolve_type_during_patch (tree type)
14431 if (unresolved_type_p (type, NULL))
14433 tree type_decl = resolve_and_layout (EXPR_WFL_NODE (type), type);
14436 parse_error_context (type,
14437 "Class %qs not found in type declaration",
14438 IDENTIFIER_POINTER (EXPR_WFL_NODE (type)));
14442 check_deprecation (type, type_decl);
14444 return TREE_TYPE (type_decl);
14449 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
14450 found. Otherwise NODE or something meant to replace it is returned. */
14453 patch_cast (tree node, tree wfl_op)
14455 tree op = TREE_OPERAND (node, 0);
14456 tree cast_type = TREE_TYPE (node);
14457 tree patched, op_type;
14460 /* Some string patching might be necessary at this stage */
14461 if ((patched = patch_string (op)))
14462 TREE_OPERAND (node, 0) = op = patched;
14463 op_type = TREE_TYPE (op);
14465 /* First resolve OP_TYPE if unresolved */
14466 if (!(cast_type = resolve_type_during_patch (cast_type)))
14467 return error_mark_node;
14469 /* Check on cast that are proven correct at compile time */
14470 if (JNUMERIC_TYPE_P (cast_type) && JNUMERIC_TYPE_P (op_type))
14473 if (cast_type == op_type)
14476 /* A narrowing conversion from a floating-point number to an
14477 integral type requires special handling (5.1.3). */
14478 if (JFLOAT_TYPE_P (op_type) && JINTEGRAL_TYPE_P (cast_type))
14479 if (cast_type != long_type_node)
14480 op = convert (integer_type_node, op);
14482 /* Try widening/narrowing conversion. Potentially, things need
14483 to be worked out in gcc so we implement the extreme cases
14484 correctly. fold_convert() needs to be fixed. */
14485 return convert (cast_type, op);
14488 /* It's also valid to cast a boolean into a boolean */
14489 if (op_type == boolean_type_node && cast_type == boolean_type_node)
14492 /* null can be casted to references */
14493 if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
14494 return build_null_of_type (cast_type);
14496 /* The remaining legal casts involve conversion between reference
14497 types. Check for their compile time correctness. */
14498 if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type)
14499 && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
14501 TREE_TYPE (node) = promote_type (cast_type);
14502 /* Now, the case can be determined correct at compile time if
14503 OP_TYPE can be converted into CAST_TYPE by assignment
14504 conversion (5.2) */
14506 if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
14508 TREE_SET_CODE (node, NOP_EXPR);
14512 if (flag_emit_class_files)
14514 TREE_SET_CODE (node, CONVERT_EXPR);
14518 /* The cast requires a run-time check */
14519 return build3 (CALL_EXPR, promote_type (cast_type),
14520 build_address_of (soft_checkcast_node),
14521 tree_cons (NULL_TREE, build_class_ref (cast_type),
14522 build_tree_list (NULL_TREE, op)),
14526 /* Any other casts are proven incorrect at compile time */
14527 t1 = xstrdup (lang_printable_name (op_type, 0));
14528 parse_error_context (wfl_op, "Invalid cast from %qs to %qs",
14529 t1, lang_printable_name (cast_type, 0));
14531 return error_mark_node;
14534 /* Build a null constant and give it the type TYPE. */
14537 build_null_of_type (tree type)
14539 tree node = build_int_cst (promote_type (type), 0);
14543 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
14544 a list of indices. */
14546 build_array_ref (int location, tree array, tree index)
14548 tree node = build4 (ARRAY_REF, NULL_TREE, array, index,
14549 NULL_TREE, NULL_TREE);
14550 EXPR_WFL_LINECOL (node) = location;
14554 /* 15.12 Array Access Expression */
14557 patch_array_ref (tree node)
14559 tree array = TREE_OPERAND (node, 0);
14560 tree array_type = TREE_TYPE (array);
14561 tree index = TREE_OPERAND (node, 1);
14562 tree index_type = TREE_TYPE (index);
14563 int error_found = 0;
14565 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14567 if (TREE_CODE (array_type) == POINTER_TYPE)
14568 array_type = TREE_TYPE (array_type);
14570 /* The array reference must be an array */
14571 if (!TYPE_ARRAY_P (array_type))
14573 parse_error_context
14575 "%<[]%> can only be applied to arrays. It can't be applied to %qs",
14576 lang_printable_name (array_type, 0));
14577 TREE_TYPE (node) = error_mark_node;
14581 /* The array index undergoes unary numeric promotion. The promoted
14582 type must be int */
14583 index = do_unary_numeric_promotion (index);
14584 if (TREE_TYPE (index) != int_type_node)
14586 if (valid_cast_to_p (index_type, int_type_node))
14587 parse_error_context (wfl_operator,
14588 "Incompatible type for %<[]%>. Explicit cast needed to convert %qs to %<int%>",
14589 lang_printable_name (index_type, 0));
14591 parse_error_context (wfl_operator,
14592 "Incompatible type for %<[]%>. Can't convert %qs to %<int%>",
14593 lang_printable_name (index_type, 0));
14594 TREE_TYPE (node) = error_mark_node;
14599 return error_mark_node;
14601 array_type = TYPE_ARRAY_ELEMENT (array_type);
14603 if (flag_emit_class_files || flag_emit_xref)
14605 TREE_OPERAND (node, 0) = array;
14606 TREE_OPERAND (node, 1) = index;
14609 node = build_java_arrayaccess (array, array_type, index);
14610 TREE_TYPE (node) = array_type;
14614 /* 15.9 Array Creation Expressions */
14617 build_newarray_node (tree type, tree dims, int extra_dims)
14619 tree node = build3 (NEW_ARRAY_EXPR, NULL_TREE, type,
14621 build_int_cst (NULL_TREE, extra_dims));
14626 patch_newarray (tree node)
14628 tree type = TREE_OPERAND (node, 0);
14629 tree dims = TREE_OPERAND (node, 1);
14630 tree cdim, array_type;
14631 int error_found = 0;
14633 int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
14635 /* Dimension types are verified. It's better for the types to be
14636 verified in order. */
14637 for (cdim = dims, ndims = 0; cdim; cdim = TREE_CHAIN (cdim), ndims++ )
14640 tree dim = TREE_VALUE (cdim);
14642 /* Dim might have been saved during its evaluation */
14643 dim = (TREE_CODE (dim) == SAVE_EXPR ? TREE_OPERAND (dim, 0) : dim);
14645 /* The type of each specified dimension must be an integral type. */
14646 if (!JINTEGRAL_TYPE_P (TREE_TYPE (dim)))
14649 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
14650 promoted type must be int. */
14653 dim = do_unary_numeric_promotion (dim);
14654 if (TREE_TYPE (dim) != int_type_node)
14658 /* Report errors on types here */
14661 parse_error_context
14662 (TREE_PURPOSE (cdim),
14663 "Incompatible type for dimension in array creation expression. %s convert %qs to %<int%>",
14664 (valid_cast_to_p (TREE_TYPE (dim), int_type_node) ?
14665 "Explicit cast needed to" : "Can't"),
14666 lang_printable_name (TREE_TYPE (dim), 0));
14670 TREE_PURPOSE (cdim) = NULL_TREE;
14673 /* Resolve array base type if unresolved */
14674 if (!(type = resolve_type_during_patch (type)))
14679 /* We don't want further evaluation of this bogus array creation
14681 TREE_TYPE (node) = error_mark_node;
14682 return error_mark_node;
14685 /* Set array_type to the actual (promoted) array type of the result. */
14686 if (TREE_CODE (type) == RECORD_TYPE)
14687 type = build_pointer_type (type);
14688 while (--xdims >= 0)
14690 type = promote_type (build_java_array_type (type, -1));
14692 dims = nreverse (dims);
14694 for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
14698 = build_java_array_type (type,
14699 TREE_CODE (cdim) == INTEGER_CST
14700 ? (HOST_WIDE_INT) TREE_INT_CST_LOW (cdim)
14702 array_type = promote_type (array_type);
14704 dims = nreverse (dims);
14706 /* The node is transformed into a function call. Things are done
14707 differently according to the number of dimensions. If the number
14708 of dimension is equal to 1, then the nature of the base type
14709 (primitive or not) matters. */
14711 return build_new_array (type, TREE_VALUE (dims));
14713 /* Can't reuse what's already written in expr.c because it uses the
14714 JVM stack representation. Provide a build_multianewarray. FIXME */
14715 return build3 (CALL_EXPR, array_type,
14716 build_address_of (soft_multianewarray_node),
14717 tree_cons (NULL_TREE,
14718 build_class_ref (TREE_TYPE (array_type)),
14719 tree_cons (NULL_TREE,
14720 build_int_cst (NULL_TREE, ndims),
14725 /* 10.6 Array initializer. */
14727 /* Build a wfl for array element that don't have one, so we can
14728 pin-point errors. */
14731 maybe_build_array_element_wfl (tree node)
14733 if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
14735 /* FIXME - old code used "prev_lc.line" and "elc.prev_col */
14736 return build_expr_wfl (NULL_TREE,
14737 #ifdef USE_MAPPED_LOCATION
14741 ctxp->lexer->token_start.line,
14742 ctxp->lexer->token_start.col
14750 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
14751 identification of initialized arrays easier to detect during walk
14755 build_new_array_init (int location, tree values)
14757 tree constructor = build_constructor (NULL_TREE, values);
14758 tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
14759 EXPR_WFL_LINECOL (to_return) = location;
14763 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
14764 occurred. Otherwise return NODE after having set its type
14768 patch_new_array_init (tree type, tree node)
14770 int error_seen = 0;
14771 tree current, element_type;
14772 HOST_WIDE_INT length;
14773 int all_constant = 1;
14774 tree init = TREE_OPERAND (node, 0);
14776 if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
14778 parse_error_context (node,
14779 "Invalid array initializer for non-array type %qs",
14780 lang_printable_name (type, 1));
14781 return error_mark_node;
14783 type = TREE_TYPE (type);
14784 element_type = TYPE_ARRAY_ELEMENT (type);
14786 CONSTRUCTOR_ELTS (init) = nreverse (CONSTRUCTOR_ELTS (init));
14788 for (length = 0, current = CONSTRUCTOR_ELTS (init);
14789 current; length++, current = TREE_CHAIN (current))
14791 tree elt = TREE_VALUE (current);
14792 if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
14794 error_seen |= array_constructor_check_entry (element_type, current);
14795 elt = TREE_VALUE (current);
14796 /* When compiling to native code, STRING_CST is converted to
14797 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
14798 if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
14803 TREE_VALUE (current) = patch_new_array_init (element_type, elt);
14804 TREE_PURPOSE (current) = NULL_TREE;
14807 if (elt && TREE_CODE (elt) == TREE_LIST
14808 && TREE_VALUE (elt) == error_mark_node)
14813 return error_mark_node;
14815 /* Create a new type. We can't reuse the one we have here by
14816 patching its dimension because it originally is of dimension -1
14817 hence reused by gcc. This would prevent triangular arrays. */
14818 type = build_java_array_type (element_type, length);
14819 TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
14820 TREE_TYPE (node) = promote_type (type);
14821 TREE_CONSTANT (init) = all_constant;
14822 TREE_INVARIANT (init) = all_constant;
14823 TREE_CONSTANT (node) = all_constant;
14824 TREE_INVARIANT (node) = all_constant;
14828 /* Verify that one entry of the initializer element list can be
14829 assigned to the array base type. Report 1 if an error occurred, 0
14833 array_constructor_check_entry (tree type, tree entry)
14835 char *array_type_string = NULL; /* For error reports */
14836 tree value, type_value, new_value, wfl_value, patched;
14837 int error_seen = 0;
14839 new_value = NULL_TREE;
14840 wfl_value = TREE_VALUE (entry);
14842 value = java_complete_tree (TREE_VALUE (entry));
14843 /* patch_string return error_mark_node if arg is error_mark_node */
14844 if ((patched = patch_string (value)))
14846 if (value == error_mark_node)
14849 type_value = TREE_TYPE (value);
14851 /* At anytime, try_builtin_assignconv can report a warning on
14852 constant overflow during narrowing. */
14853 SET_WFL_OPERATOR (wfl_operator, TREE_PURPOSE (entry), wfl_value);
14854 new_value = try_builtin_assignconv (wfl_operator, type, value);
14855 if (!new_value && (new_value = try_reference_assignconv (type, value)))
14856 type_value = promote_type (type);
14858 /* Check and report errors */
14861 const char *const msg = (!valid_cast_to_p (type_value, type) ?
14862 "Can't" : "Explicit cast needed to");
14863 if (!array_type_string)
14864 array_type_string = xstrdup (lang_printable_name (type, 1));
14865 parse_error_context
14866 (wfl_operator, "Incompatible type for array. %s convert %qs to %qs",
14867 msg, lang_printable_name (type_value, 1), array_type_string);
14872 TREE_VALUE (entry) = new_value;
14874 if (array_type_string)
14875 free (array_type_string);
14877 TREE_PURPOSE (entry) = NULL_TREE;
14882 build_this (int location)
14884 tree node = build_wfl_node (this_identifier_node);
14885 TREE_SET_CODE (node, THIS_EXPR);
14886 EXPR_WFL_LINECOL (node) = location;
14890 /* 14.15 The return statement. It builds a modify expression that
14891 assigns the returned value to the RESULT_DECL that hold the value
14895 build_return (int location, tree op)
14897 tree node = build1 (RETURN_EXPR, NULL_TREE, op);
14898 EXPR_WFL_LINECOL (node) = location;
14899 node = build_debugable_stmt (location, node);
14904 patch_return (tree node)
14906 tree return_exp = TREE_OPERAND (node, 0);
14907 tree meth = current_function_decl;
14908 tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
14909 int error_found = 0;
14911 TREE_TYPE (node) = error_mark_node;
14912 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14914 /* It's invalid to have a return value within a function that is
14915 declared with the keyword void or that is a constructor */
14916 if (return_exp && (mtype == void_type_node || DECL_CONSTRUCTOR_P (meth)))
14919 /* It's invalid to use a return statement in a static block */
14920 if (DECL_CLINIT_P (current_function_decl))
14923 /* It's invalid to have a no return value within a function that
14924 isn't declared with the keyword `void' */
14925 if (!return_exp && (mtype != void_type_node && !DECL_CONSTRUCTOR_P (meth)))
14928 if (DECL_INSTINIT_P (current_function_decl))
14933 if (DECL_INSTINIT_P (current_function_decl))
14934 parse_error_context (wfl_operator,
14935 "%<return%> inside instance initializer");
14937 else if (DECL_CLINIT_P (current_function_decl))
14938 parse_error_context (wfl_operator,
14939 "%<return%> inside static initializer");
14941 else if (!DECL_CONSTRUCTOR_P (meth))
14943 char *t = xstrdup (lang_printable_name (mtype, 0));
14944 parse_error_context (wfl_operator,
14945 "%<return%> with%s value from %<%s %s%>",
14946 (error_found == 1 ? "" : "out"),
14947 t, lang_printable_name (meth, 2));
14951 parse_error_context (wfl_operator,
14952 "%<return%> with value from constructor %qs",
14953 lang_printable_name (meth, 2));
14954 return error_mark_node;
14957 /* If we have a return_exp, build a modify expression and expand
14958 it. Note: at that point, the assignment is declared valid, but we
14959 may want to carry some more hacks */
14962 tree exp = java_complete_tree (return_exp);
14963 tree modify, patched;
14965 if ((patched = patch_string (exp)))
14968 modify = build2 (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
14969 EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
14970 modify = java_complete_tree (modify);
14972 if (modify != error_mark_node)
14974 TREE_SIDE_EFFECTS (modify) = 1;
14975 TREE_OPERAND (node, 0) = modify;
14978 return error_mark_node;
14980 TREE_TYPE (node) = void_type_node;
14981 TREE_SIDE_EFFECTS (node) = 1;
14985 /* 14.8 The if Statement */
14988 build_if_else_statement (int location, tree expression, tree if_body,
14993 else_body = build_java_empty_stmt ();
14994 node = build3 (COND_EXPR, NULL_TREE, expression, if_body, else_body);
14995 EXPR_WFL_LINECOL (node) = location;
14996 node = build_debugable_stmt (location, node);
15001 patch_if_else_statement (tree node)
15003 tree expression = TREE_OPERAND (node, 0);
15004 int can_complete_normally
15005 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
15006 | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2)));
15008 TREE_TYPE (node) = error_mark_node;
15009 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15011 /* The type of expression must be boolean */
15012 if (TREE_TYPE (expression) != boolean_type_node
15013 && TREE_TYPE (expression) != promoted_boolean_type_node)
15015 parse_error_context
15017 "Incompatible type for %<if%>. Can't convert %qs to %<boolean%>",
15018 lang_printable_name (TREE_TYPE (expression), 0));
15019 return error_mark_node;
15022 TREE_TYPE (node) = void_type_node;
15023 TREE_SIDE_EFFECTS (node) = 1;
15024 CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
15028 /* 14.6 Labeled Statements */
15030 /* Action taken when a labeled statement is parsed. a new
15031 LABELED_BLOCK_EXPR is created. No statement is attached to the
15032 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
15035 build_labeled_block (int location, tree label)
15038 tree label_decl, node;
15039 if (label == NULL_TREE || label == continue_identifier_node)
15040 label_name = label;
15043 label_name = merge_qualified_name (label_id, label);
15044 /* Issue an error if we try to reuse a label that was previously
15046 if (IDENTIFIER_LOCAL_VALUE (label_name))
15048 EXPR_WFL_LINECOL (wfl_operator) = location;
15049 parse_error_context (wfl_operator,
15050 "Declaration of %qs shadows a previous label declaration",
15051 IDENTIFIER_POINTER (label));
15052 EXPR_WFL_LINECOL (wfl_operator) =
15053 EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
15054 parse_error_context (wfl_operator,
15055 "This is the location of the previous declaration of label %qs",
15056 IDENTIFIER_POINTER (label));
15057 java_error_count--;
15061 label_decl = create_label_decl (label_name);
15062 node = build2 (LABELED_BLOCK_EXPR, NULL_TREE, label_decl, NULL_TREE);
15063 EXPR_WFL_LINECOL (node) = location;
15064 TREE_SIDE_EFFECTS (node) = 1;
15068 /* A labeled statement LBE is attached a statement. */
15071 finish_labeled_statement (tree lbe, /* Labeled block expr */
15074 /* In anyways, tie the loop to its statement */
15075 LABELED_BLOCK_BODY (lbe) = statement;
15076 pop_labeled_block ();
15077 POP_LABELED_BLOCK ();
15081 /* 14.10, 14.11, 14.12 Loop Statements */
15083 /* Create an empty LOOP_EXPR and make it the last in the nested loop
15087 build_new_loop (tree loop_body)
15089 tree loop = build1 (LOOP_EXPR, NULL_TREE, loop_body);
15090 TREE_SIDE_EFFECTS (loop) = 1;
15095 /* Create a loop body according to the following structure:
15097 COMPOUND_EXPR (loop main body)
15098 EXIT_EXPR (this order is for while/for loops.
15099 LABELED_BLOCK_EXPR the order is reversed for do loops)
15100 LABEL_DECL (a continue occurring here branches at the
15101 BODY end of this labeled block)
15104 REVERSED, if nonzero, tells that the loop condition expr comes
15105 after the body, like in the do-while loop.
15107 To obtain a loop, the loop body structure described above is
15108 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
15111 LABEL_DECL (use this label to exit the loop)
15113 <structure described above> */
15116 build_loop_body (int location, tree condition, int reversed)
15118 tree first, second, body;
15120 condition = build1 (EXIT_EXPR, NULL_TREE, condition); /* Force walk */
15121 EXPR_WFL_LINECOL (condition) = location; /* For accurate error report */
15122 condition = build_debugable_stmt (location, condition);
15123 TREE_SIDE_EFFECTS (condition) = 1;
15125 body = build_labeled_block (0, continue_identifier_node);
15126 first = (reversed ? body : condition);
15127 second = (reversed ? condition : body);
15128 return build2 (COMPOUND_EXPR, NULL_TREE,
15129 build2 (COMPOUND_EXPR, NULL_TREE, first, second),
15130 build_java_empty_stmt ());
15133 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
15134 their order) on the current loop. Unlink the current loop from the
15138 finish_loop_body (int location, tree condition, tree body, int reversed)
15140 tree to_return = ctxp->current_loop;
15141 tree loop_body = LOOP_EXPR_BODY (to_return);
15144 tree cnode = LOOP_EXPR_BODY_CONDITION_EXPR (loop_body, reversed);
15145 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
15146 The real EXIT_EXPR is one operand further. */
15147 EXPR_WFL_LINECOL (cnode) = location;
15148 if (TREE_CODE (cnode) == EXPR_WITH_FILE_LOCATION)
15150 cnode = EXPR_WFL_NODE (cnode);
15151 /* This one is for accurate error reports */
15152 EXPR_WFL_LINECOL (cnode) = location;
15154 TREE_OPERAND (cnode, 0) = condition;
15156 LOOP_EXPR_BODY_BODY_EXPR (loop_body, reversed) = body;
15161 /* Tailored version of finish_loop_body for FOR loops, when FOR
15162 loops feature the condition part */
15165 finish_for_loop (int location, tree condition, tree update, tree body)
15167 /* Put the condition and the loop body in place */
15168 tree loop = finish_loop_body (location, condition, body, 0);
15169 /* LOOP is the current loop which has been now popped of the loop
15170 stack. Mark the update block as reachable and install it. We do
15171 this because the (current interpretation of the) JLS requires
15172 that the update expression be considered reachable even if the
15173 for loop's body doesn't complete normally. */
15174 if (update != NULL_TREE && !IS_EMPTY_STMT (update))
15177 if (TREE_CODE (up2) == EXPR_WITH_FILE_LOCATION)
15178 up2 = EXPR_WFL_NODE (up2);
15179 /* It is possible for the update expression to be an
15180 EXPR_WFL_NODE wrapping nothing. */
15181 if (up2 != NULL_TREE && !IS_EMPTY_STMT (up2))
15183 /* Try to detect constraint violations. These would be
15184 programming errors somewhere. */
15185 if (! EXPR_P (up2) || TREE_CODE (up2) == LOOP_EXPR)
15187 SUPPRESS_UNREACHABLE_ERROR (up2) = 1;
15190 LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
15194 /* Try to find the loop a block might be related to. This comprises
15195 the case where the LOOP_EXPR is found as the second operand of a
15196 COMPOUND_EXPR, because the loop happens to have an initialization
15197 part, then expressed as the first operand of the COMPOUND_EXPR. If
15198 the search finds something, 1 is returned. Otherwise, 0 is
15199 returned. The search is assumed to start from a
15200 LABELED_BLOCK_EXPR's block. */
15203 search_loop (tree statement)
15205 if (TREE_CODE (statement) == LOOP_EXPR)
15208 if (TREE_CODE (statement) == BLOCK)
15209 statement = BLOCK_SUBBLOCKS (statement);
15213 if (statement && TREE_CODE (statement) == COMPOUND_EXPR)
15214 while (statement && TREE_CODE (statement) == COMPOUND_EXPR)
15215 statement = TREE_OPERAND (statement, 1);
15217 return (TREE_CODE (statement) == LOOP_EXPR
15218 && FOR_LOOP_P (statement) ? statement : NULL_TREE);
15221 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
15222 returned otherwise. */
15225 labeled_block_contains_loop_p (tree block, tree loop)
15230 if (LABELED_BLOCK_BODY (block) == loop)
15233 if (FOR_LOOP_P (loop) && search_loop (LABELED_BLOCK_BODY (block)) == loop)
15239 /* If the loop isn't surrounded by a labeled statement, create one and
15240 insert LOOP as its body. */
15243 patch_loop_statement (tree loop)
15247 TREE_TYPE (loop) = void_type_node;
15248 if (labeled_block_contains_loop_p (ctxp->current_labeled_block, loop))
15251 loop_label = build_labeled_block (0, NULL_TREE);
15252 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
15253 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
15254 LABELED_BLOCK_BODY (loop_label) = loop;
15255 PUSH_LABELED_BLOCK (loop_label);
15259 /* 14.13, 14.14: break and continue Statements */
15261 /* Build a break or a continue statement. a null NAME indicates an
15262 unlabeled break/continue statement. */
15265 build_bc_statement (int location, int is_break, tree name)
15267 tree break_continue, label_block_expr = NULL_TREE;
15271 if (!(label_block_expr = IDENTIFIER_LOCAL_VALUE
15272 (merge_qualified_name (label_id, EXPR_WFL_NODE (name)))))
15273 /* Null means that we don't have a target for this named
15274 break/continue. In this case, we make the target to be the
15275 label name, so that the error can be reported accurately in
15276 patch_bc_statement. */
15277 label_block_expr = EXPR_WFL_NODE (name);
15279 /* Unlabeled break/continue will be handled during the
15280 break/continue patch operation */
15281 break_continue = build1 (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr);
15283 IS_BREAK_STMT_P (break_continue) = is_break;
15284 TREE_SIDE_EFFECTS (break_continue) = 1;
15285 EXPR_WFL_LINECOL (break_continue) = location;
15286 break_continue = build_debugable_stmt (location, break_continue);
15287 return break_continue;
15290 /* Verification of a break/continue statement. */
15293 patch_bc_statement (tree node)
15295 tree bc_label = EXIT_BLOCK_LABELED_BLOCK (node), target_stmt;
15296 tree labeled_block = ctxp->current_labeled_block;
15297 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15299 /* Having an identifier here means that the target is unknown. */
15300 if (bc_label != NULL_TREE && TREE_CODE (bc_label) == IDENTIFIER_NODE)
15302 parse_error_context (wfl_operator, "No label definition found for %qs",
15303 IDENTIFIER_POINTER (bc_label));
15304 return error_mark_node;
15306 if (! IS_BREAK_STMT_P (node))
15308 /* It's a continue statement. */
15309 for (;; labeled_block = TREE_CHAIN (labeled_block))
15311 if (labeled_block == NULL_TREE)
15313 if (bc_label == NULL_TREE)
15314 parse_error_context (wfl_operator,
15315 "%<continue%> must be in loop");
15317 parse_error_context
15318 (wfl_operator, "continue label %qs does not name a loop",
15319 IDENTIFIER_POINTER (bc_label));
15320 return error_mark_node;
15322 if ((DECL_NAME (LABELED_BLOCK_LABEL (labeled_block))
15323 == continue_identifier_node)
15324 && (bc_label == NULL_TREE
15325 || TREE_CHAIN (labeled_block) == bc_label))
15327 bc_label = labeled_block;
15332 else if (!bc_label)
15334 for (;; labeled_block = TREE_CHAIN (labeled_block))
15336 if (labeled_block == NULL_TREE)
15338 parse_error_context (wfl_operator,
15339 "%<break%> must be in loop or switch");
15340 return error_mark_node;
15342 target_stmt = LABELED_BLOCK_BODY (labeled_block);
15343 if (TREE_CODE (target_stmt) == SWITCH_EXPR
15344 || search_loop (target_stmt))
15346 bc_label = labeled_block;
15352 EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
15353 CAN_COMPLETE_NORMALLY (bc_label) = 1;
15355 /* Our break/continue don't return values. */
15356 TREE_TYPE (node) = void_type_node;
15357 /* Encapsulate the break within a compound statement so that it's
15358 expanded all the times by expand_expr (and not clobbered
15359 sometimes, like after a if statement) */
15360 node = add_stmt_to_compound (NULL_TREE, void_type_node, node);
15361 TREE_SIDE_EFFECTS (node) = 1;
15365 /* Process the exit expression belonging to a loop. Its type must be
15369 patch_exit_expr (tree node)
15371 tree expression = TREE_OPERAND (node, 0);
15372 TREE_TYPE (node) = error_mark_node;
15373 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15375 /* The type of expression must be boolean */
15376 if (TREE_TYPE (expression) != boolean_type_node)
15378 parse_error_context
15380 "Incompatible type for loop conditional. Can't convert %qs to %<boolean%>",
15381 lang_printable_name (TREE_TYPE (expression), 0));
15382 return error_mark_node;
15384 /* Now we know things are allright, invert the condition, fold and
15386 TREE_OPERAND (node, 0) =
15387 fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
15389 if (! integer_zerop (TREE_OPERAND (node, 0))
15390 && ctxp->current_loop != NULL_TREE
15391 && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
15392 CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
15393 if (! integer_onep (TREE_OPERAND (node, 0)))
15394 CAN_COMPLETE_NORMALLY (node) = 1;
15397 TREE_TYPE (node) = void_type_node;
15401 /* 14.9 Switch statement */
15404 patch_switch_statement (tree node)
15406 tree se = TREE_OPERAND (node, 0), se_type;
15409 /* Complete the switch expression */
15410 se = TREE_OPERAND (node, 0) = java_complete_tree (se);
15411 se_type = TREE_TYPE (se);
15412 /* The type of the switch expression must be char, byte, short or
15414 if (! JINTEGRAL_TYPE_P (se_type) || se_type == long_type_node)
15416 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15417 parse_error_context (wfl_operator,
15418 "Incompatible type for %<switch%>. Can't convert %qs to %<int%>",
15419 lang_printable_name (se_type, 0));
15420 /* This is what java_complete_tree will check */
15421 TREE_OPERAND (node, 0) = error_mark_node;
15422 return error_mark_node;
15425 /* Save and restore the outer case label list. */
15426 save = case_label_list;
15427 case_label_list = NULL_TREE;
15429 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
15431 /* See if we've found a duplicate label. We can't leave this until
15432 code generation, because in `--syntax-only' and `-C' modes we
15433 don't do ordinary code generation. */
15434 for (iter = case_label_list; iter != NULL_TREE; iter = TREE_CHAIN (iter))
15436 HOST_WIDE_INT val = TREE_INT_CST_LOW (TREE_VALUE (iter));
15438 for (subiter = TREE_CHAIN (iter);
15439 subiter != NULL_TREE;
15440 subiter = TREE_CHAIN (subiter))
15442 HOST_WIDE_INT subval = TREE_INT_CST_LOW (TREE_VALUE (subiter));
15445 EXPR_WFL_LINECOL (wfl_operator)
15446 = EXPR_WFL_LINECOL (TREE_PURPOSE (iter));
15447 /* The case_label_list is in reverse order, so print the
15448 outer label first. */
15449 parse_error_context (wfl_operator, "duplicate case label: %<"
15450 HOST_WIDE_INT_PRINT_DEC "%>", subval);
15451 EXPR_WFL_LINECOL (wfl_operator)
15452 = EXPR_WFL_LINECOL (TREE_PURPOSE (subiter));
15453 parse_error_context (wfl_operator, "original label is here");
15460 case_label_list = save;
15462 /* Ready to return */
15463 if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
15465 TREE_TYPE (node) = error_mark_node;
15466 return error_mark_node;
15468 TREE_TYPE (node) = void_type_node;
15469 TREE_SIDE_EFFECTS (node) = 1;
15470 CAN_COMPLETE_NORMALLY (node)
15471 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
15472 || ! SWITCH_HAS_DEFAULT (node);
15478 /* Build an assertion expression for `assert CONDITION : VALUE'; VALUE
15479 might be NULL_TREE. */
15482 #ifdef USE_MAPPED_LOCATION
15483 source_location location,
15487 tree condition, tree value)
15490 tree klass = GET_CPC ();
15492 if (! enable_assertions (klass))
15494 condition = build2 (TRUTH_ANDIF_EXPR, NULL_TREE,
15495 boolean_false_node, condition);
15496 if (value == NULL_TREE)
15497 value = build_java_empty_stmt ();
15498 return build_if_else_statement (location, condition,
15502 if (! CLASS_USES_ASSERTIONS (klass))
15504 tree field, classdollar, id, call;
15505 tree class_type = TREE_TYPE (klass);
15507 field = add_field (class_type,
15508 get_identifier ("$assertionsDisabled"),
15510 ACC_PRIVATE | ACC_STATIC | ACC_FINAL);
15511 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (field);
15512 FIELD_SYNTHETIC (field) = 1;
15514 classdollar = build_incomplete_class_ref (location, class_type);
15516 /* Call CLASS.desiredAssertionStatus(). */
15517 id = build_wfl_node (get_identifier ("desiredAssertionStatus"));
15518 call = build3 (CALL_EXPR, NULL_TREE, id, NULL_TREE, NULL_TREE);
15519 call = make_qualified_primary (classdollar, call, location);
15520 TREE_SIDE_EFFECTS (call) = 1;
15522 /* Invert to obtain !CLASS.desiredAssertionStatus(). This may
15523 seem odd, but we do it to generate code identical to that of
15525 call = build1 (TRUTH_NOT_EXPR, NULL_TREE, call);
15526 TREE_SIDE_EFFECTS (call) = 1;
15527 DECL_INITIAL (field) = call;
15529 /* Record the initializer in the initializer statement list. */
15530 call = build2 (MODIFY_EXPR, NULL_TREE, field, call);
15531 TREE_CHAIN (call) = CPC_STATIC_INITIALIZER_STMT (ctxp);
15532 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, call);
15533 MODIFY_EXPR_FROM_INITIALIZATION_P (call) = 1;
15535 CLASS_USES_ASSERTIONS (klass) = 1;
15538 if (value != NULL_TREE)
15539 value = tree_cons (NULL_TREE, value, NULL_TREE);
15541 node = build_wfl_node (get_identifier ("java"));
15542 node = make_qualified_name (node, build_wfl_node (get_identifier ("lang")),
15544 node = make_qualified_name (node, build_wfl_node (get_identifier ("AssertionError")),
15547 node = build3 (NEW_CLASS_EXPR, NULL_TREE, node, value, NULL_TREE);
15548 TREE_SIDE_EFFECTS (node) = 1;
15549 /* It is too early to use BUILD_THROW. */
15550 node = build1 (THROW_EXPR, NULL_TREE, node);
15551 TREE_SIDE_EFFECTS (node) = 1;
15553 /* We invert the condition; if we just put NODE as the `else' part
15554 then we generate weird-looking bytecode. */
15555 condition = build1 (TRUTH_NOT_EXPR, NULL_TREE, condition);
15556 /* Check $assertionsDisabled. */
15558 = build2 (TRUTH_ANDIF_EXPR, NULL_TREE,
15559 build1 (TRUTH_NOT_EXPR, NULL_TREE,
15560 build_wfl_node (get_identifier ("$assertionsDisabled"))),
15562 node = build_if_else_statement (location, condition, node, NULL_TREE);
15566 /* 14.18 The try/catch statements */
15568 /* Encapsulate TRY_STMTS' in a try catch sequence. The catch clause
15569 catches TYPE and executes CATCH_STMTS. */
15572 encapsulate_with_try_catch (int location, tree type_or_name, tree try_stmts,
15575 tree try_block, catch_clause_param, catch_block, catch;
15577 /* First build a try block */
15578 try_block = build_expr_block (try_stmts, NULL_TREE);
15580 /* Build a catch block: we need a catch clause parameter */
15581 if (TREE_CODE (type_or_name) == EXPR_WITH_FILE_LOCATION)
15583 tree catch_type = obtain_incomplete_type (type_or_name);
15585 catch_clause_param = build_decl (VAR_DECL, wpv_id, catch_type);
15586 register_incomplete_type (JDEP_VARIABLE, type_or_name,
15587 catch_clause_param, catch_type);
15588 dep = CLASSD_LAST (ctxp->classd_list);
15589 JDEP_GET_PATCH (dep) = &TREE_TYPE (catch_clause_param);
15592 catch_clause_param = build_decl (VAR_DECL, wpv_id,
15593 build_pointer_type (type_or_name));
15596 catch_block = build_expr_block (NULL_TREE, catch_clause_param);
15598 /* Initialize the variable and store in the block */
15599 catch = build2 (MODIFY_EXPR, NULL_TREE, catch_clause_param,
15600 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
15601 add_stmt_to_block (catch_block, NULL_TREE, catch);
15603 /* Add the catch statements */
15604 add_stmt_to_block (catch_block, NULL_TREE, catch_stmts);
15606 /* Now we can build a JAVA_CATCH_EXPR */
15607 catch_block = build1 (JAVA_CATCH_EXPR, NULL_TREE, catch_block);
15609 return build_try_statement (location, try_block, catch_block);
15613 build_try_statement (int location, tree try_block, tree catches)
15615 tree node = build2 (TRY_EXPR, NULL_TREE, try_block, catches);
15616 EXPR_WFL_LINECOL (node) = location;
15621 build_try_finally_statement (int location, tree try_block, tree finally)
15623 tree node = build2 (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
15624 EXPR_WFL_LINECOL (node) = location;
15629 patch_try_statement (tree node)
15631 int error_found = 0;
15632 tree try = TREE_OPERAND (node, 0);
15633 /* Exception handlers are considered in left to right order */
15634 tree catch = nreverse (TREE_OPERAND (node, 1));
15635 tree current, caught_type_list = NULL_TREE;
15637 /* Check catch clauses, if any. Every time we find an error, we try
15638 to process the next catch clause. We process the catch clause before
15639 the try block so that when processing the try block we can check thrown
15640 exceptions against the caught type list. */
15641 for (current = catch; current; current = TREE_CHAIN (current))
15643 tree carg_decl, carg_type;
15644 tree sub_current, catch_block, catch_clause;
15647 /* At this point, the structure of the catch clause is
15648 JAVA_CATCH_EXPR (catch node)
15649 BLOCK (with the decl of the parameter)
15651 MODIFY_EXPR (assignment of the catch parameter)
15652 BLOCK (catch clause block)
15654 catch_clause = TREE_OPERAND (current, 0);
15655 carg_decl = BLOCK_EXPR_DECLS (catch_clause);
15656 carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
15658 /* Catch clauses can't have more than one parameter declared,
15659 but it's already enforced by the grammar. Make sure that the
15660 only parameter of the clause statement in of class Throwable
15661 or a subclass of Throwable, but that was done earlier. The
15662 catch clause parameter type has also been resolved. */
15664 /* Just make sure that the catch clause parameter type inherits
15665 from java.lang.Throwable */
15666 if (!inherits_from_p (carg_type, throwable_type_node))
15668 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
15669 parse_error_context (wfl_operator,
15670 "Can't catch class %qs. Catch clause parameter type must be a subclass of class %<java.lang.Throwable%>",
15671 lang_printable_name (carg_type, 0));
15676 /* Partial check for unreachable catch statement: The catch
15677 clause is reachable iff is no earlier catch block A in
15678 the try statement such that the type of the catch
15679 clause's parameter is the same as or a subclass of the
15680 type of A's parameter */
15682 for (sub_current = catch;
15683 sub_current != current; sub_current = TREE_CHAIN (sub_current))
15685 tree sub_catch_clause, decl;
15686 sub_catch_clause = TREE_OPERAND (sub_current, 0);
15687 decl = BLOCK_EXPR_DECLS (sub_catch_clause);
15689 if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
15691 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
15692 parse_error_context
15694 "%<catch%> not reached because of the catch clause at line %d",
15695 EXPR_WFL_LINENO (sub_current));
15696 unreachable = error_found = 1;
15700 /* Complete the catch clause block */
15701 catch_block = java_complete_tree (TREE_OPERAND (current, 0));
15702 if (catch_block == error_mark_node)
15707 if (CAN_COMPLETE_NORMALLY (catch_block))
15708 CAN_COMPLETE_NORMALLY (node) = 1;
15709 TREE_OPERAND (current, 0) = catch_block;
15714 /* Things to do here: the exception must be thrown */
15716 /* Link this type to the caught type list */
15717 caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
15720 PUSH_EXCEPTIONS (caught_type_list);
15721 if ((try = java_complete_tree (try)) == error_mark_node)
15723 if (CAN_COMPLETE_NORMALLY (try))
15724 CAN_COMPLETE_NORMALLY (node) = 1;
15727 /* Verification ends here */
15729 return error_mark_node;
15731 TREE_OPERAND (node, 0) = try;
15732 TREE_OPERAND (node, 1) = catch;
15733 TREE_TYPE (node) = void_type_node;
15737 /* 14.17 The synchronized Statement */
15740 patch_synchronized_statement (tree node, tree wfl_op1)
15742 tree expr = java_complete_tree (TREE_OPERAND (node, 0));
15743 tree block = TREE_OPERAND (node, 1);
15745 tree tmp, enter, exit, expr_decl, assignment;
15747 if (expr == error_mark_node)
15749 block = java_complete_tree (block);
15753 /* We might be trying to synchronize on a STRING_CST */
15754 if ((tmp = patch_string (expr)))
15757 /* The TYPE of expr must be a reference type */
15758 if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
15760 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15761 parse_error_context (wfl_operator, "Incompatible type for %<synchronized%>. Can't convert %qs to %<java.lang.Object%>",
15762 lang_printable_name (TREE_TYPE (expr), 0));
15763 return error_mark_node;
15766 if (flag_emit_xref)
15768 TREE_OPERAND (node, 0) = expr;
15769 TREE_OPERAND (node, 1) = java_complete_tree (block);
15770 CAN_COMPLETE_NORMALLY (node) = 1;
15774 /* Generate a try-finally for the synchronized statement, except
15775 that the handler that catches all throw exception calls
15776 _Jv_MonitorExit and then rethrow the exception.
15777 The synchronized statement is then implemented as:
15780 _Jv_MonitorEnter (expression)
15782 _Jv_MonitorExit (expression)
15786 e = _Jv_exception_info ();
15787 _Jv_MonitorExit (expression)
15791 expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
15792 BUILD_MONITOR_ENTER (enter, expr_decl);
15793 BUILD_MONITOR_EXIT (exit, expr_decl);
15794 CAN_COMPLETE_NORMALLY (enter) = 1;
15795 CAN_COMPLETE_NORMALLY (exit) = 1;
15796 assignment = build2 (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
15797 TREE_SIDE_EFFECTS (assignment) = 1;
15798 node = build2 (COMPOUND_EXPR, NULL_TREE,
15799 build2 (COMPOUND_EXPR, NULL_TREE, assignment, enter),
15800 build2 (TRY_FINALLY_EXPR, NULL_TREE, block, exit));
15801 node = build_expr_block (node, expr_decl);
15803 return java_complete_tree (node);
15806 /* 14.16 The throw Statement */
15809 patch_throw_statement (tree node, tree wfl_op1)
15811 tree expr = TREE_OPERAND (node, 0);
15812 tree type = TREE_TYPE (expr);
15813 int unchecked_ok = 0, tryblock_throws_ok = 0;
15815 /* Thrown expression must be assignable to java.lang.Throwable */
15816 if (!try_reference_assignconv (throwable_type_node, expr))
15818 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15819 parse_error_context (wfl_operator,
15820 "Can't throw %qs; it must be a subclass of class %<java.lang.Throwable%>",
15821 lang_printable_name (type, 0));
15822 /* If the thrown expression was a reference, we further the
15823 compile-time check. */
15824 if (!JREFERENCE_TYPE_P (type))
15825 return error_mark_node;
15828 /* At least one of the following must be true */
15830 /* The type of the throw expression is a not checked exception,
15831 i.e. is a unchecked expression. */
15832 unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
15834 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15835 /* An instance can't throw a checked exception unless that exception
15836 is explicitly declared in the `throws' clause of each
15837 constructor. This doesn't apply to anonymous classes, since they
15838 don't have declared constructors. */
15840 && DECL_INSTINIT_P (current_function_decl)
15841 && !ANONYMOUS_CLASS_P (current_class))
15844 for (current = TYPE_METHODS (current_class); current;
15845 current = TREE_CHAIN (current))
15846 if (DECL_CONSTRUCTOR_P (current)
15847 && !check_thrown_exceptions_do (TREE_TYPE (expr)))
15849 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)",
15850 lang_printable_name (TREE_TYPE (expr), 0));
15851 return error_mark_node;
15855 /* Throw is contained in a try statement and at least one catch
15856 clause can receive the thrown expression or the current method is
15857 declared to throw such an exception. Or, the throw statement is
15858 contained in a method or constructor declaration and the type of
15859 the Expression is assignable to at least one type listed in the
15860 throws clause the declaration. */
15862 tryblock_throws_ok = check_thrown_exceptions_do (TREE_TYPE (expr));
15863 if (!(unchecked_ok || tryblock_throws_ok))
15865 /* If there is a surrounding try block that has no matching
15866 clatch clause, report it first. A surrounding try block exits
15867 only if there is something after the list of checked
15868 exception thrown by the current function (if any). */
15869 if (IN_TRY_BLOCK_P ())
15870 parse_error_context (wfl_operator, "Checked exception %qs can't be caught by any of the catch clause(s) of the surrounding %<try%> block",
15871 lang_printable_name (type, 0));
15872 /* If we have no surrounding try statement and the method doesn't have
15873 any throws, report it now. FIXME */
15875 /* We report that the exception can't be throw from a try block
15876 in all circumstances but when the `throw' is inside a static
15878 else if (!EXCEPTIONS_P (currently_caught_type_list)
15879 && !tryblock_throws_ok)
15881 if (DECL_CLINIT_P (current_function_decl))
15882 parse_error_context (wfl_operator,
15883 "Checked exception %qs can't be thrown in initializer",
15884 lang_printable_name (type, 0));
15886 parse_error_context (wfl_operator,
15887 "Checked exception %qs isn't thrown from a %<try%> block",
15888 lang_printable_name (type, 0));
15890 /* Otherwise, the current method doesn't have the appropriate
15891 throws declaration */
15893 parse_error_context (wfl_operator, "Checked exception %qs doesn't match any of current method's %<throws%> declaration(s)",
15894 lang_printable_name (type, 0));
15895 return error_mark_node;
15898 if (! flag_emit_class_files && ! flag_emit_xref)
15899 BUILD_THROW (node, expr);
15901 /* If doing xrefs, keep the location where the `throw' was seen. */
15902 if (flag_emit_xref)
15903 EXPR_WFL_LINECOL (node) = EXPR_WFL_LINECOL (wfl_op1);
15907 /* Check that exception said to be thrown by method DECL can be
15908 effectively caught from where DECL is invoked. THIS_EXPR is the
15909 expression that computes `this' for the method call. */
15911 check_thrown_exceptions (
15912 #ifdef USE_MAPPED_LOCATION
15913 source_location location,
15918 tree decl, tree this_expr)
15921 int is_array_call = 0;
15923 /* Skip check within generated methods, such as access$<n>. */
15924 if (OUTER_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (current_function_decl)))
15927 if (this_expr != NULL_TREE
15928 && TREE_CODE (TREE_TYPE (this_expr)) == POINTER_TYPE
15929 && TYPE_ARRAY_P (TREE_TYPE (TREE_TYPE (this_expr))))
15932 /* For all the unchecked exceptions thrown by DECL. */
15933 for (throws = DECL_FUNCTION_THROWS (decl); throws;
15934 throws = TREE_CHAIN (throws))
15935 if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
15937 /* Suppress errors about cloning arrays. */
15938 if (is_array_call && DECL_NAME (decl) == get_identifier ("clone"))
15941 #ifdef USE_MAPPED_LOCATION
15942 SET_EXPR_LOCATION (wfl_operator, location);
15944 EXPR_WFL_LINECOL (wfl_operator) = location;
15946 if (DECL_FINIT_P (current_function_decl))
15947 parse_error_context
15948 (wfl_operator, "Exception %qs can't be thrown in initializer",
15949 lang_printable_name (TREE_VALUE (throws), 0));
15952 parse_error_context
15953 (wfl_operator, "Exception %qs must be caught, or it must be declared in the %<throws%> clause of %qs",
15954 lang_printable_name (TREE_VALUE (throws), 0),
15955 (DECL_INIT_P (current_function_decl) ?
15956 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))) :
15957 IDENTIFIER_POINTER (DECL_NAME (current_function_decl))));
15962 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
15963 try-catch blocks, OR is listed in the `throws' clause of the
15967 check_thrown_exceptions_do (tree exception)
15969 tree list = currently_caught_type_list;
15970 resolve_and_layout (exception, NULL_TREE);
15971 /* First, all the nested try-catch-finally at that stage. The
15972 last element contains `throws' clause exceptions, if any. */
15973 if (IS_UNCHECKED_EXCEPTION_P (exception))
15978 for (caught = TREE_VALUE (list); caught; caught = TREE_CHAIN (caught))
15979 if (valid_ref_assignconv_cast_p (exception, TREE_VALUE (caught), 0))
15981 list = TREE_CHAIN (list);
15987 purge_unchecked_exceptions (tree mdecl)
15989 tree throws = DECL_FUNCTION_THROWS (mdecl);
15990 tree new = NULL_TREE;
15994 tree next = TREE_CHAIN (throws);
15995 if (!IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (throws)))
15997 TREE_CHAIN (throws) = new;
16002 /* List is inverted here, but it doesn't matter */
16003 DECL_FUNCTION_THROWS (mdecl) = new;
16006 /* This function goes over all of CLASS_TYPE ctors and checks whether
16007 each of them features at least one unchecked exception in its
16008 `throws' clause. If it's the case, it returns `true', `false'
16012 ctors_unchecked_throws_clause_p (tree class_type)
16016 for (current = TYPE_METHODS (class_type); current;
16017 current = TREE_CHAIN (current))
16019 bool ctu = false; /* Ctor Throws Unchecked */
16020 if (DECL_CONSTRUCTOR_P (current))
16023 for (throws = DECL_FUNCTION_THROWS (current); throws && !ctu;
16024 throws = TREE_CHAIN (throws))
16025 if (inherits_from_p (TREE_VALUE (throws), exception_type_node))
16028 /* We return false as we found one ctor that is unfit. */
16029 if (!ctu && DECL_CONSTRUCTOR_P (current))
16032 /* All ctors feature at least one unchecked exception in their
16033 `throws' clause. */
16037 /* 15.24 Conditional Operator ?: */
16040 patch_conditional_expr (tree node, tree wfl_cond, tree wfl_op1)
16042 tree cond = TREE_OPERAND (node, 0);
16043 tree op1 = TREE_OPERAND (node, 1);
16044 tree op2 = TREE_OPERAND (node, 2);
16045 tree resulting_type = NULL_TREE;
16046 tree t1, t2, patched;
16047 int error_found = 0;
16049 /* Operands of ?: might be StringBuffers crafted as a result of a
16050 string concatenation. Obtain a descent operand here. */
16051 if ((patched = patch_string (op1)))
16052 TREE_OPERAND (node, 1) = op1 = patched;
16053 if ((patched = patch_string (op2)))
16054 TREE_OPERAND (node, 2) = op2 = patched;
16056 t1 = TREE_TYPE (op1);
16057 t2 = TREE_TYPE (op2);
16059 /* The first expression must be a boolean */
16060 if (TREE_TYPE (cond) != boolean_type_node)
16062 SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
16063 parse_error_context (wfl_operator,
16064 "Incompatible type for %<?:%>. Can't convert %qs to %<boolean%>",
16065 lang_printable_name (TREE_TYPE (cond), 0));
16069 /* Second and third can be numeric, boolean (i.e. primitive),
16070 references or null. Anything else results in an error */
16071 if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
16072 || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node)
16073 && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
16074 || (t1 == boolean_type_node && t2 == boolean_type_node)))
16077 /* Determine the type of the conditional expression. Same types are
16078 easy to deal with */
16080 resulting_type = t1;
16082 /* There are different rules for numeric types */
16083 else if (JNUMERIC_TYPE_P (t1))
16085 /* if byte/short found, the resulting type is short */
16086 if ((t1 == byte_type_node && t2 == short_type_node)
16087 || (t1 == short_type_node && t2 == byte_type_node))
16088 resulting_type = short_type_node;
16090 /* If t1 is a constant int and t2 is of type byte, short or char
16091 and t1's value fits in t2, then the resulting type is t2 */
16092 else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
16093 && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
16094 resulting_type = t2;
16096 /* If t2 is a constant int and t1 is of type byte, short or char
16097 and t2's value fits in t1, then the resulting type is t1 */
16098 else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
16099 && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
16100 resulting_type = t1;
16102 /* Otherwise, binary numeric promotion is applied and the
16103 resulting type is the promoted type of operand 1 and 2 */
16105 resulting_type = binary_numeric_promotion (t1, t2,
16106 &TREE_OPERAND (node, 1),
16107 &TREE_OPERAND (node, 2));
16110 /* Cases of a reference and a null type */
16111 else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
16112 resulting_type = t1;
16114 else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
16115 resulting_type = t2;
16117 /* Last case: different reference types. If a type can be converted
16118 into the other one by assignment conversion, the latter
16119 determines the type of the expression */
16120 else if ((resulting_type = try_reference_assignconv (t1, op2)))
16121 resulting_type = promote_type (t1);
16123 else if ((resulting_type = try_reference_assignconv (t2, op1)))
16124 resulting_type = promote_type (t2);
16126 /* If we don't have any resulting type, we're in trouble */
16127 if (!resulting_type)
16129 char *t = xstrdup (lang_printable_name (t1, 0));
16130 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
16131 parse_error_context (wfl_operator,
16132 "Incompatible type for %<?:%>. Can't convert %qs to %qs",
16133 t, lang_printable_name (t2, 0));
16140 TREE_TYPE (node) = error_mark_node;
16141 return error_mark_node;
16144 TREE_TYPE (node) = resulting_type;
16145 TREE_SET_CODE (node, COND_EXPR);
16146 CAN_COMPLETE_NORMALLY (node) = 1;
16150 /* Wrap EXPR with code to initialize DECL's class, if appropriate. */
16153 maybe_build_class_init_for_field (tree decl, tree expr)
16155 tree clas = DECL_CONTEXT (decl);
16156 if (flag_emit_class_files || flag_emit_xref)
16159 if (TREE_CODE (decl) == VAR_DECL && FIELD_STATIC (decl)
16160 && FIELD_FINAL (decl))
16162 tree init = DECL_INITIAL (decl);
16163 if (init != NULL_TREE)
16164 init = fold_constant_for_init (init, decl);
16165 if (init != NULL_TREE && CONSTANT_VALUE_P (init))
16169 return build_class_init (clas, expr);
16172 /* Try to constant fold NODE.
16173 If NODE is not a constant expression, return NULL_EXPR.
16174 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
16177 fold_constant_for_init (tree node, tree context)
16179 tree op0, op1, val;
16180 enum tree_code code = TREE_CODE (node);
16185 if (node == null_pointer_node)
16194 case TRUNC_MOD_EXPR:
16202 case TRUTH_ANDIF_EXPR:
16203 case TRUTH_ORIF_EXPR:
16210 op0 = TREE_OPERAND (node, 0);
16211 op1 = TREE_OPERAND (node, 1);
16212 val = fold_constant_for_init (op0, context);
16213 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16215 TREE_OPERAND (node, 0) = val;
16216 val = fold_constant_for_init (op1, context);
16217 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16219 TREE_OPERAND (node, 1) = val;
16220 return patch_binop (node, op0, op1);
16222 case UNARY_PLUS_EXPR:
16224 case TRUTH_NOT_EXPR:
16227 op0 = TREE_OPERAND (node, 0);
16228 val = fold_constant_for_init (op0, context);
16229 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16231 TREE_OPERAND (node, 0) = val;
16232 val = patch_unaryop (node, op0);
16233 if (! TREE_CONSTANT (val))
16240 val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
16241 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16243 TREE_OPERAND (node, 0) = val;
16244 val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
16245 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16247 TREE_OPERAND (node, 1) = val;
16248 val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
16249 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16251 TREE_OPERAND (node, 2) = val;
16252 return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
16253 : TREE_OPERAND (node, 2);
16257 if (! FIELD_FINAL (node)
16258 || DECL_INITIAL (node) == NULL_TREE)
16260 val = DECL_INITIAL (node);
16261 /* Guard against infinite recursion. */
16262 DECL_INITIAL (node) = NULL_TREE;
16263 val = fold_constant_for_init (val, node);
16264 if (val != NULL_TREE && TREE_CODE (val) != STRING_CST)
16265 val = try_builtin_assignconv (NULL_TREE, TREE_TYPE (node), val);
16266 DECL_INITIAL (node) = val;
16269 case EXPR_WITH_FILE_LOCATION:
16270 /* Compare java_complete_tree and resolve_expression_name. */
16271 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
16272 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
16274 tree name = EXPR_WFL_NODE (node);
16276 if (PRIMARY_P (node))
16278 else if (! QUALIFIED_P (name))
16280 decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
16281 if (decl == NULL_TREE
16282 || (! FIELD_STATIC (decl) && ! FIELD_FINAL (decl)))
16284 return fold_constant_for_init (decl, decl);
16288 tree r = NULL_TREE;
16289 /* Install the proper context for the field resolution. */
16290 tree saved_current_class = current_class;
16291 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
16292 current_class = DECL_CONTEXT (context);
16293 qualify_ambiguous_name (node);
16294 r = resolve_field_access (node, &decl, NULL);
16295 /* Restore prior context. */
16296 current_class = saved_current_class;
16297 if (r != error_mark_node && decl != NULL_TREE)
16298 return fold_constant_for_init (decl, decl);
16304 op0 = TREE_OPERAND (node, 0);
16305 val = fold_constant_for_init (op0, context);
16306 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16308 TREE_OPERAND (node, 0) = val;
16312 #ifdef USE_COMPONENT_REF
16314 case COMPONENT_REF:
16323 #ifdef USE_COMPONENT_REF
16324 /* Context is 'T' for TypeName, 'P' for PackageName,
16325 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
16328 resolve_simple_name (tree name, int context)
16333 resolve_qualified_name (tree name, int context)
16339 init_src_parse (void)
16341 /* Sanity check; we've been bit by this before. */
16342 if (ARRAY_SIZE (ctxp->modifier_ctx) != MODIFIER_TK - PUBLIC_TK)
16348 /* This section deals with the functions that are called when tables
16349 recording class initialization information are traversed. */
16351 /* This function is called for each class that is known definitely
16352 initialized when a given static method was called. This function
16353 augments a compound expression (INFO) storing all assignment to
16354 initialized static class flags if a flag already existed, otherwise
16355 a new one is created. */
16358 emit_test_initialization (void **entry_p, void *info)
16360 tree l = (tree) info;
16362 tree key = (tree) *entry_p;
16364 htab_t cf_ht = DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl);
16366 /* If we haven't found a flag and we're dealing with self registered
16367 with current_function_decl, then don't do anything. Self is
16368 always added as definitely initialized but this information is
16369 valid only if used outside the current function. */
16370 if (current_function_decl == TREE_PURPOSE (l)
16371 && java_treetreehash_find (cf_ht, key) == NULL)
16374 ite = java_treetreehash_new (cf_ht, key);
16376 /* If we don't have a variable, create one and install it. */
16381 decl = build_decl (VAR_DECL, NULL_TREE, boolean_type_node);
16382 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
16383 LOCAL_CLASS_INITIALIZATION_FLAG (decl) = 1;
16384 DECL_CONTEXT (decl) = current_function_decl;
16385 DECL_INITIAL (decl) = boolean_true_node;
16386 /* Don't emit any symbolic debugging info for this decl. */
16387 DECL_IGNORED_P (decl) = 1;
16389 /* The trick is to find the right context for it. */
16390 block = BLOCK_SUBBLOCKS (GET_CURRENT_BLOCK (current_function_decl));
16391 TREE_CHAIN (decl) = BLOCK_EXPR_DECLS (block);
16392 BLOCK_EXPR_DECLS (block) = decl;
16398 /* Now simply augment the compound that holds all the assignments
16399 pertaining to this method invocation. */
16400 init = build2 (MODIFY_EXPR, boolean_type_node, decl, boolean_true_node);
16401 TREE_SIDE_EFFECTS (init) = 1;
16402 TREE_VALUE (l) = add_stmt_to_compound (TREE_VALUE (l), void_type_node, init);
16403 TREE_SIDE_EFFECTS (TREE_VALUE (l)) = 1;
16408 #ifdef __XGETTEXT__
16409 /* Depending on the version of Bison used to compile this grammar,
16410 it may issue generic diagnostics spelled "syntax error" or
16411 "parse error". To prevent this from changing the translation
16412 template randomly, we list all the variants of this particular
16413 diagnostic here. Translators: there is no fine distinction
16414 between diagnostics with "syntax error" in them, and diagnostics
16415 with "parse error" in them. It's okay to give them both the same
16417 const char d1[] = N_("syntax error");
16418 const char d2[] = N_("parse error");
16419 const char d3[] = N_("syntax error; also virtual memory exhausted");
16420 const char d4[] = N_("parse error; also virtual memory exhausted");
16421 const char d5[] = N_("syntax error: cannot back up");
16422 const char d6[] = N_("parse error: cannot back up");
16425 #include "gt-java-parse.h"
16426 #include "gtype-java.h"