1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to
21 the Free Software Foundation, 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 jdeplist *reverse_jdep_list (struct parser_ctxt *);
281 static void static_ref_err (tree, tree, tree);
282 static void parser_add_interface (tree, tree, tree);
283 static void add_superinterfaces (tree, tree);
284 static tree jdep_resolve_class (jdep *);
285 static int note_possible_classname (const char *, int);
286 static void java_complete_expand_classes (void);
287 static void java_complete_expand_class (tree);
288 static void java_complete_expand_methods (tree);
289 static tree cut_identifier_in_qualified (tree);
290 static tree java_stabilize_reference (tree);
291 static tree do_unary_numeric_promotion (tree);
292 static char * operator_string (tree);
293 static tree do_merge_string_cste (tree, const char *, int, int);
294 static tree merge_string_cste (tree, tree, int);
295 static tree java_refold (tree);
296 static int java_decl_equiv (tree, tree);
297 static int binop_compound_p (enum tree_code);
298 static tree search_loop (tree);
299 static int labeled_block_contains_loop_p (tree, tree);
300 static int check_abstract_method_definitions (int, tree, tree);
301 static void java_check_abstract_method_definitions (tree);
302 static void java_debug_context_do (int);
303 static void java_parser_context_push_initialized_field (void);
304 static void java_parser_context_pop_initialized_field (void);
305 static tree reorder_static_initialized (tree);
306 static void java_parser_context_suspend (void);
307 static void java_parser_context_resume (void);
308 static int pop_current_osb (struct parser_ctxt *);
310 /* JDK 1.1 work. FIXME */
312 static tree maybe_make_nested_class_name (tree);
313 static int make_nested_class_name (tree);
314 static void link_nested_class_to_enclosing (void);
315 static tree resolve_inner_class (htab_t, tree, tree *, tree *, tree);
316 static tree find_as_inner_class (tree, tree, tree);
317 static tree find_as_inner_class_do (tree, tree);
318 static int check_inner_class_redefinition (tree, tree);
320 static tree build_thisn_assign (void);
321 static tree build_current_thisn (tree);
322 static tree build_access_to_thisn (tree, tree, int);
323 static tree maybe_build_thisn_access_method (tree);
325 static tree build_outer_field_access (tree, tree);
326 static tree build_outer_field_access_methods (tree);
327 static tree build_outer_field_access_expr (int, tree, tree,
329 static tree build_outer_method_access_method (tree);
330 static tree build_new_access_id (void);
331 static tree build_outer_field_access_method (tree, tree, tree,
334 static int outer_field_access_p (tree, tree);
335 static int outer_field_expanded_access_p (tree, tree *,
337 static tree outer_field_access_fix (tree, tree, tree);
338 static tree build_incomplete_class_ref (int, tree);
339 static tree patch_incomplete_class_ref (tree);
340 static tree create_anonymous_class (tree);
341 static void patch_anonymous_class (tree, tree, tree);
342 static void add_inner_class_fields (tree, tree);
344 static tree build_dot_class_method (tree);
345 static tree build_dot_class_method_invocation (tree, tree);
346 static void create_new_parser_context (int);
347 static tree maybe_build_class_init_for_field (tree, tree);
349 static int emit_test_initialization (void **, void *);
351 static char *string_convert_int_cst (tree);
353 /* Number of error found so far. */
354 int java_error_count;
355 /* Number of warning found so far. */
356 int java_warning_count;
357 /* Tell when not to fold, when doing xrefs */
359 /* Cyclic inheritance report, as it can be set by layout_class */
360 const char *cyclic_inheritance_report;
362 /* The current parser context */
363 struct parser_ctxt *ctxp;
365 /* List of things that were analyzed for which code will be generated */
366 struct parser_ctxt *ctxp_for_generation = NULL;
368 /* binop_lookup maps token to tree_code. It is used where binary
369 operations are involved and required by the parser. RDIV_EXPR
370 covers both integral/floating point division. The code is changed
371 once the type of both operator is worked out. */
373 static const enum tree_code binop_lookup[19] =
375 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
376 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
377 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
378 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
379 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
381 #define BINOP_LOOKUP(VALUE) \
382 binop_lookup [((VALUE) - PLUS_TK) % ARRAY_SIZE (binop_lookup)]
384 /* This is the end index for binary operators that can also be used
385 in compound assignments. */
386 #define BINOP_COMPOUND_CANDIDATES 11
388 /* The "$L" identifier we use to create labels. */
389 static GTY(()) tree label_id;
391 /* The "StringBuffer" identifier used for the String `+' operator. */
392 static GTY(()) tree wfl_string_buffer;
394 /* The "append" identifier used for String `+' operator. */
395 static GTY(()) tree wfl_append;
397 /* The "toString" identifier used for String `+' operator. */
398 static GTY(()) tree wfl_to_string;
400 /* The "java.lang" import qualified name. */
401 static GTY(()) tree java_lang_id;
403 /* The generated `inst$' identifier used for generated enclosing
404 instance/field access functions. */
405 static GTY(()) tree inst_id;
407 /* Context and flag for static blocks */
408 static GTY(()) tree current_static_block;
410 /* The generated `write_parm_value$' identifier. */
411 static GTY(()) tree wpv_id;
413 /* The list of all packages we've seen so far */
414 static GTY(()) tree package_list;
416 /* Hold THIS for the scope of the current method decl. */
417 static GTY(()) tree current_this;
419 /* Hold a list of catch clauses list. The first element of this list is
420 the list of the catch clauses of the currently analyzed try block. */
421 static GTY(()) tree currently_caught_type_list;
423 /* This holds a linked list of all the case labels for the current
424 switch statement. It is only used when checking to see if there
425 are duplicate labels. FIXME: probably this should just be attached
426 to the switch itself; then it could be referenced via
427 `ctxp->current_loop'. */
428 static GTY(()) tree case_label_list;
430 /* Anonymous class counter. Will be reset to 1 every time a non
431 anonymous class gets created. */
432 static int anonymous_class_counter = 1;
434 static GTY(()) tree src_parse_roots[1];
436 /* All classes seen from source code */
437 #define gclass_list src_parse_roots[0]
439 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
440 line and point it out. */
441 /* Should point out the one that don't fit. ASCII/unicode, going
444 #define check_modifiers(__message, __value, __mask) do { \
445 if ((__value) & ~(__mask)) \
447 size_t i, remainder = (__value) & ~(__mask); \
448 for (i = 0; i < ARRAY_SIZE (ctxp->modifier_ctx); i++) \
449 if ((1 << i) & remainder) \
450 parse_error_context (ctxp->modifier_ctx [i], (__message), \
451 java_accstring_lookup (1 << i)); \
462 #ifdef USE_MAPPED_LOCATION
463 source_location location;
472 #ifdef USE_MAPPED_LOCATION
473 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
474 SET_EXPR_LOCATION(EXPR, (TOKEN).location)
476 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
477 (EXPR_WFL_LINECOL (EXPR) = (TOKEN).location)
485 /* Things defined here have to match the order of what's in the
486 binop_lookup table. */
488 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
489 %token LS_TK SRS_TK ZRS_TK
490 %token AND_TK XOR_TK OR_TK
491 %token BOOL_AND_TK BOOL_OR_TK
492 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
494 /* This maps to the same binop_lookup entry than the token above */
496 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
498 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
499 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
502 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
504 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
505 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
506 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
507 %token PAD_TK ABSTRACT_TK STRICT_TK
510 /* Keep those two in order, too */
511 %token DECR_TK INCR_TK
513 /* From now one, things can be in any order */
515 %token DEFAULT_TK IF_TK THROW_TK
516 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
517 %token THROWS_TK BREAK_TK IMPORT_TK
518 %token ELSE_TK INSTANCEOF_TK RETURN_TK
519 %token VOID_TK CATCH_TK INTERFACE_TK
520 %token CASE_TK EXTENDS_TK FINALLY_TK
521 %token SUPER_TK WHILE_TK CLASS_TK
522 %token SWITCH_TK CONST_TK TRY_TK
523 %token FOR_TK NEW_TK CONTINUE_TK
524 %token GOTO_TK PACKAGE_TK THIS_TK
527 %token BYTE_TK SHORT_TK INT_TK LONG_TK
528 %token CHAR_TK INTEGRAL_TK
530 %token FLOAT_TK DOUBLE_TK FP_TK
534 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
536 %token ASSIGN_ANY_TK ASSIGN_TK
537 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
539 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
540 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
542 %type <value> modifiers MODIFIER_TK final synchronized
544 %type <node> super ID_TK identifier
545 %type <node> name simple_name qualified_name
546 %type <node> type_declaration compilation_unit
547 field_declaration method_declaration extends_interfaces
548 interfaces interface_type_list
549 import_declarations package_declaration
550 type_declarations interface_body
551 interface_member_declaration constant_declaration
552 interface_member_declarations interface_type
553 abstract_method_declaration
554 %type <node> class_body_declaration class_member_declaration
555 static_initializer constructor_declaration block
556 %type <node> class_body_declarations constructor_header
557 %type <node> class_or_interface_type class_type class_type_list
558 constructor_declarator explicit_constructor_invocation
559 %type <node> dim_expr dim_exprs this_or_super throws
561 %type <node> variable_declarator_id variable_declarator
562 variable_declarators variable_initializer
563 variable_initializers constructor_body
566 %type <node> class_body block_end constructor_block_end
567 %type <node> statement statement_without_trailing_substatement
568 labeled_statement if_then_statement label_decl
569 if_then_else_statement while_statement for_statement
570 statement_nsi labeled_statement_nsi do_statement
571 if_then_else_statement_nsi while_statement_nsi
572 for_statement_nsi statement_expression_list for_init
573 for_update statement_expression expression_statement
574 primary_no_new_array expression primary array_type
575 array_creation_initialized array_creation_uninitialized
576 class_instance_creation_expression field_access
577 method_invocation array_access something_dot_new
578 argument_list postfix_expression while_expression
579 post_increment_expression post_decrement_expression
580 unary_expression_not_plus_minus unary_expression
581 pre_increment_expression pre_decrement_expression
583 multiplicative_expression additive_expression
584 shift_expression relational_expression
585 equality_expression and_expression
586 exclusive_or_expression inclusive_or_expression
587 conditional_and_expression conditional_or_expression
588 conditional_expression assignment_expression
589 left_hand_side assignment for_header for_begin
590 constant_expression do_statement_begin empty_statement
591 switch_statement synchronized_statement throw_statement
592 try_statement assert_statement
593 switch_expression switch_block
594 catches catch_clause catch_clause_parameter finally
595 anonymous_class_creation trap_overflow_corner_case
596 %type <node> return_statement break_statement continue_statement
598 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
599 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
600 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
601 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
602 %type <operator> ASSIGN_ANY_TK assignment_operator
603 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
604 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
605 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
606 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
607 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
608 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
609 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
610 %type <operator> NEW_TK ASSERT_TK
612 %type <node> method_body
614 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
615 STRING_LIT_TK NULL_TK VOID_TK
617 %type <node> IF_TK WHILE_TK FOR_TK
619 %type <node> formal_parameter_list formal_parameter
620 method_declarator method_header
622 %type <node> primitive_type reference_type type
623 BOOLEAN_TK INTEGRAL_TK FP_TK
625 /* Added or modified JDK 1.1 rule types */
626 %type <node> type_literals
629 /* 19.2 Production from 2.3: The Syntactic Grammar */
630 goal: compilation_unit
634 /* 19.3 Productions from 3: Lexical structure */
644 /* 19.4 Productions from 4: Types, Values and Variables */
657 class_or_interface_type
661 class_or_interface_type:
666 class_or_interface_type /* Default rule */
670 class_or_interface_type
676 int osb = pop_current_osb (ctxp);
677 tree t = build_java_array_type (($1), -1);
679 t = build_unresolved_array_type (t);
684 int osb = pop_current_osb (ctxp);
687 t = build_unresolved_array_type (t);
692 /* 19.5 Productions from 6: Names */
694 simple_name /* Default rule */
695 | qualified_name /* Default rule */
699 identifier /* Default rule */
703 name DOT_TK identifier
704 { $$ = make_qualified_name ($1, $3, $2.location); }
711 /* 19.6: Production from 7: Packages */
714 | package_declaration
715 | import_declarations
717 | package_declaration import_declarations
718 | package_declaration type_declarations
719 | import_declarations type_declarations
720 | package_declaration import_declarations type_declarations
728 | import_declarations import_declaration
736 | type_declarations type_declaration
740 PACKAGE_TK name SC_TK
742 ctxp->package = EXPR_WFL_NODE ($2);
743 register_package (ctxp->package);
746 {yyerror ("Missing name"); RECOVER;}
747 | PACKAGE_TK name error
748 {yyerror ("';' expected"); RECOVER;}
752 single_type_import_declaration
753 | type_import_on_demand_declaration
756 single_type_import_declaration:
759 tree name = EXPR_WFL_NODE ($2), last_name;
760 int i = IDENTIFIER_LENGTH (name)-1;
761 const char *last = &IDENTIFIER_POINTER (name)[i];
762 while (last != IDENTIFIER_POINTER (name))
768 last_name = get_identifier (++last);
769 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
771 tree err = find_name_in_single_imports (last_name);
772 if (err && err != name)
774 ($2, "Ambiguous class: %qs and %qs",
775 IDENTIFIER_POINTER (name),
776 IDENTIFIER_POINTER (err));
778 REGISTER_IMPORT ($2, last_name);
781 REGISTER_IMPORT ($2, last_name);
784 {yyerror ("Missing name"); RECOVER;}
785 | IMPORT_TK name error
786 {yyerror ("';' expected"); RECOVER;}
789 type_import_on_demand_declaration:
790 IMPORT_TK name DOT_TK MULT_TK SC_TK
792 tree name = EXPR_WFL_NODE ($2);
794 /* Search for duplicates. */
795 for (it = ctxp->import_demand_list; it; it = TREE_CHAIN (it))
796 if (EXPR_WFL_NODE (TREE_PURPOSE (it)) == name)
798 /* Don't import the same thing more than once, just ignore
799 duplicates (7.5.2) */
802 read_import_dir ($2);
803 ctxp->import_demand_list =
804 chainon (ctxp->import_demand_list,
805 build_tree_list ($2, NULL_TREE));
808 | IMPORT_TK name DOT_TK error
809 {yyerror ("'*' expected"); RECOVER;}
810 | IMPORT_TK name DOT_TK MULT_TK error
811 {yyerror ("';' expected"); RECOVER;}
816 { end_class_declaration (0); }
817 | interface_declaration
818 { end_class_declaration (0); }
823 yyerror ("Class or interface declaration expected");
827 /* 19.7 Shortened from the original:
828 modifiers: modifier | modifiers modifier
829 modifier: any of public... */
835 | modifiers MODIFIER_TK
840 (ctxp->modifier_ctx [$2], "Modifier %qs declared twice",
841 java_accstring_lookup (acc));
849 /* 19.8.1 Production from $8.1: Class Declaration */
851 modifiers CLASS_TK identifier super interfaces
852 { create_class ($1, $3, $4, $5); }
855 | CLASS_TK identifier super interfaces
856 { create_class (0, $2, $3, $4); }
859 | modifiers CLASS_TK error
860 { yyerror ("Missing class name"); RECOVER; }
862 { yyerror ("Missing class name"); RECOVER; }
863 | CLASS_TK identifier error
865 if (!ctxp->class_err) yyerror ("'{' expected");
868 | modifiers CLASS_TK identifier error
869 { if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER; }
874 | EXTENDS_TK class_type
876 | EXTENDS_TK class_type error
877 {yyerror ("'{' expected"); ctxp->class_err=1;}
879 {yyerror ("Missing super class name"); ctxp->class_err=1;}
884 | IMPLEMENTS_TK interface_type_list
886 | IMPLEMENTS_TK error
889 yyerror ("Missing interface name");
896 ctxp->interface_number = 1;
897 $$ = build_tree_list ($1, NULL_TREE);
899 | interface_type_list C_TK interface_type
901 ctxp->interface_number++;
902 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
904 | interface_type_list C_TK error
905 {yyerror ("Missing interface name"); RECOVER;}
911 /* Store the location of the `}' when doing xrefs */
913 DECL_END_SOURCE_LINE (GET_CPC ()) = $2.location;
916 | OCB_TK class_body_declarations CCB_TK
918 /* Store the location of the `}' when doing xrefs */
920 DECL_END_SOURCE_LINE (GET_CPC ()) = $3.location;
925 class_body_declarations:
926 class_body_declaration
927 | class_body_declarations class_body_declaration
930 class_body_declaration:
931 class_member_declaration
933 | constructor_declaration
934 | block /* Added, JDK1.1, instance initializer */
936 if (!IS_EMPTY_STMT ($1))
938 TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
939 SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
944 class_member_declaration:
947 | class_declaration /* Added, JDK1.1 inner classes */
948 { end_class_declaration (1); }
949 | interface_declaration /* Added, JDK1.1 inner interfaces */
950 { end_class_declaration (1); }
954 /* 19.8.2 Productions from 8.3: Field Declarations */
956 type variable_declarators SC_TK
957 { register_fields (0, $1, $2); }
958 | modifiers type variable_declarators SC_TK
961 ("Illegal modifier %qs for field declaration",
962 $1, FIELD_MODIFIERS);
963 check_modifiers_consistency ($1);
964 register_fields ($1, $2, $3);
968 variable_declarators:
969 /* Should we use build_decl_list () instead ? FIXME */
970 variable_declarator /* Default rule */
971 | variable_declarators C_TK variable_declarator
972 { $$ = chainon ($1, $3); }
973 | variable_declarators C_TK error
974 {yyerror ("Missing term"); RECOVER;}
978 variable_declarator_id
979 { $$ = build_tree_list ($1, NULL_TREE); }
980 | variable_declarator_id ASSIGN_TK variable_initializer
982 if (java_error_count)
985 ($1, build_assignment ($2.token, $2.location, $1, $3));
987 | variable_declarator_id ASSIGN_TK error
989 yyerror ("Missing variable initializer");
990 $$ = build_tree_list ($1, NULL_TREE);
993 | variable_declarator_id ASSIGN_TK variable_initializer error
995 yyerror ("';' expected");
996 $$ = build_tree_list ($1, NULL_TREE);
1001 variable_declarator_id:
1003 | variable_declarator_id OSB_TK CSB_TK
1004 { $$ = build_unresolved_array_type ($1); }
1006 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
1007 | variable_declarator_id OSB_TK error
1009 yyerror ("']' expected");
1012 | variable_declarator_id CSB_TK error
1013 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
1016 variable_initializer:
1021 /* 19.8.3 Productions from 8.4: Method Declarations */
1025 current_function_decl = $1;
1026 if (current_function_decl
1027 && TREE_CODE (current_function_decl) == FUNCTION_DECL)
1028 source_start_java_method (current_function_decl);
1030 current_function_decl = NULL_TREE;
1033 { finish_method_declaration ($3); }
1034 | method_header error
1035 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
1039 type method_declarator throws
1040 { $$ = method_header (0, $1, $2, $3); }
1041 | VOID_TK method_declarator throws
1042 { $$ = method_header (0, void_type_node, $2, $3); }
1043 | modifiers type method_declarator throws
1044 { $$ = method_header ($1, $2, $3, $4); }
1045 | modifiers VOID_TK method_declarator throws
1046 { $$ = method_header ($1, void_type_node, $3, $4); }
1049 yyerror ("Invalid method declaration, method name required");
1052 | modifiers type error
1054 yyerror ("Identifier expected");
1059 yyerror ("Identifier expected");
1062 | modifiers VOID_TK error
1064 yyerror ("Identifier expected");
1069 yyerror ("Invalid method declaration, return type required");
1075 identifier OP_TK CP_TK
1077 ctxp->formal_parameter_number = 0;
1078 $$ = method_declarator ($1, NULL_TREE);
1080 | identifier OP_TK formal_parameter_list CP_TK
1081 { $$ = method_declarator ($1, $3); }
1082 | method_declarator OSB_TK CSB_TK
1084 SET_EXPR_LOCATION_FROM_TOKEN (wfl_operator, $2);
1086 build_unresolved_array_type (TREE_PURPOSE ($1));
1087 parse_warning_context
1089 "Discouraged form of returned type specification");
1091 | identifier OP_TK error
1092 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1093 | method_declarator OSB_TK error
1094 {yyerror ("']' expected"); RECOVER;}
1097 formal_parameter_list:
1100 ctxp->formal_parameter_number = 1;
1102 | formal_parameter_list C_TK formal_parameter
1104 ctxp->formal_parameter_number += 1;
1105 $$ = chainon ($1, $3);
1107 | formal_parameter_list C_TK error
1108 { yyerror ("Missing formal parameter term"); RECOVER; }
1112 type variable_declarator_id
1114 $$ = build_tree_list ($2, $1);
1116 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1118 $$ = build_tree_list ($3, $2);
1119 ARG_FINAL_P ($$) = 1;
1123 yyerror ("Missing identifier"); RECOVER;
1128 yyerror ("Missing identifier"); RECOVER;
1136 check_modifiers ("Illegal modifier %qs. Only %<final%> was expected here",
1138 if ($1 != ACC_FINAL)
1139 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1145 | THROWS_TK class_type_list
1148 {yyerror ("Missing class type term"); RECOVER;}
1153 { $$ = build_tree_list ($1, $1); }
1154 | class_type_list C_TK class_type
1155 { $$ = tree_cons ($3, $3, $1); }
1156 | class_type_list C_TK error
1157 {yyerror ("Missing class type term"); RECOVER;}
1162 | SC_TK { $$ = NULL_TREE; }
1165 /* 19.8.4 Productions from 8.5: Static Initializers */
1169 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1170 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1171 current_static_block = NULL_TREE;
1175 static: /* Test lval.sub_token here */
1178 check_modifiers ("Illegal modifier %qs for static initializer", $1, ACC_STATIC);
1179 /* Can't have a static initializer in an innerclass */
1180 if ($1 | ACC_STATIC &&
1181 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1183 (MODIFIER_WFL (STATIC_TK),
1184 "Can't define static initializer in class %qs. Static initializer can only be defined in top-level classes",
1185 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1186 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1190 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1191 constructor_declaration:
1194 current_function_decl = $1;
1195 source_start_java_method (current_function_decl);
1198 { finish_method_declaration ($3); }
1202 constructor_declarator throws
1203 { $$ = method_header (0, NULL_TREE, $1, $2); }
1204 | modifiers constructor_declarator throws
1205 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1208 constructor_declarator:
1209 simple_name OP_TK CP_TK
1211 ctxp->formal_parameter_number = 0;
1212 $$ = method_declarator ($1, NULL_TREE);
1214 | simple_name OP_TK formal_parameter_list CP_TK
1215 { $$ = method_declarator ($1, $3); }
1219 /* Unlike regular method, we always need a complete (empty)
1220 body so we can safely perform all the required code
1221 addition (super invocation and field initialization) */
1222 block_begin constructor_block_end
1224 BLOCK_EXPR_BODY ($2) = build_java_empty_stmt ();
1227 | block_begin explicit_constructor_invocation constructor_block_end
1229 | block_begin block_statements constructor_block_end
1231 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1235 constructor_block_end:
1239 /* Error recovery for that rule moved down expression_statement: rule. */
1240 explicit_constructor_invocation:
1241 this_or_super OP_TK CP_TK SC_TK
1243 $$ = build_method_invocation ($1, NULL_TREE);
1244 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1245 $$ = java_method_add_stmt (current_function_decl, $$);
1247 | this_or_super OP_TK argument_list CP_TK SC_TK
1249 $$ = build_method_invocation ($1, $3);
1250 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1251 $$ = java_method_add_stmt (current_function_decl, $$);
1253 /* Added, JDK1.1 inner classes. Modified because the rule
1254 'primary' couldn't work. */
1255 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1256 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1257 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1258 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1261 this_or_super: /* Added, simplifies error diagnostics */
1264 tree wfl = build_wfl_node (this_identifier_node);
1265 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1270 tree wfl = build_wfl_node (super_identifier_node);
1271 SET_EXPR_LOCATION_FROM_TOKEN (wfl, $1);
1276 /* 19.9 Productions from 9: Interfaces */
1277 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1278 interface_declaration:
1279 INTERFACE_TK identifier
1280 { create_interface (0, $2, NULL_TREE); }
1283 | modifiers INTERFACE_TK identifier
1284 { create_interface ($1, $3, NULL_TREE); }
1287 | INTERFACE_TK identifier extends_interfaces
1288 { create_interface (0, $2, $3); }
1291 | modifiers INTERFACE_TK identifier extends_interfaces
1292 { create_interface ($1, $3, $4); }
1295 | INTERFACE_TK identifier error
1296 { yyerror ("'{' expected"); RECOVER; }
1297 | modifiers INTERFACE_TK identifier error
1298 { yyerror ("'{' expected"); RECOVER; }
1302 EXTENDS_TK interface_type
1304 ctxp->interface_number = 1;
1305 $$ = build_tree_list ($2, NULL_TREE);
1307 | extends_interfaces C_TK interface_type
1309 ctxp->interface_number++;
1310 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1313 {yyerror ("Invalid interface type"); RECOVER;}
1314 | extends_interfaces C_TK error
1315 {yyerror ("Missing term"); RECOVER;}
1321 | OCB_TK interface_member_declarations CCB_TK
1325 interface_member_declarations:
1326 interface_member_declaration
1327 | interface_member_declarations interface_member_declaration
1330 interface_member_declaration:
1331 constant_declaration
1332 | abstract_method_declaration
1333 | class_declaration /* Added, JDK1.1 inner classes */
1334 { end_class_declaration (1); }
1335 | interface_declaration /* Added, JDK1.1 inner interfaces */
1336 { end_class_declaration (1); }
1339 constant_declaration:
1343 abstract_method_declaration:
1346 check_abstract_method_header ($1);
1347 current_function_decl = NULL_TREE; /* FIXME ? */
1349 | method_header error
1350 {yyerror ("';' expected"); RECOVER;}
1353 /* 19.10 Productions from 10: Arrays */
1356 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1357 | OCB_TK C_TK CCB_TK
1358 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1359 | OCB_TK variable_initializers CCB_TK
1360 { $$ = build_new_array_init ($1.location, $2); }
1361 | OCB_TK variable_initializers C_TK CCB_TK
1362 { $$ = build_new_array_init ($1.location, $2); }
1365 variable_initializers:
1366 variable_initializer
1368 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1371 | variable_initializers C_TK variable_initializer
1373 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1375 | variable_initializers C_TK error
1376 {yyerror ("Missing term"); RECOVER;}
1379 /* 19.11 Production from 14: Blocks and Statements */
1381 block_begin block_end
1383 | block_begin block_statements block_end
1395 maybe_absorb_scoping_blocks ();
1396 /* Store the location of the `}' when doing xrefs */
1397 if (current_function_decl && flag_emit_xref)
1398 DECL_END_SOURCE_LINE (current_function_decl) = $1.location;
1400 if (!BLOCK_SUBBLOCKS ($$))
1401 BLOCK_SUBBLOCKS ($$) = build_java_empty_stmt ();
1407 | block_statements block_statement
1411 local_variable_declaration_statement
1413 { java_method_add_stmt (current_function_decl, $1); }
1414 | class_declaration /* Added, JDK1.1 local classes */
1416 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1417 end_class_declaration (1);
1421 local_variable_declaration_statement:
1422 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1425 local_variable_declaration:
1426 type variable_declarators
1427 { declare_local_variables (0, $1, $2); }
1428 | final type variable_declarators /* Added, JDK1.1 final locals */
1429 { declare_local_variables ($1, $2, $3); }
1433 statement_without_trailing_substatement
1436 | if_then_else_statement
1439 { $$ = exit_block (); }
1443 statement_without_trailing_substatement
1444 | labeled_statement_nsi
1445 | if_then_else_statement_nsi
1446 | while_statement_nsi
1448 { $$ = exit_block (); }
1451 statement_without_trailing_substatement:
1454 | expression_statement
1458 | continue_statement
1460 | synchronized_statement
1469 if (flag_extraneous_semicolon
1470 && ! current_static_block
1471 && (! current_function_decl ||
1472 /* Verify we're not in a inner class declaration */
1473 (GET_CPC () != TYPE_NAME
1474 (DECL_CONTEXT (current_function_decl)))))
1477 #ifdef USE_MAPPED_LOCATION
1478 SET_EXPR_LOCATION (wfl_operator, input_location);
1480 EXPR_WFL_SET_LINECOL (wfl_operator, input_line, -1);
1482 parse_warning_context (wfl_operator, "An empty declaration is a deprecated feature that should not be used");
1484 $$ = build_java_empty_stmt ();
1489 identifier REL_CL_TK
1491 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1492 EXPR_WFL_NODE ($1));
1494 push_labeled_block ($$);
1495 PUSH_LABELED_BLOCK ($$);
1500 label_decl statement
1501 { $$ = finish_labeled_statement ($1, $2); }
1503 {yyerror ("':' expected"); RECOVER;}
1506 labeled_statement_nsi:
1507 label_decl statement_nsi
1508 { $$ = finish_labeled_statement ($1, $2); }
1511 /* We concentrate here a bunch of error handling rules that we couldn't write
1512 earlier, because expression_statement catches a missing ';'. */
1513 expression_statement:
1514 statement_expression SC_TK
1516 /* We have a statement. Generate a WFL around it so
1518 #ifdef USE_MAPPED_LOCATION
1519 $$ = expr_add_location ($1, input_location, 1);
1521 $$ = build_expr_wfl ($1, input_filename, input_line, 0);
1522 JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1524 /* We know we have a statement, so set the debug
1525 info to be eventually generate here. */
1529 YYNOT_TWICE yyerror ("Invalid expression statement");
1530 DRECOVER (expr_stmt);
1534 YYNOT_TWICE yyerror ("Invalid expression statement");
1535 DRECOVER (expr_stmt);
1539 YYNOT_TWICE yyerror ("Invalid expression statement");
1540 DRECOVER (expr_stmt);
1542 | this_or_super OP_TK error
1543 {yyerror ("')' expected"); RECOVER;}
1544 | this_or_super OP_TK CP_TK error
1546 parse_ctor_invocation_error ();
1549 | this_or_super OP_TK argument_list error
1550 {yyerror ("')' expected"); RECOVER;}
1551 | this_or_super OP_TK argument_list CP_TK error
1553 parse_ctor_invocation_error ();
1556 | name DOT_TK SUPER_TK error
1557 {yyerror ("'(' expected"); RECOVER;}
1558 | name DOT_TK SUPER_TK OP_TK error
1559 {yyerror ("')' expected"); RECOVER;}
1560 | name DOT_TK SUPER_TK OP_TK argument_list error
1561 {yyerror ("')' expected"); RECOVER;}
1562 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1563 {yyerror ("';' expected"); RECOVER;}
1564 | name DOT_TK SUPER_TK OP_TK CP_TK error
1565 {yyerror ("';' expected"); RECOVER;}
1568 statement_expression:
1570 | pre_increment_expression
1571 | pre_decrement_expression
1572 | post_increment_expression
1573 | post_decrement_expression
1575 | class_instance_creation_expression
1579 IF_TK OP_TK expression CP_TK statement
1581 $$ = build_if_else_statement ($2.location, $3,
1585 {yyerror ("'(' expected"); RECOVER;}
1587 {yyerror ("Missing term"); RECOVER;}
1588 | IF_TK OP_TK expression error
1589 {yyerror ("')' expected"); RECOVER;}
1592 if_then_else_statement:
1593 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1594 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1597 if_then_else_statement_nsi:
1598 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1599 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1609 /* Make into "proper list" of COMPOUND_EXPRs.
1610 I.e. make the last statement also have its own
1612 maybe_absorb_scoping_blocks ();
1613 TREE_OPERAND ($1, 1) = exit_block ();
1614 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1619 SWITCH_TK OP_TK expression CP_TK
1621 $$ = build3 (SWITCH_EXPR, NULL_TREE, $3,
1622 NULL_TREE, NULL_TREE);
1623 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
1626 {yyerror ("'(' expected"); RECOVER;}
1627 | SWITCH_TK OP_TK error
1628 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1629 | SWITCH_TK OP_TK expression CP_TK error
1630 {yyerror ("'{' expected"); RECOVER;}
1633 /* Default assignment is there to avoid type node on switch_block
1639 | OCB_TK switch_labels CCB_TK
1641 | OCB_TK switch_block_statement_groups CCB_TK
1643 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1647 switch_block_statement_groups:
1648 switch_block_statement_group
1649 | switch_block_statement_groups switch_block_statement_group
1652 switch_block_statement_group:
1653 switch_labels block_statements
1658 | switch_labels switch_label
1662 CASE_TK constant_expression REL_CL_TK
1664 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1665 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1666 java_method_add_stmt (current_function_decl, lab);
1668 | DEFAULT_TK REL_CL_TK
1670 tree lab = make_node (DEFAULT_EXPR);
1671 SET_EXPR_LOCATION_FROM_TOKEN (lab, $1);
1672 java_method_add_stmt (current_function_decl, lab);
1675 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1676 | CASE_TK constant_expression error
1677 {yyerror ("':' expected"); RECOVER;}
1679 {yyerror ("':' expected"); RECOVER;}
1683 WHILE_TK OP_TK expression CP_TK
1685 tree body = build_loop_body ($2.location, $3, 0);
1686 $$ = build_new_loop (body);
1691 while_expression statement
1692 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1694 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1695 | WHILE_TK OP_TK error
1696 {yyerror ("Missing term and ')' expected"); RECOVER;}
1697 | WHILE_TK OP_TK expression error
1698 {yyerror ("')' expected"); RECOVER;}
1701 while_statement_nsi:
1702 while_expression statement_nsi
1703 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1709 tree body = build_loop_body (0, NULL_TREE, 1);
1710 $$ = build_new_loop (body);
1712 /* Need error handing here. FIXME */
1716 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1717 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1721 for_begin SC_TK expression SC_TK for_update CP_TK statement
1723 if (CONSTANT_CLASS_P ($3))
1724 $3 = build_wfl_node ($3);
1725 $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1727 | for_begin SC_TK SC_TK for_update CP_TK statement
1729 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1730 /* We have not condition, so we get rid of the EXIT_EXPR */
1731 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1732 build_java_empty_stmt ();
1734 | for_begin SC_TK error
1735 {yyerror ("Invalid control expression"); RECOVER;}
1736 | for_begin SC_TK expression SC_TK error
1737 {yyerror ("Invalid update expression"); RECOVER;}
1738 | for_begin SC_TK SC_TK error
1739 {yyerror ("Invalid update expression"); RECOVER;}
1743 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1744 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1745 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1747 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1748 /* We have not condition, so we get rid of the EXIT_EXPR */
1749 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1750 build_java_empty_stmt ();
1757 /* This scope defined for local variable that may be
1758 defined within the scope of the for loop */
1762 {yyerror ("'(' expected"); DRECOVER(for_1);}
1763 | FOR_TK OP_TK error
1764 {yyerror ("Invalid init statement"); RECOVER;}
1770 /* We now declare the loop body. The loop is
1771 declared as a for loop. */
1772 tree body = build_loop_body (0, NULL_TREE, 0);
1773 $$ = build_new_loop (body);
1774 FOR_LOOP_P ($$) = 1;
1775 /* The loop is added to the current block the for
1776 statement is defined within */
1777 java_method_add_stmt (current_function_decl, $$);
1780 for_init: /* Can be empty */
1781 { $$ = build_java_empty_stmt (); }
1782 | statement_expression_list
1784 /* Init statement recorded within the previously
1785 defined block scope */
1786 $$ = java_method_add_stmt (current_function_decl, $1);
1788 | local_variable_declaration
1790 /* Local variable are recorded within the previously
1791 defined block scope */
1794 | statement_expression_list error
1795 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1798 for_update: /* Can be empty */
1799 {$$ = build_java_empty_stmt ();}
1800 | statement_expression_list
1801 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1804 statement_expression_list:
1805 statement_expression
1806 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1807 | statement_expression_list C_TK statement_expression
1808 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1809 | statement_expression_list C_TK error
1810 {yyerror ("Missing term"); RECOVER;}
1815 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1816 | BREAK_TK identifier SC_TK
1817 { $$ = build_bc_statement ($1.location, 1, $2); }
1819 {yyerror ("Missing term"); RECOVER;}
1820 | BREAK_TK identifier error
1821 {yyerror ("';' expected"); RECOVER;}
1826 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1827 | CONTINUE_TK identifier SC_TK
1828 { $$ = build_bc_statement ($1.location, 0, $2); }
1830 {yyerror ("Missing term"); RECOVER;}
1831 | CONTINUE_TK identifier error
1832 {yyerror ("';' expected"); RECOVER;}
1837 { $$ = build_return ($1.location, NULL_TREE); }
1838 | RETURN_TK expression SC_TK
1839 { $$ = build_return ($1.location, $2); }
1841 {yyerror ("Missing term"); RECOVER;}
1842 | RETURN_TK expression error
1843 {yyerror ("';' expected"); RECOVER;}
1847 THROW_TK expression SC_TK
1849 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1850 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1853 {yyerror ("Missing term"); RECOVER;}
1854 | THROW_TK expression error
1855 {yyerror ("';' expected"); RECOVER;}
1859 ASSERT_TK expression REL_CL_TK expression SC_TK
1861 $$ = build_assertion ($1.location, $2, $4);
1863 | ASSERT_TK expression SC_TK
1865 $$ = build_assertion ($1.location, $2, NULL_TREE);
1868 {yyerror ("Missing term"); RECOVER;}
1869 | ASSERT_TK expression error
1870 {yyerror ("';' expected"); RECOVER;}
1873 synchronized_statement:
1874 synchronized OP_TK expression CP_TK block
1876 $$ = build2 (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1877 EXPR_WFL_LINECOL ($$) =
1878 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1880 | synchronized OP_TK expression CP_TK error
1881 {yyerror ("'{' expected"); RECOVER;}
1882 | synchronized error
1883 {yyerror ("'(' expected"); RECOVER;}
1884 | synchronized OP_TK error CP_TK
1885 {yyerror ("Missing term"); RECOVER;}
1886 | synchronized OP_TK error
1887 {yyerror ("Missing term"); RECOVER;}
1894 "Illegal modifier %qs. Only %<synchronized%> was expected here",
1895 $1, ACC_SYNCHRONIZED);
1896 if ($1 != ACC_SYNCHRONIZED)
1897 MODIFIER_WFL (SYNCHRONIZED_TK) =
1898 build_wfl_node (NULL_TREE);
1903 TRY_TK block catches
1904 { $$ = build_try_statement ($1.location, $2, $3); }
1905 | TRY_TK block finally
1906 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1907 | TRY_TK block catches finally
1908 { $$ = build_try_finally_statement
1909 ($1.location, build_try_statement ($1.location,
1913 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1918 | catches catch_clause
1920 TREE_CHAIN ($2) = $1;
1926 catch_clause_parameter block
1928 java_method_add_stmt (current_function_decl, $2);
1934 catch_clause_parameter:
1935 CATCH_TK OP_TK formal_parameter CP_TK
1937 /* We add a block to define a scope for
1938 formal_parameter (CCBP). The formal parameter is
1939 declared initialized by the appropriate function
1945 ccpb = enter_block ();
1946 init = build_assignment
1947 (ASSIGN_TK, $2.location, TREE_PURPOSE ($3),
1948 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
1949 declare_local_variables (0, TREE_VALUE ($3),
1951 (TREE_PURPOSE ($3), init));
1952 $$ = build1 (JAVA_CATCH_EXPR, NULL_TREE, ccpb);
1953 SET_EXPR_LOCATION_FROM_TOKEN ($$, $1);
1957 $$ = error_mark_node;
1961 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1962 | CATCH_TK OP_TK error
1964 yyerror ("Missing term or ')' expected");
1965 RECOVER; $$ = NULL_TREE;
1967 | CATCH_TK OP_TK error CP_TK /* That's for () */
1968 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1975 {yyerror ("'{' expected"); RECOVER; }
1978 /* 19.12 Production from 15: Expressions */
1980 primary_no_new_array
1981 | array_creation_uninitialized
1982 | array_creation_initialized
1985 primary_no_new_array:
1988 { $$ = build_this ($1.location); }
1989 | OP_TK expression CP_TK
1991 | class_instance_creation_expression
1996 /* Added, JDK1.1 inner classes. Documentation is wrong
1997 referring to a 'ClassName' (class_name) rule that doesn't
1998 exist. Used name: instead. */
1999 | name DOT_TK THIS_TK
2001 tree wfl = build_wfl_node (this_identifier_node);
2002 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
2004 | OP_TK expression error
2005 {yyerror ("')' expected"); RECOVER;}
2007 {yyerror ("'class' or 'this' expected" ); RECOVER;}
2008 | primitive_type DOT_TK error
2009 {yyerror ("'class' expected" ); RECOVER;}
2010 | VOID_TK DOT_TK error
2011 {yyerror ("'class' expected" ); RECOVER;}
2015 name DOT_TK CLASS_TK
2016 { $$ = build_incomplete_class_ref ($2.location, $1); }
2017 | array_type DOT_TK CLASS_TK
2018 { $$ = build_incomplete_class_ref ($2.location, $1); }
2019 | primitive_type DOT_TK CLASS_TK
2020 { $$ = build_incomplete_class_ref ($2.location, $1); }
2021 | VOID_TK DOT_TK CLASS_TK
2023 $$ = build_incomplete_class_ref ($2.location,
2028 class_instance_creation_expression:
2029 NEW_TK class_type OP_TK argument_list CP_TK
2030 { $$ = build_new_invocation ($2, $4); }
2031 | NEW_TK class_type OP_TK CP_TK
2032 { $$ = build_new_invocation ($2, NULL_TREE); }
2033 | anonymous_class_creation
2034 /* Added, JDK1.1 inner classes, modified to use name or
2035 primary instead of primary solely which couldn't work in
2037 | something_dot_new identifier OP_TK CP_TK
2039 tree ctor = build_new_invocation ($2, NULL_TREE);
2040 $$ = make_qualified_primary ($1, ctor,
2041 EXPR_WFL_LINECOL ($1));
2043 | something_dot_new identifier OP_TK CP_TK class_body
2044 | something_dot_new identifier OP_TK argument_list CP_TK
2046 tree ctor = build_new_invocation ($2, $4);
2047 $$ = make_qualified_primary ($1, ctor,
2048 EXPR_WFL_LINECOL ($1));
2050 | something_dot_new identifier OP_TK argument_list CP_TK class_body
2051 | NEW_TK error SC_TK
2052 {$$ = NULL_TREE; yyerror ("'(' expected"); DRECOVER(new_1);}
2053 | NEW_TK class_type error
2054 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2055 | NEW_TK class_type OP_TK error
2056 {$$ = NULL_TREE; yyerror ("')' or term expected"); RECOVER;}
2057 | NEW_TK class_type OP_TK argument_list error
2058 {$$ = NULL_TREE; yyerror ("')' expected"); RECOVER;}
2059 | something_dot_new error
2063 yyerror ("Identifier expected");
2066 | something_dot_new identifier error
2067 {$$ = NULL_TREE; yyerror ("'(' expected"); RECOVER;}
2070 /* Created after JDK1.1 rules originally added to
2071 class_instance_creation_expression, but modified to use
2072 'class_type' instead of 'TypeName' (type_name) which is mentioned
2073 in the documentation but doesn't exist. */
2075 anonymous_class_creation:
2076 NEW_TK class_type OP_TK argument_list CP_TK
2077 { create_anonymous_class ($2); }
2080 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2081 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2083 end_class_declaration (1);
2085 /* Now we can craft the new expression */
2086 $$ = build_new_invocation (id, $4);
2088 /* Note that we can't possibly be here if
2089 `class_type' is an interface (in which case the
2090 anonymous class extends Object and implements
2091 `class_type', hence its constructor can't have
2094 /* Otherwise, the innerclass must feature a
2095 constructor matching `argument_list'. Anonymous
2096 classes are a bit special: it's impossible to
2097 define constructor for them, hence constructors
2098 must be generated following the hints provided by
2099 the `new' expression. Whether a super constructor
2100 of that nature exists or not is to be verified
2101 later on in verify_constructor_super.
2103 It's during the expansion of a `new' statement
2104 referring to an anonymous class that a ctor will
2105 be generated for the anonymous class, with the
2109 | NEW_TK class_type OP_TK CP_TK
2110 { create_anonymous_class ($2); }
2113 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2114 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2116 end_class_declaration (1);
2118 /* Now we can craft the new expression. The
2119 statement doesn't need to be remember so that a
2120 constructor can be generated, since its signature
2121 is already known. */
2122 $$ = build_new_invocation (id, NULL_TREE);
2126 something_dot_new: /* Added, not part of the specs. */
2129 | primary DOT_TK NEW_TK
2136 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2137 ctxp->formal_parameter_number = 1;
2139 | argument_list C_TK expression
2141 ctxp->formal_parameter_number += 1;
2142 $$ = tree_cons (NULL_TREE, $3, $1);
2144 | argument_list C_TK error
2145 {yyerror ("Missing term"); RECOVER;}
2148 array_creation_uninitialized:
2149 NEW_TK primitive_type dim_exprs
2150 { $$ = build_newarray_node ($2, $3, 0); }
2151 | NEW_TK class_or_interface_type dim_exprs
2152 { $$ = build_newarray_node ($2, $3, 0); }
2153 | NEW_TK primitive_type dim_exprs dims
2154 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2155 | NEW_TK class_or_interface_type dim_exprs dims
2156 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2157 | NEW_TK error CSB_TK
2158 {yyerror ("'[' expected"); DRECOVER ("]");}
2159 | NEW_TK error OSB_TK
2160 {yyerror ("']' expected"); RECOVER;}
2163 array_creation_initialized:
2164 /* Added, JDK1.1 anonymous array. Initial documentation rule
2166 NEW_TK class_or_interface_type dims array_initializer
2169 int osb = pop_current_osb (ctxp);
2171 obstack_grow (&temporary_obstack, "[]", 2);
2172 obstack_1grow (&temporary_obstack, '\0');
2173 sig = obstack_finish (&temporary_obstack);
2174 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2175 $2, get_identifier (sig), $4);
2177 | NEW_TK primitive_type dims array_initializer
2179 int osb = pop_current_osb (ctxp);
2182 type = build_java_array_type (type, -1);
2183 $$ = build3 (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2184 build_pointer_type (type), NULL_TREE, $4);
2186 | NEW_TK error CSB_TK
2187 {yyerror ("'[' expected"); DRECOVER ("]");}
2188 | NEW_TK error OSB_TK
2189 {yyerror ("']' expected"); RECOVER;}
2194 { $$ = build_tree_list (NULL_TREE, $1); }
2195 | dim_exprs dim_expr
2196 { $$ = tree_cons (NULL_TREE, $2, $$); }
2200 OSB_TK expression CSB_TK
2202 if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2204 $2 = build_wfl_node ($2);
2205 TREE_TYPE ($2) = NULL_TREE;
2207 EXPR_WFL_LINECOL ($2) = $1.location;
2210 | OSB_TK expression error
2211 {yyerror ("']' expected"); RECOVER;}
2214 yyerror ("Missing term");
2215 yyerror ("']' expected");
2224 /* If not initialized, allocate memory for the osb
2226 if (!ctxp->osb_limit)
2228 allocate = ctxp->osb_limit = 32;
2229 ctxp->osb_depth = -1;
2231 /* If capacity overflown, reallocate a bigger chunk */
2232 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2233 allocate = ctxp->osb_limit << 1;
2237 allocate *= sizeof (int);
2238 if (ctxp->osb_number)
2239 ctxp->osb_number = xrealloc (ctxp->osb_number,
2242 ctxp->osb_number = xmalloc (allocate);
2245 CURRENT_OSB (ctxp) = 1;
2247 | dims OSB_TK CSB_TK
2248 { CURRENT_OSB (ctxp)++; }
2250 { yyerror ("']' expected"); RECOVER;}
2254 primary DOT_TK identifier
2255 { $$ = make_qualified_primary ($1, $3, $2.location); }
2256 /* FIXME - REWRITE TO:
2257 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2258 | SUPER_TK DOT_TK identifier
2260 tree super_wfl = build_wfl_node (super_identifier_node);
2261 SET_EXPR_LOCATION_FROM_TOKEN (super_wfl, $1);
2262 $$ = make_qualified_name (super_wfl, $3, $2.location);
2265 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2270 { $$ = build_method_invocation ($1, NULL_TREE); }
2271 | name OP_TK argument_list CP_TK
2272 { $$ = build_method_invocation ($1, $3); }
2273 | primary DOT_TK identifier OP_TK CP_TK
2275 if (TREE_CODE ($1) == THIS_EXPR)
2276 $$ = build_this_super_qualified_invocation
2277 (1, $3, NULL_TREE, 0, $2.location);
2280 tree invok = build_method_invocation ($3, NULL_TREE);
2281 $$ = make_qualified_primary ($1, invok, $2.location);
2284 | primary DOT_TK identifier OP_TK argument_list CP_TK
2286 if (TREE_CODE ($1) == THIS_EXPR)
2287 $$ = build_this_super_qualified_invocation
2288 (1, $3, $5, 0, $2.location);
2291 tree invok = build_method_invocation ($3, $5);
2292 $$ = make_qualified_primary ($1, invok, $2.location);
2295 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2297 $$ = build_this_super_qualified_invocation
2298 (0, $3, NULL_TREE, $1.location, $2.location);
2300 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2302 $$ = build_this_super_qualified_invocation
2303 (0, $3, $5, $1.location, $2.location);
2305 /* Screws up thing. I let it here until I'm convinced it can
2307 | primary DOT_TK error
2308 {yyerror ("'(' expected"); DRECOVER(bad);} */
2309 | SUPER_TK DOT_TK error CP_TK
2310 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2311 | SUPER_TK DOT_TK error DOT_TK
2312 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2316 name OSB_TK expression CSB_TK
2317 { $$ = build_array_ref ($2.location, $1, $3); }
2318 | primary_no_new_array OSB_TK expression CSB_TK
2319 { $$ = build_array_ref ($2.location, $1, $3); }
2320 | array_creation_initialized OSB_TK expression CSB_TK
2321 { $$ = build_array_ref ($2.location, $1, $3); }
2324 yyerror ("Missing term and ']' expected");
2325 DRECOVER(array_access);
2327 | name OSB_TK expression error
2329 yyerror ("']' expected");
2330 DRECOVER(array_access);
2332 | primary_no_new_array OSB_TK error
2334 yyerror ("Missing term and ']' expected");
2335 DRECOVER(array_access);
2337 | primary_no_new_array OSB_TK expression error
2339 yyerror ("']' expected");
2340 DRECOVER(array_access);
2342 | array_creation_initialized OSB_TK error
2344 yyerror ("Missing term and ']' expected");
2345 DRECOVER(array_access);
2347 | array_creation_initialized OSB_TK expression error
2349 yyerror ("']' expected");
2350 DRECOVER(array_access);
2357 | post_increment_expression
2358 | post_decrement_expression
2361 post_increment_expression:
2362 postfix_expression INCR_TK
2363 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2366 post_decrement_expression:
2367 postfix_expression DECR_TK
2368 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2371 trap_overflow_corner_case:
2372 pre_increment_expression
2373 | pre_decrement_expression
2374 | PLUS_TK unary_expression
2375 {$$ = build_unaryop ($1.token, $1.location, $2); }
2376 | unary_expression_not_plus_minus
2378 {yyerror ("Missing term"); RECOVER}
2382 trap_overflow_corner_case
2385 error_if_numeric_overflow ($1);
2388 | MINUS_TK trap_overflow_corner_case
2389 {$$ = build_unaryop ($1.token, $1.location, $2); }
2391 {yyerror ("Missing term"); RECOVER}
2394 pre_increment_expression:
2395 INCR_TK unary_expression
2396 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2398 {yyerror ("Missing term"); RECOVER}
2401 pre_decrement_expression:
2402 DECR_TK unary_expression
2403 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2405 {yyerror ("Missing term"); RECOVER}
2408 unary_expression_not_plus_minus:
2410 | NOT_TK unary_expression
2411 {$$ = build_unaryop ($1.token, $1.location, $2); }
2412 | NEG_TK unary_expression
2413 {$$ = build_unaryop ($1.token, $1.location, $2); }
2416 {yyerror ("Missing term"); RECOVER}
2418 {yyerror ("Missing term"); RECOVER}
2421 cast_expression: /* Error handling here is potentially weak */
2422 OP_TK primitive_type dims CP_TK unary_expression
2425 int osb = pop_current_osb (ctxp);
2427 type = build_java_array_type (type, -1);
2428 $$ = build_cast ($1.location, type, $5);
2430 | OP_TK primitive_type CP_TK unary_expression
2431 { $$ = build_cast ($1.location, $2, $4); }
2432 | OP_TK expression CP_TK unary_expression_not_plus_minus
2433 { $$ = build_cast ($1.location, $2, $4); }
2434 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2437 int osb = pop_current_osb (ctxp);
2438 obstack_grow (&temporary_obstack,
2439 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2440 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2442 obstack_grow (&temporary_obstack, "[]", 2);
2443 obstack_1grow (&temporary_obstack, '\0');
2444 ptr = obstack_finish (&temporary_obstack);
2445 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2446 $$ = build_cast ($1.location, $2, $5);
2448 | OP_TK primitive_type OSB_TK error
2449 {yyerror ("']' expected, invalid type expression");}
2452 YYNOT_TWICE yyerror ("Invalid type expression"); RECOVER;
2455 | OP_TK primitive_type dims CP_TK error
2456 {yyerror ("Missing term"); RECOVER;}
2457 | OP_TK primitive_type CP_TK error
2458 {yyerror ("Missing term"); RECOVER;}
2459 | OP_TK name dims CP_TK error
2460 {yyerror ("Missing term"); RECOVER;}
2463 multiplicative_expression:
2465 | multiplicative_expression MULT_TK unary_expression
2467 $$ = build_binop (BINOP_LOOKUP ($2.token),
2468 $2.location, $1, $3);
2470 | multiplicative_expression DIV_TK unary_expression
2472 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2475 | multiplicative_expression REM_TK unary_expression
2477 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2480 | multiplicative_expression MULT_TK error
2481 {yyerror ("Missing term"); RECOVER;}
2482 | multiplicative_expression DIV_TK error
2483 {yyerror ("Missing term"); RECOVER;}
2484 | multiplicative_expression REM_TK error
2485 {yyerror ("Missing term"); RECOVER;}
2488 additive_expression:
2489 multiplicative_expression
2490 | additive_expression PLUS_TK multiplicative_expression
2492 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2495 | additive_expression MINUS_TK multiplicative_expression
2497 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2500 | additive_expression PLUS_TK error
2501 {yyerror ("Missing term"); RECOVER;}
2502 | additive_expression MINUS_TK error
2503 {yyerror ("Missing term"); RECOVER;}
2508 | shift_expression LS_TK additive_expression
2510 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2513 | shift_expression SRS_TK additive_expression
2515 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2518 | shift_expression ZRS_TK additive_expression
2520 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2523 | shift_expression LS_TK error
2524 {yyerror ("Missing term"); RECOVER;}
2525 | shift_expression SRS_TK error
2526 {yyerror ("Missing term"); RECOVER;}
2527 | shift_expression ZRS_TK error
2528 {yyerror ("Missing term"); RECOVER;}
2531 relational_expression:
2533 | relational_expression LT_TK shift_expression
2535 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2538 | relational_expression GT_TK shift_expression
2540 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2543 | relational_expression LTE_TK shift_expression
2545 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2548 | relational_expression GTE_TK shift_expression
2550 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2553 | relational_expression INSTANCEOF_TK reference_type
2554 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2555 | relational_expression LT_TK error
2556 {yyerror ("Missing term"); RECOVER;}
2557 | relational_expression GT_TK error
2558 {yyerror ("Missing term"); RECOVER;}
2559 | relational_expression LTE_TK error
2560 {yyerror ("Missing term"); RECOVER;}
2561 | relational_expression GTE_TK error
2562 {yyerror ("Missing term"); RECOVER;}
2563 | relational_expression INSTANCEOF_TK error
2564 {yyerror ("Invalid reference type"); RECOVER;}
2567 equality_expression:
2568 relational_expression
2569 | equality_expression EQ_TK relational_expression
2571 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2574 | equality_expression NEQ_TK relational_expression
2576 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2579 | equality_expression EQ_TK error
2580 {yyerror ("Missing term"); RECOVER;}
2581 | equality_expression NEQ_TK error
2582 {yyerror ("Missing term"); RECOVER;}
2587 | and_expression AND_TK equality_expression
2589 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2592 | and_expression AND_TK error
2593 {yyerror ("Missing term"); RECOVER;}
2596 exclusive_or_expression:
2598 | exclusive_or_expression XOR_TK and_expression
2600 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2603 | exclusive_or_expression XOR_TK error
2604 {yyerror ("Missing term"); RECOVER;}
2607 inclusive_or_expression:
2608 exclusive_or_expression
2609 | inclusive_or_expression OR_TK exclusive_or_expression
2611 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2614 | inclusive_or_expression OR_TK error
2615 {yyerror ("Missing term"); RECOVER;}
2618 conditional_and_expression:
2619 inclusive_or_expression
2620 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2622 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2625 | conditional_and_expression BOOL_AND_TK error
2626 {yyerror ("Missing term"); RECOVER;}
2629 conditional_or_expression:
2630 conditional_and_expression
2631 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2633 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2636 | conditional_or_expression BOOL_OR_TK error
2637 {yyerror ("Missing term"); RECOVER;}
2640 conditional_expression: /* Error handling here is weak */
2641 conditional_or_expression
2642 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2644 $$ = build3 (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2645 SET_EXPR_LOCATION_FROM_TOKEN ($$, $2);
2647 | conditional_or_expression REL_QM_TK REL_CL_TK error
2650 yyerror ("Missing term");
2653 | conditional_or_expression REL_QM_TK error
2654 {yyerror ("Missing term"); DRECOVER (2);}
2655 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2656 {yyerror ("Missing term"); DRECOVER (3);}
2659 assignment_expression:
2660 conditional_expression
2665 left_hand_side assignment_operator assignment_expression
2666 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2667 | left_hand_side assignment_operator error
2669 YYNOT_TWICE yyerror ("Missing term");
2680 assignment_operator:
2686 assignment_expression
2689 constant_expression:
2695 /* Helper function to retrieve an OSB count. Should be used when the
2696 `dims:' rule is being used. */
2699 pop_current_osb (struct parser_ctxt *ctxp)
2703 if (ctxp->osb_depth < 0)
2706 to_return = CURRENT_OSB (ctxp);
2714 /* This section of the code deal with save/restoring parser contexts.
2715 Add mode documentation here. FIXME */
2717 /* Helper function. Create a new parser context. With
2718 COPY_FROM_PREVIOUS set to a nonzero value, content of the previous
2719 context is copied, otherwise, the new context is zeroed. The newly
2720 created context becomes the current one. */
2723 create_new_parser_context (int copy_from_previous)
2725 struct parser_ctxt *new;
2727 new = ggc_alloc (sizeof (struct parser_ctxt));
2728 if (copy_from_previous)
2730 memcpy (new, ctxp, sizeof (struct parser_ctxt));
2731 /* This flag, indicating the context saves global values,
2732 should only be set by java_parser_context_save_global. */
2733 new->saved_data_ctx = 0;
2736 memset (new, 0, sizeof (struct parser_ctxt));
2742 /* Create a new parser context and make it the current one. */
2745 java_push_parser_context (void)
2747 create_new_parser_context (0);
2751 java_pop_parser_context (int generate)
2754 struct parser_ctxt *next;
2762 input_location = ctxp->save_location;
2763 current_class = ctxp->class_type;
2766 /* If the old and new lexers differ, then free the old one. */
2767 if (ctxp->lexer && next && ctxp->lexer != next->lexer)
2768 java_destroy_lexer (ctxp->lexer);
2770 /* Set the single import class file flag to 0 for the current list
2771 of imported things */
2772 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2773 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 0;
2775 /* If we pushed a context to parse a class intended to be generated,
2776 we keep it so we can remember the class. What we could actually
2777 do is to just update a list of class names. */
2780 ctxp->next = ctxp_for_generation;
2781 ctxp_for_generation = ctxp;
2784 /* And restore those of the previous context */
2785 if ((ctxp = next)) /* Assignment is really meant here */
2786 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2787 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_VALUE (current)) = 1;
2790 /* Create a parser context for the use of saving some global
2794 java_parser_context_save_global (void)
2798 java_push_parser_context ();
2799 ctxp->saved_data_ctx = 1;
2802 /* If this context already stores data, create a new one suitable
2803 for data storage. */
2804 else if (ctxp->saved_data)
2806 create_new_parser_context (1);
2807 ctxp->saved_data_ctx = 1;
2810 ctxp->save_location = input_location;
2811 ctxp->class_type = current_class;
2812 ctxp->function_decl = current_function_decl;
2813 ctxp->saved_data = 1;
2816 /* Restore some global variables from the previous context. Make the
2817 previous context the current one. */
2820 java_parser_context_restore_global (void)
2822 input_location = ctxp->save_location;
2823 current_class = ctxp->class_type;
2825 #ifdef USE_MAPPED_LOCATION
2826 SET_EXPR_LOCATION (wfl_operator, ctxp->save_location);
2828 EXPR_WFL_FILENAME_NODE (wfl_operator) = get_identifier (input_filename);
2830 current_function_decl = ctxp->function_decl;
2831 ctxp->saved_data = 0;
2832 if (ctxp->saved_data_ctx)
2833 java_pop_parser_context (0);
2836 /* Suspend vital data for the current class/function being parsed so
2837 that an other class can be parsed. Used to let local/anonymous
2838 classes be parsed. */
2841 java_parser_context_suspend (void)
2843 /* This makes debugging through java_debug_context easier */
2844 static const char *const name = "<inner buffer context>";
2846 /* Duplicate the previous context, use it to save the globals we're
2848 create_new_parser_context (1);
2849 ctxp->function_decl = current_function_decl;
2850 ctxp->class_type = current_class;
2852 /* Then create a new context which inherits all data from the
2853 previous one. This will be the new current context */
2854 create_new_parser_context (1);
2856 /* Help debugging */
2857 ctxp->next->filename = name;
2860 /* Resume vital data for the current class/function being parsed so
2861 that an other class can be parsed. Used to let local/anonymous
2862 classes be parsed. The trick is the data storing file position
2863 informations must be restored to their current value, so parsing
2864 can resume as if no context was ever saved. */
2867 java_parser_context_resume (void)
2869 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2870 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2871 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2873 /* We need to inherit the list of classes to complete/generate */
2874 restored->classd_list = old->classd_list;
2875 restored->class_list = old->class_list;
2877 /* Restore the current class and function from the saver */
2878 current_class = saver->class_type;
2879 current_function_decl = saver->function_decl;
2881 /* Retrieve the restored context */
2884 /* Re-installed the data for the parsing to carry on */
2885 memcpy (&ctxp->marker_begining, &old->marker_begining,
2886 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2889 /* Add a new anchor node to which all statement(s) initializing static
2890 and non static initialized upon declaration field(s) will be
2894 java_parser_context_push_initialized_field (void)
2898 node = build_tree_list (NULL_TREE, NULL_TREE);
2899 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2900 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2902 node = build_tree_list (NULL_TREE, NULL_TREE);
2903 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2904 CPC_INITIALIZER_LIST (ctxp) = node;
2906 node = build_tree_list (NULL_TREE, NULL_TREE);
2907 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2908 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2911 /* Pop the lists of initialized field. If this lists aren't empty,
2912 remember them so we can use it to create and populate the finit$
2913 or <clinit> functions. */
2916 java_parser_context_pop_initialized_field (void)
2919 tree class_type = TREE_TYPE (GET_CPC ());
2921 if (CPC_INITIALIZER_LIST (ctxp))
2923 stmts = CPC_INITIALIZER_STMT (ctxp);
2924 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2925 if (stmts && !java_error_count)
2926 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2929 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2931 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2932 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2933 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2934 /* Keep initialization in order to enforce 8.5 */
2935 if (stmts && !java_error_count)
2936 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2939 /* JDK 1.1 instance initializers */
2940 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2942 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2943 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2944 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2945 if (stmts && !java_error_count)
2946 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2951 reorder_static_initialized (tree list)
2953 /* We have to keep things in order. The alias initializer have to
2954 come first, then the initialized regular field, in reverse to
2955 keep them in lexical order. */
2956 tree marker, previous = NULL_TREE;
2957 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2958 if (TREE_CODE (marker) == TREE_LIST
2959 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2962 /* No static initialized, the list is fine as is */
2964 list = TREE_CHAIN (marker);
2966 /* No marker? reverse the whole list */
2968 list = nreverse (list);
2970 /* Otherwise, reverse what's after the marker and the new reordered
2971 sublist will replace the marker. */
2974 TREE_CHAIN (previous) = NULL_TREE;
2975 list = nreverse (list);
2976 list = chainon (TREE_CHAIN (marker), list);
2981 /* Helper functions to dump the parser context stack. */
2983 #define TAB_CONTEXT(C) \
2984 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2987 java_debug_context_do (int tab)
2989 struct parser_ctxt *copy = ctxp;
2993 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2995 fprintf (stderr, "filename: %s\n", copy->filename);
2997 fprintf (stderr, "package: %s\n",
2999 IDENTIFIER_POINTER (copy->package) : "<none>"));
3001 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
3003 fprintf (stderr, "saved data: %d\n", copy->saved_data);
3009 /* Dump the stacked up parser contexts. Intended to be called from a
3013 java_debug_context (void)
3015 java_debug_context_do (0);
3020 /* Flag for the error report routine to issue the error the first time
3021 it's called (overriding the default behavior which is to drop the
3022 first invocation and honor the second one, taking advantage of a
3024 static int force_error = 0;
3026 /* Reporting an constructor invocation error. */
3028 parse_ctor_invocation_error (void)
3030 if (DECL_CONSTRUCTOR_P (current_function_decl))
3031 yyerror ("Constructor invocation must be first thing in a constructor");
3033 yyerror ("Only constructors can invoke constructors");
3036 /* Reporting JDK1.1 features not implemented. */
3039 parse_jdk1_1_error (const char *msg)
3041 sorry (": %qs JDK1.1(TM) feature", msg);
3043 return build_java_empty_stmt ();
3046 static int do_warning = 0;
3049 yyerror (const char *msgid)
3051 #ifdef USE_MAPPED_LOCATION
3052 static source_location elc;
3053 expanded_location xloc = expand_location (input_location);
3054 int current_line = xloc.line;
3058 int current_line = input_line;
3060 static int prev_lineno;
3061 static const char *prev_msg;
3063 char *remainder, *code_from_source;
3065 if (!force_error && prev_lineno == current_line)
3067 #ifndef USE_MAPPED_LOCATION
3068 current_line = ctxp->lexer->token_start.line;
3071 /* Save current error location but report latter, when the context is
3073 if (ctxp->java_error_flag == 0)
3075 ctxp->java_error_flag = 1;
3076 #ifdef USE_MAPPED_LOCATION
3077 elc = input_location;
3079 elc = ctxp->lexer->token_start;
3081 /* Do something to use the previous line if we're reaching the
3082 end of the file... */
3083 #ifdef VERBOSE_SKELETON
3084 printf ("* Error detected (%s)\n", (msgid ? msgid : "(null)"));
3089 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
3090 if (!force_error && msgid == prev_msg && prev_lineno == current_line)
3093 ctxp->java_error_flag = 0;
3095 java_warning_count++;
3100 if (elc.col == 0 && msgid && msgid[1] == ';')
3101 elc = ctxp->prev_line_end;
3106 #ifdef USE_MAPPED_LOCATION
3107 prev_lineno = current_line;
3108 code_from_source = java_get_line_col (xloc.file, current_line, xloc.column);
3110 save_lineno = input_line;
3111 prev_lineno = input_line = current_line;
3112 code_from_source = java_get_line_col (input_filename, current_line,
3113 ctxp->lexer->token_start.col);
3117 obstack_grow0 (&temporary_obstack,
3118 code_from_source, strlen (code_from_source));
3119 remainder = obstack_finish (&temporary_obstack);
3121 warning ("%s.\n%s", msgid, remainder);
3123 error ("%s.\n%s", msgid, remainder);
3125 /* This allow us to cheaply avoid an extra 'Invalid expression
3126 statement' error report when errors have been already reported on
3127 the same line. This occurs when we report an error but don't have
3128 a synchronization point other than ';', which
3129 expression_statement is the only one to take care of. */
3130 #ifndef USE_MAPPED_LOCATION
3131 input_line = save_lineno;
3133 ctxp->prevent_ese = input_line;
3137 issue_warning_error_from_context (
3138 #ifdef USE_MAPPED_LOCATION
3143 const char *msgid, va_list *ap)
3145 #ifdef USE_MAPPED_LOCATION
3146 source_location saved_location = input_location;
3147 expanded_location xloc = expand_location (cl);
3149 java_lc save_lc = ctxp->lexer->token_start;
3150 const char *saved = ctxp->filename, *saved_input_filename;
3155 text.err_no = errno;
3157 text.format_spec = msgid;
3158 pp_format_text (global_dc->printer, &text);
3159 strncpy (buffer, pp_formatted_text (global_dc->printer), sizeof (buffer) - 1);
3160 buffer[sizeof (buffer) - 1] = '\0';
3161 pp_clear_output_area (global_dc->printer);
3165 #ifdef USE_MAPPED_LOCATION
3166 if (xloc.file != NULL)
3168 ctxp->filename = xloc.file;
3169 input_location = cl;
3172 ctxp->lexer->token_start.line = EXPR_WFL_LINENO (cl);
3173 ctxp->lexer->token_start.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1
3174 : EXPR_WFL_COLNO (cl) == 0xffe ? -2
3175 : EXPR_WFL_COLNO (cl));
3177 /* We have a CL, that's a good reason for using it if it contains data */
3178 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3179 ctxp->filename = EXPR_WFL_FILENAME (cl);
3180 saved_input_filename = input_filename;
3181 input_filename = ctxp->filename;
3184 java_error (buffer);
3185 #ifdef USE_MAPPED_LOCATION
3186 input_location = saved_location;
3188 ctxp->filename = saved;
3189 input_filename = saved_input_filename;
3190 ctxp->lexer->token_start = save_lc;
3195 /* Issue an error message at a current source line CL.
3196 FUTURE/FIXME: change cl to be a source_location. */
3199 parse_error_context (tree cl, const char *msgid, ...)
3202 va_start (ap, msgid);
3203 #ifdef USE_MAPPED_LOCATION
3204 issue_warning_error_from_context (EXPR_LOCATION (cl), msgid, &ap);
3206 issue_warning_error_from_context (cl, msgid, &ap);
3211 /* Issue a warning at a current source line CL.
3212 FUTURE/FIXME: change cl to be a source_location. */
3215 parse_warning_context (tree cl, const char *msgid, ...)
3218 va_start (ap, msgid);
3221 #ifdef USE_MAPPED_LOCATION
3222 issue_warning_error_from_context (EXPR_LOCATION (cl), msgid, &ap);
3224 issue_warning_error_from_context (cl, msgid, &ap);
3231 find_expr_with_wfl (tree node)
3235 enum tree_code_class code;
3238 switch (TREE_CODE (node))
3241 node = BLOCK_EXPR_BODY (node);
3245 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3248 node = TREE_OPERAND (node, 1);
3252 node = TREE_OPERAND (node, 0);
3255 case LABELED_BLOCK_EXPR:
3256 node = LABELED_BLOCK_BODY (node);
3260 code = TREE_CODE_CLASS (TREE_CODE (node));
3261 if (((code == tcc_unary) || (code == tcc_binary)
3262 || (code == tcc_expression))
3263 && EXPR_WFL_LINECOL (node))
3271 /* Issue a missing return statement error. Uses METHOD to figure the
3272 last line of the method the error occurs in. */
3275 missing_return_error (tree method)
3277 #ifdef USE_MAPPED_LOCATION
3278 SET_EXPR_LOCATION (wfl_operator, DECL_FUNCTION_LAST_LINE (method));
3280 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_FUNCTION_LAST_LINE (method), -2);
3282 parse_error_context (wfl_operator, "Missing return statement");
3285 /* Issue an unreachable statement error. From NODE, find the next
3286 statement to report appropriately. */
3288 unreachable_stmt_error (tree node)
3290 /* Browse node to find the next expression node that has a WFL. Use
3291 the location to report the error */
3292 if (TREE_CODE (node) == COMPOUND_EXPR)
3293 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3295 node = find_expr_with_wfl (node);
3299 #ifdef USE_MAPPED_LOCATION
3300 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
3302 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3304 parse_error_context (wfl_operator, "Unreachable statement");
3311 not_accessible_field_error (tree wfl, tree decl)
3314 (wfl, "Can't access %s field %<%s.%s%> from %qs",
3315 accessibility_string (get_access_flags_from_decl (decl)),
3316 GET_TYPE_NAME (DECL_CONTEXT (decl)),
3317 IDENTIFIER_POINTER (DECL_NAME (decl)),
3318 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
3323 java_report_errors (void)
3325 if (java_error_count)
3326 fprintf (stderr, "%d error%s",
3327 java_error_count, (java_error_count == 1 ? "" : "s"));
3328 if (java_warning_count)
3329 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3330 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3331 if (java_error_count || java_warning_count)
3332 putc ('\n', stderr);
3333 return java_error_count;
3337 java_accstring_lookup (int flags)
3339 static char buffer [80];
3340 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3342 /* Access modifier looked-up first for easier report on forbidden
3344 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3345 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3346 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3347 if (flags & ACC_STATIC) COPY_RETURN ("static");
3348 if (flags & ACC_FINAL) COPY_RETURN ("final");
3349 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3350 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3351 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3352 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3353 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3354 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3361 /* Returns a string denoting the accessibility of a class or a member as
3362 indicated by FLAGS. We need a separate function from
3363 java_accstring_lookup, as the latter can return spurious "static", etc.
3364 if package-private access is defined (in which case none of the
3365 relevant access control bits in FLAGS is set). */
3368 accessibility_string (int flags)
3370 if (flags & ACC_PRIVATE) return "private";
3371 if (flags & ACC_PROTECTED) return "protected";
3372 if (flags & ACC_PUBLIC) return "public";
3374 return "package-private";
3377 /* Issuing error messages upon redefinition of classes, interfaces or
3381 classitf_redefinition_error (const char *context, tree id, tree decl, tree cl)
3383 parse_error_context (cl, "%s %qs already defined in %s:%d",
3384 context, IDENTIFIER_POINTER (id),
3385 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3386 /* Here we should point out where its redefined. It's a unicode. FIXME */
3390 variable_redefinition_error (tree context, tree name, tree type, int line)
3392 const char *type_name;
3394 /* Figure a proper name for type. We might haven't resolved it */
3395 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3396 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3398 type_name = lang_printable_name (type, 0);
3400 parse_error_context (context,
3401 "Variable %qs is already defined in this method and was declared %<%s %s%> at line %d",
3402 IDENTIFIER_POINTER (name),
3403 type_name, IDENTIFIER_POINTER (name), line);
3406 /* If ANAME is terminated with `[]', it indicates an array. This
3407 function returns the number of `[]' found and if this number is
3408 greater than zero, it extracts the array type name and places it in
3409 the node pointed to by TRIMMED unless TRIMMED is null. */
3412 build_type_name_from_array_name (tree aname, tree *trimmed)
3414 const char *name = IDENTIFIER_POINTER (aname);
3415 int len = IDENTIFIER_LENGTH (aname);
3418 STRING_STRIP_BRACKETS (name, len, array_dims);
3420 if (array_dims && trimmed)
3421 *trimmed = get_identifier_with_length (name, len);
3427 build_array_from_name (tree type, tree type_wfl, tree name, tree *ret_name)
3431 /* Eventually get more dims */
3432 more_dims = build_type_name_from_array_name (name, &name);
3434 /* If we have, then craft a new type for this variable */
3439 /* If we have a pointer, use its type */
3440 if (TREE_CODE (type) == POINTER_TYPE)
3441 type = TREE_TYPE (type);
3443 /* Building the first dimension of a primitive type uses this
3445 if (JPRIMITIVE_TYPE_P (type))
3447 type = build_java_array_type (type, -1);
3450 /* Otherwise, if we have a WFL for this type, use it (the type
3451 is already an array on an unresolved type, and we just keep
3452 on adding dimensions) */
3456 more_dims += build_type_name_from_array_name (TYPE_NAME (save),
3460 /* Add all the dimensions */
3462 type = build_unresolved_array_type (type);
3464 /* The type may have been incomplete in the first place */
3466 type = obtain_incomplete_type (type);
3474 /* Build something that the type identifier resolver will identify as
3475 being an array to an unresolved type. TYPE_WFL is a WFL on a
3479 build_unresolved_array_type (tree type_or_wfl)
3484 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3485 just create a array type */
3486 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3487 return build_java_array_type (type_or_wfl, -1);
3489 obstack_grow (&temporary_obstack,
3490 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3491 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3492 obstack_grow0 (&temporary_obstack, "[]", 2);
3493 ptr = obstack_finish (&temporary_obstack);
3494 #ifdef USE_MAPPED_LOCATION
3495 wfl = build_expr_wfl (get_identifier (ptr), EXPR_LOCATION (type_or_wfl));
3497 wfl = build_expr_wfl (get_identifier (ptr),
3498 EXPR_WFL_FILENAME (type_or_wfl),
3499 EXPR_WFL_LINENO (type_or_wfl),
3500 EXPR_WFL_COLNO (type_or_wfl));
3502 /* Re-install the existing qualifications so that the type can be
3503 resolved properly. */
3504 EXPR_WFL_QUALIFICATION (wfl) = EXPR_WFL_QUALIFICATION (type_or_wfl);
3509 parser_add_interface (tree class_decl, tree interface_decl, tree wfl)
3511 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3512 parse_error_context (wfl, "Interface %qs repeated",
3513 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3516 /* Bulk of common class/interface checks. Return 1 if an error was
3517 encountered. TAG is 0 for a class, 1 for an interface. */
3520 check_class_interface_creation (int is_interface, int flags, tree raw_name,
3521 tree qualified_name, tree decl, tree cl)
3524 int sca = 0; /* Static class allowed */
3525 int icaf = 0; /* Inner class allowed flags */
3526 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3529 fprintf (stderr, " %s%s %s",
3530 (CPC_INNER_P () ? "inner" : ""),
3531 (is_interface ? "interface" : "class"),
3532 IDENTIFIER_POINTER (qualified_name));
3534 /* Scope of an interface/class type name:
3535 - Can't be imported by a single type import
3536 - Can't already exists in the package */
3537 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3538 && (node = find_name_in_single_imports (raw_name))
3542 (cl, "%s name %qs clashes with imported type %qs",
3543 (is_interface ? "Interface" : "Class"),
3544 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
3547 if (decl && CLASS_COMPLETE_P (decl))
3549 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
3550 qualified_name, decl, cl);
3554 if (check_inner_class_redefinition (raw_name, cl))
3557 /* If public, file name should match class/interface name, except
3558 when dealing with an inner class */
3559 if (!CPC_INNER_P () && (flags & ACC_PUBLIC ))
3561 const char *fname = input_filename;
3564 for (f = fname + strlen (fname);
3565 f != fname && ! IS_DIR_SEPARATOR (*f);
3568 if (IS_DIR_SEPARATOR (*f))
3570 if (strncmp (IDENTIFIER_POINTER (raw_name),
3571 f , IDENTIFIER_LENGTH (raw_name)) ||
3572 f [IDENTIFIER_LENGTH (raw_name)] != '.')
3574 (cl, "Public %s %qs must be defined in a file called %<%s.java%>",
3575 (is_interface ? "interface" : "class"),
3576 IDENTIFIER_POINTER (qualified_name),
3577 IDENTIFIER_POINTER (raw_name));
3580 /* Static classes can be declared only in top level classes. Note:
3581 once static, a inner class is a top level class. */
3582 if (flags & ACC_STATIC)
3584 /* Catch the specific error of declaring an class inner class
3585 with no toplevel enclosing class. Prevent check_modifiers from
3586 complaining a second time */
3587 if (CPC_INNER_P () && !TOPLEVEL_CLASS_DECL_P (GET_CPC()))
3589 parse_error_context (cl, "Inner class %qs can't be static. Static classes can only occur in interfaces and top-level classes",
3590 IDENTIFIER_POINTER (qualified_name));
3593 /* Else, in the context of a top-level class declaration, let
3594 `check_modifiers' do its job, otherwise, give it a go */
3596 sca = (GET_CPC_LIST () ? ACC_STATIC : 0);
3599 /* Inner classes can be declared private or protected
3600 within their enclosing classes. */
3603 /* A class which is local to a block can't be public, private,
3604 protected or static. But it is created final, so allow this
3606 if (current_function_decl)
3607 icaf = sca = uaaf = ACC_FINAL;
3610 check_modifiers_consistency (flags);
3611 icaf = ACC_PROTECTED;
3612 if (! CLASS_INTERFACE (GET_CPC ()))
3613 icaf |= ACC_PRIVATE;
3620 uaaf = INTERFACE_INNER_MODIFIERS;
3622 uaaf = INTERFACE_MODIFIERS;
3624 check_modifiers ("Illegal modifier %qs for interface declaration",
3628 check_modifiers ((current_function_decl ?
3629 "Illegal modifier %qs for local class declaration" :
3630 "Illegal modifier %qs for class declaration"),
3631 flags, uaaf|sca|icaf);
3635 /* Construct a nested class name. If the final component starts with
3636 a digit, return true. Otherwise return false. */
3638 make_nested_class_name (tree cpc_list)
3645 make_nested_class_name (TREE_CHAIN (cpc_list));
3647 /* Pick the qualified name when dealing with the first upmost
3649 name = (TREE_CHAIN (cpc_list)
3650 ? TREE_PURPOSE (cpc_list) : DECL_NAME (TREE_VALUE (cpc_list)));
3651 obstack_grow (&temporary_obstack,
3652 IDENTIFIER_POINTER (name), IDENTIFIER_LENGTH (name));
3653 obstack_1grow (&temporary_obstack, '$');
3655 return ISDIGIT (IDENTIFIER_POINTER (name)[0]);
3658 /* Can't redefine a class already defined in an earlier scope. */
3661 check_inner_class_redefinition (tree raw_name, tree cl)
3665 for (scope_list = GET_CPC_LIST (); scope_list;
3666 scope_list = GET_NEXT_ENCLOSING_CPC (scope_list))
3667 if (raw_name == GET_CPC_UN_NODE (scope_list))
3670 (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",
3671 IDENTIFIER_POINTER (raw_name));
3677 /* Tries to find a decl for CLASS_TYPE within ENCLOSING. If we fail,
3678 we remember ENCLOSING and SUPER. */
3681 resolve_inner_class (htab_t circularity_hash, tree cl, tree *enclosing,
3682 tree *super, tree class_type)
3684 tree local_enclosing = *enclosing;
3685 tree local_super = NULL_TREE;
3687 while (local_enclosing)
3689 tree intermediate, decl;
3691 *htab_find_slot (circularity_hash, local_enclosing, INSERT) =
3694 if ((decl = find_as_inner_class (local_enclosing, class_type, cl)))
3697 intermediate = local_enclosing;
3698 /* Explore enclosing contexts. */
3699 while (INNER_CLASS_DECL_P (intermediate))
3701 intermediate = DECL_CONTEXT (intermediate);
3702 if ((decl = find_as_inner_class (intermediate, class_type, cl)))
3706 /* Now go to the upper classes, bail out if necessary. We will
3707 analyze the returned SUPER and act accordingly (see
3708 do_resolve_class). */
3709 if (JPRIMITIVE_TYPE_P (TREE_TYPE (local_enclosing))
3710 || TREE_TYPE (local_enclosing) == void_type_node)
3712 parse_error_context (cl, "Qualifier must be a reference");
3713 local_enclosing = NULL_TREE;
3716 local_super = CLASSTYPE_SUPER (TREE_TYPE (local_enclosing));
3717 if (!local_super || local_super == object_type_node)
3720 if (TREE_CODE (local_super) == POINTER_TYPE)
3721 local_super = do_resolve_class (NULL, local_super, NULL, NULL);
3723 local_super = TYPE_NAME (local_super);
3725 /* We may not have checked for circular inheritance yet, so do so
3726 here to prevent an infinite loop. */
3727 if (htab_find (circularity_hash, local_super) != NULL)
3730 cl = lookup_cl (local_enclosing);
3733 (cl, "Cyclic inheritance involving %s",
3734 IDENTIFIER_POINTER (DECL_NAME (local_enclosing)));
3735 local_enclosing = NULL_TREE;
3738 local_enclosing = local_super;
3741 /* We failed. Return LOCAL_SUPER and LOCAL_ENCLOSING. */
3742 *super = local_super;
3743 *enclosing = local_enclosing;
3748 /* Within ENCLOSING, find a decl for NAME and return it. NAME can be
3752 find_as_inner_class (tree enclosing, tree name, tree cl)
3754 tree qual, to_return;
3758 name = TYPE_NAME (name);
3760 /* First search: within the scope of `enclosing', search for name */
3761 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3762 qual = EXPR_WFL_QUALIFICATION (cl);
3764 qual = build_tree_list (cl, NULL_TREE);
3766 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3768 if ((to_return = find_as_inner_class_do (qual, enclosing)))
3771 /* We're dealing with a qualified name. Try to resolve thing until
3772 we get something that is an enclosing class. */
3773 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3775 tree acc = NULL_TREE, decl = NULL_TREE, ptr;
3777 for (qual = EXPR_WFL_QUALIFICATION (cl); qual && !decl;
3778 qual = TREE_CHAIN (qual))
3780 acc = merge_qualified_name (acc,
3781 EXPR_WFL_NODE (TREE_PURPOSE (qual)));
3782 BUILD_PTR_FROM_NAME (ptr, acc);
3783 decl = do_resolve_class (NULL_TREE, ptr, NULL_TREE, cl);
3786 /* A NULL qual and a decl means that the search ended
3787 successfully?!? We have to do something then. FIXME */
3792 qual = EXPR_WFL_QUALIFICATION (cl);
3794 /* Otherwise, create a qual for the other part of the resolution. */
3796 qual = build_tree_list (build_unknown_wfl (name), NULL_TREE);
3798 return find_as_inner_class_do (qual, enclosing);
3801 /* We go inside the list of sub classes and try to find a way
3805 find_as_inner_class_do (tree qual, tree enclosing)
3810 for (; qual && enclosing; qual = TREE_CHAIN (qual))
3812 tree name_to_match = EXPR_WFL_NODE (TREE_PURPOSE (qual));
3813 tree next_enclosing = NULL_TREE;
3816 for (inner_list = DECL_INNER_CLASS_LIST (enclosing);
3817 inner_list; inner_list = TREE_CHAIN (inner_list))
3819 if (TREE_VALUE (inner_list) == name_to_match)
3821 next_enclosing = TREE_PURPOSE (inner_list);
3825 enclosing = next_enclosing;
3828 return (!qual && enclosing ? enclosing : NULL_TREE);
3832 link_nested_class_to_enclosing (void)
3834 if (GET_ENCLOSING_CPC ())
3836 tree enclosing = GET_ENCLOSING_CPC_CONTEXT ();
3837 DECL_INNER_CLASS_LIST (enclosing) =
3838 tree_cons (GET_CPC (), GET_CPC_UN (),
3839 DECL_INNER_CLASS_LIST (enclosing));
3844 maybe_make_nested_class_name (tree name)
3846 tree id = NULL_TREE;
3850 /* If we're in a function, we must append a number to create the
3851 nested class name. However, we don't do this if the class we
3852 are constructing is anonymous, because in that case we'll
3853 already have a number as the class name. */
3854 if (! make_nested_class_name (GET_CPC_LIST ())
3855 && current_function_decl != NULL_TREE
3856 && ! ISDIGIT (IDENTIFIER_POINTER (name)[0]))
3859 sprintf (buf, "%d", anonymous_class_counter);
3860 ++anonymous_class_counter;
3861 obstack_grow (&temporary_obstack, buf, strlen (buf));
3862 obstack_1grow (&temporary_obstack, '$');
3864 obstack_grow0 (&temporary_obstack,
3865 IDENTIFIER_POINTER (name),
3866 IDENTIFIER_LENGTH (name));
3867 id = get_identifier (obstack_finish (&temporary_obstack));
3869 QUALIFIED_P (id) = 1;
3874 /* If DECL is NULL, create and push a new DECL, record the current
3875 line CL and do other maintenance things. */
3878 maybe_create_class_interface_decl (tree decl, tree raw_name,
3879 tree qualified_name, tree cl)
3882 decl = push_class (make_class (), qualified_name);
3884 /* Take care of the file and line business */
3885 #ifdef USE_MAPPED_LOCATION
3886 DECL_SOURCE_LOCATION (decl) = EXPR_LOCATION (cl);
3888 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
3889 /* If we're emitting xrefs, store the line/col number information */
3891 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (cl);
3893 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
3895 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
3896 CLASS_PARSED_P (TREE_TYPE (decl)) = 1;
3897 #ifdef USE_MAPPED_LOCATION
3899 tree tmp = maybe_get_identifier (EXPR_FILENAME (cl));
3900 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3901 tmp && IS_A_COMMAND_LINE_FILENAME_P (tmp);
3904 CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
3905 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
3908 PUSH_CPC (decl, raw_name);
3909 DECL_CONTEXT (decl) = GET_ENCLOSING_CPC_CONTEXT ();
3911 /* Link the declaration to the already seen ones */
3912 TREE_CHAIN (decl) = ctxp->class_list;
3913 ctxp->class_list = decl;
3915 /* Create a new nodes in the global lists */
3916 gclass_list = tree_cons (NULL_TREE, decl, gclass_list);
3917 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
3919 /* Install a new dependency list element */
3920 create_jdep_list (ctxp);
3922 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
3923 IDENTIFIER_POINTER (qualified_name)));
3928 add_superinterfaces (tree decl, tree interface_list)
3931 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3932 takes care of ensuring that:
3933 - This is an accessible interface type,
3934 - Circularity detection.
3935 parser_add_interface is then called. If present but not defined,
3936 the check operation is delayed until the super interface gets
3938 for (node = interface_list; node; node = TREE_CHAIN (node))
3940 tree current = TREE_PURPOSE (node);
3941 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
3942 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
3944 if (!parser_check_super_interface (idecl, decl, current))
3945 parser_add_interface (decl, idecl, current);
3948 register_incomplete_type (JDEP_INTERFACE,
3949 current, decl, NULL_TREE);
3953 /* Create an interface in pass1 and return its decl. Return the
3954 interface's decl in pass 2. */
3957 create_interface (int flags, tree id, tree super)
3959 tree raw_name = EXPR_WFL_NODE (id);
3960 tree q_name = parser_qualified_classname (raw_name);
3961 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
3963 /* Certain syntax errors are making SUPER be like ID. Avoid this
3965 if (ctxp->class_err && id == super)
3968 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
3970 /* Basic checks: scope, redefinition, modifiers */
3971 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
3977 /* Suspend the current parsing context if we're parsing an inner
3981 java_parser_context_suspend ();
3982 /* Interface members are public. */
3983 if (CLASS_INTERFACE (GET_CPC ()))
3984 flags |= ACC_PUBLIC;
3987 /* Push a new context for (static) initialized upon declaration fields */
3988 java_parser_context_push_initialized_field ();
3990 /* Interface modifiers check
3991 - public/abstract allowed (already done at that point)
3992 - abstract is obsolete (comes first, it's a warning, or should be)
3993 - Can't use twice the same (checked in the modifier rule) */
3994 if ((flags & ACC_ABSTRACT) && flag_redundant)
3995 parse_warning_context
3996 (MODIFIER_WFL (ABSTRACT_TK),
3997 "Redundant use of %<abstract%> modifier. Interface %qs is implicitly abstract", IDENTIFIER_POINTER (raw_name));
3999 /* Create a new decl if DECL is NULL, otherwise fix it */
4000 decl = maybe_create_class_interface_decl (decl, raw_name, q_name, id);
4002 /* Interfaces are always abstract. */
4003 flags |= ACC_ABSTRACT;
4005 /* Inner interfaces are always static. */
4006 if (INNER_CLASS_DECL_P (decl))
4007 flags |= ACC_STATIC;
4009 /* Set super info and mark the class a complete */
4010 set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
4011 object_type_node, ctxp->interface_number);
4012 ctxp->interface_number = 0;
4013 CLASS_COMPLETE_P (decl) = 1;
4014 add_superinterfaces (decl, super);
4016 /* Eventually sets the @deprecated tag flag */
4017 CHECK_DEPRECATED (decl);
4022 /* Patch anonymous class CLASS, by either extending or implementing
4026 patch_anonymous_class (tree type_decl, tree class_decl, tree wfl)
4028 tree class = TREE_TYPE (class_decl);
4029 tree type = TREE_TYPE (type_decl);
4030 tree binfo = TYPE_BINFO (class);
4032 /* If it's an interface, implement it */
4033 if (CLASS_INTERFACE (type_decl))
4035 if (parser_check_super_interface (type_decl, class_decl, wfl))
4038 if (!VEC_space (tree, BINFO_BASE_BINFOS (binfo), 1))
4040 /* Extend the binfo - by reallocating and copying it. */
4045 new_binfo = make_tree_binfo ((BINFO_N_BASE_BINFOS (binfo) + 1) * 2);
4046 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
4047 BINFO_BASE_APPEND (new_binfo, base_binfo);
4048 CLASS_HAS_SUPER_FLAG (new_binfo) = CLASS_HAS_SUPER_FLAG (binfo);
4049 BINFO_VTABLE (new_binfo) = BINFO_VTABLE (binfo);
4050 TYPE_BINFO (class) = new_binfo;
4053 /* And add the interface */
4054 parser_add_interface (class_decl, type_decl, wfl);
4056 /* Otherwise, it's a type we want to extend */
4059 if (parser_check_super (type_decl, class_decl, wfl))
4061 BINFO_TYPE (BINFO_BASE_BINFO (binfo, 0)) = type;
4065 /* Create an anonymous class which extends/implements TYPE_NAME, and return
4069 create_anonymous_class (tree type_name)
4072 tree super = NULL_TREE, itf = NULL_TREE;
4073 tree id, type_decl, class;
4075 /* The unqualified name of the anonymous class. It's just a number. */
4076 sprintf (buffer, "%d", anonymous_class_counter++);
4077 id = build_wfl_node (get_identifier (buffer));
4078 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL (type_name);
4080 /* We know about the type to extend/implement. We go ahead */
4081 if ((type_decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (type_name))))
4083 /* Create a class which either implements on extends the designated
4084 class. The class bears an inaccessible name. */
4085 if (CLASS_INTERFACE (type_decl))
4087 /* It's OK to modify it here. It's been already used and
4088 shouldn't be reused */
4089 ctxp->interface_number = 1;
4090 /* Interfaces should presented as a list of WFLs */
4091 itf = build_tree_list (type_name, NULL_TREE);
4097 class = create_class (ACC_FINAL, id, super, itf);
4099 /* We didn't know anything about the stuff. We register a dependence. */
4101 register_incomplete_type (JDEP_ANONYMOUS, type_name, class, NULL_TREE);
4103 ANONYMOUS_CLASS_P (TREE_TYPE (class)) = 1;
4107 /* Create a class in pass1 and return its decl. Return class
4108 interface's decl in pass 2. */
4111 create_class (int flags, tree id, tree super, tree interfaces)
4113 tree raw_name = EXPR_WFL_NODE (id);
4114 tree class_id, decl;
4115 tree super_decl_type;
4117 /* Certain syntax errors are making SUPER be like ID. Avoid this
4119 if (ctxp->class_err && id == super)
4122 class_id = parser_qualified_classname (raw_name);
4123 decl = IDENTIFIER_CLASS_VALUE (class_id);
4124 EXPR_WFL_NODE (id) = class_id;
4126 /* Basic check: scope, redefinition, modifiers */
4127 if (check_class_interface_creation (0, flags, raw_name, class_id, decl, id))
4133 /* Suspend the current parsing context if we're parsing an inner
4134 class or an anonymous class. */
4137 java_parser_context_suspend ();
4138 /* Interface members are public. */
4139 if (CLASS_INTERFACE (GET_CPC ()))
4140 flags |= ACC_PUBLIC;
4143 /* Push a new context for (static) initialized upon declaration fields */
4144 java_parser_context_push_initialized_field ();
4146 /* Class modifier check:
4147 - Allowed modifier (already done at that point)
4148 - abstract AND final forbidden
4149 - Public classes defined in the correct file */
4150 if ((flags & ACC_ABSTRACT) && (flags & ACC_FINAL))
4152 (id, "Class %qs can't be declared both abstract and final",
4153 IDENTIFIER_POINTER (raw_name));
4155 /* Create a new decl if DECL is NULL, otherwise fix it */
4156 decl = maybe_create_class_interface_decl (decl, raw_name, class_id, id);
4158 /* If SUPER exists, use it, otherwise use Object */
4161 /* java.lang.Object can't extend anything. */
4162 if (TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_id)) == object_type_node)
4164 parse_error_context (id, "%<java.lang.Object%> can't extend anything");
4169 register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
4171 else if (TREE_TYPE (decl) != object_type_node)
4172 super_decl_type = object_type_node;
4173 /* We're defining java.lang.Object */
4175 super_decl_type = NULL_TREE;
4177 /* A class nested in an interface is implicitly static. */
4178 if (INNER_CLASS_DECL_P (decl)
4179 && CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (DECL_CONTEXT (decl)))))
4181 flags |= ACC_STATIC;
4184 /* Set super info and mark the class as complete. */
4185 set_super_info (flags, TREE_TYPE (decl), super_decl_type,
4186 ctxp->interface_number);
4187 ctxp->interface_number = 0;
4188 CLASS_COMPLETE_P (decl) = 1;
4189 add_superinterfaces (decl, interfaces);
4191 /* TYPE_VFIELD' is a compiler-generated field used to point to
4192 virtual function tables. In gcj, every class has a common base
4193 virtual function table in java.lang.object. */
4194 TYPE_VFIELD (TREE_TYPE (decl)) = TYPE_VFIELD (object_type_node);
4196 /* Add the private this$<n> field, Replicate final locals still in
4197 scope as private final fields mangled like val$<local_name>.
4198 This does not occur for top level (static) inner classes. */
4199 if (PURE_INNER_CLASS_DECL_P (decl))
4200 add_inner_class_fields (decl, current_function_decl);
4202 /* If doing xref, store the location at which the inherited class
4203 (if any) was seen. */
4204 if (flag_emit_xref && super)
4205 DECL_INHERITED_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (super);
4207 /* Eventually sets the @deprecated tag flag */
4208 CHECK_DEPRECATED (decl);
4210 /* Reset the anonymous class counter when declaring non inner classes */
4211 if (!INNER_CLASS_DECL_P (decl))
4212 anonymous_class_counter = 1;
4217 /* End a class declaration: register the statements used to create
4218 finit$ and <clinit>, pop the current class and resume the prior
4219 parser context if necessary. */
4222 end_class_declaration (int resume)
4224 /* If an error occurred, context weren't pushed and won't need to be
4225 popped by a resume. */
4226 int no_error_occurred = ctxp->next && GET_CPC () != error_mark_node;
4228 if (GET_CPC () != error_mark_node)
4229 dump_java_tree (TDI_class, GET_CPC ());
4231 java_parser_context_pop_initialized_field ();
4233 if (resume && no_error_occurred)
4234 java_parser_context_resume ();
4236 /* We're ending a class declaration, this is a good time to reset
4237 the interface cout. Note that might have been already done in
4238 create_interface, but if at that time an inner class was being
4239 dealt with, the interface count was reset in a context created
4240 for the sake of handling inner classes declaration. */
4241 ctxp->interface_number = 0;
4245 add_inner_class_fields (tree class_decl, tree fct_decl)
4247 tree block, marker, f;
4249 f = add_field (TREE_TYPE (class_decl),
4250 build_current_thisn (TREE_TYPE (class_decl)),
4251 build_pointer_type (TREE_TYPE (DECL_CONTEXT (class_decl))),
4253 FIELD_THISN (f) = 1;
4258 for (block = GET_CURRENT_BLOCK (fct_decl);
4259 block && TREE_CODE (block) == BLOCK; block = BLOCK_SUPERCONTEXT (block))
4262 for (decl = BLOCK_EXPR_DECLS (block); decl; decl = TREE_CHAIN (decl))
4265 tree wfl, init, list;
4267 /* Avoid non final arguments. */
4268 if (!LOCAL_FINAL_P (decl))
4271 MANGLE_OUTER_LOCAL_VARIABLE_NAME (name, DECL_NAME (decl));
4272 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID (pname, DECL_NAME (decl));
4273 wfl = build_wfl_node (name);
4274 init = build_wfl_node (pname);
4275 /* Build an initialization for the field: it will be
4276 initialized by a parameter added to finit$, bearing a
4277 mangled name of the field itself (param$<n>.) The
4278 parameter is provided to finit$ by the constructor
4279 invoking it (hence the constructor will also feature a
4280 hidden parameter, set to the value of the outer context
4281 local at the time the inner class is created.)
4283 Note: we take into account all possible locals that can
4284 be accessed by the inner class. It's actually not trivial
4285 to minimize these aliases down to the ones really
4286 used. One way to do that would be to expand all regular
4287 methods first, then finit$ to get a picture of what's
4288 used. It works with the exception that we would have to
4289 go back on all constructor invoked in regular methods to
4290 have their invocation reworked (to include the right amount
4291 of alias initializer parameters.)
4293 The only real way around, I think, is a first pass to
4294 identify locals really used in the inner class. We leave
4295 the flag FIELD_LOCAL_ALIAS_USED around for that future
4298 On the other hand, it only affect local inner classes,
4299 whose constructors (and finit$ call) will be featuring
4300 unnecessary arguments. It's easy for a developer to keep
4301 this number of parameter down by using the `final'
4302 keyword only when necessary. For the time being, we can
4303 issue a warning on unnecessary finals. FIXME */
4304 init = build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (wfl),
4307 /* Register the field. The TREE_LIST holding the part
4308 initialized/initializer will be marked ARG_FINAL_P so
4309 that the created field can be marked
4310 FIELD_LOCAL_ALIAS. */
4311 list = build_tree_list (wfl, init);
4312 ARG_FINAL_P (list) = 1;
4313 register_fields (ACC_PRIVATE | ACC_FINAL, TREE_TYPE (decl), list);
4317 if (!CPC_INITIALIZER_STMT (ctxp))
4320 /* If we ever registered an alias field, insert and marker to
4321 remember where the list ends. The second part of the list (the one
4322 featuring initialized fields) so it can be later reversed to
4323 enforce 8.5. The marker will be removed during that operation. */
4324 marker = build_tree_list (NULL_TREE, NULL_TREE);
4325 TREE_CHAIN (marker) = CPC_INITIALIZER_STMT (ctxp);
4326 SET_CPC_INITIALIZER_STMT (ctxp, marker);
4329 /* Can't use lookup_field () since we don't want to load the class and
4330 can't set the CLASS_LOADED_P flag */
4333 find_field (tree class, tree name)
4336 for (decl = TYPE_FIELDS (class); decl; decl = TREE_CHAIN (decl))
4338 if (DECL_NAME (decl) == name)
4344 /* Wrap around lookup_field that doesn't potentially upset the value
4348 lookup_field_wrapper (tree class, tree name)
4351 tree decl = NULL_TREE;
4352 java_parser_context_save_global ();
4354 /* Last chance: if we're within the context of an inner class, we
4355 might be trying to access a local variable defined in an outer
4356 context. We try to look for it now. */
4357 if (INNER_CLASS_TYPE_P (class) && TREE_CODE (name) == IDENTIFIER_NODE)
4360 MANGLE_OUTER_LOCAL_VARIABLE_NAME (new_name, name);
4361 decl = lookup_field (&type, new_name);
4362 if (decl && decl != error_mark_node)
4363 FIELD_LOCAL_ALIAS_USED (decl) = 1;
4365 if (!decl || decl == error_mark_node)
4368 decl = lookup_field (&type, name);
4371 /* If the field still hasn't been found, try the next enclosing context. */
4372 if (!decl && INNER_CLASS_TYPE_P (class))
4374 tree outer_type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class)));
4375 decl = lookup_field_wrapper (outer_type, name);
4378 java_parser_context_restore_global ();
4379 return decl == error_mark_node ? NULL : decl;
4382 /* Find duplicate field within the same class declarations and report
4383 the error. Returns 1 if a duplicated field was found, 0
4387 duplicate_declaration_error_p (tree new_field_name, tree new_type, tree cl)
4389 /* This might be modified to work with method decl as well */
4390 tree decl = find_field (TREE_TYPE (GET_CPC ()), new_field_name);
4393 char *t1 = xstrdup (purify_type_name
4394 ((TREE_CODE (new_type) == POINTER_TYPE
4395 && TREE_TYPE (new_type) == NULL_TREE) ?
4396 IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
4397 lang_printable_name (new_type, 1)));
4398 /* The type may not have been completed by the time we report
4400 char *t2 = xstrdup (purify_type_name
4401 ((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
4402 && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
4403 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
4404 lang_printable_name (TREE_TYPE (decl), 1)));
4406 (cl, "Duplicate variable declaration: %<%s %s%> was %<%s %s%> (%s:%d)",
4407 t1, IDENTIFIER_POINTER (new_field_name),
4408 t2, IDENTIFIER_POINTER (DECL_NAME (decl)),
4409 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
4417 /* Field registration routine. If TYPE doesn't exist, field
4418 declarations are linked to the undefined TYPE dependency list, to
4419 be later resolved in java_complete_class () */
4422 register_fields (int flags, tree type, tree variable_list)
4424 tree current, saved_type;
4425 tree class_type = NULL_TREE;
4426 location_t saved_location = input_location;
4428 tree wfl = NULL_TREE;
4431 class_type = TREE_TYPE (GET_CPC ());
4433 if (!class_type || class_type == error_mark_node)
4436 /* If we're adding fields to interfaces, those fields are public,
4438 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
4440 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK),
4441 flags, ACC_PUBLIC, "interface field(s)");
4442 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (STATIC_TK),
4443 flags, ACC_STATIC, "interface field(s)");
4444 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (FINAL_TK),
4445 flags, ACC_FINAL, "interface field(s)");
4446 check_modifiers ("Illegal interface member modifier %qs", flags,
4447 INTERFACE_FIELD_MODIFIERS);
4448 flags |= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
4451 /* Obtain a suitable type for resolution, if necessary */
4452 SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
4454 /* If TYPE is fully resolved and we don't have a reference, make one */
4455 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4457 for (current = variable_list, saved_type = type; current;
4458 current = TREE_CHAIN (current), type = saved_type)
4462 tree cl = TREE_PURPOSE (current);
4463 tree init = TREE_VALUE (current);
4464 tree current_name = EXPR_WFL_NODE (cl);
4466 /* Can't declare non-final static fields in inner classes */
4467 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (class_type)
4468 && !(flags & ACC_FINAL))
4470 (cl, "Field %qs can't be static in inner class %qs unless it is final",
4471 IDENTIFIER_POINTER (EXPR_WFL_NODE (cl)),
4472 lang_printable_name (class_type, 0));
4474 /* Process NAME, as it may specify extra dimension(s) for it */
4475 type = build_array_from_name (type, wfl, current_name, ¤t_name);
4477 /* Type adjustment. We may have just readjusted TYPE because
4478 the variable specified more dimensions. Make sure we have
4479 a reference if we can and don't have one already. Also
4480 change the name if we have an init. */
4481 if (type != saved_type)
4483 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4485 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
4488 real_type = GET_REAL_TYPE (type);
4489 /* Check for redeclarations */
4490 if (duplicate_declaration_error_p (current_name, real_type, cl))
4493 /* Set input_line to the line the field was found and create a
4494 declaration for it. Eventually sets the @deprecated tag flag. */
4495 #ifdef USE_MAPPED_LOCATION
4496 input_location = EXPR_LOCATION (cl);
4499 input_line = EXPR_WFL_LINECOL (cl);
4501 input_line = EXPR_WFL_LINENO (cl);
4503 field_decl = add_field (class_type, current_name, real_type, flags);
4504 CHECK_DEPRECATED_NO_RESET (field_decl);
4506 /* If the field denotes a final instance variable, then we
4507 allocate a LANG_DECL_SPECIFIC part to keep track of its
4508 initialization. We also mark whether the field was
4509 initialized upon its declaration. We don't do that if the
4510 created field is an alias to a final local. */
4511 if (!ARG_FINAL_P (current) && (flags & ACC_FINAL))
4513 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (field_decl);
4514 DECL_FIELD_FINAL_WFL (field_decl) = cl;
4517 /* If the couple initializer/initialized is marked ARG_FINAL_P,
4518 we mark the created field FIELD_LOCAL_ALIAS, so that we can
4519 hide parameters to this inner class finit$ and
4520 constructors. It also means that the field isn't final per
4522 if (ARG_FINAL_P (current))
4524 FIELD_LOCAL_ALIAS (field_decl) = 1;
4525 FIELD_FINAL (field_decl) = 0;
4528 /* Check if we must chain. */
4530 register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
4532 /* If we have an initialization value tied to the field */
4535 /* The field is declared static */
4536 if (flags & ACC_STATIC)
4538 /* We include the field and its initialization part into
4539 a list used to generate <clinit>. After <clinit> is
4540 walked, field initializations will be processed and
4541 fields initialized with known constants will be taken
4542 out of <clinit> and have their DECL_INITIAL set
4544 TREE_CHAIN (init) = CPC_STATIC_INITIALIZER_STMT (ctxp);
4545 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, init);
4546 if (TREE_OPERAND (init, 1)
4547 && TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
4548 TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
4550 /* A non-static field declared with an immediate initialization is
4551 to be initialized in <init>, if any. This field is remembered
4552 to be processed at the time of the generation of <init>. */
4555 TREE_CHAIN (init) = CPC_INITIALIZER_STMT (ctxp);
4556 SET_CPC_INITIALIZER_STMT (ctxp, init);
4558 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
4559 DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
4564 input_location = saved_location;
4567 /* Generate finit$, using the list of initialized fields to populate
4568 its body. finit$'s parameter(s) list is adjusted to include the
4569 one(s) used to initialized the field(s) caching outer context
4573 generate_finit (tree class_type)
4576 tree list = TYPE_FINIT_STMT_LIST (class_type);
4577 tree mdecl, current, parms;
4579 parms = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
4580 class_type, NULL_TREE,
4582 CRAFTED_PARAM_LIST_FIXUP (parms);
4583 mdecl = create_artificial_method (class_type, ACC_PRIVATE, void_type_node,
4584 finit_identifier_node, parms);
4585 fix_method_argument_names (parms, mdecl);
4586 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4588 DECL_FUNCTION_NAP (mdecl) = count;
4589 start_artificial_method_body (mdecl);
4591 for (current = list; current; current = TREE_CHAIN (current))
4592 java_method_add_stmt (mdecl,
4593 build_debugable_stmt (EXPR_WFL_LINECOL (current),
4595 end_artificial_method_body (mdecl);
4599 /* Generate a function to run the instance initialization code. The
4600 private method is called `instinit$'. Unless we're dealing with an
4601 anonymous class, we determine whether all ctors of CLASS_TYPE
4602 declare a checked exception in their `throws' clause in order to
4603 see whether it's necessary to encapsulate the instance initializer
4604 statements in a try/catch/rethrow sequence. */
4607 generate_instinit (tree class_type)
4610 tree compound = NULL_TREE;
4611 tree parms = tree_cons (this_identifier_node,
4612 build_pointer_type (class_type), end_params_node);
4613 tree mdecl = create_artificial_method (class_type, ACC_PRIVATE,
4615 instinit_identifier_node, parms);
4617 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4620 /* Gather all the statements in a compound */
4621 for (current = TYPE_II_STMT_LIST (class_type);
4622 current; current = TREE_CHAIN (current))
4623 compound = add_stmt_to_compound (compound, NULL_TREE, current);
4625 /* We need to encapsulate COMPOUND by a try/catch statement to
4626 rethrow exceptions that might occur in the instance initializer.
4627 We do that only if all ctors of CLASS_TYPE are set to catch a
4628 checked exception. This doesn't apply to anonymous classes (since
4629 they don't have declared ctors.) */
4630 if (!ANONYMOUS_CLASS_P (class_type) &&
4631 ctors_unchecked_throws_clause_p (class_type))
4633 compound = encapsulate_with_try_catch (0, exception_type_node, compound,
4634 build1 (THROW_EXPR, NULL_TREE,
4635 build_wfl_node (wpv_id)));
4636 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (NULL_TREE,
4637 exception_type_node);
4640 start_artificial_method_body (mdecl);
4641 java_method_add_stmt (mdecl, compound);
4642 end_artificial_method_body (mdecl);
4649 build_instinit_invocation (tree class_type)
4651 tree to_return = NULL_TREE;
4653 if (TYPE_II_STMT_LIST (class_type))
4655 tree parm = build_tree_list (NULL_TREE,
4656 build_wfl_node (this_identifier_node));
4658 build_method_invocation (build_wfl_node (instinit_identifier_node),
4664 /* Shared across method_declarator and method_header to remember the
4665 patch stage that was reached during the declaration of the method.
4666 A method DECL is built differently is there is no patch
4667 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
4668 pending on the currently defined method. */
4670 static int patch_stage;
4672 /* Check the method declaration and add the method to its current
4673 class. If the argument list is known to contain incomplete types,
4674 the method is partially added and the registration will be resume
4675 once the method arguments resolved. If TYPE is NULL, we're dealing
4676 with a constructor. */
4679 method_header (int flags, tree type, tree mdecl, tree throws)
4681 tree type_wfl = NULL_TREE;
4682 tree meth_name = NULL_TREE;
4683 tree current, orig_arg, this_class = NULL;
4685 location_t saved_location;
4686 int constructor_ok = 0, must_chain;
4689 if (mdecl == error_mark_node)
4690 return error_mark_node;
4691 meth = TREE_VALUE (mdecl);
4692 id = TREE_PURPOSE (mdecl);
4694 check_modifiers_consistency (flags);
4697 this_class = TREE_TYPE (GET_CPC ());
4699 if (!this_class || this_class == error_mark_node)
4702 /* There are some forbidden modifiers for an abstract method and its
4703 class must be abstract as well. */
4704 if (type && (flags & ACC_ABSTRACT))
4706 ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
4707 ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
4708 ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
4709 ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
4710 ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED, id, "Synchronized");
4711 ABSTRACT_CHECK (flags, ACC_STRICT, id, "Strictfp");
4712 if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
4713 && !CLASS_INTERFACE (TYPE_NAME (this_class)))
4716 "Class %qs must be declared abstract to define abstract method %qs",
4717 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())),
4718 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4721 /* A native method can't be strictfp. */
4722 if ((flags & ACC_NATIVE) && (flags & ACC_STRICT))
4723 parse_error_context (id, "native method %qs can't be strictfp",
4724 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4725 /* No such thing as a transient or volatile method. */
4726 if ((flags & ACC_TRANSIENT))
4727 parse_error_context (id, "method %qs can't be transient",
4728 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4729 if ((flags & ACC_VOLATILE))
4730 parse_error_context (id, "method %qs can't be volatile",
4731 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4733 /* Things to be checked when declaring a constructor */
4736 int ec = java_error_count;
4737 /* 8.6: Constructor declarations: we might be trying to define a
4738 method without specifying a return type. */
4739 if (EXPR_WFL_NODE (id) != GET_CPC_UN ())
4741 (id, "Invalid method declaration, return type required");
4742 /* 8.6.3: Constructor modifiers */
4745 JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
4746 JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
4747 JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
4748 JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
4749 JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
4750 JCONSTRUCTOR_CHECK (flags, ACC_STRICT, id, "strictfp");
4752 /* If we found error here, we don't consider it's OK to tread
4753 the method definition as a constructor, for the rest of this
4755 if (ec == java_error_count)
4759 /* Method declared within the scope of an interface are implicitly
4760 abstract and public. Conflicts with other erroneously provided
4761 modifiers are checked right after. */
4763 if (CLASS_INTERFACE (TYPE_NAME (this_class)))
4765 /* If FLAGS isn't set because of a modifier, turn the
4766 corresponding modifier WFL to NULL so we issue a warning on
4767 the obsolete use of the modifier */
4768 if (!(flags & ACC_PUBLIC))
4769 MODIFIER_WFL (PUBLIC_TK) = NULL;
4770 if (!(flags & ACC_ABSTRACT))
4771 MODIFIER_WFL (ABSTRACT_TK) = NULL;
4772 flags |= ACC_PUBLIC;
4773 flags |= ACC_ABSTRACT;
4776 /* Inner class can't declare static methods */
4777 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (this_class))
4780 (id, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
4781 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)),
4782 lang_printable_name (this_class, 0));
4785 /* Modifiers context reset moved up, so abstract method declaration
4786 modifiers can be later checked. */
4788 /* Set constructor returned type to void and method name to <init>,
4789 unless we found an error identifier the constructor (in which
4790 case we retain the original name) */
4793 type = void_type_node;
4795 meth_name = init_identifier_node;
4798 meth_name = EXPR_WFL_NODE (id);
4800 /* Do the returned type resolution and registration if necessary */
4801 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
4804 type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
4805 EXPR_WFL_NODE (id) = meth_name;
4806 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4810 patch_stage = JDEP_METHOD_RETURN;
4811 register_incomplete_type (patch_stage, type_wfl, id, type);
4812 TREE_TYPE (meth) = GET_REAL_TYPE (type);
4815 TREE_TYPE (meth) = type;
4817 saved_location = input_location;
4818 /* When defining an abstract or interface method, the curly
4819 bracket at level 1 doesn't exist because there is no function
4821 #ifdef USE_MAPPED_LOCATION
4822 input_location = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 :
4823 EXPR_LOCATION (id));
4825 input_line = (ctxp->first_ccb_indent1 ? (int) ctxp->first_ccb_indent1 :
4826 EXPR_WFL_LINENO (id));
4829 /* Remember the original argument list */
4830 orig_arg = TYPE_ARG_TYPES (meth);
4832 if (patch_stage) /* includes ret type and/or all args */
4835 meth = add_method_1 (this_class, flags, meth_name, meth);
4836 /* Patch for the return type */
4837 if (patch_stage == JDEP_METHOD_RETURN)
4839 jdep = CLASSD_LAST (ctxp->classd_list);
4840 JDEP_GET_PATCH (jdep) = &TREE_TYPE (TREE_TYPE (meth));
4842 /* This is the stop JDEP. METH allows the function's signature
4844 register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
4847 meth = add_method (this_class, flags, meth_name,
4848 build_java_signature (meth));
4850 /* Remember final parameters */
4851 MARK_FINAL_PARMS (meth, orig_arg);
4853 /* Fix the method argument list so we have the argument name
4855 fix_method_argument_names (orig_arg, meth);
4857 /* Register the parameter number and re-install the current line
4859 DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
4860 input_location = saved_location;
4862 /* Register exception specified by the `throws' keyword for
4863 resolution and set the method decl appropriate field to the list.
4864 Note: the grammar ensures that what we get here are class
4868 throws = nreverse (throws);
4869 for (current = throws; current; current = TREE_CHAIN (current))
4871 register_incomplete_type (JDEP_EXCEPTION, TREE_VALUE (current),
4872 NULL_TREE, NULL_TREE);
4873 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
4874 &TREE_VALUE (current);
4876 DECL_FUNCTION_THROWS (meth) = throws;
4879 if (TREE_TYPE (GET_CPC ()) != object_type_node)
4880 DECL_FUNCTION_WFL (meth) = id;
4882 /* Set the flag if we correctly processed a constructor */
4885 DECL_CONSTRUCTOR_P (meth) = 1;
4886 /* Compute and store the number of artificial parameters declared
4887 for this constructor */
4888 for (count = 0, current = TYPE_FIELDS (this_class); current;
4889 current = TREE_CHAIN (current))
4890 if (FIELD_LOCAL_ALIAS (current))
4892 DECL_FUNCTION_NAP (meth) = count;
4895 /* Eventually set the @deprecated tag flag */
4896 CHECK_DEPRECATED (meth);
4898 /* If doing xref, store column and line number information instead
4899 of the line number only. */
4902 #ifdef USE_MAPPED_LOCATION
4903 DECL_SOURCE_LOCATION (meth) = EXPR_LOCATION (id);
4905 DECL_SOURCE_LINE (meth) = EXPR_WFL_LINECOL (id);
4913 fix_method_argument_names (tree orig_arg, tree meth)
4915 tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
4916 if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
4918 TREE_PURPOSE (arg) = this_identifier_node;
4919 arg = TREE_CHAIN (arg);
4921 while (orig_arg != end_params_node)
4923 TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
4924 orig_arg = TREE_CHAIN (orig_arg);
4925 arg = TREE_CHAIN (arg);
4929 /* Complete the method declaration with METHOD_BODY. */
4932 finish_method_declaration (tree method_body)
4936 if (!current_function_decl)
4939 flags = get_access_flags_from_decl (current_function_decl);
4941 /* 8.4.5 Method Body */
4942 if ((flags & ACC_ABSTRACT || flags & ACC_NATIVE) && method_body)
4944 tree name = DECL_NAME (current_function_decl);
4945 parse_error_context (DECL_FUNCTION_WFL (current_function_decl),
4946 "%s method %qs can't have a body defined",
4947 (METHOD_NATIVE (current_function_decl) ?
4948 "Native" : "Abstract"),
4949 IDENTIFIER_POINTER (name));
4950 method_body = NULL_TREE;
4952 else if (!(flags & ACC_ABSTRACT) && !(flags & ACC_NATIVE) && !method_body)
4954 tree name = DECL_NAME (current_function_decl);
4956 (DECL_FUNCTION_WFL (current_function_decl),
4957 "Non native and non abstract method %qs must have a body defined",
4958 IDENTIFIER_POINTER (name));
4959 method_body = NULL_TREE;
4962 if (flag_emit_class_files && method_body
4963 && TREE_CODE (method_body) == NOP_EXPR
4964 && TREE_TYPE (current_function_decl)
4965 && TREE_TYPE (TREE_TYPE (current_function_decl)) == void_type_node)
4966 method_body = build1 (RETURN_EXPR, void_type_node, NULL);
4968 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
4969 maybe_absorb_scoping_blocks ();
4970 /* Exit function's body */
4972 /* Merge last line of the function with first line, directly in the
4973 function decl. It will be used to emit correct debug info. */
4974 if (!flag_emit_xref)
4975 DECL_FUNCTION_LAST_LINE (current_function_decl) = ctxp->last_ccb_indent1;
4977 /* Since function's argument's list are shared, reset the
4978 ARG_FINAL_P parameter that might have been set on some of this
4979 function parameters. */
4980 UNMARK_FINAL_PARMS (current_function_decl);
4982 /* So we don't have an irrelevant function declaration context for
4983 the next static block we'll see. */
4984 current_function_decl = NULL_TREE;
4987 /* Build a an error message for constructor circularity errors. */
4990 constructor_circularity_msg (tree from, tree to)
4992 static char string [4096];
4993 char *t = xstrdup (lang_printable_name (from, 2));
4994 sprintf (string, "'%s' invokes '%s'", t, lang_printable_name (to, 2));
4999 /* Verify a circular call to METH. Return 1 if an error is found, 0
5002 static GTY(()) tree vcc_list;
5004 verify_constructor_circularity (tree meth, tree current)
5008 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
5010 if (TREE_VALUE (c) == meth)
5016 vcc_list = nreverse (vcc_list);
5017 for (liste = vcc_list; liste; liste = TREE_CHAIN (liste))
5020 (TREE_PURPOSE (TREE_PURPOSE (liste)), "%s",
5021 constructor_circularity_msg
5022 (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste))));
5026 t = xstrdup (lang_printable_name (meth, 2));
5027 parse_error_context (TREE_PURPOSE (c),
5028 "%s: recursive invocation of constructor %qs",
5029 constructor_circularity_msg (current, meth), t);
5031 vcc_list = NULL_TREE;
5035 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
5037 vcc_list = tree_cons (c, current, vcc_list);
5038 if (verify_constructor_circularity (meth, TREE_VALUE (c)))
5040 vcc_list = TREE_CHAIN (vcc_list);
5045 /* Check modifiers that can be declared but exclusively */
5048 check_modifiers_consistency (int flags)
5051 tree cl = NULL_TREE;
5053 THIS_MODIFIER_ONLY (flags, ACC_PUBLIC, PUBLIC_TK, acc_count, cl);
5054 THIS_MODIFIER_ONLY (flags, ACC_PRIVATE, PRIVATE_TK, acc_count, cl);
5055 THIS_MODIFIER_ONLY (flags, ACC_PROTECTED, PROTECTED_TK, acc_count, cl);
5058 (cl, "Inconsistent member declaration. At most one of %<public%>, %<private%>, or %<protected%> may be specified");
5062 THIS_MODIFIER_ONLY (flags, ACC_FINAL, FINAL_TK, acc_count, cl);
5063 THIS_MODIFIER_ONLY (flags, ACC_VOLATILE, VOLATILE_TK, acc_count, cl);
5065 parse_error_context (cl,
5066 "Inconsistent member declaration. At most one of %<final%> or %<volatile%> may be specified");
5069 /* Check the methode header METH for abstract specifics features */
5072 check_abstract_method_header (tree meth)
5074 int flags = get_access_flags_from_decl (meth);
5076 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (ABSTRACT_TK), flags,
5077 ACC_ABSTRACT, "abstract method",
5078 IDENTIFIER_POINTER (DECL_NAME (meth)));
5079 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (PUBLIC_TK), flags,
5080 ACC_PUBLIC, "abstract method",
5081 IDENTIFIER_POINTER (DECL_NAME (meth)));
5083 check_modifiers ("Illegal modifier %qs for interface method",
5084 flags, INTERFACE_METHOD_MODIFIERS);
5087 /* Create a FUNCTION_TYPE node and start augmenting it with the
5088 declared function arguments. Arguments type that can't be resolved
5089 are left as they are, but the returned node is marked as containing
5090 incomplete types. */
5093 method_declarator (tree id, tree list)
5095 tree arg_types = NULL_TREE, current, node;
5096 tree meth = make_node (FUNCTION_TYPE);
5099 patch_stage = JDEP_NO_PATCH;
5101 if (GET_CPC () == error_mark_node)
5102 return error_mark_node;
5104 /* If we're dealing with an inner class constructor, we hide the
5105 this$<n> decl in the name field of its parameter declaration. We
5106 also might have to hide the outer context local alias
5107 initializers. Not done when the class is a toplevel class. */
5108 if (PURE_INNER_CLASS_DECL_P (GET_CPC ())
5109 && EXPR_WFL_NODE (id) == GET_CPC_UN ())
5111 tree aliases_list, type, thisn;
5112 /* First the aliases, linked to the regular parameters */
5114 build_alias_initializer_parameter_list (AIPL_FUNCTION_DECLARATION,
5115 TREE_TYPE (GET_CPC ()),
5117 list = chainon (nreverse (aliases_list), list);
5120 type = TREE_TYPE (DECL_CONTEXT (GET_CPC ()));
5121 thisn = build_current_thisn (TREE_TYPE (GET_CPC ()));
5122 list = tree_cons (build_wfl_node (thisn), build_pointer_type (type),
5126 for (current = list; current; current = TREE_CHAIN (current))
5129 tree wfl_name = TREE_PURPOSE (current);
5130 tree type = TREE_VALUE (current);
5131 tree name = EXPR_WFL_NODE (wfl_name);
5132 tree already, arg_node;
5133 tree type_wfl = NULL_TREE;
5136 /* Obtain a suitable type for resolution, if necessary */
5137 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
5139 /* Process NAME, as it may specify extra dimension(s) for it */
5140 type = build_array_from_name (type, type_wfl, name, &name);
5141 EXPR_WFL_NODE (wfl_name) = name;
5143 real_type = GET_REAL_TYPE (type);
5144 if (TREE_CODE (real_type) == RECORD_TYPE)
5146 real_type = promote_type (real_type);
5147 if (TREE_CODE (type) == TREE_LIST)
5148 TREE_PURPOSE (type) = real_type;
5151 /* Check redefinition */
5152 for (already = arg_types; already; already = TREE_CHAIN (already))
5153 if (TREE_PURPOSE (already) == name)
5156 (wfl_name, "Variable %qs is used more than once in the argument list of method %qs",
5157 IDENTIFIER_POINTER (name),
5158 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
5162 /* If we've an incomplete argument type, we know there is a location
5163 to patch when the type get resolved, later. */
5167 patch_stage = JDEP_METHOD;
5168 type = register_incomplete_type (patch_stage,
5169 type_wfl, wfl_name, type);
5170 jdep = CLASSD_LAST (ctxp->classd_list);
5171 JDEP_MISC (jdep) = id;
5174 /* The argument node: a name and a (possibly) incomplete type. */
5175 arg_node = build_tree_list (name, real_type);
5176 /* Remember arguments declared final. */
5177 ARG_FINAL_P (arg_node) = ARG_FINAL_P (current);
5180 JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
5181 TREE_CHAIN (arg_node) = arg_types;
5182 arg_types = arg_node;
5184 TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
5185 node = build_tree_list (id, meth);
5190 unresolved_type_p (tree wfl, tree *returned)
5192 if (TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION)
5196 tree decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (wfl));
5197 if (decl && current_class && (decl == TYPE_NAME (current_class)))
5198 *returned = TREE_TYPE (decl);
5199 else if (GET_CPC_UN () == EXPR_WFL_NODE (wfl))
5200 *returned = TREE_TYPE (GET_CPC ());
5202 *returned = NULL_TREE;
5211 /* From NAME, build a qualified identifier node using the
5212 qualification from the current package definition. */
5215 parser_qualified_classname (tree name)
5217 tree nested_class_name;
5219 if ((nested_class_name = maybe_make_nested_class_name (name)))
5220 return nested_class_name;
5223 return merge_qualified_name (ctxp->package, name);
5228 /* Called once the type a interface extends is resolved. Returns 0 if
5229 everything is OK. */
5232 parser_check_super_interface (tree super_decl, tree this_decl, tree this_wfl)
5234 tree super_type = TREE_TYPE (super_decl);
5236 /* Has to be an interface */
5237 if (!CLASS_INTERFACE (super_decl))
5240 (this_wfl, "%s %qs can't implement/extend %s %qs",
5241 (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (this_decl))) ?
5242 "Interface" : "Class"),
5243 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5244 (TYPE_ARRAY_P (super_type) ? "array" : "class"),
5245 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5249 /* Check top-level interface access. Inner classes are subject to member
5250 access rules (6.6.1). */
5251 if (! INNER_CLASS_P (super_type)
5252 && check_pkg_class_access (DECL_NAME (super_decl),
5253 NULL_TREE, true, this_decl))
5256 SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
5257 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5258 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
5262 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
5263 0 if everything is OK. */
5266 parser_check_super (tree super_decl, tree this_decl, tree wfl)
5268 tree super_type = TREE_TYPE (super_decl);
5270 /* SUPER should be a CLASS (neither an array nor an interface) */
5271 if (TYPE_ARRAY_P (super_type) || CLASS_INTERFACE (TYPE_NAME (super_type)))
5274 (wfl, "Class %qs can't subclass %s %qs",
5275 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5276 (CLASS_INTERFACE (TYPE_NAME (super_type)) ? "interface" : "array"),
5277 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5281 if (CLASS_FINAL (TYPE_NAME (super_type)))
5283 parse_error_context (wfl, "Can't subclass final classes: %s",
5284 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
5288 /* Check top-level class scope. Inner classes are subject to member access
5290 if (! INNER_CLASS_P (super_type)
5291 && (check_pkg_class_access (DECL_NAME (super_decl), wfl, true, NULL_TREE)))
5294 SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
5295 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
5296 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
5300 /* Create a new dependency list and link it (in a LIFO manner) to the
5301 CTXP list of type dependency list. */
5304 create_jdep_list (struct parser_ctxt *ctxp)
5306 jdeplist *new = xmalloc (sizeof (jdeplist));
5307 new->first = new->last = NULL;
5308 new->next = ctxp->classd_list;
5309 ctxp->classd_list = new;
5313 reverse_jdep_list (struct parser_ctxt *ctxp)
5315 jdeplist *prev = NULL, *current, *next;
5316 for (current = ctxp->classd_list; current; current = next)
5318 next = current->next;
5319 current->next = prev;
5325 /* Create a fake pointer based on the ID stored in
5326 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
5327 registered again. */
5330 obtain_incomplete_type (tree type_name)
5332 tree ptr = NULL_TREE, name;
5334 if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
5335 name = EXPR_WFL_NODE (type_name);
5336 else if (INCOMPLETE_TYPE_P (type_name))
5337 name = TYPE_NAME (type_name);
5341 /* Workaround from build_pointer_type for incomplete types. */
5342 BUILD_PTR_FROM_NAME (ptr, name);
5343 TYPE_MODE (ptr) = ptr_mode;
5349 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
5350 non NULL instead of computing a new fake type based on WFL. The new
5351 dependency is inserted in the current type dependency list, in FIFO
5355 register_incomplete_type (int kind, tree wfl, tree decl, tree ptr)
5357 jdep *new = xmalloc (sizeof (jdep));
5359 if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
5360 ptr = obtain_incomplete_type (wfl);
5362 JDEP_KIND (new) = kind;
5363 JDEP_DECL (new) = decl;
5364 JDEP_TO_RESOLVE (new) = ptr;
5365 JDEP_WFL (new) = wfl;
5366 JDEP_CHAIN (new) = NULL;
5367 JDEP_MISC (new) = NULL_TREE;
5368 /* For some dependencies, set the enclosing class of the current
5369 class to be the enclosing context */
5370 if ((kind == JDEP_INTERFACE || kind == JDEP_ANONYMOUS || kind == JDEP_SUPER)
5371 && GET_ENCLOSING_CPC ())
5372 JDEP_ENCLOSING (new) = TREE_VALUE (GET_ENCLOSING_CPC ());
5374 JDEP_ENCLOSING (new) = GET_CPC ();
5375 JDEP_GET_PATCH (new) = (tree *)NULL;
5377 JDEP_INSERT (ctxp->classd_list, new);
5382 /* This checks for circular references with innerclasses. We start
5383 from SOURCE and should never reach TARGET. Extended/implemented
5384 types in SOURCE have their enclosing context checked not to reach
5385 TARGET. When the last enclosing context of SOURCE is reached, its
5386 extended/implemented types are also checked not to reach TARGET.
5387 In case of error, WFL of the offending type is returned; NULL_TREE
5391 check_inner_circular_reference (tree source, tree target)
5397 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (source), i, base_binfo); i++)
5401 /* We can end up with a NULL_TREE or an incomplete type here if
5402 we encountered previous type resolution errors. It's safe to
5403 simply ignore these cases. */
5404 su = BINFO_TYPE (base_binfo);
5405 if (INCOMPLETE_TYPE_P (su))
5408 if (inherits_from_p (su, target))
5409 return lookup_cl (TYPE_NAME (su));
5411 for (ctx = DECL_CONTEXT (TYPE_NAME (su)); ctx; ctx = DECL_CONTEXT (ctx))
5413 /* An enclosing context shouldn't be TARGET */
5414 if (ctx == TYPE_NAME (target))
5415 return lookup_cl (TYPE_NAME (su));
5417 /* When we reach the enclosing last context, start a check
5418 on it, with the same target */
5419 if (! DECL_CONTEXT (ctx) &&
5420 (cl = check_inner_circular_reference (TREE_TYPE (ctx), target)))
5427 /* Explore TYPE's `extends' clause member(s) and return the WFL of the
5428 offending type if a circularity is detected. NULL_TREE is returned
5429 otherwise. TYPE can be an interface or a class. */
5432 check_circular_reference (tree type)
5437 if (!BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
5440 if (! CLASS_INTERFACE (TYPE_NAME (type)))
5442 if (inherits_from_p (CLASSTYPE_SUPER (type), type))
5443 return lookup_cl (TYPE_NAME (type));
5447 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (type), i, base_binfo); i++)
5449 if (BINFO_TYPE (base_binfo) != object_type_node
5450 && interface_of_p (type, BINFO_TYPE (base_binfo)))
5451 return lookup_cl (TYPE_NAME (BINFO_TYPE (base_binfo)));
5457 java_check_circular_reference (void)
5460 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5462 tree type = TREE_TYPE (current);
5465 cl = check_circular_reference (type);
5467 cl = check_inner_circular_reference (type, type);
5469 parse_error_context (cl, "Cyclic class inheritance%s",
5470 (cyclic_inheritance_report ?
5471 cyclic_inheritance_report : ""));
5475 /* Augment the parameter list PARM with parameters crafted to
5476 initialize outer context locals aliases. Through ARTIFICIAL, a
5477 count is kept of the number of crafted parameters. MODE governs
5478 what eventually gets created: something suitable for a function
5479 creation or a function invocation, either the constructor or
5483 build_alias_initializer_parameter_list (int mode, tree class_type, tree parm,
5487 tree additional_parms = NULL_TREE;
5489 for (field = TYPE_FIELDS (class_type); field; field = TREE_CHAIN (field))
5490 if (FIELD_LOCAL_ALIAS (field))
5492 const char *buffer = IDENTIFIER_POINTER (DECL_NAME (field));
5493 tree purpose = NULL_TREE, value = NULL_TREE, name = NULL_TREE;
5498 case AIPL_FUNCTION_DECLARATION:
5499 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (mangled_id,
5501 purpose = build_wfl_node (mangled_id);
5502 if (TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
5503 value = build_wfl_node (TYPE_NAME (TREE_TYPE (field)));
5505 value = TREE_TYPE (field);
5508 case AIPL_FUNCTION_CREATION:
5509 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (purpose,
5511 value = TREE_TYPE (field);
5514 case AIPL_FUNCTION_FINIT_INVOCATION:
5515 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (mangled_id,
5517 /* Now, this is wrong. purpose should always be the NAME
5518 of something and value its matching value (decl, type,
5519 etc...) FIXME -- but there is a lot to fix. */
5521 /* When invoked for this kind of operation, we already
5522 know whether a field is used or not. */
5523 purpose = TREE_TYPE (field);
5524 value = build_wfl_node (mangled_id);
5527 case AIPL_FUNCTION_CTOR_INVOCATION:
5528 /* There are two case: the constructor invocation happens
5529 outside the local inner, in which case, locales from the outer
5530 context are directly used.
5532 Otherwise, we fold to using the alias directly. */
5533 if (class_type == current_class)
5537 name = get_identifier (&buffer[4]);
5538 value = IDENTIFIER_LOCAL_VALUE (name);
5542 additional_parms = tree_cons (purpose, value, additional_parms);
5546 if (additional_parms)
5548 if (ANONYMOUS_CLASS_P (class_type)
5549 && mode == AIPL_FUNCTION_CTOR_INVOCATION)
5550 additional_parms = nreverse (additional_parms);
5551 parm = chainon (additional_parms, parm);
5557 /* Craft a constructor for CLASS_DECL -- what we should do when none
5558 where found. ARGS is non NULL when a special signature must be
5559 enforced. This is the case for anonymous classes. */
5562 craft_constructor (tree class_decl, tree args)
5564 tree class_type = TREE_TYPE (class_decl);
5565 tree parm = NULL_TREE;
5566 /* Inherit access flags for the constructor from its enclosing class. */
5567 int valid_ctor_flags = ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE;
5568 int flags = (get_access_flags_from_decl (class_decl) & valid_ctor_flags);
5569 int i = 0, artificial = 0;
5570 tree decl, ctor_name;
5573 ctor_name = init_identifier_node;
5575 /* If we're dealing with an inner class constructor, we hide the
5576 this$<n> decl in the name field of its parameter declaration. */
5577 if (PURE_INNER_CLASS_TYPE_P (class_type))
5579 tree type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_type)));
5580 parm = tree_cons (build_current_thisn (class_type),
5581 build_pointer_type (type), parm);
5583 /* Some more arguments to be hidden here. The values of the local
5584 variables of the outer context that the inner class needs to see. */
5585 parm = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
5590 /* Then if there are any args to be enforced, enforce them now */
5591 for (; args && args != end_params_node; args = TREE_CHAIN (args))
5593 /* If we see a `void *', we need to change it to Object. */
5594 if (TREE_VALUE (args) == TREE_TYPE (null_pointer_node))
5595 TREE_VALUE (args) = object_ptr_type_node;
5597 sprintf (buffer, "parm%d", i++);
5598 parm = tree_cons (get_identifier (buffer), TREE_VALUE (args), parm);
5601 CRAFTED_PARAM_LIST_FIXUP (parm);
5602 decl = create_artificial_method (class_type, flags, void_type_node,
5604 fix_method_argument_names (parm, decl);
5605 /* Now, mark the artificial parameters. */
5606 DECL_FUNCTION_NAP (decl) = artificial;
5607 DECL_FUNCTION_SYNTHETIC_CTOR (decl) = DECL_CONSTRUCTOR_P (decl) = 1;
5608 DECL_INLINE (decl) = 1;
5613 /* Fix the constructors. This will be called right after circular
5614 references have been checked. It is necessary to fix constructors
5615 early even if no code generation will take place for that class:
5616 some generated constructor might be required by the class whose
5617 compilation triggered this one to be simply loaded. */
5620 java_fix_constructors (void)
5624 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5626 tree class_type = TREE_TYPE (current);
5630 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
5633 output_class = current_class = class_type;
5634 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
5636 if (DECL_CONSTRUCTOR_P (decl))
5638 fix_constructors (decl);
5643 /* Anonymous class constructor can't be generated that early. */
5644 if (!saw_ctor && !ANONYMOUS_CLASS_P (class_type))
5645 craft_constructor (current, NULL_TREE);
5649 /* safe_layout_class just makes sure that we can load a class without
5650 disrupting the current_class, input_file, input_line, etc, information
5651 about the class processed currently. */
5654 safe_layout_class (tree class)
5656 tree save_current_class = current_class;
5657 location_t save_location = input_location;
5659 layout_class (class);
5661 current_class = save_current_class;
5662 input_location = save_location;
5666 jdep_resolve_class (jdep *dep)
5670 if (JDEP_RESOLVED_P (dep))
5671 decl = JDEP_RESOLVED_DECL (dep);
5674 decl = resolve_class (JDEP_ENCLOSING (dep), JDEP_TO_RESOLVE (dep),
5675 JDEP_DECL (dep), JDEP_WFL (dep));
5676 JDEP_RESOLVED (dep, decl);
5677 /* If there is no WFL, that's ok. We generate this warning
5679 if (decl && JDEP_WFL (dep) != NULL_TREE)
5680 check_deprecation (JDEP_WFL (dep), decl);
5684 complete_class_report_errors (dep);
5685 else if (INNER_CLASS_DECL_P (decl))
5687 tree inner = TREE_TYPE (decl);
5688 if (! CLASS_LOADED_P (inner))
5690 safe_layout_class (inner);
5691 if (TYPE_SIZE (inner) == error_mark_node)
5692 TYPE_SIZE (inner) = NULL_TREE;
5694 check_inner_class_access (decl, JDEP_ENCLOSING (dep), JDEP_WFL (dep));
5699 /* Complete unsatisfied class declaration and their dependencies */
5702 java_complete_class (void)
5709 /* Process imports */
5712 /* Reverse things so we have the right order */
5713 ctxp->class_list = nreverse (ctxp->class_list);
5714 ctxp->classd_list = reverse_jdep_list (ctxp);
5716 for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
5718 cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
5722 /* We keep the compilation unit imports in the class so that
5723 they can be used later to resolve type dependencies that
5724 aren't necessary to solve now. */
5725 TYPE_IMPORT_LIST (TREE_TYPE (cclass)) = ctxp->import_list;
5726 TYPE_IMPORT_DEMAND_LIST (TREE_TYPE (cclass)) = ctxp->import_demand_list;
5728 for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
5731 if (!(decl = jdep_resolve_class (dep)))
5734 /* Now it's time to patch */
5735 switch (JDEP_KIND (dep))
5738 /* Simply patch super */
5739 if (parser_check_super (decl, JDEP_DECL (dep), JDEP_WFL (dep)))
5741 BINFO_TYPE (BINFO_BASE_BINFO
5742 (TYPE_BINFO (TREE_TYPE (JDEP_DECL (dep))), 0))
5748 /* We do part of the job done in add_field */
5749 tree field_decl = JDEP_DECL (dep);
5750 tree field_type = TREE_TYPE (decl);
5751 if (TREE_CODE (field_type) == RECORD_TYPE)
5752 field_type = promote_type (field_type);
5753 TREE_TYPE (field_decl) = field_type;
5754 DECL_ALIGN (field_decl) = 0;
5755 DECL_USER_ALIGN (field_decl) = 0;
5756 layout_decl (field_decl, 0);
5757 SOURCE_FRONTEND_DEBUG
5758 (("Completed field/var decl '%s' with '%s'",
5759 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
5760 IDENTIFIER_POINTER (DECL_NAME (decl))));
5763 case JDEP_METHOD: /* We start patching a method */
5764 case JDEP_METHOD_RETURN:
5770 type = TREE_TYPE(decl);
5771 if (TREE_CODE (type) == RECORD_TYPE)
5772 type = promote_type (type);
5773 JDEP_APPLY_PATCH (dep, type);
5774 SOURCE_FRONTEND_DEBUG
5775 (((JDEP_KIND (dep) == JDEP_METHOD_RETURN ?
5776 "Completing fct '%s' with ret type '%s'":
5777 "Completing arg '%s' with type '%s'"),
5778 IDENTIFIER_POINTER (EXPR_WFL_NODE
5779 (JDEP_DECL_WFL (dep))),
5780 IDENTIFIER_POINTER (DECL_NAME (decl))));
5784 dep = JDEP_CHAIN (dep);
5785 if (JDEP_KIND (dep) == JDEP_METHOD_END)
5788 decl = jdep_resolve_class (dep);
5792 tree mdecl = JDEP_DECL (dep), signature;
5793 /* Recompute and reset the signature, check first that
5794 all types are now defined. If they're not,
5795 don't build the signature. */
5796 if (check_method_types_complete (mdecl))
5798 signature = build_java_signature (TREE_TYPE (mdecl));
5799 set_java_signature (TREE_TYPE (mdecl), signature);
5806 case JDEP_INTERFACE:
5807 if (parser_check_super_interface (decl, JDEP_DECL (dep),
5810 parser_add_interface (JDEP_DECL (dep), decl, JDEP_WFL (dep));
5815 type = TREE_TYPE(decl);
5816 if (TREE_CODE (type) == RECORD_TYPE)
5817 type = promote_type (type);
5818 JDEP_APPLY_PATCH (dep, type);
5822 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5823 SOURCE_FRONTEND_DEBUG
5824 (("Completing a random type dependency on a '%s' node",
5825 tree_code_name [TREE_CODE (JDEP_DECL (dep))]));
5828 case JDEP_EXCEPTION:
5829 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5830 SOURCE_FRONTEND_DEBUG
5831 (("Completing '%s' 'throws' argument node",
5832 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
5835 case JDEP_ANONYMOUS:
5836 patch_anonymous_class (decl, JDEP_DECL (dep), JDEP_WFL (dep));
5847 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
5851 resolve_class (tree enclosing, tree class_type, tree decl, tree cl)
5853 tree tname = TYPE_NAME (class_type);
5854 tree resolved_type = TREE_TYPE (class_type);
5856 tree resolved_type_decl;
5858 if (resolved_type != NULL_TREE)
5860 tree resolved_type_decl = TYPE_NAME (resolved_type);
5861 if (resolved_type_decl == NULL_TREE
5862 || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
5864 resolved_type_decl = build_decl (TYPE_DECL,
5865 TYPE_NAME (class_type),
5868 return resolved_type_decl;
5871 /* 1- Check to see if we have an array. If true, find what we really
5873 if ((array_dims = build_type_name_from_array_name (tname,
5874 &TYPE_NAME (class_type))))
5875 WFL_STRIP_BRACKET (cl, cl);
5877 /* 2- Resolve the bare type */
5878 if (!(resolved_type_decl = do_resolve_class (enclosing, class_type,
5881 resolved_type = TREE_TYPE (resolved_type_decl);
5883 /* 3- If we have an array, reconstruct the array down to its nesting */
5886 for (; array_dims; array_dims--)
5887 resolved_type = build_java_array_type (resolved_type, -1);
5888 resolved_type_decl = TYPE_NAME (resolved_type);
5890 TREE_TYPE (class_type) = resolved_type;
5891 return resolved_type_decl;
5894 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
5895 are used to report error messages; CL must either be NULL_TREE or a
5896 WFL wrapping a class. Do not try to replace TYPE_NAME (class_type)
5897 by a variable, since it is changed by find_in_imports{_on_demand}
5898 and (but it doesn't really matter) qualify_and_find. */
5901 do_resolve_class (tree enclosing, tree class_type, tree decl, tree cl)
5903 tree new_class_decl = NULL_TREE, super = NULL_TREE;
5904 tree saved_enclosing_type = enclosing ? TREE_TYPE (enclosing) : NULL_TREE;
5906 htab_t circularity_hash;
5908 if (QUALIFIED_P (TYPE_NAME (class_type)))
5910 /* If the type name is of the form `Q . Id', then Q is either a
5911 package name or a class name. First we try to find Q as a
5912 class and then treat Id as a member type. If we can't find Q
5913 as a class then we fall through. */
5914 tree q, left, left_type, right;
5915 if (split_qualified_name (&left, &right, TYPE_NAME (class_type)) == 0)
5917 BUILD_PTR_FROM_NAME (left_type, left);
5918 q = do_resolve_class (enclosing, left_type, decl, cl);
5922 saved_enclosing_type = TREE_TYPE (q);
5923 BUILD_PTR_FROM_NAME (class_type, right);
5930 /* This hash table is used to register the classes we're going
5931 through when searching the current class as an inner class, in
5932 order to detect circular references. Remember to free it before
5933 returning the section 0- of this function. */
5934 circularity_hash = htab_create (20, htab_hash_pointer, htab_eq_pointer,
5937 /* 0- Search in the current class as an inner class.
5938 Maybe some code here should be added to load the class or
5939 something, at least if the class isn't an inner class and ended
5940 being loaded from class file. FIXME. */
5943 new_class_decl = resolve_inner_class (circularity_hash, cl, &enclosing,
5944 &super, class_type);
5948 /* If we haven't found anything because SUPER reached Object and
5949 ENCLOSING happens to be an innerclass, try the enclosing context. */
5950 if ((!super || super == object_type_node) &&
5951 enclosing && INNER_CLASS_DECL_P (enclosing))
5952 enclosing = DECL_CONTEXT (enclosing);
5954 enclosing = NULL_TREE;
5957 htab_delete (circularity_hash);
5960 return new_class_decl;
5963 /* 1- Check for the type in single imports. This will change
5964 TYPE_NAME() if something relevant is found */
5965 find_in_imports (saved_enclosing_type, class_type);
5967 /* 2- And check for the type in the current compilation unit */
5968 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5970 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)))
5971 load_class (TYPE_NAME (class_type), 0);
5972 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5975 /* 3- Search according to the current package definition */
5976 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5978 if ((new_class_decl = qualify_and_find (class_type, ctxp->package,
5979 TYPE_NAME (class_type))))
5980 return new_class_decl;
5983 /* 4- Check the import on demands. Don't allow bar.baz to be
5984 imported from foo.* */
5985 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5986 if (find_in_imports_on_demand (saved_enclosing_type, class_type))
5989 /* If found in find_in_imports_on_demand, the type has already been
5991 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5992 return new_class_decl;
5994 /* 5- Try with a name qualified with the package name we've seen so far */
5995 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5999 /* If there is a current package (ctxp->package), it's the first
6000 element of package_list and we can skip it. */
6001 for (package = (ctxp->package ?
6002 TREE_CHAIN (package_list) : package_list);
6003 package; package = TREE_CHAIN (package))
6004 if ((new_class_decl = qualify_and_find (class_type,
6005 TREE_PURPOSE (package),
6006 TYPE_NAME (class_type))))
6007 return new_class_decl;
6010 /* 5- Check another compilation unit that bears the name of type */
6011 load_class (TYPE_NAME (class_type), 0);
6014 cl = lookup_cl (decl);
6016 /* If we don't have a value for CL, then we're being called recursively.
6017 We can't check package access just yet, but it will be taken care of
6021 if (check_pkg_class_access (TYPE_NAME (class_type), cl, true, NULL_TREE))
6025 /* 6- Last call for a resolution */
6026 decl_result = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
6028 /* The final lookup might have registered a.b.c into a.b$c If we
6029 failed at the first lookup, progressively change the name if
6030 applicable and use the matching DECL instead. */
6031 if (!decl_result && QUALIFIED_P (TYPE_NAME (class_type)))
6034 tree name = TYPE_NAME (class_type);
6035 char *namebuffer = alloca (IDENTIFIER_LENGTH (name) + 1);
6037 strcpy (namebuffer, IDENTIFIER_POINTER (name));
6041 /* Reach the last '.', and if applicable, replace it by a `$' and
6042 see if this exists as a type. */
6043 if ((separator = strrchr (namebuffer, '.')))
6046 name = get_identifier (namebuffer);
6047 decl_result = IDENTIFIER_CLASS_VALUE (name);
6049 } while (!decl_result && separator);
6055 qualify_and_find (tree class_type, tree package, tree name)
6057 tree new_qualified = merge_qualified_name (package, name);
6058 tree new_class_decl;
6060 if (!IDENTIFIER_CLASS_VALUE (new_qualified))
6061 load_class (new_qualified, 0);
6062 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (new_qualified)))
6064 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)))
6065 load_class (TREE_TYPE (new_class_decl), 0);
6066 TYPE_NAME (class_type) = new_qualified;
6067 return IDENTIFIER_CLASS_VALUE (new_qualified);
6072 /* Resolve NAME and lay it out (if not done and if not the current
6073 parsed class). Return a decl node. This function is meant to be
6074 called when type resolution is necessary during the walk pass. */
6077 resolve_and_layout (tree something, tree cl)
6079 tree decl, decl_type;
6081 /* Don't do that on the current class */
6082 if (something == current_class)
6083 return TYPE_NAME (current_class);
6085 /* Don't do anything for void and other primitive types */
6086 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
6089 /* Pointer types can be reall pointer types or fake pointers. When
6090 finding a real pointer, recheck for primitive types */
6091 if (TREE_CODE (something) == POINTER_TYPE)
6093 if (TREE_TYPE (something))
6095 something = TREE_TYPE (something);
6096 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
6100 something = TYPE_NAME (something);
6103 /* Don't do anything for arrays of primitive types */
6104 if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
6105 && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
6108 /* Something might be a WFL */
6109 if (TREE_CODE (something) == EXPR_WITH_FILE_LOCATION)
6110 something = EXPR_WFL_NODE (something);
6112 /* Otherwise, if something is not and IDENTIFIER_NODE, it can be a a
6113 TYPE_DECL or a real TYPE */
6114 else if (TREE_CODE (something) != IDENTIFIER_NODE)
6115 something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
6116 DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
6118 if (!(decl = resolve_no_layout (something, cl)))
6121 /* Resolve and layout if necessary */
6122 decl_type = TREE_TYPE (decl);
6123 layout_class_methods (decl_type);
6125 if (CLASS_FROM_SOURCE_P (decl_type))
6126 java_check_methods (decl);
6127 /* Layout the type if necessary */
6128 if (decl_type != current_class && !CLASS_LOADED_P (decl_type))
6129 safe_layout_class (decl_type);
6134 /* Resolve a class, returns its decl but doesn't perform any
6135 layout. The current parsing context is saved and restored */
6138 resolve_no_layout (tree name, tree cl)
6141 BUILD_PTR_FROM_NAME (ptr, name);
6142 java_parser_context_save_global ();
6143 decl = resolve_class (TYPE_NAME (current_class), ptr, NULL_TREE, cl);
6144 java_parser_context_restore_global ();
6149 /* Called when reporting errors. Skip the '[]'s in a complex array
6150 type description that failed to be resolved. purify_type_name can't
6151 use an identifier tree. */
6154 purify_type_name (const char *name)
6156 int len = strlen (name);
6159 STRING_STRIP_BRACKETS (name, len, bracket_found);
6162 char *stripped_name = xmemdup (name, len, len+1);
6163 stripped_name [len] = '\0';
6164 return stripped_name;
6169 /* The type CURRENT refers to can't be found. We print error messages. */
6172 complete_class_report_errors (jdep *dep)
6176 if (!JDEP_WFL (dep))
6179 name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
6180 switch (JDEP_KIND (dep))
6184 (JDEP_WFL (dep), "Superclass %qs of class %qs not found",
6185 purify_type_name (name),
6186 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6190 (JDEP_WFL (dep), "Type %qs not found in declaration of field %qs",
6191 purify_type_name (name),
6192 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6194 case JDEP_METHOD: /* Covers arguments */
6196 (JDEP_WFL (dep), "Type %qs not found in the declaration of the argument %qs of method %qs",
6197 purify_type_name (name),
6198 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
6199 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
6201 case JDEP_METHOD_RETURN: /* Covers return type */
6203 (JDEP_WFL (dep), "Type %qs not found in the declaration of the return type of method %qs",
6204 purify_type_name (name),
6205 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
6207 case JDEP_INTERFACE:
6209 (JDEP_WFL (dep), "Superinterface %qs of %s %qs not found",
6210 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
6211 (CLASS_OR_INTERFACE (JDEP_DECL (dep), "class", "interface")),
6212 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6216 (JDEP_WFL (dep), "Type %qs not found in the declaration of the local variable %qs",
6217 purify_type_name (IDENTIFIER_POINTER
6218 (EXPR_WFL_NODE (JDEP_WFL (dep)))),
6219 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
6221 case JDEP_EXCEPTION: /* As specified by `throws' */
6223 (JDEP_WFL (dep), "Class %qs not found in %<throws%>",
6224 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
6227 /* Fix for -Wall. Just break doing nothing. The error will be
6233 /* Return a static string containing the DECL prototype string. If
6234 DECL is a constructor, use the class name instead of the form
6238 get_printable_method_name (tree decl)
6240 const char *to_return;
6241 tree name = NULL_TREE;
6243 if (DECL_CONSTRUCTOR_P (decl))
6245 name = DECL_NAME (decl);
6246 DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
6249 to_return = lang_printable_name (decl, 2);
6250 if (DECL_CONSTRUCTOR_P (decl))
6251 DECL_NAME (decl) = name;
6256 /* Track method being redefined inside the same class. As a side
6257 effect, set DECL_NAME to an IDENTIFIER (prior entering this
6258 function it's a FWL, so we can track errors more accurately.) */
6261 check_method_redefinition (tree class, tree method)
6265 /* There's no need to verify <clinit> and finit$ and instinit$ */
6266 if (DECL_CLINIT_P (method)
6267 || DECL_FINIT_P (method) || DECL_INSTINIT_P (method))
6270 sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
6271 for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
6273 if (redef == method)
6275 if (DECL_NAME (redef) == DECL_NAME (method)
6276 && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef))
6277 && !DECL_ARTIFICIAL (method))
6280 (DECL_FUNCTION_WFL (method), "Duplicate %s declaration %qs",
6281 (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
6282 get_printable_method_name (redef));
6289 /* Return 1 if check went ok, 0 otherwise. */
6291 check_abstract_method_definitions (int do_interface, tree class_decl,
6294 tree class = TREE_TYPE (class_decl);
6295 tree method, end_type;
6298 end_type = (do_interface ? object_type_node : type);
6299 for (method = TYPE_METHODS (type); method; method = TREE_CHAIN (method))
6301 tree other_super, other_method, method_sig, method_name;
6303 int end_type_reached = 0;
6305 if (!METHOD_ABSTRACT (method) || METHOD_FINAL (method))
6308 /* Now verify that somewhere in between TYPE and CLASS,
6309 abstract method METHOD gets a non abstract definition
6310 that is inherited by CLASS. */
6312 method_sig = build_java_signature (TREE_TYPE (method));
6313 method_name = DECL_NAME (method);
6314 if (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION)
6315 method_name = EXPR_WFL_NODE (method_name);
6317 other_super = class;
6319 if (other_super == end_type)
6320 end_type_reached = 1;
6323 for (other_method = TYPE_METHODS (other_super); other_method;
6324 other_method = TREE_CHAIN (other_method))
6326 tree s = build_java_signature (TREE_TYPE (other_method));
6327 tree other_name = DECL_NAME (other_method);
6329 if (TREE_CODE (other_name) == EXPR_WITH_FILE_LOCATION)
6330 other_name = EXPR_WFL_NODE (other_name);
6331 if (!DECL_CLINIT_P (other_method)
6332 && !DECL_CONSTRUCTOR_P (other_method)
6333 && method_name == other_name
6335 && !METHOD_ABSTRACT (other_method))
6341 other_super = CLASSTYPE_SUPER (other_super);
6342 } while (!end_type_reached);
6344 /* Report that abstract METHOD didn't find an implementation
6345 that CLASS can use. */
6348 char *t = xstrdup (lang_printable_name
6349 (TREE_TYPE (TREE_TYPE (method)), 0));
6350 tree ccn = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
6353 (lookup_cl (class_decl),
6354 "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",
6355 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
6356 t, lang_printable_name (method, 2),
6357 (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))) ?
6358 "interface" : "class"),
6359 IDENTIFIER_POINTER (ccn),
6360 (CLASS_INTERFACE (class_decl) ? "interface" : "class"),
6361 IDENTIFIER_POINTER (DECL_NAME (class_decl)));
6367 if (ok && do_interface)
6369 /* Check for implemented interfaces. */
6374 ok && BINFO_BASE_ITERATE (TYPE_BINFO (type), i, base_binfo);
6376 ok = check_abstract_method_definitions (1, class_decl,
6377 BINFO_TYPE (base_binfo));
6383 /* Check that CLASS_DECL somehow implements all inherited abstract
6387 java_check_abstract_method_definitions (tree class_decl)
6389 tree class = TREE_TYPE (class_decl);
6390 tree super, base_binfo;
6393 if (CLASS_ABSTRACT (class_decl))
6396 /* Check for inherited types */
6399 super = CLASSTYPE_SUPER (super);
6400 check_abstract_method_definitions (0, class_decl, super);
6401 } while (super != object_type_node);
6403 /* Check for implemented interfaces. */
6404 for (i = 1; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6405 check_abstract_method_definitions (1, class_decl, BINFO_TYPE (base_binfo));
6408 /* Check all the types method DECL uses and return 1 if all of them
6409 are now complete, 0 otherwise. This is used to check whether its
6410 safe to build a method signature or not. */
6413 check_method_types_complete (tree decl)
6415 tree type = TREE_TYPE (decl);
6418 if (!INCOMPLETE_TYPE_P (TREE_TYPE (type)))
6421 args = TYPE_ARG_TYPES (type);
6422 if (TREE_CODE (type) == METHOD_TYPE)
6423 args = TREE_CHAIN (args);
6424 for (; args != end_params_node; args = TREE_CHAIN (args))
6425 if (INCOMPLETE_TYPE_P (TREE_VALUE (args)))
6431 /* Visible interface to check methods contained in CLASS_DECL */
6434 java_check_methods (tree class_decl)
6436 if (CLASS_METHOD_CHECKED_P (TREE_TYPE (class_decl)))
6439 if (CLASS_INTERFACE (class_decl))
6440 java_check_abstract_methods (class_decl);
6442 java_check_regular_methods (class_decl);
6444 CLASS_METHOD_CHECKED_P (TREE_TYPE (class_decl)) = 1;
6447 /* Like not_accessible_p, but doesn't refer to the current class at
6450 hack_is_accessible_p (tree member, tree from_where)
6452 int flags = get_access_flags_from_decl (member);
6454 if (from_where == DECL_CONTEXT (member)
6455 || (flags & ACC_PUBLIC))
6458 if ((flags & ACC_PROTECTED))
6460 if (inherits_from_p (from_where, DECL_CONTEXT (member)))
6464 if ((flags & ACC_PRIVATE))
6467 /* Package private, or protected. */
6468 return in_same_package (TYPE_NAME (from_where),
6469 TYPE_NAME (DECL_CONTEXT (member)));
6472 /* Check all the methods of CLASS_DECL. Methods are first completed
6473 then checked according to regular method existence rules. If no
6474 constructor for CLASS_DECL were encountered, then build its
6477 java_check_regular_methods (tree class_decl)
6479 int saw_constructor = ANONYMOUS_CLASS_P (TREE_TYPE (class_decl));
6481 tree class = TREE_TYPE (class_decl);
6482 tree found = NULL_TREE;
6485 /* It is not necessary to check methods defined in java.lang.Object */
6486 if (class == object_type_node)
6489 if (!TYPE_NVIRTUALS (class))
6490 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6492 /* Should take interfaces into account. FIXME */
6493 for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
6496 tree method_wfl = DECL_FUNCTION_WFL (method);
6499 /* Check for redefinitions */
6500 if (check_method_redefinition (class, method))
6503 /* We verify things thrown by the method. They must inherit from
6504 java.lang.Throwable. */
6505 for (mthrows = DECL_FUNCTION_THROWS (method);
6506 mthrows; mthrows = TREE_CHAIN (mthrows))
6508 if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
6510 (TREE_PURPOSE (mthrows), "Class %qs in %<throws%> clause must be a subclass of class %<java.lang.Throwable%>",
6512 (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
6515 /* If we see one constructor a mark so we don't generate the
6516 default one. Also skip other verifications: constructors
6517 can't be inherited hence hidden or overridden. */
6518 if (DECL_CONSTRUCTOR_P (method))
6520 saw_constructor = 1;
6524 sig = build_java_argument_signature (TREE_TYPE (method));
6525 found = lookup_argument_method_generic (class, DECL_NAME (method), sig,
6526 SEARCH_SUPER | SEARCH_INTERFACE);
6528 /* Inner class can't declare static methods */
6529 if (METHOD_STATIC (method) && !TOPLEVEL_CLASS_DECL_P (class_decl))
6531 char *t = xstrdup (lang_printable_name (class, 0));
6533 (method_wfl, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
6534 lang_printable_name (method, 2), t);
6538 /* Nothing overrides or it's a private method. */
6541 if (METHOD_PRIVATE (found))
6547 /* If `found' is declared in an interface, make sure the
6548 modifier matches. */
6549 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
6550 && clinit_identifier_node != DECL_NAME (found)
6551 && !METHOD_PUBLIC (method))
6553 tree found_decl = TYPE_NAME (DECL_CONTEXT (found));
6554 parse_error_context (method_wfl, "Class %qs must override %qs with a public method in order to implement interface %qs",
6555 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
6556 lang_printable_name (method, 2),
6557 IDENTIFIER_POINTER (DECL_NAME (found_decl)));
6560 /* Can't override a method with the same name and different return
6562 if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
6565 (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 2));
6568 "Method %qs was defined with return type %qs in class %qs",
6569 lang_printable_name (found, 2), t,
6571 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6575 aflags = get_access_flags_from_decl (found);
6577 /* Can't override final. Can't override static. */
6578 if (METHOD_FINAL (found) || METHOD_STATIC (found))
6580 /* Static *can* override static */
6581 if (METHOD_STATIC (found) && METHOD_STATIC (method))
6585 "%s methods can't be overridden. Method %qs is %s in class %qs",
6586 (METHOD_FINAL (found) ? "Final" : "Static"),
6587 lang_printable_name (found, 2),
6588 (METHOD_FINAL (found) ? "final" : "static"),
6590 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6594 /* Static method can't override instance method. */
6595 if (METHOD_STATIC (method))
6599 "Instance methods can't be overridden by a static method. Method %qs is an instance method in class %qs",
6600 lang_printable_name (found, 2),
6602 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6606 /* - Overriding/hiding public must be public
6607 - Overriding/hiding protected must be protected or public
6608 - If the overridden or hidden method has default (package)
6609 access, then the overriding or hiding method must not be
6610 private; otherwise, a compile-time error occurs. If
6611 `found' belongs to an interface, things have been already
6613 if (!CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
6614 && ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method))
6615 || (METHOD_PROTECTED (found)
6616 && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
6617 || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
6618 && METHOD_PRIVATE (method))))
6622 "Methods can't be overridden to be more private. Method %qs is not %s in class %qs", lang_printable_name (method, 2),
6623 (METHOD_PUBLIC (method) ? "public" :
6624 (METHOD_PRIVATE (method) ? "private" : "protected")),
6625 IDENTIFIER_POINTER (DECL_NAME
6626 (TYPE_NAME (DECL_CONTEXT (found)))));
6630 /* Check this method against all the other implementations it
6631 overrides. Here we only check the class hierarchy; the rest
6632 of the checking is done later. If this method is just a
6633 Miranda method, we can skip the check. */
6634 if (! METHOD_INVISIBLE (method))
6635 check_concrete_throws_clauses (class, method, DECL_NAME (method), sig);
6638 /* The above throws clause check only looked at superclasses. Now
6639 we must also make sure that all methods declared in interfaces
6640 have compatible throws clauses. FIXME: there are more efficient
6641 ways to organize this checking; we should implement one. */
6642 check_interface_throws_clauses (class, class);
6644 if (!TYPE_NVIRTUALS (class))
6645 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6647 /* Search for inherited abstract method not yet implemented in this
6649 java_check_abstract_method_definitions (class_decl);
6651 if (!saw_constructor)
6655 /* Check to make sure that all the methods in all the interfaces
6656 implemented by CLASS_DECL are compatible with the concrete
6657 implementations available in CHECK_CLASS_DECL. */
6659 check_interface_throws_clauses (tree check_class_decl, tree class_decl)
6661 for (; class_decl != NULL_TREE; class_decl = CLASSTYPE_SUPER (class_decl))
6665 if (! CLASS_LOADED_P (class_decl))
6667 if (CLASS_FROM_SOURCE_P (class_decl))
6668 safe_layout_class (class_decl);
6670 load_class (class_decl, 1);
6673 for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (class_decl)) - 1; i > 0; --i)
6676 = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (class_decl), i));
6679 for (iface_method = TYPE_METHODS (interface);
6680 iface_method != NULL_TREE;
6681 iface_method = TREE_CHAIN (iface_method))
6685 /* First look for a concrete method implemented or
6686 inherited by this class. No need to search
6687 interfaces here, since we're already looking through
6689 sig = build_java_argument_signature (TREE_TYPE (iface_method));
6691 = lookup_argument_method_generic (check_class_decl,
6692 DECL_NAME (iface_method),
6693 sig, SEARCH_VISIBLE);
6694 /* If we don't find an implementation, that is ok. Any
6695 potential errors from that are diagnosed elsewhere.
6696 Also, multiple inheritance with conflicting throws
6697 clauses is fine in the absence of a concrete
6699 if (method != NULL_TREE && !METHOD_ABSTRACT (method)
6700 && !METHOD_INVISIBLE (iface_method))
6702 tree method_wfl = DECL_FUNCTION_WFL (method);
6703 check_throws_clauses (method, method_wfl, iface_method);
6707 /* Now check superinterfaces. */
6708 check_interface_throws_clauses (check_class_decl, interface);
6713 /* Check throws clauses of a method against the clauses of all the
6714 methods it overrides. We do this by searching up the class
6715 hierarchy, examining all matching accessible methods. */
6717 check_concrete_throws_clauses (tree class, tree self_method,
6718 tree name, tree signature)
6720 tree method = lookup_argument_method_generic (class, name, signature,
6721 SEARCH_SUPER | SEARCH_VISIBLE);
6722 while (method != NULL_TREE)
6724 if (! METHOD_INVISIBLE (method) && hack_is_accessible_p (method, class))
6725 check_throws_clauses (self_method, DECL_FUNCTION_WFL (self_method),
6728 method = lookup_argument_method_generic (DECL_CONTEXT (method),
6730 SEARCH_SUPER | SEARCH_VISIBLE);
6734 /* Generate an error if the `throws' clause of METHOD (if any) is
6735 incompatible with the `throws' clause of FOUND (if any). */
6737 check_throws_clauses (tree method, tree method_wfl, tree found)
6741 /* Can't check these things with class loaded from bytecode. FIXME */
6742 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (found)))
6745 for (mthrows = DECL_FUNCTION_THROWS (method);
6746 mthrows; mthrows = TREE_CHAIN (mthrows))
6750 /* We don't verify unchecked expressions */
6751 if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
6753 /* Checked expression must be compatible */
6754 for (fthrows = DECL_FUNCTION_THROWS (found);
6755 fthrows; fthrows = TREE_CHAIN (fthrows))
6757 if (inherits_from_p (TREE_VALUE (mthrows), TREE_VALUE (fthrows)))
6763 (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",
6764 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))),
6765 lang_printable_name (found, 2),
6767 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6772 /* Check abstract method of interface INTERFACE */
6774 java_check_abstract_methods (tree interface_decl)
6778 tree interface = TREE_TYPE (interface_decl);
6781 for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
6783 /* 2- Check for double definition inside the defining interface */
6784 if (check_method_redefinition (interface, method))
6787 /* 3- Overriding is OK as far as we preserve the return type. */
6788 found = lookup_java_interface_method2 (interface, method);
6792 t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 2));
6794 (DECL_FUNCTION_WFL (found),
6795 "Method %qs was defined with return type %qs in class %qs",
6796 lang_printable_name (found, 2), t,
6798 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6804 /* 4- Inherited methods can't differ by their returned types */
6805 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (interface), i, base_binfo); i++)
6807 tree sub_interface_method, sub_interface;
6809 sub_interface = BINFO_TYPE (base_binfo);
6810 for (sub_interface_method = TYPE_METHODS (sub_interface);
6811 sub_interface_method;
6812 sub_interface_method = TREE_CHAIN (sub_interface_method))
6814 found = lookup_java_interface_method2 (interface,
6815 sub_interface_method);
6816 if (found && (found != sub_interface_method))
6819 (lookup_cl (sub_interface_method),
6820 "Interface %qs inherits method %qs from interface %qs. This method is redefined with a different return type in interface %qs",
6821 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
6822 lang_printable_name (found, 2),
6824 (DECL_NAME (TYPE_NAME
6825 (DECL_CONTEXT (sub_interface_method)))),
6827 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6833 /* Lookup methods in interfaces using their name and partial
6834 signature. Return a matching method only if their types differ. */
6837 lookup_java_interface_method2 (tree class, tree method_decl)
6843 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6845 if ((BINFO_TYPE (base_binfo) != object_type_node)
6847 lookup_java_method2 (BINFO_TYPE (base_binfo), method_decl, 1)))
6850 for (i = 0; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
6852 to_return = lookup_java_interface_method2
6853 (BINFO_TYPE (base_binfo), method_decl);
6861 /* Lookup method using their name and partial signature. Return a
6862 matching method only if their types differ. */
6865 lookup_java_method2 (tree clas, tree method_decl, int do_interface)
6867 tree method, method_signature, method_name, method_type, name;
6869 method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
6870 name = DECL_NAME (method_decl);
6871 method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6872 EXPR_WFL_NODE (name) : name);
6873 method_type = TREE_TYPE (TREE_TYPE (method_decl));
6875 while (clas != NULL_TREE)
6877 for (method = TYPE_METHODS (clas);
6878 method != NULL_TREE; method = TREE_CHAIN (method))
6880 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
6881 tree name = DECL_NAME (method);
6882 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6883 EXPR_WFL_NODE (name) : name) == method_name
6884 && method_sig == method_signature
6885 && TREE_TYPE (TREE_TYPE (method)) != method_type)
6888 clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
6893 /* Return the line that matches DECL line number, and try its best to
6894 position the column number. Used during error reports.
6895 FUTURE/FIXME: return source_location instead of node. */
6897 static GTY(()) tree cl_v;
6899 lookup_cl (tree decl)
6901 #ifndef USE_MAPPED_LOCATION
6908 if (cl_v == NULL_TREE)
6910 cl_v = build_unknown_wfl (NULL_TREE);
6913 #ifdef USE_MAPPED_LOCATION
6914 SET_EXPR_LOCATION (cl_v, DECL_SOURCE_LOCATION (decl));
6916 EXPR_WFL_FILENAME_NODE (cl_v) = get_identifier (DECL_SOURCE_FILE (decl));
6917 EXPR_WFL_SET_LINECOL (cl_v, DECL_SOURCE_LINE (decl), -1);
6919 line = java_get_line_col (EXPR_WFL_FILENAME (cl_v),
6920 EXPR_WFL_LINENO (cl_v), EXPR_WFL_COLNO (cl_v));
6922 found = strstr ((const char *)line,
6923 (const char *)IDENTIFIER_POINTER (DECL_NAME (decl)));
6925 EXPR_WFL_SET_LINECOL (cl_v, EXPR_WFL_LINENO (cl_v), found - line);
6931 /* Look for a simple name in the single-type import list */
6934 find_name_in_single_imports (tree name)
6938 for (node = ctxp->import_list; node; node = TREE_CHAIN (node))
6939 if (TREE_VALUE (node) == name)
6940 return (EXPR_WFL_NODE (TREE_PURPOSE (node)));
6945 /* Process all single-type import. */
6948 process_imports (void)
6953 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
6955 tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import));
6956 char *original_name;
6958 /* Don't load twice something already defined. */
6959 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6962 original_name = xmemdup (IDENTIFIER_POINTER (to_be_found),
6963 IDENTIFIER_LENGTH (to_be_found),
6964 IDENTIFIER_LENGTH (to_be_found) + 1);
6970 QUALIFIED_P (to_be_found) = 1;
6971 load_class (to_be_found, 0);
6973 check_pkg_class_access (to_be_found, TREE_PURPOSE (import), true, NULL_TREE);
6975 /* We found it, we can bail out */
6976 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6978 check_deprecation (TREE_PURPOSE (import),
6979 IDENTIFIER_CLASS_VALUE (to_be_found));
6983 /* We haven't found it. Maybe we're trying to access an
6984 inner class. The only way for us to know is to try again
6985 after having dropped a qualifier. If we can't break it further,
6986 we have an error. */
6987 if (split_qualified_name (&left, NULL, to_be_found))
6992 if (!IDENTIFIER_CLASS_VALUE (to_be_found))
6994 parse_error_context (TREE_PURPOSE (import),
6995 "Class or interface %qs not found in import",
7000 free (original_name);
7007 /* Possibly find and mark a class imported by a single-type import
7011 find_in_imports (tree enclosing_type, tree class_type)
7013 tree import = (enclosing_type ? TYPE_IMPORT_LIST (enclosing_type) :
7017 if (TREE_VALUE (import) == TYPE_NAME (class_type))
7019 TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
7020 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
7023 import = TREE_CHAIN (import);
7028 note_possible_classname (const char *name, int len)
7031 if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
7033 else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
7037 node = ident_subst (name, len, "", '/', '.', "");
7038 IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
7039 QUALIFIED_P (node) = strchr (name, '/') ? 1 : 0;
7043 /* Read a import directory, gathering potential match for further type
7044 references. Indifferently reads a filesystem or a ZIP archive
7048 read_import_dir (tree wfl)
7050 tree package_id = EXPR_WFL_NODE (wfl);
7051 const char *package_name = IDENTIFIER_POINTER (package_id);
7052 int package_length = IDENTIFIER_LENGTH (package_id);
7054 JCF *saved_jcf = current_jcf;
7059 struct buffer filename[1];
7061 if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
7063 IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
7065 BUFFER_INIT (filename);
7066 buffer_grow (filename, package_length + 100);
7068 for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
7070 const char *entry_name = jcf_path_name (entry);
7071 int entry_length = strlen (entry_name);
7072 if (jcf_path_is_zipfile (entry))
7075 buffer_grow (filename, entry_length);
7076 memcpy (filename->data, entry_name, entry_length - 1);
7077 filename->data[entry_length-1] = '\0';
7078 zipf = opendir_in_zip ((const char *) filename->data, jcf_path_is_system (entry));
7080 error ("malformed .zip archive in CLASSPATH: %s", entry_name);
7083 ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
7084 BUFFER_RESET (filename);
7085 for (k = 0; k < package_length; k++)
7087 char ch = package_name[k];
7088 *filename->ptr++ = ch == '.' ? '/' : ch;
7090 *filename->ptr++ = '/';
7092 for (k = 0; k < zipf->count; k++, zipd = ZIPDIR_NEXT (zipd))
7094 const char *current_entry = ZIPDIR_FILENAME (zipd);
7095 int current_entry_len = zipd->filename_length;
7097 if (current_entry_len >= BUFFER_LENGTH (filename)
7098 && strncmp ((const char *) filename->data, current_entry,
7099 BUFFER_LENGTH (filename)) != 0)
7101 found |= note_possible_classname (current_entry,
7108 BUFFER_RESET (filename);
7109 buffer_grow (filename, entry_length + package_length + 4);
7110 strcpy ((char *) filename->data, entry_name);
7111 filename->ptr = filename->data + entry_length;
7112 for (k = 0; k < package_length; k++)
7114 char ch = package_name[k];
7115 *filename->ptr++ = ch == '.' ? '/' : ch;
7117 *filename->ptr = '\0';
7119 dirp = opendir ((const char *) filename->data);
7122 *filename->ptr++ = '/';
7127 struct dirent *direntp = readdir (dirp);
7130 d_name = direntp->d_name;
7131 len = strlen (direntp->d_name);
7132 buffer_grow (filename, len+1);
7133 strcpy ((char *) filename->ptr, d_name);
7134 found |= note_possible_classname ((const char *) filename->data + entry_length,
7135 package_length+len+1);
7142 free (filename->data);
7144 /* Here we should have a unified way of retrieving an entry, to be
7148 static int first = 1;
7151 error ("Can't find default package %qs. Check the CLASSPATH environment variable and the access to the archives", package_name);
7156 parse_error_context (wfl, "Package %qs not found in import",
7158 current_jcf = saved_jcf;
7161 current_jcf = saved_jcf;
7164 /* Possibly find a type in the import on demands specified
7165 types. Returns 1 if an error occurred, 0 otherwise. Run through the
7166 entire list, to detected potential double definitions. */
7169 find_in_imports_on_demand (tree enclosing_type, tree class_type)
7171 tree class_type_name = TYPE_NAME (class_type);
7172 tree import = (enclosing_type ? TYPE_IMPORT_DEMAND_LIST (enclosing_type) :
7173 ctxp->import_demand_list);
7174 tree cl = NULL_TREE;
7175 int seen_once = -1; /* -1 when not set, 1 if seen once, >1 otherwise. */
7176 int to_return = -1; /* -1 when not set, 0 or 1 otherwise */
7179 for (; import; import = TREE_CHAIN (import))
7181 location_t saved_location = input_location;
7183 const char *id_name;
7184 tree decl, type_name_copy;
7186 obstack_grow (&temporary_obstack,
7187 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
7188 IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
7189 obstack_1grow (&temporary_obstack, '.');
7190 obstack_grow0 (&temporary_obstack,
7191 IDENTIFIER_POINTER (class_type_name),
7192 IDENTIFIER_LENGTH (class_type_name));
7193 id_name = obstack_finish (&temporary_obstack);
7195 if (! (node = maybe_get_identifier (id_name)))
7198 /* Setup input_line so that it refers to the line of the import (in
7199 case we parse a class file and encounter errors */
7200 #ifdef USE_MAPPED_LOCATION
7201 input_location = EXPR_LOCATION (TREE_PURPOSE (import));
7203 input_line = EXPR_WFL_LINENO (TREE_PURPOSE (import));
7206 type_name_copy = TYPE_NAME (class_type);
7207 TYPE_NAME (class_type) = node;
7208 QUALIFIED_P (node) = 1;
7209 decl = IDENTIFIER_CLASS_VALUE (node);
7211 /* If there is no DECL set for the class or if the class isn't
7212 loaded and not seen in source yet, then load */
7213 if (!decl || ! CLASS_LOADED_P (TREE_TYPE (decl)))
7215 load_class (node, 0);
7216 decl = IDENTIFIER_CLASS_VALUE (node);
7218 if (decl && ! INNER_CLASS_P (TREE_TYPE (decl)))
7219 access_check = check_pkg_class_access (node, TREE_PURPOSE (import),
7222 /* 6.6.1: Inner classes are subject to member access rules. */
7225 input_location = saved_location;
7227 /* If the loaded class is not accessible or couldn't be loaded,
7228 we restore the original TYPE_NAME and process the next
7230 if (access_check || !decl)
7232 TYPE_NAME (class_type) = type_name_copy;
7236 /* If the loaded class is accessible, we keep a tab on it to
7237 detect and report multiple inclusions. */
7238 if (IS_A_CLASSFILE_NAME (node))
7242 cl = TREE_PURPOSE (import);
7245 else if (seen_once >= 0)
7247 tree location = (cl ? cl : TREE_PURPOSE (import));
7248 tree package = (cl ? EXPR_WFL_NODE (cl) :
7249 EXPR_WFL_NODE (TREE_PURPOSE (import)));
7253 "Type %qs also potentially defined in package %qs",
7254 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
7255 IDENTIFIER_POINTER (package));
7258 to_return = access_check;
7264 return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
7267 /* Add package NAME to the list of packages encountered so far. To
7268 speed up class lookup in do_resolve_class, we make sure a
7269 particular package is added only once. */
7272 register_package (tree name)
7278 pht = htab_create (50, htab_hash_pointer, htab_eq_pointer, NULL);
7280 e = htab_find_slot (pht, name, INSERT);
7283 package_list = chainon (package_list, build_tree_list (name, NULL));
7289 resolve_package (tree pkg, tree *next, tree *type_name)
7292 tree decl = NULL_TREE;
7293 *type_name = NULL_TREE;
7295 /* The trick is to determine when the package name stops and were
7296 the name of something contained in the package starts. Then we
7297 return a fully qualified name of what we want to get. */
7299 *next = EXPR_WFL_QUALIFICATION (pkg);
7301 /* Try to progressively construct a type name */
7302 if (TREE_CODE (pkg) == EXPR_WITH_FILE_LOCATION)
7303 for (current = EXPR_WFL_QUALIFICATION (pkg);
7304 current; current = TREE_CHAIN (current))
7306 /* If we don't have what we're expecting, exit now. TYPE_NAME
7307 will be null and the error caught later. */
7308 if (TREE_CODE (QUAL_WFL (current)) != EXPR_WITH_FILE_LOCATION)
7311 merge_qualified_name (*type_name, EXPR_WFL_NODE (QUAL_WFL (current)));
7312 if ((decl = resolve_no_layout (*type_name, NULL_TREE)))
7314 /* resolve_package should be used in a loop, hence we
7315 point at this one to naturally process the next one at
7316 the next iteration. */
7325 /* Check accessibility of inner classes according to member access rules.
7326 DECL is the inner class, ENCLOSING_DECL is the class from which the
7327 access is being attempted. */
7330 check_inner_class_access (tree decl, tree enclosing_decl, tree cl)
7333 tree enclosing_decl_type;
7335 /* We don't issue an error message when CL is null. CL can be null
7336 as a result of processing a JDEP crafted by source_start_java_method
7337 for the purpose of patching its parm decl. But the error would
7338 have been already trapped when fixing the method's signature.
7339 DECL can also be NULL in case of earlier errors. */
7343 enclosing_decl_type = TREE_TYPE (enclosing_decl);
7345 if (CLASS_PRIVATE (decl))
7347 /* Access is permitted only within the body of the top-level
7348 class in which DECL is declared. */
7349 tree top_level = decl;
7350 while (DECL_CONTEXT (top_level))
7351 top_level = DECL_CONTEXT (top_level);
7352 while (DECL_CONTEXT (enclosing_decl))
7353 enclosing_decl = DECL_CONTEXT (enclosing_decl);
7354 if (top_level == enclosing_decl)
7358 else if (CLASS_PROTECTED (decl))
7361 /* Access is permitted from within the same package... */
7362 if (in_same_package (decl, enclosing_decl))
7365 /* ... or from within the body of a subtype of the context in which
7366 DECL is declared. */
7367 decl_context = DECL_CONTEXT (decl);
7368 while (enclosing_decl)
7370 if (CLASS_INTERFACE (decl))
7372 if (interface_of_p (TREE_TYPE (decl_context),
7373 enclosing_decl_type))
7378 /* Eww. The order of the arguments is different!! */
7379 if (inherits_from_p (enclosing_decl_type,
7380 TREE_TYPE (decl_context)))
7383 enclosing_decl = DECL_CONTEXT (enclosing_decl);
7385 access = "protected";
7387 else if (! CLASS_PUBLIC (decl))
7389 /* Access is permitted only from within the same package as DECL. */
7390 if (in_same_package (decl, enclosing_decl))
7392 access = "non-public";
7395 /* Class is public. */
7398 parse_error_context (cl, "Nested %s %s is %s; cannot be accessed from here",
7399 (CLASS_INTERFACE (decl) ? "interface" : "class"),
7400 lang_printable_name (decl, 2), access);
7403 /* Accessibility check for top-level classes. If CLASS_NAME is in a
7404 foreign package, it must be PUBLIC. Return 0 if no access
7405 violations were found, 1 otherwise. If VERBOSE is true and an error
7406 was found, it is reported and accounted for. If CL is NULL then
7407 look it up with THIS_DECL. */
7410 check_pkg_class_access (tree class_name, tree cl, bool verbose, tree this_decl)
7414 if (!IDENTIFIER_CLASS_VALUE (class_name))
7417 if (!(type = TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_name))))
7420 if (!CLASS_PUBLIC (TYPE_NAME (type)))
7422 /* Access to a private class within the same package is
7425 split_qualified_name (&l, &r, class_name);
7426 if (!QUALIFIED_P (class_name) && !ctxp->package)
7427 /* Both in the empty package. */
7429 if (l == ctxp->package)
7430 /* Both in the same package. */
7435 (cl == NULL ? lookup_cl (this_decl): cl,
7436 "Can't access %s %qs. Only public classes and interfaces in other packages can be accessed",
7437 (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
7438 IDENTIFIER_POINTER (class_name));
7444 /* Local variable declaration. */
7447 declare_local_variables (int modifier, tree type, tree vlist)
7449 tree decl, current, saved_type;
7450 tree type_wfl = NULL_TREE;
7454 /* Push a new block if statements were seen between the last time we
7455 pushed a block and now. Keep a count of blocks to close */
7456 if (BLOCK_EXPR_BODY (GET_CURRENT_BLOCK (current_function_decl)))
7458 tree b = enter_block ();
7459 BLOCK_IS_IMPLICIT (b) = 1;
7465 for (i = 0; i < ARRAY_SIZE (ctxp->modifier_ctx); i++)
7466 if (1 << i & modifier)
7468 if (modifier == ACC_FINAL)
7473 (ctxp->modifier_ctx [i],
7474 "Only %<final%> is allowed as a local variables modifier");
7479 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
7480 hold the TYPE value if a new incomplete has to be created (as
7481 opposed to being found already existing and reused). */
7482 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
7484 /* If TYPE is fully resolved and we don't have a reference, make one */
7485 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
7487 /* Go through all the declared variables */
7488 for (current = vlist, saved_type = type; current;
7489 current = TREE_CHAIN (current), type = saved_type)
7491 tree other, real_type;
7492 tree wfl = TREE_PURPOSE (current);
7493 tree name = EXPR_WFL_NODE (wfl);
7494 tree init = TREE_VALUE (current);
7496 /* Process NAME, as it may specify extra dimension(s) for it */
7497 type = build_array_from_name (type, type_wfl, name, &name);
7499 /* Variable redefinition check */
7500 if ((other = lookup_name_in_blocks (name)))
7502 variable_redefinition_error (wfl, name, TREE_TYPE (other),
7503 DECL_SOURCE_LINE (other));
7507 /* Type adjustment. We may have just readjusted TYPE because
7508 the variable specified more dimensions. Make sure we have
7509 a reference if we can and don't have one already. */
7510 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
7512 real_type = GET_REAL_TYPE (type);
7513 /* Never layout this decl. This will be done when its scope
7515 decl = build_decl (VAR_DECL, name, real_type);
7516 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
7517 DECL_FINAL (decl) = final_p;
7518 BLOCK_CHAIN_DECL (decl);
7520 /* If doing xreferencing, replace the line number with the WFL
7522 #ifdef USE_MAPPED_LOCATION
7524 DECL_SOURCE_LOCATION (decl) = EXPR_LOCATION (wfl);
7527 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (wfl);
7530 /* Don't try to use an INIT statement when an error was found */
7531 if (init && java_error_count)
7534 /* Remember it if this is an initialized-upon-declaration final
7536 if (init && final_p)
7538 DECL_LOCAL_FINAL_IUD (decl) = 1;
7541 /* Add the initialization function to the current function's code */
7544 /* Name might have been readjusted */
7545 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = name;
7546 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
7547 java_method_add_stmt (current_function_decl,
7548 build_debugable_stmt (EXPR_WFL_LINECOL (init),
7552 /* Setup dependency the type of the decl */
7556 register_incomplete_type (JDEP_VARIABLE, type_wfl, decl, type);
7557 dep = CLASSD_LAST (ctxp->classd_list);
7558 JDEP_GET_PATCH (dep) = &TREE_TYPE (decl);
7561 SOURCE_FRONTEND_DEBUG (("Defined locals"));
7564 /* Called during parsing. Build decls from argument list. */
7567 source_start_java_method (tree fndecl)
7576 current_function_decl = fndecl;
7578 /* New scope for the function */
7580 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
7581 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
7583 tree type = TREE_VALUE (tem);
7584 tree name = TREE_PURPOSE (tem);
7586 /* If type is incomplete. Create an incomplete decl and ask for
7587 the decl to be patched later */
7588 if (INCOMPLETE_TYPE_P (type))
7591 tree real_type = GET_REAL_TYPE (type);
7592 parm_decl = build_decl (PARM_DECL, name, real_type);
7593 type = obtain_incomplete_type (type);
7594 register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
7595 jdep = CLASSD_LAST (ctxp->classd_list);
7596 JDEP_MISC (jdep) = name;
7597 JDEP_GET_PATCH (jdep) = &TREE_TYPE (parm_decl);
7600 parm_decl = build_decl (PARM_DECL, name, type);
7602 /* Remember if a local variable was declared final (via its
7603 TREE_LIST of type/name.) Set DECL_FINAL accordingly. */
7604 if (ARG_FINAL_P (tem))
7606 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (parm_decl);
7607 DECL_FINAL (parm_decl) = 1;
7610 BLOCK_CHAIN_DECL (parm_decl);
7612 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
7613 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) =
7615 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
7616 DECL_MAX_LOCALS (current_function_decl) = i;
7619 /* Called during parsing. Creates an artificial method declaration. */
7622 create_artificial_method (tree class, int flags, tree type,
7623 tree name, tree args)
7626 location_t save_location = input_location;
7628 input_location = DECL_SOURCE_LOCATION (TYPE_NAME (class));
7629 mdecl = make_node (FUNCTION_TYPE);
7630 TREE_TYPE (mdecl) = type;
7631 TYPE_ARG_TYPES (mdecl) = args;
7632 /* We used to compute the signature of MDECL here and then use
7633 add_method(), but that failed because our caller might modify
7634 the type of the returned method, which trashes the cache in
7635 get_type_from_signature(). */
7636 mdecl = add_method_1 (class, flags, name, mdecl);
7637 input_location = save_location;
7638 DECL_ARTIFICIAL (mdecl) = 1;
7642 /* Starts the body if an artificial method. */
7645 start_artificial_method_body (tree mdecl)
7647 #ifdef USE_MAPPED_LOCATION
7648 DECL_SOURCE_LOCATION (mdecl) = ctxp->file_start_location;
7649 DECL_FUNCTION_LAST_LINE (mdecl) = ctxp->file_start_location;
7651 DECL_SOURCE_LINE (mdecl) = 1;
7652 DECL_FUNCTION_LAST_LINE (mdecl) = 1;
7654 source_start_java_method (mdecl);
7659 end_artificial_method_body (tree mdecl)
7661 /* exit_block modifies DECL_FUNCTION_BODY (current_function_decl).
7662 It has to be evaluated first. (if mdecl is current_function_decl,
7663 we have an undefined behavior if no temporary variable is used.) */
7664 tree b = exit_block ();
7665 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = b;
7669 /* Dump a tree of some kind. This is a convenience wrapper for the
7670 dump_* functions in tree-dump.c. */
7672 dump_java_tree (enum tree_dump_index phase, tree t)
7677 stream = dump_begin (phase, &flags);
7681 dump_node (t, flags, stream);
7682 dump_end (phase, stream);
7686 /* Terminate a function and expand its body. */
7689 source_end_java_method (void)
7691 tree fndecl = current_function_decl;
7696 java_parser_context_save_global ();
7697 #ifdef USE_MAPPED_LOCATION
7698 input_location = ctxp->last_ccb_indent1;
7700 input_line = ctxp->last_ccb_indent1;
7703 /* Turn function bodies with only a NOP expr null, so they don't get
7704 generated at all and we won't get warnings when using the -W
7706 if (IS_EMPTY_STMT (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))))
7707 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) = NULL_TREE;
7709 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))
7710 && ! flag_emit_class_files
7711 && ! flag_emit_xref)
7712 finish_method (fndecl);
7714 current_function_decl = NULL_TREE;
7715 java_parser_context_restore_global ();
7716 current_function_decl = NULL_TREE;
7719 /* Record EXPR in the current function block. Complements compound
7720 expression second operand if necessary. */
7723 java_method_add_stmt (tree fndecl, tree expr)
7725 if (!GET_CURRENT_BLOCK (fndecl))
7727 return add_stmt_to_block (GET_CURRENT_BLOCK (fndecl), NULL_TREE, expr);
7731 add_stmt_to_block (tree b, tree type, tree stmt)
7733 tree body = BLOCK_EXPR_BODY (b), c;
7735 if (java_error_count)
7738 if ((c = add_stmt_to_compound (body, type, stmt)) == body)
7741 BLOCK_EXPR_BODY (b) = c;
7742 TREE_SIDE_EFFECTS (c) = 1;
7746 /* Lays out the methods for the classes seen so far. */
7749 java_layout_seen_class_methods (void)
7751 tree previous_list = all_class_list;
7752 tree end = NULL_TREE;
7757 for (current = previous_list;
7758 current != end; current = TREE_CHAIN (current))
7760 tree decl = TREE_VALUE (current);
7761 tree cls = TREE_TYPE (decl);
7763 input_location = DECL_SOURCE_LOCATION (decl);
7765 if (! CLASS_LOADED_P (cls))
7766 load_class (cls, 0);
7768 layout_class_methods (cls);
7771 /* Note that new classes might have been added while laying out
7772 methods, changing the value of all_class_list. */
7774 if (previous_list != all_class_list)
7776 end = previous_list;
7777 previous_list = all_class_list;
7784 static GTY(()) tree stop_reordering;
7786 java_reorder_fields (void)
7790 for (current = gclass_list; current; current = TREE_CHAIN (current))
7792 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
7794 if (current_class == stop_reordering)
7797 /* Reverse the fields, but leave the dummy field in front.
7798 Fields are already ordered for Object and Class */
7799 if (TYPE_FIELDS (current_class) && current_class != object_type_node
7800 && current_class != class_type_node)
7802 /* If the dummy field is there, reverse the right fields and
7803 just layout the type for proper fields offset */
7804 if (!DECL_NAME (TYPE_FIELDS (current_class)))
7806 tree fields = TYPE_FIELDS (current_class);
7807 TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
7808 TYPE_SIZE (current_class) = NULL_TREE;
7810 /* We don't have a dummy field, we need to layout the class,
7811 after having reversed the fields */
7814 TYPE_FIELDS (current_class) =
7815 nreverse (TYPE_FIELDS (current_class));
7816 TYPE_SIZE (current_class) = NULL_TREE;
7820 /* There are cases were gclass_list will be empty. */
7822 stop_reordering = TREE_TYPE (TREE_VALUE (gclass_list));
7825 /* Layout the methods of all classes loaded in one way or another.
7826 Check methods of source parsed classes. Then reorder the
7827 fields and layout the classes or the type of all source parsed
7831 java_layout_classes (void)
7834 int save_error_count = java_error_count;
7836 /* Layout the methods of all classes seen so far */
7837 java_layout_seen_class_methods ();
7838 java_parse_abort_on_error ();
7839 all_class_list = NULL_TREE;
7841 /* Then check the methods of all parsed classes */
7842 for (current = gclass_list; current; current = TREE_CHAIN (current))
7843 if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
7844 java_check_methods (TREE_VALUE (current));
7845 java_parse_abort_on_error ();
7847 for (current = gclass_list; current; current = TREE_CHAIN (current))
7849 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
7850 layout_class (current_class);
7852 /* Error reported by the caller */
7853 if (java_error_count)
7857 /* We might have reloaded classes durign the process of laying out
7858 classes for code generation. We must layout the methods of those
7859 late additions, as constructor checks might use them */
7860 java_layout_seen_class_methods ();
7861 java_parse_abort_on_error ();
7864 /* Expand methods in the current set of classes remembered for
7868 java_complete_expand_classes (void)
7872 do_not_fold = flag_emit_xref;
7874 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
7875 if (!INNER_CLASS_DECL_P (current))
7876 java_complete_expand_class (current);
7879 /* Expand the methods found in OUTER, starting first by OUTER's inner
7883 java_complete_expand_class (tree outer)
7887 /* We need to go after all inner classes and start expanding them,
7888 starting with most nested ones. We have to do that because nested
7889 classes might add functions to outer classes */
7891 for (inner_list = DECL_INNER_CLASS_LIST (outer);
7892 inner_list; inner_list = TREE_CHAIN (inner_list))
7893 java_complete_expand_class (TREE_PURPOSE (inner_list));
7895 java_complete_expand_methods (outer);
7898 /* Expand methods registered in CLASS_DECL. The general idea is that
7899 we expand regular methods first. This allows us get an estimate on
7900 how outer context local alias fields are really used so we can add
7901 to the constructor just enough code to initialize them properly (it
7902 also lets us generate finit$ correctly.) Then we expand the
7903 constructors and then <clinit>. */
7906 java_complete_expand_methods (tree class_decl)
7908 tree clinit, decl, first_decl;
7910 output_class = current_class = TREE_TYPE (class_decl);
7912 /* Pre-expand <clinit> to figure whether we really need it or
7913 not. If we do need it, we pre-expand the static fields so they're
7914 ready to be used somewhere else. <clinit> will be fully expanded
7915 after we processed the constructors. */
7916 first_decl = TYPE_METHODS (current_class);
7917 clinit = maybe_generate_pre_expand_clinit (current_class);
7919 /* Then generate finit$ (if we need to) because constructors will
7921 if (TYPE_FINIT_STMT_LIST (current_class))
7922 java_complete_expand_method (generate_finit (current_class));
7924 /* Then generate instinit$ (if we need to) because constructors will
7926 if (TYPE_II_STMT_LIST (current_class))
7927 java_complete_expand_method (generate_instinit (current_class));
7929 /* Now do the constructors */
7930 for (decl = first_decl ; !java_error_count && decl; decl = TREE_CHAIN (decl))
7932 if (!DECL_CONSTRUCTOR_P (decl))
7934 java_complete_expand_method (decl);
7937 /* First, do the ordinary methods. */
7938 for (decl = first_decl; decl; decl = TREE_CHAIN (decl))
7940 /* Ctors aren't part of this batch. */
7941 if (DECL_CONSTRUCTOR_P (decl) || DECL_CLINIT_P (decl))
7944 /* Skip abstract or native methods -- but do handle native
7945 methods when generating JNI stubs. */
7946 if (METHOD_ABSTRACT (decl) || (! flag_jni && METHOD_NATIVE (decl)))
7948 DECL_FUNCTION_BODY (decl) = NULL_TREE;
7952 if (METHOD_NATIVE (decl))
7955 current_function_decl = decl;
7956 body = build_jni_stub (decl);
7957 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl)) = body;
7960 java_complete_expand_method (decl);
7963 /* If there is indeed a <clinit>, fully expand it now */
7966 /* Prevent the use of `this' inside <clinit> */
7967 ctxp->explicit_constructor_p = 1;
7968 java_complete_expand_method (clinit);
7969 ctxp->explicit_constructor_p = 0;
7972 /* We might have generated a class$ that we now want to expand */
7973 if (TYPE_DOT_CLASS (current_class))
7974 java_complete_expand_method (TYPE_DOT_CLASS (current_class));
7976 /* Now verify constructor circularity (stop after the first one we
7978 if (!CLASS_INTERFACE (class_decl))
7979 for (decl = TYPE_METHODS (current_class); decl; decl = TREE_CHAIN (decl))
7980 if (DECL_CONSTRUCTOR_P (decl)
7981 && verify_constructor_circularity (decl, decl))
7985 /* Attempt to create <clinit>. Pre-expand static fields so they can be
7986 safely used in some other methods/constructors. */
7989 maybe_generate_pre_expand_clinit (tree class_type)
7991 tree current, mdecl;
7993 if (!TYPE_CLINIT_STMT_LIST (class_type))
7996 /* Go through all static fields and pre expand them */
7997 for (current = TYPE_FIELDS (class_type); current;
7998 current = TREE_CHAIN (current))
7999 if (FIELD_STATIC (current))
8000 build_field_ref (NULL_TREE, class_type, DECL_NAME (current));
8002 /* Then build the <clinit> method */
8003 mdecl = create_artificial_method (class_type, ACC_STATIC, void_type_node,
8004 clinit_identifier_node, end_params_node);
8005 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
8007 start_artificial_method_body (mdecl);
8009 /* We process the list of assignment we produced as the result of
8010 the declaration of initialized static field and add them as
8011 statement to the <clinit> method. */
8012 for (current = TYPE_CLINIT_STMT_LIST (class_type); current;
8013 current = TREE_CHAIN (current))
8015 tree stmt = current;
8016 /* We build the assignment expression that will initialize the
8017 field to its value. There are strict rules on static
8018 initializers (8.5). FIXME */
8019 if (TREE_CODE (stmt) != BLOCK && !IS_EMPTY_STMT (stmt))
8020 stmt = build_debugable_stmt (EXPR_WFL_LINECOL (stmt), stmt);
8021 java_method_add_stmt (mdecl, stmt);
8024 end_artificial_method_body (mdecl);
8026 /* Now we want to place <clinit> as the last method (because we need
8027 it at least for interface so that it doesn't interfere with the
8028 dispatch table based lookup. */
8029 if (TREE_CHAIN (TYPE_METHODS (class_type)))
8031 current = TREE_CHAIN (TYPE_METHODS (class_type));
8032 TYPE_METHODS (class_type) = current;
8034 while (TREE_CHAIN (current))
8035 current = TREE_CHAIN (current);
8037 TREE_CHAIN (current) = mdecl;
8038 TREE_CHAIN (mdecl) = NULL_TREE;
8044 /* Analyzes a method body and look for something that isn't a
8045 MODIFY_EXPR with a constant value. */
8048 analyze_clinit_body (tree this_class, tree bbody)
8051 switch (TREE_CODE (bbody))
8054 bbody = BLOCK_EXPR_BODY (bbody);
8057 case EXPR_WITH_FILE_LOCATION:
8058 bbody = EXPR_WFL_NODE (bbody);
8062 if (analyze_clinit_body (this_class, TREE_OPERAND (bbody, 0)))
8064 bbody = TREE_OPERAND (bbody, 1);
8068 /* If we're generating to class file and we're dealing with an
8069 array initialization, we return 1 to keep <clinit> */
8070 if (TREE_CODE (TREE_OPERAND (bbody, 1)) == NEW_ARRAY_INIT
8071 && flag_emit_class_files)
8074 /* There are a few cases where we're required to keep
8076 - If this is an assignment whose operand is not constant,
8077 - If this is an assignment to a non-initialized field,
8078 - If this field is not a member of the current class.
8080 return (! TREE_CONSTANT (TREE_OPERAND (bbody, 1))
8081 || ! DECL_INITIAL (TREE_OPERAND (bbody, 0))
8082 || DECL_CONTEXT (TREE_OPERAND (bbody, 0)) != this_class);
8091 /* See whether we could get rid of <clinit>. Criteria are: all static
8092 final fields have constant initial values and the body of <clinit>
8093 is empty. Return 1 if <clinit> was discarded, 0 otherwise. */
8096 maybe_yank_clinit (tree mdecl)
8101 if (!DECL_CLINIT_P (mdecl))
8104 /* If the body isn't empty, then we keep <clinit>. Note that if
8105 we're emitting classfiles, this isn't enough not to rule it
8107 fbody = DECL_FUNCTION_BODY (mdecl);
8108 bbody = BLOCK_EXPR_BODY (fbody);
8109 if (bbody && bbody != error_mark_node)
8110 bbody = BLOCK_EXPR_BODY (bbody);
8113 if (bbody && ! flag_emit_class_files && !IS_EMPTY_STMT (bbody))
8116 type = DECL_CONTEXT (mdecl);
8117 current = TYPE_FIELDS (type);
8119 for (current = (current ? TREE_CHAIN (current) : current);
8120 current; current = TREE_CHAIN (current))
8124 /* We're not interested in non-static fields. */
8125 if (!FIELD_STATIC (current))
8128 /* Nor in fields without initializers. */
8129 f_init = DECL_INITIAL (current);
8130 if (f_init == NULL_TREE)
8133 /* Anything that isn't String or a basic type is ruled out -- or
8134 if we know how to deal with it (when doing things natively) we
8135 should generated an empty <clinit> so that SUID are computed
8137 if (! JSTRING_TYPE_P (TREE_TYPE (current))
8138 && ! JNUMERIC_TYPE_P (TREE_TYPE (current)))
8141 if (! FIELD_FINAL (current) || ! TREE_CONSTANT (f_init))
8145 /* Now we analyze the method body and look for something that
8146 isn't a MODIFY_EXPR */
8147 if (!IS_EMPTY_STMT (bbody) && analyze_clinit_body (type, bbody))
8150 /* Get rid of <clinit> in the class' list of methods */
8151 if (TYPE_METHODS (type) == mdecl)
8152 TYPE_METHODS (type) = TREE_CHAIN (mdecl);
8154 for (current = TYPE_METHODS (type); current;
8155 current = TREE_CHAIN (current))
8156 if (TREE_CHAIN (current) == mdecl)
8158 TREE_CHAIN (current) = TREE_CHAIN (mdecl);
8165 /* Install the argument from MDECL. Suitable to completion and
8166 expansion of mdecl's body. */
8169 start_complete_expand_method (tree mdecl)
8173 pushlevel (1); /* Prepare for a parameter push */
8174 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
8175 DECL_ARGUMENTS (mdecl) = tem;
8177 for (; tem; tem = TREE_CHAIN (tem))
8179 /* TREE_CHAIN (tem) will change after pushdecl. */
8180 tree next = TREE_CHAIN (tem);
8181 tree type = TREE_TYPE (tem);
8182 if (targetm.calls.promote_prototypes (type)
8183 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
8184 && INTEGRAL_TYPE_P (type))
8185 type = integer_type_node;
8186 DECL_ARG_TYPE (tem) = type;
8187 layout_decl (tem, 0);
8189 /* Re-install the next so that the list is kept and the loop
8191 TREE_CHAIN (tem) = next;
8193 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
8194 input_location = DECL_SOURCE_LOCATION (mdecl);
8195 build_result_decl (mdecl);
8199 /* Complete and expand a method. */
8202 java_complete_expand_method (tree mdecl)
8204 tree fbody, block_body, exception_copy;
8206 current_function_decl = mdecl;
8207 /* Fix constructors before expanding them */
8208 if (DECL_CONSTRUCTOR_P (mdecl))
8209 fix_constructors (mdecl);
8211 /* Expand functions that have a body */
8212 if (!DECL_FUNCTION_BODY (mdecl))
8215 fbody = DECL_FUNCTION_BODY (mdecl);
8216 block_body = BLOCK_EXPR_BODY (fbody);
8217 exception_copy = NULL_TREE;
8219 current_function_decl = mdecl;
8222 fprintf (stderr, " [%s.",
8223 lang_printable_name (DECL_CONTEXT (mdecl), 0));
8224 announce_function (mdecl);
8226 fprintf (stderr, "]");
8228 /* Prepare the function for tree completion */
8229 start_complete_expand_method (mdecl);
8231 /* Install the current this */
8232 current_this = (!METHOD_STATIC (mdecl) ?
8233 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl)) : NULL_TREE);
8235 /* Purge the `throws' list of unchecked exceptions (we save a copy
8236 of the list and re-install it later.) */
8237 exception_copy = copy_list (DECL_FUNCTION_THROWS (mdecl));
8238 purge_unchecked_exceptions (mdecl);
8240 /* Install exceptions thrown with `throws' */
8241 PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
8243 if (block_body != NULL_TREE)
8245 block_body = java_complete_tree (block_body);
8247 /* Before we check initialization, attached all class initialization
8248 variable to the block_body */
8249 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (mdecl),
8250 attach_init_test_initialization_flags, block_body);
8252 if (! flag_emit_xref && ! METHOD_NATIVE (mdecl))
8254 check_for_initialization (block_body, mdecl);
8256 /* Go through all the flags marking the initialization of
8257 static variables and see whether they're definitively
8258 assigned, in which case the type is remembered as
8259 definitively initialized in MDECL. */
8260 if (STATIC_CLASS_INIT_OPT_P ())
8262 /* Always register the context as properly initialized in
8263 MDECL. This used with caution helps removing extra
8264 initialization of self. */
8265 if (METHOD_STATIC (mdecl))
8268 (DECL_FUNCTION_INITIALIZED_CLASS_TABLE (mdecl),
8269 DECL_CONTEXT (mdecl), INSERT)) = DECL_CONTEXT (mdecl);
8273 ctxp->explicit_constructor_p = 0;
8276 BLOCK_EXPR_BODY (fbody) = block_body;
8278 /* If we saw a return but couldn't evaluate it properly, we'll have
8279 an error_mark_node here. */
8280 if (block_body != error_mark_node
8281 && (block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
8282 && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE
8284 missing_return_error (current_function_decl);
8286 /* See if we can get rid of <clinit> if MDECL happens to be <clinit> */
8287 maybe_yank_clinit (mdecl);
8289 /* Pop the current level, with special measures if we found errors. */
8290 if (java_error_count)
8291 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
8294 /* Pop the exceptions and sanity check */
8296 if (currently_caught_type_list)
8299 /* Restore the copy of the list of exceptions if emitting xrefs. */
8300 DECL_FUNCTION_THROWS (mdecl) = exception_copy;
8303 /* For with each class for which there's code to generate. */
8306 java_expand_method_bodies (tree class)
8309 for (decl = TYPE_METHODS (class); decl; decl = TREE_CHAIN (decl))
8313 if (! DECL_FUNCTION_BODY (decl))
8316 current_function_decl = decl;
8318 block = BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl));
8320 /* Save the function body for gimplify and inlining. */
8321 DECL_SAVED_TREE (decl) = block;
8323 /* It's time to assign the variable flagging static class
8324 initialization based on which classes invoked static methods
8325 are definitely initializing. This should be flagged. */
8326 if (STATIC_CLASS_INIT_OPT_P ())
8328 tree list = DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (decl);
8329 for (; list != NULL_TREE; list = TREE_CHAIN (list))
8331 /* Executed for each statement calling a static function.
8332 LIST is a TREE_LIST whose PURPOSE is the called function
8333 and VALUE is a compound whose second operand can be patched
8334 with static class initialization flag assignments. */
8336 tree called_method = TREE_PURPOSE (list);
8337 tree compound = TREE_VALUE (list);
8338 tree assignment_compound_list
8339 = build_tree_list (called_method, NULL);
8341 /* For each class definitely initialized in
8342 CALLED_METHOD, fill ASSIGNMENT_COMPOUND with
8343 assignment to the class initialization flag. */
8344 htab_traverse (DECL_FUNCTION_INITIALIZED_CLASS_TABLE (called_method),
8345 emit_test_initialization,
8346 assignment_compound_list);
8348 if (TREE_VALUE (assignment_compound_list))
8349 TREE_OPERAND (compound, 1)
8350 = TREE_VALUE (assignment_compound_list);
8354 /* Expand the function body. */
8355 source_end_java_method ();
8361 /* This section of the code deals with accessing enclosing context
8362 fields either directly by using the relevant access to this$<n> or
8363 by invoking an access method crafted for that purpose. */
8365 /* Build the necessary access from an inner class to an outer
8366 class. This routine could be optimized to cache previous result
8367 (decl, current_class and returned access). When an access method
8368 needs to be generated, it always takes the form of a read. It might
8369 be later turned into a write by calling outer_field_access_fix. */
8372 build_outer_field_access (tree id, tree decl)
8374 tree access = NULL_TREE;
8375 tree ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
8376 tree decl_ctx = DECL_CONTEXT (decl);
8378 /* If the immediate enclosing context of the current class is the
8379 field decl's class or inherits from it; build the access as
8380 `this$<n>.<field>'. Note that we will break the `private' barrier
8381 if we're not emitting bytecodes. */
8382 if ((ctx == decl_ctx || inherits_from_p (ctx, decl_ctx))
8383 && (!FIELD_PRIVATE (decl) || !flag_emit_class_files ))
8385 tree thisn = build_current_thisn (current_class);
8386 access = make_qualified_primary (build_wfl_node (thisn),
8387 id, EXPR_WFL_LINECOL (id));
8389 /* Otherwise, generate access methods to outer this and access the
8390 field (either using an access method or by direct access.) */
8393 int lc = EXPR_WFL_LINECOL (id);
8395 /* Now we chain the required number of calls to the access$0 to
8396 get a hold to the enclosing instance we need, and then we
8397 build the field access. */
8398 access = build_access_to_thisn (current_class, decl_ctx, lc);
8400 /* If the field is private and we're generating bytecode, then
8401 we generate an access method */
8402 if (FIELD_PRIVATE (decl) && flag_emit_class_files )
8404 tree name = build_outer_field_access_methods (decl);
8405 access = build_outer_field_access_expr (lc, decl_ctx,
8406 name, access, NULL_TREE);
8408 /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'.
8409 Once again we break the `private' access rule from a foreign
8412 access = make_qualified_primary (access, id, lc);
8414 return resolve_expression_name (access, NULL);
8417 /* Return a nonzero value if NODE describes an outer field inner
8421 outer_field_access_p (tree type, tree decl)
8423 if (!INNER_CLASS_TYPE_P (type)
8424 || TREE_CODE (decl) != FIELD_DECL
8425 || DECL_CONTEXT (decl) == type)
8428 /* If the inner class extends the declaration context of the field
8429 we're trying to access, then this isn't an outer field access */
8430 if (inherits_from_p (type, DECL_CONTEXT (decl)))
8433 for (type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))); ;
8434 type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))))
8436 if (type == DECL_CONTEXT (decl))
8439 if (!DECL_CONTEXT (TYPE_NAME (type)))
8441 /* Before we give up, see whether the field is inherited from
8442 the enclosing context we're considering. */
8443 if (inherits_from_p (type, DECL_CONTEXT (decl)))
8452 /* Return a nonzero value if NODE represents an outer field inner
8453 access that was been already expanded. As a side effect, it returns
8454 the name of the field being accessed and the argument passed to the
8455 access function, suitable for a regeneration of the access method
8456 call if necessary. */
8459 outer_field_expanded_access_p (tree node, tree *name, tree *arg_type,
8464 if (TREE_CODE (node) != CALL_EXPR)
8467 /* Well, gcj generates slightly different tree nodes when compiling
8468 to native or bytecodes. It's the case for function calls. */
8470 if (flag_emit_class_files
8471 && TREE_CODE (node) == CALL_EXPR
8472 && OUTER_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (TREE_OPERAND (node, 0))))
8474 else if (!flag_emit_class_files)
8476 node = TREE_OPERAND (node, 0);
8478 if (node && TREE_OPERAND (node, 0)
8479 && TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR)
8481 node = TREE_OPERAND (node, 0);
8482 if (TREE_OPERAND (node, 0)
8483 && TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL
8484 && (OUTER_FIELD_ACCESS_IDENTIFIER_P
8485 (DECL_NAME (TREE_OPERAND (node, 0)))))
8490 if (identified && name && arg_type && arg)
8492 tree argument = TREE_OPERAND (node, 1);
8493 *name = DECL_NAME (TREE_OPERAND (node, 0));
8494 *arg_type = TREE_TYPE (TREE_TYPE (TREE_VALUE (argument)));
8495 *arg = TREE_VALUE (argument);
8500 /* Detect in NODE an outer field read access from an inner class and
8501 transform it into a write with RHS as an argument. This function is
8502 called from the java_complete_lhs when an assignment to a LHS can
8506 outer_field_access_fix (tree wfl, tree node, tree rhs)
8508 tree name, arg_type, arg;
8510 if (outer_field_expanded_access_p (node, &name, &arg_type, &arg))
8512 node = build_outer_field_access_expr (EXPR_WFL_LINECOL (wfl),
8513 arg_type, name, arg, rhs);
8514 return java_complete_tree (node);
8519 /* Construct the expression that calls an access method:
8520 <type>.access$<n>(<arg1> [, <arg2>]);
8522 ARG2 can be NULL and will be omitted in that case. It will denote a
8526 build_outer_field_access_expr (int lc, tree type, tree access_method_name,
8527 tree arg1, tree arg2)
8529 tree args, cn, access;
8531 args = arg1 ? arg1 :
8532 build_wfl_node (build_current_thisn (current_class));
8533 args = build_tree_list (NULL_TREE, args);
8536 args = tree_cons (NULL_TREE, arg2, args);
8538 access = build_method_invocation (build_wfl_node (access_method_name), args);
8539 cn = build_wfl_node (DECL_NAME (TYPE_NAME (type)));
8540 return make_qualified_primary (cn, access, lc);
8544 build_new_access_id (void)
8546 static int access_n_counter = 1;
8549 sprintf (buffer, "access$%d", access_n_counter++);
8550 return get_identifier (buffer);
8553 /* Create the static access functions for the outer field DECL. We define a
8555 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$) {
8559 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$,
8560 TREE_TYPE (<field>) value$) {
8561 return inst$.field = value$;
8563 We should have a usage flags on the DECL so we can lazily turn the ones
8564 we're using for code generation. FIXME.
8568 build_outer_field_access_methods (tree decl)
8570 tree id, args, stmt, mdecl;
8572 if (FIELD_INNER_ACCESS_P (decl))
8573 return FIELD_INNER_ACCESS (decl);
8575 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
8577 /* Create the identifier and a function named after it. */
8578 id = build_new_access_id ();
8580 /* The identifier is marked as bearing the name of a generated write
8581 access function for outer field accessed from inner classes. */
8582 OUTER_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
8584 /* Create the read access */
8585 args = build_tree_list (inst_id, build_pointer_type (DECL_CONTEXT (decl)));
8586 TREE_CHAIN (args) = end_params_node;
8587 stmt = make_qualified_primary (build_wfl_node (inst_id),
8588 build_wfl_node (DECL_NAME (decl)), 0);
8589 stmt = build_return (0, stmt);
8590 mdecl = build_outer_field_access_method (DECL_CONTEXT (decl),
8591 TREE_TYPE (decl), id, args, stmt);
8592 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
8594 /* Create the write access method. No write access for final variable */
8595 if (!FIELD_FINAL (decl))
8597 args = build_tree_list (inst_id,
8598 build_pointer_type (DECL_CONTEXT (decl)));
8599 TREE_CHAIN (args) = build_tree_list (wpv_id, TREE_TYPE (decl));
8600 TREE_CHAIN (TREE_CHAIN (args)) = end_params_node;
8601 stmt = make_qualified_primary (build_wfl_node (inst_id),
8602 build_wfl_node (DECL_NAME (decl)), 0);
8603 stmt = build_return (0, build_assignment (ASSIGN_TK, 0, stmt,
8604 build_wfl_node (wpv_id)));
8605 mdecl = build_outer_field_access_method (DECL_CONTEXT (decl),
8606 TREE_TYPE (decl), id,
8609 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
8611 /* Return the access name */
8612 return FIELD_INNER_ACCESS (decl) = id;
8615 /* Build an field access method NAME. */
8618 build_outer_field_access_method (tree class, tree type, tree name,
8619 tree args, tree body)
8621 tree saved_current_function_decl, mdecl;
8623 /* Create the method */
8624 mdecl = create_artificial_method (class, ACC_STATIC, type, name, args);
8625 fix_method_argument_names (args, mdecl);
8626 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8628 /* Attach the method body. */
8629 saved_current_function_decl = current_function_decl;
8630 start_artificial_method_body (mdecl);
8631 java_method_add_stmt (mdecl, body);
8632 end_artificial_method_body (mdecl);
8633 current_function_decl = saved_current_function_decl;
8639 /* This section deals with building access function necessary for
8640 certain kinds of method invocation from inner classes. */
8643 build_outer_method_access_method (tree decl)
8645 tree saved_current_function_decl, mdecl;
8646 tree args = NULL_TREE, call_args = NULL_TREE;
8647 tree carg, id, body, class;
8649 int parm_id_count = 0;
8651 /* Test this abort with an access to a private field */
8652 if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "access$"))
8655 /* Check the cache first */
8656 if (DECL_FUNCTION_INNER_ACCESS (decl))
8657 return DECL_FUNCTION_INNER_ACCESS (decl);
8659 class = DECL_CONTEXT (decl);
8661 /* Obtain an access identifier and mark it */
8662 id = build_new_access_id ();
8663 OUTER_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
8665 carg = TYPE_ARG_TYPES (TREE_TYPE (decl));
8666 /* Create the arguments, as much as the original */
8667 for (; carg && carg != end_params_node;
8668 carg = TREE_CHAIN (carg))
8670 sprintf (buffer, "write_parm_value$%d", parm_id_count++);
8671 args = chainon (args, build_tree_list (get_identifier (buffer),
8672 TREE_VALUE (carg)));
8674 args = chainon (args, end_params_node);
8676 /* Create the method */
8677 mdecl = create_artificial_method (class, ACC_STATIC,
8678 TREE_TYPE (TREE_TYPE (decl)), id, args);
8679 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8680 /* There is a potential bug here. We should be able to use
8681 fix_method_argument_names, but then arg names get mixed up and
8682 eventually a constructor will have its this$0 altered and the
8683 outer context won't be assignment properly. The testcase is
8685 TYPE_ARG_TYPES (TREE_TYPE (mdecl)) = args;
8687 /* Attach the method body. */
8688 saved_current_function_decl = current_function_decl;
8689 start_artificial_method_body (mdecl);
8691 /* The actual method invocation uses the same args. When invoking a
8692 static methods that way, we don't want to skip the first
8695 if (!METHOD_STATIC (decl))
8696 carg = TREE_CHAIN (carg);
8697 for (; carg && carg != end_params_node; carg = TREE_CHAIN (carg))
8698 call_args = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (carg)),
8701 body = build_method_invocation (build_wfl_node (DECL_NAME (decl)),
8703 if (!METHOD_STATIC (decl))
8704 body = make_qualified_primary (build_wfl_node (TREE_PURPOSE (args)),
8706 if (TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
8707 body = build_return (0, body);
8708 java_method_add_stmt (mdecl,body);
8709 end_artificial_method_body (mdecl);
8710 current_function_decl = saved_current_function_decl;
8712 /* Back tag the access function so it know what it accesses */
8713 DECL_FUNCTION_ACCESS_DECL (decl) = mdecl;
8715 /* Tag the current method so it knows it has an access generated */
8716 return DECL_FUNCTION_INNER_ACCESS (decl) = mdecl;
8720 /* This section of the code deals with building expressions to access
8721 the enclosing instance of an inner class. The enclosing instance is
8722 kept in a generated field called this$<n>, with <n> being the
8723 inner class nesting level (starting from 0.) */
8725 /* Build an access to a given this$<n>, always chaining access call to
8726 others. Access methods to this$<n> are build on the fly if
8727 necessary. This CAN'T be used to solely access this$<n-1> from
8728 this$<n> (which alway yield to special cases and optimization, see
8729 for example build_outer_field_access). */
8732 build_access_to_thisn (tree from, tree to, int lc)
8734 tree access = NULL_TREE;
8736 while (from != to && PURE_INNER_CLASS_TYPE_P (from))
8740 access = build_current_thisn (from);
8741 access = build_wfl_node (access);
8745 tree access0_wfl, cn;
8747 maybe_build_thisn_access_method (from);
8748 access0_wfl = build_wfl_node (access0_identifier_node);
8749 cn = build_wfl_node (DECL_NAME (TYPE_NAME (from)));
8750 EXPR_WFL_LINECOL (access0_wfl) = lc;
8751 access = build_tree_list (NULL_TREE, access);
8752 access = build_method_invocation (access0_wfl, access);
8753 access = make_qualified_primary (cn, access, lc);
8756 /* If FROM isn't an inner class, that's fine, we've done enough.
8757 What we're looking for can be accessed from there. */
8758 from = DECL_CONTEXT (TYPE_NAME (from));
8761 from = TREE_TYPE (from);
8766 /* Build an access function to the this$<n> local to TYPE. NULL_TREE
8767 is returned if nothing needs to be generated. Otherwise, the method
8768 generated and a method decl is returned.
8770 NOTE: These generated methods should be declared in a class file
8771 attribute so that they can't be referred to directly. */
8774 maybe_build_thisn_access_method (tree type)
8776 tree mdecl, args, stmt, rtype;
8777 tree saved_current_function_decl;
8779 /* If TYPE is a top-level class, no access method is required.
8780 If there already is such an access method, bail out. */
8781 if (CLASS_ACCESS0_GENERATED_P (type) || !PURE_INNER_CLASS_TYPE_P (type))
8784 /* We generate the method. The method looks like:
8785 static <outer_of_type> access$0 (<type> inst$) { return inst$.this$<n>; }
8787 args = build_tree_list (inst_id, build_pointer_type (type));
8788 TREE_CHAIN (args) = end_params_node;
8789 rtype = build_pointer_type (TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))));
8790 mdecl = create_artificial_method (type, ACC_STATIC, rtype,
8791 access0_identifier_node, args);
8792 fix_method_argument_names (args, mdecl);
8793 layout_class_method (type, NULL_TREE, mdecl, NULL_TREE);
8794 stmt = build_current_thisn (type);
8795 stmt = make_qualified_primary (build_wfl_node (inst_id),
8796 build_wfl_node (stmt), 0);
8797 stmt = build_return (0, stmt);
8799 saved_current_function_decl = current_function_decl;
8800 start_artificial_method_body (mdecl);
8801 java_method_add_stmt (mdecl, stmt);
8802 end_artificial_method_body (mdecl);
8803 current_function_decl = saved_current_function_decl;
8805 CLASS_ACCESS0_GENERATED_P (type) = 1;
8810 /* Craft an correctly numbered `this$<n>'string. this$0 is used for
8811 the first level of innerclassing. this$1 for the next one, etc...
8812 This function can be invoked with TYPE to NULL, available and then
8813 has to count the parser context. */
8815 static GTY(()) tree saved_thisn;
8816 static GTY(()) tree saved_type;
8819 build_current_thisn (tree type)
8821 static int saved_i = -1;
8822 static int saved_type_i = 0;
8829 if (type == saved_type)
8833 for (i = -1, decl = DECL_CONTEXT (TYPE_NAME (type));
8834 decl; decl = DECL_CONTEXT (decl), i++)
8842 i = list_length (GET_CPC_LIST ())-2;
8847 sprintf (buffer, "this$%d", i);
8849 saved_thisn = get_identifier (buffer);
8853 /* Return the assignment to the hidden enclosing context `this$<n>'
8854 by the second incoming parameter to the innerclass constructor. The
8855 form used is `this.this$<n> = this$<n>;'. */
8858 build_thisn_assign (void)
8860 if (current_class && PURE_INNER_CLASS_TYPE_P (current_class))
8862 tree thisn = build_current_thisn (current_class);
8863 tree lhs = make_qualified_primary (build_wfl_node (this_identifier_node),
8864 build_wfl_node (thisn), 0);
8865 tree rhs = build_wfl_node (thisn);
8866 #ifdef USE_MAPPED_LOCATION
8867 SET_EXPR_LOCATION (lhs, input_location);
8869 EXPR_WFL_SET_LINECOL (lhs, input_line, 0);
8871 return build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (lhs), lhs, rhs);
8877 /* Building the synthetic `class$' used to implement the `.class' 1.1
8878 extension for non primitive types. This method looks like:
8880 static Class class$(String type) throws NoClassDefFoundError
8882 try {return (java.lang.Class.forName (String));}
8883 catch (ClassNotFoundException e) {
8884 throw new NoClassDefFoundError(e.getMessage());}
8887 static GTY(()) tree get_message_wfl;
8888 static GTY(()) tree type_parm_wfl;
8891 build_dot_class_method (tree class)
8893 #define BWF(S) build_wfl_node (get_identifier ((S)))
8894 #ifdef USE_MAPPED_LOCATION
8895 #define MQN(X,Y) make_qualified_name ((X), (Y), UNKNOWN_LOCATION)
8897 #define MQN(X,Y) make_qualified_name ((X), (Y), 0)
8899 tree args, tmp, saved_current_function_decl, mdecl, qual_name;
8900 tree stmt, throw_stmt;
8902 if (!get_message_wfl)
8904 get_message_wfl = build_wfl_node (get_identifier ("getMessage"));
8905 type_parm_wfl = build_wfl_node (get_identifier ("type$"));
8908 /* Build the arguments */
8909 args = build_tree_list (get_identifier ("type$"),
8910 build_pointer_type (string_type_node));
8911 TREE_CHAIN (args) = end_params_node;
8913 /* Build the qualified name java.lang.Class.forName */
8914 tmp = MQN (MQN (MQN (BWF ("java"),
8915 BWF ("lang")), BWF ("Class")), BWF ("forName"));
8917 /* Create the "class$" function */
8918 mdecl = create_artificial_method (class, ACC_STATIC,
8919 build_pointer_type (class_type_node),
8920 classdollar_identifier_node, args);
8921 qual_name = MQN (MQN (BWF ("java"), BWF ("lang")),
8922 BWF ("NoClassDefFoundError"));
8923 DECL_FUNCTION_THROWS (mdecl) = build_tree_list (NULL_TREE, qual_name);
8924 register_incomplete_type (JDEP_EXCEPTION, qual_name, NULL_TREE, NULL_TREE);
8925 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
8926 &TREE_VALUE (DECL_FUNCTION_THROWS (mdecl));
8928 /* We start by building the try block. We need to build:
8929 return (java.lang.Class.forName (type)); */
8930 stmt = build_method_invocation (tmp,
8931 build_tree_list (NULL_TREE, type_parm_wfl));
8932 stmt = build_return (0, stmt);
8934 /* Now onto the catch block. We start by building the expression
8935 throwing a new exception: throw new NoClassDefFoundError (_.getMessage) */
8936 #ifdef USE_MAPPED_LOCATION
8937 throw_stmt = make_qualified_name (build_wfl_node (wpv_id),
8938 get_message_wfl, UNKNOWN_LOCATION);
8940 throw_stmt = make_qualified_name (build_wfl_node (wpv_id),
8941 get_message_wfl, 0);
8943 throw_stmt = build_method_invocation (throw_stmt, NULL_TREE);
8945 /* Build new NoClassDefFoundError (_.getMessage) */
8946 throw_stmt = build_new_invocation
8947 (build_wfl_node (get_identifier ("NoClassDefFoundError")),
8948 build_tree_list (build_pointer_type (string_type_node), throw_stmt));
8950 /* Build the throw, (it's too early to use BUILD_THROW) */
8951 throw_stmt = build1 (THROW_EXPR, NULL_TREE, throw_stmt);
8953 /* Encapsulate STMT in a try block. The catch clause executes THROW_STMT */
8954 qual_name = MQN (MQN (BWF ("java"), BWF ("lang")),
8955 BWF ("ClassNotFoundException"));
8956 stmt = encapsulate_with_try_catch (0, qual_name, stmt, throw_stmt);
8958 fix_method_argument_names (args, mdecl);
8959 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
8960 saved_current_function_decl = current_function_decl;
8961 start_artificial_method_body (mdecl);
8962 java_method_add_stmt (mdecl, stmt);
8963 end_artificial_method_body (mdecl);
8964 current_function_decl = saved_current_function_decl;
8965 TYPE_DOT_CLASS (class) = mdecl;
8971 build_dot_class_method_invocation (tree this_class, tree type)
8973 tree dot_class_method = TYPE_DOT_CLASS (this_class);
8976 if (TYPE_ARRAY_P (type))
8977 sig_id = build_java_signature (type);
8979 sig_id = DECL_NAME (TYPE_NAME (type));
8981 /* Ensure that the proper name separator is used */
8982 sig_id = unmangle_classname (IDENTIFIER_POINTER (sig_id),
8983 IDENTIFIER_LENGTH (sig_id));
8985 s = build_string (IDENTIFIER_LENGTH (sig_id),
8986 IDENTIFIER_POINTER (sig_id));
8987 t = build_method_invocation (build_wfl_node (DECL_NAME (dot_class_method)),
8988 build_tree_list (NULL_TREE, s));
8989 if (DECL_CONTEXT (dot_class_method) != this_class)
8991 tree class_name = DECL_NAME (TYPE_NAME (DECL_CONTEXT (dot_class_method)));
8992 t = make_qualified_primary (build_wfl_node (class_name), t, 0);
8997 /* This section of the code deals with constructor. */
8999 /* Craft a body for default constructor. Patch existing constructor
9000 bodies with call to super() and field initialization statements if
9004 fix_constructors (tree mdecl)
9006 tree iii; /* Instance Initializer Invocation */
9007 tree *bodyp = &DECL_FUNCTION_BODY (mdecl);
9008 tree thisn_assign, compound = NULL_TREE;
9009 tree class_type = DECL_CONTEXT (mdecl);
9011 if (DECL_FIXED_CONSTRUCTOR_P (mdecl))
9013 DECL_FIXED_CONSTRUCTOR_P (mdecl) = 1;
9017 /* It is an error for the compiler to generate a default
9018 constructor if the superclass doesn't have a constructor that
9019 takes no argument, or the same args for an anonymous class */
9020 if (verify_constructor_super (mdecl))
9022 tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (class_type));
9023 tree save = DECL_NAME (mdecl);
9024 const char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
9025 DECL_NAME (mdecl) = DECL_NAME (sclass_decl);
9027 (lookup_cl (TYPE_NAME (class_type)),
9028 "No constructor matching %qs found in class %qs",
9029 lang_printable_name (mdecl, 2), n);
9030 DECL_NAME (mdecl) = save;
9033 /* The constructor body must be crafted by hand. It's the
9034 constructor we defined when we realize we didn't have the
9035 CLASSNAME() constructor */
9036 start_artificial_method_body (mdecl);
9038 /* Insert an assignment to the this$<n> hidden field, if
9040 if ((thisn_assign = build_thisn_assign ()))
9041 java_method_add_stmt (mdecl, thisn_assign);
9043 /* We don't generate a super constructor invocation if we're
9044 compiling java.lang.Object. build_super_invocation takes care
9046 java_method_add_stmt (mdecl, build_super_invocation (mdecl));
9049 if ((iii = build_instinit_invocation (class_type)))
9050 java_method_add_stmt (mdecl, iii);
9052 end_artificial_method_body (mdecl);
9054 /* Search for an explicit constructor invocation */
9058 int invokes_this = 0;
9059 tree main_block = BLOCK_EXPR_BODY (*bodyp);
9064 switch (TREE_CODE (body))
9067 found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
9068 if (CALL_THIS_CONSTRUCTOR_P (body))
9072 case EXPR_WITH_FILE_LOCATION:
9073 bodyp = &TREE_OPERAND (body, 0);
9076 bodyp = &BLOCK_EXPR_BODY (body);
9084 /* Generate the assignment to this$<n>, if necessary */
9085 if ((thisn_assign = build_thisn_assign ()))
9086 compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
9088 /* The constructor is missing an invocation of super() */
9090 compound = add_stmt_to_compound (compound, NULL_TREE,
9091 build_super_invocation (mdecl));
9092 /* Explicit super() invocation should take place before the
9093 instance initializer blocks. */
9096 compound = add_stmt_to_compound (compound, NULL_TREE, *bodyp);
9097 *bodyp = build_java_empty_stmt ();
9100 DECL_INIT_CALLS_THIS (mdecl) = invokes_this;
9102 /* Insert the instance initializer block right after. */
9103 if (!invokes_this && (iii = build_instinit_invocation (class_type)))
9104 compound = add_stmt_to_compound (compound, NULL_TREE, iii);
9106 /* Fix the constructor main block if we're adding extra stmts */
9109 compound = add_stmt_to_compound (compound, NULL_TREE,
9110 BLOCK_EXPR_BODY (main_block));
9111 BLOCK_EXPR_BODY (main_block) = compound;
9116 /* Browse constructors in the super class, searching for a constructor
9117 that doesn't take any argument. Return 0 if one is found, 1
9118 otherwise. If the current class is an anonymous inner class, look
9119 for something that has the same signature. */
9122 verify_constructor_super (tree mdecl)
9124 tree class = CLASSTYPE_SUPER (current_class);
9125 int super_inner = PURE_INNER_CLASS_TYPE_P (class);
9131 if (ANONYMOUS_CLASS_P (current_class))
9133 tree mdecl_arg_type;
9134 SKIP_THIS_AND_ARTIFICIAL_PARMS (mdecl_arg_type, mdecl);
9135 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
9136 if (DECL_CONSTRUCTOR_P (sdecl))
9139 tree arg_type = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
9141 arg_type = TREE_CHAIN (arg_type);
9142 for (m_arg_type = mdecl_arg_type;
9143 (arg_type != end_params_node
9144 && m_arg_type != end_params_node);
9145 arg_type = TREE_CHAIN (arg_type),
9146 m_arg_type = TREE_CHAIN (m_arg_type))
9147 if (!valid_method_invocation_conversion_p
9148 (TREE_VALUE (arg_type),
9149 TREE_VALUE (m_arg_type)))
9152 if (arg_type == end_params_node && m_arg_type == end_params_node)
9158 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
9160 tree arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
9162 arg = TREE_CHAIN (arg);
9163 if (DECL_CONSTRUCTOR_P (sdecl) && arg == end_params_node)
9170 /* Generate code for all context remembered for code generation. */
9172 static GTY(()) tree reversed_class_list;
9174 java_expand_classes (void)
9176 int save_error_count = 0;
9177 static struct parser_ctxt *cur_ctxp = NULL;
9178 location_t save_location;
9180 java_parse_abort_on_error ();
9181 if (!(ctxp = ctxp_for_generation))
9183 java_layout_classes ();
9184 java_parse_abort_on_error ();
9185 save_location = input_location;
9187 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9190 for (current = cur_ctxp->class_list;
9192 current = TREE_CHAIN (current))
9193 gen_indirect_dispatch_tables (TREE_TYPE (current));
9196 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9199 input_location = ctxp->file_start_location;
9200 lang_init_source (2); /* Error msgs have method prototypes */
9201 java_complete_expand_classes (); /* Complete and expand classes */
9202 java_parse_abort_on_error ();
9204 input_location = save_location;
9206 /* Find anonymous classes and expand their constructor. This extra pass is
9207 necessary because the constructor itself is only generated when the
9208 method in which it is defined is expanded. */
9209 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9213 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9215 output_class = current_class = TREE_TYPE (current);
9216 if (ANONYMOUS_CLASS_P (current_class))
9219 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9221 if (DECL_CONSTRUCTOR_P (d))
9223 java_complete_expand_method (d);
9224 break; /* There is only one constructor. */
9231 /* Expanding the constructors of anonymous classes generates access
9232 methods. Scan all the methods looking for null DECL_RESULTs --
9233 this will be the case if a method hasn't been expanded. */
9234 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9238 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9241 output_class = current_class = TREE_TYPE (current);
9242 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9244 if (DECL_RESULT (d) == NULL_TREE)
9245 java_complete_expand_method (d);
9250 /* ??? Instead of all this we could iterate around the list of
9251 classes until there were no more un-expanded methods. It would
9252 take a little longer -- one pass over the whole list of methods
9253 -- but it would be simpler. Like this: */
9256 int something_changed;
9260 something_changed = 0;
9261 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9265 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9268 output_class = current_class = TREE_TYPE (current);
9269 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
9271 if (DECL_RESULT (d) == NULL_TREE)
9273 something_changed = 1;
9274 java_complete_expand_method (d);
9280 while (something_changed);
9284 /* If we've found error at that stage, don't try to generate
9285 anything, unless we're emitting xrefs or checking the syntax only
9286 (but not using -fsyntax-only for the purpose of generating
9288 if (java_error_count && !flag_emit_xref
9289 && (!flag_syntax_only && !flag_emit_class_files))
9292 /* Now things are stable, go for generation of the class data. */
9294 /* We pessimistically marked all methods and fields external until
9295 we knew what set of classes we were planning to compile. Now mark
9296 those that will be generated locally as not external. */
9297 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9301 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9302 java_mark_class_local (TREE_TYPE (current));
9305 /* Compile the classes. */
9306 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9309 reversed_class_list = NULL;
9313 /* We write out the classes in reverse order. This ensures that
9314 inner classes are written before their containing classes,
9315 which is important for parallel builds. Otherwise, the
9316 class file for the outer class may be found, but the class
9317 file for the inner class may not be present. In that
9318 situation, the compiler cannot fall back to the original
9319 source, having already read the outer class, so we must
9320 prevent that situation. */
9321 for (current = ctxp->class_list;
9323 current = TREE_CHAIN (current))
9325 = tree_cons (NULL_TREE, current, reversed_class_list);
9327 for (current = reversed_class_list;
9329 current = TREE_CHAIN (current))
9331 output_class = current_class = TREE_TYPE (TREE_VALUE (current));
9332 if (flag_emit_class_files)
9333 write_classfile (current_class);
9335 expand_xref (current_class);
9336 else if (! flag_syntax_only)
9337 java_expand_method_bodies (current_class);
9343 java_finish_classes (void)
9345 static struct parser_ctxt *cur_ctxp = NULL;
9346 for (cur_ctxp = ctxp_for_generation; cur_ctxp; cur_ctxp = cur_ctxp->next)
9350 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
9352 output_class = current_class = TREE_TYPE (current);
9358 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
9359 a tree list node containing RIGHT. Fore coming RIGHTs will be
9360 chained to this hook. LOCATION contains the location of the
9361 separating `.' operator. */
9364 make_qualified_primary (tree primary, tree right, int location)
9368 if (TREE_CODE (primary) != EXPR_WITH_FILE_LOCATION)
9369 wfl = build_wfl_wrap (primary, location);
9373 /* If wfl wasn't qualified, we build a first anchor */
9374 if (!EXPR_WFL_QUALIFICATION (wfl))
9375 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (wfl, NULL_TREE);
9378 /* And chain them */
9379 EXPR_WFL_LINECOL (right) = location;
9380 chainon (EXPR_WFL_QUALIFICATION (wfl), build_tree_list (right, NULL_TREE));
9381 PRIMARY_P (wfl) = 1;
9385 /* Simple merge of two name separated by a `.' */
9388 merge_qualified_name (tree left, tree right)
9391 if (!left && !right)
9400 obstack_grow (&temporary_obstack, IDENTIFIER_POINTER (left),
9401 IDENTIFIER_LENGTH (left));
9402 obstack_1grow (&temporary_obstack, '.');
9403 obstack_grow0 (&temporary_obstack, IDENTIFIER_POINTER (right),
9404 IDENTIFIER_LENGTH (right));
9405 node = get_identifier (obstack_base (&temporary_obstack));
9406 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
9407 QUALIFIED_P (node) = 1;
9411 /* Merge the two parts of a qualified name into LEFT. Set the
9412 location information of the resulting node to LOCATION, usually
9413 inherited from the location information of the `.' operator. */
9416 make_qualified_name (tree left, tree right,
9417 #ifdef USE_MAPPED_LOCATION
9418 source_location location
9424 #ifdef USE_COMPONENT_REF
9425 tree node = build3 (COMPONENT_REF, NULL_TREE, left, right, NULL_TREE);
9426 SET_EXPR_LOCATION (node, location);
9429 tree left_id = EXPR_WFL_NODE (left);
9430 tree right_id = EXPR_WFL_NODE (right);
9433 merge = merge_qualified_name (left_id, right_id);
9435 /* Left wasn't qualified and is now qualified */
9436 #ifdef USE_MAPPED_LOCATION
9437 if (!QUALIFIED_P (left_id))
9439 tree wfl = build_expr_wfl (left_id, EXPR_LOCATION (left));
9440 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
9443 wfl = build_expr_wfl (right_id, location);
9445 if (!QUALIFIED_P (left_id))
9447 tree wfl = build_expr_wfl (left_id, ctxp->filename, 0, 0);
9448 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (left);
9449 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
9452 wfl = build_expr_wfl (right_id, ctxp->filename, 0, 0);
9453 EXPR_WFL_LINECOL (wfl) = location;
9455 chainon (EXPR_WFL_QUALIFICATION (left), build_tree_list (wfl, NULL_TREE));
9456 EXPR_WFL_NODE (left) = merge;
9461 /* Extract the last identifier component of the qualified in WFL. The
9462 last identifier is removed from the linked list */
9465 cut_identifier_in_qualified (tree wfl)
9468 tree previous = NULL_TREE;
9469 for (q = EXPR_WFL_QUALIFICATION (wfl); ; previous = q, q = TREE_CHAIN (q))
9470 if (!TREE_CHAIN (q))
9473 /* Operating on a non qualified qualified WFL. */
9476 TREE_CHAIN (previous) = NULL_TREE;
9477 return TREE_PURPOSE (q);
9481 /* Resolve the expression name NAME. Return its decl. */
9484 resolve_expression_name (tree id, tree *orig)
9486 tree name = EXPR_WFL_NODE (id);
9489 /* 6.5.5.1: Simple expression names */
9490 if (!PRIMARY_P (id) && !QUALIFIED_P (name))
9492 /* 15.13.1: NAME can appear within the scope of a local variable
9494 if ((decl = IDENTIFIER_LOCAL_VALUE (name)))
9497 /* 15.13.1: NAME can appear within a class declaration */
9500 decl = lookup_field_wrapper (current_class, name);
9503 tree access = NULL_TREE;
9504 int fs = FIELD_STATIC (decl);
9506 /* If we're accessing an outer scope local alias, make
9507 sure we change the name of the field we're going to
9509 if (FIELD_LOCAL_ALIAS_USED (decl))
9510 name = DECL_NAME (decl);
9512 check_deprecation (id, decl);
9514 /* Instance variable (8.3.1.1) can't appear within
9515 static method, static initializer or initializer for
9516 a static variable. */
9517 if (!fs && METHOD_STATIC (current_function_decl))
9519 static_ref_err (id, name, current_class);
9520 return error_mark_node;
9522 /* Instance variables can't appear as an argument of
9523 an explicit constructor invocation */
9524 if (!fs && ctxp->explicit_constructor_p
9525 && !enclosing_context_p (DECL_CONTEXT (decl), current_class))
9528 (id, "Can't reference %qs before the superclass constructor has been called", IDENTIFIER_POINTER (name));
9529 return error_mark_node;
9532 /* If we're processing an inner class and we're trying
9533 to access a field belonging to an outer class, build
9534 the access to the field */
9535 if (!fs && outer_field_access_p (current_class, decl))
9537 if (CLASS_STATIC (TYPE_NAME (current_class)))
9539 static_ref_err (id, DECL_NAME (decl), current_class);
9540 return error_mark_node;
9542 access = build_outer_field_access (id, decl);
9548 /* Otherwise build what it takes to access the field */
9549 access = build_field_ref ((fs ? NULL_TREE : current_this),
9550 DECL_CONTEXT (decl), name);
9552 access = maybe_build_class_init_for_field (decl, access);
9553 /* We may be asked to save the real field access node */
9556 /* Last check: can we access the field? */
9557 if (not_accessible_p (current_class, decl, NULL_TREE, 0))
9559 not_accessible_field_error (id, decl);
9560 return error_mark_node;
9562 /* And we return what we got */
9565 /* Fall down to error report on undefined variable */
9568 /* 6.5.5.2 Qualified Expression Names */
9573 qualify_ambiguous_name (id);
9574 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
9575 /* 15.10.2: Accessing Superclass Members using super */
9576 return resolve_field_access (id, orig, NULL);
9579 /* We've got an error here */
9580 if (INNER_CLASS_TYPE_P (current_class))
9581 parse_error_context (id,
9582 "Local variable %qs can't be accessed from within the inner class %qs unless it is declared final",
9583 IDENTIFIER_POINTER (name),
9584 IDENTIFIER_POINTER (DECL_NAME
9585 (TYPE_NAME (current_class))));
9587 parse_error_context (id, "Undefined variable %qs",
9588 IDENTIFIER_POINTER (name));
9590 return error_mark_node;
9594 static_ref_err (tree wfl, tree field_id, tree class_type)
9598 "Can't make a static reference to nonstatic variable %qs in class %qs",
9599 IDENTIFIER_POINTER (field_id),
9600 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class_type))));
9603 /* 15.10.1 Field Access Using a Primary and/or Expression Name.
9604 We return something suitable to generate the field access. We also
9605 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
9606 recipient's address can be null. */
9609 resolve_field_access (tree qual_wfl, tree *field_decl, tree *field_type)
9613 tree decl = NULL_TREE, where_found, type_found;
9615 if (resolve_qualified_expression_name (qual_wfl, &decl,
9616 &where_found, &type_found))
9617 return error_mark_node;
9619 /* Resolve the LENGTH field of an array here */
9620 if (DECL_P (decl) && DECL_NAME (decl) == length_identifier_node
9621 && type_found && TYPE_ARRAY_P (type_found)
9622 && ! flag_emit_class_files && ! flag_emit_xref)
9624 tree length = build_java_array_length_access (where_found);
9627 /* In case we're dealing with a static array, we need to
9628 initialize its class before the array length can be fetched.
9629 It's also a good time to create a DECL_RTL for the field if
9630 none already exists, otherwise if the field was declared in a
9631 class found in an external file and hasn't been (and won't
9632 be) accessed for its value, none will be created. */
9633 if (TREE_CODE (where_found) == VAR_DECL && FIELD_STATIC (where_found))
9635 build_static_field_ref (where_found);
9636 field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
9639 /* We might have been trying to resolve field.method(). In which
9640 case, the resolution is over and decl is the answer */
9641 else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
9643 else if (JDECL_P (decl))
9646 type_found = DECL_CONTEXT (decl);
9647 is_static = FIELD_STATIC (decl);
9648 field_ref = build_field_ref ((is_static && !flag_emit_xref?
9649 NULL_TREE : where_found),
9650 type_found, DECL_NAME (decl));
9651 if (field_ref == error_mark_node)
9652 return error_mark_node;
9654 field_ref = maybe_build_class_init_for_field (decl, field_ref);
9656 /* If we're looking at a static field, we may need to generate a
9657 class initialization for it. This can happen when the access
9658 looks like `field.ref', where `field' is a static field in an
9659 interface we implement. */
9660 if (!flag_emit_class_files
9662 && TREE_CODE (where_found) == VAR_DECL
9663 && FIELD_STATIC (where_found))
9665 build_static_field_ref (where_found);
9666 field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
9675 *field_type = (QUAL_DECL_TYPE (decl) ?
9676 QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
9680 /* If NODE is an access to a static field, strip out the class
9681 initialization part and return the field decl, otherwise, return
9685 extract_field_decl (tree node)
9687 if (TREE_CODE (node) == COMPOUND_EXPR)
9689 tree op1 = TREE_OPERAND (node, 1);
9690 if (TREE_CODE (op1) == COMPOUND_EXPR)
9692 tree call = TREE_OPERAND (op1, 0);
9693 if (TREE_CODE (call) == CALL_EXPR
9694 && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
9695 && (TREE_OPERAND (TREE_OPERAND (call, 0), 0)
9696 == soft_initclass_node))
9697 return TREE_OPERAND (op1, 1);
9699 else if (JDECL_P (op1))
9705 /* 6.5.5.2: Qualified Expression Names */
9708 resolve_qualified_expression_name (tree wfl, tree *found_decl,
9709 tree *where_found, tree *type_found)
9711 int from_type = 0; /* Field search initiated from a type */
9712 int from_super = 0, from_cast = 0, from_qualified_this = 0;
9713 int previous_call_static = 0;
9715 tree decl = NULL_TREE, type = NULL_TREE, q;
9716 /* For certain for of inner class instantiation */
9717 tree saved_current, saved_this;
9718 #define RESTORE_THIS_AND_CURRENT_CLASS \
9719 { current_class = saved_current; current_this = saved_this;}
9721 *type_found = *where_found = NULL_TREE;
9723 for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
9725 tree qual_wfl = QUAL_WFL (q);
9726 tree ret_decl; /* for EH checking */
9727 #ifdef USE_MAPPED_LOCATION
9728 source_location location; /* for EH checking */
9730 int location; /* for EH checking */
9733 /* 15.10.1 Field Access Using a Primary */
9734 switch (TREE_CODE (qual_wfl))
9737 case NEW_CLASS_EXPR:
9738 /* If the access to the function call is a non static field,
9739 build the code to access it. */
9740 if (JDECL_P (decl) && !FIELD_STATIC (decl))
9742 decl = maybe_access_field (decl, *where_found,
9743 DECL_CONTEXT (decl));
9744 if (decl == error_mark_node)
9748 /* And code for the function call */
9749 if (complete_function_arguments (qual_wfl))
9752 /* We might have to setup a new current class and a new this
9753 for the search of an inner class, relative to the type of
9754 a expression resolved as `decl'. The current values are
9755 saved and restored shortly after */
9756 saved_current = current_class;
9757 saved_this = current_this;
9759 && (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
9760 || from_qualified_this))
9762 /* If we still have `from_qualified_this', we have the form
9763 <T>.this.f() and we need to build <T>.this */
9764 if (from_qualified_this)
9766 decl = build_access_to_thisn (current_class, type, 0);
9767 decl = java_complete_tree (decl);
9768 type = TREE_TYPE (TREE_TYPE (decl));
9770 current_class = type;
9771 current_this = decl;
9772 from_qualified_this = 0;
9775 if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
9776 CALL_USING_SUPER (qual_wfl) = 1;
9777 #ifdef USE_MAPPED_LOCATION
9778 location = (TREE_CODE (qual_wfl) == CALL_EXPR
9779 ? EXPR_LOCATION (TREE_OPERAND (qual_wfl, 0))
9780 : UNKNOWN_LOCATION);
9782 location = (TREE_CODE (qual_wfl) == CALL_EXPR ?
9783 EXPR_WFL_LINECOL (TREE_OPERAND (qual_wfl, 0)) : 0);
9785 *where_found = patch_method_invocation (qual_wfl, decl, type,
9787 &is_static, &ret_decl);
9789 if (*where_found == error_mark_node)
9791 RESTORE_THIS_AND_CURRENT_CLASS;
9794 *type_found = type = QUAL_DECL_TYPE (*where_found);
9796 *where_found = force_evaluation_order (*where_found);
9798 /* If we're creating an inner class instance, check for that
9799 an enclosing instance is in scope */
9800 if (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
9801 && INNER_ENCLOSING_SCOPE_CHECK (type))
9804 (qual_wfl, "No enclosing instance for inner class %qs is in scope%s",
9805 lang_printable_name (type, 0),
9806 (!current_this ? "" :
9807 "; an explicit one must be provided when creating this inner class"));
9808 RESTORE_THIS_AND_CURRENT_CLASS;
9812 /* In case we had to change then to resolve a inner class
9813 instantiation using a primary qualified by a `new' */
9814 RESTORE_THIS_AND_CURRENT_CLASS;
9816 #ifdef USE_MAPPED_LOCATION
9817 if (location != UNKNOWN_LOCATION)
9822 tree arguments = NULL_TREE;
9823 if (TREE_CODE (qual_wfl) == CALL_EXPR
9824 && TREE_OPERAND (qual_wfl, 1) != NULL_TREE)
9825 arguments = TREE_VALUE (TREE_OPERAND (qual_wfl, 1));
9826 check_thrown_exceptions (location, ret_decl, arguments);
9829 /* If the previous call was static and this one is too,
9830 build a compound expression to hold the two (because in
9831 that case, previous function calls aren't transported as
9832 forcoming function's argument. */
9833 if (previous_call_static && is_static)
9835 /* We must set CAN_COMPLETE_NORMALLY for the first call
9836 since it is done nowhere else. */
9837 CAN_COMPLETE_NORMALLY (decl) = 1;
9838 decl = build2 (COMPOUND_EXPR, TREE_TYPE (*where_found),
9839 decl, *where_found);
9840 TREE_SIDE_EFFECTS (decl) = 1;
9844 previous_call_static = is_static;
9845 decl = *where_found;
9850 case NEW_ARRAY_EXPR:
9851 case NEW_ANONYMOUS_ARRAY_EXPR:
9852 *where_found = decl = java_complete_tree (qual_wfl);
9853 if (decl == error_mark_node)
9855 *type_found = type = QUAL_DECL_TYPE (decl);
9859 *where_found = decl = java_complete_tree (qual_wfl);
9860 if (decl == error_mark_node)
9862 *type_found = type = QUAL_DECL_TYPE (decl);
9866 case CONDITIONAL_EXPR:
9869 *where_found = decl = java_complete_tree (qual_wfl);
9870 if (decl == error_mark_node)
9872 *type_found = type = QUAL_DECL_TYPE (decl);
9876 /* If the access to the function call is a non static field,
9877 build the code to access it. */
9878 if (JDECL_P (decl) && !FIELD_STATIC (decl))
9880 decl = maybe_access_field (decl, *where_found, type);
9881 if (decl == error_mark_node)
9884 /* And code for the array reference expression */
9885 decl = java_complete_tree (qual_wfl);
9886 if (decl == error_mark_node)
9888 type = QUAL_DECL_TYPE (decl);
9892 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
9894 if ((type = patch_string (decl)))
9896 *where_found = QUAL_RESOLUTION (q) = decl;
9897 *type_found = type = TREE_TYPE (decl);
9901 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
9903 *where_found = QUAL_RESOLUTION (q) = decl;
9904 *type_found = type = TREE_TYPE (decl);
9908 /* Fix for -Wall Just go to the next statement. Don't
9913 /* If we fall here, we weren't processing a (static) function call. */
9914 previous_call_static = 0;
9916 /* It can be the keyword THIS */
9917 if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
9918 && EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
9923 (wfl, "Keyword %<this%> used outside allowed context");
9926 if (ctxp->explicit_constructor_p
9927 && type == current_class)
9929 parse_error_context (wfl, "Can't reference %<this%> before the superclass constructor has been called");
9932 /* We have to generate code for intermediate access */
9933 if (!from_type || TREE_TYPE (TREE_TYPE (current_this)) == type)
9935 *where_found = decl = current_this;
9936 *type_found = type = QUAL_DECL_TYPE (decl);
9938 /* We're trying to access the this from somewhere else. Make sure
9939 it's allowed before doing so. */
9942 if (!enclosing_context_p (type, current_class))
9944 char *p = xstrdup (lang_printable_name (type, 0));
9945 parse_error_context (qual_wfl, "Can't use variable %<%s.this%>: type %qs isn't an outer type of type %qs",
9947 lang_printable_name (current_class, 0));
9951 from_qualified_this = 1;
9952 /* If there's nothing else after that, we need to
9953 produce something now, otherwise, the section of the
9954 code that needs to produce <T>.this will generate
9955 what is necessary. */
9956 if (!TREE_CHAIN (q))
9958 decl = build_access_to_thisn (current_class, type, 0);
9959 *where_found = decl = java_complete_tree (decl);
9960 *type_found = type = TREE_TYPE (decl);
9968 /* 15.10.2 Accessing Superclass Members using SUPER */
9969 if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
9970 && EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
9973 /* Check on the restricted use of SUPER */
9974 if (METHOD_STATIC (current_function_decl)
9975 || current_class == object_type_node)
9978 (wfl, "Keyword %<super%> used outside allowed context");
9981 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
9982 node = build_cast (EXPR_WFL_LINECOL (qual_wfl),
9983 CLASSTYPE_SUPER (current_class),
9984 build_this (EXPR_WFL_LINECOL (qual_wfl)));
9985 *where_found = decl = java_complete_tree (node);
9986 if (decl == error_mark_node)
9988 *type_found = type = QUAL_DECL_TYPE (decl);
9989 from_super = from_type = 1;
9993 /* 15.13.1: Can't search for field name in packages, so we
9994 assume a variable/class name was meant. */
9995 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
9998 if ((decl = resolve_package (wfl, &q, &name)))
10001 *where_found = decl;
10003 check_pkg_class_access (DECL_NAME (decl), qual_wfl, true, NULL);
10005 /* We want to be absolutely sure that the class is laid
10006 out. We're going to search something inside it. */
10007 *type_found = type = TREE_TYPE (decl);
10008 layout_class (type);
10011 /* Fix them all the way down, if any are left. */
10014 list = TREE_CHAIN (q);
10017 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (list)) = 0;
10018 list = TREE_CHAIN (list);
10024 if (from_super || from_cast)
10025 parse_error_context
10026 ((from_cast ? qual_wfl : wfl),
10027 "No variable %qs defined in class %qs",
10028 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10029 lang_printable_name (type, 0));
10031 parse_error_context
10032 (qual_wfl, "Undefined variable or class name: %qs",
10033 IDENTIFIER_POINTER (name));
10038 /* We have a type name. It's been already resolved when the
10039 expression was qualified. */
10040 else if (RESOLVE_TYPE_NAME_P (qual_wfl) && QUAL_RESOLUTION (q))
10042 decl = QUAL_RESOLUTION (q);
10044 /* Sneak preview. If next we see a `new', we're facing a
10045 qualification which resulted in a type being selected
10046 instead of a field. Report the error. */
10048 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR)
10050 parse_error_context (qual_wfl, "Undefined variable %qs",
10051 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10055 check_pkg_class_access (DECL_NAME (decl), qual_wfl, true, NULL);
10057 check_deprecation (qual_wfl, decl);
10059 type = TREE_TYPE (decl);
10062 /* We resolve an expression name */
10065 tree field_decl = NULL_TREE;
10067 /* If there exists an early resolution, use it. That occurs
10068 only once and we know that there are more things to
10069 come. Don't do that when processing something after SUPER
10070 (we need more thing to be put in place below */
10071 if (!from_super && QUAL_RESOLUTION (q))
10073 decl = QUAL_RESOLUTION (q);
10076 if (TREE_CODE (decl) == FIELD_DECL && !FIELD_STATIC (decl))
10079 *where_found = current_this;
10082 static_ref_err (qual_wfl, DECL_NAME (decl),
10086 if (outer_field_access_p (current_class, decl))
10087 decl = build_outer_field_access (qual_wfl, decl);
10091 *where_found = TREE_TYPE (decl);
10092 if (TREE_CODE (*where_found) == POINTER_TYPE)
10093 *where_found = TREE_TYPE (*where_found);
10098 /* Report and error if we're using a numerical literal as a
10099 qualifier. It can only be an INTEGER_CST. */
10100 else if (TREE_CODE (qual_wfl) == INTEGER_CST)
10102 parse_error_context
10103 (wfl, "Can't use type %qs as a qualifier",
10104 lang_printable_name (TREE_TYPE (qual_wfl), 0));
10108 /* We have to search for a field, knowing the type of its
10109 container. The flag FROM_TYPE indicates that we resolved
10110 the last member of the expression as a type name, which
10111 means that for the resolution of this field, we'll look
10112 for other errors than if it was resolved as a member of
10117 tree field_decl_type; /* For layout */
10119 if (!from_type && !JREFERENCE_TYPE_P (type))
10121 parse_error_context
10122 (qual_wfl, "Attempt to reference field %qs in %<%s %s%>",
10123 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10124 lang_printable_name (type, 0),
10125 IDENTIFIER_POINTER (DECL_NAME (decl)));
10129 field_decl = lookup_field_wrapper (type,
10130 EXPR_WFL_NODE (qual_wfl));
10132 /* Maybe what we're trying to access to is an inner
10133 class, only if decl is a TYPE_DECL. */
10134 if (!field_decl && TREE_CODE (decl) == TYPE_DECL)
10136 tree ptr, inner_decl;
10138 BUILD_PTR_FROM_NAME (ptr, EXPR_WFL_NODE (qual_wfl));
10139 inner_decl = resolve_class (decl, ptr, NULL_TREE, qual_wfl);
10142 check_inner_class_access (inner_decl, decl, qual_wfl);
10143 type = TREE_TYPE (inner_decl);
10150 if (field_decl == NULL_TREE)
10152 parse_error_context
10153 (qual_wfl, "No variable %qs defined in type %qs",
10154 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
10155 GET_TYPE_NAME (type));
10158 if (field_decl == error_mark_node)
10161 /* Layout the type of field_decl, since we may need
10162 it. Don't do primitive types or loaded classes. The
10163 situation of non primitive arrays may not handled
10164 properly here. FIXME */
10165 if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
10166 field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
10168 field_decl_type = TREE_TYPE (field_decl);
10169 if (!JPRIMITIVE_TYPE_P (field_decl_type)
10170 && !CLASS_LOADED_P (field_decl_type)
10171 && !TYPE_ARRAY_P (field_decl_type))
10172 resolve_and_layout (field_decl_type, NULL_TREE);
10174 /* Check on accessibility here */
10175 if (not_accessible_p (current_class, field_decl,
10176 *type_found, from_super))
10177 return not_accessible_field_error (qual_wfl,field_decl);
10178 check_deprecation (qual_wfl, field_decl);
10180 /* There are things to check when fields are accessed
10181 from type. There are no restrictions on a static
10182 declaration of the field when it is accessed from an
10184 is_static = FIELD_STATIC (field_decl);
10185 if (!from_super && from_type
10186 && !TYPE_INTERFACE_P (type)
10188 && (current_function_decl
10189 && METHOD_STATIC (current_function_decl)))
10191 static_ref_err (qual_wfl, EXPR_WFL_NODE (qual_wfl), type);
10194 from_cast = from_super = 0;
10196 /* It's an access from a type but it isn't static, we
10197 make it relative to `this'. */
10198 if (!is_static && from_type)
10199 decl = current_this;
10201 /* If we need to generate something to get a proper
10202 handle on what this field is accessed from, do it
10206 decl = maybe_access_field (decl, *where_found, *type_found);
10207 if (decl == error_mark_node)
10211 /* We want to keep the location were found it, and the type
10213 *where_found = decl;
10214 *type_found = type;
10216 /* Generate the correct expression for field access from
10218 if (from_qualified_this)
10220 field_decl = build_outer_field_access (qual_wfl, field_decl);
10221 from_qualified_this = 0;
10224 /* This is the decl found and eventually the next one to
10229 type = QUAL_DECL_TYPE (decl);
10231 /* Sneak preview. If decl is qualified by a `new', report
10232 the error here to be accurate on the peculiar construct */
10234 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR
10235 && !JREFERENCE_TYPE_P (type))
10237 parse_error_context (qual_wfl, "Attempt to reference field %<new%> in a %qs",
10238 lang_printable_name (type, 0));
10242 /* `q' might have changed due to a after package resolution
10243 re-qualification */
10247 *found_decl = decl;
10251 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
10252 can't be accessed from REFERENCE (a record type). If MEMBER
10253 features a protected access, we then use WHERE which, if non null,
10254 holds the type of MEMBER's access that is checked against
10255 6.6.2.1. This function should be used when decl is a field or a
10259 not_accessible_p (tree reference, tree member, tree where, int from_super)
10261 int access_flag = get_access_flags_from_decl (member);
10262 bool is_static = false;
10264 if (TREE_CODE (member) == FIELD_DECL ||
10265 TREE_CODE (member) == VAR_DECL)
10266 is_static = FIELD_STATIC (member);
10268 is_static = METHOD_STATIC (member);
10270 /* Access always granted for members declared public */
10271 if (access_flag & ACC_PUBLIC)
10274 /* Check access on protected members */
10275 if (access_flag & ACC_PROTECTED)
10277 /* Access granted if it occurs from within the package
10278 containing the class in which the protected member is
10280 if (class_in_current_package (DECL_CONTEXT (member)))
10283 /* If accessed with the form `super.member', then access is granted */
10287 /* If WHERE is active, access was made through a qualifier. For
10288 non-static members, access is granted if the type of the qualifier
10289 is or is a sublass of the type the access is made from (6.6.2.1.) */
10290 if (where && !is_static)
10294 if (inherits_from_p (where, reference))
10296 if (INNER_CLASS_TYPE_P (reference))
10297 reference = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (reference)));
10304 /* Otherwise, access is granted if occurring from within the class
10305 where member is declared, or a subclass of it. */
10308 if (inherits_from_p (reference, DECL_CONTEXT (member)))
10310 if (INNER_CLASS_TYPE_P (reference))
10311 reference = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (reference)));
10318 /* Check access on private members. Access is granted only if it
10319 occurs from within the class in which it is declared -- that does
10320 it for innerclasses too. */
10321 if (access_flag & ACC_PRIVATE)
10323 if (reference == DECL_CONTEXT (member) ||
10324 common_enclosing_context_p (DECL_CONTEXT (member), reference))
10329 /* Default access is permitted only when occurring from within the
10330 package in which the context (MEMBER) is declared. */
10331 return !class_in_current_package (DECL_CONTEXT (member));
10334 /* Test deprecated decl access. */
10336 check_deprecation (tree wfl, tree decl)
10341 if (! warn_deprecated)
10344 /* We want to look at the element type of arrays here, so we strip
10345 all surrounding array types. */
10346 if (TYPE_ARRAY_P (TREE_TYPE (decl)))
10348 elt = TREE_TYPE (decl);
10349 while (TYPE_ARRAY_P (elt))
10350 elt = TYPE_ARRAY_ELEMENT (elt);
10351 /* We'll end up with a pointer type, so we use TREE_TYPE to go
10353 decl = TYPE_NAME (TREE_TYPE (elt));
10355 file = DECL_SOURCE_FILE (decl);
10357 /* Complain if the field is deprecated and the file it was defined
10358 in isn't compiled at the same time the file which contains its
10360 if (DECL_DEPRECATED (decl)
10361 && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
10364 switch (TREE_CODE (decl))
10366 case FUNCTION_DECL:
10374 parse_warning_context (wfl, "The class %qs has been deprecated",
10375 IDENTIFIER_POINTER (DECL_NAME (decl)));
10380 /* Don't issue a message if the context as been deprecated as a
10382 if (! CLASS_DEPRECATED (TYPE_NAME (DECL_CONTEXT (decl))))
10383 parse_warning_context
10384 (wfl, "The %s %qs in class %qs has been deprecated",
10385 the, lang_printable_name (decl, 0),
10386 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
10390 /* Returns 1 if class was declared in the current package, 0 otherwise */
10392 static GTY(()) tree cicp_cache;
10394 class_in_current_package (tree class)
10396 int qualified_flag;
10399 if (cicp_cache == class)
10402 qualified_flag = QUALIFIED_P (DECL_NAME (TYPE_NAME (class)));
10404 /* If the current package is empty and the name of CLASS is
10405 qualified, class isn't in the current package. If there is a
10406 current package and the name of the CLASS is not qualified, class
10407 isn't in the current package */
10408 if ((!ctxp->package && qualified_flag) || (ctxp->package && !qualified_flag))
10411 /* If there is not package and the name of CLASS isn't qualified,
10412 they belong to the same unnamed package */
10413 if (!ctxp->package && !qualified_flag)
10416 /* Compare the left part of the name of CLASS with the package name */
10417 split_qualified_name (&left, NULL, DECL_NAME (TYPE_NAME (class)));
10418 if (ctxp->package == left)
10420 cicp_cache = class;
10426 /* This function may generate code to access DECL from WHERE. This is
10427 done only if certain conditions meet. */
10430 maybe_access_field (tree decl, tree where, tree type)
10432 if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
10433 && !FIELD_STATIC (decl))
10434 decl = build_field_ref (where ? where : current_this,
10435 (type ? type : DECL_CONTEXT (decl)),
10440 /* Build a method invocation, by patching PATCH. If non NULL
10441 and according to the situation, PRIMARY and WHERE may be
10442 used. IS_STATIC is set to 1 if the invoked function is static. */
10445 patch_method_invocation (tree patch, tree primary, tree where, int from_super,
10446 int *is_static, tree *ret_decl)
10448 tree wfl = TREE_OPERAND (patch, 0);
10449 tree args = TREE_OPERAND (patch, 1);
10450 tree name = EXPR_WFL_NODE (wfl);
10452 int is_static_flag = 0;
10453 int is_super_init = 0;
10454 tree this_arg = NULL_TREE;
10455 int is_array_clone_call = 0;
10457 /* Should be overridden if everything goes well. Otherwise, if
10458 something fails, it should keep this value. It stop the
10459 evaluation of a bogus assignment. See java_complete_tree,
10460 MODIFY_EXPR: for the reasons why we sometimes want to keep on
10461 evaluating an assignment */
10462 TREE_TYPE (patch) = error_mark_node;
10464 /* Since lookup functions are messing with line numbers, save the
10466 java_parser_context_save_global ();
10468 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
10470 /* Resolution of qualified name, excluding constructors */
10471 if (QUALIFIED_P (name) && !CALL_CONSTRUCTOR_P (patch))
10473 tree identifier, identifier_wfl, type, resolved;
10474 /* Extract the last IDENTIFIER of the qualified
10475 expression. This is a wfl and we will use it's location
10476 data during error report. */
10477 identifier_wfl = cut_identifier_in_qualified (wfl);
10478 identifier = EXPR_WFL_NODE (identifier_wfl);
10480 /* Given the context, IDENTIFIER is syntactically qualified
10481 as a MethodName. We need to qualify what's before */
10482 qualify_ambiguous_name (wfl);
10483 resolved = resolve_field_access (wfl, NULL, NULL);
10485 if (TREE_CODE (resolved) == VAR_DECL && FIELD_STATIC (resolved)
10486 && FIELD_FINAL (resolved)
10487 && !inherits_from_p (DECL_CONTEXT (resolved), current_class)
10488 && !flag_emit_class_files && !flag_emit_xref)
10489 resolved = build_class_init (DECL_CONTEXT (resolved), resolved);
10491 if (resolved == error_mark_node)
10492 PATCH_METHOD_RETURN_ERROR ();
10494 type = GET_SKIP_TYPE (resolved);
10495 resolve_and_layout (type, NULL_TREE);
10497 if (JPRIMITIVE_TYPE_P (type))
10499 parse_error_context
10501 "Can't invoke a method on primitive type %qs",
10502 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
10503 PATCH_METHOD_RETURN_ERROR ();
10506 list = lookup_method_invoke (0, identifier_wfl, type, identifier, args);
10507 args = nreverse (args);
10509 /* We're resolving a call from a type */
10510 if (TREE_CODE (resolved) == TYPE_DECL)
10512 if (CLASS_INTERFACE (resolved))
10514 parse_error_context
10516 "Can't make static reference to method %qs in interface %qs",
10517 IDENTIFIER_POINTER (identifier),
10518 IDENTIFIER_POINTER (name));
10519 PATCH_METHOD_RETURN_ERROR ();
10521 if (list && !METHOD_STATIC (list))
10523 char *fct_name = xstrdup (lang_printable_name (list, 2));
10524 parse_error_context
10526 "Can't make static reference to method %<%s %s%> in class %qs",
10527 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
10528 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
10530 PATCH_METHOD_RETURN_ERROR ();
10534 this_arg = primary = resolved;
10536 if (TYPE_ARRAY_P (type) && identifier == get_identifier ("clone"))
10537 is_array_clone_call = 1;
10539 /* IDENTIFIER_WFL will be used to report any problem further */
10540 wfl = identifier_wfl;
10542 /* Resolution of simple names, names generated after a primary: or
10546 tree class_to_search = NULL_TREE;
10547 int lc; /* Looking for Constructor */
10549 /* We search constructor in their target class */
10550 if (CALL_CONSTRUCTOR_P (patch))
10552 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10553 class_to_search = EXPR_WFL_NODE (wfl);
10554 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
10555 this_identifier_node)
10556 class_to_search = NULL_TREE;
10557 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
10558 super_identifier_node)
10561 if (CLASSTYPE_SUPER (current_class))
10563 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
10566 parse_error_context (wfl, "Can't invoke super constructor on java.lang.Object");
10567 PATCH_METHOD_RETURN_ERROR ();
10571 /* Class to search is NULL if we're searching the current one */
10572 if (class_to_search)
10574 class_to_search = resolve_and_layout (class_to_search, wfl);
10576 if (!class_to_search)
10578 parse_error_context
10579 (wfl, "Class %qs not found in type declaration",
10580 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10581 PATCH_METHOD_RETURN_ERROR ();
10584 /* Can't instantiate an abstract class, but we can
10585 invoke it's constructor. It's use within the `new'
10586 context is denied here. */
10587 if (CLASS_ABSTRACT (class_to_search)
10588 && TREE_CODE (patch) == NEW_CLASS_EXPR)
10590 parse_error_context
10591 (wfl, "Class %qs is an abstract class. It can't be instantiated",
10592 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
10593 PATCH_METHOD_RETURN_ERROR ();
10596 class_to_search = TREE_TYPE (class_to_search);
10599 class_to_search = current_class;
10602 /* This is a regular search in the local class, unless an
10603 alternate class is specified. */
10606 if (where != NULL_TREE)
10607 class_to_search = where;
10608 else if (QUALIFIED_P (name))
10609 class_to_search = current_class;
10612 class_to_search = current_class;
10616 if (has_method (class_to_search, name))
10618 if (! INNER_CLASS_TYPE_P (class_to_search))
10620 parse_error_context (wfl,
10621 "No method named %qs in scope",
10622 IDENTIFIER_POINTER (name));
10623 PATCH_METHOD_RETURN_ERROR ();
10626 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_to_search)));
10632 /* NAME is a simple identifier or comes from a primary. Search
10633 in the class whose declaration contain the method being
10635 resolve_and_layout (class_to_search, NULL_TREE);
10637 list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
10638 /* Don't continue if no method were found, as the next statement
10639 can't be executed then. */
10641 PATCH_METHOD_RETURN_ERROR ();
10643 if (TYPE_ARRAY_P (class_to_search)
10644 && DECL_NAME (list) == get_identifier ("clone"))
10645 is_array_clone_call = 1;
10647 /* Check for static reference if non static methods */
10648 if (check_for_static_method_reference (wfl, patch, list,
10649 class_to_search, primary))
10650 PATCH_METHOD_RETURN_ERROR ();
10652 /* Check for inner classes creation from illegal contexts */
10653 if (lc && (INNER_CLASS_TYPE_P (class_to_search)
10654 && !CLASS_STATIC (TYPE_NAME (class_to_search)))
10655 && INNER_ENCLOSING_SCOPE_CHECK (class_to_search)
10656 && !DECL_INIT_P (current_function_decl))
10658 parse_error_context
10659 (wfl, "No enclosing instance for inner class %qs is in scope%s",
10660 lang_printable_name (class_to_search, 0),
10661 (!current_this ? "" :
10662 "; an explicit one must be provided when creating this inner class"));
10663 PATCH_METHOD_RETURN_ERROR ();
10666 /* Non static methods are called with the current object extra
10667 argument. If patch a `new TYPE()', the argument is the value
10668 returned by the object allocator. If method is resolved as a
10669 primary, use the primary otherwise use the current THIS. */
10670 args = nreverse (args);
10671 if (TREE_CODE (patch) != NEW_CLASS_EXPR)
10673 this_arg = primary ? primary : current_this;
10675 /* If we're using an access method, things are different.
10676 There are two family of cases:
10678 1) We're not generating bytecodes:
10680 - LIST is non static. It's invocation is transformed from
10681 x(a1,...,an) into this$<n>.x(a1,....an).
10682 - LIST is static. It's invocation is transformed from
10683 x(a1,...,an) into TYPE_OF(this$<n>).x(a1,....an)
10685 2) We're generating bytecodes:
10687 - LIST is non static. It's invocation is transformed from
10688 x(a1,....,an) into access$<n>(this$<n>,a1,...,an).
10689 - LIST is static. It's invocation is transformed from
10690 x(a1,....,an) into TYPE_OF(this$<n>).x(a1,....an).
10692 Of course, this$<n> can be arbitrarily complex, ranging from
10693 this$0 (the immediate outer context) to
10694 access$0(access$0(...(this$0))).
10696 maybe_use_access_method returns a nonzero value if the
10697 this_arg has to be moved into the (then generated) stub
10698 argument list. In the meantime, the selected function
10699 might have be replaced by a generated stub. */
10701 maybe_use_access_method (is_super_init, &list, &this_arg))
10703 args = tree_cons (NULL_TREE, this_arg, args);
10704 this_arg = NULL_TREE; /* So it doesn't get chained twice */
10709 /* Merge point of all resolution schemes. If we have nothing, this
10710 is an error, already signaled */
10712 PATCH_METHOD_RETURN_ERROR ();
10714 /* Check accessibility, position the is_static flag, build and
10716 if (not_accessible_p (DECL_CONTEXT (current_function_decl), list,
10717 (primary ? TREE_TYPE (TREE_TYPE (primary)) :
10718 NULL_TREE), from_super)
10719 /* Calls to clone() on array types are permitted as a special-case. */
10720 && !is_array_clone_call)
10722 const char *const fct_name = IDENTIFIER_POINTER (DECL_NAME (list));
10723 const char *const access =
10724 accessibility_string (get_access_flags_from_decl (list));
10725 const char *const klass =
10726 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list))));
10727 const char *const refklass =
10728 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class)));
10729 const char *const what = (DECL_CONSTRUCTOR_P (list)
10730 ? "constructor" : "method");
10731 parse_error_context (wfl,
10732 "Can't access %s %s %<%s.%s%> from %qs",
10733 access, what, klass, fct_name, refklass);
10734 PATCH_METHOD_RETURN_ERROR ();
10737 /* Deprecation check: check whether the method being invoked or the
10738 instance-being-created's type are deprecated. */
10739 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10740 check_deprecation (wfl, TYPE_NAME (DECL_CONTEXT (list)));
10741 check_deprecation (wfl, list);
10743 /* If invoking a innerclass constructor, there are hidden parameters
10745 if (TREE_CODE (patch) == NEW_CLASS_EXPR
10746 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
10748 /* And make sure we add the accessed local variables to be saved
10749 in field aliases. */
10750 args = build_alias_initializer_parameter_list
10751 (AIPL_FUNCTION_CTOR_INVOCATION, DECL_CONTEXT (list), args, NULL);
10753 /* Secretly pass the current_this/primary as a second argument */
10754 if (primary || current_this)
10757 tree this_type = (current_this ?
10758 TREE_TYPE (TREE_TYPE (current_this)) : NULL_TREE);
10759 /* Method's (list) enclosing context */
10760 tree mec = DECL_CONTEXT (TYPE_NAME (DECL_CONTEXT (list)));
10761 /* If we have a primary, use it. */
10763 extra_arg = primary;
10764 /* The current `this' is an inner class but isn't a direct
10765 enclosing context for the inner class we're trying to
10766 create. Build an access to the proper enclosing context
10768 else if (current_this && PURE_INNER_CLASS_TYPE_P (this_type)
10769 && this_type != TREE_TYPE (mec))
10772 extra_arg = build_access_to_thisn (current_class,
10773 TREE_TYPE (mec), 0);
10774 extra_arg = java_complete_tree (extra_arg);
10776 /* Otherwise, just use the current `this' as an enclosing
10779 extra_arg = current_this;
10780 args = tree_cons (NULL_TREE, extra_arg, args);
10783 args = tree_cons (NULL_TREE, integer_zero_node, args);
10786 /* This handles the situation where a constructor invocation needs
10787 to have an enclosing context passed as a second parameter (the
10788 constructor is one of an inner class). */
10789 if ((is_super_init ||
10790 (TREE_CODE (patch) == CALL_EXPR && name == this_identifier_node))
10791 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
10793 tree dest = TYPE_NAME (DECL_CONTEXT (list));
10795 build_access_to_thisn (current_class, DECL_CONTEXT (dest), 0);
10796 extra_arg = java_complete_tree (extra_arg);
10797 args = tree_cons (NULL_TREE, extra_arg, args);
10800 is_static_flag = METHOD_STATIC (list);
10801 if (! is_static_flag && this_arg != NULL_TREE)
10802 args = tree_cons (NULL_TREE, this_arg, args);
10804 /* In the context of an explicit constructor invocation, we can't
10805 invoke any method relying on `this'. Exceptions are: we're
10806 invoking a static function, primary exists and is not the current
10807 this, we're creating a new object. */
10808 if (ctxp->explicit_constructor_p
10810 && (!primary || primary == current_this)
10811 && (TREE_CODE (patch) != NEW_CLASS_EXPR))
10813 parse_error_context (wfl, "Can't reference %<this%> before the superclass constructor has been called");
10814 PATCH_METHOD_RETURN_ERROR ();
10816 java_parser_context_restore_global ();
10818 *is_static = is_static_flag;
10819 /* Sometimes, we want the decl of the selected method. Such as for
10823 patch = patch_invoke (patch, list, args);
10825 /* Now is a good time to insert the call to finit$ */
10826 if (is_super_init && CLASS_HAS_FINIT_P (current_class))
10828 tree finit_parms, finit_call;
10830 /* Prepare to pass hidden parameters to finit$, if any. */
10831 finit_parms = build_alias_initializer_parameter_list
10832 (AIPL_FUNCTION_FINIT_INVOCATION, current_class, NULL_TREE, NULL);
10835 build_method_invocation (build_wfl_node (finit_identifier_node),
10838 /* Generate the code used to initialize fields declared with an
10839 initialization statement and build a compound statement along
10840 with the super constructor invocation. */
10841 CAN_COMPLETE_NORMALLY (patch) = 1;
10842 patch = build2 (COMPOUND_EXPR, void_type_node, patch,
10843 java_complete_tree (finit_call));
10848 /* Check that we're not trying to do a static reference to a method in
10849 non static method. Return 1 if it's the case, 0 otherwise. */
10852 check_for_static_method_reference (tree wfl, tree node, tree method,
10853 tree where, tree primary)
10855 if (METHOD_STATIC (current_function_decl)
10856 && !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
10858 char *fct_name = xstrdup (lang_printable_name (method, 0));
10859 parse_error_context
10860 (wfl, "Can't make static reference to method %<%s %s%> in class %qs",
10861 lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
10862 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (where))));
10869 /* Fix the invocation of *MDECL if necessary in the case of a
10870 invocation from an inner class. *THIS_ARG might be modified
10871 appropriately and an alternative access to *MDECL might be
10875 maybe_use_access_method (int is_super_init, tree *mdecl, tree *this_arg)
10878 tree md = *mdecl, ta = *this_arg;
10880 int non_static_context = !METHOD_STATIC (md);
10883 || DECL_CONTEXT (md) == current_class
10884 || !PURE_INNER_CLASS_TYPE_P (current_class)
10885 || DECL_FINIT_P (md)
10886 || DECL_INSTINIT_P (md))
10889 /* If we're calling a method found in an enclosing class, generate
10890 what it takes to retrieve the right this. Don't do that if we're
10891 invoking a static method. Note that if MD's type is unrelated to
10892 CURRENT_CLASS, then the current this can be used. */
10894 if (non_static_context && DECL_CONTEXT (md) != object_type_node)
10896 ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
10897 if (inherits_from_p (ctx, DECL_CONTEXT (md)))
10899 ta = build_current_thisn (current_class);
10900 ta = build_wfl_node (ta);
10907 maybe_build_thisn_access_method (type);
10908 if (inherits_from_p (type, DECL_CONTEXT (md)))
10910 ta = build_access_to_thisn (ctx, type, 0);
10913 type = (DECL_CONTEXT (TYPE_NAME (type)) ?
10914 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))) : NULL_TREE);
10917 ta = java_complete_tree (ta);
10920 /* We might have to use an access method to get to MD. We can
10921 break the method access rule as far as we're not generating
10923 if (METHOD_PRIVATE (md) && flag_emit_class_files)
10925 md = build_outer_method_access_method (md);
10932 /* Returning a nonzero value indicates we were doing a non static
10933 method invocation that is now a static invocation. It will have
10934 callee displace `this' to insert it in the regular argument
10936 return (non_static_context && to_return);
10939 /* Patch an invoke expression METHOD and ARGS, based on its invocation
10943 patch_invoke (tree patch, tree method, tree args)
10946 tree original_call, t, ta;
10947 tree check = NULL_TREE;
10949 /* Last step for args: convert build-in types. If we're dealing with
10950 a new TYPE() type call, the first argument to the constructor
10951 isn't found in the incoming argument list, but delivered by
10953 t = TYPE_ARG_TYPES (TREE_TYPE (method));
10954 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
10955 t = TREE_CHAIN (t);
10956 for (ta = args; t != end_params_node && ta;
10957 t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
10958 if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
10959 TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
10960 TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
10962 /* Resolve unresolved returned type issues */
10963 t = TREE_TYPE (TREE_TYPE (method));
10964 if (TREE_CODE (t) == POINTER_TYPE && !CLASS_LOADED_P (TREE_TYPE (t)))
10965 resolve_and_layout (TREE_TYPE (t), NULL);
10967 if (flag_emit_class_files || flag_emit_xref)
10971 switch (invocation_mode (method, CALL_USING_SUPER (patch)))
10973 case INVOKE_VIRTUAL:
10974 dtable = invoke_build_dtable (0, args);
10975 func = build_invokevirtual (dtable, method);
10978 case INVOKE_NONVIRTUAL:
10979 /* If the object for the method call is null, we throw an
10980 exception. We don't do this if the object is the current
10981 method's `this'. In other cases we just rely on an
10982 optimization pass to eliminate redundant checks. */
10983 if (TREE_VALUE (args) != current_this)
10985 /* We use a save_expr here to make sure we only evaluate
10986 the new `self' expression once. */
10987 tree save_arg = save_expr (TREE_VALUE (args));
10988 TREE_VALUE (args) = save_arg;
10989 check = java_check_reference (save_arg, 1);
10991 /* Fall through. */
10994 case INVOKE_STATIC:
10996 tree signature = build_java_signature (TREE_TYPE (method));
10997 func = build_known_method_ref (method, TREE_TYPE (method),
10998 DECL_CONTEXT (method),
11003 case INVOKE_INTERFACE:
11004 dtable = invoke_build_dtable (1, args);
11005 func = build_invokeinterface (dtable, method);
11012 /* Ensure self_type is initialized, (invokestatic). FIXME */
11013 func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
11016 TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
11017 TREE_OPERAND (patch, 0) = func;
11018 TREE_OPERAND (patch, 1) = args;
11019 patch = check_for_builtin (method, patch);
11020 original_call = patch;
11022 /* We're processing a `new TYPE ()' form. New is called and its
11023 returned value is the first argument to the constructor. We build
11024 a COMPOUND_EXPR and use saved expression so that the overall NEW
11025 expression value is a pointer to a newly created and initialized
11027 if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
11029 tree class = DECL_CONTEXT (method);
11030 tree c1, saved_new, new;
11033 if (flag_emit_class_files || flag_emit_xref)
11035 TREE_TYPE (patch) = build_pointer_type (class);
11038 if (!TYPE_SIZE (class))
11039 safe_layout_class (class);
11041 (class_has_finalize_method (class) ? alloc_object_node
11042 : alloc_no_finalizer_node);
11043 new = build3 (CALL_EXPR, promote_type (class),
11044 build_address_of (alloc_node),
11045 build_tree_list (NULL_TREE, build_class_ref (class)),
11047 saved_new = save_expr (new);
11048 c1 = build_tree_list (NULL_TREE, saved_new);
11049 TREE_CHAIN (c1) = TREE_OPERAND (original_call, 1);
11050 TREE_OPERAND (original_call, 1) = c1;
11051 TREE_SET_CODE (original_call, CALL_EXPR);
11052 patch = build2 (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new);
11055 /* If CHECK is set, then we are building a check to see if the object
11057 if (check != NULL_TREE)
11059 /* We have to call force_evaluation_order now because creating a
11060 COMPOUND_EXPR wraps the arg list in a way that makes it
11061 unrecognizable by force_evaluation_order later. Yuk. */
11062 patch = build2 (COMPOUND_EXPR, TREE_TYPE (patch), check,
11063 force_evaluation_order (patch));
11064 TREE_SIDE_EFFECTS (patch) = 1;
11067 /* In order to be able to modify PATCH later, we SAVE_EXPR it and
11068 put it as the first expression of a COMPOUND_EXPR. The second
11069 expression being an empty statement to be later patched if
11070 necessary. We remember a TREE_LIST (the PURPOSE is the method,
11071 the VALUE is the compound) in a hashtable and return a
11072 COMPOUND_EXPR built so that the result of the evaluation of the
11073 original PATCH node is returned. */
11074 if (STATIC_CLASS_INIT_OPT_P ()
11075 && current_function_decl && METHOD_STATIC (method))
11078 tree fndecl = current_function_decl;
11079 /* We have to call force_evaluation_order now because creating a
11080 COMPOUND_EXPR wraps the arg list in a way that makes it
11081 unrecognizable by force_evaluation_order later. Yuk. */
11082 tree save = force_evaluation_order (patch);
11083 tree type = TREE_TYPE (patch);
11085 patch = build2 (COMPOUND_EXPR, type, save, build_java_empty_stmt ());
11086 list = tree_cons (method, patch,
11087 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl));
11089 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl) = list;
11091 patch = build2 (COMPOUND_EXPR, type, patch, save);
11098 invocation_mode (tree method, int super)
11100 int access = get_access_flags_from_decl (method);
11103 return INVOKE_SUPER;
11105 if (access & ACC_STATIC)
11106 return INVOKE_STATIC;
11108 /* We have to look for a constructor before we handle nonvirtual
11109 calls; otherwise the constructor will look nonvirtual. */
11110 if (DECL_CONSTRUCTOR_P (method))
11111 return INVOKE_STATIC;
11113 if (access & ACC_PRIVATE)
11114 return INVOKE_NONVIRTUAL;
11116 /* Binary compatibility: just because it's final today, that doesn't
11117 mean it'll be final tomorrow. */
11118 if (! flag_indirect_dispatch
11119 || DECL_CONTEXT (method) == object_type_node)
11121 if (access & ACC_FINAL)
11122 return INVOKE_NONVIRTUAL;
11124 if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
11125 return INVOKE_NONVIRTUAL;
11128 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
11129 return INVOKE_INTERFACE;
11131 return INVOKE_VIRTUAL;
11134 /* Retrieve a refined list of matching methods. It covers the step
11135 15.11.2 (Compile-Time Step 2) */
11138 lookup_method_invoke (int lc, tree cl, tree class, tree name, tree arg_list)
11140 tree atl = end_params_node; /* Arg Type List */
11141 tree method, signature, list, node;
11142 const char *candidates; /* Used for error report */
11145 /* Fix the arguments */
11146 for (node = arg_list; node; node = TREE_CHAIN (node))
11148 tree current_arg = TREE_TYPE (TREE_VALUE (node));
11149 /* Non primitive type may have to be resolved */
11150 if (!JPRIMITIVE_TYPE_P (current_arg))
11151 resolve_and_layout (current_arg, NULL_TREE);
11153 if (TREE_CODE (current_arg) == RECORD_TYPE)
11154 current_arg = promote_type (current_arg);
11155 atl = tree_cons (NULL_TREE, current_arg, atl);
11158 /* Presto. If we're dealing with an anonymous class and a
11159 constructor call, generate the right constructor now, since we
11160 know the arguments' types. */
11162 if (lc && ANONYMOUS_CLASS_P (class))
11164 tree mdecl = craft_constructor (TYPE_NAME (class), atl);
11165 /* The anonymous class may have already been laid out, so make sure
11166 the new constructor is laid out here. */
11167 layout_class_method (class, CLASSTYPE_SUPER (class), mdecl, NULL_TREE);
11170 /* Find all candidates and then refine the list, searching for the
11171 most specific method. */
11172 list = find_applicable_accessible_methods_list (lc, class, name, atl);
11173 list = find_most_specific_methods_list (list);
11174 if (list && !TREE_CHAIN (list))
11175 return TREE_VALUE (list);
11177 /* Issue an error. List candidates if any. Candidates are listed
11178 only if accessible (non accessible methods may end-up here for
11179 the sake of a better error report). */
11184 obstack_grow (&temporary_obstack, ". Candidates are:\n", 18);
11185 for (current = list; current; current = TREE_CHAIN (current))
11187 tree cm = TREE_VALUE (current);
11188 char string [4096];
11189 if (!cm || not_accessible_p (class, cm, NULL_TREE, 0))
11192 (string, " '%s' in '%s'%s",
11193 get_printable_method_name (cm),
11194 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
11195 (TREE_CHAIN (current) ? "\n" : ""));
11196 obstack_grow (&temporary_obstack, string, strlen (string));
11198 obstack_1grow (&temporary_obstack, '\0');
11199 candidates = obstack_finish (&temporary_obstack);
11201 /* Issue the error message */
11202 method = make_node (FUNCTION_TYPE);
11203 TYPE_ARG_TYPES (method) = atl;
11204 signature = build_java_argument_signature (method);
11205 dup = xstrdup (lang_printable_name (class, 0));
11206 parse_error_context (cl, "Can't find %s %<%s(%s)%> in type %qs%s",
11207 (lc ? "constructor" : "method"),
11208 (lc ? dup : IDENTIFIER_POINTER (name)),
11209 IDENTIFIER_POINTER (signature), dup,
11210 (candidates ? candidates : ""));
11215 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
11216 when we're looking for a constructor. */
11219 find_applicable_accessible_methods_list (int lc, tree class, tree name,
11222 static htab_t searched_classes;
11223 static int search_not_done = 0;
11224 tree list = NULL_TREE, all_list = NULL_TREE;
11228 /* Check the hash table to determine if this class has been searched
11230 if (searched_classes)
11232 if (htab_find (searched_classes, class) != NULL)
11237 searched_classes = htab_create (10, htab_hash_pointer,
11238 htab_eq_pointer, NULL);
11242 *htab_find_slot (searched_classes, class, INSERT) = class;
11244 if (!CLASS_LOADED_P (class))
11246 load_class (class, 1);
11247 safe_layout_class (class);
11250 /* Search interfaces */
11251 if (TREE_CODE (TYPE_NAME (class)) == TYPE_DECL
11252 && CLASS_INTERFACE (TYPE_NAME (class)))
11254 search_applicable_methods_list (lc, TYPE_METHODS (class),
11255 name, arglist, &list, &all_list);
11256 for (i = 1; BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
11258 tree t = BINFO_TYPE (base_binfo);
11261 rlist = find_applicable_accessible_methods_list (lc, t, name,
11263 list = chainon (rlist, list);
11266 /* Search classes */
11269 search_applicable_methods_list (lc, TYPE_METHODS (class),
11270 name, arglist, &list, &all_list);
11272 /* When looking finit$, class$ or instinit$, we turn LC to 1 so
11273 that we only search in class. Note that we should have found
11274 something at this point. */
11275 if (ID_FINIT_P (name) || ID_CLASSDOLLAR_P (name) || ID_INSTINIT_P (name))
11282 /* We must search all interfaces of this class */
11286 BINFO_BASE_ITERATE (TYPE_BINFO (class), i, base_binfo); i++)
11288 tree t = BINFO_TYPE (base_binfo);
11289 if (t != object_type_node)
11292 = find_applicable_accessible_methods_list (lc, t,
11294 list = chainon (rlist, list);
11299 /* Search superclass */
11300 if (!lc && CLASSTYPE_SUPER (class) != NULL_TREE)
11303 class = CLASSTYPE_SUPER (class);
11304 rlist = find_applicable_accessible_methods_list (lc, class,
11306 list = chainon (rlist, list);
11312 /* We're done. Reset the searched classes list and finally search
11313 java.lang.Object if it wasn't searched already. */
11314 if (!search_not_done)
11317 && TYPE_METHODS (object_type_node)
11318 && htab_find (searched_classes, object_type_node) == NULL)
11320 search_applicable_methods_list (lc,
11321 TYPE_METHODS (object_type_node),
11322 name, arglist, &list, &all_list);
11324 htab_delete (searched_classes);
11325 searched_classes = NULL;
11328 /* Either return the list obtained or all selected (but
11329 inaccessible) methods for better error report. */
11330 return (!list ? all_list : list);
11333 /* Effectively search for the appropriate method in method */
11336 search_applicable_methods_list (int lc, tree method, tree name, tree arglist,
11337 tree *list, tree *all_list)
11339 for (; method; method = TREE_CHAIN (method))
11341 /* When dealing with constructor, stop here, otherwise search
11343 if (lc && !DECL_CONSTRUCTOR_P (method))
11345 else if (!lc && (DECL_CONSTRUCTOR_P (method)
11346 || (DECL_NAME (method) != name)))
11349 if (argument_types_convertible (method, arglist))
11351 /* Retain accessible methods only */
11352 if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
11353 method, NULL_TREE, 0))
11354 *list = tree_cons (NULL_TREE, method, *list);
11356 /* Also retain all selected method here */
11357 *all_list = tree_cons (NULL_TREE, method, *list);
11362 /* 15.11.2.2 Choose the Most Specific Method */
11365 find_most_specific_methods_list (tree list)
11368 int abstract, candidates;
11369 tree current, new_list = NULL_TREE;
11370 for (current = list; current; current = TREE_CHAIN (current))
11373 DECL_SPECIFIC_COUNT (TREE_VALUE (current)) = 0;
11375 for (method = list; method; method = TREE_CHAIN (method))
11377 tree method_v, current_v;
11378 /* Don't test a method against itself */
11379 if (method == current)
11382 method_v = TREE_VALUE (method);
11383 current_v = TREE_VALUE (current);
11385 /* Compare arguments and location where methods where declared */
11386 if (argument_types_convertible (method_v, current_v))
11388 if (valid_method_invocation_conversion_p
11389 (DECL_CONTEXT (method_v), DECL_CONTEXT (current_v))
11390 || (INNER_CLASS_TYPE_P (DECL_CONTEXT (current_v))
11391 && enclosing_context_p (DECL_CONTEXT (method_v),
11392 DECL_CONTEXT (current_v))))
11394 int v = (DECL_SPECIFIC_COUNT (current_v) +=
11395 (INNER_CLASS_TYPE_P (DECL_CONTEXT (current_v)) ? 2 : 1));
11396 max = (v > max ? v : max);
11402 /* Review the list and select the maximally specific methods */
11403 for (current = list, abstract = -1, candidates = -1;
11404 current; current = TREE_CHAIN (current))
11405 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
11407 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
11408 abstract += (METHOD_ABSTRACT (TREE_VALUE (current)) ? 1 : 0);
11412 /* If we have several and they're all abstract, just pick the
11414 if (candidates > 0 && candidates == abstract)
11416 /* FIXME: merge the throws clauses. There is no convenient way
11417 to do this in gcj right now, since ideally we'd like to
11418 introduce a new METHOD_DECL here, but that is really not
11420 new_list = nreverse (new_list);
11421 TREE_CHAIN (new_list) = NULL_TREE;
11425 /* We have several (we couldn't find a most specific), all but one
11426 are abstract, we pick the only non abstract one. */
11427 if (candidates > 0 && (candidates == abstract+1))
11429 for (current = new_list; current; current = TREE_CHAIN (current))
11430 if (!METHOD_ABSTRACT (TREE_VALUE (current)))
11432 TREE_CHAIN (current) = NULL_TREE;
11433 new_list = current;
11437 /* If we can't find one, lower expectations and try to gather multiple
11438 maximally specific methods */
11439 while (!new_list && max)
11443 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
11444 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
11451 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
11452 converted by method invocation conversion (5.3) to the type of the
11453 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
11454 to change less often than M1. */
11456 static GTY(()) tree m2_arg_value;
11457 static GTY(()) tree m2_arg_cache;
11460 argument_types_convertible (tree m1, tree m2_or_arglist)
11462 tree m1_arg, m2_arg;
11464 SKIP_THIS_AND_ARTIFICIAL_PARMS (m1_arg, m1)
11466 if (m2_arg_value == m2_or_arglist)
11467 m2_arg = m2_arg_cache;
11470 /* M2_OR_ARGLIST can be a function DECL or a raw list of
11472 if (m2_or_arglist && TREE_CODE (m2_or_arglist) == FUNCTION_DECL)
11474 m2_arg = TYPE_ARG_TYPES (TREE_TYPE (m2_or_arglist));
11475 if (!METHOD_STATIC (m2_or_arglist))
11476 m2_arg = TREE_CHAIN (m2_arg);
11479 m2_arg = m2_or_arglist;
11481 m2_arg_value = m2_or_arglist;
11482 m2_arg_cache = m2_arg;
11485 while (m1_arg != end_params_node && m2_arg != end_params_node)
11487 resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
11488 if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
11489 TREE_VALUE (m2_arg)))
11491 m1_arg = TREE_CHAIN (m1_arg);
11492 m2_arg = TREE_CHAIN (m2_arg);
11494 return m1_arg == end_params_node && m2_arg == end_params_node;
11497 /* Qualification routines */
11499 /* Given a name x.y.z, look up x locally. If it's found, save the
11500 decl. If it's not found, mark the name as RESOLVE_PACKAGE_NAME_P,
11501 so that we later try and load the appropriate classes. */
11503 qualify_ambiguous_name (tree id)
11507 /* We inspect the first item of the qualification list. As a sanity
11508 check, make sure that it is an identfier node. */
11509 tree qual = EXPR_WFL_QUALIFICATION (id);
11510 tree qual_wfl = QUAL_WFL (qual);
11512 if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
11515 name = EXPR_WFL_NODE (qual_wfl);
11517 /* If we don't have an identifier, or we have a 'this' or 'super',
11518 then field access processing is all we need : there is nothing
11520 if (!name || TREE_CODE (name) != IDENTIFIER_NODE ||
11521 name == this_identifier_node ||
11522 name == super_identifier_node)
11525 /* If name appears within the scope of a local variable declaration
11526 or parameter declaration, or is a field within an enclosing
11527 class, then it is an expression name. Save the decl and let
11528 resolve_field_access do it's work. */
11529 if ((decl = IDENTIFIER_LOCAL_VALUE (name)) ||
11530 (decl = lookup_field_wrapper (current_class, name)))
11532 QUAL_RESOLUTION (qual) = decl;
11536 /* If name is a known class name (either declared or imported), mark
11537 us as a type name. */
11538 if ((decl = resolve_and_layout (name, NULL_TREE)))
11540 RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
11541 QUAL_RESOLUTION (qual) = decl;
11544 /* Check here that NAME isn't declared by more than one
11545 type-import-on-demand declaration of the compilation unit
11546 containing NAME. FIXME */
11548 /* We couldn't find a declaration for the name. Assume for now that
11549 we have a qualified class name that needs to be loaded from an
11550 external class file. */
11552 RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
11554 /* Propagate the qualification across other components of the
11556 for (qual = TREE_CHAIN (qual); qual;
11557 qual_wfl = QUAL_WFL (qual), qual = TREE_CHAIN (qual))
11559 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
11560 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
11563 /* Store the global qualification for the ambiguous part of ID back
11565 if (RESOLVE_TYPE_NAME_P (qual_wfl))
11566 RESOLVE_TYPE_NAME_P (id) = 1;
11567 else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
11568 RESOLVE_PACKAGE_NAME_P (id) = 1;
11571 /* Patch tree nodes in a function body. When a BLOCK is found, push
11572 local variable decls if present.
11573 Same as java_complete_lhs, but does resolve static finals to values. */
11576 java_complete_tree (tree node)
11578 node = java_complete_lhs (node);
11579 if (JDECL_P (node) && CLASS_FINAL_VARIABLE_P (node)
11580 && DECL_INITIAL (node) != NULL_TREE
11581 && !flag_emit_xref)
11583 tree value = fold_constant_for_init (node, node);
11584 if (value != NULL_TREE)
11591 java_stabilize_reference (tree node)
11593 if (TREE_CODE (node) == COMPOUND_EXPR)
11595 tree op0 = TREE_OPERAND (node, 0);
11596 tree op1 = TREE_OPERAND (node, 1);
11597 TREE_OPERAND (node, 0) = save_expr (op0);
11598 TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
11601 return stabilize_reference (node);
11604 /* Patch tree nodes in a function body. When a BLOCK is found, push
11605 local variable decls if present.
11606 Same as java_complete_tree, but does not resolve static finals to values. */
11609 java_complete_lhs (tree node)
11611 tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
11614 /* CONVERT_EXPR always has its type set, even though it needs to be
11616 if (TREE_TYPE (node) && TREE_CODE (node) != CONVERT_EXPR)
11619 /* The switch block implements cases processing container nodes
11620 first. Contained nodes are always written back. Leaves come
11621 next and return a value. */
11622 switch (TREE_CODE (node))
11626 /* 1- Block section.
11627 Set the local values on decl names so we can identify them
11628 faster when they're referenced. At that stage, identifiers
11629 are legal so we don't check for declaration errors. */
11630 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
11632 DECL_CONTEXT (cn) = current_function_decl;
11633 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
11635 if (BLOCK_EXPR_BODY (node) == NULL_TREE)
11636 CAN_COMPLETE_NORMALLY (node) = 1;
11639 tree stmt = BLOCK_EXPR_BODY (node);
11641 int error_seen = 0;
11642 if (TREE_CODE (stmt) == COMPOUND_EXPR)
11644 /* Re-order from (((A; B); C); ...; Z) to
11645 (A; (B; (C ; (...; Z)))).
11646 This makes it easier to scan the statements left-to-right
11647 without using recursion (which might overflow the stack
11648 if the block has many statements. */
11651 tree left = TREE_OPERAND (stmt, 0);
11652 if (TREE_CODE (left) != COMPOUND_EXPR)
11654 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
11655 TREE_OPERAND (left, 1) = stmt;
11658 BLOCK_EXPR_BODY (node) = stmt;
11661 /* Now do the actual complete, without deep recursion for
11663 ptr = &BLOCK_EXPR_BODY (node);
11664 while (TREE_CODE (*ptr) == COMPOUND_EXPR
11665 && !IS_EMPTY_STMT (TREE_OPERAND (*ptr, 1)))
11667 tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
11668 tree *next = &TREE_OPERAND (*ptr, 1);
11669 TREE_OPERAND (*ptr, 0) = cur;
11670 if (IS_EMPTY_STMT (cur))
11672 /* Optimization; makes it easier to detect empty bodies.
11673 Most useful for <clinit> with all-constant initializer. */
11677 if (TREE_CODE (cur) == ERROR_MARK)
11679 else if (! CAN_COMPLETE_NORMALLY (cur))
11684 if (TREE_CODE (wfl_op2) == BLOCK)
11685 wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
11686 else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
11687 wfl_op2 = TREE_OPERAND (wfl_op2, 0);
11691 if (TREE_CODE (wfl_op2) != CASE_EXPR
11692 && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
11693 unreachable_stmt_error (*ptr);
11695 if (TREE_TYPE (*ptr) == NULL_TREE)
11696 TREE_TYPE (*ptr) = void_type_node;
11699 *ptr = java_complete_tree (*ptr);
11701 if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
11702 return error_mark_node;
11703 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
11705 /* Turn local bindings to null */
11706 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
11707 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = NULL_TREE;
11709 TREE_TYPE (node) = void_type_node;
11712 /* 2- They are expressions but ultimately deal with statements */
11715 wfl_op1 = TREE_OPERAND (node, 0);
11716 COMPLETE_CHECK_OP_0 (node);
11717 /* 14.19 A throw statement cannot complete normally. */
11718 CAN_COMPLETE_NORMALLY (node) = 0;
11719 return patch_throw_statement (node, wfl_op1);
11721 case SYNCHRONIZED_EXPR:
11722 wfl_op1 = TREE_OPERAND (node, 0);
11723 return patch_synchronized_statement (node, wfl_op1);
11726 return patch_try_statement (node);
11728 case TRY_FINALLY_EXPR:
11729 COMPLETE_CHECK_OP_0 (node);
11730 COMPLETE_CHECK_OP_1 (node);
11731 if (IS_EMPTY_STMT (TREE_OPERAND (node, 0)))
11732 /* Reduce try/finally nodes with an empty try block. */
11733 return TREE_OPERAND (node, 1);
11734 if (IS_EMPTY_STMT (TREE_OPERAND (node, 1)))
11735 /* Likewise for an empty finally block. */
11736 return TREE_OPERAND (node, 0);
11737 CAN_COMPLETE_NORMALLY (node)
11738 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
11739 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
11740 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
11743 case LABELED_BLOCK_EXPR:
11744 PUSH_LABELED_BLOCK (node);
11745 if (LABELED_BLOCK_BODY (node))
11746 COMPLETE_CHECK_OP_1 (node);
11747 TREE_TYPE (node) = void_type_node;
11748 POP_LABELED_BLOCK ();
11750 if (IS_EMPTY_STMT (LABELED_BLOCK_BODY (node)))
11752 LABELED_BLOCK_BODY (node) = NULL_TREE;
11753 CAN_COMPLETE_NORMALLY (node) = 1;
11755 else if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
11756 CAN_COMPLETE_NORMALLY (node) = 1;
11759 case EXIT_BLOCK_EXPR:
11760 return patch_bc_statement (node);
11763 cn = java_complete_tree (TREE_OPERAND (node, 0));
11764 if (cn == error_mark_node)
11767 /* First, the case expression must be constant. Values of final
11768 fields are accepted. */
11770 if ((TREE_CODE (cn) == COMPOUND_EXPR || TREE_CODE (cn) == COMPONENT_REF)
11771 && JDECL_P (TREE_OPERAND (cn, 1))
11772 && FIELD_FINAL (TREE_OPERAND (cn, 1))
11773 && DECL_INITIAL (TREE_OPERAND (cn, 1)))
11775 cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
11776 TREE_OPERAND (cn, 1));
11778 /* Accept final locals too. */
11779 else if (TREE_CODE (cn) == VAR_DECL && DECL_FINAL (cn)
11780 && DECL_INITIAL (cn))
11781 cn = fold_constant_for_init (DECL_INITIAL (cn), cn);
11783 if (!TREE_CONSTANT (cn) && !flag_emit_xref)
11785 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11786 parse_error_context (node, "Constant expression required");
11787 return error_mark_node;
11790 nn = ctxp->current_loop;
11792 /* It must be assignable to the type of the switch expression. */
11793 if (!try_builtin_assignconv (NULL_TREE,
11794 TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
11796 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11797 parse_error_context
11799 "Incompatible type for case. Can't convert %qs to %<int%>",
11800 lang_printable_name (TREE_TYPE (cn), 0));
11801 return error_mark_node;
11804 cn = fold (convert (int_type_node, cn));
11805 TREE_CONSTANT_OVERFLOW (cn) = 0;
11806 CAN_COMPLETE_NORMALLY (cn) = 1;
11808 /* Save the label on a list so that we can later check for
11810 case_label_list = tree_cons (node, cn, case_label_list);
11812 /* Multiple instance of a case label bearing the same value is
11813 checked later. The case expression is all right so far. */
11814 if (TREE_CODE (cn) == VAR_DECL)
11815 cn = DECL_INITIAL (cn);
11816 TREE_OPERAND (node, 0) = cn;
11817 TREE_TYPE (node) = void_type_node;
11818 CAN_COMPLETE_NORMALLY (node) = 1;
11819 TREE_SIDE_EFFECTS (node) = 1;
11823 nn = ctxp->current_loop;
11824 /* Only one default label is allowed per switch statement */
11825 if (SWITCH_HAS_DEFAULT (nn))
11827 #ifdef USE_MAPPED_LOCATION
11828 SET_EXPR_LOCATION (wfl_operator, EXPR_LOCATION (node));
11830 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11832 parse_error_context (wfl_operator,
11833 "Duplicate case label: %<default%>");
11834 return error_mark_node;
11837 SWITCH_HAS_DEFAULT (nn) = 1;
11838 TREE_TYPE (node) = void_type_node;
11839 TREE_SIDE_EFFECTS (node) = 1;
11840 CAN_COMPLETE_NORMALLY (node) = 1;
11846 /* Check whether the loop was enclosed in a labeled
11847 statement. If not, create one, insert the loop in it and
11849 nn = patch_loop_statement (node);
11851 /* Anyways, walk the body of the loop */
11852 if (TREE_CODE (node) == LOOP_EXPR)
11853 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11854 /* Switch statement: walk the switch expression and the cases */
11856 node = patch_switch_statement (node);
11858 if (node == error_mark_node || TREE_OPERAND (node, 0) == error_mark_node)
11859 nn = error_mark_node;
11862 TREE_TYPE (nn) = TREE_TYPE (node) = void_type_node;
11863 /* If we returned something different, that's because we
11864 inserted a label. Pop the label too. */
11867 if (CAN_COMPLETE_NORMALLY (node))
11868 CAN_COMPLETE_NORMALLY (nn) = 1;
11869 POP_LABELED_BLOCK ();
11876 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11877 return patch_exit_expr (node);
11881 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
11882 if (TREE_OPERAND (node, 0) == error_mark_node)
11883 return error_mark_node;
11884 /* then-else branches */
11885 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
11886 if (TREE_OPERAND (node, 1) == error_mark_node)
11887 return error_mark_node;
11889 /* This is a special case due to build_assertion(). When
11890 assertions are disabled we build a COND_EXPR in which
11891 Operand 1 is the body of the assertion. If that happens to
11892 be a string concatenation we'll need to patch it here. */
11893 tree patched = patch_string (TREE_OPERAND (node, 1));
11895 TREE_OPERAND (node, 1) = patched;
11897 TREE_OPERAND (node, 2) = java_complete_tree (TREE_OPERAND (node, 2));
11898 if (TREE_OPERAND (node, 2) == error_mark_node)
11899 return error_mark_node;
11900 return patch_if_else_statement (node);
11903 case CONDITIONAL_EXPR:
11905 wfl_op1 = TREE_OPERAND (node, 0);
11906 COMPLETE_CHECK_OP_0 (node);
11907 wfl_op2 = TREE_OPERAND (node, 1);
11908 COMPLETE_CHECK_OP_1 (node);
11909 wfl_op3 = TREE_OPERAND (node, 2);
11910 COMPLETE_CHECK_OP_2 (node);
11911 return patch_conditional_expr (node, wfl_op1, wfl_op2);
11913 /* 3- Expression section */
11914 case COMPOUND_EXPR:
11915 wfl_op2 = TREE_OPERAND (node, 1);
11916 TREE_OPERAND (node, 0) = nn =
11917 java_complete_tree (TREE_OPERAND (node, 0));
11918 if (IS_EMPTY_STMT (wfl_op2))
11919 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
11922 if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
11924 /* An unreachable condition in a do-while statement
11925 is *not* (technically) an unreachable statement. */
11927 if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
11928 nn = EXPR_WFL_NODE (nn);
11929 /* NN can be NULL_TREE exactly when UPDATE is, in
11930 finish_for_loop. */
11931 if (nn != NULL_TREE && TREE_CODE (nn) != EXIT_EXPR)
11933 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
11934 if (SUPPRESS_UNREACHABLE_ERROR (nn))
11936 /* Perhaps this warning should have an
11937 associated flag. The code being compiled is
11938 pedantically correct, but useless. */
11939 parse_warning_context (wfl_operator,
11940 "Unreachable statement");
11943 parse_error_context (wfl_operator,
11944 "Unreachable statement");
11947 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
11948 if (TREE_OPERAND (node, 1) == error_mark_node)
11949 return error_mark_node;
11950 /* Even though we might allow the case where the first
11951 operand doesn't return normally, we still should compute
11952 CAN_COMPLETE_NORMALLY correctly. */
11953 CAN_COMPLETE_NORMALLY (node)
11954 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
11955 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
11957 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
11961 /* CAN_COMPLETE_NORMALLY (node) = 0; */
11962 return patch_return (node);
11964 case EXPR_WITH_FILE_LOCATION:
11965 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
11966 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
11969 node = resolve_expression_name (node, NULL);
11970 if (node == error_mark_node)
11972 /* Keep line number information somewhere were it doesn't
11973 disrupt the completion process. */
11974 if (flag_emit_xref && TREE_CODE (node) != CALL_EXPR)
11976 EXPR_WFL_NODE (wfl) = TREE_OPERAND (node, 1);
11977 TREE_OPERAND (node, 1) = wfl;
11979 CAN_COMPLETE_NORMALLY (node) = 1;
11984 location_t save_location = input_location;
11985 #ifdef USE_MAPPED_LOCATION
11986 input_location = EXPR_LOCATION (node);
11987 if (input_location == UNKNOWN_LOCATION)
11988 input_location = save_location;
11990 input_line = EXPR_WFL_LINENO (node);
11992 body = java_complete_tree (EXPR_WFL_NODE (node));
11993 input_location = save_location;
11994 EXPR_WFL_NODE (node) = body;
11995 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
11996 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
11997 if (IS_EMPTY_STMT (body) || TREE_CONSTANT (body))
11999 /* Makes it easier to constant fold, detect empty bodies. */
12002 if (body == error_mark_node)
12004 /* Its important for the evaluation of assignment that
12005 this mark on the TREE_TYPE is propagated. */
12006 TREE_TYPE (node) = error_mark_node;
12007 return error_mark_node;
12010 TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
12015 case NEW_ARRAY_EXPR:
12016 /* Patch all the dimensions */
12018 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
12020 int location = EXPR_WFL_LINECOL (TREE_VALUE (cn));
12021 tree dim = convert (int_type_node,
12022 java_complete_tree (TREE_VALUE (cn)));
12023 if (dim == error_mark_node)
12030 TREE_VALUE (cn) = dim;
12031 /* Setup the location of the current dimension, for
12032 later error report. */
12033 #ifdef USE_MAPPED_LOCATION
12034 TREE_PURPOSE (cn) = expr_add_location (NULL_TREE, location, 0);
12036 TREE_PURPOSE (cn) =
12037 build_expr_wfl (NULL_TREE, input_filename, 0, 0);
12038 EXPR_WFL_LINECOL (TREE_PURPOSE (cn)) = location;
12042 /* They complete the array creation expression, if no errors
12044 CAN_COMPLETE_NORMALLY (node) = 1;
12045 return (flag ? error_mark_node
12046 : force_evaluation_order (patch_newarray (node)));
12048 case NEW_ANONYMOUS_ARRAY_EXPR:
12049 /* Create the array type if necessary. */
12050 if (ANONYMOUS_ARRAY_DIMS_SIG (node))
12052 tree type = ANONYMOUS_ARRAY_BASE_TYPE (node);
12053 if (!(type = resolve_type_during_patch (type)))
12054 return error_mark_node;
12055 type = build_array_from_name (type, NULL_TREE,
12056 ANONYMOUS_ARRAY_DIMS_SIG (node), NULL);
12057 ANONYMOUS_ARRAY_BASE_TYPE (node) = build_pointer_type (type);
12059 node = patch_new_array_init (ANONYMOUS_ARRAY_BASE_TYPE (node),
12060 ANONYMOUS_ARRAY_INITIALIZER (node));
12061 if (node == error_mark_node)
12062 return error_mark_node;
12063 CAN_COMPLETE_NORMALLY (node) = 1;
12066 case NEW_CLASS_EXPR:
12068 /* Complete function's argument(s) first */
12069 if (complete_function_arguments (node))
12070 return error_mark_node;
12073 tree decl, wfl = TREE_OPERAND (node, 0);
12074 int in_this = CALL_THIS_CONSTRUCTOR_P (node);
12075 int from_super = (EXPR_WFL_NODE (TREE_OPERAND (node, 0)) ==
12076 super_identifier_node);
12078 #ifdef USE_MAPPED_LOCATION
12079 source_location location = EXPR_LOCATION (node);
12081 int location = EXPR_WFL_LINECOL (node);
12084 node = patch_method_invocation (node, NULL_TREE, NULL_TREE,
12085 from_super, 0, &decl);
12086 if (node == error_mark_node)
12087 return error_mark_node;
12089 if (TREE_CODE (node) == CALL_EXPR
12090 && TREE_OPERAND (node, 1) != NULL_TREE)
12091 arguments = TREE_VALUE (TREE_OPERAND (node, 1));
12093 arguments = NULL_TREE;
12094 check_thrown_exceptions (location, decl, arguments);
12095 /* If we call this(...), register signature and positions */
12097 DECL_CONSTRUCTOR_CALLS (current_function_decl) =
12098 tree_cons (wfl, decl,
12099 DECL_CONSTRUCTOR_CALLS (current_function_decl));
12100 CAN_COMPLETE_NORMALLY (node) = 1;
12101 return force_evaluation_order (node);
12105 /* Save potential wfls */
12106 wfl_op1 = TREE_OPERAND (node, 0);
12107 TREE_OPERAND (node, 0) = nn = java_complete_lhs (wfl_op1);
12109 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node)
12110 && TREE_CODE (nn) == VAR_DECL && TREE_STATIC (nn)
12111 && DECL_INITIAL (nn) != NULL_TREE)
12115 value = fold_constant_for_init (nn, nn);
12117 /* When we have a primitype type, or a string and we're not
12118 emitting a class file, we actually don't want to generate
12119 anything for the assignment. */
12120 if (value != NULL_TREE &&
12121 (JPRIMITIVE_TYPE_P (TREE_TYPE (value)) ||
12122 (TREE_TYPE (value) == string_ptr_type_node &&
12123 ! flag_emit_class_files)))
12125 /* Prepare node for patch_assignment */
12126 TREE_OPERAND (node, 1) = value;
12127 /* Call patch assignment to verify the assignment */
12128 if (patch_assignment (node, wfl_op1) == error_mark_node)
12129 return error_mark_node;
12130 /* Set DECL_INITIAL properly (a conversion might have
12131 been decided by patch_assignment) and return the
12132 empty statement. */
12135 tree patched = patch_string (TREE_OPERAND (node, 1));
12137 DECL_INITIAL (nn) = patched;
12139 DECL_INITIAL (nn) = TREE_OPERAND (node, 1);
12140 DECL_FIELD_FINAL_IUD (nn) = 1;
12141 return build_java_empty_stmt ();
12144 if (! flag_emit_class_files)
12145 DECL_INITIAL (nn) = NULL_TREE;
12147 wfl_op2 = TREE_OPERAND (node, 1);
12149 if (TREE_OPERAND (node, 0) == error_mark_node)
12150 return error_mark_node;
12152 flag = COMPOUND_ASSIGN_P (wfl_op2);
12155 /* This might break when accessing outer field from inner
12156 class. TESTME, FIXME */
12157 tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0));
12159 /* Hand stabilize the lhs on both places */
12160 TREE_OPERAND (node, 0) = lvalue;
12161 TREE_OPERAND (TREE_OPERAND (node, 1), 0) =
12162 (flag_emit_class_files ? lvalue : save_expr (lvalue));
12164 /* 15.25.2.a: Left hand is not an array access. FIXME */
12165 /* Now complete the RHS. We write it back later on. */
12166 nn = java_complete_tree (TREE_OPERAND (node, 1));
12168 if ((cn = patch_string (nn)))
12171 /* The last part of the rewrite for E1 op= E2 is to have
12172 E1 = (T)(E1 op E2), with T being the type of E1. */
12173 nn = java_complete_tree (build_cast (EXPR_WFL_LINECOL (wfl_op2),
12174 TREE_TYPE (lvalue), nn));
12176 /* If the assignment is compound and has reference type,
12177 then ensure the LHS has type String and nothing else. */
12178 if (JREFERENCE_TYPE_P (TREE_TYPE (lvalue))
12179 && ! JSTRING_TYPE_P (TREE_TYPE (lvalue)))
12180 parse_error_context (wfl_op2,
12181 "Incompatible type for %<+=%>. Can't convert %qs to %<java.lang.String%>",
12182 lang_printable_name (TREE_TYPE (lvalue), 0));
12184 /* 15.25.2.b: Left hand is an array access. FIXME */
12187 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
12188 function to complete this RHS. Note that a NEW_ARRAY_INIT
12189 might have been already fully expanded if created as a result
12190 of processing an anonymous array initializer. We avoid doing
12191 the operation twice by testing whether the node already bears
12193 else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT && !TREE_TYPE (wfl_op2))
12194 nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
12195 TREE_OPERAND (node, 1));
12196 /* Otherwise we simply complete the RHS */
12198 nn = java_complete_tree (TREE_OPERAND (node, 1));
12200 if (nn == error_mark_node)
12201 return error_mark_node;
12203 /* Write back the RHS as we evaluated it. */
12204 TREE_OPERAND (node, 1) = nn;
12206 /* In case we're handling = with a String as a RHS, we need to
12207 produce a String out of the RHS (it might still be a
12208 STRING_CST or a StringBuffer at this stage */
12209 if ((nn = patch_string (TREE_OPERAND (node, 1))))
12210 TREE_OPERAND (node, 1) = nn;
12212 if ((nn = outer_field_access_fix (wfl_op1, TREE_OPERAND (node, 0),
12213 TREE_OPERAND (node, 1))))
12215 /* We return error_mark_node if outer_field_access_fix
12216 detects we write into a final. */
12217 if (nn == error_mark_node)
12218 return error_mark_node;
12223 node = patch_assignment (node, wfl_op1);
12224 if (node == error_mark_node)
12225 return error_mark_node;
12226 /* Reorganize the tree if necessary. */
12227 if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node))
12228 || JSTRING_P (TREE_TYPE (node))))
12229 node = java_refold (node);
12232 /* Seek to set DECL_INITIAL to a proper value, since it might have
12233 undergone a conversion in patch_assignment. We do that only when
12234 it's necessary to have DECL_INITIAL properly set. */
12235 nn = TREE_OPERAND (node, 0);
12236 if (TREE_CODE (nn) == VAR_DECL
12237 && DECL_INITIAL (nn) && CONSTANT_VALUE_P (DECL_INITIAL (nn))
12238 && FIELD_STATIC (nn) && FIELD_FINAL (nn)
12239 && (JPRIMITIVE_TYPE_P (TREE_TYPE (nn))
12240 || TREE_TYPE (nn) == string_ptr_type_node))
12241 DECL_INITIAL (nn) = TREE_OPERAND (node, 1);
12243 CAN_COMPLETE_NORMALLY (node) = 1;
12255 case TRUNC_MOD_EXPR:
12256 case TRUNC_DIV_EXPR:
12258 case TRUTH_ANDIF_EXPR:
12259 case TRUTH_ORIF_EXPR:
12266 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
12267 knows how to handle those cases. */
12268 wfl_op1 = TREE_OPERAND (node, 0);
12269 wfl_op2 = TREE_OPERAND (node, 1);
12271 CAN_COMPLETE_NORMALLY (node) = 1;
12272 /* Don't complete string nodes if dealing with the PLUS operand. */
12273 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
12275 nn = java_complete_tree (wfl_op1);
12276 if (nn == error_mark_node)
12277 return error_mark_node;
12279 TREE_OPERAND (node, 0) = nn;
12281 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
12283 nn = java_complete_tree (wfl_op2);
12284 if (nn == error_mark_node)
12285 return error_mark_node;
12287 TREE_OPERAND (node, 1) = nn;
12289 return patch_binop (node, wfl_op1, wfl_op2);
12291 case INSTANCEOF_EXPR:
12292 wfl_op1 = TREE_OPERAND (node, 0);
12293 COMPLETE_CHECK_OP_0 (node);
12294 if (flag_emit_xref)
12296 TREE_TYPE (node) = boolean_type_node;
12299 return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
12301 case UNARY_PLUS_EXPR:
12303 case TRUTH_NOT_EXPR:
12305 case PREDECREMENT_EXPR:
12306 case PREINCREMENT_EXPR:
12307 case POSTDECREMENT_EXPR:
12308 case POSTINCREMENT_EXPR:
12310 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
12311 how to handle those cases. */
12312 wfl_op1 = TREE_OPERAND (node, 0);
12313 CAN_COMPLETE_NORMALLY (node) = 1;
12314 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
12315 if (TREE_OPERAND (node, 0) == error_mark_node)
12316 return error_mark_node;
12317 node = patch_unaryop (node, wfl_op1);
12318 CAN_COMPLETE_NORMALLY (node) = 1;
12322 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
12323 how to handle those cases. */
12324 wfl_op1 = TREE_OPERAND (node, 0);
12325 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
12326 if (TREE_OPERAND (node, 0) == error_mark_node)
12327 return error_mark_node;
12328 if (!flag_emit_class_files && !flag_emit_xref)
12329 TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
12330 /* The same applies to wfl_op2 */
12331 wfl_op2 = TREE_OPERAND (node, 1);
12332 TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
12333 if (TREE_OPERAND (node, 1) == error_mark_node)
12334 return error_mark_node;
12335 if (!flag_emit_class_files && !flag_emit_xref)
12336 TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
12337 return patch_array_ref (node);
12342 case COMPONENT_REF:
12343 /* The first step in the re-write of qualified name handling. FIXME.
12344 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
12345 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
12346 if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
12348 tree name = TREE_OPERAND (node, 1);
12349 tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
12350 if (field == NULL_TREE)
12352 error ("missing static field %qs", IDENTIFIER_POINTER (name));
12353 return error_mark_node;
12355 if (! FIELD_STATIC (field))
12357 error ("not a static field %qs", IDENTIFIER_POINTER (name));
12358 return error_mark_node;
12367 /* Can't use THIS in a static environment */
12370 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12371 parse_error_context (wfl_operator,
12372 "Keyword %<this%> used outside allowed context");
12373 TREE_TYPE (node) = error_mark_node;
12374 return error_mark_node;
12376 if (ctxp->explicit_constructor_p)
12378 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12379 parse_error_context
12380 (wfl_operator, "Can't reference %<this%> or %<super%> before the superclass constructor has been called");
12381 TREE_TYPE (node) = error_mark_node;
12382 return error_mark_node;
12384 return current_this;
12386 case CLASS_LITERAL:
12387 CAN_COMPLETE_NORMALLY (node) = 1;
12388 node = patch_incomplete_class_ref (node);
12389 if (node == error_mark_node)
12390 return error_mark_node;
12394 CAN_COMPLETE_NORMALLY (node) = 1;
12395 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
12396 and it's time to turn it into the appropriate String object */
12397 if ((nn = patch_string (node)))
12400 internal_error ("No case for %s", tree_code_name [TREE_CODE (node)]);
12405 /* Complete function call's argument. Return a nonzero value is an
12406 error was found. */
12409 complete_function_arguments (tree node)
12414 ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
12415 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
12417 tree wfl = TREE_VALUE (cn), parm, temp;
12418 parm = java_complete_tree (wfl);
12420 if (parm == error_mark_node)
12425 /* If we have a string literal that we haven't transformed yet or a
12426 crafted string buffer, as a result of the use of the String
12427 `+' operator. Build `parm.toString()' and expand it. */
12428 if ((temp = patch_string (parm)))
12431 TREE_VALUE (cn) = parm;
12433 ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
12437 /* Sometimes (for loops and variable initialized during their
12438 declaration), we want to wrap a statement around a WFL and turn it
12442 build_debugable_stmt (int location, tree stmt)
12444 if (TREE_CODE (stmt) != EXPR_WITH_FILE_LOCATION)
12446 #ifdef USE_MAPPED_LOCATION
12447 stmt = expr_add_location (stmt, location, 1);
12449 stmt = build_expr_wfl (stmt, input_filename, 0, 0);
12450 EXPR_WFL_LINECOL (stmt) = location;
12451 JAVA_MAYBE_GENERATE_DEBUG_INFO (stmt);
12458 build_expr_block (tree body, tree decls)
12460 tree node = make_node (BLOCK);
12461 BLOCK_EXPR_DECLS (node) = decls;
12462 BLOCK_EXPR_BODY (node) = body;
12464 TREE_TYPE (node) = TREE_TYPE (body);
12465 TREE_SIDE_EFFECTS (node) = 1;
12469 /* Create a new function block and link it appropriately to current
12470 function block chain */
12475 tree b = build_expr_block (NULL_TREE, NULL_TREE);
12477 /* Link block B supercontext to the previous block. The current
12478 function DECL is used as supercontext when enter_a_block is called
12479 for the first time for a given function. The current function body
12480 (DECL_FUNCTION_BODY) is set to be block B. */
12482 tree fndecl = current_function_decl;
12485 BLOCK_SUPERCONTEXT (b) = current_static_block;
12486 current_static_block = b;
12489 else if (!DECL_FUNCTION_BODY (fndecl))
12491 BLOCK_SUPERCONTEXT (b) = fndecl;
12492 DECL_FUNCTION_BODY (fndecl) = b;
12496 BLOCK_SUPERCONTEXT (b) = DECL_FUNCTION_BODY (fndecl);
12497 DECL_FUNCTION_BODY (fndecl) = b;
12502 /* Exit a block by changing the current function body
12503 (DECL_FUNCTION_BODY) to the current block super context, only if
12504 the block being exited isn't the method's top level one. */
12510 if (current_function_decl)
12512 b = DECL_FUNCTION_BODY (current_function_decl);
12513 if (BLOCK_SUPERCONTEXT (b) != current_function_decl)
12514 DECL_FUNCTION_BODY (current_function_decl) = BLOCK_SUPERCONTEXT (b);
12518 b = current_static_block;
12520 if (BLOCK_SUPERCONTEXT (b))
12521 current_static_block = BLOCK_SUPERCONTEXT (b);
12526 /* Lookup for NAME in the nested function's blocks, all the way up to
12527 the current toplevel one. It complies with Java's local variable
12531 lookup_name_in_blocks (tree name)
12533 tree b = GET_CURRENT_BLOCK (current_function_decl);
12535 while (b != current_function_decl)
12539 /* Paranoid sanity check. To be removed */
12540 if (TREE_CODE (b) != BLOCK)
12543 for (current = BLOCK_EXPR_DECLS (b); current;
12544 current = TREE_CHAIN (current))
12545 if (DECL_NAME (current) == name)
12547 b = BLOCK_SUPERCONTEXT (b);
12553 maybe_absorb_scoping_blocks (void)
12555 while (BLOCK_IS_IMPLICIT (GET_CURRENT_BLOCK (current_function_decl)))
12557 tree b = exit_block ();
12558 java_method_add_stmt (current_function_decl, b);
12559 SOURCE_FRONTEND_DEBUG (("Absorbing scoping block at line %d", input_line));
12564 /* This section of the source is reserved to build_* functions that
12565 are building incomplete tree nodes and the patch_* functions that
12566 are completing them. */
12568 /* Wrap a non WFL node around a WFL. */
12571 build_wfl_wrap (tree node, int location)
12573 tree wfl, node_to_insert = node;
12575 /* We want to process THIS . xxx symbolically, to keep it consistent
12576 with the way we're processing SUPER. A THIS from a primary as a
12577 different form than a SUPER. Turn THIS into something symbolic */
12578 if (TREE_CODE (node) == THIS_EXPR)
12579 node_to_insert = wfl = build_wfl_node (this_identifier_node);
12581 #ifdef USE_MAPPED_LOCATION
12582 wfl = build_unknown_wfl (NULL_TREE);
12584 SET_EXPR_LOCATION (wfl, location);
12586 wfl = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
12588 EXPR_WFL_LINECOL (wfl) = location;
12590 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (node_to_insert, NULL_TREE);
12594 /* Build a super() constructor invocation. Returns an empty statement if
12595 we're currently dealing with the class java.lang.Object. */
12598 build_super_invocation (tree mdecl)
12600 if (DECL_CONTEXT (mdecl) == object_type_node)
12601 return build_java_empty_stmt ();
12604 tree super_wfl = build_wfl_node (super_identifier_node);
12605 tree a = NULL_TREE, t;
12607 /* This is called after parsing is done, so the parser context
12608 won't be accurate. Set location info from current_class decl. */
12609 tree class_wfl = lookup_cl (TYPE_NAME (current_class));
12610 EXPR_WFL_LINECOL (super_wfl) = EXPR_WFL_LINECOL (class_wfl);
12612 /* If we're dealing with an anonymous class, pass the arguments
12613 of the crafted constructor along. */
12614 if (ANONYMOUS_CLASS_P (DECL_CONTEXT (mdecl)))
12616 SKIP_THIS_AND_ARTIFICIAL_PARMS (t, mdecl);
12617 for (; t != end_params_node; t = TREE_CHAIN (t))
12618 a = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (t)), a);
12620 return build_method_invocation (super_wfl, a);
12624 /* Build a SUPER/THIS qualified method invocation. */
12627 build_this_super_qualified_invocation (int use_this, tree name, tree args,
12628 int lloc, int rloc)
12632 build_wfl_node (use_this ? this_identifier_node : super_identifier_node);
12633 EXPR_WFL_LINECOL (wfl) = lloc;
12634 invok = build_method_invocation (name, args);
12635 return make_qualified_primary (wfl, invok, rloc);
12638 /* Build an incomplete CALL_EXPR node. */
12641 build_method_invocation (tree name, tree args)
12643 tree call = build3 (CALL_EXPR, NULL_TREE, name, args, NULL_TREE);
12644 TREE_SIDE_EFFECTS (call) = 1;
12645 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
12649 /* Build an incomplete new xxx(...) node. */
12652 build_new_invocation (tree name, tree args)
12654 tree call = build3 (NEW_CLASS_EXPR, NULL_TREE, name, args, NULL_TREE);
12655 TREE_SIDE_EFFECTS (call) = 1;
12656 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
12660 /* Build an incomplete assignment expression. */
12663 build_assignment (int op, int op_location, tree lhs, tree rhs)
12666 /* Build the corresponding binop if we deal with a Compound
12667 Assignment operator. Mark the binop sub-tree as part of a
12668 Compound Assignment expression */
12669 if (op != ASSIGN_TK)
12671 rhs = build_binop (BINOP_LOOKUP (op), op_location, lhs, rhs);
12672 COMPOUND_ASSIGN_P (rhs) = 1;
12674 assignment = build2 (MODIFY_EXPR, NULL_TREE, lhs, rhs);
12675 TREE_SIDE_EFFECTS (assignment) = 1;
12676 EXPR_WFL_LINECOL (assignment) = op_location;
12680 /* Print an INTEGER_CST node as decimal in a static buffer, and return
12681 the buffer. This is used only for string conversion. */
12683 string_convert_int_cst (tree node)
12685 /* Long.MIN_VALUE is -9223372036854775808, 20 characters. */
12686 static char buffer[21];
12688 unsigned HOST_WIDE_INT lo = TREE_INT_CST_LOW (node);
12689 unsigned HOST_WIDE_INT hi = TREE_INT_CST_HIGH (node);
12690 char *p = buffer + sizeof (buffer);
12693 unsigned HOST_WIDE_INT hibit = (((unsigned HOST_WIDE_INT) 1)
12694 << (HOST_BITS_PER_WIDE_INT - 1));
12698 /* If negative, note the fact and negate the value. */
12708 /* Divide by 10 until there are no bits left. */
12711 unsigned HOST_WIDE_INT acc = 0;
12712 unsigned HOST_WIDE_INT outhi = 0, outlo = 0;
12715 /* Use long division to compute the result and the remainder. */
12716 for (i = 0; i < 2 * HOST_BITS_PER_WIDE_INT; ++i)
12718 /* Shift a bit into accumulator. */
12723 /* Shift the value. */
12729 /* Shift the correct bit into the result. */
12731 if ((outlo & hibit))
12741 /* '0' == 060 in Java, but might not be here (think EBCDIC). */
12742 *--p = '\060' + acc;
12750 *--p = '\055'; /* '-' == 055 in Java, but might not be here. */
12755 /* Print an INTEGER_CST node in a static buffer, and return the
12756 buffer. This is used only for error handling. */
12758 print_int_node (tree node)
12760 static char buffer [80];
12761 if (TREE_CONSTANT_OVERFLOW (node))
12762 sprintf (buffer, "<overflow>");
12764 if (TREE_INT_CST_HIGH (node) == 0)
12765 sprintf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
12766 TREE_INT_CST_LOW (node));
12767 else if (TREE_INT_CST_HIGH (node) == -1
12768 && TREE_INT_CST_LOW (node) != 0)
12769 sprintf (buffer, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
12770 -TREE_INT_CST_LOW (node));
12772 sprintf (buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
12773 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
12779 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
12782 /* 15.25 Assignment operators. */
12785 patch_assignment (tree node, tree wfl_op1)
12787 tree rhs = TREE_OPERAND (node, 1);
12788 tree lvalue = TREE_OPERAND (node, 0), llvalue;
12789 tree lhs_type = NULL_TREE, rhs_type, new_rhs = NULL_TREE;
12790 int error_found = 0;
12791 int lvalue_from_array = 0;
12794 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12796 /* Lhs can be a named variable */
12797 if (JDECL_P (lvalue))
12799 lhs_type = TREE_TYPE (lvalue);
12801 /* Or Lhs can be an array access. */
12802 else if (TREE_CODE (lvalue) == ARRAY_REF)
12804 lhs_type = TREE_TYPE (lvalue);
12805 lvalue_from_array = 1;
12807 /* Or a field access */
12808 else if (TREE_CODE (lvalue) == COMPONENT_REF)
12809 lhs_type = TREE_TYPE (lvalue);
12810 /* Or a function return slot */
12811 else if (TREE_CODE (lvalue) == RESULT_DECL)
12813 /* If the return type is an integral type, then we create the
12814 RESULT_DECL with a promoted type, but we need to do these
12815 checks against the unpromoted type to ensure type safety. So
12816 here we look at the real type, not the type of the decl we
12818 lhs_type = TREE_TYPE (TREE_TYPE (current_function_decl));
12821 /* Otherwise, we might want to try to write into an optimized static
12822 final, this is an of a different nature, reported further on. */
12823 else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
12824 && resolve_expression_name (wfl_op1, &llvalue))
12826 lhs_type = TREE_TYPE (lvalue);
12830 parse_error_context (wfl_op1, "Invalid left hand side of assignment");
12834 rhs_type = TREE_TYPE (rhs);
12836 /* 5.1 Try the assignment conversion for builtin type. */
12837 new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
12839 /* 5.2 If it failed, try a reference conversion */
12841 new_rhs = try_reference_assignconv (lhs_type, rhs);
12843 /* 15.25.2 If we have a compound assignment, convert RHS into the
12845 else if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
12846 new_rhs = convert (lhs_type, rhs);
12848 /* Explicit cast required. This is an error */
12851 char *t1 = xstrdup (lang_printable_name (TREE_TYPE (rhs), 0));
12852 char *t2 = xstrdup (lang_printable_name (lhs_type, 0));
12854 char operation [32]; /* Max size known */
12856 /* If the assignment is part of a declaration, we use the WFL of
12857 the declared variable to point out the error and call it a
12858 declaration problem. If the assignment is a genuine =
12859 operator, we call is a operator `=' problem, otherwise we
12860 call it an assignment problem. In both of these last cases,
12861 we use the WFL of the operator to indicate the error. */
12863 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node))
12866 strcpy (operation, "declaration");
12870 wfl = wfl_operator;
12871 if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
12872 strcpy (operation, "assignment");
12873 else if (is_return)
12874 strcpy (operation, "'return'");
12876 strcpy (operation, "'='");
12879 if (!valid_cast_to_p (rhs_type, lhs_type))
12880 parse_error_context
12881 (wfl, "Incompatible type for %s. Can't convert %qs to %qs",
12882 operation, t1, t2);
12884 parse_error_context (wfl, "Incompatible type for %s. Explicit cast needed to convert %qs to %qs",
12885 operation, t1, t2);
12886 free (t1); free (t2);
12891 return error_mark_node;
12893 /* If we're processing a `return' statement, promote the actual type
12894 to the promoted type. */
12896 new_rhs = convert (TREE_TYPE (lvalue), new_rhs);
12898 /* 10.10: Array Store Exception runtime check */
12899 if (!flag_emit_class_files
12901 && lvalue_from_array
12902 && JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type)))
12904 tree array, store_check, base, index_expr;
12906 /* Save RHS so that it doesn't get re-evaluated by the store check. */
12907 new_rhs = save_expr (new_rhs);
12909 /* Get the INDIRECT_REF. */
12910 array = TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0);
12911 /* Get the array pointer expr. */
12912 array = TREE_OPERAND (array, 0);
12913 store_check = build_java_arraystore_check (array, new_rhs);
12915 index_expr = TREE_OPERAND (lvalue, 1);
12917 if (TREE_CODE (index_expr) == COMPOUND_EXPR)
12919 /* A COMPOUND_EXPR here is a bounds check. The bounds check must
12920 happen before the store check, so prepare to insert the store
12921 check within the second operand of the existing COMPOUND_EXPR. */
12927 index_expr = TREE_OPERAND (base, 1);
12928 TREE_OPERAND (base, 1) = build2 (COMPOUND_EXPR, TREE_TYPE (index_expr),
12929 store_check, index_expr);
12932 /* Final locals can be used as case values in switch
12933 statement. Prepare them for this eventuality. */
12934 if (TREE_CODE (lvalue) == VAR_DECL
12935 && DECL_FINAL (lvalue)
12936 && TREE_CONSTANT (new_rhs)
12937 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (lvalue))
12938 && JINTEGRAL_TYPE_P (TREE_TYPE (lvalue))
12941 TREE_CONSTANT (lvalue) = 1;
12942 TREE_INVARIANT (lvalue) = 1;
12943 DECL_INITIAL (lvalue) = new_rhs;
12946 /* Copy the rhs if it's a reference. */
12947 if (! flag_check_references && ! flag_emit_class_files && optimize > 0)
12949 switch (TREE_CODE (new_rhs))
12953 case COMPONENT_REF:
12954 /* Transform a = foo.bar
12955 into a = ({int tmp; tmp = foo.bar;}).
12956 We need to ensure that if a read from memory fails
12957 because of a NullPointerException, a destination variable
12958 will remain unchanged. An explicit temporary does what
12961 If flag_check_references is set, this is unnecessary
12962 because we'll check each reference before doing any
12963 reads. If optimize is not set the result will never be
12964 written to a stack slot that contains the LHS. */
12966 tree tmp = build_decl (VAR_DECL, get_identifier ("<tmp>"),
12967 TREE_TYPE (new_rhs));
12968 tree block = make_node (BLOCK);
12970 = build2 (MODIFY_EXPR, TREE_TYPE (new_rhs), tmp, fold (new_rhs));
12971 DECL_CONTEXT (tmp) = current_function_decl;
12972 TREE_TYPE (block) = TREE_TYPE (new_rhs);
12973 BLOCK_VARS (block) = tmp;
12974 BLOCK_EXPR_BODY (block) = assignment;
12975 TREE_SIDE_EFFECTS (block) = 1;
12984 TREE_OPERAND (node, 0) = lvalue;
12985 TREE_OPERAND (node, 1) = new_rhs;
12986 TREE_TYPE (node) = lhs_type;
12990 /* Check that type SOURCE can be cast into type DEST. If the cast
12991 can't occur at all, return NULL; otherwise, return a possibly
12995 try_reference_assignconv (tree lhs_type, tree rhs)
12997 tree new_rhs = NULL_TREE;
12998 tree rhs_type = TREE_TYPE (rhs);
13000 if (!JPRIMITIVE_TYPE_P (rhs_type) && JREFERENCE_TYPE_P (lhs_type))
13002 /* `null' may be assigned to any reference type */
13003 if (rhs == null_pointer_node)
13004 new_rhs = null_pointer_node;
13005 /* Try the reference assignment conversion */
13006 else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
13008 /* This is a magic assignment that we process differently */
13009 else if (TREE_CODE (rhs) == JAVA_EXC_OBJ_EXPR)
13015 /* Check that RHS can be converted into LHS_TYPE by the assignment
13016 conversion (5.2), for the cases of RHS being a builtin type. Return
13017 NULL_TREE if the conversion fails or if because RHS isn't of a
13018 builtin type. Return a converted RHS if the conversion is possible. */
13021 try_builtin_assignconv (tree wfl_op1, tree lhs_type, tree rhs)
13023 tree new_rhs = NULL_TREE;
13024 tree rhs_type = TREE_TYPE (rhs);
13026 /* Handle boolean specially. */
13027 if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
13028 || TREE_CODE (lhs_type) == BOOLEAN_TYPE)
13030 if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
13031 && TREE_CODE (lhs_type) == BOOLEAN_TYPE)
13035 /* 5.1.1 Try Identity Conversion,
13036 5.1.2 Try Widening Primitive Conversion */
13037 else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
13038 new_rhs = convert (lhs_type, rhs);
13040 /* Try a narrowing primitive conversion (5.1.3):
13041 - expression is a constant expression of type byte, short, char,
13043 - variable is byte, short or char AND
13044 - The value of the expression is representable in the type of the
13046 else if ((rhs_type == byte_type_node || rhs_type == short_type_node
13047 || rhs_type == char_type_node || rhs_type == int_type_node)
13048 && TREE_CONSTANT (rhs)
13049 && (lhs_type == byte_type_node || lhs_type == char_type_node
13050 || lhs_type == short_type_node))
13052 if (int_fits_type_p (rhs, lhs_type))
13053 new_rhs = convert (lhs_type, rhs);
13054 else if (wfl_op1) /* Might be called with a NULL */
13055 parse_warning_context
13057 "Constant expression %qs too wide for narrowing primitive conversion to %qs",
13058 print_int_node (rhs), lang_printable_name (lhs_type, 0));
13059 /* Reported a warning that will turn into an error further
13060 down, so we don't return */
13066 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
13067 conversion (5.1.1) or widening primitive conversion (5.1.2). Return
13068 0 is the conversion test fails. This implements parts the method
13069 invocation conversion (5.3). */
13072 valid_builtin_assignconv_identity_widening_p (tree lhs_type, tree rhs_type)
13074 /* 5.1.1: This is the identity conversion part. */
13075 if (lhs_type == rhs_type)
13078 /* Reject non primitive types and boolean conversions. */
13079 if (!JNUMERIC_TYPE_P (lhs_type) || !JNUMERIC_TYPE_P (rhs_type))
13082 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
13083 than a char can't be converted into a char. Short can't too, but
13084 the < test below takes care of that */
13085 if (lhs_type == char_type_node && rhs_type == byte_type_node)
13088 /* Accept all promoted type here. Note, we can't use <= in the test
13089 below, because we still need to bounce out assignments of short
13090 to char and the likes */
13091 if (lhs_type == int_type_node
13092 && (rhs_type == promoted_byte_type_node
13093 || rhs_type == promoted_short_type_node
13094 || rhs_type == promoted_char_type_node
13095 || rhs_type == promoted_boolean_type_node))
13098 /* From here, an integral is widened if its precision is smaller
13099 than the precision of the LHS or if the LHS is a floating point
13100 type, or the RHS is a float and the RHS a double. */
13101 if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type)
13102 && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
13103 || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
13104 || (rhs_type == float_type_node && lhs_type == double_type_node))
13110 /* Check that something of SOURCE type can be assigned or cast to
13111 something of DEST type at runtime. Return 1 if the operation is
13112 valid, 0 otherwise. If CAST is set to 1, we're treating the case
13113 were SOURCE is cast into DEST, which borrows a lot of the
13114 assignment check. */
13117 valid_ref_assignconv_cast_p (tree source, tree dest, int cast)
13119 /* SOURCE or DEST might be null if not from a declared entity. */
13120 if (!source || !dest)
13122 if (JNULLP_TYPE_P (source))
13124 if (TREE_CODE (source) == POINTER_TYPE)
13125 source = TREE_TYPE (source);
13126 if (TREE_CODE (dest) == POINTER_TYPE)
13127 dest = TREE_TYPE (dest);
13129 /* If source and dest are being compiled from bytecode, they may need to
13131 if (CLASS_P (source) && !CLASS_LOADED_P (source))
13133 load_class (source, 1);
13134 safe_layout_class (source);
13136 if (CLASS_P (dest) && !CLASS_LOADED_P (dest))
13138 load_class (dest, 1);
13139 safe_layout_class (dest);
13142 /* Case where SOURCE is a class type */
13143 if (TYPE_CLASS_P (source))
13145 if (TYPE_CLASS_P (dest))
13146 return (source == dest
13147 || inherits_from_p (source, dest)
13148 || (cast && inherits_from_p (dest, source)));
13149 if (TYPE_INTERFACE_P (dest))
13151 /* If doing a cast and SOURCE is final, the operation is
13152 always correct a compile time (because even if SOURCE
13153 does not implement DEST, a subclass of SOURCE might). */
13154 if (cast && !CLASS_FINAL (TYPE_NAME (source)))
13156 /* Otherwise, SOURCE must implement DEST */
13157 return interface_of_p (dest, source);
13159 /* DEST is an array, cast permitted if SOURCE is of Object type */
13160 return (cast && source == object_type_node ? 1 : 0);
13162 if (TYPE_INTERFACE_P (source))
13164 if (TYPE_CLASS_P (dest))
13166 /* If not casting, DEST must be the Object type */
13168 return dest == object_type_node;
13169 /* We're doing a cast. The cast is always valid is class
13170 DEST is not final, otherwise, DEST must implement SOURCE */
13171 else if (!CLASS_FINAL (TYPE_NAME (dest)))
13174 return interface_of_p (source, dest);
13176 if (TYPE_INTERFACE_P (dest))
13178 /* If doing a cast, then if SOURCE and DEST contain method
13179 with the same signature but different return type, then
13180 this is a (compile time) error */
13183 tree method_source, method_dest;
13187 for (method_source = TYPE_METHODS (source); method_source;
13188 method_source = TREE_CHAIN (method_source))
13191 build_java_argument_signature (TREE_TYPE (method_source));
13192 source_type = TREE_TYPE (TREE_TYPE (method_source));
13193 source_name = DECL_NAME (method_source);
13194 for (method_dest = TYPE_METHODS (dest);
13195 method_dest; method_dest = TREE_CHAIN (method_dest))
13197 build_java_argument_signature (TREE_TYPE (method_dest))
13198 && source_name == DECL_NAME (method_dest)
13199 && source_type != TREE_TYPE (TREE_TYPE (method_dest)))
13205 return source == dest || interface_of_p (dest, source);
13211 && (DECL_NAME (TYPE_NAME (source))
13212 == java_lang_cloneable_identifier_node
13213 || (DECL_NAME (TYPE_NAME (source))
13214 == java_io_serializable_identifier_node)));
13217 if (TYPE_ARRAY_P (source))
13219 if (TYPE_CLASS_P (dest))
13220 return dest == object_type_node;
13221 /* Can't cast an array to an interface unless the interface is
13222 java.lang.Cloneable or java.io.Serializable. */
13223 if (TYPE_INTERFACE_P (dest))
13224 return (DECL_NAME (TYPE_NAME (dest))
13225 == java_lang_cloneable_identifier_node
13226 || (DECL_NAME (TYPE_NAME (dest))
13227 == java_io_serializable_identifier_node));
13230 tree source_element_type = TYPE_ARRAY_ELEMENT (source);
13231 tree dest_element_type = TYPE_ARRAY_ELEMENT (dest);
13233 /* In case of severe errors, they turn out null */
13234 if (!dest_element_type || !source_element_type)
13236 if (source_element_type == dest_element_type)
13238 return valid_ref_assignconv_cast_p (source_element_type,
13239 dest_element_type, cast);
13247 valid_cast_to_p (tree source, tree dest)
13249 if (TREE_CODE (source) == POINTER_TYPE)
13250 source = TREE_TYPE (source);
13251 if (TREE_CODE (dest) == POINTER_TYPE)
13252 dest = TREE_TYPE (dest);
13254 if (TREE_CODE (source) == RECORD_TYPE && TREE_CODE (dest) == RECORD_TYPE)
13255 return valid_ref_assignconv_cast_p (source, dest, 1);
13257 else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
13260 else if (TREE_CODE (source) == BOOLEAN_TYPE
13261 && TREE_CODE (dest) == BOOLEAN_TYPE)
13268 do_unary_numeric_promotion (tree arg)
13270 tree type = TREE_TYPE (arg);
13271 if ((TREE_CODE (type) == INTEGER_TYPE && TYPE_PRECISION (type) < 32)
13272 || TREE_CODE (type) == CHAR_TYPE)
13273 arg = convert (int_type_node, arg);
13277 /* Return a nonzero value if SOURCE can be converted into DEST using
13278 the method invocation conversion rule (5.3). */
13280 valid_method_invocation_conversion_p (tree dest, tree source)
13282 return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
13283 && valid_builtin_assignconv_identity_widening_p (dest, source))
13284 || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
13285 && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
13286 && valid_ref_assignconv_cast_p (source, dest, 0)));
13289 /* Build an incomplete binop expression. */
13292 build_binop (enum tree_code op, int op_location, tree op1, tree op2)
13294 tree binop = build2 (op, NULL_TREE, op1, op2);
13295 TREE_SIDE_EFFECTS (binop) = 1;
13296 /* Store the location of the operator, for better error report. The
13297 string of the operator will be rebuild based on the OP value. */
13298 EXPR_WFL_LINECOL (binop) = op_location;
13302 /* Build the string of the operator retained by NODE. If NODE is part
13303 of a compound expression, add an '=' at the end of the string. This
13304 function is called when an error needs to be reported on an
13305 operator. The string is returned as a pointer to a static character
13309 operator_string (tree node)
13311 #define BUILD_OPERATOR_STRING(S) \
13313 sprintf (buffer, "%s%s", S, (COMPOUND_ASSIGN_P (node) ? "=" : "")); \
13317 static char buffer [10];
13318 switch (TREE_CODE (node))
13320 case MULT_EXPR: BUILD_OPERATOR_STRING ("*");
13321 case RDIV_EXPR: BUILD_OPERATOR_STRING ("/");
13322 case TRUNC_MOD_EXPR: BUILD_OPERATOR_STRING ("%");
13323 case PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
13324 case MINUS_EXPR: BUILD_OPERATOR_STRING ("-");
13325 case LSHIFT_EXPR: BUILD_OPERATOR_STRING ("<<");
13326 case RSHIFT_EXPR: BUILD_OPERATOR_STRING (">>");
13327 case URSHIFT_EXPR: BUILD_OPERATOR_STRING (">>>");
13328 case BIT_AND_EXPR: BUILD_OPERATOR_STRING ("&");
13329 case BIT_XOR_EXPR: BUILD_OPERATOR_STRING ("^");
13330 case BIT_IOR_EXPR: BUILD_OPERATOR_STRING ("|");
13331 case TRUTH_ANDIF_EXPR: BUILD_OPERATOR_STRING ("&&");
13332 case TRUTH_ORIF_EXPR: BUILD_OPERATOR_STRING ("||");
13333 case EQ_EXPR: BUILD_OPERATOR_STRING ("==");
13334 case NE_EXPR: BUILD_OPERATOR_STRING ("!=");
13335 case GT_EXPR: BUILD_OPERATOR_STRING (">");
13336 case GE_EXPR: BUILD_OPERATOR_STRING (">=");
13337 case LT_EXPR: BUILD_OPERATOR_STRING ("<");
13338 case LE_EXPR: BUILD_OPERATOR_STRING ("<=");
13339 case UNARY_PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
13340 case NEGATE_EXPR: BUILD_OPERATOR_STRING ("-");
13341 case TRUTH_NOT_EXPR: BUILD_OPERATOR_STRING ("!");
13342 case BIT_NOT_EXPR: BUILD_OPERATOR_STRING ("~");
13343 case PREINCREMENT_EXPR: /* Fall through */
13344 case POSTINCREMENT_EXPR: BUILD_OPERATOR_STRING ("++");
13345 case PREDECREMENT_EXPR: /* Fall through */
13346 case POSTDECREMENT_EXPR: BUILD_OPERATOR_STRING ("--");
13348 internal_error ("unregistered operator %s",
13349 tree_code_name [TREE_CODE (node)]);
13352 #undef BUILD_OPERATOR_STRING
13355 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
13358 java_decl_equiv (tree var_acc1, tree var_acc2)
13360 if (JDECL_P (var_acc1))
13361 return (var_acc1 == var_acc2);
13363 return (TREE_CODE (var_acc1) == COMPONENT_REF
13364 && TREE_CODE (var_acc2) == COMPONENT_REF
13365 && TREE_OPERAND (TREE_OPERAND (var_acc1, 0), 0)
13366 == TREE_OPERAND (TREE_OPERAND (var_acc2, 0), 0)
13367 && TREE_OPERAND (var_acc1, 1) == TREE_OPERAND (var_acc2, 1));
13370 /* Return a nonzero value if CODE is one of the operators that can be
13371 used in conjunction with the `=' operator in a compound assignment. */
13374 binop_compound_p (enum tree_code code)
13377 for (i = 0; i < BINOP_COMPOUND_CANDIDATES; i++)
13378 if (binop_lookup [i] == code)
13381 return i < BINOP_COMPOUND_CANDIDATES;
13384 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
13387 java_refold (tree t)
13389 tree c, b, ns, decl;
13391 if (TREE_CODE (t) != MODIFY_EXPR)
13394 c = TREE_OPERAND (t, 1);
13395 if (! (c && TREE_CODE (c) == COMPOUND_EXPR
13396 && TREE_CODE (TREE_OPERAND (c, 0)) == MODIFY_EXPR
13397 && binop_compound_p (TREE_CODE (TREE_OPERAND (c, 1)))))
13400 /* Now the left branch of the binary operator. */
13401 b = TREE_OPERAND (TREE_OPERAND (c, 1), 0);
13402 if (! (b && TREE_CODE (b) == NOP_EXPR
13403 && TREE_CODE (TREE_OPERAND (b, 0)) == SAVE_EXPR))
13406 ns = TREE_OPERAND (TREE_OPERAND (b, 0), 0);
13407 if (! (ns && TREE_CODE (ns) == NOP_EXPR
13408 && TREE_CODE (TREE_OPERAND (ns, 0)) == SAVE_EXPR))
13411 decl = TREE_OPERAND (TREE_OPERAND (ns, 0), 0);
13412 if ((JDECL_P (decl) || TREE_CODE (decl) == COMPONENT_REF)
13413 /* It's got to be the an equivalent decl */
13414 && java_decl_equiv (decl, TREE_OPERAND (TREE_OPERAND (c, 0), 0)))
13416 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
13417 TREE_OPERAND (TREE_OPERAND (c, 1), 0) = TREE_OPERAND (ns, 0);
13418 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
13419 TREE_OPERAND (t, 1) = TREE_OPERAND (c, 1);
13420 /* Change the right part of the BINOP_EXPR */
13421 TREE_OPERAND (TREE_OPERAND (t, 1), 1) = TREE_OPERAND (c, 0);
13427 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
13428 errors but we modify NODE so that it contains the type computed
13429 according to the expression, when it's fixed. Otherwise, we write
13430 error_mark_node as the type. It allows us to further the analysis
13431 of remaining nodes and detects more errors in certain cases. */
13434 patch_binop (tree node, tree wfl_op1, tree wfl_op2)
13436 tree op1 = TREE_OPERAND (node, 0);
13437 tree op2 = TREE_OPERAND (node, 1);
13438 tree op1_type = TREE_TYPE (op1);
13439 tree op2_type = TREE_TYPE (op2);
13440 tree prom_type = NULL_TREE, cn;
13441 enum tree_code code = TREE_CODE (node);
13443 /* If 1, tell the routine that we have to return error_mark_node
13444 after checking for the initialization of the RHS */
13445 int error_found = 0;
13447 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13449 /* If either op<n>_type are NULL, this might be early signs of an
13450 error situation, unless it's too early to tell (in case we're
13451 handling a `+', `==', `!=' or `instanceof'.) We want to set op<n>_type
13452 correctly so the error can be later on reported accurately. */
13453 if (! (code == PLUS_EXPR || code == NE_EXPR
13454 || code == EQ_EXPR || code == INSTANCEOF_EXPR))
13459 n = java_complete_tree (op1);
13460 op1_type = TREE_TYPE (n);
13464 n = java_complete_tree (op2);
13465 op2_type = TREE_TYPE (n);
13471 /* 15.16 Multiplicative operators */
13472 case MULT_EXPR: /* 15.16.1 Multiplication Operator * */
13473 case RDIV_EXPR: /* 15.16.2 Division Operator / */
13474 case TRUNC_DIV_EXPR: /* 15.16.2 Integral type Division Operator / */
13475 case TRUNC_MOD_EXPR: /* 15.16.3 Remainder operator % */
13476 if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
13478 if (!JNUMERIC_TYPE_P (op1_type))
13479 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13480 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13481 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13482 TREE_TYPE (node) = error_mark_node;
13486 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13488 /* Detect integral division by zero */
13489 if ((code == RDIV_EXPR || code == TRUNC_MOD_EXPR)
13490 && TREE_CODE (prom_type) == INTEGER_TYPE
13491 && (op2 == integer_zero_node || op2 == long_zero_node ||
13492 (TREE_CODE (op2) == INTEGER_CST &&
13493 ! TREE_INT_CST_LOW (op2) && ! TREE_INT_CST_HIGH (op2))))
13495 parse_warning_context
13497 "Evaluating this expression will result in an arithmetic exception being thrown");
13498 TREE_CONSTANT (node) = 0;
13499 TREE_INVARIANT (node) = 0;
13502 /* Change the division operator if necessary */
13503 if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
13504 TREE_SET_CODE (node, TRUNC_DIV_EXPR);
13506 /* Before divisions as is disappear, try to simplify and bail if
13507 applicable, otherwise we won't perform even simple
13508 simplifications like (1-1)/3. We can't do that with floating
13509 point number, folds can't handle them at this stage. */
13510 if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2)
13511 && JINTEGRAL_TYPE_P (op1) && JINTEGRAL_TYPE_P (op2))
13513 TREE_TYPE (node) = prom_type;
13514 node = fold (node);
13515 if (TREE_CODE (node) != code)
13519 if (TREE_CODE (prom_type) == INTEGER_TYPE
13520 && flag_use_divide_subroutine
13521 && ! flag_emit_class_files
13522 && (code == RDIV_EXPR || code == TRUNC_MOD_EXPR))
13523 return build_java_soft_divmod (TREE_CODE (node), prom_type, op1, op2);
13525 /* This one is more complicated. FLOATs are processed by a
13526 function call to soft_fmod. Duplicate the value of the
13527 COMPOUND_ASSIGN_P flag. */
13528 if (code == TRUNC_MOD_EXPR)
13530 tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
13531 COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
13536 /* 15.17 Additive Operators */
13537 case PLUS_EXPR: /* 15.17.1 String Concatenation Operator + */
13539 /* Operation is valid if either one argument is a string
13540 constant, a String object or a StringBuffer crafted for the
13541 purpose of the a previous usage of the String concatenation
13544 if (TREE_CODE (op1) == STRING_CST
13545 || TREE_CODE (op2) == STRING_CST
13546 || JSTRING_TYPE_P (op1_type)
13547 || JSTRING_TYPE_P (op2_type)
13548 || IS_CRAFTED_STRING_BUFFER_P (op1)
13549 || IS_CRAFTED_STRING_BUFFER_P (op2))
13550 return build_string_concatenation (op1, op2);
13552 case MINUS_EXPR: /* 15.17.2 Additive Operators (+ and -) for
13554 if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
13556 if (!JNUMERIC_TYPE_P (op1_type))
13557 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13558 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13559 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13560 TREE_TYPE (node) = error_mark_node;
13564 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13567 /* 15.18 Shift Operators */
13571 if (!JINTEGRAL_TYPE_P (op1_type) || !JINTEGRAL_TYPE_P (op2_type))
13573 if (!JINTEGRAL_TYPE_P (op1_type))
13574 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
13577 if (JNUMERIC_TYPE_P (op2_type))
13578 parse_error_context (wfl_operator,
13579 "Incompatible type for %qs. Explicit cast needed to convert shift distance from %qs to integral",
13580 operator_string (node),
13581 lang_printable_name (op2_type, 0));
13583 parse_error_context (wfl_operator,
13584 "Incompatible type for %qs. Can't convert shift distance from %qs to integral",
13585 operator_string (node),
13586 lang_printable_name (op2_type, 0));
13588 TREE_TYPE (node) = error_mark_node;
13593 /* Unary numeric promotion (5.6.1) is performed on each operand
13595 op1 = do_unary_numeric_promotion (op1);
13596 op2 = do_unary_numeric_promotion (op2);
13598 /* If the right hand side is of type `long', first cast it to
13600 if (TREE_TYPE (op2) == long_type_node)
13601 op2 = build1 (CONVERT_EXPR, int_type_node, op2);
13603 /* The type of the shift expression is the type of the promoted
13604 type of the left-hand operand */
13605 prom_type = TREE_TYPE (op1);
13607 /* Shift int only up to 0x1f and long up to 0x3f */
13608 if (prom_type == int_type_node)
13609 op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
13610 build_int_cst (NULL_TREE, 0x1f)));
13612 op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
13613 build_int_cst (NULL_TREE, 0x3f)));
13615 /* The >>> operator is a >> operating on unsigned quantities */
13616 if (code == URSHIFT_EXPR && ! flag_emit_class_files)
13619 tree utype = java_unsigned_type (prom_type);
13620 op1 = convert (utype, op1);
13621 TREE_SET_CODE (node, RSHIFT_EXPR);
13622 TREE_OPERAND (node, 0) = op1;
13623 TREE_OPERAND (node, 1) = op2;
13624 TREE_TYPE (node) = utype;
13625 to_return = convert (prom_type, node);
13626 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
13627 COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
13628 TREE_SIDE_EFFECTS (to_return)
13629 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13634 /* 15.19.1 Type Comparison Operator instanceof */
13635 case INSTANCEOF_EXPR:
13637 TREE_TYPE (node) = boolean_type_node;
13639 /* OP1_TYPE might be NULL when OP1 is a string constant. */
13640 if ((cn = patch_string (op1)))
13643 op1_type = TREE_TYPE (op1);
13645 if (op1_type == NULL_TREE)
13648 if (!(op2_type = resolve_type_during_patch (op2)))
13649 return error_mark_node;
13651 /* The first operand must be a reference type or the null type */
13652 if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
13653 error_found = 1; /* Error reported further below */
13655 /* The second operand must be a reference type */
13656 if (!JREFERENCE_TYPE_P (op2_type))
13658 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
13659 parse_error_context
13660 (wfl_operator, "Invalid argument %qs for %<instanceof%>",
13661 lang_printable_name (op2_type, 0));
13665 if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
13667 /* If the first operand is null, the result is always false */
13668 if (op1 == null_pointer_node)
13669 return boolean_false_node;
13670 else if (flag_emit_class_files)
13672 TREE_OPERAND (node, 1) = op2_type;
13673 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
13676 /* Otherwise we have to invoke instance of to figure it out */
13678 return build_instanceof (op1, op2_type);
13680 /* There is no way the expression operand can be an instance of
13681 the type operand. This is a compile time error. */
13684 char *t1 = xstrdup (lang_printable_name (op1_type, 0));
13685 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
13686 parse_error_context
13687 (wfl_operator, "Impossible for %qs to be instance of %qs",
13688 t1, lang_printable_name (op2_type, 0));
13695 /* 15.21 Bitwise and Logical Operators */
13699 if (JINTEGRAL_TYPE_P (op1_type) && JINTEGRAL_TYPE_P (op2_type))
13700 /* Binary numeric promotion is performed on both operand and the
13701 expression retain that type */
13702 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13704 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE
13705 && TREE_CODE (op1_type) == BOOLEAN_TYPE)
13706 /* The type of the bitwise operator expression is BOOLEAN */
13707 prom_type = boolean_type_node;
13710 if (!JINTEGRAL_TYPE_P (op1_type))
13711 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
13712 if (!JINTEGRAL_TYPE_P (op2_type) && (op1_type != op2_type))
13713 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op2_type);
13714 TREE_TYPE (node) = error_mark_node;
13716 /* Insert a break here if adding thing before the switch's
13717 break for this case */
13721 /* 15.22 Conditional-And Operator */
13722 case TRUTH_ANDIF_EXPR:
13723 /* 15.23 Conditional-Or Operator */
13724 case TRUTH_ORIF_EXPR:
13725 /* Operands must be of BOOLEAN type */
13726 if (TREE_CODE (op1_type) != BOOLEAN_TYPE ||
13727 TREE_CODE (op2_type) != BOOLEAN_TYPE)
13729 if (TREE_CODE (op1_type) != BOOLEAN_TYPE)
13730 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op1_type);
13731 if (TREE_CODE (op2_type) != BOOLEAN_TYPE && (op1_type != op2_type))
13732 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op2_type);
13733 TREE_TYPE (node) = boolean_type_node;
13737 else if (integer_zerop (op1))
13739 return code == TRUTH_ANDIF_EXPR ? op1 : op2;
13741 else if (integer_onep (op1))
13743 return code == TRUTH_ANDIF_EXPR ? op2 : op1;
13745 /* The type of the conditional operators is BOOLEAN */
13746 prom_type = boolean_type_node;
13749 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
13754 /* The type of each of the operands must be a primitive numeric
13756 if (!JNUMERIC_TYPE_P (op1_type) || ! JNUMERIC_TYPE_P (op2_type))
13758 if (!JNUMERIC_TYPE_P (op1_type))
13759 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
13760 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
13761 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
13762 TREE_TYPE (node) = boolean_type_node;
13766 /* Binary numeric promotion is performed on the operands */
13767 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13768 /* The type of the relation expression is always BOOLEAN */
13769 prom_type = boolean_type_node;
13772 /* 15.20 Equality Operator */
13775 /* It's time for us to patch the strings. */
13776 if ((cn = patch_string (op1)))
13779 op1_type = TREE_TYPE (op1);
13781 if ((cn = patch_string (op2)))
13784 op2_type = TREE_TYPE (op2);
13787 /* 15.20.1 Numerical Equality Operators == and != */
13788 /* Binary numeric promotion is performed on the operands */
13789 if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
13790 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
13792 /* 15.20.2 Boolean Equality Operators == and != */
13793 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE &&
13794 TREE_CODE (op2_type) == BOOLEAN_TYPE)
13795 ; /* Nothing to do here */
13797 /* 15.20.3 Reference Equality Operators == and != */
13798 /* Types have to be either references or the null type. If
13799 they're references, it must be possible to convert either
13800 type to the other by casting conversion. */
13801 else if ((op1 == null_pointer_node && op2 == null_pointer_node)
13802 || (op1 == null_pointer_node && JREFERENCE_TYPE_P (op2_type))
13803 || (JREFERENCE_TYPE_P (op1_type) && op2 == null_pointer_node)
13804 || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
13805 && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
13806 || valid_ref_assignconv_cast_p (op2_type,
13808 ; /* Nothing to do here */
13810 /* Else we have an error figure what can't be converted into
13811 what and report the error */
13815 t1 = xstrdup (lang_printable_name (op1_type, 0));
13816 parse_error_context
13818 "Incompatible type for %qs. Can't convert %qs to %qs",
13819 operator_string (node), t1,
13820 lang_printable_name (op2_type, 0));
13822 TREE_TYPE (node) = boolean_type_node;
13826 prom_type = boolean_type_node;
13833 return error_mark_node;
13835 TREE_OPERAND (node, 0) = op1;
13836 TREE_OPERAND (node, 1) = op2;
13837 TREE_TYPE (node) = prom_type;
13838 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13840 if (flag_emit_xref)
13843 /* fold does not respect side-effect order as required for Java but not C.
13844 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
13847 if (flag_emit_class_files ? (TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
13848 : ! TREE_SIDE_EFFECTS (node))
13849 node = fold (node);
13853 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
13854 zero value, the value of CSTE comes after the valude of STRING */
13857 do_merge_string_cste (tree cste, const char *string, int string_len, int after)
13859 const char *old = TREE_STRING_POINTER (cste);
13860 int old_len = TREE_STRING_LENGTH (cste);
13861 int len = old_len + string_len;
13862 char *new = alloca (len+1);
13866 memcpy (new, string, string_len);
13867 memcpy (&new [string_len], old, old_len);
13871 memcpy (new, old, old_len);
13872 memcpy (&new [old_len], string, string_len);
13875 return build_string (len, new);
13878 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
13879 new STRING_CST on success, NULL_TREE on failure. */
13882 merge_string_cste (tree op1, tree op2, int after)
13884 /* Handle two string constants right away. */
13885 if (TREE_CODE (op2) == STRING_CST)
13886 return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
13887 TREE_STRING_LENGTH (op2), after);
13889 /* Reasonable integer constant can be treated right away. */
13890 if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
13892 static const char *const boolean_true = "true";
13893 static const char *const boolean_false = "false";
13894 static const char *const null_pointer = "null";
13896 const char *string;
13898 if (op2 == boolean_true_node)
13899 string = boolean_true;
13900 else if (op2 == boolean_false_node)
13901 string = boolean_false;
13902 else if (op2 == null_pointer_node
13903 || (integer_zerop (op2)
13904 && TREE_CODE (TREE_TYPE (op2)) == POINTER_TYPE))
13905 /* FIXME: null is not a compile-time constant, so it is only safe to
13906 merge if the overall expression is non-constant. However, this
13907 code always merges without checking the overall expression. */
13908 string = null_pointer;
13909 else if (TREE_TYPE (op2) == char_type_node)
13911 /* Convert the character into UTF-8. */
13912 unsigned int c = (unsigned int) TREE_INT_CST_LOW (op2);
13913 unsigned char *p = (unsigned char *) ch;
13914 if (0x01 <= c && c <= 0x7f)
13915 *p++ = (unsigned char) c;
13916 else if (c < 0x7ff)
13918 *p++ = (unsigned char) (c >> 6 | 0xc0);
13919 *p++ = (unsigned char) ((c & 0x3f) | 0x80);
13923 *p++ = (unsigned char) (c >> 12 | 0xe0);
13924 *p++ = (unsigned char) (((c >> 6) & 0x3f) | 0x80);
13925 *p++ = (unsigned char) ((c & 0x3f) | 0x80);
13932 string = string_convert_int_cst (op2);
13934 return do_merge_string_cste (op1, string, strlen (string), after);
13939 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
13940 has to be a STRING_CST and the other part must be a STRING_CST or a
13941 INTEGRAL constant. Return a new STRING_CST if the operation
13942 succeed, NULL_TREE otherwise.
13944 If the case we want to optimize for space, we might want to return
13945 NULL_TREE for each invocation of this routine. FIXME */
13948 string_constant_concatenation (tree op1, tree op2)
13950 if (TREE_CODE (op1) == STRING_CST || (TREE_CODE (op2) == STRING_CST))
13955 string = (TREE_CODE (op1) == STRING_CST ? op1 : op2);
13956 rest = (string == op1 ? op2 : op1);
13957 invert = (string == op1 ? 0 : 1 );
13959 /* Walk REST, only if it looks reasonable */
13960 if (TREE_CODE (rest) != STRING_CST
13961 && !IS_CRAFTED_STRING_BUFFER_P (rest)
13962 && !JSTRING_TYPE_P (TREE_TYPE (rest))
13963 && TREE_CODE (rest) == EXPR_WITH_FILE_LOCATION)
13965 rest = java_complete_tree (rest);
13966 if (rest == error_mark_node)
13967 return error_mark_node;
13968 rest = fold (rest);
13970 return merge_string_cste (string, rest, invert);
13975 /* Implement the `+' operator. Does static optimization if possible,
13976 otherwise create (if necessary) and append elements to a
13977 StringBuffer. The StringBuffer will be carried around until it is
13978 used for a function call or an assignment. Then toString() will be
13979 called on it to turn it into a String object. */
13982 build_string_concatenation (tree op1, tree op2)
13985 int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
13987 if (flag_emit_xref)
13988 return build2 (PLUS_EXPR, string_type_node, op1, op2);
13990 /* Try to do some static optimization */
13991 if ((result = string_constant_concatenation (op1, op2)))
13994 /* Discard empty strings on either side of the expression */
13995 if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
14000 else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
14003 /* If operands are string constant, turn then into object references */
14004 if (TREE_CODE (op1) == STRING_CST)
14005 op1 = patch_string_cst (op1);
14006 if (op2 && TREE_CODE (op2) == STRING_CST)
14007 op2 = patch_string_cst (op2);
14009 /* If either one of the constant is null and the other non null
14010 operand is a String constant, return it. */
14011 if ((TREE_CODE (op1) == STRING_CST) && !op2)
14014 /* If OP1 isn't already a StringBuffer, create and
14015 initialize a new one */
14016 if (!IS_CRAFTED_STRING_BUFFER_P (op1))
14018 /* Two solutions here:
14019 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
14020 2) OP1 is something else, we call new StringBuffer().append(OP1). */
14021 if (TREE_CONSTANT (op1) && JSTRING_TYPE_P (TREE_TYPE (op1)))
14022 op1 = BUILD_STRING_BUFFER (op1);
14025 tree aNew = BUILD_STRING_BUFFER (NULL_TREE);
14026 op1 = make_qualified_primary (aNew, BUILD_APPEND (op1), 0);
14032 /* OP1 is no longer the last node holding a crafted StringBuffer */
14033 IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
14034 /* Create a node for `{new...,xxx}.append (op2)' */
14036 op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
14039 /* Mark the last node holding a crafted StringBuffer */
14040 IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
14042 TREE_SIDE_EFFECTS (op1) = side_effects;
14046 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
14047 StringBuffer. If no string were found to be patched, return
14051 patch_string (tree node)
14053 if (node == error_mark_node)
14054 return error_mark_node;
14055 if (TREE_CODE (node) == STRING_CST)
14056 return patch_string_cst (node);
14057 else if (IS_CRAFTED_STRING_BUFFER_P (node))
14059 int saved = ctxp->explicit_constructor_p;
14060 tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
14062 /* Temporary disable forbid the use of `this'. */
14063 ctxp->explicit_constructor_p = 0;
14064 ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
14065 /* String concatenation arguments must be evaluated in order too. */
14066 ret = force_evaluation_order (ret);
14067 /* Restore it at its previous value */
14068 ctxp->explicit_constructor_p = saved;
14074 /* Build the internal representation of a string constant. */
14077 patch_string_cst (tree node)
14080 if (! flag_emit_class_files)
14082 node = get_identifier (TREE_STRING_POINTER (node));
14083 location = alloc_name_constant (CONSTANT_String, node);
14084 node = build_ref_from_constant_pool (location);
14086 TREE_CONSTANT (node) = 1;
14087 TREE_INVARIANT (node) = 1;
14089 /* ??? Guessing that the class file code can't handle casts. */
14090 if (! flag_emit_class_files)
14091 node = convert (string_ptr_type_node, node);
14093 TREE_TYPE (node) = string_ptr_type_node;
14098 /* Build an incomplete unary operator expression. */
14101 build_unaryop (int op_token, int op_location, tree op1)
14107 case PLUS_TK: op = UNARY_PLUS_EXPR; break;
14108 case MINUS_TK: op = NEGATE_EXPR; break;
14109 case NEG_TK: op = TRUTH_NOT_EXPR; break;
14110 case NOT_TK: op = BIT_NOT_EXPR; break;
14114 unaryop = build1 (op, NULL_TREE, op1);
14115 TREE_SIDE_EFFECTS (unaryop) = 1;
14116 /* Store the location of the operator, for better error report. The
14117 string of the operator will be rebuild based on the OP value. */
14118 EXPR_WFL_LINECOL (unaryop) = op_location;
14122 /* Special case for the ++/-- operators, since they require an extra
14123 argument to build, which is set to NULL and patched
14124 later. IS_POST_P is 1 if the operator, 0 otherwise. */
14127 build_incdec (int op_token, int op_location, tree op1, int is_post_p)
14129 static const enum tree_code lookup [2][2] =
14131 { PREDECREMENT_EXPR, PREINCREMENT_EXPR, },
14132 { POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, },
14134 tree node = build2 (lookup [is_post_p][(op_token - DECR_TK)],
14135 NULL_TREE, op1, NULL_TREE);
14136 TREE_SIDE_EFFECTS (node) = 1;
14137 /* Store the location of the operator, for better error report. The
14138 string of the operator will be rebuild based on the OP value. */
14139 EXPR_WFL_LINECOL (node) = op_location;
14143 /* Build an incomplete cast operator, based on the use of the
14144 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
14145 set. java_complete_tree is trained to walk a CONVERT_EXPR even
14146 though its type is already set. */
14149 build_cast (int location, tree type, tree exp)
14151 tree node = build1 (CONVERT_EXPR, type, exp);
14152 EXPR_WFL_LINECOL (node) = location;
14156 /* Build an incomplete class reference operator. */
14158 build_incomplete_class_ref (int location, tree class_name)
14160 tree node = build1 (CLASS_LITERAL, NULL_TREE, class_name);
14161 tree class_decl = GET_CPC ();
14162 tree this_class = TREE_TYPE (class_decl);
14164 /* Generate the synthetic static method `class$'. (Previously we
14165 deferred this, causing different method tables to be emitted
14166 for native code and bytecode.) */
14167 if (!TYPE_DOT_CLASS (this_class)
14168 && !JPRIMITIVE_TYPE_P (class_name)
14169 && !(TREE_CODE (class_name) == VOID_TYPE))
14171 tree cpc_list = GET_CPC_LIST();
14172 tree cpc = cpc_list;
14175 /* For inner classes, add a 'class$' method to their outermost
14176 context, creating it if necessary. */
14178 while (GET_NEXT_ENCLOSING_CPC(cpc))
14179 cpc = GET_NEXT_ENCLOSING_CPC(cpc);
14180 class_decl = TREE_VALUE (cpc);
14182 target_class = TREE_TYPE (class_decl);
14184 if (CLASS_INTERFACE (TYPE_NAME (target_class)))
14186 /* For interfaces, adding a static 'class$' method directly
14187 is illegal. So create an inner class to contain the new
14188 method. Empirically this matches the behavior of javac. */
14190 /* We want the generated inner class inside the outermost class. */
14191 GET_CPC_LIST() = cpc;
14192 t = build_wfl_node (DECL_NAME (TYPE_NAME (object_type_node)));
14193 inner = create_anonymous_class (t);
14194 target_class = TREE_TYPE (inner);
14195 end_class_declaration (1);
14196 GET_CPC_LIST() = cpc_list;
14199 if (TYPE_DOT_CLASS (target_class) == NULL_TREE)
14200 build_dot_class_method (target_class);
14202 if (this_class != target_class)
14203 TYPE_DOT_CLASS (this_class) = TYPE_DOT_CLASS (target_class);
14206 EXPR_WFL_LINECOL (node) = location;
14210 /* Complete an incomplete class reference operator. */
14212 patch_incomplete_class_ref (tree node)
14214 tree type = TREE_OPERAND (node, 0);
14217 if (!(ref_type = resolve_type_during_patch (type)))
14218 return error_mark_node;
14220 /* If we're not emitting class files and we know ref_type is a
14221 compiled class, build a direct reference. */
14222 if ((! flag_emit_class_files && is_compiled_class (ref_type))
14223 || JPRIMITIVE_TYPE_P (ref_type)
14224 || TREE_CODE (ref_type) == VOID_TYPE)
14226 tree dot = build_class_ref (ref_type);
14227 /* A class referenced by `foo.class' is initialized. */
14228 if (!flag_emit_class_files)
14229 dot = build_class_init (ref_type, dot);
14230 return java_complete_tree (dot);
14233 /* If we're emitting class files and we have to deal with non
14234 primitive types, we invoke the synthetic static method `class$'. */
14235 ref_type = build_dot_class_method_invocation (current_class, ref_type);
14236 return java_complete_tree (ref_type);
14239 /* 15.14 Unary operators. We return error_mark_node in case of error,
14240 but preserve the type of NODE if the type is fixed. */
14243 patch_unaryop (tree node, tree wfl_op)
14245 tree op = TREE_OPERAND (node, 0);
14246 tree op_type = TREE_TYPE (op);
14247 tree prom_type = NULL_TREE, value, decl;
14248 int outer_field_flag = 0;
14249 int code = TREE_CODE (node);
14250 int error_found = 0;
14252 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14256 /* 15.13.2 Postfix Increment Operator ++ */
14257 case POSTINCREMENT_EXPR:
14258 /* 15.13.3 Postfix Increment Operator -- */
14259 case POSTDECREMENT_EXPR:
14260 /* 15.14.1 Prefix Increment Operator ++ */
14261 case PREINCREMENT_EXPR:
14262 /* 15.14.2 Prefix Decrement Operator -- */
14263 case PREDECREMENT_EXPR:
14264 op = decl = extract_field_decl (op);
14265 outer_field_flag = outer_field_expanded_access_p (op, NULL, NULL, NULL);
14266 /* We might be trying to change an outer field accessed using
14268 if (outer_field_flag)
14270 /* Retrieve the decl of the field we're trying to access. We
14271 do that by first retrieving the function we would call to
14272 access the field. It has been already verified that this
14273 field isn't final */
14274 if (flag_emit_class_files)
14275 decl = TREE_OPERAND (op, 0);
14277 decl = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (op, 0), 0), 0);
14278 decl = DECL_FUNCTION_ACCESS_DECL (decl);
14280 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
14281 else if (!JDECL_P (decl)
14282 && TREE_CODE (decl) != COMPONENT_REF
14283 && !(flag_emit_class_files && TREE_CODE (decl) == ARRAY_REF)
14284 && TREE_CODE (decl) != INDIRECT_REF
14285 && !(TREE_CODE (decl) == COMPOUND_EXPR
14286 && TREE_OPERAND (decl, 1)
14287 && (TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)))
14289 TREE_TYPE (node) = error_mark_node;
14293 /* From now on, we know that op if a variable and that it has a
14294 valid wfl. We use wfl_op to locate errors related to the
14296 if (!JNUMERIC_TYPE_P (op_type))
14298 parse_error_context
14299 (wfl_op, "Invalid argument type %qs to %qs",
14300 lang_printable_name (op_type, 0), operator_string (node));
14301 TREE_TYPE (node) = error_mark_node;
14306 /* Before the addition, binary numeric promotion is performed on
14307 both operands, if really necessary */
14308 if (JINTEGRAL_TYPE_P (op_type))
14310 value = build_int_cst (op_type, 1);
14311 TREE_TYPE (node) = op_type;
14315 value = build_int_cst (NULL_TREE, 1);
14317 binary_numeric_promotion (op_type,
14318 TREE_TYPE (value), &op, &value);
14321 /* We remember we might be accessing an outer field */
14322 if (outer_field_flag)
14324 /* We re-generate an access to the field */
14325 value = build2 (PLUS_EXPR, TREE_TYPE (op),
14326 build_outer_field_access (wfl_op, decl), value);
14328 /* And we patch the original access$() into a write
14329 with plus_op as a rhs */
14330 return outer_field_access_fix (node, op, value);
14333 /* And write back into the node. */
14334 TREE_OPERAND (node, 0) = op;
14335 TREE_OPERAND (node, 1) = value;
14336 /* Convert the overall back into its original type, if
14337 necessary, and return */
14338 if (JINTEGRAL_TYPE_P (op_type))
14339 return fold (node);
14341 return fold (convert (op_type, node));
14345 /* 15.14.3 Unary Plus Operator + */
14346 case UNARY_PLUS_EXPR:
14347 /* 15.14.4 Unary Minus Operator - */
14349 if (!JNUMERIC_TYPE_P (op_type))
14351 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op_type);
14352 TREE_TYPE (node) = error_mark_node;
14355 /* Unary numeric promotion is performed on operand */
14358 op = do_unary_numeric_promotion (op);
14359 prom_type = TREE_TYPE (op);
14360 if (code == UNARY_PLUS_EXPR)
14365 /* 15.14.5 Bitwise Complement Operator ~ */
14367 if (!JINTEGRAL_TYPE_P (op_type))
14369 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op_type);
14370 TREE_TYPE (node) = error_mark_node;
14375 op = do_unary_numeric_promotion (op);
14376 prom_type = TREE_TYPE (op);
14380 /* 15.14.6 Logical Complement Operator ! */
14381 case TRUTH_NOT_EXPR:
14382 if (TREE_CODE (op_type) != BOOLEAN_TYPE)
14384 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
14385 /* But the type is known. We will report an error if further
14386 attempt of a assignment is made with this rhs */
14387 TREE_TYPE (node) = boolean_type_node;
14391 prom_type = boolean_type_node;
14394 /* 15.15 Cast Expression */
14396 value = patch_cast (node, wfl_operator);
14397 if (value == error_mark_node)
14399 /* If this cast is part of an assignment, we tell the code
14400 that deals with it not to complain about a mismatch,
14401 because things have been cast, anyways */
14402 TREE_TYPE (node) = error_mark_node;
14407 value = fold (value);
14414 return error_mark_node;
14416 /* There are cases where node has been replaced by something else
14417 and we don't end up returning here: UNARY_PLUS_EXPR,
14418 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
14419 TREE_OPERAND (node, 0) = fold (op);
14420 TREE_TYPE (node) = prom_type;
14421 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
14422 return fold (node);
14425 /* Generic type resolution that sometimes takes place during node
14426 patching. Returned the resolved type or generate an error
14427 message. Return the resolved type or NULL_TREE. */
14430 resolve_type_during_patch (tree type)
14432 if (unresolved_type_p (type, NULL))
14434 tree type_decl = resolve_and_layout (EXPR_WFL_NODE (type), type);
14437 parse_error_context (type,
14438 "Class %qs not found in type declaration",
14439 IDENTIFIER_POINTER (EXPR_WFL_NODE (type)));
14443 check_deprecation (type, type_decl);
14445 return TREE_TYPE (type_decl);
14450 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
14451 found. Otherwise NODE or something meant to replace it is returned. */
14454 patch_cast (tree node, tree wfl_op)
14456 tree op = TREE_OPERAND (node, 0);
14457 tree cast_type = TREE_TYPE (node);
14458 tree patched, op_type;
14461 /* Some string patching might be necessary at this stage */
14462 if ((patched = patch_string (op)))
14463 TREE_OPERAND (node, 0) = op = patched;
14464 op_type = TREE_TYPE (op);
14466 /* First resolve OP_TYPE if unresolved */
14467 if (!(cast_type = resolve_type_during_patch (cast_type)))
14468 return error_mark_node;
14470 /* Check on cast that are proven correct at compile time */
14471 if (JNUMERIC_TYPE_P (cast_type) && JNUMERIC_TYPE_P (op_type))
14474 if (cast_type == op_type)
14477 /* A narrowing conversion from a floating-point number to an
14478 integral type requires special handling (5.1.3). */
14479 if (JFLOAT_TYPE_P (op_type) && JINTEGRAL_TYPE_P (cast_type))
14480 if (cast_type != long_type_node)
14481 op = convert (integer_type_node, op);
14483 /* Try widening/narrowing conversion. Potentially, things need
14484 to be worked out in gcc so we implement the extreme cases
14485 correctly. fold_convert() needs to be fixed. */
14486 return convert (cast_type, op);
14489 /* It's also valid to cast a boolean into a boolean */
14490 if (op_type == boolean_type_node && cast_type == boolean_type_node)
14493 /* null can be casted to references */
14494 if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
14495 return build_null_of_type (cast_type);
14497 /* The remaining legal casts involve conversion between reference
14498 types. Check for their compile time correctness. */
14499 if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type)
14500 && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
14502 TREE_TYPE (node) = promote_type (cast_type);
14503 /* Now, the case can be determined correct at compile time if
14504 OP_TYPE can be converted into CAST_TYPE by assignment
14505 conversion (5.2) */
14507 if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
14509 TREE_SET_CODE (node, NOP_EXPR);
14513 if (flag_emit_class_files)
14515 TREE_SET_CODE (node, CONVERT_EXPR);
14519 /* The cast requires a run-time check */
14520 return build3 (CALL_EXPR, promote_type (cast_type),
14521 build_address_of (soft_checkcast_node),
14522 tree_cons (NULL_TREE, build_class_ref (cast_type),
14523 build_tree_list (NULL_TREE, op)),
14527 /* Any other casts are proven incorrect at compile time */
14528 t1 = xstrdup (lang_printable_name (op_type, 0));
14529 parse_error_context (wfl_op, "Invalid cast from %qs to %qs",
14530 t1, lang_printable_name (cast_type, 0));
14532 return error_mark_node;
14535 /* Build a null constant and give it the type TYPE. */
14538 build_null_of_type (tree type)
14540 tree node = build_int_cst (promote_type (type), 0);
14544 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
14545 a list of indices. */
14547 build_array_ref (int location, tree array, tree index)
14549 tree node = build4 (ARRAY_REF, NULL_TREE, array, index,
14550 NULL_TREE, NULL_TREE);
14551 EXPR_WFL_LINECOL (node) = location;
14555 /* 15.12 Array Access Expression */
14558 patch_array_ref (tree node)
14560 tree array = TREE_OPERAND (node, 0);
14561 tree array_type = TREE_TYPE (array);
14562 tree index = TREE_OPERAND (node, 1);
14563 tree index_type = TREE_TYPE (index);
14564 int error_found = 0;
14566 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14568 if (TREE_CODE (array_type) == POINTER_TYPE)
14569 array_type = TREE_TYPE (array_type);
14571 /* The array reference must be an array */
14572 if (!TYPE_ARRAY_P (array_type))
14574 parse_error_context
14576 "%<[]%> can only be applied to arrays. It can't be applied to %qs",
14577 lang_printable_name (array_type, 0));
14578 TREE_TYPE (node) = error_mark_node;
14582 /* The array index undergoes unary numeric promotion. The promoted
14583 type must be int */
14584 index = do_unary_numeric_promotion (index);
14585 if (TREE_TYPE (index) != int_type_node)
14587 if (valid_cast_to_p (index_type, int_type_node))
14588 parse_error_context (wfl_operator,
14589 "Incompatible type for %<[]%>. Explicit cast needed to convert %qs to %<int%>",
14590 lang_printable_name (index_type, 0));
14592 parse_error_context (wfl_operator,
14593 "Incompatible type for %<[]%>. Can't convert %qs to %<int%>",
14594 lang_printable_name (index_type, 0));
14595 TREE_TYPE (node) = error_mark_node;
14600 return error_mark_node;
14602 array_type = TYPE_ARRAY_ELEMENT (array_type);
14604 if (flag_emit_class_files || flag_emit_xref)
14606 TREE_OPERAND (node, 0) = array;
14607 TREE_OPERAND (node, 1) = index;
14610 node = build_java_arrayaccess (array, array_type, index);
14611 TREE_TYPE (node) = array_type;
14615 /* 15.9 Array Creation Expressions */
14618 build_newarray_node (tree type, tree dims, int extra_dims)
14620 tree node = build3 (NEW_ARRAY_EXPR, NULL_TREE, type,
14622 build_int_cst (NULL_TREE, extra_dims));
14627 patch_newarray (tree node)
14629 tree type = TREE_OPERAND (node, 0);
14630 tree dims = TREE_OPERAND (node, 1);
14631 tree cdim, array_type;
14632 int error_found = 0;
14634 int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
14636 /* Dimension types are verified. It's better for the types to be
14637 verified in order. */
14638 for (cdim = dims, ndims = 0; cdim; cdim = TREE_CHAIN (cdim), ndims++ )
14641 tree dim = TREE_VALUE (cdim);
14643 /* Dim might have been saved during its evaluation */
14644 dim = (TREE_CODE (dim) == SAVE_EXPR ? TREE_OPERAND (dim, 0) : dim);
14646 /* The type of each specified dimension must be an integral type. */
14647 if (!JINTEGRAL_TYPE_P (TREE_TYPE (dim)))
14650 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
14651 promoted type must be int. */
14654 dim = do_unary_numeric_promotion (dim);
14655 if (TREE_TYPE (dim) != int_type_node)
14659 /* Report errors on types here */
14662 parse_error_context
14663 (TREE_PURPOSE (cdim),
14664 "Incompatible type for dimension in array creation expression. %s convert %qs to %<int%>",
14665 (valid_cast_to_p (TREE_TYPE (dim), int_type_node) ?
14666 "Explicit cast needed to" : "Can't"),
14667 lang_printable_name (TREE_TYPE (dim), 0));
14671 TREE_PURPOSE (cdim) = NULL_TREE;
14674 /* Resolve array base type if unresolved */
14675 if (!(type = resolve_type_during_patch (type)))
14680 /* We don't want further evaluation of this bogus array creation
14682 TREE_TYPE (node) = error_mark_node;
14683 return error_mark_node;
14686 /* Set array_type to the actual (promoted) array type of the result. */
14687 if (TREE_CODE (type) == RECORD_TYPE)
14688 type = build_pointer_type (type);
14689 while (--xdims >= 0)
14691 type = promote_type (build_java_array_type (type, -1));
14693 dims = nreverse (dims);
14695 for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
14699 = build_java_array_type (type,
14700 TREE_CODE (cdim) == INTEGER_CST
14701 ? (HOST_WIDE_INT) TREE_INT_CST_LOW (cdim)
14703 array_type = promote_type (array_type);
14705 dims = nreverse (dims);
14707 /* The node is transformed into a function call. Things are done
14708 differently according to the number of dimensions. If the number
14709 of dimension is equal to 1, then the nature of the base type
14710 (primitive or not) matters. */
14712 return build_new_array (type, TREE_VALUE (dims));
14714 /* Can't reuse what's already written in expr.c because it uses the
14715 JVM stack representation. Provide a build_multianewarray. FIXME */
14716 return build3 (CALL_EXPR, array_type,
14717 build_address_of (soft_multianewarray_node),
14718 tree_cons (NULL_TREE,
14719 build_class_ref (TREE_TYPE (array_type)),
14720 tree_cons (NULL_TREE,
14721 build_int_cst (NULL_TREE, ndims),
14726 /* 10.6 Array initializer. */
14728 /* Build a wfl for array element that don't have one, so we can
14729 pin-point errors. */
14732 maybe_build_array_element_wfl (tree node)
14734 if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
14736 /* FIXME - old code used "prev_lc.line" and "elc.prev_col */
14737 return build_expr_wfl (NULL_TREE,
14738 #ifdef USE_MAPPED_LOCATION
14742 ctxp->lexer->token_start.line,
14743 ctxp->lexer->token_start.col
14751 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
14752 identification of initialized arrays easier to detect during walk
14756 build_new_array_init (int location, tree values)
14758 tree constructor = build_constructor (NULL_TREE, values);
14759 tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
14760 EXPR_WFL_LINECOL (to_return) = location;
14764 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
14765 occurred. Otherwise return NODE after having set its type
14769 patch_new_array_init (tree type, tree node)
14771 int error_seen = 0;
14772 tree current, element_type;
14773 HOST_WIDE_INT length;
14774 int all_constant = 1;
14775 tree init = TREE_OPERAND (node, 0);
14777 if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
14779 parse_error_context (node,
14780 "Invalid array initializer for non-array type %qs",
14781 lang_printable_name (type, 1));
14782 return error_mark_node;
14784 type = TREE_TYPE (type);
14785 element_type = TYPE_ARRAY_ELEMENT (type);
14787 CONSTRUCTOR_ELTS (init) = nreverse (CONSTRUCTOR_ELTS (init));
14789 for (length = 0, current = CONSTRUCTOR_ELTS (init);
14790 current; length++, current = TREE_CHAIN (current))
14792 tree elt = TREE_VALUE (current);
14793 if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
14795 error_seen |= array_constructor_check_entry (element_type, current);
14796 elt = TREE_VALUE (current);
14797 /* When compiling to native code, STRING_CST is converted to
14798 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
14799 if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
14804 TREE_VALUE (current) = patch_new_array_init (element_type, elt);
14805 TREE_PURPOSE (current) = NULL_TREE;
14808 if (elt && TREE_CODE (elt) == TREE_LIST
14809 && TREE_VALUE (elt) == error_mark_node)
14814 return error_mark_node;
14816 /* Create a new type. We can't reuse the one we have here by
14817 patching its dimension because it originally is of dimension -1
14818 hence reused by gcc. This would prevent triangular arrays. */
14819 type = build_java_array_type (element_type, length);
14820 TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
14821 TREE_TYPE (node) = promote_type (type);
14822 TREE_CONSTANT (init) = all_constant;
14823 TREE_INVARIANT (init) = all_constant;
14824 TREE_CONSTANT (node) = all_constant;
14825 TREE_INVARIANT (node) = all_constant;
14829 /* Verify that one entry of the initializer element list can be
14830 assigned to the array base type. Report 1 if an error occurred, 0
14834 array_constructor_check_entry (tree type, tree entry)
14836 char *array_type_string = NULL; /* For error reports */
14837 tree value, type_value, new_value, wfl_value, patched;
14838 int error_seen = 0;
14840 new_value = NULL_TREE;
14841 wfl_value = TREE_VALUE (entry);
14843 value = java_complete_tree (TREE_VALUE (entry));
14844 /* patch_string return error_mark_node if arg is error_mark_node */
14845 if ((patched = patch_string (value)))
14847 if (value == error_mark_node)
14850 type_value = TREE_TYPE (value);
14852 /* At anytime, try_builtin_assignconv can report a warning on
14853 constant overflow during narrowing. */
14854 SET_WFL_OPERATOR (wfl_operator, TREE_PURPOSE (entry), wfl_value);
14855 new_value = try_builtin_assignconv (wfl_operator, type, value);
14856 if (!new_value && (new_value = try_reference_assignconv (type, value)))
14857 type_value = promote_type (type);
14859 /* Check and report errors */
14862 const char *const msg = (!valid_cast_to_p (type_value, type) ?
14863 "Can't" : "Explicit cast needed to");
14864 if (!array_type_string)
14865 array_type_string = xstrdup (lang_printable_name (type, 1));
14866 parse_error_context
14867 (wfl_operator, "Incompatible type for array. %s convert %qs to %qs",
14868 msg, lang_printable_name (type_value, 1), array_type_string);
14873 TREE_VALUE (entry) = new_value;
14875 if (array_type_string)
14876 free (array_type_string);
14878 TREE_PURPOSE (entry) = NULL_TREE;
14883 build_this (int location)
14885 tree node = build_wfl_node (this_identifier_node);
14886 TREE_SET_CODE (node, THIS_EXPR);
14887 EXPR_WFL_LINECOL (node) = location;
14891 /* 14.15 The return statement. It builds a modify expression that
14892 assigns the returned value to the RESULT_DECL that hold the value
14896 build_return (int location, tree op)
14898 tree node = build1 (RETURN_EXPR, NULL_TREE, op);
14899 EXPR_WFL_LINECOL (node) = location;
14900 node = build_debugable_stmt (location, node);
14905 patch_return (tree node)
14907 tree return_exp = TREE_OPERAND (node, 0);
14908 tree meth = current_function_decl;
14909 tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
14910 int error_found = 0;
14912 TREE_TYPE (node) = error_mark_node;
14913 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
14915 /* It's invalid to have a return value within a function that is
14916 declared with the keyword void or that is a constructor */
14917 if (return_exp && (mtype == void_type_node || DECL_CONSTRUCTOR_P (meth)))
14920 /* It's invalid to use a return statement in a static block */
14921 if (DECL_CLINIT_P (current_function_decl))
14924 /* It's invalid to have a no return value within a function that
14925 isn't declared with the keyword `void' */
14926 if (!return_exp && (mtype != void_type_node && !DECL_CONSTRUCTOR_P (meth)))
14929 if (DECL_INSTINIT_P (current_function_decl))
14934 if (DECL_INSTINIT_P (current_function_decl))
14935 parse_error_context (wfl_operator,
14936 "%<return%> inside instance initializer");
14938 else if (DECL_CLINIT_P (current_function_decl))
14939 parse_error_context (wfl_operator,
14940 "%<return%> inside static initializer");
14942 else if (!DECL_CONSTRUCTOR_P (meth))
14944 char *t = xstrdup (lang_printable_name (mtype, 0));
14945 parse_error_context (wfl_operator,
14946 "%<return%> with%s value from %<%s %s%>",
14947 (error_found == 1 ? "" : "out"),
14948 t, lang_printable_name (meth, 2));
14952 parse_error_context (wfl_operator,
14953 "%<return%> with value from constructor %qs",
14954 lang_printable_name (meth, 2));
14955 return error_mark_node;
14958 /* If we have a return_exp, build a modify expression and expand
14959 it. Note: at that point, the assignment is declared valid, but we
14960 may want to carry some more hacks */
14963 tree exp = java_complete_tree (return_exp);
14964 tree modify, patched;
14966 if ((patched = patch_string (exp)))
14969 modify = build2 (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
14970 EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
14971 modify = java_complete_tree (modify);
14973 if (modify != error_mark_node)
14975 TREE_SIDE_EFFECTS (modify) = 1;
14976 TREE_OPERAND (node, 0) = modify;
14979 return error_mark_node;
14981 TREE_TYPE (node) = void_type_node;
14982 TREE_SIDE_EFFECTS (node) = 1;
14986 /* 14.8 The if Statement */
14989 build_if_else_statement (int location, tree expression, tree if_body,
14994 else_body = build_java_empty_stmt ();
14995 node = build3 (COND_EXPR, NULL_TREE, expression, if_body, else_body);
14996 EXPR_WFL_LINECOL (node) = location;
14997 node = build_debugable_stmt (location, node);
15002 patch_if_else_statement (tree node)
15004 tree expression = TREE_OPERAND (node, 0);
15005 int can_complete_normally
15006 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
15007 | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2)));
15009 TREE_TYPE (node) = error_mark_node;
15010 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15012 /* The type of expression must be boolean */
15013 if (TREE_TYPE (expression) != boolean_type_node
15014 && TREE_TYPE (expression) != promoted_boolean_type_node)
15016 parse_error_context
15018 "Incompatible type for %<if%>. Can't convert %qs to %<boolean%>",
15019 lang_printable_name (TREE_TYPE (expression), 0));
15020 return error_mark_node;
15023 TREE_TYPE (node) = void_type_node;
15024 TREE_SIDE_EFFECTS (node) = 1;
15025 CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
15029 /* 14.6 Labeled Statements */
15031 /* Action taken when a labeled statement is parsed. a new
15032 LABELED_BLOCK_EXPR is created. No statement is attached to the
15033 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
15036 build_labeled_block (int location, tree label)
15039 tree label_decl, node;
15040 if (label == NULL_TREE || label == continue_identifier_node)
15041 label_name = label;
15044 label_name = merge_qualified_name (label_id, label);
15045 /* Issue an error if we try to reuse a label that was previously
15047 if (IDENTIFIER_LOCAL_VALUE (label_name))
15049 EXPR_WFL_LINECOL (wfl_operator) = location;
15050 parse_error_context (wfl_operator,
15051 "Declaration of %qs shadows a previous label declaration",
15052 IDENTIFIER_POINTER (label));
15053 EXPR_WFL_LINECOL (wfl_operator) =
15054 EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
15055 parse_error_context (wfl_operator,
15056 "This is the location of the previous declaration of label %qs",
15057 IDENTIFIER_POINTER (label));
15058 java_error_count--;
15062 label_decl = create_label_decl (label_name);
15063 node = build2 (LABELED_BLOCK_EXPR, NULL_TREE, label_decl, NULL_TREE);
15064 EXPR_WFL_LINECOL (node) = location;
15065 TREE_SIDE_EFFECTS (node) = 1;
15069 /* A labeled statement LBE is attached a statement. */
15072 finish_labeled_statement (tree lbe, /* Labeled block expr */
15075 /* In anyways, tie the loop to its statement */
15076 LABELED_BLOCK_BODY (lbe) = statement;
15077 pop_labeled_block ();
15078 POP_LABELED_BLOCK ();
15082 /* 14.10, 14.11, 14.12 Loop Statements */
15084 /* Create an empty LOOP_EXPR and make it the last in the nested loop
15088 build_new_loop (tree loop_body)
15090 tree loop = build1 (LOOP_EXPR, NULL_TREE, loop_body);
15091 TREE_SIDE_EFFECTS (loop) = 1;
15096 /* Create a loop body according to the following structure:
15098 COMPOUND_EXPR (loop main body)
15099 EXIT_EXPR (this order is for while/for loops.
15100 LABELED_BLOCK_EXPR the order is reversed for do loops)
15101 LABEL_DECL (a continue occurring here branches at the
15102 BODY end of this labeled block)
15105 REVERSED, if nonzero, tells that the loop condition expr comes
15106 after the body, like in the do-while loop.
15108 To obtain a loop, the loop body structure described above is
15109 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
15112 LABEL_DECL (use this label to exit the loop)
15114 <structure described above> */
15117 build_loop_body (int location, tree condition, int reversed)
15119 tree first, second, body;
15121 condition = build1 (EXIT_EXPR, NULL_TREE, condition); /* Force walk */
15122 EXPR_WFL_LINECOL (condition) = location; /* For accurate error report */
15123 condition = build_debugable_stmt (location, condition);
15124 TREE_SIDE_EFFECTS (condition) = 1;
15126 body = build_labeled_block (0, continue_identifier_node);
15127 first = (reversed ? body : condition);
15128 second = (reversed ? condition : body);
15129 return build2 (COMPOUND_EXPR, NULL_TREE,
15130 build2 (COMPOUND_EXPR, NULL_TREE, first, second),
15131 build_java_empty_stmt ());
15134 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
15135 their order) on the current loop. Unlink the current loop from the
15139 finish_loop_body (int location, tree condition, tree body, int reversed)
15141 tree to_return = ctxp->current_loop;
15142 tree loop_body = LOOP_EXPR_BODY (to_return);
15145 tree cnode = LOOP_EXPR_BODY_CONDITION_EXPR (loop_body, reversed);
15146 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
15147 The real EXIT_EXPR is one operand further. */
15148 EXPR_WFL_LINECOL (cnode) = location;
15149 if (TREE_CODE (cnode) == EXPR_WITH_FILE_LOCATION)
15151 cnode = EXPR_WFL_NODE (cnode);
15152 /* This one is for accurate error reports */
15153 EXPR_WFL_LINECOL (cnode) = location;
15155 TREE_OPERAND (cnode, 0) = condition;
15157 LOOP_EXPR_BODY_BODY_EXPR (loop_body, reversed) = body;
15162 /* Tailored version of finish_loop_body for FOR loops, when FOR
15163 loops feature the condition part */
15166 finish_for_loop (int location, tree condition, tree update, tree body)
15168 /* Put the condition and the loop body in place */
15169 tree loop = finish_loop_body (location, condition, body, 0);
15170 /* LOOP is the current loop which has been now popped of the loop
15171 stack. Mark the update block as reachable and install it. We do
15172 this because the (current interpretation of the) JLS requires
15173 that the update expression be considered reachable even if the
15174 for loop's body doesn't complete normally. */
15175 if (update != NULL_TREE && !IS_EMPTY_STMT (update))
15178 if (TREE_CODE (up2) == EXPR_WITH_FILE_LOCATION)
15179 up2 = EXPR_WFL_NODE (up2);
15180 /* It is possible for the update expression to be an
15181 EXPR_WFL_NODE wrapping nothing. */
15182 if (up2 != NULL_TREE && !IS_EMPTY_STMT (up2))
15184 /* Try to detect constraint violations. These would be
15185 programming errors somewhere. */
15186 if (! EXPR_P (up2) || TREE_CODE (up2) == LOOP_EXPR)
15188 SUPPRESS_UNREACHABLE_ERROR (up2) = 1;
15191 LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
15195 /* Try to find the loop a block might be related to. This comprises
15196 the case where the LOOP_EXPR is found as the second operand of a
15197 COMPOUND_EXPR, because the loop happens to have an initialization
15198 part, then expressed as the first operand of the COMPOUND_EXPR. If
15199 the search finds something, 1 is returned. Otherwise, 0 is
15200 returned. The search is assumed to start from a
15201 LABELED_BLOCK_EXPR's block. */
15204 search_loop (tree statement)
15206 if (TREE_CODE (statement) == LOOP_EXPR)
15209 if (TREE_CODE (statement) == BLOCK)
15210 statement = BLOCK_SUBBLOCKS (statement);
15214 if (statement && TREE_CODE (statement) == COMPOUND_EXPR)
15215 while (statement && TREE_CODE (statement) == COMPOUND_EXPR)
15216 statement = TREE_OPERAND (statement, 1);
15218 return (TREE_CODE (statement) == LOOP_EXPR
15219 && FOR_LOOP_P (statement) ? statement : NULL_TREE);
15222 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
15223 returned otherwise. */
15226 labeled_block_contains_loop_p (tree block, tree loop)
15231 if (LABELED_BLOCK_BODY (block) == loop)
15234 if (FOR_LOOP_P (loop) && search_loop (LABELED_BLOCK_BODY (block)) == loop)
15240 /* If the loop isn't surrounded by a labeled statement, create one and
15241 insert LOOP as its body. */
15244 patch_loop_statement (tree loop)
15248 TREE_TYPE (loop) = void_type_node;
15249 if (labeled_block_contains_loop_p (ctxp->current_labeled_block, loop))
15252 loop_label = build_labeled_block (0, NULL_TREE);
15253 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
15254 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
15255 LABELED_BLOCK_BODY (loop_label) = loop;
15256 PUSH_LABELED_BLOCK (loop_label);
15260 /* 14.13, 14.14: break and continue Statements */
15262 /* Build a break or a continue statement. a null NAME indicates an
15263 unlabeled break/continue statement. */
15266 build_bc_statement (int location, int is_break, tree name)
15268 tree break_continue, label_block_expr = NULL_TREE;
15272 if (!(label_block_expr = IDENTIFIER_LOCAL_VALUE
15273 (merge_qualified_name (label_id, EXPR_WFL_NODE (name)))))
15274 /* Null means that we don't have a target for this named
15275 break/continue. In this case, we make the target to be the
15276 label name, so that the error can be reported accurately in
15277 patch_bc_statement. */
15278 label_block_expr = EXPR_WFL_NODE (name);
15280 /* Unlabeled break/continue will be handled during the
15281 break/continue patch operation */
15282 break_continue = build1 (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr);
15284 IS_BREAK_STMT_P (break_continue) = is_break;
15285 TREE_SIDE_EFFECTS (break_continue) = 1;
15286 EXPR_WFL_LINECOL (break_continue) = location;
15287 break_continue = build_debugable_stmt (location, break_continue);
15288 return break_continue;
15291 /* Verification of a break/continue statement. */
15294 patch_bc_statement (tree node)
15296 tree bc_label = EXIT_BLOCK_LABELED_BLOCK (node), target_stmt;
15297 tree labeled_block = ctxp->current_labeled_block;
15298 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15300 /* Having an identifier here means that the target is unknown. */
15301 if (bc_label != NULL_TREE && TREE_CODE (bc_label) == IDENTIFIER_NODE)
15303 parse_error_context (wfl_operator, "No label definition found for %qs",
15304 IDENTIFIER_POINTER (bc_label));
15305 return error_mark_node;
15307 if (! IS_BREAK_STMT_P (node))
15309 /* It's a continue statement. */
15310 for (;; labeled_block = TREE_CHAIN (labeled_block))
15312 if (labeled_block == NULL_TREE)
15314 if (bc_label == NULL_TREE)
15315 parse_error_context (wfl_operator,
15316 "%<continue%> must be in loop");
15318 parse_error_context
15319 (wfl_operator, "continue label %qs does not name a loop",
15320 IDENTIFIER_POINTER (bc_label));
15321 return error_mark_node;
15323 if ((DECL_NAME (LABELED_BLOCK_LABEL (labeled_block))
15324 == continue_identifier_node)
15325 && (bc_label == NULL_TREE
15326 || TREE_CHAIN (labeled_block) == bc_label))
15328 bc_label = labeled_block;
15333 else if (!bc_label)
15335 for (;; labeled_block = TREE_CHAIN (labeled_block))
15337 if (labeled_block == NULL_TREE)
15339 parse_error_context (wfl_operator,
15340 "%<break%> must be in loop or switch");
15341 return error_mark_node;
15343 target_stmt = LABELED_BLOCK_BODY (labeled_block);
15344 if (TREE_CODE (target_stmt) == SWITCH_EXPR
15345 || search_loop (target_stmt))
15347 bc_label = labeled_block;
15353 EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
15354 CAN_COMPLETE_NORMALLY (bc_label) = 1;
15356 /* Our break/continue don't return values. */
15357 TREE_TYPE (node) = void_type_node;
15358 /* Encapsulate the break within a compound statement so that it's
15359 expanded all the times by expand_expr (and not clobbered
15360 sometimes, like after a if statement) */
15361 node = add_stmt_to_compound (NULL_TREE, void_type_node, node);
15362 TREE_SIDE_EFFECTS (node) = 1;
15366 /* Process the exit expression belonging to a loop. Its type must be
15370 patch_exit_expr (tree node)
15372 tree expression = TREE_OPERAND (node, 0);
15373 TREE_TYPE (node) = error_mark_node;
15374 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15376 /* The type of expression must be boolean */
15377 if (TREE_TYPE (expression) != boolean_type_node)
15379 parse_error_context
15381 "Incompatible type for loop conditional. Can't convert %qs to %<boolean%>",
15382 lang_printable_name (TREE_TYPE (expression), 0));
15383 return error_mark_node;
15385 /* Now we know things are allright, invert the condition, fold and
15387 TREE_OPERAND (node, 0) =
15388 fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
15390 if (! integer_zerop (TREE_OPERAND (node, 0))
15391 && ctxp->current_loop != NULL_TREE
15392 && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
15393 CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
15394 if (! integer_onep (TREE_OPERAND (node, 0)))
15395 CAN_COMPLETE_NORMALLY (node) = 1;
15398 TREE_TYPE (node) = void_type_node;
15402 /* 14.9 Switch statement */
15405 patch_switch_statement (tree node)
15407 tree se = TREE_OPERAND (node, 0), se_type;
15410 /* Complete the switch expression */
15411 se = TREE_OPERAND (node, 0) = java_complete_tree (se);
15412 se_type = TREE_TYPE (se);
15413 /* The type of the switch expression must be char, byte, short or
15415 if (! JINTEGRAL_TYPE_P (se_type) || se_type == long_type_node)
15417 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
15418 parse_error_context (wfl_operator,
15419 "Incompatible type for %<switch%>. Can't convert %qs to %<int%>",
15420 lang_printable_name (se_type, 0));
15421 /* This is what java_complete_tree will check */
15422 TREE_OPERAND (node, 0) = error_mark_node;
15423 return error_mark_node;
15426 /* Save and restore the outer case label list. */
15427 save = case_label_list;
15428 case_label_list = NULL_TREE;
15430 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
15432 /* See if we've found a duplicate label. We can't leave this until
15433 code generation, because in `--syntax-only' and `-C' modes we
15434 don't do ordinary code generation. */
15435 for (iter = case_label_list; iter != NULL_TREE; iter = TREE_CHAIN (iter))
15437 HOST_WIDE_INT val = TREE_INT_CST_LOW (TREE_VALUE (iter));
15439 for (subiter = TREE_CHAIN (iter);
15440 subiter != NULL_TREE;
15441 subiter = TREE_CHAIN (subiter))
15443 HOST_WIDE_INT subval = TREE_INT_CST_LOW (TREE_VALUE (subiter));
15446 EXPR_WFL_LINECOL (wfl_operator)
15447 = EXPR_WFL_LINECOL (TREE_PURPOSE (iter));
15448 /* The case_label_list is in reverse order, so print the
15449 outer label first. */
15450 parse_error_context (wfl_operator, "duplicate case label: %<"
15451 HOST_WIDE_INT_PRINT_DEC "%>", subval);
15452 EXPR_WFL_LINECOL (wfl_operator)
15453 = EXPR_WFL_LINECOL (TREE_PURPOSE (subiter));
15454 parse_error_context (wfl_operator, "original label is here");
15461 case_label_list = save;
15463 /* Ready to return */
15464 if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
15466 TREE_TYPE (node) = error_mark_node;
15467 return error_mark_node;
15469 TREE_TYPE (node) = void_type_node;
15470 TREE_SIDE_EFFECTS (node) = 1;
15471 CAN_COMPLETE_NORMALLY (node)
15472 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
15473 || ! SWITCH_HAS_DEFAULT (node);
15479 /* Build an assertion expression for `assert CONDITION : VALUE'; VALUE
15480 might be NULL_TREE. */
15483 #ifdef USE_MAPPED_LOCATION
15484 source_location location,
15488 tree condition, tree value)
15491 tree klass = GET_CPC ();
15493 if (! enable_assertions (klass))
15495 condition = build2 (TRUTH_ANDIF_EXPR, NULL_TREE,
15496 boolean_false_node, condition);
15497 if (value == NULL_TREE)
15498 value = build_java_empty_stmt ();
15499 return build_if_else_statement (location, condition,
15503 if (! CLASS_USES_ASSERTIONS (klass))
15505 tree field, classdollar, id, call;
15506 tree class_type = TREE_TYPE (klass);
15508 field = add_field (class_type,
15509 get_identifier ("$assertionsDisabled"),
15511 ACC_PRIVATE | ACC_STATIC | ACC_FINAL);
15512 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (field);
15513 FIELD_SYNTHETIC (field) = 1;
15515 classdollar = build_incomplete_class_ref (location, class_type);
15517 /* Call CLASS.desiredAssertionStatus(). */
15518 id = build_wfl_node (get_identifier ("desiredAssertionStatus"));
15519 call = build3 (CALL_EXPR, NULL_TREE, id, NULL_TREE, NULL_TREE);
15520 call = make_qualified_primary (classdollar, call, location);
15521 TREE_SIDE_EFFECTS (call) = 1;
15523 /* Invert to obtain !CLASS.desiredAssertionStatus(). This may
15524 seem odd, but we do it to generate code identical to that of
15526 call = build1 (TRUTH_NOT_EXPR, NULL_TREE, call);
15527 TREE_SIDE_EFFECTS (call) = 1;
15528 DECL_INITIAL (field) = call;
15530 /* Record the initializer in the initializer statement list. */
15531 call = build2 (MODIFY_EXPR, NULL_TREE, field, call);
15532 TREE_CHAIN (call) = CPC_STATIC_INITIALIZER_STMT (ctxp);
15533 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, call);
15534 MODIFY_EXPR_FROM_INITIALIZATION_P (call) = 1;
15536 CLASS_USES_ASSERTIONS (klass) = 1;
15539 if (value != NULL_TREE)
15540 value = tree_cons (NULL_TREE, value, NULL_TREE);
15542 node = build_wfl_node (get_identifier ("java"));
15543 node = make_qualified_name (node, build_wfl_node (get_identifier ("lang")),
15545 node = make_qualified_name (node, build_wfl_node (get_identifier ("AssertionError")),
15548 node = build3 (NEW_CLASS_EXPR, NULL_TREE, node, value, NULL_TREE);
15549 TREE_SIDE_EFFECTS (node) = 1;
15550 /* It is too early to use BUILD_THROW. */
15551 node = build1 (THROW_EXPR, NULL_TREE, node);
15552 TREE_SIDE_EFFECTS (node) = 1;
15554 /* We invert the condition; if we just put NODE as the `else' part
15555 then we generate weird-looking bytecode. */
15556 condition = build1 (TRUTH_NOT_EXPR, NULL_TREE, condition);
15557 /* Check $assertionsDisabled. */
15559 = build2 (TRUTH_ANDIF_EXPR, NULL_TREE,
15560 build1 (TRUTH_NOT_EXPR, NULL_TREE,
15561 build_wfl_node (get_identifier ("$assertionsDisabled"))),
15563 node = build_if_else_statement (location, condition, node, NULL_TREE);
15567 /* 14.18 The try/catch statements */
15569 /* Encapsulate TRY_STMTS' in a try catch sequence. The catch clause
15570 catches TYPE and executes CATCH_STMTS. */
15573 encapsulate_with_try_catch (int location, tree type_or_name, tree try_stmts,
15576 tree try_block, catch_clause_param, catch_block, catch;
15578 /* First build a try block */
15579 try_block = build_expr_block (try_stmts, NULL_TREE);
15581 /* Build a catch block: we need a catch clause parameter */
15582 if (TREE_CODE (type_or_name) == EXPR_WITH_FILE_LOCATION)
15584 tree catch_type = obtain_incomplete_type (type_or_name);
15586 catch_clause_param = build_decl (VAR_DECL, wpv_id, catch_type);
15587 register_incomplete_type (JDEP_VARIABLE, type_or_name,
15588 catch_clause_param, catch_type);
15589 dep = CLASSD_LAST (ctxp->classd_list);
15590 JDEP_GET_PATCH (dep) = &TREE_TYPE (catch_clause_param);
15593 catch_clause_param = build_decl (VAR_DECL, wpv_id,
15594 build_pointer_type (type_or_name));
15597 catch_block = build_expr_block (NULL_TREE, catch_clause_param);
15599 /* Initialize the variable and store in the block */
15600 catch = build2 (MODIFY_EXPR, NULL_TREE, catch_clause_param,
15601 build0 (JAVA_EXC_OBJ_EXPR, ptr_type_node));
15602 add_stmt_to_block (catch_block, NULL_TREE, catch);
15604 /* Add the catch statements */
15605 add_stmt_to_block (catch_block, NULL_TREE, catch_stmts);
15607 /* Now we can build a JAVA_CATCH_EXPR */
15608 catch_block = build1 (JAVA_CATCH_EXPR, NULL_TREE, catch_block);
15610 return build_try_statement (location, try_block, catch_block);
15614 build_try_statement (int location, tree try_block, tree catches)
15616 tree node = build2 (TRY_EXPR, NULL_TREE, try_block, catches);
15617 EXPR_WFL_LINECOL (node) = location;
15622 build_try_finally_statement (int location, tree try_block, tree finally)
15624 tree node = build2 (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
15625 EXPR_WFL_LINECOL (node) = location;
15630 patch_try_statement (tree node)
15632 int error_found = 0;
15633 tree try = TREE_OPERAND (node, 0);
15634 /* Exception handlers are considered in left to right order */
15635 tree catch = nreverse (TREE_OPERAND (node, 1));
15636 tree current, caught_type_list = NULL_TREE;
15638 /* Check catch clauses, if any. Every time we find an error, we try
15639 to process the next catch clause. We process the catch clause before
15640 the try block so that when processing the try block we can check thrown
15641 exceptions against the caught type list. */
15642 for (current = catch; current; current = TREE_CHAIN (current))
15644 tree carg_decl, carg_type;
15645 tree sub_current, catch_block, catch_clause;
15648 /* At this point, the structure of the catch clause is
15649 JAVA_CATCH_EXPR (catch node)
15650 BLOCK (with the decl of the parameter)
15652 MODIFY_EXPR (assignment of the catch parameter)
15653 BLOCK (catch clause block)
15655 catch_clause = TREE_OPERAND (current, 0);
15656 carg_decl = BLOCK_EXPR_DECLS (catch_clause);
15657 carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
15659 /* Catch clauses can't have more than one parameter declared,
15660 but it's already enforced by the grammar. Make sure that the
15661 only parameter of the clause statement in of class Throwable
15662 or a subclass of Throwable, but that was done earlier. The
15663 catch clause parameter type has also been resolved. */
15665 /* Just make sure that the catch clause parameter type inherits
15666 from java.lang.Throwable */
15667 if (!inherits_from_p (carg_type, throwable_type_node))
15669 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
15670 parse_error_context (wfl_operator,
15671 "Can't catch class %qs. Catch clause parameter type must be a subclass of class %<java.lang.Throwable%>",
15672 lang_printable_name (carg_type, 0));
15677 /* Partial check for unreachable catch statement: The catch
15678 clause is reachable iff is no earlier catch block A in
15679 the try statement such that the type of the catch
15680 clause's parameter is the same as or a subclass of the
15681 type of A's parameter */
15683 for (sub_current = catch;
15684 sub_current != current; sub_current = TREE_CHAIN (sub_current))
15686 tree sub_catch_clause, decl;
15687 sub_catch_clause = TREE_OPERAND (sub_current, 0);
15688 decl = BLOCK_EXPR_DECLS (sub_catch_clause);
15690 if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
15692 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
15693 parse_error_context
15695 "%<catch%> not reached because of the catch clause at line %d",
15696 EXPR_WFL_LINENO (sub_current));
15697 unreachable = error_found = 1;
15701 /* Complete the catch clause block */
15702 catch_block = java_complete_tree (TREE_OPERAND (current, 0));
15703 if (catch_block == error_mark_node)
15708 if (CAN_COMPLETE_NORMALLY (catch_block))
15709 CAN_COMPLETE_NORMALLY (node) = 1;
15710 TREE_OPERAND (current, 0) = catch_block;
15715 /* Things to do here: the exception must be thrown */
15717 /* Link this type to the caught type list */
15718 caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
15721 PUSH_EXCEPTIONS (caught_type_list);
15722 if ((try = java_complete_tree (try)) == error_mark_node)
15724 if (CAN_COMPLETE_NORMALLY (try))
15725 CAN_COMPLETE_NORMALLY (node) = 1;
15728 /* Verification ends here */
15730 return error_mark_node;
15732 TREE_OPERAND (node, 0) = try;
15733 TREE_OPERAND (node, 1) = catch;
15734 TREE_TYPE (node) = void_type_node;
15738 /* 14.17 The synchronized Statement */
15741 patch_synchronized_statement (tree node, tree wfl_op1)
15743 tree expr = java_complete_tree (TREE_OPERAND (node, 0));
15744 tree block = TREE_OPERAND (node, 1);
15746 tree tmp, enter, exit, expr_decl, assignment;
15748 if (expr == error_mark_node)
15750 block = java_complete_tree (block);
15754 /* We might be trying to synchronize on a STRING_CST */
15755 if ((tmp = patch_string (expr)))
15758 /* The TYPE of expr must be a reference type */
15759 if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
15761 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15762 parse_error_context (wfl_operator, "Incompatible type for %<synchronized%>. Can't convert %qs to %<java.lang.Object%>",
15763 lang_printable_name (TREE_TYPE (expr), 0));
15764 return error_mark_node;
15767 if (flag_emit_xref)
15769 TREE_OPERAND (node, 0) = expr;
15770 TREE_OPERAND (node, 1) = java_complete_tree (block);
15771 CAN_COMPLETE_NORMALLY (node) = 1;
15775 /* Generate a try-finally for the synchronized statement, except
15776 that the handler that catches all throw exception calls
15777 _Jv_MonitorExit and then rethrow the exception.
15778 The synchronized statement is then implemented as:
15781 _Jv_MonitorEnter (expression)
15783 _Jv_MonitorExit (expression)
15787 e = _Jv_exception_info ();
15788 _Jv_MonitorExit (expression)
15792 expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
15793 BUILD_MONITOR_ENTER (enter, expr_decl);
15794 BUILD_MONITOR_EXIT (exit, expr_decl);
15795 CAN_COMPLETE_NORMALLY (enter) = 1;
15796 CAN_COMPLETE_NORMALLY (exit) = 1;
15797 assignment = build2 (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
15798 TREE_SIDE_EFFECTS (assignment) = 1;
15799 node = build2 (COMPOUND_EXPR, NULL_TREE,
15800 build2 (COMPOUND_EXPR, NULL_TREE, assignment, enter),
15801 build2 (TRY_FINALLY_EXPR, NULL_TREE, block, exit));
15802 node = build_expr_block (node, expr_decl);
15804 return java_complete_tree (node);
15807 /* 14.16 The throw Statement */
15810 patch_throw_statement (tree node, tree wfl_op1)
15812 tree expr = TREE_OPERAND (node, 0);
15813 tree type = TREE_TYPE (expr);
15814 int unchecked_ok = 0, tryblock_throws_ok = 0;
15816 /* Thrown expression must be assignable to java.lang.Throwable */
15817 if (!try_reference_assignconv (throwable_type_node, expr))
15819 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15820 parse_error_context (wfl_operator,
15821 "Can't throw %qs; it must be a subclass of class %<java.lang.Throwable%>",
15822 lang_printable_name (type, 0));
15823 /* If the thrown expression was a reference, we further the
15824 compile-time check. */
15825 if (!JREFERENCE_TYPE_P (type))
15826 return error_mark_node;
15829 /* At least one of the following must be true */
15831 /* The type of the throw expression is a not checked exception,
15832 i.e. is a unchecked expression. */
15833 unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
15835 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
15836 /* An instance can't throw a checked exception unless that exception
15837 is explicitly declared in the `throws' clause of each
15838 constructor. This doesn't apply to anonymous classes, since they
15839 don't have declared constructors. */
15841 && DECL_INSTINIT_P (current_function_decl)
15842 && !ANONYMOUS_CLASS_P (current_class))
15845 for (current = TYPE_METHODS (current_class); current;
15846 current = TREE_CHAIN (current))
15847 if (DECL_CONSTRUCTOR_P (current)
15848 && !check_thrown_exceptions_do (TREE_TYPE (expr)))
15850 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)",
15851 lang_printable_name (TREE_TYPE (expr), 0));
15852 return error_mark_node;
15856 /* Throw is contained in a try statement and at least one catch
15857 clause can receive the thrown expression or the current method is
15858 declared to throw such an exception. Or, the throw statement is
15859 contained in a method or constructor declaration and the type of
15860 the Expression is assignable to at least one type listed in the
15861 throws clause the declaration. */
15863 tryblock_throws_ok = check_thrown_exceptions_do (TREE_TYPE (expr));
15864 if (!(unchecked_ok || tryblock_throws_ok))
15866 /* If there is a surrounding try block that has no matching
15867 clatch clause, report it first. A surrounding try block exits
15868 only if there is something after the list of checked
15869 exception thrown by the current function (if any). */
15870 if (IN_TRY_BLOCK_P ())
15871 parse_error_context (wfl_operator, "Checked exception %qs can't be caught by any of the catch clause(s) of the surrounding %<try%> block",
15872 lang_printable_name (type, 0));
15873 /* If we have no surrounding try statement and the method doesn't have
15874 any throws, report it now. FIXME */
15876 /* We report that the exception can't be throw from a try block
15877 in all circumstances but when the `throw' is inside a static
15879 else if (!EXCEPTIONS_P (currently_caught_type_list)
15880 && !tryblock_throws_ok)
15882 if (DECL_CLINIT_P (current_function_decl))
15883 parse_error_context (wfl_operator,
15884 "Checked exception %qs can't be thrown in initializer",
15885 lang_printable_name (type, 0));
15887 parse_error_context (wfl_operator,
15888 "Checked exception %qs isn't thrown from a %<try%> block",
15889 lang_printable_name (type, 0));
15891 /* Otherwise, the current method doesn't have the appropriate
15892 throws declaration */
15894 parse_error_context (wfl_operator, "Checked exception %qs doesn't match any of current method's %<throws%> declaration(s)",
15895 lang_printable_name (type, 0));
15896 return error_mark_node;
15899 if (! flag_emit_class_files && ! flag_emit_xref)
15900 BUILD_THROW (node, expr);
15902 /* If doing xrefs, keep the location where the `throw' was seen. */
15903 if (flag_emit_xref)
15904 EXPR_WFL_LINECOL (node) = EXPR_WFL_LINECOL (wfl_op1);
15908 /* Check that exception said to be thrown by method DECL can be
15909 effectively caught from where DECL is invoked. THIS_EXPR is the
15910 expression that computes `this' for the method call. */
15912 check_thrown_exceptions (
15913 #ifdef USE_MAPPED_LOCATION
15914 source_location location,
15919 tree decl, tree this_expr)
15922 int is_array_call = 0;
15924 /* Skip check within generated methods, such as access$<n>. */
15925 if (OUTER_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (current_function_decl)))
15928 if (this_expr != NULL_TREE
15929 && TREE_CODE (TREE_TYPE (this_expr)) == POINTER_TYPE
15930 && TYPE_ARRAY_P (TREE_TYPE (TREE_TYPE (this_expr))))
15933 /* For all the unchecked exceptions thrown by DECL. */
15934 for (throws = DECL_FUNCTION_THROWS (decl); throws;
15935 throws = TREE_CHAIN (throws))
15936 if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
15938 /* Suppress errors about cloning arrays. */
15939 if (is_array_call && DECL_NAME (decl) == get_identifier ("clone"))
15942 #ifdef USE_MAPPED_LOCATION
15943 SET_EXPR_LOCATION (wfl_operator, location);
15945 EXPR_WFL_LINECOL (wfl_operator) = location;
15947 if (DECL_FINIT_P (current_function_decl))
15948 parse_error_context
15949 (wfl_operator, "Exception %qs can't be thrown in initializer",
15950 lang_printable_name (TREE_VALUE (throws), 0));
15953 parse_error_context
15954 (wfl_operator, "Exception %qs must be caught, or it must be declared in the %<throws%> clause of %qs",
15955 lang_printable_name (TREE_VALUE (throws), 0),
15956 (DECL_INIT_P (current_function_decl) ?
15957 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))) :
15958 IDENTIFIER_POINTER (DECL_NAME (current_function_decl))));
15963 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
15964 try-catch blocks, OR is listed in the `throws' clause of the
15968 check_thrown_exceptions_do (tree exception)
15970 tree list = currently_caught_type_list;
15971 resolve_and_layout (exception, NULL_TREE);
15972 /* First, all the nested try-catch-finally at that stage. The
15973 last element contains `throws' clause exceptions, if any. */
15974 if (IS_UNCHECKED_EXCEPTION_P (exception))
15979 for (caught = TREE_VALUE (list); caught; caught = TREE_CHAIN (caught))
15980 if (valid_ref_assignconv_cast_p (exception, TREE_VALUE (caught), 0))
15982 list = TREE_CHAIN (list);
15988 purge_unchecked_exceptions (tree mdecl)
15990 tree throws = DECL_FUNCTION_THROWS (mdecl);
15991 tree new = NULL_TREE;
15995 tree next = TREE_CHAIN (throws);
15996 if (!IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (throws)))
15998 TREE_CHAIN (throws) = new;
16003 /* List is inverted here, but it doesn't matter */
16004 DECL_FUNCTION_THROWS (mdecl) = new;
16007 /* This function goes over all of CLASS_TYPE ctors and checks whether
16008 each of them features at least one unchecked exception in its
16009 `throws' clause. If it's the case, it returns `true', `false'
16013 ctors_unchecked_throws_clause_p (tree class_type)
16017 for (current = TYPE_METHODS (class_type); current;
16018 current = TREE_CHAIN (current))
16020 bool ctu = false; /* Ctor Throws Unchecked */
16021 if (DECL_CONSTRUCTOR_P (current))
16024 for (throws = DECL_FUNCTION_THROWS (current); throws && !ctu;
16025 throws = TREE_CHAIN (throws))
16026 if (inherits_from_p (TREE_VALUE (throws), exception_type_node))
16029 /* We return false as we found one ctor that is unfit. */
16030 if (!ctu && DECL_CONSTRUCTOR_P (current))
16033 /* All ctors feature at least one unchecked exception in their
16034 `throws' clause. */
16038 /* 15.24 Conditional Operator ?: */
16041 patch_conditional_expr (tree node, tree wfl_cond, tree wfl_op1)
16043 tree cond = TREE_OPERAND (node, 0);
16044 tree op1 = TREE_OPERAND (node, 1);
16045 tree op2 = TREE_OPERAND (node, 2);
16046 tree resulting_type = NULL_TREE;
16047 tree t1, t2, patched;
16048 int error_found = 0;
16050 /* Operands of ?: might be StringBuffers crafted as a result of a
16051 string concatenation. Obtain a descent operand here. */
16052 if ((patched = patch_string (op1)))
16053 TREE_OPERAND (node, 1) = op1 = patched;
16054 if ((patched = patch_string (op2)))
16055 TREE_OPERAND (node, 2) = op2 = patched;
16057 t1 = TREE_TYPE (op1);
16058 t2 = TREE_TYPE (op2);
16060 /* The first expression must be a boolean */
16061 if (TREE_TYPE (cond) != boolean_type_node)
16063 SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
16064 parse_error_context (wfl_operator,
16065 "Incompatible type for %<?:%>. Can't convert %qs to %<boolean%>",
16066 lang_printable_name (TREE_TYPE (cond), 0));
16070 /* Second and third can be numeric, boolean (i.e. primitive),
16071 references or null. Anything else results in an error */
16072 if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
16073 || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node)
16074 && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
16075 || (t1 == boolean_type_node && t2 == boolean_type_node)))
16078 /* Determine the type of the conditional expression. Same types are
16079 easy to deal with */
16081 resulting_type = t1;
16083 /* There are different rules for numeric types */
16084 else if (JNUMERIC_TYPE_P (t1))
16086 /* if byte/short found, the resulting type is short */
16087 if ((t1 == byte_type_node && t2 == short_type_node)
16088 || (t1 == short_type_node && t2 == byte_type_node))
16089 resulting_type = short_type_node;
16091 /* If t1 is a constant int and t2 is of type byte, short or char
16092 and t1's value fits in t2, then the resulting type is t2 */
16093 else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
16094 && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
16095 resulting_type = t2;
16097 /* If t2 is a constant int and t1 is of type byte, short or char
16098 and t2's value fits in t1, then the resulting type is t1 */
16099 else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
16100 && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
16101 resulting_type = t1;
16103 /* Otherwise, binary numeric promotion is applied and the
16104 resulting type is the promoted type of operand 1 and 2 */
16106 resulting_type = binary_numeric_promotion (t1, t2,
16107 &TREE_OPERAND (node, 1),
16108 &TREE_OPERAND (node, 2));
16111 /* Cases of a reference and a null type */
16112 else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
16113 resulting_type = t1;
16115 else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
16116 resulting_type = t2;
16118 /* Last case: different reference types. If a type can be converted
16119 into the other one by assignment conversion, the latter
16120 determines the type of the expression */
16121 else if ((resulting_type = try_reference_assignconv (t1, op2)))
16122 resulting_type = promote_type (t1);
16124 else if ((resulting_type = try_reference_assignconv (t2, op1)))
16125 resulting_type = promote_type (t2);
16127 /* If we don't have any resulting type, we're in trouble */
16128 if (!resulting_type)
16130 char *t = xstrdup (lang_printable_name (t1, 0));
16131 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
16132 parse_error_context (wfl_operator,
16133 "Incompatible type for %<?:%>. Can't convert %qs to %qs",
16134 t, lang_printable_name (t2, 0));
16141 TREE_TYPE (node) = error_mark_node;
16142 return error_mark_node;
16145 TREE_TYPE (node) = resulting_type;
16146 TREE_SET_CODE (node, COND_EXPR);
16147 CAN_COMPLETE_NORMALLY (node) = 1;
16151 /* Wrap EXPR with code to initialize DECL's class, if appropriate. */
16154 maybe_build_class_init_for_field (tree decl, tree expr)
16156 tree clas = DECL_CONTEXT (decl);
16157 if (flag_emit_class_files || flag_emit_xref)
16160 if (TREE_CODE (decl) == VAR_DECL && FIELD_STATIC (decl)
16161 && FIELD_FINAL (decl))
16163 tree init = DECL_INITIAL (decl);
16164 if (init != NULL_TREE)
16165 init = fold_constant_for_init (init, decl);
16166 if (init != NULL_TREE && CONSTANT_VALUE_P (init))
16170 return build_class_init (clas, expr);
16173 /* Try to constant fold NODE.
16174 If NODE is not a constant expression, return NULL_EXPR.
16175 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
16178 fold_constant_for_init (tree node, tree context)
16180 tree op0, op1, val;
16181 enum tree_code code = TREE_CODE (node);
16186 if (node == null_pointer_node)
16195 case TRUNC_MOD_EXPR:
16203 case TRUTH_ANDIF_EXPR:
16204 case TRUTH_ORIF_EXPR:
16211 op0 = TREE_OPERAND (node, 0);
16212 op1 = TREE_OPERAND (node, 1);
16213 val = fold_constant_for_init (op0, context);
16214 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16216 TREE_OPERAND (node, 0) = val;
16217 val = fold_constant_for_init (op1, context);
16218 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16220 TREE_OPERAND (node, 1) = val;
16221 return patch_binop (node, op0, op1);
16223 case UNARY_PLUS_EXPR:
16225 case TRUTH_NOT_EXPR:
16228 op0 = TREE_OPERAND (node, 0);
16229 val = fold_constant_for_init (op0, context);
16230 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16232 TREE_OPERAND (node, 0) = val;
16233 val = patch_unaryop (node, op0);
16234 if (! TREE_CONSTANT (val))
16241 val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
16242 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16244 TREE_OPERAND (node, 0) = val;
16245 val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
16246 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16248 TREE_OPERAND (node, 1) = val;
16249 val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
16250 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16252 TREE_OPERAND (node, 2) = val;
16253 return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
16254 : TREE_OPERAND (node, 2);
16258 if (! FIELD_FINAL (node)
16259 || DECL_INITIAL (node) == NULL_TREE)
16261 val = DECL_INITIAL (node);
16262 /* Guard against infinite recursion. */
16263 DECL_INITIAL (node) = NULL_TREE;
16264 val = fold_constant_for_init (val, node);
16265 if (val != NULL_TREE && TREE_CODE (val) != STRING_CST)
16266 val = try_builtin_assignconv (NULL_TREE, TREE_TYPE (node), val);
16267 DECL_INITIAL (node) = val;
16270 case EXPR_WITH_FILE_LOCATION:
16271 /* Compare java_complete_tree and resolve_expression_name. */
16272 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
16273 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
16275 tree name = EXPR_WFL_NODE (node);
16277 if (PRIMARY_P (node))
16279 else if (! QUALIFIED_P (name))
16281 decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
16282 if (decl == NULL_TREE
16283 || (! FIELD_STATIC (decl) && ! FIELD_FINAL (decl)))
16285 return fold_constant_for_init (decl, decl);
16289 tree r = NULL_TREE;
16290 /* Install the proper context for the field resolution. */
16291 tree saved_current_class = current_class;
16292 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
16293 current_class = DECL_CONTEXT (context);
16294 qualify_ambiguous_name (node);
16295 r = resolve_field_access (node, &decl, NULL);
16296 /* Restore prior context. */
16297 current_class = saved_current_class;
16298 if (r != error_mark_node && decl != NULL_TREE)
16299 return fold_constant_for_init (decl, decl);
16305 op0 = TREE_OPERAND (node, 0);
16306 val = fold_constant_for_init (op0, context);
16307 if (val == NULL_TREE || ! TREE_CONSTANT (val))
16309 TREE_OPERAND (node, 0) = val;
16313 #ifdef USE_COMPONENT_REF
16315 case COMPONENT_REF:
16324 #ifdef USE_COMPONENT_REF
16325 /* Context is 'T' for TypeName, 'P' for PackageName,
16326 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
16329 resolve_simple_name (tree name, int context)
16334 resolve_qualified_name (tree name, int context)
16340 init_src_parse (void)
16342 /* Sanity check; we've been bit by this before. */
16343 if (ARRAY_SIZE (ctxp->modifier_ctx) != MODIFIER_TK - PUBLIC_TK)
16349 /* This section deals with the functions that are called when tables
16350 recording class initialization information are traversed. */
16352 /* This function is called for each class that is known definitely
16353 initialized when a given static method was called. This function
16354 augments a compound expression (INFO) storing all assignment to
16355 initialized static class flags if a flag already existed, otherwise
16356 a new one is created. */
16359 emit_test_initialization (void **entry_p, void *info)
16361 tree l = (tree) info;
16363 tree key = (tree) *entry_p;
16365 htab_t cf_ht = DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl);
16367 /* If we haven't found a flag and we're dealing with self registered
16368 with current_function_decl, then don't do anything. Self is
16369 always added as definitely initialized but this information is
16370 valid only if used outside the current function. */
16371 if (current_function_decl == TREE_PURPOSE (l)
16372 && java_treetreehash_find (cf_ht, key) == NULL)
16375 ite = java_treetreehash_new (cf_ht, key);
16377 /* If we don't have a variable, create one and install it. */
16382 decl = build_decl (VAR_DECL, NULL_TREE, boolean_type_node);
16383 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
16384 LOCAL_CLASS_INITIALIZATION_FLAG (decl) = 1;
16385 DECL_CONTEXT (decl) = current_function_decl;
16386 DECL_INITIAL (decl) = boolean_true_node;
16387 /* Don't emit any symbolic debugging info for this decl. */
16388 DECL_IGNORED_P (decl) = 1;
16390 /* The trick is to find the right context for it. */
16391 block = BLOCK_SUBBLOCKS (GET_CURRENT_BLOCK (current_function_decl));
16392 TREE_CHAIN (decl) = BLOCK_EXPR_DECLS (block);
16393 BLOCK_EXPR_DECLS (block) = decl;
16399 /* Now simply augment the compound that holds all the assignments
16400 pertaining to this method invocation. */
16401 init = build2 (MODIFY_EXPR, boolean_type_node, decl, boolean_true_node);
16402 TREE_SIDE_EFFECTS (init) = 1;
16403 TREE_VALUE (l) = add_stmt_to_compound (TREE_VALUE (l), void_type_node, init);
16404 TREE_SIDE_EFFECTS (TREE_VALUE (l)) = 1;
16409 #ifdef __XGETTEXT__
16410 /* Depending on the version of Bison used to compile this grammar,
16411 it may issue generic diagnostics spelled "syntax error" or
16412 "parse error". To prevent this from changing the translation
16413 template randomly, we list all the variants of this particular
16414 diagnostic here. Translators: there is no fine distinction
16415 between diagnostics with "syntax error" in them, and diagnostics
16416 with "parse error" in them. It's okay to give them both the same
16418 const char d1[] = N_("syntax error");
16419 const char d2[] = N_("parse error");
16420 const char d3[] = N_("syntax error; also virtual memory exhausted");
16421 const char d4[] = N_("parse error; also virtual memory exhausted");
16422 const char d5[] = N_("syntax error: cannot back up");
16423 const char d6[] = N_("parse error: cannot back up");
16426 #include "gt-java-parse.h"
16427 #include "gtype-java.h"