OSDN Git Service

Wed Apr 21 11:13:36 1999 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, 1999 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 /* Get TYPE name string, regardless whether TYPE is a class or an
133    array. */
134 #define GET_TYPE_NAME(TYPE)                             \
135   (TREE_CODE (TYPE_NAME (TYPE)) == IDENTIFIER_NODE ?    \
136    IDENTIFIER_POINTER (TYPE_NAME (TYPE)) :              \
137    IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TYPE))))
138
139 /* Pedantic warning on obsolete modifiers. Note: when cl is NULL,
140    flags was set artificially, such as for a interface method */
141 #define OBSOLETE_MODIFIER_WARNING(cl, flags, modifier, format, arg)          \
142   {                                                                          \
143     if (flag_redundant && (cl) && ((flags) & (modifier)))                    \
144       parse_warning_context (cl,                                             \
145                              "Discouraged redundant use of `%s' modifier "   \
146                              "in declaration of " format,                    \
147                              java_accstring_lookup (modifier), arg);         \
148   }
149
150 /* Quickly build a temporary pointer on hypothetical type NAME. */
151 #define BUILD_PTR_FROM_NAME(ptr, name)          \
152   {                                             \
153     ptr = build (POINTER_TYPE, NULL_TREE);      \
154     TYPE_NAME (ptr) = name;                     \
155   }
156
157 #define INCOMPLETE_TYPE_P(NODE)                         \
158   ((TREE_CODE (NODE) == POINTER_TYPE)                   \
159    && !TREE_TYPE (NODE)                                 \
160    && TREE_CODE (TYPE_NAME (NODE)) == IDENTIFIER_NODE)
161
162 /* Set the EMIT_LINE_NOTE flag of a EXPR_WLF to 1 if debug information
163    are requested. Works in the context of a parser rule. */
164 #define JAVA_MAYBE_GENERATE_DEBUG_INFO(node)            \
165   (debug_info_level != DINFO_LEVEL_NONE ?               \
166     EXPR_WFL_EMIT_LINE_NOTE (node) = 1, node : node)
167
168 /* Types classification, according to the JLS, section 4.2 */
169 #define JFLOAT_TYPE_P(TYPE)      (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
170 #define JINTEGRAL_TYPE_P(TYPE)   ((TYPE)                                   \
171                                   && (TREE_CODE ((TYPE)) == INTEGER_TYPE   \
172                                       || TREE_CODE ((TYPE)) == CHAR_TYPE))
173 #define JNUMERIC_TYPE_P(TYPE)    ((TYPE)                                \
174                                   && (JFLOAT_TYPE_P ((TYPE))            \
175                                       || JINTEGRAL_TYPE_P ((TYPE))))
176 #define JPRIMITIVE_TYPE_P(TYPE)  ((TYPE)                                  \
177                                   && (JNUMERIC_TYPE_P ((TYPE))            \
178                                   || TREE_CODE ((TYPE)) == BOOLEAN_TYPE))
179
180 #define JPRIMITIVE_TYPE_OR_VOID_P(TYPE) \
181   (JPRIMITIVE_TYPE_P (TYPE) || ((TYPE) == void_type_node))
182
183 #define JBSC_TYPE_P(TYPE) ((TYPE) && (((TYPE) == byte_type_node)        \
184                                       || ((TYPE) == short_type_node)    \
185                                       || ((TYPE) == char_type_node)))
186
187 /* Not defined in the LRM */
188 #define JSTRING_TYPE_P(TYPE) ((TYPE)                                       \
189                               && ((TYPE) == string_type_node ||            \
190                                   (TREE_CODE (TYPE) == POINTER_TYPE &&     \
191                                    TREE_TYPE (TYPE) == string_type_node)))
192 #define JSTRING_P(NODE) ((NODE)                                         \
193                          && (TREE_CODE (NODE) == STRING_CST             \
194                              || IS_CRAFTED_STRING_BUFFER_P (NODE)       \
195                              || JSTRING_TYPE_P (TREE_TYPE (NODE))))
196
197 #define JREFERENCE_TYPE_P(TYPE) ((TYPE)                                       \
198                                  && (TREE_CODE (TYPE) == RECORD_TYPE          \
199                                      || (TREE_CODE (TYPE) == POINTER_TYPE     \
200                                          &&  TREE_CODE (TREE_TYPE (TYPE)) ==  \
201                                          RECORD_TYPE)))
202 #define JNULLP_TYPE_P(TYPE) ((TYPE) && (TREE_CODE (TYPE) == POINTER_TYPE) \
203                              && (TYPE) == TREE_TYPE (null_pointer_node))
204
205 /* Other predicate */
206 #define JDECL_P(NODE) (NODE && (TREE_CODE (NODE) == PARM_DECL           \
207                                 || TREE_CODE (NODE) == VAR_DECL         \
208                                 || TREE_CODE (NODE) == FIELD_DECL))
209
210 #define TYPE_INTERFACE_P(TYPE)                                  \
211   (CLASS_P (TYPE) && CLASS_INTERFACE (TYPE_NAME (TYPE)))
212
213 #define TYPE_CLASS_P(TYPE) (CLASS_P (TYPE)                              \
214                             && !CLASS_INTERFACE (TYPE_NAME (TYPE)))
215
216 /* Standard error messages */
217 #define ERROR_CANT_CONVERT_TO_BOOLEAN(OPERATOR, NODE, TYPE)             \
218   parse_error_context                                                   \
219     ((OPERATOR), "Incompatible type for `%s'. Can't convert `%s' to "   \
220      "boolean", operator_string ((NODE)), lang_printable_name ((TYPE),0))
221
222 #define ERROR_CANT_CONVERT_TO_NUMERIC(OPERATOR, NODE, TYPE)             \
223   parse_error_context                                                   \
224     ((OPERATOR), "Incompatible type for `%s'. Can't convert `%s' to "   \
225      "numeric type", operator_string ((NODE)), lang_printable_name ((TYPE), 0))
226
227 #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE)             \
228   parse_error_context                                                   \
229     ((OPERATOR), (JPRIMITIVE_TYPE_P (TYPE) ?                            \
230      "Incompatible type for `%s'. Explicit cast needed to convert "     \
231       "`%s' to integral" : "Incompatible type for `%s'. Can't convert " \
232       "`%s' to integral"), operator_string ((NODE)),                    \
233       lang_printable_name ((TYPE), 0))
234
235 #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V)                  \
236   parse_error_context                                           \
237     ((WFL), "Variable `%s' may not have been initialized",      \
238      IDENTIFIER_POINTER (V))
239
240 /* Definition for loop handling. This is Java's own definition of a
241    loop body. See parse.y for documentation. It's valid once you hold
242    a loop's body (LOOP_EXPR_BODY) */
243
244 /* The loop main block is the one hold the condition and the loop body */
245 #define LOOP_EXPR_BODY_MAIN_BLOCK(NODE) TREE_OPERAND (NODE, 0)
246 /* And then there is the loop update block */
247 #define LOOP_EXPR_BODY_UPDATE_BLOCK(NODE) TREE_OPERAND (NODE, 1)
248
249 /* Inside the loop main block, there is the loop condition and the
250    loop body. They may be reversed if the loop being described is a
251    do-while loop. NOTE: if you use a WFL around the EXIT_EXPR so you
252    can issue debug info for it, the EXIT_EXPR will be one operand
253    further. */
254 #define LOOP_EXPR_BODY_CONDITION_EXPR(NODE, R)                  \
255   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 1 : 0))
256
257 /* Here is the labeled block the loop real body is encapsulated in */
258 #define LOOP_EXPR_BODY_LABELED_BODY(NODE, R)                    \
259   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 0 : 1))
260 /* And here is the loop's real body */
261 #define LOOP_EXPR_BODY_BODY_EXPR(NODE, R)                       \
262   LABELED_BLOCK_BODY (LOOP_EXPR_BODY_LABELED_BODY(NODE, R))
263
264 /* Does a loop have a label ? */
265 #define LOOP_HAS_LABEL_P(LOOP)                                  \
266   (ctxp->current_labeled_block                                  \
267    && LABELED_BLOCK_BODY (ctxp->current_labeled_block) == (LOOP))
268
269 /* Same operation than the one performed above, but considering the
270    previous labeled block */
271 #define LOOP_HAS_LABEL_SKIP_P(LOOP)                                          \
272   (ctxp->current_labeled_block                                               \
273    && TREE_CHAIN (ctxp->current_labeled_block)                               \
274    && LABELED_BLOCK_BODY (TREE_CHAIN (ctxp->current_labeled_block)) == (LOOP))
275
276 #define PUSH_LABELED_BLOCK(B)                           \
277   {                                                     \
278     TREE_CHAIN (B) = ctxp->current_labeled_block;       \
279     ctxp->current_labeled_block = (B);                  \
280   }
281 #define POP_LABELED_BLOCK()                                             \
282   ctxp->current_labeled_block = TREE_CHAIN (ctxp->current_labeled_block)
283
284 #define PUSH_LOOP(L)                            \
285   {                                             \
286     TREE_CHAIN (L) = ctxp->current_loop;        \
287     ctxp->current_loop = (L);                   \
288   }
289 #define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
290
291 #define PUSH_EXCEPTIONS(E)                                      \
292   currently_caught_type_list =                                  \
293     tree_cons (NULL_TREE, (E), currently_caught_type_list);
294
295 #define POP_EXCEPTIONS()                                                \
296   currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
297
298 /* Check that we're inside a try block.  */
299 #define IN_TRY_BLOCK_P()                                \
300   (currently_caught_type_list                           \
301    && ((TREE_VALUE (currently_caught_type_list) !=      \
302         DECL_FUNCTION_THROWS (current_function_decl))   \
303        || TREE_CHAIN (currently_caught_type_list)))
304
305 /* Check that we have exceptions in E.  */
306 #define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
307
308 /* Invocation modes, as returned by invocation_mode (). */
309 enum {
310   INVOKE_STATIC,
311   INVOKE_NONVIRTUAL,
312   INVOKE_SUPER,
313   INVOKE_INTERFACE,
314   INVOKE_VIRTUAL
315 };
316
317 /* We need the resolution stuff only if we compile jc1 */
318 #ifndef JC1_LITE
319
320 /* Unresolved type identifiers handling. When we process the source
321    code, we blindly accept an unknown type identifier and try to
322    resolve it later. When an unknown type identifier is encountered
323    and used, we record in a struct jdep element what the incomplete
324    type is and what it should patch. Later, java_complete_class will
325    process all classes known to have unresolved type
326    dependencies. Within each of these classes, this routine will
327    process unresolved type dependencies (JDEP_TO_RESOLVE), patch what
328    needs to be patched in the dependent tree node (JDEP_GET_PATCH,
329    JDEP_APPLY_PATCH) and perform other actions dictated by the context
330    of the patch (JDEP_KIND). The ideas are: we patch only what needs
331    to be patched, and with java_complete_class called at the right
332    time, we will start processing incomplete function bodies tree
333    nodes with everything external to function's bodies already
334    completed, it makes things much simpler. */
335
336 enum jdep_code {
337   JDEP_NO_PATCH,                /* Must be first */
338   JDEP_SUPER,                   /* Patch the type of one type
339                                    supertype. Requires some check
340                                    before it's done */
341   JDEP_FIELD,                   /* Patch the type of a class field */
342
343   /* JDEP_{METHOD,METHOD_RETURN,METHOD_END} to be kept in order */
344   JDEP_METHOD,                  /* Mark the beginning of the patching
345                                    of a method declaration, including
346                                    it's arguments */
347   JDEP_METHOD_RETURN,           /* Mark the beginning of the patching
348                                    of a method declaration. Arguments
349                                    aren't patched, only the returned
350                                    type is */
351   JDEP_METHOD_END,              /* Mark the end of the patching of a
352                                    method declaration. It indicates
353                                    that it's time to compute and
354                                    install a new signature */
355
356   JDEP_INTERFACE,               /* Patch the type of a Class/interface
357                                    extension */
358   JDEP_VARIABLE,                /* Patch the type of a variable declaration */
359   JDEP_PARM,                    /* Patch the type of a parm declaration */
360   JDEP_TYPE,                    /* Patch a random tree node type,
361                                    without the need for any specific
362                                    actions */
363   JDEP_EXCEPTION                /* Patch exceptions specified by `throws' */
364 };
365
366 typedef struct _jdep {
367 #ifdef ONLY_INT_FIELDS
368   int  kind : 8;                /* Type of patch */
369 #else
370   enum jdep_code kind : 8;
371 #endif
372
373   int  flag0 : 1;               /* Some flags */
374   tree decl;                    /* Tied decl/or WFL */
375   tree solv;                    /* What to solve */
376   tree wfl;                     /* Where thing to resolve where found */
377   tree misc;                    /* Miscellaneous info (optional). */
378   tree *patch;                  /* Address of a location to patch */
379   struct _jdep *next;           /* Linked list */
380 } jdep;
381
382
383 #define JDEP_DECL(J)          ((J)->decl)
384 #define JDEP_DECL_WFL(J)      ((J)->decl)
385 #define JDEP_KIND(J)          ((J)->kind)
386 #define JDEP_SOLV(J)          ((J)->solv)
387 #define JDEP_WFL(J)           ((J)->wfl)
388 #define JDEP_MISC(J)          ((J)->misc)
389 #define JDEP_CLASS(J)         ((J)->class)
390 #define JDEP_APPLY_PATCH(J,P) (*(J)->patch = (P))
391 #define JDEP_GET_PATCH(J)     ((J)->patch)
392 #define JDEP_CHAIN(J)         ((J)->next)
393 #define JDEP_TO_RESOLVE(J)    ((J)->solv)
394 #define JDEP_RESOLVED_DECL(J) ((J)->solv)
395 #define JDEP_RESOLVED(J, D)   ((J)->solv = D)
396 #define JDEP_RESOLVED_P(J)    \
397         (!(J)->solv || TREE_CODE ((J)->solv) != POINTER_TYPE)
398
399 typedef struct _jdeplist {
400   jdep *first;
401   jdep *last;
402   struct _jdeplist *next;
403 } jdeplist;
404
405 #endif /* JC1_LITE */
406
407 #define CLASSD_FIRST(CD) ((CD)->first)
408 #define CLASSD_LAST(CD)  ((CD)->last)
409 #define CLASSD_CHAIN(CD) ((CD)->next)
410
411 #define JDEP_INSERT(L,J)                        \
412   {                                             \
413     if (!(L)->first)                            \
414       (L)->last = (L)->first = (J);             \
415     else                                        \
416       {                                         \
417         JDEP_CHAIN ((L)->last) = (J);           \
418         (L)->last = (J);                        \
419       }                                         \
420   }
421
422 /* if TYPE can't be resolved, obtain something suitable for its
423    resolution (TYPE is saved in SAVE before being changed). and set
424    CHAIN to 1. Otherwise, type is set to something usable. CHAIN is
425    usually used to determine that a new DEP must be installed on TYPE.
426    Note that when compiling java.lang.Object, references to Object are
427    java.lang.Object.  */
428 #define SET_TYPE_FOR_RESOLUTION(TYPE, SAVE, CHAIN)                      \
429   {                                                                     \
430     tree returned_type;                                                 \
431     (CHAIN) = 0;                                                        \
432     if (TREE_TYPE (ctxp->current_parsed_class) == object_type_node      \
433         && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION                  \
434         && EXPR_WFL_NODE (TYPE) == unqualified_object_id_node)          \
435       (TYPE) = object_type_node;                                        \
436     else                                                                \
437       {                                                                 \
438         if (unresolved_type_p (type, &returned_type))                   \
439           {                                                             \
440             if (returned_type)                                          \
441               (TYPE) = returned_type;                                   \
442             else                                                        \
443               {                                                         \
444                 (SAVE) = (TYPE);                                        \
445                 (TYPE) = obtain_incomplete_type (TYPE);                 \
446                 CHAIN = 1;                                              \
447               }                                                         \
448           }                                                             \
449       }                                                                 \
450   }
451 /* Promote a type if it won't be registered as a patch */
452 #define PROMOTE_RECORD_IF_COMPLETE(TYPE, IS_INCOMPLETE)         \
453   {                                                             \
454     if (!(IS_INCOMPLETE) && TREE_CODE (TYPE) == RECORD_TYPE)    \
455       (TYPE) = promote_type (TYPE);                             \
456   }
457
458 /* Insert a DECL in the current block */
459 #define BLOCK_CHAIN_DECL(NODE)                                              \
460   {                                                                         \
461     TREE_CHAIN ((NODE)) =                                                   \
462       BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl));         \
463     BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl)) = (NODE);  \
464   }
465
466 /* Return the current block, either found in the body of the currently
467    declared function or in the current static block being defined. */
468 #define GET_CURRENT_BLOCK(F) ((F) ? DECL_FUNCTION_BODY ((F)) :  \
469                              current_static_block)
470
471 /* For an artificial BLOCK (created to house a local variable declaration not
472    at the start of an existing block), the parent block;  otherwise NULL. */
473 #define BLOCK_EXPR_ORIGIN(NODE) BLOCK_ABSTRACT_ORIGIN(NODE)
474
475 /* Merge an other line to the source line number of a decl. Used to
476    remember function's end. */
477 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
478
479 /* Retrieve those two info separately. */
480 #define DECL_SOURCE_LINE_FIRST(DECL)    (DECL_SOURCE_LINE(DECL) & 0x0000ffff)
481 #define DECL_SOURCE_LINE_LAST(DECL)     (DECL_SOURCE_LINE(DECL) >> 16)
482
483 /* Retrieve line/column from a WFL. */
484 #define EXPR_WFL_GET_LINECOL(V,LINE,COL)        \
485   {                                             \
486      (LINE) = (V) >> 12;                        \
487      (COL) = (V) & 0xfff;                       \
488    }
489
490 /* Build a WFL for expression nodes */
491 #define BUILD_EXPR_WFL(NODE, WFL)                                       \
492   build_expr_wfl ((NODE), input_filename, EXPR_WFL_LINENO ((WFL)),      \
493                   EXPR_WFL_COLNO ((WFL)))
494
495 #define EXPR_WFL_QUALIFICATION(WFL) TREE_OPERAND ((WFL), 1)
496 #define QUAL_WFL(NODE) TREE_PURPOSE (NODE)
497 #define QUAL_RESOLUTION(NODE) TREE_VALUE (NODE)
498 #define QUAL_DECL_TYPE(NODE) GET_SKIP_TYPE (NODE)
499
500 #define GET_SKIP_TYPE(NODE)                             \
501   (TREE_CODE (TREE_TYPE (NODE)) == POINTER_TYPE ?       \
502    TREE_TYPE (TREE_TYPE (NODE)): TREE_TYPE (NODE))
503
504 /* Handy macros for the walk operation */
505 #define COMPLETE_CHECK_OP(NODE, N)                      \
506 {                                                       \
507   TREE_OPERAND ((NODE), (N)) =                          \
508     java_complete_tree (TREE_OPERAND ((NODE), (N)));    \
509   if (TREE_OPERAND ((NODE), (N)) == error_mark_node)    \
510     return error_mark_node;                             \
511 }
512 #define COMPLETE_CHECK_OP_0(NODE) COMPLETE_CHECK_OP(NODE, 0)
513 #define COMPLETE_CHECK_OP_1(NODE) COMPLETE_CHECK_OP(NODE, 1)
514 #define COMPLETE_CHECK_OP_2(NODE) COMPLETE_CHECK_OP(NODE, 2)
515
516 /* Building invocations: append(ARG) and StringBuffer(ARG) */
517 #define BUILD_APPEND(ARG)                                                     \
518   ((JSTRING_TYPE_P (TREE_TYPE (ARG)) || JPRIMITIVE_TYPE_P (TREE_TYPE (ARG)))  \
519    ? build_method_invocation (wfl_append,                                     \
520                               ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE)\
521    : build_method_invocation (wfl_append,                                     \
522                               ARG ? build_tree_list (NULL,                    \
523                                                      build1 (CONVERT_EXPR,    \
524                                                              object_type_node,\
525                                                              (ARG)))          \
526                               : NULL_TREE))
527 #define BUILD_STRING_BUFFER(ARG)                                              \
528   build_new_invocation (wfl_string_buffer,                                    \
529                         (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
530
531 /* For exception handling, build diverse function calls */
532 #define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO)          \
533   {                                                     \
534     (WHERE) = build (MODIFY_EXPR, void_type_node, (TO), \
535                      soft_exceptioninfo_call_node);     \
536     TREE_SIDE_EFFECTS (WHERE) = 1;                      \
537   }
538
539 #define BUILD_THROW(WHERE, WHAT)                                        \
540   {                                                                     \
541     (WHERE) = build (CALL_EXPR, void_type_node,                         \
542                   build_address_of (throw_node),                        \
543                   build_tree_list (NULL_TREE, (WHAT)), NULL_TREE);      \
544     TREE_SIDE_EFFECTS ((WHERE)) = 1;                                    \
545   }
546
547 /* Set wfl_operator for the most accurate error location */
548 #define SET_WFL_OPERATOR(WHICH, NODE, WFL)              \
549   EXPR_WFL_LINECOL (WHICH) =                            \
550     (TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ?       \
551      EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
552
553 #define PATCH_METHOD_RETURN_ERROR()             \
554   {                                             \
555     if (ret_decl)                               \
556       *ret_decl = NULL_TREE;                    \
557     return error_mark_node;                     \
558   }
559
560 /* Convenient macro to check. Assumes that CLASS is a CLASS_DECL.  */
561 #define CHECK_METHODS(CLASS)                    \
562   {                                             \
563     if (CLASS_INTERFACE ((CLASS)))              \
564       java_check_abstract_methods ((CLASS));    \
565     else                                        \
566       java_check_regular_methods ((CLASS));     \
567   }
568
569 /* Using and reseting the @deprecated tag flag */
570 #define CHECK_DEPRECATED(DECL)                  \
571   {                                             \
572     if (ctxp->deprecated)                       \
573       DECL_DEPRECATED (DECL) = 1;               \
574     ctxp->deprecated = 0;                       \
575   }
576
577 /* Register an import */
578 #define REGISTER_IMPORT(WHOLE, NAME)                    \
579 {                                                       \
580   IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1;     \
581   node = build_tree_list ((WHOLE), (NAME));             \
582   TREE_CHAIN (node) = ctxp->import_list;                \
583   ctxp->import_list = node;                             \
584 }
585
586 /* Macro to access the osb (opening square bracket) count */
587 #define CURRENT_OSB(C) (C)->osb_number [(C)->osb_depth]
588      
589 /* Parser context data structure. */
590 struct parser_ctxt {
591
592   char *filename;                   /* Current filename */
593   FILE *finput;                     /* Current file input stream */
594   struct parser_ctxt *next;
595
596   struct java_line *p_line, *c_line; /* Previous and current line */
597   java_lc elc;                       /* Error's line column info */
598   unicode_t unget_utf8_value;        /* An unget utf8 value */
599   int ccb_indent;                    /* Keep track of {} indent, lexer */
600   int first_ccb_indent1;             /* First { at ident level 1 */
601   int last_ccb_indent1;              /* Last } at ident level 1 */
602   int parser_ccb_indent;             /* Keep track of {} indent, parser */
603   int osb_depth;                     /* Current depth of [ in an expression */
604   int osb_limit;                     /* Limit of this depth */
605   int *osb_number;                   /* Keep track of ['s */
606   int minus_seen;                    /* Integral literal overflow */
607   int lineno;                        /* Current lineno */
608   int java_error_flag;               /* Report error when true */
609   int deprecated;                    /* @deprecated tag seen */
610
611   /* This section is defined only if we compile jc1 */
612 #ifndef JC1_LITE
613   tree modifier_ctx [11];           /* WFL of modifiers */
614   tree current_class;               /* Current class */
615   tree current_function_decl;       /* Current function decl, save/restore */
616
617   struct JCF *current_jcf;          /* CU jcf */
618
619   int prevent_ese;                  /* Prevent expression statement error */
620   int class_err;                    /* Flag to report certain errors */
621
622   int formal_parameter_number;      /* Number of parameters found */
623   int interface_number;             /* # itfs declared to extend an itf def */
624
625   tree package;                     /* Defined package ID */
626
627   /* Those tow list are saved accross file traversal */
628   tree  incomplete_class;           /* List of non-complete classes */
629   tree  gclass_list;                /* All classes seen from source code */
630
631   /* These two lists won't survive file traversal */
632   tree  class_list;                 /* List of classes in a CU */
633   jdeplist *classd_list;            /* Classe dependencies in a CU */
634   
635   tree  current_parsed_class;       /* Class currently parsed */
636   tree  current_parsed_class_un;    /* Curr. parsed class unqualified name */
637
638   tree non_static_initialized;      /* List of non static initialized fields */
639   tree static_initialized;          /* List of static non final initialized */
640
641   tree import_list;                 /* List of import */
642   tree import_demand_list;          /* List of import on demand */
643
644   tree current_loop;                /* List of the currently nested 
645                                        loops/switches */
646   tree current_labeled_block;       /* List of currently nested
647                                        labeled blocks. */
648
649   int pending_block;                /* Pending block to close */
650
651   int explicit_constructor_p;       /* True when processing an explicit
652                                        constructor. This flag is used to trap
653                                        illegal argument usage during an
654                                        explicit constructor invocation. */
655 #endif /* JC1_LITE */
656 };
657
658 #ifndef JC1_LITE
659 void safe_layout_class PROTO ((tree));
660 void java_complete_class PROTO ((void));
661 void java_check_circular_reference PROTO ((void));
662 void java_check_final PROTO ((void));
663 void java_layout_classes PROTO ((void));
664 tree java_method_add_stmt PROTO ((tree, tree));
665 void java_expand_switch PROTO ((tree));
666 int java_report_errors PROTO (());
667 extern tree do_resolve_class PROTO ((tree, tree, tree));
668 #endif
669 char *java_get_line_col PROTO ((char *, int, int));
670 extern void reset_report PROTO ((void));
671
672 /* Always in use, no matter what you compile */
673 void java_push_parser_context PROTO ((void));
674 void java_pop_parser_context PROTO ((int));
675 void java_init_lex PROTO ((void));
676 extern void java_parser_context_save_global PROTO ((void));
677 extern void java_parser_context_restore_global PROTO ((void));
678 int yyparse PROTO ((void));
679 extern int java_parse PROTO ((void));
680 int yylex ();
681 void yyerror PROTO ((char *));
682 extern void java_expand_classes PROTO ((void));
683 #endif