OSDN Git Service

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