OSDN Git Service

Tue Oct 13 03:50:28 1998 Alexandre Petit-Bianco <apbianco@cygnus.com>
[pf3gnuchains/gcc-fork.git] / gcc / java / parse.h
1 /* Language parser definitions for the GNU compiler for the Java(TM) language.
2    Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
21
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc.  */
25
26 #ifndef JV_LANG_H
27 #define JV_LANG_H
28
29 #include "lex.h"
30
31 /* Extern global variable declarations */
32 extern int java_error_count;
33 extern struct obstack temporary_obstack;
34 extern struct obstack permanent_obstack;
35 extern int quiet_flag;
36
37 #ifndef JC1_LITE
38 /* Function extern to java/ */
39 extern int int_fits_type_p PROTO ((tree, tree));
40 extern tree stabilize_reference PROTO ((tree));
41 #endif
42
43 /* Macros for verbose debug info  */
44 #ifdef  VERBOSE_SKELETON
45 #define RULE( rule ) printf ( "jv_yacc:%d: rule %s\n", lineno, rule )
46 #else
47 #define RULE( rule )
48 #endif
49
50 #ifdef SOURCE_FRONTEND_DEBUG
51 #undef SOURCE_FRONTEND_DEBUG
52 #define SOURCE_FRONTEND_DEBUG(X)                                \
53   {if (!quiet_flag) {printf ("* "); printf X; putchar ('\n');} }
54 #else
55 #define SOURCE_FRONTEND_DEBUG(X)
56 #endif
57
58 /* Macro for error recovering  */
59 #ifdef YYDEBUG
60 #define RECOVERED                                       \
61   { if (!quiet_flag) {printf ("** Recovered\n");} }
62 #define DRECOVERED(s)                                           \
63   { if (!quiet_flag) {printf ("** Recovered (%s)\n", #s);}}
64 #else
65 #define RECOVERED
66 #define DRECOVERED(s)
67 #endif
68
69 #define DRECOVER(s) {yyerrok; DRECOVERED(s)}
70 #define RECOVER     {yyerrok; RECOVERED}
71
72 #define YYERROR_NOW ctxp->java_error_flag = 1
73 #define YYNOT_TWICE if (ctxp->prevent_ese != lineno)
74
75 /* Accepted modifiers */
76 #define CLASS_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_FINAL
77 #define FIELD_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_FINAL| \
78                         ACC_STATIC|ACC_TRANSIENT|ACC_VOLATILE
79 #define METHOD_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_ABSTRACT| \
80                          ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE
81 #define INTERFACE_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
82 #define INTERFACE_METHOD_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
83 #define INTERFACE_FIELD_MODIFIERS ACC_PUBLIC|ACC_STATIC|ACC_FINAL
84
85 /* Getting a modifier WFL */
86 #define MODIFIER_WFL(M)   (ctxp->modifier_ctx [(M) - PUBLIC_TK])
87
88 /* Check on modifiers */
89 #define THIS_MODIFIER_ONLY(f, m, v, count, l)                           \
90   if ((f) & (m))                                                        \
91     {                                                                   \
92       tree node = ctxp->modifier_ctx [v];                               \
93       if ((l)                                                           \
94           && ((EXPR_WFL_COLNO (node) > EXPR_WFL_COLNO (l))              \
95               || (EXPR_WFL_LINENO (node) > EXPR_WFL_LINENO (l))))       \
96         l = node;                                                       \
97       else if (!(l))                                                    \
98         l = node;                                                       \
99       count++;                                                          \
100     }
101
102 #define ABSTRACT_CHECK(flag, v, cl, s)                          \
103   if ((flag) & (v))                                             \
104     parse_error_context (cl, s " method can't be abstract");
105
106 /* Misc. */
107 #define exit_java_complete_class()              \
108   {                                             \
109     pop_obstacks ();                            \
110     return;                                     \
111   }
112
113 #define CLASS_OR_INTERFACE(decl, s1, s2)                        \
114    (decl ?                                                      \
115     ((get_access_flags_from_decl (TYPE_NAME (TREE_TYPE (decl))) \
116       & ACC_INTERFACE) ?                                        \
117      s2 : s1) : ((s1 [0]=='S'|| s1 [0]=='s') ?                  \
118                  (s1 [0]=='S' ? "Supertype" : "supertype") :    \
119                  (s1 [0] > 'A' ? "Type" : "type")))
120
121 /* Pedantic warning on obsolete modifiers. Note: when cl is NULL,
122    flags was set artificially, such as for a interface method */
123 #define OBSOLETE_MODIFIER_WARNING(cl, flags, modifier, format, arg)          \
124   {                                                                          \
125     if ((cl) && ((flags) & (modifier)))                                      \
126       parse_warning_context (cl,                                             \
127                              "Discouraged redundant use of `%s' modifier "   \
128                              "in declaration of " format,                    \
129                              java_accstring_lookup (modifier), arg);         \
130   }
131
132 /* Quickly build a temporary pointer on hypothetical type NAME. */
133 #define BUILD_PTR_FROM_NAME(ptr, name)          \
134   {                                             \
135     ptr = build (POINTER_TYPE, NULL_TREE);      \
136     TYPE_NAME (ptr) = name;                     \
137   }
138
139 #define INCOMPLETE_TYPE_P(NODE)                                 \
140   ((TREE_CODE (NODE) == TREE_LIST)                              \
141    && (TREE_CODE (TREE_PURPOSE (NODE)) == POINTER_TYPE)         \
142    && (TREE_TYPE (TREE_PURPOSE (NODE)) == NULL_TREE))
143
144 /* Set the EMIT_LINE_NOTE flag of a EXPR_WLF to 1 if debug information
145    are requested. Works in the context of a parser rule. */
146 #define JAVA_MAYBE_GENERATE_DEBUG_INFO(node)            \
147   (debug_info_level != DINFO_LEVEL_NONE ?               \
148     EXPR_WFL_EMIT_LINE_NOTE (node) = 1, node : node)
149
150 /* Types classification, according to the JLS, section 4.2 */
151 #define JFLOAT_TYPE_P(TYPE)      (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
152 #define JINTEGRAL_TYPE_P(TYPE)   ((TYPE)                                   \
153                                   && (TREE_CODE ((TYPE)) == INTEGER_TYPE   \
154                                       || TREE_CODE ((TYPE)) == CHAR_TYPE))
155 #define JNUMERIC_TYPE_P(TYPE)    ((TYPE)                                \
156                                   && (JFLOAT_TYPE_P ((TYPE))            \
157                                       || JINTEGRAL_TYPE_P ((TYPE))))
158 #define JPRIMITIVE_TYPE_P(TYPE)  ((TYPE)                                  \
159                                   && (JNUMERIC_TYPE_P ((TYPE))            \
160                                   || TREE_CODE ((TYPE)) == BOOLEAN_TYPE))
161
162 /* Not defined in the LRM */
163 #define JSTRING_TYPE_P(TYPE) ((TYPE)                                       \
164                               && ((TYPE) == string_type_node ||            \
165                                   (TREE_CODE (TYPE) == POINTER_TYPE &&     \
166                                    TREE_TYPE (TYPE) == string_type_node)))
167 #define JSTRING_P(NODE) ((NODE)                                         \
168                          && (TREE_CODE (NODE) == STRING_CST             \
169                              || IS_CRAFTED_STRING_BUFFER_P (NODE)       \
170                              || JSTRING_TYPE_P (TREE_TYPE (NODE))))
171
172 #define JREFERENCE_TYPE_P(TYPE) ((TYPE)                                       \
173                                  && (TREE_CODE (TYPE) == RECORD_TYPE          \
174                                      || (TREE_CODE (TYPE) == POINTER_TYPE     \
175                                          &&  TREE_CODE (TREE_TYPE (TYPE)) ==  \
176                                          RECORD_TYPE)))
177
178 /* Other predicate */
179 #define DECL_P(NODE) (NODE && (TREE_CODE (NODE) == PARM_DECL            \
180                                || TREE_CODE (NODE) == VAR_DECL          \
181                                || TREE_CODE (NODE) == FIELD_DECL))
182
183 #define TYPE_INTERFACE_P(TYPE)                                  \
184   (CLASS_P (TYPE) && CLASS_INTERFACE (TYPE_NAME (TYPE)))
185
186 #define TYPE_CLASS_P(TYPE) (CLASS_P (TYPE)                              \
187                             && !CLASS_INTERFACE (TYPE_NAME (TYPE))      \
188                             && !TYPE_ARRAY_P (TYPE))
189
190 /* Standard error messages */
191 #define ERROR_CANT_CONVERT_TO_BOOLEAN(OPERATOR, NODE, TYPE)             \
192   parse_error_context                                                   \
193     ((OPERATOR), "Incompatible type for `%s'. Can't convert `%s' to "   \
194      "boolean", operator_string ((NODE)), lang_printable_name ((TYPE)))
195
196 #define ERROR_CANT_CONVERT_TO_NUMERIC(OPERATOR, NODE, TYPE)             \
197   parse_error_context                                                   \
198     ((OPERATOR), "Incompatible type for `%s'. Can't convert `%s' to "   \
199      "numeric type", operator_string ((NODE)), lang_printable_name ((TYPE)))
200
201 #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE)             \
202   parse_error_context                                                   \
203     ((OPERATOR), (JPRIMITIVE_TYPE_P (TYPE) ?                            \
204      "Incompatible type for `%s'. Explicit cast needed to convert "     \
205       "`%s' to integral" : "Incompatible type for `%s'. Can't convert " \
206       "`%s' to integral"), operator_string ((NODE)),                    \
207       lang_printable_name ((TYPE)))
208
209 #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V)                  \
210   parse_error_context                                           \
211     ((WFL), "Variable `%s' may not have been initialized",      \
212      IDENTIFIER_POINTER (V))
213
214 /* Definition for loop handling. This is Java's own definition of a
215    loop body. See parse.y for documentation. It's valid once you hold
216    a loop's body (LOOP_EXPR_BODY) */
217
218 /* The loop main block is the one hold the condition and the loop body */
219 #define LOOP_EXPR_BODY_MAIN_BLOCK(NODE) TREE_OPERAND (NODE, 0)
220 /* And then there is the loop update block */
221 #define LOOP_EXPR_BODY_UPDATE_BLOCK(NODE) TREE_OPERAND (NODE, 1)
222
223 /* Inside the loop main block, there is the loop condition and the
224    loop body. They may be reversed if the loop being described is a
225    do-while loop. NOTE: if you use a WFL around the EXIT_EXPR so you
226    can issue debug info for it, the EXIT_EXPR will be one operand
227    further. */
228 #define LOOP_EXPR_BODY_CONDITION_EXPR(NODE, R)                  \
229   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 1 : 0))
230
231 /* Here is the labeled block the loop real body is encapsulated in */
232 #define LOOP_EXPR_BODY_LABELED_BODY(NODE, R)                    \
233   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 0 : 1))
234 /* And here is the loop's real body */
235 #define LOOP_EXPR_BODY_BODY_EXPR(NODE, R)                       \
236   LABELED_BLOCK_BODY (LOOP_EXPR_BODY_LABELED_BODY(NODE, R))
237
238 /* Does a loop have a label ? */
239 #define LOOP_HAS_LABEL_P(LOOP)                                  \
240   (ctxp->current_labeled_block                                  \
241    && LABELED_BLOCK_BODY (ctxp->current_labeled_block) == (LOOP))
242
243 /* Same operation than the one performed above, but considering the
244    previous labeled block */
245 #define LOOP_HAS_LABEL_SKIP_P(LOOP)                                          \
246   (ctxp->current_labeled_block                                               \
247    && TREE_CHAIN (ctxp->current_labeled_block)                               \
248    && LABELED_BLOCK_BODY (TREE_CHAIN (ctxp->current_labeled_block)) == (LOOP))
249
250 #define PUSH_LABELED_BLOCK(B)                           \
251   {                                                     \
252     TREE_CHAIN (B) = ctxp->current_labeled_block;       \
253     ctxp->current_labeled_block = (B);                  \
254   }
255 #define POP_LABELED_BLOCK()                                             \
256   ctxp->current_labeled_block = TREE_CHAIN (ctxp->current_labeled_block)
257
258 #define PUSH_LOOP(L)                            \
259   {                                             \
260     TREE_CHAIN (L) = ctxp->current_loop;        \
261     ctxp->current_loop = (L);                   \
262   }
263 #define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
264
265 #define PUSH_EXCEPTIONS(E)                                      \
266   currently_caught_type_list =                                  \
267     tree_cons (NULL_TREE, (E), currently_caught_type_list);
268
269 #define POP_EXCEPTIONS()                                                \
270   currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
271
272 /* Check that we're inside a try block */
273 #define IN_TRY_BLOCK_P()                                \
274   (currently_caught_type_list                           \
275    && ((TREE_VALUE (currently_caught_type_list) !=      \
276         DECL_FUNCTION_THROWS (current_function_decl))   \
277        || TREE_CHAIN (currently_caught_type_list)))
278
279 /* Check that we have exceptions in E */
280 #define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
281
282
283 /* Invocation modes, as returned by invocation_mode (). */
284 enum {
285   INVOKE_STATIC,
286   INVOKE_NONVIRTUAL,
287   INVOKE_SUPER,
288   INVOKE_INTERFACE,
289   INVOKE_VIRTUAL,
290 };
291
292 /* We need the resolution stuff only if we compile jc1 */
293 #ifndef JC1_LITE
294
295 /* Unresolved type identifiers handling. When we process the source
296    code, we blindly accept an unknown type identifier and try to
297    resolve it later. When an unknown type identifier is encountered
298    and used, we record in a struct jdep element what the incomplete
299    type is and what it should patch. Later, java_complete_class will
300    process all classes known to have unresolved type
301    dependencies. Within each of these classes, this routine will
302    process unresolved type dependencies (JDEP_TO_RESOLVE), patch what
303    needs to be patched in the dependent tree node (JDEP_GET_PATCH,
304    JDEP_APPLY_PATCH) and perform other actions dictated by the context
305    of the patch (JDEP_KIND). The ideas are: we patch only what needs
306    to be patched, and with java_complete_class called at the right
307    time, we will start processing incomplete function bodies tree
308    nodes with everything external to function's bodies already
309    completed, it makes things much simpler. */
310
311 enum jdep_code {
312   JDEP_NO_PATCH,                /* Must be first */
313   JDEP_SUPER,                   /* Patch the type of one type
314                                    supertype. Requires some check
315                                    before it's done */
316   JDEP_FIELD,                   /* Patch the type of a class field */
317
318   /* JDEP_{METHOD,METHOD_RETURN,METHOD_END} to be kept in order */
319   JDEP_METHOD,                  /* Mark the beginning of the patching
320                                    of a method declaration, including
321                                    it's arguments */
322   JDEP_METHOD_RETURN,           /* Mark the beginning of the patching
323                                    of a method declaration. Arguments
324                                    aren't patched, only the returned
325                                    type is */
326   JDEP_METHOD_END,              /* Mark the end of the patching of a
327                                    method declaration. It indicates
328                                    that it's time to compute and
329                                    install a new signature */
330
331   JDEP_INTERFACE,               /* Patch the type of a Class/interface
332                                    extension */
333   JDEP_VARIABLE,                /* Patch the type of a variable declaration */
334   JDEP_PARM,                    /* Patch the type of a parm declaration */
335   JDEP_TYPE,                    /* Patch a random tree node type,
336                                    without the need for any specific
337                                    actions */
338   JDEP_EXCEPTION,               /* Patch exceptions specified by `throws' */
339 };
340
341 typedef struct _jdep {
342 #ifdef ONLY_INT_FIELDS
343   int  kind : 8;                /* Type of patch */
344 #else
345   enum jdep_code kind : 8;
346 #endif
347
348   int  flag0 : 1;               /* Some flags */
349   tree decl;                    /* Tied decl/or WFL */
350   tree solv;                    /* What to solve */
351   tree wfl;                     /* Where thing to resolve where found */
352   tree misc;                    /* Miscellaneous info (optional). */
353   tree *patch;                  /* Address of a location to patch */
354   struct _jdep *next;           /* Linked list */
355 } jdep;
356
357
358 #define JDEP_DECL(J)          ((J)->decl)
359 #define JDEP_DECL_WFL(J)      ((J)->decl)
360 #define JDEP_KIND(J)          ((J)->kind)
361 #define JDEP_SOLV(J)          ((J)->solv)
362 #define JDEP_WFL(J)           ((J)->wfl)
363 #define JDEP_MISC(J)          ((J)->misc)
364 #define JDEP_CLASS(J)         ((J)->class)
365 #define JDEP_APPLY_PATCH(J,P) (*(J)->patch = (P))
366 #define JDEP_GET_PATCH(J)     ((J)->patch)
367 #define JDEP_CHAIN(J)         ((J)->next)
368 #define JDEP_TO_RESOLVE(J)    (TREE_PURPOSE ((J)->solv))
369 #define JDEP_RESOLVED_DECL(J) ((J)->solv ? TREE_PURPOSE ((J)->solv):NULL_TREE)
370 #define JDEP_RESOLVED(J, D)                     \
371   {                                             \
372     TREE_PURPOSE ((J)->solv) = D;               \
373     TREE_VALUE ((J)->solv) = (J)->solv;         \
374   }
375 #define JDEP_RESOLVED_P(J)    (!(J)->solv ||                            \
376                                TREE_VALUE ((J)->solv) == (J)->solv)
377
378 typedef struct _jdeplist {
379   jdep *first;
380   jdep *last;
381   struct _jdeplist *next;
382 } jdeplist;
383 static jdeplist *reverse_jdep_list ();
384
385 #endif /* JC1_LITE */
386
387 #define CLASSD_FIRST(CD) ((CD)->first)
388 #define CLASSD_LAST(CD)  ((CD)->last)
389 #define CLASSD_CHAIN(CD) ((CD)->next)
390
391 #define JDEP_INSERT(L,J)                        \
392   {                                             \
393     if (!(L)->first)                            \
394       (L)->last = (L)->first = (J);             \
395     else                                        \
396       {                                         \
397         JDEP_CHAIN ((L)->last) = (J);           \
398         (L)->last = (J);                        \
399       }                                         \
400   }
401
402 /* Insert a DECL in the current block */
403 #define BLOCK_CHAIN_DECL(NODE)                                              \
404   {                                                                         \
405     TREE_CHAIN ((NODE)) =                                                   \
406       BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));        \
407     BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) = (NODE); \
408   }
409
410 #define BLOCK_EXPR_DECLS(NODE)  BLOCK_VARS(NODE)
411 #define BLOCK_EXPR_BODY(NODE)   BLOCK_SUBBLOCKS(NODE)
412 #define BLOCK_EXPR_ORIGIN(NODE) BLOCK_ABSTRACT_ORIGIN(NODE)
413
414 /* Merge an other line to the source line number of a decl. Used to
415    remember function's end. */
416 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
417
418 /* Retrieve those two info separately. */
419 #define DECL_SOURCE_LINE_FIRST(DECL)    (DECL_SOURCE_LINE(DECL) & 0x0000ffff)
420 #define DECL_SOURCE_LINE_LAST(DECL)     (DECL_SOURCE_LINE(DECL) >> 16)
421
422 /* Build a WFL for expression nodes */
423 #define BUILD_EXPR_WFL(NODE, WFL)                                       \
424   build_expr_wfl ((NODE), input_filename, EXPR_WFL_LINENO ((WFL)),      \
425                   EXPR_WFL_COLNO ((WFL)))
426
427 #define EXPR_WFL_QUALIFICATION(WFL) TREE_OPERAND ((WFL), 1)
428 #define QUAL_WFL(NODE) TREE_PURPOSE (NODE)
429 #define QUAL_RESOLUTION(NODE) TREE_VALUE (NODE)
430 #define QUAL_DECL_TYPE(NODE)                            \
431   (TREE_CODE (TREE_TYPE (NODE)) == POINTER_TYPE ?       \
432    TREE_TYPE (TREE_TYPE (NODE)) : TREE_TYPE (NODE))
433
434 /* Handy macros for the walk operation */
435 #define COMPLETE_CHECK_OP(NODE, N)                      \
436 {                                                       \
437   TREE_OPERAND ((NODE), (N)) =                          \
438     java_complete_tree (TREE_OPERAND ((NODE), (N)));    \
439   if (TREE_OPERAND ((NODE), (N)) == error_mark_node)    \
440     return error_mark_node;                             \
441 }
442 #define COMPLETE_CHECK_OP_0(NODE) COMPLETE_CHECK_OP(NODE, 0)
443 #define COMPLETE_CHECK_OP_1(NODE) COMPLETE_CHECK_OP(NODE, 1)
444
445 /* Building invocations: append(ARG) and StringBuffer(ARG) */
446 #define BUILD_APPEND(ARG)                                                    \
447   build_method_invocation (wfl_append,                                       \
448                            (ARG ? build_tree_list (NULL, (ARG)): NULL_TREE))
449 #define BUILD_STRING_BUFFER(ARG)                                              \
450   build_new_invocation (wfl_string_buffer,                                    \
451                         (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
452
453 /* For exception handling, build diverse function calls */
454 #define BUILD_MONITOR_ENTER(WHERE, ARG)                         \
455   {                                                             \
456     (WHERE) = build (CALL_EXPR, int_type_node,                  \
457                      build_address_of (soft_monitorenter_node), \
458                      build_tree_list (NULL_TREE, (ARG)));       \
459     TREE_SIDE_EFFECTS (WHERE) = 1;                              \
460   }
461
462 #define BUILD_MONITOR_EXIT(WHERE, ARG)                          \
463   {                                                             \
464     (WHERE) = build (CALL_EXPR, int_type_node,                  \
465                      build_address_of (soft_monitorexit_node),  \
466                      build_tree_list (NULL_TREE, (ARG)));       \
467     TREE_SIDE_EFFECTS (WHERE) = 1;                              \
468   }
469
470 #define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO)          \
471   {                                                     \
472     (WHERE) = build (MODIFY_EXPR, void_type_node, (TO), \
473                      soft_exceptioninfo_call_node);     \
474     TREE_SIDE_EFFECTS (WHERE) = 1;                      \
475   }
476
477 #define BUILD_THROW(WHERE, WHAT)                                        \
478   {                                                                     \
479     (WHERE) = build (CALL_EXPR, void_type_node,                         \
480                   build_address_of (throw_node),                        \
481                   build_tree_list (NULL_TREE, (WHAT)), NULL_TREE);      \
482     TREE_SIDE_EFFECTS ((WHERE)) = 1;                                    \
483   }
484
485 /* Set wfl_operator for the most accurate error location */
486 #define SET_WFL_OPERATOR(WHICH, NODE, WFL)              \
487   EXPR_WFL_LINECOL (WHICH) =                            \
488     (TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ?       \
489      EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
490
491 #define PATCH_METHOD_RETURN_ERROR()             \
492   {                                             \
493     if (ret_decl)                               \
494       *ret_decl = NULL_TREE;                    \
495     return error_mark_node;                     \
496   }
497      
498 /* Parser context data structure. */
499 struct parser_ctxt {
500
501   char *filename;                   /* Current filename */
502   FILE *finput;                     /* Current file input stream */
503   struct parser_ctxt *next;
504
505   struct java_line *p_line, *c_line; /* Previous and current line */
506   java_lc elc;                       /* Error's line column info */
507   unicode_t unget_utf8_value;        /* An unget utf8 value */
508   int ccb_indent;                    /* Keep track of {} indent, lexer */
509   int first_ccb_indent1;             /* First { at ident level 1 */
510   int last_ccb_indent1;              /* Last } at ident level 1 */
511   int parser_ccb_indent;             /* Keep track of {} indent, parser */
512   int osb_number;                    /* Keep track of ['s */
513   int minus_seen;                    /* Integral literal overflow */
514   int lineno;                       /* Current lineno */
515   int java_error_flag;              /* Report error when true */
516
517   /* This section is defined only if we compile jc1 */
518 #ifndef JC1_LITE
519   tree modifier_ctx [11];            /* WFL of modifiers */
520   tree current_class;               /* Current class */
521   tree current_function_decl;       /* Current function decl, save/restore */
522
523   JCF *current_jcf;                 /* CU jcf */
524
525   int prevent_ese;                  /* Prevent expression statement error */
526   int class_err;                    /* Flag to report certain errors */
527
528   int formal_parameter_number;      /* Number of parameters found */
529   int interface_number;             /* # itfs declared to extend an itf def */
530
531   tree package;                     /* Defined package ID */
532
533   tree  incomplete_class;           /* List of non-complete classes */
534   tree  current_parsed_class;       /* Class currently parsed */
535   tree  class_list;                 /* List of classes in a CU */
536   jdeplist *classd_list;            /* Classe dependencies in a CU */
537   
538   tree non_static_initialized;      /* List of non static initialized fields */
539   tree static_initialized;          /* List of static non final initialized */
540
541   tree import_list;                 /* List of import */
542   tree import_demand_list;          /* List of import on demand */
543
544   tree current_loop;                 /* List of the currently nested loops */
545   tree current_labeled_block;        /* List of currently nested
546                                         labeled blocks. */
547
548   int pending_block;                 /* Pending block to close */
549 #endif /* JC1_LITE */
550 };
551
552 /* Functions declarations */
553 #ifndef JC1_LITE
554 static char *java_accstring_lookup PROTO ((int));
555 static void  parse_error PROTO ((char *));
556 static void  classitf_redefinition_error PROTO ((char *,tree, tree, tree));
557 static void  variable_redefinition_error PROTO ((tree, tree, tree, int));
558 static void  check_modifiers PROTO ((char *, int, int));
559 static tree  create_class PROTO ((int, tree, tree, tree));
560 static tree  create_interface PROTO ((int, tree, tree));
561 static tree  find_field PROTO ((tree, tree));
562 static tree lookup_field_wrapper PROTO ((tree, tree));
563 static int   duplicate_declaration_error PROTO ((tree, tree, tree, tree));
564 static void  register_fields PROTO ((int, tree, tree));
565 static tree parser_qualified_classname PROTO ((tree));
566 static int  parser_check_super PROTO ((tree, tree, tree));
567 static int  parser_check_super_interface PROTO ((tree, tree, tree));
568 static void check_modifiers_consistency PROTO ((int));
569 static tree lookup_cl PROTO ((tree));
570 static tree lookup_java_method2 PROTO ((tree, tree, int));
571 static tree method_header PROTO ((int, tree, tree, tree));
572 static tree method_declarator PROTO ((tree, tree));
573 static void parse_error_context VPROTO ((tree cl, char *msg, ...));
574 static void parse_warning_context VPROTO ((tree cl, char *msg, ...));
575 static tree parse_jdk1_1_error PROTO ((char *));
576 static void complete_class_report_errors PROTO ((jdep *));
577 static int process_imports PROTO ((void));
578 static void read_import_dir PROTO ((tree));
579 static int find_in_imports_on_demand PROTO ((tree));
580 static int find_in_imports PROTO ((tree));
581 static int check_pkg_class_access PROTO ((tree, tree));
582 static tree resolve_class PROTO ((tree, tree, tree));
583 static tree do_resolve_class PROTO ((tree, tree, tree));
584 static void declare_local_variables PROTO ((int, tree, tree));
585 static void source_start_java_method PROTO ((tree));
586 static void source_end_java_method PROTO ((void));
587 static void expand_start_java_method PROTO ((tree));
588 static tree find_name_in_single_imports PROTO ((tree));
589 static void check_abstract_method_header PROTO ((tree));
590 static tree lookup_java_interface_method2 PROTO ((tree, tree));
591 static tree resolve_expression_name PROTO ((tree));
592 static tree maybe_create_class_interface_decl PROTO ((tree, tree, tree));
593 static int check_class_interface_creation PROTO ((int, int, tree, tree, tree, tree));
594 static tree patch_method_invocation_stmt PROTO ((tree, tree, tree, int *, tree *));
595 static int breakdown_qualified PROTO ((tree *, tree *, tree));
596 static tree resolve_and_layout PROTO ((tree, tree));
597 static tree resolve_no_layout PROTO ((tree, tree));
598 static int identical_subpath_p PROTO ((tree, tree));
599 static int invocation_mode PROTO ((tree, int));
600 static tree find_applicable_accessible_methods_list PROTO ((tree, tree, tree));
601 static tree find_most_specific_methods_list PROTO ((tree));
602 static int argument_types_convertible PROTO ((tree, tree));
603 static tree patch_invoke PROTO ((tree, tree, tree, tree));
604 static tree lookup_method_invoke PROTO ((int, tree, tree, tree, tree));
605 static tree register_incomplete_type PROTO ((int, tree, tree, tree));
606 static tree obtain_incomplete_type PROTO ((tree));
607 static tree java_complete_tree PROTO ((tree));
608 static void java_complete_expand_method PROTO ((tree));
609 static int  unresolved_type_p PROTO ((tree, tree *));
610 static void create_jdep_list PROTO ((struct parser_ctxt *));
611 static tree build_expr_block PROTO ((tree, tree));
612 static tree enter_block PROTO ((void));
613 static tree enter_a_block PROTO ((tree));
614 static tree exit_block PROTO ((void));
615 static tree lookup_name_in_blocks PROTO ((tree));
616 static void maybe_absorb_scoping_blocks PROTO ((void));
617 static tree build_method_invocation PROTO ((tree, tree));
618 static tree build_new_invocation PROTO ((tree, tree));
619 static tree build_assignment PROTO ((int, int, tree, tree));
620 static tree build_binop PROTO ((enum tree_code, int, tree, tree));
621 static tree patch_assignment PROTO ((tree, tree, tree ));
622 static tree patch_binop PROTO ((tree, tree, tree));
623 static tree build_unaryop PROTO ((int, int, tree));
624 static tree build_incdec PROTO ((int, int, tree, int));
625 static tree patch_unaryop PROTO ((tree, tree));
626 static tree build_cast PROTO ((int, tree, tree));
627 static tree patch_cast PROTO ((tree, tree, tree));
628 static int valid_ref_assignconv_cast_p PROTO ((tree, tree, int));
629 static int valid_builtin_assignconv_identity_widening_p PROTO ((tree, tree));
630 static int valid_cast_to_p PROTO ((tree, tree));
631 static int valid_method_invocation_conversion_p PROTO ((tree, tree));
632 static tree try_builtin_assignconv PROTO ((tree, tree, tree));
633 static tree try_reference_assignconv PROTO ((tree, tree));
634 static tree build_unresolved_array_type PROTO ((tree));
635 static tree build_array_ref PROTO ((int, tree, tree));
636 static tree patch_array_ref PROTO ((tree, tree, tree));
637 static tree make_qualified_name PROTO ((tree, tree, int));
638 static tree merge_qualified_name PROTO ((tree, tree));
639 static tree make_qualified_primary PROTO ((tree, tree, int));
640 static int resolve_qualified_expression_name PROTO ((tree, tree *, tree *, tree *));
641 static void qualify_ambiguous_name PROTO ((tree));
642 static void maybe_generate_clinit PROTO ((void));
643 static tree resolve_field_access PROTO ((tree, tree *, tree *));
644 static tree build_newarray_node PROTO ((tree, tree, int));
645 static tree patch_newarray PROTO ((tree));
646 static tree resolve_type_during_patch PROTO ((tree));
647 static int not_initialized_as_it_should_p PROTO ((tree));
648 static tree build_this PROTO ((int));
649 static tree build_return PROTO ((int, tree));
650 static tree patch_return PROTO ((tree));
651 static tree maybe_access_field PROTO ((tree, tree, tree));
652 static int complete_function_arguments PROTO ((tree));
653 static int check_for_static_method_reference PROTO ((tree, tree, tree, tree, tree));
654 static int not_accessible_p PROTO ((tree, tree, int));
655 static int class_in_current_package PROTO ((tree));
656 static tree build_if_else_statement PROTO ((int, tree, tree, tree));
657 static tree patch_if_else_statement PROTO ((tree));
658 static tree add_stmt_to_compound PROTO ((tree, tree, tree));
659 static tree add_stmt_to_block PROTO ((tree, tree, tree));
660 static tree patch_exit_expr PROTO ((tree));
661 static tree build_labeled_block PROTO ((int, tree, tree));
662 static tree generate_labeled_block PROTO (());
663 static tree complete_labeled_statement PROTO ((tree, tree));
664 static tree build_bc_statement PROTO ((int, int, tree));
665 static tree patch_bc_statement PROTO ((tree));
666 static tree patch_loop_statement PROTO ((tree));
667 static tree build_new_loop PROTO ((tree));
668 static tree build_loop_body PROTO ((int, tree, int));
669 static tree complete_loop_body PROTO ((int, tree, tree, int));
670 static tree build_debugable_stmt PROTO ((int, tree));
671 static tree complete_for_loop PROTO ((int, tree, tree, tree));
672 static tree patch_switch_statement PROTO ((tree));
673 static tree string_constant_concatenation PROTO ((tree, tree));
674 static tree build_string_concatenation PROTO ((tree, tree));
675 static tree patch_string_cst PROTO ((tree));
676 static tree patch_string PROTO ((tree));
677 static tree build_jump_to_finally PROTO ((tree, tree, tree, tree));
678 static tree build_try_statement PROTO ((int, tree, tree, tree));
679 static tree patch_try_statement PROTO ((tree));
680 static tree patch_synchronized_statement PROTO ((tree, tree));
681 static tree patch_throw_statement PROTO ((tree, tree));
682 static void check_thrown_exceptions PROTO ((int, tree));
683 static int check_thrown_exceptions_do PROTO ((int, tree));
684 static void purge_unchecked_exceptions PROTO ((tree));
685 static void check_throws_clauses PROTO ((tree, tree, tree));
686
687 void safe_layout_class PROTO ((tree));
688 void java_complete_class PROTO ((void));
689 void java_check_circular_reference PROTO ((void));
690 void java_check_final PROTO ((void));
691 void java_check_methods PROTO ((void));
692 void java_layout_classes PROTO ((void));
693 tree java_method_add_stmt PROTO ((tree, tree));
694 char *java_get_line_col PROTO ((char *, int, int));
695 void java_expand_switch PROTO ((tree));
696 tree java_get_catch_block PROTO ((tree, int));
697 #endif /* JC1_LITE */
698
699 /* Always in use, no matter what you compile */
700
701 void java_push_parser_context PROTO ((void));
702 void java_init_lex PROTO ((void));
703 int yyparse PROTO ((void));
704 int yylex ();
705 void yyerror PROTO ((char *));
706
707 #endif