OSDN Git Service

* parse.y (check_static_final_variable_assignment_flag): Fix spelling.
[pf3gnuchains/gcc-fork.git] / gcc / java / parse.y
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)
5
6 This file is part of GNU CC.
7
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)
11 any later version.
12
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.
17
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.
22
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.  */
26
27 /* This file parses java source code and issues a tree node image
28 suitable for code generation (byte code and targeted CPU assembly
29 language).
30
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"
34
35 The following modifications were brought to the original grammar:
36
37 method_body: added the rule '| block SC_TK'
38 static_initializer: added the rule 'static block SC_TK'. 
39
40 Note: All the extra rules described above should go away when the
41       empty_statement rule will work.
42
43 statement_nsi: 'nsi' should be read no_short_if.
44
45 Some rules have been modified to support JDK1.1 inner classes
46 definitions and other extensions.  */
47
48 %{
49 #include "config.h"
50 #include "system.h"
51 #include <dirent.h>
52 #include "tree.h"
53 #include "rtl.h"
54 #include "obstack.h"
55 #include "toplev.h"
56 #include "flags.h"
57 #include "java-tree.h"
58 #include "jcf.h"
59 #include "lex.h"
60 #include "parse.h"
61 #include "zipfile.h"
62 #include "convert.h"
63 #include "buffer.h"
64 #include "xref.h"
65 #include "function.h"
66 #include "except.h"
67 #include "defaults.h"
68 #include "ggc.h"
69
70 #ifndef DIR_SEPARATOR
71 #define DIR_SEPARATOR '/'
72 #endif
73
74 /* Local function prototypes */
75 static char *java_accstring_lookup PARAMS ((int));
76 static void  classitf_redefinition_error PARAMS ((const char *,tree, tree, tree));
77 static void  variable_redefinition_error PARAMS ((tree, tree, tree, int));
78 static tree  create_class PARAMS ((int, tree, tree, tree));
79 static tree  create_interface PARAMS ((int, tree, tree));
80 static void  end_class_declaration PARAMS ((int));
81 static tree  find_field PARAMS ((tree, tree));
82 static tree lookup_field_wrapper PARAMS ((tree, tree));
83 static int   duplicate_declaration_error_p PARAMS ((tree, tree, tree));
84 static void  register_fields PARAMS ((int, tree, tree));
85 static tree parser_qualified_classname PARAMS ((tree));
86 static int  parser_check_super PARAMS ((tree, tree, tree));
87 static int  parser_check_super_interface PARAMS ((tree, tree, tree));
88 static void check_modifiers_consistency PARAMS ((int));
89 static tree lookup_cl PARAMS ((tree));
90 static tree lookup_java_method2 PARAMS ((tree, tree, int));
91 static tree method_header PARAMS ((int, tree, tree, tree));
92 static void fix_method_argument_names PARAMS ((tree ,tree));
93 static tree method_declarator PARAMS ((tree, tree));
94 static void parse_warning_context PARAMS ((tree cl, const char *msg, ...))
95   ATTRIBUTE_PRINTF_2;
96 static void issue_warning_error_from_context PARAMS ((tree, const char *msg, va_list))
97   ATTRIBUTE_PRINTF (2, 0);
98 static void parse_ctor_invocation_error PARAMS ((void));
99 static tree parse_jdk1_1_error PARAMS ((const char *));
100 static void complete_class_report_errors PARAMS ((jdep *));
101 static int process_imports PARAMS ((void));
102 static void read_import_dir PARAMS ((tree));
103 static int find_in_imports_on_demand PARAMS ((tree));
104 static void find_in_imports PARAMS ((tree));
105 static void check_static_final_variable_assignment_flag PARAMS ((tree));
106 static void reset_static_final_variable_assignment_flag PARAMS ((tree));
107 static void check_final_variable_local_assignment_flag PARAMS ((tree, tree));
108 static void reset_final_variable_local_assignment_flag PARAMS ((tree));
109 static int  check_final_variable_indirect_assignment PARAMS ((tree));
110 static void check_final_variable_global_assignment_flag PARAMS ((tree));
111 static void check_inner_class_access PARAMS ((tree, tree, tree));
112 static int check_pkg_class_access PARAMS ((tree, tree));
113 static void register_package PARAMS ((tree));
114 static tree resolve_package PARAMS ((tree, tree *));
115 static tree lookup_package_type PARAMS ((const char *, int));
116 static tree lookup_package_type_and_set_next PARAMS ((const char *, int, tree *));
117 static tree resolve_class PARAMS ((tree, tree, tree, tree));
118 static void declare_local_variables PARAMS ((int, tree, tree));
119 static void source_start_java_method PARAMS ((tree));
120 static void source_end_java_method PARAMS ((void));
121 static void expand_start_java_method PARAMS ((tree));
122 static tree find_name_in_single_imports PARAMS ((tree));
123 static void check_abstract_method_header PARAMS ((tree));
124 static tree lookup_java_interface_method2 PARAMS ((tree, tree));
125 static tree resolve_expression_name PARAMS ((tree, tree *));
126 static tree maybe_create_class_interface_decl PARAMS ((tree, tree, tree, tree));
127 static int check_class_interface_creation PARAMS ((int, int, tree, 
128                                                   tree, tree, tree));
129 static tree patch_method_invocation PARAMS ((tree, tree, tree, 
130                                             int *, tree *));
131 static int breakdown_qualified PARAMS ((tree *, tree *, tree));
132 static tree resolve_and_layout PARAMS ((tree, tree));
133 static tree qualify_and_find PARAMS ((tree, tree, tree));
134 static tree resolve_no_layout PARAMS ((tree, tree));
135 static int invocation_mode PARAMS ((tree, int));
136 static tree find_applicable_accessible_methods_list PARAMS ((int, tree, 
137                                                             tree, tree));
138 static void search_applicable_methods_list PARAMS ((int, tree, tree, tree, 
139                                                    tree *, tree *));
140 static tree find_most_specific_methods_list PARAMS ((tree));
141 static int argument_types_convertible PARAMS ((tree, tree));
142 static tree patch_invoke PARAMS ((tree, tree, tree));
143 static int maybe_use_access_method PARAMS ((int, tree *, tree *));
144 static tree lookup_method_invoke PARAMS ((int, tree, tree, tree, tree));
145 static tree register_incomplete_type PARAMS ((int, tree, tree, tree));
146 static tree obtain_incomplete_type PARAMS ((tree));
147 static tree java_complete_lhs PARAMS ((tree));
148 static tree java_complete_tree PARAMS ((tree));
149 static tree maybe_generate_pre_expand_clinit PARAMS ((tree));
150 static int analyze_clinit_body PARAMS ((tree));
151 static int maybe_yank_clinit PARAMS ((tree));
152 static void java_complete_expand_method PARAMS ((tree));
153 static int  unresolved_type_p PARAMS ((tree, tree *));
154 static void create_jdep_list PARAMS ((struct parser_ctxt *));
155 static tree build_expr_block PARAMS ((tree, tree));
156 static tree enter_block PARAMS ((void));
157 static tree enter_a_block PARAMS ((tree));
158 static tree exit_block PARAMS ((void));
159 static tree lookup_name_in_blocks PARAMS ((tree));
160 static void maybe_absorb_scoping_blocks PARAMS ((void));
161 static tree build_method_invocation PARAMS ((tree, tree));
162 static tree build_new_invocation PARAMS ((tree, tree));
163 static tree build_assignment PARAMS ((int, int, tree, tree));
164 static tree build_binop PARAMS ((enum tree_code, int, tree, tree));
165 static int check_final_assignment PARAMS ((tree ,tree));
166 static tree patch_assignment PARAMS ((tree, tree, tree ));
167 static tree patch_binop PARAMS ((tree, tree, tree));
168 static tree build_unaryop PARAMS ((int, int, tree));
169 static tree build_incdec PARAMS ((int, int, tree, int));
170 static tree patch_unaryop PARAMS ((tree, tree));
171 static tree build_cast PARAMS ((int, tree, tree));
172 static tree build_null_of_type PARAMS ((tree));
173 static tree patch_cast PARAMS ((tree, tree));
174 static int valid_ref_assignconv_cast_p PARAMS ((tree, tree, int));
175 static int valid_builtin_assignconv_identity_widening_p PARAMS ((tree, tree));
176 static int valid_cast_to_p PARAMS ((tree, tree));
177 static int valid_method_invocation_conversion_p PARAMS ((tree, tree));
178 static tree try_builtin_assignconv PARAMS ((tree, tree, tree));
179 static tree try_reference_assignconv PARAMS ((tree, tree));
180 static tree build_unresolved_array_type PARAMS ((tree));
181 static tree build_array_from_name PARAMS ((tree, tree, tree, tree *));
182 static tree build_array_ref PARAMS ((int, tree, tree));
183 static tree patch_array_ref PARAMS ((tree));
184 static tree make_qualified_name PARAMS ((tree, tree, int));
185 static tree merge_qualified_name PARAMS ((tree, tree));
186 static tree make_qualified_primary PARAMS ((tree, tree, int));
187 static int resolve_qualified_expression_name PARAMS ((tree, tree *, 
188                                                      tree *, tree *));
189 static void qualify_ambiguous_name PARAMS ((tree));
190 static tree resolve_field_access PARAMS ((tree, tree *, tree *));
191 static tree build_newarray_node PARAMS ((tree, tree, int));
192 static tree patch_newarray PARAMS ((tree));
193 static tree resolve_type_during_patch PARAMS ((tree));
194 static tree build_this PARAMS ((int));
195 static tree build_wfl_wrap PARAMS ((tree, int));
196 static tree build_return PARAMS ((int, tree));
197 static tree patch_return PARAMS ((tree));
198 static tree maybe_access_field PARAMS ((tree, tree, tree));
199 static int complete_function_arguments PARAMS ((tree));
200 static int check_for_static_method_reference PARAMS ((tree, tree, tree, 
201                                                       tree, tree));
202 static int not_accessible_p PARAMS ((tree, tree, int));
203 static void check_deprecation PARAMS ((tree, tree));
204 static int class_in_current_package PARAMS ((tree));
205 static tree build_if_else_statement PARAMS ((int, tree, tree, tree));
206 static tree patch_if_else_statement PARAMS ((tree));
207 static tree add_stmt_to_compound PARAMS ((tree, tree, tree));
208 static tree add_stmt_to_block PARAMS ((tree, tree, tree));
209 static tree patch_exit_expr PARAMS ((tree));
210 static tree build_labeled_block PARAMS ((int, tree));
211 static tree finish_labeled_statement PARAMS ((tree, tree));
212 static tree build_bc_statement PARAMS ((int, int, tree));
213 static tree patch_bc_statement PARAMS ((tree));
214 static tree patch_loop_statement PARAMS ((tree));
215 static tree build_new_loop PARAMS ((tree));
216 static tree build_loop_body PARAMS ((int, tree, int));
217 static tree finish_loop_body PARAMS ((int, tree, tree, int));
218 static tree build_debugable_stmt PARAMS ((int, tree));
219 static tree finish_for_loop PARAMS ((int, tree, tree, tree));
220 static tree patch_switch_statement PARAMS ((tree));
221 static tree string_constant_concatenation PARAMS ((tree, tree));
222 static tree build_string_concatenation PARAMS ((tree, tree));
223 static tree patch_string_cst PARAMS ((tree));
224 static tree patch_string PARAMS ((tree));
225 static tree build_try_statement PARAMS ((int, tree, tree));
226 static tree build_try_finally_statement PARAMS ((int, tree, tree));
227 static tree patch_try_statement PARAMS ((tree));
228 static tree patch_synchronized_statement PARAMS ((tree, tree));
229 static tree patch_throw_statement PARAMS ((tree, tree));
230 static void check_thrown_exceptions PARAMS ((int, tree));
231 static int check_thrown_exceptions_do PARAMS ((tree));
232 static void purge_unchecked_exceptions PARAMS ((tree));
233 static void check_throws_clauses PARAMS ((tree, tree, tree));
234 static void finish_method_declaration PARAMS ((tree));
235 static tree build_super_invocation PARAMS ((tree));
236 static int verify_constructor_circularity PARAMS ((tree, tree));
237 static char *constructor_circularity_msg PARAMS ((tree, tree));
238 static tree build_this_super_qualified_invocation PARAMS ((int, tree, tree,
239                                                           int, int));
240 static const char *get_printable_method_name PARAMS ((tree));
241 static tree patch_conditional_expr PARAMS ((tree, tree, tree));
242 static tree generate_finit PARAMS ((tree));
243 static void add_instance_initializer PARAMS ((tree));
244 static void fix_constructors PARAMS ((tree));
245 static tree build_alias_initializer_parameter_list PARAMS ((int, tree,
246                                                             tree, int *));
247 static void craft_constructor PARAMS ((tree, tree));
248 static int verify_constructor_super PARAMS ((tree));
249 static tree create_artificial_method PARAMS ((tree, int, tree, tree, tree));
250 static void start_artificial_method_body PARAMS ((tree));
251 static void end_artificial_method_body PARAMS ((tree));
252 static int check_method_redefinition PARAMS ((tree, tree));
253 static int reset_method_name PARAMS ((tree));
254 static int check_method_types_complete PARAMS ((tree));
255 static void java_check_regular_methods PARAMS ((tree));
256 static void java_check_abstract_methods PARAMS ((tree));
257 static tree maybe_build_primttype_type_ref PARAMS ((tree, tree));
258 static void unreachable_stmt_error PARAMS ((tree));
259 static tree find_expr_with_wfl PARAMS ((tree));
260 static void missing_return_error PARAMS ((tree));
261 static tree build_new_array_init PARAMS ((int, tree));
262 static tree patch_new_array_init PARAMS ((tree, tree));
263 static tree maybe_build_array_element_wfl PARAMS ((tree));
264 static int array_constructor_check_entry PARAMS ((tree, tree));
265 static const char *purify_type_name PARAMS ((const char *));
266 static tree fold_constant_for_init PARAMS ((tree, tree));
267 static tree strip_out_static_field_access_decl PARAMS ((tree));
268 static jdeplist *reverse_jdep_list PARAMS ((struct parser_ctxt *));
269 static void static_ref_err PARAMS ((tree, tree, tree));
270 static void parser_add_interface PARAMS ((tree, tree, tree));
271 static void add_superinterfaces PARAMS ((tree, tree));
272 static tree jdep_resolve_class PARAMS ((jdep *));
273 static int note_possible_classname PARAMS ((const char *, int));
274 static void java_complete_expand_classes PARAMS ((void));
275 static void java_complete_expand_class PARAMS ((tree));
276 static void java_complete_expand_methods PARAMS ((tree));
277 static tree cut_identifier_in_qualified PARAMS ((tree));
278 static tree java_stabilize_reference PARAMS ((tree));
279 static tree do_unary_numeric_promotion PARAMS ((tree));
280 static char * operator_string PARAMS ((tree));
281 static tree do_merge_string_cste PARAMS ((tree, const char *, int, int));
282 static tree merge_string_cste PARAMS ((tree, tree, int));
283 static tree java_refold PARAMS ((tree));
284 static int java_decl_equiv PARAMS ((tree, tree));
285 static int binop_compound_p PARAMS ((enum tree_code));
286 static tree search_loop PARAMS ((tree));
287 static int labeled_block_contains_loop_p PARAMS ((tree, tree));
288 static int check_abstract_method_definitions PARAMS ((int, tree, tree));
289 static void java_check_abstract_method_definitions PARAMS ((tree));
290 static void java_debug_context_do PARAMS ((int));
291 static void java_parser_context_push_initialized_field PARAMS ((void));
292 static void java_parser_context_pop_initialized_field PARAMS ((void));
293 static tree reorder_static_initialized PARAMS ((tree));
294 static void java_parser_context_suspend PARAMS ((void));
295 static void java_parser_context_resume PARAMS ((void));
296 static int pop_current_osb PARAMS ((struct parser_ctxt *));
297
298 /* JDK 1.1 work. FIXME */
299
300 static tree maybe_make_nested_class_name PARAMS ((tree));
301 static void make_nested_class_name PARAMS ((tree));
302 static void set_nested_class_simple_name_value PARAMS ((tree, int));
303 static void link_nested_class_to_enclosing PARAMS ((void));
304 static tree find_as_inner_class PARAMS ((tree, tree, tree));
305 static tree find_as_inner_class_do PARAMS ((tree, tree));
306 static int check_inner_class_redefinition PARAMS ((tree, tree));
307
308 static tree build_thisn_assign PARAMS ((void));
309 static tree build_current_thisn PARAMS ((tree));
310 static tree build_access_to_thisn PARAMS ((tree, tree, int));
311 static tree maybe_build_thisn_access_method PARAMS ((tree));
312
313 static tree build_outer_field_access PARAMS ((tree, tree));
314 static tree build_outer_field_access_methods PARAMS ((tree));
315 static tree build_outer_field_access_expr PARAMS ((int, tree, tree, 
316                                                   tree, tree));
317 static tree build_outer_method_access_method PARAMS ((tree));
318 static tree build_new_access_id PARAMS ((void));
319 static tree build_outer_field_access_method PARAMS ((tree, tree, tree,
320                                                     tree, tree));
321
322 static int outer_field_access_p PARAMS ((tree, tree));
323 static int outer_field_expanded_access_p PARAMS ((tree, tree *, 
324                                                  tree *, tree *));
325 static tree outer_field_access_fix PARAMS ((tree, tree, tree));
326 static tree build_incomplete_class_ref PARAMS ((int, tree));
327 static tree patch_incomplete_class_ref PARAMS ((tree));
328 static tree create_anonymous_class PARAMS ((int, tree));
329 static void patch_anonymous_class PARAMS ((tree, tree, tree));
330 static void add_inner_class_fields PARAMS ((tree, tree));
331
332 static tree build_dot_class_method PARAMS ((tree));
333 static tree build_dot_class_method_invocation PARAMS ((tree));
334 static void create_new_parser_context PARAMS ((int));
335 static void mark_parser_ctxt PARAMS ((void *));
336
337 /* Number of error found so far. */
338 int java_error_count; 
339 /* Number of warning found so far. */
340 int java_warning_count;
341 /* Tell when not to fold, when doing xrefs */
342 int do_not_fold;
343 /* Cyclic inheritance report, as it can be set by layout_class */
344 const char *cyclic_inheritance_report;
345  
346 /* Tell when we're within an instance initializer */
347 static int in_instance_initializer;
348
349 /* The current parser context */
350 struct parser_ctxt *ctxp;
351
352 /* List of things that were analyzed for which code will be generated */
353 static struct parser_ctxt *ctxp_for_generation = NULL;
354
355 /* binop_lookup maps token to tree_code. It is used where binary
356    operations are involved and required by the parser. RDIV_EXPR
357    covers both integral/floating point division. The code is changed
358    once the type of both operator is worked out.  */
359
360 static enum tree_code binop_lookup[19] = 
361   { 
362     PLUS_EXPR, MINUS_EXPR, MULT_EXPR, RDIV_EXPR, TRUNC_MOD_EXPR,
363     LSHIFT_EXPR, RSHIFT_EXPR, URSHIFT_EXPR, 
364     BIT_AND_EXPR, BIT_XOR_EXPR, BIT_IOR_EXPR,
365     TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR,
366     EQ_EXPR, NE_EXPR, GT_EXPR, GE_EXPR, LT_EXPR, LE_EXPR,
367    };
368 #define BINOP_LOOKUP(VALUE)                                             \
369   binop_lookup [((VALUE) - PLUS_TK) % ARRAY_SIZE (binop_lookup)]
370
371 /* This is the end index for binary operators that can also be used
372    in compound assignements. */
373 #define BINOP_COMPOUND_CANDIDATES 11
374
375 /* The "$L" identifier we use to create labels.  */
376 static tree label_id = NULL_TREE;
377
378 /* The "StringBuffer" identifier used for the String `+' operator. */
379 static tree wfl_string_buffer = NULL_TREE; 
380
381 /* The "append" identifier used for String `+' operator.  */
382 static tree wfl_append = NULL_TREE;
383
384 /* The "toString" identifier used for String `+' operator. */
385 static tree wfl_to_string = NULL_TREE;
386
387 /* The "java.lang" import qualified name.  */
388 static tree java_lang_id = NULL_TREE;
389
390 /* The generated `inst$' identifier used for generated enclosing
391    instance/field access functions.  */
392 static tree inst_id = NULL_TREE;
393
394 /* The "java.lang.Cloneable" qualified name.  */
395 static tree java_lang_cloneable = NULL_TREE;
396
397 /* The "java.io.Serializable" qualified name.  */
398 static tree java_io_serializable = NULL_TREE; 
399
400 /* Context and flag for static blocks */
401 static tree current_static_block = NULL_TREE;
402
403 /* The generated `write_parm_value$' identifier.  */
404 static tree wpv_id;
405
406 /* The list of all packages we've seen so far */
407 static tree package_list = NULL_TREE;
408  
409 /* Hold THIS for the scope of the current public method decl.  */
410 static tree current_this;
411
412 /* Hold a list of catch clauses list. The first element of this list is
413    the list of the catch clauses of the currently analysed try block. */
414 static tree currently_caught_type_list;
415
416 /* Check modifiers. If one doesn't fit, retrieve it in its declaration
417    line and point it out.  */
418 /* Should point out the one that don't fit. ASCII/unicode, going
419    backward. FIXME */
420
421 #define check_modifiers(__message, __value, __mask) do {        \
422   if ((__value) & ~(__mask))                                    \
423     {                                                           \
424       int i, remainder = (__value) & ~(__mask);                 \
425       for (i = 0; i <= 10; i++)                                 \
426         if ((1 << i) & remainder)                               \
427           parse_error_context (ctxp->modifier_ctx [i], (__message), \
428                                java_accstring_lookup (1 << i)); \
429     }                                                           \
430 } while (0)
431
432 %}
433
434 %union {
435   tree node;
436   int sub_token;
437   struct {
438     int token;
439     int location;
440   } operator;
441   int value;
442 }
443
444 %{
445 #include "lex.c"
446 %}
447
448 %pure_parser
449
450 /* Things defined here have to match the order of what's in the
451    binop_lookup table.  */
452
453 %token   PLUS_TK         MINUS_TK        MULT_TK         DIV_TK    REM_TK
454 %token   LS_TK           SRS_TK          ZRS_TK
455 %token   AND_TK          XOR_TK          OR_TK
456 %token   BOOL_AND_TK BOOL_OR_TK 
457 %token   EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
458
459 /* This maps to the same binop_lookup entry than the token above */
460
461 %token   PLUS_ASSIGN_TK  MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
462 %token   REM_ASSIGN_TK   
463 %token   LS_ASSIGN_TK    SRS_ASSIGN_TK   ZRS_ASSIGN_TK
464 %token   AND_ASSIGN_TK   XOR_ASSIGN_TK   OR_ASSIGN_TK
465
466
467 /* Modifier TOKEN have to be kept in this order. Don't scramble it */
468
469 %token   PUBLIC_TK       PRIVATE_TK         PROTECTED_TK
470 %token   STATIC_TK       FINAL_TK           SYNCHRONIZED_TK
471 %token   VOLATILE_TK     TRANSIENT_TK       NATIVE_TK
472 %token   PAD_TK          ABSTRACT_TK        MODIFIER_TK
473 %token   STRICT_TK
474
475 /* Keep those two in order, too */
476 %token   DECR_TK INCR_TK
477
478 /* From now one, things can be in any order */
479
480 %token   DEFAULT_TK      IF_TK              THROW_TK
481 %token   BOOLEAN_TK      DO_TK              IMPLEMENTS_TK
482 %token   THROWS_TK       BREAK_TK           IMPORT_TK       
483 %token   ELSE_TK         INSTANCEOF_TK      RETURN_TK
484 %token   VOID_TK         CATCH_TK           INTERFACE_TK
485 %token   CASE_TK         EXTENDS_TK         FINALLY_TK
486 %token   SUPER_TK        WHILE_TK           CLASS_TK
487 %token   SWITCH_TK       CONST_TK           TRY_TK
488 %token   FOR_TK          NEW_TK             CONTINUE_TK
489 %token   GOTO_TK         PACKAGE_TK         THIS_TK
490
491 %token   BYTE_TK         SHORT_TK           INT_TK            LONG_TK
492 %token   CHAR_TK         INTEGRAL_TK
493
494 %token   FLOAT_TK        DOUBLE_TK          FP_TK
495
496 %token   ID_TK
497
498 %token   REL_QM_TK         REL_CL_TK NOT_TK  NEG_TK
499
500 %token   ASSIGN_ANY_TK   ASSIGN_TK
501 %token   OP_TK  CP_TK  OCB_TK  CCB_TK  OSB_TK  CSB_TK  SC_TK  C_TK DOT_TK
502
503 %token   STRING_LIT_TK   CHAR_LIT_TK        INT_LIT_TK        FP_LIT_TK
504 %token   TRUE_TK         FALSE_TK           BOOL_LIT_TK       NULL_TK
505
506 %type    <value>        modifiers MODIFIER_TK final synchronized
507
508 %type    <node>         super ID_TK identifier
509 %type    <node>         name simple_name qualified_name
510 %type    <node>         type_declaration compilation_unit
511                         field_declaration method_declaration extends_interfaces
512                         interfaces interface_type_list
513                         class_member_declaration
514                         import_declarations package_declaration 
515                         type_declarations interface_body
516                         interface_member_declaration constant_declaration
517                         interface_member_declarations interface_type
518                         abstract_method_declaration interface_type_list
519 %type    <node>         class_body_declaration class_member_declaration
520                         static_initializer constructor_declaration block
521 %type    <node>         class_body_declarations constructor_header
522 %type    <node>         class_or_interface_type class_type class_type_list
523                         constructor_declarator explicit_constructor_invocation
524 %type    <node>         dim_expr dim_exprs this_or_super throws
525
526 %type    <node>         variable_declarator_id variable_declarator
527                         variable_declarators variable_initializer
528                         variable_initializers constructor_body
529                         array_initializer
530
531 %type    <node>         class_body block_end constructor_block_end
532 %type    <node>         statement statement_without_trailing_substatement
533                         labeled_statement if_then_statement label_decl
534                         if_then_else_statement while_statement for_statement
535                         statement_nsi labeled_statement_nsi do_statement
536                         if_then_else_statement_nsi while_statement_nsi
537                         for_statement_nsi statement_expression_list for_init
538                         for_update statement_expression expression_statement
539                         primary_no_new_array expression primary
540                         array_creation_expression array_type
541                         class_instance_creation_expression field_access
542                         method_invocation array_access something_dot_new
543                         argument_list postfix_expression while_expression 
544                         post_increment_expression post_decrement_expression
545                         unary_expression_not_plus_minus unary_expression
546                         pre_increment_expression pre_decrement_expression
547                         unary_expression_not_plus_minus cast_expression
548                         multiplicative_expression additive_expression
549                         shift_expression relational_expression 
550                         equality_expression and_expression 
551                         exclusive_or_expression inclusive_or_expression
552                         conditional_and_expression conditional_or_expression
553                         conditional_expression assignment_expression
554                         left_hand_side assignment for_header for_begin
555                         constant_expression do_statement_begin empty_statement
556                         switch_statement synchronized_statement throw_statement
557                         try_statement switch_expression switch_block
558                         catches catch_clause catch_clause_parameter finally
559                         anonymous_class_creation
560 %type    <node>         return_statement break_statement continue_statement
561
562 %type    <operator>     ASSIGN_TK      MULT_ASSIGN_TK  DIV_ASSIGN_TK  
563 %type    <operator>     REM_ASSIGN_TK  PLUS_ASSIGN_TK  MINUS_ASSIGN_TK
564 %type    <operator>     LS_ASSIGN_TK   SRS_ASSIGN_TK   ZRS_ASSIGN_TK
565 %type    <operator>     AND_ASSIGN_TK  XOR_ASSIGN_TK   OR_ASSIGN_TK
566 %type    <operator>     ASSIGN_ANY_TK  assignment_operator
567 %token   <operator>     EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK 
568 %token   <operator>     BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
569 %token   <operator>     DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
570 %token   <operator>     NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK CCB_TK
571 %token   <operator>     OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
572 %type    <operator>     THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK 
573 %type    <operator>     CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
574 %type    <operator>     NEW_TK
575
576 %type    <node>         method_body 
577         
578 %type    <node>         literal INT_LIT_TK FP_LIT_TK BOOL_LIT_TK CHAR_LIT_TK
579                         STRING_LIT_TK NULL_TK VOID_TK
580
581 %type    <node>         IF_TK WHILE_TK FOR_TK
582
583 %type    <node>         formal_parameter_list formal_parameter
584                         method_declarator method_header
585
586 %type    <node>         primitive_type reference_type type 
587                         BOOLEAN_TK INTEGRAL_TK FP_TK
588
589 /* Added or modified JDK 1.1 rule types  */
590 %type    <node>         type_literals
591
592 %%
593 /* 19.2 Production from 2.3: The Syntactic Grammar  */
594 goal:
595                 {
596                   /* Register static variables with the garbage
597                      collector.  */
598                   ggc_add_tree_root (&label_id, 1);
599                   ggc_add_tree_root (&wfl_string_buffer, 1);
600                   ggc_add_tree_root (&wfl_append, 1);
601                   ggc_add_tree_root (&wfl_to_string, 1);
602                   ggc_add_tree_root (&java_lang_id, 1);
603                   ggc_add_tree_root (&inst_id, 1);
604                   ggc_add_tree_root (&java_lang_cloneable, 1);
605                   ggc_add_tree_root (&java_io_serializable, 1);
606                   ggc_add_tree_root (&current_static_block, 1);
607                   ggc_add_tree_root (&wpv_id, 1);
608                   ggc_add_tree_root (&package_list, 1);
609                   ggc_add_tree_root (&current_this, 1);
610                   ggc_add_tree_root (&currently_caught_type_list, 1);
611                   ggc_add_root (&ctxp, 1, 
612                                 sizeof (struct parser_ctxt *),
613                                 mark_parser_ctxt);
614                   ggc_add_root (&ctxp_for_generation, 1, 
615                                 sizeof (struct parser_ctxt *),
616                                 mark_parser_ctxt);
617                 }
618         compilation_unit
619                 {}
620 ;
621
622 /* 19.3 Productions from 3: Lexical structure  */
623 literal:
624         INT_LIT_TK
625 |       FP_LIT_TK
626 |       BOOL_LIT_TK
627 |       CHAR_LIT_TK
628 |       STRING_LIT_TK
629 |       NULL_TK
630 ;
631
632 /* 19.4 Productions from 4: Types, Values and Variables  */
633 type:
634         primitive_type
635 |       reference_type
636 ;
637
638 primitive_type:
639         INTEGRAL_TK
640 |       FP_TK
641 |       BOOLEAN_TK
642 ;
643
644 reference_type:
645         class_or_interface_type
646 |       array_type
647 ;
648
649 class_or_interface_type:
650         name
651 ;
652
653 class_type:
654         class_or_interface_type /* Default rule */
655 ;
656
657 interface_type:
658          class_or_interface_type
659 ;
660
661 array_type:
662         primitive_type dims
663                 { 
664                   int osb = pop_current_osb (ctxp);
665                   tree t = build_java_array_type (($1), -1);
666                   CLASS_LOADED_P (t) = 1;
667                   while (--osb)
668                     t = build_unresolved_array_type (t);
669                   $$ = t;
670                 }
671 |       name dims
672                 { 
673                   int osb = pop_current_osb (ctxp);
674                   tree t = $1;
675                   while (osb--)
676                     t = build_unresolved_array_type (t);
677                   $$ = t;
678                 }
679 ;
680
681 /* 19.5 Productions from 6: Names  */
682 name:
683         simple_name             /* Default rule */
684 |       qualified_name          /* Default rule */
685 ;
686
687 simple_name:
688         identifier              /* Default rule */
689 ;
690
691 qualified_name:
692         name DOT_TK identifier
693                 { $$ = make_qualified_name ($1, $3, $2.location); }
694 ;
695
696 identifier:
697         ID_TK
698 ;
699
700 /* 19.6: Production from 7: Packages  */
701 compilation_unit:
702                 {$$ = NULL;}
703 |       package_declaration
704 |       import_declarations
705 |       type_declarations
706 |       package_declaration import_declarations
707 |       package_declaration type_declarations
708 |       import_declarations type_declarations
709 |       package_declaration import_declarations type_declarations
710 ;
711
712 import_declarations:
713         import_declaration
714                 {
715                   $$ = NULL;
716                 }
717 |       import_declarations import_declaration
718                 {
719                   $$ = NULL;
720                 }
721 ;
722
723 type_declarations:
724         type_declaration
725 |       type_declarations type_declaration
726 ;
727
728 package_declaration:
729         PACKAGE_TK name SC_TK
730                 { 
731                   ctxp->package = EXPR_WFL_NODE ($2);
732                   register_package (ctxp->package);
733                 }
734 |       PACKAGE_TK error
735                 {yyerror ("Missing name"); RECOVER;}
736 |       PACKAGE_TK name error
737                 {yyerror ("';' expected"); RECOVER;}
738 ;
739
740 import_declaration:
741         single_type_import_declaration
742 |       type_import_on_demand_declaration
743 ;
744
745 single_type_import_declaration:
746         IMPORT_TK name SC_TK
747                 {
748                   tree name = EXPR_WFL_NODE ($2), last_name;
749                   int   i = IDENTIFIER_LENGTH (name)-1;
750                   const char *last = &IDENTIFIER_POINTER (name)[i];
751                   while (last != IDENTIFIER_POINTER (name))
752                     {
753                       if (last [0] == '.')
754                         break;
755                       last--;
756                     }
757                   last_name = get_identifier (++last);
758                   if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
759                     {
760                       tree err = find_name_in_single_imports (last_name);
761                       if (err && err != name)
762                         parse_error_context
763                           ($2, "Ambiguous class: `%s' and `%s'",
764                            IDENTIFIER_POINTER (name), 
765                            IDENTIFIER_POINTER (err));
766                       else
767                         REGISTER_IMPORT ($2, last_name);
768                     }
769                   else
770                     REGISTER_IMPORT ($2, last_name);
771                 }
772 |       IMPORT_TK error
773                 {yyerror ("Missing name"); RECOVER;}
774 |       IMPORT_TK name error
775                 {yyerror ("';' expected"); RECOVER;}
776 ;
777
778 type_import_on_demand_declaration:
779         IMPORT_TK name DOT_TK MULT_TK SC_TK
780                 {
781                   tree name = EXPR_WFL_NODE ($2);
782                   /* Don't import java.lang.* twice. */
783                   if (name != java_lang_id)
784                     {
785                       read_import_dir ($2);
786                       ctxp->import_demand_list = 
787                         chainon (ctxp->import_demand_list,
788                                  build_tree_list ($2, NULL_TREE));
789                     }
790                 }
791 |       IMPORT_TK name DOT_TK error
792                 {yyerror ("'*' expected"); RECOVER;}
793 |       IMPORT_TK name DOT_TK MULT_TK error
794                 {yyerror ("';' expected"); RECOVER;}
795 ;
796
797 type_declaration:
798         class_declaration
799                 { end_class_declaration (0); }
800 |       interface_declaration
801                 { end_class_declaration (0); }
802 |       empty_statement
803 |       error
804                 {
805                   YYERROR_NOW;
806                   yyerror ("Class or interface declaration expected");
807                 }
808 ;
809
810 /* 19.7 Shortened from the original:
811    modifiers: modifier | modifiers modifier
812    modifier: any of public...  */
813 modifiers:
814         MODIFIER_TK
815                 {
816                   $$ = (1 << $1);
817                 }
818 |       modifiers MODIFIER_TK
819                 {
820                   int acc = (1 << $2);
821                   if ($$ & acc)
822                     parse_error_context 
823                       (ctxp->modifier_ctx [$2], "Modifier `%s' declared twice",
824                        java_accstring_lookup (acc));
825                   else
826                     {
827                       $$ |= acc;
828                     }
829                 }
830 ;
831
832 /* 19.8.1 Production from $8.1: Class Declaration */
833 class_declaration:
834         modifiers CLASS_TK identifier super interfaces
835                 { create_class ($1, $3, $4, $5); }
836         class_body
837 |       CLASS_TK identifier super interfaces 
838                 { create_class (0, $2, $3, $4); }
839         class_body
840 |       modifiers CLASS_TK error
841                 {yyerror ("Missing class name"); RECOVER;}
842 |       CLASS_TK error
843                 {yyerror ("Missing class name"); RECOVER;}
844 |       CLASS_TK identifier error
845                 {
846                   if (!ctxp->class_err) yyerror ("'{' expected"); 
847                   DRECOVER(class1);
848                 }
849 |       modifiers CLASS_TK identifier error
850                 {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
851 ;
852
853 super:
854                 { $$ = NULL; }
855 |       EXTENDS_TK class_type
856                 { $$ = $2; }
857 |       EXTENDS_TK class_type error
858                 {yyerror ("'{' expected"); ctxp->class_err=1;}
859 |       EXTENDS_TK error
860                 {yyerror ("Missing super class name"); ctxp->class_err=1;}
861 ;
862
863 interfaces:
864                 { $$ = NULL_TREE; }
865 |       IMPLEMENTS_TK interface_type_list
866                 { $$ = $2; }
867 |       IMPLEMENTS_TK error
868                 {
869                   ctxp->class_err=1;
870                   yyerror ("Missing interface name"); 
871                 }
872 ;
873
874 interface_type_list:
875         interface_type
876                 { 
877                   ctxp->interface_number = 1;
878                   $$ = build_tree_list ($1, NULL_TREE);
879                 }
880 |       interface_type_list C_TK interface_type
881                 { 
882                   ctxp->interface_number++;
883                   $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
884                 }
885 |       interface_type_list C_TK error
886                 {yyerror ("Missing interface name"); RECOVER;}
887 ;
888
889 class_body:
890         OCB_TK CCB_TK
891                 { 
892                   /* Store the location of the `}' when doing xrefs */
893                   if (flag_emit_xref)
894                     DECL_END_SOURCE_LINE (GET_CPC ()) = 
895                       EXPR_WFL_ADD_COL ($2.location, 1);
896                   $$ = GET_CPC ();
897                 }
898 |       OCB_TK class_body_declarations CCB_TK
899                 { 
900                   /* Store the location of the `}' when doing xrefs */
901                   if (flag_emit_xref)
902                     DECL_END_SOURCE_LINE (GET_CPC ()) = 
903                       EXPR_WFL_ADD_COL ($3.location, 1);
904                   $$ = GET_CPC ();
905                 }
906 ;
907
908 class_body_declarations:
909         class_body_declaration
910 |       class_body_declarations class_body_declaration
911 ;
912
913 class_body_declaration:
914         class_member_declaration
915 |       static_initializer
916 |       constructor_declaration
917 |       block                   /* Added, JDK1.1, instance initializer */
918                 {
919                   TREE_CHAIN ($1) = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
920                   SET_CPC_INSTANCE_INITIALIZER_STMT (ctxp, $1);
921                 }
922 ;
923
924 class_member_declaration:
925         field_declaration
926 |       method_declaration
927 |       class_declaration       /* Added, JDK1.1 inner classes */
928                 { end_class_declaration (1); }
929 |       interface_declaration   /* Added, JDK1.1 inner interfaces */
930                 { end_class_declaration (1); }
931 |       empty_statement
932 ;
933
934 /* 19.8.2 Productions from 8.3: Field Declarations  */
935 field_declaration:
936         type variable_declarators SC_TK
937                 { register_fields (0, $1, $2); }
938 |       modifiers type variable_declarators SC_TK
939                 {
940                   check_modifiers 
941                     ("Illegal modifier `%s' for field declaration",
942                      $1, FIELD_MODIFIERS);
943                   check_modifiers_consistency ($1);
944                   register_fields ($1, $2, $3);
945                 }
946 ;
947
948 variable_declarators:
949         /* Should we use build_decl_list () instead ? FIXME */
950         variable_declarator     /* Default rule */
951 |       variable_declarators C_TK variable_declarator
952                 { $$ = chainon ($1, $3); }
953 |       variable_declarators C_TK error
954                 {yyerror ("Missing term"); RECOVER;}
955 ;
956
957 variable_declarator:
958         variable_declarator_id
959                 { $$ = build_tree_list ($1, NULL_TREE); }
960 |       variable_declarator_id ASSIGN_TK variable_initializer
961                 { 
962                   if (java_error_count)
963                     $3 = NULL_TREE;
964                   $$ = build_tree_list 
965                     ($1, build_assignment ($2.token, $2.location, $1, $3));
966                 }
967 |       variable_declarator_id ASSIGN_TK error
968                 {
969                   yyerror ("Missing variable initializer");
970                   $$ = build_tree_list ($1, NULL_TREE);
971                   RECOVER;
972                 }
973 |       variable_declarator_id ASSIGN_TK variable_initializer error
974                 {
975                   yyerror ("';' expected");
976                   $$ = build_tree_list ($1, NULL_TREE);
977                   RECOVER;
978                 }
979 ;
980
981 variable_declarator_id:
982         identifier
983 |       variable_declarator_id OSB_TK CSB_TK
984                 { $$ = build_unresolved_array_type ($1); }
985 |       identifier error
986                 {yyerror ("Invalid declaration"); DRECOVER(vdi);}
987 |       variable_declarator_id OSB_TK error
988                 { 
989                   tree node = java_lval.node;
990                   if (node && (TREE_CODE (node) == INTEGER_CST
991                                || TREE_CODE (node) == EXPR_WITH_FILE_LOCATION))
992                     yyerror ("Can't specify array dimension in a declaration");
993                   else
994                     yyerror ("']' expected");
995                   DRECOVER(vdi);
996                 }
997 |       variable_declarator_id CSB_TK error
998                 {yyerror ("Unbalanced ']'"); DRECOVER(vdi);}
999 ;
1000
1001 variable_initializer:
1002         expression
1003 |       array_initializer
1004 ;
1005
1006 /* 19.8.3 Productions from 8.4: Method Declarations  */
1007 method_declaration:
1008         method_header 
1009                 {
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);
1014                   else
1015                     current_function_decl = NULL_TREE;
1016                 }
1017         method_body
1018                 { finish_method_declaration ($3); }
1019 |       method_header error
1020                 {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
1021 ;
1022
1023 method_header:  
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); }
1032 |       type error
1033                 {
1034                   yyerror ("Invalid method declaration, method name required");
1035                   RECOVER;
1036                 }
1037 |       modifiers type error
1038                 {RECOVER;}
1039 |       VOID_TK error
1040                 {yyerror ("Identifier expected"); RECOVER;}
1041 |       modifiers VOID_TK error
1042                 {yyerror ("Identifier expected"); RECOVER;}
1043 |       modifiers error
1044                 {
1045                   yyerror ("Invalid method declaration, return type required");
1046                   RECOVER;
1047                 }
1048 ;
1049
1050 method_declarator:
1051         identifier OP_TK CP_TK
1052                 { 
1053                   ctxp->formal_parameter_number = 0;
1054                   $$ = method_declarator ($1, NULL_TREE);
1055                 }
1056 |       identifier OP_TK formal_parameter_list CP_TK
1057                 { $$ = method_declarator ($1, $3); }
1058 |       method_declarator OSB_TK CSB_TK
1059                 {
1060                   EXPR_WFL_LINECOL (wfl_operator) = $2.location;
1061                   TREE_PURPOSE ($1) = 
1062                     build_unresolved_array_type (TREE_PURPOSE ($1));
1063                   parse_warning_context 
1064                     (wfl_operator, 
1065                      "Discouraged form of returned type specification");
1066                 }
1067 |       identifier OP_TK error
1068                 {yyerror ("')' expected"); DRECOVER(method_declarator);}
1069 |       method_declarator OSB_TK error
1070                 {yyerror ("']' expected"); RECOVER;}
1071 ;
1072
1073 formal_parameter_list:
1074         formal_parameter
1075                 {
1076                   ctxp->formal_parameter_number = 1;
1077                 }
1078 |       formal_parameter_list C_TK formal_parameter
1079                 {
1080                   ctxp->formal_parameter_number += 1;
1081                   $$ = chainon ($1, $3);
1082                 }
1083 |       formal_parameter_list C_TK error
1084                 { yyerror ("Missing formal parameter term"); RECOVER; }
1085 ;
1086
1087 formal_parameter:
1088         type variable_declarator_id
1089                 {
1090                   $$ = build_tree_list ($2, $1);
1091                 }
1092 |       final type variable_declarator_id /* Added, JDK1.1 final parms */
1093                 { 
1094                   $$ = build_tree_list ($3, $2);
1095                   ARG_FINAL_P ($$) = 1;
1096                 }
1097 |       type error
1098                 {
1099                   yyerror ("Missing identifier"); RECOVER;
1100                   $$ = NULL_TREE;
1101                 }
1102 |       final type error
1103                 {
1104                   yyerror ("Missing identifier"); RECOVER;
1105                   $$ = NULL_TREE;
1106                 }
1107 ;
1108
1109 final:
1110         modifiers
1111                 {
1112                   check_modifiers ("Illegal modifier `%s'. Only `final' was expected here",
1113                                    $1, ACC_FINAL);
1114                   if ($1 != ACC_FINAL)
1115                     MODIFIER_WFL (FINAL_TK) = build_wfl_node (NULL_TREE);
1116                 }
1117 ;
1118
1119 throws:
1120                 { $$ = NULL_TREE; }
1121 |       THROWS_TK class_type_list
1122                 { $$ = $2; }
1123 |       THROWS_TK error
1124                 {yyerror ("Missing class type term"); RECOVER;}
1125 ;
1126
1127 class_type_list:
1128         class_type
1129                 { $$ = build_tree_list ($1, $1); }
1130 |       class_type_list C_TK class_type
1131                 { $$ = tree_cons ($3, $3, $1); }
1132 |       class_type_list C_TK error
1133                 {yyerror ("Missing class type term"); RECOVER;}
1134 ;
1135
1136 method_body:
1137         block
1138 |       SC_TK { $$ = NULL_TREE; }
1139 ;
1140
1141 /* 19.8.4 Productions from 8.5: Static Initializers  */
1142 static_initializer:
1143         static block
1144                 {
1145                   TREE_CHAIN ($2) = CPC_STATIC_INITIALIZER_STMT (ctxp);
1146                   SET_CPC_STATIC_INITIALIZER_STMT (ctxp, $2);
1147                   current_static_block = NULL_TREE;
1148                 }
1149 ;
1150
1151 static:                         /* Test lval.sub_token here */
1152         modifiers
1153                 {
1154                   check_modifiers ("Illegal modifier `%s' for static initializer", $1, ACC_STATIC);
1155                   /* Can't have a static initializer in an innerclass */
1156                   if ($1 | ACC_STATIC &&
1157                       GET_CPC_LIST () && !TOPLEVEL_CLASS_DECL_P (GET_CPC ()))
1158                     parse_error_context 
1159                       (MODIFIER_WFL (STATIC_TK),
1160                        "Can't define static initializer in class `%s'. Static initializer can only be defined in top-level classes",
1161                        IDENTIFIER_POINTER (DECL_NAME (GET_CPC ())));
1162                   SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
1163                 }
1164 ;
1165
1166 /* 19.8.5 Productions from 8.6: Constructor Declarations  */
1167 constructor_declaration:
1168         constructor_header
1169                 {
1170                   current_function_decl = $1;
1171                   source_start_java_method (current_function_decl);
1172                 }
1173         constructor_body
1174                 { finish_method_declaration ($3); }
1175 ;
1176
1177 constructor_header:
1178         constructor_declarator throws
1179                 { $$ = method_header (0, NULL_TREE, $1, $2); }
1180 |       modifiers constructor_declarator throws
1181                 { $$ = method_header ($1, NULL_TREE, $2, $3); }
1182 ;
1183
1184 constructor_declarator:
1185         simple_name OP_TK CP_TK
1186                 { 
1187                   ctxp->formal_parameter_number = 0;  
1188                   $$ = method_declarator ($1, NULL_TREE);
1189                 }
1190 |       simple_name OP_TK formal_parameter_list CP_TK
1191                 { $$ = method_declarator ($1, $3); }
1192 ;
1193
1194 constructor_body:
1195         /* Unlike regular method, we always need a complete (empty)
1196            body so we can safely perform all the required code
1197            addition (super invocation and field initialization) */
1198         block_begin constructor_block_end
1199                 { 
1200                   BLOCK_EXPR_BODY ($2) = empty_stmt_node;
1201                   $$ = $2;
1202                 }
1203 |       block_begin explicit_constructor_invocation constructor_block_end
1204                 { $$ = $3; }
1205 |       block_begin block_statements constructor_block_end
1206                 { $$ = $3; }
1207 |       block_begin explicit_constructor_invocation block_statements constructor_block_end
1208                 { $$ = $4; }
1209 ;
1210
1211 constructor_block_end:
1212         block_end
1213 ;
1214
1215 /* Error recovery for that rule moved down expression_statement: rule.  */
1216 explicit_constructor_invocation:
1217         this_or_super OP_TK CP_TK SC_TK
1218                 { 
1219                   $$ = build_method_invocation ($1, NULL_TREE); 
1220                   $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1221                   $$ = java_method_add_stmt (current_function_decl, $$);
1222                 }
1223 |       this_or_super OP_TK argument_list CP_TK SC_TK
1224                 { 
1225                   $$ = build_method_invocation ($1, $3); 
1226                   $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
1227                   $$ = java_method_add_stmt (current_function_decl, $$);
1228                 }
1229         /* Added, JDK1.1 inner classes. Modified because the rule
1230            'primary' couldn't work.  */
1231 |       name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
1232                 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1233 |       name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
1234                 {$$ = parse_jdk1_1_error ("explicit constructor invocation"); }
1235 ;
1236
1237 this_or_super:                  /* Added, simplifies error diagnostics */
1238         THIS_TK
1239                 {
1240                   tree wfl = build_wfl_node (this_identifier_node);
1241                   EXPR_WFL_LINECOL (wfl) = $1.location;
1242                   $$ = wfl;
1243                 }
1244 |       SUPER_TK
1245                 {
1246                   tree wfl = build_wfl_node (super_identifier_node);
1247                   EXPR_WFL_LINECOL (wfl) = $1.location;
1248                   $$ = wfl;
1249                 }
1250 ;
1251
1252 /* 19.9 Productions from 9: Interfaces  */
1253 /* 19.9.1 Productions from 9.1: Interfaces Declarations  */
1254 interface_declaration:
1255         INTERFACE_TK identifier
1256                 { create_interface (0, $2, NULL_TREE); }
1257         interface_body
1258 |       modifiers INTERFACE_TK identifier
1259                 { create_interface ($1, $3, NULL_TREE); }
1260         interface_body
1261 |       INTERFACE_TK identifier extends_interfaces
1262                 { create_interface (0, $2, $3); }
1263         interface_body
1264 |       modifiers INTERFACE_TK identifier extends_interfaces
1265                 { create_interface ($1, $3, $4); }
1266         interface_body
1267 |       INTERFACE_TK identifier error
1268                 {yyerror ("'{' expected"); RECOVER;}
1269 |       modifiers INTERFACE_TK identifier error
1270                 {yyerror ("'{' expected"); RECOVER;}
1271 ;
1272
1273 extends_interfaces:
1274         EXTENDS_TK interface_type
1275                 { 
1276                   ctxp->interface_number = 1;
1277                   $$ = build_tree_list ($2, NULL_TREE);
1278                 }
1279 |       extends_interfaces C_TK interface_type
1280                 { 
1281                   ctxp->interface_number++;
1282                   $$ = chainon ($1, build_tree_list ($3, NULL_TREE));
1283                 }
1284 |       EXTENDS_TK error
1285                 {yyerror ("Invalid interface type"); RECOVER;}
1286 |       extends_interfaces C_TK error
1287                 {yyerror ("Missing term"); RECOVER;}
1288 ;
1289
1290 interface_body:
1291         OCB_TK CCB_TK
1292                 { $$ = NULL_TREE; }
1293 |       OCB_TK interface_member_declarations CCB_TK
1294                 { $$ = NULL_TREE; }
1295 ;
1296
1297 interface_member_declarations:
1298         interface_member_declaration
1299 |       interface_member_declarations interface_member_declaration
1300 ;
1301
1302 interface_member_declaration:
1303         constant_declaration
1304 |       abstract_method_declaration
1305 |       class_declaration       /* Added, JDK1.1 inner classes */
1306                 { end_class_declaration (1); }
1307 |       interface_declaration   /* Added, JDK1.1 inner interfaces */
1308                 { end_class_declaration (1); }
1309 ;
1310
1311 constant_declaration:
1312         field_declaration
1313 ;
1314
1315 abstract_method_declaration:
1316         method_header SC_TK
1317                 { 
1318                   check_abstract_method_header ($1);
1319                   current_function_decl = NULL_TREE; /* FIXME ? */
1320                 }
1321 |       method_header error
1322                 {yyerror ("';' expected"); RECOVER;}
1323 ;
1324
1325 /* 19.10 Productions from 10: Arrays  */
1326 array_initializer:
1327         OCB_TK CCB_TK
1328                 { $$ = build_new_array_init ($1.location, NULL_TREE); }
1329 |       OCB_TK variable_initializers CCB_TK
1330                 { $$ = build_new_array_init ($1.location, $2); }
1331 |       OCB_TK variable_initializers C_TK CCB_TK
1332                 { $$ = build_new_array_init ($1.location, $2); }
1333 ;
1334
1335 variable_initializers:
1336         variable_initializer
1337                 { 
1338                   $$ = tree_cons (maybe_build_array_element_wfl ($1), 
1339                                   $1, NULL_TREE);
1340                 }
1341 |       variable_initializers C_TK variable_initializer
1342                 {
1343                   $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
1344                 }
1345 |       variable_initializers C_TK error
1346                 {yyerror ("Missing term"); RECOVER;}
1347 ;
1348
1349 /* 19.11 Production from 14: Blocks and Statements  */
1350 block:
1351         OCB_TK CCB_TK
1352                 { 
1353                   /* Store the location of the `}' when doing xrefs */
1354                   if (current_function_decl && flag_emit_xref)
1355                     DECL_END_SOURCE_LINE (current_function_decl) = 
1356                       EXPR_WFL_ADD_COL ($2.location, 1);
1357                   $$ = empty_stmt_node; 
1358                 }
1359 |       block_begin block_statements block_end
1360                 { $$ = $3; }
1361 ;
1362
1363 block_begin:
1364         OCB_TK
1365                 { enter_block (); }
1366 ;
1367
1368 block_end:
1369         CCB_TK
1370                 { 
1371                   maybe_absorb_scoping_blocks ();
1372                   /* Store the location of the `}' when doing xrefs */
1373                   if (current_function_decl && flag_emit_xref)
1374                     DECL_END_SOURCE_LINE (current_function_decl) = 
1375                       EXPR_WFL_ADD_COL ($1.location, 1);                  
1376                   $$ = exit_block ();
1377                   if (!BLOCK_SUBBLOCKS ($$))
1378                     BLOCK_SUBBLOCKS ($$) = empty_stmt_node;
1379                 }
1380 ;
1381
1382 block_statements:
1383         block_statement
1384 |       block_statements block_statement
1385 ;
1386
1387 block_statement:
1388         local_variable_declaration_statement
1389 |       statement
1390                 { java_method_add_stmt (current_function_decl, $1); }
1391 |       class_declaration       /* Added, JDK1.1 local classes */
1392                 { 
1393                   LOCAL_CLASS_P (TREE_TYPE (GET_CPC ())) = 1;
1394                   end_class_declaration (1);
1395                 }
1396 ;
1397
1398 local_variable_declaration_statement:
1399         local_variable_declaration SC_TK /* Can't catch missing ';' here */
1400 ;
1401
1402 local_variable_declaration:
1403         type variable_declarators
1404                 { declare_local_variables (0, $1, $2); }
1405 |       final type variable_declarators /* Added, JDK1.1 final locals */
1406                 { declare_local_variables ($1, $2, $3); }
1407 ;
1408
1409 statement:
1410         statement_without_trailing_substatement
1411 |       labeled_statement
1412 |       if_then_statement
1413 |       if_then_else_statement
1414 |       while_statement
1415 |       for_statement
1416                 { $$ = exit_block (); }
1417 ;
1418
1419 statement_nsi:
1420         statement_without_trailing_substatement
1421 |       labeled_statement_nsi
1422 |       if_then_else_statement_nsi
1423 |       while_statement_nsi
1424 |       for_statement_nsi
1425                 { $$ = exit_block (); }
1426 ;
1427
1428 statement_without_trailing_substatement:
1429         block
1430 |       empty_statement
1431 |       expression_statement
1432 |       switch_statement
1433 |       do_statement
1434 |       break_statement
1435 |       continue_statement
1436 |       return_statement
1437 |       synchronized_statement
1438 |       throw_statement
1439 |       try_statement
1440 ;
1441
1442 empty_statement:
1443         SC_TK
1444                 { 
1445                   if (flag_extraneous_semicolon)
1446                     {
1447                       EXPR_WFL_SET_LINECOL (wfl_operator, lineno, -1);
1448                       parse_warning_context (wfl_operator, "An empty declaration is a deprecated feature that should not be used");
1449                     }
1450                   $$ = empty_stmt_node;
1451                 }
1452 ;
1453
1454 label_decl:
1455         identifier REL_CL_TK
1456                 {
1457                   $$ = build_labeled_block (EXPR_WFL_LINECOL ($1), 
1458                                             EXPR_WFL_NODE ($1));
1459                   pushlevel (2);
1460                   push_labeled_block ($$);
1461                   PUSH_LABELED_BLOCK ($$);
1462                 }
1463 ;
1464
1465 labeled_statement:
1466         label_decl statement
1467                 { $$ = finish_labeled_statement ($1, $2); }
1468 |       identifier error
1469                 {yyerror ("':' expected"); RECOVER;}
1470 ;
1471
1472 labeled_statement_nsi:
1473         label_decl statement_nsi
1474                 { $$ = finish_labeled_statement ($1, $2); }
1475 ;
1476
1477 /* We concentrate here a bunch of error handling rules that we couldn't write
1478    earlier, because expression_statement catches a missing ';'.  */
1479 expression_statement:
1480         statement_expression SC_TK
1481                 {
1482                   /* We have a statement. Generate a WFL around it so
1483                      we can debug it */
1484                   $$ = build_expr_wfl ($1, input_filename, lineno, 0);
1485                   /* We know we have a statement, so set the debug
1486                      info to be eventually generate here. */
1487                   $$ = JAVA_MAYBE_GENERATE_DEBUG_INFO ($$);
1488                 }
1489 |       error SC_TK 
1490                 {
1491                   YYNOT_TWICE yyerror ("Invalid expression statement");
1492                   DRECOVER (expr_stmt);
1493                 }
1494 |       error OCB_TK
1495                 {
1496                   YYNOT_TWICE yyerror ("Invalid expression statement");
1497                   DRECOVER (expr_stmt);
1498                 }
1499 |       error CCB_TK
1500                 {
1501                   YYNOT_TWICE yyerror ("Invalid expression statement");
1502                   DRECOVER (expr_stmt);
1503                 }
1504 |       this_or_super OP_TK error
1505                 {yyerror ("')' expected"); RECOVER;}
1506 |       this_or_super OP_TK CP_TK error
1507                 {
1508                   parse_ctor_invocation_error ();
1509                   RECOVER;
1510                 }
1511 |       this_or_super OP_TK argument_list error
1512                 {yyerror ("')' expected"); RECOVER;}
1513 |       this_or_super OP_TK argument_list CP_TK error
1514                 {
1515                   parse_ctor_invocation_error ();
1516                   RECOVER;
1517                 }
1518 |       name DOT_TK SUPER_TK error
1519                 {yyerror ("'(' expected"); RECOVER;}
1520 |       name DOT_TK SUPER_TK OP_TK error
1521                 {yyerror ("')' expected"); RECOVER;}
1522 |       name DOT_TK SUPER_TK OP_TK argument_list error
1523                 {yyerror ("')' expected"); RECOVER;}
1524 |       name DOT_TK SUPER_TK OP_TK argument_list CP_TK error
1525                 {yyerror ("';' expected"); RECOVER;}
1526 |       name DOT_TK SUPER_TK OP_TK CP_TK error
1527                 {yyerror ("';' expected"); RECOVER;}
1528 ;
1529
1530 statement_expression: 
1531         assignment
1532 |       pre_increment_expression
1533 |       pre_decrement_expression
1534 |       post_increment_expression
1535 |       post_decrement_expression
1536 |       method_invocation
1537 |       class_instance_creation_expression
1538 ;
1539
1540 if_then_statement:
1541         IF_TK OP_TK expression CP_TK statement
1542                 { 
1543                   $$ = build_if_else_statement ($2.location, $3, 
1544                                                 $5, NULL_TREE);
1545                 }
1546 |       IF_TK error
1547                 {yyerror ("'(' expected"); RECOVER;}
1548 |       IF_TK OP_TK error
1549                 {yyerror ("Missing term"); RECOVER;}
1550 |       IF_TK OP_TK expression error
1551                 {yyerror ("')' expected"); RECOVER;}
1552 ;
1553
1554 if_then_else_statement:
1555         IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
1556                 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1557 ;
1558
1559 if_then_else_statement_nsi:
1560         IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
1561                 { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
1562 ;
1563
1564 switch_statement:
1565         switch_expression
1566                 {
1567                   enter_block ();
1568                 }
1569         switch_block
1570                 { 
1571                   /* Make into "proper list" of COMPOUND_EXPRs.
1572                      I.e. make the last statment also have its own
1573                      COMPOUND_EXPR. */
1574                   maybe_absorb_scoping_blocks ();
1575                   TREE_OPERAND ($1, 1) = exit_block ();
1576                   $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
1577                 }
1578 ;
1579
1580 switch_expression:
1581         SWITCH_TK OP_TK expression CP_TK
1582                 { 
1583                   $$ = build (SWITCH_EXPR, NULL_TREE, $3, NULL_TREE);
1584                   EXPR_WFL_LINECOL ($$) = $2.location;
1585                 }
1586 |       SWITCH_TK error
1587                 {yyerror ("'(' expected"); RECOVER;}
1588 |       SWITCH_TK OP_TK error
1589                 {yyerror ("Missing term or ')'"); DRECOVER(switch_statement);}
1590 |       SWITCH_TK OP_TK expression CP_TK error
1591                 {yyerror ("'{' expected"); RECOVER;}
1592 ;
1593
1594 /* Default assignment is there to avoid type node on switch_block
1595    node. */
1596
1597 switch_block:
1598         OCB_TK CCB_TK
1599                 { $$ = NULL_TREE; }
1600 |       OCB_TK switch_labels CCB_TK
1601                 { $$ = NULL_TREE; }
1602 |       OCB_TK switch_block_statement_groups CCB_TK
1603                 { $$ = NULL_TREE; }
1604 |       OCB_TK switch_block_statement_groups switch_labels CCB_TK
1605                 { $$ = NULL_TREE; }
1606 ;
1607
1608 switch_block_statement_groups: 
1609         switch_block_statement_group
1610 |       switch_block_statement_groups switch_block_statement_group
1611 ;
1612
1613 switch_block_statement_group:
1614         switch_labels block_statements
1615 ;
1616
1617 switch_labels:
1618         switch_label
1619 |       switch_labels switch_label
1620 ;
1621
1622 switch_label:
1623         CASE_TK constant_expression REL_CL_TK
1624                 { 
1625                   tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
1626                   EXPR_WFL_LINECOL (lab) = $1.location;
1627                   java_method_add_stmt (current_function_decl, lab);
1628                 }
1629 |       DEFAULT_TK REL_CL_TK
1630                 { 
1631                   tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
1632                   EXPR_WFL_LINECOL (lab) = $1.location;
1633                   java_method_add_stmt (current_function_decl, lab);
1634                 }
1635 |       CASE_TK error
1636                 {yyerror ("Missing or invalid constant expression"); RECOVER;}
1637 |       CASE_TK constant_expression error
1638                 {yyerror ("':' expected"); RECOVER;}
1639 |       DEFAULT_TK error
1640                 {yyerror ("':' expected"); RECOVER;}
1641 ;
1642
1643 while_expression:
1644         WHILE_TK OP_TK expression CP_TK
1645                 { 
1646                   tree body = build_loop_body ($2.location, $3, 0);
1647                   $$ = build_new_loop (body);
1648                 }
1649 ;
1650
1651 while_statement:
1652         while_expression statement
1653                 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1654 |       WHILE_TK error
1655                 {YYERROR_NOW; yyerror ("'(' expected"); RECOVER;}
1656 |       WHILE_TK OP_TK error
1657                 {yyerror ("Missing term and ')' expected"); RECOVER;}
1658 |       WHILE_TK OP_TK expression error
1659                 {yyerror ("')' expected"); RECOVER;}
1660 ;
1661
1662 while_statement_nsi:
1663         while_expression statement_nsi
1664                 { $$ = finish_loop_body (0, NULL_TREE, $2, 0); }
1665 ;
1666
1667 do_statement_begin:
1668         DO_TK
1669                 { 
1670                   tree body = build_loop_body (0, NULL_TREE, 1);
1671                   $$ = build_new_loop (body);
1672                 }
1673         /* Need error handing here. FIXME */
1674 ;
1675
1676 do_statement: 
1677         do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
1678                 { $$ = finish_loop_body ($4.location, $5, $2, 1); }
1679 ;
1680
1681 for_statement:
1682         for_begin SC_TK expression SC_TK for_update CP_TK statement
1683                 {
1684                   if (TREE_CODE_CLASS (TREE_CODE ($3)) == 'c')
1685                     $3 = build_wfl_node ($3);
1686                   $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);
1687                 }
1688 |       for_begin SC_TK SC_TK for_update CP_TK statement
1689                 { 
1690                   $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1691                   /* We have not condition, so we get rid of the EXIT_EXPR */
1692                   LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) = 
1693                     empty_stmt_node;
1694                 }
1695 |       for_begin SC_TK error
1696                 {yyerror ("Invalid control expression"); RECOVER;}
1697 |       for_begin SC_TK expression SC_TK error
1698                 {yyerror ("Invalid update expression"); RECOVER;}
1699 |       for_begin SC_TK SC_TK error
1700                 {yyerror ("Invalid update expression"); RECOVER;}
1701 ;
1702
1703 for_statement_nsi:
1704         for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
1705                 { $$ = finish_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
1706 |       for_begin SC_TK SC_TK for_update CP_TK statement_nsi
1707                 { 
1708                   $$ = finish_for_loop (0, NULL_TREE, $4, $6);
1709                   /* We have not condition, so we get rid of the EXIT_EXPR */
1710                   LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) = 
1711                     empty_stmt_node;
1712                 }
1713 ;
1714
1715 for_header:
1716         FOR_TK OP_TK
1717                 { 
1718                   /* This scope defined for local variable that may be
1719                      defined within the scope of the for loop */
1720                   enter_block (); 
1721                 }
1722 |       FOR_TK error
1723                 {yyerror ("'(' expected"); DRECOVER(for_1);}
1724 |       FOR_TK OP_TK error
1725                 {yyerror ("Invalid init statement"); RECOVER;}
1726 ;
1727
1728 for_begin:
1729         for_header for_init
1730                 { 
1731                   /* We now declare the loop body. The loop is
1732                      declared as a for loop. */
1733                   tree body = build_loop_body (0, NULL_TREE, 0);
1734                   $$ =  build_new_loop (body);
1735                   FOR_LOOP_P ($$) = 1;
1736                   /* The loop is added to the current block the for
1737                      statement is defined within */
1738                   java_method_add_stmt (current_function_decl, $$);
1739                 }
1740 ;
1741 for_init:                       /* Can be empty */
1742                 { $$ = empty_stmt_node; }
1743 |       statement_expression_list
1744                 { 
1745                   /* Init statement recorded within the previously
1746                      defined block scope */
1747                   $$ = java_method_add_stmt (current_function_decl, $1);
1748                 }
1749 |       local_variable_declaration
1750                 { 
1751                   /* Local variable are recorded within the previously
1752                      defined block scope */
1753                   $$ = NULL_TREE;
1754                 }
1755 |       statement_expression_list error
1756                 {yyerror ("';' expected"); DRECOVER(for_init_1);}
1757 ;
1758
1759 for_update:                     /* Can be empty */
1760                 {$$ = empty_stmt_node;}
1761 |       statement_expression_list
1762                 { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
1763 ;
1764
1765 statement_expression_list:
1766         statement_expression
1767                 { $$ = add_stmt_to_compound (NULL_TREE, NULL_TREE, $1); }
1768 |       statement_expression_list C_TK statement_expression
1769                 { $$ = add_stmt_to_compound ($1, NULL_TREE, $3); }
1770 |       statement_expression_list C_TK error
1771                 {yyerror ("Missing term"); RECOVER;}
1772 ;
1773
1774 break_statement:
1775         BREAK_TK SC_TK
1776                 { $$ = build_bc_statement ($1.location, 1, NULL_TREE); }
1777 |       BREAK_TK identifier SC_TK
1778                 { $$ = build_bc_statement ($1.location, 1, $2); }
1779 |       BREAK_TK error
1780                 {yyerror ("Missing term"); RECOVER;}
1781 |       BREAK_TK identifier error
1782                 {yyerror ("';' expected"); RECOVER;}
1783 ;
1784
1785 continue_statement:
1786         CONTINUE_TK SC_TK
1787                 { $$ = build_bc_statement ($1.location, 0, NULL_TREE); }
1788 |       CONTINUE_TK identifier SC_TK
1789                 { $$ = build_bc_statement ($1.location, 0, $2); }
1790 |       CONTINUE_TK error
1791                 {yyerror ("Missing term"); RECOVER;}
1792 |       CONTINUE_TK identifier error
1793                 {yyerror ("';' expected"); RECOVER;}
1794 ;
1795
1796 return_statement:
1797         RETURN_TK SC_TK
1798                 { $$ = build_return ($1.location, NULL_TREE); }
1799 |       RETURN_TK expression SC_TK
1800                 { $$ = build_return ($1.location, $2); }
1801 |       RETURN_TK error
1802                 {yyerror ("Missing term"); RECOVER;}
1803 |       RETURN_TK expression error
1804                 {yyerror ("';' expected"); RECOVER;}
1805 ;
1806
1807 throw_statement:
1808         THROW_TK expression SC_TK
1809                 { 
1810                   $$ = build1 (THROW_EXPR, NULL_TREE, $2);
1811                   EXPR_WFL_LINECOL ($$) = $1.location;
1812                 }
1813 |       THROW_TK error
1814                 {yyerror ("Missing term"); RECOVER;}
1815 |       THROW_TK expression error
1816                 {yyerror ("';' expected"); RECOVER;}
1817 ;
1818
1819 synchronized_statement:
1820         synchronized OP_TK expression CP_TK block
1821                 { 
1822                   $$ = build (SYNCHRONIZED_EXPR, NULL_TREE, $3, $5);
1823                   EXPR_WFL_LINECOL ($$) = 
1824                     EXPR_WFL_LINECOL (MODIFIER_WFL (SYNCHRONIZED_TK));
1825                 }
1826 |       synchronized OP_TK expression CP_TK error
1827                 {yyerror ("'{' expected"); RECOVER;}
1828 |       synchronized error
1829                 {yyerror ("'(' expected"); RECOVER;}
1830 |       synchronized OP_TK error CP_TK
1831                 {yyerror ("Missing term"); RECOVER;}
1832 |       synchronized OP_TK error
1833                 {yyerror ("Missing term"); RECOVER;}
1834 ;
1835
1836 synchronized:
1837         modifiers
1838                 {
1839                   check_modifiers (
1840              "Illegal modifier `%s'. Only `synchronized' was expected here",
1841                                    $1, ACC_SYNCHRONIZED);
1842                   if ($1 != ACC_SYNCHRONIZED)
1843                     MODIFIER_WFL (SYNCHRONIZED_TK) = 
1844                       build_wfl_node (NULL_TREE);
1845                 }
1846 ;
1847
1848 try_statement:
1849         TRY_TK block catches
1850                 { $$ = build_try_statement ($1.location, $2, $3); }
1851 |       TRY_TK block finally
1852                 { $$ = build_try_finally_statement ($1.location, $2, $3); }
1853 |       TRY_TK block catches finally
1854                 { $$ = build_try_finally_statement 
1855                     ($1.location, build_try_statement ($1.location,
1856                                                        $2, $3), $4);
1857                 }
1858 |       TRY_TK error
1859                 {yyerror ("'{' expected"); DRECOVER (try_statement);}
1860 ;
1861
1862 catches:
1863         catch_clause
1864 |       catches catch_clause
1865                 { 
1866                   TREE_CHAIN ($2) = $1;
1867                   $$ = $2;
1868                 }
1869 ;
1870
1871 catch_clause:
1872         catch_clause_parameter block
1873                 { 
1874                   java_method_add_stmt (current_function_decl, $2);
1875                   exit_block ();
1876                   $$ = $1;
1877                 }
1878
1879 catch_clause_parameter:
1880         CATCH_TK OP_TK formal_parameter CP_TK
1881                 { 
1882                   /* We add a block to define a scope for
1883                      formal_parameter (CCBP). The formal parameter is
1884                      declared initialized by the appropriate function
1885                      call */
1886                   tree ccpb = enter_block ();
1887                   tree init = build_assignment (ASSIGN_TK, $2.location, 
1888                                                 TREE_PURPOSE ($3), 
1889                                                 soft_exceptioninfo_call_node);
1890                   declare_local_variables (0, TREE_VALUE ($3),
1891                                            build_tree_list (TREE_PURPOSE ($3),
1892                                                             init));
1893                   $$ = build1 (CATCH_EXPR, NULL_TREE, ccpb);
1894                   EXPR_WFL_LINECOL ($$) = $1.location;
1895                 }
1896 |       CATCH_TK error
1897                 {yyerror ("'(' expected"); RECOVER; $$ = NULL_TREE;}
1898 |       CATCH_TK OP_TK error 
1899                 {
1900                   yyerror ("Missing term or ')' expected"); 
1901                   RECOVER; $$ = NULL_TREE;
1902                 }
1903 |       CATCH_TK OP_TK error CP_TK /* That's for () */
1904                 {yyerror ("Missing term"); RECOVER; $$ = NULL_TREE;}
1905 ;
1906
1907 finally:
1908         FINALLY_TK block
1909                 { $$ = $2; }
1910 |       FINALLY_TK error
1911                 {yyerror ("'{' expected"); RECOVER; }
1912 ;
1913
1914 /* 19.12 Production from 15: Expressions  */
1915 primary:
1916         primary_no_new_array
1917 |       array_creation_expression
1918 ;
1919
1920 primary_no_new_array:
1921         literal
1922 |       THIS_TK
1923                 { $$ = build_this ($1.location); }
1924 |       OP_TK expression CP_TK
1925                 {$$ = $2;}
1926 |       class_instance_creation_expression
1927 |       field_access
1928 |       method_invocation
1929 |       array_access
1930 |       type_literals
1931         /* Added, JDK1.1 inner classes. Documentation is wrong
1932            refering to a 'ClassName' (class_name) rule that doesn't
1933            exist. Used name: instead.  */
1934 |       name DOT_TK THIS_TK
1935                 { 
1936                   tree wfl = build_wfl_node (this_identifier_node);
1937                   $$ = make_qualified_primary ($1, wfl, EXPR_WFL_LINECOL ($1));
1938                 }
1939 |       OP_TK expression error 
1940                 {yyerror ("')' expected"); RECOVER;}
1941 |       name DOT_TK error
1942                 {yyerror ("'class' or 'this' expected" ); RECOVER;}
1943 |       primitive_type DOT_TK error
1944                 {yyerror ("'class' expected" ); RECOVER;}
1945 |       VOID_TK DOT_TK error
1946                 {yyerror ("'class' expected" ); RECOVER;}
1947 ;
1948
1949 type_literals:
1950         name DOT_TK CLASS_TK
1951                 { $$ = build_incomplete_class_ref ($2.location, $1); }
1952 |       array_type DOT_TK CLASS_TK
1953                 { $$ = build_incomplete_class_ref ($2.location, $1); }
1954 |       primitive_type DOT_TK CLASS_TK
1955                 { $$ = build_class_ref ($1); }
1956 |       VOID_TK DOT_TK CLASS_TK
1957                 { $$ = build_class_ref (void_type_node); }
1958 ;
1959
1960 class_instance_creation_expression:
1961         NEW_TK class_type OP_TK argument_list CP_TK
1962                 { $$ = build_new_invocation ($2, $4); }
1963 |       NEW_TK class_type OP_TK CP_TK
1964                 { $$ = build_new_invocation ($2, NULL_TREE); }
1965 |       anonymous_class_creation
1966         /* Added, JDK1.1 inner classes, modified to use name or
1967            primary instead of primary solely which couldn't work in
1968            all situations.  */
1969 |       something_dot_new identifier OP_TK CP_TK
1970                 { 
1971                   tree ctor = build_new_invocation ($2, NULL_TREE);
1972                   $$ = make_qualified_primary ($1, ctor, 
1973                                                EXPR_WFL_LINECOL ($1));
1974                 }
1975 |       something_dot_new identifier OP_TK CP_TK class_body
1976 |       something_dot_new identifier OP_TK argument_list CP_TK
1977                 { 
1978                   tree ctor = build_new_invocation ($2, $4);
1979                   $$ = make_qualified_primary ($1, ctor, 
1980                                                EXPR_WFL_LINECOL ($1));
1981                 }
1982 |       something_dot_new identifier OP_TK argument_list CP_TK class_body
1983 |       NEW_TK error SC_TK 
1984                 {yyerror ("'(' expected"); DRECOVER(new_1);}
1985 |       NEW_TK class_type error
1986                 {yyerror ("'(' expected"); RECOVER;}
1987 |       NEW_TK class_type OP_TK error
1988                 {yyerror ("')' or term expected"); RECOVER;}
1989 |       NEW_TK class_type OP_TK argument_list error
1990                 {yyerror ("')' expected"); RECOVER;}
1991 |       something_dot_new error
1992                 {YYERROR_NOW; yyerror ("Identifier expected"); RECOVER;}
1993 |       something_dot_new identifier error
1994                 {yyerror ("'(' expected"); RECOVER;}
1995 ;
1996
1997 /* Created after JDK1.1 rules originally added to
1998    class_instance_creation_expression, but modified to use
1999    'class_type' instead of 'TypeName' (type_name) which is mentionned
2000    in the documentation but doesn't exist. */
2001
2002 anonymous_class_creation:
2003         NEW_TK class_type OP_TK argument_list CP_TK 
2004                 { create_anonymous_class ($1.location, $2); }
2005         class_body
2006                 { 
2007                   tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2008                   EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2009
2010                   end_class_declaration (1);
2011
2012                   /* Now we can craft the new expression */
2013                   $$ = build_new_invocation (id, $4);
2014
2015                   /* Note that we can't possibly be here if
2016                      `class_type' is an interface (in which case the
2017                      anonymous class extends Object and implements
2018                      `class_type', hence its constructor can't have
2019                      arguments.) */
2020
2021                   /* Otherwise, the innerclass must feature a
2022                      constructor matching `argument_list'. Anonymous
2023                      classes are a bit special: it's impossible to
2024                      define constructor for them, hence constructors
2025                      must be generated following the hints provided by
2026                      the `new' expression. Whether a super constructor
2027                      of that nature exists or not is to be verified
2028                      later on in verify_constructor_super. 
2029
2030                      It's during the expansion of a `new' statement
2031                      refering to an anonymous class that a ctor will
2032                      be generated for the anonymous class, with the
2033                      right arguments. */
2034
2035                 }
2036 |       NEW_TK class_type OP_TK CP_TK 
2037                 { create_anonymous_class ($1.location, $2); }
2038         class_body         
2039                 { 
2040                   tree id = build_wfl_node (DECL_NAME (GET_CPC ()));
2041                   EXPR_WFL_LINECOL (id) = EXPR_WFL_LINECOL ($2);
2042
2043                   end_class_declaration (1);
2044
2045                   /* Now we can craft the new expression. The
2046                      statement doesn't need to be remember so that a
2047                      constructor can be generated, since its signature
2048                      is already known. */
2049                   $$ = build_new_invocation (id, NULL_TREE);
2050                 }
2051 ;
2052
2053 something_dot_new:              /* Added, not part of the specs. */
2054         name DOT_TK NEW_TK
2055                 { $$ = $1; }
2056 |       primary DOT_TK NEW_TK
2057                 { $$ = $1; }
2058 ;
2059
2060 argument_list:
2061         expression
2062                 { 
2063                   $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
2064                   ctxp->formal_parameter_number = 1; 
2065                 }
2066 |       argument_list C_TK expression
2067                 {
2068                   ctxp->formal_parameter_number += 1;
2069                   $$ = tree_cons (NULL_TREE, $3, $1);
2070                 }
2071 |       argument_list C_TK error
2072                 {yyerror ("Missing term"); RECOVER;}
2073 ;
2074
2075 array_creation_expression:
2076         NEW_TK primitive_type dim_exprs
2077                 { $$ = build_newarray_node ($2, $3, 0); }
2078 |       NEW_TK class_or_interface_type dim_exprs
2079                 { $$ = build_newarray_node ($2, $3, 0); }
2080 |       NEW_TK primitive_type dim_exprs dims
2081                 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2082 |       NEW_TK class_or_interface_type dim_exprs dims
2083                 { $$ = build_newarray_node ($2, $3, pop_current_osb (ctxp));}
2084         /* Added, JDK1.1 anonymous array. Initial documentation rule
2085            modified */
2086 |       NEW_TK class_or_interface_type dims array_initializer
2087                 {
2088                   char *sig;
2089                   int osb = pop_current_osb (ctxp);
2090                   while (osb--)
2091                     obstack_1grow (&temporary_obstack, '[');
2092                   sig = obstack_finish (&temporary_obstack);
2093                   $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE,
2094                               $2, get_identifier (sig), $4);
2095                 }
2096 |       NEW_TK primitive_type dims array_initializer
2097                 { 
2098                   int osb = pop_current_osb (ctxp);
2099                   tree type = $2;
2100                   while (osb--)
2101                     type = build_java_array_type (type, -1);
2102                   $$ = build (NEW_ANONYMOUS_ARRAY_EXPR, NULL_TREE, 
2103                               build_pointer_type (type), NULL_TREE, $4);
2104                 }
2105 |       NEW_TK error CSB_TK
2106                 {yyerror ("'[' expected"); DRECOVER ("]");}
2107 |       NEW_TK error OSB_TK
2108                 {yyerror ("']' expected"); RECOVER;}
2109 ;
2110
2111 dim_exprs:
2112         dim_expr
2113                 { $$ = build_tree_list (NULL_TREE, $1); }
2114 |       dim_exprs dim_expr
2115                 { $$ = tree_cons (NULL_TREE, $2, $$); }
2116 ;
2117
2118 dim_expr:
2119         OSB_TK expression CSB_TK
2120                 { 
2121                   if (JNUMERIC_TYPE_P (TREE_TYPE ($2)))
2122                     {
2123                       $2 = build_wfl_node ($2);
2124                       TREE_TYPE ($2) = NULL_TREE;
2125                     }
2126                   EXPR_WFL_LINECOL ($2) = $1.location;
2127                   $$ = $2;
2128                 }
2129 |       OSB_TK expression error
2130                 {yyerror ("']' expected"); RECOVER;}
2131 |       OSB_TK error
2132                 {
2133                   yyerror ("Missing term");
2134                   yyerror ("']' expected");
2135                   RECOVER;
2136                 }
2137 ;
2138
2139 dims:                           
2140         OSB_TK CSB_TK
2141                 { 
2142                   int allocate = 0;
2143                   /* If not initialized, allocate memory for the osb
2144                      numbers stack */
2145                   if (!ctxp->osb_limit)
2146                     {
2147                       allocate = ctxp->osb_limit = 32;
2148                       ctxp->osb_depth = -1;
2149                     }
2150                   /* If capacity overflown, reallocate a bigger chunk */
2151                   else if (ctxp->osb_depth+1 == ctxp->osb_limit)
2152                     allocate = ctxp->osb_limit << 1;
2153                   
2154                   if (allocate)
2155                     {
2156                       allocate *= sizeof (int);
2157                       if (ctxp->osb_number)
2158                         ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
2159                                                             allocate);
2160                       else
2161                         ctxp->osb_number = (int *)xmalloc (allocate);
2162                     }
2163                   ctxp->osb_depth++;
2164                   CURRENT_OSB (ctxp) = 1;
2165                 }
2166 |       dims OSB_TK CSB_TK
2167                 { CURRENT_OSB (ctxp)++; }
2168 |       dims OSB_TK error
2169                 { yyerror ("']' expected"); RECOVER;}
2170 ;
2171
2172 field_access:
2173         primary DOT_TK identifier
2174                 { $$ = make_qualified_primary ($1, $3, $2.location); }
2175                 /*  FIXME - REWRITE TO: 
2176                 { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
2177 |       SUPER_TK DOT_TK identifier
2178                 {
2179                   tree super_wfl = build_wfl_node (super_identifier_node);
2180                   EXPR_WFL_LINECOL (super_wfl) = $1.location;
2181                   $$ = make_qualified_name (super_wfl, $3, $2.location);
2182                 }
2183 |       SUPER_TK error
2184                 {yyerror ("Field expected"); DRECOVER (super_field_acces);}
2185 ;
2186
2187 method_invocation:
2188         name OP_TK CP_TK
2189                 { $$ = build_method_invocation ($1, NULL_TREE); }
2190 |       name OP_TK argument_list CP_TK
2191                 { $$ = build_method_invocation ($1, $3); }
2192 |       primary DOT_TK identifier OP_TK CP_TK
2193                 { 
2194                   if (TREE_CODE ($1) == THIS_EXPR)
2195                     $$ = build_this_super_qualified_invocation 
2196                       (1, $3, NULL_TREE, 0, $2.location);
2197                   else
2198                     {
2199                       tree invok = build_method_invocation ($3, NULL_TREE);
2200                       $$ = make_qualified_primary ($1, invok, $2.location);
2201                     }
2202                 }
2203 |       primary DOT_TK identifier OP_TK argument_list CP_TK
2204                 { 
2205                   if (TREE_CODE ($1) == THIS_EXPR)
2206                     $$ = build_this_super_qualified_invocation 
2207                       (1, $3, $5, 0, $2.location);
2208                   else
2209                     {
2210                       tree invok = build_method_invocation ($3, $5);
2211                       $$ = make_qualified_primary ($1, invok, $2.location);
2212                     }
2213                 }
2214 |       SUPER_TK DOT_TK identifier OP_TK CP_TK
2215                 { 
2216                   $$ = build_this_super_qualified_invocation 
2217                     (0, $3, NULL_TREE, $1.location, $2.location);
2218                 }
2219 |       SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
2220                 {
2221                   $$ = build_this_super_qualified_invocation 
2222                     (0, $3, $5, $1.location, $2.location);
2223                 }
2224         /* Screws up thing. I let it here until I'm convinced it can
2225            be removed. FIXME
2226 |       primary DOT_TK error
2227                 {yyerror ("'(' expected"); DRECOVER(bad);} */
2228 |       SUPER_TK DOT_TK error CP_TK
2229                 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2230 |       SUPER_TK DOT_TK error DOT_TK
2231                 { yyerror ("'(' expected"); DRECOVER (method_invocation); }
2232 ;
2233
2234 array_access:
2235         name OSB_TK expression CSB_TK
2236                 { $$ = build_array_ref ($2.location, $1, $3); }
2237 |       primary_no_new_array OSB_TK expression CSB_TK
2238                 { $$ = build_array_ref ($2.location, $1, $3); }
2239 |       name OSB_TK error
2240                 {
2241                   yyerror ("Missing term and ']' expected");
2242                   DRECOVER(array_access);
2243                 }
2244 |       name OSB_TK expression error
2245                 {
2246                   yyerror ("']' expected");
2247                   DRECOVER(array_access);
2248                 }
2249 |       primary_no_new_array OSB_TK error
2250                 {
2251                   yyerror ("Missing term and ']' expected");
2252                   DRECOVER(array_access);
2253                 }
2254 |       primary_no_new_array OSB_TK expression error
2255                 {
2256                   yyerror ("']' expected");
2257                   DRECOVER(array_access);
2258                 }
2259 ;
2260
2261 postfix_expression:
2262         primary
2263 |       name
2264 |       post_increment_expression
2265 |       post_decrement_expression
2266 ;
2267
2268 post_increment_expression:
2269         postfix_expression INCR_TK
2270                 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2271 ;
2272
2273 post_decrement_expression:
2274         postfix_expression DECR_TK
2275                 { $$ = build_incdec ($2.token, $2.location, $1, 1); }
2276 ;
2277
2278 unary_expression:
2279         pre_increment_expression
2280 |       pre_decrement_expression
2281 |       PLUS_TK unary_expression
2282                 {$$ = build_unaryop ($1.token, $1.location, $2); }
2283 |       MINUS_TK unary_expression
2284                 {$$ = build_unaryop ($1.token, $1.location, $2); }
2285 |       unary_expression_not_plus_minus
2286 |       PLUS_TK error
2287                 {yyerror ("Missing term"); RECOVER}
2288 |       MINUS_TK error
2289                 {yyerror ("Missing term"); RECOVER}
2290 ;
2291
2292 pre_increment_expression:
2293         INCR_TK unary_expression
2294                 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2295 |       INCR_TK error
2296                 {yyerror ("Missing term"); RECOVER}
2297 ;
2298
2299 pre_decrement_expression:
2300         DECR_TK unary_expression
2301                 {$$ = build_incdec ($1.token, $1.location, $2, 0); }
2302 |       DECR_TK error
2303                 {yyerror ("Missing term"); RECOVER}
2304 ;
2305
2306 unary_expression_not_plus_minus:
2307         postfix_expression
2308 |       NOT_TK unary_expression
2309                 {$$ = build_unaryop ($1.token, $1.location, $2); }
2310 |       NEG_TK unary_expression
2311                 {$$ = build_unaryop ($1.token, $1.location, $2); }
2312 |       cast_expression
2313 |       NOT_TK error
2314                 {yyerror ("Missing term"); RECOVER}
2315 |       NEG_TK error
2316                 {yyerror ("Missing term"); RECOVER}
2317 ;
2318
2319 cast_expression:                /* Error handling here is potentially weak */
2320         OP_TK primitive_type dims CP_TK unary_expression
2321                 { 
2322                   tree type = $2;
2323                   int osb = pop_current_osb (ctxp);
2324                   while (osb--)
2325                     type = build_java_array_type (type, -1);
2326                   $$ = build_cast ($1.location, type, $5); 
2327                 }
2328 |       OP_TK primitive_type CP_TK unary_expression
2329                 { $$ = build_cast ($1.location, $2, $4); }
2330 |       OP_TK expression CP_TK unary_expression_not_plus_minus
2331                 { $$ = build_cast ($1.location, $2, $4); }
2332 |       OP_TK name dims CP_TK unary_expression_not_plus_minus
2333                 { 
2334                   const char *ptr;
2335                   int osb = pop_current_osb (ctxp); 
2336                   while (osb--)
2337                     obstack_1grow (&temporary_obstack, '[');
2338                   obstack_grow0 (&temporary_obstack, 
2339                                  IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
2340                                  IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
2341                   ptr = obstack_finish (&temporary_obstack);
2342                   EXPR_WFL_NODE ($2) = get_identifier (ptr);
2343                   $$ = build_cast ($1.location, $2, $5);
2344                 }
2345 |       OP_TK primitive_type OSB_TK error
2346                 {yyerror ("']' expected, invalid type expression");}
2347 |       OP_TK error
2348                 {
2349                   YYNOT_TWICE yyerror ("Invalid type expression"); RECOVER;
2350                   RECOVER;
2351                 }
2352 |       OP_TK primitive_type dims CP_TK error
2353                 {yyerror ("Missing term"); RECOVER;}
2354 |       OP_TK primitive_type CP_TK error
2355                 {yyerror ("Missing term"); RECOVER;}
2356 |       OP_TK name dims CP_TK error
2357                 {yyerror ("Missing term"); RECOVER;}
2358 ;
2359
2360 multiplicative_expression:
2361         unary_expression
2362 |       multiplicative_expression MULT_TK unary_expression
2363                 { 
2364                   $$ = build_binop (BINOP_LOOKUP ($2.token), 
2365                                     $2.location, $1, $3);
2366                 }
2367 |       multiplicative_expression DIV_TK unary_expression
2368                 {
2369                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2370                                     $1, $3); 
2371                 }
2372 |       multiplicative_expression REM_TK unary_expression
2373                 {
2374                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2375                                     $1, $3); 
2376                 }
2377 |       multiplicative_expression MULT_TK error
2378                 {yyerror ("Missing term"); RECOVER;}
2379 |       multiplicative_expression DIV_TK error
2380                 {yyerror ("Missing term"); RECOVER;}
2381 |       multiplicative_expression REM_TK error
2382                 {yyerror ("Missing term"); RECOVER;}
2383 ;
2384
2385 additive_expression:
2386         multiplicative_expression
2387 |       additive_expression PLUS_TK multiplicative_expression
2388                 {
2389                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2390                                     $1, $3); 
2391                 }
2392 |       additive_expression MINUS_TK multiplicative_expression
2393                 {
2394                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2395                                     $1, $3); 
2396                 }
2397 |       additive_expression PLUS_TK error
2398                 {yyerror ("Missing term"); RECOVER;}
2399 |       additive_expression MINUS_TK error
2400                 {yyerror ("Missing term"); RECOVER;}
2401 ;
2402
2403 shift_expression:
2404         additive_expression
2405 |       shift_expression LS_TK additive_expression
2406                 {
2407                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2408                                     $1, $3); 
2409                 }
2410 |       shift_expression SRS_TK additive_expression
2411                 {
2412                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2413                                     $1, $3); 
2414                 }
2415 |       shift_expression ZRS_TK additive_expression
2416                 {
2417                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2418                                     $1, $3); 
2419                 }
2420 |       shift_expression LS_TK error
2421                 {yyerror ("Missing term"); RECOVER;}
2422 |       shift_expression SRS_TK error
2423                 {yyerror ("Missing term"); RECOVER;}
2424 |       shift_expression ZRS_TK error
2425                 {yyerror ("Missing term"); RECOVER;}
2426 ;
2427
2428 relational_expression:
2429         shift_expression
2430 |       relational_expression LT_TK shift_expression
2431                 {
2432                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2433                                     $1, $3); 
2434                 }
2435 |       relational_expression GT_TK shift_expression
2436                 {
2437                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2438                                     $1, $3); 
2439                 }
2440 |       relational_expression LTE_TK shift_expression
2441                 {
2442                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2443                                     $1, $3); 
2444                 }
2445 |       relational_expression GTE_TK shift_expression
2446                 {
2447                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2448                                     $1, $3); 
2449                 }
2450 |       relational_expression INSTANCEOF_TK reference_type
2451                 { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
2452 |       relational_expression LT_TK error
2453                 {yyerror ("Missing term"); RECOVER;}
2454 |       relational_expression GT_TK error
2455                 {yyerror ("Missing term"); RECOVER;}
2456 |       relational_expression LTE_TK error
2457                 {yyerror ("Missing term"); RECOVER;}
2458 |       relational_expression GTE_TK error
2459                 {yyerror ("Missing term"); RECOVER;}
2460 |       relational_expression INSTANCEOF_TK error
2461                 {yyerror ("Invalid reference type"); RECOVER;}
2462 ;
2463
2464 equality_expression:
2465         relational_expression
2466 |       equality_expression EQ_TK relational_expression
2467                 {
2468                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2469                                     $1, $3); 
2470                 }
2471 |       equality_expression NEQ_TK relational_expression
2472                 {
2473                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2474                                     $1, $3); 
2475                 }
2476 |       equality_expression EQ_TK error
2477                 {yyerror ("Missing term"); RECOVER;}
2478 |       equality_expression NEQ_TK error
2479                 {yyerror ("Missing term"); RECOVER;}
2480 ;
2481
2482 and_expression:
2483         equality_expression
2484 |       and_expression AND_TK equality_expression
2485                 {
2486                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2487                                     $1, $3); 
2488                 }
2489 |       and_expression AND_TK error
2490                 {yyerror ("Missing term"); RECOVER;}
2491 ;
2492
2493 exclusive_or_expression:
2494         and_expression
2495 |       exclusive_or_expression XOR_TK and_expression
2496                 {
2497                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2498                                     $1, $3); 
2499                 }
2500 |       exclusive_or_expression XOR_TK error
2501                 {yyerror ("Missing term"); RECOVER;}
2502 ;
2503
2504 inclusive_or_expression:
2505         exclusive_or_expression
2506 |       inclusive_or_expression OR_TK exclusive_or_expression
2507                 {
2508                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2509                                     $1, $3); 
2510                 }
2511 |       inclusive_or_expression OR_TK error
2512                 {yyerror ("Missing term"); RECOVER;}
2513 ;
2514
2515 conditional_and_expression:
2516         inclusive_or_expression
2517 |       conditional_and_expression BOOL_AND_TK inclusive_or_expression
2518                 {
2519                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2520                                     $1, $3); 
2521                 }
2522 |       conditional_and_expression BOOL_AND_TK error
2523                 {yyerror ("Missing term"); RECOVER;}
2524 ;
2525
2526 conditional_or_expression:
2527         conditional_and_expression
2528 |       conditional_or_expression BOOL_OR_TK conditional_and_expression
2529                 {
2530                   $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
2531                                     $1, $3); 
2532                 }
2533 |       conditional_or_expression BOOL_OR_TK error
2534                 {yyerror ("Missing term"); RECOVER;}
2535 ;
2536
2537 conditional_expression:         /* Error handling here is weak */
2538         conditional_or_expression
2539 |       conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
2540                 {
2541                   $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
2542                   EXPR_WFL_LINECOL ($$) = $2.location;
2543                 }
2544 |       conditional_or_expression REL_QM_TK REL_CL_TK error
2545                 {
2546                   YYERROR_NOW;
2547                   yyerror ("Missing term");
2548                   DRECOVER (1);
2549                 }
2550 |       conditional_or_expression REL_QM_TK error
2551                 {yyerror ("Missing term"); DRECOVER (2);}
2552 |       conditional_or_expression REL_QM_TK expression REL_CL_TK error
2553                 {yyerror ("Missing term"); DRECOVER (3);}
2554 ;
2555
2556 assignment_expression:
2557         conditional_expression
2558 |       assignment
2559 ;
2560
2561 assignment:
2562         left_hand_side assignment_operator assignment_expression
2563                 { $$ = build_assignment ($2.token, $2.location, $1, $3); }
2564 |       left_hand_side assignment_operator error
2565                 {
2566                   YYNOT_TWICE yyerror ("Missing term");
2567                   DRECOVER (assign);
2568                 }
2569 ;
2570
2571 left_hand_side:
2572         name
2573 |       field_access
2574 |       array_access
2575 ;
2576
2577 assignment_operator:
2578         ASSIGN_ANY_TK
2579 |       ASSIGN_TK
2580 ;
2581
2582 expression:
2583         assignment_expression
2584 ;
2585
2586 constant_expression:
2587         expression
2588 ;
2589
2590 %%
2591
2592 /* Helper function to retrieve an OSB count. Should be used when the
2593    `dims:' rule is being used.  */
2594
2595 static int
2596 pop_current_osb (ctxp)
2597      struct parser_ctxt *ctxp;
2598 {
2599   int to_return;
2600
2601   if (ctxp->osb_depth < 0)
2602     fatal ("osb stack underflow");
2603   
2604   to_return = CURRENT_OSB (ctxp);
2605   ctxp->osb_depth--;
2606   
2607   return to_return;
2608 }
2609
2610 \f
2611
2612 /* This section of the code deal with save/restoring parser contexts.
2613    Add mode documentation here. FIXME */
2614
2615 /* Helper function. Create a new parser context. With
2616    COPY_FROM_PREVIOUS set to a non zero value, content of the previous
2617    context is copied, otherwise, the new context is zeroed. The newly
2618    created context becomes the current one.  */
2619
2620 static void
2621 create_new_parser_context (copy_from_previous)
2622     int copy_from_previous;
2623 {
2624   struct parser_ctxt *new;
2625
2626   new =  (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
2627   if (copy_from_previous)
2628     {
2629       memcpy ((PTR)new, (PTR)ctxp, sizeof (struct parser_ctxt));
2630       new->saved_data_ctx = 1;
2631     }
2632   else
2633     memset ((PTR) new, 0, sizeof (struct parser_ctxt));
2634       
2635   new->next = ctxp;
2636   ctxp = new;
2637 }
2638
2639 /* Create a new parser context and make it the current one. */
2640
2641 void
2642 java_push_parser_context ()
2643 {
2644   create_new_parser_context (0);
2645   if (ctxp->next)
2646     {
2647       ctxp->incomplete_class = ctxp->next->incomplete_class;
2648       ctxp->gclass_list = ctxp->next->gclass_list;
2649     }
2650 }  
2651
2652 void 
2653 java_pop_parser_context (generate)
2654      int generate;
2655 {
2656   tree current;
2657   struct parser_ctxt *toFree, *next;
2658
2659   if (!ctxp)
2660     return;
2661
2662   toFree = ctxp;
2663   next = ctxp->next;
2664   if (next)
2665     {
2666       next->incomplete_class = ctxp->incomplete_class;
2667       next->gclass_list = ctxp->gclass_list;
2668       lineno = ctxp->lineno;
2669       current_class = ctxp->class_type;
2670     }
2671
2672   /* If the old and new lexers differ, then free the old one.  */
2673   if (ctxp->lexer && next && ctxp->lexer != next->lexer)
2674     java_destroy_lexer (ctxp->lexer);
2675
2676   /* Set the single import class file flag to 0 for the current list
2677      of imported things */
2678   for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2679     IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 0;
2680
2681   /* And restore those of the previous context */
2682   if ((ctxp = next))            /* Assignment is really meant here */
2683     for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
2684       IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
2685   
2686   /* If we pushed a context to parse a class intended to be generated,
2687      we keep it so we can remember the class. What we could actually
2688      do is to just update a list of class names.  */
2689   if (generate)
2690     {
2691       toFree->next = ctxp_for_generation;
2692       ctxp_for_generation = toFree;
2693     }
2694   else
2695     free (toFree);
2696 }
2697
2698 /* Create a parser context for the use of saving some global
2699    variables.  */
2700
2701 void
2702 java_parser_context_save_global ()
2703 {
2704   if (!ctxp)
2705     {
2706       java_push_parser_context ();
2707       ctxp->saved_data_ctx = 1;
2708     }
2709
2710   /* If this context already stores data, create a new one suitable
2711      for data storage. */
2712   else if (ctxp->saved_data)
2713     create_new_parser_context (1);
2714
2715   ctxp->lineno = lineno;
2716   ctxp->class_type = current_class;
2717   ctxp->filename = input_filename;
2718   ctxp->function_decl = current_function_decl;
2719   ctxp->saved_data = 1;
2720 }
2721
2722 /* Restore some global variables from the previous context. Make the
2723    previous context the current one.  */
2724
2725 void
2726 java_parser_context_restore_global ()
2727 {
2728   lineno = ctxp->lineno;
2729   current_class = ctxp->class_type;
2730   input_filename = ctxp->filename;
2731   if (wfl_operator)
2732     {
2733       tree s;
2734       BUILD_FILENAME_IDENTIFIER_NODE (s, input_filename);
2735       EXPR_WFL_FILENAME_NODE (wfl_operator) = s;
2736     }
2737   current_function_decl = ctxp->function_decl;
2738   ctxp->saved_data = 0;
2739   if (ctxp->saved_data_ctx)
2740     java_pop_parser_context (0);
2741 }
2742
2743 /* Suspend vital data for the current class/function being parsed so
2744    that an other class can be parsed. Used to let local/anonymous
2745    classes be parsed.  */
2746
2747 static void
2748 java_parser_context_suspend ()
2749 {
2750   /* This makes debugging through java_debug_context easier */
2751   static const char *name = "<inner buffer context>";
2752
2753   /* Duplicate the previous context, use it to save the globals we're
2754      interested in */
2755   create_new_parser_context (1);
2756   ctxp->function_decl = current_function_decl;
2757   ctxp->class_type = current_class;
2758
2759   /* Then create a new context which inherits all data from the
2760      previous one. This will be the new current context  */
2761   create_new_parser_context (1);
2762
2763   /* Help debugging */
2764   ctxp->next->filename = name;
2765 }
2766
2767 /* Resume vital data for the current class/function being parsed so
2768    that an other class can be parsed. Used to let local/anonymous
2769    classes be parsed.  The trick is the data storing file position
2770    informations must be restored to their current value, so parsing
2771    can resume as if no context was ever saved. */
2772
2773 static void
2774 java_parser_context_resume ()
2775 {
2776   struct parser_ctxt *old = ctxp;             /* This one is to be discarded */
2777   struct parser_ctxt *saver = old->next;      /* This one contain saved info */
2778   struct parser_ctxt *restored = saver->next; /* This one is the old current */
2779
2780   /* We need to inherit the list of classes to complete/generate */
2781   restored->incomplete_class = old->incomplete_class;
2782   restored->gclass_list = old->gclass_list;
2783   restored->classd_list = old->classd_list;
2784   restored->class_list = old->class_list;
2785
2786   /* Restore the current class and function from the saver */
2787   current_class = saver->class_type;
2788   current_function_decl = saver->function_decl;
2789
2790   /* Retrive the restored context */
2791   ctxp = restored;
2792
2793   /* Re-installed the data for the parsing to carry on */
2794   bcopy (&old->marker_begining, &ctxp->marker_begining,
2795          (size_t)(&ctxp->marker_end - &ctxp->marker_begining));
2796
2797   /* Buffer context can now be discarded */
2798   free (saver);
2799   free (old);
2800 }
2801
2802 /* Add a new anchor node to which all statement(s) initializing static
2803    and non static initialized upon declaration field(s) will be
2804    linked.  */
2805
2806 static void
2807 java_parser_context_push_initialized_field ()
2808 {
2809   tree node;
2810
2811   node = build_tree_list (NULL_TREE, NULL_TREE);
2812   TREE_CHAIN (node) = CPC_STATIC_INITIALIZER_LIST (ctxp);
2813   CPC_STATIC_INITIALIZER_LIST (ctxp) = node;
2814
2815   node = build_tree_list (NULL_TREE, NULL_TREE);
2816   TREE_CHAIN (node) = CPC_INITIALIZER_LIST (ctxp);
2817   CPC_INITIALIZER_LIST (ctxp) = node;
2818
2819   node = build_tree_list (NULL_TREE, NULL_TREE);
2820   TREE_CHAIN (node) = CPC_INSTANCE_INITIALIZER_LIST (ctxp);
2821   CPC_INSTANCE_INITIALIZER_LIST (ctxp) = node;
2822 }
2823
2824 /* Pop the lists of initialized field. If this lists aren't empty,
2825    remember them so we can use it to create and populate the finit$
2826    or <clinit> functions. */
2827
2828 static void
2829 java_parser_context_pop_initialized_field ()
2830 {
2831   tree stmts;
2832   tree class_type = TREE_TYPE (GET_CPC ());
2833
2834   if (CPC_INITIALIZER_LIST (ctxp))
2835     {
2836       stmts = CPC_INITIALIZER_STMT (ctxp);
2837       CPC_INITIALIZER_LIST (ctxp) = TREE_CHAIN (CPC_INITIALIZER_LIST (ctxp));
2838       if (stmts && !java_error_count)
2839         TYPE_FINIT_STMT_LIST (class_type) = reorder_static_initialized (stmts);
2840     }
2841
2842   if (CPC_STATIC_INITIALIZER_LIST (ctxp))
2843     {
2844       stmts = CPC_STATIC_INITIALIZER_STMT (ctxp);
2845       CPC_STATIC_INITIALIZER_LIST (ctxp) = 
2846         TREE_CHAIN (CPC_STATIC_INITIALIZER_LIST (ctxp));
2847       /* Keep initialization in order to enforce 8.5 */
2848       if (stmts && !java_error_count)
2849         TYPE_CLINIT_STMT_LIST (class_type) = nreverse (stmts);
2850     }
2851
2852   /* JDK 1.1 instance initializers */
2853   if (CPC_INSTANCE_INITIALIZER_LIST (ctxp))
2854     {
2855       stmts = CPC_INSTANCE_INITIALIZER_STMT (ctxp);
2856       CPC_INSTANCE_INITIALIZER_LIST (ctxp) = 
2857         TREE_CHAIN (CPC_INSTANCE_INITIALIZER_LIST (ctxp));
2858       if (stmts && !java_error_count)
2859         TYPE_II_STMT_LIST (class_type) = nreverse (stmts);
2860     }
2861 }
2862
2863 static tree
2864 reorder_static_initialized (list)
2865      tree list;
2866 {
2867   /* We have to keep things in order. The alias initializer have to
2868      come first, then the initialized regular field, in reverse to
2869      keep them in lexical order. */
2870   tree marker, previous = NULL_TREE;
2871   for (marker = list; marker; previous = marker, marker = TREE_CHAIN (marker))
2872     if (TREE_CODE (marker) == TREE_LIST 
2873         && !TREE_VALUE (marker) && !TREE_PURPOSE (marker))
2874       break;
2875   
2876   /* No static initialized, the list is fine as is */
2877   if (!previous)
2878     list = TREE_CHAIN (marker);
2879
2880   /* No marker? reverse the whole list */
2881   else if (!marker)
2882     list = nreverse (list);
2883
2884   /* Otherwise, reverse what's after the marker and the new reordered
2885      sublist will replace the marker. */
2886   else
2887     {
2888       TREE_CHAIN (previous) = NULL_TREE;
2889       list = nreverse (list);
2890       list = chainon (TREE_CHAIN (marker), list);
2891     }
2892   return list;
2893 }
2894
2895 /* Helper functions to dump the parser context stack.  */
2896
2897 #define TAB_CONTEXT(C) \
2898   {int i; for (i = 0; i < (C); i++) fputc (' ', stderr);}
2899
2900 static void
2901 java_debug_context_do (tab)
2902      int tab;
2903 {
2904   struct parser_ctxt *copy = ctxp;
2905   while (copy)
2906     {
2907       TAB_CONTEXT (tab);
2908       fprintf (stderr, "ctxt: 0x%0lX\n", (unsigned long)copy);
2909       TAB_CONTEXT (tab);
2910       fprintf (stderr, "filename: %s\n", copy->filename);
2911       TAB_CONTEXT (tab);
2912       fprintf (stderr, "lineno: %d\n", copy->lineno);
2913       TAB_CONTEXT (tab);
2914       fprintf (stderr, "package: %s\n",
2915                (copy->package ? 
2916                 IDENTIFIER_POINTER (copy->package) : "<none>"));
2917       TAB_CONTEXT (tab);
2918       fprintf (stderr, "context for saving: %d\n", copy->saved_data_ctx);
2919       TAB_CONTEXT (tab);
2920       fprintf (stderr, "saved data: %d\n", copy->saved_data);
2921       copy = copy->next;
2922       tab += 2;
2923     }
2924 }
2925
2926 /* Dump the stacked up parser contexts. Intended to be called from a
2927    debugger.  */
2928
2929 void
2930 java_debug_context ()
2931 {
2932   java_debug_context_do (0);
2933 }
2934
2935 \f
2936
2937 /* Flag for the error report routine to issue the error the first time
2938    it's called (overriding the default behavior which is to drop the
2939    first invocation and honor the second one, taking advantage of a
2940    richer context.  */
2941 static int force_error = 0;
2942
2943 /* Reporting an constructor invocation error.  */
2944 static void
2945 parse_ctor_invocation_error ()
2946 {
2947   if (DECL_CONSTRUCTOR_P (current_function_decl))
2948     yyerror ("Constructor invocation must be first thing in a constructor"); 
2949   else
2950     yyerror ("Only constructors can invoke constructors");
2951 }
2952
2953 /* Reporting JDK1.1 features not implemented.  */
2954
2955 static tree
2956 parse_jdk1_1_error (msg)
2957     const char *msg;
2958 {
2959   sorry (": `%s' JDK1.1(TM) feature", msg);
2960   java_error_count++;
2961   return empty_stmt_node;
2962 }
2963
2964 static int do_warning = 0;
2965
2966 void
2967 yyerror (msg)
2968      const char *msg;
2969 {
2970   static java_lc elc;
2971   static int  prev_lineno;
2972   static const char *prev_msg;
2973
2974   int save_lineno;
2975   char *remainder, *code_from_source;
2976   extern struct obstack temporary_obstack;
2977   
2978   if (!force_error && prev_lineno == lineno)
2979     return;
2980
2981   /* Save current error location but report latter, when the context is
2982      richer.  */
2983   if (ctxp->java_error_flag == 0)
2984     {
2985       ctxp->java_error_flag = 1;
2986       elc = ctxp->elc;
2987       /* Do something to use the previous line if we're reaching the
2988          end of the file... */
2989 #ifdef VERBOSE_SKELETON
2990       printf ("* Error detected (%s)\n", (msg ? msg : "(null)"));
2991 #endif
2992       return;
2993     }
2994
2995   /* Ignore duplicate message on the same line. BTW, this is dubious. FIXME */
2996   if (!force_error && msg == prev_msg && prev_lineno == elc.line)
2997     return;
2998
2999   ctxp->java_error_flag = 0;
3000   if (do_warning)
3001     java_warning_count++;
3002   else
3003     java_error_count++;
3004   
3005   if (elc.col == 0 && msg && msg[1] == ';')
3006     {
3007       elc.col  = ctxp->p_line->char_col-1;
3008       elc.line = ctxp->p_line->lineno;
3009     }
3010
3011   save_lineno = lineno;
3012   prev_lineno = lineno = elc.line;
3013   prev_msg = msg;
3014
3015   code_from_source = java_get_line_col (ctxp->filename, elc.line, elc.col);
3016   obstack_grow0 (&temporary_obstack, 
3017                  code_from_source, strlen (code_from_source));
3018   remainder = obstack_finish (&temporary_obstack);
3019   if (do_warning)
3020     warning ("%s.\n%s", msg, remainder);
3021   else
3022     error ("%s.\n%s", msg, remainder);
3023
3024   /* This allow us to cheaply avoid an extra 'Invalid expression
3025      statement' error report when errors have been already reported on
3026      the same line. This occurs when we report an error but don't have
3027      a synchronization point other than ';', which
3028      expression_statement is the only one to take care of.  */
3029   ctxp->prevent_ese = lineno = save_lineno;
3030 }
3031
3032 static void
3033 issue_warning_error_from_context (cl, msg, ap)
3034      tree cl;
3035      const char *msg;
3036      va_list ap;
3037 {
3038   const char *saved, *saved_input_filename;
3039   char buffer [4096];
3040   vsprintf (buffer, msg, ap);
3041   force_error = 1;
3042
3043   ctxp->elc.line = EXPR_WFL_LINENO (cl);
3044   ctxp->elc.col  = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 : 
3045                     (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
3046
3047   /* We have a CL, that's a good reason for using it if it contains data */
3048   saved = ctxp->filename;
3049   if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
3050     ctxp->filename = EXPR_WFL_FILENAME (cl);
3051   saved_input_filename = input_filename;
3052   input_filename = ctxp->filename;
3053   java_error (NULL);
3054   java_error (buffer);
3055   ctxp->filename = saved;
3056   input_filename = saved_input_filename;
3057   force_error = 0;
3058 }
3059
3060 /* Issue an error message at a current source line CL */
3061
3062 void
3063 parse_error_context VPARAMS ((tree cl, const char *msg, ...))
3064 {
3065 #ifndef ANSI_PROTOTYPES
3066   tree cl;
3067   const char *msg;
3068 #endif
3069   va_list ap;
3070
3071   VA_START (ap, msg);
3072 #ifndef ANSI_PROTOTYPES
3073   cl = va_arg (ap, tree);
3074   msg = va_arg (ap, const char *);
3075 #endif
3076   issue_warning_error_from_context (cl, msg, ap);
3077   va_end (ap);
3078 }
3079
3080 /* Issue a warning at a current source line CL */
3081
3082 static void
3083 parse_warning_context VPARAMS ((tree cl, const char *msg, ...))
3084 {
3085 #ifndef ANSI_PROTOTYPES
3086   tree cl;
3087   const char *msg;
3088 #endif
3089   va_list ap;
3090
3091   VA_START (ap, msg);
3092 #ifndef ANSI_PROTOTYPES
3093   cl = va_arg (ap, tree);
3094   msg = va_arg (ap, const char *);
3095 #endif
3096
3097   force_error = do_warning = 1;
3098   issue_warning_error_from_context (cl, msg, ap);
3099   do_warning = force_error = 0;
3100   va_end (ap);
3101 }
3102
3103 static tree
3104 find_expr_with_wfl (node)
3105      tree node;
3106 {
3107   while (node)
3108     {
3109       char code;
3110       tree to_return;
3111
3112       switch (TREE_CODE (node))
3113         {
3114         case BLOCK:
3115           node = BLOCK_EXPR_BODY (node);
3116           continue;
3117
3118         case COMPOUND_EXPR:
3119           to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
3120           if (to_return)
3121             return to_return;
3122           node = TREE_OPERAND (node, 1);
3123           continue;
3124
3125         case LOOP_EXPR:
3126           node = TREE_OPERAND (node, 0);
3127           continue;
3128           
3129         case LABELED_BLOCK_EXPR:
3130           node = TREE_OPERAND (node, 1);
3131           continue;
3132
3133         default:
3134           code = TREE_CODE_CLASS (TREE_CODE (node));
3135           if (((code == '1') || (code == '2') || (code == 'e'))
3136               && EXPR_WFL_LINECOL (node))
3137             return node;
3138           return NULL_TREE;
3139         }
3140     }
3141   return NULL_TREE;
3142 }
3143
3144 /* Issue a missing return statement error. Uses METHOD to figure the
3145    last line of the method the error occurs in.  */
3146
3147 static void
3148 missing_return_error (method)
3149      tree method;
3150 {
3151   EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
3152   parse_error_context (wfl_operator, "Missing return statement");
3153 }
3154
3155 /* Issue an unreachable statement error. From NODE, find the next
3156    statement to report appropriately.  */
3157 static void
3158 unreachable_stmt_error (node)
3159      tree node;
3160 {
3161   /* Browse node to find the next expression node that has a WFL. Use
3162      the location to report the error */
3163   if (TREE_CODE (node) == COMPOUND_EXPR)
3164     node = find_expr_with_wfl (TREE_OPERAND (node, 1));
3165   else
3166     node = find_expr_with_wfl (node);
3167
3168   if (node)
3169     {
3170       EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
3171       parse_error_context (wfl_operator, "Unreachable statement");
3172     }
3173   else
3174     fatal ("Can't get valid statement - unreachable_stmt_error");
3175 }
3176
3177 int
3178 java_report_errors ()
3179 {
3180   if (java_error_count)
3181     fprintf (stderr, "%d error%s", 
3182              java_error_count, (java_error_count == 1 ? "" : "s"));
3183   if (java_warning_count)
3184     fprintf (stderr, "%s%d warning%s", (java_error_count ? ", " : ""),
3185              java_warning_count, (java_warning_count == 1 ? "" : "s"));
3186   if (java_error_count || java_warning_count)
3187     putc ('\n', stderr);
3188   return java_error_count;
3189 }
3190
3191 static char *
3192 java_accstring_lookup (flags)
3193      int flags;
3194 {
3195   static char buffer [80];
3196 #define COPY_RETURN(S) {strcpy (buffer, S); return buffer;}
3197
3198   /* Access modifier looked-up first for easier report on forbidden
3199      access. */
3200   if (flags & ACC_PUBLIC) COPY_RETURN ("public");
3201   if (flags & ACC_PRIVATE) COPY_RETURN ("private");
3202   if (flags & ACC_PROTECTED) COPY_RETURN ("protected");
3203   if (flags & ACC_STATIC) COPY_RETURN ("static");
3204   if (flags & ACC_FINAL) COPY_RETURN ("final");
3205   if (flags & ACC_SYNCHRONIZED) COPY_RETURN ("synchronized");
3206   if (flags & ACC_VOLATILE) COPY_RETURN ("volatile");
3207   if (flags & ACC_TRANSIENT) COPY_RETURN ("transient");
3208   if (flags & ACC_NATIVE) COPY_RETURN ("native");
3209   if (flags & ACC_INTERFACE) COPY_RETURN ("interface");
3210   if (flags & ACC_ABSTRACT) COPY_RETURN ("abstract");
3211
3212   buffer [0] = '\0';
3213   return buffer;
3214 #undef COPY_RETURN
3215 }
3216
3217 /* Issuing error messages upon redefinition of classes, interfaces or
3218    variables. */
3219
3220 static void
3221 classitf_redefinition_error (context, id, decl, cl)
3222      const char *context;
3223      tree id, decl, cl;
3224 {
3225   parse_error_context (cl, "%s `%s' already defined in %s:%d", 
3226                        context, IDENTIFIER_POINTER (id), 
3227                        DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3228   /* Here we should point out where its redefined. It's a unicode. FIXME */
3229 }
3230
3231 static void
3232 variable_redefinition_error (context, name, type, line)
3233      tree context, name, type;
3234      int line;
3235 {
3236   const char *type_name;
3237
3238   /* Figure a proper name for type. We might haven't resolved it */
3239   if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
3240     type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
3241   else
3242     type_name = lang_printable_name (type, 0);
3243
3244   parse_error_context (context,
3245                        "Variable `%s' is already defined in this method and was declared `%s %s' at line %d", 
3246                        IDENTIFIER_POINTER (name),
3247                        type_name, IDENTIFIER_POINTER (name), line);
3248 }
3249
3250 static tree
3251 build_array_from_name (type, type_wfl, name, ret_name)
3252      tree type, type_wfl, name, *ret_name;
3253 {
3254   int more_dims = 0;
3255   const char *string;
3256
3257   /* Eventually get more dims */
3258   string = IDENTIFIER_POINTER (name);
3259   while (string [more_dims] == '[')
3260     more_dims++;
3261   
3262   /* If we have, then craft a new type for this variable */
3263   if (more_dims)
3264     {
3265       name = get_identifier (&string [more_dims]);
3266
3267       /* If we have a pointer, use its type */
3268       if (TREE_CODE (type) == POINTER_TYPE)
3269         type = TREE_TYPE (type);
3270
3271       /* Building the first dimension of a primitive type uses this
3272          function */
3273       if (JPRIMITIVE_TYPE_P (type))
3274         {
3275           type = build_java_array_type (type, -1);
3276           CLASS_LOADED_P (type) = 1;
3277           more_dims--;
3278         }
3279       /* Otherwise, if we have a WFL for this type, use it (the type
3280          is already an array on an unresolved type, and we just keep
3281          on adding dimensions) */
3282       else if (type_wfl)
3283         type = type_wfl;
3284
3285       /* Add all the dimensions */
3286       while (more_dims--)
3287         type = build_unresolved_array_type (type);
3288
3289       /* The type may have been incomplete in the first place */
3290       if (type_wfl)
3291         type = obtain_incomplete_type (type);
3292     }
3293
3294   if (ret_name)
3295     *ret_name = name;
3296   return type;
3297 }
3298
3299 /* Build something that the type identifier resolver will identify as
3300    being an array to an unresolved type. TYPE_WFL is a WFL on a
3301    identifier. */
3302
3303 static tree
3304 build_unresolved_array_type (type_or_wfl)
3305      tree type_or_wfl;
3306 {
3307   const char *ptr;
3308
3309   /* TYPE_OR_WFL might be an array on a resolved type. In this case,
3310      just create a array type */
3311   if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
3312     {
3313       tree type = build_java_array_type (type_or_wfl, -1);
3314       CLASS_LOADED_P (type) = CLASS_LOADED_P (type_or_wfl);
3315       return type;
3316     }
3317
3318   obstack_1grow (&temporary_obstack, '[');
3319   obstack_grow0 (&temporary_obstack,
3320                  IDENTIFIER_POINTER (EXPR_WFL_NODE (type_or_wfl)),
3321                  IDENTIFIER_LENGTH (EXPR_WFL_NODE (type_or_wfl)));
3322   ptr = obstack_finish (&temporary_obstack);
3323   EXPR_WFL_NODE (type_or_wfl) = get_identifier (ptr);
3324   return type_or_wfl;
3325 }
3326
3327 static void
3328 parser_add_interface (class_decl, interface_decl, wfl)
3329      tree class_decl, interface_decl, wfl;
3330 {
3331   if (maybe_add_interface (TREE_TYPE (class_decl), TREE_TYPE (interface_decl)))
3332     parse_error_context (wfl, "Interface `%s' repeated",
3333                          IDENTIFIER_POINTER (DECL_NAME (interface_decl)));
3334 }
3335
3336 /* Bulk of common class/interface checks. Return 1 if an error was
3337    encountered. TAG is 0 for a class, 1 for an interface.  */
3338
3339 static int
3340 check_class_interface_creation (is_interface, flags, raw_name, qualified_name, decl, cl)
3341      int is_interface, flags;
3342      tree raw_name, qualified_name, decl, cl;
3343 {
3344   tree node;
3345   int sca = 0;                  /* Static class allowed */
3346   int icaf = 0;                 /* Inner class allowed flags */
3347   int uaaf = CLASS_MODIFIERS;   /* Usually allowed access flags */
3348
3349   if (!quiet_flag)
3350     fprintf (stderr, " %s%s %s", 
3351              (CPC_INNER_P () ? "inner" : ""),
3352              (is_interface ? "interface" : "class"), 
3353              IDENTIFIER_POINTER (qualified_name));
3354
3355   /* Scope of an interface/class type name:
3356        - Can't be imported by a single type import
3357        - Can't already exists in the package */
3358   if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (raw_name)
3359       && (node = find_name_in_single_imports (raw_name))
3360       && !CPC_INNER_P ())
3361     {