1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* This file parses java source code and issues a tree node image
28 suitable for code generation (byte code and targeted CPU assembly
31 The grammar conforms to the Java grammar described in "The Java(TM)
32 Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
33 1996, ISBN 0-201-63451-1"
35 The following modifications were brought to the original grammar:
37 method_body: added the rule '| block SC_TK'
38 static_initializer: added the rule 'static block SC_TK'.
40 Note: All the extra rules described above should go away when the
41 empty_statement rule will work.
43 statement_nsi: 'nsi' should be read no_short_if.
45 Some rules have been modified to support JDK1.1 inner classes
46 definitions and other extensions. */
57 #include "java-tree.h"
70 #define DIR_SEPARATOR '/'
73 /* Local function prototypes */
74 static char *java_accstring_lookup PARAMS
((int));
75 static void classitf_redefinition_error PARAMS
((const char *,tree
, tree
, tree
));
76 static void variable_redefinition_error PARAMS
((tree
, tree
, tree
, int));
77 static tree create_class PARAMS
((int, tree
, tree
, tree
));
78 static tree create_interface PARAMS
((int, tree
, tree
));
79 static void end_class_declaration PARAMS
((int));
80 static tree find_field PARAMS
((tree
, tree
));
81 static tree lookup_field_wrapper PARAMS
((tree
, tree
));
82 static int duplicate_declaration_error_p PARAMS
((tree
, tree
, tree
));
83 static void register_fields PARAMS
((int, tree
, tree
));
84 static tree parser_qualified_classname PARAMS
((tree
));
85 static int parser_check_super PARAMS
((tree
, tree
, tree
));
86 static int parser_check_super_interface PARAMS
((tree
, tree
, tree
));
87 static void check_modifiers_consistency PARAMS
((int));
88 static tree lookup_cl PARAMS
((tree
));
89 static tree lookup_java_method2 PARAMS
((tree
, tree
, int));
90 static tree method_header PARAMS
((int, tree
, tree
, tree
));
91 static void fix_method_argument_names PARAMS
((tree
,tree
));
92 static tree method_declarator PARAMS
((tree
, tree
));
93 static void parse_warning_context PARAMS
((tree cl
, const char *msg
, ...
))
95 static void issue_warning_error_from_context PARAMS
((tree
, const char *msg
, va_list))
96 ATTRIBUTE_PRINTF
(2, 0);
97 static void parse_ctor_invocation_error PARAMS
((void));
98 static tree parse_jdk1_1_error PARAMS
((const char *));
99 static void complete_class_report_errors PARAMS
((jdep
*));
100 static int process_imports PARAMS
((void));
101 static void read_import_dir PARAMS
((tree
));
102 static int find_in_imports_on_demand PARAMS
((tree
));
103 static void find_in_imports PARAMS
((tree
));
104 static void check_static_final_variable_assignment_flag PARAMS
((tree
));
105 static void reset_static_final_variable_assignment_flag PARAMS
((tree
));
106 static void check_final_variable_local_assignment_flag PARAMS
((tree
, tree
));
107 static void reset_final_variable_local_assignment_flag PARAMS
((tree
));
108 static int check_final_variable_indirect_assignment PARAMS
((tree
));
109 static void check_final_variable_global_assignment_flag PARAMS
((tree
));
110 static void check_inner_class_access PARAMS
((tree
, tree
, tree
));
111 static int check_pkg_class_access PARAMS
((tree
, tree
));
112 static void register_package PARAMS
((tree
));
113 static tree resolve_package PARAMS
((tree
, tree
*));
114 static tree lookup_package_type PARAMS
((const char *, int));
115 static tree resolve_class PARAMS
((tree
, tree
, tree
, tree
));
116 static void declare_local_variables PARAMS
((int, tree
, tree
));
117 static void source_start_java_method PARAMS
((tree
));
118 static void source_end_java_method PARAMS
((void));
119 static tree find_name_in_single_imports PARAMS
((tree
));
120 static void check_abstract_method_header PARAMS
((tree
));
121 static tree lookup_java_interface_method2 PARAMS
((tree
, tree
));
122 static tree resolve_expression_name PARAMS
((tree
, tree
*));
123 static tree maybe_create_class_interface_decl PARAMS
((tree
, tree
, tree
, tree
));
124 static int check_class_interface_creation PARAMS
((int, int, tree
,
126 static tree patch_method_invocation PARAMS
((tree
, tree
, tree
, int,
128 static int breakdown_qualified PARAMS
((tree
*, tree
*, tree
));
129 static int in_same_package PARAMS
((tree
, tree
));
130 static tree resolve_and_layout PARAMS
((tree
, tree
));
131 static tree qualify_and_find PARAMS
((tree
, tree
, tree
));
132 static tree resolve_no_layout PARAMS
((tree
, tree
));
133 static int invocation_mode PARAMS
((tree
, int));
134 static tree find_applicable_accessible_methods_list PARAMS
((int, tree
,
136 static void search_applicable_methods_list PARAMS
((int, tree
, tree
, tree
,
138 static tree find_most_specific_methods_list PARAMS
((tree
));
139 static int argument_types_convertible PARAMS
((tree
, tree
));
140 static tree patch_invoke PARAMS
((tree
, tree
, tree
));
141 static int maybe_use_access_method PARAMS
((int, tree
*, tree
*));
142 static tree lookup_method_invoke PARAMS
((int, tree
, tree
, tree
, tree
));
143 static tree register_incomplete_type PARAMS
((int, tree
, tree
, tree
));
144 static tree obtain_incomplete_type PARAMS
((tree
));
145 static tree java_complete_lhs PARAMS
((tree
));
146 static tree java_complete_tree PARAMS
((tree
));
147 static tree maybe_generate_pre_expand_clinit PARAMS
((tree
));
148 static int analyze_clinit_body PARAMS
((tree
));
149 static int maybe_yank_clinit PARAMS
((tree
));
150 static void java_complete_expand_method PARAMS
((tree
));
151 static int unresolved_type_p PARAMS
((tree
, tree
*));
152 static void create_jdep_list PARAMS
((struct parser_ctxt
*));
153 static tree build_expr_block PARAMS
((tree
, tree
));
154 static tree enter_block PARAMS
((void));
155 static tree exit_block PARAMS
((void));
156 static tree lookup_name_in_blocks PARAMS
((tree
));
157 static void maybe_absorb_scoping_blocks PARAMS
((void));
158 static tree build_method_invocation PARAMS
((tree
, tree
));
159 static tree build_new_invocation PARAMS
((tree
, tree
));
160 static tree build_assignment PARAMS
((int, int, tree
, tree
));
161 static tree build_binop PARAMS
((enum tree_code
, int, tree
, tree
));
162 static int check_final_assignment PARAMS
((tree
,tree
));
163 static tree patch_assignment PARAMS
((tree
, tree
, tree
));
164 static tree patch_binop PARAMS
((tree
, tree
, tree
));
165 static tree build_unaryop PARAMS
((int, int, tree
));
166 static tree build_incdec PARAMS
((int, int, tree
, int));
167 static tree patch_unaryop PARAMS
((tree
, tree
));
168 static tree build_cast PARAMS
((int, tree
, tree
));
169 static tree build_null_of_type PARAMS
((tree
));
170 static tree patch_cast PARAMS
((tree
, tree
));
171 static int valid_ref_assignconv_cast_p PARAMS
((tree
, tree
, int));
172 static int valid_builtin_assignconv_identity_widening_p PARAMS
((tree
, tree
));
173 static int valid_cast_to_p PARAMS
((tree
, tree
));
174 static int valid_method_invocation_conversion_p PARAMS
((tree
, tree
));
175 static tree try_builtin_assignconv PARAMS
((tree
, tree
, tree
));
176 static tree try_reference_assignconv PARAMS
((tree
, tree
));
177 static tree build_unresolved_array_type PARAMS
((tree
));
178 static tree build_array_from_name PARAMS
((tree
, tree
, tree
, tree
*));
179 static tree build_array_ref PARAMS
((int, tree
, tree
));
180 static tree patch_array_ref PARAMS
((tree
));
181 static tree make_qualified_name PARAMS
((tree
, tree
, int));
182 static tree merge_qualified_name PARAMS
((tree
, tree
));
183 static tree make_qualified_primary PARAMS
((tree
, tree
, int));
184 static int resolve_qualified_expression_name PARAMS
((tree
, tree
*,
186 static void qualify_ambiguous_name PARAMS
((tree
));
187 static tree resolve_field_access PARAMS
((tree
, tree
*, tree
*));
188 static tree build_newarray_node PARAMS
((tree
, tree
, int));
189 static tree patch_newarray PARAMS
((tree
));
190 static tree resolve_type_during_patch PARAMS
((tree
));
191 static tree build_this PARAMS
((int));
192 static tree build_wfl_wrap PARAMS
((tree
, int));
193 static tree build_return PARAMS
((int, tree
));
194 static tree patch_return PARAMS
((tree
));
195 static tree maybe_access_field PARAMS
((tree
, tree
, tree
));
196 static int complete_function_arguments PARAMS
((tree
));
197 static int check_for_static_method_reference PARAMS
((tree
, tree
, tree
,
199 static int not_accessible_p PARAMS
((tree
, tree
, tree
, int));
200 static void check_deprecation PARAMS
((tree
, tree
));
201 static int class_in_current_package PARAMS
((tree
));
202 static tree build_if_else_statement PARAMS
((int, tree
, tree
, tree
));
203 static tree patch_if_else_statement PARAMS
((tree
));
204 static tree add_stmt_to_compound PARAMS
((tree
, tree
, tree
));
205 static tree add_stmt_to_block PARAMS
((tree
, tree
, tree
));
206 static tree patch_exit_expr PARAMS
((tree
));
207 static tree build_labeled_block PARAMS
((int, tree
));
208 static tree finish_labeled_statement PARAMS
((tree
, tree
));
209 static tree build_bc_statement PARAMS
((int, int, tree
));
210 static tree patch_bc_statement PARAMS
((tree
));
211 static tree patch_loop_statement PARAMS
((tree
));
212 static tree build_new_loop PARAMS
((tree
));
213 static tree build_loop_body PARAMS
((int, tree
, int));
214 static tree finish_loop_body PARAMS
((int, tree
, tree
, int));
215 static tree build_debugable_stmt PARAMS
((int, tree
));
216 static tree finish_for_loop PARAMS
((int, tree
, tree
, tree
));
217 static tree patch_switch_statement PARAMS
((tree
));
218 static tree string_constant_concatenation PARAMS
((tree
, tree
));
219 static tree build_string_concatenation PARAMS
((tree
, tree
));
220 static tree patch_string_cst PARAMS
((tree
));
221 static tree patch_string PARAMS
((tree
));
222 static tree build_try_statement PARAMS
((int, tree
, tree
));
223 static tree build_try_finally_statement PARAMS
((int, tree
, tree
));
224 static tree patch_try_statement PARAMS
((tree
));
225 static tree patch_synchronized_statement PARAMS
((tree
, tree
));
226 static tree patch_throw_statement PARAMS
((tree
, tree
));
227 static void check_thrown_exceptions PARAMS
((int, tree
));
228 static int check_thrown_exceptions_do PARAMS
((tree
));
229 static void purge_unchecked_exceptions PARAMS
((tree
));
230 static void check_throws_clauses PARAMS
((tree
, tree
, tree
));
231 static void finish_method_declaration PARAMS
((tree
));
232 static tree build_super_invocation PARAMS
((tree
));
233 static int verify_constructor_circularity PARAMS
((tree
, tree
));
234 static char *constructor_circularity_msg PARAMS
((tree
, tree
));
235 static tree build_this_super_qualified_invocation PARAMS
((int, tree
, tree
,
237 static const char *get_printable_method_name PARAMS
((tree
));
238 static tree patch_conditional_expr PARAMS
((tree
, tree
, tree
));
239 static tree generate_finit PARAMS
((tree
));
240 static void add_instance_initializer PARAMS
((tree
));
241 static void fix_constructors PARAMS
((tree
));
242 static tree build_alias_initializer_parameter_list PARAMS
((int, tree
,
244 static void craft_constructor PARAMS
((tree
, tree
));
245 static int verify_constructor_super PARAMS
((tree
));
246 static tree create_artificial_method PARAMS
((tree
, int, tree
, tree
, tree
));
247 static void start_artificial_method_body PARAMS
((tree
));
248 static void end_artificial_method_body PARAMS
((tree
));
249 static int check_method_redefinition PARAMS
((tree
, tree
));
250 static int check_method_types_complete PARAMS
((tree
));
251 static void java_check_regular_methods PARAMS
((tree
));
252 static void java_check_abstract_methods PARAMS
((tree
));
253 static tree maybe_build_primttype_type_ref PARAMS
((tree
, tree
));
254 static void unreachable_stmt_error PARAMS
((tree
));
255 static tree find_expr_with_wfl PARAMS
((tree
));
256 static void missing_return_error PARAMS
((tree
));
257 static tree build_new_array_init PARAMS
((int, tree
));
258 static tree patch_new_array_init PARAMS
((tree
, tree
));
259 static tree maybe_build_array_element_wfl PARAMS
((tree
));
260 static int array_constructor_check_entry PARAMS
((tree
, tree
));
261 static const char *purify_type_name PARAMS
((const char *));
262 static tree fold_constant_for_init PARAMS
((tree
, tree
));
263 static tree strip_out_static_field_access_decl PARAMS
((tree
));
264 static jdeplist
*reverse_jdep_list PARAMS
((struct parser_ctxt
*));
265 static void static_ref_err PARAMS
((tree
, tree
, tree
));
266 static void parser_add_interface PARAMS
((tree
, tree
, tree
));
267 static void add_superinterfaces PARAMS
((tree
, tree
));
268 static tree jdep_resolve_class PARAMS
((jdep
*));
269 static int note_possible_classname PARAMS
((const char *, int));
270 static void java_complete_expand_classes PARAMS
((void));
271 static void java_complete_expand_class PARAMS
((tree
));
272 static void java_complete_expand_methods PARAMS
((tree
));
273 static tree cut_identifier_in_qualified PARAMS
((tree
));
274 static tree java_stabilize_reference PARAMS
((tree
));
275 static tree do_unary_numeric_promotion PARAMS
((tree
));
276 static char * operator_string PARAMS
((tree
));
277 static tree do_merge_string_cste PARAMS
((tree
, const char *, int, int));
278 static tree merge_string_cste PARAMS
((tree
, tree
, int));
279 static tree java_refold PARAMS
((tree
));
280 static int java_decl_equiv PARAMS
((tree
, tree
));
281 static int binop_compound_p PARAMS
((enum tree_code
));
282 static tree search_loop PARAMS
((tree
));
283 static int labeled_block_contains_loop_p PARAMS
((tree
, tree
));
284 static int check_abstract_method_definitions PARAMS
((int, tree
, tree
));
285 static void java_check_abstract_method_definitions PARAMS
((tree
));
286 static void java_debug_context_do PARAMS
((int));
287 static void java_parser_context_push_initialized_field PARAMS
((void));
288 static void java_parser_context_pop_initialized_field PARAMS
((void));
289 static tree reorder_static_initialized PARAMS
((tree
));
290 static void java_parser_context_suspend PARAMS
((void));
291 static void java_parser_context_resume PARAMS
((void));
292 static int pop_current_osb PARAMS
((struct parser_ctxt
*));
294 /* JDK 1.1 work. FIXME */
296 static tree maybe_make_nested_class_name PARAMS
((tree
));
297 static void make_nested_class_name PARAMS
((tree
));
298 static void set_nested_class_simple_name_value PARAMS
((tree
, int));
299 static void link_nested_class_to_enclosing PARAMS
((void));
300 static tree find_as_inner_class PARAMS
((tree
, tree
, tree
));
301 static tree find_as_inner_class_do PARAMS
((tree
, tree
));
302 static int check_inner_class_redefinition PARAMS
((tree
, tree
));
304 static tree build_thisn_assign PARAMS
((void));
305 static tree build_current_thisn PARAMS
((tree
));
306 static tree build_access_to_thisn PARAMS
((tree
, tree
, int));
307 static tree maybe_build_thisn_access_method PARAMS
((tree
));
309 static tree build_outer_field_access PARAMS
((tree
, tree
));
310 static tree build_outer_field_access_methods PARAMS
((tree
));
311 static tree build_outer_field_access_expr PARAMS
((int, tree
, tree
,
313 static tree build_outer_method_access_method PARAMS
((tree
));
314 static tree build_new_access_id PARAMS
((void));
315 static tree build_outer_field_access_method PARAMS
((tree
, tree
, tree
,
318 static int outer_field_access_p PARAMS
((tree
, tree
));
319 static int outer_field_expanded_access_p PARAMS
((tree
, tree
*,
321 static tree outer_field_access_fix PARAMS
((tree
, tree
, tree
));
322 static tree build_incomplete_class_ref PARAMS
((int, tree
));
323 static tree patch_incomplete_class_ref PARAMS
((tree
));
324 static tree create_anonymous_class PARAMS
((int, tree
));
325 static void patch_anonymous_class PARAMS
((tree
, tree
, tree
));
326 static void add_inner_class_fields PARAMS
((tree
, tree
));
328 static tree build_dot_class_method PARAMS
((tree
));
329 static tree build_dot_class_method_invocation PARAMS
((tree
));
330 static void create_new_parser_context PARAMS
((int));
331 static void mark_parser_ctxt PARAMS
((void *));
332 static tree maybe_build_class_init_for_field PARAMS
((tree
, tree
));
334 /* Number of error found so far. */
335 int java_error_count
;
336 /* Number of warning found so far. */
337 int java_warning_count
;
338 /* Tell when not to fold, when doing xrefs */
340 /* Cyclic inheritance report, as it can be set by layout_class */
341 const char *cyclic_inheritance_report
;
343 /* Tell when we're within an instance initializer */
344 static int in_instance_initializer
;
346 /* The current parser context */
347 struct parser_ctxt
*ctxp
;
349 /* List of things that were analyzed for which code will be generated */
350 struct parser_ctxt
*ctxp_for_generation
= NULL
;
352 /* binop_lookup maps token to tree_code. It is used where binary
353 operations are involved and required by the parser. RDIV_EXPR
354 covers both integral/floating point division. The code is changed
355 once the type of both operator is worked out. */
357 static enum tree_code binop_lookup
[19] =
359 PLUS_EXPR
, MINUS_EXPR
, MULT_EXPR
, RDIV_EXPR
, TRUNC_MOD_EXPR
,
360 LSHIFT_EXPR
, RSHIFT_EXPR
, URSHIFT_EXPR
,
361 BIT_AND_EXPR
, BIT_XOR_EXPR
, BIT_IOR_EXPR
,
362 TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
,
363 EQ_EXPR
, NE_EXPR
, GT_EXPR
, GE_EXPR
, LT_EXPR
, LE_EXPR
,
365 #define BINOP_LOOKUP(VALUE) \
366 binop_lookup
[((VALUE
) - PLUS_TK
) % ARRAY_SIZE
(binop_lookup
)]
368 /* This is the end index for binary operators that can also be used
369 in compound assignements. */
370 #define BINOP_COMPOUND_CANDIDATES 11
372 /* The "$L" identifier we use to create labels. */
373 static tree label_id
= NULL_TREE
;
375 /* The "StringBuffer" identifier used for the String `+' operator. */
376 static tree wfl_string_buffer
= NULL_TREE
;
378 /* The "append" identifier used for String `+' operator. */
379 static tree wfl_append
= NULL_TREE
;
381 /* The "toString" identifier used for String `+' operator. */
382 static tree wfl_to_string
= NULL_TREE
;
384 /* The "java.lang" import qualified name. */
385 static tree java_lang_id
= NULL_TREE
;
387 /* The generated `inst$' identifier used for generated enclosing
388 instance/field access functions. */
389 static tree inst_id
= NULL_TREE
;
391 /* The "java.lang.Cloneable" qualified name. */
392 static tree java_lang_cloneable
= NULL_TREE
;
394 /* The "java.io.Serializable" qualified name. */
395 static tree java_io_serializable
= NULL_TREE
;
397 /* Context and flag for static blocks */
398 static tree current_static_block
= NULL_TREE
;
400 /* The generated `write_parm_value$' identifier. */
403 /* The list of all packages we've seen so far */
404 static tree package_list
= NULL_TREE
;
406 /* Hold THIS for the scope of the current public method decl. */
407 static tree current_this
;
409 /* Hold a list of catch clauses list. The first element of this list is
410 the list of the catch clauses of the currently analysed try block. */
411 static tree currently_caught_type_list
;
413 static tree src_parse_roots
[1] = { NULL_TREE
};
415 /* All classes seen from source code */
416 #define gclass_list src_parse_roots[0]
418 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
419 line and point it out. */
420 /* Should point out the one that don't fit. ASCII/unicode, going
423 #define check_modifiers(__message, __value, __mask) do { \
424 if
((__value
) & ~
(__mask
)) \
426 int i
, remainder
= (__value
) & ~
(__mask
); \
427 for
(i
= 0; i
<= 10; i
++) \
428 if
((1 << i
) & remainder
) \
429 parse_error_context
(ctxp
->modifier_ctx
[i
], (__message
), \
430 java_accstring_lookup
(1 << i
)); \
452 /* Things defined here have to match the order of what's in the
453 binop_lookup table. */
455 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
456 %token LS_TK SRS_TK ZRS_TK
457 %token AND_TK XOR_TK OR_TK
458 %token BOOL_AND_TK BOOL_OR_TK
459 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
461 /* This maps to the same binop_lookup entry than the token above */
463 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
465 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
466 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
469 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
471 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
472 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
473 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
474 %token PAD_TK ABSTRACT_TK MODIFIER_TK
477 /* Keep those two in order, too */
478 %token DECR_TK INCR_TK
480 /* From now one, things can be in any order */
482 %token DEFAULT_TK IF_TK THROW_TK
483 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
484 %token THROWS_TK BREAK_TK IMPORT_TK
485 %token ELSE_TK INSTANCEOF_TK RETURN_TK
486 %token VOID_TK CATCH_TK INTERFACE_TK
487 %token CASE_TK EXTENDS_TK FINALLY_TK
488 %token SUPER_TK WHILE_TK CLASS_TK
489 %token SWITCH_TK CONST_TK TRY_TK
490 %token FOR_TK NEW_TK CONTINUE_TK
491 %token GOTO_TK PACKAGE_TK THIS_TK
493 %token BYTE_TK SHORT_TK INT_TK LONG_TK
494 %token CHAR_TK INTEGRAL_TK
496 %token FLOAT_TK DOUBLE_TK FP_TK
500 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
502 %token ASSIGN_ANY_TK ASSIGN_TK
503 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
505 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
506 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
508 %type
<value
> modifiers MODIFIER_TK final synchronized
510 %type
<node
> super ID_TK identifier
511 %type
<node
> name simple_name qualified_name
512 %type
<node
> type_declaration compilation_unit
513 field_declaration method_declaration extends_interfaces
514 interfaces interface_type_list
515 class_member_declaration
516 import_declarations package_declaration
517 type_declarations interface_body
518 interface_member_declaration constant_declaration
519 interface_member_declarations interface_type
520 abstract_method_declaration interface_type_list
521 %type
<node
> class_body_declaration class_member_declaration
522 static_initializer constructor_declaration block
523 %type
<node
> class_body_declarations constructor_header
524 %type
<node
> class_or_interface_type class_type class_type_list
525 constructor_declarator explicit_constructor_invocation
526 %type
<node
> dim_expr dim_exprs this_or_super throws
528 %type
<node
> variable_declarator_id variable_declarator
529 variable_declarators variable_initializer
530 variable_initializers constructor_body
533 %type
<node
> class_body block_end constructor_block_end
534 %type
<node
> statement statement_without_trailing_substatement
535 labeled_statement if_then_statement label_decl
536 if_then_else_statement while_statement for_statement
537 statement_nsi labeled_statement_nsi do_statement
538 if_then_else_statement_nsi while_statement_nsi
539 for_statement_nsi statement_expression_list for_init
540 for_update statement_expression expression_statement
541 primary_no_new_array expression primary
542 array_creation_expression array_type
543 class_instance_creation_expression field_access
544 method_invocation array_access something_dot_new
545 argument_list postfix_expression while_expression
546 post_increment_expression post_decrement_expression
547 unary_expression_not_plus_minus unary_expression
548 pre_increment_expression pre_decrement_expression
549 unary_expression_not_plus_minus cast_expression
550 multiplicative_expression additive_expression
551 shift_expression relational_expression
552 equality_expression and_expression
553 exclusive_or_expression inclusive_or_expression
554 conditional_and_expression conditional_or_expression
555 conditional_expression assignment_expression
556 left_hand_side assignment for_header for_begin
557 constant_expression do_statement_begin empty_statement
558 switch_statement synchronized_statement throw_statement
559 try_statement switch_expression switch_block
560 catches catch_clause catch_clause_parameter finally
561 anonymous_class_creation
562 %type
<node
> return_statement break_statement continue_statement
564 %type
<operator
> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
565 %type
<operator
> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
566 %type
<operator
> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
567 %type
<operator
> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
568 %type
<operator
> ASSIGN_ANY_TK assignment_operator
569 %token
<operator
> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
570 %token
<operator
> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
571 %token
<operator
> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
572 %token
<operator
> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
573 %token
<operator
> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
574 %type
<operator
> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
575 %type
<operator
> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
576 %type
<operator
> NEW_TK
578 %type
<node
> method_body
580 %type
<node
> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
581 STRING_LIT_TK NULL_TK VOID_TK
583 %type
<node
> IF_TK WHILE_TK FOR_TK
585 %type
<node
> formal_parameter_list formal_parameter
586 method_declarator method_header
588 %type
<node
> primitive_type reference_type type
589 BOOLEAN_TK INTEGRAL_TK FP_TK
591 /* Added or modified JDK 1.1 rule types */
592 %type
<node
> type_literals
595 /* 19.2 Production from 2.3: The Syntactic Grammar */
598 /* Register static variables with the garbage
600 ggc_add_tree_root
(&label_id
, 1);
601 ggc_add_tree_root
(&wfl_string_buffer
, 1);
602 ggc_add_tree_root
(&wfl_append
, 1);
603 ggc_add_tree_root
(&wfl_to_string
, 1);
604 ggc_add_tree_root
(&java_lang_id
, 1);
605 ggc_add_tree_root
(&inst_id
, 1);
606 ggc_add_tree_root
(&java_lang_cloneable
, 1);
607 ggc_add_tree_root
(&java_io_serializable
, 1);
608 ggc_add_tree_root
(¤t_static_block
, 1);
609 ggc_add_tree_root
(&wpv_id
, 1);
610 ggc_add_tree_root
(&package_list
, 1);
611 ggc_add_tree_root
(¤t_this
, 1);
612 ggc_add_tree_root
(¤tly_caught_type_list
, 1);
613 ggc_add_root
(&ctxp
, 1,
614 sizeof
(struct parser_ctxt
*),
616 ggc_add_root
(&ctxp_for_generation
, 1,
617 sizeof
(struct parser_ctxt
*),
624 /* 19.3 Productions from 3: Lexical structure */
634 /* 19.4 Productions from 4: Types, Values and Variables */
647 class_or_interface_type
651 class_or_interface_type:
656 class_or_interface_type
/* Default rule */
660 class_or_interface_type
666 int osb
= pop_current_osb
(ctxp
);
667 tree t
= build_java_array_type
(($1), -1);
668 CLASS_LOADED_P
(t
) = 1;
670 t
= build_unresolved_array_type
(t
);
675 int osb
= pop_current_osb
(ctxp
);
678 t
= build_unresolved_array_type
(t
);
683 /* 19.5 Productions from 6: Names */
685 simple_name
/* Default rule */
686 | qualified_name
/* Default rule */
690 identifier
/* Default rule */
694 name DOT_TK identifier
695 { $$
= make_qualified_name
($1, $3, $2.location
); }
702 /* 19.6: Production from 7: Packages */
705 | package_declaration
706 | import_declarations
708 | package_declaration import_declarations
709 | package_declaration type_declarations
710 | import_declarations type_declarations
711 | package_declaration import_declarations type_declarations
719 | import_declarations import_declaration
727 | type_declarations type_declaration
731 PACKAGE_TK name SC_TK
733 ctxp
->package
= EXPR_WFL_NODE
($2);
734 register_package
(ctxp
->package
);
737 {yyerror ("Missing name"); RECOVER
;}
738 | PACKAGE_TK name
error
739 {yyerror ("';' expected"); RECOVER
;}
743 single_type_import_declaration
744 | type_import_on_demand_declaration
747 single_type_import_declaration:
750 tree name
= EXPR_WFL_NODE
($2), last_name
;
751 int i
= IDENTIFIER_LENGTH
(name
)-1;
752 const char *last
= &IDENTIFIER_POINTER
(name
)[i
];
753 while
(last
!= IDENTIFIER_POINTER
(name
))
759 last_name
= get_identifier
(++last
);
760 if
(IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(last_name
))
762 tree err
= find_name_in_single_imports
(last_name
);
763 if
(err
&& err
!= name
)
765 ($2, "Ambiguous class: `%s' and `%s'",
766 IDENTIFIER_POINTER
(name
),
767 IDENTIFIER_POINTER
(err
));
769 REGISTER_IMPORT
($2, last_name
);
772 REGISTER_IMPORT
($2, last_name
);
775 {yyerror ("Missing name"); RECOVER
;}
776 | IMPORT_TK name
error
777 {yyerror ("';' expected"); RECOVER
;}
780 type_import_on_demand_declaration:
781 IMPORT_TK name DOT_TK MULT_TK SC_TK
783 tree name
= EXPR_WFL_NODE
($2);
784 /* Don't import java.lang.* twice. */
785 if
(name
!= java_lang_id
)
787 read_import_dir
($2);
788 ctxp
->import_demand_list
=
789 chainon
(ctxp
->import_demand_list
,
790 build_tree_list
($2, NULL_TREE
));
793 | IMPORT_TK name DOT_TK
error
794 {yyerror ("'*' expected"); RECOVER
;}
795 | IMPORT_TK name DOT_TK MULT_TK
error
796 {yyerror ("';' expected"); RECOVER
;}
801 { end_class_declaration
(0); }
802 | interface_declaration
803 { end_class_declaration
(0); }
808 yyerror ("Class or interface declaration expected");
812 /* 19.7 Shortened from the original:
813 modifiers: modifier | modifiers modifier
814 modifier: any of public... */
820 | modifiers MODIFIER_TK
825 (ctxp
->modifier_ctx
[$2], "Modifier `%s' declared twice",
826 java_accstring_lookup
(acc
));
834 /* 19.8.1 Production from $8.1: Class Declaration */
836 modifiers CLASS_TK identifier super interfaces
837 { create_class
($1, $3, $4, $5); }
839 | CLASS_TK identifier super interfaces
840 { create_class
(0, $2, $3, $4); }
842 | modifiers CLASS_TK
error
843 {yyerror ("Missing class name"); RECOVER
;}
845 {yyerror ("Missing class name"); RECOVER
;}
846 | CLASS_TK identifier
error
848 if
(!ctxp
->class_err
) yyerror ("'{' expected");
851 | modifiers CLASS_TK identifier
error
852 {if
(!ctxp
->class_err
) yyerror ("'{' expected"); RECOVER
;}
857 | EXTENDS_TK class_type
859 | EXTENDS_TK class_type
error
860 {yyerror ("'{' expected"); ctxp
->class_err
=1;}
862 {yyerror ("Missing super class name"); ctxp
->class_err
=1;}
867 | IMPLEMENTS_TK interface_type_list
869 | IMPLEMENTS_TK
error
872 yyerror ("Missing interface name");
879 ctxp
->interface_number
= 1;
880 $$
= build_tree_list
($1, NULL_TREE
);
882 | interface_type_list C_TK interface_type
884 ctxp
->interface_number
++;
885 $$
= chainon
($1, build_tree_list
($3, NULL_TREE
));
887 | interface_type_list C_TK
error
888 {yyerror ("Missing interface name"); RECOVER
;}
894 /* Store the location of the `}' when doing xrefs */
896 DECL_END_SOURCE_LINE
(GET_CPC
()) =
897 EXPR_WFL_ADD_COL
($2.location
, 1);
900 | OCB_TK class_body_declarations CCB_TK
902 /* Store the location of the `}' when doing xrefs */
904 DECL_END_SOURCE_LINE
(GET_CPC
()) =
905 EXPR_WFL_ADD_COL
($3.location
, 1);
910 class_body_declarations:
911 class_body_declaration
912 | class_body_declarations class_body_declaration
915 class_body_declaration:
916 class_member_declaration
918 | constructor_declaration
919 | block
/* Added, JDK1.1, instance initializer */
921 TREE_CHAIN
($1) = CPC_INSTANCE_INITIALIZER_STMT
(ctxp
);
922 SET_CPC_INSTANCE_INITIALIZER_STMT
(ctxp
, $1);
926 class_member_declaration:
929 | class_declaration
/* Added, JDK1.1 inner classes */
930 { end_class_declaration
(1); }
931 | interface_declaration
/* Added, JDK1.1 inner interfaces */
932 { end_class_declaration
(1); }
936 /* 19.8.2 Productions from 8.3: Field Declarations */
938 type variable_declarators SC_TK
939 { register_fields
(0, $1, $2); }
940 | modifiers type variable_declarators SC_TK
943 ("Illegal modifier `%s' for field declaration",
944 $1, FIELD_MODIFIERS
);
945 check_modifiers_consistency
($1);
946 register_fields
($1, $2, $3);
950 variable_declarators:
951 /* Should we use build_decl_list () instead ? FIXME */
952 variable_declarator
/* Default rule */
953 | variable_declarators C_TK variable_declarator
954 { $$
= chainon
($1, $3); }
955 | variable_declarators C_TK
error
956 {yyerror ("Missing term"); RECOVER
;}
960 variable_declarator_id
961 { $$
= build_tree_list
($1, NULL_TREE
); }
962 | variable_declarator_id ASSIGN_TK variable_initializer
964 if
(java_error_count
)
967 ($1, build_assignment
($2.token
, $2.location
, $1, $3));
969 | variable_declarator_id ASSIGN_TK
error
971 yyerror ("Missing variable initializer");
972 $$
= build_tree_list
($1, NULL_TREE
);
975 | variable_declarator_id ASSIGN_TK variable_initializer
error
977 yyerror ("';' expected");
978 $$
= build_tree_list
($1, NULL_TREE
);
983 variable_declarator_id:
985 | variable_declarator_id OSB_TK CSB_TK
986 { $$
= build_unresolved_array_type
($1); }
988 {yyerror ("Invalid declaration"); DRECOVER
(vdi
);}
989 | variable_declarator_id OSB_TK
error
991 tree node
= java_lval.node
;
992 if
(node
&& (TREE_CODE
(node
) == INTEGER_CST
993 || TREE_CODE
(node
) == EXPR_WITH_FILE_LOCATION
))
994 yyerror ("Can't specify array dimension in a declaration");
996 yyerror ("']' expected");
999 | variable_declarator_id CSB_TK
error
1000 {yyerror ("Unbalanced ']'"); DRECOVER
(vdi
);}
1003 variable_initializer:
1008 /* 19.8.3 Productions from 8.4: Method Declarations */
1012 current_function_decl
= $1;
1013 if
(current_function_decl
1014 && TREE_CODE
(current_function_decl
) == FUNCTION_DECL
)
1015 source_start_java_method
(current_function_decl
);
1017 current_function_decl
= NULL_TREE
;
1020 { finish_method_declaration
($3); }
1021 | method_header
error
1022 {YYNOT_TWICE
yyerror ("'{' expected"); RECOVER
;}
1026 type method_declarator throws
1027 { $$
= method_header
(0, $1, $2, $3); }
1028 | VOID_TK method_declarator throws
1029 { $$
= method_header
(0, void_type_node
, $2, $3); }
1030 | modifiers type method_declarator throws
1031 { $$
= method_header
($1, $2, $3, $4); }
1032 | modifiers VOID_TK method_declarator throws
1033 { $$
= method_header
($1, void_type_node
, $3, $4); }
1036 yyerror ("Invalid method declaration, method name required");
1039 | modifiers type
error
1042 {yyerror ("Identifier expected"); RECOVER
;}
1043 | modifiers VOID_TK
error
1044 {yyerror ("Identifier expected"); RECOVER
;}
1047 yyerror ("Invalid method declaration, return type required");
1053 identifier OP_TK CP_TK
1055 ctxp
->formal_parameter_number
= 0;
1056 $$
= method_declarator
($1, NULL_TREE
);
1058 | identifier OP_TK formal_parameter_list CP_TK
1059 { $$
= method_declarator
($1, $3); }
1060 | method_declarator OSB_TK CSB_TK
1062 EXPR_WFL_LINECOL
(wfl_operator
) = $2.location
;
1064 build_unresolved_array_type
(TREE_PURPOSE
($1));
1065 parse_warning_context
1067 "Discouraged form of returned type specification");
1069 | identifier OP_TK
error
1070 {yyerror ("')' expected"); DRECOVER
(method_declarator
);}
1071 | method_declarator OSB_TK
error
1072 {yyerror ("']' expected"); RECOVER
;}
1075 formal_parameter_list:
1078 ctxp
->formal_parameter_number
= 1;
1080 | formal_parameter_list C_TK formal_parameter
1082 ctxp
->formal_parameter_number
+= 1;
1083 $$
= chainon
($1, $3);
1085 | formal_parameter_list C_TK
error
1086 { yyerror ("Missing formal parameter term"); RECOVER
; }
1090 type variable_declarator_id
1092 $$
= build_tree_list
($2, $1);
1094 | final type variable_declarator_id
/* Added, JDK1.1 final parms */
1096 $$
= build_tree_list
($3, $2);
1097 ARG_FINAL_P
($$
) = 1;
1101 yyerror ("Missing identifier"); RECOVER
;
1106 yyerror ("Missing identifier"); RECOVER
;
1114 check_modifiers
("Illegal modifier `%s'. Only `final' was expected here",
1116 if
($1 != ACC_FINAL
)
1117 MODIFIER_WFL
(FINAL_TK
) = build_wfl_node
(NULL_TREE
);
1123 | THROWS_TK class_type_list
1126 {yyerror ("Missing class type term"); RECOVER
;}
1131 { $$
= build_tree_list
($1, $1); }
1132 | class_type_list C_TK class_type
1133 { $$
= tree_cons
($3, $3, $1); }
1134 | class_type_list C_TK
error
1135 {yyerror ("Missing class type term"); RECOVER
;}
1140 | SC_TK
{ $$
= NULL_TREE
; }
1143 /* 19.8.4 Productions from 8.5: Static Initializers */
1147 TREE_CHAIN
($2) = CPC_STATIC_INITIALIZER_STMT
(ctxp
);
1148 SET_CPC_STATIC_INITIALIZER_STMT
(ctxp
, $2);
1149 current_static_block
= NULL_TREE
;
1153 static: /* Test lval.sub_token here */
1156 check_modifiers
("Illegal modifier `%s' for static initializer", $1, ACC_STATIC
);
1157 /* Can't have a static initializer in an innerclass */
1158 if
($1 | ACC_STATIC
&&
1159 GET_CPC_LIST
() && !TOPLEVEL_CLASS_DECL_P
(GET_CPC
()))
1161 (MODIFIER_WFL
(STATIC_TK
),
1162 "Can't define static initializer in class `%s'. Static initializer can only be defined in top-level classes",
1163 IDENTIFIER_POINTER
(DECL_NAME
(GET_CPC
())));
1164 SOURCE_FRONTEND_DEBUG
(("Modifiers: %d", $1));
1168 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1169 constructor_declaration:
1172 current_function_decl
= $1;
1173 source_start_java_method
(current_function_decl
);
1176 { finish_method_declaration
($3); }
1180 constructor_declarator throws
1181 { $$
= method_header
(0, NULL_TREE
, $1, $2); }
1182 | modifiers constructor_declarator throws
1183 { $$
= method_header
($1, NULL_TREE
, $2, $3); }
1186 constructor_declarator:
1187 simple_name OP_TK CP_TK
1189 ctxp
->formal_parameter_number
= 0;
1190 $$
= method_declarator
($1, NULL_TREE
);
1192 | simple_name OP_TK formal_parameter_list CP_TK
1193 { $$
= method_declarator
($1, $3); }
1197 /* Unlike regular method, we always need a complete (empty)
1198 body so we can safely perform all the required code
1199 addition (super invocation and field initialization) */
1200 block_begin constructor_block_end
1202 BLOCK_EXPR_BODY
($2) = empty_stmt_node
;
1205 | block_begin explicit_constructor_invocation constructor_block_end
1207 | block_begin block_statements constructor_block_end
1209 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1213 constructor_block_end:
1217 /* Error recovery for that rule moved down expression_statement: rule. */
1218 explicit_constructor_invocation:
1219 this_or_super OP_TK CP_TK SC_TK
1221 $$
= build_method_invocation
($1, NULL_TREE
);
1222 $$
= build_debugable_stmt
(EXPR_WFL_LINECOL
($1), $$
);
1223 $$
= java_method_add_stmt
(current_function_decl
, $$
);
1225 | this_or_super OP_TK argument_list CP_TK SC_TK
1227 $$
= build_method_invocation
($1, $3);
1228 $$
= build_debugable_stmt
(EXPR_WFL_LINECOL
($1), $$
);
1229 $$
= java_method_add_stmt
(current_function_decl
, $$
);
1231 /* Added, JDK1.1 inner classes. Modified because the rule
1232 'primary' couldn't work. */
1233 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1234 {$$
= parse_jdk1_1_error
("explicit constructor invocation"); }
1235 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1236 {$$
= parse_jdk1_1_error
("explicit constructor invocation"); }
1239 this_or_super: /* Added, simplifies error diagnostics */
1242 tree wfl
= build_wfl_node
(this_identifier_node
);
1243 EXPR_WFL_LINECOL
(wfl
) = $1.location
;
1248 tree wfl
= build_wfl_node
(super_identifier_node
);
1249 EXPR_WFL_LINECOL
(wfl
) = $1.location
;
1254 /* 19.9 Productions from 9: Interfaces */
1255 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1256 interface_declaration:
1257 INTERFACE_TK identifier
1258 { create_interface
(0, $2, NULL_TREE
); }
1260 | modifiers INTERFACE_TK identifier
1261 { create_interface
($1, $3, NULL_TREE
); }
1263 | INTERFACE_TK identifier extends_interfaces
1264 { create_interface
(0, $2, $3); }
1266 | modifiers INTERFACE_TK identifier extends_interfaces
1267 { create_interface
($1, $3, $4); }
1269 | INTERFACE_TK identifier
error
1270 {yyerror ("'{' expected"); RECOVER
;}
1271 | modifiers INTERFACE_TK identifier
error
1272 {yyerror ("'{' expected"); RECOVER
;}
1276 EXTENDS_TK interface_type
1278 ctxp
->interface_number
= 1;
1279 $$
= build_tree_list
($2, NULL_TREE
);
1281 | extends_interfaces C_TK interface_type
1283 ctxp
->interface_number
++;
1284 $$
= chainon
($1, build_tree_list
($3, NULL_TREE
));
1287 {yyerror ("Invalid interface type"); RECOVER
;}
1288 | extends_interfaces C_TK
error
1289 {yyerror ("Missing term"); RECOVER
;}
1295 | OCB_TK interface_member_declarations CCB_TK
1299 interface_member_declarations:
1300 interface_member_declaration
1301 | interface_member_declarations interface_member_declaration
1304 interface_member_declaration:
1305 constant_declaration
1306 | abstract_method_declaration
1307 | class_declaration
/* Added, JDK1.1 inner classes */
1308 { end_class_declaration
(1); }
1309 | interface_declaration
/* Added, JDK1.1 inner interfaces */
1310 { end_class_declaration
(1); }
1313 constant_declaration:
1317 abstract_method_declaration:
1320 check_abstract_method_header
($1);
1321 current_function_decl
= NULL_TREE
; /* FIXME ? */
1323 | method_header
error
1324 {yyerror ("';' expected"); RECOVER
;}
1327 /* 19.10 Productions from 10: Arrays */
1330 { $$
= build_new_array_init
($1.location
, NULL_TREE
); }
1331 | OCB_TK variable_initializers CCB_TK
1332 { $$
= build_new_array_init
($1.location
, $2); }
1333 | OCB_TK variable_initializers C_TK CCB_TK
1334 { $$
= build_new_array_init
($1.location
, $2); }
1337 variable_initializers:
1338 variable_initializer
1340 $$
= tree_cons
(maybe_build_array_element_wfl
($1),
1343 | variable_initializers C_TK variable_initializer
1345 $$
= tree_cons
(maybe_build_array_element_wfl
($3), $3, $1);
1347 | variable_initializers C_TK
error
1348 {yyerror ("Missing term"); RECOVER
;}
1351 /* 19.11 Production from 14: Blocks and Statements */
1355 /* Store the location of the `}' when doing xrefs */
1356 if
(current_function_decl
&& flag_emit_xref
)
1357 DECL_END_SOURCE_LINE
(current_function_decl
) =
1358 EXPR_WFL_ADD_COL
($2.location
, 1);
1359 $$
= empty_stmt_node
;
1361 | block_begin block_statements block_end
1373 maybe_absorb_scoping_blocks
();
1374 /* Store the location of the `}' when doing xrefs */
1375 if
(current_function_decl
&& flag_emit_xref
)
1376 DECL_END_SOURCE_LINE
(current_function_decl
) =
1377 EXPR_WFL_ADD_COL
($1.location
, 1);
1379 if
(!BLOCK_SUBBLOCKS
($$
))
1380 BLOCK_SUBBLOCKS
($$
) = empty_stmt_node
;
1386 | block_statements block_statement
1390 local_variable_declaration_statement
1392 { java_method_add_stmt
(current_function_decl
, $1); }
1393 | class_declaration
/* Added, JDK1.1 local classes */
1395 LOCAL_CLASS_P
(TREE_TYPE
(GET_CPC
())) = 1;
1396 end_class_declaration
(1);
1400 local_variable_declaration_statement:
1401 local_variable_declaration SC_TK
/* Can't catch missing ';' here */
1404 local_variable_declaration:
1405 type variable_declarators
1406 { declare_local_variables
(0, $1, $2); }
1407 | final type variable_declarators
/* Added, JDK1.1 final locals */
1408 { declare_local_variables
($1, $2, $3); }
1412 statement_without_trailing_substatement
1415 | if_then_else_statement
1418 { $$
= exit_block
(); }
1422 statement_without_trailing_substatement
1423 | labeled_statement_nsi
1424 | if_then_else_statement_nsi
1425 | while_statement_nsi
1427 { $$
= exit_block
(); }
1430 statement_without_trailing_substatement:
1433 | expression_statement
1437 | continue_statement
1439 | synchronized_statement
1447 if
(flag_extraneous_semicolon
)
1449 EXPR_WFL_SET_LINECOL
(wfl_operator
, lineno
, -1);
1450 parse_warning_context
(wfl_operator
, "An empty declaration is a deprecated feature that should not be used");
1452 $$
= empty_stmt_node
;
1457 identifier REL_CL_TK
1459 $$
= build_labeled_block
(EXPR_WFL_LINECOL
($1),
1460 EXPR_WFL_NODE
($1));
1462 push_labeled_block
($$
);
1463 PUSH_LABELED_BLOCK
($$
);
1468 label_decl statement
1469 { $$
= finish_labeled_statement
($1, $2); }
1471 {yyerror ("':' expected"); RECOVER
;}
1474 labeled_statement_nsi:
1475 label_decl statement_nsi
1476 { $$
= finish_labeled_statement
($1, $2); }
1479 /* We concentrate here a bunch of error handling rules that we couldn't write
1480 earlier, because expression_statement catches a missing ';'. */
1481 expression_statement:
1482 statement_expression SC_TK
1484 /* We have a statement. Generate a WFL around it so
1486 $$
= build_expr_wfl
($1, input_filename
, lineno
, 0);
1487 /* We know we have a statement, so set the debug
1488 info to be eventually generate here. */
1489 $$
= JAVA_MAYBE_GENERATE_DEBUG_INFO
($$
);
1493 YYNOT_TWICE
yyerror ("Invalid expression statement");
1494 DRECOVER
(expr_stmt
);
1498 YYNOT_TWICE
yyerror ("Invalid expression statement");
1499 DRECOVER
(expr_stmt
);
1503 YYNOT_TWICE
yyerror ("Invalid expression statement");
1504 DRECOVER
(expr_stmt
);
1506 | this_or_super OP_TK
error
1507 {yyerror ("')' expected"); RECOVER
;}
1508 | this_or_super OP_TK CP_TK
error
1510 parse_ctor_invocation_error
();
1513 | this_or_super OP_TK argument_list
error
1514 {yyerror ("')' expected"); RECOVER
;}
1515 | this_or_super OP_TK argument_list CP_TK
error
1517 parse_ctor_invocation_error
();
1520 | name DOT_TK SUPER_TK
error
1521 {yyerror ("'(' expected"); RECOVER
;}
1522 | name DOT_TK SUPER_TK OP_TK
error
1523 {yyerror ("')' expected"); RECOVER
;}
1524 | name DOT_TK SUPER_TK OP_TK argument_list
error
1525 {yyerror ("')' expected"); RECOVER
;}
1526 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK
error
1527 {yyerror ("';' expected"); RECOVER
;}
1528 | name DOT_TK SUPER_TK OP_TK CP_TK
error
1529 {yyerror ("';' expected"); RECOVER
;}
1532 statement_expression:
1534 | pre_increment_expression
1535 | pre_decrement_expression
1536 | post_increment_expression
1537 | post_decrement_expression
1539 | class_instance_creation_expression
1543 IF_TK OP_TK expression CP_TK statement
1545 $$
= build_if_else_statement
($2.location
, $3,
1549 {yyerror ("'(' expected"); RECOVER
;}
1551 {yyerror ("Missing term"); RECOVER
;}
1552 | IF_TK OP_TK expression
error
1553 {yyerror ("')' expected"); RECOVER
;}
1556 if_then_else_statement:
1557 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1558 { $$
= build_if_else_statement
($2.location
, $3, $5, $7); }
1561 if_then_else_statement_nsi:
1562 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1563 { $$
= build_if_else_statement
($2.location
, $3, $5, $7); }
1573 /* Make into "proper list" of COMPOUND_EXPRs.
1574 I.e. make the last statment also have its own
1576 maybe_absorb_scoping_blocks
();
1577 TREE_OPERAND
($1, 1) = exit_block
();
1578 $$
= build_debugable_stmt
(EXPR_WFL_LINECOL
($1), $1);
1583 SWITCH_TK OP_TK expression CP_TK
1585 $$
= build
(SWITCH_EXPR
, NULL_TREE
, $3, NULL_TREE
);
1586 EXPR_WFL_LINECOL
($$
) = $2.location
;
1589 {yyerror ("'(' expected"); RECOVER
;}
1590 | SWITCH_TK OP_TK
error
1591 {yyerror ("Missing term or ')'"); DRECOVER
(switch_statement
);}
1592 | SWITCH_TK OP_TK expression CP_TK
error
1593 {yyerror ("'{' expected"); RECOVER
;}
1596 /* Default assignment is there to avoid type node on switch_block
1602 | OCB_TK switch_labels CCB_TK
1604 | OCB_TK switch_block_statement_groups CCB_TK
1606 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1610 switch_block_statement_groups:
1611 switch_block_statement_group
1612 | switch_block_statement_groups switch_block_statement_group
1615 switch_block_statement_group:
1616 switch_labels block_statements
1621 | switch_labels switch_label
1625 CASE_TK constant_expression REL_CL_TK
1627 tree lab
= build1
(CASE_EXPR
, NULL_TREE
, $2);
1628 EXPR_WFL_LINECOL
(lab
) = $1.location
;
1629 java_method_add_stmt
(current_function_decl
, lab
);
1631 | DEFAULT_TK REL_CL_TK
1633 tree lab
= build
(DEFAULT_EXPR
, NULL_TREE
, NULL_TREE
);
1634 EXPR_WFL_LINECOL
(lab
) = $1.location
;
1635 java_method_add_stmt
(current_function_decl
, lab
);
1638 {yyerror ("Missing or invalid constant expression"); RECOVER
;}
1639 | CASE_TK constant_expression
error
1640 {yyerror ("':' expected"); RECOVER
;}
1642 {yyerror ("':' expected"); RECOVER
;}
1646 WHILE_TK OP_TK expression CP_TK
1648 tree body
= build_loop_body
($2.location
, $3, 0);
1649 $$
= build_new_loop
(body
);
1654 while_expression statement
1655 { $$
= finish_loop_body
(0, NULL_TREE
, $2, 0); }
1657 {YYERROR_NOW
; yyerror ("'(' expected"); RECOVER
;}
1658 | WHILE_TK OP_TK
error
1659 {yyerror ("Missing term and ')' expected"); RECOVER
;}
1660 | WHILE_TK OP_TK expression
error
1661 {yyerror ("')' expected"); RECOVER
;}
1664 while_statement_nsi:
1665 while_expression statement_nsi
1666 { $$
= finish_loop_body
(0, NULL_TREE
, $2, 0); }
1672 tree body
= build_loop_body
(0, NULL_TREE
, 1);
1673 $$
= build_new_loop
(body
);
1675 /* Need error handing here. FIXME */
1679 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1680 { $$
= finish_loop_body
($4.location
, $5, $2, 1); }
1684 for_begin SC_TK expression SC_TK for_update CP_TK statement
1686 if
(TREE_CODE_CLASS
(TREE_CODE
($3)) == 'c')
1687 $3 = build_wfl_node
($3);
1688 $$
= finish_for_loop
(EXPR_WFL_LINECOL
($3), $3, $5, $7);
1690 | for_begin SC_TK SC_TK for_update CP_TK statement
1692 $$
= finish_for_loop
(0, NULL_TREE
, $4, $6);
1693 /* We have not condition, so we get rid of the EXIT_EXPR */
1694 LOOP_EXPR_BODY_CONDITION_EXPR
(LOOP_EXPR_BODY
($$
), 0) =
1697 | for_begin SC_TK
error
1698 {yyerror ("Invalid control expression"); RECOVER
;}
1699 | for_begin SC_TK expression SC_TK
error
1700 {yyerror ("Invalid update expression"); RECOVER
;}
1701 | for_begin SC_TK SC_TK
error
1702 {yyerror ("Invalid update expression"); RECOVER
;}
1706 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1707 { $$
= finish_for_loop
(EXPR_WFL_LINECOL
($3), $3, $5, $7);}
1708 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1710 $$
= finish_for_loop
(0, NULL_TREE
, $4, $6);
1711 /* We have not condition, so we get rid of the EXIT_EXPR */
1712 LOOP_EXPR_BODY_CONDITION_EXPR
(LOOP_EXPR_BODY
($$
), 0) =
1720 /* This scope defined for local variable that may be
1721 defined within the scope of the for loop */
1725 {yyerror ("'(' expected"); DRECOVER
(for_1
);}
1726 | FOR_TK OP_TK
error
1727 {yyerror ("Invalid init statement"); RECOVER
;}
1733 /* We now declare the loop body. The loop is
1734 declared as a for loop. */
1735 tree body
= build_loop_body
(0, NULL_TREE
, 0);
1736 $$
= build_new_loop
(body
);
1737 FOR_LOOP_P
($$
) = 1;
1738 /* The loop is added to the current block the for
1739 statement is defined within */
1740 java_method_add_stmt
(current_function_decl
, $$
);
1743 for_init: /* Can be empty */
1744 { $$
= empty_stmt_node
; }
1745 | statement_expression_list
1747 /* Init statement recorded within the previously
1748 defined block scope */
1749 $$
= java_method_add_stmt
(current_function_decl
, $1);
1751 | local_variable_declaration
1753 /* Local variable are recorded within the previously
1754 defined block scope */
1757 | statement_expression_list
error
1758 {yyerror ("';' expected"); DRECOVER
(for_init_1
);}
1761 for_update: /* Can be empty */
1762 {$$
= empty_stmt_node
;}
1763 | statement_expression_list
1764 { $$
= build_debugable_stmt
(BUILD_LOCATION
(), $1); }
1767 statement_expression_list:
1768 statement_expression
1769 { $$
= add_stmt_to_compound
(NULL_TREE
, NULL_TREE
, $1); }
1770 | statement_expression_list C_TK statement_expression
1771 { $$
= add_stmt_to_compound
($1, NULL_TREE
, $3); }
1772 | statement_expression_list C_TK
error
1773 {yyerror ("Missing term"); RECOVER
;}
1778 { $$
= build_bc_statement
($1.location
, 1, NULL_TREE
); }
1779 | BREAK_TK identifier SC_TK
1780 { $$
= build_bc_statement
($1.location
, 1, $2); }
1782 {yyerror ("Missing term"); RECOVER
;}
1783 | BREAK_TK identifier
error
1784 {yyerror ("';' expected"); RECOVER
;}
1789 { $$
= build_bc_statement
($1.location
, 0, NULL_TREE
); }
1790 | CONTINUE_TK identifier SC_TK
1791 { $$
= build_bc_statement
($1.location
, 0, $2); }
1793 {yyerror ("Missing term"); RECOVER
;}
1794 | CONTINUE_TK identifier
error
1795 {yyerror ("';' expected"); RECOVER
;}
1800 { $$
= build_return
($1.location
, NULL_TREE
); }
1801 | RETURN_TK expression SC_TK
1802 { $$
= build_return
($1.location
, $2); }
1804 {yyerror ("Missing term"); RECOVER
;}
1805 | RETURN_TK expression
error
1806 {yyerror ("';' expected"); RECOVER
;}
1810 THROW_TK expression SC_TK
1812 $$
= build1
(THROW_EXPR
, NULL_TREE
, $2);
1813 EXPR_WFL_LINECOL
($$
) = $1.location
;
1816 {yyerror ("Missing term"); RECOVER
;}
1817 | THROW_TK expression
error
1818 {yyerror ("';' expected"); RECOVER
;}
1821 synchronized_statement:
1822 synchronized OP_TK expression CP_TK block
1824 $$
= build
(SYNCHRONIZED_EXPR
, NULL_TREE
, $3, $5);
1825 EXPR_WFL_LINECOL
($$
) =
1826 EXPR_WFL_LINECOL
(MODIFIER_WFL
(SYNCHRONIZED_TK
));
1828 | synchronized OP_TK expression CP_TK
error
1829 {yyerror ("'{' expected"); RECOVER
;}
1830 | synchronized
error
1831 {yyerror ("'(' expected"); RECOVER
;}
1832 | synchronized OP_TK
error CP_TK
1833 {yyerror ("Missing term"); RECOVER
;}
1834 | synchronized OP_TK
error
1835 {yyerror ("Missing term"); RECOVER
;}
1842 "Illegal modifier `%s'. Only `synchronized' was expected here",
1843 $1, ACC_SYNCHRONIZED
);
1844 if
($1 != ACC_SYNCHRONIZED
)
1845 MODIFIER_WFL
(SYNCHRONIZED_TK
) =
1846 build_wfl_node
(NULL_TREE
);
1851 TRY_TK block catches
1852 { $$
= build_try_statement
($1.location
, $2, $3); }
1853 | TRY_TK block finally
1854 { $$
= build_try_finally_statement
($1.location
, $2, $3); }
1855 | TRY_TK block catches finally
1856 { $$
= build_try_finally_statement
1857 ($1.location
, build_try_statement
($1.location
,
1861 {yyerror ("'{' expected"); DRECOVER
(try_statement
);}
1866 | catches catch_clause
1868 TREE_CHAIN
($2) = $1;
1874 catch_clause_parameter block
1876 java_method_add_stmt
(current_function_decl
, $2);
1881 catch_clause_parameter:
1882 CATCH_TK OP_TK formal_parameter CP_TK
1884 /* We add a block to define a scope for
1885 formal_parameter (CCBP). The formal parameter is
1886 declared initialized by the appropriate function
1888 tree ccpb
= enter_block
();
1889 tree init
= build_assignment
1890 (ASSIGN_TK
, $2.location
, TREE_PURPOSE
($3),
1891 build_exception_object_ref
(ptr_type_node
));
1892 declare_local_variables
(0, TREE_VALUE
($3),
1893 build_tree_list
(TREE_PURPOSE
($3),
1895 $$
= build1
(CATCH_EXPR
, NULL_TREE
, ccpb
);
1896 EXPR_WFL_LINECOL
($$
) = $1.location
;
1899 {yyerror ("'(' expected"); RECOVER
; $$
= NULL_TREE
;}
1900 | CATCH_TK OP_TK
error
1902 yyerror ("Missing term or ')' expected");
1903 RECOVER
; $$
= NULL_TREE
;
1905 | CATCH_TK OP_TK
error CP_TK
/* That's for () */
1906 {yyerror ("Missing term"); RECOVER
; $$
= NULL_TREE
;}
1913 {yyerror ("'{' expected"); RECOVER
; }
1916 /* 19.12 Production from 15: Expressions */
1918 primary_no_new_array
1919 | array_creation_expression
1922 primary_no_new_array:
1925 { $$
= build_this
($1.location
); }
1926 | OP_TK expression CP_TK
1928 | class_instance_creation_expression
1933 /* Added, JDK1.1 inner classes. Documentation is wrong
1934 refering to a 'ClassName' (class_name) rule that doesn't
1935 exist. Used name: instead. */
1936 | name DOT_TK THIS_TK
1938 tree wfl
= build_wfl_node
(this_identifier_node
);
1939 $$
= make_qualified_primary
($1, wfl
, EXPR_WFL_LINECOL
($1));
1941 | OP_TK expression
error
1942 {yyerror ("')' expected"); RECOVER
;}
1944 {yyerror ("'class' or 'this' expected" ); RECOVER
;}
1945 | primitive_type DOT_TK
error
1946 {yyerror ("'class' expected" ); RECOVER
;}
1947 | VOID_TK DOT_TK
error
1948 {yyerror ("'class' expected" ); RECOVER
;}
1952 name DOT_TK CLASS_TK
1953 { $$
= build_incomplete_class_ref
($2.location
, $1); }
1954 | array_type DOT_TK CLASS_TK
1955 { $$
= build_incomplete_class_ref
($2.location
, $1); }
1956 | primitive_type DOT_TK CLASS_TK
1957 { $$
= build_class_ref
($1); }
1958 | VOID_TK DOT_TK CLASS_TK
1959 { $$
= build_class_ref
(void_type_node
); }
1962 class_instance_creation_expression:
1963 NEW_TK class_type OP_TK argument_list CP_TK
1964 { $$
= build_new_invocation
($2, $4); }
1965 | NEW_TK class_type OP_TK CP_TK
1966 { $$
= build_new_invocation
($2, NULL_TREE
); }
1967 | anonymous_class_creation
1968 /* Added, JDK1.1 inner classes, modified to use name or
1969 primary instead of primary solely which couldn't work in
1971 | something_dot_new identifier OP_TK CP_TK
1973 tree ctor
= build_new_invocation
($2, NULL_TREE
);
1974 $$
= make_qualified_primary
($1, ctor
,
1975 EXPR_WFL_LINECOL
($1));
1977 | something_dot_new identifier OP_TK CP_TK class_body
1978 | something_dot_new identifier OP_TK argument_list CP_TK
1980 tree ctor
= build_new_invocation
($2, $4);
1981 $$
= make_qualified_primary
($1, ctor
,
1982 EXPR_WFL_LINECOL
($1));
1984 | something_dot_new identifier OP_TK argument_list CP_TK class_body
1985 | NEW_TK
error SC_TK
1986 {yyerror ("'(' expected"); DRECOVER
(new_1
);}
1987 | NEW_TK class_type
error
1988 {yyerror ("'(' expected"); RECOVER
;}
1989 | NEW_TK class_type OP_TK
error
1990 {yyerror ("')' or term expected"); RECOVER
;}
1991 | NEW_TK class_type OP_TK argument_list
error
1992 {yyerror ("')' expected"); RECOVER
;}
1993 | something_dot_new
error
1994 {YYERROR_NOW
; yyerror ("Identifier expected"); RECOVER
;}
1995 | something_dot_new identifier
error
1996 {yyerror ("'(' expected"); RECOVER
;}
1999 /* Created after JDK1.1 rules originally added to
2000 class_instance_creation_expression, but modified to use
2001 'class_type' instead of 'TypeName' (type_name) which is mentionned
2002 in the documentation but doesn't exist. */
2004 anonymous_class_creation:
2005 NEW_TK class_type OP_TK argument_list CP_TK
2006 { create_anonymous_class
($1.location
, $2); }
2009 tree id
= build_wfl_node
(DECL_NAME
(GET_CPC
()));
2010 EXPR_WFL_LINECOL
(id
) = EXPR_WFL_LINECOL
($2);
2012 end_class_declaration
(1);
2014 /* Now we can craft the new expression */
2015 $$
= build_new_invocation
(id
, $4);
2017 /* Note that we can't possibly be here if
2018 `class_type' is an interface (in which case the
2019 anonymous class extends Object and implements
2020 `class_type', hence its constructor can't have
2023 /* Otherwise, the innerclass must feature a
2024 constructor matching `argument_list'. Anonymous
2025 classes are a bit special: it's impossible to
2026 define constructor for them, hence constructors
2027 must be generated following the hints provided by
2028 the `new' expression. Whether a super constructor
2029 of that nature exists or not is to be verified
2030 later on in verify_constructor_super.
2032 It's during the expansion of a `new' statement
2033 refering to an anonymous class that a ctor will
2034 be generated for the anonymous class, with the
2038 | NEW_TK class_type OP_TK CP_TK
2039 { create_anonymous_class
($1.location
, $2); }
2042 tree id
= build_wfl_node
(DECL_NAME
(GET_CPC
()));
2043 EXPR_WFL_LINECOL
(id
) = EXPR_WFL_LINECOL
($2);
2045 end_class_declaration
(1);
2047 /* Now we can craft the new expression. The
2048 statement doesn't need to be remember so that a
2049 constructor can be generated, since its signature
2050 is already known. */
2051 $$
= build_new_invocation
(id
, NULL_TREE
);
2055 something_dot_new: /* Added, not part of the specs. */
2058 | primary DOT_TK NEW_TK
2065 $$
= tree_cons
(NULL_TREE
, $1, NULL_TREE
);
2066 ctxp
->formal_parameter_number
= 1;
2068 | argument_list C_TK expression
2070 ctxp
->formal_parameter_number
+= 1;
2071 $$
= tree_cons
(NULL_TREE
, $3, $1);
2073 | argument_list C_TK
error
2074 {yyerror ("Missing term"); RECOVER
;}
2077 array_creation_expression:
2078 NEW_TK primitive_type dim_exprs
2079 { $$
= build_newarray_node
($2, $3, 0); }
2080 | NEW_TK class_or_interface_type dim_exprs
2081 { $$
= build_newarray_node
($2, $3, 0); }
2082 | NEW_TK primitive_type dim_exprs dims
2083 { $$
= build_newarray_node
($2, $3, pop_current_osb
(ctxp
));}
2084 | NEW_TK class_or_interface_type dim_exprs dims
2085 { $$
= build_newarray_node
($2, $3, pop_current_osb
(ctxp
));}
2086 /* Added, JDK1.1 anonymous array. Initial documentation rule
2088 | NEW_TK class_or_interface_type dims array_initializer
2091 int osb
= pop_current_osb
(ctxp
);
2093 obstack_1grow
(&temporary_obstack
, '[');
2094 sig
= obstack_finish
(&temporary_obstack
);
2095 $$
= build
(NEW_ANONYMOUS_ARRAY_EXPR
, NULL_TREE
,
2096 $2, get_identifier
(sig
), $4);
2098 | NEW_TK primitive_type dims array_initializer
2100 int osb
= pop_current_osb
(ctxp
);
2103 type
= build_java_array_type
(type
, -1);
2104 $$
= build
(NEW_ANONYMOUS_ARRAY_EXPR
, NULL_TREE
,
2105 build_pointer_type
(type
), NULL_TREE
, $4);
2107 | NEW_TK
error CSB_TK
2108 {yyerror ("'[' expected"); DRECOVER
("]");}
2109 | NEW_TK
error OSB_TK
2110 {yyerror ("']' expected"); RECOVER
;}
2115 { $$
= build_tree_list
(NULL_TREE
, $1); }
2116 | dim_exprs dim_expr
2117 { $$
= tree_cons
(NULL_TREE
, $2, $$
); }
2121 OSB_TK expression CSB_TK
2123 if
(JNUMERIC_TYPE_P
(TREE_TYPE
($2)))
2125 $2 = build_wfl_node
($2);
2126 TREE_TYPE
($2) = NULL_TREE
;
2128 EXPR_WFL_LINECOL
($2) = $1.location
;
2131 | OSB_TK expression
error
2132 {yyerror ("']' expected"); RECOVER
;}
2135 yyerror ("Missing term");
2136 yyerror ("']' expected");
2145 /* If not initialized, allocate memory for the osb
2147 if
(!ctxp
->osb_limit
)
2149 allocate
= ctxp
->osb_limit
= 32;
2150 ctxp
->osb_depth
= -1;
2152 /* If capacity overflown, reallocate a bigger chunk */
2153 else if
(ctxp
->osb_depth
+1 == ctxp
->osb_limit
)
2154 allocate
= ctxp
->osb_limit
<< 1;
2158 allocate
*= sizeof
(int);
2159 if
(ctxp
->osb_number
)
2160 ctxp
->osb_number
= (int *)xrealloc
(ctxp
->osb_number
,
2163 ctxp
->osb_number
= (int *)xmalloc
(allocate
);
2166 CURRENT_OSB
(ctxp
) = 1;
2168 | dims OSB_TK CSB_TK
2169 { CURRENT_OSB
(ctxp
)++; }
2171 { yyerror ("']' expected"); RECOVER
;}
2175 primary DOT_TK identifier
2176 { $$
= make_qualified_primary
($1, $3, $2.location
); }
2177 /* FIXME - REWRITE TO:
2178 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2179 | SUPER_TK DOT_TK identifier
2181 tree super_wfl
= build_wfl_node
(super_identifier_node
);
2182 EXPR_WFL_LINECOL
(super_wfl
) = $1.location
;
2183 $$
= make_qualified_name
(super_wfl
, $3, $2.location
);
2186 {yyerror ("Field expected"); DRECOVER
(super_field_acces
);}
2191 { $$
= build_method_invocation
($1, NULL_TREE
); }
2192 | name OP_TK argument_list CP_TK
2193 { $$
= build_method_invocation
($1, $3); }
2194 | primary DOT_TK identifier OP_TK CP_TK
2196 if
(TREE_CODE
($1) == THIS_EXPR
)
2197 $$
= build_this_super_qualified_invocation
2198 (1, $3, NULL_TREE
, 0, $2.location
);
2201 tree invok
= build_method_invocation
($3, NULL_TREE
);
2202 $$
= make_qualified_primary
($1, invok
, $2.location
);
2205 | primary DOT_TK identifier OP_TK argument_list CP_TK
2207 if
(TREE_CODE
($1) == THIS_EXPR
)
2208 $$
= build_this_super_qualified_invocation
2209 (1, $3, $5, 0, $2.location
);
2212 tree invok
= build_method_invocation
($3, $5);
2213 $$
= make_qualified_primary
($1, invok
, $2.location
);
2216 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2218 $$
= build_this_super_qualified_invocation
2219 (0, $3, NULL_TREE
, $1.location
, $2.location
);
2221 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2223 $$
= build_this_super_qualified_invocation
2224 (0, $3, $5, $1.location
, $2.location
);
2226 /* Screws up thing. I let it here until I'm convinced it can
2228 | primary DOT_TK error
2229 {yyerror ("'(' expected"); DRECOVER(bad);} */
2230 | SUPER_TK DOT_TK
error CP_TK
2231 { yyerror ("'(' expected"); DRECOVER
(method_invocation
); }
2232 | SUPER_TK DOT_TK
error DOT_TK
2233 { yyerror ("'(' expected"); DRECOVER
(method_invocation
); }
2237 name OSB_TK expression CSB_TK
2238 { $$
= build_array_ref
($2.location
, $1, $3); }
2239 | primary_no_new_array OSB_TK expression CSB_TK
2240 { $$
= build_array_ref
($2.location
, $1, $3); }
2243 yyerror ("Missing term and ']' expected");
2244 DRECOVER
(array_access
);
2246 | name OSB_TK expression
error
2248 yyerror ("']' expected");
2249 DRECOVER
(array_access
);
2251 | primary_no_new_array OSB_TK
error
2253 yyerror ("Missing term and ']' expected");
2254 DRECOVER
(array_access
);
2256 | primary_no_new_array OSB_TK expression
error
2258 yyerror ("']' expected");
2259 DRECOVER
(array_access
);
2266 | post_increment_expression
2267 | post_decrement_expression
2270 post_increment_expression:
2271 postfix_expression INCR_TK
2272 { $$
= build_incdec
($2.token
, $2.location
, $1, 1); }
2275 post_decrement_expression:
2276 postfix_expression DECR_TK
2277 { $$
= build_incdec
($2.token
, $2.location
, $1, 1); }
2281 pre_increment_expression
2282 | pre_decrement_expression
2283 | PLUS_TK unary_expression
2284 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2285 | MINUS_TK unary_expression
2286 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2287 | unary_expression_not_plus_minus
2289 {yyerror ("Missing term"); RECOVER
}
2291 {yyerror ("Missing term"); RECOVER
}
2294 pre_increment_expression:
2295 INCR_TK unary_expression
2296 {$$
= build_incdec
($1.token
, $1.location
, $2, 0); }
2298 {yyerror ("Missing term"); RECOVER
}
2301 pre_decrement_expression:
2302 DECR_TK unary_expression
2303 {$$
= build_incdec
($1.token
, $1.location
, $2, 0); }
2305 {yyerror ("Missing term"); RECOVER
}
2308 unary_expression_not_plus_minus:
2310 | NOT_TK unary_expression
2311 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2312 | NEG_TK unary_expression
2313 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2316 {yyerror ("Missing term"); RECOVER
}
2318 {yyerror ("Missing term"); RECOVER
}
2321 cast_expression: /* Error handling here is potentially weak */
2322 OP_TK primitive_type dims CP_TK unary_expression
2325 int osb
= pop_current_osb
(ctxp
);
2327 type
= build_java_array_type
(type
, -1);
2328 $$
= build_cast
($1.location
, type
, $5);
2330 | OP_TK primitive_type CP_TK unary_expression
2331 { $$
= build_cast
($1.location
, $2, $4); }
2332 | OP_TK expression CP_TK unary_expression_not_plus_minus
2333 { $$
= build_cast
($1.location
, $2, $4); }
2334 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2337 int osb
= pop_current_osb
(ctxp
);
2339 obstack_1grow
(&temporary_obstack
, '[');
2340 obstack_grow0
(&temporary_obstack
,
2341 IDENTIFIER_POINTER
(EXPR_WFL_NODE
($2)),
2342 IDENTIFIER_LENGTH
(EXPR_WFL_NODE
($2)));
2343 ptr
= obstack_finish
(&temporary_obstack
);
2344 EXPR_WFL_NODE
($2) = get_identifier
(ptr
);
2345 $$
= build_cast
($1.location
, $2, $5);
2347 | OP_TK primitive_type OSB_TK
error
2348 {yyerror ("']' expected, invalid type expression");}
2351 YYNOT_TWICE
yyerror ("Invalid type expression"); RECOVER
;
2354 | OP_TK primitive_type dims CP_TK
error
2355 {yyerror ("Missing term"); RECOVER
;}
2356 | OP_TK primitive_type CP_TK
error
2357 {yyerror ("Missing term"); RECOVER
;}
2358 | OP_TK name dims CP_TK
error
2359 {yyerror ("Missing term"); RECOVER
;}
2362 multiplicative_expression:
2364 | multiplicative_expression MULT_TK unary_expression
2366 $$
= build_binop
(BINOP_LOOKUP
($2.token
),
2367 $2.location
, $1, $3);
2369 | multiplicative_expression DIV_TK unary_expression
2371 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2374 | multiplicative_expression REM_TK unary_expression
2376 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2379 | multiplicative_expression MULT_TK
error
2380 {yyerror ("Missing term"); RECOVER
;}
2381 | multiplicative_expression DIV_TK
error
2382 {yyerror ("Missing term"); RECOVER
;}
2383 | multiplicative_expression REM_TK
error
2384 {yyerror ("Missing term"); RECOVER
;}
2387 additive_expression:
2388 multiplicative_expression
2389 | additive_expression PLUS_TK multiplicative_expression
2391 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2394 | additive_expression MINUS_TK multiplicative_expression
2396 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2399 | additive_expression PLUS_TK
error
2400 {yyerror ("Missing term"); RECOVER
;}
2401 | additive_expression MINUS_TK
error
2402 {yyerror ("Missing term"); RECOVER
;}
2407 | shift_expression LS_TK additive_expression
2409 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2412 | shift_expression SRS_TK additive_expression
2414 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2417 | shift_expression ZRS_TK additive_expression
2419 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2422 | shift_expression LS_TK
error
2423 {yyerror ("Missing term"); RECOVER
;}
2424 | shift_expression SRS_TK
error
2425 {yyerror ("Missing term"); RECOVER
;}
2426 | shift_expression ZRS_TK
error
2427 {yyerror ("Missing term"); RECOVER
;}
2430 relational_expression:
2432 | relational_expression LT_TK shift_expression
2434 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2437 | relational_expression GT_TK shift_expression
2439 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2442 | relational_expression LTE_TK shift_expression
2444 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2447 | relational_expression GTE_TK shift_expression
2449 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2452 | relational_expression INSTANCEOF_TK reference_type
2453 { $$
= build_binop
(INSTANCEOF_EXPR
, $2.location
, $1, $3); }
2454 | relational_expression LT_TK
error
2455 {yyerror ("Missing term"); RECOVER
;}
2456 | relational_expression GT_TK
error
2457 {yyerror ("Missing term"); RECOVER
;}
2458 | relational_expression LTE_TK
error
2459 {yyerror ("Missing term"); RECOVER
;}
2460 | relational_expression GTE_TK
error
2461 {yyerror ("Missing term"); RECOVER
;}
2462 | relational_expression INSTANCEOF_TK
error
2463 {yyerror ("Invalid reference type"); RECOVER
;}
2466 equality_expression:
2467 relational_expression
2468 | equality_expression EQ_TK relational_expression
2470 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2473 | equality_expression NEQ_TK relational_expression
2475 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2478 | equality_expression EQ_TK
error
2479 {yyerror ("Missing term"); RECOVER
;}
2480 | equality_expression NEQ_TK
error
2481 {yyerror ("Missing term"); RECOVER
;}
2486 | and_expression AND_TK equality_expression
2488 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2491 | and_expression AND_TK
error
2492 {yyerror ("Missing term"); RECOVER
;}
2495 exclusive_or_expression:
2497 | exclusive_or_expression XOR_TK and_expression
2499 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2502 | exclusive_or_expression XOR_TK
error
2503 {yyerror ("Missing term"); RECOVER
;}
2506 inclusive_or_expression:
2507 exclusive_or_expression
2508 | inclusive_or_expression OR_TK exclusive_or_expression
2510 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2513 | inclusive_or_expression OR_TK
error
2514 {yyerror ("Missing term"); RECOVER
;}
2517 conditional_and_expression:
2518 inclusive_or_expression
2519 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2521 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2524 | conditional_and_expression BOOL_AND_TK
error
2525 {yyerror ("Missing term"); RECOVER
;}
2528 conditional_or_expression:
2529 conditional_and_expression
2530 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2532 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2535 | conditional_or_expression BOOL_OR_TK
error
2536 {yyerror ("Missing term"); RECOVER
;}
2539 conditional_expression: /* Error handling here is weak */
2540 conditional_or_expression
2541 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2543 $$
= build
(CONDITIONAL_EXPR
, NULL_TREE
, $1, $3, $5);
2544 EXPR_WFL_LINECOL
($$
) = $2.location
;
2546 | conditional_or_expression REL_QM_TK REL_CL_TK
error
2549 yyerror ("Missing term");
2552 | conditional_or_expression REL_QM_TK
error
2553 {yyerror ("Missing term"); DRECOVER
(2);}
2554 | conditional_or_expression REL_QM_TK expression REL_CL_TK
error
2555 {yyerror ("Missing term"); DRECOVER
(3);}
2558 assignment_expression:
2559 conditional_expression
2564 left_hand_side assignment_operator assignment_expression
2565 { $$
= build_assignment
($2.token
, $2.location
, $1, $3); }
2566 | left_hand_side assignment_operator
error
2568 YYNOT_TWICE
yyerror ("Missing term");
2579 assignment_operator:
2585 assignment_expression
2588 constant_expression:
2594 /* Helper function to retrieve an OSB count. Should be used when the
2595 `dims:' rule is being used. */
2598 pop_current_osb
(ctxp
)
2599 struct parser_ctxt
*ctxp
;
2603 if
(ctxp
->osb_depth
< 0)
2606 to_return
= CURRENT_OSB
(ctxp
);
2614 /* This section of the code deal with save/restoring parser contexts.
2615 Add mode documentation here. FIXME */
2617 /* Helper function. Create a new parser context. With
2618 COPY_FROM_PREVIOUS set to a non zero value, content of the previous
2619 context is copied, otherwise, the new context is zeroed. The newly
2620 created context becomes the current one. */
2623 create_new_parser_context
(copy_from_previous
)
2624 int copy_from_previous
;
2626 struct parser_ctxt
*new
;
2628 new
= (struct parser_ctxt
*)xmalloc
(sizeof
(struct parser_ctxt
));
2629 if
(copy_from_previous
)
2631 memcpy
((PTR
)new
, (PTR
)ctxp
, sizeof
(struct parser_ctxt
));
2632 new
->saved_data_ctx
= 1;
2635 memset
((PTR
) new
, 0, sizeof
(struct parser_ctxt
));
2641 /* Create a new parser context and make it the current one. */
2644 java_push_parser_context
()
2646 create_new_parser_context
(0);
2650 java_pop_parser_context
(generate
)
2654 struct parser_ctxt
*toFree
, *next
;
2663 lineno
= ctxp
->lineno
;
2664 current_class
= ctxp
->class_type
;
2667 /* If the old and new lexers differ, then free the old one. */
2668 if
(ctxp
->lexer
&& next
&& ctxp
->lexer
!= next
->lexer
)
2669 java_destroy_lexer
(ctxp
->lexer
);
2671 /* Set the single import class file flag to 0 for the current list
2672 of imported things */
2673 for
(current
= ctxp
->import_list
; current
; current
= TREE_CHAIN
(current
))
2674 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(TREE_PURPOSE
(current
)) = 0;
2676 /* And restore those of the previous context */
2677 if
((ctxp
= next
)) /* Assignment is really meant here */
2678 for
(current
= ctxp
->import_list
; current
; current
= TREE_CHAIN
(current
))
2679 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(TREE_PURPOSE
(current
)) = 1;
2681 /* If we pushed a context to parse a class intended to be generated,
2682 we keep it so we can remember the class. What we could actually
2683 do is to just update a list of class names. */
2686 toFree
->next
= ctxp_for_generation
;
2687 ctxp_for_generation
= toFree
;
2693 /* Create a parser context for the use of saving some global
2697 java_parser_context_save_global
()
2701 java_push_parser_context
();
2702 ctxp
->saved_data_ctx
= 1;
2705 /* If this context already stores data, create a new one suitable
2706 for data storage. */
2707 else if
(ctxp
->saved_data
)
2708 create_new_parser_context
(1);
2710 ctxp
->lineno
= lineno
;
2711 ctxp
->class_type
= current_class
;
2712 ctxp
->filename
= input_filename
;
2713 ctxp
->function_decl
= current_function_decl
;
2714 ctxp
->saved_data
= 1;
2717 /* Restore some global variables from the previous context. Make the
2718 previous context the current one. */
2721 java_parser_context_restore_global
()
2723 lineno
= ctxp
->lineno
;
2724 current_class
= ctxp
->class_type
;
2725 input_filename
= ctxp
->filename
;
2729 BUILD_FILENAME_IDENTIFIER_NODE
(s
, input_filename
);
2730 EXPR_WFL_FILENAME_NODE
(wfl_operator
) = s
;
2732 current_function_decl
= ctxp
->function_decl
;
2733 ctxp
->saved_data
= 0;
2734 if
(ctxp
->saved_data_ctx
)
2735 java_pop_parser_context
(0);
2738 /* Suspend vital data for the current class/function being parsed so
2739 that an other class can be parsed. Used to let local/anonymous
2740 classes be parsed. */
2743 java_parser_context_suspend
()
2745 /* This makes debugging through java_debug_context easier */
2746 static const char *name
= "<inner buffer context>";
2748 /* Duplicate the previous context, use it to save the globals we're
2750 create_new_parser_context
(1);
2751 ctxp
->function_decl
= current_function_decl
;
2752 ctxp
->class_type
= current_class
;
2754 /* Then create a new context which inherits all data from the
2755 previous one. This will be the new current context */
2756 create_new_parser_context
(1);
2758 /* Help debugging */
2759 ctxp
->next
->filename
= name
;
2762 /* Resume vital data for the current class/function being parsed so
2763 that an other class can be parsed. Used to let local/anonymous
2764 classes be parsed. The trick is the data storing file position
2765 informations must be restored to their current value, so parsing
2766 can resume as if no context was ever saved. */
2769 java_parser_context_resume
()
2771 struct parser_ctxt
*old
= ctxp
; /* This one is to be discarded */
2772 struct parser_ctxt
*saver
= old
->next
; /* This one contain saved info */
2773 struct parser_ctxt
*restored
= saver
->next
; /* This one is the old current */
2775 /* We need to inherit the list of classes to complete/generate */
2776 restored
->classd_list
= old
->classd_list
;
2777 restored
->class_list
= old
->class_list
;
2779 /* Restore the current class and function from the saver */
2780 current_class
= saver
->class_type
;
2781 current_function_decl
= saver
->function_decl
;
2783 /* Retrive the restored context */
2786 /* Re-installed the data for the parsing to carry on */
2787 memcpy
(&ctxp
->marker_begining
, &old
->marker_begining
,
2788 (size_t)(&ctxp
->marker_end
- &ctxp
->marker_begining
));
2790 /* Buffer context can now be discarded */
2795 /* Add a new anchor node to which all statement(s) initializing static
2796 and non static initialized upon declaration field(s) will be
2800 java_parser_context_push_initialized_field
()
2804 node
= build_tree_list
(NULL_TREE
, NULL_TREE
);
2805 TREE_CHAIN
(node
) = CPC_STATIC_INITIALIZER_LIST
(ctxp
);
2806 CPC_STATIC_INITIALIZER_LIST
(ctxp
) = node
;
2808 node
= build_tree_list
(NULL_TREE
, NULL_TREE
);
2809 TREE_CHAIN
(node
) = CPC_INITIALIZER_LIST
(ctxp
);
2810 CPC_INITIALIZER_LIST
(ctxp
) = node
;
2812 node
= build_tree_list
(NULL_TREE
, NULL_TREE
);
2813 TREE_CHAIN
(node
) = CPC_INSTANCE_INITIALIZER_LIST
(ctxp
);
2814 CPC_INSTANCE_INITIALIZER_LIST
(ctxp
) = node
;
2817 /* Pop the lists of initialized field. If this lists aren't empty,
2818 remember them so we can use it to create and populate the finit$
2819 or <clinit> functions. */
2822 java_parser_context_pop_initialized_field
()
2825 tree class_type
= TREE_TYPE
(GET_CPC
());
2827 if
(CPC_INITIALIZER_LIST
(ctxp
))
2829 stmts
= CPC_INITIALIZER_STMT
(ctxp
);
2830 CPC_INITIALIZER_LIST
(ctxp
) = TREE_CHAIN
(CPC_INITIALIZER_LIST
(ctxp
));
2831 if
(stmts
&& !java_error_count
)
2832 TYPE_FINIT_STMT_LIST
(class_type
) = reorder_static_initialized
(stmts
);
2835 if
(CPC_STATIC_INITIALIZER_LIST
(ctxp
))
2837 stmts
= CPC_STATIC_INITIALIZER_STMT
(ctxp
);
2838 CPC_STATIC_INITIALIZER_LIST
(ctxp
) =
2839 TREE_CHAIN
(CPC_STATIC_INITIALIZER_LIST
(ctxp
));
2840 /* Keep initialization in order to enforce 8.5 */
2841 if
(stmts
&& !java_error_count
)
2842 TYPE_CLINIT_STMT_LIST
(class_type
) = nreverse
(stmts
);
2845 /* JDK 1.1 instance initializers */
2846 if
(CPC_INSTANCE_INITIALIZER_LIST
(ctxp
))
2848 stmts
= CPC_INSTANCE_INITIALIZER_STMT
(ctxp
);
2849 CPC_INSTANCE_INITIALIZER_LIST
(ctxp
) =
2850 TREE_CHAIN
(CPC_INSTANCE_INITIALIZER_LIST
(ctxp
));
2851 if
(stmts
&& !java_error_count
)
2852 TYPE_II_STMT_LIST
(class_type
) = nreverse
(stmts
);
2857 reorder_static_initialized
(list
)
2860 /* We have to keep things in order. The alias initializer have to
2861 come first, then the initialized regular field, in reverse to
2862 keep them in lexical order. */
2863 tree marker
, previous
= NULL_TREE
;
2864 for
(marker
= list
; marker
; previous
= marker
, marker
= TREE_CHAIN
(marker
))
2865 if
(TREE_CODE
(marker
) == TREE_LIST
2866 && !TREE_VALUE
(marker
) && !TREE_PURPOSE
(marker
))
2869 /* No static initialized, the list is fine as is */
2871 list
= TREE_CHAIN
(marker
);
2873 /* No marker? reverse the whole list */
2875 list
= nreverse
(list
);
2877 /* Otherwise, reverse what's after the marker and the new reordered
2878 sublist will replace the marker. */
2881 TREE_CHAIN
(previous
) = NULL_TREE
;
2882 list
= nreverse
(list
);
2883 list
= chainon
(TREE_CHAIN
(marker
), list
);
2888 /* Helper functions to dump the parser context stack. */
2890 #define TAB_CONTEXT(C) \
2891 {int i
; for
(i
= 0; i
< (C
); i
++) fputc
(' ', stderr
);}
2894 java_debug_context_do
(tab
)
2897 struct parser_ctxt
*copy
= ctxp
;
2901 fprintf
(stderr
, "ctxt: 0x%0lX\n", (unsigned long)copy
);
2903 fprintf
(stderr
, "filename: %s\n", copy
->filename
);
2905 fprintf
(stderr
, "lineno: %d\n", copy
->lineno
);
2907 fprintf
(stderr
, "package: %s\n",
2909 IDENTIFIER_POINTER
(copy
->package
) : "<none>"));
2911 fprintf
(stderr
, "context for saving: %d\n", copy
->saved_data_ctx
);
2913 fprintf
(stderr
, "saved data: %d\n", copy
->saved_data
);
2919 /* Dump the stacked up parser contexts. Intended to be called from a
2923 java_debug_context
()
2925 java_debug_context_do
(0);
2930 /* Flag for the error report routine to issue the error the first time
2931 it's called (overriding the default behavior which is to drop the
2932 first invocation and honor the second one, taking advantage of a
2934 static int force_error
= 0;
2936 /* Reporting an constructor invocation error. */
2938 parse_ctor_invocation_error
()
2940 if
(DECL_CONSTRUCTOR_P
(current_function_decl
))
2941 yyerror ("Constructor invocation must be first thing in a constructor");
2943 yyerror ("Only constructors can invoke constructors");
2946 /* Reporting JDK1.1 features not implemented. */
2949 parse_jdk1_1_error
(msg
)
2952 sorry
(": `%s' JDK1.1(TM) feature", msg
);
2954 return empty_stmt_node
;
2957 static int do_warning
= 0;
2964 static int prev_lineno
;
2965 static const char *prev_msg
;
2968 char *remainder
, *code_from_source
;
2970 if
(!force_error
&& prev_lineno
== lineno
)
2973 /* Save current error location but report latter, when the context is
2975 if
(ctxp
->java_error_flag
== 0)
2977 ctxp
->java_error_flag
= 1;
2979 /* Do something to use the previous line if we're reaching the
2980 end of the file... */
2981 #ifdef VERBOSE_SKELETON
2982 printf
("* Error detected (%s)\n", (msg ? msg
: "(null)"));
2987 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2988 if
(!force_error
&& msg
== prev_msg
&& prev_lineno
== elc.line
)
2991 ctxp
->java_error_flag
= 0;
2993 java_warning_count
++;
2997 if
(elc.col
== 0 && msg
&& msg
[1] == ';')
2999 elc.col
= ctxp
->p_line
->char_col
-1;
3000 elc.line
= ctxp
->p_line
->lineno
;
3003 save_lineno
= lineno
;
3004 prev_lineno
= lineno
= elc.line
;
3007 code_from_source
= java_get_line_col
(ctxp
->filename
, elc.line
, elc.col
);
3008 obstack_grow0
(&temporary_obstack
,
3009 code_from_source
, strlen
(code_from_source
));
3010 remainder
= obstack_finish
(&temporary_obstack
);
3012 warning
("%s.\n%s", msg
, remainder
);
3014 error ("%s.\n%s", msg
, remainder
);
3016 /* This allow us to cheaply avoid an extra 'Invalid expression
3017 statement' error report when errors have been already reported on
3018 the same line. This occurs when we report an error but don't have
3019 a synchronization point other than ';', which
3020 expression_statement is the only one to take care of. */
3021 ctxp
->prevent_ese
= lineno
= save_lineno
;
3025 issue_warning_error_from_context
(cl
, msg
, ap
)
3030 const char *saved
, *saved_input_filename
;
3032 vsprintf
(buffer
, msg
, ap
);
3035 ctxp
->elc.line
= EXPR_WFL_LINENO
(cl
);
3036 ctxp
->elc.col
= (EXPR_WFL_COLNO
(cl
) == 0xfff ?
-1 :
3037 (EXPR_WFL_COLNO
(cl
) == 0xffe ?
-2 : EXPR_WFL_COLNO
(cl
)));
3039 /* We have a CL, that's a good reason for using it if it contains data */
3040 saved
= ctxp
->filename
;
3041 if
(TREE_CODE
(cl
) == EXPR_WITH_FILE_LOCATION
&& EXPR_WFL_FILENAME_NODE
(cl
))
3042 ctxp
->filename
= EXPR_WFL_FILENAME
(cl
);
3043 saved_input_filename
= input_filename
;
3044 input_filename
= ctxp
->filename
;
3046 java_error
(buffer
);
3047 ctxp
->filename
= saved
;
3048 input_filename
= saved_input_filename
;
3052 /* Issue an error message at a current source line CL */
3055 parse_error_context VPARAMS
((tree cl
, const char *msg
, ...
))
3057 #ifndef ANSI_PROTOTYPES
3064 #ifndef ANSI_PROTOTYPES
3065 cl
= va_arg
(ap
, tree
);
3066 msg
= va_arg
(ap
, const char *);
3068 issue_warning_error_from_context
(cl
, msg
, ap
);
3072 /* Issue a warning at a current source line CL */
3075 parse_warning_context VPARAMS
((tree cl
, const char *msg
, ...
))
3077 #ifndef ANSI_PROTOTYPES
3084 #ifndef ANSI_PROTOTYPES
3085 cl
= va_arg
(ap
, tree
);
3086 msg
= va_arg
(ap
, const char *);
3089 force_error
= do_warning
= 1;
3090 issue_warning_error_from_context
(cl
, msg
, ap
);
3091 do_warning
= force_error
= 0;
3096 find_expr_with_wfl
(node
)
3104 switch
(TREE_CODE
(node
))
3107 node
= BLOCK_EXPR_BODY
(node
);
3111 to_return
= find_expr_with_wfl
(TREE_OPERAND
(node
, 0));
3114 node
= TREE_OPERAND
(node
, 1);
3118 node
= TREE_OPERAND
(node
, 0);
3121 case LABELED_BLOCK_EXPR
:
3122 node
= TREE_OPERAND
(node
, 1);
3126 code
= TREE_CODE_CLASS
(TREE_CODE
(node
));
3127 if
(((code
== '1') ||
(code
== '2') ||
(code
== 'e'))
3128 && EXPR_WFL_LINECOL
(node
))
3136 /* Issue a missing return statement error. Uses METHOD to figure the
3137 last line of the method the error occurs in. */
3140 missing_return_error
(method
)
3143 EXPR_WFL_SET_LINECOL
(wfl_operator
, DECL_SOURCE_LINE_LAST
(method
), -2);
3144 parse_error_context
(wfl_operator
, "Missing return statement");
3147 /* Issue an unreachable statement error. From NODE, find the next
3148 statement to report appropriately. */
3150 unreachable_stmt_error
(node
)
3153 /* Browse node to find the next expression node that has a WFL. Use
3154 the location to report the error */
3155 if
(TREE_CODE
(node
) == COMPOUND_EXPR
)
3156 node
= find_expr_with_wfl
(TREE_OPERAND
(node
, 1));
3158 node
= find_expr_with_wfl
(node
);
3162 EXPR_WFL_SET_LINECOL
(wfl_operator
, EXPR_WFL_LINENO
(node
), -2);
3163 parse_error_context
(wfl_operator
, "Unreachable statement");
3170 java_report_errors
()
3172 if
(java_error_count
)
3173 fprintf
(stderr
, "%d error%s",
3174 java_error_count
, (java_error_count
== 1 ?
"" : "s"));
3175 if
(java_warning_count
)
3176 fprintf
(stderr
, "%s%d warning%s", (java_error_count ?
", " : ""),
3177 java_warning_count
, (java_warning_count
== 1 ?
"" : "s"));
3178 if
(java_error_count || java_warning_count
)
3179 putc
('\n', stderr
);
3180 return java_error_count
;
3184 java_accstring_lookup
(flags
)
3187 static char buffer
[80];
3188 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3190 /* Access modifier looked-up first for easier report on forbidden
3192 if
(flags
& ACC_PUBLIC
) COPY_RETURN
("public");
3193 if
(flags
& ACC_PRIVATE
) COPY_RETURN
("private");
3194 if
(flags
& ACC_PROTECTED
) COPY_RETURN
("protected");
3195 if
(flags
& ACC_STATIC
) COPY_RETURN
("static");
3196 if
(flags
& ACC_FINAL
) COPY_RETURN
("final");
3197 if
(flags
& ACC_SYNCHRONIZED
) COPY_RETURN
("synchronized");
3198 if
(flags
& ACC_VOLATILE
) COPY_RETURN
("volatile");
3199 if
(flags
& ACC_TRANSIENT
) COPY_RETURN
("transient");
3200 if
(flags
& ACC_NATIVE
) COPY_RETURN
("native");
3201 if
(flags
& ACC_INTERFACE
) COPY_RETURN
("interface");
3202 if
(flags
& ACC_ABSTRACT
) COPY_RETURN
("abstract");
3209 /* Issuing error messages upon redefinition of classes, interfaces or
3213 classitf_redefinition_error
(context
, id
, decl
, cl
)
3214 const char *context
;
3217 parse_error_context
(cl
, "%s `%s' already defined in %s:%d",
3218 context
, IDENTIFIER_POINTER
(id
),
3219 DECL_SOURCE_FILE
(decl
), DECL_SOURCE_LINE
(decl
));
3220 /* Here we should point out where its redefined. It's a unicode. FIXME */
3224 variable_redefinition_error
(context
, name
, type
, line
)
3225 tree context
, name
, type
;
3228 const char *type_name
;
3230 /* Figure a proper name for type. We might haven't resolved it */
3231 if
(TREE_CODE
(type
) == POINTER_TYPE
&& !TREE_TYPE
(type
))
3232 type_name
= IDENTIFIER_POINTER
(TYPE_NAME
(type
));
3234 type_name
= lang_printable_name
(type
, 0);
3236 parse_error_context
(context
,
3237 "Variable `%s' is already defined in this method and was declared `%s %s' at line %d",
3238 IDENTIFIER_POINTER
(name
),
3239 type_name
, IDENTIFIER_POINTER
(name
), line
);
3243 build_array_from_name
(type
, type_wfl
, name
, ret_name
)
3244 tree type
, type_wfl
, name
, *ret_name
;
3249 /* Eventually get more dims */
3250 string = IDENTIFIER_POINTER
(name
);
3251 while
(string [more_dims
] == '[')
3254 /* If we have, then craft a new type for this variable */
3257 name
= get_identifier
(&string [more_dims
]);
3259 /* If we have a pointer, use its type */
3260 if
(TREE_CODE
(type
) == POINTER_TYPE
)
3261 type
= TREE_TYPE
(type
);
3263 /* Building the first dimension of a primitive type uses this
3265 if
(JPRIMITIVE_TYPE_P
(type
))
3267 type
= build_java_array_type
(type
, -1);
3268 CLASS_LOADED_P
(type
) = 1;
3271 /* Otherwise, if we have a WFL for this type, use it (the type
3272 is already an array on an unresolved type, and we just keep
3273 on adding dimensions) */
3277 /* Add all the dimensions */
3279 type
= build_unresolved_array_type
(type
);
3281 /* The type may have been incomplete in the first place */
3283 type
= obtain_incomplete_type
(type
);
3291 /* Build something that the type identifier resolver will identify as
3292 being an array to an unresolved type. TYPE_WFL is a WFL on a
3296 build_unresolved_array_type
(type_or_wfl
)
3301 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3302 just create a array type */
3303 if
(TREE_CODE
(type_or_wfl
) == RECORD_TYPE
)
3305 tree type
= build_java_array_type
(type_or_wfl
, -1);
3306 CLASS_LOADED_P
(type
) = CLASS_LOADED_P
(type_or_wfl
);
3310 obstack_1grow
(&temporary_obstack
, '[');
3311 obstack_grow0
(&temporary_obstack
,
3312 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(type_or_wfl
)),
3313 IDENTIFIER_LENGTH
(EXPR_WFL_NODE
(type_or_wfl
)));
3314 ptr
= obstack_finish
(&temporary_obstack
);
3315 EXPR_WFL_NODE
(type_or_wfl
) = get_identifier
(ptr
);
3320 parser_add_interface
(class_decl
, interface_decl
, wfl
)
3321 tree class_decl
, interface_decl
, wfl
;
3323 if
(maybe_add_interface
(TREE_TYPE
(class_decl
), TREE_TYPE
(interface_decl
)))
3324 parse_error_context
(wfl
, "Interface `%s' repeated",
3325 IDENTIFIER_POINTER
(DECL_NAME
(interface_decl
)));
3328 /* Bulk of common class/interface checks. Return 1 if an error was
3329 encountered. TAG is 0 for a class, 1 for an interface. */
3332 check_class_interface_creation
(is_interface
, flags
, raw_name
, qualified_name
, decl
, cl
)
3333 int is_interface
, flags
;
3334 tree raw_name
, qualified_name
, decl
, cl
;
3337 int sca
= 0; /* Static class allowed */
3338 int icaf
= 0; /* Inner class allowed flags */
3339 int uaaf
= CLASS_MODIFIERS
; /* Usually allowed access flags */
3342 fprintf
(stderr
, " %s%s %s",
3343 (CPC_INNER_P
() ?
"inner" : ""),
3344 (is_interface ?
"interface" : "class"),
3345 IDENTIFIER_POINTER
(qualified_name
));
3347 /* Scope of an interface/class type name:
3348 - Can't be imported by a single type import
3349 - Can't already exists in the package */
3350 if
(IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(raw_name
)
3351 && (node
= find_name_in_single_imports
(raw_name
))
3355 (cl
, "%s name `%s' clashes with imported type `%s'",
3356 (is_interface ?
"Interface" : "Class"),
3357 IDENTIFIER_POINTER
(raw_name
), IDENTIFIER_POINTER
(node
));
3360 if
(decl
&& CLASS_COMPLETE_P
(decl
))
3362 classitf_redefinition_error
((is_interface ?
"Interface" : "Class"),
3363 qualified_name
, decl
, cl
);
3367 if
(check_inner_class_redefinition
(raw_name
, cl
))
3370 /* If public, file name should match class/interface name, except
3371 when dealing with an inner class */
3372 if
(!CPC_INNER_P
() && (flags
& ACC_PUBLIC
))
3376 /* Contains OS dependent assumption on path separator. FIXME */
3377 for
(f
= &input_filename
[strlen
(input_filename
)];
3378 f
!= input_filename
&& f
[0] != '/' && f
[0] != DIR_SEPARATOR
;
3381 if
(f
[0] == '/' || f
[0] == DIR_SEPARATOR
)
3383 if
(strncmp
(IDENTIFIER_POINTER
(raw_name
),
3384 f
, IDENTIFIER_LENGTH
(raw_name
)) ||
3385 f
[IDENTIFIER_LENGTH
(raw_name
)] != '.')
3387 (cl
, "Public %s `%s' must be defined in a file called `%s.java'",
3388 (is_interface ?
"interface" : "class"),
3389 IDENTIFIER_POINTER
(qualified_name
),
3390 IDENTIFIER_POINTER
(raw_name
));
3393 /* Static classes can be declared only in top level classes. Note:
3394 once static, a inner class is a top level class. */
3395 if
(flags
& ACC_STATIC
)
3397 /* Catch the specific error of declaring an class inner class
3398 with no toplevel enclosing class. Prevent check_modifiers from
3399 complaining a second time */
3400 if
(CPC_INNER_P
() && !TOPLEVEL_CLASS_DECL_P
(GET_CPC
()))
3402 parse_error_context
(cl
, "Inner class `%s' can't be static. Static classes can only occur in interfaces and top-level classes",
3403 IDENTIFIER_POINTER
(qualified_name
));
3406 /* Else, in the context of a top-level class declaration, let
3407 `check_modifiers' do its job, otherwise, give it a go */
3409 sca
= (GET_CPC_LIST
() ? ACC_STATIC
: 0);
3412 /* Inner classes can be declared private or protected
3413 within their enclosing classes. */
3416 /* A class which is local to a block can't be public, private,
3417 protected or static. But it is created final, so allow this
3419 if
(current_function_decl
)
3420 icaf
= sca
= uaaf
= ACC_FINAL
;
3423 check_modifiers_consistency
(flags
);
3424 icaf
= ACC_PRIVATE|ACC_PROTECTED
;
3431 uaaf
= INTERFACE_INNER_MODIFIERS
;
3433 uaaf
= INTERFACE_MODIFIERS
;
3435 check_modifiers
("Illegal modifier `%s' for interface declaration",
3439 check_modifiers
((current_function_decl ?
3440 "Illegal modifier `%s' for local class declaration" :
3441 "Illegal modifier `%s' for class declaration"),
3442 flags
, uaaf|sca|icaf
);
3447 make_nested_class_name
(cpc_list
)
3455 make_nested_class_name
(TREE_CHAIN
(cpc_list
));
3457 /* Pick the qualified name when dealing with the first upmost
3459 name
= (TREE_CHAIN
(cpc_list
) ?
3460 TREE_PURPOSE
(cpc_list
) : DECL_NAME
(TREE_VALUE
(cpc_list
)));
3461 obstack_grow
(&temporary_obstack
,
3462 IDENTIFIER_POINTER
(name
), IDENTIFIER_LENGTH
(name
));
3463 /* Why is NO_DOLLAR_IN_LABEL defined? */
3465 #ifdef NO_DOLLAR_IN_LABEL
3466 internal_error
("Can't use '$' as a separator for inner classes");
3469 obstack_1grow
(&temporary_obstack
, '$');
3472 /* Can't redefine a class already defined in an earlier scope. */
3475 check_inner_class_redefinition
(raw_name
, cl
)
3480 for
(scope_list
= GET_CPC_LIST
(); scope_list
;
3481 scope_list
= GET_NEXT_ENCLOSING_CPC
(scope_list
))
3482 if
(raw_name
== GET_CPC_UN_NODE
(scope_list
))
3485 (cl
, "The class name `%s' is already defined in this scope. An inner class may not have the same simple name as any of its enclosing classes",
3486 IDENTIFIER_POINTER
(raw_name
));
3493 find_as_inner_class
(enclosing
, name
, cl
)
3494 tree enclosing
, name
, cl
;
3496 tree qual
, to_return
;
3500 name
= TYPE_NAME
(name
);
3502 /* First search: within the scope of `enclosing', search for name */
3503 if
(QUALIFIED_P
(name
) && cl
&& EXPR_WFL_NODE
(cl
) == name
)
3504 qual
= EXPR_WFL_QUALIFICATION
(cl
);
3506 qual
= build_tree_list
(cl
, NULL_TREE
);
3508 qual
= build_tree_list
(build_expr_wfl
(name
, NULL
, 0, 0), NULL_TREE
);
3510 if
((to_return
= find_as_inner_class_do
(qual
, enclosing
)))
3513 /* We're dealing with a qualified name. Try to resolve thing until
3514 we get something that is an enclosing class. */
3515 if
(QUALIFIED_P
(name
) && cl
&& EXPR_WFL_NODE
(cl
) == name
)
3517 tree acc
= NULL_TREE
, decl
= NULL_TREE
, ptr
;
3519 for
(qual
= EXPR_WFL_QUALIFICATION
(cl
); qual
&& !decl
;
3520 qual
= TREE_CHAIN
(qual
))
3522 acc
= merge_qualified_name
(acc
,
3523 EXPR_WFL_NODE
(TREE_PURPOSE
(qual
)));
3524 BUILD_PTR_FROM_NAME
(ptr
, acc
);
3526 /* Don't try to resolve ACC as a class name if it follows
3527 the current package name. We don't want to pick something
3528 that's accidentally there: for example `a.b.c' in package
3529 `a.b' shouldn't trigger loading `a' if it's there by
3532 && strstr
(IDENTIFIER_POINTER
(ctxp
->package
),
3533 IDENTIFIER_POINTER
(acc
)))
3536 decl
= do_resolve_class
(NULL_TREE
, ptr
, NULL_TREE
, cl
);
3539 /* A NULL qual and a decl means that the search ended
3540 successfully?!? We have to do something then. FIXME */
3545 qual
= EXPR_WFL_QUALIFICATION
(cl
);
3547 /* Otherwise, create a qual for the other part of the resolution. */
3549 qual
= build_tree_list
(build_expr_wfl
(name
, NULL
, 0, 0), NULL_TREE
);
3551 return find_as_inner_class_do
(qual
, enclosing
);
3554 /* We go inside the list of sub classes and try to find a way
3558 find_as_inner_class_do
(qual
, enclosing
)
3559 tree qual
, enclosing
;
3564 for
(; qual
&& enclosing
; qual
= TREE_CHAIN
(qual
))
3566 tree name_to_match
= EXPR_WFL_NODE
(TREE_PURPOSE
(qual
));
3567 tree next_enclosing
= NULL_TREE
;
3570 for
(inner_list
= DECL_INNER_CLASS_LIST
(enclosing
);
3571 inner_list
; inner_list
= TREE_CHAIN
(inner_list
))
3573 if
(TREE_VALUE
(inner_list
) == name_to_match
)
3575 next_enclosing
= TREE_PURPOSE
(inner_list
);
3579 enclosing
= next_enclosing
;
3582 return
(!qual
&& enclosing ? enclosing
: NULL_TREE
);
3585 /* Reach all inner classes and tie their unqualified name to a
3589 set_nested_class_simple_name_value
(outer
, set
)
3595 for
(l
= DECL_INNER_CLASS_LIST
(outer
); l
; l
= TREE_CHAIN
(l
))
3596 IDENTIFIER_GLOBAL_VALUE
(TREE_VALUE
(l
)) = (set ?
3597 TREE_PURPOSE
(l
) : NULL_TREE
);
3601 link_nested_class_to_enclosing
()
3603 if
(GET_ENCLOSING_CPC
())
3605 tree enclosing
= GET_ENCLOSING_CPC_CONTEXT
();
3606 DECL_INNER_CLASS_LIST
(enclosing
) =
3607 tree_cons
(GET_CPC
(), GET_CPC_UN
(),
3608 DECL_INNER_CLASS_LIST
(enclosing
));
3609 enclosing
= enclosing
;
3614 maybe_make_nested_class_name
(name
)
3617 tree id
= NULL_TREE
;
3621 make_nested_class_name
(GET_CPC_LIST
());
3622 obstack_grow0
(&temporary_obstack
,
3623 IDENTIFIER_POINTER
(name
),
3624 IDENTIFIER_LENGTH
(name
));
3625 id
= get_identifier
(obstack_finish
(&temporary_obstack
));
3627 QUALIFIED_P
(id
) = 1;
3632 /* If DECL is NULL, create and push a new DECL, record the current
3633 line CL and do other maintenance things. */
3636 maybe_create_class_interface_decl
(decl
, raw_name
, qualified_name
, cl
)
3637 tree decl
, raw_name
, qualified_name
, cl
;
3640 decl
= push_class
(make_class
(), qualified_name
);
3642 /* Take care of the file and line business */
3643 DECL_SOURCE_FILE
(decl
) = EXPR_WFL_FILENAME
(cl
);
3644 /* If we're emiting xrefs, store the line/col number information */
3646 DECL_SOURCE_LINE
(decl
) = EXPR_WFL_LINECOL
(cl
);
3648 DECL_SOURCE_LINE
(decl
) = EXPR_WFL_LINENO
(cl
);
3649 CLASS_FROM_SOURCE_P
(TREE_TYPE
(decl
)) = 1;
3650 CLASS_FROM_CURRENTLY_COMPILED_P
(TREE_TYPE
(decl
)) =
3651 IS_A_COMMAND_LINE_FILENAME_P
(EXPR_WFL_FILENAME_NODE
(cl
));
3653 PUSH_CPC
(decl
, raw_name
);
3654 DECL_CONTEXT
(decl
) = GET_ENCLOSING_CPC_CONTEXT
();
3656 /* Link the declaration to the already seen ones */
3657 TREE_CHAIN
(decl
) = ctxp
->class_list
;
3658 ctxp
->class_list
= decl
;
3660 /* Create a new nodes in the global lists */
3661 gclass_list
= tree_cons
(NULL_TREE
, decl
, gclass_list
);
3662 all_class_list
= tree_cons
(NULL_TREE
, decl
, all_class_list
);
3664 /* Install a new dependency list element */
3665 create_jdep_list
(ctxp
);
3667 SOURCE_FRONTEND_DEBUG
(("Defining class/interface %s",
3668 IDENTIFIER_POINTER
(qualified_name
)));
3673 add_superinterfaces
(decl
, interface_list
)
3674 tree decl
, interface_list
;
3677 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3678 takes care of ensuring that:
3679 - This is an accessible interface type,
3680 - Circularity detection.
3681 parser_add_interface is then called. If present but not defined,
3682 the check operation is delayed until the super interface gets
3684 for
(node
= interface_list
; node
; node
= TREE_CHAIN
(node
))
3686 tree current
= TREE_PURPOSE
(node
);
3687 tree idecl
= IDENTIFIER_CLASS_VALUE
(EXPR_WFL_NODE
(current
));
3688 if
(idecl
&& CLASS_LOADED_P
(TREE_TYPE
(idecl
)))
3690 if
(!parser_check_super_interface
(idecl
, decl
, current
))
3691 parser_add_interface
(decl
, idecl
, current
);
3694 register_incomplete_type
(JDEP_INTERFACE
,
3695 current
, decl
, NULL_TREE
);
3699 /* Create an interface in pass1 and return its decl. Return the
3700 interface's decl in pass 2. */
3703 create_interface
(flags
, id
, super
)
3707 tree raw_name
= EXPR_WFL_NODE
(id
);
3708 tree q_name
= parser_qualified_classname
(raw_name
);
3709 tree decl
= IDENTIFIER_CLASS_VALUE
(q_name
);
3711 EXPR_WFL_NODE
(id
) = q_name
; /* Keep source location, even if refined. */
3713 /* Basic checks: scope, redefinition, modifiers */
3714 if
(check_class_interface_creation
(1, flags
, raw_name
, q_name
, decl
, id
))
3720 /* Suspend the current parsing context if we're parsing an inner
3723 java_parser_context_suspend
();
3725 /* Push a new context for (static) initialized upon declaration fields */
3726 java_parser_context_push_initialized_field
();
3728 /* Interface modifiers check
3729 - public/abstract allowed (already done at that point)
3730 - abstract is obsolete (comes first, it's a warning, or should be)
3731 - Can't use twice the same (checked in the modifier rule) */
3732 if
((flags
& ACC_ABSTRACT
) && flag_redundant
)
3733 parse_warning_context
3734 (MODIFIER_WFL
(ABSTRACT_TK
),
3735 "Redundant use of `abstract' modifier. Interface `%s' is implicitely abstract", IDENTIFIER_POINTER
(raw_name
));
3737 /* Create a new decl if DECL is NULL, otherwise fix it */
3738 decl
= maybe_create_class_interface_decl
(decl
, raw_name
, q_name
, id
);
3740 /* Set super info and mark the class a complete */
3741 set_super_info
(ACC_INTERFACE | flags
, TREE_TYPE
(decl
),
3742 object_type_node
, ctxp
->interface_number
);
3743 ctxp
->interface_number
= 0;
3744 CLASS_COMPLETE_P
(decl
) = 1;
3745 add_superinterfaces
(decl
, super
);
3750 /* Anonymous class counter. Will be reset to 1 every time a non
3751 anonymous class gets created. */
3752 static int anonymous_class_counter
= 1;
3754 /* Patch anonymous class CLASS, by either extending or implementing
3758 patch_anonymous_class
(type_decl
, class_decl
, wfl
)
3759 tree type_decl
, class_decl
, wfl
;
3761 tree class
= TREE_TYPE
(class_decl
);
3762 tree type
= TREE_TYPE
(type_decl
);
3763 tree binfo
= TYPE_BINFO
(class
);
3765 /* If it's an interface, implement it */
3766 if
(CLASS_INTERFACE
(type_decl
))
3771 if
(parser_check_super_interface
(type_decl
, class_decl
, wfl
))
3774 s_binfo
= TREE_VEC_ELT
(BINFO_BASETYPES
(TYPE_BINFO
(class
)), 0);
3775 length
= TREE_VEC_LENGTH
(TYPE_BINFO_BASETYPES
(class
))+1;
3776 TYPE_BINFO_BASETYPES
(class
) = make_tree_vec
(length
);
3777 TREE_VEC_ELT
(BINFO_BASETYPES
(TYPE_BINFO
(class
)), 0) = s_binfo
;
3778 /* And add the interface */
3779 parser_add_interface
(class_decl
, type_decl
, wfl
);
3781 /* Otherwise, it's a type we want to extend */
3784 if
(parser_check_super
(type_decl
, class_decl
, wfl
))
3786 BINFO_TYPE
(TREE_VEC_ELT
(BINFO_BASETYPES
(binfo
), 0)) = type
;
3791 create_anonymous_class
(location
, type_name
)
3796 tree super
= NULL_TREE
, itf
= NULL_TREE
;
3797 tree id
, type_decl
, class
;
3799 /* The unqualified name of the anonymous class. It's just a number. */
3800 sprintf
(buffer
, "%d", anonymous_class_counter
++);
3801 id
= build_wfl_node
(get_identifier
(buffer
));
3802 EXPR_WFL_LINECOL
(id
) = location
;
3804 /* We know about the type to extend/implement. We go ahead */
3805 if
((type_decl
= IDENTIFIER_CLASS_VALUE
(EXPR_WFL_NODE
(type_name
))))
3807 /* Create a class which either implements on extends the designated
3808 class. The class bears an innacessible name. */
3809 if
(CLASS_INTERFACE
(type_decl
))
3811 /* It's OK to modify it here. It's been already used and
3812 shouldn't be reused */
3813 ctxp
->interface_number
= 1;
3814 /* Interfaces should presented as a list of WFLs */
3815 itf
= build_tree_list
(type_name
, NULL_TREE
);
3821 class
= create_class
(ACC_FINAL
, id
, super
, itf
);
3823 /* We didn't know anything about the stuff. We register a dependence. */
3825 register_incomplete_type
(JDEP_ANONYMOUS
, type_name
, class
, NULL_TREE
);
3827 ANONYMOUS_CLASS_P
(TREE_TYPE
(class
)) = 1;
3831 /* Create a class in pass1 and return its decl. Return class
3832 interface's decl in pass 2. */
3835 create_class
(flags
, id
, super
, interfaces
)
3837 tree id
, super
, interfaces
;
3839 tree raw_name
= EXPR_WFL_NODE
(id
);
3840 tree class_id
, decl
;
3841 tree super_decl_type
;
3843 class_id
= parser_qualified_classname
(raw_name
);
3844 decl
= IDENTIFIER_CLASS_VALUE
(class_id
);
3845 EXPR_WFL_NODE
(id
) = class_id
;
3847 /* Basic check: scope, redefinition, modifiers */
3848 if
(check_class_interface_creation
(0, flags
, raw_name
, class_id
, decl
, id
))
3854 /* Suspend the current parsing context if we're parsing an inner
3855 class or an anonymous class. */
3857 java_parser_context_suspend
();
3858 /* Push a new context for (static) initialized upon declaration fields */
3859 java_parser_context_push_initialized_field
();
3861 /* Class modifier check:
3862 - Allowed modifier (already done at that point)
3863 - abstract AND final forbidden
3864 - Public classes defined in the correct file */
3865 if
((flags
& ACC_ABSTRACT
) && (flags
& ACC_FINAL
))
3867 (id
, "Class `%s' can't be declared both abstract and final",
3868 IDENTIFIER_POINTER
(raw_name
));
3870 /* Create a new decl if DECL is NULL, otherwise fix it */
3871 decl
= maybe_create_class_interface_decl
(decl
, raw_name
, class_id
, id
);
3873 /* If SUPER exists, use it, otherwise use Object */
3876 /* Can't extend java.lang.Object */
3877 if
(TREE_TYPE
(IDENTIFIER_CLASS_VALUE
(class_id
)) == object_type_node
)
3879 parse_error_context
(id
, "Can't extend `java.lang.Object'");
3884 register_incomplete_type
(JDEP_SUPER
, super
, decl
, NULL_TREE
);
3886 else if
(TREE_TYPE
(decl
) != object_type_node
)
3887 super_decl_type
= object_type_node
;
3888 /* We're defining java.lang.Object */
3890 super_decl_type
= NULL_TREE
;
3892 /* A class nested in an interface is implicitly static. */
3893 if
(INNER_CLASS_DECL_P
(decl
)
3894 && CLASS_INTERFACE
(TYPE_NAME
(TREE_TYPE
(DECL_CONTEXT
(decl
)))))
3896 flags |
= ACC_STATIC
;
3899 /* Set super info and mark the class as complete. */
3900 set_super_info
(flags
, TREE_TYPE
(decl
), super_decl_type
,
3901 ctxp
->interface_number
);
3902 ctxp
->interface_number
= 0;
3903 CLASS_COMPLETE_P
(decl
) = 1;
3904 add_superinterfaces
(decl
, interfaces
);
3906 /* Add the private this$<n> field, Replicate final locals still in
3907 scope as private final fields mangled like val$<local_name>.
3908 This doesn't not occur for top level (static) inner classes. */
3909 if
(PURE_INNER_CLASS_DECL_P
(decl
))
3910 add_inner_class_fields
(decl
, current_function_decl
);
3912 /* If doing xref, store the location at which the inherited class
3913 (if any) was seen. */
3914 if
(flag_emit_xref
&& super
)
3915 DECL_INHERITED_SOURCE_LINE
(decl
) = EXPR_WFL_LINECOL
(super
);
3917 /* Eventually sets the @deprecated tag flag */
3918 CHECK_DEPRECATED
(decl
);
3920 /* Reset the anonymous class counter when declaring non inner classes */
3921 if
(!INNER_CLASS_DECL_P
(decl
))
3922 anonymous_class_counter
= 1;
3927 /* End a class declaration: register the statements used to create
3928 finit$ and <clinit>, pop the current class and resume the prior
3929 parser context if necessary. */
3932 end_class_declaration
(resume
)
3935 /* If an error occured, context weren't pushed and won't need to be
3936 popped by a resume. */
3937 int no_error_occured
= ctxp
->next
&& GET_CPC
() != error_mark_node
;
3939 java_parser_context_pop_initialized_field
();
3941 if
(resume
&& no_error_occured
)
3942 java_parser_context_resume
();
3944 /* We're ending a class declaration, this is a good time to reset
3945 the interface cout. Note that might have been already done in
3946 create_interface, but if at that time an inner class was being
3947 dealt with, the interface count was reset in a context created
3948 for the sake of handling inner classes declaration. */
3949 ctxp
->interface_number
= 0;
3953 add_inner_class_fields
(class_decl
, fct_decl
)
3957 tree block
, marker
, f
;
3959 f
= add_field
(TREE_TYPE
(class_decl
),
3960 build_current_thisn
(TREE_TYPE
(class_decl
)),
3961 build_pointer_type
(TREE_TYPE
(DECL_CONTEXT
(class_decl
))),
3963 FIELD_THISN
(f
) = 1;
3968 for
(block
= GET_CURRENT_BLOCK
(fct_decl
);
3969 block
&& TREE_CODE
(block
) == BLOCK
; block
= BLOCK_SUPERCONTEXT
(block
))
3972 for
(decl
= BLOCK_EXPR_DECLS
(block
); decl
; decl
= TREE_CHAIN
(decl
))
3975 tree wfl
, init
, list
;
3977 /* Avoid non final arguments. */
3978 if
(!LOCAL_FINAL_P
(decl
))
3981 MANGLE_OUTER_LOCAL_VARIABLE_NAME
(name
, DECL_NAME
(decl
));
3982 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID
(pname
, DECL_NAME
(decl
));
3983 wfl
= build_wfl_node
(name
);
3984 init
= build_wfl_node
(pname
);
3985 /* Build an initialization for the field: it will be
3986 initialized by a parameter added to finit$, bearing a
3987 mangled name of the field itself (param$<n>.) The
3988 parameter is provided to finit$ by the constructor
3989 invoking it (hence the constructor will also feature a
3990 hidden parameter, set to the value of the outer context
3991 local at the time the inner class is created.)
3993 Note: we take into account all possible locals that can
3994 be accessed by the inner class. It's actually not trivial
3995 to minimize these aliases down to the ones really
3996 used. One way to do that would be to expand all regular
3997 methods first, then finit$ to get a picture of what's
3998 used. It works with the exception that we would have to
3999 go back on all constructor invoked in regular methods to
4000 have their invokation reworked (to include the right amount
4001 of alias initializer parameters.)
4003 The only real way around, I think, is a first pass to
4004 identify locals really used in the inner class. We leave
4005 the flag FIELD_LOCAL_ALIAS_USED around for that future
4008 On the other hand, it only affect local inner classes,
4009 whose constructors (and finit$ call) will be featuring
4010 unecessary arguments. It's easy for a developper to keep
4011 this number of parameter down by using the `final'
4012 keyword only when necessary. For the time being, we can
4013 issue a warning on unecessary finals. FIXME */
4014 init
= build_assignment
(ASSIGN_TK
, EXPR_WFL_LINECOL
(wfl
),
4017 /* Register the field. The TREE_LIST holding the part
4018 initialized/initializer will be marked ARG_FINAL_P so
4019 that the created field can be marked
4020 FIELD_LOCAL_ALIAS. */
4021 list
= build_tree_list
(wfl
, init
);
4022 ARG_FINAL_P
(list
) = 1;
4023 register_fields
(ACC_PRIVATE | ACC_FINAL
, TREE_TYPE
(decl
), list
);
4027 if
(!CPC_INITIALIZER_STMT
(ctxp
))
4030 /* If we ever registered an alias field, insert and marker to
4031 remeber where the list ends. The second part of the list (the one
4032 featuring initialized fields) so it can be later reversed to
4033 enforce 8.5. The marker will be removed during that operation. */
4034 marker
= build_tree_list
(NULL_TREE
, NULL_TREE
);
4035 TREE_CHAIN
(marker
) = CPC_INITIALIZER_STMT
(ctxp
);
4036 SET_CPC_INITIALIZER_STMT
(ctxp
, marker
);
4039 /* Can't use lookup_field () since we don't want to load the class and
4040 can't set the CLASS_LOADED_P flag */
4043 find_field
(class
, name
)
4048 for
(decl
= TYPE_FIELDS
(class
); decl
; decl
= TREE_CHAIN
(decl
))
4050 if
(DECL_NAME
(decl
) == name
)
4056 /* Wrap around lookup_field that doesn't potentially upset the value
4060 lookup_field_wrapper
(class
, name
)
4064 tree decl
= NULL_TREE
;
4065 java_parser_context_save_global
();
4067 /* Last chance: if we're within the context of an inner class, we
4068 might be trying to access a local variable defined in an outer
4069 context. We try to look for it now. */
4070 if
(INNER_CLASS_TYPE_P
(class
))
4073 MANGLE_OUTER_LOCAL_VARIABLE_NAME
(new_name
, name
);
4074 decl
= lookup_field
(&type
, new_name
);
4075 if
(decl
&& decl
!= error_mark_node
)
4076 FIELD_LOCAL_ALIAS_USED
(decl
) = 1;
4078 if
(!decl || decl
== error_mark_node
)
4081 decl
= lookup_field
(&type
, name
);
4084 java_parser_context_restore_global
();
4085 return decl
== error_mark_node ? NULL
: decl
;
4088 /* Find duplicate field within the same class declarations and report
4089 the error. Returns 1 if a duplicated field was found, 0
4093 duplicate_declaration_error_p
(new_field_name
, new_type
, cl
)
4094 tree new_field_name
, new_type
, cl
;
4096 /* This might be modified to work with method decl as well */
4097 tree decl
= find_field
(TREE_TYPE
(GET_CPC
()), new_field_name
);
4100 char *t1
= xstrdup
(purify_type_name
4101 ((TREE_CODE
(new_type
) == POINTER_TYPE
4102 && TREE_TYPE
(new_type
) == NULL_TREE
) ?
4103 IDENTIFIER_POINTER
(TYPE_NAME
(new_type
)) :
4104 lang_printable_name
(new_type
, 1)));
4105 /* The type may not have been completed by the time we report
4107 char *t2
= xstrdup
(purify_type_name
4108 ((TREE_CODE
(TREE_TYPE
(decl
)) == POINTER_TYPE
4109 && TREE_TYPE
(TREE_TYPE
(decl
)) == NULL_TREE
) ?
4110 IDENTIFIER_POINTER
(TYPE_NAME
(TREE_TYPE
(decl
))) :
4111 lang_printable_name
(TREE_TYPE
(decl
), 1)));
4113 (cl
, "Duplicate variable declaration: `%s %s' was `%s %s' (%s:%d)",
4114 t1
, IDENTIFIER_POINTER
(new_field_name
),
4115 t2
, IDENTIFIER_POINTER
(DECL_NAME
(decl
)),
4116 DECL_SOURCE_FILE
(decl
), DECL_SOURCE_LINE
(decl
));
4124 /* Field registration routine. If TYPE doesn't exist, field
4125 declarations are linked to the undefined TYPE dependency list, to
4126 be later resolved in java_complete_class () */
4129 register_fields
(flags
, type
, variable_list
)
4131 tree type
, variable_list
;
4133 tree current
, saved_type
;
4134 tree class_type
= NULL_TREE
;
4135 int saved_lineno
= lineno
;
4137 tree wfl
= NULL_TREE
;
4140 class_type
= TREE_TYPE
(GET_CPC
());
4142 if
(!class_type || class_type
== error_mark_node
)
4145 /* If we're adding fields to interfaces, those fields are public,
4147 if
(CLASS_INTERFACE
(TYPE_NAME
(class_type
)))
4149 OBSOLETE_MODIFIER_WARNING
(MODIFIER_WFL
(PUBLIC_TK
),
4150 flags
, ACC_PUBLIC
, "interface field(s)");
4151 OBSOLETE_MODIFIER_WARNING
(MODIFIER_WFL
(STATIC_TK
),
4152 flags
, ACC_STATIC
, "interface field(s)");
4153 OBSOLETE_MODIFIER_WARNING
(MODIFIER_WFL
(FINAL_TK
),
4154 flags
, ACC_FINAL
, "interface field(s)");
4155 check_modifiers
("Illegal interface member modifier `%s'", flags
,
4156 INTERFACE_FIELD_MODIFIERS
);
4157 flags |
= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL
);
4160 /* Obtain a suitable type for resolution, if necessary */
4161 SET_TYPE_FOR_RESOLUTION
(type
, wfl
, must_chain
);
4163 /* If TYPE is fully resolved and we don't have a reference, make one */
4164 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
4166 for
(current
= variable_list
, saved_type
= type
; current
;
4167 current
= TREE_CHAIN
(current
), type
= saved_type
)
4171 tree cl
= TREE_PURPOSE
(current
);
4172 tree init
= TREE_VALUE
(current
);
4173 tree current_name
= EXPR_WFL_NODE
(cl
);
4175 /* Can't declare non-final static fields in inner classes */
4176 if
((flags
& ACC_STATIC
) && !TOPLEVEL_CLASS_TYPE_P
(class_type
)
4177 && !(flags
& ACC_FINAL
))
4179 (cl
, "Field `%s' can't be static in inner class `%s' unless it is final",
4180 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(cl
)),
4181 lang_printable_name
(class_type
, 0));
4183 /* Process NAME, as it may specify extra dimension(s) for it */
4184 type
= build_array_from_name
(type
, wfl
, current_name
, ¤t_name
);
4186 /* Type adjustment. We may have just readjusted TYPE because
4187 the variable specified more dimensions. Make sure we have
4188 a reference if we can and don't have one already. Also
4189 change the name if we have an init. */
4190 if
(type
!= saved_type
)
4192 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
4194 EXPR_WFL_NODE
(TREE_OPERAND
(init
, 0)) = current_name
;
4197 real_type
= GET_REAL_TYPE
(type
);
4198 /* Check for redeclarations */
4199 if
(duplicate_declaration_error_p
(current_name
, real_type
, cl
))
4202 /* Set lineno to the line the field was found and create a
4203 declaration for it. Eventually sets the @deprecated tag flag. */
4205 lineno
= EXPR_WFL_LINECOL
(cl
);
4207 lineno
= EXPR_WFL_LINENO
(cl
);
4208 field_decl
= add_field
(class_type
, current_name
, real_type
, flags
);
4209 CHECK_DEPRECATED
(field_decl
);
4211 /* If the field denotes a final instance variable, then we
4212 allocate a LANG_DECL_SPECIFIC part to keep track of its
4213 initialization. We also mark whether the field was
4214 initialized upon it's declaration. We don't do that if the
4215 created field is an alias to a final local. */
4216 if
(!ARG_FINAL_P
(current
) && (flags
& ACC_FINAL
))
4218 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(field_decl
);
4219 DECL_FIELD_FINAL_WFL
(field_decl
) = cl
;
4220 if
((flags
& ACC_STATIC
) && init
)
4221 DECL_FIELD_FINAL_IUD
(field_decl
) = 1;
4224 /* If the couple initializer/initialized is marked ARG_FINAL_P,
4225 we mark the created field FIELD_LOCAL_ALIAS, so that we can
4226 hide parameters to this inner class finit$ and
4227 constructors. It also means that the field isn't final per
4229 if
(ARG_FINAL_P
(current
))
4231 FIELD_LOCAL_ALIAS
(field_decl
) = 1;
4232 FIELD_FINAL
(field_decl
) = 0;
4235 /* Check if we must chain. */
4237 register_incomplete_type
(JDEP_FIELD
, wfl
, field_decl
, type
);
4239 /* If we have an initialization value tied to the field */
4242 /* The field is declared static */
4243 if
(flags
& ACC_STATIC
)
4245 /* We include the field and its initialization part into
4246 a list used to generate <clinit>. After <clinit> is
4247 walked, field initializations will be processed and
4248 fields initialized with known constants will be taken
4249 out of <clinit> and have their DECL_INITIAL set
4251 TREE_CHAIN
(init
) = CPC_STATIC_INITIALIZER_STMT
(ctxp
);
4252 SET_CPC_STATIC_INITIALIZER_STMT
(ctxp
, init
);
4253 if
(TREE_OPERAND
(init
, 1)
4254 && TREE_CODE
(TREE_OPERAND
(init
, 1)) == NEW_ARRAY_INIT
)
4255 TREE_STATIC
(TREE_OPERAND
(init
, 1)) = 1;
4257 /* A non-static field declared with an immediate initialization is
4258 to be initialized in <init>, if any. This field is remembered
4259 to be processed at the time of the generation of <init>. */
4262 TREE_CHAIN
(init
) = CPC_INITIALIZER_STMT
(ctxp
);
4263 SET_CPC_INITIALIZER_STMT
(ctxp
, init
);
4265 MODIFY_EXPR_FROM_INITIALIZATION_P
(init
) = 1;
4266 DECL_INITIAL
(field_decl
) = TREE_OPERAND
(init
, 1);
4269 lineno
= saved_lineno
;
4272 /* Generate finit$, using the list of initialized fields to populate
4273 its body. finit$'s parameter(s) list is adjusted to include the
4274 one(s) used to initialized the field(s) caching outer context
4278 generate_finit
(class_type
)
4282 tree list
= TYPE_FINIT_STMT_LIST
(class_type
);
4283 tree mdecl
, current
, parms
;
4285 parms
= build_alias_initializer_parameter_list
(AIPL_FUNCTION_CREATION
,
4286 class_type
, NULL_TREE
,
4288 CRAFTED_PARAM_LIST_FIXUP
(parms
);
4289 mdecl
= create_artificial_method
(class_type
, ACC_PRIVATE
, void_type_node
,
4290 finit_identifier_node
, parms
);
4291 fix_method_argument_names
(parms
, mdecl
);
4292 layout_class_method
(class_type
, CLASSTYPE_SUPER
(class_type
),
4294 DECL_FUNCTION_NAP
(mdecl
) = count
;
4295 start_artificial_method_body
(mdecl
);
4297 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
4298 java_method_add_stmt
(mdecl
,
4299 build_debugable_stmt
(EXPR_WFL_LINECOL
(current
),
4301 end_artificial_method_body
(mdecl
);
4306 add_instance_initializer
(mdecl
)
4310 tree stmt_list
= TYPE_II_STMT_LIST
(DECL_CONTEXT
(mdecl
));
4311 tree compound
= NULL_TREE
;
4315 for
(current
= stmt_list
; current
; current
= TREE_CHAIN
(current
))
4316 compound
= add_stmt_to_compound
(compound
, NULL_TREE
, current
);
4318 java_method_add_stmt
(mdecl
, build1
(INSTANCE_INITIALIZERS_EXPR
,
4319 NULL_TREE
, compound
));
4323 /* Shared accros method_declarator and method_header to remember the
4324 patch stage that was reached during the declaration of the method.
4325 A method DECL is built differently is there is no patch
4326 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
4327 pending on the currently defined method. */
4329 static int patch_stage
;
4331 /* Check the method declaration and add the method to its current
4332 class. If the argument list is known to contain incomplete types,
4333 the method is partially added and the registration will be resume
4334 once the method arguments resolved. If TYPE is NULL, we're dealing
4335 with a constructor. */
4338 method_header
(flags
, type
, mdecl
, throws
)
4340 tree type
, mdecl
, throws
;
4342 tree type_wfl
= NULL_TREE
;
4343 tree meth_name
= NULL_TREE
;
4344 tree current
, orig_arg
, this_class
= NULL
;
4347 int constructor_ok
= 0, must_chain
;
4350 if
(mdecl
== error_mark_node
)
4351 return error_mark_node
;
4352 meth
= TREE_VALUE
(mdecl
);
4353 id
= TREE_PURPOSE
(mdecl
);
4355 check_modifiers_consistency
(flags
);
4358 this_class
= TREE_TYPE
(GET_CPC
());
4360 if
(!this_class || this_class
== error_mark_node
)
4363 /* There are some forbidden modifiers for an abstract method and its
4364 class must be abstract as well. */
4365 if
(type
&& (flags
& ACC_ABSTRACT
))
4367 ABSTRACT_CHECK
(flags
, ACC_PRIVATE
, id
, "Private");
4368 ABSTRACT_CHECK
(flags
, ACC_STATIC
, id
, "Static");
4369 ABSTRACT_CHECK
(flags
, ACC_FINAL
, id
, "Final");
4370 ABSTRACT_CHECK
(flags
, ACC_NATIVE
, id
, "Native");
4371 ABSTRACT_CHECK
(flags
, ACC_SYNCHRONIZED
,id
, "Synchronized");
4372 if
(!CLASS_ABSTRACT
(TYPE_NAME
(this_class
))
4373 && !CLASS_INTERFACE
(TYPE_NAME
(this_class
)))
4375 (id
, "Class `%s' must be declared abstract to define abstract method `%s'",
4376 IDENTIFIER_POINTER
(DECL_NAME
(GET_CPC
())),
4377 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
4380 /* Things to be checked when declaring a constructor */
4383 int ec
= java_error_count
;
4384 /* 8.6: Constructor declarations: we might be trying to define a
4385 method without specifying a return type. */
4386 if
(EXPR_WFL_NODE
(id
) != GET_CPC_UN
())
4388 (id
, "Invalid method declaration, return type required");
4389 /* 8.6.3: Constructor modifiers */
4392 JCONSTRUCTOR_CHECK
(flags
, ACC_ABSTRACT
, id
, "abstract");
4393 JCONSTRUCTOR_CHECK
(flags
, ACC_STATIC
, id
, "static");
4394 JCONSTRUCTOR_CHECK
(flags
, ACC_FINAL
, id
, "final");
4395 JCONSTRUCTOR_CHECK
(flags
, ACC_NATIVE
, id
, "native");
4396 JCONSTRUCTOR_CHECK
(flags
, ACC_SYNCHRONIZED
, id
, "synchronized");
4398 /* If we found error here, we don't consider it's OK to tread
4399 the method definition as a constructor, for the rest of this
4401 if
(ec
== java_error_count
)
4405 /* Method declared within the scope of an interface are implicitly
4406 abstract and public. Conflicts with other erroneously provided
4407 modifiers are checked right after. */
4409 if
(CLASS_INTERFACE
(TYPE_NAME
(this_class
)))
4411 /* If FLAGS isn't set because of a modifier, turn the
4412 corresponding modifier WFL to NULL so we issue a warning on
4413 the obsolete use of the modifier */
4414 if
(!(flags
& ACC_PUBLIC
))
4415 MODIFIER_WFL
(PUBLIC_TK
) = NULL
;
4416 if
(!(flags
& ACC_ABSTRACT
))
4417 MODIFIER_WFL
(ABSTRACT_TK
) = NULL
;
4418 flags |
= ACC_PUBLIC
;
4419 flags |
= ACC_ABSTRACT
;
4422 /* Inner class can't declare static methods */
4423 if
((flags
& ACC_STATIC
) && !TOPLEVEL_CLASS_TYPE_P
(this_class
))
4426 (id
, "Method `%s' can't be static in inner class `%s'. Only members of interfaces and top-level classes can be static",
4427 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)),
4428 lang_printable_name
(this_class
, 0));
4431 /* Modifiers context reset moved up, so abstract method declaration
4432 modifiers can be later checked. */
4434 /* Set constructor returned type to void and method name to <init>,
4435 unless we found an error identifier the constructor (in which
4436 case we retain the original name) */
4439 type
= void_type_node
;
4441 meth_name
= init_identifier_node
;
4444 meth_name
= EXPR_WFL_NODE
(id
);
4446 /* Do the returned type resolution and registration if necessary */
4447 SET_TYPE_FOR_RESOLUTION
(type
, type_wfl
, must_chain
);
4450 type
= build_array_from_name
(type
, type_wfl
, meth_name
, &meth_name
);
4451 EXPR_WFL_NODE
(id
) = meth_name
;
4452 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
4456 patch_stage
= JDEP_METHOD_RETURN
;
4457 register_incomplete_type
(patch_stage
, type_wfl
, id
, type
);
4458 TREE_TYPE
(meth
) = GET_REAL_TYPE
(type
);
4461 TREE_TYPE
(meth
) = type
;
4463 saved_lineno
= lineno
;
4464 /* When defining an abstract or interface method, the curly
4465 bracket at level 1 doesn't exist because there is no function
4467 lineno
= (ctxp
->first_ccb_indent1 ? ctxp
->first_ccb_indent1
:
4468 EXPR_WFL_LINENO
(id
));
4470 /* Remember the original argument list */
4471 orig_arg
= TYPE_ARG_TYPES
(meth
);
4473 if
(patch_stage
) /* includes ret type and/or all args */
4476 meth
= add_method_1
(this_class
, flags
, meth_name
, meth
);
4477 /* Patch for the return type */
4478 if
(patch_stage
== JDEP_METHOD_RETURN
)
4480 jdep
= CLASSD_LAST
(ctxp
->classd_list
);
4481 JDEP_GET_PATCH
(jdep
) = &TREE_TYPE
(TREE_TYPE
(meth
));
4483 /* This is the stop JDEP. METH allows the function's signature
4485 register_incomplete_type
(JDEP_METHOD_END
, NULL_TREE
, meth
, NULL_TREE
);
4488 meth
= add_method
(this_class
, flags
, meth_name
,
4489 build_java_signature
(meth
));
4491 /* Remember final parameters */
4492 MARK_FINAL_PARMS
(meth
, orig_arg
);
4494 /* Fix the method argument list so we have the argument name
4496 fix_method_argument_names
(orig_arg
, meth
);
4498 /* Register the parameter number and re-install the current line
4500 DECL_MAX_LOCALS
(meth
) = ctxp
->formal_parameter_number
+1;
4501 lineno
= saved_lineno
;
4503 /* Register exception specified by the `throws' keyword for
4504 resolution and set the method decl appropriate field to the list.
4505 Note: the grammar ensures that what we get here are class
4509 throws
= nreverse
(throws
);
4510 for
(current
= throws
; current
; current
= TREE_CHAIN
(current
))
4512 register_incomplete_type
(JDEP_EXCEPTION
, TREE_VALUE
(current
),
4513 NULL_TREE
, NULL_TREE
);
4514 JDEP_GET_PATCH
(CLASSD_LAST
(ctxp
->classd_list
)) =
4515 &TREE_VALUE
(current
);
4517 DECL_FUNCTION_THROWS
(meth
) = throws
;
4520 if
(TREE_TYPE
(GET_CPC
()) != object_type_node
)
4521 DECL_FUNCTION_WFL
(meth
) = id
;
4523 /* Set the flag if we correctly processed a constructor */
4526 DECL_CONSTRUCTOR_P
(meth
) = 1;
4527 /* Compute and store the number of artificial parameters declared
4528 for this constructor */
4529 for
(count
= 0, current
= TYPE_FIELDS
(this_class
); current
;
4530 current
= TREE_CHAIN
(current
))
4531 if
(FIELD_LOCAL_ALIAS
(current
))
4533 DECL_FUNCTION_NAP
(meth
) = count
;
4536 /* Eventually set the @deprecated tag flag */
4537 CHECK_DEPRECATED
(meth
);
4539 /* If doing xref, store column and line number information instead
4540 of the line number only. */
4542 DECL_SOURCE_LINE
(meth
) = EXPR_WFL_LINECOL
(id
);
4548 fix_method_argument_names
(orig_arg
, meth
)
4549 tree orig_arg
, meth
;
4551 tree arg
= TYPE_ARG_TYPES
(TREE_TYPE
(meth
));
4552 if
(TREE_CODE
(TREE_TYPE
(meth
)) == METHOD_TYPE
)
4554 TREE_PURPOSE
(arg
) = this_identifier_node
;
4555 arg
= TREE_CHAIN
(arg
);
4557 while
(orig_arg
!= end_params_node
)
4559 TREE_PURPOSE
(arg
) = TREE_PURPOSE
(orig_arg
);
4560 orig_arg
= TREE_CHAIN
(orig_arg
);
4561 arg
= TREE_CHAIN
(arg
);
4565 /* Complete the method declaration with METHOD_BODY. */
4568 finish_method_declaration
(method_body
)
4573 if
(!current_function_decl
)
4576 flags
= get_access_flags_from_decl
(current_function_decl
);
4578 /* 8.4.5 Method Body */
4579 if
((flags
& ACC_ABSTRACT || flags
& ACC_NATIVE
) && method_body
)
4581 tree name
= DECL_NAME
(current_function_decl
);
4582 parse_error_context
(DECL_FUNCTION_WFL
(current_function_decl
),
4583 "%s method `%s' can't have a body defined",
4584 (METHOD_NATIVE
(current_function_decl
) ?
4585 "Native" : "Abstract"),
4586 IDENTIFIER_POINTER
(name
));
4587 method_body
= NULL_TREE
;
4589 else if
(!(flags
& ACC_ABSTRACT
) && !(flags
& ACC_NATIVE
) && !method_body
)
4591 tree name
= DECL_NAME
(current_function_decl
);
4593 (DECL_FUNCTION_WFL
(current_function_decl
),
4594 "Non native and non abstract method `%s' must have a body defined",
4595 IDENTIFIER_POINTER
(name
));
4596 method_body
= NULL_TREE
;
4599 if
(flag_emit_class_files
&& method_body
4600 && TREE_CODE
(method_body
) == NOP_EXPR
4601 && TREE_TYPE
(current_function_decl
)
4602 && TREE_TYPE
(TREE_TYPE
(current_function_decl
)) == void_type_node
)
4603 method_body
= build1
(RETURN_EXPR
, void_type_node
, NULL
);
4605 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(current_function_decl
)) = method_body
;
4606 maybe_absorb_scoping_blocks
();
4607 /* Exit function's body */
4609 /* Merge last line of the function with first line, directly in the
4610 function decl. It will be used to emit correct debug info. */
4611 if
(!flag_emit_xref
)
4612 DECL_SOURCE_LINE_MERGE
(current_function_decl
, ctxp
->last_ccb_indent1
);
4614 /* Since function's argument's list are shared, reset the
4615 ARG_FINAL_P parameter that might have been set on some of this
4616 function parameters. */
4617 UNMARK_FINAL_PARMS
(current_function_decl
);
4619 /* So we don't have an irrelevant function declaration context for
4620 the next static block we'll see. */
4621 current_function_decl
= NULL_TREE
;
4624 /* Build a an error message for constructor circularity errors. */
4627 constructor_circularity_msg
(from
, to
)
4630 static char string [4096];
4631 char *t
= xstrdup
(lang_printable_name
(from
, 0));
4632 sprintf
(string, "`%s' invokes `%s'", t
, lang_printable_name
(to
, 0));
4637 /* Verify a circular call to METH. Return 1 if an error is found, 0
4641 verify_constructor_circularity
(meth
, current
)
4644 static tree list
= NULL_TREE
;
4645 static int initialized_p
;
4648 /* If we haven't already registered LIST with the garbage collector,
4652 ggc_add_tree_root
(&list
, 1);
4656 for
(c
= DECL_CONSTRUCTOR_CALLS
(current
); c
; c
= TREE_CHAIN
(c
))
4658 if
(TREE_VALUE
(c
) == meth
)
4664 list
= nreverse
(list
);
4665 for
(liste
= list
; liste
; liste
= TREE_CHAIN
(liste
))
4668 (TREE_PURPOSE
(TREE_PURPOSE
(liste
)), "%s",
4669 constructor_circularity_msg
4670 (TREE_VALUE
(liste
), TREE_VALUE
(TREE_PURPOSE
(liste
))));
4674 t
= xstrdup
(lang_printable_name
(meth
, 0));
4675 parse_error_context
(TREE_PURPOSE
(c
),
4676 "%s: recursive invocation of constructor `%s'",
4677 constructor_circularity_msg
(current
, meth
), t
);
4683 for
(c
= DECL_CONSTRUCTOR_CALLS
(current
); c
; c
= TREE_CHAIN
(c
))
4685 list
= tree_cons
(c
, current
, list
);
4686 if
(verify_constructor_circularity
(meth
, TREE_VALUE
(c
)))
4688 list
= TREE_CHAIN
(list
);
4693 /* Check modifiers that can be declared but exclusively */
4696 check_modifiers_consistency
(flags
)
4700 tree cl
= NULL_TREE
;
4702 THIS_MODIFIER_ONLY
(flags
, ACC_PUBLIC
, PUBLIC_TK
, acc_count
, cl
);
4703 THIS_MODIFIER_ONLY
(flags
, ACC_PRIVATE
, PRIVATE_TK
, acc_count
, cl
);
4704 THIS_MODIFIER_ONLY
(flags
, ACC_PROTECTED
, PROTECTED_TK
, acc_count
, cl
);
4707 (cl
, "Inconsistent member declaration. At most one of `public', `private', or `protected' may be specified");
4711 THIS_MODIFIER_ONLY
(flags
, ACC_FINAL
, FINAL_TK
, acc_count
, cl
);
4712 THIS_MODIFIER_ONLY
(flags
, ACC_VOLATILE
, VOLATILE_TK
, acc_count
, cl
);
4714 parse_error_context
(cl
,
4715 "Inconsistent member declaration. At most one of `final' or `volatile' may be specified");
4718 /* Check the methode header METH for abstract specifics features */
4721 check_abstract_method_header
(meth
)
4724 int flags
= get_access_flags_from_decl
(meth
);
4726 OBSOLETE_MODIFIER_WARNING2
(MODIFIER_WFL
(ABSTRACT_TK
), flags
,
4727 ACC_ABSTRACT
, "abstract method",
4728 IDENTIFIER_POINTER
(DECL_NAME
(meth
)));
4729 OBSOLETE_MODIFIER_WARNING2
(MODIFIER_WFL
(PUBLIC_TK
), flags
,
4730 ACC_PUBLIC
, "abstract method",
4731 IDENTIFIER_POINTER
(DECL_NAME
(meth
)));
4733 check_modifiers
("Illegal modifier `%s' for interface method",
4734 flags
, INTERFACE_METHOD_MODIFIERS
);
4737 /* Create a FUNCTION_TYPE node and start augmenting it with the
4738 declared function arguments. Arguments type that can't be resolved
4739 are left as they are, but the returned node is marked as containing
4740 incomplete types. */
4743 method_declarator
(id
, list
)
4746 tree arg_types
= NULL_TREE
, current
, node
;
4747 tree meth
= make_node
(FUNCTION_TYPE
);
4750 patch_stage
= JDEP_NO_PATCH
;
4752 if
(GET_CPC
() == error_mark_node
)
4753 return error_mark_node
;
4755 /* If we're dealing with an inner class constructor, we hide the
4756 this$<n> decl in the name field of its parameter declaration. We
4757 also might have to hide the outer context local alias
4758 initializers. Not done when the class is a toplevel class. */
4759 if
(PURE_INNER_CLASS_DECL_P
(GET_CPC
())
4760 && EXPR_WFL_NODE
(id
) == GET_CPC_UN
())
4762 tree aliases_list
, type
, thisn
;
4763 /* First the aliases, linked to the regular parameters */
4765 build_alias_initializer_parameter_list
(AIPL_FUNCTION_DECLARATION
,
4766 TREE_TYPE
(GET_CPC
()),
4768 list
= chainon
(nreverse
(aliases_list
), list
);
4771 type
= TREE_TYPE
(DECL_CONTEXT
(GET_CPC
()));
4772 thisn
= build_current_thisn
(TREE_TYPE
(GET_CPC
()));
4773 list
= tree_cons
(build_wfl_node
(thisn
), build_pointer_type
(type
),
4777 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
4780 tree wfl_name
= TREE_PURPOSE
(current
);
4781 tree type
= TREE_VALUE
(current
);
4782 tree name
= EXPR_WFL_NODE
(wfl_name
);
4783 tree already
, arg_node
;
4784 tree type_wfl
= NULL_TREE
;
4787 /* Obtain a suitable type for resolution, if necessary */
4788 SET_TYPE_FOR_RESOLUTION
(type
, type_wfl
, must_chain
);
4790 /* Process NAME, as it may specify extra dimension(s) for it */
4791 type
= build_array_from_name
(type
, type_wfl
, name
, &name
);
4792 EXPR_WFL_NODE
(wfl_name
) = name
;
4794 real_type
= GET_REAL_TYPE
(type
);
4795 if
(TREE_CODE
(real_type
) == RECORD_TYPE
)
4797 real_type
= promote_type
(real_type
);
4798 if
(TREE_CODE
(type
) == TREE_LIST
)
4799 TREE_PURPOSE
(type
) = real_type
;
4802 /* Check redefinition */
4803 for
(already
= arg_types
; already
; already
= TREE_CHAIN
(already
))
4804 if
(TREE_PURPOSE
(already
) == name
)
4807 (wfl_name
, "Variable `%s' is used more than once in the argument list of method `%s'",
4808 IDENTIFIER_POINTER
(name
),
4809 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
4813 /* If we've an incomplete argument type, we know there is a location
4814 to patch when the type get resolved, later. */
4818 patch_stage
= JDEP_METHOD
;
4819 type
= register_incomplete_type
(patch_stage
,
4820 type_wfl
, wfl_name
, type
);
4821 jdep
= CLASSD_LAST
(ctxp
->classd_list
);
4822 JDEP_MISC
(jdep
) = id
;
4825 /* The argument node: a name and a (possibly) incomplete type. */
4826 arg_node
= build_tree_list
(name
, real_type
);
4827 /* Remeber arguments declared final. */
4828 ARG_FINAL_P
(arg_node
) = ARG_FINAL_P
(current
);
4831 JDEP_GET_PATCH
(jdep
) = &TREE_VALUE
(arg_node
);
4832 TREE_CHAIN
(arg_node
) = arg_types
;
4833 arg_types
= arg_node
;
4835 TYPE_ARG_TYPES
(meth
) = chainon
(nreverse
(arg_types
), end_params_node
);
4836 node
= build_tree_list
(id
, meth
);
4841 unresolved_type_p
(wfl
, returned
)
4846 if
(TREE_CODE
(wfl
) == EXPR_WITH_FILE_LOCATION
)
4850 tree decl
= IDENTIFIER_CLASS_VALUE
(EXPR_WFL_NODE
(wfl
));
4851 if
(decl
&& current_class
&& (decl
== TYPE_NAME
(current_class
)))
4852 *returned
= TREE_TYPE
(decl
);
4853 else if
(GET_CPC_UN
() == EXPR_WFL_NODE
(wfl
))
4854 *returned
= TREE_TYPE
(GET_CPC
());
4856 *returned
= NULL_TREE
;
4865 /* From NAME, build a qualified identifier node using the
4866 qualification from the current package definition. */
4869 parser_qualified_classname
(name
)
4872 tree nested_class_name
;
4874 if
((nested_class_name
= maybe_make_nested_class_name
(name
)))
4875 return nested_class_name
;
4878 return merge_qualified_name
(ctxp
->package
, name
);
4883 /* Called once the type a interface extends is resolved. Returns 0 if
4884 everything is OK. */
4887 parser_check_super_interface
(super_decl
, this_decl
, this_wfl
)
4888 tree super_decl
, this_decl
, this_wfl
;
4890 tree super_type
= TREE_TYPE
(super_decl
);
4892 /* Has to be an interface */
4893 if
(!CLASS_INTERFACE
(super_decl
))
4896 (this_wfl
, "Can't use %s `%s' to implement/extend %s `%s'",
4897 (TYPE_ARRAY_P
(super_type
) ?
"array" : "class"),
4898 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
)),
4899 (CLASS_INTERFACE
(TYPE_NAME
(TREE_TYPE
(this_decl
))) ?
4900 "interface" : "class"),
4901 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)));
4905 /* Check top-level interface access. Inner classes are subject to member
4906 access rules (6.6.1). */
4907 if
(! INNER_CLASS_P
(super_type
)
4908 && check_pkg_class_access
(DECL_NAME
(super_decl
), lookup_cl
(this_decl
)))
4911 SOURCE_FRONTEND_DEBUG
(("Completing interface %s with %s",
4912 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
4913 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
))));
4917 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
4918 0 if everthing is OK. */
4921 parser_check_super
(super_decl
, this_decl
, wfl
)
4922 tree super_decl
, this_decl
, wfl
;
4924 tree super_type
= TREE_TYPE
(super_decl
);
4926 /* SUPER should be a CLASS (neither an array nor an interface) */
4927 if
(TYPE_ARRAY_P
(super_type
) || CLASS_INTERFACE
(TYPE_NAME
(super_type
)))
4930 (wfl
, "Class `%s' can't subclass %s `%s'",
4931 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
4932 (CLASS_INTERFACE
(TYPE_NAME
(super_type
)) ?
"interface" : "array"),
4933 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
)));
4937 if
(CLASS_FINAL
(TYPE_NAME
(super_type
)))
4939 parse_error_context
(wfl
, "Can't subclass final classes: %s",
4940 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
)));
4944 /* Check top-level class scope. Inner classes are subject to member access
4946 if
(! INNER_CLASS_P
(super_type
)
4947 && (check_pkg_class_access
(DECL_NAME
(super_decl
), wfl
)))
4950 SOURCE_FRONTEND_DEBUG
(("Completing class %s with %s",
4951 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
4952 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
))));
4956 /* Create a new dependency list and link it (in a LIFO manner) to the
4957 CTXP list of type dependency list. */
4960 create_jdep_list
(ctxp
)
4961 struct parser_ctxt
*ctxp
;
4963 jdeplist
*new
= (jdeplist
*)xmalloc
(sizeof
(jdeplist
));
4964 new
->first
= new
->last
= NULL
;
4965 new
->next
= ctxp
->classd_list
;
4966 ctxp
->classd_list
= new
;
4970 reverse_jdep_list
(ctxp
)
4971 struct parser_ctxt
*ctxp
;
4973 register jdeplist
*prev
= NULL
, *current
, *next
;
4974 for
(current
= ctxp
->classd_list
; current
; current
= next
)
4976 next
= current
->next
;
4977 current
->next
= prev
;
4983 /* Create a fake pointer based on the ID stored in
4984 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
4985 registered again. */
4988 obtain_incomplete_type
(type_name
)
4991 tree ptr
= NULL_TREE
, name
;
4993 if
(TREE_CODE
(type_name
) == EXPR_WITH_FILE_LOCATION
)
4994 name
= EXPR_WFL_NODE
(type_name
);
4995 else if
(INCOMPLETE_TYPE_P
(type_name
))
4996 name
= TYPE_NAME
(type_name
);
5000 BUILD_PTR_FROM_NAME
(ptr
, name
);
5006 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
5007 non NULL instead of computing a new fake type based on WFL. The new
5008 dependency is inserted in the current type dependency list, in FIFO
5012 register_incomplete_type
(kind
, wfl
, decl
, ptr
)
5014 tree wfl
, decl
, ptr
;
5016 jdep
*new
= (jdep
*)xmalloc
(sizeof
(jdep
));
5018 if
(!ptr
&& kind
!= JDEP_METHOD_END
) /* JDEP_METHOD_END is a mere marker */
5019 ptr
= obtain_incomplete_type
(wfl
);
5021 JDEP_KIND
(new
) = kind
;
5022 JDEP_DECL
(new
) = decl
;
5023 JDEP_TO_RESOLVE
(new
) = ptr
;
5024 JDEP_WFL
(new
) = wfl
;
5025 JDEP_CHAIN
(new
) = NULL
;
5026 JDEP_MISC
(new
) = NULL_TREE
;
5027 /* For some dependencies, set the enclosing class of the current
5028 class to be the enclosing context */
5029 if
((kind
== JDEP_SUPER || kind
== JDEP_INTERFACE
5030 || kind
== JDEP_ANONYMOUS || kind
== JDEP_FIELD
)
5031 && GET_ENCLOSING_CPC
())
5032 JDEP_ENCLOSING
(new
) = TREE_VALUE
(GET_ENCLOSING_CPC
());
5034 JDEP_ENCLOSING
(new
) = GET_CPC
();
5035 JDEP_GET_PATCH
(new
) = (tree
*)NULL
;
5037 JDEP_INSERT
(ctxp
->classd_list
, new
);
5043 java_check_circular_reference
()
5046 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
5048 tree type
= TREE_TYPE
(current
);
5049 if
(CLASS_INTERFACE
(current
))
5051 /* Check all interfaces this class extends */
5052 tree basetype_vec
= TYPE_BINFO_BASETYPES
(type
);
5057 n
= TREE_VEC_LENGTH
(basetype_vec
);
5058 for
(i
= 0; i
< n
; i
++)
5060 tree vec_elt
= TREE_VEC_ELT
(basetype_vec
, i
);
5061 if
(vec_elt
&& BINFO_TYPE
(vec_elt
) != object_type_node
5062 && interface_of_p
(type
, BINFO_TYPE
(vec_elt
)))
5063 parse_error_context
(lookup_cl
(current
),
5064 "Cyclic interface inheritance");
5068 if
(inherits_from_p
(CLASSTYPE_SUPER
(type
), type
))
5069 parse_error_context
(lookup_cl
(current
),
5070 "Cyclic class inheritance%s",
5071 (cyclic_inheritance_report ?
5072 cyclic_inheritance_report
: ""));
5076 /* Augment the parameter list PARM with parameters crafted to
5077 initialize outer context locals aliases. Through ARTIFICIAL, a
5078 count is kept of the number of crafted parameters. MODE governs
5079 what eventually gets created: something suitable for a function
5080 creation or a function invocation, either the constructor or
5084 build_alias_initializer_parameter_list
(mode
, class_type
, parm
, artificial
)
5086 tree class_type
, parm
;
5090 tree additional_parms
= NULL_TREE
;
5092 for
(field
= TYPE_FIELDS
(class_type
); field
; field
= TREE_CHAIN
(field
))
5093 if
(FIELD_LOCAL_ALIAS
(field
))
5095 const char *buffer
= IDENTIFIER_POINTER
(DECL_NAME
(field
));
5096 tree purpose
= NULL_TREE
, value
= NULL_TREE
, name
= NULL_TREE
;
5101 case AIPL_FUNCTION_DECLARATION
:
5102 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR
(mangled_id
,
5104 purpose
= build_wfl_node
(mangled_id
);
5105 if
(TREE_CODE
(TREE_TYPE
(field
)) == POINTER_TYPE
)
5106 value
= build_wfl_node
(TYPE_NAME
(TREE_TYPE
(field
)));
5108 value
= TREE_TYPE
(field
);
5111 case AIPL_FUNCTION_CREATION
:
5112 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR
(purpose
,
5114 value
= TREE_TYPE
(field
);
5117 case AIPL_FUNCTION_FINIT_INVOCATION
:
5118 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR
(mangled_id
,
5120 /* Now, this is wrong. purpose should always be the NAME
5121 of something and value its matching value (decl, type,
5122 etc...) FIXME -- but there is a lot to fix. */
5124 /* When invoked for this kind of operation, we already
5125 know whether a field is used or not. */
5126 purpose
= TREE_TYPE
(field
);
5127 value
= build_wfl_node
(mangled_id
);
5130 case AIPL_FUNCTION_CTOR_INVOCATION
:
5131 /* There are two case: the constructor invokation happends
5132 outside the local inner, in which case, locales from the outer
5133 context are directly used.
5135 Otherwise, we fold to using the alias directly. */
5136 if
(class_type
== current_class
)
5140 name
= get_identifier
(&buffer
[4]);
5141 value
= IDENTIFIER_LOCAL_VALUE
(name
);
5145 additional_parms
= tree_cons
(purpose
, value
, additional_parms
);
5149 if
(additional_parms
)
5151 if
(ANONYMOUS_CLASS_P
(class_type
)
5152 && mode
== AIPL_FUNCTION_CTOR_INVOCATION
)
5153 additional_parms
= nreverse
(additional_parms
);
5154 parm
= chainon
(additional_parms
, parm
);
5160 /* Craft a constructor for CLASS_DECL -- what we should do when none
5161 where found. ARGS is non NULL when a special signature must be
5162 enforced. This is the case for anonymous classes. */
5165 craft_constructor
(class_decl
, args
)
5166 tree class_decl
, args
;
5168 tree class_type
= TREE_TYPE
(class_decl
);
5169 tree parm
= NULL_TREE
;
5170 int flags
= (get_access_flags_from_decl
(class_decl
) & ACC_PUBLIC ?
5172 int i
= 0, artificial
= 0;
5173 tree decl
, ctor_name
;
5176 /* The constructor name is <init> unless we're dealing with an
5177 anonymous class, in which case the name will be fixed after having
5179 if
(ANONYMOUS_CLASS_P
(class_type
))
5180 ctor_name
= DECL_NAME
(class_decl
);
5182 ctor_name
= init_identifier_node
;
5184 /* If we're dealing with an inner class constructor, we hide the
5185 this$<n> decl in the name field of its parameter declaration. */
5186 if
(PURE_INNER_CLASS_TYPE_P
(class_type
))
5188 tree type
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(class_type
)));
5189 parm
= tree_cons
(build_current_thisn
(class_type
),
5190 build_pointer_type
(type
), parm
);
5192 /* Some more arguments to be hidden here. The values of the local
5193 variables of the outer context that the inner class needs to see. */
5194 parm
= build_alias_initializer_parameter_list
(AIPL_FUNCTION_CREATION
,
5199 /* Then if there are any args to be enforced, enforce them now */
5200 for
(; args
&& args
!= end_params_node
; args
= TREE_CHAIN
(args
))
5202 sprintf
(buffer
, "parm%d", i
++);
5203 parm
= tree_cons
(get_identifier
(buffer
), TREE_VALUE
(args
), parm
);
5206 CRAFTED_PARAM_LIST_FIXUP
(parm
);
5207 decl
= create_artificial_method
(class_type
, flags
, void_type_node
,
5209 fix_method_argument_names
(parm
, decl
);
5210 /* Now, mark the artificial parameters. */
5211 DECL_FUNCTION_NAP
(decl
) = artificial
;
5212 DECL_FUNCTION_SYNTHETIC_CTOR
(decl
) = DECL_CONSTRUCTOR_P
(decl
) = 1;
5216 /* Fix the constructors. This will be called right after circular
5217 references have been checked. It is necessary to fix constructors
5218 early even if no code generation will take place for that class:
5219 some generated constructor might be required by the class whose
5220 compilation triggered this one to be simply loaded. */
5223 java_fix_constructors
()
5227 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
5229 tree class_type
= TREE_TYPE
(current
);
5233 if
(CLASS_INTERFACE
(TYPE_NAME
(class_type
)))
5236 for
(decl
= TYPE_METHODS
(class_type
); decl
; decl
= TREE_CHAIN
(decl
))
5238 if
(DECL_CONSTRUCTOR_P
(decl
))
5240 fix_constructors
(decl
);
5245 /* Anonymous class constructor can't be generated that early. */
5246 if
(!saw_ctor
&& !ANONYMOUS_CLASS_P
(class_type
))
5247 craft_constructor
(current
, NULL_TREE
);
5251 /* safe_layout_class just makes sure that we can load a class without
5252 disrupting the current_class, input_file, lineno, etc, information
5253 about the class processed currently. */
5256 safe_layout_class
(class
)
5259 tree save_current_class
= current_class
;
5260 const char *save_input_filename
= input_filename
;
5261 int save_lineno
= lineno
;
5263 layout_class
(class
);
5265 current_class
= save_current_class
;
5266 input_filename
= save_input_filename
;
5267 lineno
= save_lineno
;
5268 CLASS_LOADED_P
(class
) = 1;
5272 jdep_resolve_class
(dep
)
5277 if
(JDEP_RESOLVED_P
(dep
))
5278 decl
= JDEP_RESOLVED_DECL
(dep
);
5281 decl
= resolve_class
(JDEP_ENCLOSING
(dep
), JDEP_TO_RESOLVE
(dep
),
5282 JDEP_DECL
(dep
), JDEP_WFL
(dep
));
5283 JDEP_RESOLVED
(dep
, decl
);
5287 complete_class_report_errors
(dep
);
5288 else if
(PURE_INNER_CLASS_DECL_P
(decl
))
5290 tree inner
= TREE_TYPE
(decl
);
5291 if
(! CLASS_LOADED_P
(inner
))
5293 safe_layout_class
(inner
);
5294 if
(TYPE_SIZE
(inner
) == error_mark_node
)
5295 TYPE_SIZE
(inner
) = NULL_TREE
;
5297 check_inner_class_access
(decl
, JDEP_ENCLOSING
(dep
), JDEP_WFL
(dep
));
5302 /* Complete unsatisfied class declaration and their dependencies */
5305 java_complete_class
()
5312 /* Process imports */
5315 /* Rever things so we have the right order */
5316 ctxp
->class_list
= nreverse
(ctxp
->class_list
);
5317 ctxp
->classd_list
= reverse_jdep_list
(ctxp
);
5319 for
(cclassd
= ctxp
->classd_list
, cclass
= ctxp
->class_list
;
5321 cclass
= TREE_CHAIN
(cclass
), cclassd
= CLASSD_CHAIN
(cclassd
))
5324 for
(dep
= CLASSD_FIRST
(cclassd
); dep
; dep
= JDEP_CHAIN
(dep
))
5327 if
(!(decl
= jdep_resolve_class
(dep
)))
5330 /* Now it's time to patch */
5331 switch
(JDEP_KIND
(dep
))
5334 /* Simply patch super */
5335 if
(parser_check_super
(decl
, JDEP_DECL
(dep
), JDEP_WFL
(dep
)))
5337 BINFO_TYPE
(TREE_VEC_ELT
(BINFO_BASETYPES
(TYPE_BINFO
5338 (TREE_TYPE
(JDEP_DECL
(dep
)))), 0)) = TREE_TYPE
(decl
);
5343 /* We do part of the job done in add_field */
5344 tree field_decl
= JDEP_DECL
(dep
);
5345 tree field_type
= TREE_TYPE
(decl
);
5346 if
(TREE_CODE
(field_type
) == RECORD_TYPE
)
5347 field_type
= promote_type
(field_type
);
5348 TREE_TYPE
(field_decl
) = field_type
;
5349 DECL_ALIGN
(field_decl
) = 0;
5350 DECL_USER_ALIGN
(field_decl
) = 0;
5351 layout_decl
(field_decl
, 0);
5352 SOURCE_FRONTEND_DEBUG
5353 (("Completed field/var decl `%s' with `%s'",
5354 IDENTIFIER_POINTER
(DECL_NAME
(field_decl
)),
5355 IDENTIFIER_POINTER
(DECL_NAME
(decl
))));
5358 case JDEP_METHOD
: /* We start patching a method */
5359 case JDEP_METHOD_RETURN
:
5365 type
= TREE_TYPE
(decl
);
5366 if
(TREE_CODE
(type
) == RECORD_TYPE
)
5367 type
= promote_type
(type
);
5368 JDEP_APPLY_PATCH
(dep
, type
);
5369 SOURCE_FRONTEND_DEBUG
5370 (((JDEP_KIND
(dep
) == JDEP_METHOD_RETURN ?
5371 "Completing fct `%s' with ret type `%s'":
5372 "Completing arg `%s' with type `%s'"),
5373 IDENTIFIER_POINTER
(EXPR_WFL_NODE
5374 (JDEP_DECL_WFL
(dep
))),
5375 IDENTIFIER_POINTER
(DECL_NAME
(decl
))));
5379 dep
= JDEP_CHAIN
(dep
);
5380 if
(JDEP_KIND
(dep
) == JDEP_METHOD_END
)
5383 decl
= jdep_resolve_class
(dep
);
5387 tree mdecl
= JDEP_DECL
(dep
), signature
;
5388 /* Recompute and reset the signature, check first that
5389 all types are now defined. If they're not,
5390 dont build the signature. */
5391 if
(check_method_types_complete
(mdecl
))
5393 signature
= build_java_signature
(TREE_TYPE
(mdecl
));
5394 set_java_signature
(TREE_TYPE
(mdecl
), signature
);
5401 case JDEP_INTERFACE
:
5402 if
(parser_check_super_interface
(decl
, JDEP_DECL
(dep
),
5405 parser_add_interface
(JDEP_DECL
(dep
), decl
, JDEP_WFL
(dep
));
5410 type
= TREE_TYPE
(decl
);
5411 if
(TREE_CODE
(type
) == RECORD_TYPE
)
5412 type
= promote_type
(type
);
5413 JDEP_APPLY_PATCH
(dep
, type
);
5417 JDEP_APPLY_PATCH
(dep
, TREE_TYPE
(decl
));
5418 SOURCE_FRONTEND_DEBUG
5419 (("Completing a random type dependency on a '%s' node",
5420 tree_code_name
[TREE_CODE
(JDEP_DECL
(dep
))]));
5423 case JDEP_EXCEPTION
:
5424 JDEP_APPLY_PATCH
(dep
, TREE_TYPE
(decl
));
5425 SOURCE_FRONTEND_DEBUG
5426 (("Completing `%s' `throws' argument node",
5427 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
)))));
5430 case JDEP_ANONYMOUS
:
5431 patch_anonymous_class
(decl
, JDEP_DECL
(dep
), JDEP_WFL
(dep
));
5442 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
5446 resolve_class
(enclosing
, class_type
, decl
, cl
)
5447 tree enclosing
, class_type
, decl
, cl
;
5449 const char *name
= IDENTIFIER_POINTER
(TYPE_NAME
(class_type
));
5450 const char *base
= name
;
5451 tree resolved_type
= TREE_TYPE
(class_type
);
5452 tree resolved_type_decl
;
5454 if
(resolved_type
!= NULL_TREE
)
5456 tree resolved_type_decl
= TYPE_NAME
(resolved_type
);
5457 if
(resolved_type_decl
== NULL_TREE
5458 || TREE_CODE
(resolved_type_decl
) == IDENTIFIER_NODE
)
5460 resolved_type_decl
= build_decl
(TYPE_DECL
,
5461 TYPE_NAME
(class_type
),
5464 return resolved_type_decl
;
5467 /* 1- Check to see if we have an array. If true, find what we really
5469 while
(name
[0] == '[')
5473 TYPE_NAME
(class_type
) = get_identifier
(name
);
5474 WFL_STRIP_BRACKET
(cl
, cl
);
5477 /* 2- Resolve the bare type */
5478 if
(!(resolved_type_decl
= do_resolve_class
(enclosing
, class_type
,
5481 resolved_type
= TREE_TYPE
(resolved_type_decl
);
5483 /* 3- If we have and array, reconstruct the array down to its nesting */
5486 while
(base
!= name
)
5488 resolved_type
= build_java_array_type
(resolved_type
, -1);
5489 CLASS_LOADED_P
(resolved_type
) = 1;
5492 /* A TYPE_NAME that is a TYPE_DECL was set in
5493 build_java_array_type, return it. */
5494 resolved_type_decl
= TYPE_NAME
(resolved_type
);
5496 TREE_TYPE
(class_type
) = resolved_type
;
5497 return resolved_type_decl
;
5500 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
5501 are used to report error messages. */
5504 do_resolve_class
(enclosing
, class_type
, decl
, cl
)
5505 tree enclosing
, class_type
, decl
, cl
;
5507 tree new_class_decl
;
5509 /* Do not try to replace TYPE_NAME (class_type) by a variable, since
5510 it is changed by find_in_imports{_on_demand} and (but it doesn't
5511 really matter) qualify_and_find */
5513 /* 0- Search in the current class as an inner class */
5515 /* Maybe some code here should be added to load the class or
5516 something, at least if the class isn't an inner class and ended
5517 being loaded from class file. FIXME. */
5522 if
((new_class_decl
= find_as_inner_class
(enclosing
, class_type
, cl
)))
5523 return new_class_decl
;
5525 intermediate
= enclosing
;
5526 /* Explore enclosing contexts. */
5527 while
(INNER_CLASS_DECL_P
(intermediate
))
5529 intermediate
= DECL_CONTEXT
(intermediate
);
5530 if
((new_class_decl
= find_as_inner_class
(intermediate
,
5532 return new_class_decl
;
5535 /* Now go to the upper classes, bail out if necessary. */
5536 enclosing
= CLASSTYPE_SUPER
(TREE_TYPE
(enclosing
));
5537 if
(!enclosing || enclosing
== object_type_node
)
5540 if
(TREE_CODE
(enclosing
) == POINTER_TYPE
)
5541 enclosing
= do_resolve_class
(NULL
, enclosing
, NULL
, NULL
);
5543 enclosing
= TYPE_NAME
(enclosing
);
5546 /* 1- Check for the type in single imports. This will change
5547 TYPE_NAME() if something relevant is found */
5548 find_in_imports
(class_type
);
5550 /* 2- And check for the type in the current compilation unit */
5551 if
((new_class_decl
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
))))
5553 if
(!CLASS_LOADED_P
(TREE_TYPE
(new_class_decl
)) &&
5554 !CLASS_FROM_SOURCE_P
(TREE_TYPE
(new_class_decl
)))
5555 load_class
(TYPE_NAME
(class_type
), 0);
5556 return IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
));
5559 /* 3- Search according to the current package definition */
5560 if
(!QUALIFIED_P
(TYPE_NAME
(class_type
)))
5562 if
((new_class_decl
= qualify_and_find
(class_type
, ctxp
->package
,
5563 TYPE_NAME
(class_type
))))
5564 return new_class_decl
;
5567 /* 4- Check the import on demands. Don't allow bar.baz to be
5568 imported from foo.* */
5569 if
(!QUALIFIED_P
(TYPE_NAME
(class_type
)))
5570 if
(find_in_imports_on_demand
(class_type
))
5573 /* If found in find_in_imports_on_demant, the type has already been
5575 if
((new_class_decl
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
))))
5576 return new_class_decl
;
5578 /* 5- Try with a name qualified with the package name we've seen so far */
5579 if
(!QUALIFIED_P
(TYPE_NAME
(class_type
)))
5583 /* If there is a current package (ctxp->package), it's the first
5584 element of package_list and we can skip it. */
5585 for
(package
= (ctxp
->package ?
5586 TREE_CHAIN
(package_list
) : package_list
);
5587 package
; package
= TREE_CHAIN
(package
))
5588 if
((new_class_decl
= qualify_and_find
(class_type
,
5589 TREE_PURPOSE
(package
),
5590 TYPE_NAME
(class_type
))))
5591 return new_class_decl
;
5594 /* 5- Check an other compilation unit that bears the name of type */
5595 load_class
(TYPE_NAME
(class_type
), 0);
5598 cl
= lookup_cl
(decl
);
5600 /* If we don't have a value for CL, then we're being called recursively.
5601 We can't check package access just yet, but it will be taken care of
5605 if
(check_pkg_class_access
(TYPE_NAME
(class_type
), cl
))
5609 /* 6- Last call for a resolution */
5610 return IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
));
5614 qualify_and_find
(class_type
, package
, name
)
5615 tree class_type
, package
, name
;
5617 tree new_qualified
= merge_qualified_name
(package
, name
);
5618 tree new_class_decl
;
5620 if
(!IDENTIFIER_CLASS_VALUE
(new_qualified
))
5621 load_class
(new_qualified
, 0);
5622 if
((new_class_decl
= IDENTIFIER_CLASS_VALUE
(new_qualified
)))
5624 if
(!CLASS_LOADED_P
(TREE_TYPE
(new_class_decl
)) &&
5625 !CLASS_FROM_SOURCE_P
(TREE_TYPE
(new_class_decl
)))
5626 load_class
(new_qualified
, 0);
5627 TYPE_NAME
(class_type
) = new_qualified
;
5628 return IDENTIFIER_CLASS_VALUE
(new_qualified
);
5633 /* Resolve NAME and lay it out (if not done and if not the current
5634 parsed class). Return a decl node. This function is meant to be
5635 called when type resolution is necessary during the walk pass. */
5638 resolve_and_layout
(something
, cl
)
5642 tree decl
, decl_type
;
5644 /* Don't do that on the current class */
5645 if
(something
== current_class
)
5646 return TYPE_NAME
(current_class
);
5648 /* Don't do anything for void and other primitive types */
5649 if
(JPRIMITIVE_TYPE_P
(something
) || something
== void_type_node
)
5652 /* Pointer types can be reall pointer types or fake pointers. When
5653 finding a real pointer, recheck for primitive types */
5654 if
(TREE_CODE
(something
) == POINTER_TYPE
)
5656 if
(TREE_TYPE
(something
))
5658 something
= TREE_TYPE
(something
);
5659 if
(JPRIMITIVE_TYPE_P
(something
) || something
== void_type_node
)
5663 something
= TYPE_NAME
(something
);
5666 /* Don't do anything for arrays of primitive types */
5667 if
(TREE_CODE
(something
) == RECORD_TYPE
&& TYPE_ARRAY_P
(something
)
5668 && JPRIMITIVE_TYPE_P
(TYPE_ARRAY_ELEMENT
(something
)))
5671 /* Something might be a WFL */
5672 if
(TREE_CODE
(something
) == EXPR_WITH_FILE_LOCATION
)
5673 something
= EXPR_WFL_NODE
(something
);
5675 /* Otherwise, if something is not and IDENTIFIER_NODE, it can be a a
5676 TYPE_DECL or a real TYPE */
5677 else if
(TREE_CODE
(something
) != IDENTIFIER_NODE
)
5678 something
= (TREE_CODE
(TYPE_NAME
(something
)) == TYPE_DECL ?
5679 DECL_NAME
(TYPE_NAME
(something
)) : TYPE_NAME
(something
));
5681 if
(!(decl
= resolve_no_layout
(something
, cl
)))
5684 /* Resolve and layout if necessary */
5685 decl_type
= TREE_TYPE
(decl
);
5686 layout_class_methods
(decl_type
);
5688 if
(CLASS_FROM_SOURCE_P
(decl_type
))
5689 java_check_methods
(decl
);
5690 /* Layout the type if necessary */
5691 if
(decl_type
!= current_class
&& !CLASS_LOADED_P
(decl_type
))
5692 safe_layout_class
(decl_type
);
5697 /* Resolve a class, returns its decl but doesn't perform any
5698 layout. The current parsing context is saved and restored */
5701 resolve_no_layout
(name
, cl
)
5705 BUILD_PTR_FROM_NAME
(ptr
, name
);
5706 java_parser_context_save_global
();
5707 decl
= resolve_class
(TYPE_NAME
(current_class
), ptr
, NULL_TREE
, cl
);
5708 java_parser_context_restore_global
();
5713 /* Called when reporting errors. Skip leader '[' in a complex array
5714 type description that failed to be resolved. */
5717 purify_type_name
(name
)
5720 while
(*name
&& *name
== '[')
5725 /* The type CURRENT refers to can't be found. We print error messages. */
5728 complete_class_report_errors
(dep
)
5733 if
(!JDEP_WFL
(dep
))
5736 name
= IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
)));
5737 switch
(JDEP_KIND
(dep
))
5741 (JDEP_WFL
(dep
), "Superclass `%s' of class `%s' not found",
5742 purify_type_name
(name
),
5743 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
5747 (JDEP_WFL
(dep
), "Type `%s' not found in declaration of field `%s'",
5748 purify_type_name
(name
),
5749 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
5751 case JDEP_METHOD
: /* Covers arguments */
5753 (JDEP_WFL
(dep
), "Type `%s' not found in the declaration of the argument `%s' of method `%s'",
5754 purify_type_name
(name
),
5755 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_DECL_WFL
(dep
))),
5756 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_MISC
(dep
))));
5758 case JDEP_METHOD_RETURN
: /* Covers return type */
5760 (JDEP_WFL
(dep
), "Type `%s' not found in the declaration of the return type of method `%s'",
5761 purify_type_name
(name
),
5762 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_DECL_WFL
(dep
))));
5764 case JDEP_INTERFACE
:
5766 (JDEP_WFL
(dep
), "Superinterface `%s' of %s `%s' not found",
5767 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
))),
5768 (CLASS_OR_INTERFACE
(JDEP_DECL
(dep
), "class", "interface")),
5769 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
5773 (JDEP_WFL
(dep
), "Type `%s' not found in the declaration of the local variable `%s'",
5774 purify_type_name
(IDENTIFIER_POINTER
5775 (EXPR_WFL_NODE
(JDEP_WFL
(dep
)))),
5776 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
5778 case JDEP_EXCEPTION
: /* As specified by `throws' */
5780 (JDEP_WFL
(dep
), "Class `%s' not found in `throws'",
5781 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
))));
5784 /* Fix for -Wall. Just break doing nothing. The error will be
5790 /* Return a static string containing the DECL prototype string. If
5791 DECL is a constructor, use the class name instead of the form
5795 get_printable_method_name
(decl
)
5798 const char *to_return
;
5799 tree name
= NULL_TREE
;
5801 if
(DECL_CONSTRUCTOR_P
(decl
))
5803 name
= DECL_NAME
(decl
);
5804 DECL_NAME
(decl
) = DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(decl
)));
5807 to_return
= lang_printable_name
(decl
, 0);
5808 if
(DECL_CONSTRUCTOR_P
(decl
))
5809 DECL_NAME
(decl
) = name
;
5814 /* Track method being redefined inside the same class. As a side
5815 effect, set DECL_NAME to an IDENTIFIER (prior entering this
5816 function it's a FWL, so we can track errors more accurately.) */
5819 check_method_redefinition
(class
, method
)
5824 /* There's no need to verify <clinit> and finit$ */
5825 if
(DECL_CLINIT_P
(method
) || DECL_FINIT_P
(method
))
5828 sig
= TYPE_ARGUMENT_SIGNATURE
(TREE_TYPE
(method
));
5829 for
(redef
= TYPE_METHODS
(class
); redef
; redef
= TREE_CHAIN
(redef
))
5831 if
(redef
== method
)
5833 if
(DECL_NAME
(redef
) == DECL_NAME
(method
)
5834 && sig
== TYPE_ARGUMENT_SIGNATURE
(TREE_TYPE
(redef
))
5835 && !DECL_ARTIFICIAL
(method
))
5838 (DECL_FUNCTION_WFL
(method
), "Duplicate %s declaration `%s'",
5839 (DECL_CONSTRUCTOR_P
(redef
) ?
"constructor" : "method"),
5840 get_printable_method_name
(redef
));
5847 /* Return 1 if check went ok, 0 otherwise. */
5849 check_abstract_method_definitions
(do_interface
, class_decl
, type
)
5851 tree class_decl
, type
;
5853 tree class
= TREE_TYPE
(class_decl
);
5854 tree method
, end_type
;
5857 end_type
= (do_interface ? object_type_node
: type
);
5858 for
(method
= TYPE_METHODS
(type
); method
; method
= TREE_CHAIN
(method
))
5860 tree other_super
, other_method
, method_sig
, method_name
;
5862 int end_type_reached
= 0;
5864 if
(!METHOD_ABSTRACT
(method
) || METHOD_FINAL
(method
))
5867 /* Now verify that somewhere in between TYPE and CLASS,
5868 abstract method METHOD gets a non abstract definition
5869 that is inherited by CLASS. */
5871 method_sig
= build_java_signature
(TREE_TYPE
(method
));
5872 method_name
= DECL_NAME
(method
);
5873 if
(TREE_CODE
(method_name
) == EXPR_WITH_FILE_LOCATION
)
5874 method_name
= EXPR_WFL_NODE
(method_name
);
5876 other_super
= class
;
5878 if
(other_super
== end_type
)
5879 end_type_reached
= 1;
5882 for
(other_method
= TYPE_METHODS
(other_super
); other_method
;
5883 other_method
= TREE_CHAIN
(other_method
))
5885 tree s
= build_java_signature
(TREE_TYPE
(other_method
));
5886 tree other_name
= DECL_NAME
(other_method
);
5888 if
(TREE_CODE
(other_name
) == EXPR_WITH_FILE_LOCATION
)
5889 other_name
= EXPR_WFL_NODE
(other_name
);
5890 if
(!DECL_CLINIT_P
(other_method
)
5891 && !DECL_CONSTRUCTOR_P
(other_method
)
5892 && method_name
== other_name
5894 && !METHOD_ABSTRACT
(other_method
))
5900 other_super
= CLASSTYPE_SUPER
(other_super
);
5901 } while
(!end_type_reached
);
5903 /* Report that abstract METHOD didn't find an implementation
5904 that CLASS can use. */
5907 char *t
= xstrdup
(lang_printable_name
5908 (TREE_TYPE
(TREE_TYPE
(method
)), 0));
5909 tree ccn
= DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(method
)));
5912 (lookup_cl
(class_decl
),
5913 "Class `%s' doesn't define the abstract method `%s %s' from %s `%s'. This method must be defined or %s `%s' must be declared abstract",
5914 IDENTIFIER_POINTER
(DECL_NAME
(class_decl
)),
5915 t
, lang_printable_name
(method
, 0),
5916 (CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(method
))) ?
5917 "interface" : "class"),
5918 IDENTIFIER_POINTER
(ccn
),
5919 (CLASS_INTERFACE
(class_decl
) ?
"interface" : "class"),
5920 IDENTIFIER_POINTER
(DECL_NAME
(class_decl
)));
5926 if
(ok
&& do_interface
)
5928 /* Check for implemented interfaces. */
5930 tree vector
= TYPE_BINFO_BASETYPES
(type
);
5931 for
(i
= 1; ok
&& vector
&& i
< TREE_VEC_LENGTH
(vector
); i
++)
5933 tree super
= BINFO_TYPE
(TREE_VEC_ELT
(vector
, i
));
5934 ok
= check_abstract_method_definitions
(1, class_decl
, super
);
5941 /* Check that CLASS_DECL somehow implements all inherited abstract
5945 java_check_abstract_method_definitions
(class_decl
)
5948 tree class
= TREE_TYPE
(class_decl
);
5952 if
(CLASS_ABSTRACT
(class_decl
))
5955 /* Check for inherited types */
5958 super
= CLASSTYPE_SUPER
(super
);
5959 check_abstract_method_definitions
(0, class_decl
, super
);
5960 } while
(super
!= object_type_node
);
5962 /* Check for implemented interfaces. */
5963 vector
= TYPE_BINFO_BASETYPES
(class
);
5964 for
(i
= 1; i
< TREE_VEC_LENGTH
(vector
); i
++)
5966 super
= BINFO_TYPE
(TREE_VEC_ELT
(vector
, i
));
5967 check_abstract_method_definitions
(1, class_decl
, super
);
5971 /* Check all the types method DECL uses and return 1 if all of them
5972 are now complete, 0 otherwise. This is used to check whether its
5973 safe to build a method signature or not. */
5976 check_method_types_complete
(decl
)
5979 tree type
= TREE_TYPE
(decl
);
5982 if
(!INCOMPLETE_TYPE_P
(TREE_TYPE
(type
)))
5985 args
= TYPE_ARG_TYPES
(type
);
5986 if
(TREE_CODE
(type
) == METHOD_TYPE
)
5987 args
= TREE_CHAIN
(args
);
5988 for
(; args
!= end_params_node
; args
= TREE_CHAIN
(args
))
5989 if
(INCOMPLETE_TYPE_P
(TREE_VALUE
(args
)))
5995 /* Visible interface to check methods contained in CLASS_DECL */
5998 java_check_methods
(class_decl
)
6001 if
(CLASS_METHOD_CHECKED_P
(TREE_TYPE
(class_decl
)))
6004 if
(CLASS_INTERFACE
(class_decl
))
6005 java_check_abstract_methods
(class_decl
);
6007 java_check_regular_methods
(class_decl
);
6009 CLASS_METHOD_CHECKED_P
(TREE_TYPE
(class_decl
)) = 1;
6012 /* Check all the methods of CLASS_DECL. Methods are first completed
6013 then checked according to regular method existance rules. If no
6014 constructor for CLASS_DECL were encountered, then build its
6018 java_check_regular_methods
(class_decl
)
6021 int saw_constructor
= ANONYMOUS_CLASS_P
(TREE_TYPE
(class_decl
));
6023 tree class
= CLASS_TO_HANDLE_TYPE
(TREE_TYPE
(class_decl
));
6024 tree found
= NULL_TREE
;
6027 /* It is not necessary to check methods defined in java.lang.Object */
6028 if
(class
== object_type_node
)
6031 if
(!TYPE_NVIRTUALS
(class
))
6032 TYPE_METHODS
(class
) = nreverse
(TYPE_METHODS
(class
));
6034 /* Should take interfaces into account. FIXME */
6035 for
(method
= TYPE_METHODS
(class
); method
; method
= TREE_CHAIN
(method
))
6038 tree method_wfl
= DECL_FUNCTION_WFL
(method
);
6041 /* Check for redefinitions */
6042 if
(check_method_redefinition
(class
, method
))
6045 /* If we see one constructor a mark so we don't generate the
6046 default one. Also skip other verifications: constructors
6047 can't be inherited hence hiden or overriden */
6048 if
(DECL_CONSTRUCTOR_P
(method
))
6050 saw_constructor
= 1;
6054 /* We verify things thrown by the method. They must inherits from
6055 java.lang.Throwable */
6056 for
(mthrows
= DECL_FUNCTION_THROWS
(method
);
6057 mthrows
; mthrows
= TREE_CHAIN
(mthrows
))
6059 if
(!inherits_from_p
(TREE_VALUE
(mthrows
), throwable_type_node
))
6061 (TREE_PURPOSE
(mthrows
), "Class `%s' in `throws' clause must be a subclass of class `java.lang.Throwable'",
6063 (DECL_NAME
(TYPE_NAME
(TREE_VALUE
(mthrows
)))));
6066 sig
= build_java_argument_signature
(TREE_TYPE
(method
));
6067 found
= lookup_argument_method2
(class
, DECL_NAME
(method
), sig
);
6069 /* Inner class can't declare static methods */
6070 if
(METHOD_STATIC
(method
) && !TOPLEVEL_CLASS_DECL_P
(class_decl
))
6072 char *t
= xstrdup
(lang_printable_name
(class
, 0));
6074 (method_wfl
, "Method `%s' can't be static in inner class `%s'. Only members of interfaces and top-level classes can be static",
6075 lang_printable_name
(method
, 0), t
);
6079 /* Nothing overrides or it's a private method. */
6082 if
(METHOD_PRIVATE
(found
))
6088 /* If `found' is declared in an interface, make sure the
6089 modifier matches. */
6090 if
(CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(found
)))
6091 && clinit_identifier_node
!= DECL_NAME
(found
)
6092 && !METHOD_PUBLIC
(method
))
6094 tree found_decl
= TYPE_NAME
(DECL_CONTEXT
(found
));
6095 parse_error_context
(method_wfl
, "Class `%s' must override `%s' with a public method in order to implement interface `%s'",
6096 IDENTIFIER_POINTER
(DECL_NAME
(class_decl
)),
6097 lang_printable_name
(method
, 0),
6098 IDENTIFIER_POINTER
(DECL_NAME
(found_decl
)));
6101 /* Can't override a method with the same name and different return
6103 if
(TREE_TYPE
(TREE_TYPE
(found
)) != TREE_TYPE
(TREE_TYPE
(method
)))
6106 (lang_printable_name
(TREE_TYPE
(TREE_TYPE
(found
)), 0));
6109 "Method `%s' was defined with return type `%s' in class `%s'",
6110 lang_printable_name
(found
, 0), t
,
6112 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6116 aflags
= get_access_flags_from_decl
(found
);
6118 /* Can't override final. Can't override static. */
6119 if
(METHOD_FINAL
(found
) || METHOD_STATIC
(found
))
6121 /* Static *can* override static */
6122 if
(METHOD_STATIC
(found
) && METHOD_STATIC
(method
))
6126 "%s methods can't be overriden. Method `%s' is %s in class `%s'",
6127 (METHOD_FINAL
(found
) ?
"Final" : "Static"),
6128 lang_printable_name
(found
, 0),
6129 (METHOD_FINAL
(found
) ?
"final" : "static"),
6131 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6135 /* Static method can't override instance method. */
6136 if
(METHOD_STATIC
(method
))
6140 "Instance methods can't be overriden by a static method. Method `%s' is an instance method in class `%s'",
6141 lang_printable_name
(found
, 0),
6143 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6147 /* - Overriding/hiding public must be public
6148 - Overriding/hiding protected must be protected or public
6149 - If the overriden or hidden method has default (package)
6150 access, then the overriding or hiding method must not be
6151 private; otherwise, a compile-time error occurs. If
6152 `found' belongs to an interface, things have been already
6154 if
(!CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(found
)))
6155 && ((METHOD_PUBLIC
(found
) && !METHOD_PUBLIC
(method
))
6156 ||
(METHOD_PROTECTED
(found
)
6157 && !(METHOD_PUBLIC
(method
) || METHOD_PROTECTED
(method
)))
6158 ||
(!(aflags
& (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC
))
6159 && METHOD_PRIVATE
(method
))))
6163 "Methods can't be overridden to be more private. Method `%s' is not %s in class `%s'", lang_printable_name
(method
, 0),
6164 (METHOD_PUBLIC
(method
) ?
"public" :
6165 (METHOD_PRIVATE
(method
) ?
"private" : "protected")),
6166 IDENTIFIER_POINTER
(DECL_NAME
6167 (TYPE_NAME
(DECL_CONTEXT
(found
)))));
6171 /* Overriding methods must have compatible `throws' clauses on checked
6172 exceptions, if any */
6173 check_throws_clauses
(method
, method_wfl
, found
);
6175 /* Inheriting multiple methods with the same signature. FIXME */
6178 if
(!TYPE_NVIRTUALS
(class
))
6179 TYPE_METHODS
(class
) = nreverse
(TYPE_METHODS
(class
));
6181 /* Search for inherited abstract method not yet implemented in this
6183 java_check_abstract_method_definitions
(class_decl
);
6185 if
(!saw_constructor
)
6189 /* Return a non zero value if the `throws' clause of METHOD (if any)
6190 is incompatible with the `throws' clause of FOUND (if any). */
6193 check_throws_clauses
(method
, method_wfl
, found
)
6194 tree method
, method_wfl
, found
;
6196 tree mthrows
, fthrows
;
6198 /* Can't check these things with class loaded from bytecode. FIXME */
6199 if
(!CLASS_FROM_SOURCE_P
(DECL_CONTEXT
(found
)))
6202 for
(mthrows
= DECL_FUNCTION_THROWS
(method
);
6203 mthrows
; mthrows
= TREE_CHAIN
(mthrows
))
6205 /* We don't verify unchecked expressions */
6206 if
(IS_UNCHECKED_EXCEPTION_P
(TREE_VALUE
(mthrows
)))
6208 /* Checked expression must be compatible */
6209 for
(fthrows
= DECL_FUNCTION_THROWS
(found
);
6210 fthrows
; fthrows
= TREE_CHAIN
(fthrows
))
6211 if
(inherits_from_p
(TREE_VALUE
(mthrows
), TREE_VALUE
(fthrows
)))
6216 (method_wfl
, "Invalid checked exception class `%s' in `throws' clause. The exception must be a subclass of an exception thrown by `%s' from class `%s'",
6217 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(TREE_VALUE
(mthrows
)))),
6218 lang_printable_name
(found
, 0),
6220 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6225 /* Check abstract method of interface INTERFACE */
6228 java_check_abstract_methods
(interface_decl
)
6229 tree interface_decl
;
6232 tree method
, basetype_vec
, found
;
6233 tree interface
= TREE_TYPE
(interface_decl
);
6235 for
(method
= TYPE_METHODS
(interface
); method
; method
= TREE_CHAIN
(method
))
6237 /* 2- Check for double definition inside the defining interface */
6238 if
(check_method_redefinition
(interface
, method
))
6241 /* 3- Overriding is OK as far as we preserve the return type and
6242 the thrown exceptions (FIXME) */
6243 found
= lookup_java_interface_method2
(interface
, method
);
6247 t
= xstrdup
(lang_printable_name
(TREE_TYPE
(TREE_TYPE
(found
)), 0));
6249 (DECL_FUNCTION_WFL
(found
),
6250 "Method `%s' was defined with return type `%s' in class `%s'",
6251 lang_printable_name
(found
, 0), t
,
6253 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6259 /* 4- Inherited methods can't differ by their returned types */
6260 if
(!(basetype_vec
= TYPE_BINFO_BASETYPES
(interface
)))
6262 n
= TREE_VEC_LENGTH
(basetype_vec
);
6263 for
(i
= 0; i
< n
; i
++)
6265 tree sub_interface_method
, sub_interface
;
6266 tree vec_elt
= TREE_VEC_ELT
(basetype_vec
, i
);
6269 sub_interface
= BINFO_TYPE
(vec_elt
);
6270 for
(sub_interface_method
= TYPE_METHODS
(sub_interface
);
6271 sub_interface_method
;
6272 sub_interface_method
= TREE_CHAIN
(sub_interface_method
))
6274 found
= lookup_java_interface_method2
(interface
,
6275 sub_interface_method
);
6276 if
(found
&& (found
!= sub_interface_method
))
6279 (lookup_cl
(sub_interface_method
),
6280 "Interface `%s' inherits method `%s' from interface `%s'. This method is redefined with a different return type in interface `%s'",
6281 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(interface
))),
6282 lang_printable_name
(found
, 0),
6284 (DECL_NAME
(TYPE_NAME
6285 (DECL_CONTEXT
(sub_interface_method
)))),
6287 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6293 /* Lookup methods in interfaces using their name and partial
6294 signature. Return a matching method only if their types differ. */
6297 lookup_java_interface_method2
(class
, method_decl
)
6298 tree class
, method_decl
;
6301 tree basetype_vec
= TYPE_BINFO_BASETYPES
(class
), to_return
;
6306 n
= TREE_VEC_LENGTH
(basetype_vec
);
6307 for
(i
= 0; i
< n
; i
++)
6309 tree vec_elt
= TREE_VEC_ELT
(basetype_vec
, i
), to_return
;
6310 if
((BINFO_TYPE
(vec_elt
) != object_type_node
)
6312 lookup_java_method2
(BINFO_TYPE
(vec_elt
), method_decl
, 1)))
6315 for
(i
= 0; i
< n
; i
++)
6317 to_return
= lookup_java_interface_method2
6318 (BINFO_TYPE
(TREE_VEC_ELT
(basetype_vec
, i
)), method_decl
);
6326 /* Lookup method using their name and partial signature. Return a
6327 matching method only if their types differ. */
6330 lookup_java_method2
(clas
, method_decl
, do_interface
)
6331 tree clas
, method_decl
;
6334 tree method
, method_signature
, method_name
, method_type
, name
;
6336 method_signature
= build_java_argument_signature
(TREE_TYPE
(method_decl
));
6337 name
= DECL_NAME
(method_decl
);
6338 method_name
= (TREE_CODE
(name
) == EXPR_WITH_FILE_LOCATION ?
6339 EXPR_WFL_NODE
(name
) : name
);
6340 method_type
= TREE_TYPE
(TREE_TYPE
(method_decl
));
6342 while
(clas
!= NULL_TREE
)
6344 for
(method
= TYPE_METHODS
(clas
);
6345 method
!= NULL_TREE
; method
= TREE_CHAIN
(method
))
6347 tree method_sig
= build_java_argument_signature
(TREE_TYPE
(method
));
6348 tree name
= DECL_NAME
(method
);
6349 if
((TREE_CODE
(name
) == EXPR_WITH_FILE_LOCATION ?
6350 EXPR_WFL_NODE
(name
) : name
) == method_name
6351 && method_sig
== method_signature
6352 && TREE_TYPE
(TREE_TYPE
(method
)) != method_type
)
6355 clas
= (do_interface ? NULL_TREE
: CLASSTYPE_SUPER
(clas
));
6360 /* Return the line that matches DECL line number, and try its best to
6361 position the column number. Used during error reports. */
6367 static tree cl
= NULL_TREE
;
6373 if
(cl
== NULL_TREE
)
6375 cl
= build_expr_wfl
(NULL_TREE
, NULL
, 0, 0);
6376 ggc_add_tree_root
(&cl
, 1);
6379 EXPR_WFL_FILENAME_NODE
(cl
) = get_identifier
(DECL_SOURCE_FILE
(decl
));
6380 EXPR_WFL_SET_LINECOL
(cl
, DECL_SOURCE_LINE_FIRST
(decl
), -1);
6382 line
= java_get_line_col
(EXPR_WFL_FILENAME
(cl
),
6383 EXPR_WFL_LINENO
(cl
), EXPR_WFL_COLNO
(cl
));
6385 found
= strstr
((const char *)line
,
6386 (const char *)IDENTIFIER_POINTER
(DECL_NAME
(decl
)));
6388 EXPR_WFL_SET_LINECOL
(cl
, EXPR_WFL_LINENO
(cl
), found
- line
);
6393 /* Look for a simple name in the single-type import list */
6396 find_name_in_single_imports
(name
)
6401 for
(node
= ctxp
->import_list
; node
; node
= TREE_CHAIN
(node
))
6402 if
(TREE_VALUE
(node
) == name
)
6403 return
(EXPR_WFL_NODE
(TREE_PURPOSE
(node
)));
6408 /* Process all single-type import. */
6416 for
(import
= ctxp
->import_list
; import
; import
= TREE_CHAIN
(import
))
6418 tree to_be_found
= EXPR_WFL_NODE
(TREE_PURPOSE
(import
));
6419 char *original_name
;
6421 obstack_grow0
(&temporary_obstack
,
6422 IDENTIFIER_POINTER
(to_be_found
),
6423 IDENTIFIER_LENGTH
(to_be_found
));
6424 original_name
= obstack_finish
(&temporary_obstack
);
6426 /* Don't load twice something already defined. */
6427 if
(IDENTIFIER_CLASS_VALUE
(to_be_found
))
6434 QUALIFIED_P
(to_be_found
) = 1;
6435 load_class
(to_be_found
, 0);
6437 check_pkg_class_access
(to_be_found
, TREE_PURPOSE
(import
));
6439 /* We found it, we can bail out */
6440 if
(IDENTIFIER_CLASS_VALUE
(to_be_found
))
6443 /* We haven't found it. Maybe we're trying to access an
6444 inner class. The only way for us to know is to try again
6445 after having dropped a qualifier. If we can't break it further,
6446 we have an error. */
6447 if
(breakdown_qualified
(&left
, NULL
, to_be_found
))
6452 if
(!IDENTIFIER_CLASS_VALUE
(to_be_found
))
6454 parse_error_context
(TREE_PURPOSE
(import
),
6455 "Class or interface `%s' not found in import",
6460 obstack_free
(&temporary_obstack
, original_name
);
6467 /* Possibly find and mark a class imported by a single-type import
6471 find_in_imports
(class_type
)
6476 for
(import
= ctxp
->import_list
; import
; import
= TREE_CHAIN
(import
))
6477 if
(TREE_VALUE
(import
) == TYPE_NAME
(class_type
))
6479 TYPE_NAME
(class_type
) = EXPR_WFL_NODE
(TREE_PURPOSE
(import
));
6480 QUALIFIED_P
(TYPE_NAME
(class_type
)) = 1;
6485 note_possible_classname
(name
, len
)
6490 if
(len
> 5 && strncmp
(&name
[len
-5], ".java", 5) == 0)
6492 else if
(len
> 6 && strncmp
(&name
[len
-6], ".class", 6) == 0)
6496 node
= ident_subst
(name
, len
, "", '/', '.', "");
6497 IS_A_CLASSFILE_NAME
(node
) = 1; /* Or soon to be */
6498 QUALIFIED_P
(node
) = strchr
(name
, '/') ?
1 : 0;
6502 /* Read a import directory, gathering potential match for further type
6503 references. Indifferently reads a filesystem or a ZIP archive
6507 read_import_dir
(wfl
)
6510 tree package_id
= EXPR_WFL_NODE
(wfl
);
6511 const char *package_name
= IDENTIFIER_POINTER
(package_id
);
6512 int package_length
= IDENTIFIER_LENGTH
(package_id
);
6514 JCF
*saved_jcf
= current_jcf
;
6519 struct buffer filename
[1];
6522 if
(IS_AN_IMPORT_ON_DEMAND_P
(package_id
))
6524 IS_AN_IMPORT_ON_DEMAND_P
(package_id
) = 1;
6526 BUFFER_INIT
(filename
);
6527 buffer_grow
(filename
, package_length
+ 100);
6529 for
(entry
= jcf_path_start
(); entry
!= NULL
; entry
= jcf_path_next
(entry
))
6531 const char *entry_name
= jcf_path_name
(entry
);
6532 int entry_length
= strlen
(entry_name
);
6533 if
(jcf_path_is_zipfile
(entry
))
6536 buffer_grow
(filename
, entry_length
);
6537 memcpy
(filename
->data
, entry_name
, entry_length
- 1);
6538 filename
->data
[entry_length
-1] = '\0';
6539 zipf
= opendir_in_zip
(filename
->data
, jcf_path_is_system
(entry
));
6541 error ("malformed .zip archive in CLASSPATH: %s", entry_name
);
6544 ZipDirectory
*zipd
= (ZipDirectory
*) zipf
->central_directory
;
6545 BUFFER_RESET
(filename
);
6546 for
(k
= 0; k
< package_length
; k
++)
6548 char ch
= package_name
[k
];
6549 *filename
->ptr
++ = ch
== '.' ?
'/' : ch
;
6551 *filename
->ptr
++ = '/';
6553 for
(k
= 0; k
< zipf
->count
; k
++, zipd
= ZIPDIR_NEXT
(zipd
))
6555 const char *current_entry
= ZIPDIR_FILENAME
(zipd
);
6556 int current_entry_len
= zipd
->filename_length
;
6558 if
(current_entry_len
>= BUFFER_LENGTH
(filename
)
6559 && strncmp
(filename
->data
, current_entry
,
6560 BUFFER_LENGTH
(filename
)) != 0)
6562 found |
= note_possible_classname
(current_entry
,
6569 BUFFER_RESET
(filename
);
6570 buffer_grow
(filename
, entry_length
+ package_length
+ 4);
6571 strcpy
(filename
->data
, entry_name
);
6572 filename
->ptr
= filename
->data
+ entry_length
;
6573 for
(k
= 0; k
< package_length
; k
++)
6575 char ch
= package_name
[k
];
6576 *filename
->ptr
++ = ch
== '.' ?
'/' : ch
;
6578 *filename
->ptr
= '\0';
6580 dirp
= opendir
(filename
->data
);
6583 *filename
->ptr
++ = '/';
6588 struct dirent
*direntp
= readdir
(dirp
);
6591 d_name
= direntp
->d_name
;
6592 len
= strlen
(direntp
->d_name
);
6593 buffer_grow
(filename
, len
+1);
6594 strcpy
(filename
->ptr
, d_name
);
6595 found |
= note_possible_classname
(filename
->data
+ entry_length
,
6596 package_length
+len
+1);
6603 free
(filename
->data
);
6605 /* Here we should have a unified way of retrieving an entry, to be
6609 static int first
= 1;
6612 error ("Can't find default package `%s'. Check the CLASSPATH environment variable and the access to the archives.", package_name
);
6617 parse_error_context
(wfl
, "Package `%s' not found in import",
6619 current_jcf
= saved_jcf
;
6622 current_jcf
= saved_jcf
;
6625 /* Possibly find a type in the import on demands specified
6626 types. Returns 1 if an error occured, 0 otherwise. Run throught the
6627 entire list, to detected potential double definitions. */
6630 find_in_imports_on_demand
(class_type
)
6633 tree node
, import
, node_to_use
= NULL_TREE
;
6635 tree cl
= NULL_TREE
;
6637 for
(import
= ctxp
->import_demand_list
; import
; import
= TREE_CHAIN
(import
))
6639 const char *id_name
;
6640 obstack_grow
(&temporary_obstack
,
6641 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(TREE_PURPOSE
(import
))),
6642 IDENTIFIER_LENGTH
(EXPR_WFL_NODE
(TREE_PURPOSE
(import
))));
6643 obstack_1grow
(&temporary_obstack
, '.');
6644 obstack_grow0
(&temporary_obstack
,
6645 IDENTIFIER_POINTER
(TYPE_NAME
(class_type
)),
6646 IDENTIFIER_LENGTH
(TYPE_NAME
(class_type
)));
6647 id_name
= obstack_finish
(&temporary_obstack
);
6649 node
= maybe_get_identifier
(id_name
);
6650 if
(node
&& IS_A_CLASSFILE_NAME
(node
))
6654 cl
= TREE_PURPOSE
(import
);
6662 (TREE_PURPOSE
(import
),
6663 "Type `%s' also potentially defined in package `%s'",
6664 IDENTIFIER_POINTER
(TYPE_NAME
(class_type
)),
6665 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(TREE_PURPOSE
(import
))));
6672 /* Setup lineno so that it refers to the line of the import (in
6673 case we parse a class file and encounter errors */
6675 int saved_lineno
= lineno
;
6676 lineno
= EXPR_WFL_LINENO
(cl
);
6677 TYPE_NAME
(class_type
) = node_to_use
;
6678 QUALIFIED_P
(TYPE_NAME
(class_type
)) = 1;
6679 decl
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
));
6680 /* If there is no DECL set for the class or if the class isn't
6681 loaded and not seen in source yet, the load */
6682 if
(!decl ||
(!CLASS_LOADED_P
(TREE_TYPE
(decl
))
6683 && !CLASS_FROM_SOURCE_P
(TREE_TYPE
(decl
))))
6685 load_class
(node_to_use
, 0);
6686 decl
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
));
6688 lineno
= saved_lineno
;
6689 if
(! INNER_CLASS_P
(TREE_TYPE
(decl
)))
6690 return check_pkg_class_access
(TYPE_NAME
(class_type
), cl
);
6692 /* 6.6.1: Inner classes are subject to member access rules. */
6696 return
(seen_once
< 0 ?
0 : seen_once
); /* It's ok not to have found */
6699 /* Add package NAME to the list of package encountered so far. To
6700 speed up class lookup in do_resolve_class, we make sure a
6701 particular package is added only once. */
6704 register_package
(name
)
6707 static struct hash_table _pht
, *pht
= NULL
;
6711 hash_table_init
(&_pht
, hash_newfunc
,
6712 java_hash_hash_tree_node
, java_hash_compare_tree_node
);
6716 if
(!hash_lookup
(pht
, (const hash_table_key
) name
, FALSE
, NULL
))
6718 package_list
= chainon
(package_list
, build_tree_list
(name
, NULL
));
6719 hash_lookup
(pht
, (const hash_table_key
) name
, TRUE
, NULL
);
6724 resolve_package
(pkg
, next
)
6728 tree type_name
= NULL_TREE
;
6729 const char *name
= IDENTIFIER_POINTER
(EXPR_WFL_NODE
(pkg
));
6731 /* The trick is to determine when the package name stops and were
6732 the name of something contained in the package starts. Then we
6733 return a fully qualified name of what we want to get. */
6735 /* Do a quick search on well known package names */
6736 if
(!strncmp
(name
, "java.lang.reflect", 17))
6739 TREE_CHAIN
(TREE_CHAIN
(TREE_CHAIN
(EXPR_WFL_QUALIFICATION
(pkg
))));
6740 type_name
= lookup_package_type
(name
, 17);
6742 else if
(!strncmp
(name
, "java.lang", 9))
6744 *next
= TREE_CHAIN
(TREE_CHAIN
(EXPR_WFL_QUALIFICATION
(pkg
)));
6745 type_name
= lookup_package_type
(name
, 9);
6748 /* If we found something here, return */
6752 *next
= EXPR_WFL_QUALIFICATION
(pkg
);
6754 /* Try to progressively construct a type name */
6755 if
(TREE_CODE
(pkg
) == EXPR_WITH_FILE_LOCATION
)
6756 for
(acc
= NULL_TREE
, current
= EXPR_WFL_QUALIFICATION
(pkg
);
6757 current
; current
= TREE_CHAIN
(current
))
6759 acc
= merge_qualified_name
(acc
, EXPR_WFL_NODE
(QUAL_WFL
(current
)));
6760 if
((type_name
= resolve_no_layout
(acc
, NULL_TREE
)))
6763 /* resolve_package should be used in a loop, hence we
6764 point at this one to naturally process the next one at
6765 the next iteration. */
6774 lookup_package_type
(name
, from
)
6779 const char *sub
= &name
[from
+1];
6780 while
(*sub
!= '.' && *sub
)
6782 strncpy
(subname
, name
, sub
-name
);
6783 subname
[sub
-name
] = '\0';
6784 return get_identifier
(subname
);
6787 /* Check accessibility of inner classes according to member access rules.
6788 DECL is the inner class, ENCLOSING_DECL is the class from which the
6789 access is being attempted. */
6792 check_inner_class_access
(decl
, enclosing_decl
, cl
)
6793 tree decl
, enclosing_decl
, cl
;
6796 tree enclosing_decl_type
;
6798 /* We don't issue an error message when CL is null. CL can be null
6799 as a result of processing a JDEP crafted by source_start_java_method
6800 for the purpose of patching its parm decl. But the error would
6801 have been already trapped when fixing the method's signature.
6802 DECL can also be NULL in case of earlier errors. */
6806 enclosing_decl_type
= TREE_TYPE
(enclosing_decl
);
6808 if
(CLASS_PRIVATE
(decl
))
6810 /* Access is permitted only within the body of the top-level
6811 class in which DECL is declared. */
6812 tree top_level
= decl
;
6813 while
(DECL_CONTEXT
(top_level
))
6814 top_level
= DECL_CONTEXT
(top_level
);
6815 while
(DECL_CONTEXT
(enclosing_decl
))
6816 enclosing_decl
= DECL_CONTEXT
(enclosing_decl
);
6817 if
(top_level
== enclosing_decl
)
6821 else if
(CLASS_PROTECTED
(decl
))
6824 /* Access is permitted from within the same package... */
6825 if
(in_same_package
(decl
, enclosing_decl
))
6828 /* ... or from within the body of a subtype of the context in which
6829 DECL is declared. */
6830 decl_context
= DECL_CONTEXT
(decl
);
6831 while
(enclosing_decl
)
6833 if
(CLASS_INTERFACE
(decl
))
6835 if
(interface_of_p
(TREE_TYPE
(decl_context
),
6836 enclosing_decl_type
))
6841 /* Eww. The order of the arguments is different!! */
6842 if
(inherits_from_p
(enclosing_decl_type
,
6843 TREE_TYPE
(decl_context
)))
6846 enclosing_decl
= DECL_CONTEXT
(enclosing_decl
);
6848 access
= "protected";
6850 else if
(! CLASS_PUBLIC
(decl
))
6852 /* Access is permitted only from within the same package as DECL. */
6853 if
(in_same_package
(decl
, enclosing_decl
))
6855 access
= "non-public";
6858 /* Class is public. */
6861 parse_error_context
(cl
, "Nested %s %s is %s; cannot be accessed from here",
6862 (CLASS_INTERFACE
(decl
) ?
"interface" : "class"),
6863 lang_printable_name
(decl
, 0), access
);
6866 /* Accessibility check for top-level classes. If CLASS_NAME is in a foreign
6867 package, it must be PUBLIC. Return 0 if no access violations were found,
6871 check_pkg_class_access
(class_name
, cl
)
6877 if
(!IDENTIFIER_CLASS_VALUE
(class_name
))
6880 if
(!(type
= TREE_TYPE
(IDENTIFIER_CLASS_VALUE
(class_name
))))
6883 if
(!CLASS_PUBLIC
(TYPE_NAME
(type
)))
6885 /* Access to a private class within the same package is
6888 breakdown_qualified
(&l
, &r
, class_name
);
6889 if
(!QUALIFIED_P
(class_name
) && !ctxp
->package
)
6890 /* Both in the empty package. */
6892 if
(l
== ctxp
->package
)
6893 /* Both in the same package. */
6897 (cl
, "Can't access %s `%s'. Only public classes and interfaces in other packages can be accessed",
6898 (CLASS_INTERFACE
(TYPE_NAME
(type
)) ?
"interface" : "class"),
6899 IDENTIFIER_POINTER
(class_name
));
6905 /* Local variable declaration. */
6908 declare_local_variables
(modifier
, type
, vlist
)
6913 tree decl
, current
, saved_type
;
6914 tree type_wfl
= NULL_TREE
;
6918 /* Push a new block if statements were seen between the last time we
6919 pushed a block and now. Keep a count of blocks to close */
6920 if
(BLOCK_EXPR_BODY
(GET_CURRENT_BLOCK
(current_function_decl
)))
6922 tree b
= enter_block
();
6923 BLOCK_IS_IMPLICIT
(b
) = 1;
6929 for
(i
= 0; i
<= 10; i
++) if
(1 << i
& modifier
) break
;
6930 if
(modifier
== ACC_FINAL
)
6935 (ctxp
->modifier_ctx
[i
],
6936 "Only `final' is allowed as a local variables modifier");
6941 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
6942 hold the TYPE value if a new incomplete has to be created (as
6943 opposed to being found already existing and reused). */
6944 SET_TYPE_FOR_RESOLUTION
(type
, type_wfl
, must_chain
);
6946 /* If TYPE is fully resolved and we don't have a reference, make one */
6947 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
6949 /* Go through all the declared variables */
6950 for
(current
= vlist
, saved_type
= type
; current
;
6951 current
= TREE_CHAIN
(current
), type
= saved_type
)
6953 tree other
, real_type
;
6954 tree wfl
= TREE_PURPOSE
(current
);
6955 tree name
= EXPR_WFL_NODE
(wfl
);
6956 tree init
= TREE_VALUE
(current
);
6958 /* Process NAME, as it may specify extra dimension(s) for it */
6959 type
= build_array_from_name
(type
, type_wfl
, name
, &name
);
6961 /* Variable redefinition check */
6962 if
((other
= lookup_name_in_blocks
(name
)))
6964 variable_redefinition_error
(wfl
, name
, TREE_TYPE
(other
),
6965 DECL_SOURCE_LINE
(other
));
6969 /* Type adjustment. We may have just readjusted TYPE because
6970 the variable specified more dimensions. Make sure we have
6971 a reference if we can and don't have one already. */
6972 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
6974 real_type
= GET_REAL_TYPE
(type
);
6975 /* Never layout this decl. This will be done when its scope
6977 decl
= build_decl
(VAR_DECL
, name
, real_type
);
6978 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(decl
);
6979 LOCAL_FINAL
(decl
) = final_p
;
6980 BLOCK_CHAIN_DECL
(decl
);
6982 /* If doing xreferencing, replace the line number with the WFL
6985 DECL_SOURCE_LINE
(decl
) = EXPR_WFL_LINECOL
(wfl
);
6987 /* Don't try to use an INIT statement when an error was found */
6988 if
(init
&& java_error_count
)
6991 /* Add the initialization function to the current function's code */
6994 /* Name might have been readjusted */
6995 EXPR_WFL_NODE
(TREE_OPERAND
(init
, 0)) = name
;
6996 MODIFY_EXPR_FROM_INITIALIZATION_P
(init
) = 1;
6997 java_method_add_stmt
(current_function_decl
,
6998 build_debugable_stmt
(EXPR_WFL_LINECOL
(init
),
7002 /* Setup dependency the type of the decl */
7006 register_incomplete_type
(JDEP_VARIABLE
, type_wfl
, decl
, type
);
7007 dep
= CLASSD_LAST
(ctxp
->classd_list
);
7008 JDEP_GET_PATCH
(dep
) = &TREE_TYPE
(decl
);
7011 SOURCE_FRONTEND_DEBUG
(("Defined locals"));
7014 /* Called during parsing. Build decls from argument list. */
7017 source_start_java_method
(fndecl
)
7027 current_function_decl
= fndecl
;
7029 /* New scope for the function */
7031 for
(tem
= TYPE_ARG_TYPES
(TREE_TYPE
(fndecl
)), i
= 0;
7032 tem
!= end_params_node
; tem
= TREE_CHAIN
(tem
), i
++)
7034 tree type
= TREE_VALUE
(tem
);
7035 tree name
= TREE_PURPOSE
(tem
);
7037 /* If type is incomplete. Create an incomplete decl and ask for
7038 the decl to be patched later */
7039 if
(INCOMPLETE_TYPE_P
(type
))
7042 tree real_type
= GET_REAL_TYPE
(type
);
7043 parm_decl
= build_decl
(PARM_DECL
, name
, real_type
);
7044 type
= obtain_incomplete_type
(type
);
7045 register_incomplete_type
(JDEP_PARM
, NULL_TREE
, NULL_TREE
, type
);
7046 jdep
= CLASSD_LAST
(ctxp
->classd_list
);
7047 JDEP_MISC
(jdep
) = name
;
7048 JDEP_GET_PATCH
(jdep
) = &TREE_TYPE
(parm_decl
);
7051 parm_decl
= build_decl
(PARM_DECL
, name
, type
);
7053 /* Remember if a local variable was declared final (via its
7054 TREE_LIST of type/name.) Set LOCAL_FINAL accordingly. */
7055 if
(ARG_FINAL_P
(tem
))
7057 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(parm_decl
);
7058 LOCAL_FINAL
(parm_decl
) = 1;
7061 BLOCK_CHAIN_DECL
(parm_decl
);
7063 tem
= BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(current_function_decl
));
7064 BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(current_function_decl
)) =
7066 DECL_ARG_SLOT_COUNT
(current_function_decl
) = i
;
7067 DECL_MAX_LOCALS
(current_function_decl
) = i
;
7070 /* Called during parsing. Creates an artificial method declaration. */
7073 create_artificial_method
(class
, flags
, type
, name
, args
)
7076 tree type
, name
, args
;
7080 java_parser_context_save_global
();
7082 mdecl
= make_node
(FUNCTION_TYPE
);
7083 TREE_TYPE
(mdecl
) = type
;
7084 TYPE_ARG_TYPES
(mdecl
) = args
;
7085 mdecl
= add_method
(class
, flags
, name
, build_java_signature
(mdecl
));
7086 java_parser_context_restore_global
();
7087 DECL_ARTIFICIAL
(mdecl
) = 1;
7091 /* Starts the body if an artifical method. */
7094 start_artificial_method_body
(mdecl
)
7097 DECL_SOURCE_LINE
(mdecl
) = 1;
7098 DECL_SOURCE_LINE_MERGE
(mdecl
, 1);
7099 source_start_java_method
(mdecl
);
7104 end_artificial_method_body
(mdecl
)
7107 /* exit_block modifies DECL_FUNCTION_BODY (current_function_decl).
7108 It has to be evaluated first. (if mdecl is current_function_decl,
7109 we have an undefined behavior if no temporary variable is used.) */
7110 tree b
= exit_block
();
7111 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(mdecl
)) = b
;
7115 /* Terminate a function and expand its body. */
7118 source_end_java_method
()
7120 tree fndecl
= current_function_decl
;
7125 java_parser_context_save_global
();
7126 lineno
= ctxp
->last_ccb_indent1
;
7128 /* Turn function bodies with only a NOP expr null, so they don't get
7129 generated at all and we won't get warnings when using the -W
7131 if
(BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
)) == empty_stmt_node
)
7132 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
)) = NULL_TREE
;
7134 /* Generate function's code */
7135 if
(BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
))
7136 && ! flag_emit_class_files
7137 && ! flag_emit_xref
)
7138 expand_expr_stmt
(BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
)));
7140 /* pop out of its parameters */
7141 pushdecl_force_head
(DECL_ARGUMENTS
(fndecl
));
7143 BLOCK_SUPERCONTEXT
(DECL_INITIAL
(fndecl
)) = fndecl
;
7145 /* Generate rtl for function exit. */
7146 if
(! flag_emit_class_files
&& ! flag_emit_xref
)
7148 lineno
= DECL_SOURCE_LINE_LAST
(fndecl
);
7149 expand_function_end
(input_filename
, lineno
, 0);
7151 /* Run the optimizers and output assembler code for this function. */
7152 rest_of_compilation
(fndecl
);
7155 current_function_decl
= NULL_TREE
;
7156 java_parser_context_restore_global
();
7159 /* Record EXPR in the current function block. Complements compound
7160 expression second operand if necessary. */
7163 java_method_add_stmt
(fndecl
, expr
)
7166 if
(!GET_CURRENT_BLOCK
(fndecl
))
7168 return add_stmt_to_block
(GET_CURRENT_BLOCK
(fndecl
), NULL_TREE
, expr
);
7172 add_stmt_to_block
(b
, type
, stmt
)
7175 tree body
= BLOCK_EXPR_BODY
(b
), c
;
7177 if
(java_error_count
)
7180 if
((c
= add_stmt_to_compound
(body
, type
, stmt
)) == body
)
7183 BLOCK_EXPR_BODY
(b
) = c
;
7184 TREE_SIDE_EFFECTS
(c
) = 1;
7188 /* Add STMT to EXISTING if possible, otherwise create a new
7189 COMPOUND_EXPR and add STMT to it. */
7192 add_stmt_to_compound
(existing
, type
, stmt
)
7193 tree existing
, type
, stmt
;
7196 return build
(COMPOUND_EXPR
, type
, existing
, stmt
);
7201 void java_layout_seen_class_methods
()
7203 tree previous_list
= all_class_list
;
7204 tree end
= NULL_TREE
;
7209 for
(current
= previous_list
;
7210 current
!= end
; current
= TREE_CHAIN
(current
))
7211 layout_class_methods
(TREE_TYPE
(TREE_VALUE
(current
)));
7213 if
(previous_list
!= all_class_list
)
7215 end
= previous_list
;
7216 previous_list
= all_class_list
;
7224 java_reorder_fields
()
7226 static tree stop_reordering
= NULL_TREE
;
7227 static int initialized_p
;
7230 /* Register STOP_REORDERING with the garbage collector. */
7233 ggc_add_tree_root
(&stop_reordering
, 1);
7237 for
(current
= gclass_list
; current
; current
= TREE_CHAIN
(current
))
7239 current_class
= TREE_TYPE
(TREE_VALUE
(current
));
7241 if
(current_class
== stop_reordering
)
7244 /* Reverse the fields, but leave the dummy field in front.
7245 Fields are already ordered for Object and Class */
7246 if
(TYPE_FIELDS
(current_class
) && current_class
!= object_type_node
7247 && current_class
!= class_type_node
)
7249 /* If the dummy field is there, reverse the right fields and
7250 just layout the type for proper fields offset */
7251 if
(!DECL_NAME
(TYPE_FIELDS
(current_class
)))
7253 tree fields
= TYPE_FIELDS
(current_class
);
7254 TREE_CHAIN
(fields
) = nreverse
(TREE_CHAIN
(fields
));
7255 TYPE_SIZE
(current_class
) = NULL_TREE
;
7257 /* We don't have a dummy field, we need to layout the class,
7258 after having reversed the fields */
7261 TYPE_FIELDS
(current_class
) =
7262 nreverse
(TYPE_FIELDS
(current_class
));
7263 TYPE_SIZE
(current_class
) = NULL_TREE
;
7267 stop_reordering
= TREE_TYPE
(TREE_VALUE
(gclass_list
));
7270 /* Layout the methods of all classes loaded in one way or another.
7271 Check methods of source parsed classes. Then reorder the
7272 fields and layout the classes or the type of all source parsed
7276 java_layout_classes
()
7279 int save_error_count
= java_error_count
;
7281 /* Layout the methods of all classes seen so far */
7282 java_layout_seen_class_methods
();
7283 java_parse_abort_on_error
();
7284 all_class_list
= NULL_TREE
;
7286 /* Then check the methods of all parsed classes */
7287 for
(current
= gclass_list
; current
; current
= TREE_CHAIN
(current
))
7288 if
(CLASS_FROM_SOURCE_P
(TREE_TYPE
(TREE_VALUE
(current
))))
7289 java_check_methods
(TREE_VALUE
(current
));
7290 java_parse_abort_on_error
();
7292 for
(current
= gclass_list
; current
; current
= TREE_CHAIN
(current
))
7294 current_class
= TREE_TYPE
(TREE_VALUE
(current
));
7295 layout_class
(current_class
);
7297 /* From now on, the class is considered completely loaded */
7298 CLASS_LOADED_P
(current_class
) = 1;
7300 /* Error reported by the caller */
7301 if
(java_error_count
)
7305 /* We might have reloaded classes durign the process of laying out
7306 classes for code generation. We must layout the methods of those
7307 late additions, as constructor checks might use them */
7308 java_layout_seen_class_methods
();
7309 java_parse_abort_on_error
();
7312 /* Expand methods in the current set of classes rememebered for
7316 java_complete_expand_classes
()
7320 do_not_fold
= flag_emit_xref
;
7322 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
7323 if
(!INNER_CLASS_DECL_P
(current
))
7324 java_complete_expand_class
(current
);
7327 /* Expand the methods found in OUTER, starting first by OUTER's inner
7331 java_complete_expand_class
(outer
)
7336 set_nested_class_simple_name_value
(outer
, 1); /* Set */
7338 /* We need to go after all inner classes and start expanding them,
7339 starting with most nested ones. We have to do that because nested
7340 classes might add functions to outer classes */
7342 for
(inner_list
= DECL_INNER_CLASS_LIST
(outer
);
7343 inner_list
; inner_list
= TREE_CHAIN
(inner_list
))
7344 java_complete_expand_class
(TREE_PURPOSE
(inner_list
));
7346 java_complete_expand_methods
(outer
);
7347 set_nested_class_simple_name_value
(outer
, 0); /* Reset */
7350 /* Expand methods registered in CLASS_DECL. The general idea is that
7351 we expand regular methods first. This allows us get an estimate on
7352 how outer context local alias fields are really used so we can add
7353 to the constructor just enough code to initialize them properly (it
7354 also lets us generate finit$ correctly.) Then we expand the
7355 constructors and then <clinit>. */
7358 java_complete_expand_methods
(class_decl
)
7361 tree clinit
, finit
, decl
, first_decl
;
7363 current_class
= TREE_TYPE
(class_decl
);
7365 /* Find whether the class has final variables */
7366 for
(decl
= TYPE_FIELDS
(current_class
); decl
; decl
= TREE_CHAIN
(decl
))
7367 if
(FIELD_FINAL
(decl
))
7369 TYPE_HAS_FINAL_VARIABLE
(current_class
) = 1;
7373 /* Initialize a new constant pool */
7374 init_outgoing_cpool
();
7376 /* Pre-expand <clinit> to figure whether we really need it or
7377 not. If we do need it, we pre-expand the static fields so they're
7378 ready to be used somewhere else. <clinit> will be fully expanded
7379 after we processed the constructors. */
7380 first_decl
= TYPE_METHODS
(current_class
);
7381 clinit
= maybe_generate_pre_expand_clinit
(current_class
);
7383 /* Then generate finit$ (if we need to) because constructor will
7385 if
(TYPE_FINIT_STMT_LIST
(current_class
))
7387 finit
= generate_finit
(current_class
);
7388 java_complete_expand_method
(finit
);
7391 /* Now do the constructors */
7392 for
(decl
= first_decl
; !java_error_count
&& decl
; decl
= TREE_CHAIN
(decl
))
7396 if
(!DECL_CONSTRUCTOR_P
(decl
))
7399 no_body
= !DECL_FUNCTION_BODY
(decl
);
7400 /* Don't generate debug info on line zero when expanding a
7401 generated constructor. */
7403 restore_line_number_status
(1);
7405 /* Reset the final local variable assignment flags */
7406 if
(TYPE_HAS_FINAL_VARIABLE
(current_class
))
7407 reset_final_variable_local_assignment_flag
(current_class
);
7409 java_complete_expand_method
(decl
);
7411 /* Check for missed out final variable assignment */
7412 if
(TYPE_HAS_FINAL_VARIABLE
(current_class
))
7413 check_final_variable_local_assignment_flag
(current_class
, decl
);
7416 restore_line_number_status
(0);
7419 /* First, do the ordinary methods. */
7420 for
(decl
= first_decl
; decl
; decl
= TREE_CHAIN
(decl
))
7422 /* Skip abstract or native methods -- but do handle native
7423 methods when generating JNI stubs. */
7424 if
(METHOD_ABSTRACT
(decl
)
7425 ||
(! flag_jni
&& METHOD_NATIVE
(decl
))
7426 || DECL_CONSTRUCTOR_P
(decl
) || DECL_CLINIT_P
(decl
))
7429 if
(METHOD_NATIVE
(decl
))
7431 tree body
= build_jni_stub
(decl
);
7432 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(decl
)) = body
;
7435 java_complete_expand_method
(decl
);
7438 /* If there is indeed a <clinit>, fully expand it now */
7441 /* Reset the final local variable assignment flags */
7442 if
(TYPE_HAS_FINAL_VARIABLE
(current_class
))
7443 reset_static_final_variable_assignment_flag
(current_class
);
7444 /* Prevent the use of `this' inside <clinit> */
7445 ctxp
->explicit_constructor_p
= 1;
7446 java_complete_expand_method
(clinit
);
7447 ctxp
->explicit_constructor_p
= 0;
7448 /* Check for missed out static final variable assignment */
7449 if
(TYPE_HAS_FINAL_VARIABLE
(current_class
)
7450 && !CLASS_INTERFACE
(class_decl
))
7451 check_static_final_variable_assignment_flag
(current_class
);
7454 /* We might have generated a class$ that we now want to expand */
7455 if
(TYPE_DOT_CLASS
(current_class
))
7456 java_complete_expand_method
(TYPE_DOT_CLASS
(current_class
));
7458 /* Now verify constructor circularity (stop after the first one we
7460 if
(!CLASS_INTERFACE
(class_decl
))
7461 for
(decl
= TYPE_METHODS
(current_class
); decl
; decl
= TREE_CHAIN
(decl
))
7462 if
(DECL_CONSTRUCTOR_P
(decl
)
7463 && verify_constructor_circularity
(decl
, decl
))
7466 /* Final check on the initialization of final variables. */
7467 if
(TYPE_HAS_FINAL_VARIABLE
(current_class
))
7469 check_final_variable_global_assignment_flag
(current_class
);
7470 /* If we have an interface, check for uninitialized fields. */
7471 if
(CLASS_INTERFACE
(class_decl
))
7472 check_static_final_variable_assignment_flag
(current_class
);
7475 /* Save the constant pool. We'll need to restore it later. */
7476 TYPE_CPOOL
(current_class
) = outgoing_cpool
;
7479 /* Attempt to create <clinit>. Pre-expand static fields so they can be
7480 safely used in some other methods/constructors. */
7483 maybe_generate_pre_expand_clinit
(class_type
)
7486 tree current
, mdecl
;
7488 if
(!TYPE_CLINIT_STMT_LIST
(class_type
))
7491 /* Go through all static fields and pre expand them */
7492 for
(current
= TYPE_FIELDS
(class_type
); current
;
7493 current
= TREE_CHAIN
(current
))
7494 if
(FIELD_STATIC
(current
))
7495 build_field_ref
(NULL_TREE
, class_type
, DECL_NAME
(current
));
7497 /* Then build the <clinit> method */
7498 mdecl
= create_artificial_method
(class_type
, ACC_STATIC
, void_type_node
,
7499 clinit_identifier_node
, end_params_node
);
7500 layout_class_method
(class_type
, CLASSTYPE_SUPER
(class_type
),
7502 start_artificial_method_body
(mdecl
);
7504 /* We process the list of assignment we produced as the result of
7505 the declaration of initialized static field and add them as
7506 statement to the <clinit> method. */
7507 for
(current
= TYPE_CLINIT_STMT_LIST
(class_type
); current
;
7508 current
= TREE_CHAIN
(current
))
7510 tree stmt
= current
;
7511 /* We build the assignment expression that will initialize the
7512 field to its value. There are strict rules on static
7513 initializers (8.5). FIXME */
7514 if
(TREE_CODE
(stmt
) != BLOCK
&& stmt
!= empty_stmt_node
)
7515 stmt
= build_debugable_stmt
(EXPR_WFL_LINECOL
(stmt
), stmt
);
7516 java_method_add_stmt
(mdecl
, stmt
);
7519 end_artificial_method_body
(mdecl
);
7521 /* Now we want to place <clinit> as the last method (because we need
7522 it at least for interface so that it doesn't interfere with the
7523 dispatch table based lookup. */
7524 if
(TREE_CHAIN
(TYPE_METHODS
(class_type
)))
7526 current
= TREE_CHAIN
(TYPE_METHODS
(class_type
));
7527 TYPE_METHODS
(class_type
) = current
;
7529 while
(TREE_CHAIN
(current
))
7530 current
= TREE_CHAIN
(current
);
7532 TREE_CHAIN
(current
) = mdecl
;
7533 TREE_CHAIN
(mdecl
) = NULL_TREE
;
7539 /* Analyzes a method body and look for something that isn't a
7543 analyze_clinit_body
(bbody
)
7547 switch
(TREE_CODE
(bbody
))
7550 bbody
= BLOCK_EXPR_BODY
(bbody
);
7553 case EXPR_WITH_FILE_LOCATION
:
7554 bbody
= EXPR_WFL_NODE
(bbody
);
7558 if
(analyze_clinit_body
(TREE_OPERAND
(bbody
, 0)))
7560 bbody
= TREE_OPERAND
(bbody
, 1);
7575 /* See whether we could get rid of <clinit>. Criteria are: all static
7576 final fields have constant initial values and the body of <clinit>
7577 is empty. Return 1 if <clinit> was discarded, 0 otherwise. */
7580 maybe_yank_clinit
(mdecl
)
7587 if
(!DECL_CLINIT_P
(mdecl
))
7590 /* If the body isn't empty, then we keep <clinit>. Note that if
7591 we're emitting classfiles, this isn't enough not to rule it
7593 fbody
= DECL_FUNCTION_BODY
(mdecl
);
7594 bbody
= BLOCK_EXPR_BODY
(fbody
);
7595 if
(bbody
&& bbody
!= error_mark_node
)
7596 bbody
= BLOCK_EXPR_BODY
(bbody
);
7599 if
(bbody
&& ! flag_emit_class_files
&& bbody
!= empty_stmt_node
)
7602 type
= DECL_CONTEXT
(mdecl
);
7603 current
= TYPE_FIELDS
(type
);
7605 for
(current
= (current ? TREE_CHAIN
(current
) : current
);
7606 current
; current
= TREE_CHAIN
(current
))
7610 /* We're not interested in non static field */
7611 if
(!FIELD_STATIC
(current
))
7614 /* Anything that isn't String or a basic type is ruled out -- or
7615 if we know how to deal with it (when doing things natively) we
7616 should generated an empty <clinit> so that SUID are computed
7618 if
(! JSTRING_TYPE_P
(TREE_TYPE
(current
))
7619 && ! JNUMERIC_TYPE_P
(TREE_TYPE
(current
)))
7622 f_init
= DECL_INITIAL
(current
);
7623 /* If we're emitting native code, we want static final fields to
7624 have constant initializers. If we don't meet these
7625 conditions, we keep <clinit> */
7626 if
(!flag_emit_class_files
7627 && !(FIELD_FINAL
(current
) && f_init
&& TREE_CONSTANT
(f_init
)))
7629 /* If we're emitting bytecode, we want static fields to have
7630 constant initializers or no initializer. If we don't meet
7631 these conditions, we keep <clinit> */
7632 if
(flag_emit_class_files
&& f_init
&& !TREE_CONSTANT
(f_init
))
7636 /* Now we analyze the method body and look for something that
7637 isn't a MODIFY_EXPR */
7638 if
(bbody
== empty_stmt_node
)
7641 found
= analyze_clinit_body
(bbody
);
7643 if
(current || found
)
7646 /* Get rid of <clinit> in the class' list of methods */
7647 if
(TYPE_METHODS
(type
) == mdecl
)
7648 TYPE_METHODS
(type
) = TREE_CHAIN
(mdecl
);
7650 for
(current
= TYPE_METHODS
(type
); current
;
7651 current
= TREE_CHAIN
(current
))
7652 if
(TREE_CHAIN
(current
) == mdecl
)
7654 TREE_CHAIN
(current
) = TREE_CHAIN
(mdecl
);
7662 /* Complete and expand a method. */
7665 java_complete_expand_method
(mdecl
)
7668 int yank_clinit
= 0;
7670 current_function_decl
= mdecl
;
7671 /* Fix constructors before expanding them */
7672 if
(DECL_CONSTRUCTOR_P
(mdecl
))
7673 fix_constructors
(mdecl
);
7675 /* Expand functions that have a body */
7676 if
(DECL_FUNCTION_BODY
(mdecl
))
7678 tree fbody
= DECL_FUNCTION_BODY
(mdecl
);
7679 tree block_body
= BLOCK_EXPR_BODY
(fbody
);
7680 tree exception_copy
= NULL_TREE
;
7683 current_function_decl
= mdecl
;
7686 fprintf
(stderr
, " [%s.",
7687 lang_printable_name
(DECL_CONTEXT
(mdecl
), 0));
7688 announce_function
(mdecl
);
7690 fprintf
(stderr
, "]");
7692 pushlevel
(1); /* Prepare for a parameter push */
7693 ptr
= &DECL_ARGUMENTS
(mdecl
);
7694 tem
= BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(current_function_decl
));
7697 tree next
= TREE_CHAIN
(tem
);
7698 tree type
= TREE_TYPE
(tem
);
7699 if
(PROMOTE_PROTOTYPES
7700 && TYPE_PRECISION
(type
) < TYPE_PRECISION
(integer_type_node
)
7701 && INTEGRAL_TYPE_P
(type
))
7702 type
= integer_type_node
;
7703 DECL_ARG_TYPE
(tem
) = type
;
7704 layout_decl
(tem
, 0);
7707 ptr
= &TREE_CHAIN
(tem
);
7711 pushdecl_force_head
(DECL_ARGUMENTS
(mdecl
));
7712 lineno
= DECL_SOURCE_LINE_FIRST
(mdecl
);
7714 build_result_decl
(mdecl
);
7717 = (!METHOD_STATIC
(mdecl
) ?
7718 BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(mdecl
)) : NULL_TREE
);
7720 /* Purge the `throws' list of unchecked exceptions. If we're
7721 doing xref, save a copy of the list and re-install it
7724 exception_copy
= copy_list
(DECL_FUNCTION_THROWS
(mdecl
));
7726 purge_unchecked_exceptions
(mdecl
);
7728 /* Install exceptions thrown with `throws' */
7729 PUSH_EXCEPTIONS
(DECL_FUNCTION_THROWS
(mdecl
));
7731 if
(block_body
!= NULL_TREE
)
7733 block_body
= java_complete_tree
(block_body
);
7735 if
(! flag_emit_xref
&& ! METHOD_NATIVE
(mdecl
))
7736 check_for_initialization
(block_body
);
7737 ctxp
->explicit_constructor_p
= 0;
7740 BLOCK_EXPR_BODY
(fbody
) = block_body
;
7742 /* If we saw a return but couldn't evaluate it properly, we'll
7743 have an error_mark_node here. */
7744 if
(block_body
!= error_mark_node
7745 && (block_body
== NULL_TREE || CAN_COMPLETE_NORMALLY
(block_body
))
7746 && TREE_CODE
(TREE_TYPE
(TREE_TYPE
(mdecl
))) != VOID_TYPE
7748 missing_return_error
(current_function_decl
);
7750 /* Check wether we could just get rid of clinit, now the picture
7752 if
(!(yank_clinit
= maybe_yank_clinit
(mdecl
)))
7753 complete_start_java_method
(mdecl
);
7755 /* Don't go any further if we've found error(s) during the
7757 if
(!java_error_count
&& !yank_clinit
)
7758 source_end_java_method
();
7761 if
(java_error_count
)
7762 pushdecl_force_head
(DECL_ARGUMENTS
(mdecl
));
7766 /* Pop the exceptions and sanity check */
7768 if
(currently_caught_type_list
)
7772 DECL_FUNCTION_THROWS
(mdecl
) = exception_copy
;
7778 /* This section of the code deals with accessing enclosing context
7779 fields either directly by using the relevant access to this$<n> or
7780 by invoking an access method crafted for that purpose. */
7782 /* Build the necessary access from an inner class to an outer
7783 class. This routine could be optimized to cache previous result
7784 (decl, current_class and returned access). When an access method
7785 needs to be generated, it always takes the form of a read. It might
7786 be later turned into a write by calling outer_field_access_fix. */
7789 build_outer_field_access
(id
, decl
)
7792 tree access
= NULL_TREE
;
7793 tree ctx
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(current_class
)));
7794 tree decl_ctx
= DECL_CONTEXT
(decl
);
7796 /* If the immediate enclosing context of the current class is the
7797 field decl's class or inherits from it; build the access as
7798 `this$<n>.<field>'. Note that we will break the `private' barrier
7799 if we're not emitting bytecodes. */
7800 if
((ctx
== decl_ctx || inherits_from_p
(ctx
, decl_ctx
))
7801 && (!FIELD_PRIVATE
(decl
) ||
!flag_emit_class_files
))
7803 tree thisn
= build_current_thisn
(current_class
);
7804 access
= make_qualified_primary
(build_wfl_node
(thisn
),
7805 id
, EXPR_WFL_LINECOL
(id
));
7807 /* Otherwise, generate access methods to outer this and access the
7808 field (either using an access method or by direct access.) */
7811 int lc
= EXPR_WFL_LINECOL
(id
);
7813 /* Now we chain the required number of calls to the access$0 to
7814 get a hold to the enclosing instance we need, and then we
7815 build the field access. */
7816 access
= build_access_to_thisn
(current_class
, decl_ctx
, lc
);
7818 /* If the field is private and we're generating bytecode, then
7819 we generate an access method */
7820 if
(FIELD_PRIVATE
(decl
) && flag_emit_class_files
)
7822 tree name
= build_outer_field_access_methods
(decl
);
7823 access
= build_outer_field_access_expr
(lc
, decl_ctx
,
7824 name
, access
, NULL_TREE
);
7826 /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'.
7827 Once again we break the `private' access rule from a foreign
7830 access
= make_qualified_primary
(access
, id
, lc
);
7832 return resolve_expression_name
(access
, NULL
);
7835 /* Return a non zero value if NODE describes an outer field inner
7839 outer_field_access_p
(type
, decl
)
7842 if
(!INNER_CLASS_TYPE_P
(type
)
7843 || TREE_CODE
(decl
) != FIELD_DECL
7844 || DECL_CONTEXT
(decl
) == type
)
7847 /* If the inner class extends the declaration context of the field
7848 we're try to acces, then this isn't an outer field access */
7849 if
(inherits_from_p
(type
, DECL_CONTEXT
(decl
)))
7852 for
(type
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type
))); ;
7853 type
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type
))))
7855 if
(type
== DECL_CONTEXT
(decl
))
7858 if
(!DECL_CONTEXT
(TYPE_NAME
(type
)))
7860 /* Before we give up, see whether the field is inherited from
7861 the enclosing context we're considering. */
7862 if
(inherits_from_p
(type
, DECL_CONTEXT
(decl
)))
7871 /* Return a non zero value if NODE represents an outer field inner
7872 access that was been already expanded. As a side effect, it returns
7873 the name of the field being accessed and the argument passed to the
7874 access function, suitable for a regeneration of the access method
7875 call if necessary. */
7878 outer_field_expanded_access_p
(node
, name
, arg_type
, arg
)
7879 tree node
, *name
, *arg_type
, *arg
;
7883 if
(TREE_CODE
(node
) != CALL_EXPR
)
7886 /* Well, gcj generates slightly different tree nodes when compiling
7887 to native or bytecodes. It's the case for function calls. */
7889 if
(flag_emit_class_files
7890 && TREE_CODE
(node
) == CALL_EXPR
7891 && OUTER_FIELD_ACCESS_IDENTIFIER_P
(DECL_NAME
(TREE_OPERAND
(node
, 0))))
7893 else if
(!flag_emit_class_files
)
7895 node
= TREE_OPERAND
(node
, 0);
7897 if
(node
&& TREE_OPERAND
(node
, 0)
7898 && TREE_CODE
(TREE_OPERAND
(node
, 0)) == ADDR_EXPR
)
7900 node
= TREE_OPERAND
(node
, 0);
7901 if
(TREE_OPERAND
(node
, 0)
7902 && TREE_CODE
(TREE_OPERAND
(node
, 0)) == FUNCTION_DECL
7903 && (OUTER_FIELD_ACCESS_IDENTIFIER_P
7904 (DECL_NAME
(TREE_OPERAND
(node
, 0)))))
7909 if
(identified
&& name
&& arg_type
&& arg
)
7911 tree argument
= TREE_OPERAND
(node
, 1);
7912 *name
= DECL_NAME
(TREE_OPERAND
(node
, 0));
7913 *arg_type
= TREE_TYPE
(TREE_TYPE
(TREE_VALUE
(argument
)));
7914 *arg
= TREE_VALUE
(argument
);
7919 /* Detect in NODE an outer field read access from an inner class and
7920 transform it into a write with RHS as an argument. This function is
7921 called from the java_complete_lhs when an assignment to a LHS can
7925 outer_field_access_fix
(wfl
, node
, rhs
)
7926 tree wfl
, node
, rhs
;
7928 tree name
, arg_type
, arg
;
7930 if
(outer_field_expanded_access_p
(node
, &name
, &arg_type
, &arg
))
7932 /* At any rate, check whether we're trying to assign a value to
7934 tree accessed
= (JDECL_P
(node
) ? node
:
7935 (TREE_CODE
(node
) == COMPONENT_REF ?
7936 TREE_OPERAND
(node
, 1) : node
));
7937 if
(check_final_assignment
(accessed
, wfl
))
7938 return error_mark_node
;
7940 node
= build_outer_field_access_expr
(EXPR_WFL_LINECOL
(wfl
),
7941 arg_type
, name
, arg
, rhs
);
7942 return java_complete_tree
(node
);
7947 /* Construct the expression that calls an access method:
7948 <type>.access$<n>(<arg1> [, <arg2>]);
7950 ARG2 can be NULL and will be omitted in that case. It will denote a
7954 build_outer_field_access_expr
(lc
, type
, access_method_name
, arg1
, arg2
)
7956 tree type
, access_method_name
, arg1
, arg2
;
7958 tree args
, cn
, access
;
7960 args
= arg1 ? arg1
:
7961 build_wfl_node
(build_current_thisn
(current_class
));
7962 args
= build_tree_list
(NULL_TREE
, args
);
7965 args
= tree_cons
(NULL_TREE
, arg2
, args
);
7967 access
= build_method_invocation
(build_wfl_node
(access_method_name
), args
);
7968 cn
= build_wfl_node
(DECL_NAME
(TYPE_NAME
(type
)));
7969 return make_qualified_primary
(cn
, access
, lc
);
7973 build_new_access_id
()
7975 static int access_n_counter
= 1;
7978 sprintf
(buffer
, "access$%d", access_n_counter
++);
7979 return get_identifier
(buffer
);
7982 /* Create the static access functions for the outer field DECL. We define a
7984 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$) {
7988 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$,
7989 TREE_TYPE (<field>) value$) {
7990 return inst$.field = value$;
7992 We should have a usage flags on the DECL so we can lazily turn the ones
7993 we're using for code generation. FIXME.
7997 build_outer_field_access_methods
(decl
)
8000 tree id
, args
, stmt
, mdecl
;
8002 if
(FIELD_INNER_ACCESS_P
(decl
))
8003 return FIELD_INNER_ACCESS
(decl
);
8005 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(decl
);
8007 /* Create the identifier and a function named after it. */
8008 id
= build_new_access_id
();
8010 /* The identifier is marked as bearing the name of a generated write
8011 access function for outer field accessed from inner classes. */
8012 OUTER_FIELD_ACCESS_IDENTIFIER_P
(id
) = 1;
8014 /* Create the read access */
8015 args
= build_tree_list
(inst_id
, build_pointer_type
(DECL_CONTEXT
(decl
)));
8016 TREE_CHAIN
(args
) = end_params_node
;
8017 stmt
= make_qualified_primary
(build_wfl_node
(inst_id
),
8018 build_wfl_node
(DECL_NAME
(decl
)), 0);
8019 stmt
= build_return
(0, stmt
);
8020 mdecl
= build_outer_field_access_method
(DECL_CONTEXT
(decl
),
8021 TREE_TYPE
(decl
), id
, args
, stmt
);
8022 DECL_FUNCTION_ACCESS_DECL
(mdecl
) = decl
;
8024 /* Create the write access method. No write access for final variable */
8025 if
(!FIELD_FINAL
(decl
))
8027 args
= build_tree_list
(inst_id
,
8028 build_pointer_type
(DECL_CONTEXT
(decl
)));
8029 TREE_CHAIN
(args
) = build_tree_list
(wpv_id
, TREE_TYPE
(decl
));
8030 TREE_CHAIN
(TREE_CHAIN
(args
)) = end_params_node
;
8031 stmt
= make_qualified_primary
(build_wfl_node
(inst_id
),
8032 build_wfl_node
(DECL_NAME
(decl
)), 0);
8033 stmt
= build_return
(0, build_assignment
(ASSIGN_TK
, 0, stmt
,
8034 build_wfl_node
(wpv_id
)));
8035 mdecl
= build_outer_field_access_method
(DECL_CONTEXT
(decl
),
8036 TREE_TYPE
(decl
), id
,
8039 DECL_FUNCTION_ACCESS_DECL
(mdecl
) = decl
;
8041 /* Return the access name */
8042 return FIELD_INNER_ACCESS
(decl
) = id
;
8045 /* Build an field access method NAME. */
8048 build_outer_field_access_method
(class
, type
, name
, args
, body
)
8049 tree class
, type
, name
, args
, body
;
8051 tree saved_current_function_decl
, mdecl
;
8053 /* Create the method */
8054 mdecl
= create_artificial_method
(class
, ACC_STATIC
, type
, name
, args
);
8055 fix_method_argument_names
(args
, mdecl
);
8056 layout_class_method
(class
, NULL_TREE
, mdecl
, NULL_TREE
);
8058 /* Attach the method body. */
8059 saved_current_function_decl
= current_function_decl
;
8060 start_artificial_method_body
(mdecl
);
8061 java_method_add_stmt
(mdecl
, body
);
8062 end_artificial_method_body
(mdecl
);
8063 current_function_decl
= saved_current_function_decl
;
8069 /* This section deals with building access function necessary for
8070 certain kinds of method invocation from inner classes. */
8073 build_outer_method_access_method
(decl
)
8076 tree saved_current_function_decl
, mdecl
;
8077 tree args
= NULL_TREE
, call_args
= NULL_TREE
;
8078 tree carg
, id
, body
, class
;
8080 int parm_id_count
= 0;
8082 /* Test this abort with an access to a private field */
8083 if
(!strcmp
(IDENTIFIER_POINTER
(DECL_NAME
(decl
)), "access$"))
8086 /* Check the cache first */
8087 if
(DECL_FUNCTION_INNER_ACCESS
(decl
))
8088 return DECL_FUNCTION_INNER_ACCESS
(decl
);
8090 class
= DECL_CONTEXT
(decl
);
8092 /* Obtain an access identifier and mark it */
8093 id
= build_new_access_id
();
8094 OUTER_FIELD_ACCESS_IDENTIFIER_P
(id
) = 1;
8096 carg
= TYPE_ARG_TYPES
(TREE_TYPE
(decl
));
8097 /* Create the arguments, as much as the original */
8098 for
(; carg
&& carg
!= end_params_node
;
8099 carg
= TREE_CHAIN
(carg
))
8101 sprintf
(buffer
, "write_parm_value$%d", parm_id_count
++);
8102 args
= chainon
(args
, build_tree_list
(get_identifier
(buffer
),
8103 TREE_VALUE
(carg
)));
8105 args
= chainon
(args
, end_params_node
);
8107 /* Create the method */
8108 mdecl
= create_artificial_method
(class
, ACC_STATIC
,
8109 TREE_TYPE
(TREE_TYPE
(decl
)), id
, args
);
8110 layout_class_method
(class
, NULL_TREE
, mdecl
, NULL_TREE
);
8111 /* There is a potential bug here. We should be able to use
8112 fix_method_argument_names, but then arg names get mixed up and
8113 eventually a constructor will have its this$0 altered and the
8114 outer context won't be assignment properly. The test case is
8116 TYPE_ARG_TYPES
(TREE_TYPE
(mdecl
)) = args
;
8118 /* Attach the method body. */
8119 saved_current_function_decl
= current_function_decl
;
8120 start_artificial_method_body
(mdecl
);
8122 /* The actual method invocation uses the same args. When invoking a
8123 static methods that way, we don't want to skip the first
8126 if
(!METHOD_STATIC
(decl
))
8127 carg
= TREE_CHAIN
(carg
);
8128 for
(; carg
&& carg
!= end_params_node
; carg
= TREE_CHAIN
(carg
))
8129 call_args
= tree_cons
(NULL_TREE
, build_wfl_node
(TREE_PURPOSE
(carg
)),
8132 body
= build_method_invocation
(build_wfl_node
(DECL_NAME
(decl
)),
8134 if
(!METHOD_STATIC
(decl
))
8135 body
= make_qualified_primary
(build_wfl_node
(TREE_PURPOSE
(args
)),
8137 if
(TREE_TYPE
(TREE_TYPE
(decl
)) != void_type_node
)
8138 body
= build_return
(0, body
);
8139 java_method_add_stmt
(mdecl
,body
);
8140 end_artificial_method_body
(mdecl
);
8141 current_function_decl
= saved_current_function_decl
;
8143 /* Back tag the access function so it know what it accesses */
8144 DECL_FUNCTION_ACCESS_DECL
(decl
) = mdecl
;
8146 /* Tag the current method so it knows it has an access generated */
8147 return DECL_FUNCTION_INNER_ACCESS
(decl
) = mdecl
;
8151 /* This section of the code deals with building expressions to access
8152 the enclosing instance of an inner class. The enclosing instance is
8153 kept in a generated field called this$<n>, with <n> being the
8154 inner class nesting level (starting from 0.) */
8156 /* Build an access to a given this$<n>, always chaining access call to
8157 others. Access methods to this$<n> are build on the fly if
8158 necessary. This CAN'T be used to solely access this$<n-1> from
8159 this$<n> (which alway yield to special cases and optimization, see
8160 for example build_outer_field_access). */
8163 build_access_to_thisn
(from
, to
, lc
)
8167 tree access
= NULL_TREE
;
8173 access
= build_current_thisn
(from
);
8174 access
= build_wfl_node
(access
);
8178 tree access0_wfl
, cn
;
8180 maybe_build_thisn_access_method
(from
);
8181 access0_wfl
= build_wfl_node
(access0_identifier_node
);
8182 cn
= build_wfl_node
(DECL_NAME
(TYPE_NAME
(from
)));
8183 EXPR_WFL_LINECOL
(access0_wfl
) = lc
;
8184 access
= build_tree_list
(NULL_TREE
, access
);
8185 access
= build_method_invocation
(access0_wfl
, access
);
8186 access
= make_qualified_primary
(cn
, access
, lc
);
8189 /* if FROM isn't an inter class, that's fine, we've done
8190 enough. What we're looking for can be accessed from there. */
8191 from
= DECL_CONTEXT
(TYPE_NAME
(from
));
8194 from
= TREE_TYPE
(from
);
8199 /* Build an access function to the this$<n> local to TYPE. NULL_TREE
8200 is returned if nothing needs to be generated. Otherwise, the method
8201 generated and a method decl is returned.
8203 NOTE: These generated methods should be declared in a class file
8204 attribute so that they can't be referred to directly. */
8207 maybe_build_thisn_access_method
(type
)
8210 tree mdecl
, args
, stmt
, rtype
;
8211 tree saved_current_function_decl
;
8213 /* If TYPE is a top-level class, no access method is required.
8214 If there already is such an access method, bail out. */
8215 if
(CLASS_ACCESS0_GENERATED_P
(type
) ||
!PURE_INNER_CLASS_TYPE_P
(type
))
8218 /* We generate the method. The method looks like:
8219 static <outer_of_type> access$0 (<type> inst$) { return inst$.this$<n>; }
8221 args
= build_tree_list
(inst_id
, build_pointer_type
(type
));
8222 TREE_CHAIN
(args
) = end_params_node
;
8223 rtype
= build_pointer_type
(TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type
))));
8224 mdecl
= create_artificial_method
(type
, ACC_STATIC
, rtype
,
8225 access0_identifier_node
, args
);
8226 fix_method_argument_names
(args
, mdecl
);
8227 layout_class_method
(type
, NULL_TREE
, mdecl
, NULL_TREE
);
8228 stmt
= build_current_thisn
(type
);
8229 stmt
= make_qualified_primary
(build_wfl_node
(inst_id
),
8230 build_wfl_node
(stmt
), 0);
8231 stmt
= build_return
(0, stmt
);
8233 saved_current_function_decl
= current_function_decl
;
8234 start_artificial_method_body
(mdecl
);
8235 java_method_add_stmt
(mdecl
, stmt
);
8236 end_artificial_method_body
(mdecl
);
8237 current_function_decl
= saved_current_function_decl
;
8239 CLASS_ACCESS0_GENERATED_P
(type
) = 1;
8244 /* Craft an correctly numbered `this$<n>'string. this$0 is used for
8245 the first level of innerclassing. this$1 for the next one, etc...
8246 This function can be invoked with TYPE to NULL, available and then
8247 has to count the parser context. */
8250 build_current_thisn
(type
)
8253 static int saved_i
= -1;
8254 static tree saved_thisn
= NULL_TREE
;
8255 static tree saved_type
= NULL_TREE
;
8256 static int saved_type_i
= 0;
8257 static int initialized_p
;
8262 /* Register SAVED_THISN and SAVED_TYPE with the garbage collector. */
8265 ggc_add_tree_root
(&saved_thisn
, 1);
8266 ggc_add_tree_root
(&saved_type
, 1);
8272 if
(type
== saved_type
)
8276 for
(i
= -1, decl
= DECL_CONTEXT
(TYPE_NAME
(type
));
8277 decl
; decl
= DECL_CONTEXT
(decl
), i
++)
8285 i
= list_length
(GET_CPC_LIST
())-2;
8290 sprintf
(buffer
, "this$%d", i
);
8292 saved_thisn
= get_identifier
(buffer
);
8296 /* Return the assignement to the hidden enclosing context `this$<n>'
8297 by the second incoming parameter to the innerclass constructor. The
8298 form used is `this.this$<n> = this$<n>;'. */
8301 build_thisn_assign
()
8303 if
(current_class
&& PURE_INNER_CLASS_TYPE_P
(current_class
))
8305 tree thisn
= build_current_thisn
(current_class
);
8306 tree lhs
= make_qualified_primary
(build_wfl_node
(this_identifier_node
),
8307 build_wfl_node
(thisn
), 0);
8308 tree rhs
= build_wfl_node
(thisn
);
8309 EXPR_WFL_SET_LINECOL
(lhs
, lineno
, 0);
8310 return build_assignment
(ASSIGN_TK
, EXPR_WFL_LINECOL
(lhs
), lhs
, rhs
);
8316 /* Building the synthetic `class$' used to implement the `.class' 1.1
8317 extension for non primitive types. This method looks like:
8319 static Class class$(String type) throws NoClassDefFoundError
8321 try {return (java.lang.Class.forName (String));}
8322 catch (ClassNotFoundException e) {
8323 throw new NoClassDefFoundError(e.getMessage());}
8327 build_dot_class_method
(class
)
8330 #define BWF(S) build_wfl_node (get_identifier ((S)))
8331 #define MQN(X,Y) make_qualified_name ((X), (Y), 0)
8332 tree args
, tmp
, saved_current_function_decl
, mdecl
;
8333 tree stmt
, throw_stmt
, catch
, catch_block
, try_block
;
8334 tree catch_clause_param
;
8335 tree class_not_found_exception
, no_class_def_found_error
;
8337 static tree get_message_wfl
, type_parm_wfl
;
8339 if
(!get_message_wfl
)
8341 get_message_wfl
= build_wfl_node
(get_identifier
("getMessage"));
8342 type_parm_wfl
= build_wfl_node
(get_identifier
("type$"));
8343 ggc_add_tree_root
(&get_message_wfl
, 1);
8344 ggc_add_tree_root
(&type_parm_wfl
, 1);
8347 /* Build the arguments */
8348 args
= build_tree_list
(get_identifier
("type$"),
8349 build_pointer_type
(string_type_node
));
8350 TREE_CHAIN
(args
) = end_params_node
;
8352 /* Build the qualified name java.lang.Class.forName */
8353 tmp
= MQN
(MQN
(MQN
(BWF
("java"),
8354 BWF
("lang")), BWF
("Class")), BWF
("forName"));
8356 /* For things we have to catch and throw */
8357 class_not_found_exception
=
8358 lookup_class
(get_identifier
("java.lang.ClassNotFoundException"));
8359 no_class_def_found_error
=
8360 lookup_class
(get_identifier
("java.lang.NoClassDefFoundError"));
8361 load_class
(class_not_found_exception
, 1);
8362 load_class
(no_class_def_found_error
, 1);
8364 /* Create the "class$" function */
8365 mdecl
= create_artificial_method
(class
, ACC_STATIC
,
8366 build_pointer_type
(class_type_node
),
8367 classdollar_identifier_node
, args
);
8368 DECL_FUNCTION_THROWS
(mdecl
) = build_tree_list
(NULL_TREE
,
8369 no_class_def_found_error
);
8371 /* We start by building the try block. We need to build:
8372 return (java.lang.Class.forName (type)); */
8373 stmt
= build_method_invocation
(tmp
,
8374 build_tree_list
(NULL_TREE
, type_parm_wfl
));
8375 stmt
= build_return
(0, stmt
);
8376 /* Put it in a block. That's the try block */
8377 try_block
= build_expr_block
(stmt
, NULL_TREE
);
8379 /* Now onto the catch block. We start by building the expression
8380 throwing a new exception:
8381 throw new NoClassDefFoundError (_.getMessage); */
8382 throw_stmt
= make_qualified_name
(build_wfl_node
(wpv_id
),
8383 get_message_wfl
, 0);
8384 throw_stmt
= build_method_invocation
(throw_stmt
, NULL_TREE
);
8386 /* Build new NoClassDefFoundError (_.getMessage) */
8387 throw_stmt
= build_new_invocation
8388 (build_wfl_node
(get_identifier
("NoClassDefFoundError")),
8389 build_tree_list
(build_pointer_type
(string_type_node
), throw_stmt
));
8391 /* Build the throw, (it's too early to use BUILD_THROW) */
8392 throw_stmt
= build1
(THROW_EXPR
, NULL_TREE
, throw_stmt
);
8394 /* Build the catch block to encapsulate all this. We begin by
8395 building an decl for the catch clause parameter and link it to
8396 newly created block, the catch block. */
8397 catch_clause_param
=
8398 build_decl
(VAR_DECL
, wpv_id
,
8399 build_pointer_type
(class_not_found_exception
));
8400 catch_block
= build_expr_block
(NULL_TREE
, catch_clause_param
);
8402 /* We initialize the variable with the exception handler. */
8403 catch
= build
(MODIFY_EXPR
, NULL_TREE
, catch_clause_param
,
8404 build_exception_object_ref
(ptr_type_node
));
8405 add_stmt_to_block
(catch_block
, NULL_TREE
, catch
);
8407 /* We add the statement throwing the new exception */
8408 add_stmt_to_block
(catch_block
, NULL_TREE
, throw_stmt
);
8410 /* Build a catch expression for all this */
8411 catch_block
= build1
(CATCH_EXPR
, NULL_TREE
, catch_block
);
8413 /* Build the try/catch sequence */
8414 stmt
= build_try_statement
(0, try_block
, catch_block
);
8416 fix_method_argument_names
(args
, mdecl
);
8417 layout_class_method
(class
, NULL_TREE
, mdecl
, NULL_TREE
);
8418 saved_current_function_decl
= current_function_decl
;
8419 start_artificial_method_body
(mdecl
);
8420 java_method_add_stmt
(mdecl
, stmt
);
8421 end_artificial_method_body
(mdecl
);
8422 current_function_decl
= saved_current_function_decl
;
8423 TYPE_DOT_CLASS
(class
) = mdecl
;
8429 build_dot_class_method_invocation
(type
)
8434 if
(TYPE_ARRAY_P
(type
))
8435 sig_id
= build_java_signature
(type
);
8437 sig_id
= DECL_NAME
(TYPE_NAME
(type
));
8439 s
= build_string
(IDENTIFIER_LENGTH
(sig_id
),
8440 IDENTIFIER_POINTER
(sig_id
));
8441 return build_method_invocation
(build_wfl_node
(classdollar_identifier_node
),
8442 build_tree_list
(NULL_TREE
, s
));
8445 /* This section of the code deals with constructor. */
8447 /* Craft a body for default constructor. Patch existing constructor
8448 bodies with call to super() and field initialization statements if
8452 fix_constructors
(mdecl
)
8455 tree body
= DECL_FUNCTION_BODY
(mdecl
);
8456 tree thisn_assign
, compound
= NULL_TREE
;
8457 tree class_type
= DECL_CONTEXT
(mdecl
);
8461 /* It is an error for the compiler to generate a default
8462 constructor if the superclass doesn't have a constructor that
8463 takes no argument, or the same args for an anonymous class */
8464 if
(verify_constructor_super
(mdecl
))
8466 tree sclass_decl
= TYPE_NAME
(CLASSTYPE_SUPER
(class_type
));
8467 tree save
= DECL_NAME
(mdecl
);
8468 const char *n
= IDENTIFIER_POINTER
(DECL_NAME
(sclass_decl
));
8469 DECL_NAME
(mdecl
) = DECL_NAME
(sclass_decl
);
8471 (lookup_cl
(TYPE_NAME
(class_type
)),
8472 "No constructor matching `%s' found in class `%s'",
8473 lang_printable_name
(mdecl
, 0), n
);
8474 DECL_NAME
(mdecl
) = save
;
8477 /* The constructor body must be crafted by hand. It's the
8478 constructor we defined when we realize we didn't have the
8479 CLASSNAME() constructor */
8480 start_artificial_method_body
(mdecl
);
8482 /* Insert an assignment to the this$<n> hidden field, if
8484 if
((thisn_assign
= build_thisn_assign
()))
8485 java_method_add_stmt
(mdecl
, thisn_assign
);
8487 /* We don't generate a super constructor invocation if we're
8488 compiling java.lang.Object. build_super_invocation takes care
8490 compound
= java_method_add_stmt
(mdecl
, build_super_invocation
(mdecl
));
8492 /* Insert the instance initializer block right here, after the
8493 super invocation. */
8494 add_instance_initializer
(mdecl
);
8496 end_artificial_method_body
(mdecl
);
8498 /* Search for an explicit constructor invocation */
8502 tree main_block
= BLOCK_EXPR_BODY
(body
);
8505 switch
(TREE_CODE
(body
))
8508 found
= CALL_EXPLICIT_CONSTRUCTOR_P
(body
);
8512 case EXPR_WITH_FILE_LOCATION
:
8513 body
= TREE_OPERAND
(body
, 0);
8516 body
= BLOCK_EXPR_BODY
(body
);
8522 /* The constructor is missing an invocation of super() */
8524 compound
= add_stmt_to_compound
(compound
, NULL_TREE
,
8525 build_super_invocation
(mdecl
));
8527 /* Generate the assignment to this$<n>, if necessary */
8528 if
((thisn_assign
= build_thisn_assign
()))
8529 compound
= add_stmt_to_compound
(compound
, NULL_TREE
, thisn_assign
);
8531 /* Insert the instance initializer block right here, after the
8532 super invocation. */
8533 add_instance_initializer
(mdecl
);
8535 /* Fix the constructor main block if we're adding extra stmts */
8538 compound
= add_stmt_to_compound
(compound
, NULL_TREE
,
8539 BLOCK_EXPR_BODY
(main_block
));
8540 BLOCK_EXPR_BODY
(main_block
) = compound
;
8545 /* Browse constructors in the super class, searching for a constructor
8546 that doesn't take any argument. Return 0 if one is found, 1
8547 otherwise. If the current class is an anonymous inner class, look
8548 for something that has the same signature. */
8551 verify_constructor_super
(mdecl
)
8554 tree class
= CLASSTYPE_SUPER
(current_class
);
8555 int super_inner
= PURE_INNER_CLASS_TYPE_P
(class
);
8561 if
(ANONYMOUS_CLASS_P
(current_class
))
8563 tree mdecl_arg_type
;
8564 SKIP_THIS_AND_ARTIFICIAL_PARMS
(mdecl_arg_type
, mdecl
);
8565 for
(sdecl
= TYPE_METHODS
(class
); sdecl
; sdecl
= TREE_CHAIN
(sdecl
))
8566 if
(DECL_CONSTRUCTOR_P
(sdecl
))
8569 tree arg_type
= TREE_CHAIN
(TYPE_ARG_TYPES
(TREE_TYPE
(sdecl
)));
8571 arg_type
= TREE_CHAIN
(arg_type
);
8572 for
(m_arg_type
= mdecl_arg_type
;
8573 (arg_type
!= end_params_node
8574 && m_arg_type
!= end_params_node
);
8575 arg_type
= TREE_CHAIN
(arg_type
),
8576 m_arg_type
= TREE_CHAIN
(m_arg_type
))
8577 if
(TREE_VALUE
(arg_type
) != TREE_VALUE
(m_arg_type
))
8580 if
(arg_type
== end_params_node
&& m_arg_type
== end_params_node
)
8586 for
(sdecl
= TYPE_METHODS
(class
); sdecl
; sdecl
= TREE_CHAIN
(sdecl
))
8588 tree arg
= TREE_CHAIN
(TYPE_ARG_TYPES
(TREE_TYPE
(sdecl
)));
8590 arg
= TREE_CHAIN
(arg
);
8591 if
(DECL_CONSTRUCTOR_P
(sdecl
) && arg
== end_params_node
)
8598 /* Generate code for all context remembered for code generation. */
8601 java_expand_classes
()
8603 int save_error_count
= 0;
8604 static struct parser_ctxt
*saved_ctxp
= NULL
;
8606 java_parse_abort_on_error
();
8607 if
(!(ctxp
= ctxp_for_generation
))
8609 java_layout_classes
();
8610 java_parse_abort_on_error
();
8612 saved_ctxp
= ctxp_for_generation
;
8613 for
(; ctxp_for_generation
; ctxp_for_generation
= ctxp_for_generation
->next
)
8615 ctxp
= ctxp_for_generation
;
8616 input_filename
= ctxp
->filename
;
8617 lang_init_source
(2); /* Error msgs have method prototypes */
8618 java_complete_expand_classes
(); /* Complete and expand classes */
8619 java_parse_abort_on_error
();
8621 input_filename
= main_input_filename
;
8623 /* Find anonymous classes and expand their constructor, now they
8625 for
(ctxp_for_generation
= saved_ctxp
;
8626 ctxp_for_generation
; ctxp_for_generation
= ctxp_for_generation
->next
)
8629 ctxp
= ctxp_for_generation
;
8630 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
8632 current_class
= TREE_TYPE
(current
);
8633 if
(ANONYMOUS_CLASS_P
(current_class
))
8636 for
(d
= TYPE_METHODS
(current_class
); d
; d
= TREE_CHAIN
(d
))
8638 if
(DECL_CONSTRUCTOR_P
(d
))
8640 restore_line_number_status
(1);
8641 java_complete_expand_method
(d
);
8642 restore_line_number_status
(0);
8643 break
; /* We now there are no other ones */
8650 /* If we've found error at that stage, don't try to generate
8651 anything, unless we're emitting xrefs or checking the syntax only
8652 (but not using -fsyntax-only for the purpose of generating
8654 if
(java_error_count
&& !flag_emit_xref
8655 && (!flag_syntax_only
&& !flag_emit_class_files
))
8658 /* Now things are stable, go for generation of the class data. */
8659 for
(ctxp_for_generation
= saved_ctxp
;
8660 ctxp_for_generation
; ctxp_for_generation
= ctxp_for_generation
->next
)
8663 ctxp
= ctxp_for_generation
;
8664 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
8666 current_class
= TREE_TYPE
(current
);
8667 outgoing_cpool
= TYPE_CPOOL
(current_class
);
8668 if
(flag_emit_class_files
)
8669 write_classfile
(current_class
);
8671 expand_xref
(current_class
);
8672 else if
(! flag_syntax_only
)
8678 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
8679 a tree list node containing RIGHT. Fore coming RIGHTs will be
8680 chained to this hook. LOCATION contains the location of the
8681 separating `.' operator. */
8684 make_qualified_primary
(primary
, right
, location
)
8685 tree primary
, right
;
8690 if
(TREE_CODE
(primary
) != EXPR_WITH_FILE_LOCATION
)
8691 wfl
= build_wfl_wrap
(primary
, location
);
8695 /* If wfl wasn't qualified, we build a first anchor */
8696 if
(!EXPR_WFL_QUALIFICATION
(wfl
))
8697 EXPR_WFL_QUALIFICATION
(wfl
) = build_tree_list
(wfl
, NULL_TREE
);
8700 /* And chain them */
8701 EXPR_WFL_LINECOL
(right
) = location
;
8702 chainon
(EXPR_WFL_QUALIFICATION
(wfl
), build_tree_list
(right
, NULL_TREE
));
8703 PRIMARY_P
(wfl
) = 1;
8707 /* Simple merge of two name separated by a `.' */
8710 merge_qualified_name
(left
, right
)
8714 if
(!left
&& !right
)
8723 obstack_grow
(&temporary_obstack
, IDENTIFIER_POINTER
(left
),
8724 IDENTIFIER_LENGTH
(left
));
8725 obstack_1grow
(&temporary_obstack
, '.');
8726 obstack_grow0
(&temporary_obstack
, IDENTIFIER_POINTER
(right
),
8727 IDENTIFIER_LENGTH
(right
));
8728 node
= get_identifier
(obstack_base
(&temporary_obstack
));
8729 obstack_free
(&temporary_obstack
, obstack_base
(&temporary_obstack
));
8730 QUALIFIED_P
(node
) = 1;
8734 /* Merge the two parts of a qualified name into LEFT. Set the
8735 location information of the resulting node to LOCATION, usually
8736 inherited from the location information of the `.' operator. */
8739 make_qualified_name
(left
, right
, location
)
8743 #ifdef USE_COMPONENT_REF
8744 tree node
= build
(COMPONENT_REF
, NULL_TREE
, left
, right
);
8745 EXPR_WFL_LINECOL
(node
) = location
;
8748 tree left_id
= EXPR_WFL_NODE
(left
);
8749 tree right_id
= EXPR_WFL_NODE
(right
);
8752 merge
= merge_qualified_name
(left_id
, right_id
);
8754 /* Left wasn't qualified and is now qualified */
8755 if
(!QUALIFIED_P
(left_id
))
8757 tree wfl
= build_expr_wfl
(left_id
, ctxp
->filename
, 0, 0);
8758 EXPR_WFL_LINECOL
(wfl
) = EXPR_WFL_LINECOL
(left
);
8759 EXPR_WFL_QUALIFICATION
(left
) = build_tree_list
(wfl
, NULL_TREE
);
8762 wfl
= build_expr_wfl
(right_id
, ctxp
->filename
, 0, 0);
8763 EXPR_WFL_LINECOL
(wfl
) = location
;
8764 chainon
(EXPR_WFL_QUALIFICATION
(left
), build_tree_list
(wfl
, NULL_TREE
));
8766 EXPR_WFL_NODE
(left
) = merge
;
8771 /* Extract the last identifier component of the qualified in WFL. The
8772 last identifier is removed from the linked list */
8775 cut_identifier_in_qualified
(wfl
)
8779 tree previous
= NULL_TREE
;
8780 for
(q
= EXPR_WFL_QUALIFICATION
(wfl
); ; previous
= q
, q
= TREE_CHAIN
(q
))
8781 if
(!TREE_CHAIN
(q
))
8784 /* Operating on a non qualified qualified WFL. */
8787 TREE_CHAIN
(previous
) = NULL_TREE
;
8788 return TREE_PURPOSE
(q
);
8792 /* Resolve the expression name NAME. Return its decl. */
8795 resolve_expression_name
(id
, orig
)
8799 tree name
= EXPR_WFL_NODE
(id
);
8802 /* 6.5.5.1: Simple expression names */
8803 if
(!PRIMARY_P
(id
) && !QUALIFIED_P
(name
))
8805 /* 15.13.1: NAME can appear within the scope of a local variable
8807 if
((decl
= IDENTIFIER_LOCAL_VALUE
(name
)))
8810 /* 15.13.1: NAME can appear within a class declaration */
8813 decl
= lookup_field_wrapper
(current_class
, name
);
8816 tree access
= NULL_TREE
;
8817 int fs
= FIELD_STATIC
(decl
);
8819 /* If we're accessing an outer scope local alias, make
8820 sure we change the name of the field we're going to
8822 if
(FIELD_LOCAL_ALIAS_USED
(decl
))
8823 name
= DECL_NAME
(decl
);
8825 /* Instance variable (8.3.1.1) can't appear within
8826 static method, static initializer or initializer for
8827 a static variable. */
8828 if
(!fs
&& METHOD_STATIC
(current_function_decl
))
8830 static_ref_err
(id
, name
, current_class
);
8831 return error_mark_node
;
8833 /* Instance variables can't appear as an argument of
8834 an explicit constructor invocation */
8835 if
(!fs
&& ctxp
->explicit_constructor_p
8836 && !enclosing_context_p
(DECL_CONTEXT
(decl
), current_class
))
8839 (id
, "Can't reference `%s' before the superclass constructor has been called", IDENTIFIER_POINTER
(name
));
8840 return error_mark_node
;
8843 /* If we're processing an inner class and we're trying
8844 to access a field belonging to an outer class, build
8845 the access to the field */
8846 if
(!fs
&& outer_field_access_p
(current_class
, decl
))
8848 if
(CLASS_STATIC
(TYPE_NAME
(current_class
)))
8850 static_ref_err
(id
, DECL_NAME
(decl
), current_class
);
8851 return error_mark_node
;
8853 return build_outer_field_access
(id
, decl
);
8856 /* Otherwise build what it takes to access the field */
8857 access
= build_field_ref
((fs ? NULL_TREE
: current_this
),
8858 DECL_CONTEXT
(decl
), name
);
8860 access
= maybe_build_class_init_for_field
(decl
, access
);
8861 /* We may be asked to save the real field access node */
8864 /* And we return what we got */
8867 /* Fall down to error report on undefined variable */
8870 /* 6.5.5.2 Qualified Expression Names */
8875 qualify_ambiguous_name
(id
);
8876 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
8877 /* 15.10.2: Accessing Superclass Members using super */
8878 return resolve_field_access
(id
, orig
, NULL
);
8881 /* We've got an error here */
8882 parse_error_context
(id
, "Undefined variable `%s'",
8883 IDENTIFIER_POINTER
(name
));
8885 return error_mark_node
;
8889 static_ref_err
(wfl
, field_id
, class_type
)
8890 tree wfl
, field_id
, class_type
;
8894 "Can't make a static reference to nonstatic variable `%s' in class `%s'",
8895 IDENTIFIER_POINTER
(field_id
),
8896 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(class_type
))));
8899 /* 15.10.1 Field Acess Using a Primary and/or Expression Name.
8900 We return something suitable to generate the field access. We also
8901 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
8902 recipient's address can be null. */
8905 resolve_field_access
(qual_wfl
, field_decl
, field_type
)
8907 tree
*field_decl
, *field_type
;
8911 tree decl
, where_found
, type_found
;
8913 if
(resolve_qualified_expression_name
(qual_wfl
, &decl
,
8914 &where_found
, &type_found
))
8915 return error_mark_node
;
8917 /* Resolve the LENGTH field of an array here */
8918 if
(DECL_P
(decl
) && DECL_NAME
(decl
) == length_identifier_node
8919 && type_found
&& TYPE_ARRAY_P
(type_found
)
8920 && ! flag_emit_class_files
&& ! flag_emit_xref
)
8922 tree length
= build_java_array_length_access
(where_found
);
8925 /* In case we're dealing with a static array, we need to
8926 initialize its class before the array length can be fetched.
8927 It's also a good time to create a DECL_RTL for the field if
8928 none already exists, otherwise if the field was declared in a
8929 class found in an external file and hasn't been (and won't
8930 be) accessed for its value, none will be created. */
8931 if
(TREE_CODE
(where_found
) == VAR_DECL
&& FIELD_STATIC
(where_found
))
8933 build_static_field_ref
(where_found
);
8934 field_ref
= build_class_init
(DECL_CONTEXT
(where_found
), field_ref
);
8937 /* We might have been trying to resolve field.method(). In which
8938 case, the resolution is over and decl is the answer */
8939 else if
(JDECL_P
(decl
) && IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(decl
)) == decl
)
8941 else if
(JDECL_P
(decl
))
8944 type_found
= DECL_CONTEXT
(decl
);
8945 is_static
= FIELD_STATIC
(decl
);
8946 field_ref
= build_field_ref
((is_static
&& !flag_emit_xref?
8947 NULL_TREE
: where_found
),
8948 type_found
, DECL_NAME
(decl
));
8949 if
(field_ref
== error_mark_node
)
8950 return error_mark_node
;
8952 field_ref
= maybe_build_class_init_for_field
(decl
, field_ref
);
8960 *field_type
= (QUAL_DECL_TYPE
(decl
) ?
8961 QUAL_DECL_TYPE
(decl
) : TREE_TYPE
(decl
));
8965 /* If NODE is an access to f static field, strip out the class
8966 initialization part and return the field decl, otherwise, return
8970 strip_out_static_field_access_decl
(node
)
8973 if
(TREE_CODE
(node
) == COMPOUND_EXPR
)
8975 tree op1
= TREE_OPERAND
(node
, 1);
8976 if
(TREE_CODE
(op1
) == COMPOUND_EXPR
)
8978 tree call
= TREE_OPERAND
(op1
, 0);
8979 if
(TREE_CODE
(call
) == CALL_EXPR
8980 && TREE_CODE
(TREE_OPERAND
(call
, 0)) == ADDR_EXPR
8981 && TREE_OPERAND
(TREE_OPERAND
(call
, 0), 0)
8982 == soft_initclass_node
)
8983 return TREE_OPERAND
(op1
, 1);
8985 else if
(JDECL_P
(op1
))
8991 /* 6.5.5.2: Qualified Expression Names */
8994 resolve_qualified_expression_name
(wfl
, found_decl
, where_found
, type_found
)
8996 tree
*found_decl
, *type_found
, *where_found
;
8998 int from_type
= 0; /* Field search initiated from a type */
8999 int from_super
= 0, from_cast
= 0, from_qualified_this
= 0;
9000 int previous_call_static
= 0;
9002 tree decl
= NULL_TREE
, type
= NULL_TREE
, q
;
9003 /* For certain for of inner class instantiation */
9004 tree saved_current
, saved_this
;
9005 #define RESTORE_THIS_AND_CURRENT_CLASS \
9006 { current_class
= saved_current
; current_this
= saved_this
;}
9008 *type_found
= *where_found
= NULL_TREE
;
9010 for
(q
= EXPR_WFL_QUALIFICATION
(wfl
); q
; q
= TREE_CHAIN
(q
))
9012 tree qual_wfl
= QUAL_WFL
(q
);
9013 tree ret_decl
; /* for EH checking */
9014 int location
; /* for EH checking */
9016 /* 15.10.1 Field Access Using a Primary */
9017 switch
(TREE_CODE
(qual_wfl
))
9020 case NEW_CLASS_EXPR
:
9021 /* If the access to the function call is a non static field,
9022 build the code to access it. */
9023 if
(JDECL_P
(decl
) && !FIELD_STATIC
(decl
))
9025 decl
= maybe_access_field
(decl
, *where_found
,
9026 DECL_CONTEXT
(decl
));
9027 if
(decl
== error_mark_node
)
9031 /* And code for the function call */
9032 if
(complete_function_arguments
(qual_wfl
))
9035 /* We might have to setup a new current class and a new this
9036 for the search of an inner class, relative to the type of
9037 a expression resolved as `decl'. The current values are
9038 saved and restored shortly after */
9039 saved_current
= current_class
;
9040 saved_this
= current_this
;
9042 && (TREE_CODE
(qual_wfl
) == NEW_CLASS_EXPR
9043 || from_qualified_this
))
9045 /* If we still have `from_qualified_this', we have the form
9046 <T>.this.f() and we need to build <T>.this */
9047 if
(from_qualified_this
)
9049 decl
= build_access_to_thisn
(current_class
, type
, 0);
9050 decl
= java_complete_tree
(decl
);
9051 type
= TREE_TYPE
(TREE_TYPE
(decl
));
9053 current_class
= type
;
9054 current_this
= decl
;
9055 from_qualified_this
= 0;
9058 if
(from_super
&& TREE_CODE
(qual_wfl
) == CALL_EXPR
)
9059 CALL_USING_SUPER
(qual_wfl
) = 1;
9060 location
= (TREE_CODE
(qual_wfl
) == CALL_EXPR ?
9061 EXPR_WFL_LINECOL
(TREE_OPERAND
(qual_wfl
, 0)) : 0);
9062 *where_found
= patch_method_invocation
(qual_wfl
, decl
, type
,
9064 &is_static
, &ret_decl
);
9065 if
(*where_found
== error_mark_node
)
9067 RESTORE_THIS_AND_CURRENT_CLASS
;
9070 *type_found
= type
= QUAL_DECL_TYPE
(*where_found
);
9072 /* If we're creating an inner class instance, check for that
9073 an enclosing instance is in scope */
9074 if
(TREE_CODE
(qual_wfl
) == NEW_CLASS_EXPR
9075 && INNER_ENCLOSING_SCOPE_CHECK
(type
))
9078 (qual_wfl
, "No enclosing instance for inner class `%s' is in scope%s",
9079 lang_printable_name
(type
, 0),
9080 (!current_this ?
"" :
9081 "; an explicit one must be provided when creating this inner class"));
9082 RESTORE_THIS_AND_CURRENT_CLASS
;
9086 /* In case we had to change then to resolve a inner class
9087 instantiation using a primary qualified by a `new' */
9088 RESTORE_THIS_AND_CURRENT_CLASS
;
9090 /* EH check. No check on access$<n> functions */
9092 && !OUTER_FIELD_ACCESS_IDENTIFIER_P
9093 (DECL_NAME
(current_function_decl
)))
9094 check_thrown_exceptions
(location
, ret_decl
);
9096 /* If the previous call was static and this one is too,
9097 build a compound expression to hold the two (because in
9098 that case, previous function calls aren't transported as
9099 forcoming function's argument. */
9100 if
(previous_call_static
&& is_static
)
9102 decl
= build
(COMPOUND_EXPR
, type
, decl
, *where_found
);
9103 TREE_SIDE_EFFECTS
(decl
) = 1;
9107 previous_call_static
= is_static
;
9108 decl
= *where_found
;
9113 case NEW_ARRAY_EXPR
:
9114 case NEW_ANONYMOUS_ARRAY_EXPR
:
9115 *where_found
= decl
= java_complete_tree
(qual_wfl
);
9116 if
(decl
== error_mark_node
)
9118 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9119 CLASS_LOADED_P
(type
) = 1;
9123 *where_found
= decl
= java_complete_tree
(qual_wfl
);
9124 if
(decl
== error_mark_node
)
9126 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9130 case CONDITIONAL_EXPR
:
9133 *where_found
= decl
= java_complete_tree
(qual_wfl
);
9134 if
(decl
== error_mark_node
)
9136 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9140 /* If the access to the function call is a non static field,
9141 build the code to access it. */
9142 if
(JDECL_P
(decl
) && !FIELD_STATIC
(decl
))
9144 decl
= maybe_access_field
(decl
, *where_found
, type
);
9145 if
(decl
== error_mark_node
)
9148 /* And code for the array reference expression */
9149 decl
= java_complete_tree
(qual_wfl
);
9150 if
(decl
== error_mark_node
)
9152 type
= QUAL_DECL_TYPE
(decl
);
9156 if
((decl
= java_complete_tree
(qual_wfl
)) == error_mark_node
)
9158 if
((type
= patch_string
(decl
)))
9160 *where_found
= QUAL_RESOLUTION
(q
) = decl
;
9161 *type_found
= type
= TREE_TYPE
(decl
);
9165 if
((decl
= java_complete_tree
(qual_wfl
)) == error_mark_node
)
9167 *where_found
= QUAL_RESOLUTION
(q
) = decl
;
9168 *type_found
= type
= TREE_TYPE
(decl
);
9172 /* Fix for -Wall Just go to the next statement. Don't
9177 /* If we fall here, we weren't processing a (static) function call. */
9178 previous_call_static
= 0;
9180 /* It can be the keyword THIS */
9181 if
(EXPR_WFL_NODE
(qual_wfl
) == this_identifier_node
)
9186 (wfl
, "Keyword `this' used outside allowed context");
9189 if
(ctxp
->explicit_constructor_p
9190 && type
== current_class
)
9192 parse_error_context
(wfl
, "Can't reference `this' before the superclass constructor has been called");
9195 /* We have to generate code for intermediate acess */
9196 if
(!from_type || TREE_TYPE
(TREE_TYPE
(current_this
)) == type
)
9198 *where_found
= decl
= current_this
;
9199 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9201 /* We're trying to access the this from somewhere else. Make sure
9202 it's allowed before doing so. */
9205 if
(!enclosing_context_p
(type
, current_class
))
9207 char *p
= xstrdup
(lang_printable_name
(type
, 0));
9208 parse_error_context
(qual_wfl
, "Can't use variable `%s.this': type `%s' isn't an outer type of type `%s'",
9210 lang_printable_name
(current_class
, 0));
9214 from_qualified_this
= 1;
9215 /* If there's nothing else after that, we need to
9216 produce something now, otherwise, the section of the
9217 code that needs to produce <T>.this will generate
9218 what is necessary. */
9219 if
(!TREE_CHAIN
(q
))
9221 decl
= build_access_to_thisn
(current_class
, type
, 0);
9222 *where_found
= decl
= java_complete_tree
(decl
);
9223 *type_found
= type
= TREE_TYPE
(decl
);
9231 /* 15.10.2 Accessing Superclass Members using SUPER */
9232 if
(EXPR_WFL_NODE
(qual_wfl
) == super_identifier_node
)
9235 /* Check on the restricted use of SUPER */
9236 if
(METHOD_STATIC
(current_function_decl
)
9237 || current_class
== object_type_node
)
9240 (wfl
, "Keyword `super' used outside allowed context");
9243 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
9244 node
= build_cast
(EXPR_WFL_LINECOL
(qual_wfl
),
9245 CLASSTYPE_SUPER
(current_class
),
9246 build_this
(EXPR_WFL_LINECOL
(qual_wfl
)));
9247 *where_found
= decl
= java_complete_tree
(node
);
9248 if
(decl
== error_mark_node
)
9250 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9251 from_super
= from_type
= 1;
9255 /* 15.13.1: Can't search for field name in packages, so we
9256 assume a variable/class name was meant. */
9257 if
(RESOLVE_PACKAGE_NAME_P
(qual_wfl
))
9259 tree name
= resolve_package
(wfl
, &q
);
9263 *where_found
= decl
= resolve_no_layout
(name
, qual_wfl
);
9264 /* We want to be absolutely sure that the class is laid
9265 out. We're going to search something inside it. */
9266 *type_found
= type
= TREE_TYPE
(decl
);
9267 layout_class
(type
);
9270 /* Fix them all the way down, if any are left. */
9273 list
= TREE_CHAIN
(q
);
9276 RESOLVE_EXPRESSION_NAME_P
(QUAL_WFL
(list
)) = 1;
9277 RESOLVE_PACKAGE_NAME_P
(QUAL_WFL
(list
)) = 0;
9278 list
= TREE_CHAIN
(list
);
9284 if
(from_super || from_cast
)
9286 ((from_cast ? qual_wfl
: wfl
),
9287 "No variable `%s' defined in class `%s'",
9288 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)),
9289 lang_printable_name
(type
, 0));
9292 (qual_wfl
, "Undefined variable or class name: `%s'",
9293 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)));
9298 /* We have a type name. It's been already resolved when the
9299 expression was qualified. */
9300 else if
(RESOLVE_TYPE_NAME_P
(qual_wfl
))
9302 if
(!(decl
= QUAL_RESOLUTION
(q
)))
9303 return
1; /* Error reported already */
9305 /* Sneak preview. If next we see a `new', we're facing a
9306 qualification with resulted in a type being selected
9307 instead of a field. Report the error */
9309 && TREE_CODE
(TREE_PURPOSE
(TREE_CHAIN
(q
))) == NEW_CLASS_EXPR
)
9311 parse_error_context
(qual_wfl
, "Undefined variable `%s'",
9312 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
9316 if
(not_accessible_p
(TREE_TYPE
(decl
), decl
, type
, 0))
9319 (qual_wfl
, "Can't access %s field `%s.%s' from `%s'",
9320 java_accstring_lookup
(get_access_flags_from_decl
(decl
)),
9321 GET_TYPE_NAME
(type
),
9322 IDENTIFIER_POINTER
(DECL_NAME
(decl
)),
9323 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(current_class
))));
9326 check_deprecation
(qual_wfl
, decl
);
9328 type
= TREE_TYPE
(decl
);
9331 /* We resolve and expression name */
9334 tree field_decl
= NULL_TREE
;
9336 /* If there exists an early resolution, use it. That occurs
9337 only once and we know that there are more things to
9338 come. Don't do that when processing something after SUPER
9339 (we need more thing to be put in place below */
9340 if
(!from_super
&& QUAL_RESOLUTION
(q
))
9342 decl
= QUAL_RESOLUTION
(q
);
9345 if
(TREE_CODE
(decl
) == FIELD_DECL
&& !FIELD_STATIC
(decl
))
9348 *where_found
= current_this
;
9351 static_ref_err
(qual_wfl
, DECL_NAME
(decl
),
9355 if
(outer_field_access_p
(current_class
, decl
))
9356 decl
= build_outer_field_access
(qual_wfl
, decl
);
9360 *where_found
= TREE_TYPE
(decl
);
9361 if
(TREE_CODE
(*where_found
) == POINTER_TYPE
)
9362 *where_found
= TREE_TYPE
(*where_found
);
9367 /* We have to search for a field, knowing the type of its
9368 container. The flag FROM_TYPE indicates that we resolved
9369 the last member of the expression as a type name, which
9370 means that for the resolution of this field, we'll look
9371 for other errors than if it was resolved as a member of
9376 tree field_decl_type
; /* For layout */
9378 if
(!from_type
&& !JREFERENCE_TYPE_P
(type
))
9381 (qual_wfl
, "Attempt to reference field `%s' in `%s %s'",
9382 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)),
9383 lang_printable_name
(type
, 0),
9384 IDENTIFIER_POINTER
(DECL_NAME
(field_decl
)));
9388 field_decl
= lookup_field_wrapper
(type
,
9389 EXPR_WFL_NODE
(qual_wfl
));
9391 /* Maybe what we're trying to access to is an inner
9392 class, only if decl is a TYPE_DECL. */
9393 if
(!field_decl
&& TREE_CODE
(decl
) == TYPE_DECL
)
9395 tree ptr
, inner_decl
;
9397 BUILD_PTR_FROM_NAME
(ptr
, EXPR_WFL_NODE
(qual_wfl
));
9398 inner_decl
= resolve_class
(decl
, ptr
, NULL_TREE
, qual_wfl
);
9401 check_inner_class_access
(inner_decl
, decl
, qual_wfl
);
9402 type
= TREE_TYPE
(inner_decl
);
9409 if
(field_decl
== NULL_TREE
)
9412 (qual_wfl
, "No variable `%s' defined in type `%s'",
9413 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)),
9414 GET_TYPE_NAME
(type
));
9417 if
(field_decl
== error_mark_node
)
9420 /* Layout the type of field_decl, since we may need
9421 it. Don't do primitive types or loaded classes. The
9422 situation of non primitive arrays may not handled
9423 properly here. FIXME */
9424 if
(TREE_CODE
(TREE_TYPE
(field_decl
)) == POINTER_TYPE
)
9425 field_decl_type
= TREE_TYPE
(TREE_TYPE
(field_decl
));
9427 field_decl_type
= TREE_TYPE
(field_decl
);
9428 if
(!JPRIMITIVE_TYPE_P
(field_decl_type
)
9429 && !CLASS_LOADED_P
(field_decl_type
)
9430 && !TYPE_ARRAY_P
(field_decl_type
))
9431 resolve_and_layout
(field_decl_type
, NULL_TREE
);
9432 if
(TYPE_ARRAY_P
(field_decl_type
))
9433 CLASS_LOADED_P
(field_decl_type
) = 1;
9435 /* Check on accessibility here */
9436 if
(not_accessible_p
(current_class
, field_decl
,
9437 DECL_CONTEXT
(field_decl
), from_super
))
9441 "Can't access %s field `%s.%s' from `%s'",
9442 java_accstring_lookup
9443 (get_access_flags_from_decl
(field_decl
)),
9444 GET_TYPE_NAME
(type
),
9445 IDENTIFIER_POINTER
(DECL_NAME
(field_decl
)),
9447 (DECL_NAME
(TYPE_NAME
(current_class
))));
9450 check_deprecation
(qual_wfl
, field_decl
);
9452 /* There are things to check when fields are accessed
9453 from type. There are no restrictions on a static
9454 declaration of the field when it is accessed from an
9456 is_static
= FIELD_STATIC
(field_decl
);
9457 if
(!from_super
&& from_type
9458 && !TYPE_INTERFACE_P
(type
)
9460 && (current_function_decl
9461 && METHOD_STATIC
(current_function_decl
)))
9463 static_ref_err
(qual_wfl
, EXPR_WFL_NODE
(qual_wfl
), type
);
9466 from_cast
= from_super
= 0;
9468 /* It's an access from a type but it isn't static, we
9469 make it relative to `this'. */
9470 if
(!is_static
&& from_type
)
9471 decl
= current_this
;
9473 /* If we need to generate something to get a proper
9474 handle on what this field is accessed from, do it
9478 decl
= maybe_access_field
(decl
, *where_found
, *type_found
);
9479 if
(decl
== error_mark_node
)
9483 /* We want to keep the location were found it, and the type
9485 *where_found
= decl
;
9488 /* Generate the correct expression for field access from
9490 if
(from_qualified_this
)
9492 field_decl
= build_outer_field_access
(qual_wfl
, field_decl
);
9493 from_qualified_this
= 0;
9496 /* This is the decl found and eventually the next one to
9501 type
= QUAL_DECL_TYPE
(decl
);
9503 /* Sneak preview. If decl is qualified by a `new', report
9504 the error here to be accurate on the peculiar construct */
9506 && TREE_CODE
(TREE_PURPOSE
(TREE_CHAIN
(q
))) == NEW_CLASS_EXPR
9507 && !JREFERENCE_TYPE_P
(type
))
9509 parse_error_context
(qual_wfl
, "Attempt to reference field `new' in a `%s'",
9510 lang_printable_name
(type
, 0));
9514 /* `q' might have changed due to a after package resolution
9523 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
9524 can't be accessed from REFERENCE (a record type). If MEMBER
9525 features a protected access, we then use WHERE which, if non null,
9526 holds the type of MEMBER's access that is checked against
9527 6.6.2.1. This function should be used when decl is a field or a
9531 not_accessible_p
(reference
, member
, where
, from_super
)
9532 tree reference
, member
;
9536 int access_flag
= get_access_flags_from_decl
(member
);
9538 /* Inner classes are processed by check_inner_class_access */
9539 if
(INNER_CLASS_TYPE_P
(reference
))
9542 /* Access always granted for members declared public */
9543 if
(access_flag
& ACC_PUBLIC
)
9546 /* Check access on protected members */
9547 if
(access_flag
& ACC_PROTECTED
)
9549 /* Access granted if it occurs from within the package
9550 containing the class in which the protected member is
9552 if
(class_in_current_package
(DECL_CONTEXT
(member
)))
9555 /* If accessed with the form `super.member', then access is granted */
9559 /* If where is active, access was made through a
9560 qualifier. Access is granted if the type of the qualifier is
9561 or is a sublass of the type the access made from (6.6.2.1.) */
9562 if
(where
&& !inherits_from_p
(reference
, where
))
9565 /* Otherwise, access is granted if occuring from the class where
9566 member is declared or a subclass of it. Find the right
9567 context to perform the check */
9568 if
(PURE_INNER_CLASS_TYPE_P
(reference
))
9570 while
(INNER_CLASS_TYPE_P
(reference
))
9572 if
(inherits_from_p
(reference
, DECL_CONTEXT
(member
)))
9574 reference
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(reference
)));
9577 if
(inherits_from_p
(reference
, DECL_CONTEXT
(member
)))
9582 /* Check access on private members. Access is granted only if it
9583 occurs from within the class in which it is declared -- that does
9584 it for innerclasses too. */
9585 if
(access_flag
& ACC_PRIVATE
)
9587 if
(reference
== DECL_CONTEXT
(member
))
9589 if
(enclosing_context_p
(reference
, DECL_CONTEXT
(member
)))
9594 /* Default access are permitted only when occuring within the
9595 package in which the type (REFERENCE) is declared. In other words,
9596 REFERENCE is defined in the current package */
9598 return
!class_in_current_package
(reference
);
9600 /* Otherwise, access is granted */
9604 /* Test deprecated decl access. */
9606 check_deprecation
(wfl
, decl
)
9609 const char *file
= DECL_SOURCE_FILE
(decl
);
9610 /* Complain if the field is deprecated and the file it was defined
9611 in isn't compiled at the same time the file which contains its
9613 if
(DECL_DEPRECATED
(decl
)
9614 && !IS_A_COMMAND_LINE_FILENAME_P
(get_identifier
(file
)))
9617 switch
(TREE_CODE
(decl
))
9620 strcpy
(the
, "method");
9623 strcpy
(the
, "field");
9626 strcpy
(the
, "class");
9631 parse_warning_context
9632 (wfl
, "The %s `%s' in class `%s' has been deprecated",
9633 the
, lang_printable_name
(decl
, 0),
9634 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(decl
)))));
9638 /* Returns 1 if class was declared in the current package, 0 otherwise */
9641 class_in_current_package
(class
)
9644 static tree cache
= NULL_TREE
;
9651 qualified_flag
= QUALIFIED_P
(DECL_NAME
(TYPE_NAME
(class
)));
9653 /* If the current package is empty and the name of CLASS is
9654 qualified, class isn't in the current package. If there is a
9655 current package and the name of the CLASS is not qualified, class
9656 isn't in the current package */
9657 if
((!ctxp
->package
&& qualified_flag
) ||
(ctxp
->package
&& !qualified_flag
))
9660 /* If there is not package and the name of CLASS isn't qualified,
9661 they belong to the same unnamed package */
9662 if
(!ctxp
->package
&& !qualified_flag
)
9665 /* Compare the left part of the name of CLASS with the package name */
9666 breakdown_qualified
(&left
, NULL
, DECL_NAME
(TYPE_NAME
(class
)));
9667 if
(ctxp
->package
== left
)
9669 static int initialized_p
;
9670 /* Register CACHE with the garbage collector. */
9673 ggc_add_tree_root
(&cache
, 1);
9683 /* This function may generate code to access DECL from WHERE. This is
9684 done only if certain conditions meet. */
9687 maybe_access_field
(decl
, where
, type
)
9688 tree decl
, where
, type
;
9690 if
(TREE_CODE
(decl
) == FIELD_DECL
&& decl
!= current_this
9691 && !FIELD_STATIC
(decl
))
9692 decl
= build_field_ref
(where ? where
: current_this
,
9693 (type ? type
: DECL_CONTEXT
(decl
)),
9698 /* Build a method invocation, by patching PATCH. If non NULL
9699 and according to the situation, PRIMARY and WHERE may be
9700 used. IS_STATIC is set to 1 if the invoked function is static. */
9703 patch_method_invocation
(patch
, primary
, where
, from_super
,
9704 is_static
, ret_decl
)
9705 tree patch
, primary
, where
;
9710 tree wfl
= TREE_OPERAND
(patch
, 0);
9711 tree args
= TREE_OPERAND
(patch
, 1);
9712 tree name
= EXPR_WFL_NODE
(wfl
);
9714 int is_static_flag
= 0;
9715 int is_super_init
= 0;
9716 tree this_arg
= NULL_TREE
;
9717 int is_array_clone_call
= 0;
9719 /* Should be overriden if everything goes well. Otherwise, if
9720 something fails, it should keep this value. It stop the
9721 evaluation of a bogus assignment. See java_complete_tree,
9722 MODIFY_EXPR: for the reasons why we sometimes want to keep on
9723 evaluating an assignment */
9724 TREE_TYPE
(patch
) = error_mark_node
;
9726 /* Since lookup functions are messing with line numbers, save the
9728 java_parser_context_save_global
();
9730 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
9732 /* Resolution of qualified name, excluding constructors */
9733 if
(QUALIFIED_P
(name
) && !CALL_CONSTRUCTOR_P
(patch
))
9735 tree identifier
, identifier_wfl
, type
, resolved
;
9736 /* Extract the last IDENTIFIER of the qualified
9737 expression. This is a wfl and we will use it's location
9738 data during error report. */
9739 identifier_wfl
= cut_identifier_in_qualified
(wfl
);
9740 identifier
= EXPR_WFL_NODE
(identifier_wfl
);
9742 /* Given the context, IDENTIFIER is syntactically qualified
9743 as a MethodName. We need to qualify what's before */
9744 qualify_ambiguous_name
(wfl
);
9745 resolved
= resolve_field_access
(wfl
, NULL
, NULL
);
9747 if
(resolved
== error_mark_node
)
9748 PATCH_METHOD_RETURN_ERROR
();
9750 type
= GET_SKIP_TYPE
(resolved
);
9751 resolve_and_layout
(type
, NULL_TREE
);
9753 if
(JPRIMITIVE_TYPE_P
(type
))
9757 "Can't invoke a method on primitive type `%s'",
9758 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(type
))));
9759 PATCH_METHOD_RETURN_ERROR
();
9762 list
= lookup_method_invoke
(0, identifier_wfl
, type
, identifier
, args
);
9763 args
= nreverse
(args
);
9765 /* We're resolving a call from a type */
9766 if
(TREE_CODE
(resolved
) == TYPE_DECL
)
9768 if
(CLASS_INTERFACE
(resolved
))
9772 "Can't make static reference to method `%s' in interface `%s'",
9773 IDENTIFIER_POINTER
(identifier
),
9774 IDENTIFIER_POINTER
(name
));
9775 PATCH_METHOD_RETURN_ERROR
();
9777 if
(list
&& !METHOD_STATIC
(list
))
9779 char *fct_name
= xstrdup
(lang_printable_name
(list
, 0));
9782 "Can't make static reference to method `%s %s' in class `%s'",
9783 lang_printable_name
(TREE_TYPE
(TREE_TYPE
(list
)), 0),
9784 fct_name
, IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(type
))));
9786 PATCH_METHOD_RETURN_ERROR
();
9790 this_arg
= primary
= resolved
;
9792 if
(TYPE_ARRAY_P
(type
) && identifier
== get_identifier
("clone"))
9793 is_array_clone_call
= 1;
9795 /* IDENTIFIER_WFL will be used to report any problem further */
9796 wfl
= identifier_wfl
;
9798 /* Resolution of simple names, names generated after a primary: or
9802 tree class_to_search
= NULL_TREE
;
9803 int lc
; /* Looking for Constructor */
9805 /* We search constructor in their target class */
9806 if
(CALL_CONSTRUCTOR_P
(patch
))
9808 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
9809 class_to_search
= EXPR_WFL_NODE
(wfl
);
9810 else if
(EXPR_WFL_NODE
(TREE_OPERAND
(patch
, 0)) ==
9811 this_identifier_node
)
9812 class_to_search
= NULL_TREE
;
9813 else if
(EXPR_WFL_NODE
(TREE_OPERAND
(patch
, 0)) ==
9814 super_identifier_node
)
9817 if
(CLASSTYPE_SUPER
(current_class
))
9819 DECL_NAME
(TYPE_NAME
(CLASSTYPE_SUPER
(current_class
)));
9822 parse_error_context
(wfl
, "Can't invoke super constructor on java.lang.Object");
9823 PATCH_METHOD_RETURN_ERROR
();
9827 /* Class to search is NULL if we're searching the current one */
9828 if
(class_to_search
)
9830 class_to_search
= resolve_and_layout
(class_to_search
, wfl
);
9832 if
(!class_to_search
)
9835 (wfl
, "Class `%s' not found in type declaration",
9836 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
9837 PATCH_METHOD_RETURN_ERROR
();
9840 /* Can't instantiate an abstract class, but we can
9841 invoke it's constructor. It's use within the `new'
9842 context is denied here. */
9843 if
(CLASS_ABSTRACT
(class_to_search
)
9844 && TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
9847 (wfl
, "Class `%s' is an abstract class. It can't be instantiated",
9848 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
9849 PATCH_METHOD_RETURN_ERROR
();
9852 class_to_search
= TREE_TYPE
(class_to_search
);
9855 class_to_search
= current_class
;
9858 /* This is a regular search in the local class, unless an
9859 alternate class is specified. */
9862 class_to_search
= (where ? where
: current_class
);
9866 /* NAME is a simple identifier or comes from a primary. Search
9867 in the class whose declaration contain the method being
9869 resolve_and_layout
(class_to_search
, NULL_TREE
);
9871 list
= lookup_method_invoke
(lc
, wfl
, class_to_search
, name
, args
);
9872 /* Don't continue if no method were found, as the next statement
9873 can't be executed then. */
9875 PATCH_METHOD_RETURN_ERROR
();
9877 if
(TYPE_ARRAY_P
(class_to_search
)
9878 && DECL_NAME
(list
) == get_identifier
("clone"))
9879 is_array_clone_call
= 1;
9881 /* Check for static reference if non static methods */
9882 if
(check_for_static_method_reference
(wfl
, patch
, list
,
9883 class_to_search
, primary
))
9884 PATCH_METHOD_RETURN_ERROR
();
9886 /* Check for inner classes creation from illegal contexts */
9887 if
(lc
&& (INNER_CLASS_TYPE_P
(class_to_search
)
9888 && !CLASS_STATIC
(TYPE_NAME
(class_to_search
)))
9889 && INNER_ENCLOSING_SCOPE_CHECK
(class_to_search
))
9892 (wfl
, "No enclosing instance for inner class `%s' is in scope%s",
9893 lang_printable_name
(class_to_search
, 0),
9894 (!current_this ?
"" :
9895 "; an explicit one must be provided when creating this inner class"));
9896 PATCH_METHOD_RETURN_ERROR
();
9899 /* Non static methods are called with the current object extra
9900 argument. If patch a `new TYPE()', the argument is the value
9901 returned by the object allocator. If method is resolved as a
9902 primary, use the primary otherwise use the current THIS. */
9903 args
= nreverse
(args
);
9904 if
(TREE_CODE
(patch
) != NEW_CLASS_EXPR
)
9906 this_arg
= primary ? primary
: current_this
;
9908 /* If we're using an access method, things are different.
9909 There are two familly of cases:
9911 1) We're not generating bytecodes:
9913 - LIST is non static. It's invocation is transformed from
9914 x(a1,...,an) into this$<n>.x(a1,....an).
9915 - LIST is static. It's invocation is transformed from
9916 x(a1,...,an) into TYPE_OF(this$<n>).x(a1,....an)
9918 2) We're generating bytecodes:
9920 - LIST is non static. It's invocation is transformed from
9921 x(a1,....,an) into access$<n>(this$<n>,a1,...,an).
9922 - LIST is static. It's invocation is transformed from
9923 x(a1,....,an) into TYPEOF(this$<n>).x(a1,....an).
9925 Of course, this$<n> can be abitrary complex, ranging from
9926 this$0 (the immediate outer context) to
9927 access$0(access$0(...(this$0))).
9929 maybe_use_access_method returns a non zero value if the
9930 this_arg has to be moved into the (then generated) stub
9931 argument list. In the meantime, the selected function
9932 might have be replaced by a generated stub. */
9933 if
(maybe_use_access_method
(is_super_init
, &list
, &this_arg
))
9935 args
= tree_cons
(NULL_TREE
, this_arg
, args
);
9936 this_arg
= NULL_TREE
; /* So it doesn't get chained twice */
9941 /* Merge point of all resolution schemes. If we have nothing, this
9942 is an error, already signaled */
9944 PATCH_METHOD_RETURN_ERROR
();
9946 /* Check accessibility, position the is_static flag, build and
9948 if
(not_accessible_p
(DECL_CONTEXT
(current_function_decl
), list
,
9949 (primary ? TREE_TYPE
(TREE_TYPE
(primary
)) :
9950 NULL_TREE
), from_super
)
9951 /* Calls to clone() on array types are permitted as a special-case. */
9952 && !is_array_clone_call
)
9954 const char *fct_name
= IDENTIFIER_POINTER
(DECL_NAME
(list
));
9955 const char *access
=
9956 java_accstring_lookup
(get_access_flags_from_decl
(list
));
9958 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(list
))));
9959 const char *refklass
=
9960 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(current_class
)));
9961 const char *what
= (DECL_CONSTRUCTOR_P
(list
)
9962 ?
"constructor" : "method");
9963 /* FIXME: WFL yields the wrong message here but I don't know
9964 what else to use. */
9965 parse_error_context
(wfl
,
9966 "Can't access %s %s `%s.%s' from `%s'",
9967 access
, what
, klass
, fct_name
, refklass
);
9968 PATCH_METHOD_RETURN_ERROR
();
9970 check_deprecation
(wfl
, list
);
9972 /* If invoking a innerclass constructor, there are hidden parameters
9974 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
9975 && PURE_INNER_CLASS_TYPE_P
(DECL_CONTEXT
(list
)))
9977 /* And make sure we add the accessed local variables to be saved
9978 in field aliases. */
9979 args
= build_alias_initializer_parameter_list
9980 (AIPL_FUNCTION_CTOR_INVOCATION
, DECL_CONTEXT
(list
), args
, NULL
);
9982 /* Secretly pass the current_this/primary as a second argument */
9983 if
(primary || current_this
)
9986 tree this_type
= (current_this ?
9987 TREE_TYPE
(TREE_TYPE
(current_this
)) : NULL_TREE
);
9988 /* Method's (list) enclosing context */
9989 tree mec
= DECL_CONTEXT
(TYPE_NAME
(DECL_CONTEXT
(list
)));
9990 /* If we have a primary, use it. */
9992 extra_arg
= primary
;
9993 /* The current `this' is an inner class but isn't a direct
9994 enclosing context for the inner class we're trying to
9995 create. Build an access to the proper enclosing context
9997 else if
(current_this
&& PURE_INNER_CLASS_TYPE_P
(this_type
)
9998 && this_type
!= TREE_TYPE
(mec
))
10001 extra_arg
= build_access_to_thisn
(current_class
,
10002 TREE_TYPE
(mec
), 0);
10003 extra_arg
= java_complete_tree
(extra_arg
);
10005 /* Otherwise, just use the current `this' as an enclosing
10008 extra_arg
= current_this
;
10009 args
= tree_cons
(NULL_TREE
, extra_arg
, args
);
10012 args
= tree_cons
(NULL_TREE
, integer_zero_node
, args
);
10015 /* This handles the situation where a constructor invocation needs
10016 to have an enclosing context passed as a second parameter (the
10017 constructor is one of an inner class. We extract it from the
10018 current function. */
10019 if
(is_super_init
&& PURE_INNER_CLASS_TYPE_P
(DECL_CONTEXT
(list
)))
10021 tree enclosing_decl
= DECL_CONTEXT
(TYPE_NAME
(current_class
));
10024 if
(ANONYMOUS_CLASS_P
(current_class
) ||
!DECL_CONTEXT
(enclosing_decl
))
10026 extra_arg
= DECL_FUNCTION_BODY
(current_function_decl
);
10027 extra_arg
= TREE_CHAIN
(BLOCK_EXPR_DECLS
(extra_arg
));
10031 tree dest
= TREE_TYPE
(DECL_CONTEXT
(enclosing_decl
));
10033 build_access_to_thisn
(TREE_TYPE
(enclosing_decl
), dest
, 0);
10034 extra_arg
= java_complete_tree
(extra_arg
);
10036 args
= tree_cons
(NULL_TREE
, extra_arg
, args
);
10039 is_static_flag
= METHOD_STATIC
(list
);
10040 if
(! is_static_flag
&& this_arg
!= NULL_TREE
)
10041 args
= tree_cons
(NULL_TREE
, this_arg
, args
);
10043 /* In the context of an explicit constructor invocation, we can't
10044 invoke any method relying on `this'. Exceptions are: we're
10045 invoking a static function, primary exists and is not the current
10046 this, we're creating a new object. */
10047 if
(ctxp
->explicit_constructor_p
10049 && (!primary || primary
== current_this
)
10050 && (TREE_CODE
(patch
) != NEW_CLASS_EXPR
))
10052 parse_error_context
(wfl
, "Can't reference `this' before the superclass constructor has been called");
10053 PATCH_METHOD_RETURN_ERROR
();
10055 java_parser_context_restore_global
();
10057 *is_static
= is_static_flag
;
10058 /* Sometimes, we want the decl of the selected method. Such as for
10062 patch
= patch_invoke
(patch
, list
, args
);
10063 if
(is_super_init
&& CLASS_HAS_FINIT_P
(current_class
))
10065 tree finit_parms
, finit_call
;
10067 /* Prepare to pass hidden parameters to finit$, if any. */
10068 finit_parms
= build_alias_initializer_parameter_list
10069 (AIPL_FUNCTION_FINIT_INVOCATION
, current_class
, NULL_TREE
, NULL
);
10072 build_method_invocation
(build_wfl_node
(finit_identifier_node
),
10075 /* Generate the code used to initialize fields declared with an
10076 initialization statement and build a compound statement along
10077 with the super constructor invocation. */
10078 patch
= build
(COMPOUND_EXPR
, void_type_node
, patch
,
10079 java_complete_tree
(finit_call
));
10080 CAN_COMPLETE_NORMALLY
(patch
) = 1;
10085 /* Check that we're not trying to do a static reference to a method in
10086 non static method. Return 1 if it's the case, 0 otherwise. */
10089 check_for_static_method_reference
(wfl
, node
, method
, where
, primary
)
10090 tree wfl
, node
, method
, where
, primary
;
10092 if
(METHOD_STATIC
(current_function_decl
)
10093 && !METHOD_STATIC
(method
) && !primary
&& !CALL_CONSTRUCTOR_P
(node
))
10095 char *fct_name
= xstrdup
(lang_printable_name
(method
, 0));
10096 parse_error_context
10097 (wfl
, "Can't make static reference to method `%s %s' in class `%s'",
10098 lang_printable_name
(TREE_TYPE
(TREE_TYPE
(method
)), 0), fct_name
,
10099 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(where
))));
10106 /* Fix the invocation of *MDECL if necessary in the case of a
10107 invocation from an inner class. *THIS_ARG might be modified
10108 appropriately and an alternative access to *MDECL might be
10112 maybe_use_access_method
(is_super_init
, mdecl
, this_arg
)
10114 tree
*mdecl
, *this_arg
;
10117 tree md
= *mdecl
, ta
= *this_arg
;
10119 int non_static_context
= !METHOD_STATIC
(md
);
10122 || DECL_CONTEXT
(md
) == current_class
10123 ||
!PURE_INNER_CLASS_TYPE_P
(current_class
)
10124 || DECL_FINIT_P
(md
))
10127 /* If we're calling a method found in an enclosing class, generate
10128 what it takes to retrieve the right this. Don't do that if we're
10129 invoking a static method. Note that if MD's type is unrelated to
10130 CURRENT_CLASS, then the current this can be used. */
10132 if
(non_static_context
&& DECL_CONTEXT
(md
) != object_type_node
)
10134 ctx
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(current_class
)));
10135 if
(inherits_from_p
(ctx
, DECL_CONTEXT
(md
)))
10137 ta
= build_current_thisn
(current_class
);
10138 ta
= build_wfl_node
(ta
);
10145 maybe_build_thisn_access_method
(type
);
10146 if
(inherits_from_p
(type
, DECL_CONTEXT
(md
)))
10148 ta
= build_access_to_thisn
(ctx
, type
, 0);
10151 type
= (DECL_CONTEXT
(TYPE_NAME
(type
)) ?
10152 TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type
))) : NULL_TREE
);
10155 ta
= java_complete_tree
(ta
);
10158 /* We might have to use an access method to get to MD. We can
10159 break the method access rule as far as we're not generating
10161 if
(METHOD_PRIVATE
(md
) && flag_emit_class_files
)
10163 md
= build_outer_method_access_method
(md
);
10170 /* Returnin a non zero value indicates we were doing a non static
10171 method invokation that is now a static invocation. It will have
10172 callee displace `this' to insert it in the regular argument
10174 return
(non_static_context
&& to_return
);
10177 /* Patch an invoke expression METHOD and ARGS, based on its invocation
10181 patch_invoke
(patch
, method
, args
)
10182 tree patch
, method
, args
;
10185 tree original_call
, t
, ta
;
10186 tree check
= NULL_TREE
;
10188 /* Last step for args: convert build-in types. If we're dealing with
10189 a new TYPE() type call, the first argument to the constructor
10190 isn't found in the incoming argument list, but delivered by
10192 t
= TYPE_ARG_TYPES
(TREE_TYPE
(method
));
10193 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
10194 t
= TREE_CHAIN
(t
);
10195 for
(ta
= args
; t
!= end_params_node
&& ta
;
10196 t
= TREE_CHAIN
(t
), ta
= TREE_CHAIN
(ta
))
10197 if
(JPRIMITIVE_TYPE_P
(TREE_TYPE
(TREE_VALUE
(ta
))) &&
10198 TREE_TYPE
(TREE_VALUE
(ta
)) != TREE_VALUE
(t
))
10199 TREE_VALUE
(ta
) = convert
(TREE_VALUE
(t
), TREE_VALUE
(ta
));
10201 /* Resolve unresolved returned type isses */
10202 t
= TREE_TYPE
(TREE_TYPE
(method
));
10203 if
(TREE_CODE
(t
) == POINTER_TYPE
&& !CLASS_LOADED_P
(TREE_TYPE
(t
)))
10204 resolve_and_layout
(TREE_TYPE
(t
), NULL
);
10206 if
(flag_emit_class_files || flag_emit_xref
)
10210 tree signature
= build_java_signature
(TREE_TYPE
(method
));
10211 switch
(invocation_mode
(method
, CALL_USING_SUPER
(patch
)))
10213 case INVOKE_VIRTUAL
:
10214 dtable
= invoke_build_dtable
(0, args
);
10215 func
= build_invokevirtual
(dtable
, method
);
10218 case INVOKE_NONVIRTUAL
:
10219 /* If the object for the method call is null, we throw an
10220 exception. We don't do this if the object is the current
10221 method's `this'. In other cases we just rely on an
10222 optimization pass to eliminate redundant checks. */
10223 if
(TREE_VALUE
(args
) != current_this
)
10225 /* We use a save_expr here to make sure we only evaluate
10226 the new `self' expression once. */
10227 tree save_arg
= save_expr
(TREE_VALUE
(args
));
10228 TREE_VALUE
(args
) = save_arg
;
10229 check
= java_check_reference
(save_arg
, 1);
10231 /* Fall through. */
10234 case INVOKE_STATIC
:
10235 func
= build_known_method_ref
(method
, TREE_TYPE
(method
),
10236 DECL_CONTEXT
(method
),
10240 case INVOKE_INTERFACE
:
10241 dtable
= invoke_build_dtable
(1, args
);
10242 func
= build_invokeinterface
(dtable
, method
);
10249 /* Ensure self_type is initialized, (invokestatic). FIXME */
10250 func
= build1
(NOP_EXPR
, build_pointer_type
(TREE_TYPE
(method
)), func
);
10253 TREE_TYPE
(patch
) = TREE_TYPE
(TREE_TYPE
(method
));
10254 TREE_OPERAND
(patch
, 0) = func
;
10255 TREE_OPERAND
(patch
, 1) = args
;
10256 original_call
= patch
;
10258 /* We're processing a `new TYPE ()' form. New is called and its
10259 returned value is the first argument to the constructor. We build
10260 a COMPOUND_EXPR and use saved expression so that the overall NEW
10261 expression value is a pointer to a newly created and initialized
10263 if
(TREE_CODE
(original_call
) == NEW_CLASS_EXPR
)
10265 tree class
= DECL_CONTEXT
(method
);
10266 tree c1
, saved_new
, size
, new
;
10267 if
(flag_emit_class_files || flag_emit_xref
)
10269 TREE_TYPE
(patch
) = build_pointer_type
(class
);
10272 if
(!TYPE_SIZE
(class
))
10273 safe_layout_class
(class
);
10274 size
= size_in_bytes
(class
);
10275 new
= build
(CALL_EXPR
, promote_type
(class
),
10276 build_address_of
(alloc_object_node
),
10277 tree_cons
(NULL_TREE
, build_class_ref
(class
),
10278 build_tree_list
(NULL_TREE
,
10279 size_in_bytes
(class
))),
10281 saved_new
= save_expr
(new
);
10282 c1
= build_tree_list
(NULL_TREE
, saved_new
);
10283 TREE_CHAIN
(c1
) = TREE_OPERAND
(original_call
, 1);
10284 TREE_OPERAND
(original_call
, 1) = c1
;
10285 TREE_SET_CODE
(original_call
, CALL_EXPR
);
10286 patch
= build
(COMPOUND_EXPR
, TREE_TYPE
(new
), patch
, saved_new
);
10289 /* If CHECK is set, then we are building a check to see if the object
10291 if
(check
!= NULL_TREE
)
10293 patch
= build
(COMPOUND_EXPR
, TREE_TYPE
(patch
), check
, patch
);
10294 TREE_SIDE_EFFECTS
(patch
) = 1;
10301 invocation_mode
(method
, super
)
10305 int access
= get_access_flags_from_decl
(method
);
10308 return INVOKE_SUPER
;
10310 if
(access
& ACC_STATIC
)
10311 return INVOKE_STATIC
;
10313 /* We have to look for a constructor before we handle nonvirtual
10314 calls; otherwise the constructor will look nonvirtual. */
10315 if
(DECL_CONSTRUCTOR_P
(method
))
10316 return INVOKE_STATIC
;
10318 if
(access
& ACC_FINAL || access
& ACC_PRIVATE
)
10319 return INVOKE_NONVIRTUAL
;
10321 if
(CLASS_FINAL
(TYPE_NAME
(DECL_CONTEXT
(method
))))
10322 return INVOKE_NONVIRTUAL
;
10324 if
(CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(method
))))
10325 return INVOKE_INTERFACE
;
10327 return INVOKE_VIRTUAL
;
10330 /* Retrieve a refined list of matching methods. It covers the step
10331 15.11.2 (Compile-Time Step 2) */
10334 lookup_method_invoke
(lc
, cl
, class
, name
, arg_list
)
10337 tree class
, name
, arg_list
;
10339 tree atl
= end_params_node
; /* Arg Type List */
10340 tree method
, signature
, list
, node
;
10341 const char *candidates
; /* Used for error report */
10344 /* Fix the arguments */
10345 for
(node
= arg_list
; node
; node
= TREE_CHAIN
(node
))
10347 tree current_arg
= TREE_TYPE
(TREE_VALUE
(node
));
10348 /* Non primitive type may have to be resolved */
10349 if
(!JPRIMITIVE_TYPE_P
(current_arg
))
10350 resolve_and_layout
(current_arg
, NULL_TREE
);
10352 if
(TREE_CODE
(current_arg
) == RECORD_TYPE
)
10353 current_arg
= promote_type
(current_arg
);
10354 atl
= tree_cons
(NULL_TREE
, current_arg
, atl
);
10357 /* Presto. If we're dealing with an anonymous class and a
10358 constructor call, generate the right constructor now, since we
10359 know the arguments' types. */
10361 if
(lc
&& ANONYMOUS_CLASS_P
(class
))
10362 craft_constructor
(TYPE_NAME
(class
), atl
);
10364 /* Find all candidates and then refine the list, searching for the
10365 most specific method. */
10366 list
= find_applicable_accessible_methods_list
(lc
, class
, name
, atl
);
10367 list
= find_most_specific_methods_list
(list
);
10368 if
(list
&& !TREE_CHAIN
(list
))
10369 return TREE_VALUE
(list
);
10371 /* Issue an error. List candidates if any. Candidates are listed
10372 only if accessible (non accessible methods may end-up here for
10373 the sake of a better error report). */
10378 obstack_grow
(&temporary_obstack
, ". Candidates are:\n", 18);
10379 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
10381 tree cm
= TREE_VALUE
(current
);
10382 char string [4096];
10383 if
(!cm || not_accessible_p
(class
, cm
, NULL_TREE
, 0))
10386 (string, " `%s' in `%s'%s",
10387 get_printable_method_name
(cm
),
10388 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(cm
)))),
10389 (TREE_CHAIN
(current
) ?
"\n" : ""));
10390 obstack_grow
(&temporary_obstack
, string, strlen
(string));
10392 obstack_1grow
(&temporary_obstack
, '\0');
10393 candidates
= obstack_finish
(&temporary_obstack
);
10395 /* Issue the error message */
10396 method
= make_node
(FUNCTION_TYPE
);
10397 TYPE_ARG_TYPES
(method
) = atl
;
10398 signature
= build_java_argument_signature
(method
);
10399 dup
= xstrdup
(lang_printable_name
(class
, 0));
10400 parse_error_context
(cl
, "Can't find %s `%s(%s)' in type `%s'%s",
10401 (lc ?
"constructor" : "method"),
10402 (lc ? dup
: IDENTIFIER_POINTER
(name
)),
10403 IDENTIFIER_POINTER
(signature
), dup
,
10404 (candidates ? candidates
: ""));
10409 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
10410 when we're looking for a constructor. */
10413 find_applicable_accessible_methods_list
(lc
, class
, name
, arglist
)
10415 tree class
, name
, arglist
;
10417 static struct hash_table t
, *searched_classes
= NULL
;
10418 static int search_not_done
= 0;
10419 tree list
= NULL_TREE
, all_list
= NULL_TREE
;
10421 /* Check the hash table to determine if this class has been searched
10423 if
(searched_classes
)
10425 if
(hash_lookup
(searched_classes
,
10426 (const hash_table_key
) class
, FALSE
, NULL
))
10431 hash_table_init
(&t
, hash_newfunc
, java_hash_hash_tree_node
,
10432 java_hash_compare_tree_node
);
10433 searched_classes
= &t
;
10437 hash_lookup
(searched_classes
,
10438 (const hash_table_key
) class
, TRUE
, NULL
);
10440 if
(!CLASS_LOADED_P
(class
) && !CLASS_FROM_SOURCE_P
(class
))
10442 load_class
(class
, 1);
10443 safe_layout_class
(class
);
10446 /* Search interfaces */
10447 if
(TREE_CODE
(TYPE_NAME
(class
)) == TYPE_DECL
10448 && CLASS_INTERFACE
(TYPE_NAME
(class
)))
10451 tree basetype_vec
= TYPE_BINFO_BASETYPES
(class
);
10452 search_applicable_methods_list
(lc
, TYPE_METHODS
(class
),
10453 name
, arglist
, &list
, &all_list
);
10454 n
= TREE_VEC_LENGTH
(basetype_vec
);
10455 for
(i
= 1; i
< n
; i
++)
10457 tree t
= BINFO_TYPE
(TREE_VEC_ELT
(basetype_vec
, i
));
10460 rlist
= find_applicable_accessible_methods_list
(lc
, t
, name
,
10462 list
= chainon
(rlist
, list
);
10465 /* Search classes */
10469 int seen_inner_class
= 0;
10470 search_applicable_methods_list
(lc
, TYPE_METHODS
(class
),
10471 name
, arglist
, &list
, &all_list
);
10473 /* When looking finit$ or class$, we turn LC to 1 so that we
10474 only search in class. Note that we should have found
10475 something at this point. */
10476 if
(ID_FINIT_P
(name
) || ID_CLASSDOLLAR_P
(name
))
10483 /* We must search all interfaces of this class */
10486 tree basetype_vec
= TYPE_BINFO_BASETYPES
(sc
);
10487 int n
= TREE_VEC_LENGTH
(basetype_vec
), i
;
10488 for
(i
= 1; i
< n
; i
++)
10490 tree t
= BINFO_TYPE
(TREE_VEC_ELT
(basetype_vec
, i
));
10491 if
(t
!= object_type_node
)
10494 = find_applicable_accessible_methods_list
(lc
, t
,
10496 list
= chainon
(rlist
, list
);
10501 /* Search enclosing context of inner classes before looking
10503 while
(!lc
&& INNER_CLASS_TYPE_P
(class
))
10506 seen_inner_class
= 1;
10507 class
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(class
)));
10508 rlist
= find_applicable_accessible_methods_list
(lc
, class
,
10510 list
= chainon
(rlist
, list
);
10513 if
(!lc
&& seen_inner_class
10514 && TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(sc
))) == CLASSTYPE_SUPER
(sc
))
10515 class
= CLASSTYPE_SUPER
(sc
);
10519 /* Search superclass */
10520 if
(!lc
&& CLASSTYPE_SUPER
(class
) != NULL_TREE
)
10523 class
= CLASSTYPE_SUPER
(class
);
10524 rlist
= find_applicable_accessible_methods_list
(lc
, class
,
10526 list
= chainon
(rlist
, list
);
10532 /* We're done. Reset the searched classes list and finally search
10533 java.lang.Object if it wasn't searched already. */
10534 if
(!search_not_done
)
10537 && TYPE_METHODS
(object_type_node
)
10538 && !hash_lookup
(searched_classes
,
10539 (const hash_table_key
) object_type_node
,
10542 search_applicable_methods_list
(lc
,
10543 TYPE_METHODS
(object_type_node
),
10544 name
, arglist
, &list
, &all_list
);
10546 hash_table_free
(searched_classes
);
10547 searched_classes
= NULL
;
10550 /* Either return the list obtained or all selected (but
10551 inaccessible) methods for better error report. */
10552 return
(!list ? all_list
: list
);
10555 /* Effectively search for the appropriate method in method */
10558 search_applicable_methods_list
(lc
, method
, name
, arglist
, list
, all_list
)
10560 tree method
, name
, arglist
;
10561 tree
*list
, *all_list
;
10563 for
(; method
; method
= TREE_CHAIN
(method
))
10565 /* When dealing with constructor, stop here, otherwise search
10567 if
(lc
&& !DECL_CONSTRUCTOR_P
(method
))
10569 else if
(!lc
&& (DECL_CONSTRUCTOR_P
(method
)
10570 ||
(DECL_NAME
(method
) != name
)))
10573 if
(argument_types_convertible
(method
, arglist
))
10575 /* Retain accessible methods only */
10576 if
(!not_accessible_p
(DECL_CONTEXT
(current_function_decl
),
10577 method
, NULL_TREE
, 0))
10578 *list
= tree_cons
(NULL_TREE
, method
, *list
);
10580 /* Also retain all selected method here */
10581 *all_list
= tree_cons
(NULL_TREE
, method
, *list
);
10586 /* 15.11.2.2 Choose the Most Specific Method */
10589 find_most_specific_methods_list
(list
)
10593 int abstract
, candidates
;
10594 tree current
, new_list
= NULL_TREE
;
10595 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
10598 DECL_SPECIFIC_COUNT
(TREE_VALUE
(current
)) = 0;
10600 for
(method
= list
; method
; method
= TREE_CHAIN
(method
))
10602 tree method_v
, current_v
;
10603 /* Don't test a method against itself */
10604 if
(method
== current
)
10607 method_v
= TREE_VALUE
(method
);
10608 current_v
= TREE_VALUE
(current
);
10610 /* Compare arguments and location where methods where declared */
10611 if
(argument_types_convertible
(method_v
, current_v
))
10613 if
(valid_method_invocation_conversion_p
10614 (DECL_CONTEXT
(method_v
), DECL_CONTEXT
(current_v
))
10615 ||
(INNER_CLASS_TYPE_P
(DECL_CONTEXT
(current_v
))
10616 && enclosing_context_p
(DECL_CONTEXT
(method_v
),
10617 DECL_CONTEXT
(current_v
))))
10619 int v
= (DECL_SPECIFIC_COUNT
(current_v
) +=
10620 (INNER_CLASS_TYPE_P
(DECL_CONTEXT
(current_v
)) ?
2 : 1));
10621 max
= (v
> max ? v
: max
);
10627 /* Review the list and select the maximally specific methods */
10628 for
(current
= list
, abstract
= -1, candidates
= -1;
10629 current
; current
= TREE_CHAIN
(current
))
10630 if
(DECL_SPECIFIC_COUNT
(TREE_VALUE
(current
)) == max
)
10632 new_list
= tree_cons
(NULL_TREE
, TREE_VALUE
(current
), new_list
);
10633 abstract
+= (METHOD_ABSTRACT
(TREE_VALUE
(current
)) ?
1 : 0);
10637 /* If we have several and they're all abstract, just pick the
10639 if
(candidates
> 0 && (candidates
== abstract
))
10641 new_list
= nreverse
(new_list
);
10642 TREE_CHAIN
(new_list
) = NULL_TREE
;
10645 /* We have several (we couldn't find a most specific), all but one
10646 are abstract, we pick the only non abstract one. */
10647 if
(candidates
> 0 && (candidates
== abstract
+1))
10649 for
(current
= new_list
; current
; current
= TREE_CHAIN
(current
))
10650 if
(!METHOD_ABSTRACT
(TREE_VALUE
(current
)))
10652 TREE_CHAIN
(current
) = NULL_TREE
;
10653 new_list
= current
;
10657 /* If we can't find one, lower expectations and try to gather multiple
10658 maximally specific methods */
10659 while
(!new_list
&& max
)
10663 if
(DECL_SPECIFIC_COUNT
(TREE_VALUE
(current
)) == max
)
10664 new_list
= tree_cons
(NULL_TREE
, TREE_VALUE
(current
), new_list
);
10671 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
10672 converted by method invocation conversion (5.3) to the type of the
10673 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
10674 to change less often than M1. */
10677 argument_types_convertible
(m1
, m2_or_arglist
)
10678 tree m1
, m2_or_arglist
;
10680 static tree m2_arg_value
= NULL_TREE
;
10681 static tree m2_arg_cache
= NULL_TREE
;
10682 static int initialized_p
;
10684 register tree m1_arg
, m2_arg
;
10686 /* Register M2_ARG_VALUE and M2_ARG_CACHE with the garbage
10688 if
(!initialized_p
)
10690 ggc_add_tree_root
(&m2_arg_value
, 1);
10691 ggc_add_tree_root
(&m2_arg_cache
, 1);
10695 SKIP_THIS_AND_ARTIFICIAL_PARMS
(m1_arg
, m1
)
10697 if
(m2_arg_value
== m2_or_arglist
)
10698 m2_arg
= m2_arg_cache
;
10701 /* M2_OR_ARGLIST can be a function DECL or a raw list of
10703 if
(m2_or_arglist
&& TREE_CODE
(m2_or_arglist
) == FUNCTION_DECL
)
10705 m2_arg
= TYPE_ARG_TYPES
(TREE_TYPE
(m2_or_arglist
));
10706 if
(!METHOD_STATIC
(m2_or_arglist
))
10707 m2_arg
= TREE_CHAIN
(m2_arg
);
10710 m2_arg
= m2_or_arglist
;
10712 m2_arg_value
= m2_or_arglist
;
10713 m2_arg_cache
= m2_arg
;
10716 while
(m1_arg
!= end_params_node
&& m2_arg
!= end_params_node
)
10718 resolve_and_layout
(TREE_VALUE
(m1_arg
), NULL_TREE
);
10719 if
(!valid_method_invocation_conversion_p
(TREE_VALUE
(m1_arg
),
10720 TREE_VALUE
(m2_arg
)))
10722 m1_arg
= TREE_CHAIN
(m1_arg
);
10723 m2_arg
= TREE_CHAIN
(m2_arg
);
10725 return m1_arg
== end_params_node
&& m2_arg
== end_params_node
;
10728 /* Qualification routines */
10731 qualify_ambiguous_name
(id
)
10734 tree qual
, qual_wfl
, name
= NULL_TREE
, decl
, ptr_type
= NULL_TREE
,
10735 saved_current_class
;
10736 int again
, super_found
= 0, this_found
= 0, new_array_found
= 0;
10739 /* We first qualify the first element, then derive qualification of
10740 others based on the first one. If the first element is qualified
10741 by a resolution (field or type), this resolution is stored in the
10742 QUAL_RESOLUTION of the qual element being examined. We need to
10743 save the current_class since the use of SUPER might change the
10745 saved_current_class
= current_class
;
10746 qual
= EXPR_WFL_QUALIFICATION
(id
);
10749 /* Simple qualified expression feature a qual_wfl that is a
10750 WFL. Expression derived from a primary feature more complicated
10751 things like a CALL_EXPR. Expression from primary need to be
10752 worked out to extract the part on which the qualification will
10754 qual_wfl
= QUAL_WFL
(qual
);
10755 switch
(TREE_CODE
(qual_wfl
))
10758 qual_wfl
= TREE_OPERAND
(qual_wfl
, 0);
10759 if
(TREE_CODE
(qual_wfl
) != EXPR_WITH_FILE_LOCATION
)
10761 qual
= EXPR_WFL_QUALIFICATION
(qual_wfl
);
10762 qual_wfl
= QUAL_WFL
(qual
);
10765 case NEW_ARRAY_EXPR
:
10766 case NEW_ANONYMOUS_ARRAY_EXPR
:
10767 qual
= TREE_CHAIN
(qual
);
10768 again
= new_array_found
= 1;
10772 case NEW_CLASS_EXPR
:
10773 qual_wfl
= TREE_OPERAND
(qual_wfl
, 0);
10776 while
(TREE_CODE
(qual_wfl
) == ARRAY_REF
)
10777 qual_wfl
= TREE_OPERAND
(qual_wfl
, 0);
10780 qual
= TREE_CHAIN
(qual
);
10781 qual_wfl
= QUAL_WFL
(qual
);
10783 case CLASS_LITERAL
:
10784 qual
= TREE_CHAIN
(qual
);
10785 qual_wfl
= QUAL_WFL
(qual
);
10788 /* Fix for -Wall. Just break doing nothing */
10792 ptr_type
= current_class
;
10794 code
= TREE_CODE
(qual_wfl
);
10796 /* Pos evaluation: non WFL leading expression nodes */
10797 if
(code
== CONVERT_EXPR
10798 && TREE_CODE
(TREE_TYPE
(qual_wfl
)) == EXPR_WITH_FILE_LOCATION
)
10799 name
= EXPR_WFL_NODE
(TREE_TYPE
(qual_wfl
));
10801 else if
(code
== INTEGER_CST
)
10804 else if
((code
== ARRAY_REF || code
== CALL_EXPR || code
== MODIFY_EXPR
) &&
10805 TREE_CODE
(TREE_OPERAND
(qual_wfl
, 0)) == EXPR_WITH_FILE_LOCATION
)
10806 name
= EXPR_WFL_NODE
(TREE_OPERAND
(qual_wfl
, 0));
10808 else if
(code
== TREE_LIST
)
10809 name
= EXPR_WFL_NODE
(TREE_PURPOSE
(qual_wfl
));
10811 else if
(code
== STRING_CST || code
== CONDITIONAL_EXPR
10812 || code
== PLUS_EXPR
)
10814 qual
= TREE_CHAIN
(qual
);
10815 qual_wfl
= QUAL_WFL
(qual
);
10820 name
= EXPR_WFL_NODE
(qual_wfl
);
10823 qual
= EXPR_WFL_QUALIFICATION
(qual_wfl
);
10828 /* If we have a THIS (from a primary), we set the context accordingly */
10829 if
(name
== this_identifier_node
)
10831 /* This isn't really elegant. One more added irregularity
10832 before I start using COMPONENT_REF (hopefully very soon.) */
10833 if
(TREE_CODE
(TREE_PURPOSE
(qual
)) == ARRAY_REF
10834 && TREE_CODE
(TREE_OPERAND
(TREE_PURPOSE
(qual
), 0)) ==
10835 EXPR_WITH_FILE_LOCATION
10836 && EXPR_WFL_NODE
(TREE_OPERAND
(TREE_PURPOSE
(qual
), 0)) ==
10837 this_identifier_node
)
10839 qual
= TREE_OPERAND
(TREE_PURPOSE
(qual
), 0);
10840 qual
= EXPR_WFL_QUALIFICATION
(qual
);
10842 qual
= TREE_CHAIN
(qual
);
10843 qual_wfl
= QUAL_WFL
(qual
);
10844 if
(TREE_CODE
(qual_wfl
) == CALL_EXPR
)
10847 name
= EXPR_WFL_NODE
(qual_wfl
);
10850 /* If we have a SUPER, we set the context accordingly */
10851 if
(name
== super_identifier_node
)
10853 current_class
= CLASSTYPE_SUPER
(ptr_type
);
10854 /* Check that there is such a thing as a super class. If not,
10855 return. The error will be caught later on, during the
10857 if
(!current_class
)
10859 current_class
= saved_current_class
;
10862 qual
= TREE_CHAIN
(qual
);
10863 /* Do one more interation to set things up */
10864 super_found
= again
= 1;
10868 /* If name appears within the scope of a local variable declaration
10869 or parameter declaration, then it is an expression name. We don't
10870 carry this test out if we're in the context of the use of SUPER
10872 if
(!this_found
&& !super_found
10873 && TREE_CODE
(name
) != STRING_CST
&& TREE_CODE
(name
) != INTEGER_CST
10874 && (decl
= IDENTIFIER_LOCAL_VALUE
(name
)))
10876 RESOLVE_EXPRESSION_NAME_P
(qual_wfl
) = 1;
10877 QUAL_RESOLUTION
(qual
) = decl
;
10880 /* If within the class/interface NAME was found to be used there
10881 exists a (possibly inherited) field named NAME, then this is an
10882 expression name. If we saw a NEW_ARRAY_EXPR before and want to
10883 address length, it is OK. */
10884 else if
((decl
= lookup_field_wrapper
(ptr_type
, name
))
10885 || name
== length_identifier_node
)
10887 RESOLVE_EXPRESSION_NAME_P
(qual_wfl
) = 1;
10888 QUAL_RESOLUTION
(qual
) = (new_array_found ? NULL_TREE
: decl
);
10891 /* We reclassify NAME as yielding to a type name resolution if:
10892 - NAME is a class/interface declared within the compilation
10893 unit containing NAME,
10894 - NAME is imported via a single-type-import declaration,
10895 - NAME is declared in an another compilation unit of the package
10896 of the compilation unit containing NAME,
10897 - NAME is declared by exactly on type-import-on-demand declaration
10898 of the compilation unit containing NAME.
10899 - NAME is actually a STRING_CST. */
10900 else if
(TREE_CODE
(name
) == STRING_CST || TREE_CODE
(name
) == INTEGER_CST
10901 ||
(decl
= resolve_and_layout
(name
, NULL_TREE
)))
10903 RESOLVE_TYPE_NAME_P
(qual_wfl
) = 1;
10904 QUAL_RESOLUTION
(qual
) = decl
;
10907 /* Method call, array references and cast are expression name */
10908 else if
(TREE_CODE
(QUAL_WFL
(qual
)) == CALL_EXPR
10909 || TREE_CODE
(QUAL_WFL
(qual
)) == ARRAY_REF
10910 || TREE_CODE
(QUAL_WFL
(qual
)) == CONVERT_EXPR
10911 || TREE_CODE
(QUAL_WFL
(qual
)) == MODIFY_EXPR
)
10912 RESOLVE_EXPRESSION_NAME_P
(qual_wfl
) = 1;
10914 /* Check here that NAME isn't declared by more than one
10915 type-import-on-demand declaration of the compilation unit
10916 containing NAME. FIXME */
10918 /* Otherwise, NAME is reclassified as a package name */
10920 RESOLVE_PACKAGE_NAME_P
(qual_wfl
) = 1;
10922 /* Propagate the qualification accross other components of the
10924 for
(qual
= TREE_CHAIN
(qual
); qual
;
10925 qual_wfl
= QUAL_WFL
(qual
), qual
= TREE_CHAIN
(qual
))
10927 if
(RESOLVE_PACKAGE_NAME_P
(qual_wfl
))
10928 RESOLVE_PACKAGE_NAME_P
(QUAL_WFL
(qual
)) = 1;
10930 RESOLVE_EXPRESSION_NAME_P
(QUAL_WFL
(qual
)) = 1;
10933 /* Store the global qualification for the ambiguous part of ID back
10935 if
(RESOLVE_EXPRESSION_NAME_P
(qual_wfl
))
10936 RESOLVE_EXPRESSION_NAME_P
(id
) = 1;
10937 else if
(RESOLVE_TYPE_NAME_P
(qual_wfl
))
10938 RESOLVE_TYPE_NAME_P
(id
) = 1;
10939 else if
(RESOLVE_PACKAGE_NAME_P
(qual_wfl
))
10940 RESOLVE_PACKAGE_NAME_P
(id
) = 1;
10942 /* Restore the current class */
10943 current_class
= saved_current_class
;
10947 breakdown_qualified
(left
, right
, source
)
10948 tree
*left
, *right
, source
;
10951 int l
= IDENTIFIER_LENGTH
(source
);
10953 base
= alloca
(l
+ 1);
10954 memcpy
(base
, IDENTIFIER_POINTER
(source
), l
+ 1);
10956 /* Breakdown NAME into REMAINDER . IDENTIFIER */
10958 while
(*p
!= '.' && p
!= base
)
10961 /* We didn't find a '.'. Return an error */
10967 *right
= get_identifier
(p
+1);
10968 *left
= get_identifier
(base
);
10973 /* Return TRUE if two classes are from the same package. */
10976 in_same_package
(name1
, name2
)
10983 if
(TREE_CODE
(name1
) == TYPE_DECL
)
10984 name1
= DECL_NAME
(name1
);
10985 if
(TREE_CODE
(name2
) == TYPE_DECL
)
10986 name2
= DECL_NAME
(name2
);
10988 if
(QUALIFIED_P
(name1
) != QUALIFIED_P
(name2
))
10989 /* One in empty package. */
10992 if
(QUALIFIED_P
(name1
) == 0 && QUALIFIED_P
(name2
) == 0)
10993 /* Both in empty package. */
10996 breakdown_qualified
(&pkg1
, &tmp
, name1
);
10997 breakdown_qualified
(&pkg2
, &tmp
, name2
);
10999 return
(pkg1
== pkg2
);
11002 /* Patch tree nodes in a function body. When a BLOCK is found, push
11003 local variable decls if present.
11004 Same as java_complete_lhs, but does resolve static finals to values. */
11007 java_complete_tree
(node
)
11010 node
= java_complete_lhs
(node
);
11011 if
(JDECL_P
(node
) && CLASS_FINAL_VARIABLE_P
(node
)
11012 && DECL_INITIAL
(node
) != NULL_TREE
11013 && !flag_emit_xref
)
11015 tree value
= DECL_INITIAL
(node
);
11016 DECL_INITIAL
(node
) = NULL_TREE
;
11017 value
= fold_constant_for_init
(value
, node
);
11018 DECL_INITIAL
(node
) = value
;
11019 if
(value
!= NULL_TREE
)
11021 /* fold_constant_for_init sometimes widen the original type
11022 of the constant (i.e. byte to int.) It's not desirable,
11023 especially if NODE is a function argument. */
11024 if
(TREE_CODE
(value
) == INTEGER_CST
11025 && TREE_TYPE
(node
) != TREE_TYPE
(value
))
11026 return convert
(TREE_TYPE
(node
), value
);
11031 DECL_FIELD_FINAL_IUD
(node
) = 0;
11037 java_stabilize_reference
(node
)
11040 if
(TREE_CODE
(node
) == COMPOUND_EXPR
)
11042 tree op0
= TREE_OPERAND
(node
, 0);
11043 tree op1
= TREE_OPERAND
(node
, 1);
11044 TREE_OPERAND
(node
, 0) = save_expr
(op0
);
11045 TREE_OPERAND
(node
, 1) = java_stabilize_reference
(op1
);
11048 return stabilize_reference
(node
);
11051 /* Patch tree nodes in a function body. When a BLOCK is found, push
11052 local variable decls if present.
11053 Same as java_complete_tree, but does not resolve static finals to values. */
11056 java_complete_lhs
(node
)
11059 tree nn
, cn
, wfl_op1
, wfl_op2
, wfl_op3
;
11062 /* CONVERT_EXPR always has its type set, even though it needs to be
11064 if
(TREE_TYPE
(node
) && TREE_CODE
(node
) != CONVERT_EXPR
)
11067 /* The switch block implements cases processing container nodes
11068 first. Contained nodes are always written back. Leaves come
11069 next and return a value. */
11070 switch
(TREE_CODE
(node
))
11074 /* 1- Block section.
11075 Set the local values on decl names so we can identify them
11076 faster when they're referenced. At that stage, identifiers
11077 are legal so we don't check for declaration errors. */
11078 for
(cn
= BLOCK_EXPR_DECLS
(node
); cn
; cn
= TREE_CHAIN
(cn
))
11080 DECL_CONTEXT
(cn
) = current_function_decl
;
11081 IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(cn
)) = cn
;
11083 if
(BLOCK_EXPR_BODY
(node
) == NULL_TREE
)
11084 CAN_COMPLETE_NORMALLY
(node
) = 1;
11087 tree stmt
= BLOCK_EXPR_BODY
(node
);
11089 int error_seen
= 0;
11090 if
(TREE_CODE
(stmt
) == COMPOUND_EXPR
)
11092 /* Re-order from (((A; B); C); ...; Z) to
11093 (A; (B; (C ; (...; Z)))).
11094 This makes it easier to scan the statements left-to-right
11095 without using recursion (which might overflow the stack
11096 if the block has many statements. */
11099 tree left
= TREE_OPERAND
(stmt
, 0);
11100 if
(TREE_CODE
(left
) != COMPOUND_EXPR
)
11102 TREE_OPERAND
(stmt
, 0) = TREE_OPERAND
(left
, 1);
11103 TREE_OPERAND
(left
, 1) = stmt
;
11106 BLOCK_EXPR_BODY
(node
) = stmt
;
11109 /* Now do the actual complete, without deep recursion for
11111 ptr
= &BLOCK_EXPR_BODY
(node
);
11112 while
(TREE_CODE
(*ptr
) == COMPOUND_EXPR
11113 && TREE_OPERAND
(*ptr
, 1) != empty_stmt_node
)
11115 tree cur
= java_complete_tree
(TREE_OPERAND
(*ptr
, 0));
11116 tree
*next
= &TREE_OPERAND
(*ptr
, 1);
11117 TREE_OPERAND
(*ptr
, 0) = cur
;
11118 if
(cur
== empty_stmt_node
)
11120 /* Optimization; makes it easier to detect empty bodies.
11121 Most useful for <clinit> with all-constant initializer. */
11125 if
(TREE_CODE
(cur
) == ERROR_MARK
)
11127 else if
(! CAN_COMPLETE_NORMALLY
(cur
))
11132 if
(TREE_CODE
(wfl_op2
) == BLOCK
)
11133 wfl_op2
= BLOCK_EXPR_BODY
(wfl_op2
);
11134 else if
(TREE_CODE
(wfl_op2
) == COMPOUND_EXPR
)
11135 wfl_op2
= TREE_OPERAND
(wfl_op2
, 0);
11139 if
(TREE_CODE
(wfl_op2
) != CASE_EXPR
11140 && TREE_CODE
(wfl_op2
) != DEFAULT_EXPR
)
11141 unreachable_stmt_error
(*ptr
);
11145 *ptr
= java_complete_tree
(*ptr
);
11147 if
(TREE_CODE
(*ptr
) == ERROR_MARK || error_seen
> 0)
11148 return error_mark_node
;
11149 CAN_COMPLETE_NORMALLY
(node
) = CAN_COMPLETE_NORMALLY
(*ptr
);
11151 /* Turn local bindings to null */
11152 for
(cn
= BLOCK_EXPR_DECLS
(node
); cn
; cn
= TREE_CHAIN
(cn
))
11153 IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(cn
)) = NULL_TREE
;
11155 TREE_TYPE
(node
) = void_type_node
;
11158 /* 2- They are expressions but ultimately deal with statements */
11161 wfl_op1
= TREE_OPERAND
(node
, 0);
11162 COMPLETE_CHECK_OP_0
(node
);
11163 /* 14.19 A throw statement cannot complete normally. */
11164 CAN_COMPLETE_NORMALLY
(node
) = 0;
11165 return patch_throw_statement
(node
, wfl_op1
);
11167 case SYNCHRONIZED_EXPR
:
11168 wfl_op1
= TREE_OPERAND
(node
, 0);
11169 return patch_synchronized_statement
(node
, wfl_op1
);
11172 return patch_try_statement
(node
);
11174 case TRY_FINALLY_EXPR
:
11175 COMPLETE_CHECK_OP_0
(node
);
11176 COMPLETE_CHECK_OP_1
(node
);
11177 if
(TREE_OPERAND
(node
, 0) == empty_stmt_node
)
11178 return TREE_OPERAND
(node
, 1);
11179 if
(TREE_OPERAND
(node
, 1) == empty_stmt_node
)
11180 return TREE_OPERAND
(node
, 0);
11181 CAN_COMPLETE_NORMALLY
(node
)
11182 = (CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 0))
11183 && CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1)));
11184 TREE_TYPE
(node
) = TREE_TYPE
(TREE_OPERAND
(node
, 0));
11187 case CLEANUP_POINT_EXPR
:
11188 COMPLETE_CHECK_OP_0
(node
);
11189 TREE_TYPE
(node
) = void_type_node
;
11190 CAN_COMPLETE_NORMALLY
(node
) =
11191 CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 0));
11194 case WITH_CLEANUP_EXPR
:
11195 COMPLETE_CHECK_OP_0
(node
);
11196 COMPLETE_CHECK_OP_2
(node
);
11197 CAN_COMPLETE_NORMALLY
(node
) =
11198 CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 0));
11199 TREE_TYPE
(node
) = void_type_node
;
11202 case LABELED_BLOCK_EXPR
:
11203 PUSH_LABELED_BLOCK
(node
);
11204 if
(LABELED_BLOCK_BODY
(node
))
11205 COMPLETE_CHECK_OP_1
(node
);
11206 TREE_TYPE
(node
) = void_type_node
;
11207 POP_LABELED_BLOCK
();
11209 if
(LABELED_BLOCK_BODY
(node
) == empty_stmt_node
)
11211 LABELED_BLOCK_BODY
(node
) = NULL_TREE
;
11212 CAN_COMPLETE_NORMALLY
(node
) = 1;
11214 else if
(CAN_COMPLETE_NORMALLY
(LABELED_BLOCK_BODY
(node
)))
11215 CAN_COMPLETE_NORMALLY
(node
) = 1;
11218 case EXIT_BLOCK_EXPR
:
11219 /* We don't complete operand 1, because it's the return value of
11220 the EXIT_BLOCK_EXPR which doesn't exist it Java */
11221 return patch_bc_statement
(node
);
11224 cn
= java_complete_tree
(TREE_OPERAND
(node
, 0));
11225 if
(cn
== error_mark_node
)
11228 /* First, the case expression must be constant. Values of final
11229 fields are accepted. */
11231 if
((TREE_CODE
(cn
) == COMPOUND_EXPR || TREE_CODE
(cn
) == COMPONENT_REF
)
11232 && JDECL_P
(TREE_OPERAND
(cn
, 1))
11233 && FIELD_FINAL
(TREE_OPERAND
(cn
, 1))
11234 && DECL_INITIAL
(TREE_OPERAND
(cn
, 1)))
11236 cn
= fold_constant_for_init
(DECL_INITIAL
(TREE_OPERAND
(cn
, 1)),
11237 TREE_OPERAND
(cn
, 1));
11240 if
(!TREE_CONSTANT
(cn
) && !flag_emit_xref
)
11242 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11243 parse_error_context
(node
, "Constant expression required");
11244 return error_mark_node
;
11247 nn
= ctxp
->current_loop
;
11249 /* It must be assignable to the type of the switch expression. */
11250 if
(!try_builtin_assignconv
(NULL_TREE
,
11251 TREE_TYPE
(TREE_OPERAND
(nn
, 0)), cn
))
11253 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11254 parse_error_context
11256 "Incompatible type for case. Can't convert `%s' to `int'",
11257 lang_printable_name
(TREE_TYPE
(cn
), 0));
11258 return error_mark_node
;
11261 cn
= fold
(convert
(int_type_node
, cn
));
11263 /* Multiple instance of a case label bearing the same
11264 value is checked during code generation. The case
11265 expression is allright so far. */
11266 if
(TREE_CODE
(cn
) == VAR_DECL
)
11267 cn
= DECL_INITIAL
(cn
);
11268 TREE_OPERAND
(node
, 0) = cn
;
11269 TREE_TYPE
(node
) = void_type_node
;
11270 CAN_COMPLETE_NORMALLY
(node
) = 1;
11271 TREE_SIDE_EFFECTS
(node
) = 1;
11275 nn
= ctxp
->current_loop
;
11276 /* Only one default label is allowed per switch statement */
11277 if
(SWITCH_HAS_DEFAULT
(nn
))
11279 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11280 parse_error_context
(wfl_operator
,
11281 "Duplicate case label: `default'");
11282 return error_mark_node
;
11285 SWITCH_HAS_DEFAULT
(nn
) = 1;
11286 TREE_TYPE
(node
) = void_type_node
;
11287 TREE_SIDE_EFFECTS
(node
) = 1;
11288 CAN_COMPLETE_NORMALLY
(node
) = 1;
11294 /* Check whether the loop was enclosed in a labeled
11295 statement. If not, create one, insert the loop in it and
11297 nn
= patch_loop_statement
(node
);
11299 /* Anyways, walk the body of the loop */
11300 if
(TREE_CODE
(node
) == LOOP_EXPR
)
11301 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11302 /* Switch statement: walk the switch expression and the cases */
11304 node
= patch_switch_statement
(node
);
11306 if
(node
== error_mark_node || TREE_OPERAND
(node
, 0) == error_mark_node
)
11307 nn
= error_mark_node
;
11310 TREE_TYPE
(nn
) = TREE_TYPE
(node
) = void_type_node
;
11311 /* If we returned something different, that's because we
11312 inserted a label. Pop the label too. */
11315 if
(CAN_COMPLETE_NORMALLY
(node
))
11316 CAN_COMPLETE_NORMALLY
(nn
) = 1;
11317 POP_LABELED_BLOCK
();
11324 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11325 return patch_exit_expr
(node
);
11329 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11330 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
11331 return error_mark_node
;
11332 /* then-else branches */
11333 TREE_OPERAND
(node
, 1) = java_complete_tree
(TREE_OPERAND
(node
, 1));
11334 if
(TREE_OPERAND
(node
, 1) == error_mark_node
)
11335 return error_mark_node
;
11336 TREE_OPERAND
(node
, 2) = java_complete_tree
(TREE_OPERAND
(node
, 2));
11337 if
(TREE_OPERAND
(node
, 2) == error_mark_node
)
11338 return error_mark_node
;
11339 return patch_if_else_statement
(node
);
11342 case CONDITIONAL_EXPR
:
11344 wfl_op1
= TREE_OPERAND
(node
, 0);
11345 COMPLETE_CHECK_OP_0
(node
);
11346 wfl_op2
= TREE_OPERAND
(node
, 1);
11347 COMPLETE_CHECK_OP_1
(node
);
11348 wfl_op3
= TREE_OPERAND
(node
, 2);
11349 COMPLETE_CHECK_OP_2
(node
);
11350 return patch_conditional_expr
(node
, wfl_op1
, wfl_op2
);
11352 /* 3- Expression section */
11353 case COMPOUND_EXPR
:
11354 wfl_op2
= TREE_OPERAND
(node
, 1);
11355 TREE_OPERAND
(node
, 0) = nn
=
11356 java_complete_tree
(TREE_OPERAND
(node
, 0));
11357 if
(wfl_op2
== empty_stmt_node
)
11358 CAN_COMPLETE_NORMALLY
(node
) = CAN_COMPLETE_NORMALLY
(nn
);
11361 if
(! CAN_COMPLETE_NORMALLY
(nn
) && TREE_CODE
(nn
) != ERROR_MARK
)
11363 /* An unreachable condition in a do-while statement
11364 is *not* (technically) an unreachable statement. */
11366 if
(TREE_CODE
(nn
) == EXPR_WITH_FILE_LOCATION
)
11367 nn
= EXPR_WFL_NODE
(nn
);
11368 if
(TREE_CODE
(nn
) != EXIT_EXPR
)
11370 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op2
);
11371 parse_error_context
(wfl_operator
, "Unreachable statement");
11374 TREE_OPERAND
(node
, 1) = java_complete_tree
(TREE_OPERAND
(node
, 1));
11375 if
(TREE_OPERAND
(node
, 1) == error_mark_node
)
11376 return error_mark_node
;
11377 CAN_COMPLETE_NORMALLY
(node
)
11378 = CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1));
11380 TREE_TYPE
(node
) = TREE_TYPE
(TREE_OPERAND
(node
, 1));
11384 /* CAN_COMPLETE_NORMALLY (node) = 0; */
11385 return patch_return
(node
);
11387 case EXPR_WITH_FILE_LOCATION
:
11388 if
(!EXPR_WFL_NODE
(node
) /* Or a PRIMARY flag ? */
11389 || TREE_CODE
(EXPR_WFL_NODE
(node
)) == IDENTIFIER_NODE
)
11392 node
= resolve_expression_name
(node
, NULL
);
11393 if
(node
== error_mark_node
)
11395 /* Keep line number information somewhere were it doesn't
11396 disrupt the completion process. */
11397 if
(flag_emit_xref
&& TREE_CODE
(node
) != CALL_EXPR
)
11399 EXPR_WFL_NODE
(wfl
) = TREE_OPERAND
(node
, 1);
11400 TREE_OPERAND
(node
, 1) = wfl
;
11402 CAN_COMPLETE_NORMALLY
(node
) = 1;
11407 int save_lineno
= lineno
;
11408 lineno
= EXPR_WFL_LINENO
(node
);
11409 body
= java_complete_tree
(EXPR_WFL_NODE
(node
));
11410 lineno
= save_lineno
;
11411 EXPR_WFL_NODE
(node
) = body
;
11412 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(body
);
11413 CAN_COMPLETE_NORMALLY
(node
) = CAN_COMPLETE_NORMALLY
(body
);
11414 if
(body
== empty_stmt_node || TREE_CONSTANT
(body
))
11416 /* Makes it easier to constant fold, detect empty bodies. */
11419 if
(body
== error_mark_node
)
11421 /* Its important for the evaluation of assignment that
11422 this mark on the TREE_TYPE is propagated. */
11423 TREE_TYPE
(node
) = error_mark_node
;
11424 return error_mark_node
;
11427 TREE_TYPE
(node
) = TREE_TYPE
(EXPR_WFL_NODE
(node
));
11432 case NEW_ARRAY_EXPR
:
11433 /* Patch all the dimensions */
11435 for
(cn
= TREE_OPERAND
(node
, 1); cn
; cn
= TREE_CHAIN
(cn
))
11437 int location
= EXPR_WFL_LINECOL
(TREE_VALUE
(cn
));
11438 tree dim
= convert
(int_type_node
,
11439 java_complete_tree
(TREE_VALUE
(cn
)));
11440 if
(dim
== error_mark_node
)
11447 TREE_VALUE
(cn
) = dim
;
11448 /* Setup the location of the current dimension, for
11449 later error report. */
11450 TREE_PURPOSE
(cn
) =
11451 build_expr_wfl
(NULL_TREE
, input_filename
, 0, 0);
11452 EXPR_WFL_LINECOL
(TREE_PURPOSE
(cn
)) = location
;
11455 /* They complete the array creation expression, if no errors
11457 CAN_COMPLETE_NORMALLY
(node
) = 1;
11458 return
(flag ? error_mark_node
11459 : force_evaluation_order
(patch_newarray
(node
)));
11461 case NEW_ANONYMOUS_ARRAY_EXPR
:
11462 /* Create the array type if necessary. */
11463 if
(ANONYMOUS_ARRAY_DIMS_SIG
(node
))
11465 tree type
= ANONYMOUS_ARRAY_BASE_TYPE
(node
);
11466 if
(!(type
= resolve_type_during_patch
(type
)))
11467 return error_mark_node
;
11468 type
= build_array_from_name
(type
, NULL_TREE
,
11469 ANONYMOUS_ARRAY_DIMS_SIG
(node
), NULL
);
11470 ANONYMOUS_ARRAY_BASE_TYPE
(node
) = build_pointer_type
(type
);
11472 node
= patch_new_array_init
(ANONYMOUS_ARRAY_BASE_TYPE
(node
),
11473 ANONYMOUS_ARRAY_INITIALIZER
(node
));
11474 if
(node
== error_mark_node
)
11475 return error_mark_node
;
11476 CAN_COMPLETE_NORMALLY
(node
) = 1;
11479 case NEW_CLASS_EXPR
:
11481 /* Complete function's argument(s) first */
11482 if
(complete_function_arguments
(node
))
11483 return error_mark_node
;
11486 tree decl
, wfl
= TREE_OPERAND
(node
, 0);
11487 int in_this
= CALL_THIS_CONSTRUCTOR_P
(node
);
11488 int from_super
= (EXPR_WFL_NODE
(TREE_OPERAND
(node
, 0)) ==
11489 super_identifier_node
);
11491 node
= patch_method_invocation
(node
, NULL_TREE
, NULL_TREE
,
11492 from_super
, 0, &decl
);
11493 if
(node
== error_mark_node
)
11494 return error_mark_node
;
11496 check_thrown_exceptions
(EXPR_WFL_LINECOL
(node
), decl
);
11497 /* If we call this(...), register signature and positions */
11499 DECL_CONSTRUCTOR_CALLS
(current_function_decl
) =
11500 tree_cons
(wfl
, decl
,
11501 DECL_CONSTRUCTOR_CALLS
(current_function_decl
));
11502 CAN_COMPLETE_NORMALLY
(node
) = 1;
11503 return force_evaluation_order
(node
);
11507 /* Save potential wfls */
11508 wfl_op1
= TREE_OPERAND
(node
, 0);
11509 TREE_OPERAND
(node
, 0) = nn
= java_complete_lhs
(wfl_op1
);
11511 if
(MODIFY_EXPR_FROM_INITIALIZATION_P
(node
)
11512 && TREE_CODE
(nn
) == VAR_DECL
&& TREE_STATIC
(nn
)
11513 && DECL_INITIAL
(nn
) != NULL_TREE
)
11517 value
= fold_constant_for_init
(nn
, nn
);
11519 if
(value
!= NULL_TREE
)
11521 tree type
= TREE_TYPE
(value
);
11522 if
(JPRIMITIVE_TYPE_P
(type
) ||
11523 (type
== string_ptr_type_node
&& ! flag_emit_class_files
))
11524 return empty_stmt_node
;
11526 if
(! flag_emit_class_files
)
11527 DECL_INITIAL
(nn
) = NULL_TREE
;
11528 if
(CLASS_FINAL_VARIABLE_P
(nn
))
11529 DECL_FIELD_FINAL_IUD
(nn
) = 0;
11531 wfl_op2
= TREE_OPERAND
(node
, 1);
11533 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
11534 return error_mark_node
;
11536 flag
= COMPOUND_ASSIGN_P
(wfl_op2
);
11539 /* This might break when accessing outer field from inner
11540 class. TESTME, FIXME */
11541 tree lvalue
= java_stabilize_reference
(TREE_OPERAND
(node
, 0));
11543 /* Hand stabilize the lhs on both places */
11544 TREE_OPERAND
(node
, 0) = lvalue
;
11545 TREE_OPERAND
(TREE_OPERAND
(node
, 1), 0) =
11546 (flag_emit_class_files ? lvalue
: save_expr
(lvalue
));
11548 /* 15.25.2.a: Left hand is not an array access. FIXME */
11549 /* Now complete the RHS. We write it back later on. */
11550 nn
= java_complete_tree
(TREE_OPERAND
(node
, 1));
11552 if
((cn
= patch_string
(nn
)))
11555 /* The last part of the rewrite for E1 op= E2 is to have
11556 E1 = (T)(E1 op E2), with T being the type of E1. */
11557 nn
= java_complete_tree
(build_cast
(EXPR_WFL_LINECOL
(wfl_op2
),
11558 TREE_TYPE
(lvalue
), nn
));
11560 /* If the assignment is compound and has reference type,
11561 then ensure the LHS has type String and nothing else. */
11562 if
(JREFERENCE_TYPE_P
(TREE_TYPE
(lvalue
))
11563 && ! JSTRING_TYPE_P
(TREE_TYPE
(lvalue
)))
11564 parse_error_context
(wfl_op2
,
11565 "Incompatible type for `+='. Can't convert `%s' to `java.lang.String'",
11566 lang_printable_name
(TREE_TYPE
(lvalue
), 0));
11568 /* 15.25.2.b: Left hand is an array access. FIXME */
11571 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
11572 function to complete this RHS. Note that a NEW_ARRAY_INIT
11573 might have been already fully expanded if created as a result
11574 of processing an anonymous array initializer. We avoid doing
11575 the operation twice by testing whether the node already bears
11577 else if
(TREE_CODE
(wfl_op2
) == NEW_ARRAY_INIT
&& !TREE_TYPE
(wfl_op2
))
11578 nn
= patch_new_array_init
(TREE_TYPE
(TREE_OPERAND
(node
, 0)),
11579 TREE_OPERAND
(node
, 1));
11580 /* Otherwise we simply complete the RHS */
11582 nn
= java_complete_tree
(TREE_OPERAND
(node
, 1));
11584 if
(nn
== error_mark_node
)
11585 return error_mark_node
;
11587 /* Write back the RHS as we evaluated it. */
11588 TREE_OPERAND
(node
, 1) = nn
;
11590 /* In case we're handling = with a String as a RHS, we need to
11591 produce a String out of the RHS (it might still be a
11592 STRING_CST or a StringBuffer at this stage */
11593 if
((nn
= patch_string
(TREE_OPERAND
(node
, 1))))
11594 TREE_OPERAND
(node
, 1) = nn
;
11596 if
((nn
= outer_field_access_fix
(wfl_op1
, TREE_OPERAND
(node
, 0),
11597 TREE_OPERAND
(node
, 1))))
11599 /* We return error_mark_node if outer_field_access_fix
11600 detects we write into a final. */
11601 if
(nn
== error_mark_node
)
11602 return error_mark_node
;
11607 node
= patch_assignment
(node
, wfl_op1
, wfl_op2
);
11608 /* Reorganize the tree if necessary. */
11609 if
(flag
&& (!JREFERENCE_TYPE_P
(TREE_TYPE
(node
))
11610 || JSTRING_P
(TREE_TYPE
(node
))))
11611 node
= java_refold
(node
);
11614 CAN_COMPLETE_NORMALLY
(node
) = 1;
11626 case TRUNC_MOD_EXPR
:
11627 case TRUNC_DIV_EXPR
:
11629 case TRUTH_ANDIF_EXPR
:
11630 case TRUTH_ORIF_EXPR
:
11637 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
11638 knows how to handle those cases. */
11639 wfl_op1
= TREE_OPERAND
(node
, 0);
11640 wfl_op2
= TREE_OPERAND
(node
, 1);
11642 CAN_COMPLETE_NORMALLY
(node
) = 1;
11643 /* Don't complete string nodes if dealing with the PLUS operand. */
11644 if
(TREE_CODE
(node
) != PLUS_EXPR ||
!JSTRING_P
(wfl_op1
))
11646 nn
= java_complete_tree
(wfl_op1
);
11647 if
(nn
== error_mark_node
)
11648 return error_mark_node
;
11650 TREE_OPERAND
(node
, 0) = nn
;
11652 if
(TREE_CODE
(node
) != PLUS_EXPR ||
!JSTRING_P
(wfl_op2
))
11654 nn
= java_complete_tree
(wfl_op2
);
11655 if
(nn
== error_mark_node
)
11656 return error_mark_node
;
11658 TREE_OPERAND
(node
, 1) = nn
;
11660 return force_evaluation_order
(patch_binop
(node
, wfl_op1
, wfl_op2
));
11662 case INSTANCEOF_EXPR
:
11663 wfl_op1
= TREE_OPERAND
(node
, 0);
11664 COMPLETE_CHECK_OP_0
(node
);
11665 if
(flag_emit_xref
)
11667 TREE_TYPE
(node
) = boolean_type_node
;
11670 return patch_binop
(node
, wfl_op1
, TREE_OPERAND
(node
, 1));
11672 case UNARY_PLUS_EXPR
:
11674 case TRUTH_NOT_EXPR
:
11676 case PREDECREMENT_EXPR
:
11677 case PREINCREMENT_EXPR
:
11678 case POSTDECREMENT_EXPR
:
11679 case POSTINCREMENT_EXPR
:
11681 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
11682 how to handle those cases. */
11683 wfl_op1
= TREE_OPERAND
(node
, 0);
11684 CAN_COMPLETE_NORMALLY
(node
) = 1;
11685 TREE_OPERAND
(node
, 0) = java_complete_tree
(wfl_op1
);
11686 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
11687 return error_mark_node
;
11688 node
= patch_unaryop
(node
, wfl_op1
);
11689 CAN_COMPLETE_NORMALLY
(node
) = 1;
11693 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
11694 how to handle those cases. */
11695 wfl_op1
= TREE_OPERAND
(node
, 0);
11696 TREE_OPERAND
(node
, 0) = java_complete_tree
(wfl_op1
);
11697 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
11698 return error_mark_node
;
11699 if
(!flag_emit_class_files
&& !flag_emit_xref
)
11700 TREE_OPERAND
(node
, 0) = save_expr
(TREE_OPERAND
(node
, 0));
11701 /* The same applies to wfl_op2 */
11702 wfl_op2
= TREE_OPERAND
(node
, 1);
11703 TREE_OPERAND
(node
, 1) = java_complete_tree
(wfl_op2
);
11704 if
(TREE_OPERAND
(node
, 1) == error_mark_node
)
11705 return error_mark_node
;
11706 if
(!flag_emit_class_files
&& !flag_emit_xref
)
11707 TREE_OPERAND
(node
, 1) = save_expr
(TREE_OPERAND
(node
, 1));
11708 return patch_array_ref
(node
);
11713 case COMPONENT_REF
:
11714 /* The first step in the re-write of qualified name handling. FIXME.
11715 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
11716 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11717 if
(TREE_CODE
(TREE_OPERAND
(node
, 0)) == RECORD_TYPE
)
11719 tree name
= TREE_OPERAND
(node
, 1);
11720 tree field
= lookup_field_wrapper
(TREE_OPERAND
(node
, 0), name
);
11721 if
(field
== NULL_TREE
)
11723 error ("missing static field `%s'", IDENTIFIER_POINTER
(name
));
11724 return error_mark_node
;
11726 if
(! FIELD_STATIC
(field
))
11728 error ("not a static field `%s'", IDENTIFIER_POINTER
(name
));
11729 return error_mark_node
;
11738 /* Can't use THIS in a static environment */
11741 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11742 parse_error_context
(wfl_operator
,
11743 "Keyword `this' used outside allowed context");
11744 TREE_TYPE
(node
) = error_mark_node
;
11745 return error_mark_node
;
11747 if
(ctxp
->explicit_constructor_p
)
11749 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11750 parse_error_context
11751 (wfl_operator
, "Can't reference `this' or `super' before the superclass constructor has been called");
11752 TREE_TYPE
(node
) = error_mark_node
;
11753 return error_mark_node
;
11755 return current_this
;
11757 case CLASS_LITERAL
:
11758 CAN_COMPLETE_NORMALLY
(node
) = 1;
11759 node
= patch_incomplete_class_ref
(node
);
11760 if
(node
== error_mark_node
)
11761 return error_mark_node
;
11764 case INSTANCE_INITIALIZERS_EXPR
:
11765 in_instance_initializer
++;
11766 node
= java_complete_tree
(TREE_OPERAND
(node
, 0));
11767 in_instance_initializer
--;
11768 if
(node
!= error_mark_node
)
11769 TREE_TYPE
(node
) = void_type_node
;
11771 return error_mark_node
;
11775 CAN_COMPLETE_NORMALLY
(node
) = 1;
11776 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
11777 and it's time to turn it into the appropriate String object */
11778 if
((nn
= patch_string
(node
)))
11781 internal_error
("No case for %s", tree_code_name
[TREE_CODE
(node
)]);
11786 /* Complete function call's argument. Return a non zero value is an
11787 error was found. */
11790 complete_function_arguments
(node
)
11796 ctxp
->explicit_constructor_p
+= (CALL_EXPLICIT_CONSTRUCTOR_P
(node
) ?
1 : 0);
11797 for
(cn
= TREE_OPERAND
(node
, 1); cn
; cn
= TREE_CHAIN
(cn
))
11799 tree wfl
= TREE_VALUE
(cn
), parm
, temp
;
11800 parm
= java_complete_tree
(wfl
);
11802 if
(parm
== error_mark_node
)
11807 /* If have a string literal that we haven't transformed yet or a
11808 crafted string buffer, as a result of use of the the String
11809 `+' operator. Build `parm.toString()' and expand it. */
11810 if
((temp
= patch_string
(parm
)))
11812 /* Inline PRIMTYPE.TYPE read access */
11813 parm
= maybe_build_primttype_type_ref
(parm
, wfl
);
11815 TREE_VALUE
(cn
) = parm
;
11817 ctxp
->explicit_constructor_p
-= (CALL_EXPLICIT_CONSTRUCTOR_P
(node
) ?
1 : 0);
11821 /* Sometimes (for loops and variable initialized during their
11822 declaration), we want to wrap a statement around a WFL and turn it
11826 build_debugable_stmt
(location
, stmt
)
11830 if
(TREE_CODE
(stmt
) != EXPR_WITH_FILE_LOCATION
)
11832 stmt
= build_expr_wfl
(stmt
, input_filename
, 0, 0);
11833 EXPR_WFL_LINECOL
(stmt
) = location
;
11835 JAVA_MAYBE_GENERATE_DEBUG_INFO
(stmt
);
11840 build_expr_block
(body
, decls
)
11843 tree node
= make_node
(BLOCK
);
11844 BLOCK_EXPR_DECLS
(node
) = decls
;
11845 BLOCK_EXPR_BODY
(node
) = body
;
11847 TREE_TYPE
(node
) = TREE_TYPE
(body
);
11848 TREE_SIDE_EFFECTS
(node
) = 1;
11852 /* Create a new function block and link it approriately to current
11853 function block chain */
11858 tree b
= build_expr_block
(NULL_TREE
, NULL_TREE
);
11860 /* Link block B supercontext to the previous block. The current
11861 function DECL is used as supercontext when enter_a_block is called
11862 for the first time for a given function. The current function body
11863 (DECL_FUNCTION_BODY) is set to be block B. */
11865 tree fndecl
= current_function_decl
;
11868 BLOCK_SUPERCONTEXT
(b
) = current_static_block
;
11869 current_static_block
= b
;
11872 else if
(!DECL_FUNCTION_BODY
(fndecl
))
11874 BLOCK_SUPERCONTEXT
(b
) = fndecl
;
11875 DECL_FUNCTION_BODY
(fndecl
) = b
;
11879 BLOCK_SUPERCONTEXT
(b
) = DECL_FUNCTION_BODY
(fndecl
);
11880 DECL_FUNCTION_BODY
(fndecl
) = b
;
11885 /* Exit a block by changing the current function body
11886 (DECL_FUNCTION_BODY) to the current block super context, only if
11887 the block being exited isn't the method's top level one. */
11893 if
(current_function_decl
)
11895 b
= DECL_FUNCTION_BODY
(current_function_decl
);
11896 if
(BLOCK_SUPERCONTEXT
(b
) != current_function_decl
)
11897 DECL_FUNCTION_BODY
(current_function_decl
) = BLOCK_SUPERCONTEXT
(b
);
11901 b
= current_static_block
;
11903 if
(BLOCK_SUPERCONTEXT
(b
))
11904 current_static_block
= BLOCK_SUPERCONTEXT
(b
);
11909 /* Lookup for NAME in the nested function's blocks, all the way up to
11910 the current toplevel one. It complies with Java's local variable
11914 lookup_name_in_blocks
(name
)
11917 tree b
= GET_CURRENT_BLOCK
(current_function_decl
);
11919 while
(b
!= current_function_decl
)
11923 /* Paranoid sanity check. To be removed */
11924 if
(TREE_CODE
(b
) != BLOCK
)
11927 for
(current
= BLOCK_EXPR_DECLS
(b
); current
;
11928 current
= TREE_CHAIN
(current
))
11929 if
(DECL_NAME
(current
) == name
)
11931 b
= BLOCK_SUPERCONTEXT
(b
);
11937 maybe_absorb_scoping_blocks
()
11939 while
(BLOCK_IS_IMPLICIT
(GET_CURRENT_BLOCK
(current_function_decl
)))
11941 tree b
= exit_block
();
11942 java_method_add_stmt
(current_function_decl
, b
);
11943 SOURCE_FRONTEND_DEBUG
(("Absorbing scoping block at line %d", lineno
));
11948 /* This section of the source is reserved to build_* functions that
11949 are building incomplete tree nodes and the patch_* functions that
11950 are completing them. */
11952 /* Wrap a non WFL node around a WFL. */
11954 build_wfl_wrap
(node
, location
)
11958 tree wfl
, node_to_insert
= node
;
11960 /* We want to process THIS . xxx symbolicaly, to keep it consistent
11961 with the way we're processing SUPER. A THIS from a primary as a
11962 different form than a SUPER. Turn THIS into something symbolic */
11963 if
(TREE_CODE
(node
) == THIS_EXPR
)
11964 node_to_insert
= wfl
= build_wfl_node
(this_identifier_node
);
11966 wfl
= build_expr_wfl
(NULL_TREE
, ctxp
->filename
, 0, 0);
11968 EXPR_WFL_LINECOL
(wfl
) = location
;
11969 EXPR_WFL_QUALIFICATION
(wfl
) = build_tree_list
(node_to_insert
, NULL_TREE
);
11974 /* Build a super() constructor invocation. Returns empty_stmt_node if
11975 we're currently dealing with the class java.lang.Object. */
11978 build_super_invocation
(mdecl
)
11981 if
(DECL_CONTEXT
(mdecl
) == object_type_node
)
11982 return empty_stmt_node
;
11985 tree super_wfl
= build_wfl_node
(super_identifier_node
);
11986 tree a
= NULL_TREE
, t
;
11987 /* If we're dealing with an anonymous class, pass the arguments
11988 of the crafted constructor along. */
11989 if
(ANONYMOUS_CLASS_P
(DECL_CONTEXT
(mdecl
)))
11991 SKIP_THIS_AND_ARTIFICIAL_PARMS
(t
, mdecl
);
11992 for
(; t
!= end_params_node
; t
= TREE_CHAIN
(t
))
11993 a
= tree_cons
(NULL_TREE
, build_wfl_node
(TREE_PURPOSE
(t
)), a
);
11995 return build_method_invocation
(super_wfl
, a
);
11999 /* Build a SUPER/THIS qualified method invocation. */
12002 build_this_super_qualified_invocation
(use_this
, name
, args
, lloc
, rloc
)
12009 build_wfl_node
(use_this ? this_identifier_node
: super_identifier_node
);
12010 EXPR_WFL_LINECOL
(wfl
) = lloc
;
12011 invok
= build_method_invocation
(name
, args
);
12012 return make_qualified_primary
(wfl
, invok
, rloc
);
12015 /* Build an incomplete CALL_EXPR node. */
12018 build_method_invocation
(name
, args
)
12022 tree call
= build
(CALL_EXPR
, NULL_TREE
, name
, args
, NULL_TREE
);
12023 TREE_SIDE_EFFECTS
(call
) = 1;
12024 EXPR_WFL_LINECOL
(call
) = EXPR_WFL_LINECOL
(name
);
12028 /* Build an incomplete new xxx(...) node. */
12031 build_new_invocation
(name
, args
)
12034 tree call
= build
(NEW_CLASS_EXPR
, NULL_TREE
, name
, args
, NULL_TREE
);
12035 TREE_SIDE_EFFECTS
(call
) = 1;
12036 EXPR_WFL_LINECOL
(call
) = EXPR_WFL_LINECOL
(name
);
12040 /* Build an incomplete assignment expression. */
12043 build_assignment
(op
, op_location
, lhs
, rhs
)
12044 int op
, op_location
;
12048 /* Build the corresponding binop if we deal with a Compound
12049 Assignment operator. Mark the binop sub-tree as part of a
12050 Compound Assignment expression */
12051 if
(op
!= ASSIGN_TK
)
12053 rhs
= build_binop
(BINOP_LOOKUP
(op
), op_location
, lhs
, rhs
);
12054 COMPOUND_ASSIGN_P
(rhs
) = 1;
12056 assignment
= build
(MODIFY_EXPR
, NULL_TREE
, lhs
, rhs
);
12057 TREE_SIDE_EFFECTS
(assignment
) = 1;
12058 EXPR_WFL_LINECOL
(assignment
) = op_location
;
12062 /* Print an INTEGER_CST node in a static buffer, and return the buffer. */
12065 print_int_node
(node
)
12068 static char buffer
[80];
12069 if
(TREE_CONSTANT_OVERFLOW
(node
))
12070 sprintf
(buffer
, "<overflow>");
12072 if
(TREE_INT_CST_HIGH
(node
) == 0)
12073 sprintf
(buffer
, HOST_WIDE_INT_PRINT_UNSIGNED
,
12074 TREE_INT_CST_LOW
(node
));
12075 else if
(TREE_INT_CST_HIGH
(node
) == -1
12076 && TREE_INT_CST_LOW
(node
) != 0)
12079 sprintf
(&buffer
[1], HOST_WIDE_INT_PRINT_UNSIGNED
,
12080 -TREE_INT_CST_LOW
(node
));
12083 sprintf
(buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
12084 TREE_INT_CST_HIGH
(node
), TREE_INT_CST_LOW
(node
));
12091 /* This section of the code handle assignment check with FINAL
12095 reset_static_final_variable_assignment_flag
(class
)
12099 for
(field
= TYPE_FIELDS
(class
); field
; field
= TREE_CHAIN
(field
))
12100 if
(CLASS_FINAL_VARIABLE_P
(field
))
12101 DECL_FIELD_FINAL_LIIC
(field
) = 0;
12104 /* Figure whether all final static variable have been initialized. */
12107 check_static_final_variable_assignment_flag
(class
)
12112 for
(field
= TYPE_FIELDS
(class
); field
; field
= TREE_CHAIN
(field
))
12113 if
(CLASS_FINAL_VARIABLE_P
(field
)
12114 && !DECL_FIELD_FINAL_IUD
(field
) && !DECL_FIELD_FINAL_LIIC
(field
))
12115 parse_error_context
12116 (DECL_FIELD_FINAL_WFL
(field
),
12117 "Blank static final variable `%s' may not have been initialized",
12118 IDENTIFIER_POINTER
(DECL_NAME
(field
)));
12121 /* This function marks all final variable locally unassigned. */
12124 reset_final_variable_local_assignment_flag
(class
)
12128 for
(field
= TYPE_FIELDS
(class
); field
; field
= TREE_CHAIN
(field
))
12129 if
(FINAL_VARIABLE_P
(field
))
12130 DECL_FIELD_FINAL_LIIC
(field
) = 0;
12133 /* Figure whether all final variables have beem initialized in MDECL
12134 and mark MDECL accordingly. */
12137 check_final_variable_local_assignment_flag
(class
, mdecl
)
12142 int initialized
= 0;
12143 int non_initialized
= 0;
12145 if
(DECL_FUNCTION_SYNTHETIC_CTOR
(mdecl
))
12148 /* First find out whether all final variables or no final variable
12149 are initialized in this ctor. We don't take into account final
12150 variable that have been initialized upon declaration. */
12151 for
(field
= TYPE_FIELDS
(class
); field
; field
= TREE_CHAIN
(field
))
12152 if
(FINAL_VARIABLE_P
(field
) && !DECL_FIELD_FINAL_IUD
(field
))
12154 if
(DECL_FIELD_FINAL_LIIC
(field
))
12160 /* There were no non initialized variable and no initialized variable.
12161 This ctor is fine. */
12162 if
(!non_initialized
&& !initialized
)
12163 DECL_FUNCTION_ALL_FINAL_INITIALIZED
(mdecl
) = 1;
12164 /* If no variables have been initialized, that fine. We'll check
12165 later whether this ctor calls a constructor which initializes
12166 them. We mark the ctor as not initializing all its finals. */
12167 else if
(initialized
== 0)
12168 DECL_FUNCTION_ALL_FINAL_INITIALIZED
(mdecl
) = 0;
12169 /* If we have a mixed bag, then we have a problem. We need to report
12170 all the variables we're not initializing. */
12171 else if
(initialized
&& non_initialized
)
12173 DECL_FUNCTION_ALL_FINAL_INITIALIZED
(mdecl
) = 0;
12174 for
(field
= TYPE_FIELDS
(class
); field
; field
= TREE_CHAIN
(field
))
12175 if
(FIELD_FINAL
(field
)
12176 && !DECL_FIELD_FINAL_IUD
(field
) && !DECL_FIELD_FINAL_LIIC
(field
))
12178 parse_error_context
12179 (lookup_cl
(mdecl
),
12180 "Blank final variable `%s' may not have been initialized in this constructor",
12181 IDENTIFIER_POINTER
(DECL_NAME
(field
)));
12182 DECL_FIELD_FINAL_IERR
(field
) = 1;
12185 /* Otherwise we know this ctor is initializing all its final
12186 variable. We mark it so. */
12188 DECL_FUNCTION_ALL_FINAL_INITIALIZED
(mdecl
) = 1;
12191 /* This function recurses in a simple what through STMT and stops when
12192 it finds a constructor call. It then verifies that the called
12193 constructor initialized its final properly. Return 1 upon success,
12194 0 or -1 otherwise. */
12197 check_final_variable_indirect_assignment
(stmt
)
12201 switch
(TREE_CODE
(stmt
))
12203 case EXPR_WITH_FILE_LOCATION
:
12204 return check_final_variable_indirect_assignment
(EXPR_WFL_NODE
(stmt
));
12205 case COMPOUND_EXPR
:
12206 res
= check_final_variable_indirect_assignment
(TREE_OPERAND
(stmt
, 0));
12209 return check_final_variable_indirect_assignment
(TREE_OPERAND
(stmt
, 1));
12211 return check_final_variable_indirect_assignment
(TREE_OPERAND
(stmt
, 0));
12214 tree decl
= TREE_OPERAND
(stmt
, 0);
12217 if
(TREE_CODE
(decl
) != FUNCTION_DECL
)
12218 decl
= TREE_OPERAND
(TREE_OPERAND
(decl
, 0), 0);
12219 if
(TREE_CODE
(decl
) != FUNCTION_DECL
)
12221 if
(DECL_FUNCTION_ALL_FINAL_INITIALIZED
(decl
))
12223 if
(DECL_FINIT_P
(decl
) || DECL_CONTEXT
(decl
) != current_class
)
12225 fbody
= BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(decl
));
12226 if
(fbody
== error_mark_node
)
12228 fbody
= BLOCK_EXPR_BODY
(fbody
);
12229 return check_final_variable_indirect_assignment
(fbody
);
12237 /* This is the last chance to catch a final variable initialization
12238 problem. This routine will report an error if a final variable was
12239 never (globally) initialized and never reported as not having been
12240 initialized properly. */
12243 check_final_variable_global_assignment_flag
(class
)
12249 /* We go through all natural ctors and see whether they're
12250 initializing all their final variables or not. */
12251 current_function_decl
= NULL_TREE
; /* For the error report. */
12252 for
(mdecl
= TYPE_METHODS
(class
); mdecl
; mdecl
= TREE_CHAIN
(mdecl
))
12253 if
(DECL_CONSTRUCTOR_P
(mdecl
) && ! DECL_FUNCTION_SYNTHETIC_CTOR
(mdecl
))
12255 if
(!DECL_FUNCTION_ALL_FINAL_INITIALIZED
(mdecl
))
12257 /* It doesn't. Maybe it calls a constructor that initializes
12259 tree fbody
= BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(mdecl
));
12260 if
(fbody
== error_mark_node
)
12262 fbody
= BLOCK_EXPR_BODY
(fbody
);
12263 if
(check_final_variable_indirect_assignment
(fbody
) == 1)
12265 DECL_FUNCTION_ALL_FINAL_INITIALIZED
(mdecl
) = 1;
12269 parse_error_context
12270 (lookup_cl
(mdecl
),
12271 "Final variable initialization error in this constructor");
12277 /* Finally we catch final variables that never were initialized */
12278 for
(field
= TYPE_FIELDS
(class
); field
; field
= TREE_CHAIN
(field
))
12279 if
(FINAL_VARIABLE_P
(field
)
12280 /* If the field wasn't initialized upon declaration */
12281 && !DECL_FIELD_FINAL_IUD
(field
)
12282 /* There wasn't natural ctor in which the field could have been
12285 /* If we never reported a problem with this field */
12286 && !DECL_FIELD_FINAL_IERR
(field
))
12288 current_function_decl
= NULL
;
12289 parse_error_context
12290 (DECL_FIELD_FINAL_WFL
(field
),
12291 "Final variable `%s' hasn't been initialized upon its declaration",
12292 IDENTIFIER_POINTER
(DECL_NAME
(field
)));
12297 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
12301 check_final_assignment
(lvalue
, wfl
)
12304 if
(TREE_CODE
(lvalue
) != COMPONENT_REF
&& !JDECL_P
(lvalue
))
12307 if
(TREE_CODE
(lvalue
) == COMPONENT_REF
12308 && JDECL_P
(TREE_OPERAND
(lvalue
, 1)))
12309 lvalue
= TREE_OPERAND
(lvalue
, 1);
12311 if
(!FIELD_FINAL
(lvalue
))
12314 /* Now the logic. We can modify a final VARIABLE:
12315 1) in finit$, (its declaration was followed by an initialization,)
12316 2) consistently in each natural ctor, if it wasn't initialized in
12317 finit$ or once in <clinit>. In any other cases, an error should be
12319 if
(DECL_FINIT_P
(current_function_decl
))
12321 DECL_FIELD_FINAL_IUD
(lvalue
) = 1;
12325 if
(!DECL_FUNCTION_SYNTHETIC_CTOR
(current_function_decl
)
12326 /* Only if it wasn't given a value upon initialization */
12327 && DECL_LANG_SPECIFIC
(lvalue
) && !DECL_FIELD_FINAL_IUD
(lvalue
)
12328 /* If it was never assigned a value in this constructor */
12329 && !DECL_FIELD_FINAL_LIIC
(lvalue
))
12331 /* Turn the locally assigned flag on, it will be checked later
12332 on to point out at discrepancies. */
12333 DECL_FIELD_FINAL_LIIC
(lvalue
) = 1;
12334 if
(DECL_CLINIT_P
(current_function_decl
))
12335 DECL_FIELD_FINAL_IUD
(lvalue
) = 1;
12339 /* Other problems should be reported right away. */
12340 parse_error_context
12341 (wfl
, "Can't %sassign a value to the final variable `%s'",
12342 (FIELD_STATIC
(lvalue
) ?
"re" : ""),
12343 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
12345 /* Note that static field can be initialized once and only once. */
12346 if
(FIELD_STATIC
(lvalue
))
12347 DECL_FIELD_FINAL_IERR
(lvalue
) = 1;
12352 /* Inline references to java.lang.PRIMTYPE.TYPE when accessed in
12353 read. This is needed to avoid circularities in the implementation
12354 of these fields in libjava. */
12357 maybe_build_primttype_type_ref
(rhs
, wfl
)
12360 tree to_return
= NULL_TREE
;
12361 tree rhs_type
= TREE_TYPE
(rhs
);
12362 if
(TREE_CODE
(rhs
) == COMPOUND_EXPR
)
12364 tree n
= TREE_OPERAND
(rhs
, 1);
12365 if
(TREE_CODE
(n
) == VAR_DECL
12366 && DECL_NAME
(n
) == TYPE_identifier_node
12367 && rhs_type
== class_ptr_type
12368 && TREE_CODE
(EXPR_WFL_NODE
(wfl
)) == IDENTIFIER_NODE
)
12370 const char *self_name
= IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
));
12371 if
(!strncmp
(self_name
, "java.lang.", 10))
12372 to_return
= build_primtype_type_ref
(self_name
);
12375 return
(to_return ? to_return
: rhs
);
12378 /* 15.25 Assignment operators. */
12381 patch_assignment
(node
, wfl_op1
, wfl_op2
)
12386 tree rhs
= TREE_OPERAND
(node
, 1);
12387 tree lvalue
= TREE_OPERAND
(node
, 0), llvalue
;
12388 tree lhs_type
= NULL_TREE
, rhs_type
, new_rhs
= NULL_TREE
;
12389 int error_found
= 0;
12390 int lvalue_from_array
= 0;
12392 /* Can't assign to a (blank) final. */
12393 if
(check_final_assignment
(lvalue
, wfl_op1
))
12396 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
12398 /* Lhs can be a named variable */
12399 if
(JDECL_P
(lvalue
))
12401 lhs_type
= TREE_TYPE
(lvalue
);
12403 /* Or Lhs can be a array acccess. Should that be lvalue ? FIXME +
12404 comment on reason why */
12405 else if
(TREE_CODE
(wfl_op1
) == ARRAY_REF
)
12407 lhs_type
= TREE_TYPE
(lvalue
);
12408 lvalue_from_array
= 1;
12410 /* Or a field access */
12411 else if
(TREE_CODE
(lvalue
) == COMPONENT_REF
)
12412 lhs_type
= TREE_TYPE
(lvalue
);
12413 /* Or a function return slot */
12414 else if
(TREE_CODE
(lvalue
) == RESULT_DECL
)
12415 lhs_type
= TREE_TYPE
(lvalue
);
12416 /* Otherwise, we might want to try to write into an optimized static
12417 final, this is an of a different nature, reported further on. */
12418 else if
(TREE_CODE
(wfl_op1
) == EXPR_WITH_FILE_LOCATION
12419 && resolve_expression_name
(wfl_op1
, &llvalue
))
12421 if
(!error_found
&& check_final_assignment
(llvalue
, wfl_op1
))
12423 /* What we should do instead is resetting the all the flags
12424 previously set, exchange lvalue for llvalue and continue. */
12426 return error_mark_node
;
12429 lhs_type
= TREE_TYPE
(lvalue
);
12433 parse_error_context
(wfl_op1
, "Invalid left hand side of assignment");
12437 rhs_type
= TREE_TYPE
(rhs
);
12438 /* 5.1 Try the assignment conversion for builtin type. */
12439 new_rhs
= try_builtin_assignconv
(wfl_op1
, lhs_type
, rhs
);
12441 /* 5.2 If it failed, try a reference conversion */
12442 if
(!new_rhs
&& (new_rhs
= try_reference_assignconv
(lhs_type
, rhs
)))
12443 lhs_type
= promote_type
(rhs_type
);
12445 /* 15.25.2 If we have a compound assignment, convert RHS into the
12447 else if
(COMPOUND_ASSIGN_P
(TREE_OPERAND
(node
, 1)))
12448 new_rhs
= convert
(lhs_type
, rhs
);
12450 /* Explicit cast required. This is an error */
12453 char *t1
= xstrdup
(lang_printable_name
(TREE_TYPE
(rhs
), 0));
12454 char *t2
= xstrdup
(lang_printable_name
(lhs_type
, 0));
12456 char operation
[32]; /* Max size known */
12458 /* If the assignment is part of a declaration, we use the WFL of
12459 the declared variable to point out the error and call it a
12460 declaration problem. If the assignment is a genuine =
12461 operator, we call is a operator `=' problem, otherwise we
12462 call it an assignment problem. In both of these last cases,
12463 we use the WFL of the operator to indicate the error. */
12465 if
(MODIFY_EXPR_FROM_INITIALIZATION_P
(node
))
12468 strcpy
(operation
, "declaration");
12472 wfl
= wfl_operator
;
12473 if
(COMPOUND_ASSIGN_P
(TREE_OPERAND
(node
, 1)))
12474 strcpy
(operation
, "assignment");
12475 else if
(TREE_CODE
(TREE_OPERAND
(node
, 0)) == RESULT_DECL
)
12476 strcpy
(operation
, "`return'");
12478 strcpy
(operation
, "`='");
12481 if
(!valid_cast_to_p
(rhs_type
, lhs_type
))
12482 parse_error_context
12483 (wfl
, "Incompatible type for %s. Can't convert `%s' to `%s'",
12484 operation
, t1
, t2
);
12486 parse_error_context
(wfl
, "Incompatible type for %s. Explicit cast needed to convert `%s' to `%s'",
12487 operation
, t1
, t2
);
12488 free
(t1
); free
(t2
);
12492 /* Inline read access to java.lang.PRIMTYPE.TYPE */
12494 new_rhs
= maybe_build_primttype_type_ref
(new_rhs
, wfl_op2
);
12497 return error_mark_node
;
12499 /* 10.10: Array Store Exception runtime check */
12500 if
(!flag_emit_class_files
12502 && lvalue_from_array
12503 && JREFERENCE_TYPE_P
(TYPE_ARRAY_ELEMENT
(lhs_type
)))
12506 tree base
= lvalue
;
12508 /* We need to retrieve the right argument for
12509 _Jv_CheckArrayStore. This is somewhat complicated by bounds
12510 and null pointer checks, both of which wrap the operand in
12511 one layer of COMPOUND_EXPR. */
12512 if
(TREE_CODE
(lvalue
) == COMPOUND_EXPR
)
12513 base
= TREE_OPERAND
(lvalue
, 0);
12516 base
= TREE_OPERAND
(base
, 0);
12517 if
(flag_bounds_check
)
12518 base
= TREE_OPERAND
(base
, 1);
12519 if
(flag_check_references
)
12520 base
= TREE_OPERAND
(base
, 1);
12521 base
= TREE_OPERAND
(base
, 0);
12524 /* Build the invocation of _Jv_CheckArrayStore */
12525 new_rhs
= save_expr
(new_rhs
);
12526 check
= build
(CALL_EXPR
, void_type_node
,
12527 build_address_of
(soft_checkarraystore_node
),
12528 tree_cons
(NULL_TREE
, base
,
12529 build_tree_list
(NULL_TREE
, new_rhs
)),
12531 TREE_SIDE_EFFECTS
(check
) = 1;
12533 /* We have to decide on an insertion point */
12534 if
(TREE_CODE
(lvalue
) == COMPOUND_EXPR
)
12537 if
(flag_bounds_check
)
12539 t
= TREE_OPERAND
(TREE_OPERAND
(TREE_OPERAND
(lvalue
, 1), 0), 0);
12540 TREE_OPERAND
(TREE_OPERAND
(TREE_OPERAND
(lvalue
, 1), 0), 0) =
12541 build
(COMPOUND_EXPR
, void_type_node
, t
, check
);
12544 TREE_OPERAND
(lvalue
, 1) = build
(COMPOUND_EXPR
, lhs_type
,
12545 check
, TREE_OPERAND
(lvalue
, 1));
12549 /* Make sure the bound check will happen before the store check */
12550 if
(flag_bounds_check
)
12551 TREE_OPERAND
(TREE_OPERAND
(lvalue
, 0), 0) =
12552 build
(COMPOUND_EXPR
, void_type_node
,
12553 TREE_OPERAND
(TREE_OPERAND
(lvalue
, 0), 0), check
);
12555 lvalue
= build
(COMPOUND_EXPR
, lhs_type
, check
, lvalue
);
12559 /* Final locals can be used as case values in switch
12560 statement. Prepare them for this eventuality. */
12561 if
(TREE_CODE
(lvalue
) == VAR_DECL
12562 && LOCAL_FINAL_P
(lvalue
)
12563 && TREE_CONSTANT
(new_rhs
)
12564 && IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(lvalue
))
12565 && JINTEGRAL_TYPE_P
(TREE_TYPE
(lvalue
))
12568 TREE_CONSTANT
(lvalue
) = 1;
12569 DECL_INITIAL
(lvalue
) = new_rhs
;
12572 TREE_OPERAND
(node
, 0) = lvalue
;
12573 TREE_OPERAND
(node
, 1) = new_rhs
;
12574 TREE_TYPE
(node
) = lhs_type
;
12578 /* Check that type SOURCE can be cast into type DEST. If the cast
12579 can't occur at all, return 0 otherwise 1. This function is used to
12580 produce accurate error messages on the reasons why an assignment
12584 try_reference_assignconv
(lhs_type
, rhs
)
12585 tree lhs_type
, rhs
;
12587 tree new_rhs
= NULL_TREE
;
12588 tree rhs_type
= TREE_TYPE
(rhs
);
12590 if
(!JPRIMITIVE_TYPE_P
(rhs_type
) && JREFERENCE_TYPE_P
(lhs_type
))
12592 /* `null' may be assigned to any reference type */
12593 if
(rhs
== null_pointer_node
)
12594 new_rhs
= null_pointer_node
;
12595 /* Try the reference assignment conversion */
12596 else if
(valid_ref_assignconv_cast_p
(rhs_type
, lhs_type
, 0))
12598 /* This is a magic assignment that we process differently */
12599 else if
(TREE_CODE
(rhs
) == EXC_PTR_EXPR
)
12605 /* Check that RHS can be converted into LHS_TYPE by the assignment
12606 conversion (5.2), for the cases of RHS being a builtin type. Return
12607 NULL_TREE if the conversion fails or if because RHS isn't of a
12608 builtin type. Return a converted RHS if the conversion is possible. */
12611 try_builtin_assignconv
(wfl_op1
, lhs_type
, rhs
)
12612 tree wfl_op1
, lhs_type
, rhs
;
12614 tree new_rhs
= NULL_TREE
;
12615 tree rhs_type
= TREE_TYPE
(rhs
);
12617 /* Handle boolean specially. */
12618 if
(TREE_CODE
(rhs_type
) == BOOLEAN_TYPE
12619 || TREE_CODE
(lhs_type
) == BOOLEAN_TYPE
)
12621 if
(TREE_CODE
(rhs_type
) == BOOLEAN_TYPE
12622 && TREE_CODE
(lhs_type
) == BOOLEAN_TYPE
)
12626 /* Zero accepted everywhere */
12627 else if
(TREE_CODE
(rhs
) == INTEGER_CST
12628 && TREE_INT_CST_HIGH
(rhs
) == 0 && TREE_INT_CST_LOW
(rhs
) == 0
12629 && JPRIMITIVE_TYPE_P
(rhs_type
))
12630 new_rhs
= convert
(lhs_type
, rhs
);
12632 /* 5.1.1 Try Identity Conversion,
12633 5.1.2 Try Widening Primitive Conversion */
12634 else if
(valid_builtin_assignconv_identity_widening_p
(lhs_type
, rhs_type
))
12635 new_rhs
= convert
(lhs_type
, rhs
);
12637 /* Try a narrowing primitive conversion (5.1.3):
12638 - expression is a constant expression of type int AND
12639 - variable is byte, short or char AND
12640 - The value of the expression is representable in the type of the
12642 else if
(rhs_type
== int_type_node
&& TREE_CONSTANT
(rhs
)
12643 && (lhs_type
== byte_type_node || lhs_type
== char_type_node
12644 || lhs_type
== short_type_node
))
12646 if
(int_fits_type_p
(rhs
, lhs_type
))
12647 new_rhs
= convert
(lhs_type
, rhs
);
12648 else if
(wfl_op1
) /* Might be called with a NULL */
12649 parse_warning_context
12650 (wfl_op1
, "Constant expression `%s' too wide for narrowing primitive conversion to `%s'",
12651 print_int_node
(rhs
), lang_printable_name
(lhs_type
, 0));
12652 /* Reported a warning that will turn into an error further
12653 down, so we don't return */
12659 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
12660 conversion (5.1.1) or widening primitive conversion (5.1.2). Return
12661 0 is the conversion test fails. This implements parts the method
12662 invocation convertion (5.3). */
12665 valid_builtin_assignconv_identity_widening_p
(lhs_type
, rhs_type
)
12666 tree lhs_type
, rhs_type
;
12668 /* 5.1.1: This is the identity conversion part. */
12669 if
(lhs_type
== rhs_type
)
12672 /* Reject non primitive types and boolean conversions. */
12673 if
(!JNUMERIC_TYPE_P
(lhs_type
) ||
!JNUMERIC_TYPE_P
(rhs_type
))
12676 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
12677 than a char can't be converted into a char. Short can't too, but
12678 the < test below takes care of that */
12679 if
(lhs_type
== char_type_node
&& rhs_type
== byte_type_node
)
12682 /* Accept all promoted type here. Note, we can't use <= in the test
12683 below, because we still need to bounce out assignments of short
12684 to char and the likes */
12685 if
(lhs_type
== int_type_node
12686 && (rhs_type
== promoted_byte_type_node
12687 || rhs_type
== promoted_short_type_node
12688 || rhs_type
== promoted_char_type_node
12689 || rhs_type
== promoted_boolean_type_node
))
12692 /* From here, an integral is widened if its precision is smaller
12693 than the precision of the LHS or if the LHS is a floating point
12694 type, or the RHS is a float and the RHS a double. */
12695 if
((JINTEGRAL_TYPE_P
(rhs_type
) && JINTEGRAL_TYPE_P
(lhs_type
)
12696 && (TYPE_PRECISION
(rhs_type
) < TYPE_PRECISION
(lhs_type
)))
12697 ||
(JINTEGRAL_TYPE_P
(rhs_type
) && JFLOAT_TYPE_P
(lhs_type
))
12698 ||
(rhs_type
== float_type_node
&& lhs_type
== double_type_node
))
12704 /* Check that something of SOURCE type can be assigned or cast to
12705 something of DEST type at runtime. Return 1 if the operation is
12706 valid, 0 otherwise. If CAST is set to 1, we're treating the case
12707 were SOURCE is cast into DEST, which borrows a lot of the
12708 assignment check. */
12711 valid_ref_assignconv_cast_p
(source
, dest
, cast
)
12716 /* SOURCE or DEST might be null if not from a declared entity. */
12717 if
(!source ||
!dest
)
12719 if
(JNULLP_TYPE_P
(source
))
12721 if
(TREE_CODE
(source
) == POINTER_TYPE
)
12722 source
= TREE_TYPE
(source
);
12723 if
(TREE_CODE
(dest
) == POINTER_TYPE
)
12724 dest
= TREE_TYPE
(dest
);
12726 /* If source and dest are being compiled from bytecode, they may need to
12728 if
(CLASS_P
(source
) && !CLASS_LOADED_P
(source
))
12730 load_class
(source
, 1);
12731 safe_layout_class
(source
);
12733 if
(CLASS_P
(dest
) && !CLASS_LOADED_P
(dest
))
12735 load_class
(dest
, 1);
12736 safe_layout_class
(dest
);
12739 /* Case where SOURCE is a class type */
12740 if
(TYPE_CLASS_P
(source
))
12742 if
(TYPE_CLASS_P
(dest
))
12743 return
(source
== dest
12744 || inherits_from_p
(source
, dest
)
12745 ||
(cast
&& inherits_from_p
(dest
, source
)));
12746 if
(TYPE_INTERFACE_P
(dest
))
12748 /* If doing a cast and SOURCE is final, the operation is
12749 always correct a compile time (because even if SOURCE
12750 does not implement DEST, a subclass of SOURCE might). */
12751 if
(cast
&& !CLASS_FINAL
(TYPE_NAME
(source
)))
12753 /* Otherwise, SOURCE must implement DEST */
12754 return interface_of_p
(dest
, source
);
12756 /* DEST is an array, cast permited if SOURCE is of Object type */
12757 return
(cast
&& source
== object_type_node ?
1 : 0);
12759 if
(TYPE_INTERFACE_P
(source
))
12761 if
(TYPE_CLASS_P
(dest
))
12763 /* If not casting, DEST must be the Object type */
12765 return dest
== object_type_node
;
12766 /* We're doing a cast. The cast is always valid is class
12767 DEST is not final, otherwise, DEST must implement SOURCE */
12768 else if
(!CLASS_FINAL
(TYPE_NAME
(dest
)))
12771 return interface_of_p
(source
, dest
);
12773 if
(TYPE_INTERFACE_P
(dest
))
12775 /* If doing a cast, then if SOURCE and DEST contain method
12776 with the same signature but different return type, then
12777 this is a (compile time) error */
12780 tree method_source
, method_dest
;
12784 for
(method_source
= TYPE_METHODS
(source
); method_source
;
12785 method_source
= TREE_CHAIN
(method_source
))
12788 build_java_argument_signature
(TREE_TYPE
(method_source
));
12789 source_type
= TREE_TYPE
(TREE_TYPE
(method_source
));
12790 source_name
= DECL_NAME
(method_source
);
12791 for
(method_dest
= TYPE_METHODS
(dest
);
12792 method_dest
; method_dest
= TREE_CHAIN
(method_dest
))
12794 build_java_argument_signature
(TREE_TYPE
(method_dest
))
12795 && source_name
== DECL_NAME
(method_dest
)
12796 && source_type
!= TREE_TYPE
(TREE_TYPE
(method_dest
)))
12802 return source
== dest || interface_of_p
(dest
, source
);
12808 && (DECL_NAME
(TYPE_NAME
(source
)) == java_lang_cloneable
12809 ||
(DECL_NAME
(TYPE_NAME
(source
))
12810 == java_io_serializable
)));
12813 if
(TYPE_ARRAY_P
(source
))
12815 if
(TYPE_CLASS_P
(dest
))
12816 return dest
== object_type_node
;
12817 /* Can't cast an array to an interface unless the interface is
12818 java.lang.Cloneable or java.io.Serializable. */
12819 if
(TYPE_INTERFACE_P
(dest
))
12820 return
(DECL_NAME
(TYPE_NAME
(dest
)) == java_lang_cloneable
12821 || DECL_NAME
(TYPE_NAME
(dest
)) == java_io_serializable
);
12824 tree source_element_type
= TYPE_ARRAY_ELEMENT
(source
);
12825 tree dest_element_type
= TYPE_ARRAY_ELEMENT
(dest
);
12827 /* In case of severe errors, they turn out null */
12828 if
(!dest_element_type ||
!source_element_type
)
12830 if
(source_element_type
== dest_element_type
)
12832 return valid_ref_assignconv_cast_p
(source_element_type
,
12833 dest_element_type
, cast
);
12841 valid_cast_to_p
(source
, dest
)
12845 if
(TREE_CODE
(source
) == POINTER_TYPE
)
12846 source
= TREE_TYPE
(source
);
12847 if
(TREE_CODE
(dest
) == POINTER_TYPE
)
12848 dest
= TREE_TYPE
(dest
);
12850 if
(TREE_CODE
(source
) == RECORD_TYPE
&& TREE_CODE
(dest
) == RECORD_TYPE
)
12851 return valid_ref_assignconv_cast_p
(source
, dest
, 1);
12853 else if
(JNUMERIC_TYPE_P
(source
) && JNUMERIC_TYPE_P
(dest
))
12856 else if
(TREE_CODE
(source
) == BOOLEAN_TYPE
12857 && TREE_CODE
(dest
) == BOOLEAN_TYPE
)
12864 do_unary_numeric_promotion
(arg
)
12867 tree type
= TREE_TYPE
(arg
);
12868 if
((TREE_CODE
(type
) == INTEGER_TYPE
&& TYPE_PRECISION
(type
) < 32)
12869 || TREE_CODE
(type
) == CHAR_TYPE
)
12870 arg
= convert
(int_type_node
, arg
);
12874 /* Return a non zero value if SOURCE can be converted into DEST using
12875 the method invocation conversion rule (5.3). */
12877 valid_method_invocation_conversion_p
(dest
, source
)
12880 return
((JPRIMITIVE_TYPE_P
(source
) && JPRIMITIVE_TYPE_P
(dest
)
12881 && valid_builtin_assignconv_identity_widening_p
(dest
, source
))
12882 ||
((JREFERENCE_TYPE_P
(source
) || JNULLP_TYPE_P
(source
))
12883 && (JREFERENCE_TYPE_P
(dest
) || JNULLP_TYPE_P
(dest
))
12884 && valid_ref_assignconv_cast_p
(source
, dest
, 0)));
12887 /* Build an incomplete binop expression. */
12890 build_binop
(op
, op_location
, op1
, op2
)
12895 tree binop
= build
(op
, NULL_TREE
, op1
, op2
);
12896 TREE_SIDE_EFFECTS
(binop
) = 1;
12897 /* Store the location of the operator, for better error report. The
12898 string of the operator will be rebuild based on the OP value. */
12899 EXPR_WFL_LINECOL
(binop
) = op_location
;
12903 /* Build the string of the operator retained by NODE. If NODE is part
12904 of a compound expression, add an '=' at the end of the string. This
12905 function is called when an error needs to be reported on an
12906 operator. The string is returned as a pointer to a static character
12910 operator_string
(node
)
12913 #define BUILD_OPERATOR_STRING(S) \
12915 sprintf
(buffer
, "%s%s", S
, (COMPOUND_ASSIGN_P
(node
) ?
"=" : "")); \
12919 static char buffer
[10];
12920 switch
(TREE_CODE
(node
))
12922 case MULT_EXPR
: BUILD_OPERATOR_STRING
("*");
12923 case RDIV_EXPR
: BUILD_OPERATOR_STRING
("/");
12924 case TRUNC_MOD_EXPR
: BUILD_OPERATOR_STRING
("%");
12925 case PLUS_EXPR
: BUILD_OPERATOR_STRING
("+");
12926 case MINUS_EXPR
: BUILD_OPERATOR_STRING
("-");
12927 case LSHIFT_EXPR
: BUILD_OPERATOR_STRING
("<<");
12928 case RSHIFT_EXPR
: BUILD_OPERATOR_STRING
(">>");
12929 case URSHIFT_EXPR
: BUILD_OPERATOR_STRING
(">>>");
12930 case BIT_AND_EXPR
: BUILD_OPERATOR_STRING
("&");
12931 case BIT_XOR_EXPR
: BUILD_OPERATOR_STRING
("^");
12932 case BIT_IOR_EXPR
: BUILD_OPERATOR_STRING
("|");
12933 case TRUTH_ANDIF_EXPR
: BUILD_OPERATOR_STRING
("&&");
12934 case TRUTH_ORIF_EXPR
: BUILD_OPERATOR_STRING
("||");
12935 case EQ_EXPR
: BUILD_OPERATOR_STRING
("==");
12936 case NE_EXPR
: BUILD_OPERATOR_STRING
("!=");
12937 case GT_EXPR
: BUILD_OPERATOR_STRING
(">");
12938 case GE_EXPR
: BUILD_OPERATOR_STRING
(">=");
12939 case LT_EXPR
: BUILD_OPERATOR_STRING
("<");
12940 case LE_EXPR
: BUILD_OPERATOR_STRING
("<=");
12941 case UNARY_PLUS_EXPR
: BUILD_OPERATOR_STRING
("+");
12942 case NEGATE_EXPR
: BUILD_OPERATOR_STRING
("-");
12943 case TRUTH_NOT_EXPR
: BUILD_OPERATOR_STRING
("!");
12944 case BIT_NOT_EXPR
: BUILD_OPERATOR_STRING
("~");
12945 case PREINCREMENT_EXPR
: /* Fall through */
12946 case POSTINCREMENT_EXPR
: BUILD_OPERATOR_STRING
("++");
12947 case PREDECREMENT_EXPR
: /* Fall through */
12948 case POSTDECREMENT_EXPR
: BUILD_OPERATOR_STRING
("--");
12950 internal_error
("unregistered operator %s",
12951 tree_code_name
[TREE_CODE
(node
)]);
12954 #undef BUILD_OPERATOR_STRING
12957 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
12960 java_decl_equiv
(var_acc1
, var_acc2
)
12961 tree var_acc1
, var_acc2
;
12963 if
(JDECL_P
(var_acc1
))
12964 return
(var_acc1
== var_acc2
);
12966 return
(TREE_CODE
(var_acc1
) == COMPONENT_REF
12967 && TREE_CODE
(var_acc2
) == COMPONENT_REF
12968 && TREE_OPERAND
(TREE_OPERAND
(var_acc1
, 0), 0)
12969 == TREE_OPERAND
(TREE_OPERAND
(var_acc2
, 0), 0)
12970 && TREE_OPERAND
(var_acc1
, 1) == TREE_OPERAND
(var_acc2
, 1));
12973 /* Return a non zero value if CODE is one of the operators that can be
12974 used in conjunction with the `=' operator in a compound assignment. */
12977 binop_compound_p
(code
)
12978 enum tree_code code
;
12981 for
(i
= 0; i
< BINOP_COMPOUND_CANDIDATES
; i
++)
12982 if
(binop_lookup
[i
] == code
)
12985 return i
< BINOP_COMPOUND_CANDIDATES
;
12988 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
12994 tree c
, b
, ns
, decl
;
12996 if
(TREE_CODE
(t
) != MODIFY_EXPR
)
12999 c
= TREE_OPERAND
(t
, 1);
13000 if
(! (c
&& TREE_CODE
(c
) == COMPOUND_EXPR
13001 && TREE_CODE
(TREE_OPERAND
(c
, 0)) == MODIFY_EXPR
13002 && binop_compound_p
(TREE_CODE
(TREE_OPERAND
(c
, 1)))))
13005 /* Now the left branch of the binary operator. */
13006 b
= TREE_OPERAND
(TREE_OPERAND
(c
, 1), 0);
13007 if
(! (b
&& TREE_CODE
(b
) == NOP_EXPR
13008 && TREE_CODE
(TREE_OPERAND
(b
, 0)) == SAVE_EXPR
))
13011 ns
= TREE_OPERAND
(TREE_OPERAND
(b
, 0), 0);
13012 if
(! (ns
&& TREE_CODE
(ns
) == NOP_EXPR
13013 && TREE_CODE
(TREE_OPERAND
(ns
, 0)) == SAVE_EXPR
))
13016 decl
= TREE_OPERAND
(TREE_OPERAND
(ns
, 0), 0);
13017 if
((JDECL_P
(decl
) || TREE_CODE
(decl
) == COMPONENT_REF
)
13018 /* It's got to be the an equivalent decl */
13019 && java_decl_equiv
(decl
, TREE_OPERAND
(TREE_OPERAND
(c
, 0), 0)))
13021 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
13022 TREE_OPERAND
(TREE_OPERAND
(c
, 1), 0) = TREE_OPERAND
(ns
, 0);
13023 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
13024 TREE_OPERAND
(t
, 1) = TREE_OPERAND
(c
, 1);
13025 /* Change the right part of the BINOP_EXPR */
13026 TREE_OPERAND
(TREE_OPERAND
(t
, 1), 1) = TREE_OPERAND
(c
, 0);
13032 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
13033 errors but we modify NODE so that it contains the type computed
13034 according to the expression, when it's fixed. Otherwise, we write
13035 error_mark_node as the type. It allows us to further the analysis
13036 of remaining nodes and detects more errors in certain cases. */
13039 patch_binop
(node
, wfl_op1
, wfl_op2
)
13044 tree op1
= TREE_OPERAND
(node
, 0);
13045 tree op2
= TREE_OPERAND
(node
, 1);
13046 tree op1_type
= TREE_TYPE
(op1
);
13047 tree op2_type
= TREE_TYPE
(op2
);
13048 tree prom_type
= NULL_TREE
, cn
;
13049 int code
= TREE_CODE
(node
);
13051 /* If 1, tell the routine that we have to return error_mark_node
13052 after checking for the initialization of the RHS */
13053 int error_found
= 0;
13055 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
13057 /* If either op<n>_type are NULL, this might be early signs of an
13058 error situation, unless it's too early to tell (in case we're
13059 handling a `+', `==', `!=' or `instanceof'.) We want to set op<n>_type
13060 correctly so the error can be later on reported accurately. */
13061 if
(! (code
== PLUS_EXPR || code
== NE_EXPR
13062 || code
== EQ_EXPR || code
== INSTANCEOF_EXPR
))
13067 n
= java_complete_tree
(op1
);
13068 op1_type
= TREE_TYPE
(n
);
13072 n
= java_complete_tree
(op2
);
13073 op2_type
= TREE_TYPE
(n
);
13079 /* 15.16 Multiplicative operators */
13080 case MULT_EXPR
: /* 15.16.1 Multiplication Operator * */
13081 case RDIV_EXPR
: /* 15.16.2 Division Operator / */
13082 case TRUNC_DIV_EXPR
: /* 15.16.2 Integral type Division Operator / */
13083 case TRUNC_MOD_EXPR
: /* 15.16.3 Remainder operator % */
13084 if
(!JNUMERIC_TYPE_P
(op1_type
) ||
!JNUMERIC_TYPE_P
(op2_type
))
13086 if
(!JNUMERIC_TYPE_P
(op1_type
))
13087 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op1_type
);
13088 if
(!JNUMERIC_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13089 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op2_type
);
13090 TREE_TYPE
(node
) = error_mark_node
;
13094 prom_type
= binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13095 /* Change the division operator if necessary */
13096 if
(code
== RDIV_EXPR
&& TREE_CODE
(prom_type
) == INTEGER_TYPE
)
13097 TREE_SET_CODE
(node
, TRUNC_DIV_EXPR
);
13099 if
(TREE_CODE
(prom_type
) == INTEGER_TYPE
13100 && flag_use_divide_subroutine
13101 && ! flag_emit_class_files
13102 && (code
== RDIV_EXPR || code
== TRUNC_MOD_EXPR
))
13103 return build_java_soft_divmod
(TREE_CODE
(node
), prom_type
, op1
, op2
);
13105 /* This one is more complicated. FLOATs are processed by a
13106 function call to soft_fmod. Duplicate the value of the
13107 COMPOUND_ASSIGN_P flag. */
13108 if
(code
== TRUNC_MOD_EXPR
)
13110 tree mod
= build_java_binop
(TRUNC_MOD_EXPR
, prom_type
, op1
, op2
);
13111 COMPOUND_ASSIGN_P
(mod
) = COMPOUND_ASSIGN_P
(node
);
13112 TREE_SIDE_EFFECTS
(mod
)
13113 = TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13118 /* 15.17 Additive Operators */
13119 case PLUS_EXPR
: /* 15.17.1 String Concatenation Operator + */
13121 /* Operation is valid if either one argument is a string
13122 constant, a String object or a StringBuffer crafted for the
13123 purpose of the a previous usage of the String concatenation
13126 if
(TREE_CODE
(op1
) == STRING_CST
13127 || TREE_CODE
(op2
) == STRING_CST
13128 || JSTRING_TYPE_P
(op1_type
)
13129 || JSTRING_TYPE_P
(op2_type
)
13130 || IS_CRAFTED_STRING_BUFFER_P
(op1
)
13131 || IS_CRAFTED_STRING_BUFFER_P
(op2
))
13132 return build_string_concatenation
(op1
, op2
);
13134 case MINUS_EXPR
: /* 15.17.2 Additive Operators (+ and -) for
13136 if
(!JNUMERIC_TYPE_P
(op1_type
) ||
!JNUMERIC_TYPE_P
(op2_type
))
13138 if
(!JNUMERIC_TYPE_P
(op1_type
))
13139 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op1_type
);
13140 if
(!JNUMERIC_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13141 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op2_type
);
13142 TREE_TYPE
(node
) = error_mark_node
;
13146 prom_type
= binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13149 /* 15.18 Shift Operators */
13153 if
(!JINTEGRAL_TYPE_P
(op1_type
) ||
!JINTEGRAL_TYPE_P
(op2_type
))
13155 if
(!JINTEGRAL_TYPE_P
(op1_type
))
13156 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op1_type
);
13159 if
(JNUMERIC_TYPE_P
(op2_type
))
13160 parse_error_context
(wfl_operator
,
13161 "Incompatible type for `%s'. Explicit cast needed to convert shift distance from `%s' to integral",
13162 operator_string
(node
),
13163 lang_printable_name
(op2_type
, 0));
13165 parse_error_context
(wfl_operator
,
13166 "Incompatible type for `%s'. Can't convert shift distance from `%s' to integral",
13167 operator_string
(node
),
13168 lang_printable_name
(op2_type
, 0));
13170 TREE_TYPE
(node
) = error_mark_node
;
13175 /* Unary numeric promotion (5.6.1) is performed on each operand
13177 op1
= do_unary_numeric_promotion
(op1
);
13178 op2
= do_unary_numeric_promotion
(op2
);
13180 /* The type of the shift expression is the type of the promoted
13181 type of the left-hand operand */
13182 prom_type
= TREE_TYPE
(op1
);
13184 /* Shift int only up to 0x1f and long up to 0x3f */
13185 if
(prom_type
== int_type_node
)
13186 op2
= fold
(build
(BIT_AND_EXPR
, int_type_node
, op2
,
13187 build_int_2
(0x1f, 0)));
13189 op2
= fold
(build
(BIT_AND_EXPR
, int_type_node
, op2
,
13190 build_int_2
(0x3f, 0)));
13192 /* The >>> operator is a >> operating on unsigned quantities */
13193 if
(code
== URSHIFT_EXPR
&& ! flag_emit_class_files
)
13196 tree utype
= unsigned_type
(prom_type
);
13197 op1
= convert
(utype
, op1
);
13198 TREE_SET_CODE
(node
, RSHIFT_EXPR
);
13199 TREE_OPERAND
(node
, 0) = op1
;
13200 TREE_OPERAND
(node
, 1) = op2
;
13201 TREE_TYPE
(node
) = utype
;
13202 to_return
= convert
(prom_type
, node
);
13203 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
13204 COMPOUND_ASSIGN_P
(to_return
) = COMPOUND_ASSIGN_P
(node
);
13205 TREE_SIDE_EFFECTS
(to_return
)
13206 = TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13211 /* 15.19.1 Type Comparison Operator instaceof */
13212 case INSTANCEOF_EXPR
:
13214 TREE_TYPE
(node
) = boolean_type_node
;
13216 if
(!(op2_type
= resolve_type_during_patch
(op2
)))
13217 return error_mark_node
;
13219 /* The first operand must be a reference type or the null type */
13220 if
(!JREFERENCE_TYPE_P
(op1_type
) && op1
!= null_pointer_node
)
13221 error_found
= 1; /* Error reported further below */
13223 /* The second operand must be a reference type */
13224 if
(!JREFERENCE_TYPE_P
(op2_type
))
13226 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op2
);
13227 parse_error_context
13228 (wfl_operator
, "Invalid argument `%s' for `instanceof'",
13229 lang_printable_name
(op2_type
, 0));
13233 if
(!error_found
&& valid_ref_assignconv_cast_p
(op1_type
, op2_type
, 1))
13235 /* If the first operand is null, the result is always false */
13236 if
(op1
== null_pointer_node
)
13237 return boolean_false_node
;
13238 else if
(flag_emit_class_files
)
13240 TREE_OPERAND
(node
, 1) = op2_type
;
13241 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(op1
);
13244 /* Otherwise we have to invoke instance of to figure it out */
13246 return build_instanceof
(op1
, op2_type
);
13248 /* There is no way the expression operand can be an instance of
13249 the type operand. This is a compile time error. */
13252 char *t1
= xstrdup
(lang_printable_name
(op1_type
, 0));
13253 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
13254 parse_error_context
13255 (wfl_operator
, "Impossible for `%s' to be instance of `%s'",
13256 t1
, lang_printable_name
(op2_type
, 0));
13263 /* 15.21 Bitwise and Logical Operators */
13267 if
(JINTEGRAL_TYPE_P
(op1_type
) && JINTEGRAL_TYPE_P
(op2_type
))
13268 /* Binary numeric promotion is performed on both operand and the
13269 expression retain that type */
13270 prom_type
= binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13272 else if
(TREE_CODE
(op1_type
) == BOOLEAN_TYPE
13273 && TREE_CODE
(op1_type
) == BOOLEAN_TYPE
)
13274 /* The type of the bitwise operator expression is BOOLEAN */
13275 prom_type
= boolean_type_node
;
13278 if
(!JINTEGRAL_TYPE_P
(op1_type
))
13279 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op1_type
);
13280 if
(!JINTEGRAL_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13281 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op2_type
);
13282 TREE_TYPE
(node
) = error_mark_node
;
13284 /* Insert a break here if adding thing before the switch's
13285 break for this case */
13289 /* 15.22 Conditional-And Operator */
13290 case TRUTH_ANDIF_EXPR
:
13291 /* 15.23 Conditional-Or Operator */
13292 case TRUTH_ORIF_EXPR
:
13293 /* Operands must be of BOOLEAN type */
13294 if
(TREE_CODE
(op1_type
) != BOOLEAN_TYPE ||
13295 TREE_CODE
(op2_type
) != BOOLEAN_TYPE
)
13297 if
(TREE_CODE
(op1_type
) != BOOLEAN_TYPE
)
13298 ERROR_CANT_CONVERT_TO_BOOLEAN
(wfl_operator
, node
, op1_type
);
13299 if
(TREE_CODE
(op2_type
) != BOOLEAN_TYPE
&& (op1_type
!= op2_type
))
13300 ERROR_CANT_CONVERT_TO_BOOLEAN
(wfl_operator
, node
, op2_type
);
13301 TREE_TYPE
(node
) = boolean_type_node
;
13305 /* The type of the conditional operators is BOOLEAN */
13306 prom_type
= boolean_type_node
;
13309 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
13314 /* The type of each of the operands must be a primitive numeric
13316 if
(!JNUMERIC_TYPE_P
(op1_type
) ||
! JNUMERIC_TYPE_P
(op2_type
))
13318 if
(!JNUMERIC_TYPE_P
(op1_type
))
13319 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op1_type
);
13320 if
(!JNUMERIC_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13321 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op2_type
);
13322 TREE_TYPE
(node
) = boolean_type_node
;
13326 /* Binary numeric promotion is performed on the operands */
13327 binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13328 /* The type of the relation expression is always BOOLEAN */
13329 prom_type
= boolean_type_node
;
13332 /* 15.20 Equality Operator */
13335 /* It's time for us to patch the strings. */
13336 if
((cn
= patch_string
(op1
)))
13339 op1_type
= TREE_TYPE
(op1
);
13341 if
((cn
= patch_string
(op2
)))
13344 op2_type
= TREE_TYPE
(op2
);
13347 /* 15.20.1 Numerical Equality Operators == and != */
13348 /* Binary numeric promotion is performed on the operands */
13349 if
(JNUMERIC_TYPE_P
(op1_type
) && JNUMERIC_TYPE_P
(op2_type
))
13350 binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13352 /* 15.20.2 Boolean Equality Operators == and != */
13353 else if
(TREE_CODE
(op1_type
) == BOOLEAN_TYPE
&&
13354 TREE_CODE
(op2_type
) == BOOLEAN_TYPE
)
13355 ; /* Nothing to do here */
13357 /* 15.20.3 Reference Equality Operators == and != */
13358 /* Types have to be either references or the null type. If
13359 they're references, it must be possible to convert either
13360 type to the other by casting conversion. */
13361 else if
(op1
== null_pointer_node || op2
== null_pointer_node
13362 ||
(JREFERENCE_TYPE_P
(op1_type
) && JREFERENCE_TYPE_P
(op2_type
)
13363 && (valid_ref_assignconv_cast_p
(op1_type
, op2_type
, 1)
13364 || valid_ref_assignconv_cast_p
(op2_type
,
13366 ; /* Nothing to do here */
13368 /* Else we have an error figure what can't be converted into
13369 what and report the error */
13373 t1
= xstrdup
(lang_printable_name
(op1_type
, 0));
13374 parse_error_context
13376 "Incompatible type for `%s'. Can't convert `%s' to `%s'",
13377 operator_string
(node
), t1
,
13378 lang_printable_name
(op2_type
, 0));
13380 TREE_TYPE
(node
) = boolean_type_node
;
13384 prom_type
= boolean_type_node
;
13389 return error_mark_node
;
13391 TREE_OPERAND
(node
, 0) = op1
;
13392 TREE_OPERAND
(node
, 1) = op2
;
13393 TREE_TYPE
(node
) = prom_type
;
13394 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13396 if
(flag_emit_xref
)
13399 /* fold does not respect side-effect order as required for Java but not C.
13400 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
13403 if
(flag_emit_class_files ?
(TREE_CONSTANT
(op1
) && TREE_CONSTANT
(op2
))
13404 : ! TREE_SIDE_EFFECTS
(node
))
13405 node
= fold
(node
);
13409 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
13410 zero value, the value of CSTE comes after the valude of STRING */
13413 do_merge_string_cste
(cste
, string, string_len
, after
)
13415 const char *string;
13416 int string_len
, after
;
13418 const char *old
= TREE_STRING_POINTER
(cste
);
13419 int old_len
= TREE_STRING_LENGTH
(cste
);
13420 int len
= old_len
+ string_len
;
13421 char *new
= alloca
(len
+1);
13425 memcpy
(new
, string, string_len
);
13426 memcpy
(&new
[string_len
], old
, old_len
);
13430 memcpy
(new
, old
, old_len
);
13431 memcpy
(&new
[old_len
], string, string_len
);
13434 return build_string
(len
, new
);
13437 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
13438 new STRING_CST on success, NULL_TREE on failure */
13441 merge_string_cste
(op1
, op2
, after
)
13445 /* Handle two string constants right away */
13446 if
(TREE_CODE
(op2
) == STRING_CST
)
13447 return do_merge_string_cste
(op1
, TREE_STRING_POINTER
(op2
),
13448 TREE_STRING_LENGTH
(op2
), after
);
13450 /* Reasonable integer constant can be treated right away */
13451 if
(TREE_CODE
(op2
) == INTEGER_CST
&& !TREE_CONSTANT_OVERFLOW
(op2
))
13453 static const char *boolean_true
= "true";
13454 static const char *boolean_false
= "false";
13455 static const char *null_pointer
= "null";
13457 const char *string;
13459 if
(op2
== boolean_true_node
)
13460 string = boolean_true
;
13461 else if
(op2
== boolean_false_node
)
13462 string = boolean_false
;
13463 else if
(op2
== null_pointer_node
)
13464 string = null_pointer
;
13465 else if
(TREE_TYPE
(op2
) == char_type_node
)
13467 ch
[0] = (char )TREE_INT_CST_LOW
(op2
);
13472 string = print_int_node
(op2
);
13474 return do_merge_string_cste
(op1
, string, strlen
(string), after
);
13479 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
13480 has to be a STRING_CST and the other part must be a STRING_CST or a
13481 INTEGRAL constant. Return a new STRING_CST if the operation
13482 succeed, NULL_TREE otherwise.
13484 If the case we want to optimize for space, we might want to return
13485 NULL_TREE for each invocation of this routine. FIXME */
13488 string_constant_concatenation
(op1
, op2
)
13491 if
(TREE_CODE
(op1
) == STRING_CST ||
(TREE_CODE
(op2
) == STRING_CST
))
13496 string = (TREE_CODE
(op1
) == STRING_CST ? op1
: op2
);
13497 rest
= (string == op1 ? op2
: op1
);
13498 invert
= (string == op1 ?
0 : 1 );
13500 /* Walk REST, only if it looks reasonable */
13501 if
(TREE_CODE
(rest
) != STRING_CST
13502 && !IS_CRAFTED_STRING_BUFFER_P
(rest
)
13503 && !JSTRING_TYPE_P
(TREE_TYPE
(rest
))
13504 && TREE_CODE
(rest
) == EXPR_WITH_FILE_LOCATION
)
13506 rest
= java_complete_tree
(rest
);
13507 if
(rest
== error_mark_node
)
13508 return error_mark_node
;
13509 rest
= fold
(rest
);
13511 return merge_string_cste
(string, rest
, invert
);
13516 /* Implement the `+' operator. Does static optimization if possible,
13517 otherwise create (if necessary) and append elements to a
13518 StringBuffer. The StringBuffer will be carried around until it is
13519 used for a function call or an assignment. Then toString() will be
13520 called on it to turn it into a String object. */
13523 build_string_concatenation
(op1
, op2
)
13527 int side_effects
= TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13529 if
(flag_emit_xref
)
13530 return build
(PLUS_EXPR
, string_type_node
, op1
, op2
);
13532 /* Try to do some static optimization */
13533 if
((result
= string_constant_concatenation
(op1
, op2
)))
13536 /* Discard empty strings on either side of the expression */
13537 if
(TREE_CODE
(op1
) == STRING_CST
&& TREE_STRING_LENGTH
(op1
) == 0)
13542 else if
(TREE_CODE
(op2
) == STRING_CST
&& TREE_STRING_LENGTH
(op2
) == 0)
13545 /* If operands are string constant, turn then into object references */
13546 if
(TREE_CODE
(op1
) == STRING_CST
)
13547 op1
= patch_string_cst
(op1
);
13548 if
(op2
&& TREE_CODE
(op2
) == STRING_CST
)
13549 op2
= patch_string_cst
(op2
);
13551 /* If either one of the constant is null and the other non null
13552 operand is a String object, return it. */
13553 if
(JSTRING_TYPE_P
(TREE_TYPE
(op1
)) && !op2
)
13556 /* If OP1 isn't already a StringBuffer, create and
13557 initialize a new one */
13558 if
(!IS_CRAFTED_STRING_BUFFER_P
(op1
))
13560 /* Two solutions here:
13561 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
13562 2) OP1 is something else, we call new StringBuffer().append(OP1). */
13563 if
(TREE_CONSTANT
(op1
) && JSTRING_TYPE_P
(TREE_TYPE
(op1
)))
13564 op1
= BUILD_STRING_BUFFER
(op1
);
13567 tree aNew
= BUILD_STRING_BUFFER
(NULL_TREE
);
13568 op1
= make_qualified_primary
(aNew
, BUILD_APPEND
(op1
), 0);
13574 /* OP1 is no longer the last node holding a crafted StringBuffer */
13575 IS_CRAFTED_STRING_BUFFER_P
(op1
) = 0;
13576 /* Create a node for `{new...,xxx}.append (op2)' */
13578 op1
= make_qualified_primary
(op1
, BUILD_APPEND
(op2
), 0);
13581 /* Mark the last node holding a crafted StringBuffer */
13582 IS_CRAFTED_STRING_BUFFER_P
(op1
) = 1;
13584 TREE_SIDE_EFFECTS
(op1
) = side_effects
;
13588 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
13589 StringBuffer. If no string were found to be patched, return
13593 patch_string
(node
)
13596 if
(node
== error_mark_node
)
13597 return error_mark_node
;
13598 if
(TREE_CODE
(node
) == STRING_CST
)
13599 return patch_string_cst
(node
);
13600 else if
(IS_CRAFTED_STRING_BUFFER_P
(node
))
13602 int saved
= ctxp
->explicit_constructor_p
;
13603 tree invoke
= build_method_invocation
(wfl_to_string
, NULL_TREE
);
13605 /* Temporary disable forbid the use of `this'. */
13606 ctxp
->explicit_constructor_p
= 0;
13607 ret
= java_complete_tree
(make_qualified_primary
(node
, invoke
, 0));
13608 /* String concatenation arguments must be evaluated in order too. */
13609 ret
= force_evaluation_order
(ret
);
13610 /* Restore it at its previous value */
13611 ctxp
->explicit_constructor_p
= saved
;
13617 /* Build the internal representation of a string constant. */
13620 patch_string_cst
(node
)
13624 if
(! flag_emit_class_files
)
13626 node
= get_identifier
(TREE_STRING_POINTER
(node
));
13627 location
= alloc_name_constant
(CONSTANT_String
, node
);
13628 node
= build_ref_from_constant_pool
(location
);
13630 TREE_TYPE
(node
) = string_ptr_type_node
;
13631 TREE_CONSTANT
(node
) = 1;
13635 /* Build an incomplete unary operator expression. */
13638 build_unaryop
(op_token
, op_location
, op1
)
13639 int op_token
, op_location
;
13646 case PLUS_TK
: op
= UNARY_PLUS_EXPR
; break
;
13647 case MINUS_TK
: op
= NEGATE_EXPR
; break
;
13648 case NEG_TK
: op
= TRUTH_NOT_EXPR
; break
;
13649 case NOT_TK
: op
= BIT_NOT_EXPR
; break
;
13653 unaryop
= build1
(op
, NULL_TREE
, op1
);
13654 TREE_SIDE_EFFECTS
(unaryop
) = 1;
13655 /* Store the location of the operator, for better error report. The
13656 string of the operator will be rebuild based on the OP value. */
13657 EXPR_WFL_LINECOL
(unaryop
) = op_location
;
13661 /* Special case for the ++/-- operators, since they require an extra
13662 argument to build, which is set to NULL and patched
13663 later. IS_POST_P is 1 if the operator, 0 otherwise. */
13666 build_incdec
(op_token
, op_location
, op1
, is_post_p
)
13667 int op_token
, op_location
;
13671 static enum tree_code lookup
[2][2] =
13673 { PREDECREMENT_EXPR
, PREINCREMENT_EXPR
, },
13674 { POSTDECREMENT_EXPR
, POSTINCREMENT_EXPR
, },
13676 tree node
= build
(lookup
[is_post_p
][(op_token
- DECR_TK
)],
13677 NULL_TREE
, op1
, NULL_TREE
);
13678 TREE_SIDE_EFFECTS
(node
) = 1;
13679 /* Store the location of the operator, for better error report. The
13680 string of the operator will be rebuild based on the OP value. */
13681 EXPR_WFL_LINECOL
(node
) = op_location
;
13685 /* Build an incomplete cast operator, based on the use of the
13686 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
13687 set. java_complete_tree is trained to walk a CONVERT_EXPR even
13688 though its type is already set. */
13691 build_cast
(location
, type
, exp
)
13695 tree node
= build1
(CONVERT_EXPR
, type
, exp
);
13696 EXPR_WFL_LINECOL
(node
) = location
;
13700 /* Build an incomplete class reference operator. */
13702 build_incomplete_class_ref
(location
, class_name
)
13706 tree node
= build1
(CLASS_LITERAL
, NULL_TREE
, class_name
);
13707 EXPR_WFL_LINECOL
(node
) = location
;
13711 /* Complete an incomplete class reference operator. */
13713 patch_incomplete_class_ref
(node
)
13716 tree type
= TREE_OPERAND
(node
, 0);
13719 if
(!(ref_type
= resolve_type_during_patch
(type
)))
13720 return error_mark_node
;
13722 if
(!flag_emit_class_files || JPRIMITIVE_TYPE_P
(ref_type
))
13724 /* A class referenced by `foo.class' is initialized. */
13725 return build_class_init
(ref_type
, build_class_ref
(ref_type
));
13728 /* If we're emitting class files and we have to deal with non
13729 primitive types, we invoke (and consider generating) the
13730 synthetic static method `class$'. */
13731 if
(!TYPE_DOT_CLASS
(current_class
))
13732 build_dot_class_method
(current_class
);
13733 ref_type
= build_dot_class_method_invocation
(ref_type
);
13734 return java_complete_tree
(ref_type
);
13737 /* 15.14 Unary operators. We return error_mark_node in case of error,
13738 but preserve the type of NODE if the type is fixed. */
13741 patch_unaryop
(node
, wfl_op
)
13745 tree op
= TREE_OPERAND
(node
, 0);
13746 tree op_type
= TREE_TYPE
(op
);
13747 tree prom_type
= NULL_TREE
, value
, decl
;
13748 int outer_field_flag
= 0;
13749 int code
= TREE_CODE
(node
);
13750 int error_found
= 0;
13752 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
13756 /* 15.13.2 Postfix Increment Operator ++ */
13757 case POSTINCREMENT_EXPR
:
13758 /* 15.13.3 Postfix Increment Operator -- */
13759 case POSTDECREMENT_EXPR
:
13760 /* 15.14.1 Prefix Increment Operator ++ */
13761 case PREINCREMENT_EXPR
:
13762 /* 15.14.2 Prefix Decrement Operator -- */
13763 case PREDECREMENT_EXPR
:
13764 op
= decl
= strip_out_static_field_access_decl
(op
);
13765 outer_field_flag
= outer_field_expanded_access_p
(op
, NULL
, NULL
, NULL
);
13766 /* We might be trying to change an outer field accessed using
13768 if
(outer_field_flag
)
13770 /* Retrieve the decl of the field we're trying to access. We
13771 do that by first retrieving the function we would call to
13772 access the field. It has been already verified that this
13773 field isn't final */
13774 if
(flag_emit_class_files
)
13775 decl
= TREE_OPERAND
(op
, 0);
13777 decl
= TREE_OPERAND
(TREE_OPERAND
(TREE_OPERAND
(op
, 0), 0), 0);
13778 decl
= DECL_FUNCTION_ACCESS_DECL
(decl
);
13780 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
13781 else if
(!JDECL_P
(decl
)
13782 && TREE_CODE
(decl
) != COMPONENT_REF
13783 && !(flag_emit_class_files
&& TREE_CODE
(decl
) == ARRAY_REF
)
13784 && TREE_CODE
(decl
) != INDIRECT_REF
13785 && !(TREE_CODE
(decl
) == COMPOUND_EXPR
13786 && TREE_OPERAND
(decl
, 1)
13787 && (TREE_CODE
(TREE_OPERAND
(decl
, 1)) == INDIRECT_REF
)))
13790 /* Before screaming, check that we're not in fact trying to
13791 increment a optimized static final access, in which case
13792 we issue an different error message. */
13793 if
(!(TREE_CODE
(wfl_op
) == EXPR_WITH_FILE_LOCATION
13794 && resolve_expression_name
(wfl_op
, &lvalue
)
13795 && check_final_assignment
(lvalue
, wfl_op
)))
13796 parse_error_context
(wfl_operator
, "Invalid argument to `%s'",
13797 operator_string
(node
));
13798 TREE_TYPE
(node
) = error_mark_node
;
13802 if
(check_final_assignment
(op
, wfl_op
))
13805 /* From now on, we know that op if a variable and that it has a
13806 valid wfl. We use wfl_op to locate errors related to the
13808 else if
(!JNUMERIC_TYPE_P
(op_type
))
13810 parse_error_context
13811 (wfl_op
, "Invalid argument type `%s' to `%s'",
13812 lang_printable_name
(op_type
, 0), operator_string
(node
));
13813 TREE_TYPE
(node
) = error_mark_node
;
13818 /* Before the addition, binary numeric promotion is performed on
13819 both operands, if really necessary */
13820 if
(JINTEGRAL_TYPE_P
(op_type
))
13822 value
= build_int_2
(1, 0);
13823 TREE_TYPE
(value
) = TREE_TYPE
(node
) = op_type
;
13827 value
= build_int_2
(1, 0);
13829 binary_numeric_promotion
(op_type
,
13830 TREE_TYPE
(value
), &op
, &value
);
13833 /* We remember we might be accessing an outer field */
13834 if
(outer_field_flag
)
13836 /* We re-generate an access to the field */
13837 value
= build
(PLUS_EXPR
, TREE_TYPE
(op
),
13838 build_outer_field_access
(wfl_op
, decl
), value
);
13840 /* And we patch the original access$() into a write
13841 with plus_op as a rhs */
13842 return outer_field_access_fix
(node
, op
, value
);
13845 /* And write back into the node. */
13846 TREE_OPERAND
(node
, 0) = op
;
13847 TREE_OPERAND
(node
, 1) = value
;
13848 /* Convert the overall back into its original type, if
13849 necessary, and return */
13850 if
(JINTEGRAL_TYPE_P
(op_type
))
13851 return fold
(node
);
13853 return fold
(convert
(op_type
, node
));
13857 /* 15.14.3 Unary Plus Operator + */
13858 case UNARY_PLUS_EXPR
:
13859 /* 15.14.4 Unary Minus Operator - */
13861 if
(!JNUMERIC_TYPE_P
(op_type
))
13863 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op_type
);
13864 TREE_TYPE
(node
) = error_mark_node
;
13867 /* Unary numeric promotion is performed on operand */
13870 op
= do_unary_numeric_promotion
(op
);
13871 prom_type
= TREE_TYPE
(op
);
13872 if
(code
== UNARY_PLUS_EXPR
)
13877 /* 15.14.5 Bitwise Complement Operator ~ */
13879 if
(!JINTEGRAL_TYPE_P
(op_type
))
13881 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op_type
);
13882 TREE_TYPE
(node
) = error_mark_node
;
13887 op
= do_unary_numeric_promotion
(op
);
13888 prom_type
= TREE_TYPE
(op
);
13892 /* 15.14.6 Logical Complement Operator ! */
13893 case TRUTH_NOT_EXPR
:
13894 if
(TREE_CODE
(op_type
) != BOOLEAN_TYPE
)
13896 ERROR_CANT_CONVERT_TO_BOOLEAN
(wfl_operator
, node
, op_type
);
13897 /* But the type is known. We will report an error if further
13898 attempt of a assignment is made with this rhs */
13899 TREE_TYPE
(node
) = boolean_type_node
;
13903 prom_type
= boolean_type_node
;
13906 /* 15.15 Cast Expression */
13908 value
= patch_cast
(node
, wfl_operator
);
13909 if
(value
== error_mark_node
)
13911 /* If this cast is part of an assignment, we tell the code
13912 that deals with it not to complain about a mismatch,
13913 because things have been cast, anyways */
13914 TREE_TYPE
(node
) = error_mark_node
;
13919 value
= fold
(value
);
13920 TREE_SIDE_EFFECTS
(value
) = TREE_SIDE_EFFECTS
(op
);
13927 return error_mark_node
;
13929 /* There are cases where node has been replaced by something else
13930 and we don't end up returning here: UNARY_PLUS_EXPR,
13931 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
13932 TREE_OPERAND
(node
, 0) = fold
(op
);
13933 TREE_TYPE
(node
) = prom_type
;
13934 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(op
);
13935 return fold
(node
);
13938 /* Generic type resolution that sometimes takes place during node
13939 patching. Returned the resolved type or generate an error
13940 message. Return the resolved type or NULL_TREE. */
13943 resolve_type_during_patch
(type
)
13946 if
(unresolved_type_p
(type
, NULL
))
13948 tree type_decl
= resolve_and_layout
(EXPR_WFL_NODE
(type
), type
);
13951 parse_error_context
(type
,
13952 "Class `%s' not found in type declaration",
13953 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(type
)));
13958 CLASS_LOADED_P
(TREE_TYPE
(type_decl
)) = 1;
13959 return TREE_TYPE
(type_decl
);
13964 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
13965 found. Otherwise NODE or something meant to replace it is returned. */
13968 patch_cast
(node
, wfl_op
)
13972 tree op
= TREE_OPERAND
(node
, 0);
13973 tree op_type
= TREE_TYPE
(op
);
13974 tree cast_type
= TREE_TYPE
(node
);
13977 /* First resolve OP_TYPE if unresolved */
13978 if
(!(cast_type
= resolve_type_during_patch
(cast_type
)))
13979 return error_mark_node
;
13981 /* Check on cast that are proven correct at compile time */
13982 if
(JNUMERIC_TYPE_P
(cast_type
) && JNUMERIC_TYPE_P
(op_type
))
13985 if
(cast_type
== op_type
)
13988 /* float and double type are converted to the original type main
13989 variant and then to the target type. */
13990 if
(JFLOAT_TYPE_P
(op_type
) && TREE_CODE
(cast_type
) == CHAR_TYPE
)
13991 op
= convert
(integer_type_node
, op
);
13993 /* Try widening/narowwing convertion. Potentially, things need
13994 to be worked out in gcc so we implement the extreme cases
13995 correctly. fold_convert() needs to be fixed. */
13996 return convert
(cast_type
, op
);
13999 /* It's also valid to cast a boolean into a boolean */
14000 if
(op_type
== boolean_type_node
&& cast_type
== boolean_type_node
)
14003 /* null can be casted to references */
14004 if
(op
== null_pointer_node
&& JREFERENCE_TYPE_P
(cast_type
))
14005 return build_null_of_type
(cast_type
);
14007 /* The remaining legal casts involve conversion between reference
14008 types. Check for their compile time correctness. */
14009 if
(JREFERENCE_TYPE_P
(op_type
) && JREFERENCE_TYPE_P
(cast_type
)
14010 && valid_ref_assignconv_cast_p
(op_type
, cast_type
, 1))
14012 TREE_TYPE
(node
) = promote_type
(cast_type
);
14013 /* Now, the case can be determined correct at compile time if
14014 OP_TYPE can be converted into CAST_TYPE by assignment
14015 conversion (5.2) */
14017 if
(valid_ref_assignconv_cast_p
(op_type
, cast_type
, 0))
14019 TREE_SET_CODE
(node
, NOP_EXPR
);
14023 if
(flag_emit_class_files
)
14025 TREE_SET_CODE
(node
, CONVERT_EXPR
);
14029 /* The cast requires a run-time check */
14030 return build
(CALL_EXPR
, promote_type
(cast_type
),
14031 build_address_of
(soft_checkcast_node
),
14032 tree_cons
(NULL_TREE
, build_class_ref
(cast_type
),
14033 build_tree_list
(NULL_TREE
, op
)),
14037 /* Any other casts are proven incorrect at compile time */
14038 t1
= xstrdup
(lang_printable_name
(op_type
, 0));
14039 parse_error_context
(wfl_op
, "Invalid cast from `%s' to `%s'",
14040 t1
, lang_printable_name
(cast_type
, 0));
14042 return error_mark_node
;
14045 /* Build a null constant and give it the type TYPE. */
14048 build_null_of_type
(type
)
14051 tree node
= build_int_2
(0, 0);
14052 TREE_TYPE
(node
) = promote_type
(type
);
14056 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
14057 a list of indices. */
14059 build_array_ref
(location
, array
, index
)
14063 tree node
= build
(ARRAY_REF
, NULL_TREE
, array
, index
);
14064 EXPR_WFL_LINECOL
(node
) = location
;
14068 /* 15.12 Array Access Expression */
14071 patch_array_ref
(node
)
14074 tree array
= TREE_OPERAND
(node
, 0);
14075 tree array_type
= TREE_TYPE
(array
);
14076 tree index
= TREE_OPERAND
(node
, 1);
14077 tree index_type
= TREE_TYPE
(index
);
14078 int error_found
= 0;
14080 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14082 if
(TREE_CODE
(array_type
) == POINTER_TYPE
)
14083 array_type
= TREE_TYPE
(array_type
);
14085 /* The array reference must be an array */
14086 if
(!TYPE_ARRAY_P
(array_type
))
14088 parse_error_context
14090 "`[]' can only be applied to arrays. It can't be applied to `%s'",
14091 lang_printable_name
(array_type
, 0));
14092 TREE_TYPE
(node
) = error_mark_node
;
14096 /* The array index undergoes unary numeric promotion. The promoted
14097 type must be int */
14098 index
= do_unary_numeric_promotion
(index
);
14099 if
(TREE_TYPE
(index
) != int_type_node
)
14101 if
(valid_cast_to_p
(index_type
, int_type_node
))
14102 parse_error_context
(wfl_operator
,
14103 "Incompatible type for `[]'. Explicit cast needed to convert `%s' to `int'",
14104 lang_printable_name
(index_type
, 0));
14106 parse_error_context
(wfl_operator
,
14107 "Incompatible type for `[]'. Can't convert `%s' to `int'",
14108 lang_printable_name
(index_type
, 0));
14109 TREE_TYPE
(node
) = error_mark_node
;
14114 return error_mark_node
;
14116 array_type
= TYPE_ARRAY_ELEMENT
(array_type
);
14118 if
(flag_emit_class_files || flag_emit_xref
)
14120 TREE_OPERAND
(node
, 0) = array
;
14121 TREE_OPERAND
(node
, 1) = index
;
14125 /* The save_expr is for correct evaluation order. It would be cleaner
14126 to use force_evaluation_order (see comment there), but that is
14127 difficult when we also have to deal with bounds checking. */
14128 if
(TREE_SIDE_EFFECTS
(index
))
14129 array
= save_expr
(array
);
14130 node
= build_java_arrayaccess
(array
, array_type
, index
);
14131 if
(TREE_SIDE_EFFECTS
(index
))
14132 node
= build
(COMPOUND_EXPR
, array_type
, array
, node
);
14134 TREE_TYPE
(node
) = array_type
;
14138 /* 15.9 Array Creation Expressions */
14141 build_newarray_node
(type
, dims
, extra_dims
)
14147 build
(NEW_ARRAY_EXPR
, NULL_TREE
, type
, nreverse
(dims
),
14148 build_int_2
(extra_dims
, 0));
14153 patch_newarray
(node
)
14156 tree type
= TREE_OPERAND
(node
, 0);
14157 tree dims
= TREE_OPERAND
(node
, 1);
14158 tree cdim
, array_type
;
14159 int error_found
= 0;
14161 int xdims
= TREE_INT_CST_LOW
(TREE_OPERAND
(node
, 2));
14163 /* Dimension types are verified. It's better for the types to be
14164 verified in order. */
14165 for
(cdim
= dims
, ndims
= 0; cdim
; cdim
= TREE_CHAIN
(cdim
), ndims
++ )
14168 tree dim
= TREE_VALUE
(cdim
);
14170 /* Dim might have been saved during its evaluation */
14171 dim
= (TREE_CODE
(dim
) == SAVE_EXPR ? TREE_OPERAND
(dim
, 0) : dim
);
14173 /* The type of each specified dimension must be an integral type. */
14174 if
(!JINTEGRAL_TYPE_P
(TREE_TYPE
(dim
)))
14177 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
14178 promoted type must be int. */
14181 dim
= do_unary_numeric_promotion
(dim
);
14182 if
(TREE_TYPE
(dim
) != int_type_node
)
14186 /* Report errors on types here */
14189 parse_error_context
14190 (TREE_PURPOSE
(cdim
),
14191 "Incompatible type for dimension in array creation expression. %s convert `%s' to `int'",
14192 (valid_cast_to_p
(TREE_TYPE
(dim
), int_type_node
) ?
14193 "Explicit cast needed to" : "Can't"),
14194 lang_printable_name
(TREE_TYPE
(dim
), 0));
14198 TREE_PURPOSE
(cdim
) = NULL_TREE
;
14201 /* Resolve array base type if unresolved */
14202 if
(!(type
= resolve_type_during_patch
(type
)))
14207 /* We don't want further evaluation of this bogus array creation
14209 TREE_TYPE
(node
) = error_mark_node
;
14210 return error_mark_node
;
14213 /* Set array_type to the actual (promoted) array type of the result. */
14214 if
(TREE_CODE
(type
) == RECORD_TYPE
)
14215 type
= build_pointer_type
(type
);
14216 while
(--xdims
>= 0)
14218 type
= promote_type
(build_java_array_type
(type
, -1));
14220 dims
= nreverse
(dims
);
14222 for
(cdim
= dims
; cdim
; cdim
= TREE_CHAIN
(cdim
))
14226 = build_java_array_type
(type
,
14227 TREE_CODE
(cdim
) == INTEGER_CST
14228 ?
(HOST_WIDE_INT
) TREE_INT_CST_LOW
(cdim
)
14230 array_type
= promote_type
(array_type
);
14232 dims
= nreverse
(dims
);
14234 /* The node is transformed into a function call. Things are done
14235 differently according to the number of dimensions. If the number
14236 of dimension is equal to 1, then the nature of the base type
14237 (primitive or not) matters. */
14239 return build_new_array
(type
, TREE_VALUE
(dims
));
14241 /* Can't reuse what's already written in expr.c because it uses the
14242 JVM stack representation. Provide a build_multianewarray. FIXME */
14243 return build
(CALL_EXPR
, array_type
,
14244 build_address_of
(soft_multianewarray_node
),
14245 tree_cons
(NULL_TREE
, build_class_ref
(TREE_TYPE
(array_type
)),
14246 tree_cons
(NULL_TREE
,
14247 build_int_2
(ndims
, 0), dims
)),
14251 /* 10.6 Array initializer. */
14253 /* Build a wfl for array element that don't have one, so we can
14254 pin-point errors. */
14257 maybe_build_array_element_wfl
(node
)
14260 if
(TREE_CODE
(node
) != EXPR_WITH_FILE_LOCATION
)
14261 return build_expr_wfl
(NULL_TREE
, ctxp
->filename
,
14262 ctxp
->elc.line
, ctxp
->elc.prev_col
);
14267 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
14268 identification of initialized arrays easier to detect during walk
14272 build_new_array_init
(location
, values
)
14276 tree constructor
= build
(CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, values
);
14277 tree to_return
= build1
(NEW_ARRAY_INIT
, NULL_TREE
, constructor
);
14278 EXPR_WFL_LINECOL
(to_return
) = location
;
14282 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
14283 occurred. Otherwise return NODE after having set its type
14287 patch_new_array_init
(type
, node
)
14290 int error_seen
= 0;
14291 tree current
, element_type
;
14292 HOST_WIDE_INT length
;
14293 int all_constant
= 1;
14294 tree init
= TREE_OPERAND
(node
, 0);
14296 if
(TREE_CODE
(type
) != POINTER_TYPE ||
! TYPE_ARRAY_P
(TREE_TYPE
(type
)))
14298 parse_error_context
(node
,
14299 "Invalid array initializer for non-array type `%s'",
14300 lang_printable_name
(type
, 1));
14301 return error_mark_node
;
14303 type
= TREE_TYPE
(type
);
14304 element_type
= TYPE_ARRAY_ELEMENT
(type
);
14306 CONSTRUCTOR_ELTS
(init
) = nreverse
(CONSTRUCTOR_ELTS
(init
));
14308 for
(length
= 0, current
= CONSTRUCTOR_ELTS
(init
);
14309 current
; length
++, current
= TREE_CHAIN
(current
))
14311 tree elt
= TREE_VALUE
(current
);
14312 if
(elt
== NULL_TREE || TREE_CODE
(elt
) != NEW_ARRAY_INIT
)
14314 error_seen |
= array_constructor_check_entry
(element_type
, current
);
14315 elt
= TREE_VALUE
(current
);
14316 /* When compiling to native code, STRING_CST is converted to
14317 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
14318 if
(! TREE_CONSTANT
(elt
) || TREE_CODE
(elt
) == INDIRECT_REF
)
14323 TREE_VALUE
(current
) = patch_new_array_init
(element_type
, elt
);
14324 TREE_PURPOSE
(current
) = NULL_TREE
;
14327 if
(elt
&& TREE_CODE
(elt
) == TREE_LIST
14328 && TREE_VALUE
(elt
) == error_mark_node
)
14333 return error_mark_node
;
14335 /* Create a new type. We can't reuse the one we have here by
14336 patching its dimension because it originally is of dimension -1
14337 hence reused by gcc. This would prevent triangular arrays. */
14338 type
= build_java_array_type
(element_type
, length
);
14339 TREE_TYPE
(init
) = TREE_TYPE
(TREE_CHAIN
(TREE_CHAIN
(TYPE_FIELDS
(type
))));
14340 TREE_TYPE
(node
) = promote_type
(type
);
14341 TREE_CONSTANT
(init
) = all_constant
;
14342 TREE_CONSTANT
(node
) = all_constant
;
14346 /* Verify that one entry of the initializer element list can be
14347 assigned to the array base type. Report 1 if an error occurred, 0
14351 array_constructor_check_entry
(type
, entry
)
14354 char *array_type_string
= NULL
; /* For error reports */
14355 tree value
, type_value
, new_value
, wfl_value
, patched
;
14356 int error_seen
= 0;
14358 new_value
= NULL_TREE
;
14359 wfl_value
= TREE_VALUE
(entry
);
14361 value
= java_complete_tree
(TREE_VALUE
(entry
));
14362 /* patch_string return error_mark_node if arg is error_mark_node */
14363 if
((patched
= patch_string
(value
)))
14365 if
(value
== error_mark_node
)
14368 type_value
= TREE_TYPE
(value
);
14370 /* At anytime, try_builtin_assignconv can report a warning on
14371 constant overflow during narrowing. */
14372 SET_WFL_OPERATOR
(wfl_operator
, TREE_PURPOSE
(entry
), wfl_value
);
14373 new_value
= try_builtin_assignconv
(wfl_operator
, type
, value
);
14374 if
(!new_value
&& (new_value
= try_reference_assignconv
(type
, value
)))
14375 type_value
= promote_type
(type
);
14377 /* Check and report errors */
14380 const char *msg
= (!valid_cast_to_p
(type_value
, type
) ?
14381 "Can't" : "Explicit cast needed to");
14382 if
(!array_type_string
)
14383 array_type_string
= xstrdup
(lang_printable_name
(type
, 1));
14384 parse_error_context
14385 (wfl_operator
, "Incompatible type for array. %s convert `%s' to `%s'",
14386 msg
, lang_printable_name
(type_value
, 1), array_type_string
);
14392 new_value
= maybe_build_primttype_type_ref
(new_value
, wfl_value
);
14393 TREE_VALUE
(entry
) = new_value
;
14396 if
(array_type_string
)
14397 free
(array_type_string
);
14399 TREE_PURPOSE
(entry
) = NULL_TREE
;
14404 build_this
(location
)
14407 tree node
= build_wfl_node
(this_identifier_node
);
14408 TREE_SET_CODE
(node
, THIS_EXPR
);
14409 EXPR_WFL_LINECOL
(node
) = location
;
14413 /* 14.15 The return statement. It builds a modify expression that
14414 assigns the returned value to the RESULT_DECL that hold the value
14418 build_return
(location
, op
)
14422 tree node
= build1
(RETURN_EXPR
, NULL_TREE
, op
);
14423 EXPR_WFL_LINECOL
(node
) = location
;
14424 node
= build_debugable_stmt
(location
, node
);
14429 patch_return
(node
)
14432 tree return_exp
= TREE_OPERAND
(node
, 0);
14433 tree meth
= current_function_decl
;
14434 tree mtype
= TREE_TYPE
(TREE_TYPE
(current_function_decl
));
14435 int error_found
= 0;
14437 TREE_TYPE
(node
) = error_mark_node
;
14438 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14440 /* It's invalid to have a return value within a function that is
14441 declared with the keyword void or that is a constructor */
14442 if
(return_exp
&& (mtype
== void_type_node || DECL_CONSTRUCTOR_P
(meth
)))
14445 /* It's invalid to use a return statement in a static block */
14446 if
(DECL_CLINIT_P
(current_function_decl
))
14449 /* It's invalid to have a no return value within a function that
14450 isn't declared with the keyword `void' */
14451 if
(!return_exp
&& (mtype
!= void_type_node
&& !DECL_CONSTRUCTOR_P
(meth
)))
14454 if
(in_instance_initializer
)
14459 if
(in_instance_initializer
)
14460 parse_error_context
(wfl_operator
,
14461 "`return' inside instance initializer");
14463 else if
(DECL_CLINIT_P
(current_function_decl
))
14464 parse_error_context
(wfl_operator
,
14465 "`return' inside static initializer");
14467 else if
(!DECL_CONSTRUCTOR_P
(meth
))
14469 char *t
= xstrdup
(lang_printable_name
(mtype
, 0));
14470 parse_error_context
(wfl_operator
,
14471 "`return' with%s value from `%s %s'",
14472 (error_found
== 1 ?
"" : "out"),
14473 t
, lang_printable_name
(meth
, 0));
14477 parse_error_context
(wfl_operator
,
14478 "`return' with value from constructor `%s'",
14479 lang_printable_name
(meth
, 0));
14480 return error_mark_node
;
14483 /* If we have a return_exp, build a modify expression and expand
14484 it. Note: at that point, the assignment is declared valid, but we
14485 may want to carry some more hacks */
14488 tree exp
= java_complete_tree
(return_exp
);
14489 tree modify
, patched
;
14491 /* If the function returned value and EXP are booleans, EXP has
14492 to be converted into the type of DECL_RESULT, which is integer
14493 (see complete_start_java_method) */
14494 if
(TREE_TYPE
(exp
) == boolean_type_node
&&
14495 TREE_TYPE
(TREE_TYPE
(meth
)) == boolean_type_node
)
14496 exp
= convert_to_integer
(TREE_TYPE
(DECL_RESULT
(meth
)), exp
);
14498 /* `null' can be assigned to a function returning a reference */
14499 if
(JREFERENCE_TYPE_P
(TREE_TYPE
(TREE_TYPE
(meth
))) &&
14500 exp
== null_pointer_node
)
14501 exp
= build_null_of_type
(TREE_TYPE
(TREE_TYPE
(meth
)));
14503 if
((patched
= patch_string
(exp
)))
14506 modify
= build
(MODIFY_EXPR
, NULL_TREE
, DECL_RESULT
(meth
), exp
);
14507 EXPR_WFL_LINECOL
(modify
) = EXPR_WFL_LINECOL
(node
);
14508 modify
= java_complete_tree
(modify
);
14510 if
(modify
!= error_mark_node
)
14512 TREE_SIDE_EFFECTS
(modify
) = 1;
14513 TREE_OPERAND
(node
, 0) = modify
;
14516 return error_mark_node
;
14518 TREE_TYPE
(node
) = void_type_node
;
14519 TREE_SIDE_EFFECTS
(node
) = 1;
14523 /* 14.8 The if Statement */
14526 build_if_else_statement
(location
, expression
, if_body
, else_body
)
14528 tree expression
, if_body
, else_body
;
14532 else_body
= empty_stmt_node
;
14533 node
= build
(COND_EXPR
, NULL_TREE
, expression
, if_body
, else_body
);
14534 EXPR_WFL_LINECOL
(node
) = location
;
14535 node
= build_debugable_stmt
(location
, node
);
14540 patch_if_else_statement
(node
)
14543 tree expression
= TREE_OPERAND
(node
, 0);
14545 TREE_TYPE
(node
) = error_mark_node
;
14546 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14548 /* The type of expression must be boolean */
14549 if
(TREE_TYPE
(expression
) != boolean_type_node
14550 && TREE_TYPE
(expression
) != promoted_boolean_type_node
)
14552 parse_error_context
14554 "Incompatible type for `if'. Can't convert `%s' to `boolean'",
14555 lang_printable_name
(TREE_TYPE
(expression
), 0));
14556 return error_mark_node
;
14559 TREE_TYPE
(node
) = void_type_node
;
14560 TREE_SIDE_EFFECTS
(node
) = 1;
14561 CAN_COMPLETE_NORMALLY
(node
)
14562 = CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1))
14563 | CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 2));
14567 /* 14.6 Labeled Statements */
14569 /* Action taken when a lableled statement is parsed. a new
14570 LABELED_BLOCK_EXPR is created. No statement is attached to the
14571 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
14574 build_labeled_block
(location
, label
)
14579 tree label_decl
, node
;
14580 if
(label
== NULL_TREE || label
== continue_identifier_node
)
14581 label_name
= label
;
14584 label_name
= merge_qualified_name
(label_id
, label
);
14585 /* Issue an error if we try to reuse a label that was previously
14587 if
(IDENTIFIER_LOCAL_VALUE
(label_name
))
14589 EXPR_WFL_LINECOL
(wfl_operator
) = location
;
14590 parse_error_context
(wfl_operator
,
14591 "Declaration of `%s' shadows a previous label declaration",
14592 IDENTIFIER_POINTER
(label
));
14593 EXPR_WFL_LINECOL
(wfl_operator
) =
14594 EXPR_WFL_LINECOL
(IDENTIFIER_LOCAL_VALUE
(label_name
));
14595 parse_error_context
(wfl_operator
,
14596 "This is the location of the previous declaration of label `%s'",
14597 IDENTIFIER_POINTER
(label
));
14598 java_error_count
--;
14602 label_decl
= create_label_decl
(label_name
);
14603 node
= build
(LABELED_BLOCK_EXPR
, NULL_TREE
, label_decl
, NULL_TREE
);
14604 EXPR_WFL_LINECOL
(node
) = location
;
14605 TREE_SIDE_EFFECTS
(node
) = 1;
14609 /* A labeled statement LBE is attached a statement. */
14612 finish_labeled_statement
(lbe
, statement
)
14613 tree lbe
; /* Labeled block expr */
14616 /* In anyways, tie the loop to its statement */
14617 LABELED_BLOCK_BODY
(lbe
) = statement
;
14618 pop_labeled_block
();
14619 POP_LABELED_BLOCK
();
14623 /* 14.10, 14.11, 14.12 Loop Statements */
14625 /* Create an empty LOOP_EXPR and make it the last in the nested loop
14629 build_new_loop
(loop_body
)
14632 tree loop
= build
(LOOP_EXPR
, NULL_TREE
, loop_body
);
14633 TREE_SIDE_EFFECTS
(loop
) = 1;
14638 /* Create a loop body according to the following structure:
14640 COMPOUND_EXPR (loop main body)
14641 EXIT_EXPR (this order is for while/for loops.
14642 LABELED_BLOCK_EXPR the order is reversed for do loops)
14643 LABEL_DECL (a continue occuring here branches at the
14644 BODY end of this labeled block)
14647 REVERSED, if non zero, tells that the loop condition expr comes
14648 after the body, like in the do-while loop.
14650 To obtain a loop, the loop body structure described above is
14651 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
14654 LABEL_DECL (use this label to exit the loop)
14656 <structure described above> */
14659 build_loop_body
(location
, condition
, reversed
)
14664 tree first
, second
, body
;
14666 condition
= build
(EXIT_EXPR
, NULL_TREE
, condition
); /* Force walk */
14667 EXPR_WFL_LINECOL
(condition
) = location
; /* For accurate error report */
14668 condition
= build_debugable_stmt
(location
, condition
);
14669 TREE_SIDE_EFFECTS
(condition
) = 1;
14671 body
= build_labeled_block
(0, continue_identifier_node
);
14672 first
= (reversed ? body
: condition
);
14673 second
= (reversed ? condition
: body
);
14675 build
(COMPOUND_EXPR
, NULL_TREE
,
14676 build
(COMPOUND_EXPR
, NULL_TREE
, first
, second
), empty_stmt_node
);
14679 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
14680 their order) on the current loop. Unlink the current loop from the
14684 finish_loop_body
(location
, condition
, body
, reversed
)
14686 tree condition
, body
;
14689 tree to_return
= ctxp
->current_loop
;
14690 tree loop_body
= LOOP_EXPR_BODY
(to_return
);
14693 tree cnode
= LOOP_EXPR_BODY_CONDITION_EXPR
(loop_body
, reversed
);
14694 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
14695 The real EXIT_EXPR is one operand further. */
14696 EXPR_WFL_LINECOL
(cnode
) = location
;
14697 /* This one is for accurate error reports */
14698 EXPR_WFL_LINECOL
(TREE_OPERAND
(cnode
, 0)) = location
;
14699 TREE_OPERAND
(TREE_OPERAND
(cnode
, 0), 0) = condition
;
14701 LOOP_EXPR_BODY_BODY_EXPR
(loop_body
, reversed
) = body
;
14706 /* Tailored version of finish_loop_body for FOR loops, when FOR
14707 loops feature the condition part */
14710 finish_for_loop
(location
, condition
, update
, body
)
14712 tree condition
, update
, body
;
14714 /* Put the condition and the loop body in place */
14715 tree loop
= finish_loop_body
(location
, condition
, body
, 0);
14716 /* LOOP is the current loop which has been now popped of the loop
14717 stack. Install the update block */
14718 LOOP_EXPR_BODY_UPDATE_BLOCK
(LOOP_EXPR_BODY
(loop
)) = update
;
14722 /* Try to find the loop a block might be related to. This comprises
14723 the case where the LOOP_EXPR is found as the second operand of a
14724 COMPOUND_EXPR, because the loop happens to have an initialization
14725 part, then expressed as the first operand of the COMPOUND_EXPR. If
14726 the search finds something, 1 is returned. Otherwise, 0 is
14727 returned. The search is assumed to start from a
14728 LABELED_BLOCK_EXPR's block. */
14731 search_loop
(statement
)
14734 if
(TREE_CODE
(statement
) == LOOP_EXPR
)
14737 if
(TREE_CODE
(statement
) == BLOCK
)
14738 statement
= BLOCK_SUBBLOCKS
(statement
);
14742 if
(statement
&& TREE_CODE
(statement
) == COMPOUND_EXPR
)
14743 while
(statement
&& TREE_CODE
(statement
) == COMPOUND_EXPR
)
14744 statement
= TREE_OPERAND
(statement
, 1);
14746 return
(TREE_CODE
(statement
) == LOOP_EXPR
14747 && FOR_LOOP_P
(statement
) ? statement
: NULL_TREE
);
14750 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
14751 returned otherwise. */
14754 labeled_block_contains_loop_p
(block
, loop
)
14760 if
(LABELED_BLOCK_BODY
(block
) == loop
)
14763 if
(FOR_LOOP_P
(loop
) && search_loop
(LABELED_BLOCK_BODY
(block
)) == loop
)
14769 /* If the loop isn't surrounded by a labeled statement, create one and
14770 insert LOOP as its body. */
14773 patch_loop_statement
(loop
)
14778 TREE_TYPE
(loop
) = void_type_node
;
14779 if
(labeled_block_contains_loop_p
(ctxp
->current_labeled_block
, loop
))
14782 loop_label
= build_labeled_block
(0, NULL_TREE
);
14783 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
14784 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
14785 LABELED_BLOCK_BODY
(loop_label
) = loop
;
14786 PUSH_LABELED_BLOCK
(loop_label
);
14790 /* 14.13, 14.14: break and continue Statements */
14792 /* Build a break or a continue statement. a null NAME indicates an
14793 unlabeled break/continue statement. */
14796 build_bc_statement
(location
, is_break
, name
)
14797 int location
, is_break
;
14800 tree break_continue
, label_block_expr
= NULL_TREE
;
14804 if
(!(label_block_expr
= IDENTIFIER_LOCAL_VALUE
14805 (merge_qualified_name
(label_id
, EXPR_WFL_NODE
(name
)))))
14806 /* Null means that we don't have a target for this named
14807 break/continue. In this case, we make the target to be the
14808 label name, so that the error can be reported accuratly in
14809 patch_bc_statement. */
14810 label_block_expr
= EXPR_WFL_NODE
(name
);
14812 /* Unlabeled break/continue will be handled during the
14813 break/continue patch operation */
14815 = build
(EXIT_BLOCK_EXPR
, NULL_TREE
, label_block_expr
, NULL_TREE
);
14817 IS_BREAK_STMT_P
(break_continue
) = is_break
;
14818 TREE_SIDE_EFFECTS
(break_continue
) = 1;
14819 EXPR_WFL_LINECOL
(break_continue
) = location
;
14820 break_continue
= build_debugable_stmt
(location
, break_continue
);
14821 return break_continue
;
14824 /* Verification of a break/continue statement. */
14827 patch_bc_statement
(node
)
14830 tree bc_label
= EXIT_BLOCK_LABELED_BLOCK
(node
), target_stmt
;
14831 tree labeled_block
= ctxp
->current_labeled_block
;
14832 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14834 /* Having an identifier here means that the target is unknown. */
14835 if
(bc_label
!= NULL_TREE
&& TREE_CODE
(bc_label
) == IDENTIFIER_NODE
)
14837 parse_error_context
(wfl_operator
, "No label definition found for `%s'",
14838 IDENTIFIER_POINTER
(bc_label
));
14839 return error_mark_node
;
14841 if
(! IS_BREAK_STMT_P
(node
))
14843 /* It's a continue statement. */
14844 for
(;; labeled_block
= TREE_CHAIN
(labeled_block
))
14846 if
(labeled_block
== NULL_TREE
)
14848 if
(bc_label
== NULL_TREE
)
14849 parse_error_context
(wfl_operator
,
14850 "`continue' must be in loop");
14852 parse_error_context
14853 (wfl_operator
, "continue label `%s' does not name a loop",
14854 IDENTIFIER_POINTER
(bc_label
));
14855 return error_mark_node
;
14857 if
((DECL_NAME
(LABELED_BLOCK_LABEL
(labeled_block
))
14858 == continue_identifier_node
)
14859 && (bc_label
== NULL_TREE
14860 || TREE_CHAIN
(labeled_block
) == bc_label
))
14862 bc_label
= labeled_block
;
14867 else if
(!bc_label
)
14869 for
(;; labeled_block
= TREE_CHAIN
(labeled_block
))
14871 if
(labeled_block
== NULL_TREE
)
14873 parse_error_context
(wfl_operator
,
14874 "`break' must be in loop or switch");
14875 return error_mark_node
;
14877 target_stmt
= LABELED_BLOCK_BODY
(labeled_block
);
14878 if
(TREE_CODE
(target_stmt
) == SWITCH_EXPR
14879 || search_loop
(target_stmt
))
14881 bc_label
= labeled_block
;
14887 EXIT_BLOCK_LABELED_BLOCK
(node
) = bc_label
;
14888 CAN_COMPLETE_NORMALLY
(bc_label
) = 1;
14890 /* Our break/continue don't return values. */
14891 TREE_TYPE
(node
) = void_type_node
;
14892 /* Encapsulate the break within a compound statement so that it's
14893 expanded all the times by expand_expr (and not clobbered
14894 sometimes, like after a if statement) */
14895 node
= add_stmt_to_compound
(NULL_TREE
, void_type_node
, node
);
14896 TREE_SIDE_EFFECTS
(node
) = 1;
14900 /* Process the exit expression belonging to a loop. Its type must be
14904 patch_exit_expr
(node
)
14907 tree expression
= TREE_OPERAND
(node
, 0);
14908 TREE_TYPE
(node
) = error_mark_node
;
14909 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14911 /* The type of expression must be boolean */
14912 if
(TREE_TYPE
(expression
) != boolean_type_node
)
14914 parse_error_context
14916 "Incompatible type for loop conditional. Can't convert `%s' to `boolean'",
14917 lang_printable_name
(TREE_TYPE
(expression
), 0));
14918 return error_mark_node
;
14920 /* Now we know things are allright, invert the condition, fold and
14922 TREE_OPERAND
(node
, 0) =
14923 fold
(build1
(TRUTH_NOT_EXPR
, boolean_type_node
, expression
));
14925 if
(! integer_zerop
(TREE_OPERAND
(node
, 0))
14926 && ctxp
->current_loop
!= NULL_TREE
14927 && TREE_CODE
(ctxp
->current_loop
) == LOOP_EXPR
)
14928 CAN_COMPLETE_NORMALLY
(ctxp
->current_loop
) = 1;
14929 if
(! integer_onep
(TREE_OPERAND
(node
, 0)))
14930 CAN_COMPLETE_NORMALLY
(node
) = 1;
14933 TREE_TYPE
(node
) = void_type_node
;
14937 /* 14.9 Switch statement */
14940 patch_switch_statement
(node
)
14943 tree se
= TREE_OPERAND
(node
, 0), se_type
;
14945 /* Complete the switch expression */
14946 se
= TREE_OPERAND
(node
, 0) = java_complete_tree
(se
);
14947 se_type
= TREE_TYPE
(se
);
14948 /* The type of the switch expression must be char, byte, short or
14950 if
(! JINTEGRAL_TYPE_P
(se_type
) || se_type
== long_type_node
)
14952 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14953 parse_error_context
(wfl_operator
,
14954 "Incompatible type for `switch'. Can't convert `%s' to `int'",
14955 lang_printable_name
(se_type
, 0));
14956 /* This is what java_complete_tree will check */
14957 TREE_OPERAND
(node
, 0) = error_mark_node
;
14958 return error_mark_node
;
14961 TREE_OPERAND
(node
, 1) = java_complete_tree
(TREE_OPERAND
(node
, 1));
14963 /* Ready to return */
14964 if
(TREE_CODE
(TREE_OPERAND
(node
, 1)) == ERROR_MARK
)
14966 TREE_TYPE
(node
) = error_mark_node
;
14967 return error_mark_node
;
14969 TREE_TYPE
(node
) = void_type_node
;
14970 TREE_SIDE_EFFECTS
(node
) = 1;
14971 CAN_COMPLETE_NORMALLY
(node
)
14972 = CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1))
14973 ||
! SWITCH_HAS_DEFAULT
(node
);
14977 /* 14.18 The try/catch statements */
14980 build_try_statement
(location
, try_block
, catches
)
14982 tree try_block
, catches
;
14984 tree node
= build
(TRY_EXPR
, NULL_TREE
, try_block
, catches
);
14985 EXPR_WFL_LINECOL
(node
) = location
;
14990 build_try_finally_statement
(location
, try_block
, finally
)
14992 tree try_block
, finally
;
14994 tree node
= build
(TRY_FINALLY_EXPR
, NULL_TREE
, try_block
, finally
);
14995 EXPR_WFL_LINECOL
(node
) = location
;
15000 patch_try_statement
(node
)
15003 int error_found
= 0;
15004 tree try
= TREE_OPERAND
(node
, 0);
15005 /* Exception handlers are considered in left to right order */
15006 tree catch
= nreverse
(TREE_OPERAND
(node
, 1));
15007 tree current
, caught_type_list
= NULL_TREE
;
15009 /* Check catch clauses, if any. Every time we find an error, we try
15010 to process the next catch clause. We process the catch clause before
15011 the try block so that when processing the try block we can check thrown
15012 exceptions againts the caught type list. */
15013 for
(current
= catch
; current
; current
= TREE_CHAIN
(current
))
15015 tree carg_decl
, carg_type
;
15016 tree sub_current
, catch_block
, catch_clause
;
15019 /* At this point, the structure of the catch clause is
15020 CATCH_EXPR (catch node)
15021 BLOCK (with the decl of the parameter)
15023 MODIFY_EXPR (assignment of the catch parameter)
15024 BLOCK (catch clause block)
15026 catch_clause
= TREE_OPERAND
(current
, 0);
15027 carg_decl
= BLOCK_EXPR_DECLS
(catch_clause
);
15028 carg_type
= TREE_TYPE
(TREE_TYPE
(carg_decl
));
15030 /* Catch clauses can't have more than one parameter declared,
15031 but it's already enforced by the grammar. Make sure that the
15032 only parameter of the clause statement in of class Throwable
15033 or a subclass of Throwable, but that was done earlier. The
15034 catch clause parameter type has also been resolved. */
15036 /* Just make sure that the catch clause parameter type inherits
15037 from java.lang.Throwable */
15038 if
(!inherits_from_p
(carg_type
, throwable_type_node
))
15040 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(current
);
15041 parse_error_context
(wfl_operator
,
15042 "Can't catch class `%s'. Catch clause parameter type must be a subclass of class `java.lang.Throwable'",
15043 lang_printable_name
(carg_type
, 0));
15048 /* Partial check for unreachable catch statement: The catch
15049 clause is reachable iff is no earlier catch block A in
15050 the try statement such that the type of the catch
15051 clause's parameter is the same as or a subclass of the
15052 type of A's parameter */
15054 for
(sub_current
= catch
;
15055 sub_current
!= current
; sub_current
= TREE_CHAIN
(sub_current
))
15057 tree sub_catch_clause
, decl
;
15058 sub_catch_clause
= TREE_OPERAND
(sub_current
, 0);
15059 decl
= BLOCK_EXPR_DECLS
(sub_catch_clause
);
15061 if
(inherits_from_p
(carg_type
, TREE_TYPE
(TREE_TYPE
(decl
))))
15063 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(current
);
15064 parse_error_context
15066 "`catch' not reached because of the catch clause at line %d",
15067 EXPR_WFL_LINENO
(sub_current
));
15068 unreachable
= error_found
= 1;
15072 /* Complete the catch clause block */
15073 catch_block
= java_complete_tree
(TREE_OPERAND
(current
, 0));
15074 if
(catch_block
== error_mark_node
)
15079 if
(CAN_COMPLETE_NORMALLY
(catch_block
))
15080 CAN_COMPLETE_NORMALLY
(node
) = 1;
15081 TREE_OPERAND
(current
, 0) = catch_block
;
15086 /* Things to do here: the exception must be thrown */
15088 /* Link this type to the caught type list */
15089 caught_type_list
= tree_cons
(NULL_TREE
, carg_type
, caught_type_list
);
15092 PUSH_EXCEPTIONS
(caught_type_list
);
15093 if
((try
= java_complete_tree
(try
)) == error_mark_node
)
15095 if
(CAN_COMPLETE_NORMALLY
(try
))
15096 CAN_COMPLETE_NORMALLY
(node
) = 1;
15099 /* Verification ends here */
15101 return error_mark_node
;
15103 TREE_OPERAND
(node
, 0) = try
;
15104 TREE_OPERAND
(node
, 1) = catch
;
15105 TREE_TYPE
(node
) = void_type_node
;
15109 /* 14.17 The synchronized Statement */
15112 patch_synchronized_statement
(node
, wfl_op1
)
15113 tree node
, wfl_op1
;
15115 tree expr
= java_complete_tree
(TREE_OPERAND
(node
, 0));
15116 tree block
= TREE_OPERAND
(node
, 1);
15118 tree tmp
, enter
, exit
, expr_decl
, assignment
;
15120 if
(expr
== error_mark_node
)
15122 block
= java_complete_tree
(block
);
15126 /* We might be trying to synchronize on a STRING_CST */
15127 if
((tmp
= patch_string
(expr
)))
15130 /* The TYPE of expr must be a reference type */
15131 if
(!JREFERENCE_TYPE_P
(TREE_TYPE
(expr
)))
15133 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15134 parse_error_context
(wfl_operator
, "Incompatible type for `synchronized'. Can't convert `%s' to `java.lang.Object'",
15135 lang_printable_name
(TREE_TYPE
(expr
), 0));
15136 return error_mark_node
;
15139 if
(flag_emit_xref
)
15141 TREE_OPERAND
(node
, 0) = expr
;
15142 TREE_OPERAND
(node
, 1) = java_complete_tree
(block
);
15143 CAN_COMPLETE_NORMALLY
(node
) = 1;
15147 /* Generate a try-finally for the synchronized statement, except
15148 that the handler that catches all throw exception calls
15149 _Jv_MonitorExit and then rethrow the exception.
15150 The synchronized statement is then implemented as:
15153 _Jv_MonitorEnter (expression)
15155 _Jv_MonitorExit (expression)
15159 e = _Jv_exception_info ();
15160 _Jv_MonitorExit (expression)
15164 expr_decl
= build_decl
(VAR_DECL
, generate_name
(), TREE_TYPE
(expr
));
15165 BUILD_MONITOR_ENTER
(enter
, expr_decl
);
15166 BUILD_MONITOR_EXIT
(exit
, expr_decl
);
15167 CAN_COMPLETE_NORMALLY
(enter
) = 1;
15168 CAN_COMPLETE_NORMALLY
(exit
) = 1;
15169 assignment
= build
(MODIFY_EXPR
, NULL_TREE
, expr_decl
, expr
);
15170 TREE_SIDE_EFFECTS
(assignment
) = 1;
15171 node
= build1
(CLEANUP_POINT_EXPR
, NULL_TREE
,
15172 build
(COMPOUND_EXPR
, NULL_TREE
,
15173 build
(WITH_CLEANUP_EXPR
, NULL_TREE
,
15174 build
(COMPOUND_EXPR
, NULL_TREE
,
15175 assignment
, enter
),
15178 node
= build_expr_block
(node
, expr_decl
);
15180 return java_complete_tree
(node
);
15183 /* 14.16 The throw Statement */
15186 patch_throw_statement
(node
, wfl_op1
)
15187 tree node
, wfl_op1
;
15189 tree expr
= TREE_OPERAND
(node
, 0);
15190 tree type
= TREE_TYPE
(expr
);
15191 int unchecked_ok
= 0, tryblock_throws_ok
= 0;
15193 /* Thrown expression must be assignable to java.lang.Throwable */
15194 if
(!try_reference_assignconv
(throwable_type_node
, expr
))
15196 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15197 parse_error_context
(wfl_operator
,
15198 "Can't throw `%s'; it must be a subclass of class `java.lang.Throwable'",
15199 lang_printable_name
(type
, 0));
15200 /* If the thrown expression was a reference, we further the
15201 compile-time check. */
15202 if
(!JREFERENCE_TYPE_P
(type
))
15203 return error_mark_node
;
15206 /* At least one of the following must be true */
15208 /* The type of the throw expression is a not checked exception,
15209 i.e. is a unchecked expression. */
15210 unchecked_ok
= IS_UNCHECKED_EXCEPTION_P
(TREE_TYPE
(type
));
15212 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15213 /* An instance can't throw a checked excetion unless that exception
15214 is explicitely declared in the `throws' clause of each
15215 constructor. This doesn't apply to anonymous classes, since they
15216 don't have declared constructors. */
15218 && in_instance_initializer
&& !ANONYMOUS_CLASS_P
(current_class
))
15221 for
(current
= TYPE_METHODS
(current_class
); current
;
15222 current
= TREE_CHAIN
(current
))
15223 if
(DECL_CONSTRUCTOR_P
(current
)
15224 && !check_thrown_exceptions_do
(TREE_TYPE
(expr
)))
15226 parse_error_context
(wfl_operator
, "Checked exception `%s' can't be thrown in instance initializer (not all declared constructor are declaring it in their `throws' clause)",
15227 lang_printable_name
(TREE_TYPE
(expr
), 0));
15228 return error_mark_node
;
15232 /* Throw is contained in a try statement and at least one catch
15233 clause can receive the thrown expression or the current method is
15234 declared to throw such an exception. Or, the throw statement is
15235 contained in a method or constructor declaration and the type of
15236 the Expression is assignable to at least one type listed in the
15237 throws clause the declaration. */
15239 tryblock_throws_ok
= check_thrown_exceptions_do
(TREE_TYPE
(expr
));
15240 if
(!(unchecked_ok || tryblock_throws_ok
))
15242 /* If there is a surrounding try block that has no matching
15243 clatch clause, report it first. A surrounding try block exits
15244 only if there is something after the list of checked
15245 exception thrown by the current function (if any). */
15246 if
(IN_TRY_BLOCK_P
())
15247 parse_error_context
(wfl_operator
, "Checked exception `%s' can't be caught by any of the catch clause(s) of the surrounding `try' block",
15248 lang_printable_name
(type
, 0));
15249 /* If we have no surrounding try statement and the method doesn't have
15250 any throws, report it now. FIXME */
15252 /* We report that the exception can't be throw from a try block
15253 in all circumstances but when the `throw' is inside a static
15255 else if
(!EXCEPTIONS_P
(currently_caught_type_list
)
15256 && !tryblock_throws_ok
)
15258 if
(DECL_CLINIT_P
(current_function_decl
))
15259 parse_error_context
(wfl_operator
,
15260 "Checked exception `%s' can't be thrown in initializer",
15261 lang_printable_name
(type
, 0));
15263 parse_error_context
(wfl_operator
,
15264 "Checked exception `%s' isn't thrown from a `try' block",
15265 lang_printable_name
(type
, 0));
15267 /* Otherwise, the current method doesn't have the appropriate
15268 throws declaration */
15270 parse_error_context
(wfl_operator
, "Checked exception `%s' doesn't match any of current method's `throws' declaration(s)",
15271 lang_printable_name
(type
, 0));
15272 return error_mark_node
;
15275 if
(! flag_emit_class_files
&& ! flag_emit_xref
)
15276 BUILD_THROW
(node
, expr
);
15278 /* If doing xrefs, keep the location where the `throw' was seen. */
15279 if
(flag_emit_xref
)
15280 EXPR_WFL_LINECOL
(node
) = EXPR_WFL_LINECOL
(wfl_op1
);
15284 /* Check that exception said to be thrown by method DECL can be
15285 effectively caught from where DECL is invoked. */
15288 check_thrown_exceptions
(location
, decl
)
15293 /* For all the unchecked exceptions thrown by DECL */
15294 for
(throws
= DECL_FUNCTION_THROWS
(decl
); throws
;
15295 throws
= TREE_CHAIN
(throws
))
15296 if
(!check_thrown_exceptions_do
(TREE_VALUE
(throws
)))
15299 /* Temporary hack to suppresses errors about cloning arrays. FIXME */
15300 if
(DECL_NAME
(decl
) == get_identifier
("clone"))
15303 EXPR_WFL_LINECOL
(wfl_operator
) = location
;
15304 if
(DECL_FINIT_P
(current_function_decl
))
15305 parse_error_context
15306 (wfl_operator
, "Exception `%s' can't be thrown in initializer",
15307 lang_printable_name
(TREE_VALUE
(throws
), 0));
15310 parse_error_context
15311 (wfl_operator
, "Exception `%s' must be caught, or it must be declared in the `throws' clause of `%s'",
15312 lang_printable_name
(TREE_VALUE
(throws
), 0),
15313 (DECL_INIT_P
(current_function_decl
) ?
15314 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(current_class
))) :
15315 IDENTIFIER_POINTER
(DECL_NAME
(current_function_decl
))));
15320 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
15321 try-catch blocks, OR is listed in the `throws' clause of the
15325 check_thrown_exceptions_do
(exception
)
15328 tree list
= currently_caught_type_list
;
15329 resolve_and_layout
(exception
, NULL_TREE
);
15330 /* First, all the nested try-catch-finally at that stage. The
15331 last element contains `throws' clause exceptions, if any. */
15332 if
(IS_UNCHECKED_EXCEPTION_P
(exception
))
15337 for
(caught
= TREE_VALUE
(list
); caught
; caught
= TREE_CHAIN
(caught
))
15338 if
(valid_ref_assignconv_cast_p
(exception
, TREE_VALUE
(caught
), 0))
15340 list
= TREE_CHAIN
(list
);
15346 purge_unchecked_exceptions
(mdecl
)
15349 tree throws
= DECL_FUNCTION_THROWS
(mdecl
);
15350 tree new
= NULL_TREE
;
15354 tree next
= TREE_CHAIN
(throws
);
15355 if
(!IS_UNCHECKED_EXCEPTION_P
(TREE_VALUE
(throws
)))
15357 TREE_CHAIN
(throws
) = new
;
15362 /* List is inverted here, but it doesn't matter */
15363 DECL_FUNCTION_THROWS
(mdecl
) = new
;
15366 /* 15.24 Conditional Operator ?: */
15369 patch_conditional_expr
(node
, wfl_cond
, wfl_op1
)
15370 tree node
, wfl_cond
, wfl_op1
;
15372 tree cond
= TREE_OPERAND
(node
, 0);
15373 tree op1
= TREE_OPERAND
(node
, 1);
15374 tree op2
= TREE_OPERAND
(node
, 2);
15375 tree resulting_type
= NULL_TREE
;
15376 tree t1
, t2
, patched
;
15377 int error_found
= 0;
15379 /* Operands of ?: might be StringBuffers crafted as a result of a
15380 string concatenation. Obtain a descent operand here. */
15381 if
((patched
= patch_string
(op1
)))
15382 TREE_OPERAND
(node
, 1) = op1
= patched
;
15383 if
((patched
= patch_string
(op2
)))
15384 TREE_OPERAND
(node
, 2) = op2
= patched
;
15386 t1
= TREE_TYPE
(op1
);
15387 t2
= TREE_TYPE
(op2
);
15389 /* The first expression must be a boolean */
15390 if
(TREE_TYPE
(cond
) != boolean_type_node
)
15392 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_cond
);
15393 parse_error_context
(wfl_operator
,
15394 "Incompatible type for `?:'. Can't convert `%s' to `boolean'",
15395 lang_printable_name
(TREE_TYPE
(cond
), 0));
15399 /* Second and third can be numeric, boolean (i.e. primitive),
15400 references or null. Anything else results in an error */
15401 if
(!((JNUMERIC_TYPE_P
(t1
) && JNUMERIC_TYPE_P
(t2
))
15402 ||
((JREFERENCE_TYPE_P
(t1
) || op1
== null_pointer_node
)
15403 && (JREFERENCE_TYPE_P
(t2
) || op2
== null_pointer_node
))
15404 ||
(t1
== boolean_type_node
&& t2
== boolean_type_node
)))
15407 /* Determine the type of the conditional expression. Same types are
15408 easy to deal with */
15410 resulting_type
= t1
;
15412 /* There are different rules for numeric types */
15413 else if
(JNUMERIC_TYPE_P
(t1
))
15415 /* if byte/short found, the resulting type is short */
15416 if
((t1
== byte_type_node
&& t2
== short_type_node
)
15417 ||
(t1
== short_type_node
&& t2
== byte_type_node
))
15418 resulting_type
= short_type_node
;
15420 /* If t1 is a constant int and t2 is of type byte, short or char
15421 and t1's value fits in t2, then the resulting type is t2 */
15422 else if
((t1
== int_type_node
&& TREE_CONSTANT
(TREE_OPERAND
(node
, 1)))
15423 && JBSC_TYPE_P
(t2
) && int_fits_type_p
(TREE_OPERAND
(node
, 1), t2
))
15424 resulting_type
= t2
;
15426 /* If t2 is a constant int and t1 is of type byte, short or char
15427 and t2's value fits in t1, then the resulting type is t1 */
15428 else if
((t2
== int_type_node
&& TREE_CONSTANT
(TREE_OPERAND
(node
, 2)))
15429 && JBSC_TYPE_P
(t1
) && int_fits_type_p
(TREE_OPERAND
(node
, 2), t1
))
15430 resulting_type
= t1
;
15432 /* Otherwise, binary numeric promotion is applied and the
15433 resulting type is the promoted type of operand 1 and 2 */
15435 resulting_type
= binary_numeric_promotion
(t1
, t2
,
15436 &TREE_OPERAND
(node
, 1),
15437 &TREE_OPERAND
(node
, 2));
15440 /* Cases of a reference and a null type */
15441 else if
(JREFERENCE_TYPE_P
(t1
) && op2
== null_pointer_node
)
15442 resulting_type
= t1
;
15444 else if
(JREFERENCE_TYPE_P
(t2
) && op1
== null_pointer_node
)
15445 resulting_type
= t2
;
15447 /* Last case: different reference types. If a type can be converted
15448 into the other one by assignment conversion, the latter
15449 determines the type of the expression */
15450 else if
((resulting_type
= try_reference_assignconv
(t1
, op2
)))
15451 resulting_type
= promote_type
(t1
);
15453 else if
((resulting_type
= try_reference_assignconv
(t2
, op1
)))
15454 resulting_type
= promote_type
(t2
);
15456 /* If we don't have any resulting type, we're in trouble */
15457 if
(!resulting_type
)
15459 char *t
= xstrdup
(lang_printable_name
(t1
, 0));
15460 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15461 parse_error_context
(wfl_operator
,
15462 "Incompatible type for `?:'. Can't convert `%s' to `%s'",
15463 t
, lang_printable_name
(t2
, 0));
15470 TREE_TYPE
(node
) = error_mark_node
;
15471 return error_mark_node
;
15474 TREE_TYPE
(node
) = resulting_type
;
15475 TREE_SET_CODE
(node
, COND_EXPR
);
15476 CAN_COMPLETE_NORMALLY
(node
) = 1;
15480 /* Wrap EXPR with code to initialize DECL's class, if appropriate. */
15483 maybe_build_class_init_for_field
(decl
, expr
)
15486 tree clas
= DECL_CONTEXT
(decl
);
15487 if
(flag_emit_class_files || flag_emit_xref
)
15490 if
(TREE_CODE
(decl
) == VAR_DECL
&& FIELD_STATIC
(decl
)
15491 && FIELD_FINAL
(decl
))
15493 tree init
= DECL_INITIAL
(decl
);
15494 if
(init
!= NULL_TREE
)
15495 init
= fold_constant_for_init
(init
, decl
);
15496 if
(init
!= NULL_TREE
&& CONSTANT_VALUE_P
(init
))
15500 return build_class_init
(clas
, expr
);
15503 /* Try to constant fold NODE.
15504 If NODE is not a constant expression, return NULL_EXPR.
15505 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
15508 fold_constant_for_init
(node
, context
)
15512 tree op0
, op1
, val
;
15513 enum tree_code code
= TREE_CODE
(node
);
15525 case TRUNC_MOD_EXPR
:
15533 case TRUTH_ANDIF_EXPR
:
15534 case TRUTH_ORIF_EXPR
:
15541 op0
= TREE_OPERAND
(node
, 0);
15542 op1
= TREE_OPERAND
(node
, 1);
15543 val
= fold_constant_for_init
(op0
, context
);
15544 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15546 TREE_OPERAND
(node
, 0) = val
;
15547 val
= fold_constant_for_init
(op1
, context
);
15548 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15550 TREE_OPERAND
(node
, 1) = val
;
15551 return patch_binop
(node
, op0
, op1
);
15553 case UNARY_PLUS_EXPR
:
15555 case TRUTH_NOT_EXPR
:
15558 op0
= TREE_OPERAND
(node
, 0);
15559 val
= fold_constant_for_init
(op0
, context
);
15560 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15562 TREE_OPERAND
(node
, 0) = val
;
15563 return patch_unaryop
(node
, op0
);
15567 val
= fold_constant_for_init
(TREE_OPERAND
(node
, 0), context
);
15568 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15570 TREE_OPERAND
(node
, 0) = val
;
15571 val
= fold_constant_for_init
(TREE_OPERAND
(node
, 1), context
);
15572 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15574 TREE_OPERAND
(node
, 1) = val
;
15575 val
= fold_constant_for_init
(TREE_OPERAND
(node
, 2), context
);
15576 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15578 TREE_OPERAND
(node
, 2) = val
;
15579 return integer_zerop
(TREE_OPERAND
(node
, 0)) ? TREE_OPERAND
(node
, 1)
15580 : TREE_OPERAND
(node
, 2);
15584 if
(! FIELD_FINAL
(node
)
15585 || DECL_INITIAL
(node
) == NULL_TREE
)
15587 val
= DECL_INITIAL
(node
);
15588 /* Guard against infinite recursion. */
15589 DECL_INITIAL
(node
) = NULL_TREE
;
15590 val
= fold_constant_for_init
(val
, node
);
15591 DECL_INITIAL
(node
) = val
;
15592 if
(!val
&& CLASS_FINAL_VARIABLE_P
(node
))
15593 DECL_FIELD_FINAL_IUD
(node
) = 0;
15596 case EXPR_WITH_FILE_LOCATION
:
15597 /* Compare java_complete_tree and resolve_expression_name. */
15598 if
(!EXPR_WFL_NODE
(node
) /* Or a PRIMARY flag ? */
15599 || TREE_CODE
(EXPR_WFL_NODE
(node
)) == IDENTIFIER_NODE
)
15601 tree name
= EXPR_WFL_NODE
(node
);
15603 if
(PRIMARY_P
(node
))
15605 else if
(! QUALIFIED_P
(name
))
15607 decl
= lookup_field_wrapper
(DECL_CONTEXT
(context
), name
);
15608 if
(decl
== NULL_TREE
15609 ||
(! FIELD_STATIC
(decl
) && ! FIELD_FINAL
(decl
)))
15611 return fold_constant_for_init
(decl
, decl
);
15615 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
15616 qualify_ambiguous_name
(node
);
15617 if
(resolve_field_access
(node
, &decl
, NULL
)
15618 && decl
!= NULL_TREE
)
15619 return fold_constant_for_init
(decl
, decl
);
15625 op0
= TREE_OPERAND
(node
, 0);
15626 val
= fold_constant_for_init
(op0
, context
);
15627 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
15629 TREE_OPERAND
(node
, 0) = val
;
15633 #ifdef USE_COMPONENT_REF
15635 case COMPONENT_REF
:
15644 #ifdef USE_COMPONENT_REF
15645 /* Context is 'T' for TypeName, 'P' for PackageName,
15646 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
15649 resolve_simple_name
(name
, context
)
15656 resolve_qualified_name
(name
, context
)
15663 /* Mark P, which is really a `struct parser_ctxt **' for GC. */
15666 mark_parser_ctxt
(p
)
15669 struct parser_ctxt
*pc
= *((struct parser_ctxt
**) p
);
15676 for
(i
= 0; i
< 11; ++i
)
15677 ggc_mark_tree
(pc
->modifier_ctx
[i
]);
15678 ggc_mark_tree
(pc
->class_type
);
15679 ggc_mark_tree
(pc
->function_decl
);
15680 ggc_mark_tree
(pc
->package
);
15681 ggc_mark_tree
(pc
->class_list
);
15682 ggc_mark_tree
(pc
->current_parsed_class
);
15683 ggc_mark_tree
(pc
->current_parsed_class_un
);
15684 ggc_mark_tree
(pc
->non_static_initialized
);
15685 ggc_mark_tree
(pc
->static_initialized
);
15686 ggc_mark_tree
(pc
->instance_initializers
);
15687 ggc_mark_tree
(pc
->import_list
);
15688 ggc_mark_tree
(pc
->import_demand_list
);
15689 ggc_mark_tree
(pc
->current_loop
);
15690 ggc_mark_tree
(pc
->current_labeled_block
);
15691 #endif /* JC1_LITE */
15694 mark_parser_ctxt
(&pc
->next
);
15700 /* Register roots with the garbage collector. */
15701 ggc_add_tree_root
(src_parse_roots
, sizeof
(src_parse_roots
) / sizeof
(tree
));