1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999 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"
67 #define DIR_SEPARATOR '/'
70 /* Local function prototypes */
71 static char *java_accstring_lookup PROTO ((int));
72 static void classitf_redefinition_error PROTO ((char *,tree, tree, tree));
73 static void variable_redefinition_error PROTO ((tree, tree, tree, int));
74 static void check_modifiers PROTO ((char *, int, int));
75 static tree create_class PROTO ((int, tree, tree, tree));
76 static tree create_interface PROTO ((int, tree, tree));
77 static tree find_field PROTO ((tree, tree));
78 static tree lookup_field_wrapper PROTO ((tree, tree));
79 static int duplicate_declaration_error_p PROTO ((tree, tree, tree));
80 static void register_fields PROTO ((int, tree, tree));
81 static tree parser_qualified_classname PROTO ((tree));
82 static int parser_check_super PROTO ((tree, tree, tree));
83 static int parser_check_super_interface PROTO ((tree, tree, tree));
84 static void check_modifiers_consistency PROTO ((int));
85 static tree lookup_cl PROTO ((tree));
86 static tree lookup_java_method2 PROTO ((tree, tree, int));
87 static tree method_header PROTO ((int, tree, tree, tree));
88 static void fix_method_argument_names PROTO ((tree ,tree));
89 static tree method_declarator PROTO ((tree, tree));
90 static void parse_warning_context PVPROTO ((tree cl, const char *msg, ...))
92 static void issue_warning_error_from_context PROTO ((tree, const char *msg, va_list));
93 static tree parse_jdk1_1_error PROTO ((char *));
94 static void complete_class_report_errors PROTO ((jdep *));
95 static int process_imports PROTO ((void));
96 static void read_import_dir PROTO ((tree));
97 static int find_in_imports_on_demand PROTO ((tree));
98 static int find_in_imports PROTO ((tree));
99 static int check_pkg_class_access PROTO ((tree, tree));
100 static tree resolve_package PROTO ((tree, tree *));
101 static tree lookup_package_type PROTO ((char *, int));
102 static tree resolve_class PROTO ((tree, tree, tree));
103 static void declare_local_variables PROTO ((int, tree, tree));
104 static void source_start_java_method PROTO ((tree));
105 static void source_end_java_method PROTO ((void));
106 static void expand_start_java_method PROTO ((tree));
107 static tree find_name_in_single_imports PROTO ((tree));
108 static void check_abstract_method_header PROTO ((tree));
109 static tree lookup_java_interface_method2 PROTO ((tree, tree));
110 static tree resolve_expression_name PROTO ((tree, tree *));
111 static tree maybe_create_class_interface_decl PROTO ((tree, tree, tree));
112 static int check_class_interface_creation PROTO ((int, int, tree,
114 static tree patch_method_invocation PROTO ((tree, tree, tree,
116 static int breakdown_qualified PROTO ((tree *, tree *, tree));
117 static tree resolve_and_layout PROTO ((tree, tree));
118 static tree resolve_no_layout PROTO ((tree, tree));
119 static int invocation_mode PROTO ((tree, int));
120 static tree find_applicable_accessible_methods_list PROTO ((int, tree,
122 static void search_applicable_methods_list PROTO ((int, tree, tree, tree,
124 static tree find_most_specific_methods_list PROTO ((tree));
125 static int argument_types_convertible PROTO ((tree, tree));
126 static tree patch_invoke PROTO ((tree, tree, tree));
127 static tree lookup_method_invoke PROTO ((int, tree, tree, tree, tree));
128 static tree register_incomplete_type PROTO ((int, tree, tree, tree));
129 static tree obtain_incomplete_type PROTO ((tree));
130 static tree java_complete_lhs PROTO ((tree));
131 static tree java_complete_tree PROTO ((tree));
132 static void java_complete_expand_method PROTO ((tree));
133 static int unresolved_type_p PROTO ((tree, tree *));
134 static void create_jdep_list PROTO ((struct parser_ctxt *));
135 static tree build_expr_block PROTO ((tree, tree));
136 static tree enter_block PROTO ((void));
137 static tree enter_a_block PROTO ((tree));
138 static tree exit_block PROTO ((void));
139 static tree lookup_name_in_blocks PROTO ((tree));
140 static void maybe_absorb_scoping_blocks PROTO ((void));
141 static tree build_method_invocation PROTO ((tree, tree));
142 static tree build_new_invocation PROTO ((tree, tree));
143 static tree build_assignment PROTO ((int, int, tree, tree));
144 static tree build_binop PROTO ((enum tree_code, int, tree, tree));
145 static int check_final_assignment PROTO ((tree ,tree));
146 static tree patch_assignment PROTO ((tree, tree, tree ));
147 static tree patch_binop PROTO ((tree, tree, tree));
148 static tree build_unaryop PROTO ((int, int, tree));
149 static tree build_incdec PROTO ((int, int, tree, int));
150 static tree patch_unaryop PROTO ((tree, tree));
151 static tree build_cast PROTO ((int, tree, tree));
152 static tree build_null_of_type PROTO ((tree));
153 static tree patch_cast PROTO ((tree, tree));
154 static int valid_ref_assignconv_cast_p PROTO ((tree, tree, int));
155 static int valid_builtin_assignconv_identity_widening_p PROTO ((tree, tree));
156 static int valid_cast_to_p PROTO ((tree, tree));
157 static int valid_method_invocation_conversion_p PROTO ((tree, tree));
158 static tree try_builtin_assignconv PROTO ((tree, tree, tree));
159 static tree try_reference_assignconv PROTO ((tree, tree));
160 static tree build_unresolved_array_type PROTO ((tree));
161 static tree build_array_from_name PROTO ((tree, tree, tree, tree *));
162 static tree build_array_ref PROTO ((int, tree, tree));
163 static tree patch_array_ref PROTO ((tree));
164 static tree make_qualified_name PROTO ((tree, tree, int));
165 static tree merge_qualified_name PROTO ((tree, tree));
166 static tree make_qualified_primary PROTO ((tree, tree, int));
167 static int resolve_qualified_expression_name PROTO ((tree, tree *,
169 static void qualify_ambiguous_name PROTO ((tree));
170 static void maybe_generate_clinit PROTO ((void));
171 static tree resolve_field_access PROTO ((tree, tree *, tree *));
172 static tree build_newarray_node PROTO ((tree, tree, int));
173 static tree patch_newarray PROTO ((tree));
174 static tree resolve_type_during_patch PROTO ((tree));
175 static tree build_this PROTO ((int));
176 static tree build_return PROTO ((int, tree));
177 static tree patch_return PROTO ((tree));
178 static tree maybe_access_field PROTO ((tree, tree, tree));
179 static int complete_function_arguments PROTO ((tree));
180 static int check_for_static_method_reference PROTO ((tree, tree, tree, tree, tree));
181 static int not_accessible_p PROTO ((tree, tree, int));
182 static void check_deprecation PROTO ((tree, tree));
183 static int class_in_current_package PROTO ((tree));
184 static tree build_if_else_statement PROTO ((int, tree, tree, tree));
185 static tree patch_if_else_statement PROTO ((tree));
186 static tree add_stmt_to_compound PROTO ((tree, tree, tree));
187 static tree add_stmt_to_block PROTO ((tree, tree, tree));
188 static tree patch_exit_expr PROTO ((tree));
189 static tree build_labeled_block PROTO ((int, tree));
190 static tree finish_labeled_statement PROTO ((tree, tree));
191 static tree build_bc_statement PROTO ((int, int, tree));
192 static tree patch_bc_statement PROTO ((tree));
193 static tree patch_loop_statement PROTO ((tree));
194 static tree build_new_loop PROTO ((tree));
195 static tree build_loop_body PROTO ((int, tree, int));
196 static tree finish_loop_body PROTO ((int, tree, tree, int));
197 static tree build_debugable_stmt PROTO ((int, tree));
198 static tree finish_for_loop PROTO ((int, tree, tree, tree));
199 static tree patch_switch_statement PROTO ((tree));
200 static tree string_constant_concatenation PROTO ((tree, tree));
201 static tree build_string_concatenation PROTO ((tree, tree));
202 static tree patch_string_cst PROTO ((tree));
203 static tree patch_string PROTO ((tree));
204 static tree build_try_statement PROTO ((int, tree, tree));
205 static tree build_try_finally_statement PROTO ((int, tree, tree));
206 static tree patch_try_statement PROTO ((tree));
207 static tree patch_synchronized_statement PROTO ((tree, tree));
208 static tree patch_throw_statement PROTO ((tree, tree));
209 static void check_thrown_exceptions PROTO ((int, tree));
210 static int check_thrown_exceptions_do PROTO ((tree));
211 static void purge_unchecked_exceptions PROTO ((tree));
212 static void check_throws_clauses PROTO ((tree, tree, tree));
213 static void finish_method_declaration PROTO ((tree));
214 static tree build_super_invocation PROTO (());
215 static int verify_constructor_circularity PROTO ((tree, tree));
216 static char *constructor_circularity_msg PROTO ((tree, tree));
217 static tree build_this_super_qualified_invocation PROTO ((int, tree, tree,
219 static char *get_printable_method_name PROTO ((tree));
220 static tree patch_conditional_expr PROTO ((tree, tree, tree));
221 static void maybe_generate_finit PROTO (());
222 static void fix_constructors PROTO ((tree));
223 static int verify_constructor_super PROTO (());
224 static tree create_artificial_method PROTO ((tree, int, tree, tree, tree));
225 static void start_artificial_method_body PROTO ((tree));
226 static void end_artificial_method_body PROTO ((tree));
227 static int check_method_redefinition PROTO ((tree, tree));
228 static int reset_method_name PROTO ((tree));
229 static void java_check_regular_methods PROTO ((tree));
230 static void java_check_abstract_methods PROTO ((tree));
231 static tree maybe_build_primttype_type_ref PROTO ((tree, tree));
232 static void unreachable_stmt_error PROTO ((tree));
233 static tree find_expr_with_wfl PROTO ((tree));
234 static void missing_return_error PROTO ((tree));
235 static tree build_new_array_init PROTO ((int, tree));
236 static tree patch_new_array_init PROTO ((tree, tree));
237 static tree maybe_build_array_element_wfl PROTO ((tree));
238 static int array_constructor_check_entry PROTO ((tree, tree));
239 static char *purify_type_name PROTO ((char *));
240 static tree patch_initialized_static_field PROTO ((tree));
241 static tree fold_constant_for_init PROTO ((tree, tree));
242 static tree strip_out_static_field_access_decl PROTO ((tree));
243 static jdeplist *reverse_jdep_list PROTO ((struct parser_ctxt *));
245 /* Number of error found so far. */
246 int java_error_count;
247 /* Number of warning found so far. */
248 int java_warning_count;
250 /* The current parser context */
251 struct parser_ctxt *ctxp;
253 /* List of things that were analyzed for which code will be generated */
254 static struct parser_ctxt *ctxp_for_generation = NULL;
256 /* binop_lookup maps token to tree_code. It is used where binary
257 operations are involved and required by the parser. RDIV_EXPR
258 covers both integral/floating point division. The code is changed
259 once the type of both operator is worked out. */
261 static enum tree_code binop_lookup[19] =
263 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
264 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
265 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
266 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
267 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
269 #define BINOP_LOOKUP(VALUE) \
270 binop_lookup [((VALUE) - PLUS_TK)% \
271 (sizeof (binop_lookup) / sizeof (binop_lookup[0]))]
273 /* Fake WFL used to report error message. It is initialized once if
274 needed and reused with it's location information is overriden. */
275 tree wfl_operator = NULL_TREE;
277 /* The "$L" identifier we use to create labels. */
278 static tree label_id = NULL_TREE;
280 /* The "StringBuffer" identifier used for the String `+' operator. */
281 static tree wfl_string_buffer = NULL_TREE;
283 /* The "append" identifier used for String `+' operator. */
284 static tree wfl_append = NULL_TREE;
286 /* The "toString" identifier used for String `+' operator. */
287 static tree wfl_to_string = NULL_TREE;
289 /* The "java.lang" import qualified name. */
290 static tree java_lang_id = NULL_TREE;
292 /* The "java.lang.Cloneable" qualified name. */
293 static tree java_lang_cloneable = NULL_TREE;
295 /* Context and flag for static blocks */
296 static tree current_static_block = NULL_TREE;
316 /* Things defined here have to match the order of what's in the
317 binop_lookup table. */
319 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
320 %token LS_TK SRS_TK ZRS_TK
321 %token AND_TK XOR_TK OR_TK
322 %token BOOL_AND_TK BOOL_OR_TK
323 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
325 /* This maps to the same binop_lookup entry than the token above */
327 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
329 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
330 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
333 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
335 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
336 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
337 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
338 %token PAD_TK ABSTRACT_TK MODIFIER_TK
340 /* Keep those two in order, too */
341 %token DECR_TK INCR_TK
343 /* From now one, things can be in any order */
345 %token DEFAULT_TK IF_TK THROW_TK
346 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
347 %token THROWS_TK BREAK_TK IMPORT_TK
348 %token ELSE_TK INSTANCEOF_TK RETURN_TK
349 %token VOID_TK CATCH_TK INTERFACE_TK
350 %token CASE_TK EXTENDS_TK FINALLY_TK
351 %token SUPER_TK WHILE_TK CLASS_TK
352 %token SWITCH_TK CONST_TK TRY_TK
353 %token FOR_TK NEW_TK CONTINUE_TK
354 %token GOTO_TK PACKAGE_TK THIS_TK
356 %token BYTE_TK SHORT_TK INT_TK LONG_TK
357 %token CHAR_TK INTEGRAL_TK
359 %token FLOAT_TK DOUBLE_TK FP_TK
363 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
365 %token ASSIGN_ANY_TK ASSIGN_TK
366 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
368 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
369 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
371 %type <value> modifiers MODIFIER_TK
373 %type <node> super ID_TK identifier
374 %type <node> name simple_name qualified_name
375 %type <node> class_declaration type_declaration compilation_unit
376 field_declaration method_declaration extends_interfaces
377 interfaces interface_type_list
378 interface_declaration class_member_declaration
379 import_declarations package_declaration
380 type_declarations interface_body
381 interface_member_declaration constant_declaration
382 interface_member_declarations interface_type
383 abstract_method_declaration interface_type_list
384 %type <node> class_body_declaration class_member_declaration
385 static_initializer constructor_declaration block
386 %type <node> class_body_declarations constructor_header
387 %type <node> class_or_interface_type class_type class_type_list
388 constructor_declarator explicit_constructor_invocation
389 %type <node> dim_expr dim_exprs this_or_super throws
391 %type <node> variable_declarator_id variable_declarator
392 variable_declarators variable_initializer
393 variable_initializers constructor_body
396 %type <node> class_body block_end
397 %type <node> statement statement_without_trailing_substatement
398 labeled_statement if_then_statement label_decl
399 if_then_else_statement while_statement for_statement
400 statement_nsi labeled_statement_nsi do_statement
401 if_then_else_statement_nsi while_statement_nsi
402 for_statement_nsi statement_expression_list for_init
403 for_update statement_expression expression_statement
404 primary_no_new_array expression primary
405 array_creation_expression array_type
406 class_instance_creation_expression field_access
407 method_invocation array_access something_dot_new
408 argument_list postfix_expression while_expression
409 post_increment_expression post_decrement_expression
410 unary_expression_not_plus_minus unary_expression
411 pre_increment_expression pre_decrement_expression
412 unary_expression_not_plus_minus cast_expression
413 multiplicative_expression additive_expression
414 shift_expression relational_expression
415 equality_expression and_expression
416 exclusive_or_expression inclusive_or_expression
417 conditional_and_expression conditional_or_expression
418 conditional_expression assignment_expression
419 left_hand_side assignment for_header for_begin
420 constant_expression do_statement_begin empty_statement
421 switch_statement synchronized_statement throw_statement
422 try_statement switch_expression switch_block
423 catches catch_clause catch_clause_parameter finally
424 %type <node> return_statement break_statement continue_statement
426 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
427 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
428 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
429 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
430 %type <operator> ASSIGN_ANY_TK assignment_operator
431 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
432 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
433 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
434 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK
435 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
436 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
437 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
439 %type <node> method_body
441 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
442 STRING_LIT_TK NULL_TK VOID_TK
444 %type <node> IF_TK WHILE_TK FOR_TK
446 %type <node> formal_parameter_list formal_parameter
447 method_declarator method_header
449 %type <node> primitive_type reference_type type
450 BOOLEAN_TK INTEGRAL_TK FP_TK
453 /* 19.2 Production from 2.3: The Syntactic Grammar */
459 /* 19.3 Productions from 3: Lexical structure */
469 /* 19.4 Productions from 4: Types, Values and Variables */
482 class_or_interface_type
486 class_or_interface_type:
491 class_or_interface_type /* Default rule */
495 class_or_interface_type
499 primitive_type OSB_TK CSB_TK
501 $$ = build_java_array_type ($1, -1);
502 CLASS_LOADED_P ($$) = 1;
505 { $$ = build_unresolved_array_type ($1); }
506 | array_type OSB_TK CSB_TK
507 { $$ = build_unresolved_array_type ($1); }
508 | primitive_type OSB_TK error
509 {RULE ("']' expected"); RECOVER;}
510 | array_type OSB_TK error
511 {RULE ("']' expected"); RECOVER;}
514 /* 19.5 Productions from 6: Names */
516 simple_name /* Default rule */
517 | qualified_name /* Default rule */
521 identifier /* Default rule */
525 name DOT_TK identifier
526 { $$ = make_qualified_name ($1, $3, $2.location); }
533 /* 19.6: Production from 7: Packages */
536 | package_declaration
537 | import_declarations
539 | package_declaration import_declarations
540 | package_declaration type_declarations
541 | import_declarations type_declarations
542 | package_declaration import_declarations type_declarations
550 | import_declarations import_declaration
558 | type_declarations type_declaration
562 PACKAGE_TK name SC_TK
563 { ctxp->package = EXPR_WFL_NODE ($2); }
565 {yyerror ("Missing name"); RECOVER;}
566 | PACKAGE_TK name error
567 {yyerror ("';' expected"); RECOVER;}
571 single_type_import_declaration
572 | type_import_on_demand_declaration
575 single_type_import_declaration:
578 tree name = EXPR_WFL_NODE ($2), node, last_name;
579 int i = IDENTIFIER_LENGTH (name)-1;
580 char *last = &IDENTIFIER_POINTER (name)[i];
581 while (last != IDENTIFIER_POINTER (name))
587 last_name = get_identifier (++last);
588 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
590 tree err = find_name_in_single_imports (last_name);
591 if (err && err != name)
593 ($2, "Ambiguous class: `%s' and `%s'",
594 IDENTIFIER_POINTER (name),
595 IDENTIFIER_POINTER (err));
597 REGISTER_IMPORT ($2, last_name)
600 REGISTER_IMPORT ($2, last_name);
603 {yyerror ("Missing name"); RECOVER;}
604 | IMPORT_TK name error
605 {yyerror ("';' expected"); RECOVER;}
608 type_import_on_demand_declaration:
609 IMPORT_TK name DOT_TK MULT_TK SC_TK
611 tree name = EXPR_WFL_NODE ($2);
612 /* Don't import java.lang.* twice. */
613 if (name != java_lang_id)
615 tree node = build_tree_list ($2, NULL_TREE);
616 read_import_dir ($2);
617 TREE_CHAIN (node) = ctxp->import_demand_list;
618 ctxp->import_demand_list = node;
621 | IMPORT_TK name DOT_TK error
622 {yyerror ("'*' expected"); RECOVER;}
623 | IMPORT_TK name DOT_TK MULT_TK error
624 {yyerror ("';' expected"); RECOVER;}
630 maybe_generate_finit ();
631 maybe_generate_clinit ();
634 | interface_declaration
636 maybe_generate_clinit ();
644 yyerror ("Class or interface declaration expected");
648 /* 19.7 Shortened from the original:
649 modifiers: modifier | modifiers modifier
650 modifier: any of public... */
656 | modifiers MODIFIER_TK
661 (ctxp->modifier_ctx [$2], "Modifier `%s' declared twice",
662 java_accstring_lookup (acc));
670 /* 19.8.1 Production from $8.1: Class Declaration */
672 modifiers CLASS_TK identifier super interfaces
673 { create_class ($1, $3, $4, $5); }
678 | CLASS_TK identifier super interfaces
679 { create_class (0, $2, $3, $4); }
684 | modifiers CLASS_TK error
685 {yyerror ("Missing class name"); RECOVER;}
687 {yyerror ("Missing class name"); RECOVER;}
688 | CLASS_TK identifier error
690 if (!ctxp->class_err) yyerror ("'{' expected");
693 | modifiers CLASS_TK identifier error
694 {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
699 | EXTENDS_TK class_type
701 | EXTENDS_TK class_type error
702 {yyerror ("'{' expected"); ctxp->class_err=1;}
704 {yyerror ("Missing super class name"); ctxp->class_err=1;}
709 | IMPLEMENTS_TK interface_type_list
711 | IMPLEMENTS_TK error
714 yyerror ("Missing interface name");
721 ctxp->interface_number = 1;
722 $$ = build_tree_list ($1, NULL_TREE);
724 | interface_type_list C_TK interface_type
726 ctxp->interface_number++;
727 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
729 | interface_type_list C_TK error
730 {yyerror ("Missing interface name"); RECOVER;}
735 { $$ = ctxp->current_parsed_class; }
736 | OCB_TK class_body_declarations CCB_TK
737 { $$ = ctxp->current_parsed_class; }
740 class_body_declarations:
741 class_body_declaration
742 | class_body_declarations class_body_declaration
745 class_body_declaration:
746 class_member_declaration
748 | constructor_declaration
749 | block /* Added, JDK1.1, instance initializer */
750 { $$ = parse_jdk1_1_error ("instance initializer"); }
753 class_member_declaration:
755 | field_declaration SC_TK
758 | class_declaration /* Added, JDK1.1 inner classes */
759 { $$ = parse_jdk1_1_error ("inner classe declaration"); }
760 | interface_declaration /* Added, JDK1.1 inner classes */
761 { $$ = parse_jdk1_1_error ("inner interface declaration"); }
764 /* 19.8.2 Productions from 8.3: Field Declarations */
766 type variable_declarators SC_TK
767 { register_fields (0, $1, $2); }
768 | modifiers type variable_declarators SC_TK
771 ("Illegal modifier `%s' for field declaration",
772 $1, FIELD_MODIFIERS);
773 check_modifiers_consistency ($1);
774 register_fields ($1, $2, $3);
778 variable_declarators:
779 /* Should we use build_decl_list () instead ? FIXME */
780 variable_declarator /* Default rule */
781 | variable_declarators C_TK variable_declarator
782 { $$ = chainon ($1, $3); }
783 | variable_declarators C_TK error
784 {yyerror ("Missing term"); RECOVER;}
788 variable_declarator_id
789 { $$ = build_tree_list ($1, NULL_TREE); }
790 | variable_declarator_id ASSIGN_TK variable_initializer
792 if (java_error_count)
795 ($1, build_assignment ($2.token, $2.location, $1, $3));
797 | variable_declarator_id ASSIGN_TK error
799 yyerror ("Missing variable initializer");
800 $$ = build_tree_list ($1, NULL_TREE);
803 | variable_declarator_id ASSIGN_TK variable_initializer error
805 yyerror ("';' expected");
806 $$ = build_tree_list ($1, NULL_TREE);
811 variable_declarator_id:
813 | variable_declarator_id OSB_TK CSB_TK
814 { $$ = build_unresolved_array_type ($1); }
816 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
817 | variable_declarator_id OSB_TK error
818 {yyerror ("']' expected"); DRECOVER(vdi);}
819 | variable_declarator_id CSB_TK error
820 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
823 variable_initializer:
828 /* 19.8.3 Productions from 8.4: Method Declarations */
832 current_function_decl = $1;
833 source_start_java_method (current_function_decl);
836 { finish_method_declaration ($3); }
837 | method_header error
838 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
842 type method_declarator throws
843 { $$ = method_header (0, $1, $2, $3); }
844 | VOID_TK method_declarator throws
845 { $$ = method_header (0, void_type_node, $2, $3); }
846 | modifiers type method_declarator throws
847 { $$ = method_header ($1, $2, $3, $4); }
848 | modifiers VOID_TK method_declarator throws
849 { $$ = method_header ($1, void_type_node, $3, $4); }
852 | modifiers type error
855 {yyerror ("Identifier expected"); RECOVER;}
856 | modifiers VOID_TK error
857 {yyerror ("Identifier expected"); RECOVER;}
860 yyerror ("Invalid method declaration, return type required");
866 identifier OP_TK CP_TK
867 { $$ = method_declarator ($1, NULL_TREE); }
868 | identifier OP_TK formal_parameter_list CP_TK
869 { $$ = method_declarator ($1, $3); }
870 | method_declarator OSB_TK CSB_TK
872 EXPR_WFL_LINECOL (wfl_operator) = $2.location;
874 build_unresolved_array_type (TREE_PURPOSE ($1));
875 parse_warning_context
877 "Discouraged form of returned type specification");
879 | identifier OP_TK error
880 {yyerror ("')' expected"); DRECOVER(method_declarator);}
881 | method_declarator OSB_TK error
882 {yyerror ("']' expected"); RECOVER;}
885 formal_parameter_list:
888 ctxp->formal_parameter_number = 1;
890 | formal_parameter_list C_TK formal_parameter
892 ctxp->formal_parameter_number += 1;
893 $$ = chainon ($1, $3);
895 | formal_parameter_list C_TK error
896 {yyerror ("Missing formal parameter term"); RECOVER;}
900 type variable_declarator_id
902 $$ = build_tree_list ($2, $1);
904 | modifiers type variable_declarator_id /* Added, JDK1.1 final parms */
905 { $$ = parse_jdk1_1_error ("final parameters"); }
907 {yyerror ("Missing identifier"); RECOVER;}
908 | modifiers type error
910 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
911 yyerror ("Missing identifier"); RECOVER;
917 | THROWS_TK class_type_list
920 {yyerror ("Missing class type term"); RECOVER;}
925 { $$ = build_tree_list ($1, $1); }
926 | class_type_list C_TK class_type
927 { $$ = tree_cons ($3, $3, $1); }
928 | class_type_list C_TK error
929 {yyerror ("Missing class type term"); RECOVER;}
936 { $$ = NULL_TREE; } /* Probably not the right thing to do. */
939 /* 19.8.4 Productions from 8.5: Static Initializers */
943 TREE_CHAIN ($2) = ctxp->static_initialized;
944 ctxp->static_initialized = $2;
946 | static block SC_TK /* Shouldn't be here. FIXME */
948 TREE_CHAIN ($2) = ctxp->static_initialized;
949 ctxp->static_initialized = $2;
953 static: /* Test lval.sub_token here */
956 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
960 /* 19.8.5 Productions from 8.6: Constructor Declarations */
961 constructor_declaration:
964 current_function_decl = $1;
965 source_start_java_method (current_function_decl);
968 { finish_method_declaration ($3); }
972 constructor_declarator throws
973 { $$ = method_header (0, NULL_TREE, $1, $2); }
974 | modifiers constructor_declarator throws
975 { $$ = method_header ($1, NULL_TREE, $2, $3); }
978 constructor_declarator:
979 simple_name OP_TK CP_TK
980 { $$ = method_declarator ($1, NULL_TREE); }
981 | simple_name OP_TK formal_parameter_list CP_TK
982 { $$ = method_declarator ($1, $3); }
986 /* Unlike regular method, we always need a complete (empty)
987 body so we can safely perform all the required code
988 addition (super invocation and field initialization) */
989 block_begin block_end
991 BLOCK_EXPR_BODY ($2) = empty_stmt_node;
994 | block_begin explicit_constructor_invocation block_end
996 | block_begin block_statements block_end
998 | block_begin explicit_constructor_invocation block_statements block_end
1002 /* Error recovery for that rule moved down expression_statement: rule. */
1003 explicit_constructor_invocation:
1004 this_or_super OP_TK CP_TK SC_TK
1006 $$ = build_method_invocation ($1, NULL_TREE);
1007 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1008 $$ = java_method_add_stmt (current_function_decl, $$);
1010 | this_or_super OP_TK argument_list CP_TK SC_TK
1012 $$ = build_method_invocation ($1, $3);
1013 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1014 $$ = java_method_add_stmt (current_function_decl, $$);
1016 /* Added, JDK1.1 inner classes. Modified because the rule
1017 'primary' couldn't work. */
1018 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1019 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1020 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1021 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1024 this_or_super: /* Added, simplifies error diagnostics */
1027 tree wfl = build_wfl_node (this_identifier_node);
1028 EXPR_WFL_LINECOL (wfl) = $1.location;
1033 tree wfl = build_wfl_node (super_identifier_node);
1034 EXPR_WFL_LINECOL (wfl) = $1.location;
1039 /* 19.9 Productions from 9: Interfaces */
1040 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1041 interface_declaration:
1042 INTERFACE_TK identifier
1043 { create_interface (0, $2, NULL_TREE); }
1048 | modifiers INTERFACE_TK identifier
1049 { create_interface ($1, $3, NULL_TREE); }
1054 | INTERFACE_TK identifier extends_interfaces
1055 { create_interface (0, $2, $3); }
1060 | modifiers INTERFACE_TK identifier extends_interfaces
1061 { create_interface ($1, $3, $4); }
1066 | INTERFACE_TK identifier error
1067 {yyerror ("'{' expected"); RECOVER;}
1068 | modifiers INTERFACE_TK identifier error
1069 {yyerror ("'{' expected"); RECOVER;}
1073 EXTENDS_TK interface_type
1075 ctxp->interface_number = 1;
1076 $$ = build_tree_list ($2, NULL_TREE);
1078 | extends_interfaces C_TK interface_type
1080 ctxp->interface_number++;
1081 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1084 {yyerror ("Invalid interface type"); RECOVER;}
1085 | extends_interfaces C_TK error
1086 {yyerror ("Missing term"); RECOVER;}
1092 | OCB_TK interface_member_declarations CCB_TK
1096 interface_member_declarations:
1097 interface_member_declaration
1098 | interface_member_declarations interface_member_declaration
1101 interface_member_declaration:
1102 constant_declaration
1103 | abstract_method_declaration
1104 | class_declaration /* Added, JDK1.1 inner classes */
1105 { $$ = parse_jdk1_1_error ("inner class declaration"); }
1106 | interface_declaration /* Added, JDK1.1 inner classes */
1107 { $$ = parse_jdk1_1_error ("inner interface declaration"); }
1110 constant_declaration:
1114 abstract_method_declaration:
1117 check_abstract_method_header ($1);
1118 current_function_decl = NULL_TREE; /* FIXME ? */
1120 | method_header error
1121 {yyerror ("';' expected"); RECOVER;}
1124 /* 19.10 Productions from 10: Arrays */
1127 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1128 | OCB_TK variable_initializers CCB_TK
1129 { $$ = build_new_array_init ($1.location, $2); }
1130 | OCB_TK variable_initializers C_TK CCB_TK
1131 { $$ = build_new_array_init ($1.location, $2); }
1134 variable_initializers:
1135 variable_initializer
1137 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1140 | variable_initializers C_TK variable_initializer
1142 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1144 | variable_initializers C_TK error
1145 {yyerror ("Missing term"); RECOVER;}
1148 /* 19.11 Production from 14: Blocks and Statements */
1151 { $$ = empty_stmt_node; }
1152 | block_begin block_statements block_end
1164 maybe_absorb_scoping_blocks ();
1171 | block_statements block_statement
1175 local_variable_declaration_statement
1177 { java_method_add_stmt (current_function_decl, $1); }
1178 | class_declaration /* Added, JDK1.1 inner classes */
1179 { parse_jdk1_1_error ("inner class declaration"); }
1182 local_variable_declaration_statement:
1183 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1186 local_variable_declaration:
1187 type variable_declarators
1188 { declare_local_variables (0, $1, $2); }
1189 | modifiers type variable_declarators /* Added, JDK1.1 final locals */
1190 { declare_local_variables ($1, $2, $3); }
1194 statement_without_trailing_substatement
1197 | if_then_else_statement
1201 /* If the for loop is unlabeled, we must return the
1202 block it was defined it. It our last chance to
1203 get a hold on it. */
1204 if (!LOOP_HAS_LABEL_P ($$))
1210 statement_without_trailing_substatement
1211 | labeled_statement_nsi
1212 | if_then_else_statement_nsi
1213 | while_statement_nsi
1217 statement_without_trailing_substatement:
1220 | expression_statement
1224 | continue_statement
1226 | synchronized_statement
1233 { $$ = empty_stmt_node; }
1237 identifier REL_CL_TK
1239 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1240 EXPR_WFL_NODE ($1));
1242 push_labeled_block ($$);
1243 PUSH_LABELED_BLOCK ($$);
1248 label_decl statement
1249 { $$ = finish_labeled_statement ($1, $2); }
1251 {yyerror ("':' expected"); RECOVER;}
1254 labeled_statement_nsi:
1255 label_decl statement_nsi
1256 { $$ = finish_labeled_statement ($1, $2); }
1259 /* We concentrate here a bunch of error handling rules that we couldn't write
1260 earlier, because expression_statement catches a missing ';'. */
1261 expression_statement:
1262 statement_expression SC_TK
1264 /* We have a statement. Generate a WFL around it so
1266 $$ = build_expr_wfl ($1, input_filename, lineno, 0);
1267 /* We know we have a statement, so set the debug
1268 info to be eventually generate here. */
1269 $$ = JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1273 if (ctxp->prevent_ese != lineno)
1274 yyerror ("Invalid expression statement");
1275 DRECOVER (expr_stmt);
1279 if (ctxp->prevent_ese != lineno)
1280 yyerror ("Invalid expression statement");
1281 DRECOVER (expr_stmt);
1285 if (ctxp->prevent_ese != lineno)
1286 yyerror ("Invalid expression statement");
1287 DRECOVER (expr_stmt);
1289 | this_or_super OP_TK error
1290 {yyerror ("')' expected"); RECOVER;}
1291 | this_or_super OP_TK CP_TK error
1293 yyerror ("Constructor invocation must be first "
1294 "thing in a constructor");
1297 | this_or_super OP_TK argument_list error
1298 {yyerror ("')' expected"); RECOVER;}
1299 | this_or_super OP_TK argument_list CP_TK error
1301 yyerror ("Constructor invocation must be first "
1302 "thing in a constructor");
1305 | name DOT_TK SUPER_TK error
1306 {yyerror ("'(' expected"); RECOVER;}
1307 | name DOT_TK SUPER_TK OP_TK error
1308 {yyerror ("')' expected"); RECOVER;}
1309 | name DOT_TK SUPER_TK OP_TK argument_list error
1310 {yyerror ("')' expected"); RECOVER;}
1311 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1312 {yyerror ("';' expected"); RECOVER;}
1313 | name DOT_TK SUPER_TK OP_TK CP_TK error
1314 {yyerror ("';' expected"); RECOVER;}
1317 statement_expression:
1319 | pre_increment_expression
1320 | pre_decrement_expression
1321 | post_increment_expression
1322 | post_decrement_expression
1324 | class_instance_creation_expression
1328 IF_TK OP_TK expression CP_TK statement
1330 $$ = build_if_else_statement ($2.location, $3,
1334 {yyerror ("'(' expected"); RECOVER;}
1336 {yyerror ("Missing term"); RECOVER;}
1337 | IF_TK OP_TK expression error
1338 {yyerror ("')' expected"); RECOVER;}
1341 if_then_else_statement:
1342 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1343 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1346 if_then_else_statement_nsi:
1347 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1348 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1358 /* Make into "proper list" of COMPOUND_EXPRs.
1359 I.e. make the last statment also have its own
1361 maybe_absorb_scoping_blocks ();
1362 TREE_OPERAND ($1, 1) = exit_block ();
1363 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1368 SWITCH_TK OP_TK expression CP_TK
1370 $$ = build (SWITCH_EXPR, NULL_TREE, $3, NULL_TREE);
1371 EXPR_WFL_LINECOL ($$) = $2.location;
1374 {yyerror ("'(' expected"); RECOVER;}
1375 | SWITCH_TK OP_TK error
1376 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1377 | SWITCH_TK OP_TK expression CP_TK error
1378 {yyerror ("'{' expected"); RECOVER;}
1381 /* Default assignment is there to avoid type node on switch_block
1387 | OCB_TK switch_labels CCB_TK
1389 | OCB_TK switch_block_statement_groups CCB_TK
1391 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1395 switch_block_statement_groups:
1396 switch_block_statement_group
1397 | switch_block_statement_groups switch_block_statement_group
1400 switch_block_statement_group:
1401 switch_labels block_statements
1406 | switch_labels switch_label
1410 CASE_TK constant_expression REL_CL_TK
1412 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1413 EXPR_WFL_LINECOL (lab) = $1.location;
1414 java_method_add_stmt (current_function_decl, lab);
1416 | DEFAULT_TK REL_CL_TK
1418 tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
1419 EXPR_WFL_LINECOL (lab) = $1.location;
1420 java_method_add_stmt (current_function_decl, lab);
1423 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1424 | CASE_TK constant_expression error
1425 {yyerror ("':' expected"); RECOVER;}
1427 {yyerror ("':' expected"); RECOVER;}
1431 WHILE_TK OP_TK expression CP_TK
1433 tree body = build_loop_body ($2.location, $3, 0);
1434 $$ = build_new_loop (body);
1439 while_expression statement
1440 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1442 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1443 | WHILE_TK OP_TK error
1444 {yyerror ("Missing term and ')' expected"); RECOVER;}
1445 | WHILE_TK OP_TK expression error
1446 {yyerror ("')' expected"); RECOVER;}
1449 while_statement_nsi:
1450 while_expression statement_nsi
1451 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1457 tree body = build_loop_body (0, NULL_TREE, 1);
1458 $$ = build_new_loop (body);
1460 /* Need error handing here. FIXME */
1464 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1465 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1469 for_begin SC_TK expression SC_TK for_update CP_TK statement
1470 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7); }
1471 | for_begin SC_TK SC_TK for_update CP_TK statement
1473 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1474 /* We have not condition, so we get rid of the EXIT_EXPR */
1475 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1478 | for_begin SC_TK error
1479 {yyerror ("Invalid control expression"); RECOVER;}
1480 | for_begin SC_TK expression SC_TK error
1481 {yyerror ("Invalid update expression"); RECOVER;}
1482 | for_begin SC_TK SC_TK error
1483 {yyerror ("Invalid update expression"); RECOVER;}
1487 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1488 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1489 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1491 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1492 /* We have not condition, so we get rid of the EXIT_EXPR */
1493 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1501 /* This scope defined for local variable that may be
1502 defined within the scope of the for loop */
1506 {yyerror ("'(' expected"); DRECOVER(for_1);}
1507 | FOR_TK OP_TK error
1508 {yyerror ("Invalid init statement"); RECOVER;}
1514 /* We now declare the loop body. The loop is
1515 declared as a for loop. */
1516 tree body = build_loop_body (0, NULL_TREE, 0);
1517 $$ = build_new_loop (body);
1518 IS_FOR_LOOP_P ($$) = 1;
1519 /* The loop is added to the current block the for
1520 statement is defined within */
1521 java_method_add_stmt (current_function_decl, $$);
1524 for_init: /* Can be empty */
1525 { $$ = empty_stmt_node; }
1526 | statement_expression_list
1528 /* Init statement recorded within the previously
1529 defined block scope */
1530 $$ = java_method_add_stmt (current_function_decl, $1);
1532 | local_variable_declaration
1534 /* Local variable are recorded within the previously
1535 defined block scope */
1538 | statement_expression_list error
1539 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1542 for_update: /* Can be empty */
1543 {$$ = empty_stmt_node;}
1544 | statement_expression_list
1545 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1548 statement_expression_list:
1549 statement_expression
1550 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1551 | statement_expression_list C_TK statement_expression
1552 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1553 | statement_expression_list C_TK error
1554 {yyerror ("Missing term"); RECOVER;}
1559 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1560 | BREAK_TK identifier SC_TK
1561 { $$ = build_bc_statement ($1.location, 1, $2); }
1563 {yyerror ("Missing term"); RECOVER;}
1564 | BREAK_TK identifier error
1565 {yyerror ("';' expected"); RECOVER;}
1570 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1571 | CONTINUE_TK identifier SC_TK
1572 { $$ = build_bc_statement ($1.location, 0, $2); }
1574 {yyerror ("Missing term"); RECOVER;}
1575 | CONTINUE_TK identifier error
1576 {yyerror ("';' expected"); RECOVER;}
1581 { $$ = build_return ($1.location, NULL_TREE); }
1582 | RETURN_TK expression SC_TK
1583 { $$ = build_return ($1.location, $2); }
1585 {yyerror ("Missing term"); RECOVER;}
1586 | RETURN_TK expression error
1587 {yyerror ("';' expected"); RECOVER;}
1591 THROW_TK expression SC_TK
1593 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1594 EXPR_WFL_LINECOL ($$) = $1.location;
1597 {yyerror ("Missing term"); RECOVER;}
1598 | THROW_TK expression error
1599 {yyerror ("';' expected"); RECOVER;}
1602 synchronized_statement:
1603 synchronized OP_TK expression CP_TK block
1605 $$ = build (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1606 EXPR_WFL_LINECOL ($$) =
1607 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1609 | synchronized OP_TK expression CP_TK error
1610 {yyerror ("'{' expected"); RECOVER;}
1611 | synchronized error
1612 {yyerror ("'(' expected"); RECOVER;}
1613 | synchronized OP_TK error CP_TK
1614 {yyerror ("Missing term"); RECOVER;}
1615 | synchronized OP_TK error
1616 {yyerror ("Missing term"); RECOVER;}
1622 if ((1 << $1) != ACC_SYNCHRONIZED)
1623 fatal ("synchronized was '%d' - yyparse", (1 << $1));
1628 TRY_TK block catches
1629 { $$ = build_try_statement ($1.location, $2, $3); }
1630 | TRY_TK block finally
1631 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1632 | TRY_TK block catches finally
1633 { $$ = build_try_finally_statement
1634 ($1.location, build_try_statement ($1.location,
1638 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1643 | catches catch_clause
1645 TREE_CHAIN ($2) = $1;
1651 catch_clause_parameter block
1653 java_method_add_stmt (current_function_decl, $2);
1658 catch_clause_parameter:
1659 CATCH_TK OP_TK formal_parameter CP_TK
1661 /* We add a block to define a scope for
1662 formal_parameter (CCBP). The formal parameter is
1663 declared initialized by the appropriate function
1665 tree ccpb = enter_block ();
1666 tree init = build_assignment (ASSIGN_TK, $2.location,
1668 soft_exceptioninfo_call_node);
1669 declare_local_variables (0, TREE_VALUE ($3),
1670 build_tree_list (TREE_PURPOSE ($3),
1672 $$ = build1 (CATCH_EXPR, NULL_TREE, ccpb);
1673 EXPR_WFL_LINECOL ($$) = $1.location;
1676 {yyerror ("'(' expected"); RECOVER;}
1677 | CATCH_TK OP_TK error
1678 {yyerror ("Missing term or ')' expected"); DRECOVER (2);}
1679 | CATCH_TK OP_TK error CP_TK /* That's for () */
1680 {yyerror ("')' expected"); DRECOVER (1);}
1687 {yyerror ("'{' expected"); RECOVER; }
1690 /* 19.12 Production from 15: Expressions */
1692 primary_no_new_array
1693 | array_creation_expression
1696 primary_no_new_array:
1699 { $$ = build_this ($1.location); }
1700 | OP_TK expression CP_TK
1702 | class_instance_creation_expression
1706 /* type DOT_TK CLASS_TK doens't work. So we split the rule
1707 'type' into its components. Missing is something for array,
1708 which will complete the reference_type part. FIXME */
1709 | name DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
1710 { $$ = parse_jdk1_1_error ("named class literals"); }
1711 | primitive_type DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
1712 { $$ = build_class_ref ($1); }
1713 | VOID_TK DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
1714 { $$ = build_class_ref (void_type_node); }
1715 /* Added, JDK1.1 inner classes. Documentation is wrong
1716 refering to a 'ClassName' (class_name) rule that doesn't
1717 exist. Used name instead. */
1718 | name DOT_TK THIS_TK
1719 { $$ = parse_jdk1_1_error ("class literals"); }
1720 | OP_TK expression error
1721 {yyerror ("')' expected"); RECOVER;}
1723 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1724 | primitive_type DOT_TK error
1725 {yyerror ("'class' expected" ); RECOVER;}
1726 | VOID_TK DOT_TK error
1727 {yyerror ("'class' expected" ); RECOVER;}
1730 class_instance_creation_expression:
1731 NEW_TK class_type OP_TK argument_list CP_TK
1732 { $$ = build_new_invocation ($2, $4); }
1733 | NEW_TK class_type OP_TK CP_TK
1734 { $$ = build_new_invocation ($2, NULL_TREE); }
1735 /* Added, JDK1.1 inner classes but modified to use
1736 'class_type' instead of 'TypeName' (type_name) mentionned
1737 in the documentation but doesn't exist. */
1738 | NEW_TK class_type OP_TK argument_list CP_TK class_body
1739 { $$ = parse_jdk1_1_error ("inner class instance creation"); }
1740 | NEW_TK class_type OP_TK CP_TK class_body
1741 { $$ = parse_jdk1_1_error ("inner class instance creation"); }
1742 /* Added, JDK1.1 inner classes, modified to use name or
1743 primary instead of primary solely which couldn't work in
1745 | something_dot_new identifier OP_TK CP_TK
1746 | something_dot_new identifier OP_TK CP_TK class_body
1747 | something_dot_new identifier OP_TK argument_list CP_TK
1748 | something_dot_new identifier OP_TK argument_list CP_TK class_body
1749 | NEW_TK error SC_TK
1750 {yyerror ("'(' expected"); DRECOVER(new_1);}
1751 | NEW_TK class_type error
1752 {yyerror ("'(' expected"); RECOVER;}
1753 | NEW_TK class_type OP_TK error
1754 {yyerror ("')' or term expected"); RECOVER;}
1755 | NEW_TK class_type OP_TK argument_list error
1756 {yyerror ("')' expected"); RECOVER;}
1757 | something_dot_new error
1758 {YYERROR_NOW; yyerror ("Identifier expected"); RECOVER;}
1759 | something_dot_new identifier error
1760 {yyerror ("'(' expected"); RECOVER;}
1763 something_dot_new: /* Added, not part of the specs. */
1765 | primary DOT_TK NEW_TK
1771 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1772 ctxp->formal_parameter_number = 1;
1774 | argument_list C_TK expression
1776 ctxp->formal_parameter_number += 1;
1777 $$ = tree_cons (NULL_TREE, $3, $1);
1779 | argument_list C_TK error
1780 {yyerror ("Missing term"); RECOVER;}
1783 array_creation_expression:
1784 NEW_TK primitive_type dim_exprs
1785 { $$ = build_newarray_node ($2, $3, 0); }
1786 | NEW_TK class_or_interface_type dim_exprs
1787 { $$ = build_newarray_node ($2, $3, 0); }
1788 | NEW_TK primitive_type dim_exprs dims
1789 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
1790 | NEW_TK class_or_interface_type dim_exprs dims
1791 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
1792 /* Added, JDK1.1 anonymous array. Initial documentation rule
1794 | NEW_TK class_or_interface_type dims array_initializer
1795 { $$ = parse_jdk1_1_error ("anonymous array"); }
1796 | NEW_TK primitive_type dims array_initializer
1797 { $$ = parse_jdk1_1_error ("anonymous array"); }
1798 | NEW_TK error CSB_TK
1799 {yyerror ("'[' expected"); DRECOVER ("]");}
1800 | NEW_TK error OSB_TK
1801 {yyerror ("']' expected"); RECOVER;}
1806 { $$ = build_tree_list (NULL_TREE, $1); }
1807 | dim_exprs dim_expr
1808 { $$ = tree_cons (NULL_TREE, $2, $$); }
1812 OSB_TK expression CSB_TK
1814 EXPR_WFL_LINECOL ($2) = $1.location;
1817 | OSB_TK expression error
1818 {yyerror ("']' expected"); RECOVER;}
1821 yyerror ("Missing term");
1822 yyerror ("']' expected");
1831 /* If not initialized, allocate memory for the osb
1833 if (!ctxp->osb_limit)
1835 allocate = ctxp->osb_limit = 32;
1836 ctxp->osb_depth = -1;
1838 /* If capacity overflown, reallocate a bigger chuck */
1839 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
1840 allocate = ctxp->osb_limit << 1;
1844 allocate *= sizeof (int);
1845 if (ctxp->osb_number)
1846 ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
1849 ctxp->osb_number = (int *)xmalloc (allocate);
1852 CURRENT_OSB (ctxp) = 1;
1854 | dims OSB_TK CSB_TK
1855 { CURRENT_OSB (ctxp)++; }
1857 { yyerror ("']' expected"); RECOVER;}
1861 primary DOT_TK identifier
1862 { $$ = make_qualified_primary ($1, $3, $2.location); }
1863 /* FIXME - REWRITE TO:
1864 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
1865 | SUPER_TK DOT_TK identifier
1868 build_wfl_node (super_identifier_node);
1869 EXPR_WFL_LINECOL (super_wfl) = $1.location;
1870 $$ = make_qualified_name (super_wfl, $3, $2.location);
1873 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
1878 { $$ = build_method_invocation ($1, NULL_TREE); }
1879 | name OP_TK argument_list CP_TK
1880 { $$ = build_method_invocation ($1, $3); }
1881 | primary DOT_TK identifier OP_TK CP_TK
1883 if (TREE_CODE ($1) == THIS_EXPR)
1884 $$ = build_this_super_qualified_invocation
1885 (1, $3, NULL_TREE, 0, $2.location);
1888 tree invok = build_method_invocation ($3, NULL_TREE);
1889 $$ = make_qualified_primary ($1, invok, $2.location);
1892 | primary DOT_TK identifier OP_TK argument_list CP_TK
1894 if (TREE_CODE ($1) == THIS_EXPR)
1895 $$ = build_this_super_qualified_invocation
1896 (1, $3, $5, 0, $2.location);
1899 tree invok = build_method_invocation ($3, $5);
1900 $$ = make_qualified_primary ($1, invok, $2.location);
1903 | SUPER_TK DOT_TK identifier OP_TK CP_TK
1905 $$ = build_this_super_qualified_invocation
1906 (0, $3, NULL_TREE, $1.location, $2.location);
1908 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
1910 $$ = build_this_super_qualified_invocation
1911 (0, $3, $5, $1.location, $2.location);
1913 /* Screws up thing. I let it here until I'm convinced it can
1915 | primary DOT_TK error
1916 {yyerror ("'(' expected"); DRECOVER(bad);} */
1917 | SUPER_TK DOT_TK error CP_TK
1918 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
1919 | SUPER_TK DOT_TK error DOT_TK
1920 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
1924 name OSB_TK expression CSB_TK
1925 { $$ = build_array_ref ($2.location, $1, $3); }
1926 | primary_no_new_array OSB_TK expression CSB_TK
1927 { $$ = build_array_ref ($2.location, $1, $3); }
1930 yyerror ("Missing term and ']' expected");
1931 DRECOVER(array_access);
1933 | name OSB_TK expression error
1935 yyerror ("']' expected");
1936 DRECOVER(array_access);
1938 | primary_no_new_array OSB_TK error
1940 yyerror ("Missing term and ']' expected");
1941 DRECOVER(array_access);
1943 | primary_no_new_array OSB_TK expression error
1945 yyerror ("']' expected");
1946 DRECOVER(array_access);
1953 | post_increment_expression
1954 | post_decrement_expression
1957 post_increment_expression:
1958 postfix_expression INCR_TK
1959 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
1962 post_decrement_expression:
1963 postfix_expression DECR_TK
1964 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
1968 pre_increment_expression
1969 | pre_decrement_expression
1970 | PLUS_TK unary_expression
1971 {$$ = build_unaryop ($1.token, $1.location, $2); }
1972 | MINUS_TK unary_expression
1973 {$$ = build_unaryop ($1.token, $1.location, $2); }
1974 | unary_expression_not_plus_minus
1976 {yyerror ("Missing term"); RECOVER}
1978 {yyerror ("Missing term"); RECOVER}
1981 pre_increment_expression:
1982 INCR_TK unary_expression
1983 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
1985 {yyerror ("Missing term"); RECOVER}
1988 pre_decrement_expression:
1989 DECR_TK unary_expression
1990 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
1992 {yyerror ("Missing term"); RECOVER}
1995 unary_expression_not_plus_minus:
1997 | NOT_TK unary_expression
1998 {$$ = build_unaryop ($1.token, $1.location, $2); }
1999 | NEG_TK unary_expression
2000 {$$ = build_unaryop ($1.token, $1.location, $2); }
2003 {yyerror ("Missing term"); RECOVER}
2005 {yyerror ("Missing term"); RECOVER}
2008 cast_expression: /* Error handling here is potentially weak */
2009 OP_TK primitive_type dims CP_TK unary_expression
2012 while (CURRENT_OSB (ctxp)--)
2013 type = build_java_array_type (type, -1);
2015 $$ = build_cast ($1.location, type, $5);
2017 | OP_TK primitive_type CP_TK unary_expression
2018 { $$ = build_cast ($1.location, $2, $4); }
2019 | OP_TK expression CP_TK unary_expression_not_plus_minus
2020 { $$ = build_cast ($1.location, $2, $4); }
2021 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2024 while (CURRENT_OSB (ctxp)--)
2025 obstack_1grow (&temporary_obstack, '[');
2027 obstack_grow0 (&temporary_obstack,
2028 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2029 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2030 ptr = obstack_finish (&temporary_obstack);
2031 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2032 $$ = build_cast ($1.location, $2, $5);
2034 | OP_TK primitive_type OSB_TK error
2035 {yyerror ("']' expected, invalid type expression");}
2038 if (ctxp->prevent_ese != lineno)
2039 yyerror ("Invalid type expression"); RECOVER;
2042 | OP_TK primitive_type dims CP_TK error
2043 {yyerror ("Missing term"); RECOVER;}
2044 | OP_TK primitive_type CP_TK error
2045 {yyerror ("Missing term"); RECOVER;}
2046 | OP_TK name dims CP_TK error
2047 {yyerror ("Missing term"); RECOVER;}
2050 multiplicative_expression:
2052 | multiplicative_expression MULT_TK unary_expression
2054 $$ = build_binop (BINOP_LOOKUP ($2.token),
2055 $2.location, $1, $3);
2057 | multiplicative_expression DIV_TK unary_expression
2059 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2062 | multiplicative_expression REM_TK unary_expression
2064 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2067 | multiplicative_expression MULT_TK error
2068 {yyerror ("Missing term"); RECOVER;}
2069 | multiplicative_expression DIV_TK error
2070 {yyerror ("Missing term"); RECOVER;}
2071 | multiplicative_expression REM_TK error
2072 {yyerror ("Missing term"); RECOVER;}
2075 additive_expression:
2076 multiplicative_expression
2077 | additive_expression PLUS_TK multiplicative_expression
2079 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2082 | additive_expression MINUS_TK multiplicative_expression
2084 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2087 | additive_expression PLUS_TK error
2088 {yyerror ("Missing term"); RECOVER;}
2089 | additive_expression MINUS_TK error
2090 {yyerror ("Missing term"); RECOVER;}
2095 | shift_expression LS_TK additive_expression
2097 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2100 | shift_expression SRS_TK additive_expression
2102 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2105 | shift_expression ZRS_TK additive_expression
2107 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2110 | shift_expression LS_TK error
2111 {yyerror ("Missing term"); RECOVER;}
2112 | shift_expression SRS_TK error
2113 {yyerror ("Missing term"); RECOVER;}
2114 | shift_expression ZRS_TK error
2115 {yyerror ("Missing term"); RECOVER;}
2118 relational_expression:
2120 | relational_expression LT_TK shift_expression
2122 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2125 | relational_expression GT_TK shift_expression
2127 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2130 | relational_expression LTE_TK shift_expression
2132 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2135 | relational_expression GTE_TK shift_expression
2137 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2140 | relational_expression INSTANCEOF_TK reference_type
2141 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2142 | relational_expression LT_TK error
2143 {yyerror ("Missing term"); RECOVER;}
2144 | relational_expression GT_TK error
2145 {yyerror ("Missing term"); RECOVER;}
2146 | relational_expression LTE_TK error
2147 {yyerror ("Missing term"); RECOVER;}
2148 | relational_expression GTE_TK error
2149 {yyerror ("Missing term"); RECOVER;}
2150 | relational_expression INSTANCEOF_TK error
2151 {yyerror ("Invalid reference type"); RECOVER;}
2154 equality_expression:
2155 relational_expression
2156 | equality_expression EQ_TK relational_expression
2158 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2161 | equality_expression NEQ_TK relational_expression
2163 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2166 | equality_expression EQ_TK error
2167 {yyerror ("Missing term"); RECOVER;}
2168 | equality_expression NEQ_TK error
2169 {yyerror ("Missing term"); RECOVER;}
2174 | and_expression AND_TK equality_expression
2176 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2179 | and_expression AND_TK error
2180 {yyerror ("Missing term"); RECOVER;}
2183 exclusive_or_expression:
2185 | exclusive_or_expression XOR_TK and_expression
2187 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2190 | exclusive_or_expression XOR_TK error
2191 {yyerror ("Missing term"); RECOVER;}
2194 inclusive_or_expression:
2195 exclusive_or_expression
2196 | inclusive_or_expression OR_TK exclusive_or_expression
2198 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2201 | inclusive_or_expression OR_TK error
2202 {yyerror ("Missing term"); RECOVER;}
2205 conditional_and_expression:
2206 inclusive_or_expression
2207 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2209 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2212 | conditional_and_expression BOOL_AND_TK error
2213 {yyerror ("Missing term"); RECOVER;}
2216 conditional_or_expression:
2217 conditional_and_expression
2218 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2220 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2223 | conditional_or_expression BOOL_OR_TK error
2224 {yyerror ("Missing term"); RECOVER;}
2227 conditional_expression: /* Error handling here is weak */
2228 conditional_or_expression
2229 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2231 $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2232 EXPR_WFL_LINECOL ($$) = $2.location;
2234 | conditional_or_expression REL_QM_TK REL_CL_TK error
2237 yyerror ("Missing term");
2240 | conditional_or_expression REL_QM_TK error
2241 {yyerror ("Missing term"); DRECOVER (2);}
2242 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2243 {yyerror ("Missing term"); DRECOVER (3);}
2246 assignment_expression:
2247 conditional_expression
2252 left_hand_side assignment_operator assignment_expression
2253 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2254 | left_hand_side assignment_operator error
2256 if (ctxp->prevent_ese != lineno)
2257 yyerror ("Missing term");
2268 assignment_operator:
2274 assignment_expression
2277 constant_expression:
2284 /* Flag for the error report routine to issue the error the first time
2285 it's called (overriding the default behavior which is to drop the
2286 first invocation and honor the second one, taking advantage of a
2288 static int force_error = 0;
2290 /* Create a new parser context and make it the current one. */
2293 java_push_parser_context ()
2295 struct parser_ctxt *new =
2296 (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2298 bzero ((PTR) new, sizeof (struct parser_ctxt));
2303 ctxp->incomplete_class = ctxp->next->incomplete_class;
2304 ctxp->gclass_list = ctxp->next->gclass_list;
2308 /* If the first file of a file list was a class file, no context
2309 exists for a source file to be parsed. This boolean remembers that
2310 java_parser_context_save_global might have created a dummy one, so
2311 that java_parser_context_restore_global can pop it. */
2312 static int extra_ctxp_pushed_p = 0;
2315 java_parser_context_save_global ()
2319 java_push_parser_context ();
2320 extra_ctxp_pushed_p = 1;
2322 ctxp->finput = finput;
2323 ctxp->lineno = lineno;
2324 ctxp->current_class = current_class;
2325 ctxp->filename = input_filename;
2326 ctxp->current_function_decl = current_function_decl;
2330 java_parser_context_restore_global ()
2332 finput = ctxp->finput;
2333 lineno = ctxp->lineno;
2334 current_class = ctxp->current_class;
2335 input_filename = ctxp->filename;
2336 current_function_decl = ctxp->current_function_decl;
2337 if (!ctxp->next && extra_ctxp_pushed_p)
2339 java_pop_parser_context (0);
2340 extra_ctxp_pushed_p = 0;
2345 java_pop_parser_context (generate)
2349 struct parser_ctxt *toFree, *next;
2358 next->incomplete_class = ctxp->incomplete_class;
2359 next->gclass_list = ctxp->gclass_list;
2360 lineno = ctxp->lineno;
2361 finput = ctxp->finput;
2362 current_class = ctxp->current_class;
2365 /* Set the single import class file flag to 0 for the current list
2366 of imported things */
2367 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2368 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 0;
2370 /* And restore those of the previous context */
2371 if ((ctxp = next)) /* Assignment is really meant here */
2372 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2373 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
2377 toFree->next = ctxp_for_generation;
2378 ctxp_for_generation = toFree;
2384 /* Reporting JDK1.1 features not implemented */
2387 parse_jdk1_1_error (msg)
2390 sorry (": `%s' JDK1.1(TM) feature", msg);
2392 return empty_stmt_node;
2395 static int do_warning = 0;
2402 static int prev_lineno;
2403 static char *prev_msg;
2406 char *remainder, *code_from_source;
2407 extern struct obstack temporary_obstack;
2409 if (!force_error && prev_lineno == lineno)
2412 /* Save current error location but report latter, when the context is
2414 if (ctxp->java_error_flag == 0)
2416 ctxp->java_error_flag = 1;
2418 /* Do something to use the previous line if we're reaching the
2419 end of the file... */
2420 #ifdef VERBOSE_SKELETON
2421 printf ("* Error detected (%s)\n", (msg ? msg : "(null)"));
2426 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2427 if (!force_error && msg == prev_msg && prev_lineno == elc.line)
2430 ctxp->java_error_flag = 0;
2432 java_warning_count++;
2436 if (elc.col == 0 && msg[1] == ';')
2438 elc.col = ctxp->p_line->char_col-1;
2439 elc.line = ctxp->p_line->lineno;
2442 save_lineno = lineno;
2443 prev_lineno = lineno = elc.line;
2446 code_from_source = java_get_line_col (ctxp->filename, elc.line, elc.col);
2447 obstack_grow0 (&temporary_obstack,
2448 code_from_source, strlen (code_from_source));
2449 remainder = obstack_finish (&temporary_obstack);
2451 warning ("%s.\n%s", msg, remainder);
2453 error ("%s.\n%s", msg, remainder);
2455 /* This allow us to cheaply avoid an extra 'Invalid expression
2456 statement' error report when errors have been already reported on
2457 the same line. This occurs when we report an error but don't have
2458 a synchronization point other than ';', which
2459 expression_statement is the only one to take care of. */
2460 ctxp->prevent_ese = lineno = save_lineno;
2464 issue_warning_error_from_context (cl, msg, ap)
2469 char *saved, *saved_input_filename;
2471 vsprintf (buffer, msg, ap);
2474 ctxp->elc.line = EXPR_WFL_LINENO (cl);
2475 ctxp->elc.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 :
2476 (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
2478 /* We have a CL, that's a good reason for using it if it contains data */
2479 saved = ctxp->filename;
2480 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
2481 ctxp->filename = EXPR_WFL_FILENAME (cl);
2482 saved_input_filename = input_filename;
2483 input_filename = ctxp->filename;
2485 java_error (buffer);
2486 ctxp->filename = saved;
2487 input_filename = saved_input_filename;
2491 /* Issue an error message at a current source line CL */
2494 parse_error_context VPROTO ((tree cl, const char *msg, ...))
2496 #ifndef ANSI_PROTOTYPES
2503 #ifndef ANSI_PROTOTYPES
2504 cl = va_arg (ap, tree);
2505 msg = va_arg (ap, const char *);
2507 issue_warning_error_from_context (cl, msg, ap);
2511 /* Issue a warning at a current source line CL */
2514 parse_warning_context VPROTO ((tree cl, const char *msg, ...))
2516 #ifndef ANSI_PROTOTYPES
2523 #ifndef ANSI_PROTOTYPES
2524 cl = va_arg (ap, tree);
2525 msg = va_arg (ap, const char *);
2528 force_error = do_warning = 1;
2529 issue_warning_error_from_context (cl, msg, ap);
2530 do_warning = force_error = 0;
2535 find_expr_with_wfl (node)
2543 switch (TREE_CODE (node))
2546 node = BLOCK_EXPR_BODY (node);
2550 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
2553 node = TREE_OPERAND (node, 1);
2557 node = TREE_OPERAND (node, 0);
2560 case LABELED_BLOCK_EXPR:
2561 node = TREE_OPERAND (node, 1);
2565 code = TREE_CODE_CLASS (TREE_CODE (node));
2566 if (((code == '1') || (code == '2') || (code == 'e'))
2567 && EXPR_WFL_LINECOL (node))
2575 /* Issue a missing return statement error. Uses METHOD to figure the
2576 last line of the method the error occurs in. */
2579 missing_return_error (method)
2582 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
2583 parse_error_context (wfl_operator, "Missing return statement");
2586 /* Issue an unreachable statement error. From NODE, find the next
2587 statement to report appropriately. */
2589 unreachable_stmt_error (node)
2592 /* Browse node to find the next expression node that has a WFL. Use
2593 the location to report the error */
2594 if (TREE_CODE (node) == COMPOUND_EXPR)
2595 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
2597 node = find_expr_with_wfl (node);
2601 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
2602 parse_error_context (wfl_operator, "Unreachable statement");
2605 fatal ("Can't get valid statement - unreachable_stmt_error");
2609 java_report_errors ()
2611 if (java_error_count)
2612 fprintf (stderr, "%d error%s",
2613 java_error_count, (java_error_count == 1 ? "" : "s"));
2614 if (java_warning_count)
2615 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
2616 java_warning_count, (java_warning_count == 1 ? "" : "s"));
2617 if (java_error_count || java_warning_count)
2618 putc ('\n', stderr);
2619 return java_error_count;
2623 java_accstring_lookup (flags)
2626 static char buffer [80];
2627 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
2629 /* Access modifier looked-up first for easier report on forbidden
2631 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
2632 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
2633 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
2634 if (flags & ACC_STATIC) COPY_RETURN ("static");
2635 if (flags & ACC_FINAL) COPY_RETURN ("final");
2636 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
2637 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
2638 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
2639 if (flags & ACC_NATIVE) COPY_RETURN ("native");
2640 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
2641 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
2648 /* Issuing error messages upon redefinition of classes, interfaces or
2652 classitf_redefinition_error (context, id, decl, cl)
2656 parse_error_context (cl, "%s `%s' already defined in %s:%d",
2657 context, IDENTIFIER_POINTER (id),
2658 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
2659 /* Here we should point out where its redefined. It's a unicode. FIXME */
2663 variable_redefinition_error (context, name, type, line)
2664 tree context, name, type;
2669 /* Figure a proper name for type. We might haven't resolved it */
2670 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
2671 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
2673 type_name = lang_printable_name (type, 0);
2675 parse_error_context (context,
2676 "Variable `%s' is already defined in this method and "
2677 "was declared `%s %s' at line %d",
2678 IDENTIFIER_POINTER (name),
2679 type_name, IDENTIFIER_POINTER (name), line);
2683 build_array_from_name (type, type_wfl, name, ret_name)
2684 tree type, type_wfl, name, *ret_name;
2689 /* Eventually get more dims */
2690 string = IDENTIFIER_POINTER (name);
2691 while (string [more_dims] == '[')
2694 /* If we have, then craft a new type for this variable */
2697 name = get_identifier (&string [more_dims]);
2699 /* If we have a pointer, use its type */
2700 if (TREE_CODE (type) == POINTER_TYPE)
2701 type = TREE_TYPE (type);
2703 /* Building the first dimension of a primitive type uses this
2705 if (JPRIMITIVE_TYPE_P (type))
2707 type = build_java_array_type (type, -1);
2708 CLASS_LOADED_P (type) = 1;
2711 /* Otherwise, if we have a WFL for this type, use it (the type
2712 is already an array on an unresolved type, and we just keep
2713 on adding dimensions) */
2717 /* Add all the dimensions */
2719 type = build_unresolved_array_type (type);
2721 /* The type may have been incomplete in the first place */
2723 type = obtain_incomplete_type (type);
2730 /* Build something that the type identifier resolver will identify as
2731 being an array to an unresolved type. TYPE_WFL is a WFL on a
2735 build_unresolved_array_type (type_or_wfl)
2740 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
2741 just create a array type */
2742 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
2744 tree type = build_java_array_type (type_or_wfl, -1);
2745 CLASS_LOADED_P (type) = CLASS_LOADED_P (type_or_wfl);
2749 obstack_1grow (&temporary_obstack, '[');
2750 obstack_grow0 (&temporary_obstack,
2751 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
2752 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
2753 ptr = obstack_finish (&temporary_obstack);
2754 return build_expr_wfl (get_identifier (ptr),
2755 EXPR_WFL_FILENAME (type_or_wfl),
2756 EXPR_WFL_LINENO (type_or_wfl),
2757 EXPR_WFL_COLNO (type_or_wfl));
2760 /* Check modifiers. If one doesn't fit, retrieve it in its declaration line
2761 and point it out. */
2764 check_modifiers (message, value, mask)
2769 /* Should point out the one that don't fit. ASCII/unicode,
2770 going backward. FIXME */
2773 int i, remainder = value & ~mask;
2774 for (i = 0; i <= 10; i++)
2775 if ((1 << i) & remainder)
2776 parse_error_context (ctxp->modifier_ctx [i], message,
2777 java_accstring_lookup (1 << i));
2782 parser_add_interface (class_decl, interface_decl, wfl)
2783 tree class_decl, interface_decl, wfl;
2785 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
2786 parse_error_context (wfl, "Interface `%s' repeated",
2787 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
2790 /* Bulk of common class/interface checks. Return 1 if an error was
2791 encountered. TAG is 0 for a class, 1 for an interface. */
2794 check_class_interface_creation (is_interface, flags, raw_name, qualified_name, decl, cl)
2795 int is_interface, flags;
2796 tree raw_name, qualified_name, decl, cl;
2801 fprintf (stderr, " %s %s", (is_interface ? "interface" : "class"),
2802 IDENTIFIER_POINTER (qualified_name));
2804 /* Scope of an interface/class type name:
2805 - Can't be imported by a single type import
2806 - Can't already exists in the package */
2807 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
2808 && (node = find_name_in_single_imports (raw_name)))
2811 (cl, "%s name `%s' clashes with imported type `%s'",
2812 (is_interface ? "Interface" : "Class"),
2813 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
2816 if (decl && CLASS_COMPLETE_P (decl))
2818 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
2819 qualified_name, decl, cl);
2823 /* If public, file name should match class/interface name */
2824 if (flags & ACC_PUBLIC)
2828 /* Contains OS dependent assumption on path separator. FIXME */
2829 for (f = &input_filename [strlen (input_filename)];
2830 f != input_filename && f[0] != '/' && f[0] != DIR_SEPARATOR;
2833 if (f[0] == '/' || f[0] == DIR_SEPARATOR)
2835 if (strncmp (IDENTIFIER_POINTER (raw_name),
2836 f , IDENTIFIER_LENGTH (raw_name)) ||
2837 f [IDENTIFIER_LENGTH (raw_name)] != '.')
2838 parse_error_context (cl, "Public %s `%s' must be defined in a file "
2840 (is_interface ? "interface" : "class"),
2841 IDENTIFIER_POINTER (qualified_name),
2842 IDENTIFIER_POINTER (raw_name));
2845 check_modifiers ((is_interface ?
2846 "Illegal modifier `%s' for interface declaration" :
2847 "Illegal modifier `%s' for class declaration"), flags,
2848 (is_interface ? INTERFACE_MODIFIERS : CLASS_MODIFIERS));
2852 /* If DECL is NULL, create and push a new DECL, record the current
2853 line CL and do other maintenance things. */
2856 maybe_create_class_interface_decl (decl, qualified_name, cl)
2857 tree decl, qualified_name, cl;
2860 decl = push_class (make_class (), qualified_name);
2862 /* Take care of the file and line business */
2863 DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
2864 /* If we're emiting xrefs, store the line/col number information */
2866 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (cl);
2868 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
2869 CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
2870 CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (TREE_TYPE (decl)) =
2871 IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
2873 ctxp->current_parsed_class = decl;
2875 /* Link the declaration to the already seen ones */
2876 TREE_CHAIN (decl) = ctxp->class_list;
2877 ctxp->class_list = decl;
2879 /* Create a new nodes in the global lists */
2880 ctxp->gclass_list = tree_cons (NULL_TREE, decl, ctxp->gclass_list);
2881 all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
2883 /* Install a new dependency list element */
2884 create_jdep_list (ctxp);
2886 SOURCE_FRONTEND_DEBUG (("Defining class/interface %s",
2887 IDENTIFIER_POINTER (qualified_name)));
2892 add_superinterfaces (decl, interface_list)
2893 tree decl, interface_list;
2896 /* Superinterface(s): if present and defined, parser_check_super_interface ()
2897 takes care of ensuring that:
2898 - This is an accessible interface type,
2899 - Circularity detection.
2900 parser_add_interface is then called. If present but not defined,
2901 the check operation is delayed until the super interface gets
2903 for (node = interface_list; node; node = TREE_CHAIN (node))
2905 tree current = TREE_PURPOSE (node);
2906 tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
2907 if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
2909 if (!parser_check_super_interface (idecl, decl, current))
2910 parser_add_interface (decl, idecl, current);
2913 register_incomplete_type (JDEP_INTERFACE,
2914 current, decl, NULL_TREE);
2918 /* Create an interface in pass1 and return its decl. Return the
2919 interface's decl in pass 2. */
2922 create_interface (flags, id, super)
2926 tree raw_name = EXPR_WFL_NODE (id);
2927 tree q_name = parser_qualified_classname (id);
2928 tree decl = IDENTIFIER_CLASS_VALUE (q_name);
2930 EXPR_WFL_NODE (id) = q_name; /* Keep source location, even if refined. */
2932 /* Basic checks: scope, redefinition, modifiers */
2933 if (check_class_interface_creation (1, flags, raw_name, q_name, decl, id))
2936 /* Interface modifiers check
2937 - public/abstract allowed (already done at that point)
2938 - abstract is obsolete (comes first, it's a warning, or should be)
2939 - Can't use twice the same (checked in the modifier rule) */
2940 if ((flags & ACC_ABSTRACT) && flag_redundant)
2941 parse_warning_context
2942 (MODIFIER_WFL (ABSTRACT_TK),
2943 "Redundant use of `abstract' modifier. Interface `%s' is implicitely "
2944 "abstract", IDENTIFIER_POINTER (raw_name));
2946 /* Create a new decl if DECL is NULL, otherwise fix it */
2947 decl = maybe_create_class_interface_decl (decl, q_name, id);
2949 /* Set super info and mark the class a complete */
2950 set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
2951 object_type_node, ctxp->interface_number);
2952 ctxp->interface_number = 0;
2953 CLASS_COMPLETE_P (decl) = 1;
2954 add_superinterfaces (decl, super);
2959 /* Create an class in pass1 and return its decl. Return class
2960 interface's decl in pass 2. */
2963 create_class (flags, id, super, interfaces)
2965 tree id, super, interfaces;
2967 tree raw_name = EXPR_WFL_NODE (id);
2968 tree class_id, decl;
2969 tree super_decl_type;
2971 class_id = parser_qualified_classname (id);
2972 decl = IDENTIFIER_CLASS_VALUE (class_id);
2973 ctxp->current_parsed_class_un = EXPR_WFL_NODE (id);
2974 EXPR_WFL_NODE (id) = class_id;
2976 /* Basic check: scope, redefinition, modifiers */
2977 if (check_class_interface_creation (0, flags, raw_name, class_id, decl, id))
2980 /* Class modifier check:
2981 - Allowed modifier (already done at that point)
2982 - abstract AND final forbidden
2983 - Public classes defined in the correct file */
2984 if ((flags & ACC_ABSTRACT) && (flags & ACC_FINAL))
2985 parse_error_context (id, "Class `%s' can't be declared both abstract "
2986 "and final", IDENTIFIER_POINTER (raw_name));
2988 /* Create a new decl if DECL is NULL, otherwise fix it */
2989 decl = maybe_create_class_interface_decl (decl, class_id, id);
2991 /* If SUPER exists, use it, otherwise use Object */
2994 /* Can't extend java.lang.Object */
2995 if (TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_id)) == object_type_node)
2997 parse_error_context (id, "Can't extend `java.lang.Object'");
3002 register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
3004 else if (TREE_TYPE (decl) != object_type_node)
3005 super_decl_type = object_type_node;
3006 /* We're defining java.lang.Object */
3008 super_decl_type = NULL_TREE;
3010 /* Set super info and mark the class a complete */
3011 set_super_info (flags, TREE_TYPE (decl), super_decl_type,
3012 ctxp->interface_number);
3013 ctxp->interface_number = 0;
3014 CLASS_COMPLETE_P (decl) = 1;
3015 add_superinterfaces (decl, interfaces);
3017 /* Eventually sets the @deprecated tag flag */
3018 CHECK_DEPRECATED (decl);
3023 /* Can't use lookup_field () since we don't want to load the class and
3024 can't set the CLASS_LOADED_P flag */
3027 find_field (class, name)
3032 for (decl = TYPE_FIELDS (class); decl; decl = TREE_CHAIN (decl))
3034 if (DECL_NAME (decl) == name)
3040 /* Wrap around lookup_field that doesn't potentially upset the value
3044 lookup_field_wrapper (class, name)
3049 java_parser_context_save_global ();
3050 decl = lookup_field (&type, name);
3051 java_parser_context_restore_global ();
3055 /* Find duplicate field within the same class declarations and report
3056 the error. Returns 1 if a duplicated field was found, 0
3060 duplicate_declaration_error_p (new_field_name, new_type, cl)
3061 tree new_field_name, new_type, cl;
3063 /* This might be modified to work with method decl as well */
3064 tree decl = find_field (TREE_TYPE (ctxp->current_parsed_class),
3068 char *t1 = strdup (purify_type_name
3069 ((TREE_CODE (new_type) == POINTER_TYPE
3070 && TREE_TYPE (new_type) == NULL_TREE) ?
3071 IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
3072 lang_printable_name (new_type, 1)));
3073 /* The type may not have been completed by the time we report
3075 char *t2 = strdup (purify_type_name
3076 ((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
3077 && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
3078 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
3079 lang_printable_name (TREE_TYPE (decl), 1)));
3081 (cl , "Duplicate variable declaration: `%s %s' was `%s %s' (%s:%d)",
3082 t1, IDENTIFIER_POINTER (new_field_name),
3083 t2, IDENTIFIER_POINTER (DECL_NAME (decl)),
3084 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3092 /* Field registration routine. If TYPE doesn't exist, field
3093 declarations are linked to the undefined TYPE dependency list, to
3094 be later resolved in java_complete_class () */
3097 register_fields (flags, type, variable_list)
3099 tree type, variable_list;
3101 tree current, saved_type;
3102 tree class_type = TREE_TYPE (ctxp->current_parsed_class);
3103 int saved_lineno = lineno;
3105 tree wfl = NULL_TREE;
3107 /* If we're adding fields to interfaces, those fields are public,
3109 if (CLASS_INTERFACE (TYPE_NAME (class_type)))
3111 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK),
3113 "%s", "interface field(s)");
3114 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (STATIC_TK),
3116 "%s", "interface field(s)");
3117 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (FINAL_TK),
3118 flags, ACC_FINAL, "%s", "interface field(s)");
3119 check_modifiers ("Illegal interface member modifier `%s'", flags,
3120 INTERFACE_FIELD_MODIFIERS);
3121 flags |= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
3124 /* Obtain a suitable type for resolution, if necessary */
3125 SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
3127 /* If TYPE is fully resolved and we don't have a reference, make one */
3128 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
3130 for (current = variable_list, saved_type = type; current;
3131 current = TREE_CHAIN (current), type = saved_type)
3135 tree cl = TREE_PURPOSE (current);
3136 tree init = TREE_VALUE (current);
3137 tree current_name = EXPR_WFL_NODE (cl);
3139 /* Process NAME, as it may specify extra dimension(s) for it */
3140 type = build_array_from_name (type, wfl, current_name, ¤t_name);
3142 /* Type adjustment. We may have just readjusted TYPE because
3143 the variable specified more dimensions. Make sure we have
3144 a reference if we can and don't have one already. Also
3145 change the name if we have an init. */
3146 if (type != saved_type)
3148 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
3150 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
3153 real_type = GET_REAL_TYPE (type);
3154 /* Check for redeclarations */
3155 if (duplicate_declaration_error_p (current_name, real_type, cl))
3158 /* Set lineno to the line the field was found and create a
3159 declaration for it. Eventually sets the @deprecated tag flag. */
3161 lineno = EXPR_WFL_LINECOL (cl);
3163 lineno = EXPR_WFL_LINENO (cl);
3164 field_decl = add_field (class_type, current_name, real_type, flags);
3165 CHECK_DEPRECATED (field_decl);
3167 /* Check if we must chain. */
3169 register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
3171 /* If we have an initialization value tied to the field */
3174 /* The field is declared static */
3175 if (flags & ACC_STATIC)
3177 /* We include the field and its initialization part into
3178 a list used to generate <clinit>. After <clinit> is
3179 walked, field initializations will be processed and
3180 fields initialized with known constants will be taken
3181 out of <clinit> and have their DECL_INITIAL set
3183 TREE_CHAIN (init) = ctxp->static_initialized;
3184 ctxp->static_initialized = init;
3185 DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
3186 if (TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
3187 TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
3189 /* A non-static field declared with an immediate initialization is
3190 to be initialized in <init>, if any. This field is remembered
3191 to be processed at the time of the generation of <init>. */
3194 TREE_CHAIN (init) = ctxp->non_static_initialized;
3195 ctxp->non_static_initialized = init;
3197 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
3200 lineno = saved_lineno;
3203 /* Generate the method $finit$ that initializes fields initialized
3204 upon declaration. */
3207 maybe_generate_finit ()
3209 tree mdecl, current;
3211 if (!ctxp->non_static_initialized || java_error_count)
3214 mdecl = create_artificial_method (TREE_TYPE (ctxp->current_parsed_class),
3215 ACC_PRIVATE, void_type_node,
3216 finit_identifier_node, end_params_node);
3217 start_artificial_method_body (mdecl);
3219 ctxp->non_static_initialized = nreverse (ctxp->non_static_initialized);
3220 for (current = ctxp->non_static_initialized; current;
3221 current = TREE_CHAIN (current))
3222 java_method_add_stmt (mdecl,
3223 build_debugable_stmt (EXPR_WFL_LINECOL (current),
3226 end_artificial_method_body (mdecl);
3227 CLASS_HAS_FINIT_P (TREE_TYPE (ctxp->current_parsed_class)) = 1;
3228 ctxp->non_static_initialized = NULL_TREE;
3231 /* Check whether it is necessary to generate a <clinit> for the class
3235 maybe_generate_clinit ()
3238 int is_interface = CLASS_INTERFACE (ctxp->current_parsed_class);
3239 int has_non_primitive_fields = 0;
3241 if (!ctxp->static_initialized || java_error_count)
3245 for (c = TYPE_FIELDS (TREE_TYPE (ctxp->current_parsed_class));
3246 c; c = TREE_CHAIN (c))
3247 has_non_primitive_fields |= !JPRIMITIVE_TYPE_P (TREE_TYPE (c));
3248 if (!has_non_primitive_fields && is_interface)
3251 mdecl = create_artificial_method (TREE_TYPE (ctxp->current_parsed_class),
3252 ACC_STATIC, void_type_node,
3253 clinit_identifier_node, end_params_node);
3254 start_artificial_method_body (mdecl);
3256 /* Keep initialization in order to enforce 8.5 */
3257 ctxp->static_initialized = nreverse (ctxp->static_initialized);
3259 /* We process the list of assignment we produced as the result of
3260 the declaration of initialized static field and add them as
3261 statement to the <clinit> method. */
3262 for (c = ctxp->static_initialized; c; c = TREE_CHAIN (c))
3264 /* We build the assignment expression that will initialize the
3265 field to its value. There are strict rules on static
3266 initializers (8.5). FIXME */
3267 java_method_add_stmt (mdecl,
3268 build_debugable_stmt (EXPR_WFL_LINECOL (c), c));
3271 end_artificial_method_body (mdecl);
3272 ctxp->static_initialized = NULL_TREE;
3275 /* Shared accros method_declarator and method_header to remember the
3276 patch stage that was reached during the declaration of the method.
3277 A method DECL is built differently is there is no patch
3278 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
3279 pending on the currently defined method. */
3281 static int patch_stage;
3283 /* Check the method declaration and add the method to its current
3284 class. If the argument list is known to contain incomplete types,
3285 the method is partially added and the registration will be resume
3286 once the method arguments resolved. If TYPE is NULL, we're dealing
3287 with a constructor. */
3290 method_header (flags, type, mdecl, throws)
3292 tree type, mdecl, throws;
3294 tree meth = TREE_VALUE (mdecl);
3295 tree id = TREE_PURPOSE (mdecl);
3296 tree this_class = TREE_TYPE (ctxp->current_parsed_class);
3297 tree type_wfl = NULL_TREE;
3298 tree meth_name = NULL_TREE, current, orig_arg;
3300 int constructor_ok = 0, must_chain;
3302 check_modifiers_consistency (flags);
3304 /* There are some forbidden modifiers for an abstract method and its
3305 class must be abstract as well. */
3306 if (type && (flags & ACC_ABSTRACT))
3308 ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
3309 ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
3310 ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
3311 ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
3312 ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED,id, "Synchronized");
3313 if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
3314 && !CLASS_INTERFACE (TYPE_NAME (this_class)))
3316 (id, "Class `%s' must be declared abstract to define abstract "
3318 IDENTIFIER_POINTER (DECL_NAME (ctxp->current_parsed_class)),
3319 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
3321 /* Things to be checked when declaring a constructor */
3324 int ec = java_error_count;
3325 /* 8.6: Constructor declarations: we might be trying to define a
3326 method without specifying a return type. */
3327 if (EXPR_WFL_NODE (id) != ctxp->current_parsed_class_un)
3329 (id, "Invalid method declaration, return type required");
3330 /* 8.6.3: Constructor modifiers */
3333 JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
3334 JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
3335 JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
3336 JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
3337 JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
3339 /* If we found error here, we don't consider it's OK to tread
3340 the method definition as a constructor, for the rest of this
3342 if (ec == java_error_count)
3346 /* Method declared within the scope of an interface are implicitly
3347 abstract and public. Conflicts with other erroneously provided
3348 modifiers are checked right after. */
3350 if (CLASS_INTERFACE (TYPE_NAME (this_class)))
3352 /* If FLAGS isn't set because of a modifier, turn the
3353 corresponding modifier WFL to NULL so we issue a warning on
3354 the obsolete use of the modifier */
3355 if (!(flags & ACC_PUBLIC))
3356 MODIFIER_WFL (PUBLIC_TK) = NULL;
3357 if (!(flags & ACC_ABSTRACT))
3358 MODIFIER_WFL (ABSTRACT_TK) = NULL;
3359 flags |= ACC_PUBLIC;
3360 flags |= ACC_ABSTRACT;
3363 /* Modifiers context reset moved up, so abstract method declaration
3364 modifiers can be later checked. */
3366 /* Set constructor returned type to void and method name to <init>,
3367 unless we found an error identifier the constructor (in which
3368 case we retain the original name) */
3371 type = void_type_node;
3373 meth_name = init_identifier_node;
3376 meth_name = EXPR_WFL_NODE (id);
3378 /* Do the returned type resolution and registration if necessary */
3379 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
3382 type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
3383 EXPR_WFL_NODE (id) = meth_name;
3384 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
3388 patch_stage = JDEP_METHOD_RETURN;
3389 register_incomplete_type (patch_stage, type_wfl, id, type);
3390 TREE_TYPE (meth) = GET_REAL_TYPE (type);
3393 TREE_TYPE (meth) = type;
3395 saved_lineno = lineno;
3396 /* When defining an abstract or interface method, the curly
3397 bracket at level 1 doesn't exist because there is no function
3399 lineno = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 :
3400 EXPR_WFL_LINENO (id));
3402 /* Remember the original argument list */
3403 orig_arg = TYPE_ARG_TYPES (meth);
3405 if (patch_stage) /* includes ret type and/or all args */
3408 meth = add_method_1 (this_class, flags, meth_name, meth);
3409 /* Patch for the return type */
3410 if (patch_stage == JDEP_METHOD_RETURN)
3412 jdep = CLASSD_LAST (ctxp->classd_list);
3413 JDEP_GET_PATCH (jdep) = &TREE_TYPE (TREE_TYPE (meth));
3415 /* This is the stop JDEP. METH allows the function's signature
3417 register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
3420 meth = add_method (this_class, flags, meth_name,
3421 build_java_signature (meth));
3423 /* Fix the method argument list so we have the argument name
3425 fix_method_argument_names (orig_arg, meth);
3427 /* Register the parameter number and re-install the current line
3429 DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
3430 lineno = saved_lineno;
3432 /* Register exception specified by the `throws' keyword for
3433 resolution and set the method decl appropriate field to the list.
3434 Note: the grammar ensures that what we get here are class
3438 throws = nreverse (throws);
3439 for (current = throws; current; current = TREE_CHAIN (current))
3441 register_incomplete_type (JDEP_EXCEPTION, TREE_VALUE (current),
3442 NULL_TREE, NULL_TREE);
3443 JDEP_GET_PATCH (CLASSD_LAST (ctxp->classd_list)) =
3444 &TREE_VALUE (current);
3446 DECL_FUNCTION_THROWS (meth) = throws;
3449 /* We set the DECL_NAME to ID so we can track the location where
3450 the function was declared. This allow us to report
3451 redefinition error accurately. When method are verified,
3452 DECL_NAME is reinstalled properly (using the content of the
3453 WFL node ID) (see check_method_redefinition). We don't do that
3454 when Object is being defined. Constructor <init> names will be
3455 reinstalled the same way. */
3456 if (TREE_TYPE (ctxp->current_parsed_class) != object_type_node)
3457 DECL_NAME (meth) = id;
3459 /* Set the flag if we correctly processed a constructor */
3461 DECL_CONSTRUCTOR_P (meth) = 1;
3463 /* Eventually set the @deprecated tag flag */
3464 CHECK_DEPRECATED (meth);
3470 fix_method_argument_names (orig_arg, meth)
3471 tree orig_arg, meth;
3473 tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
3474 if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
3476 TREE_PURPOSE (arg) = this_identifier_node;
3477 arg = TREE_CHAIN (arg);
3479 while (orig_arg != end_params_node)
3481 TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
3482 orig_arg = TREE_CHAIN (orig_arg);
3483 arg = TREE_CHAIN (arg);
3487 /* Complete the method declaration with METHOD_BODY. */
3490 finish_method_declaration (method_body)
3493 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
3494 maybe_absorb_scoping_blocks ();
3495 /* Exit function's body */
3497 /* Merge last line of the function with first line, directly in the
3498 function decl. It will be used to emit correct debug info. */
3499 DECL_SOURCE_LINE_MERGE (current_function_decl, ctxp->last_ccb_indent1);
3500 /* So we don't have an irrelevant function declaration context for
3501 the next static block we'll see. */
3502 current_function_decl = NULL_TREE;
3505 /* Build a an error message for constructor circularity errors. */
3508 constructor_circularity_msg (from, to)
3511 static char string [4096];
3512 char *t = strdup (lang_printable_name (from, 0));
3513 sprintf (string, "`%s' invokes `%s'", t, lang_printable_name (to, 0));
3518 /* Verify a circular call to METH. Return 1 if an error is found, 0
3522 verify_constructor_circularity (meth, current)
3525 static tree list = NULL_TREE;
3527 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
3529 if (TREE_VALUE (c) == meth)
3535 list = nreverse (list);
3536 for (liste = list; liste; liste = TREE_CHAIN (liste))
3539 (TREE_PURPOSE (TREE_PURPOSE (liste)),
3540 constructor_circularity_msg
3541 (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste))));
3545 t = strdup (lang_printable_name (meth, 0));
3546 parse_error_context (TREE_PURPOSE (c),
3547 "%s: recursive invocation of constructor `%s'",
3548 constructor_circularity_msg (current, meth), t);
3554 for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
3556 list = tree_cons (c, current, list);
3557 if (verify_constructor_circularity (meth, TREE_VALUE (c)))
3559 list = TREE_CHAIN (list);
3564 /* Check modifiers that can be declared but exclusively */
3567 check_modifiers_consistency (flags)
3571 tree cl = NULL_TREE;
3573 THIS_MODIFIER_ONLY (flags, ACC_PUBLIC, 0, acc_count, cl);
3574 THIS_MODIFIER_ONLY (flags, ACC_PRIVATE, 1, acc_count, cl);
3575 THIS_MODIFIER_ONLY (flags, ACC_PROTECTED, 2, acc_count, cl);
3578 (cl, "Inconsistent member declaration. At most one of `public', "
3579 "`private', or `protected' may be specified");
3582 /* Check the methode header METH for abstract specifics features */
3585 check_abstract_method_header (meth)
3588 int flags = get_access_flags_from_decl (meth);
3589 /* DECL_NAME might still be a WFL node */
3590 tree name = GET_METHOD_NAME (meth);
3592 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (ABSTRACT_TK), flags,
3593 ACC_ABSTRACT, "abstract method `%s'",
3594 IDENTIFIER_POINTER (name));
3595 OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (PUBLIC_TK), flags,
3596 ACC_PUBLIC, "abstract method `%s'",
3597 IDENTIFIER_POINTER (name));
3599 check_modifiers ("Illegal modifier `%s' for interface method",
3600 flags, INTERFACE_METHOD_MODIFIERS);
3603 /* Create a FUNCTION_TYPE node and start augmenting it with the
3604 declared function arguments. Arguments type that can't be resolved
3605 are left as they are, but the returned node is marked as containing
3606 incomplete types. */
3609 method_declarator (id, list)
3612 tree arg_types = NULL_TREE, current, node;
3613 tree meth = make_node (FUNCTION_TYPE);
3616 patch_stage = JDEP_NO_PATCH;
3618 for (current = list; current; current = TREE_CHAIN (current))
3621 tree wfl_name = TREE_PURPOSE (current);
3622 tree type = TREE_VALUE (current);
3623 tree name = EXPR_WFL_NODE (wfl_name);
3624 tree already, arg_node;
3625 tree type_wfl = NULL_TREE;
3628 /* Obtain a suitable type for resolution, if necessary */
3629 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
3631 /* Process NAME, as it may specify extra dimension(s) for it */
3632 type = build_array_from_name (type, type_wfl, name, &name);
3633 EXPR_WFL_NODE (wfl_name) = name;
3635 real_type = GET_REAL_TYPE (type);
3636 if (TREE_CODE (real_type) == RECORD_TYPE)
3638 real_type = promote_type (real_type);
3639 if (TREE_CODE (type) == TREE_LIST)
3640 TREE_PURPOSE (type) = real_type;
3643 /* Check redefinition */
3644 for (already = arg_types; already; already = TREE_CHAIN (already))
3645 if (TREE_PURPOSE (already) == name)
3648 (wfl_name, "Variable `%s' is used more than once in the "
3649 "argument list of method `%s'", IDENTIFIER_POINTER (name),
3650 IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
3654 /* If we've an incomplete argument type, we know there is a location
3655 to patch when the type get resolved, later. */
3659 patch_stage = JDEP_METHOD;
3660 type = register_incomplete_type (patch_stage,
3661 type_wfl, wfl_name, type);
3662 jdep = CLASSD_LAST (ctxp->classd_list);
3663 JDEP_MISC (jdep) = id;
3666 /* The argument node: a name and a (possibly) incomplete type */
3667 arg_node = build_tree_list (name, real_type);
3669 JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
3670 TREE_CHAIN (arg_node) = arg_types;
3671 arg_types = arg_node;
3673 TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
3674 node = build_tree_list (id, meth);
3679 unresolved_type_p (wfl, returned)
3684 if (TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION)
3686 tree decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (wfl));
3688 *returned = (decl ? TREE_TYPE (decl) : NULL_TREE);
3696 /* From NAME, build a qualified identifier node using the
3697 qualification from the current package definition. */
3700 parser_qualified_classname (name)
3704 return merge_qualified_name (ctxp->package, EXPR_WFL_NODE (name));
3706 return EXPR_WFL_NODE (name);
3709 /* Called once the type a interface extends is resolved. Returns 0 if
3710 everything is OK. */
3713 parser_check_super_interface (super_decl, this_decl, this_wfl)
3714 tree super_decl, this_decl, this_wfl;
3716 tree super_type = TREE_TYPE (super_decl);
3718 /* Has to be an interface */
3719 if (!CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (super_decl))))
3722 (this_wfl, "Can't use %s `%s' to implement/extend %s `%s'",
3723 (TYPE_ARRAY_P (super_type) ? "array" : "class"),
3724 IDENTIFIER_POINTER (DECL_NAME (super_decl)),
3725 (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (this_decl))) ?
3726 "interface" : "class"),
3727 IDENTIFIER_POINTER (DECL_NAME (this_decl)));
3731 /* Check scope: same package OK, other package: OK if public */
3732 if (check_pkg_class_access (DECL_NAME (super_decl), lookup_cl (this_decl)))
3735 SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
3736 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
3737 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
3741 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
3742 0 if everthing is OK. */
3745 parser_check_super (super_decl, this_decl, wfl)
3746 tree super_decl, this_decl, wfl;
3748 tree super_type = TREE_TYPE (super_decl);
3750 /* SUPER should be a CLASS (neither an array nor an interface) */
3751 if (TYPE_ARRAY_P (super_type) || CLASS_INTERFACE (TYPE_NAME (super_type)))
3754 (wfl, "Class `%s' can't subclass %s `%s'",
3755 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
3756 (CLASS_INTERFACE (TYPE_NAME (super_type)) ? "interface" : "array"),
3757 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
3761 if (CLASS_FINAL (TYPE_NAME (super_type)))
3763 parse_error_context (wfl, "Can't subclass final classes: %s",
3764 IDENTIFIER_POINTER (DECL_NAME (super_decl)));
3768 /* Check scope: same package OK, other package: OK if public */
3769 if (check_pkg_class_access (DECL_NAME (super_decl), wfl))
3772 SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
3773 IDENTIFIER_POINTER (DECL_NAME (this_decl)),
3774 IDENTIFIER_POINTER (DECL_NAME (super_decl))));
3778 /* Create a new dependency list and link it (in a LIFO manner) to the
3779 CTXP list of type dependency list. */
3782 create_jdep_list (ctxp)
3783 struct parser_ctxt *ctxp;
3785 jdeplist *new = (jdeplist *)xmalloc (sizeof (jdeplist));
3786 new->first = new->last = NULL;
3787 new->next = ctxp->classd_list;
3788 ctxp->classd_list = new;
3792 reverse_jdep_list (ctxp)
3793 struct parser_ctxt *ctxp;
3795 register jdeplist *prev = NULL, *current, *next;
3796 for (current = ctxp->classd_list; current; current = next)
3798 next = current->next;
3799 current->next = prev;
3805 /* Create a fake pointer based on the ID stored in
3806 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
3807 registered again. */
3810 obtain_incomplete_type (type_name)
3815 if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
3816 name = EXPR_WFL_NODE (type_name);
3817 else if (INCOMPLETE_TYPE_P (type_name))
3818 name = TYPE_NAME (type_name);
3820 fatal ("invalid type name - obtain_incomplete_type");
3822 for (ptr = ctxp->incomplete_class; ptr; ptr = TREE_CHAIN (ptr))
3823 if (TYPE_NAME (ptr) == name)
3828 push_obstacks (&permanent_obstack, &permanent_obstack);
3829 BUILD_PTR_FROM_NAME (ptr, name);
3832 TREE_CHAIN (ptr) = ctxp->incomplete_class;
3833 ctxp->incomplete_class = ptr;
3839 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
3840 non NULL instead of computing a new fake type based on WFL. The new
3841 dependency is inserted in the current type dependency list, in FIFO
3845 register_incomplete_type (kind, wfl, decl, ptr)
3847 tree wfl, decl, ptr;
3849 jdep *new = (jdep *)xmalloc (sizeof (jdep));
3851 if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
3852 ptr = obtain_incomplete_type (wfl);
3854 JDEP_KIND (new) = kind;
3855 JDEP_DECL (new) = decl;
3856 JDEP_SOLV (new) = ptr;
3857 JDEP_WFL (new) = wfl;
3858 JDEP_CHAIN (new) = NULL;
3859 JDEP_MISC (new) = NULL_TREE;
3860 JDEP_GET_PATCH (new) = (tree *)NULL;
3862 JDEP_INSERT (ctxp->classd_list, new);
3868 java_check_circular_reference ()
3871 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
3873 tree type = TREE_TYPE (current);
3874 if (CLASS_INTERFACE (TYPE_NAME (type)))
3876 /* Check all interfaces this class extends */
3877 tree basetype_vec = TYPE_BINFO_BASETYPES (type);
3882 n = TREE_VEC_LENGTH (basetype_vec);
3883 for (i = 0; i < n; i++)
3885 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
3886 if (vec_elt && BINFO_TYPE (vec_elt) != object_type_node
3887 && interface_of_p (type, BINFO_TYPE (vec_elt)))
3888 parse_error_context (lookup_cl (current),
3889 "Cyclic interface inheritance");
3893 if (inherits_from_p (CLASSTYPE_SUPER (type), type))
3894 parse_error_context (lookup_cl (current),
3895 "Cyclic class inheritance");
3899 /* safe_layout_class just makes sure that we can load a class without
3900 disrupting the current_class, input_file, lineno, etc, information
3901 about the class processed currently. */
3904 safe_layout_class (class)
3907 tree save_current_class = current_class;
3908 char *save_input_filename = input_filename;
3909 int save_lineno = lineno;
3911 push_obstacks (&permanent_obstack, &permanent_obstack);
3913 layout_class (class);
3916 current_class = save_current_class;
3917 input_filename = save_input_filename;
3918 lineno = save_lineno;
3919 CLASS_LOADED_P (class) = 1;
3923 jdep_resolve_class (dep)
3928 if (JDEP_RESOLVED_P (dep))
3929 decl = JDEP_RESOLVED_DECL (dep);
3932 decl = resolve_class (JDEP_TO_RESOLVE (dep),
3933 JDEP_DECL (dep), JDEP_WFL (dep));
3934 JDEP_RESOLVED (dep, decl);
3938 complete_class_report_errors (dep);
3943 /* Complete unsatisfied class declaration and their dependencies */
3946 java_complete_class ()
3953 push_obstacks (&permanent_obstack, &permanent_obstack);
3955 /* Process imports and reverse the import on demand list */
3957 if (ctxp->import_demand_list)
3958 ctxp->import_demand_list = nreverse (ctxp->import_demand_list);
3960 /* Rever things so we have the right order */
3961 ctxp->class_list = nreverse (ctxp->class_list);
3962 ctxp->classd_list = reverse_jdep_list (ctxp);
3964 for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
3966 cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
3969 for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
3972 if (!(decl = jdep_resolve_class (dep)))
3975 /* Now it's time to patch */
3976 switch (JDEP_KIND (dep))
3979 /* Simply patch super */
3980 if (parser_check_super (decl, JDEP_DECL (dep), JDEP_WFL (dep)))
3982 BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO
3983 (TREE_TYPE (JDEP_DECL (dep)))), 0)) = TREE_TYPE (decl);
3988 /* We do part of the job done in add_field */
3989 tree field_decl = JDEP_DECL (dep);
3990 tree field_type = TREE_TYPE (decl);
3991 push_obstacks (&permanent_obstack, &permanent_obstack);
3992 if (TREE_CODE (field_type) == RECORD_TYPE)
3993 field_type = promote_type (field_type);
3995 TREE_TYPE (field_decl) = field_type;
3996 DECL_ALIGN (field_decl) = 0;
3997 layout_decl (field_decl, 0);
3998 SOURCE_FRONTEND_DEBUG
3999 (("Completed field/var decl `%s' with `%s'",
4000 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
4001 IDENTIFIER_POINTER (DECL_NAME (decl))));
4004 case JDEP_METHOD: /* We start patching a method */
4005 case JDEP_METHOD_RETURN:
4011 type = TREE_TYPE(decl);
4012 if (TREE_CODE (type) == RECORD_TYPE)
4013 type = promote_type (type);
4014 JDEP_APPLY_PATCH (dep, type);
4015 SOURCE_FRONTEND_DEBUG
4016 (((JDEP_KIND (dep) == JDEP_METHOD_RETURN ?
4017 "Completing fct `%s' with ret type `%s'":
4018 "Completing arg `%s' with type `%s'"),
4019 IDENTIFIER_POINTER (EXPR_WFL_NODE
4020 (JDEP_DECL_WFL (dep))),
4021 IDENTIFIER_POINTER (DECL_NAME (decl))));
4025 dep = JDEP_CHAIN (dep);
4026 if (JDEP_KIND (dep) == JDEP_METHOD_END)
4029 decl = jdep_resolve_class (dep);
4033 tree mdecl = JDEP_DECL (dep), signature;
4034 push_obstacks (&permanent_obstack, &permanent_obstack);
4035 /* Recompute and reset the signature */
4036 signature = build_java_signature (TREE_TYPE (mdecl));
4037 set_java_signature (TREE_TYPE (mdecl), signature);
4044 case JDEP_INTERFACE:
4045 if (parser_check_super_interface (decl, JDEP_DECL (dep),
4048 parser_add_interface (JDEP_DECL (dep), decl, JDEP_WFL (dep));
4053 type = TREE_TYPE(decl);
4054 if (TREE_CODE (type) == RECORD_TYPE)
4055 type = promote_type (type);
4056 JDEP_APPLY_PATCH (dep, type);
4060 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
4061 SOURCE_FRONTEND_DEBUG
4062 (("Completing a random type dependency on a '%s' node",
4063 tree_code_name [TREE_CODE (JDEP_DECL (dep))]));
4066 case JDEP_EXCEPTION:
4067 JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
4068 SOURCE_FRONTEND_DEBUG
4069 (("Completing `%s' `throws' argument node",
4070 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
4074 fatal ("Can't handle patch code %d - java_complete_class",
4083 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
4087 resolve_class (class_type, decl, cl)
4088 tree class_type, decl, cl;
4090 char *name = IDENTIFIER_POINTER (TYPE_NAME (class_type));
4092 tree resolved_type = TREE_TYPE (class_type);
4093 tree resolved_type_decl;
4095 if (resolved_type != NULL_TREE)
4097 tree resolved_type_decl = TYPE_NAME (resolved_type);
4098 if (resolved_type_decl == NULL_TREE
4099 || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
4101 resolved_type_decl = build_decl (TYPE_DECL,
4102 TYPE_NAME (class_type),
4105 return resolved_type_decl;
4108 /* 1- Check to see if we have an array. If true, find what we really
4110 while (name[0] == '[')
4113 TYPE_NAME (class_type) = get_identifier (name);
4115 /* 2- Resolve the bare type */
4116 if (!(resolved_type_decl = do_resolve_class (class_type, decl, cl)))
4118 resolved_type = TREE_TYPE (resolved_type_decl);
4120 /* 3- If we have and array, reconstruct the array down to its nesting */
4123 while (base != name)
4125 if (TREE_CODE (resolved_type) == RECORD_TYPE)
4126 resolved_type = promote_type (resolved_type);
4127 resolved_type = build_java_array_type (resolved_type, -1);
4128 CLASS_LOADED_P (resolved_type) = 1;
4131 /* Build a fake decl for this, since this is what is expected to
4133 resolved_type_decl =
4134 build_decl (TYPE_DECL, TYPE_NAME (resolved_type), resolved_type);
4135 /* Figure how those two things are important for error report. FIXME */
4136 DECL_SOURCE_LINE (resolved_type_decl) = 0;
4137 DECL_SOURCE_FILE (resolved_type_decl) = input_filename;
4138 TYPE_NAME (class_type) = TYPE_NAME (resolved_type);
4140 TREE_TYPE (class_type) = resolved_type;
4141 return resolved_type_decl;
4144 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
4145 are used to report error messages. */
4148 do_resolve_class (class_type, decl, cl)
4153 tree new_class_decl;
4154 tree original_name = NULL_TREE;
4156 /* Do not try to replace TYPE_NAME (class_type) by a variable, since
4157 its is changed by find_in_imports{_on_demand} */
4159 /* 1- Check for the type in single imports */
4160 if (find_in_imports (class_type))
4163 /* 2- And check for the type in the current compilation unit. If it fails,
4164 try with a name qualified with the package name if appropriate. */
4165 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
4167 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
4168 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
4169 load_class (TYPE_NAME (class_type), 0);
4170 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4173 original_name = TYPE_NAME (class_type);
4174 if (!QUALIFIED_P (TYPE_NAME (class_type)) && ctxp->package)
4175 TYPE_NAME (class_type) = merge_qualified_name (ctxp->package,
4176 TYPE_NAME (class_type));
4178 if (!(new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
4179 load_class (TYPE_NAME (class_type), 0);
4180 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
4182 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
4183 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
4184 load_class (TYPE_NAME (class_type), 0);
4185 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4188 new_name = TYPE_NAME (class_type);
4189 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (new_name)) != NULL_TREE)
4191 if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
4192 !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
4193 load_class (new_name, 0);
4194 return IDENTIFIER_CLASS_VALUE (new_name);
4198 tree class = read_class (new_name);
4199 if (class != NULL_TREE)
4201 tree decl = IDENTIFIER_CLASS_VALUE (new_name);
4202 if (decl == NULL_TREE)
4203 decl = push_class (class, new_name);
4208 TYPE_NAME (class_type) = original_name;
4210 /* 3- Check an other compilation unit that bears the name of type */
4211 load_class (TYPE_NAME (class_type), 0);
4212 if (check_pkg_class_access (TYPE_NAME (class_type),
4213 (cl ? cl : lookup_cl (decl))))
4216 if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
4217 return new_class_decl;
4219 /* 4- Check the import on demands. Don't allow bar.baz to be
4220 imported from foo.* */
4221 if (!QUALIFIED_P (TYPE_NAME (class_type)))
4222 if (find_in_imports_on_demand (class_type))
4225 /* 5- Last call for a resolution */
4226 return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
4229 /* Resolve NAME and lay it out (if not done and if not the current
4230 parsed class). Return a decl node. This function is meant to be
4231 called when type resolution is necessary during the walk pass. */
4234 resolve_and_layout (something, cl)
4240 /* Don't do that on the current class */
4241 if (something == current_class)
4242 return TYPE_NAME (current_class);
4244 /* Don't do anything for void and other primitive types */
4245 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
4248 /* Pointer types can be reall pointer types or fake pointers. When
4249 finding a real pointer, recheck for primitive types */
4250 if (TREE_CODE (something) == POINTER_TYPE)
4252 if (TREE_TYPE (something))
4254 something = TREE_TYPE (something);
4255 if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
4259 something = TYPE_NAME (something);
4262 /* Don't do anything for arrays of primitive types */
4263 if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
4264 && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
4267 /* If something is not and IDENTIFIER_NODE, it can be a a TYPE_DECL
4269 if (TREE_CODE (something) != IDENTIFIER_NODE)
4270 something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
4271 DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
4273 if (!(decl = resolve_no_layout (something, cl)))
4276 /* Resolve and layout if necessary */
4277 layout_class_methods (TREE_TYPE (decl));
4278 if (CLASS_FROM_SOURCE_P (TREE_TYPE (decl)))
4279 CHECK_METHODS (decl);
4280 if (TREE_TYPE (decl) != current_class && !CLASS_LOADED_P (TREE_TYPE (decl)))
4281 safe_layout_class (TREE_TYPE (decl));
4286 /* Resolve a class, returns its decl but doesn't perform any
4287 layout. The current parsing context is saved and restored */
4290 resolve_no_layout (name, cl)
4294 BUILD_PTR_FROM_NAME (ptr, name);
4295 java_parser_context_save_global ();
4296 decl = resolve_class (ptr, NULL_TREE, cl);
4297 java_parser_context_restore_global ();
4302 /* Called when reporting errors. Skip leader '[' in a complex array
4303 type description that failed to be resolved. */
4306 purify_type_name (name)
4309 while (*name && *name == '[')
4314 /* The type CURRENT refers to can't be found. We print error messages. */
4317 complete_class_report_errors (dep)
4322 if (!JDEP_WFL (dep))
4325 name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
4326 switch (JDEP_KIND (dep))
4330 (JDEP_WFL (dep), "Superclass `%s' of class `%s' not found",
4331 purify_type_name (name),
4332 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4336 (JDEP_WFL (dep), "Type `%s' not found in declaration of field `%s'",
4337 purify_type_name (name),
4338 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4340 case JDEP_METHOD: /* Covers arguments */
4342 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the "
4343 "argument `%s' of method `%s'",
4344 purify_type_name (name),
4345 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
4346 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
4348 case JDEP_METHOD_RETURN: /* Covers return type */
4350 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the "
4351 "return type of method `%s'",
4352 purify_type_name (name),
4353 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
4355 case JDEP_INTERFACE:
4357 (JDEP_WFL (dep), "Superinterface `%s' of %s `%s' not found",
4358 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
4359 (CLASS_OR_INTERFACE (JDEP_DECL (dep), "class", "interface")),
4360 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4364 (JDEP_WFL (dep), "Type `%s' not found in the declaration of the "
4365 "local variable `%s'",
4366 purify_type_name (IDENTIFIER_POINTER
4367 (EXPR_WFL_NODE (JDEP_WFL (dep)))),
4368 IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
4370 case JDEP_EXCEPTION: /* As specified by `throws' */
4372 (JDEP_WFL (dep), "Class `%s' not found in `throws'",
4373 IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
4376 /* Fix for -Wall. Just break doing nothing. The error will be
4382 /* Check uninitialized final. */
4389 /* Return a static string containing the DECL prototype string. If
4390 DECL is a constructor, use the class name instead of the form
4394 get_printable_method_name (decl)
4398 tree name = NULL_TREE;
4400 if (DECL_CONSTRUCTOR_P (decl))
4402 name = DECL_NAME (decl);
4403 DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
4406 to_return = lang_printable_name (decl, 0);
4407 if (DECL_CONSTRUCTOR_P (decl))
4408 DECL_NAME (decl) = name;
4413 /* Reinstall the proper DECL_NAME on METHOD. Return 0 if the method
4414 nevertheless needs to be verfied, 1 otherwise. */
4417 reset_method_name (method)
4420 if (!IS_CLINIT (method) && DECL_NAME (method) != finit_identifier_node)
4422 /* NAME is just the plain name when Object is being defined */
4423 if (DECL_CONTEXT (method) != object_type_node)
4424 DECL_NAME (method) = (DECL_CONSTRUCTOR_P (method) ?
4425 init_identifier_node : GET_METHOD_NAME (method));
4432 /* Return the name of METHOD_DECL, when DECL_NAME is a WFL */
4435 java_get_real_method_name (method_decl)
4438 tree method_name = DECL_NAME (method_decl);
4439 if (DECL_CONSTRUCTOR_P (method_decl))
4440 return init_identifier_node;
4442 /* Explain here why METHOD_DECL doesn't have the DECL_CONSTRUCTUR_P
4443 and still can be a constructor. FIXME */
4445 /* Don't confuse method only bearing the name of their class as
4447 else if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (method_decl))
4449 && ctxp->current_parsed_class_un == EXPR_WFL_NODE (method_name)
4450 && get_access_flags_from_decl (method_decl) <= ACC_PROTECTED
4451 && TREE_TYPE (TREE_TYPE (method_decl)) == void_type_node)
4452 return init_identifier_node;
4454 return EXPR_WFL_NODE (method_name);
4457 /* Track method being redefined inside the same class. As a side
4458 effect, set DECL_NAME to an IDENTIFIER (prior entering this
4459 function it's a FWL, so we can track errors more accurately */
4462 check_method_redefinition (class, method)
4466 tree cl = DECL_NAME (method);
4467 tree sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
4468 /* decl name of artificial <clinit> and $finit$ doesn't need to be
4469 fixed and checked */
4471 /* Reset the method name before running the check. If it returns 1,
4472 the method doesn't need to be verified with respect to method
4473 redeclaration and we return 0 */
4474 if (reset_method_name (method))
4477 name = DECL_NAME (method);
4478 for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
4480 if (redef == method)
4482 if (DECL_NAME (redef) == name
4483 && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef)))
4486 (cl, "Duplicate %s declaration `%s'",
4487 (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
4488 get_printable_method_name (redef));
4495 /* Check all the methods of CLASS. Methods are first completed then
4496 checked according to regular method existance rules.
4497 If no constructor were encountered, then build its declaration. */
4500 java_check_regular_methods (class_decl)
4503 int saw_constructor = 0;
4505 tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (class_decl));
4506 tree super_class = CLASSTYPE_SUPER (class);
4507 tree saved_found_wfl = NULL_TREE, found = NULL_TREE;
4510 /* It is not necessary to check methods defined in java.lang.Object */
4511 if (class == object_type_node)
4514 if (!TYPE_NVIRTUALS (class))
4515 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
4517 /* Should take interfaces into account. FIXME */
4518 for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
4521 tree method_wfl = DECL_NAME (method);
4524 /* If we previously found something and its name was saved,
4526 if (found && saved_found_wfl)
4528 DECL_NAME (found) = saved_found_wfl;
4529 saved_found_wfl = NULL_TREE;
4532 /* Check for redefinitions */
4533 if (check_method_redefinition (class, method))
4536 /* If we see one constructor a mark so we don't generate the
4537 default one. Also skip other verifications: constructors
4538 can't be inherited hence hiden or overriden */
4539 if (DECL_CONSTRUCTOR_P (method))
4541 saw_constructor = 1;
4545 /* We verify things thrown by the method. They must inherits from
4546 java.lang.Throwable */
4547 for (mthrows = DECL_FUNCTION_THROWS (method);
4548 mthrows; mthrows = TREE_CHAIN (mthrows))
4550 if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
4552 (TREE_PURPOSE (mthrows), "Class `%s' in `throws' clause must be "
4553 "a subclass of class `java.lang.Throwable'",
4555 (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
4558 sig = build_java_argument_signature (TREE_TYPE (method));
4559 found = lookup_argument_method (super_class, DECL_NAME (method), sig);
4561 /* Nothing overrides or it's a private method. */
4564 if (METHOD_PRIVATE (found))
4570 /* If found wasn't verified, it's DECL_NAME won't be set properly.
4571 We set it temporarily for the sake of the error report. */
4572 saved_found_wfl = DECL_NAME (found);
4573 reset_method_name (found);
4575 /* Can't override a method with the same name and different return
4577 if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
4579 char *t = strdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)),
4583 "Method `%s' was defined with return type `%s' in class `%s'",
4584 lang_printable_name (found, 0), t,
4586 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4590 /* Can't override final. Can't override static. */
4591 if (METHOD_FINAL (found) || METHOD_STATIC (found))
4593 /* Static *can* override static */
4594 if (METHOD_STATIC (found) && METHOD_STATIC (method))
4598 "%s methods can't be overriden. Method `%s' is %s in class `%s'",
4599 (METHOD_FINAL (found) ? "Final" : "Static"),
4600 lang_printable_name (found, 0),
4601 (METHOD_FINAL (found) ? "final" : "static"),
4603 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4606 /* Static method can't override instance method. */
4607 if (METHOD_STATIC (method))
4611 "Instance methods can't be overriden by a static method. Method "
4612 "`%s' is an instance method in class `%s'",
4613 lang_printable_name (found, 0),
4615 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4619 aflags = get_access_flags_from_decl (found);
4620 /* - Overriding/hiding public must be public
4621 - Overriding/hiding protected must be protected or public
4622 - If the overriden or hidden method has default (package)
4623 access, then the overriding or hiding method must not be
4624 private; otherwise, a compile-time error occurs */
4625 if ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method))
4626 || (METHOD_PROTECTED (found)
4627 && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
4628 || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
4629 && METHOD_PRIVATE (method)))
4633 "Methods can't be overridden to be more private. Method `%s' is "
4634 "not %s in class `%s'", lang_printable_name (method, 0),
4635 (METHOD_PUBLIC (method) ? "public" :
4636 (METHOD_PRIVATE (method) ? "private" : "protected")),
4637 IDENTIFIER_POINTER (DECL_NAME
4638 (TYPE_NAME (DECL_CONTEXT (found)))));
4642 /* Overriding methods must have compatible `throws' clauses on checked
4643 exceptions, if any */
4644 check_throws_clauses (method, method_wfl, found);
4646 /* If the method has default access in an other package, then
4647 issue a warning that the current method doesn't override the
4648 one that was found elsewhere. Do not issue this warning when
4649 the match was found in java.lang.Object. */
4650 if (DECL_CONTEXT (found) != object_type_node
4651 && (!aflags || (aflags > ACC_PROTECTED))
4652 && !class_in_current_package (DECL_CONTEXT (found))
4653 && flag_not_overriding)
4654 parse_warning_context
4655 (method_wfl, "Method `%s' in class `%s' does not "
4656 "override the corresponding method in class `%s', which is "
4657 "private to a different package",
4658 lang_printable_name (found, 0),
4659 IDENTIFIER_POINTER (DECL_NAME (class_decl)),
4660 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4662 /* Inheriting multiple methods with the same signature. FIXME */
4665 /* Don't forget eventual pending found and saved_found_wfl. Take
4666 into account that we might have exited because we saw an
4667 aritifical method as the last entry. */
4669 if (found && !DECL_ARTIFICIAL (found) && saved_found_wfl)
4670 DECL_NAME (found) = saved_found_wfl;
4672 if (!TYPE_NVIRTUALS (class))
4673 TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
4675 if (!saw_constructor)
4677 /* No constructor seen, we craft one, at line 0. Since this
4678 operation takes place after we laid methods out
4679 (layout_class_methods), we prepare the its DECL
4684 /* If the class is declared PUBLIC, the default constructor is
4685 PUBLIC otherwise it has default access implied by no access
4687 flags = (get_access_flags_from_decl (class_decl) & ACC_PUBLIC ?
4689 decl = create_artificial_method (class, flags, void_type_node,
4690 init_identifier_node, end_params_node);
4691 DECL_CONSTRUCTOR_P (decl) = 1;
4692 layout_class_method (TREE_TYPE (class_decl), NULL_TREE, decl, NULL_TREE);
4696 /* Return a non zero value if the `throws' clause of METHOD (if any)
4697 is incompatible with the `throws' clause of FOUND (if any). */
4700 check_throws_clauses (method, method_wfl, found)
4701 tree method, method_wfl, found;
4703 tree mthrows, fthrows;
4705 /* Can't check these things with class loaded from bytecode. FIXME */
4706 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (found)))
4709 for (mthrows = DECL_FUNCTION_THROWS (method);
4710 mthrows; mthrows = TREE_CHAIN (mthrows))
4712 /* We don't verify unchecked expressions */
4713 if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
4715 /* Checked expression must be compatible */
4716 for (fthrows = DECL_FUNCTION_THROWS (found);
4717 fthrows; fthrows = TREE_CHAIN (fthrows))
4718 if (inherits_from_p (TREE_VALUE (mthrows), TREE_VALUE (fthrows)))
4723 (method_wfl, "Invalid checked exception class `%s' in "
4724 "`throws' clause. The exception must be a subclass of an "
4725 "exception thrown by `%s' from class `%s'",
4726 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))),
4727 lang_printable_name (found, 0),
4729 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4734 /* Check abstract method of interface INTERFACE */
4737 java_check_abstract_methods (interface_decl)
4738 tree interface_decl;
4741 tree method, basetype_vec, found;
4742 tree interface = TREE_TYPE (interface_decl);
4744 for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
4746 tree method_wfl = DECL_NAME (method);
4748 /* 2- Check for double definition inside the defining interface */
4749 if (check_method_redefinition (interface, method))
4752 /* 3- Overriding is OK as far as we preserve the return type and
4753 the thrown exceptions (FIXME) */
4754 found = lookup_java_interface_method2 (interface, method);
4758 tree saved_found_wfl = DECL_NAME (found);
4759 reset_method_name (found);
4760 t = strdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
4763 "Method `%s' was defined with return type `%s' in class `%s'",
4764 lang_printable_name (found, 0), t,
4766 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4770 DECL_NAME (found) = saved_found_wfl;
4774 /* 4- Inherited methods can't differ by their returned types */
4775 if (!(basetype_vec = TYPE_BINFO_BASETYPES (interface)))
4777 n = TREE_VEC_LENGTH (basetype_vec);
4778 for (i = 0; i < n; i++)
4780 tree sub_interface_method, sub_interface;
4781 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
4784 sub_interface = BINFO_TYPE (vec_elt);
4785 for (sub_interface_method = TYPE_METHODS (sub_interface);
4786 sub_interface_method;
4787 sub_interface_method = TREE_CHAIN (sub_interface_method))
4789 found = lookup_java_interface_method2 (interface,
4790 sub_interface_method);
4791 if (found && (found != sub_interface_method))
4793 tree saved_found_wfl = DECL_NAME (found);
4794 reset_method_name (found);
4796 (lookup_cl (sub_interface_method),
4797 "Interface `%s' inherits method `%s' from interface `%s'. "
4798 "This method is redefined with a different return type in "
4800 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
4801 lang_printable_name (found, 0),
4803 (DECL_NAME (TYPE_NAME
4804 (DECL_CONTEXT (sub_interface_method)))),
4806 (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
4807 DECL_NAME (found) = saved_found_wfl;
4813 /* Lookup methods in interfaces using their name and partial
4814 signature. Return a matching method only if their types differ. */
4817 lookup_java_interface_method2 (class, method_decl)
4818 tree class, method_decl;
4821 tree basetype_vec = TYPE_BINFO_BASETYPES (class), to_return;
4826 n = TREE_VEC_LENGTH (basetype_vec);
4827 for (i = 0; i < n; i++)
4829 tree vec_elt = TREE_VEC_ELT (basetype_vec, i), to_return;
4830 if ((BINFO_TYPE (vec_elt) != object_type_node)
4832 lookup_java_method2 (BINFO_TYPE (vec_elt), method_decl, 1)))
4835 for (i = 0; i < n; i++)
4837 to_return = lookup_java_interface_method2
4838 (BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i)), method_decl);
4846 /* Lookup method using their name and partial signature. Return a
4847 matching method only if their types differ. */
4850 lookup_java_method2 (clas, method_decl, do_interface)
4851 tree clas, method_decl;
4854 tree method, method_signature, method_name, method_type, name;
4856 method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
4857 name = DECL_NAME (method_decl);
4858 method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
4859 EXPR_WFL_NODE (name) : name);
4860 method_type = TREE_TYPE (TREE_TYPE (method_decl));
4862 while (clas != NULL_TREE)
4864 for (method = TYPE_METHODS (clas);
4865 method != NULL_TREE; method = TREE_CHAIN (method))
4867 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
4868 tree name = DECL_NAME (method);
4869 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
4870 EXPR_WFL_NODE (name) : name) == method_name
4871 && method_sig == method_signature
4872 && TREE_TYPE (TREE_TYPE (method)) != method_type)
4875 clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
4880 /* Return the line that matches DECL line number. Used during error
4887 static tree cl = NULL_TREE;
4892 if (cl == NULL_TREE)
4893 cl = build_expr_wfl (NULL_TREE, NULL, 0, 0);
4895 EXPR_WFL_FILENAME_NODE (cl) = get_identifier (DECL_SOURCE_FILE (decl));
4896 EXPR_WFL_SET_LINECOL (cl, DECL_SOURCE_LINE_FIRST (decl), -1);
4901 /* Look for a simple name in the single-type import list */
4904 find_name_in_single_imports (name)
4909 for (node = ctxp->import_list; node; node = TREE_CHAIN (node))
4910 if (TREE_VALUE (node) == name)
4911 return (EXPR_WFL_NODE (TREE_PURPOSE (node)));
4916 /* Process all single-type import. */
4924 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
4926 tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import));
4928 /* Don't load twice something already defined. */
4929 if (IDENTIFIER_CLASS_VALUE (to_be_found))
4931 QUALIFIED_P (to_be_found) = 1;
4932 load_class (to_be_found, 0);
4934 check_pkg_class_access (to_be_found, TREE_PURPOSE (import));
4935 if (!IDENTIFIER_CLASS_VALUE (to_be_found))
4937 parse_error_context (TREE_PURPOSE (import),
4938 "Class or interface `%s' not found in import",
4939 IDENTIFIER_POINTER (to_be_found));
4948 /* Possibly find a class imported by a single-type import statement. Return
4949 1 if an error occured, 0 otherwise. */
4952 find_in_imports (class_type)
4957 for (import = ctxp->import_list; import; import = TREE_CHAIN (import))
4958 if (TREE_VALUE (import) == TYPE_NAME (class_type))
4960 TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
4961 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
4967 note_possible_classname (name, len)
4972 if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
4974 else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
4978 node = ident_subst (name, len, "", '/', '.', "");
4979 IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
4980 QUALIFIED_P (node) = 1; /* As soon as we turn / into . */
4984 /* Read a import directory, gathering potential match for further type
4985 references. Indifferently reads a filesystem or a ZIP archive
4989 read_import_dir (wfl)
4992 tree package_id = EXPR_WFL_NODE (wfl);
4993 char *package_name = IDENTIFIER_POINTER (package_id);
4994 int package_length = IDENTIFIER_LENGTH (package_id);
4996 JCF *saved_jcf = current_jcf;
5001 struct buffer filename[1];
5004 if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
5006 IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
5008 BUFFER_INIT (filename);
5009 buffer_grow (filename, package_length + 100);
5011 for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
5013 char *entry_name = jcf_path_name (entry);
5014 int entry_length = strlen (entry_name);
5015 if (jcf_path_is_zipfile (entry))
5018 buffer_grow (filename, entry_length);
5019 memcpy (filename->data, entry_name, entry_length - 1);
5020 filename->data[entry_length-1] = '\0';
5021 zipf = opendir_in_zip (filename->data, jcf_path_is_system (entry));
5023 error ("malformed .zip archive in CLASSPATH: %s", entry_name);
5026 ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
5027 BUFFER_RESET (filename);
5028 for (k = 0; k < package_length; k++)
5030 char ch = package_name[k];
5031 *filename->ptr++ = ch == '.' ? '/' : ch;
5033 *filename->ptr++ = '/';
5035 for (k = 0; k < zipf->count; k++, zipd = ZIPDIR_NEXT (zipd))
5037 char *current_entry = ZIPDIR_FILENAME (zipd);
5038 int current_entry_len = zipd->filename_length;
5040 if (current_entry_len >= BUFFER_LENGTH (filename)
5041 && strncmp (filename->data, current_entry,
5042 BUFFER_LENGTH (filename)) != 0)
5044 found |= note_possible_classname (current_entry,
5051 BUFFER_RESET (filename);
5052 buffer_grow (filename, entry_length + package_length + 4);
5053 strcpy (filename->data, entry_name);
5054 filename->ptr = filename->data + entry_length;
5055 for (k = 0; k < package_length; k++)
5057 char ch = package_name[k];
5058 *filename->ptr++ = ch == '.' ? '/' : ch;
5060 *filename->ptr = '\0';
5062 dirp = opendir (filename->data);
5065 *filename->ptr++ = '/';
5070 struct dirent *direntp = readdir (dirp);
5073 d_name = direntp->d_name;
5074 len = strlen (direntp->d_name);
5075 buffer_grow (filename, len+1);
5076 strcpy (filename->ptr, d_name);
5077 found |= note_possible_classname (filename->data + entry_length,
5078 package_length+len+1);
5085 free (filename->data);
5087 /* Here we should have a unified way of retrieving an entry, to be
5091 static int first = 1;
5095 sprintf (buffer, "Can't find default package `%s'. Check "
5096 "the CLASSPATH environment variable and the access to the "
5097 "archives.", package_name);
5103 parse_error_context (wfl, "Package `%s' not found in import",
5105 current_jcf = saved_jcf;
5108 current_jcf = saved_jcf;
5111 /* Possibly find a type in the import on demands specified
5112 types. Returns 1 if an error occured, 0 otherwise. Run throught the
5113 entire list, to detected potential double definitions. */
5116 find_in_imports_on_demand (class_type)
5119 tree node, import, node_to_use;
5123 for (import = ctxp->import_demand_list; import; import = TREE_CHAIN (import))
5126 obstack_grow (&temporary_obstack,
5127 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
5128 IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
5129 obstack_1grow (&temporary_obstack, '.');
5130 obstack_grow0 (&temporary_obstack,
5131 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
5132 IDENTIFIER_LENGTH (TYPE_NAME (class_type)));
5133 id_name = obstack_finish (&temporary_obstack);
5135 node = maybe_get_identifier (id_name);
5136 if (node && IS_A_CLASSFILE_NAME (node))
5140 cl = TREE_PURPOSE (import);
5148 (import, "Type `%s' also potentially defined in package `%s'",
5149 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
5150 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))));
5157 /* Setup lineno so that it refers to the line of the import (in
5158 case we parse a class file and encounter errors */
5160 int saved_lineno = lineno;
5161 lineno = EXPR_WFL_LINENO (cl);
5162 TYPE_NAME (class_type) = node_to_use;
5163 QUALIFIED_P (TYPE_NAME (class_type)) = 1;
5164 decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
5165 /* If there is no DECL set for the class or if the class isn't
5166 loaded and not seen in source yet, the load */
5167 if (!decl || (!CLASS_LOADED_P (TREE_TYPE (decl))
5168 && !CLASS_FROM_SOURCE_P (TREE_TYPE (decl))))
5169 load_class (node_to_use, 0);
5170 lineno = saved_lineno;
5171 return check_pkg_class_access (TYPE_NAME (class_type), cl);
5174 return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
5178 resolve_package (pkg, next)
5181 tree type_name = NULL_TREE;
5182 char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (pkg));
5184 /* The trick is to determine when the package name stops and were
5185 the name of something contained in the package starts. Then we
5186 return a fully qualified name of what we want to get. */
5188 /* Do a quick search on well known package names */
5189 if (!strncmp (name, "java.lang.reflect", 17))
5192 TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg))));
5193 type_name = lookup_package_type (name, 17);
5195 else if (!strncmp (name, "java.lang", 9))
5197 *next = TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg)));
5198 type_name = lookup_package_type (name, 9);
5201 return NULL_TREE; /* FIXME, search all imported packages. */
5207 lookup_package_type (name, from)
5212 char *sub = &name[from+1];
5213 while (*sub != '.' && *sub)
5215 strncpy (subname, name, sub-name);
5216 subname [sub-name] = '\0';
5217 return get_identifier (subname);
5220 /* Check that CLASS_NAME refers to a PUBLIC class. Return 0 if no
5221 access violations were found, 1 otherwise. */
5224 check_pkg_class_access (class_name, cl)
5230 if (!QUALIFIED_P (class_name) || !IDENTIFIER_CLASS_VALUE (class_name))
5233 if (!(type = TREE_TYPE (IDENTIFIER_CLASS_VALUE (class_name))))
5236 if (!CLASS_PUBLIC (TYPE_NAME (type)))
5238 /* Access to a private class within the same package is
5241 breakdown_qualified (&l, &r, class_name);
5242 if (l == ctxp->package)
5246 (cl, "Can't access %s `%s'. Only public classes and interfaces in "
5247 "other packages can be accessed",
5248 (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
5249 IDENTIFIER_POINTER (class_name));
5255 /* Local variable declaration. */
5258 declare_local_variables (modifier, type, vlist)
5263 tree decl, current, saved_type;
5264 tree type_wfl = NULL_TREE;
5267 /* Push a new block if statements were seen between the last time we
5268 pushed a block and now. Keep a cound of block to close */
5269 if (BLOCK_EXPR_BODY (GET_CURRENT_BLOCK (current_function_decl)))
5271 tree body = GET_CURRENT_BLOCK (current_function_decl);
5272 tree b = enter_block ();
5273 BLOCK_EXPR_ORIGIN (b) = body;
5279 for (i = 0; i <= 10; i++) if (1 << i & modifier) break;
5280 if (modifier == ACC_FINAL)
5282 if (flag_static_local_jdk1_1)
5283 parse_warning_context (ctxp->modifier_ctx [i],
5284 "Unsupported JDK1.1 `final' local variable "
5285 "(treated as non final)");
5290 (ctxp->modifier_ctx [i],
5291 "Only `final' is allowed as a local variables modifier");
5296 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
5297 hold the TYPE value if a new incomplete has to be created (as
5298 opposed to being found already existing and reused). */
5299 SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
5301 /* If TYPE is fully resolved and we don't have a reference, make one */
5302 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
5304 /* Go through all the declared variables */
5305 for (current = vlist, saved_type = type; current;
5306 current = TREE_CHAIN (current), type = saved_type)
5308 tree other, real_type;
5309 tree wfl = TREE_PURPOSE (current);
5310 tree name = EXPR_WFL_NODE (wfl);
5311 tree init = TREE_VALUE (current);
5313 /* Process NAME, as it may specify extra dimension(s) for it */
5314 type = build_array_from_name (type, type_wfl, name, &name);
5316 /* Variable redefinition check */
5317 if ((other = lookup_name_in_blocks (name)))
5319 variable_redefinition_error (wfl, name, TREE_TYPE (other),
5320 DECL_SOURCE_LINE (other));
5324 /* Type adjustment. We may have just readjusted TYPE because
5325 the variable specified more dimensions. Make sure we have
5326 a reference if we can and don't have one already. */
5327 PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
5329 real_type = GET_REAL_TYPE (type);
5330 /* Never layout this decl. This will be done when its scope
5332 decl = build_decl (VAR_DECL, name, real_type);
5333 BLOCK_CHAIN_DECL (decl);
5335 /* If doing xreferencing, replace the line number with the WFL
5338 DECL_SOURCE_LINE (decl) = EXPR_WFL_LINECOL (wfl);
5340 /* Don't try to use an INIT statement when an error was found */
5341 if (init && java_error_count)
5344 /* Add the initialization function to the current function's code */
5347 /* Name might have been readjusted */
5348 EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = name;
5349 MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
5350 java_method_add_stmt (current_function_decl,
5351 build_debugable_stmt (EXPR_WFL_LINECOL (init),
5355 /* Setup dependency the type of the decl */
5359 register_incomplete_type (JDEP_VARIABLE, type_wfl, decl, type);
5360 dep = CLASSD_LAST (ctxp->classd_list);
5361 JDEP_GET_PATCH (dep) = &TREE_TYPE (decl);
5364 SOURCE_FRONTEND_DEBUG (("Defined locals"));
5367 /* Called during parsing. Build decls from argument list. */
5370 source_start_java_method (fndecl)
5377 current_function_decl = fndecl;
5379 /* New scope for the function */
5381 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
5382 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
5384 tree type = TREE_VALUE (tem);
5385 tree name = TREE_PURPOSE (tem);
5387 /* If type is incomplete. Create an incomplete decl and ask for
5388 the decl to be patched later */
5389 if (INCOMPLETE_TYPE_P (type))
5392 tree real_type = GET_REAL_TYPE (type);
5393 parm_decl = build_decl (PARM_DECL, name, real_type);
5394 type = obtain_incomplete_type (type);
5395 register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
5396 jdep = CLASSD_LAST (ctxp->classd_list);
5397 JDEP_MISC (jdep) = name;
5398 JDEP_GET_PATCH (jdep) = &TREE_TYPE (parm_decl);
5401 parm_decl = build_decl (PARM_DECL, name, type);
5403 BLOCK_CHAIN_DECL (parm_decl);
5405 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
5406 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) =
5408 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
5411 /* Called during parsing. Creates an artificial method declaration. */
5414 create_artificial_method (class, flags, type, name, args)
5417 tree type, name, args;
5419 int saved_lineno = lineno;
5423 mdecl = make_node (FUNCTION_TYPE);
5424 TREE_TYPE (mdecl) = type;
5425 TYPE_ARG_TYPES (mdecl) = args;
5426 mdecl = add_method (class, flags, name, build_java_signature (mdecl));
5427 lineno = saved_lineno;
5428 DECL_ARTIFICIAL (mdecl) = 1;
5432 /* Starts the body if an artifical method. */
5435 start_artificial_method_body (mdecl)
5438 DECL_SOURCE_LINE (mdecl) = 1;
5439 DECL_SOURCE_LINE_MERGE (mdecl, 1);
5440 source_start_java_method (mdecl);
5445 end_artificial_method_body (mdecl)
5448 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
5452 /* Called during expansion. Push decls formerly built from argument
5453 list so they're usable during expansion. */
5456 expand_start_java_method (fndecl)
5461 current_function_decl = fndecl;
5463 announce_function (fndecl);
5464 pushlevel (1); /* Push parameters */
5465 ptr = &DECL_ARGUMENTS (fndecl);
5466 tem = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));
5469 tree next = TREE_CHAIN (tem);
5470 tree type = TREE_TYPE (tem);
5471 #ifdef PROMOTE_PROTOTYPES
5472 if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
5473 && INTEGRAL_TYPE_P (type))
5474 type = integer_type_node;
5476 DECL_ARG_TYPE (tem) = type;
5477 layout_decl (tem, 0);
5480 ptr = &TREE_CHAIN (tem);
5484 pushdecl_force_head (DECL_ARGUMENTS (fndecl));
5485 lineno = DECL_SOURCE_LINE_FIRST (fndecl);
5488 /* Terminate a function and expand its body. */
5491 source_end_java_method ()
5493 tree fndecl = current_function_decl;
5495 java_parser_context_save_global ();
5496 lineno = ctxp->last_ccb_indent1;
5498 /* Set EH language codes */
5499 java_set_exception_lang_code ();
5501 /* Turn function bodies with only a NOP expr null, so they don't get
5502 generated at all and we won't get warnings when using the -W
5504 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) == empty_stmt_node)
5505 BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)) = NULL_TREE;
5507 /* Generate function's code */
5508 if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl))
5509 && ! flag_emit_class_files
5510 && ! flag_emit_xref)
5511 expand_expr_stmt (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (fndecl)));
5513 /* pop out of its parameters */
5514 pushdecl_force_head (DECL_ARGUMENTS (fndecl));
5516 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
5518 /* Generate rtl for function exit. */
5519 if (! flag_emit_class_files && ! flag_emit_xref)
5521 lineno = DECL_SOURCE_LINE_LAST (fndecl);
5522 /* Emit catch-finally clauses */
5524 expand_function_end (input_filename, lineno, 0);
5526 /* Run the optimizers and output assembler code for this function. */
5527 rest_of_compilation (fndecl);
5530 current_function_decl = NULL_TREE;
5531 /* permanent_allocation (1); */
5532 java_parser_context_restore_global ();
5535 /* Record EXPR in the current function block. Complements compound
5536 expression second operand if necessary. */
5539 java_method_add_stmt (fndecl, expr)
5542 return add_stmt_to_block (GET_CURRENT_BLOCK (fndecl), NULL_TREE, expr);
5546 add_stmt_to_block (b, type, stmt)
5549 tree body = BLOCK_EXPR_BODY (b), c;
5551 if (java_error_count)
5554 if ((c = add_stmt_to_compound (body, type, stmt)) == body)
5557 BLOCK_EXPR_BODY (b) = c;
5558 TREE_SIDE_EFFECTS (c) = 1;
5562 /* Add STMT to EXISTING if possible, otherwise create a new
5563 COMPOUND_EXPR and add STMT to it. */
5566 add_stmt_to_compound (existing, type, stmt)
5567 tree existing, type, stmt;
5570 return build (COMPOUND_EXPR, type, existing, stmt);
5575 /* Hold THIS for the scope of the current public method decl. */
5576 static tree current_this;
5578 void java_layout_seen_class_methods ()
5580 tree previous_list = all_class_list;
5581 tree end = NULL_TREE;
5586 for (current = previous_list;
5587 current != end; current = TREE_CHAIN (current))
5588 layout_class_methods (TREE_TYPE (TREE_VALUE (current)));
5590 if (previous_list != all_class_list)
5592 end = previous_list;
5593 previous_list = all_class_list;
5600 /* Layout the methods of all classes loaded in one way on an
5601 other. Check methods of source parsed classes. Then reorder the
5602 fields and layout the classes or the type of all source parsed
5606 java_layout_classes ()
5609 int save_error_count = java_error_count;
5611 /* Layout the methods of all classes seen so far */
5612 java_layout_seen_class_methods ();
5613 java_parse_abort_on_error ();
5614 all_class_list = NULL_TREE;
5616 /* Then check the methods of all parsed classes */
5617 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
5618 if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
5619 CHECK_METHODS (TREE_VALUE (current));
5620 java_parse_abort_on_error ();
5622 for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
5624 current_class = TREE_TYPE (TREE_VALUE (current));
5626 /* Reverse the fields, but leave the dummy field in front.
5627 Fields are already ordered for Object and Class */
5628 if (TYPE_FIELDS (current_class) && current_class != object_type_node
5629 && current_class != class_type_node)
5631 /* If the dummy field is there, reverse the right fields and
5632 just layout the type for proper fields offset */
5633 if (!DECL_NAME (TYPE_FIELDS (current_class)))
5635 tree fields = TYPE_FIELDS (current_class);
5636 TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
5637 TYPE_SIZE (current_class) = NULL_TREE;
5638 layout_type (current_class);
5640 /* We don't have a dummy field, we need to layout the class,
5641 after having reversed the fields */
5644 TYPE_FIELDS (current_class) =
5645 nreverse (TYPE_FIELDS (current_class));
5646 TYPE_SIZE (current_class) = NULL_TREE;
5647 layout_class (current_class);
5651 layout_class (current_class);
5653 /* From now on, the class is considered completely loaded */
5654 CLASS_LOADED_P (current_class) = 1;
5656 /* Error reported by the caller */
5657 if (java_error_count)
5661 /* We might have reloaded classes durign the process of laying out
5662 classes for code generation. We must layout the methods of those
5663 late additions, as constructor checks might use them */
5664 java_layout_seen_class_methods ();
5665 java_parse_abort_on_error ();
5668 /* Expand all methods in all registered classes. */
5671 java_complete_expand_methods ()
5675 for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
5678 tree class_type = CLASS_TO_HANDLE_TYPE (TREE_TYPE (current));
5681 current_class = TREE_TYPE (current);
5682 is_interface = CLASS_INTERFACE (TYPE_NAME (current_class));
5684 /* Initialize a new constant pool */
5685 init_outgoing_cpool ();
5687 /* We want <clinit> (if any) to be processed first. */
5688 decl = tree_last (TYPE_METHODS (class_type));
5689 if (IS_CLINIT (decl))
5691 tree list = nreverse (TYPE_METHODS (class_type));
5692 list = TREE_CHAIN (list);
5693 TREE_CHAIN (decl) = NULL_TREE;
5694 TYPE_METHODS (class_type) = chainon (decl, nreverse (list));
5697 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
5699 /* Process only <clinit> method bodies in interfaces. */
5700 if (is_interface && decl != TYPE_METHODS (class_type))
5703 current_function_decl = decl;
5704 /* Don't generate debug info on line zero when expanding a
5705 generated constructor. */
5706 if (DECL_CONSTRUCTOR_P (decl) && !DECL_FUNCTION_BODY (decl))
5708 /* If we found errors, it's too dangerous to try to
5709 generate and expand a constructor */
5710 if (!java_error_count)
5712 restore_line_number_status (1);
5713 java_complete_expand_method (decl);
5714 restore_line_number_status (0);
5717 else if (METHOD_ABSTRACT (decl) || METHOD_NATIVE (decl))
5720 java_complete_expand_method (decl);
5723 /* Now verify constructor circularity (stop after the first one
5726 for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
5727 if (DECL_CONSTRUCTOR_P (decl) &&
5728 verify_constructor_circularity (decl, decl))
5731 /* Make the class data, register it and run the rest of decl
5732 compilation on it */
5733 if (!java_error_count)
5735 if (flag_emit_class_files)
5736 write_classfile (current_class);
5738 expand_xref (current_class);
5739 else if (! flag_syntax_only)
5740 finish_class (current_class);
5745 /* Hold a list of catch clauses list. The first element of this list is
5746 the list of the catch clauses of the currently analysed try block. */
5747 static tree currently_caught_type_list;
5749 /* Complete and expand a method. */
5752 java_complete_expand_method (mdecl)
5755 /* Fix constructors before expanding them */
5756 if (DECL_CONSTRUCTOR_P (mdecl))
5757 fix_constructors (mdecl);
5759 /* Expand functions that have a body */
5760 if (DECL_FUNCTION_BODY (mdecl))
5762 tree fbody = DECL_FUNCTION_BODY (mdecl);
5763 tree block_body = BLOCK_EXPR_BODY (fbody);
5764 expand_start_java_method (mdecl);
5765 build_result_decl (mdecl);
5768 = (!METHOD_STATIC (mdecl) ?
5769 BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl)) : NULL_TREE);
5771 /* Purge the `throws' list of unchecked exceptions */
5772 purge_unchecked_exceptions (mdecl);
5774 /* Install exceptions thrown with `throws' */
5775 PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
5777 if (block_body != NULL_TREE)
5779 /* Prevent the use of `this' inside <clinit> */
5780 if (IS_CLINIT (current_function_decl))
5781 ctxp->explicit_constructor_p = 1;
5783 block_body = java_complete_tree (block_body);
5784 check_for_initialization (block_body);
5785 ctxp->explicit_constructor_p = 0;
5787 BLOCK_EXPR_BODY (fbody) = block_body;
5789 if ((block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
5790 && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE)
5791 missing_return_error (current_function_decl);
5793 complete_start_java_method (mdecl);
5795 /* Don't go any further if we've found error(s) during the
5797 if (!java_error_count)
5798 source_end_java_method ();
5801 pushdecl_force_head (DECL_ARGUMENTS (mdecl));
5805 /* Pop the exceptions and sanity check */
5807 if (currently_caught_type_list)
5808 fatal ("Exception list non empty - java_complete_expand_method");
5812 /* Craft a body for default constructor. Patch existing constructor
5813 bodies with call to super() and field initialization statements if
5817 fix_constructors (mdecl)
5820 tree body = DECL_FUNCTION_BODY (mdecl);
5824 /* The constructor body must be crafted by hand. It's the
5825 constructor we defined when we realize we didn't have the
5826 CLASSNAME() constructor */
5830 /* It is an error for the compiler to generate a default
5831 constructor if the superclass doesn't have a constructor that
5832 takes no argument */
5833 if (verify_constructor_super ())
5835 tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (current_class));
5836 char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
5837 parse_error_context (lookup_cl (TYPE_NAME (current_class)),
5838 "No constructor matching `%s()' found in "
5839 "class `%s'", n, n);
5842 start_artificial_method_body (mdecl);
5844 /* We don't generate a super constructor invocation if we're
5845 compiling java.lang.Object. build_super_invocation takes care
5847 compound = java_method_add_stmt (mdecl, build_super_invocation ());
5849 end_artificial_method_body (mdecl);
5851 /* Search for an explicit constructor invocation */
5855 tree main_block = BLOCK_EXPR_BODY (body);
5856 tree compound = NULL_TREE;
5859 switch (TREE_CODE (body))
5862 found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
5866 case EXPR_WITH_FILE_LOCATION:
5867 body = TREE_OPERAND (body, 0);
5870 body = BLOCK_EXPR_BODY (body);
5876 /* The constructor is missing an invocation of super() */
5878 compound = add_stmt_to_compound (compound, NULL_TREE,
5879 build_super_invocation ());
5881 /* Fix the constructor main block if we're adding extra stmts */
5884 compound = add_stmt_to_compound (compound, NULL_TREE,
5885 BLOCK_EXPR_BODY (main_block));
5886 BLOCK_EXPR_BODY (main_block) = compound;
5891 /* Browse constructors in the super class, searching for a constructor
5892 that doesn't take any argument. Return 0 if one is found, 1
5896 verify_constructor_super ()
5898 tree class = CLASSTYPE_SUPER (current_class);
5905 for (mdecl = TYPE_METHODS (class); mdecl; mdecl = TREE_CHAIN (mdecl))
5907 if (DECL_CONSTRUCTOR_P (mdecl)
5908 && TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (mdecl))) == end_params_node)
5915 /* Expand finals. */
5918 java_expand_finals ()
5922 /* Generate code for all context remembered for code generation. */
5925 java_expand_classes ()
5927 int save_error_count = 0;
5928 java_parse_abort_on_error ();
5929 if (!(ctxp = ctxp_for_generation))
5931 java_layout_classes ();
5932 java_parse_abort_on_error ();
5934 for (; ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
5936 ctxp = ctxp_for_generation;
5937 lang_init_source (2); /* Error msgs have method prototypes */
5938 java_complete_expand_methods (); /* Complete and expand method bodies */
5939 java_parse_abort_on_error ();
5940 java_expand_finals (); /* Expand and check the finals */
5941 java_parse_abort_on_error ();
5942 java_check_final (); /* Check unitialized final */
5943 java_parse_abort_on_error ();
5947 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
5948 a tree list node containing RIGHT. Fore coming RIGHTs will be
5949 chained to this hook. LOCATION contains the location of the
5950 separating `.' operator. */
5953 make_qualified_primary (primary, right, location)
5954 tree primary, right;
5959 /* We want to process THIS . xxx symbolicaly, to keep it consistent
5960 with the way we're processing SUPER. A THIS from a primary as a
5961 different form than a SUPER. Turn THIS into something symbolic */
5962 if (TREE_CODE (primary) == THIS_EXPR)
5964 wfl = build_wfl_node (this_identifier_node);
5965 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (primary);
5966 wfl = make_qualified_name (wfl, right, location);
5967 PRIMARY_P (wfl) = 1;
5970 /* Other non WFL node are wrapped around a WFL */
5971 else if (TREE_CODE (primary) != EXPR_WITH_FILE_LOCATION)
5973 wfl = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
5974 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (primary);
5975 EXPR_WFL_QUALIFICATION (wfl) = build_tree_list (primary, NULL_TREE);
5980 if (!EXPR_WFL_QUALIFICATION (primary))
5981 EXPR_WFL_QUALIFICATION (primary) =
5982 build_tree_list (primary, NULL_TREE);
5985 EXPR_WFL_LINECOL (right) = location;
5986 chainon (EXPR_WFL_QUALIFICATION (wfl), build_tree_list (right, NULL_TREE));
5987 PRIMARY_P (wfl) = 1;
5991 /* Simple merge of two name separated by a `.' */
5994 merge_qualified_name (left, right)
5998 obstack_grow (&temporary_obstack, IDENTIFIER_POINTER (left),
5999 IDENTIFIER_LENGTH (left));
6000 obstack_1grow (&temporary_obstack, '.');
6001 obstack_grow0 (&temporary_obstack, IDENTIFIER_POINTER (right),
6002 IDENTIFIER_LENGTH (right));
6003 node = get_identifier (obstack_base (&temporary_obstack));
6004 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
6005 QUALIFIED_P (node) = 1;
6009 /* Merge the two parts of a qualified name into LEFT. Set the
6010 location information of the resulting node to LOCATION, usually
6011 inherited from the location information of the `.' operator. */
6014 make_qualified_name (left, right, location)
6018 #ifdef USE_COMPONENT_REF
6019 tree node = build (COMPONENT_REF, NULL_TREE, left, right);
6020 EXPR_WFL_LINECOL (node) = location;
6023 tree left_id = EXPR_WFL_NODE (left);
6024 tree right_id = EXPR_WFL_NODE (right);
6027 merge = merge_qualified_name (left_id, right_id);
6029 /* Left wasn't qualified and is now qualified */
6030 if (!QUALIFIED_P (left_id))
6032 tree wfl = build_expr_wfl (left_id, ctxp->filename, 0, 0);
6033 EXPR_WFL_LINECOL (wfl) = EXPR_WFL_LINECOL (left);
6034 EXPR_WFL_QUALIFICATION (left) = build_tree_list (wfl, NULL_TREE);
6037 wfl = build_expr_wfl (right_id, ctxp->filename, 0, 0);
6038 EXPR_WFL_LINECOL (wfl) = location;
6039 chainon (EXPR_WFL_QUALIFICATION (left), build_tree_list (wfl, NULL_TREE));
6041 EXPR_WFL_NODE (left) = merge;
6046 /* Extract the last identifier component of the qualified in WFL. The
6047 last identifier is removed from the linked list */
6050 cut_identifier_in_qualified (wfl)
6054 tree previous = NULL_TREE;
6055 for (q = EXPR_WFL_QUALIFICATION (wfl); ; previous = q, q = TREE_CHAIN (q))
6056 if (!TREE_CHAIN (q))
6059 fatal ("Operating on a non qualified qualified WFL - "
6060 "cut_identifier_in_qualified");
6061 TREE_CHAIN (previous) = NULL_TREE;
6062 return TREE_PURPOSE (q);
6066 /* Resolve the expression name NAME. Return its decl. */
6069 resolve_expression_name (id, orig)
6073 tree name = EXPR_WFL_NODE (id);
6076 /* 6.5.5.1: Simple expression names */
6077 if (!PRIMARY_P (id) && !QUALIFIED_P (name))
6079 /* 15.13.1: NAME can appear within the scope of a local variable
6081 if ((decl = IDENTIFIER_LOCAL_VALUE (name)))
6084 /* 15.13.1: NAME can appear within a class declaration */
6087 decl = lookup_field_wrapper (current_class, name);
6090 int fs = FIELD_STATIC (decl);
6091 /* Instance variable (8.3.1.1) can't appear within
6092 static method, static initializer or initializer for
6093 a static variable. */
6094 if (!fs && METHOD_STATIC (current_function_decl))
6097 (id, "Can't make a static reference to nonstatic variable "
6098 "`%s' in class `%s'",
6099 IDENTIFIER_POINTER (name),
6100 IDENTIFIER_POINTER (DECL_NAME
6101 (TYPE_NAME (current_class))));
6102 return error_mark_node;
6104 /* Instance variables can't appear as an argument of
6105 an explicit constructor invocation */
6106 if (!fs && ctxp->explicit_constructor_p)
6109 (id, "Can't reference `%s' before the superclass "
6110 "constructor has been called", IDENTIFIER_POINTER (name));
6111 return error_mark_node;
6114 /* Otherwise build what it takes to access the field */
6115 decl = build_field_ref ((fs ? NULL_TREE : current_this),
6116 DECL_CONTEXT (decl), name);
6117 if (fs && !flag_emit_class_files && !flag_emit_xref)
6118 decl = build_class_init (DECL_CONTEXT (decl), decl);
6119 /* We may be asked to save the real field access node */
6122 /* And we return what we got */
6125 /* Fall down to error report on undefined variable */
6128 /* 6.5.5.2 Qualified Expression Names */
6133 qualify_ambiguous_name (id);
6134 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
6135 /* 15.10.2: Accessing Superclass Members using super */
6136 return resolve_field_access (id, NULL, NULL);
6139 /* We've got an error here */
6140 parse_error_context (id, "Undefined variable `%s'",
6141 IDENTIFIER_POINTER (name));
6143 return error_mark_node;
6146 /* 15.10.1 Field Acess Using a Primary and/or Expression Name.
6147 We return something suitable to generate the field access. We also
6148 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
6149 recipient's address can be null. */
6152 resolve_field_access (qual_wfl, field_decl, field_type)
6154 tree *field_decl, *field_type;
6158 tree decl, where_found, type_found;
6160 if (resolve_qualified_expression_name (qual_wfl, &decl,
6161 &where_found, &type_found))
6162 return error_mark_node;
6164 /* Resolve the LENGTH field of an array here */
6165 if (DECL_NAME (decl) == length_identifier_node && TYPE_ARRAY_P (type_found)
6166 && ! flag_emit_class_files && ! flag_emit_xref)
6168 tree length = build_java_array_length_access (where_found);
6170 build_java_arraynull_check (type_found, length, int_type_node);
6172 /* We might have been trying to resolve field.method(). In which
6173 case, the resolution is over and decl is the answer */
6174 else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
6176 else if (JDECL_P (decl))
6178 int static_final_found = 0;
6180 type_found = DECL_CONTEXT (decl);
6181 is_static = JDECL_P (decl) && FIELD_STATIC (decl);
6182 if (FIELD_FINAL (decl)
6183 && JPRIMITIVE_TYPE_P (TREE_TYPE (decl))
6184 && DECL_LANG_SPECIFIC (decl)
6185 && DECL_INITIAL (decl))
6187 field_ref = DECL_INITIAL (decl);
6188 static_final_found = 1;
6191 field_ref = build_field_ref ((is_static ? NULL_TREE : where_found),
6192 type_found, DECL_NAME (decl));
6193 if (field_ref == error_mark_node)
6194 return error_mark_node;
6195 if (is_static && !static_final_found
6196 && !flag_emit_class_files && !flag_emit_xref)
6198 field_ref = build_class_init (type_found, field_ref);
6199 /* If the static field was identified by an expression that
6200 needs to be generated, make the field access a compound
6201 expression whose first part of the evaluation of the
6202 field selector part. */
6203 if (where_found && TREE_CODE (where_found) != TYPE_DECL
6204 && TREE_CODE (where_found) != RECORD_TYPE)
6206 tree type = QUAL_DECL_TYPE (field_ref);
6207 field_ref = build (COMPOUND_EXPR, type, where_found, field_ref);
6217 *field_type = (QUAL_DECL_TYPE (decl) ?
6218 QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
6222 /* If NODE is an access to f static field, strip out the class
6223 initialization part and return the field decl, otherwise, return
6227 strip_out_static_field_access_decl (node)
6230 if (TREE_CODE (node) == COMPOUND_EXPR)
6232 tree op1 = TREE_OPERAND (node, 1);
6233 if (TREE_CODE (op1) == COMPOUND_EXPR)
6235 tree call = TREE_OPERAND (op1, 0);
6236 if (TREE_CODE (call) == CALL_EXPR
6237 && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
6238 && TREE_OPERAND (TREE_OPERAND (call, 0), 0)
6239 == soft_initclass_node)
6240 return TREE_OPERAND (op1, 1);
6246 /* 6.5.5.2: Qualified Expression Names */
6249 resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
6251 tree *found_decl, *type_found, *where_found;
6253 int from_type = 0; /* Field search initiated from a type */
6254 int from_super = 0, from_cast = 0;
6255 int previous_call_static = 0;
6257 tree decl = NULL_TREE, type = NULL_TREE, q;
6258 *type_found = *where_found = NULL_TREE;
6260 for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
6262 tree qual_wfl = QUAL_WFL (q);
6264 /* 15.10.1 Field Access Using a Primary */
6265 switch (TREE_CODE (qual_wfl))
6268 case NEW_CLASS_EXPR:
6269 /* If the access to the function call is a non static field,
6270 build the code to access it. */
6271 if (JDECL_P (decl) && !FIELD_STATIC (decl))
6273 decl = maybe_access_field (decl, *where_found,
6274 DECL_CONTEXT (decl));
6275 if (decl == error_mark_node)
6278 /* And code for the function call */
6279 if (complete_function_arguments (qual_wfl))
6281 if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
6282 CALL_USING_SUPER (qual_wfl) = 1;
6284 patch_method_invocation (qual_wfl, decl, type, &is_static, NULL);
6285 if (*where_found == error_mark_node)
6287 *type_found = type = QUAL_DECL_TYPE (*where_found);
6289 /* If the previous call was static and this one is too,
6290 build a compound expression to hold the two (because in
6291 that case, previous function calls aren't transported as
6292 forcoming function's argument. */
6293 if (previous_call_static && is_static)
6295 decl = build (COMPOUND_EXPR, type, decl, *where_found);
6296 TREE_SIDE_EFFECTS (decl) = 1;
6300 previous_call_static = is_static;
6301 decl = *where_found;
6305 case NEW_ARRAY_EXPR:
6306 *where_found = decl = java_complete_tree (qual_wfl);
6307 if (decl == error_mark_node)
6309 *type_found = type = QUAL_DECL_TYPE (decl);
6310 CLASS_LOADED_P (type) = 1;
6314 *where_found = decl = java_complete_tree (qual_wfl);
6315 if (decl == error_mark_node)
6317 *type_found = type = QUAL_DECL_TYPE (decl);
6321 case CONDITIONAL_EXPR:
6323 *where_found = decl = java_complete_tree (qual_wfl);
6324 if (decl == error_mark_node)
6326 *type_found = type = QUAL_DECL_TYPE (decl);
6330 /* If the access to the function call is a non static field,
6331 build the code to access it. */
6332 if (JDECL_P (decl) && !FIELD_STATIC (decl))
6334 decl = maybe_access_field (decl, *where_found, type);
6335 if (decl == error_mark_node)
6338 /* And code for the array reference expression */
6339 decl = java_complete_tree (qual_wfl);
6340 if (decl == error_mark_node)
6342 type = QUAL_DECL_TYPE (decl);
6346 /* Fix for -Wall Just go to the next statement. Don't
6351 /* If we fall here, we weren't processing a (static) function call. */
6352 previous_call_static = 0;
6354 /* It can be the keyword THIS */
6355 if (EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
6360 (wfl, "Keyword `this' used outside allowed context");
6363 /* We have to generate code for intermediate acess */
6364 *where_found = decl = current_this;
6365 *type_found = type = QUAL_DECL_TYPE (decl);
6369 /* 15.10.2 Accessing Superclass Members using SUPER */
6370 if (EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
6373 /* Check on the restricted use of SUPER */
6374 if (METHOD_STATIC (current_function_decl)
6375 || current_class == object_type_node)
6378 (wfl, "Keyword `super' used outside allowed context");
6381 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
6382 node = build_cast (EXPR_WFL_LINECOL (qual_wfl),
6383 CLASSTYPE_SUPER (current_class),
6384 build_this (EXPR_WFL_LINECOL (qual_wfl)));
6385 *where_found = decl = java_complete_tree (node);
6386 if (decl == error_mark_node)
6388 *type_found = type = QUAL_DECL_TYPE (decl);
6389 from_super = from_type = 1;
6393 /* 15.13.1: Can't search for field name in packages, so we
6394 assume a variable/class name was meant. */
6395 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
6397 tree name = resolve_package (wfl, &q);
6400 *where_found = decl = resolve_no_layout (name, qual_wfl);
6401 /* We wan't to be absolutely that the class is laid
6402 out. We're going to search something inside it. */
6403 *type_found = type = TREE_TYPE (decl);
6404 layout_class (type);
6406 /* Should be a list, really. FIXME */
6407 RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (TREE_CHAIN (q))) = 1;
6408 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (TREE_CHAIN (q))) = 0;
6412 if (from_super || from_cast)
6414 ((from_cast ? qual_wfl : wfl),
6415 "No variable `%s' defined in class `%s'",
6416 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6417 lang_printable_name (type, 0));
6420 (qual_wfl, "Undefined variable or class name: `%s'",
6421 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)));
6426 /* We have a type name. It's been already resolved when the
6427 expression was qualified. */
6428 else if (RESOLVE_TYPE_NAME_P (qual_wfl))
6430 if (!(decl = QUAL_RESOLUTION (q)))
6431 return 1; /* Error reported already */
6433 if (not_accessible_p (TREE_TYPE (decl), decl, 0))
6436 (qual_wfl, "Can't access %s field `%s.%s' from `%s'",
6437 java_accstring_lookup (get_access_flags_from_decl (decl)),
6438 GET_TYPE_NAME (type),
6439 IDENTIFIER_POINTER (DECL_NAME (decl)),
6440 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
6443 check_deprecation (qual_wfl, decl);
6445 type = TREE_TYPE (decl);
6448 /* We resolve and expression name */
6453 /* If there exists an early resolution, use it. That occurs
6454 only once and we know that there are more things to
6455 come. Don't do that when processing something after SUPER
6456 (we need more thing to be put in place below */
6457 if (!from_super && QUAL_RESOLUTION (q))
6459 decl = QUAL_RESOLUTION (q);
6462 if (!FIELD_STATIC (decl))
6463 *where_found = current_this;
6466 *where_found = TREE_TYPE (decl);
6467 if (TREE_CODE (*where_found) == POINTER_TYPE)
6468 *where_found = TREE_TYPE (*where_found);
6473 /* We have to search for a field, knowing the type of its
6474 container. The flag FROM_TYPE indicates that we resolved
6475 the last member of the expression as a type name, which
6476 means that for the resolution of this field, we'll look
6477 for other errors than if it was resolved as a member of
6482 tree field_decl_type; /* For layout */
6484 if (!from_type && !JREFERENCE_TYPE_P (type))
6487 (qual_wfl, "Attempt to reference field `%s' in `%s %s'",
6488 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6489 lang_printable_name (type, 0),
6490 IDENTIFIER_POINTER (DECL_NAME (field_decl)));
6494 field_decl = lookup_field_wrapper (type,
6495 EXPR_WFL_NODE (qual_wfl));
6496 if (field_decl == NULL_TREE)
6499 (qual_wfl, "No variable `%s' defined in type `%s'",
6500 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6501 GET_TYPE_NAME (type));
6504 if (field_decl == error_mark_node)
6507 /* Layout the type of field_decl, since we may need
6508 it. Don't do primitive types or loaded classes. The
6509 situation of non primitive arrays may not handled
6510 properly here. FIXME */
6511 if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
6512 field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
6514 field_decl_type = TREE_TYPE (field_decl);
6515 if (!JPRIMITIVE_TYPE_P (field_decl_type)
6516 && !CLASS_LOADED_P (field_decl_type)
6517 && !TYPE_ARRAY_P (field_decl_type))
6518 resolve_and_layout (field_decl_type, NULL_TREE);
6519 if (TYPE_ARRAY_P (field_decl_type))
6520 CLASS_LOADED_P (field_decl_type) = 1;
6522 /* Check on accessibility here */
6523 if (not_accessible_p (type, field_decl, from_super))
6527 "Can't access %s field `%s.%s' from `%s'",
6528 java_accstring_lookup
6529 (get_access_flags_from_decl (field_decl)),
6530 GET_TYPE_NAME (type),
6531 IDENTIFIER_POINTER (DECL_NAME (field_decl)),
6533 (DECL_NAME (TYPE_NAME (current_class))));
6536 check_deprecation (qual_wfl, field_decl);
6538 /* There are things to check when fields are accessed
6539 from type. There are no restrictions on a static
6540 declaration of the field when it is accessed from an
6542 is_static = FIELD_STATIC (field_decl);
6543 if (!from_super && from_type
6544 && !TYPE_INTERFACE_P (type) && !is_static)
6547 (qual_wfl, "Can't make a static reference to nonstatic "
6548 "variable `%s' in class `%s'",
6549 IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
6550 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
6553 from_cast = from_super = 0;
6555 /* If we need to generate something to get a proper
6556 handle on what this field is accessed from, do it
6560 decl = maybe_access_field (decl, *where_found, *type_found);
6561 if (decl == error_mark_node)
6565 /* We want to keep the location were found it, and the type
6567 *where_found = decl;
6570 /* This is the decl found and eventually the next one to
6575 type = QUAL_DECL_TYPE (decl);
6582 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
6583 can't be accessed from REFERENCE (a record type). */
6585 int not_accessible_p (reference, member, from_super)
6586 tree reference, member;
6589 int access_flag = get_access_flags_from_decl (member);
6591 /* Access always granted for members declared public */
6592 if (access_flag & ACC_PUBLIC)
6595 /* Check access on protected members */
6596 if (access_flag & ACC_PROTECTED)
6598 /* Access granted if it occurs from within the package
6599 containing the class in which the protected member is
6601 if (class_in_current_package (DECL_CONTEXT (member)))
6604 /* If accessed with the form `super.member', then access is granted */
6608 /* Otherwise, access is granted if occuring from the class where
6609 member is declared or a subclass of it */
6610 if (inherits_from_p (reference, current_class))
6615 /* Check access on private members. Access is granted only if it
6616 occurs from within the class in witch it is declared */
6617 if (access_flag & ACC_PRIVATE)
6618 return (current_class == DECL_CONTEXT (member) ? 0 : 1);
6620 /* Default access are permitted only when occuring within the
6621 package in which the type (REFERENCE) is declared. In other words,
6622 REFERENCE is defined in the current package */
6624 return !class_in_current_package (reference);
6626 /* Otherwise, access is granted */
6630 /* Test deprecated decl access. */
6632 check_deprecation (wfl, decl)
6635 char *file = DECL_SOURCE_FILE (decl);
6636 /* Complain if the field is deprecated and the file it was defined
6637 in isn't compiled at the same time the file which contains its
6639 if (DECL_DEPRECATED (decl)
6640 && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
6643 switch (TREE_CODE (decl))
6646 strcpy (the, "method");
6649 strcpy (the, "field");
6652 strcpy (the, "class");
6655 fatal ("unexpected DECL code - check_deprecation");
6657 parse_warning_context
6658 (wfl, "The %s `%s' in class `%s' has been deprecated",
6659 the, lang_printable_name (decl, 0),
6660 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
6664 /* Returns 1 if class was declared in the current package, 0 otherwise */
6667 class_in_current_package (class)
6670 static tree cache = NULL_TREE;
6677 qualified_flag = QUALIFIED_P (DECL_NAME (TYPE_NAME (class)));
6679 /* If the current package is empty and the name of CLASS is
6680 qualified, class isn't in the current package. If there is a
6681 current package and the name of the CLASS is not qualified, class
6682 isn't in the current package */
6683 if ((!ctxp->package && qualified_flag) || (ctxp->package && !qualified_flag))
6686 /* If there is not package and the name of CLASS isn't qualified,
6687 they belong to the same unnamed package */
6688 if (!ctxp->package && !qualified_flag)
6691 /* Compare the left part of the name of CLASS with the package name */
6692 breakdown_qualified (&left, NULL, DECL_NAME (TYPE_NAME (class)));
6693 if (ctxp->package == left)
6701 /* This function may generate code to access DECL from WHERE. This is
6702 done only if certain conditions meet. */
6705 maybe_access_field (decl, where, type)
6706 tree decl, where, type;
6708 if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
6709 && !FIELD_STATIC (decl))
6710 decl = build_field_ref (where ? where : current_this,
6711 (type ? type : DECL_CONTEXT (decl)),
6716 /* Build a method invocation, by patching PATCH. If non NULL
6717 and according to the situation, PRIMARY and WHERE may be
6718 used. IS_STATIC is set to 1 if the invoked function is static. */
6721 patch_method_invocation (patch, primary, where, is_static, ret_decl)
6722 tree patch, primary, where;
6726 tree wfl = TREE_OPERAND (patch, 0);
6727 tree args = TREE_OPERAND (patch, 1);
6728 tree name = EXPR_WFL_NODE (wfl);
6730 int is_static_flag = 0;
6731 int is_super_init = 0;
6732 tree this_arg = NULL_TREE;
6734 /* Should be overriden if everything goes well. Otherwise, if
6735 something fails, it should keep this value. It stop the
6736 evaluation of a bogus assignment. See java_complete_tree,
6737 MODIFY_EXPR: for the reasons why we sometimes want to keep on
6738 evaluating an assignment */
6739 TREE_TYPE (patch) = error_mark_node;
6741 /* Since lookup functions are messing with line numbers, save the
6743 java_parser_context_save_global ();
6745 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
6747 /* Resolution of qualified name, excluding constructors */
6748 if (QUALIFIED_P (name) && !CALL_CONSTRUCTOR_P (patch))
6750 tree class_decl, identifier, identifier_wfl;
6751 /* Extract the last IDENTIFIER of the qualified
6752 expression. This is a wfl and we will use it's location
6753 data during error report. */
6754 identifier_wfl = cut_identifier_in_qualified (wfl);
6755 identifier = EXPR_WFL_NODE (identifier_wfl);
6757 /* Given the context, IDENTIFIER is syntactically qualified
6758 as a MethodName. We need to qualify what's before */
6759 qualify_ambiguous_name (wfl);
6761 /* Package resolution are erroneous */
6762 if (RESOLVE_PACKAGE_NAME_P (wfl))
6765 breakdown_qualified (&remainder, NULL, EXPR_WFL_NODE (wfl));
6766 parse_error_context (wfl, "Can't search method `%s' in package "
6767 "`%s'",IDENTIFIER_POINTER (identifier),
6768 IDENTIFIER_POINTER (remainder));
6769 PATCH_METHOD_RETURN_ERROR ();
6771 /* We're resolving a call from a type */
6772 else if (RESOLVE_TYPE_NAME_P (wfl))
6774 tree decl = QUAL_RESOLUTION (EXPR_WFL_QUALIFICATION (wfl));
6775 tree name = DECL_NAME (decl);
6778 class_decl = resolve_and_layout (name, wfl);
6779 if (CLASS_INTERFACE (decl))
6782 (identifier_wfl, "Can't make static reference to method "
6783 "`%s' in interface `%s'", IDENTIFIER_POINTER (identifier),
6784 IDENTIFIER_POINTER (name));
6785 PATCH_METHOD_RETURN_ERROR ();
6787 /* Look the method up in the type selector. The method ought
6789 type = TREE_TYPE (class_decl);
6790 list = lookup_method_invoke (0, wfl, type, identifier, args);
6791 if (list && !METHOD_STATIC (list))
6793 char *fct_name = strdup (lang_printable_name (list, 0));
6796 "Can't make static reference to method `%s %s' in class `%s'",
6797 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
6798 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
6800 PATCH_METHOD_RETURN_ERROR ();
6802 args = nreverse (args);
6804 /* We're resolving an expression name */
6809 /* 1- Find the field to which the call applies */
6810 field = resolve_field_access (wfl, NULL, &type);
6811 if (field == error_mark_node)
6812 PATCH_METHOD_RETURN_ERROR ();
6813 /* field is used in lieu of a primary. It alows us not to
6814 report errors on erroneous use of `this' in
6818 /* 2- Do the layout of the class where the last field
6819 was found, so we can search it. */
6820 class_decl = resolve_and_layout (type, NULL_TREE);
6821 if (class_decl != NULL_TREE)
6822 type = TREE_TYPE (class_decl);
6824 /* 3- Retrieve a filtered list of method matches, Refine
6825 if necessary. In any cases, point out errors. */
6826 list = lookup_method_invoke (0, identifier_wfl, type,
6829 /* 4- Add the field as an argument */
6830 args = nreverse (args);
6834 /* IDENTIFIER_WFL will be used to report any problem further */
6835 wfl = identifier_wfl;
6837 /* Resolution of simple names, names generated after a primary: or
6841 tree class_to_search;
6842 int lc; /* Looking for Constructor */
6844 /* We search constructor in their target class */
6845 if (CALL_CONSTRUCTOR_P (patch))
6847 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
6848 class_to_search = EXPR_WFL_NODE (wfl);
6849 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
6850 this_identifier_node)
6851 class_to_search = NULL_TREE;
6852 else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
6853 super_identifier_node)
6856 if (CLASSTYPE_SUPER (current_class))
6858 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
6861 parse_error_context (wfl, "Can't invoke super constructor "
6862 "on java.lang.Object");
6863 PATCH_METHOD_RETURN_ERROR ();
6867 /* Class to search is NULL if we're searching the current one */
6868 if (class_to_search)
6870 class_to_search = resolve_and_layout (class_to_search,
6872 if (!class_to_search)
6875 (wfl, "Class `%s' not found in type declaration",
6876 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
6877 PATCH_METHOD_RETURN_ERROR ();
6880 /* Can't instantiate an abstract class, but we can
6881 invoke it's constructor. It's use within the `new'
6882 context is denied here. */
6883 if (CLASS_ABSTRACT (class_to_search)
6884 && TREE_CODE (patch) == NEW_CLASS_EXPR)
6887 (wfl, "Class `%s' is an abstract class. It can't be "
6888 "instantiated", IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
6889 PATCH_METHOD_RETURN_ERROR ();
6891 class_to_search = TREE_TYPE (class_to_search);
6894 class_to_search = current_class;
6897 /* This is a regular search in the local class, unless an
6898 alternate class is specified. */
6901 class_to_search = (where ? where : current_class);
6905 /* NAME is a simple identifier or comes from a primary. Search
6906 in the class whose declaration contain the method being
6908 resolve_and_layout (class_to_search, NULL_TREE);
6909 list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
6911 /* Don't continue if no method were found, as the next statement
6912 can't be executed then. */
6914 PATCH_METHOD_RETURN_ERROR ();
6916 /* Check for static reference if non static methods */
6917 if (check_for_static_method_reference (wfl, patch, list,
6918 class_to_search, primary))
6919 PATCH_METHOD_RETURN_ERROR ();
6921 /* Non static methods are called with the current object extra
6922 argument. If patch a `new TYPE()', the argument is the value
6923 returned by the object allocator. If method is resolved as a
6924 primary, use the primary otherwise use the current THIS. */
6925 args = nreverse (args);
6926 if (TREE_CODE (patch) != NEW_CLASS_EXPR)
6927 this_arg = primary ? primary : current_this;
6930 /* Merge point of all resolution schemes. If we have nothing, this
6931 is an error, already signaled */
6933 PATCH_METHOD_RETURN_ERROR ();
6935 /* Check accessibility, position the is_static flag, build and
6937 if (not_accessible_p (DECL_CONTEXT (current_function_decl), list, 0))
6939 char *fct_name = strdup (lang_printable_name (list, 0));
6941 (wfl, "Can't access %s method `%s %s.%s' from `%s'",
6942 java_accstring_lookup (get_access_flags_from_decl (list)),
6943 lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0),
6944 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list)))),
6945 fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
6947 PATCH_METHOD_RETURN_ERROR ();
6949 check_deprecation (wfl, list);
6951 is_static_flag = METHOD_STATIC (list);
6952 if (! METHOD_STATIC (list) && this_arg != NULL_TREE)
6953 args = tree_cons (NULL_TREE, this_arg, args);
6955 /* In the context of an explicit constructor invocation, we can't
6956 invoke any method relying on `this'. Exceptions are: we're
6957 invoking a static function, primary exists and is not the current
6958 this, we're creating a new object. */
6959 if (ctxp->explicit_constructor_p
6961 && (!primary || primary == current_this)
6962 && (TREE_CODE (patch) != NEW_CLASS_EXPR))
6965 (wfl, "Can't reference `this' before the superclass constructor has "
6967 PATCH_METHOD_RETURN_ERROR ();
6969 java_parser_context_restore_global ();
6971 *is_static = is_static_flag;
6972 /* Sometimes, we want the decl of the selected method. Such as for
6976 patch = patch_invoke (patch, list, args);
6977 if (is_super_init && CLASS_HAS_FINIT_P (current_class))
6979 /* Generate the code used to initialize fields declared with an
6980 initialization statement. For now, it returns a call the the
6981 artificial function $finit$, if required. */
6984 build_method_invocation (build_expr_wfl (finit_identifier_node,
6985 input_filename, 0, 0),
6987 patch = build (COMPOUND_EXPR, void_type_node, patch,
6988 java_complete_tree (finit_call));
6989 CAN_COMPLETE_NORMALLY (patch) = 1;
6994 /* Check that we're not trying to do a static reference to a method in
6995 non static method. Return 1 if it's the case, 0 otherwise. */
6998 check_for_static_method_reference (wfl, node, method, where, primary)
6999 tree wfl, node, method, where, primary;
7001 if (METHOD_STATIC (current_function_decl)
7002 && !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
7004 char *fct_name = strdup (lang_printable_name (method, 0));
7006 (wfl, "Can't make static reference to method `%s %s' in class `%s'",
7007 lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
7008 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (where))));
7015 /* Patch an invoke expression METHOD and ARGS, based on its invocation
7019 patch_invoke (patch, method, args)
7020 tree patch, method, args;
7023 tree original_call, t, ta;
7025 /* Last step for args: convert build-in types. If we're dealing with
7026 a new TYPE() type call, the first argument to the constructor
7027 isn't found in the incomming argument list, but delivered by
7029 t = TYPE_ARG_TYPES (TREE_TYPE (method));
7030 if (TREE_CODE (patch) == NEW_CLASS_EXPR)
7032 for (ta = args; t != end_params_node && ta;
7033 t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
7034 if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
7035 TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
7036 TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
7038 if (flag_emit_class_files || flag_emit_xref)
7042 tree signature = build_java_signature (TREE_TYPE (method));
7043 switch (invocation_mode (method, CALL_USING_SUPER (patch)))
7045 case INVOKE_VIRTUAL:
7046 dtable = invoke_build_dtable (0, args);
7047 func = build_invokevirtual (dtable, method);
7052 func = build_known_method_ref (method, TREE_TYPE (method),
7053 DECL_CONTEXT (method),
7057 case INVOKE_INTERFACE:
7058 dtable = invoke_build_dtable (1, args);
7059 func = build_invokeinterface (dtable, DECL_NAME (method), signature);
7063 fatal ("internal error - unknown invocation_mode result");
7066 /* Ensure self_type is initialized, (invokestatic). FIXME */
7067 func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
7070 TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
7071 TREE_OPERAND (patch, 0) = func;
7072 TREE_OPERAND (patch, 1) = args;
7073 original_call = patch;
7075 /* We're processing a `new TYPE ()' form. New is called an its
7076 returned value is the first argument to the constructor. We build
7077 a COMPOUND_EXPR and use saved expression so that the overall NEW
7078 expression value is a pointer to a newly created and initialized
7080 if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
7082 tree class = DECL_CONTEXT (method);
7083 tree c1, saved_new, size, new;
7084 if (flag_emit_class_files || flag_emit_xref)
7086 TREE_TYPE (patch) = build_pointer_type (class);
7089 if (!TYPE_SIZE (class))
7090 safe_layout_class (class);
7091 size = size_in_bytes (class);
7092 new = build (CALL_EXPR, promote_type (class),
7093 build_address_of (alloc_object_node),
7094 tree_cons (NULL_TREE, build_class_ref (class),
7095 build_tree_list (NULL_TREE,
7096 size_in_bytes (class))),
7098 saved_new = save_expr (new);
7099 c1 = build_tree_list (NULL_TREE, saved_new);
7100 TREE_CHAIN (c1) = TREE_OPERAND (original_call, 1);
7101 TREE_OPERAND (original_call, 1) = c1;
7102 TREE_SET_CODE (original_call, CALL_EXPR);
7103 patch = build (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new);
7109 invocation_mode (method, super)
7113 int access = get_access_flags_from_decl (method);
7116 return INVOKE_SUPER;
7118 if (access & ACC_STATIC || access & ACC_FINAL || access & ACC_PRIVATE)
7119 return INVOKE_STATIC;
7121 if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
7122 return INVOKE_STATIC;
7124 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
7125 return INVOKE_INTERFACE;
7127 if (DECL_CONSTRUCTOR_P (method))
7128 return INVOKE_STATIC;
7130 return INVOKE_VIRTUAL;
7133 /* Retrieve a refined list of matching methods. It covers the step
7134 15.11.2 (Compile-Time Step 2) */
7137 lookup_method_invoke (lc, cl, class, name, arg_list)
7140 tree class, name, arg_list;
7142 tree atl = end_params_node; /* Arg Type List */
7143 tree method, signature, list, node;
7144 char *candidates; /* Used for error report */
7146 /* Fix the arguments */
7147 for (node = arg_list; node; node = TREE_CHAIN (node))
7149 tree current_arg = TREE_TYPE (TREE_VALUE (node));
7150 /* Non primitive type may have to be resolved */
7151 if (!JPRIMITIVE_TYPE_P (current_arg))
7152 resolve_and_layout (current_arg, NULL_TREE);
7154 if (TREE_CODE (current_arg) == RECORD_TYPE)
7155 current_arg = promote_type (current_arg);
7156 atl = tree_cons (NULL_TREE, current_arg, atl);
7159 /* Find all candidates and then refine the list, searching for the
7160 most specific method. */
7161 list = find_applicable_accessible_methods_list (lc, class, name, atl);
7162 list = find_most_specific_methods_list (list);
7163 if (list && !TREE_CHAIN (list))
7164 return TREE_VALUE (list);
7166 /* Issue an error. List candidates if any. Candidates are listed
7167 only if accessible (non accessible methods may end-up here for
7168 the sake of a better error report). */
7173 obstack_grow (&temporary_obstack, ". Candidates are:\n", 18);
7174 for (current = list; current; current = TREE_CHAIN (current))
7176 tree cm = TREE_VALUE (current);
7178 if (!cm || not_accessible_p (class, cm, 0))
7181 (string, " `%s' in `%s'%s",
7182 get_printable_method_name (cm),
7183 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
7184 (TREE_CHAIN (current) ? "\n" : ""));
7185 obstack_grow (&temporary_obstack, string, strlen (string));
7187 obstack_1grow (&temporary_obstack, '\0');
7188 candidates = obstack_finish (&temporary_obstack);
7190 /* Issue the error message */
7191 method = make_node (FUNCTION_TYPE);
7192 TYPE_ARG_TYPES (method) = atl;
7193 signature = build_java_argument_signature (method);
7194 parse_error_context (cl, "Can't find %s `%s(%s)' in class `%s'%s",
7195 (lc ? "constructor" : "method"),
7197 IDENTIFIER_POINTER(DECL_NAME (TYPE_NAME (class))) :
7198 IDENTIFIER_POINTER (name)),
7199 IDENTIFIER_POINTER (signature),
7200 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class))),
7201 (candidates ? candidates : ""));
7205 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
7206 when we're looking for a constructor. */
7209 find_applicable_accessible_methods_list (lc, class, name, arglist)
7211 tree class, name, arglist;
7213 tree list = NULL_TREE, all_list = NULL_TREE;
7215 /* Search interfaces */
7216 if (CLASS_INTERFACE (TYPE_NAME (class)))
7218 static tree searched_interfaces = NULL_TREE;
7219 static int search_not_done = 0;
7221 tree basetype_vec = TYPE_BINFO_BASETYPES (class);
7223 /* Have we searched this interface already? */
7224 if (searched_interfaces)
7227 for (current = searched_interfaces;
7228 current; current = TREE_CHAIN (current))
7229 if (TREE_VALUE (current) == class)
7232 searched_interfaces = tree_cons (NULL_TREE, class, searched_interfaces);
7234 search_applicable_methods_list
7235 (lc, TYPE_METHODS (class), name, arglist, &list, &all_list);
7237 n = TREE_VEC_LENGTH (basetype_vec);
7238 for (i = 0; i < n; i++)
7240 tree t = BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i));
7243 /* Skip java.lang.Object (we'll search it once later.) */
7244 if (t == object_type_node)
7248 rlist = find_applicable_accessible_methods_list (lc, t, name,
7250 all_list = chainon (rlist, (list ? list : all_list));
7254 /* We're done. Reset the searched interfaces list and finally search
7256 if (!search_not_done)
7258 searched_interfaces = NULL_TREE;
7259 search_applicable_methods_list (lc, TYPE_METHODS (object_type_node),
7260 name, arglist, &list, &all_list);
7263 /* Search classes */
7265 while (class != NULL_TREE)
7267 search_applicable_methods_list
7268 (lc, TYPE_METHODS (class), name, arglist, &list, &all_list);
7269 class = (lc ? NULL_TREE : CLASSTYPE_SUPER (class));
7272 /* Either return the list obtained or all selected (but
7273 inaccessible) methods for better error report. */
7274 return (!list ? all_list : list);
7277 /* Effectively search for the approriate method in method */
7280 search_applicable_methods_list(lc, method, name, arglist, list, all_list)
7282 tree method, name, arglist;
7283 tree *list, *all_list;
7285 for (; method; method = TREE_CHAIN (method))
7287 /* When dealing with constructor, stop here, otherwise search
7289 if (lc && !DECL_CONSTRUCTOR_P (method))
7291 else if (!lc && (DECL_CONSTRUCTOR_P (method)
7292 || (GET_METHOD_NAME (method) != name)))
7295 if (argument_types_convertible (method, arglist))
7297 /* Retain accessible methods only */
7298 if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
7300 *list = tree_cons (NULL_TREE, method, *list);
7302 /* Also retain all selected method here */
7303 *all_list = tree_cons (NULL_TREE, method, *list);
7308 /* 15.11.2.2 Choose the Most Specific Method */
7311 find_most_specific_methods_list (list)
7315 tree current, new_list = NULL_TREE;
7316 for (current = list; current; current = TREE_CHAIN (current))
7319 DECL_SPECIFIC_COUNT (TREE_VALUE (current)) = 0;
7321 for (method = list; method; method = TREE_CHAIN (method))
7323 /* Don't test a method against itself */
7324 if (method == current)
7327 /* Compare arguments and location where method where declared */
7328 if (argument_types_convertible (TREE_VALUE (method),
7329 TREE_VALUE (current))
7330 && valid_method_invocation_conversion_p
7331 (DECL_CONTEXT (TREE_VALUE (method)),
7332 DECL_CONTEXT (TREE_VALUE (current))))
7334 int v = ++DECL_SPECIFIC_COUNT (TREE_VALUE (current));
7335 max = (v > max ? v : max);
7340 /* Review the list and select the maximally specific methods */
7341 for (current = list; current; current = TREE_CHAIN (current))
7342 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
7343 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
7345 /* If we can't find one, lower expectations and try to gather multiple
7346 maximally specific methods */
7351 if (DECL_SPECIFIC_COUNT (TREE_VALUE (current)) == max)
7352 new_list = tree_cons (NULL_TREE, TREE_VALUE (current), new_list);
7360 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
7361 converted by method invocation conversion (5.3) to the type of the
7362 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
7363 to change less often than M1. */
7366 argument_types_convertible (m1, m2_or_arglist)
7367 tree m1, m2_or_arglist;
7369 static tree m2_arg_value = NULL_TREE;
7370 static tree m2_arg_cache = NULL_TREE;
7372 register tree m1_arg, m2_arg;
7374 m1_arg = TYPE_ARG_TYPES (TREE_TYPE (m1));
7375 if (!METHOD_STATIC (m1))
7376 m1_arg = TREE_CHAIN (m1_arg);
7378 if (m2_arg_value == m2_or_arglist)
7379 m2_arg = m2_arg_cache;
7382 /* M2_OR_ARGLIST can be a function DECL or a raw list of
7384 if (m2_or_arglist && TREE_CODE (m2_or_arglist) == FUNCTION_DECL)
7386 m2_arg = TYPE_ARG_TYPES (TREE_TYPE (m2_or_arglist));
7387 if (!METHOD_STATIC (m2_or_arglist))
7388 m2_arg = TREE_CHAIN (m2_arg);
7391 m2_arg = m2_or_arglist;
7393 m2_arg_value = m2_or_arglist;
7394 m2_arg_cache = m2_arg;
7397 while (m1_arg != end_params_node && m2_arg != end_params_node)
7399 resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
7400 if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
7401 TREE_VALUE (m2_arg)))
7403 m1_arg = TREE_CHAIN (m1_arg);
7404 m2_arg = TREE_CHAIN (m2_arg);
7406 return m1_arg == end_params_node && m2_arg == end_params_node;
7409 /* Qualification routines */
7412 qualify_ambiguous_name (id)
7415 tree qual, qual_wfl, name, decl, ptr_type, saved_current_class;
7416 int again, super_found = 0, this_found = 0, new_array_found = 0;
7418 /* We first qualify the first element, then derive qualification of
7419 others based on the first one. If the first element is qualified
7420 by a resolution (field or type), this resolution is stored in the
7421 QUAL_RESOLUTION of the qual element being examined. We need to
7422 save the current_class since the use of SUPER might change the
7424 saved_current_class = current_class;
7425 qual = EXPR_WFL_QUALIFICATION (id);
7428 /* Simple qualified expression feature a qual_wfl that is a
7429 WFL. Expression derived from a primary feature more complicated
7430 things like a CALL_EXPR. Expression from primary need to be
7431 worked out to extract the part on which the qualification will
7433 qual_wfl = QUAL_WFL (qual);
7434 switch (TREE_CODE (qual_wfl))
7437 qual_wfl = TREE_OPERAND (qual_wfl, 0);
7438 if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
7440 qual = EXPR_WFL_QUALIFICATION (qual_wfl);
7441 qual_wfl = QUAL_WFL (qual);
7444 case NEW_ARRAY_EXPR:
7445 qual = TREE_CHAIN (qual);
7446 new_array_found = again = 1;
7448 case NEW_CLASS_EXPR:
7450 qual_wfl = TREE_OPERAND (qual_wfl, 0);
7453 while (TREE_CODE (qual_wfl) == ARRAY_REF)
7454 qual_wfl = TREE_OPERAND (qual_wfl, 0);
7457 /* Fix for -Wall. Just break doing nothing */
7460 name = EXPR_WFL_NODE (qual_wfl);
7461 ptr_type = current_class;
7463 /* If we have a THIS (from a primary), we set the context accordingly */
7464 if (name == this_identifier_node)
7466 qual = TREE_CHAIN (qual);
7467 qual_wfl = QUAL_WFL (qual);
7468 if (TREE_CODE (qual_wfl) == CALL_EXPR)
7471 name = EXPR_WFL_NODE (qual_wfl);
7474 /* If we have a SUPER, we set the context accordingly */
7475 if (name == super_identifier_node)
7477 current_class = CLASSTYPE_SUPER (ptr_type);
7478 /* Check that there is such a thing as a super class. If not,
7479 return. The error will be caught later on, during the
7483 current_class = saved_current_class;
7486 qual = TREE_CHAIN (qual);
7487 /* Do one more interation to set things up */
7488 super_found = again = 1;
7490 /* Loop one more time if we're dealing with ?: or a string
7491 constant, or a convert expression */
7492 if (TREE_CODE (qual_wfl) == CONDITIONAL_EXPR
7493 || TREE_CODE (qual_wfl) == STRING_CST
7494 || TREE_CODE (qual_wfl) == CONVERT_EXPR)
7496 qual = TREE_CHAIN (qual);
7497 qual_wfl = QUAL_WFL (qual);
7502 /* If name appears within the scope of a location variable
7503 declaration or parameter declaration, then it is an expression
7504 name. We don't carry this test out if we're in the context of the
7505 use of SUPER or THIS */
7506 if (!this_found && !super_found && (decl = IDENTIFIER_LOCAL_VALUE (name)))
7508 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
7509 QUAL_RESOLUTION (qual) = decl;
7512 /* If within the class/interface NAME was found to be used there
7513 exists a (possibly inherited) field named NAME, then this is an
7514 expression name. If we saw a NEW_ARRAY_EXPR before and want to
7515 address length, it is OK. */
7516 else if ((decl = lookup_field_wrapper (ptr_type, name))
7517 || (new_array_found && name == length_identifier_node))
7519 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
7520 QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
7523 /* We reclassify NAME as a type name if:
7524 - NAME is a class/interface declared within the compilation
7525 unit containing NAME,
7526 - NAME is imported via a single-type-import declaration,
7527 - NAME is declared in an another compilation unit of the package
7528 of the compilation unit containing NAME,
7529 - NAME is declared by exactly on type-import-on-demand declaration
7530 of the compilation unit containing NAME. */
7531 else if ((decl = resolve_and_layout (name, NULL_TREE)))
7533 RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
7534 QUAL_RESOLUTION (qual) = decl;
7537 /* Method call are expression name */
7538 else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR
7539 || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF)
7540 RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
7542 /* Check here that NAME isn't declared by more than one
7543 type-import-on-demand declaration of the compilation unit
7544 containing NAME. FIXME */
7546 /* Otherwise, NAME is reclassified as a package name */
7548 RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
7550 /* Propagate the qualification accross other components of the
7552 for (qual = TREE_CHAIN (qual); qual;
7553 qual_wfl = QUAL_WFL (qual), qual = TREE_CHAIN (qual))
7555 if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
7556 RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
7558 RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (qual)) = 1;
7561 /* Store the global qualification for the ambiguous part of ID back
7563 if (RESOLVE_EXPRESSION_NAME_P (qual_wfl))
7564 RESOLVE_EXPRESSION_NAME_P (id) = 1;
7565 else if (RESOLVE_TYPE_NAME_P (qual_wfl))
7566 RESOLVE_TYPE_NAME_P (id) = 1;
7567 else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
7568 RESOLVE_PACKAGE_NAME_P (id) = 1;
7570 /* Restore the current class */
7571 current_class = saved_current_class;
7575 breakdown_qualified (left, right, source)
7576 tree *left, *right, source;
7578 char *p = IDENTIFIER_POINTER (source), *base;
7579 int l = IDENTIFIER_LENGTH (source);
7581 /* Breakdown NAME into REMAINDER . IDENTIFIER */
7584 while (*p != '.' && p != base)
7587 /* We didn't find a '.'. Return an error */
7593 *right = get_identifier (p+1);
7594 *left = get_identifier (IDENTIFIER_POINTER (source));
7600 /* Patch tree nodes in a function body. When a BLOCK is found, push
7601 local variable decls if present.
7602 Same as java_complete_lhs, but does resolve static finals to values. */
7605 java_complete_tree (node)
7608 node = java_complete_lhs (node);
7609 if (TREE_CODE (node) == VAR_DECL && FIELD_STATIC (node)
7610 && FIELD_FINAL (node) && DECL_INITIAL (node) != NULL_TREE)
7612 tree value = DECL_INITIAL (node);
7613 DECL_INITIAL (node) = NULL_TREE;
7614 value = fold_constant_for_init (value, node);
7615 DECL_INITIAL (node) = value;
7616 if (value != NULL_TREE)
7623 java_stabilize_reference (node)
7626 if (TREE_CODE (node) == COMPOUND_EXPR)
7628 tree op0 = TREE_OPERAND (node, 0);
7629 tree op1 = TREE_OPERAND (node, 1);
7630 TREE_OPERAND (node, 0) = save_expr (op0);
7631 TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
7635 return stabilize_reference (node);
7638 /* Patch tree nodes in a function body. When a BLOCK is found, push
7639 local variable decls if present.
7640 Same as java_complete_tree, but does not resolve static finals to values. */
7643 java_complete_lhs (node)
7646 tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
7649 /* CONVERT_EXPR always has its type set, even though it needs to be
7651 if (TREE_TYPE (node) && TREE_CODE (node) != CONVERT_EXPR)
7654 /* The switch block implements cases processing container nodes
7655 first. Contained nodes are always written back. Leaves come
7656 next and return a value. */
7657 switch (TREE_CODE (node))
7661 /* 1- Block section.
7662 Set the local values on decl names so we can identify them
7663 faster when they're referenced. At that stage, identifiers
7664 are legal so we don't check for declaration errors. */
7665 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
7667 DECL_CONTEXT (cn) = current_function_decl;
7668 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
7670 if (BLOCK_EXPR_BODY (node) == NULL_TREE)
7671 CAN_COMPLETE_NORMALLY (node) = 1;
7674 tree stmt = BLOCK_EXPR_BODY (node);
7677 if (TREE_CODE (stmt) == COMPOUND_EXPR)
7679 /* Re-order from (((A; B); C); ...; Z) to
7680 (A; (B; (C ; (...; Z)))).
7681 This makes it easier to scan the statements left-to-right
7682 without using recursion (which might overflow the stack
7683 if the block has many statements. */
7686 tree left = TREE_OPERAND (stmt, 0);
7687 if (TREE_CODE (left) != COMPOUND_EXPR)
7689 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
7690 TREE_OPERAND (left, 1) = stmt;
7693 BLOCK_EXPR_BODY (node) = stmt;
7696 /* Now do the actual complete, without deep recursion for
7698 ptr = &BLOCK_EXPR_BODY (node);
7699 while (TREE_CODE (*ptr) == COMPOUND_EXPR
7700 && TREE_OPERAND (*ptr, 1) != empty_stmt_node)
7702 tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
7703 tree *next = &TREE_OPERAND (*ptr, 1);
7704 TREE_OPERAND (*ptr, 0) = cur;
7705 if (TREE_CODE (cur) == ERROR_MARK)
7707 else if (! CAN_COMPLETE_NORMALLY (cur))
7712 if (TREE_CODE (wfl_op2) == BLOCK)
7713 wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
7714 else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
7715 wfl_op2 = TREE_OPERAND (wfl_op2, 0);
7719 if (TREE_CODE (wfl_op2) != CASE_EXPR
7720 && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
7721 unreachable_stmt_error (*ptr);
7725 *ptr = java_complete_tree (*ptr);
7727 if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
7728 return error_mark_node;
7729 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
7731 /* Turn local bindings to null */
7732 for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
7733 IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = NULL_TREE;
7735 TREE_TYPE (node) = void_type_node;
7738 /* 2- They are expressions but ultimately deal with statements */
7741 wfl_op1 = TREE_OPERAND (node, 0);
7742 COMPLETE_CHECK_OP_0 (node);
7743 /* CAN_COMPLETE_NORMALLY (node) = 0; */
7744 return patch_throw_statement (node, wfl_op1);
7746 case SYNCHRONIZED_EXPR:
7747 wfl_op1 = TREE_OPERAND (node, 0);
7748 return patch_synchronized_statement (node, wfl_op1);
7751 return patch_try_statement (node);
7753 case TRY_FINALLY_EXPR:
7754 COMPLETE_CHECK_OP_0 (node);
7755 COMPLETE_CHECK_OP_1 (node);
7756 CAN_COMPLETE_NORMALLY (node)
7757 = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
7758 && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
7759 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
7762 case CLEANUP_POINT_EXPR:
7763 COMPLETE_CHECK_OP_0 (node);
7764 TREE_TYPE (node) = void_type_node;
7765 CAN_COMPLETE_NORMALLY (node) =
7766 CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
7769 case WITH_CLEANUP_EXPR:
7770 COMPLETE_CHECK_OP_0 (node);
7771 COMPLETE_CHECK_OP_2 (node);
7772 CAN_COMPLETE_NORMALLY (node) =
7773 CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
7774 TREE_TYPE (node) = void_type_node;
7777 case LABELED_BLOCK_EXPR:
7778 PUSH_LABELED_BLOCK (node);
7779 if (LABELED_BLOCK_BODY (node))
7780 COMPLETE_CHECK_OP_1 (node);
7781 TREE_TYPE (node) = void_type_node;
7782 POP_LABELED_BLOCK ();
7783 if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
7784 CAN_COMPLETE_NORMALLY (node) = 1;
7787 case EXIT_BLOCK_EXPR:
7788 /* We don't complete operand 1, because it's the return value of
7789 the EXIT_BLOCK_EXPR which doesn't exist it Java */
7790 return patch_bc_statement (node);
7793 cn = java_complete_tree (TREE_OPERAND (node, 0));
7794 if (cn == error_mark_node)
7797 /* First, the case expression must be constant */
7800 if (!TREE_CONSTANT (cn))
7802 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
7803 parse_error_context (node, "Constant expression required");
7804 return error_mark_node;
7807 nn = ctxp->current_loop;
7809 /* It must be assignable to the type of the switch expression. */
7810 if (!try_builtin_assignconv (NULL_TREE,
7811 TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
7813 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
7816 "Incompatible type for case. Can't convert `%s' to `int'",
7817 lang_printable_name (TREE_TYPE (cn), 0));
7818 return error_mark_node;
7821 cn = fold (convert (int_type_node, cn));
7823 /* Multiple instance of a case label bearing the same
7824 value is checked during code generation. The case
7825 expression is allright so far. */
7826 TREE_OPERAND (node, 0) = cn;
7827 TREE_TYPE (node) = void_type_node;
7828 CAN_COMPLETE_NORMALLY (node) = 1;
7829 TREE_SIDE_EFFECTS (node) = 1;
7833 nn = ctxp->current_loop;
7834 /* Only one default label is allowed per switch statement */
7835 if (SWITCH_HAS_DEFAULT (nn))
7837 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
7838 parse_error_context (wfl_operator,
7839 "Duplicate case label: `default'");
7840 return error_mark_node;
7843 SWITCH_HAS_DEFAULT (nn) = 1;
7844 TREE_TYPE (node) = void_type_node;
7845 TREE_SIDE_EFFECTS (node) = 1;
7846 CAN_COMPLETE_NORMALLY (node) = 1;
7852 /* Check whether the loop was enclosed in a labeled
7853 statement. If not, create one, insert the loop in it and
7855 nn = patch_loop_statement (node);
7857 /* Anyways, walk the body of the loop */
7858 if (TREE_CODE (node) == LOOP_EXPR)
7859 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
7860 /* Switch statement: walk the switch expression and the cases */
7862 node = patch_switch_statement (node);
7864 if (TREE_OPERAND (node, 0) == error_mark_node)
7865 nn = error_mark_node;
7868 TREE_TYPE (nn) = TREE_TYPE (node) = void_type_node;
7869 /* If we returned something different, that's because we
7870 inserted a label. Pop the label too. */
7873 if (CAN_COMPLETE_NORMALLY (node))
7874 CAN_COMPLETE_NORMALLY (nn) = 1;
7875 POP_LABELED_BLOCK ();
7882 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
7883 return patch_exit_expr (node);
7887 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
7888 if (TREE_OPERAND (node, 0) == error_mark_node)
7889 return error_mark_node;
7890 /* then-else branches */
7891 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
7892 if (TREE_OPERAND (node, 1) == error_mark_node)
7893 return error_mark_node;
7894 TREE_OPERAND (node, 2) = java_complete_tree (TREE_OPERAND (node, 2));
7895 if (TREE_OPERAND (node, 2) == error_mark_node)
7896 return error_mark_node;
7897 return patch_if_else_statement (node);
7900 case CONDITIONAL_EXPR:
7902 wfl_op1 = TREE_OPERAND (node, 0);
7903 COMPLETE_CHECK_OP_0 (node);
7904 wfl_op2 = TREE_OPERAND (node, 1);
7905 COMPLETE_CHECK_OP_1 (node);
7906 wfl_op3 = TREE_OPERAND (node, 2);
7907 COMPLETE_CHECK_OP_2 (node);
7908 return patch_conditional_expr (node, wfl_op1, wfl_op2);
7910 /* 3- Expression section */
7912 wfl_op2 = TREE_OPERAND (node, 1);
7913 TREE_OPERAND (node, 0) = nn =
7914 java_complete_tree (TREE_OPERAND (node, 0));
7915 if (wfl_op2 == empty_stmt_node)
7916 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
7919 if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
7921 /* An unreachable condition in a do-while statement
7922 is *not* (technically) an unreachable statement. */
7924 if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
7925 nn = EXPR_WFL_NODE (nn);
7926 if (TREE_CODE (nn) != EXIT_EXPR)
7928 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
7929 parse_error_context (wfl_operator, "Unreachable statement");
7932 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
7933 if (TREE_OPERAND (node, 1) == error_mark_node)
7934 return error_mark_node;
7935 CAN_COMPLETE_NORMALLY (node)
7936 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1));
7938 TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
7942 /* CAN_COMPLETE_NORMALLY (node) = 0; */
7943 return patch_return (node);
7945 case EXPR_WITH_FILE_LOCATION:
7946 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
7947 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
7950 node = resolve_expression_name (node, NULL);
7951 if (node == error_mark_node)
7953 /* Keep line number information somewhere were it doesn't
7954 disrupt the completion process. */
7957 EXPR_WFL_NODE (wfl) = TREE_OPERAND (node, 1);
7958 TREE_OPERAND (node, 1) = wfl;
7960 CAN_COMPLETE_NORMALLY (node) = 1;
7965 int save_lineno = lineno;
7966 lineno = EXPR_WFL_LINENO (node);
7967 body = java_complete_tree (EXPR_WFL_NODE (node));
7968 lineno = save_lineno;
7969 EXPR_WFL_NODE (node) = body;
7970 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
7971 CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
7972 if (body == error_mark_node)
7974 /* Its important for the evaluation of assignment that
7975 this mark on the TREE_TYPE is propagated. */
7976 TREE_TYPE (node) = error_mark_node;
7977 return error_mark_node;
7980 TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
7985 case NEW_ARRAY_EXPR:
7986 /* Patch all the dimensions */
7988 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
7990 int location = EXPR_WFL_LINECOL (TREE_VALUE (cn));
7991 tree dim = java_complete_tree (TREE_VALUE (cn));
7992 if (dim == error_mark_node)
7999 TREE_VALUE (cn) = dim;
8000 /* Setup the location of the current dimension, for
8001 later error report. */
8003 build_expr_wfl (NULL_TREE, input_filename, 0, 0);
8004 EXPR_WFL_LINECOL (TREE_PURPOSE (cn)) = location;
8007 /* They complete the array creation expression, if no errors
8009 CAN_COMPLETE_NORMALLY (node) = 1;
8010 return (flag ? error_mark_node
8011 : force_evaluation_order (patch_newarray (node)));
8013 case NEW_CLASS_EXPR:
8015 /* Complete function's argument(s) first */
8016 if (complete_function_arguments (node))
8017 return error_mark_node;
8020 tree decl, wfl = TREE_OPERAND (node, 0);
8021 int in_this = CALL_THIS_CONSTRUCTOR_P (node);
8023 node = patch_method_invocation (node, NULL_TREE,
8024 NULL_TREE, 0, &decl);
8025 if (node == error_mark_node)
8026 return error_mark_node;
8028 check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
8029 /* If we call this(...), register signature and positions */
8031 DECL_CONSTRUCTOR_CALLS (current_function_decl) =
8032 tree_cons (wfl, decl,
8033 DECL_CONSTRUCTOR_CALLS (current_function_decl));
8034 CAN_COMPLETE_NORMALLY (node) = 1;
8035 return force_evaluation_order (node);
8039 /* Save potential wfls */
8040 wfl_op1 = TREE_OPERAND (node, 0);
8041 wfl_op2 = TREE_OPERAND (node, 1);
8042 TREE_OPERAND (node, 0) = java_complete_lhs (wfl_op1);
8043 if (TREE_OPERAND (node, 0) == error_mark_node)
8044 return error_mark_node;
8046 if (COMPOUND_ASSIGN_P (wfl_op2))
8048 tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0));
8050 /* Hand stablize the lhs on both places */
8051 TREE_OPERAND (node, 0) = lvalue;
8052 TREE_OPERAND (TREE_OPERAND (node, 1), 0) = lvalue;
8054 /* Now complete the RHS. We write it back later on. */
8055 nn = java_complete_tree (TREE_OPERAND (node, 1));
8057 if ((cn = patch_string (nn)))
8060 /* The last part of the rewrite for E1 op= E2 is to have
8061 E1 = (T)(E1 op E2), with T being the type of E1. */
8062 nn = java_complete_tree (build_cast (EXPR_WFL_LINECOL (wfl_op2),
8063 TREE_TYPE (lvalue), nn));
8066 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
8067 function to complete this RHS */
8068 else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT)
8069 nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
8070 TREE_OPERAND (node, 1));
8071 /* Otherwise we simply complete the RHS */
8073 nn = java_complete_tree (TREE_OPERAND (node, 1));
8075 if (nn == error_mark_node)
8076 return error_mark_node;
8078 /* Write back the RHS as we evaluated it. */
8079 TREE_OPERAND (node, 1) = nn;
8081 /* In case we're handling = with a String as a RHS, we need to
8082 produce a String out of the RHS (it might still be a
8083 STRING_CST or a StringBuffer at this stage */
8084 if ((nn = patch_string (TREE_OPERAND (node, 1))))
8085 TREE_OPERAND (node, 1) = nn;
8086 node = patch_assignment (node, wfl_op1, wfl_op2);
8087 CAN_COMPLETE_NORMALLY (node) = 1;
8089 /* Before returning the node, in the context of a static field
8090 assignment in <clinit>, we may want to carray further
8091 optimizations. (VAR_DECL means it's a static field. See
8093 if (IS_CLINIT (current_function_decl)
8094 && MODIFY_EXPR_FROM_INITIALIZATION_P (node)
8095 && TREE_CODE (TREE_OPERAND (node, 0)) == VAR_DECL)
8096 node = patch_initialized_static_field (node);
8109 case TRUNC_MOD_EXPR:
8111 case TRUTH_ANDIF_EXPR:
8112 case TRUTH_ORIF_EXPR:
8119 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
8120 knows how to handle those cases. */
8121 wfl_op1 = TREE_OPERAND (node, 0);
8122 wfl_op2 = TREE_OPERAND (node, 1);
8124 CAN_COMPLETE_NORMALLY (node) = 1;
8125 /* Don't complete string nodes if dealing with the PLUS operand. */
8126 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
8128 nn = java_complete_tree (wfl_op1);
8129 if (nn == error_mark_node)
8130 return error_mark_node;
8131 if ((cn = patch_string (nn)))
8133 TREE_OPERAND (node, 0) = nn;
8135 if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
8137 nn = java_complete_tree (wfl_op2);
8138 if (nn == error_mark_node)
8139 return error_mark_node;
8140 if ((cn = patch_string (nn)))
8142 TREE_OPERAND (node, 1) = nn;
8144 return force_evaluation_order (patch_binop (node, wfl_op1, wfl_op2));
8146 case INSTANCEOF_EXPR:
8147 wfl_op1 = TREE_OPERAND (node, 0);
8148 COMPLETE_CHECK_OP_0 (node);
8149 return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
8151 case UNARY_PLUS_EXPR:
8153 case TRUTH_NOT_EXPR:
8155 case PREDECREMENT_EXPR:
8156 case PREINCREMENT_EXPR:
8157 case POSTDECREMENT_EXPR:
8158 case POSTINCREMENT_EXPR:
8160 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
8161 how to handle those cases. */
8162 wfl_op1 = TREE_OPERAND (node, 0);
8163 CAN_COMPLETE_NORMALLY (node) = 1;
8164 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
8165 if (TREE_OPERAND (node, 0) == error_mark_node)
8166 return error_mark_node;
8167 node = patch_unaryop (node, wfl_op1);
8168 CAN_COMPLETE_NORMALLY (node) = 1;
8172 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
8173 how to handle those cases. */
8174 wfl_op1 = TREE_OPERAND (node, 0);
8175 TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
8176 if (TREE_OPERAND (node, 0) == error_mark_node)
8177 return error_mark_node;
8178 if (!flag_emit_class_files && !flag_emit_xref)
8179 TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
8180 /* The same applies to wfl_op2 */
8181 wfl_op2 = TREE_OPERAND (node, 1);
8182 TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
8183 if (TREE_OPERAND (node, 1) == error_mark_node)
8184 return error_mark_node;
8185 if (!flag_emit_class_files && !flag_emit_xref)
8186 TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
8187 return patch_array_ref (node);
8193 /* The first step in the re-write of qualified name handling. FIXME.
8194 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
8195 TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
8196 if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
8198 tree name = TREE_OPERAND (node, 1);
8199 tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
8200 if (field == NULL_TREE)
8202 error ("missing static field `%s'", IDENTIFIER_POINTER (name));
8203 return error_mark_node;
8205 if (! FIELD_STATIC (field))
8207 error ("not a static field `%s'", IDENTIFIER_POINTER (name));
8208 return error_mark_node;
8213 fatal ("unimplemented java_complete_tree for COMPONENT_REF");
8217 /* Can't use THIS in a static environment */
8220 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8221 parse_error_context (wfl_operator, "Keyword `this' used outside "
8223 TREE_TYPE (node) = error_mark_node;
8224 return error_mark_node;
8226 if (ctxp->explicit_constructor_p)
8228 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8230 (wfl_operator, "Can't reference `this' or `super' before the "
8231 "superclass constructor has been called");
8232 TREE_TYPE (node) = error_mark_node;
8233 return error_mark_node;
8235 return current_this;
8238 CAN_COMPLETE_NORMALLY (node) = 1;
8239 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
8240 and it's time to turn it into the appropriate String object
8242 if ((node = patch_string (node)))
8244 fatal ("No case for tree code `%s' - java_complete_tree\n",
8245 tree_code_name [TREE_CODE (node)]);
8250 /* Complete function call's argument. Return a non zero value is an
8254 complete_function_arguments (node)
8260 ctxp->explicit_constructor_p += (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
8261 for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
8263 tree wfl = TREE_VALUE (cn), parm, temp;
8264 parm = java_complete_tree (wfl);
8265 if (parm == error_mark_node)
8270 /* If have a string literal that we haven't transformed yet or a
8271 crafted string buffer, as a result of use of the the String
8272 `+' operator. Build `parm.toString()' and expand it. */
8273 if ((temp = patch_string (parm)))
8275 /* Inline PRIMTYPE.TYPE read access */
8276 parm = maybe_build_primttype_type_ref (parm, wfl);
8278 TREE_VALUE (cn) = parm;
8280 ctxp->explicit_constructor_p -= (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
8284 /* Sometimes (for loops and variable initialized during their
8285 declaration), we want to wrap a statement around a WFL and turn it
8289 build_debugable_stmt (location, stmt)
8293 if (TREE_CODE (stmt) != EXPR_WITH_FILE_LOCATION)
8295 stmt = build_expr_wfl (stmt, input_filename, 0, 0);
8296 EXPR_WFL_LINECOL (stmt) = location;
8298 JAVA_MAYBE_GENERATE_DEBUG_INFO (stmt);
8303 build_expr_block (body, decls)
8306 tree node = make_node (BLOCK);
8307 BLOCK_EXPR_DECLS (node) = decls;
8308 BLOCK_EXPR_BODY (node) = body;
8310 TREE_TYPE (node) = TREE_TYPE (body);
8311 TREE_SIDE_EFFECTS (node) = 1;
8315 /* Create a new function block and link it approriately to current
8316 function block chain */
8321 return (enter_a_block (build_expr_block (NULL_TREE, NULL_TREE)));
8324 /* Link block B supercontext to the previous block. The current
8325 function DECL is used as supercontext when enter_a_block is called
8326 for the first time for a given function. The current function body
8327 (DECL_FUNCTION_BODY) is set to be block B. */
8333 tree fndecl = current_function_decl;
8336 BLOCK_SUPERCONTEXT (b) = current_static_block;
8337 current_static_block = b;
8340 else if (!DECL_FUNCTION_BODY (fndecl))
8342 BLOCK_SUPERCONTEXT (b) = fndecl;
8343 DECL_FUNCTION_BODY (fndecl) = b;
8347 BLOCK_SUPERCONTEXT (b) = DECL_FUNCTION_BODY (fndecl);
8348 DECL_FUNCTION_BODY (fndecl) = b;
8353 /* Exit a block by changing the current function body
8354 (DECL_FUNCTION_BODY) to the current block super context, only if
8355 the block being exited isn't the method's top level one. */
8361 if (current_function_decl)
8363 b = DECL_FUNCTION_BODY (current_function_decl);
8364 if (BLOCK_SUPERCONTEXT (b) != current_function_decl)
8365 DECL_FUNCTION_BODY (current_function_decl) = BLOCK_SUPERCONTEXT (b);
8369 b = current_static_block;
8371 if (BLOCK_SUPERCONTEXT (b))
8372 current_static_block = BLOCK_SUPERCONTEXT (b);
8377 /* Lookup for NAME in the nested function's blocks, all the way up to
8378 the current toplevel one. It complies with Java's local variable
8382 lookup_name_in_blocks (name)
8385 tree b = GET_CURRENT_BLOCK (current_function_decl);
8387 while (b != current_function_decl)
8391 /* Paranoid sanity check. To be removed */
8392 if (TREE_CODE (b) != BLOCK)
8393 fatal ("non block expr function body - lookup_name_in_blocks");
8395 for (current = BLOCK_EXPR_DECLS (b); current;
8396 current = TREE_CHAIN (current))
8397 if (DECL_NAME (current) == name)
8399 b = BLOCK_SUPERCONTEXT (b);
8405 maybe_absorb_scoping_blocks ()
8407 while (BLOCK_EXPR_ORIGIN (GET_CURRENT_BLOCK (current_function_decl)))
8409 tree b = exit_block ();
8410 java_method_add_stmt (current_function_decl, b);
8411 SOURCE_FRONTEND_DEBUG (("Absorbing scoping block at line %d", lineno));
8416 /* This section of the source is reserved to build_* functions that
8417 are building incomplete tree nodes and the patch_* functions that
8418 are completing them. */
8420 /* Build a super() constructor invocation. Returns empty_stmt_node if
8421 we're currently dealing with the class java.lang.Object. */
8424 build_super_invocation ()
8426 if (current_class == object_type_node)
8427 return empty_stmt_node;
8430 tree super_wfl = build_wfl_node (super_identifier_node);
8431 return build_method_invocation (super_wfl, NULL_TREE);
8435 /* Build a SUPER/THIS qualified method invocation. */
8438 build_this_super_qualified_invocation (use_this, name, args, lloc, rloc)
8446 build_wfl_node (use_this ? this_identifier_node : super_identifier_node);
8447 EXPR_WFL_LINECOL (wfl) = lloc;
8448 invok = build_method_invocation (name, args);
8449 return make_qualified_primary (wfl, invok, rloc);
8452 /* Build an incomplete CALL_EXPR node. */
8455 build_method_invocation (name, args)
8459 tree call = build (CALL_EXPR, NULL_TREE, name, args, NULL_TREE);
8460 TREE_SIDE_EFFECTS (call) = 1;
8461 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
8465 /* Build an incomplete new xxx(...) node. */
8468 build_new_invocation (name, args)
8471 tree call = build (NEW_CLASS_EXPR, NULL_TREE, name, args, NULL_TREE);
8472 TREE_SIDE_EFFECTS (call) = 1;
8473 EXPR_WFL_LINECOL (call) = EXPR_WFL_LINECOL (name);
8477 /* Build an incomplete assignment expression. */
8480 build_assignment (op, op_location, lhs, rhs)
8481 int op, op_location;
8485 /* Build the corresponding binop if we deal with a Compound
8486 Assignment operator. Mark the binop sub-tree as part of a
8487 Compound Assignment expression */
8488 if (op != ASSIGN_TK)
8490 rhs = build_binop (BINOP_LOOKUP (op), op_location, lhs, rhs);
8491 COMPOUND_ASSIGN_P (rhs) = 1;
8493 assignment = build (MODIFY_EXPR, NULL_TREE, lhs, rhs);
8494 TREE_SIDE_EFFECTS (assignment) = 1;
8495 EXPR_WFL_LINECOL (assignment) = op_location;
8499 /* Print an INTEGER_CST node in a static buffer, and return the buffer. */
8502 print_int_node (node)
8505 static char buffer [80];
8506 if (TREE_CONSTANT_OVERFLOW (node))
8507 sprintf (buffer, "<overflow>");
8509 if (TREE_INT_CST_HIGH (node) == 0)
8510 sprintf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
8511 TREE_INT_CST_LOW (node));
8512 else if (TREE_INT_CST_HIGH (node) == -1
8513 && TREE_INT_CST_LOW (node) != 0)
8516 sprintf (&buffer [1], HOST_WIDE_INT_PRINT_UNSIGNED,
8517 -TREE_INT_CST_LOW (node));
8520 sprintf (buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
8521 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
8526 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
8530 check_final_assignment (lvalue, wfl)
8533 if (JDECL_P (lvalue)
8534 && FIELD_FINAL (lvalue) && !IS_CLINIT (current_function_decl))
8537 (wfl, "Can't assign a value to the final variable `%s'",
8538 IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
8544 /* Inline references to java.lang.PRIMTYPE.TYPE when accessed in
8545 read. This is needed to avoid circularities in the implementation
8546 of these fields in libjava. */
8549 maybe_build_primttype_type_ref (rhs, wfl)
8552 tree to_return = NULL_TREE;
8553 tree rhs_type = TREE_TYPE (rhs);
8554 if (TREE_CODE (rhs) == COMPOUND_EXPR)
8556 tree n = TREE_OPERAND (rhs, 1);
8557 if (TREE_CODE (n) == VAR_DECL
8558 && DECL_NAME (n) == TYPE_identifier_node
8559 && rhs_type == class_ptr_type)
8561 char *self_name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl));
8562 if (!strncmp (self_name, "java.lang.", 10))
8563 to_return = build_primtype_type_ref (self_name);
8566 return (to_return ? to_return : rhs );
8569 /* 15.25 Assignment operators. */
8572 patch_assignment (node, wfl_op1, wfl_op2)
8577 tree rhs = TREE_OPERAND (node, 1);
8578 tree lvalue = TREE_OPERAND (node, 0), llvalue;
8579 tree lhs_type, rhs_type, new_rhs = NULL_TREE;
8580 int error_found = 0;
8581 int lvalue_from_array = 0;
8583 /* Can't assign to a final. */
8584 if (check_final_assignment (lvalue, wfl_op1))
8587 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
8589 /* Lhs can be a named variable */
8590 if (JDECL_P (lvalue))
8592 lhs_type = TREE_TYPE (lvalue);
8594 /* Or Lhs can be a array acccess. Should that be lvalue ? FIXME +
8595 comment on reason why */
8596 else if (TREE_CODE (wfl_op1) == ARRAY_REF)
8598 lhs_type = TREE_TYPE (lvalue);
8599 lvalue_from_array = 1;
8601 /* Or a field access */
8602 else if (TREE_CODE (lvalue) == COMPONENT_REF)
8603 lhs_type = TREE_TYPE (lvalue);
8604 /* Or a function return slot */
8605 else if (TREE_CODE (lvalue) == RESULT_DECL)
8606 lhs_type = TREE_TYPE (lvalue);
8607 /* Otherwise, we might want to try to write into an optimized static
8608 final, this is an of a different nature, reported further on. */
8609 else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
8610 && resolve_expression_name (wfl_op1, &llvalue))
8612 if (check_final_assignment (llvalue, wfl_op1))
8614 /* What we should do instead is resetting the all the flags
8615 previously set, exchange lvalue for llvalue and continue. */
8617 return error_mark_node;
8620 lhs_type = TREE_TYPE (lvalue);
8624 parse_error_context (wfl_op1, "Invalid left hand side of assignment");
8628 rhs_type = TREE_TYPE (rhs);
8629 /* 5.1 Try the assignment conversion for builtin type. */
8630 new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
8632 /* 5.2 If it failed, try a reference conversion */
8633 if (!new_rhs && (new_rhs = try_reference_assignconv (lhs_type, rhs)))
8634 lhs_type = promote_type (rhs_type);
8636 /* 15.25.2 If we have a compound assignment, convert RHS into the
8638 else if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
8639 new_rhs = convert (lhs_type, rhs);
8641 /* Explicit cast required. This is an error */
8644 char *t1 = strdup (lang_printable_name (TREE_TYPE (rhs), 0));
8645 char *t2 = strdup (lang_printable_name (lhs_type, 0));
8647 char operation [32]; /* Max size known */
8649 /* If the assignment is part of a declaration, we use the WFL of
8650 the declared variable to point out the error and call it a
8651 declaration problem. If the assignment is a genuine =
8652 operator, we call is a operator `=' problem, otherwise we
8653 call it an assignment problem. In both of these last cases,
8654 we use the WFL of the operator to indicate the error. */
8656 if (MODIFY_EXPR_FROM_INITIALIZATION_P (node))
8659 strcpy (operation, "declaration");
8664 if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
8665 strcpy (operation, "assignment");
8666 else if (TREE_CODE (TREE_OPERAND (node, 0)) == RESULT_DECL)
8667 strcpy (operation, "`return'");
8669 strcpy (operation, "`='");
8673 (wfl, (!valid_cast_to_p (rhs_type, lhs_type) ?
8674 "Incompatible type for %s. Can't convert `%s' to `%s'" :
8675 "Incompatible type for %s. Explicit cast "
8676 "needed to convert `%s' to `%s'"), operation, t1, t2);
8677 free (t1); free (t2);
8681 /* Inline read access to java.lang.PRIMTYPE.TYPE */
8683 new_rhs = maybe_build_primttype_type_ref (new_rhs, wfl_op2);
8686 return error_mark_node;
8688 /* 10.10: Array Store Exception runtime check */
8689 if (!flag_emit_class_files
8691 && lvalue_from_array
8692 && JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type))
8693 && !CLASS_FINAL (TYPE_NAME (GET_SKIP_TYPE (rhs_type))))
8698 /* We need to retrieve the right argument for _Jv_CheckArrayStore */
8699 if (TREE_CODE (lvalue) == COMPOUND_EXPR)
8700 base = TREE_OPERAND (lvalue, 0);
8703 if (flag_bounds_check)
8704 base = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (base, 0), 1), 0);
8706 base = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
8709 /* Build the invocation of _Jv_CheckArrayStore */
8710 check = build (CALL_EXPR, void_type_node,
8711 build_address_of (soft_checkarraystore_node),
8712 tree_cons (NULL_TREE, base,
8713 build_tree_list (NULL_TREE, new_rhs)),
8715 TREE_SIDE_EFFECTS (check) = 1;
8717 /* We have to decide on an insertion point */
8718 if (TREE_CODE (lvalue) == COMPOUND_EXPR)
8721 if (flag_bounds_check)
8723 t = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (lvalue, 1), 0), 0);
8724 TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (lvalue, 1), 0), 0) =
8725 build (COMPOUND_EXPR, void_type_node, t, check);
8728 TREE_OPERAND (lvalue, 1) = build (COMPOUND_EXPR, lhs_type,
8729 check, TREE_OPERAND (lvalue, 1));
8733 /* Make sure the bound check will happen before the store check */
8734 if (flag_bounds_check)
8735 TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0) =
8736 build (COMPOUND_EXPR, void_type_node,
8737 TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0), check);
8739 lvalue = build (COMPOUND_EXPR, lhs_type, check, lvalue);
8743 TREE_OPERAND (node, 0) = lvalue;
8744 TREE_OPERAND (node, 1) = new_rhs;
8745 TREE_TYPE (node) = lhs_type;
8749 /* Optimize static (final) field initialized upon declaration.
8750 - If the field is static final and is assigned to a primitive
8751 constant type, then set its DECL_INITIAL to the value.
8755 patch_initialized_static_field (node)
8758 tree field = TREE_OPERAND (node, 0);
8759 tree value = TREE_OPERAND (node, 1);
8761 if (DECL_INITIAL (field) != NULL_TREE)
8763 tree type = TREE_TYPE (value);
8764 if (FIELD_FINAL (field) && TREE_CONSTANT (value)
8765 && (JPRIMITIVE_TYPE_P (type)
8766 || (flag_emit_class_files
8767 && TREE_CODE (type) == POINTER_TYPE
8768 && TREE_TYPE (type) == string_type_node)))
8770 DECL_INITIAL (field) = value;
8771 return empty_stmt_node;
8773 DECL_INITIAL (field) = NULL_TREE;
8778 /* Check that type SOURCE can be cast into type DEST. If the cast
8779 can't occur at all, return 0 otherwise 1. This function is used to
8780 produce accurate error messages on the reasons why an assignment
8784 try_reference_assignconv (lhs_type, rhs)
8787 tree new_rhs = NULL_TREE;
8788 tree rhs_type = TREE_TYPE (rhs);
8790 if (!JPRIMITIVE_TYPE_P (rhs_type) && JREFERENCE_TYPE_P (lhs_type))
8792 /* `null' may be assigned to any reference type */
8793 if (rhs == null_pointer_node)
8794 new_rhs = null_pointer_node;
8795 /* Try the reference assignment conversion */
8796 else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
8798 /* This is a magic assignment that we process differently */
8799 else if (rhs == soft_exceptioninfo_call_node)
8805 /* Check that RHS can be converted into LHS_TYPE by the assignment
8806 conversion (5.2), for the cases of RHS being a builtin type. Return
8807 NULL_TREE if the conversion fails or if because RHS isn't of a
8808 builtin type. Return a converted RHS if the conversion is possible. */
8811 try_builtin_assignconv (wfl_op1, lhs_type, rhs)
8812 tree wfl_op1, lhs_type, rhs;
8814 tree new_rhs = NULL_TREE;
8815 tree rhs_type = TREE_TYPE (rhs);
8817 /* Zero accepted everywhere */
8818 if (TREE_CODE (rhs) == INTEGER_CST
8819 && TREE_INT_CST_HIGH (rhs) == 0 && TREE_INT_CST_LOW (rhs) == 0
8820 && JPRIMITIVE_TYPE_P (rhs_type))
8821 new_rhs = convert (lhs_type, rhs);
8823 /* 5.1.1 Try Identity Conversion,
8824 5.1.2 Try Widening Primitive Conversion */
8825 else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
8826 new_rhs = convert (lhs_type, rhs);
8828 /* Try a narrowing primitive conversion (5.1.3):
8829 - expression is a constant expression of type int AND
8830 - variable is byte, short or char AND
8831 - The value of the expression is representable in the type of the
8833 else if (rhs_type == int_type_node && TREE_CONSTANT (rhs)
8834 && (lhs_type == byte_type_node || lhs_type == char_type_node
8835 || lhs_type == short_type_node))
8837 if (int_fits_type_p (rhs, lhs_type))
8838 new_rhs = convert (lhs_type, rhs);
8839 else if (wfl_op1) /* Might be called with a NULL */
8840 parse_warning_context
8841 (wfl_op1, "Constant expression `%s' to wide for narrowing "
8842 "primitive conversion to `%s'",
8843 print_int_node (rhs), lang_printable_name (lhs_type, 0));
8844 /* Reported a warning that will turn into an error further
8845 down, so we don't return */
8851 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
8852 conversion (5.1.1) or widening primitve conversion (5.1.2). Return
8853 0 is the conversion test fails. This implements parts the method
8854 invocation convertion (5.3). */
8857 valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type)
8858 tree lhs_type, rhs_type;
8860 /* 5.1.1: This is the identity conversion part. */
8861 if (lhs_type == rhs_type)
8864 /* Reject non primitive types */
8865 if (!JPRIMITIVE_TYPE_P (lhs_type) || !JPRIMITIVE_TYPE_P (rhs_type))
8868 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
8869 than a char can't be converted into a char. Short can't too, but
8870 the < test below takes care of that */
8871 if (lhs_type == char_type_node && rhs_type == byte_type_node)
8874 /* Accept all promoted type here. Note, we can't use <= in the test
8875 below, because we still need to bounce out assignments of short
8876 to char and the likes */
8877 if (lhs_type == int_type_node
8878 && (rhs_type == promoted_byte_type_node
8879 || rhs_type == promoted_short_type_node
8880 || rhs_type == promoted_char_type_node
8881 || rhs_type == promoted_boolean_type_node))
8884 /* From here, an integral is widened if its precision is smaller
8885 than the precision of the LHS or if the LHS is a floating point
8886 type, or the RHS is a float and the RHS a double. */
8887 if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type)
8888 && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
8889 || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
8890 || (rhs_type == float_type_node && lhs_type == double_type_node))
8896 /* Check that something of SOURCE type can be assigned or cast to
8897 something of DEST type at runtime. Return 1 if the operation is
8898 valid, 0 otherwise. If CAST is set to 1, we're treating the case
8899 were SOURCE is cast into DEST, which borrows a lot of the
8900 assignment check. */
8903 valid_ref_assignconv_cast_p (source, dest, cast)
8908 /* SOURCE or DEST might be null if not from a declared entity. */
8909 if (!source || !dest)
8911 if (JNULLP_TYPE_P (source))
8913 if (TREE_CODE (source) == POINTER_TYPE)
8914 source = TREE_TYPE (source);
8915 if (TREE_CODE (dest) == POINTER_TYPE)
8916 dest = TREE_TYPE (dest);
8917 /* Case where SOURCE is a class type */
8918 if (TYPE_CLASS_P (source))
8920 if (TYPE_CLASS_P (dest))
8921 return source == dest || inherits_from_p (source, dest)
8922 || (cast && inherits_from_p (dest, source));
8923 if (TYPE_INTERFACE_P (dest))
8925 /* If doing a cast and SOURCE is final, the operation is
8926 always correct a compile time (because even if SOURCE
8927 does not implement DEST, a subclass of SOURCE might). */
8928 if (cast && !CLASS_FINAL (TYPE_NAME (source)))
8930 /* Otherwise, SOURCE must implement DEST */
8931 return interface_of_p (dest, source);
8933 /* DEST is an array, cast permited if SOURCE is of Object type */
8934 return (cast && source == object_type_node ? 1 : 0);
8936 if (TYPE_INTERFACE_P (source))
8938 if (TYPE_CLASS_P (dest))
8940 /* If not casting, DEST must be the Object type */
8942 return dest == object_type_node;
8943 /* We're doing a cast. The cast is always valid is class
8944 DEST is not final, otherwise, DEST must implement SOURCE */
8945 else if (!CLASS_FINAL (TYPE_NAME (dest)))
8948 return interface_of_p (source, dest);
8950 if (TYPE_INTERFACE_P (dest))
8952 /* If doing a cast, then if SOURCE and DEST contain method
8953 with the same signature but different return type, then
8954 this is a (compile time) error */
8957 tree method_source, method_dest;
8961 for (method_source = TYPE_METHODS (source); method_source;
8962 method_source = TREE_CHAIN (method_source))
8965 build_java_argument_signature (TREE_TYPE (method_source));
8966 source_type = TREE_TYPE (TREE_TYPE (method_source));
8967 source_name = DECL_NAME (method_source);
8968 for (method_dest = TYPE_METHODS (dest);
8969 method_dest; method_dest = TREE_CHAIN (method_dest))
8971 build_java_argument_signature (TREE_TYPE (method_dest))
8972 && source_name == DECL_NAME (method_dest)
8973 && source_type != TREE_TYPE (TREE_TYPE (method_dest)))
8979 return source == dest || interface_of_p (dest, source);
8984 if (TYPE_ARRAY_P (source))
8986 if (TYPE_CLASS_P (dest))
8987 return dest == object_type_node;
8988 /* Can't cast an array to an interface unless the interface is
8989 java.lang.Cloneable */
8990 if (TYPE_INTERFACE_P (dest))
8991 return (DECL_NAME (TYPE_NAME (dest)) == java_lang_cloneable ? 1 : 0);
8994 tree source_element_type = TYPE_ARRAY_ELEMENT (source);
8995 tree dest_element_type = TYPE_ARRAY_ELEMENT (dest);
8997 /* In case of severe errors, they turn out null */
8998 if (!dest_element_type || !source_element_type)
9000 if (source_element_type == dest_element_type)
9002 return valid_ref_assignconv_cast_p (source_element_type,
9003 dest_element_type, cast);
9011 valid_cast_to_p (source, dest)
9015 if (TREE_CODE (source) == POINTER_TYPE)
9016 source = TREE_TYPE (source);
9017 if (TREE_CODE (dest) == POINTER_TYPE)
9018 dest = TREE_TYPE (dest);
9020 if (TREE_CODE (source) == RECORD_TYPE && TREE_CODE (dest) == RECORD_TYPE)
9021 return valid_ref_assignconv_cast_p (source, dest, 1);
9023 else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
9029 /* Method invocation conversion test. Return 1 if type SOURCE can be
9030 converted to type DEST through the methond invocation conversion
9034 do_unary_numeric_promotion (arg)
9037 tree type = TREE_TYPE (arg);
9038 if (TREE_CODE (type) == INTEGER_TYPE ? TYPE_PRECISION (type) < 32
9039 : TREE_CODE (type) == CHAR_TYPE)
9040 arg = convert (int_type_node, arg);
9044 /* Return a non zero value if SOURCE can be converted into DEST using
9045 the method invocation conversion rule (5.3). */
9047 valid_method_invocation_conversion_p (dest, source)
9050 return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
9051 && valid_builtin_assignconv_identity_widening_p (dest, source))
9052 || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
9053 && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
9054 && valid_ref_assignconv_cast_p (source, dest, 0)));
9057 /* Build an incomplete binop expression. */
9060 build_binop (op, op_location, op1, op2)
9065 tree binop = build (op, NULL_TREE, op1, op2);
9066 TREE_SIDE_EFFECTS (binop) = 1;
9067 /* Store the location of the operator, for better error report. The
9068 string of the operator will be rebuild based on the OP value. */
9069 EXPR_WFL_LINECOL (binop) = op_location;
9073 /* Build the string of the operator retained by NODE. If NODE is part
9074 of a compound expression, add an '=' at the end of the string. This
9075 function is called when an error needs to be reported on an
9076 operator. The string is returned as a pointer to a static character
9080 operator_string (node)
9083 #define BUILD_OPERATOR_STRING(S) \
9085 sprintf (buffer, "%s%s", S, (COMPOUND_ASSIGN_P (node) ? "=" : "")); \
9089 static char buffer [10];
9090 switch (TREE_CODE (node))
9092 case MULT_EXPR: BUILD_OPERATOR_STRING ("*");
9093 case RDIV_EXPR: BUILD_OPERATOR_STRING ("/");
9094 case TRUNC_MOD_EXPR: BUILD_OPERATOR_STRING ("%");
9095 case PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
9096 case MINUS_EXPR: BUILD_OPERATOR_STRING ("-");
9097 case LSHIFT_EXPR: BUILD_OPERATOR_STRING ("<<");
9098 case RSHIFT_EXPR: BUILD_OPERATOR_STRING (">>");
9099 case URSHIFT_EXPR: BUILD_OPERATOR_STRING (">>>");
9100 case BIT_AND_EXPR: BUILD_OPERATOR_STRING ("&");
9101 case BIT_XOR_EXPR: BUILD_OPERATOR_STRING ("^");
9102 case BIT_IOR_EXPR: BUILD_OPERATOR_STRING ("|");
9103 case TRUTH_ANDIF_EXPR: BUILD_OPERATOR_STRING ("&&");
9104 case TRUTH_ORIF_EXPR: BUILD_OPERATOR_STRING ("||");
9105 case EQ_EXPR: BUILD_OPERATOR_STRING ("==");
9106 case NE_EXPR: BUILD_OPERATOR_STRING ("!=");
9107 case GT_EXPR: BUILD_OPERATOR_STRING (">");
9108 case GE_EXPR: BUILD_OPERATOR_STRING (">=");
9109 case LT_EXPR: BUILD_OPERATOR_STRING ("<");
9110 case LE_EXPR: BUILD_OPERATOR_STRING ("<=");
9111 case UNARY_PLUS_EXPR: BUILD_OPERATOR_STRING ("+");
9112 case NEGATE_EXPR: BUILD_OPERATOR_STRING ("-");
9113 case TRUTH_NOT_EXPR: BUILD_OPERATOR_STRING ("!");
9114 case BIT_NOT_EXPR: BUILD_OPERATOR_STRING ("~");
9115 case PREINCREMENT_EXPR: /* Fall through */
9116 case POSTINCREMENT_EXPR: BUILD_OPERATOR_STRING ("++");
9117 case PREDECREMENT_EXPR: /* Fall through */
9118 case POSTDECREMENT_EXPR: BUILD_OPERATOR_STRING ("--");
9120 fatal ("unregistered operator %s - operator_string",
9121 tree_code_name [TREE_CODE (node)]);
9124 #undef BUILD_OPERATOR_STRING
9127 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
9128 errors but we modify NODE so that it contains the type computed
9129 according to the expression, when it's fixed. Otherwise, we write
9130 error_mark_node as the type. It allows us to further the analysis
9131 of remaining nodes and detects more errors in certain cases. */
9134 patch_binop (node, wfl_op1, wfl_op2)
9139 tree op1 = TREE_OPERAND (node, 0);
9140 tree op2 = TREE_OPERAND (node, 1);
9141 tree op1_type = TREE_TYPE (op1);
9142 tree op2_type = TREE_TYPE (op2);
9144 int code = TREE_CODE (node);
9146 /* If 1, tell the routine that we have to return error_mark_node
9147 after checking for the initialization of the RHS */
9148 int error_found = 0;
9150 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
9154 /* 15.16 Multiplicative operators */
9155 case MULT_EXPR: /* 15.16.1 Multiplication Operator * */
9156 case RDIV_EXPR: /* 15.16.2 Division Operator / */
9157 case TRUNC_MOD_EXPR: /* 15.16.3 Remainder operator % */
9158 if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
9160 if (!JPRIMITIVE_TYPE_P (op1_type))
9161 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
9162 if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
9163 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
9164 TREE_TYPE (node) = error_mark_node;
9168 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9169 /* Change the division operator if necessary */
9170 if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
9171 TREE_SET_CODE (node, TRUNC_DIV_EXPR);
9173 /* This one is more complicated. FLOATs are processed by a
9174 function call to soft_fmod. Duplicate the value of the
9175 COMPOUND_ASSIGN_P flag. */
9176 if (code == TRUNC_MOD_EXPR)
9178 tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
9179 COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
9180 TREE_SIDE_EFFECTS (mod)
9181 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
9186 /* 15.17 Additive Operators */
9187 case PLUS_EXPR: /* 15.17.1 String Concatenation Operator + */
9189 /* Operation is valid if either one argument is a string
9190 constant, a String object or a StringBuffer crafted for the
9191 purpose of the a previous usage of the String concatenation
9194 if (TREE_CODE (op1) == STRING_CST
9195 || TREE_CODE (op2) == STRING_CST
9196 || JSTRING_TYPE_P (op1_type)
9197 || JSTRING_TYPE_P (op2_type)
9198 || IS_CRAFTED_STRING_BUFFER_P (op1)
9199 || IS_CRAFTED_STRING_BUFFER_P (op2))
9200 return build_string_concatenation (op1, op2);
9202 case MINUS_EXPR: /* 15.17.2 Additive Operators (+ and -) for
9204 if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
9206 if (!JPRIMITIVE_TYPE_P (op1_type))
9207 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
9208 if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
9209 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
9210 TREE_TYPE (node) = error_mark_node;
9214 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9217 /* 15.18 Shift Operators */
9221 if (!JINTEGRAL_TYPE_P (op1_type) || !JINTEGRAL_TYPE_P (op2_type))
9223 if (!JINTEGRAL_TYPE_P (op1_type))
9224 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
9227 (wfl_operator, (JPRIMITIVE_TYPE_P (op2_type) ?
9228 "Incompatible type for `%s'. Explicit cast needed to convert "
9229 "shift distance from `%s' to integral" :
9230 "Incompatible type for `%s'. Can't convert shift distance from "
9231 "`%s' to integral"),
9232 operator_string (node), lang_printable_name (op2_type, 0));
9233 TREE_TYPE (node) = error_mark_node;
9238 /* Unary numeric promotion (5.6.1) is performed on each operand
9240 op1 = do_unary_numeric_promotion (op1);
9241 op2 = do_unary_numeric_promotion (op2);
9243 /* The type of the shift expression is the type of the promoted
9244 type of the left-hand operand */
9245 prom_type = TREE_TYPE (op1);
9247 /* Shift int only up to 0x1f and long up to 0x3f */
9248 if (prom_type == int_type_node)
9249 op2 = fold (build (BIT_AND_EXPR, int_type_node, op2,
9250 build_int_2 (0x1f, 0)));
9252 op2 = fold (build (BIT_AND_EXPR, int_type_node, op2,
9253 build_int_2 (0x3f, 0)));
9255 /* The >>> operator is a >> operating on unsigned quantities */
9256 if (code == URSHIFT_EXPR && ! flag_emit_class_files)
9259 tree utype = unsigned_type (prom_type);
9260 op1 = convert (utype, op1);
9261 TREE_SET_CODE (node, RSHIFT_EXPR);
9262 TREE_OPERAND (node, 0) = op1;
9263 TREE_OPERAND (node, 1) = op2;
9264 TREE_TYPE (node) = utype;
9265 to_return = convert (prom_type, node);
9266 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
9267 COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
9268 TREE_SIDE_EFFECTS (to_return)
9269 = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
9274 /* 15.19.1 Type Comparison Operator instaceof */
9275 case INSTANCEOF_EXPR:
9277 TREE_TYPE (node) = boolean_type_node;
9279 if (!(op2_type = resolve_type_during_patch (op2)))
9280 return error_mark_node;
9282 /* The first operand must be a reference type or the null type */
9283 if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
9284 error_found = 1; /* Error reported further below */
9286 /* The second operand must be a reference type */
9287 if (!JREFERENCE_TYPE_P (op2_type))
9289 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
9291 (wfl_operator, "Invalid argument `%s' for `instanceof'",
9292 lang_printable_name (op2_type, 0));
9296 if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
9298 /* If the first operand is null, the result is always false */
9299 if (op1 == null_pointer_node)
9300 return boolean_false_node;
9301 else if (flag_emit_class_files)
9303 TREE_OPERAND (node, 1) = op2_type;
9304 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
9307 /* Otherwise we have to invoke instance of to figure it out */
9311 build (CALL_EXPR, boolean_type_node,
9312 build_address_of (soft_instanceof_node),
9315 build_tree_list (NULL_TREE,
9316 build_class_ref (op2_type))),
9318 TREE_SIDE_EFFECTS (call) = TREE_SIDE_EFFECTS (op1);
9322 /* There is no way the expression operand can be an instance of
9323 the type operand. This is a compile time error. */
9326 char *t1 = strdup (lang_printable_name (op1_type, 0));
9327 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
9329 (wfl_operator, "Impossible for `%s' to be instance of `%s'",
9330 t1, lang_printable_name (op2_type, 0));
9337 /* 15.21 Bitwise and Logical Operators */
9341 if (JINTEGRAL_TYPE_P (op1_type) && JINTEGRAL_TYPE_P (op2_type))
9342 /* Binary numeric promotion is performed on both operand and the
9343 expression retain that type */
9344 prom_type = binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9346 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE
9347 && TREE_CODE (op1_type) == BOOLEAN_TYPE)
9348 /* The type of the bitwise operator expression is BOOLEAN */
9349 prom_type = boolean_type_node;
9352 if (!JINTEGRAL_TYPE_P (op1_type))
9353 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
9354 if (!JINTEGRAL_TYPE_P (op2_type) && (op1_type != op2_type))
9355 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op2_type);
9356 TREE_TYPE (node) = error_mark_node;
9358 /* Insert a break here if adding thing before the switch's
9359 break for this case */
9363 /* 15.22 Conditional-And Operator */
9364 case TRUTH_ANDIF_EXPR:
9365 /* 15.23 Conditional-Or Operator */
9366 case TRUTH_ORIF_EXPR:
9367 /* Operands must be of BOOLEAN type */
9368 if (TREE_CODE (op1_type) != BOOLEAN_TYPE ||
9369 TREE_CODE (op2_type) != BOOLEAN_TYPE)
9371 if (TREE_CODE (op1_type) != BOOLEAN_TYPE)
9372 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op1_type);
9373 if (TREE_CODE (op2_type) != BOOLEAN_TYPE && (op1_type != op2_type))
9374 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op2_type);
9375 TREE_TYPE (node) = boolean_type_node;
9379 /* The type of the conditional operators is BOOLEAN */
9380 prom_type = boolean_type_node;
9383 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
9388 /* The type of each of the operands must be a primitive numeric
9390 if (!JNUMERIC_TYPE_P (op1_type) || ! JNUMERIC_TYPE_P (op2_type))
9392 if (!JNUMERIC_TYPE_P (op1_type))
9393 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
9394 if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
9395 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
9396 TREE_TYPE (node) = boolean_type_node;
9400 /* Binary numeric promotion is performed on the operands */
9401 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9402 /* The type of the relation expression is always BOOLEAN */
9403 prom_type = boolean_type_node;
9406 /* 15.20 Equality Operator */
9409 /* 15.20.1 Numerical Equality Operators == and != */
9410 /* Binary numeric promotion is performed on the operands */
9411 if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
9412 binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
9414 /* 15.20.2 Boolean Equality Operators == and != */
9415 else if (TREE_CODE (op1_type) == BOOLEAN_TYPE &&
9416 TREE_CODE (op2_type) == BOOLEAN_TYPE)
9417 ; /* Nothing to do here */
9419 /* 15.20.3 Reference Equality Operators == and != */
9420 /* Types have to be either references or the null type. If
9421 they're references, it must be possible to convert either
9422 type to the other by casting conversion. */
9423 else if (op1 == null_pointer_node || op2 == null_pointer_node
9424 || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
9425 && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
9426 || valid_ref_assignconv_cast_p (op2_type,
9428 ; /* Nothing to do here */
9430 /* Else we have an error figure what can't be converted into
9431 what and report the error */
9435 t1 = strdup (lang_printable_name (op1_type, 0));
9437 (wfl_operator, "Incompatible type for `%s'. Can't convert `%s' "
9438 "to `%s'", operator_string (node), t1,
9439 lang_printable_name (op2_type, 0));
9441 TREE_TYPE (node) = boolean_type_node;
9445 prom_type = boolean_type_node;
9450 return error_mark_node;
9452 TREE_OPERAND (node, 0) = op1;
9453 TREE_OPERAND (node, 1) = op2;
9454 TREE_TYPE (node) = prom_type;
9455 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
9457 /* fold does not respect side-effect order as required for Java but not C.
9458 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
9461 if (flag_emit_class_files ? (TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
9462 : ! TREE_SIDE_EFFECTS (node))
9467 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
9468 zero value, the value of CSTE comes after the valude of STRING */
9471 do_merge_string_cste (cste, string, string_len, after)
9474 int string_len, after;
9476 int len = TREE_STRING_LENGTH (cste) + string_len;
9477 char *old = TREE_STRING_POINTER (cste);
9478 TREE_STRING_LENGTH (cste) = len;
9479 TREE_STRING_POINTER (cste) = obstack_alloc (expression_obstack, len+1);
9482 strcpy (TREE_STRING_POINTER (cste), string);
9483 strcat (TREE_STRING_POINTER (cste), old);
9487 strcpy (TREE_STRING_POINTER (cste), old);
9488 strcat (TREE_STRING_POINTER (cste), string);
9493 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
9494 new STRING_CST on success, NULL_TREE on failure */
9497 merge_string_cste (op1, op2, after)
9501 /* Handle two string constants right away */
9502 if (TREE_CODE (op2) == STRING_CST)
9503 return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
9504 TREE_STRING_LENGTH (op2), after);
9506 /* Reasonable integer constant can be treated right away */
9507 if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
9509 static char *boolean_true = "true";
9510 static char *boolean_false = "false";
9511 static char *null_pointer = "null";
9515 if (op2 == boolean_true_node)
9516 string = boolean_true;
9517 else if (op2 == boolean_false_node)
9518 string = boolean_false;
9519 else if (op2 == null_pointer_node)
9520 string = null_pointer;
9521 else if (TREE_TYPE (op2) == char_type_node)
9523 ch[0] = (char )TREE_INT_CST_LOW (op2);
9528 string = print_int_node (op2);
9530 return do_merge_string_cste (op1, string, strlen (string), after);
9535 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
9536 has to be a STRING_CST and the other part must be a STRING_CST or a
9537 INTEGRAL constant. Return a new STRING_CST if the operation
9538 succeed, NULL_TREE otherwise.
9540 If the case we want to optimize for space, we might want to return
9541 NULL_TREE for each invocation of this routine. FIXME */
9544 string_constant_concatenation (op1, op2)
9547 if (TREE_CODE (op1) == STRING_CST || (TREE_CODE (op2) == STRING_CST))
9552 string = (TREE_CODE (op1) == STRING_CST ? op1 : op2);
9553 rest = (string == op1 ? op2 : op1);
9554 invert = (string == op1 ? 0 : 1 );
9556 /* Walk REST, only if it looks reasonable */
9557 if (TREE_CODE (rest) != STRING_CST
9558 && !IS_CRAFTED_STRING_BUFFER_P (rest)
9559 && !JSTRING_TYPE_P (TREE_TYPE (rest))
9560 && TREE_CODE (rest) == EXPR_WITH_FILE_LOCATION)
9562 rest = java_complete_tree (rest);
9563 if (rest == error_mark_node)
9564 return error_mark_node;
9567 return merge_string_cste (string, rest, invert);
9572 /* Implement the `+' operator. Does static optimization if possible,
9573 otherwise create (if necessary) and append elements to a
9574 StringBuffer. The StringBuffer will be carried around until it is
9575 used for a function call or an assignment. Then toString() will be
9576 called on it to turn it into a String object. */
9579 build_string_concatenation (op1, op2)
9583 int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
9585 /* Try to do some static optimization */
9586 if ((result = string_constant_concatenation (op1, op2)))
9589 /* Discard empty strings on either side of the expression */
9590 if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
9595 else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
9598 /* If operands are string constant, turn then into object references */
9599 if (TREE_CODE (op1) == STRING_CST)
9600 op1 = patch_string_cst (op1);
9601 if (op2 && TREE_CODE (op2) == STRING_CST)
9602 op2 = patch_string_cst (op2);
9604 /* If either one of the constant is null and the other non null
9605 operand is a String object, return it. */
9606 if (JSTRING_TYPE_P (TREE_TYPE (op1)) && !op2)
9609 /* If OP1 isn't already a StringBuffer, create and
9610 initialize a new one */
9611 if (!IS_CRAFTED_STRING_BUFFER_P (op1))
9613 /* Two solutions here:
9614 1) OP1 is a string reference, we call new StringBuffer(OP1)
9615 2) OP1 is something else, we call new StringBuffer().append(OP1). */
9616 if (JSTRING_TYPE_P (TREE_TYPE (op1)))
9617 op1 = BUILD_STRING_BUFFER (op1);
9620 tree aNew = BUILD_STRING_BUFFER (NULL_TREE);
9621 op1 = make_qualified_primary (aNew, BUILD_APPEND (op1), 0);
9627 /* OP1 is no longer the last node holding a crafted StringBuffer */
9628 IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
9629 /* Create a node for `{new...,xxx}.append (op2)' */
9631 op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
9634 /* Mark the last node holding a crafted StringBuffer */
9635 IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
9637 TREE_SIDE_EFFECTS (op1) = side_effects;
9641 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
9642 StringBuffer. If no string were found to be patched, return
9649 if (node == error_mark_node)
9650 return error_mark_node;
9651 if (TREE_CODE (node) == STRING_CST)
9652 return patch_string_cst (node);
9653 else if (IS_CRAFTED_STRING_BUFFER_P (node))
9655 int saved = ctxp->explicit_constructor_p;
9656 tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
9658 /* Temporary disable forbid the use of `this'. */
9659 ctxp->explicit_constructor_p = 0;
9660 ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
9661 /* Restore it at its previous value */
9662 ctxp->explicit_constructor_p = saved;
9668 /* Build the internal representation of a string constant. */
9671 patch_string_cst (node)
9675 if (! flag_emit_class_files)
9677 push_obstacks (&permanent_obstack, &permanent_obstack);
9678 node = get_identifier (TREE_STRING_POINTER (node));
9679 location = alloc_name_constant (CONSTANT_String, node);
9680 node = build_ref_from_constant_pool (location);
9682 TREE_TYPE (node) = promote_type (string_type_node);
9683 TREE_CONSTANT (node) = 1;
9687 /* Build an incomplete unary operator expression. */
9690 build_unaryop (op_token, op_location, op1)
9691 int op_token, op_location;
9698 case PLUS_TK: op = UNARY_PLUS_EXPR; break;
9699 case MINUS_TK: op = NEGATE_EXPR; break;
9700 case NEG_TK: op = TRUTH_NOT_EXPR; break;
9701 case NOT_TK: op = BIT_NOT_EXPR; break;
9702 default: fatal ("Unknown token `%d' for unary operator - build_unaryop",
9706 unaryop = build1 (op, NULL_TREE, op1);
9707 TREE_SIDE_EFFECTS (unaryop) = 1;
9708 /* Store the location of the operator, for better error report. The
9709 string of the operator will be rebuild based on the OP value. */
9710 EXPR_WFL_LINECOL (unaryop) = op_location;
9714 /* Special case for the ++/-- operators, since they require an extra
9715 argument to build, which is set to NULL and patched
9716 later. IS_POST_P is 1 if the operator, 0 otherwise. */
9719 build_incdec (op_token, op_location, op1, is_post_p)
9720 int op_token, op_location;
9724 static enum tree_code lookup [2][2] =
9726 { PREDECREMENT_EXPR, PREINCREMENT_EXPR, },
9727 { POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, },
9729 tree node = build (lookup [is_post_p][(op_token - DECR_TK)],
9730 NULL_TREE, op1, NULL_TREE);
9731 TREE_SIDE_EFFECTS (node) = 1;
9732 /* Store the location of the operator, for better error report. The
9733 string of the operator will be rebuild based on the OP value. */
9734 EXPR_WFL_LINECOL (node) = op_location;
9738 /* Build an incomplete cast operator, based on the use of the
9739 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
9740 set. java_complete_tree is trained to walk a CONVERT_EXPR even
9741 though its type is already set. */
9744 build_cast (location, type, exp)
9748 tree node = build1 (CONVERT_EXPR, type, exp);
9749 EXPR_WFL_LINECOL (node) = location;
9753 /* 15.14 Unary operators. We return error_mark_node in case of error,
9754 but preserve the type of NODE if the type is fixed. */
9757 patch_unaryop (node, wfl_op)
9761 tree op = TREE_OPERAND (node, 0);
9762 tree op_type = TREE_TYPE (op);
9763 tree prom_type, value, decl;
9764 int code = TREE_CODE (node);
9765 int error_found = 0;
9767 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
9771 /* 15.13.2 Postfix Increment Operator ++ */
9772 case POSTINCREMENT_EXPR:
9773 /* 15.13.3 Postfix Increment Operator -- */
9774 case POSTDECREMENT_EXPR:
9775 /* 15.14.1 Prefix Increment Operator ++ */
9776 case PREINCREMENT_EXPR:
9777 /* 15.14.2 Prefix Decrement Operator -- */
9778 case PREDECREMENT_EXPR:
9779 decl = strip_out_static_field_access_decl (op);
9780 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
9782 && TREE_CODE (decl) != COMPONENT_REF
9783 && !(flag_emit_class_files && TREE_CODE (decl) == ARRAY_REF)
9784 && TREE_CODE (decl) != INDIRECT_REF
9785 && !(TREE_CODE (decl) == COMPOUND_EXPR
9786 && TREE_OPERAND (decl, 1)
9787 && (TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)))
9790 /* Before screaming, check that we're not in fact trying to
9791 increment a optimized static final access, in which case
9792 we issue an different error message. */
9793 if (!(TREE_CODE (wfl_op) == EXPR_WITH_FILE_LOCATION
9794 && resolve_expression_name (wfl_op, &lvalue)
9795 && check_final_assignment (lvalue, wfl_op)))
9796 parse_error_context (wfl_operator, "Invalid argument to `%s'",
9797 operator_string (node));
9798 TREE_TYPE (node) = error_mark_node;
9801 else if (check_final_assignment (op, wfl_op))
9804 /* From now on, we know that op if a variable and that it has a
9805 valid wfl. We use wfl_op to locate errors related to the
9807 else if (!JNUMERIC_TYPE_P (op_type))
9810 (wfl_op, "Invalid argument type `%s' to `%s'",
9811 lang_printable_name (op_type, 0), operator_string (node));
9812 TREE_TYPE (node) = error_mark_node;
9817 /* Before the addition, binary numeric promotion is performed on
9819 value = build_int_2 (1, 0);
9821 binary_numeric_promotion (op_type, TREE_TYPE (value), &op, &value);
9822 /* And write the promoted incremented and increment */
9823 TREE_OPERAND (node, 0) = op;
9824 TREE_OPERAND (node, 1) = value;
9825 /* Convert the overall back into its original type. */
9826 return fold (convert (op_type, node));
9830 /* 15.14.3 Unary Plus Operator + */
9831 case UNARY_PLUS_EXPR:
9832 /* 15.14.4 Unary Minus Operator - */
9834 if (!JNUMERIC_TYPE_P (op_type))
9836 ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op_type);
9837 TREE_TYPE (node) = error_mark_node;
9840 /* Unary numeric promotion is performed on operand */
9843 op = do_unary_numeric_promotion (op);
9844 prom_type = TREE_TYPE (op);
9845 if (code == UNARY_PLUS_EXPR)
9850 /* 15.14.5 Bitwise Complement Operator ~ */
9852 if (!JINTEGRAL_TYPE_P (op_type))
9854 ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op_type);
9855 TREE_TYPE (node) = error_mark_node;
9860 op = do_unary_numeric_promotion (op);
9861 prom_type = TREE_TYPE (op);
9865 /* 15.14.6 Logical Complement Operator ! */
9866 case TRUTH_NOT_EXPR:
9867 if (TREE_CODE (op_type) != BOOLEAN_TYPE)
9869 ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
9870 /* But the type is known. We will report an error if further
9871 attempt of a assignment is made with this rhs */
9872 TREE_TYPE (node) = boolean_type_node;
9876 prom_type = boolean_type_node;
9879 /* 15.15 Cast Expression */
9881 value = patch_cast (node, wfl_operator);
9882 if (value == error_mark_node)
9884 /* If this cast is part of an assignment, we tell the code
9885 that deals with it not to complain about a mismatch,
9886 because things have been cast, anyways */
9887 TREE_TYPE (node) = error_mark_node;
9892 value = fold (value);
9893 TREE_SIDE_EFFECTS (value) = TREE_SIDE_EFFECTS (op);
9900 return error_mark_node;
9902 /* There are cases where node has been replaced by something else
9903 and we don't end up returning here: UNARY_PLUS_EXPR,
9904 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
9905 TREE_OPERAND (node, 0) = fold (op);
9906 TREE_TYPE (node) = prom_type;
9907 TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
9911 /* Generic type resolution that sometimes takes place during node
9912 patching. Returned the resolved type or generate an error
9913 message. Return the resolved type or NULL_TREE. */
9916 resolve_type_during_patch (type)
9919 if (unresolved_type_p (type, NULL))
9921 tree type_decl = resolve_no_layout (EXPR_WFL_NODE (type), NULL_TREE);
9924 parse_error_context (type,
9925 "Class `%s' not found in type declaration",
9926 IDENTIFIER_POINTER (EXPR_WFL_NODE (type)));
9931 CLASS_LOADED_P (TREE_TYPE (type_decl)) = 1;
9932 return TREE_TYPE (type_decl);
9937 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
9938 found. Otherwise NODE or something meant to replace it is returned. */
9941 patch_cast (node, wfl_operator)
9945 tree op = TREE_OPERAND (node, 0);
9946 tree op_type = TREE_TYPE (op);
9947 tree cast_type = TREE_TYPE (node);
9950 /* First resolve OP_TYPE if unresolved */
9951 if (!(cast_type = resolve_type_during_patch (cast_type)))
9952 return error_mark_node;
9954 /* Check on cast that are proven correct at compile time */
9955 if (JNUMERIC_TYPE_P (cast_type) && JNUMERIC_TYPE_P (op_type))
9957 static tree convert_narrow ();
9959 if (cast_type == op_type)
9962 /* float and double type are converted to the original type main
9963 variant and then to the target type. */
9964 if (JFLOAT_TYPE_P (op_type) && TREE_CODE (cast_type) == CHAR_TYPE)
9965 op = convert (integer_type_node, op);
9967 /* Try widening/narowwing convertion. Potentially, things need
9968 to be worked out in gcc so we implement the extreme cases
9969 correctly. fold_convert() needs to be fixed. */
9970 return convert (cast_type, op);
9973 /* It's also valid to cast a boolean into a boolean */
9974 if (op_type == boolean_type_node && cast_type == boolean_type_node)
9977 /* null can be casted to references */
9978 if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
9979 return build_null_of_type (cast_type);
9981 /* The remaining legal casts involve conversion between reference
9982 types. Check for their compile time correctness. */
9983 if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type)
9984 && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
9986 TREE_TYPE (node) = promote_type (cast_type);
9987 /* Now, the case can be determined correct at compile time if
9988 OP_TYPE can be converted into CAST_TYPE by assignment
9991 if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
9993 TREE_SET_CODE (node, NOP_EXPR);
9997 if (flag_emit_class_files)
9999 TREE_SET_CODE (node, CONVERT_EXPR);
10003 /* The cast requires a run-time check */
10004 return build (CALL_EXPR, promote_type (cast_type),
10005 build_address_of (soft_checkcast_node),
10006 tree_cons (NULL_TREE, build_class_ref (cast_type),
10007 build_tree_list (NULL_TREE, op)),
10011 /* Any other casts are proven incorrect at compile time */
10012 t1 = strdup (lang_printable_name (op_type, 0));
10013 parse_error_context (wfl_operator, "Invalid cast from `%s' to `%s'",
10014 t1, lang_printable_name (cast_type, 0));
10016 return error_mark_node;
10019 /* Build a null constant and give it the type TYPE. */
10022 build_null_of_type (type)
10025 tree node = build_int_2 (0, 0);
10026 TREE_TYPE (node) = promote_type (type);
10030 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
10031 a list of indices. */
10033 build_array_ref (location, array, index)
10037 tree node = build (ARRAY_REF, NULL_TREE, array, index);
10038 EXPR_WFL_LINECOL (node) = location;
10042 /* 15.12 Array Access Expression */
10045 patch_array_ref (node)
10048 tree array = TREE_OPERAND (node, 0);
10049 tree array_type = TREE_TYPE (array);
10050 tree index = TREE_OPERAND (node, 1);
10051 tree index_type = TREE_TYPE (index);
10052 int error_found = 0;
10054 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10056 if (TREE_CODE (array_type) == POINTER_TYPE)
10057 array_type = TREE_TYPE (array_type);
10059 /* The array reference must be an array */
10060 if (!TYPE_ARRAY_P (array_type))
10062 parse_error_context
10063 (wfl_operator, "`[]' can only be applied to arrays. It can't be "
10064 "applied to `%s'", lang_printable_name (array_type, 0));
10065 TREE_TYPE (node) = error_mark_node;
10069 /* The array index underdoes unary numeric promotion. The promoted
10070 type must be int */
10071 index = do_unary_numeric_promotion (index);
10072 if (TREE_TYPE (index) != int_type_node)
10074 int could_cast = valid_cast_to_p (index_type, int_type_node);
10075 parse_error_context
10077 (could_cast ? "Incompatible type for `[]'. Explicit cast needed to "
10078 "convert `%s' to `int'" : "Incompatible type for `[]'. "
10079 "Can't convert `%s' to `int'"),
10080 lang_printable_name (index_type, 0));
10081 TREE_TYPE (node) = error_mark_node;
10086 return error_mark_node;
10088 array_type = TYPE_ARRAY_ELEMENT (array_type);
10090 if (flag_emit_class_files || flag_emit_xref)
10092 TREE_OPERAND (node, 0) = array;
10093 TREE_OPERAND (node, 1) = index;
10097 /* The save_expr is for correct evaluation order. It would be cleaner
10098 to use force_evaluation_order (see comment there), but that is
10099 difficult when we also have to deal with bounds checking. */
10100 if (TREE_SIDE_EFFECTS (index))
10101 array = save_expr (array);
10102 node = build_java_arrayaccess (array, array_type, index);
10103 if (TREE_SIDE_EFFECTS (index))
10104 node = build (COMPOUND_EXPR, array_type, array, node);
10106 TREE_TYPE (node) = array_type;
10110 /* 15.9 Array Creation Expressions */
10113 build_newarray_node (type, dims, extra_dims)
10119 build (NEW_ARRAY_EXPR, NULL_TREE, type, nreverse (dims),
10120 build_int_2 (extra_dims, 0));
10125 patch_newarray (node)
10128 tree type = TREE_OPERAND (node, 0);
10129 tree dims = TREE_OPERAND (node, 1);
10130 tree cdim, array_type;
10131 int error_found = 0;
10133 int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
10135 /* Dimension types are verified. It's better for the types to be
10136 verified in order. */
10137 for (cdim = dims, ndims = 0; cdim; cdim = TREE_CHAIN (cdim), ndims++ )
10140 tree dim = TREE_VALUE (cdim);
10142 /* Dim might have been saved during its evaluation */
10143 dim = (TREE_CODE (dim) == SAVE_EXPR ? dim = TREE_OPERAND (dim, 0) : dim);
10145 /* The type of each specified dimension must be an integral type. */
10146 if (!JINTEGRAL_TYPE_P (TREE_TYPE (dim)))
10149 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
10150 promoted type must be int. */
10153 dim = do_unary_numeric_promotion (dim);
10154 if (TREE_TYPE (dim) != int_type_node)
10158 /* Report errors on types here */
10161 parse_error_context
10162 (TREE_PURPOSE (cdim),
10163 "Incompatible type for dimension in array creation expression. "
10164 "%s convert `%s' to `int'",
10165 (valid_cast_to_p (TREE_TYPE (dim), int_type_node) ?
10166 "Explicit cast needed to" : "Can't"),
10167 lang_printable_name (TREE_TYPE (dim), 0));
10171 TREE_PURPOSE (cdim) = NULL_TREE;
10174 /* Resolve array base type if unresolved */
10175 if (!(type = resolve_type_during_patch (type)))
10180 /* We don't want further evaluation of this bogus array creation
10182 TREE_TYPE (node) = error_mark_node;
10183 return error_mark_node;
10186 /* Set array_type to the actual (promoted) array type of the result. */
10187 if (TREE_CODE (type) == RECORD_TYPE)
10188 type = build_pointer_type (type);
10189 while (--xdims >= 0)
10191 type = promote_type (build_java_array_type (type, -1));
10193 dims = nreverse (dims);
10195 for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
10198 array_type = build_java_array_type (type,
10199 TREE_CODE (cdim) == INTEGER_CST ?
10200 TREE_INT_CST_LOW (cdim) : -1);
10201 array_type = promote_type (array_type);
10203 dims = nreverse (dims);
10205 /* The node is transformed into a function call. Things are done
10206 differently according to the number of dimensions. If the number
10207 of dimension is equal to 1, then the nature of the base type
10208 (primitive or not) matters. */
10210 return build_new_array (type, TREE_VALUE (dims));
10212 /* Can't reuse what's already written in expr.c because it uses the
10213 JVM stack representation. Provide a build_multianewarray. FIXME */
10214 return build (CALL_EXPR, array_type,
10215 build_address_of (soft_multianewarray_node),
10216 tree_cons (NULL_TREE, build_class_ref (TREE_TYPE (array_type)),
10217 tree_cons (NULL_TREE,
10218 build_int_2 (ndims, 0), dims )),
10222 /* 10.6 Array initializer. */
10224 /* Build a wfl for array element that don't have one, so we can
10225 pin-point errors. */
10228 maybe_build_array_element_wfl (node)
10231 if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
10232 return build_expr_wfl (NULL_TREE, ctxp->filename,
10233 ctxp->elc.line, ctxp->elc.prev_col);
10238 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
10239 identification of initialized arrays easier to detect during walk
10243 build_new_array_init (location, values)
10247 tree constructor = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, values);
10248 tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
10249 EXPR_WFL_LINECOL (to_return) = location;
10253 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
10254 occurred. Otherwise return NODE after having set its type
10258 patch_new_array_init (type, node)
10261 int error_seen = 0;
10262 tree current, element_type;
10263 HOST_WIDE_INT length;
10264 int all_constant = 1;
10265 tree init = TREE_OPERAND (node, 0);
10267 if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
10269 parse_error_context (node,
10270 "Invalid array initializer for non-array type `%s'",
10271 lang_printable_name (type, 1));
10272 return error_mark_node;
10274 type = TREE_TYPE (type);
10275 element_type = TYPE_ARRAY_ELEMENT (type);
10277 CONSTRUCTOR_ELTS (init) = nreverse (CONSTRUCTOR_ELTS (init));
10279 for (length = 0, current = CONSTRUCTOR_ELTS (init);
10280 current; length++, current = TREE_CHAIN (current))
10282 tree elt = TREE_VALUE (current);
10283 if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
10285 error_seen |= array_constructor_check_entry (element_type, current);
10286 elt = TREE_VALUE (current);
10287 /* When compiling to native code, STRING_CST is converted to
10288 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
10289 if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
10294 TREE_VALUE (current) = patch_new_array_init (element_type, elt);
10295 TREE_PURPOSE (current) = NULL_TREE;
10298 if (elt && TREE_VALUE (elt) == error_mark_node)
10303 return error_mark_node;
10305 /* Create a new type. We can't reuse the one we have here by
10306 patching its dimension because it originally is of dimension -1
10307 hence reused by gcc. This would prevent triangular arrays. */
10308 type = build_java_array_type (element_type, length);
10309 TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
10310 TREE_TYPE (node) = promote_type (type);
10311 TREE_CONSTANT (init) = all_constant;
10312 TREE_CONSTANT (node) = all_constant;
10316 /* Verify that one entry of the initializer element list can be
10317 assigned to the array base type. Report 1 if an error occurred, 0
10321 array_constructor_check_entry (type, entry)
10324 char *array_type_string = NULL; /* For error reports */
10325 tree value, type_value, new_value, wfl_value, patched;
10326 int error_seen = 0;
10328 new_value = NULL_TREE;
10329 wfl_value = TREE_VALUE (entry);
10331 value = java_complete_tree (TREE_VALUE (entry));
10332 /* patch_string return error_mark_node if arg is error_mark_node */
10333 if ((patched = patch_string (value)))
10335 if (value == error_mark_node)
10338 type_value = TREE_TYPE (value);
10340 /* At anytime, try_builtin_assignconv can report a warning on
10341 constant overflow during narrowing. */
10342 SET_WFL_OPERATOR (wfl_operator, TREE_PURPOSE (entry), wfl_value);
10343 new_value = try_builtin_assignconv (wfl_operator, type, value);
10344 if (!new_value && (new_value = try_reference_assignconv (type, value)))
10345 type_value = promote_type (type);
10347 /* Check and report errors */
10350 char *msg = (!valid_cast_to_p (type_value, type) ?
10351 "Can't" : "Explicit cast needed to");
10352 if (!array_type_string)
10353 array_type_string = strdup (lang_printable_name (type, 1));
10354 parse_error_context
10355 (wfl_operator, "Incompatible type for array. %s convert `%s' to `%s'",
10356 msg, lang_printable_name (type_value, 1), array_type_string);
10362 new_value = maybe_build_primttype_type_ref (new_value, wfl_operator);
10363 TREE_VALUE (entry) = new_value;
10366 if (array_type_string)
10367 free (array_type_string);
10369 TREE_PURPOSE (entry) = NULL_TREE;
10374 build_this (location)
10377 tree node = build_wfl_node (this_identifier_node);
10378 TREE_SET_CODE (node, THIS_EXPR);
10379 EXPR_WFL_LINECOL (node) = location;
10383 /* 14.15 The return statement. It builds a modify expression that
10384 assigns the returned value to the RESULT_DECL that hold the value
10388 build_return (location, op)
10392 tree node = build1 (RETURN_EXPR, NULL_TREE, op);
10393 EXPR_WFL_LINECOL (node) = location;
10394 node = build_debugable_stmt (location, node);
10399 patch_return (node)
10402 tree return_exp = TREE_OPERAND (node, 0);
10403 tree meth = current_function_decl;
10404 tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
10405 int error_found = 0;
10407 TREE_TYPE (node) = error_mark_node;
10408 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10410 /* It's invalid to have a return value within a function that is
10411 declared with the keyword void or that is a constructor */
10412 if (return_exp && (mtype == void_type_node || DECL_CONSTRUCTOR_P (meth)))
10415 /* It's invalid to use a return statement in a static block */
10416 if (IS_CLINIT (current_function_decl))
10419 /* It's invalid to have a no return value within a function that
10420 isn't declared with the keyword `void' */
10421 if (!return_exp && (mtype != void_type_node && !DECL_CONSTRUCTOR_P (meth)))
10426 if (IS_CLINIT (current_function_decl))
10427 parse_error_context (wfl_operator,
10428 "`return' inside static initializer.");
10430 else if (!DECL_CONSTRUCTOR_P (meth))
10432 char *t = strdup (lang_printable_name (mtype, 0));
10433 parse_error_context (wfl_operator,
10434 "`return' with%s value from `%s %s'",
10435 (error_found == 1 ? "" : "out"),
10436 t, lang_printable_name (meth, 0));
10440 parse_error_context (wfl_operator,
10441 "`return' with value from constructor `%s'",
10442 lang_printable_name (meth, 0));
10443 return error_mark_node;
10446 /* If we have a return_exp, build a modify expression and expand
10447 it. Note: at that point, the assignment is declared valid, but we
10448 may want to carry some more hacks */
10451 tree exp = java_complete_tree (return_exp);
10452 tree modify, patched;
10454 /* If the function returned value and EXP are booleans, EXP has
10455 to be converted into the type of DECL_RESULT, which is integer
10456 (see complete_start_java_method) */
10457 if (TREE_TYPE (exp) == boolean_type_node &&
10458 TREE_TYPE (TREE_TYPE (meth)) == boolean_type_node)
10459 exp = convert_to_integer (TREE_TYPE (DECL_RESULT (meth)), exp);
10461 /* `null' can be assigned to a function returning a reference */
10462 if (JREFERENCE_TYPE_P (TREE_TYPE (TREE_TYPE (meth))) &&
10463 exp == null_pointer_node)
10464 exp = build_null_of_type (TREE_TYPE (TREE_TYPE (meth)));
10466 if ((patched = patch_string (exp)))
10469 modify = build (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
10470 EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
10471 modify = java_complete_tree (modify);
10473 if (modify != error_mark_node)
10475 TREE_SIDE_EFFECTS (modify) = 1;
10476 TREE_OPERAND (node, 0) = modify;
10479 return error_mark_node;
10481 TREE_TYPE (node) = void_type_node;
10482 TREE_SIDE_EFFECTS (node) = 1;
10486 /* 14.8 The if Statement */
10489 build_if_else_statement (location, expression, if_body, else_body)
10491 tree expression, if_body, else_body;
10495 else_body = empty_stmt_node;
10496 node = build (COND_EXPR, NULL_TREE, expression, if_body, else_body);
10497 EXPR_WFL_LINECOL (node) = location;
10498 node = build_debugable_stmt (location, node);
10503 patch_if_else_statement (node)
10506 tree expression = TREE_OPERAND (node, 0);
10508 TREE_TYPE (node) = error_mark_node;
10509 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10511 /* The type of expression must be boolean */
10512 if (TREE_TYPE (expression) != boolean_type_node
10513 && TREE_TYPE (expression) != promoted_boolean_type_node)
10515 parse_error_context
10517 "Incompatible type for `if'. Can't convert `%s' to `boolean'",
10518 lang_printable_name (TREE_TYPE (expression), 0));
10519 return error_mark_node;
10522 TREE_TYPE (node) = void_type_node;
10523 TREE_SIDE_EFFECTS (node) = 1;
10524 CAN_COMPLETE_NORMALLY (node)
10525 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
10526 | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2));
10530 /* 14.6 Labeled Statements */
10532 /* Action taken when a lableled statement is parsed. a new
10533 LABELED_BLOCK_EXPR is created. No statement is attached to the
10534 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
10537 build_labeled_block (location, label)
10542 tree label_decl, node;
10543 if (label == NULL_TREE || label == continue_identifier_node)
10544 label_name = label;
10547 label_name = merge_qualified_name (label_id, label);
10548 /* Issue an error if we try to reuse a label that was previously
10550 if (IDENTIFIER_LOCAL_VALUE (label_name))
10552 EXPR_WFL_LINECOL (wfl_operator) = location;
10553 parse_error_context (wfl_operator, "Declaration of `%s' shadows "
10554 "a previous label declaration",
10555 IDENTIFIER_POINTER (label));
10556 EXPR_WFL_LINECOL (wfl_operator) =
10557 EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
10558 parse_error_context (wfl_operator, "This is the location of the "
10559 "previous declaration of label `%s'",
10560 IDENTIFIER_POINTER (label));
10561 java_error_count--;
10565 label_decl = create_label_decl (label_name);
10566 node = build (LABELED_BLOCK_EXPR, NULL_TREE, label_decl, NULL_TREE);
10567 EXPR_WFL_LINECOL (node) = location;
10568 TREE_SIDE_EFFECTS (node) = 1;
10572 /* A labeled statement LBE is attached a statement. */
10575 finish_labeled_statement (lbe, statement)
10576 tree lbe; /* Labeled block expr */
10579 /* In anyways, tie the loop to its statement */
10580 LABELED_BLOCK_BODY (lbe) = statement;
10582 /* Ok, if statement is a for loop, we have to attach the labeled
10583 statement to the block the for loop belongs to and return the
10585 if (TREE_CODE (statement) == LOOP_EXPR && IS_FOR_LOOP_P (statement))
10587 java_method_add_stmt (current_function_decl, lbe);
10588 lbe = exit_block ();
10590 pop_labeled_block ();
10591 POP_LABELED_BLOCK ();
10595 /* 14.10, 14.11, 14.12 Loop Statements */
10597 /* Create an empty LOOP_EXPR and make it the last in the nested loop
10601 build_new_loop (loop_body)
10604 tree loop = build (LOOP_EXPR, NULL_TREE, loop_body);
10605 TREE_SIDE_EFFECTS (loop) = 1;
10610 /* Create a loop body according to the following structure:
10612 COMPOUND_EXPR (loop main body)
10613 EXIT_EXPR (this order is for while/for loops.
10614 LABELED_BLOCK_EXPR the order is reversed for do loops)
10615 LABEL_DECL (a continue occuring here branches at the
10616 BODY end of this labeled block)
10619 REVERSED, if non zero, tells that the loop condition expr comes
10620 after the body, like in the do-while loop.
10622 To obtain a loop, the loop body structure described above is
10623 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
10626 LABEL_DECL (use this label to exit the loop)
10628 <structure described above> */
10631 build_loop_body (location, condition, reversed)
10636 tree first, second, body;
10638 condition = build (EXIT_EXPR, NULL_TREE, condition); /* Force walk */
10639 EXPR_WFL_LINECOL (condition) = location; /* For accurate error report */
10640 condition = build_debugable_stmt (location, condition);
10641 TREE_SIDE_EFFECTS (condition) = 1;
10643 body = build_labeled_block (0, continue_identifier_node);
10644 first = (reversed ? body : condition);
10645 second = (reversed ? condition : body);
10647 build (COMPOUND_EXPR, NULL_TREE,
10648 build (COMPOUND_EXPR, NULL_TREE, first, second), empty_stmt_node);
10651 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
10652 their order) on the current loop. Unlink the current loop from the
10656 finish_loop_body (location, condition, body, reversed)
10658 tree condition, body;
10661 tree to_return = ctxp->current_loop;
10662 tree loop_body = LOOP_EXPR_BODY (to_return);
10665 tree cnode = LOOP_EXPR_BODY_CONDITION_EXPR (loop_body, reversed);
10666 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
10667 The real EXIT_EXPR is one operand further. */
10668 EXPR_WFL_LINECOL (cnode) = location;
10669 /* This one is for accurate error reports */
10670 EXPR_WFL_LINECOL (TREE_OPERAND (cnode, 0)) = location;
10671 TREE_OPERAND (TREE_OPERAND (cnode, 0), 0) = condition;
10673 LOOP_EXPR_BODY_BODY_EXPR (loop_body, reversed) = body;
10678 /* Tailored version of finish_loop_body for FOR loops, when FOR
10679 loops feature the condition part */
10682 finish_for_loop (location, condition, update, body)
10684 tree condition, update, body;
10686 /* Put the condition and the loop body in place */
10687 tree loop = finish_loop_body (location, condition, body, 0);
10688 /* LOOP is the current loop which has been now popped of the loop
10689 stack. Install the update block */
10690 LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
10694 /* If the loop isn't surrounded by a labeled statement, create one and
10695 insert LOOP as its body. */
10698 patch_loop_statement (loop)
10701 if (! LOOP_HAS_LABEL_P (loop))
10703 tree loop_label = build_labeled_block (0, NULL_TREE);
10704 LABELED_BLOCK_BODY (loop_label) = loop;
10705 PUSH_LABELED_BLOCK (loop_label);
10708 TREE_TYPE (loop) = void_type_node;
10712 /* 14.13, 14.14: break and continue Statements */
10714 /* Build a break or a continue statement. a null NAME indicates an
10715 unlabeled break/continue statement. */
10718 build_bc_statement (location, is_break, name)
10719 int location, is_break;
10722 tree break_continue, label_block_expr = NULL_TREE;
10726 if (!(label_block_expr = IDENTIFIER_LOCAL_VALUE
10727 (merge_qualified_name (label_id, EXPR_WFL_NODE (name)))))
10728 /* Null means that we don't have a target for this named
10729 break/continue. In this case, we make the target to be the
10730 label name, so that the error can be reported accuratly in
10731 patch_bc_statement. */
10732 label_block_expr = EXPR_WFL_NODE (name);
10734 /* Unlabeled break/continue will be handled during the
10735 break/continue patch operation */
10737 = build (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr, NULL_TREE);
10739 IS_BREAK_STMT_P (break_continue) = is_break;
10740 TREE_SIDE_EFFECTS (break_continue) = 1;
10741 EXPR_WFL_LINECOL (break_continue) = location;
10742 break_continue = build_debugable_stmt (location, break_continue);
10743 return break_continue;
10746 /* Verification of a break/continue statement. */
10749 patch_bc_statement (node)
10752 tree bc_label = EXIT_BLOCK_LABELED_BLOCK (node), target_stmt;
10753 tree labeled_block = ctxp->current_labeled_block;
10754 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10756 /* Having an identifier here means that the target is unknown. */
10757 if (bc_label != NULL_TREE && TREE_CODE (bc_label) == IDENTIFIER_NODE)
10759 parse_error_context (wfl_operator, "No label definition found for `%s'",
10760 IDENTIFIER_POINTER (bc_label));
10761 return error_mark_node;
10763 if (! IS_BREAK_STMT_P (node))
10765 /* It's a continue statement. */
10766 for (;; labeled_block = TREE_CHAIN (labeled_block))
10768 if (labeled_block == NULL_TREE)
10770 if (bc_label == NULL_TREE)
10771 parse_error_context (wfl_operator,
10772 "`continue' must be in loop");
10774 parse_error_context
10775 (wfl_operator, "continue label `%s' does not name a loop",
10776 IDENTIFIER_POINTER (bc_label));
10777 return error_mark_node;
10779 if ((DECL_NAME (LABELED_BLOCK_LABEL (labeled_block))
10780 == continue_identifier_node)
10781 && (bc_label == NULL_TREE
10782 || TREE_CHAIN (labeled_block) == bc_label))
10784 bc_label = labeled_block;
10789 else if (!bc_label)
10791 for (;; labeled_block = TREE_CHAIN (labeled_block))
10793 if (labeled_block == NULL_TREE)
10795 parse_error_context (wfl_operator,
10796 "`break' must be in loop or switch");
10797 return error_mark_node;
10799 target_stmt = LABELED_BLOCK_BODY (labeled_block);
10800 if (TREE_CODE (target_stmt) == SWITCH_EXPR
10801 || TREE_CODE (target_stmt) == LOOP_EXPR)
10803 bc_label = labeled_block;
10809 EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
10810 CAN_COMPLETE_NORMALLY (bc_label) = 1;
10812 /* Our break/continue don't return values. */
10813 TREE_TYPE (node) = void_type_node;
10814 /* Encapsulate the break within a compound statement so that it's
10815 expanded all the times by expand_expr (and not clobered
10816 sometimes, like after a if statement) */
10817 node = add_stmt_to_compound (NULL_TREE, void_type_node, node);
10818 TREE_SIDE_EFFECTS (node) = 1;
10822 /* Process the exit expression belonging to a loop. Its type must be
10826 patch_exit_expr (node)
10829 tree expression = TREE_OPERAND (node, 0);
10830 TREE_TYPE (node) = error_mark_node;
10831 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10833 /* The type of expression must be boolean */
10834 if (TREE_TYPE (expression) != boolean_type_node)
10836 parse_error_context
10838 "Incompatible type for loop conditional. Can't convert `%s' to "
10840 lang_printable_name (TREE_TYPE (expression), 0));
10841 return error_mark_node;
10843 /* Now we know things are allright, invert the condition, fold and
10845 TREE_OPERAND (node, 0) =
10846 fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
10848 if (! integer_zerop (TREE_OPERAND (node, 0))
10849 && ctxp->current_loop != NULL_TREE
10850 && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
10851 CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
10852 if (! integer_onep (TREE_OPERAND (node, 0)))
10853 CAN_COMPLETE_NORMALLY (node) = 1;
10856 TREE_TYPE (node) = void_type_node;
10860 /* 14.9 Switch statement */
10863 patch_switch_statement (node)
10866 tree se = TREE_OPERAND (node, 0), se_type;
10868 /* Complete the switch expression */
10869 se = TREE_OPERAND (node, 0) = java_complete_tree (se);
10870 se_type = TREE_TYPE (se);
10871 /* The type of the switch expression must be char, byte, short or
10873 if (!JINTEGRAL_TYPE_P (se_type))
10875 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
10876 parse_error_context (wfl_operator, "Incompatible type for `switch'. "
10877 "Can't convert `%s' to `int'",
10878 lang_printable_name (se_type, 0));
10879 /* This is what java_complete_tree will check */
10880 TREE_OPERAND (node, 0) = error_mark_node;
10881 return error_mark_node;
10884 TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
10886 /* Ready to return */
10887 if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
10889 TREE_TYPE (node) = error_mark_node;
10890 return error_mark_node;
10892 TREE_TYPE (node) = void_type_node;
10893 TREE_SIDE_EFFECTS (node) = 1;
10894 CAN_COMPLETE_NORMALLY (node)
10895 = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
10896 || ! SWITCH_HAS_DEFAULT (node);
10900 /* 14.18 The try statement */
10903 build_try_statement (location, try_block, catches)
10905 tree try_block, catches;
10907 tree node = build (TRY_EXPR, NULL_TREE, try_block, catches);
10908 EXPR_WFL_LINECOL (node) = location;
10913 build_try_finally_statement (location, try_block, finally)
10915 tree try_block, finally;
10917 tree node = build (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
10918 EXPR_WFL_LINECOL (node) = location;
10923 patch_try_statement (node)
10926 int error_found = 0;
10927 tree try = TREE_OPERAND (node, 0);
10928 /* Exception handlers are considered in left to right order */
10929 tree catch = nreverse (TREE_OPERAND (node, 1));
10930 tree current, caught_type_list = NULL_TREE;
10932 /* Check catch clauses, if any. Every time we find an error, we try
10933 to process the next catch clause. We process the catch clause before
10934 the try block so that when processing the try block we can check thrown
10935 exceptions againts the caught type list. */
10936 for (current = catch; current; current = TREE_CHAIN (current))
10938 tree carg_decl, carg_type;
10939 tree sub_current, catch_block, catch_clause;
10942 /* At this point, the structure of the catch clause is
10943 CATCH_EXPR (catch node)
10944 BLOCK (with the decl of the parameter)
10946 MODIFY_EXPR (assignment of the catch parameter)
10947 BLOCK (catch clause block)
10949 catch_clause = TREE_OPERAND (current, 0);
10950 carg_decl = BLOCK_EXPR_DECLS (catch_clause);
10951 carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
10953 /* Catch clauses can't have more than one parameter declared,
10954 but it's already enforced by the grammar. Make sure that the
10955 only parameter of the clause statement in of class Throwable
10956 or a subclass of Throwable, but that was done earlier. The
10957 catch clause parameter type has also been resolved. */
10959 /* Just make sure that the catch clause parameter type inherits
10960 from java.lang.Throwable */
10961 if (!inherits_from_p (carg_type, throwable_type_node))
10963 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
10964 parse_error_context (wfl_operator,
10965 "Can't catch class `%s'. Catch clause "
10966 "parameter type must be a subclass of "
10967 "class `java.lang.Throwable'",
10968 lang_printable_name (carg_type, 0));
10973 /* Partial check for unreachable catch statement: The catch
10974 clause is reachable iff is no earlier catch block A in
10975 the try statement such that the type of the catch
10976 clause's parameter is the same as or a subclass of the
10977 type of A's parameter */
10979 for (sub_current = catch;
10980 sub_current != current; sub_current = TREE_CHAIN (sub_current))
10982 tree sub_catch_clause, decl;
10983 sub_catch_clause = TREE_OPERAND (sub_current, 0);
10984 decl = BLOCK_EXPR_DECLS (sub_catch_clause);
10986 if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
10988 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (current);
10989 parse_error_context
10990 (wfl_operator, "`catch' not reached because of the catch "
10991 "clause at line %d", EXPR_WFL_LINENO (sub_current));
10992 unreachable = error_found = 1;
10996 /* Complete the catch clause block */
10997 catch_block = java_complete_tree (TREE_OPERAND (current, 0));
10998 if (catch_block == error_mark_node)
11003 if (CAN_COMPLETE_NORMALLY (catch_block))
11004 CAN_COMPLETE_NORMALLY (node) = 1;
11005 TREE_OPERAND (current, 0) = catch_block;
11010 /* Things to do here: the exception must be thrown */
11012 /* Link this type to the caught type list */
11013 caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
11016 PUSH_EXCEPTIONS (caught_type_list);
11017 if ((try = java_complete_tree (try)) == error_mark_node)
11019 if (CAN_COMPLETE_NORMALLY (try))
11020 CAN_COMPLETE_NORMALLY (node) = 1;
11023 /* Verification ends here */
11025 return error_mark_node;
11027 TREE_OPERAND (node, 0) = try;
11028 TREE_OPERAND (node, 1) = catch;
11029 TREE_TYPE (node) = void_type_node;
11033 /* 14.17 The synchronized Statement */
11036 patch_synchronized_statement (node, wfl_op1)
11037 tree node, wfl_op1;
11039 tree expr = java_complete_tree (TREE_OPERAND (node, 0));
11040 tree block = TREE_OPERAND (node, 1);
11042 tree enter, exit, expr_decl, assignment;
11044 if (expr == error_mark_node)
11046 block = java_complete_tree (block);
11050 /* The TYPE of expr must be a reference type */
11051 if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
11053 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11054 parse_error_context (wfl_operator, "Incompatible type for `synchronized'"
11055 ". Can't convert `%s' to `java.lang.Object'",
11056 lang_printable_name (TREE_TYPE (expr), 0));
11057 return error_mark_node;
11060 /* Generate a try-finally for the synchronized statement, except
11061 that the handler that catches all throw exception calls
11062 _Jv_MonitorExit and then rethrow the exception.
11063 The synchronized statement is then implemented as:
11066 _Jv_MonitorEnter (expression)
11068 _Jv_MonitorExit (expression)
11072 e = _Jv_exception_info ();
11073 _Jv_MonitorExit (expression)
11077 expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
11078 BUILD_MONITOR_ENTER (enter, expr_decl);
11079 BUILD_MONITOR_EXIT (exit, expr_decl);
11080 CAN_COMPLETE_NORMALLY (enter) = 1;
11081 CAN_COMPLETE_NORMALLY (exit) = 1;
11082 assignment = build (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
11083 TREE_SIDE_EFFECTS (assignment) = 1;
11084 node = build1 (CLEANUP_POINT_EXPR, NULL_TREE,
11085 build (COMPOUND_EXPR, NULL_TREE,
11086 build (WITH_CLEANUP_EXPR, NULL_TREE,
11087 build (COMPOUND_EXPR, NULL_TREE,
11088 assignment, enter),
11091 node = build_expr_block (node, expr_decl);
11093 return java_complete_tree (node);
11096 /* 14.16 The throw Statement */
11099 patch_throw_statement (node, wfl_op1)
11100 tree node, wfl_op1;
11102 tree expr = TREE_OPERAND (node, 0);
11103 tree type = TREE_TYPE (expr);
11104 int unchecked_ok = 0, tryblock_throws_ok = 0;
11106 /* Thrown expression must be assignable to java.lang.Throwable */
11107 if (!try_reference_assignconv (throwable_type_node, expr))
11109 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11110 parse_error_context (wfl_operator, "Can't throw `%s'; it must be a "
11111 "subclass of class `java.lang.Throwable'",
11112 lang_printable_name (type, 0));
11113 /* If the thrown expression was a reference, we further the
11114 compile-time check. */
11115 if (!JREFERENCE_TYPE_P (type))
11116 return error_mark_node;
11119 /* At least one of the following must be true */
11121 /* The type of the throw expression is a not checked exception,
11122 i.e. is a unchecked expression. */
11123 unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
11125 /* Throw is contained in a try statement and at least one catch
11126 clause can receive the thrown expression or the current method is
11127 declared to throw such an exception. Or, the throw statement is
11128 contained in a method or constructor declaration and the type of
11129 the Expression is assignable to at least one type listed in the
11130 throws clause the declaration. */
11131 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11133 tryblock_throws_ok = check_thrown_exceptions_do (TREE_TYPE (expr));
11134 if (!(unchecked_ok || tryblock_throws_ok))
11136 /* If there is a surrounding try block that has no matching
11137 clatch clause, report it first. A surrounding try block exits
11138 only if there is something after the list of checked
11139 exception thrown by the current function (if any). */
11140 if (IN_TRY_BLOCK_P ())
11141 parse_error_context (wfl_operator, "Checked exception `%s' can't be "
11142 "caught by any of the catch clause(s) "
11143 "of the surrounding `try' block",
11144 lang_printable_name (type, 0));
11145 /* If we have no surrounding try statement and the method doesn't have
11146 any throws, report it now. FIXME */
11148 /* We report that the exception can't be throw from a try block
11149 in all circumstances but when the `throw' is inside a static
11151 else if (!EXCEPTIONS_P (currently_caught_type_list)
11152 && !tryblock_throws_ok)
11154 if (IS_CLINIT (current_function_decl))
11155 parse_error_context (wfl_operator, "Checked exception `%s' can't "
11156 "be thrown in initializer",
11157 lang_printable_name (type, 0));
11159 parse_error_context (wfl_operator, "Checked exception `%s' isn't "
11160 "thrown from a `try' block",
11161 lang_printable_name (type, 0));
11163 /* Otherwise, the current method doesn't have the appropriate
11164 throws declaration */
11166 parse_error_context (wfl_operator, "Checked exception `%s' doesn't "
11167 "match any of current method's `throws' "
11169 lang_printable_name (type, 0));
11170 return error_mark_node;
11173 if (! flag_emit_class_files)
11174 BUILD_THROW (node, expr);
11178 /* Check that exception said to be thrown by method DECL can be
11179 effectively caught from where DECL is invoked. */
11182 check_thrown_exceptions (location, decl)
11187 /* For all the unchecked exceptions thrown by DECL */
11188 for (throws = DECL_FUNCTION_THROWS (decl); throws;
11189 throws = TREE_CHAIN (throws))
11190 if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
11193 /* Temporary hack to suppresses errors about cloning arrays. FIXME */
11194 if (DECL_NAME (decl) == get_identifier ("clone"))
11197 EXPR_WFL_LINECOL (wfl_operator) = location;
11198 parse_error_context
11199 (wfl_operator, "Exception `%s' must be caught, or it must be "
11200 "declared in the `throws' clause of `%s'",
11201 lang_printable_name (TREE_VALUE (throws), 0),
11202 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
11206 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
11207 try-catch blocks, OR is listed in the `throws' clause of the
11211 check_thrown_exceptions_do (exception)
11214 tree list = currently_caught_type_list;
11215 resolve_and_layout (exception, NULL_TREE);
11216 /* First, all the nested try-catch-finally at that stage. The
11217 last element contains `throws' clause exceptions, if any. */
11218 if (IS_UNCHECKED_EXCEPTION_P (exception))
11223 for (caught = TREE_VALUE (list); caught; caught = TREE_CHAIN (caught))
11224 if (valid_ref_assignconv_cast_p (exception, TREE_VALUE (caught), 0))
11226 list = TREE_CHAIN (list);
11232 purge_unchecked_exceptions (mdecl)
11235 tree throws = DECL_FUNCTION_THROWS (mdecl);
11236 tree new = NULL_TREE;
11240 tree next = TREE_CHAIN (throws);
11241 if (!IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (throws)))
11243 TREE_CHAIN (throws) = new;
11248 /* List is inverted here, but it doesn't matter */
11249 DECL_FUNCTION_THROWS (mdecl) = new;
11252 /* 15.24 Conditional Operator ?: */
11255 patch_conditional_expr (node, wfl_cond, wfl_op1)
11256 tree node, wfl_cond, wfl_op1;
11258 tree cond = TREE_OPERAND (node, 0);
11259 tree op1 = TREE_OPERAND (node, 1);
11260 tree op2 = TREE_OPERAND (node, 2);
11261 tree resulting_type = NULL_TREE;
11262 tree t1, t2, patched;
11263 int error_found = 0;
11265 /* Operands of ?: might be StringBuffers crafted as a result of a
11266 string concatenation. Obtain a descent operand here. */
11267 if ((patched = patch_string (op1)))
11268 TREE_OPERAND (node, 1) = op1 = patched;
11269 if ((patched = patch_string (op2)))
11270 TREE_OPERAND (node, 2) = op2 = patched;
11272 t1 = TREE_TYPE (op1);
11273 t2 = TREE_TYPE (op2);
11275 /* The first expression must be a boolean */
11276 if (TREE_TYPE (cond) != boolean_type_node)
11278 SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
11279 parse_error_context (wfl_operator, "Incompatible type for `?:'. Can't "
11280 "convert `%s' to `boolean'",
11281 lang_printable_name (TREE_TYPE (cond), 0));
11285 /* Second and third can be numeric, boolean (i.e. primitive),
11286 references or null. Anything else results in an error */
11287 if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
11288 || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node)
11289 && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
11290 || (t1 == boolean_type_node && t2 == boolean_type_node)))
11293 /* Determine the type of the conditional expression. Same types are
11294 easy to deal with */
11296 resulting_type = t1;
11298 /* There are different rules for numeric types */
11299 else if (JNUMERIC_TYPE_P (t1))
11301 /* if byte/short found, the resulting type is short */
11302 if ((t1 == byte_type_node && t2 == short_type_node)
11303 || (t1 == short_type_node && t2 == byte_type_node))
11304 resulting_type = short_type_node;
11306 /* If t1 is a constant int and t2 is of type byte, short or char
11307 and t1's value fits in t2, then the resulting type is t2 */
11308 else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
11309 && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
11310 resulting_type = t2;
11312 /* If t2 is a constant int and t1 is of type byte, short or char
11313 and t2's value fits in t1, then the resulting type is t1 */
11314 else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
11315 && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
11316 resulting_type = t1;
11318 /* Otherwise, binary numeric promotion is applied and the
11319 resulting type is the promoted type of operand 1 and 2 */
11321 resulting_type = binary_numeric_promotion (t2, t2,
11322 &TREE_OPERAND (node, 1),
11323 &TREE_OPERAND (node, 2));
11326 /* Cases of a reference and a null type */
11327 else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
11328 resulting_type = t1;
11330 else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
11331 resulting_type = t2;
11333 /* Last case: different reference types. If a type can be converted
11334 into the other one by assignment conversion, the latter
11335 determines the type of the expression */
11336 else if ((resulting_type = try_reference_assignconv (t1, op2)))
11337 resulting_type = promote_type (t1);
11339 else if ((resulting_type = try_reference_assignconv (t2, op1)))
11340 resulting_type = promote_type (t2);
11342 /* If we don't have any resulting type, we're in trouble */
11343 if (!resulting_type)
11345 char *t = strdup (lang_printable_name (t1, 0));
11346 SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
11347 parse_error_context (wfl_operator, "Incompatible type for `?:'. Can't "
11348 "convert `%s' to `%s'", t,
11349 lang_printable_name (t2, 0));
11356 TREE_TYPE (node) = error_mark_node;
11357 return error_mark_node;
11360 TREE_TYPE (node) = resulting_type;
11361 TREE_SET_CODE (node, COND_EXPR);
11362 CAN_COMPLETE_NORMALLY (node) = 1;
11366 /* Try to constant fold NODE.
11367 If NODE is not a constant expression, return NULL_EXPR.
11368 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
11371 fold_constant_for_init (node, context)
11375 tree op0, op1, val;
11376 enum tree_code code = TREE_CODE (node);
11378 if (code == INTEGER_CST || code == REAL_CST || code == STRING_CST)
11380 if (TREE_TYPE (node) != NULL_TREE)
11388 case TRUNC_MOD_EXPR:
11396 case TRUTH_ANDIF_EXPR:
11397 case TRUTH_ORIF_EXPR:
11404 op0 = TREE_OPERAND (node, 0);
11405 op1 = TREE_OPERAND (node, 1);
11406 val = fold_constant_for_init (op0, context);
11407 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11409 TREE_OPERAND (node, 0) = val;
11410 val = fold_constant_for_init (op1, context);
11411 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11413 TREE_OPERAND (node, 1) = val;
11414 return patch_binop (node, op0, op1);
11416 case UNARY_PLUS_EXPR:
11418 case TRUTH_NOT_EXPR:
11421 op0 = TREE_OPERAND (node, 0);
11422 val = fold_constant_for_init (op0, context);
11423 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11425 TREE_OPERAND (node, 0) = val;
11426 return patch_unaryop (node, op0);
11430 val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
11431 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11433 TREE_OPERAND (node, 0) = val;
11434 val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
11435 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11437 TREE_OPERAND (node, 1) = val;
11438 val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
11439 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11441 TREE_OPERAND (node, 2) = val;
11442 return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
11443 : TREE_OPERAND (node, 2);
11446 if (! FIELD_STATIC (node) || ! FIELD_FINAL (node)
11447 || DECL_INITIAL (node) == NULL_TREE)
11449 val = DECL_INITIAL (node);
11450 /* Guard against infinite recursion. */
11451 DECL_INITIAL (node) = NULL_TREE;
11452 val = fold_constant_for_init (val, DECL_CONTEXT (node));
11453 DECL_INITIAL (node) = val;
11456 case EXPR_WITH_FILE_LOCATION:
11457 /* Compare java_complete_tree and resolve_expression_name. */
11458 if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
11459 || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
11461 tree name = EXPR_WFL_NODE (node);
11463 if (PRIMARY_P (node))
11465 else if (! QUALIFIED_P (name))
11467 decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
11468 if (! FIELD_STATIC (decl))
11470 return fold_constant_for_init (decl, decl);
11475 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
11476 qualify_ambiguous_name (node);
11477 if (resolve_field_access (node, &decl, NULL)
11478 && decl != NULL_TREE)
11479 return fold_constant_for_init (decl, decl);
11486 op0 = TREE_OPERAND (node, 0);
11487 val = fold_constant_for_init (op0, context);
11488 if (val == NULL_TREE || ! TREE_CONSTANT (val))
11490 TREE_OPERAND (node, 0) = val;
11494 #ifdef USE_COMPONENT_REF
11496 case COMPONENT_REF:
11505 #ifdef USE_COMPONENT_REF
11506 /* Context is 'T' for TypeName, 'P' for PackageName,
11507 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
11510 resolve_simple_name (name, context)
11517 resolve_qualified_name (name, context)