1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to
21 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
24 Java and all Java-based marks are trademarks or registered trademarks
25 of Sun Microsystems, Inc. in the United States and other countries.
26 The Free Software Foundation is independent of Sun Microsystems, Inc. */
28 /* This file parses java source code and issues a tree node image
29 suitable for code generation (byte code and targeted CPU assembly
32 The grammar conforms to the Java grammar described in "The Java(TM)
33 Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
34 1996, ISBN 0-201-63451-1"
36 The following modifications were brought to the original grammar:
38 method_body: added the rule '| block SC_TK'
39 static_initializer: added the rule 'static block SC_TK'.
41 Note: All the extra rules described above should go away when the
42 empty_statement rule will work.
44 statement_nsi: 'nsi' should be read no_short_if.
46 Some rules have been modified to support JDK1.1 inner classes
47 definitions and other extensions. */
52 #include "coretypes.h"
60 #include "pretty-print.h"
61 #include "diagnostic.h"
63 #include "java-tree.h"
74 #include "tree-inline.h"
78 /* Local function prototypes */
79 static char *java_accstring_lookup
(int);
80 static const char *accessibility_string
(int);
81 static void classitf_redefinition_error
(const char *,tree
, tree
, tree
);
82 static void variable_redefinition_error
(tree
, tree
, tree
, int);
83 static tree create_class
(int, tree
, tree
, tree
);
84 static tree create_interface
(int, tree
, tree
);
85 static void end_class_declaration
(int);
86 static tree find_field
(tree
, tree
);
87 static tree lookup_field_wrapper
(tree
, tree
);
88 static int duplicate_declaration_error_p
(tree
, tree
, tree
);
89 static void register_fields
(int, tree
, tree
);
90 static tree parser_qualified_classname
(tree
);
91 static int parser_check_super
(tree
, tree
, tree
);
92 static int parser_check_super_interface
(tree
, tree
, tree
);
93 static void check_modifiers_consistency
(int);
94 static tree lookup_cl
(tree
);
95 static tree lookup_java_method2
(tree
, tree
, int);
96 static tree method_header
(int, tree
, tree
, tree
);
97 static void fix_method_argument_names
(tree
,tree
);
98 static tree method_declarator
(tree
, tree
);
99 static void parse_warning_context
(tree cl
, const char *gmsgid
, ...
) ATTRIBUTE_GCC_DIAG
(2,3);
100 #ifdef USE_MAPPED_LOCATION
101 static void issue_warning_error_from_context
102 (source_location
, const char *gmsgid
, va_list *);
104 static void issue_warning_error_from_context
105 (tree
, const char *gmsgid
, va_list *);
107 static void parse_ctor_invocation_error
(void);
108 static tree parse_jdk1_1_error
(const char *);
109 static void complete_class_report_errors
(jdep
*);
110 static int process_imports
(void);
111 static void read_import_dir
(tree
);
112 static int find_in_imports_on_demand
(tree
, tree
);
113 static void find_in_imports
(tree
, tree
);
114 static void check_inner_class_access
(tree
, tree
, tree
);
115 static int check_pkg_class_access
(tree
, tree
, bool, tree
);
116 static tree resolve_package
(tree
, tree
*, tree
*);
117 static tree resolve_class
(tree
, tree
, tree
, tree
);
118 static void declare_local_variables
(int, tree
, tree
);
119 static void dump_java_tree
(enum tree_dump_index
, tree
);
120 static void source_start_java_method
(tree
);
121 static void source_end_java_method
(void);
122 static tree find_name_in_single_imports
(tree
);
123 static void check_abstract_method_header
(tree
);
124 static tree lookup_java_interface_method2
(tree
, tree
);
125 static tree resolve_expression_name
(tree
, tree
*);
126 static tree maybe_create_class_interface_decl
(tree
, tree
, tree
, tree
);
127 static int check_class_interface_creation
(int, int, tree
, tree
, tree
, tree
);
128 static tree patch_method_invocation
(tree
, tree
, tree
, int, int *, tree
*);
129 static tree resolve_and_layout
(tree
, tree
);
130 static tree qualify_and_find
(tree
, tree
, tree
);
131 static tree resolve_no_layout
(tree
, tree
);
132 static int invocation_mode
(tree
, int);
133 static tree find_applicable_accessible_methods_list
(int, tree
, tree
, tree
);
134 static void search_applicable_methods_list
(int, tree
, tree
, tree
, tree
*, tree
*);
135 static tree find_most_specific_methods_list
(tree
);
136 static int argument_types_convertible
(tree
, tree
);
137 static tree patch_invoke
(tree
, tree
, tree
);
138 static int maybe_use_access_method
(int, tree
*, tree
*);
139 static tree lookup_method_invoke
(int, tree
, tree
, tree
, tree
);
140 static tree register_incomplete_type
(int, tree
, tree
, tree
);
141 static tree check_inner_circular_reference
(tree
, tree
);
142 static tree check_circular_reference
(tree
);
143 static tree obtain_incomplete_type
(tree
);
144 static tree java_complete_lhs
(tree
);
145 static tree java_complete_tree
(tree
);
146 static tree maybe_generate_pre_expand_clinit
(tree
);
147 static int analyze_clinit_body
(tree
, tree
);
148 static int maybe_yank_clinit
(tree
);
149 static void start_complete_expand_method
(tree
);
150 static void java_complete_expand_method
(tree
);
151 static void java_expand_method_bodies
(tree
);
152 static int unresolved_type_p
(tree
, tree
*);
153 static void create_jdep_list
(struct parser_ctxt
*);
154 static tree build_expr_block
(tree
, tree
);
155 static tree enter_block
(void);
156 static tree exit_block
(void);
157 static tree lookup_name_in_blocks
(tree
);
158 static void maybe_absorb_scoping_blocks
(void);
159 static tree build_method_invocation
(tree
, tree
);
160 static tree build_new_invocation
(tree
, tree
);
161 static tree build_assignment
(int, int, tree
, tree
);
162 static tree build_binop
(enum tree_code
, int, tree
, tree
);
163 static tree patch_assignment
(tree
, tree
);
164 static tree patch_binop
(tree
, tree
, tree
, int);
165 static tree build_unaryop
(int, int, tree
);
166 static tree build_incdec
(int, int, tree
, int);
167 static tree patch_unaryop
(tree
, tree
);
168 static tree build_cast
(int, tree
, tree
);
169 static tree build_null_of_type
(tree
);
170 static tree patch_cast
(tree
, tree
);
171 static int valid_ref_assignconv_cast_p
(tree
, tree
, int);
172 static int valid_builtin_assignconv_identity_widening_p
(tree
, tree
);
173 static int valid_cast_to_p
(tree
, tree
);
174 static int valid_method_invocation_conversion_p
(tree
, tree
);
175 static tree try_builtin_assignconv
(tree
, tree
, tree
);
176 static tree try_reference_assignconv
(tree
, tree
);
177 static tree build_unresolved_array_type
(tree
);
178 static int build_type_name_from_array_name
(tree
, tree
*);
179 static tree build_array_from_name
(tree
, tree
, tree
, tree
*);
180 static tree build_array_ref
(int, tree
, tree
);
181 static tree patch_array_ref
(tree
);
182 #ifdef USE_MAPPED_LOCATION
183 static tree make_qualified_name
(tree
, tree
, source_location
);
185 static tree make_qualified_name
(tree
, tree
, int);
187 static tree merge_qualified_name
(tree
, tree
);
188 static tree make_qualified_primary
(tree
, tree
, int);
189 static int resolve_qualified_expression_name
(tree
, tree
*, tree
*, tree
*);
190 static void qualify_ambiguous_name
(tree
);
191 static tree resolve_field_access
(tree
, tree
*, tree
*);
192 static tree build_newarray_node
(tree
, tree
, int);
193 static tree patch_newarray
(tree
);
194 static tree resolve_type_during_patch
(tree
);
195 static tree build_this
(int);
196 static tree build_wfl_wrap
(tree
, int);
197 static tree build_return
(int, tree
);
198 static tree patch_return
(tree
);
199 static tree maybe_access_field
(tree
, tree
, tree
);
200 static int complete_function_arguments
(tree
);
201 static int check_for_static_method_reference
(tree
, tree
, tree
, tree
, tree
);
202 static int not_accessible_p
(tree
, tree
, tree
, int);
203 static void check_deprecation
(tree
, tree
);
204 static int class_in_current_package
(tree
);
205 static tree build_if_else_statement
(int, tree
, tree
, tree
);
206 static tree patch_if_else_statement
(tree
);
207 static tree add_stmt_to_block
(tree
, tree
, tree
);
208 static tree patch_exit_expr
(tree
);
209 static tree build_labeled_block
(int, tree
);
210 static tree finish_labeled_statement
(tree
, tree
);
211 static tree build_bc_statement
(int, int, tree
);
212 static tree patch_bc_statement
(tree
);
213 static tree patch_loop_statement
(tree
);
214 static tree build_new_loop
(tree
);
215 static tree build_loop_body
(int, tree
, int);
216 static tree finish_loop_body
(int, tree
, tree
, int);
217 static tree build_debugable_stmt
(int, tree
);
218 static tree finish_for_loop
(int, tree
, tree
, tree
);
219 static tree patch_switch_statement
(tree
);
220 static tree string_constant_concatenation
(tree
, tree
);
221 static tree build_string_concatenation
(tree
, tree
);
222 static tree patch_string_cst
(tree
);
223 static tree patch_string
(tree
);
224 static tree encapsulate_with_try_catch
(int, tree
, tree
, tree
);
225 #ifdef USE_MAPPED_LOCATION
226 static tree build_assertion
(source_location
, tree
, tree
);
228 static tree build_assertion
(int, tree
, tree
);
230 static tree build_try_statement
(int, tree
, tree
);
231 static tree build_try_finally_statement
(int, tree
, tree
);
232 static tree patch_try_statement
(tree
);
233 static tree patch_synchronized_statement
(tree
, tree
);
234 static tree patch_throw_statement
(tree
, tree
);
235 #ifdef USE_MAPPED_LOCATION
236 static void check_thrown_exceptions
(source_location
, tree
, tree
);
238 static void check_thrown_exceptions
(int, tree
, tree
);
240 static int check_thrown_exceptions_do
(tree
);
241 static void purge_unchecked_exceptions
(tree
);
242 static bool ctors_unchecked_throws_clause_p
(tree
);
243 static void check_concrete_throws_clauses
(tree
, tree
, tree
, tree
);
244 static void check_throws_clauses
(tree
, tree
, tree
);
245 static void finish_method_declaration
(tree
);
246 static tree build_super_invocation
(tree
);
247 static int verify_constructor_circularity
(tree
, tree
);
248 static char *constructor_circularity_msg
(tree
, tree
);
249 static tree build_this_super_qualified_invocation
(int, tree
, tree
, int, int);
250 static const char *get_printable_method_name
(tree
);
251 static tree patch_conditional_expr
(tree
, tree
, tree
);
252 static tree generate_finit
(tree
);
253 static tree generate_instinit
(tree
);
254 static tree build_instinit_invocation
(tree
);
255 static void fix_constructors
(tree
);
256 static tree build_alias_initializer_parameter_list
(int, tree
, tree
, int *);
257 static tree craft_constructor
(tree
, tree
);
258 static int verify_constructor_super
(tree
);
259 static tree create_artificial_method
(tree
, int, tree
, tree
, tree
);
260 static void start_artificial_method_body
(tree
);
261 static void end_artificial_method_body
(tree
);
262 static int check_method_redefinition
(tree
, tree
);
263 static int check_method_types_complete
(tree
);
264 static bool hack_is_accessible_p
(tree
, tree
);
265 static void java_check_regular_methods
(tree
);
266 static void check_interface_throws_clauses
(tree
, tree
);
267 static void java_check_abstract_methods
(tree
);
268 static void unreachable_stmt_error
(tree
);
269 static int not_accessible_field_error
(tree
, tree
);
270 static tree find_expr_with_wfl
(tree
);
271 static void missing_return_error
(tree
);
272 static tree build_new_array_init
(int, tree
);
273 static tree patch_new_array_init
(tree
, tree
);
274 static tree maybe_build_array_element_wfl
(tree
);
275 static int array_constructor_check_entry
(tree
, tree
);
276 static const char *purify_type_name
(const char *);
277 static tree fold_constant_for_init
(tree
, tree
);
278 static jdeplist
*reverse_jdep_list
(struct parser_ctxt
*);
279 static void static_ref_err
(tree
, tree
, tree
);
280 static void parser_add_interface
(tree
, tree
, tree
);
281 static void add_superinterfaces
(tree
, tree
);
282 static tree jdep_resolve_class
(jdep
*);
283 static int note_possible_classname
(const char *, int);
284 static void java_complete_expand_classes
(void);
285 static void java_complete_expand_class
(tree
);
286 static void java_complete_expand_methods
(tree
);
287 static tree cut_identifier_in_qualified
(tree
);
288 static tree java_stabilize_reference
(tree
);
289 static tree do_unary_numeric_promotion
(tree
);
290 static char * operator_string
(tree
);
291 static tree do_merge_string_cste
(tree
, const char *, int, int);
292 static tree merge_string_cste
(tree
, tree
, int);
293 static tree java_refold
(tree
);
294 static int java_decl_equiv
(tree
, tree
);
295 static int binop_compound_p
(enum tree_code
);
296 static tree search_loop
(tree
);
297 static int labeled_block_contains_loop_p
(tree
, tree
);
298 static int check_abstract_method_definitions
(int, tree
, tree
);
299 static void java_check_abstract_method_definitions
(tree
);
300 static void java_debug_context_do
(int);
301 static void java_parser_context_push_initialized_field
(void);
302 static void java_parser_context_pop_initialized_field
(void);
303 static tree reorder_static_initialized
(tree
);
304 static void java_parser_context_suspend
(void);
305 static void java_parser_context_resume
(void);
306 static int pop_current_osb
(struct parser_ctxt
*);
308 /* JDK 1.1 work. FIXME */
310 static tree maybe_make_nested_class_name
(tree
);
311 static int make_nested_class_name
(tree
);
312 static void link_nested_class_to_enclosing
(void);
313 static tree resolve_inner_class
(htab_t
, tree
, tree
*, tree
*, tree
);
314 static tree find_as_inner_class
(tree
, tree
, tree
);
315 static tree find_as_inner_class_do
(tree
, tree
);
316 static int check_inner_class_redefinition
(tree
, tree
);
318 static tree build_thisn_assign
(void);
319 static tree build_current_thisn
(tree
);
320 static tree build_access_to_thisn
(tree
, tree
, int);
321 static tree maybe_build_thisn_access_method
(tree
);
323 static tree build_nested_field_access
(tree
, tree
);
324 static tree build_nested_field_access_methods
(tree
);
325 static tree build_nested_field_access_method
(tree
, tree
, tree
, tree
, tree
);
326 static tree build_nested_field_access_expr
(int, tree
, tree
, tree
, tree
);
327 static tree build_outer_method_access_method
(tree
);
328 static tree build_new_access_id
(void);
330 static int nested_field_access_p
(tree
, tree
);
331 static int nested_field_expanded_access_p
(tree
, tree
*, tree
*, tree
*);
332 static tree nested_field_access_fix
(tree
, tree
, tree
);
334 static tree build_incomplete_class_ref
(int, tree
);
335 static tree patch_incomplete_class_ref
(tree
);
336 static tree create_anonymous_class
(tree
);
337 static void patch_anonymous_class
(tree
, tree
, tree
);
338 static void add_inner_class_fields
(tree
, tree
);
340 static tree build_dot_class_method
(tree
);
341 static tree build_dot_class_method_invocation
(tree
, tree
);
342 static void create_new_parser_context
(int);
343 static tree maybe_build_class_init_for_field
(tree
, tree
);
345 static int emit_test_initialization
(void **, void *);
347 static char *string_convert_int_cst
(tree
);
349 /* Number of error found so far. */
350 int java_error_count
;
351 /* Number of warning found so far. */
352 int java_warning_count
;
353 /* Cyclic inheritance report, as it can be set by layout_class */
354 const char *cyclic_inheritance_report
;
356 /* The current parser context */
357 struct parser_ctxt
*ctxp
;
359 /* List of things that were analyzed for which code will be generated */
360 struct parser_ctxt
*ctxp_for_generation
= NULL
;
361 struct parser_ctxt
*ctxp_for_generation_last
= NULL
;
363 /* binop_lookup maps token to tree_code. It is used where binary
364 operations are involved and required by the parser. RDIV_EXPR
365 covers both integral/floating point division. The code is changed
366 once the type of both operator is worked out. */
368 static const enum tree_code binop_lookup
[19] =
370 PLUS_EXPR
, MINUS_EXPR
, MULT_EXPR
, RDIV_EXPR
, TRUNC_MOD_EXPR
,
371 LSHIFT_EXPR
, RSHIFT_EXPR
, URSHIFT_EXPR
,
372 BIT_AND_EXPR
, BIT_XOR_EXPR
, BIT_IOR_EXPR
,
373 TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
,
374 EQ_EXPR
, NE_EXPR
, GT_EXPR
, GE_EXPR
, LT_EXPR
, LE_EXPR
,
376 #define BINOP_LOOKUP(VALUE) \
377 binop_lookup
[((VALUE
) - PLUS_TK
) % ARRAY_SIZE
(binop_lookup
)]
379 /* This is the end index for binary operators that can also be used
380 in compound assignments. */
381 #define BINOP_COMPOUND_CANDIDATES 11
383 /* The "$L" identifier we use to create labels. */
384 static GTY
(()) tree label_id
;
386 /* The "StringBuffer" identifier used for the String `+' operator. */
387 static GTY
(()) tree wfl_string_buffer
;
389 /* The "append" identifier used for String `+' operator. */
390 static GTY
(()) tree wfl_append
;
392 /* The "toString" identifier used for String `+' operator. */
393 static GTY
(()) tree wfl_to_string
;
395 /* The "java.lang" import qualified name. */
396 static GTY
(()) tree java_lang_id
;
398 /* The generated `inst$' identifier used for generated enclosing
399 instance/field access functions. */
400 static GTY
(()) tree inst_id
;
402 /* Context and flag for static blocks */
403 static GTY
(()) tree current_static_block
;
405 /* The generated `write_parm_value$' identifier. */
406 static GTY
(()) tree wpv_id
;
408 /* Hold THIS for the scope of the current method decl. */
409 static GTY
(()) tree current_this
;
411 /* Hold a list of catch clauses list. The first element of this list is
412 the list of the catch clauses of the currently analyzed try block. */
413 static GTY
(()) tree currently_caught_type_list
;
415 /* This holds a linked list of all the case labels for the current
416 switch statement. It is only used when checking to see if there
417 are duplicate labels. FIXME: probably this should just be attached
418 to the switch itself; then it could be referenced via
419 `ctxp->current_loop'. */
420 static GTY
(()) tree case_label_list
;
422 /* Anonymous class counter. Will be reset to 1 every time a non
423 anonymous class gets created. */
424 static int anonymous_class_counter
= 1;
426 static GTY
(()) tree src_parse_roots
[1];
428 /* All classes seen from source code */
429 #define gclass_list src_parse_roots[0]
431 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
432 line and point it out. */
433 /* Should point out the one that don't fit. ASCII/unicode, going
436 #define check_modifiers(__message, __value, __mask) do { \
437 if
((__value
) & ~
(__mask
)) \
439 size_t i
, remainder
= (__value
) & ~
(__mask
); \
440 for
(i
= 0; i
< ARRAY_SIZE
(ctxp
->modifier_ctx
); i
++) \
441 if
((1 << i
) & remainder
) \
442 parse_error_context
(ctxp
->modifier_ctx
[i
], (__message
), \
443 java_accstring_lookup
(1 << i
)); \
454 #ifdef USE_MAPPED_LOCATION
455 source_location location
;
464 #ifdef USE_MAPPED_LOCATION
465 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
466 SET_EXPR_LOCATION
(EXPR
, (TOKEN
).location
)
468 #define SET_EXPR_LOCATION_FROM_TOKEN(EXPR, TOKEN) \
469 (EXPR_WFL_LINECOL
(EXPR
) = (TOKEN
).location
)
477 /* Things defined here have to match the order of what's in the
478 binop_lookup table. */
480 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
481 %token LS_TK SRS_TK ZRS_TK
482 %token AND_TK XOR_TK OR_TK
483 %token BOOL_AND_TK BOOL_OR_TK
484 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
486 /* This maps to the same binop_lookup entry than the token above */
488 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
490 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
491 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
494 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
496 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
497 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
498 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
499 %token PAD_TK ABSTRACT_TK STRICT_TK
502 /* Keep those two in order, too */
503 %token DECR_TK INCR_TK
505 /* From now one, things can be in any order */
507 %token DEFAULT_TK IF_TK THROW_TK
508 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
509 %token THROWS_TK BREAK_TK IMPORT_TK
510 %token ELSE_TK INSTANCEOF_TK RETURN_TK
511 %token VOID_TK CATCH_TK INTERFACE_TK
512 %token CASE_TK EXTENDS_TK FINALLY_TK
513 %token SUPER_TK WHILE_TK CLASS_TK
514 %token SWITCH_TK CONST_TK TRY_TK
515 %token FOR_TK NEW_TK CONTINUE_TK
516 %token GOTO_TK PACKAGE_TK THIS_TK
519 %token BYTE_TK SHORT_TK INT_TK LONG_TK
520 %token CHAR_TK INTEGRAL_TK
522 %token FLOAT_TK DOUBLE_TK FP_TK
526 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
528 %token ASSIGN_ANY_TK ASSIGN_TK
529 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
531 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
532 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
534 %type
<value
> modifiers MODIFIER_TK final synchronized
536 %type
<node
> super ID_TK identifier
537 %type
<node
> name simple_name qualified_name
538 %type
<node
> type_declaration compilation_unit
539 field_declaration method_declaration extends_interfaces
540 interfaces interface_type_list
541 import_declarations package_declaration
542 type_declarations interface_body
543 interface_member_declaration constant_declaration
544 interface_member_declarations interface_type
545 abstract_method_declaration
546 %type
<node
> class_body_declaration class_member_declaration
547 static_initializer constructor_declaration block
548 %type
<node
> class_body_declarations constructor_header
549 %type
<node
> class_or_interface_type class_type class_type_list
550 constructor_declarator explicit_constructor_invocation
551 %type
<node
> dim_expr dim_exprs this_or_super throws
553 %type
<node
> variable_declarator_id variable_declarator
554 variable_declarators variable_initializer
555 variable_initializers constructor_body
558 %type
<node
> class_body block_end constructor_block_end
559 %type
<node
> statement statement_without_trailing_substatement
560 labeled_statement if_then_statement label_decl
561 if_then_else_statement while_statement for_statement
562 statement_nsi labeled_statement_nsi do_statement
563 if_then_else_statement_nsi while_statement_nsi
564 for_statement_nsi statement_expression_list for_init
565 for_update statement_expression expression_statement
566 primary_no_new_array expression primary array_type
567 array_creation_initialized array_creation_uninitialized
568 class_instance_creation_expression field_access
569 method_invocation array_access something_dot_new
570 argument_list postfix_expression while_expression
571 post_increment_expression post_decrement_expression
572 unary_expression_not_plus_minus unary_expression
573 pre_increment_expression pre_decrement_expression
575 multiplicative_expression additive_expression
576 shift_expression relational_expression
577 equality_expression and_expression
578 exclusive_or_expression inclusive_or_expression
579 conditional_and_expression conditional_or_expression
580 conditional_expression assignment_expression
581 left_hand_side assignment for_header for_begin
582 constant_expression do_statement_begin empty_statement
583 switch_statement synchronized_statement throw_statement
584 try_statement assert_statement
585 switch_expression switch_block
586 catches catch_clause catch_clause_parameter finally
587 anonymous_class_creation trap_overflow_corner_case
588 %type
<node
> return_statement break_statement continue_statement
590 %type
<operator
> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
591 %type
<operator
> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
592 %type
<operator
> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
593 %type
<operator
> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
594 %type
<operator
> ASSIGN_ANY_TK assignment_operator
595 %token
<operator
> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
596 %token
<operator
> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
597 %token
<operator
> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
598 %token
<operator
> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
599 %token
<operator
> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
600 %type
<operator
> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
601 %type
<operator
> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
602 %type
<operator
> NEW_TK ASSERT_TK
604 %type
<node
> method_body
606 %type
<node
> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
607 STRING_LIT_TK NULL_TK VOID_TK
609 %type
<node
> IF_TK WHILE_TK FOR_TK
611 %type
<node
> formal_parameter_list formal_parameter
612 method_declarator method_header
614 %type
<node
> primitive_type reference_type type
615 BOOLEAN_TK INTEGRAL_TK FP_TK
617 /* Added or modified JDK 1.1 rule types */
618 %type
<node
> type_literals
621 /* 19.2 Production from 2.3: The Syntactic Grammar */
622 goal: compilation_unit
626 /* 19.3 Productions from 3: Lexical structure */
636 /* 19.4 Productions from 4: Types, Values and Variables */
649 class_or_interface_type
653 class_or_interface_type:
658 class_or_interface_type
/* Default rule */
662 class_or_interface_type
668 int osb
= pop_current_osb
(ctxp
);
669 tree t
= build_java_array_type
(($1), -1);
671 t
= build_unresolved_array_type
(t
);
676 int osb
= pop_current_osb
(ctxp
);
679 t
= build_unresolved_array_type
(t
);
684 /* 19.5 Productions from 6: Names */
686 simple_name
/* Default rule */
687 | qualified_name
/* Default rule */
691 identifier
/* Default rule */
695 name DOT_TK identifier
696 { $$
= make_qualified_name
($1, $3, $2.location
); }
703 /* 19.6: Production from 7: Packages */
706 | package_declaration
707 | import_declarations
709 | package_declaration import_declarations
710 | package_declaration type_declarations
711 | import_declarations type_declarations
712 | package_declaration import_declarations type_declarations
720 | import_declarations import_declaration
728 | type_declarations type_declaration
732 PACKAGE_TK name SC_TK
734 ctxp
->package
= EXPR_WFL_NODE
($2);
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: %qs and %qs",
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);
785 /* Search for duplicates. */
786 for
(it
= ctxp
->import_demand_list
; it
; it
= TREE_CHAIN
(it
))
787 if
(EXPR_WFL_NODE
(TREE_PURPOSE
(it
)) == name
)
789 /* Don't import the same thing more than once, just ignore
790 duplicates (7.5.2) */
793 read_import_dir
($2);
794 ctxp
->import_demand_list
=
795 chainon
(ctxp
->import_demand_list
,
796 build_tree_list
($2, NULL_TREE
));
799 | IMPORT_TK name DOT_TK
error
800 {yyerror ("'*' expected"); RECOVER
;}
801 | IMPORT_TK name DOT_TK MULT_TK
error
802 {yyerror ("';' expected"); RECOVER
;}
807 { end_class_declaration
(0); }
808 | interface_declaration
809 { end_class_declaration
(0); }
814 yyerror ("Class or interface declaration expected");
818 /* 19.7 Shortened from the original:
819 modifiers: modifier | modifiers modifier
820 modifier: any of public... */
826 | modifiers MODIFIER_TK
831 (ctxp
->modifier_ctx
[$2], "Modifier %qs declared twice",
832 java_accstring_lookup
(acc
));
840 /* 19.8.1 Production from $8.1: Class Declaration */
842 modifiers CLASS_TK identifier super interfaces
843 { create_class
($1, $3, $4, $5); }
846 | CLASS_TK identifier super interfaces
847 { create_class
(0, $2, $3, $4); }
850 | modifiers CLASS_TK
error
851 { yyerror ("Missing class name"); RECOVER
; }
853 { yyerror ("Missing class name"); RECOVER
; }
854 | CLASS_TK identifier
error
856 if
(!ctxp
->class_err
) yyerror ("'{' expected");
859 | modifiers CLASS_TK identifier
error
860 { if
(!ctxp
->class_err
) yyerror ("'{' expected"); RECOVER
; }
865 | EXTENDS_TK class_type
867 | EXTENDS_TK class_type
error
868 {yyerror ("'{' expected"); ctxp
->class_err
=1;}
870 {yyerror ("Missing super class name"); ctxp
->class_err
=1;}
875 | IMPLEMENTS_TK interface_type_list
877 | IMPLEMENTS_TK
error
880 yyerror ("Missing interface name");
887 ctxp
->interface_number
= 1;
888 $$
= build_tree_list
($1, NULL_TREE
);
890 | interface_type_list C_TK interface_type
892 ctxp
->interface_number
++;
893 $$
= chainon
($1, build_tree_list
($3, NULL_TREE
));
895 | interface_type_list C_TK
error
896 {yyerror ("Missing interface name"); RECOVER
;}
904 | OCB_TK class_body_declarations CCB_TK
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 if
(!IS_EMPTY_STMT
($1))
923 TREE_CHAIN
($1) = CPC_INSTANCE_INITIALIZER_STMT
(ctxp
);
924 SET_CPC_INSTANCE_INITIALIZER_STMT
(ctxp
, $1);
929 class_member_declaration:
932 | class_declaration
/* Added, JDK1.1 inner classes */
933 { end_class_declaration
(1); }
934 | interface_declaration
/* Added, JDK1.1 inner interfaces */
935 { end_class_declaration
(1); }
939 /* 19.8.2 Productions from 8.3: Field Declarations */
941 type variable_declarators SC_TK
942 { register_fields
(0, $1, $2); }
943 | modifiers type variable_declarators SC_TK
946 ("Illegal modifier %qs for field declaration",
947 $1, FIELD_MODIFIERS
);
948 check_modifiers_consistency
($1);
949 register_fields
($1, $2, $3);
953 variable_declarators:
954 /* Should we use build_decl_list () instead ? FIXME */
955 variable_declarator
/* Default rule */
956 | variable_declarators C_TK variable_declarator
957 { $$
= chainon
($1, $3); }
958 | variable_declarators C_TK
error
959 {yyerror ("Missing term"); RECOVER
;}
963 variable_declarator_id
964 { $$
= build_tree_list
($1, NULL_TREE
); }
965 | variable_declarator_id ASSIGN_TK variable_initializer
967 if
(java_error_count
)
970 ($1, build_assignment
($2.token
, $2.location
, $1, $3));
972 | variable_declarator_id ASSIGN_TK
error
974 yyerror ("Missing variable initializer");
975 $$
= build_tree_list
($1, NULL_TREE
);
978 | variable_declarator_id ASSIGN_TK variable_initializer
error
980 yyerror ("';' expected");
981 $$
= build_tree_list
($1, NULL_TREE
);
986 variable_declarator_id:
988 | variable_declarator_id OSB_TK CSB_TK
989 { $$
= build_unresolved_array_type
($1); }
991 {yyerror ("Invalid declaration"); DRECOVER
(vdi
);}
992 | variable_declarator_id OSB_TK
error
994 yyerror ("']' expected");
997 | variable_declarator_id CSB_TK
error
998 {yyerror ("Unbalanced ']'"); DRECOVER
(vdi
);}
1001 variable_initializer:
1006 /* 19.8.3 Productions from 8.4: Method Declarations */
1010 current_function_decl
= $1;
1011 if
(current_function_decl
1012 && TREE_CODE
(current_function_decl
) == FUNCTION_DECL
)
1013 source_start_java_method
(current_function_decl
);
1015 current_function_decl
= NULL_TREE
;
1018 { finish_method_declaration
($3); }
1019 | method_header
error
1020 {YYNOT_TWICE
yyerror ("'{' expected"); RECOVER
;}
1024 type method_declarator throws
1025 { $$
= method_header
(0, $1, $2, $3); }
1026 | VOID_TK method_declarator throws
1027 { $$
= method_header
(0, void_type_node
, $2, $3); }
1028 | modifiers type method_declarator throws
1029 { $$
= method_header
($1, $2, $3, $4); }
1030 | modifiers VOID_TK method_declarator throws
1031 { $$
= method_header
($1, void_type_node
, $3, $4); }
1034 yyerror ("Invalid method declaration, method name required");
1037 | modifiers type
error
1039 yyerror ("Identifier expected");
1044 yyerror ("Identifier expected");
1047 | modifiers VOID_TK
error
1049 yyerror ("Identifier expected");
1054 yyerror ("Invalid method declaration, return type required");
1060 identifier OP_TK CP_TK
1062 ctxp
->formal_parameter_number
= 0;
1063 $$
= method_declarator
($1, NULL_TREE
);
1065 | identifier OP_TK formal_parameter_list CP_TK
1066 { $$
= method_declarator
($1, $3); }
1067 | method_declarator OSB_TK CSB_TK
1069 SET_EXPR_LOCATION_FROM_TOKEN
(wfl_operator
, $2);
1071 build_unresolved_array_type
(TREE_PURPOSE
($1));
1072 parse_warning_context
1074 "Discouraged form of returned type specification");
1076 | identifier OP_TK
error
1077 {yyerror ("')' expected"); DRECOVER
(method_declarator
);}
1078 | method_declarator OSB_TK
error
1079 {yyerror ("']' expected"); RECOVER
;}
1082 formal_parameter_list:
1085 ctxp
->formal_parameter_number
= 1;
1087 | formal_parameter_list C_TK formal_parameter
1089 ctxp
->formal_parameter_number
+= 1;
1090 $$
= chainon
($1, $3);
1092 | formal_parameter_list C_TK
error
1093 { yyerror ("Missing formal parameter term"); RECOVER
; }
1097 type variable_declarator_id
1099 $$
= build_tree_list
($2, $1);
1101 | final type variable_declarator_id
/* Added, JDK1.1 final parms */
1103 $$
= build_tree_list
($3, $2);
1104 ARG_FINAL_P
($$
) = 1;
1108 yyerror ("Missing identifier"); RECOVER
;
1113 yyerror ("Missing identifier"); RECOVER
;
1121 check_modifiers
("Illegal modifier %qs. Only %<final%> was expected here",
1123 if
($1 != ACC_FINAL
)
1124 MODIFIER_WFL
(FINAL_TK
) = build_wfl_node
(NULL_TREE
);
1130 | THROWS_TK class_type_list
1133 {yyerror ("Missing class type term"); RECOVER
;}
1138 { $$
= build_tree_list
($1, $1); }
1139 | class_type_list C_TK class_type
1140 { $$
= tree_cons
($3, $3, $1); }
1141 | class_type_list C_TK
error
1142 {yyerror ("Missing class type term"); RECOVER
;}
1147 | SC_TK
{ $$
= NULL_TREE
; }
1150 /* 19.8.4 Productions from 8.5: Static Initializers */
1154 TREE_CHAIN
($2) = CPC_STATIC_INITIALIZER_STMT
(ctxp
);
1155 SET_CPC_STATIC_INITIALIZER_STMT
(ctxp
, $2);
1156 current_static_block
= NULL_TREE
;
1160 static: /* Test lval.sub_token here */
1163 check_modifiers
("Illegal modifier %qs for static initializer", $1, ACC_STATIC
);
1164 /* Can't have a static initializer in an innerclass */
1165 if
($1 | ACC_STATIC
&&
1166 GET_CPC_LIST
() && !TOPLEVEL_CLASS_DECL_P
(GET_CPC
()))
1168 (MODIFIER_WFL
(STATIC_TK
),
1169 "Can't define static initializer in class %qs. Static initializer can only be defined in top-level classes",
1170 IDENTIFIER_POINTER
(DECL_NAME
(GET_CPC
())));
1171 SOURCE_FRONTEND_DEBUG
(("Modifiers: %d", $1));
1175 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1176 constructor_declaration:
1179 current_function_decl
= $1;
1180 source_start_java_method
(current_function_decl
);
1183 { finish_method_declaration
($3); }
1187 constructor_declarator throws
1188 { $$
= method_header
(0, NULL_TREE
, $1, $2); }
1189 | modifiers constructor_declarator throws
1190 { $$
= method_header
($1, NULL_TREE
, $2, $3); }
1193 constructor_declarator:
1194 simple_name OP_TK CP_TK
1196 ctxp
->formal_parameter_number
= 0;
1197 $$
= method_declarator
($1, NULL_TREE
);
1199 | simple_name OP_TK formal_parameter_list CP_TK
1200 { $$
= method_declarator
($1, $3); }
1204 /* Unlike regular method, we always need a complete (empty)
1205 body so we can safely perform all the required code
1206 addition (super invocation and field initialization) */
1207 block_begin constructor_block_end
1209 BLOCK_EXPR_BODY
($2) = build_java_empty_stmt
();
1212 | block_begin explicit_constructor_invocation constructor_block_end
1214 | block_begin block_statements constructor_block_end
1216 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1220 constructor_block_end:
1224 /* Error recovery for that rule moved down expression_statement: rule. */
1225 explicit_constructor_invocation:
1226 this_or_super OP_TK CP_TK SC_TK
1228 $$
= build_method_invocation
($1, NULL_TREE
);
1229 $$
= build_debugable_stmt
(EXPR_WFL_LINECOL
($1), $$
);
1230 $$
= java_method_add_stmt
(current_function_decl
, $$
);
1232 | this_or_super OP_TK argument_list CP_TK SC_TK
1234 $$
= build_method_invocation
($1, $3);
1235 $$
= build_debugable_stmt
(EXPR_WFL_LINECOL
($1), $$
);
1236 $$
= java_method_add_stmt
(current_function_decl
, $$
);
1238 /* Added, JDK1.1 inner classes. Modified because the rule
1239 'primary' couldn't work. */
1240 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1241 {$$
= parse_jdk1_1_error
("explicit constructor invocation"); }
1242 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1243 {$$
= parse_jdk1_1_error
("explicit constructor invocation"); }
1246 this_or_super: /* Added, simplifies error diagnostics */
1249 tree wfl
= build_wfl_node
(this_identifier_node
);
1250 SET_EXPR_LOCATION_FROM_TOKEN
(wfl
, $1);
1255 tree wfl
= build_wfl_node
(super_identifier_node
);
1256 SET_EXPR_LOCATION_FROM_TOKEN
(wfl
, $1);
1261 /* 19.9 Productions from 9: Interfaces */
1262 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1263 interface_declaration:
1264 INTERFACE_TK identifier
1265 { create_interface
(0, $2, NULL_TREE
); }
1268 | modifiers INTERFACE_TK identifier
1269 { create_interface
($1, $3, NULL_TREE
); }
1272 | INTERFACE_TK identifier extends_interfaces
1273 { create_interface
(0, $2, $3); }
1276 | modifiers INTERFACE_TK identifier extends_interfaces
1277 { create_interface
($1, $3, $4); }
1280 | INTERFACE_TK identifier
error
1281 { yyerror ("'{' expected"); RECOVER
; }
1282 | modifiers INTERFACE_TK identifier
error
1283 { yyerror ("'{' expected"); RECOVER
; }
1287 EXTENDS_TK interface_type
1289 ctxp
->interface_number
= 1;
1290 $$
= build_tree_list
($2, NULL_TREE
);
1292 | extends_interfaces C_TK interface_type
1294 ctxp
->interface_number
++;
1295 $$
= chainon
($1, build_tree_list
($3, NULL_TREE
));
1298 {yyerror ("Invalid interface type"); RECOVER
;}
1299 | extends_interfaces C_TK
error
1300 {yyerror ("Missing term"); RECOVER
;}
1306 | OCB_TK interface_member_declarations CCB_TK
1310 interface_member_declarations:
1311 interface_member_declaration
1312 | interface_member_declarations interface_member_declaration
1315 interface_member_declaration:
1316 constant_declaration
1317 | abstract_method_declaration
1318 | class_declaration
/* Added, JDK1.1 inner classes */
1319 { end_class_declaration
(1); }
1320 | interface_declaration
/* Added, JDK1.1 inner interfaces */
1321 { end_class_declaration
(1); }
1324 constant_declaration:
1328 abstract_method_declaration:
1331 check_abstract_method_header
($1);
1332 current_function_decl
= NULL_TREE
; /* FIXME ? */
1334 | method_header
error
1335 {yyerror ("';' expected"); RECOVER
;}
1338 /* 19.10 Productions from 10: Arrays */
1341 { $$
= build_new_array_init
($1.location
, NULL_TREE
); }
1342 | OCB_TK C_TK CCB_TK
1343 { $$
= build_new_array_init
($1.location
, NULL_TREE
); }
1344 | OCB_TK variable_initializers CCB_TK
1345 { $$
= build_new_array_init
($1.location
, $2); }
1346 | OCB_TK variable_initializers C_TK CCB_TK
1347 { $$
= build_new_array_init
($1.location
, $2); }
1350 variable_initializers:
1351 variable_initializer
1353 $$
= tree_cons
(maybe_build_array_element_wfl
($1),
1356 | variable_initializers C_TK variable_initializer
1358 $$
= tree_cons
(maybe_build_array_element_wfl
($3), $3, $1);
1360 | variable_initializers C_TK
error
1361 {yyerror ("Missing term"); RECOVER
;}
1364 /* 19.11 Production from 14: Blocks and Statements */
1366 block_begin block_end
1368 | block_begin block_statements block_end
1380 maybe_absorb_scoping_blocks
();
1382 if
(!BLOCK_SUBBLOCKS
($$
))
1383 BLOCK_SUBBLOCKS
($$
) = build_java_empty_stmt
();
1389 | block_statements block_statement
1393 local_variable_declaration_statement
1395 { java_method_add_stmt
(current_function_decl
, $1); }
1396 | class_declaration
/* Added, JDK1.1 local classes */
1398 LOCAL_CLASS_P
(TREE_TYPE
(GET_CPC
())) = 1;
1399 end_class_declaration
(1);
1403 local_variable_declaration_statement:
1404 local_variable_declaration SC_TK
/* Can't catch missing ';' here */
1407 local_variable_declaration:
1408 type variable_declarators
1409 { declare_local_variables
(0, $1, $2); }
1410 | final type variable_declarators
/* Added, JDK1.1 final locals */
1411 { declare_local_variables
($1, $2, $3); }
1415 statement_without_trailing_substatement
1418 | if_then_else_statement
1421 { $$
= exit_block
(); }
1425 statement_without_trailing_substatement
1426 | labeled_statement_nsi
1427 | if_then_else_statement_nsi
1428 | while_statement_nsi
1430 { $$
= exit_block
(); }
1433 statement_without_trailing_substatement:
1436 | expression_statement
1440 | continue_statement
1442 | synchronized_statement
1451 if
(flag_extraneous_semicolon
1452 && ! current_static_block
1453 && (! current_function_decl ||
1454 /* Verify we're not in a inner class declaration */
1455 (GET_CPC
() != TYPE_NAME
1456 (DECL_CONTEXT
(current_function_decl
)))))
1459 #ifdef USE_MAPPED_LOCATION
1460 SET_EXPR_LOCATION
(wfl_operator
, input_location
);
1462 EXPR_WFL_SET_LINECOL
(wfl_operator
, input_line
, -1);
1464 parse_warning_context
(wfl_operator
, "An empty declaration is a deprecated feature that should not be used");
1466 $$
= build_java_empty_stmt
();
1471 identifier REL_CL_TK
1473 $$
= build_labeled_block
(EXPR_WFL_LINECOL
($1),
1474 EXPR_WFL_NODE
($1));
1476 push_labeled_block
($$
);
1477 PUSH_LABELED_BLOCK
($$
);
1482 label_decl statement
1483 { $$
= finish_labeled_statement
($1, $2); }
1485 {yyerror ("':' expected"); RECOVER
;}
1488 labeled_statement_nsi:
1489 label_decl statement_nsi
1490 { $$
= finish_labeled_statement
($1, $2); }
1493 /* We concentrate here a bunch of error handling rules that we couldn't write
1494 earlier, because expression_statement catches a missing ';'. */
1495 expression_statement:
1496 statement_expression SC_TK
1498 /* We have a statement. Generate a WFL around it so
1500 #ifdef USE_MAPPED_LOCATION
1501 $$
= expr_add_location
($1, input_location
, 1);
1503 $$
= build_expr_wfl
($1, input_filename
, input_line
, 0);
1504 JAVA_MAYBE_GENERATE_DEBUG_INFO
($$
);
1506 /* We know we have a statement, so set the debug
1507 info to be eventually generate here. */
1511 YYNOT_TWICE
yyerror ("Invalid expression statement");
1512 DRECOVER
(expr_stmt
);
1516 YYNOT_TWICE
yyerror ("Invalid expression statement");
1517 DRECOVER
(expr_stmt
);
1521 YYNOT_TWICE
yyerror ("Invalid expression statement");
1522 DRECOVER
(expr_stmt
);
1524 | this_or_super OP_TK
error
1525 {yyerror ("')' expected"); RECOVER
;}
1526 | this_or_super OP_TK CP_TK
error
1528 parse_ctor_invocation_error
();
1531 | this_or_super OP_TK argument_list
error
1532 {yyerror ("')' expected"); RECOVER
;}
1533 | this_or_super OP_TK argument_list CP_TK
error
1535 parse_ctor_invocation_error
();
1538 | name DOT_TK SUPER_TK
error
1539 {yyerror ("'(' expected"); RECOVER
;}
1540 | name DOT_TK SUPER_TK OP_TK
error
1541 {yyerror ("')' expected"); RECOVER
;}
1542 | name DOT_TK SUPER_TK OP_TK argument_list
error
1543 {yyerror ("')' expected"); RECOVER
;}
1544 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK
error
1545 {yyerror ("';' expected"); RECOVER
;}
1546 | name DOT_TK SUPER_TK OP_TK CP_TK
error
1547 {yyerror ("';' expected"); RECOVER
;}
1550 statement_expression:
1552 | pre_increment_expression
1553 | pre_decrement_expression
1554 | post_increment_expression
1555 | post_decrement_expression
1557 | class_instance_creation_expression
1561 IF_TK OP_TK expression CP_TK statement
1563 $$
= build_if_else_statement
($2.location
, $3,
1567 {yyerror ("'(' expected"); RECOVER
;}
1569 {yyerror ("Missing term"); RECOVER
;}
1570 | IF_TK OP_TK expression
error
1571 {yyerror ("')' expected"); RECOVER
;}
1574 if_then_else_statement:
1575 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1576 { $$
= build_if_else_statement
($2.location
, $3, $5, $7); }
1579 if_then_else_statement_nsi:
1580 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1581 { $$
= build_if_else_statement
($2.location
, $3, $5, $7); }
1591 /* Make into "proper list" of COMPOUND_EXPRs.
1592 I.e. make the last statement also have its own
1594 maybe_absorb_scoping_blocks
();
1595 TREE_OPERAND
($1, 1) = exit_block
();
1596 $$
= build_debugable_stmt
(EXPR_WFL_LINECOL
($1), $1);
1601 SWITCH_TK OP_TK expression CP_TK
1603 $$
= build3
(SWITCH_EXPR
, NULL_TREE
, $3,
1604 NULL_TREE
, NULL_TREE
);
1605 SET_EXPR_LOCATION_FROM_TOKEN
($$
, $2);
1608 {yyerror ("'(' expected"); RECOVER
;}
1609 | SWITCH_TK OP_TK
error
1610 {yyerror ("Missing term or ')'"); DRECOVER
(switch_statement
);}
1611 | SWITCH_TK OP_TK expression CP_TK
error
1612 {yyerror ("'{' expected"); RECOVER
;}
1615 /* Default assignment is there to avoid type node on switch_block
1621 | OCB_TK switch_labels CCB_TK
1623 | OCB_TK switch_block_statement_groups CCB_TK
1625 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1629 switch_block_statement_groups:
1630 switch_block_statement_group
1631 | switch_block_statement_groups switch_block_statement_group
1634 switch_block_statement_group:
1635 switch_labels block_statements
1640 | switch_labels switch_label
1644 CASE_TK constant_expression REL_CL_TK
1646 tree lab
= build1
(CASE_EXPR
, NULL_TREE
, $2);
1647 SET_EXPR_LOCATION_FROM_TOKEN
(lab
, $1);
1648 java_method_add_stmt
(current_function_decl
, lab
);
1650 | DEFAULT_TK REL_CL_TK
1652 tree lab
= make_node
(DEFAULT_EXPR
);
1653 SET_EXPR_LOCATION_FROM_TOKEN
(lab
, $1);
1654 java_method_add_stmt
(current_function_decl
, lab
);
1657 {yyerror ("Missing or invalid constant expression"); RECOVER
;}
1658 | CASE_TK constant_expression
error
1659 {yyerror ("':' expected"); RECOVER
;}
1661 {yyerror ("':' expected"); RECOVER
;}
1665 WHILE_TK OP_TK expression CP_TK
1667 tree body
= build_loop_body
($2.location
, $3, 0);
1668 $$
= build_new_loop
(body
);
1673 while_expression statement
1674 { $$
= finish_loop_body
(0, NULL_TREE
, $2, 0); }
1676 {YYERROR_NOW
; yyerror ("'(' expected"); RECOVER
;}
1677 | WHILE_TK OP_TK
error
1678 {yyerror ("Missing term and ')' expected"); RECOVER
;}
1679 | WHILE_TK OP_TK expression
error
1680 {yyerror ("')' expected"); RECOVER
;}
1683 while_statement_nsi:
1684 while_expression statement_nsi
1685 { $$
= finish_loop_body
(0, NULL_TREE
, $2, 0); }
1691 tree body
= build_loop_body
(0, NULL_TREE
, 1);
1692 $$
= build_new_loop
(body
);
1694 /* Need error handing here. FIXME */
1698 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1699 { $$
= finish_loop_body
($4.location
, $5, $2, 1); }
1703 for_begin SC_TK expression SC_TK for_update CP_TK statement
1705 if
(CONSTANT_CLASS_P
($3))
1706 $3 = build_wfl_node
($3);
1707 $$
= finish_for_loop
(EXPR_WFL_LINECOL
($3), $3, $5, $7);
1709 | for_begin SC_TK SC_TK for_update CP_TK statement
1711 $$
= finish_for_loop
(0, NULL_TREE
, $4, $6);
1712 /* We have not condition, so we get rid of the EXIT_EXPR */
1713 LOOP_EXPR_BODY_CONDITION_EXPR
(LOOP_EXPR_BODY
($$
), 0) =
1714 build_java_empty_stmt
();
1716 | for_begin SC_TK
error
1717 {yyerror ("Invalid control expression"); RECOVER
;}
1718 | for_begin SC_TK expression SC_TK
error
1719 {yyerror ("Invalid update expression"); RECOVER
;}
1720 | for_begin SC_TK SC_TK
error
1721 {yyerror ("Invalid update expression"); RECOVER
;}
1725 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1726 { $$
= finish_for_loop
(EXPR_WFL_LINECOL
($3), $3, $5, $7);}
1727 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1729 $$
= finish_for_loop
(0, NULL_TREE
, $4, $6);
1730 /* We have not condition, so we get rid of the EXIT_EXPR */
1731 LOOP_EXPR_BODY_CONDITION_EXPR
(LOOP_EXPR_BODY
($$
), 0) =
1732 build_java_empty_stmt
();
1739 /* This scope defined for local variable that may be
1740 defined within the scope of the for loop */
1744 {yyerror ("'(' expected"); DRECOVER
(for_1
);}
1745 | FOR_TK OP_TK
error
1746 {yyerror ("Invalid init statement"); RECOVER
;}
1752 /* We now declare the loop body. The loop is
1753 declared as a for loop. */
1754 tree body
= build_loop_body
(0, NULL_TREE
, 0);
1755 $$
= build_new_loop
(body
);
1756 FOR_LOOP_P
($$
) = 1;
1757 /* The loop is added to the current block the for
1758 statement is defined within */
1759 java_method_add_stmt
(current_function_decl
, $$
);
1762 for_init: /* Can be empty */
1763 { $$
= build_java_empty_stmt
(); }
1764 | statement_expression_list
1766 /* Init statement recorded within the previously
1767 defined block scope */
1768 $$
= java_method_add_stmt
(current_function_decl
, $1);
1770 | local_variable_declaration
1772 /* Local variable are recorded within the previously
1773 defined block scope */
1776 | statement_expression_list
error
1777 {yyerror ("';' expected"); DRECOVER
(for_init_1
);}
1780 for_update: /* Can be empty */
1781 {$$
= build_java_empty_stmt
();}
1782 | statement_expression_list
1783 { $$
= build_debugable_stmt
(BUILD_LOCATION
(), $1); }
1786 statement_expression_list:
1787 statement_expression
1788 { $$
= add_stmt_to_compound
(NULL_TREE
, NULL_TREE
, $1); }
1789 | statement_expression_list C_TK statement_expression
1790 { $$
= add_stmt_to_compound
($1, NULL_TREE
, $3); }
1791 | statement_expression_list C_TK
error
1792 {yyerror ("Missing term"); RECOVER
;}
1797 { $$
= build_bc_statement
($1.location
, 1, NULL_TREE
); }
1798 | BREAK_TK identifier SC_TK
1799 { $$
= build_bc_statement
($1.location
, 1, $2); }
1801 {yyerror ("Missing term"); RECOVER
;}
1802 | BREAK_TK identifier
error
1803 {yyerror ("';' expected"); RECOVER
;}
1808 { $$
= build_bc_statement
($1.location
, 0, NULL_TREE
); }
1809 | CONTINUE_TK identifier SC_TK
1810 { $$
= build_bc_statement
($1.location
, 0, $2); }
1812 {yyerror ("Missing term"); RECOVER
;}
1813 | CONTINUE_TK identifier
error
1814 {yyerror ("';' expected"); RECOVER
;}
1819 { $$
= build_return
($1.location
, NULL_TREE
); }
1820 | RETURN_TK expression SC_TK
1821 { $$
= build_return
($1.location
, $2); }
1823 {yyerror ("Missing term"); RECOVER
;}
1824 | RETURN_TK expression
error
1825 {yyerror ("';' expected"); RECOVER
;}
1829 THROW_TK expression SC_TK
1831 $$
= build1
(THROW_EXPR
, NULL_TREE
, $2);
1832 SET_EXPR_LOCATION_FROM_TOKEN
($$
, $1);
1835 {yyerror ("Missing term"); RECOVER
;}
1836 | THROW_TK expression
error
1837 {yyerror ("';' expected"); RECOVER
;}
1841 ASSERT_TK expression REL_CL_TK expression SC_TK
1843 $$
= build_assertion
($1.location
, $2, $4);
1845 | ASSERT_TK expression SC_TK
1847 $$
= build_assertion
($1.location
, $2, NULL_TREE
);
1850 {yyerror ("Missing term"); RECOVER
;}
1851 | ASSERT_TK expression
error
1852 {yyerror ("';' expected"); RECOVER
;}
1855 synchronized_statement:
1856 synchronized OP_TK expression CP_TK block
1858 $$
= build2
(SYNCHRONIZED_EXPR
, NULL_TREE
, $3, $5);
1859 EXPR_WFL_LINECOL
($$
) =
1860 EXPR_WFL_LINECOL
(MODIFIER_WFL
(SYNCHRONIZED_TK
));
1862 | synchronized OP_TK expression CP_TK
error
1863 {yyerror ("'{' expected"); RECOVER
;}
1864 | synchronized
error
1865 {yyerror ("'(' expected"); RECOVER
;}
1866 | synchronized OP_TK
error CP_TK
1867 {yyerror ("Missing term"); RECOVER
;}
1868 | synchronized OP_TK
error
1869 {yyerror ("Missing term"); RECOVER
;}
1876 "Illegal modifier %qs. Only %<synchronized%> was expected here",
1877 $1, ACC_SYNCHRONIZED
);
1878 if
($1 != ACC_SYNCHRONIZED
)
1879 MODIFIER_WFL
(SYNCHRONIZED_TK
) =
1880 build_wfl_node
(NULL_TREE
);
1885 TRY_TK block catches
1886 { $$
= build_try_statement
($1.location
, $2, $3); }
1887 | TRY_TK block finally
1888 { $$
= build_try_finally_statement
($1.location
, $2, $3); }
1889 | TRY_TK block catches finally
1890 { $$
= build_try_finally_statement
1891 ($1.location
, build_try_statement
($1.location
,
1895 {yyerror ("'{' expected"); DRECOVER
(try_statement
);}
1900 | catches catch_clause
1902 TREE_CHAIN
($2) = $1;
1908 catch_clause_parameter block
1910 java_method_add_stmt
(current_function_decl
, $2);
1916 catch_clause_parameter:
1917 CATCH_TK OP_TK formal_parameter CP_TK
1919 /* We add a block to define a scope for
1920 formal_parameter (CCBP). The formal parameter is
1921 declared initialized by the appropriate function
1927 ccpb
= enter_block
();
1928 init
= build_assignment
1929 (ASSIGN_TK
, $2.location
, TREE_PURPOSE
($3),
1930 build0
(JAVA_EXC_OBJ_EXPR
, ptr_type_node
));
1931 declare_local_variables
(0, TREE_VALUE
($3),
1933 (TREE_PURPOSE
($3), init
));
1934 $$
= build1
(JAVA_CATCH_EXPR
, NULL_TREE
, ccpb
);
1935 SET_EXPR_LOCATION_FROM_TOKEN
($$
, $1);
1939 $$
= error_mark_node
;
1943 {yyerror ("'(' expected"); RECOVER
; $$
= NULL_TREE
;}
1944 | CATCH_TK OP_TK
error
1946 yyerror ("Missing term or ')' expected");
1947 RECOVER
; $$
= NULL_TREE
;
1949 | CATCH_TK OP_TK
error CP_TK
/* That's for () */
1950 {yyerror ("Missing term"); RECOVER
; $$
= NULL_TREE
;}
1957 {yyerror ("'{' expected"); RECOVER
; }
1960 /* 19.12 Production from 15: Expressions */
1962 primary_no_new_array
1963 | array_creation_uninitialized
1964 | array_creation_initialized
1967 primary_no_new_array:
1970 { $$
= build_this
($1.location
); }
1971 | OP_TK expression CP_TK
1973 | class_instance_creation_expression
1978 /* Added, JDK1.1 inner classes. Documentation is wrong
1979 referring to a 'ClassName' (class_name) rule that doesn't
1980 exist. Used name: instead. */
1981 | name DOT_TK THIS_TK
1983 tree wfl
= build_wfl_node
(this_identifier_node
);
1984 $$
= make_qualified_primary
($1, wfl
, EXPR_WFL_LINECOL
($1));
1986 | OP_TK expression
error
1987 {yyerror ("')' expected"); RECOVER
;}
1989 {yyerror ("'class' or 'this' expected" ); RECOVER
;}
1990 | primitive_type DOT_TK
error
1991 {yyerror ("'class' expected" ); RECOVER
;}
1992 | VOID_TK DOT_TK
error
1993 {yyerror ("'class' expected" ); RECOVER
;}
1997 name DOT_TK CLASS_TK
1998 { $$
= build_incomplete_class_ref
($2.location
, $1); }
1999 | array_type DOT_TK CLASS_TK
2000 { $$
= build_incomplete_class_ref
($2.location
, $1); }
2001 | primitive_type DOT_TK CLASS_TK
2002 { $$
= build_incomplete_class_ref
($2.location
, $1); }
2003 | VOID_TK DOT_TK CLASS_TK
2005 $$
= build_incomplete_class_ref
($2.location
,
2010 class_instance_creation_expression:
2011 NEW_TK class_type OP_TK argument_list CP_TK
2012 { $$
= build_new_invocation
($2, $4); }
2013 | NEW_TK class_type OP_TK CP_TK
2014 { $$
= build_new_invocation
($2, NULL_TREE
); }
2015 | anonymous_class_creation
2016 /* Added, JDK1.1 inner classes, modified to use name or
2017 primary instead of primary solely which couldn't work in
2019 | something_dot_new identifier OP_TK CP_TK
2021 tree ctor
= build_new_invocation
($2, NULL_TREE
);
2022 $$
= make_qualified_primary
($1, ctor
,
2023 EXPR_WFL_LINECOL
($1));
2025 | something_dot_new identifier OP_TK CP_TK class_body
2026 | something_dot_new identifier OP_TK argument_list CP_TK
2028 tree ctor
= build_new_invocation
($2, $4);
2029 $$
= make_qualified_primary
($1, ctor
,
2030 EXPR_WFL_LINECOL
($1));
2032 | something_dot_new identifier OP_TK argument_list CP_TK class_body
2033 | NEW_TK
error SC_TK
2034 {$$
= NULL_TREE
; yyerror ("'(' expected"); DRECOVER
(new_1
);}
2035 | NEW_TK class_type
error
2036 {$$
= NULL_TREE
; yyerror ("'(' expected"); RECOVER
;}
2037 | NEW_TK class_type OP_TK
error
2038 {$$
= NULL_TREE
; yyerror ("')' or term expected"); RECOVER
;}
2039 | NEW_TK class_type OP_TK argument_list
error
2040 {$$
= NULL_TREE
; yyerror ("')' expected"); RECOVER
;}
2041 | something_dot_new
error
2045 yyerror ("Identifier expected");
2048 | something_dot_new identifier
error
2049 {$$
= NULL_TREE
; yyerror ("'(' expected"); RECOVER
;}
2052 /* Created after JDK1.1 rules originally added to
2053 class_instance_creation_expression, but modified to use
2054 'class_type' instead of 'TypeName' (type_name) which is mentioned
2055 in the documentation but doesn't exist. */
2057 anonymous_class_creation:
2058 NEW_TK class_type OP_TK argument_list CP_TK
2059 { create_anonymous_class
($2); }
2062 tree id
= build_wfl_node
(DECL_NAME
(GET_CPC
()));
2063 EXPR_WFL_LINECOL
(id
) = EXPR_WFL_LINECOL
($2);
2065 end_class_declaration
(1);
2067 /* Now we can craft the new expression */
2068 $$
= build_new_invocation
(id
, $4);
2070 /* Note that we can't possibly be here if
2071 `class_type' is an interface (in which case the
2072 anonymous class extends Object and implements
2073 `class_type', hence its constructor can't have
2076 /* Otherwise, the innerclass must feature a
2077 constructor matching `argument_list'. Anonymous
2078 classes are a bit special: it's impossible to
2079 define constructor for them, hence constructors
2080 must be generated following the hints provided by
2081 the `new' expression. Whether a super constructor
2082 of that nature exists or not is to be verified
2083 later on in verify_constructor_super.
2085 It's during the expansion of a `new' statement
2086 referring to an anonymous class that a ctor will
2087 be generated for the anonymous class, with the
2091 | NEW_TK class_type OP_TK CP_TK
2092 { create_anonymous_class
($2); }
2095 tree id
= build_wfl_node
(DECL_NAME
(GET_CPC
()));
2096 EXPR_WFL_LINECOL
(id
) = EXPR_WFL_LINECOL
($2);
2098 end_class_declaration
(1);
2100 /* Now we can craft the new expression. The
2101 statement doesn't need to be remember so that a
2102 constructor can be generated, since its signature
2103 is already known. */
2104 $$
= build_new_invocation
(id
, NULL_TREE
);
2108 something_dot_new: /* Added, not part of the specs. */
2111 | primary DOT_TK NEW_TK
2118 $$
= tree_cons
(NULL_TREE
, $1, NULL_TREE
);
2119 ctxp
->formal_parameter_number
= 1;
2121 | argument_list C_TK expression
2123 ctxp
->formal_parameter_number
+= 1;
2124 $$
= tree_cons
(NULL_TREE
, $3, $1);
2126 | argument_list C_TK
error
2127 {yyerror ("Missing term"); RECOVER
;}
2130 array_creation_uninitialized:
2131 NEW_TK primitive_type dim_exprs
2132 { $$
= build_newarray_node
($2, $3, 0); }
2133 | NEW_TK class_or_interface_type dim_exprs
2134 { $$
= build_newarray_node
($2, $3, 0); }
2135 | NEW_TK primitive_type dim_exprs dims
2136 { $$
= build_newarray_node
($2, $3, pop_current_osb
(ctxp
));}
2137 | NEW_TK class_or_interface_type dim_exprs dims
2138 { $$
= build_newarray_node
($2, $3, pop_current_osb
(ctxp
));}
2139 | NEW_TK
error CSB_TK
2140 {yyerror ("'[' expected"); DRECOVER
("]");}
2141 | NEW_TK
error OSB_TK
2142 {yyerror ("']' expected"); RECOVER
;}
2145 array_creation_initialized:
2146 /* Added, JDK1.1 anonymous array. Initial documentation rule
2148 NEW_TK class_or_interface_type dims array_initializer
2151 int osb
= pop_current_osb
(ctxp
);
2153 obstack_grow
(&temporary_obstack
, "[]", 2);
2154 obstack_1grow
(&temporary_obstack
, '\0');
2155 sig
= obstack_finish
(&temporary_obstack
);
2156 $$
= build3
(NEW_ANONYMOUS_ARRAY_EXPR
, NULL_TREE
,
2157 $2, get_identifier
(sig
), $4);
2159 | NEW_TK primitive_type dims array_initializer
2161 int osb
= pop_current_osb
(ctxp
);
2164 type
= build_java_array_type
(type
, -1);
2165 $$
= build3
(NEW_ANONYMOUS_ARRAY_EXPR
, NULL_TREE
,
2166 build_pointer_type
(type
), NULL_TREE
, $4);
2168 | NEW_TK
error CSB_TK
2169 {yyerror ("'[' expected"); DRECOVER
("]");}
2170 | NEW_TK
error OSB_TK
2171 {yyerror ("']' expected"); RECOVER
;}
2176 { $$
= build_tree_list
(NULL_TREE
, $1); }
2177 | dim_exprs dim_expr
2178 { $$
= tree_cons
(NULL_TREE
, $2, $$
); }
2182 OSB_TK expression CSB_TK
2184 if
(JNUMERIC_TYPE_P
(TREE_TYPE
($2)))
2186 $2 = build_wfl_node
($2);
2187 TREE_TYPE
($2) = NULL_TREE
;
2189 EXPR_WFL_LINECOL
($2) = $1.location
;
2192 | OSB_TK expression
error
2193 {yyerror ("']' expected"); RECOVER
;}
2196 yyerror ("Missing term");
2197 yyerror ("']' expected");
2206 /* If not initialized, allocate memory for the osb
2208 if
(!ctxp
->osb_limit
)
2210 allocate
= ctxp
->osb_limit
= 32;
2211 ctxp
->osb_depth
= -1;
2213 /* If capacity overflown, reallocate a bigger chunk */
2214 else if
(ctxp
->osb_depth
+1 == ctxp
->osb_limit
)
2215 allocate
= ctxp
->osb_limit
<< 1;
2219 allocate
*= sizeof
(int);
2220 if
(ctxp
->osb_number
)
2221 ctxp
->osb_number
= xrealloc
(ctxp
->osb_number
,
2224 ctxp
->osb_number
= xmalloc
(allocate
);
2227 CURRENT_OSB
(ctxp
) = 1;
2229 | dims OSB_TK CSB_TK
2230 { CURRENT_OSB
(ctxp
)++; }
2232 { yyerror ("']' expected"); RECOVER
;}
2236 primary DOT_TK identifier
2237 { $$
= make_qualified_primary
($1, $3, $2.location
); }
2238 /* FIXME - REWRITE TO:
2239 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2240 | SUPER_TK DOT_TK identifier
2242 tree super_wfl
= build_wfl_node
(super_identifier_node
);
2243 SET_EXPR_LOCATION_FROM_TOKEN
(super_wfl
, $1);
2244 $$
= make_qualified_name
(super_wfl
, $3, $2.location
);
2247 {yyerror ("Field expected"); DRECOVER
(super_field_acces
);}
2252 { $$
= build_method_invocation
($1, NULL_TREE
); }
2253 | name OP_TK argument_list CP_TK
2254 { $$
= build_method_invocation
($1, $3); }
2255 | primary DOT_TK identifier OP_TK CP_TK
2257 if
(TREE_CODE
($1) == THIS_EXPR
)
2258 $$
= build_this_super_qualified_invocation
2259 (1, $3, NULL_TREE
, 0, $2.location
);
2262 tree invok
= build_method_invocation
($3, NULL_TREE
);
2263 $$
= make_qualified_primary
($1, invok
, $2.location
);
2266 | primary DOT_TK identifier OP_TK argument_list CP_TK
2268 if
(TREE_CODE
($1) == THIS_EXPR
)
2269 $$
= build_this_super_qualified_invocation
2270 (1, $3, $5, 0, $2.location
);
2273 tree invok
= build_method_invocation
($3, $5);
2274 $$
= make_qualified_primary
($1, invok
, $2.location
);
2277 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2279 $$
= build_this_super_qualified_invocation
2280 (0, $3, NULL_TREE
, $1.location
, $2.location
);
2282 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2284 $$
= build_this_super_qualified_invocation
2285 (0, $3, $5, $1.location
, $2.location
);
2287 /* Screws up thing. I let it here until I'm convinced it can
2289 | primary DOT_TK error
2290 {yyerror ("'(' expected"); DRECOVER(bad);} */
2291 | SUPER_TK DOT_TK
error CP_TK
2292 { yyerror ("'(' expected"); DRECOVER
(method_invocation
); }
2293 | SUPER_TK DOT_TK
error DOT_TK
2294 { yyerror ("'(' expected"); DRECOVER
(method_invocation
); }
2298 name OSB_TK expression CSB_TK
2299 { $$
= build_array_ref
($2.location
, $1, $3); }
2300 | primary_no_new_array OSB_TK expression CSB_TK
2301 { $$
= build_array_ref
($2.location
, $1, $3); }
2302 | array_creation_initialized OSB_TK expression CSB_TK
2303 { $$
= build_array_ref
($2.location
, $1, $3); }
2306 yyerror ("Missing term and ']' expected");
2307 DRECOVER
(array_access
);
2309 | name OSB_TK expression
error
2311 yyerror ("']' expected");
2312 DRECOVER
(array_access
);
2314 | primary_no_new_array OSB_TK
error
2316 yyerror ("Missing term and ']' expected");
2317 DRECOVER
(array_access
);
2319 | primary_no_new_array OSB_TK expression
error
2321 yyerror ("']' expected");
2322 DRECOVER
(array_access
);
2324 | array_creation_initialized OSB_TK
error
2326 yyerror ("Missing term and ']' expected");
2327 DRECOVER
(array_access
);
2329 | array_creation_initialized OSB_TK expression
error
2331 yyerror ("']' expected");
2332 DRECOVER
(array_access
);
2339 | post_increment_expression
2340 | post_decrement_expression
2343 post_increment_expression:
2344 postfix_expression INCR_TK
2345 { $$
= build_incdec
($2.token
, $2.location
, $1, 1); }
2348 post_decrement_expression:
2349 postfix_expression DECR_TK
2350 { $$
= build_incdec
($2.token
, $2.location
, $1, 1); }
2353 trap_overflow_corner_case:
2354 pre_increment_expression
2355 | pre_decrement_expression
2356 | PLUS_TK unary_expression
2357 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2358 | unary_expression_not_plus_minus
2360 {yyerror ("Missing term"); RECOVER
}
2364 trap_overflow_corner_case
2367 error_if_numeric_overflow
($1);
2370 | MINUS_TK trap_overflow_corner_case
2371 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2373 {yyerror ("Missing term"); RECOVER
}
2376 pre_increment_expression:
2377 INCR_TK unary_expression
2378 {$$
= build_incdec
($1.token
, $1.location
, $2, 0); }
2380 {yyerror ("Missing term"); RECOVER
}
2383 pre_decrement_expression:
2384 DECR_TK unary_expression
2385 {$$
= build_incdec
($1.token
, $1.location
, $2, 0); }
2387 {yyerror ("Missing term"); RECOVER
}
2390 unary_expression_not_plus_minus:
2392 | NOT_TK unary_expression
2393 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2394 | NEG_TK unary_expression
2395 {$$
= build_unaryop
($1.token
, $1.location
, $2); }
2398 {yyerror ("Missing term"); RECOVER
}
2400 {yyerror ("Missing term"); RECOVER
}
2403 cast_expression: /* Error handling here is potentially weak */
2404 OP_TK primitive_type dims CP_TK unary_expression
2407 int osb
= pop_current_osb
(ctxp
);
2409 type
= build_java_array_type
(type
, -1);
2410 $$
= build_cast
($1.location
, type
, $5);
2412 | OP_TK primitive_type CP_TK unary_expression
2413 { $$
= build_cast
($1.location
, $2, $4); }
2414 | OP_TK expression CP_TK unary_expression_not_plus_minus
2415 { $$
= build_cast
($1.location
, $2, $4); }
2416 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2419 int osb
= pop_current_osb
(ctxp
);
2420 obstack_grow
(&temporary_obstack
,
2421 IDENTIFIER_POINTER
(EXPR_WFL_NODE
($2)),
2422 IDENTIFIER_LENGTH
(EXPR_WFL_NODE
($2)));
2424 obstack_grow
(&temporary_obstack
, "[]", 2);
2425 obstack_1grow
(&temporary_obstack
, '\0');
2426 ptr
= obstack_finish
(&temporary_obstack
);
2427 EXPR_WFL_NODE
($2) = get_identifier
(ptr
);
2428 $$
= build_cast
($1.location
, $2, $5);
2430 | OP_TK primitive_type OSB_TK
error
2431 {yyerror ("']' expected, invalid type expression");}
2434 YYNOT_TWICE
yyerror ("Invalid type expression"); RECOVER
;
2437 | OP_TK primitive_type dims CP_TK
error
2438 {yyerror ("Missing term"); RECOVER
;}
2439 | OP_TK primitive_type CP_TK
error
2440 {yyerror ("Missing term"); RECOVER
;}
2441 | OP_TK name dims CP_TK
error
2442 {yyerror ("Missing term"); RECOVER
;}
2445 multiplicative_expression:
2447 | multiplicative_expression MULT_TK unary_expression
2449 $$
= build_binop
(BINOP_LOOKUP
($2.token
),
2450 $2.location
, $1, $3);
2452 | multiplicative_expression DIV_TK unary_expression
2454 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2457 | multiplicative_expression REM_TK unary_expression
2459 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2462 | multiplicative_expression MULT_TK
error
2463 {yyerror ("Missing term"); RECOVER
;}
2464 | multiplicative_expression DIV_TK
error
2465 {yyerror ("Missing term"); RECOVER
;}
2466 | multiplicative_expression REM_TK
error
2467 {yyerror ("Missing term"); RECOVER
;}
2470 additive_expression:
2471 multiplicative_expression
2472 | additive_expression PLUS_TK multiplicative_expression
2474 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2477 | additive_expression MINUS_TK multiplicative_expression
2479 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2482 | additive_expression PLUS_TK
error
2483 {yyerror ("Missing term"); RECOVER
;}
2484 | additive_expression MINUS_TK
error
2485 {yyerror ("Missing term"); RECOVER
;}
2490 | shift_expression LS_TK additive_expression
2492 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2495 | shift_expression SRS_TK additive_expression
2497 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2500 | shift_expression ZRS_TK additive_expression
2502 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2505 | shift_expression LS_TK
error
2506 {yyerror ("Missing term"); RECOVER
;}
2507 | shift_expression SRS_TK
error
2508 {yyerror ("Missing term"); RECOVER
;}
2509 | shift_expression ZRS_TK
error
2510 {yyerror ("Missing term"); RECOVER
;}
2513 relational_expression:
2515 | relational_expression LT_TK shift_expression
2517 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2520 | relational_expression GT_TK shift_expression
2522 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2525 | relational_expression LTE_TK shift_expression
2527 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2530 | relational_expression GTE_TK shift_expression
2532 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2535 | relational_expression INSTANCEOF_TK reference_type
2536 { $$
= build_binop
(INSTANCEOF_EXPR
, $2.location
, $1, $3); }
2537 | relational_expression LT_TK
error
2538 {yyerror ("Missing term"); RECOVER
;}
2539 | relational_expression GT_TK
error
2540 {yyerror ("Missing term"); RECOVER
;}
2541 | relational_expression LTE_TK
error
2542 {yyerror ("Missing term"); RECOVER
;}
2543 | relational_expression GTE_TK
error
2544 {yyerror ("Missing term"); RECOVER
;}
2545 | relational_expression INSTANCEOF_TK
error
2546 {yyerror ("Invalid reference type"); RECOVER
;}
2549 equality_expression:
2550 relational_expression
2551 | equality_expression EQ_TK relational_expression
2553 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2556 | equality_expression NEQ_TK relational_expression
2558 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2561 | equality_expression EQ_TK
error
2562 {yyerror ("Missing term"); RECOVER
;}
2563 | equality_expression NEQ_TK
error
2564 {yyerror ("Missing term"); RECOVER
;}
2569 | and_expression AND_TK equality_expression
2571 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2574 | and_expression AND_TK
error
2575 {yyerror ("Missing term"); RECOVER
;}
2578 exclusive_or_expression:
2580 | exclusive_or_expression XOR_TK and_expression
2582 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2585 | exclusive_or_expression XOR_TK
error
2586 {yyerror ("Missing term"); RECOVER
;}
2589 inclusive_or_expression:
2590 exclusive_or_expression
2591 | inclusive_or_expression OR_TK exclusive_or_expression
2593 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2596 | inclusive_or_expression OR_TK
error
2597 {yyerror ("Missing term"); RECOVER
;}
2600 conditional_and_expression:
2601 inclusive_or_expression
2602 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2604 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2607 | conditional_and_expression BOOL_AND_TK
error
2608 {yyerror ("Missing term"); RECOVER
;}
2611 conditional_or_expression:
2612 conditional_and_expression
2613 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2615 $$
= build_binop
(BINOP_LOOKUP
($2.token
), $2.location
,
2618 | conditional_or_expression BOOL_OR_TK
error
2619 {yyerror ("Missing term"); RECOVER
;}
2622 conditional_expression: /* Error handling here is weak */
2623 conditional_or_expression
2624 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2626 $$
= build3
(CONDITIONAL_EXPR
, NULL_TREE
, $1, $3, $5);
2627 SET_EXPR_LOCATION_FROM_TOKEN
($$
, $2);
2629 | conditional_or_expression REL_QM_TK REL_CL_TK
error
2632 yyerror ("Missing term");
2635 | conditional_or_expression REL_QM_TK
error
2636 {yyerror ("Missing term"); DRECOVER
(2);}
2637 | conditional_or_expression REL_QM_TK expression REL_CL_TK
error
2638 {yyerror ("Missing term"); DRECOVER
(3);}
2641 assignment_expression:
2642 conditional_expression
2647 left_hand_side assignment_operator assignment_expression
2648 { $$
= build_assignment
($2.token
, $2.location
, $1, $3); }
2649 | left_hand_side assignment_operator
error
2651 YYNOT_TWICE
yyerror ("Missing term");
2662 assignment_operator:
2668 assignment_expression
2671 constant_expression:
2677 /* Helper function to retrieve an OSB count. Should be used when the
2678 `dims:' rule is being used. */
2681 pop_current_osb
(struct parser_ctxt
*ctxp
)
2685 if
(ctxp
->osb_depth
< 0)
2688 to_return
= CURRENT_OSB
(ctxp
);
2696 /* This section of the code deal with save/restoring parser contexts.
2697 Add mode documentation here. FIXME */
2699 /* Helper function. Create a new parser context. With
2700 COPY_FROM_PREVIOUS set to a nonzero value, content of the previous
2701 context is copied, otherwise, the new context is zeroed. The newly
2702 created context becomes the current one. */
2705 create_new_parser_context
(int copy_from_previous
)
2707 struct parser_ctxt
*new
;
2709 new
= ggc_alloc
(sizeof
(struct parser_ctxt
));
2710 if
(copy_from_previous
)
2712 memcpy
(new
, ctxp
, sizeof
(struct parser_ctxt
));
2713 /* This flag, indicating the context saves global values,
2714 should only be set by java_parser_context_save_global. */
2715 new
->saved_data_ctx
= 0;
2718 memset
(new
, 0, sizeof
(struct parser_ctxt
));
2724 /* Create a new parser context and make it the current one. */
2727 java_push_parser_context
(void)
2729 create_new_parser_context
(0);
2733 java_pop_parser_context
(int generate
)
2736 struct parser_ctxt
*next
;
2744 input_location
= ctxp
->save_location
;
2745 current_class
= ctxp
->class_type
;
2748 /* If the old and new lexers differ, then free the old one. */
2749 if
(ctxp
->lexer
&& next
&& ctxp
->lexer
!= next
->lexer
)
2750 java_destroy_lexer
(ctxp
->lexer
);
2752 /* Set the single import class file flag to 0 for the current list
2753 of imported things */
2754 for
(current
= ctxp
->import_list
; current
; current
= TREE_CHAIN
(current
))
2755 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(TREE_VALUE
(current
)) = 0;
2757 /* If we pushed a context to parse a class intended to be generated,
2758 we keep it so we can remember the class. What we could actually
2759 do is to just update a list of class names. */
2762 if
(ctxp_for_generation_last
== NULL
)
2763 ctxp_for_generation
= ctxp
;
2765 ctxp_for_generation_last
->next
= ctxp
;
2767 ctxp_for_generation_last
= ctxp
;
2770 /* And restore those of the previous context */
2771 if
((ctxp
= next
)) /* Assignment is really meant here */
2772 for
(current
= ctxp
->import_list
; current
; current
= TREE_CHAIN
(current
))
2773 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(TREE_VALUE
(current
)) = 1;
2776 /* Create a parser context for the use of saving some global
2780 java_parser_context_save_global
(void)
2784 java_push_parser_context
();
2785 ctxp
->saved_data_ctx
= 1;
2788 /* If this context already stores data, create a new one suitable
2789 for data storage. */
2790 else if
(ctxp
->saved_data
)
2792 create_new_parser_context
(1);
2793 ctxp
->saved_data_ctx
= 1;
2796 ctxp
->save_location
= input_location
;
2797 ctxp
->class_type
= current_class
;
2798 ctxp
->function_decl
= current_function_decl
;
2799 ctxp
->saved_data
= 1;
2802 /* Restore some global variables from the previous context. Make the
2803 previous context the current one. */
2806 java_parser_context_restore_global
(void)
2808 input_location
= ctxp
->save_location
;
2809 current_class
= ctxp
->class_type
;
2811 #ifdef USE_MAPPED_LOCATION
2812 SET_EXPR_LOCATION
(wfl_operator
, ctxp
->save_location
);
2814 EXPR_WFL_FILENAME_NODE
(wfl_operator
) = get_identifier
(input_filename
);
2816 current_function_decl
= ctxp
->function_decl
;
2817 ctxp
->saved_data
= 0;
2818 if
(ctxp
->saved_data_ctx
)
2819 java_pop_parser_context
(0);
2822 /* Suspend vital data for the current class/function being parsed so
2823 that an other class can be parsed. Used to let local/anonymous
2824 classes be parsed. */
2827 java_parser_context_suspend
(void)
2829 /* This makes debugging through java_debug_context easier */
2830 static const char *const name
= "<inner buffer context>";
2832 /* Duplicate the previous context, use it to save the globals we're
2834 create_new_parser_context
(1);
2835 ctxp
->function_decl
= current_function_decl
;
2836 ctxp
->class_type
= current_class
;
2838 /* Then create a new context which inherits all data from the
2839 previous one. This will be the new current context */
2840 create_new_parser_context
(1);
2842 /* Help debugging */
2843 ctxp
->next
->filename
= name
;
2846 /* Resume vital data for the current class/function being parsed so
2847 that an other class can be parsed. Used to let local/anonymous
2848 classes be parsed. The trick is the data storing file position
2849 informations must be restored to their current value, so parsing
2850 can resume as if no context was ever saved. */
2853 java_parser_context_resume
(void)
2855 struct parser_ctxt
*old
= ctxp
; /* This one is to be discarded */
2856 struct parser_ctxt
*saver
= old
->next
; /* This one contain saved info */
2857 struct parser_ctxt
*restored
= saver
->next
; /* This one is the old current */
2859 /* We need to inherit the list of classes to complete/generate */
2860 restored
->classd_list
= old
->classd_list
;
2861 restored
->class_list
= old
->class_list
;
2863 /* Restore the current class and function from the saver */
2864 current_class
= saver
->class_type
;
2865 current_function_decl
= saver
->function_decl
;
2867 /* Retrieve the restored context */
2870 /* Re-installed the data for the parsing to carry on */
2871 memcpy
(&ctxp
->marker_begining
, &old
->marker_begining
,
2872 (size_t)(&ctxp
->marker_end
- &ctxp
->marker_begining
));
2875 /* Add a new anchor node to which all statement(s) initializing static
2876 and non static initialized upon declaration field(s) will be
2880 java_parser_context_push_initialized_field
(void)
2884 node
= build_tree_list
(NULL_TREE
, NULL_TREE
);
2885 TREE_CHAIN
(node
) = CPC_STATIC_INITIALIZER_LIST
(ctxp
);
2886 CPC_STATIC_INITIALIZER_LIST
(ctxp
) = node
;
2888 node
= build_tree_list
(NULL_TREE
, NULL_TREE
);
2889 TREE_CHAIN
(node
) = CPC_INITIALIZER_LIST
(ctxp
);
2890 CPC_INITIALIZER_LIST
(ctxp
) = node
;
2892 node
= build_tree_list
(NULL_TREE
, NULL_TREE
);
2893 TREE_CHAIN
(node
) = CPC_INSTANCE_INITIALIZER_LIST
(ctxp
);
2894 CPC_INSTANCE_INITIALIZER_LIST
(ctxp
) = node
;
2897 /* Pop the lists of initialized field. If this lists aren't empty,
2898 remember them so we can use it to create and populate the finit$
2899 or <clinit> functions. */
2902 java_parser_context_pop_initialized_field
(void)
2905 tree class_type
= TREE_TYPE
(GET_CPC
());
2907 if
(CPC_INITIALIZER_LIST
(ctxp
))
2909 stmts
= CPC_INITIALIZER_STMT
(ctxp
);
2910 CPC_INITIALIZER_LIST
(ctxp
) = TREE_CHAIN
(CPC_INITIALIZER_LIST
(ctxp
));
2911 if
(stmts
&& !java_error_count
)
2912 TYPE_FINIT_STMT_LIST
(class_type
) = reorder_static_initialized
(stmts
);
2915 if
(CPC_STATIC_INITIALIZER_LIST
(ctxp
))
2917 stmts
= CPC_STATIC_INITIALIZER_STMT
(ctxp
);
2918 CPC_STATIC_INITIALIZER_LIST
(ctxp
) =
2919 TREE_CHAIN
(CPC_STATIC_INITIALIZER_LIST
(ctxp
));
2920 /* Keep initialization in order to enforce 8.5 */
2921 if
(stmts
&& !java_error_count
)
2922 TYPE_CLINIT_STMT_LIST
(class_type
) = nreverse
(stmts
);
2925 /* JDK 1.1 instance initializers */
2926 if
(CPC_INSTANCE_INITIALIZER_LIST
(ctxp
))
2928 stmts
= CPC_INSTANCE_INITIALIZER_STMT
(ctxp
);
2929 CPC_INSTANCE_INITIALIZER_LIST
(ctxp
) =
2930 TREE_CHAIN
(CPC_INSTANCE_INITIALIZER_LIST
(ctxp
));
2931 if
(stmts
&& !java_error_count
)
2932 TYPE_II_STMT_LIST
(class_type
) = nreverse
(stmts
);
2937 reorder_static_initialized
(tree list
)
2939 /* We have to keep things in order. The alias initializer have to
2940 come first, then the initialized regular field, in reverse to
2941 keep them in lexical order. */
2942 tree marker
, previous
= NULL_TREE
;
2943 for
(marker
= list
; marker
; previous
= marker
, marker
= TREE_CHAIN
(marker
))
2944 if
(TREE_CODE
(marker
) == TREE_LIST
2945 && !TREE_VALUE
(marker
) && !TREE_PURPOSE
(marker
))
2948 /* No static initialized, the list is fine as is */
2950 list
= TREE_CHAIN
(marker
);
2952 /* No marker? reverse the whole list */
2954 list
= nreverse
(list
);
2956 /* Otherwise, reverse what's after the marker and the new reordered
2957 sublist will replace the marker. */
2960 TREE_CHAIN
(previous
) = NULL_TREE
;
2961 list
= nreverse
(list
);
2962 list
= chainon
(TREE_CHAIN
(marker
), list
);
2967 /* Helper functions to dump the parser context stack. */
2969 #define TAB_CONTEXT(C) \
2970 {int i
; for
(i
= 0; i
< (C
); i
++) fputc
(' ', stderr
);}
2973 java_debug_context_do
(int tab
)
2975 struct parser_ctxt
*copy
= ctxp
;
2979 fprintf
(stderr
, "ctxt: 0x%0lX\n", (unsigned long)copy
);
2981 fprintf
(stderr
, "filename: %s\n", copy
->filename
);
2983 fprintf
(stderr
, "package: %s\n",
2985 IDENTIFIER_POINTER
(copy
->package
) : "<none>"));
2987 fprintf
(stderr
, "context for saving: %d\n", copy
->saved_data_ctx
);
2989 fprintf
(stderr
, "saved data: %d\n", copy
->saved_data
);
2995 /* Dump the stacked up parser contexts. Intended to be called from a
2999 java_debug_context
(void)
3001 java_debug_context_do
(0);
3006 /* Flag for the error report routine to issue the error the first time
3007 it's called (overriding the default behavior which is to drop the
3008 first invocation and honor the second one, taking advantage of a
3010 static int force_error
= 0;
3012 /* Reporting an constructor invocation error. */
3014 parse_ctor_invocation_error
(void)
3016 if
(DECL_CONSTRUCTOR_P
(current_function_decl
))
3017 yyerror ("Constructor invocation must be first thing in a constructor");
3019 yyerror ("Only constructors can invoke constructors");
3022 /* Reporting JDK1.1 features not implemented. */
3025 parse_jdk1_1_error
(const char *msg
)
3027 sorry
(": %qs JDK1.1(TM) feature", msg
);
3029 return build_java_empty_stmt
();
3032 static int do_warning
= 0;
3035 yyerror (const char *msgid
)
3037 #ifdef USE_MAPPED_LOCATION
3038 static source_location elc
;
3039 expanded_location xloc
= expand_location
(input_location
);
3040 int current_line
= xloc.line
;
3044 int current_line
= input_line
;
3046 static int prev_lineno
;
3047 static const char *prev_msg
;
3049 char *remainder
, *code_from_source
;
3051 if
(!force_error
&& prev_lineno
== current_line
)
3053 #ifndef USE_MAPPED_LOCATION
3054 current_line
= ctxp
->lexer
->token_start.line
;
3057 /* Save current error location but report latter, when the context is
3059 if
(ctxp
->java_error_flag
== 0)
3061 ctxp
->java_error_flag
= 1;
3062 #ifdef USE_MAPPED_LOCATION
3063 elc
= input_location
;
3065 elc
= ctxp
->lexer
->token_start
;
3067 /* Do something to use the previous line if we're reaching the
3068 end of the file... */
3069 #ifdef VERBOSE_SKELETON
3070 printf
("* Error detected (%s)\n", (msgid ? msgid
: "(null)"));
3075 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
3076 if
(!force_error
&& msgid
== prev_msg
&& prev_lineno
== current_line
)
3079 ctxp
->java_error_flag
= 0;
3081 java_warning_count
++;
3086 if
(elc.col
== 0 && msgid
&& msgid
[1] == ';')
3087 elc
= ctxp
->prev_line_end
;
3092 #ifdef USE_MAPPED_LOCATION
3093 prev_lineno
= current_line
;
3094 code_from_source
= java_get_line_col
(xloc.file
, current_line
, xloc.column
);
3096 save_lineno
= input_line
;
3097 prev_lineno
= input_line
= current_line
;
3098 code_from_source
= java_get_line_col
(input_filename
, current_line
,
3099 ctxp
->lexer
->token_start.col
);
3103 obstack_grow0
(&temporary_obstack
,
3104 code_from_source
, strlen
(code_from_source
));
3105 remainder
= obstack_finish
(&temporary_obstack
);
3107 warning
(0, "%s.\n%s", msgid
, remainder
);
3109 error ("%s.\n%s", msgid
, remainder
);
3111 /* This allow us to cheaply avoid an extra 'Invalid expression
3112 statement' error report when errors have been already reported on
3113 the same line. This occurs when we report an error but don't have
3114 a synchronization point other than ';', which
3115 expression_statement is the only one to take care of. */
3116 #ifndef USE_MAPPED_LOCATION
3117 input_line
= save_lineno
;
3119 ctxp
->prevent_ese
= input_line
;
3123 issue_warning_error_from_context
(
3124 #ifdef USE_MAPPED_LOCATION
3129 const char *gmsgid
, va_list *ap
)
3131 #ifdef USE_MAPPED_LOCATION
3132 source_location saved_location
= input_location
;
3133 expanded_location xloc
= expand_location
(cl
);
3135 java_lc save_lc
= ctxp
->lexer
->token_start
;
3136 const char *saved
= ctxp
->filename
, *saved_input_filename
;
3141 text.err_no
= errno
;
3143 text.format_spec
= gmsgid
;
3144 pp_format_text
(global_dc
->printer
, &text
);
3145 strncpy
(buffer
, pp_formatted_text
(global_dc
->printer
), sizeof
(buffer
) - 1);
3146 buffer
[sizeof
(buffer
) - 1] = '\0';
3147 pp_clear_output_area
(global_dc
->printer
);
3151 #ifdef USE_MAPPED_LOCATION
3152 if
(xloc.file
!= NULL
)
3154 ctxp
->filename
= xloc.file
;
3155 input_location
= cl
;
3158 ctxp
->lexer
->token_start.line
= EXPR_WFL_LINENO
(cl
);
3159 ctxp
->lexer
->token_start.col
= (EXPR_WFL_COLNO
(cl
) == 0xfff ?
-1
3160 : EXPR_WFL_COLNO
(cl
) == 0xffe ?
-2
3161 : EXPR_WFL_COLNO
(cl
));
3163 /* We have a CL, that's a good reason for using it if it contains data */
3164 if
(TREE_CODE
(cl
) == EXPR_WITH_FILE_LOCATION
&& EXPR_WFL_FILENAME_NODE
(cl
))
3165 ctxp
->filename
= EXPR_WFL_FILENAME
(cl
);
3166 saved_input_filename
= input_filename
;
3167 input_filename
= ctxp
->filename
;
3170 java_error
(buffer
);
3171 #ifdef USE_MAPPED_LOCATION
3172 input_location
= saved_location
;
3174 ctxp
->filename
= saved
;
3175 input_filename
= saved_input_filename
;
3176 ctxp
->lexer
->token_start
= save_lc
;
3181 /* Issue an error message at a current source line CL.
3182 FUTURE/FIXME: change cl to be a source_location. */
3185 parse_error_context
(tree cl
, const char *gmsgid
, ...
)
3188 va_start
(ap
, gmsgid
);
3189 #ifdef USE_MAPPED_LOCATION
3190 issue_warning_error_from_context
(EXPR_LOCATION
(cl
), gmsgid
, &ap
);
3192 issue_warning_error_from_context
(cl
, gmsgid
, &ap
);
3197 /* Issue a warning at a current source line CL.
3198 FUTURE/FIXME: change cl to be a source_location. */
3201 parse_warning_context
(tree cl
, const char *gmsgid
, ...
)
3204 va_start
(ap
, gmsgid
);
3207 #ifdef USE_MAPPED_LOCATION
3208 issue_warning_error_from_context
(EXPR_LOCATION
(cl
), gmsgid
, &ap
);
3210 issue_warning_error_from_context
(cl
, gmsgid
, &ap
);
3217 find_expr_with_wfl
(tree node
)
3221 enum tree_code_class code
;
3224 switch
(TREE_CODE
(node
))
3227 node
= BLOCK_EXPR_BODY
(node
);
3231 to_return
= find_expr_with_wfl
(TREE_OPERAND
(node
, 0));
3234 node
= TREE_OPERAND
(node
, 1);
3238 node
= TREE_OPERAND
(node
, 0);
3241 case LABELED_BLOCK_EXPR
:
3242 node
= LABELED_BLOCK_BODY
(node
);
3246 code
= TREE_CODE_CLASS
(TREE_CODE
(node
));
3247 if
(((code
== tcc_unary
) ||
(code
== tcc_binary
)
3248 ||
(code
== tcc_expression
))
3249 && EXPR_WFL_LINECOL
(node
))
3257 /* Issue a missing return statement error. Uses METHOD to figure the
3258 last line of the method the error occurs in. */
3261 missing_return_error
(tree method
)
3263 #ifdef USE_MAPPED_LOCATION
3264 SET_EXPR_LOCATION
(wfl_operator
, DECL_FUNCTION_LAST_LINE
(method
));
3266 EXPR_WFL_SET_LINECOL
(wfl_operator
, DECL_FUNCTION_LAST_LINE
(method
), -2);
3268 parse_error_context
(wfl_operator
, "Missing return statement");
3271 /* Issue an unreachable statement error. From NODE, find the next
3272 statement to report appropriately. */
3274 unreachable_stmt_error
(tree node
)
3276 /* Browse node to find the next expression node that has a WFL. Use
3277 the location to report the error */
3278 if
(TREE_CODE
(node
) == COMPOUND_EXPR
)
3279 node
= find_expr_with_wfl
(TREE_OPERAND
(node
, 1));
3281 node
= find_expr_with_wfl
(node
);
3285 #ifdef USE_MAPPED_LOCATION
3286 SET_EXPR_LOCATION
(wfl_operator
, EXPR_LOCATION
(node
));
3288 EXPR_WFL_SET_LINECOL
(wfl_operator
, EXPR_WFL_LINENO
(node
), -2);
3290 parse_error_context
(wfl_operator
, "Unreachable statement");
3297 not_accessible_field_error
(tree wfl
, tree decl
)
3300 (wfl
, "Can't access %s field %<%s.%s%> from %qs",
3301 accessibility_string
(get_access_flags_from_decl
(decl
)),
3302 GET_TYPE_NAME
(DECL_CONTEXT
(decl
)),
3303 IDENTIFIER_POINTER
(DECL_NAME
(decl
)),
3304 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(current_class
))));
3309 java_report_errors
(void)
3311 if
(java_error_count
)
3312 fprintf
(stderr
, "%d error%s",
3313 java_error_count
, (java_error_count
== 1 ?
"" : "s"));
3314 if
(java_warning_count
)
3315 fprintf
(stderr
, "%s%d warning%s", (java_error_count ?
", " : ""),
3316 java_warning_count
, (java_warning_count
== 1 ?
"" : "s"));
3317 if
(java_error_count || java_warning_count
)
3318 putc
('\n', stderr
);
3319 return java_error_count
;
3323 java_accstring_lookup
(int flags
)
3325 static char buffer
[80];
3326 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3328 /* Access modifier looked-up first for easier report on forbidden
3330 if
(flags
& ACC_PUBLIC
) COPY_RETURN
("public");
3331 if
(flags
& ACC_PRIVATE
) COPY_RETURN
("private");
3332 if
(flags
& ACC_PROTECTED
) COPY_RETURN
("protected");
3333 if
(flags
& ACC_STATIC
) COPY_RETURN
("static");
3334 if
(flags
& ACC_FINAL
) COPY_RETURN
("final");
3335 if
(flags
& ACC_SYNCHRONIZED
) COPY_RETURN
("synchronized");
3336 if
(flags
& ACC_VOLATILE
) COPY_RETURN
("volatile");
3337 if
(flags
& ACC_TRANSIENT
) COPY_RETURN
("transient");
3338 if
(flags
& ACC_NATIVE
) COPY_RETURN
("native");
3339 if
(flags
& ACC_INTERFACE
) COPY_RETURN
("interface");
3340 if
(flags
& ACC_ABSTRACT
) COPY_RETURN
("abstract");
3347 /* Returns a string denoting the accessibility of a class or a member as
3348 indicated by FLAGS. We need a separate function from
3349 java_accstring_lookup, as the latter can return spurious "static", etc.
3350 if package-private access is defined (in which case none of the
3351 relevant access control bits in FLAGS is set). */
3354 accessibility_string
(int flags
)
3356 if
(flags
& ACC_PRIVATE
) return
"private";
3357 if
(flags
& ACC_PROTECTED
) return
"protected";
3358 if
(flags
& ACC_PUBLIC
) return
"public";
3360 return
"package-private";
3363 /* Issuing error messages upon redefinition of classes, interfaces or
3367 classitf_redefinition_error
(const char *context
, tree id
, tree decl
, tree cl
)
3369 parse_error_context
(cl
, "%s %qs already defined in %s:%d",
3370 context
, IDENTIFIER_POINTER
(id
),
3371 DECL_SOURCE_FILE
(decl
), DECL_SOURCE_LINE
(decl
));
3372 /* Here we should point out where its redefined. It's a unicode. FIXME */
3376 variable_redefinition_error
(tree context
, tree name
, tree type
, int line
)
3378 const char *type_name
;
3380 /* Figure a proper name for type. We might haven't resolved it */
3381 if
(TREE_CODE
(type
) == POINTER_TYPE
&& !TREE_TYPE
(type
))
3382 type_name
= IDENTIFIER_POINTER
(TYPE_NAME
(type
));
3384 type_name
= lang_printable_name
(type
, 0);
3386 parse_error_context
(context
,
3387 "Variable %qs is already defined in this method and was declared %<%s %s%> at line %d",
3388 IDENTIFIER_POINTER
(name
),
3389 type_name
, IDENTIFIER_POINTER
(name
), line
);
3392 /* If ANAME is terminated with `[]', it indicates an array. This
3393 function returns the number of `[]' found and if this number is
3394 greater than zero, it extracts the array type name and places it in
3395 the node pointed to by TRIMMED unless TRIMMED is null. */
3398 build_type_name_from_array_name
(tree aname
, tree
*trimmed
)
3400 const char *name
= IDENTIFIER_POINTER
(aname
);
3401 int len
= IDENTIFIER_LENGTH
(aname
);
3404 STRING_STRIP_BRACKETS
(name
, len
, array_dims
);
3406 if
(array_dims
&& trimmed
)
3407 *trimmed
= get_identifier_with_length
(name
, len
);
3413 build_array_from_name
(tree type
, tree type_wfl
, tree name
, tree
*ret_name
)
3417 /* Eventually get more dims */
3418 more_dims
= build_type_name_from_array_name
(name
, &name
);
3420 /* If we have, then craft a new type for this variable */
3425 /* If we have a pointer, use its type */
3426 if
(TREE_CODE
(type
) == POINTER_TYPE
)
3427 type
= TREE_TYPE
(type
);
3429 /* Building the first dimension of a primitive type uses this
3431 if
(JPRIMITIVE_TYPE_P
(type
))
3433 type
= build_java_array_type
(type
, -1);
3436 /* Otherwise, if we have a WFL for this type, use it (the type
3437 is already an array on an unresolved type, and we just keep
3438 on adding dimensions) */
3442 more_dims
+= build_type_name_from_array_name
(TYPE_NAME
(save
),
3446 /* Add all the dimensions */
3448 type
= build_unresolved_array_type
(type
);
3450 /* The type may have been incomplete in the first place */
3452 type
= obtain_incomplete_type
(type
);
3460 /* Build something that the type identifier resolver will identify as
3461 being an array to an unresolved type. TYPE_WFL is a WFL on a
3465 build_unresolved_array_type
(tree type_or_wfl
)
3470 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3471 just create a array type */
3472 if
(TREE_CODE
(type_or_wfl
) == RECORD_TYPE
)
3473 return build_java_array_type
(type_or_wfl
, -1);
3475 obstack_grow
(&temporary_obstack
,
3476 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(type_or_wfl
)),
3477 IDENTIFIER_LENGTH
(EXPR_WFL_NODE
(type_or_wfl
)));
3478 obstack_grow0
(&temporary_obstack
, "[]", 2);
3479 ptr
= obstack_finish
(&temporary_obstack
);
3480 #ifdef USE_MAPPED_LOCATION
3481 wfl
= build_expr_wfl
(get_identifier
(ptr
), EXPR_LOCATION
(type_or_wfl
));
3483 wfl
= build_expr_wfl
(get_identifier
(ptr
),
3484 EXPR_WFL_FILENAME
(type_or_wfl
),
3485 EXPR_WFL_LINENO
(type_or_wfl
),
3486 EXPR_WFL_COLNO
(type_or_wfl
));
3488 /* Re-install the existing qualifications so that the type can be
3489 resolved properly. */
3490 EXPR_WFL_QUALIFICATION
(wfl
) = EXPR_WFL_QUALIFICATION
(type_or_wfl
);
3495 parser_add_interface
(tree class_decl
, tree interface_decl
, tree wfl
)
3497 if
(maybe_add_interface
(TREE_TYPE
(class_decl
), TREE_TYPE
(interface_decl
)))
3498 parse_error_context
(wfl
, "Interface %qs repeated",
3499 IDENTIFIER_POINTER
(DECL_NAME
(interface_decl
)));
3502 /* Bulk of common class/interface checks. Return 1 if an error was
3503 encountered. TAG is 0 for a class, 1 for an interface. */
3506 check_class_interface_creation
(int is_interface
, int flags
, tree raw_name
,
3507 tree qualified_name
, tree decl
, tree cl
)
3510 int sca
= 0; /* Static class allowed */
3511 int icaf
= 0; /* Inner class allowed flags */
3512 int uaaf
= CLASS_MODIFIERS
; /* Usually allowed access flags */
3515 fprintf
(stderr
, " %s%s %s",
3516 (CPC_INNER_P
() ?
"inner" : ""),
3517 (is_interface ?
"interface" : "class"),
3518 IDENTIFIER_POINTER
(qualified_name
));
3520 /* Scope of an interface/class type name:
3521 - Can't be imported by a single type import
3522 - Can't already exists in the package */
3523 if
(IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P
(raw_name
)
3524 && (node
= find_name_in_single_imports
(raw_name
))
3528 (cl
, "%s name %qs clashes with imported type %qs",
3529 (is_interface ?
"Interface" : "Class"),
3530 IDENTIFIER_POINTER
(raw_name
), IDENTIFIER_POINTER
(node
));
3533 if
(decl
&& CLASS_COMPLETE_P
(decl
))
3535 classitf_redefinition_error
((is_interface ?
"Interface" : "Class"),
3536 qualified_name
, decl
, cl
);
3540 if
(check_inner_class_redefinition
(raw_name
, cl
))
3543 /* If public, file name should match class/interface name, except
3544 when dealing with an inner class */
3545 if
(!CPC_INNER_P
() && (flags
& ACC_PUBLIC
))
3547 const char *fname
= input_filename
;
3550 for
(f
= fname
+ strlen
(fname
);
3551 f
!= fname
&& ! IS_DIR_SEPARATOR
(*f
);
3554 if
(IS_DIR_SEPARATOR
(*f
))
3556 if
(strncmp
(IDENTIFIER_POINTER
(raw_name
),
3557 f
, IDENTIFIER_LENGTH
(raw_name
)) ||
3558 f
[IDENTIFIER_LENGTH
(raw_name
)] != '.')
3560 (cl
, "Public %s %qs must be defined in a file called %<%s.java%>",
3561 (is_interface ?
"interface" : "class"),
3562 IDENTIFIER_POINTER
(qualified_name
),
3563 IDENTIFIER_POINTER
(raw_name
));
3566 /* Static classes can be declared only in top level classes. Note:
3567 once static, a inner class is a top level class. */
3568 if
(flags
& ACC_STATIC
)
3570 /* Catch the specific error of declaring an class inner class
3571 with no toplevel enclosing class. Prevent check_modifiers from
3572 complaining a second time */
3573 if
(CPC_INNER_P
() && !TOPLEVEL_CLASS_DECL_P
(GET_CPC
()))
3575 parse_error_context
(cl
, "Inner class %qs can't be static. Static classes can only occur in interfaces and top-level classes",
3576 IDENTIFIER_POINTER
(qualified_name
));
3579 /* Else, in the context of a top-level class declaration, let
3580 `check_modifiers' do its job, otherwise, give it a go */
3582 sca
= (GET_CPC_LIST
() ? ACC_STATIC
: 0);
3585 /* Inner classes can be declared private or protected
3586 within their enclosing classes. */
3589 /* A class which is local to a block can't be public, private,
3590 protected or static. But it is created final, so allow this
3592 if
(current_function_decl
)
3593 icaf
= sca
= uaaf
= ACC_FINAL
;
3596 check_modifiers_consistency
(flags
);
3597 icaf
= ACC_PROTECTED
;
3598 if
(! CLASS_INTERFACE
(GET_CPC
()))
3599 icaf |
= ACC_PRIVATE
;
3606 uaaf
= INTERFACE_INNER_MODIFIERS
;
3608 uaaf
= INTERFACE_MODIFIERS
;
3610 check_modifiers
("Illegal modifier %qs for interface declaration",
3614 check_modifiers
((current_function_decl ?
3615 "Illegal modifier %qs for local class declaration" :
3616 "Illegal modifier %qs for class declaration"),
3617 flags
, uaaf|sca|icaf
);
3621 /* Construct a nested class name. If the final component starts with
3622 a digit, return true. Otherwise return false. */
3624 make_nested_class_name
(tree cpc_list
)
3631 make_nested_class_name
(TREE_CHAIN
(cpc_list
));
3633 /* Pick the qualified name when dealing with the first upmost
3635 name
= (TREE_CHAIN
(cpc_list
)
3636 ? TREE_PURPOSE
(cpc_list
) : DECL_NAME
(TREE_VALUE
(cpc_list
)));
3637 obstack_grow
(&temporary_obstack
,
3638 IDENTIFIER_POINTER
(name
), IDENTIFIER_LENGTH
(name
));
3639 obstack_1grow
(&temporary_obstack
, '$');
3641 return ISDIGIT
(IDENTIFIER_POINTER
(name
)[0]);
3644 /* Can't redefine a class already defined in an earlier scope. */
3647 check_inner_class_redefinition
(tree raw_name
, tree cl
)
3651 for
(scope_list
= GET_CPC_LIST
(); scope_list
;
3652 scope_list
= GET_NEXT_ENCLOSING_CPC
(scope_list
))
3653 if
(raw_name
== GET_CPC_UN_NODE
(scope_list
))
3656 (cl
, "The class name %qs is already defined in this scope. An inner class may not have the same simple name as any of its enclosing classes",
3657 IDENTIFIER_POINTER
(raw_name
));
3663 /* Tries to find a decl for CLASS_TYPE within ENCLOSING. If we fail,
3664 we remember ENCLOSING and SUPER. */
3667 resolve_inner_class
(htab_t circularity_hash
, tree cl
, tree
*enclosing
,
3668 tree
*super
, tree class_type
)
3670 tree local_enclosing
= *enclosing
;
3671 tree local_super
= NULL_TREE
;
3673 while
(local_enclosing
)
3675 tree intermediate
, decl
;
3677 *htab_find_slot
(circularity_hash
, local_enclosing
, INSERT
) =
3680 if
((decl
= find_as_inner_class
(local_enclosing
, class_type
, cl
)))
3683 intermediate
= local_enclosing
;
3684 /* Explore enclosing contexts. */
3685 while
(INNER_CLASS_DECL_P
(intermediate
))
3687 intermediate
= DECL_CONTEXT
(intermediate
);
3688 if
((decl
= find_as_inner_class
(intermediate
, class_type
, cl
)))
3692 /* Now go to the upper classes, bail out if necessary. We will
3693 analyze the returned SUPER and act accordingly (see
3694 do_resolve_class). */
3695 if
(JPRIMITIVE_TYPE_P
(TREE_TYPE
(local_enclosing
))
3696 || TREE_TYPE
(local_enclosing
) == void_type_node
)
3698 parse_error_context
(cl
, "Qualifier must be a reference");
3699 local_enclosing
= NULL_TREE
;
3702 local_super
= CLASSTYPE_SUPER
(TREE_TYPE
(local_enclosing
));
3703 if
(!local_super || local_super
== object_type_node
)
3706 if
(TREE_CODE
(local_super
) == POINTER_TYPE
)
3707 local_super
= do_resolve_class
(NULL
, NULL
, local_super
, NULL
, NULL
);
3709 local_super
= TYPE_NAME
(local_super
);
3711 /* We may not have checked for circular inheritance yet, so do so
3712 here to prevent an infinite loop. */
3713 if
(htab_find
(circularity_hash
, local_super
) != NULL
)
3716 cl
= lookup_cl
(local_enclosing
);
3719 (cl
, "Cyclic inheritance involving %s",
3720 IDENTIFIER_POINTER
(DECL_NAME
(local_enclosing
)));
3721 local_enclosing
= NULL_TREE
;
3724 local_enclosing
= local_super
;
3727 /* We failed. Return LOCAL_SUPER and LOCAL_ENCLOSING. */
3728 *super
= local_super
;
3729 *enclosing
= local_enclosing
;
3734 /* Within ENCLOSING, find a decl for NAME and return it. NAME can be
3738 find_as_inner_class
(tree enclosing
, tree name
, tree cl
)
3740 tree qual
, to_return
;
3744 name
= TYPE_NAME
(name
);
3746 /* First search: within the scope of `enclosing', search for name */
3747 if
(QUALIFIED_P
(name
) && cl
&& EXPR_WFL_NODE
(cl
) == name
)
3748 qual
= EXPR_WFL_QUALIFICATION
(cl
);
3750 qual
= build_tree_list
(cl
, NULL_TREE
);
3752 qual
= build_tree_list
(build_unknown_wfl
(name
), NULL_TREE
);
3754 if
((to_return
= find_as_inner_class_do
(qual
, enclosing
)))
3757 /* We're dealing with a qualified name. Try to resolve thing until
3758 we get something that is an enclosing class. */
3759 if
(QUALIFIED_P
(name
) && cl
&& EXPR_WFL_NODE
(cl
) == name
)
3761 tree acc
= NULL_TREE
, decl
= NULL_TREE
, ptr
;
3763 for
(qual
= EXPR_WFL_QUALIFICATION
(cl
); qual
&& !decl
;
3764 qual
= TREE_CHAIN
(qual
))
3766 acc
= merge_qualified_name
(acc
,
3767 EXPR_WFL_NODE
(TREE_PURPOSE
(qual
)));
3768 BUILD_PTR_FROM_NAME
(ptr
, acc
);
3769 decl
= do_resolve_class
(NULL_TREE
, NULL_TREE
, ptr
, NULL_TREE
, cl
);
3772 /* A NULL qual and a decl means that the search ended
3773 successfully?!? We have to do something then. FIXME */
3778 qual
= EXPR_WFL_QUALIFICATION
(cl
);
3780 /* Otherwise, create a qual for the other part of the resolution. */
3782 qual
= build_tree_list
(build_unknown_wfl
(name
), NULL_TREE
);
3784 return find_as_inner_class_do
(qual
, enclosing
);
3787 /* We go inside the list of sub classes and try to find a way
3791 find_as_inner_class_do
(tree qual
, tree enclosing
)
3796 for
(; qual
&& enclosing
; qual
= TREE_CHAIN
(qual
))
3798 tree name_to_match
= EXPR_WFL_NODE
(TREE_PURPOSE
(qual
));
3799 tree next_enclosing
= NULL_TREE
;
3802 for
(inner_list
= DECL_INNER_CLASS_LIST
(enclosing
);
3803 inner_list
; inner_list
= TREE_CHAIN
(inner_list
))
3805 if
(TREE_VALUE
(inner_list
) == name_to_match
)
3807 next_enclosing
= TREE_PURPOSE
(inner_list
);
3811 enclosing
= next_enclosing
;
3814 return
(!qual
&& enclosing ? enclosing
: NULL_TREE
);
3818 link_nested_class_to_enclosing
(void)
3820 if
(GET_ENCLOSING_CPC
())
3822 tree enclosing
= GET_ENCLOSING_CPC_CONTEXT
();
3823 DECL_INNER_CLASS_LIST
(enclosing
) =
3824 tree_cons
(GET_CPC
(), GET_CPC_UN
(),
3825 DECL_INNER_CLASS_LIST
(enclosing
));
3830 maybe_make_nested_class_name
(tree name
)
3832 tree id
= NULL_TREE
;
3836 /* If we're in a function, we must append a number to create the
3837 nested class name. However, we don't do this if the class we
3838 are constructing is anonymous, because in that case we'll
3839 already have a number as the class name. */
3840 if
(! make_nested_class_name
(GET_CPC_LIST
())
3841 && current_function_decl
!= NULL_TREE
3842 && ! ISDIGIT
(IDENTIFIER_POINTER
(name
)[0]))
3845 sprintf
(buf
, "%d", anonymous_class_counter
);
3846 ++anonymous_class_counter
;
3847 obstack_grow
(&temporary_obstack
, buf
, strlen
(buf
));
3848 obstack_1grow
(&temporary_obstack
, '$');
3850 obstack_grow0
(&temporary_obstack
,
3851 IDENTIFIER_POINTER
(name
),
3852 IDENTIFIER_LENGTH
(name
));
3853 id
= get_identifier
(obstack_finish
(&temporary_obstack
));
3855 QUALIFIED_P
(id
) = 1;
3860 /* If DECL is NULL, create and push a new DECL, record the current
3861 line CL and do other maintenance things. */
3864 maybe_create_class_interface_decl
(tree decl
, tree raw_name
,
3865 tree qualified_name
, tree cl
)
3868 decl
= push_class
(make_class
(), qualified_name
);
3870 /* Take care of the file and line business */
3871 #ifdef USE_MAPPED_LOCATION
3872 DECL_SOURCE_LOCATION
(decl
) = EXPR_LOCATION
(cl
);
3874 DECL_SOURCE_FILE
(decl
) = EXPR_WFL_FILENAME
(cl
);
3875 DECL_SOURCE_LINE
(decl
) = EXPR_WFL_LINENO
(cl
);
3877 CLASS_FROM_SOURCE_P
(TREE_TYPE
(decl
)) = 1;
3878 CLASS_PARSED_P
(TREE_TYPE
(decl
)) = 1;
3879 #ifdef USE_MAPPED_LOCATION
3881 tree tmp
= maybe_get_identifier
(EXPR_FILENAME
(cl
));
3882 CLASS_FROM_CURRENTLY_COMPILED_P
(TREE_TYPE
(decl
)) =
3883 tmp
&& IS_A_COMMAND_LINE_FILENAME_P
(tmp
);
3886 CLASS_FROM_CURRENTLY_COMPILED_P
(TREE_TYPE
(decl
)) =
3887 IS_A_COMMAND_LINE_FILENAME_P
(EXPR_WFL_FILENAME_NODE
(cl
));
3890 PUSH_CPC
(decl
, raw_name
);
3891 DECL_CONTEXT
(decl
) = GET_ENCLOSING_CPC_CONTEXT
();
3893 /* Link the declaration to the already seen ones */
3894 TREE_CHAIN
(decl
) = ctxp
->class_list
;
3895 ctxp
->class_list
= decl
;
3897 /* Create a new nodes in the global lists */
3898 gclass_list
= tree_cons
(NULL_TREE
, decl
, gclass_list
);
3899 all_class_list
= tree_cons
(NULL_TREE
, decl
, all_class_list
);
3901 /* Install a new dependency list element */
3902 create_jdep_list
(ctxp
);
3904 SOURCE_FRONTEND_DEBUG
(("Defining class/interface %s",
3905 IDENTIFIER_POINTER
(qualified_name
)));
3910 add_superinterfaces
(tree decl
, tree interface_list
)
3913 /* Superinterface(s): if present and defined, parser_check_super_interface ()
3914 takes care of ensuring that:
3915 - This is an accessible interface type,
3916 - Circularity detection.
3917 parser_add_interface is then called. If present but not defined,
3918 the check operation is delayed until the super interface gets
3920 for
(node
= interface_list
; node
; node
= TREE_CHAIN
(node
))
3922 tree current
= TREE_PURPOSE
(node
);
3923 tree idecl
= IDENTIFIER_CLASS_VALUE
(EXPR_WFL_NODE
(current
));
3924 if
(idecl
&& CLASS_LOADED_P
(TREE_TYPE
(idecl
)))
3926 if
(!parser_check_super_interface
(idecl
, decl
, current
))
3927 parser_add_interface
(decl
, idecl
, current
);
3930 register_incomplete_type
(JDEP_INTERFACE
,
3931 current
, decl
, NULL_TREE
);
3935 /* Create an interface in pass1 and return its decl. Return the
3936 interface's decl in pass 2. */
3939 create_interface
(int flags
, tree id
, tree super
)
3941 tree raw_name
= EXPR_WFL_NODE
(id
);
3942 tree q_name
= parser_qualified_classname
(raw_name
);
3943 tree decl
= IDENTIFIER_CLASS_VALUE
(q_name
);
3945 /* Certain syntax errors are making SUPER be like ID. Avoid this
3947 if
(ctxp
->class_err
&& id
== super
)
3950 EXPR_WFL_NODE
(id
) = q_name
; /* Keep source location, even if refined. */
3952 /* Basic checks: scope, redefinition, modifiers */
3953 if
(check_class_interface_creation
(1, flags
, raw_name
, q_name
, decl
, id
))
3959 /* Suspend the current parsing context if we're parsing an inner
3963 java_parser_context_suspend
();
3964 /* Interface members are public. */
3965 if
(CLASS_INTERFACE
(GET_CPC
()))
3966 flags |
= ACC_PUBLIC
;
3969 /* Push a new context for (static) initialized upon declaration fields */
3970 java_parser_context_push_initialized_field
();
3972 /* Interface modifiers check
3973 - public/abstract allowed (already done at that point)
3974 - abstract is obsolete (comes first, it's a warning, or should be)
3975 - Can't use twice the same (checked in the modifier rule) */
3976 if
((flags
& ACC_ABSTRACT
) && flag_redundant
)
3977 parse_warning_context
3978 (MODIFIER_WFL
(ABSTRACT_TK
),
3979 "Redundant use of %<abstract%> modifier. Interface %qs is implicitly abstract", IDENTIFIER_POINTER
(raw_name
));
3981 /* Create a new decl if DECL is NULL, otherwise fix it */
3982 decl
= maybe_create_class_interface_decl
(decl
, raw_name
, q_name
, id
);
3984 /* Interfaces are always abstract. */
3985 flags |
= ACC_ABSTRACT
;
3987 /* Inner interfaces are always static. */
3988 if
(INNER_CLASS_DECL_P
(decl
))
3989 flags |
= ACC_STATIC
;
3991 /* Set super info and mark the class a complete */
3992 set_super_info
(ACC_INTERFACE | flags
, TREE_TYPE
(decl
),
3993 object_type_node
, ctxp
->interface_number
);
3994 ctxp
->interface_number
= 0;
3995 CLASS_COMPLETE_P
(decl
) = 1;
3996 add_superinterfaces
(decl
, super
);
3998 /* Eventually sets the @deprecated tag flag */
3999 CHECK_DEPRECATED
(decl
);
4004 /* Patch anonymous class CLASS, by either extending or implementing
4008 patch_anonymous_class
(tree type_decl
, tree class_decl
, tree wfl
)
4010 tree class
= TREE_TYPE
(class_decl
);
4011 tree type
= TREE_TYPE
(type_decl
);
4012 tree binfo
= TYPE_BINFO
(class
);
4014 /* If it's an interface, implement it */
4015 if
(CLASS_INTERFACE
(type_decl
))
4017 if
(parser_check_super_interface
(type_decl
, class_decl
, wfl
))
4020 if
(!VEC_space
(tree
, BINFO_BASE_BINFOS
(binfo
), 1))
4022 /* Extend the binfo - by reallocating and copying it. */
4027 new_binfo
= make_tree_binfo
((BINFO_N_BASE_BINFOS
(binfo
) + 1) * 2);
4028 for
(i
= 0; BINFO_BASE_ITERATE
(binfo
, i
, base_binfo
); i
++)
4029 BINFO_BASE_APPEND
(new_binfo
, base_binfo
);
4030 CLASS_HAS_SUPER_FLAG
(new_binfo
) = CLASS_HAS_SUPER_FLAG
(binfo
);
4031 BINFO_VTABLE
(new_binfo
) = BINFO_VTABLE
(binfo
);
4032 TYPE_BINFO
(class
) = new_binfo
;
4035 /* And add the interface */
4036 parser_add_interface
(class_decl
, type_decl
, wfl
);
4038 /* Otherwise, it's a type we want to extend */
4041 if
(parser_check_super
(type_decl
, class_decl
, wfl
))
4043 BINFO_TYPE
(BINFO_BASE_BINFO
(binfo
, 0)) = type
;
4047 /* Create an anonymous class which extends/implements TYPE_NAME, and return
4051 create_anonymous_class
(tree type_name
)
4054 tree super
= NULL_TREE
, itf
= NULL_TREE
;
4055 tree id
, type_decl
, class
;
4057 /* The unqualified name of the anonymous class. It's just a number. */
4058 sprintf
(buffer
, "%d", anonymous_class_counter
++);
4059 id
= build_wfl_node
(get_identifier
(buffer
));
4060 EXPR_WFL_LINECOL
(id
) = EXPR_WFL_LINECOL
(type_name
);
4062 /* We know about the type to extend/implement. We go ahead */
4063 if
((type_decl
= IDENTIFIER_CLASS_VALUE
(EXPR_WFL_NODE
(type_name
))))
4065 /* Create a class which either implements on extends the designated
4066 class. The class bears an inaccessible name. */
4067 if
(CLASS_INTERFACE
(type_decl
))
4069 /* It's OK to modify it here. It's been already used and
4070 shouldn't be reused */
4071 ctxp
->interface_number
= 1;
4072 /* Interfaces should presented as a list of WFLs */
4073 itf
= build_tree_list
(type_name
, NULL_TREE
);
4079 class
= create_class
(ACC_FINAL
, id
, super
, itf
);
4081 /* We didn't know anything about the stuff. We register a dependence. */
4083 register_incomplete_type
(JDEP_ANONYMOUS
, type_name
, class
, NULL_TREE
);
4085 ANONYMOUS_CLASS_P
(TREE_TYPE
(class
)) = 1;
4089 /* Create a class in pass1 and return its decl. Return class
4090 interface's decl in pass 2. */
4093 create_class
(int flags
, tree id
, tree super
, tree interfaces
)
4095 tree raw_name
= EXPR_WFL_NODE
(id
);
4096 tree class_id
, decl
;
4097 tree super_decl_type
;
4099 /* Certain syntax errors are making SUPER be like ID. Avoid this
4101 if
(ctxp
->class_err
&& id
== super
)
4104 class_id
= parser_qualified_classname
(raw_name
);
4105 decl
= IDENTIFIER_CLASS_VALUE
(class_id
);
4106 EXPR_WFL_NODE
(id
) = class_id
;
4108 /* Basic check: scope, redefinition, modifiers */
4109 if
(check_class_interface_creation
(0, flags
, raw_name
, class_id
, decl
, id
))
4115 /* Suspend the current parsing context if we're parsing an inner
4116 class or an anonymous class. */
4119 java_parser_context_suspend
();
4120 /* Interface members are public. */
4121 if
(CLASS_INTERFACE
(GET_CPC
()))
4122 flags |
= ACC_PUBLIC
;
4125 /* Push a new context for (static) initialized upon declaration fields */
4126 java_parser_context_push_initialized_field
();
4128 /* Class modifier check:
4129 - Allowed modifier (already done at that point)
4130 - abstract AND final forbidden
4131 - Public classes defined in the correct file */
4132 if
((flags
& ACC_ABSTRACT
) && (flags
& ACC_FINAL
))
4134 (id
, "Class %qs can't be declared both abstract and final",
4135 IDENTIFIER_POINTER
(raw_name
));
4137 /* Create a new decl if DECL is NULL, otherwise fix it */
4138 decl
= maybe_create_class_interface_decl
(decl
, raw_name
, class_id
, id
);
4140 /* If SUPER exists, use it, otherwise use Object */
4143 /* java.lang.Object can't extend anything. */
4144 if
(TREE_TYPE
(IDENTIFIER_CLASS_VALUE
(class_id
)) == object_type_node
)
4146 parse_error_context
(id
, "%<java.lang.Object%> can't extend anything");
4151 register_incomplete_type
(JDEP_SUPER
, super
, decl
, NULL_TREE
);
4153 else if
(TREE_TYPE
(decl
) != object_type_node
)
4154 super_decl_type
= object_type_node
;
4155 /* We're defining java.lang.Object */
4157 super_decl_type
= NULL_TREE
;
4159 /* A class nested in an interface is implicitly static. */
4160 if
(INNER_CLASS_DECL_P
(decl
)
4161 && CLASS_INTERFACE
(TYPE_NAME
(TREE_TYPE
(DECL_CONTEXT
(decl
)))))
4163 flags |
= ACC_STATIC
;
4166 /* Set super info and mark the class as complete. */
4167 set_super_info
(flags
, TREE_TYPE
(decl
), super_decl_type
,
4168 ctxp
->interface_number
);
4169 ctxp
->interface_number
= 0;
4170 CLASS_COMPLETE_P
(decl
) = 1;
4171 add_superinterfaces
(decl
, interfaces
);
4173 /* TYPE_VFIELD' is a compiler-generated field used to point to
4174 virtual function tables. In gcj, every class has a common base
4175 virtual function table in java.lang.object. */
4176 TYPE_VFIELD
(TREE_TYPE
(decl
)) = TYPE_VFIELD
(object_type_node
);
4178 /* We keep the compilation unit imports in the class so that
4179 they can be used later to resolve type dependencies that
4180 aren't necessary to solve now. */
4181 TYPE_IMPORT_LIST
(TREE_TYPE
(decl
)) = ctxp
->import_list
;
4182 TYPE_IMPORT_DEMAND_LIST
(TREE_TYPE
(decl
)) = ctxp
->import_demand_list
;
4184 /* Add the private this$<n> field, Replicate final locals still in
4185 scope as private final fields mangled like val$<local_name>.
4186 This does not occur for top level (static) inner classes. */
4187 if
(PURE_INNER_CLASS_DECL_P
(decl
))
4188 add_inner_class_fields
(decl
, current_function_decl
);
4190 /* Eventually sets the @deprecated tag flag */
4191 CHECK_DEPRECATED
(decl
);
4193 /* Reset the anonymous class counter when declaring non inner classes */
4194 if
(!INNER_CLASS_DECL_P
(decl
))
4195 anonymous_class_counter
= 1;
4200 /* End a class declaration: register the statements used to create
4201 finit$ and <clinit>, pop the current class and resume the prior
4202 parser context if necessary. */
4205 end_class_declaration
(int resume
)
4207 /* If an error occurred, context weren't pushed and won't need to be
4208 popped by a resume. */
4209 int no_error_occurred
= ctxp
->next
&& GET_CPC
() != error_mark_node
;
4211 if
(GET_CPC
() != error_mark_node
)
4212 dump_java_tree
(TDI_class
, GET_CPC
());
4214 java_parser_context_pop_initialized_field
();
4216 if
(resume
&& no_error_occurred
)
4217 java_parser_context_resume
();
4219 /* We're ending a class declaration, this is a good time to reset
4220 the interface cout. Note that might have been already done in
4221 create_interface, but if at that time an inner class was being
4222 dealt with, the interface count was reset in a context created
4223 for the sake of handling inner classes declaration. */
4224 ctxp
->interface_number
= 0;
4228 add_inner_class_fields
(tree class_decl
, tree fct_decl
)
4230 tree block
, marker
, f
;
4232 f
= add_field
(TREE_TYPE
(class_decl
),
4233 build_current_thisn
(TREE_TYPE
(class_decl
)),
4234 build_pointer_type
(TREE_TYPE
(DECL_CONTEXT
(class_decl
))),
4236 FIELD_THISN
(f
) = 1;
4241 for
(block
= GET_CURRENT_BLOCK
(fct_decl
);
4242 block
&& TREE_CODE
(block
) == BLOCK
; block
= BLOCK_SUPERCONTEXT
(block
))
4245 for
(decl
= BLOCK_EXPR_DECLS
(block
); decl
; decl
= TREE_CHAIN
(decl
))
4248 tree wfl
, init
, list
;
4250 /* Avoid non final arguments. */
4251 if
(!LOCAL_FINAL_P
(decl
))
4254 MANGLE_OUTER_LOCAL_VARIABLE_NAME
(name
, DECL_NAME
(decl
));
4255 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID
(pname
, DECL_NAME
(decl
));
4256 wfl
= build_wfl_node
(name
);
4257 init
= build_wfl_node
(pname
);
4258 /* Build an initialization for the field: it will be
4259 initialized by a parameter added to finit$, bearing a
4260 mangled name of the field itself (param$<n>.) The
4261 parameter is provided to finit$ by the constructor
4262 invoking it (hence the constructor will also feature a
4263 hidden parameter, set to the value of the outer context
4264 local at the time the inner class is created.)
4266 Note: we take into account all possible locals that can
4267 be accessed by the inner class. It's actually not trivial
4268 to minimize these aliases down to the ones really
4269 used. One way to do that would be to expand all regular
4270 methods first, then finit$ to get a picture of what's
4271 used. It works with the exception that we would have to
4272 go back on all constructor invoked in regular methods to
4273 have their invocation reworked (to include the right amount
4274 of alias initializer parameters.)
4276 The only real way around, I think, is a first pass to
4277 identify locals really used in the inner class. We leave
4278 the flag FIELD_LOCAL_ALIAS_USED around for that future
4281 On the other hand, it only affect local inner classes,
4282 whose constructors (and finit$ call) will be featuring
4283 unnecessary arguments. It's easy for a developer to keep
4284 this number of parameter down by using the `final'
4285 keyword only when necessary. For the time being, we can
4286 issue a warning on unnecessary finals. FIXME */
4287 init
= build_assignment
(ASSIGN_TK
, EXPR_WFL_LINECOL
(wfl
),
4290 /* Register the field. The TREE_LIST holding the part
4291 initialized/initializer will be marked ARG_FINAL_P so
4292 that the created field can be marked
4293 FIELD_LOCAL_ALIAS. */
4294 list
= build_tree_list
(wfl
, init
);
4295 ARG_FINAL_P
(list
) = 1;
4296 register_fields
(ACC_PRIVATE | ACC_FINAL
, TREE_TYPE
(decl
), list
);
4300 if
(!CPC_INITIALIZER_STMT
(ctxp
))
4303 /* If we ever registered an alias field, insert and marker to
4304 remember where the list ends. The second part of the list (the one
4305 featuring initialized fields) so it can be later reversed to
4306 enforce 8.5. The marker will be removed during that operation. */
4307 marker
= build_tree_list
(NULL_TREE
, NULL_TREE
);
4308 TREE_CHAIN
(marker
) = CPC_INITIALIZER_STMT
(ctxp
);
4309 SET_CPC_INITIALIZER_STMT
(ctxp
, marker
);
4312 /* Can't use lookup_field () since we don't want to load the class and
4313 can't set the CLASS_LOADED_P flag */
4316 find_field
(tree class
, tree name
)
4319 for
(decl
= TYPE_FIELDS
(class
); decl
; decl
= TREE_CHAIN
(decl
))
4321 if
(DECL_NAME
(decl
) == name
)
4327 /* Wrap around lookup_field that doesn't potentially upset the value
4331 lookup_field_wrapper
(tree class
, tree name
)
4334 tree decl
= NULL_TREE
;
4335 java_parser_context_save_global
();
4337 /* Last chance: if we're within the context of an inner class, we
4338 might be trying to access a local variable defined in an outer
4339 context. We try to look for it now. */
4340 if
(INNER_CLASS_TYPE_P
(class
) && TREE_CODE
(name
) == IDENTIFIER_NODE
)
4343 MANGLE_OUTER_LOCAL_VARIABLE_NAME
(new_name
, name
);
4344 decl
= lookup_field
(&type
, new_name
);
4345 if
(decl
&& decl
!= error_mark_node
)
4346 FIELD_LOCAL_ALIAS_USED
(decl
) = 1;
4348 if
(!decl || decl
== error_mark_node
)
4351 decl
= lookup_field
(&type
, name
);
4354 /* If the field still hasn't been found, try the next enclosing context. */
4355 if
(!decl
&& INNER_CLASS_TYPE_P
(class
))
4357 tree outer_type
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(class
)));
4358 decl
= lookup_field_wrapper
(outer_type
, name
);
4361 java_parser_context_restore_global
();
4362 return decl
== error_mark_node ? NULL
: decl
;
4365 /* Find duplicate field within the same class declarations and report
4366 the error. Returns 1 if a duplicated field was found, 0
4370 duplicate_declaration_error_p
(tree new_field_name
, tree new_type
, tree cl
)
4372 /* This might be modified to work with method decl as well */
4373 tree decl
= find_field
(TREE_TYPE
(GET_CPC
()), new_field_name
);
4376 char *t1
= xstrdup
(purify_type_name
4377 ((TREE_CODE
(new_type
) == POINTER_TYPE
4378 && TREE_TYPE
(new_type
) == NULL_TREE
) ?
4379 IDENTIFIER_POINTER
(TYPE_NAME
(new_type
)) :
4380 lang_printable_name
(new_type
, 1)));
4381 /* The type may not have been completed by the time we report
4383 char *t2
= xstrdup
(purify_type_name
4384 ((TREE_CODE
(TREE_TYPE
(decl
)) == POINTER_TYPE
4385 && TREE_TYPE
(TREE_TYPE
(decl
)) == NULL_TREE
) ?
4386 IDENTIFIER_POINTER
(TYPE_NAME
(TREE_TYPE
(decl
))) :
4387 lang_printable_name
(TREE_TYPE
(decl
), 1)));
4389 (cl
, "Duplicate variable declaration: %<%s %s%> was %<%s %s%> (%s:%d)",
4390 t1
, IDENTIFIER_POINTER
(new_field_name
),
4391 t2
, IDENTIFIER_POINTER
(DECL_NAME
(decl
)),
4392 DECL_SOURCE_FILE
(decl
), DECL_SOURCE_LINE
(decl
));
4400 /* Field registration routine. If TYPE doesn't exist, field
4401 declarations are linked to the undefined TYPE dependency list, to
4402 be later resolved in java_complete_class () */
4405 register_fields
(int flags
, tree type
, tree variable_list
)
4407 tree current
, saved_type
;
4408 tree class_type
= NULL_TREE
;
4409 location_t saved_location
= input_location
;
4411 tree wfl
= NULL_TREE
;
4414 class_type
= TREE_TYPE
(GET_CPC
());
4416 if
(!class_type || class_type
== error_mark_node
)
4419 /* If we're adding fields to interfaces, those fields are public,
4421 if
(CLASS_INTERFACE
(TYPE_NAME
(class_type
)))
4423 OBSOLETE_MODIFIER_WARNING
(MODIFIER_WFL
(PUBLIC_TK
),
4424 flags
, ACC_PUBLIC
, "interface field(s)");
4425 OBSOLETE_MODIFIER_WARNING
(MODIFIER_WFL
(STATIC_TK
),
4426 flags
, ACC_STATIC
, "interface field(s)");
4427 OBSOLETE_MODIFIER_WARNING
(MODIFIER_WFL
(FINAL_TK
),
4428 flags
, ACC_FINAL
, "interface field(s)");
4429 check_modifiers
("Illegal interface member modifier %qs", flags
,
4430 INTERFACE_FIELD_MODIFIERS
);
4431 flags |
= (ACC_PUBLIC | ACC_STATIC | ACC_FINAL
);
4434 /* Obtain a suitable type for resolution, if necessary */
4435 SET_TYPE_FOR_RESOLUTION
(type
, wfl
, must_chain
);
4437 /* If TYPE is fully resolved and we don't have a reference, make one */
4438 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
4440 for
(current
= variable_list
, saved_type
= type
; current
;
4441 current
= TREE_CHAIN
(current
), type
= saved_type
)
4445 tree cl
= TREE_PURPOSE
(current
);
4446 tree init
= TREE_VALUE
(current
);
4447 tree current_name
= EXPR_WFL_NODE
(cl
);
4449 /* Can't declare non-final static fields in inner classes */
4450 if
((flags
& ACC_STATIC
) && !TOPLEVEL_CLASS_TYPE_P
(class_type
)
4451 && !(flags
& ACC_FINAL
))
4453 (cl
, "Field %qs can't be static in inner class %qs unless it is final",
4454 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(cl
)),
4455 lang_printable_name
(class_type
, 0));
4457 /* Process NAME, as it may specify extra dimension(s) for it */
4458 type
= build_array_from_name
(type
, wfl
, current_name
, ¤t_name
);
4460 /* Type adjustment. We may have just readjusted TYPE because
4461 the variable specified more dimensions. Make sure we have
4462 a reference if we can and don't have one already. Also
4463 change the name if we have an init. */
4464 if
(type
!= saved_type
)
4466 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
4468 EXPR_WFL_NODE
(TREE_OPERAND
(init
, 0)) = current_name
;
4471 real_type
= GET_REAL_TYPE
(type
);
4472 /* Check for redeclarations */
4473 if
(duplicate_declaration_error_p
(current_name
, real_type
, cl
))
4476 /* Set input_line to the line the field was found and create a
4477 declaration for it. Eventually sets the @deprecated tag flag. */
4478 #ifdef USE_MAPPED_LOCATION
4479 input_location
= EXPR_LOCATION
(cl
);
4481 input_line
= EXPR_WFL_LINENO
(cl
);
4483 field_decl
= add_field
(class_type
, current_name
, real_type
, flags
);
4484 CHECK_DEPRECATED_NO_RESET
(field_decl
);
4486 /* If the field denotes a final instance variable, then we
4487 allocate a LANG_DECL_SPECIFIC part to keep track of its
4488 initialization. We also mark whether the field was
4489 initialized upon its declaration. We don't do that if the
4490 created field is an alias to a final local. */
4491 if
(!ARG_FINAL_P
(current
) && (flags
& ACC_FINAL
))
4493 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(field_decl
);
4494 DECL_FIELD_FINAL_WFL
(field_decl
) = cl
;
4497 /* If the couple initializer/initialized is marked ARG_FINAL_P,
4498 we mark the created field FIELD_LOCAL_ALIAS, so that we can
4499 hide parameters to this inner class finit$ and
4500 constructors. It also means that the field isn't final per
4502 if
(ARG_FINAL_P
(current
))
4504 FIELD_LOCAL_ALIAS
(field_decl
) = 1;
4505 FIELD_FINAL
(field_decl
) = 0;
4508 /* Check if we must chain. */
4510 register_incomplete_type
(JDEP_FIELD
, wfl
, field_decl
, type
);
4512 /* If we have an initialization value tied to the field */
4515 /* The field is declared static */
4516 if
(flags
& ACC_STATIC
)
4518 /* We include the field and its initialization part into
4519 a list used to generate <clinit>. After <clinit> is
4520 walked, field initializations will be processed and
4521 fields initialized with known constants will be taken
4522 out of <clinit> and have their DECL_INITIAL set
4524 TREE_CHAIN
(init
) = CPC_STATIC_INITIALIZER_STMT
(ctxp
);
4525 SET_CPC_STATIC_INITIALIZER_STMT
(ctxp
, init
);
4526 if
(TREE_OPERAND
(init
, 1)
4527 && TREE_CODE
(TREE_OPERAND
(init
, 1)) == NEW_ARRAY_INIT
)
4528 TREE_STATIC
(TREE_OPERAND
(init
, 1)) = 1;
4530 /* A non-static field declared with an immediate initialization is
4531 to be initialized in <init>, if any. This field is remembered
4532 to be processed at the time of the generation of <init>. */
4535 TREE_CHAIN
(init
) = CPC_INITIALIZER_STMT
(ctxp
);
4536 SET_CPC_INITIALIZER_STMT
(ctxp
, init
);
4538 MODIFY_EXPR_FROM_INITIALIZATION_P
(init
) = 1;
4539 DECL_INITIAL
(field_decl
) = TREE_OPERAND
(init
, 1);
4544 input_location
= saved_location
;
4547 /* Generate finit$, using the list of initialized fields to populate
4548 its body. finit$'s parameter(s) list is adjusted to include the
4549 one(s) used to initialized the field(s) caching outer context
4553 generate_finit
(tree class_type
)
4556 tree list
= TYPE_FINIT_STMT_LIST
(class_type
);
4557 tree mdecl
, current
, parms
;
4559 parms
= build_alias_initializer_parameter_list
(AIPL_FUNCTION_CREATION
,
4560 class_type
, NULL_TREE
,
4562 CRAFTED_PARAM_LIST_FIXUP
(parms
);
4563 mdecl
= create_artificial_method
(class_type
, ACC_PRIVATE
, void_type_node
,
4564 finit_identifier_node
, parms
);
4565 fix_method_argument_names
(parms
, mdecl
);
4566 layout_class_method
(class_type
, CLASSTYPE_SUPER
(class_type
),
4568 DECL_FUNCTION_NAP
(mdecl
) = count
;
4569 start_artificial_method_body
(mdecl
);
4571 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
4572 java_method_add_stmt
(mdecl
,
4573 build_debugable_stmt
(EXPR_WFL_LINECOL
(current
),
4575 end_artificial_method_body
(mdecl
);
4579 /* Generate a function to run the instance initialization code. The
4580 private method is called `instinit$'. Unless we're dealing with an
4581 anonymous class, we determine whether all ctors of CLASS_TYPE
4582 declare a checked exception in their `throws' clause in order to
4583 see whether it's necessary to encapsulate the instance initializer
4584 statements in a try/catch/rethrow sequence. */
4587 generate_instinit
(tree class_type
)
4590 tree compound
= NULL_TREE
;
4591 tree parms
= tree_cons
(this_identifier_node
,
4592 build_pointer_type
(class_type
), end_params_node
);
4593 tree mdecl
= create_artificial_method
(class_type
, ACC_PRIVATE
,
4595 instinit_identifier_node
, parms
);
4597 layout_class_method
(class_type
, CLASSTYPE_SUPER
(class_type
),
4600 /* Gather all the statements in a compound */
4601 for
(current
= TYPE_II_STMT_LIST
(class_type
);
4602 current
; current
= TREE_CHAIN
(current
))
4603 compound
= add_stmt_to_compound
(compound
, NULL_TREE
, current
);
4605 /* We need to encapsulate COMPOUND by a try/catch statement to
4606 rethrow exceptions that might occur in the instance initializer.
4607 We do that only if all ctors of CLASS_TYPE are set to catch a
4608 checked exception. This doesn't apply to anonymous classes (since
4609 they don't have declared ctors.) */
4610 if
(!ANONYMOUS_CLASS_P
(class_type
) &&
4611 ctors_unchecked_throws_clause_p
(class_type
))
4613 compound
= encapsulate_with_try_catch
(0, exception_type_node
, compound
,
4614 build1
(THROW_EXPR
, NULL_TREE
,
4615 build_wfl_node
(wpv_id
)));
4616 DECL_FUNCTION_THROWS
(mdecl
) = build_tree_list
(NULL_TREE
,
4617 exception_type_node
);
4620 start_artificial_method_body
(mdecl
);
4621 java_method_add_stmt
(mdecl
, compound
);
4622 end_artificial_method_body
(mdecl
);
4629 build_instinit_invocation
(tree class_type
)
4631 tree to_return
= NULL_TREE
;
4633 if
(TYPE_II_STMT_LIST
(class_type
))
4635 tree parm
= build_tree_list
(NULL_TREE
,
4636 build_wfl_node
(this_identifier_node
));
4638 build_method_invocation
(build_wfl_node
(instinit_identifier_node
),
4644 /* Shared across method_declarator and method_header to remember the
4645 patch stage that was reached during the declaration of the method.
4646 A method DECL is built differently is there is no patch
4647 (JDEP_NO_PATCH) or a patch (JDEP_METHOD or JDEP_METHOD_RETURN)
4648 pending on the currently defined method. */
4650 static int patch_stage
;
4652 /* Check the method declaration and add the method to its current
4653 class. If the argument list is known to contain incomplete types,
4654 the method is partially added and the registration will be resume
4655 once the method arguments resolved. If TYPE is NULL, we're dealing
4656 with a constructor. */
4659 method_header
(int flags
, tree type
, tree mdecl
, tree throws
)
4661 tree type_wfl
= NULL_TREE
;
4662 tree meth_name
= NULL_TREE
;
4663 tree current
, orig_arg
, this_class
= NULL
;
4665 location_t saved_location
;
4666 int constructor_ok
= 0, must_chain
;
4669 if
(mdecl
== error_mark_node
)
4670 return error_mark_node
;
4671 meth
= TREE_VALUE
(mdecl
);
4672 id
= TREE_PURPOSE
(mdecl
);
4674 check_modifiers_consistency
(flags
);
4677 this_class
= TREE_TYPE
(GET_CPC
());
4679 if
(!this_class || this_class
== error_mark_node
)
4682 /* There are some forbidden modifiers for an abstract method and its
4683 class must be abstract as well. */
4684 if
(type
&& (flags
& ACC_ABSTRACT
))
4686 ABSTRACT_CHECK
(flags
, ACC_PRIVATE
, id
, "Private");
4687 ABSTRACT_CHECK
(flags
, ACC_STATIC
, id
, "Static");
4688 ABSTRACT_CHECK
(flags
, ACC_FINAL
, id
, "Final");
4689 ABSTRACT_CHECK
(flags
, ACC_NATIVE
, id
, "Native");
4690 ABSTRACT_CHECK
(flags
, ACC_SYNCHRONIZED
, id
, "Synchronized");
4691 ABSTRACT_CHECK
(flags
, ACC_STRICT
, id
, "Strictfp");
4692 if
(!CLASS_ABSTRACT
(TYPE_NAME
(this_class
))
4693 && !CLASS_INTERFACE
(TYPE_NAME
(this_class
)))
4696 "Class %qs must be declared abstract to define abstract method %qs",
4697 IDENTIFIER_POINTER
(DECL_NAME
(GET_CPC
())),
4698 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
4701 /* A native method can't be strictfp. */
4702 if
((flags
& ACC_NATIVE
) && (flags
& ACC_STRICT
))
4703 parse_error_context
(id
, "native method %qs can't be strictfp",
4704 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
4705 /* No such thing as a transient or volatile method. */
4706 if
((flags
& ACC_TRANSIENT
))
4707 parse_error_context
(id
, "method %qs can't be transient",
4708 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
4709 if
((flags
& ACC_VOLATILE
))
4710 parse_error_context
(id
, "method %qs can't be volatile",
4711 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
4713 /* Things to be checked when declaring a constructor */
4716 int ec
= java_error_count
;
4717 /* 8.6: Constructor declarations: we might be trying to define a
4718 method without specifying a return type. */
4719 if
(EXPR_WFL_NODE
(id
) != GET_CPC_UN
())
4721 (id
, "Invalid method declaration, return type required");
4722 /* 8.6.3: Constructor modifiers */
4725 JCONSTRUCTOR_CHECK
(flags
, ACC_ABSTRACT
, id
, "abstract");
4726 JCONSTRUCTOR_CHECK
(flags
, ACC_STATIC
, id
, "static");
4727 JCONSTRUCTOR_CHECK
(flags
, ACC_FINAL
, id
, "final");
4728 JCONSTRUCTOR_CHECK
(flags
, ACC_NATIVE
, id
, "native");
4729 JCONSTRUCTOR_CHECK
(flags
, ACC_SYNCHRONIZED
, id
, "synchronized");
4730 JCONSTRUCTOR_CHECK
(flags
, ACC_STRICT
, id
, "strictfp");
4732 /* If we found error here, we don't consider it's OK to tread
4733 the method definition as a constructor, for the rest of this
4735 if
(ec
== java_error_count
)
4739 /* Method declared within the scope of an interface are implicitly
4740 abstract and public. Conflicts with other erroneously provided
4741 modifiers are checked right after. */
4743 if
(CLASS_INTERFACE
(TYPE_NAME
(this_class
)))
4745 /* If FLAGS isn't set because of a modifier, turn the
4746 corresponding modifier WFL to NULL so we issue a warning on
4747 the obsolete use of the modifier */
4748 if
(!(flags
& ACC_PUBLIC
))
4749 MODIFIER_WFL
(PUBLIC_TK
) = NULL
;
4750 if
(!(flags
& ACC_ABSTRACT
))
4751 MODIFIER_WFL
(ABSTRACT_TK
) = NULL
;
4752 flags |
= ACC_PUBLIC
;
4753 flags |
= ACC_ABSTRACT
;
4756 /* Inner class can't declare static methods */
4757 if
((flags
& ACC_STATIC
) && !TOPLEVEL_CLASS_TYPE_P
(this_class
))
4760 (id
, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
4761 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)),
4762 lang_printable_name
(this_class
, 0));
4765 /* Modifiers context reset moved up, so abstract method declaration
4766 modifiers can be later checked. */
4768 /* Set constructor returned type to void and method name to <init>,
4769 unless we found an error identifier the constructor (in which
4770 case we retain the original name) */
4773 type
= void_type_node
;
4775 meth_name
= init_identifier_node
;
4778 meth_name
= EXPR_WFL_NODE
(id
);
4780 /* Do the returned type resolution and registration if necessary */
4781 SET_TYPE_FOR_RESOLUTION
(type
, type_wfl
, must_chain
);
4784 type
= build_array_from_name
(type
, type_wfl
, meth_name
, &meth_name
);
4785 EXPR_WFL_NODE
(id
) = meth_name
;
4786 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
4790 patch_stage
= JDEP_METHOD_RETURN
;
4791 register_incomplete_type
(patch_stage
, type_wfl
, id
, type
);
4792 TREE_TYPE
(meth
) = GET_REAL_TYPE
(type
);
4795 TREE_TYPE
(meth
) = type
;
4797 saved_location
= input_location
;
4798 /* When defining an abstract or interface method, the curly
4799 bracket at level 1 doesn't exist because there is no function
4801 #ifdef USE_MAPPED_LOCATION
4802 input_location
= (ctxp
->first_ccb_indent1 ? ctxp
->first_ccb_indent1
:
4803 EXPR_LOCATION
(id
));
4805 input_line
= (ctxp
->first_ccb_indent1 ?
(int) ctxp
->first_ccb_indent1
:
4806 EXPR_WFL_LINENO
(id
));
4809 /* Remember the original argument list */
4810 orig_arg
= TYPE_ARG_TYPES
(meth
);
4812 if
(patch_stage
) /* includes ret type and/or all args */
4815 meth
= add_method_1
(this_class
, flags
, meth_name
, meth
);
4816 /* Patch for the return type */
4817 if
(patch_stage
== JDEP_METHOD_RETURN
)
4819 jdep
= CLASSD_LAST
(ctxp
->classd_list
);
4820 JDEP_GET_PATCH
(jdep
) = &TREE_TYPE
(TREE_TYPE
(meth
));
4822 /* This is the stop JDEP. METH allows the function's signature
4824 register_incomplete_type
(JDEP_METHOD_END
, NULL_TREE
, meth
, NULL_TREE
);
4827 meth
= add_method
(this_class
, flags
, meth_name
,
4828 build_java_signature
(meth
));
4830 /* Remember final parameters */
4831 MARK_FINAL_PARMS
(meth
, orig_arg
);
4833 /* Fix the method argument list so we have the argument name
4835 fix_method_argument_names
(orig_arg
, meth
);
4837 /* Register the parameter number and re-install the current line
4839 DECL_MAX_LOCALS
(meth
) = ctxp
->formal_parameter_number
+1;
4840 input_location
= saved_location
;
4842 /* Register exception specified by the `throws' keyword for
4843 resolution and set the method decl appropriate field to the list.
4844 Note: the grammar ensures that what we get here are class
4848 throws
= nreverse
(throws
);
4849 for
(current
= throws
; current
; current
= TREE_CHAIN
(current
))
4851 register_incomplete_type
(JDEP_EXCEPTION
, TREE_VALUE
(current
),
4852 NULL_TREE
, NULL_TREE
);
4853 JDEP_GET_PATCH
(CLASSD_LAST
(ctxp
->classd_list
)) =
4854 &TREE_VALUE
(current
);
4856 DECL_FUNCTION_THROWS
(meth
) = throws
;
4859 if
(TREE_TYPE
(GET_CPC
()) != object_type_node
)
4860 DECL_FUNCTION_WFL
(meth
) = id
;
4862 /* Set the flag if we correctly processed a constructor */
4865 DECL_CONSTRUCTOR_P
(meth
) = 1;
4866 /* Compute and store the number of artificial parameters declared
4867 for this constructor */
4868 for
(count
= 0, current
= TYPE_FIELDS
(this_class
); current
;
4869 current
= TREE_CHAIN
(current
))
4870 if
(FIELD_LOCAL_ALIAS
(current
))
4872 DECL_FUNCTION_NAP
(meth
) = count
;
4875 /* Eventually set the @deprecated tag flag */
4876 CHECK_DEPRECATED
(meth
);
4882 fix_method_argument_names
(tree orig_arg
, tree meth
)
4884 tree arg
= TYPE_ARG_TYPES
(TREE_TYPE
(meth
));
4885 if
(TREE_CODE
(TREE_TYPE
(meth
)) == METHOD_TYPE
)
4887 TREE_PURPOSE
(arg
) = this_identifier_node
;
4888 arg
= TREE_CHAIN
(arg
);
4890 while
(orig_arg
!= end_params_node
)
4892 TREE_PURPOSE
(arg
) = TREE_PURPOSE
(orig_arg
);
4893 orig_arg
= TREE_CHAIN
(orig_arg
);
4894 arg
= TREE_CHAIN
(arg
);
4898 /* Complete the method declaration with METHOD_BODY. */
4901 finish_method_declaration
(tree method_body
)
4905 if
(!current_function_decl
)
4908 flags
= get_access_flags_from_decl
(current_function_decl
);
4910 /* 8.4.5 Method Body */
4911 if
((flags
& ACC_ABSTRACT || flags
& ACC_NATIVE
) && method_body
)
4913 tree name
= DECL_NAME
(current_function_decl
);
4914 parse_error_context
(DECL_FUNCTION_WFL
(current_function_decl
),
4915 "%s method %qs can't have a body defined",
4916 (METHOD_NATIVE
(current_function_decl
) ?
4917 "Native" : "Abstract"),
4918 IDENTIFIER_POINTER
(name
));
4919 method_body
= NULL_TREE
;
4921 else if
(!(flags
& ACC_ABSTRACT
) && !(flags
& ACC_NATIVE
) && !method_body
)
4923 tree name
= DECL_NAME
(current_function_decl
);
4925 (DECL_FUNCTION_WFL
(current_function_decl
),
4926 "Non native and non abstract method %qs must have a body defined",
4927 IDENTIFIER_POINTER
(name
));
4928 method_body
= NULL_TREE
;
4931 if
(flag_emit_class_files
&& method_body
4932 && TREE_CODE
(method_body
) == NOP_EXPR
4933 && TREE_TYPE
(current_function_decl
)
4934 && TREE_TYPE
(TREE_TYPE
(current_function_decl
)) == void_type_node
)
4935 method_body
= build1
(RETURN_EXPR
, void_type_node
, NULL
);
4937 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(current_function_decl
)) = method_body
;
4938 maybe_absorb_scoping_blocks
();
4939 /* Exit function's body */
4941 /* Merge last line of the function with first line, directly in the
4942 function decl. It will be used to emit correct debug info. */
4943 DECL_FUNCTION_LAST_LINE
(current_function_decl
) = ctxp
->last_ccb_indent1
;
4945 /* Since function's argument's list are shared, reset the
4946 ARG_FINAL_P parameter that might have been set on some of this
4947 function parameters. */
4948 UNMARK_FINAL_PARMS
(current_function_decl
);
4950 /* So we don't have an irrelevant function declaration context for
4951 the next static block we'll see. */
4952 current_function_decl
= NULL_TREE
;
4955 /* Build a an error message for constructor circularity errors. */
4958 constructor_circularity_msg
(tree from
, tree to
)
4960 static char string [4096];
4961 char *t
= xstrdup
(lang_printable_name
(from
, 2));
4962 sprintf
(string, "'%s' invokes '%s'", t
, lang_printable_name
(to
, 2));
4967 /* Verify a circular call to METH. Return 1 if an error is found, 0
4970 static GTY
(()) tree vcc_list
;
4972 verify_constructor_circularity
(tree meth
, tree current
)
4976 for
(c
= DECL_CONSTRUCTOR_CALLS
(current
); c
; c
= TREE_CHAIN
(c
))
4978 if
(TREE_VALUE
(c
) == meth
)
4984 vcc_list
= nreverse
(vcc_list
);
4985 for
(liste
= vcc_list
; liste
; liste
= TREE_CHAIN
(liste
))
4988 (TREE_PURPOSE
(TREE_PURPOSE
(liste
)), "%s",
4989 constructor_circularity_msg
4990 (TREE_VALUE
(liste
), TREE_VALUE
(TREE_PURPOSE
(liste
))));
4994 t
= xstrdup
(lang_printable_name
(meth
, 2));
4995 parse_error_context
(TREE_PURPOSE
(c
),
4996 "%s: recursive invocation of constructor %qs",
4997 constructor_circularity_msg
(current
, meth
), t
);
4999 vcc_list
= NULL_TREE
;
5003 for
(c
= DECL_CONSTRUCTOR_CALLS
(current
); c
; c
= TREE_CHAIN
(c
))
5005 vcc_list
= tree_cons
(c
, current
, vcc_list
);
5006 if
(verify_constructor_circularity
(meth
, TREE_VALUE
(c
)))
5008 vcc_list
= TREE_CHAIN
(vcc_list
);
5013 /* Check modifiers that can be declared but exclusively */
5016 check_modifiers_consistency
(int flags
)
5019 tree cl
= NULL_TREE
;
5021 THIS_MODIFIER_ONLY
(flags
, ACC_PUBLIC
, PUBLIC_TK
, acc_count
, cl
);
5022 THIS_MODIFIER_ONLY
(flags
, ACC_PRIVATE
, PRIVATE_TK
, acc_count
, cl
);
5023 THIS_MODIFIER_ONLY
(flags
, ACC_PROTECTED
, PROTECTED_TK
, acc_count
, cl
);
5026 (cl
, "Inconsistent member declaration. At most one of %<public%>, %<private%>, or %<protected%> may be specified");
5030 THIS_MODIFIER_ONLY
(flags
, ACC_FINAL
, FINAL_TK
, acc_count
, cl
);
5031 THIS_MODIFIER_ONLY
(flags
, ACC_VOLATILE
, VOLATILE_TK
, acc_count
, cl
);
5033 parse_error_context
(cl
,
5034 "Inconsistent member declaration. At most one of %<final%> or %<volatile%> may be specified");
5037 /* Check the methode header METH for abstract specifics features */
5040 check_abstract_method_header
(tree meth
)
5042 int flags
= get_access_flags_from_decl
(meth
);
5044 OBSOLETE_MODIFIER_WARNING2
(MODIFIER_WFL
(ABSTRACT_TK
), flags
,
5045 ACC_ABSTRACT
, "abstract method",
5046 IDENTIFIER_POINTER
(DECL_NAME
(meth
)));
5047 OBSOLETE_MODIFIER_WARNING2
(MODIFIER_WFL
(PUBLIC_TK
), flags
,
5048 ACC_PUBLIC
, "abstract method",
5049 IDENTIFIER_POINTER
(DECL_NAME
(meth
)));
5051 check_modifiers
("Illegal modifier %qs for interface method",
5052 flags
, INTERFACE_METHOD_MODIFIERS
);
5055 /* Create a FUNCTION_TYPE node and start augmenting it with the
5056 declared function arguments. Arguments type that can't be resolved
5057 are left as they are, but the returned node is marked as containing
5058 incomplete types. */
5061 method_declarator
(tree id
, tree list
)
5063 tree arg_types
= NULL_TREE
, current
, node
;
5064 tree meth
= make_node
(FUNCTION_TYPE
);
5067 patch_stage
= JDEP_NO_PATCH
;
5069 if
(GET_CPC
() == error_mark_node
)
5070 return error_mark_node
;
5072 /* If we're dealing with an inner class constructor, we hide the
5073 this$<n> decl in the name field of its parameter declaration. We
5074 also might have to hide the outer context local alias
5075 initializers. Not done when the class is a toplevel class. */
5076 if
(PURE_INNER_CLASS_DECL_P
(GET_CPC
())
5077 && EXPR_WFL_NODE
(id
) == GET_CPC_UN
())
5079 tree aliases_list
, type
, thisn
;
5080 /* First the aliases, linked to the regular parameters */
5082 build_alias_initializer_parameter_list
(AIPL_FUNCTION_DECLARATION
,
5083 TREE_TYPE
(GET_CPC
()),
5085 list
= chainon
(nreverse
(aliases_list
), list
);
5088 type
= TREE_TYPE
(DECL_CONTEXT
(GET_CPC
()));
5089 thisn
= build_current_thisn
(TREE_TYPE
(GET_CPC
()));
5090 list
= tree_cons
(build_wfl_node
(thisn
), build_pointer_type
(type
),
5094 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
5097 tree wfl_name
= TREE_PURPOSE
(current
);
5098 tree type
= TREE_VALUE
(current
);
5099 tree name
= EXPR_WFL_NODE
(wfl_name
);
5100 tree already
, arg_node
;
5101 tree type_wfl
= NULL_TREE
;
5104 /* Obtain a suitable type for resolution, if necessary */
5105 SET_TYPE_FOR_RESOLUTION
(type
, type_wfl
, must_chain
);
5107 /* Process NAME, as it may specify extra dimension(s) for it */
5108 type
= build_array_from_name
(type
, type_wfl
, name
, &name
);
5109 EXPR_WFL_NODE
(wfl_name
) = name
;
5111 real_type
= GET_REAL_TYPE
(type
);
5112 if
(TREE_CODE
(real_type
) == RECORD_TYPE
)
5114 real_type
= promote_type
(real_type
);
5115 if
(TREE_CODE
(type
) == TREE_LIST
)
5116 TREE_PURPOSE
(type
) = real_type
;
5119 /* Check redefinition */
5120 for
(already
= arg_types
; already
; already
= TREE_CHAIN
(already
))
5121 if
(TREE_PURPOSE
(already
) == name
)
5124 (wfl_name
, "Variable %qs is used more than once in the argument list of method %qs",
5125 IDENTIFIER_POINTER
(name
),
5126 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(id
)));
5130 /* If we've an incomplete argument type, we know there is a location
5131 to patch when the type get resolved, later. */
5135 patch_stage
= JDEP_METHOD
;
5136 type
= register_incomplete_type
(patch_stage
,
5137 type_wfl
, wfl_name
, type
);
5138 jdep
= CLASSD_LAST
(ctxp
->classd_list
);
5139 JDEP_MISC
(jdep
) = id
;
5142 /* The argument node: a name and a (possibly) incomplete type. */
5143 arg_node
= build_tree_list
(name
, real_type
);
5144 /* Remember arguments declared final. */
5145 ARG_FINAL_P
(arg_node
) = ARG_FINAL_P
(current
);
5148 JDEP_GET_PATCH
(jdep
) = &TREE_VALUE
(arg_node
);
5149 TREE_CHAIN
(arg_node
) = arg_types
;
5150 arg_types
= arg_node
;
5152 TYPE_ARG_TYPES
(meth
) = chainon
(nreverse
(arg_types
), end_params_node
);
5153 node
= build_tree_list
(id
, meth
);
5158 unresolved_type_p
(tree wfl
, tree
*returned
)
5160 if
(TREE_CODE
(wfl
) == EXPR_WITH_FILE_LOCATION
)
5164 tree decl
= IDENTIFIER_CLASS_VALUE
(EXPR_WFL_NODE
(wfl
));
5165 if
(decl
&& current_class
&& (decl
== TYPE_NAME
(current_class
)))
5166 *returned
= TREE_TYPE
(decl
);
5167 else if
(GET_CPC_UN
() == EXPR_WFL_NODE
(wfl
))
5168 *returned
= TREE_TYPE
(GET_CPC
());
5170 *returned
= NULL_TREE
;
5179 /* From NAME, build a qualified identifier node using the
5180 qualification from the current package definition. */
5183 parser_qualified_classname
(tree name
)
5185 tree nested_class_name
;
5187 if
((nested_class_name
= maybe_make_nested_class_name
(name
)))
5188 return nested_class_name
;
5191 return merge_qualified_name
(ctxp
->package
, name
);
5196 /* Called once the type a interface extends is resolved. Returns 0 if
5197 everything is OK. */
5200 parser_check_super_interface
(tree super_decl
, tree this_decl
, tree this_wfl
)
5202 tree super_type
= TREE_TYPE
(super_decl
);
5204 /* Has to be an interface */
5205 if
(!CLASS_INTERFACE
(super_decl
))
5208 (this_wfl
, "%s %qs can't implement/extend %s %qs",
5209 (CLASS_INTERFACE
(TYPE_NAME
(TREE_TYPE
(this_decl
))) ?
5210 "Interface" : "Class"),
5211 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
5212 (TYPE_ARRAY_P
(super_type
) ?
"array" : "class"),
5213 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
)));
5217 /* Check top-level interface access. Inner classes are subject to member
5218 access rules (6.6.1). */
5219 if
(! INNER_CLASS_P
(super_type
)
5220 && check_pkg_class_access
(DECL_NAME
(super_decl
),
5221 NULL_TREE
, true
, this_decl
))
5224 SOURCE_FRONTEND_DEBUG
(("Completing interface %s with %s",
5225 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
5226 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
))));
5230 /* Makes sure that SUPER_DECL is suitable to extend THIS_DECL. Returns
5231 0 if everything is OK. */
5234 parser_check_super
(tree super_decl
, tree this_decl
, tree wfl
)
5236 tree super_type
= TREE_TYPE
(super_decl
);
5238 /* SUPER should be a CLASS (neither an array nor an interface) */
5239 if
(TYPE_ARRAY_P
(super_type
) || CLASS_INTERFACE
(TYPE_NAME
(super_type
)))
5242 (wfl
, "Class %qs can't subclass %s %qs",
5243 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
5244 (CLASS_INTERFACE
(TYPE_NAME
(super_type
)) ?
"interface" : "array"),
5245 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
)));
5249 if
(CLASS_FINAL
(TYPE_NAME
(super_type
)))
5251 parse_error_context
(wfl
, "Can't subclass final classes: %s",
5252 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
)));
5256 /* Check top-level class scope. Inner classes are subject to member access
5258 if
(! INNER_CLASS_P
(super_type
)
5259 && (check_pkg_class_access
(DECL_NAME
(super_decl
), wfl
, true
, NULL_TREE
)))
5262 SOURCE_FRONTEND_DEBUG
(("Completing class %s with %s",
5263 IDENTIFIER_POINTER
(DECL_NAME
(this_decl
)),
5264 IDENTIFIER_POINTER
(DECL_NAME
(super_decl
))));
5268 /* Create a new dependency list and link it (in a LIFO manner) to the
5269 CTXP list of type dependency list. */
5272 create_jdep_list
(struct parser_ctxt
*ctxp
)
5274 jdeplist
*new
= xmalloc
(sizeof
(jdeplist
));
5275 new
->first
= new
->last
= NULL
;
5276 new
->next
= ctxp
->classd_list
;
5277 ctxp
->classd_list
= new
;
5281 reverse_jdep_list
(struct parser_ctxt
*ctxp
)
5283 jdeplist
*prev
= NULL
, *current
, *next
;
5284 for
(current
= ctxp
->classd_list
; current
; current
= next
)
5286 next
= current
->next
;
5287 current
->next
= prev
;
5293 /* Create a fake pointer based on the ID stored in
5294 TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
5295 registered again. */
5298 obtain_incomplete_type
(tree type_name
)
5300 tree ptr
= NULL_TREE
, name
;
5302 if
(TREE_CODE
(type_name
) == EXPR_WITH_FILE_LOCATION
)
5303 name
= EXPR_WFL_NODE
(type_name
);
5304 else if
(INCOMPLETE_TYPE_P
(type_name
))
5305 name
= TYPE_NAME
(type_name
);
5309 /* Workaround from build_pointer_type for incomplete types. */
5310 BUILD_PTR_FROM_NAME
(ptr
, name
);
5311 TYPE_MODE
(ptr
) = ptr_mode
;
5317 /* Register a incomplete type whose name is WFL. Reuse PTR if PTR is
5318 non NULL instead of computing a new fake type based on WFL. The new
5319 dependency is inserted in the current type dependency list, in FIFO
5323 register_incomplete_type
(int kind
, tree wfl
, tree decl
, tree ptr
)
5325 jdep
*new
= xmalloc
(sizeof
(jdep
));
5327 if
(!ptr
&& kind
!= JDEP_METHOD_END
) /* JDEP_METHOD_END is a mere marker */
5328 ptr
= obtain_incomplete_type
(wfl
);
5330 JDEP_KIND
(new
) = kind
;
5331 JDEP_DECL
(new
) = decl
;
5332 JDEP_TO_RESOLVE
(new
) = ptr
;
5333 JDEP_WFL
(new
) = wfl
;
5334 JDEP_CHAIN
(new
) = NULL
;
5335 JDEP_MISC
(new
) = NULL_TREE
;
5336 /* For some dependencies, set the enclosing class of the current
5337 class to be the enclosing context */
5338 if
((kind
== JDEP_INTERFACE || kind
== JDEP_ANONYMOUS || kind
== JDEP_SUPER
)
5339 && GET_ENCLOSING_CPC
())
5340 JDEP_ENCLOSING
(new
) = TREE_VALUE
(GET_ENCLOSING_CPC
());
5342 JDEP_ENCLOSING
(new
) = GET_CPC
();
5343 JDEP_GET_PATCH
(new
) = (tree
*)NULL
;
5345 JDEP_INSERT
(ctxp
->classd_list
, new
);
5350 /* This checks for circular references with innerclasses. We start
5351 from SOURCE and should never reach TARGET. Extended/implemented
5352 types in SOURCE have their enclosing context checked not to reach
5353 TARGET. When the last enclosing context of SOURCE is reached, its
5354 extended/implemented types are also checked not to reach TARGET.
5355 In case of error, WFL of the offending type is returned; NULL_TREE
5359 check_inner_circular_reference
(tree source
, tree target
)
5365 for
(i
= 0; BINFO_BASE_ITERATE
(TYPE_BINFO
(source
), i
, base_binfo
); i
++)
5369 /* We can end up with a NULL_TREE or an incomplete type here if
5370 we encountered previous type resolution errors. It's safe to
5371 simply ignore these cases. */
5372 su
= BINFO_TYPE
(base_binfo
);
5373 if
(INCOMPLETE_TYPE_P
(su
))
5376 if
(inherits_from_p
(su
, target
))
5377 return lookup_cl
(TYPE_NAME
(su
));
5379 for
(ctx
= DECL_CONTEXT
(TYPE_NAME
(su
)); ctx
; ctx
= DECL_CONTEXT
(ctx
))
5381 /* An enclosing context shouldn't be TARGET */
5382 if
(ctx
== TYPE_NAME
(target
))
5383 return lookup_cl
(TYPE_NAME
(su
));
5385 /* When we reach the enclosing last context, start a check
5386 on it, with the same target */
5387 if
(! DECL_CONTEXT
(ctx
) &&
5388 (cl
= check_inner_circular_reference
(TREE_TYPE
(ctx
), target
)))
5395 /* Explore TYPE's `extends' clause member(s) and return the WFL of the
5396 offending type if a circularity is detected. NULL_TREE is returned
5397 otherwise. TYPE can be an interface or a class. */
5400 check_circular_reference
(tree type
)
5405 if
(!BINFO_N_BASE_BINFOS
(TYPE_BINFO
(type
)))
5408 if
(! CLASS_INTERFACE
(TYPE_NAME
(type
)))
5410 if
(inherits_from_p
(CLASSTYPE_SUPER
(type
), type
))
5411 return lookup_cl
(TYPE_NAME
(type
));
5415 for
(i
= 0; BINFO_BASE_ITERATE
(TYPE_BINFO
(type
), i
, base_binfo
); i
++)
5417 if
(BINFO_TYPE
(base_binfo
) != object_type_node
5418 && interface_of_p
(type
, BINFO_TYPE
(base_binfo
)))
5419 return lookup_cl
(TYPE_NAME
(BINFO_TYPE
(base_binfo
)));
5425 java_check_circular_reference
(void)
5428 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
5430 tree type
= TREE_TYPE
(current
);
5433 cl
= check_circular_reference
(type
);
5435 cl
= check_inner_circular_reference
(type
, type
);
5437 parse_error_context
(cl
, "Cyclic class inheritance%s",
5438 (cyclic_inheritance_report ?
5439 cyclic_inheritance_report
: ""));
5443 /* Augment the parameter list PARM with parameters crafted to
5444 initialize outer context locals aliases. Through ARTIFICIAL, a
5445 count is kept of the number of crafted parameters. MODE governs
5446 what eventually gets created: something suitable for a function
5447 creation or a function invocation, either the constructor or
5451 build_alias_initializer_parameter_list
(int mode
, tree class_type
, tree parm
,
5455 tree additional_parms
= NULL_TREE
;
5457 for
(field
= TYPE_FIELDS
(class_type
); field
; field
= TREE_CHAIN
(field
))
5458 if
(FIELD_LOCAL_ALIAS
(field
))
5460 const char *buffer
= IDENTIFIER_POINTER
(DECL_NAME
(field
));
5461 tree purpose
= NULL_TREE
, value
= NULL_TREE
, name
= NULL_TREE
;
5466 case AIPL_FUNCTION_DECLARATION
:
5467 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR
(mangled_id
,
5469 purpose
= build_wfl_node
(mangled_id
);
5470 if
(TREE_CODE
(TREE_TYPE
(field
)) == POINTER_TYPE
)
5471 value
= build_wfl_node
(TYPE_NAME
(TREE_TYPE
(field
)));
5473 value
= TREE_TYPE
(field
);
5476 case AIPL_FUNCTION_CREATION
:
5477 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR
(purpose
,
5479 value
= TREE_TYPE
(field
);
5482 case AIPL_FUNCTION_FINIT_INVOCATION
:
5483 MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR
(mangled_id
,
5485 /* Now, this is wrong. purpose should always be the NAME
5486 of something and value its matching value (decl, type,
5487 etc...) FIXME -- but there is a lot to fix. */
5489 /* When invoked for this kind of operation, we already
5490 know whether a field is used or not. */
5491 purpose
= TREE_TYPE
(field
);
5492 value
= build_wfl_node
(mangled_id
);
5495 case AIPL_FUNCTION_CTOR_INVOCATION
:
5496 /* There are two case: the constructor invocation happens
5497 outside the local inner, in which case, locales from the outer
5498 context are directly used.
5500 Otherwise, we fold to using the alias directly. */
5501 if
(class_type
== current_class
)
5505 name
= get_identifier
(&buffer
[4]);
5506 value
= IDENTIFIER_LOCAL_VALUE
(name
);
5510 additional_parms
= tree_cons
(purpose
, value
, additional_parms
);
5514 if
(additional_parms
)
5516 if
(ANONYMOUS_CLASS_P
(class_type
)
5517 && mode
== AIPL_FUNCTION_CTOR_INVOCATION
)
5518 additional_parms
= nreverse
(additional_parms
);
5519 parm
= chainon
(additional_parms
, parm
);
5525 /* Craft a constructor for CLASS_DECL -- what we should do when none
5526 where found. ARGS is non NULL when a special signature must be
5527 enforced. This is the case for anonymous classes. */
5530 craft_constructor
(tree class_decl
, tree args
)
5532 tree class_type
= TREE_TYPE
(class_decl
);
5533 tree parm
= NULL_TREE
;
5534 /* Inherit access flags for the constructor from its enclosing class. */
5535 int valid_ctor_flags
= ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE
;
5536 int flags
= (get_access_flags_from_decl
(class_decl
) & valid_ctor_flags
);
5537 int i
= 0, artificial
= 0;
5538 tree decl
, ctor_name
;
5541 ctor_name
= init_identifier_node
;
5543 /* If we're dealing with an inner class constructor, we hide the
5544 this$<n> decl in the name field of its parameter declaration. */
5545 if
(PURE_INNER_CLASS_TYPE_P
(class_type
))
5547 tree type
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(class_type
)));
5548 parm
= tree_cons
(build_current_thisn
(class_type
),
5549 build_pointer_type
(type
), parm
);
5551 /* Some more arguments to be hidden here. The values of the local
5552 variables of the outer context that the inner class needs to see. */
5553 parm
= build_alias_initializer_parameter_list
(AIPL_FUNCTION_CREATION
,
5558 /* Then if there are any args to be enforced, enforce them now */
5559 for
(; args
&& args
!= end_params_node
; args
= TREE_CHAIN
(args
))
5561 /* If we see a `void *', we need to change it to Object. */
5562 if
(TREE_VALUE
(args
) == TREE_TYPE
(null_pointer_node
))
5563 TREE_VALUE
(args
) = object_ptr_type_node
;
5565 sprintf
(buffer
, "parm%d", i
++);
5566 parm
= tree_cons
(get_identifier
(buffer
), TREE_VALUE
(args
), parm
);
5569 CRAFTED_PARAM_LIST_FIXUP
(parm
);
5570 decl
= create_artificial_method
(class_type
, flags
, void_type_node
,
5572 fix_method_argument_names
(parm
, decl
);
5573 /* Now, mark the artificial parameters. */
5574 DECL_FUNCTION_NAP
(decl
) = artificial
;
5575 DECL_FUNCTION_SYNTHETIC_CTOR
(decl
) = DECL_CONSTRUCTOR_P
(decl
) = 1;
5576 DECL_INLINE
(decl
) = 1;
5581 /* Fix the constructors. This will be called right after circular
5582 references have been checked. It is necessary to fix constructors
5583 early even if no code generation will take place for that class:
5584 some generated constructor might be required by the class whose
5585 compilation triggered this one to be simply loaded. */
5588 java_fix_constructors
(void)
5592 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
5594 tree class_type
= TREE_TYPE
(current
);
5598 if
(CLASS_INTERFACE
(TYPE_NAME
(class_type
)))
5601 output_class
= current_class
= class_type
;
5602 for
(decl
= TYPE_METHODS
(class_type
); decl
; decl
= TREE_CHAIN
(decl
))
5604 if
(DECL_CONSTRUCTOR_P
(decl
))
5606 fix_constructors
(decl
);
5611 /* Anonymous class constructor can't be generated that early. */
5612 if
(!saw_ctor
&& !ANONYMOUS_CLASS_P
(class_type
))
5613 craft_constructor
(current
, NULL_TREE
);
5617 /* safe_layout_class just makes sure that we can load a class without
5618 disrupting the current_class, input_file, input_line, etc, information
5619 about the class processed currently. */
5622 safe_layout_class
(tree class
)
5624 tree save_current_class
= current_class
;
5625 location_t save_location
= input_location
;
5627 layout_class
(class
);
5629 current_class
= save_current_class
;
5630 input_location
= save_location
;
5634 jdep_resolve_class
(jdep
*dep
)
5638 if
(JDEP_RESOLVED_P
(dep
))
5639 decl
= JDEP_RESOLVED_DECL
(dep
);
5642 decl
= resolve_class
(JDEP_ENCLOSING
(dep
), JDEP_TO_RESOLVE
(dep
),
5643 JDEP_DECL
(dep
), JDEP_WFL
(dep
));
5644 JDEP_RESOLVED
(dep
, decl
);
5645 /* If there is no WFL, that's ok. We generate this warning
5647 if
(decl
&& JDEP_WFL
(dep
) != NULL_TREE
)
5648 check_deprecation
(JDEP_WFL
(dep
), decl
);
5652 complete_class_report_errors
(dep
);
5653 else if
(INNER_CLASS_DECL_P
(decl
))
5655 tree inner
= TREE_TYPE
(decl
);
5656 if
(! CLASS_LOADED_P
(inner
))
5658 safe_layout_class
(inner
);
5659 if
(TYPE_SIZE
(inner
) == error_mark_node
)
5660 TYPE_SIZE
(inner
) = NULL_TREE
;
5662 check_inner_class_access
(decl
, JDEP_ENCLOSING
(dep
), JDEP_WFL
(dep
));
5667 /* Complete unsatisfied class declaration and their dependencies */
5670 java_complete_class
(void)
5677 /* Process imports */
5680 /* Reverse things so we have the right order */
5681 ctxp
->class_list
= nreverse
(ctxp
->class_list
);
5682 ctxp
->classd_list
= reverse_jdep_list
(ctxp
);
5684 for
(cclassd
= ctxp
->classd_list
, cclass
= ctxp
->class_list
;
5686 cclass
= TREE_CHAIN
(cclass
), cclassd
= CLASSD_CHAIN
(cclassd
))
5690 for
(dep
= CLASSD_FIRST
(cclassd
); dep
; dep
= JDEP_CHAIN
(dep
))
5693 if
(!(decl
= jdep_resolve_class
(dep
)))
5696 /* Now it's time to patch */
5697 switch
(JDEP_KIND
(dep
))
5700 /* Simply patch super */
5701 if
(parser_check_super
(decl
, JDEP_DECL
(dep
), JDEP_WFL
(dep
)))
5703 BINFO_TYPE
(BINFO_BASE_BINFO
5704 (TYPE_BINFO
(TREE_TYPE
(JDEP_DECL
(dep
))), 0))
5710 /* We do part of the job done in add_field */
5711 tree field_decl
= JDEP_DECL
(dep
);
5712 tree field_type
= TREE_TYPE
(decl
);
5713 if
(TREE_CODE
(field_type
) == RECORD_TYPE
)
5714 field_type
= promote_type
(field_type
);
5715 TREE_TYPE
(field_decl
) = field_type
;
5716 DECL_ALIGN
(field_decl
) = 0;
5717 DECL_USER_ALIGN
(field_decl
) = 0;
5718 layout_decl
(field_decl
, 0);
5719 SOURCE_FRONTEND_DEBUG
5720 (("Completed field/var decl '%s' with '%s'",
5721 IDENTIFIER_POINTER
(DECL_NAME
(field_decl
)),
5722 IDENTIFIER_POINTER
(DECL_NAME
(decl
))));
5725 case JDEP_METHOD
: /* We start patching a method */
5726 case JDEP_METHOD_RETURN
:
5732 type
= TREE_TYPE
(decl
);
5733 if
(TREE_CODE
(type
) == RECORD_TYPE
)
5734 type
= promote_type
(type
);
5735 JDEP_APPLY_PATCH
(dep
, type
);
5736 SOURCE_FRONTEND_DEBUG
5737 (((JDEP_KIND
(dep
) == JDEP_METHOD_RETURN ?
5738 "Completing fct '%s' with ret type '%s'":
5739 "Completing arg '%s' with type '%s'"),
5740 IDENTIFIER_POINTER
(EXPR_WFL_NODE
5741 (JDEP_DECL_WFL
(dep
))),
5742 IDENTIFIER_POINTER
(DECL_NAME
(decl
))));
5746 dep
= JDEP_CHAIN
(dep
);
5747 if
(JDEP_KIND
(dep
) == JDEP_METHOD_END
)
5750 decl
= jdep_resolve_class
(dep
);
5754 tree mdecl
= JDEP_DECL
(dep
), signature
;
5755 /* Recompute and reset the signature, check first that
5756 all types are now defined. If they're not,
5757 don't build the signature. */
5758 if
(check_method_types_complete
(mdecl
))
5760 signature
= build_java_signature
(TREE_TYPE
(mdecl
));
5761 set_java_signature
(TREE_TYPE
(mdecl
), signature
);
5768 case JDEP_INTERFACE
:
5769 if
(parser_check_super_interface
(decl
, JDEP_DECL
(dep
),
5772 parser_add_interface
(JDEP_DECL
(dep
), decl
, JDEP_WFL
(dep
));
5777 type
= TREE_TYPE
(decl
);
5778 if
(TREE_CODE
(type
) == RECORD_TYPE
)
5779 type
= promote_type
(type
);
5780 JDEP_APPLY_PATCH
(dep
, type
);
5784 JDEP_APPLY_PATCH
(dep
, TREE_TYPE
(decl
));
5785 SOURCE_FRONTEND_DEBUG
5786 (("Completing a random type dependency on a '%s' node",
5787 tree_code_name
[TREE_CODE
(JDEP_DECL
(dep
))]));
5790 case JDEP_EXCEPTION
:
5791 JDEP_APPLY_PATCH
(dep
, TREE_TYPE
(decl
));
5792 SOURCE_FRONTEND_DEBUG
5793 (("Completing '%s' 'throws' argument node",
5794 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
)))));
5797 case JDEP_ANONYMOUS
:
5798 patch_anonymous_class
(decl
, JDEP_DECL
(dep
), JDEP_WFL
(dep
));
5809 /* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
5813 resolve_class
(tree enclosing
, tree class_type
, tree decl
, tree cl
)
5815 tree tname
= TYPE_NAME
(class_type
);
5816 tree resolved_type
= TREE_TYPE
(class_type
);
5818 tree resolved_type_decl
;
5820 if
(resolved_type
!= NULL_TREE
)
5822 tree resolved_type_decl
= TYPE_NAME
(resolved_type
);
5823 if
(resolved_type_decl
== NULL_TREE
5824 || TREE_CODE
(resolved_type_decl
) == IDENTIFIER_NODE
)
5826 resolved_type_decl
= build_decl
(TYPE_DECL
,
5827 TYPE_NAME
(class_type
),
5830 return resolved_type_decl
;
5833 /* 1- Check to see if we have an array. If true, find what we really
5835 if
((array_dims
= build_type_name_from_array_name
(tname
,
5836 &TYPE_NAME
(class_type
))))
5837 WFL_STRIP_BRACKET
(cl
, cl
);
5839 /* 2- Resolve the bare type */
5840 if
(!(resolved_type_decl
= do_resolve_class
(enclosing
, NULL_TREE
, class_type
,
5843 resolved_type
= TREE_TYPE
(resolved_type_decl
);
5845 /* 3- If we have an array, reconstruct the array down to its nesting */
5848 for
(; array_dims
; array_dims
--)
5849 resolved_type
= build_java_array_type
(resolved_type
, -1);
5850 resolved_type_decl
= TYPE_NAME
(resolved_type
);
5852 TREE_TYPE
(class_type
) = resolved_type
;
5853 return resolved_type_decl
;
5856 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
5857 are used to report error messages; CL must either be NULL_TREE or a
5858 WFL wrapping a class. Do not try to replace TYPE_NAME (class_type)
5859 by a variable, since it is changed by find_in_imports{_on_demand}
5860 and (but it doesn't really matter) qualify_and_find. */
5863 do_resolve_class
(tree enclosing
, tree import_type
, tree class_type
, tree decl
,
5866 tree new_class_decl
= NULL_TREE
, super
= NULL_TREE
;
5867 tree saved_enclosing_type
= enclosing ? TREE_TYPE
(enclosing
) : NULL_TREE
;
5869 htab_t circularity_hash
;
5871 if
(QUALIFIED_P
(TYPE_NAME
(class_type
)))
5873 /* If the type name is of the form `Q . Id', then Q is either a
5874 package name or a class name. First we try to find Q as a
5875 class and then treat Id as a member type. If we can't find Q
5876 as a class then we fall through. */
5877 tree q
, left
, left_type
, right
;
5878 if
(split_qualified_name
(&left
, &right
, TYPE_NAME
(class_type
)) == 0)
5880 BUILD_PTR_FROM_NAME
(left_type
, left
);
5881 q
= do_resolve_class
(enclosing
, import_type
, left_type
, decl
, cl
);
5885 saved_enclosing_type
= TREE_TYPE
(q
);
5886 BUILD_PTR_FROM_NAME
(class_type
, right
);
5893 /* This hash table is used to register the classes we're going
5894 through when searching the current class as an inner class, in
5895 order to detect circular references. Remember to free it before
5896 returning the section 0- of this function. */
5897 circularity_hash
= htab_create
(20, htab_hash_pointer
, htab_eq_pointer
,
5900 /* 0- Search in the current class as an inner class.
5901 Maybe some code here should be added to load the class or
5902 something, at least if the class isn't an inner class and ended
5903 being loaded from class file. FIXME. */
5906 new_class_decl
= resolve_inner_class
(circularity_hash
, cl
, &enclosing
,
5907 &super
, class_type
);
5911 /* If we haven't found anything because SUPER reached Object and
5912 ENCLOSING happens to be an innerclass, try the enclosing context. */
5913 if
((!super || super
== object_type_node
) &&
5914 enclosing
&& INNER_CLASS_DECL_P
(enclosing
))
5915 enclosing
= DECL_CONTEXT
(enclosing
);
5917 enclosing
= NULL_TREE
;
5920 htab_delete
(circularity_hash
);
5923 return new_class_decl
;
5926 /* 1- Check for the type in single imports. Look at enclosing classes and,
5927 if we're laying out a superclass, at the import list for the subclass.
5928 This will change TYPE_NAME() if something relevant is found. */
5929 if
(import_type
&& TYPE_IMPORT_LIST
(import_type
))
5930 find_in_imports
(import_type
, class_type
);
5931 find_in_imports
(saved_enclosing_type
, class_type
);
5933 /* 2- And check for the type in the current compilation unit */
5934 if
((new_class_decl
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
))))
5936 if
(!CLASS_LOADED_P
(TREE_TYPE
(new_class_decl
)))
5937 load_class
(TYPE_NAME
(class_type
), 0);
5938 return IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
));
5941 /* 3- Search according to the current package definition */
5942 if
(!QUALIFIED_P
(TYPE_NAME
(class_type
)))
5944 if
((new_class_decl
= qualify_and_find
(class_type
, ctxp
->package
,
5945 TYPE_NAME
(class_type
))))
5946 return new_class_decl
;
5949 /* 4- Check the import on demands. Don't allow bar.baz to be
5950 imported from foo.* */
5951 if
(!QUALIFIED_P
(TYPE_NAME
(class_type
)))
5954 && TYPE_IMPORT_DEMAND_LIST
(import_type
)
5955 && find_in_imports_on_demand
(import_type
, class_type
))
5957 if
(find_in_imports_on_demand
(saved_enclosing_type
, class_type
))
5961 /* If found in find_in_imports_on_demand, the type has already been
5963 if
((new_class_decl
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
))))
5964 return new_class_decl
;
5966 /* 5- Check another compilation unit that bears the name of type */
5967 load_class
(TYPE_NAME
(class_type
), 0);
5970 cl
= lookup_cl
(decl
);
5972 /* If we don't have a value for CL, then we're being called recursively.
5973 We can't check package access just yet, but it will be taken care of
5977 if
(check_pkg_class_access
(TYPE_NAME
(class_type
), cl
, true
, NULL_TREE
))
5981 /* 6- Last call for a resolution */
5982 decl_result
= IDENTIFIER_CLASS_VALUE
(TYPE_NAME
(class_type
));
5984 /* The final lookup might have registered a.b.c into a.b$c If we
5985 failed at the first lookup, progressively change the name if
5986 applicable and use the matching DECL instead. */
5987 if
(!decl_result
&& QUALIFIED_P
(TYPE_NAME
(class_type
)))
5990 tree name
= TYPE_NAME
(class_type
);
5991 char *namebuffer
= alloca
(IDENTIFIER_LENGTH
(name
) + 1);
5993 strcpy
(namebuffer
, IDENTIFIER_POINTER
(name
));
5997 /* Reach the last '.', and if applicable, replace it by a `$' and
5998 see if this exists as a type. */
5999 if
((separator
= strrchr
(namebuffer
, '.')))
6002 name
= get_identifier
(namebuffer
);
6003 decl_result
= IDENTIFIER_CLASS_VALUE
(name
);
6005 } while
(!decl_result
&& separator
);
6011 qualify_and_find
(tree class_type
, tree package
, tree name
)
6013 tree new_qualified
= merge_qualified_name
(package
, name
);
6014 tree new_class_decl
;
6016 if
(!IDENTIFIER_CLASS_VALUE
(new_qualified
))
6017 load_class
(new_qualified
, 0);
6018 if
((new_class_decl
= IDENTIFIER_CLASS_VALUE
(new_qualified
)))
6020 if
(!CLASS_LOADED_P
(TREE_TYPE
(new_class_decl
)))
6021 load_class
(TREE_TYPE
(new_class_decl
), 0);
6022 TYPE_NAME
(class_type
) = new_qualified
;
6023 return IDENTIFIER_CLASS_VALUE
(new_qualified
);
6028 /* Resolve NAME and lay it out (if not done and if not the current
6029 parsed class). Return a decl node. This function is meant to be
6030 called when type resolution is necessary during the walk pass. */
6033 resolve_and_layout
(tree something
, tree cl
)
6035 tree decl
, decl_type
;
6037 /* Don't do that on the current class */
6038 if
(something
== current_class
)
6039 return TYPE_NAME
(current_class
);
6041 /* Don't do anything for void and other primitive types */
6042 if
(JPRIMITIVE_TYPE_P
(something
) || something
== void_type_node
)
6045 /* Pointer types can be reall pointer types or fake pointers. When
6046 finding a real pointer, recheck for primitive types */
6047 if
(TREE_CODE
(something
) == POINTER_TYPE
)
6049 if
(TREE_TYPE
(something
))
6051 something
= TREE_TYPE
(something
);
6052 if
(JPRIMITIVE_TYPE_P
(something
) || something
== void_type_node
)
6056 something
= TYPE_NAME
(something
);
6059 /* Don't do anything for arrays of primitive types */
6060 if
(TREE_CODE
(something
) == RECORD_TYPE
&& TYPE_ARRAY_P
(something
)
6061 && JPRIMITIVE_TYPE_P
(TYPE_ARRAY_ELEMENT
(something
)))
6064 /* Something might be a WFL */
6065 if
(TREE_CODE
(something
) == EXPR_WITH_FILE_LOCATION
)
6066 something
= EXPR_WFL_NODE
(something
);
6068 /* Otherwise, if something is not and IDENTIFIER_NODE, it can be a a
6069 TYPE_DECL or a real TYPE */
6070 else if
(TREE_CODE
(something
) != IDENTIFIER_NODE
)
6071 something
= (TREE_CODE
(TYPE_NAME
(something
)) == TYPE_DECL ?
6072 DECL_NAME
(TYPE_NAME
(something
)) : TYPE_NAME
(something
));
6074 if
(!(decl
= resolve_no_layout
(something
, cl
)))
6077 /* Resolve and layout if necessary */
6078 decl_type
= TREE_TYPE
(decl
);
6079 layout_class_methods
(decl_type
);
6081 if
(CLASS_FROM_SOURCE_P
(decl_type
))
6082 java_check_methods
(decl
);
6083 /* Layout the type if necessary */
6084 if
(decl_type
!= current_class
&& !CLASS_LOADED_P
(decl_type
))
6085 safe_layout_class
(decl_type
);
6090 /* Resolve a class, returns its decl but doesn't perform any
6091 layout. The current parsing context is saved and restored */
6094 resolve_no_layout
(tree name
, tree cl
)
6097 BUILD_PTR_FROM_NAME
(ptr
, name
);
6098 java_parser_context_save_global
();
6099 decl
= resolve_class
(TYPE_NAME
(current_class
), ptr
, NULL_TREE
, cl
);
6100 java_parser_context_restore_global
();
6105 /* Called when reporting errors. Skip the '[]'s in a complex array
6106 type description that failed to be resolved. purify_type_name can't
6107 use an identifier tree. */
6110 purify_type_name
(const char *name
)
6112 int len
= strlen
(name
);
6115 STRING_STRIP_BRACKETS
(name
, len
, bracket_found
);
6118 char *stripped_name
= xmemdup
(name
, len
, len
+1);
6119 stripped_name
[len
] = '\0';
6120 return stripped_name
;
6125 /* The type CURRENT refers to can't be found. We print error messages. */
6128 complete_class_report_errors
(jdep
*dep
)
6132 if
(!JDEP_WFL
(dep
))
6135 name
= IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
)));
6136 switch
(JDEP_KIND
(dep
))
6140 (JDEP_WFL
(dep
), "Superclass %qs of class %qs not found",
6141 purify_type_name
(name
),
6142 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
6146 (JDEP_WFL
(dep
), "Type %qs not found in declaration of field %qs",
6147 purify_type_name
(name
),
6148 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
6150 case JDEP_METHOD
: /* Covers arguments */
6152 (JDEP_WFL
(dep
), "Type %qs not found in the declaration of the argument %qs of method %qs",
6153 purify_type_name
(name
),
6154 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_DECL_WFL
(dep
))),
6155 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_MISC
(dep
))));
6157 case JDEP_METHOD_RETURN
: /* Covers return type */
6159 (JDEP_WFL
(dep
), "Type %qs not found in the declaration of the return type of method %qs",
6160 purify_type_name
(name
),
6161 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_DECL_WFL
(dep
))));
6163 case JDEP_INTERFACE
:
6165 (JDEP_WFL
(dep
), "Superinterface %qs of %s %qs not found",
6166 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
))),
6167 (CLASS_OR_INTERFACE
(JDEP_DECL
(dep
), "class", "interface")),
6168 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
6172 (JDEP_WFL
(dep
), "Type %qs not found in the declaration of the local variable %qs",
6173 purify_type_name
(IDENTIFIER_POINTER
6174 (EXPR_WFL_NODE
(JDEP_WFL
(dep
)))),
6175 IDENTIFIER_POINTER
(DECL_NAME
(JDEP_DECL
(dep
))));
6177 case JDEP_EXCEPTION
: /* As specified by `throws' */
6179 (JDEP_WFL
(dep
), "Class %qs not found in %<throws%>",
6180 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(JDEP_WFL
(dep
))));
6183 /* Fix for -Wall. Just break doing nothing. The error will be
6189 /* Return a static string containing the DECL prototype string. If
6190 DECL is a constructor, use the class name instead of the form
6194 get_printable_method_name
(tree decl
)
6196 const char *to_return
;
6197 tree name
= NULL_TREE
;
6199 if
(DECL_CONSTRUCTOR_P
(decl
))
6201 name
= DECL_NAME
(decl
);
6202 DECL_NAME
(decl
) = DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(decl
)));
6205 to_return
= lang_printable_name
(decl
, 2);
6206 if
(DECL_CONSTRUCTOR_P
(decl
))
6207 DECL_NAME
(decl
) = name
;
6212 /* Track method being redefined inside the same class. As a side
6213 effect, set DECL_NAME to an IDENTIFIER (prior entering this
6214 function it's a FWL, so we can track errors more accurately.) */
6217 check_method_redefinition
(tree class
, tree method
)
6221 /* There's no need to verify <clinit> and finit$ and instinit$ */
6222 if
(DECL_CLINIT_P
(method
)
6223 || DECL_FINIT_P
(method
) || DECL_INSTINIT_P
(method
))
6226 sig
= TYPE_ARGUMENT_SIGNATURE
(TREE_TYPE
(method
));
6227 for
(redef
= TYPE_METHODS
(class
); redef
; redef
= TREE_CHAIN
(redef
))
6229 if
(redef
== method
)
6231 if
(DECL_NAME
(redef
) == DECL_NAME
(method
)
6232 && sig
== TYPE_ARGUMENT_SIGNATURE
(TREE_TYPE
(redef
))
6233 && !DECL_ARTIFICIAL
(method
))
6236 (DECL_FUNCTION_WFL
(method
), "Duplicate %s declaration %qs",
6237 (DECL_CONSTRUCTOR_P
(redef
) ?
"constructor" : "method"),
6238 get_printable_method_name
(redef
));
6245 /* Return 1 if check went ok, 0 otherwise. */
6247 check_abstract_method_definitions
(int do_interface
, tree class_decl
,
6250 tree class
= TREE_TYPE
(class_decl
);
6251 tree method
, end_type
;
6254 end_type
= (do_interface ? object_type_node
: type
);
6255 for
(method
= TYPE_METHODS
(type
); method
; method
= TREE_CHAIN
(method
))
6257 tree other_super
, other_method
, method_sig
, method_name
;
6259 int end_type_reached
= 0;
6261 if
(!METHOD_ABSTRACT
(method
) || METHOD_FINAL
(method
))
6264 /* Now verify that somewhere in between TYPE and CLASS,
6265 abstract method METHOD gets a non abstract definition
6266 that is inherited by CLASS. */
6268 method_sig
= build_java_signature
(TREE_TYPE
(method
));
6269 method_name
= DECL_NAME
(method
);
6270 if
(TREE_CODE
(method_name
) == EXPR_WITH_FILE_LOCATION
)
6271 method_name
= EXPR_WFL_NODE
(method_name
);
6273 other_super
= class
;
6275 if
(other_super
== end_type
)
6276 end_type_reached
= 1;
6279 for
(other_method
= TYPE_METHODS
(other_super
); other_method
;
6280 other_method
= TREE_CHAIN
(other_method
))
6282 tree s
= build_java_signature
(TREE_TYPE
(other_method
));
6283 tree other_name
= DECL_NAME
(other_method
);
6285 if
(TREE_CODE
(other_name
) == EXPR_WITH_FILE_LOCATION
)
6286 other_name
= EXPR_WFL_NODE
(other_name
);
6287 if
(!DECL_CLINIT_P
(other_method
)
6288 && !DECL_CONSTRUCTOR_P
(other_method
)
6289 && method_name
== other_name
6291 && !METHOD_ABSTRACT
(other_method
))
6297 other_super
= CLASSTYPE_SUPER
(other_super
);
6298 } while
(!end_type_reached
);
6300 /* Report that abstract METHOD didn't find an implementation
6301 that CLASS can use. */
6304 char *t
= xstrdup
(lang_printable_name
6305 (TREE_TYPE
(TREE_TYPE
(method
)), 0));
6306 tree ccn
= DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(method
)));
6309 (lookup_cl
(class_decl
),
6310 "Class %qs doesn't define the abstract method %<%s %s%> from %s %<%s%>. This method must be defined or %s %qs must be declared abstract",
6311 IDENTIFIER_POINTER
(DECL_NAME
(class_decl
)),
6312 t
, lang_printable_name
(method
, 2),
6313 (CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(method
))) ?
6314 "interface" : "class"),
6315 IDENTIFIER_POINTER
(ccn
),
6316 (CLASS_INTERFACE
(class_decl
) ?
"interface" : "class"),
6317 IDENTIFIER_POINTER
(DECL_NAME
(class_decl
)));
6323 if
(ok
&& do_interface
)
6325 /* Check for implemented interfaces. */
6330 ok
&& BINFO_BASE_ITERATE
(TYPE_BINFO
(type
), i
, base_binfo
);
6332 ok
= check_abstract_method_definitions
(1, class_decl
,
6333 BINFO_TYPE
(base_binfo
));
6339 /* Check that CLASS_DECL somehow implements all inherited abstract
6343 java_check_abstract_method_definitions
(tree class_decl
)
6345 tree class
= TREE_TYPE
(class_decl
);
6346 tree super
, base_binfo
;
6349 if
(CLASS_ABSTRACT
(class_decl
))
6352 /* Check for inherited types */
6355 super
= CLASSTYPE_SUPER
(super
);
6356 check_abstract_method_definitions
(0, class_decl
, super
);
6357 } while
(super
!= object_type_node
);
6359 /* Check for implemented interfaces. */
6360 for
(i
= 1; BINFO_BASE_ITERATE
(TYPE_BINFO
(class
), i
, base_binfo
); i
++)
6361 check_abstract_method_definitions
(1, class_decl
, BINFO_TYPE
(base_binfo
));
6364 /* Check all the types method DECL uses and return 1 if all of them
6365 are now complete, 0 otherwise. This is used to check whether its
6366 safe to build a method signature or not. */
6369 check_method_types_complete
(tree decl
)
6371 tree type
= TREE_TYPE
(decl
);
6374 if
(!INCOMPLETE_TYPE_P
(TREE_TYPE
(type
)))
6377 args
= TYPE_ARG_TYPES
(type
);
6378 if
(TREE_CODE
(type
) == METHOD_TYPE
)
6379 args
= TREE_CHAIN
(args
);
6380 for
(; args
!= end_params_node
; args
= TREE_CHAIN
(args
))
6381 if
(INCOMPLETE_TYPE_P
(TREE_VALUE
(args
)))
6387 /* Visible interface to check methods contained in CLASS_DECL */
6390 java_check_methods
(tree class_decl
)
6392 if
(CLASS_METHOD_CHECKED_P
(TREE_TYPE
(class_decl
)))
6395 if
(CLASS_INTERFACE
(class_decl
))
6396 java_check_abstract_methods
(class_decl
);
6398 java_check_regular_methods
(class_decl
);
6400 CLASS_METHOD_CHECKED_P
(TREE_TYPE
(class_decl
)) = 1;
6403 /* Like not_accessible_p, but doesn't refer to the current class at
6406 hack_is_accessible_p
(tree member
, tree from_where
)
6408 int flags
= get_access_flags_from_decl
(member
);
6410 if
(from_where
== DECL_CONTEXT
(member
)
6411 ||
(flags
& ACC_PUBLIC
))
6414 if
((flags
& ACC_PROTECTED
))
6416 if
(inherits_from_p
(from_where
, DECL_CONTEXT
(member
)))
6420 if
((flags
& ACC_PRIVATE
))
6423 /* Package private, or protected. */
6424 return in_same_package
(TYPE_NAME
(from_where
),
6425 TYPE_NAME
(DECL_CONTEXT
(member
)));
6428 /* Check all the methods of CLASS_DECL. Methods are first completed
6429 then checked according to regular method existence rules. If no
6430 constructor for CLASS_DECL were encountered, then build its
6433 java_check_regular_methods
(tree class_decl
)
6435 int saw_constructor
= ANONYMOUS_CLASS_P
(TREE_TYPE
(class_decl
));
6437 tree class
= TREE_TYPE
(class_decl
);
6438 tree found
= NULL_TREE
;
6441 /* It is not necessary to check methods defined in java.lang.Object */
6442 if
(class
== object_type_node
)
6445 if
(!TYPE_NVIRTUALS
(class
))
6446 TYPE_METHODS
(class
) = nreverse
(TYPE_METHODS
(class
));
6448 /* Should take interfaces into account. FIXME */
6449 for
(method
= TYPE_METHODS
(class
); method
; method
= TREE_CHAIN
(method
))
6452 tree method_wfl
= DECL_FUNCTION_WFL
(method
);
6455 /* Check for redefinitions */
6456 if
(check_method_redefinition
(class
, method
))
6459 /* We verify things thrown by the method. They must inherit from
6460 java.lang.Throwable. */
6461 for
(mthrows
= DECL_FUNCTION_THROWS
(method
);
6462 mthrows
; mthrows
= TREE_CHAIN
(mthrows
))
6464 if
(!inherits_from_p
(TREE_VALUE
(mthrows
), throwable_type_node
))
6466 (TREE_PURPOSE
(mthrows
), "Class %qs in %<throws%> clause must be a subclass of class %<java.lang.Throwable%>",
6468 (DECL_NAME
(TYPE_NAME
(TREE_VALUE
(mthrows
)))));
6471 /* If we see one constructor a mark so we don't generate the
6472 default one. Also skip other verifications: constructors
6473 can't be inherited hence hidden or overridden. */
6474 if
(DECL_CONSTRUCTOR_P
(method
))
6476 saw_constructor
= 1;
6480 sig
= build_java_argument_signature
(TREE_TYPE
(method
));
6481 found
= lookup_argument_method_generic
(class
, DECL_NAME
(method
), sig
,
6482 SEARCH_SUPER | SEARCH_INTERFACE
);
6484 /* Inner class can't declare static methods */
6485 if
(METHOD_STATIC
(method
) && !TOPLEVEL_CLASS_DECL_P
(class_decl
))
6487 char *t
= xstrdup
(lang_printable_name
(class
, 0));
6489 (method_wfl
, "Method %qs can't be static in inner class %qs. Only members of interfaces and top-level classes can be static",
6490 lang_printable_name
(method
, 2), t
);
6494 /* Nothing overrides or it's a private method. */
6497 if
(METHOD_PRIVATE
(found
))
6503 /* If `found' is declared in an interface, make sure the
6504 modifier matches. */
6505 if
(CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(found
)))
6506 && clinit_identifier_node
!= DECL_NAME
(found
)
6507 && !METHOD_PUBLIC
(method
))
6509 tree found_decl
= TYPE_NAME
(DECL_CONTEXT
(found
));
6510 parse_error_context
(method_wfl
, "Class %qs must override %qs with a public method in order to implement interface %qs",
6511 IDENTIFIER_POINTER
(DECL_NAME
(class_decl
)),
6512 lang_printable_name
(method
, 2),
6513 IDENTIFIER_POINTER
(DECL_NAME
(found_decl
)));
6516 /* Can't override a method with the same name and different return
6518 if
(TREE_TYPE
(TREE_TYPE
(found
)) != TREE_TYPE
(TREE_TYPE
(method
)))
6521 (lang_printable_name
(TREE_TYPE
(TREE_TYPE
(found
)), 2));
6524 "Method %qs was defined with return type %qs in class %qs",
6525 lang_printable_name
(found
, 2), t
,
6527 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6531 aflags
= get_access_flags_from_decl
(found
);
6533 /* Can't override final. Can't override static. */
6534 if
(METHOD_FINAL
(found
) || METHOD_STATIC
(found
))
6536 /* Static *can* override static */
6537 if
(METHOD_STATIC
(found
) && METHOD_STATIC
(method
))
6541 "%s methods can't be overridden. Method %qs is %s in class %qs",
6542 (METHOD_FINAL
(found
) ?
"Final" : "Static"),
6543 lang_printable_name
(found
, 2),
6544 (METHOD_FINAL
(found
) ?
"final" : "static"),
6546 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6550 /* Static method can't override instance method. */
6551 if
(METHOD_STATIC
(method
))
6555 "Instance methods can't be overridden by a static method. Method %qs is an instance method in class %qs",
6556 lang_printable_name
(found
, 2),
6558 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6562 /* - Overriding/hiding public must be public
6563 - Overriding/hiding protected must be protected or public
6564 - If the overridden or hidden method has default (package)
6565 access, then the overriding or hiding method must not be
6566 private; otherwise, a compile-time error occurs. If
6567 `found' belongs to an interface, things have been already
6569 if
(!CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(found
)))
6570 && ((METHOD_PUBLIC
(found
) && !METHOD_PUBLIC
(method
))
6571 ||
(METHOD_PROTECTED
(found
)
6572 && !(METHOD_PUBLIC
(method
) || METHOD_PROTECTED
(method
)))
6573 ||
(!(aflags
& (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC
))
6574 && METHOD_PRIVATE
(method
))))
6578 "Methods can't be overridden to be more private. Method %qs is not %s in class %qs", lang_printable_name
(method
, 2),
6579 (METHOD_PUBLIC
(method
) ?
"public" :
6580 (METHOD_PRIVATE
(method
) ?
"private" : "protected")),
6581 IDENTIFIER_POINTER
(DECL_NAME
6582 (TYPE_NAME
(DECL_CONTEXT
(found
)))));
6586 /* Check this method against all the other implementations it
6587 overrides. Here we only check the class hierarchy; the rest
6588 of the checking is done later. If this method is just a
6589 Miranda method, we can skip the check. */
6590 if
(! METHOD_INVISIBLE
(method
))
6591 check_concrete_throws_clauses
(class
, method
, DECL_NAME
(method
), sig
);
6594 /* The above throws clause check only looked at superclasses. Now
6595 we must also make sure that all methods declared in interfaces
6596 have compatible throws clauses. FIXME: there are more efficient
6597 ways to organize this checking; we should implement one. */
6598 check_interface_throws_clauses
(class
, class
);
6600 if
(!TYPE_NVIRTUALS
(class
))
6601 TYPE_METHODS
(class
) = nreverse
(TYPE_METHODS
(class
));
6603 /* Search for inherited abstract method not yet implemented in this
6605 java_check_abstract_method_definitions
(class_decl
);
6607 if
(!saw_constructor
)
6611 /* Check to make sure that all the methods in all the interfaces
6612 implemented by CLASS_DECL are compatible with the concrete
6613 implementations available in CHECK_CLASS_DECL. */
6615 check_interface_throws_clauses
(tree check_class_decl
, tree class_decl
)
6617 for
(; class_decl
!= NULL_TREE
; class_decl
= CLASSTYPE_SUPER
(class_decl
))
6621 if
(! CLASS_LOADED_P
(class_decl
))
6623 if
(CLASS_FROM_SOURCE_P
(class_decl
))
6624 safe_layout_class
(class_decl
);
6626 load_class
(class_decl
, 1);
6629 for
(i
= BINFO_N_BASE_BINFOS
(TYPE_BINFO
(class_decl
)) - 1; i
> 0; --i
)
6632 = BINFO_TYPE
(BINFO_BASE_BINFO
(TYPE_BINFO
(class_decl
), i
));
6635 for
(iface_method
= TYPE_METHODS
(interface
);
6636 iface_method
!= NULL_TREE
;
6637 iface_method
= TREE_CHAIN
(iface_method
))
6641 /* First look for a concrete method implemented or
6642 inherited by this class. No need to search
6643 interfaces here, since we're already looking through
6645 sig
= build_java_argument_signature
(TREE_TYPE
(iface_method
));
6647 = lookup_argument_method_generic
(check_class_decl
,
6648 DECL_NAME
(iface_method
),
6649 sig
, SEARCH_VISIBLE
);
6650 /* If we don't find an implementation, that is ok. Any
6651 potential errors from that are diagnosed elsewhere.
6652 Also, multiple inheritance with conflicting throws
6653 clauses is fine in the absence of a concrete
6655 if
(method
!= NULL_TREE
&& !METHOD_ABSTRACT
(method
)
6656 && !METHOD_INVISIBLE
(iface_method
))
6658 tree method_wfl
= DECL_FUNCTION_WFL
(method
);
6659 check_throws_clauses
(method
, method_wfl
, iface_method
);
6663 /* Now check superinterfaces. */
6664 check_interface_throws_clauses
(check_class_decl
, interface
);
6669 /* Check throws clauses of a method against the clauses of all the
6670 methods it overrides. We do this by searching up the class
6671 hierarchy, examining all matching accessible methods. */
6673 check_concrete_throws_clauses
(tree class
, tree self_method
,
6674 tree name
, tree signature
)
6676 tree method
= lookup_argument_method_generic
(class
, name
, signature
,
6677 SEARCH_SUPER | SEARCH_VISIBLE
);
6678 while
(method
!= NULL_TREE
)
6680 if
(! METHOD_INVISIBLE
(method
) && hack_is_accessible_p
(method
, class
))
6681 check_throws_clauses
(self_method
, DECL_FUNCTION_WFL
(self_method
),
6684 method
= lookup_argument_method_generic
(DECL_CONTEXT
(method
),
6686 SEARCH_SUPER | SEARCH_VISIBLE
);
6690 /* Generate an error if the `throws' clause of METHOD (if any) is
6691 incompatible with the `throws' clause of FOUND (if any). */
6693 check_throws_clauses
(tree method
, tree method_wfl
, tree found
)
6697 for
(mthrows
= DECL_FUNCTION_THROWS
(method
);
6698 mthrows
; mthrows
= TREE_CHAIN
(mthrows
))
6702 /* We don't verify unchecked expressions */
6703 if
(IS_UNCHECKED_EXCEPTION_P
(TREE_VALUE
(mthrows
)))
6705 /* Checked expression must be compatible */
6706 for
(fthrows
= DECL_FUNCTION_THROWS
(found
);
6707 fthrows
; fthrows
= TREE_CHAIN
(fthrows
))
6709 if
(inherits_from_p
(TREE_VALUE
(mthrows
), TREE_VALUE
(fthrows
)))
6715 (method_wfl
, "Invalid checked exception class %qs in %<throws%> clause. The exception must be a subclass of an exception thrown by %qs from class %qs",
6716 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(TREE_VALUE
(mthrows
)))),
6717 lang_printable_name
(found
, 2),
6719 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6724 /* Check abstract method of interface INTERFACE */
6726 java_check_abstract_methods
(tree interface_decl
)
6730 tree interface
= TREE_TYPE
(interface_decl
);
6733 for
(method
= TYPE_METHODS
(interface
); method
; method
= TREE_CHAIN
(method
))
6735 /* 2- Check for double definition inside the defining interface */
6736 if
(check_method_redefinition
(interface
, method
))
6739 /* 3- Overriding is OK as far as we preserve the return type. */
6740 found
= lookup_java_interface_method2
(interface
, method
);
6744 t
= xstrdup
(lang_printable_name
(TREE_TYPE
(TREE_TYPE
(found
)), 2));
6746 (DECL_FUNCTION_WFL
(found
),
6747 "Method %qs was defined with return type %qs in class %qs",
6748 lang_printable_name
(found
, 2), t
,
6750 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6756 /* 4- Inherited methods can't differ by their returned types */
6757 for
(i
= 0; BINFO_BASE_ITERATE
(TYPE_BINFO
(interface
), i
, base_binfo
); i
++)
6759 tree sub_interface_method
, sub_interface
;
6761 sub_interface
= BINFO_TYPE
(base_binfo
);
6762 for
(sub_interface_method
= TYPE_METHODS
(sub_interface
);
6763 sub_interface_method
;
6764 sub_interface_method
= TREE_CHAIN
(sub_interface_method
))
6766 found
= lookup_java_interface_method2
(interface
,
6767 sub_interface_method
);
6768 if
(found
&& (found
!= sub_interface_method
))
6771 (lookup_cl
(sub_interface_method
),
6772 "Interface %qs inherits method %qs from interface %qs. This method is redefined with a different return type in interface %qs",
6773 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(interface
))),
6774 lang_printable_name
(found
, 2),
6776 (DECL_NAME
(TYPE_NAME
6777 (DECL_CONTEXT
(sub_interface_method
)))),
6779 (DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(found
)))));
6785 /* Lookup methods in interfaces using their name and partial
6786 signature. Return a matching method only if their types differ. */
6789 lookup_java_interface_method2
(tree class
, tree method_decl
)
6795 for
(i
= 0; BINFO_BASE_ITERATE
(TYPE_BINFO
(class
), i
, base_binfo
); i
++)
6797 if
((BINFO_TYPE
(base_binfo
) != object_type_node
)
6799 lookup_java_method2
(BINFO_TYPE
(base_binfo
), method_decl
, 1)))
6802 for
(i
= 0; BINFO_BASE_ITERATE
(TYPE_BINFO
(class
), i
, base_binfo
); i
++)
6804 to_return
= lookup_java_interface_method2
6805 (BINFO_TYPE
(base_binfo
), method_decl
);
6813 /* Lookup method using their name and partial signature. Return a
6814 matching method only if their types differ. */
6817 lookup_java_method2
(tree clas
, tree method_decl
, int do_interface
)
6819 tree method
, method_signature
, method_name
, method_type
, name
;
6821 method_signature
= build_java_argument_signature
(TREE_TYPE
(method_decl
));
6822 name
= DECL_NAME
(method_decl
);
6823 method_name
= (TREE_CODE
(name
) == EXPR_WITH_FILE_LOCATION ?
6824 EXPR_WFL_NODE
(name
) : name
);
6825 method_type
= TREE_TYPE
(TREE_TYPE
(method_decl
));
6827 while
(clas
!= NULL_TREE
)
6829 for
(method
= TYPE_METHODS
(clas
);
6830 method
!= NULL_TREE
; method
= TREE_CHAIN
(method
))
6832 tree method_sig
= build_java_argument_signature
(TREE_TYPE
(method
));
6833 tree name
= DECL_NAME
(method
);
6834 if
((TREE_CODE
(name
) == EXPR_WITH_FILE_LOCATION ?
6835 EXPR_WFL_NODE
(name
) : name
) == method_name
6836 && method_sig
== method_signature
6837 && TREE_TYPE
(TREE_TYPE
(method
)) != method_type
)
6840 clas
= (do_interface ? NULL_TREE
: CLASSTYPE_SUPER
(clas
));
6845 /* Return the line that matches DECL line number, and try its best to
6846 position the column number. Used during error reports.
6847 FUTURE/FIXME: return source_location instead of node. */
6849 static GTY
(()) tree cl_v
;
6851 lookup_cl
(tree decl
)
6853 #ifndef USE_MAPPED_LOCATION
6860 if
(cl_v
== NULL_TREE
)
6862 cl_v
= build_unknown_wfl
(NULL_TREE
);
6865 #ifdef USE_MAPPED_LOCATION
6866 SET_EXPR_LOCATION
(cl_v
, DECL_SOURCE_LOCATION
(decl
));
6868 EXPR_WFL_FILENAME_NODE
(cl_v
) = get_identifier
(DECL_SOURCE_FILE
(decl
));
6869 EXPR_WFL_SET_LINECOL
(cl_v
, DECL_SOURCE_LINE
(decl
), -1);
6871 line
= java_get_line_col
(EXPR_WFL_FILENAME
(cl_v
),
6872 EXPR_WFL_LINENO
(cl_v
), EXPR_WFL_COLNO
(cl_v
));
6874 found
= strstr
((const char *)line
,
6875 (const char *)IDENTIFIER_POINTER
(DECL_NAME
(decl
)));
6877 EXPR_WFL_SET_LINECOL
(cl_v
, EXPR_WFL_LINENO
(cl_v
), found
- line
);
6883 /* Look for a simple name in the single-type import list */
6886 find_name_in_single_imports
(tree name
)
6890 for
(node
= ctxp
->import_list
; node
; node
= TREE_CHAIN
(node
))
6891 if
(TREE_VALUE
(node
) == name
)
6892 return
(EXPR_WFL_NODE
(TREE_PURPOSE
(node
)));
6897 /* Process all single-type import. */
6900 process_imports
(void)
6905 for
(import
= ctxp
->import_list
; import
; import
= TREE_CHAIN
(import
))
6907 tree to_be_found
= EXPR_WFL_NODE
(TREE_PURPOSE
(import
));
6908 char *original_name
;
6910 /* Don't load twice something already defined. */
6911 if
(IDENTIFIER_CLASS_VALUE
(to_be_found
))
6914 original_name
= xmemdup
(IDENTIFIER_POINTER
(to_be_found
),
6915 IDENTIFIER_LENGTH
(to_be_found
),
6916 IDENTIFIER_LENGTH
(to_be_found
) + 1);
6922 QUALIFIED_P
(to_be_found
) = 1;
6923 load_class
(to_be_found
, 0);
6925 check_pkg_class_access
(to_be_found
, TREE_PURPOSE
(import
), true
, NULL_TREE
);
6927 /* We found it, we can bail out */
6928 if
(IDENTIFIER_CLASS_VALUE
(to_be_found
))
6930 check_deprecation
(TREE_PURPOSE
(import
),
6931 IDENTIFIER_CLASS_VALUE
(to_be_found
));
6935 /* We haven't found it. Maybe we're trying to access an
6936 inner class. The only way for us to know is to try again
6937 after having dropped a qualifier. If we can't break it further,
6938 we have an error. */
6939 if
(split_qualified_name
(&left
, NULL
, to_be_found
))
6944 if
(!IDENTIFIER_CLASS_VALUE
(to_be_found
))
6946 parse_error_context
(TREE_PURPOSE
(import
),
6947 "Class or interface %qs not found in import",
6952 free
(original_name
);
6959 /* Possibly find and mark a class imported by a single-type import
6963 find_in_imports
(tree enclosing_type
, tree class_type
)
6966 if
(enclosing_type
&& TYPE_IMPORT_LIST
(enclosing_type
))
6967 import
= TYPE_IMPORT_LIST
(enclosing_type
);
6969 import
= ctxp
->import_list
;
6973 if
(TREE_VALUE
(import
) == TYPE_NAME
(class_type
))
6975 TYPE_NAME
(class_type
) = EXPR_WFL_NODE
(TREE_PURPOSE
(import
));
6976 QUALIFIED_P
(TYPE_NAME
(class_type
)) = 1;
6979 import
= TREE_CHAIN
(import
);
6984 note_possible_classname
(const char *name
, int len
)
6987 if
(len
> 5 && strncmp
(&name
[len
-5], ".java", 5) == 0)
6989 else if
(len
> 6 && strncmp
(&name
[len
-6], ".class", 6) == 0)
6993 node
= ident_subst
(name
, len
, "", '/', '.', "");
6994 IS_A_CLASSFILE_NAME
(node
) = 1; /* Or soon to be */
6995 QUALIFIED_P
(node
) = strchr
(name
, '/') ?
1 : 0;
6999 /* Read a import directory, gathering potential match for further type
7000 references. Indifferently reads a filesystem or a ZIP archive
7004 read_import_dir
(tree wfl
)
7006 tree package_id
= EXPR_WFL_NODE
(wfl
);
7007 const char *package_name
= IDENTIFIER_POINTER
(package_id
);
7008 int package_length
= IDENTIFIER_LENGTH
(package_id
);
7010 JCF
*saved_jcf
= current_jcf
;
7015 struct buffer filename
[1];
7017 if
(IS_AN_IMPORT_ON_DEMAND_P
(package_id
))
7019 IS_AN_IMPORT_ON_DEMAND_P
(package_id
) = 1;
7021 BUFFER_INIT
(filename
);
7022 buffer_grow
(filename
, package_length
+ 100);
7024 for
(entry
= jcf_path_start
(); entry
!= NULL
; entry
= jcf_path_next
(entry
))
7026 const char *entry_name
= jcf_path_name
(entry
);
7027 int entry_length
= strlen
(entry_name
);
7028 if
(jcf_path_is_zipfile
(entry
))
7031 buffer_grow
(filename
, entry_length
);
7032 memcpy
(filename
->data
, entry_name
, entry_length
- 1);
7033 filename
->data
[entry_length
-1] = '\0';
7034 zipf
= opendir_in_zip
((const char *) filename
->data
, jcf_path_is_system
(entry
));
7036 error ("malformed .zip archive in CLASSPATH: %s", entry_name
);
7039 ZipDirectory
*zipd
= (ZipDirectory
*) zipf
->central_directory
;
7040 BUFFER_RESET
(filename
);
7041 for
(k
= 0; k
< package_length
; k
++)
7043 char ch
= package_name
[k
];
7044 *filename
->ptr
++ = ch
== '.' ?
'/' : ch
;
7046 *filename
->ptr
++ = '/';
7048 for
(k
= 0; k
< zipf
->count
; k
++, zipd
= ZIPDIR_NEXT
(zipd
))
7050 const char *current_entry
= ZIPDIR_FILENAME
(zipd
);
7051 int current_entry_len
= zipd
->filename_length
;
7053 if
(current_entry_len
>= BUFFER_LENGTH
(filename
)
7054 && strncmp
((const char *) filename
->data
, current_entry
,
7055 BUFFER_LENGTH
(filename
)) != 0)
7057 found |
= note_possible_classname
(current_entry
,
7064 BUFFER_RESET
(filename
);
7065 buffer_grow
(filename
, entry_length
+ package_length
+ 4);
7066 strcpy
((char *) filename
->data
, entry_name
);
7067 filename
->ptr
= filename
->data
+ entry_length
;
7068 for
(k
= 0; k
< package_length
; k
++)
7070 char ch
= package_name
[k
];
7071 *filename
->ptr
++ = ch
== '.' ?
'/' : ch
;
7073 *filename
->ptr
= '\0';
7075 dirp
= opendir
((const char *) filename
->data
);
7078 *filename
->ptr
++ = '/';
7083 struct dirent
*direntp
= readdir
(dirp
);
7086 d_name
= direntp
->d_name
;
7087 len
= strlen
(direntp
->d_name
);
7088 buffer_grow
(filename
, len
+1);
7089 strcpy
((char *) filename
->ptr
, d_name
);
7090 found |
= note_possible_classname
((const char *) filename
->data
+ entry_length
,
7091 package_length
+len
+1);
7098 free
(filename
->data
);
7100 /* Here we should have a unified way of retrieving an entry, to be
7104 static int first
= 1;
7107 error ("Can't find default package %qs. Check the CLASSPATH environment variable and the access to the archives", package_name
);
7112 parse_error_context
(wfl
, "Package %qs not found in import",
7114 current_jcf
= saved_jcf
;
7117 current_jcf
= saved_jcf
;
7120 /* Possibly find a type in the import on demands specified
7121 types. Returns 1 if an error occurred, 0 otherwise. Run through the
7122 entire list, to detected potential double definitions. */
7125 find_in_imports_on_demand
(tree enclosing_type
, tree class_type
)
7127 tree class_type_name
= TYPE_NAME
(class_type
);
7128 tree cl
= NULL_TREE
;
7129 int seen_once
= -1; /* -1 when not set, 1 if seen once, >1 otherwise. */
7130 int to_return
= -1; /* -1 when not set, 0 or 1 otherwise */
7134 if
(enclosing_type
&& TYPE_IMPORT_DEMAND_LIST
(enclosing_type
))
7135 import
= TYPE_IMPORT_DEMAND_LIST
(enclosing_type
);
7137 import
= ctxp
->import_demand_list
;
7139 for
(; import
; import
= TREE_CHAIN
(import
))
7141 location_t saved_location
= input_location
;
7143 const char *id_name
;
7144 tree decl
, type_name_copy
;
7146 obstack_grow
(&temporary_obstack
,
7147 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(TREE_PURPOSE
(import
))),
7148 IDENTIFIER_LENGTH
(EXPR_WFL_NODE
(TREE_PURPOSE
(import
))));
7149 obstack_1grow
(&temporary_obstack
, '.');
7150 obstack_grow0
(&temporary_obstack
,
7151 IDENTIFIER_POINTER
(class_type_name
),
7152 IDENTIFIER_LENGTH
(class_type_name
));
7153 id_name
= obstack_finish
(&temporary_obstack
);
7155 if
(! (node
= maybe_get_identifier
(id_name
)))
7158 /* Setup input_line so that it refers to the line of the import (in
7159 case we parse a class file and encounter errors */
7160 #ifdef USE_MAPPED_LOCATION
7161 input_location
= EXPR_LOCATION
(TREE_PURPOSE
(import
));
7163 input_line
= EXPR_WFL_LINENO
(TREE_PURPOSE
(import
));
7166 type_name_copy
= TYPE_NAME
(class_type
);
7167 TYPE_NAME
(class_type
) = node
;
7168 QUALIFIED_P
(node
) = 1;
7169 decl
= IDENTIFIER_CLASS_VALUE
(node
);
7171 /* If there is no DECL set for the class or if the class isn't
7172 loaded and not seen in source yet, then load */
7173 if
(!decl ||
! CLASS_LOADED_P
(TREE_TYPE
(decl
)))
7175 load_class
(node
, 0);
7176 decl
= IDENTIFIER_CLASS_VALUE
(node
);
7178 if
(decl
&& ! INNER_CLASS_P
(TREE_TYPE
(decl
)))
7179 access_check
= check_pkg_class_access
(node
, TREE_PURPOSE
(import
),
7182 /* 6.6.1: Inner classes are subject to member access rules. */
7185 input_location
= saved_location
;
7187 /* If the loaded class is not accessible or couldn't be loaded,
7188 we restore the original TYPE_NAME and process the next
7190 if
(access_check ||
!decl
)
7192 TYPE_NAME
(class_type
) = type_name_copy
;
7196 /* If the loaded class is accessible, we keep a tab on it to
7197 detect and report multiple inclusions. */
7198 if
(IS_A_CLASSFILE_NAME
(node
))
7202 cl
= TREE_PURPOSE
(import
);
7205 else if
(seen_once
>= 0)
7207 tree location
= (cl ? cl
: TREE_PURPOSE
(import
));
7208 tree package
= (cl ? EXPR_WFL_NODE
(cl
) :
7209 EXPR_WFL_NODE
(TREE_PURPOSE
(import
)));
7213 "Type %qs also potentially defined in package %qs",
7214 IDENTIFIER_POINTER
(TYPE_NAME
(class_type
)),
7215 IDENTIFIER_POINTER
(package
));
7218 to_return
= access_check
;
7224 return
(seen_once
< 0 ?
0 : seen_once
); /* It's ok not to have found */
7228 resolve_package
(tree pkg
, tree
*next
, tree
*type_name
)
7231 tree decl
= NULL_TREE
;
7232 *type_name
= NULL_TREE
;
7234 /* The trick is to determine when the package name stops and were
7235 the name of something contained in the package starts. Then we
7236 return a fully qualified name of what we want to get. */
7238 *next
= EXPR_WFL_QUALIFICATION
(pkg
);
7240 /* Try to progressively construct a type name */
7241 if
(TREE_CODE
(pkg
) == EXPR_WITH_FILE_LOCATION
)
7242 for
(current
= EXPR_WFL_QUALIFICATION
(pkg
);
7243 current
; current
= TREE_CHAIN
(current
))
7245 /* If we don't have what we're expecting, exit now. TYPE_NAME
7246 will be null and the error caught later. */
7247 if
(TREE_CODE
(QUAL_WFL
(current
)) != EXPR_WITH_FILE_LOCATION
)
7250 merge_qualified_name
(*type_name
, EXPR_WFL_NODE
(QUAL_WFL
(current
)));
7251 if
((decl
= resolve_no_layout
(*type_name
, NULL_TREE
)))
7253 /* resolve_package should be used in a loop, hence we
7254 point at this one to naturally process the next one at
7255 the next iteration. */
7264 /* Check accessibility of inner classes according to member access rules.
7265 DECL is the inner class, ENCLOSING_DECL is the class from which the
7266 access is being attempted. */
7269 check_inner_class_access
(tree decl
, tree enclosing_decl
, tree cl
)
7272 tree enclosing_decl_type
;
7274 /* We don't issue an error message when CL is null. CL can be null
7275 as a result of processing a JDEP crafted by source_start_java_method
7276 for the purpose of patching its parm decl. But the error would
7277 have been already trapped when fixing the method's signature.
7278 DECL can also be NULL in case of earlier errors. */
7282 enclosing_decl_type
= TREE_TYPE
(enclosing_decl
);
7284 if
(CLASS_PRIVATE
(decl
))
7286 /* Access is permitted only within the body of the top-level
7287 class in which DECL is declared. */
7288 tree top_level
= decl
;
7289 while
(DECL_CONTEXT
(top_level
))
7290 top_level
= DECL_CONTEXT
(top_level
);
7291 while
(DECL_CONTEXT
(enclosing_decl
))
7292 enclosing_decl
= DECL_CONTEXT
(enclosing_decl
);
7293 if
(top_level
== enclosing_decl
)
7297 else if
(CLASS_PROTECTED
(decl
))
7300 /* Access is permitted from within the same package... */
7301 if
(in_same_package
(decl
, enclosing_decl
))
7304 /* ... or from within the body of a subtype of the context in which
7305 DECL is declared. */
7306 decl_context
= DECL_CONTEXT
(decl
);
7307 while
(enclosing_decl
)
7309 if
(CLASS_INTERFACE
(decl
))
7311 if
(interface_of_p
(TREE_TYPE
(decl_context
),
7312 enclosing_decl_type
))
7317 /* Eww. The order of the arguments is different!! */
7318 if
(inherits_from_p
(enclosing_decl_type
,
7319 TREE_TYPE
(decl_context
)))
7322 enclosing_decl
= DECL_CONTEXT
(enclosing_decl
);
7324 access
= "protected";
7326 else if
(! CLASS_PUBLIC
(decl
))
7328 /* Access is permitted only from within the same package as DECL. */
7329 if
(in_same_package
(decl
, enclosing_decl
))
7331 access
= "non-public";
7334 /* Class is public. */
7337 parse_error_context
(cl
, "Nested %s %s is %s; cannot be accessed from here",
7338 (CLASS_INTERFACE
(decl
) ?
"interface" : "class"),
7339 lang_printable_name
(decl
, 2), access
);
7342 /* Accessibility check for top-level classes. If CLASS_NAME is in a
7343 foreign package, it must be PUBLIC. Return 0 if no access
7344 violations were found, 1 otherwise. If VERBOSE is true and an error
7345 was found, it is reported and accounted for. If CL is NULL then
7346 look it up with THIS_DECL. */
7349 check_pkg_class_access
(tree class_name
, tree cl
, bool verbose
, tree this_decl
)
7353 if
(!IDENTIFIER_CLASS_VALUE
(class_name
))
7356 if
(!(type
= TREE_TYPE
(IDENTIFIER_CLASS_VALUE
(class_name
))))
7359 if
(!CLASS_PUBLIC
(TYPE_NAME
(type
)))
7361 /* Access to a private class within the same package is
7364 split_qualified_name
(&l
, &r
, class_name
);
7365 if
(!QUALIFIED_P
(class_name
) && !ctxp
->package
)
7366 /* Both in the empty package. */
7368 if
(l
== ctxp
->package
)
7369 /* Both in the same package. */
7374 (cl
== NULL ? lookup_cl
(this_decl
): cl
,
7375 "Can't access %s %qs. Only public classes and interfaces in other packages can be accessed",
7376 (CLASS_INTERFACE
(TYPE_NAME
(type
)) ?
"interface" : "class"),
7377 IDENTIFIER_POINTER
(class_name
));
7383 /* Local variable declaration. */
7386 declare_local_variables
(int modifier
, tree type
, tree vlist
)
7388 tree decl
, current
, saved_type
;
7389 tree type_wfl
= NULL_TREE
;
7393 /* Push a new block if statements were seen between the last time we
7394 pushed a block and now. Keep a count of blocks to close */
7395 if
(BLOCK_EXPR_BODY
(GET_CURRENT_BLOCK
(current_function_decl
)))
7397 tree b
= enter_block
();
7398 BLOCK_IS_IMPLICIT
(b
) = 1;
7404 for
(i
= 0; i
< ARRAY_SIZE
(ctxp
->modifier_ctx
); i
++)
7405 if
(1 << i
& modifier
)
7407 if
(modifier
== ACC_FINAL
)
7412 (ctxp
->modifier_ctx
[i
],
7413 "Only %<final%> is allowed as a local variables modifier");
7418 /* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
7419 hold the TYPE value if a new incomplete has to be created (as
7420 opposed to being found already existing and reused). */
7421 SET_TYPE_FOR_RESOLUTION
(type
, type_wfl
, must_chain
);
7423 /* If TYPE is fully resolved and we don't have a reference, make one */
7424 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
7426 /* Go through all the declared variables */
7427 for
(current
= vlist
, saved_type
= type
; current
;
7428 current
= TREE_CHAIN
(current
), type
= saved_type
)
7430 tree other
, real_type
;
7431 tree wfl
= TREE_PURPOSE
(current
);
7432 tree name
= EXPR_WFL_NODE
(wfl
);
7433 tree init
= TREE_VALUE
(current
);
7435 /* Process NAME, as it may specify extra dimension(s) for it */
7436 type
= build_array_from_name
(type
, type_wfl
, name
, &name
);
7438 /* Variable redefinition check */
7439 if
((other
= lookup_name_in_blocks
(name
)))
7441 variable_redefinition_error
(wfl
, name
, TREE_TYPE
(other
),
7442 DECL_SOURCE_LINE
(other
));
7446 /* Type adjustment. We may have just readjusted TYPE because
7447 the variable specified more dimensions. Make sure we have
7448 a reference if we can and don't have one already. */
7449 PROMOTE_RECORD_IF_COMPLETE
(type
, must_chain
);
7451 real_type
= GET_REAL_TYPE
(type
);
7452 /* Never layout this decl. This will be done when its scope
7454 decl
= build_decl
(VAR_DECL
, name
, real_type
);
7455 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(decl
);
7456 DECL_FINAL
(decl
) = final_p
;
7457 BLOCK_CHAIN_DECL
(decl
);
7459 /* Don't try to use an INIT statement when an error was found */
7460 if
(init
&& java_error_count
)
7463 /* Remember it if this is an initialized-upon-declaration final
7465 if
(init
&& final_p
)
7467 DECL_LOCAL_FINAL_IUD
(decl
) = 1;
7470 /* Add the initialization function to the current function's code */
7473 /* Name might have been readjusted */
7474 EXPR_WFL_NODE
(TREE_OPERAND
(init
, 0)) = name
;
7475 MODIFY_EXPR_FROM_INITIALIZATION_P
(init
) = 1;
7476 java_method_add_stmt
(current_function_decl
,
7477 build_debugable_stmt
(EXPR_WFL_LINECOL
(init
),
7481 /* Setup dependency the type of the decl */
7485 register_incomplete_type
(JDEP_VARIABLE
, type_wfl
, decl
, type
);
7486 dep
= CLASSD_LAST
(ctxp
->classd_list
);
7487 JDEP_GET_PATCH
(dep
) = &TREE_TYPE
(decl
);
7490 SOURCE_FRONTEND_DEBUG
(("Defined locals"));
7493 /* Called during parsing. Build decls from argument list. */
7496 source_start_java_method
(tree fndecl
)
7505 current_function_decl
= fndecl
;
7507 /* New scope for the function */
7509 for
(tem
= TYPE_ARG_TYPES
(TREE_TYPE
(fndecl
)), i
= 0;
7510 tem
!= end_params_node
; tem
= TREE_CHAIN
(tem
), i
++)
7512 tree type
= TREE_VALUE
(tem
);
7513 tree name
= TREE_PURPOSE
(tem
);
7515 /* If type is incomplete. Create an incomplete decl and ask for
7516 the decl to be patched later */
7517 if
(INCOMPLETE_TYPE_P
(type
))
7520 tree real_type
= GET_REAL_TYPE
(type
);
7521 parm_decl
= build_decl
(PARM_DECL
, name
, real_type
);
7522 type
= obtain_incomplete_type
(type
);
7523 register_incomplete_type
(JDEP_PARM
, NULL_TREE
, NULL_TREE
, type
);
7524 jdep
= CLASSD_LAST
(ctxp
->classd_list
);
7525 JDEP_MISC
(jdep
) = name
;
7526 JDEP_GET_PATCH
(jdep
) = &TREE_TYPE
(parm_decl
);
7529 parm_decl
= build_decl
(PARM_DECL
, name
, type
);
7531 /* Remember if a local variable was declared final (via its
7532 TREE_LIST of type/name.) Set DECL_FINAL accordingly. */
7533 if
(ARG_FINAL_P
(tem
))
7535 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(parm_decl
);
7536 DECL_FINAL
(parm_decl
) = 1;
7539 BLOCK_CHAIN_DECL
(parm_decl
);
7541 tem
= BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(current_function_decl
));
7542 BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(current_function_decl
)) =
7544 DECL_ARG_SLOT_COUNT
(current_function_decl
) = i
;
7545 DECL_MAX_LOCALS
(current_function_decl
) = i
;
7548 /* Called during parsing. Creates an artificial method declaration. */
7551 create_artificial_method
(tree class
, int flags
, tree type
,
7552 tree name
, tree args
)
7555 location_t save_location
= input_location
;
7557 input_location
= DECL_SOURCE_LOCATION
(TYPE_NAME
(class
));
7558 mdecl
= make_node
(FUNCTION_TYPE
);
7559 TREE_TYPE
(mdecl
) = type
;
7560 TYPE_ARG_TYPES
(mdecl
) = args
;
7561 /* We used to compute the signature of MDECL here and then use
7562 add_method(), but that failed because our caller might modify
7563 the type of the returned method, which trashes the cache in
7564 get_type_from_signature(). */
7565 mdecl
= add_method_1
(class
, flags
, name
, mdecl
);
7566 input_location
= save_location
;
7567 DECL_ARTIFICIAL
(mdecl
) = 1;
7571 /* Starts the body if an artificial method. */
7574 start_artificial_method_body
(tree mdecl
)
7576 #ifdef USE_MAPPED_LOCATION
7577 DECL_SOURCE_LOCATION
(mdecl
) = ctxp
->file_start_location
;
7578 DECL_FUNCTION_LAST_LINE
(mdecl
) = ctxp
->file_start_location
;
7580 DECL_SOURCE_LINE
(mdecl
) = 1;
7581 DECL_FUNCTION_LAST_LINE
(mdecl
) = 1;
7583 source_start_java_method
(mdecl
);
7588 end_artificial_method_body
(tree mdecl
)
7590 /* exit_block modifies DECL_FUNCTION_BODY (current_function_decl).
7591 It has to be evaluated first. (if mdecl is current_function_decl,
7592 we have an undefined behavior if no temporary variable is used.) */
7593 tree b
= exit_block
();
7594 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(mdecl
)) = b
;
7598 /* Dump a tree of some kind. This is a convenience wrapper for the
7599 dump_* functions in tree-dump.c. */
7601 dump_java_tree
(enum tree_dump_index phase
, tree t
)
7606 stream
= dump_begin
(phase
, &flags
);
7610 dump_node
(t
, flags
, stream
);
7611 dump_end
(phase
, stream
);
7615 /* Terminate a function and expand its body. */
7618 source_end_java_method
(void)
7620 tree fndecl
= current_function_decl
;
7625 java_parser_context_save_global
();
7626 #ifdef USE_MAPPED_LOCATION
7627 input_location
= ctxp
->last_ccb_indent1
;
7629 input_line
= ctxp
->last_ccb_indent1
;
7632 /* Turn function bodies with only a NOP expr null, so they don't get
7633 generated at all and we won't get warnings when using the -W
7635 if
(IS_EMPTY_STMT
(BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
))))
7636 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
)) = NULL_TREE
;
7638 if
(BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(fndecl
))
7639 && ! flag_emit_class_files
)
7640 finish_method
(fndecl
);
7642 current_function_decl
= NULL_TREE
;
7643 java_parser_context_restore_global
();
7644 current_function_decl
= NULL_TREE
;
7647 /* Record EXPR in the current function block. Complements compound
7648 expression second operand if necessary. */
7651 java_method_add_stmt
(tree fndecl
, tree expr
)
7653 if
(!GET_CURRENT_BLOCK
(fndecl
))
7655 return add_stmt_to_block
(GET_CURRENT_BLOCK
(fndecl
), NULL_TREE
, expr
);
7659 add_stmt_to_block
(tree b
, tree type
, tree stmt
)
7661 tree body
= BLOCK_EXPR_BODY
(b
), c
;
7663 if
(java_error_count
)
7666 if
((c
= add_stmt_to_compound
(body
, type
, stmt
)) == body
)
7669 BLOCK_EXPR_BODY
(b
) = c
;
7670 TREE_SIDE_EFFECTS
(c
) = 1;
7674 /* Lays out the methods for the classes seen so far. */
7677 java_layout_seen_class_methods
(void)
7679 tree previous_list
= all_class_list
;
7680 tree end
= NULL_TREE
;
7685 for
(current
= previous_list
;
7686 current
!= end
; current
= TREE_CHAIN
(current
))
7688 tree decl
= TREE_VALUE
(current
);
7689 tree cls
= TREE_TYPE
(decl
);
7691 input_location
= DECL_SOURCE_LOCATION
(decl
);
7693 if
(! CLASS_LOADED_P
(cls
))
7694 load_class
(cls
, 0);
7696 layout_class_methods
(cls
);
7699 /* Note that new classes might have been added while laying out
7700 methods, changing the value of all_class_list. */
7702 if
(previous_list
!= all_class_list
)
7704 end
= previous_list
;
7705 previous_list
= all_class_list
;
7712 static GTY
(()) tree stop_reordering
;
7714 java_reorder_fields
(void)
7718 for
(current
= gclass_list
; current
; current
= TREE_CHAIN
(current
))
7720 output_class
= current_class
= TREE_TYPE
(TREE_VALUE
(current
));
7722 if
(current_class
== stop_reordering
)
7725 /* Reverse the fields, but leave the dummy field in front.
7726 Fields are already ordered for Object and Class */
7727 if
(TYPE_FIELDS
(current_class
) && current_class
!= object_type_node
7728 && current_class
!= class_type_node
)
7730 /* If the dummy field is there, reverse the right fields and
7731 just layout the type for proper fields offset */
7732 if
(!DECL_NAME
(TYPE_FIELDS
(current_class
)))
7734 tree fields
= TYPE_FIELDS
(current_class
);
7735 TREE_CHAIN
(fields
) = nreverse
(TREE_CHAIN
(fields
));
7736 TYPE_SIZE
(current_class
) = NULL_TREE
;
7738 /* We don't have a dummy field, we need to layout the class,
7739 after having reversed the fields */
7742 TYPE_FIELDS
(current_class
) =
7743 nreverse
(TYPE_FIELDS
(current_class
));
7744 TYPE_SIZE
(current_class
) = NULL_TREE
;
7748 /* There are cases were gclass_list will be empty. */
7750 stop_reordering
= TREE_TYPE
(TREE_VALUE
(gclass_list
));
7753 /* Layout the methods of all classes loaded in one way or another.
7754 Check methods of source parsed classes. Then reorder the
7755 fields and layout the classes or the type of all source parsed
7759 java_layout_classes
(void)
7762 int save_error_count
= java_error_count
;
7764 /* Layout the methods of all classes seen so far */
7765 java_layout_seen_class_methods
();
7766 java_parse_abort_on_error
();
7767 all_class_list
= NULL_TREE
;
7769 /* Then check the methods of all parsed classes */
7770 for
(current
= gclass_list
; current
; current
= TREE_CHAIN
(current
))
7771 if
(CLASS_FROM_SOURCE_P
(TREE_TYPE
(TREE_VALUE
(current
))))
7772 java_check_methods
(TREE_VALUE
(current
));
7773 java_parse_abort_on_error
();
7775 for
(current
= gclass_list
; current
; current
= TREE_CHAIN
(current
))
7777 output_class
= current_class
= TREE_TYPE
(TREE_VALUE
(current
));
7778 layout_class
(current_class
);
7780 /* Error reported by the caller */
7781 if
(java_error_count
)
7785 /* We might have reloaded classes durign the process of laying out
7786 classes for code generation. We must layout the methods of those
7787 late additions, as constructor checks might use them */
7788 java_layout_seen_class_methods
();
7789 java_parse_abort_on_error
();
7792 /* Expand methods in the current set of classes remembered for
7796 java_complete_expand_classes
(void)
7800 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
7801 if
(!INNER_CLASS_DECL_P
(current
))
7802 java_complete_expand_class
(current
);
7805 /* Expand the methods found in OUTER, starting first by OUTER's inner
7809 java_complete_expand_class
(tree outer
)
7813 /* We need to go after all inner classes and start expanding them,
7814 starting with most nested ones. We have to do that because nested
7815 classes might add functions to outer classes */
7817 for
(inner_list
= DECL_INNER_CLASS_LIST
(outer
);
7818 inner_list
; inner_list
= TREE_CHAIN
(inner_list
))
7819 java_complete_expand_class
(TREE_PURPOSE
(inner_list
));
7821 java_complete_expand_methods
(outer
);
7824 /* Expand methods registered in CLASS_DECL. The general idea is that
7825 we expand regular methods first. This allows us get an estimate on
7826 how outer context local alias fields are really used so we can add
7827 to the constructor just enough code to initialize them properly (it
7828 also lets us generate finit$ correctly.) Then we expand the
7829 constructors and then <clinit>. */
7832 java_complete_expand_methods
(tree class_decl
)
7834 tree clinit
, decl
, first_decl
;
7836 output_class
= current_class
= TREE_TYPE
(class_decl
);
7838 /* Pre-expand <clinit> to figure whether we really need it or
7839 not. If we do need it, we pre-expand the static fields so they're
7840 ready to be used somewhere else. <clinit> will be fully expanded
7841 after we processed the constructors. */
7842 first_decl
= TYPE_METHODS
(current_class
);
7843 clinit
= maybe_generate_pre_expand_clinit
(current_class
);
7845 /* Then generate finit$ (if we need to) because constructors will
7847 if
(TYPE_FINIT_STMT_LIST
(current_class
))
7848 java_complete_expand_method
(generate_finit
(current_class
));
7850 /* Then generate instinit$ (if we need to) because constructors will
7852 if
(TYPE_II_STMT_LIST
(current_class
))
7853 java_complete_expand_method
(generate_instinit
(current_class
));
7855 /* Now do the constructors */
7856 for
(decl
= first_decl
; !java_error_count
&& decl
; decl
= TREE_CHAIN
(decl
))
7858 if
(!DECL_CONSTRUCTOR_P
(decl
))
7860 java_complete_expand_method
(decl
);
7863 /* First, do the ordinary methods. */
7864 for
(decl
= first_decl
; decl
; decl
= TREE_CHAIN
(decl
))
7866 /* Ctors aren't part of this batch. */
7867 if
(DECL_CONSTRUCTOR_P
(decl
) || DECL_CLINIT_P
(decl
))
7870 /* Skip abstract or native methods -- but do handle native
7871 methods when generating JNI stubs. */
7872 if
(METHOD_ABSTRACT
(decl
) ||
(! flag_jni
&& METHOD_NATIVE
(decl
)))
7874 DECL_FUNCTION_BODY
(decl
) = NULL_TREE
;
7878 if
(METHOD_NATIVE
(decl
))
7881 current_function_decl
= decl
;
7882 body
= build_jni_stub
(decl
);
7883 BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(decl
)) = body
;
7886 java_complete_expand_method
(decl
);
7889 /* If there is indeed a <clinit>, fully expand it now */
7892 /* Prevent the use of `this' inside <clinit> */
7893 ctxp
->explicit_constructor_p
= 1;
7894 java_complete_expand_method
(clinit
);
7895 ctxp
->explicit_constructor_p
= 0;
7898 /* We might have generated a class$ that we now want to expand */
7899 if
(TYPE_DOT_CLASS
(current_class
))
7900 java_complete_expand_method
(TYPE_DOT_CLASS
(current_class
));
7902 /* Now verify constructor circularity (stop after the first one we
7904 if
(!CLASS_INTERFACE
(class_decl
))
7905 for
(decl
= TYPE_METHODS
(current_class
); decl
; decl
= TREE_CHAIN
(decl
))
7906 if
(DECL_CONSTRUCTOR_P
(decl
)
7907 && verify_constructor_circularity
(decl
, decl
))
7911 /* Attempt to create <clinit>. Pre-expand static fields so they can be
7912 safely used in some other methods/constructors. */
7915 maybe_generate_pre_expand_clinit
(tree class_type
)
7917 tree current
, mdecl
;
7919 if
(!TYPE_CLINIT_STMT_LIST
(class_type
))
7922 /* Go through all static fields and pre expand them */
7923 for
(current
= TYPE_FIELDS
(class_type
); current
;
7924 current
= TREE_CHAIN
(current
))
7925 if
(FIELD_STATIC
(current
))
7926 build_field_ref
(NULL_TREE
, class_type
, DECL_NAME
(current
));
7928 /* Then build the <clinit> method */
7929 mdecl
= create_artificial_method
(class_type
, ACC_STATIC
, void_type_node
,
7930 clinit_identifier_node
, end_params_node
);
7931 layout_class_method
(class_type
, CLASSTYPE_SUPER
(class_type
),
7933 start_artificial_method_body
(mdecl
);
7935 /* We process the list of assignment we produced as the result of
7936 the declaration of initialized static field and add them as
7937 statement to the <clinit> method. */
7938 for
(current
= TYPE_CLINIT_STMT_LIST
(class_type
); current
;
7939 current
= TREE_CHAIN
(current
))
7941 tree stmt
= current
;
7942 /* We build the assignment expression that will initialize the
7943 field to its value. There are strict rules on static
7944 initializers (8.5). FIXME */
7945 if
(TREE_CODE
(stmt
) != BLOCK
&& !IS_EMPTY_STMT
(stmt
))
7946 stmt
= build_debugable_stmt
(EXPR_WFL_LINECOL
(stmt
), stmt
);
7947 java_method_add_stmt
(mdecl
, stmt
);
7950 end_artificial_method_body
(mdecl
);
7952 /* Now we want to place <clinit> as the last method (because we need
7953 it at least for interface so that it doesn't interfere with the
7954 dispatch table based lookup. */
7955 if
(TREE_CHAIN
(TYPE_METHODS
(class_type
)))
7957 current
= TREE_CHAIN
(TYPE_METHODS
(class_type
));
7958 TYPE_METHODS
(class_type
) = current
;
7960 while
(TREE_CHAIN
(current
))
7961 current
= TREE_CHAIN
(current
);
7963 TREE_CHAIN
(current
) = mdecl
;
7964 TREE_CHAIN
(mdecl
) = NULL_TREE
;
7970 /* Analyzes a method body and look for something that isn't a
7971 MODIFY_EXPR with a constant value. */
7974 analyze_clinit_body
(tree this_class
, tree bbody
)
7977 switch
(TREE_CODE
(bbody
))
7980 bbody
= BLOCK_EXPR_BODY
(bbody
);
7983 case EXPR_WITH_FILE_LOCATION
:
7984 bbody
= EXPR_WFL_NODE
(bbody
);
7988 if
(analyze_clinit_body
(this_class
, TREE_OPERAND
(bbody
, 0)))
7990 bbody
= TREE_OPERAND
(bbody
, 1);
7994 /* If we're generating to class file and we're dealing with an
7995 array initialization, we return 1 to keep <clinit> */
7996 if
(TREE_CODE
(TREE_OPERAND
(bbody
, 1)) == NEW_ARRAY_INIT
7997 && flag_emit_class_files
)
8000 /* There are a few cases where we're required to keep
8002 - If this is an assignment whose operand is not constant,
8003 - If this is an assignment to a non-initialized field,
8004 - If this field is not a member of the current class.
8006 return
(! TREE_CONSTANT
(TREE_OPERAND
(bbody
, 1))
8007 ||
! DECL_INITIAL
(TREE_OPERAND
(bbody
, 0))
8008 || DECL_CONTEXT
(TREE_OPERAND
(bbody
, 0)) != this_class
);
8017 /* See whether we could get rid of <clinit>. Criteria are: all static
8018 final fields have constant initial values and the body of <clinit>
8019 is empty. Return 1 if <clinit> was discarded, 0 otherwise. */
8022 maybe_yank_clinit
(tree mdecl
)
8027 if
(!DECL_CLINIT_P
(mdecl
))
8030 /* If the body isn't empty, then we keep <clinit>. Note that if
8031 we're emitting classfiles, this isn't enough not to rule it
8033 fbody
= DECL_FUNCTION_BODY
(mdecl
);
8034 bbody
= BLOCK_EXPR_BODY
(fbody
);
8035 if
(bbody
&& bbody
!= error_mark_node
)
8036 bbody
= BLOCK_EXPR_BODY
(bbody
);
8039 if
(bbody
&& ! flag_emit_class_files
&& !IS_EMPTY_STMT
(bbody
))
8042 type
= DECL_CONTEXT
(mdecl
);
8043 current
= TYPE_FIELDS
(type
);
8045 for
(current
= (current ? TREE_CHAIN
(current
) : current
);
8046 current
; current
= TREE_CHAIN
(current
))
8050 /* We're not interested in non-static fields. */
8051 if
(!FIELD_STATIC
(current
))
8054 /* Nor in fields without initializers. */
8055 f_init
= DECL_INITIAL
(current
);
8056 if
(f_init
== NULL_TREE
)
8059 /* Anything that isn't String or a basic type is ruled out -- or
8060 if we know how to deal with it (when doing things natively) we
8061 should generated an empty <clinit> so that SUID are computed
8063 if
(! JSTRING_TYPE_P
(TREE_TYPE
(current
))
8064 && ! JNUMERIC_TYPE_P
(TREE_TYPE
(current
)))
8067 if
(! FIELD_FINAL
(current
) ||
! TREE_CONSTANT
(f_init
))
8071 /* Now we analyze the method body and look for something that
8072 isn't a MODIFY_EXPR */
8073 if
(bbody
&& !IS_EMPTY_STMT
(bbody
) && analyze_clinit_body
(type
, bbody
))
8076 /* Get rid of <clinit> in the class' list of methods */
8077 if
(TYPE_METHODS
(type
) == mdecl
)
8078 TYPE_METHODS
(type
) = TREE_CHAIN
(mdecl
);
8080 for
(current
= TYPE_METHODS
(type
); current
;
8081 current
= TREE_CHAIN
(current
))
8082 if
(TREE_CHAIN
(current
) == mdecl
)
8084 TREE_CHAIN
(current
) = TREE_CHAIN
(mdecl
);
8091 /* Install the argument from MDECL. Suitable to completion and
8092 expansion of mdecl's body. */
8095 start_complete_expand_method
(tree mdecl
)
8099 pushlevel
(1); /* Prepare for a parameter push */
8100 tem
= BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(current_function_decl
));
8101 DECL_ARGUMENTS
(mdecl
) = tem
;
8103 for
(; tem
; tem
= TREE_CHAIN
(tem
))
8105 /* TREE_CHAIN (tem) will change after pushdecl. */
8106 tree next
= TREE_CHAIN
(tem
);
8107 tree type
= TREE_TYPE
(tem
);
8108 if
(targetm.calls.promote_prototypes
(type
)
8109 && TYPE_PRECISION
(type
) < TYPE_PRECISION
(integer_type_node
)
8110 && INTEGRAL_TYPE_P
(type
))
8111 type
= integer_type_node
;
8112 DECL_ARG_TYPE
(tem
) = type
;
8113 layout_decl
(tem
, 0);
8115 /* Re-install the next so that the list is kept and the loop
8117 TREE_CHAIN
(tem
) = next
;
8119 pushdecl_force_head
(DECL_ARGUMENTS
(mdecl
));
8120 input_location
= DECL_SOURCE_LOCATION
(mdecl
);
8121 build_result_decl
(mdecl
);
8125 /* Complete and expand a method. */
8128 java_complete_expand_method
(tree mdecl
)
8130 tree fbody
, block_body
, exception_copy
;
8132 current_function_decl
= mdecl
;
8133 /* Fix constructors before expanding them */
8134 if
(DECL_CONSTRUCTOR_P
(mdecl
))
8135 fix_constructors
(mdecl
);
8137 /* Expand functions that have a body */
8138 if
(!DECL_FUNCTION_BODY
(mdecl
))
8141 fbody
= DECL_FUNCTION_BODY
(mdecl
);
8142 block_body
= BLOCK_EXPR_BODY
(fbody
);
8143 exception_copy
= NULL_TREE
;
8145 current_function_decl
= mdecl
;
8148 fprintf
(stderr
, " [%s.",
8149 lang_printable_name
(DECL_CONTEXT
(mdecl
), 0));
8150 announce_function
(mdecl
);
8152 fprintf
(stderr
, "]");
8154 /* Prepare the function for tree completion */
8155 start_complete_expand_method
(mdecl
);
8157 /* Install the current this */
8158 current_this
= (!METHOD_STATIC
(mdecl
) ?
8159 BLOCK_EXPR_DECLS
(DECL_FUNCTION_BODY
(mdecl
)) : NULL_TREE
);
8161 /* Purge the `throws' list of unchecked exceptions (we save a copy
8162 of the list and re-install it later.) */
8163 exception_copy
= copy_list
(DECL_FUNCTION_THROWS
(mdecl
));
8164 purge_unchecked_exceptions
(mdecl
);
8166 /* Install exceptions thrown with `throws' */
8167 PUSH_EXCEPTIONS
(DECL_FUNCTION_THROWS
(mdecl
));
8169 if
(block_body
!= NULL_TREE
)
8171 block_body
= java_complete_tree
(block_body
);
8173 /* Before we check initialization, attached all class initialization
8174 variable to the block_body */
8175 htab_traverse
(DECL_FUNCTION_INIT_TEST_TABLE
(mdecl
),
8176 attach_init_test_initialization_flags
, block_body
);
8178 if
(! METHOD_NATIVE
(mdecl
))
8180 check_for_initialization
(block_body
, mdecl
);
8182 /* Go through all the flags marking the initialization of
8183 static variables and see whether they're definitively
8184 assigned, in which case the type is remembered as
8185 definitively initialized in MDECL. */
8186 if
(STATIC_CLASS_INIT_OPT_P
())
8188 /* Always register the context as properly initialized in
8189 MDECL. This used with caution helps removing extra
8190 initialization of self. */
8191 if
(METHOD_STATIC
(mdecl
))
8194 (DECL_FUNCTION_INITIALIZED_CLASS_TABLE
(mdecl
),
8195 DECL_CONTEXT
(mdecl
), INSERT
)) = DECL_CONTEXT
(mdecl
);
8199 ctxp
->explicit_constructor_p
= 0;
8202 BLOCK_EXPR_BODY
(fbody
) = block_body
;
8204 /* If we saw a return but couldn't evaluate it properly, we'll have
8205 an error_mark_node here. */
8206 if
(block_body
!= error_mark_node
8207 && (block_body
== NULL_TREE || CAN_COMPLETE_NORMALLY
(block_body
))
8208 && TREE_CODE
(TREE_TYPE
(TREE_TYPE
(mdecl
))) != VOID_TYPE
)
8209 missing_return_error
(current_function_decl
);
8211 /* See if we can get rid of <clinit> if MDECL happens to be <clinit> */
8212 maybe_yank_clinit
(mdecl
);
8214 /* Pop the current level, with special measures if we found errors. */
8215 if
(java_error_count
)
8216 pushdecl_force_head
(DECL_ARGUMENTS
(mdecl
));
8219 /* Pop the exceptions and sanity check */
8221 if
(currently_caught_type_list
)
8224 /* Restore the copy of the list of exceptions. */
8225 DECL_FUNCTION_THROWS
(mdecl
) = exception_copy
;
8228 /* For with each class for which there's code to generate. */
8231 java_expand_method_bodies
(tree class
)
8234 for
(decl
= TYPE_METHODS
(class
); decl
; decl
= TREE_CHAIN
(decl
))
8238 if
(! DECL_FUNCTION_BODY
(decl
))
8241 current_function_decl
= decl
;
8243 block
= BLOCK_EXPR_BODY
(DECL_FUNCTION_BODY
(decl
));
8245 /* Save the function body for gimplify and inlining. */
8246 DECL_SAVED_TREE
(decl
) = block
;
8248 /* It's time to assign the variable flagging static class
8249 initialization based on which classes invoked static methods
8250 are definitely initializing. This should be flagged. */
8251 if
(STATIC_CLASS_INIT_OPT_P
())
8253 tree list
= DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND
(decl
);
8254 for
(; list
!= NULL_TREE
; list
= TREE_CHAIN
(list
))
8256 /* Executed for each statement calling a static function.
8257 LIST is a TREE_LIST whose PURPOSE is the called function
8258 and VALUE is a compound whose second operand can be patched
8259 with static class initialization flag assignments. */
8261 tree called_method
= TREE_PURPOSE
(list
);
8262 tree compound
= TREE_VALUE
(list
);
8263 tree assignment_compound_list
8264 = build_tree_list
(called_method
, NULL
);
8266 /* For each class definitely initialized in
8267 CALLED_METHOD, fill ASSIGNMENT_COMPOUND with
8268 assignment to the class initialization flag. */
8269 htab_traverse
(DECL_FUNCTION_INITIALIZED_CLASS_TABLE
(called_method
),
8270 emit_test_initialization
,
8271 assignment_compound_list
);
8273 if
(TREE_VALUE
(assignment_compound_list
))
8274 TREE_OPERAND
(compound
, 1)
8275 = TREE_VALUE
(assignment_compound_list
);
8279 /* Expand the function body. */
8280 source_end_java_method
();
8286 /* This section of the code deals with accessing enclosing context
8287 fields either directly by using the relevant access to this$<n> or
8288 by invoking an access method crafted for that purpose. */
8290 /* Build the necessary access across nested class boundaries.
8291 This routine could be optimized to cache previous result
8292 (decl, current_class and returned access). When an access method
8293 needs to be generated, it always takes the form of a read. It might
8294 be later turned into a write by calling nested_field_access_fix. */
8297 build_nested_field_access
(tree id
, tree decl
)
8299 tree access
= NULL_TREE
;
8300 tree ctx
= NULL_TREE
;
8301 tree decl_ctx
= DECL_CONTEXT
(decl
);
8302 bool is_static
= FIELD_STATIC
(decl
);
8304 if
(DECL_CONTEXT
(TYPE_NAME
(current_class
)))
8305 ctx
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(current_class
)));
8307 /* For non-static fields, if the immediate enclosing context of the
8308 current class is the field decl's class or inherits from it,
8309 build the access as `this$<n>.<field>'. Note that we will break
8310 the `private' barrier if we're not emitting bytecodes. */
8313 && (ctx
== decl_ctx || inherits_from_p
(ctx
, decl_ctx
))
8314 && (!FIELD_PRIVATE
(decl
) ||
!flag_emit_class_files
))
8316 tree thisn
= build_current_thisn
(current_class
);
8317 access
= make_qualified_primary
(build_wfl_node
(thisn
),
8318 id
, EXPR_WFL_LINECOL
(id
));
8320 /* Otherwise, generate and use accessor methods for the field as
8324 int lc
= EXPR_WFL_LINECOL
(id
);
8326 /* Now we chain the required number of calls to the access$0 to
8327 get a hold to the enclosing instance we need for a non-static
8328 field, and then we build the field access. */
8330 access
= build_access_to_thisn
(current_class
, decl_ctx
, lc
);
8332 /* If the field is private and we're generating bytecode, then
8333 we generate an access method. */
8334 if
(FIELD_PRIVATE
(decl
) && flag_emit_class_files
)
8336 tree name
= build_nested_field_access_methods
(decl
);
8337 access
= build_nested_field_access_expr
(lc
, decl_ctx
,
8338 name
, access
, NULL_TREE
);
8340 /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'
8341 for non-static fields.
8342 Once again we break the `private' access rule from a foreign
8346 tree class_name
= DECL_NAME
(TYPE_NAME
(decl_ctx
));
8348 = make_qualified_primary
(build_wfl_node
(class_name
), id
, lc
);
8351 access
= make_qualified_primary
(access
, id
, lc
);
8354 return resolve_expression_name
(access
, NULL
);
8357 /* Return a nonzero value if DECL describes a field access across nested
8358 class boundaries. That is, DECL is in a class that either encloses,
8359 is enclosed by or shares a common enclosing class with, the class
8363 nested_field_access_p
(tree type
, tree decl
)
8365 bool is_static
= false
;
8366 tree decl_type
= DECL_CONTEXT
(decl
);
8367 tree type_root
, decl_type_root
;
8369 if
(decl_type
== type
8370 ||
(TREE_CODE
(decl
) != FIELD_DECL
&& TREE_CODE
(decl
) != VAR_DECL
))
8373 if
(!INNER_CLASS_TYPE_P
(type
)
8374 && !(TREE_CODE
(decl_type
) == RECORD_TYPE
8375 && INNER_CLASS_TYPE_P
(decl_type
)))
8378 is_static
= FIELD_STATIC
(decl
);
8380 /* If TYPE extends the declaration context of the non-static
8381 field we're trying to access, then this isn't a nested field
8382 access we need to worry about. */
8383 if
(!is_static
&& inherits_from_p
(type
, decl_type
))
8386 for
(type_root
= type
;
8387 DECL_CONTEXT
(TYPE_NAME
(type_root
));
8388 type_root
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type_root
))))
8390 if
(type_root
== decl_type
)
8394 if
(TREE_CODE
(decl_type
) == RECORD_TYPE
8395 && INNER_CLASS_TYPE_P
(decl_type
))
8397 for
(decl_type_root
= decl_type
;
8398 DECL_CONTEXT
(TYPE_NAME
(decl_type_root
));
8400 = TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(decl_type_root
))))
8402 if
(decl_type_root
== type
)
8407 decl_type_root
= decl_type
;
8409 if
(type_root
== decl_type_root
)
8412 /* Before we give up, see whether it is a non-static field
8413 inherited from the enclosing context we are considering. */
8414 if
(!DECL_CONTEXT
(TYPE_NAME
(type_root
))
8416 && inherits_from_p
(type_root
, decl_type
))
8422 /* Return a nonzero value if NODE represents a cross-nested-class
8423 access that has already been expanded. As a side effect, it returns
8424 the name of the field being accessed and the argument passed to the
8425 access function, suitable for a regeneration of the access method
8426 call if necessary. */
8429 nested_field_expanded_access_p
(tree node
, tree
*name
, tree
*arg_type
,
8434 if
(TREE_CODE
(node
) != CALL_EXPR
)
8437 /* Well, GCJ generates slightly different tree nodes when compiling
8438 to native or bytecodes. It's the case for function calls. */
8440 if
(flag_emit_class_files
8441 && TREE_CODE
(node
) == CALL_EXPR
8442 && NESTED_FIELD_ACCESS_IDENTIFIER_P
(DECL_NAME
(TREE_OPERAND
(node
, 0))))
8444 else if
(!flag_emit_class_files
)
8446 node
= TREE_OPERAND
(node
, 0);
8448 if
(node
&& TREE_OPERAND
(node
, 0)
8449 && TREE_CODE
(TREE_OPERAND
(node
, 0)) == ADDR_EXPR
)
8451 node
= TREE_OPERAND
(node
, 0);
8452 if
(TREE_OPERAND
(node
, 0)
8453 && TREE_CODE
(TREE_OPERAND
(node
, 0)) == FUNCTION_DECL
8454 && (NESTED_FIELD_ACCESS_IDENTIFIER_P
8455 (DECL_NAME
(TREE_OPERAND
(node
, 0)))))
8460 if
(identified
&& name
&& arg_type
&& arg
)
8462 tree argument
= TREE_OPERAND
(node
, 1);
8463 *name
= DECL_NAME
(TREE_OPERAND
(node
, 0));
8465 /* The accessors for static fields do not take in a this$<n> argument,
8466 so we take the class name from the accessor's context instead. */
8469 *arg_type
= TREE_TYPE
(TREE_TYPE
(TREE_VALUE
(argument
)));
8470 *arg
= TREE_VALUE
(argument
);
8474 *arg_type
= DECL_CONTEXT
(TREE_OPERAND
(node
, 0));
8481 /* Detect in NODE cross-nested-class field read access and
8482 transform it into a write with RHS as an argument. This function
8483 is called from the java_complete_lhs when an assignment to a LHS can
8487 nested_field_access_fix
(tree wfl
, tree node
, tree rhs
)
8489 tree name
, arg_type
, arg
;
8491 if
(nested_field_expanded_access_p
(node
, &name
, &arg_type
, &arg
))
8493 node
= build_nested_field_access_expr
(EXPR_WFL_LINECOL
(wfl
),
8494 arg_type
, name
, arg
, rhs
);
8495 return java_complete_tree
(node
);
8500 /* Construct the expression that calls an access method:
8501 <type>.access$<n>(<arg1> [, <arg2>]);
8503 ARG2 can be NULL and will be omitted in that case. It will denote a
8507 build_nested_field_access_expr
(int lc
, tree type
, tree access_method_name
,
8508 tree arg1
, tree arg2
)
8510 tree args
, cn
, access
;
8513 args
= build_tree_list
(NULL_TREE
, arg1
);
8520 args
= tree_cons
(NULL_TREE
, arg2
, args
);
8522 args
= build_tree_list
(NULL_TREE
, arg2
);
8526 = build_method_invocation
(build_wfl_node
(access_method_name
), args
);
8527 cn
= build_wfl_node
(DECL_NAME
(TYPE_NAME
(type
)));
8529 return make_qualified_primary
(cn
, access
, lc
);
8532 /* Build the name of a synthetic accessor used to access class members
8533 across nested class boundaries. */
8536 build_new_access_id
(void)
8538 static int access_n_counter
= 1;
8541 sprintf
(buffer
, "access$%d", access_n_counter
++);
8542 return get_identifier
(buffer
);
8545 /* Create the static access functions for the cross-nested-class field DECL.
8547 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$) {
8551 TREE_TYPE (<field>) access$<n> (DECL_CONTEXT (<field>) inst$,
8552 TREE_TYPE (<field>) value$) {
8553 return inst$.field = value$;
8555 For static fields, these methods are generated without the instance
8557 We should have a usage flag on the DECL so we can lazily turn the ones
8558 we're using for code generation. FIXME.
8562 build_nested_field_access_methods
(tree decl
)
8564 tree id
, args
, stmt
, mdecl
, class_name
= NULL_TREE
;
8565 bool is_static
= FIELD_STATIC
(decl
);
8567 if
(FIELD_NESTED_ACCESS_P
(decl
))
8568 return FIELD_NESTED_ACCESS
(decl
);
8570 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(decl
);
8572 /* Create the identifier and a function named after it. */
8573 id
= build_new_access_id
();
8575 /* The identifier is marked as bearing the name of a generated write
8576 access function for outer field accessed from inner classes. */
8577 NESTED_FIELD_ACCESS_IDENTIFIER_P
(id
) = 1;
8579 /* Create the read access. */
8582 args
= build_tree_list
(inst_id
,
8583 build_pointer_type
(DECL_CONTEXT
(decl
)));
8584 TREE_CHAIN
(args
) = end_params_node
;
8585 stmt
= make_qualified_primary
(build_wfl_node
(inst_id
),
8586 build_wfl_node
(DECL_NAME
(decl
)), 0);
8590 args
= end_params_node
;
8591 class_name
= DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(decl
)));
8592 stmt
= make_qualified_primary
(build_wfl_node
(class_name
),
8593 build_wfl_node
(DECL_NAME
(decl
)), 0);
8595 stmt
= build_return
(0, stmt
);
8596 mdecl
= build_nested_field_access_method
(DECL_CONTEXT
(decl
),
8597 TREE_TYPE
(decl
), id
, args
, stmt
);
8598 DECL_FUNCTION_ACCESS_DECL
(mdecl
) = decl
;
8600 /* Create the write access method. No write access for final variable */
8601 if
(!FIELD_FINAL
(decl
))
8605 args
= build_tree_list
(inst_id
,
8606 build_pointer_type
(DECL_CONTEXT
(decl
)));
8607 TREE_CHAIN
(args
) = build_tree_list
(wpv_id
, TREE_TYPE
(decl
));
8608 TREE_CHAIN
(TREE_CHAIN
(args
)) = end_params_node
;
8609 stmt
= make_qualified_primary
(build_wfl_node
(inst_id
),
8610 build_wfl_node
(DECL_NAME
(decl
)),
8615 args
= build_tree_list
(wpv_id
, TREE_TYPE
(decl
));
8616 TREE_CHAIN
(args
) = end_params_node
;
8617 stmt
= make_qualified_primary
(build_wfl_node
(class_name
),
8618 build_wfl_node
(DECL_NAME
(decl
)),
8621 stmt
= build_return
(0, build_assignment
(ASSIGN_TK
, 0, stmt
,
8622 build_wfl_node
(wpv_id
)));
8623 mdecl
= build_nested_field_access_method
(DECL_CONTEXT
(decl
),
8624 TREE_TYPE
(decl
), id
,
8627 DECL_FUNCTION_ACCESS_DECL
(mdecl
) = decl
;
8629 /* Return the access name */
8630 return FIELD_NESTED_ACCESS
(decl
) = id
;
8633 /* Build a field access method NAME. */
8636 build_nested_field_access_method
(tree class
, tree type
, tree name
,
8637 tree args
, tree body
)
8639 tree saved_current_function_decl
, mdecl
;
8641 /* Create the method */
8642 mdecl
= create_artificial_method
(class
, ACC_STATIC
, type
, name
, args
);
8643 fix_method_argument_names
(args
, mdecl
);
8644 layout_class_method
(class
, NULL_TREE
, mdecl
, NULL_TREE
);
8646 /* Attach the method body. */
8647 saved_current_function_decl
= current_function_decl
;
8648 start_artificial_method_body
(mdecl
);
8649 java_method_add_stmt
(mdecl
, body
);
8650 end_artificial_method_body
(mdecl
);
8651 current_function_decl
= saved_current_function_decl
;
8657 /* This section deals with building access function necessary for
8658 certain kinds of method invocation from inner classes. */
8661 build_outer_method_access_method
(tree decl
)
8663 tree saved_current_function_decl
, mdecl
;
8664 tree args
= NULL_TREE
, call_args
= NULL_TREE
;
8665 tree carg
, id
, body
, class
;
8667 int parm_id_count
= 0;
8669 /* Test this abort with an access to a private field */
8670 if
(!strcmp
(IDENTIFIER_POINTER
(DECL_NAME
(decl
)), "access$"))
8673 /* Check the cache first */
8674 if
(DECL_FUNCTION_INNER_ACCESS
(decl
))
8675 return DECL_FUNCTION_INNER_ACCESS
(decl
);
8677 class
= DECL_CONTEXT
(decl
);
8679 /* Obtain an access identifier and mark it */
8680 id
= build_new_access_id
();
8681 NESTED_FIELD_ACCESS_IDENTIFIER_P
(id
) = 1;
8683 carg
= TYPE_ARG_TYPES
(TREE_TYPE
(decl
));
8684 /* Create the arguments, as much as the original */
8685 for
(; carg
&& carg
!= end_params_node
;
8686 carg
= TREE_CHAIN
(carg
))
8688 sprintf
(buffer
, "write_parm_value$%d", parm_id_count
++);
8689 args
= chainon
(args
, build_tree_list
(get_identifier
(buffer
),
8690 TREE_VALUE
(carg
)));
8692 args
= chainon
(args
, end_params_node
);
8694 /* Create the method */
8695 mdecl
= create_artificial_method
(class
, ACC_STATIC
,
8696 TREE_TYPE
(TREE_TYPE
(decl
)), id
, args
);
8697 layout_class_method
(class
, NULL_TREE
, mdecl
, NULL_TREE
);
8698 /* There is a potential bug here. We should be able to use
8699 fix_method_argument_names, but then arg names get mixed up and
8700 eventually a constructor will have its this$0 altered and the
8701 outer context won't be assignment properly. The testcase is
8703 TYPE_ARG_TYPES
(TREE_TYPE
(mdecl
)) = args
;
8705 /* Attach the method body. */
8706 saved_current_function_decl
= current_function_decl
;
8707 start_artificial_method_body
(mdecl
);
8709 /* The actual method invocation uses the same args. When invoking a
8710 static methods that way, we don't want to skip the first
8713 if
(!METHOD_STATIC
(decl
))
8714 carg
= TREE_CHAIN
(carg
);
8715 for
(; carg
&& carg
!= end_params_node
; carg
= TREE_CHAIN
(carg
))
8716 call_args
= tree_cons
(NULL_TREE
, build_wfl_node
(TREE_PURPOSE
(carg
)),
8719 body
= build_method_invocation
(build_wfl_node
(DECL_NAME
(decl
)),
8721 if
(!METHOD_STATIC
(decl
))
8722 body
= make_qualified_primary
(build_wfl_node
(TREE_PURPOSE
(args
)),
8724 if
(TREE_TYPE
(TREE_TYPE
(decl
)) != void_type_node
)
8725 body
= build_return
(0, body
);
8726 java_method_add_stmt
(mdecl
,body
);
8727 end_artificial_method_body
(mdecl
);
8728 current_function_decl
= saved_current_function_decl
;
8730 /* Back tag the access function so it know what it accesses */
8731 DECL_FUNCTION_ACCESS_DECL
(decl
) = mdecl
;
8733 /* Tag the current method so it knows it has an access generated */
8734 return DECL_FUNCTION_INNER_ACCESS
(decl
) = mdecl
;
8738 /* This section of the code deals with building expressions to access
8739 the enclosing instance of an inner class. The enclosing instance is
8740 kept in a generated field called this$<n>, with <n> being the
8741 inner class nesting level (starting from 0.) */
8743 /* Build an access to a given this$<n>, always chaining access call to
8744 others. Access methods to this$<n> are build on the fly if
8745 necessary. This CAN'T be used to solely access this$<n-1> from
8746 this$<n> (which alway yield to special cases and optimization, see
8747 for example build_nested_field_access). */
8750 build_access_to_thisn
(tree from
, tree to
, int lc
)
8752 tree access
= NULL_TREE
;
8754 while
(from
!= to
&& PURE_INNER_CLASS_TYPE_P
(from
))
8758 access
= build_current_thisn
(from
);
8759 access
= build_wfl_node
(access
);
8763 tree access0_wfl
, cn
;
8765 maybe_build_thisn_access_method
(from
);
8766 access0_wfl
= build_wfl_node
(access0_identifier_node
);
8767 cn
= build_wfl_node
(DECL_NAME
(TYPE_NAME
(from
)));
8768 EXPR_WFL_LINECOL
(access0_wfl
) = lc
;
8769 access
= build_tree_list
(NULL_TREE
, access
);
8770 access
= build_method_invocation
(access0_wfl
, access
);
8771 access
= make_qualified_primary
(cn
, access
, lc
);
8774 /* If FROM isn't an inner class, that's fine, we've done enough.
8775 What we're looking for can be accessed from there. */
8776 from
= DECL_CONTEXT
(TYPE_NAME
(from
));
8779 from
= TREE_TYPE
(from
);
8784 /* Build an access function to the this$<n> local to TYPE. NULL_TREE
8785 is returned if nothing needs to be generated. Otherwise, the method
8786 generated and a method decl is returned.
8788 NOTE: These generated methods should be declared in a class file
8789 attribute so that they can't be referred to directly. */
8792 maybe_build_thisn_access_method
(tree type
)
8794 tree mdecl
, args
, stmt
, rtype
;
8795 tree saved_current_function_decl
;
8797 /* If TYPE is a top-level class, no access method is required.
8798 If there already is such an access method, bail out. */
8799 if
(CLASS_ACCESS0_GENERATED_P
(type
) ||
!PURE_INNER_CLASS_TYPE_P
(type
))
8802 /* We generate the method. The method looks like:
8803 static <outer_of_type> access$0 (<type> inst$) { return inst$.this$<n>; }
8805 args
= build_tree_list
(inst_id
, build_pointer_type
(type
));
8806 TREE_CHAIN
(args
) = end_params_node
;
8807 rtype
= build_pointer_type
(TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type
))));
8808 mdecl
= create_artificial_method
(type
, ACC_STATIC
, rtype
,
8809 access0_identifier_node
, args
);
8810 fix_method_argument_names
(args
, mdecl
);
8811 layout_class_method
(type
, NULL_TREE
, mdecl
, NULL_TREE
);
8812 stmt
= build_current_thisn
(type
);
8813 stmt
= make_qualified_primary
(build_wfl_node
(inst_id
),
8814 build_wfl_node
(stmt
), 0);
8815 stmt
= build_return
(0, stmt
);
8817 saved_current_function_decl
= current_function_decl
;
8818 start_artificial_method_body
(mdecl
);
8819 java_method_add_stmt
(mdecl
, stmt
);
8820 end_artificial_method_body
(mdecl
);
8821 current_function_decl
= saved_current_function_decl
;
8823 CLASS_ACCESS0_GENERATED_P
(type
) = 1;
8828 /* Craft an correctly numbered `this$<n>'string. this$0 is used for
8829 the first level of innerclassing. this$1 for the next one, etc...
8830 This function can be invoked with TYPE to NULL, available and then
8831 has to count the parser context. */
8833 static GTY
(()) tree saved_thisn
;
8834 static GTY
(()) tree saved_type
;
8837 build_current_thisn
(tree type
)
8839 static int saved_i
= -1;
8840 static int saved_type_i
= 0;
8847 if
(type
== saved_type
)
8851 for
(i
= -1, decl
= DECL_CONTEXT
(TYPE_NAME
(type
));
8852 decl
; decl
= DECL_CONTEXT
(decl
), i
++)
8860 i
= list_length
(GET_CPC_LIST
())-2;
8865 sprintf
(buffer
, "this$%d", i
);
8867 saved_thisn
= get_identifier
(buffer
);
8871 /* Return the assignment to the hidden enclosing context `this$<n>'
8872 by the second incoming parameter to the innerclass constructor. The
8873 form used is `this.this$<n> = this$<n>;'. */
8876 build_thisn_assign
(void)
8878 if
(current_class
&& PURE_INNER_CLASS_TYPE_P
(current_class
))
8880 tree thisn
= build_current_thisn
(current_class
);
8881 tree lhs
= make_qualified_primary
(build_wfl_node
(this_identifier_node
),
8882 build_wfl_node
(thisn
), 0);
8883 tree rhs
= build_wfl_node
(thisn
);
8884 #ifdef USE_MAPPED_LOCATION
8885 SET_EXPR_LOCATION
(lhs
, input_location
);
8887 EXPR_WFL_SET_LINECOL
(lhs
, input_line
, 0);
8889 return build_assignment
(ASSIGN_TK
, EXPR_WFL_LINECOL
(lhs
), lhs
, rhs
);
8895 /* Building the synthetic `class$' used to implement the `.class' 1.1
8896 extension for non primitive types. This method looks like:
8898 static Class class$(String type) throws NoClassDefFoundError
8900 try {return (java.lang.Class.forName (String));}
8901 catch (ClassNotFoundException e) {
8902 throw new NoClassDefFoundError(e.getMessage());}
8905 static GTY
(()) tree get_message_wfl
;
8906 static GTY
(()) tree type_parm_wfl
;
8909 build_dot_class_method
(tree class
)
8911 #define BWF(S) build_wfl_node (get_identifier ((S)))
8912 #ifdef USE_MAPPED_LOCATION
8913 #define MQN(X,Y) make_qualified_name ((X), (Y), UNKNOWN_LOCATION)
8915 #define MQN(X,Y) make_qualified_name ((X), (Y), 0)
8917 tree args
, tmp
, saved_current_function_decl
, mdecl
, qual_name
;
8918 tree stmt
, throw_stmt
;
8920 if
(!get_message_wfl
)
8922 get_message_wfl
= build_wfl_node
(get_identifier
("getMessage"));
8923 type_parm_wfl
= build_wfl_node
(get_identifier
("type$"));
8926 /* Build the arguments */
8927 args
= build_tree_list
(get_identifier
("type$"),
8928 build_pointer_type
(string_type_node
));
8929 TREE_CHAIN
(args
) = end_params_node
;
8931 /* Build the qualified name java.lang.Class.forName */
8932 tmp
= MQN
(MQN
(MQN
(BWF
("java"),
8933 BWF
("lang")), BWF
("Class")), BWF
("forName"));
8935 /* Create the "class$" function */
8936 mdecl
= create_artificial_method
(class
, ACC_STATIC
,
8937 build_pointer_type
(class_type_node
),
8938 classdollar_identifier_node
, args
);
8939 qual_name
= MQN
(MQN
(BWF
("java"), BWF
("lang")),
8940 BWF
("NoClassDefFoundError"));
8941 DECL_FUNCTION_THROWS
(mdecl
) = build_tree_list
(NULL_TREE
, qual_name
);
8942 register_incomplete_type
(JDEP_EXCEPTION
, qual_name
, NULL_TREE
, NULL_TREE
);
8943 JDEP_GET_PATCH
(CLASSD_LAST
(ctxp
->classd_list
)) =
8944 &TREE_VALUE
(DECL_FUNCTION_THROWS
(mdecl
));
8946 /* We start by building the try block. We need to build:
8947 return (java.lang.Class.forName (type)); */
8948 stmt
= build_method_invocation
(tmp
,
8949 build_tree_list
(NULL_TREE
, type_parm_wfl
));
8950 stmt
= build_return
(0, stmt
);
8952 /* Now onto the catch block. We start by building the expression
8953 throwing a new exception: throw new NoClassDefFoundError (_.getMessage) */
8954 #ifdef USE_MAPPED_LOCATION
8955 throw_stmt
= make_qualified_name
(build_wfl_node
(wpv_id
),
8956 get_message_wfl
, UNKNOWN_LOCATION
);
8958 throw_stmt
= make_qualified_name
(build_wfl_node
(wpv_id
),
8959 get_message_wfl
, 0);
8961 throw_stmt
= build_method_invocation
(throw_stmt
, NULL_TREE
);
8963 /* Build new NoClassDefFoundError (_.getMessage) */
8964 throw_stmt
= build_new_invocation
8965 (build_wfl_node
(get_identifier
("NoClassDefFoundError")),
8966 build_tree_list
(build_pointer_type
(string_type_node
), throw_stmt
));
8968 /* Build the throw, (it's too early to use BUILD_THROW) */
8969 throw_stmt
= build1
(THROW_EXPR
, NULL_TREE
, throw_stmt
);
8971 /* Encapsulate STMT in a try block. The catch clause executes THROW_STMT */
8972 qual_name
= MQN
(MQN
(BWF
("java"), BWF
("lang")),
8973 BWF
("ClassNotFoundException"));
8974 stmt
= encapsulate_with_try_catch
(0, qual_name
, stmt
, throw_stmt
);
8976 fix_method_argument_names
(args
, mdecl
);
8977 layout_class_method
(class
, NULL_TREE
, mdecl
, NULL_TREE
);
8978 saved_current_function_decl
= current_function_decl
;
8979 start_artificial_method_body
(mdecl
);
8980 java_method_add_stmt
(mdecl
, stmt
);
8981 end_artificial_method_body
(mdecl
);
8982 current_function_decl
= saved_current_function_decl
;
8983 TYPE_DOT_CLASS
(class
) = mdecl
;
8989 build_dot_class_method_invocation
(tree this_class
, tree type
)
8991 tree dot_class_method
= TYPE_DOT_CLASS
(this_class
);
8994 if
(TYPE_ARRAY_P
(type
))
8995 sig_id
= build_java_signature
(type
);
8997 sig_id
= DECL_NAME
(TYPE_NAME
(type
));
8999 /* Ensure that the proper name separator is used */
9000 sig_id
= unmangle_classname
(IDENTIFIER_POINTER
(sig_id
),
9001 IDENTIFIER_LENGTH
(sig_id
));
9003 s
= build_string
(IDENTIFIER_LENGTH
(sig_id
),
9004 IDENTIFIER_POINTER
(sig_id
));
9005 t
= build_method_invocation
(build_wfl_node
(DECL_NAME
(dot_class_method
)),
9006 build_tree_list
(NULL_TREE
, s
));
9007 if
(DECL_CONTEXT
(dot_class_method
) != this_class
)
9009 tree class_name
= DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(dot_class_method
)));
9010 t
= make_qualified_primary
(build_wfl_node
(class_name
), t
, 0);
9015 /* This section of the code deals with constructor. */
9017 /* Craft a body for default constructor. Patch existing constructor
9018 bodies with call to super() and field initialization statements if
9022 fix_constructors
(tree mdecl
)
9024 tree iii
; /* Instance Initializer Invocation */
9025 tree
*bodyp
= &DECL_FUNCTION_BODY
(mdecl
);
9026 tree thisn_assign
, compound
= NULL_TREE
;
9027 tree class_type
= DECL_CONTEXT
(mdecl
);
9029 if
(DECL_FIXED_CONSTRUCTOR_P
(mdecl
))
9031 DECL_FIXED_CONSTRUCTOR_P
(mdecl
) = 1;
9035 /* It is an error for the compiler to generate a default
9036 constructor if the superclass doesn't have a constructor that
9037 takes no argument, or the same args for an anonymous class */
9038 if
(verify_constructor_super
(mdecl
))
9040 tree sclass_decl
= TYPE_NAME
(CLASSTYPE_SUPER
(class_type
));
9041 tree save
= DECL_NAME
(mdecl
);
9042 const char *n
= IDENTIFIER_POINTER
(DECL_NAME
(sclass_decl
));
9043 DECL_NAME
(mdecl
) = DECL_NAME
(sclass_decl
);
9045 (lookup_cl
(TYPE_NAME
(class_type
)),
9046 "No constructor matching %qs found in class %qs",
9047 lang_printable_name
(mdecl
, 2), n
);
9048 DECL_NAME
(mdecl
) = save
;
9051 /* The constructor body must be crafted by hand. It's the
9052 constructor we defined when we realize we didn't have the
9053 CLASSNAME() constructor */
9054 start_artificial_method_body
(mdecl
);
9056 /* Insert an assignment to the this$<n> hidden field, if
9058 if
((thisn_assign
= build_thisn_assign
()))
9059 java_method_add_stmt
(mdecl
, thisn_assign
);
9061 /* We don't generate a super constructor invocation if we're
9062 compiling java.lang.Object. build_super_invocation takes care
9064 java_method_add_stmt
(mdecl
, build_super_invocation
(mdecl
));
9067 if
((iii
= build_instinit_invocation
(class_type
)))
9068 java_method_add_stmt
(mdecl
, iii
);
9070 end_artificial_method_body
(mdecl
);
9072 /* Search for an explicit constructor invocation */
9076 int invokes_this
= 0;
9077 tree main_block
= BLOCK_EXPR_BODY
(*bodyp
);
9082 switch
(TREE_CODE
(body
))
9085 found
= CALL_EXPLICIT_CONSTRUCTOR_P
(body
);
9086 if
(CALL_THIS_CONSTRUCTOR_P
(body
))
9090 case EXPR_WITH_FILE_LOCATION
:
9091 bodyp
= &TREE_OPERAND
(body
, 0);
9094 bodyp
= &BLOCK_EXPR_BODY
(body
);
9102 /* Generate the assignment to this$<n>, if necessary */
9103 if
((thisn_assign
= build_thisn_assign
()))
9104 compound
= add_stmt_to_compound
(compound
, NULL_TREE
, thisn_assign
);
9106 /* The constructor is missing an invocation of super() */
9108 compound
= add_stmt_to_compound
(compound
, NULL_TREE
,
9109 build_super_invocation
(mdecl
));
9110 /* Explicit super() invocation should take place before the
9111 instance initializer blocks. */
9114 compound
= add_stmt_to_compound
(compound
, NULL_TREE
, *bodyp
);
9115 *bodyp
= build_java_empty_stmt
();
9118 DECL_INIT_CALLS_THIS
(mdecl
) = invokes_this
;
9120 /* Insert the instance initializer block right after. */
9121 if
(!invokes_this
&& (iii
= build_instinit_invocation
(class_type
)))
9122 compound
= add_stmt_to_compound
(compound
, NULL_TREE
, iii
);
9124 /* Fix the constructor main block if we're adding extra stmts */
9127 compound
= add_stmt_to_compound
(compound
, NULL_TREE
,
9128 BLOCK_EXPR_BODY
(main_block
));
9129 BLOCK_EXPR_BODY
(main_block
) = compound
;
9134 /* Browse constructors in the super class, searching for a constructor
9135 that doesn't take any argument. Return 0 if one is found, 1
9136 otherwise. If the current class is an anonymous inner class, look
9137 for something that has the same signature. */
9140 verify_constructor_super
(tree mdecl
)
9142 tree class
= CLASSTYPE_SUPER
(current_class
);
9143 int super_inner
= PURE_INNER_CLASS_TYPE_P
(class
);
9149 if
(ANONYMOUS_CLASS_P
(current_class
))
9151 tree mdecl_arg_type
;
9152 SKIP_THIS_AND_ARTIFICIAL_PARMS
(mdecl_arg_type
, mdecl
);
9153 for
(sdecl
= TYPE_METHODS
(class
); sdecl
; sdecl
= TREE_CHAIN
(sdecl
))
9154 if
(DECL_CONSTRUCTOR_P
(sdecl
))
9157 tree arg_type
= TREE_CHAIN
(TYPE_ARG_TYPES
(TREE_TYPE
(sdecl
)));
9159 arg_type
= TREE_CHAIN
(arg_type
);
9160 for
(m_arg_type
= mdecl_arg_type
;
9161 (arg_type
!= end_params_node
9162 && m_arg_type
!= end_params_node
);
9163 arg_type
= TREE_CHAIN
(arg_type
),
9164 m_arg_type
= TREE_CHAIN
(m_arg_type
))
9165 if
(!valid_method_invocation_conversion_p
9166 (TREE_VALUE
(arg_type
),
9167 TREE_VALUE
(m_arg_type
)))
9170 if
(arg_type
== end_params_node
&& m_arg_type
== end_params_node
)
9176 for
(sdecl
= TYPE_METHODS
(class
); sdecl
; sdecl
= TREE_CHAIN
(sdecl
))
9178 tree arg
= TREE_CHAIN
(TYPE_ARG_TYPES
(TREE_TYPE
(sdecl
)));
9180 arg
= TREE_CHAIN
(arg
);
9181 if
(DECL_CONSTRUCTOR_P
(sdecl
) && arg
== end_params_node
)
9188 /* Generate code for all context remembered for code generation. */
9190 static GTY
(()) tree reversed_class_list
;
9192 java_expand_classes
(void)
9194 int save_error_count
= 0;
9195 static struct parser_ctxt
*cur_ctxp
= NULL
;
9196 location_t save_location
;
9198 java_parse_abort_on_error
();
9199 if
(!(ctxp
= ctxp_for_generation
))
9201 java_layout_classes
();
9202 java_parse_abort_on_error
();
9203 save_location
= input_location
;
9205 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9208 for
(current
= cur_ctxp
->class_list
;
9210 current
= TREE_CHAIN
(current
))
9211 gen_indirect_dispatch_tables
(TREE_TYPE
(current
));
9214 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9217 input_location
= ctxp
->file_start_location
;
9218 lang_init_source
(2); /* Error msgs have method prototypes */
9219 java_complete_expand_classes
(); /* Complete and expand classes */
9220 java_parse_abort_on_error
();
9222 input_location
= save_location
;
9224 /* Find anonymous classes and expand their constructor. This extra pass is
9225 necessary because the constructor itself is only generated when the
9226 method in which it is defined is expanded. */
9227 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9231 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
9233 output_class
= current_class
= TREE_TYPE
(current
);
9234 if
(ANONYMOUS_CLASS_P
(current_class
))
9237 for
(d
= TYPE_METHODS
(current_class
); d
; d
= TREE_CHAIN
(d
))
9239 if
(DECL_CONSTRUCTOR_P
(d
))
9241 java_complete_expand_method
(d
);
9242 break
; /* There is only one constructor. */
9249 /* Expanding the constructors of anonymous classes generates access
9250 methods. Scan all the methods looking for null DECL_RESULTs --
9251 this will be the case if a method hasn't been expanded. */
9252 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9256 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
9259 output_class
= current_class
= TREE_TYPE
(current
);
9260 for
(d
= TYPE_METHODS
(current_class
); d
; d
= TREE_CHAIN
(d
))
9262 if
(DECL_RESULT
(d
) == NULL_TREE
)
9263 java_complete_expand_method
(d
);
9268 /* ??? Instead of all this we could iterate around the list of
9269 classes until there were no more un-expanded methods. It would
9270 take a little longer -- one pass over the whole list of methods
9271 -- but it would be simpler. Like this: */
9274 int something_changed
;
9278 something_changed
= 0;
9279 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9283 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
9286 output_class
= current_class
= TREE_TYPE
(current
);
9287 for
(d
= TYPE_METHODS
(current_class
); d
; d
= TREE_CHAIN
(d
))
9289 if
(DECL_RESULT
(d
) == NULL_TREE
)
9291 something_changed
= 1;
9292 java_complete_expand_method
(d
);
9298 while
(something_changed
);
9302 /* If we've found error at that stage, don't try to generate
9303 anything, unless we're checking the syntax only
9304 (but not using -fsyntax-only for the purpose of generating
9306 if
(java_error_count
9307 && (!flag_syntax_only
&& !flag_emit_class_files
))
9310 /* Now things are stable, go for generation of the class data. */
9312 /* We pessimistically marked all methods and fields external until
9313 we knew what set of classes we were planning to compile. Now mark
9314 those that will be generated locally as not external. */
9315 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9319 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
9320 java_mark_class_local
(TREE_TYPE
(current
));
9323 /* Compile the classes. */
9324 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9327 reversed_class_list
= NULL
;
9331 /* We write out the classes in reverse order. This ensures that
9332 inner classes are written before their containing classes,
9333 which is important for parallel builds. Otherwise, the
9334 class file for the outer class may be found, but the class
9335 file for the inner class may not be present. In that
9336 situation, the compiler cannot fall back to the original
9337 source, having already read the outer class, so we must
9338 prevent that situation. */
9339 for
(current
= ctxp
->class_list
;
9341 current
= TREE_CHAIN
(current
))
9343 = tree_cons
(NULL_TREE
, current
, reversed_class_list
);
9345 for
(current
= reversed_class_list
;
9347 current
= TREE_CHAIN
(current
))
9349 output_class
= current_class
= TREE_TYPE
(TREE_VALUE
(current
));
9350 if
(flag_emit_class_files
)
9351 write_classfile
(current_class
);
9352 else if
(! flag_syntax_only
)
9353 java_expand_method_bodies
(current_class
);
9359 java_finish_classes
(void)
9361 static struct parser_ctxt
*cur_ctxp
= NULL
;
9362 for
(cur_ctxp
= ctxp_for_generation
; cur_ctxp
; cur_ctxp
= cur_ctxp
->next
)
9366 for
(current
= ctxp
->class_list
; current
; current
= TREE_CHAIN
(current
))
9368 output_class
= current_class
= TREE_TYPE
(current
);
9374 /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
9375 a tree list node containing RIGHT. Fore coming RIGHTs will be
9376 chained to this hook. LOCATION contains the location of the
9377 separating `.' operator. */
9380 make_qualified_primary
(tree primary
, tree right
, int location
)
9384 if
(TREE_CODE
(primary
) != EXPR_WITH_FILE_LOCATION
)
9385 wfl
= build_wfl_wrap
(primary
, location
);
9389 /* If wfl wasn't qualified, we build a first anchor */
9390 if
(!EXPR_WFL_QUALIFICATION
(wfl
))
9391 EXPR_WFL_QUALIFICATION
(wfl
) = build_tree_list
(wfl
, NULL_TREE
);
9394 /* And chain them */
9395 EXPR_WFL_LINECOL
(right
) = location
;
9396 chainon
(EXPR_WFL_QUALIFICATION
(wfl
), build_tree_list
(right
, NULL_TREE
));
9397 PRIMARY_P
(wfl
) = 1;
9401 /* Simple merge of two name separated by a `.' */
9404 merge_qualified_name
(tree left
, tree right
)
9407 if
(!left
&& !right
)
9416 obstack_grow
(&temporary_obstack
, IDENTIFIER_POINTER
(left
),
9417 IDENTIFIER_LENGTH
(left
));
9418 obstack_1grow
(&temporary_obstack
, '.');
9419 obstack_grow0
(&temporary_obstack
, IDENTIFIER_POINTER
(right
),
9420 IDENTIFIER_LENGTH
(right
));
9421 node
= get_identifier
(obstack_base
(&temporary_obstack
));
9422 obstack_free
(&temporary_obstack
, obstack_base
(&temporary_obstack
));
9423 QUALIFIED_P
(node
) = 1;
9427 /* Merge the two parts of a qualified name into LEFT. Set the
9428 location information of the resulting node to LOCATION, usually
9429 inherited from the location information of the `.' operator. */
9432 make_qualified_name
(tree left
, tree right
,
9433 #ifdef USE_MAPPED_LOCATION
9434 source_location location
9440 #ifdef USE_COMPONENT_REF
9441 tree node
= build3
(COMPONENT_REF
, NULL_TREE
, left
, right
, NULL_TREE
);
9442 SET_EXPR_LOCATION
(node
, location
);
9445 tree left_id
= EXPR_WFL_NODE
(left
);
9446 tree right_id
= EXPR_WFL_NODE
(right
);
9449 merge
= merge_qualified_name
(left_id
, right_id
);
9451 /* Left wasn't qualified and is now qualified */
9452 #ifdef USE_MAPPED_LOCATION
9453 if
(!QUALIFIED_P
(left_id
))
9455 tree wfl
= build_expr_wfl
(left_id
, EXPR_LOCATION
(left
));
9456 EXPR_WFL_QUALIFICATION
(left
) = build_tree_list
(wfl
, NULL_TREE
);
9459 wfl
= build_expr_wfl
(right_id
, location
);
9461 if
(!QUALIFIED_P
(left_id
))
9463 tree wfl
= build_expr_wfl
(left_id
, ctxp
->filename
, 0, 0);
9464 EXPR_WFL_LINECOL
(wfl
) = EXPR_WFL_LINECOL
(left
);
9465 EXPR_WFL_QUALIFICATION
(left
) = build_tree_list
(wfl
, NULL_TREE
);
9468 wfl
= build_expr_wfl
(right_id
, ctxp
->filename
, 0, 0);
9469 EXPR_WFL_LINECOL
(wfl
) = location
;
9471 chainon
(EXPR_WFL_QUALIFICATION
(left
), build_tree_list
(wfl
, NULL_TREE
));
9472 EXPR_WFL_NODE
(left
) = merge
;
9477 /* Extract the last identifier component of the qualified in WFL. The
9478 last identifier is removed from the linked list */
9481 cut_identifier_in_qualified
(tree wfl
)
9484 tree previous
= NULL_TREE
;
9485 for
(q
= EXPR_WFL_QUALIFICATION
(wfl
); ; previous
= q
, q
= TREE_CHAIN
(q
))
9486 if
(!TREE_CHAIN
(q
))
9489 /* Operating on a non qualified qualified WFL. */
9492 TREE_CHAIN
(previous
) = NULL_TREE
;
9493 return TREE_PURPOSE
(q
);
9497 /* Resolve the expression name NAME. Return its decl. */
9500 resolve_expression_name
(tree id
, tree
*orig
)
9502 tree name
= EXPR_WFL_NODE
(id
);
9505 /* 6.5.5.1: Simple expression names */
9506 if
(!PRIMARY_P
(id
) && !QUALIFIED_P
(name
))
9508 /* 15.13.1: NAME can appear within the scope of a local variable
9510 if
((decl
= IDENTIFIER_LOCAL_VALUE
(name
)))
9513 /* 15.13.1: NAME can appear within a class declaration */
9516 decl
= lookup_field_wrapper
(current_class
, name
);
9519 tree access
= NULL_TREE
;
9520 int fs
= FIELD_STATIC
(decl
);
9522 /* If we're accessing an outer scope local alias, make
9523 sure we change the name of the field we're going to
9525 if
(FIELD_LOCAL_ALIAS_USED
(decl
))
9526 name
= DECL_NAME
(decl
);
9528 check_deprecation
(id
, decl
);
9530 /* Instance variable (8.3.1.1) can't appear within
9531 static method, static initializer or initializer for
9532 a static variable. */
9533 if
(!fs
&& METHOD_STATIC
(current_function_decl
))
9535 static_ref_err
(id
, name
, current_class
);
9536 return error_mark_node
;
9538 /* Instance variables can't appear as an argument of
9539 an explicit constructor invocation */
9540 if
(!fs
&& ctxp
->explicit_constructor_p
9541 && !enclosing_context_p
(DECL_CONTEXT
(decl
), current_class
))
9544 (id
, "Can't reference %qs before the superclass constructor has been called", IDENTIFIER_POINTER
(name
));
9545 return error_mark_node
;
9548 /* If we're processing an inner class and we're trying
9549 to access a field belonging to an outer class, build
9550 the access to the field. */
9551 if
(nested_field_access_p
(current_class
, decl
))
9553 if
(!fs
&& CLASS_STATIC
(TYPE_NAME
(current_class
)))
9555 static_ref_err
(id
, DECL_NAME
(decl
), current_class
);
9556 return error_mark_node
;
9558 access
= build_nested_field_access
(id
, decl
);
9564 /* Otherwise build what it takes to access the field */
9565 access
= build_field_ref
((fs ? NULL_TREE
: current_this
),
9566 DECL_CONTEXT
(decl
), name
);
9568 access
= maybe_build_class_init_for_field
(decl
, access
);
9569 /* We may be asked to save the real field access node */
9572 /* Last check: can we access the field? */
9573 if
(not_accessible_p
(current_class
, decl
, NULL_TREE
, 0))
9575 not_accessible_field_error
(id
, decl
);
9576 return error_mark_node
;
9578 /* And we return what we got */
9581 /* Fall down to error report on undefined variable */
9584 /* 6.5.5.2 Qualified Expression Names */
9589 qualify_ambiguous_name
(id
);
9590 /* 15.10.1 Field Access Using a Primary and/or Expression Name */
9591 /* 15.10.2: Accessing Superclass Members using super */
9592 return resolve_field_access
(id
, orig
, NULL
);
9595 /* We've got an error here */
9596 if
(INNER_CLASS_TYPE_P
(current_class
))
9597 parse_error_context
(id
,
9598 "Local variable %qs can't be accessed from within the inner class %qs unless it is declared final",
9599 IDENTIFIER_POINTER
(name
),
9600 IDENTIFIER_POINTER
(DECL_NAME
9601 (TYPE_NAME
(current_class
))));
9603 parse_error_context
(id
, "Undefined variable %qs",
9604 IDENTIFIER_POINTER
(name
));
9606 return error_mark_node
;
9610 static_ref_err
(tree wfl
, tree field_id
, tree class_type
)
9614 "Can't make a static reference to nonstatic variable %qs in class %qs",
9615 IDENTIFIER_POINTER
(field_id
),
9616 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(class_type
))));
9619 /* 15.10.1 Field Access Using a Primary and/or Expression Name.
9620 We return something suitable to generate the field access. We also
9621 return the field decl in FIELD_DECL and its type in FIELD_TYPE. If
9622 recipient's address can be null. */
9625 resolve_field_access
(tree qual_wfl
, tree
*field_decl
, tree
*field_type
)
9629 tree decl
= NULL_TREE
, where_found
, type_found
;
9631 if
(resolve_qualified_expression_name
(qual_wfl
, &decl
,
9632 &where_found
, &type_found
))
9633 return error_mark_node
;
9635 /* Resolve the LENGTH field of an array here */
9636 if
(DECL_P
(decl
) && DECL_NAME
(decl
) == length_identifier_node
9637 && type_found
&& TYPE_ARRAY_P
(type_found
)
9638 && ! flag_emit_class_files
)
9640 tree length
= build_java_array_length_access
(where_found
);
9643 /* In case we're dealing with a static array, we need to
9644 initialize its class before the array length can be fetched. */
9645 if
(TREE_CODE
(where_found
) == VAR_DECL
&& FIELD_STATIC
(where_found
))
9647 build_static_field_ref
(where_found
);
9648 field_ref
= build_class_init
(DECL_CONTEXT
(where_found
), field_ref
);
9651 /* We might have been trying to resolve field.method(). In which
9652 case, the resolution is over and decl is the answer */
9653 else if
(JDECL_P
(decl
) && IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(decl
)) == decl
)
9655 else if
(JDECL_P
(decl
))
9658 type_found
= DECL_CONTEXT
(decl
);
9659 is_static
= FIELD_STATIC
(decl
);
9660 field_ref
= build_field_ref
((is_static ?
9661 NULL_TREE
: where_found
),
9662 type_found
, DECL_NAME
(decl
));
9663 if
(field_ref
== error_mark_node
)
9664 return error_mark_node
;
9666 field_ref
= maybe_build_class_init_for_field
(decl
, field_ref
);
9668 /* If we're looking at a static field, we may need to generate a
9669 class initialization for it. This can happen when the access
9670 looks like `field.ref', where `field' is a static field in an
9671 interface we implement. */
9672 if
(!flag_emit_class_files
9673 && TREE_CODE
(where_found
) == VAR_DECL
9674 && FIELD_STATIC
(where_found
))
9676 build_static_field_ref
(where_found
);
9677 field_ref
= build_class_init
(DECL_CONTEXT
(where_found
), field_ref
);
9686 *field_type
= (QUAL_DECL_TYPE
(decl
) ?
9687 QUAL_DECL_TYPE
(decl
) : TREE_TYPE
(decl
));
9691 /* If NODE is an access to a static field, strip out the class
9692 initialization part and return the field decl, otherwise, return
9696 extract_field_decl
(tree node
)
9698 if
(TREE_CODE
(node
) == COMPOUND_EXPR
)
9700 tree op1
= TREE_OPERAND
(node
, 1);
9701 if
(TREE_CODE
(op1
) == COMPOUND_EXPR
)
9703 tree call
= TREE_OPERAND
(op1
, 0);
9704 if
(TREE_CODE
(call
) == CALL_EXPR
9705 && TREE_CODE
(TREE_OPERAND
(call
, 0)) == ADDR_EXPR
9706 && (TREE_OPERAND
(TREE_OPERAND
(call
, 0), 0)
9707 == soft_initclass_node
))
9708 return TREE_OPERAND
(op1
, 1);
9710 else if
(JDECL_P
(op1
))
9716 /* 6.5.5.2: Qualified Expression Names */
9719 resolve_qualified_expression_name
(tree wfl
, tree
*found_decl
,
9720 tree
*where_found
, tree
*type_found
)
9722 int from_type
= 0; /* Field search initiated from a type */
9723 int from_super
= 0, from_cast
= 0, from_qualified_this
= 0;
9724 int previous_call_static
= 0;
9726 tree decl
= NULL_TREE
, type
= NULL_TREE
, q
;
9727 /* For certain for of inner class instantiation */
9728 tree saved_current
, saved_this
;
9729 #define RESTORE_THIS_AND_CURRENT_CLASS \
9730 { current_class
= saved_current
; current_this
= saved_this
;}
9732 *type_found
= *where_found
= NULL_TREE
;
9734 for
(q
= EXPR_WFL_QUALIFICATION
(wfl
); q
; q
= TREE_CHAIN
(q
))
9736 tree qual_wfl
= QUAL_WFL
(q
);
9737 tree ret_decl
; /* for EH checking */
9738 #ifdef USE_MAPPED_LOCATION
9739 source_location location
; /* for EH checking */
9741 int location
; /* for EH checking */
9744 /* 15.10.1 Field Access Using a Primary */
9745 switch
(TREE_CODE
(qual_wfl
))
9748 case NEW_CLASS_EXPR
:
9749 /* If the access to the function call is a non static field,
9750 build the code to access it. */
9751 if
(JDECL_P
(decl
) && !FIELD_STATIC
(decl
))
9753 decl
= maybe_access_field
(decl
, *where_found
,
9754 DECL_CONTEXT
(decl
));
9755 if
(decl
== error_mark_node
)
9759 /* And code for the function call */
9760 if
(complete_function_arguments
(qual_wfl
))
9763 /* We might have to setup a new current class and a new this
9764 for the search of an inner class, relative to the type of
9765 a expression resolved as `decl'. The current values are
9766 saved and restored shortly after */
9767 saved_current
= current_class
;
9768 saved_this
= current_this
;
9770 && (TREE_CODE
(qual_wfl
) == NEW_CLASS_EXPR
9771 || from_qualified_this
))
9773 /* If we still have `from_qualified_this', we have the form
9774 <T>.this.f() and we need to build <T>.this */
9775 if
(from_qualified_this
)
9777 decl
= build_access_to_thisn
(current_class
, type
, 0);
9778 decl
= java_complete_tree
(decl
);
9779 type
= TREE_TYPE
(TREE_TYPE
(decl
));
9781 current_class
= type
;
9782 current_this
= decl
;
9783 from_qualified_this
= 0;
9786 if
(from_super
&& TREE_CODE
(qual_wfl
) == CALL_EXPR
)
9787 CALL_USING_SUPER
(qual_wfl
) = 1;
9788 #ifdef USE_MAPPED_LOCATION
9789 location
= (TREE_CODE
(qual_wfl
) == CALL_EXPR
9790 ? EXPR_LOCATION
(TREE_OPERAND
(qual_wfl
, 0))
9791 : UNKNOWN_LOCATION
);
9793 location
= (TREE_CODE
(qual_wfl
) == CALL_EXPR ?
9794 EXPR_WFL_LINECOL
(TREE_OPERAND
(qual_wfl
, 0)) : 0);
9796 *where_found
= patch_method_invocation
(qual_wfl
, decl
, type
,
9798 &is_static
, &ret_decl
);
9800 if
(*where_found
== error_mark_node
)
9802 RESTORE_THIS_AND_CURRENT_CLASS
;
9805 *type_found
= type
= QUAL_DECL_TYPE
(*where_found
);
9807 *where_found
= force_evaluation_order
(*where_found
);
9809 /* If we're creating an inner class instance, check for that
9810 an enclosing instance is in scope */
9811 if
(TREE_CODE
(qual_wfl
) == NEW_CLASS_EXPR
9812 && INNER_ENCLOSING_SCOPE_CHECK
(type
))
9815 (qual_wfl
, "No enclosing instance for inner class %qs is in scope%s",
9816 lang_printable_name
(type
, 0),
9817 (!current_this ?
"" :
9818 "; an explicit one must be provided when creating this inner class"));
9819 RESTORE_THIS_AND_CURRENT_CLASS
;
9823 /* In case we had to change then to resolve a inner class
9824 instantiation using a primary qualified by a `new' */
9825 RESTORE_THIS_AND_CURRENT_CLASS
;
9827 #ifdef USE_MAPPED_LOCATION
9828 if
(location
!= UNKNOWN_LOCATION
)
9833 tree arguments
= NULL_TREE
;
9834 if
(TREE_CODE
(qual_wfl
) == CALL_EXPR
9835 && TREE_OPERAND
(qual_wfl
, 1) != NULL_TREE
)
9836 arguments
= TREE_VALUE
(TREE_OPERAND
(qual_wfl
, 1));
9837 check_thrown_exceptions
(location
, ret_decl
, arguments
);
9840 /* If the previous call was static and this one is too,
9841 build a compound expression to hold the two (because in
9842 that case, previous function calls aren't transported as
9843 forcoming function's argument. */
9844 if
(previous_call_static
&& is_static
)
9846 /* We must set CAN_COMPLETE_NORMALLY for the first call
9847 since it is done nowhere else. */
9848 CAN_COMPLETE_NORMALLY
(decl
) = 1;
9849 decl
= build2
(COMPOUND_EXPR
, TREE_TYPE
(*where_found
),
9850 decl
, *where_found
);
9851 TREE_SIDE_EFFECTS
(decl
) = 1;
9855 previous_call_static
= is_static
;
9856 decl
= *where_found
;
9861 case NEW_ARRAY_EXPR
:
9862 case NEW_ANONYMOUS_ARRAY_EXPR
:
9863 *where_found
= decl
= java_complete_tree
(qual_wfl
);
9864 if
(decl
== error_mark_node
)
9866 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9870 *where_found
= decl
= java_complete_tree
(qual_wfl
);
9871 if
(decl
== error_mark_node
)
9873 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9877 case CONDITIONAL_EXPR
:
9880 *where_found
= decl
= java_complete_tree
(qual_wfl
);
9881 if
(decl
== error_mark_node
)
9883 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9887 /* If the access to the function call is a non static field,
9888 build the code to access it. */
9889 if
(JDECL_P
(decl
) && !FIELD_STATIC
(decl
))
9891 decl
= maybe_access_field
(decl
, *where_found
, type
);
9892 if
(decl
== error_mark_node
)
9895 /* And code for the array reference expression */
9896 decl
= java_complete_tree
(qual_wfl
);
9897 if
(decl
== error_mark_node
)
9899 type
= QUAL_DECL_TYPE
(decl
);
9903 if
((decl
= java_complete_tree
(qual_wfl
)) == error_mark_node
)
9905 if
((type
= patch_string
(decl
)))
9907 *where_found
= QUAL_RESOLUTION
(q
) = decl
;
9908 *type_found
= type
= TREE_TYPE
(decl
);
9912 if
((decl
= java_complete_tree
(qual_wfl
)) == error_mark_node
)
9914 *where_found
= QUAL_RESOLUTION
(q
) = decl
;
9915 *type_found
= type
= TREE_TYPE
(decl
);
9919 /* Fix for -Wall Just go to the next statement. Don't
9924 /* If we fall here, we weren't processing a (static) function call. */
9925 previous_call_static
= 0;
9927 /* It can be the keyword THIS */
9928 if
(TREE_CODE
(qual_wfl
) == EXPR_WITH_FILE_LOCATION
9929 && EXPR_WFL_NODE
(qual_wfl
) == this_identifier_node
)
9934 (wfl
, "Keyword %<this%> used outside allowed context");
9937 if
(ctxp
->explicit_constructor_p
9938 && type
== current_class
)
9940 parse_error_context
(wfl
, "Can't reference %<this%> before the superclass constructor has been called");
9943 /* We have to generate code for intermediate access */
9944 if
(!from_type || TREE_TYPE
(TREE_TYPE
(current_this
)) == type
)
9946 *where_found
= decl
= current_this
;
9947 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
9949 /* We're trying to access the this from somewhere else. Make sure
9950 it's allowed before doing so. */
9953 if
(!enclosing_context_p
(type
, current_class
))
9955 char *p
= xstrdup
(lang_printable_name
(type
, 0));
9956 parse_error_context
(qual_wfl
, "Can't use variable %<%s.this%>: type %qs isn't an outer type of type %qs",
9958 lang_printable_name
(current_class
, 0));
9962 from_qualified_this
= 1;
9963 /* If there's nothing else after that, we need to
9964 produce something now, otherwise, the section of the
9965 code that needs to produce <T>.this will generate
9966 what is necessary. */
9967 if
(!TREE_CHAIN
(q
))
9969 decl
= build_access_to_thisn
(current_class
, type
, 0);
9970 *where_found
= decl
= java_complete_tree
(decl
);
9971 *type_found
= type
= TREE_TYPE
(decl
);
9979 /* 15.10.2 Accessing Superclass Members using SUPER */
9980 if
(TREE_CODE
(qual_wfl
) == EXPR_WITH_FILE_LOCATION
9981 && EXPR_WFL_NODE
(qual_wfl
) == super_identifier_node
)
9984 /* Check on the restricted use of SUPER */
9985 if
(METHOD_STATIC
(current_function_decl
)
9986 || current_class
== object_type_node
)
9989 (wfl
, "Keyword %<super%> used outside allowed context");
9992 /* Otherwise, treat SUPER as (SUPER_CLASS)THIS */
9993 node
= build_cast
(EXPR_WFL_LINECOL
(qual_wfl
),
9994 CLASSTYPE_SUPER
(current_class
),
9995 build_this
(EXPR_WFL_LINECOL
(qual_wfl
)));
9996 *where_found
= decl
= java_complete_tree
(node
);
9997 if
(decl
== error_mark_node
)
9999 *type_found
= type
= QUAL_DECL_TYPE
(decl
);
10000 from_super
= from_type
= 1;
10004 /* 15.13.1: Can't search for field name in packages, so we
10005 assume a variable/class name was meant. */
10006 if
(RESOLVE_PACKAGE_NAME_P
(qual_wfl
))
10009 if
((decl
= resolve_package
(wfl
, &q
, &name
)))
10012 *where_found
= decl
;
10014 check_pkg_class_access
(DECL_NAME
(decl
), qual_wfl
, true
, NULL
);
10016 /* We want to be absolutely sure that the class is laid
10017 out. We're going to search something inside it. */
10018 *type_found
= type
= TREE_TYPE
(decl
);
10019 layout_class
(type
);
10022 /* Fix them all the way down, if any are left. */
10025 list
= TREE_CHAIN
(q
);
10028 RESOLVE_PACKAGE_NAME_P
(QUAL_WFL
(list
)) = 0;
10029 list
= TREE_CHAIN
(list
);
10035 if
(from_super || from_cast
)
10036 parse_error_context
10037 ((from_cast ? qual_wfl
: wfl
),
10038 "No variable %qs defined in class %qs",
10039 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)),
10040 lang_printable_name
(type
, 0));
10042 parse_error_context
10043 (qual_wfl
, "Undefined variable or class name: %qs",
10044 IDENTIFIER_POINTER
(name
));
10049 /* We have a type name. It's been already resolved when the
10050 expression was qualified. */
10051 else if
(RESOLVE_TYPE_NAME_P
(qual_wfl
) && QUAL_RESOLUTION
(q
))
10053 decl
= QUAL_RESOLUTION
(q
);
10055 /* Sneak preview. If next we see a `new', we're facing a
10056 qualification which resulted in a type being selected
10057 instead of a field. Report the error. */
10059 && TREE_CODE
(TREE_PURPOSE
(TREE_CHAIN
(q
))) == NEW_CLASS_EXPR
)
10061 parse_error_context
(qual_wfl
, "Undefined variable %qs",
10062 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
10066 check_pkg_class_access
(DECL_NAME
(decl
), qual_wfl
, true
, NULL
);
10068 check_deprecation
(qual_wfl
, decl
);
10070 type
= TREE_TYPE
(decl
);
10073 /* We resolve an expression name */
10076 tree field_decl
= NULL_TREE
;
10078 /* If there exists an early resolution, use it. That occurs
10079 only once and we know that there are more things to
10080 come. Don't do that when processing something after SUPER
10081 (we need more thing to be put in place below */
10082 if
(!from_super
&& QUAL_RESOLUTION
(q
))
10084 decl
= QUAL_RESOLUTION
(q
);
10087 if
(TREE_CODE
(decl
) == FIELD_DECL
10088 || TREE_CODE
(decl
) == VAR_DECL
)
10090 if
(TREE_CODE
(decl
) == FIELD_DECL
10091 && !FIELD_STATIC
(decl
))
10094 *where_found
= current_this
;
10097 static_ref_err
(qual_wfl
, DECL_NAME
(decl
),
10104 *where_found
= TREE_TYPE
(decl
);
10105 if
(TREE_CODE
(*where_found
) == POINTER_TYPE
)
10106 *where_found
= TREE_TYPE
(*where_found
);
10108 if
(nested_field_access_p
(current_class
, decl
))
10109 decl
= build_nested_field_access
(qual_wfl
, decl
);
10113 *where_found
= TREE_TYPE
(decl
);
10114 if
(TREE_CODE
(*where_found
) == POINTER_TYPE
)
10115 *where_found
= TREE_TYPE
(*where_found
);
10120 /* Report and error if we're using a numerical literal as a
10121 qualifier. It can only be an INTEGER_CST. */
10122 else if
(TREE_CODE
(qual_wfl
) == INTEGER_CST
)
10124 parse_error_context
10125 (wfl
, "Can't use type %qs as a qualifier",
10126 lang_printable_name
(TREE_TYPE
(qual_wfl
), 0));
10130 /* We have to search for a field, knowing the type of its
10131 container. The flag FROM_TYPE indicates that we resolved
10132 the last member of the expression as a type name, which
10133 means that for the resolution of this field, we'll look
10134 for other errors than if it was resolved as a member of
10139 tree field_decl_type
; /* For layout */
10141 if
(!from_type
&& !JREFERENCE_TYPE_P
(type
))
10143 parse_error_context
10144 (qual_wfl
, "Attempt to reference field %qs in %<%s %s%>",
10145 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)),
10146 lang_printable_name
(type
, 0),
10147 IDENTIFIER_POINTER
(DECL_NAME
(decl
)));
10151 field_decl
= lookup_field_wrapper
(type
,
10152 EXPR_WFL_NODE
(qual_wfl
));
10154 /* Maybe what we're trying to access to is an inner
10155 class, only if decl is a TYPE_DECL. */
10156 if
(!field_decl
&& TREE_CODE
(decl
) == TYPE_DECL
)
10158 tree ptr
, inner_decl
;
10160 BUILD_PTR_FROM_NAME
(ptr
, EXPR_WFL_NODE
(qual_wfl
));
10161 inner_decl
= resolve_class
(decl
, ptr
, NULL_TREE
, qual_wfl
);
10164 check_inner_class_access
(inner_decl
, decl
, qual_wfl
);
10165 type
= TREE_TYPE
(inner_decl
);
10172 if
(field_decl
== NULL_TREE
)
10174 parse_error_context
10175 (qual_wfl
, "No variable %qs defined in type %qs",
10176 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(qual_wfl
)),
10177 GET_TYPE_NAME
(type
));
10180 if
(field_decl
== error_mark_node
)
10183 /* Layout the type of field_decl, since we may need
10184 it. Don't do primitive types or loaded classes. The
10185 situation of non primitive arrays may not handled
10186 properly here. FIXME */
10187 if
(TREE_CODE
(TREE_TYPE
(field_decl
)) == POINTER_TYPE
)
10188 field_decl_type
= TREE_TYPE
(TREE_TYPE
(field_decl
));
10190 field_decl_type
= TREE_TYPE
(field_decl
);
10191 if
(!JPRIMITIVE_TYPE_P
(field_decl_type
)
10192 && !CLASS_LOADED_P
(field_decl_type
)
10193 && !TYPE_ARRAY_P
(field_decl_type
))
10194 resolve_and_layout
(field_decl_type
, NULL_TREE
);
10196 /* Check on accessibility here */
10197 if
(not_accessible_p
(current_class
, field_decl
,
10198 *type_found
, from_super
))
10199 return not_accessible_field_error
(qual_wfl
,field_decl
);
10200 check_deprecation
(qual_wfl
, field_decl
);
10202 /* There are things to check when fields are accessed
10203 from type. There are no restrictions on a static
10204 declaration of the field when it is accessed from an
10206 is_static
= FIELD_STATIC
(field_decl
);
10207 if
(!from_super
&& from_type
10208 && !TYPE_INTERFACE_P
(type
)
10210 && (current_function_decl
10211 && METHOD_STATIC
(current_function_decl
)))
10213 static_ref_err
(qual_wfl
, EXPR_WFL_NODE
(qual_wfl
), type
);
10216 from_cast
= from_super
= 0;
10218 /* If it's an access from a type but isn't static, we
10219 make it relative to `this'. */
10220 if
(!is_static
&& from_type
)
10221 decl
= current_this
;
10223 /* If we need to generate something to get a proper
10224 handle on what this field is accessed from, do it
10228 decl
= maybe_access_field
(decl
, *where_found
, *type_found
);
10229 if
(decl
== error_mark_node
)
10233 /* We want to keep the location where we found it, and the
10235 *where_found
= decl
;
10236 *type_found
= type
;
10238 /* Generate the correct expression for field access from
10240 if
(from_qualified_this
)
10243 = build_nested_field_access
(qual_wfl
, field_decl
);
10244 from_qualified_this
= 0;
10247 /* If needed, generate accessors for static field access. */
10249 && FIELD_PRIVATE
(field_decl
)
10250 && flag_emit_class_files
10251 && nested_field_access_p
(current_class
, field_decl
))
10252 field_decl
= build_nested_field_access
(qual_wfl
, field_decl
);
10254 /* This is the decl found and eventually the next one to
10259 type
= QUAL_DECL_TYPE
(decl
);
10261 /* Sneak preview. If decl is qualified by a `new', report
10262 the error here to be accurate on the peculiar construct */
10264 && TREE_CODE
(TREE_PURPOSE
(TREE_CHAIN
(q
))) == NEW_CLASS_EXPR
10265 && !JREFERENCE_TYPE_P
(type
))
10267 parse_error_context
(qual_wfl
, "Attempt to reference field %<new%> in a %qs",
10268 lang_printable_name
(type
, 0));
10272 /* `q' might have changed due to a after package resolution
10273 re-qualification */
10277 *found_decl
= decl
;
10281 /* 6.6 Qualified name and access control. Returns 1 if MEMBER (a decl)
10282 can't be accessed from REFERENCE (a record type). If MEMBER
10283 features a protected access, we then use WHERE which, if non null,
10284 holds the type of MEMBER's access that is checked against
10285 6.6.2.1. This function should be used when decl is a field or a
10289 not_accessible_p
(tree reference
, tree member
, tree where
, int from_super
)
10291 int access_flag
= get_access_flags_from_decl
(member
);
10292 bool is_static
= false
;
10294 if
(TREE_CODE
(member
) == FIELD_DECL ||
10295 TREE_CODE
(member
) == VAR_DECL
)
10296 is_static
= FIELD_STATIC
(member
);
10298 is_static
= METHOD_STATIC
(member
);
10300 /* Access always granted for members declared public */
10301 if
(access_flag
& ACC_PUBLIC
)
10304 /* Check access on protected members */
10305 if
(access_flag
& ACC_PROTECTED
)
10307 /* Access granted if it occurs from within the package
10308 containing the class in which the protected member is
10310 if
(class_in_current_package
(DECL_CONTEXT
(member
)))
10313 /* If accessed with the form `super.member', then access is granted */
10317 /* If WHERE is active, access was made through a qualifier. For
10318 non-static members, access is granted if the type of the qualifier
10319 is or is a sublass of the type the access is made from (6.6.2.1.) */
10320 if
(where
&& !is_static
)
10324 if
(inherits_from_p
(where
, reference
))
10326 if
(INNER_CLASS_TYPE_P
(reference
))
10327 reference
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(reference
)));
10334 /* Otherwise, access is granted if occurring from within the class
10335 where member is declared, or a subclass of it. */
10338 if
(inherits_from_p
(reference
, DECL_CONTEXT
(member
)))
10340 if
(INNER_CLASS_TYPE_P
(reference
))
10341 reference
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(reference
)));
10348 /* Check access on private members. Access is granted only if it
10349 occurs from within the class in which it is declared -- that does
10350 it for innerclasses too. */
10351 if
(access_flag
& ACC_PRIVATE
)
10353 if
(reference
== DECL_CONTEXT
(member
) ||
10354 common_enclosing_context_p
(DECL_CONTEXT
(member
), reference
))
10359 /* Default access is permitted only when occurring from within the
10360 package in which the context (MEMBER) is declared. */
10361 return
!class_in_current_package
(DECL_CONTEXT
(member
));
10364 /* Test deprecated decl access. */
10366 check_deprecation
(tree wfl
, tree decl
)
10371 if
(! warn_deprecated
)
10374 /* We want to look at the element type of arrays here, so we strip
10375 all surrounding array types. */
10376 if
(TYPE_ARRAY_P
(TREE_TYPE
(decl
)))
10378 elt
= TREE_TYPE
(decl
);
10379 while
(TYPE_ARRAY_P
(elt
))
10380 elt
= TYPE_ARRAY_ELEMENT
(elt
);
10381 /* We'll end up with a pointer type, so we use TREE_TYPE to go
10383 decl
= TYPE_NAME
(TREE_TYPE
(elt
));
10385 file
= DECL_SOURCE_FILE
(decl
);
10387 /* Complain if the field is deprecated and the file it was defined
10388 in isn't compiled at the same time the file which contains its
10390 if
(DECL_DEPRECATED
(decl
)
10391 && !IS_A_COMMAND_LINE_FILENAME_P
(get_identifier
(file
)))
10394 switch
(TREE_CODE
(decl
))
10396 case FUNCTION_DECL
:
10404 parse_warning_context
(wfl
, "The class %qs has been deprecated",
10405 IDENTIFIER_POINTER
(DECL_NAME
(decl
)));
10410 /* Don't issue a message if the context as been deprecated as a
10412 if
(! CLASS_DEPRECATED
(TYPE_NAME
(DECL_CONTEXT
(decl
))))
10413 parse_warning_context
10414 (wfl
, "The %s %qs in class %qs has been deprecated",
10415 the
, lang_printable_name
(decl
, 0),
10416 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(decl
)))));
10420 /* Returns 1 if class was declared in the current package, 0 otherwise */
10422 static GTY
(()) tree cicp_cache
;
10424 class_in_current_package
(tree class
)
10426 int qualified_flag
;
10429 if
(cicp_cache
== class
)
10432 qualified_flag
= QUALIFIED_P
(DECL_NAME
(TYPE_NAME
(class
)));
10434 /* If the current package is empty and the name of CLASS is
10435 qualified, class isn't in the current package. If there is a
10436 current package and the name of the CLASS is not qualified, class
10437 isn't in the current package */
10438 if
((!ctxp
->package
&& qualified_flag
) ||
(ctxp
->package
&& !qualified_flag
))
10441 /* If there is not package and the name of CLASS isn't qualified,
10442 they belong to the same unnamed package */
10443 if
(!ctxp
->package
&& !qualified_flag
)
10446 /* Compare the left part of the name of CLASS with the package name */
10447 split_qualified_name
(&left
, NULL
, DECL_NAME
(TYPE_NAME
(class
)));
10448 if
(ctxp
->package
== left
)
10450 cicp_cache
= class
;
10456 /* This function may generate code to access DECL from WHERE. This is
10457 done only if certain conditions meet. */
10460 maybe_access_field
(tree decl
, tree where
, tree type
)
10462 if
(TREE_CODE
(decl
) == FIELD_DECL
&& decl
!= current_this
10463 && !FIELD_STATIC
(decl
))
10464 decl
= build_field_ref
(where ? where
: current_this
,
10465 (type ? type
: DECL_CONTEXT
(decl
)),
10470 /* Build a method invocation, by patching PATCH. If non NULL
10471 and according to the situation, PRIMARY and WHERE may be
10472 used. IS_STATIC is set to 1 if the invoked function is static. */
10475 patch_method_invocation
(tree patch
, tree primary
, tree where
, int from_super
,
10476 int *is_static
, tree
*ret_decl
)
10478 tree wfl
= TREE_OPERAND
(patch
, 0);
10479 tree args
= TREE_OPERAND
(patch
, 1);
10480 tree name
= EXPR_WFL_NODE
(wfl
);
10482 int is_static_flag
= 0;
10483 int is_super_init
= 0;
10484 tree this_arg
= NULL_TREE
;
10485 int is_array_clone_call
= 0;
10487 /* Should be overridden if everything goes well. Otherwise, if
10488 something fails, it should keep this value. It stop the
10489 evaluation of a bogus assignment. See java_complete_tree,
10490 MODIFY_EXPR: for the reasons why we sometimes want to keep on
10491 evaluating an assignment */
10492 TREE_TYPE
(patch
) = error_mark_node
;
10494 /* Since lookup functions are messing with line numbers, save the
10496 java_parser_context_save_global
();
10498 /* 15.11.1: Compile-Time Step 1: Determine Class or Interface to Search */
10500 /* Resolution of qualified name, excluding constructors */
10501 if
(QUALIFIED_P
(name
) && !CALL_CONSTRUCTOR_P
(patch
))
10503 tree identifier
, identifier_wfl
, type
, resolved
;
10504 /* Extract the last IDENTIFIER of the qualified
10505 expression. This is a wfl and we will use it's location
10506 data during error report. */
10507 identifier_wfl
= cut_identifier_in_qualified
(wfl
);
10508 identifier
= EXPR_WFL_NODE
(identifier_wfl
);
10510 /* Given the context, IDENTIFIER is syntactically qualified
10511 as a MethodName. We need to qualify what's before */
10512 qualify_ambiguous_name
(wfl
);
10513 resolved
= resolve_field_access
(wfl
, NULL
, NULL
);
10515 if
(TREE_CODE
(resolved
) == VAR_DECL
&& FIELD_STATIC
(resolved
)
10516 && FIELD_FINAL
(resolved
)
10517 && !inherits_from_p
(DECL_CONTEXT
(resolved
), current_class
)
10518 && !flag_emit_class_files
)
10519 resolved
= build_class_init
(DECL_CONTEXT
(resolved
), resolved
);
10521 if
(resolved
== error_mark_node
)
10522 PATCH_METHOD_RETURN_ERROR
();
10524 type
= GET_SKIP_TYPE
(resolved
);
10525 resolve_and_layout
(type
, NULL_TREE
);
10527 if
(JPRIMITIVE_TYPE_P
(type
))
10529 parse_error_context
10531 "Can't invoke a method on primitive type %qs",
10532 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(type
))));
10533 PATCH_METHOD_RETURN_ERROR
();
10536 list
= lookup_method_invoke
(0, identifier_wfl
, type
, identifier
, args
);
10537 args
= nreverse
(args
);
10539 /* We're resolving a call from a type */
10540 if
(TREE_CODE
(resolved
) == TYPE_DECL
)
10542 if
(CLASS_INTERFACE
(resolved
))
10544 parse_error_context
10546 "Can't make static reference to method %qs in interface %qs",
10547 IDENTIFIER_POINTER
(identifier
),
10548 IDENTIFIER_POINTER
(name
));
10549 PATCH_METHOD_RETURN_ERROR
();
10551 if
(list
&& !METHOD_STATIC
(list
))
10553 char *fct_name
= xstrdup
(lang_printable_name
(list
, 2));
10554 parse_error_context
10556 "Can't make static reference to method %<%s %s%> in class %qs",
10557 lang_printable_name
(TREE_TYPE
(TREE_TYPE
(list
)), 0),
10558 fct_name
, IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(type
))));
10560 PATCH_METHOD_RETURN_ERROR
();
10564 this_arg
= primary
= resolved
;
10566 if
(TYPE_ARRAY_P
(type
) && identifier
== get_identifier
("clone"))
10567 is_array_clone_call
= 1;
10569 /* IDENTIFIER_WFL will be used to report any problem further */
10570 wfl
= identifier_wfl
;
10572 /* Resolution of simple names, names generated after a primary: or
10576 tree class_to_search
= NULL_TREE
;
10577 int lc
; /* Looking for Constructor */
10579 /* We search constructor in their target class */
10580 if
(CALL_CONSTRUCTOR_P
(patch
))
10582 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
10583 class_to_search
= EXPR_WFL_NODE
(wfl
);
10584 else if
(EXPR_WFL_NODE
(TREE_OPERAND
(patch
, 0)) ==
10585 this_identifier_node
)
10586 class_to_search
= NULL_TREE
;
10587 else if
(EXPR_WFL_NODE
(TREE_OPERAND
(patch
, 0)) ==
10588 super_identifier_node
)
10591 if
(CLASSTYPE_SUPER
(current_class
))
10593 DECL_NAME
(TYPE_NAME
(CLASSTYPE_SUPER
(current_class
)));
10596 parse_error_context
(wfl
, "Can't invoke super constructor on java.lang.Object");
10597 PATCH_METHOD_RETURN_ERROR
();
10601 /* Class to search is NULL if we're searching the current one */
10602 if
(class_to_search
)
10604 class_to_search
= resolve_and_layout
(class_to_search
, wfl
);
10606 if
(!class_to_search
)
10608 parse_error_context
10609 (wfl
, "Class %qs not found in type declaration",
10610 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
10611 PATCH_METHOD_RETURN_ERROR
();
10614 /* Can't instantiate an abstract class, but we can
10615 invoke it's constructor. It's use within the `new'
10616 context is denied here. */
10617 if
(CLASS_ABSTRACT
(class_to_search
)
10618 && TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
10620 parse_error_context
10621 (wfl
, "Class %qs is an abstract class. It can't be instantiated",
10622 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(wfl
)));
10623 PATCH_METHOD_RETURN_ERROR
();
10626 class_to_search
= TREE_TYPE
(class_to_search
);
10629 class_to_search
= current_class
;
10632 /* This is a regular search in the local class, unless an
10633 alternate class is specified. */
10636 if
(where
!= NULL_TREE
)
10637 class_to_search
= where
;
10638 else if
(QUALIFIED_P
(name
))
10639 class_to_search
= current_class
;
10642 class_to_search
= current_class
;
10646 if
(has_method
(class_to_search
, name
))
10648 if
(! INNER_CLASS_TYPE_P
(class_to_search
))
10650 parse_error_context
(wfl
,
10651 "No method named %qs in scope",
10652 IDENTIFIER_POINTER
(name
));
10653 PATCH_METHOD_RETURN_ERROR
();
10656 = TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(class_to_search
)));
10662 /* NAME is a simple identifier or comes from a primary. Search
10663 in the class whose declaration contain the method being
10665 resolve_and_layout
(class_to_search
, NULL_TREE
);
10667 list
= lookup_method_invoke
(lc
, wfl
, class_to_search
, name
, args
);
10668 /* Don't continue if no method were found, as the next statement
10669 can't be executed then. */
10671 PATCH_METHOD_RETURN_ERROR
();
10673 if
(TYPE_ARRAY_P
(class_to_search
)
10674 && DECL_NAME
(list
) == get_identifier
("clone"))
10675 is_array_clone_call
= 1;
10677 /* Check for static reference if non static methods */
10678 if
(check_for_static_method_reference
(wfl
, patch
, list
,
10679 class_to_search
, primary
))
10680 PATCH_METHOD_RETURN_ERROR
();
10682 /* Check for inner classes creation from illegal contexts */
10683 if
(lc
&& (INNER_CLASS_TYPE_P
(class_to_search
)
10684 && !CLASS_STATIC
(TYPE_NAME
(class_to_search
)))
10685 && INNER_ENCLOSING_SCOPE_CHECK
(class_to_search
)
10686 && !DECL_INIT_P
(current_function_decl
))
10688 parse_error_context
10689 (wfl
, "No enclosing instance for inner class %qs is in scope%s",
10690 lang_printable_name
(class_to_search
, 0),
10691 (!current_this ?
"" :
10692 "; an explicit one must be provided when creating this inner class"));
10693 PATCH_METHOD_RETURN_ERROR
();
10696 /* Non static methods are called with the current object extra
10697 argument. If patch a `new TYPE()', the argument is the value
10698 returned by the object allocator. If method is resolved as a
10699 primary, use the primary otherwise use the current THIS. */
10700 args
= nreverse
(args
);
10701 if
(TREE_CODE
(patch
) != NEW_CLASS_EXPR
)
10703 this_arg
= primary ? primary
: current_this
;
10705 /* If we're using an access method, things are different.
10706 There are two family of cases:
10708 1) We're not generating bytecodes:
10710 - LIST is non static. It's invocation is transformed from
10711 x(a1,...,an) into this$<n>.x(a1,....an).
10712 - LIST is static. It's invocation is transformed from
10713 x(a1,...,an) into TYPE_OF(this$<n>).x(a1,....an)
10715 2) We're generating bytecodes:
10717 - LIST is non static. It's invocation is transformed from
10718 x(a1,....,an) into access$<n>(this$<n>,a1,...,an).
10719 - LIST is static. It's invocation is transformed from
10720 x(a1,....,an) into TYPE_OF(this$<n>).x(a1,....an).
10722 Of course, this$<n> can be arbitrarily complex, ranging from
10723 this$0 (the immediate outer context) to
10724 access$0(access$0(...(this$0))).
10726 maybe_use_access_method returns a nonzero value if the
10727 this_arg has to be moved into the (then generated) stub
10728 argument list. In the meantime, the selected function
10729 might have be replaced by a generated stub. */
10731 maybe_use_access_method
(is_super_init
, &list
, &this_arg
))
10733 args
= tree_cons
(NULL_TREE
, this_arg
, args
);
10734 this_arg
= NULL_TREE
; /* So it doesn't get chained twice */
10739 /* Merge point of all resolution schemes. If we have nothing, this
10740 is an error, already signaled */
10742 PATCH_METHOD_RETURN_ERROR
();
10744 /* Check accessibility, position the is_static flag, build and
10746 if
(not_accessible_p
(DECL_CONTEXT
(current_function_decl
), list
,
10747 (primary ? TREE_TYPE
(TREE_TYPE
(primary
)) :
10748 NULL_TREE
), from_super
)
10749 /* Calls to clone() on array types are permitted as a special-case. */
10750 && !is_array_clone_call
)
10752 const char *const fct_name
= IDENTIFIER_POINTER
(DECL_NAME
(list
));
10753 const char *const access
=
10754 accessibility_string
(get_access_flags_from_decl
(list
));
10755 const char *const klass
=
10756 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(list
))));
10757 const char *const refklass
=
10758 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(current_class
)));
10759 const char *const what
= (DECL_CONSTRUCTOR_P
(list
)
10760 ?
"constructor" : "method");
10761 parse_error_context
(wfl
,
10762 "Can't access %s %s %<%s.%s%> from %qs",
10763 access
, what
, klass
, fct_name
, refklass
);
10764 PATCH_METHOD_RETURN_ERROR
();
10767 /* Deprecation check: check whether the method being invoked or the
10768 instance-being-created's type are deprecated. */
10769 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
10770 check_deprecation
(wfl
, TYPE_NAME
(DECL_CONTEXT
(list
)));
10771 check_deprecation
(wfl
, list
);
10773 /* If invoking a innerclass constructor, there are hidden parameters
10775 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
10776 && PURE_INNER_CLASS_TYPE_P
(DECL_CONTEXT
(list
)))
10778 /* And make sure we add the accessed local variables to be saved
10779 in field aliases. */
10780 args
= build_alias_initializer_parameter_list
10781 (AIPL_FUNCTION_CTOR_INVOCATION
, DECL_CONTEXT
(list
), args
, NULL
);
10783 /* Secretly pass the current_this/primary as a second argument */
10784 if
(primary || current_this
)
10787 tree this_type
= (current_this ?
10788 TREE_TYPE
(TREE_TYPE
(current_this
)) : NULL_TREE
);
10789 /* Method's (list) enclosing context */
10790 tree mec
= DECL_CONTEXT
(TYPE_NAME
(DECL_CONTEXT
(list
)));
10791 /* If we have a primary, use it. */
10793 extra_arg
= primary
;
10794 /* The current `this' is an inner class but isn't a direct
10795 enclosing context for the inner class we're trying to
10796 create. Build an access to the proper enclosing context
10798 else if
(current_this
&& PURE_INNER_CLASS_TYPE_P
(this_type
)
10799 && this_type
!= TREE_TYPE
(mec
))
10802 extra_arg
= build_access_to_thisn
(current_class
,
10803 TREE_TYPE
(mec
), 0);
10804 extra_arg
= java_complete_tree
(extra_arg
);
10806 /* Otherwise, just use the current `this' as an enclosing
10809 extra_arg
= current_this
;
10810 args
= tree_cons
(NULL_TREE
, extra_arg
, args
);
10813 args
= tree_cons
(NULL_TREE
, integer_zero_node
, args
);
10816 /* This handles the situation where a constructor invocation needs
10817 to have an enclosing context passed as a second parameter (the
10818 constructor is one of an inner class). */
10819 if
((is_super_init ||
10820 (TREE_CODE
(patch
) == CALL_EXPR
&& name
== this_identifier_node
))
10821 && PURE_INNER_CLASS_TYPE_P
(DECL_CONTEXT
(list
)))
10823 tree dest
= TYPE_NAME
(DECL_CONTEXT
(list
));
10825 build_access_to_thisn
(current_class
, DECL_CONTEXT
(dest
), 0);
10826 extra_arg
= java_complete_tree
(extra_arg
);
10827 args
= tree_cons
(NULL_TREE
, extra_arg
, args
);
10830 is_static_flag
= METHOD_STATIC
(list
);
10831 if
(! is_static_flag
&& this_arg
!= NULL_TREE
)
10832 args
= tree_cons
(NULL_TREE
, this_arg
, args
);
10834 /* In the context of an explicit constructor invocation, we can't
10835 invoke any method relying on `this'. Exceptions are: we're
10836 invoking a static function, primary exists and is not the current
10837 this, we're creating a new object. */
10838 if
(ctxp
->explicit_constructor_p
10840 && (!primary || primary
== current_this
)
10841 && (TREE_CODE
(patch
) != NEW_CLASS_EXPR
))
10843 parse_error_context
(wfl
, "Can't reference %<this%> before the superclass constructor has been called");
10844 PATCH_METHOD_RETURN_ERROR
();
10846 java_parser_context_restore_global
();
10848 *is_static
= is_static_flag
;
10849 /* Sometimes, we want the decl of the selected method. Such as for
10853 patch
= patch_invoke
(patch
, list
, args
);
10855 /* Now is a good time to insert the call to finit$ */
10856 if
(is_super_init
&& CLASS_HAS_FINIT_P
(current_class
))
10858 tree finit_parms
, finit_call
;
10860 /* Prepare to pass hidden parameters to finit$, if any. */
10861 finit_parms
= build_alias_initializer_parameter_list
10862 (AIPL_FUNCTION_FINIT_INVOCATION
, current_class
, NULL_TREE
, NULL
);
10865 build_method_invocation
(build_wfl_node
(finit_identifier_node
),
10868 /* Generate the code used to initialize fields declared with an
10869 initialization statement and build a compound statement along
10870 with the super constructor invocation. */
10871 CAN_COMPLETE_NORMALLY
(patch
) = 1;
10872 patch
= build2
(COMPOUND_EXPR
, void_type_node
, patch
,
10873 java_complete_tree
(finit_call
));
10878 /* Check that we're not trying to do a static reference to a method in
10879 non static method. Return 1 if it's the case, 0 otherwise. */
10882 check_for_static_method_reference
(tree wfl
, tree node
, tree method
,
10883 tree where
, tree primary
)
10885 if
(METHOD_STATIC
(current_function_decl
)
10886 && !METHOD_STATIC
(method
) && !primary
&& !CALL_CONSTRUCTOR_P
(node
))
10888 char *fct_name
= xstrdup
(lang_printable_name
(method
, 0));
10889 parse_error_context
10890 (wfl
, "Can't make static reference to method %<%s %s%> in class %qs",
10891 lang_printable_name
(TREE_TYPE
(TREE_TYPE
(method
)), 0), fct_name
,
10892 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(where
))));
10899 /* Fix the invocation of *MDECL if necessary in the case of a
10900 invocation from an inner class. *THIS_ARG might be modified
10901 appropriately and an alternative access to *MDECL might be
10905 maybe_use_access_method
(int is_super_init
, tree
*mdecl
, tree
*this_arg
)
10908 tree md
= *mdecl
, ta
= *this_arg
;
10910 int non_static_context
= !METHOD_STATIC
(md
);
10913 || DECL_CONTEXT
(md
) == current_class
10914 ||
!PURE_INNER_CLASS_TYPE_P
(current_class
)
10915 || DECL_FINIT_P
(md
)
10916 || DECL_INSTINIT_P
(md
))
10919 /* If we're calling a method found in an enclosing class, generate
10920 what it takes to retrieve the right this. Don't do that if we're
10921 invoking a static method. Note that if MD's type is unrelated to
10922 CURRENT_CLASS, then the current this can be used. */
10924 if
(non_static_context
&& DECL_CONTEXT
(md
) != object_type_node
)
10926 ctx
= TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(current_class
)));
10927 if
(inherits_from_p
(ctx
, DECL_CONTEXT
(md
)))
10929 ta
= build_current_thisn
(current_class
);
10930 ta
= build_wfl_node
(ta
);
10937 maybe_build_thisn_access_method
(type
);
10938 if
(inherits_from_p
(type
, DECL_CONTEXT
(md
)))
10940 ta
= build_access_to_thisn
(ctx
, type
, 0);
10943 type
= (DECL_CONTEXT
(TYPE_NAME
(type
)) ?
10944 TREE_TYPE
(DECL_CONTEXT
(TYPE_NAME
(type
))) : NULL_TREE
);
10947 ta
= java_complete_tree
(ta
);
10950 /* We might have to use an access method to get to MD. We can
10951 break the method access rule as far as we're not generating
10953 if
(METHOD_PRIVATE
(md
) && flag_emit_class_files
)
10955 md
= build_outer_method_access_method
(md
);
10962 /* Returning a nonzero value indicates we were doing a non static
10963 method invocation that is now a static invocation. It will have
10964 callee displace `this' to insert it in the regular argument
10966 return
(non_static_context
&& to_return
);
10969 /* Patch an invoke expression METHOD and ARGS, based on its invocation
10973 patch_invoke
(tree patch
, tree method
, tree args
)
10976 tree original_call
, t
, ta
;
10977 tree check
= NULL_TREE
;
10979 /* Last step for args: convert build-in types. If we're dealing with
10980 a new TYPE() type call, the first argument to the constructor
10981 isn't found in the incoming argument list, but delivered by
10983 t
= TYPE_ARG_TYPES
(TREE_TYPE
(method
));
10984 if
(TREE_CODE
(patch
) == NEW_CLASS_EXPR
)
10985 t
= TREE_CHAIN
(t
);
10986 for
(ta
= args
; t
!= end_params_node
&& ta
;
10987 t
= TREE_CHAIN
(t
), ta
= TREE_CHAIN
(ta
))
10988 if
(JPRIMITIVE_TYPE_P
(TREE_TYPE
(TREE_VALUE
(ta
))) &&
10989 TREE_TYPE
(TREE_VALUE
(ta
)) != TREE_VALUE
(t
))
10990 TREE_VALUE
(ta
) = convert
(TREE_VALUE
(t
), TREE_VALUE
(ta
));
10992 /* Resolve unresolved returned type issues */
10993 t
= TREE_TYPE
(TREE_TYPE
(method
));
10994 if
(TREE_CODE
(t
) == POINTER_TYPE
&& !CLASS_LOADED_P
(TREE_TYPE
(t
)))
10995 resolve_and_layout
(TREE_TYPE
(t
), NULL
);
10997 if
(flag_emit_class_files
)
11001 switch
(invocation_mode
(method
, CALL_USING_SUPER
(patch
)))
11003 case INVOKE_VIRTUAL
:
11004 dtable
= invoke_build_dtable
(0, args
);
11005 func
= build_invokevirtual
(dtable
, method
);
11008 case INVOKE_NONVIRTUAL
:
11009 /* If the object for the method call is null, we throw an
11010 exception. We don't do this if the object is the current
11011 method's `this'. In other cases we just rely on an
11012 optimization pass to eliminate redundant checks. */
11013 if
(TREE_VALUE
(args
) != current_this
)
11015 /* We use a save_expr here to make sure we only evaluate
11016 the new `self' expression once. */
11017 tree save_arg
= save_expr
(TREE_VALUE
(args
));
11018 TREE_VALUE
(args
) = save_arg
;
11019 check
= java_check_reference
(save_arg
, 1);
11021 /* Fall through. */
11024 case INVOKE_STATIC
:
11026 tree signature
= build_java_signature
(TREE_TYPE
(method
));
11027 func
= build_known_method_ref
(method
, TREE_TYPE
(method
),
11028 DECL_CONTEXT
(method
),
11033 case INVOKE_INTERFACE
:
11034 dtable
= invoke_build_dtable
(1, args
);
11035 func
= build_invokeinterface
(dtable
, method
);
11042 /* Ensure self_type is initialized, (invokestatic). FIXME */
11043 func
= build1
(NOP_EXPR
, build_pointer_type
(TREE_TYPE
(method
)), func
);
11046 TREE_TYPE
(patch
) = TREE_TYPE
(TREE_TYPE
(method
));
11047 TREE_OPERAND
(patch
, 0) = func
;
11048 TREE_OPERAND
(patch
, 1) = args
;
11049 patch
= check_for_builtin
(method
, patch
);
11050 original_call
= patch
;
11052 /* We're processing a `new TYPE ()' form. New is called and its
11053 returned value is the first argument to the constructor. We build
11054 a COMPOUND_EXPR and use saved expression so that the overall NEW
11055 expression value is a pointer to a newly created and initialized
11057 if
(TREE_CODE
(original_call
) == NEW_CLASS_EXPR
)
11059 tree class
= DECL_CONTEXT
(method
);
11060 tree c1
, saved_new
, new
;
11063 if
(flag_emit_class_files
)
11065 TREE_TYPE
(patch
) = build_pointer_type
(class
);
11068 if
(!TYPE_SIZE
(class
))
11069 safe_layout_class
(class
);
11071 (class_has_finalize_method
(class
) ? alloc_object_node
11072 : alloc_no_finalizer_node
);
11073 new
= build3
(CALL_EXPR
, promote_type
(class
),
11074 build_address_of
(alloc_node
),
11075 build_tree_list
(NULL_TREE
, build_class_ref
(class
)),
11077 saved_new
= save_expr
(new
);
11078 c1
= build_tree_list
(NULL_TREE
, saved_new
);
11079 TREE_CHAIN
(c1
) = TREE_OPERAND
(original_call
, 1);
11080 TREE_OPERAND
(original_call
, 1) = c1
;
11081 TREE_SET_CODE
(original_call
, CALL_EXPR
);
11082 patch
= build2
(COMPOUND_EXPR
, TREE_TYPE
(new
), patch
, saved_new
);
11085 /* If CHECK is set, then we are building a check to see if the object
11087 if
(check
!= NULL_TREE
)
11089 /* We have to call force_evaluation_order now because creating a
11090 COMPOUND_EXPR wraps the arg list in a way that makes it
11091 unrecognizable by force_evaluation_order later. Yuk. */
11092 patch
= build2
(COMPOUND_EXPR
, TREE_TYPE
(patch
), check
,
11093 force_evaluation_order
(patch
));
11094 TREE_SIDE_EFFECTS
(patch
) = 1;
11097 /* In order to be able to modify PATCH later, we SAVE_EXPR it and
11098 put it as the first expression of a COMPOUND_EXPR. The second
11099 expression being an empty statement to be later patched if
11100 necessary. We remember a TREE_LIST (the PURPOSE is the method,
11101 the VALUE is the compound) in a hashtable and return a
11102 COMPOUND_EXPR built so that the result of the evaluation of the
11103 original PATCH node is returned. */
11104 if
(STATIC_CLASS_INIT_OPT_P
()
11105 && current_function_decl
&& METHOD_STATIC
(method
))
11108 tree fndecl
= current_function_decl
;
11109 /* We have to call force_evaluation_order now because creating a
11110 COMPOUND_EXPR wraps the arg list in a way that makes it
11111 unrecognizable by force_evaluation_order later. Yuk. */
11112 tree save
= force_evaluation_order
(patch
);
11113 tree type
= TREE_TYPE
(patch
);
11115 patch
= build2
(COMPOUND_EXPR
, type
, save
, build_java_empty_stmt
());
11116 list
= tree_cons
(method
, patch
,
11117 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND
(fndecl
));
11119 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND
(fndecl
) = list
;
11121 patch
= build2
(COMPOUND_EXPR
, type
, patch
, save
);
11128 invocation_mode
(tree method
, int super
)
11130 int access
= get_access_flags_from_decl
(method
);
11133 return INVOKE_SUPER
;
11135 if
(access
& ACC_STATIC
)
11136 return INVOKE_STATIC
;
11138 /* We have to look for a constructor before we handle nonvirtual
11139 calls; otherwise the constructor will look nonvirtual. */
11140 if
(DECL_CONSTRUCTOR_P
(method
))
11141 return INVOKE_STATIC
;
11143 if
(access
& ACC_PRIVATE
)
11144 return INVOKE_NONVIRTUAL
;
11146 /* Binary compatibility: just because it's final today, that doesn't
11147 mean it'll be final tomorrow. */
11148 if
(! flag_indirect_dispatch
11149 || DECL_CONTEXT
(method
) == object_type_node
)
11151 if
(access
& ACC_FINAL
)
11152 return INVOKE_NONVIRTUAL
;
11154 if
(CLASS_FINAL
(TYPE_NAME
(DECL_CONTEXT
(method
))))
11155 return INVOKE_NONVIRTUAL
;
11158 if
(CLASS_INTERFACE
(TYPE_NAME
(DECL_CONTEXT
(method
))))
11159 return INVOKE_INTERFACE
;
11161 return INVOKE_VIRTUAL
;
11164 /* Retrieve a refined list of matching methods. It covers the step
11165 15.11.2 (Compile-Time Step 2) */
11168 lookup_method_invoke
(int lc
, tree cl
, tree class
, tree name
, tree arg_list
)
11170 tree atl
= end_params_node
; /* Arg Type List */
11171 tree method
, signature
, list
, node
;
11172 const char *candidates
; /* Used for error report */
11175 /* Fix the arguments */
11176 for
(node
= arg_list
; node
; node
= TREE_CHAIN
(node
))
11178 tree current_arg
= TREE_TYPE
(TREE_VALUE
(node
));
11179 /* Non primitive type may have to be resolved */
11180 if
(!JPRIMITIVE_TYPE_P
(current_arg
))
11181 resolve_and_layout
(current_arg
, NULL_TREE
);
11183 if
(TREE_CODE
(current_arg
) == RECORD_TYPE
)
11184 current_arg
= promote_type
(current_arg
);
11185 atl
= tree_cons
(NULL_TREE
, current_arg
, atl
);
11188 /* Presto. If we're dealing with an anonymous class and a
11189 constructor call, generate the right constructor now, since we
11190 know the arguments' types. */
11192 if
(lc
&& ANONYMOUS_CLASS_P
(class
))
11194 tree mdecl
= craft_constructor
(TYPE_NAME
(class
), atl
);
11195 /* The anonymous class may have already been laid out, so make sure
11196 the new constructor is laid out here. */
11197 layout_class_method
(class
, CLASSTYPE_SUPER
(class
), mdecl
, NULL_TREE
);
11200 /* Find all candidates and then refine the list, searching for the
11201 most specific method. */
11202 list
= find_applicable_accessible_methods_list
(lc
, class
, name
, atl
);
11203 list
= find_most_specific_methods_list
(list
);
11204 if
(list
&& !TREE_CHAIN
(list
))
11205 return TREE_VALUE
(list
);
11207 /* Issue an error. List candidates if any. Candidates are listed
11208 only if accessible (non accessible methods may end-up here for
11209 the sake of a better error report). */
11214 obstack_grow
(&temporary_obstack
, ". Candidates are:\n", 18);
11215 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
11217 tree cm
= TREE_VALUE
(current
);
11218 char string [4096];
11219 if
(!cm || not_accessible_p
(class
, cm
, NULL_TREE
, 0))
11222 (string, " '%s' in '%s'%s",
11223 get_printable_method_name
(cm
),
11224 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(DECL_CONTEXT
(cm
)))),
11225 (TREE_CHAIN
(current
) ?
"\n" : ""));
11226 obstack_grow
(&temporary_obstack
, string, strlen
(string));
11228 obstack_1grow
(&temporary_obstack
, '\0');
11229 candidates
= obstack_finish
(&temporary_obstack
);
11231 /* Issue the error message */
11232 method
= make_node
(FUNCTION_TYPE
);
11233 TYPE_ARG_TYPES
(method
) = atl
;
11234 signature
= build_java_argument_signature
(method
);
11235 dup
= xstrdup
(lang_printable_name
(class
, 0));
11236 parse_error_context
(cl
, "Can't find %s %<%s(%s)%> in type %qs%s",
11237 (lc ?
"constructor" : "method"),
11238 (lc ? dup
: IDENTIFIER_POINTER
(name
)),
11239 IDENTIFIER_POINTER
(signature
), dup
,
11240 (candidates ? candidates
: ""));
11245 /* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
11246 when we're looking for a constructor. */
11249 find_applicable_accessible_methods_list
(int lc
, tree class
, tree name
,
11252 static htab_t searched_classes
;
11253 static int search_not_done
= 0;
11254 tree list
= NULL_TREE
, all_list
= NULL_TREE
;
11258 /* Check the hash table to determine if this class has been searched
11260 if
(searched_classes
)
11262 if
(htab_find
(searched_classes
, class
) != NULL
)
11267 searched_classes
= htab_create
(10, htab_hash_pointer
,
11268 htab_eq_pointer
, NULL
);
11272 *htab_find_slot
(searched_classes
, class
, INSERT
) = class
;
11274 if
(!CLASS_LOADED_P
(class
))
11276 load_class
(class
, 1);
11277 safe_layout_class
(class
);
11280 /* Search interfaces */
11281 if
(TREE_CODE
(TYPE_NAME
(class
)) == TYPE_DECL
11282 && CLASS_INTERFACE
(TYPE_NAME
(class
)))
11284 search_applicable_methods_list
(lc
, TYPE_METHODS
(class
),
11285 name
, arglist
, &list
, &all_list
);
11286 for
(i
= 1; BINFO_BASE_ITERATE
(TYPE_BINFO
(class
), i
, base_binfo
); i
++)
11288 tree t
= BINFO_TYPE
(base_binfo
);
11291 rlist
= find_applicable_accessible_methods_list
(lc
, t
, name
,
11293 list
= chainon
(rlist
, list
);
11296 /* Search classes */
11299 search_applicable_methods_list
(lc
, TYPE_METHODS
(class
),
11300 name
, arglist
, &list
, &all_list
);
11302 /* When looking finit$, class$ or instinit$, we turn LC to 1 so
11303 that we only search in class. Note that we should have found
11304 something at this point. */
11305 if
(ID_FINIT_P
(name
) || ID_CLASSDOLLAR_P
(name
) || ID_INSTINIT_P
(name
))
11312 /* We must search all interfaces of this class */
11316 BINFO_BASE_ITERATE
(TYPE_BINFO
(class
), i
, base_binfo
); i
++)
11318 tree t
= BINFO_TYPE
(base_binfo
);
11319 if
(t
!= object_type_node
)
11322 = find_applicable_accessible_methods_list
(lc
, t
,
11324 list
= chainon
(rlist
, list
);
11329 /* Search superclass */
11330 if
(!lc
&& CLASSTYPE_SUPER
(class
) != NULL_TREE
)
11333 class
= CLASSTYPE_SUPER
(class
);
11334 rlist
= find_applicable_accessible_methods_list
(lc
, class
,
11336 list
= chainon
(rlist
, list
);
11342 /* We're done. Reset the searched classes list and finally search
11343 java.lang.Object if it wasn't searched already. */
11344 if
(!search_not_done
)
11347 && TYPE_METHODS
(object_type_node
)
11348 && htab_find
(searched_classes
, object_type_node
) == NULL
)
11350 search_applicable_methods_list
(lc
,
11351 TYPE_METHODS
(object_type_node
),
11352 name
, arglist
, &list
, &all_list
);
11354 htab_delete
(searched_classes
);
11355 searched_classes
= NULL
;
11358 /* Either return the list obtained or all selected (but
11359 inaccessible) methods for better error report. */
11360 return
(!list ? all_list
: list
);
11363 /* Effectively search for the appropriate method in method */
11366 search_applicable_methods_list
(int lc
, tree method
, tree name
, tree arglist
,
11367 tree
*list
, tree
*all_list
)
11369 for
(; method
; method
= TREE_CHAIN
(method
))
11371 /* When dealing with constructor, stop here, otherwise search
11373 if
(lc
&& !DECL_CONSTRUCTOR_P
(method
))
11375 else if
(!lc
&& (DECL_CONSTRUCTOR_P
(method
)
11376 ||
(DECL_NAME
(method
) != name
)))
11379 if
(argument_types_convertible
(method
, arglist
))
11381 /* Retain accessible methods only */
11382 if
(!not_accessible_p
(DECL_CONTEXT
(current_function_decl
),
11383 method
, NULL_TREE
, 0))
11384 *list
= tree_cons
(NULL_TREE
, method
, *list
);
11386 /* Also retain all selected method here */
11387 *all_list
= tree_cons
(NULL_TREE
, method
, *list
);
11392 /* 15.11.2.2 Choose the Most Specific Method */
11395 find_most_specific_methods_list
(tree list
)
11398 int abstract
, candidates
;
11399 tree current
, new_list
= NULL_TREE
;
11400 for
(current
= list
; current
; current
= TREE_CHAIN
(current
))
11403 DECL_SPECIFIC_COUNT
(TREE_VALUE
(current
)) = 0;
11405 for
(method
= list
; method
; method
= TREE_CHAIN
(method
))
11407 tree method_v
, current_v
;
11408 /* Don't test a method against itself */
11409 if
(method
== current
)
11412 method_v
= TREE_VALUE
(method
);
11413 current_v
= TREE_VALUE
(current
);
11415 /* Compare arguments and location where methods where declared */
11416 if
(argument_types_convertible
(method_v
, current_v
))
11418 if
(valid_method_invocation_conversion_p
11419 (DECL_CONTEXT
(method_v
), DECL_CONTEXT
(current_v
)))
11421 int v
= (DECL_SPECIFIC_COUNT
(current_v
) += 1);
11422 max
= (v
> max ? v
: max
);
11428 /* Review the list and select the maximally specific methods */
11429 for
(current
= list
, abstract
= -1, candidates
= -1;
11430 current
; current
= TREE_CHAIN
(current
))
11431 if
(DECL_SPECIFIC_COUNT
(TREE_VALUE
(current
)) == max
)
11433 new_list
= tree_cons
(NULL_TREE
, TREE_VALUE
(current
), new_list
);
11434 abstract
+= (METHOD_ABSTRACT
(TREE_VALUE
(current
)) ?
1 : 0);
11438 /* If we have several and they're all abstract, just pick the
11440 if
(candidates
> 0 && candidates
== abstract
)
11442 /* FIXME: merge the throws clauses. There is no convenient way
11443 to do this in gcj right now, since ideally we'd like to
11444 introduce a new METHOD_DECL here, but that is really not
11446 new_list
= nreverse
(new_list
);
11447 TREE_CHAIN
(new_list
) = NULL_TREE
;
11451 /* We have several (we couldn't find a most specific), all but one
11452 are abstract, we pick the only non abstract one. */
11453 if
(candidates
> 0 && (candidates
== abstract
+1))
11455 for
(current
= new_list
; current
; current
= TREE_CHAIN
(current
))
11456 if
(!METHOD_ABSTRACT
(TREE_VALUE
(current
)))
11458 TREE_CHAIN
(current
) = NULL_TREE
;
11459 new_list
= current
;
11463 /* If we can't find one, lower expectations and try to gather multiple
11464 maximally specific methods */
11465 while
(!new_list
&& max
)
11469 if
(DECL_SPECIFIC_COUNT
(TREE_VALUE
(current
)) == max
)
11470 new_list
= tree_cons
(NULL_TREE
, TREE_VALUE
(current
), new_list
);
11477 /* Make sure that the type of each M2_OR_ARGLIST arguments can be
11478 converted by method invocation conversion (5.3) to the type of the
11479 corresponding parameter of M1. Implementation expects M2_OR_ARGLIST
11480 to change less often than M1. */
11482 static GTY
(()) tree m2_arg_value
;
11483 static GTY
(()) tree m2_arg_cache
;
11486 argument_types_convertible
(tree m1
, tree m2_or_arglist
)
11488 tree m1_arg
, m2_arg
;
11490 SKIP_THIS_AND_ARTIFICIAL_PARMS
(m1_arg
, m1
)
11492 if
(m2_arg_value
== m2_or_arglist
)
11493 m2_arg
= m2_arg_cache
;
11496 /* M2_OR_ARGLIST can be a function DECL or a raw list of
11498 if
(m2_or_arglist
&& TREE_CODE
(m2_or_arglist
) == FUNCTION_DECL
)
11500 m2_arg
= TYPE_ARG_TYPES
(TREE_TYPE
(m2_or_arglist
));
11501 if
(!METHOD_STATIC
(m2_or_arglist
))
11502 m2_arg
= TREE_CHAIN
(m2_arg
);
11505 m2_arg
= m2_or_arglist
;
11507 m2_arg_value
= m2_or_arglist
;
11508 m2_arg_cache
= m2_arg
;
11511 while
(m1_arg
!= end_params_node
&& m2_arg
!= end_params_node
)
11513 resolve_and_layout
(TREE_VALUE
(m1_arg
), NULL_TREE
);
11514 if
(!valid_method_invocation_conversion_p
(TREE_VALUE
(m1_arg
),
11515 TREE_VALUE
(m2_arg
)))
11517 m1_arg
= TREE_CHAIN
(m1_arg
);
11518 m2_arg
= TREE_CHAIN
(m2_arg
);
11520 return m1_arg
== end_params_node
&& m2_arg
== end_params_node
;
11523 /* Qualification routines */
11525 /* Given a name x.y.z, look up x locally. If it's found, save the
11526 decl. If it's not found, mark the name as RESOLVE_PACKAGE_NAME_P,
11527 so that we later try and load the appropriate classes. */
11529 qualify_ambiguous_name
(tree id
)
11533 /* We inspect the first item of the qualification list. As a sanity
11534 check, make sure that it is an identfier node. */
11535 tree qual
= EXPR_WFL_QUALIFICATION
(id
);
11536 tree qual_wfl
= QUAL_WFL
(qual
);
11538 if
(TREE_CODE
(qual_wfl
) != EXPR_WITH_FILE_LOCATION
)
11541 name
= EXPR_WFL_NODE
(qual_wfl
);
11543 /* If we don't have an identifier, or we have a 'this' or 'super',
11544 then field access processing is all we need : there is nothing
11546 if
(!name || TREE_CODE
(name
) != IDENTIFIER_NODE ||
11547 name
== this_identifier_node ||
11548 name
== super_identifier_node
)
11551 /* If name appears within the scope of a local variable declaration
11552 or parameter declaration, or is a field within an enclosing
11553 class, then it is an expression name. Save the decl and let
11554 resolve_field_access do it's work. */
11555 if
((decl
= IDENTIFIER_LOCAL_VALUE
(name
)) ||
11556 (decl
= lookup_field_wrapper
(current_class
, name
)))
11558 QUAL_RESOLUTION
(qual
) = decl
;
11562 /* If name is a known class name (either declared or imported), mark
11563 us as a type name. */
11564 if
((decl
= resolve_and_layout
(name
, NULL_TREE
)))
11566 RESOLVE_TYPE_NAME_P
(qual_wfl
) = 1;
11567 QUAL_RESOLUTION
(qual
) = decl
;
11570 /* Check here that NAME isn't declared by more than one
11571 type-import-on-demand declaration of the compilation unit
11572 containing NAME. FIXME */
11574 /* We couldn't find a declaration for the name. Assume for now that
11575 we have a qualified class name that needs to be loaded from an
11576 external class file. */
11578 RESOLVE_PACKAGE_NAME_P
(qual_wfl
) = 1;
11580 /* Propagate the qualification across other components of the
11582 for
(qual
= TREE_CHAIN
(qual
); qual
;
11583 qual_wfl
= QUAL_WFL
(qual
), qual
= TREE_CHAIN
(qual
))
11585 if
(RESOLVE_PACKAGE_NAME_P
(qual_wfl
))
11586 RESOLVE_PACKAGE_NAME_P
(QUAL_WFL
(qual
)) = 1;
11589 /* Store the global qualification for the ambiguous part of ID back
11591 if
(RESOLVE_TYPE_NAME_P
(qual_wfl
))
11592 RESOLVE_TYPE_NAME_P
(id
) = 1;
11593 else if
(RESOLVE_PACKAGE_NAME_P
(qual_wfl
))
11594 RESOLVE_PACKAGE_NAME_P
(id
) = 1;
11597 /* Patch tree nodes in a function body. When a BLOCK is found, push
11598 local variable decls if present.
11599 Same as java_complete_lhs, but does resolve static finals to values. */
11602 java_complete_tree
(tree node
)
11604 node
= java_complete_lhs
(node
);
11605 if
(JDECL_P
(node
) && CLASS_FINAL_VARIABLE_P
(node
)
11606 && DECL_INITIAL
(node
) != NULL_TREE
)
11608 tree value
= fold_constant_for_init
(node
, node
);
11609 if
(value
!= NULL_TREE
)
11616 java_stabilize_reference
(tree node
)
11618 if
(TREE_CODE
(node
) == COMPOUND_EXPR
)
11620 tree op0
= TREE_OPERAND
(node
, 0);
11621 tree op1
= TREE_OPERAND
(node
, 1);
11622 TREE_OPERAND
(node
, 0) = save_expr
(op0
);
11623 TREE_OPERAND
(node
, 1) = java_stabilize_reference
(op1
);
11626 return stabilize_reference
(node
);
11629 /* Patch tree nodes in a function body. When a BLOCK is found, push
11630 local variable decls if present.
11631 Same as java_complete_tree, but does not resolve static finals to values. */
11634 java_complete_lhs
(tree node
)
11636 tree nn
, cn
, wfl_op1
, wfl_op2
, wfl_op3
;
11639 /* CONVERT_EXPR always has its type set, even though it needs to be
11641 if
(TREE_TYPE
(node
) && TREE_CODE
(node
) != CONVERT_EXPR
)
11644 /* The switch block implements cases processing container nodes
11645 first. Contained nodes are always written back. Leaves come
11646 next and return a value. */
11647 switch
(TREE_CODE
(node
))
11651 /* 1- Block section.
11652 Set the local values on decl names so we can identify them
11653 faster when they're referenced. At that stage, identifiers
11654 are legal so we don't check for declaration errors. */
11655 for
(cn
= BLOCK_EXPR_DECLS
(node
); cn
; cn
= TREE_CHAIN
(cn
))
11657 DECL_CONTEXT
(cn
) = current_function_decl
;
11658 IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(cn
)) = cn
;
11660 if
(BLOCK_EXPR_BODY
(node
) == NULL_TREE
)
11661 CAN_COMPLETE_NORMALLY
(node
) = 1;
11664 tree stmt
= BLOCK_EXPR_BODY
(node
);
11666 int error_seen
= 0;
11667 if
(TREE_CODE
(stmt
) == COMPOUND_EXPR
)
11669 /* Re-order from (((A; B); C); ...; Z) to
11670 (A; (B; (C ; (...; Z)))).
11671 This makes it easier to scan the statements left-to-right
11672 without using recursion (which might overflow the stack
11673 if the block has many statements. */
11676 tree left
= TREE_OPERAND
(stmt
, 0);
11677 if
(TREE_CODE
(left
) != COMPOUND_EXPR
)
11679 TREE_OPERAND
(stmt
, 0) = TREE_OPERAND
(left
, 1);
11680 TREE_OPERAND
(left
, 1) = stmt
;
11683 BLOCK_EXPR_BODY
(node
) = stmt
;
11686 /* Now do the actual complete, without deep recursion for
11688 ptr
= &BLOCK_EXPR_BODY
(node
);
11689 while
(TREE_CODE
(*ptr
) == COMPOUND_EXPR
11690 && !IS_EMPTY_STMT
(TREE_OPERAND
(*ptr
, 1)))
11692 tree cur
= java_complete_tree
(TREE_OPERAND
(*ptr
, 0));
11693 tree
*next
= &TREE_OPERAND
(*ptr
, 1);
11694 TREE_OPERAND
(*ptr
, 0) = cur
;
11695 if
(IS_EMPTY_STMT
(cur
))
11697 /* Optimization; makes it easier to detect empty bodies.
11698 Most useful for <clinit> with all-constant initializer. */
11702 if
(TREE_CODE
(cur
) == ERROR_MARK
)
11704 else if
(! CAN_COMPLETE_NORMALLY
(cur
))
11709 if
(TREE_CODE
(wfl_op2
) == BLOCK
)
11710 wfl_op2
= BLOCK_EXPR_BODY
(wfl_op2
);
11711 else if
(TREE_CODE
(wfl_op2
) == COMPOUND_EXPR
)
11712 wfl_op2
= TREE_OPERAND
(wfl_op2
, 0);
11716 if
(TREE_CODE
(wfl_op2
) != CASE_EXPR
11717 && TREE_CODE
(wfl_op2
) != DEFAULT_EXPR
)
11718 unreachable_stmt_error
(*ptr
);
11720 if
(TREE_TYPE
(*ptr
) == NULL_TREE
)
11721 TREE_TYPE
(*ptr
) = void_type_node
;
11724 *ptr
= java_complete_tree
(*ptr
);
11726 if
(TREE_CODE
(*ptr
) == ERROR_MARK || error_seen
> 0)
11727 return error_mark_node
;
11728 CAN_COMPLETE_NORMALLY
(node
) = CAN_COMPLETE_NORMALLY
(*ptr
);
11730 /* Turn local bindings to null */
11731 for
(cn
= BLOCK_EXPR_DECLS
(node
); cn
; cn
= TREE_CHAIN
(cn
))
11732 IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(cn
)) = NULL_TREE
;
11734 TREE_TYPE
(node
) = void_type_node
;
11737 /* 2- They are expressions but ultimately deal with statements */
11740 wfl_op1
= TREE_OPERAND
(node
, 0);
11741 COMPLETE_CHECK_OP_0
(node
);
11742 /* 14.19 A throw statement cannot complete normally. */
11743 CAN_COMPLETE_NORMALLY
(node
) = 0;
11744 return patch_throw_statement
(node
, wfl_op1
);
11746 case SYNCHRONIZED_EXPR
:
11747 wfl_op1
= TREE_OPERAND
(node
, 0);
11748 return patch_synchronized_statement
(node
, wfl_op1
);
11751 return patch_try_statement
(node
);
11753 case TRY_FINALLY_EXPR
:
11754 COMPLETE_CHECK_OP_0
(node
);
11755 COMPLETE_CHECK_OP_1
(node
);
11756 if
(IS_EMPTY_STMT
(TREE_OPERAND
(node
, 0)))
11757 /* Reduce try/finally nodes with an empty try block. */
11758 return TREE_OPERAND
(node
, 1);
11759 if
(IS_EMPTY_STMT
(TREE_OPERAND
(node
, 1)))
11760 /* Likewise for an empty finally block. */
11761 return TREE_OPERAND
(node
, 0);
11762 CAN_COMPLETE_NORMALLY
(node
)
11763 = (CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 0))
11764 && CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1)));
11765 TREE_TYPE
(node
) = TREE_TYPE
(TREE_OPERAND
(node
, 0));
11768 case LABELED_BLOCK_EXPR
:
11769 PUSH_LABELED_BLOCK
(node
);
11770 if
(LABELED_BLOCK_BODY
(node
))
11771 COMPLETE_CHECK_OP_1
(node
);
11772 TREE_TYPE
(node
) = void_type_node
;
11773 POP_LABELED_BLOCK
();
11775 if
(IS_EMPTY_STMT
(LABELED_BLOCK_BODY
(node
)))
11777 LABELED_BLOCK_BODY
(node
) = NULL_TREE
;
11778 CAN_COMPLETE_NORMALLY
(node
) = 1;
11780 else if
(CAN_COMPLETE_NORMALLY
(LABELED_BLOCK_BODY
(node
)))
11781 CAN_COMPLETE_NORMALLY
(node
) = 1;
11784 case EXIT_BLOCK_EXPR
:
11785 return patch_bc_statement
(node
);
11788 cn
= java_complete_tree
(TREE_OPERAND
(node
, 0));
11789 if
(cn
== error_mark_node
)
11792 /* First, the case expression must be constant. Values of final
11793 fields are accepted. */
11794 nn
= fold_constant_for_init
(cn
, NULL_TREE
);
11795 if
(nn
!= NULL_TREE
)
11799 if
((TREE_CODE
(cn
) == COMPOUND_EXPR
11800 || TREE_CODE
(cn
) == COMPONENT_REF
)
11801 && JDECL_P
(TREE_OPERAND
(cn
, 1))
11802 && FIELD_FINAL
(TREE_OPERAND
(cn
, 1))
11803 && DECL_INITIAL
(TREE_OPERAND
(cn
, 1)))
11805 cn
= fold_constant_for_init
(DECL_INITIAL
(TREE_OPERAND
(cn
, 1)),
11806 TREE_OPERAND
(cn
, 1));
11808 /* Accept final locals too. */
11809 else if
(TREE_CODE
(cn
) == VAR_DECL
&& DECL_FINAL
(cn
)
11810 && DECL_INITIAL
(cn
))
11811 cn
= fold_constant_for_init
(DECL_INITIAL
(cn
), cn
);
11813 if
(!TREE_CONSTANT
(cn
))
11815 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11816 parse_error_context
(node
, "Constant expression required");
11817 return error_mark_node
;
11820 nn
= ctxp
->current_loop
;
11822 /* It must be assignable to the type of the switch expression. */
11823 if
(!try_builtin_assignconv
(NULL_TREE
,
11824 TREE_TYPE
(TREE_OPERAND
(nn
, 0)), cn
))
11826 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11827 parse_error_context
11829 "Incompatible type for case. Can't convert %qs to %<int%>",
11830 lang_printable_name
(TREE_TYPE
(cn
), 0));
11831 return error_mark_node
;
11834 cn
= fold
(convert
(int_type_node
, cn
));
11835 TREE_CONSTANT_OVERFLOW
(cn
) = 0;
11836 CAN_COMPLETE_NORMALLY
(cn
) = 1;
11838 /* Save the label on a list so that we can later check for
11840 case_label_list
= tree_cons
(node
, cn
, case_label_list
);
11842 /* Multiple instance of a case label bearing the same value is
11843 checked later. The case expression is all right so far. */
11844 if
(TREE_CODE
(cn
) == VAR_DECL
)
11845 cn
= DECL_INITIAL
(cn
);
11846 TREE_OPERAND
(node
, 0) = cn
;
11847 TREE_TYPE
(node
) = void_type_node
;
11848 CAN_COMPLETE_NORMALLY
(node
) = 1;
11849 TREE_SIDE_EFFECTS
(node
) = 1;
11853 nn
= ctxp
->current_loop
;
11854 /* Only one default label is allowed per switch statement */
11855 if
(SWITCH_HAS_DEFAULT
(nn
))
11857 #ifdef USE_MAPPED_LOCATION
11858 SET_EXPR_LOCATION
(wfl_operator
, EXPR_LOCATION
(node
));
11860 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
11862 parse_error_context
(wfl_operator
,
11863 "Duplicate case label: %<default%>");
11864 return error_mark_node
;
11867 SWITCH_HAS_DEFAULT
(nn
) = 1;
11868 TREE_TYPE
(node
) = void_type_node
;
11869 TREE_SIDE_EFFECTS
(node
) = 1;
11870 CAN_COMPLETE_NORMALLY
(node
) = 1;
11876 /* Check whether the loop was enclosed in a labeled
11877 statement. If not, create one, insert the loop in it and
11879 nn
= patch_loop_statement
(node
);
11881 /* Anyways, walk the body of the loop */
11882 if
(TREE_CODE
(node
) == LOOP_EXPR
)
11883 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11884 /* Switch statement: walk the switch expression and the cases */
11886 node
= patch_switch_statement
(node
);
11888 if
(node
== error_mark_node || TREE_OPERAND
(node
, 0) == error_mark_node
)
11889 nn
= error_mark_node
;
11892 TREE_TYPE
(nn
) = TREE_TYPE
(node
) = void_type_node
;
11893 /* If we returned something different, that's because we
11894 inserted a label. Pop the label too. */
11897 if
(CAN_COMPLETE_NORMALLY
(node
))
11898 CAN_COMPLETE_NORMALLY
(nn
) = 1;
11899 POP_LABELED_BLOCK
();
11906 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11907 return patch_exit_expr
(node
);
11911 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
11912 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
11913 return error_mark_node
;
11914 /* then-else branches */
11915 TREE_OPERAND
(node
, 1) = java_complete_tree
(TREE_OPERAND
(node
, 1));
11916 if
(TREE_OPERAND
(node
, 1) == error_mark_node
)
11917 return error_mark_node
;
11919 /* This is a special case due to build_assertion(). When
11920 assertions are disabled we build a COND_EXPR in which
11921 Operand 1 is the body of the assertion. If that happens to
11922 be a string concatenation we'll need to patch it here. */
11923 tree patched
= patch_string
(TREE_OPERAND
(node
, 1));
11925 TREE_OPERAND
(node
, 1) = patched
;
11927 TREE_OPERAND
(node
, 2) = java_complete_tree
(TREE_OPERAND
(node
, 2));
11928 if
(TREE_OPERAND
(node
, 2) == error_mark_node
)
11929 return error_mark_node
;
11930 return patch_if_else_statement
(node
);
11933 case CONDITIONAL_EXPR
:
11935 wfl_op1
= TREE_OPERAND
(node
, 0);
11936 COMPLETE_CHECK_OP_0
(node
);
11937 wfl_op2
= TREE_OPERAND
(node
, 1);
11938 COMPLETE_CHECK_OP_1
(node
);
11939 wfl_op3
= TREE_OPERAND
(node
, 2);
11940 COMPLETE_CHECK_OP_2
(node
);
11941 return patch_conditional_expr
(node
, wfl_op1
, wfl_op2
);
11943 /* 3- Expression section */
11944 case COMPOUND_EXPR
:
11945 wfl_op2
= TREE_OPERAND
(node
, 1);
11946 TREE_OPERAND
(node
, 0) = nn
=
11947 java_complete_tree
(TREE_OPERAND
(node
, 0));
11948 if
(IS_EMPTY_STMT
(wfl_op2
))
11949 CAN_COMPLETE_NORMALLY
(node
) = CAN_COMPLETE_NORMALLY
(nn
);
11952 if
(! CAN_COMPLETE_NORMALLY
(nn
) && TREE_CODE
(nn
) != ERROR_MARK
)
11954 /* An unreachable condition in a do-while statement
11955 is *not* (technically) an unreachable statement. */
11957 if
(TREE_CODE
(nn
) == EXPR_WITH_FILE_LOCATION
)
11958 nn
= EXPR_WFL_NODE
(nn
);
11959 /* NN can be NULL_TREE exactly when UPDATE is, in
11960 finish_for_loop. */
11961 if
(nn
!= NULL_TREE
&& TREE_CODE
(nn
) != EXIT_EXPR
)
11963 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op2
);
11964 if
(SUPPRESS_UNREACHABLE_ERROR
(nn
))
11966 /* Perhaps this warning should have an
11967 associated flag. The code being compiled is
11968 pedantically correct, but useless. */
11969 parse_warning_context
(wfl_operator
,
11970 "Unreachable statement");
11973 parse_error_context
(wfl_operator
,
11974 "Unreachable statement");
11977 TREE_OPERAND
(node
, 1) = java_complete_tree
(TREE_OPERAND
(node
, 1));
11978 if
(TREE_OPERAND
(node
, 1) == error_mark_node
)
11979 return error_mark_node
;
11980 /* Even though we might allow the case where the first
11981 operand doesn't return normally, we still should compute
11982 CAN_COMPLETE_NORMALLY correctly. */
11983 CAN_COMPLETE_NORMALLY
(node
)
11984 = (CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 0))
11985 && CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1)));
11987 TREE_TYPE
(node
) = TREE_TYPE
(TREE_OPERAND
(node
, 1));
11991 /* CAN_COMPLETE_NORMALLY (node) = 0; */
11992 return patch_return
(node
);
11994 case EXPR_WITH_FILE_LOCATION
:
11995 if
(!EXPR_WFL_NODE
(node
) /* Or a PRIMARY flag ? */
11996 || TREE_CODE
(EXPR_WFL_NODE
(node
)) == IDENTIFIER_NODE
)
11998 node
= resolve_expression_name
(node
, NULL
);
11999 if
(node
== error_mark_node
)
12001 CAN_COMPLETE_NORMALLY
(node
) = 1;
12006 location_t save_location
= input_location
;
12007 #ifdef USE_MAPPED_LOCATION
12008 input_location
= EXPR_LOCATION
(node
);
12009 if
(input_location
== UNKNOWN_LOCATION
)
12010 input_location
= save_location
;
12012 input_line
= EXPR_WFL_LINENO
(node
);
12014 body
= java_complete_tree
(EXPR_WFL_NODE
(node
));
12015 input_location
= save_location
;
12016 EXPR_WFL_NODE
(node
) = body
;
12017 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(body
);
12018 CAN_COMPLETE_NORMALLY
(node
) = CAN_COMPLETE_NORMALLY
(body
);
12019 if
(IS_EMPTY_STMT
(body
) || TREE_CONSTANT
(body
))
12021 /* Makes it easier to constant fold, detect empty bodies. */
12024 if
(body
== error_mark_node
)
12026 /* Its important for the evaluation of assignment that
12027 this mark on the TREE_TYPE is propagated. */
12028 TREE_TYPE
(node
) = error_mark_node
;
12029 return error_mark_node
;
12032 TREE_TYPE
(node
) = TREE_TYPE
(EXPR_WFL_NODE
(node
));
12037 case NEW_ARRAY_EXPR
:
12038 /* Patch all the dimensions */
12040 for
(cn
= TREE_OPERAND
(node
, 1); cn
; cn
= TREE_CHAIN
(cn
))
12042 int location
= EXPR_WFL_LINECOL
(TREE_VALUE
(cn
));
12043 tree dim
= convert
(int_type_node
,
12044 java_complete_tree
(TREE_VALUE
(cn
)));
12045 if
(dim
== error_mark_node
)
12052 TREE_VALUE
(cn
) = dim
;
12053 /* Setup the location of the current dimension, for
12054 later error report. */
12055 #ifdef USE_MAPPED_LOCATION
12056 TREE_PURPOSE
(cn
) = expr_add_location
(NULL_TREE
, location
, 0);
12058 TREE_PURPOSE
(cn
) =
12059 build_expr_wfl
(NULL_TREE
, input_filename
, 0, 0);
12060 EXPR_WFL_LINECOL
(TREE_PURPOSE
(cn
)) = location
;
12064 /* They complete the array creation expression, if no errors
12066 CAN_COMPLETE_NORMALLY
(node
) = 1;
12067 return
(flag ? error_mark_node
12068 : force_evaluation_order
(patch_newarray
(node
)));
12070 case NEW_ANONYMOUS_ARRAY_EXPR
:
12071 /* Create the array type if necessary. */
12072 if
(ANONYMOUS_ARRAY_DIMS_SIG
(node
))
12074 tree type
= ANONYMOUS_ARRAY_BASE_TYPE
(node
);
12075 if
(!(type
= resolve_type_during_patch
(type
)))
12076 return error_mark_node
;
12077 type
= build_array_from_name
(type
, NULL_TREE
,
12078 ANONYMOUS_ARRAY_DIMS_SIG
(node
), NULL
);
12079 ANONYMOUS_ARRAY_BASE_TYPE
(node
) = build_pointer_type
(type
);
12081 node
= patch_new_array_init
(ANONYMOUS_ARRAY_BASE_TYPE
(node
),
12082 ANONYMOUS_ARRAY_INITIALIZER
(node
));
12083 if
(node
== error_mark_node
)
12084 return error_mark_node
;
12085 CAN_COMPLETE_NORMALLY
(node
) = 1;
12088 case NEW_CLASS_EXPR
:
12090 /* Complete function's argument(s) first */
12091 if
(complete_function_arguments
(node
))
12092 return error_mark_node
;
12095 tree decl
, wfl
= TREE_OPERAND
(node
, 0);
12096 int in_this
= CALL_THIS_CONSTRUCTOR_P
(node
);
12097 int from_super
= (EXPR_WFL_NODE
(TREE_OPERAND
(node
, 0)) ==
12098 super_identifier_node
);
12100 #ifdef USE_MAPPED_LOCATION
12101 source_location location
= EXPR_LOCATION
(node
);
12103 int location
= EXPR_WFL_LINECOL
(node
);
12106 node
= patch_method_invocation
(node
, NULL_TREE
, NULL_TREE
,
12107 from_super
, 0, &decl
);
12108 if
(node
== error_mark_node
)
12109 return error_mark_node
;
12111 if
(TREE_CODE
(node
) == CALL_EXPR
12112 && TREE_OPERAND
(node
, 1) != NULL_TREE
)
12113 arguments
= TREE_VALUE
(TREE_OPERAND
(node
, 1));
12115 arguments
= NULL_TREE
;
12116 check_thrown_exceptions
(location
, decl
, arguments
);
12117 /* If we call this(...), register signature and positions */
12119 DECL_CONSTRUCTOR_CALLS
(current_function_decl
) =
12120 tree_cons
(wfl
, decl
,
12121 DECL_CONSTRUCTOR_CALLS
(current_function_decl
));
12122 CAN_COMPLETE_NORMALLY
(node
) = 1;
12123 return force_evaluation_order
(node
);
12127 /* Save potential wfls */
12128 wfl_op1
= TREE_OPERAND
(node
, 0);
12129 TREE_OPERAND
(node
, 0) = nn
= java_complete_lhs
(wfl_op1
);
12131 if
(MODIFY_EXPR_FROM_INITIALIZATION_P
(node
)
12132 && TREE_CODE
(nn
) == VAR_DECL
&& TREE_STATIC
(nn
)
12133 && DECL_INITIAL
(nn
) != NULL_TREE
)
12137 value
= fold_constant_for_init
(nn
, nn
);
12139 /* When we have a primitype type, or a string and we're not
12140 emitting a class file, we actually don't want to generate
12141 anything for the assignment. */
12142 if
(value
!= NULL_TREE
&&
12143 (JPRIMITIVE_TYPE_P
(TREE_TYPE
(value
)) ||
12144 (TREE_TYPE
(value
) == string_ptr_type_node
&&
12145 ! flag_emit_class_files
)))
12147 /* Prepare node for patch_assignment */
12148 TREE_OPERAND
(node
, 1) = value
;
12149 /* Call patch assignment to verify the assignment */
12150 if
(patch_assignment
(node
, wfl_op1
) == error_mark_node
)
12151 return error_mark_node
;
12152 /* Set DECL_INITIAL properly (a conversion might have
12153 been decided by patch_assignment) and return the
12154 empty statement. */
12157 tree patched
= patch_string
(TREE_OPERAND
(node
, 1));
12159 DECL_INITIAL
(nn
) = patched
;
12161 DECL_INITIAL
(nn
) = TREE_OPERAND
(node
, 1);
12162 DECL_FIELD_FINAL_IUD
(nn
) = 1;
12163 return build_java_empty_stmt
();
12166 if
(! flag_emit_class_files
)
12167 DECL_INITIAL
(nn
) = NULL_TREE
;
12169 wfl_op2
= TREE_OPERAND
(node
, 1);
12171 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
12172 return error_mark_node
;
12174 flag
= COMPOUND_ASSIGN_P
(wfl_op2
);
12177 /* This might break when accessing outer field from inner
12178 class. TESTME, FIXME */
12179 tree lvalue
= java_stabilize_reference
(TREE_OPERAND
(node
, 0));
12181 /* Hand stabilize the lhs on both places */
12182 TREE_OPERAND
(node
, 0) = lvalue
;
12183 TREE_OPERAND
(TREE_OPERAND
(node
, 1), 0) =
12184 (flag_emit_class_files ? lvalue
: save_expr
(lvalue
));
12186 /* 15.25.2.a: Left hand is not an array access. FIXME */
12187 /* Now complete the RHS. We write it back later on. */
12188 nn
= java_complete_tree
(TREE_OPERAND
(node
, 1));
12190 if
((cn
= patch_string
(nn
)))
12193 /* The last part of the rewrite for E1 op= E2 is to have
12194 E1 = (T)(E1 op E2), with T being the type of E1. */
12195 nn
= java_complete_tree
(build_cast
(EXPR_WFL_LINECOL
(wfl_op2
),
12196 TREE_TYPE
(lvalue
), nn
));
12198 /* If the assignment is compound and has reference type,
12199 then ensure the LHS has type String and nothing else. */
12200 if
(JREFERENCE_TYPE_P
(TREE_TYPE
(lvalue
))
12201 && ! JSTRING_TYPE_P
(TREE_TYPE
(lvalue
)))
12202 parse_error_context
(wfl_op2
,
12203 "Incompatible type for %<+=%>. Can't convert %qs to %<java.lang.String%>",
12204 lang_printable_name
(TREE_TYPE
(lvalue
), 0));
12206 /* 15.25.2.b: Left hand is an array access. FIXME */
12209 /* If we're about to patch a NEW_ARRAY_INIT, we call a special
12210 function to complete this RHS. Note that a NEW_ARRAY_INIT
12211 might have been already fully expanded if created as a result
12212 of processing an anonymous array initializer. We avoid doing
12213 the operation twice by testing whether the node already bears
12215 else if
(TREE_CODE
(wfl_op2
) == NEW_ARRAY_INIT
&& !TREE_TYPE
(wfl_op2
))
12216 nn
= patch_new_array_init
(TREE_TYPE
(TREE_OPERAND
(node
, 0)),
12217 TREE_OPERAND
(node
, 1));
12218 /* Otherwise we simply complete the RHS */
12220 nn
= java_complete_tree
(TREE_OPERAND
(node
, 1));
12222 if
(nn
== error_mark_node
)
12223 return error_mark_node
;
12225 /* Write back the RHS as we evaluated it. */
12226 TREE_OPERAND
(node
, 1) = nn
;
12228 /* In case we're handling = with a String as a RHS, we need to
12229 produce a String out of the RHS (it might still be a
12230 STRING_CST or a StringBuffer at this stage */
12231 if
((nn
= patch_string
(TREE_OPERAND
(node
, 1))))
12232 TREE_OPERAND
(node
, 1) = nn
;
12234 if
((nn
= nested_field_access_fix
(wfl_op1
, TREE_OPERAND
(node
, 0),
12235 TREE_OPERAND
(node
, 1))))
12237 /* We return error_mark_node if nested_field_access_fix
12238 detects we write into a final. */
12239 if
(nn
== error_mark_node
)
12240 return error_mark_node
;
12245 node
= patch_assignment
(node
, wfl_op1
);
12246 if
(node
== error_mark_node
)
12247 return error_mark_node
;
12248 /* Reorganize the tree if necessary. */
12249 if
(flag
&& (!JREFERENCE_TYPE_P
(TREE_TYPE
(node
))
12250 || JSTRING_P
(TREE_TYPE
(node
))))
12251 node
= java_refold
(node
);
12254 /* Seek to set DECL_INITIAL to a proper value, since it might have
12255 undergone a conversion in patch_assignment. We do that only when
12256 it's necessary to have DECL_INITIAL properly set. */
12257 nn
= TREE_OPERAND
(node
, 0);
12258 if
(TREE_CODE
(nn
) == VAR_DECL
12259 && DECL_INITIAL
(nn
) && CONSTANT_VALUE_P
(DECL_INITIAL
(nn
))
12260 && FIELD_STATIC
(nn
) && FIELD_FINAL
(nn
)
12261 && (JPRIMITIVE_TYPE_P
(TREE_TYPE
(nn
))
12262 || TREE_TYPE
(nn
) == string_ptr_type_node
))
12263 DECL_INITIAL
(nn
) = TREE_OPERAND
(node
, 1);
12265 CAN_COMPLETE_NORMALLY
(node
) = 1;
12277 case TRUNC_MOD_EXPR
:
12278 case TRUNC_DIV_EXPR
:
12280 case TRUTH_ANDIF_EXPR
:
12281 case TRUTH_ORIF_EXPR
:
12288 /* Operands 0 and 1 are WFL in certain cases only. patch_binop
12289 knows how to handle those cases. */
12290 wfl_op1
= TREE_OPERAND
(node
, 0);
12291 wfl_op2
= TREE_OPERAND
(node
, 1);
12293 CAN_COMPLETE_NORMALLY
(node
) = 1;
12294 /* Don't complete string nodes if dealing with the PLUS operand. */
12295 if
(TREE_CODE
(node
) != PLUS_EXPR ||
!JSTRING_P
(wfl_op1
))
12297 nn
= java_complete_tree
(wfl_op1
);
12298 if
(nn
== error_mark_node
)
12299 return error_mark_node
;
12301 TREE_OPERAND
(node
, 0) = nn
;
12303 if
(TREE_CODE
(node
) != PLUS_EXPR ||
!JSTRING_P
(wfl_op2
))
12305 nn
= java_complete_tree
(wfl_op2
);
12306 if
(nn
== error_mark_node
)
12307 return error_mark_node
;
12309 TREE_OPERAND
(node
, 1) = nn
;
12311 return patch_binop
(node
, wfl_op1
, wfl_op2
, 0);
12313 case INSTANCEOF_EXPR
:
12314 wfl_op1
= TREE_OPERAND
(node
, 0);
12315 COMPLETE_CHECK_OP_0
(node
);
12316 return patch_binop
(node
, wfl_op1
, TREE_OPERAND
(node
, 1), 0);
12318 case UNARY_PLUS_EXPR
:
12320 case TRUTH_NOT_EXPR
:
12322 case PREDECREMENT_EXPR
:
12323 case PREINCREMENT_EXPR
:
12324 case POSTDECREMENT_EXPR
:
12325 case POSTINCREMENT_EXPR
:
12327 /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
12328 how to handle those cases. */
12329 wfl_op1
= TREE_OPERAND
(node
, 0);
12330 CAN_COMPLETE_NORMALLY
(node
) = 1;
12331 TREE_OPERAND
(node
, 0) = java_complete_tree
(wfl_op1
);
12332 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
12333 return error_mark_node
;
12334 node
= patch_unaryop
(node
, wfl_op1
);
12335 CAN_COMPLETE_NORMALLY
(node
) = 1;
12339 /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
12340 how to handle those cases. */
12341 wfl_op1
= TREE_OPERAND
(node
, 0);
12342 TREE_OPERAND
(node
, 0) = java_complete_tree
(wfl_op1
);
12343 if
(TREE_OPERAND
(node
, 0) == error_mark_node
)
12344 return error_mark_node
;
12345 if
(!flag_emit_class_files
)
12346 TREE_OPERAND
(node
, 0) = save_expr
(TREE_OPERAND
(node
, 0));
12347 /* The same applies to wfl_op2 */
12348 wfl_op2
= TREE_OPERAND
(node
, 1);
12349 TREE_OPERAND
(node
, 1) = java_complete_tree
(wfl_op2
);
12350 if
(TREE_OPERAND
(node
, 1) == error_mark_node
)
12351 return error_mark_node
;
12352 if
(!flag_emit_class_files
)
12353 TREE_OPERAND
(node
, 1) = save_expr
(TREE_OPERAND
(node
, 1));
12354 return patch_array_ref
(node
);
12359 case COMPONENT_REF
:
12360 /* The first step in the re-write of qualified name handling. FIXME.
12361 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
12362 TREE_OPERAND
(node
, 0) = java_complete_tree
(TREE_OPERAND
(node
, 0));
12363 if
(TREE_CODE
(TREE_OPERAND
(node
, 0)) == RECORD_TYPE
)
12365 tree name
= TREE_OPERAND
(node
, 1);
12366 tree field
= lookup_field_wrapper
(TREE_OPERAND
(node
, 0), name
);
12367 if
(field
== NULL_TREE
)
12369 error ("missing static field %qs", IDENTIFIER_POINTER
(name
));
12370 return error_mark_node
;
12372 if
(! FIELD_STATIC
(field
))
12374 error ("not a static field %qs", IDENTIFIER_POINTER
(name
));
12375 return error_mark_node
;
12384 /* Can't use THIS in a static environment */
12387 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
12388 parse_error_context
(wfl_operator
,
12389 "Keyword %<this%> used outside allowed context");
12390 TREE_TYPE
(node
) = error_mark_node
;
12391 return error_mark_node
;
12393 if
(ctxp
->explicit_constructor_p
)
12395 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
12396 parse_error_context
12397 (wfl_operator
, "Can't reference %<this%> or %<super%> before the superclass constructor has been called");
12398 TREE_TYPE
(node
) = error_mark_node
;
12399 return error_mark_node
;
12401 return current_this
;
12403 case CLASS_LITERAL
:
12404 CAN_COMPLETE_NORMALLY
(node
) = 1;
12405 node
= patch_incomplete_class_ref
(node
);
12406 if
(node
== error_mark_node
)
12407 return error_mark_node
;
12411 CAN_COMPLETE_NORMALLY
(node
) = 1;
12412 /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
12413 and it's time to turn it into the appropriate String object */
12414 if
((nn
= patch_string
(node
)))
12417 internal_error
("No case for %s", tree_code_name
[TREE_CODE
(node
)]);
12422 /* Complete function call's argument. Return a nonzero value is an
12423 error was found. */
12426 complete_function_arguments
(tree node
)
12431 ctxp
->explicit_constructor_p
+= (CALL_EXPLICIT_CONSTRUCTOR_P
(node
) ?
1 : 0);
12432 for
(cn
= TREE_OPERAND
(node
, 1); cn
; cn
= TREE_CHAIN
(cn
))
12434 tree wfl
= TREE_VALUE
(cn
), parm
, temp
;
12435 parm
= java_complete_tree
(wfl
);
12437 if
(parm
== error_mark_node
)
12442 /* If we have a string literal that we haven't transformed yet or a
12443 crafted string buffer, as a result of the use of the String
12444 `+' operator. Build `parm.toString()' and expand it. */
12445 if
((temp
= patch_string
(parm
)))
12448 TREE_VALUE
(cn
) = parm
;
12450 ctxp
->explicit_constructor_p
-= (CALL_EXPLICIT_CONSTRUCTOR_P
(node
) ?
1 : 0);
12454 /* Sometimes (for loops and variable initialized during their
12455 declaration), we want to wrap a statement around a WFL and turn it
12459 build_debugable_stmt
(int location
, tree stmt
)
12461 if
(TREE_CODE
(stmt
) != EXPR_WITH_FILE_LOCATION
)
12463 #ifdef USE_MAPPED_LOCATION
12464 stmt
= expr_add_location
(stmt
, location
, 1);
12466 stmt
= build_expr_wfl
(stmt
, input_filename
, 0, 0);
12467 EXPR_WFL_LINECOL
(stmt
) = location
;
12468 JAVA_MAYBE_GENERATE_DEBUG_INFO
(stmt
);
12475 build_expr_block
(tree body
, tree decls
)
12477 tree node
= make_node
(BLOCK
);
12478 BLOCK_EXPR_DECLS
(node
) = decls
;
12479 BLOCK_EXPR_BODY
(node
) = body
;
12481 TREE_TYPE
(node
) = TREE_TYPE
(body
);
12482 TREE_SIDE_EFFECTS
(node
) = 1;
12486 /* Create a new function block and link it appropriately to current
12487 function block chain */
12492 tree b
= build_expr_block
(NULL_TREE
, NULL_TREE
);
12494 /* Link block B supercontext to the previous block. The current
12495 function DECL is used as supercontext when enter_a_block is called
12496 for the first time for a given function. The current function body
12497 (DECL_FUNCTION_BODY) is set to be block B. */
12499 tree fndecl
= current_function_decl
;
12502 BLOCK_SUPERCONTEXT
(b
) = current_static_block
;
12503 current_static_block
= b
;
12506 else if
(!DECL_FUNCTION_BODY
(fndecl
))
12508 BLOCK_SUPERCONTEXT
(b
) = fndecl
;
12509 DECL_FUNCTION_BODY
(fndecl
) = b
;
12513 BLOCK_SUPERCONTEXT
(b
) = DECL_FUNCTION_BODY
(fndecl
);
12514 DECL_FUNCTION_BODY
(fndecl
) = b
;
12519 /* Exit a block by changing the current function body
12520 (DECL_FUNCTION_BODY) to the current block super context, only if
12521 the block being exited isn't the method's top level one. */
12527 if
(current_function_decl
)
12529 b
= DECL_FUNCTION_BODY
(current_function_decl
);
12530 if
(BLOCK_SUPERCONTEXT
(b
) != current_function_decl
)
12531 DECL_FUNCTION_BODY
(current_function_decl
) = BLOCK_SUPERCONTEXT
(b
);
12535 b
= current_static_block
;
12537 if
(BLOCK_SUPERCONTEXT
(b
))
12538 current_static_block
= BLOCK_SUPERCONTEXT
(b
);
12543 /* Lookup for NAME in the nested function's blocks, all the way up to
12544 the current toplevel one. It complies with Java's local variable
12548 lookup_name_in_blocks
(tree name
)
12550 tree b
= GET_CURRENT_BLOCK
(current_function_decl
);
12552 while
(b
!= current_function_decl
)
12556 /* Paranoid sanity check. To be removed */
12557 if
(TREE_CODE
(b
) != BLOCK
)
12560 for
(current
= BLOCK_EXPR_DECLS
(b
); current
;
12561 current
= TREE_CHAIN
(current
))
12562 if
(DECL_NAME
(current
) == name
)
12564 b
= BLOCK_SUPERCONTEXT
(b
);
12570 maybe_absorb_scoping_blocks
(void)
12572 while
(BLOCK_IS_IMPLICIT
(GET_CURRENT_BLOCK
(current_function_decl
)))
12574 tree b
= exit_block
();
12575 java_method_add_stmt
(current_function_decl
, b
);
12576 SOURCE_FRONTEND_DEBUG
(("Absorbing scoping block at line %d", input_line
));
12581 /* This section of the source is reserved to build_* functions that
12582 are building incomplete tree nodes and the patch_* functions that
12583 are completing them. */
12585 /* Wrap a non WFL node around a WFL. */
12588 build_wfl_wrap
(tree node
, int location
)
12590 tree wfl
, node_to_insert
= node
;
12592 /* We want to process THIS . xxx symbolically, to keep it consistent
12593 with the way we're processing SUPER. A THIS from a primary as a
12594 different form than a SUPER. Turn THIS into something symbolic */
12595 if
(TREE_CODE
(node
) == THIS_EXPR
)
12596 node_to_insert
= wfl
= build_wfl_node
(this_identifier_node
);
12598 #ifdef USE_MAPPED_LOCATION
12599 wfl
= build_unknown_wfl
(NULL_TREE
);
12601 SET_EXPR_LOCATION
(wfl
, location
);
12603 wfl
= build_expr_wfl
(NULL_TREE
, ctxp
->filename
, 0, 0);
12605 EXPR_WFL_LINECOL
(wfl
) = location
;
12607 EXPR_WFL_QUALIFICATION
(wfl
) = build_tree_list
(node_to_insert
, NULL_TREE
);
12611 /* Build a super() constructor invocation. Returns an empty statement if
12612 we're currently dealing with the class java.lang.Object. */
12615 build_super_invocation
(tree mdecl
)
12617 if
(DECL_CONTEXT
(mdecl
) == object_type_node
)
12618 return build_java_empty_stmt
();
12621 tree super_wfl
= build_wfl_node
(super_identifier_node
);
12622 tree a
= NULL_TREE
, t
;
12624 /* This is called after parsing is done, so the parser context
12625 won't be accurate. Set location info from current_class decl. */
12626 tree class_wfl
= lookup_cl
(TYPE_NAME
(current_class
));
12627 EXPR_WFL_LINECOL
(super_wfl
) = EXPR_WFL_LINECOL
(class_wfl
);
12629 /* If we're dealing with an anonymous class, pass the arguments
12630 of the crafted constructor along. */
12631 if
(ANONYMOUS_CLASS_P
(DECL_CONTEXT
(mdecl
)))
12633 SKIP_THIS_AND_ARTIFICIAL_PARMS
(t
, mdecl
);
12634 for
(; t
!= end_params_node
; t
= TREE_CHAIN
(t
))
12635 a
= tree_cons
(NULL_TREE
, build_wfl_node
(TREE_PURPOSE
(t
)), a
);
12637 return build_method_invocation
(super_wfl
, a
);
12641 /* Build a SUPER/THIS qualified method invocation. */
12644 build_this_super_qualified_invocation
(int use_this
, tree name
, tree args
,
12645 int lloc
, int rloc
)
12649 build_wfl_node
(use_this ? this_identifier_node
: super_identifier_node
);
12650 EXPR_WFL_LINECOL
(wfl
) = lloc
;
12651 invok
= build_method_invocation
(name
, args
);
12652 return make_qualified_primary
(wfl
, invok
, rloc
);
12655 /* Build an incomplete CALL_EXPR node. */
12658 build_method_invocation
(tree name
, tree args
)
12660 tree call
= build3
(CALL_EXPR
, NULL_TREE
, name
, args
, NULL_TREE
);
12661 TREE_SIDE_EFFECTS
(call
) = 1;
12662 EXPR_WFL_LINECOL
(call
) = EXPR_WFL_LINECOL
(name
);
12666 /* Build an incomplete new xxx(...) node. */
12669 build_new_invocation
(tree name
, tree args
)
12671 tree call
= build3
(NEW_CLASS_EXPR
, NULL_TREE
, name
, args
, NULL_TREE
);
12672 TREE_SIDE_EFFECTS
(call
) = 1;
12673 EXPR_WFL_LINECOL
(call
) = EXPR_WFL_LINECOL
(name
);
12677 /* Build an incomplete assignment expression. */
12680 build_assignment
(int op
, int op_location
, tree lhs
, tree rhs
)
12683 /* Build the corresponding binop if we deal with a Compound
12684 Assignment operator. Mark the binop sub-tree as part of a
12685 Compound Assignment expression */
12686 if
(op
!= ASSIGN_TK
)
12688 rhs
= build_binop
(BINOP_LOOKUP
(op
), op_location
, lhs
, rhs
);
12689 COMPOUND_ASSIGN_P
(rhs
) = 1;
12691 assignment
= build2
(MODIFY_EXPR
, NULL_TREE
, lhs
, rhs
);
12692 TREE_SIDE_EFFECTS
(assignment
) = 1;
12693 EXPR_WFL_LINECOL
(assignment
) = op_location
;
12697 /* Print an INTEGER_CST node as decimal in a static buffer, and return
12698 the buffer. This is used only for string conversion. */
12700 string_convert_int_cst
(tree node
)
12702 /* Long.MIN_VALUE is -9223372036854775808, 20 characters. */
12703 static char buffer
[21];
12705 unsigned HOST_WIDE_INT lo
= TREE_INT_CST_LOW
(node
);
12706 unsigned HOST_WIDE_INT hi
= TREE_INT_CST_HIGH
(node
);
12707 char *p
= buffer
+ sizeof
(buffer
);
12710 unsigned HOST_WIDE_INT hibit
= (((unsigned HOST_WIDE_INT
) 1)
12711 << (HOST_BITS_PER_WIDE_INT
- 1));
12715 /* If negative, note the fact and negate the value. */
12725 /* Divide by 10 until there are no bits left. */
12728 unsigned HOST_WIDE_INT acc
= 0;
12729 unsigned HOST_WIDE_INT outhi
= 0, outlo
= 0;
12732 /* Use long division to compute the result and the remainder. */
12733 for
(i
= 0; i
< 2 * HOST_BITS_PER_WIDE_INT
; ++i
)
12735 /* Shift a bit into accumulator. */
12740 /* Shift the value. */
12746 /* Shift the correct bit into the result. */
12748 if
((outlo
& hibit
))
12758 /* '0' == 060 in Java, but might not be here (think EBCDIC). */
12759 *--p
= '\060' + acc
;
12767 *--p
= '\055'; /* '-' == 055 in Java, but might not be here. */
12772 /* Print an INTEGER_CST node in a static buffer, and return the
12773 buffer. This is used only for error handling. */
12775 print_int_node
(tree node
)
12777 static char buffer
[80];
12778 if
(TREE_CONSTANT_OVERFLOW
(node
))
12779 sprintf
(buffer
, "<overflow>");
12781 if
(TREE_INT_CST_HIGH
(node
) == 0)
12782 sprintf
(buffer
, HOST_WIDE_INT_PRINT_UNSIGNED
,
12783 TREE_INT_CST_LOW
(node
));
12784 else if
(TREE_INT_CST_HIGH
(node
) == -1
12785 && TREE_INT_CST_LOW
(node
) != 0)
12786 sprintf
(buffer
, "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
12787 -TREE_INT_CST_LOW
(node
));
12789 sprintf
(buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
12790 TREE_INT_CST_HIGH
(node
), TREE_INT_CST_LOW
(node
));
12796 /* Return 1 if an assignment to a FINAL is attempted in a non suitable
12799 /* 15.25 Assignment operators. */
12802 patch_assignment
(tree node
, tree wfl_op1
)
12804 tree rhs
= TREE_OPERAND
(node
, 1);
12805 tree lvalue
= TREE_OPERAND
(node
, 0), llvalue
;
12806 tree lhs_type
= NULL_TREE
, rhs_type
, new_rhs
= NULL_TREE
;
12807 int error_found
= 0;
12808 int lvalue_from_array
= 0;
12811 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
12813 /* Lhs can be a named variable */
12814 if
(JDECL_P
(lvalue
))
12816 lhs_type
= TREE_TYPE
(lvalue
);
12818 /* Or Lhs can be an array access. */
12819 else if
(TREE_CODE
(lvalue
) == ARRAY_REF
)
12821 lhs_type
= TREE_TYPE
(lvalue
);
12822 lvalue_from_array
= 1;
12824 /* Or a field access */
12825 else if
(TREE_CODE
(lvalue
) == COMPONENT_REF
)
12826 lhs_type
= TREE_TYPE
(lvalue
);
12827 /* Or a function return slot */
12828 else if
(TREE_CODE
(lvalue
) == RESULT_DECL
)
12830 /* If the return type is an integral type, then we create the
12831 RESULT_DECL with a promoted type, but we need to do these
12832 checks against the unpromoted type to ensure type safety. So
12833 here we look at the real type, not the type of the decl we
12835 lhs_type
= TREE_TYPE
(TREE_TYPE
(current_function_decl
));
12838 /* Otherwise, we might want to try to write into an optimized static
12839 final, this is an of a different nature, reported further on. */
12840 else if
(TREE_CODE
(wfl_op1
) == EXPR_WITH_FILE_LOCATION
12841 && resolve_expression_name
(wfl_op1
, &llvalue
))
12843 lhs_type
= TREE_TYPE
(lvalue
);
12847 parse_error_context
(wfl_op1
, "Invalid left hand side of assignment");
12851 rhs_type
= TREE_TYPE
(rhs
);
12853 /* 5.1 Try the assignment conversion for builtin type. */
12854 new_rhs
= try_builtin_assignconv
(wfl_op1
, lhs_type
, rhs
);
12856 /* 5.2 If it failed, try a reference conversion */
12858 new_rhs
= try_reference_assignconv
(lhs_type
, rhs
);
12860 /* 15.25.2 If we have a compound assignment, convert RHS into the
12862 else if
(COMPOUND_ASSIGN_P
(TREE_OPERAND
(node
, 1)))
12863 new_rhs
= convert
(lhs_type
, rhs
);
12865 /* Explicit cast required. This is an error */
12868 char *t1
= xstrdup
(lang_printable_name
(TREE_TYPE
(rhs
), 0));
12869 char *t2
= xstrdup
(lang_printable_name
(lhs_type
, 0));
12871 char operation
[32]; /* Max size known */
12873 /* If the assignment is part of a declaration, we use the WFL of
12874 the declared variable to point out the error and call it a
12875 declaration problem. If the assignment is a genuine =
12876 operator, we call is a operator `=' problem, otherwise we
12877 call it an assignment problem. In both of these last cases,
12878 we use the WFL of the operator to indicate the error. */
12880 if
(MODIFY_EXPR_FROM_INITIALIZATION_P
(node
))
12883 strcpy
(operation
, "declaration");
12887 wfl
= wfl_operator
;
12888 if
(COMPOUND_ASSIGN_P
(TREE_OPERAND
(node
, 1)))
12889 strcpy
(operation
, "assignment");
12890 else if
(is_return
)
12891 strcpy
(operation
, "'return'");
12893 strcpy
(operation
, "'='");
12896 if
(!valid_cast_to_p
(rhs_type
, lhs_type
))
12897 parse_error_context
12898 (wfl
, "Incompatible type for %s. Can't convert %qs to %qs",
12899 operation
, t1
, t2
);
12901 parse_error_context
(wfl
, "Incompatible type for %s. Explicit cast needed to convert %qs to %qs",
12902 operation
, t1
, t2
);
12903 free
(t1
); free
(t2
);
12908 return error_mark_node
;
12910 /* If we're processing a `return' statement, promote the actual type
12911 to the promoted type. */
12913 new_rhs
= convert
(TREE_TYPE
(lvalue
), new_rhs
);
12915 /* 10.10: Array Store Exception runtime check */
12916 if
(!flag_emit_class_files
12917 && lvalue_from_array
12918 && JREFERENCE_TYPE_P
(TYPE_ARRAY_ELEMENT
(lhs_type
)))
12920 tree array
, store_check
, base
, index_expr
;
12922 /* Save RHS so that it doesn't get re-evaluated by the store check. */
12923 new_rhs
= save_expr
(new_rhs
);
12925 /* Get the INDIRECT_REF. */
12926 array
= TREE_OPERAND
(TREE_OPERAND
(lvalue
, 0), 0);
12927 /* Get the array pointer expr. */
12928 array
= TREE_OPERAND
(array
, 0);
12929 store_check
= build_java_arraystore_check
(array
, new_rhs
);
12931 index_expr
= TREE_OPERAND
(lvalue
, 1);
12933 if
(TREE_CODE
(index_expr
) == COMPOUND_EXPR
)
12935 /* A COMPOUND_EXPR here is a bounds check. The bounds check must
12936 happen before the store check, so prepare to insert the store
12937 check within the second operand of the existing COMPOUND_EXPR. */
12943 index_expr
= TREE_OPERAND
(base
, 1);
12944 TREE_OPERAND
(base
, 1) = build2
(COMPOUND_EXPR
, TREE_TYPE
(index_expr
),
12945 store_check
, index_expr
);
12948 /* Final locals can be used as case values in switch
12949 statement. Prepare them for this eventuality. */
12950 if
(TREE_CODE
(lvalue
) == VAR_DECL
12951 && DECL_FINAL
(lvalue
)
12952 && TREE_CONSTANT
(new_rhs
)
12953 && IDENTIFIER_LOCAL_VALUE
(DECL_NAME
(lvalue
))
12954 && JINTEGRAL_TYPE_P
(TREE_TYPE
(lvalue
))
12957 TREE_CONSTANT
(lvalue
) = 1;
12958 TREE_INVARIANT
(lvalue
) = 1;
12959 DECL_INITIAL
(lvalue
) = new_rhs
;
12962 /* Copy the rhs if it's a reference. */
12963 if
(! flag_check_references
&& ! flag_emit_class_files
&& optimize
> 0)
12965 switch
(TREE_CODE
(new_rhs
))
12969 case COMPONENT_REF
:
12970 /* Transform a = foo.bar
12971 into a = ({int tmp; tmp = foo.bar;}).
12972 We need to ensure that if a read from memory fails
12973 because of a NullPointerException, a destination variable
12974 will remain unchanged. An explicit temporary does what
12977 If flag_check_references is set, this is unnecessary
12978 because we'll check each reference before doing any
12979 reads. If optimize is not set the result will never be
12980 written to a stack slot that contains the LHS. */
12982 tree tmp
= build_decl
(VAR_DECL
, get_identifier
("<tmp>"),
12983 TREE_TYPE
(new_rhs
));
12984 tree block
= make_node
(BLOCK
);
12986 = build2
(MODIFY_EXPR
, TREE_TYPE
(new_rhs
), tmp
, fold
(new_rhs
));
12987 DECL_CONTEXT
(tmp
) = current_function_decl
;
12988 TREE_TYPE
(block
) = TREE_TYPE
(new_rhs
);
12989 BLOCK_VARS
(block
) = tmp
;
12990 BLOCK_EXPR_BODY
(block
) = assignment
;
12991 TREE_SIDE_EFFECTS
(block
) = 1;
13000 TREE_OPERAND
(node
, 0) = lvalue
;
13001 TREE_OPERAND
(node
, 1) = new_rhs
;
13002 TREE_TYPE
(node
) = lhs_type
;
13006 /* Check that type SOURCE can be cast into type DEST. If the cast
13007 can't occur at all, return NULL; otherwise, return a possibly
13011 try_reference_assignconv
(tree lhs_type
, tree rhs
)
13013 tree new_rhs
= NULL_TREE
;
13014 tree rhs_type
= TREE_TYPE
(rhs
);
13016 if
(!JPRIMITIVE_TYPE_P
(rhs_type
) && JREFERENCE_TYPE_P
(lhs_type
))
13018 /* `null' may be assigned to any reference type */
13019 if
(rhs
== null_pointer_node
)
13020 new_rhs
= null_pointer_node
;
13021 /* Try the reference assignment conversion */
13022 else if
(valid_ref_assignconv_cast_p
(rhs_type
, lhs_type
, 0))
13024 /* This is a magic assignment that we process differently */
13025 else if
(TREE_CODE
(rhs
) == JAVA_EXC_OBJ_EXPR
)
13031 /* Check that RHS can be converted into LHS_TYPE by the assignment
13032 conversion (5.2), for the cases of RHS being a builtin type. Return
13033 NULL_TREE if the conversion fails or if because RHS isn't of a
13034 builtin type. Return a converted RHS if the conversion is possible. */
13037 try_builtin_assignconv
(tree wfl_op1
, tree lhs_type
, tree rhs
)
13039 tree new_rhs
= NULL_TREE
;
13040 tree rhs_type
= TREE_TYPE
(rhs
);
13042 /* Handle boolean specially. */
13043 if
(TREE_CODE
(rhs_type
) == BOOLEAN_TYPE
13044 || TREE_CODE
(lhs_type
) == BOOLEAN_TYPE
)
13046 if
(TREE_CODE
(rhs_type
) == BOOLEAN_TYPE
13047 && TREE_CODE
(lhs_type
) == BOOLEAN_TYPE
)
13051 /* 5.1.1 Try Identity Conversion,
13052 5.1.2 Try Widening Primitive Conversion */
13053 else if
(valid_builtin_assignconv_identity_widening_p
(lhs_type
, rhs_type
))
13054 new_rhs
= convert
(lhs_type
, rhs
);
13056 /* Try a narrowing primitive conversion (5.1.3):
13057 - expression is a constant expression of type byte, short, char,
13059 - variable is byte, short or char AND
13060 - The value of the expression is representable in the type of the
13062 else if
((rhs_type
== byte_type_node || rhs_type
== short_type_node
13063 || rhs_type
== char_type_node || rhs_type
== int_type_node
)
13064 && TREE_CONSTANT
(rhs
)
13065 && (lhs_type
== byte_type_node || lhs_type
== char_type_node
13066 || lhs_type
== short_type_node
))
13068 if
(int_fits_type_p
(rhs
, lhs_type
))
13069 new_rhs
= convert
(lhs_type
, rhs
);
13070 else if
(wfl_op1
) /* Might be called with a NULL */
13071 parse_warning_context
13073 "Constant expression %qs too wide for narrowing primitive conversion to %qs",
13074 print_int_node
(rhs
), lang_printable_name
(lhs_type
, 0));
13075 /* Reported a warning that will turn into an error further
13076 down, so we don't return */
13082 /* Return 1 if RHS_TYPE can be converted to LHS_TYPE by identity
13083 conversion (5.1.1) or widening primitive conversion (5.1.2). Return
13084 0 is the conversion test fails. This implements parts the method
13085 invocation conversion (5.3). */
13088 valid_builtin_assignconv_identity_widening_p
(tree lhs_type
, tree rhs_type
)
13090 /* 5.1.1: This is the identity conversion part. */
13091 if
(lhs_type
== rhs_type
)
13094 /* Reject non primitive types and boolean conversions. */
13095 if
(!JNUMERIC_TYPE_P
(lhs_type
) ||
!JNUMERIC_TYPE_P
(rhs_type
))
13098 /* 5.1.2: widening primitive conversion. byte, even if it's smaller
13099 than a char can't be converted into a char. Short can't too, but
13100 the < test below takes care of that */
13101 if
(lhs_type
== char_type_node
&& rhs_type
== byte_type_node
)
13104 /* Accept all promoted type here. Note, we can't use <= in the test
13105 below, because we still need to bounce out assignments of short
13106 to char and the likes */
13107 if
(lhs_type
== int_type_node
13108 && (rhs_type
== promoted_byte_type_node
13109 || rhs_type
== promoted_short_type_node
13110 || rhs_type
== promoted_char_type_node
13111 || rhs_type
== promoted_boolean_type_node
))
13114 /* From here, an integral is widened if its precision is smaller
13115 than the precision of the LHS or if the LHS is a floating point
13116 type, or the RHS is a float and the RHS a double. */
13117 if
((JINTEGRAL_TYPE_P
(rhs_type
) && JINTEGRAL_TYPE_P
(lhs_type
)
13118 && (TYPE_PRECISION
(rhs_type
) < TYPE_PRECISION
(lhs_type
)))
13119 ||
(JINTEGRAL_TYPE_P
(rhs_type
) && JFLOAT_TYPE_P
(lhs_type
))
13120 ||
(rhs_type
== float_type_node
&& lhs_type
== double_type_node
))
13126 /* Check that something of SOURCE type can be assigned or cast to
13127 something of DEST type at runtime. Return 1 if the operation is
13128 valid, 0 otherwise. If CAST is set to 1, we're treating the case
13129 were SOURCE is cast into DEST, which borrows a lot of the
13130 assignment check. */
13133 valid_ref_assignconv_cast_p
(tree source
, tree dest
, int cast
)
13135 /* SOURCE or DEST might be null if not from a declared entity. */
13136 if
(!source ||
!dest
)
13138 if
(JNULLP_TYPE_P
(source
))
13140 if
(TREE_CODE
(source
) == POINTER_TYPE
)
13141 source
= TREE_TYPE
(source
);
13142 if
(TREE_CODE
(dest
) == POINTER_TYPE
)
13143 dest
= TREE_TYPE
(dest
);
13145 /* If source and dest are being compiled from bytecode, they may need to
13147 if
(CLASS_P
(source
) && !CLASS_LOADED_P
(source
))
13149 load_class
(source
, 1);
13150 safe_layout_class
(source
);
13152 if
(CLASS_P
(dest
) && !CLASS_LOADED_P
(dest
))
13154 load_class
(dest
, 1);
13155 safe_layout_class
(dest
);
13158 /* Case where SOURCE is a class type */
13159 if
(TYPE_CLASS_P
(source
))
13161 if
(TYPE_CLASS_P
(dest
))
13162 return
(source
== dest
13163 || inherits_from_p
(source
, dest
)
13164 ||
(cast
&& inherits_from_p
(dest
, source
)));
13165 if
(TYPE_INTERFACE_P
(dest
))
13167 /* If doing a cast and SOURCE is final, the operation is
13168 always correct a compile time (because even if SOURCE
13169 does not implement DEST, a subclass of SOURCE might). */
13170 if
(cast
&& !CLASS_FINAL
(TYPE_NAME
(source
)))
13172 /* Otherwise, SOURCE must implement DEST */
13173 return interface_of_p
(dest
, source
);
13175 /* DEST is an array, cast permitted if SOURCE is of Object type */
13176 return
(cast
&& source
== object_type_node ?
1 : 0);
13178 if
(TYPE_INTERFACE_P
(source
))
13180 if
(TYPE_CLASS_P
(dest
))
13182 /* If not casting, DEST must be the Object type */
13184 return dest
== object_type_node
;
13185 /* We're doing a cast. The cast is always valid is class
13186 DEST is not final, otherwise, DEST must implement SOURCE */
13187 else if
(!CLASS_FINAL
(TYPE_NAME
(dest
)))
13190 return interface_of_p
(source
, dest
);
13192 if
(TYPE_INTERFACE_P
(dest
))
13194 /* If doing a cast, then if SOURCE and DEST contain method
13195 with the same signature but different return type, then
13196 this is a (compile time) error */
13199 tree method_source
, method_dest
;
13203 for
(method_source
= TYPE_METHODS
(source
); method_source
;
13204 method_source
= TREE_CHAIN
(method_source
))
13207 build_java_argument_signature
(TREE_TYPE
(method_source
));
13208 source_type
= TREE_TYPE
(TREE_TYPE
(method_source
));
13209 source_name
= DECL_NAME
(method_source
);
13210 for
(method_dest
= TYPE_METHODS
(dest
);
13211 method_dest
; method_dest
= TREE_CHAIN
(method_dest
))
13213 build_java_argument_signature
(TREE_TYPE
(method_dest
))
13214 && source_name
== DECL_NAME
(method_dest
)
13215 && source_type
!= TREE_TYPE
(TREE_TYPE
(method_dest
)))
13221 return source
== dest || interface_of_p
(dest
, source
);
13227 && (DECL_NAME
(TYPE_NAME
(source
))
13228 == java_lang_cloneable_identifier_node
13229 ||
(DECL_NAME
(TYPE_NAME
(source
))
13230 == java_io_serializable_identifier_node
)));
13233 if
(TYPE_ARRAY_P
(source
))
13235 if
(TYPE_CLASS_P
(dest
))
13236 return dest
== object_type_node
;
13237 /* Can't cast an array to an interface unless the interface is
13238 java.lang.Cloneable or java.io.Serializable. */
13239 if
(TYPE_INTERFACE_P
(dest
))
13240 return
(DECL_NAME
(TYPE_NAME
(dest
))
13241 == java_lang_cloneable_identifier_node
13242 ||
(DECL_NAME
(TYPE_NAME
(dest
))
13243 == java_io_serializable_identifier_node
));
13246 tree source_element_type
= TYPE_ARRAY_ELEMENT
(source
);
13247 tree dest_element_type
= TYPE_ARRAY_ELEMENT
(dest
);
13249 /* In case of severe errors, they turn out null */
13250 if
(!dest_element_type ||
!source_element_type
)
13252 if
(source_element_type
== dest_element_type
)
13254 return valid_ref_assignconv_cast_p
(source_element_type
,
13255 dest_element_type
, cast
);
13263 valid_cast_to_p
(tree source
, tree dest
)
13265 if
(TREE_CODE
(source
) == POINTER_TYPE
)
13266 source
= TREE_TYPE
(source
);
13267 if
(TREE_CODE
(dest
) == POINTER_TYPE
)
13268 dest
= TREE_TYPE
(dest
);
13270 if
(TREE_CODE
(source
) == RECORD_TYPE
&& TREE_CODE
(dest
) == RECORD_TYPE
)
13271 return valid_ref_assignconv_cast_p
(source
, dest
, 1);
13273 else if
(JNUMERIC_TYPE_P
(source
) && JNUMERIC_TYPE_P
(dest
))
13276 else if
(TREE_CODE
(source
) == BOOLEAN_TYPE
13277 && TREE_CODE
(dest
) == BOOLEAN_TYPE
)
13284 do_unary_numeric_promotion
(tree arg
)
13286 tree type
= TREE_TYPE
(arg
);
13287 if
((TREE_CODE
(type
) == INTEGER_TYPE
&& TYPE_PRECISION
(type
) < 32)
13288 || TREE_CODE
(type
) == CHAR_TYPE
)
13289 arg
= convert
(int_type_node
, arg
);
13293 /* Return a nonzero value if SOURCE can be converted into DEST using
13294 the method invocation conversion rule (5.3). */
13296 valid_method_invocation_conversion_p
(tree dest
, tree source
)
13298 return
((JPRIMITIVE_TYPE_P
(source
) && JPRIMITIVE_TYPE_P
(dest
)
13299 && valid_builtin_assignconv_identity_widening_p
(dest
, source
))
13300 ||
((JREFERENCE_TYPE_P
(source
) || JNULLP_TYPE_P
(source
))
13301 && (JREFERENCE_TYPE_P
(dest
) || JNULLP_TYPE_P
(dest
))
13302 && valid_ref_assignconv_cast_p
(source
, dest
, 0)));
13305 /* Build an incomplete binop expression. */
13308 build_binop
(enum tree_code op
, int op_location
, tree op1
, tree op2
)
13310 tree binop
= build2
(op
, NULL_TREE
, op1
, op2
);
13311 TREE_SIDE_EFFECTS
(binop
) = 1;
13312 /* Store the location of the operator, for better error report. The
13313 string of the operator will be rebuild based on the OP value. */
13314 EXPR_WFL_LINECOL
(binop
) = op_location
;
13318 /* Build the string of the operator retained by NODE. If NODE is part
13319 of a compound expression, add an '=' at the end of the string. This
13320 function is called when an error needs to be reported on an
13321 operator. The string is returned as a pointer to a static character
13325 operator_string
(tree node
)
13327 #define BUILD_OPERATOR_STRING(S) \
13329 sprintf
(buffer
, "%s%s", S
, (COMPOUND_ASSIGN_P
(node
) ?
"=" : "")); \
13333 static char buffer
[10];
13334 switch
(TREE_CODE
(node
))
13336 case MULT_EXPR
: BUILD_OPERATOR_STRING
("*");
13337 case RDIV_EXPR
: BUILD_OPERATOR_STRING
("/");
13338 case TRUNC_MOD_EXPR
: BUILD_OPERATOR_STRING
("%");
13339 case PLUS_EXPR
: BUILD_OPERATOR_STRING
("+");
13340 case MINUS_EXPR
: BUILD_OPERATOR_STRING
("-");
13341 case LSHIFT_EXPR
: BUILD_OPERATOR_STRING
("<<");
13342 case RSHIFT_EXPR
: BUILD_OPERATOR_STRING
(">>");
13343 case URSHIFT_EXPR
: BUILD_OPERATOR_STRING
(">>>");
13344 case BIT_AND_EXPR
: BUILD_OPERATOR_STRING
("&");
13345 case BIT_XOR_EXPR
: BUILD_OPERATOR_STRING
("^");
13346 case BIT_IOR_EXPR
: BUILD_OPERATOR_STRING
("|");
13347 case TRUTH_ANDIF_EXPR
: BUILD_OPERATOR_STRING
("&&");
13348 case TRUTH_ORIF_EXPR
: BUILD_OPERATOR_STRING
("||");
13349 case EQ_EXPR
: BUILD_OPERATOR_STRING
("==");
13350 case NE_EXPR
: BUILD_OPERATOR_STRING
("!=");
13351 case GT_EXPR
: BUILD_OPERATOR_STRING
(">");
13352 case GE_EXPR
: BUILD_OPERATOR_STRING
(">=");
13353 case LT_EXPR
: BUILD_OPERATOR_STRING
("<");
13354 case LE_EXPR
: BUILD_OPERATOR_STRING
("<=");
13355 case UNARY_PLUS_EXPR
: BUILD_OPERATOR_STRING
("+");
13356 case NEGATE_EXPR
: BUILD_OPERATOR_STRING
("-");
13357 case TRUTH_NOT_EXPR
: BUILD_OPERATOR_STRING
("!");
13358 case BIT_NOT_EXPR
: BUILD_OPERATOR_STRING
("~");
13359 case PREINCREMENT_EXPR
: /* Fall through */
13360 case POSTINCREMENT_EXPR
: BUILD_OPERATOR_STRING
("++");
13361 case PREDECREMENT_EXPR
: /* Fall through */
13362 case POSTDECREMENT_EXPR
: BUILD_OPERATOR_STRING
("--");
13364 internal_error
("unregistered operator %s",
13365 tree_code_name
[TREE_CODE
(node
)]);
13368 #undef BUILD_OPERATOR_STRING
13371 /* Return 1 if VAR_ACCESS1 is equivalent to VAR_ACCESS2. */
13374 java_decl_equiv
(tree var_acc1
, tree var_acc2
)
13376 if
(JDECL_P
(var_acc1
))
13377 return
(var_acc1
== var_acc2
);
13379 return
(TREE_CODE
(var_acc1
) == COMPONENT_REF
13380 && TREE_CODE
(var_acc2
) == COMPONENT_REF
13381 && TREE_OPERAND
(TREE_OPERAND
(var_acc1
, 0), 0)
13382 == TREE_OPERAND
(TREE_OPERAND
(var_acc2
, 0), 0)
13383 && TREE_OPERAND
(var_acc1
, 1) == TREE_OPERAND
(var_acc2
, 1));
13386 /* Return a nonzero value if CODE is one of the operators that can be
13387 used in conjunction with the `=' operator in a compound assignment. */
13390 binop_compound_p
(enum tree_code code
)
13393 for
(i
= 0; i
< BINOP_COMPOUND_CANDIDATES
; i
++)
13394 if
(binop_lookup
[i
] == code
)
13397 return i
< BINOP_COMPOUND_CANDIDATES
;
13400 /* Reorganize after a fold to get SAVE_EXPR to generate what we want. */
13403 java_refold
(tree t
)
13405 tree c
, b
, ns
, decl
;
13407 if
(TREE_CODE
(t
) != MODIFY_EXPR
)
13410 c
= TREE_OPERAND
(t
, 1);
13411 if
(! (c
&& TREE_CODE
(c
) == COMPOUND_EXPR
13412 && TREE_CODE
(TREE_OPERAND
(c
, 0)) == MODIFY_EXPR
13413 && binop_compound_p
(TREE_CODE
(TREE_OPERAND
(c
, 1)))))
13416 /* Now the left branch of the binary operator. */
13417 b
= TREE_OPERAND
(TREE_OPERAND
(c
, 1), 0);
13418 if
(! (b
&& TREE_CODE
(b
) == NOP_EXPR
13419 && TREE_CODE
(TREE_OPERAND
(b
, 0)) == SAVE_EXPR
))
13422 ns
= TREE_OPERAND
(TREE_OPERAND
(b
, 0), 0);
13423 if
(! (ns
&& TREE_CODE
(ns
) == NOP_EXPR
13424 && TREE_CODE
(TREE_OPERAND
(ns
, 0)) == SAVE_EXPR
))
13427 decl
= TREE_OPERAND
(TREE_OPERAND
(ns
, 0), 0);
13428 if
((JDECL_P
(decl
) || TREE_CODE
(decl
) == COMPONENT_REF
)
13429 /* It's got to be the an equivalent decl */
13430 && java_decl_equiv
(decl
, TREE_OPERAND
(TREE_OPERAND
(c
, 0), 0)))
13432 /* Shorten the NOP_EXPR/SAVE_EXPR path. */
13433 TREE_OPERAND
(TREE_OPERAND
(c
, 1), 0) = TREE_OPERAND
(ns
, 0);
13434 /* Substitute the COMPOUND_EXPR by the BINOP_EXPR */
13435 TREE_OPERAND
(t
, 1) = TREE_OPERAND
(c
, 1);
13436 /* Change the right part of the BINOP_EXPR */
13437 TREE_OPERAND
(TREE_OPERAND
(t
, 1), 1) = TREE_OPERAND
(c
, 0);
13443 /* Binary operators (15.16 up to 15.18). We return error_mark_node on
13444 errors but we modify NODE so that it contains the type computed
13445 according to the expression, when it's fixed. Otherwise, we write
13446 error_mark_node as the type. It allows us to further the analysis
13447 of remaining nodes and detects more errors in certain cases. */
13450 patch_binop
(tree node
, tree wfl_op1
, tree wfl_op2
, int folding
)
13452 tree op1
= TREE_OPERAND
(node
, 0);
13453 tree op2
= TREE_OPERAND
(node
, 1);
13454 tree op1_type
= TREE_TYPE
(op1
);
13455 tree op2_type
= TREE_TYPE
(op2
);
13456 tree prom_type
= NULL_TREE
, cn
;
13457 enum tree_code code
= TREE_CODE
(node
);
13459 /* If 1, tell the routine that we have to return error_mark_node
13460 after checking for the initialization of the RHS */
13461 int error_found
= 0;
13463 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
13465 /* If either op<n>_type are NULL, this might be early signs of an
13466 error situation, unless it's too early to tell (in case we're
13467 handling a `+', `==', `!=' or `instanceof'.) We want to set op<n>_type
13468 correctly so the error can be later on reported accurately. */
13469 if
(! (code
== PLUS_EXPR || code
== NE_EXPR
13470 || code
== EQ_EXPR || code
== INSTANCEOF_EXPR
))
13475 n
= java_complete_tree
(op1
);
13476 op1_type
= TREE_TYPE
(n
);
13480 n
= java_complete_tree
(op2
);
13481 op2_type
= TREE_TYPE
(n
);
13487 /* 15.16 Multiplicative operators */
13488 case MULT_EXPR
: /* 15.16.1 Multiplication Operator * */
13489 case RDIV_EXPR
: /* 15.16.2 Division Operator / */
13490 case TRUNC_DIV_EXPR
: /* 15.16.2 Integral type Division Operator / */
13491 case TRUNC_MOD_EXPR
: /* 15.16.3 Remainder operator % */
13492 if
(!JNUMERIC_TYPE_P
(op1_type
) ||
!JNUMERIC_TYPE_P
(op2_type
))
13494 if
(!JNUMERIC_TYPE_P
(op1_type
))
13495 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op1_type
);
13496 if
(!JNUMERIC_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13497 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op2_type
);
13498 TREE_TYPE
(node
) = error_mark_node
;
13502 prom_type
= binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13504 /* Detect integral division by zero */
13505 if
((code
== RDIV_EXPR || code
== TRUNC_MOD_EXPR
)
13506 && TREE_CODE
(prom_type
) == INTEGER_TYPE
13507 && (op2
== integer_zero_node || op2
== long_zero_node ||
13508 (TREE_CODE
(op2
) == INTEGER_CST
&&
13509 ! TREE_INT_CST_LOW
(op2
) && ! TREE_INT_CST_HIGH
(op2
))))
13511 parse_warning_context
13513 "Evaluating this expression will result in an arithmetic exception being thrown");
13514 TREE_CONSTANT
(node
) = 0;
13515 TREE_INVARIANT
(node
) = 0;
13518 /* Change the division operator if necessary */
13519 if
(code
== RDIV_EXPR
&& TREE_CODE
(prom_type
) == INTEGER_TYPE
)
13520 TREE_SET_CODE
(node
, TRUNC_DIV_EXPR
);
13522 /* Before divisions as is disappear, try to simplify and bail if
13523 applicable, otherwise we won't perform even simple
13524 simplifications like (1-1)/3. We can't do that with floating
13525 point number, folds can't handle them at this stage. */
13526 if
(code
== RDIV_EXPR
&& TREE_CONSTANT
(op1
) && TREE_CONSTANT
(op2
)
13527 && JINTEGRAL_TYPE_P
(op1
) && JINTEGRAL_TYPE_P
(op2
))
13529 TREE_TYPE
(node
) = prom_type
;
13530 node
= fold
(node
);
13531 if
(TREE_CODE
(node
) != code
)
13535 if
(TREE_CODE
(prom_type
) == INTEGER_TYPE
13536 && flag_use_divide_subroutine
13537 && ! flag_emit_class_files
13538 && (code
== RDIV_EXPR || code
== TRUNC_MOD_EXPR
))
13539 return build_java_soft_divmod
(TREE_CODE
(node
), prom_type
, op1
, op2
);
13541 /* This one is more complicated. FLOATs are processed by a
13542 function call to soft_fmod. Duplicate the value of the
13543 COMPOUND_ASSIGN_P flag. */
13544 if
(code
== TRUNC_MOD_EXPR
)
13546 tree mod
= build_java_binop
(TRUNC_MOD_EXPR
, prom_type
, op1
, op2
);
13547 COMPOUND_ASSIGN_P
(mod
) = COMPOUND_ASSIGN_P
(node
);
13552 /* 15.17 Additive Operators */
13553 case PLUS_EXPR
: /* 15.17.1 String Concatenation Operator + */
13555 /* Operation is valid if either one argument is a string
13556 constant, a String object or a StringBuffer crafted for the
13557 purpose of the a previous usage of the String concatenation
13560 if
(TREE_CODE
(op1
) == STRING_CST
13561 || TREE_CODE
(op2
) == STRING_CST
13562 || JSTRING_TYPE_P
(op1_type
)
13563 || JSTRING_TYPE_P
(op2_type
)
13564 || IS_CRAFTED_STRING_BUFFER_P
(op1
)
13565 || IS_CRAFTED_STRING_BUFFER_P
(op2
))
13566 return build_string_concatenation
(op1
, op2
);
13568 case MINUS_EXPR
: /* 15.17.2 Additive Operators (+ and -) for
13570 if
(!JNUMERIC_TYPE_P
(op1_type
) ||
!JNUMERIC_TYPE_P
(op2_type
))
13572 if
(!JNUMERIC_TYPE_P
(op1_type
))
13573 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op1_type
);
13574 if
(!JNUMERIC_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13575 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op2_type
);
13576 TREE_TYPE
(node
) = error_mark_node
;
13580 prom_type
= binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13583 /* 15.18 Shift Operators */
13587 if
(!JINTEGRAL_TYPE_P
(op1_type
) ||
!JINTEGRAL_TYPE_P
(op2_type
))
13589 if
(!JINTEGRAL_TYPE_P
(op1_type
))
13590 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op1_type
);
13593 if
(JNUMERIC_TYPE_P
(op2_type
))
13594 parse_error_context
(wfl_operator
,
13595 "Incompatible type for %qs. Explicit cast needed to convert shift distance from %qs to integral",
13596 operator_string
(node
),
13597 lang_printable_name
(op2_type
, 0));
13599 parse_error_context
(wfl_operator
,
13600 "Incompatible type for %qs. Can't convert shift distance from %qs to integral",
13601 operator_string
(node
),
13602 lang_printable_name
(op2_type
, 0));
13604 TREE_TYPE
(node
) = error_mark_node
;
13609 /* Unary numeric promotion (5.6.1) is performed on each operand
13611 op1
= do_unary_numeric_promotion
(op1
);
13612 op2
= do_unary_numeric_promotion
(op2
);
13614 /* If the right hand side is of type `long', first cast it to
13616 if
(TREE_TYPE
(op2
) == long_type_node
)
13617 op2
= build1
(CONVERT_EXPR
, int_type_node
, op2
);
13619 /* The type of the shift expression is the type of the promoted
13620 type of the left-hand operand */
13621 prom_type
= TREE_TYPE
(op1
);
13623 /* Shift int only up to 0x1f and long up to 0x3f */
13624 if
(prom_type
== int_type_node
)
13625 op2
= fold
(build2
(BIT_AND_EXPR
, int_type_node
, op2
,
13626 build_int_cst
(NULL_TREE
, 0x1f)));
13628 op2
= fold
(build2
(BIT_AND_EXPR
, int_type_node
, op2
,
13629 build_int_cst
(NULL_TREE
, 0x3f)));
13631 /* The >>> operator is a >> operating on unsigned quantities */
13632 if
(code
== URSHIFT_EXPR
&& (folding ||
! flag_emit_class_files
))
13635 tree utype
= java_unsigned_type
(prom_type
);
13636 op1
= convert
(utype
, op1
);
13638 to_return
= fold_build2
(RSHIFT_EXPR
, utype
, op1
, op2
);
13639 to_return
= convert
(prom_type
, to_return
);
13640 /* Copy the original value of the COMPOUND_ASSIGN_P flag */
13641 COMPOUND_ASSIGN_P
(to_return
) = COMPOUND_ASSIGN_P
(node
);
13642 TREE_SIDE_EFFECTS
(to_return
)
13643 = TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13648 /* 15.19.1 Type Comparison Operator instanceof */
13649 case INSTANCEOF_EXPR
:
13651 TREE_TYPE
(node
) = boolean_type_node
;
13653 /* OP1_TYPE might be NULL when OP1 is a string constant. */
13654 if
((cn
= patch_string
(op1
)))
13657 op1_type
= TREE_TYPE
(op1
);
13659 if
(op1_type
== NULL_TREE
)
13662 if
(!(op2_type
= resolve_type_during_patch
(op2
)))
13663 return error_mark_node
;
13665 /* The first operand must be a reference type or the null type */
13666 if
(!JREFERENCE_TYPE_P
(op1_type
) && op1
!= null_pointer_node
)
13667 error_found
= 1; /* Error reported further below */
13669 /* The second operand must be a reference type */
13670 if
(!JREFERENCE_TYPE_P
(op2_type
))
13672 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op2
);
13673 parse_error_context
13674 (wfl_operator
, "Invalid argument %qs for %<instanceof%>",
13675 lang_printable_name
(op2_type
, 0));
13679 if
(!error_found
&& valid_ref_assignconv_cast_p
(op1_type
, op2_type
, 1))
13681 /* If the first operand is null, the result is always false */
13682 if
(op1
== null_pointer_node
)
13683 return boolean_false_node
;
13684 else if
(flag_emit_class_files
)
13686 TREE_OPERAND
(node
, 1) = op2_type
;
13687 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(op1
);
13690 /* Otherwise we have to invoke instance of to figure it out */
13692 return build_instanceof
(op1
, op2_type
);
13694 /* There is no way the expression operand can be an instance of
13695 the type operand. This is a compile time error. */
13698 char *t1
= xstrdup
(lang_printable_name
(op1_type
, 0));
13699 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
13700 parse_error_context
13701 (wfl_operator
, "Impossible for %qs to be instance of %qs",
13702 t1
, lang_printable_name
(op2_type
, 0));
13709 /* 15.21 Bitwise and Logical Operators */
13713 if
(JINTEGRAL_TYPE_P
(op1_type
) && JINTEGRAL_TYPE_P
(op2_type
))
13714 /* Binary numeric promotion is performed on both operand and the
13715 expression retain that type */
13716 prom_type
= binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13718 else if
(TREE_CODE
(op1_type
) == BOOLEAN_TYPE
13719 && TREE_CODE
(op1_type
) == BOOLEAN_TYPE
)
13720 /* The type of the bitwise operator expression is BOOLEAN */
13721 prom_type
= boolean_type_node
;
13724 if
(!JINTEGRAL_TYPE_P
(op1_type
))
13725 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op1_type
);
13726 if
(!JINTEGRAL_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13727 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op2_type
);
13728 TREE_TYPE
(node
) = error_mark_node
;
13730 /* Insert a break here if adding thing before the switch's
13731 break for this case */
13735 /* 15.22 Conditional-And Operator */
13736 case TRUTH_ANDIF_EXPR
:
13737 /* 15.23 Conditional-Or Operator */
13738 case TRUTH_ORIF_EXPR
:
13739 /* Operands must be of BOOLEAN type */
13740 if
(TREE_CODE
(op1_type
) != BOOLEAN_TYPE ||
13741 TREE_CODE
(op2_type
) != BOOLEAN_TYPE
)
13743 if
(TREE_CODE
(op1_type
) != BOOLEAN_TYPE
)
13744 ERROR_CANT_CONVERT_TO_BOOLEAN
(wfl_operator
, node
, op1_type
);
13745 if
(TREE_CODE
(op2_type
) != BOOLEAN_TYPE
&& (op1_type
!= op2_type
))
13746 ERROR_CANT_CONVERT_TO_BOOLEAN
(wfl_operator
, node
, op2_type
);
13747 TREE_TYPE
(node
) = boolean_type_node
;
13751 else if
(integer_zerop
(op1
))
13753 return code
== TRUTH_ANDIF_EXPR ? op1
: op2
;
13755 else if
(integer_onep
(op1
))
13757 return code
== TRUTH_ANDIF_EXPR ? op2
: op1
;
13759 /* The type of the conditional operators is BOOLEAN */
13760 prom_type
= boolean_type_node
;
13763 /* 15.19.1 Numerical Comparison Operators <, <=, >, >= */
13768 /* The type of each of the operands must be a primitive numeric
13770 if
(!JNUMERIC_TYPE_P
(op1_type
) ||
! JNUMERIC_TYPE_P
(op2_type
))
13772 if
(!JNUMERIC_TYPE_P
(op1_type
))
13773 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op1_type
);
13774 if
(!JNUMERIC_TYPE_P
(op2_type
) && (op1_type
!= op2_type
))
13775 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op2_type
);
13776 TREE_TYPE
(node
) = boolean_type_node
;
13780 /* Binary numeric promotion is performed on the operands */
13781 binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13782 /* The type of the relation expression is always BOOLEAN */
13783 prom_type
= boolean_type_node
;
13786 /* 15.20 Equality Operator */
13789 /* It's time for us to patch the strings. */
13790 if
((cn
= patch_string
(op1
)))
13793 op1_type
= TREE_TYPE
(op1
);
13795 if
((cn
= patch_string
(op2
)))
13798 op2_type
= TREE_TYPE
(op2
);
13801 /* 15.20.1 Numerical Equality Operators == and != */
13802 /* Binary numeric promotion is performed on the operands */
13803 if
(JNUMERIC_TYPE_P
(op1_type
) && JNUMERIC_TYPE_P
(op2_type
))
13804 binary_numeric_promotion
(op1_type
, op2_type
, &op1
, &op2
);
13806 /* 15.20.2 Boolean Equality Operators == and != */
13807 else if
(TREE_CODE
(op1_type
) == BOOLEAN_TYPE
&&
13808 TREE_CODE
(op2_type
) == BOOLEAN_TYPE
)
13809 ; /* Nothing to do here */
13811 /* 15.20.3 Reference Equality Operators == and != */
13812 /* Types have to be either references or the null type. If
13813 they're references, it must be possible to convert either
13814 type to the other by casting conversion. */
13815 else if
((op1
== null_pointer_node
&& op2
== null_pointer_node
)
13816 ||
(op1
== null_pointer_node
&& JREFERENCE_TYPE_P
(op2_type
))
13817 ||
(JREFERENCE_TYPE_P
(op1_type
) && op2
== null_pointer_node
)
13818 ||
(JREFERENCE_TYPE_P
(op1_type
) && JREFERENCE_TYPE_P
(op2_type
)
13819 && (valid_ref_assignconv_cast_p
(op1_type
, op2_type
, 1)
13820 || valid_ref_assignconv_cast_p
(op2_type
,
13822 ; /* Nothing to do here */
13824 /* Else we have an error figure what can't be converted into
13825 what and report the error */
13829 t1
= xstrdup
(lang_printable_name
(op1_type
, 0));
13830 parse_error_context
13832 "Incompatible type for %qs. Can't convert %qs to %qs",
13833 operator_string
(node
), t1
,
13834 lang_printable_name
(op2_type
, 0));
13836 TREE_TYPE
(node
) = boolean_type_node
;
13840 prom_type
= boolean_type_node
;
13847 return error_mark_node
;
13849 TREE_OPERAND
(node
, 0) = op1
;
13850 TREE_OPERAND
(node
, 1) = op2
;
13851 TREE_TYPE
(node
) = prom_type
;
13852 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13854 /* fold does not respect side-effect order as required for Java but not C.
13855 * Also, it sometimes create SAVE_EXPRs which are bad when emitting
13858 if
(flag_emit_class_files ?
(TREE_CONSTANT
(op1
) && TREE_CONSTANT
(op2
))
13859 : ! TREE_SIDE_EFFECTS
(node
))
13860 node
= fold
(node
);
13864 /* Concatenate the STRING_CST CSTE and STRING. When AFTER is a non
13865 zero value, the value of CSTE comes after the valude of STRING */
13868 do_merge_string_cste
(tree cste
, const char *string, int string_len
, int after
)
13870 const char *old
= TREE_STRING_POINTER
(cste
);
13871 int old_len
= TREE_STRING_LENGTH
(cste
);
13872 int len
= old_len
+ string_len
;
13873 char *new
= alloca
(len
+1);
13877 memcpy
(new
, string, string_len
);
13878 memcpy
(&new
[string_len
], old
, old_len
);
13882 memcpy
(new
, old
, old_len
);
13883 memcpy
(&new
[old_len
], string, string_len
);
13886 return build_string
(len
, new
);
13889 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
13890 new STRING_CST on success, NULL_TREE on failure. */
13893 merge_string_cste
(tree op1
, tree op2
, int after
)
13895 /* Handle two string constants right away. */
13896 if
(TREE_CODE
(op2
) == STRING_CST
)
13897 return do_merge_string_cste
(op1
, TREE_STRING_POINTER
(op2
),
13898 TREE_STRING_LENGTH
(op2
), after
);
13900 /* Reasonable integer constant can be treated right away. */
13901 if
(TREE_CODE
(op2
) == INTEGER_CST
&& !TREE_CONSTANT_OVERFLOW
(op2
))
13903 static const char *const boolean_true
= "true";
13904 static const char *const boolean_false
= "false";
13905 static const char *const null_pointer
= "null";
13907 const char *string;
13909 if
(op2
== boolean_true_node
)
13910 string = boolean_true
;
13911 else if
(op2
== boolean_false_node
)
13912 string = boolean_false
;
13913 else if
(op2
== null_pointer_node
13914 ||
(integer_zerop
(op2
)
13915 && TREE_CODE
(TREE_TYPE
(op2
)) == POINTER_TYPE
))
13916 /* FIXME: null is not a compile-time constant, so it is only safe to
13917 merge if the overall expression is non-constant. However, this
13918 code always merges without checking the overall expression. */
13919 string = null_pointer
;
13920 else if
(TREE_TYPE
(op2
) == char_type_node
)
13922 /* Convert the character into UTF-8. */
13923 unsigned int c
= (unsigned int) TREE_INT_CST_LOW
(op2
);
13924 unsigned char *p
= (unsigned char *) ch
;
13925 if
(0x01 <= c
&& c
<= 0x7f)
13926 *p
++ = (unsigned char) c
;
13927 else if
(c
< 0x7ff)
13929 *p
++ = (unsigned char) (c
>> 6 |
0xc0);
13930 *p
++ = (unsigned char) ((c
& 0x3f) |
0x80);
13934 *p
++ = (unsigned char) (c
>> 12 |
0xe0);
13935 *p
++ = (unsigned char) (((c
>> 6) & 0x3f) |
0x80);
13936 *p
++ = (unsigned char) ((c
& 0x3f) |
0x80);
13943 string = string_convert_int_cst
(op2
);
13945 return do_merge_string_cste
(op1
, string, strlen
(string), after
);
13950 /* Tries to statically concatenate OP1 and OP2 if possible. Either one
13951 has to be a STRING_CST and the other part must be a STRING_CST or a
13952 INTEGRAL constant. Return a new STRING_CST if the operation
13953 succeed, NULL_TREE otherwise.
13955 If the case we want to optimize for space, we might want to return
13956 NULL_TREE for each invocation of this routine. FIXME */
13959 string_constant_concatenation
(tree op1
, tree op2
)
13961 if
(TREE_CODE
(op1
) == STRING_CST ||
(TREE_CODE
(op2
) == STRING_CST
))
13966 string = (TREE_CODE
(op1
) == STRING_CST ? op1
: op2
);
13967 rest
= (string == op1 ? op2
: op1
);
13968 invert
= (string == op1 ?
0 : 1 );
13970 /* Walk REST, only if it looks reasonable */
13971 if
(TREE_CODE
(rest
) != STRING_CST
13972 && !IS_CRAFTED_STRING_BUFFER_P
(rest
)
13973 && !JSTRING_TYPE_P
(TREE_TYPE
(rest
))
13974 && TREE_CODE
(rest
) == EXPR_WITH_FILE_LOCATION
)
13976 rest
= java_complete_tree
(rest
);
13977 if
(rest
== error_mark_node
)
13978 return error_mark_node
;
13979 rest
= fold
(rest
);
13981 return merge_string_cste
(string, rest
, invert
);
13986 /* Implement the `+' operator. Does static optimization if possible,
13987 otherwise create (if necessary) and append elements to a
13988 StringBuffer. The StringBuffer will be carried around until it is
13989 used for a function call or an assignment. Then toString() will be
13990 called on it to turn it into a String object. */
13993 build_string_concatenation
(tree op1
, tree op2
)
13996 int side_effects
= TREE_SIDE_EFFECTS
(op1
) | TREE_SIDE_EFFECTS
(op2
);
13998 /* Try to do some static optimization */
13999 if
((result
= string_constant_concatenation
(op1
, op2
)))
14002 /* Discard empty strings on either side of the expression */
14003 if
(TREE_CODE
(op1
) == STRING_CST
&& TREE_STRING_LENGTH
(op1
) == 0)
14008 else if
(TREE_CODE
(op2
) == STRING_CST
&& TREE_STRING_LENGTH
(op2
) == 0)
14011 /* If operands are string constant, turn then into object references */
14012 if
(TREE_CODE
(op1
) == STRING_CST
)
14013 op1
= patch_string_cst
(op1
);
14014 if
(op2
&& TREE_CODE
(op2
) == STRING_CST
)
14015 op2
= patch_string_cst
(op2
);
14017 /* If either one of the constant is null and the other non null
14018 operand is a String constant, return it. */
14019 if
((TREE_CODE
(op1
) == STRING_CST
) && !op2
)
14022 /* If OP1 isn't already a StringBuffer, create and
14023 initialize a new one */
14024 if
(!IS_CRAFTED_STRING_BUFFER_P
(op1
))
14026 /* Two solutions here:
14027 1) OP1 is a constant string reference, we call new StringBuffer(OP1)
14028 2) OP1 is something else, we call new StringBuffer().append(OP1). */
14029 if
(TREE_CONSTANT
(op1
) && JSTRING_TYPE_P
(TREE_TYPE
(op1
)))
14030 op1
= BUILD_STRING_BUFFER
(op1
);
14033 tree aNew
= BUILD_STRING_BUFFER
(NULL_TREE
);
14034 op1
= make_qualified_primary
(aNew
, BUILD_APPEND
(op1
), 0);
14040 /* OP1 is no longer the last node holding a crafted StringBuffer */
14041 IS_CRAFTED_STRING_BUFFER_P
(op1
) = 0;
14042 /* Create a node for `{new...,xxx}.append (op2)' */
14043 op1
= make_qualified_primary
(op1
, BUILD_APPEND
(op2
), 0);
14046 /* Mark the last node holding a crafted StringBuffer */
14047 IS_CRAFTED_STRING_BUFFER_P
(op1
) = 1;
14049 TREE_SIDE_EFFECTS
(op1
) = side_effects
;
14053 /* Patch the string node NODE. NODE can be a STRING_CST of a crafted
14054 StringBuffer. If no string were found to be patched, return
14058 patch_string
(tree node
)
14060 if
(node
== error_mark_node
)
14061 return error_mark_node
;
14062 if
(TREE_CODE
(node
) == STRING_CST
)
14063 return patch_string_cst
(node
);
14064 else if
(IS_CRAFTED_STRING_BUFFER_P
(node
))
14066 int saved
= ctxp
->explicit_constructor_p
;
14067 tree invoke
= build_method_invocation
(wfl_to_string
, NULL_TREE
);
14069 /* Temporary disable forbid the use of `this'. */
14070 ctxp
->explicit_constructor_p
= 0;
14071 ret
= java_complete_tree
(make_qualified_primary
(node
, invoke
, 0));
14072 /* String concatenation arguments must be evaluated in order too. */
14073 ret
= force_evaluation_order
(ret
);
14074 /* Restore it at its previous value */
14075 ctxp
->explicit_constructor_p
= saved
;
14081 /* Build the internal representation of a string constant. */
14084 patch_string_cst
(tree node
)
14087 if
(! flag_emit_class_files
)
14089 node
= get_identifier
(TREE_STRING_POINTER
(node
));
14090 location
= alloc_name_constant
(CONSTANT_String
, node
);
14091 node
= build_ref_from_constant_pool
(location
);
14093 TREE_CONSTANT
(node
) = 1;
14094 TREE_INVARIANT
(node
) = 1;
14096 /* ??? Guessing that the class file code can't handle casts. */
14097 if
(! flag_emit_class_files
)
14098 node
= convert
(string_ptr_type_node
, node
);
14100 TREE_TYPE
(node
) = string_ptr_type_node
;
14105 /* Build an incomplete unary operator expression. */
14108 build_unaryop
(int op_token
, int op_location
, tree op1
)
14114 case PLUS_TK
: op
= UNARY_PLUS_EXPR
; break
;
14115 case MINUS_TK
: op
= NEGATE_EXPR
; break
;
14116 case NEG_TK
: op
= TRUTH_NOT_EXPR
; break
;
14117 case NOT_TK
: op
= BIT_NOT_EXPR
; break
;
14121 unaryop
= build1
(op
, NULL_TREE
, op1
);
14122 TREE_SIDE_EFFECTS
(unaryop
) = 1;
14123 /* Store the location of the operator, for better error report. The
14124 string of the operator will be rebuild based on the OP value. */
14125 EXPR_WFL_LINECOL
(unaryop
) = op_location
;
14129 /* Special case for the ++/-- operators, since they require an extra
14130 argument to build, which is set to NULL and patched
14131 later. IS_POST_P is 1 if the operator, 0 otherwise. */
14134 build_incdec
(int op_token
, int op_location
, tree op1
, int is_post_p
)
14136 static const enum tree_code lookup
[2][2] =
14138 { PREDECREMENT_EXPR
, PREINCREMENT_EXPR
, },
14139 { POSTDECREMENT_EXPR
, POSTINCREMENT_EXPR
, },
14141 tree node
= build2
(lookup
[is_post_p
][(op_token
- DECR_TK
)],
14142 NULL_TREE
, op1
, NULL_TREE
);
14143 TREE_SIDE_EFFECTS
(node
) = 1;
14144 /* Store the location of the operator, for better error report. The
14145 string of the operator will be rebuild based on the OP value. */
14146 EXPR_WFL_LINECOL
(node
) = op_location
;
14150 /* Build an incomplete cast operator, based on the use of the
14151 CONVERT_EXPR. Note that TREE_TYPE of the constructed node is
14152 set. java_complete_tree is trained to walk a CONVERT_EXPR even
14153 though its type is already set. */
14156 build_cast
(int location
, tree type
, tree exp
)
14158 tree node
= build1
(CONVERT_EXPR
, type
, exp
);
14159 EXPR_WFL_LINECOL
(node
) = location
;
14163 /* Build an incomplete class reference operator. */
14165 build_incomplete_class_ref
(int location
, tree class_name
)
14167 tree node
= build1
(CLASS_LITERAL
, NULL_TREE
, class_name
);
14168 tree class_decl
= GET_CPC
();
14169 tree this_class
= TREE_TYPE
(class_decl
);
14171 /* Generate the synthetic static method `class$'. (Previously we
14172 deferred this, causing different method tables to be emitted
14173 for native code and bytecode.) */
14174 if
(!TYPE_DOT_CLASS
(this_class
)
14175 && !JPRIMITIVE_TYPE_P
(class_name
)
14176 && !(TREE_CODE
(class_name
) == VOID_TYPE
))
14178 tree cpc_list
= GET_CPC_LIST
();
14179 tree cpc
= cpc_list
;
14182 /* For inner classes, add a 'class$' method to their outermost
14183 context, creating it if necessary. */
14185 while
(GET_NEXT_ENCLOSING_CPC
(cpc
))
14186 cpc
= GET_NEXT_ENCLOSING_CPC
(cpc
);
14187 class_decl
= TREE_VALUE
(cpc
);
14189 target_class
= TREE_TYPE
(class_decl
);
14191 if
(CLASS_INTERFACE
(TYPE_NAME
(target_class
)))
14193 /* For interfaces, adding a static 'class$' method directly
14194 is illegal. So create an inner class to contain the new
14195 method. Empirically this matches the behavior of javac. */
14197 /* We want the generated inner class inside the outermost class. */
14198 GET_CPC_LIST
() = cpc
;
14199 t
= build_wfl_node
(DECL_NAME
(TYPE_NAME
(object_type_node
)));
14200 inner
= create_anonymous_class
(t
);
14201 target_class
= TREE_TYPE
(inner
);
14202 end_class_declaration
(1);
14203 GET_CPC_LIST
() = cpc_list
;
14206 if
(TYPE_DOT_CLASS
(target_class
) == NULL_TREE
)
14207 build_dot_class_method
(target_class
);
14209 if
(this_class
!= target_class
)
14210 TYPE_DOT_CLASS
(this_class
) = TYPE_DOT_CLASS
(target_class
);
14213 EXPR_WFL_LINECOL
(node
) = location
;
14217 /* Complete an incomplete class reference operator. */
14219 patch_incomplete_class_ref
(tree node
)
14221 tree type
= TREE_OPERAND
(node
, 0);
14224 if
(!(ref_type
= resolve_type_during_patch
(type
)))
14225 return error_mark_node
;
14227 /* If we're not emitting class files and we know ref_type is a
14228 compiled class, build a direct reference. */
14229 if
((! flag_emit_class_files
&& is_compiled_class
(ref_type
))
14230 || JPRIMITIVE_TYPE_P
(ref_type
)
14231 || TREE_CODE
(ref_type
) == VOID_TYPE
)
14233 tree dot
= build_class_ref
(ref_type
);
14234 /* A class referenced by `foo.class' is initialized. */
14235 if
(!flag_emit_class_files
)
14236 dot
= build_class_init
(ref_type
, dot
);
14237 return java_complete_tree
(dot
);
14240 /* If we're emitting class files and we have to deal with non
14241 primitive types, we invoke the synthetic static method `class$'. */
14242 ref_type
= build_dot_class_method_invocation
(current_class
, ref_type
);
14243 return java_complete_tree
(ref_type
);
14246 /* 15.14 Unary operators. We return error_mark_node in case of error,
14247 but preserve the type of NODE if the type is fixed. */
14250 patch_unaryop
(tree node
, tree wfl_op
)
14252 tree op
= TREE_OPERAND
(node
, 0);
14253 tree op_type
= TREE_TYPE
(op
);
14254 tree prom_type
= NULL_TREE
, value
, decl
;
14255 int nested_field_flag
= 0;
14256 int code
= TREE_CODE
(node
);
14257 int error_found
= 0;
14259 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14263 /* 15.13.2 Postfix Increment Operator ++ */
14264 case POSTINCREMENT_EXPR
:
14265 /* 15.13.3 Postfix Increment Operator -- */
14266 case POSTDECREMENT_EXPR
:
14267 /* 15.14.1 Prefix Increment Operator ++ */
14268 case PREINCREMENT_EXPR
:
14269 /* 15.14.2 Prefix Decrement Operator -- */
14270 case PREDECREMENT_EXPR
:
14271 op
= decl
= extract_field_decl
(op
);
14273 = nested_field_expanded_access_p
(op
, NULL
, NULL
, NULL
);
14274 /* We might be trying to change an outer field accessed using
14276 if
(nested_field_flag
)
14278 /* Retrieve the decl of the field we're trying to access. We
14279 do that by first retrieving the function we would call to
14280 access the field. It has been already verified that this
14281 field isn't final */
14282 if
(flag_emit_class_files
)
14283 decl
= TREE_OPERAND
(op
, 0);
14285 decl
= TREE_OPERAND
(TREE_OPERAND
(TREE_OPERAND
(op
, 0), 0), 0);
14286 decl
= DECL_FUNCTION_ACCESS_DECL
(decl
);
14288 /* We really should have a JAVA_ARRAY_EXPR to avoid this */
14289 else if
(!JDECL_P
(decl
)
14290 && TREE_CODE
(decl
) != COMPONENT_REF
14291 && !(flag_emit_class_files
&& TREE_CODE
(decl
) == ARRAY_REF
)
14292 && TREE_CODE
(decl
) != INDIRECT_REF
14293 && !(TREE_CODE
(decl
) == COMPOUND_EXPR
14294 && TREE_OPERAND
(decl
, 1)
14295 && (TREE_CODE
(TREE_OPERAND
(decl
, 1)) == INDIRECT_REF
)))
14297 TREE_TYPE
(node
) = error_mark_node
;
14301 /* From now on, we know that op if a variable and that it has a
14302 valid wfl. We use wfl_op to locate errors related to the
14304 if
(!JNUMERIC_TYPE_P
(op_type
))
14306 parse_error_context
14307 (wfl_op
, "Invalid argument type %qs to %qs",
14308 lang_printable_name
(op_type
, 0), operator_string
(node
));
14309 TREE_TYPE
(node
) = error_mark_node
;
14314 /* Before the addition, binary numeric promotion is performed on
14315 both operands, if really necessary */
14316 if
(JINTEGRAL_TYPE_P
(op_type
))
14318 value
= build_int_cst
(op_type
, 1);
14319 TREE_TYPE
(node
) = op_type
;
14323 value
= build_int_cst
(NULL_TREE
, 1);
14325 binary_numeric_promotion
(op_type
,
14326 TREE_TYPE
(value
), &op
, &value
);
14329 /* We remember we might be accessing an outer field */
14330 if
(nested_field_flag
)
14332 /* We re-generate an access to the field */
14333 value
= build2
(PLUS_EXPR
, TREE_TYPE
(op
),
14334 build_nested_field_access
(wfl_op
, decl
), value
);
14336 /* And we patch the original access$() into a write
14337 with plus_op as a rhs */
14338 return nested_field_access_fix
(node
, op
, value
);
14341 /* And write back into the node. */
14342 TREE_OPERAND
(node
, 0) = op
;
14343 TREE_OPERAND
(node
, 1) = value
;
14344 /* Convert the overall back into its original type, if
14345 necessary, and return */
14346 if
(JINTEGRAL_TYPE_P
(op_type
))
14347 return fold
(node
);
14349 return fold
(convert
(op_type
, node
));
14353 /* 15.14.3 Unary Plus Operator + */
14354 case UNARY_PLUS_EXPR
:
14355 /* 15.14.4 Unary Minus Operator - */
14357 if
(!JNUMERIC_TYPE_P
(op_type
))
14359 ERROR_CANT_CONVERT_TO_NUMERIC
(wfl_operator
, node
, op_type
);
14360 TREE_TYPE
(node
) = error_mark_node
;
14363 /* Unary numeric promotion is performed on operand */
14366 op
= do_unary_numeric_promotion
(op
);
14367 prom_type
= TREE_TYPE
(op
);
14368 if
(code
== UNARY_PLUS_EXPR
)
14373 /* 15.14.5 Bitwise Complement Operator ~ */
14375 if
(!JINTEGRAL_TYPE_P
(op_type
))
14377 ERROR_CAST_NEEDED_TO_INTEGRAL
(wfl_operator
, node
, op_type
);
14378 TREE_TYPE
(node
) = error_mark_node
;
14383 op
= do_unary_numeric_promotion
(op
);
14384 prom_type
= TREE_TYPE
(op
);
14388 /* 15.14.6 Logical Complement Operator ! */
14389 case TRUTH_NOT_EXPR
:
14390 if
(TREE_CODE
(op_type
) != BOOLEAN_TYPE
)
14392 ERROR_CANT_CONVERT_TO_BOOLEAN
(wfl_operator
, node
, op_type
);
14393 /* But the type is known. We will report an error if further
14394 attempt of a assignment is made with this rhs */
14395 TREE_TYPE
(node
) = boolean_type_node
;
14399 prom_type
= boolean_type_node
;
14402 /* 15.15 Cast Expression */
14404 value
= patch_cast
(node
, wfl_operator
);
14405 if
(value
== error_mark_node
)
14407 /* If this cast is part of an assignment, we tell the code
14408 that deals with it not to complain about a mismatch,
14409 because things have been cast, anyways */
14410 TREE_TYPE
(node
) = error_mark_node
;
14415 value
= fold
(value
);
14421 /* This can only happen when the type is already known. */
14422 gcc_assert
(TREE_TYPE
(node
) != NULL_TREE
);
14423 prom_type
= TREE_TYPE
(node
);
14428 return error_mark_node
;
14430 /* There are cases where node has been replaced by something else
14431 and we don't end up returning here: UNARY_PLUS_EXPR,
14432 CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
14433 TREE_OPERAND
(node
, 0) = fold
(op
);
14434 TREE_TYPE
(node
) = prom_type
;
14435 TREE_SIDE_EFFECTS
(node
) = TREE_SIDE_EFFECTS
(op
);
14436 return fold
(node
);
14439 /* Generic type resolution that sometimes takes place during node
14440 patching. Returned the resolved type or generate an error
14441 message. Return the resolved type or NULL_TREE. */
14444 resolve_type_during_patch
(tree type
)
14446 if
(unresolved_type_p
(type
, NULL
))
14448 tree type_decl
= resolve_and_layout
(EXPR_WFL_NODE
(type
), type
);
14451 parse_error_context
(type
,
14452 "Class %qs not found in type declaration",
14453 IDENTIFIER_POINTER
(EXPR_WFL_NODE
(type
)));
14457 check_deprecation
(type
, type_decl
);
14459 return TREE_TYPE
(type_decl
);
14464 /* 5.5 Casting Conversion. error_mark_node is returned if an error is
14465 found. Otherwise NODE or something meant to replace it is returned. */
14468 patch_cast
(tree node
, tree wfl_op
)
14470 tree op
= TREE_OPERAND
(node
, 0);
14471 tree cast_type
= TREE_TYPE
(node
);
14472 tree patched
, op_type
;
14475 /* Some string patching might be necessary at this stage */
14476 if
((patched
= patch_string
(op
)))
14477 TREE_OPERAND
(node
, 0) = op
= patched
;
14478 op_type
= TREE_TYPE
(op
);
14480 /* First resolve OP_TYPE if unresolved */
14481 if
(!(cast_type
= resolve_type_during_patch
(cast_type
)))
14482 return error_mark_node
;
14484 /* Check on cast that are proven correct at compile time */
14485 if
(JNUMERIC_TYPE_P
(cast_type
) && JNUMERIC_TYPE_P
(op_type
))
14488 if
(cast_type
== op_type
)
14491 /* A narrowing conversion from a floating-point number to an
14492 integral type requires special handling (5.1.3). */
14493 if
(JFLOAT_TYPE_P
(op_type
) && JINTEGRAL_TYPE_P
(cast_type
))
14494 if
(cast_type
!= long_type_node
)
14495 op
= convert
(integer_type_node
, op
);
14497 /* Try widening/narrowing conversion. Potentially, things need
14498 to be worked out in gcc so we implement the extreme cases
14499 correctly. fold_convert() needs to be fixed. */
14500 return convert
(cast_type
, op
);
14503 /* It's also valid to cast a boolean into a boolean */
14504 if
(op_type
== boolean_type_node
&& cast_type
== boolean_type_node
)
14507 /* null can be casted to references */
14508 if
(op
== null_pointer_node
&& JREFERENCE_TYPE_P
(cast_type
))
14509 return build_null_of_type
(cast_type
);
14511 /* The remaining legal casts involve conversion between reference
14512 types. Check for their compile time correctness. */
14513 if
(JREFERENCE_TYPE_P
(op_type
) && JREFERENCE_TYPE_P
(cast_type
)
14514 && valid_ref_assignconv_cast_p
(op_type
, cast_type
, 1))
14516 TREE_TYPE
(node
) = promote_type
(cast_type
);
14517 /* Now, the case can be determined correct at compile time if
14518 OP_TYPE can be converted into CAST_TYPE by assignment
14519 conversion (5.2) */
14521 if
(valid_ref_assignconv_cast_p
(op_type
, cast_type
, 0))
14523 TREE_SET_CODE
(node
, NOP_EXPR
);
14527 if
(flag_emit_class_files
)
14529 TREE_SET_CODE
(node
, CONVERT_EXPR
);
14533 /* The cast requires a run-time check */
14534 return build3
(CALL_EXPR
, promote_type
(cast_type
),
14535 build_address_of
(soft_checkcast_node
),
14536 tree_cons
(NULL_TREE
, build_class_ref
(cast_type
),
14537 build_tree_list
(NULL_TREE
, op
)),
14541 /* Any other casts are proven incorrect at compile time */
14542 t1
= xstrdup
(lang_printable_name
(op_type
, 0));
14543 parse_error_context
(wfl_op
, "Invalid cast from %qs to %qs",
14544 t1
, lang_printable_name
(cast_type
, 0));
14546 return error_mark_node
;
14549 /* Build a null constant and give it the type TYPE. */
14552 build_null_of_type
(tree type
)
14554 tree node
= build_int_cst
(promote_type
(type
), 0);
14558 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
14559 a list of indices. */
14561 build_array_ref
(int location
, tree array
, tree index
)
14563 tree node
= build4
(ARRAY_REF
, NULL_TREE
, array
, index
,
14564 NULL_TREE
, NULL_TREE
);
14565 EXPR_WFL_LINECOL
(node
) = location
;
14569 /* 15.12 Array Access Expression */
14572 patch_array_ref
(tree node
)
14574 tree array
= TREE_OPERAND
(node
, 0);
14575 tree array_type
= TREE_TYPE
(array
);
14576 tree index
= TREE_OPERAND
(node
, 1);
14577 tree index_type
= TREE_TYPE
(index
);
14578 int error_found
= 0;
14580 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14582 if
(TREE_CODE
(array_type
) == POINTER_TYPE
)
14583 array_type
= TREE_TYPE
(array_type
);
14585 /* The array reference must be an array */
14586 if
(!TYPE_ARRAY_P
(array_type
))
14588 parse_error_context
14590 "%<[]%> can only be applied to arrays. It can't be applied to %qs",
14591 lang_printable_name
(array_type
, 0));
14592 TREE_TYPE
(node
) = error_mark_node
;
14596 /* The array index undergoes unary numeric promotion. The promoted
14597 type must be int */
14598 index
= do_unary_numeric_promotion
(index
);
14599 if
(TREE_TYPE
(index
) != int_type_node
)
14601 if
(valid_cast_to_p
(index_type
, int_type_node
))
14602 parse_error_context
(wfl_operator
,
14603 "Incompatible type for %<[]%>. Explicit cast needed to convert %qs to %<int%>",
14604 lang_printable_name
(index_type
, 0));
14606 parse_error_context
(wfl_operator
,
14607 "Incompatible type for %<[]%>. Can't convert %qs to %<int%>",
14608 lang_printable_name
(index_type
, 0));
14609 TREE_TYPE
(node
) = error_mark_node
;
14614 return error_mark_node
;
14616 array_type
= TYPE_ARRAY_ELEMENT
(array_type
);
14618 if
(flag_emit_class_files
)
14620 TREE_OPERAND
(node
, 0) = array
;
14621 TREE_OPERAND
(node
, 1) = index
;
14624 node
= build_java_arrayaccess
(array
, array_type
, index
);
14625 TREE_TYPE
(node
) = array_type
;
14629 /* 15.9 Array Creation Expressions */
14632 build_newarray_node
(tree type
, tree dims
, int extra_dims
)
14634 tree node
= build3
(NEW_ARRAY_EXPR
, NULL_TREE
, type
,
14636 build_int_cst
(NULL_TREE
, extra_dims
));
14641 patch_newarray
(tree node
)
14643 tree type
= TREE_OPERAND
(node
, 0);
14644 tree dims
= TREE_OPERAND
(node
, 1);
14645 tree cdim
, array_type
;
14646 int error_found
= 0;
14648 int xdims
= TREE_INT_CST_LOW
(TREE_OPERAND
(node
, 2));
14650 /* Dimension types are verified. It's better for the types to be
14651 verified in order. */
14652 for
(cdim
= dims
, ndims
= 0; cdim
; cdim
= TREE_CHAIN
(cdim
), ndims
++ )
14655 tree dim
= TREE_VALUE
(cdim
);
14657 /* Dim might have been saved during its evaluation */
14658 dim
= (TREE_CODE
(dim
) == SAVE_EXPR ? TREE_OPERAND
(dim
, 0) : dim
);
14660 /* The type of each specified dimension must be an integral type. */
14661 if
(!JINTEGRAL_TYPE_P
(TREE_TYPE
(dim
)))
14664 /* Each expression undergoes an unary numeric promotion (5.6.1) and the
14665 promoted type must be int. */
14668 dim
= do_unary_numeric_promotion
(dim
);
14669 if
(TREE_TYPE
(dim
) != int_type_node
)
14673 /* Report errors on types here */
14676 parse_error_context
14677 (TREE_PURPOSE
(cdim
),
14678 "Incompatible type for dimension in array creation expression. %s convert %qs to %<int%>",
14679 (valid_cast_to_p
(TREE_TYPE
(dim
), int_type_node
) ?
14680 "Explicit cast needed to" : "Can't"),
14681 lang_printable_name
(TREE_TYPE
(dim
), 0));
14685 TREE_PURPOSE
(cdim
) = NULL_TREE
;
14688 /* Resolve array base type if unresolved */
14689 if
(!(type
= resolve_type_during_patch
(type
)))
14694 /* We don't want further evaluation of this bogus array creation
14696 TREE_TYPE
(node
) = error_mark_node
;
14697 return error_mark_node
;
14700 /* Set array_type to the actual (promoted) array type of the result. */
14701 if
(TREE_CODE
(type
) == RECORD_TYPE
)
14702 type
= build_pointer_type
(type
);
14703 while
(--xdims
>= 0)
14705 type
= promote_type
(build_java_array_type
(type
, -1));
14707 dims
= nreverse
(dims
);
14709 for
(cdim
= dims
; cdim
; cdim
= TREE_CHAIN
(cdim
))
14713 = build_java_array_type
(type
,
14714 TREE_CODE
(cdim
) == INTEGER_CST
14715 ?
(HOST_WIDE_INT
) TREE_INT_CST_LOW
(cdim
)
14717 array_type
= promote_type
(array_type
);
14719 dims
= nreverse
(dims
);
14721 /* The node is transformed into a function call. Things are done
14722 differently according to the number of dimensions. If the number
14723 of dimension is equal to 1, then the nature of the base type
14724 (primitive or not) matters. */
14726 return build_new_array
(type
, TREE_VALUE
(dims
));
14728 /* Can't reuse what's already written in expr.c because it uses the
14729 JVM stack representation. Provide a build_multianewarray. FIXME */
14730 return build3
(CALL_EXPR
, array_type
,
14731 build_address_of
(soft_multianewarray_node
),
14732 tree_cons
(NULL_TREE
,
14733 build_class_ref
(TREE_TYPE
(array_type
)),
14734 tree_cons
(NULL_TREE
,
14735 build_int_cst
(NULL_TREE
, ndims
),
14740 /* 10.6 Array initializer. */
14742 /* Build a wfl for array element that don't have one, so we can
14743 pin-point errors. */
14746 maybe_build_array_element_wfl
(tree node
)
14748 if
(TREE_CODE
(node
) != EXPR_WITH_FILE_LOCATION
)
14750 /* FIXME - old code used "prev_lc.line" and "elc.prev_col */
14751 return build_expr_wfl
(NULL_TREE
,
14752 #ifdef USE_MAPPED_LOCATION
14756 ctxp
->lexer
->token_start.line
,
14757 ctxp
->lexer
->token_start.col
14765 /* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
14766 identification of initialized arrays easier to detect during walk
14770 build_new_array_init
(int location
, tree values
)
14772 tree constructor
= build_constructor
(NULL_TREE
, values
);
14773 tree to_return
= build1
(NEW_ARRAY_INIT
, NULL_TREE
, constructor
);
14774 EXPR_WFL_LINECOL
(to_return
) = location
;
14778 /* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
14779 occurred. Otherwise return NODE after having set its type
14783 patch_new_array_init
(tree type
, tree node
)
14785 int error_seen
= 0;
14786 tree current
, element_type
;
14787 HOST_WIDE_INT length
;
14788 int all_constant
= 1;
14789 tree init
= TREE_OPERAND
(node
, 0);
14791 if
(TREE_CODE
(type
) != POINTER_TYPE ||
! TYPE_ARRAY_P
(TREE_TYPE
(type
)))
14793 parse_error_context
(node
,
14794 "Invalid array initializer for non-array type %qs",
14795 lang_printable_name
(type
, 1));
14796 return error_mark_node
;
14798 type
= TREE_TYPE
(type
);
14799 element_type
= TYPE_ARRAY_ELEMENT
(type
);
14801 CONSTRUCTOR_ELTS
(init
) = nreverse
(CONSTRUCTOR_ELTS
(init
));
14803 for
(length
= 0, current
= CONSTRUCTOR_ELTS
(init
);
14804 current
; length
++, current
= TREE_CHAIN
(current
))
14806 tree elt
= TREE_VALUE
(current
);
14807 if
(elt
== NULL_TREE || TREE_CODE
(elt
) != NEW_ARRAY_INIT
)
14809 error_seen |
= array_constructor_check_entry
(element_type
, current
);
14810 elt
= TREE_VALUE
(current
);
14811 /* When compiling to native code, STRING_CST is converted to
14812 INDIRECT_REF, but still with a TREE_CONSTANT flag. */
14813 if
(! TREE_CONSTANT
(elt
) || TREE_CODE
(elt
) == INDIRECT_REF
)
14818 TREE_VALUE
(current
) = patch_new_array_init
(element_type
, elt
);
14819 TREE_PURPOSE
(current
) = NULL_TREE
;
14822 if
(elt
&& TREE_CODE
(elt
) == TREE_LIST
14823 && TREE_VALUE
(elt
) == error_mark_node
)
14828 return error_mark_node
;
14830 /* Create a new type. We can't reuse the one we have here by
14831 patching its dimension because it originally is of dimension -1
14832 hence reused by gcc. This would prevent triangular arrays. */
14833 type
= build_java_array_type
(element_type
, length
);
14834 TREE_TYPE
(init
) = TREE_TYPE
(TREE_CHAIN
(TREE_CHAIN
(TYPE_FIELDS
(type
))));
14835 TREE_TYPE
(node
) = promote_type
(type
);
14836 TREE_CONSTANT
(init
) = all_constant
;
14837 TREE_INVARIANT
(init
) = all_constant
;
14838 TREE_CONSTANT
(node
) = all_constant
;
14839 TREE_INVARIANT
(node
) = all_constant
;
14843 /* Verify that one entry of the initializer element list can be
14844 assigned to the array base type. Report 1 if an error occurred, 0
14848 array_constructor_check_entry
(tree type
, tree entry
)
14850 char *array_type_string
= NULL
; /* For error reports */
14851 tree value
, type_value
, new_value
, wfl_value
, patched
;
14852 int error_seen
= 0;
14854 new_value
= NULL_TREE
;
14855 wfl_value
= TREE_VALUE
(entry
);
14857 value
= java_complete_tree
(TREE_VALUE
(entry
));
14858 /* patch_string return error_mark_node if arg is error_mark_node */
14859 if
((patched
= patch_string
(value
)))
14861 if
(value
== error_mark_node
)
14864 type_value
= TREE_TYPE
(value
);
14866 /* At anytime, try_builtin_assignconv can report a warning on
14867 constant overflow during narrowing. */
14868 SET_WFL_OPERATOR
(wfl_operator
, TREE_PURPOSE
(entry
), wfl_value
);
14869 new_value
= try_builtin_assignconv
(wfl_operator
, type
, value
);
14870 if
(!new_value
&& (new_value
= try_reference_assignconv
(type
, value
)))
14871 type_value
= promote_type
(type
);
14873 /* Check and report errors */
14876 const char *const msg
= (!valid_cast_to_p
(type_value
, type
) ?
14877 "Can't" : "Explicit cast needed to");
14878 if
(!array_type_string
)
14879 array_type_string
= xstrdup
(lang_printable_name
(type
, 1));
14880 parse_error_context
14881 (wfl_operator
, "Incompatible type for array. %s convert %qs to %qs",
14882 msg
, lang_printable_name
(type_value
, 1), array_type_string
);
14887 TREE_VALUE
(entry
) = new_value
;
14889 if
(array_type_string
)
14890 free
(array_type_string
);
14892 TREE_PURPOSE
(entry
) = NULL_TREE
;
14897 build_this
(int location
)
14899 tree node
= build_wfl_node
(this_identifier_node
);
14900 TREE_SET_CODE
(node
, THIS_EXPR
);
14901 EXPR_WFL_LINECOL
(node
) = location
;
14905 /* 14.15 The return statement. It builds a modify expression that
14906 assigns the returned value to the RESULT_DECL that hold the value
14910 build_return
(int location
, tree op
)
14912 tree node
= build1
(RETURN_EXPR
, NULL_TREE
, op
);
14913 EXPR_WFL_LINECOL
(node
) = location
;
14914 node
= build_debugable_stmt
(location
, node
);
14919 patch_return
(tree node
)
14921 tree return_exp
= TREE_OPERAND
(node
, 0);
14922 tree meth
= current_function_decl
;
14923 tree mtype
= TREE_TYPE
(TREE_TYPE
(current_function_decl
));
14924 int error_found
= 0;
14926 TREE_TYPE
(node
) = error_mark_node
;
14927 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
14929 /* It's invalid to have a return value within a function that is
14930 declared with the keyword void or that is a constructor */
14931 if
(return_exp
&& (mtype
== void_type_node || DECL_CONSTRUCTOR_P
(meth
)))
14934 /* It's invalid to use a return statement in a static block */
14935 if
(DECL_CLINIT_P
(current_function_decl
))
14938 /* It's invalid to have a no return value within a function that
14939 isn't declared with the keyword `void' */
14940 if
(!return_exp
&& (mtype
!= void_type_node
&& !DECL_CONSTRUCTOR_P
(meth
)))
14943 if
(DECL_INSTINIT_P
(current_function_decl
))
14948 if
(DECL_INSTINIT_P
(current_function_decl
))
14949 parse_error_context
(wfl_operator
,
14950 "%<return%> inside instance initializer");
14952 else if
(DECL_CLINIT_P
(current_function_decl
))
14953 parse_error_context
(wfl_operator
,
14954 "%<return%> inside static initializer");
14956 else if
(!DECL_CONSTRUCTOR_P
(meth
))
14958 char *t
= xstrdup
(lang_printable_name
(mtype
, 0));
14959 parse_error_context
(wfl_operator
,
14960 "%<return%> with%s value from %<%s %s%>",
14961 (error_found
== 1 ?
"" : "out"),
14962 t
, lang_printable_name
(meth
, 2));
14966 parse_error_context
(wfl_operator
,
14967 "%<return%> with value from constructor %qs",
14968 lang_printable_name
(meth
, 2));
14969 return error_mark_node
;
14972 /* If we have a return_exp, build a modify expression and expand
14973 it. Note: at that point, the assignment is declared valid, but we
14974 may want to carry some more hacks */
14977 tree exp
= java_complete_tree
(return_exp
);
14978 tree modify
, patched
;
14980 if
((patched
= patch_string
(exp
)))
14983 modify
= build2
(MODIFY_EXPR
, NULL_TREE
, DECL_RESULT
(meth
), exp
);
14984 EXPR_WFL_LINECOL
(modify
) = EXPR_WFL_LINECOL
(node
);
14985 modify
= java_complete_tree
(modify
);
14987 if
(modify
!= error_mark_node
)
14989 TREE_SIDE_EFFECTS
(modify
) = 1;
14990 TREE_OPERAND
(node
, 0) = modify
;
14993 return error_mark_node
;
14995 TREE_TYPE
(node
) = void_type_node
;
14996 TREE_SIDE_EFFECTS
(node
) = 1;
15000 /* 14.8 The if Statement */
15003 build_if_else_statement
(int location
, tree expression
, tree if_body
,
15008 else_body
= build_java_empty_stmt
();
15009 node
= build3
(COND_EXPR
, NULL_TREE
, expression
, if_body
, else_body
);
15010 EXPR_WFL_LINECOL
(node
) = location
;
15011 node
= build_debugable_stmt
(location
, node
);
15016 patch_if_else_statement
(tree node
)
15018 tree expression
= TREE_OPERAND
(node
, 0);
15019 int can_complete_normally
15020 = (CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1))
15021 | CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 2)));
15023 TREE_TYPE
(node
) = error_mark_node
;
15024 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
15026 /* The type of expression must be boolean */
15027 if
(TREE_TYPE
(expression
) != boolean_type_node
15028 && TREE_TYPE
(expression
) != promoted_boolean_type_node
)
15030 parse_error_context
15032 "Incompatible type for %<if%>. Can't convert %qs to %<boolean%>",
15033 lang_printable_name
(TREE_TYPE
(expression
), 0));
15034 return error_mark_node
;
15037 TREE_TYPE
(node
) = void_type_node
;
15038 TREE_SIDE_EFFECTS
(node
) = 1;
15039 CAN_COMPLETE_NORMALLY
(node
) = can_complete_normally
;
15043 /* 14.6 Labeled Statements */
15045 /* Action taken when a labeled statement is parsed. a new
15046 LABELED_BLOCK_EXPR is created. No statement is attached to the
15047 label, yet. LABEL can be NULL_TREE for artificially-generated blocks. */
15050 build_labeled_block
(int location
, tree label
)
15053 tree label_decl
, node
;
15054 if
(label
== NULL_TREE || label
== continue_identifier_node
)
15055 label_name
= label
;
15058 label_name
= merge_qualified_name
(label_id
, label
);
15059 /* Issue an error if we try to reuse a label that was previously
15061 if
(IDENTIFIER_LOCAL_VALUE
(label_name
))
15063 EXPR_WFL_LINECOL
(wfl_operator
) = location
;
15064 parse_error_context
(wfl_operator
,
15065 "Declaration of %qs shadows a previous label declaration",
15066 IDENTIFIER_POINTER
(label
));
15067 EXPR_WFL_LINECOL
(wfl_operator
) =
15068 EXPR_WFL_LINECOL
(IDENTIFIER_LOCAL_VALUE
(label_name
));
15069 parse_error_context
(wfl_operator
,
15070 "This is the location of the previous declaration of label %qs",
15071 IDENTIFIER_POINTER
(label
));
15072 java_error_count
--;
15076 label_decl
= create_label_decl
(label_name
);
15077 node
= build2
(LABELED_BLOCK_EXPR
, NULL_TREE
, label_decl
, NULL_TREE
);
15078 EXPR_WFL_LINECOL
(node
) = location
;
15079 TREE_SIDE_EFFECTS
(node
) = 1;
15083 /* A labeled statement LBE is attached a statement. */
15086 finish_labeled_statement
(tree lbe
, /* Labeled block expr */
15089 /* In anyways, tie the loop to its statement */
15090 LABELED_BLOCK_BODY
(lbe
) = statement
;
15091 pop_labeled_block
();
15092 POP_LABELED_BLOCK
();
15096 /* 14.10, 14.11, 14.12 Loop Statements */
15098 /* Create an empty LOOP_EXPR and make it the last in the nested loop
15102 build_new_loop
(tree loop_body
)
15104 tree loop
= build1
(LOOP_EXPR
, NULL_TREE
, loop_body
);
15105 TREE_SIDE_EFFECTS
(loop
) = 1;
15110 /* Create a loop body according to the following structure:
15112 COMPOUND_EXPR (loop main body)
15113 EXIT_EXPR (this order is for while/for loops.
15114 LABELED_BLOCK_EXPR the order is reversed for do loops)
15115 LABEL_DECL (a continue occurring here branches at the
15116 BODY end of this labeled block)
15119 REVERSED, if nonzero, tells that the loop condition expr comes
15120 after the body, like in the do-while loop.
15122 To obtain a loop, the loop body structure described above is
15123 encapsulated within a LOOP_EXPR surrounded by a LABELED_BLOCK_EXPR:
15126 LABEL_DECL (use this label to exit the loop)
15128 <structure described above> */
15131 build_loop_body
(int location
, tree condition
, int reversed
)
15133 tree first
, second
, body
;
15135 condition
= build1
(EXIT_EXPR
, NULL_TREE
, condition
); /* Force walk */
15136 EXPR_WFL_LINECOL
(condition
) = location
; /* For accurate error report */
15137 condition
= build_debugable_stmt
(location
, condition
);
15138 TREE_SIDE_EFFECTS
(condition
) = 1;
15140 body
= build_labeled_block
(0, continue_identifier_node
);
15141 first
= (reversed ? body
: condition
);
15142 second
= (reversed ? condition
: body
);
15143 return build2
(COMPOUND_EXPR
, NULL_TREE
,
15144 build2
(COMPOUND_EXPR
, NULL_TREE
, first
, second
),
15145 build_java_empty_stmt
());
15148 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
15149 their order) on the current loop. Unlink the current loop from the
15153 finish_loop_body
(int location
, tree condition
, tree body
, int reversed
)
15155 tree to_return
= ctxp
->current_loop
;
15156 tree loop_body
= LOOP_EXPR_BODY
(to_return
);
15159 tree cnode
= LOOP_EXPR_BODY_CONDITION_EXPR
(loop_body
, reversed
);
15160 /* We wrapped the EXIT_EXPR around a WFL so we can debug it.
15161 The real EXIT_EXPR is one operand further. */
15162 EXPR_WFL_LINECOL
(cnode
) = location
;
15163 if
(TREE_CODE
(cnode
) == EXPR_WITH_FILE_LOCATION
)
15165 cnode
= EXPR_WFL_NODE
(cnode
);
15166 /* This one is for accurate error reports */
15167 EXPR_WFL_LINECOL
(cnode
) = location
;
15169 TREE_OPERAND
(cnode
, 0) = condition
;
15171 LOOP_EXPR_BODY_BODY_EXPR
(loop_body
, reversed
) = body
;
15176 /* Tailored version of finish_loop_body for FOR loops, when FOR
15177 loops feature the condition part */
15180 finish_for_loop
(int location
, tree condition
, tree update
, tree body
)
15182 /* Put the condition and the loop body in place */
15183 tree loop
= finish_loop_body
(location
, condition
, body
, 0);
15184 /* LOOP is the current loop which has been now popped of the loop
15185 stack. Mark the update block as reachable and install it. We do
15186 this because the (current interpretation of the) JLS requires
15187 that the update expression be considered reachable even if the
15188 for loop's body doesn't complete normally. */
15189 if
(update
!= NULL_TREE
&& !IS_EMPTY_STMT
(update
))
15192 if
(TREE_CODE
(up2
) == EXPR_WITH_FILE_LOCATION
)
15193 up2
= EXPR_WFL_NODE
(up2
);
15194 /* It is possible for the update expression to be an
15195 EXPR_WFL_NODE wrapping nothing. */
15196 if
(up2
!= NULL_TREE
&& !IS_EMPTY_STMT
(up2
))
15198 /* Try to detect constraint violations. These would be
15199 programming errors somewhere. */
15200 if
(! EXPR_P
(up2
) || TREE_CODE
(up2
) == LOOP_EXPR
)
15202 SUPPRESS_UNREACHABLE_ERROR
(up2
) = 1;
15205 LOOP_EXPR_BODY_UPDATE_BLOCK
(LOOP_EXPR_BODY
(loop
)) = update
;
15209 /* Try to find the loop a block might be related to. This comprises
15210 the case where the LOOP_EXPR is found as the second operand of a
15211 COMPOUND_EXPR, because the loop happens to have an initialization
15212 part, then expressed as the first operand of the COMPOUND_EXPR. If
15213 the search finds something, 1 is returned. Otherwise, 0 is
15214 returned. The search is assumed to start from a
15215 LABELED_BLOCK_EXPR's block. */
15218 search_loop
(tree statement
)
15220 if
(TREE_CODE
(statement
) == LOOP_EXPR
)
15223 if
(TREE_CODE
(statement
) == BLOCK
)
15224 statement
= BLOCK_SUBBLOCKS
(statement
);
15228 if
(statement
&& TREE_CODE
(statement
) == COMPOUND_EXPR
)
15229 while
(statement
&& TREE_CODE
(statement
) == COMPOUND_EXPR
)
15230 statement
= TREE_OPERAND
(statement
, 1);
15232 return
(TREE_CODE
(statement
) == LOOP_EXPR
15233 && FOR_LOOP_P
(statement
) ? statement
: NULL_TREE
);
15236 /* Return 1 if LOOP can be found in the labeled block BLOCK. 0 is
15237 returned otherwise. */
15240 labeled_block_contains_loop_p
(tree block
, tree loop
)
15245 if
(LABELED_BLOCK_BODY
(block
) == loop
)
15248 if
(FOR_LOOP_P
(loop
) && search_loop
(LABELED_BLOCK_BODY
(block
)) == loop
)
15254 /* If the loop isn't surrounded by a labeled statement, create one and
15255 insert LOOP as its body. */
15258 patch_loop_statement
(tree loop
)
15262 TREE_TYPE
(loop
) = void_type_node
;
15263 if
(labeled_block_contains_loop_p
(ctxp
->current_labeled_block
, loop
))
15266 loop_label
= build_labeled_block
(0, NULL_TREE
);
15267 /* LOOP is an EXPR node, so it should have a valid EXPR_WFL_LINECOL
15268 that LOOP_LABEL could enquire about, for a better accuracy. FIXME */
15269 LABELED_BLOCK_BODY
(loop_label
) = loop
;
15270 PUSH_LABELED_BLOCK
(loop_label
);
15274 /* 14.13, 14.14: break and continue Statements */
15276 /* Build a break or a continue statement. a null NAME indicates an
15277 unlabeled break/continue statement. */
15280 build_bc_statement
(int location
, int is_break
, tree name
)
15282 tree break_continue
, label_block_expr
= NULL_TREE
;
15286 if
(!(label_block_expr
= IDENTIFIER_LOCAL_VALUE
15287 (merge_qualified_name
(label_id
, EXPR_WFL_NODE
(name
)))))
15288 /* Null means that we don't have a target for this named
15289 break/continue. In this case, we make the target to be the
15290 label name, so that the error can be reported accurately in
15291 patch_bc_statement. */
15292 label_block_expr
= EXPR_WFL_NODE
(name
);
15294 /* Unlabeled break/continue will be handled during the
15295 break/continue patch operation */
15296 break_continue
= build1
(EXIT_BLOCK_EXPR
, NULL_TREE
, label_block_expr
);
15298 IS_BREAK_STMT_P
(break_continue
) = is_break
;
15299 TREE_SIDE_EFFECTS
(break_continue
) = 1;
15300 EXPR_WFL_LINECOL
(break_continue
) = location
;
15301 break_continue
= build_debugable_stmt
(location
, break_continue
);
15302 return break_continue
;
15305 /* Verification of a break/continue statement. */
15308 patch_bc_statement
(tree node
)
15310 tree bc_label
= EXIT_BLOCK_LABELED_BLOCK
(node
), target_stmt
;
15311 tree labeled_block
= ctxp
->current_labeled_block
;
15312 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
15314 /* Having an identifier here means that the target is unknown. */
15315 if
(bc_label
!= NULL_TREE
&& TREE_CODE
(bc_label
) == IDENTIFIER_NODE
)
15317 parse_error_context
(wfl_operator
, "No label definition found for %qs",
15318 IDENTIFIER_POINTER
(bc_label
));
15319 return error_mark_node
;
15321 if
(! IS_BREAK_STMT_P
(node
))
15323 /* It's a continue statement. */
15324 for
(;; labeled_block
= TREE_CHAIN
(labeled_block
))
15326 if
(labeled_block
== NULL_TREE
)
15328 if
(bc_label
== NULL_TREE
)
15329 parse_error_context
(wfl_operator
,
15330 "%<continue%> must be in loop");
15332 parse_error_context
15333 (wfl_operator
, "continue label %qs does not name a loop",
15334 IDENTIFIER_POINTER
(bc_label
));
15335 return error_mark_node
;
15337 if
((DECL_NAME
(LABELED_BLOCK_LABEL
(labeled_block
))
15338 == continue_identifier_node
)
15339 && (bc_label
== NULL_TREE
15340 || TREE_CHAIN
(labeled_block
) == bc_label
))
15342 bc_label
= labeled_block
;
15347 else if
(!bc_label
)
15349 for
(;; labeled_block
= TREE_CHAIN
(labeled_block
))
15351 if
(labeled_block
== NULL_TREE
)
15353 parse_error_context
(wfl_operator
,
15354 "%<break%> must be in loop or switch");
15355 return error_mark_node
;
15357 target_stmt
= LABELED_BLOCK_BODY
(labeled_block
);
15358 if
(TREE_CODE
(target_stmt
) == SWITCH_EXPR
15359 || search_loop
(target_stmt
))
15361 bc_label
= labeled_block
;
15367 EXIT_BLOCK_LABELED_BLOCK
(node
) = bc_label
;
15368 CAN_COMPLETE_NORMALLY
(bc_label
) = 1;
15370 /* Our break/continue don't return values. */
15371 TREE_TYPE
(node
) = void_type_node
;
15372 /* Encapsulate the break within a compound statement so that it's
15373 expanded all the times by expand_expr (and not clobbered
15374 sometimes, like after a if statement) */
15375 node
= add_stmt_to_compound
(NULL_TREE
, void_type_node
, node
);
15376 TREE_SIDE_EFFECTS
(node
) = 1;
15380 /* Process the exit expression belonging to a loop. Its type must be
15384 patch_exit_expr
(tree node
)
15386 tree expression
= TREE_OPERAND
(node
, 0);
15387 TREE_TYPE
(node
) = error_mark_node
;
15388 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
15390 /* The type of expression must be boolean */
15391 if
(TREE_TYPE
(expression
) != boolean_type_node
)
15393 parse_error_context
15395 "Incompatible type for loop conditional. Can't convert %qs to %<boolean%>",
15396 lang_printable_name
(TREE_TYPE
(expression
), 0));
15397 return error_mark_node
;
15399 /* Now we know things are allright, invert the condition, fold and
15401 TREE_OPERAND
(node
, 0) =
15402 fold
(build1
(TRUTH_NOT_EXPR
, boolean_type_node
, expression
));
15404 if
(! integer_zerop
(TREE_OPERAND
(node
, 0))
15405 && ctxp
->current_loop
!= NULL_TREE
15406 && TREE_CODE
(ctxp
->current_loop
) == LOOP_EXPR
)
15407 CAN_COMPLETE_NORMALLY
(ctxp
->current_loop
) = 1;
15408 if
(! integer_onep
(TREE_OPERAND
(node
, 0)))
15409 CAN_COMPLETE_NORMALLY
(node
) = 1;
15412 TREE_TYPE
(node
) = void_type_node
;
15416 /* 14.9 Switch statement */
15419 patch_switch_statement
(tree node
)
15421 tree se
= TREE_OPERAND
(node
, 0), se_type
;
15424 /* Complete the switch expression */
15425 se
= TREE_OPERAND
(node
, 0) = java_complete_tree
(se
);
15426 se_type
= TREE_TYPE
(se
);
15427 /* The type of the switch expression must be char, byte, short or
15429 if
(! JINTEGRAL_TYPE_P
(se_type
) || se_type
== long_type_node
)
15431 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(node
);
15432 parse_error_context
(wfl_operator
,
15433 "Incompatible type for %<switch%>. Can't convert %qs to %<int%>",
15434 lang_printable_name
(se_type
, 0));
15435 /* This is what java_complete_tree will check */
15436 TREE_OPERAND
(node
, 0) = error_mark_node
;
15437 return error_mark_node
;
15440 /* Save and restore the outer case label list. */
15441 save
= case_label_list
;
15442 case_label_list
= NULL_TREE
;
15444 TREE_OPERAND
(node
, 1) = java_complete_tree
(TREE_OPERAND
(node
, 1));
15446 /* See if we've found a duplicate label. We can't leave this until
15447 code generation, because in `--syntax-only' and `-C' modes we
15448 don't do ordinary code generation. */
15449 for
(iter
= case_label_list
; iter
!= NULL_TREE
; iter
= TREE_CHAIN
(iter
))
15451 HOST_WIDE_INT val
= TREE_INT_CST_LOW
(TREE_VALUE
(iter
));
15453 for
(subiter
= TREE_CHAIN
(iter
);
15454 subiter
!= NULL_TREE
;
15455 subiter
= TREE_CHAIN
(subiter
))
15457 HOST_WIDE_INT subval
= TREE_INT_CST_LOW
(TREE_VALUE
(subiter
));
15460 EXPR_WFL_LINECOL
(wfl_operator
)
15461 = EXPR_WFL_LINECOL
(TREE_PURPOSE
(iter
));
15462 /* The case_label_list is in reverse order, so print the
15463 outer label first. */
15464 parse_error_context
(wfl_operator
, "duplicate case label: %<"
15465 HOST_WIDE_INT_PRINT_DEC
"%>", subval
);
15466 EXPR_WFL_LINECOL
(wfl_operator
)
15467 = EXPR_WFL_LINECOL
(TREE_PURPOSE
(subiter
));
15468 parse_error_context
(wfl_operator
, "original label is here");
15475 case_label_list
= save
;
15477 /* Ready to return */
15478 if
(TREE_CODE
(TREE_OPERAND
(node
, 1)) == ERROR_MARK
)
15480 TREE_TYPE
(node
) = error_mark_node
;
15481 return error_mark_node
;
15483 TREE_TYPE
(node
) = void_type_node
;
15484 TREE_SIDE_EFFECTS
(node
) = 1;
15485 CAN_COMPLETE_NORMALLY
(node
)
15486 = CAN_COMPLETE_NORMALLY
(TREE_OPERAND
(node
, 1))
15487 ||
! SWITCH_HAS_DEFAULT
(node
);
15493 /* Build an assertion expression for `assert CONDITION : VALUE'; VALUE
15494 might be NULL_TREE. */
15497 #ifdef USE_MAPPED_LOCATION
15498 source_location location
,
15502 tree condition
, tree value
)
15505 tree klass
= GET_CPC
();
15507 if
(! enable_assertions
(klass
))
15509 condition
= build2
(TRUTH_ANDIF_EXPR
, NULL_TREE
,
15510 boolean_false_node
, condition
);
15511 if
(value
== NULL_TREE
)
15512 value
= build_java_empty_stmt
();
15513 return build_if_else_statement
(location
, condition
,
15517 if
(! CLASS_USES_ASSERTIONS
(klass
))
15519 tree field
, classdollar
, id
, call
;
15520 tree class_type
= TREE_TYPE
(klass
);
15522 field
= add_field
(class_type
,
15523 get_identifier
("$assertionsDisabled"),
15525 ACC_PRIVATE | ACC_STATIC | ACC_FINAL
);
15526 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(field
);
15527 FIELD_SYNTHETIC
(field
) = 1;
15529 classdollar
= build_incomplete_class_ref
(location
, class_type
);
15531 /* Call CLASS.desiredAssertionStatus(). */
15532 id
= build_wfl_node
(get_identifier
("desiredAssertionStatus"));
15533 call
= build3
(CALL_EXPR
, NULL_TREE
, id
, NULL_TREE
, NULL_TREE
);
15534 call
= make_qualified_primary
(classdollar
, call
, location
);
15535 TREE_SIDE_EFFECTS
(call
) = 1;
15537 /* Invert to obtain !CLASS.desiredAssertionStatus(). This may
15538 seem odd, but we do it to generate code identical to that of
15540 call
= build1
(TRUTH_NOT_EXPR
, NULL_TREE
, call
);
15541 TREE_SIDE_EFFECTS
(call
) = 1;
15542 DECL_INITIAL
(field
) = call
;
15544 /* Record the initializer in the initializer statement list. */
15545 call
= build2
(MODIFY_EXPR
, NULL_TREE
, field
, call
);
15546 TREE_CHAIN
(call
) = CPC_STATIC_INITIALIZER_STMT
(ctxp
);
15547 SET_CPC_STATIC_INITIALIZER_STMT
(ctxp
, call
);
15548 MODIFY_EXPR_FROM_INITIALIZATION_P
(call
) = 1;
15550 CLASS_USES_ASSERTIONS
(klass
) = 1;
15553 if
(value
!= NULL_TREE
)
15554 value
= tree_cons
(NULL_TREE
, value
, NULL_TREE
);
15556 node
= build_wfl_node
(get_identifier
("java"));
15557 node
= make_qualified_name
(node
, build_wfl_node
(get_identifier
("lang")),
15559 node
= make_qualified_name
(node
, build_wfl_node
(get_identifier
("AssertionError")),
15562 node
= build3
(NEW_CLASS_EXPR
, NULL_TREE
, node
, value
, NULL_TREE
);
15563 TREE_SIDE_EFFECTS
(node
) = 1;
15564 /* It is too early to use BUILD_THROW. */
15565 node
= build1
(THROW_EXPR
, NULL_TREE
, node
);
15566 TREE_SIDE_EFFECTS
(node
) = 1;
15568 /* We invert the condition; if we just put NODE as the `else' part
15569 then we generate weird-looking bytecode. */
15570 condition
= build1
(TRUTH_NOT_EXPR
, NULL_TREE
, condition
);
15571 /* Check $assertionsDisabled. */
15573 = build2
(TRUTH_ANDIF_EXPR
, NULL_TREE
,
15574 build1
(TRUTH_NOT_EXPR
, NULL_TREE
,
15575 build_wfl_node
(get_identifier
("$assertionsDisabled"))),
15577 node
= build_if_else_statement
(location
, condition
, node
, NULL_TREE
);
15581 /* 14.18 The try/catch statements */
15583 /* Encapsulate TRY_STMTS' in a try catch sequence. The catch clause
15584 catches TYPE and executes CATCH_STMTS. */
15587 encapsulate_with_try_catch
(int location
, tree type_or_name
, tree try_stmts
,
15590 tree try_block
, catch_clause_param
, catch_block
, catch
;
15592 /* First build a try block */
15593 try_block
= build_expr_block
(try_stmts
, NULL_TREE
);
15595 /* Build a catch block: we need a catch clause parameter */
15596 if
(TREE_CODE
(type_or_name
) == EXPR_WITH_FILE_LOCATION
)
15598 tree catch_type
= obtain_incomplete_type
(type_or_name
);
15600 catch_clause_param
= build_decl
(VAR_DECL
, wpv_id
, catch_type
);
15601 register_incomplete_type
(JDEP_VARIABLE
, type_or_name
,
15602 catch_clause_param
, catch_type
);
15603 dep
= CLASSD_LAST
(ctxp
->classd_list
);
15604 JDEP_GET_PATCH
(dep
) = &TREE_TYPE
(catch_clause_param
);
15607 catch_clause_param
= build_decl
(VAR_DECL
, wpv_id
,
15608 build_pointer_type
(type_or_name
));
15611 catch_block
= build_expr_block
(NULL_TREE
, catch_clause_param
);
15613 /* Initialize the variable and store in the block */
15614 catch
= build2
(MODIFY_EXPR
, NULL_TREE
, catch_clause_param
,
15615 build0
(JAVA_EXC_OBJ_EXPR
, ptr_type_node
));
15616 add_stmt_to_block
(catch_block
, NULL_TREE
, catch
);
15618 /* Add the catch statements */
15619 add_stmt_to_block
(catch_block
, NULL_TREE
, catch_stmts
);
15621 /* Now we can build a JAVA_CATCH_EXPR */
15622 catch_block
= build1
(JAVA_CATCH_EXPR
, NULL_TREE
, catch_block
);
15624 return build_try_statement
(location
, try_block
, catch_block
);
15628 build_try_statement
(int location
, tree try_block
, tree catches
)
15630 tree node
= build2
(TRY_EXPR
, NULL_TREE
, try_block
, catches
);
15631 EXPR_WFL_LINECOL
(node
) = location
;
15636 build_try_finally_statement
(int location
, tree try_block
, tree finally
)
15638 tree node
= build2
(TRY_FINALLY_EXPR
, NULL_TREE
, try_block
, finally
);
15639 EXPR_WFL_LINECOL
(node
) = location
;
15644 patch_try_statement
(tree node
)
15646 int error_found
= 0;
15647 tree try
= TREE_OPERAND
(node
, 0);
15648 /* Exception handlers are considered in left to right order */
15649 tree catch
= nreverse
(TREE_OPERAND
(node
, 1));
15650 tree current
, caught_type_list
= NULL_TREE
;
15652 /* Check catch clauses, if any. Every time we find an error, we try
15653 to process the next catch clause. We process the catch clause before
15654 the try block so that when processing the try block we can check thrown
15655 exceptions against the caught type list. */
15656 for
(current
= catch
; current
; current
= TREE_CHAIN
(current
))
15658 tree carg_decl
, carg_type
;
15659 tree sub_current
, catch_block
, catch_clause
;
15662 /* At this point, the structure of the catch clause is
15663 JAVA_CATCH_EXPR (catch node)
15664 BLOCK (with the decl of the parameter)
15666 MODIFY_EXPR (assignment of the catch parameter)
15667 BLOCK (catch clause block)
15669 catch_clause
= TREE_OPERAND
(current
, 0);
15670 carg_decl
= BLOCK_EXPR_DECLS
(catch_clause
);
15671 carg_type
= TREE_TYPE
(TREE_TYPE
(carg_decl
));
15673 /* Catch clauses can't have more than one parameter declared,
15674 but it's already enforced by the grammar. Make sure that the
15675 only parameter of the clause statement in of class Throwable
15676 or a subclass of Throwable, but that was done earlier. The
15677 catch clause parameter type has also been resolved. */
15679 /* Just make sure that the catch clause parameter type inherits
15680 from java.lang.Throwable */
15681 if
(!inherits_from_p
(carg_type
, throwable_type_node
))
15683 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(current
);
15684 parse_error_context
(wfl_operator
,
15685 "Can't catch class %qs. Catch clause parameter type must be a subclass of class %<java.lang.Throwable%>",
15686 lang_printable_name
(carg_type
, 0));
15691 /* Partial check for unreachable catch statement: The catch
15692 clause is reachable iff is no earlier catch block A in
15693 the try statement such that the type of the catch
15694 clause's parameter is the same as or a subclass of the
15695 type of A's parameter */
15697 for
(sub_current
= catch
;
15698 sub_current
!= current
; sub_current
= TREE_CHAIN
(sub_current
))
15700 tree sub_catch_clause
, decl
;
15701 sub_catch_clause
= TREE_OPERAND
(sub_current
, 0);
15702 decl
= BLOCK_EXPR_DECLS
(sub_catch_clause
);
15704 if
(inherits_from_p
(carg_type
, TREE_TYPE
(TREE_TYPE
(decl
))))
15706 EXPR_WFL_LINECOL
(wfl_operator
) = EXPR_WFL_LINECOL
(current
);
15707 parse_error_context
15709 "%<catch%> not reached because of the catch clause at line %d",
15710 EXPR_WFL_LINENO
(sub_current
));
15711 unreachable
= error_found
= 1;
15715 /* Complete the catch clause block */
15716 catch_block
= java_complete_tree
(TREE_OPERAND
(current
, 0));
15717 if
(catch_block
== error_mark_node
)
15722 if
(CAN_COMPLETE_NORMALLY
(catch_block
))
15723 CAN_COMPLETE_NORMALLY
(node
) = 1;
15724 TREE_OPERAND
(current
, 0) = catch_block
;
15729 /* Things to do here: the exception must be thrown */
15731 /* Link this type to the caught type list */
15732 caught_type_list
= tree_cons
(NULL_TREE
, carg_type
, caught_type_list
);
15735 PUSH_EXCEPTIONS
(caught_type_list
);
15736 if
((try
= java_complete_tree
(try
)) == error_mark_node
)
15738 if
(CAN_COMPLETE_NORMALLY
(try
))
15739 CAN_COMPLETE_NORMALLY
(node
) = 1;
15742 /* Verification ends here */
15744 return error_mark_node
;
15746 TREE_OPERAND
(node
, 0) = try
;
15747 TREE_OPERAND
(node
, 1) = catch
;
15748 TREE_TYPE
(node
) = void_type_node
;
15752 /* 14.17 The synchronized Statement */
15755 patch_synchronized_statement
(tree node
, tree wfl_op1
)
15757 tree expr
= java_complete_tree
(TREE_OPERAND
(node
, 0));
15758 tree block
= TREE_OPERAND
(node
, 1);
15760 tree tmp
, enter
, exit
, expr_decl
, assignment
;
15762 if
(expr
== error_mark_node
)
15764 block
= java_complete_tree
(block
);
15768 /* We might be trying to synchronize on a STRING_CST */
15769 if
((tmp
= patch_string
(expr
)))
15772 /* The TYPE of expr must be a reference type */
15773 if
(!JREFERENCE_TYPE_P
(TREE_TYPE
(expr
)))
15775 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15776 parse_error_context
(wfl_operator
, "Incompatible type for %<synchronized%>. Can't convert %qs to %<java.lang.Object%>",
15777 lang_printable_name
(TREE_TYPE
(expr
), 0));
15778 return error_mark_node
;
15781 /* Generate a try-finally for the synchronized statement, except
15782 that the handler that catches all throw exception calls
15783 _Jv_MonitorExit and then rethrow the exception.
15784 The synchronized statement is then implemented as:
15787 _Jv_MonitorEnter (expression)
15789 _Jv_MonitorExit (expression)
15793 e = _Jv_exception_info ();
15794 _Jv_MonitorExit (expression)
15798 expr_decl
= build_decl
(VAR_DECL
, generate_name
(), TREE_TYPE
(expr
));
15799 BUILD_MONITOR_ENTER
(enter
, expr_decl
);
15800 BUILD_MONITOR_EXIT
(exit
, expr_decl
);
15801 CAN_COMPLETE_NORMALLY
(enter
) = 1;
15802 CAN_COMPLETE_NORMALLY
(exit
) = 1;
15803 assignment
= build2
(MODIFY_EXPR
, NULL_TREE
, expr_decl
, expr
);
15804 TREE_SIDE_EFFECTS
(assignment
) = 1;
15805 node
= build2
(COMPOUND_EXPR
, NULL_TREE
,
15806 build2
(COMPOUND_EXPR
, NULL_TREE
, assignment
, enter
),
15807 build2
(TRY_FINALLY_EXPR
, NULL_TREE
, block
, exit
));
15808 node
= build_expr_block
(node
, expr_decl
);
15810 return java_complete_tree
(node
);
15813 /* 14.16 The throw Statement */
15816 patch_throw_statement
(tree node
, tree wfl_op1
)
15818 tree expr
= TREE_OPERAND
(node
, 0);
15819 tree type
= TREE_TYPE
(expr
);
15820 int unchecked_ok
= 0, tryblock_throws_ok
= 0;
15822 /* Thrown expression must be assignable to java.lang.Throwable */
15823 if
(!try_reference_assignconv
(throwable_type_node
, expr
))
15825 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15826 parse_error_context
(wfl_operator
,
15827 "Can't throw %qs; it must be a subclass of class %<java.lang.Throwable%>",
15828 lang_printable_name
(type
, 0));
15829 /* If the thrown expression was a reference, we further the
15830 compile-time check. */
15831 if
(!JREFERENCE_TYPE_P
(type
))
15832 return error_mark_node
;
15835 /* At least one of the following must be true */
15837 /* The type of the throw expression is a not checked exception,
15838 i.e. is a unchecked expression. */
15839 unchecked_ok
= IS_UNCHECKED_EXCEPTION_P
(TREE_TYPE
(type
));
15841 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
15842 /* An instance can't throw a checked exception unless that exception
15843 is explicitly declared in the `throws' clause of each
15844 constructor. This doesn't apply to anonymous classes, since they
15845 don't have declared constructors. */
15847 && DECL_INSTINIT_P
(current_function_decl
)
15848 && !ANONYMOUS_CLASS_P
(current_class
))
15851 for
(current
= TYPE_METHODS
(current_class
); current
;
15852 current
= TREE_CHAIN
(current
))
15853 if
(DECL_CONSTRUCTOR_P
(current
)
15854 && !check_thrown_exceptions_do
(TREE_TYPE
(expr
)))
15856 parse_error_context
(wfl_operator
, "Checked exception %qs can't be thrown in instance initializer (not all declared constructor are declaring it in their %<throws%> clause)",
15857 lang_printable_name
(TREE_TYPE
(expr
), 0));
15858 return error_mark_node
;
15862 /* Throw is contained in a try statement and at least one catch
15863 clause can receive the thrown expression or the current method is
15864 declared to throw such an exception. Or, the throw statement is
15865 contained in a method or constructor declaration and the type of
15866 the Expression is assignable to at least one type listed in the
15867 throws clause the declaration. */
15869 tryblock_throws_ok
= check_thrown_exceptions_do
(TREE_TYPE
(expr
));
15870 if
(!(unchecked_ok || tryblock_throws_ok
))
15872 /* If there is a surrounding try block that has no matching
15873 clatch clause, report it first. A surrounding try block exits
15874 only if there is something after the list of checked
15875 exception thrown by the current function (if any). */
15876 if
(IN_TRY_BLOCK_P
())
15877 parse_error_context
(wfl_operator
, "Checked exception %qs can't be caught by any of the catch clause(s) of the surrounding %<try%> block",
15878 lang_printable_name
(type
, 0));
15879 /* If we have no surrounding try statement and the method doesn't have
15880 any throws, report it now. FIXME */
15882 /* We report that the exception can't be throw from a try block
15883 in all circumstances but when the `throw' is inside a static
15885 else if
(!EXCEPTIONS_P
(currently_caught_type_list
)
15886 && !tryblock_throws_ok
)
15888 if
(DECL_CLINIT_P
(current_function_decl
))
15889 parse_error_context
(wfl_operator
,
15890 "Checked exception %qs can't be thrown in initializer",
15891 lang_printable_name
(type
, 0));
15893 parse_error_context
(wfl_operator
,
15894 "Checked exception %qs isn't thrown from a %<try%> block",
15895 lang_printable_name
(type
, 0));
15897 /* Otherwise, the current method doesn't have the appropriate
15898 throws declaration */
15900 parse_error_context
(wfl_operator
, "Checked exception %qs doesn't match any of current method's %<throws%> declaration(s)",
15901 lang_printable_name
(type
, 0));
15902 return error_mark_node
;
15905 if
(! flag_emit_class_files
)
15906 BUILD_THROW
(node
, expr
);
15911 /* Check that exception said to be thrown by method DECL can be
15912 effectively caught from where DECL is invoked. THIS_EXPR is the
15913 expression that computes `this' for the method call. */
15915 check_thrown_exceptions
(
15916 #ifdef USE_MAPPED_LOCATION
15917 source_location location
,
15922 tree decl
, tree this_expr
)
15925 int is_array_call
= 0;
15927 /* Skip check within generated methods, such as access$<n>. */
15928 if
(NESTED_FIELD_ACCESS_IDENTIFIER_P
(DECL_NAME
(current_function_decl
)))
15931 if
(this_expr
!= NULL_TREE
15932 && TREE_CODE
(TREE_TYPE
(this_expr
)) == POINTER_TYPE
15933 && TYPE_ARRAY_P
(TREE_TYPE
(TREE_TYPE
(this_expr
))))
15936 /* For all the unchecked exceptions thrown by DECL. */
15937 for
(throws
= DECL_FUNCTION_THROWS
(decl
); throws
;
15938 throws
= TREE_CHAIN
(throws
))
15939 if
(!check_thrown_exceptions_do
(TREE_VALUE
(throws
)))
15941 /* Suppress errors about cloning arrays. */
15942 if
(is_array_call
&& DECL_NAME
(decl
) == get_identifier
("clone"))
15945 #ifdef USE_MAPPED_LOCATION
15946 SET_EXPR_LOCATION
(wfl_operator
, location
);
15948 EXPR_WFL_LINECOL
(wfl_operator
) = location
;
15950 if
(DECL_FINIT_P
(current_function_decl
))
15951 parse_error_context
15952 (wfl_operator
, "Exception %qs can't be thrown in initializer",
15953 lang_printable_name
(TREE_VALUE
(throws
), 0));
15956 parse_error_context
15957 (wfl_operator
, "Exception %qs must be caught, or it must be declared in the %<throws%> clause of %qs",
15958 lang_printable_name
(TREE_VALUE
(throws
), 0),
15959 (DECL_INIT_P
(current_function_decl
) ?
15960 IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(current_class
))) :
15961 IDENTIFIER_POINTER
(DECL_NAME
(current_function_decl
))));
15966 /* Return 1 if checked EXCEPTION is caught at the current nesting level of
15967 try-catch blocks, OR is listed in the `throws' clause of the
15971 check_thrown_exceptions_do
(tree exception
)
15973 tree list
= currently_caught_type_list
;
15974 resolve_and_layout
(exception
, NULL_TREE
);
15975 /* First, all the nested try-catch-finally at that stage. The
15976 last element contains `throws' clause exceptions, if any. */
15977 if
(IS_UNCHECKED_EXCEPTION_P
(exception
))
15982 for
(caught
= TREE_VALUE
(list
); caught
; caught
= TREE_CHAIN
(caught
))
15983 if
(valid_ref_assignconv_cast_p
(exception
, TREE_VALUE
(caught
), 0))
15985 list
= TREE_CHAIN
(list
);
15991 purge_unchecked_exceptions
(tree mdecl
)
15993 tree throws
= DECL_FUNCTION_THROWS
(mdecl
);
15994 tree new
= NULL_TREE
;
15998 tree next
= TREE_CHAIN
(throws
);
15999 if
(!IS_UNCHECKED_EXCEPTION_P
(TREE_VALUE
(throws
)))
16001 TREE_CHAIN
(throws
) = new
;
16006 /* List is inverted here, but it doesn't matter */
16007 DECL_FUNCTION_THROWS
(mdecl
) = new
;
16010 /* This function goes over all of CLASS_TYPE ctors and checks whether
16011 each of them features at least one unchecked exception in its
16012 `throws' clause. If it's the case, it returns `true', `false'
16016 ctors_unchecked_throws_clause_p
(tree class_type
)
16020 for
(current
= TYPE_METHODS
(class_type
); current
;
16021 current
= TREE_CHAIN
(current
))
16023 bool ctu
= false
; /* Ctor Throws Unchecked */
16024 if
(DECL_CONSTRUCTOR_P
(current
))
16027 for
(throws
= DECL_FUNCTION_THROWS
(current
); throws
&& !ctu
;
16028 throws
= TREE_CHAIN
(throws
))
16029 if
(inherits_from_p
(TREE_VALUE
(throws
), exception_type_node
))
16032 /* We return false as we found one ctor that is unfit. */
16033 if
(!ctu
&& DECL_CONSTRUCTOR_P
(current
))
16036 /* All ctors feature at least one unchecked exception in their
16037 `throws' clause. */
16041 /* 15.24 Conditional Operator ?: */
16044 patch_conditional_expr
(tree node
, tree wfl_cond
, tree wfl_op1
)
16046 tree cond
= TREE_OPERAND
(node
, 0);
16047 tree op1
= TREE_OPERAND
(node
, 1);
16048 tree op2
= TREE_OPERAND
(node
, 2);
16049 tree resulting_type
= NULL_TREE
;
16050 tree t1
, t2
, patched
;
16051 int error_found
= 0;
16053 /* The condition and operands of ?: might be StringBuffers crafted
16054 as a result of a string concatenation. Obtain decent ones here. */
16055 if
((patched
= patch_string
(cond
)))
16056 TREE_OPERAND
(node
, 0) = cond
= patched
;
16057 if
((patched
= patch_string
(op1
)))
16058 TREE_OPERAND
(node
, 1) = op1
= patched
;
16059 if
((patched
= patch_string
(op2
)))
16060 TREE_OPERAND
(node
, 2) = op2
= patched
;
16062 t1
= TREE_TYPE
(op1
);
16063 t2
= TREE_TYPE
(op2
);
16065 /* The first expression must be a boolean */
16066 if
(TREE_TYPE
(cond
) != boolean_type_node
)
16068 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_cond
);
16069 parse_error_context
(wfl_operator
,
16070 "Incompatible type for %<?:%>. Can't convert %qs to %<boolean%>",
16071 lang_printable_name
(TREE_TYPE
(cond
), 0));
16075 /* Second and third can be numeric, boolean (i.e. primitive),
16076 references or null. Anything else results in an error */
16077 if
(!((JNUMERIC_TYPE_P
(t1
) && JNUMERIC_TYPE_P
(t2
))
16078 ||
((JREFERENCE_TYPE_P
(t1
) || op1
== null_pointer_node
)
16079 && (JREFERENCE_TYPE_P
(t2
) || op2
== null_pointer_node
))
16080 ||
(t1
== boolean_type_node
&& t2
== boolean_type_node
)))
16083 /* Determine the type of the conditional expression. Same types are
16084 easy to deal with */
16086 resulting_type
= t1
;
16088 /* There are different rules for numeric types */
16089 else if
(JNUMERIC_TYPE_P
(t1
))
16091 /* if byte/short found, the resulting type is short */
16092 if
((t1
== byte_type_node
&& t2
== short_type_node
)
16093 ||
(t1
== short_type_node
&& t2
== byte_type_node
))
16094 resulting_type
= short_type_node
;
16096 /* If t1 is a constant int and t2 is of type byte, short or char
16097 and t1's value fits in t2, then the resulting type is t2 */
16098 else if
((t1
== int_type_node
&& TREE_CONSTANT
(TREE_OPERAND
(node
, 1)))
16099 && JBSC_TYPE_P
(t2
) && int_fits_type_p
(TREE_OPERAND
(node
, 1), t2
))
16100 resulting_type
= t2
;
16102 /* If t2 is a constant int and t1 is of type byte, short or char
16103 and t2's value fits in t1, then the resulting type is t1 */
16104 else if
((t2
== int_type_node
&& TREE_CONSTANT
(TREE_OPERAND
(node
, 2)))
16105 && JBSC_TYPE_P
(t1
) && int_fits_type_p
(TREE_OPERAND
(node
, 2), t1
))
16106 resulting_type
= t1
;
16108 /* Otherwise, binary numeric promotion is applied and the
16109 resulting type is the promoted type of operand 1 and 2 */
16111 resulting_type
= binary_numeric_promotion
(t1
, t2
,
16112 &TREE_OPERAND
(node
, 1),
16113 &TREE_OPERAND
(node
, 2));
16116 /* Cases of a reference and a null type */
16117 else if
(JREFERENCE_TYPE_P
(t1
) && op2
== null_pointer_node
)
16118 resulting_type
= t1
;
16120 else if
(JREFERENCE_TYPE_P
(t2
) && op1
== null_pointer_node
)
16121 resulting_type
= t2
;
16123 /* Last case: different reference types. If a type can be converted
16124 into the other one by assignment conversion, the latter
16125 determines the type of the expression */
16126 else if
((resulting_type
= try_reference_assignconv
(t1
, op2
)))
16127 resulting_type
= promote_type
(t1
);
16129 else if
((resulting_type
= try_reference_assignconv
(t2
, op1
)))
16130 resulting_type
= promote_type
(t2
);
16132 /* If we don't have any resulting type, we're in trouble */
16133 if
(!resulting_type
)
16135 char *t
= xstrdup
(lang_printable_name
(t1
, 0));
16136 SET_WFL_OPERATOR
(wfl_operator
, node
, wfl_op1
);
16137 parse_error_context
(wfl_operator
,
16138 "Incompatible type for %<?:%>. Can't convert %qs to %qs",
16139 t
, lang_printable_name
(t2
, 0));
16146 TREE_TYPE
(node
) = error_mark_node
;
16147 return error_mark_node
;
16150 TREE_TYPE
(node
) = resulting_type
;
16151 TREE_SET_CODE
(node
, COND_EXPR
);
16152 CAN_COMPLETE_NORMALLY
(node
) = 1;
16156 /* Wrap EXPR with code to initialize DECL's class, if appropriate. */
16159 maybe_build_class_init_for_field
(tree decl
, tree expr
)
16161 tree clas
= DECL_CONTEXT
(decl
);
16162 if
(flag_emit_class_files
)
16165 if
(TREE_CODE
(decl
) == VAR_DECL
&& FIELD_STATIC
(decl
)
16166 && FIELD_FINAL
(decl
))
16168 tree init
= DECL_INITIAL
(decl
);
16169 if
(init
!= NULL_TREE
)
16170 init
= fold_constant_for_init
(init
, decl
);
16171 if
(init
!= NULL_TREE
&& CONSTANT_VALUE_P
(init
))
16175 return build_class_init
(clas
, expr
);
16178 /* Try to constant fold NODE.
16179 If NODE is not a constant expression, return NULL_EXPR.
16180 CONTEXT is a static final VAR_DECL whose initializer we are folding. */
16183 fold_constant_for_init
(tree node
, tree context
)
16185 tree op0
, op1
, val
;
16186 enum tree_code code
= TREE_CODE
(node
);
16191 if
(node
== null_pointer_node
)
16200 case TRUNC_MOD_EXPR
:
16208 case TRUTH_ANDIF_EXPR
:
16209 case TRUTH_ORIF_EXPR
:
16216 op0
= TREE_OPERAND
(node
, 0);
16217 op1
= TREE_OPERAND
(node
, 1);
16218 val
= fold_constant_for_init
(op0
, context
);
16219 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16221 TREE_OPERAND
(node
, 0) = val
;
16222 val
= fold_constant_for_init
(op1
, context
);
16223 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16225 TREE_OPERAND
(node
, 1) = val
;
16226 return patch_binop
(node
, op0
, op1
, 1);
16228 case UNARY_PLUS_EXPR
:
16230 case TRUTH_NOT_EXPR
:
16234 op0
= TREE_OPERAND
(node
, 0);
16235 val
= fold_constant_for_init
(op0
, context
);
16236 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16238 TREE_OPERAND
(node
, 0) = val
;
16239 val
= patch_unaryop
(node
, op0
);
16240 if
(! TREE_CONSTANT
(val
))
16247 val
= fold_constant_for_init
(TREE_OPERAND
(node
, 0), context
);
16248 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16250 TREE_OPERAND
(node
, 0) = val
;
16251 val
= fold_constant_for_init
(TREE_OPERAND
(node
, 1), context
);
16252 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16254 TREE_OPERAND
(node
, 1) = val
;
16255 val
= fold_constant_for_init
(TREE_OPERAND
(node
, 2), context
);
16256 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16258 TREE_OPERAND
(node
, 2) = val
;
16259 return integer_zerop
(TREE_OPERAND
(node
, 0)) ? TREE_OPERAND
(node
, 2)
16260 : TREE_OPERAND
(node
, 1);
16264 if
(! FIELD_FINAL
(node
)
16265 || DECL_INITIAL
(node
) == NULL_TREE
)
16267 val
= DECL_INITIAL
(node
);
16268 /* Guard against infinite recursion. */
16269 DECL_INITIAL
(node
) = NULL_TREE
;
16270 val
= fold_constant_for_init
(val
, node
);
16271 if
(val
!= NULL_TREE
&& TREE_CODE
(val
) != STRING_CST
)
16272 val
= try_builtin_assignconv
(NULL_TREE
, TREE_TYPE
(node
), val
);
16273 DECL_INITIAL
(node
) = val
;
16276 case EXPR_WITH_FILE_LOCATION
:
16277 /* Compare java_complete_tree and resolve_expression_name. */
16278 if
(!EXPR_WFL_NODE
(node
) /* Or a PRIMARY flag ? */
16279 || TREE_CODE
(EXPR_WFL_NODE
(node
)) == IDENTIFIER_NODE
)
16281 tree name
= EXPR_WFL_NODE
(node
);
16283 if
(PRIMARY_P
(node
))
16285 else if
(! QUALIFIED_P
(name
))
16287 decl
= lookup_field_wrapper
(DECL_CONTEXT
(context
), name
);
16288 if
(decl
== NULL_TREE
16289 ||
(! FIELD_STATIC
(decl
) && ! FIELD_FINAL
(decl
)))
16291 return fold_constant_for_init
(decl
, decl
);
16295 tree r
= NULL_TREE
;
16296 /* Install the proper context for the field resolution. */
16297 tree saved_current_class
= current_class
;
16298 /* Wait until the USE_COMPONENT_REF re-write. FIXME. */
16299 current_class
= DECL_CONTEXT
(context
);
16300 qualify_ambiguous_name
(node
);
16301 r
= resolve_field_access
(node
, &decl
, NULL
);
16302 /* Restore prior context. */
16303 current_class
= saved_current_class
;
16304 if
(r
!= error_mark_node
&& decl
!= NULL_TREE
)
16305 return fold_constant_for_init
(decl
, decl
);
16311 op0
= TREE_OPERAND
(node
, 0);
16312 val
= fold_constant_for_init
(op0
, context
);
16313 if
(val
== NULL_TREE ||
! TREE_CONSTANT
(val
))
16315 TREE_OPERAND
(node
, 0) = val
;
16319 #ifdef USE_COMPONENT_REF
16321 case COMPONENT_REF
:
16330 #ifdef USE_COMPONENT_REF
16331 /* Context is 'T' for TypeName, 'P' for PackageName,
16332 'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
16335 resolve_simple_name
(tree name
, int context
)
16340 resolve_qualified_name
(tree name
, int context
)
16346 init_src_parse
(void)
16348 /* Sanity check; we've been bit by this before. */
16349 if
(ARRAY_SIZE
(ctxp
->modifier_ctx
) != MODIFIER_TK
- PUBLIC_TK
)
16355 /* This section deals with the functions that are called when tables
16356 recording class initialization information are traversed. */
16358 /* This function is called for each class that is known definitely
16359 initialized when a given static method was called. This function
16360 augments a compound expression (INFO) storing all assignment to
16361 initialized static class flags if a flag already existed, otherwise
16362 a new one is created. */
16365 emit_test_initialization
(void **entry_p
, void *info
)
16367 tree l
= (tree
) info
;
16369 tree key
= (tree
) *entry_p
;
16371 htab_t cf_ht
= DECL_FUNCTION_INIT_TEST_TABLE
(current_function_decl
);
16373 /* If we haven't found a flag and we're dealing with self registered
16374 with current_function_decl, then don't do anything. Self is
16375 always added as definitely initialized but this information is
16376 valid only if used outside the current function. */
16377 if
(current_function_decl
== TREE_PURPOSE
(l
)
16378 && java_treetreehash_find
(cf_ht
, key
) == NULL
)
16381 ite
= java_treetreehash_new
(cf_ht
, key
);
16383 /* If we don't have a variable, create one and install it. */
16388 decl
= build_decl
(VAR_DECL
, NULL_TREE
, boolean_type_node
);
16389 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC
(decl
);
16390 LOCAL_CLASS_INITIALIZATION_FLAG
(decl
) = 1;
16391 DECL_CONTEXT
(decl
) = current_function_decl
;
16392 DECL_INITIAL
(decl
) = boolean_true_node
;
16393 /* Don't emit any symbolic debugging info for this decl. */
16394 DECL_IGNORED_P
(decl
) = 1;
16396 /* The trick is to find the right context for it. */
16397 block
= BLOCK_SUBBLOCKS
(GET_CURRENT_BLOCK
(current_function_decl
));
16398 TREE_CHAIN
(decl
) = BLOCK_EXPR_DECLS
(block
);
16399 BLOCK_EXPR_DECLS
(block
) = decl
;
16405 /* Now simply augment the compound that holds all the assignments
16406 pertaining to this method invocation. */
16407 init
= build2
(MODIFY_EXPR
, boolean_type_node
, decl
, boolean_true_node
);
16408 TREE_SIDE_EFFECTS
(init
) = 1;
16409 TREE_VALUE
(l
) = add_stmt_to_compound
(TREE_VALUE
(l
), void_type_node
, init
);
16410 TREE_SIDE_EFFECTS
(TREE_VALUE
(l
)) = 1;
16415 #ifdef __XGETTEXT__
16416 /* Depending on the version of Bison used to compile this grammar,
16417 it may issue generic diagnostics spelled "syntax error" or
16418 "parse error". To prevent this from changing the translation
16419 template randomly, we list all the variants of this particular
16420 diagnostic here. Translators: there is no fine distinction
16421 between diagnostics with "syntax error" in them, and diagnostics
16422 with "parse error" in them. It's okay to give them both the same
16424 const char d1
[] = N_
("syntax error");
16425 const char d2
[] = N_
("parse error");
16426 const char d3
[] = N_
("syntax error; also virtual memory exhausted");
16427 const char d4
[] = N_
("parse error; also virtual memory exhausted");
16428 const char d5
[] = N_
("syntax error: cannot back up");
16429 const char d6
[] = N_
("parse error: cannot back up");
16432 #include "gt-java-parse.h"
16433 #include "gtype-java.h"