OSDN Git Service

Wed Nov 18 23:54:53 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 VERBOSE_SKELETON
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 #define JCONSTRUCTOR_CHECK(FLAG, V, CL, S)                      \
107   if ((FLAG) & (V))                                             \
108     parse_error_context ((CL), "Constructor can't be %s", (S)); \
109       
110 /* Misc. */
111 #define exit_java_complete_class()              \
112   {                                             \
113     pop_obstacks ();                            \
114     return;                                     \
115   }
116
117 #define CLASS_OR_INTERFACE(decl, s1, s2)                        \
118    (decl ?                                                      \
119     ((get_access_flags_from_decl (TYPE_NAME (TREE_TYPE (decl))) \
120       & ACC_INTERFACE) ?                                        \
121      s2 : s1) : ((s1 [0]=='S'|| s1 [0]=='s') ?                  \
122                  (s1 [0]=='S' ? "Supertype" : "supertype") :    \
123                  (s1 [0] > 'A' ? "Type" : "type")))
124
125 #define GET_REAL_TYPE(TYPE)                                     \
126   (TREE_CODE (TYPE) == TREE_LIST ? TREE_PURPOSE (TYPE) : TYPE)
127
128 #define GET_METHOD_NAME(METHOD)                                 \
129   (TREE_CODE (DECL_NAME (METHOD)) == EXPR_WITH_FILE_LOCATION ?  \
130    EXPR_WFL_NODE (DECL_NAME (METHOD)) : DECL_NAME (METHOD))
131
132 /* Pedantic warning on obsolete modifiers. Note: when cl is NULL,
133    flags was set artificially, such as for a interface method */
134 #define OBSOLETE_MODIFIER_WARNING(cl, flags, modifier, format, arg)          \
135   {                                                                          \
136     if (flag_redundant && (cl) && ((flags) & (modifier)))                    \
137       parse_warning_context (cl,                                             \
138                              "Discouraged redundant use of `%s' modifier "   \
139                              "in declaration of " format,                    \
140                              java_accstring_lookup (modifier), arg);         \
141   }
142
143 /* Quickly build a temporary pointer on hypothetical type NAME. */
144 #define BUILD_PTR_FROM_NAME(ptr, name)          \
145   {                                             \
146     ptr = build (POINTER_TYPE, NULL_TREE);      \
147     TYPE_NAME (ptr) = name;                     \
148   }
149
150 #define INCOMPLETE_TYPE_P(NODE)                                 \
151   ((TREE_CODE (NODE) == TREE_LIST)                              \
152    && (TREE_CODE (TREE_PURPOSE (NODE)) == POINTER_TYPE)         \
153    && (TREE_TYPE (TREE_PURPOSE (NODE)) == NULL_TREE))
154
155 /* Set the EMIT_LINE_NOTE flag of a EXPR_WLF to 1 if debug information
156    are requested. Works in the context of a parser rule. */
157 #define JAVA_MAYBE_GENERATE_DEBUG_INFO(node)            \
158   (debug_info_level != DINFO_LEVEL_NONE ?               \
159     EXPR_WFL_EMIT_LINE_NOTE (node) = 1, node : node)
160
161 /* Types classification, according to the JLS, section 4.2 */
162 #define JFLOAT_TYPE_P(TYPE)      (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
163 #define JINTEGRAL_TYPE_P(TYPE)   ((TYPE)                                   \
164                                   && (TREE_CODE ((TYPE)) == INTEGER_TYPE   \
165                                       || TREE_CODE ((TYPE)) == CHAR_TYPE))
166 #define JNUMERIC_TYPE_P(TYPE)    ((TYPE)                                \
167                                   && (JFLOAT_TYPE_P ((TYPE))            \
168                                       || JINTEGRAL_TYPE_P ((TYPE))))
169 #define JPRIMITIVE_TYPE_P(TYPE)  ((TYPE)                                  \
170                                   && (JNUMERIC_TYPE_P ((TYPE))            \
171                                   || TREE_CODE ((TYPE)) == BOOLEAN_TYPE))
172
173 #define JBSC_TYPE_P(TYPE) ((TYPE) && (((TYPE) == byte_type_node)        \
174                                       || ((TYPE) == short_type_node)    \
175                                       || ((TYPE) == char_type_node)))
176
177 /* Not defined in the LRM */
178 #define JSTRING_TYPE_P(TYPE) ((TYPE)                                       \
179                               && ((TYPE) == string_type_node ||            \
180                                   (TREE_CODE (TYPE) == POINTER_TYPE &&     \
181                                    TREE_TYPE (TYPE) == string_type_node)))
182 #define JSTRING_P(NODE) ((NODE)                                         \
183                          && (TREE_CODE (NODE) == STRING_CST             \
184                              || IS_CRAFTED_STRING_BUFFER_P (NODE)       \
185                              || JSTRING_TYPE_P (TREE_TYPE (NODE))))
186
187 #define JREFERENCE_TYPE_P(TYPE) ((TYPE)                                       \
188                                  && (TREE_CODE (TYPE) == RECORD_TYPE          \
189                                      || (TREE_CODE (TYPE) == POINTER_TYPE     \
190                                          &&  TREE_CODE (TREE_TYPE (TYPE)) ==  \
191                                          RECORD_TYPE)))
192 #define JNULLP_TYPE_P(TYPE) ((TYPE) && (TREE_CODE (TYPE) == POINTER_TYPE) \
193                              && (TYPE) == TREE_TYPE (null_pointer_node))
194
195 /* Other predicate */
196 #define DECL_P(NODE) (NODE && (TREE_CODE (NODE) == PARM_DECL            \
197                                || TREE_CODE (NODE) == VAR_DECL          \
198                                || TREE_CODE (NODE) == FIELD_DECL))
199
200 #define TYPE_INTERFACE_P(TYPE)                                  \
201   (CLASS_P (TYPE) && CLASS_INTERFACE (TYPE_NAME (TYPE)))
202
203 #define TYPE_CLASS_P(TYPE) (CLASS_P (TYPE)                              \
204                             && !CLASS_INTERFACE (TYPE_NAME (TYPE))      \
205                             && !TYPE_ARRAY_P (TYPE))
206
207 /* Standard error messages */
208 #define ERROR_CANT_CONVERT_TO_BOOLEAN(OPERATOR, NODE, TYPE)             \
209   parse_error_context                                                   \
210     ((OPERATOR), "Incompatible type for `%s'. Can't convert `%s' to "   \
211      "boolean", operator_string ((NODE)), lang_printable_name ((TYPE),0))
212
213 #define ERROR_CANT_CONVERT_TO_NUMERIC(OPERATOR, NODE, TYPE)             \
214   parse_error_context                                                   \
215     ((OPERATOR), "Incompatible type for `%s'. Can't convert `%s' to "   \
216      "numeric type", operator_string ((NODE)), lang_printable_name ((TYPE), 0))
217
218 #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE)             \
219   parse_error_context                                                   \
220     ((OPERATOR), (JPRIMITIVE_TYPE_P (TYPE) ?                            \
221      "Incompatible type for `%s'. Explicit cast needed to convert "     \
222       "`%s' to integral" : "Incompatible type for `%s'. Can't convert " \
223       "`%s' to integral"), operator_string ((NODE)),                    \
224       lang_printable_name ((TYPE), 0))
225
226 #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V)                  \
227   parse_error_context                                           \
228     ((WFL), "Variable `%s' may not have been initialized",      \
229      IDENTIFIER_POINTER (V))
230
231 /* Definition for loop handling. This is Java's own definition of a
232    loop body. See parse.y for documentation. It's valid once you hold
233    a loop's body (LOOP_EXPR_BODY) */
234
235 /* The loop main block is the one hold the condition and the loop body */
236 #define LOOP_EXPR_BODY_MAIN_BLOCK(NODE) TREE_OPERAND (NODE, 0)
237 /* And then there is the loop update block */
238 #define LOOP_EXPR_BODY_UPDATE_BLOCK(NODE) TREE_OPERAND (NODE, 1)
239
240 /* Inside the loop main block, there is the loop condition and the
241    loop body. They may be reversed if the loop being described is a
242    do-while loop. NOTE: if you use a WFL around the EXIT_EXPR so you
243    can issue debug info for it, the EXIT_EXPR will be one operand
244    further. */
245 #define LOOP_EXPR_BODY_CONDITION_EXPR(NODE, R)                  \
246   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 1 : 0))
247
248 /* Here is the labeled block the loop real body is encapsulated in */
249 #define LOOP_EXPR_BODY_LABELED_BODY(NODE, R)                    \
250   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 0 : 1))
251 /* And here is the loop's real body */
252 #define LOOP_EXPR_BODY_BODY_EXPR(NODE, R)                       \
253   LABELED_BLOCK_BODY (LOOP_EXPR_BODY_LABELED_BODY(NODE, R))
254
255 /* Does a loop have a label ? */
256 #define LOOP_HAS_LABEL_P(LOOP)                                  \
257   (ctxp->current_labeled_block                                  \
258    && LABELED_BLOCK_BODY (ctxp->current_labeled_block) == (LOOP))
259
260 /* Same operation than the one performed above, but considering the
261    previous labeled block */
262 #define LOOP_HAS_LABEL_SKIP_P(LOOP)                                          \
263   (ctxp->current_labeled_block                                               \
264    && TREE_CHAIN (ctxp->current_labeled_block)                               \
265    && LABELED_BLOCK_BODY (TREE_CHAIN (ctxp->current_labeled_block)) == (LOOP))
266
267 #define PUSH_LABELED_BLOCK(B)                           \
268   {                                                     \
269     TREE_CHAIN (B) = ctxp->current_labeled_block;       \
270     ctxp->current_labeled_block = (B);                  \
271   }
272 #define POP_LABELED_BLOCK()                                             \
273   ctxp->current_labeled_block = TREE_CHAIN (ctxp->current_labeled_block)
274
275 #define PUSH_LOOP(L)                            \
276   {                                             \
277     TREE_CHAIN (L) = ctxp->current_loop;        \
278     ctxp->current_loop = (L);                   \
279   }
280 #define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
281
282 #define PUSH_EXCEPTIONS(E)                                      \
283   currently_caught_type_list =                                  \
284     tree_cons (NULL_TREE, (E), currently_caught_type_list);
285
286 #define POP_EXCEPTIONS()                                                \
287   currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
288
289 /* Check that we're inside a try block.  */
290 #define IN_TRY_BLOCK_P()                                \
291   (currently_caught_type_list                           \
292    && ((TREE_VALUE (currently_caught_type_list) !=      \
293         DECL_FUNCTION_THROWS (current_function_decl))   \
294        || TREE_CHAIN (currently_caught_type_list)))
295
296 /* Check that we have exceptions in E.  */
297 #define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
298
299 /* Invocation modes, as returned by invocation_mode (). */
300 enum {
301   INVOKE_STATIC,
302   INVOKE_NONVIRTUAL,
303   INVOKE_SUPER,
304   INVOKE_INTERFACE,
305   INVOKE_VIRTUAL,
306 };
307
308 /* We need the resolution stuff only if we compile jc1 */
309 #ifndef JC1_LITE
310
311 /* Unresolved type identifiers handling. When we process the source
312    code, we blindly accept an unknown type identifier and try to
313    resolve it later. When an unknown type identifier is encountered
314    and used, we record in a struct jdep element what the incomplete
315    type is and what it should patch. Later, java_complete_class will
316    process all classes known to have unresolved type
317    dependencies. Within each of these classes, this routine will
318    process unresolved type dependencies (JDEP_TO_RESOLVE), patch what
319    needs to be patched in the dependent tree node (JDEP_GET_PATCH,
320    JDEP_APPLY_PATCH) and perform other actions dictated by the context
321    of the patch (JDEP_KIND). The ideas are: we patch only what needs
322    to be patched, and with java_complete_class called at the right
323    time, we will start processing incomplete function bodies tree
324    nodes with everything external to function's bodies already
325    completed, it makes things much simpler. */
326
327 enum jdep_code {
328   JDEP_NO_PATCH,                /* Must be first */
329   JDEP_SUPER,                   /* Patch the type of one type
330                                    supertype. Requires some check
331                                    before it's done */
332   JDEP_FIELD,                   /* Patch the type of a class field */
333
334   /* JDEP_{METHOD,METHOD_RETURN,METHOD_END} to be kept in order */
335   JDEP_METHOD,                  /* Mark the beginning of the patching
336                                    of a method declaration, including
337                                    it's arguments */
338   JDEP_METHOD_RETURN,           /* Mark the beginning of the patching
339                                    of a method declaration. Arguments
340                                    aren't patched, only the returned
341                                    type is */
342   JDEP_METHOD_END,              /* Mark the end of the patching of a
343                                    method declaration. It indicates
344                                    that it's time to compute and
345                                    install a new signature */
346
347   JDEP_INTERFACE,               /* Patch the type of a Class/interface
348                                    extension */
349   JDEP_VARIABLE,                /* Patch the type of a variable declaration */
350   JDEP_PARM,                    /* Patch the type of a parm declaration */
351   JDEP_TYPE,                    /* Patch a random tree node type,
352                                    without the need for any specific
353                                    actions */
354   JDEP_EXCEPTION,               /* Patch exceptions specified by `throws' */
355 };
356
357 typedef struct _jdep {
358 #ifdef ONLY_INT_FIELDS
359   int  kind : 8;                /* Type of patch */
360 #else
361   enum jdep_code kind : 8;
362 #endif
363
364   int  flag0 : 1;               /* Some flags */
365   tree decl;                    /* Tied decl/or WFL */
366   tree solv;                    /* What to solve */
367   tree wfl;                     /* Where thing to resolve where found */
368   tree misc;                    /* Miscellaneous info (optional). */
369   tree *patch;                  /* Address of a location to patch */
370   struct _jdep *next;           /* Linked list */
371 } jdep;
372
373
374 #define JDEP_DECL(J)          ((J)->decl)
375 #define JDEP_DECL_WFL(J)      ((J)->decl)
376 #define JDEP_KIND(J)          ((J)->kind)
377 #define JDEP_SOLV(J)          ((J)->solv)
378 #define JDEP_WFL(J)           ((J)->wfl)
379 #define JDEP_MISC(J)          ((J)->misc)
380 #define JDEP_CLASS(J)         ((J)->class)
381 #define JDEP_APPLY_PATCH(J,P) (*(J)->patch = (P))
382 #define JDEP_GET_PATCH(J)     ((J)->patch)
383 #define JDEP_CHAIN(J)         ((J)->next)
384 #define JDEP_TO_RESOLVE(J)    (TREE_PURPOSE ((J)->solv))
385 #define JDEP_RESOLVED_DECL(J) ((J)->solv ? TREE_PURPOSE ((J)->solv):NULL_TREE)
386 #define JDEP_RESOLVED(J, D)                     \
387   {                                             \
388     TREE_PURPOSE ((J)->solv) = D;               \
389     TREE_VALUE ((J)->solv) = (J)->solv;         \
390   }
391 #define JDEP_RESOLVED_P(J)    (!(J)->solv ||                            \
392                                TREE_VALUE ((J)->solv) == (J)->solv)
393
394 typedef struct _jdeplist {
395   jdep *first;
396   jdep *last;
397   struct _jdeplist *next;
398 } jdeplist;
399 static jdeplist *reverse_jdep_list ();
400
401 #endif /* JC1_LITE */
402
403 #define CLASSD_FIRST(CD) ((CD)->first)
404 #define CLASSD_LAST(CD)  ((CD)->last)
405 #define CLASSD_CHAIN(CD) ((CD)->next)
406
407 #define JDEP_INSERT(L,J)                        \
408   {                                             \
409     if (!(L)->first)                            \
410       (L)->last = (L)->first = (J);             \
411     else                                        \
412       {                                         \
413         JDEP_CHAIN ((L)->last) = (J);           \
414         (L)->last = (J);                        \
415       }                                         \
416   }
417
418 /* if TYPE can't be resolved, obtain something suitable for its
419    resolution (TYPE is saved in SAVE before being changed). and set
420    CHAIN to 1. Otherwise, type is set to something usable. CHAIN is
421    usually used to determine that a new DEP must be installed on TYPE.
422    Note that when compiling java.lang.Object, references to Object are
423    java.lang.Object.  */
424 #define SET_TYPE_FOR_RESOLUTION(TYPE, SAVE, CHAIN)                      \
425   {                                                                     \
426     tree returned_type;                                                 \
427     (CHAIN) = 0;                                                        \
428     if (TREE_TYPE (ctxp->current_parsed_class) == object_type_node      \
429         && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION                  \
430         && EXPR_WFL_NODE (TYPE) == unqualified_object_id_node)          \
431       (TYPE) = object_type_node;                                        \
432     else                                                                \
433       {                                                                 \
434         if (unresolved_type_p (type, &returned_type))                   \
435           {                                                             \
436             if (returned_type)                                          \
437               (TYPE) = returned_type;                                   \
438             else                                                        \
439               {                                                         \
440                 (SAVE) = (TYPE);                                        \
441                 (TYPE) = obtain_incomplete_type (TYPE);                 \
442                 CHAIN = 1;                                              \
443               }                                                         \
444           }                                                             \
445       }                                                                 \
446   }
447
448 /* Insert a DECL in the current block */
449 #define BLOCK_CHAIN_DECL(NODE)                                              \
450   {                                                                         \
451     TREE_CHAIN ((NODE)) =                                                   \
452       BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl));        \
453     BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (current_function_decl)) = (NODE); \
454   }
455
456 #define BLOCK_EXPR_DECLS(NODE)  BLOCK_VARS(NODE)
457 #define BLOCK_EXPR_BODY(NODE)   BLOCK_SUBBLOCKS(NODE)
458
459 /* For an artificial BLOCK (created to house a local variable declaration not
460    at the start of an existing block), the parent block;  otherwise NULL. */
461 #define BLOCK_EXPR_ORIGIN(NODE) BLOCK_ABSTRACT_ORIGIN(NODE)
462
463 /* Merge an other line to the source line number of a decl. Used to
464    remember function's end. */
465 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
466
467 /* Retrieve those two info separately. */
468 #define DECL_SOURCE_LINE_FIRST(DECL)    (DECL_SOURCE_LINE(DECL) & 0x0000ffff)
469 #define DECL_SOURCE_LINE_LAST(DECL)     (DECL_SOURCE_LINE(DECL) >> 16)
470
471 /* Build a WFL for expression nodes */
472 #define BUILD_EXPR_WFL(NODE, WFL)                                       \
473   build_expr_wfl ((NODE), input_filename, EXPR_WFL_LINENO ((WFL)),      \
474                   EXPR_WFL_COLNO ((WFL)))
475
476 #define EXPR_WFL_QUALIFICATION(WFL) TREE_OPERAND ((WFL), 1)
477 #define QUAL_WFL(NODE) TREE_PURPOSE (NODE)
478 #define QUAL_RESOLUTION(NODE) TREE_VALUE (NODE)
479 #define QUAL_DECL_TYPE(NODE)                            \
480   (TREE_CODE (TREE_TYPE (NODE)) == POINTER_TYPE ?       \
481    TREE_TYPE (TREE_TYPE (NODE)) : TREE_TYPE (NODE))
482
483 /* Handy macros for the walk operation */
484 #define COMPLETE_CHECK_OP(NODE, N)                      \
485 {                                                       \
486   TREE_OPERAND ((NODE), (N)) =                          \
487     java_complete_tree (TREE_OPERAND ((NODE), (N)));    \
488   if (TREE_OPERAND ((NODE), (N)) == error_mark_node)    \
489     return error_mark_node;                             \
490 }
491 #define COMPLETE_CHECK_OP_0(NODE) COMPLETE_CHECK_OP(NODE, 0)
492 #define COMPLETE_CHECK_OP_1(NODE) COMPLETE_CHECK_OP(NODE, 1)
493 #define COMPLETE_CHECK_OP_2(NODE) COMPLETE_CHECK_OP(NODE, 2)
494
495 /* Building invocations: append(ARG) and StringBuffer(ARG) */
496 #define BUILD_APPEND(ARG)                                                    \
497   build_method_invocation (wfl_append,                                       \
498                            (ARG ? build_tree_list (NULL, (ARG)): NULL_TREE))
499 #define BUILD_STRING_BUFFER(ARG)                                              \
500   build_new_invocation (wfl_string_buffer,                                    \
501                         (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
502
503 /* For exception handling, build diverse function calls */
504 #define BUILD_MONITOR_ENTER(WHERE, ARG)                         \
505   {                                                             \
506     (WHERE) = build (CALL_EXPR, int_type_node,                  \
507                      build_address_of (soft_monitorenter_node), \
508                      build_tree_list (NULL_TREE, (ARG)),        \
509                      NULL_TREE);                                \
510     TREE_SIDE_EFFECTS (WHERE) = 1;                              \
511   }
512
513 #define BUILD_MONITOR_EXIT(WHERE, ARG)                          \
514   {                                                             \
515     (WHERE) = build (CALL_EXPR, int_type_node,                  \
516                      build_address_of (soft_monitorexit_node),  \
517                      build_tree_list (NULL_TREE, (ARG)),        \
518                      NULL_TREE);                                \
519     TREE_SIDE_EFFECTS (WHERE) = 1;                              \
520   }
521
522 #define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO)          \
523   {                                                     \
524     (WHERE) = build (MODIFY_EXPR, void_type_node, (TO), \
525                      soft_exceptioninfo_call_node);     \
526     TREE_SIDE_EFFECTS (WHERE) = 1;                      \
527   }
528
529 #define BUILD_THROW(WHERE, WHAT)                                        \
530   {                                                                     \
531     (WHERE) = build (CALL_EXPR, void_type_node,                         \
532                   build_address_of (throw_node),                        \
533                   build_tree_list (NULL_TREE, (WHAT)), NULL_TREE);      \
534     TREE_SIDE_EFFECTS ((WHERE)) = 1;                                    \
535   }
536
537 /* Set wfl_operator for the most accurate error location */
538 #define SET_WFL_OPERATOR(WHICH, NODE, WFL)              \
539   EXPR_WFL_LINECOL (WHICH) =                            \
540     (TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ?       \
541      EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
542
543 #define PATCH_METHOD_RETURN_ERROR()             \
544   {                                             \
545     if (ret_decl)                               \
546       *ret_decl = NULL_TREE;                    \
547     return error_mark_node;                     \
548   }
549
550 /* Convenient macro to check. Assumes that CLASS is a CLASS_DECL.  */
551 #define CHECK_METHODS(CLASS)                    \
552   {                                             \
553     if (CLASS_INTERFACE ((CLASS)))              \
554       java_check_abstract_methods ((CLASS));    \
555     else                                        \
556       java_check_regular_methods ((CLASS));     \
557   }
558
559 /* Using and reseting the @deprecated tag flag */
560 #define CHECK_DEPRECATED(DECL)                  \
561   {                                             \
562     if (ctxp->deprecated)                       \
563       DECL_DEPRECATED (DECL) = 1;               \
564     ctxp->deprecated = 0;                       \
565   }
566
567 /* Register an impor */
568 #define REGISTER_IMPORT(WHOLE, NAME)                    \
569 {                                                       \
570   IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1;     \
571   node = build_tree_list ((WHOLE), (NAME));             \
572   TREE_CHAIN (node) = ctxp->import_list;                \
573   ctxp->import_list = node;                             \
574 }
575      
576 /* Parser context data structure. */
577 struct parser_ctxt {
578
579   char *filename;                   /* Current filename */
580   FILE *finput;                     /* Current file input stream */
581   struct parser_ctxt *next;
582
583   struct java_line *p_line, *c_line; /* Previous and current line */
584   java_lc elc;                       /* Error's line column info */
585   unicode_t unget_utf8_value;        /* An unget utf8 value */
586   int ccb_indent;                    /* Keep track of {} indent, lexer */
587   int first_ccb_indent1;             /* First { at ident level 1 */
588   int last_ccb_indent1;              /* Last } at ident level 1 */
589   int parser_ccb_indent;             /* Keep track of {} indent, parser */
590   int osb_number;                    /* Keep track of ['s */
591   int minus_seen;                    /* Integral literal overflow */
592   int lineno;                       /* Current lineno */
593   int java_error_flag;              /* Report error when true */
594   int deprecated;                    /* @deprecated tag seen */
595
596   /* This section is defined only if we compile jc1 */
597 #ifndef JC1_LITE
598   tree modifier_ctx [11];            /* WFL of modifiers */
599   tree current_class;               /* Current class */
600   tree current_function_decl;       /* Current function decl, save/restore */
601
602   JCF *current_jcf;                 /* CU jcf */
603
604   int prevent_ese;                  /* Prevent expression statement error */
605   int class_err;                    /* Flag to report certain errors */
606
607   int formal_parameter_number;      /* Number of parameters found */
608   int interface_number;             /* # itfs declared to extend an itf def */
609
610   tree package;                     /* Defined package ID */
611
612   tree  incomplete_class;           /* List of non-complete classes */
613   tree  current_parsed_class;       /* Class currently parsed */
614   tree  current_parsed_class_un;    /* Curr. parsed class unqualified name */
615   tree  class_list;                 /* List of classes in a CU */
616   tree  gclass_list;                /* All classes seen so far. */
617   jdeplist *classd_list;            /* Classe dependencies in a CU */
618   
619   tree non_static_initialized;      /* List of non static initialized fields */
620   tree static_initialized;          /* List of static non final initialized */
621
622   tree import_list;                 /* List of import */
623   tree import_demand_list;          /* List of import on demand */
624
625   tree current_loop;                 /* List of the currently nested loops/switches */
626   tree current_labeled_block;        /* List of currently nested
627                                         labeled blocks. */
628
629   int pending_block;                 /* Pending block to close */
630
631   int explicit_constructor_p;        /* True when processing an
632                                         explicit constructor. This flag is 
633                                         used to trap illegal argument usage 
634                                         during an explicit constructor
635                                         invocation. */
636 #endif /* JC1_LITE */
637 };
638
639 /* Functions declarations */
640 #ifndef JC1_LITE
641 static char *java_accstring_lookup PROTO ((int));
642 static void  classitf_redefinition_error PROTO ((char *,tree, tree, tree));
643 static void  variable_redefinition_error PROTO ((tree, tree, tree, int));
644 static void  check_modifiers PROTO ((char *, int, int));
645 static tree  create_class PROTO ((int, tree, tree, tree));
646 static tree  create_interface PROTO ((int, tree, tree));
647 static tree  find_field PROTO ((tree, tree));
648 static tree lookup_field_wrapper PROTO ((tree, tree));
649 static int   duplicate_declaration_error_p PROTO ((tree, tree, tree));
650 static void  register_fields PROTO ((int, tree, tree));
651 static tree parser_qualified_classname PROTO ((tree));
652 static int  parser_check_super PROTO ((tree, tree, tree));
653 static int  parser_check_super_interface PROTO ((tree, tree, tree));
654 static void check_modifiers_consistency PROTO ((int));
655 static tree lookup_cl PROTO ((tree));
656 static tree lookup_java_method2 PROTO ((tree, tree, int));
657 static tree method_header PROTO ((int, tree, tree, tree));
658 static void fix_method_argument_names PROTO ((tree ,tree));
659 static tree method_declarator PROTO ((tree, tree));
660 static void parse_warning_context VPROTO ((tree cl, char *msg, ...));
661 static void issue_warning_error_from_context PROTO ((tree, char *msg, va_list));
662 static tree parse_jdk1_1_error PROTO ((char *));
663 static void complete_class_report_errors PROTO ((jdep *));
664 static int process_imports PROTO ((void));
665 static void read_import_dir PROTO ((tree));
666 static int find_in_imports_on_demand PROTO ((tree));
667 static int find_in_imports PROTO ((tree));
668 static int check_pkg_class_access PROTO ((tree, tree));
669 static tree resolve_package PROTO ((tree, tree *));
670 static tree lookup_package_type PROTO ((char *, int));
671 static tree resolve_class PROTO ((tree, tree, tree));
672 static tree do_resolve_class PROTO ((tree, tree, tree));
673 static void declare_local_variables PROTO ((int, tree, tree));
674 static void source_start_java_method PROTO ((tree));
675 static void source_end_java_method PROTO ((void));
676 static void expand_start_java_method PROTO ((tree));
677 static tree find_name_in_single_imports PROTO ((tree));
678 static void check_abstract_method_header PROTO ((tree));
679 static tree lookup_java_interface_method2 PROTO ((tree, tree));
680 static tree resolve_expression_name PROTO ((tree, tree *));
681 static tree maybe_create_class_interface_decl PROTO ((tree, tree, tree));
682 static int check_class_interface_creation PROTO ((int, int, tree, 
683                                                   tree, tree, tree));
684 static tree patch_method_invocation PROTO ((tree, tree, tree, 
685                                             int *, tree *, int));
686 static int breakdown_qualified PROTO ((tree *, tree *, tree));
687 static tree resolve_and_layout PROTO ((tree, tree));
688 static tree resolve_no_layout PROTO ((tree, tree));
689 static int invocation_mode PROTO ((tree, int));
690 static tree find_applicable_accessible_methods_list PROTO ((int, tree, 
691                                                             tree, tree));
692 static tree find_most_specific_methods_list PROTO ((tree));
693 static int argument_types_convertible PROTO ((tree, tree));
694 static tree patch_invoke PROTO ((tree, tree, tree, int));
695 static tree lookup_method_invoke PROTO ((int, tree, tree, tree, tree));
696 static tree register_incomplete_type PROTO ((int, tree, tree, tree));
697 static tree obtain_incomplete_type PROTO ((tree));
698 static tree java_complete_tree PROTO ((tree));
699 static void java_complete_expand_method PROTO ((tree));
700 static int  unresolved_type_p PROTO ((tree, tree *));
701 static void create_jdep_list PROTO ((struct parser_ctxt *));
702 static tree build_expr_block PROTO ((tree, tree));
703 static tree enter_block PROTO ((void));
704 static tree enter_a_block PROTO ((tree));
705 static tree exit_block PROTO ((void));
706 static tree lookup_name_in_blocks PROTO ((tree));
707 static void maybe_absorb_scoping_blocks PROTO ((void));
708 static tree build_method_invocation PROTO ((tree, tree));
709 static tree build_new_invocation PROTO ((tree, tree));
710 static tree build_assignment PROTO ((int, int, tree, tree));
711 static tree build_binop PROTO ((enum tree_code, int, tree, tree));
712 static int check_final_assignment PROTO ((tree ,tree));
713 static tree patch_assignment PROTO ((tree, tree, tree ));
714 static tree patch_binop PROTO ((tree, tree, tree));
715 static tree build_unaryop PROTO ((int, int, tree));
716 static tree build_incdec PROTO ((int, int, tree, int));
717 static tree patch_unaryop PROTO ((tree, tree));
718 static tree build_cast PROTO ((int, tree, tree));
719 static tree build_null_of_type PROTO ((tree));
720 static tree patch_cast PROTO ((tree, tree));
721 static int valid_ref_assignconv_cast_p PROTO ((tree, tree, int));
722 static int valid_builtin_assignconv_identity_widening_p PROTO ((tree, tree));
723 static int valid_cast_to_p PROTO ((tree, tree));
724 static int valid_method_invocation_conversion_p PROTO ((tree, tree));
725 static tree try_builtin_assignconv PROTO ((tree, tree, tree));
726 static tree try_reference_assignconv PROTO ((tree, tree));
727 static tree build_unresolved_array_type PROTO ((tree));
728 static tree build_array_from_name PROTO ((tree, tree, tree, tree *));
729 static tree build_array_ref PROTO ((int, tree, tree));
730 static tree patch_array_ref PROTO ((tree));
731 static tree make_qualified_name PROTO ((tree, tree, int));
732 static tree merge_qualified_name PROTO ((tree, tree));
733 static tree make_qualified_primary PROTO ((tree, tree, int));
734 static int resolve_qualified_expression_name PROTO ((tree, tree *, 
735                                                      tree *, tree *));
736 static void qualify_ambiguous_name PROTO ((tree));
737 static void maybe_generate_clinit PROTO ((void));
738 static tree resolve_field_access PROTO ((tree, tree *, tree *));
739 static tree build_newarray_node PROTO ((tree, tree, int));
740 static tree patch_newarray PROTO ((tree));
741 static tree resolve_type_during_patch PROTO ((tree));
742 static tree build_this PROTO ((int));
743 static tree build_return PROTO ((int, tree));
744 static tree patch_return PROTO ((tree));
745 static tree maybe_access_field PROTO ((tree, tree, tree));
746 static int complete_function_arguments PROTO ((tree));
747 static int check_for_static_method_reference PROTO ((tree, tree, tree, tree, tree));
748 static int not_accessible_p PROTO ((tree, tree, int));
749 static void check_deprecation PROTO ((tree, tree));
750 static int class_in_current_package PROTO ((tree));
751 static tree build_if_else_statement PROTO ((int, tree, tree, tree));
752 static tree patch_if_else_statement PROTO ((tree));
753 static tree add_stmt_to_compound PROTO ((tree, tree, tree));
754 static tree add_stmt_to_block PROTO ((tree, tree, tree));
755 static tree patch_exit_expr PROTO ((tree));
756 static tree build_labeled_block PROTO ((int, tree));
757 static tree generate_labeled_block PROTO (());
758 static tree complete_labeled_statement PROTO ((tree, tree));
759 static tree build_bc_statement PROTO ((int, int, tree));
760 static tree patch_bc_statement PROTO ((tree));
761 static tree patch_loop_statement PROTO ((tree));
762 static tree build_new_loop PROTO ((tree));
763 static tree build_loop_body PROTO ((int, tree, int));
764 static tree complete_loop_body PROTO ((int, tree, tree, int));
765 static tree build_debugable_stmt PROTO ((int, tree));
766 static tree complete_for_loop PROTO ((int, tree, tree, tree));
767 static tree patch_switch_statement PROTO ((tree));
768 static tree string_constant_concatenation PROTO ((tree, tree));
769 static tree build_string_concatenation PROTO ((tree, tree));
770 static tree patch_string_cst PROTO ((tree));
771 static tree patch_string PROTO ((tree));
772 static tree build_jump_to_finally PROTO ((tree, tree, tree, tree));
773 static tree build_try_statement PROTO ((int, tree, tree, tree));
774 static tree patch_try_statement PROTO ((tree));
775 static tree patch_synchronized_statement PROTO ((tree, tree));
776 static tree patch_throw_statement PROTO ((tree, tree));
777 static void check_thrown_exceptions PROTO ((int, tree));
778 static int check_thrown_exceptions_do PROTO ((tree));
779 static void purge_unchecked_exceptions PROTO ((tree));
780 static void check_throws_clauses PROTO ((tree, tree, tree));
781 static void complete_method_declaration PROTO ((tree));
782 static tree build_super_invocation PROTO (());
783 static int verify_constructor_circularity PROTO ((tree, tree));
784 static char *constructor_circularity_msg PROTO ((tree, tree));
785 static tree build_this_super_qualified_invocation PROTO ((int, tree, tree,
786                                                           int, int));
787 static char *get_printable_method_name PROTO ((tree));
788 static tree patch_conditional_expr PROTO ((tree, tree, tree));
789 static void maybe_generate_finit PROTO (());
790 static void fix_constructors PROTO ((tree));
791 static int verify_constructor_super PROTO (());
792 static tree create_artificial_method PROTO ((tree, int, tree, tree, tree));
793 static void start_artificial_method_body PROTO ((tree));
794 static void end_artificial_method_body PROTO ((tree));
795 static tree generate_field_initialization_code PROTO ((tree));
796 static int check_method_redefinition PROTO ((tree, tree));
797 static int reset_method_name PROTO ((tree));
798 static void java_check_regular_methods PROTO ((tree));
799 static void java_check_abstract_methods PROTO ((tree));
800 static tree maybe_build_primttype_type_ref PROTO ((tree, tree));
801
802 void safe_layout_class PROTO ((tree));
803 void java_complete_class PROTO ((void));
804 void java_check_circular_reference PROTO ((void));
805 void java_check_final PROTO ((void));
806 void java_check_methods PROTO ((void));
807 void java_layout_classes PROTO ((void));
808 tree java_method_add_stmt PROTO ((tree, tree));
809 char *java_get_line_col PROTO ((char *, int, int));
810 void java_expand_switch PROTO ((tree));
811 tree java_get_catch_block PROTO ((tree, int));
812 int java_report_errors PROTO (());
813 #endif /* JC1_LITE */
814
815 /* Always in use, no matter what you compile */
816
817 void java_push_parser_context PROTO ((void));
818 void java_pop_parser_context PROTO ((int));
819 void java_init_lex PROTO ((void));
820 int yyparse PROTO ((void));
821 int yylex ();
822 void yyerror PROTO ((char *));
823
824 #endif