1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* This file parses java source code and issues a tree node image
28 suitable for code generation (byte code and targeted CPU assembly
31 The grammar conforms to the Java grammar described in "The Java(TM)
32 Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
33 1996, ISBN 0-201-63451-1"
35 The following modifications were brought to the original grammar:
37 method_body: added the rule '| block SC_TK'
38 static_initializer: added the rule 'static block SC_TK'.
40 Note: All the extra rules described above should go away when the
41 empty_statement rule will work.
43 statement_nsi: 'nsi' should be read no_short_if.
45 Some rules have been modified to support JDK1.1 inner classes
46 definitions and other extensions. */
57 #include "java-tree.h"
69 /* Local function prototypes */
70 static char *java_accstring_lookup PARAMS ((int));
71 static void classitf_redefinition_error PARAMS ((const char *,tree, tree, tree));
72 static void variable_redefinition_error PARAMS ((tree, tree, tree, int));
73 static tree create_class PARAMS ((int, tree, tree, tree));
74 static tree create_interface PARAMS ((int, tree, tree));
75 static tree find_field PARAMS ((tree, tree));
76 static tree lookup_field_wrapper PARAMS ((tree, tree));
77 static int duplicate_declaration_error_p PARAMS ((tree, tree, tree));
78 static void register_fields PARAMS ((int, tree, tree));
79 static tree parser_qualified_classname PARAMS ((tree));
80 static int parser_check_super PARAMS ((tree, tree, tree));
81 static int parser_check_super_interface PARAMS ((tree, tree, tree));
82 static void check_modifiers_consistency PARAMS ((int));
83 static tree lookup_cl PARAMS ((tree));
84 static tree lookup_java_method2 PARAMS ((tree, tree, int));
85 static tree method_header PARAMS ((int, tree, tree, tree));
86 static void fix_method_argument_names PARAMS ((tree ,tree));
87 static tree method_declarator PARAMS ((tree, tree));
88 static void parse_warning_context PARAMS ((tree cl, const char *msg, ...))
90 static void issue_warning_error_from_context PARAMS ((tree, const char *msg, va_list));
91 static void parse_ctor_invocation_error PARAMS ((void));
92 static tree parse_jdk1_1_error PARAMS ((const char *));
93 static void complete_class_report_errors PARAMS ((jdep *));
94 static int process_imports PARAMS ((void));
95 static void read_import_dir PARAMS ((tree));
96 static int find_in_imports_on_demand PARAMS ((tree));
97 static int find_in_imports PARAMS ((tree));
98 static int check_pkg_class_access PARAMS ((tree, tree));
99 static tree resolve_package PARAMS ((tree, tree *));
100 static tree lookup_package_type PARAMS ((const char *, int));
101 static tree lookup_package_type_and_set_next PARAMS ((const char *, int, tree *));
102 static tree resolve_class PARAMS ((tree, tree, tree));
103 static void declare_local_variables PARAMS ((int, tree, tree));
104 static void source_start_java_method PARAMS ((tree));
105 static void source_end_java_method PARAMS ((void));
106 static void expand_start_java_method PARAMS ((tree));
107 static tree find_name_in_single_imports PARAMS ((tree));
108 static void check_abstract_method_header PARAMS ((tree));
109 static tree lookup_java_interface_method2 PARAMS ((tree, tree));
110 static tree resolve_expression_name PARAMS ((tree, tree *));
111 static tree maybe_create_class_interface_decl PARAMS ((tree, tree, tree));
112 static int check_class_interface_creation PARAMS ((int, int, tree,
114 static tree patch_method_invocation PARAMS ((tree, tree, tree,
116 static int breakdown_qualified PARAMS ((tree *, tree *, tree));
117 static tree resolve_and_layout PARAMS ((tree, tree));
118 static tree resolve_no_layout PARAMS ((tree, tree));
119 static int invocation_mode PARAMS ((tree, int));
120 static tree find_applicable_accessible_methods_list PARAMS ((int, tree,
122 static void search_applicable_methods_list PARAMS ((int, tree, tree, tree,
124 static tree find_most_specific_methods_list PARAMS ((tree));
125 static int argument_types_convertible PARAMS ((tree, tree));
126 static tree patch_invoke PARAMS ((tree, tree, tree));
127 static tree lookup_method_invoke PARAMS ((int, tree, tree, tree, tree));
128 static tree register_incomplete_type PARAMS ((int, tree, tree, tree));
129 static tree obtain_incomplete_type PARAMS ((tree));
130 static tree java_complete_lhs PARAMS ((tree));
131 static tree java_complete_tree PARAMS ((tree));
132 static int java_pre_expand_clinit PARAMS ((tree));
133 static void java_complete_expand_method PARAMS ((tree));
134 static int unresolved_type_p PARAMS ((tree, tree *));
135 static void create_jdep_list PARAMS ((struct parser_ctxt *));
136 static tree build_expr_block PARAMS ((tree, tree));
137 static tree enter_block PARAMS ((void));
138 static tree enter_a_block PARAMS ((tree));
139 static tree exit_block PARAMS ((void));
140 static tree lookup_name_in_blocks PARAMS ((tree));
141 static void maybe_absorb_scoping_blocks PARAMS ((void));
142 static tree build_method_invocation PARAMS ((tree, tree));
143 static tree build_new_invocation PARAMS ((tree, tree));
144 static tree build_assignment PARAMS ((int, int, tree, tree));
145 static tree build_binop PARAMS ((enum tree_code, int, tree, tree));
146 static int check_final_assignment PARAMS ((tree ,tree));
147 static tree patch_assignment PARAMS ((tree, tree, tree ));
148 static tree patch_binop PARAMS ((tree, tree, tree));
149 static tree build_unaryop PARAMS ((int, int, tree));
150 static tree build_incdec PARAMS ((int, int, tree, int));
151 static tree patch_unaryop PARAMS ((tree, tree));
152 static tree build_cast PARAMS ((int, tree, tree));
153 static tree build_null_of_type PARAMS ((tree));
154 static tree patch_cast PARAMS ((tree, tree));
155 static int valid_ref_assignconv_cast_p PARAMS ((tree, tree, int));
156 static int valid_builtin_assignconv_identity_widening_p PARAMS ((tree, tree));
157 static int valid_cast_to_p PARAMS ((tree, tree));
158 static int valid_method_invocation_conversion_p PARAMS ((tree, tree));
159 static tree try_builtin_assignconv PARAMS ((tree, tree, tree));
160 static tree try_reference_assignconv PARAMS ((tree, tree));
161 static tree build_unresolved_array_type PARAMS ((tree));
162 static tree build_array_from_name PARAMS ((tree, tree, tree, tree *));
163 static tree build_array_ref PARAMS ((int, tree, tree));
164 static tree patch_array_ref PARAMS ((tree));
165 static tree make_qualified_name PARAMS ((tree, tree, int));
166 static tree merge_qualified_name PARAMS ((tree, tree));
167 static tree make_qualified_primary PARAMS ((tree, tree, int));
168 static int resolve_qualified_expression_name PARAMS ((tree, tree *,
170 static void qualify_ambiguous_name PARAMS ((tree));
171 static void maybe_generate_clinit PARAMS ((void));
172 static tree resolve_field_access PARAMS ((tree, tree *, tree *));
173 static tree build_newarray_node PARAMS ((tree, tree, int));
174 static tree patch_newarray PARAMS ((tree));
175 static tree resolve_type_during_patch PARAMS ((tree));
176 static tree build_this PARAMS ((int));
177 static tree build_return PARAMS ((int, tree));
178 static tree patch_return PARAMS ((tree));
179 static tree maybe_access_field PARAMS ((tree, tree, tree));
180 static int complete_function_arguments PARAMS ((tree));
181 static int check_for_static_method_reference PARAMS ((tree, tree, tree, tree, tree));
182 static int not_accessible_p PARAMS ((tree, tree, int));
183 static void check_deprecation PARAMS ((tree, tree));
184 static int class_in_current_package PARAMS ((tree));
185 static tree build_if_else_statement PARAMS ((int, tree, tree, tree));
186 static tree patch_if_else_statement PARAMS ((tree));
187 static tree add_stmt_to_compound PARAMS ((tree, tree, tree));
188 static tree add_stmt_to_block PARAMS ((tree, tree, tree));
189 static tree patch_exit_expr PARAMS ((tree));
190 static tree build_labeled_block PARAMS ((int, tree));
191 static tree finish_labeled_statement PARAMS ((tree, tree));
192 static tree build_bc_statement PARAMS ((int, int, tree));
193 static tree patch_bc_statement PARAMS ((tree));
194 static tree patch_loop_statement PARAMS ((tree));
195 static tree build_new_loop PARAMS ((tree));
196 static tree build_loop_body PARAMS ((int, tree, int));
197 static tree finish_loop_body PARAMS ((int, tree, tree, int));
198 static tree build_debugable_stmt PARAMS ((int, tree));
199 static tree finish_for_loop PARAMS ((int, tree, tree, tree));
200 static tree patch_switch_statement PARAMS ((tree));
201 static tree string_constant_concatenation PARAMS ((tree, tree));
202 static tree build_string_concatenation PARAMS ((tree, tree));
203 static tree patch_string_cst PARAMS ((tree));
204 static tree patch_string PARAMS ((tree));
205 static tree build_try_statement PARAMS ((int, tree, tree));
206 static tree build_try_finally_statement PARAMS ((int, tree, tree));
207 static tree patch_try_statement PARAMS ((tree));
208 static tree patch_synchronized_statement PARAMS ((tree, tree));
209 static tree patch_throw_statement PARAMS ((tree, tree));
210 static void check_thrown_exceptions PARAMS ((int, tree));
211 static int check_thrown_exceptions_do PARAMS ((tree));
212 static void purge_unchecked_exceptions PARAMS ((tree));
213 static void check_throws_clauses PARAMS ((tree, tree, tree));
214 static void finish_method_declaration PARAMS ((tree));
215 static tree build_super_invocation PARAMS ((tree));
216 static int verify_constructor_circularity PARAMS ((tree, tree));
217 static char *constructor_circularity_msg PARAMS ((tree, tree));
218 static tree build_this_super_qualified_invocation PARAMS ((int, tree, tree,
220 static const char *get_printable_method_name PARAMS ((tree));
221 static tree patch_conditional_expr PARAMS ((tree, tree, tree));
222 static void maybe_generate_finit PARAMS ((void));
223 static void fix_constructors PARAMS ((tree));
224 static int verify_constructor_super PARAMS ((void));
225 static tree create_artificial_method PARAMS ((tree, int, tree, tree, tree));
226 static void start_artificial_method_body PARAMS ((tree));
227 static void end_artificial_method_body PARAMS ((tree));
228 static int check_method_redefinition PARAMS ((tree, tree));
229 static int reset_method_name PARAMS ((tree));
230 static void java_check_regular_methods PARAMS ((tree));
231 static void java_check_abstract_methods PARAMS ((tree));
232 static tree maybe_build_primttype_type_ref PARAMS ((tree, tree));
233 static void unreachable_stmt_error PARAMS ((tree));
234 static tree find_expr_with_wfl PARAMS ((tree));
235 static void missing_return_error PARAMS ((tree));
236 static tree build_new_array_init PARAMS ((int, tree));
237 static tree patch_new_array_init PARAMS ((tree, tree));
238 static tree maybe_build_array_element_wfl PARAMS ((tree));
239 static int array_constructor_check_entry PARAMS ((tree, tree));
240 static const char *purify_type_name PARAMS ((const char *));
241 static tree fold_constant_for_init PARAMS ((tree, tree));
242 static tree strip_out_static_field_access_decl PARAMS ((tree));
243 static jdeplist *reverse_jdep_list PARAMS ((struct parser_ctxt *));
244 static void static_ref_err PARAMS ((tree, tree, tree));
245 static void parser_add_interface PARAMS ((tree, tree, tree));
246 static void add_superinterfaces PARAMS ((tree, tree));
247 static tree jdep_resolve_class PARAMS ((jdep *));
248 static int note_possible_classname PARAMS ((const char *, int));
249 static void java_complete_expand_methods PARAMS ((void));
250 static void java_expand_finals PARAMS ((void));
251 static tree cut_identifier_in_qualified PARAMS ((tree));
252 static tree java_stabilize_reference PARAMS ((tree));
253 static tree do_unary_numeric_promotion PARAMS ((tree));
254 static char * operator_string PARAMS ((tree));
255 static tree do_merge_string_cste PARAMS ((tree, const char *, int, int));
256 static tree merge_string_cste PARAMS ((tree, tree, int));
257 static tree java_refold PARAMS ((tree));
258 static int java_decl_equiv PARAMS ((tree, tree));
259 static int binop_compound_p PARAMS ((enum tree_code));
260 static tree search_loop PARAMS ((tree));
261 static int labeled_block_contains_loop_p PARAMS ((tree, tree));
262 static void check_abstract_method_definitions PARAMS ((int, tree, tree));
263 static void java_check_abstract_method_definitions PARAMS ((tree));
264 static void java_debug_context_do PARAMS ((int));
266 /* Number of error found so far. */
267 int java_error_count;
268 /* Number of warning found so far. */
269 int java_warning_count;
270 /* Tell when not to fold, when doing xrefs */
273 /* The current parser context */
274 struct parser_ctxt *ctxp;
276 /* List of things that were analyzed for which code will be generated */
277 static struct parser_ctxt *ctxp_for_generation = NULL;
279 /* binop_lookup maps token to tree_code. It is used where binary
280 operations are involved and required by the parser. RDIV_EXPR
281 covers both integral/floating point division. The code is changed
282 once the type of both operator is worked out. */
284 static enum tree_code binop_lookup[19] =
286 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
287 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
288 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
289 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
290 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
292 #define BINOP_LOOKUP(VALUE) \
293 binop_lookup [((VALUE) - PLUS_TK)% \
294 (sizeof (binop_lookup) / sizeof (binop_lookup[0]))]
296 /* This is the end index for binary operators that can also be used
297 in compound assignements. */
298 #define BINOP_COMPOUND_CANDIDATES 11
300 /* Fake WFL used to report error message. It is initialized once if
301 needed and reused with it's location information is overriden. */
302 tree wfl_operator = NULL_TREE;
304 /* The "$L" identifier we use to create labels. */
305 static tree label_id = NULL_TREE;
307 /* The "StringBuffer" identifier used for the String `+' operator. */
308 static tree wfl_string_buffer = NULL_TREE;
310 /* The "append" identifier used for String `+' operator. */
311 static tree wfl_append = NULL_TREE;
313 /* The "toString" identifier used for String `+' operator. */
314 static tree wfl_to_string = NULL_TREE;
316 /* The "java.lang" import qualified name. */
317 static tree java_lang_id = NULL_TREE;
319 /* The "java.lang.Cloneable" qualified name. */
320 static tree java_lang_cloneable = NULL_TREE;
322 /* Context and flag for static blocks */
323 static tree current_static_block = NULL_TREE;
325 /* The list of all packages we've seen so far */
326 static tree package_list = NULL_TREE;
328 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
329 line and point it out. */
330 /* Should point out the one that don't fit. ASCII/unicode, going
333 #define check_modifiers(__message, __value, __mask) do { \
334 if ((__value) & ~(__mask)) \
336 int i, remainder = (__value) & ~(__mask); \
337 for (i = 0; i <= 10; i++) \
338 if ((1 << i) & remainder) \
339 parse_error_context (ctxp->modifier_ctx [i], (__message), \
340 java_accstring_lookup (1 << i)); \
362 /* Things defined here have to match the order of what's in the
363 binop_lookup table. */
365 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
366 %token LS_TK SRS_TK ZRS_TK
367 %token AND_TK XOR_TK OR_TK
368 %token BOOL_AND_TK BOOL_OR_TK
369 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
371 /* This maps to the same binop_lookup entry than the token above */
373 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
375 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
376 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
379 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
381 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
382 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
383 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
384 %token PAD_TK ABSTRACT_TK MODIFIER_TK
386 /* Keep those two in order, too */
387 %token DECR_TK INCR_TK
389 /* From now one, things can be in any order */
391 %token DEFAULT_TK IF_TK THROW_TK
392 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
393 %token THROWS_TK BREAK_TK IMPORT_TK
394 %token ELSE_TK INSTANCEOF_TK RETURN_TK
395 %token VOID_TK CATCH_TK INTERFACE_TK
396 %token CASE_TK EXTENDS_TK FINALLY_TK
397 %token SUPER_TK WHILE_TK CLASS_TK
398 %token SWITCH_TK CONST_TK TRY_TK
399 %token FOR_TK NEW_TK CONTINUE_TK
400 %token GOTO_TK PACKAGE_TK THIS_TK
402 %token BYTE_TK SHORT_TK INT_TK LONG_TK
403 %token CHAR_TK INTEGRAL_TK
405 %token FLOAT_TK DOUBLE_TK FP_TK
409 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
411 %token ASSIGN_ANY_TK ASSIGN_TK
412 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
414 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
415 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
417 %type <value> modifiers MODIFIER_TK final
419 %type <node> super ID_TK identifier
420 %type <node> name simple_name qualified_name
421 %type <node> class_declaration type_declaration compilation_unit
422 field_declaration method_declaration extends_interfaces
423 interfaces interface_type_list
424 interface_declaration class_member_declaration
425 import_declarations package_declaration
426 type_declarations interface_body
427 interface_member_declaration constant_declaration
428 interface_member_declarations interface_type
429 abstract_method_declaration interface_type_list
430 %type <node> class_body_declaration class_member_declaration
431 static_initializer constructor_declaration block
432 %type <node> class_body_declarations constructor_header
433 %type <node> class_or_interface_type class_type class_type_list
434 constructor_declarator explicit_constructor_invocation
435 %type <node> dim_expr dim_exprs this_or_super throws
437 %type <node> variable_declarator_id variable_declarator
438 variable_declarators variable_initializer
439 variable_initializers constructor_body
442 %type <node> class_body block_end constructor_block_end
443 %type <node> statement statement_without_trailing_substatement
444 labeled_statement if_then_statement label_decl
445 if_then_else_statement while_statement for_statement
446 statement_nsi labeled_statement_nsi do_statement
447 if_then_else_statement_nsi while_statement_nsi
448 for_statement_nsi statement_expression_list for_init
449 for_update statement_expression expression_statement
450 primary_no_new_array expression primary
451 array_creation_expression array_type
452 class_instance_creation_expression field_access
453 method_invocation array_access something_dot_new
454 argument_list postfix_expression while_expression
455 post_increment_expression post_decrement_expression
456 unary_expression_not_plus_minus unary_expression
457 pre_increment_expression pre_decrement_expression
458 unary_expression_not_plus_minus cast_expression
459 multiplicative_expression additive_expression
460 shift_expression relational_expression
461 equality_expression and_expression
462 exclusive_or_expression inclusive_or_expression
463 conditional_and_expression conditional_or_expression
464 conditional_expression assignment_expression
465 left_hand_side assignment for_header for_begin
466 constant_expression do_statement_begin empty_statement
467 switch_statement synchronized_statement throw_statement
468 try_statement switch_expression switch_block
469 catches catch_clause catch_clause_parameter finally
470 %type <node> return_statement break_statement continue_statement
472 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
473 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
474 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
475 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
476 %type <operator> ASSIGN_ANY_TK assignment_operator
477 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
478 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
479 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
480 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
481 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
482 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
483 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
485 %type <node> method_body
487 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
488 STRING_LIT_TK NULL_TK VOID_TK
490 %type <node> IF_TK WHILE_TK FOR_TK
492 %type <node> formal_parameter_list formal_parameter
493 method_declarator method_header
495 %type <node> primitive_type reference_type type
496 BOOLEAN_TK INTEGRAL_TK FP_TK
499 /* 19.2 Production from 2.3: The Syntactic Grammar */
505 /* 19.3 Productions from 3: Lexical structure */
515 /* 19.4 Productions from 4: Types, Values and Variables */
528 class_or_interface_type
532 class_or_interface_type:
537 class_or_interface_type /* Default rule */
541 class_or_interface_type
545 primitive_type OSB_TK CSB_TK
547 $$ = build_java_array_type ($1, -1);
548 CLASS_LOADED_P ($$) = 1;
551 { $$ = build_unresolved_array_type ($1); }
552 | array_type OSB_TK CSB_TK
553 { $$ = build_unresolved_array_type ($1); }
554 | primitive_type OSB_TK error
555 {RULE ("']' expected"); RECOVER;}
556 | array_type OSB_TK error
557 {RULE ("']' expected"); RECOVER;}
560 /* 19.5 Productions from 6: Names */
562 simple_name /* Default rule */
563 | qualified_name /* Default rule */
567 identifier /* Default rule */
571 name DOT_TK identifier
572 { $$ = make_qualified_name ($1, $3, $2.location); }
579 /* 19.6: Production from 7: Packages */
582 | package_declaration
583 | import_declarations
585 | package_declaration import_declarations
586 | package_declaration type_declarations
587 | import_declarations type_declarations
588 | package_declaration import_declarations type_declarations
596 | import_declarations import_declaration
604 | type_declarations type_declaration
608 PACKAGE_TK name SC_TK
610 ctxp->package = EXPR_WFL_NODE ($2);
611 package_list = tree_cons (ctxp->package, NULL, package_list);
614 {yyerror ("Missing name"); RECOVER;}
615 | PACKAGE_TK name error
616 {yyerror ("';' expected"); RECOVER;}
620 single_type_import_declaration
621 | type_import_on_demand_declaration
624 single_type_import_declaration:
627 tree name = EXPR_WFL_NODE ($2), node, last_name;
628 int i = IDENTIFIER_LENGTH (name)-1;
629 const char *last = &IDENTIFIER_POINTER (name)[i];
630 while (last != IDENTIFIER_POINTER (name))
636 last_name = get_identifier (++last);
637 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
639 tree err = find_name_in_single_imports (last_name);
640 if (err && err != name)
642 ($2, "Ambiguous class: `%s' and `%s'",
643 IDENTIFIER_POINTER (name),
644 IDENTIFIER_POINTER (err));
646 REGISTER_IMPORT ($2, last_name)
649 REGISTER_IMPORT ($2, last_name);
652 {yyerror ("Missing name"); RECOVER;}
653 | IMPORT_TK name error
654 {yyerror ("';' expected"); RECOVER;}
657 type_import_on_demand_declaration:
658 IMPORT_TK name DOT_TK MULT_TK SC_TK
660 tree name = EXPR_WFL_NODE ($2);
661 /* Don't import java.lang.* twice. */
662 if (name != java_lang_id)
664 tree node = build_tree_list ($2, NULL_TREE);
665 read_import_dir ($2);
666 TREE_CHAIN (node) = ctxp->import_demand_list;
667 ctxp->import_demand_list = node;
670 | IMPORT_TK name DOT_TK error
671 {yyerror ("'*' expected"); RECOVER;}
672 | IMPORT_TK name DOT_TK MULT_TK error
673 {yyerror ("';' expected"); RECOVER;}
679 maybe_generate_finit ();
680 maybe_generate_clinit ();
683 | interface_declaration
685 maybe_generate_clinit ();
693 yyerror ("Class or interface declaration expected");
697 /* 19.7 Shortened from the original:
698 modifiers: modifier | modifiers modifier
699 modifier: any of public... */
705 | modifiers MODIFIER_TK
710 (ctxp->modifier_ctx [$2], "Modifier `%s' declared twice",
711 java_accstring_lookup (acc));
719 /* 19.8.1 Production from $8.1: Class Declaration */
721 modifiers CLASS_TK identifier super interfaces
722 { create_class ($1, $3, $4, $5); }
727 | CLASS_TK identifier super interfaces
728 { create_class (0, $2, $3, $4); }
733 | modifiers CLASS_TK error
734 {yyerror ("Missing class name"); RECOVER;}
736 {yyerror ("Missing class name"); RECOVER;}
737 | CLASS_TK identifier error
739 if (!ctxp->class_err) yyerror ("'{' expected");
742 | modifiers CLASS_TK identifier error
743 {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
748 | EXTENDS_TK class_type
750 | EXTENDS_TK class_type error
751 {yyerror ("'{' expected"); ctxp->class_err=1;}
753 {yyerror ("Missing super class name"); ctxp->class_err=1;}
758 | IMPLEMENTS_TK interface_type_list
760 | IMPLEMENTS_TK error
763 yyerror ("Missing interface name");
770 ctxp->interface_number = 1;
771 $$ = build_tree_list ($1, NULL_TREE);
773 | interface_type_list C_TK interface_type
775 ctxp->interface_number++;
776 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
778 | interface_type_list C_TK error
779 {yyerror ("Missing interface name"); RECOVER;}
785 /* Store the location of the `}' when doing xrefs */
787 DECL_END_SOURCE_LINE (ctxp->current_parsed_class) =
788 EXPR_WFL_ADD_COL ($2.location, 1);
789 $$ = ctxp->current_parsed_class;
791 | OCB_TK class_body_declarations CCB_TK
793 /* Store the location of the `}' when doing xrefs */
795 DECL_END_SOURCE_LINE (ctxp->current_parsed_class) =
796 EXPR_WFL_ADD_COL ($3.location, 1);
797 $$ = ctxp->current_parsed_class;
801 class_body_declarations:
802 class_body_declaration
803 | class_body_declarations class_body_declaration
806 class_body_declaration:
807 class_member_declaration
809 | constructor_declaration
810 | block /* Added, JDK1.1, instance initializer */
811 { $$ = parse_jdk1_1_error ("instance initializer"); }
814 class_member_declaration:
816 | field_declaration SC_TK
819 | class_declaration /* Added, JDK1.1 inner classes */
820 { $$ = parse_jdk1_1_error ("inner classe declaration"); }
821 | interface_declaration /* Added, JDK1.1 inner classes */
822 { $$ = parse_jdk1_1_error ("inner interface declaration"); }
825 /* 19.8.2 Productions from 8.3: Field Declarations */
827 type variable_declarators SC_TK
828 { register_fields (0, $1, $2); }
829 | modifiers type variable_declarators SC_TK
832 ("Illegal modifier `%s' for field declaration",
833 $1, FIELD_MODIFIERS);
834 check_modifiers_consistency ($1);
835 register_fields ($1, $2, $3);
839 variable_declarators:
840 /* Should we use build_decl_list () instead ? FIXME */
841 variable_declarator /* Default rule */
842 | variable_declarators C_TK variable_declarator
843 { $$ = chainon ($1, $3); }
844 | variable_declarators C_TK error
845 {yyerror ("Missing term"); RECOVER;}
849 variable_declarator_id
850 { $$ = build_tree_list ($1, NULL_TREE); }
851 | variable_declarator_id ASSIGN_TK variable_initializer
853 if (java_error_count)
856 ($1, build_assignment ($2.token, $2.location, $1, $3));
858 | variable_declarator_id ASSIGN_TK error
860 yyerror ("Missing variable initializer");
861 $$ = build_tree_list ($1, NULL_TREE);
864 | variable_declarator_id ASSIGN_TK variable_initializer error
866 yyerror ("';' expected");
867 $$ = build_tree_list ($1, NULL_TREE);
872 variable_declarator_id:
874 | variable_declarator_id OSB_TK CSB_TK
875 { $$ = build_unresolved_array_type ($1); }
877 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
878 | variable_declarator_id OSB_TK error
879 {yyerror ("']' expected"); DRECOVER(vdi);}
880 | variable_declarator_id CSB_TK error
881 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
884 variable_initializer:
889 /* 19.8.3 Productions from 8.4: Method Declarations */
893 current_function_decl = $1;
894 source_start_java_method (current_function_decl);
897 { finish_method_declaration ($3); }
898 | method_header error
899 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
903 type method_declarator throws
904 { $$ = method_header (0, $1, $2, $3); }
905 | VOID_TK method_declarator throws
906 { $$ = method_header (0, void_type_node, $2, $3); }
907 | modifiers type method_declarator throws
908 { $$ = method_header ($1, $2, $3, $4); }
909 | modifiers VOID_TK method_declarator throws
910 { $$ = method_header ($1, void_type_node, $3, $4); }
913 yyerror ("Invalid method declaration, method name required");
916 | modifiers type error
919 {yyerror ("Identifier expected"); RECOVER;}
920 | modifiers VOID_TK error
921 {yyerror ("Identifier expected"); RECOVER;}
924 yyerror ("Invalid method declaration, return type required");
930 identifier OP_TK CP_TK
931 { $$ = method_declarator ($1, NULL_TREE); }
932 | identifier OP_TK formal_parameter_list CP_TK
933 { $$ = method_declarator ($1, $3); }
934 | method_declarator OSB_TK CSB_TK
936 EXPR_WFL_LINECOL (wfl_operator) = $2.location;
938 build_unresolved_array_type (TREE_PURPOSE ($1));
939 parse_warning_context
941 "Discouraged form of returned type specification");
943 | identifier OP_TK error
944 {yyerror ("')' expected"); DRECOVER(method_declarator);}
945 | method_declarator OSB_TK error
946 {yyerror ("']' expected"); RECOVER;}
949 formal_parameter_list:
952 ctxp->formal_parameter_number = 1;
954 | formal_parameter_list C_TK formal_parameter
956 ctxp->formal_parameter_number += 1;
957 $$ = chainon ($1, $3);
959 | formal_parameter_list C_TK error
960 {yyerror ("Missing formal parameter term"); RECOVER;}
964 type variable_declarator_id
966 $$ = build_tree_list ($2, $1);
968 | final type variable_declarator_id /* Added, JDK1.1 final parms */
970 parse_jdk1_1_error ("final parameters");
971 $$ = build_tree_list ($3, $2);
975 yyerror ("Missing identifier"); RECOVER;
980 yyerror ("Missing identifier"); RECOVER;
988 check_modifiers ("Illegal modifier `%s'. Only `final' was expected here",
991 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
997 | THROWS_TK class_type_list
1000 {yyerror ("Missing class type term"); RECOVER;}
1005 { $$ = build_tree_list ($1, $1); }
1006 | class_type_list C_TK class_type
1007 { $$ = tree_cons ($3, $3, $1); }
1008 | class_type_list C_TK error
1009 {yyerror ("Missing class type term"); RECOVER;}
1016 { $$ = NULL_TREE; } /* Probably not the right thing to do. */
1019 /* 19.8.4 Productions from 8.5: Static Initializers */
1023 TREE_CHAIN ($2) = ctxp->static_initialized;
1024 ctxp->static_initialized = $2;
1026 | static block SC_TK /* Shouldn't be here. FIXME */
1028 TREE_CHAIN ($2) = ctxp->static_initialized;
1029 ctxp->static_initialized = $2;
1033 static: /* Test lval.sub_token here */
1036 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1040 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1041 constructor_declaration:
1044 current_function_decl = $1;
1045 source_start_java_method (current_function_decl);
1048 { finish_method_declaration ($3); }
1052 constructor_declarator throws
1053 { $$ = method_header (0, NULL_TREE, $1, $2); }
1054 | modifiers constructor_declarator throws
1055 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1058 constructor_declarator:
1059 simple_name OP_TK CP_TK
1060 { $$ = method_declarator ($1, NULL_TREE); }
1061 | simple_name OP_TK formal_parameter_list CP_TK
1062 { $$ = method_declarator ($1, $3); }
1066 /* Unlike regular method, we always need a complete (empty)
1067 body so we can safely perform all the required code
1068 addition (super invocation and field initialization) */
1069 block_begin constructor_block_end
1071 BLOCK_EXPR_BODY ($2) = empty_stmt_node;
1074 | block_begin explicit_constructor_invocation constructor_block_end
1076 | block_begin block_statements constructor_block_end
1078 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1082 constructor_block_end:
1086 /* Error recovery for that rule moved down expression_statement: rule. */
1087 explicit_constructor_invocation:
1088 this_or_super OP_TK CP_TK SC_TK
1090 $$ = build_method_invocation ($1, NULL_TREE);
1091 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1092 $$ = java_method_add_stmt (current_function_decl, $$);
1094 | this_or_super OP_TK argument_list CP_TK SC_TK
1096 $$ = build_method_invocation ($1, $3);
1097 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1098 $$ = java_method_add_stmt (current_function_decl, $$);
1100 /* Added, JDK1.1 inner classes. Modified because the rule
1101 'primary' couldn't work. */
1102 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1103 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1104 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1105 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1108 this_or_super: /* Added, simplifies error diagnostics */
1111 tree wfl = build_wfl_node (this_identifier_node);
1112 EXPR_WFL_LINECOL (wfl) = $1.location;
1117 tree wfl = build_wfl_node (super_identifier_node);
1118 EXPR_WFL_LINECOL (wfl) = $1.location;
1123 /* 19.9 Productions from 9: Interfaces */
1124 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1125 interface_declaration:
1126 INTERFACE_TK identifier
1127 { create_interface (0, $2, NULL_TREE); }
1132 | modifiers INTERFACE_TK identifier
1133 { create_interface ($1, $3, NULL_TREE); }
1138 | INTERFACE_TK identifier extends_interfaces
1139 { create_interface (0, $2, $3); }
1144 | modifiers INTERFACE_TK identifier extends_interfaces
1145 { create_interface ($1, $3, $4); }
1150 | INTERFACE_TK identifier error
1151 {yyerror ("'{' expected"); RECOVER;}
1152 | modifiers INTERFACE_TK identifier error
1153 {yyerror ("'{' expected"); RECOVER;}
1157 EXTENDS_TK interface_type
1159 ctxp->interface_number = 1;
1160 $$ = build_tree_list ($2, NULL_TREE);
1162 | extends_interfaces C_TK interface_type
1164 ctxp->interface_number++;
1165 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1168 {yyerror ("Invalid interface type"); RECOVER;}
1169 | extends_interfaces C_TK error
1170 {yyerror ("Missing term"); RECOVER;}
1176 | OCB_TK interface_member_declarations CCB_TK
1180 interface_member_declarations:
1181 interface_member_declaration
1182 | interface_member_declarations interface_member_declaration
1185 interface_member_declaration:
1186 constant_declaration
1187 | abstract_method_declaration
1188 | class_declaration /* Added, JDK1.1 inner classes */
1189 { $$ = parse_jdk1_1_error ("inner class declaration"); }
1190 | interface_declaration /* Added, JDK1.1 inner classes */
1191 { $$ = parse_jdk1_1_error ("inner interface declaration"); }
1194 constant_declaration:
1198 abstract_method_declaration:
1201 check_abstract_method_header ($1);
1202 current_function_decl = NULL_TREE; /* FIXME ? */
1204 | method_header error
1205 {yyerror ("';' expected"); RECOVER;}
1208 /* 19.10 Productions from 10: Arrays */
1211 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1212 | OCB_TK variable_initializers CCB_TK
1213 { $$ = build_new_array_init ($1.location, $2); }
1214 | OCB_TK variable_initializers C_TK CCB_TK
1215 { $$ = build_new_array_init ($1.location, $2); }
1218 variable_initializers:
1219 variable_initializer
1221 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1224 | variable_initializers C_TK variable_initializer
1226 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1228 | variable_initializers C_TK error
1229 {yyerror ("Missing term"); RECOVER;}
1232 /* 19.11 Production from 14: Blocks and Statements */
1236 /* Store the location of the `}' when doing xrefs */
1237 if (current_function_decl && flag_emit_xref)
1238 DECL_END_SOURCE_LINE (current_function_decl) =
1239 EXPR_WFL_ADD_COL ($2.location, 1);
1240 $$ = empty_stmt_node;
1242 | block_begin block_statements block_end
1254 maybe_absorb_scoping_blocks ();
1255 /* Store the location of the `}' when doing xrefs */
1256 if (current_function_decl && flag_emit_xref)
1257 DECL_END_SOURCE_LINE (current_function_decl) =
1258 EXPR_WFL_ADD_COL ($1.location, 1);
1265 | block_statements block_statement
1269 local_variable_declaration_statement
1271 { java_method_add_stmt (current_function_decl, $1); }
1272 | class_declaration /* Added, JDK1.1 inner classes */
1273 { parse_jdk1_1_error ("inner class declaration"); }
1276 local_variable_declaration_statement:
1277 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1280 local_variable_declaration:
1281 type variable_declarators
1282 { declare_local_variables (0, $1, $2); }
1283 | final type variable_declarators /* Added, JDK1.1 final locals */
1284 { declare_local_variables ($1, $2, $3); }
1288 statement_without_trailing_substatement
1291 | if_then_else_statement
1294 { $$ = exit_block (); }
1298 statement_without_trailing_substatement
1299 | labeled_statement_nsi
1300 | if_then_else_statement_nsi
1301 | while_statement_nsi
1303 { $$ = exit_block (); }
1306 statement_without_trailing_substatement:
1309 | expression_statement
1313 | continue_statement
1315 | synchronized_statement
1322 { $$ = empty_stmt_node; }
1326 identifier REL_CL_TK
1328 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1329 EXPR_WFL_NODE ($1));
1331 push_labeled_block ($$);
1332 PUSH_LABELED_BLOCK ($$);
1337 label_decl statement
1338 { $$ = finish_labeled_statement ($1, $2); }
1340 {yyerror ("':' expected"); RECOVER;}
1343 labeled_statement_nsi:
1344 label_decl statement_nsi
1345 { $$ = finish_labeled_statement ($1, $2); }
1348 /* We concentrate here a bunch of error handling rules that we couldn't write
1349 earlier, because expression_statement catches a missing ';'. */
1350 expression_statement:
1351 statement_expression SC_TK
1353 /* We have a statement. Generate a WFL around it so
1355 $$ = build_expr_wfl ($1, input_filename, lineno, 0);
1356 /* We know we have a statement, so set the debug
1357 info to be eventually generate here. */
1358 $$ = JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1362 if (ctxp->prevent_ese != lineno)
1363 yyerror ("Invalid expression statement");
1364 DRECOVER (expr_stmt);
1368 if (ctxp->prevent_ese != lineno)
1369 yyerror ("Invalid expression statement");
1370 DRECOVER (expr_stmt);
1374 if (ctxp->prevent_ese != lineno)
1375 yyerror ("Invalid expression statement");
1376 DRECOVER (expr_stmt);
1378 | this_or_super OP_TK error
1379 {yyerror ("')' expected"); RECOVER;}
1380 | this_or_super OP_TK CP_TK error
1382 parse_ctor_invocation_error ();
1385 | this_or_super OP_TK argument_list error
1386 {yyerror ("')' expected"); RECOVER;}
1387 | this_or_super OP_TK argument_list CP_TK error
1389 parse_ctor_invocation_error ();
1392 | name DOT_TK SUPER_TK error
1393 {yyerror ("'(' expected"); RECOVER;}
1394 | name DOT_TK SUPER_TK OP_TK error
1395 {yyerror ("')' expected"); RECOVER;}
1396 | name DOT_TK SUPER_TK OP_TK argument_list error
1397 {yyerror ("')' expected"); RECOVER;}
1398 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1399 {yyerror ("';' expected"); RECOVER;}
1400 | name DOT_TK SUPER_TK OP_TK CP_TK error
1401 {yyerror ("';' expected"); RECOVER;}
1404 statement_expression:
1406 | pre_increment_expression
1407 | pre_decrement_expression
1408 | post_increment_expression
1409 | post_decrement_expression
1411 | class_instance_creation_expression
1415 IF_TK OP_TK expression CP_TK statement
1417 $$ = build_if_else_statement ($2.location, $3,
1421 {yyerror ("'(' expected"); RECOVER;}
1423 {yyerror ("Missing term"); RECOVER;}
1424 | IF_TK OP_TK expression error
1425 {yyerror ("')' expected"); RECOVER;}
1428 if_then_else_statement:
1429 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1430 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1433 if_then_else_statement_nsi:
1434 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1435 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1445 /* Make into "proper list" of COMPOUND_EXPRs.
1446 I.e. make the last statment also have its own
1448 maybe_absorb_scoping_blocks ();
1449 TREE_OPERAND ($1, 1) = exit_block ();
1450 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1455 SWITCH_TK OP_TK expression CP_TK
1457 $$ = build (SWITCH_EXPR, NULL_TREE, $3, NULL_TREE);
1458 EXPR_WFL_LINECOL ($$) = $2.location;
1461 {yyerror ("'(' expected"); RECOVER;}
1462 | SWITCH_TK OP_TK error
1463 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1464 | SWITCH_TK OP_TK expression CP_TK error
1465 {yyerror ("'{' expected"); RECOVER;}
1468 /* Default assignment is there to avoid type node on switch_block
1474 | OCB_TK switch_labels CCB_TK
1476 | OCB_TK switch_block_statement_groups CCB_TK
1478 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1482 switch_block_statement_groups:
1483 switch_block_statement_group
1484 | switch_block_statement_groups switch_block_statement_group
1487 switch_block_statement_group:
1488 switch_labels block_statements
1493 | switch_labels switch_label
1497 CASE_TK constant_expression REL_CL_TK
1499 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1500 EXPR_WFL_LINECOL (lab) = $1.location;
1501 java_method_add_stmt (current_function_decl, lab);
1503 | DEFAULT_TK REL_CL_TK
1505 tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
1506 EXPR_WFL_LINECOL (lab) = $1.location;
1507 java_method_add_stmt (current_function_decl, lab);
1510 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1511 | CASE_TK constant_expression error
1512 {yyerror ("':' expected"); RECOVER;}
1514 {yyerror ("':' expected"); RECOVER;}
1518 WHILE_TK OP_TK expression CP_TK
1520 tree body = build_loop_body ($2.location, $3, 0);
1521 $$ = build_new_loop (body);
1526 while_expression statement
1527 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1529 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1530 | WHILE_TK OP_TK error
1531 {yyerror ("Missing term and ')' expected"); RECOVER;}
1532 | WHILE_TK OP_TK expression error
1533 {yyerror ("')' expected"); RECOVER;}
1536 while_statement_nsi:
1537 while_expression statement_nsi
1538 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1544 tree body = build_loop_body (0, NULL_TREE, 1);
1545 $$ = build_new_loop (body);
1547 /* Need error handing here. FIXME */
1551 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1552 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1556 for_begin SC_TK expression SC_TK for_update CP_TK statement
1557 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7); }
1558 | for_begin SC_TK SC_TK for_update CP_TK statement
1560 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1561 /* We have not condition, so we get rid of the EXIT_EXPR */
1562 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1565 | for_begin SC_TK error
1566 {yyerror ("Invalid control expression"); RECOVER;}
1567 | for_begin SC_TK expression SC_TK error
1568 {yyerror ("Invalid update expression"); RECOVER;}
1569 | for_begin SC_TK SC_TK error
1570 {yyerror ("Invalid update expression"); RECOVER;}
1574 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1575 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1576 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1578 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1579 /* We have not condition, so we get rid of the EXIT_EXPR */
1580 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1588 /* This scope defined for local variable that may be
1589 defined within the scope of the for loop */
1593 {yyerror ("'(' expected"); DRECOVER(for_1);}
1594 | FOR_TK OP_TK error
1595 {yyerror ("Invalid init statement"); RECOVER;}
1601 /* We now declare the loop body. The loop is
1602 declared as a for loop. */
1603 tree body = build_loop_body (0, NULL_TREE, 0);
1604 $$ = build_new_loop (body);
1605 IS_FOR_LOOP_P ($$) = 1;
1606 /* The loop is added to the current block the for
1607 statement is defined within */
1608 java_method_add_stmt (current_function_decl, $$);
1611 for_init: /* Can be empty */
1612 { $$ = empty_stmt_node; }
1613 | statement_expression_list
1615 /* Init statement recorded within the previously
1616 defined block scope */
1617 $$ = java_method_add_stmt (current_function_decl, $1);
1619 | local_variable_declaration
1621 /* Local variable are recorded within the previously
1622 defined block scope */
1625 | statement_expression_list error
1626 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1629 for_update: /* Can be empty */
1630 {$$ = empty_stmt_node;}
1631 | statement_expression_list
1632 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1635 statement_expression_list:
1636 statement_expression
1637 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1638 | statement_expression_list C_TK statement_expression
1639 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1640 | statement_expression_list C_TK error
1641 {yyerror ("Missing term"); RECOVER;}
1646 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1647 | BREAK_TK identifier SC_TK
1648 { $$ = build_bc_statement ($1.location, 1, $2); }
1650 {yyerror ("Missing term"); RECOVER;}
1651 | BREAK_TK identifier error
1652 {yyerror ("';' expected"); RECOVER;}
1657 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1658 | CONTINUE_TK identifier SC_TK
1659 { $$ = build_bc_statement ($1.location, 0, $2); }
1661 {yyerror ("Missing term"); RECOVER;}
1662 | CONTINUE_TK identifier error
1663 {yyerror ("';' expected"); RECOVER;}
1668 { $$ = build_return ($1.location, NULL_TREE); }
1669 | RETURN_TK expression SC_TK
1670 { $$ = build_return ($1.location, $2); }
1672 {yyerror ("Missing term"); RECOVER;}
1673 | RETURN_TK expression error
1674 {yyerror ("';' expected"); RECOVER;}
1678 THROW_TK expression SC_TK
1680 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1681 EXPR_WFL_LINECOL ($$) = $1.location;
1684 {yyerror ("Missing term"); RECOVER;}
1685 | THROW_TK expression error
1686 {yyerror ("';' expected"); RECOVER;}
1689 synchronized_statement:
1690 synchronized OP_TK expression CP_TK block
1692 $$ = build (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1693 EXPR_WFL_LINECOL ($$) =
1694 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1696 | synchronized OP_TK expression CP_TK error
1697 {yyerror ("'{' expected"); RECOVER;}
1698 | synchronized error
1699 {yyerror ("'(' expected"); RECOVER;}
1700 | synchronized OP_TK error CP_TK
1701 {yyerror ("Missing term"); RECOVER;}
1702 | synchronized OP_TK error
1703 {yyerror ("Missing term"); RECOVER;}
1710 "Illegal modifier `%s'. Only `synchronized' was expected here",
1711 $1, ACC_SYNCHRONIZED);
1712 if ($1 != ACC_SYNCHRONIZED)
1713 MODIFIER_WFL (SYNCHRONIZED_TK) =
1714 build_wfl_node (NULL_TREE);
1719 TRY_TK block catches
1720 { $$ = build_try_statement ($1.location, $2, $3); }
1721 | TRY_TK block finally
1722 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1723 | TRY_TK block catches finally
1724 { $$ = build_try_finally_statement
1725 ($1.location, build_try_statement ($1.location,
1729 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1734 | catches catch_clause
1736 TREE_CHAIN ($2) = $1;
1742 catch_clause_parameter block
1744 java_method_add_stmt (current_function_decl, $2);
1749 catch_clause_parameter:
1750 CATCH_TK OP_TK formal_parameter CP_TK
1752 /* We add a block to define a scope for
1753 formal_parameter (CCBP). The formal parameter is
1754 declared initialized by the appropriate function
1756 tree ccpb = enter_block ();
1757 tree init = build_assignment (ASSIGN_TK, $2.location,
1759 soft_exceptioninfo_call_node);
1760 declare_local_variables (0, TREE_VALUE ($3),
1761 build_tree_list (TREE_PURPOSE ($3),
1763 $$ = build1 (CATCH_EXPR, NULL_TREE, ccpb);
1764 EXPR_WFL_LINECOL ($$) = $1.location;
1767 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1768 | CATCH_TK OP_TK error
1770 yyerror ("Missing term or ')' expected");
1771 RECOVER; $$ = NULL_TREE;
1773 | CATCH_TK OP_TK error CP_TK /* That's for () */
1774 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1781 {yyerror ("'{' expected"); RECOVER; }
1784 /* 19.12 Production from 15: Expressions */
1786 primary_no_new_array
1787 | array_creation_expression
1790 primary_no_new_array:
1793 { $$ = build_this ($1.location); }
1794 | OP_TK expression CP_TK
1796 | class_instance_creation_expression
1800 /* type DOT_TK CLASS_TK doens't work. So we split the rule
1801 'type' into its components. Missing is something for array,
1802 which will complete the reference_type part. FIXME */
1803 | name DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
1804 { $$ = parse_jdk1_1_error ("named class literals"); }
1805 | primitive_type DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
1806 { $$ = build_class_ref ($1); }
1807 | VOID_TK DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
1808 { $$ = build_class_ref (void_type_node); }
1809 /* Added, JDK1.1 inner classes. Documentation is wrong
1810 refering to a 'ClassName' (class_name) rule that doesn't
1811 exist. Used name instead. */
1812 | name DOT_TK THIS_TK
1813 { $$ = parse_jdk1_1_error ("class literals"); }
1814 | OP_TK expression error
1815 {yyerror ("')' expected"); RECOVER;}
1817 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1818 | primitive_type DOT_TK error
1819 {yyerror ("'class' expected" ); RECOVER;}
1820 | VOID_TK DOT_TK error
1821 {yyerror ("'class' expected" ); RECOVER;}
1824 class_instance_creation_expression:
1825 NEW_TK class_type OP_TK argument_list CP_TK
1826 { $$ = build_new_invocation ($2, $4); }
1827 | NEW_TK class_type OP_TK CP_TK
1828 { $$ = build_new_invocation ($2, NULL_TREE); }
1829 /* Added, JDK1.1 inner classes but modified to use
1830 'class_type' instead of 'TypeName' (type_name) mentionned
1831 in the documentation but doesn't exist. */
1832 | NEW_TK class_type OP_TK argument_list CP_TK class_body
1833 { $$ = parse_jdk1_1_error ("inner class instance creation"); }
1834 | NEW_TK class_type OP_TK CP_TK class_body
1835 { $$ = parse_jdk1_1_error ("inner class instance creation"); }
1836 /* Added, JDK1.1 inner classes, modified to use name or
1837 primary instead of primary solely which couldn't work in
1839 | something_dot_new identifier OP_TK CP_TK
1840 | something_dot_new identifier OP_TK CP_TK class_body
1841 | something_dot_new identifier OP_TK argument_list CP_TK
1842 | something_dot_new identifier OP_TK argument_list CP_TK class_body
1843 | NEW_TK error SC_TK
1844 {yyerror ("'(' expected"); DRECOVER(new_1);}
1845 | NEW_TK class_type error
1846 {yyerror ("'(' expected"); RECOVER;}
1847 | NEW_TK class_type OP_TK error
1848 {yyerror ("')' or term expected"); RECOVER;}
1849 | NEW_TK class_type OP_TK argument_list error
1850 {yyerror ("')' expected"); RECOVER;}
1851 | something_dot_new error
1852 {YYERROR_NOW; yyerror ("Identifier expected"); RECOVER;}
1853 | something_dot_new identifier error
1854 {yyerror ("'(' expected"); RECOVER;}
1857 something_dot_new: /* Added, not part of the specs. */
1859 | primary DOT_TK NEW_TK
1865 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1866 ctxp->formal_parameter_number = 1;
1868 | argument_list C_TK expression
1870 ctxp->formal_parameter_number += 1;
1871 $$ = tree_cons (NULL_TREE, $3, $1);
1873 | argument_list C_TK error
1874 {yyerror ("Missing term"); RECOVER;}
1877 array_creation_expression:
1878 NEW_TK primitive_type dim_exprs
1879 { $$ = build_newarray_node ($2, $3, 0); }
1880 | NEW_TK class_or_interface_type dim_exprs
1881 { $$ = build_newarray_node ($2, $3, 0); }
1882 | NEW_TK primitive_type dim_exprs dims
1883 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
1884 | NEW_TK class_or_interface_type dim_exprs dims
1885 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
1886 /* Added, JDK1.1 anonymous array. Initial documentation rule
1888 | NEW_TK class_or_interface_type dims array_initializer
1889 { $$ = parse_jdk1_1_error ("anonymous array"); }
1890 | NEW_TK primitive_type dims array_initializer
1891 { $$ = parse_jdk1_1_error ("anonymous array"); }
1892 | NEW_TK error CSB_TK
1893 {yyerror ("'[' expected"); DRECOVER ("]");}
1894 | NEW_TK error OSB_TK
1895 {yyerror ("']' expected"); RECOVER;}
1900 { $$ = build_tree_list (NULL_TREE, $1); }
1901 | dim_exprs dim_expr
1902 { $$ = tree_cons (NULL_TREE, $2, $$); }
1906 OSB_TK expression CSB_TK
1908 EXPR_WFL_LINECOL ($2) = $1.location;
1911 | OSB_TK expression error
1912 {yyerror ("']' expected"); RECOVER;}
1915 yyerror ("Missing term");
1916 yyerror ("']' expected");
1925 /* If not initialized, allocate memory for the osb
1927 if (!ctxp->osb_limit)
1929 allocate = ctxp->osb_limit = 32;
1930 ctxp->osb_depth = -1;
1932 /* If capacity overflown, reallocate a bigger chuck */
1933 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
1934 allocate = ctxp->osb_limit << 1;
1938 allocate *= sizeof (int);
1939 if (ctxp->osb_number)
1940 ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
1943 ctxp->osb_number = (int *)xmalloc (allocate);
1946 CURRENT_OSB (ctxp) = 1;
1948 | dims OSB_TK CSB_TK
1949 { CURRENT_OSB (ctxp)++; }
1951 { yyerror ("']' expected"); RECOVER;}
1955 primary DOT_TK identifier
1956 { $$ = make_qualified_primary ($1, $3, $2.location); }
1957 /* FIXME - REWRITE TO:
1958 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
1959 | SUPER_TK DOT_TK identifier
1962 build_wfl_node (super_identifier_node);
1963 EXPR_WFL_LINECOL (super_wfl) = $1.location;
1964 $$ = make_qualified_name (super_wfl, $3, $2.location);
1967 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
1972 { $$ = build_method_invocation ($1, NULL_TREE); }
1973 | name OP_TK argument_list CP_TK
1974 { $$ = build_method_invocation ($1, $3); }
1975 | primary DOT_TK identifier OP_TK CP_TK
1977 if (TREE_CODE ($1) == THIS_EXPR)
1978 $$ = build_this_super_qualified_invocation
1979 (1, $3, NULL_TREE, 0, $2.location);
1982 tree invok = build_method_invocation ($3, NULL_TREE);
1983 $$ = make_qualified_primary ($1, invok, $2.location);
1986 | primary DOT_TK identifier OP_TK argument_list CP_TK
1988 if (TREE_CODE ($1) == THIS_EXPR)
1989 $$ = build_this_super_qualified_invocation
1990 (1, $3, $5, 0, $2.location);
1993 tree invok = build_method_invocation ($3, $5);
1994 $$ = make_qualified_primary ($1, invok, $2.location);
1997 | SUPER_TK DOT_TK identifier OP_TK CP_TK
1999 $$ = build_this_super_qualified_invocation
2000 (0, $3, NULL_TREE, $1.location, $2.location);
2002 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2004 $$ = build_this_super_qualified_invocation
2005 (0, $3, $5, $1.location, $2.location);
2007 /* Screws up thing. I let it here until I'm convinced it can
2009 | primary DOT_TK error
2010 {yyerror ("'(' expected"); DRECOVER(bad);} */
2011 | SUPER_TK DOT_TK error CP_TK
2012 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2013 | SUPER_TK DOT_TK error DOT_TK
2014 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2018 name OSB_TK expression CSB_TK
2019 { $$ = build_array_ref ($2.location, $1, $3); }
2020 | primary_no_new_array OSB_TK expression CSB_TK
2021 { $$ = build_array_ref ($2.location, $1, $3); }
2024 yyerror ("Missing term and ']' expected");
2025 DRECOVER(array_access);
2027 | name OSB_TK expression error
2029 yyerror ("']' expected");
2030 DRECOVER(array_access);
2032 | primary_no_new_array OSB_TK error
2034 yyerror ("Missing term and ']' expected");
2035 DRECOVER(array_access);
2037 | primary_no_new_array OSB_TK expression error
2039 yyerror ("']' expected");
2040 DRECOVER(array_access);
2047 | post_increment_expression
2048 | post_decrement_expression
2051 post_increment_expression:
2052 postfix_expression INCR_TK
2053 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2056 post_decrement_expression:
2057 postfix_expression DECR_TK
2058 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2062 pre_increment_expression
2063 | pre_decrement_expression
2064 | PLUS_TK unary_expression
2065 {$$ = build_unaryop ($1.token, $1.location, $2); }
2066 | MINUS_TK unary_expression
2067 {$$ = build_unaryop ($1.token, $1.location, $2); }
2068 | unary_expression_not_plus_minus
2070 {yyerror ("Missing term"); RECOVER}
2072 {yyerror ("Missing term"); RECOVER}
2075 pre_increment_expression:
2076 INCR_TK unary_expression
2077 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2079 {yyerror ("Missing term"); RECOVER}
2082 pre_decrement_expression:
2083 DECR_TK unary_expression
2084 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2086 {yyerror ("Missing term"); RECOVER}
2089 unary_expression_not_plus_minus:
2091 | NOT_TK unary_expression
2092 {$$ = build_unaryop ($1.token, $1.location, $2); }
2093 | NEG_TK unary_expression
2094 {$$ = build_unaryop ($1.token, $1.location, $2); }
2097 {yyerror ("Missing term"); RECOVER}
2099 {yyerror ("Missing term"); RECOVER}
2102 cast_expression: /* Error handling here is potentially weak */
2103 OP_TK primitive_type dims CP_TK unary_expression
2106 while (CURRENT_OSB (ctxp)--)
2107 type = build_java_array_type (type, -1);
2109 $$ = build_cast ($1.location, type, $5);
2111 | OP_TK primitive_type CP_TK unary_expression
2112 { $$ = build_cast ($1.location, $2, $4); }
2113 | OP_TK expression CP_TK unary_expression_not_plus_minus
2114 { $$ = build_cast ($1.location, $2, $4); }
2115 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2118 while (CURRENT_OSB (ctxp)--)
2119 obstack_1grow (&temporary_obstack, '[');
2121 obstack_grow0 (&temporary_obstack,
2122 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2123 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2124 ptr = obstack_finish (&temporary_obstack);
2125 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2126 $$ = build_cast ($1.location, $2, $5);
2128 | OP_TK primitive_type OSB_TK error
2129 {yyerror ("']' expected, invalid type expression");}
2132 if (ctxp->prevent_ese != lineno)
2133 yyerror ("Invalid type expression"); RECOVER;
2136 | OP_TK primitive_type dims CP_TK error
2137 {yyerror ("Missing term"); RECOVER;}
2138 | OP_TK primitive_type CP_TK error
2139 {yyerror ("Missing term"); RECOVER;}
2140 | OP_TK name dims CP_TK error
2141 {yyerror ("Missing term"); RECOVER;}
2144 multiplicative_expression:
2146 | multiplicative_expression MULT_TK unary_expression
2148 $$ = build_binop (BINOP_LOOKUP ($2.token),
2149 $2.location, $1, $3);
2151 | multiplicative_expression DIV_TK unary_expression
2153 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2156 | multiplicative_expression REM_TK unary_expression
2158 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2161 | multiplicative_expression MULT_TK error
2162 {yyerror ("Missing term"); RECOVER;}
2163 | multiplicative_expression DIV_TK error
2164 {yyerror ("Missing term"); RECOVER;}
2165 | multiplicative_expression REM_TK error
2166 {yyerror ("Missing term"); RECOVER;}
2169 additive_expression:
2170 multiplicative_expression
2171 | additive_expression PLUS_TK multiplicative_expression
2173 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2176 | additive_expression MINUS_TK multiplicative_expression
2178 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2181 | additive_expression PLUS_TK error
2182 {yyerror ("Missing term"); RECOVER;}
2183 | additive_expression MINUS_TK error
2184 {yyerror ("Missing term"); RECOVER;}
2189 | shift_expression LS_TK additive_expression
2191 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2194 | shift_expression SRS_TK additive_expression
2196 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2199 | shift_expression ZRS_TK additive_expression
2201 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2204 | shift_expression LS_TK error
2205 {yyerror ("Missing term"); RECOVER;}
2206 | shift_expression SRS_TK error
2207 {yyerror ("Missing term"); RECOVER;}
2208 | shift_expression ZRS_TK error
2209 {yyerror ("Missing term"); RECOVER;}
2212 relational_expression:
2214 | relational_expression LT_TK shift_expression
2216 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2219 | relational_expression GT_TK shift_expression
2221 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2224 | relational_expression LTE_TK shift_expression
2226 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2229 | relational_expression GTE_TK shift_expression
2231 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2234 | relational_expression INSTANCEOF_TK reference_type
2235 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2236 | relational_expression LT_TK error
2237 {yyerror ("Missing term"); RECOVER;}
2238 | relational_expression GT_TK error
2239 {yyerror ("Missing term"); RECOVER;}
2240 | relational_expression LTE_TK error
2241 {yyerror ("Missing term"); RECOVER;}
2242 | relational_expression GTE_TK error
2243 {yyerror ("Missing term"); RECOVER;}
2244 | relational_expression INSTANCEOF_TK error
2245 {yyerror ("Invalid reference type"); RECOVER;}
2248 equality_expression:
2249 relational_expression
2250 | equality_expression EQ_TK relational_expression
2252 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2255 | equality_expression NEQ_TK relational_expression
2257 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2260 | equality_expression EQ_TK error
2261 {yyerror ("Missing term"); RECOVER;}
2262 | equality_expression NEQ_TK error
2263 {yyerror ("Missing term"); RECOVER;}
2268 | and_expression AND_TK equality_expression
2270 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2273 | and_expression AND_TK error
2274 {yyerror ("Missing term"); RECOVER;}
2277 exclusive_or_expression:
2279 | exclusive_or_expression XOR_TK and_expression
2281 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2284 | exclusive_or_expression XOR_TK error
2285 {yyerror ("Missing term"); RECOVER;}
2288 inclusive_or_expression:
2289 exclusive_or_expression
2290 | inclusive_or_expression OR_TK exclusive_or_expression
2292 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2295 | inclusive_or_expression OR_TK error
2296 {yyerror ("Missing term"); RECOVER;}
2299 conditional_and_expression:
2300 inclusive_or_expression
2301 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2303 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2306 | conditional_and_expression BOOL_AND_TK error
2307 {yyerror ("Missing term"); RECOVER;}
2310 conditional_or_expression:
2311 conditional_and_expression
2312 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2314 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2317 | conditional_or_expression BOOL_OR_TK error
2318 {yyerror ("Missing term"); RECOVER;}
2321 conditional_expression: /* Error handling here is weak */
2322 conditional_or_expression
2323 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2325 $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2326 EXPR_WFL_LINECOL ($$) = $2.location;
2328 | conditional_or_expression REL_QM_TK REL_CL_TK error
2331 yyerror ("Missing term");
2334 | conditional_or_expression REL_QM_TK error
2335 {yyerror ("Missing term"); DRECOVER (2);}
2336 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2337 {yyerror ("Missing term"); DRECOVER (3);}
2340 assignment_expression:
2341 conditional_expression
2346 left_hand_side assignment_operator assignment_expression
2347 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2348 | left_hand_side assignment_operator error
2350 if (ctxp->prevent_ese != lineno)
2351 yyerror ("Missing term");
2362 assignment_operator:
2368 assignment_expression
2371 constant_expression:
2378 /* Flag for the error report routine to issue the error the first time
2379 it's called (overriding the default behavior which is to drop the
2380 first invocation and honor the second one, taking advantage of a
2382 static int force_error = 0;
2384 /* Create a new parser context and make it the current one. */
2387 java_push_parser_context ()
2389 struct parser_ctxt *new =
2390 (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2392 bzero ((PTR) new, sizeof (struct parser_ctxt));
2397 ctxp->incomplete_class = ctxp->next->incomplete_class;
2398 ctxp->gclass_list = ctxp->next->gclass_list;
2403 java_parser_context_save_global ()
2407 java_push_parser_context ();
2408 ctxp->saved_data_ctx = 1;
2410 else if (ctxp->saved_data)
2412 struct parser_ctxt *new =
2413 (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2414 bzero ((PTR)new, sizeof (struct parser_ctxt));
2415 memcpy ((PTR)new, (PTR)ctxp, sizeof (struct parser_ctxt));
2418 ctxp->saved_data_ctx = 1;
2420 ctxp->finput = finput;
2421 ctxp->lineno = lineno;
2422 ctxp->current_class = current_class;
2423 ctxp->filename = input_filename;
2424 ctxp->current_function_decl = current_function_decl;
2425 ctxp->saved_data = 1;
2429 java_parser_context_restore_global ()
2431 finput = ctxp->finput;
2432 lineno = ctxp->lineno;
2433 current_class = ctxp->current_class;
2434 input_filename = ctxp->filename;
2435 ctxp->saved_data = 0;
2436 current_function_decl = ctxp->current_function_decl;
2437 if (ctxp->saved_data_ctx)
2438 java_pop_parser_context (0);
2442 java_pop_parser_context (generate)
2446 struct parser_ctxt *toFree, *next;
2455 next->incomplete_class = ctxp->incomplete_class;
2456 next->gclass_list = ctxp->gclass_list;
2457 lineno = ctxp->lineno;
2458 finput = ctxp->finput;
2459 current_class = ctxp->current_class;
2462 /* Set the single import class file flag to 0 for the current list
2463 of imported things */
2464 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2465 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 0;
2467 /* And restore those of the previous context */
2468 if ((ctxp = next)) /* Assignment is really meant here */
2469 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2470 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
2474 toFree->next = ctxp_for_generation;
2475 ctxp_for_generation = toFree;
2481 /* Dump the stacked up parser contexts. Intended to be called from a
2485 java_debug_context_do (tab)
2488 #define JAVA_TAB_CONTEXT(C) \
2489 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2491 struct parser_ctxt *copy = ctxp;
2494 JAVA_TAB_CONTEXT (tab);
2495 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2496 JAVA_TAB_CONTEXT (tab);
2497 fprintf (stderr, "filename: %s\n", copy->filename);
2498 JAVA_TAB_CONTEXT (tab);
2499 fprintf (stderr, "package: %s\n",
2501 IDENTIFIER_POINTER (copy->package) : "<none>"));
2502 JAVA_TAB_CONTEXT (tab);
2503 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2504 JAVA_TAB_CONTEXT (tab);
2505 fprintf (stderr, "saved data: %d\n", copy->saved_data);
2509 #undef JAVA_TAB_CONTEXT
2513 java_debug_context ()
2515 java_debug_context_do (0);
2519 /* Reporting an constructor invocation error. */
2521 parse_ctor_invocation_error ()
2523 if (DECL_CONSTRUCTOR_P (current_function_decl))
2524 yyerror ("Constructor invocation must be first thing in a constructor");
2526 yyerror ("Only constructors can invoke constructors");
2529 /* Reporting JDK1.1 features not implemented. */
2532 parse_jdk1_1_error (msg)
2535 sorry (": `%s' JDK1.1(TM) feature", msg);
2537 return empty_stmt_node;
2540 static int do_warning = 0;
2547 static int prev_lineno;
2548 static const char *prev_msg;
2551 char *remainder, *code_from_source;
2552 extern struct obstack temporary_obstack;
2554 if (!force_error && prev_lineno == lineno)
2557 /* Save current error location but report latter, when the context is
2559 if (ctxp->java_error_flag == 0)
2561 ctxp->java_error_flag = 1;
2563 /* Do something to use the previous line if we're reaching the
2564 end of the file... */
2565 #ifdef VERBOSE_SKELETON
2566 printf ("* Error detected (%s)\n", (msg ? msg : "(null)"));
2571 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2572 if (!force_error && msg == prev_msg && prev_lineno == elc.line)
2575 ctxp->java_error_flag = 0;
2577 java_warning_count++;
2581 if (elc.col == 0 && msg[1] == ';')
2583 elc.col = ctxp->p_line->char_col-1;
2584 elc.line = ctxp->p_line->lineno;
2587 save_lineno = lineno;
2588 prev_lineno = lineno = elc.line;
2591 code_from_source = java_get_line_col (ctxp->filename, elc.line, elc.col);
2592 obstack_grow0 (&temporary_obstack,
2593 code_from_source, strlen (code_from_source));
2594 remainder = obstack_finish (&temporary_obstack);
2596 warning ("%s.\n%s", msg, remainder);
2598 error ("%s.\n%s", msg, remainder);
2600 /* This allow us to cheaply avoid an extra 'Invalid expression
2601 statement' error report when errors have been already reported on
2602 the same line. This occurs when we report an error but don't have
2603 a synchronization point other than ';', which
2604 expression_statement is the only one to take care of. */
2605 ctxp->prevent_ese = lineno = save_lineno;
2609 issue_warning_error_from_context (cl, msg, ap)
2614 char *saved, *saved_input_filename;
2616 vsprintf (buffer, msg, ap);
2619 ctxp->elc.line = EXPR_WFL_LINENO (cl);
2620 ctxp->elc.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 :
2621 (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
2623 /* We have a CL, that's a good reason for using it if it contains data */
2624 saved = ctxp->filename;
2625 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
2626 ctxp->filename = EXPR_WFL_FILENAME (cl);
2627 saved_input_filename = input_filename;
2628 input_filename = ctxp->filename;
2630 java_error (buffer);
2631 ctxp->filename = saved;
2632 input_filename = saved_input_filename;
2636 /* Issue an error message at a current source line CL */
2639 parse_error_context VPARAMS ((tree cl, const char *msg, ...))
2641 #ifndef ANSI_PROTOTYPES
2648 #ifndef ANSI_PROTOTYPES
2649 cl = va_arg (ap, tree);
2650 msg = va_arg (ap, const char *);
2652 issue_warning_error_from_context (cl, msg, ap);
2656 /* Issue a warning at a current source line CL */
2659 parse_warning_context VPARAMS ((tree cl, const char *msg, ...))
2661 #ifndef ANSI_PROTOTYPES
2668 #ifndef ANSI_PROTOTYPES
2669 cl = va_arg (ap, tree);
2670 msg = va_arg (ap, const char *);
2673 force_error = do_warning = 1;
2674 issue_warning_error_from_context (cl, msg, ap);
2675 do_warning = force_error = 0;
2680 find_expr_with_wfl (node)
2688 switch (TREE_CODE (node))
2691 node = BLOCK_EXPR_BODY (node);
2695 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
2698 node = TREE_OPERAND (node, 1);
2702 node = TREE_OPERAND (node, 0);
2705 case LABELED_BLOCK_EXPR:
2706 node = TREE_OPERAND (node, 1);
2710 code = TREE_CODE_CLASS (TREE_CODE (node));
2711 if (((code == '1') || (code == '2') || (code == 'e'))
2712 && EXPR_WFL_LINECOL (node))
2720 /* Issue a missing return statement error. Uses METHOD to figure the
2721 last line of the method the error occurs in. */
2724 missing_return_error (method)
2727 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
2728 parse_error_context (wfl_operator, "Missing return statement");
2731 /* Issue an unreachable statement error. From NODE, find the next
2732 statement to report appropriately. */
2734 unreachable_stmt_error (node)
2737 /* Browse node to find the next expression node that has a WFL. Use
2738 the location to report the error */
2739 if (TREE_CODE (node) == COMPOUND_EXPR)
2740 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
2742 node = find_expr_with_wfl (node);
2746 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
2747 parse_error_context (wfl_operator, "Unreachable statement");
2750 fatal ("Can't get valid statement - unreachable_stmt_error");
2754 java_report_errors ()
2756 if (java_error_count)
2757 fprintf (stderr, "%d error%s",
2758 java_error_count, (java_error_count == 1 ? "" : "s"));
2759 if (java_warning_count)
2760 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
2761 java_warning_count, (java_warning_count == 1 ? "" : "s"));
2762 if (java_error_count || java_warning_count)
2763 putc ('\n', stderr);
2764 return java_error_count;
2768 java_accstring_lookup (flags)
2771 static char buffer [80];
2772 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
2774 /* Access modifier looked-up first for easier report on forbidden
2776 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
2777 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
2778 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
2779 if (flags & ACC_STATIC) COPY_RETURN ("static");
2780 if (flags & ACC_FINAL) COPY_RETURN ("final");
2781 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
2782 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
2783 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
2784 if (flags & ACC_NATIVE) COPY_RETURN ("native");
2785 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
2786 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
2793 /* Issuing error messages upon redefinition of classes, interfaces or
2797 classitf_redefinition_error (context, id, decl, cl)
2798 const char *context;
2801 parse_error_context (cl, "%s `%s' already defined in %s:%d",
2802 context, IDENTIFIER_POINTER (id),
2803 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
2804 /* Here we should point out where its redefined. It's a unicode. FIXME */
2808 variable_redefinition_error (context, name, type, line)
2809 tree context, name, type;
2812 const char *type_name;
2814 /* Figure a proper name for type. We might haven't resolved it */
2815 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
2816 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
2818 type_name = lang_printable_name (type, 0);
2820 parse_error_context (context,
2821 "Variable `%s' is already defined in this method and was declared `%s %s' at line %d",
2822 IDENTIFIER_POINTER (name),
2823 type_name, IDENTIFIER_POINTER (name), line);
2827 build_array_from_name (type, type_wfl, name, ret_name)
2828 tree type, type_wfl, name, *ret_name;
2833 /* Eventually get more dims */
2834 string = IDENTIFIER_POINTER (name);
2835 while (string [more_dims] == '[')
2838 /* If we have, then craft a new type for this variable */
2841 name = get_identifier (&string [more_dims]);
2843 /* If we have a pointer, use its type */
2844 if (TREE_CODE (type) == POINTER_TYPE)
2845 type = TREE_TYPE (type);
2847 /* Building the first dimension of a primitive type uses this
2849 if (JPRIMITIVE_TYPE_P (type))
2851 type = build_java_array_type (type, -1);
2852 CLASS_LOADED_P (type) = 1;
2855 /* Otherwise, if we have a WFL for this type, use it (the type
2856 is already an array on an unresolved type, and we just keep
2857 on adding dimensions) */
2861 /* Add all the dimensions */
2863 type = build_unresolved_array_type (type);
2865 /* The type may have been incomplete in the first place */
2867 type = obtain_incomplete_type (type);
2874 /* Build something that the type identifier resolver will identify as
2875 being an array to an unresolved type. TYPE_WFL is a WFL on a
2879 build_unresolved_array_type (type_or_wfl)
2884 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
2885 just create a array type */
2886 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
2888 tree type = build_java_array_type (type_or_wfl, -1);
2889 CLASS_LOADED_P (type) = CLASS_LOADED_P (type_or_wfl);
2893 obstack_1grow (&temporary_obstack, '[');
2894 obstack_grow0 (&temporary_obstack,
2895 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
2896 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
2897 ptr = obstack_finish (&temporary_obstack);
2898 return build_expr_wfl (get_identifier (ptr),
2899 EXPR_WFL_FILENAME (type_or_wfl),
2900 EXPR_WFL_LINENO (type_or_wfl),
2901 EXPR_WFL_COLNO (type_or_wfl));
2905 parser_add_interface (class_decl, interface_decl, wfl)
2906 tree class_decl, interface_decl, wfl;
2908 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
2909 parse_error_context (wfl, "Interface `%s' repeated",
2910 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
2913 /* Bulk of common class/interface checks. Return 1 if an error was
2914 encountered. TAG is 0 for a class, 1 for an interface. */
2917 check_class_interface_creation (is_interface, flags, raw_name, qualified_name, decl, cl)
2918 int is_interface, flags;
2919 tree raw_name, qualified_name, decl, cl;
2924 fprintf (stderr, " %s %s", (is_interface ? "interface" : "class"),
2925 IDENTIFIER_POINTER (qualified_name));
2927 /* Scope of an interface/class type name:
2928 - Can't be imported by a single type import
2929 - Can't already exists in the package */
2930 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
2931 && (node = find_name_in_single_imports (raw_name)))
2934 (cl, "%s name `%s' clashes with imported type `%s'",
2935 (is_interface ? "Interface" : "Class"),
2936 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
2939 if (decl && CLASS_COMPLETE_P (decl))
2941 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
2942 qualified_name, decl, cl);
2946 /* If public, file name should match class/interface name */
2947 if (flags & ACC_PUBLIC)
2951 /* Contains OS dependent assumption on path separator. FIXME */
2952 for (f = &input_filename [strlen (input_filename)];
2953 f != input_filename && f[0] != '/' && f[0] != DIR_SEPARATOR;
2956 if (f[0] == '/' || f[0] == DIR_SEPARATOR)
2958 if (strncmp (IDENTIFIER_POINTER (raw_name),
2959 f , IDENTIFIER_LENGTH (raw_name)) ||
2960 f [IDENTIFIER_LENGTH (raw_name)] != '.')
2962 (cl, "Public %s `%s' must be defined in a file called `%s.java'",
2963 (is_interface ? "interface" : "class"),
2964 IDENTIFIER_POINTER (qualified_name),
2965 IDENTIFIER_POINTER (raw_name));
2969 check_modifiers ("Illegal modifier `%s' for interface declaration",
2970 flags, INTERFACE_MODIFIERS);
2972 check_modifiers ("Illegal modifier `%s' for class declaration",
2973 flags, CLASS_MODIFIERS);
2977 /* If DECL is NULL, create and push a new DECL, record the current
2978 line CL and do other maintenance things. */
2981 maybe_create_class_interface_decl (decl, qualified_name, cl)
2982 tree decl, qualified_name, cl;
2985 decl = push_class (make_class (), qualified_name);
2987 /* Take care of the file and line business */
2988 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
2989 /* If we're emiting xrefs, store the line/col number information */
2991 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (cl);
2993 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
2994 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
2995 CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (TREE_TYPE (decl)) =
2996 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
2998 ctxp->current_parsed_class = decl;
3000 /* Link the declaration to the already seen ones */
3001 TREE_CHAIN (decl) = ctxp->class_list;
3002 ctxp->class_list = decl;
3004 /* Create a new nodes in the global lists */
3005 ctxp->gclass_list = tree_cons (NULL_TREE, decl, ctxp->gclass_list);
3006 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
3008 /* Install a new dependency list element */
3009 create_jdep_list (ctxp);
3011 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
3012 IDENTIFIER_POINTER (qualified_name)));
3017 add_superinterfaces (decl, interface_list)
3018 tree decl, interface_list;
3021 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3022 takes care of ensuring that:
3023 - This is an accessible interface type,
3024 - Circularity detection.
3025 parser_add_interface is then called. If present but not defined,
3026 the check operation is delayed until the super interface gets
3028 for (node = interface_list; node; node = TREE_CHAIN (node))
3030 tree current = TREE_PURPOSE (node);
3031 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
3032 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
3034 if (!parser_check_super_interface (idecl, decl, current))
3035 parser_add_interface (decl, idecl, current);
3038 register_incomplete_type (JDEP_INTERFACE,
3039 current, decl, NULL_TREE);
3043 /* Create an interface in pass1 and return its decl. Return the
3044 interface's decl in pass 2. */
3047 create_interface (flags, id, super)
3051 tree raw_name = EXPR_WFL_NODE (id);
3052 tree q_name = parser_qualified_classname (id);
3053 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
3055 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
3057 /* Basic checks: scope, redefinition, modifiers */
3058 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
3061 /* Interface modifiers check
3062 - public/abstract allowed (already done at that point)
3063 - abstract is obsolete (comes first, it's a warning, or should be)
3064 - Can't use twice the same (checked in the modifier rule) */
3065 if ((flags & ACC_ABSTRACT) && flag_redundant)
3066 parse_warning_context
3067 (MODIFIER_WFL (ABSTRACT_TK),
3068 "Redundant use of `abstract' modifier. Interface `%s' is implicitely abstract", IDENTIFIER_POINTER (raw_name));
3070 /* Create a new decl if DECL is NULL, otherwise fix it */
3071 decl = maybe_create_class_interface_decl (decl, q_name, id);
3073 /* Set super info and mark the class a complete */
3074 set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
3075 object_type_node, ctxp->interface_number);
3076 ctxp->interface_number = 0;
3077 CLASS_COMPLETE_P (decl) = 1;
3078 add_superinterfaces (decl, super);
3083 /* Create an class in pass1 and return its decl. Return class
3084 interface's decl in pass 2. */
3087 create_class (flags, id, super, interfaces)
3089 tree id, super, interfaces;
3091 tree raw_name = EXPR_WFL_NODE (id);
3092 tree class_id, decl;
3093 tree super_decl_type;
3095 class_id = parser_qualified_classname (id);
3096 decl = IDENTIFIER_CLASS_VALUE (class_id);
3097 ctxp->current_parsed_class_un = EXPR_WFL_NODE (id);
3098 EXPR_WFL_NODE (id) = class_id;
3100 /* Basic check: scope, redefinition, modifiers */
3101 if (check_class_interface_creation (0, flags, raw_name, class_id, decl, id))
3104 /* Class modifier check:
3105 - Allowed modifier (already done at that point)
3106 - abstract AND final forbidden
3107 - Public classes defined in the correct file */
3108 if ((flags & ACC_ABSTRACT) && (flags & ACC_FINAL))
3110 (id, "Class `%s' can't be declared both abstract and final",
3111 IDENTIFIER_POINTER (raw_name));
3113 /* Create a new decl if DECL is NULL, otherwise fix it */
3114 decl = maybe_create_class_interface_decl (decl, class_id, id);
3116 /* If SUPER exists, use it, otherwise use Object */
3119 /* Can't extend java.lang.Object */
3120 if (TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_id)) == object_type_node)
3122 parse_error_context (id, "Can't extend `java.lang.Object'");
3127 register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
3129 else if (TREE_TYPE (decl) != object_type_node)
3130 super_decl_type = object_type_node;
3131 /* We're defining java.lang.Object */
3133 super_decl_type = NULL_TREE;
3135 /* Set super info and mark the class a complete */
3136 set_super_info (flags, TREE_TYPE (decl), super_decl_type,
3137 ctxp->interface_number);
3138 ctxp->interface_number = 0;
3139 CLASS_COMPLETE_P (decl) = 1;
3140 add_superinterfaces (decl, interfaces);
3142 /* If doing xref, store the location at which the inherited class
3143 (if any) was seen. */
3144 if (flag_emit_xref && super)
3145 DECL_INHERITED_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (super);
3147 /* Eventually sets the @deprecated tag flag */
3148 CHECK_DEPRECATED (decl);
3153 /* Can't use lookup_field () since we don't want to load the class and
3154 can't set the CLASS_LOADED_P flag */
3157 find_field (class, name)
3162 for (decl = TYPE_FIELDS (class); decl; decl = TREE_CHAIN (decl))
3164 if (DECL_NAME (decl) == name)
3170 /* Wrap around lookup_field that doesn't potentially upset the value
3174 lookup_field_wrapper (class, name)
3179 java_parser_context_save_global ();
3180 decl = lookup_field (&type, name);
3181 java_parser_context_restore_global ();
3182 return decl == error_mark_node ? NULL : decl;
3185 /* Find duplicate field within the same class declarations and report
3186 the error. Returns 1 if a duplicated field was found, 0
3190 duplicate_declaration_error_p (new_field_name, new_type, cl)
3191 tree new_field_name, new_type, cl;
3193 /* This might be modified to work with method decl as well */
3194 tree decl = find_field (TREE_TYPE (ctxp->current_parsed_class),
3198 char *t1 = xstrdup (purify_type_name
3199 ((TREE_CODE (new_type) == POINTER_TYPE
3200 && TREE_TYPE (new_type) == NULL_TREE) ?
3201 IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
3202 lang_printable_name (new_type, 1)));
3203 /* The type may not have been completed by the time we report
3205 char *t2 = xstrdup (purify_type_name
3206 ((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
3207 && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
3208 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
3209 lang_printable_name (TREE_TYPE (decl), 1)));
3211 (cl , "Duplicate variable declaration: `%s %s' was `%s %s' (%s:%d)",
3212 t1, IDENTIFIER_POINTER (new_field_name),
3213 t2, IDENTIFIER_POINTER (DECL_NAME (decl)),
3214 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3222 /* Field registration routine. If TYPE doesn't exist, field
3223 declarations are linked to the undefined TYPE dependency list, to
3224 be later resolved in java_complete_class () */
3227 register_fields (flags, type, variable_list)
3229 tree type, variable_list;
3231 tree current, saved_type;
3232 tree class_type = TREE_TYPE (ctxp->current_parsed_class);
3233 int saved_lineno = lineno;
3235 tree wfl = NULL_TREE;
3237 /* If we're adding fields to interfaces, those fields are public,
3239 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
3241 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK),
3242 flags, ACC_PUBLIC, "interface field(s)");
3243 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (STATIC_TK),
3244 flags, ACC_STATIC, "interface field(s)");
3245 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (FINAL_TK),
3246 flags, ACC_FINAL, "interface field(s)");
3247 check_modifiers ("Illegal interface member modifier `%s'", flags,
3248 INTERFACE_FIELD_MODIFIERS);
3249 flags |= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
3252 /* Obtain a suitable type for resolution, if necessary */
3253 SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
3255 /* If TYPE is fully resolved and we don't have a reference, make one */
3256 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
3258 for (current = variable_list, saved_type = type; current;
3259 current = TREE_CHAIN (current), type = saved_type)
3263 tree cl = TREE_PURPOSE (current);
3264 tree init = TREE_VALUE (current);
3265 tree current_name = EXPR_WFL_NODE (cl);
3267 /* Process NAME, as it may specify extra dimension(s) for it */
3268 type = build_array_from_name (type, wfl, current_name, ¤t_name);
3270 /* Type adjustment. We may have just readjusted TYPE because
3271 the variable specified more dimensions. Make sure we have
3272 a reference if we can and don't have one already. Also
3273 change the name if we have an init. */
3274 if (type != saved_type)
3276 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
3278 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
3281 real_type = GET_REAL_TYPE (type);
3282 /* Check for redeclarations */
3283 if (duplicate_declaration_error_p (current_name, real_type, cl))
3286 /* Set lineno to the line the field was found and create a
3287 declaration for it. Eventually sets the @deprecated tag flag. */
3289 lineno = EXPR_WFL_LINECOL (cl);
3291 lineno = EXPR_WFL_LINENO (cl);
3292 field_decl = add_field (class_type, current_name, real_type, flags);
3293 CHECK_DEPRECATED (field_decl);
3295 /* Check if we must chain. */
3297 register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
3299 /* If we have an initialization value tied to the field */
3302 /* The field is declared static */
3303 if (flags & ACC_STATIC)
3305 /* We include the field and its initialization part into
3306 a list used to generate <clinit>. After <clinit> is
3307 walked, field initializations will be processed and
3308 fields initialized with known constants will be taken
3309 out of <clinit> and have their DECL_INITIAL set
3311 TREE_CHAIN (init) = ctxp->static_initialized;
3312 ctxp->static_initialized = init;
3313 if (TREE_OPERAND (init, 1)
3314 && TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
3315 TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
3317 /* A non-static field declared with an immediate initialization is
3318 to be initialized in <init>, if any. This field is remembered
3319 to be processed at the time of the generation of <init>. */
3322 TREE_CHAIN (init) = ctxp->non_static_initialized;
3323 ctxp->non_static_initialized = init;
3325 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
3326 DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
3329 lineno = saved_lineno;
3332 /* Generate the method $finit$ that initializes fields initialized
3333 upon declaration. */
3336 maybe_generate_finit ()
3338 tree mdecl, current;
3340 if (!ctxp->non_static_initialized || java_error_count)
3343 mdecl = create_artificial_method (TREE_TYPE (ctxp->current_parsed_class),
3344 ACC_PRIVATE, void_type_node,
3345 finit_identifier_node, end_params_node);
3346 start_artificial_method_body (mdecl);
3348 ctxp->non_static_initialized = nreverse (ctxp->non_static_initialized);
3349 for (current = ctxp->non_static_initialized; current;
3350 current = TREE_CHAIN (current))
3351 java_method_add_stmt (mdecl,
3352 build_debugable_stmt (EXPR_WFL_LINECOL (current),
3355 end_artificial_method_body (mdecl);
3356 CLASS_HAS_FINIT_P (TREE_TYPE (ctxp->current_parsed_class)) = 1;
3357 ctxp->non_static_initialized = NULL_TREE;
3360 /* Check whether it is necessary to generate a <clinit> for the class
3364 maybe_generate_clinit ()
3368 if (!ctxp->static_initialized || java_error_count)
3371 mdecl = create_artificial_method (TREE_TYPE (ctxp->current_parsed_class),
3372 ACC_STATIC, void_type_node,
3373 clinit_identifier_node, end_params_node);
3374 start_artificial_method_body (mdecl);
3376 /* Keep initialization in order to enforce 8.5 */
3377 ctxp->static_initialized = nreverse (ctxp->static_initialized);
3379 /* We process the list of assignment we produced as the result of
3380 the declaration of initialized static field and add them as
3381 statement to the <clinit> method. */
3382 for (c = ctxp->static_initialized; c; c = TREE_CHAIN (c))
3384 /* We build the assignment expression that will initialize the
3385 field to its value. There are strict rules on static
3386 initializers (8.5). FIXME */
3387 java_method_add_stmt (mdecl,
3388 build_debugable_stmt (EXPR_WFL_LINECOL (c), c));
3391 end_artificial_method_body (mdecl);
3392 ctxp->static_initialized = NULL_TREE;
3395 /* Shared accros method_declarator and method_header to remember the
3396 patch stage that was reached during the declaration of the method.
3397 A method DECL is built differently is there is no patch
3398 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
3399 pending on the currently defined method. */
3401 static int patch_stage;
3403 /* Check the method declaration and add the method to its current
3404 class. If the argument list is known to contain incomplete types,
3405 the method is partially added and the registration will be resume
3406 once the method arguments resolved. If TYPE is NULL, we're dealing
3407 with a constructor. */
3410 method_header (flags, type, mdecl, throws)
3412 tree type, mdecl, throws;
3414 tree meth = TREE_VALUE (mdecl);
3415 tree id = TREE_PURPOSE (mdecl);
3416 tree type_wfl = NULL_TREE;
3417 tree meth_name = NULL_TREE;
3418 tree current, orig_arg, this_class;
3420 int constructor_ok = 0, must_chain;
3422 check_modifiers_consistency (flags);
3424 if (ctxp->current_parsed_class)
3425 this_class = TREE_TYPE (ctxp->current_parsed_class);
3429 /* There are some forbidden modifiers for an abstract method and its
3430 class must be abstract as well. */
3431 if (type && (flags & ACC_ABSTRACT))
3433 ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
3434 ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
3435 ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
3436 ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
3437 ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED,id, "Synchronized");
3438 if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
3439 && !CLASS_INTERFACE (TYPE_NAME (this_class)))
3441 (id, "Class `%s' must be declared abstract to define abstract method `%s'",
3442 IDENTIFIER_POINTER (DECL_NAME (ctxp->current_parsed_class)),
3443 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
3445 /* Things to be checked when declaring a constructor */
3448 int ec = java_error_count;
3449 /* 8.6: Constructor declarations: we might be trying to define a
3450 method without specifying a return type. */
3451 if (EXPR_WFL_NODE (id) != ctxp->current_parsed_class_un)
3453 (id, "Invalid method declaration, return type required");
3454 /* 8.6.3: Constructor modifiers */
3457 JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
3458 JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
3459 JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
3460 JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
3461 JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
3463 /* If we found error here, we don't consider it's OK to tread
3464 the method definition as a constructor, for the rest of this
3466 if (ec == java_error_count)
3470 /* Method declared within the scope of an interface are implicitly
3471 abstract and public. Conflicts with other erroneously provided
3472 modifiers are checked right after. */
3474 if (CLASS_INTERFACE (TYPE_NAME (this_class)))
3476 /* If FLAGS isn't set because of a modifier, turn the
3477 corresponding modifier WFL to NULL so we issue a warning on
3478 the obsolete use of the modifier */
3479 if (!(flags & ACC_PUBLIC))
3480 MODIFIER_WFL (PUBLIC_TK) = NULL;
3481 if (!(flags & ACC_ABSTRACT))
3482 MODIFIER_WFL (ABSTRACT_TK) = NULL;
3483 flags |= ACC_PUBLIC;
3484 flags |= ACC_ABSTRACT;
3487 /* Modifiers context reset moved up, so abstract method declaration
3488 modifiers can be later checked. */
3490 /* Set constructor returned type to void and method name to <init>,
3491 unless we found an error identifier the constructor (in which
3492 case we retain the original name) */
3495 type = void_type_node;
3497 meth_name = init_identifier_node;
3500 meth_name = EXPR_WFL_NODE (id);
3502 /* Do the returned type resolution and registration if necessary */
3503 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
3506 type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
3507 EXPR_WFL_NODE (id) = meth_name;
3508 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
3512 patch_stage = JDEP_METHOD_RETURN;
3513 register_incomplete_type (patch_stage, type_wfl, id, type);
3514 TREE_TYPE (meth) = GET_REAL_TYPE (type);
3517 TREE_TYPE (meth) = type;
3519 saved_lineno = lineno;
3520 /* When defining an abstract or interface method, the curly
3521 bracket at level 1 doesn't exist because there is no function
3523 lineno = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 :
3524 EXPR_WFL_LINENO (id));
3526 /* Remember the original argument list */
3527 orig_arg = TYPE_ARG_TYPES (meth);
3529 if (patch_stage) /* includes ret type and/or all args */
3532 meth = add_method_1 (this_class, flags, meth_name, meth);
3533 /* Patch for the return type */
3534 if (patch_stage == JDEP_METHOD_RETURN)
3536 jdep = CLASSD_LAST (ctxp->classd_list);
3537 JDEP_GET_PATCH (jdep) = &TREE_TYPE (TREE_TYPE (meth));
3539 /* This is the stop JDEP. METH allows the function's signature
3541 register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
3544 meth = add_method (this_class, flags, meth_name,
3545 build_java_signature (meth));
3547 /* Fix the method argument list so we have the argument name
3549 fix_method_argument_names (orig_arg, meth);
3551 /* Register the parameter number and re-install the current line
3553 DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
3554 lineno = saved_lineno;
3556 /* Register exception specified by the `throws' keyword for
3557 resolution and set the method decl appropriate field to the list.
3558 Note: the grammar ensures that what we get here are class
3562 throws = nreverse (throws);
3563 for (current = throws; current; current = TREE_CHAIN (current))
3565 register_incomplete_type (JDEP_EXCEPTION, TREE_VALUE (current),
3566 NULL_TREE, NULL_TREE);
3567 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
3568 &TREE_VALUE (current);
3570 DECL_FUNCTION_THROWS (meth) = throws;
3573 /* We set the DECL_NAME to ID so we can track the location where
3574 the function was declared. This allow us to report
3575 redefinition error accurately. When method are verified,
3576 DECL_NAME is reinstalled properly (using the content of the
3577 WFL node ID) (see check_method_redefinition). We don't do that
3578 when Object is being defined. Constructor <init> names will be
3579 reinstalled the same way. */
3580 if (TREE_TYPE (ctxp->current_parsed_class) != object_type_node)
3581 DECL_NAME (meth) = id;
3583 /* Set the flag if we correctly processed a constructor */
3585 DECL_CONSTRUCTOR_P (meth) = 1;
3587 /* Eventually set the @deprecated tag flag */
3588 CHECK_DEPRECATED (meth);
3590 /* If doing xref, store column and line number information instead
3591 of the line number only. */
3593 DECL_SOURCE_LINE (meth) = EXPR_WFL_LINECOL (id);
3599 fix_method_argument_names (orig_arg, meth)
3600 tree orig_arg, meth;
3602 tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
3603 if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
3605 TREE_PURPOSE (arg) = this_identifier_node;
3606 arg = TREE_CHAIN (arg);
3608 while (orig_arg != end_params_node)
3610 TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
3611 orig_arg = TREE_CHAIN (orig_arg);
3612 arg = TREE_CHAIN (arg);
3616 /* Complete the method declaration with METHOD_BODY. */
3619 finish_method_declaration (method_body)
3624 if (!current_function_decl)
3627 flags = get_access_flags_from_decl (current_function_decl);
3629 /* 8.4.5 Method Body */
3630 if ((flags & ACC_ABSTRACT || flags & ACC_NATIVE) && method_body)
3632 tree wfl = DECL_NAME (current_function_decl);
3633 parse_error_context (wfl,
3634 "%s method `%s' can't have a body defined",
3635 (METHOD_NATIVE (current_function_decl) ?
3636 "Native" : "Abstract"),
3637 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
3638 method_body = NULL_TREE;
3640 else if (!(flags & ACC_ABSTRACT) && !(flags & ACC_NATIVE) && !method_body)
3642 tree wfl = DECL_NAME (current_function_decl);
3645 "Non native and non abstract method `%s' must have a body defined",
3646 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
3647 method_body = NULL_TREE;
3650 if (flag_emit_class_files && method_body
3651 && TREE_CODE (method_body) == NOP_EXPR
3652 && TREE_TYPE (current_function_decl)
3653 && TREE_TYPE (TREE_TYPE (current_function_decl)) == void_type_node)
3654 method_body = build1 (RETURN_EXPR, void_type_node, NULL);
3656 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
3657 maybe_absorb_scoping_blocks ();
3658 /* Exit function's body */
3660 /* Merge last line of the function with first line, directly in the
3661 function decl. It will be used to emit correct debug info. */
3662 if (!flag_emit_xref)
3663 DECL_SOURCE_LINE_MERGE (current_function_decl, ctxp->last_ccb_indent1);
3664 /* So we don't have an irrelevant function declaration context for
3665 the next static block we'll see. */
3666 current_function_decl = NULL_TREE;
3669 /* Build a an error message for constructor circularity errors. */
3672 constructor_circularity_msg (from, to)
3675 static char string [4096];
3676 char *t = xstrdup (lang_printable_name (from, 0));
3677 sprintf (string, "`%s' invokes `%s'", t, lang_printable_name (to, 0));
3682 /* Verify a circular call to METH. Return 1 if an error is found, 0
3686 verify_constructor_circularity (meth, current)
3689 static tree list = NULL_TREE;
3691 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
3693 if (TREE_VALUE (c) == meth)
3699 list = nreverse (list);
3700 for (liste = list; liste; liste = TREE_CHAIN (liste))
3703 (TREE_PURPOSE (TREE_PURPOSE (liste)), "%s",
3704 constructor_circularity_msg
3705 (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste))));
3709 t = xstrdup (lang_printable_name (meth, 0));
3710 parse_error_context (TREE_PURPOSE (c),
3711 "%s: recursive invocation of constructor `%s'",
3712 constructor_circularity_msg (current, meth), t);
3718 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
3720 list = tree_cons (c, current, list);
3721 if (verify_constructor_circularity (meth, TREE_VALUE (c)))
3723 list = TREE_CHAIN (list);
3728 /* Check modifiers that can be declared but exclusively */
3731 check_modifiers_consistency (flags)
3735 tree cl = NULL_TREE;
3737 THIS_MODIFIER_ONLY (flags, ACC_PUBLIC, 0, acc_count, cl);
3738 THIS_MODIFIER_ONLY (flags, ACC_PRIVATE, 1, acc_count, cl);
3739 THIS_MODIFIER_ONLY (flags, ACC_PROTECTED, 2, acc_count, cl);
3742 (cl, "Inconsistent member declaration. At most one of `public', `private', or `protected' may be specified");
3745 /* Check the methode header METH for abstract specifics features */
3748 check_abstract_method_header (meth)
3751 int flags = get_access_flags_from_decl (meth);
3752 /* DECL_NAME might still be a WFL node */
3753 tree name = GET_METHOD_NAME (meth);
3755 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (ABSTRACT_TK), flags,
3756 ACC_ABSTRACT, "abstract method",
3757 IDENTIFIER_POINTER (name));
3758 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (PUBLIC_TK), flags,
3759 ACC_PUBLIC, "abstract method",
3760 IDENTIFIER_POINTER (name));
3762 check_modifiers ("Illegal modifier `%s' for interface method",
3763 flags, INTERFACE_METHOD_MODIFIERS);
3766 /* Create a FUNCTION_TYPE node and start augmenting it with the
3767 declared function arguments. Arguments type that can't be resolved
3768 are left as they are, but the returned node is marked as containing
3769 incomplete types. */
3772 method_declarator (id, list)
3775 tree arg_types = NULL_TREE, current, node;
3776 tree meth = make_node (FUNCTION_TYPE);
3779 patch_stage = JDEP_NO_PATCH;
3781 for (current = list; current; current = TREE_CHAIN (current))
3784 tree wfl_name = TREE_PURPOSE (current);
3785 tree type = TREE_VALUE (current);
3786 tree name = EXPR_WFL_NODE (wfl_name);
3787 tree already, arg_node;
3788 tree type_wfl = NULL_TREE;
3791 /* Obtain a suitable type for resolution, if necessary */
3792 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
3794 /* Process NAME, as it may specify extra dimension(s) for it */
3795 type = build_array_from_name (type, type_wfl, name, &name);
3796 EXPR_WFL_NODE (wfl_name) = name;
3798 real_type = GET_REAL_TYPE (type);
3799 if (TREE_CODE (real_type) == RECORD_TYPE)
3801 real_type = promote_type (real_type);
3802 if (TREE_CODE (type) == TREE_LIST)
3803 TREE_PURPOSE (type) = real_type;
3806 /* Check redefinition */
3807 for (already = arg_types; already; already = TREE_CHAIN (already))
3808 if (TREE_PURPOSE (already) == name)
3811 (wfl_name, "Variable `%s' is used more than once in the argument list of method `%s'",
3812 IDENTIFIER_POINTER (name),
3813 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
3817 /* If we've an incomplete argument type, we know there is a location
3818 to patch when the type get resolved, later. */
3822 patch_stage = JDEP_METHOD;
3823 type = register_incomplete_type (patch_stage,
3824 type_wfl, wfl_name, type);
3825 jdep = CLASSD_LAST (ctxp->classd_list);
3826 JDEP_MISC (jdep) = id;
3829 /* The argument node: a name and a (possibly) incomplete type */
3830 arg_node = build_tree_list (name, real_type);
3832 JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
3833 TREE_CHAIN (arg_node) = arg_types;
3834 arg_types = arg_node;
3836 TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
3837 node = build_tree_list (id, meth);
3842 unresolved_type_p (wfl, returned)
3847 if (TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION)
3849 tree decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (wfl));
3851 *returned = (decl ? TREE_TYPE (decl) : NULL_TREE);
3859 /* From NAME, build a qualified identifier node using the
3860 qualification from the current package definition. */
3863 parser_qualified_classname (name)
3867 return merge_qualified_name (ctxp->package, EXPR_WFL_NODE (name));
3869 return EXPR_WFL_NODE (name);
3872 /* Called once the type a interface extends is resolved. Returns 0 if
3873 everything is OK. */
3876 parser_check_super_interface (super_decl, this_decl, this_wfl)
3877 tree super_decl, this_decl, this_wfl;
3879 tree super_type = TREE_TYPE (super_decl);
3881 /* Has to be an interface */
3882 if (!CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (super_decl))))
3885 (this_wfl, "Can't use %s `%s' to implement/extend %s `%s'",
3886 (TYPE_ARRAY_P (super_type) ? "array" : "class"),
3887 IDENTIFIER_POINTER (DECL_NAME (super_decl)),
3888 (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (this_decl))) ?
3889 "interface" : "class"),
3890 IDENTIFIER_POINTER (DECL_NAME (this_decl)));
3894 /* Check scope: same package OK, other package: OK if public */
3895 if (check_pkg_class_access (DECL_NAME (super_decl), lookup_cl (this_decl)))
3898 SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
3899 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
3900 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
3904 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
3905 0 if everthing is OK. */
3908 parser_check_super (super_decl, this_decl, wfl)
3909 tree super_decl, this_decl, wfl;
3911 tree super_type = TREE_TYPE (super_decl);
3913 /* SUPER should be a CLASS (neither an array nor an interface) */
3914 if (TYPE_ARRAY_P (super_type) || CLASS_INTERFACE (TYPE_NAME (super_type)))
3917 (wfl, "Class `%s' can't subclass %s `%s'",
3918 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
3919 (CLASS_INTERFACE (TYPE_NAME (super_type)) ? "interface" : "array"),
3920 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
3924 if (CLASS_FINAL (TYPE_NAME (super_type)))
3926 parse_error_context (wfl, "Can't subclass final classes: %s",
3927 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
3931 /* Check scope: same package OK, other package: OK if public */
3932 if (check_pkg_class_access (DECL_NAME (super_decl), wfl))
3935 SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
3936 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
3937 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
3941 /* Create a new dependency list and link it (in a LIFO manner) to the
3942 CTXP list of type dependency list. */
3945 create_jdep_list (ctxp)
3946 struct parser_ctxt *ctxp;
3948 jdeplist *new = (jdeplist *)xmalloc (sizeof (jdeplist));
3949 new->first = new->last = NULL;
3950 new->next = ctxp->classd_list;
3951 ctxp->classd_list = new;
3955 reverse_jdep_list (ctxp)
3956 struct parser_ctxt *ctxp;
3958 register jdeplist *prev = NULL, *current, *next;
3959 for (current = ctxp->classd_list; current; current = next)
3961 next = current->next;
3962 current->next = prev;
3968 /* Create a fake pointer based on the ID stored in
3969 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
3970 registered again. */
3973 obtain_incomplete_type (type_name)
3978 if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
3979 name = EXPR_WFL_NODE (type_name);
3980 else if (INCOMPLETE_TYPE_P (type_name))
3981 name = TYPE_NAME (type_name);
3983 fatal ("invalid type name - obtain_incomplete_type");
3985 for (ptr = ctxp->incomplete_class; ptr; ptr = TREE_CHAIN (ptr))
3986 if (TYPE_NAME (ptr) == name)
3991 push_obstacks (&permanent_obstack, &permanent_obstack);
3992 BUILD_PTR_FROM_NAME (ptr, name);
3995 TREE_CHAIN (ptr) = ctxp->incomplete_class;
3996 ctxp->incomplete_class = ptr;
4002 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
4003 non NULL instead of computing a new fake type based on WFL. The new
4004 dependency is inserted in the current type dependency list, in FIFO
4008 register_incomplete_type (kind, wfl, decl, ptr)
4010 tree wfl, decl, ptr;
4012 jdep *new = (jdep *)xmalloc (sizeof (jdep));
4014 if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
4015 ptr = obtain_incomplete_type (wfl);
4017 JDEP_KIND (new) = kind;
4018 JDEP_DECL (new) = decl;
4019 JDEP_SOLV (new) = ptr;
4020 JDEP_WFL (new) = wfl;
4021 JDEP_CHAIN (new) = NULL;
4022 JDEP_MISC (new) = NULL_TREE;
4023 JDEP_GET_PATCH (new) = (tree *)NULL;
4025 JDEP_INSERT (ctxp->classd_list, new);
4031 java_check_circular_reference ()
4034 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
4036 tree type = TREE_TYPE (current);
4037 if (CLASS_INTERFACE (current))
4039 /* Check all interfaces this class extends */
4040 tree basetype_vec = TYPE_BINFO_BASETYPES (type);
4045 n = TREE_VEC_LENGTH (basetype_vec);
4046 for (i = 0; i < n; i++)
4048 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
4049 if (vec_elt && BINFO_TYPE (vec_elt) != object_type_node
4050 && interface_of_p (type, BINFO_TYPE (vec_elt)))
4051 parse_error_context (lookup_cl (current),
4052 "Cyclic interface inheritance");
4056 if (inherits_from_p (CLASSTYPE_SUPER (type), type))
4057 parse_error_context (lookup_cl (current),
4058 "Cyclic class inheritance");
4062 /* Fix the constructors. This will be called right after circular
4063 references have been checked. It is necessary to fix constructors
4064 early even if no code generation will take place for that class:
4065 some generated constructor might be required by the class whose
4066 compilation triggered this one to be simply loaded. */
4069 java_fix_constructors ()
4073 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
4076 tree class_type = TREE_TYPE (current);
4079 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
4081 if (DECL_CONSTRUCTOR_P (decl))
4083 fix_constructors (decl);
4090 int flags = (get_access_flags_from_decl (current) & ACC_PUBLIC ?
4092 decl = create_artificial_method (class_type, flags, void_type_node,
4093 init_identifier_node,
4095 DECL_CONSTRUCTOR_P (decl) = 1;
4100 /* safe_layout_class just makes sure that we can load a class without
4101 disrupting the current_class, input_file, lineno, etc, information
4102 about the class processed currently. */
4105 safe_layout_class (class)
4108 tree save_current_class = current_class;
4109 char *save_input_filename = input_filename;
4110 int save_lineno = lineno;
4112 push_obstacks (&permanent_obstack, &permanent_obstack);
4114 layout_class (class);
4117 current_class = save_current_class;
4118 input_filename = save_input_filename;
4119 lineno = save_lineno;
4120 CLASS_LOADED_P (class) = 1;
4124 jdep_resolve_class (dep)
4129 if (JDEP_RESOLVED_P (dep))
4130 decl = JDEP_RESOLVED_DECL (dep);
4133 decl = resolve_class (JDEP_TO_RESOLVE (dep),
4134 JDEP_DECL (dep), JDEP_WFL (dep));
4135 JDEP_RESOLVED (dep, decl);
4139 complete_class_report_errors (dep);
4144 /* Complete unsatisfied class declaration and their dependencies */
4147 java_complete_class ()
4154 push_obstacks (&permanent_obstack, &permanent_obstack);
4156 /* Process imports and reverse the import on demand list */
4158 if (ctxp->import_demand_list)
4159 ctxp->import_demand_list = nreverse (ctxp->import_demand_list);
4161 /* Rever things so we have the right order */
4162 ctxp->class_list = nreverse (ctxp->class_list);
4163 ctxp->classd_list = reverse_jdep_list (ctxp);
4165 for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
4167 cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
4170 for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
4173 if (!(decl = jdep_resolve_class (dep)))
4176 /* Now it's time to patch */
4177 switch (JDEP_KIND (dep))
4180 /* Simply patch super */
4181 if (parser_check_super (decl, JDEP_DECL (dep), JDEP_WFL (dep)))
4183 BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO
4184 (TREE_TYPE (JDEP_DECL (dep)))), 0)) = TREE_TYPE (decl);
4189 /* We do part of the job done in add_field */
4190 tree field_decl = JDEP_DECL (dep);
4191 tree field_type = TREE_TYPE (decl);
4192 push_obstacks (&permanent_obstack, &permanent_obstack);
4193 if (TREE_CODE (field_type) == RECORD_TYPE)
4194 field_type = promote_type (field_type);
4196 TREE_TYPE (field_decl) = field_type;
4197 DECL_ALIGN (field_decl) = 0;
4198 layout_decl (field_decl, 0);
4199 SOURCE_FRONTEND_DEBUG
4200 (("Completed field/var decl `%s' with `%s'",
4201 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
4202 IDENTIFIER_POINTER (DECL_NAME (decl))));
4205 case JDEP_METHOD: /* We start patching a method */
4206 case JDEP_METHOD_RETURN:
4212 type = TREE_TYPE(decl);
4213 if (TREE_CODE (type) == RECORD_TYPE)
4214 type = promote_type (type);
4215 JDEP_APPLY_PATCH (dep, type);
4216 SOURCE_FRONTEND_DEBUG
4217 (((JDEP_KIND (dep) == JDEP_METHOD_RETURN ?
4218 "Completing fct `%s' with ret type `%s'":
4219 "Completing arg `%s' with type `%s'"),
4220 IDENTIFIER_POINTER (EXPR_WFL_NODE
4221 (JDEP_DECL_WFL (dep))),
4222 IDENTIFIER_POINTER (DECL_NAME (decl))));
4226 dep = JDEP_CHAIN (dep);
4227 if (JDEP_KIND (dep) == JDEP_METHOD_END)
4230 decl = jdep_resolve_class (dep);
4234 tree mdecl = JDEP_DECL (dep), signature;
4235 push_obstacks (&permanent_obstack, &permanent_obstack);
4236 /* Recompute and reset the signature */
4237 signature = build_java_signature (TREE_TYPE (mdecl));
4238 set_java_signature (TREE_TYPE (mdecl), signature);
4245 case JDEP_INTERFACE:
4246 if (parser_check_super_interface (decl, JDEP_DECL (dep),
4249 parser_add_interface (JDEP_DECL (dep), decl, JDEP_WFL (dep));
4254 type = TREE_TYPE(decl);
4255 if (TREE_CODE (type) == RECORD_TYPE)
4256 type = promote_type (type);
4257 JDEP_APPLY_PATCH (dep, type);
4261 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
4262 SOURCE_FRONTEND_DEBUG
4263 (("Completing a random type dependency on a '%s' node",
4264 tree_code_name [TREE_CODE (JDEP_DECL (dep))]));
4267 case JDEP_EXCEPTION:
4268 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
4269 SOURCE_FRONTEND_DEBUG
4270 (("Completing `%s' `throws' argument node",
4271 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
4275 fatal ("Can't handle patch code %d - java_complete_class",
4284 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
4288 resolve_class (class_type, decl, cl)
4289 tree class_type, decl, cl;
4291 const char *name = IDENTIFIER_POINTER (TYPE_NAME (class_type));
4292 const char *base = name;
4293 tree resolved_type = TREE_TYPE (class_type);
4294 tree resolved_type_decl;
4296 if (resolved_type != NULL_TREE)
4298 tree resolved_type_decl = TYPE_NAME (resolved_type);
4299 if (resolved_type_decl == NULL_TREE
4300 || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
4302 resolved_type_decl = build_decl (TYPE_DECL,
4303 TYPE_NAME (class_type),
4306 return resolved_type_decl;
4309 /* 1- Check to see if we have an array. If true, find what we really
4311 while (name[0] == '[')
4314 TYPE_NAME (class_type) = get_identifier (name);
4316 /* 2- Resolve the bare type */
4317 if (!(resolved_type_decl = do_resolve_class (class_type, decl, cl)))
4319 resolved_type = TREE_TYPE (resolved_type_decl);
4321 /* 3- If we have and array, reconstruct the array down to its nesting */
4324 while (base != name)
4326 if (TREE_CODE (resolved_type) == RECORD_TYPE)
4327 resolved_type = promote_type (resolved_type);
4328 resolved_type = build_java_array_type (resolved_type, -1);
4329 CLASS_LOADED_P (resolved_type) = 1;
4332 /* Build a fake decl for this, since this is what is expected to
4334 resolved_type_decl =
4335 build_decl (TYPE_DECL, TYPE_NAME (resolved_type), resolved_type);
4336 /* Figure how those two things are important for error report. FIXME */
4337 DECL_SOURCE_LINE (resolved_type_decl) = 0;
4338 DECL_SOURCE_FILE (resolved_type_decl) = input_filename;
4339 TYPE_NAME (class_type) = TYPE_NAME (resolved_type);
4341 TREE_TYPE (class_type) = resolved_type;
4342 return resolved_type_decl;
4345 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
4346 are used to report error messages. */
4349 do_resolve_class (class_type, decl, cl)
4354 tree new_class_decl;
4355 tree original_name = NULL_TREE;
4357 /* Do not try to replace TYPE_NAME (class_type) by a variable, since
4358 its is changed by find_in_imports{_on_demand} */
4360 /* 1- Check for the type in single imports */
4361 if (find_in_imports (class_type))
4364 /* 2- And check for the type in the current compilation unit. If it fails,
4365 try with a name qualified with the package name we've seen so far */
4366 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
4368 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
4369 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
4370 load_class (TYPE_NAME (class_type), 0);
4371 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4374 original_name = TYPE_NAME (class_type);
4375 if (!QUALIFIED_P (TYPE_NAME (class_type)))
4378 for (package = package_list; package; package = TREE_CHAIN (package))
4382 new_qualified = merge_qualified_name (TREE_PURPOSE (package),
4384 TYPE_NAME (class_type) = new_qualified;
4385 new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4386 if (!new_class_decl)
4387 load_class (TYPE_NAME (class_type), 0);
4388 new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4391 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
4392 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
4393 load_class (TYPE_NAME (class_type), 0);
4394 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4398 TYPE_NAME (class_type) = original_name;
4400 /* 3- Check an other compilation unit that bears the name of type */
4401 load_class (TYPE_NAME (class_type), 0);
4402 if (check_pkg_class_access (TYPE_NAME (class_type),
4403 (cl ? cl : lookup_cl (decl))))
4406 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
4407 return new_class_decl;
4409 /* 4- Check the import on demands. Don't allow bar.baz to be
4410 imported from foo.* */
4411 if (!QUALIFIED_P (TYPE_NAME (class_type)))
4412 if (find_in_imports_on_demand (class_type))
4415 /* 5- Last call for a resolution */
4416 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4419 /* Resolve NAME and lay it out (if not done and if not the current
4420 parsed class). Return a decl node. This function is meant to be
4421 called when type resolution is necessary during the walk pass. */
4424 resolve_and_layout (something, cl)
4430 /* Don't do that on the current class */
4431 if (something == current_class)
4432 return TYPE_NAME (current_class);
4434 /* Don't do anything for void and other primitive types */
4435 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
4438 /* Pointer types can be reall pointer types or fake pointers. When
4439 finding a real pointer, recheck for primitive types */
4440 if (TREE_CODE (something) == POINTER_TYPE)
4442 if (TREE_TYPE (something))
4444 something = TREE_TYPE (something);
4445 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
4449 something = TYPE_NAME (something);
4452 /* Don't do anything for arrays of primitive types */
4453 if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
4454 && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
4457 /* If something is not and IDENTIFIER_NODE, it can be a a TYPE_DECL
4459 if (TREE_CODE (something) != IDENTIFIER_NODE)
4460 something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
4461 DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
4463 if (!(decl = resolve_no_layout (something, cl)))
4466 /* Resolve and layout if necessary */
4467 layout_class_methods (TREE_TYPE (decl));
4468 /* Check methods, but only once */
4469 if (CLASS_FROM_SOURCE_P (TREE_TYPE (decl))
4470 && !CLASS_LOADED_P (TREE_TYPE (decl)))
4471 CHECK_METHODS (decl);
4472 if (TREE_TYPE (decl) != current_class && !CLASS_LOADED_P (TREE_TYPE (decl)))
4473 safe_layout_class (TREE_TYPE (decl));
4478 /* Resolve a class, returns its decl but doesn't perform any
4479 layout. The current parsing context is saved and restored */
4482 resolve_no_layout (name, cl)
4486 BUILD_PTR_FROM_NAME (ptr, name);
4487 java_parser_context_save_global ();
4488 decl = resolve_class (ptr, NULL_TREE, cl);
4489 java_parser_context_restore_global ();
4494 /* Called when reporting errors. Skip leader '[' in a complex array
4495 type description that failed to be resolved. */
4498 purify_type_name (name)
4501 while (*name && *name == '[')
4506 /* The type CURRENT refers to can't be found. We print error messages. */
4509 complete_class_report_errors (dep)
4514 if (!JDEP_WFL (dep))
4517 name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
4518 switch (JDEP_KIND (dep))
4522 (JDEP_WFL (dep), "Superclass `%s' of class `%s' not found",
4523 purify_type_name (name),
4524 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4528 (JDEP_WFL (dep), "Type `%s' not found in declaration of field `%s'",
4529 purify_type_name (name),
4530 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4532 case JDEP_METHOD: /* Covers arguments */
4534 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the argument `%s' of method `%s'",
4535 purify_type_name (name),
4536 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
4537 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
4539 case JDEP_METHOD_RETURN: /* Covers return type */
4541 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the return type of method `%s'",
4542 purify_type_name (name),
4543 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
4545 case JDEP_INTERFACE:
4547 (JDEP_WFL (dep), "Superinterface `%s' of %s `%s' not found",
4548 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
4549 (CLASS_OR_INTERFACE (JDEP_DECL (dep), "class", "interface")),
4550 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4554 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the local variable `%s'",
4555 purify_type_name (IDENTIFIER_POINTER
4556 (EXPR_WFL_NODE (JDEP_WFL (dep)))),
4557 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4559 case JDEP_EXCEPTION: /* As specified by `throws' */
4561 (JDEP_WFL (dep), "Class `%s' not found in `throws'",
4562 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
4565 /* Fix for -Wall. Just break doing nothing. The error will be
4571 /* Check uninitialized final. */
4578 /* Return a static string containing the DECL prototype string. If
4579 DECL is a constructor, use the class name instead of the form
4583 get_printable_method_name (decl)
4586 const char *to_return;
4587 tree name = NULL_TREE;
4589 if (DECL_CONSTRUCTOR_P (decl))
4591 name = DECL_NAME (decl);
4592 DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
4595 to_return = lang_printable_name (decl, 0);
4596 if (DECL_CONSTRUCTOR_P (decl))
4597 DECL_NAME (decl) = name;
4602 /* Reinstall the proper DECL_NAME on METHOD. Return 0 if the method
4603 nevertheless needs to be verfied, 1 otherwise. */
4606 reset_method_name (method)
4609 if (!IS_CLINIT (method) && DECL_NAME (method) != finit_identifier_node)
4611 /* NAME is just the plain name when Object is being defined */
4612 if (DECL_CONTEXT (method) != object_type_node)
4613 DECL_NAME (method) = (DECL_CONSTRUCTOR_P (method) ?
4614 init_identifier_node : GET_METHOD_NAME (method));
4621 /* Return the name of METHOD_DECL, when DECL_NAME is a WFL */
4624 java_get_real_method_name (method_decl)
4627 tree method_name = DECL_NAME (method_decl);
4628 if (DECL_CONSTRUCTOR_P (method_decl))
4629 return init_identifier_node;
4631 /* Explain here why METHOD_DECL doesn't have the DECL_CONSTRUCTUR_P
4632 and still can be a constructor. FIXME */
4634 /* Don't confuse method only bearing the name of their class as
4636 else if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (method_decl))
4638 && ctxp->current_parsed_class_un == EXPR_WFL_NODE (method_name)
4639 && get_access_flags_from_decl (method_decl) <= ACC_PROTECTED
4640 && TREE_TYPE (TREE_TYPE (method_decl)) == void_type_node)
4641 return init_identifier_node;
4643 return EXPR_WFL_NODE (method_name);
4646 /* Track method being redefined inside the same class. As a side
4647 effect, set DECL_NAME to an IDENTIFIER (prior entering this
4648 function it's a FWL, so we can track errors more accurately.) */
4651 check_method_redefinition (class, method)
4655 tree cl = DECL_NAME (method);
4656 tree sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
4657 /* decl name of artificial <clinit> and $finit$ doesn't need to be
4658 fixed and checked */
4660 /* Reset the method name before running the check. If it returns 1,
4661 the method doesn't need to be verified with respect to method
4662 redeclaration and we return 0 */
4663 if (reset_method_name (method))
4666 name = DECL_NAME (method);
4667 for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
4669 if (redef == method)
4671 if (DECL_NAME (redef) == name
4672 && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef)))
4675 (cl, "Duplicate %s declaration `%s'",
4676 (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
4677 get_printable_method_name (redef));
4685 check_abstract_method_definitions (do_interface, class_decl, type)
4687 tree class_decl, type;
4689 tree class = TREE_TYPE (class_decl);
4690 tree method, end_type;
4692 end_type = (do_interface ? object_type_node : type);
4693 for (method = TYPE_METHODS (type); method; method = TREE_CHAIN (method))
4695 tree other_super, other_method, method_sig, method_name;
4698 if (!METHOD_ABSTRACT (method) || METHOD_FINAL (method))
4701 /* Now verify that somewhere in between TYPE and CLASS,
4702 abstract method METHOD gets a non abstract definition
4703 that is inherited by CLASS. */
4705 method_sig = build_java_signature (TREE_TYPE (method));
4706 method_name = DECL_NAME (method);
4707 if (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION)
4708 method_name = EXPR_WFL_NODE (method_name);
4710 for (other_super = class; other_super != end_type;
4711 other_super = CLASSTYPE_SUPER (other_super))
4713 for (other_method = TYPE_METHODS (other_super); other_method;
4714 other_method = TREE_CHAIN (other_method))
4716 tree s = build_java_signature (TREE_TYPE (other_method));
4717 tree other_name = DECL_NAME (other_method);
4719 if (TREE_CODE (other_name) == EXPR_WITH_FILE_LOCATION)
4720 other_name = EXPR_WFL_NODE (other_name);
4721 if (!IS_CLINIT (other_method)
4722 && !DECL_CONSTRUCTOR_P (other_method)
4723 && method_name == other_name && method_sig == s)
4731 /* Report that abstract METHOD didn't find an implementation
4732 that CLASS can use. */
4735 char *t = xstrdup (lang_printable_name
4736 (TREE_TYPE (TREE_TYPE (method)), 0));
4737 tree ccn = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
4738 tree saved_wfl = NULL_TREE;
4740 if (TREE_CODE (DECL_NAME (method)) == EXPR_WITH_FILE_LOCATION)
4742 saved_wfl = DECL_NAME (method);
4743 DECL_NAME (method) = EXPR_WFL_NODE (DECL_NAME (method));
4747 (lookup_cl (class_decl),
4748 "Class `%s' doesn't define the abstract method `%s %s' from %s `%s'. This method must be defined or %s `%s' must be declared abstract",
4749 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
4750 t, lang_printable_name (method, 0),
4751 (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))) ?
4752 "interface" : "class"),
4753 IDENTIFIER_POINTER (ccn),
4754 (CLASS_INTERFACE (class_decl) ? "interface" : "class"),
4755 IDENTIFIER_POINTER (DECL_NAME (class_decl)));
4760 DECL_NAME (method) = saved_wfl;
4765 /* Check that CLASS_DECL somehow implements all inherited abstract
4769 java_check_abstract_method_definitions (class_decl)
4772 tree class = TREE_TYPE (class_decl);
4776 if (CLASS_ABSTRACT (class_decl))
4779 /* Check for inherited types */
4780 for (super = CLASSTYPE_SUPER (class); super != object_type_node;
4781 super = CLASSTYPE_SUPER (super))
4783 if (!CLASS_ABSTRACT (TYPE_NAME (super)))
4786 check_abstract_method_definitions (0, class_decl, super);
4789 /* Check for implemented interfaces. */
4790 vector = TYPE_BINFO_BASETYPES (class);
4791 for (i = 1; i < TREE_VEC_LENGTH (vector); i++)
4793 super = BINFO_TYPE (TREE_VEC_ELT (vector, i));
4794 check_abstract_method_definitions (1, class_decl, super);
4798 /* Check all the methods of CLASS_DECL. Methods are first completed
4799 then checked according to regular method existance rules. If no
4800 constructor for CLASS_DECL were encountered, then build its
4804 java_check_regular_methods (class_decl)
4807 int saw_constructor = 0;
4809 tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (class_decl));
4810 tree saved_found_wfl = NULL_TREE, found = NULL_TREE;
4813 /* It is not necessary to check methods defined in java.lang.Object */
4814 if (class == object_type_node)
4817 if (!TYPE_NVIRTUALS (class))
4818 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
4820 /* Should take interfaces into account. FIXME */
4821 for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
4824 tree method_wfl = DECL_NAME (method);
4827 /* If we previously found something and its name was saved,
4829 if (found && saved_found_wfl)
4831 DECL_NAME (found) = saved_found_wfl;
4832 saved_found_wfl = NULL_TREE;
4835 /* Check for redefinitions */
4836 if (check_method_redefinition (class, method))
4839 /* If we see one constructor a mark so we don't generate the
4840 default one. Also skip other verifications: constructors
4841 can't be inherited hence hiden or overriden */
4842 if (DECL_CONSTRUCTOR_P (method))
4844 saw_constructor = 1;
4848 /* We verify things thrown by the method. They must inherits from
4849 java.lang.Throwable */
4850 for (mthrows = DECL_FUNCTION_THROWS (method);
4851 mthrows; mthrows = TREE_CHAIN (mthrows))
4853 if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
4855 (TREE_PURPOSE (mthrows), "Class `%s' in `throws' clause must be a subclass of class `java.lang.Throwable'",
4857 (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
4860 sig = build_java_argument_signature (TREE_TYPE (method));
4861 found = lookup_argument_method2 (class, DECL_NAME (method), sig);
4863 /* Nothing overrides or it's a private method. */
4866 if (METHOD_PRIVATE (found))
4872 /* If found wasn't verified, it's DECL_NAME won't be set properly.
4873 We set it temporarily for the sake of the error report. */
4874 saved_found_wfl = DECL_NAME (found);
4875 reset_method_name (found);
4877 /* If `found' is declared in an interface, make sure the
4878 modifier matches. */
4879 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
4880 && clinit_identifier_node != DECL_NAME (found)
4881 && !METHOD_PUBLIC (method))
4883 tree found_decl = TYPE_NAME (DECL_CONTEXT (found));
4884 parse_error_context (method_wfl, "Class `%s' must override `%s' with a public method in order to implement interface `%s'",
4885 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
4886 lang_printable_name (method, 0),
4887 IDENTIFIER_POINTER (DECL_NAME (found_decl)));
4890 /* Can't override a method with the same name and different return
4892 if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
4895 (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
4898 "Method `%s' was defined with return type `%s' in class `%s'",
4899 lang_printable_name (found, 0), t,
4901 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4905 aflags = get_access_flags_from_decl (found);
4906 /* If the method has default, access in an other package, then
4907 issue a warning that the current method doesn't override the
4908 one that was found elsewhere. Do not issue this warning when
4909 the match was found in java.lang.Object. */
4910 if (DECL_CONTEXT (found) != object_type_node
4911 && ((aflags & ACC_VISIBILITY) == 0)
4912 && !class_in_current_package (DECL_CONTEXT (found))
4913 && DECL_NAME (found) != clinit_identifier_node
4914 && flag_not_overriding)
4916 parse_warning_context
4917 (method_wfl, "Method `%s' in class `%s' does not override the corresponding method in class `%s', which is private to a different package",
4918 lang_printable_name (found, 0),
4919 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
4920 IDENTIFIER_POINTER (DECL_NAME
4921 (TYPE_NAME (DECL_CONTEXT (found)))));
4925 /* Can't override final. Can't override static. */
4926 if (METHOD_FINAL (found) || METHOD_STATIC (found))
4928 /* Static *can* override static */
4929 if (METHOD_STATIC (found) && METHOD_STATIC (method))
4933 "%s methods can't be overriden. Method `%s' is %s in class `%s'",
4934 (METHOD_FINAL (found) ? "Final" : "Static"),
4935 lang_printable_name (found, 0),
4936 (METHOD_FINAL (found) ? "final" : "static"),
4938 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4942 /* Static method can't override instance method. */
4943 if (METHOD_STATIC (method))
4947 "Instance methods can't be overriden by a static method. Method `%s' is an instance method in class `%s'",
4948 lang_printable_name (found, 0),
4950 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4954 /* - Overriding/hiding public must be public
4955 - Overriding/hiding protected must be protected or public
4956 - If the overriden or hidden method has default (package)
4957 access, then the overriding or hiding method must not be
4958 private; otherwise, a compile-time error occurs. If
4959 `found' belongs to an interface, things have been already
4961 if (!CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
4962 && ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method))
4963 || (METHOD_PROTECTED (found)
4964 && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
4965 || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
4966 && METHOD_PRIVATE (method))))
4970 "Methods can't be overridden to be more private. Method `%s' is not %s in class `%s'", lang_printable_name (method, 0),
4971 (METHOD_PUBLIC (method) ? "public" :
4972 (METHOD_PRIVATE (method) ? "private" : "protected")),
4973 IDENTIFIER_POINTER (DECL_NAME
4974 (TYPE_NAME (DECL_CONTEXT (found)))));
4978 /* Overriding methods must have compatible `throws' clauses on checked
4979 exceptions, if any */
4980 check_throws_clauses (method, method_wfl, found);
4982 /* Inheriting multiple methods with the same signature. FIXME */
4985 /* Don't forget eventual pending found and saved_found_wfl. Take
4986 into account that we might have exited because we saw an
4987 artificial method as the last entry. */
4989 if (found && !DECL_ARTIFICIAL (found) && saved_found_wfl)
4990 DECL_NAME (found) = saved_found_wfl;
4992 if (!TYPE_NVIRTUALS (class))
4993 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
4995 /* Search for inherited abstract method not yet implemented in this
4997 java_check_abstract_method_definitions (class_decl);
4999 if (!saw_constructor)
5000 fatal ("No constructor found");
5003 /* Return a non zero value if the `throws' clause of METHOD (if any)
5004 is incompatible with the `throws' clause of FOUND (if any). */
5007 check_throws_clauses (method, method_wfl, found)
5008 tree method, method_wfl, found;
5010 tree mthrows, fthrows;
5012 /* Can't check these things with class loaded from bytecode. FIXME */
5013 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (found)))
5016 for (mthrows = DECL_FUNCTION_THROWS (method);
5017 mthrows; mthrows = TREE_CHAIN (mthrows))
5019 /* We don't verify unchecked expressions */
5020 if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
5022 /* Checked expression must be compatible */
5023 for (fthrows = DECL_FUNCTION_THROWS (found);
5024 fthrows; fthrows = TREE_CHAIN (fthrows))
5025 if (inherits_from_p (TREE_VALUE (mthrows), TREE_VALUE (fthrows)))
5030 (method_wfl, "Invalid checked exception class `%s' in `throws' clause. The exception must be a subclass of an exception thrown by `%s' from class `%s'",
5031 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))),
5032 lang_printable_name (found, 0),
5034 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
5039 /* Check abstract method of interface INTERFACE */
5042 java_check_abstract_methods (interface_decl)
5043 tree interface_decl;
5046 tree method, basetype_vec, found;
5047 tree interface = TREE_TYPE (interface_decl);
5049 for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
5051 tree method_wfl = DECL_NAME (method);
5053 /* 2- Check for double definition inside the defining interface */
5054 if (check_method_redefinition (interface, method))
5057 /* 3- Overriding is OK as far as we preserve the return type and
5058 the thrown exceptions (FIXME) */
5059 found = lookup_java_interface_method2 (interface, method);
5063 tree saved_found_wfl = DECL_NAME (found);
5064 reset_method_name (found);
5065 t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
5068 "Method `%s' was defined with return type `%s' in class `%s'",
5069 lang_printable_name (found, 0), t,
5071 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
5073 DECL_NAME (found) = saved_found_wfl;
5078 /* 4- Inherited methods can't differ by their returned types */
5079 if (!(basetype_vec = TYPE_BINFO_BASETYPES (interface)))
5081 n = TREE_VEC_LENGTH (basetype_vec);
5082 for (i = 0; i < n; i++)
5084 tree sub_interface_method, sub_interface;
5085 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
5088 sub_interface = BINFO_TYPE (vec_elt);
5089 for (sub_interface_method = TYPE_METHODS (sub_interface);
5090 sub_interface_method;
5091 sub_interface_method = TREE_CHAIN (sub_interface_method))
5093 found = lookup_java_interface_method2 (interface,
5094 sub_interface_method);
5095 if (found && (found != sub_interface_method))
5097 tree saved_found_wfl = DECL_NAME (found);
5098 reset_method_name (found);
5100 (lookup_cl (sub_interface_method),
5101 "Interface `%s' inherits method `%s' from interface `%s'. This method is redefined with a different return type in interface `%s'",
5102 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
5103 lang_printable_name (found, 0),
5105 (DECL_NAME (TYPE_NAME
5106 (DECL_CONTEXT (sub_interface_method)))),
5108 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
5109 DECL_NAME (found) = saved_found_wfl;
5115 /* Lookup methods in interfaces using their name and partial
5116 signature. Return a matching method only if their types differ. */
5119 lookup_java_interface_method2 (class, method_decl)
5120 tree class, method_decl;
5123 tree basetype_vec = TYPE_BINFO_BASETYPES (class), to_return;
5128 n = TREE_VEC_LENGTH (basetype_vec);
5129 for (i = 0; i < n; i++)
5131 tree vec_elt = TREE_VEC_ELT (basetype_vec, i), to_return;
5132 if ((BINFO_TYPE (vec_elt) != object_type_node)
5134 lookup_java_method2 (BINFO_TYPE (vec_elt), method_decl, 1)))
5137 for (i = 0; i < n; i++)
5139 to_return = lookup_java_interface_method2
5140 (BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i)), method_decl);
5148 /* Lookup method using their name and partial signature. Return a
5149 matching method only if their types differ. */
5152 lookup_java_method2 (clas, method_decl, do_interface)
5153 tree clas, method_decl;
5156 tree method, method_signature, method_name, method_type, name;
5158 method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
5159 name = DECL_NAME (method_decl);
5160 method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
5161 EXPR_WFL_NODE (name) : name);
5162 method_type = TREE_TYPE (TREE_TYPE (method_decl));
5164 while (clas != NULL_TREE)
5166 for (method = TYPE_METHODS (clas);
5167 method != NULL_TREE; method = TREE_CHAIN (method))
5169 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
5170 tree name = DECL_NAME (method);
5171 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
5172 EXPR_WFL_NODE (name) : name) == method_name
5173 && method_sig == method_signature
5174 && TREE_TYPE (TREE_TYPE (method)) != method_type)
5177 clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
5182 /* Return the line that matches DECL line number, and try its best to
5183 position the column number. Used during error reports. */
5189 static tree cl = NULL_TREE;
5195 if (cl == NULL_TREE)
5196 cl = build_expr_wfl (NULL_TREE, NULL, 0, 0);
5198 EXPR_WFL_FILENAME_NODE (cl) = get_identifier (DECL_SOURCE_FILE (decl));
5199 EXPR_WFL_SET_LINECOL (cl, DECL_SOURCE_LINE_FIRST (decl), -1);
5201 line = java_get_line_col (IDENTIFIER_POINTER (EXPR_WFL_FILENAME_NODE (cl)),
5202 EXPR_WFL_LINENO (cl), EXPR_WFL_COLNO (cl));
5204 found = strstr ((const char *)line,
5205 (const char *)IDENTIFIER_POINTER (DECL_NAME (decl)));
5207 EXPR_WFL_SET_LINECOL (cl, EXPR_WFL_LINENO (cl), found - line);
5212 /* Look for a simple name in the single-type import list */
5215 find_name_in_single_imports (name)
5220 for (node = ctxp->import_list; node; node = TREE_CHAIN (node))
5221 if (TREE_VALUE (node) == name)
5222 return (EXPR_WFL_NODE (TREE_PURPOSE (node)));
5227 /* Process all single-type import. */
5235 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
5237 tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import));
5239 /* Don't load twice something already defined. */
5240 if (IDENTIFIER_CLASS_VALUE (to_be_found))
5242 QUALIFIED_P (to_be_found) = 1;
5243 load_class (to_be_found, 0);
5245 check_pkg_class_access (to_be_found, TREE_PURPOSE (import));
5246 if (!IDENTIFIER_CLASS_VALUE (to_be_found))
5248 parse_error_context (TREE_PURPOSE (import),
5249 "Class or interface `%s' not found in import",
5250 IDENTIFIER_POINTER (to_be_found));
5259 /* Possibly find a class imported by a single-type import statement. Return
5260 1 if an error occured, 0 otherwise. */
5263 find_in_imports (class_type)
5268 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
5269 if (TREE_VALUE (import) == TYPE_NAME (class_type))
5271 TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
5272 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
5278 note_possible_classname (name, len)
5283 if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
5285 else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
5289 node = ident_subst (name, len, "", '/', '.', "");
5290 IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
5291 QUALIFIED_P (node) = strchr (name, '/') ? 1 : 0;
5295 /* Read a import directory, gathering potential match for further type
5296 references. Indifferently reads a filesystem or a ZIP archive
5300 read_import_dir (wfl)
5303 tree package_id = EXPR_WFL_NODE (wfl);
5304 const char *package_name = IDENTIFIER_POINTER (package_id);
5305 int package_length = IDENTIFIER_LENGTH (package_id);
5307 JCF *saved_jcf = current_jcf;
5312 struct buffer filename[1];
5315 if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
5317 IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
5319 BUFFER_INIT (filename);
5320 buffer_grow (filename, package_length + 100);
5322 for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
5324 const char *entry_name = jcf_path_name (entry);
5325 int entry_length = strlen (entry_name);
5326 if (jcf_path_is_zipfile (entry))
5329 buffer_grow (filename, entry_length);
5330 memcpy (filename->data, entry_name, entry_length - 1);
5331 filename->data[entry_length-1] = '\0';
5332 zipf = opendir_in_zip (filename->data, jcf_path_is_system (entry));
5334 error ("malformed .zip archive in CLASSPATH: %s", entry_name);
5337 ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
5338 BUFFER_RESET (filename);
5339 for (k = 0; k < package_length; k++)
5341 char ch = package_name[k];
5342 *filename->ptr++ = ch == '.' ? '/' : ch;
5344 *filename->ptr++ = '/';
5346 for (k = 0; k < zipf->count; k++, zipd = ZIPDIR_NEXT (zipd))
5348 const char *current_entry = ZIPDIR_FILENAME (zipd);
5349 int current_entry_len = zipd->filename_length;
5351 if (current_entry_len >= BUFFER_LENGTH (filename)
5352 && strncmp (filename->data, current_entry,
5353 BUFFER_LENGTH (filename)) != 0)
5355 found |= note_possible_classname (current_entry,
5362 BUFFER_RESET (filename);
5363 buffer_grow (filename, entry_length + package_length + 4);
5364 strcpy (filename->data, entry_name);
5365 filename->ptr = filename->data + entry_length;
5366 for (k = 0; k < package_length; k++)
5368 char ch = package_name[k];
5369 *filename->ptr++ = ch == '.' ? '/' : ch;
5371 *filename->ptr = '\0';
5373 dirp = opendir (filename->data);
5376 *filename->ptr++ = '/';
5381 struct dirent *direntp = readdir (dirp);
5384 d_name = direntp->d_name;
5385 len = strlen (direntp->d_name);
5386 buffer_grow (filename, len+1);
5387 strcpy (filename->ptr, d_name);
5388 found |= note_possible_classname (filename->data + entry_length,
5389 package_length+len+1);
5396 free (filename->data);
5398 /* Here we should have a unified way of retrieving an entry, to be
5402 static int first = 1;
5405 error ("Can't find default package `%s'. Check the CLASSPATH environment variable and the access to the archives.", package_name);
5410 parse_error_context (wfl, "Package `%s' not found in import",
5412 current_jcf = saved_jcf;
5415 current_jcf = saved_jcf;
5418 /* Possibly find a type in the import on demands specified
5419 types. Returns 1 if an error occured, 0 otherwise. Run throught the
5420 entire list, to detected potential double definitions. */
5423 find_in_imports_on_demand (class_type)
5426 tree node, import, node_to_use = NULL_TREE;
5428 tree cl = NULL_TREE;
5430 for (import = ctxp->import_demand_list; import; import = TREE_CHAIN (import))
5432 const char *id_name;
5433 obstack_grow (&temporary_obstack,
5434 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
5435 IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
5436 obstack_1grow (&temporary_obstack, '.');
5437 obstack_grow0 (&temporary_obstack,
5438 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
5439 IDENTIFIER_LENGTH (TYPE_NAME (class_type)));
5440 id_name = obstack_finish (&temporary_obstack);
5442 node = maybe_get_identifier (id_name);
5443 if (node && IS_A_CLASSFILE_NAME (node))
5447 cl = TREE_PURPOSE (import);
5455 (import, "Type `%s' also potentially defined in package `%s'",
5456 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
5457 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))));
5464 /* Setup lineno so that it refers to the line of the import (in
5465 case we parse a class file and encounter errors */
5467 int saved_lineno = lineno;
5468 lineno = EXPR_WFL_LINENO (cl);
5469 TYPE_NAME (class_type) = node_to_use;
5470 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
5471 decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5472 /* If there is no DECL set for the class or if the class isn't
5473 loaded and not seen in source yet, the load */
5474 if (!decl || (!CLASS_LOADED_P (TREE_TYPE (decl))
5475 && !CLASS_FROM_SOURCE_P (TREE_TYPE (decl))))
5476 load_class (node_to_use, 0);
5477 lineno = saved_lineno;
5478 return check_pkg_class_access (TYPE_NAME (class_type), cl);
5481 return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
5485 resolve_package (pkg, next)
5489 tree type_name = NULL_TREE;
5490 const char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (pkg));
5492 /* The trick is to determine when the package name stops and were
5493 the name of something contained in the package starts. Then we
5494 return a fully qualified name of what we want to get. */
5496 /* Do a quick search on well known package names */
5497 if (!strncmp (name, "java.lang.reflect", 17))
5500 TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg))));
5501 type_name = lookup_package_type (name, 17);
5503 else if (!strncmp (name, "java.lang", 9))
5505 *next = TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg)));
5506 type_name = lookup_package_type (name, 9);
5509 /* If we found something here, return */
5513 *next = EXPR_WFL_QUALIFICATION (pkg);
5515 /* Try the current package. */
5516 if (ctxp->package && !strncmp (name, IDENTIFIER_POINTER (ctxp->package),
5517 IDENTIFIER_LENGTH (ctxp->package)))
5520 lookup_package_type_and_set_next (name,
5521 IDENTIFIER_LENGTH (ctxp->package),
5527 /* Search in imported package */
5528 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
5530 tree current_pkg_name = EXPR_WFL_NODE (TREE_PURPOSE (current));
5531 int len = IDENTIFIER_LENGTH (current_pkg_name);
5532 if (!strncmp (name, IDENTIFIER_POINTER (current_pkg_name), len))
5536 breakdown_qualified (&left, &dummy, current_pkg_name);
5537 len = IDENTIFIER_LENGTH (left);
5538 type_name = lookup_package_type_and_set_next (name, len, next);
5548 lookup_package_type_and_set_next (name, len, next)
5554 tree type_name = lookup_package_type (name, len);
5559 ptr = IDENTIFIER_POINTER (type_name);
5560 while (ptr && (ptr = strchr (ptr, '.')))
5562 *next = TREE_CHAIN (*next);
5569 lookup_package_type (name, from)
5574 const char *sub = &name[from+1];
5575 while (*sub != '.' && *sub)
5577 strncpy (subname, name, sub-name);
5578 subname [sub-name] = '\0';
5579 return get_identifier (subname);
5582 /* Check that CLASS_NAME refers to a PUBLIC class. Return 0 if no
5583 access violations were found, 1 otherwise. */
5586 check_pkg_class_access (class_name, cl)
5592 if (!QUALIFIED_P (class_name) || !IDENTIFIER_CLASS_VALUE (class_name))
5595 if (!(type = TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_name))))
5598 if (!CLASS_PUBLIC (TYPE_NAME (type)))
5600 /* Access to a private class within the same package is
5603 breakdown_qualified (&l, &r, class_name);
5604 if (l == ctxp->package)
5608 (cl, "Can't access %s `%s'. Only public classes and interfaces in other packages can be accessed",
5609 (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
5610 IDENTIFIER_POINTER (class_name));
5616 /* Local variable declaration. */
5619 declare_local_variables (modifier, type, vlist)
5624 tree decl, current, saved_type;
5625 tree type_wfl = NULL_TREE;
5628 /* Push a new block if statements were seen between the last time we
5629 pushed a block and now. Keep a cound of block to close */
5630 if (BLOCK_EXPR_BODY (GET_CURRENT_BLOCK (current_function_decl)))
5632 tree body = GET_CURRENT_BLOCK (current_function_decl);
5633 tree b = enter_block ();
5634 BLOCK_EXPR_ORIGIN (b) = body;
5640 for (i = 0; i <= 10; i++) if (1 << i & modifier) break;
5641 if (modifier == ACC_FINAL)
5643 if (flag_static_local_jdk1_1)
5644 parse_warning_context (ctxp->modifier_ctx [i],
5645 "Unsupported JDK1.1 `final' local variable (treated as non final)");
5650 (ctxp->modifier_ctx [i],
5651 "Only `final' is allowed as a local variables modifier");
5656 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
5657 hold the TYPE value if a new incomplete has to be created (as
5658 opposed to being found already existing and reused). */
5659 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
5661 /* If TYPE is fully resolved and we don't have a reference, make one */
5662 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
5664 /* Go through all the declared variables */
5665 for (current = vlist, saved_type = type; current;
5666 current = TREE_CHAIN (current), type = saved_type)
5668 tree other, real_type;
5669 tree wfl = TREE_PURPOSE (current);
5670 tree name = EXPR_WFL_NODE (wfl);
5671 tree init = TREE_VALUE (current);
5673 /* Process NAME, as it may specify extra dimension(s) for it */
5674 type = build_array_from_name (type, type_wfl, name, &name);
5676 /* Variable redefinition check */
5677 if ((other = lookup_name_in_blocks (name)))
5679 variable_redefinition_error (wfl, name, TREE_TYPE (other),
5680 DECL_SOURCE_LINE (other));
5684 /* Type adjustment. We may have just readjusted TYPE because
5685 the variable specified more dimensions. Make sure we have
5686 a reference if we can and don't have one already. */
5687 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
5689 real_type = GET_REAL_TYPE (type);
5690 /* Never layout this decl. This will be done when its scope
5692 decl = build_decl (VAR_DECL, name, real_type);
5693 BLOCK_CHAIN_DECL (decl);
5695 /* If doing xreferencing, replace the line number with the WFL
5698 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (wfl);
5700 /* Don't try to use an INIT statement when an error was found */
5701 if (init && java_error_count)
5704 /* Add the initialization function to the current function's code */
5707 /* Name might have been readjusted */
5708 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = name;
5709 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
5710 java_method_add_stmt (current_function_decl,
5711 build_debugable_stmt (EXPR_WFL_LINECOL (init),
5715 /* Setup dependency the type of the decl */
5719 register_incomplete_type (JDEP_VARIABLE, type_wfl, decl, type);
5720 dep = CLASSD_LAST (ctxp->classd_list);
5721 JDEP_GET_PATCH (dep) = &TREE_TYPE (decl);
5724 SOURCE_FRONTEND_DEBUG (("Defined locals"));
5727 /* Called during parsing. Build decls from argument list. */
5730 source_start_java_method (fndecl)
5740 current_function_decl = fndecl;
5742 /* New scope for the function */
5744 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
5745 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
5747 tree type = TREE_VALUE (tem);
5748 tree name = TREE_PURPOSE (tem);
5750 /* If type is incomplete. Create an incomplete decl and ask for
5751 the decl to be patched later */
5752 if (INCOMPLETE_TYPE_P (type))
5755 tree real_type = GET_REAL_TYPE (type);
5756 parm_decl = build_decl (PARM_DECL, name, real_type);
5757 type = obtain_incomplete_type (type);
5758 register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
5759 jdep = CLASSD_LAST (ctxp->classd_list);
5760 JDEP_MISC (jdep) = name;
5761 JDEP_GET_PATCH (jdep) = &TREE_TYPE (parm_decl);
5764 parm_decl = build_decl (PARM_DECL, name, type);
5766 BLOCK_CHAIN_DECL (parm_decl);
5768 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
5769 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) =
5771 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
5774 /* Called during parsing. Creates an artificial method declaration. */
5777 create_artificial_method (class, flags, type, name, args)
5780 tree type, name, args;
5782 int saved_lineno = lineno;
5786 mdecl = make_node (FUNCTION_TYPE);
5787 TREE_TYPE (mdecl) = type;
5788 TYPE_ARG_TYPES (mdecl) = args;
5789 mdecl = add_method (class, flags, name, build_java_signature (mdecl));
5790 lineno = saved_lineno;
5791 DECL_ARTIFICIAL (mdecl) = 1;
5795 /* Starts the body if an artifical method. */
5798 start_artificial_method_body (mdecl)
5801 DECL_SOURCE_LINE (mdecl) = 1;
5802 DECL_SOURCE_LINE_MERGE (mdecl, 1);
5803 source_start_java_method (mdecl);
5808 end_artificial_method_body (mdecl)
5811 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
5815 /* Called during expansion. Push decls formerly built from argument
5816 list so they're usable during expansion. */
5819 expand_start_java_method (fndecl)
5824 current_function_decl = fndecl;
5826 announce_function (fndecl);
5827 pushlevel (1); /* Push parameters */
5828 ptr = &DECL_ARGUMENTS (fndecl);
5829 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
5832 tree next = TREE_CHAIN (tem);
5833 tree type = TREE_TYPE (tem);
5834 if (PROMOTE_PROTOTYPES
5835 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
5836 && INTEGRAL_TYPE_P (type))
5837 type = integer_type_node;
5838 DECL_ARG_TYPE (tem) = type;
5839 layout_decl (tem, 0);
5842 ptr = &TREE_CHAIN (tem);
5846 pushdecl_force_head (DECL_ARGUMENTS (fndecl));
5847 lineno = DECL_SOURCE_LINE_FIRST (fndecl);
5850 /* Terminate a function and expand its body. */
5853 source_end_java_method ()
5855 tree fndecl = current_function_decl;
5856 int flag_asynchronous_exceptions = asynchronous_exceptions;
5861 java_parser_context_save_global ();
5862 lineno = ctxp->last_ccb_indent1;
5864 /* Set EH language codes */
5865 java_set_exception_lang_code ();
5867 /* Turn function bodies with only a NOP expr null, so they don't get
5868 generated at all and we won't get warnings when using the -W
5870 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) == empty_stmt_node)
5871 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) = NULL_TREE;
5873 /* Generate function's code */
5874 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))
5875 && ! flag_emit_class_files
5876 && ! flag_emit_xref)
5877 expand_expr_stmt (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)));
5879 /* pop out of its parameters */
5880 pushdecl_force_head (DECL_ARGUMENTS (fndecl));
5882 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
5884 /* Generate rtl for function exit. */
5885 if (! flag_emit_class_files && ! flag_emit_xref)
5887 lineno = DECL_SOURCE_LINE_LAST (fndecl);
5888 /* Emit catch-finally clauses */
5890 expand_function_end (input_filename, lineno, 0);
5892 /* FIXME: If the current method contains any exception handlers,
5893 force asynchronous_exceptions: this is necessary because signal
5894 handlers in libjava may throw exceptions. This is far from being
5895 a perfect solution, but it's better than doing nothing at all.*/
5897 asynchronous_exceptions = 1;
5899 /* Run the optimizers and output assembler code for this function. */
5900 rest_of_compilation (fndecl);
5903 current_function_decl = NULL_TREE;
5904 permanent_allocation (1);
5905 java_parser_context_restore_global ();
5906 asynchronous_exceptions = flag_asynchronous_exceptions;
5909 /* Record EXPR in the current function block. Complements compound
5910 expression second operand if necessary. */
5913 java_method_add_stmt (fndecl, expr)
5916 if (!GET_CURRENT_BLOCK (fndecl))
5918 return add_stmt_to_block (GET_CURRENT_BLOCK (fndecl), NULL_TREE, expr);
5922 add_stmt_to_block (b, type, stmt)
5925 tree body = BLOCK_EXPR_BODY (b), c;
5927 if (java_error_count)
5930 if ((c = add_stmt_to_compound (body, type, stmt)) == body)
5933 BLOCK_EXPR_BODY (b) = c;
5934 TREE_SIDE_EFFECTS (c) = 1;
5938 /* Add STMT to EXISTING if possible, otherwise create a new
5939 COMPOUND_EXPR and add STMT to it. */
5942 add_stmt_to_compound (existing, type, stmt)
5943 tree existing, type, stmt;
5946 return build (COMPOUND_EXPR, type, existing, stmt);
5951 /* Hold THIS for the scope of the current public method decl. */
5952 static tree current_this;
5954 void java_layout_seen_class_methods ()
5956 tree previous_list = all_class_list;
5957 tree end = NULL_TREE;
5962 for (current = previous_list;
5963 current != end; current = TREE_CHAIN (current))
5964 layout_class_methods (TREE_TYPE (TREE_VALUE (current)));
5966 if (previous_list != all_class_list)
5968 end = previous_list;
5969 previous_list = all_class_list;
5976 /* Layout the methods of all classes loaded in one way on an
5977 other. Check methods of source parsed classes. Then reorder the
5978 fields and layout the classes or the type of all source parsed
5982 java_layout_classes ()
5985 int save_error_count = java_error_count;
5987 /* Layout the methods of all classes seen so far */
5988 java_layout_seen_class_methods ();
5989 java_parse_abort_on_error ();
5990 all_class_list = NULL_TREE;
5992 /* Then check the methods of all parsed classes */
5993 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
5994 if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
5995 CHECK_METHODS (TREE_VALUE (current));
5996 java_parse_abort_on_error ();
5998 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
6000 current_class = TREE_TYPE (TREE_VALUE (current));
6002 /* Reverse the fields, but leave the dummy field in front.
6003 Fields are already ordered for Object and Class */
6004 if (TYPE_FIELDS (current_class) && current_class != object_type_node
6005 && current_class != class_type_node)
6007 /* If the dummy field is there, reverse the right fields and
6008 just layout the type for proper fields offset */
6009 if (!DECL_NAME (TYPE_FIELDS (current_class)))
6011 tree fields = TYPE_FIELDS (current_class);
6012 TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
6013 TYPE_SIZE (current_class) = NULL_TREE;
6014 layout_type (current_class);
6016 /* We don't have a dummy field, we need to layout the class,
6017 after having reversed the fields */
6020 TYPE_FIELDS (current_class) =
6021 nreverse (TYPE_FIELDS (current_class));
6022 TYPE_SIZE (current_class) = NULL_TREE;
6023 layout_class (current_class);
6027 layout_class (current_class);
6029 /* From now on, the class is considered completely loaded */
6030 CLASS_LOADED_P (current_class) = 1;
6032 /* Error reported by the caller */
6033 if (java_error_count)
6037 /* We might have reloaded classes durign the process of laying out
6038 classes for code generation. We must layout the methods of those
6039 late additions, as constructor checks might use them */
6040 java_layout_seen_class_methods ();
6041 java_parse_abort_on_error ();
6044 /* Expand all methods in all registered classes. */
6047 java_complete_expand_methods ()
6051 do_not_fold = flag_emit_xref;
6053 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
6056 tree class_type = CLASS_TO_HANDLE_TYPE (TREE_TYPE (current));
6057 tree decl, prev_decl;
6059 current_class = TREE_TYPE (current);
6060 is_interface = CLASS_INTERFACE (TYPE_NAME (current_class));
6062 /* Initialize a new constant pool */
6063 init_outgoing_cpool ();
6065 /* We want <clinit> (if any) to be processed first. */
6066 for (prev_decl = NULL_TREE, decl = TYPE_METHODS (class_type);
6067 decl; prev_decl= decl, decl = TREE_CHAIN (decl))
6068 if (IS_CLINIT (decl))
6070 if (!java_pre_expand_clinit (decl))
6073 TREE_CHAIN (prev_decl) = TREE_CHAIN (decl);
6075 TYPE_METHODS (class_type) = TREE_CHAIN (decl);
6080 /* Now go on for regular business. */
6081 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
6083 current_function_decl = decl;
6084 /* Don't generate debug info on line zero when expanding a
6085 generated constructor. */
6086 if (DECL_CONSTRUCTOR_P (decl) && !DECL_FUNCTION_BODY (decl))
6088 /* If we found errors, it's too dangerous to try to
6089 generate and expand a constructor */
6090 if (!java_error_count)
6092 restore_line_number_status (1);
6093 java_complete_expand_method (decl);
6094 restore_line_number_status (0);
6097 else if (METHOD_ABSTRACT (decl) || METHOD_NATIVE (decl))
6100 java_complete_expand_method (decl);
6103 /* Now verify constructor circularity (stop after the first one
6106 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
6107 if (DECL_CONSTRUCTOR_P (decl) &&
6108 verify_constructor_circularity (decl, decl))
6111 /* Make the class data, register it and run the rest of decl
6112 compilation on it */
6113 if (!java_error_count)
6115 if (flag_emit_class_files)
6116 write_classfile (current_class);
6118 expand_xref (current_class);
6119 else if (! flag_syntax_only)
6125 /* Hold a list of catch clauses list. The first element of this list is
6126 the list of the catch clauses of the currently analysed try block. */
6127 static tree currently_caught_type_list;
6129 /* Complete and expand <clinit>. Return a non zero value if <clinit>
6130 is worth keeping. */
6133 java_pre_expand_clinit (decl)
6136 tree fbody = DECL_FUNCTION_BODY (decl);
6139 if (fbody != NULL_TREE)
6141 /* First check if we can ignore empty <clinit> */
6142 tree block_body = BLOCK_EXPR_BODY (fbody);
6144 current_this = NULL_TREE;
6145 current_function_decl = decl;
6146 if (block_body != NULL_TREE)
6148 /* Prevent the use of `this' inside <clinit> */
6149 ctxp->explicit_constructor_p = 1;
6150 block_body = java_complete_tree (block_body);
6151 ctxp->explicit_constructor_p = 0;
6153 BLOCK_EXPR_BODY (fbody) = block_body;
6154 if (block_body != NULL_TREE && TREE_CODE (block_body) == BLOCK
6155 && BLOCK_EXPR_BODY (block_body) == empty_stmt_node)
6162 /* Complete and expand a method. */
6165 java_complete_expand_method (mdecl)
6168 /* Fix constructors before expanding them */
6169 if (DECL_CONSTRUCTOR_P (mdecl))
6170 fix_constructors (mdecl);
6172 /* Expand functions that have a body */
6173 if (DECL_FUNCTION_BODY (mdecl))
6175 tree fbody = DECL_FUNCTION_BODY (mdecl);
6176 tree block_body = BLOCK_EXPR_BODY (fbody);
6177 tree exception_copy = NULL_TREE;
6178 expand_start_java_method (mdecl);
6179 build_result_decl (mdecl);
6182 = (!METHOD_STATIC (mdecl) ?
6183 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl)) : NULL_TREE);
6185 /* Purge the `throws' list of unchecked exceptions. If we're
6186 doing xref, save a copy of the list and re-install it
6189 exception_copy = copy_list (DECL_FUNCTION_THROWS (mdecl));
6191 purge_unchecked_exceptions (mdecl);
6193 /* Install exceptions thrown with `throws' */
6194 PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
6196 if (block_body != NULL_TREE)
6198 block_body = java_complete_tree (block_body);
6199 if (!flag_emit_xref)
6200 check_for_initialization (block_body);
6201 ctxp->explicit_constructor_p = 0;
6203 BLOCK_EXPR_BODY (fbody) = block_body;
6205 if ((block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
6206 && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE
6208 missing_return_error (current_function_decl);
6210 complete_start_java_method (mdecl);
6212 /* Don't go any further if we've found error(s) during the
6214 if (!java_error_count)
6215 source_end_java_method ();
6218 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
6222 /* Pop the exceptions and sanity check */
6224 if (currently_caught_type_list)
6225 fatal ("Exception list non empty - java_complete_expand_method");
6228 DECL_FUNCTION_THROWS (mdecl) = exception_copy;
6232 /* Craft a body for default constructor. Patch existing constructor
6233 bodies with call to super() and field initialization statements if
6237 fix_constructors (mdecl)
6240 tree body = DECL_FUNCTION_BODY (mdecl);
6244 /* The constructor body must be crafted by hand. It's the
6245 constructor we defined when we realize we didn't have the
6246 CLASSNAME() constructor */
6250 /* It is an error for the compiler to generate a default
6251 constructor if the superclass doesn't have a constructor that
6252 takes no argument */
6253 if (verify_constructor_super ())
6255 tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (current_class));
6256 const char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
6258 (lookup_cl (TYPE_NAME (current_class)),
6259 "No constructor matching `%s()' found in class `%s'", n, n);
6262 start_artificial_method_body (mdecl);
6264 /* We don't generate a super constructor invocation if we're
6265 compiling java.lang.Object. build_super_invocation takes care
6267 compound = java_method_add_stmt (mdecl, build_super_invocation (mdecl));
6269 end_artificial_method_body (mdecl);
6271 /* Search for an explicit constructor invocation */
6275 tree main_block = BLOCK_EXPR_BODY (body);
6276 tree compound = NULL_TREE;
6279 switch (TREE_CODE (body))
6282 found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
6286 case EXPR_WITH_FILE_LOCATION:
6287 body = TREE_OPERAND (body, 0);
6290 body = BLOCK_EXPR_BODY (body);
6296 /* The constructor is missing an invocation of super() */
6298 compound = add_stmt_to_compound (compound, NULL_TREE,
6299 build_super_invocation (mdecl));
6301 /* Fix the constructor main block if we're adding extra stmts */
6304 compound = add_stmt_to_compound (compound, NULL_TREE,
6305 BLOCK_EXPR_BODY (main_block));
6306 BLOCK_EXPR_BODY (main_block) = compound;
6311 /* Browse constructors in the super class, searching for a constructor
6312 that doesn't take any argument. Return 0 if one is found, 1
6316 verify_constructor_super ()
6318 tree class = CLASSTYPE_SUPER (current_class);
6325 for (mdecl = TYPE_METHODS (class); mdecl; mdecl = TREE_CHAIN (mdecl))
6327 if (DECL_CONSTRUCTOR_P (mdecl)
6328 && TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (mdecl)))
6336 /* Expand finals. */
6339 java_expand_finals ()
6343 /* Generate code for all context remembered for code generation. */
6346 java_expand_classes ()
6348 int save_error_count = 0;
6349 java_parse_abort_on_error ();
6350 if (!(ctxp = ctxp_for_generation))
6352 java_layout_classes ();
6353 java_parse_abort_on_error ();
6355 for (; ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
6357 ctxp = ctxp_for_generation;
6358 lang_init_source (2); /* Error msgs have method prototypes */
6359 java_complete_expand_methods (); /* Complete and expand method bodies */
6360 java_parse_abort_on_error ();
6361 java_expand_finals (); /* Expand and check the finals */
6362 java_parse_abort_on_error ();
6363 java_check_final (); /* Check unitialized final */
6364 java_parse_abort_on_error ();
6368 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
6369 a tree list node containing RIGHT. Fore coming RIGHTs will be
6370 chained to this hook. LOCATION contains the location of the
6371 separating `.' operator. */
6374 make_qualified_primary (primary, right, location)
6375 tree primary, right;
6380 /* We want to process THIS . xxx symbolicaly, to keep it consistent
6381 with the way we're processing SUPER. A THIS from a primary as a
6382 different form than a SUPER. Turn THIS into something symbolic */
6383 if (TREE_CODE (primary) == THIS_EXPR)
6385 wfl = build_wfl_node (this_identifier_node);
6386 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (primary);
6387 wfl = make_qualified_name (wfl, right, location);
6388 PRIMARY_P (wfl) = 1;
6391 /* Other non WFL node are wrapped around a WFL */
6392 else if (TREE_CODE (primary) != EXPR_WITH_FILE_LOCATION)
6394 wfl = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
6395 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (primary);
6396 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (primary, NULL_TREE);
6401 if (!EXPR_WFL_QUALIFICATION (primary))
6402 EXPR_WFL_QUALIFICATION (primary) =
6403 build_tree_list (primary, NULL_TREE);
6406 EXPR_WFL_LINECOL (right) = location;
6407 chainon (EXPR_WFL_QUALIFICATION (wfl), build_tree_list (right, NULL_TREE));
6408 PRIMARY_P (wfl) = 1;
6412 /* Simple merge of two name separated by a `.' */
6415 merge_qualified_name (left, right)
6419 obstack_grow (&temporary_obstack, IDENTIFIER_POINTER (left),
6420 IDENTIFIER_LENGTH (left));
6421 obstack_1grow (&temporary_obstack, '.');
6422 obstack_grow0 (&temporary_obstack, IDENTIFIER_POINTER (right),
6423 IDENTIFIER_LENGTH (right));
6424 node = get_identifier (obstack_base (&temporary_obstack));
6425 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
6426 QUALIFIED_P (node) = 1;
6430 /* Merge the two parts of a qualified name into LEFT. Set the
6431 location information of the resulting node to LOCATION, usually
6432 inherited from the location information of the `.' operator. */
6435 make_qualified_name (left, right, location)
6439 #ifdef USE_COMPONENT_REF
6440 tree node = build (COMPONENT_REF, NULL_TREE, left, right);
6441 EXPR_WFL_LINECOL (node) = location;
6444 tree left_id = EXPR_WFL_NODE (left);
6445 tree right_id = EXPR_WFL_NODE (right);
6448 merge = merge_qualified_name (left_id, right_id);
6450 /* Left wasn't qualified and is now qualified */
6451 if (!QUALIFIED_P (left_id))
6453 tree wfl = build_expr_wfl (left_id, ctxp->filename, 0, 0);
6454 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (left);
6455 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
6458 wfl = build_expr_wfl (right_id, ctxp->filename, 0, 0);
6459 EXPR_WFL_LINECOL (wfl) = location;
6460 chainon (EXPR_WFL_QUALIFICATION (left), build_tree_list (wfl, NULL_TREE));
6462 EXPR_WFL_NODE (left) = merge;
6467 /* Extract the last identifier component of the qualified in WFL. The
6468 last identifier is removed from the linked list */
6471 cut_identifier_in_qualified (wfl)
6475 tree previous = NULL_TREE;
6476 for (q = EXPR_WFL_QUALIFICATION (wfl); ; previous = q, q = TREE_CHAIN (q))
6477 if (!TREE_CHAIN (q))
6480 fatal ("Operating on a non qualified qualified WFL - cut_identifier_in_qualified");
6481 TREE_CHAIN (previous) = NULL_TREE;
6482 return TREE_PURPOSE (q);
6486 /* Resolve the expression name NAME. Return its decl. */
6489 resolve_expression_name (id, orig)
6493 tree name = EXPR_WFL_NODE (id);
6496 /* 6.5.5.1: Simple expression names */
6497 if (!PRIMARY_P (id) && !QUALIFIED_P (name))
6499 /* 15.13.1: NAME can appear within the scope of a local variable
6501 if ((decl = IDENTIFIER_LOCAL_VALUE (name)))
6504 /* 15.13.1: NAME can appear within a class declaration */
6507 decl = lookup_field_wrapper (current_class, name);
6510 int fs = FIELD_STATIC (decl);
6511 /* Instance variable (8.3.1.1) can't appear within
6512 static method, static initializer or initializer for
6513 a static variable. */
6514 if (!fs && METHOD_STATIC (current_function_decl))
6516 static_ref_err (id, name, current_class);
6517 return error_mark_node;
6519 /* Instance variables can't appear as an argument of
6520 an explicit constructor invocation */
6521 if (!fs && ctxp->explicit_constructor_p)
6524 (id, "Can't reference `%s' before the superclass constructor has been called", IDENTIFIER_POINTER (name));
6525 return error_mark_node;
6528 /* Otherwise build what it takes to access the field */
6529 decl = build_field_ref ((fs ? NULL_TREE : current_this),
6530 DECL_CONTEXT (decl), name);
6531 if (fs && !flag_emit_class_files && !flag_emit_xref)
6532 decl = build_class_init (DECL_CONTEXT (decl), decl);
6533 /* We may be asked to save the real field access node */
6536 /* And we return what we got */
6539 /* Fall down to error report on undefined variable */
6542 /* 6.5.5.2 Qualified Expression Names */
6547 qualify_ambiguous_name (id);
6548 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
6549 /* 15.10.2: Accessing Superclass Members using super */
6550 return resolve_field_access (id, orig, NULL);
6553 /* We've got an error here */
6554 parse_error_context (id, "Undefined variable `%s'",
6555 IDENTIFIER_POINTER (name));
6557 return error_mark_node;
6561 static_ref_err (wfl, field_id, class_type)
6562 tree wfl, field_id, class_type;
6566 "Can't make a static reference to nonstatic variable `%s' in class `%s'",
6567 IDENTIFIER_POINTER (field_id),
6568 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class_type))));
6571 /* 15.10.1 Field Acess Using a Primary and/or Expression Name.
6572 We return something suitable to generate the field access. We also
6573 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
6574 recipient's address can be null. */
6577 resolve_field_access (qual_wfl, field_decl, field_type)
6579 tree *field_decl, *field_type;
6583 tree decl, where_found, type_found;
6585 if (resolve_qualified_expression_name (qual_wfl, &decl,
6586 &where_found, &type_found))
6587 return error_mark_node;
6589 /* Resolve the LENGTH field of an array here */
6590 if (DECL_NAME (decl) == length_identifier_node && TYPE_ARRAY_P (type_found)
6591 && ! flag_emit_class_files && ! flag_emit_xref)
6593 tree length = build_java_array_length_access (where_found);
6595 build_java_arraynull_check (type_found, length, int_type_node);
6597 /* We might have been trying to resolve field.method(). In which
6598 case, the resolution is over and decl is the answer */
6599 else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
6601 else if (JDECL_P (decl))
6603 int static_final_found = 0;
6605 type_found = DECL_CONTEXT (decl);
6606 is_static = JDECL_P (decl) && FIELD_STATIC (decl);
6607 if (FIELD_FINAL (decl)
6608 && JPRIMITIVE_TYPE_P (TREE_TYPE (decl))
6609 && DECL_LANG_SPECIFIC (decl)
6610 && DECL_INITIAL (decl))
6612 field_ref = DECL_INITIAL (decl);
6613 static_final_found = 1;
6616 field_ref = build_field_ref ((is_static && !flag_emit_xref?
6617 NULL_TREE : where_found),
6618 type_found, DECL_NAME (decl));
6619 if (field_ref == error_mark_node)
6620 return error_mark_node;
6621 if (is_static && !static_final_found
6622 && !flag_emit_class_files && !flag_emit_xref)
6623 field_ref = build_class_init (type_found, field_ref);
6631 *field_type = (QUAL_DECL_TYPE (decl) ?
6632 QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
6636 /* If NODE is an access to f static field, strip out the class
6637 initialization part and return the field decl, otherwise, return
6641 strip_out_static_field_access_decl (node)
6644 if (TREE_CODE (node) == COMPOUND_EXPR)
6646 tree op1 = TREE_OPERAND (node, 1);
6647 if (TREE_CODE (op1) == COMPOUND_EXPR)
6649 tree call = TREE_OPERAND (op1, 0);
6650 if (TREE_CODE (call) == CALL_EXPR
6651 && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
6652 && TREE_OPERAND (TREE_OPERAND (call, 0), 0)
6653 == soft_initclass_node)
6654 return TREE_OPERAND (op1, 1);
6656 else if (JDECL_P (op1))
6662 /* 6.5.5.2: Qualified Expression Names */
6665 resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
6667 tree *found_decl, *type_found, *where_found;
6669 int from_type = 0; /* Field search initiated from a type */
6670 int from_super = 0, from_cast = 0;
6671 int previous_call_static = 0;
6673 tree decl = NULL_TREE, type = NULL_TREE, q;
6674 *type_found = *where_found = NULL_TREE;
6676 for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
6678 tree qual_wfl = QUAL_WFL (q);
6679 tree ret_decl; /* for EH checking */
6680 int location; /* for EH checking */
6682 /* 15.10.1 Field Access Using a Primary */
6683 switch (TREE_CODE (qual_wfl))
6686 case NEW_CLASS_EXPR:
6687 /* If the access to the function call is a non static field,
6688 build the code to access it. */
6689 if (JDECL_P (decl) && !FIELD_STATIC (decl))
6691 decl = maybe_access_field (decl, *where_found,
6692 DECL_CONTEXT (decl));
6693 if (decl == error_mark_node)
6696 /* And code for the function call */
6697 if (complete_function_arguments (qual_wfl))
6700 if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
6701 CALL_USING_SUPER (qual_wfl) = 1;
6702 location = (TREE_CODE (qual_wfl) == CALL_EXPR ?
6703 EXPR_WFL_LINECOL (TREE_OPERAND (qual_wfl, 0)) : 0);
6704 *where_found = patch_method_invocation (qual_wfl, decl, type,
6705 &is_static, &ret_decl);
6706 if (*where_found == error_mark_node)
6708 *type_found = type = QUAL_DECL_TYPE (*where_found);
6712 check_thrown_exceptions (location, ret_decl);
6714 /* If the previous call was static and this one is too,
6715 build a compound expression to hold the two (because in
6716 that case, previous function calls aren't transported as
6717 forcoming function's argument. */
6718 if (previous_call_static && is_static)
6720 decl = build (COMPOUND_EXPR, type, decl, *where_found);
6721 TREE_SIDE_EFFECTS (decl) = 1;
6725 previous_call_static = is_static;
6726 decl = *where_found;
6730 case NEW_ARRAY_EXPR:
6731 *where_found = decl = java_complete_tree (qual_wfl);
6732 if (decl == error_mark_node)
6734 *type_found = type = QUAL_DECL_TYPE (decl);
6735 CLASS_LOADED_P (type) = 1;
6739 *where_found = decl = java_complete_tree (qual_wfl);
6740 if (decl == error_mark_node)
6742 *type_found = type = QUAL_DECL_TYPE (decl);
6746 case CONDITIONAL_EXPR:
6749 *where_found = decl = java_complete_tree (qual_wfl);
6750 if (decl == error_mark_node)
6752 *type_found = type = QUAL_DECL_TYPE (decl);
6756 /* If the access to the function call is a non static field,
6757 build the code to access it. */
6758 if (JDECL_P (decl) && !FIELD_STATIC (decl))
6760 decl = maybe_access_field (decl, *where_found, type);
6761 if (decl == error_mark_node)
6764 /* And code for the array reference expression */
6765 decl = java_complete_tree (qual_wfl);
6766 if (decl == error_mark_node)
6768 type = QUAL_DECL_TYPE (decl);
6772 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
6774 if ((type = patch_string (decl)))
6776 *where_found = QUAL_RESOLUTION (q) = decl;
6777 *type_found = type = TREE_TYPE (decl);
6781 /* Fix for -Wall Just go to the next statement. Don't
6786 /* If we fall here, we weren't processing a (static) function call. */
6787 previous_call_static = 0;
6789 /* It can be the keyword THIS */
6790 if (EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
6795 (wfl, "Keyword `this' used outside allowed context");
6798 if (ctxp->explicit_constructor_p)
6800 parse_error_context (wfl, "Can't reference `this' before the superclass constructor has been called");
6803 /* We have to generate code for intermediate acess */
6804 *where_found = decl = current_this;
6805 *type_found = type = QUAL_DECL_TYPE (decl);
6809 /* 15.10.2 Accessing Superclass Members using SUPER */
6810 if (EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
6813 /* Check on the restricted use of SUPER */
6814 if (METHOD_STATIC (current_function_decl)
6815 || current_class == object_type_node)
6818 (wfl, "Keyword `super' used outside allowed context");
6821 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
6822 node = build_cast (EXPR_WFL_LINECOL (qual_wfl),
6823 CLASSTYPE_SUPER (current_class),
6824 build_this (EXPR_WFL_LINECOL (qual_wfl)));
6825 *where_found = decl = java_complete_tree (node);
6826 if (decl == error_mark_node)
6828 *type_found = type = QUAL_DECL_TYPE (decl);
6829 from_super = from_type = 1;
6833 /* 15.13.1: Can't search for field name in packages, so we
6834 assume a variable/class name was meant. */
6835 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
6837 tree name = resolve_package (wfl, &q);
6840 *where_found = decl = resolve_no_layout (name, qual_wfl);
6841 /* We wan't to be absolutely that the class is laid
6842 out. We're going to search something inside it. */
6843 *type_found = type = TREE_TYPE (decl);
6844 layout_class (type);
6846 /* Should be a list, really. FIXME */
6847 RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (TREE_CHAIN (q))) = 1;
6848 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (TREE_CHAIN (q))) = 0;
6852 if (from_super || from_cast)
6854 ((from_cast ? qual_wfl : wfl),
6855 "No variable `%s' defined in class `%s'",
6856 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6857 lang_printable_name (type, 0));
6860 (qual_wfl, "Undefined variable or class name: `%s'",
6861 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)));
6866 /* We have a type name. It's been already resolved when the
6867 expression was qualified. */
6868 else if (RESOLVE_TYPE_NAME_P (qual_wfl))
6870 if (!(decl = QUAL_RESOLUTION (q)))
6871 return 1; /* Error reported already */
6873 if (not_accessible_p (TREE_TYPE (decl), decl, 0))
6876 (qual_wfl, "Can't access %s field `%s.%s' from `%s'",
6877 java_accstring_lookup (get_access_flags_from_decl (decl)),
6878 GET_TYPE_NAME (type),
6879 IDENTIFIER_POINTER (DECL_NAME (decl)),
6880 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
6883 check_deprecation (qual_wfl, decl);
6885 type = TREE_TYPE (decl);
6888 /* We resolve and expression name */
6891 tree field_decl = NULL_TREE;
6893 /* If there exists an early resolution, use it. That occurs
6894 only once and we know that there are more things to
6895 come. Don't do that when processing something after SUPER
6896 (we need more thing to be put in place below */
6897 if (!from_super && QUAL_RESOLUTION (q))
6899 decl = QUAL_RESOLUTION (q);
6902 if (TREE_CODE (decl) == FIELD_DECL && !FIELD_STATIC (decl))
6905 *where_found = current_this;
6908 static_ref_err (qual_wfl, DECL_NAME (decl),
6915 *where_found = TREE_TYPE (decl);
6916 if (TREE_CODE (*where_found) == POINTER_TYPE)
6917 *where_found = TREE_TYPE (*where_found);
6922 /* We have to search for a field, knowing the type of its
6923 container. The flag FROM_TYPE indicates that we resolved
6924 the last member of the expression as a type name, which
6925 means that for the resolution of this field, we'll look
6926 for other errors than if it was resolved as a member of
6931 tree field_decl_type; /* For layout */
6933 if (!from_type && !JREFERENCE_TYPE_P (type))
6936 (qual_wfl, "Attempt to reference field `%s' in `%s %s'",
6937 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6938 lang_printable_name (type, 0),
6939 IDENTIFIER_POINTER (DECL_NAME (field_decl)));
6943 field_decl = lookup_field_wrapper (type,
6944 EXPR_WFL_NODE (qual_wfl));
6945 if (field_decl == NULL_TREE)
6948 (qual_wfl, "No variable `%s' defined in type `%s'",
6949 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6950 GET_TYPE_NAME (type));
6953 if (field_decl == error_mark_node)
6956 /* Layout the type of field_decl, since we may need
6957 it. Don't do primitive types or loaded classes. The
6958 situation of non primitive arrays may not handled
6959 properly here. FIXME */
6960 if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
6961 field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
6963 field_decl_type = TREE_TYPE (field_decl);
6964 if (!JPRIMITIVE_TYPE_P (field_decl_type)
6965 && !CLASS_LOADED_P (field_decl_type)
6966 && !TYPE_ARRAY_P (field_decl_type))
6967 resolve_and_layout (field_decl_type, NULL_TREE);
6968 if (TYPE_ARRAY_P (field_decl_type))
6969 CLASS_LOADED_P (field_decl_type) = 1;
6971 /* Check on accessibility here */
6972 if (not_accessible_p (type, field_decl, from_super))
6976 "Can't access %s field `%s.%s' from `%s'",
6977 java_accstring_lookup
6978 (get_access_flags_from_decl (field_decl)),
6979 GET_TYPE_NAME (type),
6980 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
6982 (DECL_NAME (TYPE_NAME (current_class))));
6985 check_deprecation (qual_wfl, field_decl);
6987 /* There are things to check when fields are accessed
6988 from type. There are no restrictions on a static
6989 declaration of the field when it is accessed from an
6991 is_static = FIELD_STATIC (field_decl);
6992 if (!from_super && from_type
6993 && !TYPE_INTERFACE_P (type) && !is_static)
6995 static_ref_err (qual_wfl, EXPR_WFL_NODE (qual_wfl), type);
6998 from_cast = from_super = 0;
7000 /* If we need to generate something to get a proper
7001 handle on what this field is accessed from, do it
7005 decl = maybe_access_field (decl, *where_found, *type_found);
7006 if (decl == error_mark_node)
7010 /* We want to keep the location were found it, and the type
7012 *where_found = decl;
7015 /* This is the decl found and eventually the next one to
7020 type = QUAL_DECL_TYPE (decl);
7027 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
7028 can't be accessed from REFERENCE (a record type). */
7031 not_accessible_p (reference, member, from_super)
7032 tree reference, member;
7035 int access_flag = get_access_flags_from_decl (member);
7037 /* Access always granted for members declared public */
7038 if (access_flag & ACC_PUBLIC)
7041 /* Check access on protected members */
7042 if (access_flag & ACC_PROTECTED)
7044 /* Access granted if it occurs from within the package
7045 containing the class in which the protected member is
7047 if (class_in_current_package (DECL_CONTEXT (member)))
7050 /* If accessed with the form `super.member', then access is granted */
7054 /* Otherwise, access is granted if occuring from the class where
7055 member is declared or a subclass of it */
7056 if (inherits_from_p (reference, current_class))
7061 /* Check access on private members. Access is granted only if it
7062 occurs from within the class in witch it is declared */
7063 if (access_flag & ACC_PRIVATE)
7064 return (current_class == DECL_CONTEXT (member) ? 0 : 1);
7066 /* Default access are permitted only when occuring within the
7067 package in which the type (REFERENCE) is declared. In other words,
7068 REFERENCE is defined in the current package */
7070 return !class_in_current_package (reference);
7072 /* Otherwise, access is granted */
7076 /* Test deprecated decl access. */
7078 check_deprecation (wfl, decl)
7081 const char *file = DECL_SOURCE_FILE (decl);
7082 /* Complain if the field is deprecated and the file it was defined
7083 in isn't compiled at the same time the file which contains its
7085 if (DECL_DEPRECATED (decl)
7086 && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
7089 switch (TREE_CODE (decl))
7092 strcpy (the, "method");
7095 strcpy (the, "field");
7098 strcpy (the, "class");
7101 fatal ("unexpected DECL code - check_deprecation");
7103 parse_warning_context
7104 (wfl, "The %s `%s' in class `%s' has been deprecated",
7105 the, lang_printable_name (decl, 0),
7106 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
7110 /* Returns 1 if class was declared in the current package, 0 otherwise */
7113 class_in_current_package (class)
7116 static tree cache = NULL_TREE;
7123 qualified_flag = QUALIFIED_P (DECL_NAME (TYPE_NAME (class)));
7125 /* If the current package is empty and the name of CLASS is
7126 qualified, class isn't in the current package. If there is a
7127 current package and the name of the CLASS is not qualified, class
7128 isn't in the current package */
7129 if ((!ctxp->package && qualified_flag) || (ctxp->package && !qualified_flag))
7132 /* If there is not package and the name of CLASS isn't qualified,
7133 they belong to the same unnamed package */
7134 if (!ctxp->package && !qualified_flag)
7137 /* Compare the left part of the name of CLASS with the package name */
7138 breakdown_qualified (&left, NULL, DECL_NAME (TYPE_NAME (class)));
7139 if (ctxp->package == left)
7147 /* This function may generate code to access DECL from WHERE. This is
7148 done only if certain conditions meet. */
7151 maybe_access_field (decl, where, type)
7152 tree decl, where, type;
7154 if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
7155 && !FIELD_STATIC (decl))
7156 decl = build_field_ref (where ? where : current_this,
7157 (type ? type : DECL_CONTEXT (decl)),
7162 /* Build a method invocation, by patching PATCH. If non NULL
7163 and according to the situation, PRIMARY and WHERE may be
7164 used. IS_STATIC is set to 1 if the invoked function is static. */
7167 patch_method_invocation (patch, primary, where, is_static, ret_decl)
7168 tree patch, primary, where;
7172 tree wfl = TREE_OPERAND (patch, 0);
7173 tree args = TREE_OPERAND (patch, 1);
7174 tree name = EXPR_WFL_NODE (wfl);
7176 int is_static_flag = 0;
7177 int is_super_init = 0;
7178 tree this_arg = NULL_TREE;
7180 /* Should be overriden if everything goes well. Otherwise, if
7181 something fails, it should keep this value. It stop the
7182 evaluation of a bogus assignment. See java_complete_tree,
7183 MODIFY_EXPR: for the reasons why we sometimes want to keep on
7184 evaluating an assignment */
7185 TREE_TYPE (patch) = error_mark_node;
7187 /* Since lookup functions are messing with line numbers, save the
7189 java_parser_context_save_global ();
7191 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
7193 /* Resolution of qualified name, excluding constructors */
7194 if (QUALIFIED_P (name) && !CALL_CONSTRUCTOR_P (patch))
7196 tree class_decl, identifier, identifier_wfl;
7197 /* Extract the last IDENTIFIER of the qualified
7198 expression. This is a wfl and we will use it's location
7199 data during error report. */
7200 identifier_wfl = cut_identifier_in_qualified (wfl);
7201 identifier = EXPR_WFL_NODE (identifier_wfl);
7203 /* Given the context, IDENTIFIER is syntactically qualified
7204 as a MethodName. We need to qualify what's before */
7205 qualify_ambiguous_name (wfl);
7207 /* Package resolution */
7208 if (RESOLVE_PACKAGE_NAME_P (wfl))
7210 tree next, decl, name = resolve_package (wfl, &next);
7215 breakdown_qualified (&remainder, NULL, EXPR_WFL_NODE (wfl));
7217 (wfl, "Can't search method `%s' in package `%s'",
7218 IDENTIFIER_POINTER (identifier),
7219 IDENTIFIER_POINTER (remainder));
7220 PATCH_METHOD_RETURN_ERROR ();
7222 RESOLVE_PACKAGE_NAME_P (wfl) = 0;
7223 if ((decl = resolve_no_layout (name, QUAL_WFL (next))))
7225 QUAL_RESOLUTION (EXPR_WFL_QUALIFICATION (wfl)) = decl;
7226 RESOLVE_EXPRESSION_NAME_P (wfl) = 0;
7227 RESOLVE_TYPE_NAME_P (wfl) = 1;
7231 RESOLVE_EXPRESSION_NAME_P (wfl) = 1;
7232 RESOLVE_TYPE_NAME_P (wfl) = 0;
7236 /* We're resolving a call from a type */
7237 if (RESOLVE_TYPE_NAME_P (wfl))
7239 tree decl = QUAL_RESOLUTION (EXPR_WFL_QUALIFICATION (wfl));
7240 tree name = DECL_NAME (decl);
7243 class_decl = resolve_and_layout (name, wfl);
7244 if (CLASS_INTERFACE (decl))
7248 "Can't make static reference to method `%s' in interface `%s'",
7249 IDENTIFIER_POINTER (identifier),
7250 IDENTIFIER_POINTER (name));
7251 PATCH_METHOD_RETURN_ERROR ();
7253 /* Look the method up in the type selector. The method ought
7255 type = TREE_TYPE (class_decl);
7256 list = lookup_method_invoke (0, wfl, type, identifier, args);
7257 if (list && !METHOD_STATIC (list))
7259 char *fct_name = xstrdup (lang_printable_name (list, 0));
7262 "Can't make static reference to method `%s %s' in class `%s'",
7263 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
7264 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
7266 PATCH_METHOD_RETURN_ERROR ();
7268 args = nreverse (args);
7270 /* We're resolving an expression name */
7275 /* 1- Find the field to which the call applies */
7276 field = resolve_field_access (wfl, NULL, &type);
7277 if (field == error_mark_node)
7278 PATCH_METHOD_RETURN_ERROR ();
7279 /* field is used in lieu of a primary. It alows us not to
7280 report errors on erroneous use of `this' in
7284 /* 2- Do the layout of the class where the last field
7285 was found, so we can search it. */
7286 class_decl = resolve_and_layout (type, NULL_TREE);
7287 if (class_decl != NULL_TREE)
7288 type = TREE_TYPE (class_decl);
7290 /* 3- Retrieve a filtered list of method matches, Refine
7291 if necessary. In any cases, point out errors. */
7292 list = lookup_method_invoke (0, identifier_wfl, type,
7295 /* 4- Add the field as an argument */
7296 args = nreverse (args);
7300 /* IDENTIFIER_WFL will be used to report any problem further */
7301 wfl = identifier_wfl;
7303 /* Resolution of simple names, names generated after a primary: or
7307 tree class_to_search = NULL_TREE;
7308 int lc; /* Looking for Constructor */
7310 /* We search constructor in their target class */
7311 if (CALL_CONSTRUCTOR_P (patch))
7313 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
7314 class_to_search = EXPR_WFL_NODE (wfl);
7315 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
7316 this_identifier_node)
7317 class_to_search = NULL_TREE;
7318 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
7319 super_identifier_node)
7322 if (CLASSTYPE_SUPER (current_class))
7324 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
7327 parse_error_context (wfl, "Can't invoke super constructor on java.lang.Object");
7328 PATCH_METHOD_RETURN_ERROR ();
7332 /* Class to search is NULL if we're searching the current one */
7333 if (class_to_search)
7335 class_to_search = resolve_and_layout (class_to_search,
7337 if (!class_to_search)
7340 (wfl, "Class `%s' not found in type declaration",
7341 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
7342 PATCH_METHOD_RETURN_ERROR ();
7345 /* Can't instantiate an abstract class, but we can
7346 invoke it's constructor. It's use within the `new'
7347 context is denied here. */
7348 if (CLASS_ABSTRACT (class_to_search)
7349 && TREE_CODE (patch) == NEW_CLASS_EXPR)
7352 (wfl, "Class `%s' is an abstract class. It can't be instantiated",
7353 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
7354 PATCH_METHOD_RETURN_ERROR ();
7356 class_to_search = TREE_TYPE (class_to_search);
7359 class_to_search = current_class;
7362 /* This is a regular search in the local class, unless an
7363 alternate class is specified. */
7366 class_to_search = (where ? where : current_class);
7370 /* NAME is a simple identifier or comes from a primary. Search
7371 in the class whose declaration contain the method being
7373 resolve_and_layout (class_to_search, NULL_TREE);
7374 list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
7376 /* Don't continue if no method were found, as the next statement
7377 can't be executed then. */
7379 PATCH_METHOD_RETURN_ERROR ();
7381 /* Check for static reference if non static methods */
7382 if (check_for_static_method_reference (wfl, patch, list,
7383 class_to_search, primary))
7384 PATCH_METHOD_RETURN_ERROR ();
7386 /* Non static methods are called with the current object extra
7387 argument. If patch a `new TYPE()', the argument is the value
7388 returned by the object allocator. If method is resolved as a
7389 primary, use the primary otherwise use the current THIS. */
7390 args = nreverse (args);
7391 if (TREE_CODE (patch) != NEW_CLASS_EXPR)
7392 this_arg = primary ? primary : current_this;
7395 /* Merge point of all resolution schemes. If we have nothing, this
7396 is an error, already signaled */
7398 PATCH_METHOD_RETURN_ERROR ();
7400 /* Check accessibility, position the is_static flag, build and
7402 if (not_accessible_p (DECL_CONTEXT (current_function_decl), list, 0))
7404 char *fct_name = xstrdup (lang_printable_name (list, 0));
7406 (wfl, "Can't access %s method `%s %s.%s' from `%s'",
7407 java_accstring_lookup (get_access_flags_from_decl (list)),
7408 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
7409 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list)))),
7410 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
7412 PATCH_METHOD_RETURN_ERROR ();
7414 check_deprecation (wfl, list);
7416 is_static_flag = METHOD_STATIC (list);
7417 if (! METHOD_STATIC (list) && this_arg != NULL_TREE)
7418 args = tree_cons (NULL_TREE, this_arg, args);
7420 /* In the context of an explicit constructor invocation, we can't
7421 invoke any method relying on `this'. Exceptions are: we're
7422 invoking a static function, primary exists and is not the current
7423 this, we're creating a new object. */
7424 if (ctxp->explicit_constructor_p
7426 && (!primary || primary == current_this)
7427 && (TREE_CODE (patch) != NEW_CLASS_EXPR))
7429 parse_error_context (wfl, "Can't reference `this' before the superclass constructor has been called");
7430 PATCH_METHOD_RETURN_ERROR ();
7432 java_parser_context_restore_global ();
7434 *is_static = is_static_flag;
7435 /* Sometimes, we want the decl of the selected method. Such as for
7439 patch = patch_invoke (patch, list, args);
7440 if (is_super_init && CLASS_HAS_FINIT_P (current_class))
7442 /* Generate the code used to initialize fields declared with an
7443 initialization statement. For now, it returns a call the the
7444 artificial function $finit$, if required. */
7447 build_method_invocation (build_expr_wfl (finit_identifier_node,
7448 input_filename, 0, 0),
7450 patch = build (COMPOUND_EXPR, void_type_node, patch,
7451 java_complete_tree (finit_call));
7452 CAN_COMPLETE_NORMALLY (patch) = 1;
7457 /* Check that we're not trying to do a static reference to a method in
7458 non static method. Return 1 if it's the case, 0 otherwise. */
7461 check_for_static_method_reference (wfl, node, method, where, primary)
7462 tree wfl, node, method, where, primary;
7464 if (METHOD_STATIC (current_function_decl)
7465 && !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
7467 char *fct_name = xstrdup (lang_printable_name (method, 0));
7469 (wfl, "Can't make static reference to method `%s %s' in class `%s'",
7470 lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
7471 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (where))));
7478 /* Patch an invoke expression METHOD and ARGS, based on its invocation
7482 patch_invoke (patch, method, args)
7483 tree patch, method, args;
7486 tree original_call, t, ta;
7488 /* Last step for args: convert build-in types. If we're dealing with
7489 a new TYPE() type call, the first argument to the constructor
7490 isn't found in the incomming argument list, but delivered by
7492 t = TYPE_ARG_TYPES (TREE_TYPE (method));
7493 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
7495 for (ta = args; t != end_params_node && ta;
7496 t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
7497 if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
7498 TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
7499 TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
7501 /* Resolve unresolved returned type isses */
7502 t = TREE_TYPE (TREE_TYPE (method));
7503 if (TREE_CODE (t) == POINTER_TYPE && !CLASS_LOADED_P (TREE_TYPE (t)))
7504 resolve_and_layout (TREE_TYPE (t), NULL);
7506 if (flag_emit_class_files || flag_emit_xref)
7510 tree signature = build_java_signature (TREE_TYPE (method));
7511 switch (invocation_mode (method, CALL_USING_SUPER (patch)))
7513 case INVOKE_VIRTUAL:
7514 dtable = invoke_build_dtable (0, args);
7515 func = build_invokevirtual (dtable, method);
7520 func = build_known_method_ref (method, TREE_TYPE (method),
7521 DECL_CONTEXT (method),
7525 case INVOKE_INTERFACE:
7526 dtable = invoke_build_dtable (1, args);
7527 func = build_invokeinterface (dtable, method);
7531 fatal ("internal error - unknown invocation_mode result");
7534 /* Ensure self_type is initialized, (invokestatic). FIXME */
7535 func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
7538 TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
7539 TREE_OPERAND (patch, 0) = func;
7540 TREE_OPERAND (patch, 1) = args;
7541 original_call = patch;
7543 /* We're processing a `new TYPE ()' form. New is called an its
7544 returned value is the first argument to the constructor. We build
7545 a COMPOUND_EXPR and use saved expression so that the overall NEW
7546 expression value is a pointer to a newly created and initialized
7548 if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
7550 tree class = DECL_CONTEXT (method);
7551 tree c1, saved_new, size, new;
7552 if (flag_emit_class_files || flag_emit_xref)
7554 TREE_TYPE (patch) = build_pointer_type (class);
7557 if (!TYPE_SIZE (class))
7558 safe_layout_class (class);
7559 size = size_in_bytes (class);
7560 new = build (CALL_EXPR, promote_type (class),
7561 build_address_of (alloc_object_node),
7562 tree_cons (NULL_TREE, build_class_ref (class),
7563 build_tree_list (NULL_TREE,
7564 size_in_bytes (class))),
7566 saved_new = save_expr (new);
7567 c1 = build_tree_list (NULL_TREE, saved_new);
7568 TREE_CHAIN (c1) = TREE_OPERAND (original_call, 1);
7569 TREE_OPERAND (original_call, 1) = c1;
7570 TREE_SET_CODE (original_call, CALL_EXPR);
7571 patch = build (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new);
7577 invocation_mode (method, super)
7581 int access = get_access_flags_from_decl (method);
7584 return INVOKE_SUPER;
7586 if (access & ACC_STATIC || access & ACC_FINAL || access & ACC_PRIVATE)
7587 return INVOKE_STATIC;
7589 if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
7590 return INVOKE_STATIC;
7592 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
7593 return INVOKE_INTERFACE;
7595 if (DECL_CONSTRUCTOR_P (method))
7596 return INVOKE_STATIC;
7598 return INVOKE_VIRTUAL;
7601 /* Retrieve a refined list of matching methods. It covers the step
7602 15.11.2 (Compile-Time Step 2) */
7605 lookup_method_invoke (lc, cl, class, name, arg_list)
7608 tree class, name, arg_list;
7610 tree atl = end_params_node; /* Arg Type List */
7611 tree method, signature, list, node;
7612 const char *candidates; /* Used for error report */
7615 /* Fix the arguments */
7616 for (node = arg_list; node; node = TREE_CHAIN (node))
7618 tree current_arg = TREE_TYPE (TREE_VALUE (node));
7619 /* Non primitive type may have to be resolved */
7620 if (!JPRIMITIVE_TYPE_P (current_arg))
7621 resolve_and_layout (current_arg, NULL_TREE);
7623 if (TREE_CODE (current_arg) == RECORD_TYPE)
7624 current_arg = promote_type (current_arg);
7625 atl = tree_cons (NULL_TREE, current_arg, atl);
7628 /* Find all candidates and then refine the list, searching for the
7629 most specific method. */
7630 list = find_applicable_accessible_methods_list (lc, class, name, atl);
7631 list = find_most_specific_methods_list (list);
7632 if (list && !TREE_CHAIN (list))
7633 return TREE_VALUE (list);
7635 /* Issue an error. List candidates if any. Candidates are listed
7636 only if accessible (non accessible methods may end-up here for
7637 the sake of a better error report). */
7642 obstack_grow (&temporary_obstack, ". Candidates are:\n", 18);
7643 for (current = list; current; current = TREE_CHAIN (current))
7645 tree cm = TREE_VALUE (current);
7647 if (!cm || not_accessible_p (class, cm, 0))
7650 (string, " `%s' in `%s'%s",
7651 get_printable_method_name (cm),
7652 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
7653 (TREE_CHAIN (current) ? "\n" : ""));
7654 obstack_grow (&temporary_obstack, string, strlen (string));
7656 obstack_1grow (&temporary_obstack, '\0');
7657 candidates = obstack_finish (&temporary_obstack);
7659 /* Issue the error message */
7660 method = make_node (FUNCTION_TYPE);
7661 TYPE_ARG_TYPES (method) = atl;
7662 signature = build_java_argument_signature (method);
7663 dup = xstrdup (lang_printable_name (class, 0));
7664 parse_error_context (cl, "Can't find %s `%s(%s)' in type `%s'%s",
7665 (lc ? "constructor" : "method"),
7666 (lc ? dup : IDENTIFIER_POINTER (name)),
7667 IDENTIFIER_POINTER (signature), dup,
7668 (candidates ? candidates : ""));
7673 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
7674 when we're looking for a constructor. */
7677 find_applicable_accessible_methods_list (lc, class, name, arglist)
7679 tree class, name, arglist;
7681 tree list = NULL_TREE, all_list = NULL_TREE;
7683 /* Search interfaces */
7684 if (CLASS_INTERFACE (TYPE_NAME (class))
7685 || CLASS_ABSTRACT (TYPE_NAME (class)))
7687 static tree searched_interfaces = NULL_TREE;
7688 static int search_not_done = 0;
7690 tree basetype_vec = TYPE_BINFO_BASETYPES (class);
7692 /* Have we searched this interface already? */
7693 if (searched_interfaces)
7696 for (current = searched_interfaces;
7697 current; current = TREE_CHAIN (current))
7698 if (TREE_VALUE (current) == class)
7701 searched_interfaces = tree_cons (NULL_TREE, class, searched_interfaces);
7703 search_applicable_methods_list
7704 (lc, TYPE_METHODS (class), name, arglist, &list, &all_list);
7706 n = TREE_VEC_LENGTH (basetype_vec);
7707 for (i = 0; i < n; i++)
7709 tree t = BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i));
7712 /* Skip java.lang.Object (we'll search it once later.) */
7713 if (t == object_type_node)
7717 rlist = find_applicable_accessible_methods_list (lc, t, name,
7719 all_list = chainon (rlist, (list ? list : all_list));
7723 /* We're done. Reset the searched interfaces list and finally search
7725 if (!search_not_done)
7727 searched_interfaces = NULL_TREE;
7728 search_applicable_methods_list (lc, TYPE_METHODS (object_type_node),
7729 name, arglist, &list, &all_list);
7732 /* Search classes */
7734 while (class != NULL_TREE)
7736 search_applicable_methods_list
7737 (lc, TYPE_METHODS (class), name, arglist, &list, &all_list);
7738 class = (lc ? NULL_TREE : CLASSTYPE_SUPER (class));
7741 /* Either return the list obtained or all selected (but
7742 inaccessible) methods for better error report. */
7743 return (!list ? all_list : list);
7746 /* Effectively search for the approriate method in method */
7749 search_applicable_methods_list(lc, method, name, arglist, list, all_list)
7751 tree method, name, arglist;
7752 tree *list, *all_list;
7754 for (; method; method = TREE_CHAIN (method))
7756 /* When dealing with constructor, stop here, otherwise search
7758 if (lc && !DECL_CONSTRUCTOR_P (method))
7760 else if (!lc && (DECL_CONSTRUCTOR_P (method)
7761 || (GET_METHOD_NAME (method) != name)))
7764 if (argument_types_convertible (method, arglist))
7766 /* Retain accessible methods only */
7767 if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
7769 *list = tree_cons (NULL_TREE, method, *list);
7771 /* Also retain all selected method here */
7772 *all_list = tree_cons (NULL_TREE, method, *list);
7777 /* 15.11.2.2 Choose the Most Specific Method */
7780 find_most_specific_methods_list (list)
7784 tree current, new_list = NULL_TREE;
7785 for (current = list; current; current = TREE_CHAIN (current))
7788 DECL_SPECIFIC_COUNT (TREE_VALUE (current)) = 0;
7790 for (method = list; method; method = TREE_CHAIN (method))
7792 /* Don't test a method against itself */
7793 if (method == current)
7796 /* Compare arguments and location where method where declared */
7797 if (argument_types_convertible (TREE_VALUE (method),
7798 TREE_VALUE (current))
7799 && valid_method_invocation_conversion_p
7800 (DECL_CONTEXT (TREE_VALUE (method)),
7801 DECL_CONTEXT (TREE_VALUE (current))))
7803 int v = ++DECL_SPECIFIC_COUNT (TREE_VALUE (current));
7804 max = (v > max ? v : max);
7809 /* Review the list and select the maximally specific methods */
7810 for (current = list; current; current = TREE_CHAIN (current))
7811 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
7812 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
7814 /* If we can't find one, lower expectations and try to gather multiple
7815 maximally specific methods */
7820 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
7821 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
7829 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
7830 converted by method invocation conversion (5.3) to the type of the
7831 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
7832 to change less often than M1. */
7835 argument_types_convertible (m1, m2_or_arglist)
7836 tree m1, m2_or_arglist;
7838 static tree m2_arg_value = NULL_TREE;
7839 static tree m2_arg_cache = NULL_TREE;
7841 register tree m1_arg, m2_arg;
7843 m1_arg = TYPE_ARG_TYPES (TREE_TYPE (m1));
7844 if (!METHOD_STATIC (m1))
7845 m1_arg = TREE_CHAIN (m1_arg);
7847 if (m2_arg_value == m2_or_arglist)
7848 m2_arg = m2_arg_cache;
7851 /* M2_OR_ARGLIST can be a function DECL or a raw list of
7853 if (m2_or_arglist && TREE_CODE (m2_or_arglist) == FUNCTION_DECL)
7855 m2_arg = TYPE_ARG_TYPES (TREE_TYPE (m2_or_arglist));
7856 if (!METHOD_STATIC (m2_or_arglist))
7857 m2_arg = TREE_CHAIN (m2_arg);
7860 m2_arg = m2_or_arglist;
7862 m2_arg_value = m2_or_arglist;
7863 m2_arg_cache = m2_arg;
7866 while (m1_arg != end_params_node && m2_arg != end_params_node)
7868 resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
7869 if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
7870 TREE_VALUE (m2_arg)))
7872 m1_arg = TREE_CHAIN (m1_arg);
7873 m2_arg = TREE_CHAIN (m2_arg);
7875 return m1_arg == end_params_node && m2_arg == end_params_node;
7878 /* Qualification routines */
7881 qualify_ambiguous_name (id)
7884 tree qual, qual_wfl, name = NULL_TREE, decl, ptr_type = NULL_TREE,
7885 saved_current_class;
7886 int again, super_found = 0, this_found = 0, new_array_found = 0;
7889 /* We first qualify the first element, then derive qualification of
7890 others based on the first one. If the first element is qualified
7891 by a resolution (field or type), this resolution is stored in the
7892 QUAL_RESOLUTION of the qual element being examined. We need to
7893 save the current_class since the use of SUPER might change the
7895 saved_current_class = current_class;
7896 qual = EXPR_WFL_QUALIFICATION (id);
7899 /* Simple qualified expression feature a qual_wfl that is a
7900 WFL. Expression derived from a primary feature more complicated
7901 things like a CALL_EXPR. Expression from primary need to be
7902 worked out to extract the part on which the qualification will
7904 qual_wfl = QUAL_WFL (qual);
7905 switch (TREE_CODE (qual_wfl))
7908 qual_wfl = TREE_OPERAND (qual_wfl, 0);
7909 if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
7911 qual = EXPR_WFL_QUALIFICATION (qual_wfl);
7912 qual_wfl = QUAL_WFL (qual);
7915 case NEW_ARRAY_EXPR:
7916 qual = TREE_CHAIN (qual);
7917 again = new_array_found = 1;
7919 case NEW_CLASS_EXPR:
7921 qual_wfl = TREE_OPERAND (qual_wfl, 0);
7924 while (TREE_CODE (qual_wfl) == ARRAY_REF)
7925 qual_wfl = TREE_OPERAND (qual_wfl, 0);
7928 qual = TREE_CHAIN (qual);
7929 qual_wfl = QUAL_WFL (qual);
7932 /* Fix for -Wall. Just break doing nothing */
7936 ptr_type = current_class;
7938 code = TREE_CODE (qual_wfl);
7940 /* Pos evaluation: non WFL leading expression nodes */
7941 if (code == CONVERT_EXPR
7942 && TREE_CODE (TREE_TYPE (qual_wfl)) == EXPR_WITH_FILE_LOCATION)
7943 name = EXPR_WFL_NODE (TREE_TYPE (qual_wfl));
7945 else if ((code == ARRAY_REF || code == CALL_EXPR || code == MODIFY_EXPR) &&
7946 TREE_CODE (TREE_OPERAND (qual_wfl, 0)) == EXPR_WITH_FILE_LOCATION)
7947 name = EXPR_WFL_NODE (TREE_OPERAND (qual_wfl, 0));
7949 else if (code == STRING_CST || code == CONDITIONAL_EXPR
7950 || code == PLUS_EXPR)
7952 qual = TREE_CHAIN (qual);
7953 qual_wfl = QUAL_WFL (qual);
7958 name = EXPR_WFL_NODE (qual_wfl);
7961 qual = EXPR_WFL_QUALIFICATION (qual_wfl);
7966 /* If we have a THIS (from a primary), we set the context accordingly */
7967 if (name == this_identifier_node)
7969 qual = TREE_CHAIN (qual);
7970 qual_wfl = QUAL_WFL (qual);
7971 if (TREE_CODE (qual_wfl) == CALL_EXPR)
7974 name = EXPR_WFL_NODE (qual_wfl);
7977 /* If we have a SUPER, we set the context accordingly */
7978 if (name == super_identifier_node)
7980 current_class = CLASSTYPE_SUPER (ptr_type);
7981 /* Check that there is such a thing as a super class. If not,
7982 return. The error will be caught later on, during the
7986 current_class = saved_current_class;
7989 qual = TREE_CHAIN (qual);
7990 /* Do one more interation to set things up */
7991 super_found = again = 1;
7995 /* If name appears within the scope of a location variable
7996 declaration or parameter declaration, then it is an expression
7997 name. We don't carry this test out if we're in the context of the
7998 use of SUPER or THIS */
7999 if (!this_found && !super_found &&
8000 TREE_CODE (name) != STRING_CST && (decl = IDENTIFIER_LOCAL_VALUE (name)))
8002 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
8003 QUAL_RESOLUTION (qual) = decl;
8006 /* If within the class/interface NAME was found to be used there
8007 exists a (possibly inherited) field named NAME, then this is an
8008 expression name. If we saw a NEW_ARRAY_EXPR before and want to
8009 address length, it is OK. */
8010 else if ((decl = lookup_field_wrapper (ptr_type, name))
8011 || (new_array_found && name == length_identifier_node))
8013 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
8014 QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
8017 /* We reclassify NAME as yielding to a type name resolution if:
8018 - NAME is a class/interface declared within the compilation
8019 unit containing NAME,
8020 - NAME is imported via a single-type-import declaration,
8021 - NAME is declared in an another compilation unit of the package
8022 of the compilation unit containing NAME,
8023 - NAME is declared by exactly on type-import-on-demand declaration
8024 of the compilation unit containing NAME.
8025 - NAME is actually a STRING_CST. */
8026 else if (TREE_CODE (name) == STRING_CST ||
8027 (decl = resolve_and_layout (name, NULL_TREE)))
8029 RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
8030 QUAL_RESOLUTION (qual) = decl;
8033 /* Method call are expression name */
8034 else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR
8035 || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF
8036 || TREE_CODE (QUAL_WFL (qual)) == CONVERT_EXPR)
8037 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
8039 /* Check here that NAME isn't declared by more than one
8040 type-import-on-demand declaration of the compilation unit
8041 containing NAME. FIXME */
8043 /* Otherwise, NAME is reclassified as a package name */
8045 RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
8047 /* Propagate the qualification accross other components of the
8049 for (qual = TREE_CHAIN (qual); qual;
8050 qual_wfl = QUAL_WFL (qual), qual = TREE_CHAIN (qual))
8052 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
8053 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
8055 RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (qual)) = 1;
8058 /* Store the global qualification for the ambiguous part of ID back
8060 if (RESOLVE_EXPRESSION_NAME_P (qual_wfl))
8061 RESOLVE_EXPRESSION_NAME_P (id) = 1;
8062 else if (RESOLVE_TYPE_NAME_P (qual_wfl))
8063 RESOLVE_TYPE_NAME_P (id) = 1;
8064 else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
8065 RESOLVE_PACKAGE_NAME_P (id) = 1;
8067 /* Restore the current class */
8068 current_class = saved_current_class;
8072 breakdown_qualified (left, right, source)
8073 tree *left, *right, source;
8075 char *p = IDENTIFIER_POINTER (source), *base;
8076 int l = IDENTIFIER_LENGTH (source);
8078 /* Breakdown NAME into REMAINDER . IDENTIFIER */
8081 while (*p != '.' && p != base)
8084 /* We didn't find a '.'. Return an error */
8090 *right = get_identifier (p+1);
8091 *left = get_identifier (IDENTIFIER_POINTER (source));
8097 /* Patch tree nodes in a function body. When a BLOCK is found, push
8098 local variable decls if present.
8099 Same as java_complete_lhs, but does resolve static finals to values. */
8102 java_complete_tree (node)
8105 node = java_complete_lhs (node);
8106 if (TREE_CODE (node) == VAR_DECL && FIELD_STATIC (node)
8107 && FIELD_FINAL (node) && DECL_INITIAL (node) != NULL_TREE
8110 tree value = DECL_INITIAL (node);
8111 DECL_INITIAL (node) = NULL_TREE;
8112 push_obstacks (&permanent_obstack, &permanent_obstack);
8113 value = fold_constant_for_init (value, node);
8115 DECL_INITIAL (node) = value;
8116 if (value != NULL_TREE)
8123 java_stabilize_reference (node)
8126 if (TREE_CODE (node) == COMPOUND_EXPR)
8128 tree op0 = TREE_OPERAND (node, 0);
8129 tree op1 = TREE_OPERAND (node, 1);
8130 TREE_OPERAND (node, 0) = save_expr (op0);
8131 TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
8134 return stabilize_reference (node);
8137 /* Patch tree nodes in a function body. When a BLOCK is found, push
8138 local variable decls if present.
8139 Same as java_complete_tree, but does not resolve static finals to values. */
8142 java_complete_lhs (node)
8145 tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
8148 /* CONVERT_EXPR always has its type set, even though it needs to be
8150 if (TREE_TYPE (node) && TREE_CODE (node) != CONVERT_EXPR)
8153 /* The switch block implements cases processing container nodes
8154 first. Contained nodes are always written back. Leaves come
8155 next and return a value. */
8156 switch (TREE_CODE (node))
8160 /* 1- Block section.
8161 Set the local values on decl names so we can identify them
8162 faster when they're referenced. At that stage, identifiers
8163 are legal so we don't check for declaration errors. */
8164 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
8166 DECL_CONTEXT (cn) = current_function_decl;
8167 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
8169 if (BLOCK_EXPR_BODY (node) == NULL_TREE)
8170 CAN_COMPLETE_NORMALLY (node) = 1;
8173 tree stmt = BLOCK_EXPR_BODY (node);
8176 if (TREE_CODE (stmt) == COMPOUND_EXPR)
8178 /* Re-order from (((A; B); C); ...; Z) to
8179 (A; (B; (C ; (...; Z)))).
8180 This makes it easier to scan the statements left-to-right
8181 without using recursion (which might overflow the stack
8182 if the block has many statements. */
8185 tree left = TREE_OPERAND (stmt, 0);
8186 if (TREE_CODE (left) != COMPOUND_EXPR)
8188 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
8189 TREE_OPERAND (left, 1) = stmt;
8192 BLOCK_EXPR_BODY (node) = stmt;
8195 /* Now do the actual complete, without deep recursion for
8197 ptr = &BLOCK_EXPR_BODY (node);
8198 while (TREE_CODE (*ptr) == COMPOUND_EXPR
8199 && TREE_OPERAND (*ptr, 1) != empty_stmt_node)
8201 tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
8202 tree *next = &TREE_OPERAND (*ptr, 1);
8203 TREE_OPERAND (*ptr, 0) = cur;
8204 if (cur == empty_stmt_node)
8206 /* Optimization; makes it easier to detect empty bodies.
8207 Most useful for <clinit> with all-constant initializer. */
8211 if (TREE_CODE (cur) == ERROR_MARK)
8213 else if (! CAN_COMPLETE_NORMALLY (cur))
8218 if (TREE_CODE (wfl_op2) == BLOCK)
8219 wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
8220 else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
8221 wfl_op2 = TREE_OPERAND (wfl_op2, 0);
8225 if (TREE_CODE (wfl_op2) != CASE_EXPR
8226 && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
8227 unreachable_stmt_error (*ptr);
8231 *ptr = java_complete_tree (*ptr);
8233 if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
8234 return error_mark_node;
8235 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
8237 /* Turn local bindings to null */
8238 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
8239 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = NULL_TREE;
8241 TREE_TYPE (node) = void_type_node;
8244 /* 2- They are expressions but ultimately deal with statements */
8247 wfl_op1 = TREE_OPERAND (node, 0);
8248 COMPLETE_CHECK_OP_0 (node);
8249 /* CAN_COMPLETE_NORMALLY (node) = 0; */
8250 return patch_throw_statement (node, wfl_op1);
8252 case SYNCHRONIZED_EXPR:
8253 wfl_op1 = TREE_OPERAND (node, 0);
8254 return patch_synchronized_statement (node, wfl_op1);
8257 return patch_try_statement (node);
8259 case TRY_FINALLY_EXPR:
8260 COMPLETE_CHECK_OP_0 (node);
8261 COMPLETE_CHECK_OP_1 (node);
8262 CAN_COMPLETE_NORMALLY (node)
8263 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
8264 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
8265 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
8268 case CLEANUP_POINT_EXPR:
8269 COMPLETE_CHECK_OP_0 (node);
8270 TREE_TYPE (node) = void_type_node;
8271 CAN_COMPLETE_NORMALLY (node) =
8272 CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
8275 case WITH_CLEANUP_EXPR:
8276 COMPLETE_CHECK_OP_0 (node);
8277 COMPLETE_CHECK_OP_2 (node);
8278 CAN_COMPLETE_NORMALLY (node) =
8279 CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
8280 TREE_TYPE (node) = void_type_node;
8283 case LABELED_BLOCK_EXPR:
8284 PUSH_LABELED_BLOCK (node);
8285 if (LABELED_BLOCK_BODY (node))
8286 COMPLETE_CHECK_OP_1 (node);
8287 TREE_TYPE (node) = void_type_node;
8288 POP_LABELED_BLOCK ();
8290 if (LABELED_BLOCK_BODY (node) == empty_stmt_node)
8292 LABELED_BLOCK_BODY (node) = NULL_TREE;
8293 CAN_COMPLETE_NORMALLY (node) = 1;
8295 else if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
8296 CAN_COMPLETE_NORMALLY (node) = 1;
8299 case EXIT_BLOCK_EXPR:
8300 /* We don't complete operand 1, because it's the return value of
8301 the EXIT_BLOCK_EXPR which doesn't exist it Java */
8302 return patch_bc_statement (node);
8305 cn = java_complete_tree (TREE_OPERAND (node, 0));
8306 if (cn == error_mark_node)
8309 /* First, the case expression must be constant. Values of final
8310 fields are accepted. */
8312 if ((TREE_CODE (cn) == COMPOUND_EXPR || TREE_CODE (cn) == COMPONENT_REF)
8313 && JDECL_P (TREE_OPERAND (cn, 1))
8314 && FIELD_FINAL (TREE_OPERAND (cn, 1))
8315 && DECL_INITIAL (TREE_OPERAND (cn, 1)))
8317 push_obstacks (&permanent_obstack, &permanent_obstack);
8318 cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
8319 TREE_OPERAND (cn, 1));
8323 if (!TREE_CONSTANT (cn) && !flag_emit_xref)
8325 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8326 parse_error_context (node, "Constant expression required");
8327 return error_mark_node;
8330 nn = ctxp->current_loop;
8332 /* It must be assignable to the type of the switch expression. */
8333 if (!try_builtin_assignconv (NULL_TREE,
8334 TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
8336 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8339 "Incompatible type for case. Can't convert `%s' to `int'",
8340 lang_printable_name (TREE_TYPE (cn), 0));
8341 return error_mark_node;
8344 cn = fold (convert (int_type_node, cn));
8346 /* Multiple instance of a case label bearing the same
8347 value is checked during code generation. The case
8348 expression is allright so far. */
8349 TREE_OPERAND (node, 0) = cn;
8350 TREE_TYPE (node) = void_type_node;
8351 CAN_COMPLETE_NORMALLY (node) = 1;
8352 TREE_SIDE_EFFECTS (node) = 1;
8356 nn = ctxp->current_loop;
8357 /* Only one default label is allowed per switch statement */
8358 if (SWITCH_HAS_DEFAULT (nn))
8360 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8361 parse_error_context (wfl_operator,
8362 "Duplicate case label: `default'");
8363 return error_mark_node;
8366 SWITCH_HAS_DEFAULT (nn) = 1;
8367 TREE_TYPE (node) = void_type_node;
8368 TREE_SIDE_EFFECTS (node) = 1;
8369 CAN_COMPLETE_NORMALLY (node) = 1;
8375 /* Check whether the loop was enclosed in a labeled
8376 statement. If not, create one, insert the loop in it and
8378 nn = patch_loop_statement (node);
8380 /* Anyways, walk the body of the loop */
8381 if (TREE_CODE (node) == LOOP_EXPR)
8382 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
8383 /* Switch statement: walk the switch expression and the cases */
8385 node = patch_switch_statement (node);
8387 if (TREE_OPERAND (node, 0) == error_mark_node)
8388 nn = error_mark_node;
8391 TREE_TYPE (nn) = TREE_TYPE (node) = void_type_node;
8392 /* If we returned something different, that's because we
8393 inserted a label. Pop the label too. */
8396 if (CAN_COMPLETE_NORMALLY (node))
8397 CAN_COMPLETE_NORMALLY (nn) = 1;
8398 POP_LABELED_BLOCK ();
8405 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
8406 return patch_exit_expr (node);
8410 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
8411 if (TREE_OPERAND (node, 0) == error_mark_node)
8412 return error_mark_node;
8413 /* then-else branches */
8414 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
8415 if (TREE_OPERAND (node, 1) == error_mark_node)
8416 return error_mark_node;
8417 TREE_OPERAND (node, 2) = java_complete_tree (TREE_OPERAND (node, 2));
8418 if (TREE_OPERAND (node, 2) == error_mark_node)
8419 return error_mark_node;
8420 return patch_if_else_statement (node);
8423 case CONDITIONAL_EXPR:
8425 wfl_op1 = TREE_OPERAND (node, 0);
8426 COMPLETE_CHECK_OP_0 (node);
8427 wfl_op2 = TREE_OPERAND (node, 1);
8428 COMPLETE_CHECK_OP_1 (node);
8429 wfl_op3 = TREE_OPERAND (node, 2);
8430 COMPLETE_CHECK_OP_2 (node);
8431 return patch_conditional_expr (node, wfl_op1, wfl_op2);
8433 /* 3- Expression section */
8435 wfl_op2 = TREE_OPERAND (node, 1);
8436 TREE_OPERAND (node, 0) = nn =
8437 java_complete_tree (TREE_OPERAND (node, 0));
8438 if (wfl_op2 == empty_stmt_node)
8439 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
8442 if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
8444 /* An unreachable condition in a do-while statement
8445 is *not* (technically) an unreachable statement. */
8447 if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
8448 nn = EXPR_WFL_NODE (nn);
8449 if (TREE_CODE (nn) != EXIT_EXPR)
8451 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
8452 parse_error_context (wfl_operator, "Unreachable statement");
8455 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
8456 if (TREE_OPERAND (node, 1) == error_mark_node)
8457 return error_mark_node;
8458 CAN_COMPLETE_NORMALLY (node)
8459 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1));
8461 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
8465 /* CAN_COMPLETE_NORMALLY (node) = 0; */
8466 return patch_return (node);
8468 case EXPR_WITH_FILE_LOCATION:
8469 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
8470 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
8473 node = resolve_expression_name (node, NULL);
8474 if (node == error_mark_node)
8476 /* Keep line number information somewhere were it doesn't
8477 disrupt the completion process. */
8478 if (flag_emit_xref && TREE_CODE (node) != CALL_EXPR)
8480 EXPR_WFL_NODE (wfl) = TREE_OPERAND (node, 1);
8481 TREE_OPERAND (node, 1) = wfl;
8483 CAN_COMPLETE_NORMALLY (node) = 1;
8488 int save_lineno = lineno;
8489 lineno = EXPR_WFL_LINENO (node);
8490 body = java_complete_tree (EXPR_WFL_NODE (node));
8491 lineno = save_lineno;
8492 EXPR_WFL_NODE (node) = body;
8493 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
8494 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
8495 if (body == empty_stmt_node)
8497 /* Optimization; makes it easier to detect empty bodies. */
8500 if (body == error_mark_node)
8502 /* Its important for the evaluation of assignment that
8503 this mark on the TREE_TYPE is propagated. */
8504 TREE_TYPE (node) = error_mark_node;
8505 return error_mark_node;
8508 TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
8513 case NEW_ARRAY_EXPR:
8514 /* Patch all the dimensions */
8516 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
8518 int location = EXPR_WFL_LINECOL (TREE_VALUE (cn));
8519 tree dim = convert (int_type_node,
8520 java_complete_tree (TREE_VALUE (cn)));
8521 if (dim == error_mark_node)
8528 TREE_VALUE (cn) = dim;
8529 /* Setup the location of the current dimension, for
8530 later error report. */
8532 build_expr_wfl (NULL_TREE, input_filename, 0, 0);
8533 EXPR_WFL_LINECOL (TREE_PURPOSE (cn)) = location;
8536 /* They complete the array creation expression, if no errors
8538 CAN_COMPLETE_NORMALLY (node) = 1;
8539 return (flag ? error_mark_node
8540 : force_evaluation_order (patch_newarray (node)));
8542 case NEW_CLASS_EXPR:
8544 /* Complete function's argument(s) first */
8545 if (complete_function_arguments (node))
8546 return error_mark_node;
8549 tree decl, wfl = TREE_OPERAND (node, 0);
8550 int in_this = CALL_THIS_CONSTRUCTOR_P (node);
8552 node = patch_method_invocation (node, NULL_TREE,
8553 NULL_TREE, 0, &decl);
8554 if (node == error_mark_node)
8555 return error_mark_node;
8557 check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
8558 /* If we call this(...), register signature and positions */
8560 DECL_CONSTRUCTOR_CALLS (current_function_decl) =
8561 tree_cons (wfl, decl,
8562 DECL_CONSTRUCTOR_CALLS (current_function_decl));
8563 CAN_COMPLETE_NORMALLY (node) = 1;
8564 return force_evaluation_order (node);
8568 /* Save potential wfls */
8569 wfl_op1 = TREE_OPERAND (node, 0);
8570 TREE_OPERAND (node, 0) = nn = java_complete_lhs (wfl_op1);
8571 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node)
8572 && TREE_CODE (nn) == VAR_DECL && TREE_STATIC (nn)
8573 && DECL_INITIAL (nn) != NULL_TREE)
8577 push_obstacks (&permanent_obstack, &permanent_obstack);
8578 value = fold_constant_for_init (nn, nn);
8580 if (value != NULL_TREE)
8582 tree type = TREE_TYPE (value);
8583 if (JPRIMITIVE_TYPE_P (type) || type == string_ptr_type_node)
8584 return empty_stmt_node;
8586 DECL_INITIAL (nn) = NULL_TREE;
8588 wfl_op2 = TREE_OPERAND (node, 1);
8590 if (TREE_OPERAND (node, 0) == error_mark_node)
8591 return error_mark_node;
8593 flag = COMPOUND_ASSIGN_P (wfl_op2);
8596 tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0));
8598 /* Hand stablize the lhs on both places */
8599 TREE_OPERAND (node, 0) = lvalue;
8600 TREE_OPERAND (TREE_OPERAND (node, 1), 0) =
8601 (flag_emit_class_files ? lvalue : save_expr (lvalue));
8603 /* 15.25.2.a: Left hand is not an array access. FIXME */
8604 /* Now complete the RHS. We write it back later on. */
8605 nn = java_complete_tree (TREE_OPERAND (node, 1));
8607 if ((cn = patch_string (nn)))
8610 /* The last part of the rewrite for E1 op= E2 is to have
8611 E1 = (T)(E1 op E2), with T being the type of E1. */
8612 nn = java_complete_tree (build_cast (EXPR_WFL_LINECOL (wfl_op2),
8613 TREE_TYPE (lvalue), nn));
8615 /* 15.25.2.b: Left hand is an array access. FIXME */
8618 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
8619 function to complete this RHS */
8620 else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT)
8621 nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
8622 TREE_OPERAND (node, 1));
8623 /* Otherwise we simply complete the RHS */
8625 nn = java_complete_tree (TREE_OPERAND (node, 1));
8627 if (nn == error_mark_node)
8628 return error_mark_node;
8630 /* Write back the RHS as we evaluated it. */
8631 TREE_OPERAND (node, 1) = nn;
8633 /* In case we're handling = with a String as a RHS, we need to
8634 produce a String out of the RHS (it might still be a
8635 STRING_CST or a StringBuffer at this stage */
8636 if ((nn = patch_string (TREE_OPERAND (node, 1))))
8637 TREE_OPERAND (node, 1) = nn;
8638 node = patch_assignment (node, wfl_op1, wfl_op2);
8639 /* Reorganize the tree if necessary. */
8640 if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node))
8641 || JSTRING_P (TREE_TYPE (node))))
8642 node = java_refold (node);
8643 CAN_COMPLETE_NORMALLY (node) = 1;
8655 case TRUNC_MOD_EXPR:
8657 case TRUTH_ANDIF_EXPR:
8658 case TRUTH_ORIF_EXPR:
8665 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
8666 knows how to handle those cases. */
8667 wfl_op1 = TREE_OPERAND (node, 0);
8668 wfl_op2 = TREE_OPERAND (node, 1);
8670 CAN_COMPLETE_NORMALLY (node) = 1;
8671 /* Don't complete string nodes if dealing with the PLUS operand. */
8672 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
8674 nn = java_complete_tree (wfl_op1);
8675 if (nn == error_mark_node)
8676 return error_mark_node;
8677 if ((cn = patch_string (nn)))
8679 TREE_OPERAND (node, 0) = nn;
8681 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
8683 nn = java_complete_tree (wfl_op2);
8684 if (nn == error_mark_node)
8685 return error_mark_node;
8686 if ((cn = patch_string (nn)))
8688 TREE_OPERAND (node, 1) = nn;
8690 return force_evaluation_order (patch_binop (node, wfl_op1, wfl_op2));
8692 case INSTANCEOF_EXPR:
8693 wfl_op1 = TREE_OPERAND (node, 0);
8694 COMPLETE_CHECK_OP_0 (node);
8697 TREE_TYPE (node) = boolean_type_node;
8700 return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
8702 case UNARY_PLUS_EXPR:
8704 case TRUTH_NOT_EXPR:
8706 case PREDECREMENT_EXPR:
8707 case PREINCREMENT_EXPR:
8708 case POSTDECREMENT_EXPR:
8709 case POSTINCREMENT_EXPR:
8711 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
8712 how to handle those cases. */
8713 wfl_op1 = TREE_OPERAND (node, 0);
8714 CAN_COMPLETE_NORMALLY (node) = 1;
8715 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
8716 if (TREE_OPERAND (node, 0) == error_mark_node)
8717 return error_mark_node;
8718 node = patch_unaryop (node, wfl_op1);
8719 CAN_COMPLETE_NORMALLY (node) = 1;
8723 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
8724 how to handle those cases. */
8725 wfl_op1 = TREE_OPERAND (node, 0);
8726 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
8727 if (TREE_OPERAND (node, 0) == error_mark_node)
8728 return error_mark_node;
8729 if (!flag_emit_class_files && !flag_emit_xref)
8730 TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
8731 /* The same applies to wfl_op2 */
8732 wfl_op2 = TREE_OPERAND (node, 1);
8733 TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
8734 if (TREE_OPERAND (node, 1) == error_mark_node)
8735 return error_mark_node;
8736 if (!flag_emit_class_files && !flag_emit_xref)
8737 TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
8738 return patch_array_ref (node);
8744 /* The first step in the re-write of qualified name handling. FIXME.
8745 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
8746 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
8747 if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
8749 tree name = TREE_OPERAND (node, 1);
8750 tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
8751 if (field == NULL_TREE)
8753 error ("missing static field `%s'", IDENTIFIER_POINTER (name));
8754 return error_mark_node;
8756 if (! FIELD_STATIC (field))
8758 error ("not a static field `%s'", IDENTIFIER_POINTER (name));
8759 return error_mark_node;
8764 fatal ("unimplemented java_complete_tree for COMPONENT_REF");
8768 /* Can't use THIS in a static environment */
8771 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8772 parse_error_context (wfl_operator,
8773 "Keyword `this' used outside allowed context");
8774 TREE_TYPE (node) = error_mark_node;
8775 return error_mark_node;
8777 if (ctxp->explicit_constructor_p)
8779 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8781 (wfl_operator, "Can't reference `this' or `super' before the superclass constructor has been called");
8782 TREE_TYPE (node) = error_mark_node;
8783 return error_mark_node;
8785 return current_this;
8788 CAN_COMPLETE_NORMALLY (node) = 1;
8789 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
8790 and it's time to turn it into the appropriate String object
8792 if ((node = patch_string (node)))
8794 fatal ("No case for tree code `%s' - java_complete_tree\n",
8795 tree_code_name [TREE_CODE (node)]);
8800 /* Complete function call's argument. Return a non zero value is an
8804 complete_function_arguments (node)
8810 ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
8811 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
8813 tree wfl = TREE_VALUE (cn), parm, temp;
8814 parm = java_complete_tree (wfl);
8815 if (parm == error_mark_node)
8820 /* If have a string literal that we haven't transformed yet or a
8821 crafted string buffer, as a result of use of the the String
8822 `+' operator. Build `parm.toString()' and expand it. */
8823 if ((temp = patch_string (parm)))
8825 /* Inline PRIMTYPE.TYPE read access */
8826 parm = maybe_build_primttype_type_ref (parm, wfl);
8828 TREE_VALUE (cn) = parm;
8830 ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
8834 /* Sometimes (for loops and variable initialized during their
8835 declaration), we want to wrap a statement around a WFL and turn it
8839 build_debugable_stmt (location, stmt)
8843 if (TREE_CODE (stmt) != EXPR_WITH_FILE_LOCATION)
8845 stmt = build_expr_wfl (stmt, input_filename, 0, 0);
8846 EXPR_WFL_LINECOL (stmt) = location;
8848 JAVA_MAYBE_GENERATE_DEBUG_INFO (stmt);
8853 build_expr_block (body, decls)
8856 tree node = make_node (BLOCK);
8857 BLOCK_EXPR_DECLS (node) = decls;
8858 BLOCK_EXPR_BODY (node) = body;
8860 TREE_TYPE (node) = TREE_TYPE (body);
8861 TREE_SIDE_EFFECTS (node) = 1;
8865 /* Create a new function block and link it approriately to current
8866 function block chain */
8871 return (enter_a_block (build_expr_block (NULL_TREE, NULL_TREE)));
8874 /* Link block B supercontext to the previous block. The current
8875 function DECL is used as supercontext when enter_a_block is called
8876 for the first time for a given function. The current function body
8877 (DECL_FUNCTION_BODY) is set to be block B. */
8883 tree fndecl = current_function_decl;
8886 BLOCK_SUPERCONTEXT (b) = current_static_block;
8887 current_static_block = b;
8890 else if (!DECL_FUNCTION_BODY (fndecl))
8892 BLOCK_SUPERCONTEXT (b) = fndecl;
8893 DECL_FUNCTION_BODY (fndecl) = b;
8897 BLOCK_SUPERCONTEXT (b) = DECL_FUNCTION_BODY (fndecl);
8898 DECL_FUNCTION_BODY (fndecl) = b;
8903 /* Exit a block by changing the current function body
8904 (DECL_FUNCTION_BODY) to the current block super context, only if
8905 the block being exited isn't the method's top level one. */
8911 if (current_function_decl)
8913 b = DECL_FUNCTION_BODY (current_function_decl);
8914 if (BLOCK_SUPERCONTEXT (b) != current_function_decl)
8915 DECL_FUNCTION_BODY (current_function_decl) = BLOCK_SUPERCONTEXT (b);
8919 b = current_static_block;
8921 if (BLOCK_SUPERCONTEXT (b))
8922 current_static_block = BLOCK_SUPERCONTEXT (b);
8927 /* Lookup for NAME in the nested function's blocks, all the way up to
8928 the current toplevel one. It complies with Java's local variable
8932 lookup_name_in_blocks (name)
8935 tree b = GET_CURRENT_BLOCK (current_function_decl);
8937 while (b != current_function_decl)
8941 /* Paranoid sanity check. To be removed */
8942 if (TREE_CODE (b) != BLOCK)
8943 fatal ("non block expr function body - lookup_name_in_blocks");
8945 for (current = BLOCK_EXPR_DECLS (b); current;
8946 current = TREE_CHAIN (current))
8947 if (DECL_NAME (current) == name)
8949 b = BLOCK_SUPERCONTEXT (b);
8955 maybe_absorb_scoping_blocks ()
8957 while (BLOCK_EXPR_ORIGIN (GET_CURRENT_BLOCK (current_function_decl)))
8959 tree b = exit_block ();
8960 java_method_add_stmt (current_function_decl, b);
8961 SOURCE_FRONTEND_DEBUG (("Absorbing scoping block at line %d", lineno));
8966 /* This section of the source is reserved to build_* functions that
8967 are building incomplete tree nodes and the patch_* functions that
8968 are completing them. */
8970 /* Build a super() constructor invocation. Returns empty_stmt_node if
8971 we're currently dealing with the class java.lang.Object. */
8974 build_super_invocation (mdecl)
8977 if (DECL_CONTEXT (mdecl) == object_type_node)
8978 return empty_stmt_node;
8981 tree super_wfl = build_wfl_node (super_identifier_node);
8982 return build_method_invocation (super_wfl, NULL_TREE);
8986 /* Build a SUPER/THIS qualified method invocation. */
8989 build_this_super_qualified_invocation (use_this, name, args, lloc, rloc)
8997 build_wfl_node (use_this ? this_identifier_node : super_identifier_node);
8998 EXPR_WFL_LINECOL (wfl) = lloc;
8999 invok = build_method_invocation (name, args);
9000 return make_qualified_primary (wfl, invok, rloc);
9003 /* Build an incomplete CALL_EXPR node. */
9006 build_method_invocation (name, args)
9010 tree call = build (CALL_EXPR, NULL_TREE, name, args, NULL_TREE);
9011 TREE_SIDE_EFFECTS (call) = 1;
9012 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
9016 /* Build an incomplete new xxx(...) node. */
9019 build_new_invocation (name, args)
9022 tree call = build (NEW_CLASS_EXPR, NULL_TREE, name, args, NULL_TREE);
9023 TREE_SIDE_EFFECTS (call) = 1;
9024 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
9028 /* Build an incomplete assignment expression. */
9031 build_assignment (op, op_location, lhs, rhs)
9032 int op, op_location;
9036 /* Build the corresponding binop if we deal with a Compound
9037 Assignment operator. Mark the binop sub-tree as part of a
9038 Compound Assignment expression */
9039 if (op != ASSIGN_TK)
9041 rhs = build_binop (BINOP_LOOKUP (op), op_location, lhs, rhs);
9042 COMPOUND_ASSIGN_P (rhs) = 1;
9044 assignment = build (MODIFY_EXPR, NULL_TREE, lhs, rhs);
9045 TREE_SIDE_EFFECTS (assignment) = 1;
9046 EXPR_WFL_LINECOL (assignment) = op_location;
9050 /* Print an INTEGER_CST node in a static buffer, and return the buffer. */
9053 print_int_node (node)
9056 static char buffer [80];
9057 if (TREE_CONSTANT_OVERFLOW (node))
9058 sprintf (buffer, "<overflow>");
9060 if (TREE_INT_CST_HIGH (node) == 0)
9061 sprintf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
9062 TREE_INT_CST_LOW (node));
9063 else if (TREE_INT_CST_HIGH (node) == -1
9064 && TREE_INT_CST_LOW (node) != 0)
9067 sprintf (&buffer [1], HOST_WIDE_INT_PRINT_UNSIGNED,
9068 -TREE_INT_CST_LOW (node));
9071 sprintf (buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
9072 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
9077 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
9081 check_final_assignment (lvalue, wfl)
9084 if (JDECL_P (lvalue)
9085 && FIELD_FINAL (lvalue) && !IS_CLINIT (current_function_decl))
9088 (wfl, "Can't assign a value to the final variable `%s'",
9089 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
9095 /* Inline references to java.lang.PRIMTYPE.TYPE when accessed in
9096 read. This is needed to avoid circularities in the implementation
9097 of these fields in libjava. */
9100 maybe_build_primttype_type_ref (rhs, wfl)
9103 tree to_return = NULL_TREE;
9104 tree rhs_type = TREE_TYPE (rhs);
9105 if (TREE_CODE (rhs) == COMPOUND_EXPR)
9107 tree n = TREE_OPERAND (rhs, 1);
9108 if (TREE_CODE (n) == VAR_DECL
9109 && DECL_NAME (n) == TYPE_identifier_node
9110 && rhs_type == class_ptr_type)
9112 const char *self_name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl));
9113 if (!strncmp (self_name, "java.lang.", 10))
9114 to_return = build_primtype_type_ref (self_name);
9117 return (to_return ? to_return : rhs );
9120 /* 15.25 Assignment operators. */
9123 patch_assignment (node, wfl_op1, wfl_op2)
9128 tree rhs = TREE_OPERAND (node, 1);
9129 tree lvalue = TREE_OPERAND (node, 0), llvalue;
9130 tree lhs_type = NULL_TREE, rhs_type, new_rhs = NULL_TREE;
9131 int error_found = 0;
9132 int lvalue_from_array = 0;
9134 /* Can't assign to a final. */
9135 if (check_final_assignment (lvalue, wfl_op1))
9138 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
9140 /* Lhs can be a named variable */
9141 if (JDECL_P (lvalue))
9143 lhs_type = TREE_TYPE (lvalue);
9145 /* Or Lhs can be a array acccess. Should that be lvalue ? FIXME +
9146 comment on reason why */
9147 else if (TREE_CODE (wfl_op1) == ARRAY_REF)
9149 lhs_type = TREE_TYPE (lvalue);
9150 lvalue_from_array = 1;
9152 /* Or a field access */
9153 else if (TREE_CODE (lvalue) == COMPONENT_REF)
9154 lhs_type = TREE_TYPE (lvalue);
9155 /* Or a function return slot */
9156 else if (TREE_CODE (lvalue) == RESULT_DECL)
9157 lhs_type = TREE_TYPE (lvalue);
9158 /* Otherwise, we might want to try to write into an optimized static
9159 final, this is an of a different nature, reported further on. */
9160 else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
9161 && resolve_expression_name (wfl_op1, &llvalue))
9163 if (check_final_assignment (llvalue, wfl_op1))
9165 /* What we should do instead is resetting the all the flags
9166 previously set, exchange lvalue for llvalue and continue. */
9168 return error_mark_node;
9171 lhs_type = TREE_TYPE (lvalue);
9175 parse_error_context (wfl_op1, "Invalid left hand side of assignment");
9179 rhs_type = TREE_TYPE (rhs);
9180 /* 5.1 Try the assignment conversion for builtin type. */
9181 new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
9183 /* 5.2 If it failed, try a reference conversion */
9184 if (!new_rhs && (new_rhs = try_reference_assignconv (lhs_type, rhs)))
9185 lhs_type = promote_type (rhs_type);
9187 /* 15.25.2 If we have a compound assignment, convert RHS into the
9189 else if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
9190 new_rhs = convert (lhs_type, rhs);
9192 /* Explicit cast required. This is an error */
9195 char *t1 = xstrdup (lang_printable_name (TREE_TYPE (rhs), 0));
9196 char *t2 = xstrdup (lang_printable_name (lhs_type, 0));
9198 char operation [32]; /* Max size known */
9200 /* If the assignment is part of a declaration, we use the WFL of
9201 the declared variable to point out the error and call it a
9202 declaration problem. If the assignment is a genuine =
9203 operator, we call is a operator `=' problem, otherwise we
9204 call it an assignment problem. In both of these last cases,
9205 we use the WFL of the operator to indicate the error. */
9207 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node))
9210 strcpy (operation, "declaration");
9215 if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
9216 strcpy (operation, "assignment");
9217 else if (TREE_CODE (TREE_OPERAND (node, 0)) == RESULT_DECL)
9218 strcpy (operation, "`return'");
9220 strcpy (operation, "`='");
9223 if (!valid_cast_to_p (rhs_type, lhs_type))
9225 (wfl, "Incompatible type for %s. Can't convert `%s' to `%s'",
9228 parse_error_context (wfl, "Incompatible type for %s. Explicit cast needed to convert `%s' to `%s'",
9230 free (t1); free (t2);
9234 /* Inline read access to java.lang.PRIMTYPE.TYPE */
9236 new_rhs = maybe_build_primttype_type_ref (new_rhs, wfl_op2);
9239 return error_mark_node;
9241 /* 10.10: Array Store Exception runtime check */
9242 if (!flag_emit_class_files
9244 && lvalue_from_array
9245 && JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type)))
9250 /* We need to retrieve the right argument for _Jv_CheckArrayStore */
9251 if (TREE_CODE (lvalue) == COMPOUND_EXPR)
9252 base = TREE_OPERAND (lvalue, 0);
9255 if (flag_bounds_check)
9256 base = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (base, 0), 1), 0);
9258 base = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
9261 /* Build the invocation of _Jv_CheckArrayStore */
9262 new_rhs = save_expr (new_rhs);
9263 check = build (CALL_EXPR, void_type_node,
9264 build_address_of (soft_checkarraystore_node),
9265 tree_cons (NULL_TREE, base,
9266 build_tree_list (NULL_TREE, new_rhs)),
9268 TREE_SIDE_EFFECTS (check) = 1;
9270 /* We have to decide on an insertion point */
9271 if (TREE_CODE (lvalue) == COMPOUND_EXPR)
9274 if (flag_bounds_check)
9276 t = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (lvalue, 1), 0), 0);
9277 TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (lvalue, 1), 0), 0) =
9278 build (COMPOUND_EXPR, void_type_node, t, check);
9281 TREE_OPERAND (lvalue, 1) = build (COMPOUND_EXPR, lhs_type,
9282 check, TREE_OPERAND (lvalue, 1));
9286 /* Make sure the bound check will happen before the store check */
9287 if (flag_bounds_check)
9288 TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0) =
9289 build (COMPOUND_EXPR, void_type_node,
9290 TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0), check);
9292 lvalue = build (COMPOUND_EXPR, lhs_type, check, lvalue);
9296 TREE_OPERAND (node, 0) = lvalue;
9297 TREE_OPERAND (node, 1) = new_rhs;
9298 TREE_TYPE (node) = lhs_type;
9302 /* Check that type SOURCE can be cast into type DEST. If the cast
9303 can't occur at all, return 0 otherwise 1. This function is used to
9304 produce accurate error messages on the reasons why an assignment
9308 try_reference_assignconv (lhs_type, rhs)
9311 tree new_rhs = NULL_TREE;
9312 tree rhs_type = TREE_TYPE (rhs);
9314 if (!JPRIMITIVE_TYPE_P (rhs_type) && JREFERENCE_TYPE_P (lhs_type))
9316 /* `null' may be assigned to any reference type */
9317 if (rhs == null_pointer_node)
9318 new_rhs = null_pointer_node;
9319 /* Try the reference assignment conversion */
9320 else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
9322 /* This is a magic assignment that we process differently */
9323 else if (rhs == soft_exceptioninfo_call_node)
9329 /* Check that RHS can be converted into LHS_TYPE by the assignment
9330 conversion (5.2), for the cases of RHS being a builtin type. Return
9331 NULL_TREE if the conversion fails or if because RHS isn't of a
9332 builtin type. Return a converted RHS if the conversion is possible. */
9335 try_builtin_assignconv (wfl_op1, lhs_type, rhs)
9336 tree wfl_op1, lhs_type, rhs;
9338 tree new_rhs = NULL_TREE;
9339 tree rhs_type = TREE_TYPE (rhs);
9341 /* Zero accepted everywhere */
9342 if (TREE_CODE (rhs) == INTEGER_CST
9343 && TREE_INT_CST_HIGH (rhs) == 0 && TREE_INT_CST_LOW (rhs) == 0
9344 && JPRIMITIVE_TYPE_P (rhs_type))
9345 new_rhs = convert (lhs_type, rhs);
9347 /* 5.1.1 Try Identity Conversion,
9348 5.1.2 Try Widening Primitive Conversion */
9349 else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
9350 new_rhs = convert (lhs_type, rhs);
9352 /* Try a narrowing primitive conversion (5.1.3):
9353 - expression is a constant expression of type int AND
9354 - variable is byte, short or char AND
9355 - The value of the expression is representable in the type of the
9357 else if (rhs_type == int_type_node && TREE_CONSTANT (rhs)
9358 && (lhs_type == byte_type_node || lhs_type == char_type_node
9359 || lhs_type == short_type_node))
9361 if (int_fits_type_p (rhs, lhs_type))
9362 new_rhs = convert (lhs_type, rhs);
9363 else if (wfl_op1) /* Might be called with a NULL */
9364 parse_warning_context
9365 (wfl_op1, "Constant expression `%s' to wide for narrowing primitive conversion to `%s'",
9366 print_int_node (rhs), lang_printable_name (lhs_type, 0));
9367 /* Reported a warning that will turn into an error further
9368 down, so we don't return */
9374 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
9375 conversion (5.1.1) or widening primitve conversion (5.1.2). Return
9376 0 is the conversion test fails. This implements parts the method
9377 invocation convertion (5.3). */
9380 valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type)
9381 tree lhs_type, rhs_type;
9383 /* 5.1.1: This is the identity conversion part. */
9384 if (lhs_type == rhs_type)
9387 /* Reject non primitive types */
9388 if (!JPRIMITIVE_TYPE_P (lhs_type) || !JPRIMITIVE_TYPE_P (rhs_type))
9391 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
9392 than a char can't be converted into a char. Short can't too, but
9393 the < test below takes care of that */
9394 if (lhs_type == char_type_node && rhs_type == byte_type_node)
9397 /* Accept all promoted type here. Note, we can't use <= in the test
9398 below, because we still need to bounce out assignments of short
9399 to char and the likes */
9400 if (lhs_type == int_type_node
9401 && (rhs_type == promoted_byte_type_node
9402 || rhs_type == promoted_short_type_node
9403 || rhs_type == promoted_char_type_node
9404 || rhs_type == promoted_boolean_type_node))
9407 /* From here, an integral is widened if its precision is smaller
9408 than the precision of the LHS or if the LHS is a floating point
9409 type, or the RHS is a float and the RHS a double. */
9410 if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type)
9411 && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
9412 || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
9413 || (rhs_type == float_type_node && lhs_type == double_type_node))
9419 /* Check that something of SOURCE type can be assigned or cast to
9420 something of DEST type at runtime. Return 1 if the operation is
9421 valid, 0 otherwise. If CAST is set to 1, we're treating the case
9422 were SOURCE is cast into DEST, which borrows a lot of the
9423 assignment check. */
9426 valid_ref_assignconv_cast_p (source, dest, cast)
9431 /* SOURCE or DEST might be null if not from a declared entity. */
9432 if (!source || !dest)
9434 if (JNULLP_TYPE_P (source))
9436 if (TREE_CODE (source) == POINTER_TYPE)
9437 source = TREE_TYPE (source);
9438 if (TREE_CODE (dest) == POINTER_TYPE)
9439 dest = TREE_TYPE (dest);
9440 /* Case where SOURCE is a class type */
9441 if (TYPE_CLASS_P (source))
9443 if (TYPE_CLASS_P (dest))
9444 return source == dest || inherits_from_p (source, dest)
9445 || (cast && inherits_from_p (dest, source));
9446 if (TYPE_INTERFACE_P (dest))
9448 /* If doing a cast and SOURCE is final, the operation is
9449 always correct a compile time (because even if SOURCE
9450 does not implement DEST, a subclass of SOURCE might). */
9451 if (cast && !CLASS_FINAL (TYPE_NAME (source)))
9453 /* Otherwise, SOURCE must implement DEST */
9454 return interface_of_p (dest, source);
9456 /* DEST is an array, cast permited if SOURCE is of Object type */
9457 return (cast && source == object_type_node ? 1 : 0);
9459 if (TYPE_INTERFACE_P (source))
9461 if (TYPE_CLASS_P (dest))
9463 /* If not casting, DEST must be the Object type */
9465 return dest == object_type_node;
9466 /* We're doing a cast. The cast is always valid is class
9467 DEST is not final, otherwise, DEST must implement SOURCE */
9468 else if (!CLASS_FINAL (TYPE_NAME (dest)))
9471 return interface_of_p (source, dest);
9473 if (TYPE_INTERFACE_P (dest))
9475 /* If doing a cast, then if SOURCE and DEST contain method
9476 with the same signature but different return type, then
9477 this is a (compile time) error */
9480 tree method_source, method_dest;
9484 for (method_source = TYPE_METHODS (source); method_source;
9485 method_source = TREE_CHAIN (method_source))
9488 build_java_argument_signature (TREE_TYPE (method_source));
9489 source_type = TREE_TYPE (TREE_TYPE (method_source));
9490 source_name = DECL_NAME (method_source);
9491 for (method_dest = TYPE_METHODS (dest);
9492 method_dest; method_dest = TREE_CHAIN (method_dest))
9494 build_java_argument_signature (TREE_TYPE (method_dest))
9495 && source_name == DECL_NAME (method_dest)
9496 && source_type != TREE_TYPE (TREE_TYPE (method_dest)))
9502 return source == dest || interface_of_p (dest, source);
9506 (DECL_NAME (TYPE_NAME (source)) == java_lang_cloneable) : 0);
9508 if (TYPE_ARRAY_P (source))
9510 if (TYPE_CLASS_P (dest))
9511 return dest == object_type_node;
9512 /* Can't cast an array to an interface unless the interface is
9513 java.lang.Cloneable */
9514 if (TYPE_INTERFACE_P (dest))
9515 return (DECL_NAME (TYPE_NAME (dest)) == java_lang_cloneable ? 1 : 0);
9518 tree source_element_type = TYPE_ARRAY_ELEMENT (source);
9519 tree dest_element_type = TYPE_ARRAY_ELEMENT (dest);
9521 /* In case of severe errors, they turn out null */
9522 if (!dest_element_type || !source_element_type)
9524 if (source_element_type == dest_element_type)
9526 return valid_ref_assignconv_cast_p (source_element_type,
9527 dest_element_type, cast);
9535 valid_cast_to_p (source, dest)
9539 if (TREE_CODE (source) == POINTER_TYPE)
9540 source = TREE_TYPE (source);
9541 if (TREE_CODE (dest) == POINTER_TYPE)
9542 dest = TREE_TYPE (dest);
9544 if (TREE_CODE (source) == RECORD_TYPE && TREE_CODE (dest) == RECORD_TYPE)
9545 return valid_ref_assignconv_cast_p (source, dest, 1);
9547 else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
9553 /* Method invocation conversion test. Return 1 if type SOURCE can be
9554 converted to type DEST through the methond invocation conversion
9558 do_unary_numeric_promotion (arg)
9561 tree type = TREE_TYPE (arg);
9562 if (TREE_CODE (type) == INTEGER_TYPE ? TYPE_PRECISION (type) < 32
9563 : TREE_CODE (type) == CHAR_TYPE)
9564 arg = convert (int_type_node, arg);
9568 /* Return a non zero value if SOURCE can be converted into DEST using
9569 the method invocation conversion rule (5.3). */
9571 valid_method_invocation_conversion_p (dest, source)
9574 return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
9575 && valid_builtin_assignconv_identity_widening_p (dest, source))
9576 || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
9577 && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
9578 && valid_ref_assignconv_cast_p (source, dest, 0)));
9581 /* Build an incomplete binop expression. */
9584 build_binop (op, op_location, op1, op2)
9589 tree binop = build (op, NULL_TREE, op1, op2);
9590 TREE_SIDE_EFFECTS (binop) = 1;
9591 /* Store the location of the operator, for better error report. The
9592 string of the operator will be rebuild based on the OP value. */
9593 EXPR_WFL_LINECOL (binop) = op_location;
9597 /* Build the string of the operator retained by NODE. If NODE is part
9598 of a compound expression, add an '=' at the end of the string. This
9599 function is called when an error needs to be reported on an
9600 operator. The string is returned as a pointer to a static character
9604 operator_string (node)
9607 #define BUILD_OPERATOR_STRING(S) \
9609 sprintf (buffer, "%s%s", S, (COMPOUND_ASSIGN_P (node) ? "=" : "")); \
9613 static char buffer [10];
9614 switch (TREE_CODE (node))
9616 case MULT_EXPR: BUILD_OPERATOR_STRING ("*");
9617 case RDIV_EXPR: BUILD_OPERATOR_STRING ("/");
9618 case TRUNC_MOD_EXPR: BUILD_OPERATOR_STRING ("%");
9619 case PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
9620 case MINUS_EXPR: BUILD_OPERATOR_STRING ("-");
9621 case LSHIFT_EXPR: BUILD_OPERATOR_STRING ("<<");
9622 case RSHIFT_EXPR: BUILD_OPERATOR_STRING (">>");
9623 case URSHIFT_EXPR: BUILD_OPERATOR_STRING (">>>");
9624 case BIT_AND_EXPR: BUILD_OPERATOR_STRING ("&");
9625 case BIT_XOR_EXPR: BUILD_OPERATOR_STRING ("^");
9626 case BIT_IOR_EXPR: BUILD_OPERATOR_STRING ("|");
9627 case TRUTH_ANDIF_EXPR: BUILD_OPERATOR_STRING ("&&");
9628 case TRUTH_ORIF_EXPR: BUILD_OPERATOR_STRING ("||");
9629 case EQ_EXPR: BUILD_OPERATOR_STRING ("==");
9630 case NE_EXPR: BUILD_OPERATOR_STRING ("!=");
9631 case GT_EXPR: BUILD_OPERATOR_STRING (">");
9632 case GE_EXPR: BUILD_OPERATOR_STRING (">=");
9633 case LT_EXPR: BUILD_OPERATOR_STRING ("<");
9634 case LE_EXPR: BUILD_OPERATOR_STRING ("<=");
9635 case UNARY_PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
9636 case NEGATE_EXPR: BUILD_OPERATOR_STRING ("-");
9637 case TRUTH_NOT_EXPR: BUILD_OPERATOR_STRING ("!");
9638 case BIT_NOT_EXPR: BUILD_OPERATOR_STRING ("~");
9639 case PREINCREMENT_EXPR: /* Fall through */
9640 case POSTINCREMENT_EXPR: BUILD_OPERATOR_STRING ("++");
9641 case PREDECREMENT_EXPR: /* Fall through */
9642 case POSTDECREMENT_EXPR: BUILD_OPERATOR_STRING ("--");
9644 fatal ("unregistered operator %s - operator_string",
9645 tree_code_name [TREE_CODE (node)]);
9648 #undef BUILD_OPERATOR_STRING
9651 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
9654 java_decl_equiv (var_acc1, var_acc2)
9655 tree var_acc1, var_acc2;
9657 if (JDECL_P (var_acc1))
9658 return (var_acc1 == var_acc2);
9660 return (TREE_CODE (var_acc1) == COMPONENT_REF
9661 && TREE_CODE (var_acc2) == COMPONENT_REF
9662 && TREE_OPERAND (TREE_OPERAND (var_acc1, 0), 0)
9663 == TREE_OPERAND (TREE_OPERAND (var_acc2, 0), 0)
9664 && TREE_OPERAND (var_acc1, 1) == TREE_OPERAND (var_acc2, 1));
9667 /* Return a non zero value if CODE is one of the operators that can be
9668 used in conjunction with the `=' operator in a compound assignment. */
9671 binop_compound_p (code)
9672 enum tree_code code;
9675 for (i = 0; i < BINOP_COMPOUND_CANDIDATES; i++)
9676 if (binop_lookup [i] == code)
9679 return i < BINOP_COMPOUND_CANDIDATES;
9682 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
9688 tree c, b, ns, decl;
9690 if (TREE_CODE (t) != MODIFY_EXPR)
9693 c = TREE_OPERAND (t, 1);
9694 if (! (c && TREE_CODE (c) == COMPOUND_EXPR
9695 && TREE_CODE (TREE_OPERAND (c, 0)) == MODIFY_EXPR
9696 && binop_compound_p (TREE_CODE (TREE_OPERAND (c, 1)))))
9699 /* Now the left branch of the binary operator. */
9700 b = TREE_OPERAND (TREE_OPERAND (c, 1), 0);
9701 if (! (b && TREE_CODE (b) == NOP_EXPR
9702 && TREE_CODE (TREE_OPERAND (b, 0)) == SAVE_EXPR))
9705 ns = TREE_OPERAND (TREE_OPERAND (b, 0), 0);
9706 if (! (ns && TREE_CODE (ns) == NOP_EXPR
9707 && TREE_CODE (TREE_OPERAND (ns, 0)) == SAVE_EXPR))
9710 decl = TREE_OPERAND (TREE_OPERAND (ns, 0), 0);
9711 if ((JDECL_P (decl) || TREE_CODE (decl) == COMPONENT_REF)
9712 /* It's got to be the an equivalent decl */
9713 && java_decl_equiv (decl, TREE_OPERAND (TREE_OPERAND (c, 0), 0)))
9715 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
9716 TREE_OPERAND (TREE_OPERAND (c, 1), 0) = TREE_OPERAND (ns, 0);
9717 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
9718 TREE_OPERAND (t, 1) = TREE_OPERAND (c, 1);
9719 /* Change the right part of the BINOP_EXPR */
9720 TREE_OPERAND (TREE_OPERAND (t, 1), 1) = TREE_OPERAND (c, 0);
9726 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
9727 errors but we modify NODE so that it contains the type computed
9728 according to the expression, when it's fixed. Otherwise, we write
9729 error_mark_node as the type. It allows us to further the analysis
9730 of remaining nodes and detects more errors in certain cases. */
9733 patch_binop (node, wfl_op1, wfl_op2)
9738 tree op1 = TREE_OPERAND (node, 0);
9739 tree op2 = TREE_OPERAND (node, 1);
9740 tree op1_type = TREE_TYPE (op1);
9741 tree op2_type = TREE_TYPE (op2);
9742 tree prom_type = NULL_TREE;
9743 int code = TREE_CODE (node);
9745 /* If 1, tell the routine that we have to return error_mark_node
9746 after checking for the initialization of the RHS */
9747 int error_found = 0;
9749 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
9753 /* 15.16 Multiplicative operators */
9754 case MULT_EXPR: /* 15.16.1 Multiplication Operator * */
9755 case RDIV_EXPR: /* 15.16.2 Division Operator / */
9756 case TRUNC_MOD_EXPR: /* 15.16.3 Remainder operator % */
9757 if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
9759 if (!JPRIMITIVE_TYPE_P (op1_type))
9760 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
9761 if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
9762 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
9763 TREE_TYPE (node) = error_mark_node;
9767 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9768 /* Change the division operator if necessary */
9769 if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
9770 TREE_SET_CODE (node, TRUNC_DIV_EXPR);
9772 if (TREE_CODE (prom_type) == INTEGER_TYPE
9773 && flag_use_divide_subroutine
9774 && ! flag_emit_class_files
9775 && (code == RDIV_EXPR || code == TRUNC_MOD_EXPR))
9776 return build_java_soft_divmod (TREE_CODE (node), prom_type, op1, op2);
9778 /* This one is more complicated. FLOATs are processed by a
9779 function call to soft_fmod. Duplicate the value of the
9780 COMPOUND_ASSIGN_P flag. */
9781 if (code == TRUNC_MOD_EXPR)
9783 tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
9784 COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
9785 TREE_SIDE_EFFECTS (mod)
9786 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
9791 /* 15.17 Additive Operators */
9792 case PLUS_EXPR: /* 15.17.1 String Concatenation Operator + */
9794 /* Operation is valid if either one argument is a string
9795 constant, a String object or a StringBuffer crafted for the
9796 purpose of the a previous usage of the String concatenation
9799 if (TREE_CODE (op1) == STRING_CST
9800 || TREE_CODE (op2) == STRING_CST
9801 || JSTRING_TYPE_P (op1_type)
9802 || JSTRING_TYPE_P (op2_type)
9803 || IS_CRAFTED_STRING_BUFFER_P (op1)
9804 || IS_CRAFTED_STRING_BUFFER_P (op2))
9805 return build_string_concatenation (op1, op2);
9807 case MINUS_EXPR: /* 15.17.2 Additive Operators (+ and -) for
9809 if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
9811 if (!JPRIMITIVE_TYPE_P (op1_type))
9812 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
9813 if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
9814 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
9815 TREE_TYPE (node) = error_mark_node;
9819 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9822 /* 15.18 Shift Operators */
9826 if (!JINTEGRAL_TYPE_P (op1_type) || !JINTEGRAL_TYPE_P (op2_type))
9828 if (!JINTEGRAL_TYPE_P (op1_type))
9829 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
9832 if (JPRIMITIVE_TYPE_P (op2_type))
9833 parse_error_context (wfl_operator,
9834 "Incompatible type for `%s'. Explicit cast needed to convert shift distance from `%s' to integral",
9835 operator_string (node),
9836 lang_printable_name (op2_type, 0));
9838 parse_error_context (wfl_operator,
9839 "Incompatible type for `%s'. Can't convert shift distance from `%s' to integral",
9840 operator_string (node),
9841 lang_printable_name (op2_type, 0));
9843 TREE_TYPE (node) = error_mark_node;
9848 /* Unary numeric promotion (5.6.1) is performed on each operand
9850 op1 = do_unary_numeric_promotion (op1);
9851 op2 = do_unary_numeric_promotion (op2);
9853 /* The type of the shift expression is the type of the promoted
9854 type of the left-hand operand */
9855 prom_type = TREE_TYPE (op1);
9857 /* Shift int only up to 0x1f and long up to 0x3f. The bytecode
9858 generator should take care of removing this operation. FIXME */
9859 op2 = fold (build (BIT_AND_EXPR, prom_type, convert (prom_type, op2),
9860 (prom_type == int_type_node ? build_int_2 (0x1f, 0) :
9861 convert (prom_type, build_int_2 (0x3f, 0)))));
9863 /* The >>> operator is a >> operating on unsigned quantities */
9864 if (code == URSHIFT_EXPR && ! flag_emit_class_files)
9867 tree utype = unsigned_type (prom_type);
9868 op1 = convert (utype, op1);
9869 TREE_SET_CODE (node, RSHIFT_EXPR);
9870 TREE_OPERAND (node, 0) = op1;
9871 TREE_OPERAND (node, 1) = op2;
9872 TREE_TYPE (node) = utype;
9873 to_return = convert (prom_type, node);
9874 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
9875 COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
9876 TREE_SIDE_EFFECTS (to_return)
9877 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
9882 /* 15.19.1 Type Comparison Operator instaceof */
9883 case INSTANCEOF_EXPR:
9885 TREE_TYPE (node) = boolean_type_node;
9887 if (!(op2_type = resolve_type_during_patch (op2)))
9888 return error_mark_node;
9890 /* The first operand must be a reference type or the null type */
9891 if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
9892 error_found = 1; /* Error reported further below */
9894 /* The second operand must be a reference type */
9895 if (!JREFERENCE_TYPE_P (op2_type))
9897 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
9899 (wfl_operator, "Invalid argument `%s' for `instanceof'",
9900 lang_printable_name (op2_type, 0));
9904 if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
9906 /* If the first operand is null, the result is always false */
9907 if (op1 == null_pointer_node)
9908 return boolean_false_node;
9909 else if (flag_emit_class_files)
9911 TREE_OPERAND (node, 1) = op2_type;
9912 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
9915 /* Otherwise we have to invoke instance of to figure it out */
9919 build (CALL_EXPR, boolean_type_node,
9920 build_address_of (soft_instanceof_node),
9923 build_tree_list (NULL_TREE,
9924 build_class_ref (op2_type))),
9926 TREE_SIDE_EFFECTS (call) = TREE_SIDE_EFFECTS (op1);
9930 /* There is no way the expression operand can be an instance of
9931 the type operand. This is a compile time error. */
9934 char *t1 = xstrdup (lang_printable_name (op1_type, 0));
9935 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
9937 (wfl_operator, "Impossible for `%s' to be instance of `%s'",
9938 t1, lang_printable_name (op2_type, 0));
9945 /* 15.21 Bitwise and Logical Operators */
9949 if (JINTEGRAL_TYPE_P (op1_type) && JINTEGRAL_TYPE_P (op2_type))
9950 /* Binary numeric promotion is performed on both operand and the
9951 expression retain that type */
9952 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9954 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE
9955 && TREE_CODE (op1_type) == BOOLEAN_TYPE)
9956 /* The type of the bitwise operator expression is BOOLEAN */
9957 prom_type = boolean_type_node;
9960 if (!JINTEGRAL_TYPE_P (op1_type))
9961 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
9962 if (!JINTEGRAL_TYPE_P (op2_type) && (op1_type != op2_type))
9963 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op2_type);
9964 TREE_TYPE (node) = error_mark_node;
9966 /* Insert a break here if adding thing before the switch's
9967 break for this case */
9971 /* 15.22 Conditional-And Operator */
9972 case TRUTH_ANDIF_EXPR:
9973 /* 15.23 Conditional-Or Operator */
9974 case TRUTH_ORIF_EXPR:
9975 /* Operands must be of BOOLEAN type */
9976 if (TREE_CODE (op1_type) != BOOLEAN_TYPE ||
9977 TREE_CODE (op2_type) != BOOLEAN_TYPE)
9979 if (TREE_CODE (op1_type) != BOOLEAN_TYPE)
9980 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op1_type);
9981 if (TREE_CODE (op2_type) != BOOLEAN_TYPE && (op1_type != op2_type))
9982 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op2_type);
9983 TREE_TYPE (node) = boolean_type_node;
9987 /* The type of the conditional operators is BOOLEAN */
9988 prom_type = boolean_type_node;
9991 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
9996 /* The type of each of the operands must be a primitive numeric
9998 if (!JNUMERIC_TYPE_P (op1_type) || ! JNUMERIC_TYPE_P (op2_type))
10000 if (!JNUMERIC_TYPE_P (op1_type))
10001 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
10002 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
10003 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
10004 TREE_TYPE (node) = boolean_type_node;
10008 /* Binary numeric promotion is performed on the operands */
10009 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
10010 /* The type of the relation expression is always BOOLEAN */
10011 prom_type = boolean_type_node;
10014 /* 15.20 Equality Operator */
10017 /* 15.20.1 Numerical Equality Operators == and != */
10018 /* Binary numeric promotion is performed on the operands */
10019 if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
10020 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
10022 /* 15.20.2 Boolean Equality Operators == and != */
10023 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE &&
10024 TREE_CODE (op2_type) == BOOLEAN_TYPE)
10025 ; /* Nothing to do here */
10027 /* 15.20.3 Reference Equality Operators == and != */
10028 /* Types have to be either references or the null type. If
10029 they're references, it must be possible to convert either
10030 type to the other by casting conversion. */
10031 else if (op1 == null_pointer_node || op2 == null_pointer_node
10032 || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
10033 && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
10034 || valid_ref_assignconv_cast_p (op2_type,
10036 ; /* Nothing to do here */
10038 /* Else we have an error figure what can't be converted into
10039 what and report the error */
10043 t1 = xstrdup (lang_printable_name (op1_type, 0));
10044 parse_error_context
10046 "Incompatible type for `%s'. Can't convert `%s' to `%s'",
10047 operator_string (node), t1,
10048 lang_printable_name (op2_type, 0));
10050 TREE_TYPE (node) = boolean_type_node;
10054 prom_type = boolean_type_node;
10059 return error_mark_node;
10061 TREE_OPERAND (node, 0) = op1;
10062 TREE_OPERAND (node, 1) = op2;
10063 TREE_TYPE (node) = prom_type;
10064 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
10066 if (flag_emit_xref)
10069 /* fold does not respect side-effect order as required for Java but not C.
10070 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
10073 if (flag_emit_class_files ? (TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
10074 : ! TREE_SIDE_EFFECTS (node))
10075 node = fold (node);
10079 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
10080 zero value, the value of CSTE comes after the valude of STRING */
10083 do_merge_string_cste (cste, string, string_len, after)
10085 const char *string;
10086 int string_len, after;
10088 int len = TREE_STRING_LENGTH (cste) + string_len;
10089 const char *old = TREE_STRING_POINTER (cste);
10090 TREE_STRING_LENGTH (cste) = len;
10091 TREE_STRING_POINTER (cste) = obstack_alloc (expression_obstack, len+1);
10094 strcpy (TREE_STRING_POINTER (cste), string);
10095 strcat (TREE_STRING_POINTER (cste), old);
10099 strcpy (TREE_STRING_POINTER (cste), old);
10100 strcat (TREE_STRING_POINTER (cste), string);
10105 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
10106 new STRING_CST on success, NULL_TREE on failure */
10109 merge_string_cste (op1, op2, after)
10113 /* Handle two string constants right away */
10114 if (TREE_CODE (op2) == STRING_CST)
10115 return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
10116 TREE_STRING_LENGTH (op2), after);
10118 /* Reasonable integer constant can be treated right away */
10119 if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
10121 static const char *boolean_true = "true";
10122 static const char *boolean_false = "false";
10123 static const char *null_pointer = "null";
10125 const char *string;
10127 if (op2 == boolean_true_node)
10128 string = boolean_true;
10129 else if (op2 == boolean_false_node)
10130 string = boolean_false;
10131 else if (op2 == null_pointer_node)
10132 string = null_pointer;
10133 else if (TREE_TYPE (op2) == char_type_node)
10135 ch[0] = (char )TREE_INT_CST_LOW (op2);
10140 string = print_int_node (op2);
10142 return do_merge_string_cste (op1, string, strlen (string), after);
10147 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
10148 has to be a STRING_CST and the other part must be a STRING_CST or a
10149 INTEGRAL constant. Return a new STRING_CST if the operation
10150 succeed, NULL_TREE otherwise.
10152 If the case we want to optimize for space, we might want to return
10153 NULL_TREE for each invocation of this routine. FIXME */
10156 string_constant_concatenation (op1, op2)
10159 if (TREE_CODE (op1) == STRING_CST || (TREE_CODE (op2) == STRING_CST))
10164 string = (TREE_CODE (op1) == STRING_CST ? op1 : op2);
10165 rest = (string == op1 ? op2 : op1);
10166 invert = (string == op1 ? 0 : 1 );
10168 /* Walk REST, only if it looks reasonable */
10169 if (TREE_CODE (rest) != STRING_CST
10170 && !IS_CRAFTED_STRING_BUFFER_P (rest)
10171 && !JSTRING_TYPE_P (TREE_TYPE (rest))
10172 && TREE_CODE (rest) == EXPR_WITH_FILE_LOCATION)
10174 rest = java_complete_tree (rest);
10175 if (rest == error_mark_node)
10176 return error_mark_node;
10177 rest = fold (rest);
10179 return merge_string_cste (string, rest, invert);
10184 /* Implement the `+' operator. Does static optimization if possible,
10185 otherwise create (if necessary) and append elements to a
10186 StringBuffer. The StringBuffer will be carried around until it is
10187 used for a function call or an assignment. Then toString() will be
10188 called on it to turn it into a String object. */
10191 build_string_concatenation (op1, op2)
10195 int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
10197 if (flag_emit_xref)
10198 return build (PLUS_EXPR, string_type_node, op1, op2);
10200 /* Try to do some static optimization */
10201 if ((result = string_constant_concatenation (op1, op2)))
10204 /* Discard empty strings on either side of the expression */
10205 if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
10210 else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
10213 /* If operands are string constant, turn then into object references */
10214 if (TREE_CODE (op1) == STRING_CST)
10215 op1 = patch_string_cst (op1);
10216 if (op2 && TREE_CODE (op2) == STRING_CST)
10217 op2 = patch_string_cst (op2);
10219 /* If either one of the constant is null and the other non null
10220 operand is a String object, return it. */
10221 if (JSTRING_TYPE_P (TREE_TYPE (op1)) && !op2)
10224 /* If OP1 isn't already a StringBuffer, create and
10225 initialize a new one */
10226 if (!IS_CRAFTED_STRING_BUFFER_P (op1))
10228 /* Two solutions here:
10229 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
10230 2) OP1 is something else, we call new StringBuffer().append(OP1). */
10231 if (TREE_CONSTANT (op1) && JSTRING_TYPE_P (TREE_TYPE (op1)))
10232 op1 = BUILD_STRING_BUFFER (op1);
10235 tree aNew = BUILD_STRING_BUFFER (NULL_TREE);
10236 op1 = make_qualified_primary (aNew, BUILD_APPEND (op1), 0);
10242 /* OP1 is no longer the last node holding a crafted StringBuffer */
10243 IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
10244 /* Create a node for `{new...,xxx}.append (op2)' */
10246 op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
10249 /* Mark the last node holding a crafted StringBuffer */
10250 IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
10252 TREE_SIDE_EFFECTS (op1) = side_effects;
10256 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
10257 StringBuffer. If no string were found to be patched, return
10261 patch_string (node)
10264 if (node == error_mark_node)
10265 return error_mark_node;
10266 if (TREE_CODE (node) == STRING_CST)
10267 return patch_string_cst (node);
10268 else if (IS_CRAFTED_STRING_BUFFER_P (node))
10270 int saved = ctxp->explicit_constructor_p;
10271 tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
10273 /* Temporary disable forbid the use of `this'. */
10274 ctxp->explicit_constructor_p = 0;
10275 ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
10276 /* Restore it at its previous value */
10277 ctxp->explicit_constructor_p = saved;
10283 /* Build the internal representation of a string constant. */
10286 patch_string_cst (node)
10290 if (! flag_emit_class_files)
10292 push_obstacks (&permanent_obstack, &permanent_obstack);
10293 node = get_identifier (TREE_STRING_POINTER (node));
10294 location = alloc_name_constant (CONSTANT_String, node);
10295 node = build_ref_from_constant_pool (location);
10298 TREE_TYPE (node) = string_ptr_type_node;
10299 TREE_CONSTANT (node) = 1;
10303 /* Build an incomplete unary operator expression. */
10306 build_unaryop (op_token, op_location, op1)
10307 int op_token, op_location;
10314 case PLUS_TK: op = UNARY_PLUS_EXPR; break;
10315 case MINUS_TK: op = NEGATE_EXPR; break;
10316 case NEG_TK: op = TRUTH_NOT_EXPR; break;
10317 case NOT_TK: op = BIT_NOT_EXPR; break;
10318 default: fatal ("Unknown token `%d' for unary operator - build_unaryop",
10322 unaryop = build1 (op, NULL_TREE, op1);
10323 TREE_SIDE_EFFECTS (unaryop) = 1;
10324 /* Store the location of the operator, for better error report. The
10325 string of the operator will be rebuild based on the OP value. */
10326 EXPR_WFL_LINECOL (unaryop) = op_location;
10330 /* Special case for the ++/-- operators, since they require an extra
10331 argument to build, which is set to NULL and patched
10332 later. IS_POST_P is 1 if the operator, 0 otherwise. */
10335 build_incdec (op_token, op_location, op1, is_post_p)
10336 int op_token, op_location;
10340 static enum tree_code lookup [2][2] =
10342 { PREDECREMENT_EXPR, PREINCREMENT_EXPR, },
10343 { POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, },
10345 tree node = build (lookup [is_post_p][(op_token - DECR_TK)],
10346 NULL_TREE, op1, NULL_TREE);
10347 TREE_SIDE_EFFECTS (node) = 1;
10348 /* Store the location of the operator, for better error report. The
10349 string of the operator will be rebuild based on the OP value. */
10350 EXPR_WFL_LINECOL (node) = op_location;
10354 /* Build an incomplete cast operator, based on the use of the
10355 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
10356 set. java_complete_tree is trained to walk a CONVERT_EXPR even
10357 though its type is already set. */
10360 build_cast (location, type, exp)
10364 tree node = build1 (CONVERT_EXPR, type, exp);
10365 EXPR_WFL_LINECOL (node) = location;
10369 /* 15.14 Unary operators. We return error_mark_node in case of error,
10370 but preserve the type of NODE if the type is fixed. */
10373 patch_unaryop (node, wfl_op)
10377 tree op = TREE_OPERAND (node, 0);
10378 tree op_type = TREE_TYPE (op);
10379 tree prom_type = NULL_TREE, value, decl;
10380 int code = TREE_CODE (node);
10381 int error_found = 0;
10383 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10387 /* 15.13.2 Postfix Increment Operator ++ */
10388 case POSTINCREMENT_EXPR:
10389 /* 15.13.3 Postfix Increment Operator -- */
10390 case POSTDECREMENT_EXPR:
10391 /* 15.14.1 Prefix Increment Operator ++ */
10392 case PREINCREMENT_EXPR:
10393 /* 15.14.2 Prefix Decrement Operator -- */
10394 case PREDECREMENT_EXPR:
10395 op = decl = strip_out_static_field_access_decl (op);
10396 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
10397 if (!JDECL_P (decl)
10398 && TREE_CODE (decl) != COMPONENT_REF
10399 && !(flag_emit_class_files && TREE_CODE (decl) == ARRAY_REF)
10400 && TREE_CODE (decl) != INDIRECT_REF
10401 && !(TREE_CODE (decl) == COMPOUND_EXPR
10402 && TREE_OPERAND (decl, 1)
10403 && (TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)))
10406 /* Before screaming, check that we're not in fact trying to
10407 increment a optimized static final access, in which case
10408 we issue an different error message. */
10409 if (!(TREE_CODE (wfl_op) == EXPR_WITH_FILE_LOCATION
10410 && resolve_expression_name (wfl_op, &lvalue)
10411 && check_final_assignment (lvalue, wfl_op)))
10412 parse_error_context (wfl_operator, "Invalid argument to `%s'",
10413 operator_string (node));
10414 TREE_TYPE (node) = error_mark_node;
10417 else if (check_final_assignment (op, wfl_op))
10420 /* From now on, we know that op if a variable and that it has a
10421 valid wfl. We use wfl_op to locate errors related to the
10423 else if (!JNUMERIC_TYPE_P (op_type))
10425 parse_error_context
10426 (wfl_op, "Invalid argument type `%s' to `%s'",
10427 lang_printable_name (op_type, 0), operator_string (node));
10428 TREE_TYPE (node) = error_mark_node;
10433 /* Before the addition, binary numeric promotion is performed on
10434 both operands, if really necessary */
10435 if (JINTEGRAL_TYPE_P (op_type))
10437 value = build_int_2 (1, 0);
10438 TREE_TYPE (value) = TREE_TYPE (node) = op_type;
10442 value = build_int_2 (1, 0);
10444 binary_numeric_promotion (op_type,
10445 TREE_TYPE (value), &op, &value);
10447 /* And write back into the node. */
10448 TREE_OPERAND (node, 0) = op;
10449 TREE_OPERAND (node, 1) = value;
10450 /* Convert the overall back into its original type, if
10451 necessary, and return */
10452 if (JINTEGRAL_TYPE_P (op_type))
10453 return fold (node);
10455 return fold (convert (op_type, node));
10459 /* 15.14.3 Unary Plus Operator + */
10460 case UNARY_PLUS_EXPR:
10461 /* 15.14.4 Unary Minus Operator - */
10463 if (!JNUMERIC_TYPE_P (op_type))
10465 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op_type);
10466 TREE_TYPE (node) = error_mark_node;
10469 /* Unary numeric promotion is performed on operand */
10472 op = do_unary_numeric_promotion (op);
10473 prom_type = TREE_TYPE (op);
10474 if (code == UNARY_PLUS_EXPR)
10479 /* 15.14.5 Bitwise Complement Operator ~ */
10481 if (!JINTEGRAL_TYPE_P (op_type))
10483 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op_type);
10484 TREE_TYPE (node) = error_mark_node;
10489 op = do_unary_numeric_promotion (op);
10490 prom_type = TREE_TYPE (op);
10494 /* 15.14.6 Logical Complement Operator ! */
10495 case TRUTH_NOT_EXPR:
10496 if (TREE_CODE (op_type) != BOOLEAN_TYPE)
10498 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
10499 /* But the type is known. We will report an error if further
10500 attempt of a assignment is made with this rhs */
10501 TREE_TYPE (node) = boolean_type_node;
10505 prom_type = boolean_type_node;
10508 /* 15.15 Cast Expression */
10510 value = patch_cast (node, wfl_operator);
10511 if (value == error_mark_node)
10513 /* If this cast is part of an assignment, we tell the code
10514 that deals with it not to complain about a mismatch,
10515 because things have been cast, anyways */
10516 TREE_TYPE (node) = error_mark_node;
10521 value = fold (value);
10522 TREE_SIDE_EFFECTS (value) = TREE_SIDE_EFFECTS (op);
10529 return error_mark_node;
10531 /* There are cases where node has been replaced by something else
10532 and we don't end up returning here: UNARY_PLUS_EXPR,
10533 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
10534 TREE_OPERAND (node, 0) = fold (op);
10535 TREE_TYPE (node) = prom_type;
10536 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
10537 return fold (node);
10540 /* Generic type resolution that sometimes takes place during node
10541 patching. Returned the resolved type or generate an error
10542 message. Return the resolved type or NULL_TREE. */
10545 resolve_type_during_patch (type)
10548 if (unresolved_type_p (type, NULL))
10550 tree type_decl = resolve_no_layout (EXPR_WFL_NODE (type), NULL_TREE);
10553 parse_error_context (type,
10554 "Class `%s' not found in type declaration",
10555 IDENTIFIER_POINTER (EXPR_WFL_NODE (type)));
10560 CLASS_LOADED_P (TREE_TYPE (type_decl)) = 1;
10561 return TREE_TYPE (type_decl);
10566 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
10567 found. Otherwise NODE or something meant to replace it is returned. */
10570 patch_cast (node, wfl_operator)
10574 tree op = TREE_OPERAND (node, 0);
10575 tree op_type = TREE_TYPE (op);
10576 tree cast_type = TREE_TYPE (node);
10579 /* First resolve OP_TYPE if unresolved */
10580 if (!(cast_type = resolve_type_during_patch (cast_type)))
10581 return error_mark_node;
10583 /* Check on cast that are proven correct at compile time */
10584 if (JNUMERIC_TYPE_P (cast_type) && JNUMERIC_TYPE_P (op_type))
10587 if (cast_type == op_type)
10590 /* float and double type are converted to the original type main
10591 variant and then to the target type. */
10592 if (JFLOAT_TYPE_P (op_type) && TREE_CODE (cast_type) == CHAR_TYPE)
10593 op = convert (integer_type_node, op);
10595 /* Try widening/narowwing convertion. Potentially, things need
10596 to be worked out in gcc so we implement the extreme cases
10597 correctly. fold_convert() needs to be fixed. */
10598 return convert (cast_type, op);
10601 /* It's also valid to cast a boolean into a boolean */
10602 if (op_type == boolean_type_node && cast_type == boolean_type_node)
10605 /* null can be casted to references */
10606 if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
10607 return build_null_of_type (cast_type);
10609 /* The remaining legal casts involve conversion between reference
10610 types. Check for their compile time correctness. */
10611 if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type)
10612 && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
10614 TREE_TYPE (node) = promote_type (cast_type);
10615 /* Now, the case can be determined correct at compile time if
10616 OP_TYPE can be converted into CAST_TYPE by assignment
10617 conversion (5.2) */
10619 if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
10621 TREE_SET_CODE (node, NOP_EXPR);
10625 if (flag_emit_class_files)
10627 TREE_SET_CODE (node, CONVERT_EXPR);
10631 /* The cast requires a run-time check */
10632 return build (CALL_EXPR, promote_type (cast_type),
10633 build_address_of (soft_checkcast_node),
10634 tree_cons (NULL_TREE, build_class_ref (cast_type),
10635 build_tree_list (NULL_TREE, op)),
10639 /* Any other casts are proven incorrect at compile time */
10640 t1 = xstrdup (lang_printable_name (op_type, 0));
10641 parse_error_context (wfl_operator, "Invalid cast from `%s' to `%s'",
10642 t1, lang_printable_name (cast_type, 0));
10644 return error_mark_node;
10647 /* Build a null constant and give it the type TYPE. */
10650 build_null_of_type (type)
10653 tree node = build_int_2 (0, 0);
10654 TREE_TYPE (node) = promote_type (type);
10658 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
10659 a list of indices. */
10661 build_array_ref (location, array, index)
10665 tree node = build (ARRAY_REF, NULL_TREE, array, index);
10666 EXPR_WFL_LINECOL (node) = location;
10670 /* 15.12 Array Access Expression */
10673 patch_array_ref (node)
10676 tree array = TREE_OPERAND (node, 0);
10677 tree array_type = TREE_TYPE (array);
10678 tree index = TREE_OPERAND (node, 1);
10679 tree index_type = TREE_TYPE (index);
10680 int error_found = 0;
10682 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10684 if (TREE_CODE (array_type) == POINTER_TYPE)
10685 array_type = TREE_TYPE (array_type);
10687 /* The array reference must be an array */
10688 if (!TYPE_ARRAY_P (array_type))
10690 parse_error_context
10692 "`[]' can only be applied to arrays. It can't be applied to `%s'",
10693 lang_printable_name (array_type, 0));
10694 TREE_TYPE (node) = error_mark_node;
10698 /* The array index underdoes unary numeric promotion. The promoted
10699 type must be int */
10700 index = do_unary_numeric_promotion (index);
10701 if (TREE_TYPE (index) != int_type_node)
10703 if (valid_cast_to_p (index_type, int_type_node))
10704 parse_error_context (wfl_operator,
10705 "Incompatible type for `[]'. Explicit cast needed to convert `%s' to `int'",
10706 lang_printable_name (index_type, 0));
10708 parse_error_context (wfl_operator,
10709 "Incompatible type for `[]'. Can't convert `%s' to `int'",
10710 lang_printable_name (index_type, 0));
10711 TREE_TYPE (node) = error_mark_node;
10716 return error_mark_node;
10718 array_type = TYPE_ARRAY_ELEMENT (array_type);
10720 if (flag_emit_class_files || flag_emit_xref)
10722 TREE_OPERAND (node, 0) = array;
10723 TREE_OPERAND (node, 1) = index;
10727 /* The save_expr is for correct evaluation order. It would be cleaner
10728 to use force_evaluation_order (see comment there), but that is
10729 difficult when we also have to deal with bounds checking. */
10730 if (TREE_SIDE_EFFECTS (index))
10731 array = save_expr (array);
10732 node = build_java_arrayaccess (array, array_type, index);
10733 if (TREE_SIDE_EFFECTS (index))
10734 node = build (COMPOUND_EXPR, array_type, array, node);
10736 TREE_TYPE (node) = array_type;
10740 /* 15.9 Array Creation Expressions */
10743 build_newarray_node (type, dims, extra_dims)
10749 build (NEW_ARRAY_EXPR, NULL_TREE, type, nreverse (dims),
10750 build_int_2 (extra_dims, 0));
10755 patch_newarray (node)
10758 tree type = TREE_OPERAND (node, 0);
10759 tree dims = TREE_OPERAND (node, 1);
10760 tree cdim, array_type;
10761 int error_found = 0;
10763 int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
10765 /* Dimension types are verified. It's better for the types to be
10766 verified in order. */
10767 for (cdim = dims, ndims = 0; cdim; cdim = TREE_CHAIN (cdim), ndims++ )
10770 tree dim = TREE_VALUE (cdim);
10772 /* Dim might have been saved during its evaluation */
10773 dim = (TREE_CODE (dim) == SAVE_EXPR ? dim = TREE_OPERAND (dim, 0) : dim);
10775 /* The type of each specified dimension must be an integral type. */
10776 if (!JINTEGRAL_TYPE_P (TREE_TYPE (dim)))
10779 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
10780 promoted type must be int. */
10783 dim = do_unary_numeric_promotion (dim);
10784 if (TREE_TYPE (dim) != int_type_node)
10788 /* Report errors on types here */
10791 parse_error_context
10792 (TREE_PURPOSE (cdim),
10793 "Incompatible type for dimension in array creation expression. %s convert `%s' to `int'",
10794 (valid_cast_to_p (TREE_TYPE (dim), int_type_node) ?
10795 "Explicit cast needed to" : "Can't"),
10796 lang_printable_name (TREE_TYPE (dim), 0));
10800 TREE_PURPOSE (cdim) = NULL_TREE;
10803 /* Resolve array base type if unresolved */
10804 if (!(type = resolve_type_during_patch (type)))
10809 /* We don't want further evaluation of this bogus array creation
10811 TREE_TYPE (node) = error_mark_node;
10812 return error_mark_node;
10815 /* Set array_type to the actual (promoted) array type of the result. */
10816 if (TREE_CODE (type) == RECORD_TYPE)
10817 type = build_pointer_type (type);
10818 while (--xdims >= 0)
10820 type = promote_type (build_java_array_type (type, -1));
10822 dims = nreverse (dims);
10824 for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
10828 = build_java_array_type (type,
10829 TREE_CODE (cdim) == INTEGER_CST
10830 ? (HOST_WIDE_INT) TREE_INT_CST_LOW (cdim)
10832 array_type = promote_type (array_type);
10834 dims = nreverse (dims);
10836 /* The node is transformed into a function call. Things are done
10837 differently according to the number of dimensions. If the number
10838 of dimension is equal to 1, then the nature of the base type
10839 (primitive or not) matters. */
10841 return build_new_array (type, TREE_VALUE (dims));
10843 /* Can't reuse what's already written in expr.c because it uses the
10844 JVM stack representation. Provide a build_multianewarray. FIXME */
10845 return build (CALL_EXPR, array_type,
10846 build_address_of (soft_multianewarray_node),
10847 tree_cons (NULL_TREE, build_class_ref (TREE_TYPE (array_type)),
10848 tree_cons (NULL_TREE,
10849 build_int_2 (ndims, 0), dims )),
10853 /* 10.6 Array initializer. */
10855 /* Build a wfl for array element that don't have one, so we can
10856 pin-point errors. */
10859 maybe_build_array_element_wfl (node)
10862 if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
10863 return build_expr_wfl (NULL_TREE, ctxp->filename,
10864 ctxp->elc.line, ctxp->elc.prev_col);
10869 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
10870 identification of initialized arrays easier to detect during walk
10874 build_new_array_init (location, values)
10878 tree constructor = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, values);
10879 tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
10880 EXPR_WFL_LINECOL (to_return) = location;
10884 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
10885 occurred. Otherwise return NODE after having set its type
10889 patch_new_array_init (type, node)
10892 int error_seen = 0;
10893 tree current, element_type;
10894 HOST_WIDE_INT length;
10895 int all_constant = 1;
10896 tree init = TREE_OPERAND (node, 0);
10898 if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
10900 parse_error_context (node,
10901 "Invalid array initializer for non-array type `%s'",
10902 lang_printable_name (type, 1));
10903 return error_mark_node;
10905 type = TREE_TYPE (type);
10906 element_type = TYPE_ARRAY_ELEMENT (type);
10908 CONSTRUCTOR_ELTS (init) = nreverse (CONSTRUCTOR_ELTS (init));
10910 for (length = 0, current = CONSTRUCTOR_ELTS (init);
10911 current; length++, current = TREE_CHAIN (current))
10913 tree elt = TREE_VALUE (current);
10914 if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
10916 error_seen |= array_constructor_check_entry (element_type, current);
10917 elt = TREE_VALUE (current);
10918 /* When compiling to native code, STRING_CST is converted to
10919 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
10920 if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
10925 TREE_VALUE (current) = patch_new_array_init (element_type, elt);
10926 TREE_PURPOSE (current) = NULL_TREE;
10929 if (elt && TREE_VALUE (elt) == error_mark_node)
10934 return error_mark_node;
10936 /* Create a new type. We can't reuse the one we have here by
10937 patching its dimension because it originally is of dimension -1
10938 hence reused by gcc. This would prevent triangular arrays. */
10939 type = build_java_array_type (element_type, length);
10940 TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
10941 TREE_TYPE (node) = promote_type (type);
10942 TREE_CONSTANT (init) = all_constant;
10943 TREE_CONSTANT (node) = all_constant;
10947 /* Verify that one entry of the initializer element list can be
10948 assigned to the array base type. Report 1 if an error occurred, 0
10952 array_constructor_check_entry (type, entry)
10955 char *array_type_string = NULL; /* For error reports */
10956 tree value, type_value, new_value, wfl_value, patched;
10957 int error_seen = 0;
10959 new_value = NULL_TREE;
10960 wfl_value = TREE_VALUE (entry);
10962 push_obstacks (&permanent_obstack, &permanent_obstack);
10963 value = java_complete_tree (TREE_VALUE (entry));
10964 /* patch_string return error_mark_node if arg is error_mark_node */
10965 if ((patched = patch_string (value)))
10967 if (value == error_mark_node)
10970 type_value = TREE_TYPE (value);
10972 /* At anytime, try_builtin_assignconv can report a warning on
10973 constant overflow during narrowing. */
10974 SET_WFL_OPERATOR (wfl_operator, TREE_PURPOSE (entry), wfl_value);
10975 new_value = try_builtin_assignconv (wfl_operator, type, value);
10976 if (!new_value && (new_value = try_reference_assignconv (type, value)))
10977 type_value = promote_type (type);
10980 /* Check and report errors */
10983 const char *msg = (!valid_cast_to_p (type_value, type) ?
10984 "Can't" : "Explicit cast needed to");
10985 if (!array_type_string)
10986 array_type_string = xstrdup (lang_printable_name (type, 1));
10987 parse_error_context
10988 (wfl_operator, "Incompatible type for array. %s convert `%s' to `%s'",
10989 msg, lang_printable_name (type_value, 1), array_type_string);
10995 new_value = maybe_build_primttype_type_ref (new_value, wfl_operator);
10996 TREE_VALUE (entry) = new_value;
10999 if (array_type_string)
11000 free (array_type_string);
11002 TREE_PURPOSE (entry) = NULL_TREE;
11007 build_this (location)
11010 tree node = build_wfl_node (this_identifier_node);
11011 TREE_SET_CODE (node, THIS_EXPR);
11012 EXPR_WFL_LINECOL (node) = location;
11016 /* 14.15 The return statement. It builds a modify expression that
11017 assigns the returned value to the RESULT_DECL that hold the value
11021 build_return (location, op)
11025 tree node = build1 (RETURN_EXPR, NULL_TREE, op);
11026 EXPR_WFL_LINECOL (node) = location;
11027 node = build_debugable_stmt (location, node);
11032 patch_return (node)
11035 tree return_exp = TREE_OPERAND (node, 0);
11036 tree meth = current_function_decl;
11037 tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
11038 int error_found = 0;
11040 TREE_TYPE (node) = error_mark_node;
11041 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11043 /* It's invalid to have a return value within a function that is
11044 declared with the keyword void or that is a constructor */
11045 if (return_exp && (mtype == void_type_node || DECL_CONSTRUCTOR_P (meth)))
11048 /* It's invalid to use a return statement in a static block */
11049 if (IS_CLINIT (current_function_decl))
11052 /* It's invalid to have a no return value within a function that
11053 isn't declared with the keyword `void' */
11054 if (!return_exp && (mtype != void_type_node && !DECL_CONSTRUCTOR_P (meth)))
11059 if (IS_CLINIT (current_function_decl))
11060 parse_error_context (wfl_operator,
11061 "`return' inside static initializer.");
11063 else if (!DECL_CONSTRUCTOR_P (meth))
11065 char *t = xstrdup (lang_printable_name (mtype, 0));
11066 parse_error_context (wfl_operator,
11067 "`return' with%s value from `%s %s'",
11068 (error_found == 1 ? "" : "out"),
11069 t, lang_printable_name (meth, 0));
11073 parse_error_context (wfl_operator,
11074 "`return' with value from constructor `%s'",
11075 lang_printable_name (meth, 0));
11076 return error_mark_node;
11079 /* If we have a return_exp, build a modify expression and expand
11080 it. Note: at that point, the assignment is declared valid, but we
11081 may want to carry some more hacks */
11084 tree exp = java_complete_tree (return_exp);
11085 tree modify, patched;
11087 /* If the function returned value and EXP are booleans, EXP has
11088 to be converted into the type of DECL_RESULT, which is integer
11089 (see complete_start_java_method) */
11090 if (TREE_TYPE (exp) == boolean_type_node &&
11091 TREE_TYPE (TREE_TYPE (meth)) == boolean_type_node)
11092 exp = convert_to_integer (TREE_TYPE (DECL_RESULT (meth)), exp);
11094 /* `null' can be assigned to a function returning a reference */
11095 if (JREFERENCE_TYPE_P (TREE_TYPE (TREE_TYPE (meth))) &&
11096 exp == null_pointer_node)
11097 exp = build_null_of_type (TREE_TYPE (TREE_TYPE (meth)));
11099 if ((patched = patch_string (exp)))
11102 modify = build (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
11103 EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
11104 modify = java_complete_tree (modify);
11106 if (modify != error_mark_node)
11108 TREE_SIDE_EFFECTS (modify) = 1;
11109 TREE_OPERAND (node, 0) = modify;
11112 return error_mark_node;
11114 TREE_TYPE (node) = void_type_node;
11115 TREE_SIDE_EFFECTS (node) = 1;
11119 /* 14.8 The if Statement */
11122 build_if_else_statement (location, expression, if_body, else_body)
11124 tree expression, if_body, else_body;
11128 else_body = empty_stmt_node;
11129 node = build (COND_EXPR, NULL_TREE, expression, if_body, else_body);
11130 EXPR_WFL_LINECOL (node) = location;
11131 node = build_debugable_stmt (location, node);
11136 patch_if_else_statement (node)
11139 tree expression = TREE_OPERAND (node, 0);
11141 TREE_TYPE (node) = error_mark_node;
11142 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11144 /* The type of expression must be boolean */
11145 if (TREE_TYPE (expression) != boolean_type_node
11146 && TREE_TYPE (expression) != promoted_boolean_type_node)
11148 parse_error_context
11150 "Incompatible type for `if'. Can't convert `%s' to `boolean'",
11151 lang_printable_name (TREE_TYPE (expression), 0));
11152 return error_mark_node;
11155 TREE_TYPE (node) = void_type_node;
11156 TREE_SIDE_EFFECTS (node) = 1;
11157 CAN_COMPLETE_NORMALLY (node)
11158 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
11159 | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2));
11163 /* 14.6 Labeled Statements */
11165 /* Action taken when a lableled statement is parsed. a new
11166 LABELED_BLOCK_EXPR is created. No statement is attached to the
11167 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
11170 build_labeled_block (location, label)
11175 tree label_decl, node;
11176 if (label == NULL_TREE || label == continue_identifier_node)
11177 label_name = label;
11180 label_name = merge_qualified_name (label_id, label);
11181 /* Issue an error if we try to reuse a label that was previously
11183 if (IDENTIFIER_LOCAL_VALUE (label_name))
11185 EXPR_WFL_LINECOL (wfl_operator) = location;
11186 parse_error_context (wfl_operator,
11187 "Declaration of `%s' shadows a previous label declaration",
11188 IDENTIFIER_POINTER (label));
11189 EXPR_WFL_LINECOL (wfl_operator) =
11190 EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
11191 parse_error_context (wfl_operator,
11192 "This is the location of the previous declaration of label `%s'",
11193 IDENTIFIER_POINTER (label));
11194 java_error_count--;
11198 label_decl = create_label_decl (label_name);
11199 node = build (LABELED_BLOCK_EXPR, NULL_TREE, label_decl, NULL_TREE);
11200 EXPR_WFL_LINECOL (node) = location;
11201 TREE_SIDE_EFFECTS (node) = 1;
11205 /* A labeled statement LBE is attached a statement. */
11208 finish_labeled_statement (lbe, statement)
11209 tree lbe; /* Labeled block expr */
11212 /* In anyways, tie the loop to its statement */
11213 LABELED_BLOCK_BODY (lbe) = statement;
11214 pop_labeled_block ();
11215 POP_LABELED_BLOCK ();
11219 /* 14.10, 14.11, 14.12 Loop Statements */
11221 /* Create an empty LOOP_EXPR and make it the last in the nested loop
11225 build_new_loop (loop_body)
11228 tree loop = build (LOOP_EXPR, NULL_TREE, loop_body);
11229 TREE_SIDE_EFFECTS (loop) = 1;
11234 /* Create a loop body according to the following structure:
11236 COMPOUND_EXPR (loop main body)
11237 EXIT_EXPR (this order is for while/for loops.
11238 LABELED_BLOCK_EXPR the order is reversed for do loops)
11239 LABEL_DECL (a continue occuring here branches at the
11240 BODY end of this labeled block)
11243 REVERSED, if non zero, tells that the loop condition expr comes
11244 after the body, like in the do-while loop.
11246 To obtain a loop, the loop body structure described above is
11247 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
11250 LABEL_DECL (use this label to exit the loop)
11252 <structure described above> */
11255 build_loop_body (location, condition, reversed)
11260 tree first, second, body;
11262 condition = build (EXIT_EXPR, NULL_TREE, condition); /* Force walk */
11263 EXPR_WFL_LINECOL (condition) = location; /* For accurate error report */
11264 condition = build_debugable_stmt (location, condition);
11265 TREE_SIDE_EFFECTS (condition) = 1;
11267 body = build_labeled_block (0, continue_identifier_node);
11268 first = (reversed ? body : condition);
11269 second = (reversed ? condition : body);
11271 build (COMPOUND_EXPR, NULL_TREE,
11272 build (COMPOUND_EXPR, NULL_TREE, first, second), empty_stmt_node);
11275 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
11276 their order) on the current loop. Unlink the current loop from the
11280 finish_loop_body (location, condition, body, reversed)
11282 tree condition, body;
11285 tree to_return = ctxp->current_loop;
11286 tree loop_body = LOOP_EXPR_BODY (to_return);
11289 tree cnode = LOOP_EXPR_BODY_CONDITION_EXPR (loop_body, reversed);
11290 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
11291 The real EXIT_EXPR is one operand further. */
11292 EXPR_WFL_LINECOL (cnode) = location;
11293 /* This one is for accurate error reports */
11294 EXPR_WFL_LINECOL (TREE_OPERAND (cnode, 0)) = location;
11295 TREE_OPERAND (TREE_OPERAND (cnode, 0), 0) = condition;
11297 LOOP_EXPR_BODY_BODY_EXPR (loop_body, reversed) = body;
11302 /* Tailored version of finish_loop_body for FOR loops, when FOR
11303 loops feature the condition part */
11306 finish_for_loop (location, condition, update, body)
11308 tree condition, update, body;
11310 /* Put the condition and the loop body in place */
11311 tree loop = finish_loop_body (location, condition, body, 0);
11312 /* LOOP is the current loop which has been now popped of the loop
11313 stack. Install the update block */
11314 LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
11318 /* Try to find the loop a block might be related to. This comprises
11319 the case where the LOOP_EXPR is found as the second operand of a
11320 COMPOUND_EXPR, because the loop happens to have an initialization
11321 part, then expressed as the first operand of the COMPOUND_EXPR. If
11322 the search finds something, 1 is returned. Otherwise, 0 is
11323 returned. The search is assumed to start from a
11324 LABELED_BLOCK_EXPR's block. */
11327 search_loop (statement)
11330 if (TREE_CODE (statement) == LOOP_EXPR)
11333 if (TREE_CODE (statement) == BLOCK)
11334 statement = BLOCK_SUBBLOCKS (statement);
11338 if (statement && TREE_CODE (statement) == COMPOUND_EXPR)
11339 while (statement && TREE_CODE (statement) == COMPOUND_EXPR)
11340 statement = TREE_OPERAND (statement, 1);
11342 return (TREE_CODE (statement) == LOOP_EXPR
11343 && IS_FOR_LOOP_P (statement) ? statement : NULL_TREE);
11346 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
11347 returned otherwise. */
11350 labeled_block_contains_loop_p (block, loop)
11356 if (LABELED_BLOCK_BODY (block) == loop)
11359 if (IS_FOR_LOOP_P (loop)
11360 && search_loop (LABELED_BLOCK_BODY (block)) == loop)
11366 /* If the loop isn't surrounded by a labeled statement, create one and
11367 insert LOOP as its body. */
11370 patch_loop_statement (loop)
11375 TREE_TYPE (loop) = void_type_node;
11376 if (labeled_block_contains_loop_p (ctxp->current_labeled_block, loop))
11379 loop_label = build_labeled_block (0, NULL_TREE);
11380 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
11381 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
11382 LABELED_BLOCK_BODY (loop_label) = loop;
11383 PUSH_LABELED_BLOCK (loop_label);
11387 /* 14.13, 14.14: break and continue Statements */
11389 /* Build a break or a continue statement. a null NAME indicates an
11390 unlabeled break/continue statement. */
11393 build_bc_statement (location, is_break, name)
11394 int location, is_break;
11397 tree break_continue, label_block_expr = NULL_TREE;
11401 if (!(label_block_expr = IDENTIFIER_LOCAL_VALUE
11402 (merge_qualified_name (label_id, EXPR_WFL_NODE (name)))))
11403 /* Null means that we don't have a target for this named
11404 break/continue. In this case, we make the target to be the
11405 label name, so that the error can be reported accuratly in
11406 patch_bc_statement. */
11407 label_block_expr = EXPR_WFL_NODE (name);
11409 /* Unlabeled break/continue will be handled during the
11410 break/continue patch operation */
11412 = build (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr, NULL_TREE);
11414 IS_BREAK_STMT_P (break_continue) = is_break;
11415 TREE_SIDE_EFFECTS (break_continue) = 1;
11416 EXPR_WFL_LINECOL (break_continue) = location;
11417 break_continue = build_debugable_stmt (location, break_continue);
11418 return break_continue;
11421 /* Verification of a break/continue statement. */
11424 patch_bc_statement (node)
11427 tree bc_label = EXIT_BLOCK_LABELED_BLOCK (node), target_stmt;
11428 tree labeled_block = ctxp->current_labeled_block;
11429 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11431 /* Having an identifier here means that the target is unknown. */
11432 if (bc_label != NULL_TREE && TREE_CODE (bc_label) == IDENTIFIER_NODE)
11434 parse_error_context (wfl_operator, "No label definition found for `%s'",
11435 IDENTIFIER_POINTER (bc_label));
11436 return error_mark_node;
11438 if (! IS_BREAK_STMT_P (node))
11440 /* It's a continue statement. */
11441 for (;; labeled_block = TREE_CHAIN (labeled_block))
11443 if (labeled_block == NULL_TREE)
11445 if (bc_label == NULL_TREE)
11446 parse_error_context (wfl_operator,
11447 "`continue' must be in loop");
11449 parse_error_context
11450 (wfl_operator, "continue label `%s' does not name a loop",
11451 IDENTIFIER_POINTER (bc_label));
11452 return error_mark_node;
11454 if ((DECL_NAME (LABELED_BLOCK_LABEL (labeled_block))
11455 == continue_identifier_node)
11456 && (bc_label == NULL_TREE
11457 || TREE_CHAIN (labeled_block) == bc_label))
11459 bc_label = labeled_block;
11464 else if (!bc_label)
11466 for (;; labeled_block = TREE_CHAIN (labeled_block))
11468 if (labeled_block == NULL_TREE)
11470 parse_error_context (wfl_operator,
11471 "`break' must be in loop or switch");
11472 return error_mark_node;
11474 target_stmt = LABELED_BLOCK_BODY (labeled_block);
11475 if (TREE_CODE (target_stmt) == SWITCH_EXPR
11476 || search_loop (target_stmt))
11478 bc_label = labeled_block;
11484 EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
11485 CAN_COMPLETE_NORMALLY (bc_label) = 1;
11487 /* Our break/continue don't return values. */
11488 TREE_TYPE (node) = void_type_node;
11489 /* Encapsulate the break within a compound statement so that it's
11490 expanded all the times by expand_expr (and not clobbered
11491 sometimes, like after a if statement) */
11492 node = add_stmt_to_compound (NULL_TREE, void_type_node, node);
11493 TREE_SIDE_EFFECTS (node) = 1;
11497 /* Process the exit expression belonging to a loop. Its type must be
11501 patch_exit_expr (node)
11504 tree expression = TREE_OPERAND (node, 0);
11505 TREE_TYPE (node) = error_mark_node;
11506 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11508 /* The type of expression must be boolean */
11509 if (TREE_TYPE (expression) != boolean_type_node)
11511 parse_error_context
11513 "Incompatible type for loop conditional. Can't convert `%s' to `boolean'",
11514 lang_printable_name (TREE_TYPE (expression), 0));
11515 return error_mark_node;
11517 /* Now we know things are allright, invert the condition, fold and
11519 TREE_OPERAND (node, 0) =
11520 fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
11522 if (! integer_zerop (TREE_OPERAND (node, 0))
11523 && ctxp->current_loop != NULL_TREE
11524 && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
11525 CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
11526 if (! integer_onep (TREE_OPERAND (node, 0)))
11527 CAN_COMPLETE_NORMALLY (node) = 1;
11530 TREE_TYPE (node) = void_type_node;
11534 /* 14.9 Switch statement */
11537 patch_switch_statement (node)
11540 tree se = TREE_OPERAND (node, 0), se_type;
11542 /* Complete the switch expression */
11543 se = TREE_OPERAND (node, 0) = java_complete_tree (se);
11544 se_type = TREE_TYPE (se);
11545 /* The type of the switch expression must be char, byte, short or
11547 if (!JINTEGRAL_TYPE_P (se_type))
11549 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11550 parse_error_context (wfl_operator,
11551 "Incompatible type for `switch'. Can't convert `%s' to `int'",
11552 lang_printable_name (se_type, 0));
11553 /* This is what java_complete_tree will check */
11554 TREE_OPERAND (node, 0) = error_mark_node;
11555 return error_mark_node;
11558 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
11560 /* Ready to return */
11561 if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
11563 TREE_TYPE (node) = error_mark_node;
11564 return error_mark_node;
11566 TREE_TYPE (node) = void_type_node;
11567 TREE_SIDE_EFFECTS (node) = 1;
11568 CAN_COMPLETE_NORMALLY (node)
11569 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
11570 || ! SWITCH_HAS_DEFAULT (node);
11574 /* 14.18 The try statement */
11577 build_try_statement (location, try_block, catches)
11579 tree try_block, catches;
11581 tree node = build (TRY_EXPR, NULL_TREE, try_block, catches);
11582 EXPR_WFL_LINECOL (node) = location;
11587 build_try_finally_statement (location, try_block, finally)
11589 tree try_block, finally;
11591 tree node = build (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
11592 EXPR_WFL_LINECOL (node) = location;
11597 patch_try_statement (node)
11600 int error_found = 0;
11601 tree try = TREE_OPERAND (node, 0);
11602 /* Exception handlers are considered in left to right order */
11603 tree catch = nreverse (TREE_OPERAND (node, 1));
11604 tree current, caught_type_list = NULL_TREE;
11606 /* Check catch clauses, if any. Every time we find an error, we try
11607 to process the next catch clause. We process the catch clause before
11608 the try block so that when processing the try block we can check thrown
11609 exceptions againts the caught type list. */
11610 for (current = catch; current; current = TREE_CHAIN (current))
11612 tree carg_decl, carg_type;
11613 tree sub_current, catch_block, catch_clause;
11616 /* At this point, the structure of the catch clause is
11617 CATCH_EXPR (catch node)
11618 BLOCK (with the decl of the parameter)
11620 MODIFY_EXPR (assignment of the catch parameter)
11621 BLOCK (catch clause block)
11623 catch_clause = TREE_OPERAND (current, 0);
11624 carg_decl = BLOCK_EXPR_DECLS (catch_clause);
11625 carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
11627 /* Catch clauses can't have more than one parameter declared,
11628 but it's already enforced by the grammar. Make sure that the
11629 only parameter of the clause statement in of class Throwable
11630 or a subclass of Throwable, but that was done earlier. The
11631 catch clause parameter type has also been resolved. */
11633 /* Just make sure that the catch clause parameter type inherits
11634 from java.lang.Throwable */
11635 if (!inherits_from_p (carg_type, throwable_type_node))
11637 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
11638 parse_error_context (wfl_operator,
11639 "Can't catch class `%s'. Catch clause parameter type must be a subclass of class `java.lang.Throwable'",
11640 lang_printable_name (carg_type, 0));
11645 /* Partial check for unreachable catch statement: The catch
11646 clause is reachable iff is no earlier catch block A in
11647 the try statement such that the type of the catch
11648 clause's parameter is the same as or a subclass of the
11649 type of A's parameter */
11651 for (sub_current = catch;
11652 sub_current != current; sub_current = TREE_CHAIN (sub_current))
11654 tree sub_catch_clause, decl;
11655 sub_catch_clause = TREE_OPERAND (sub_current, 0);
11656 decl = BLOCK_EXPR_DECLS (sub_catch_clause);
11658 if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
11660 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
11661 parse_error_context
11663 "`catch' not reached because of the catch clause at line %d",
11664 EXPR_WFL_LINENO (sub_current));
11665 unreachable = error_found = 1;
11669 /* Complete the catch clause block */
11670 catch_block = java_complete_tree (TREE_OPERAND (current, 0));
11671 if (catch_block == error_mark_node)
11676 if (CAN_COMPLETE_NORMALLY (catch_block))
11677 CAN_COMPLETE_NORMALLY (node) = 1;
11678 TREE_OPERAND (current, 0) = catch_block;
11683 /* Things to do here: the exception must be thrown */
11685 /* Link this type to the caught type list */
11686 caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
11689 PUSH_EXCEPTIONS (caught_type_list);
11690 if ((try = java_complete_tree (try)) == error_mark_node)
11692 if (CAN_COMPLETE_NORMALLY (try))
11693 CAN_COMPLETE_NORMALLY (node) = 1;
11696 /* Verification ends here */
11698 return error_mark_node;
11700 TREE_OPERAND (node, 0) = try;
11701 TREE_OPERAND (node, 1) = catch;
11702 TREE_TYPE (node) = void_type_node;
11706 /* 14.17 The synchronized Statement */
11709 patch_synchronized_statement (node, wfl_op1)
11710 tree node, wfl_op1;
11712 tree expr = java_complete_tree (TREE_OPERAND (node, 0));
11713 tree block = TREE_OPERAND (node, 1);
11715 tree enter, exit, expr_decl, assignment;
11717 if (expr == error_mark_node)
11719 block = java_complete_tree (block);
11723 /* The TYPE of expr must be a reference type */
11724 if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
11726 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11727 parse_error_context (wfl_operator, "Incompatible type for `synchronized'. Can't convert `%s' to `java.lang.Object'",
11728 lang_printable_name (TREE_TYPE (expr), 0));
11729 return error_mark_node;
11732 if (flag_emit_xref)
11734 TREE_OPERAND (node, 0) = expr;
11735 TREE_OPERAND (node, 1) = java_complete_tree (block);
11736 CAN_COMPLETE_NORMALLY (node) = 1;
11740 /* Generate a try-finally for the synchronized statement, except
11741 that the handler that catches all throw exception calls
11742 _Jv_MonitorExit and then rethrow the exception.
11743 The synchronized statement is then implemented as:
11746 _Jv_MonitorEnter (expression)
11748 _Jv_MonitorExit (expression)
11752 e = _Jv_exception_info ();
11753 _Jv_MonitorExit (expression)
11757 expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
11758 BUILD_MONITOR_ENTER (enter, expr_decl);
11759 BUILD_MONITOR_EXIT (exit, expr_decl);
11760 CAN_COMPLETE_NORMALLY (enter) = 1;
11761 CAN_COMPLETE_NORMALLY (exit) = 1;
11762 assignment = build (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
11763 TREE_SIDE_EFFECTS (assignment) = 1;
11764 node = build1 (CLEANUP_POINT_EXPR, NULL_TREE,
11765 build (COMPOUND_EXPR, NULL_TREE,
11766 build (WITH_CLEANUP_EXPR, NULL_TREE,
11767 build (COMPOUND_EXPR, NULL_TREE,
11768 assignment, enter),
11771 node = build_expr_block (node, expr_decl);
11773 return java_complete_tree (node);
11776 /* 14.16 The throw Statement */
11779 patch_throw_statement (node, wfl_op1)
11780 tree node, wfl_op1;
11782 tree expr = TREE_OPERAND (node, 0);
11783 tree type = TREE_TYPE (expr);
11784 int unchecked_ok = 0, tryblock_throws_ok = 0;
11786 /* Thrown expression must be assignable to java.lang.Throwable */
11787 if (!try_reference_assignconv (throwable_type_node, expr))
11789 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11790 parse_error_context (wfl_operator,
11791 "Can't throw `%s'; it must be a subclass of class `java.lang.Throwable'",
11792 lang_printable_name (type, 0));
11793 /* If the thrown expression was a reference, we further the
11794 compile-time check. */
11795 if (!JREFERENCE_TYPE_P (type))
11796 return error_mark_node;
11799 /* At least one of the following must be true */
11801 /* The type of the throw expression is a not checked exception,
11802 i.e. is a unchecked expression. */
11803 unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
11805 /* Throw is contained in a try statement and at least one catch
11806 clause can receive the thrown expression or the current method is
11807 declared to throw such an exception. Or, the throw statement is
11808 contained in a method or constructor declaration and the type of
11809 the Expression is assignable to at least one type listed in the
11810 throws clause the declaration. */
11811 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11813 tryblock_throws_ok = check_thrown_exceptions_do (TREE_TYPE (expr));
11814 if (!(unchecked_ok || tryblock_throws_ok))
11816 /* If there is a surrounding try block that has no matching
11817 clatch clause, report it first. A surrounding try block exits
11818 only if there is something after the list of checked
11819 exception thrown by the current function (if any). */
11820 if (IN_TRY_BLOCK_P ())
11821 parse_error_context (wfl_operator, "Checked exception `%s' can't be caught by any of the catch clause(s) of the surrounding `try' block",
11822 lang_printable_name (type, 0));
11823 /* If we have no surrounding try statement and the method doesn't have
11824 any throws, report it now. FIXME */
11826 /* We report that the exception can't be throw from a try block
11827 in all circumstances but when the `throw' is inside a static
11829 else if (!EXCEPTIONS_P (currently_caught_type_list)
11830 && !tryblock_throws_ok)
11832 if (IS_CLINIT (current_function_decl))
11833 parse_error_context (wfl_operator,
11834 "Checked exception `%s' can't be thrown in initializer",
11835 lang_printable_name (type, 0));
11837 parse_error_context (wfl_operator,
11838 "Checked exception `%s' isn't thrown from a `try' block",
11839 lang_printable_name (type, 0));
11841 /* Otherwise, the current method doesn't have the appropriate
11842 throws declaration */
11844 parse_error_context (wfl_operator, "Checked exception `%s' doesn't match any of current method's `throws' declaration(s)",
11845 lang_printable_name (type, 0));
11846 return error_mark_node;
11849 if (! flag_emit_class_files && ! flag_emit_xref)
11850 BUILD_THROW (node, expr);
11852 /* If doing xrefs, keep the location where the `throw' was seen. */
11853 if (flag_emit_xref)
11854 EXPR_WFL_LINECOL (node) = EXPR_WFL_LINECOL (wfl_op1);
11858 /* Check that exception said to be thrown by method DECL can be
11859 effectively caught from where DECL is invoked. */
11862 check_thrown_exceptions (location, decl)
11867 /* For all the unchecked exceptions thrown by DECL */
11868 for (throws = DECL_FUNCTION_THROWS (decl); throws;
11869 throws = TREE_CHAIN (throws))
11870 if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
11873 /* Temporary hack to suppresses errors about cloning arrays. FIXME */
11874 if (DECL_NAME (decl) == get_identifier ("clone"))
11877 EXPR_WFL_LINECOL (wfl_operator) = location;
11878 if (DECL_NAME (current_function_decl) == finit_identifier_node)
11879 parse_error_context
11880 (wfl_operator, "Exception `%s' can't be thrown in initializer",
11881 lang_printable_name (TREE_VALUE (throws), 0));
11884 parse_error_context
11885 (wfl_operator, "Exception `%s' must be caught, or it must be declared in the `throws' clause of `%s'",
11886 lang_printable_name (TREE_VALUE (throws), 0),
11887 (DECL_NAME (current_function_decl) == init_identifier_node ?
11888 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))) :
11889 IDENTIFIER_POINTER (DECL_NAME (current_function_decl))));
11894 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
11895 try-catch blocks, OR is listed in the `throws' clause of the
11899 check_thrown_exceptions_do (exception)
11902 tree list = currently_caught_type_list;
11903 resolve_and_layout (exception, NULL_TREE);
11904 /* First, all the nested try-catch-finally at that stage. The
11905 last element contains `throws' clause exceptions, if any. */
11906 if (IS_UNCHECKED_EXCEPTION_P (exception))
11911 for (caught = TREE_VALUE (list); caught; caught = TREE_CHAIN (caught))
11912 if (valid_ref_assignconv_cast_p (exception, TREE_VALUE (caught), 0))
11914 list = TREE_CHAIN (list);
11920 purge_unchecked_exceptions (mdecl)
11923 tree throws = DECL_FUNCTION_THROWS (mdecl);
11924 tree new = NULL_TREE;
11928 tree next = TREE_CHAIN (throws);
11929 if (!IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (throws)))
11931 TREE_CHAIN (throws) = new;
11936 /* List is inverted here, but it doesn't matter */
11937 DECL_FUNCTION_THROWS (mdecl) = new;
11940 /* 15.24 Conditional Operator ?: */
11943 patch_conditional_expr (node, wfl_cond, wfl_op1)
11944 tree node, wfl_cond, wfl_op1;
11946 tree cond = TREE_OPERAND (node, 0);
11947 tree op1 = TREE_OPERAND (node, 1);
11948 tree op2 = TREE_OPERAND (node, 2);
11949 tree resulting_type = NULL_TREE;
11950 tree t1, t2, patched;
11951 int error_found = 0;
11953 /* Operands of ?: might be StringBuffers crafted as a result of a
11954 string concatenation. Obtain a descent operand here. */
11955 if ((patched = patch_string (op1)))
11956 TREE_OPERAND (node, 1) = op1 = patched;
11957 if ((patched = patch_string (op2)))
11958 TREE_OPERAND (node, 2) = op2 = patched;
11960 t1 = TREE_TYPE (op1);
11961 t2 = TREE_TYPE (op2);
11963 /* The first expression must be a boolean */
11964 if (TREE_TYPE (cond) != boolean_type_node)
11966 SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
11967 parse_error_context (wfl_operator,
11968 "Incompatible type for `?:'. Can't convert `%s' to `boolean'",
11969 lang_printable_name (TREE_TYPE (cond), 0));
11973 /* Second and third can be numeric, boolean (i.e. primitive),
11974 references or null. Anything else results in an error */
11975 if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
11976 || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node)
11977 && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
11978 || (t1 == boolean_type_node && t2 == boolean_type_node)))
11981 /* Determine the type of the conditional expression. Same types are
11982 easy to deal with */
11984 resulting_type = t1;
11986 /* There are different rules for numeric types */
11987 else if (JNUMERIC_TYPE_P (t1))
11989 /* if byte/short found, the resulting type is short */
11990 if ((t1 == byte_type_node && t2 == short_type_node)
11991 || (t1 == short_type_node && t2 == byte_type_node))
11992 resulting_type = short_type_node;
11994 /* If t1 is a constant int and t2 is of type byte, short or char
11995 and t1's value fits in t2, then the resulting type is t2 */
11996 else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
11997 && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
11998 resulting_type = t2;
12000 /* If t2 is a constant int and t1 is of type byte, short or char
12001 and t2's value fits in t1, then the resulting type is t1 */
12002 else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
12003 && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
12004 resulting_type = t1;
12006 /* Otherwise, binary numeric promotion is applied and the
12007 resulting type is the promoted type of operand 1 and 2 */
12009 resulting_type = binary_numeric_promotion (t1, t2,
12010 &TREE_OPERAND (node, 1),
12011 &TREE_OPERAND (node, 2));
12014 /* Cases of a reference and a null type */
12015 else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
12016 resulting_type = t1;
12018 else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
12019 resulting_type = t2;
12021 /* Last case: different reference types. If a type can be converted
12022 into the other one by assignment conversion, the latter
12023 determines the type of the expression */
12024 else if ((resulting_type = try_reference_assignconv (t1, op2)))
12025 resulting_type = promote_type (t1);
12027 else if ((resulting_type = try_reference_assignconv (t2, op1)))
12028 resulting_type = promote_type (t2);
12030 /* If we don't have any resulting type, we're in trouble */
12031 if (!resulting_type)
12033 char *t = xstrdup (lang_printable_name (t1, 0));
12034 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
12035 parse_error_context (wfl_operator,
12036 "Incompatible type for `?:'. Can't convert `%s' to `%s'",
12037 t, lang_printable_name (t2, 0));
12044 TREE_TYPE (node) = error_mark_node;
12045 return error_mark_node;
12048 TREE_TYPE (node) = resulting_type;
12049 TREE_SET_CODE (node, COND_EXPR);
12050 CAN_COMPLETE_NORMALLY (node) = 1;
12054 /* Try to constant fold NODE.
12055 If NODE is not a constant expression, return NULL_EXPR.
12056 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
12059 fold_constant_for_init (node, context)
12063 tree op0, op1, val;
12064 enum tree_code code = TREE_CODE (node);
12066 if (code == STRING_CST)
12069 if (code == INTEGER_CST || code == REAL_CST)
12070 return convert (TREE_TYPE (context), node);
12071 if (TREE_TYPE (node) != NULL_TREE && code != VAR_DECL && code != FIELD_DECL)
12079 case TRUNC_MOD_EXPR:
12087 case TRUTH_ANDIF_EXPR:
12088 case TRUTH_ORIF_EXPR:
12095 op0 = TREE_OPERAND (node, 0);
12096 op1 = TREE_OPERAND (node, 1);
12097 val = fold_constant_for_init (op0, context);
12098 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12100 TREE_OPERAND (node, 0) = val;
12101 val = fold_constant_for_init (op1, context);
12102 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12104 TREE_OPERAND (node, 1) = val;
12105 return patch_binop (node, op0, op1);
12107 case UNARY_PLUS_EXPR:
12109 case TRUTH_NOT_EXPR:
12112 op0 = TREE_OPERAND (node, 0);
12113 val = fold_constant_for_init (op0, context);
12114 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12116 TREE_OPERAND (node, 0) = val;
12117 return patch_unaryop (node, op0);
12121 val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
12122 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12124 TREE_OPERAND (node, 0) = val;
12125 val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
12126 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12128 TREE_OPERAND (node, 1) = val;
12129 val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
12130 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12132 TREE_OPERAND (node, 2) = val;
12133 return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
12134 : TREE_OPERAND (node, 2);
12138 if (! FIELD_FINAL (node)
12139 || DECL_INITIAL (node) == NULL_TREE)
12141 val = DECL_INITIAL (node);
12142 /* Guard against infinite recursion. */
12143 DECL_INITIAL (node) = NULL_TREE;
12144 val = fold_constant_for_init (val, node);
12145 DECL_INITIAL (node) = val;
12148 case EXPR_WITH_FILE_LOCATION:
12149 /* Compare java_complete_tree and resolve_expression_name. */
12150 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
12151 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
12153 tree name = EXPR_WFL_NODE (node);
12155 if (PRIMARY_P (node))
12157 else if (! QUALIFIED_P (name))
12159 decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
12160 if (decl == NULL_TREE
12161 || (! FIELD_STATIC (decl) && ! FIELD_FINAL (decl)))
12163 return fold_constant_for_init (decl, decl);
12167 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
12168 qualify_ambiguous_name (node);
12169 if (resolve_field_access (node, &decl, NULL)
12170 && decl != NULL_TREE)
12171 return fold_constant_for_init (decl, decl);
12177 op0 = TREE_OPERAND (node, 0);
12178 val = fold_constant_for_init (op0, context);
12179 if (val == NULL_TREE || ! TREE_CONSTANT (val))
12181 TREE_OPERAND (node, 0) = val;
12185 #ifdef USE_COMPONENT_REF
12187 case COMPONENT_REF:
12196 #ifdef USE_COMPONENT_REF
12197 /* Context is 'T' for TypeName, 'P' for PackageName,
12198 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
12201 resolve_simple_name (name, context)
12208 resolve_qualified_name (name, context)