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"
70 #define DIR_SEPARATOR '/'
73 /* Local function prototypes */
74 static char *java_accstring_lookup PARAMS ((int));
75 static void classitf_redefinition_error PARAMS ((const char *,tree, tree, tree));
76 static void variable_redefinition_error PARAMS ((tree, tree, tree, int));
77 static tree create_class PARAMS ((int, tree, tree, tree));
78 static tree create_interface PARAMS ((int, tree, tree));
79 static void end_class_declaration PARAMS ((int));
80 static tree find_field PARAMS ((tree, tree));
81 static tree lookup_field_wrapper PARAMS ((tree, tree));
82 static int duplicate_declaration_error_p PARAMS ((tree, tree, tree));
83 static void register_fields PARAMS ((int, tree, tree));
84 static tree parser_qualified_classname PARAMS ((int, tree));
85 static int parser_check_super PARAMS ((tree, tree, tree));
86 static int parser_check_super_interface PARAMS ((tree, tree, tree));
87 static void check_modifiers_consistency PARAMS ((int));
88 static tree lookup_cl PARAMS ((tree));
89 static tree lookup_java_method2 PARAMS ((tree, tree, int));
90 static tree method_header PARAMS ((int, tree, tree, tree));
91 static void fix_method_argument_names PARAMS ((tree ,tree));
92 static tree method_declarator PARAMS ((tree, tree));
93 static void parse_warning_context PARAMS ((tree cl, const char *msg, ...))
95 static void issue_warning_error_from_context PARAMS ((tree, const char *msg, va_list));
96 static void parse_ctor_invocation_error PARAMS ((void));
97 static tree parse_jdk1_1_error PARAMS ((const char *));
98 static void complete_class_report_errors PARAMS ((jdep *));
99 static int process_imports PARAMS ((void));
100 static void read_import_dir PARAMS ((tree));
101 static int find_in_imports_on_demand PARAMS ((tree));
102 static int find_in_imports PARAMS ((tree));
103 static int check_pkg_class_access PARAMS ((tree, tree));
104 static tree resolve_package PARAMS ((tree, tree *));
105 static tree lookup_package_type PARAMS ((const char *, int));
106 static tree lookup_package_type_and_set_next PARAMS ((const char *, int, tree *));
107 static tree resolve_class PARAMS ((tree, tree, tree, tree));
108 static void declare_local_variables PARAMS ((int, tree, tree));
109 static void source_start_java_method PARAMS ((tree));
110 static void source_end_java_method PARAMS ((void));
111 static void expand_start_java_method PARAMS ((tree));
112 static tree find_name_in_single_imports PARAMS ((tree));
113 static void check_abstract_method_header PARAMS ((tree));
114 static tree lookup_java_interface_method2 PARAMS ((tree, tree));
115 static tree resolve_expression_name PARAMS ((tree, tree *));
116 static tree maybe_create_class_interface_decl PARAMS ((tree, tree, tree, tree));
117 static int check_class_interface_creation PARAMS ((int, int, tree,
119 static tree patch_method_invocation PARAMS ((tree, tree, tree,
121 static int breakdown_qualified PARAMS ((tree *, tree *, tree));
122 static tree resolve_and_layout PARAMS ((tree, tree));
123 static tree resolve_no_layout PARAMS ((tree, tree));
124 static int invocation_mode PARAMS ((tree, int));
125 static tree find_applicable_accessible_methods_list PARAMS ((int, tree,
127 static void search_applicable_methods_list PARAMS ((int, tree, tree, tree,
129 static tree find_most_specific_methods_list PARAMS ((tree));
130 static int argument_types_convertible PARAMS ((tree, tree));
131 static tree patch_invoke PARAMS ((tree, tree, tree));
132 static int maybe_use_access_method PARAMS ((int, tree *, tree *));
133 static tree lookup_method_invoke PARAMS ((int, tree, tree, tree, tree));
134 static tree register_incomplete_type PARAMS ((int, tree, tree, tree));
135 static tree obtain_incomplete_type PARAMS ((tree));
136 static tree java_complete_lhs PARAMS ((tree));
137 static tree java_complete_tree PARAMS ((tree));
138 static tree maybe_generate_pre_expand_clinit PARAMS ((tree));
139 static void java_complete_expand_method PARAMS ((tree));
140 static int unresolved_type_p PARAMS ((tree, tree *));
141 static void create_jdep_list PARAMS ((struct parser_ctxt *));
142 static tree build_expr_block PARAMS ((tree, tree));
143 static tree enter_block PARAMS ((void));
144 static tree enter_a_block PARAMS ((tree));
145 static tree exit_block PARAMS ((void));
146 static tree lookup_name_in_blocks PARAMS ((tree));
147 static void maybe_absorb_scoping_blocks PARAMS ((void));
148 static tree build_method_invocation PARAMS ((tree, tree));
149 static tree build_new_invocation PARAMS ((tree, tree));
150 static tree build_assignment PARAMS ((int, int, tree, tree));
151 static tree build_binop PARAMS ((enum tree_code, int, tree, tree));
152 static int check_final_assignment PARAMS ((tree ,tree));
153 static tree patch_assignment PARAMS ((tree, tree, tree ));
154 static tree patch_binop PARAMS ((tree, tree, tree));
155 static tree build_unaryop PARAMS ((int, int, tree));
156 static tree build_incdec PARAMS ((int, int, tree, int));
157 static tree patch_unaryop PARAMS ((tree, tree));
158 static tree build_cast PARAMS ((int, tree, tree));
159 static tree build_null_of_type PARAMS ((tree));
160 static tree patch_cast PARAMS ((tree, tree));
161 static int valid_ref_assignconv_cast_p PARAMS ((tree, tree, int));
162 static int valid_builtin_assignconv_identity_widening_p PARAMS ((tree, tree));
163 static int valid_cast_to_p PARAMS ((tree, tree));
164 static int valid_method_invocation_conversion_p PARAMS ((tree, tree));
165 static tree try_builtin_assignconv PARAMS ((tree, tree, tree));
166 static tree try_reference_assignconv PARAMS ((tree, tree));
167 static tree build_unresolved_array_type PARAMS ((tree));
168 static tree build_array_from_name PARAMS ((tree, tree, tree, tree *));
169 static tree build_array_ref PARAMS ((int, tree, tree));
170 static tree patch_array_ref PARAMS ((tree));
171 static tree make_qualified_name PARAMS ((tree, tree, int));
172 static tree merge_qualified_name PARAMS ((tree, tree));
173 static tree make_qualified_primary PARAMS ((tree, tree, int));
174 static int resolve_qualified_expression_name PARAMS ((tree, tree *,
176 static void qualify_ambiguous_name PARAMS ((tree));
177 static tree resolve_field_access PARAMS ((tree, tree *, tree *));
178 static tree build_newarray_node PARAMS ((tree, tree, int));
179 static tree patch_newarray PARAMS ((tree));
180 static tree resolve_type_during_patch PARAMS ((tree));
181 static tree build_this PARAMS ((int));
182 static tree build_wfl_wrap PARAMS ((tree));
183 static tree build_return PARAMS ((int, tree));
184 static tree patch_return PARAMS ((tree));
185 static tree maybe_access_field PARAMS ((tree, tree, tree));
186 static int complete_function_arguments PARAMS ((tree));
187 static int check_for_static_method_reference PARAMS ((tree, tree, tree,
189 static int not_accessible_p PARAMS ((tree, tree, int));
190 static void check_deprecation PARAMS ((tree, tree));
191 static int class_in_current_package PARAMS ((tree));
192 static tree build_if_else_statement PARAMS ((int, tree, tree, tree));
193 static tree patch_if_else_statement PARAMS ((tree));
194 static tree add_stmt_to_compound PARAMS ((tree, tree, tree));
195 static tree add_stmt_to_block PARAMS ((tree, tree, tree));
196 static tree patch_exit_expr PARAMS ((tree));
197 static tree build_labeled_block PARAMS ((int, tree));
198 static tree finish_labeled_statement PARAMS ((tree, tree));
199 static tree build_bc_statement PARAMS ((int, int, tree));
200 static tree patch_bc_statement PARAMS ((tree));
201 static tree patch_loop_statement PARAMS ((tree));
202 static tree build_new_loop PARAMS ((tree));
203 static tree build_loop_body PARAMS ((int, tree, int));
204 static tree finish_loop_body PARAMS ((int, tree, tree, int));
205 static tree build_debugable_stmt PARAMS ((int, tree));
206 static tree finish_for_loop PARAMS ((int, tree, tree, tree));
207 static tree patch_switch_statement PARAMS ((tree));
208 static tree string_constant_concatenation PARAMS ((tree, tree));
209 static tree build_string_concatenation PARAMS ((tree, tree));
210 static tree patch_string_cst PARAMS ((tree));
211 static tree patch_string PARAMS ((tree));
212 static tree build_try_statement PARAMS ((int, tree, tree));
213 static tree build_try_finally_statement PARAMS ((int, tree, tree));
214 static tree patch_try_statement PARAMS ((tree));
215 static tree patch_synchronized_statement PARAMS ((tree, tree));
216 static tree patch_throw_statement PARAMS ((tree, tree));
217 static void check_thrown_exceptions PARAMS ((int, tree));
218 static int check_thrown_exceptions_do PARAMS ((tree));
219 static void purge_unchecked_exceptions PARAMS ((tree));
220 static void check_throws_clauses PARAMS ((tree, tree, tree));
221 static void finish_method_declaration PARAMS ((tree));
222 static tree build_super_invocation PARAMS ((tree));
223 static int verify_constructor_circularity PARAMS ((tree, tree));
224 static char *constructor_circularity_msg PARAMS ((tree, tree));
225 static tree build_this_super_qualified_invocation PARAMS ((int, tree, tree,
227 static const char *get_printable_method_name PARAMS ((tree));
228 static tree patch_conditional_expr PARAMS ((tree, tree, tree));
229 static tree generate_finit PARAMS ((tree));
230 static void add_instance_initializer PARAMS ((tree));
231 static void fix_constructors PARAMS ((tree));
232 static tree build_alias_initializer_parameter_list PARAMS ((int, tree,
234 static void craft_constructor PARAMS ((tree, tree));
235 static int verify_constructor_super PARAMS ((tree));
236 static tree create_artificial_method PARAMS ((tree, int, tree, tree, tree));
237 static void start_artificial_method_body PARAMS ((tree));
238 static void end_artificial_method_body PARAMS ((tree));
239 static int check_method_redefinition PARAMS ((tree, tree));
240 static int reset_method_name PARAMS ((tree));
241 static void java_check_regular_methods PARAMS ((tree));
242 static void java_check_abstract_methods PARAMS ((tree));
243 static tree maybe_build_primttype_type_ref PARAMS ((tree, tree));
244 static void unreachable_stmt_error PARAMS ((tree));
245 static tree find_expr_with_wfl PARAMS ((tree));
246 static void missing_return_error PARAMS ((tree));
247 static tree build_new_array_init PARAMS ((int, tree));
248 static tree patch_new_array_init PARAMS ((tree, tree));
249 static tree maybe_build_array_element_wfl PARAMS ((tree));
250 static int array_constructor_check_entry PARAMS ((tree, tree));
251 static const char *purify_type_name PARAMS ((const char *));
252 static tree fold_constant_for_init PARAMS ((tree, tree));
253 static tree strip_out_static_field_access_decl PARAMS ((tree));
254 static jdeplist *reverse_jdep_list PARAMS ((struct parser_ctxt *));
255 static void static_ref_err PARAMS ((tree, tree, tree));
256 static void parser_add_interface PARAMS ((tree, tree, tree));
257 static void add_superinterfaces PARAMS ((tree, tree));
258 static tree jdep_resolve_class PARAMS ((jdep *));
259 static int note_possible_classname PARAMS ((const char *, int));
260 static void java_complete_expand_classes PARAMS ((void));
261 static void java_complete_expand_class PARAMS ((tree));
262 static void java_complete_expand_methods PARAMS ((tree));
263 static tree cut_identifier_in_qualified PARAMS ((tree));
264 static tree java_stabilize_reference PARAMS ((tree));
265 static tree do_unary_numeric_promotion PARAMS ((tree));
266 static char * operator_string PARAMS ((tree));
267 static tree do_merge_string_cste PARAMS ((tree, const char *, int, int));
268 static tree merge_string_cste PARAMS ((tree, tree, int));
269 static tree java_refold PARAMS ((tree));
270 static int java_decl_equiv PARAMS ((tree, tree));
271 static int binop_compound_p PARAMS ((enum tree_code));
272 static tree search_loop PARAMS ((tree));
273 static int labeled_block_contains_loop_p PARAMS ((tree, tree));
274 static void check_abstract_method_definitions PARAMS ((int, tree, tree));
275 static void java_check_abstract_method_definitions PARAMS ((tree));
276 static void java_debug_context_do PARAMS ((int));
277 static void java_parser_context_push_initialized_field PARAMS ((void));
278 static void java_parser_context_pop_initialized_field PARAMS ((void));
279 static tree reorder_static_initialized PARAMS ((tree));
280 static void java_parser_context_suspend PARAMS ((void));
281 static void java_parser_context_resume PARAMS ((void));
283 /* JDK 1.1 work. FIXME */
285 static tree maybe_make_nested_class_name PARAMS ((tree));
286 static void make_nested_class_name PARAMS ((tree));
287 static void set_nested_class_simple_name_value PARAMS ((tree, int));
288 static void link_nested_class_to_enclosing PARAMS ((void));
289 static tree find_as_inner_class PARAMS ((tree, tree, tree));
290 static tree find_as_inner_class_do PARAMS ((tree, tree));
291 static int check_inner_class_redefinition PARAMS ((tree, tree));
293 static tree build_thisn_assign PARAMS ((void));
294 static tree build_current_thisn PARAMS ((tree));
295 static tree build_access_to_thisn PARAMS ((tree, tree, int));
296 static tree maybe_build_thisn_access_method PARAMS ((tree));
298 static tree build_outer_field_access PARAMS ((tree, tree));
299 static tree build_outer_field_access_methods PARAMS ((tree));
300 static tree build_outer_field_access_expr PARAMS ((int, tree, tree,
302 static tree build_outer_method_access_method PARAMS ((tree));
303 static tree build_new_access_id PARAMS ((void));
304 static tree build_outer_field_access_method PARAMS ((tree, tree, tree,
307 static int outer_field_access_p PARAMS ((tree, tree));
308 static int outer_field_expanded_access_p PARAMS ((tree, tree *,
310 static tree outer_field_access_fix PARAMS ((tree, tree, tree));
311 static tree build_incomplete_class_ref PARAMS ((int, tree));
312 static tree patch_incomplete_class_ref PARAMS ((tree));
313 static tree create_anonymous_class PARAMS ((int, tree));
314 static void patch_anonymous_class PARAMS ((tree, tree, tree));
315 static void add_inner_class_fields PARAMS ((tree, tree));
317 /* Number of error found so far. */
318 int java_error_count;
319 /* Number of warning found so far. */
320 int java_warning_count;
321 /* Tell when not to fold, when doing xrefs */
323 /* Cyclic inheritance report, as it can be set by layout_class */
324 char *cyclic_inheritance_report;
326 /* Tell when we're within an instance initializer */
327 static int in_instance_initializer;
329 /* The current parser context */
330 struct parser_ctxt *ctxp;
332 /* List of things that were analyzed for which code will be generated */
333 static struct parser_ctxt *ctxp_for_generation = NULL;
335 /* binop_lookup maps token to tree_code. It is used where binary
336 operations are involved and required by the parser. RDIV_EXPR
337 covers both integral/floating point division. The code is changed
338 once the type of both operator is worked out. */
340 static enum tree_code binop_lookup[19] =
342 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
343 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
344 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
345 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
346 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
348 #define BINOP_LOOKUP(VALUE) \
349 binop_lookup [((VALUE) - PLUS_TK)% \
350 (sizeof (binop_lookup) / sizeof (binop_lookup[0]))]
352 /* This is the end index for binary operators that can also be used
353 in compound assignements. */
354 #define BINOP_COMPOUND_CANDIDATES 11
356 /* Fake WFL used to report error message. It is initialized once if
357 needed and reused with it's location information is overriden. */
358 tree wfl_operator = NULL_TREE;
360 /* The "$L" identifier we use to create labels. */
361 static tree label_id = NULL_TREE;
363 /* The "StringBuffer" identifier used for the String `+' operator. */
364 static tree wfl_string_buffer = NULL_TREE;
366 /* The "append" identifier used for String `+' operator. */
367 static tree wfl_append = NULL_TREE;
369 /* The "toString" identifier used for String `+' operator. */
370 static tree wfl_to_string = NULL_TREE;
372 /* The "java.lang" import qualified name. */
373 static tree java_lang_id = NULL_TREE;
375 /* The generated `inst$' identifier used for generated enclosing
376 instance/field access functions. */
377 static tree inst_id = NULL_TREE;
379 /* The "java.lang.Cloneable" qualified name. */
380 static tree java_lang_cloneable = NULL_TREE;
382 /* Context and flag for static blocks */
383 static tree current_static_block = NULL_TREE;
385 /* The generated `write_parm_value$' identifier. */
388 /* The list of all packages we've seen so far */
389 static tree package_list = NULL_TREE;
391 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
392 line and point it out. */
393 /* Should point out the one that don't fit. ASCII/unicode, going
396 #define check_modifiers(__message, __value, __mask) do { \
397 if ((__value) & ~(__mask)) \
399 int i, remainder = (__value) & ~(__mask); \
400 for (i = 0; i <= 10; i++) \
401 if ((1 << i) & remainder) \
402 parse_error_context (ctxp->modifier_ctx [i], (__message), \
403 java_accstring_lookup (1 << i)); \
425 /* Things defined here have to match the order of what's in the
426 binop_lookup table. */
428 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
429 %token LS_TK SRS_TK ZRS_TK
430 %token AND_TK XOR_TK OR_TK
431 %token BOOL_AND_TK BOOL_OR_TK
432 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
434 /* This maps to the same binop_lookup entry than the token above */
436 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
438 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
439 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
442 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
444 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
445 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
446 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
447 %token PAD_TK ABSTRACT_TK MODIFIER_TK
449 /* Keep those two in order, too */
450 %token DECR_TK INCR_TK
452 /* From now one, things can be in any order */
454 %token DEFAULT_TK IF_TK THROW_TK
455 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
456 %token THROWS_TK BREAK_TK IMPORT_TK
457 %token ELSE_TK INSTANCEOF_TK RETURN_TK
458 %token VOID_TK CATCH_TK INTERFACE_TK
459 %token CASE_TK EXTENDS_TK FINALLY_TK
460 %token SUPER_TK WHILE_TK CLASS_TK
461 %token SWITCH_TK CONST_TK TRY_TK
462 %token FOR_TK NEW_TK CONTINUE_TK
463 %token GOTO_TK PACKAGE_TK THIS_TK
465 %token BYTE_TK SHORT_TK INT_TK LONG_TK
466 %token CHAR_TK INTEGRAL_TK
468 %token FLOAT_TK DOUBLE_TK FP_TK
472 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
474 %token ASSIGN_ANY_TK ASSIGN_TK
475 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
477 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
478 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
480 %type <value> modifiers MODIFIER_TK final synchronized
482 %type <node> super ID_TK identifier
483 %type <node> name simple_name qualified_name
484 %type <node> type_declaration compilation_unit
485 field_declaration method_declaration extends_interfaces
486 interfaces interface_type_list
487 class_member_declaration
488 import_declarations package_declaration
489 type_declarations interface_body
490 interface_member_declaration constant_declaration
491 interface_member_declarations interface_type
492 abstract_method_declaration interface_type_list
493 %type <node> class_body_declaration class_member_declaration
494 static_initializer constructor_declaration block
495 %type <node> class_body_declarations constructor_header
496 %type <node> class_or_interface_type class_type class_type_list
497 constructor_declarator explicit_constructor_invocation
498 %type <node> dim_expr dim_exprs this_or_super throws
500 %type <node> variable_declarator_id variable_declarator
501 variable_declarators variable_initializer
502 variable_initializers constructor_body
505 %type <node> class_body block_end constructor_block_end
506 %type <node> statement statement_without_trailing_substatement
507 labeled_statement if_then_statement label_decl
508 if_then_else_statement while_statement for_statement
509 statement_nsi labeled_statement_nsi do_statement
510 if_then_else_statement_nsi while_statement_nsi
511 for_statement_nsi statement_expression_list for_init
512 for_update statement_expression expression_statement
513 primary_no_new_array expression primary
514 array_creation_expression array_type
515 class_instance_creation_expression field_access
516 method_invocation array_access something_dot_new
517 argument_list postfix_expression while_expression
518 post_increment_expression post_decrement_expression
519 unary_expression_not_plus_minus unary_expression
520 pre_increment_expression pre_decrement_expression
521 unary_expression_not_plus_minus cast_expression
522 multiplicative_expression additive_expression
523 shift_expression relational_expression
524 equality_expression and_expression
525 exclusive_or_expression inclusive_or_expression
526 conditional_and_expression conditional_or_expression
527 conditional_expression assignment_expression
528 left_hand_side assignment for_header for_begin
529 constant_expression do_statement_begin empty_statement
530 switch_statement synchronized_statement throw_statement
531 try_statement switch_expression switch_block
532 catches catch_clause catch_clause_parameter finally
533 anonymous_class_creation
534 %type <node> return_statement break_statement continue_statement
536 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
537 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
538 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
539 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
540 %type <operator> ASSIGN_ANY_TK assignment_operator
541 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
542 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
543 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
544 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
545 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
546 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
547 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
548 %type <operator> NEW_TK
550 %type <node> method_body
552 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
553 STRING_LIT_TK NULL_TK VOID_TK
555 %type <node> IF_TK WHILE_TK FOR_TK
557 %type <node> formal_parameter_list formal_parameter
558 method_declarator method_header
560 %type <node> primitive_type reference_type type
561 BOOLEAN_TK INTEGRAL_TK FP_TK
563 /* Added or modified JDK 1.1 rule types */
564 %type <node> type_literals array_type_literal
567 /* 19.2 Production from 2.3: The Syntactic Grammar */
573 /* 19.3 Productions from 3: Lexical structure */
583 /* 19.4 Productions from 4: Types, Values and Variables */
596 class_or_interface_type
600 class_or_interface_type:
605 class_or_interface_type /* Default rule */
609 class_or_interface_type
613 primitive_type OSB_TK CSB_TK
615 $$ = build_java_array_type ($1, -1);
616 CLASS_LOADED_P ($$) = 1;
619 { $$ = build_unresolved_array_type ($1); }
620 | array_type OSB_TK CSB_TK
621 { $$ = build_unresolved_array_type ($1); }
622 | primitive_type OSB_TK error
623 {RULE ("']' expected"); RECOVER;}
624 | array_type OSB_TK error
625 {RULE ("']' expected"); RECOVER;}
628 /* 19.5 Productions from 6: Names */
630 simple_name /* Default rule */
631 | qualified_name /* Default rule */
635 identifier /* Default rule */
639 name DOT_TK identifier
640 { $$ = make_qualified_name ($1, $3, $2.location); }
647 /* 19.6: Production from 7: Packages */
650 | package_declaration
651 | import_declarations
653 | package_declaration import_declarations
654 | package_declaration type_declarations
655 | import_declarations type_declarations
656 | package_declaration import_declarations type_declarations
664 | import_declarations import_declaration
672 | type_declarations type_declaration
676 PACKAGE_TK name SC_TK
678 ctxp->package = EXPR_WFL_NODE ($2);
679 package_list = tree_cons (ctxp->package, NULL, package_list);
682 {yyerror ("Missing name"); RECOVER;}
683 | PACKAGE_TK name error
684 {yyerror ("';' expected"); RECOVER;}
688 single_type_import_declaration
689 | type_import_on_demand_declaration
692 single_type_import_declaration:
695 tree name = EXPR_WFL_NODE ($2), node, last_name;
696 int i = IDENTIFIER_LENGTH (name)-1;
697 const char *last = &IDENTIFIER_POINTER (name)[i];
698 while (last != IDENTIFIER_POINTER (name))
704 last_name = get_identifier (++last);
705 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
707 tree err = find_name_in_single_imports (last_name);
708 if (err && err != name)
710 ($2, "Ambiguous class: `%s' and `%s'",
711 IDENTIFIER_POINTER (name),
712 IDENTIFIER_POINTER (err));
714 REGISTER_IMPORT ($2, last_name)
717 REGISTER_IMPORT ($2, last_name);
720 {yyerror ("Missing name"); RECOVER;}
721 | IMPORT_TK name error
722 {yyerror ("';' expected"); RECOVER;}
725 type_import_on_demand_declaration:
726 IMPORT_TK name DOT_TK MULT_TK SC_TK
728 tree name = EXPR_WFL_NODE ($2);
729 /* Don't import java.lang.* twice. */
730 if (name != java_lang_id)
732 tree node = build_tree_list ($2, NULL_TREE);
733 read_import_dir ($2);
734 TREE_CHAIN (node) = ctxp->import_demand_list;
735 ctxp->import_demand_list = node;
738 | IMPORT_TK name DOT_TK error
739 {yyerror ("'*' expected"); RECOVER;}
740 | IMPORT_TK name DOT_TK MULT_TK error
741 {yyerror ("';' expected"); RECOVER;}
746 { end_class_declaration (0); }
747 | interface_declaration
748 { end_class_declaration (0); }
754 yyerror ("Class or interface declaration expected");
758 /* 19.7 Shortened from the original:
759 modifiers: modifier | modifiers modifier
760 modifier: any of public... */
766 | modifiers MODIFIER_TK
771 (ctxp->modifier_ctx [$2], "Modifier `%s' declared twice",
772 java_accstring_lookup (acc));
780 /* 19.8.1 Production from $8.1: Class Declaration */
782 modifiers CLASS_TK identifier super interfaces
783 { create_class ($1, $3, $4, $5); }
785 | CLASS_TK identifier super interfaces
786 { create_class (0, $2, $3, $4); }
788 | modifiers CLASS_TK error
789 {yyerror ("Missing class name"); RECOVER;}
791 {yyerror ("Missing class name"); RECOVER;}
792 | CLASS_TK identifier error
794 if (!ctxp->class_err) yyerror ("'{' expected");
797 | modifiers CLASS_TK identifier error
798 {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
803 | EXTENDS_TK class_type
805 | EXTENDS_TK class_type error
806 {yyerror ("'{' expected"); ctxp->class_err=1;}
808 {yyerror ("Missing super class name"); ctxp->class_err=1;}
813 | IMPLEMENTS_TK interface_type_list
815 | IMPLEMENTS_TK error
818 yyerror ("Missing interface name");
825 ctxp->interface_number = 1;
826 $$ = build_tree_list ($1, NULL_TREE);
828 | interface_type_list C_TK interface_type
830 ctxp->interface_number++;
831 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
833 | interface_type_list C_TK error
834 {yyerror ("Missing interface name"); RECOVER;}
840 /* Store the location of the `}' when doing xrefs */
842 DECL_END_SOURCE_LINE (GET_CPC ()) =
843 EXPR_WFL_ADD_COL ($2.location, 1);
846 | OCB_TK class_body_declarations CCB_TK
848 /* Store the location of the `}' when doing xrefs */
850 DECL_END_SOURCE_LINE (GET_CPC ()) =
851 EXPR_WFL_ADD_COL ($3.location, 1);
856 class_body_declarations:
857 class_body_declaration
858 | class_body_declarations class_body_declaration
861 class_body_declaration:
862 class_member_declaration
864 | constructor_declaration
865 | block /* Added, JDK1.1, instance initializer */
867 TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
868 SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
872 class_member_declaration:
874 | field_declaration SC_TK
877 | class_declaration /* Added, JDK1.1 inner classes */
878 { end_class_declaration (1); }
879 | interface_declaration /* Added, JDK1.1 inner interfaces */
880 { end_class_declaration (1); }
883 /* 19.8.2 Productions from 8.3: Field Declarations */
885 type variable_declarators SC_TK
886 { register_fields (0, $1, $2); }
887 | modifiers type variable_declarators SC_TK
890 ("Illegal modifier `%s' for field declaration",
891 $1, FIELD_MODIFIERS);
892 check_modifiers_consistency ($1);
893 register_fields ($1, $2, $3);
897 variable_declarators:
898 /* Should we use build_decl_list () instead ? FIXME */
899 variable_declarator /* Default rule */
900 | variable_declarators C_TK variable_declarator
901 { $$ = chainon ($1, $3); }
902 | variable_declarators C_TK error
903 {yyerror ("Missing term"); RECOVER;}
907 variable_declarator_id
908 { $$ = build_tree_list ($1, NULL_TREE); }
909 | variable_declarator_id ASSIGN_TK variable_initializer
911 if (java_error_count)
914 ($1, build_assignment ($2.token, $2.location, $1, $3));
916 | variable_declarator_id ASSIGN_TK error
918 yyerror ("Missing variable initializer");
919 $$ = build_tree_list ($1, NULL_TREE);
922 | variable_declarator_id ASSIGN_TK variable_initializer error
924 yyerror ("';' expected");
925 $$ = build_tree_list ($1, NULL_TREE);
930 variable_declarator_id:
932 | variable_declarator_id OSB_TK CSB_TK
933 { $$ = build_unresolved_array_type ($1); }
935 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
936 | variable_declarator_id OSB_TK error
937 {yyerror ("']' expected"); DRECOVER(vdi);}
938 | variable_declarator_id CSB_TK error
939 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
942 variable_initializer:
947 /* 19.8.3 Productions from 8.4: Method Declarations */
951 current_function_decl = $1;
952 if (current_function_decl
953 && TREE_CODE (current_function_decl) == FUNCTION_DECL)
954 source_start_java_method (current_function_decl);
956 current_function_decl = NULL_TREE;
959 { finish_method_declaration ($3); }
960 | method_header error
961 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
965 type method_declarator throws
966 { $$ = method_header (0, $1, $2, $3); }
967 | VOID_TK method_declarator throws
968 { $$ = method_header (0, void_type_node, $2, $3); }
969 | modifiers type method_declarator throws
970 { $$ = method_header ($1, $2, $3, $4); }
971 | modifiers VOID_TK method_declarator throws
972 { $$ = method_header ($1, void_type_node, $3, $4); }
975 yyerror ("Invalid method declaration, method name required");
978 | modifiers type error
981 {yyerror ("Identifier expected"); RECOVER;}
982 | modifiers VOID_TK error
983 {yyerror ("Identifier expected"); RECOVER;}
986 yyerror ("Invalid method declaration, return type required");
992 identifier OP_TK CP_TK
994 ctxp->formal_parameter_number = 0;
995 $$ = method_declarator ($1, NULL_TREE);
997 | identifier OP_TK formal_parameter_list CP_TK
998 { $$ = method_declarator ($1, $3); }
999 | method_declarator OSB_TK CSB_TK
1001 EXPR_WFL_LINECOL (wfl_operator) = $2.location;
1003 build_unresolved_array_type (TREE_PURPOSE ($1));
1004 parse_warning_context
1006 "Discouraged form of returned type specification");
1008 | identifier OP_TK error
1009 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1010 | method_declarator OSB_TK error
1011 {yyerror ("']' expected"); RECOVER;}
1014 formal_parameter_list:
1017 ctxp->formal_parameter_number = 1;
1019 | formal_parameter_list C_TK formal_parameter
1021 ctxp->formal_parameter_number += 1;
1022 $$ = chainon ($1, $3);
1024 | formal_parameter_list C_TK error
1025 { yyerror ("Missing formal parameter term"); RECOVER; }
1029 type variable_declarator_id
1031 $$ = build_tree_list ($2, $1);
1033 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1035 $$ = build_tree_list ($3, $2);
1036 ARG_FINAL_P ($$) = 1;
1040 yyerror ("Missing identifier"); RECOVER;
1045 yyerror ("Missing identifier"); RECOVER;
1053 check_modifiers ("Illegal modifier `%s'. Only `final' was expected here",
1055 if ($1 != ACC_FINAL)
1056 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1062 | THROWS_TK class_type_list
1065 {yyerror ("Missing class type term"); RECOVER;}
1070 { $$ = build_tree_list ($1, $1); }
1071 | class_type_list C_TK class_type
1072 { $$ = tree_cons ($3, $3, $1); }
1073 | class_type_list C_TK error
1074 {yyerror ("Missing class type term"); RECOVER;}
1081 { $$ = NULL_TREE; } /* Probably not the right thing to do. */
1084 /* 19.8.4 Productions from 8.5: Static Initializers */
1088 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1089 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1091 | static block SC_TK /* Shouldn't be here. FIXME */
1093 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1094 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1098 static: /* Test lval.sub_token here */
1101 check_modifiers ("Illegal modifier `%s' for static initializer", $1, ACC_STATIC);
1102 /* Can't have a static initializer in an innerclass */
1103 if ($1 | ACC_STATIC &&
1104 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1106 (MODIFIER_WFL (STATIC_TK),
1107 "Can't define static initializer in class `%s'. Static initializer can only be defined in top-level classes",
1108 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1109 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1113 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1114 constructor_declaration:
1117 current_function_decl = $1;
1118 source_start_java_method (current_function_decl);
1121 { finish_method_declaration ($3); }
1125 constructor_declarator throws
1126 { $$ = method_header (0, NULL_TREE, $1, $2); }
1127 | modifiers constructor_declarator throws
1128 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1131 constructor_declarator:
1132 simple_name OP_TK CP_TK
1134 ctxp->formal_parameter_number = 0;
1135 $$ = method_declarator ($1, NULL_TREE);
1137 | simple_name OP_TK formal_parameter_list CP_TK
1138 { $$ = method_declarator ($1, $3); }
1142 /* Unlike regular method, we always need a complete (empty)
1143 body so we can safely perform all the required code
1144 addition (super invocation and field initialization) */
1145 block_begin constructor_block_end
1147 BLOCK_EXPR_BODY ($2) = empty_stmt_node;
1150 | block_begin explicit_constructor_invocation constructor_block_end
1152 | block_begin block_statements constructor_block_end
1154 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1158 constructor_block_end:
1162 /* Error recovery for that rule moved down expression_statement: rule. */
1163 explicit_constructor_invocation:
1164 this_or_super OP_TK CP_TK SC_TK
1166 $$ = build_method_invocation ($1, NULL_TREE);
1167 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1168 $$ = java_method_add_stmt (current_function_decl, $$);
1170 | this_or_super OP_TK argument_list CP_TK SC_TK
1172 $$ = build_method_invocation ($1, $3);
1173 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1174 $$ = java_method_add_stmt (current_function_decl, $$);
1176 /* Added, JDK1.1 inner classes. Modified because the rule
1177 'primary' couldn't work. */
1178 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1179 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1180 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1181 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1184 this_or_super: /* Added, simplifies error diagnostics */
1187 tree wfl = build_wfl_node (this_identifier_node);
1188 EXPR_WFL_LINECOL (wfl) = $1.location;
1193 tree wfl = build_wfl_node (super_identifier_node);
1194 EXPR_WFL_LINECOL (wfl) = $1.location;
1199 /* 19.9 Productions from 9: Interfaces */
1200 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1201 interface_declaration:
1202 INTERFACE_TK identifier
1203 { create_interface (0, $2, NULL_TREE); }
1205 | modifiers INTERFACE_TK identifier
1206 { create_interface ($1, $3, NULL_TREE); }
1208 | INTERFACE_TK identifier extends_interfaces
1209 { create_interface (0, $2, $3); }
1211 | modifiers INTERFACE_TK identifier extends_interfaces
1212 { create_interface ($1, $3, $4); }
1214 | INTERFACE_TK identifier error
1215 {yyerror ("'{' expected"); RECOVER;}
1216 | modifiers INTERFACE_TK identifier error
1217 {yyerror ("'{' expected"); RECOVER;}
1221 EXTENDS_TK interface_type
1223 ctxp->interface_number = 1;
1224 $$ = build_tree_list ($2, NULL_TREE);
1226 | extends_interfaces C_TK interface_type
1228 ctxp->interface_number++;
1229 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1232 {yyerror ("Invalid interface type"); RECOVER;}
1233 | extends_interfaces C_TK error
1234 {yyerror ("Missing term"); RECOVER;}
1240 | OCB_TK interface_member_declarations CCB_TK
1244 interface_member_declarations:
1245 interface_member_declaration
1246 | interface_member_declarations interface_member_declaration
1249 interface_member_declaration:
1250 constant_declaration
1251 | abstract_method_declaration
1252 | class_declaration /* Added, JDK1.1 inner classes */
1253 { end_class_declaration (1); }
1254 | interface_declaration /* Added, JDK1.1 inner interfaces */
1255 { end_class_declaration (1); }
1258 constant_declaration:
1262 abstract_method_declaration:
1265 check_abstract_method_header ($1);
1266 current_function_decl = NULL_TREE; /* FIXME ? */
1268 | method_header error
1269 {yyerror ("';' expected"); RECOVER;}
1272 /* 19.10 Productions from 10: Arrays */
1275 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1276 | OCB_TK variable_initializers CCB_TK
1277 { $$ = build_new_array_init ($1.location, $2); }
1278 | OCB_TK variable_initializers C_TK CCB_TK
1279 { $$ = build_new_array_init ($1.location, $2); }
1282 variable_initializers:
1283 variable_initializer
1285 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1288 | variable_initializers C_TK variable_initializer
1290 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1292 | variable_initializers C_TK error
1293 {yyerror ("Missing term"); RECOVER;}
1296 /* 19.11 Production from 14: Blocks and Statements */
1300 /* Store the location of the `}' when doing xrefs */
1301 if (current_function_decl && flag_emit_xref)
1302 DECL_END_SOURCE_LINE (current_function_decl) =
1303 EXPR_WFL_ADD_COL ($2.location, 1);
1304 $$ = empty_stmt_node;
1306 | block_begin block_statements block_end
1318 maybe_absorb_scoping_blocks ();
1319 /* Store the location of the `}' when doing xrefs */
1320 if (current_function_decl && flag_emit_xref)
1321 DECL_END_SOURCE_LINE (current_function_decl) =
1322 EXPR_WFL_ADD_COL ($1.location, 1);
1329 | block_statements block_statement
1333 local_variable_declaration_statement
1335 { java_method_add_stmt (current_function_decl, $1); }
1336 | class_declaration /* Added, JDK1.1 local classes */
1338 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1339 end_class_declaration (1);
1343 local_variable_declaration_statement:
1344 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1347 local_variable_declaration:
1348 type variable_declarators
1349 { declare_local_variables (0, $1, $2); }
1350 | final type variable_declarators /* Added, JDK1.1 final locals */
1351 { declare_local_variables ($1, $2, $3); }
1355 statement_without_trailing_substatement
1358 | if_then_else_statement
1361 { $$ = exit_block (); }
1365 statement_without_trailing_substatement
1366 | labeled_statement_nsi
1367 | if_then_else_statement_nsi
1368 | while_statement_nsi
1370 { $$ = exit_block (); }
1373 statement_without_trailing_substatement:
1376 | expression_statement
1380 | continue_statement
1382 | synchronized_statement
1389 { $$ = empty_stmt_node; }
1393 identifier REL_CL_TK
1395 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1396 EXPR_WFL_NODE ($1));
1398 push_labeled_block ($$);
1399 PUSH_LABELED_BLOCK ($$);
1404 label_decl statement
1405 { $$ = finish_labeled_statement ($1, $2); }
1407 {yyerror ("':' expected"); RECOVER;}
1410 labeled_statement_nsi:
1411 label_decl statement_nsi
1412 { $$ = finish_labeled_statement ($1, $2); }
1415 /* We concentrate here a bunch of error handling rules that we couldn't write
1416 earlier, because expression_statement catches a missing ';'. */
1417 expression_statement:
1418 statement_expression SC_TK
1420 /* We have a statement. Generate a WFL around it so
1422 $$ = build_expr_wfl ($1, input_filename, lineno, 0);
1423 /* We know we have a statement, so set the debug
1424 info to be eventually generate here. */
1425 $$ = JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1429 if (ctxp->prevent_ese != lineno)
1430 yyerror ("Invalid expression statement");
1431 DRECOVER (expr_stmt);
1435 if (ctxp->prevent_ese != lineno)
1436 yyerror ("Invalid expression statement");
1437 DRECOVER (expr_stmt);
1441 if (ctxp->prevent_ese != lineno)
1442 yyerror ("Invalid expression statement");
1443 DRECOVER (expr_stmt);
1445 | this_or_super OP_TK error
1446 {yyerror ("')' expected"); RECOVER;}
1447 | this_or_super OP_TK CP_TK error
1449 parse_ctor_invocation_error ();
1452 | this_or_super OP_TK argument_list error
1453 {yyerror ("')' expected"); RECOVER;}
1454 | this_or_super OP_TK argument_list CP_TK error
1456 parse_ctor_invocation_error ();
1459 | name DOT_TK SUPER_TK error
1460 {yyerror ("'(' expected"); RECOVER;}
1461 | name DOT_TK SUPER_TK OP_TK error
1462 {yyerror ("')' expected"); RECOVER;}
1463 | name DOT_TK SUPER_TK OP_TK argument_list error
1464 {yyerror ("')' expected"); RECOVER;}
1465 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1466 {yyerror ("';' expected"); RECOVER;}
1467 | name DOT_TK SUPER_TK OP_TK CP_TK error
1468 {yyerror ("';' expected"); RECOVER;}
1471 statement_expression:
1473 | pre_increment_expression
1474 | pre_decrement_expression
1475 | post_increment_expression
1476 | post_decrement_expression
1478 | class_instance_creation_expression
1482 IF_TK OP_TK expression CP_TK statement
1484 $$ = build_if_else_statement ($2.location, $3,
1488 {yyerror ("'(' expected"); RECOVER;}
1490 {yyerror ("Missing term"); RECOVER;}
1491 | IF_TK OP_TK expression error
1492 {yyerror ("')' expected"); RECOVER;}
1495 if_then_else_statement:
1496 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1497 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1500 if_then_else_statement_nsi:
1501 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1502 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1512 /* Make into "proper list" of COMPOUND_EXPRs.
1513 I.e. make the last statment also have its own
1515 maybe_absorb_scoping_blocks ();
1516 TREE_OPERAND ($1, 1) = exit_block ();
1517 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1522 SWITCH_TK OP_TK expression CP_TK
1524 $$ = build (SWITCH_EXPR, NULL_TREE, $3, NULL_TREE);
1525 EXPR_WFL_LINECOL ($$) = $2.location;
1528 {yyerror ("'(' expected"); RECOVER;}
1529 | SWITCH_TK OP_TK error
1530 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1531 | SWITCH_TK OP_TK expression CP_TK error
1532 {yyerror ("'{' expected"); RECOVER;}
1535 /* Default assignment is there to avoid type node on switch_block
1541 | OCB_TK switch_labels CCB_TK
1543 | OCB_TK switch_block_statement_groups CCB_TK
1545 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1549 switch_block_statement_groups:
1550 switch_block_statement_group
1551 | switch_block_statement_groups switch_block_statement_group
1554 switch_block_statement_group:
1555 switch_labels block_statements
1560 | switch_labels switch_label
1564 CASE_TK constant_expression REL_CL_TK
1566 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1567 EXPR_WFL_LINECOL (lab) = $1.location;
1568 java_method_add_stmt (current_function_decl, lab);
1570 | DEFAULT_TK REL_CL_TK
1572 tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
1573 EXPR_WFL_LINECOL (lab) = $1.location;
1574 java_method_add_stmt (current_function_decl, lab);
1577 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1578 | CASE_TK constant_expression error
1579 {yyerror ("':' expected"); RECOVER;}
1581 {yyerror ("':' expected"); RECOVER;}
1585 WHILE_TK OP_TK expression CP_TK
1587 tree body = build_loop_body ($2.location, $3, 0);
1588 $$ = build_new_loop (body);
1593 while_expression statement
1594 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1596 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1597 | WHILE_TK OP_TK error
1598 {yyerror ("Missing term and ')' expected"); RECOVER;}
1599 | WHILE_TK OP_TK expression error
1600 {yyerror ("')' expected"); RECOVER;}
1603 while_statement_nsi:
1604 while_expression statement_nsi
1605 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1611 tree body = build_loop_body (0, NULL_TREE, 1);
1612 $$ = build_new_loop (body);
1614 /* Need error handing here. FIXME */
1618 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1619 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1623 for_begin SC_TK expression SC_TK for_update CP_TK statement
1624 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7); }
1625 | for_begin SC_TK SC_TK for_update CP_TK statement
1627 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1628 /* We have not condition, so we get rid of the EXIT_EXPR */
1629 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1632 | for_begin SC_TK error
1633 {yyerror ("Invalid control expression"); RECOVER;}
1634 | for_begin SC_TK expression SC_TK error
1635 {yyerror ("Invalid update expression"); RECOVER;}
1636 | for_begin SC_TK SC_TK error
1637 {yyerror ("Invalid update expression"); RECOVER;}
1641 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1642 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1643 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1645 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1646 /* We have not condition, so we get rid of the EXIT_EXPR */
1647 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1655 /* This scope defined for local variable that may be
1656 defined within the scope of the for loop */
1660 {yyerror ("'(' expected"); DRECOVER(for_1);}
1661 | FOR_TK OP_TK error
1662 {yyerror ("Invalid init statement"); RECOVER;}
1668 /* We now declare the loop body. The loop is
1669 declared as a for loop. */
1670 tree body = build_loop_body (0, NULL_TREE, 0);
1671 $$ = build_new_loop (body);
1672 FOR_LOOP_P ($$) = 1;
1673 /* The loop is added to the current block the for
1674 statement is defined within */
1675 java_method_add_stmt (current_function_decl, $$);
1678 for_init: /* Can be empty */
1679 { $$ = empty_stmt_node; }
1680 | statement_expression_list
1682 /* Init statement recorded within the previously
1683 defined block scope */
1684 $$ = java_method_add_stmt (current_function_decl, $1);
1686 | local_variable_declaration
1688 /* Local variable are recorded within the previously
1689 defined block scope */
1692 | statement_expression_list error
1693 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1696 for_update: /* Can be empty */
1697 {$$ = empty_stmt_node;}
1698 | statement_expression_list
1699 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1702 statement_expression_list:
1703 statement_expression
1704 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1705 | statement_expression_list C_TK statement_expression
1706 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1707 | statement_expression_list C_TK error
1708 {yyerror ("Missing term"); RECOVER;}
1713 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1714 | BREAK_TK identifier SC_TK
1715 { $$ = build_bc_statement ($1.location, 1, $2); }
1717 {yyerror ("Missing term"); RECOVER;}
1718 | BREAK_TK identifier error
1719 {yyerror ("';' expected"); RECOVER;}
1724 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1725 | CONTINUE_TK identifier SC_TK
1726 { $$ = build_bc_statement ($1.location, 0, $2); }
1728 {yyerror ("Missing term"); RECOVER;}
1729 | CONTINUE_TK identifier error
1730 {yyerror ("';' expected"); RECOVER;}
1735 { $$ = build_return ($1.location, NULL_TREE); }
1736 | RETURN_TK expression SC_TK
1737 { $$ = build_return ($1.location, $2); }
1739 {yyerror ("Missing term"); RECOVER;}
1740 | RETURN_TK expression error
1741 {yyerror ("';' expected"); RECOVER;}
1745 THROW_TK expression SC_TK
1747 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1748 EXPR_WFL_LINECOL ($$) = $1.location;
1751 {yyerror ("Missing term"); RECOVER;}
1752 | THROW_TK expression error
1753 {yyerror ("';' expected"); RECOVER;}
1756 synchronized_statement:
1757 synchronized OP_TK expression CP_TK block
1759 $$ = build (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1760 EXPR_WFL_LINECOL ($$) =
1761 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1763 | synchronized OP_TK expression CP_TK error
1764 {yyerror ("'{' expected"); RECOVER;}
1765 | synchronized error
1766 {yyerror ("'(' expected"); RECOVER;}
1767 | synchronized OP_TK error CP_TK
1768 {yyerror ("Missing term"); RECOVER;}
1769 | synchronized OP_TK error
1770 {yyerror ("Missing term"); RECOVER;}
1777 "Illegal modifier `%s'. Only `synchronized' was expected here",
1778 $1, ACC_SYNCHRONIZED);
1779 if ($1 != ACC_SYNCHRONIZED)
1780 MODIFIER_WFL (SYNCHRONIZED_TK) =
1781 build_wfl_node (NULL_TREE);
1786 TRY_TK block catches
1787 { $$ = build_try_statement ($1.location, $2, $3); }
1788 | TRY_TK block finally
1789 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1790 | TRY_TK block catches finally
1791 { $$ = build_try_finally_statement
1792 ($1.location, build_try_statement ($1.location,
1796 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1801 | catches catch_clause
1803 TREE_CHAIN ($2) = $1;
1809 catch_clause_parameter block
1811 java_method_add_stmt (current_function_decl, $2);
1816 catch_clause_parameter:
1817 CATCH_TK OP_TK formal_parameter CP_TK
1819 /* We add a block to define a scope for
1820 formal_parameter (CCBP). The formal parameter is
1821 declared initialized by the appropriate function
1823 tree ccpb = enter_block ();
1824 tree init = build_assignment (ASSIGN_TK, $2.location,
1826 soft_exceptioninfo_call_node);
1827 declare_local_variables (0, TREE_VALUE ($3),
1828 build_tree_list (TREE_PURPOSE ($3),
1830 $$ = build1 (CATCH_EXPR, NULL_TREE, ccpb);
1831 EXPR_WFL_LINECOL ($$) = $1.location;
1834 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1835 | CATCH_TK OP_TK error
1837 yyerror ("Missing term or ')' expected");
1838 RECOVER; $$ = NULL_TREE;
1840 | CATCH_TK OP_TK error CP_TK /* That's for () */
1841 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1848 {yyerror ("'{' expected"); RECOVER; }
1851 /* 19.12 Production from 15: Expressions */
1853 primary_no_new_array
1854 | array_creation_expression
1857 primary_no_new_array:
1860 { $$ = build_this ($1.location); }
1861 | OP_TK expression CP_TK
1863 | class_instance_creation_expression
1868 /* Added, JDK1.1 inner classes. Documentation is wrong
1869 refering to a 'ClassName' (class_name) rule that doesn't
1870 exist. Used name: instead. */
1871 | name DOT_TK THIS_TK
1873 tree wfl = build_wfl_node (this_identifier_node);
1874 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
1876 | OP_TK expression error
1877 {yyerror ("')' expected"); RECOVER;}
1879 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1880 | primitive_type DOT_TK error
1881 {yyerror ("'class' expected" ); RECOVER;}
1882 | VOID_TK DOT_TK error
1883 {yyerror ("'class' expected" ); RECOVER;}
1886 /* Added, JDK1.1 type literals. We can't use `type' directly, so we
1887 broke the rule down a bit. */
1890 primitive_type OSB_TK CSB_TK
1892 $$ = build_java_array_type ($1, -1);
1893 CLASS_LOADED_P ($$) = 1;
1895 | name OSB_TK CSB_TK
1896 { $$ = build_unresolved_array_type ($1); }
1897 /* This triggers two reduce/reduce conflict between array_type_literal and
1899 | array_type OSB_TK CSB_TK
1900 { $$ = build_unresolved_array_type ($1); }
1905 name DOT_TK CLASS_TK
1906 { $$ = build_incomplete_class_ref ($2.location, $1); }
1907 | array_type_literal DOT_TK CLASS_TK
1908 { $$ = build_incomplete_class_ref ($2.location, $1); }
1909 | primitive_type DOT_TK CLASS_TK
1910 { $$ = build_class_ref ($1); }
1911 | VOID_TK DOT_TK CLASS_TK
1912 { $$ = build_class_ref (void_type_node); }
1915 class_instance_creation_expression:
1916 NEW_TK class_type OP_TK argument_list CP_TK
1917 { $$ = build_new_invocation ($2, $4); }
1918 | NEW_TK class_type OP_TK CP_TK
1919 { $$ = build_new_invocation ($2, NULL_TREE); }
1920 | anonymous_class_creation
1921 /* Added, JDK1.1 inner classes, modified to use name or
1922 primary instead of primary solely which couldn't work in
1924 | something_dot_new identifier OP_TK CP_TK
1926 tree ctor = build_new_invocation ($2, NULL_TREE);
1927 $$ = make_qualified_primary ($1, ctor,
1928 EXPR_WFL_LINECOL ($1));
1930 | something_dot_new identifier OP_TK CP_TK class_body
1931 | something_dot_new identifier OP_TK argument_list CP_TK
1933 tree ctor = build_new_invocation ($2, $4);
1934 $$ = make_qualified_primary ($1, ctor,
1935 EXPR_WFL_LINECOL ($1));
1937 | something_dot_new identifier OP_TK argument_list CP_TK class_body
1938 | NEW_TK error SC_TK
1939 {yyerror ("'(' expected"); DRECOVER(new_1);}
1940 | NEW_TK class_type error
1941 {yyerror ("'(' expected"); RECOVER;}
1942 | NEW_TK class_type OP_TK error
1943 {yyerror ("')' or term expected"); RECOVER;}
1944 | NEW_TK class_type OP_TK argument_list error
1945 {yyerror ("')' expected"); RECOVER;}
1946 | something_dot_new error
1947 {YYERROR_NOW; yyerror ("Identifier expected"); RECOVER;}
1948 | something_dot_new identifier error
1949 {yyerror ("'(' expected"); RECOVER;}
1952 /* Created after JDK1.1 rules originally added to
1953 class_instance_creation_expression, but modified to use
1954 'class_type' instead of 'TypeName' (type_name) which is mentionned
1955 in the documentation but doesn't exist. */
1957 anonymous_class_creation:
1958 NEW_TK class_type OP_TK argument_list CP_TK
1959 { create_anonymous_class ($1.location, $2); }
1962 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
1963 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
1965 end_class_declaration (1);
1967 /* Now we can craft the new expression */
1968 $$ = build_new_invocation (id, $4);
1970 /* Note that we can't possibly be here if
1971 `class_type' is an interface (in which case the
1972 anonymous class extends Object and implements
1973 `class_type', hence its constructor can't have
1976 /* Otherwise, the innerclass must feature a
1977 constructor matching `argument_list'. Anonymous
1978 classes are a bit special: it's impossible to
1979 define constructor for them, hence constructors
1980 must be generated following the hints provided by
1981 the `new' expression. Whether a super constructor
1982 of that nature exists or not is to be verified
1983 later on in verify_constructor_super.
1985 It's during the expansion of a `new' statement
1986 refering to an anonymous class that a ctor will
1987 be generated for the anonymous class, with the
1991 | NEW_TK class_type OP_TK CP_TK
1992 { create_anonymous_class ($1.location, $2); }
1995 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
1996 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
1998 end_class_declaration (1);
2000 /* Now we can craft the new expression. The
2001 statement doesn't need to be remember so that a
2002 constructor can be generated, since its signature
2003 is already known. */
2004 $$ = build_new_invocation (id, NULL_TREE);
2008 something_dot_new: /* Added, not part of the specs. */
2011 | primary DOT_TK NEW_TK
2018 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2019 ctxp->formal_parameter_number = 1;
2021 | argument_list C_TK expression
2023 ctxp->formal_parameter_number += 1;
2024 $$ = tree_cons (NULL_TREE, $3, $1);
2026 | argument_list C_TK error
2027 {yyerror ("Missing term"); RECOVER;}
2030 array_creation_expression:
2031 NEW_TK primitive_type dim_exprs
2032 { $$ = build_newarray_node ($2, $3, 0); }
2033 | NEW_TK class_or_interface_type dim_exprs
2034 { $$ = build_newarray_node ($2, $3, 0); }
2035 | NEW_TK primitive_type dim_exprs dims
2036 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
2037 | NEW_TK class_or_interface_type dim_exprs dims
2038 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
2039 /* Added, JDK1.1 anonymous array. Initial documentation rule
2041 | NEW_TK class_or_interface_type dims array_initializer
2044 while (CURRENT_OSB (ctxp)--)
2045 obstack_1grow (&temporary_obstack, '[');
2046 sig = obstack_finish (&temporary_obstack);
2047 $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2048 $2, get_identifier (sig), $4);
2050 | NEW_TK primitive_type dims array_initializer
2053 while (CURRENT_OSB (ctxp)--)
2054 type = build_java_array_type (type, -1);
2055 $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2056 build_pointer_type (type), NULL_TREE, $4);
2058 | NEW_TK error CSB_TK
2059 {yyerror ("'[' expected"); DRECOVER ("]");}
2060 | NEW_TK error OSB_TK
2061 {yyerror ("']' expected"); RECOVER;}
2066 { $$ = build_tree_list (NULL_TREE, $1); }
2067 | dim_exprs dim_expr
2068 { $$ = tree_cons (NULL_TREE, $2, $$); }
2072 OSB_TK expression CSB_TK
2074 EXPR_WFL_LINECOL ($2) = $1.location;
2077 | OSB_TK expression error
2078 {yyerror ("']' expected"); RECOVER;}
2081 yyerror ("Missing term");
2082 yyerror ("']' expected");
2091 /* If not initialized, allocate memory for the osb
2093 if (!ctxp->osb_limit)
2095 allocate = ctxp->osb_limit = 32;
2096 ctxp->osb_depth = -1;
2098 /* If capacity overflown, reallocate a bigger chunk */
2099 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2100 allocate = ctxp->osb_limit << 1;
2104 allocate *= sizeof (int);
2105 if (ctxp->osb_number)
2106 ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
2109 ctxp->osb_number = (int *)xmalloc (allocate);
2112 CURRENT_OSB (ctxp) = 1;
2114 | dims OSB_TK CSB_TK
2115 { CURRENT_OSB (ctxp)++; }
2117 { yyerror ("']' expected"); RECOVER;}
2121 primary DOT_TK identifier
2122 { $$ = make_qualified_primary ($1, $3, $2.location); }
2123 /* FIXME - REWRITE TO:
2124 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2125 | SUPER_TK DOT_TK identifier
2128 build_wfl_node (super_identifier_node);
2129 EXPR_WFL_LINECOL (super_wfl) = $1.location;
2130 $$ = make_qualified_name (super_wfl, $3, $2.location);
2133 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2138 { $$ = build_method_invocation ($1, NULL_TREE); }
2139 | name OP_TK argument_list CP_TK
2140 { $$ = build_method_invocation ($1, $3); }
2141 | primary DOT_TK identifier OP_TK CP_TK
2143 if (TREE_CODE ($1) == THIS_EXPR)
2144 $$ = build_this_super_qualified_invocation
2145 (1, $3, NULL_TREE, 0, $2.location);
2148 tree invok = build_method_invocation ($3, NULL_TREE);
2149 $$ = make_qualified_primary ($1, invok, $2.location);
2152 | primary DOT_TK identifier OP_TK argument_list CP_TK
2154 if (TREE_CODE ($1) == THIS_EXPR)
2155 $$ = build_this_super_qualified_invocation
2156 (1, $3, $5, 0, $2.location);
2159 tree invok = build_method_invocation ($3, $5);
2160 $$ = make_qualified_primary ($1, invok, $2.location);
2163 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2165 $$ = build_this_super_qualified_invocation
2166 (0, $3, NULL_TREE, $1.location, $2.location);
2168 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2170 $$ = build_this_super_qualified_invocation
2171 (0, $3, $5, $1.location, $2.location);
2173 /* Screws up thing. I let it here until I'm convinced it can
2175 | primary DOT_TK error
2176 {yyerror ("'(' expected"); DRECOVER(bad);} */
2177 | SUPER_TK DOT_TK error CP_TK
2178 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2179 | SUPER_TK DOT_TK error DOT_TK
2180 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2184 name OSB_TK expression CSB_TK
2185 { $$ = build_array_ref ($2.location, $1, $3); }
2186 | primary_no_new_array OSB_TK expression CSB_TK
2187 { $$ = build_array_ref ($2.location, $1, $3); }
2190 yyerror ("Missing term and ']' expected");
2191 DRECOVER(array_access);
2193 | name OSB_TK expression error
2195 yyerror ("']' expected");
2196 DRECOVER(array_access);
2198 | primary_no_new_array OSB_TK error
2200 yyerror ("Missing term and ']' expected");
2201 DRECOVER(array_access);
2203 | primary_no_new_array OSB_TK expression error
2205 yyerror ("']' expected");
2206 DRECOVER(array_access);
2213 | post_increment_expression
2214 | post_decrement_expression
2217 post_increment_expression:
2218 postfix_expression INCR_TK
2219 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2222 post_decrement_expression:
2223 postfix_expression DECR_TK
2224 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2228 pre_increment_expression
2229 | pre_decrement_expression
2230 | PLUS_TK unary_expression
2231 {$$ = build_unaryop ($1.token, $1.location, $2); }
2232 | MINUS_TK unary_expression
2233 {$$ = build_unaryop ($1.token, $1.location, $2); }
2234 | unary_expression_not_plus_minus
2236 {yyerror ("Missing term"); RECOVER}
2238 {yyerror ("Missing term"); RECOVER}
2241 pre_increment_expression:
2242 INCR_TK unary_expression
2243 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2245 {yyerror ("Missing term"); RECOVER}
2248 pre_decrement_expression:
2249 DECR_TK unary_expression
2250 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2252 {yyerror ("Missing term"); RECOVER}
2255 unary_expression_not_plus_minus:
2257 | NOT_TK unary_expression
2258 {$$ = build_unaryop ($1.token, $1.location, $2); }
2259 | NEG_TK unary_expression
2260 {$$ = build_unaryop ($1.token, $1.location, $2); }
2263 {yyerror ("Missing term"); RECOVER}
2265 {yyerror ("Missing term"); RECOVER}
2268 cast_expression: /* Error handling here is potentially weak */
2269 OP_TK primitive_type dims CP_TK unary_expression
2272 while (CURRENT_OSB (ctxp)--)
2273 type = build_java_array_type (type, -1);
2275 $$ = build_cast ($1.location, type, $5);
2277 | OP_TK primitive_type CP_TK unary_expression
2278 { $$ = build_cast ($1.location, $2, $4); }
2279 | OP_TK expression CP_TK unary_expression_not_plus_minus
2280 { $$ = build_cast ($1.location, $2, $4); }
2281 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2284 while (CURRENT_OSB (ctxp)--)
2285 obstack_1grow (&temporary_obstack, '[');
2287 obstack_grow0 (&temporary_obstack,
2288 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2289 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2290 ptr = obstack_finish (&temporary_obstack);
2291 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2292 $$ = build_cast ($1.location, $2, $5);
2294 | OP_TK primitive_type OSB_TK error
2295 {yyerror ("']' expected, invalid type expression");}
2298 if (ctxp->prevent_ese != lineno)
2299 yyerror ("Invalid type expression"); RECOVER;
2302 | OP_TK primitive_type dims CP_TK error
2303 {yyerror ("Missing term"); RECOVER;}
2304 | OP_TK primitive_type CP_TK error
2305 {yyerror ("Missing term"); RECOVER;}
2306 | OP_TK name dims CP_TK error
2307 {yyerror ("Missing term"); RECOVER;}
2310 multiplicative_expression:
2312 | multiplicative_expression MULT_TK unary_expression
2314 $$ = build_binop (BINOP_LOOKUP ($2.token),
2315 $2.location, $1, $3);
2317 | multiplicative_expression DIV_TK unary_expression
2319 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2322 | multiplicative_expression REM_TK unary_expression
2324 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2327 | multiplicative_expression MULT_TK error
2328 {yyerror ("Missing term"); RECOVER;}
2329 | multiplicative_expression DIV_TK error
2330 {yyerror ("Missing term"); RECOVER;}
2331 | multiplicative_expression REM_TK error
2332 {yyerror ("Missing term"); RECOVER;}
2335 additive_expression:
2336 multiplicative_expression
2337 | additive_expression PLUS_TK multiplicative_expression
2339 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2342 | additive_expression MINUS_TK multiplicative_expression
2344 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2347 | additive_expression PLUS_TK error
2348 {yyerror ("Missing term"); RECOVER;}
2349 | additive_expression MINUS_TK error
2350 {yyerror ("Missing term"); RECOVER;}
2355 | shift_expression LS_TK additive_expression
2357 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2360 | shift_expression SRS_TK additive_expression
2362 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2365 | shift_expression ZRS_TK additive_expression
2367 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2370 | shift_expression LS_TK error
2371 {yyerror ("Missing term"); RECOVER;}
2372 | shift_expression SRS_TK error
2373 {yyerror ("Missing term"); RECOVER;}
2374 | shift_expression ZRS_TK error
2375 {yyerror ("Missing term"); RECOVER;}
2378 relational_expression:
2380 | relational_expression LT_TK shift_expression
2382 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2385 | relational_expression GT_TK shift_expression
2387 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2390 | relational_expression LTE_TK shift_expression
2392 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2395 | relational_expression GTE_TK shift_expression
2397 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2400 | relational_expression INSTANCEOF_TK reference_type
2401 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2402 | relational_expression LT_TK error
2403 {yyerror ("Missing term"); RECOVER;}
2404 | relational_expression GT_TK error
2405 {yyerror ("Missing term"); RECOVER;}
2406 | relational_expression LTE_TK error
2407 {yyerror ("Missing term"); RECOVER;}
2408 | relational_expression GTE_TK error
2409 {yyerror ("Missing term"); RECOVER;}
2410 | relational_expression INSTANCEOF_TK error
2411 {yyerror ("Invalid reference type"); RECOVER;}
2414 equality_expression:
2415 relational_expression
2416 | equality_expression EQ_TK relational_expression
2418 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2421 | equality_expression NEQ_TK relational_expression
2423 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2426 | equality_expression EQ_TK error
2427 {yyerror ("Missing term"); RECOVER;}
2428 | equality_expression NEQ_TK error
2429 {yyerror ("Missing term"); RECOVER;}
2434 | and_expression AND_TK equality_expression
2436 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2439 | and_expression AND_TK error
2440 {yyerror ("Missing term"); RECOVER;}
2443 exclusive_or_expression:
2445 | exclusive_or_expression XOR_TK and_expression
2447 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2450 | exclusive_or_expression XOR_TK error
2451 {yyerror ("Missing term"); RECOVER;}
2454 inclusive_or_expression:
2455 exclusive_or_expression
2456 | inclusive_or_expression OR_TK exclusive_or_expression
2458 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2461 | inclusive_or_expression OR_TK error
2462 {yyerror ("Missing term"); RECOVER;}
2465 conditional_and_expression:
2466 inclusive_or_expression
2467 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2469 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2472 | conditional_and_expression BOOL_AND_TK error
2473 {yyerror ("Missing term"); RECOVER;}
2476 conditional_or_expression:
2477 conditional_and_expression
2478 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2480 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2483 | conditional_or_expression BOOL_OR_TK error
2484 {yyerror ("Missing term"); RECOVER;}
2487 conditional_expression: /* Error handling here is weak */
2488 conditional_or_expression
2489 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2491 $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2492 EXPR_WFL_LINECOL ($$) = $2.location;
2494 | conditional_or_expression REL_QM_TK REL_CL_TK error
2497 yyerror ("Missing term");
2500 | conditional_or_expression REL_QM_TK error
2501 {yyerror ("Missing term"); DRECOVER (2);}
2502 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2503 {yyerror ("Missing term"); DRECOVER (3);}
2506 assignment_expression:
2507 conditional_expression
2512 left_hand_side assignment_operator assignment_expression
2513 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2514 | left_hand_side assignment_operator error
2516 if (ctxp->prevent_ese != lineno)
2517 yyerror ("Missing term");
2528 assignment_operator:
2534 assignment_expression
2537 constant_expression:
2544 /* This section of the code deal with save/restoring parser contexts.
2545 Add mode documentation here. FIXME */
2547 /* Helper function. Create a new parser context. With
2548 COPY_FROM_PREVIOUS set to a non zero value, content of the previous
2549 context is copied, otherwise, the new context is zeroed. The newly
2550 created context becomes the current one. */
2553 create_new_parser_context (copy_from_previous)
2554 int copy_from_previous;
2556 struct parser_ctxt *new;
2558 new = (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2559 if (copy_from_previous)
2561 memcpy ((PTR)new, (PTR)ctxp, sizeof (struct parser_ctxt));
2562 new->saved_data_ctx = 1;
2565 bzero ((PTR) new, sizeof (struct parser_ctxt));
2571 /* Create a new parser context and make it the current one. */
2574 java_push_parser_context ()
2576 create_new_parser_context (0);
2579 ctxp->incomplete_class = ctxp->next->incomplete_class;
2580 ctxp->gclass_list = ctxp->next->gclass_list;
2585 java_pop_parser_context (generate)
2589 struct parser_ctxt *toFree, *next;
2598 next->incomplete_class = ctxp->incomplete_class;
2599 next->gclass_list = ctxp->gclass_list;
2600 lineno = ctxp->lineno;
2601 finput = ctxp->finput;
2602 current_class = ctxp->current_class;
2605 /* Set the single import class file flag to 0 for the current list
2606 of imported things */
2607 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2608 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 0;
2610 /* And restore those of the previous context */
2611 if ((ctxp = next)) /* Assignment is really meant here */
2612 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2613 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
2615 /* If we pushed a context to parse a class intended to be generated,
2616 we keep it so we can remember the class. What we could actually
2617 do is to just update a list of class names. */
2620 toFree->next = ctxp_for_generation;
2621 ctxp_for_generation = toFree;
2627 /* Create a parser context for the use of saving some global
2631 java_parser_context_save_global ()
2635 java_push_parser_context ();
2636 ctxp->saved_data_ctx = 1;
2639 /* If this context already stores data, create a new one suitable
2640 for data storage. */
2641 else if (ctxp->saved_data)
2642 create_new_parser_context (1);
2644 ctxp->finput = finput;
2645 ctxp->lineno = lineno;
2646 ctxp->current_class = current_class;
2647 ctxp->filename = input_filename;
2648 ctxp->current_function_decl = current_function_decl;
2649 ctxp->saved_data = 1;
2652 /* Restore some global variables from the previous context. Make the
2653 previous context the current one. */
2656 java_parser_context_restore_global ()
2658 finput = ctxp->finput;
2659 lineno = ctxp->lineno;
2660 current_class = ctxp->current_class;
2661 input_filename = ctxp->filename;
2662 current_function_decl = ctxp->current_function_decl;
2663 ctxp->saved_data = 0;
2664 if (ctxp->saved_data_ctx)
2665 java_pop_parser_context (0);
2668 /* Suspend vital data for the current class/function being parsed so
2669 that an other class can be parsed. Used to let local/anonymous
2670 classes be parsed. */
2673 java_parser_context_suspend ()
2675 /* This makes debugging through java_debug_context easier */
2676 static char *name = "<inner buffer context>";
2678 /* Duplicate the previous context, use it to save the globals we're
2680 create_new_parser_context (1);
2681 ctxp->current_function_decl = current_function_decl;
2682 ctxp->current_class = current_class;
2684 /* Then create a new context which inherits all data from the
2685 previous one. This will be the new current context */
2686 create_new_parser_context (1);
2688 /* Help debugging */
2689 ctxp->next->filename = name;
2692 /* Resume vital data for the current class/function being parsed so
2693 that an other class can be parsed. Used to let local/anonymous
2694 classes be parsed. The trick is the data storing file position
2695 informations must be restored to their current value, so parsing
2696 can resume as if no context was ever saved. */
2699 java_parser_context_resume ()
2701 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2702 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2703 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2705 /* We need to inherit the list of classes to complete/generate */
2706 restored->incomplete_class = old->incomplete_class;
2707 restored->gclass_list = old->gclass_list;
2708 restored->classd_list = old->classd_list;
2709 restored->class_list = old->class_list;
2711 /* Restore the current class and function from the saver */
2712 current_class = saver->current_class;
2713 current_function_decl = saver->current_function_decl;
2715 /* Retrive the restored context */
2718 /* Re-installed the data for the parsing to carry on */
2719 bcopy (&old->marker_begining, &ctxp->marker_begining,
2720 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2722 /* Buffer context can now be discarded */
2727 /* Add a new anchor node to which all statement(s) initializing static
2728 and non static initialized upon declaration field(s) will be
2732 java_parser_context_push_initialized_field ()
2736 node = build_tree_list (NULL_TREE, NULL_TREE);
2737 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2738 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2740 node = build_tree_list (NULL_TREE, NULL_TREE);
2741 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2742 CPC_INITIALIZER_LIST (ctxp) = node;
2744 node = build_tree_list (NULL_TREE, NULL_TREE);
2745 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2746 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2749 /* Pop the lists of initialized field. If this lists aren't empty,
2750 remember them so we can use it to create and populate the $finit$
2751 or <clinit> functions. */
2754 java_parser_context_pop_initialized_field ()
2757 tree class_type = TREE_TYPE (GET_CPC ());
2759 if (CPC_INITIALIZER_LIST (ctxp))
2761 stmts = CPC_INITIALIZER_STMT (ctxp);
2762 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2763 if (stmts && !java_error_count)
2764 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2767 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2769 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2770 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2771 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2772 /* Keep initialization in order to enforce 8.5 */
2773 if (stmts && !java_error_count)
2774 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2777 /* JDK 1.1 instance initializers */
2778 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2780 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2781 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2782 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2783 if (stmts && !java_error_count)
2784 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2789 reorder_static_initialized (list)
2792 /* We have to keep things in order. The alias initializer have to
2793 come first, then the initialized regular field, in reverse to
2794 keep them in lexical order. */
2795 tree marker, previous = NULL_TREE;
2796 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2797 if (TREE_CODE (marker) == TREE_LIST
2798 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2801 /* No static initialized, the list is fine as is */
2803 list = TREE_CHAIN (marker);
2805 /* No marker? reverse the whole list */
2807 list = nreverse (list);
2809 /* Otherwise, reverse what's after the marker and the new reordered
2810 sublist will replace the marker. */
2813 TREE_CHAIN (previous) = NULL_TREE;
2814 list = nreverse (list);
2815 list = chainon (TREE_CHAIN (marker), list);
2820 /* Helper functions to dump the parser context stack. */
2822 #define TAB_CONTEXT(C) \
2823 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2826 java_debug_context_do (tab)
2829 struct parser_ctxt *copy = ctxp;
2833 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2835 fprintf (stderr, "filename: %s\n", copy->filename);
2837 fprintf (stderr, "lineno: %d\n", copy->lineno);
2839 fprintf (stderr, "package: %s\n",
2841 IDENTIFIER_POINTER (copy->package) : "<none>"));
2843 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2845 fprintf (stderr, "saved data: %d\n", copy->saved_data);
2851 /* Dump the stacked up parser contexts. Intended to be called from a
2855 java_debug_context ()
2857 java_debug_context_do (0);
2862 /* Flag for the error report routine to issue the error the first time
2863 it's called (overriding the default behavior which is to drop the
2864 first invocation and honor the second one, taking advantage of a
2866 static int force_error = 0;
2868 /* Reporting an constructor invocation error. */
2870 parse_ctor_invocation_error ()
2872 if (DECL_CONSTRUCTOR_P (current_function_decl))
2873 yyerror ("Constructor invocation must be first thing in a constructor");
2875 yyerror ("Only constructors can invoke constructors");
2878 /* Reporting JDK1.1 features not implemented. */
2881 parse_jdk1_1_error (msg)
2884 sorry (": `%s' JDK1.1(TM) feature", msg);
2886 return empty_stmt_node;
2889 static int do_warning = 0;
2896 static int prev_lineno;
2897 static const char *prev_msg;
2900 char *remainder, *code_from_source;
2901 extern struct obstack temporary_obstack;
2903 if (!force_error && prev_lineno == lineno)
2906 /* Save current error location but report latter, when the context is
2908 if (ctxp->java_error_flag == 0)
2910 ctxp->java_error_flag = 1;
2912 /* Do something to use the previous line if we're reaching the
2913 end of the file... */
2914 #ifdef VERBOSE_SKELETON
2915 printf ("* Error detected (%s)\n", (msg ? msg : "(null)"));
2920 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2921 if (!force_error && msg == prev_msg && prev_lineno == elc.line)
2924 ctxp->java_error_flag = 0;
2926 java_warning_count++;
2930 if (elc.col == 0 && msg[1] == ';')
2932 elc.col = ctxp->p_line->char_col-1;
2933 elc.line = ctxp->p_line->lineno;
2936 save_lineno = lineno;
2937 prev_lineno = lineno = elc.line;
2940 code_from_source = java_get_line_col (ctxp->filename, elc.line, elc.col);
2941 obstack_grow0 (&temporary_obstack,
2942 code_from_source, strlen (code_from_source));
2943 remainder = obstack_finish (&temporary_obstack);
2945 warning ("%s.\n%s", msg, remainder);
2947 error ("%s.\n%s", msg, remainder);
2949 /* This allow us to cheaply avoid an extra 'Invalid expression
2950 statement' error report when errors have been already reported on
2951 the same line. This occurs when we report an error but don't have
2952 a synchronization point other than ';', which
2953 expression_statement is the only one to take care of. */
2954 ctxp->prevent_ese = lineno = save_lineno;
2958 issue_warning_error_from_context (cl, msg, ap)
2963 char *saved, *saved_input_filename;
2965 vsprintf (buffer, msg, ap);
2968 ctxp->elc.line = EXPR_WFL_LINENO (cl);
2969 ctxp->elc.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 :
2970 (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
2972 /* We have a CL, that's a good reason for using it if it contains data */
2973 saved = ctxp->filename;
2974 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
2975 ctxp->filename = EXPR_WFL_FILENAME (cl);
2976 saved_input_filename = input_filename;
2977 input_filename = ctxp->filename;
2979 java_error (buffer);
2980 ctxp->filename = saved;
2981 input_filename = saved_input_filename;
2985 /* Issue an error message at a current source line CL */
2988 parse_error_context VPARAMS ((tree cl, const char *msg, ...))
2990 #ifndef ANSI_PROTOTYPES
2997 #ifndef ANSI_PROTOTYPES
2998 cl = va_arg (ap, tree);
2999 msg = va_arg (ap, const char *);
3001 issue_warning_error_from_context (cl, msg, ap);
3005 /* Issue a warning at a current source line CL */
3008 parse_warning_context VPARAMS ((tree cl, const char *msg, ...))
3010 #ifndef ANSI_PROTOTYPES
3017 #ifndef ANSI_PROTOTYPES
3018 cl = va_arg (ap, tree);
3019 msg = va_arg (ap, const char *);
3022 force_error = do_warning = 1;
3023 issue_warning_error_from_context (cl, msg, ap);
3024 do_warning = force_error = 0;
3029 find_expr_with_wfl (node)
3037 switch (TREE_CODE (node))
3040 node = BLOCK_EXPR_BODY (node);
3044 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3047 node = TREE_OPERAND (node, 1);
3051 node = TREE_OPERAND (node, 0);
3054 case LABELED_BLOCK_EXPR:
3055 node = TREE_OPERAND (node, 1);
3059 code = TREE_CODE_CLASS (TREE_CODE (node));
3060 if (((code == '1') || (code == '2') || (code == 'e'))
3061 && EXPR_WFL_LINECOL (node))
3069 /* Issue a missing return statement error. Uses METHOD to figure the
3070 last line of the method the error occurs in. */
3073 missing_return_error (method)
3076 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
3077 parse_error_context (wfl_operator, "Missing return statement");
3080 /* Issue an unreachable statement error. From NODE, find the next
3081 statement to report appropriately. */
3083 unreachable_stmt_error (node)
3086 /* Browse node to find the next expression node that has a WFL. Use
3087 the location to report the error */
3088 if (TREE_CODE (node) == COMPOUND_EXPR)
3089 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3091 node = find_expr_with_wfl (node);
3095 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3096 parse_error_context (wfl_operator, "Unreachable statement");
3099 fatal ("Can't get valid statement - unreachable_stmt_error");
3103 java_report_errors ()
3105 if (java_error_count)
3106 fprintf (stderr, "%d error%s",
3107 java_error_count, (java_error_count == 1 ? "" : "s"));
3108 if (java_warning_count)
3109 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3110 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3111 if (java_error_count || java_warning_count)
3112 putc ('\n', stderr);
3113 return java_error_count;
3117 java_accstring_lookup (flags)
3120 static char buffer [80];
3121 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3123 /* Access modifier looked-up first for easier report on forbidden
3125 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3126 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3127 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3128 if (flags & ACC_STATIC) COPY_RETURN ("static");
3129 if (flags & ACC_FINAL) COPY_RETURN ("final");
3130 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3131 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3132 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3133 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3134 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3135 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3142 /* Issuing error messages upon redefinition of classes, interfaces or
3146 classitf_redefinition_error (context, id, decl, cl)
3147 const char *context;
3150 parse_error_context (cl, "%s `%s' already defined in %s:%d",
3151 context, IDENTIFIER_POINTER (id),
3152 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3153 /* Here we should point out where its redefined. It's a unicode. FIXME */
3157 variable_redefinition_error (context, name, type, line)
3158 tree context, name, type;
3161 const char *type_name;
3163 /* Figure a proper name for type. We might haven't resolved it */
3164 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3165 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3167 type_name = lang_printable_name (type, 0);
3169 parse_error_context (context,
3170 "Variable `%s' is already defined in this method and was declared `%s %s' at line %d",
3171 IDENTIFIER_POINTER (name),
3172 type_name, IDENTIFIER_POINTER (name), line);
3176 build_array_from_name (type, type_wfl, name, ret_name)
3177 tree type, type_wfl, name, *ret_name;
3182 /* Eventually get more dims */
3183 string = IDENTIFIER_POINTER (name);
3184 while (string [more_dims] == '[')
3187 /* If we have, then craft a new type for this variable */
3190 name = get_identifier (&string [more_dims]);
3192 /* If we have a pointer, use its type */
3193 if (TREE_CODE (type) == POINTER_TYPE)
3194 type = TREE_TYPE (type);
3196 /* Building the first dimension of a primitive type uses this
3198 if (JPRIMITIVE_TYPE_P (type))
3200 type = build_java_array_type (type, -1);
3201 CLASS_LOADED_P (type) = 1;
3204 /* Otherwise, if we have a WFL for this type, use it (the type
3205 is already an array on an unresolved type, and we just keep
3206 on adding dimensions) */
3210 /* Add all the dimensions */
3212 type = build_unresolved_array_type (type);
3214 /* The type may have been incomplete in the first place */
3216 type = obtain_incomplete_type (type);
3224 /* Build something that the type identifier resolver will identify as
3225 being an array to an unresolved type. TYPE_WFL is a WFL on a
3229 build_unresolved_array_type (type_or_wfl)
3234 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3235 just create a array type */
3236 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3238 tree type = build_java_array_type (type_or_wfl, -1);
3239 CLASS_LOADED_P (type) = CLASS_LOADED_P (type_or_wfl);
3243 obstack_1grow (&temporary_obstack, '[');
3244 obstack_grow0 (&temporary_obstack,
3245 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3246 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3247 ptr = obstack_finish (&temporary_obstack);
3248 return build_expr_wfl (get_identifier (ptr),
3249 EXPR_WFL_FILENAME (type_or_wfl),
3250 EXPR_WFL_LINENO (type_or_wfl),
3251 EXPR_WFL_COLNO (type_or_wfl));
3255 parser_add_interface (class_decl, interface_decl, wfl)
3256 tree class_decl, interface_decl, wfl;
3258 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3259 parse_error_context (wfl, "Interface `%s' repeated",
3260 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3263 /* Bulk of common class/interface checks. Return 1 if an error was
3264 encountered. TAG is 0 for a class, 1 for an interface. */
3267 check_class_interface_creation (is_interface, flags, raw_name, qualified_name, decl, cl)
3268 int is_interface, flags;
3269 tree raw_name, qualified_name, decl, cl;
3272 int sca = 0; /* Static class allowed */
3273 int icaf = 0; /* Inner class allowed flags */
3274 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3277 fprintf (stderr, " %s%s %s",
3278 (CPC_INNER_P () ? "inner" : ""),
3279 (is_interface ? "interface" : "class"),
3280 IDENTIFIER_POINTER (qualified_name));
3282 /* Scope of an interface/class type name:
3283 - Can't be imported by a single type import
3284 - Can't already exists in the package */
3285 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3286 && (node = find_name_in_single_imports (raw_name)))
3289 (cl, "%s name `%s' clashes with imported type `%s'",
3290 (is_interface ? "Interface" : "Class"),
3291 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
3294 if (decl && CLASS_COMPLETE_P (decl))
3296 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
3297 qualified_name, decl, cl);
3301 if (check_inner_class_redefinition (raw_name, cl))
3304 /* If public, file name should match class/interface name, except
3305 when dealing with an inner class */
3306 if (!CPC_INNER_P () && (flags & ACC_PUBLIC ))
3310 /* Contains OS dependent assumption on path separator. FIXME */
3311 for (f = &input_filename [strlen (input_filename)];
3312 f != input_filename && f[0] != '/' && f[0] != DIR_SEPARATOR;
3315 if (f[0] == '/' || f[0] == DIR_SEPARATOR)
3317 if (strncmp (IDENTIFIER_POINTER (raw_name),
3318 f , IDENTIFIER_LENGTH (raw_name)) ||
3319 f [IDENTIFIER_LENGTH (raw_name)] != '.')
3321 (cl, "Public %s `%s' must be defined in a file called `%s.java'",
3322 (is_interface ? "interface" : "class"),
3323 IDENTIFIER_POINTER (qualified_name),
3324 IDENTIFIER_POINTER (raw_name));
3327 /* Static classes can be declared only in top level classes. Note:
3328 once static, a inner class is a top level class. */
3329 if (flags & ACC_STATIC)
3331 /* Catch the specific error of declaring an class inner class
3332 with no toplevel enclosing class. Prevent check_modifiers from
3333 complaining a second time */
3334 if (CPC_INNER_P () && !TOPLEVEL_CLASS_DECL_P (GET_CPC()))
3336 parse_error_context (cl, "Inner class `%s' can't be static. Static classes can only occur in interfaces and top-level classes",
3337 IDENTIFIER_POINTER (qualified_name));
3340 /* Else, in the context of a top-level class declaration, let
3341 `check_modifiers' do its job, otherwise, give it a go */
3343 sca = (GET_CPC_LIST () ? ACC_STATIC : 0);
3346 /* Inner classes and interfaces can be declared private or protected
3347 within their enclosing classes. */
3350 /* A class which is local to a block can't be public, private,
3351 protected or static. But it is created final, so allow this
3353 if (current_function_decl)
3354 icaf = sca = uaaf = ACC_FINAL;
3357 check_modifiers_consistency (flags);
3358 icaf = ACC_PRIVATE|ACC_PROTECTED;
3363 check_modifiers ("Illegal modifier `%s' for interface declaration",
3364 flags, INTERFACE_MODIFIERS);
3366 check_modifiers ("Illegal modifier `%s' for class declaration",
3367 flags, uaaf|sca|icaf);
3372 make_nested_class_name (cpc_list)
3380 make_nested_class_name (TREE_CHAIN (cpc_list));
3382 /* Pick the qualified name when dealing with the first upmost
3384 name = (TREE_CHAIN (cpc_list) ?
3385 TREE_PURPOSE (cpc_list) : DECL_NAME (TREE_VALUE (cpc_list)));
3386 obstack_grow (&temporary_obstack,
3387 IDENTIFIER_POINTER (name), IDENTIFIER_LENGTH (name));
3388 /* Why is NO_DOLLAR_IN_LABEL defined? */
3390 #ifdef NO_DOLLAR_IN_LABEL
3391 fatal ("make_nested_class_name: Can't use '$' as a separator "
3392 "for inner classes");
3395 obstack_1grow (&temporary_obstack, '$');
3398 /* Can't redefine a class already defined in an earlier scope. */
3401 check_inner_class_redefinition (raw_name, cl)
3406 for (scope_list = GET_CPC_LIST (); scope_list;
3407 scope_list = GET_NEXT_ENCLOSING_CPC (scope_list))
3408 if (raw_name == GET_CPC_UN_NODE (scope_list))
3411 (cl, "The class name `%s' is already defined in this scope. An inner class may not have the same simple name as any of its enclosing classes",
3412 IDENTIFIER_POINTER (raw_name));
3419 find_as_inner_class (enclosing, name, cl)
3420 tree enclosing, name, cl;
3422 tree qual, to_return;
3426 name = TYPE_NAME (name);
3428 /* First search: within the scope of `enclosing', search for name */
3429 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3430 qual = EXPR_WFL_QUALIFICATION (cl);
3432 qual = build_tree_list (cl, NULL_TREE);
3434 qual = build_tree_list (build_expr_wfl (name, NULL, 0, 0), NULL_TREE);
3436 if ((to_return = find_as_inner_class_do (qual, enclosing)))
3439 /* We're dealing with a qualified name. Try to resolve thing until
3440 we get something that is an enclosing class. */
3441 if (QUALIFIED_P (name) && cl && EXPR_WFL_NODE (cl) == name)
3443 tree acc = NULL_TREE, decl = NULL_TREE, ptr;
3445 for(qual = EXPR_WFL_QUALIFICATION (cl); qual && !decl;
3446 qual = TREE_CHAIN (qual))
3448 acc = merge_qualified_name (acc,
3449 EXPR_WFL_NODE (TREE_PURPOSE (qual)));
3450 BUILD_PTR_FROM_NAME (ptr, acc);
3451 decl = do_resolve_class (NULL_TREE, ptr, NULL_TREE, cl);
3454 /* A NULL qual and a decl means that the search ended
3455 successfully?!? We have to do something then. FIXME */
3460 qual = EXPR_WFL_QUALIFICATION (cl);
3462 /* Otherwise, create a qual for the other part of the resolution. */
3464 qual = build_tree_list (build_expr_wfl (name, NULL, 0, 0), NULL_TREE);
3466 return find_as_inner_class_do (qual, enclosing);
3469 /* We go inside the list of sub classes and try to find a way
3473 find_as_inner_class_do (qual, enclosing)
3474 tree qual, enclosing;
3479 for (; qual && enclosing; qual = TREE_CHAIN (qual))
3481 tree name_to_match = EXPR_WFL_NODE (TREE_PURPOSE (qual));
3482 tree next_enclosing = NULL_TREE;
3485 for (inner_list = DECL_INNER_CLASS_LIST (enclosing);
3486 inner_list; inner_list = TREE_CHAIN (inner_list))
3488 if (TREE_VALUE (inner_list) == name_to_match)
3490 next_enclosing = TREE_PURPOSE (inner_list);
3494 enclosing = next_enclosing;
3497 return (!qual && enclosing ? enclosing : NULL_TREE);
3500 /* Reach all inner classes and tie their unqualified name to a
3504 set_nested_class_simple_name_value (outer, set)
3510 for (l = DECL_INNER_CLASS_LIST (outer); l; l = TREE_CHAIN (l))
3511 IDENTIFIER_GLOBAL_VALUE (TREE_VALUE (l)) = (set ?
3512 TREE_PURPOSE (l) : NULL_TREE);
3516 link_nested_class_to_enclosing ()
3518 if (GET_ENCLOSING_CPC ())
3520 tree enclosing = GET_ENCLOSING_CPC_CONTEXT ();
3521 DECL_INNER_CLASS_LIST (enclosing) =
3522 tree_cons (GET_CPC (), GET_CPC_UN (),
3523 DECL_INNER_CLASS_LIST (enclosing));
3524 enclosing = enclosing;
3529 maybe_make_nested_class_name (name)
3532 tree id = NULL_TREE;
3536 make_nested_class_name (GET_CPC_LIST ());
3537 obstack_grow (&temporary_obstack,
3538 IDENTIFIER_POINTER (name),
3539 IDENTIFIER_LENGTH (name));
3540 id = get_identifier (obstack_finish (&temporary_obstack));
3542 QUALIFIED_P (id) = 1;
3547 /* If DECL is NULL, create and push a new DECL, record the current
3548 line CL and do other maintenance things. */
3551 maybe_create_class_interface_decl (decl, raw_name, qualified_name, cl)
3552 tree decl, raw_name, qualified_name, cl;
3555 decl = push_class (make_class (), qualified_name);
3557 /* Take care of the file and line business */
3558 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
3559 /* If we're emiting xrefs, store the line/col number information */
3561 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (cl);
3563 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
3564 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
3565 CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (TREE_TYPE (decl)) =
3566 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
3568 PUSH_CPC (decl, raw_name);
3569 DECL_CONTEXT (decl) = GET_ENCLOSING_CPC_CONTEXT ();
3571 /* Link the declaration to the already seen ones */
3572 TREE_CHAIN (decl) = ctxp->class_list;
3573 ctxp->class_list = decl;
3575 /* Create a new nodes in the global lists */
3576 ctxp->gclass_list = tree_cons (NULL_TREE, decl, ctxp->gclass_list);
3577 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
3579 /* Install a new dependency list element */
3580 create_jdep_list (ctxp);
3582 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
3583 IDENTIFIER_POINTER (qualified_name)));
3588 add_superinterfaces (decl, interface_list)
3589 tree decl, interface_list;
3592 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3593 takes care of ensuring that:
3594 - This is an accessible interface type,
3595 - Circularity detection.
3596 parser_add_interface is then called. If present but not defined,
3597 the check operation is delayed until the super interface gets
3599 for (node = interface_list; node; node = TREE_CHAIN (node))
3601 tree current = TREE_PURPOSE (node);
3602 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
3603 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
3605 if (!parser_check_super_interface (idecl, decl, current))
3606 parser_add_interface (decl, idecl, current);
3609 register_incomplete_type (JDEP_INTERFACE,
3610 current, decl, NULL_TREE);
3614 /* Create an interface in pass1 and return its decl. Return the
3615 interface's decl in pass 2. */
3618 create_interface (flags, id, super)
3622 tree raw_name = EXPR_WFL_NODE (id);
3623 tree q_name = parser_qualified_classname (flags & ACC_STATIC, raw_name);
3624 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
3626 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
3628 /* Basic checks: scope, redefinition, modifiers */
3629 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
3635 /* Suspend the current parsing context if we're parsing an inner
3638 java_parser_context_suspend ();
3640 /* Push a new context for (static) initialized upon declaration fields */
3641 java_parser_context_push_initialized_field ();
3643 /* Interface modifiers check
3644 - public/abstract allowed (already done at that point)
3645 - abstract is obsolete (comes first, it's a warning, or should be)
3646 - Can't use twice the same (checked in the modifier rule) */
3647 if ((flags & ACC_ABSTRACT) && flag_redundant)
3648 parse_warning_context
3649 (MODIFIER_WFL (ABSTRACT_TK),
3650 "Redundant use of `abstract' modifier. Interface `%s' is implicitely abstract", IDENTIFIER_POINTER (raw_name));
3652 /* Create a new decl if DECL is NULL, otherwise fix it */
3653 decl = maybe_create_class_interface_decl (decl, raw_name, q_name, id);
3655 /* Set super info and mark the class a complete */
3656 set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
3657 object_type_node, ctxp->interface_number);
3658 ctxp->interface_number = 0;
3659 CLASS_COMPLETE_P (decl) = 1;
3660 add_superinterfaces (decl, super);
3665 /* Anonymous class counter. Will be reset to 1 every time a non
3666 anonymous class gets created. */
3667 static int anonymous_class_counter = 1;
3669 /* Patch anonymous class CLASS, by either extending or implementing
3673 patch_anonymous_class (type_decl, class_decl, wfl)
3674 tree type_decl, class_decl, wfl;
3676 tree class = TREE_TYPE (class_decl);
3677 tree type = TREE_TYPE (type_decl);
3678 tree binfo = TYPE_BINFO (class);
3680 /* If it's an interface, implement it */
3681 if (CLASS_INTERFACE (type_decl))
3686 if (parser_check_super_interface (type_decl, class_decl, wfl))
3689 s_binfo = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (class)), 0);
3690 length = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (class))+1;
3691 TYPE_BINFO_BASETYPES (class) = make_tree_vec (length);
3692 TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (class)), 0) = s_binfo;
3693 /* And add the interface */
3694 parser_add_interface (class_decl, type_decl, wfl);
3696 /* Otherwise, it's a type we want to extend */
3699 if (parser_check_super (type_decl, class_decl, wfl))
3701 BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), 0)) = type;
3706 create_anonymous_class (location, type_name)
3711 tree super = NULL_TREE, itf = NULL_TREE;
3712 tree id, type_decl, class;
3714 /* The unqualified name of the anonymous class. It's just a number. */
3715 sprintf (buffer, "%d", anonymous_class_counter++);
3716 id = build_wfl_node (get_identifier (buffer));
3717 EXPR_WFL_LINECOL (id) = location;
3719 /* We know about the type to extend/implement. We go ahead */
3720 if ((type_decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (type_name))))
3722 /* Create a class which either implements on extends the designated
3723 class. The class bears an innacessible name. */
3724 if (CLASS_INTERFACE (type_decl))
3726 /* It's OK to modify it here. It's been already used and
3727 shouldn't be reused */
3728 ctxp->interface_number = 1;
3729 /* Interfaces should presented as a list of WFLs */
3730 itf = build_tree_list (type_name, NULL_TREE);
3736 class = create_class (ACC_FINAL, id, super, itf);
3738 /* We didn't know anything about the stuff. We register a dependence. */
3740 register_incomplete_type (JDEP_ANONYMOUS, type_name, class, NULL_TREE);
3742 ANONYMOUS_CLASS_P (TREE_TYPE (class)) = 1;
3746 /* Create an class in pass1 and return its decl. Return class
3747 interface's decl in pass 2. */
3750 create_class (flags, id, super, interfaces)
3752 tree id, super, interfaces;
3754 tree raw_name = EXPR_WFL_NODE (id);
3755 tree class_id, decl;
3756 tree super_decl_type;
3758 class_id = parser_qualified_classname (0, raw_name);
3759 decl = IDENTIFIER_CLASS_VALUE (class_id);
3760 EXPR_WFL_NODE (id) = class_id;
3762 /* Basic check: scope, redefinition, modifiers */
3763 if (check_class_interface_creation (0, flags, raw_name, class_id, decl, id))
3769 /* Suspend the current parsing context if we're parsing an inner
3770 class or an anonymous class. */
3772 java_parser_context_suspend ();
3773 /* Push a new context for (static) initialized upon declaration fields */
3774 java_parser_context_push_initialized_field ();
3776 /* Class modifier check:
3777 - Allowed modifier (already done at that point)
3778 - abstract AND final forbidden
3779 - Public classes defined in the correct file */
3780 if ((flags & ACC_ABSTRACT) && (flags & ACC_FINAL))
3782 (id, "Class `%s' can't be declared both abstract and final",
3783 IDENTIFIER_POINTER (raw_name));
3785 /* Create a new decl if DECL is NULL, otherwise fix it */
3786 decl = maybe_create_class_interface_decl (decl, raw_name, class_id, id);
3788 /* If SUPER exists, use it, otherwise use Object */
3791 /* Can't extend java.lang.Object */
3792 if (TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_id)) == object_type_node)
3794 parse_error_context (id, "Can't extend `java.lang.Object'");
3799 register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
3801 else if (TREE_TYPE (decl) != object_type_node)
3802 super_decl_type = object_type_node;
3803 /* We're defining java.lang.Object */
3805 super_decl_type = NULL_TREE;
3807 /* Set super info and mark the class a complete */
3808 set_super_info (flags, TREE_TYPE (decl), super_decl_type,
3809 ctxp->interface_number);
3810 ctxp->interface_number = 0;
3811 CLASS_COMPLETE_P (decl) = 1;
3812 add_superinterfaces (decl, interfaces);
3814 /* If the class is a top level inner class, install an alias. */
3815 if (INNER_CLASS_DECL_P (decl) && CLASS_STATIC (decl))
3817 tree alias = parser_qualified_classname (1, raw_name);
3818 IDENTIFIER_GLOBAL_VALUE (alias) = decl;
3821 /* Add the private this$<n> field, Replicate final locals still in
3822 scope as private final fields mangled like val$<local_name>.
3823 This doesn't not occur for top level (static) inner classes. */
3824 if (PURE_INNER_CLASS_DECL_P (decl))
3825 add_inner_class_fields (decl, current_function_decl);
3827 /* If doing xref, store the location at which the inherited class
3828 (if any) was seen. */
3829 if (flag_emit_xref && super)
3830 DECL_INHERITED_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (super);
3832 /* Eventually sets the @deprecated tag flag */
3833 CHECK_DEPRECATED (decl);
3835 /* Reset the anonymous class counter when declaring a toplevel class */
3836 if (TOPLEVEL_CLASS_DECL_P (decl))
3837 anonymous_class_counter = 1;
3842 /* End a class declaration: register the statements used to create
3843 $finit$ and <clinit>, pop the current class and resume the prior
3844 parser context if necessary. */
3847 end_class_declaration (resume)
3850 /* If an error occured, context weren't pushed and won't need to be
3851 popped by a resume. */
3852 int no_error_occured = ctxp->next && GET_CPC () != error_mark_node;
3854 java_parser_context_pop_initialized_field ();
3856 if (resume && no_error_occured)
3857 java_parser_context_resume ();
3861 add_inner_class_fields (class_decl, fct_decl)
3865 tree block, marker, f;
3867 f = add_field (TREE_TYPE (class_decl),
3868 build_current_thisn (TREE_TYPE (class_decl)),
3869 build_pointer_type (TREE_TYPE (DECL_CONTEXT (class_decl))),
3871 FIELD_THISN (f) = 1;
3876 for (block = GET_CURRENT_BLOCK (fct_decl);
3877 block && TREE_CODE (block) == BLOCK; block = BLOCK_SUPERCONTEXT (block))
3880 for (decl = BLOCK_EXPR_DECLS (block); decl; decl = TREE_CHAIN (decl))
3883 tree wfl, init, list;
3885 /* Avoid non final arguments. */
3886 if (!LOCAL_FINAL (decl))
3889 MANGLE_OUTER_LOCAL_VARIABLE_NAME (name, DECL_NAME (decl));
3890 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID (pname, DECL_NAME (decl));
3891 wfl = build_wfl_node (get_identifier (name));
3892 init = build_wfl_node (get_identifier (pname));
3893 /* Build an initialization for the field: it will be
3894 initialized by a parameter added to $finit$, bearing a
3895 mangled name of the field itself (param$<n>.) The
3896 parameter is provided to $finit$ by the constructor
3897 invoking it (hence the constructor will also feature a
3898 hidden parameter, set to the value of the outer context
3899 local at the time the inner class is created.)
3901 Note: we take into account all possible locals that can
3902 be accessed by the inner class. It's actually not trivial
3903 to minimize these aliases down to the ones really
3904 used. One way to do that would be to expand all regular
3905 methods first, then $finit$ to get a picture of what's
3906 used. It works with the exception that we would have to
3907 go back on all constructor invoked in regular methods to
3908 have their invokation reworked (to include the right amount
3909 of alias initializer parameters.)
3911 The only real way around, I think, is a first pass to
3912 identify locals really used in the inner class. We leave
3913 the flag FIELD_LOCAL_ALIAS_USED around for that future
3916 On the other hand, it only affect local inner classes,
3917 whose constructors (and $finit$ call) will be featuring
3918 unecessary arguments. It's easy for a developper to keep
3919 this number of parameter down by using the `final'
3920 keyword only when necessary. For the time being, we can
3921 issue a warning on unecessary finals. FIXME */
3922 init = build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (wfl),
3925 /* Register the field. The TREE_LIST holding the part
3926 initialized/initializer will be marked ARG_FINAL_P so
3927 that the created field can be marked
3928 FIELD_LOCAL_ALIAS. */
3929 list = build_tree_list (wfl, init);
3930 ARG_FINAL_P (list) = 1;
3931 register_fields (ACC_PRIVATE | ACC_FINAL, TREE_TYPE (decl), list);
3935 if (!CPC_INITIALIZER_STMT (ctxp))
3938 /* If we ever registered an alias field, insert and marker to
3939 remeber where the list ends. The second part of the list (the one
3940 featuring initialized fields) so it can be later reversed to
3941 enforce 8.5. The marker will be removed during that operation. */
3942 marker = build_tree_list (NULL_TREE, NULL_TREE);
3943 TREE_CHAIN (marker) = CPC_INITIALIZER_STMT (ctxp);
3944 SET_CPC_INITIALIZER_STMT (ctxp, marker);
3947 /* Can't use lookup_field () since we don't want to load the class and
3948 can't set the CLASS_LOADED_P flag */
3951 find_field (class, name)
3956 for (decl = TYPE_FIELDS (class); decl; decl = TREE_CHAIN (decl))
3958 if (DECL_NAME (decl) == name)
3964 /* Wrap around lookup_field that doesn't potentially upset the value
3968 lookup_field_wrapper (class, name)
3973 java_parser_context_save_global ();
3974 decl = lookup_field (&type, name);
3975 java_parser_context_restore_global ();
3976 return decl == error_mark_node ? NULL : decl;
3979 /* Find duplicate field within the same class declarations and report
3980 the error. Returns 1 if a duplicated field was found, 0
3984 duplicate_declaration_error_p (new_field_name, new_type, cl)
3985 tree new_field_name, new_type, cl;
3987 /* This might be modified to work with method decl as well */
3988 tree decl = find_field (TREE_TYPE (GET_CPC ()), new_field_name);
3991 char *t1 = xstrdup (purify_type_name
3992 ((TREE_CODE (new_type) == POINTER_TYPE
3993 && TREE_TYPE (new_type) == NULL_TREE) ?
3994 IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
3995 lang_printable_name (new_type, 1)));
3996 /* The type may not have been completed by the time we report
3998 char *t2 = xstrdup (purify_type_name
3999 ((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
4000 && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
4001 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
4002 lang_printable_name (TREE_TYPE (decl), 1)));
4004 (cl , "Duplicate variable declaration: `%s %s' was `%s %s' (%s:%d)",
4005 t1, IDENTIFIER_POINTER (new_field_name),
4006 t2, IDENTIFIER_POINTER (DECL_NAME (decl)),
4007 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
4015 /* Field registration routine. If TYPE doesn't exist, field
4016 declarations are linked to the undefined TYPE dependency list, to
4017 be later resolved in java_complete_class () */
4020 register_fields (flags, type, variable_list)
4022 tree type, variable_list;
4024 tree current, saved_type;
4025 tree class_type = NULL_TREE;
4026 int saved_lineno = lineno;
4028 tree wfl = NULL_TREE;
4031 class_type = TREE_TYPE (GET_CPC ());
4033 if (!class_type || class_type == error_mark_node)
4036 /* If we're adding fields to interfaces, those fields are public,
4038 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
4040 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK),
4041 flags, ACC_PUBLIC, "interface field(s)");
4042 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (STATIC_TK),
4043 flags, ACC_STATIC, "interface field(s)");
4044 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (FINAL_TK),
4045 flags, ACC_FINAL, "interface field(s)");
4046 check_modifiers ("Illegal interface member modifier `%s'", flags,
4047 INTERFACE_FIELD_MODIFIERS);
4048 flags |= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
4051 /* Obtain a suitable type for resolution, if necessary */
4052 SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
4054 /* If TYPE is fully resolved and we don't have a reference, make one */
4055 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4057 for (current = variable_list, saved_type = type; current;
4058 current = TREE_CHAIN (current), type = saved_type)
4062 tree cl = TREE_PURPOSE (current);
4063 tree init = TREE_VALUE (current);
4064 tree current_name = EXPR_WFL_NODE (cl);
4066 /* Can't declare static fields in inner classes */
4067 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (class_type)
4068 && !CLASS_INTERFACE (TYPE_NAME (class_type)))
4070 (cl, "Field `%s' can't be static in innerclass `%s'. Only members of interfaces and top-level classes can be static",
4071 IDENTIFIER_POINTER (EXPR_WFL_NODE (cl)),
4072 lang_printable_name (class_type, 0));
4074 /* Process NAME, as it may specify extra dimension(s) for it */
4075 type = build_array_from_name (type, wfl, current_name, ¤t_name);
4077 /* Type adjustment. We may have just readjusted TYPE because
4078 the variable specified more dimensions. Make sure we have
4079 a reference if we can and don't have one already. Also
4080 change the name if we have an init. */
4081 if (type != saved_type)
4083 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4085 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
4088 real_type = GET_REAL_TYPE (type);
4089 /* Check for redeclarations */
4090 if (duplicate_declaration_error_p (current_name, real_type, cl))
4093 /* Set lineno to the line the field was found and create a
4094 declaration for it. Eventually sets the @deprecated tag flag. */
4096 lineno = EXPR_WFL_LINECOL (cl);
4098 lineno = EXPR_WFL_LINENO (cl);
4099 field_decl = add_field (class_type, current_name, real_type, flags);
4100 CHECK_DEPRECATED (field_decl);
4102 /* If the couple initializer/initialized is marked ARG_FINAL_P, we
4103 mark the created field FIELD_LOCAL_ALIAS, so that we can
4104 hide parameters to this inner class $finit$ and constructors. */
4105 if (ARG_FINAL_P (current))
4106 FIELD_LOCAL_ALIAS (field_decl) = 1;
4108 /* Check if we must chain. */
4110 register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
4112 /* If we have an initialization value tied to the field */
4115 /* The field is declared static */
4116 if (flags & ACC_STATIC)
4118 /* We include the field and its initialization part into
4119 a list used to generate <clinit>. After <clinit> is
4120 walked, field initializations will be processed and
4121 fields initialized with known constants will be taken
4122 out of <clinit> and have their DECL_INITIAL set
4124 TREE_CHAIN (init) = CPC_STATIC_INITIALIZER_STMT (ctxp);
4125 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, init);
4126 if (TREE_OPERAND (init, 1)
4127 && TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
4128 TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
4130 /* A non-static field declared with an immediate initialization is
4131 to be initialized in <init>, if any. This field is remembered
4132 to be processed at the time of the generation of <init>. */
4135 TREE_CHAIN (init) = CPC_INITIALIZER_STMT (ctxp);
4136 SET_CPC_INITIALIZER_STMT (ctxp, init);
4138 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
4139 DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
4142 lineno = saved_lineno;
4145 /* Generate $finit$, using the list of initialized fields to populate
4146 its body. $finit$'s parameter(s) list is adjusted to include the
4147 one(s) used to initialized the field(s) caching outer context
4151 generate_finit (class_type)
4155 tree list = TYPE_FINIT_STMT_LIST (class_type);
4156 tree mdecl, current, parms;
4158 parms = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
4159 class_type, NULL_TREE,
4161 CRAFTED_PARAM_LIST_FIXUP (parms);
4162 mdecl = create_artificial_method (class_type, ACC_PRIVATE, void_type_node,
4163 finit_identifier_node, parms);
4164 fix_method_argument_names (parms, mdecl);
4165 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
4167 DECL_FUNCTION_NAP (mdecl) = count;
4168 start_artificial_method_body (mdecl);
4170 for (current = list; current; current = TREE_CHAIN (current))
4171 java_method_add_stmt (mdecl,
4172 build_debugable_stmt (EXPR_WFL_LINECOL (current),
4174 end_artificial_method_body (mdecl);
4179 add_instance_initializer (mdecl)
4183 tree stmt_list = TYPE_II_STMT_LIST (DECL_CONTEXT (mdecl));
4184 tree compound = NULL_TREE;
4188 for (current = stmt_list; current; current = TREE_CHAIN (current))
4189 compound = add_stmt_to_compound (compound, NULL_TREE, current);
4191 java_method_add_stmt (mdecl, build1 (INSTANCE_INITIALIZERS_EXPR,
4192 NULL_TREE, compound));
4196 /* Shared accros method_declarator and method_header to remember the
4197 patch stage that was reached during the declaration of the method.
4198 A method DECL is built differently is there is no patch
4199 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
4200 pending on the currently defined method. */
4202 static int patch_stage;
4204 /* Check the method declaration and add the method to its current
4205 class. If the argument list is known to contain incomplete types,
4206 the method is partially added and the registration will be resume
4207 once the method arguments resolved. If TYPE is NULL, we're dealing
4208 with a constructor. */
4211 method_header (flags, type, mdecl, throws)
4213 tree type, mdecl, throws;
4215 tree meth = TREE_VALUE (mdecl);
4216 tree id = TREE_PURPOSE (mdecl);
4217 tree type_wfl = NULL_TREE;
4218 tree meth_name = NULL_TREE;
4219 tree current, orig_arg, this_class = NULL;
4221 int constructor_ok = 0, must_chain;
4224 check_modifiers_consistency (flags);
4227 this_class = TREE_TYPE (GET_CPC ());
4229 if (!this_class || this_class == error_mark_node)
4232 /* There are some forbidden modifiers for an abstract method and its
4233 class must be abstract as well. */
4234 if (type && (flags & ACC_ABSTRACT))
4236 ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
4237 ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
4238 ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
4239 ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
4240 ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED,id, "Synchronized");
4241 if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
4242 && !CLASS_INTERFACE (TYPE_NAME (this_class)))
4244 (id, "Class `%s' must be declared abstract to define abstract method `%s'",
4245 IDENTIFIER_POINTER (DECL_NAME (ctxp->current_parsed_class)),
4246 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4249 /* Things to be checked when declaring a constructor */
4252 int ec = java_error_count;
4253 /* 8.6: Constructor declarations: we might be trying to define a
4254 method without specifying a return type. */
4255 if (EXPR_WFL_NODE (id) != GET_CPC_UN ())
4257 (id, "Invalid method declaration, return type required");
4258 /* 8.6.3: Constructor modifiers */
4261 JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
4262 JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
4263 JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
4264 JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
4265 JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
4267 /* If we found error here, we don't consider it's OK to tread
4268 the method definition as a constructor, for the rest of this
4270 if (ec == java_error_count)
4274 /* Method declared within the scope of an interface are implicitly
4275 abstract and public. Conflicts with other erroneously provided
4276 modifiers are checked right after. */
4278 if (CLASS_INTERFACE (TYPE_NAME (this_class)))
4280 /* If FLAGS isn't set because of a modifier, turn the
4281 corresponding modifier WFL to NULL so we issue a warning on
4282 the obsolete use of the modifier */
4283 if (!(flags & ACC_PUBLIC))
4284 MODIFIER_WFL (PUBLIC_TK) = NULL;
4285 if (!(flags & ACC_ABSTRACT))
4286 MODIFIER_WFL (ABSTRACT_TK) = NULL;
4287 flags |= ACC_PUBLIC;
4288 flags |= ACC_ABSTRACT;
4291 /* Inner class can't declare static methods */
4292 if ((flags & ACC_STATIC) && !TOPLEVEL_CLASS_TYPE_P (this_class))
4295 (id, "Method `%s' can't be static in inner class `%s'. Only members of interfaces and top-level classes can be static",
4296 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)),
4297 lang_printable_name (this_class, 0));
4300 /* Modifiers context reset moved up, so abstract method declaration
4301 modifiers can be later checked. */
4303 /* Set constructor returned type to void and method name to <init>,
4304 unless we found an error identifier the constructor (in which
4305 case we retain the original name) */
4308 type = void_type_node;
4310 meth_name = init_identifier_node;
4313 meth_name = EXPR_WFL_NODE (id);
4315 /* Do the returned type resolution and registration if necessary */
4316 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
4319 type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
4320 EXPR_WFL_NODE (id) = meth_name;
4321 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
4325 patch_stage = JDEP_METHOD_RETURN;
4326 register_incomplete_type (patch_stage, type_wfl, id, type);
4327 TREE_TYPE (meth) = GET_REAL_TYPE (type);
4330 TREE_TYPE (meth) = type;
4332 saved_lineno = lineno;
4333 /* When defining an abstract or interface method, the curly
4334 bracket at level 1 doesn't exist because there is no function
4336 lineno = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 :
4337 EXPR_WFL_LINENO (id));
4339 /* Remember the original argument list */
4340 orig_arg = TYPE_ARG_TYPES (meth);
4342 if (patch_stage) /* includes ret type and/or all args */
4345 meth = add_method_1 (this_class, flags, meth_name, meth);
4346 /* Patch for the return type */
4347 if (patch_stage == JDEP_METHOD_RETURN)
4349 jdep = CLASSD_LAST (ctxp->classd_list);
4350 JDEP_GET_PATCH (jdep) = &TREE_TYPE (TREE_TYPE (meth));
4352 /* This is the stop JDEP. METH allows the function's signature
4354 register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
4357 meth = add_method (this_class, flags, meth_name,
4358 build_java_signature (meth));
4360 /* Remember final parameters */
4361 MARK_FINAL_PARMS (meth, orig_arg);
4363 /* Fix the method argument list so we have the argument name
4365 fix_method_argument_names (orig_arg, meth);
4367 /* Register the parameter number and re-install the current line
4369 DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
4370 lineno = saved_lineno;
4372 /* Register exception specified by the `throws' keyword for
4373 resolution and set the method decl appropriate field to the list.
4374 Note: the grammar ensures that what we get here are class
4378 throws = nreverse (throws);
4379 for (current = throws; current; current = TREE_CHAIN (current))
4381 register_incomplete_type (JDEP_EXCEPTION, TREE_VALUE (current),
4382 NULL_TREE, NULL_TREE);
4383 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
4384 &TREE_VALUE (current);
4386 DECL_FUNCTION_THROWS (meth) = throws;
4389 /* We set the DECL_NAME to ID so we can track the location where
4390 the function was declared. This allow us to report
4391 redefinition error accurately. When method are verified,
4392 DECL_NAME is reinstalled properly (using the content of the
4393 WFL node ID) (see check_method_redefinition). We don't do that
4394 when Object is being defined. Constructor <init> names will be
4395 reinstalled the same way. */
4396 if (TREE_TYPE (GET_CPC ()) != object_type_node)
4397 DECL_NAME (meth) = id;
4399 /* Set the flag if we correctly processed a constructor */
4402 DECL_CONSTRUCTOR_P (meth) = 1;
4403 /* Compute and store the number of artificial parameters declared
4404 for this constructor */
4405 for (count = 0, current = TYPE_FIELDS (this_class); current;
4406 current = TREE_CHAIN (current))
4407 if (FIELD_LOCAL_ALIAS (current))
4409 DECL_FUNCTION_NAP (meth) = count;
4412 /* Eventually set the @deprecated tag flag */
4413 CHECK_DEPRECATED (meth);
4415 /* If doing xref, store column and line number information instead
4416 of the line number only. */
4418 DECL_SOURCE_LINE (meth) = EXPR_WFL_LINECOL (id);
4424 fix_method_argument_names (orig_arg, meth)
4425 tree orig_arg, meth;
4427 tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
4428 if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
4430 TREE_PURPOSE (arg) = this_identifier_node;
4431 arg = TREE_CHAIN (arg);
4433 while (orig_arg != end_params_node)
4435 TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
4436 orig_arg = TREE_CHAIN (orig_arg);
4437 arg = TREE_CHAIN (arg);
4441 /* Complete the method declaration with METHOD_BODY. */
4444 finish_method_declaration (method_body)
4449 if (!current_function_decl)
4452 flags = get_access_flags_from_decl (current_function_decl);
4454 /* 8.4.5 Method Body */
4455 if ((flags & ACC_ABSTRACT || flags & ACC_NATIVE) && method_body)
4457 tree wfl = DECL_NAME (current_function_decl);
4458 parse_error_context (wfl,
4459 "%s method `%s' can't have a body defined",
4460 (METHOD_NATIVE (current_function_decl) ?
4461 "Native" : "Abstract"),
4462 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
4463 method_body = NULL_TREE;
4465 else if (!(flags & ACC_ABSTRACT) && !(flags & ACC_NATIVE) && !method_body)
4467 tree wfl = DECL_NAME (current_function_decl);
4470 "Non native and non abstract method `%s' must have a body defined",
4471 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
4472 method_body = NULL_TREE;
4475 if (flag_emit_class_files && method_body
4476 && TREE_CODE (method_body) == NOP_EXPR
4477 && TREE_TYPE (current_function_decl)
4478 && TREE_TYPE (TREE_TYPE (current_function_decl)) == void_type_node)
4479 method_body = build1 (RETURN_EXPR, void_type_node, NULL);
4481 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
4482 maybe_absorb_scoping_blocks ();
4483 /* Exit function's body */
4485 /* Merge last line of the function with first line, directly in the
4486 function decl. It will be used to emit correct debug info. */
4487 if (!flag_emit_xref)
4488 DECL_SOURCE_LINE_MERGE (current_function_decl, ctxp->last_ccb_indent1);
4490 /* Since function's argument's list are shared, reset the
4491 ARG_FINAL_P parameter that might have been set on some of this
4492 function parameters. */
4493 UNMARK_FINAL_PARMS (current_function_decl);
4495 /* So we don't have an irrelevant function declaration context for
4496 the next static block we'll see. */
4497 current_function_decl = NULL_TREE;
4500 /* Build a an error message for constructor circularity errors. */
4503 constructor_circularity_msg (from, to)
4506 static char string [4096];
4507 char *t = xstrdup (lang_printable_name (from, 0));
4508 sprintf (string, "`%s' invokes `%s'", t, lang_printable_name (to, 0));
4513 /* Verify a circular call to METH. Return 1 if an error is found, 0
4517 verify_constructor_circularity (meth, current)
4520 static tree list = NULL_TREE;
4522 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
4524 if (TREE_VALUE (c) == meth)
4530 list = nreverse (list);
4531 for (liste = list; liste; liste = TREE_CHAIN (liste))
4534 (TREE_PURPOSE (TREE_PURPOSE (liste)), "%s",
4535 constructor_circularity_msg
4536 (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste))));
4540 t = xstrdup (lang_printable_name (meth, 0));
4541 parse_error_context (TREE_PURPOSE (c),
4542 "%s: recursive invocation of constructor `%s'",
4543 constructor_circularity_msg (current, meth), t);
4549 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
4551 list = tree_cons (c, current, list);
4552 if (verify_constructor_circularity (meth, TREE_VALUE (c)))
4554 list = TREE_CHAIN (list);
4559 /* Check modifiers that can be declared but exclusively */
4562 check_modifiers_consistency (flags)
4566 tree cl = NULL_TREE;
4568 THIS_MODIFIER_ONLY (flags, ACC_PUBLIC, 0, acc_count, cl);
4569 THIS_MODIFIER_ONLY (flags, ACC_PRIVATE, 1, acc_count, cl);
4570 THIS_MODIFIER_ONLY (flags, ACC_PROTECTED, 2, acc_count, cl);
4573 (cl, "Inconsistent member declaration. At most one of `public', `private', or `protected' may be specified");
4576 /* Check the methode header METH for abstract specifics features */
4579 check_abstract_method_header (meth)
4582 int flags = get_access_flags_from_decl (meth);
4583 /* DECL_NAME might still be a WFL node */
4584 tree name = GET_METHOD_NAME (meth);
4586 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (ABSTRACT_TK), flags,
4587 ACC_ABSTRACT, "abstract method",
4588 IDENTIFIER_POINTER (name));
4589 OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (PUBLIC_TK), flags,
4590 ACC_PUBLIC, "abstract method",
4591 IDENTIFIER_POINTER (name));
4593 check_modifiers ("Illegal modifier `%s' for interface method",
4594 flags, INTERFACE_METHOD_MODIFIERS);
4597 /* Create a FUNCTION_TYPE node and start augmenting it with the
4598 declared function arguments. Arguments type that can't be resolved
4599 are left as they are, but the returned node is marked as containing
4600 incomplete types. */
4603 method_declarator (id, list)
4606 tree arg_types = NULL_TREE, current, node;
4607 tree meth = make_node (FUNCTION_TYPE);
4610 patch_stage = JDEP_NO_PATCH;
4612 /* If we're dealing with an inner class constructor, we hide the
4613 this$<n> decl in the name field of its parameter declaration. We
4614 also might have to hide the outer context local alias
4615 initializers. Not done when the class is a toplevel class. */
4616 if (PURE_INNER_CLASS_DECL_P (GET_CPC ())
4617 && EXPR_WFL_NODE (id) == GET_CPC_UN ())
4619 tree aliases_list, type, thisn;
4620 /* First the aliases, linked to the regular parameters */
4622 build_alias_initializer_parameter_list (AIPL_FUNCTION_DECLARATION,
4623 TREE_TYPE (GET_CPC ()),
4625 list = chainon (nreverse (aliases_list), list);
4628 type = TREE_TYPE (DECL_CONTEXT (GET_CPC ()));
4629 thisn = build_current_thisn (TYPE_NAME (GET_CPC ()));
4630 list = tree_cons (build_wfl_node (thisn), build_pointer_type (type),
4634 for (current = list; current; current = TREE_CHAIN (current))
4637 tree wfl_name = TREE_PURPOSE (current);
4638 tree type = TREE_VALUE (current);
4639 tree name = EXPR_WFL_NODE (wfl_name);
4640 tree already, arg_node;
4641 tree type_wfl = NULL_TREE;
4644 /* Obtain a suitable type for resolution, if necessary */
4645 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
4647 /* Process NAME, as it may specify extra dimension(s) for it */
4648 type = build_array_from_name (type, type_wfl, name, &name);
4649 EXPR_WFL_NODE (wfl_name) = name;
4651 real_type = GET_REAL_TYPE (type);
4652 if (TREE_CODE (real_type) == RECORD_TYPE)
4654 real_type = promote_type (real_type);
4655 if (TREE_CODE (type) == TREE_LIST)
4656 TREE_PURPOSE (type) = real_type;
4659 /* Check redefinition */
4660 for (already = arg_types; already; already = TREE_CHAIN (already))
4661 if (TREE_PURPOSE (already) == name)
4664 (wfl_name, "Variable `%s' is used more than once in the argument list of method `%s'",
4665 IDENTIFIER_POINTER (name),
4666 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
4670 /* If we've an incomplete argument type, we know there is a location
4671 to patch when the type get resolved, later. */
4675 patch_stage = JDEP_METHOD;
4676 type = register_incomplete_type (patch_stage,
4677 type_wfl, wfl_name, type);
4678 jdep = CLASSD_LAST (ctxp->classd_list);
4679 JDEP_MISC (jdep) = id;
4682 /* The argument node: a name and a (possibly) incomplete type. */
4683 arg_node = build_tree_list (name, real_type);
4684 /* Remeber arguments declared final. */
4685 ARG_FINAL_P (arg_node) = ARG_FINAL_P (current);
4688 JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
4689 TREE_CHAIN (arg_node) = arg_types;
4690 arg_types = arg_node;
4692 TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
4693 node = build_tree_list (id, meth);
4698 unresolved_type_p (wfl, returned)
4703 if (TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION)
4705 tree decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (wfl));
4707 *returned = (decl ? TREE_TYPE (decl) : NULL_TREE);
4715 /* From NAME, build a qualified identifier node using the
4716 qualification from the current package definition. */
4719 parser_qualified_classname (is_static, name)
4723 tree nested_class_name;
4726 && (nested_class_name = maybe_make_nested_class_name (name)))
4727 return nested_class_name;
4730 return merge_qualified_name (ctxp->package, name);
4735 /* Called once the type a interface extends is resolved. Returns 0 if
4736 everything is OK. */
4739 parser_check_super_interface (super_decl, this_decl, this_wfl)
4740 tree super_decl, this_decl, this_wfl;
4742 tree super_type = TREE_TYPE (super_decl);
4744 /* Has to be an interface */
4745 if (!CLASS_INTERFACE (super_decl))
4748 (this_wfl, "Can't use %s `%s' to implement/extend %s `%s'",
4749 (TYPE_ARRAY_P (super_type) ? "array" : "class"),
4750 IDENTIFIER_POINTER (DECL_NAME (super_decl)),
4751 (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (this_decl))) ?
4752 "interface" : "class"),
4753 IDENTIFIER_POINTER (DECL_NAME (this_decl)));
4757 /* Check scope: same package OK, other package: OK if public */
4758 if (check_pkg_class_access (DECL_NAME (super_decl), lookup_cl (this_decl)))
4761 SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
4762 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
4763 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
4767 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
4768 0 if everthing is OK. */
4771 parser_check_super (super_decl, this_decl, wfl)
4772 tree super_decl, this_decl, wfl;
4774 tree super_type = TREE_TYPE (super_decl);
4776 /* SUPER should be a CLASS (neither an array nor an interface) */
4777 if (TYPE_ARRAY_P (super_type) || CLASS_INTERFACE (TYPE_NAME (super_type)))
4780 (wfl, "Class `%s' can't subclass %s `%s'",
4781 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
4782 (CLASS_INTERFACE (TYPE_NAME (super_type)) ? "interface" : "array"),
4783 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
4787 if (CLASS_FINAL (TYPE_NAME (super_type)))
4789 parse_error_context (wfl, "Can't subclass final classes: %s",
4790 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
4794 /* Check scope: same package OK, other package: OK if public */
4795 if (check_pkg_class_access (DECL_NAME (super_decl), wfl))
4798 SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
4799 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
4800 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
4804 /* Create a new dependency list and link it (in a LIFO manner) to the
4805 CTXP list of type dependency list. */
4808 create_jdep_list (ctxp)
4809 struct parser_ctxt *ctxp;
4811 jdeplist *new = (jdeplist *)xmalloc (sizeof (jdeplist));
4812 new->first = new->last = NULL;
4813 new->next = ctxp->classd_list;
4814 ctxp->classd_list = new;
4818 reverse_jdep_list (ctxp)
4819 struct parser_ctxt *ctxp;
4821 register jdeplist *prev = NULL, *current, *next;
4822 for (current = ctxp->classd_list; current; current = next)
4824 next = current->next;
4825 current->next = prev;
4831 /* Create a fake pointer based on the ID stored in
4832 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
4833 registered again. */
4836 obtain_incomplete_type (type_name)
4841 if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
4842 name = EXPR_WFL_NODE (type_name);
4843 else if (INCOMPLETE_TYPE_P (type_name))
4844 name = TYPE_NAME (type_name);
4846 fatal ("invalid type name - obtain_incomplete_type");
4848 for (ptr = ctxp->incomplete_class; ptr; ptr = TREE_CHAIN (ptr))
4849 if (TYPE_NAME (ptr) == name)
4854 push_obstacks (&permanent_obstack, &permanent_obstack);
4855 BUILD_PTR_FROM_NAME (ptr, name);
4858 TREE_CHAIN (ptr) = ctxp->incomplete_class;
4859 ctxp->incomplete_class = ptr;
4865 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
4866 non NULL instead of computing a new fake type based on WFL. The new
4867 dependency is inserted in the current type dependency list, in FIFO
4871 register_incomplete_type (kind, wfl, decl, ptr)
4873 tree wfl, decl, ptr;
4875 jdep *new = (jdep *)xmalloc (sizeof (jdep));
4877 if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
4878 ptr = obtain_incomplete_type (wfl);
4880 JDEP_KIND (new) = kind;
4881 JDEP_DECL (new) = decl;
4882 JDEP_SOLV (new) = ptr;
4883 JDEP_WFL (new) = wfl;
4884 JDEP_CHAIN (new) = NULL;
4885 JDEP_MISC (new) = NULL_TREE;
4886 JDEP_ENCLOSING (new) = GET_CPC ();
4887 JDEP_GET_PATCH (new) = (tree *)NULL;
4889 JDEP_INSERT (ctxp->classd_list, new);
4895 java_check_circular_reference ()
4898 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
4900 tree type = TREE_TYPE (current);
4901 if (CLASS_INTERFACE (current))
4903 /* Check all interfaces this class extends */
4904 tree basetype_vec = TYPE_BINFO_BASETYPES (type);
4909 n = TREE_VEC_LENGTH (basetype_vec);
4910 for (i = 0; i < n; i++)
4912 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
4913 if (vec_elt && BINFO_TYPE (vec_elt) != object_type_node
4914 && interface_of_p (type, BINFO_TYPE (vec_elt)))
4915 parse_error_context (lookup_cl (current),
4916 "Cyclic interface inheritance");
4920 if (inherits_from_p (CLASSTYPE_SUPER (type), type))
4921 parse_error_context (lookup_cl (current),
4922 "Cyclic class inheritance%s",
4923 (cyclic_inheritance_report ?
4924 cyclic_inheritance_report : ""));
4928 /* Augment the parameter list PARM with parameters crafted to
4929 initialize outer context locals aliases. Through ARTIFICIAL, a
4930 count is kept of the number of crafted parameters. MODE governs
4931 what eventually gets created: something suitable for a function
4932 creation or a function invocation, either the constructor or
4936 build_alias_initializer_parameter_list (mode, class_type, parm, artificial)
4938 tree class_type, parm;
4942 for (field = TYPE_FIELDS (class_type); field; field = TREE_CHAIN (field))
4943 if (FIELD_LOCAL_ALIAS (field))
4945 char *buffer = IDENTIFIER_POINTER (DECL_NAME (field));
4946 tree purpose = NULL_TREE, value = NULL_TREE, name = NULL_TREE;
4950 case AIPL_FUNCTION_DECLARATION:
4951 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (buffer, &buffer [4]);
4952 purpose = build_wfl_node (get_identifier (buffer));
4953 if (TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
4954 value = build_wfl_node (TYPE_NAME (TREE_TYPE (field)));
4956 value = TREE_TYPE (field);
4959 case AIPL_FUNCTION_CREATION:
4960 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (buffer, &buffer [4]);
4961 purpose = get_identifier (buffer);
4962 value = TREE_TYPE (field);
4965 case AIPL_FUNCTION_FINIT_INVOCATION:
4966 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR (buffer, &buffer [4]);
4967 /* Now, this is wrong. purpose should always be the NAME
4968 of something and value its matching value (decl, type,
4969 etc...) FIXME -- but there is a lot to fix. */
4971 /* When invoked for this kind of operation, we already
4972 know whether a field is used or not. */
4973 purpose = TREE_TYPE (field);
4974 value = build_wfl_node (get_identifier (buffer));
4977 case AIPL_FUNCTION_CTOR_INVOCATION:
4978 /* There are two case: the constructor invokation happends
4979 outside the local inner, in which case, locales from the outer
4980 context are directly used.
4982 Otherwise, we fold to using the alias directly. */
4983 if (class_type == current_class)
4987 name = get_identifier (&buffer[4]);
4988 value = IDENTIFIER_LOCAL_VALUE (name);
4992 parm = tree_cons (purpose, value, parm);
4999 /* Craft a constructor for CLASS_DECL -- what we should do when none
5000 where found. ARGS is non NULL when a special signature must be
5001 enforced. This is the case for anonymous classes. */
5004 craft_constructor (class_decl, args)
5005 tree class_decl, args;
5007 tree class_type = TREE_TYPE (class_decl);
5008 tree parm = NULL_TREE;
5009 int flags = (get_access_flags_from_decl (class_decl) & ACC_PUBLIC ?
5011 int i = 0, artificial = 0;
5012 tree decl, ctor_name;
5015 push_obstacks (&permanent_obstack, &permanent_obstack);
5017 /* The constructor name is <init> unless we're dealing with an
5018 anonymous class, in which case the name will be fixed after having
5020 if (ANONYMOUS_CLASS_P (class_type))
5021 ctor_name = DECL_NAME (class_decl);
5023 ctor_name = init_identifier_node;
5025 /* If we're dealing with an inner class constructor, we hide the
5026 this$<n> decl in the name field of its parameter declaration. */
5027 if (PURE_INNER_CLASS_TYPE_P (class_type))
5029 tree type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class_type)));
5030 parm = tree_cons (build_current_thisn (class_type),
5031 build_pointer_type (type), parm);
5033 /* Some more arguments to be hidden here. The values of the local
5034 variables of the outer context that the inner class needs to see. */
5035 parm = build_alias_initializer_parameter_list (AIPL_FUNCTION_CREATION,
5040 /* Then if there are any args to be enforced, enforce them now */
5041 for (; args && args != end_params_node; args = TREE_CHAIN (args))
5043 sprintf (buffer, "parm%d", i++);
5044 parm = tree_cons (get_identifier (buffer), TREE_VALUE (args), parm);
5047 CRAFTED_PARAM_LIST_FIXUP (parm);
5048 decl = create_artificial_method (class_type, flags, void_type_node,
5050 fix_method_argument_names (parm, decl);
5051 /* Now, mark the artificial parameters. */
5052 DECL_FUNCTION_NAP (decl) = artificial;
5055 DECL_CONSTRUCTOR_P (decl) = 1;
5059 /* Fix the constructors. This will be called right after circular
5060 references have been checked. It is necessary to fix constructors
5061 early even if no code generation will take place for that class:
5062 some generated constructor might be required by the class whose
5063 compilation triggered this one to be simply loaded. */
5066 java_fix_constructors ()
5070 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5072 tree class_type = TREE_TYPE (current);
5076 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
5079 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
5081 if (DECL_CONSTRUCTOR_P (decl))
5083 fix_constructors (decl);
5088 /* Anonymous class constructor can't be generated that early. */
5089 if (!saw_ctor && !ANONYMOUS_CLASS_P (class_type))
5090 craft_constructor (current, NULL_TREE);
5094 /* safe_layout_class just makes sure that we can load a class without
5095 disrupting the current_class, input_file, lineno, etc, information
5096 about the class processed currently. */
5099 safe_layout_class (class)
5102 tree save_current_class = current_class;
5103 char *save_input_filename = input_filename;
5104 int save_lineno = lineno;
5106 push_obstacks (&permanent_obstack, &permanent_obstack);
5108 layout_class (class);
5111 current_class = save_current_class;
5112 input_filename = save_input_filename;
5113 lineno = save_lineno;
5114 CLASS_LOADED_P (class) = 1;
5118 jdep_resolve_class (dep)
5123 if (JDEP_RESOLVED_P (dep))
5124 decl = JDEP_RESOLVED_DECL (dep);
5127 decl = resolve_class (JDEP_ENCLOSING (dep), JDEP_TO_RESOLVE (dep),
5128 JDEP_DECL (dep), JDEP_WFL (dep));
5129 JDEP_RESOLVED (dep, decl);
5133 complete_class_report_errors (dep);
5138 /* Complete unsatisfied class declaration and their dependencies */
5141 java_complete_class ()
5148 push_obstacks (&permanent_obstack, &permanent_obstack);
5150 /* Process imports and reverse the import on demand list */
5152 if (ctxp->import_demand_list)
5153 ctxp->import_demand_list = nreverse (ctxp->import_demand_list);
5155 /* Rever things so we have the right order */
5156 ctxp->class_list = nreverse (ctxp->class_list);
5157 ctxp->classd_list = reverse_jdep_list (ctxp);
5159 for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
5161 cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
5164 for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
5167 if (!(decl = jdep_resolve_class (dep)))
5170 /* Now it's time to patch */
5171 switch (JDEP_KIND (dep))
5174 /* Simply patch super */
5175 if (parser_check_super (decl, JDEP_DECL (dep), JDEP_WFL (dep)))
5177 BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO
5178 (TREE_TYPE (JDEP_DECL (dep)))), 0)) = TREE_TYPE (decl);
5183 /* We do part of the job done in add_field */
5184 tree field_decl = JDEP_DECL (dep);
5185 tree field_type = TREE_TYPE (decl);
5186 push_obstacks (&permanent_obstack, &permanent_obstack);
5187 if (TREE_CODE (field_type) == RECORD_TYPE)
5188 field_type = promote_type (field_type);
5190 TREE_TYPE (field_decl) = field_type;
5191 DECL_ALIGN (field_decl) = 0;
5192 layout_decl (field_decl, 0);
5193 SOURCE_FRONTEND_DEBUG
5194 (("Completed field/var decl `%s' with `%s'",
5195 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
5196 IDENTIFIER_POINTER (DECL_NAME (decl))));
5199 case JDEP_METHOD: /* We start patching a method */
5200 case JDEP_METHOD_RETURN:
5206 type = TREE_TYPE(decl);
5207 if (TREE_CODE (type) == RECORD_TYPE)
5208 type = promote_type (type);
5209 JDEP_APPLY_PATCH (dep, type);
5210 SOURCE_FRONTEND_DEBUG
5211 (((JDEP_KIND (dep) == JDEP_METHOD_RETURN ?
5212 "Completing fct `%s' with ret type `%s'":
5213 "Completing arg `%s' with type `%s'"),
5214 IDENTIFIER_POINTER (EXPR_WFL_NODE
5215 (JDEP_DECL_WFL (dep))),
5216 IDENTIFIER_POINTER (DECL_NAME (decl))));
5220 dep = JDEP_CHAIN (dep);
5221 if (JDEP_KIND (dep) == JDEP_METHOD_END)
5224 decl = jdep_resolve_class (dep);
5228 tree mdecl = JDEP_DECL (dep), signature;
5229 push_obstacks (&permanent_obstack, &permanent_obstack);
5230 /* Recompute and reset the signature */
5231 signature = build_java_signature (TREE_TYPE (mdecl));
5232 set_java_signature (TREE_TYPE (mdecl), signature);
5239 case JDEP_INTERFACE:
5240 if (parser_check_super_interface (decl, JDEP_DECL (dep),
5243 parser_add_interface (JDEP_DECL (dep), decl, JDEP_WFL (dep));
5248 type = TREE_TYPE(decl);
5249 if (TREE_CODE (type) == RECORD_TYPE)
5250 type = promote_type (type);
5251 JDEP_APPLY_PATCH (dep, type);
5255 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5256 SOURCE_FRONTEND_DEBUG
5257 (("Completing a random type dependency on a '%s' node",
5258 tree_code_name [TREE_CODE (JDEP_DECL (dep))]));
5261 case JDEP_EXCEPTION:
5262 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
5263 SOURCE_FRONTEND_DEBUG
5264 (("Completing `%s' `throws' argument node",
5265 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
5268 case JDEP_ANONYMOUS:
5269 patch_anonymous_class (decl, JDEP_DECL (dep), JDEP_WFL (dep));
5273 fatal ("Can't handle patch code %d - java_complete_class",
5282 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
5286 resolve_class (enclosing, class_type, decl, cl)
5287 tree enclosing, class_type, decl, cl;
5289 const char *name = IDENTIFIER_POINTER (TYPE_NAME (class_type));
5290 const char *base = name;
5291 tree resolved_type = TREE_TYPE (class_type);
5292 tree resolved_type_decl;
5294 if (resolved_type != NULL_TREE)
5296 tree resolved_type_decl = TYPE_NAME (resolved_type);
5297 if (resolved_type_decl == NULL_TREE
5298 || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
5300 resolved_type_decl = build_decl (TYPE_DECL,
5301 TYPE_NAME (class_type),
5304 return resolved_type_decl;
5307 /* 1- Check to see if we have an array. If true, find what we really
5309 while (name[0] == '[')
5312 TYPE_NAME (class_type) = get_identifier (name);
5314 /* 2- Resolve the bare type */
5315 if (!(resolved_type_decl = do_resolve_class (enclosing, class_type,
5318 resolved_type = TREE_TYPE (resolved_type_decl);
5320 /* 3- If we have and array, reconstruct the array down to its nesting */
5323 while (base != name)
5325 if (TREE_CODE (resolved_type) == RECORD_TYPE)
5326 resolved_type = promote_type (resolved_type);
5327 resolved_type = build_java_array_type (resolved_type, -1);
5328 CLASS_LOADED_P (resolved_type) = 1;
5331 /* Build a fake decl for this, since this is what is expected to
5333 resolved_type_decl =
5334 build_decl (TYPE_DECL, TYPE_NAME (resolved_type), resolved_type);
5335 /* Figure how those two things are important for error report. FIXME */
5336 DECL_SOURCE_LINE (resolved_type_decl) = 0;
5337 DECL_SOURCE_FILE (resolved_type_decl) = input_filename;
5338 TYPE_NAME (class_type) = TYPE_NAME (resolved_type);
5340 TREE_TYPE (class_type) = resolved_type;
5341 return resolved_type_decl;
5344 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
5345 are used to report error messages. */
5348 do_resolve_class (enclosing, class_type, decl, cl)
5349 tree enclosing, class_type, decl, cl;
5351 tree new_class_decl;
5352 tree original_name = NULL_TREE;
5354 /* Do not try to replace TYPE_NAME (class_type) by a variable, since
5355 its is changed by find_in_imports{_on_demand} */
5357 /* 0- Search in the current class as an inner class */
5359 /* Maybe some code here should be added to load the class or
5360 something, at least if the class isn't an inner class and ended
5361 being loaded from class file. FIXME. */
5362 if ((new_class_decl = find_as_inner_class (enclosing, class_type, cl)))
5363 return new_class_decl;
5365 /* 1- Check for the type in single imports */
5366 if (find_in_imports (class_type))
5369 /* 2- And check for the type in the current compilation unit. If it fails,
5370 try with a name qualified with the package name we've seen so far */
5371 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5373 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
5374 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
5375 load_class (TYPE_NAME (class_type), 0);
5376 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5379 original_name = TYPE_NAME (class_type);
5380 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5383 for (package = package_list; package; package = TREE_CHAIN (package))
5387 new_qualified = merge_qualified_name (TREE_PURPOSE (package),
5389 TYPE_NAME (class_type) = new_qualified;
5390 new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5391 if (!new_class_decl)
5392 load_class (TYPE_NAME (class_type), 0);
5393 new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5396 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
5397 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
5398 load_class (TYPE_NAME (class_type), 0);
5399 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5404 TYPE_NAME (class_type) = original_name;
5406 /* 3- Check an other compilation unit that bears the name of type */
5407 load_class (TYPE_NAME (class_type), 0);
5408 if (check_pkg_class_access (TYPE_NAME (class_type),
5409 (cl ? cl : lookup_cl (decl))))
5412 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
5413 return new_class_decl;
5415 /* 4- Check the import on demands. Don't allow bar.baz to be
5416 imported from foo.* */
5417 if (!QUALIFIED_P (TYPE_NAME (class_type)))
5418 if (find_in_imports_on_demand (class_type))
5421 /* 5- Last call for a resolution */
5422 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5425 /* Resolve NAME and lay it out (if not done and if not the current
5426 parsed class). Return a decl node. This function is meant to be
5427 called when type resolution is necessary during the walk pass. */
5430 resolve_and_layout (something, cl)
5436 /* Don't do that on the current class */
5437 if (something == current_class)
5438 return TYPE_NAME (current_class);
5440 /* Don't do anything for void and other primitive types */
5441 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
5444 /* Pointer types can be reall pointer types or fake pointers. When
5445 finding a real pointer, recheck for primitive types */
5446 if (TREE_CODE (something) == POINTER_TYPE)
5448 if (TREE_TYPE (something))
5450 something = TREE_TYPE (something);
5451 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
5455 something = TYPE_NAME (something);
5458 /* Don't do anything for arrays of primitive types */
5459 if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
5460 && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
5463 /* Something might be a WFL */
5464 if (TREE_CODE (something) == EXPR_WITH_FILE_LOCATION)
5465 something = EXPR_WFL_NODE (something);
5467 /* Otherwise, if something is not and IDENTIFIER_NODE, it can be a a
5468 TYPE_DECL or a real TYPE */
5469 else if (TREE_CODE (something) != IDENTIFIER_NODE)
5470 something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
5471 DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
5473 if (!(decl = resolve_no_layout (something, cl)))
5476 /* Resolve and layout if necessary */
5477 layout_class_methods (TREE_TYPE (decl));
5478 /* Check methods, but only once */
5479 if (CLASS_FROM_SOURCE_P (TREE_TYPE (decl))
5480 && !CLASS_LOADED_P (TREE_TYPE (decl)))
5481 CHECK_METHODS (decl);
5482 if (TREE_TYPE (decl) != current_class && !CLASS_LOADED_P (TREE_TYPE (decl)))
5483 safe_layout_class (TREE_TYPE (decl));
5488 /* Resolve a class, returns its decl but doesn't perform any
5489 layout. The current parsing context is saved and restored */
5492 resolve_no_layout (name, cl)
5496 BUILD_PTR_FROM_NAME (ptr, name);
5497 java_parser_context_save_global ();
5498 decl = resolve_class (TYPE_NAME (current_class), ptr, NULL_TREE, cl);
5499 java_parser_context_restore_global ();
5504 /* Called when reporting errors. Skip leader '[' in a complex array
5505 type description that failed to be resolved. */
5508 purify_type_name (name)
5511 while (*name && *name == '[')
5516 /* The type CURRENT refers to can't be found. We print error messages. */
5519 complete_class_report_errors (dep)
5524 if (!JDEP_WFL (dep))
5527 name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
5528 switch (JDEP_KIND (dep))
5532 (JDEP_WFL (dep), "Superclass `%s' of class `%s' not found",
5533 purify_type_name (name),
5534 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
5538 (JDEP_WFL (dep), "Type `%s' not found in declaration of field `%s'",
5539 purify_type_name (name),
5540 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
5542 case JDEP_METHOD: /* Covers arguments */
5544 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the argument `%s' of method `%s'",
5545 purify_type_name (name),
5546 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
5547 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
5549 case JDEP_METHOD_RETURN: /* Covers return type */
5551 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the return type of method `%s'",
5552 purify_type_name (name),
5553 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
5555 case JDEP_INTERFACE:
5557 (JDEP_WFL (dep), "Superinterface `%s' of %s `%s' not found",
5558 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
5559 (CLASS_OR_INTERFACE (JDEP_DECL (dep), "class", "interface")),
5560 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
5564 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the local variable `%s'",
5565 purify_type_name (IDENTIFIER_POINTER
5566 (EXPR_WFL_NODE (JDEP_WFL (dep)))),
5567 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
5569 case JDEP_EXCEPTION: /* As specified by `throws' */
5571 (JDEP_WFL (dep), "Class `%s' not found in `throws'",
5572 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
5575 /* Fix for -Wall. Just break doing nothing. The error will be
5581 /* Return a static string containing the DECL prototype string. If
5582 DECL is a constructor, use the class name instead of the form
5586 get_printable_method_name (decl)
5589 const char *to_return;
5590 tree name = NULL_TREE;
5592 if (DECL_CONSTRUCTOR_P (decl))
5594 name = DECL_NAME (decl);
5595 DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
5598 to_return = lang_printable_name (decl, 0);
5599 if (DECL_CONSTRUCTOR_P (decl))
5600 DECL_NAME (decl) = name;
5605 /* Reinstall the proper DECL_NAME on METHOD. Return 0 if the method
5606 nevertheless needs to be verfied, 1 otherwise. */
5609 reset_method_name (method)
5612 if (!DECL_CLINIT_P (method) && !DECL_FINIT_P (method))
5614 /* NAME is just the plain name when Object is being defined */
5615 if (DECL_CONTEXT (method) != object_type_node)
5616 DECL_NAME (method) = (DECL_CONSTRUCTOR_P (method) ?
5617 init_identifier_node : GET_METHOD_NAME (method));
5624 /* Return the name of METHOD_DECL, when DECL_NAME is a WFL */
5627 java_get_real_method_name (method_decl)
5630 tree method_name = DECL_NAME (method_decl);
5631 if (DECL_CONSTRUCTOR_P (method_decl))
5632 return init_identifier_node;
5634 /* Explain here why METHOD_DECL doesn't have the DECL_CONSTRUCTUR_P
5635 and still can be a constructor. FIXME */
5637 /* Don't confuse method only bearing the name of their class as
5639 else if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (method_decl))
5641 && GET_CPC_UN () == EXPR_WFL_NODE (method_name)
5642 && get_access_flags_from_decl (method_decl) <= ACC_PROTECTED
5643 && TREE_TYPE (TREE_TYPE (method_decl)) == void_type_node)
5644 return init_identifier_node;
5646 return EXPR_WFL_NODE (method_name);
5649 /* Track method being redefined inside the same class. As a side
5650 effect, set DECL_NAME to an IDENTIFIER (prior entering this
5651 function it's a FWL, so we can track errors more accurately.) */
5654 check_method_redefinition (class, method)
5658 tree cl = DECL_NAME (method);
5659 tree sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
5660 /* decl name of artificial <clinit> and $finit$ doesn't need to be
5661 fixed and checked */
5663 /* Reset the method name before running the check. If it returns 1,
5664 the method doesn't need to be verified with respect to method
5665 redeclaration and we return 0 */
5666 if (reset_method_name (method))
5669 name = DECL_NAME (method);
5670 for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
5672 if (redef == method)
5674 if (DECL_NAME (redef) == name
5675 && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef)))
5678 (cl, "Duplicate %s declaration `%s'",
5679 (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
5680 get_printable_method_name (redef));
5688 check_abstract_method_definitions (do_interface, class_decl, type)
5690 tree class_decl, type;
5692 tree class = TREE_TYPE (class_decl);
5693 tree method, end_type;
5695 end_type = (do_interface ? object_type_node : type);
5696 for (method = TYPE_METHODS (type); method; method = TREE_CHAIN (method))
5698 tree other_super, other_method, method_sig, method_name;
5701 if (!METHOD_ABSTRACT (method) || METHOD_FINAL (method))
5704 /* Now verify that somewhere in between TYPE and CLASS,
5705 abstract method METHOD gets a non abstract definition
5706 that is inherited by CLASS. */
5708 method_sig = build_java_signature (TREE_TYPE (method));
5709 method_name = DECL_NAME (method);
5710 if (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION)
5711 method_name = EXPR_WFL_NODE (method_name);
5713 for (other_super = class; other_super != end_type;
5714 other_super = CLASSTYPE_SUPER (other_super))
5716 for (other_method = TYPE_METHODS (other_super); other_method;
5717 other_method = TREE_CHAIN (other_method))
5719 tree s = build_java_signature (TREE_TYPE (other_method));
5720 tree other_name = DECL_NAME (other_method);
5722 if (TREE_CODE (other_name) == EXPR_WITH_FILE_LOCATION)
5723 other_name = EXPR_WFL_NODE (other_name);
5724 if (!DECL_CLINIT_P (other_method)
5725 && !DECL_CONSTRUCTOR_P (other_method)
5726 && method_name == other_name && method_sig == s)
5734 /* Report that abstract METHOD didn't find an implementation
5735 that CLASS can use. */
5738 char *t = xstrdup (lang_printable_name
5739 (TREE_TYPE (TREE_TYPE (method)), 0));
5740 tree ccn = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
5741 tree saved_wfl = NULL_TREE;
5743 if (TREE_CODE (DECL_NAME (method)) == EXPR_WITH_FILE_LOCATION)
5745 saved_wfl = DECL_NAME (method);
5746 DECL_NAME (method) = EXPR_WFL_NODE (DECL_NAME (method));
5750 (lookup_cl (class_decl),
5751 "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",
5752 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
5753 t, lang_printable_name (method, 0),
5754 (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))) ?
5755 "interface" : "class"),
5756 IDENTIFIER_POINTER (ccn),
5757 (CLASS_INTERFACE (class_decl) ? "interface" : "class"),
5758 IDENTIFIER_POINTER (DECL_NAME (class_decl)));
5763 DECL_NAME (method) = saved_wfl;
5768 /* Check that CLASS_DECL somehow implements all inherited abstract
5772 java_check_abstract_method_definitions (class_decl)
5775 tree class = TREE_TYPE (class_decl);
5779 if (CLASS_ABSTRACT (class_decl))
5782 /* Check for inherited types */
5783 for (super = CLASSTYPE_SUPER (class); super != object_type_node;
5784 super = CLASSTYPE_SUPER (super))
5786 if (!CLASS_ABSTRACT (TYPE_NAME (super)))
5789 check_abstract_method_definitions (0, class_decl, super);
5792 /* Check for implemented interfaces. */
5793 vector = TYPE_BINFO_BASETYPES (class);
5794 for (i = 1; i < TREE_VEC_LENGTH (vector); i++)
5796 super = BINFO_TYPE (TREE_VEC_ELT (vector, i));
5797 check_abstract_method_definitions (1, class_decl, super);
5801 /* Check all the methods of CLASS_DECL. Methods are first completed
5802 then checked according to regular method existance rules. If no
5803 constructor for CLASS_DECL were encountered, then build its
5807 java_check_regular_methods (class_decl)
5810 int saw_constructor = ANONYMOUS_CLASS_P (TREE_TYPE (class_decl));
5812 tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (class_decl));
5813 tree saved_found_wfl = NULL_TREE, found = NULL_TREE;
5816 /* It is not necessary to check methods defined in java.lang.Object */
5817 if (class == object_type_node)
5820 if (!TYPE_NVIRTUALS (class))
5821 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
5823 /* Should take interfaces into account. FIXME */
5824 for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
5827 tree method_wfl = DECL_NAME (method);
5830 /* If we previously found something and its name was saved,
5832 if (found && saved_found_wfl)
5834 DECL_NAME (found) = saved_found_wfl;
5835 saved_found_wfl = NULL_TREE;
5838 /* Check for redefinitions */
5839 if (check_method_redefinition (class, method))
5842 /* If we see one constructor a mark so we don't generate the
5843 default one. Also skip other verifications: constructors
5844 can't be inherited hence hiden or overriden */
5845 if (DECL_CONSTRUCTOR_P (method))
5847 saw_constructor = 1;
5851 /* We verify things thrown by the method. They must inherits from
5852 java.lang.Throwable */
5853 for (mthrows = DECL_FUNCTION_THROWS (method);
5854 mthrows; mthrows = TREE_CHAIN (mthrows))
5856 if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
5858 (TREE_PURPOSE (mthrows), "Class `%s' in `throws' clause must be a subclass of class `java.lang.Throwable'",
5860 (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
5863 sig = build_java_argument_signature (TREE_TYPE (method));
5864 found = lookup_argument_method2 (class, DECL_NAME (method), sig);
5866 /* Inner class can't declare static methods */
5867 if (METHOD_STATIC (method) && !TOPLEVEL_CLASS_DECL_P (class_decl))
5869 char *t = xstrdup (lang_printable_name (class, 0));
5871 (method_wfl, "Method `%s' can't be static in inner class `%s'. Only members of interfaces and top-level classes can be static",
5872 lang_printable_name (method, 0), t);
5876 /* Nothing overrides or it's a private method. */
5879 if (METHOD_PRIVATE (found))
5885 /* If found wasn't verified, it's DECL_NAME won't be set properly.
5886 We set it temporarily for the sake of the error report. */
5887 saved_found_wfl = DECL_NAME (found);
5888 reset_method_name (found);
5890 /* If `found' is declared in an interface, make sure the
5891 modifier matches. */
5892 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
5893 && clinit_identifier_node != DECL_NAME (found)
5894 && !METHOD_PUBLIC (method))
5896 tree found_decl = TYPE_NAME (DECL_CONTEXT (found));
5897 parse_error_context (method_wfl, "Class `%s' must override `%s' with a public method in order to implement interface `%s'",
5898 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
5899 lang_printable_name (method, 0),
5900 IDENTIFIER_POINTER (DECL_NAME (found_decl)));
5903 /* Can't override a method with the same name and different return
5905 if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
5908 (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
5911 "Method `%s' was defined with return type `%s' in class `%s'",
5912 lang_printable_name (found, 0), t,
5914 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
5918 aflags = get_access_flags_from_decl (found);
5919 /* If the method has default, access in an other package, then
5920 issue a warning that the current method doesn't override the
5921 one that was found elsewhere. Do not issue this warning when
5922 the match was found in java.lang.Object. */
5923 if (DECL_CONTEXT (found) != object_type_node
5924 && ((aflags & ACC_VISIBILITY) == 0)
5925 && !class_in_current_package (DECL_CONTEXT (found))
5926 && !DECL_CLINIT_P (found)
5927 && flag_not_overriding)
5929 parse_warning_context
5930 (method_wfl, "Method `%s' in class `%s' does not override the corresponding method in class `%s', which is private to a different package",
5931 lang_printable_name (found, 0),
5932 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
5933 IDENTIFIER_POINTER (DECL_NAME
5934 (TYPE_NAME (DECL_CONTEXT (found)))));
5938 /* Can't override final. Can't override static. */
5939 if (METHOD_FINAL (found) || METHOD_STATIC (found))
5941 /* Static *can* override static */
5942 if (METHOD_STATIC (found) && METHOD_STATIC (method))
5946 "%s methods can't be overriden. Method `%s' is %s in class `%s'",
5947 (METHOD_FINAL (found) ? "Final" : "Static"),
5948 lang_printable_name (found, 0),
5949 (METHOD_FINAL (found) ? "final" : "static"),
5951 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
5955 /* Static method can't override instance method. */
5956 if (METHOD_STATIC (method))
5960 "Instance methods can't be overriden by a static method. Method `%s' is an instance method in class `%s'",
5961 lang_printable_name (found, 0),
5963 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
5967 /* - Overriding/hiding public must be public
5968 - Overriding/hiding protected must be protected or public
5969 - If the overriden or hidden method has default (package)
5970 access, then the overriding or hiding method must not be
5971 private; otherwise, a compile-time error occurs. If
5972 `found' belongs to an interface, things have been already
5974 if (!CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found)))
5975 && ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method))
5976 || (METHOD_PROTECTED (found)
5977 && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
5978 || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
5979 && METHOD_PRIVATE (method))))
5983 "Methods can't be overridden to be more private. Method `%s' is not %s in class `%s'", lang_printable_name (method, 0),
5984 (METHOD_PUBLIC (method) ? "public" :
5985 (METHOD_PRIVATE (method) ? "private" : "protected")),
5986 IDENTIFIER_POINTER (DECL_NAME
5987 (TYPE_NAME (DECL_CONTEXT (found)))));
5991 /* Overriding methods must have compatible `throws' clauses on checked
5992 exceptions, if any */
5993 check_throws_clauses (method, method_wfl, found);
5995 /* Inheriting multiple methods with the same signature. FIXME */
5998 /* Don't forget eventual pending found and saved_found_wfl. Take
5999 into account that we might have exited because we saw an
6000 artificial method as the last entry. */
6002 if (found && !DECL_ARTIFICIAL (found) && saved_found_wfl)
6003 DECL_NAME (found) = saved_found_wfl;
6005 if (!TYPE_NVIRTUALS (class))
6006 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
6008 /* Search for inherited abstract method not yet implemented in this
6010 java_check_abstract_method_definitions (class_decl);
6012 if (!saw_constructor)
6013 fatal ("No constructor found");
6016 /* Return a non zero value if the `throws' clause of METHOD (if any)
6017 is incompatible with the `throws' clause of FOUND (if any). */
6020 check_throws_clauses (method, method_wfl, found)
6021 tree method, method_wfl, found;
6023 tree mthrows, fthrows;
6025 /* Can't check these things with class loaded from bytecode. FIXME */
6026 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (found)))
6029 for (mthrows = DECL_FUNCTION_THROWS (method);
6030 mthrows; mthrows = TREE_CHAIN (mthrows))
6032 /* We don't verify unchecked expressions */
6033 if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
6035 /* Checked expression must be compatible */
6036 for (fthrows = DECL_FUNCTION_THROWS (found);
6037 fthrows; fthrows = TREE_CHAIN (fthrows))
6038 if (inherits_from_p (TREE_VALUE (mthrows), TREE_VALUE (fthrows)))
6043 (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'",
6044 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))),
6045 lang_printable_name (found, 0),
6047 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6052 /* Check abstract method of interface INTERFACE */
6055 java_check_abstract_methods (interface_decl)
6056 tree interface_decl;
6059 tree method, basetype_vec, found;
6060 tree interface = TREE_TYPE (interface_decl);
6062 for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
6064 tree method_wfl = DECL_NAME (method);
6066 /* 2- Check for double definition inside the defining interface */
6067 if (check_method_redefinition (interface, method))
6070 /* 3- Overriding is OK as far as we preserve the return type and
6071 the thrown exceptions (FIXME) */
6072 found = lookup_java_interface_method2 (interface, method);
6076 tree saved_found_wfl = DECL_NAME (found);
6077 reset_method_name (found);
6078 t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
6081 "Method `%s' was defined with return type `%s' in class `%s'",
6082 lang_printable_name (found, 0), t,
6084 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6086 DECL_NAME (found) = saved_found_wfl;
6091 /* 4- Inherited methods can't differ by their returned types */
6092 if (!(basetype_vec = TYPE_BINFO_BASETYPES (interface)))
6094 n = TREE_VEC_LENGTH (basetype_vec);
6095 for (i = 0; i < n; i++)
6097 tree sub_interface_method, sub_interface;
6098 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
6101 sub_interface = BINFO_TYPE (vec_elt);
6102 for (sub_interface_method = TYPE_METHODS (sub_interface);
6103 sub_interface_method;
6104 sub_interface_method = TREE_CHAIN (sub_interface_method))
6106 found = lookup_java_interface_method2 (interface,
6107 sub_interface_method);
6108 if (found && (found != sub_interface_method))
6110 tree saved_found_wfl = DECL_NAME (found);
6111 reset_method_name (found);
6113 (lookup_cl (sub_interface_method),
6114 "Interface `%s' inherits method `%s' from interface `%s'. This method is redefined with a different return type in interface `%s'",
6115 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
6116 lang_printable_name (found, 0),
6118 (DECL_NAME (TYPE_NAME
6119 (DECL_CONTEXT (sub_interface_method)))),
6121 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
6122 DECL_NAME (found) = saved_found_wfl;
6128 /* Lookup methods in interfaces using their name and partial
6129 signature. Return a matching method only if their types differ. */
6132 lookup_java_interface_method2 (class, method_decl)
6133 tree class, method_decl;
6136 tree basetype_vec = TYPE_BINFO_BASETYPES (class), to_return;
6141 n = TREE_VEC_LENGTH (basetype_vec);
6142 for (i = 0; i < n; i++)
6144 tree vec_elt = TREE_VEC_ELT (basetype_vec, i), to_return;
6145 if ((BINFO_TYPE (vec_elt) != object_type_node)
6147 lookup_java_method2 (BINFO_TYPE (vec_elt), method_decl, 1)))
6150 for (i = 0; i < n; i++)
6152 to_return = lookup_java_interface_method2
6153 (BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i)), method_decl);
6161 /* Lookup method using their name and partial signature. Return a
6162 matching method only if their types differ. */
6165 lookup_java_method2 (clas, method_decl, do_interface)
6166 tree clas, method_decl;
6169 tree method, method_signature, method_name, method_type, name;
6171 method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
6172 name = DECL_NAME (method_decl);
6173 method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6174 EXPR_WFL_NODE (name) : name);
6175 method_type = TREE_TYPE (TREE_TYPE (method_decl));
6177 while (clas != NULL_TREE)
6179 for (method = TYPE_METHODS (clas);
6180 method != NULL_TREE; method = TREE_CHAIN (method))
6182 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
6183 tree name = DECL_NAME (method);
6184 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
6185 EXPR_WFL_NODE (name) : name) == method_name
6186 && method_sig == method_signature
6187 && TREE_TYPE (TREE_TYPE (method)) != method_type)
6190 clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
6195 /* Return the line that matches DECL line number, and try its best to
6196 position the column number. Used during error reports. */
6202 static tree cl = NULL_TREE;
6208 if (cl == NULL_TREE)
6209 cl = build_expr_wfl (NULL_TREE, NULL, 0, 0);
6211 EXPR_WFL_FILENAME_NODE (cl) = get_identifier (DECL_SOURCE_FILE (decl));
6212 EXPR_WFL_SET_LINECOL (cl, DECL_SOURCE_LINE_FIRST (decl), -1);
6214 line = java_get_line_col (IDENTIFIER_POINTER (EXPR_WFL_FILENAME_NODE (cl)),
6215 EXPR_WFL_LINENO (cl), EXPR_WFL_COLNO (cl));
6217 found = strstr ((const char *)line,
6218 (const char *)IDENTIFIER_POINTER (DECL_NAME (decl)));
6220 EXPR_WFL_SET_LINECOL (cl, EXPR_WFL_LINENO (cl), found - line);
6225 /* Look for a simple name in the single-type import list */
6228 find_name_in_single_imports (name)
6233 for (node = ctxp->import_list; node; node = TREE_CHAIN (node))
6234 if (TREE_VALUE (node) == name)
6235 return (EXPR_WFL_NODE (TREE_PURPOSE (node)));
6240 /* Process all single-type import. */
6248 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
6250 tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import));
6252 /* Don't load twice something already defined. */
6253 if (IDENTIFIER_CLASS_VALUE (to_be_found))
6255 QUALIFIED_P (to_be_found) = 1;
6256 load_class (to_be_found, 0);
6258 check_pkg_class_access (to_be_found, TREE_PURPOSE (import));
6259 if (!IDENTIFIER_CLASS_VALUE (to_be_found))
6261 parse_error_context (TREE_PURPOSE (import),
6262 "Class or interface `%s' not found in import",
6263 IDENTIFIER_POINTER (to_be_found));
6272 /* Possibly find a class imported by a single-type import statement. Return
6273 1 if an error occured, 0 otherwise. */
6276 find_in_imports (class_type)
6281 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
6282 if (TREE_VALUE (import) == TYPE_NAME (class_type))
6284 TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
6285 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
6291 note_possible_classname (name, len)
6296 if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
6298 else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
6302 node = ident_subst (name, len, "", '/', '.', "");
6303 IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
6304 QUALIFIED_P (node) = strchr (name, '/') ? 1 : 0;
6308 /* Read a import directory, gathering potential match for further type
6309 references. Indifferently reads a filesystem or a ZIP archive
6313 read_import_dir (wfl)
6316 tree package_id = EXPR_WFL_NODE (wfl);
6317 const char *package_name = IDENTIFIER_POINTER (package_id);
6318 int package_length = IDENTIFIER_LENGTH (package_id);
6320 JCF *saved_jcf = current_jcf;
6325 struct buffer filename[1];
6328 if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
6330 IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
6332 BUFFER_INIT (filename);
6333 buffer_grow (filename, package_length + 100);
6335 for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
6337 const char *entry_name = jcf_path_name (entry);
6338 int entry_length = strlen (entry_name);
6339 if (jcf_path_is_zipfile (entry))
6342 buffer_grow (filename, entry_length);
6343 memcpy (filename->data, entry_name, entry_length - 1);
6344 filename->data[entry_length-1] = '\0';
6345 zipf = opendir_in_zip (filename->data, jcf_path_is_system (entry));
6347 error ("malformed .zip archive in CLASSPATH: %s", entry_name);
6350 ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
6351 BUFFER_RESET (filename);
6352 for (k = 0; k < package_length; k++)
6354 char ch = package_name[k];
6355 *filename->ptr++ = ch == '.' ? '/' : ch;
6357 *filename->ptr++ = '/';
6359 for (k = 0; k < zipf->count; k++, zipd = ZIPDIR_NEXT (zipd))
6361 const char *current_entry = ZIPDIR_FILENAME (zipd);
6362 int current_entry_len = zipd->filename_length;
6364 if (current_entry_len >= BUFFER_LENGTH (filename)
6365 && strncmp (filename->data, current_entry,
6366 BUFFER_LENGTH (filename)) != 0)
6368 found |= note_possible_classname (current_entry,
6375 BUFFER_RESET (filename);
6376 buffer_grow (filename, entry_length + package_length + 4);
6377 strcpy (filename->data, entry_name);
6378 filename->ptr = filename->data + entry_length;
6379 for (k = 0; k < package_length; k++)
6381 char ch = package_name[k];
6382 *filename->ptr++ = ch == '.' ? '/' : ch;
6384 *filename->ptr = '\0';
6386 dirp = opendir (filename->data);
6389 *filename->ptr++ = '/';
6394 struct dirent *direntp = readdir (dirp);
6397 d_name = direntp->d_name;
6398 len = strlen (direntp->d_name);
6399 buffer_grow (filename, len+1);
6400 strcpy (filename->ptr, d_name);
6401 found |= note_possible_classname (filename->data + entry_length,
6402 package_length+len+1);
6409 free (filename->data);
6411 /* Here we should have a unified way of retrieving an entry, to be
6415 static int first = 1;
6418 error ("Can't find default package `%s'. Check the CLASSPATH environment variable and the access to the archives.", package_name);
6423 parse_error_context (wfl, "Package `%s' not found in import",
6425 current_jcf = saved_jcf;
6428 current_jcf = saved_jcf;
6431 /* Possibly find a type in the import on demands specified
6432 types. Returns 1 if an error occured, 0 otherwise. Run throught the
6433 entire list, to detected potential double definitions. */
6436 find_in_imports_on_demand (class_type)
6439 tree node, import, node_to_use = NULL_TREE;
6441 tree cl = NULL_TREE;
6443 for (import = ctxp->import_demand_list; import; import = TREE_CHAIN (import))
6445 const char *id_name;
6446 obstack_grow (&temporary_obstack,
6447 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
6448 IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
6449 obstack_1grow (&temporary_obstack, '.');
6450 obstack_grow0 (&temporary_obstack,
6451 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
6452 IDENTIFIER_LENGTH (TYPE_NAME (class_type)));
6453 id_name = obstack_finish (&temporary_obstack);
6455 node = maybe_get_identifier (id_name);
6456 if (node && IS_A_CLASSFILE_NAME (node))
6460 cl = TREE_PURPOSE (import);
6468 (import, "Type `%s' also potentially defined in package `%s'",
6469 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
6470 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))));
6477 /* Setup lineno so that it refers to the line of the import (in
6478 case we parse a class file and encounter errors */
6480 int saved_lineno = lineno;
6481 lineno = EXPR_WFL_LINENO (cl);
6482 TYPE_NAME (class_type) = node_to_use;
6483 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
6484 decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
6485 /* If there is no DECL set for the class or if the class isn't
6486 loaded and not seen in source yet, the load */
6487 if (!decl || (!CLASS_LOADED_P (TREE_TYPE (decl))
6488 && !CLASS_FROM_SOURCE_P (TREE_TYPE (decl))))
6489 load_class (node_to_use, 0);
6490 lineno = saved_lineno;
6491 return check_pkg_class_access (TYPE_NAME (class_type), cl);
6494 return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
6498 resolve_package (pkg, next)
6502 tree type_name = NULL_TREE;
6503 const char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (pkg));
6505 /* The trick is to determine when the package name stops and were
6506 the name of something contained in the package starts. Then we
6507 return a fully qualified name of what we want to get. */
6509 /* Do a quick search on well known package names */
6510 if (!strncmp (name, "java.lang.reflect", 17))
6513 TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg))));
6514 type_name = lookup_package_type (name, 17);
6516 else if (!strncmp (name, "java.lang", 9))
6518 *next = TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg)));
6519 type_name = lookup_package_type (name, 9);
6522 /* If we found something here, return */
6526 *next = EXPR_WFL_QUALIFICATION (pkg);
6528 /* Try the current package. */
6529 if (ctxp->package && !strncmp (name, IDENTIFIER_POINTER (ctxp->package),
6530 IDENTIFIER_LENGTH (ctxp->package)))
6533 lookup_package_type_and_set_next (name,
6534 IDENTIFIER_LENGTH (ctxp->package),
6540 /* Search in imported package */
6541 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
6543 tree current_pkg_name = EXPR_WFL_NODE (TREE_PURPOSE (current));
6544 int len = IDENTIFIER_LENGTH (current_pkg_name);
6545 if (!strncmp (name, IDENTIFIER_POINTER (current_pkg_name), len))
6549 breakdown_qualified (&left, &dummy, current_pkg_name);
6550 len = IDENTIFIER_LENGTH (left);
6551 type_name = lookup_package_type_and_set_next (name, len, next);
6557 /* Try to progressively construct a type name */
6558 if (TREE_CODE (pkg) == EXPR_WITH_FILE_LOCATION)
6559 for (acc = NULL_TREE, current = EXPR_WFL_QUALIFICATION (pkg);
6560 current; current = TREE_CHAIN (current))
6562 acc = merge_qualified_name (acc, EXPR_WFL_NODE (QUAL_WFL (current)));
6563 if ((type_name = resolve_no_layout (acc, NULL_TREE)))
6573 lookup_package_type_and_set_next (name, len, next)
6579 tree type_name = lookup_package_type (name, len);
6584 ptr = IDENTIFIER_POINTER (type_name);
6585 while (ptr && (ptr = strchr (ptr, '.')))
6587 *next = TREE_CHAIN (*next);
6594 lookup_package_type (name, from)
6599 const char *sub = &name[from+1];
6600 while (*sub != '.' && *sub)
6602 strncpy (subname, name, sub-name);
6603 subname [sub-name] = '\0';
6604 return get_identifier (subname);
6607 /* Check that CLASS_NAME refers to a PUBLIC class. Return 0 if no
6608 access violations were found, 1 otherwise. */
6611 check_pkg_class_access (class_name, cl)
6617 if (!QUALIFIED_P (class_name) || !IDENTIFIER_CLASS_VALUE (class_name))
6620 if (!(type = TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_name))))
6623 if (!CLASS_PUBLIC (TYPE_NAME (type)))
6625 /* Access to a private class within the same package is
6628 breakdown_qualified (&l, &r, class_name);
6629 if (l == ctxp->package)
6633 (cl, "Can't access %s `%s'. Only public classes and interfaces in other packages can be accessed",
6634 (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
6635 IDENTIFIER_POINTER (class_name));
6641 /* Local variable declaration. */
6644 declare_local_variables (modifier, type, vlist)
6649 tree decl, current, saved_type;
6650 tree type_wfl = NULL_TREE;
6654 /* Push a new block if statements were seen between the last time we
6655 pushed a block and now. Keep a cound of block to close */
6656 if (BLOCK_EXPR_BODY (GET_CURRENT_BLOCK (current_function_decl)))
6658 tree body = GET_CURRENT_BLOCK (current_function_decl);
6659 tree b = enter_block ();
6660 BLOCK_EXPR_ORIGIN (b) = body;
6666 for (i = 0; i <= 10; i++) if (1 << i & modifier) break;
6667 if (modifier == ACC_FINAL)
6672 (ctxp->modifier_ctx [i],
6673 "Only `final' is allowed as a local variables modifier");
6678 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
6679 hold the TYPE value if a new incomplete has to be created (as
6680 opposed to being found already existing and reused). */
6681 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
6683 /* If TYPE is fully resolved and we don't have a reference, make one */
6684 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
6686 /* Go through all the declared variables */
6687 for (current = vlist, saved_type = type; current;
6688 current = TREE_CHAIN (current), type = saved_type)
6690 tree other, real_type;
6691 tree wfl = TREE_PURPOSE (current);
6692 tree name = EXPR_WFL_NODE (wfl);
6693 tree init = TREE_VALUE (current);
6695 /* Process NAME, as it may specify extra dimension(s) for it */
6696 type = build_array_from_name (type, type_wfl, name, &name);
6698 /* Variable redefinition check */
6699 if ((other = lookup_name_in_blocks (name)))
6701 variable_redefinition_error (wfl, name, TREE_TYPE (other),
6702 DECL_SOURCE_LINE (other));
6706 /* Type adjustment. We may have just readjusted TYPE because
6707 the variable specified more dimensions. Make sure we have
6708 a reference if we can and don't have one already. */
6709 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
6711 real_type = GET_REAL_TYPE (type);
6712 /* Never layout this decl. This will be done when its scope
6714 decl = build_decl (VAR_DECL, name, real_type);
6715 LOCAL_FINAL (decl) = final_p;
6716 BLOCK_CHAIN_DECL (decl);
6718 /* If doing xreferencing, replace the line number with the WFL
6721 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (wfl);
6723 /* Don't try to use an INIT statement when an error was found */
6724 if (init && java_error_count)
6727 /* Add the initialization function to the current function's code */
6730 /* Name might have been readjusted */
6731 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = name;
6732 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
6733 java_method_add_stmt (current_function_decl,
6734 build_debugable_stmt (EXPR_WFL_LINECOL (init),
6738 /* Setup dependency the type of the decl */
6742 register_incomplete_type (JDEP_VARIABLE, type_wfl, decl, type);
6743 dep = CLASSD_LAST (ctxp->classd_list);
6744 JDEP_GET_PATCH (dep) = &TREE_TYPE (decl);
6747 SOURCE_FRONTEND_DEBUG (("Defined locals"));
6750 /* Called during parsing. Build decls from argument list. */
6753 source_start_java_method (fndecl)
6760 int flag_inner = DECL_CONSTRUCTOR_P (fndecl)
6761 && (INNER_CLASS_TYPE_P (DECL_CONTEXT (fndecl)) ? 1 : 0);
6767 current_function_decl = fndecl;
6769 /* New scope for the function */
6771 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
6772 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
6774 tree type = TREE_VALUE (tem);
6775 tree name = TREE_PURPOSE (tem);
6777 /* If type is incomplete. Create an incomplete decl and ask for
6778 the decl to be patched later */
6779 if (INCOMPLETE_TYPE_P (type))
6782 tree real_type = GET_REAL_TYPE (type);
6783 parm_decl = build_decl (PARM_DECL, name, real_type);
6784 type = obtain_incomplete_type (type);
6785 register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
6786 jdep = CLASSD_LAST (ctxp->classd_list);
6787 JDEP_MISC (jdep) = name;
6788 JDEP_GET_PATCH (jdep) = &TREE_TYPE (parm_decl);
6791 parm_decl = build_decl (PARM_DECL, name, type);
6793 /* Remember if a local variable was declared final (via its
6794 TREE_LIST of type/name.) Set LOCAL_FINAL accordingly. */
6795 if (ARG_FINAL_P (tem))
6796 LOCAL_FINAL (parm_decl) = 1;
6798 BLOCK_CHAIN_DECL (parm_decl);
6801 /* If this is a constructor of a inner class, hide the extra
6802 this$<n> parameter */
6803 if (i == 0 && flag_inner)
6805 tree link = TREE_CHAIN (tem);
6806 tree type = DECL_CONTEXT (TYPE_NAME (DECL_CONTEXT (fndecl)));
6808 type = build_pointer_type (TREE_TYPE (type));
6809 parm_decl = build_decl (PARM_DECL,
6810 build_current_thisn (current_class), type);
6811 BLOCK_CHAIN_DECL (parm_decl);
6812 /* We hide the this$<n> decl in the name field of its
6813 parameter declaration. */
6814 parm_decl = build_tree_list (DECL_NAME (parm_decl), type);
6815 TREE_CHAIN (tem) = parm_decl;
6816 TREE_CHAIN (parm_decl) = link;
6823 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
6824 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) =
6826 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
6827 DECL_MAX_LOCALS (current_function_decl) = i;
6830 /* Called during parsing. Creates an artificial method declaration. */
6833 create_artificial_method (class, flags, type, name, args)
6836 tree type, name, args;
6840 java_parser_context_save_global ();
6842 mdecl = make_node (FUNCTION_TYPE);
6843 TREE_TYPE (mdecl) = type;
6844 TYPE_ARG_TYPES (mdecl) = args;
6845 mdecl = add_method (class, flags, name, build_java_signature (mdecl));
6846 java_parser_context_restore_global ();
6847 DECL_ARTIFICIAL (mdecl) = 1;
6851 /* Starts the body if an artifical method. */
6854 start_artificial_method_body (mdecl)
6857 DECL_SOURCE_LINE (mdecl) = 1;
6858 DECL_SOURCE_LINE_MERGE (mdecl, 1);
6859 source_start_java_method (mdecl);
6864 end_artificial_method_body (mdecl)
6867 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
6871 /* Called during expansion. Push decls formerly built from argument
6872 list so they're usable during expansion. */
6875 expand_start_java_method (fndecl)
6880 current_function_decl = fndecl;
6883 fprintf (stderr, " [%s.", lang_printable_name (DECL_CONTEXT (fndecl), 0));
6884 announce_function (fndecl);
6886 fprintf (stderr, "]");
6888 pushlevel (1); /* Prepare for a parameter push */
6889 ptr = &DECL_ARGUMENTS (fndecl);
6890 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
6893 tree next = TREE_CHAIN (tem);
6894 tree type = TREE_TYPE (tem);
6895 if (PROMOTE_PROTOTYPES
6896 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
6897 && INTEGRAL_TYPE_P (type))
6898 type = integer_type_node;
6899 DECL_ARG_TYPE (tem) = type;
6900 layout_decl (tem, 0);
6903 ptr = &TREE_CHAIN (tem);
6907 pushdecl_force_head (DECL_ARGUMENTS (fndecl));
6908 lineno = DECL_SOURCE_LINE_FIRST (fndecl);
6911 /* Terminate a function and expand its body. */
6914 source_end_java_method ()
6916 tree fndecl = current_function_decl;
6917 int flag_asynchronous_exceptions = asynchronous_exceptions;
6922 java_parser_context_save_global ();
6923 lineno = ctxp->last_ccb_indent1;
6925 /* Set EH language codes */
6926 java_set_exception_lang_code ();
6928 /* Turn function bodies with only a NOP expr null, so they don't get
6929 generated at all and we won't get warnings when using the -W
6931 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) == empty_stmt_node)
6932 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) = NULL_TREE;
6934 /* Generate function's code */
6935 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))
6936 && ! flag_emit_class_files
6937 && ! flag_emit_xref)
6938 expand_expr_stmt (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)));
6940 /* pop out of its parameters */
6941 pushdecl_force_head (DECL_ARGUMENTS (fndecl));
6943 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6945 /* Generate rtl for function exit. */
6946 if (! flag_emit_class_files && ! flag_emit_xref)
6948 lineno = DECL_SOURCE_LINE_LAST (fndecl);
6949 /* Emit catch-finally clauses */
6951 expand_function_end (input_filename, lineno, 0);
6953 /* FIXME: If the current method contains any exception handlers,
6954 force asynchronous_exceptions: this is necessary because signal
6955 handlers in libjava may throw exceptions. This is far from being
6956 a perfect solution, but it's better than doing nothing at all.*/
6958 asynchronous_exceptions = 1;
6960 /* Run the optimizers and output assembler code for this function. */
6961 rest_of_compilation (fndecl);
6964 current_function_decl = NULL_TREE;
6965 permanent_allocation (1);
6966 java_parser_context_restore_global ();
6967 asynchronous_exceptions = flag_asynchronous_exceptions;
6970 /* Record EXPR in the current function block. Complements compound
6971 expression second operand if necessary. */
6974 java_method_add_stmt (fndecl, expr)
6977 if (!GET_CURRENT_BLOCK (fndecl))
6979 return add_stmt_to_block (GET_CURRENT_BLOCK (fndecl), NULL_TREE, expr);
6983 add_stmt_to_block (b, type, stmt)
6986 tree body = BLOCK_EXPR_BODY (b), c;
6988 if (java_error_count)
6991 if ((c = add_stmt_to_compound (body, type, stmt)) == body)
6994 BLOCK_EXPR_BODY (b) = c;
6995 TREE_SIDE_EFFECTS (c) = 1;
6999 /* Add STMT to EXISTING if possible, otherwise create a new
7000 COMPOUND_EXPR and add STMT to it. */
7003 add_stmt_to_compound (existing, type, stmt)
7004 tree existing, type, stmt;
7007 return build (COMPOUND_EXPR, type, existing, stmt);
7012 /* Hold THIS for the scope of the current public method decl. */
7013 static tree current_this;
7015 void java_layout_seen_class_methods ()
7017 tree previous_list = all_class_list;
7018 tree end = NULL_TREE;
7023 for (current = previous_list;
7024 current != end; current = TREE_CHAIN (current))
7025 layout_class_methods (TREE_TYPE (TREE_VALUE (current)));
7027 if (previous_list != all_class_list)
7029 end = previous_list;
7030 previous_list = all_class_list;
7038 java_reorder_fields ()
7040 static tree stop_reordering = NULL_TREE;
7043 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
7045 current_class = TREE_TYPE (TREE_VALUE (current));
7047 if (current_class == stop_reordering)
7050 /* Reverse the fields, but leave the dummy field in front.
7051 Fields are already ordered for Object and Class */
7052 if (TYPE_FIELDS (current_class) && current_class != object_type_node
7053 && current_class != class_type_node)
7055 /* If the dummy field is there, reverse the right fields and
7056 just layout the type for proper fields offset */
7057 if (!DECL_NAME (TYPE_FIELDS (current_class)))
7059 tree fields = TYPE_FIELDS (current_class);
7060 TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
7061 TYPE_SIZE (current_class) = NULL_TREE;
7063 /* We don't have a dummy field, we need to layout the class,
7064 after having reversed the fields */
7067 TYPE_FIELDS (current_class) =
7068 nreverse (TYPE_FIELDS (current_class));
7069 TYPE_SIZE (current_class) = NULL_TREE;
7073 stop_reordering = TREE_TYPE (TREE_VALUE (ctxp->gclass_list));
7076 /* Layout the methods of all classes loaded in one way on an
7077 other. Check methods of source parsed classes. Then reorder the
7078 fields and layout the classes or the type of all source parsed
7082 java_layout_classes ()
7085 int save_error_count = java_error_count;
7087 /* Layout the methods of all classes seen so far */
7088 java_layout_seen_class_methods ();
7089 java_parse_abort_on_error ();
7090 all_class_list = NULL_TREE;
7092 /* Then check the methods of all parsed classes */
7093 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
7094 if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
7095 CHECK_METHODS (TREE_VALUE (current));
7096 java_parse_abort_on_error ();
7098 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
7100 current_class = TREE_TYPE (TREE_VALUE (current));
7101 layout_class (current_class);
7103 /* From now on, the class is considered completely loaded */
7104 CLASS_LOADED_P (current_class) = 1;
7106 /* Error reported by the caller */
7107 if (java_error_count)
7111 /* We might have reloaded classes durign the process of laying out
7112 classes for code generation. We must layout the methods of those
7113 late additions, as constructor checks might use them */
7114 java_layout_seen_class_methods ();
7115 java_parse_abort_on_error ();
7118 /* Expand methods in the current set of classes rememebered for
7122 java_complete_expand_classes ()
7126 do_not_fold = flag_emit_xref;
7128 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
7129 if (!INNER_CLASS_DECL_P (current))
7130 java_complete_expand_class (current);
7133 /* Expand the methods found in OUTER, starting first by OUTER's inner
7137 java_complete_expand_class (outer)
7142 set_nested_class_simple_name_value (outer, 1); /* Set */
7144 /* We need to go after all inner classes and start expanding them,
7145 starting with most nested ones. We have to do that because nested
7146 classes might add functions to outer classes */
7148 for (inner_list = DECL_INNER_CLASS_LIST (outer);
7149 inner_list; inner_list = TREE_CHAIN (inner_list))
7150 java_complete_expand_class (TREE_PURPOSE (inner_list));
7152 java_complete_expand_methods (outer);
7153 set_nested_class_simple_name_value (outer, 0); /* Reset */
7156 /* Expand methods registered in CLASS_DECL. The general idea is that
7157 we expand regular methods first. This allows us get an estimate on
7158 how outer context local alias fields are really used so we can add
7159 to the constructor just enough code to initialize them properly (it
7160 also lets us generate $finit$ correctly.) Then we expand the
7161 constructors and then <clinit>. */
7164 java_complete_expand_methods (class_decl)
7167 tree clinit, finit, decl, first_decl;
7169 current_class = TREE_TYPE (class_decl);
7171 /* Initialize a new constant pool */
7172 init_outgoing_cpool ();
7174 /* Pre-expand <clinit> to figure whether we really need it or
7175 not. If we do need it, we pre-expand the static fields so they're
7176 ready to be used somewhere else. <clinit> will be fully expanded
7177 after we processed the constructors. */
7178 first_decl = TYPE_METHODS (current_class);
7179 clinit = maybe_generate_pre_expand_clinit (current_class);
7181 /* Then generate $finit$ (if we need to) because constructor will
7183 if (TYPE_FINIT_STMT_LIST (current_class))
7185 finit = generate_finit (current_class);
7186 java_complete_expand_method (finit);
7189 /* Now do the constructors */
7190 for (decl = first_decl ; !java_error_count && decl; decl = TREE_CHAIN (decl))
7194 if (!DECL_CONSTRUCTOR_P (decl))
7197 no_body = !DECL_FUNCTION_BODY (decl);
7198 /* Don't generate debug info on line zero when expanding a
7199 generated constructor. */
7201 restore_line_number_status (1);
7203 java_complete_expand_method (decl);
7206 restore_line_number_status (0);
7209 /* First, do the ordinary methods. */
7210 for (decl = first_decl; decl; decl = TREE_CHAIN (decl))
7212 /* Skip abstract or native methods */
7213 if (METHOD_ABSTRACT (decl) || METHOD_NATIVE (decl)
7214 || DECL_CONSTRUCTOR_P (decl) || DECL_CLINIT_P (decl))
7216 java_complete_expand_method (decl);
7219 /* If there is indeed a <clinit>, fully expand it now */
7222 /* Prevent the use of `this' inside <clinit> */
7223 ctxp->explicit_constructor_p = 1;
7224 java_complete_expand_method (clinit);
7225 ctxp->explicit_constructor_p = 0;
7228 /* Now verify constructor circularity (stop after the first one we
7230 if (!CLASS_INTERFACE (class_decl))
7231 for (decl = TYPE_METHODS (current_class); decl; decl = TREE_CHAIN (decl))
7232 if (DECL_CONSTRUCTOR_P (decl)
7233 && verify_constructor_circularity (decl, decl))
7236 /* Save the constant pool. We'll need to restore it later. */
7237 TYPE_CPOOL (current_class) = outgoing_cpool;
7240 /* Hold a list of catch clauses list. The first element of this list is
7241 the list of the catch clauses of the currently analysed try block. */
7242 static tree currently_caught_type_list;
7244 /* Attempt to create <clinit>. Pre-expand static fields so they can be
7245 safely used in some other methods/constructors. */
7248 maybe_generate_pre_expand_clinit (class_type)
7251 tree current, mdecl;
7253 if (!TYPE_CLINIT_STMT_LIST (class_type))
7256 /* Go through all static fields and pre expand them */
7257 for (current = TYPE_FIELDS (class_type); current;
7258 current = TREE_CHAIN (current))
7259 if (FIELD_STATIC (current))
7260 build_field_ref (NULL_TREE, class_type, DECL_NAME (current));
7262 /* Then build the <clinit> method */
7263 mdecl = create_artificial_method (class_type, ACC_STATIC, void_type_node,
7264 clinit_identifier_node, end_params_node);
7265 layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
7267 start_artificial_method_body (mdecl);
7269 /* We process the list of assignment we produced as the result of
7270 the declaration of initialized static field and add them as
7271 statement to the <clinit> method. */
7272 for (current = TYPE_CLINIT_STMT_LIST (class_type); current;
7273 current = TREE_CHAIN (current))
7275 /* We build the assignment expression that will initialize the
7276 field to its value. There are strict rules on static
7277 initializers (8.5). FIXME */
7278 tree stmt = build_debugable_stmt (EXPR_WFL_LINECOL (current), current);
7279 java_method_add_stmt (mdecl, stmt);
7282 end_artificial_method_body (mdecl);
7284 /* Now we want to place <clinit> as the last method for interface so
7285 that it doesn't interfere with the dispatch table based
7287 if (CLASS_INTERFACE (TYPE_NAME (class_type))
7288 && TREE_CHAIN (TYPE_METHODS (class_type)))
7291 TYPE_METHODS (class_type) = TREE_CHAIN (TYPE_METHODS (class_type));
7293 while (TREE_CHAIN (current))
7294 current = TREE_CHAIN (current);
7295 TREE_CHAIN (current) = mdecl;
7296 TREE_CHAIN (mdecl) = NULL_TREE;
7302 /* Complete and expand a method. */
7305 java_complete_expand_method (mdecl)
7308 current_function_decl = mdecl;
7309 /* Fix constructors before expanding them */
7310 if (DECL_CONSTRUCTOR_P (mdecl))
7311 fix_constructors (mdecl);
7313 /* Expand functions that have a body */
7314 if (DECL_FUNCTION_BODY (mdecl))
7316 tree fbody = DECL_FUNCTION_BODY (mdecl);
7317 tree block_body = BLOCK_EXPR_BODY (fbody);
7318 tree exception_copy = NULL_TREE;
7319 expand_start_java_method (mdecl);
7320 build_result_decl (mdecl);
7323 = (!METHOD_STATIC (mdecl) ?
7324 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl)) : NULL_TREE);
7326 /* Purge the `throws' list of unchecked exceptions. If we're
7327 doing xref, save a copy of the list and re-install it
7330 exception_copy = copy_list (DECL_FUNCTION_THROWS (mdecl));
7332 purge_unchecked_exceptions (mdecl);
7334 /* Install exceptions thrown with `throws' */
7335 PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
7337 if (block_body != NULL_TREE)
7339 block_body = java_complete_tree (block_body);
7341 if (!flag_emit_xref)
7342 check_for_initialization (block_body);
7343 ctxp->explicit_constructor_p = 0;
7345 BLOCK_EXPR_BODY (fbody) = block_body;
7347 /* If we saw a return but couldn't evaluate it properly, we'll
7348 have an error_mark_node here. */
7349 if (block_body != error_mark_node
7350 && (block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
7351 && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE
7353 missing_return_error (current_function_decl);
7355 complete_start_java_method (mdecl);
7357 /* Don't go any further if we've found error(s) during the
7359 if (!java_error_count)
7360 source_end_java_method ();
7363 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
7367 /* Pop the exceptions and sanity check */
7369 if (currently_caught_type_list)
7370 fatal ("Exception list non empty - java_complete_expand_method");
7373 DECL_FUNCTION_THROWS (mdecl) = exception_copy;
7379 /* This section of the code deals with accessing enclosing context
7380 fields either directly by using the relevant access to this$<n> or
7381 by invoking an access method crafted for that purpose. */
7383 /* Build the necessary access from an inner class to an outer
7384 class. This routine could be optimized to cache previous result
7385 (decl, current_class and returned access). When an access method
7386 needs to be generated, it always takes the form of a read. It might
7387 be later turned into a write by calling outer_field_access_fix. */
7390 build_outer_field_access (id, decl)
7393 tree access = NULL_TREE;
7394 tree ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
7396 /* If decl's class is the direct outer class of the current_class,
7397 build the access as `this$<n>.<field>'. Not that we will break
7398 the `private' barrier if we're not emitting bytecodes. */
7399 if (ctx == DECL_CONTEXT (decl)
7400 && (!FIELD_PRIVATE (decl) || !flag_emit_class_files ))
7402 tree thisn = build_current_thisn (current_class);
7403 access = make_qualified_primary (build_wfl_node (thisn),
7404 id, EXPR_WFL_LINECOL (id));
7406 /* Otherwise, generate access methods to outer this and access the
7407 field (either using an access method or by direct access.) */
7410 int lc = EXPR_WFL_LINECOL (id);
7412 /* Now we chain the required number of calls to the access$0 to
7413 get a hold to the enclosing instance we need, and the we
7414 build the field access. */
7415 access = build_access_to_thisn (ctx, DECL_CONTEXT (decl), lc);
7417 /* If the field is private and we're generating bytecode, then
7418 we generate an access method */
7419 if (FIELD_PRIVATE (decl) && flag_emit_class_files )
7421 tree name = build_outer_field_access_methods (decl);
7422 access = build_outer_field_access_expr (lc, DECL_CONTEXT (decl),
7423 name, access, NULL_TREE);
7425 /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'.
7426 Once again we break the `private' access rule from a foreign
7429 access = make_qualified_primary (access, id, lc);
7431 return resolve_expression_name (access, NULL);
7434 /* Return a non zero value if NODE describes an outer field inner
7438 outer_field_access_p (type, decl)
7441 if (!INNER_CLASS_TYPE_P (type)
7442 || TREE_CODE (decl) != FIELD_DECL
7443 || DECL_CONTEXT (decl) == type)
7446 for (type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))); ;
7447 type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))))
7449 if (type == DECL_CONTEXT (decl))
7451 if (!DECL_CONTEXT (TYPE_NAME (type)))
7458 /* Return a non zero value if NODE represents an outer field inner
7459 access that was been already expanded. As a side effect, it returns
7460 the name of the field being accessed and the argument passed to the
7461 access function, suitable for a regeneration of the access method
7462 call if necessary. */
7465 outer_field_expanded_access_p (node, name, arg_type, arg)
7466 tree node, *name, *arg_type, *arg;
7470 if (TREE_CODE (node) != CALL_EXPR)
7473 /* Well, gcj generates slightly different tree nodes when compiling
7474 to native or bytecodes. It's the case for function calls. */
7476 if (flag_emit_class_files
7477 && TREE_CODE (node) == CALL_EXPR
7478 && OUTER_FIELD_ACCESS_IDENTIFIER_P (DECL_NAME (TREE_OPERAND (node, 0))))
7480 else if (!flag_emit_class_files)
7482 node = TREE_OPERAND (node, 0);
7484 if (node && TREE_OPERAND (node, 0)
7485 && TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR)
7487 node = TREE_OPERAND (node, 0);
7488 if (TREE_OPERAND (node, 0)
7489 && TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL
7490 && (OUTER_FIELD_ACCESS_IDENTIFIER_P
7491 (DECL_NAME (TREE_OPERAND (node, 0)))))
7496 if (identified && name && arg_type && arg)
7498 tree argument = TREE_OPERAND (node, 1);
7499 *name = DECL_NAME (TREE_OPERAND (node, 0));
7500 *arg_type = TREE_TYPE (TREE_TYPE (TREE_VALUE (argument)));
7501 *arg = TREE_VALUE (argument);
7506 /* Detect in NODE an outer field read access from an inner class and
7507 transform it into a write with RHS as an argument. This function is
7508 called from the java_complete_lhs when an assignment to a LHS can
7512 outer_field_access_fix (wfl, node, rhs)
7513 tree wfl, node, rhs;
7515 tree name, arg_type, arg;
7517 if (outer_field_expanded_access_p (node, &name, &arg_type, &arg))
7519 /* At any rate, check whether we're trying to assign a value to
7521 tree accessed = (JDECL_P (node) ? node :
7522 (TREE_CODE (node) == COMPONENT_REF ?
7523 TREE_OPERAND (node, 1) : node));
7524 if (check_final_assignment (accessed, wfl))
7525 return error_mark_node;
7527 node = build_outer_field_access_expr (EXPR_WFL_LINECOL (wfl),
7528 arg_type, name, arg, rhs);
7529 return java_complete_tree (node);
7534 /* Construct the expression that calls an access method:
7535 <type>.access$<n>(<arg1> [, <arg2>]);
7537 ARG2 can be NULL and will be omitted in that case. It will denote a
7541 build_outer_field_access_expr (lc, type, access_method_name, arg1, arg2)
7543 tree type, access_method_name, arg1, arg2;
7545 tree args, cn, access;
7547 args = arg1 ? arg1 :
7548 build_wfl_node (build_current_thisn (current_class));
7549 args = build_tree_list (NULL_TREE, args);
7552 args = tree_cons (NULL_TREE, arg2, args);
7554 access = build_method_invocation (build_wfl_node (access_method_name), args);
7555 cn = build_wfl_node (DECL_NAME (TYPE_NAME (type)));
7556 return make_qualified_primary (cn, access, lc);
7560 build_new_access_id ()
7562 static int access_n_counter = 1;
7565 sprintf (buffer, "access$%d", access_n_counter++);
7566 return get_identifier (buffer);
7569 /* Create the static access functions for the outer field DECL. We define a
7571 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$) {
7575 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$,
7576 TREE_TYPE (<field>) value$) {
7577 return inst$.field = value$;
7579 We should have a usage flags on the DECL so we can lazily turn the ones
7580 we're using for code generation. FIXME.
7584 build_outer_field_access_methods (decl)
7587 tree id, args, stmt, mdecl;
7589 /* Check point, to be removed. FIXME */
7590 if (FIELD_INNER_ACCESS (decl)
7591 && TREE_CODE (FIELD_INNER_ACCESS (decl)) != IDENTIFIER_NODE)
7594 if (FIELD_INNER_ACCESS (decl))
7595 return FIELD_INNER_ACCESS (decl);
7597 push_obstacks (&permanent_obstack, &permanent_obstack);
7599 /* Create the identifier and a function named after it. */
7600 id = build_new_access_id ();
7602 /* The identifier is marked as bearing the name of a generated write
7603 access function for outer field accessed from inner classes. */
7604 OUTER_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
7606 /* Create the read access */
7607 args = build_tree_list (inst_id, build_pointer_type (DECL_CONTEXT (decl)));
7608 TREE_CHAIN (args) = end_params_node;
7609 stmt = make_qualified_primary (build_wfl_node (inst_id),
7610 build_wfl_node (DECL_NAME (decl)), 0);
7611 stmt = build_return (0, stmt);
7612 mdecl = build_outer_field_access_method (DECL_CONTEXT (decl),
7613 TREE_TYPE (decl), id, args, stmt);
7614 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
7616 /* Create the write access method */
7617 args = build_tree_list (inst_id, build_pointer_type (DECL_CONTEXT (decl)));
7618 TREE_CHAIN (args) = build_tree_list (wpv_id, TREE_TYPE (decl));
7619 TREE_CHAIN (TREE_CHAIN (args)) = end_params_node;
7620 stmt = make_qualified_primary (build_wfl_node (inst_id),
7621 build_wfl_node (DECL_NAME (decl)), 0);
7622 stmt = build_return (0, build_assignment (ASSIGN_TK, 0, stmt,
7623 build_wfl_node (wpv_id)));
7625 mdecl = build_outer_field_access_method (DECL_CONTEXT (decl),
7626 TREE_TYPE (decl), id, args, stmt);
7627 DECL_FUNCTION_ACCESS_DECL (mdecl) = decl;
7630 /* Return the access name */
7631 return FIELD_INNER_ACCESS (decl) = id;
7634 /* Build an field access method NAME. */
7637 build_outer_field_access_method (class, type, name, args, body)
7638 tree class, type, name, args, body;
7640 tree saved_current_function_decl, mdecl;
7642 /* Create the method */
7643 mdecl = create_artificial_method (class, ACC_STATIC, type, name, args);
7644 fix_method_argument_names (args, mdecl);
7645 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
7647 /* Attach the method body. */
7648 saved_current_function_decl = current_function_decl;
7649 start_artificial_method_body (mdecl);
7650 java_method_add_stmt (mdecl, body);
7651 end_artificial_method_body (mdecl);
7652 current_function_decl = saved_current_function_decl;
7658 /* This section deals with building access function necessary for
7659 certain kinds of method invocation from inner classes. */
7662 build_outer_method_access_method (decl)
7665 tree saved_current_function_decl, mdecl;
7666 tree args = NULL_TREE, call_args = NULL_TREE;
7667 tree carg, id, body, class;
7669 int parm_id_count = 0;
7671 /* Test this abort with an access to a private field */
7672 if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "access$"))
7675 /* Check the cache first */
7676 if (DECL_FUNCTION_INNER_ACCESS (decl))
7677 return DECL_FUNCTION_INNER_ACCESS (decl);
7679 class = DECL_CONTEXT (decl);
7681 /* Obtain an access identifier and mark it */
7682 id = build_new_access_id ();
7683 OUTER_FIELD_ACCESS_IDENTIFIER_P (id) = 1;
7685 push_obstacks (&permanent_obstack, &permanent_obstack);
7687 carg = TYPE_ARG_TYPES (TREE_TYPE (decl));
7688 /* Create the arguments, as much as the original */
7689 for (; carg && carg != end_params_node;
7690 carg = TREE_CHAIN (carg))
7692 sprintf (buffer, "write_parm_value$%d", parm_id_count++);
7693 args = chainon (args, build_tree_list (get_identifier (buffer),
7694 TREE_VALUE (carg)));
7696 args = chainon (args, end_params_node);
7698 /* Create the method */
7699 mdecl = create_artificial_method (class, ACC_STATIC,
7700 TREE_TYPE (TREE_TYPE (decl)), id, args);
7701 layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
7702 /* There is a potential bug here. We should be able to use
7703 fix_method_argument_names, but then arg names get mixed up and
7704 eventually a constructor will have its this$0 altered and the
7705 outer context won't be assignment properly. The test case is
7707 TYPE_ARG_TYPES (TREE_TYPE (mdecl)) = args;
7709 /* Attach the method body. */
7710 saved_current_function_decl = current_function_decl;
7711 start_artificial_method_body (mdecl);
7713 /* The actual method invocation uses the same args. When invoking a
7714 static methods that way, we don't want to skip the first
7717 if (!METHOD_STATIC (decl))
7718 carg = TREE_CHAIN (carg);
7719 for (; carg && carg != end_params_node; carg = TREE_CHAIN (carg))
7720 call_args = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (carg)),
7723 body = build_method_invocation (build_wfl_node (DECL_NAME (decl)),
7725 if (!METHOD_STATIC (decl))
7726 body = make_qualified_primary (build_wfl_node (TREE_PURPOSE (args)),
7728 if (TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
7729 body = build_return (0, body);
7730 java_method_add_stmt (mdecl,body);
7731 end_artificial_method_body (mdecl);
7732 current_function_decl = saved_current_function_decl;
7735 /* Back tag the access function so it know what it accesses */
7736 DECL_FUNCTION_ACCESS_DECL (decl) = mdecl;
7738 /* Tag the current method so it knows it has an access generated */
7739 return DECL_FUNCTION_INNER_ACCESS (decl) = mdecl;
7743 /* This section of the code deals with building expressions to access
7744 the enclosing instance of an inner class. The enclosing instance is
7745 kept in a generated field called this$<n>, with <n> being the
7746 inner class nesting level (starting from 0.) */
7748 /* Build an access to a given this$<n>, possibly by chaining access
7749 call to others. Access methods to this$<n> are build on the fly if
7753 build_access_to_thisn (from, to, lc)
7757 tree access = NULL_TREE;
7761 tree access0_wfl, cn;
7763 maybe_build_thisn_access_method (from);
7764 access0_wfl = build_wfl_node (access0_identifier_node);
7765 cn = build_wfl_node (DECL_NAME (TYPE_NAME (from)));
7766 EXPR_WFL_LINECOL (access0_wfl) = lc;
7770 access = build_current_thisn (current_class);
7771 access = build_wfl_node (access);
7773 access = build_tree_list (NULL_TREE, access);
7774 access = build_method_invocation (access0_wfl, access);
7775 access = make_qualified_primary (cn, access, lc);
7777 from = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (from)));
7782 /* Build an access function to the this$<n> local to TYPE. NULL_TREE
7783 is returned if nothing needs to be generated. Otherwise, the method
7784 generated, fully walked and a method decl is returned.
7786 NOTE: These generated methods should be declared in a class file
7787 attribute so that they can't be referred to directly. */
7790 maybe_build_thisn_access_method (type)
7793 tree mdecl, args, stmt, rtype;
7794 tree saved_current_function_decl;
7796 /* If TYPE is a top-level class, no access method is required.
7797 If there already is such an access method, bail out. */
7798 if (CLASS_ACCESS0_GENERATED_P (type) || !INNER_CLASS_TYPE_P (type))
7801 /* We generate the method. The method looks like:
7802 static <outer_of_type> access$0 (<type> inst$) { return inst$.this$<n>; }
7804 push_obstacks (&permanent_obstack, &permanent_obstack);
7805 args = build_tree_list (inst_id, build_pointer_type (type));
7806 TREE_CHAIN (args) = end_params_node;
7807 rtype = build_pointer_type (TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))));
7808 mdecl = create_artificial_method (type, ACC_STATIC, rtype,
7809 access0_identifier_node, args);
7810 fix_method_argument_names (args, mdecl);
7811 layout_class_method (type, NULL_TREE, mdecl, NULL_TREE);
7812 stmt = build_current_thisn (type);
7813 stmt = make_qualified_primary (build_wfl_node (inst_id),
7814 build_wfl_node (stmt), 0);
7815 stmt = build_return (0, stmt);
7817 saved_current_function_decl = current_function_decl;
7818 start_artificial_method_body (mdecl);
7819 java_method_add_stmt (mdecl, stmt);
7820 end_artificial_method_body (mdecl);
7821 current_function_decl = saved_current_function_decl;
7824 CLASS_ACCESS0_GENERATED_P (type) = 1;
7829 /* Craft an correctly numbered `this$<n>'string. this$0 is used for
7830 the first level of innerclassing. this$1 for the next one, etc...
7831 This function can be invoked with TYPE to NULL, available and then
7832 has to count the parser context. */
7835 build_current_thisn (type)
7838 static int saved_i = -1;
7839 static tree saved_thisn = NULL_TREE;
7847 static tree saved_type = NULL_TREE;
7848 static int saved_type_i = 0;
7850 if (type == saved_type)
7854 for (i = -1, decl = DECL_CONTEXT (TYPE_NAME (type));
7855 decl; decl = DECL_CONTEXT (decl), i++)
7863 i = list_length (GET_CPC_LIST ())-2;
7868 sprintf (buffer, "this$%d", i);
7870 saved_thisn = get_identifier (buffer);
7874 /* Return the assignement to the hidden enclosing context `this$<n>'
7875 by the second incoming parameter to the innerclass constructor. The
7876 form used is `this.this$<n> = this$<n>;'. */
7879 build_thisn_assign ()
7881 if (current_class && PURE_INNER_CLASS_TYPE_P (current_class))
7883 tree thisn = build_current_thisn (current_class);
7884 tree lhs = make_qualified_primary (build_wfl_node (this_identifier_node),
7885 build_wfl_node (thisn), 0);
7886 tree rhs = build_wfl_node (thisn);
7887 EXPR_WFL_SET_LINECOL (lhs, lineno, 0);
7888 return build_assignment (ASSIGN_TK, EXPR_WFL_LINECOL (lhs), lhs, rhs);
7894 /* This section of the code deals with constructor. */
7896 /* Craft a body for default constructor. Patch existing constructor
7897 bodies with call to super() and field initialization statements if
7901 fix_constructors (mdecl)
7904 tree body = DECL_FUNCTION_BODY (mdecl);
7905 tree thisn_assign, compound = NULL_TREE;
7906 tree class_type = DECL_CONTEXT (mdecl);
7910 /* It is an error for the compiler to generate a default
7911 constructor if the superclass doesn't have a constructor that
7912 takes no argument, or the same args for an anonymous class */
7913 if (verify_constructor_super (mdecl))
7915 tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (class_type));
7916 tree save = DECL_NAME (mdecl);
7917 const char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
7918 DECL_NAME (mdecl) = DECL_NAME (sclass_decl);
7920 (lookup_cl (TYPE_NAME (class_type)),
7921 "No constructor matching `%s' found in class `%s'",
7922 lang_printable_name (mdecl, 0), n);
7923 DECL_NAME (mdecl) = save;
7926 /* The constructor body must be crafted by hand. It's the
7927 constructor we defined when we realize we didn't have the
7928 CLASSNAME() constructor */
7929 start_artificial_method_body (mdecl);
7931 /* We don't generate a super constructor invocation if we're
7932 compiling java.lang.Object. build_super_invocation takes care
7934 compound = java_method_add_stmt (mdecl, build_super_invocation (mdecl));
7936 /* Insert the instance initializer block right here, after the
7937 super invocation. */
7938 add_instance_initializer (mdecl);
7940 /* Insert an assignment to the this$<n> hidden field, if
7942 if ((thisn_assign = build_thisn_assign ()))
7943 java_method_add_stmt (mdecl, thisn_assign);
7945 end_artificial_method_body (mdecl);
7947 /* Search for an explicit constructor invocation */
7951 tree main_block = BLOCK_EXPR_BODY (body);
7954 switch (TREE_CODE (body))
7957 found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
7961 case EXPR_WITH_FILE_LOCATION:
7962 body = TREE_OPERAND (body, 0);
7965 body = BLOCK_EXPR_BODY (body);
7971 /* The constructor is missing an invocation of super() */
7973 compound = add_stmt_to_compound (compound, NULL_TREE,
7974 build_super_invocation (mdecl));
7976 /* Insert the instance initializer block right here, after the
7977 super invocation. */
7978 add_instance_initializer (mdecl);
7980 /* Generate the assignment to this$<n>, if necessary */
7981 if ((thisn_assign = build_thisn_assign ()))
7982 compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
7984 /* Fix the constructor main block if we're adding extra stmts */
7987 compound = add_stmt_to_compound (compound, NULL_TREE,
7988 BLOCK_EXPR_BODY (main_block));
7989 BLOCK_EXPR_BODY (main_block) = compound;
7994 /* Browse constructors in the super class, searching for a constructor
7995 that doesn't take any argument. Return 0 if one is found, 1
7996 otherwise. If the current class is an anonymous inner class, look
7997 for something that has the same signature. */
8000 verify_constructor_super (mdecl)
8003 tree class = CLASSTYPE_SUPER (current_class);
8009 if (ANONYMOUS_CLASS_P (current_class))
8011 tree mdecl_arg_type;
8012 SKIP_THIS_AND_ARTIFICIAL_PARMS (mdecl_arg_type, mdecl);
8013 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
8014 if (DECL_CONSTRUCTOR_P (sdecl))
8017 for (arg_type = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
8018 arg_type != end_params_node &&
8019 mdecl_arg_type != end_params_node;
8020 arg_type = TREE_CHAIN (arg_type),
8021 mdecl_arg_type = TREE_CHAIN (mdecl_arg_type))
8022 if (TREE_VALUE (arg_type) != TREE_VALUE (mdecl_arg_type))
8025 if (arg_type == end_params_node &&
8026 mdecl_arg_type == end_params_node)
8032 for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
8034 if (DECL_CONSTRUCTOR_P (sdecl)
8035 && TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)))
8043 /* Generate code for all context remembered for code generation. */
8046 java_expand_classes ()
8048 int save_error_count = 0;
8049 static struct parser_ctxt *saved_ctxp = NULL;
8051 java_parse_abort_on_error ();
8052 if (!(ctxp = ctxp_for_generation))
8054 java_layout_classes ();
8055 java_parse_abort_on_error ();
8057 saved_ctxp = ctxp_for_generation;
8058 for (; ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
8060 ctxp = ctxp_for_generation;
8061 lang_init_source (2); /* Error msgs have method prototypes */
8062 java_complete_expand_classes (); /* Complete and expand classes */
8063 java_parse_abort_on_error ();
8066 /* Find anonymous classes and expand their constructor, now they
8068 for (ctxp_for_generation = saved_ctxp;
8069 ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
8072 ctxp = ctxp_for_generation;
8073 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
8075 current_class = TREE_TYPE (current);
8076 if (ANONYMOUS_CLASS_P (current_class))
8079 for (d = TYPE_METHODS (current_class); d; d = TREE_CHAIN (d))
8081 if (DECL_CONSTRUCTOR_P (d))
8083 restore_line_number_status (1);
8084 reset_method_name (d);
8085 java_complete_expand_method (d);
8086 restore_line_number_status (0);
8087 break; /* We now there are no other ones */
8094 /* If we've found error at that stage, don't try to generate
8095 anything, unless we're emitting xrefs or checking the syntax only
8096 (but not using -fsyntax-only for the purpose of generating
8098 if (java_error_count && !flag_emit_xref
8099 && (!flag_syntax_only && !flag_emit_class_files))
8102 /* Now things are stable, go for generation of the class data. */
8103 for (ctxp_for_generation = saved_ctxp;
8104 ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
8107 ctxp = ctxp_for_generation;
8108 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
8110 current_class = TREE_TYPE (current);
8111 outgoing_cpool = TYPE_CPOOL (current_class);
8112 if (flag_emit_class_files)
8113 write_classfile (current_class);
8115 expand_xref (current_class);
8116 else if (! flag_syntax_only)
8122 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
8123 a tree list node containing RIGHT. Fore coming RIGHTs will be
8124 chained to this hook. LOCATION contains the location of the
8125 separating `.' operator. */
8128 make_qualified_primary (primary, right, location)
8129 tree primary, right;
8134 if (TREE_CODE (primary) != EXPR_WITH_FILE_LOCATION)
8135 wfl = build_wfl_wrap (primary);
8139 /* If wfl wasn't qualified, we build a first anchor */
8140 if (!EXPR_WFL_QUALIFICATION (wfl))
8141 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (wfl, NULL_TREE);
8144 /* And chain them */
8145 EXPR_WFL_LINECOL (right) = location;
8146 chainon (EXPR_WFL_QUALIFICATION (wfl), build_tree_list (right, NULL_TREE));
8147 PRIMARY_P (wfl) = 1;
8151 /* Simple merge of two name separated by a `.' */
8154 merge_qualified_name (left, right)
8158 if (!left && !right)
8167 obstack_grow (&temporary_obstack, IDENTIFIER_POINTER (left),
8168 IDENTIFIER_LENGTH (left));
8169 obstack_1grow (&temporary_obstack, '.');
8170 obstack_grow0 (&temporary_obstack, IDENTIFIER_POINTER (right),
8171 IDENTIFIER_LENGTH (right));
8172 node = get_identifier (obstack_base (&temporary_obstack));
8173 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
8174 QUALIFIED_P (node) = 1;
8178 /* Merge the two parts of a qualified name into LEFT. Set the
8179 location information of the resulting node to LOCATION, usually
8180 inherited from the location information of the `.' operator. */
8183 make_qualified_name (left, right, location)
8187 #ifdef USE_COMPONENT_REF
8188 tree node = build (COMPONENT_REF, NULL_TREE, left, right);
8189 EXPR_WFL_LINECOL (node) = location;
8192 tree left_id = EXPR_WFL_NODE (left);
8193 tree right_id = EXPR_WFL_NODE (right);
8196 merge = merge_qualified_name (left_id, right_id);
8198 /* Left wasn't qualified and is now qualified */
8199 if (!QUALIFIED_P (left_id))
8201 tree wfl = build_expr_wfl (left_id, ctxp->filename, 0, 0);
8202 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (left);
8203 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
8206 wfl = build_expr_wfl (right_id, ctxp->filename, 0, 0);
8207 EXPR_WFL_LINECOL (wfl) = location;
8208 chainon (EXPR_WFL_QUALIFICATION (left), build_tree_list (wfl, NULL_TREE));
8210 EXPR_WFL_NODE (left) = merge;
8215 /* Extract the last identifier component of the qualified in WFL. The
8216 last identifier is removed from the linked list */
8219 cut_identifier_in_qualified (wfl)
8223 tree previous = NULL_TREE;
8224 for (q = EXPR_WFL_QUALIFICATION (wfl); ; previous = q, q = TREE_CHAIN (q))
8225 if (!TREE_CHAIN (q))
8228 fatal ("Operating on a non qualified qualified WFL - cut_identifier_in_qualified");
8229 TREE_CHAIN (previous) = NULL_TREE;
8230 return TREE_PURPOSE (q);
8234 /* Resolve the expression name NAME. Return its decl. */
8237 resolve_expression_name (id, orig)
8241 tree name = EXPR_WFL_NODE (id);
8244 /* 6.5.5.1: Simple expression names */
8245 if (!PRIMARY_P (id) && !QUALIFIED_P (name))
8247 /* 15.13.1: NAME can appear within the scope of a local variable
8249 if ((decl = IDENTIFIER_LOCAL_VALUE (name)))
8252 /* 15.13.1: NAME can appear within a class declaration */
8255 decl = lookup_field_wrapper (current_class, name);
8257 /* Last chance: if we're within the context of an inner
8258 class, we might be trying to access a local variable
8259 defined in an outer context. We try to look for it
8261 if (!decl && INNER_CLASS_TYPE_P (current_class))
8264 MANGLE_OUTER_LOCAL_VARIABLE_NAME (alias_buffer, name);
8265 name = get_identifier (alias_buffer);
8266 decl = lookup_field_wrapper (current_class, name);
8268 FIELD_LOCAL_ALIAS_USED (decl) = 1;
8273 tree access = NULL_TREE;
8274 int fs = FIELD_STATIC (decl);
8275 /* Instance variable (8.3.1.1) can't appear within
8276 static method, static initializer or initializer for
8277 a static variable. */
8278 if (!fs && METHOD_STATIC (current_function_decl))
8280 static_ref_err (id, name, current_class);
8281 return error_mark_node;
8283 /* Instance variables can't appear as an argument of
8284 an explicit constructor invocation */
8285 if (!fs && ctxp->explicit_constructor_p)
8288 (id, "Can't reference `%s' before the superclass constructor has been called", IDENTIFIER_POINTER (name));
8289 return error_mark_node;
8292 /* If we're processing an inner class and we're trying
8293 to access a field belonging to an outer class, build
8294 the access to the field */
8295 if (!fs && outer_field_access_p (current_class, decl))
8296 return build_outer_field_access (id, decl);
8298 /* Otherwise build what it takes to access the field */
8299 access = build_field_ref ((fs ? NULL_TREE : current_this),
8300 DECL_CONTEXT (decl), name);
8301 if (fs && !flag_emit_class_files && !flag_emit_xref)
8302 access = build_class_init (DECL_CONTEXT (access), access);
8303 /* We may be asked to save the real field access node */
8306 /* And we return what we got */
8309 /* Fall down to error report on undefined variable */
8312 /* 6.5.5.2 Qualified Expression Names */
8317 qualify_ambiguous_name (id);
8318 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
8319 /* 15.10.2: Accessing Superclass Members using super */
8320 return resolve_field_access (id, orig, NULL);
8323 /* We've got an error here */
8324 parse_error_context (id, "Undefined variable `%s'",
8325 IDENTIFIER_POINTER (name));
8327 return error_mark_node;
8331 static_ref_err (wfl, field_id, class_type)
8332 tree wfl, field_id, class_type;
8336 "Can't make a static reference to nonstatic variable `%s' in class `%s'",
8337 IDENTIFIER_POINTER (field_id),
8338 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class_type))));
8341 /* 15.10.1 Field Acess Using a Primary and/or Expression Name.
8342 We return something suitable to generate the field access. We also
8343 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
8344 recipient's address can be null. */
8347 resolve_field_access (qual_wfl, field_decl, field_type)
8349 tree *field_decl, *field_type;
8353 tree decl, where_found, type_found;
8355 if (resolve_qualified_expression_name (qual_wfl, &decl,
8356 &where_found, &type_found))
8357 return error_mark_node;
8359 /* Resolve the LENGTH field of an array here */
8360 if (DECL_NAME (decl) == length_identifier_node && TYPE_ARRAY_P (type_found)
8361 && ! flag_emit_class_files && ! flag_emit_xref)
8363 tree length = build_java_array_length_access (where_found);
8365 build_java_arraynull_check (type_found, length, int_type_node);
8367 /* We might have been trying to resolve field.method(). In which
8368 case, the resolution is over and decl is the answer */
8369 else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
8371 else if (JDECL_P (decl))
8373 int static_final_found = 0;
8375 type_found = DECL_CONTEXT (decl);
8376 is_static = JDECL_P (decl) && FIELD_STATIC (decl);
8377 if (FIELD_FINAL (decl)
8378 && JPRIMITIVE_TYPE_P (TREE_TYPE (decl))
8379 && DECL_LANG_SPECIFIC (decl)
8380 && DECL_INITIAL (decl))
8382 field_ref = DECL_INITIAL (decl);
8383 static_final_found = 1;
8386 field_ref = build_field_ref ((is_static && !flag_emit_xref?
8387 NULL_TREE : where_found),
8388 type_found, DECL_NAME (decl));
8389 if (field_ref == error_mark_node)
8390 return error_mark_node;
8391 if (is_static && !static_final_found
8392 && !flag_emit_class_files && !flag_emit_xref)
8393 field_ref = build_class_init (type_found, field_ref);
8401 *field_type = (QUAL_DECL_TYPE (decl) ?
8402 QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
8406 /* If NODE is an access to f static field, strip out the class
8407 initialization part and return the field decl, otherwise, return
8411 strip_out_static_field_access_decl (node)
8414 if (TREE_CODE (node) == COMPOUND_EXPR)
8416 tree op1 = TREE_OPERAND (node, 1);
8417 if (TREE_CODE (op1) == COMPOUND_EXPR)
8419 tree call = TREE_OPERAND (op1, 0);
8420 if (TREE_CODE (call) == CALL_EXPR
8421 && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
8422 && TREE_OPERAND (TREE_OPERAND (call, 0), 0)
8423 == soft_initclass_node)
8424 return TREE_OPERAND (op1, 1);
8426 else if (JDECL_P (op1))
8432 /* 6.5.5.2: Qualified Expression Names */
8435 resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
8437 tree *found_decl, *type_found, *where_found;
8439 int from_type = 0; /* Field search initiated from a type */
8440 int from_super = 0, from_cast = 0, from_qualified_this = 0;
8441 int previous_call_static = 0;
8443 tree decl = NULL_TREE, type = NULL_TREE, q;
8444 /* For certain for of inner class instantiation */
8445 tree saved_current, saved_this;
8446 #define RESTORE_THIS_AND_CURRENT_CLASS \
8447 { current_class = saved_current; current_this = saved_this;}
8449 *type_found = *where_found = NULL_TREE;
8451 for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
8453 tree qual_wfl = QUAL_WFL (q);
8454 tree ret_decl; /* for EH checking */
8455 int location; /* for EH checking */
8457 /* 15.10.1 Field Access Using a Primary */
8458 switch (TREE_CODE (qual_wfl))
8461 case NEW_CLASS_EXPR:
8462 /* If the access to the function call is a non static field,
8463 build the code to access it. */
8464 if (JDECL_P (decl) && !FIELD_STATIC (decl))
8466 decl = maybe_access_field (decl, *where_found,
8467 DECL_CONTEXT (decl));
8468 if (decl == error_mark_node)
8472 /* And code for the function call */
8473 if (complete_function_arguments (qual_wfl))
8476 /* We might have to setup a new current class and a new this
8477 for the search of an inner class, relative to the type of
8478 a expression resolved as `decl'. The current values are
8479 saved and restored shortly after */
8480 saved_current = current_class;
8481 saved_this = current_this;
8482 if (decl && TREE_CODE (qual_wfl) == NEW_CLASS_EXPR)
8484 current_class = type;
8485 current_this = decl;
8488 if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
8489 CALL_USING_SUPER (qual_wfl) = 1;
8490 location = (TREE_CODE (qual_wfl) == CALL_EXPR ?
8491 EXPR_WFL_LINECOL (TREE_OPERAND (qual_wfl, 0)) : 0);
8492 *where_found = patch_method_invocation (qual_wfl, decl, type,
8493 &is_static, &ret_decl);
8494 if (*where_found == error_mark_node)
8496 RESTORE_THIS_AND_CURRENT_CLASS;
8499 *type_found = type = QUAL_DECL_TYPE (*where_found);
8501 /* If we're creating an inner class instance, check for that
8502 an enclosing instance is in scope */
8503 if (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR
8504 && INNER_CLASS_TYPE_P (type) && current_this
8505 && (DECL_CONTEXT (TYPE_NAME (type))
8506 != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this)))))
8509 (qual_wfl, "No enclosing instance for inner class `%s' is in scope; an explicit one must be provided when creating this inner class",
8510 lang_printable_name (type, 0));
8511 RESTORE_THIS_AND_CURRENT_CLASS;
8515 /* In case we had to change then to resolve a inner class
8516 instantiation using a primary qualified by a `new' */
8517 RESTORE_THIS_AND_CURRENT_CLASS;
8521 check_thrown_exceptions (location, ret_decl);
8523 /* If the previous call was static and this one is too,
8524 build a compound expression to hold the two (because in
8525 that case, previous function calls aren't transported as
8526 forcoming function's argument. */
8527 if (previous_call_static && is_static)
8529 decl = build (COMPOUND_EXPR, type, decl, *where_found);
8530 TREE_SIDE_EFFECTS (decl) = 1;
8534 previous_call_static = is_static;
8535 decl = *where_found;
8540 case NEW_ARRAY_EXPR:
8541 case NEW_ANONYMOUS_ARRAY_EXPR:
8542 *where_found = decl = java_complete_tree (qual_wfl);
8543 if (decl == error_mark_node)
8545 *type_found = type = QUAL_DECL_TYPE (decl);
8546 CLASS_LOADED_P (type) = 1;
8550 *where_found = decl = java_complete_tree (qual_wfl);
8551 if (decl == error_mark_node)
8553 *type_found = type = QUAL_DECL_TYPE (decl);
8557 case CONDITIONAL_EXPR:
8560 *where_found = decl = java_complete_tree (qual_wfl);
8561 if (decl == error_mark_node)
8563 *type_found = type = QUAL_DECL_TYPE (decl);
8567 /* If the access to the function call is a non static field,
8568 build the code to access it. */
8569 if (JDECL_P (decl) && !FIELD_STATIC (decl))
8571 decl = maybe_access_field (decl, *where_found, type);
8572 if (decl == error_mark_node)
8575 /* And code for the array reference expression */
8576 decl = java_complete_tree (qual_wfl);
8577 if (decl == error_mark_node)
8579 type = QUAL_DECL_TYPE (decl);
8583 if ((decl = java_complete_tree (qual_wfl)) == error_mark_node)
8585 if ((type = patch_string (decl)))
8587 *where_found = QUAL_RESOLUTION (q) = decl;
8588 *type_found = type = TREE_TYPE (decl);
8592 /* Fix for -Wall Just go to the next statement. Don't
8597 /* If we fall here, we weren't processing a (static) function call. */
8598 previous_call_static = 0;
8600 /* It can be the keyword THIS */
8601 if (EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
8606 (wfl, "Keyword `this' used outside allowed context");
8609 if (ctxp->explicit_constructor_p)
8611 parse_error_context (wfl, "Can't reference `this' before the superclass constructor has been called");
8614 /* We have to generate code for intermediate acess */
8615 if (!from_type || TREE_TYPE (TREE_TYPE (current_this)) == type)
8617 *where_found = decl = current_this;
8618 *type_found = type = QUAL_DECL_TYPE (decl);
8620 /* We're trying to access the this from somewhere else... */
8623 *where_found = decl = build_current_thisn (type);
8624 from_qualified_this = 1;
8631 /* 15.10.2 Accessing Superclass Members using SUPER */
8632 if (EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
8635 /* Check on the restricted use of SUPER */
8636 if (METHOD_STATIC (current_function_decl)
8637 || current_class == object_type_node)
8640 (wfl, "Keyword `super' used outside allowed context");
8643 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
8644 node = build_cast (EXPR_WFL_LINECOL (qual_wfl),
8645 CLASSTYPE_SUPER (current_class),
8646 build_this (EXPR_WFL_LINECOL (qual_wfl)));
8647 *where_found = decl = java_complete_tree (node);
8648 if (decl == error_mark_node)
8650 *type_found = type = QUAL_DECL_TYPE (decl);
8651 from_super = from_type = 1;
8655 /* 15.13.1: Can't search for field name in packages, so we
8656 assume a variable/class name was meant. */
8657 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
8659 tree name = resolve_package (wfl, &q);
8663 *where_found = decl = resolve_no_layout (name, qual_wfl);
8664 /* We wan't to be absolutely that the class is laid
8665 out. We're going to search something inside it. */
8666 *type_found = type = TREE_TYPE (decl);
8667 layout_class (type);
8669 /* Should be a list, really. FIXME */
8670 /* Fix them all the way down */
8672 list = TREE_CHAIN (q);
8675 RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (list)) = 1;
8676 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (list)) = 0;
8677 list = TREE_CHAIN (list);
8682 if (from_super || from_cast)
8684 ((from_cast ? qual_wfl : wfl),
8685 "No variable `%s' defined in class `%s'",
8686 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
8687 lang_printable_name (type, 0));
8690 (qual_wfl, "Undefined variable or class name: `%s'",
8691 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)));
8696 /* We have a type name. It's been already resolved when the
8697 expression was qualified. */
8698 else if (RESOLVE_TYPE_NAME_P (qual_wfl))
8700 if (!(decl = QUAL_RESOLUTION (q)))
8701 return 1; /* Error reported already */
8703 /* Sneak preview. If next we see a `new', we're facing a
8704 qualification with resulted in a type being selected
8705 instead of a field. Report the error */
8707 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR)
8709 parse_error_context (qual_wfl, "Undefined variable `%s'",
8710 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
8714 if (not_accessible_p (TREE_TYPE (decl), decl, 0))
8717 (qual_wfl, "Can't access %s field `%s.%s' from `%s'",
8718 java_accstring_lookup (get_access_flags_from_decl (decl)),
8719 GET_TYPE_NAME (type),
8720 IDENTIFIER_POINTER (DECL_NAME (decl)),
8721 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
8724 check_deprecation (qual_wfl, decl);
8726 type = TREE_TYPE (decl);
8729 /* We resolve and expression name */
8732 tree field_decl = NULL_TREE;
8734 /* If there exists an early resolution, use it. That occurs
8735 only once and we know that there are more things to
8736 come. Don't do that when processing something after SUPER
8737 (we need more thing to be put in place below */
8738 if (!from_super && QUAL_RESOLUTION (q))
8740 decl = QUAL_RESOLUTION (q);
8743 if (TREE_CODE (decl) == FIELD_DECL && !FIELD_STATIC (decl))
8746 *where_found = current_this;
8749 static_ref_err (qual_wfl, DECL_NAME (decl),
8756 *where_found = TREE_TYPE (decl);
8757 if (TREE_CODE (*where_found) == POINTER_TYPE)
8758 *where_found = TREE_TYPE (*where_found);
8763 /* We have to search for a field, knowing the type of its
8764 container. The flag FROM_TYPE indicates that we resolved
8765 the last member of the expression as a type name, which
8766 means that for the resolution of this field, we'll look
8767 for other errors than if it was resolved as a member of
8772 tree field_decl_type; /* For layout */
8774 if (!from_type && !JREFERENCE_TYPE_P (type))
8777 (qual_wfl, "Attempt to reference field `%s' in `%s %s'",
8778 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
8779 lang_printable_name (type, 0),
8780 IDENTIFIER_POINTER (DECL_NAME (field_decl)));
8784 field_decl = lookup_field_wrapper (type,
8785 EXPR_WFL_NODE (qual_wfl));
8786 if (field_decl == NULL_TREE)
8789 (qual_wfl, "No variable `%s' defined in type `%s'",
8790 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
8791 GET_TYPE_NAME (type));
8794 if (field_decl == error_mark_node)
8797 /* Layout the type of field_decl, since we may need
8798 it. Don't do primitive types or loaded classes. The
8799 situation of non primitive arrays may not handled
8800 properly here. FIXME */
8801 if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
8802 field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
8804 field_decl_type = TREE_TYPE (field_decl);
8805 if (!JPRIMITIVE_TYPE_P (field_decl_type)
8806 && !CLASS_LOADED_P (field_decl_type)
8807 && !TYPE_ARRAY_P (field_decl_type))
8808 resolve_and_layout (field_decl_type, NULL_TREE);
8809 if (TYPE_ARRAY_P (field_decl_type))
8810 CLASS_LOADED_P (field_decl_type) = 1;
8812 /* Check on accessibility here */
8813 if (not_accessible_p (type, field_decl, from_super))
8817 "Can't access %s field `%s.%s' from `%s'",
8818 java_accstring_lookup
8819 (get_access_flags_from_decl (field_decl)),
8820 GET_TYPE_NAME (type),
8821 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
8823 (DECL_NAME (TYPE_NAME (current_class))));
8826 check_deprecation (qual_wfl, field_decl);
8828 /* There are things to check when fields are accessed
8829 from type. There are no restrictions on a static
8830 declaration of the field when it is accessed from an
8832 is_static = FIELD_STATIC (field_decl);
8833 if (!from_super && from_type
8834 && !TYPE_INTERFACE_P (type)
8836 && (current_function_decl
8837 && METHOD_STATIC (current_function_decl)))
8839 static_ref_err (qual_wfl, EXPR_WFL_NODE (qual_wfl), type);
8842 from_cast = from_super = 0;
8844 /* It's an access from a type but it isn't static, we
8845 make it relative to `this'. */
8846 if (!is_static && from_type)
8847 decl = current_this;
8849 /* If we need to generate something to get a proper
8850 handle on what this field is accessed from, do it
8854 decl = maybe_access_field (decl, *where_found, *type_found);
8855 if (decl == error_mark_node)
8859 /* We want to keep the location were found it, and the type
8861 *where_found = decl;
8864 /* Generate the correct expression for field access from
8866 if (from_qualified_this)
8868 field_decl = build_outer_field_access (qual_wfl, field_decl);
8869 from_qualified_this = 0;
8872 /* This is the decl found and eventually the next one to
8877 type = QUAL_DECL_TYPE (decl);
8879 /* Sneak preview. If decl is qualified by a `new', report
8880 the error here to be accurate on the peculiar construct */
8882 && TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR
8883 && !JREFERENCE_TYPE_P (type))
8885 parse_error_context (qual_wfl, "Attempt to reference field `new' in a `%s'",
8886 lang_printable_name (type, 0));
8895 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
8896 can't be accessed from REFERENCE (a record type). */
8899 not_accessible_p (reference, member, from_super)
8900 tree reference, member;
8903 int access_flag = get_access_flags_from_decl (member);
8905 /* Access always granted for members declared public */
8906 if (access_flag & ACC_PUBLIC)
8909 /* Check access on protected members */
8910 if (access_flag & ACC_PROTECTED)
8912 /* Access granted if it occurs from within the package
8913 containing the class in which the protected member is
8915 if (class_in_current_package (DECL_CONTEXT (member)))
8918 /* If accessed with the form `super.member', then access is granted */
8922 /* Otherwise, access is granted if occuring from the class where
8923 member is declared or a subclass of it */
8924 if (inherits_from_p (reference, current_class))
8929 /* Check access on private members. Access is granted only if it
8930 occurs from within the class in witch it is declared. Exceptions
8931 are access from inner-classes. This section is probably not
8933 if (access_flag & ACC_PRIVATE)
8934 return (current_class == DECL_CONTEXT (member) ? 0 :
8935 (INNER_CLASS_TYPE_P (current_class) ? 0 : 1));
8937 /* Default access are permitted only when occuring within the
8938 package in which the type (REFERENCE) is declared. In other words,
8939 REFERENCE is defined in the current package */
8941 return !class_in_current_package (reference);
8943 /* Otherwise, access is granted */
8947 /* Test deprecated decl access. */
8949 check_deprecation (wfl, decl)
8952 const char *file = DECL_SOURCE_FILE (decl);
8953 /* Complain if the field is deprecated and the file it was defined
8954 in isn't compiled at the same time the file which contains its
8956 if (DECL_DEPRECATED (decl)
8957 && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
8960 switch (TREE_CODE (decl))
8963 strcpy (the, "method");
8966 strcpy (the, "field");
8969 strcpy (the, "class");
8972 fatal ("unexpected DECL code - check_deprecation");
8974 parse_warning_context
8975 (wfl, "The %s `%s' in class `%s' has been deprecated",
8976 the, lang_printable_name (decl, 0),
8977 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
8981 /* Returns 1 if class was declared in the current package, 0 otherwise */
8984 class_in_current_package (class)
8987 static tree cache = NULL_TREE;
8994 qualified_flag = QUALIFIED_P (DECL_NAME (TYPE_NAME (class)));
8996 /* If the current package is empty and the name of CLASS is
8997 qualified, class isn't in the current package. If there is a
8998 current package and the name of the CLASS is not qualified, class
8999 isn't in the current package */
9000 if ((!ctxp->package && qualified_flag) || (ctxp->package && !qualified_flag))
9003 /* If there is not package and the name of CLASS isn't qualified,
9004 they belong to the same unnamed package */
9005 if (!ctxp->package && !qualified_flag)
9008 /* Compare the left part of the name of CLASS with the package name */
9009 breakdown_qualified (&left, NULL, DECL_NAME (TYPE_NAME (class)));
9010 if (ctxp->package == left)
9018 /* This function may generate code to access DECL from WHERE. This is
9019 done only if certain conditions meet. */
9022 maybe_access_field (decl, where, type)
9023 tree decl, where, type;
9025 if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
9026 && !FIELD_STATIC (decl))
9027 decl = build_field_ref (where ? where : current_this,
9028 (type ? type : DECL_CONTEXT (decl)),
9033 /* Build a method invocation, by patching PATCH. If non NULL
9034 and according to the situation, PRIMARY and WHERE may be
9035 used. IS_STATIC is set to 1 if the invoked function is static. */
9038 patch_method_invocation (patch, primary, where, is_static, ret_decl)
9039 tree patch, primary, where;
9043 tree wfl = TREE_OPERAND (patch, 0);
9044 tree args = TREE_OPERAND (patch, 1);
9045 tree name = EXPR_WFL_NODE (wfl);
9047 int is_static_flag = 0;
9048 int is_super_init = 0;
9049 tree this_arg = NULL_TREE;
9051 /* Should be overriden if everything goes well. Otherwise, if
9052 something fails, it should keep this value. It stop the
9053 evaluation of a bogus assignment. See java_complete_tree,
9054 MODIFY_EXPR: for the reasons why we sometimes want to keep on
9055 evaluating an assignment */
9056 TREE_TYPE (patch) = error_mark_node;
9058 /* Since lookup functions are messing with line numbers, save the
9060 java_parser_context_save_global ();
9062 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
9064 /* Resolution of qualified name, excluding constructors */
9065 if (QUALIFIED_P (name) && !CALL_CONSTRUCTOR_P (patch))
9067 tree class_decl, identifier, identifier_wfl;
9068 /* Extract the last IDENTIFIER of the qualified
9069 expression. This is a wfl and we will use it's location
9070 data during error report. */
9071 identifier_wfl = cut_identifier_in_qualified (wfl);
9072 identifier = EXPR_WFL_NODE (identifier_wfl);
9074 /* Given the context, IDENTIFIER is syntactically qualified
9075 as a MethodName. We need to qualify what's before */
9076 qualify_ambiguous_name (wfl);
9078 /* Package resolution */
9079 if (RESOLVE_PACKAGE_NAME_P (wfl))
9081 tree next, decl, name = resolve_package (wfl, &next);
9086 breakdown_qualified (&remainder, NULL, EXPR_WFL_NODE (wfl));
9088 (wfl, "Can't search method `%s' in package `%s'",
9089 IDENTIFIER_POINTER (identifier),
9090 IDENTIFIER_POINTER (remainder));
9091 PATCH_METHOD_RETURN_ERROR ();
9093 RESOLVE_PACKAGE_NAME_P (wfl) = 0;
9094 if ((decl = resolve_no_layout (name, QUAL_WFL (next))))
9096 QUAL_RESOLUTION (EXPR_WFL_QUALIFICATION (wfl)) = decl;
9097 RESOLVE_EXPRESSION_NAME_P (wfl) = 0;
9098 RESOLVE_TYPE_NAME_P (wfl) = 1;
9102 RESOLVE_EXPRESSION_NAME_P (wfl) = 1;
9103 RESOLVE_TYPE_NAME_P (wfl) = 0;
9107 /* We're resolving a call from a type */
9108 if (RESOLVE_TYPE_NAME_P (wfl))
9110 tree decl = QUAL_RESOLUTION (EXPR_WFL_QUALIFICATION (wfl));
9111 tree name = DECL_NAME (decl);
9114 class_decl = resolve_and_layout (name, wfl);
9115 if (CLASS_INTERFACE (decl))
9119 "Can't make static reference to method `%s' in interface `%s'",
9120 IDENTIFIER_POINTER (identifier),
9121 IDENTIFIER_POINTER (name));
9122 PATCH_METHOD_RETURN_ERROR ();
9124 /* Look the method up in the type selector. The method ought
9126 type = TREE_TYPE (class_decl);
9127 list = lookup_method_invoke (0, wfl, type, identifier, args);
9128 if (list && !METHOD_STATIC (list))
9130 char *fct_name = xstrdup (lang_printable_name (list, 0));
9133 "Can't make static reference to method `%s %s' in class `%s'",
9134 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
9135 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
9137 PATCH_METHOD_RETURN_ERROR ();
9139 args = nreverse (args);
9141 /* We're resolving an expression name */
9146 /* 1- Find the field to which the call applies */
9147 field = resolve_field_access (wfl, NULL, &type);
9148 if (field == error_mark_node)
9149 PATCH_METHOD_RETURN_ERROR ();
9150 /* field is used in lieu of a primary. It alows us not to
9151 report errors on erroneous use of `this' in
9155 /* 2- Do the layout of the class where the last field
9156 was found, so we can search it. */
9157 class_decl = resolve_and_layout (type, NULL_TREE);
9158 if (class_decl != NULL_TREE)
9159 type = TREE_TYPE (class_decl);
9161 /* 3- Retrieve a filtered list of method matches, Refine
9162 if necessary. In any cases, point out errors. */
9163 list = lookup_method_invoke (0, identifier_wfl, type,
9166 /* 4- Add the field as an argument */
9167 args = nreverse (args);
9171 /* IDENTIFIER_WFL will be used to report any problem further */
9172 wfl = identifier_wfl;
9174 /* Resolution of simple names, names generated after a primary: or
9178 tree class_to_search = NULL_TREE;
9179 int lc; /* Looking for Constructor */
9181 /* We search constructor in their target class */
9182 if (CALL_CONSTRUCTOR_P (patch))
9184 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
9185 class_to_search = EXPR_WFL_NODE (wfl);
9186 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
9187 this_identifier_node)
9188 class_to_search = NULL_TREE;
9189 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
9190 super_identifier_node)
9193 if (CLASSTYPE_SUPER (current_class))
9195 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
9198 parse_error_context (wfl, "Can't invoke super constructor on java.lang.Object");
9199 PATCH_METHOD_RETURN_ERROR ();
9203 /* Class to search is NULL if we're searching the current one */
9204 if (class_to_search)
9206 class_to_search = resolve_and_layout (class_to_search, wfl);
9208 if (!class_to_search)
9211 (wfl, "Class `%s' not found in type declaration",
9212 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
9213 PATCH_METHOD_RETURN_ERROR ();
9216 /* Can't instantiate an abstract class, but we can
9217 invoke it's constructor. It's use within the `new'
9218 context is denied here. */
9219 if (CLASS_ABSTRACT (class_to_search)
9220 && TREE_CODE (patch) == NEW_CLASS_EXPR)
9223 (wfl, "Class `%s' is an abstract class. It can't be instantiated",
9224 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
9225 PATCH_METHOD_RETURN_ERROR ();
9228 class_to_search = TREE_TYPE (class_to_search);
9231 class_to_search = current_class;
9234 /* This is a regular search in the local class, unless an
9235 alternate class is specified. */
9238 class_to_search = (where ? where : current_class);
9242 /* NAME is a simple identifier or comes from a primary. Search
9243 in the class whose declaration contain the method being
9245 resolve_and_layout (class_to_search, NULL_TREE);
9247 list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
9248 /* Don't continue if no method were found, as the next statement
9249 can't be executed then. */
9251 PATCH_METHOD_RETURN_ERROR ();
9253 /* Check for static reference if non static methods */
9254 if (check_for_static_method_reference (wfl, patch, list,
9255 class_to_search, primary))
9256 PATCH_METHOD_RETURN_ERROR ();
9258 /* Non static methods are called with the current object extra
9259 argument. If patch a `new TYPE()', the argument is the value
9260 returned by the object allocator. If method is resolved as a
9261 primary, use the primary otherwise use the current THIS. */
9262 args = nreverse (args);
9263 if (TREE_CODE (patch) != NEW_CLASS_EXPR)
9265 this_arg = primary ? primary : current_this;
9267 /* If we're using an access method, things are different.
9268 There are two familly of cases:
9270 1) We're not generating bytecodes:
9272 - LIST is non static. It's invocation is transformed from
9273 x(a1,...,an) into this$<n>.x(a1,....an).
9274 - LIST is static. It's invocation is transformed from
9275 x(a1,...,an) into TYPE_OF(this$<n>).x(a1,....an)
9277 2) We're generating bytecodes:
9279 - LIST is non static. It's invocation is transformed from
9280 x(a1,....,an) into access$<n>(this$<n>,a1,...,an).
9281 - LIST is static. It's invocation is transformed from
9282 x(a1,....,an) into TYPEOF(this$<n>).x(a1,....an).
9284 Of course, this$<n> can be abitrary complex, ranging from
9285 this$0 (the immediate outer context) to
9286 access$0(access$0(...(this$0))).
9288 maybe_use_access_method returns a non zero value if the
9289 this_arg has to be deplaced into the (then generated)
9290 stub argument list. In the mean time, the selected
9291 function might have be replaced by a generated stub. */
9292 if (maybe_use_access_method (is_super_init, &list, &this_arg))
9293 args = tree_cons (NULL_TREE, this_arg, args);
9297 /* Merge point of all resolution schemes. If we have nothing, this
9298 is an error, already signaled */
9300 PATCH_METHOD_RETURN_ERROR ();
9302 /* Check accessibility, position the is_static flag, build and
9304 if (not_accessible_p (DECL_CONTEXT (current_function_decl), list, 0))
9306 char *fct_name = xstrdup (lang_printable_name (list, 0));
9308 (wfl, "Can't access %s method `%s %s.%s' from `%s'",
9309 java_accstring_lookup (get_access_flags_from_decl (list)),
9310 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
9311 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list)))),
9312 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
9314 PATCH_METHOD_RETURN_ERROR ();
9316 check_deprecation (wfl, list);
9318 /* If invoking a innerclass constructor, there are hidden parameters
9320 if (TREE_CODE (patch) == NEW_CLASS_EXPR
9321 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
9323 /* And make sure we add the accessed local variables to be saved
9324 in field aliases. */
9325 args = build_alias_initializer_parameter_list
9326 (AIPL_FUNCTION_CTOR_INVOCATION, DECL_CONTEXT (list), args, NULL);
9328 /* We have to reverse things. Find out why. FIXME */
9329 if (ANONYMOUS_CLASS_P (DECL_CONTEXT (list)))
9330 args = nreverse (args);
9332 /* Secretely pass the current_this/primary as a second argument */
9333 args = tree_cons (NULL_TREE, (primary ? primary : current_this), args);
9336 is_static_flag = METHOD_STATIC (list);
9337 if (! METHOD_STATIC (list) && this_arg != NULL_TREE)
9338 args = tree_cons (NULL_TREE, this_arg, args);
9340 /* In the context of an explicit constructor invocation, we can't
9341 invoke any method relying on `this'. Exceptions are: we're
9342 invoking a static function, primary exists and is not the current
9343 this, we're creating a new object. */
9344 if (ctxp->explicit_constructor_p
9346 && (!primary || primary == current_this)
9347 && (TREE_CODE (patch) != NEW_CLASS_EXPR))
9349 parse_error_context (wfl, "Can't reference `this' before the superclass constructor has been called");
9350 PATCH_METHOD_RETURN_ERROR ();
9352 java_parser_context_restore_global ();
9354 *is_static = is_static_flag;
9355 /* Sometimes, we want the decl of the selected method. Such as for
9359 patch = patch_invoke (patch, list, args);
9360 if (is_super_init && CLASS_HAS_FINIT_P (current_class))
9362 tree finit_parms, finit_call;
9364 /* Prepare to pass hidden parameters to $finit$, if any. */
9365 finit_parms = build_alias_initializer_parameter_list
9366 (AIPL_FUNCTION_FINIT_INVOCATION, current_class, NULL_TREE, NULL);
9369 build_method_invocation (build_wfl_node (finit_identifier_node),
9372 /* Generate the code used to initialize fields declared with an
9373 initialization statement and build a compound statement along
9374 with the super constructor invocation. */
9375 patch = build (COMPOUND_EXPR, void_type_node, patch,
9376 java_complete_tree (finit_call));
9377 CAN_COMPLETE_NORMALLY (patch) = 1;
9382 /* Check that we're not trying to do a static reference to a method in
9383 non static method. Return 1 if it's the case, 0 otherwise. */
9386 check_for_static_method_reference (wfl, node, method, where, primary)
9387 tree wfl, node, method, where, primary;
9389 if (METHOD_STATIC (current_function_decl)
9390 && !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
9392 char *fct_name = xstrdup (lang_printable_name (method, 0));
9394 (wfl, "Can't make static reference to method `%s %s' in class `%s'",
9395 lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
9396 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (where))));
9403 /* Fix the invocation of *MDECL if necessary in the case of a
9404 invocation from an inner class. *THIS_ARG might be modified
9405 appropriately and an alternative access to *MDECL might be
9409 maybe_use_access_method (is_super_init, mdecl, this_arg)
9411 tree *mdecl, *this_arg;
9414 tree md = *mdecl, ta = *this_arg;
9416 int non_static_context = !METHOD_STATIC (md);
9419 || !INNER_CLASS_TYPE_P (current_class) || DECL_FINIT_P (md))
9422 /* If we're calling a method found in an enclosing class, generate
9423 what it takes to retrieve the right this. Don't do that if we're
9424 invoking a static method. */
9426 if (non_static_context)
9428 ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
9429 if (ctx == DECL_CONTEXT (md))
9431 ta = build_current_thisn (current_class);
9432 ta = build_wfl_node (ta);
9439 maybe_build_thisn_access_method (type);
9440 if (type == DECL_CONTEXT (md))
9442 ta = build_access_to_thisn (ctx, type, 0);
9445 type = (DECL_CONTEXT (TYPE_NAME (type)) ?
9446 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type))) : NULL_TREE);
9449 ta = java_complete_tree (ta);
9452 /* We might have to use an access method to get to MD. We can
9453 break the method access rule as far as we're not generating
9455 if (METHOD_PRIVATE (md) && flag_emit_class_files)
9457 md = build_outer_method_access_method (md);
9464 /* Returnin a non zero value indicates we were doing a non static
9465 method invokation that is now a static invocation. It will have
9466 callee displace `this' to insert it in the regular argument
9468 return (non_static_context && to_return);
9471 /* Patch an invoke expression METHOD and ARGS, based on its invocation
9475 patch_invoke (patch, method, args)
9476 tree patch, method, args;
9479 tree original_call, t, ta;
9481 /* Last step for args: convert build-in types. If we're dealing with
9482 a new TYPE() type call, the first argument to the constructor
9483 isn't found in the incomming argument list, but delivered by
9485 t = TYPE_ARG_TYPES (TREE_TYPE (method));
9486 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
9488 for (ta = args; t != end_params_node && ta;
9489 t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
9490 if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
9491 TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
9492 TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
9494 /* Resolve unresolved returned type isses */
9495 t = TREE_TYPE (TREE_TYPE (method));
9496 if (TREE_CODE (t) == POINTER_TYPE && !CLASS_LOADED_P (TREE_TYPE (t)))
9497 resolve_and_layout (TREE_TYPE (t), NULL);
9499 if (flag_emit_class_files || flag_emit_xref)
9503 tree signature = build_java_signature (TREE_TYPE (method));
9504 switch (invocation_mode (method, CALL_USING_SUPER (patch)))
9506 case INVOKE_VIRTUAL:
9507 dtable = invoke_build_dtable (0, args);
9508 func = build_invokevirtual (dtable, method);
9513 func = build_known_method_ref (method, TREE_TYPE (method),
9514 DECL_CONTEXT (method),
9518 case INVOKE_INTERFACE:
9519 dtable = invoke_build_dtable (1, args);
9520 func = build_invokeinterface (dtable, method);
9524 fatal ("internal error - unknown invocation_mode result");
9527 /* Ensure self_type is initialized, (invokestatic). FIXME */
9528 func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
9531 TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
9532 TREE_OPERAND (patch, 0) = func;
9533 TREE_OPERAND (patch, 1) = args;
9534 original_call = patch;
9536 /* We're processing a `new TYPE ()' form. New is called an its
9537 returned value is the first argument to the constructor. We build
9538 a COMPOUND_EXPR and use saved expression so that the overall NEW
9539 expression value is a pointer to a newly created and initialized
9541 if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
9543 tree class = DECL_CONTEXT (method);
9544 tree c1, saved_new, size, new;
9545 if (flag_emit_class_files || flag_emit_xref)
9547 TREE_TYPE (patch) = build_pointer_type (class);
9550 if (!TYPE_SIZE (class))
9551 safe_layout_class (class);
9552 size = size_in_bytes (class);
9553 new = build (CALL_EXPR, promote_type (class),
9554 build_address_of (alloc_object_node),
9555 tree_cons (NULL_TREE, build_class_ref (class),
9556 build_tree_list (NULL_TREE,
9557 size_in_bytes (class))),
9559 saved_new = save_expr (new);
9560 c1 = build_tree_list (NULL_TREE, saved_new);
9561 TREE_CHAIN (c1) = TREE_OPERAND (original_call, 1);
9562 TREE_OPERAND (original_call, 1) = c1;
9563 TREE_SET_CODE (original_call, CALL_EXPR);
9564 patch = build (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new);
9570 invocation_mode (method, super)
9574 int access = get_access_flags_from_decl (method);
9577 return INVOKE_SUPER;
9579 if (access & ACC_STATIC || access & ACC_FINAL || access & ACC_PRIVATE)
9580 return INVOKE_STATIC;
9582 if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
9583 return INVOKE_STATIC;
9585 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
9586 return INVOKE_INTERFACE;
9588 if (DECL_CONSTRUCTOR_P (method))
9589 return INVOKE_STATIC;
9591 return INVOKE_VIRTUAL;
9594 /* Retrieve a refined list of matching methods. It covers the step
9595 15.11.2 (Compile-Time Step 2) */
9598 lookup_method_invoke (lc, cl, class, name, arg_list)
9601 tree class, name, arg_list;
9603 tree atl = end_params_node; /* Arg Type List */
9604 tree method, signature, list, node;
9605 const char *candidates; /* Used for error report */
9608 /* Fix the arguments */
9609 for (node = arg_list; node; node = TREE_CHAIN (node))
9611 tree current_arg = TREE_TYPE (TREE_VALUE (node));
9612 /* Non primitive type may have to be resolved */
9613 if (!JPRIMITIVE_TYPE_P (current_arg))
9614 resolve_and_layout (current_arg, NULL_TREE);
9616 if (TREE_CODE (current_arg) == RECORD_TYPE)
9617 current_arg = promote_type (current_arg);
9618 atl = tree_cons (NULL_TREE, current_arg, atl);
9621 /* Presto. If we're dealing with an anonymous class and a
9622 constructor call, generate the right constructor now, since we
9623 know the arguments' types. */
9625 if (lc && ANONYMOUS_CLASS_P (class))
9626 craft_constructor (TYPE_NAME (class), atl);
9628 /* Find all candidates and then refine the list, searching for the
9629 most specific method. */
9630 list = find_applicable_accessible_methods_list (lc, class, name, atl);
9631 list = find_most_specific_methods_list (list);
9632 if (list && !TREE_CHAIN (list))
9633 return TREE_VALUE (list);
9635 /* Issue an error. List candidates if any. Candidates are listed
9636 only if accessible (non accessible methods may end-up here for
9637 the sake of a better error report). */
9642 obstack_grow (&temporary_obstack, ". Candidates are:\n", 18);
9643 for (current = list; current; current = TREE_CHAIN (current))
9645 tree cm = TREE_VALUE (current);
9647 if (!cm || not_accessible_p (class, cm, 0))
9650 (string, " `%s' in `%s'%s",
9651 get_printable_method_name (cm),
9652 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
9653 (TREE_CHAIN (current) ? "\n" : ""));
9654 obstack_grow (&temporary_obstack, string, strlen (string));
9656 obstack_1grow (&temporary_obstack, '\0');
9657 candidates = obstack_finish (&temporary_obstack);
9659 /* Issue the error message */
9660 method = make_node (FUNCTION_TYPE);
9661 TYPE_ARG_TYPES (method) = atl;
9662 signature = build_java_argument_signature (method);
9663 dup = xstrdup (lang_printable_name (class, 0));
9664 parse_error_context (cl, "Can't find %s `%s(%s)' in type `%s'%s",
9665 (lc ? "constructor" : "method"),
9666 (lc ? dup : IDENTIFIER_POINTER (name)),
9667 IDENTIFIER_POINTER (signature), dup,
9668 (candidates ? candidates : ""));
9673 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
9674 when we're looking for a constructor. */
9677 find_applicable_accessible_methods_list (lc, class, name, arglist)
9679 tree class, name, arglist;
9681 tree list = NULL_TREE, all_list = NULL_TREE;
9683 if (!CLASS_LOADED_P (class) && !CLASS_FROM_SOURCE_P (class))
9685 load_class (class, 1);
9686 safe_layout_class (class);
9689 /* Search interfaces */
9690 if (CLASS_INTERFACE (TYPE_NAME (class))
9691 || CLASS_ABSTRACT (TYPE_NAME (class)))
9693 static tree searched_interfaces = NULL_TREE;
9694 static int search_not_done = 0;
9696 tree basetype_vec = TYPE_BINFO_BASETYPES (class);
9698 /* Have we searched this interface already? */
9699 if (searched_interfaces)
9702 for (current = searched_interfaces;
9703 current; current = TREE_CHAIN (current))
9704 if (TREE_VALUE (current) == class)
9707 searched_interfaces = tree_cons (NULL_TREE, class, searched_interfaces);
9709 search_applicable_methods_list
9710 (lc, TYPE_METHODS (class), name, arglist, &list, &all_list);
9712 n = TREE_VEC_LENGTH (basetype_vec);
9713 for (i = 0; i < n; i++)
9715 tree t = BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i));
9718 /* Skip java.lang.Object (we'll search it once later.) */
9719 if (t == object_type_node)
9723 rlist = find_applicable_accessible_methods_list (lc, t, name,
9725 all_list = chainon (rlist, (list ? list : all_list));
9729 /* We're done. Reset the searched interfaces list and finally search
9731 if (!search_not_done)
9733 searched_interfaces = NULL_TREE;
9734 search_applicable_methods_list (lc, TYPE_METHODS (object_type_node),
9735 name, arglist, &list, &all_list);
9738 /* Search classes */
9741 tree saved_class = class;
9742 search_applicable_methods_list (lc, TYPE_METHODS (class),
9743 name, arglist, &list, &all_list);
9745 /* Search enclosing context of inner classes before looking
9747 while (!lc && INNER_CLASS_TYPE_P (class))
9749 class = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class)));
9750 search_applicable_methods_list (lc, TYPE_METHODS (class),
9751 name, arglist, &list, &all_list);
9754 for (class = saved_class, class = (lc ? NULL_TREE :
9755 CLASSTYPE_SUPER (class)); class;
9756 class = CLASSTYPE_SUPER (class))
9757 search_applicable_methods_list
9758 (lc, TYPE_METHODS (class), name, arglist, &list, &all_list);
9761 /* Either return the list obtained or all selected (but
9762 inaccessible) methods for better error report. */
9763 return (!list ? all_list : list);
9766 /* Effectively search for the approriate method in method */
9769 search_applicable_methods_list (lc, method, name, arglist, list, all_list)
9771 tree method, name, arglist;
9772 tree *list, *all_list;
9774 for (; method; method = TREE_CHAIN (method))
9776 /* When dealing with constructor, stop here, otherwise search
9778 if (lc && !DECL_CONSTRUCTOR_P (method))
9780 else if (!lc && (DECL_CONSTRUCTOR_P (method)
9781 || (GET_METHOD_NAME (method) != name)))
9784 if (argument_types_convertible (method, arglist))
9786 /* Retain accessible methods only */
9787 if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
9789 *list = tree_cons (NULL_TREE, method, *list);
9791 /* Also retain all selected method here */
9792 *all_list = tree_cons (NULL_TREE, method, *list);
9797 /* 15.11.2.2 Choose the Most Specific Method */
9800 find_most_specific_methods_list (list)
9804 tree current, new_list = NULL_TREE;
9805 for (current = list; current; current = TREE_CHAIN (current))
9808 DECL_SPECIFIC_COUNT (TREE_VALUE (current)) = 0;
9810 for (method = list; method; method = TREE_CHAIN (method))
9812 /* Don't test a method against itself */
9813 if (method == current)
9816 /* Compare arguments and location where method where declared */
9817 if (argument_types_convertible (TREE_VALUE (method),
9818 TREE_VALUE (current))
9819 && valid_method_invocation_conversion_p
9820 (DECL_CONTEXT (TREE_VALUE (method)),
9821 DECL_CONTEXT (TREE_VALUE (current))))
9823 int v = ++DECL_SPECIFIC_COUNT (TREE_VALUE (current));
9824 max = (v > max ? v : max);
9829 /* Review the list and select the maximally specific methods */
9830 for (current = list; current; current = TREE_CHAIN (current))
9831 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
9832 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
9834 /* If we can't find one, lower expectations and try to gather multiple
9835 maximally specific methods */
9840 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
9841 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
9849 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
9850 converted by method invocation conversion (5.3) to the type of the
9851 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
9852 to change less often than M1. */
9855 argument_types_convertible (m1, m2_or_arglist)
9856 tree m1, m2_or_arglist;
9858 static tree m2_arg_value = NULL_TREE;
9859 static tree m2_arg_cache = NULL_TREE;
9861 register tree m1_arg, m2_arg;
9863 SKIP_THIS_AND_ARTIFICIAL_PARMS (m1_arg, m1)
9865 if (m2_arg_value == m2_or_arglist)
9866 m2_arg = m2_arg_cache;
9869 /* M2_OR_ARGLIST can be a function DECL or a raw list of
9871 if (m2_or_arglist && TREE_CODE (m2_or_arglist) == FUNCTION_DECL)
9873 m2_arg = TYPE_ARG_TYPES (TREE_TYPE (m2_or_arglist));
9874 if (!METHOD_STATIC (m2_or_arglist))
9875 m2_arg = TREE_CHAIN (m2_arg);
9878 m2_arg = m2_or_arglist;
9880 m2_arg_value = m2_or_arglist;
9881 m2_arg_cache = m2_arg;
9884 while (m1_arg != end_params_node && m2_arg != end_params_node)
9886 resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
9887 if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
9888 TREE_VALUE (m2_arg)))
9890 m1_arg = TREE_CHAIN (m1_arg);
9891 m2_arg = TREE_CHAIN (m2_arg);
9893 return m1_arg == end_params_node && m2_arg == end_params_node;
9896 /* Qualification routines */
9899 qualify_ambiguous_name (id)
9902 tree qual, qual_wfl, name = NULL_TREE, decl, ptr_type = NULL_TREE,
9903 saved_current_class;
9904 int again, super_found = 0, this_found = 0, new_array_found = 0;
9907 /* We first qualify the first element, then derive qualification of
9908 others based on the first one. If the first element is qualified
9909 by a resolution (field or type), this resolution is stored in the
9910 QUAL_RESOLUTION of the qual element being examined. We need to
9911 save the current_class since the use of SUPER might change the
9913 saved_current_class = current_class;
9914 qual = EXPR_WFL_QUALIFICATION (id);
9917 /* Simple qualified expression feature a qual_wfl that is a
9918 WFL. Expression derived from a primary feature more complicated
9919 things like a CALL_EXPR. Expression from primary need to be
9920 worked out to extract the part on which the qualification will
9922 qual_wfl = QUAL_WFL (qual);
9923 switch (TREE_CODE (qual_wfl))
9926 qual_wfl = TREE_OPERAND (qual_wfl, 0);
9927 if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
9929 qual = EXPR_WFL_QUALIFICATION (qual_wfl);
9930 qual_wfl = QUAL_WFL (qual);
9933 case NEW_ARRAY_EXPR:
9934 case NEW_ANONYMOUS_ARRAY_EXPR:
9935 qual = TREE_CHAIN (qual);
9936 again = new_array_found = 1;
9938 case NEW_CLASS_EXPR:
9940 qual_wfl = TREE_OPERAND (qual_wfl, 0);
9943 while (TREE_CODE (qual_wfl) == ARRAY_REF)
9944 qual_wfl = TREE_OPERAND (qual_wfl, 0);
9947 qual = TREE_CHAIN (qual);
9948 qual_wfl = QUAL_WFL (qual);
9951 /* Fix for -Wall. Just break doing nothing */
9955 ptr_type = current_class;
9957 code = TREE_CODE (qual_wfl);
9959 /* Pos evaluation: non WFL leading expression nodes */
9960 if (code == CONVERT_EXPR
9961 && TREE_CODE (TREE_TYPE (qual_wfl)) == EXPR_WITH_FILE_LOCATION)
9962 name = EXPR_WFL_NODE (TREE_TYPE (qual_wfl));
9964 else if (code == INTEGER_CST)
9967 else if ((code == ARRAY_REF || code == CALL_EXPR || code == MODIFY_EXPR) &&
9968 TREE_CODE (TREE_OPERAND (qual_wfl, 0)) == EXPR_WITH_FILE_LOCATION)
9969 name = EXPR_WFL_NODE (TREE_OPERAND (qual_wfl, 0));
9971 else if (code == TREE_LIST)
9972 name = EXPR_WFL_NODE (TREE_PURPOSE (qual_wfl));
9974 else if (code == STRING_CST || code == CONDITIONAL_EXPR
9975 || code == PLUS_EXPR)
9977 qual = TREE_CHAIN (qual);
9978 qual_wfl = QUAL_WFL (qual);
9983 name = EXPR_WFL_NODE (qual_wfl);
9986 qual = EXPR_WFL_QUALIFICATION (qual_wfl);
9991 /* If we have a THIS (from a primary), we set the context accordingly */
9992 if (name == this_identifier_node)
9994 qual = TREE_CHAIN (qual);
9995 qual_wfl = QUAL_WFL (qual);
9996 if (TREE_CODE (qual_wfl) == CALL_EXPR)
9999 name = EXPR_WFL_NODE (qual_wfl);
10002 /* If we have a SUPER, we set the context accordingly */
10003 if (name == super_identifier_node)
10005 current_class = CLASSTYPE_SUPER (ptr_type);
10006 /* Check that there is such a thing as a super class. If not,
10007 return. The error will be caught later on, during the
10009 if (!current_class)
10011 current_class = saved_current_class;
10014 qual = TREE_CHAIN (qual);
10015 /* Do one more interation to set things up */
10016 super_found = again = 1;
10020 /* If name appears within the scope of a location variable
10021 declaration or parameter declaration, then it is an expression
10022 name. We don't carry this test out if we're in the context of the
10023 use of SUPER or THIS */
10024 if (!this_found && !super_found
10025 && TREE_CODE (name) != STRING_CST && TREE_CODE (name) != INTEGER_CST
10026 && (decl = IDENTIFIER_LOCAL_VALUE (name)))
10028 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
10029 QUAL_RESOLUTION (qual) = decl;
10032 /* If within the class/interface NAME was found to be used there
10033 exists a (possibly inherited) field named NAME, then this is an
10034 expression name. If we saw a NEW_ARRAY_EXPR before and want to
10035 address length, it is OK. */
10036 else if ((decl = lookup_field_wrapper (ptr_type, name))
10037 || (new_array_found && name == length_identifier_node))
10039 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
10040 QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
10043 /* We reclassify NAME as yielding to a type name resolution if:
10044 - NAME is a class/interface declared within the compilation
10045 unit containing NAME,
10046 - NAME is imported via a single-type-import declaration,
10047 - NAME is declared in an another compilation unit of the package
10048 of the compilation unit containing NAME,
10049 - NAME is declared by exactly on type-import-on-demand declaration
10050 of the compilation unit containing NAME.
10051 - NAME is actually a STRING_CST. */
10052 else if (TREE_CODE (name) == STRING_CST || TREE_CODE (name) == INTEGER_CST
10053 || (decl = resolve_and_layout (name, NULL_TREE)))
10055 RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
10056 QUAL_RESOLUTION (qual) = decl;
10059 /* Method call are expression name */
10060 else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR
10061 || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF
10062 || TREE_CODE (QUAL_WFL (qual)) == CONVERT_EXPR)
10063 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
10065 /* Check here that NAME isn't declared by more than one
10066 type-import-on-demand declaration of the compilation unit
10067 containing NAME. FIXME */
10069 /* Otherwise, NAME is reclassified as a package name */
10071 RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
10073 /* Propagate the qualification accross other components of the
10075 for (qual = TREE_CHAIN (qual); qual;
10076 qual_wfl = QUAL_WFL (qual), qual = TREE_CHAIN (qual))
10078 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
10079 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
10081 RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (qual)) = 1;
10084 /* Store the global qualification for the ambiguous part of ID back
10086 if (RESOLVE_EXPRESSION_NAME_P (qual_wfl))
10087 RESOLVE_EXPRESSION_NAME_P (id) = 1;
10088 else if (RESOLVE_TYPE_NAME_P (qual_wfl))
10089 RESOLVE_TYPE_NAME_P (id) = 1;
10090 else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
10091 RESOLVE_PACKAGE_NAME_P (id) = 1;
10093 /* Restore the current class */
10094 current_class = saved_current_class;
10098 breakdown_qualified (left, right, source)
10099 tree *left, *right, source;
10101 char *p = IDENTIFIER_POINTER (source), *base;
10102 int l = IDENTIFIER_LENGTH (source);
10104 /* Breakdown NAME into REMAINDER . IDENTIFIER */
10107 while (*p != '.' && p != base)
10110 /* We didn't find a '.'. Return an error */
10116 *right = get_identifier (p+1);
10117 *left = get_identifier (IDENTIFIER_POINTER (source));
10123 /* Patch tree nodes in a function body. When a BLOCK is found, push
10124 local variable decls if present.
10125 Same as java_complete_lhs, but does resolve static finals to values. */
10128 java_complete_tree (node)
10131 node = java_complete_lhs (node);
10132 if (TREE_CODE (node) == VAR_DECL && FIELD_STATIC (node)
10133 && FIELD_FINAL (node) && DECL_INITIAL (node) != NULL_TREE
10134 && !flag_emit_xref)
10136 tree value = DECL_INITIAL (node);
10137 DECL_INITIAL (node) = NULL_TREE;
10138 push_obstacks (&permanent_obstack, &permanent_obstack);
10139 value = fold_constant_for_init (value, node);
10141 DECL_INITIAL (node) = value;
10142 if (value != NULL_TREE)
10144 /* fold_constant_for_init sometimes widen the original type
10145 of the constant (i.e. byte to int.) It's not desirable,
10146 especially if NODE is a function argument. */
10147 if (TREE_CODE (value) == INTEGER_CST
10148 && TREE_TYPE (node) != TREE_TYPE (value))
10149 return convert (TREE_TYPE (node), value);
10158 java_stabilize_reference (node)
10161 if (TREE_CODE (node) == COMPOUND_EXPR)
10163 tree op0 = TREE_OPERAND (node, 0);
10164 tree op1 = TREE_OPERAND (node, 1);
10165 TREE_OPERAND (node, 0) = save_expr (op0);
10166 TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
10169 return stabilize_reference (node);
10172 /* Patch tree nodes in a function body. When a BLOCK is found, push
10173 local variable decls if present.
10174 Same as java_complete_tree, but does not resolve static finals to values. */
10177 java_complete_lhs (node)
10180 tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
10183 /* CONVERT_EXPR always has its type set, even though it needs to be
10185 if (TREE_TYPE (node) && TREE_CODE (node) != CONVERT_EXPR)
10188 /* The switch block implements cases processing container nodes
10189 first. Contained nodes are always written back. Leaves come
10190 next and return a value. */
10191 switch (TREE_CODE (node))
10195 /* 1- Block section.
10196 Set the local values on decl names so we can identify them
10197 faster when they're referenced. At that stage, identifiers
10198 are legal so we don't check for declaration errors. */
10199 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
10201 DECL_CONTEXT (cn) = current_function_decl;
10202 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
10204 if (BLOCK_EXPR_BODY (node) == NULL_TREE)
10205 CAN_COMPLETE_NORMALLY (node) = 1;
10208 tree stmt = BLOCK_EXPR_BODY (node);
10210 int error_seen = 0;
10211 if (TREE_CODE (stmt) == COMPOUND_EXPR)
10213 /* Re-order from (((A; B); C); ...; Z) to
10214 (A; (B; (C ; (...; Z)))).
10215 This makes it easier to scan the statements left-to-right
10216 without using recursion (which might overflow the stack
10217 if the block has many statements. */
10220 tree left = TREE_OPERAND (stmt, 0);
10221 if (TREE_CODE (left) != COMPOUND_EXPR)
10223 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
10224 TREE_OPERAND (left, 1) = stmt;
10227 BLOCK_EXPR_BODY (node) = stmt;
10230 /* Now do the actual complete, without deep recursion for
10232 ptr = &BLOCK_EXPR_BODY (node);
10233 while (TREE_CODE (*ptr) == COMPOUND_EXPR
10234 && TREE_OPERAND (*ptr, 1) != empty_stmt_node)
10236 tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
10237 tree *next = &TREE_OPERAND (*ptr, 1);
10238 TREE_OPERAND (*ptr, 0) = cur;
10239 if (cur == empty_stmt_node)
10241 /* Optimization; makes it easier to detect empty bodies.
10242 Most useful for <clinit> with all-constant initializer. */
10246 if (TREE_CODE (cur) == ERROR_MARK)
10248 else if (! CAN_COMPLETE_NORMALLY (cur))
10253 if (TREE_CODE (wfl_op2) == BLOCK)
10254 wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
10255 else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
10256 wfl_op2 = TREE_OPERAND (wfl_op2, 0);
10260 if (TREE_CODE (wfl_op2) != CASE_EXPR
10261 && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
10262 unreachable_stmt_error (*ptr);
10266 *ptr = java_complete_tree (*ptr);
10268 if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
10269 return error_mark_node;
10270 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
10272 /* Turn local bindings to null */
10273 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
10274 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = NULL_TREE;
10276 TREE_TYPE (node) = void_type_node;
10279 /* 2- They are expressions but ultimately deal with statements */
10282 wfl_op1 = TREE_OPERAND (node, 0);
10283 COMPLETE_CHECK_OP_0 (node);
10284 /* 14.19 A throw statement cannot complete normally. */
10285 CAN_COMPLETE_NORMALLY (node) = 0;
10286 return patch_throw_statement (node, wfl_op1);
10288 case SYNCHRONIZED_EXPR:
10289 wfl_op1 = TREE_OPERAND (node, 0);
10290 return patch_synchronized_statement (node, wfl_op1);
10293 return patch_try_statement (node);
10295 case TRY_FINALLY_EXPR:
10296 COMPLETE_CHECK_OP_0 (node);
10297 COMPLETE_CHECK_OP_1 (node);
10298 CAN_COMPLETE_NORMALLY (node)
10299 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
10300 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
10301 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
10304 case CLEANUP_POINT_EXPR:
10305 COMPLETE_CHECK_OP_0 (node);
10306 TREE_TYPE (node) = void_type_node;
10307 CAN_COMPLETE_NORMALLY (node) =
10308 CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
10311 case WITH_CLEANUP_EXPR:
10312 COMPLETE_CHECK_OP_0 (node);
10313 COMPLETE_CHECK_OP_2 (node);
10314 CAN_COMPLETE_NORMALLY (node) =
10315 CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
10316 TREE_TYPE (node) = void_type_node;
10319 case LABELED_BLOCK_EXPR:
10320 PUSH_LABELED_BLOCK (node);
10321 if (LABELED_BLOCK_BODY (node))
10322 COMPLETE_CHECK_OP_1 (node);
10323 TREE_TYPE (node) = void_type_node;
10324 POP_LABELED_BLOCK ();
10326 if (LABELED_BLOCK_BODY (node) == empty_stmt_node)
10328 LABELED_BLOCK_BODY (node) = NULL_TREE;
10329 CAN_COMPLETE_NORMALLY (node) = 1;
10331 else if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
10332 CAN_COMPLETE_NORMALLY (node) = 1;
10335 case EXIT_BLOCK_EXPR:
10336 /* We don't complete operand 1, because it's the return value of
10337 the EXIT_BLOCK_EXPR which doesn't exist it Java */
10338 return patch_bc_statement (node);
10341 cn = java_complete_tree (TREE_OPERAND (node, 0));
10342 if (cn == error_mark_node)
10345 /* First, the case expression must be constant. Values of final
10346 fields are accepted. */
10348 if ((TREE_CODE (cn) == COMPOUND_EXPR || TREE_CODE (cn) == COMPONENT_REF)
10349 && JDECL_P (TREE_OPERAND (cn, 1))
10350 && FIELD_FINAL (TREE_OPERAND (cn, 1))
10351 && DECL_INITIAL (TREE_OPERAND (cn, 1)))
10353 push_obstacks (&permanent_obstack, &permanent_obstack);
10354 cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
10355 TREE_OPERAND (cn, 1));
10359 if (!TREE_CONSTANT (cn) && !flag_emit_xref)
10361 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10362 parse_error_context (node, "Constant expression required");
10363 return error_mark_node;
10366 nn = ctxp->current_loop;
10368 /* It must be assignable to the type of the switch expression. */
10369 if (!try_builtin_assignconv (NULL_TREE,
10370 TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
10372 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10373 parse_error_context
10375 "Incompatible type for case. Can't convert `%s' to `int'",
10376 lang_printable_name (TREE_TYPE (cn), 0));
10377 return error_mark_node;
10380 cn = fold (convert (int_type_node, cn));
10382 /* Multiple instance of a case label bearing the same
10383 value is checked during code generation. The case
10384 expression is allright so far. */
10385 TREE_OPERAND (node, 0) = cn;
10386 TREE_TYPE (node) = void_type_node;
10387 CAN_COMPLETE_NORMALLY (node) = 1;
10388 TREE_SIDE_EFFECTS (node) = 1;
10392 nn = ctxp->current_loop;
10393 /* Only one default label is allowed per switch statement */
10394 if (SWITCH_HAS_DEFAULT (nn))
10396 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10397 parse_error_context (wfl_operator,
10398 "Duplicate case label: `default'");
10399 return error_mark_node;
10402 SWITCH_HAS_DEFAULT (nn) = 1;
10403 TREE_TYPE (node) = void_type_node;
10404 TREE_SIDE_EFFECTS (node) = 1;
10405 CAN_COMPLETE_NORMALLY (node) = 1;
10411 /* Check whether the loop was enclosed in a labeled
10412 statement. If not, create one, insert the loop in it and
10414 nn = patch_loop_statement (node);
10416 /* Anyways, walk the body of the loop */
10417 if (TREE_CODE (node) == LOOP_EXPR)
10418 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
10419 /* Switch statement: walk the switch expression and the cases */
10421 node = patch_switch_statement (node);
10423 if (TREE_OPERAND (node, 0) == error_mark_node)
10424 nn = error_mark_node;
10427 TREE_TYPE (nn) = TREE_TYPE (node) = void_type_node;
10428 /* If we returned something different, that's because we
10429 inserted a label. Pop the label too. */
10432 if (CAN_COMPLETE_NORMALLY (node))
10433 CAN_COMPLETE_NORMALLY (nn) = 1;
10434 POP_LABELED_BLOCK ();
10441 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
10442 return patch_exit_expr (node);
10446 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
10447 if (TREE_OPERAND (node, 0) == error_mark_node)
10448 return error_mark_node;
10449 /* then-else branches */
10450 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
10451 if (TREE_OPERAND (node, 1) == error_mark_node)
10452 return error_mark_node;
10453 TREE_OPERAND (node, 2) = java_complete_tree (TREE_OPERAND (node, 2));
10454 if (TREE_OPERAND (node, 2) == error_mark_node)
10455 return error_mark_node;
10456 return patch_if_else_statement (node);
10459 case CONDITIONAL_EXPR:
10461 wfl_op1 = TREE_OPERAND (node, 0);
10462 COMPLETE_CHECK_OP_0 (node);
10463 wfl_op2 = TREE_OPERAND (node, 1);
10464 COMPLETE_CHECK_OP_1 (node);
10465 wfl_op3 = TREE_OPERAND (node, 2);
10466 COMPLETE_CHECK_OP_2 (node);
10467 return patch_conditional_expr (node, wfl_op1, wfl_op2);
10469 /* 3- Expression section */
10470 case COMPOUND_EXPR:
10471 wfl_op2 = TREE_OPERAND (node, 1);
10472 TREE_OPERAND (node, 0) = nn =
10473 java_complete_tree (TREE_OPERAND (node, 0));
10474 if (wfl_op2 == empty_stmt_node)
10475 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
10478 if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
10480 /* An unreachable condition in a do-while statement
10481 is *not* (technically) an unreachable statement. */
10483 if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
10484 nn = EXPR_WFL_NODE (nn);
10485 if (TREE_CODE (nn) != EXIT_EXPR)
10487 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
10488 parse_error_context (wfl_operator, "Unreachable statement");
10491 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
10492 if (TREE_OPERAND (node, 1) == error_mark_node)
10493 return error_mark_node;
10494 CAN_COMPLETE_NORMALLY (node)
10495 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1));
10497 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
10501 /* CAN_COMPLETE_NORMALLY (node) = 0; */
10502 return patch_return (node);
10504 case EXPR_WITH_FILE_LOCATION:
10505 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
10506 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
10509 node = resolve_expression_name (node, NULL);
10510 if (node == error_mark_node)
10512 /* Keep line number information somewhere were it doesn't
10513 disrupt the completion process. */
10514 if (flag_emit_xref && TREE_CODE (node) != CALL_EXPR)
10516 EXPR_WFL_NODE (wfl) = TREE_OPERAND (node, 1);
10517 TREE_OPERAND (node, 1) = wfl;
10519 CAN_COMPLETE_NORMALLY (node) = 1;
10524 int save_lineno = lineno;
10525 lineno = EXPR_WFL_LINENO (node);
10526 body = java_complete_tree (EXPR_WFL_NODE (node));
10527 lineno = save_lineno;
10528 EXPR_WFL_NODE (node) = body;
10529 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
10530 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
10531 if (body == empty_stmt_node)
10533 /* Optimization; makes it easier to detect empty bodies. */
10536 if (body == error_mark_node)
10538 /* Its important for the evaluation of assignment that
10539 this mark on the TREE_TYPE is propagated. */
10540 TREE_TYPE (node) = error_mark_node;
10541 return error_mark_node;
10544 TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
10549 case NEW_ARRAY_EXPR:
10550 /* Patch all the dimensions */
10552 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
10554 int location = EXPR_WFL_LINECOL (TREE_VALUE (cn));
10555 tree dim = convert (int_type_node,
10556 java_complete_tree (TREE_VALUE (cn)));
10557 if (dim == error_mark_node)
10564 TREE_VALUE (cn) = dim;
10565 /* Setup the location of the current dimension, for
10566 later error report. */
10567 TREE_PURPOSE (cn) =
10568 build_expr_wfl (NULL_TREE, input_filename, 0, 0);
10569 EXPR_WFL_LINECOL (TREE_PURPOSE (cn)) = location;
10572 /* They complete the array creation expression, if no errors
10574 CAN_COMPLETE_NORMALLY (node) = 1;
10575 return (flag ? error_mark_node
10576 : force_evaluation_order (patch_newarray (node)));
10578 case NEW_ANONYMOUS_ARRAY_EXPR:
10579 /* Create the array type if necessary. */
10580 if (ANONYMOUS_ARRAY_DIMS_SIG (node))
10582 tree type = ANONYMOUS_ARRAY_BASE_TYPE (node);
10583 if (!(type = resolve_type_during_patch (type)))
10584 return error_mark_node;
10585 type = build_array_from_name (type, NULL_TREE,
10586 ANONYMOUS_ARRAY_DIMS_SIG (node), NULL);
10587 ANONYMOUS_ARRAY_BASE_TYPE (node) = build_pointer_type (type);
10589 node = patch_new_array_init (ANONYMOUS_ARRAY_BASE_TYPE (node),
10590 ANONYMOUS_ARRAY_INITIALIZER (node));
10591 if (node == error_mark_node)
10592 return error_mark_node;
10593 CAN_COMPLETE_NORMALLY (node) = 1;
10596 case NEW_CLASS_EXPR:
10598 /* Complete function's argument(s) first */
10599 if (complete_function_arguments (node))
10600 return error_mark_node;
10603 tree decl, wfl = TREE_OPERAND (node, 0);
10604 int in_this = CALL_THIS_CONSTRUCTOR_P (node);
10606 node = patch_method_invocation (node, NULL_TREE,
10607 NULL_TREE, 0, &decl);
10608 if (node == error_mark_node)
10609 return error_mark_node;
10611 check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
10612 /* If we call this(...), register signature and positions */
10614 DECL_CONSTRUCTOR_CALLS (current_function_decl) =
10615 tree_cons (wfl, decl,
10616 DECL_CONSTRUCTOR_CALLS (current_function_decl));
10617 CAN_COMPLETE_NORMALLY (node) = 1;
10618 return force_evaluation_order (node);
10622 /* Save potential wfls */
10623 wfl_op1 = TREE_OPERAND (node, 0);
10624 TREE_OPERAND (node, 0) = nn = java_complete_lhs (wfl_op1);
10626 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node)
10627 && TREE_CODE (nn) == VAR_DECL && TREE_STATIC (nn)
10628 && DECL_INITIAL (nn) != NULL_TREE)
10632 push_obstacks (&permanent_obstack, &permanent_obstack);
10633 value = fold_constant_for_init (nn, nn);
10636 if (value != NULL_TREE)
10638 tree type = TREE_TYPE (value);
10639 if (JPRIMITIVE_TYPE_P (type) ||
10640 (type == string_ptr_type_node && ! flag_emit_class_files))
10641 return empty_stmt_node;
10643 DECL_INITIAL (nn) = NULL_TREE;
10645 wfl_op2 = TREE_OPERAND (node, 1);
10647 if (TREE_OPERAND (node, 0) == error_mark_node)
10648 return error_mark_node;
10650 flag = COMPOUND_ASSIGN_P (wfl_op2);
10653 /* This might break when accessing outer field from inner
10654 class. TESTME, FIXME */
10655 tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0));
10657 /* Hand stablize the lhs on both places */
10658 TREE_OPERAND (node, 0) = lvalue;
10659 TREE_OPERAND (TREE_OPERAND (node, 1), 0) =
10660 (flag_emit_class_files ? lvalue : save_expr (lvalue));
10662 /* 15.25.2.a: Left hand is not an array access. FIXME */
10663 /* Now complete the RHS. We write it back later on. */
10664 nn = java_complete_tree (TREE_OPERAND (node, 1));
10666 if ((cn = patch_string (nn)))
10669 /* The last part of the rewrite for E1 op= E2 is to have
10670 E1 = (T)(E1 op E2), with T being the type of E1. */
10671 nn = java_complete_tree (build_cast (EXPR_WFL_LINECOL (wfl_op2),
10672 TREE_TYPE (lvalue), nn));
10674 /* 15.25.2.b: Left hand is an array access. FIXME */
10677 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
10678 function to complete this RHS. Note that a NEW_ARRAY_INIT
10679 might have been already fully expanded if created as a result
10680 of processing an anonymous array initializer. We avoid doing
10681 the operation twice by testing whether the node already bears
10683 else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT && !TREE_TYPE (wfl_op2))
10684 nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
10685 TREE_OPERAND (node, 1));
10686 /* Otherwise we simply complete the RHS */
10688 nn = java_complete_tree (TREE_OPERAND (node, 1));
10690 if (nn == error_mark_node)
10691 return error_mark_node;
10693 /* Write back the RHS as we evaluated it. */
10694 TREE_OPERAND (node, 1) = nn;
10696 /* In case we're handling = with a String as a RHS, we need to
10697 produce a String out of the RHS (it might still be a
10698 STRING_CST or a StringBuffer at this stage */
10699 if ((nn = patch_string (TREE_OPERAND (node, 1))))
10700 TREE_OPERAND (node, 1) = nn;
10702 if ((nn = outer_field_access_fix (wfl_op1, TREE_OPERAND (node, 0),
10703 TREE_OPERAND (node, 1))))
10705 /* We return error_mark_node if outer_field_access_fix
10706 detects we write into a final. */
10707 if (nn == error_mark_node)
10708 return error_mark_node;
10713 node = patch_assignment (node, wfl_op1, wfl_op2);
10714 /* Reorganize the tree if necessary. */
10715 if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node))
10716 || JSTRING_P (TREE_TYPE (node))))
10717 node = java_refold (node);
10720 CAN_COMPLETE_NORMALLY (node) = 1;
10732 case TRUNC_MOD_EXPR:
10733 case TRUNC_DIV_EXPR:
10735 case TRUTH_ANDIF_EXPR:
10736 case TRUTH_ORIF_EXPR:
10743 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
10744 knows how to handle those cases. */
10745 wfl_op1 = TREE_OPERAND (node, 0);
10746 wfl_op2 = TREE_OPERAND (node, 1);
10748 CAN_COMPLETE_NORMALLY (node) = 1;
10749 /* Don't complete string nodes if dealing with the PLUS operand. */
10750 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
10752 nn = java_complete_tree (wfl_op1);
10753 if (nn == error_mark_node)
10754 return error_mark_node;
10755 if ((cn = patch_string (nn)))
10757 TREE_OPERAND (node, 0) = nn;
10759 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
10761 nn = java_complete_tree (wfl_op2);
10762 if (nn == error_mark_node)
10763 return error_mark_node;
10764 if ((cn = patch_string (nn)))
10766 TREE_OPERAND (node, 1) = nn;
10768 return force_evaluation_order (patch_binop (node, wfl_op1, wfl_op2));
10770 case INSTANCEOF_EXPR:
10771 wfl_op1 = TREE_OPERAND (node, 0);
10772 COMPLETE_CHECK_OP_0 (node);
10773 if (flag_emit_xref)
10775 TREE_TYPE (node) = boolean_type_node;
10778 return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
10780 case UNARY_PLUS_EXPR:
10782 case TRUTH_NOT_EXPR:
10784 case PREDECREMENT_EXPR:
10785 case PREINCREMENT_EXPR:
10786 case POSTDECREMENT_EXPR:
10787 case POSTINCREMENT_EXPR:
10789 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
10790 how to handle those cases. */
10791 wfl_op1 = TREE_OPERAND (node, 0);
10792 CAN_COMPLETE_NORMALLY (node) = 1;
10793 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
10794 if (TREE_OPERAND (node, 0) == error_mark_node)
10795 return error_mark_node;
10796 node = patch_unaryop (node, wfl_op1);
10797 CAN_COMPLETE_NORMALLY (node) = 1;
10801 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
10802 how to handle those cases. */
10803 wfl_op1 = TREE_OPERAND (node, 0);
10804 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
10805 if (TREE_OPERAND (node, 0) == error_mark_node)
10806 return error_mark_node;
10807 if (!flag_emit_class_files && !flag_emit_xref)
10808 TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
10809 /* The same applies to wfl_op2 */
10810 wfl_op2 = TREE_OPERAND (node, 1);
10811 TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
10812 if (TREE_OPERAND (node, 1) == error_mark_node)
10813 return error_mark_node;
10814 if (!flag_emit_class_files && !flag_emit_xref)
10815 TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
10816 return patch_array_ref (node);
10821 case COMPONENT_REF:
10822 /* The first step in the re-write of qualified name handling. FIXME.
10823 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
10824 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
10825 if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
10827 tree name = TREE_OPERAND (node, 1);
10828 tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
10829 if (field == NULL_TREE)
10831 error ("missing static field `%s'", IDENTIFIER_POINTER (name));
10832 return error_mark_node;
10834 if (! FIELD_STATIC (field))
10836 error ("not a static field `%s'", IDENTIFIER_POINTER (name));
10837 return error_mark_node;
10842 fatal ("unimplemented java_complete_tree for COMPONENT_REF");
10846 /* Can't use THIS in a static environment */
10849 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10850 parse_error_context (wfl_operator,
10851 "Keyword `this' used outside allowed context");
10852 TREE_TYPE (node) = error_mark_node;
10853 return error_mark_node;
10855 if (ctxp->explicit_constructor_p)
10857 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10858 parse_error_context
10859 (wfl_operator, "Can't reference `this' or `super' before the superclass constructor has been called");
10860 TREE_TYPE (node) = error_mark_node;
10861 return error_mark_node;
10863 return current_this;
10865 case CLASS_LITERAL:
10866 CAN_COMPLETE_NORMALLY (node) = 1;
10867 node = patch_incomplete_class_ref (node);
10868 if (node == error_mark_node)
10869 return error_mark_node;
10872 case INSTANCE_INITIALIZERS_EXPR:
10873 in_instance_initializer++;
10874 node = java_complete_tree (TREE_OPERAND (node, 0));
10875 in_instance_initializer--;
10876 if (node != error_mark_node)
10877 TREE_TYPE (node) = void_type_node;
10879 return error_mark_node;
10883 CAN_COMPLETE_NORMALLY (node) = 1;
10884 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
10885 and it's time to turn it into the appropriate String object */
10886 if ((nn = patch_string (node)))
10889 fatal ("No case for tree code `%s' - java_complete_tree\n",
10890 tree_code_name [TREE_CODE (node)]);
10895 /* Complete function call's argument. Return a non zero value is an
10896 error was found. */
10899 complete_function_arguments (node)
10905 ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
10906 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
10908 tree wfl = TREE_VALUE (cn), parm, temp;
10909 parm = java_complete_tree (wfl);
10911 if (parm == error_mark_node)
10916 /* If have a string literal that we haven't transformed yet or a
10917 crafted string buffer, as a result of use of the the String
10918 `+' operator. Build `parm.toString()' and expand it. */
10919 if ((temp = patch_string (parm)))
10921 /* Inline PRIMTYPE.TYPE read access */
10922 parm = maybe_build_primttype_type_ref (parm, wfl);
10924 TREE_VALUE (cn) = parm;
10926 ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
10930 /* Sometimes (for loops and variable initialized during their
10931 declaration), we want to wrap a statement around a WFL and turn it
10935 build_debugable_stmt (location, stmt)
10939 if (TREE_CODE (stmt) != EXPR_WITH_FILE_LOCATION)
10941 stmt = build_expr_wfl (stmt, input_filename, 0, 0);
10942 EXPR_WFL_LINECOL (stmt) = location;
10944 JAVA_MAYBE_GENERATE_DEBUG_INFO (stmt);
10949 build_expr_block (body, decls)
10952 tree node = make_node (BLOCK);
10953 BLOCK_EXPR_DECLS (node) = decls;
10954 BLOCK_EXPR_BODY (node) = body;
10956 TREE_TYPE (node) = TREE_TYPE (body);
10957 TREE_SIDE_EFFECTS (node) = 1;
10961 /* Create a new function block and link it approriately to current
10962 function block chain */
10967 return (enter_a_block (build_expr_block (NULL_TREE, NULL_TREE)));
10970 /* Link block B supercontext to the previous block. The current
10971 function DECL is used as supercontext when enter_a_block is called
10972 for the first time for a given function. The current function body
10973 (DECL_FUNCTION_BODY) is set to be block B. */
10979 tree fndecl = current_function_decl;
10982 BLOCK_SUPERCONTEXT (b) = current_static_block;
10983 current_static_block = b;
10986 else if (!DECL_FUNCTION_BODY (fndecl))
10988 BLOCK_SUPERCONTEXT (b) = fndecl;
10989 DECL_FUNCTION_BODY (fndecl) = b;
10993 BLOCK_SUPERCONTEXT (b) = DECL_FUNCTION_BODY (fndecl);
10994 DECL_FUNCTION_BODY (fndecl) = b;
10999 /* Exit a block by changing the current function body
11000 (DECL_FUNCTION_BODY) to the current block super context, only if
11001 the block being exited isn't the method's top level one. */
11007 if (current_function_decl)
11009 b = DECL_FUNCTION_BODY (current_function_decl);
11010 if (BLOCK_SUPERCONTEXT (b) != current_function_decl)
11011 DECL_FUNCTION_BODY (current_function_decl) = BLOCK_SUPERCONTEXT (b);
11015 b = current_static_block;
11017 if (BLOCK_SUPERCONTEXT (b))
11018 current_static_block = BLOCK_SUPERCONTEXT (b);
11023 /* Lookup for NAME in the nested function's blocks, all the way up to
11024 the current toplevel one. It complies with Java's local variable
11028 lookup_name_in_blocks (name)
11031 tree b = GET_CURRENT_BLOCK (current_function_decl);
11033 while (b != current_function_decl)
11037 /* Paranoid sanity check. To be removed */
11038 if (TREE_CODE (b) != BLOCK)
11039 fatal ("non block expr function body - lookup_name_in_blocks");
11041 for (current = BLOCK_EXPR_DECLS (b); current;
11042 current = TREE_CHAIN (current))
11043 if (DECL_NAME (current) == name)
11045 b = BLOCK_SUPERCONTEXT (b);
11051 maybe_absorb_scoping_blocks ()
11053 while (BLOCK_EXPR_ORIGIN (GET_CURRENT_BLOCK (current_function_decl)))
11055 tree b = exit_block ();
11056 java_method_add_stmt (current_function_decl, b);
11057 SOURCE_FRONTEND_DEBUG (("Absorbing scoping block at line %d", lineno));
11062 /* This section of the source is reserved to build_* functions that
11063 are building incomplete tree nodes and the patch_* functions that
11064 are completing them. */
11066 /* Wrap a non WFL node around a WFL. */
11068 build_wfl_wrap (node)
11071 tree wfl, node_to_insert = node;
11073 /* We want to process THIS . xxx symbolicaly, to keep it consistent
11074 with the way we're processing SUPER. A THIS from a primary as a
11075 different form than a SUPER. Turn THIS into something symbolic */
11076 if (TREE_CODE (node) == THIS_EXPR)
11077 node_to_insert = wfl = build_wfl_node (this_identifier_node);
11079 wfl = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
11081 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (node);
11082 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (node_to_insert, NULL_TREE);
11087 /* Build a super() constructor invocation. Returns empty_stmt_node if
11088 we're currently dealing with the class java.lang.Object. */
11091 build_super_invocation (mdecl)
11094 if (DECL_CONTEXT (mdecl) == object_type_node)
11095 return empty_stmt_node;
11098 tree super_wfl = build_wfl_node (super_identifier_node);
11099 tree a = NULL_TREE, t;
11100 /* If we're dealing with an anonymous class, pass the arguments
11101 of the crafted constructor along. */
11102 if (ANONYMOUS_CLASS_P (DECL_CONTEXT (mdecl)))
11104 SKIP_THIS_AND_ARTIFICIAL_PARMS (t, mdecl);
11105 for (; t != end_params_node; t = TREE_CHAIN (t))
11106 a = tree_cons (NULL_TREE, build_wfl_node (TREE_PURPOSE (t)), a);
11108 return build_method_invocation (super_wfl, a);
11112 /* Build a SUPER/THIS qualified method invocation. */
11115 build_this_super_qualified_invocation (use_this, name, args, lloc, rloc)
11123 build_wfl_node (use_this ? this_identifier_node : super_identifier_node);
11124 EXPR_WFL_LINECOL (wfl) = lloc;
11125 invok = build_method_invocation (name, args);
11126 return make_qualified_primary (wfl, invok, rloc);
11129 /* Build an incomplete CALL_EXPR node. */
11132 build_method_invocation (name, args)
11136 tree call = build (CALL_EXPR, NULL_TREE, name, args, NULL_TREE);
11137 TREE_SIDE_EFFECTS (call) = 1;
11138 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
11142 /* Build an incomplete new xxx(...) node. */
11145 build_new_invocation (name, args)
11148 tree call = build (NEW_CLASS_EXPR, NULL_TREE, name, args, NULL_TREE);
11149 TREE_SIDE_EFFECTS (call) = 1;
11150 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
11154 /* Build an incomplete assignment expression. */
11157 build_assignment (op, op_location, lhs, rhs)
11158 int op, op_location;
11162 /* Build the corresponding binop if we deal with a Compound
11163 Assignment operator. Mark the binop sub-tree as part of a
11164 Compound Assignment expression */
11165 if (op != ASSIGN_TK)
11167 rhs = build_binop (BINOP_LOOKUP (op), op_location, lhs, rhs);
11168 COMPOUND_ASSIGN_P (rhs) = 1;
11170 assignment = build (MODIFY_EXPR, NULL_TREE, lhs, rhs);
11171 TREE_SIDE_EFFECTS (assignment) = 1;
11172 EXPR_WFL_LINECOL (assignment) = op_location;
11176 /* Print an INTEGER_CST node in a static buffer, and return the buffer. */
11179 print_int_node (node)
11182 static char buffer [80];
11183 if (TREE_CONSTANT_OVERFLOW (node))
11184 sprintf (buffer, "<overflow>");
11186 if (TREE_INT_CST_HIGH (node) == 0)
11187 sprintf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
11188 TREE_INT_CST_LOW (node));
11189 else if (TREE_INT_CST_HIGH (node) == -1
11190 && TREE_INT_CST_LOW (node) != 0)
11193 sprintf (&buffer [1], HOST_WIDE_INT_PRINT_UNSIGNED,
11194 -TREE_INT_CST_LOW (node));
11197 sprintf (buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
11198 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
11203 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
11207 check_final_assignment (lvalue, wfl)
11210 if (TREE_CODE (lvalue) == COMPOUND_EXPR
11211 && JDECL_P (TREE_OPERAND (lvalue, 1)))
11212 lvalue = TREE_OPERAND (lvalue, 1);
11214 if (TREE_CODE (lvalue) == FIELD_DECL
11215 && FIELD_FINAL (lvalue)
11216 && !DECL_CLINIT_P (current_function_decl)
11217 && !DECL_FINIT_P (current_function_decl))
11219 parse_error_context
11220 (wfl, "Can't assign a value to the final variable `%s'",
11221 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
11227 /* Inline references to java.lang.PRIMTYPE.TYPE when accessed in
11228 read. This is needed to avoid circularities in the implementation
11229 of these fields in libjava. */
11232 maybe_build_primttype_type_ref (rhs, wfl)
11235 tree to_return = NULL_TREE;
11236 tree rhs_type = TREE_TYPE (rhs);
11237 if (TREE_CODE (rhs) == COMPOUND_EXPR)
11239 tree n = TREE_OPERAND (rhs, 1);
11240 if (TREE_CODE (n) == VAR_DECL
11241 && DECL_NAME (n) == TYPE_identifier_node
11242 && rhs_type == class_ptr_type)
11244 const char *self_name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl));
11245 if (!strncmp (self_name, "java.lang.", 10))
11246 to_return = build_primtype_type_ref (self_name);
11249 return (to_return ? to_return : rhs );
11252 /* 15.25 Assignment operators. */
11255 patch_assignment (node, wfl_op1, wfl_op2)
11260 tree rhs = TREE_OPERAND (node, 1);
11261 tree lvalue = TREE_OPERAND (node, 0), llvalue;
11262 tree lhs_type = NULL_TREE, rhs_type, new_rhs = NULL_TREE;
11263 int error_found = 0;
11264 int lvalue_from_array = 0;
11266 /* Can't assign to a (blank) final. */
11267 if (check_final_assignment (lvalue, wfl_op1))
11270 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11272 /* Lhs can be a named variable */
11273 if (JDECL_P (lvalue))
11275 lhs_type = TREE_TYPE (lvalue);
11277 /* Or Lhs can be a array acccess. Should that be lvalue ? FIXME +
11278 comment on reason why */
11279 else if (TREE_CODE (wfl_op1) == ARRAY_REF)
11281 lhs_type = TREE_TYPE (lvalue);
11282 lvalue_from_array = 1;
11284 /* Or a field access */
11285 else if (TREE_CODE (lvalue) == COMPONENT_REF)
11286 lhs_type = TREE_TYPE (lvalue);
11287 /* Or a function return slot */
11288 else if (TREE_CODE (lvalue) == RESULT_DECL)
11289 lhs_type = TREE_TYPE (lvalue);
11290 /* Otherwise, we might want to try to write into an optimized static
11291 final, this is an of a different nature, reported further on. */
11292 else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
11293 && resolve_expression_name (wfl_op1, &llvalue))
11295 if (!error_found && check_final_assignment (llvalue, wfl_op1))
11297 /* What we should do instead is resetting the all the flags
11298 previously set, exchange lvalue for llvalue and continue. */
11300 return error_mark_node;
11303 lhs_type = TREE_TYPE (lvalue);
11307 parse_error_context (wfl_op1, "Invalid left hand side of assignment");
11311 rhs_type = TREE_TYPE (rhs);
11312 /* 5.1 Try the assignment conversion for builtin type. */
11313 new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
11315 /* 5.2 If it failed, try a reference conversion */
11316 if (!new_rhs && (new_rhs = try_reference_assignconv (lhs_type, rhs)))
11317 lhs_type = promote_type (rhs_type);
11319 /* 15.25.2 If we have a compound assignment, convert RHS into the
11321 else if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
11322 new_rhs = convert (lhs_type, rhs);
11324 /* Explicit cast required. This is an error */
11327 char *t1 = xstrdup (lang_printable_name (TREE_TYPE (rhs), 0));
11328 char *t2 = xstrdup (lang_printable_name (lhs_type, 0));
11330 char operation [32]; /* Max size known */
11332 /* If the assignment is part of a declaration, we use the WFL of
11333 the declared variable to point out the error and call it a
11334 declaration problem. If the assignment is a genuine =
11335 operator, we call is a operator `=' problem, otherwise we
11336 call it an assignment problem. In both of these last cases,
11337 we use the WFL of the operator to indicate the error. */
11339 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node))
11342 strcpy (operation, "declaration");
11346 wfl = wfl_operator;
11347 if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
11348 strcpy (operation, "assignment");
11349 else if (TREE_CODE (TREE_OPERAND (node, 0)) == RESULT_DECL)
11350 strcpy (operation, "`return'");
11352 strcpy (operation, "`='");
11355 if (!valid_cast_to_p (rhs_type, lhs_type))
11356 parse_error_context
11357 (wfl, "Incompatible type for %s. Can't convert `%s' to `%s'",
11358 operation, t1, t2);
11360 parse_error_context (wfl, "Incompatible type for %s. Explicit cast needed to convert `%s' to `%s'",
11361 operation, t1, t2);
11362 free (t1); free (t2);
11366 /* Inline read access to java.lang.PRIMTYPE.TYPE */
11368 new_rhs = maybe_build_primttype_type_ref (new_rhs, wfl_op2);
11371 return error_mark_node;
11373 /* 10.10: Array Store Exception runtime check */
11374 if (!flag_emit_class_files
11376 && lvalue_from_array
11377 && JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type)))
11380 tree base = lvalue;
11382 /* We need to retrieve the right argument for _Jv_CheckArrayStore */
11383 if (TREE_CODE (lvalue) == COMPOUND_EXPR)
11384 base = TREE_OPERAND (lvalue, 0);
11387 if (flag_bounds_check)
11388 base = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (base, 0), 1), 0);
11390 base = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
11393 /* Build the invocation of _Jv_CheckArrayStore */
11394 new_rhs = save_expr (new_rhs);
11395 check = build (CALL_EXPR, void_type_node,
11396 build_address_of (soft_checkarraystore_node),
11397 tree_cons (NULL_TREE, base,
11398 build_tree_list (NULL_TREE, new_rhs)),
11400 TREE_SIDE_EFFECTS (check) = 1;
11402 /* We have to decide on an insertion point */
11403 if (TREE_CODE (lvalue) == COMPOUND_EXPR)
11406 if (flag_bounds_check)
11408 t = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (lvalue, 1), 0), 0);
11409 TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (lvalue, 1), 0), 0) =
11410 build (COMPOUND_EXPR, void_type_node, t, check);
11413 TREE_OPERAND (lvalue, 1) = build (COMPOUND_EXPR, lhs_type,
11414 check, TREE_OPERAND (lvalue, 1));
11418 /* Make sure the bound check will happen before the store check */
11419 if (flag_bounds_check)
11420 TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0) =
11421 build (COMPOUND_EXPR, void_type_node,
11422 TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0), check);
11424 lvalue = build (COMPOUND_EXPR, lhs_type, check, lvalue);
11428 TREE_OPERAND (node, 0) = lvalue;
11429 TREE_OPERAND (node, 1) = new_rhs;
11430 TREE_TYPE (node) = lhs_type;
11434 /* Check that type SOURCE can be cast into type DEST. If the cast
11435 can't occur at all, return 0 otherwise 1. This function is used to
11436 produce accurate error messages on the reasons why an assignment
11440 try_reference_assignconv (lhs_type, rhs)
11441 tree lhs_type, rhs;
11443 tree new_rhs = NULL_TREE;
11444 tree rhs_type = TREE_TYPE (rhs);
11446 if (!JPRIMITIVE_TYPE_P (rhs_type) && JREFERENCE_TYPE_P (lhs_type))
11448 /* `null' may be assigned to any reference type */
11449 if (rhs == null_pointer_node)
11450 new_rhs = null_pointer_node;
11451 /* Try the reference assignment conversion */
11452 else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
11454 /* This is a magic assignment that we process differently */
11455 else if (rhs == soft_exceptioninfo_call_node)
11461 /* Check that RHS can be converted into LHS_TYPE by the assignment
11462 conversion (5.2), for the cases of RHS being a builtin type. Return
11463 NULL_TREE if the conversion fails or if because RHS isn't of a
11464 builtin type. Return a converted RHS if the conversion is possible. */
11467 try_builtin_assignconv (wfl_op1, lhs_type, rhs)
11468 tree wfl_op1, lhs_type, rhs;
11470 tree new_rhs = NULL_TREE;
11471 tree rhs_type = TREE_TYPE (rhs);
11473 /* Zero accepted everywhere */
11474 if (TREE_CODE (rhs) == INTEGER_CST
11475 && TREE_INT_CST_HIGH (rhs) == 0 && TREE_INT_CST_LOW (rhs) == 0
11476 && JPRIMITIVE_TYPE_P (rhs_type))
11477 new_rhs = convert (lhs_type, rhs);
11479 /* 5.1.1 Try Identity Conversion,
11480 5.1.2 Try Widening Primitive Conversion */
11481 else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
11482 new_rhs = convert (lhs_type, rhs);
11484 /* Try a narrowing primitive conversion (5.1.3):
11485 - expression is a constant expression of type int AND
11486 - variable is byte, short or char AND
11487 - The value of the expression is representable in the type of the
11489 else if (rhs_type == int_type_node && TREE_CONSTANT (rhs)
11490 && (lhs_type == byte_type_node || lhs_type == char_type_node
11491 || lhs_type == short_type_node))
11493 if (int_fits_type_p (rhs, lhs_type))
11494 new_rhs = convert (lhs_type, rhs);
11495 else if (wfl_op1) /* Might be called with a NULL */
11496 parse_warning_context
11497 (wfl_op1, "Constant expression `%s' to wide for narrowing primitive conversion to `%s'",
11498 print_int_node (rhs), lang_printable_name (lhs_type, 0));
11499 /* Reported a warning that will turn into an error further
11500 down, so we don't return */
11506 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
11507 conversion (5.1.1) or widening primitve conversion (5.1.2). Return
11508 0 is the conversion test fails. This implements parts the method
11509 invocation convertion (5.3). */
11512 valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type)
11513 tree lhs_type, rhs_type;
11515 /* 5.1.1: This is the identity conversion part. */
11516 if (lhs_type == rhs_type)
11519 /* Reject non primitive types */
11520 if (!JPRIMITIVE_TYPE_P (lhs_type) || !JPRIMITIVE_TYPE_P (rhs_type))
11523 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
11524 than a char can't be converted into a char. Short can't too, but
11525 the < test below takes care of that */
11526 if (lhs_type == char_type_node && rhs_type == byte_type_node)
11529 /* Accept all promoted type here. Note, we can't use <= in the test
11530 below, because we still need to bounce out assignments of short
11531 to char and the likes */
11532 if (lhs_type == int_type_node
11533 && (rhs_type == promoted_byte_type_node
11534 || rhs_type == promoted_short_type_node
11535 || rhs_type == promoted_char_type_node
11536 || rhs_type == promoted_boolean_type_node))
11539 /* From here, an integral is widened if its precision is smaller
11540 than the precision of the LHS or if the LHS is a floating point
11541 type, or the RHS is a float and the RHS a double. */
11542 if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type)
11543 && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
11544 || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
11545 || (rhs_type == float_type_node && lhs_type == double_type_node))
11551 /* Check that something of SOURCE type can be assigned or cast to
11552 something of DEST type at runtime. Return 1 if the operation is
11553 valid, 0 otherwise. If CAST is set to 1, we're treating the case
11554 were SOURCE is cast into DEST, which borrows a lot of the
11555 assignment check. */
11558 valid_ref_assignconv_cast_p (source, dest, cast)
11563 /* SOURCE or DEST might be null if not from a declared entity. */
11564 if (!source || !dest)
11566 if (JNULLP_TYPE_P (source))
11568 if (TREE_CODE (source) == POINTER_TYPE)
11569 source = TREE_TYPE (source);
11570 if (TREE_CODE (dest) == POINTER_TYPE)
11571 dest = TREE_TYPE (dest);
11572 /* Case where SOURCE is a class type */
11573 if (TYPE_CLASS_P (source))
11575 if (TYPE_CLASS_P (dest))
11576 return (source == dest
11577 || inherits_from_p (source, dest)
11578 || enclosing_context_p (dest, source /*source, dest*/)
11579 || (cast && inherits_from_p (dest, source)));
11580 if (TYPE_INTERFACE_P (dest))
11582 /* If doing a cast and SOURCE is final, the operation is
11583 always correct a compile time (because even if SOURCE
11584 does not implement DEST, a subclass of SOURCE might). */
11585 if (cast && !CLASS_FINAL (TYPE_NAME (source)))
11587 /* Otherwise, SOURCE must implement DEST */
11588 return interface_of_p (dest, source);
11590 /* DEST is an array, cast permited if SOURCE is of Object type */
11591 return (cast && source == object_type_node ? 1 : 0);
11593 if (TYPE_INTERFACE_P (source))
11595 if (TYPE_CLASS_P (dest))
11597 /* If not casting, DEST must be the Object type */
11599 return dest == object_type_node;
11600 /* We're doing a cast. The cast is always valid is class
11601 DEST is not final, otherwise, DEST must implement SOURCE */
11602 else if (!CLASS_FINAL (TYPE_NAME (dest)))
11605 return interface_of_p (source, dest);
11607 if (TYPE_INTERFACE_P (dest))
11609 /* If doing a cast, then if SOURCE and DEST contain method
11610 with the same signature but different return type, then
11611 this is a (compile time) error */
11614 tree method_source, method_dest;
11618 for (method_source = TYPE_METHODS (source); method_source;
11619 method_source = TREE_CHAIN (method_source))
11622 build_java_argument_signature (TREE_TYPE (method_source));
11623 source_type = TREE_TYPE (TREE_TYPE (method_source));
11624 source_name = DECL_NAME (method_source);
11625 for (method_dest = TYPE_METHODS (dest);
11626 method_dest; method_dest = TREE_CHAIN (method_dest))
11628 build_java_argument_signature (TREE_TYPE (method_dest))
11629 && source_name == DECL_NAME (method_dest)
11630 && source_type != TREE_TYPE (TREE_TYPE (method_dest)))
11636 return source == dest || interface_of_p (dest, source);
11640 (DECL_NAME (TYPE_NAME (source)) == java_lang_cloneable) : 0);
11642 if (TYPE_ARRAY_P (source))
11644 if (TYPE_CLASS_P (dest))
11645 return dest == object_type_node;
11646 /* Can't cast an array to an interface unless the interface is
11647 java.lang.Cloneable */
11648 if (TYPE_INTERFACE_P (dest))
11649 return (DECL_NAME (TYPE_NAME (dest)) == java_lang_cloneable ? 1 : 0);
11652 tree source_element_type = TYPE_ARRAY_ELEMENT (source);
11653 tree dest_element_type = TYPE_ARRAY_ELEMENT (dest);
11655 /* In case of severe errors, they turn out null */
11656 if (!dest_element_type || !source_element_type)
11658 if (source_element_type == dest_element_type)
11660 return valid_ref_assignconv_cast_p (source_element_type,
11661 dest_element_type, cast);
11669 valid_cast_to_p (source, dest)
11673 if (TREE_CODE (source) == POINTER_TYPE)
11674 source = TREE_TYPE (source);
11675 if (TREE_CODE (dest) == POINTER_TYPE)
11676 dest = TREE_TYPE (dest);
11678 if (TREE_CODE (source) == RECORD_TYPE && TREE_CODE (dest) == RECORD_TYPE)
11679 return valid_ref_assignconv_cast_p (source, dest, 1);
11681 else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
11687 /* Method invocation conversion test. Return 1 if type SOURCE can be
11688 converted to type DEST through the methond invocation conversion
11692 do_unary_numeric_promotion (arg)
11695 tree type = TREE_TYPE (arg);
11696 if (TREE_CODE (type) == INTEGER_TYPE ? TYPE_PRECISION (type) < 32
11697 : TREE_CODE (type) == CHAR_TYPE)
11698 arg = convert (int_type_node, arg);
11702 /* Return a non zero value if SOURCE can be converted into DEST using
11703 the method invocation conversion rule (5.3). */
11705 valid_method_invocation_conversion_p (dest, source)
11708 return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
11709 && valid_builtin_assignconv_identity_widening_p (dest, source))
11710 || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
11711 && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
11712 && valid_ref_assignconv_cast_p (source, dest, 0)));
11715 /* Build an incomplete binop expression. */
11718 build_binop (op, op_location, op1, op2)
11723 tree binop = build (op, NULL_TREE, op1, op2);
11724 TREE_SIDE_EFFECTS (binop) = 1;
11725 /* Store the location of the operator, for better error report. The
11726 string of the operator will be rebuild based on the OP value. */
11727 EXPR_WFL_LINECOL (binop) = op_location;
11731 /* Build the string of the operator retained by NODE. If NODE is part
11732 of a compound expression, add an '=' at the end of the string. This
11733 function is called when an error needs to be reported on an
11734 operator. The string is returned as a pointer to a static character
11738 operator_string (node)
11741 #define BUILD_OPERATOR_STRING(S) \
11743 sprintf (buffer, "%s%s", S, (COMPOUND_ASSIGN_P (node) ? "=" : "")); \
11747 static char buffer [10];
11748 switch (TREE_CODE (node))
11750 case MULT_EXPR: BUILD_OPERATOR_STRING ("*");
11751 case RDIV_EXPR: BUILD_OPERATOR_STRING ("/");
11752 case TRUNC_MOD_EXPR: BUILD_OPERATOR_STRING ("%");
11753 case PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
11754 case MINUS_EXPR: BUILD_OPERATOR_STRING ("-");
11755 case LSHIFT_EXPR: BUILD_OPERATOR_STRING ("<<");
11756 case RSHIFT_EXPR: BUILD_OPERATOR_STRING (">>");
11757 case URSHIFT_EXPR: BUILD_OPERATOR_STRING (">>>");
11758 case BIT_AND_EXPR: BUILD_OPERATOR_STRING ("&");
11759 case BIT_XOR_EXPR: BUILD_OPERATOR_STRING ("^");
11760 case BIT_IOR_EXPR: BUILD_OPERATOR_STRING ("|");
11761 case TRUTH_ANDIF_EXPR: BUILD_OPERATOR_STRING ("&&");
11762 case TRUTH_ORIF_EXPR: BUILD_OPERATOR_STRING ("||");
11763 case EQ_EXPR: BUILD_OPERATOR_STRING ("==");
11764 case NE_EXPR: BUILD_OPERATOR_STRING ("!=");
11765 case GT_EXPR: BUILD_OPERATOR_STRING (">");
11766 case GE_EXPR: BUILD_OPERATOR_STRING (">=");
11767 case LT_EXPR: BUILD_OPERATOR_STRING ("<");
11768 case LE_EXPR: BUILD_OPERATOR_STRING ("<=");
11769 case UNARY_PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
11770 case NEGATE_EXPR: BUILD_OPERATOR_STRING ("-");
11771 case TRUTH_NOT_EXPR: BUILD_OPERATOR_STRING ("!");
11772 case BIT_NOT_EXPR: BUILD_OPERATOR_STRING ("~");
11773 case PREINCREMENT_EXPR: /* Fall through */
11774 case POSTINCREMENT_EXPR: BUILD_OPERATOR_STRING ("++");
11775 case PREDECREMENT_EXPR: /* Fall through */
11776 case POSTDECREMENT_EXPR: BUILD_OPERATOR_STRING ("--");
11778 fatal ("unregistered operator %s - operator_string",
11779 tree_code_name [TREE_CODE (node)]);
11782 #undef BUILD_OPERATOR_STRING
11785 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
11788 java_decl_equiv (var_acc1, var_acc2)
11789 tree var_acc1, var_acc2;
11791 if (JDECL_P (var_acc1))
11792 return (var_acc1 == var_acc2);
11794 return (TREE_CODE (var_acc1) == COMPONENT_REF
11795 && TREE_CODE (var_acc2) == COMPONENT_REF
11796 && TREE_OPERAND (TREE_OPERAND (var_acc1, 0), 0)
11797 == TREE_OPERAND (TREE_OPERAND (var_acc2, 0), 0)
11798 && TREE_OPERAND (var_acc1, 1) == TREE_OPERAND (var_acc2, 1));
11801 /* Return a non zero value if CODE is one of the operators that can be
11802 used in conjunction with the `=' operator in a compound assignment. */
11805 binop_compound_p (code)
11806 enum tree_code code;
11809 for (i = 0; i < BINOP_COMPOUND_CANDIDATES; i++)
11810 if (binop_lookup [i] == code)
11813 return i < BINOP_COMPOUND_CANDIDATES;
11816 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
11822 tree c, b, ns, decl;
11824 if (TREE_CODE (t) != MODIFY_EXPR)
11827 c = TREE_OPERAND (t, 1);
11828 if (! (c && TREE_CODE (c) == COMPOUND_EXPR
11829 && TREE_CODE (TREE_OPERAND (c, 0)) == MODIFY_EXPR
11830 && binop_compound_p (TREE_CODE (TREE_OPERAND (c, 1)))))
11833 /* Now the left branch of the binary operator. */
11834 b = TREE_OPERAND (TREE_OPERAND (c, 1), 0);
11835 if (! (b && TREE_CODE (b) == NOP_EXPR
11836 && TREE_CODE (TREE_OPERAND (b, 0)) == SAVE_EXPR))
11839 ns = TREE_OPERAND (TREE_OPERAND (b, 0), 0);
11840 if (! (ns && TREE_CODE (ns) == NOP_EXPR
11841 && TREE_CODE (TREE_OPERAND (ns, 0)) == SAVE_EXPR))
11844 decl = TREE_OPERAND (TREE_OPERAND (ns, 0), 0);
11845 if ((JDECL_P (decl) || TREE_CODE (decl) == COMPONENT_REF)
11846 /* It's got to be the an equivalent decl */
11847 && java_decl_equiv (decl, TREE_OPERAND (TREE_OPERAND (c, 0), 0)))
11849 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
11850 TREE_OPERAND (TREE_OPERAND (c, 1), 0) = TREE_OPERAND (ns, 0);
11851 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
11852 TREE_OPERAND (t, 1) = TREE_OPERAND (c, 1);
11853 /* Change the right part of the BINOP_EXPR */
11854 TREE_OPERAND (TREE_OPERAND (t, 1), 1) = TREE_OPERAND (c, 0);
11860 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
11861 errors but we modify NODE so that it contains the type computed
11862 according to the expression, when it's fixed. Otherwise, we write
11863 error_mark_node as the type. It allows us to further the analysis
11864 of remaining nodes and detects more errors in certain cases. */
11867 patch_binop (node, wfl_op1, wfl_op2)
11872 tree op1 = TREE_OPERAND (node, 0);
11873 tree op2 = TREE_OPERAND (node, 1);
11874 tree op1_type = TREE_TYPE (op1);
11875 tree op2_type = TREE_TYPE (op2);
11876 tree prom_type = NULL_TREE;
11877 int code = TREE_CODE (node);
11879 /* If 1, tell the routine that we have to return error_mark_node
11880 after checking for the initialization of the RHS */
11881 int error_found = 0;
11883 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
11887 /* 15.16 Multiplicative operators */
11888 case MULT_EXPR: /* 15.16.1 Multiplication Operator * */
11889 case RDIV_EXPR: /* 15.16.2 Division Operator / */
11890 case TRUNC_DIV_EXPR: /* 15.16.2 Integral type Division Operator / */
11891 case TRUNC_MOD_EXPR: /* 15.16.3 Remainder operator % */
11892 if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
11894 if (!JPRIMITIVE_TYPE_P (op1_type))
11895 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
11896 if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
11897 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
11898 TREE_TYPE (node) = error_mark_node;
11902 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
11903 /* Change the division operator if necessary */
11904 if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
11905 TREE_SET_CODE (node, TRUNC_DIV_EXPR);
11907 if (TREE_CODE (prom_type) == INTEGER_TYPE
11908 && flag_use_divide_subroutine
11909 && ! flag_emit_class_files
11910 && (code == RDIV_EXPR || code == TRUNC_MOD_EXPR))
11911 return build_java_soft_divmod (TREE_CODE (node), prom_type, op1, op2);
11913 /* This one is more complicated. FLOATs are processed by a
11914 function call to soft_fmod. Duplicate the value of the
11915 COMPOUND_ASSIGN_P flag. */
11916 if (code == TRUNC_MOD_EXPR)
11918 tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
11919 COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
11920 TREE_SIDE_EFFECTS (mod)
11921 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
11926 /* 15.17 Additive Operators */
11927 case PLUS_EXPR: /* 15.17.1 String Concatenation Operator + */
11929 /* Operation is valid if either one argument is a string
11930 constant, a String object or a StringBuffer crafted for the
11931 purpose of the a previous usage of the String concatenation
11934 if (TREE_CODE (op1) == STRING_CST
11935 || TREE_CODE (op2) == STRING_CST
11936 || JSTRING_TYPE_P (op1_type)
11937 || JSTRING_TYPE_P (op2_type)
11938 || IS_CRAFTED_STRING_BUFFER_P (op1)
11939 || IS_CRAFTED_STRING_BUFFER_P (op2))
11940 return build_string_concatenation (op1, op2);
11942 case MINUS_EXPR: /* 15.17.2 Additive Operators (+ and -) for
11944 if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
11946 if (!JPRIMITIVE_TYPE_P (op1_type))
11947 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
11948 if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
11949 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
11950 TREE_TYPE (node) = error_mark_node;
11954 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
11957 /* 15.18 Shift Operators */
11961 if (!JINTEGRAL_TYPE_P (op1_type) || !JINTEGRAL_TYPE_P (op2_type))
11963 if (!JINTEGRAL_TYPE_P (op1_type))
11964 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
11967 if (JPRIMITIVE_TYPE_P (op2_type))
11968 parse_error_context (wfl_operator,
11969 "Incompatible type for `%s'. Explicit cast needed to convert shift distance from `%s' to integral",
11970 operator_string (node),
11971 lang_printable_name (op2_type, 0));
11973 parse_error_context (wfl_operator,
11974 "Incompatible type for `%s'. Can't convert shift distance from `%s' to integral",
11975 operator_string (node),
11976 lang_printable_name (op2_type, 0));
11978 TREE_TYPE (node) = error_mark_node;
11983 /* Unary numeric promotion (5.6.1) is performed on each operand
11985 op1 = do_unary_numeric_promotion (op1);
11986 op2 = do_unary_numeric_promotion (op2);
11988 /* The type of the shift expression is the type of the promoted
11989 type of the left-hand operand */
11990 prom_type = TREE_TYPE (op1);
11992 /* Shift int only up to 0x1f and long up to 0x3f */
11993 if (prom_type == int_type_node)
11994 op2 = fold (build (BIT_AND_EXPR, int_type_node, op2,
11995 build_int_2 (0x1f, 0)));
11997 op2 = fold (build (BIT_AND_EXPR, int_type_node, op2,
11998 build_int_2 (0x3f, 0)));
12000 /* The >>> operator is a >> operating on unsigned quantities */
12001 if (code == URSHIFT_EXPR && ! flag_emit_class_files)
12004 tree utype = unsigned_type (prom_type);
12005 op1 = convert (utype, op1);
12006 TREE_SET_CODE (node, RSHIFT_EXPR);
12007 TREE_OPERAND (node, 0) = op1;
12008 TREE_OPERAND (node, 1) = op2;
12009 TREE_TYPE (node) = utype;
12010 to_return = convert (prom_type, node);
12011 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
12012 COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
12013 TREE_SIDE_EFFECTS (to_return)
12014 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
12019 /* 15.19.1 Type Comparison Operator instaceof */
12020 case INSTANCEOF_EXPR:
12022 TREE_TYPE (node) = boolean_type_node;
12024 if (!(op2_type = resolve_type_during_patch (op2)))
12025 return error_mark_node;
12027 /* The first operand must be a reference type or the null type */
12028 if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
12029 error_found = 1; /* Error reported further below */
12031 /* The second operand must be a reference type */
12032 if (!JREFERENCE_TYPE_P (op2_type))
12034 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
12035 parse_error_context
12036 (wfl_operator, "Invalid argument `%s' for `instanceof'",
12037 lang_printable_name (op2_type, 0));
12041 if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
12043 /* If the first operand is null, the result is always false */
12044 if (op1 == null_pointer_node)
12045 return boolean_false_node;
12046 else if (flag_emit_class_files)
12048 TREE_OPERAND (node, 1) = op2_type;
12049 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
12052 /* Otherwise we have to invoke instance of to figure it out */
12056 build (CALL_EXPR, boolean_type_node,
12057 build_address_of (soft_instanceof_node),
12060 build_tree_list (NULL_TREE,
12061 build_class_ref (op2_type))),
12063 TREE_SIDE_EFFECTS (call) = TREE_SIDE_EFFECTS (op1);
12067 /* There is no way the expression operand can be an instance of
12068 the type operand. This is a compile time error. */
12071 char *t1 = xstrdup (lang_printable_name (op1_type, 0));
12072 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
12073 parse_error_context
12074 (wfl_operator, "Impossible for `%s' to be instance of `%s'",
12075 t1, lang_printable_name (op2_type, 0));
12082 /* 15.21 Bitwise and Logical Operators */
12086 if (JINTEGRAL_TYPE_P (op1_type) && JINTEGRAL_TYPE_P (op2_type))
12087 /* Binary numeric promotion is performed on both operand and the
12088 expression retain that type */
12089 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
12091 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE
12092 && TREE_CODE (op1_type) == BOOLEAN_TYPE)
12093 /* The type of the bitwise operator expression is BOOLEAN */
12094 prom_type = boolean_type_node;
12097 if (!JINTEGRAL_TYPE_P (op1_type))
12098 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
12099 if (!JINTEGRAL_TYPE_P (op2_type) && (op1_type != op2_type))
12100 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op2_type);
12101 TREE_TYPE (node) = error_mark_node;
12103 /* Insert a break here if adding thing before the switch's
12104 break for this case */
12108 /* 15.22 Conditional-And Operator */
12109 case TRUTH_ANDIF_EXPR:
12110 /* 15.23 Conditional-Or Operator */
12111 case TRUTH_ORIF_EXPR:
12112 /* Operands must be of BOOLEAN type */
12113 if (TREE_CODE (op1_type) != BOOLEAN_TYPE ||
12114 TREE_CODE (op2_type) != BOOLEAN_TYPE)
12116 if (TREE_CODE (op1_type) != BOOLEAN_TYPE)
12117 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op1_type);
12118 if (TREE_CODE (op2_type) != BOOLEAN_TYPE && (op1_type != op2_type))
12119 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op2_type);
12120 TREE_TYPE (node) = boolean_type_node;
12124 /* The type of the conditional operators is BOOLEAN */
12125 prom_type = boolean_type_node;
12128 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
12133 /* The type of each of the operands must be a primitive numeric
12135 if (!JNUMERIC_TYPE_P (op1_type) || ! JNUMERIC_TYPE_P (op2_type))
12137 if (!JNUMERIC_TYPE_P (op1_type))
12138 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
12139 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
12140 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
12141 TREE_TYPE (node) = boolean_type_node;
12145 /* Binary numeric promotion is performed on the operands */
12146 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
12147 /* The type of the relation expression is always BOOLEAN */
12148 prom_type = boolean_type_node;
12151 /* 15.20 Equality Operator */
12154 /* 15.20.1 Numerical Equality Operators == and != */
12155 /* Binary numeric promotion is performed on the operands */
12156 if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
12157 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
12159 /* 15.20.2 Boolean Equality Operators == and != */
12160 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE &&
12161 TREE_CODE (op2_type) == BOOLEAN_TYPE)
12162 ; /* Nothing to do here */
12164 /* 15.20.3 Reference Equality Operators == and != */
12165 /* Types have to be either references or the null type. If
12166 they're references, it must be possible to convert either
12167 type to the other by casting conversion. */
12168 else if (op1 == null_pointer_node || op2 == null_pointer_node
12169 || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
12170 && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
12171 || valid_ref_assignconv_cast_p (op2_type,
12173 ; /* Nothing to do here */
12175 /* Else we have an error figure what can't be converted into
12176 what and report the error */
12180 t1 = xstrdup (lang_printable_name (op1_type, 0));
12181 parse_error_context
12183 "Incompatible type for `%s'. Can't convert `%s' to `%s'",
12184 operator_string (node), t1,
12185 lang_printable_name (op2_type, 0));
12187 TREE_TYPE (node) = boolean_type_node;
12191 prom_type = boolean_type_node;
12196 return error_mark_node;
12198 TREE_OPERAND (node, 0) = op1;
12199 TREE_OPERAND (node, 1) = op2;
12200 TREE_TYPE (node) = prom_type;
12201 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
12203 if (flag_emit_xref)
12206 /* fold does not respect side-effect order as required for Java but not C.
12207 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
12210 if (flag_emit_class_files ? (TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
12211 : ! TREE_SIDE_EFFECTS (node))
12212 node = fold (node);
12216 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
12217 zero value, the value of CSTE comes after the valude of STRING */
12220 do_merge_string_cste (cste, string, string_len, after)
12222 const char *string;
12223 int string_len, after;
12225 int len = TREE_STRING_LENGTH (cste) + string_len;
12226 const char *old = TREE_STRING_POINTER (cste);
12227 TREE_STRING_LENGTH (cste) = len;
12228 TREE_STRING_POINTER (cste) = obstack_alloc (expression_obstack, len+1);
12231 strcpy (TREE_STRING_POINTER (cste), string);
12232 strcat (TREE_STRING_POINTER (cste), old);
12236 strcpy (TREE_STRING_POINTER (cste), old);
12237 strcat (TREE_STRING_POINTER (cste), string);
12242 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
12243 new STRING_CST on success, NULL_TREE on failure */
12246 merge_string_cste (op1, op2, after)
12250 /* Handle two string constants right away */
12251 if (TREE_CODE (op2) == STRING_CST)
12252 return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
12253 TREE_STRING_LENGTH (op2), after);
12255 /* Reasonable integer constant can be treated right away */
12256 if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
12258 static const char *boolean_true = "true";
12259 static const char *boolean_false = "false";
12260 static const char *null_pointer = "null";
12262 const char *string;
12264 if (op2 == boolean_true_node)
12265 string = boolean_true;
12266 else if (op2 == boolean_false_node)
12267 string = boolean_false;
12268 else if (op2 == null_pointer_node)
12269 string = null_pointer;
12270 else if (TREE_TYPE (op2) == char_type_node)
12272 ch[0] = (char )TREE_INT_CST_LOW (op2);
12277 string = print_int_node (op2);
12279 return do_merge_string_cste (op1, string, strlen (string), after);
12284 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
12285 has to be a STRING_CST and the other part must be a STRING_CST or a
12286 INTEGRAL constant. Return a new STRING_CST if the operation
12287 succeed, NULL_TREE otherwise.
12289 If the case we want to optimize for space, we might want to return
12290 NULL_TREE for each invocation of this routine. FIXME */
12293 string_constant_concatenation (op1, op2)
12296 if (TREE_CODE (op1) == STRING_CST || (TREE_CODE (op2) == STRING_CST))
12301 string = (TREE_CODE (op1) == STRING_CST ? op1 : op2);
12302 rest = (string == op1 ? op2 : op1);
12303 invert = (string == op1 ? 0 : 1 );
12305 /* Walk REST, only if it looks reasonable */
12306 if (TREE_CODE (rest) != STRING_CST
12307 && !IS_CRAFTED_STRING_BUFFER_P (rest)
12308 && !JSTRING_TYPE_P (TREE_TYPE (rest))
12309 && TREE_CODE (rest) == EXPR_WITH_FILE_LOCATION)
12311 rest = java_complete_tree (rest);
12312 if (rest == error_mark_node)
12313 return error_mark_node;
12314 rest = fold (rest);
12316 return merge_string_cste (string, rest, invert);
12321 /* Implement the `+' operator. Does static optimization if possible,
12322 otherwise create (if necessary) and append elements to a
12323 StringBuffer. The StringBuffer will be carried around until it is
12324 used for a function call or an assignment. Then toString() will be
12325 called on it to turn it into a String object. */
12328 build_string_concatenation (op1, op2)
12332 int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
12334 if (flag_emit_xref)
12335 return build (PLUS_EXPR, string_type_node, op1, op2);
12337 /* Try to do some static optimization */
12338 if ((result = string_constant_concatenation (op1, op2)))
12341 /* Discard empty strings on either side of the expression */
12342 if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
12347 else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
12350 /* If operands are string constant, turn then into object references */
12351 if (TREE_CODE (op1) == STRING_CST)
12352 op1 = patch_string_cst (op1);
12353 if (op2 && TREE_CODE (op2) == STRING_CST)
12354 op2 = patch_string_cst (op2);
12356 /* If either one of the constant is null and the other non null
12357 operand is a String object, return it. */
12358 if (JSTRING_TYPE_P (TREE_TYPE (op1)) && !op2)
12361 /* If OP1 isn't already a StringBuffer, create and
12362 initialize a new one */
12363 if (!IS_CRAFTED_STRING_BUFFER_P (op1))
12365 /* Two solutions here:
12366 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
12367 2) OP1 is something else, we call new StringBuffer().append(OP1). */
12368 if (TREE_CONSTANT (op1) && JSTRING_TYPE_P (TREE_TYPE (op1)))
12369 op1 = BUILD_STRING_BUFFER (op1);
12372 tree aNew = BUILD_STRING_BUFFER (NULL_TREE);
12373 op1 = make_qualified_primary (aNew, BUILD_APPEND (op1), 0);
12379 /* OP1 is no longer the last node holding a crafted StringBuffer */
12380 IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
12381 /* Create a node for `{new...,xxx}.append (op2)' */
12383 op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
12386 /* Mark the last node holding a crafted StringBuffer */
12387 IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
12389 TREE_SIDE_EFFECTS (op1) = side_effects;
12393 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
12394 StringBuffer. If no string were found to be patched, return
12398 patch_string (node)
12401 if (node == error_mark_node)
12402 return error_mark_node;
12403 if (TREE_CODE (node) == STRING_CST)
12404 return patch_string_cst (node);
12405 else if (IS_CRAFTED_STRING_BUFFER_P (node))
12407 int saved = ctxp->explicit_constructor_p;
12408 tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
12410 /* Temporary disable forbid the use of `this'. */
12411 ctxp->explicit_constructor_p = 0;
12412 ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
12413 /* String concatenation arguments must be evaluated in order too. */
12414 ret = force_evaluation_order (ret);
12415 /* Restore it at its previous value */
12416 ctxp->explicit_constructor_p = saved;
12422 /* Build the internal representation of a string constant. */
12425 patch_string_cst (node)
12429 if (! flag_emit_class_files)
12431 push_obstacks (&permanent_obstack, &permanent_obstack);
12432 node = get_identifier (TREE_STRING_POINTER (node));
12433 location = alloc_name_constant (CONSTANT_String, node);
12434 node = build_ref_from_constant_pool (location);
12437 TREE_TYPE (node) = string_ptr_type_node;
12438 TREE_CONSTANT (node) = 1;
12442 /* Build an incomplete unary operator expression. */
12445 build_unaryop (op_token, op_location, op1)
12446 int op_token, op_location;
12453 case PLUS_TK: op = UNARY_PLUS_EXPR; break;
12454 case MINUS_TK: op = NEGATE_EXPR; break;
12455 case NEG_TK: op = TRUTH_NOT_EXPR; break;
12456 case NOT_TK: op = BIT_NOT_EXPR; break;
12457 default: fatal ("Unknown token `%d' for unary operator - build_unaryop",
12461 unaryop = build1 (op, NULL_TREE, op1);
12462 TREE_SIDE_EFFECTS (unaryop) = 1;
12463 /* Store the location of the operator, for better error report. The
12464 string of the operator will be rebuild based on the OP value. */
12465 EXPR_WFL_LINECOL (unaryop) = op_location;
12469 /* Special case for the ++/-- operators, since they require an extra
12470 argument to build, which is set to NULL and patched
12471 later. IS_POST_P is 1 if the operator, 0 otherwise. */
12474 build_incdec (op_token, op_location, op1, is_post_p)
12475 int op_token, op_location;
12479 static enum tree_code lookup [2][2] =
12481 { PREDECREMENT_EXPR, PREINCREMENT_EXPR, },
12482 { POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, },
12484 tree node = build (lookup [is_post_p][(op_token - DECR_TK)],
12485 NULL_TREE, op1, NULL_TREE);
12486 TREE_SIDE_EFFECTS (node) = 1;
12487 /* Store the location of the operator, for better error report. The
12488 string of the operator will be rebuild based on the OP value. */
12489 EXPR_WFL_LINECOL (node) = op_location;
12493 /* Build an incomplete cast operator, based on the use of the
12494 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
12495 set. java_complete_tree is trained to walk a CONVERT_EXPR even
12496 though its type is already set. */
12499 build_cast (location, type, exp)
12503 tree node = build1 (CONVERT_EXPR, type, exp);
12504 EXPR_WFL_LINECOL (node) = location;
12508 /* Build an incomplete class reference operator. */
12510 build_incomplete_class_ref (location, class_name)
12514 tree node = build1 (CLASS_LITERAL, NULL_TREE, class_name);
12515 EXPR_WFL_LINECOL (node) = location;
12519 /* Complete an incomplete class reference operator. */
12521 patch_incomplete_class_ref (node)
12524 tree type = TREE_OPERAND (node, 0);
12527 if (!(ref_type = resolve_type_during_patch (type)))
12528 return error_mark_node;
12530 return build_class_ref (ref_type);
12533 /* 15.14 Unary operators. We return error_mark_node in case of error,
12534 but preserve the type of NODE if the type is fixed. */
12537 patch_unaryop (node, wfl_op)
12541 tree op = TREE_OPERAND (node, 0);
12542 tree op_type = TREE_TYPE (op);
12543 tree prom_type = NULL_TREE, value, decl;
12544 int outer_field_flag = 0;
12545 int code = TREE_CODE (node);
12546 int error_found = 0;
12548 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12552 /* 15.13.2 Postfix Increment Operator ++ */
12553 case POSTINCREMENT_EXPR:
12554 /* 15.13.3 Postfix Increment Operator -- */
12555 case POSTDECREMENT_EXPR:
12556 /* 15.14.1 Prefix Increment Operator ++ */
12557 case PREINCREMENT_EXPR:
12558 /* 15.14.2 Prefix Decrement Operator -- */
12559 case PREDECREMENT_EXPR:
12560 op = decl = strip_out_static_field_access_decl (op);
12561 outer_field_flag = outer_field_expanded_access_p (op, NULL, NULL, NULL);
12562 /* We might be trying to change an outer field accessed using
12564 if (outer_field_flag)
12566 /* Retrieve the decl of the field we're trying to access. We
12567 do that by first retrieving the function we would call to
12568 access the field. It has been already verified that this
12569 field isn't final */
12570 if (flag_emit_class_files)
12571 decl = TREE_OPERAND (op, 0);
12573 decl = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (op, 0), 0), 0);
12574 decl = DECL_FUNCTION_ACCESS_DECL (decl);
12576 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
12577 else if (!JDECL_P (decl)
12578 && TREE_CODE (decl) != COMPONENT_REF
12579 && !(flag_emit_class_files && TREE_CODE (decl) == ARRAY_REF)
12580 && TREE_CODE (decl) != INDIRECT_REF
12581 && !(TREE_CODE (decl) == COMPOUND_EXPR
12582 && TREE_OPERAND (decl, 1)
12583 && (TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)))
12586 /* Before screaming, check that we're not in fact trying to
12587 increment a optimized static final access, in which case
12588 we issue an different error message. */
12589 if (!(TREE_CODE (wfl_op) == EXPR_WITH_FILE_LOCATION
12590 && resolve_expression_name (wfl_op, &lvalue)
12591 && check_final_assignment (lvalue, wfl_op)))
12592 parse_error_context (wfl_operator, "Invalid argument to `%s'",
12593 operator_string (node));
12594 TREE_TYPE (node) = error_mark_node;
12598 if (check_final_assignment (op, wfl_op))
12601 /* From now on, we know that op if a variable and that it has a
12602 valid wfl. We use wfl_op to locate errors related to the
12604 else if (!JNUMERIC_TYPE_P (op_type))
12606 parse_error_context
12607 (wfl_op, "Invalid argument type `%s' to `%s'",
12608 lang_printable_name (op_type, 0), operator_string (node));
12609 TREE_TYPE (node) = error_mark_node;
12614 /* Before the addition, binary numeric promotion is performed on
12615 both operands, if really necessary */
12616 if (JINTEGRAL_TYPE_P (op_type))
12618 value = build_int_2 (1, 0);
12619 TREE_TYPE (value) = TREE_TYPE (node) = op_type;
12623 value = build_int_2 (1, 0);
12625 binary_numeric_promotion (op_type,
12626 TREE_TYPE (value), &op, &value);
12629 /* We remember we might be accessing an outer field */
12630 if (outer_field_flag)
12632 /* We re-generate an access to the field */
12633 value = build (PLUS_EXPR, TREE_TYPE (op),
12634 build_outer_field_access (wfl_op, decl), value);
12636 /* And we patch the original access$() into a write
12637 with plus_op as a rhs */
12638 return outer_field_access_fix (node, op, value);
12641 /* And write back into the node. */
12642 TREE_OPERAND (node, 0) = op;
12643 TREE_OPERAND (node, 1) = value;
12644 /* Convert the overall back into its original type, if
12645 necessary, and return */
12646 if (JINTEGRAL_TYPE_P (op_type))
12647 return fold (node);
12649 return fold (convert (op_type, node));
12653 /* 15.14.3 Unary Plus Operator + */
12654 case UNARY_PLUS_EXPR:
12655 /* 15.14.4 Unary Minus Operator - */
12657 if (!JNUMERIC_TYPE_P (op_type))
12659 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op_type);
12660 TREE_TYPE (node) = error_mark_node;
12663 /* Unary numeric promotion is performed on operand */
12666 op = do_unary_numeric_promotion (op);
12667 prom_type = TREE_TYPE (op);
12668 if (code == UNARY_PLUS_EXPR)
12673 /* 15.14.5 Bitwise Complement Operator ~ */
12675 if (!JINTEGRAL_TYPE_P (op_type))
12677 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op_type);
12678 TREE_TYPE (node) = error_mark_node;
12683 op = do_unary_numeric_promotion (op);
12684 prom_type = TREE_TYPE (op);
12688 /* 15.14.6 Logical Complement Operator ! */
12689 case TRUTH_NOT_EXPR:
12690 if (TREE_CODE (op_type) != BOOLEAN_TYPE)
12692 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
12693 /* But the type is known. We will report an error if further
12694 attempt of a assignment is made with this rhs */
12695 TREE_TYPE (node) = boolean_type_node;
12699 prom_type = boolean_type_node;
12702 /* 15.15 Cast Expression */
12704 value = patch_cast (node, wfl_operator);
12705 if (value == error_mark_node)
12707 /* If this cast is part of an assignment, we tell the code
12708 that deals with it not to complain about a mismatch,
12709 because things have been cast, anyways */
12710 TREE_TYPE (node) = error_mark_node;
12715 value = fold (value);
12716 TREE_SIDE_EFFECTS (value) = TREE_SIDE_EFFECTS (op);
12723 return error_mark_node;
12725 /* There are cases where node has been replaced by something else
12726 and we don't end up returning here: UNARY_PLUS_EXPR,
12727 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
12728 TREE_OPERAND (node, 0) = fold (op);
12729 TREE_TYPE (node) = prom_type;
12730 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
12731 return fold (node);
12734 /* Generic type resolution that sometimes takes place during node
12735 patching. Returned the resolved type or generate an error
12736 message. Return the resolved type or NULL_TREE. */
12739 resolve_type_during_patch (type)
12742 if (unresolved_type_p (type, NULL))
12744 tree type_decl = resolve_no_layout (EXPR_WFL_NODE (type), NULL_TREE);
12747 parse_error_context (type,
12748 "Class `%s' not found in type declaration",
12749 IDENTIFIER_POINTER (EXPR_WFL_NODE (type)));
12754 CLASS_LOADED_P (TREE_TYPE (type_decl)) = 1;
12755 return TREE_TYPE (type_decl);
12760 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
12761 found. Otherwise NODE or something meant to replace it is returned. */
12764 patch_cast (node, wfl_operator)
12768 tree op = TREE_OPERAND (node, 0);
12769 tree op_type = TREE_TYPE (op);
12770 tree cast_type = TREE_TYPE (node);
12773 /* First resolve OP_TYPE if unresolved */
12774 if (!(cast_type = resolve_type_during_patch (cast_type)))
12775 return error_mark_node;
12777 /* Check on cast that are proven correct at compile time */
12778 if (JNUMERIC_TYPE_P (cast_type) && JNUMERIC_TYPE_P (op_type))
12781 if (cast_type == op_type)
12784 /* float and double type are converted to the original type main
12785 variant and then to the target type. */
12786 if (JFLOAT_TYPE_P (op_type) && TREE_CODE (cast_type) == CHAR_TYPE)
12787 op = convert (integer_type_node, op);
12789 /* Try widening/narowwing convertion. Potentially, things need
12790 to be worked out in gcc so we implement the extreme cases
12791 correctly. fold_convert() needs to be fixed. */
12792 return convert (cast_type, op);
12795 /* It's also valid to cast a boolean into a boolean */
12796 if (op_type == boolean_type_node && cast_type == boolean_type_node)
12799 /* null can be casted to references */
12800 if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
12801 return build_null_of_type (cast_type);
12803 /* The remaining legal casts involve conversion between reference
12804 types. Check for their compile time correctness. */
12805 if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type)
12806 && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
12808 TREE_TYPE (node) = promote_type (cast_type);
12809 /* Now, the case can be determined correct at compile time if
12810 OP_TYPE can be converted into CAST_TYPE by assignment
12811 conversion (5.2) */
12813 if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
12815 TREE_SET_CODE (node, NOP_EXPR);
12819 if (flag_emit_class_files)
12821 TREE_SET_CODE (node, CONVERT_EXPR);
12825 /* The cast requires a run-time check */
12826 return build (CALL_EXPR, promote_type (cast_type),
12827 build_address_of (soft_checkcast_node),
12828 tree_cons (NULL_TREE, build_class_ref (cast_type),
12829 build_tree_list (NULL_TREE, op)),
12833 /* Any other casts are proven incorrect at compile time */
12834 t1 = xstrdup (lang_printable_name (op_type, 0));
12835 parse_error_context (wfl_operator, "Invalid cast from `%s' to `%s'",
12836 t1, lang_printable_name (cast_type, 0));
12838 return error_mark_node;
12841 /* Build a null constant and give it the type TYPE. */
12844 build_null_of_type (type)
12847 tree node = build_int_2 (0, 0);
12848 TREE_TYPE (node) = promote_type (type);
12852 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
12853 a list of indices. */
12855 build_array_ref (location, array, index)
12859 tree node = build (ARRAY_REF, NULL_TREE, array, index);
12860 EXPR_WFL_LINECOL (node) = location;
12864 /* 15.12 Array Access Expression */
12867 patch_array_ref (node)
12870 tree array = TREE_OPERAND (node, 0);
12871 tree array_type = TREE_TYPE (array);
12872 tree index = TREE_OPERAND (node, 1);
12873 tree index_type = TREE_TYPE (index);
12874 int error_found = 0;
12876 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
12878 if (TREE_CODE (array_type) == POINTER_TYPE)
12879 array_type = TREE_TYPE (array_type);
12881 /* The array reference must be an array */
12882 if (!TYPE_ARRAY_P (array_type))
12884 parse_error_context
12886 "`[]' can only be applied to arrays. It can't be applied to `%s'",
12887 lang_printable_name (array_type, 0));
12888 TREE_TYPE (node) = error_mark_node;
12892 /* The array index undergoes unary numeric promotion. The promoted
12893 type must be int */
12894 index = do_unary_numeric_promotion (index);
12895 if (TREE_TYPE (index) != int_type_node)
12897 if (valid_cast_to_p (index_type, int_type_node))
12898 parse_error_context (wfl_operator,
12899 "Incompatible type for `[]'. Explicit cast needed to convert `%s' to `int'",
12900 lang_printable_name (index_type, 0));
12902 parse_error_context (wfl_operator,
12903 "Incompatible type for `[]'. Can't convert `%s' to `int'",
12904 lang_printable_name (index_type, 0));
12905 TREE_TYPE (node) = error_mark_node;
12910 return error_mark_node;
12912 array_type = TYPE_ARRAY_ELEMENT (array_type);
12914 if (flag_emit_class_files || flag_emit_xref)
12916 TREE_OPERAND (node, 0) = array;
12917 TREE_OPERAND (node, 1) = index;
12921 /* The save_expr is for correct evaluation order. It would be cleaner
12922 to use force_evaluation_order (see comment there), but that is
12923 difficult when we also have to deal with bounds checking. */
12924 if (TREE_SIDE_EFFECTS (index))
12925 array = save_expr (array);
12926 node = build_java_arrayaccess (array, array_type, index);
12927 if (TREE_SIDE_EFFECTS (index))
12928 node = build (COMPOUND_EXPR, array_type, array, node);
12930 TREE_TYPE (node) = array_type;
12934 /* 15.9 Array Creation Expressions */
12937 build_newarray_node (type, dims, extra_dims)
12943 build (NEW_ARRAY_EXPR, NULL_TREE, type, nreverse (dims),
12944 build_int_2 (extra_dims, 0));
12949 patch_newarray (node)
12952 tree type = TREE_OPERAND (node, 0);
12953 tree dims = TREE_OPERAND (node, 1);
12954 tree cdim, array_type;
12955 int error_found = 0;
12957 int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
12959 /* Dimension types are verified. It's better for the types to be
12960 verified in order. */
12961 for (cdim = dims, ndims = 0; cdim; cdim = TREE_CHAIN (cdim), ndims++ )
12964 tree dim = TREE_VALUE (cdim);
12966 /* Dim might have been saved during its evaluation */
12967 dim = (TREE_CODE (dim) == SAVE_EXPR ? dim = TREE_OPERAND (dim, 0) : dim);
12969 /* The type of each specified dimension must be an integral type. */
12970 if (!JINTEGRAL_TYPE_P (TREE_TYPE (dim)))
12973 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
12974 promoted type must be int. */
12977 dim = do_unary_numeric_promotion (dim);
12978 if (TREE_TYPE (dim) != int_type_node)
12982 /* Report errors on types here */
12985 parse_error_context
12986 (TREE_PURPOSE (cdim),
12987 "Incompatible type for dimension in array creation expression. %s convert `%s' to `int'",
12988 (valid_cast_to_p (TREE_TYPE (dim), int_type_node) ?
12989 "Explicit cast needed to" : "Can't"),
12990 lang_printable_name (TREE_TYPE (dim), 0));
12994 TREE_PURPOSE (cdim) = NULL_TREE;
12997 /* Resolve array base type if unresolved */
12998 if (!(type = resolve_type_during_patch (type)))
13003 /* We don't want further evaluation of this bogus array creation
13005 TREE_TYPE (node) = error_mark_node;
13006 return error_mark_node;
13009 /* Set array_type to the actual (promoted) array type of the result. */
13010 if (TREE_CODE (type) == RECORD_TYPE)
13011 type = build_pointer_type (type);
13012 while (--xdims >= 0)
13014 type = promote_type (build_java_array_type (type, -1));
13016 dims = nreverse (dims);
13018 for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
13022 = build_java_array_type (type,
13023 TREE_CODE (cdim) == INTEGER_CST
13024 ? (HOST_WIDE_INT) TREE_INT_CST_LOW (cdim)
13026 array_type = promote_type (array_type);
13028 dims = nreverse (dims);
13030 /* The node is transformed into a function call. Things are done
13031 differently according to the number of dimensions. If the number
13032 of dimension is equal to 1, then the nature of the base type
13033 (primitive or not) matters. */
13035 return build_new_array (type, TREE_VALUE (dims));
13037 /* Can't reuse what's already written in expr.c because it uses the
13038 JVM stack representation. Provide a build_multianewarray. FIXME */
13039 return build (CALL_EXPR, array_type,
13040 build_address_of (soft_multianewarray_node),
13041 tree_cons (NULL_TREE, build_class_ref (TREE_TYPE (array_type)),
13042 tree_cons (NULL_TREE,
13043 build_int_2 (ndims, 0), dims )),
13047 /* 10.6 Array initializer. */
13049 /* Build a wfl for array element that don't have one, so we can
13050 pin-point errors. */
13053 maybe_build_array_element_wfl (node)
13056 if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
13057 return build_expr_wfl (NULL_TREE, ctxp->filename,
13058 ctxp->elc.line, ctxp->elc.prev_col);
13063 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
13064 identification of initialized arrays easier to detect during walk
13068 build_new_array_init (location, values)
13072 tree constructor = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, values);
13073 tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
13074 EXPR_WFL_LINECOL (to_return) = location;
13078 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
13079 occurred. Otherwise return NODE after having set its type
13083 patch_new_array_init (type, node)
13086 int error_seen = 0;
13087 tree current, element_type;
13088 HOST_WIDE_INT length;
13089 int all_constant = 1;
13090 tree init = TREE_OPERAND (node, 0);
13092 if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
13094 parse_error_context (node,
13095 "Invalid array initializer for non-array type `%s'",
13096 lang_printable_name (type, 1));
13097 return error_mark_node;
13099 type = TREE_TYPE (type);
13100 element_type = TYPE_ARRAY_ELEMENT (type);
13102 CONSTRUCTOR_ELTS (init) = nreverse (CONSTRUCTOR_ELTS (init));
13104 for (length = 0, current = CONSTRUCTOR_ELTS (init);
13105 current; length++, current = TREE_CHAIN (current))
13107 tree elt = TREE_VALUE (current);
13108 if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
13110 error_seen |= array_constructor_check_entry (element_type, current);
13111 elt = TREE_VALUE (current);
13112 /* When compiling to native code, STRING_CST is converted to
13113 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
13114 if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
13119 TREE_VALUE (current) = patch_new_array_init (element_type, elt);
13120 TREE_PURPOSE (current) = NULL_TREE;
13123 if (elt && TREE_VALUE (elt) == error_mark_node)
13128 return error_mark_node;
13130 /* Create a new type. We can't reuse the one we have here by
13131 patching its dimension because it originally is of dimension -1
13132 hence reused by gcc. This would prevent triangular arrays. */
13133 type = build_java_array_type (element_type, length);
13134 TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
13135 TREE_TYPE (node) = promote_type (type);
13136 TREE_CONSTANT (init) = all_constant;
13137 TREE_CONSTANT (node) = all_constant;
13141 /* Verify that one entry of the initializer element list can be
13142 assigned to the array base type. Report 1 if an error occurred, 0
13146 array_constructor_check_entry (type, entry)
13149 char *array_type_string = NULL; /* For error reports */
13150 tree value, type_value, new_value, wfl_value, patched;
13151 int error_seen = 0;
13153 new_value = NULL_TREE;
13154 wfl_value = TREE_VALUE (entry);
13156 push_obstacks (&permanent_obstack, &permanent_obstack);
13157 value = java_complete_tree (TREE_VALUE (entry));
13158 /* patch_string return error_mark_node if arg is error_mark_node */
13159 if ((patched = patch_string (value)))
13161 if (value == error_mark_node)
13164 type_value = TREE_TYPE (value);
13166 /* At anytime, try_builtin_assignconv can report a warning on
13167 constant overflow during narrowing. */
13168 SET_WFL_OPERATOR (wfl_operator, TREE_PURPOSE (entry), wfl_value);
13169 new_value = try_builtin_assignconv (wfl_operator, type, value);
13170 if (!new_value && (new_value = try_reference_assignconv (type, value)))
13171 type_value = promote_type (type);
13174 /* Check and report errors */
13177 const char *msg = (!valid_cast_to_p (type_value, type) ?
13178 "Can't" : "Explicit cast needed to");
13179 if (!array_type_string)
13180 array_type_string = xstrdup (lang_printable_name (type, 1));
13181 parse_error_context
13182 (wfl_operator, "Incompatible type for array. %s convert `%s' to `%s'",
13183 msg, lang_printable_name (type_value, 1), array_type_string);
13189 new_value = maybe_build_primttype_type_ref (new_value, wfl_operator);
13190 TREE_VALUE (entry) = new_value;
13193 if (array_type_string)
13194 free (array_type_string);
13196 TREE_PURPOSE (entry) = NULL_TREE;
13201 build_this (location)
13204 tree node = build_wfl_node (this_identifier_node);
13205 TREE_SET_CODE (node, THIS_EXPR);
13206 EXPR_WFL_LINECOL (node) = location;
13210 /* 14.15 The return statement. It builds a modify expression that
13211 assigns the returned value to the RESULT_DECL that hold the value
13215 build_return (location, op)
13219 tree node = build1 (RETURN_EXPR, NULL_TREE, op);
13220 EXPR_WFL_LINECOL (node) = location;
13221 node = build_debugable_stmt (location, node);
13226 patch_return (node)
13229 tree return_exp = TREE_OPERAND (node, 0);
13230 tree meth = current_function_decl;
13231 tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
13232 int error_found = 0;
13234 TREE_TYPE (node) = error_mark_node;
13235 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13237 /* It's invalid to have a return value within a function that is
13238 declared with the keyword void or that is a constructor */
13239 if (return_exp && (mtype == void_type_node || DECL_CONSTRUCTOR_P (meth)))
13242 /* It's invalid to use a return statement in a static block */
13243 if (DECL_CLINIT_P (current_function_decl))
13246 /* It's invalid to have a no return value within a function that
13247 isn't declared with the keyword `void' */
13248 if (!return_exp && (mtype != void_type_node && !DECL_CONSTRUCTOR_P (meth)))
13251 if (in_instance_initializer)
13256 if (in_instance_initializer)
13257 parse_error_context (wfl_operator,
13258 "`return' inside instance initializer");
13260 else if (DECL_CLINIT_P (current_function_decl))
13261 parse_error_context (wfl_operator,
13262 "`return' inside static initializer");
13264 else if (!DECL_CONSTRUCTOR_P (meth))
13266 char *t = xstrdup (lang_printable_name (mtype, 0));
13267 parse_error_context (wfl_operator,
13268 "`return' with%s value from `%s %s'",
13269 (error_found == 1 ? "" : "out"),
13270 t, lang_printable_name (meth, 0));
13274 parse_error_context (wfl_operator,
13275 "`return' with value from constructor `%s'",
13276 lang_printable_name (meth, 0));
13277 return error_mark_node;
13280 /* If we have a return_exp, build a modify expression and expand
13281 it. Note: at that point, the assignment is declared valid, but we
13282 may want to carry some more hacks */
13285 tree exp = java_complete_tree (return_exp);
13286 tree modify, patched;
13288 /* If the function returned value and EXP are booleans, EXP has
13289 to be converted into the type of DECL_RESULT, which is integer
13290 (see complete_start_java_method) */
13291 if (TREE_TYPE (exp) == boolean_type_node &&
13292 TREE_TYPE (TREE_TYPE (meth)) == boolean_type_node)
13293 exp = convert_to_integer (TREE_TYPE (DECL_RESULT (meth)), exp);
13295 /* `null' can be assigned to a function returning a reference */
13296 if (JREFERENCE_TYPE_P (TREE_TYPE (TREE_TYPE (meth))) &&
13297 exp == null_pointer_node)
13298 exp = build_null_of_type (TREE_TYPE (TREE_TYPE (meth)));
13300 if ((patched = patch_string (exp)))
13303 modify = build (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
13304 EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
13305 modify = java_complete_tree (modify);
13307 if (modify != error_mark_node)
13309 TREE_SIDE_EFFECTS (modify) = 1;
13310 TREE_OPERAND (node, 0) = modify;
13313 return error_mark_node;
13315 TREE_TYPE (node) = void_type_node;
13316 TREE_SIDE_EFFECTS (node) = 1;
13320 /* 14.8 The if Statement */
13323 build_if_else_statement (location, expression, if_body, else_body)
13325 tree expression, if_body, else_body;
13329 else_body = empty_stmt_node;
13330 node = build (COND_EXPR, NULL_TREE, expression, if_body, else_body);
13331 EXPR_WFL_LINECOL (node) = location;
13332 node = build_debugable_stmt (location, node);
13337 patch_if_else_statement (node)
13340 tree expression = TREE_OPERAND (node, 0);
13342 TREE_TYPE (node) = error_mark_node;
13343 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13345 /* The type of expression must be boolean */
13346 if (TREE_TYPE (expression) != boolean_type_node
13347 && TREE_TYPE (expression) != promoted_boolean_type_node)
13349 parse_error_context
13351 "Incompatible type for `if'. Can't convert `%s' to `boolean'",
13352 lang_printable_name (TREE_TYPE (expression), 0));
13353 return error_mark_node;
13356 TREE_TYPE (node) = void_type_node;
13357 TREE_SIDE_EFFECTS (node) = 1;
13358 CAN_COMPLETE_NORMALLY (node)
13359 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
13360 | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2));
13364 /* 14.6 Labeled Statements */
13366 /* Action taken when a lableled statement is parsed. a new
13367 LABELED_BLOCK_EXPR is created. No statement is attached to the
13368 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
13371 build_labeled_block (location, label)
13376 tree label_decl, node;
13377 if (label == NULL_TREE || label == continue_identifier_node)
13378 label_name = label;
13381 label_name = merge_qualified_name (label_id, label);
13382 /* Issue an error if we try to reuse a label that was previously
13384 if (IDENTIFIER_LOCAL_VALUE (label_name))
13386 EXPR_WFL_LINECOL (wfl_operator) = location;
13387 parse_error_context (wfl_operator,
13388 "Declaration of `%s' shadows a previous label declaration",
13389 IDENTIFIER_POINTER (label));
13390 EXPR_WFL_LINECOL (wfl_operator) =
13391 EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
13392 parse_error_context (wfl_operator,
13393 "This is the location of the previous declaration of label `%s'",
13394 IDENTIFIER_POINTER (label));
13395 java_error_count--;
13399 label_decl = create_label_decl (label_name);
13400 node = build (LABELED_BLOCK_EXPR, NULL_TREE, label_decl, NULL_TREE);
13401 EXPR_WFL_LINECOL (node) = location;
13402 TREE_SIDE_EFFECTS (node) = 1;
13406 /* A labeled statement LBE is attached a statement. */
13409 finish_labeled_statement (lbe, statement)
13410 tree lbe; /* Labeled block expr */
13413 /* In anyways, tie the loop to its statement */
13414 LABELED_BLOCK_BODY (lbe) = statement;
13415 pop_labeled_block ();
13416 POP_LABELED_BLOCK ();
13420 /* 14.10, 14.11, 14.12 Loop Statements */
13422 /* Create an empty LOOP_EXPR and make it the last in the nested loop
13426 build_new_loop (loop_body)
13429 tree loop = build (LOOP_EXPR, NULL_TREE, loop_body);
13430 TREE_SIDE_EFFECTS (loop) = 1;
13435 /* Create a loop body according to the following structure:
13437 COMPOUND_EXPR (loop main body)
13438 EXIT_EXPR (this order is for while/for loops.
13439 LABELED_BLOCK_EXPR the order is reversed for do loops)
13440 LABEL_DECL (a continue occuring here branches at the
13441 BODY end of this labeled block)
13444 REVERSED, if non zero, tells that the loop condition expr comes
13445 after the body, like in the do-while loop.
13447 To obtain a loop, the loop body structure described above is
13448 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
13451 LABEL_DECL (use this label to exit the loop)
13453 <structure described above> */
13456 build_loop_body (location, condition, reversed)
13461 tree first, second, body;
13463 condition = build (EXIT_EXPR, NULL_TREE, condition); /* Force walk */
13464 EXPR_WFL_LINECOL (condition) = location; /* For accurate error report */
13465 condition = build_debugable_stmt (location, condition);
13466 TREE_SIDE_EFFECTS (condition) = 1;
13468 body = build_labeled_block (0, continue_identifier_node);
13469 first = (reversed ? body : condition);
13470 second = (reversed ? condition : body);
13472 build (COMPOUND_EXPR, NULL_TREE,
13473 build (COMPOUND_EXPR, NULL_TREE, first, second), empty_stmt_node);
13476 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
13477 their order) on the current loop. Unlink the current loop from the
13481 finish_loop_body (location, condition, body, reversed)
13483 tree condition, body;
13486 tree to_return = ctxp->current_loop;
13487 tree loop_body = LOOP_EXPR_BODY (to_return);
13490 tree cnode = LOOP_EXPR_BODY_CONDITION_EXPR (loop_body, reversed);
13491 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
13492 The real EXIT_EXPR is one operand further. */
13493 EXPR_WFL_LINECOL (cnode) = location;
13494 /* This one is for accurate error reports */
13495 EXPR_WFL_LINECOL (TREE_OPERAND (cnode, 0)) = location;
13496 TREE_OPERAND (TREE_OPERAND (cnode, 0), 0) = condition;
13498 LOOP_EXPR_BODY_BODY_EXPR (loop_body, reversed) = body;
13503 /* Tailored version of finish_loop_body for FOR loops, when FOR
13504 loops feature the condition part */
13507 finish_for_loop (location, condition, update, body)
13509 tree condition, update, body;
13511 /* Put the condition and the loop body in place */
13512 tree loop = finish_loop_body (location, condition, body, 0);
13513 /* LOOP is the current loop which has been now popped of the loop
13514 stack. Install the update block */
13515 LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
13519 /* Try to find the loop a block might be related to. This comprises
13520 the case where the LOOP_EXPR is found as the second operand of a
13521 COMPOUND_EXPR, because the loop happens to have an initialization
13522 part, then expressed as the first operand of the COMPOUND_EXPR. If
13523 the search finds something, 1 is returned. Otherwise, 0 is
13524 returned. The search is assumed to start from a
13525 LABELED_BLOCK_EXPR's block. */
13528 search_loop (statement)
13531 if (TREE_CODE (statement) == LOOP_EXPR)
13534 if (TREE_CODE (statement) == BLOCK)
13535 statement = BLOCK_SUBBLOCKS (statement);
13539 if (statement && TREE_CODE (statement) == COMPOUND_EXPR)
13540 while (statement && TREE_CODE (statement) == COMPOUND_EXPR)
13541 statement = TREE_OPERAND (statement, 1);
13543 return (TREE_CODE (statement) == LOOP_EXPR
13544 && FOR_LOOP_P (statement) ? statement : NULL_TREE);
13547 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
13548 returned otherwise. */
13551 labeled_block_contains_loop_p (block, loop)
13557 if (LABELED_BLOCK_BODY (block) == loop)
13560 if (FOR_LOOP_P (loop) && search_loop (LABELED_BLOCK_BODY (block)) == loop)
13566 /* If the loop isn't surrounded by a labeled statement, create one and
13567 insert LOOP as its body. */
13570 patch_loop_statement (loop)
13575 TREE_TYPE (loop) = void_type_node;
13576 if (labeled_block_contains_loop_p (ctxp->current_labeled_block, loop))
13579 loop_label = build_labeled_block (0, NULL_TREE);
13580 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
13581 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
13582 LABELED_BLOCK_BODY (loop_label) = loop;
13583 PUSH_LABELED_BLOCK (loop_label);
13587 /* 14.13, 14.14: break and continue Statements */
13589 /* Build a break or a continue statement. a null NAME indicates an
13590 unlabeled break/continue statement. */
13593 build_bc_statement (location, is_break, name)
13594 int location, is_break;
13597 tree break_continue, label_block_expr = NULL_TREE;
13601 if (!(label_block_expr = IDENTIFIER_LOCAL_VALUE
13602 (merge_qualified_name (label_id, EXPR_WFL_NODE (name)))))
13603 /* Null means that we don't have a target for this named
13604 break/continue. In this case, we make the target to be the
13605 label name, so that the error can be reported accuratly in
13606 patch_bc_statement. */
13607 label_block_expr = EXPR_WFL_NODE (name);
13609 /* Unlabeled break/continue will be handled during the
13610 break/continue patch operation */
13612 = build (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr, NULL_TREE);
13614 IS_BREAK_STMT_P (break_continue) = is_break;
13615 TREE_SIDE_EFFECTS (break_continue) = 1;
13616 EXPR_WFL_LINECOL (break_continue) = location;
13617 break_continue = build_debugable_stmt (location, break_continue);
13618 return break_continue;
13621 /* Verification of a break/continue statement. */
13624 patch_bc_statement (node)
13627 tree bc_label = EXIT_BLOCK_LABELED_BLOCK (node), target_stmt;
13628 tree labeled_block = ctxp->current_labeled_block;
13629 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13631 /* Having an identifier here means that the target is unknown. */
13632 if (bc_label != NULL_TREE && TREE_CODE (bc_label) == IDENTIFIER_NODE)
13634 parse_error_context (wfl_operator, "No label definition found for `%s'",
13635 IDENTIFIER_POINTER (bc_label));
13636 return error_mark_node;
13638 if (! IS_BREAK_STMT_P (node))
13640 /* It's a continue statement. */
13641 for (;; labeled_block = TREE_CHAIN (labeled_block))
13643 if (labeled_block == NULL_TREE)
13645 if (bc_label == NULL_TREE)
13646 parse_error_context (wfl_operator,
13647 "`continue' must be in loop");
13649 parse_error_context
13650 (wfl_operator, "continue label `%s' does not name a loop",
13651 IDENTIFIER_POINTER (bc_label));
13652 return error_mark_node;
13654 if ((DECL_NAME (LABELED_BLOCK_LABEL (labeled_block))
13655 == continue_identifier_node)
13656 && (bc_label == NULL_TREE
13657 || TREE_CHAIN (labeled_block) == bc_label))
13659 bc_label = labeled_block;
13664 else if (!bc_label)
13666 for (;; labeled_block = TREE_CHAIN (labeled_block))
13668 if (labeled_block == NULL_TREE)
13670 parse_error_context (wfl_operator,
13671 "`break' must be in loop or switch");
13672 return error_mark_node;
13674 target_stmt = LABELED_BLOCK_BODY (labeled_block);
13675 if (TREE_CODE (target_stmt) == SWITCH_EXPR
13676 || search_loop (target_stmt))
13678 bc_label = labeled_block;
13684 EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
13685 CAN_COMPLETE_NORMALLY (bc_label) = 1;
13687 /* Our break/continue don't return values. */
13688 TREE_TYPE (node) = void_type_node;
13689 /* Encapsulate the break within a compound statement so that it's
13690 expanded all the times by expand_expr (and not clobbered
13691 sometimes, like after a if statement) */
13692 node = add_stmt_to_compound (NULL_TREE, void_type_node, node);
13693 TREE_SIDE_EFFECTS (node) = 1;
13697 /* Process the exit expression belonging to a loop. Its type must be
13701 patch_exit_expr (node)
13704 tree expression = TREE_OPERAND (node, 0);
13705 TREE_TYPE (node) = error_mark_node;
13706 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13708 /* The type of expression must be boolean */
13709 if (TREE_TYPE (expression) != boolean_type_node)
13711 parse_error_context
13713 "Incompatible type for loop conditional. Can't convert `%s' to `boolean'",
13714 lang_printable_name (TREE_TYPE (expression), 0));
13715 return error_mark_node;
13717 /* Now we know things are allright, invert the condition, fold and
13719 TREE_OPERAND (node, 0) =
13720 fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
13722 if (! integer_zerop (TREE_OPERAND (node, 0))
13723 && ctxp->current_loop != NULL_TREE
13724 && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
13725 CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
13726 if (! integer_onep (TREE_OPERAND (node, 0)))
13727 CAN_COMPLETE_NORMALLY (node) = 1;
13730 TREE_TYPE (node) = void_type_node;
13734 /* 14.9 Switch statement */
13737 patch_switch_statement (node)
13740 tree se = TREE_OPERAND (node, 0), se_type;
13742 /* Complete the switch expression */
13743 se = TREE_OPERAND (node, 0) = java_complete_tree (se);
13744 se_type = TREE_TYPE (se);
13745 /* The type of the switch expression must be char, byte, short or
13747 if (!JINTEGRAL_TYPE_P (se_type))
13749 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
13750 parse_error_context (wfl_operator,
13751 "Incompatible type for `switch'. Can't convert `%s' to `int'",
13752 lang_printable_name (se_type, 0));
13753 /* This is what java_complete_tree will check */
13754 TREE_OPERAND (node, 0) = error_mark_node;
13755 return error_mark_node;
13758 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
13760 /* Ready to return */
13761 if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
13763 TREE_TYPE (node) = error_mark_node;
13764 return error_mark_node;
13766 TREE_TYPE (node) = void_type_node;
13767 TREE_SIDE_EFFECTS (node) = 1;
13768 CAN_COMPLETE_NORMALLY (node)
13769 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
13770 || ! SWITCH_HAS_DEFAULT (node);
13774 /* 14.18 The try statement */
13777 build_try_statement (location, try_block, catches)
13779 tree try_block, catches;
13781 tree node = build (TRY_EXPR, NULL_TREE, try_block, catches);
13782 EXPR_WFL_LINECOL (node) = location;
13787 build_try_finally_statement (location, try_block, finally)
13789 tree try_block, finally;
13791 tree node = build (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
13792 EXPR_WFL_LINECOL (node) = location;
13797 patch_try_statement (node)
13800 int error_found = 0;
13801 tree try = TREE_OPERAND (node, 0);
13802 /* Exception handlers are considered in left to right order */
13803 tree catch = nreverse (TREE_OPERAND (node, 1));
13804 tree current, caught_type_list = NULL_TREE;
13806 /* Check catch clauses, if any. Every time we find an error, we try
13807 to process the next catch clause. We process the catch clause before
13808 the try block so that when processing the try block we can check thrown
13809 exceptions againts the caught type list. */
13810 for (current = catch; current; current = TREE_CHAIN (current))
13812 tree carg_decl, carg_type;
13813 tree sub_current, catch_block, catch_clause;
13816 /* At this point, the structure of the catch clause is
13817 CATCH_EXPR (catch node)
13818 BLOCK (with the decl of the parameter)
13820 MODIFY_EXPR (assignment of the catch parameter)
13821 BLOCK (catch clause block)
13823 catch_clause = TREE_OPERAND (current, 0);
13824 carg_decl = BLOCK_EXPR_DECLS (catch_clause);
13825 carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
13827 /* Catch clauses can't have more than one parameter declared,
13828 but it's already enforced by the grammar. Make sure that the
13829 only parameter of the clause statement in of class Throwable
13830 or a subclass of Throwable, but that was done earlier. The
13831 catch clause parameter type has also been resolved. */
13833 /* Just make sure that the catch clause parameter type inherits
13834 from java.lang.Throwable */
13835 if (!inherits_from_p (carg_type, throwable_type_node))
13837 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
13838 parse_error_context (wfl_operator,
13839 "Can't catch class `%s'. Catch clause parameter type must be a subclass of class `java.lang.Throwable'",
13840 lang_printable_name (carg_type, 0));
13845 /* Partial check for unreachable catch statement: The catch
13846 clause is reachable iff is no earlier catch block A in
13847 the try statement such that the type of the catch
13848 clause's parameter is the same as or a subclass of the
13849 type of A's parameter */
13851 for (sub_current = catch;
13852 sub_current != current; sub_current = TREE_CHAIN (sub_current))
13854 tree sub_catch_clause, decl;
13855 sub_catch_clause = TREE_OPERAND (sub_current, 0);
13856 decl = BLOCK_EXPR_DECLS (sub_catch_clause);
13858 if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
13860 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
13861 parse_error_context
13863 "`catch' not reached because of the catch clause at line %d",
13864 EXPR_WFL_LINENO (sub_current));
13865 unreachable = error_found = 1;
13869 /* Complete the catch clause block */
13870 catch_block = java_complete_tree (TREE_OPERAND (current, 0));
13871 if (catch_block == error_mark_node)
13876 if (CAN_COMPLETE_NORMALLY (catch_block))
13877 CAN_COMPLETE_NORMALLY (node) = 1;
13878 TREE_OPERAND (current, 0) = catch_block;
13883 /* Things to do here: the exception must be thrown */
13885 /* Link this type to the caught type list */
13886 caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
13889 PUSH_EXCEPTIONS (caught_type_list);
13890 if ((try = java_complete_tree (try)) == error_mark_node)
13892 if (CAN_COMPLETE_NORMALLY (try))
13893 CAN_COMPLETE_NORMALLY (node) = 1;
13896 /* Verification ends here */
13898 return error_mark_node;
13900 TREE_OPERAND (node, 0) = try;
13901 TREE_OPERAND (node, 1) = catch;
13902 TREE_TYPE (node) = void_type_node;
13906 /* 14.17 The synchronized Statement */
13909 patch_synchronized_statement (node, wfl_op1)
13910 tree node, wfl_op1;
13912 tree expr = java_complete_tree (TREE_OPERAND (node, 0));
13913 tree block = TREE_OPERAND (node, 1);
13915 tree enter, exit, expr_decl, assignment;
13917 if (expr == error_mark_node)
13919 block = java_complete_tree (block);
13923 /* The TYPE of expr must be a reference type */
13924 if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
13926 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
13927 parse_error_context (wfl_operator, "Incompatible type for `synchronized'. Can't convert `%s' to `java.lang.Object'",
13928 lang_printable_name (TREE_TYPE (expr), 0));
13929 return error_mark_node;
13932 if (flag_emit_xref)
13934 TREE_OPERAND (node, 0) = expr;
13935 TREE_OPERAND (node, 1) = java_complete_tree (block);
13936 CAN_COMPLETE_NORMALLY (node) = 1;
13940 /* Generate a try-finally for the synchronized statement, except
13941 that the handler that catches all throw exception calls
13942 _Jv_MonitorExit and then rethrow the exception.
13943 The synchronized statement is then implemented as:
13946 _Jv_MonitorEnter (expression)
13948 _Jv_MonitorExit (expression)
13952 e = _Jv_exception_info ();
13953 _Jv_MonitorExit (expression)
13957 expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
13958 BUILD_MONITOR_ENTER (enter, expr_decl);
13959 BUILD_MONITOR_EXIT (exit, expr_decl);
13960 CAN_COMPLETE_NORMALLY (enter) = 1;
13961 CAN_COMPLETE_NORMALLY (exit) = 1;
13962 assignment = build (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
13963 TREE_SIDE_EFFECTS (assignment) = 1;
13964 node = build1 (CLEANUP_POINT_EXPR, NULL_TREE,
13965 build (COMPOUND_EXPR, NULL_TREE,
13966 build (WITH_CLEANUP_EXPR, NULL_TREE,
13967 build (COMPOUND_EXPR, NULL_TREE,
13968 assignment, enter),
13971 node = build_expr_block (node, expr_decl);
13973 return java_complete_tree (node);
13976 /* 14.16 The throw Statement */
13979 patch_throw_statement (node, wfl_op1)
13980 tree node, wfl_op1;
13982 tree expr = TREE_OPERAND (node, 0);
13983 tree type = TREE_TYPE (expr);
13984 int unchecked_ok = 0, tryblock_throws_ok = 0;
13986 /* Thrown expression must be assignable to java.lang.Throwable */
13987 if (!try_reference_assignconv (throwable_type_node, expr))
13989 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
13990 parse_error_context (wfl_operator,
13991 "Can't throw `%s'; it must be a subclass of class `java.lang.Throwable'",
13992 lang_printable_name (type, 0));
13993 /* If the thrown expression was a reference, we further the
13994 compile-time check. */
13995 if (!JREFERENCE_TYPE_P (type))
13996 return error_mark_node;
13999 /* At least one of the following must be true */
14001 /* The type of the throw expression is a not checked exception,
14002 i.e. is a unchecked expression. */
14003 unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
14005 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
14006 /* An instance can't throw a checked excetion unless that exception
14007 is explicitely declared in the `throws' clause of each
14008 constructor. This doesn't apply to anonymous classes, since they
14009 don't have declared constructors. */
14011 && in_instance_initializer && !ANONYMOUS_CLASS_P (current_class))
14014 for (current = TYPE_METHODS (current_class); current;
14015 current = TREE_CHAIN (current))
14016 if (DECL_CONSTRUCTOR_P (current)
14017 && !check_thrown_exceptions_do (TREE_TYPE (expr)))
14019 parse_error_context (wfl_operator, "Checked exception `%s' can't be thrown in instance initializer (not all declared constructor are declaring it in their `throws' clause)",
14020 lang_printable_name (TREE_TYPE (expr), 0));
14021 return error_mark_node;
14025 /* Throw is contained in a try statement and at least one catch
14026 clause can receive the thrown expression or the current method is
14027 declared to throw such an exception. Or, the throw statement is
14028 contained in a method or constructor declaration and the type of
14029 the Expression is assignable to at least one type listed in the
14030 throws clause the declaration. */
14032 tryblock_throws_ok = check_thrown_exceptions_do (TREE_TYPE (expr));
14033 if (!(unchecked_ok || tryblock_throws_ok))
14035 /* If there is a surrounding try block that has no matching
14036 clatch clause, report it first. A surrounding try block exits
14037 only if there is something after the list of checked
14038 exception thrown by the current function (if any). */
14039 if (IN_TRY_BLOCK_P ())
14040 parse_error_context (wfl_operator, "Checked exception `%s' can't be caught by any of the catch clause(s) of the surrounding `try' block",
14041 lang_printable_name (type, 0));
14042 /* If we have no surrounding try statement and the method doesn't have
14043 any throws, report it now. FIXME */
14045 /* We report that the exception can't be throw from a try block
14046 in all circumstances but when the `throw' is inside a static
14048 else if (!EXCEPTIONS_P (currently_caught_type_list)
14049 && !tryblock_throws_ok)
14051 if (DECL_CLINIT_P (current_function_decl))
14052 parse_error_context (wfl_operator,
14053 "Checked exception `%s' can't be thrown in initializer",
14054 lang_printable_name (type, 0));
14056 parse_error_context (wfl_operator,
14057 "Checked exception `%s' isn't thrown from a `try' block",
14058 lang_printable_name (type, 0));
14060 /* Otherwise, the current method doesn't have the appropriate
14061 throws declaration */
14063 parse_error_context (wfl_operator, "Checked exception `%s' doesn't match any of current method's `throws' declaration(s)",
14064 lang_printable_name (type, 0));
14065 return error_mark_node;
14068 if (! flag_emit_class_files && ! flag_emit_xref)
14069 BUILD_THROW (node, expr);
14071 /* If doing xrefs, keep the location where the `throw' was seen. */
14072 if (flag_emit_xref)
14073 EXPR_WFL_LINECOL (node) = EXPR_WFL_LINECOL (wfl_op1);
14077 /* Check that exception said to be thrown by method DECL can be
14078 effectively caught from where DECL is invoked. */
14081 check_thrown_exceptions (location, decl)
14086 /* For all the unchecked exceptions thrown by DECL */
14087 for (throws = DECL_FUNCTION_THROWS (decl); throws;
14088 throws = TREE_CHAIN (throws))
14089 if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
14092 /* Temporary hack to suppresses errors about cloning arrays. FIXME */
14093 if (DECL_NAME (decl) == get_identifier ("clone"))
14096 EXPR_WFL_LINECOL (wfl_operator) = location;
14097 if (DECL_FINIT_P (current_function_decl))
14098 parse_error_context
14099 (wfl_operator, "Exception `%s' can't be thrown in initializer",
14100 lang_printable_name (TREE_VALUE (throws), 0));
14103 parse_error_context
14104 (wfl_operator, "Exception `%s' must be caught, or it must be declared in the `throws' clause of `%s'",
14105 lang_printable_name (TREE_VALUE (throws), 0),
14106 (DECL_INIT_P (current_function_decl) ?
14107 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))) :
14108 IDENTIFIER_POINTER (DECL_NAME (current_function_decl))));
14113 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
14114 try-catch blocks, OR is listed in the `throws' clause of the
14118 check_thrown_exceptions_do (exception)
14121 tree list = currently_caught_type_list;
14122 resolve_and_layout (exception, NULL_TREE);
14123 /* First, all the nested try-catch-finally at that stage. The
14124 last element contains `throws' clause exceptions, if any. */
14125 if (IS_UNCHECKED_EXCEPTION_P (exception))
14130 for (caught = TREE_VALUE (list); caught; caught = TREE_CHAIN (caught))
14131 if (valid_ref_assignconv_cast_p (exception, TREE_VALUE (caught), 0))
14133 list = TREE_CHAIN (list);
14139 purge_unchecked_exceptions (mdecl)
14142 tree throws = DECL_FUNCTION_THROWS (mdecl);
14143 tree new = NULL_TREE;
14147 tree next = TREE_CHAIN (throws);
14148 if (!IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (throws)))
14150 TREE_CHAIN (throws) = new;
14155 /* List is inverted here, but it doesn't matter */
14156 DECL_FUNCTION_THROWS (mdecl) = new;
14159 /* 15.24 Conditional Operator ?: */
14162 patch_conditional_expr (node, wfl_cond, wfl_op1)
14163 tree node, wfl_cond, wfl_op1;
14165 tree cond = TREE_OPERAND (node, 0);
14166 tree op1 = TREE_OPERAND (node, 1);
14167 tree op2 = TREE_OPERAND (node, 2);
14168 tree resulting_type = NULL_TREE;
14169 tree t1, t2, patched;
14170 int error_found = 0;
14172 /* Operands of ?: might be StringBuffers crafted as a result of a
14173 string concatenation. Obtain a descent operand here. */
14174 if ((patched = patch_string (op1)))
14175 TREE_OPERAND (node, 1) = op1 = patched;
14176 if ((patched = patch_string (op2)))
14177 TREE_OPERAND (node, 2) = op2 = patched;
14179 t1 = TREE_TYPE (op1);
14180 t2 = TREE_TYPE (op2);
14182 /* The first expression must be a boolean */
14183 if (TREE_TYPE (cond) != boolean_type_node)
14185 SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
14186 parse_error_context (wfl_operator,
14187 "Incompatible type for `?:'. Can't convert `%s' to `boolean'",
14188 lang_printable_name (TREE_TYPE (cond), 0));
14192 /* Second and third can be numeric, boolean (i.e. primitive),
14193 references or null. Anything else results in an error */
14194 if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
14195 || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node)
14196 && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
14197 || (t1 == boolean_type_node && t2 == boolean_type_node)))
14200 /* Determine the type of the conditional expression. Same types are
14201 easy to deal with */
14203 resulting_type = t1;
14205 /* There are different rules for numeric types */
14206 else if (JNUMERIC_TYPE_P (t1))
14208 /* if byte/short found, the resulting type is short */
14209 if ((t1 == byte_type_node && t2 == short_type_node)
14210 || (t1 == short_type_node && t2 == byte_type_node))
14211 resulting_type = short_type_node;
14213 /* If t1 is a constant int and t2 is of type byte, short or char
14214 and t1's value fits in t2, then the resulting type is t2 */
14215 else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
14216 && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
14217 resulting_type = t2;
14219 /* If t2 is a constant int and t1 is of type byte, short or char
14220 and t2's value fits in t1, then the resulting type is t1 */
14221 else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
14222 && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
14223 resulting_type = t1;
14225 /* Otherwise, binary numeric promotion is applied and the
14226 resulting type is the promoted type of operand 1 and 2 */
14228 resulting_type = binary_numeric_promotion (t1, t2,
14229 &TREE_OPERAND (node, 1),
14230 &TREE_OPERAND (node, 2));
14233 /* Cases of a reference and a null type */
14234 else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
14235 resulting_type = t1;
14237 else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
14238 resulting_type = t2;
14240 /* Last case: different reference types. If a type can be converted
14241 into the other one by assignment conversion, the latter
14242 determines the type of the expression */
14243 else if ((resulting_type = try_reference_assignconv (t1, op2)))
14244 resulting_type = promote_type (t1);
14246 else if ((resulting_type = try_reference_assignconv (t2, op1)))
14247 resulting_type = promote_type (t2);
14249 /* If we don't have any resulting type, we're in trouble */
14250 if (!resulting_type)
14252 char *t = xstrdup (lang_printable_name (t1, 0));
14253 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
14254 parse_error_context (wfl_operator,
14255 "Incompatible type for `?:'. Can't convert `%s' to `%s'",
14256 t, lang_printable_name (t2, 0));
14263 TREE_TYPE (node) = error_mark_node;
14264 return error_mark_node;
14267 TREE_TYPE (node) = resulting_type;
14268 TREE_SET_CODE (node, COND_EXPR);
14269 CAN_COMPLETE_NORMALLY (node) = 1;
14273 /* Try to constant fold NODE.
14274 If NODE is not a constant expression, return NULL_EXPR.
14275 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
14278 fold_constant_for_init (node, context)
14282 tree op0, op1, val;
14283 enum tree_code code = TREE_CODE (node);
14285 if (code == STRING_CST)
14288 if (code == INTEGER_CST || code == REAL_CST)
14289 return convert (TREE_TYPE (context), node);
14290 if (TREE_TYPE (node) != NULL_TREE && code != VAR_DECL && code != FIELD_DECL)
14298 case TRUNC_MOD_EXPR:
14306 case TRUTH_ANDIF_EXPR:
14307 case TRUTH_ORIF_EXPR:
14314 op0 = TREE_OPERAND (node, 0);
14315 op1 = TREE_OPERAND (node, 1);
14316 val = fold_constant_for_init (op0, context);
14317 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14319 TREE_OPERAND (node, 0) = val;
14320 val = fold_constant_for_init (op1, context);
14321 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14323 TREE_OPERAND (node, 1) = val;
14324 return patch_binop (node, op0, op1);
14326 case UNARY_PLUS_EXPR:
14328 case TRUTH_NOT_EXPR:
14331 op0 = TREE_OPERAND (node, 0);
14332 val = fold_constant_for_init (op0, context);
14333 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14335 TREE_OPERAND (node, 0) = val;
14336 return patch_unaryop (node, op0);
14340 val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
14341 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14343 TREE_OPERAND (node, 0) = val;
14344 val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
14345 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14347 TREE_OPERAND (node, 1) = val;
14348 val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
14349 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14351 TREE_OPERAND (node, 2) = val;
14352 return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
14353 : TREE_OPERAND (node, 2);
14357 if (! FIELD_FINAL (node)
14358 || DECL_INITIAL (node) == NULL_TREE)
14360 val = DECL_INITIAL (node);
14361 /* Guard against infinite recursion. */
14362 DECL_INITIAL (node) = NULL_TREE;
14363 val = fold_constant_for_init (val, node);
14364 DECL_INITIAL (node) = val;
14367 case EXPR_WITH_FILE_LOCATION:
14368 /* Compare java_complete_tree and resolve_expression_name. */
14369 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
14370 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
14372 tree name = EXPR_WFL_NODE (node);
14374 if (PRIMARY_P (node))
14376 else if (! QUALIFIED_P (name))
14378 decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
14379 if (decl == NULL_TREE
14380 || (! FIELD_STATIC (decl) && ! FIELD_FINAL (decl)))
14382 return fold_constant_for_init (decl, decl);
14386 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
14387 qualify_ambiguous_name (node);
14388 if (resolve_field_access (node, &decl, NULL)
14389 && decl != NULL_TREE)
14390 return fold_constant_for_init (decl, decl);
14396 op0 = TREE_OPERAND (node, 0);
14397 val = fold_constant_for_init (op0, context);
14398 if (val == NULL_TREE || ! TREE_CONSTANT (val))
14400 TREE_OPERAND (node, 0) = val;
14404 #ifdef USE_COMPONENT_REF
14406 case COMPONENT_REF:
14415 #ifdef USE_COMPONENT_REF
14416 /* Context is 'T' for TypeName, 'P' for PackageName,
14417 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
14420 resolve_simple_name (name, context)
14427 resolve_qualified_name (name, context)