1 /* Source code parsing and tree node generation for the GNU compiler
2 for the Java(TM) language.
3 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* This file parses java source code and issues a tree node image
28 suitable for code generation (byte code and targeted CPU assembly
31 The grammar conforms to the Java grammar described in "The Java(TM)
32 Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
33 1996, ISBN 0-201-63451-1"
35 The following modifications were brought to the original grammar:
37 method_body: added the rule '| block SC_TK'
38 static_initializer: added the rule 'static block SC_TK'.
40 Note: All the extra rules described above should go away when the
41 empty_statement rule will work.
43 statement_nsi: 'nsi' should be read no_short_if.
45 Some rules have been modified to support JDK1.1 inner classes
46 definitions and other extensions. */
57 #include "java-tree.h"
70 #define DIR_SEPARATOR '/'
73 /* Local function prototypes */
74 static char *java_accstring_lookup PARAMS ((int));
75 static void classitf_redefinition_error PARAMS ((const char *,tree, tree, tree));
76 static void variable_redefinition_error PARAMS ((tree, tree, tree, int));
77 static tree create_class PARAMS ((int, tree, tree, tree));
78 static tree create_interface PARAMS ((int, tree, tree));
79 static void end_class_declaration PARAMS ((int));
80 static tree find_field PARAMS ((tree, tree));
81 static tree lookup_field_wrapper PARAMS ((tree, tree));
82 static int duplicate_declaration_error_p PARAMS ((tree, tree, tree));
83 static void register_fields PARAMS ((int, tree, tree));
84 static tree parser_qualified_classname PARAMS ((tree));
85 static int parser_check_super PARAMS ((tree, tree, tree));
86 static int parser_check_super_interface PARAMS ((tree, tree, tree));
87 static void check_modifiers_consistency PARAMS ((int));
88 static tree lookup_cl PARAMS ((tree));
89 static tree lookup_java_method2 PARAMS ((tree, tree, int));
90 static tree method_header PARAMS ((int, tree, tree, tree));
91 static void fix_method_argument_names PARAMS ((tree ,tree));
92 static tree method_declarator PARAMS ((tree, tree));
93 static void parse_warning_context PARAMS ((tree cl, const char *msg, ...))
95 static void issue_warning_error_from_context PARAMS ((tree, const char *msg, va_list));
96 static void parse_ctor_invocation_error PARAMS ((void));
97 static tree parse_jdk1_1_error PARAMS ((const char *));
98 static void complete_class_report_errors PARAMS ((jdep *));
99 static int process_imports PARAMS ((void));
100 static void read_import_dir PARAMS ((tree));
101 static int find_in_imports_on_demand PARAMS ((tree));
102 static void find_in_imports PARAMS ((tree));
103 static void check_inner_class_access PARAMS ((tree, tree, tree));
104 static int check_pkg_class_access PARAMS ((tree, tree));
105 static void register_package PARAMS ((tree));
106 static tree resolve_package PARAMS ((tree, tree *));
107 static tree lookup_package_type PARAMS ((const char *, int));
108 static tree lookup_package_type_and_set_next PARAMS ((const char *, int, tree *));
109 static tree resolve_class PARAMS ((tree, tree, tree, tree));
110 static void declare_local_variables PARAMS ((int, tree, tree));
111 static void source_start_java_method PARAMS ((tree));
112 static void source_end_java_method PARAMS ((void));
113 static void expand_start_java_method PARAMS ((tree));
114 static tree find_name_in_single_imports PARAMS ((tree));
115 static void check_abstract_method_header PARAMS ((tree));
116 static tree lookup_java_interface_method2 PARAMS ((tree, tree));
117 static tree resolve_expression_name PARAMS ((tree, tree *));
118 static tree maybe_create_class_interface_decl PARAMS ((tree, tree, tree, tree));
119 static int check_class_interface_creation PARAMS ((int, int, tree,
121 static tree patch_method_invocation PARAMS ((tree, tree, tree,
123 static int breakdown_qualified PARAMS ((tree *, tree *, tree));
124 static tree resolve_and_layout PARAMS ((tree, tree));
125 static tree qualify_and_find PARAMS ((tree, tree, tree));
126 static tree resolve_no_layout PARAMS ((tree, tree));
127 static int invocation_mode PARAMS ((tree, int));
128 static tree find_applicable_accessible_methods_list PARAMS ((int, tree,
130 static void search_applicable_methods_list PARAMS ((int, tree, tree, tree,
132 static tree find_most_specific_methods_list PARAMS ((tree));
133 static int argument_types_convertible PARAMS ((tree, tree));
134 static tree patch_invoke PARAMS ((tree, tree, tree));
135 static int maybe_use_access_method PARAMS ((int, tree *, tree *));
136 static tree lookup_method_invoke PARAMS ((int, tree, tree, tree, tree));
137 static tree register_incomplete_type PARAMS ((int, tree, tree, tree));
138 static tree obtain_incomplete_type PARAMS ((tree));
139 static tree java_complete_lhs PARAMS ((tree));
140 static tree java_complete_tree PARAMS ((tree));
141 static tree maybe_generate_pre_expand_clinit PARAMS ((tree));
142 static int maybe_yank_clinit PARAMS ((tree));
143 static void java_complete_expand_method PARAMS ((tree));
144 static int unresolved_type_p PARAMS ((tree, tree *));
145 static void create_jdep_list PARAMS ((struct parser_ctxt *));
146 static tree build_expr_block PARAMS ((tree, tree));
147 static tree enter_block PARAMS ((void));
148 static tree enter_a_block PARAMS ((tree));
149 static tree exit_block PARAMS ((void));
150 static tree lookup_name_in_blocks PARAMS ((tree));
151 static void maybe_absorb_scoping_blocks PARAMS ((void));
152 static tree build_method_invocation PARAMS ((tree, tree));
153 static tree build_new_invocation PARAMS ((tree, tree));
154 static tree build_assignment PARAMS ((int, int, tree, tree));
155 static tree build_binop PARAMS ((enum tree_code, int, tree, tree));
156 static int check_final_assignment PARAMS ((tree ,tree));
157 static tree patch_assignment PARAMS ((tree, tree, tree ));
158 static tree patch_binop PARAMS ((tree, tree, tree));
159 static tree build_unaryop PARAMS ((int, int, tree));
160 static tree build_incdec PARAMS ((int, int, tree, int));
161 static tree patch_unaryop PARAMS ((tree, tree));
162 static tree build_cast PARAMS ((int, tree, tree));
163 static tree build_null_of_type PARAMS ((tree));
164 static tree patch_cast PARAMS ((tree, tree));
165 static int valid_ref_assignconv_cast_p PARAMS ((tree, tree, int));
166 static int valid_builtin_assignconv_identity_widening_p PARAMS ((tree, tree));
167 static int valid_cast_to_p PARAMS ((tree, tree));
168 static int valid_method_invocation_conversion_p PARAMS ((tree, tree));
169 static tree try_builtin_assignconv PARAMS ((tree, tree, tree));
170 static tree try_reference_assignconv PARAMS ((tree, tree));
171 static tree build_unresolved_array_type PARAMS ((tree));
172 static tree build_array_from_name PARAMS ((tree, tree, tree, tree *));
173 static tree build_array_ref PARAMS ((int, tree, tree));
174 static tree patch_array_ref PARAMS ((tree));
175 static tree make_qualified_name PARAMS ((tree, tree, int));
176 static tree merge_qualified_name PARAMS ((tree, tree));
177 static tree make_qualified_primary PARAMS ((tree, tree, int));
178 static int resolve_qualified_expression_name PARAMS ((tree, tree *,
180 static void qualify_ambiguous_name PARAMS ((tree));
181 static tree resolve_field_access PARAMS ((tree, tree *, tree *));
182 static tree build_newarray_node PARAMS ((tree, tree, int));
183 static tree patch_newarray PARAMS ((tree));
184 static tree resolve_type_during_patch PARAMS ((tree));
185 static tree build_this PARAMS ((int));
186 static tree build_wfl_wrap PARAMS ((tree, int));
187 static tree build_return PARAMS ((int, tree));
188 static tree patch_return PARAMS ((tree));
189 static tree maybe_access_field PARAMS ((tree, tree, tree));
190 static int complete_function_arguments PARAMS ((tree));
191 static int check_for_static_method_reference PARAMS ((tree, tree, tree,
193 static int not_accessible_p PARAMS ((tree, tree, int));
194 static void check_deprecation PARAMS ((tree, tree));
195 static int class_in_current_package PARAMS ((tree));
196 static tree build_if_else_statement PARAMS ((int, tree, tree, tree));
197 static tree patch_if_else_statement PARAMS ((tree));
198 static tree add_stmt_to_compound PARAMS ((tree, tree, tree));
199 static tree add_stmt_to_block PARAMS ((tree, tree, tree));
200 static tree patch_exit_expr PARAMS ((tree));
201 static tree build_labeled_block PARAMS ((int, tree));
202 static tree finish_labeled_statement PARAMS ((tree, tree));
203 static tree build_bc_statement PARAMS ((int, int, tree));
204 static tree patch_bc_statement PARAMS ((tree));
205 static tree patch_loop_statement PARAMS ((tree));
206 static tree build_new_loop PARAMS ((tree));
207 static tree build_loop_body PARAMS ((int, tree, int));
208 static tree finish_loop_body PARAMS ((int, tree, tree, int));
209 static tree build_debugable_stmt PARAMS ((int, tree));
210 static tree finish_for_loop PARAMS ((int, tree, tree, tree));
211 static tree patch_switch_statement PARAMS ((tree));
212 static tree string_constant_concatenation PARAMS ((tree, tree));
213 static tree build_string_concatenation PARAMS ((tree, tree));
214 static tree patch_string_cst PARAMS ((tree));
215 static tree patch_string PARAMS ((tree));
216 static tree build_try_statement PARAMS ((int, tree, tree));
217 static tree build_try_finally_statement PARAMS ((int, tree, tree));
218 static tree patch_try_statement PARAMS ((tree));
219 static tree patch_synchronized_statement PARAMS ((tree, tree));
220 static tree patch_throw_statement PARAMS ((tree, tree));
221 static void check_thrown_exceptions PARAMS ((int, tree));
222 static int check_thrown_exceptions_do PARAMS ((tree));
223 static void purge_unchecked_exceptions PARAMS ((tree));
224 static void check_throws_clauses PARAMS ((tree, tree, tree));
225 static void finish_method_declaration PARAMS ((tree));
226 static tree build_super_invocation PARAMS ((tree));
227 static int verify_constructor_circularity PARAMS ((tree, tree));
228 static char *constructor_circularity_msg PARAMS ((tree, tree));
229 static tree build_this_super_qualified_invocation PARAMS ((int, tree, tree,
231 static const char *get_printable_method_name PARAMS ((tree));
232 static tree patch_conditional_expr PARAMS ((tree, tree, tree));
233 static tree generate_finit PARAMS ((tree));
234 static void add_instance_initializer PARAMS ((tree));
235 static void fix_constructors PARAMS ((tree));
236 static tree build_alias_initializer_parameter_list PARAMS ((int, tree,
238 static void craft_constructor PARAMS ((tree, tree));
239 static int verify_constructor_super PARAMS ((tree));
240 static tree create_artificial_method PARAMS ((tree, int, tree, tree, tree));
241 static void start_artificial_method_body PARAMS ((tree));
242 static void end_artificial_method_body PARAMS ((tree));
243 static int check_method_redefinition PARAMS ((tree, tree));
244 static int reset_method_name PARAMS ((tree));
245 static int check_method_types_complete PARAMS ((tree));
246 static void java_check_regular_methods PARAMS ((tree));
247 static void java_check_abstract_methods PARAMS ((tree));
248 static tree maybe_build_primttype_type_ref PARAMS ((tree, tree));
249 static void unreachable_stmt_error PARAMS ((tree));
250 static tree find_expr_with_wfl PARAMS ((tree));
251 static void missing_return_error PARAMS ((tree));
252 static tree build_new_array_init PARAMS ((int, tree));
253 static tree patch_new_array_init PARAMS ((tree, tree));
254 static tree maybe_build_array_element_wfl PARAMS ((tree));
255 static int array_constructor_check_entry PARAMS ((tree, tree));
256 static const char *purify_type_name PARAMS ((const char *));
257 static tree fold_constant_for_init PARAMS ((tree, tree));
258 static tree strip_out_static_field_access_decl PARAMS ((tree));
259 static jdeplist *reverse_jdep_list PARAMS ((struct parser_ctxt *));
260 static void static_ref_err PARAMS ((tree, tree, tree));
261 static void parser_add_interface PARAMS ((tree, tree, tree));
262 static void add_superinterfaces PARAMS ((tree, tree));
263 static tree jdep_resolve_class PARAMS ((jdep *));
264 static int note_possible_classname PARAMS ((const char *, int));
265 static void java_complete_expand_classes PARAMS ((void));
266 static void java_complete_expand_class PARAMS ((tree));
267 static void java_complete_expand_methods PARAMS ((tree));
268 static tree cut_identifier_in_qualified PARAMS ((tree));
269 static tree java_stabilize_reference PARAMS ((tree));
270 static tree do_unary_numeric_promotion PARAMS ((tree));
271 static char * operator_string PARAMS ((tree));
272 static tree do_merge_string_cste PARAMS ((tree, const char *, int, int));
273 static tree merge_string_cste PARAMS ((tree, tree, int));
274 static tree java_refold PARAMS ((tree));
275 static int java_decl_equiv PARAMS ((tree, tree));
276 static int binop_compound_p PARAMS ((enum tree_code));
277 static tree search_loop PARAMS ((tree));
278 static int labeled_block_contains_loop_p PARAMS ((tree, tree));
279 static void check_abstract_method_definitions PARAMS ((int, tree, tree));
280 static void java_check_abstract_method_definitions PARAMS ((tree));
281 static void java_debug_context_do PARAMS ((int));
282 static void java_parser_context_push_initialized_field PARAMS ((void));
283 static void java_parser_context_pop_initialized_field PARAMS ((void));
284 static tree reorder_static_initialized PARAMS ((tree));
285 static void java_parser_context_suspend PARAMS ((void));
286 static void java_parser_context_resume PARAMS ((void));
288 /* JDK 1.1 work. FIXME */
290 static tree maybe_make_nested_class_name PARAMS ((tree));
291 static void make_nested_class_name PARAMS ((tree));
292 static void set_nested_class_simple_name_value PARAMS ((tree, int));
293 static void link_nested_class_to_enclosing PARAMS ((void));
294 static tree find_as_inner_class PARAMS ((tree, tree, tree));
295 static tree find_as_inner_class_do PARAMS ((tree, tree));
296 static int check_inner_class_redefinition PARAMS ((tree, tree));
298 static tree build_thisn_assign PARAMS ((void));
299 static tree build_current_thisn PARAMS ((tree));
300 static tree build_access_to_thisn PARAMS ((tree, tree, int));
301 static tree maybe_build_thisn_access_method PARAMS ((tree));
303 static tree build_outer_field_access PARAMS ((tree, tree));
304 static tree build_outer_field_access_methods PARAMS ((tree));
305 static tree build_outer_field_access_expr PARAMS ((int, tree, tree,
307 static tree build_outer_method_access_method PARAMS ((tree));
308 static tree build_new_access_id PARAMS ((void));
309 static tree build_outer_field_access_method PARAMS ((tree, tree, tree,
312 static int outer_field_access_p PARAMS ((tree, tree));
313 static int outer_field_expanded_access_p PARAMS ((tree, tree *,
315 static tree outer_field_access_fix PARAMS ((tree, tree, tree));
316 static tree build_incomplete_class_ref PARAMS ((int, tree));
317 static tree patch_incomplete_class_ref PARAMS ((tree));
318 static tree create_anonymous_class PARAMS ((int, tree));
319 static void patch_anonymous_class PARAMS ((tree, tree, tree));
320 static void add_inner_class_fields PARAMS ((tree, tree));
322 static tree build_dot_class_method PARAMS ((tree));
323 static tree build_dot_class_method_invocation PARAMS ((tree));
324 static void create_new_parser_context PARAMS ((int));
326 /* Number of error found so far. */
327 int java_error_count;
328 /* Number of warning found so far. */
329 int java_warning_count;
330 /* Tell when not to fold, when doing xrefs */
332 /* Cyclic inheritance report, as it can be set by layout_class */
333 char *cyclic_inheritance_report;
335 /* Tell when we're within an instance initializer */
336 static int in_instance_initializer;
338 /* The current parser context */
339 struct parser_ctxt *ctxp;
341 /* List of things that were analyzed for which code will be generated */
342 static struct parser_ctxt *ctxp_for_generation = NULL;
344 /* binop_lookup maps token to tree_code. It is used where binary
345 operations are involved and required by the parser. RDIV_EXPR
346 covers both integral/floating point division. The code is changed
347 once the type of both operator is worked out. */
349 static enum tree_code binop_lookup[19] =
351 PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
352 LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR,
353 BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
354 TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
355 EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
357 #define BINOP_LOOKUP(VALUE) \
358 binop_lookup [((VALUE) - PLUS_TK)% \
359 (sizeof (binop_lookup) / sizeof (binop_lookup[0]))]
361 /* This is the end index for binary operators that can also be used
362 in compound assignements. */
363 #define BINOP_COMPOUND_CANDIDATES 11
365 /* Fake WFL used to report error message. It is initialized once if
366 needed and reused with it's location information is overriden. */
367 tree wfl_operator = NULL_TREE;
369 /* The "$L" identifier we use to create labels. */
370 static tree label_id = NULL_TREE;
372 /* The "StringBuffer" identifier used for the String `+' operator. */
373 static tree wfl_string_buffer = NULL_TREE;
375 /* The "append" identifier used for String `+' operator. */
376 static tree wfl_append = NULL_TREE;
378 /* The "toString" identifier used for String `+' operator. */
379 static tree wfl_to_string = NULL_TREE;
381 /* The "java.lang" import qualified name. */
382 static tree java_lang_id = NULL_TREE;
384 /* The generated `inst$' identifier used for generated enclosing
385 instance/field access functions. */
386 static tree inst_id = NULL_TREE;
388 /* The "java.lang.Cloneable" qualified name. */
389 static tree java_lang_cloneable = NULL_TREE;
391 /* Context and flag for static blocks */
392 static tree current_static_block = NULL_TREE;
394 /* The generated `write_parm_value$' identifier. */
397 /* The list of all packages we've seen so far */
398 static tree package_list = NULL_TREE;
400 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
401 line and point it out. */
402 /* Should point out the one that don't fit. ASCII/unicode, going
405 #define check_modifiers(__message, __value, __mask) do { \
406 if ((__value) & ~(__mask)) \
408 int i, remainder = (__value) & ~(__mask); \
409 for (i = 0; i <= 10; i++) \
410 if ((1 << i) & remainder) \
411 parse_error_context (ctxp->modifier_ctx [i], (__message), \
412 java_accstring_lookup (1 << i)); \
434 /* Things defined here have to match the order of what's in the
435 binop_lookup table. */
437 %token PLUS_TK MINUS_TK MULT_TK DIV_TK REM_TK
438 %token LS_TK SRS_TK ZRS_TK
439 %token AND_TK XOR_TK OR_TK
440 %token BOOL_AND_TK BOOL_OR_TK
441 %token EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
443 /* This maps to the same binop_lookup entry than the token above */
445 %token PLUS_ASSIGN_TK MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
447 %token LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
448 %token AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
451 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
453 %token PUBLIC_TK PRIVATE_TK PROTECTED_TK
454 %token STATIC_TK FINAL_TK SYNCHRONIZED_TK
455 %token VOLATILE_TK TRANSIENT_TK NATIVE_TK
456 %token PAD_TK ABSTRACT_TK MODIFIER_TK
458 /* Keep those two in order, too */
459 %token DECR_TK INCR_TK
461 /* From now one, things can be in any order */
463 %token DEFAULT_TK IF_TK THROW_TK
464 %token BOOLEAN_TK DO_TK IMPLEMENTS_TK
465 %token THROWS_TK BREAK_TK IMPORT_TK
466 %token ELSE_TK INSTANCEOF_TK RETURN_TK
467 %token VOID_TK CATCH_TK INTERFACE_TK
468 %token CASE_TK EXTENDS_TK FINALLY_TK
469 %token SUPER_TK WHILE_TK CLASS_TK
470 %token SWITCH_TK CONST_TK TRY_TK
471 %token FOR_TK NEW_TK CONTINUE_TK
472 %token GOTO_TK PACKAGE_TK THIS_TK
474 %token BYTE_TK SHORT_TK INT_TK LONG_TK
475 %token CHAR_TK INTEGRAL_TK
477 %token FLOAT_TK DOUBLE_TK FP_TK
481 %token REL_QM_TK REL_CL_TK NOT_TK NEG_TK
483 %token ASSIGN_ANY_TK ASSIGN_TK
484 %token OP_TK CP_TK OCB_TK CCB_TK OSB_TK CSB_TK SC_TK C_TK DOT_TK
486 %token STRING_LIT_TK CHAR_LIT_TK INT_LIT_TK FP_LIT_TK
487 %token TRUE_TK FALSE_TK BOOL_LIT_TK NULL_TK
489 %type <value> modifiers MODIFIER_TK final synchronized
491 %type <node> super ID_TK identifier
492 %type <node> name simple_name qualified_name
493 %type <node> type_declaration compilation_unit
494 field_declaration method_declaration extends_interfaces
495 interfaces interface_type_list
496 class_member_declaration
497 import_declarations package_declaration
498 type_declarations interface_body
499 interface_member_declaration constant_declaration
500 interface_member_declarations interface_type
501 abstract_method_declaration interface_type_list
502 %type <node> class_body_declaration class_member_declaration
503 static_initializer constructor_declaration block
504 %type <node> class_body_declarations constructor_header
505 %type <node> class_or_interface_type class_type class_type_list
506 constructor_declarator explicit_constructor_invocation
507 %type <node> dim_expr dim_exprs this_or_super throws
509 %type <node> variable_declarator_id variable_declarator
510 variable_declarators variable_initializer
511 variable_initializers constructor_body
514 %type <node> class_body block_end constructor_block_end
515 %type <node> statement statement_without_trailing_substatement
516 labeled_statement if_then_statement label_decl
517 if_then_else_statement while_statement for_statement
518 statement_nsi labeled_statement_nsi do_statement
519 if_then_else_statement_nsi while_statement_nsi
520 for_statement_nsi statement_expression_list for_init
521 for_update statement_expression expression_statement
522 primary_no_new_array expression primary
523 array_creation_expression array_type
524 class_instance_creation_expression field_access
525 method_invocation array_access something_dot_new
526 argument_list postfix_expression while_expression
527 post_increment_expression post_decrement_expression
528 unary_expression_not_plus_minus unary_expression
529 pre_increment_expression pre_decrement_expression
530 unary_expression_not_plus_minus cast_expression
531 multiplicative_expression additive_expression
532 shift_expression relational_expression
533 equality_expression and_expression
534 exclusive_or_expression inclusive_or_expression
535 conditional_and_expression conditional_or_expression
536 conditional_expression assignment_expression
537 left_hand_side assignment for_header for_begin
538 constant_expression do_statement_begin empty_statement
539 switch_statement synchronized_statement throw_statement
540 try_statement switch_expression switch_block
541 catches catch_clause catch_clause_parameter finally
542 anonymous_class_creation
543 %type <node> return_statement break_statement continue_statement
545 %type <operator> ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
546 %type <operator> REM_ASSIGN_TK PLUS_ASSIGN_TK MINUS_ASSIGN_TK
547 %type <operator> LS_ASSIGN_TK SRS_ASSIGN_TK ZRS_ASSIGN_TK
548 %type <operator> AND_ASSIGN_TK XOR_ASSIGN_TK OR_ASSIGN_TK
549 %type <operator> ASSIGN_ANY_TK assignment_operator
550 %token <operator> EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK
551 %token <operator> BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
552 %token <operator> DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
553 %token <operator> NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
554 %token <operator> OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
555 %type <operator> THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK
556 %type <operator> CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
557 %type <operator> NEW_TK
559 %type <node> method_body
561 %type <node> literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
562 STRING_LIT_TK NULL_TK VOID_TK
564 %type <node> IF_TK WHILE_TK FOR_TK
566 %type <node> formal_parameter_list formal_parameter
567 method_declarator method_header
569 %type <node> primitive_type reference_type type
570 BOOLEAN_TK INTEGRAL_TK FP_TK
572 /* Added or modified JDK 1.1 rule types */
573 %type <node> type_literals array_type_literal
576 /* 19.2 Production from 2.3: The Syntactic Grammar */
582 /* 19.3 Productions from 3: Lexical structure */
592 /* 19.4 Productions from 4: Types, Values and Variables */
605 class_or_interface_type
609 class_or_interface_type:
614 class_or_interface_type /* Default rule */
618 class_or_interface_type
622 primitive_type OSB_TK CSB_TK
624 $$ = build_java_array_type ($1, -1);
625 CLASS_LOADED_P ($$) = 1;
628 { $$ = build_unresolved_array_type ($1); }
629 | array_type OSB_TK CSB_TK
630 { $$ = build_unresolved_array_type ($1); }
631 | primitive_type OSB_TK error
632 {RULE ("']' expected"); RECOVER;}
633 | array_type OSB_TK error
634 {RULE ("']' expected"); RECOVER;}
637 /* 19.5 Productions from 6: Names */
639 simple_name /* Default rule */
640 | qualified_name /* Default rule */
644 identifier /* Default rule */
646 if (strchr (IDENTIFIER_POINTER (EXPR_WFL_NODE ($$)), '$'))
647 parse_error_context ($$, "Invalide name `%s'",
648 IDENTIFIER_POINTER (EXPR_WFL_NODE ($$)));
653 name DOT_TK identifier
654 { $$ = make_qualified_name ($1, $3, $2.location); }
661 /* 19.6: Production from 7: Packages */
664 | package_declaration
665 | import_declarations
667 | package_declaration import_declarations
668 | package_declaration type_declarations
669 | import_declarations type_declarations
670 | package_declaration import_declarations type_declarations
678 | import_declarations import_declaration
686 | type_declarations type_declaration
690 PACKAGE_TK name SC_TK
692 ctxp->package = EXPR_WFL_NODE ($2);
693 register_package (ctxp->package);
696 {yyerror ("Missing name"); RECOVER;}
697 | PACKAGE_TK name error
698 {yyerror ("';' expected"); RECOVER;}
702 single_type_import_declaration
703 | type_import_on_demand_declaration
706 single_type_import_declaration:
709 tree name = EXPR_WFL_NODE ($2), last_name;
710 int i = IDENTIFIER_LENGTH (name)-1;
711 const char *last = &IDENTIFIER_POINTER (name)[i];
712 while (last != IDENTIFIER_POINTER (name))
718 last_name = get_identifier (++last);
719 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
721 tree err = find_name_in_single_imports (last_name);
722 if (err && err != name)
724 ($2, "Ambiguous class: `%s' and `%s'",
725 IDENTIFIER_POINTER (name),
726 IDENTIFIER_POINTER (err));
728 REGISTER_IMPORT ($2, last_name);
731 REGISTER_IMPORT ($2, last_name);
734 {yyerror ("Missing name"); RECOVER;}
735 | IMPORT_TK name error
736 {yyerror ("';' expected"); RECOVER;}
739 type_import_on_demand_declaration:
740 IMPORT_TK name DOT_TK MULT_TK SC_TK
742 tree name = EXPR_WFL_NODE ($2);
743 /* Don't import java.lang.* twice. */
744 if (name != java_lang_id)
746 read_import_dir ($2);
747 ctxp->import_demand_list =
748 chainon (ctxp->import_demand_list,
749 build_tree_list ($2, NULL_TREE));
752 | IMPORT_TK name DOT_TK error
753 {yyerror ("'*' expected"); RECOVER;}
754 | IMPORT_TK name DOT_TK MULT_TK error
755 {yyerror ("';' expected"); RECOVER;}
760 { end_class_declaration (0); }
761 | interface_declaration
762 { end_class_declaration (0); }
768 yyerror ("Class or interface declaration expected");
772 /* 19.7 Shortened from the original:
773 modifiers: modifier | modifiers modifier
774 modifier: any of public... */
780 | modifiers MODIFIER_TK
785 (ctxp->modifier_ctx [$2], "Modifier `%s' declared twice",
786 java_accstring_lookup (acc));
794 /* 19.8.1 Production from $8.1: Class Declaration */
796 modifiers CLASS_TK identifier super interfaces
797 { create_class ($1, $3, $4, $5); }
799 | CLASS_TK identifier super interfaces
800 { create_class (0, $2, $3, $4); }
802 | modifiers CLASS_TK error
803 {yyerror ("Missing class name"); RECOVER;}
805 {yyerror ("Missing class name"); RECOVER;}
806 | CLASS_TK identifier error
808 if (!ctxp->class_err) yyerror ("'{' expected");
811 | modifiers CLASS_TK identifier error
812 {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
817 | EXTENDS_TK class_type
819 | EXTENDS_TK class_type error
820 {yyerror ("'{' expected"); ctxp->class_err=1;}
822 {yyerror ("Missing super class name"); ctxp->class_err=1;}
827 | IMPLEMENTS_TK interface_type_list
829 | IMPLEMENTS_TK error
832 yyerror ("Missing interface name");
839 ctxp->interface_number = 1;
840 $$ = build_tree_list ($1, NULL_TREE);
842 | interface_type_list C_TK interface_type
844 ctxp->interface_number++;
845 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
847 | interface_type_list C_TK error
848 {yyerror ("Missing interface name"); RECOVER;}
854 /* Store the location of the `}' when doing xrefs */
856 DECL_END_SOURCE_LINE (GET_CPC ()) =
857 EXPR_WFL_ADD_COL ($2.location, 1);
860 | OCB_TK class_body_declarations CCB_TK
862 /* Store the location of the `}' when doing xrefs */
864 DECL_END_SOURCE_LINE (GET_CPC ()) =
865 EXPR_WFL_ADD_COL ($3.location, 1);
870 class_body_declarations:
871 class_body_declaration
872 | class_body_declarations class_body_declaration
875 class_body_declaration:
876 class_member_declaration
878 | constructor_declaration
879 | block /* Added, JDK1.1, instance initializer */
881 TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
882 SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
886 class_member_declaration:
888 | field_declaration SC_TK
891 | class_declaration /* Added, JDK1.1 inner classes */
892 { end_class_declaration (1); }
893 | interface_declaration /* Added, JDK1.1 inner interfaces */
894 { end_class_declaration (1); }
897 /* 19.8.2 Productions from 8.3: Field Declarations */
899 type variable_declarators SC_TK
900 { register_fields (0, $1, $2); }
901 | modifiers type variable_declarators SC_TK
904 ("Illegal modifier `%s' for field declaration",
905 $1, FIELD_MODIFIERS);
906 check_modifiers_consistency ($1);
907 register_fields ($1, $2, $3);
911 variable_declarators:
912 /* Should we use build_decl_list () instead ? FIXME */
913 variable_declarator /* Default rule */
914 | variable_declarators C_TK variable_declarator
915 { $$ = chainon ($1, $3); }
916 | variable_declarators C_TK error
917 {yyerror ("Missing term"); RECOVER;}
921 variable_declarator_id
922 { $$ = build_tree_list ($1, NULL_TREE); }
923 | variable_declarator_id ASSIGN_TK variable_initializer
925 if (java_error_count)
928 ($1, build_assignment ($2.token, $2.location, $1, $3));
930 | variable_declarator_id ASSIGN_TK error
932 yyerror ("Missing variable initializer");
933 $$ = build_tree_list ($1, NULL_TREE);
936 | variable_declarator_id ASSIGN_TK variable_initializer error
938 yyerror ("';' expected");
939 $$ = build_tree_list ($1, NULL_TREE);
944 variable_declarator_id:
946 | variable_declarator_id OSB_TK CSB_TK
947 { $$ = build_unresolved_array_type ($1); }
949 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
950 | variable_declarator_id OSB_TK error
951 {yyerror ("']' expected"); DRECOVER(vdi);}
952 | variable_declarator_id CSB_TK error
953 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
956 variable_initializer:
961 /* 19.8.3 Productions from 8.4: Method Declarations */
965 current_function_decl = $1;
966 if (current_function_decl
967 && TREE_CODE (current_function_decl) == FUNCTION_DECL)
968 source_start_java_method (current_function_decl);
970 current_function_decl = NULL_TREE;
973 { finish_method_declaration ($3); }
974 | method_header error
975 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
979 type method_declarator throws
980 { $$ = method_header (0, $1, $2, $3); }
981 | VOID_TK method_declarator throws
982 { $$ = method_header (0, void_type_node, $2, $3); }
983 | modifiers type method_declarator throws
984 { $$ = method_header ($1, $2, $3, $4); }
985 | modifiers VOID_TK method_declarator throws
986 { $$ = method_header ($1, void_type_node, $3, $4); }
989 yyerror ("Invalid method declaration, method name required");
992 | modifiers type error
995 {yyerror ("Identifier expected"); RECOVER;}
996 | modifiers VOID_TK error
997 {yyerror ("Identifier expected"); RECOVER;}
1000 yyerror ("Invalid method declaration, return type required");
1006 identifier OP_TK CP_TK
1008 ctxp->formal_parameter_number = 0;
1009 $$ = method_declarator ($1, NULL_TREE);
1011 | identifier OP_TK formal_parameter_list CP_TK
1012 { $$ = method_declarator ($1, $3); }
1013 | method_declarator OSB_TK CSB_TK
1015 EXPR_WFL_LINECOL (wfl_operator) = $2.location;
1017 build_unresolved_array_type (TREE_PURPOSE ($1));
1018 parse_warning_context
1020 "Discouraged form of returned type specification");
1022 | identifier OP_TK error
1023 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1024 | method_declarator OSB_TK error
1025 {yyerror ("']' expected"); RECOVER;}
1028 formal_parameter_list:
1031 ctxp->formal_parameter_number = 1;
1033 | formal_parameter_list C_TK formal_parameter
1035 ctxp->formal_parameter_number += 1;
1036 $$ = chainon ($1, $3);
1038 | formal_parameter_list C_TK error
1039 { yyerror ("Missing formal parameter term"); RECOVER; }
1043 type variable_declarator_id
1045 $$ = build_tree_list ($2, $1);
1047 | final type variable_declarator_id /* Added, JDK1.1 final parms */
1049 $$ = build_tree_list ($3, $2);
1050 ARG_FINAL_P ($$) = 1;
1054 yyerror ("Missing identifier"); RECOVER;
1059 yyerror ("Missing identifier"); RECOVER;
1067 check_modifiers ("Illegal modifier `%s'. Only `final' was expected here",
1069 if ($1 != ACC_FINAL)
1070 MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1076 | THROWS_TK class_type_list
1079 {yyerror ("Missing class type term"); RECOVER;}
1084 { $$ = build_tree_list ($1, $1); }
1085 | class_type_list C_TK class_type
1086 { $$ = tree_cons ($3, $3, $1); }
1087 | class_type_list C_TK error
1088 {yyerror ("Missing class type term"); RECOVER;}
1095 { $$ = NULL_TREE; } /* Probably not the right thing to do. */
1098 /* 19.8.4 Productions from 8.5: Static Initializers */
1102 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1103 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1105 | static block SC_TK /* Shouldn't be here. FIXME */
1107 TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1108 SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1112 static: /* Test lval.sub_token here */
1115 check_modifiers ("Illegal modifier `%s' for static initializer", $1, ACC_STATIC);
1116 /* Can't have a static initializer in an innerclass */
1117 if ($1 | ACC_STATIC &&
1118 GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1120 (MODIFIER_WFL (STATIC_TK),
1121 "Can't define static initializer in class `%s'. Static initializer can only be defined in top-level classes",
1122 IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1123 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1127 /* 19.8.5 Productions from 8.6: Constructor Declarations */
1128 constructor_declaration:
1131 current_function_decl = $1;
1132 source_start_java_method (current_function_decl);
1135 { finish_method_declaration ($3); }
1139 constructor_declarator throws
1140 { $$ = method_header (0, NULL_TREE, $1, $2); }
1141 | modifiers constructor_declarator throws
1142 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1145 constructor_declarator:
1146 simple_name OP_TK CP_TK
1148 ctxp->formal_parameter_number = 0;
1149 $$ = method_declarator ($1, NULL_TREE);
1151 | simple_name OP_TK formal_parameter_list CP_TK
1152 { $$ = method_declarator ($1, $3); }
1156 /* Unlike regular method, we always need a complete (empty)
1157 body so we can safely perform all the required code
1158 addition (super invocation and field initialization) */
1159 block_begin constructor_block_end
1161 BLOCK_EXPR_BODY ($2) = empty_stmt_node;
1164 | block_begin explicit_constructor_invocation constructor_block_end
1166 | block_begin block_statements constructor_block_end
1168 | block_begin explicit_constructor_invocation block_statements constructor_block_end
1172 constructor_block_end:
1176 /* Error recovery for that rule moved down expression_statement: rule. */
1177 explicit_constructor_invocation:
1178 this_or_super OP_TK CP_TK SC_TK
1180 $$ = build_method_invocation ($1, NULL_TREE);
1181 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1182 $$ = java_method_add_stmt (current_function_decl, $$);
1184 | this_or_super OP_TK argument_list CP_TK SC_TK
1186 $$ = build_method_invocation ($1, $3);
1187 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1188 $$ = java_method_add_stmt (current_function_decl, $$);
1190 /* Added, JDK1.1 inner classes. Modified because the rule
1191 'primary' couldn't work. */
1192 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1193 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1194 | name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1195 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1198 this_or_super: /* Added, simplifies error diagnostics */
1201 tree wfl = build_wfl_node (this_identifier_node);
1202 EXPR_WFL_LINECOL (wfl) = $1.location;
1207 tree wfl = build_wfl_node (super_identifier_node);
1208 EXPR_WFL_LINECOL (wfl) = $1.location;
1213 /* 19.9 Productions from 9: Interfaces */
1214 /* 19.9.1 Productions from 9.1: Interfaces Declarations */
1215 interface_declaration:
1216 INTERFACE_TK identifier
1217 { create_interface (0, $2, NULL_TREE); }
1219 | modifiers INTERFACE_TK identifier
1220 { create_interface ($1, $3, NULL_TREE); }
1222 | INTERFACE_TK identifier extends_interfaces
1223 { create_interface (0, $2, $3); }
1225 | modifiers INTERFACE_TK identifier extends_interfaces
1226 { create_interface ($1, $3, $4); }
1228 | INTERFACE_TK identifier error
1229 {yyerror ("'{' expected"); RECOVER;}
1230 | modifiers INTERFACE_TK identifier error
1231 {yyerror ("'{' expected"); RECOVER;}
1235 EXTENDS_TK interface_type
1237 ctxp->interface_number = 1;
1238 $$ = build_tree_list ($2, NULL_TREE);
1240 | extends_interfaces C_TK interface_type
1242 ctxp->interface_number++;
1243 $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1246 {yyerror ("Invalid interface type"); RECOVER;}
1247 | extends_interfaces C_TK error
1248 {yyerror ("Missing term"); RECOVER;}
1254 | OCB_TK interface_member_declarations CCB_TK
1258 interface_member_declarations:
1259 interface_member_declaration
1260 | interface_member_declarations interface_member_declaration
1263 interface_member_declaration:
1264 constant_declaration
1265 | abstract_method_declaration
1266 | class_declaration /* Added, JDK1.1 inner classes */
1267 { end_class_declaration (1); }
1268 | interface_declaration /* Added, JDK1.1 inner interfaces */
1269 { end_class_declaration (1); }
1272 constant_declaration:
1276 abstract_method_declaration:
1279 check_abstract_method_header ($1);
1280 current_function_decl = NULL_TREE; /* FIXME ? */
1282 | method_header error
1283 {yyerror ("';' expected"); RECOVER;}
1286 /* 19.10 Productions from 10: Arrays */
1289 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1290 | OCB_TK variable_initializers CCB_TK
1291 { $$ = build_new_array_init ($1.location, $2); }
1292 | OCB_TK variable_initializers C_TK CCB_TK
1293 { $$ = build_new_array_init ($1.location, $2); }
1296 variable_initializers:
1297 variable_initializer
1299 $$ = tree_cons (maybe_build_array_element_wfl ($1),
1302 | variable_initializers C_TK variable_initializer
1304 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1306 | variable_initializers C_TK error
1307 {yyerror ("Missing term"); RECOVER;}
1310 /* 19.11 Production from 14: Blocks and Statements */
1314 /* Store the location of the `}' when doing xrefs */
1315 if (current_function_decl && flag_emit_xref)
1316 DECL_END_SOURCE_LINE (current_function_decl) =
1317 EXPR_WFL_ADD_COL ($2.location, 1);
1318 $$ = empty_stmt_node;
1320 | block_begin block_statements block_end
1332 maybe_absorb_scoping_blocks ();
1333 /* Store the location of the `}' when doing xrefs */
1334 if (current_function_decl && flag_emit_xref)
1335 DECL_END_SOURCE_LINE (current_function_decl) =
1336 EXPR_WFL_ADD_COL ($1.location, 1);
1338 if (!BLOCK_SUBBLOCKS ($$))
1339 BLOCK_SUBBLOCKS ($$) = empty_stmt_node;
1345 | block_statements block_statement
1349 local_variable_declaration_statement
1351 { java_method_add_stmt (current_function_decl, $1); }
1352 | class_declaration /* Added, JDK1.1 local classes */
1354 LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1355 end_class_declaration (1);
1359 local_variable_declaration_statement:
1360 local_variable_declaration SC_TK /* Can't catch missing ';' here */
1363 local_variable_declaration:
1364 type variable_declarators
1365 { declare_local_variables (0, $1, $2); }
1366 | final type variable_declarators /* Added, JDK1.1 final locals */
1367 { declare_local_variables ($1, $2, $3); }
1371 statement_without_trailing_substatement
1374 | if_then_else_statement
1377 { $$ = exit_block (); }
1381 statement_without_trailing_substatement
1382 | labeled_statement_nsi
1383 | if_then_else_statement_nsi
1384 | while_statement_nsi
1386 { $$ = exit_block (); }
1389 statement_without_trailing_substatement:
1392 | expression_statement
1396 | continue_statement
1398 | synchronized_statement
1405 { $$ = empty_stmt_node; }
1409 identifier REL_CL_TK
1411 $$ = build_labeled_block (EXPR_WFL_LINECOL ($1),
1412 EXPR_WFL_NODE ($1));
1414 push_labeled_block ($$);
1415 PUSH_LABELED_BLOCK ($$);
1420 label_decl statement
1421 { $$ = finish_labeled_statement ($1, $2); }
1423 {yyerror ("':' expected"); RECOVER;}
1426 labeled_statement_nsi:
1427 label_decl statement_nsi
1428 { $$ = finish_labeled_statement ($1, $2); }
1431 /* We concentrate here a bunch of error handling rules that we couldn't write
1432 earlier, because expression_statement catches a missing ';'. */
1433 expression_statement:
1434 statement_expression SC_TK
1436 /* We have a statement. Generate a WFL around it so
1438 $$ = build_expr_wfl ($1, input_filename, lineno, 0);
1439 /* We know we have a statement, so set the debug
1440 info to be eventually generate here. */
1441 $$ = JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1445 if (ctxp->prevent_ese != lineno)
1446 yyerror ("Invalid expression statement");
1447 DRECOVER (expr_stmt);
1451 if (ctxp->prevent_ese != lineno)
1452 yyerror ("Invalid expression statement");
1453 DRECOVER (expr_stmt);
1457 if (ctxp->prevent_ese != lineno)
1458 yyerror ("Invalid expression statement");
1459 DRECOVER (expr_stmt);
1461 | this_or_super OP_TK error
1462 {yyerror ("')' expected"); RECOVER;}
1463 | this_or_super OP_TK CP_TK error
1465 parse_ctor_invocation_error ();
1468 | this_or_super OP_TK argument_list error
1469 {yyerror ("')' expected"); RECOVER;}
1470 | this_or_super OP_TK argument_list CP_TK error
1472 parse_ctor_invocation_error ();
1475 | name DOT_TK SUPER_TK error
1476 {yyerror ("'(' expected"); RECOVER;}
1477 | name DOT_TK SUPER_TK OP_TK error
1478 {yyerror ("')' expected"); RECOVER;}
1479 | name DOT_TK SUPER_TK OP_TK argument_list error
1480 {yyerror ("')' expected"); RECOVER;}
1481 | name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1482 {yyerror ("';' expected"); RECOVER;}
1483 | name DOT_TK SUPER_TK OP_TK CP_TK error
1484 {yyerror ("';' expected"); RECOVER;}
1487 statement_expression:
1489 | pre_increment_expression
1490 | pre_decrement_expression
1491 | post_increment_expression
1492 | post_decrement_expression
1494 | class_instance_creation_expression
1498 IF_TK OP_TK expression CP_TK statement
1500 $$ = build_if_else_statement ($2.location, $3,
1504 {yyerror ("'(' expected"); RECOVER;}
1506 {yyerror ("Missing term"); RECOVER;}
1507 | IF_TK OP_TK expression error
1508 {yyerror ("')' expected"); RECOVER;}
1511 if_then_else_statement:
1512 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1513 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1516 if_then_else_statement_nsi:
1517 IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1518 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1528 /* Make into "proper list" of COMPOUND_EXPRs.
1529 I.e. make the last statment also have its own
1531 maybe_absorb_scoping_blocks ();
1532 TREE_OPERAND ($1, 1) = exit_block ();
1533 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1538 SWITCH_TK OP_TK expression CP_TK
1540 $$ = build (SWITCH_EXPR, NULL_TREE, $3, NULL_TREE);
1541 EXPR_WFL_LINECOL ($$) = $2.location;
1544 {yyerror ("'(' expected"); RECOVER;}
1545 | SWITCH_TK OP_TK error
1546 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1547 | SWITCH_TK OP_TK expression CP_TK error
1548 {yyerror ("'{' expected"); RECOVER;}
1551 /* Default assignment is there to avoid type node on switch_block
1557 | OCB_TK switch_labels CCB_TK
1559 | OCB_TK switch_block_statement_groups CCB_TK
1561 | OCB_TK switch_block_statement_groups switch_labels CCB_TK
1565 switch_block_statement_groups:
1566 switch_block_statement_group
1567 | switch_block_statement_groups switch_block_statement_group
1570 switch_block_statement_group:
1571 switch_labels block_statements
1576 | switch_labels switch_label
1580 CASE_TK constant_expression REL_CL_TK
1582 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1583 EXPR_WFL_LINECOL (lab) = $1.location;
1584 java_method_add_stmt (current_function_decl, lab);
1586 | DEFAULT_TK REL_CL_TK
1588 tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
1589 EXPR_WFL_LINECOL (lab) = $1.location;
1590 java_method_add_stmt (current_function_decl, lab);
1593 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1594 | CASE_TK constant_expression error
1595 {yyerror ("':' expected"); RECOVER;}
1597 {yyerror ("':' expected"); RECOVER;}
1601 WHILE_TK OP_TK expression CP_TK
1603 tree body = build_loop_body ($2.location, $3, 0);
1604 $$ = build_new_loop (body);
1609 while_expression statement
1610 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1612 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1613 | WHILE_TK OP_TK error
1614 {yyerror ("Missing term and ')' expected"); RECOVER;}
1615 | WHILE_TK OP_TK expression error
1616 {yyerror ("')' expected"); RECOVER;}
1619 while_statement_nsi:
1620 while_expression statement_nsi
1621 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1627 tree body = build_loop_body (0, NULL_TREE, 1);
1628 $$ = build_new_loop (body);
1630 /* Need error handing here. FIXME */
1634 do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1635 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1639 for_begin SC_TK expression SC_TK for_update CP_TK statement
1641 if (TREE_CODE_CLASS (TREE_CODE ($3)) == 'c')
1642 $3 = build_wfl_node ($3);
1643 $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1645 | for_begin SC_TK SC_TK for_update CP_TK statement
1647 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1648 /* We have not condition, so we get rid of the EXIT_EXPR */
1649 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1652 | for_begin SC_TK error
1653 {yyerror ("Invalid control expression"); RECOVER;}
1654 | for_begin SC_TK expression SC_TK error
1655 {yyerror ("Invalid update expression"); RECOVER;}
1656 | for_begin SC_TK SC_TK error
1657 {yyerror ("Invalid update expression"); RECOVER;}
1661 for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1662 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1663 | for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1665 $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1666 /* We have not condition, so we get rid of the EXIT_EXPR */
1667 LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) =
1675 /* This scope defined for local variable that may be
1676 defined within the scope of the for loop */
1680 {yyerror ("'(' expected"); DRECOVER(for_1);}
1681 | FOR_TK OP_TK error
1682 {yyerror ("Invalid init statement"); RECOVER;}
1688 /* We now declare the loop body. The loop is
1689 declared as a for loop. */
1690 tree body = build_loop_body (0, NULL_TREE, 0);
1691 $$ = build_new_loop (body);
1692 FOR_LOOP_P ($$) = 1;
1693 /* The loop is added to the current block the for
1694 statement is defined within */
1695 java_method_add_stmt (current_function_decl, $$);
1698 for_init: /* Can be empty */
1699 { $$ = empty_stmt_node; }
1700 | statement_expression_list
1702 /* Init statement recorded within the previously
1703 defined block scope */
1704 $$ = java_method_add_stmt (current_function_decl, $1);
1706 | local_variable_declaration
1708 /* Local variable are recorded within the previously
1709 defined block scope */
1712 | statement_expression_list error
1713 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1716 for_update: /* Can be empty */
1717 {$$ = empty_stmt_node;}
1718 | statement_expression_list
1719 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1722 statement_expression_list:
1723 statement_expression
1724 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1725 | statement_expression_list C_TK statement_expression
1726 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1727 | statement_expression_list C_TK error
1728 {yyerror ("Missing term"); RECOVER;}
1733 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1734 | BREAK_TK identifier SC_TK
1735 { $$ = build_bc_statement ($1.location, 1, $2); }
1737 {yyerror ("Missing term"); RECOVER;}
1738 | BREAK_TK identifier error
1739 {yyerror ("';' expected"); RECOVER;}
1744 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1745 | CONTINUE_TK identifier SC_TK
1746 { $$ = build_bc_statement ($1.location, 0, $2); }
1748 {yyerror ("Missing term"); RECOVER;}
1749 | CONTINUE_TK identifier error
1750 {yyerror ("';' expected"); RECOVER;}
1755 { $$ = build_return ($1.location, NULL_TREE); }
1756 | RETURN_TK expression SC_TK
1757 { $$ = build_return ($1.location, $2); }
1759 {yyerror ("Missing term"); RECOVER;}
1760 | RETURN_TK expression error
1761 {yyerror ("';' expected"); RECOVER;}
1765 THROW_TK expression SC_TK
1767 $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1768 EXPR_WFL_LINECOL ($$) = $1.location;
1771 {yyerror ("Missing term"); RECOVER;}
1772 | THROW_TK expression error
1773 {yyerror ("';' expected"); RECOVER;}
1776 synchronized_statement:
1777 synchronized OP_TK expression CP_TK block
1779 $$ = build (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1780 EXPR_WFL_LINECOL ($$) =
1781 EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1783 | synchronized OP_TK expression CP_TK error
1784 {yyerror ("'{' expected"); RECOVER;}
1785 | synchronized error
1786 {yyerror ("'(' expected"); RECOVER;}
1787 | synchronized OP_TK error CP_TK
1788 {yyerror ("Missing term"); RECOVER;}
1789 | synchronized OP_TK error
1790 {yyerror ("Missing term"); RECOVER;}
1797 "Illegal modifier `%s'. Only `synchronized' was expected here",
1798 $1, ACC_SYNCHRONIZED);
1799 if ($1 != ACC_SYNCHRONIZED)
1800 MODIFIER_WFL (SYNCHRONIZED_TK) =
1801 build_wfl_node (NULL_TREE);
1806 TRY_TK block catches
1807 { $$ = build_try_statement ($1.location, $2, $3); }
1808 | TRY_TK block finally
1809 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1810 | TRY_TK block catches finally
1811 { $$ = build_try_finally_statement
1812 ($1.location, build_try_statement ($1.location,
1816 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1821 | catches catch_clause
1823 TREE_CHAIN ($2) = $1;
1829 catch_clause_parameter block
1831 java_method_add_stmt (current_function_decl, $2);
1836 catch_clause_parameter:
1837 CATCH_TK OP_TK formal_parameter CP_TK
1839 /* We add a block to define a scope for
1840 formal_parameter (CCBP). The formal parameter is
1841 declared initialized by the appropriate function
1843 tree ccpb = enter_block ();
1844 tree init = build_assignment (ASSIGN_TK, $2.location,
1846 soft_exceptioninfo_call_node);
1847 declare_local_variables (0, TREE_VALUE ($3),
1848 build_tree_list (TREE_PURPOSE ($3),
1850 $$ = build1 (CATCH_EXPR, NULL_TREE, ccpb);
1851 EXPR_WFL_LINECOL ($$) = $1.location;
1854 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1855 | CATCH_TK OP_TK error
1857 yyerror ("Missing term or ')' expected");
1858 RECOVER; $$ = NULL_TREE;
1860 | CATCH_TK OP_TK error CP_TK /* That's for () */
1861 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1868 {yyerror ("'{' expected"); RECOVER; }
1871 /* 19.12 Production from 15: Expressions */
1873 primary_no_new_array
1874 | array_creation_expression
1877 primary_no_new_array:
1880 { $$ = build_this ($1.location); }
1881 | OP_TK expression CP_TK
1883 | class_instance_creation_expression
1888 /* Added, JDK1.1 inner classes. Documentation is wrong
1889 refering to a 'ClassName' (class_name) rule that doesn't
1890 exist. Used name: instead. */
1891 | name DOT_TK THIS_TK
1893 tree wfl = build_wfl_node (this_identifier_node);
1894 $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
1896 | OP_TK expression error
1897 {yyerror ("')' expected"); RECOVER;}
1899 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1900 | primitive_type DOT_TK error
1901 {yyerror ("'class' expected" ); RECOVER;}
1902 | VOID_TK DOT_TK error
1903 {yyerror ("'class' expected" ); RECOVER;}
1906 /* Added, JDK1.1 type literals. We can't use `type' directly, so we
1907 broke the rule down a bit. */
1910 primitive_type OSB_TK CSB_TK
1912 $$ = build_java_array_type ($1, -1);
1913 CLASS_LOADED_P ($$) = 1;
1915 | name OSB_TK CSB_TK
1916 { $$ = build_unresolved_array_type ($1); }
1917 /* This triggers two reduce/reduce conflict between array_type_literal and
1919 | array_type OSB_TK CSB_TK
1920 { $$ = build_unresolved_array_type ($1); }
1925 name DOT_TK CLASS_TK
1926 { $$ = build_incomplete_class_ref ($2.location, $1); }
1927 | array_type_literal DOT_TK CLASS_TK
1928 { $$ = build_incomplete_class_ref ($2.location, $1); }
1929 | primitive_type DOT_TK CLASS_TK
1930 { $$ = build_class_ref ($1); }
1931 | VOID_TK DOT_TK CLASS_TK
1932 { $$ = build_class_ref (void_type_node); }
1935 class_instance_creation_expression:
1936 NEW_TK class_type OP_TK argument_list CP_TK
1937 { $$ = build_new_invocation ($2, $4); }
1938 | NEW_TK class_type OP_TK CP_TK
1939 { $$ = build_new_invocation ($2, NULL_TREE); }
1940 | anonymous_class_creation
1941 /* Added, JDK1.1 inner classes, modified to use name or
1942 primary instead of primary solely which couldn't work in
1944 | something_dot_new identifier OP_TK CP_TK
1946 tree ctor = build_new_invocation ($2, NULL_TREE);
1947 $$ = make_qualified_primary ($1, ctor,
1948 EXPR_WFL_LINECOL ($1));
1950 | something_dot_new identifier OP_TK CP_TK class_body
1951 | something_dot_new identifier OP_TK argument_list CP_TK
1953 tree ctor = build_new_invocation ($2, $4);
1954 $$ = make_qualified_primary ($1, ctor,
1955 EXPR_WFL_LINECOL ($1));
1957 | something_dot_new identifier OP_TK argument_list CP_TK class_body
1958 | NEW_TK error SC_TK
1959 {yyerror ("'(' expected"); DRECOVER(new_1);}
1960 | NEW_TK class_type error
1961 {yyerror ("'(' expected"); RECOVER;}
1962 | NEW_TK class_type OP_TK error
1963 {yyerror ("')' or term expected"); RECOVER;}
1964 | NEW_TK class_type OP_TK argument_list error
1965 {yyerror ("')' expected"); RECOVER;}
1966 | something_dot_new error
1967 {YYERROR_NOW; yyerror ("Identifier expected"); RECOVER;}
1968 | something_dot_new identifier error
1969 {yyerror ("'(' expected"); RECOVER;}
1972 /* Created after JDK1.1 rules originally added to
1973 class_instance_creation_expression, but modified to use
1974 'class_type' instead of 'TypeName' (type_name) which is mentionned
1975 in the documentation but doesn't exist. */
1977 anonymous_class_creation:
1978 NEW_TK class_type OP_TK argument_list CP_TK
1979 { create_anonymous_class ($1.location, $2); }
1982 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
1983 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
1985 end_class_declaration (1);
1987 /* Now we can craft the new expression */
1988 $$ = build_new_invocation (id, $4);
1990 /* Note that we can't possibly be here if
1991 `class_type' is an interface (in which case the
1992 anonymous class extends Object and implements
1993 `class_type', hence its constructor can't have
1996 /* Otherwise, the innerclass must feature a
1997 constructor matching `argument_list'. Anonymous
1998 classes are a bit special: it's impossible to
1999 define constructor for them, hence constructors
2000 must be generated following the hints provided by
2001 the `new' expression. Whether a super constructor
2002 of that nature exists or not is to be verified
2003 later on in verify_constructor_super.
2005 It's during the expansion of a `new' statement
2006 refering to an anonymous class that a ctor will
2007 be generated for the anonymous class, with the
2011 | NEW_TK class_type OP_TK CP_TK
2012 { create_anonymous_class ($1.location, $2); }
2015 tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2016 EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2018 end_class_declaration (1);
2020 /* Now we can craft the new expression. The
2021 statement doesn't need to be remember so that a
2022 constructor can be generated, since its signature
2023 is already known. */
2024 $$ = build_new_invocation (id, NULL_TREE);
2028 something_dot_new: /* Added, not part of the specs. */
2031 | primary DOT_TK NEW_TK
2038 $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2039 ctxp->formal_parameter_number = 1;
2041 | argument_list C_TK expression
2043 ctxp->formal_parameter_number += 1;
2044 $$ = tree_cons (NULL_TREE, $3, $1);
2046 | argument_list C_TK error
2047 {yyerror ("Missing term"); RECOVER;}
2050 array_creation_expression:
2051 NEW_TK primitive_type dim_exprs
2052 { $$ = build_newarray_node ($2, $3, 0); }
2053 | NEW_TK class_or_interface_type dim_exprs
2054 { $$ = build_newarray_node ($2, $3, 0); }
2055 | NEW_TK primitive_type dim_exprs dims
2056 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
2057 | NEW_TK class_or_interface_type dim_exprs dims
2058 { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
2059 /* Added, JDK1.1 anonymous array. Initial documentation rule
2061 | NEW_TK class_or_interface_type dims array_initializer
2064 while (CURRENT_OSB (ctxp)--)
2065 obstack_1grow (&temporary_obstack, '[');
2066 sig = obstack_finish (&temporary_obstack);
2067 $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2068 $2, get_identifier (sig), $4);
2070 | NEW_TK primitive_type dims array_initializer
2073 while (CURRENT_OSB (ctxp)--)
2074 type = build_java_array_type (type, -1);
2075 $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2076 build_pointer_type (type), NULL_TREE, $4);
2078 | NEW_TK error CSB_TK
2079 {yyerror ("'[' expected"); DRECOVER ("]");}
2080 | NEW_TK error OSB_TK
2081 {yyerror ("']' expected"); RECOVER;}
2086 { $$ = build_tree_list (NULL_TREE, $1); }
2087 | dim_exprs dim_expr
2088 { $$ = tree_cons (NULL_TREE, $2, $$); }
2092 OSB_TK expression CSB_TK
2094 if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2096 $2 = build_wfl_node ($2);
2097 TREE_TYPE ($2) = NULL_TREE;
2099 EXPR_WFL_LINECOL ($2) = $1.location;
2102 | OSB_TK expression error
2103 {yyerror ("']' expected"); RECOVER;}
2106 yyerror ("Missing term");
2107 yyerror ("']' expected");
2116 /* If not initialized, allocate memory for the osb
2118 if (!ctxp->osb_limit)
2120 allocate = ctxp->osb_limit = 32;
2121 ctxp->osb_depth = -1;
2123 /* If capacity overflown, reallocate a bigger chunk */
2124 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2125 allocate = ctxp->osb_limit << 1;
2129 allocate *= sizeof (int);
2130 if (ctxp->osb_number)
2131 ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
2134 ctxp->osb_number = (int *)xmalloc (allocate);
2137 CURRENT_OSB (ctxp) = 1;
2139 | dims OSB_TK CSB_TK
2140 { CURRENT_OSB (ctxp)++; }
2142 { yyerror ("']' expected"); RECOVER;}
2146 primary DOT_TK identifier
2147 { $$ = make_qualified_primary ($1, $3, $2.location); }
2148 /* FIXME - REWRITE TO:
2149 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2150 | SUPER_TK DOT_TK identifier
2153 build_wfl_node (super_identifier_node);
2154 EXPR_WFL_LINECOL (super_wfl) = $1.location;
2155 $$ = make_qualified_name (super_wfl, $3, $2.location);
2158 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2163 { $$ = build_method_invocation ($1, NULL_TREE); }
2164 | name OP_TK argument_list CP_TK
2165 { $$ = build_method_invocation ($1, $3); }
2166 | primary DOT_TK identifier OP_TK CP_TK
2168 if (TREE_CODE ($1) == THIS_EXPR)
2169 $$ = build_this_super_qualified_invocation
2170 (1, $3, NULL_TREE, 0, $2.location);
2173 tree invok = build_method_invocation ($3, NULL_TREE);
2174 $$ = make_qualified_primary ($1, invok, $2.location);
2177 | primary DOT_TK identifier OP_TK argument_list CP_TK
2179 if (TREE_CODE ($1) == THIS_EXPR)
2180 $$ = build_this_super_qualified_invocation
2181 (1, $3, $5, 0, $2.location);
2184 tree invok = build_method_invocation ($3, $5);
2185 $$ = make_qualified_primary ($1, invok, $2.location);
2188 | SUPER_TK DOT_TK identifier OP_TK CP_TK
2190 $$ = build_this_super_qualified_invocation
2191 (0, $3, NULL_TREE, $1.location, $2.location);
2193 | SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2195 $$ = build_this_super_qualified_invocation
2196 (0, $3, $5, $1.location, $2.location);
2198 /* Screws up thing. I let it here until I'm convinced it can
2200 | primary DOT_TK error
2201 {yyerror ("'(' expected"); DRECOVER(bad);} */
2202 | SUPER_TK DOT_TK error CP_TK
2203 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2204 | SUPER_TK DOT_TK error DOT_TK
2205 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2209 name OSB_TK expression CSB_TK
2210 { $$ = build_array_ref ($2.location, $1, $3); }
2211 | primary_no_new_array OSB_TK expression CSB_TK
2212 { $$ = build_array_ref ($2.location, $1, $3); }
2215 yyerror ("Missing term and ']' expected");
2216 DRECOVER(array_access);
2218 | name OSB_TK expression error
2220 yyerror ("']' expected");
2221 DRECOVER(array_access);
2223 | primary_no_new_array OSB_TK error
2225 yyerror ("Missing term and ']' expected");
2226 DRECOVER(array_access);
2228 | primary_no_new_array OSB_TK expression error
2230 yyerror ("']' expected");
2231 DRECOVER(array_access);
2238 | post_increment_expression
2239 | post_decrement_expression
2242 post_increment_expression:
2243 postfix_expression INCR_TK
2244 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2247 post_decrement_expression:
2248 postfix_expression DECR_TK
2249 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2253 pre_increment_expression
2254 | pre_decrement_expression
2255 | PLUS_TK unary_expression
2256 {$$ = build_unaryop ($1.token, $1.location, $2); }
2257 | MINUS_TK unary_expression
2258 {$$ = build_unaryop ($1.token, $1.location, $2); }
2259 | unary_expression_not_plus_minus
2261 {yyerror ("Missing term"); RECOVER}
2263 {yyerror ("Missing term"); RECOVER}
2266 pre_increment_expression:
2267 INCR_TK unary_expression
2268 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2270 {yyerror ("Missing term"); RECOVER}
2273 pre_decrement_expression:
2274 DECR_TK unary_expression
2275 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2277 {yyerror ("Missing term"); RECOVER}
2280 unary_expression_not_plus_minus:
2282 | NOT_TK unary_expression
2283 {$$ = build_unaryop ($1.token, $1.location, $2); }
2284 | NEG_TK unary_expression
2285 {$$ = build_unaryop ($1.token, $1.location, $2); }
2288 {yyerror ("Missing term"); RECOVER}
2290 {yyerror ("Missing term"); RECOVER}
2293 cast_expression: /* Error handling here is potentially weak */
2294 OP_TK primitive_type dims CP_TK unary_expression
2297 while (CURRENT_OSB (ctxp)--)
2298 type = build_java_array_type (type, -1);
2300 $$ = build_cast ($1.location, type, $5);
2302 | OP_TK primitive_type CP_TK unary_expression
2303 { $$ = build_cast ($1.location, $2, $4); }
2304 | OP_TK expression CP_TK unary_expression_not_plus_minus
2305 { $$ = build_cast ($1.location, $2, $4); }
2306 | OP_TK name dims CP_TK unary_expression_not_plus_minus
2309 while (CURRENT_OSB (ctxp)--)
2310 obstack_1grow (&temporary_obstack, '[');
2312 obstack_grow0 (&temporary_obstack,
2313 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2314 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2315 ptr = obstack_finish (&temporary_obstack);
2316 EXPR_WFL_NODE ($2) = get_identifier (ptr);
2317 $$ = build_cast ($1.location, $2, $5);
2319 | OP_TK primitive_type OSB_TK error
2320 {yyerror ("']' expected, invalid type expression");}
2323 if (ctxp->prevent_ese != lineno)
2324 yyerror ("Invalid type expression"); RECOVER;
2327 | OP_TK primitive_type dims CP_TK error
2328 {yyerror ("Missing term"); RECOVER;}
2329 | OP_TK primitive_type CP_TK error
2330 {yyerror ("Missing term"); RECOVER;}
2331 | OP_TK name dims CP_TK error
2332 {yyerror ("Missing term"); RECOVER;}
2335 multiplicative_expression:
2337 | multiplicative_expression MULT_TK unary_expression
2339 $$ = build_binop (BINOP_LOOKUP ($2.token),
2340 $2.location, $1, $3);
2342 | multiplicative_expression DIV_TK unary_expression
2344 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2347 | multiplicative_expression REM_TK unary_expression
2349 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2352 | multiplicative_expression MULT_TK error
2353 {yyerror ("Missing term"); RECOVER;}
2354 | multiplicative_expression DIV_TK error
2355 {yyerror ("Missing term"); RECOVER;}
2356 | multiplicative_expression REM_TK error
2357 {yyerror ("Missing term"); RECOVER;}
2360 additive_expression:
2361 multiplicative_expression
2362 | additive_expression PLUS_TK multiplicative_expression
2364 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2367 | additive_expression MINUS_TK multiplicative_expression
2369 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2372 | additive_expression PLUS_TK error
2373 {yyerror ("Missing term"); RECOVER;}
2374 | additive_expression MINUS_TK error
2375 {yyerror ("Missing term"); RECOVER;}
2380 | shift_expression LS_TK additive_expression
2382 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2385 | shift_expression SRS_TK additive_expression
2387 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2390 | shift_expression ZRS_TK additive_expression
2392 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2395 | shift_expression LS_TK error
2396 {yyerror ("Missing term"); RECOVER;}
2397 | shift_expression SRS_TK error
2398 {yyerror ("Missing term"); RECOVER;}
2399 | shift_expression ZRS_TK error
2400 {yyerror ("Missing term"); RECOVER;}
2403 relational_expression:
2405 | relational_expression LT_TK shift_expression
2407 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2410 | relational_expression GT_TK shift_expression
2412 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2415 | relational_expression LTE_TK shift_expression
2417 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2420 | relational_expression GTE_TK shift_expression
2422 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2425 | relational_expression INSTANCEOF_TK reference_type
2426 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2427 | relational_expression LT_TK error
2428 {yyerror ("Missing term"); RECOVER;}
2429 | relational_expression GT_TK error
2430 {yyerror ("Missing term"); RECOVER;}
2431 | relational_expression LTE_TK error
2432 {yyerror ("Missing term"); RECOVER;}
2433 | relational_expression GTE_TK error
2434 {yyerror ("Missing term"); RECOVER;}
2435 | relational_expression INSTANCEOF_TK error
2436 {yyerror ("Invalid reference type"); RECOVER;}
2439 equality_expression:
2440 relational_expression
2441 | equality_expression EQ_TK relational_expression
2443 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2446 | equality_expression NEQ_TK relational_expression
2448 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2451 | equality_expression EQ_TK error
2452 {yyerror ("Missing term"); RECOVER;}
2453 | equality_expression NEQ_TK error
2454 {yyerror ("Missing term"); RECOVER;}
2459 | and_expression AND_TK equality_expression
2461 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2464 | and_expression AND_TK error
2465 {yyerror ("Missing term"); RECOVER;}
2468 exclusive_or_expression:
2470 | exclusive_or_expression XOR_TK and_expression
2472 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2475 | exclusive_or_expression XOR_TK error
2476 {yyerror ("Missing term"); RECOVER;}
2479 inclusive_or_expression:
2480 exclusive_or_expression
2481 | inclusive_or_expression OR_TK exclusive_or_expression
2483 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2486 | inclusive_or_expression OR_TK error
2487 {yyerror ("Missing term"); RECOVER;}
2490 conditional_and_expression:
2491 inclusive_or_expression
2492 | conditional_and_expression BOOL_AND_TK inclusive_or_expression
2494 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2497 | conditional_and_expression BOOL_AND_TK error
2498 {yyerror ("Missing term"); RECOVER;}
2501 conditional_or_expression:
2502 conditional_and_expression
2503 | conditional_or_expression BOOL_OR_TK conditional_and_expression
2505 $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2508 | conditional_or_expression BOOL_OR_TK error
2509 {yyerror ("Missing term"); RECOVER;}
2512 conditional_expression: /* Error handling here is weak */
2513 conditional_or_expression
2514 | conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2516 $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2517 EXPR_WFL_LINECOL ($$) = $2.location;
2519 | conditional_or_expression REL_QM_TK REL_CL_TK error
2522 yyerror ("Missing term");
2525 | conditional_or_expression REL_QM_TK error
2526 {yyerror ("Missing term"); DRECOVER (2);}
2527 | conditional_or_expression REL_QM_TK expression REL_CL_TK error
2528 {yyerror ("Missing term"); DRECOVER (3);}
2531 assignment_expression:
2532 conditional_expression
2537 left_hand_side assignment_operator assignment_expression
2538 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2539 | left_hand_side assignment_operator error
2541 if (ctxp->prevent_ese != lineno)
2542 yyerror ("Missing term");
2553 assignment_operator:
2559 assignment_expression
2562 constant_expression:
2569 /* This section of the code deal with save/restoring parser contexts.
2570 Add mode documentation here. FIXME */
2572 /* Helper function. Create a new parser context. With
2573 COPY_FROM_PREVIOUS set to a non zero value, content of the previous
2574 context is copied, otherwise, the new context is zeroed. The newly
2575 created context becomes the current one. */
2578 create_new_parser_context (copy_from_previous)
2579 int copy_from_previous;
2581 struct parser_ctxt *new;
2583 new = (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2584 if (copy_from_previous)
2586 memcpy ((PTR)new, (PTR)ctxp, sizeof (struct parser_ctxt));
2587 new->saved_data_ctx = 1;
2590 bzero ((PTR) new, sizeof (struct parser_ctxt));
2596 /* Create a new parser context and make it the current one. */
2599 java_push_parser_context ()
2601 create_new_parser_context (0);
2604 ctxp->incomplete_class = ctxp->next->incomplete_class;
2605 ctxp->gclass_list = ctxp->next->gclass_list;
2610 java_pop_parser_context (generate)
2614 struct parser_ctxt *toFree, *next;
2623 next->incomplete_class = ctxp->incomplete_class;
2624 next->gclass_list = ctxp->gclass_list;
2625 lineno = ctxp->lineno;
2626 finput = ctxp->finput;
2627 current_class = ctxp->current_class;
2630 /* Set the single import class file flag to 0 for the current list
2631 of imported things */
2632 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2633 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 0;
2635 /* And restore those of the previous context */
2636 if ((ctxp = next)) /* Assignment is really meant here */
2637 for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2638 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
2640 /* If we pushed a context to parse a class intended to be generated,
2641 we keep it so we can remember the class. What we could actually
2642 do is to just update a list of class names. */
2645 toFree->next = ctxp_for_generation;
2646 ctxp_for_generation = toFree;
2652 /* Create a parser context for the use of saving some global
2656 java_parser_context_save_global ()
2660 java_push_parser_context ();
2661 ctxp->saved_data_ctx = 1;
2664 /* If this context already stores data, create a new one suitable
2665 for data storage. */
2666 else if (ctxp->saved_data)
2667 create_new_parser_context (1);
2669 ctxp->finput = finput;
2670 ctxp->lineno = lineno;
2671 ctxp->current_class = current_class;
2672 ctxp->filename = input_filename;
2673 ctxp->current_function_decl = current_function_decl;
2674 ctxp->saved_data = 1;
2677 /* Restore some global variables from the previous context. Make the
2678 previous context the current one. */
2681 java_parser_context_restore_global ()
2683 finput = ctxp->finput;
2684 lineno = ctxp->lineno;
2685 current_class = ctxp->current_class;
2686 input_filename = ctxp->filename;
2687 current_function_decl = ctxp->current_function_decl;
2688 ctxp->saved_data = 0;
2689 if (ctxp->saved_data_ctx)
2690 java_pop_parser_context (0);
2693 /* Suspend vital data for the current class/function being parsed so
2694 that an other class can be parsed. Used to let local/anonymous
2695 classes be parsed. */
2698 java_parser_context_suspend ()
2700 /* This makes debugging through java_debug_context easier */
2701 static const char *name = "<inner buffer context>";
2703 /* Duplicate the previous context, use it to save the globals we're
2705 create_new_parser_context (1);
2706 ctxp->current_function_decl = current_function_decl;
2707 ctxp->current_class = current_class;
2709 /* Then create a new context which inherits all data from the
2710 previous one. This will be the new current context */
2711 create_new_parser_context (1);
2713 /* Help debugging */
2714 ctxp->next->filename = name;
2717 /* Resume vital data for the current class/function being parsed so
2718 that an other class can be parsed. Used to let local/anonymous
2719 classes be parsed. The trick is the data storing file position
2720 informations must be restored to their current value, so parsing
2721 can resume as if no context was ever saved. */
2724 java_parser_context_resume ()
2726 struct parser_ctxt *old = ctxp; /* This one is to be discarded */
2727 struct parser_ctxt *saver = old->next; /* This one contain saved info */
2728 struct parser_ctxt *restored = saver->next; /* This one is the old current */
2730 /* We need to inherit the list of classes to complete/generate */
2731 restored->incomplete_class = old->incomplete_class;
2732 restored->gclass_list = old->gclass_list;
2733 restored->classd_list = old->classd_list;
2734 restored->class_list = old->class_list;
2736 /* Restore the current class and function from the saver */
2737 current_class = saver->current_class;
2738 current_function_decl = saver->current_function_decl;
2740 /* Retrive the restored context */
2743 /* Re-installed the data for the parsing to carry on */
2744 bcopy (&old->marker_begining, &ctxp->marker_begining,
2745 (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2747 /* Buffer context can now be discarded */
2752 /* Add a new anchor node to which all statement(s) initializing static
2753 and non static initialized upon declaration field(s) will be
2757 java_parser_context_push_initialized_field ()
2761 node = build_tree_list (NULL_TREE, NULL_TREE);
2762 TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2763 CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2765 node = build_tree_list (NULL_TREE, NULL_TREE);
2766 TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2767 CPC_INITIALIZER_LIST (ctxp) = node;
2769 node = build_tree_list (NULL_TREE, NULL_TREE);
2770 TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2771 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2774 /* Pop the lists of initialized field. If this lists aren't empty,
2775 remember them so we can use it to create and populate the $finit$
2776 or <clinit> functions. */
2779 java_parser_context_pop_initialized_field ()
2782 tree class_type = TREE_TYPE (GET_CPC ());
2784 if (CPC_INITIALIZER_LIST (ctxp))
2786 stmts = CPC_INITIALIZER_STMT (ctxp);
2787 CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2788 if (stmts && !java_error_count)
2789 TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2792 if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2794 stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2795 CPC_STATIC_INITIALIZER_LIST (ctxp) =
2796 TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2797 /* Keep initialization in order to enforce 8.5 */
2798 if (stmts && !java_error_count)
2799 TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2802 /* JDK 1.1 instance initializers */
2803 if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2805 stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2806 CPC_INSTANCE_INITIALIZER_LIST (ctxp) =
2807 TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2808 if (stmts && !java_error_count)
2809 TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2814 reorder_static_initialized (list)
2817 /* We have to keep things in order. The alias initializer have to
2818 come first, then the initialized regular field, in reverse to
2819 keep them in lexical order. */
2820 tree marker, previous = NULL_TREE;
2821 for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2822 if (TREE_CODE (marker) == TREE_LIST
2823 && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2826 /* No static initialized, the list is fine as is */
2828 list = TREE_CHAIN (marker);
2830 /* No marker? reverse the whole list */
2832 list = nreverse (list);
2834 /* Otherwise, reverse what's after the marker and the new reordered
2835 sublist will replace the marker. */
2838 TREE_CHAIN (previous) = NULL_TREE;
2839 list = nreverse (list);
2840 list = chainon (TREE_CHAIN (marker), list);
2845 /* Helper functions to dump the parser context stack. */
2847 #define TAB_CONTEXT(C) \
2848 {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2851 java_debug_context_do (tab)
2854 struct parser_ctxt *copy = ctxp;
2858 fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2860 fprintf (stderr, "filename: %s\n", copy->filename);
2862 fprintf (stderr, "lineno: %d\n", copy->lineno);
2864 fprintf (stderr, "package: %s\n",
2866 IDENTIFIER_POINTER (copy->package) : "<none>"));
2868 fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2870 fprintf (stderr, "saved data: %d\n", copy->saved_data);
2876 /* Dump the stacked up parser contexts. Intended to be called from a
2880 java_debug_context ()
2882 java_debug_context_do (0);
2887 /* Flag for the error report routine to issue the error the first time
2888 it's called (overriding the default behavior which is to drop the
2889 first invocation and honor the second one, taking advantage of a
2891 static int force_error = 0;
2893 /* Reporting an constructor invocation error. */
2895 parse_ctor_invocation_error ()
2897 if (DECL_CONSTRUCTOR_P (current_function_decl))
2898 yyerror ("Constructor invocation must be first thing in a constructor");
2900 yyerror ("Only constructors can invoke constructors");
2903 /* Reporting JDK1.1 features not implemented. */
2906 parse_jdk1_1_error (msg)
2909 sorry (": `%s' JDK1.1(TM) feature", msg);
2911 return empty_stmt_node;
2914 static int do_warning = 0;
2921 static int prev_lineno;
2922 static const char *prev_msg;
2925 char *remainder, *code_from_source;
2926 extern struct obstack temporary_obstack;
2928 if (!force_error && prev_lineno == lineno)
2931 /* Save current error location but report latter, when the context is
2933 if (ctxp->java_error_flag == 0)
2935 ctxp->java_error_flag = 1;
2937 /* Do something to use the previous line if we're reaching the
2938 end of the file... */
2939 #ifdef VERBOSE_SKELETON
2940 printf ("* Error detected (%s)\n", (msg ? msg : "(null)"));
2945 /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2946 if (!force_error && msg == prev_msg && prev_lineno == elc.line)
2949 ctxp->java_error_flag = 0;
2951 java_warning_count++;
2955 if (elc.col == 0 && msg && msg[1] == ';')
2957 elc.col = ctxp->p_line->char_col-1;
2958 elc.line = ctxp->p_line->lineno;
2961 save_lineno = lineno;
2962 prev_lineno = lineno = elc.line;
2965 code_from_source = java_get_line_col (ctxp->filename, elc.line, elc.col);
2966 obstack_grow0 (&temporary_obstack,
2967 code_from_source, strlen (code_from_source));
2968 remainder = obstack_finish (&temporary_obstack);
2970 warning ("%s.\n%s", msg, remainder);
2972 error ("%s.\n%s", msg, remainder);
2974 /* This allow us to cheaply avoid an extra 'Invalid expression
2975 statement' error report when errors have been already reported on
2976 the same line. This occurs when we report an error but don't have
2977 a synchronization point other than ';', which
2978 expression_statement is the only one to take care of. */
2979 ctxp->prevent_ese = lineno = save_lineno;
2983 issue_warning_error_from_context (cl, msg, ap)
2988 const char *saved, *saved_input_filename;
2990 vsprintf (buffer, msg, ap);
2993 ctxp->elc.line = EXPR_WFL_LINENO (cl);
2994 ctxp->elc.col = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 :
2995 (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
2997 /* We have a CL, that's a good reason for using it if it contains data */
2998 saved = ctxp->filename;
2999 if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3000 ctxp->filename = EXPR_WFL_FILENAME (cl);
3001 saved_input_filename = input_filename;
3002 input_filename = ctxp->filename;
3004 java_error (buffer);
3005 ctxp->filename = saved;
3006 input_filename = saved_input_filename;
3010 /* Issue an error message at a current source line CL */
3013 parse_error_context VPARAMS ((tree cl, const char *msg, ...))
3015 #ifndef ANSI_PROTOTYPES
3022 #ifndef ANSI_PROTOTYPES
3023 cl = va_arg (ap, tree);
3024 msg = va_arg (ap, const char *);
3026 issue_warning_error_from_context (cl, msg, ap);
3030 /* Issue a warning at a current source line CL */
3033 parse_warning_context VPARAMS ((tree cl, const char *msg, ...))
3035 #ifndef ANSI_PROTOTYPES
3042 #ifndef ANSI_PROTOTYPES
3043 cl = va_arg (ap, tree);
3044 msg = va_arg (ap, const char *);
3047 force_error = do_warning = 1;
3048 issue_warning_error_from_context (cl, msg, ap);
3049 do_warning = force_error = 0;
3054 find_expr_with_wfl (node)
3062 switch (TREE_CODE (node))
3065 node = BLOCK_EXPR_BODY (node);
3069 to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3072 node = TREE_OPERAND (node, 1);
3076 node = TREE_OPERAND (node, 0);
3079 case LABELED_BLOCK_EXPR:
3080 node = TREE_OPERAND (node, 1);
3084 code = TREE_CODE_CLASS (TREE_CODE (node));
3085 if (((code == '1') || (code == '2') || (code == 'e'))
3086 && EXPR_WFL_LINECOL (node))
3094 /* Issue a missing return statement error. Uses METHOD to figure the
3095 last line of the method the error occurs in. */
3098 missing_return_error (method)
3101 EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
3102 parse_error_context (wfl_operator, "Missing return statement");
3105 /* Issue an unreachable statement error. From NODE, find the next
3106 statement to report appropriately. */
3108 unreachable_stmt_error (node)
3111 /* Browse node to find the next expression node that has a WFL. Use
3112 the location to report the error */
3113 if (TREE_CODE (node) == COMPOUND_EXPR)
3114 node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3116 node = find_expr_with_wfl (node);
3120 EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3121 parse_error_context (wfl_operator, "Unreachable statement");
3124 fatal ("Can't get valid statement - unreachable_stmt_error");
3128 java_report_errors ()
3130 if (java_error_count)
3131 fprintf (stderr, "%d error%s",
3132 java_error_count, (java_error_count == 1 ? "" : "s"));
3133 if (java_warning_count)
3134 fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3135 java_warning_count, (java_warning_count == 1 ? "" : "s"));
3136 if (java_error_count || java_warning_count)
3137 putc ('\n', stderr);
3138 return java_error_count;
3142 java_accstring_lookup (flags)
3145 static char buffer [80];
3146 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3148 /* Access modifier looked-up first for easier report on forbidden
3150 if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3151 if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3152 if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3153 if (flags & ACC_STATIC) COPY_RETURN ("static");
3154 if (flags & ACC_FINAL) COPY_RETURN ("final");
3155 if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3156 if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3157 if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3158 if (flags & ACC_NATIVE) COPY_RETURN ("native");
3159 if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3160 if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3167 /* Issuing error messages upon redefinition of classes, interfaces or
3171 classitf_redefinition_error (context, id, decl, cl)
3172 const char *context;
3175 parse_error_context (cl, "%s `%s' already defined in %s:%d",
3176 context, IDENTIFIER_POINTER (id),
3177 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3178 /* Here we should point out where its redefined. It's a unicode. FIXME */
3182 variable_redefinition_error (context, name, type, line)
3183 tree context, name, type;
3186 const char *type_name;
3188 /* Figure a proper name for type. We might haven't resolved it */
3189 if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3190 type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3192 type_name = lang_printable_name (type, 0);
3194 parse_error_context (context,
3195 "Variable `%s' is already defined in this method and was declared `%s %s' at line %d",
3196 IDENTIFIER_POINTER (name),
3197 type_name, IDENTIFIER_POINTER (name), line);
3201 build_array_from_name (type, type_wfl, name, ret_name)
3202 tree type, type_wfl, name, *ret_name;
3207 /* Eventually get more dims */
3208 string = IDENTIFIER_POINTER (name);
3209 while (string [more_dims] == '[')
3212 /* If we have, then craft a new type for this variable */
3215 name = get_identifier (&string [more_dims]);
3217 /* If we have a pointer, use its type */
3218 if (TREE_CODE (type) == POINTER_TYPE)
3219 type = TREE_TYPE (type);
3221 /* Building the first dimension of a primitive type uses this
3223 if (JPRIMITIVE_TYPE_P (type))
3225 type = build_java_array_type (type, -1);
3226 CLASS_LOADED_P (type) = 1;
3229 /* Otherwise, if we have a WFL for this type, use it (the type
3230 is already an array on an unresolved type, and we just keep
3231 on adding dimensions) */
3235 /* Add all the dimensions */
3237 type = build_unresolved_array_type (type);
3239 /* The type may have been incomplete in the first place */
3241 type = obtain_incomplete_type (type);
3249 /* Build something that the type identifier resolver will identify as
3250 being an array to an unresolved type. TYPE_WFL is a WFL on a
3254 build_unresolved_array_type (type_or_wfl)
3259 /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3260 just create a array type */
3261 if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3263 tree type = build_java_array_type (type_or_wfl, -1);
3264 CLASS_LOADED_P (type) = CLASS_LOADED_P (type_or_wfl);
3268 obstack_1grow (&temporary_obstack, '[');
3269 obstack_grow0 (&temporary_obstack,
3270 IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3271 IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3272 ptr = obstack_finish (&temporary_obstack);
3273 return build_expr_wfl (get_identifier (ptr),
3274 EXPR_WFL_FILENAME (type_or_wfl),
3275 EXPR_WFL_LINENO (type_or_wfl),
3276 EXPR_WFL_COLNO (type_or_wfl));
3280 parser_add_interface (class_decl, interface_decl, wfl)
3281 tree class_decl, interface_decl, wfl;
3283 if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3284 parse_error_context (wfl, "Interface `%s' repeated",
3285 IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3288 /* Bulk of common class/interface checks. Return 1 if an error was
3289 encountered. TAG is 0 for a class, 1 for an interface. */
3292 check_class_interface_creation (is_interface, flags, raw_name, qualified_name, decl, cl)
3293 int is_interface, flags;
3294 tree raw_name, qualified_name, decl, cl;
3297 int sca = 0; /* Static class allowed */
3298 int icaf = 0; /* Inner class allowed flags */
3299 int uaaf = CLASS_MODIFIERS; /* Usually allowed access flags */
3302 fprintf (stderr, " %s%s %s",
3303 (CPC_INNER_P () ? "inner" : ""),
3304 (is_interface ? "interface" : "class"),
3305 IDENTIFIER_POINTER (qualified_name));
3307 /* Scope of an interface/class type name:
3308 - Can't be imported by a single type import
3309 - Can't already exists in the package */
3310 if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3311 && (node = find_name_in_single_imports (raw_name)))
3314 (cl, "%s name `%s' clashes with imported type `%s'",
3315 (is_interface ? "Interface" : "Class"),
3316 IDENTIFIER_POINTER (raw_name), IDENTIFIER_POINTER (node));
3319 if (decl && CLASS_COMPLETE_P (decl))
3321 classitf_redefinition_error ((is_interface ? "Interface" : "Class"),
3322 qualified_name, decl, cl);
3326 if (check_inner_class_redefinition (raw_name, cl))
3329 /* If public, file name should match class/interface name, except
3330 when dealing with an inner class */
3331 if (!CPC_INNER_P () && (flags & ACC_PUBLIC ))
3335 /* Contains OS dependent assumption on path separator. FIXME */
3336 for (f = &input_filename [strlen (input_filename)];
3337 f != input_filename && f[0] != '/' && f[0] != DIR_SEPARATOR;
3340 if (f[0] == '/' || f[0] == DIR_SEPARATOR)
3342 if (strncmp (IDENTIFIER_POINTER (raw_name),
3343 f , IDENTIFIER_LENGTH (raw_name)) ||
3344 f [IDENTIFIER_LENGTH (raw_name)] != '.')
3346 (cl, "Public %s `%s' must be defined in a file called `%s.java'",
3347 (is_interface ? "interface" : "class"),
3348 IDENTIFIER_POINTER (qualified_name),
3349 IDENTIFIER_POINTER (raw_name));
3352 /* Static classes can be declared only in top level classes. Note:
3353 once static, a inner class is a top level class. */
3354 if (flags & ACC_STATIC)
3356 /* Catch the specific error of declaring an class inner class
3357 with no toplevel enclosing class. Prevent check_modifiers from
3358 complaining a second time */
3359 if (CPC_INNER_P () && !TOPLEVEL_CLASS_DECL_P (GET_CPC()))
3361 parse_error_context (cl, "Inner class `%s' can't be static. Static classes can only occur in interfaces and top-level classes",
3362 IDENTIFIER_POINTER (qualified_name));