OSDN Git Service

Respective ChangeLogs for common, cp/, java/
[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_INNER_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_ABSTRACT|ACC_STATIC
83 #define INTERFACE_METHOD_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
84 #define INTERFACE_FIELD_MODIFIERS ACC_PUBLIC|ACC_STATIC|ACC_FINAL
85
86 /* Getting a modifier WFL */
87 #define MODIFIER_WFL(M)   (ctxp->modifier_ctx [(M) - PUBLIC_TK])
88
89 /* Check on modifiers */
90 #define THIS_MODIFIER_ONLY(f, m, v, count, l)                           \
91   if ((f) & (m))                                                        \
92     {                                                                   \
93       tree node = MODIFIER_WFL (v);                                     \
94       if ((l)                                                           \
95           && ((EXPR_WFL_COLNO (node) > EXPR_WFL_COLNO (l))              \
96               || (EXPR_WFL_LINENO (node) > EXPR_WFL_LINENO (l))))       \
97         l = node;                                                       \
98       else if (!(l))                                                    \
99         l = node;                                                       \
100       count++;                                                          \
101     }
102
103 #define ABSTRACT_CHECK(FLAG, V, CL, S)                          \
104   if ((FLAG) & (V))                                             \
105     parse_error_context ((CL), "%s method can't be abstract", (S));
106
107 #define JCONSTRUCTOR_CHECK(FLAG, V, CL, S)                      \
108   if ((FLAG) & (V))                                             \
109     parse_error_context ((CL), "Constructor can't be %s", (S)); \
110       
111 /* Misc. */
112 #define exit_java_complete_class()              \
113   {                                             \
114     pop_obstacks ();                            \
115     return;                                     \
116   }
117
118 #define CLASS_OR_INTERFACE(decl, s1, s2)                        \
119    (decl ?                                                      \
120     ((get_access_flags_from_decl (TYPE_NAME (TREE_TYPE (decl))) \
121       & ACC_INTERFACE) ?                                        \
122      s2 : s1) : ((s1 [0]=='S'|| s1 [0]=='s') ?                  \
123                  (s1 [0]=='S' ? "Supertype" : "supertype") :    \
124                  (s1 [0] > 'A' ? "Type" : "type")))
125
126 #define GET_REAL_TYPE(TYPE)                                     \
127   (TREE_CODE (TYPE) == TREE_LIST ? TREE_PURPOSE (TYPE) : TYPE)
128
129 #define GET_METHOD_NAME(METHOD)                                 \
130   (TREE_CODE (DECL_NAME (METHOD)) == EXPR_WITH_FILE_LOCATION ?  \
131    EXPR_WFL_NODE (DECL_NAME (METHOD)) : DECL_NAME (METHOD))
132
133 /* Get TYPE name string, regardless whether TYPE is a class or an
134    array. */
135 #define GET_TYPE_NAME(TYPE)                             \
136   (TREE_CODE (TYPE_NAME (TYPE)) == IDENTIFIER_NODE ?    \
137    IDENTIFIER_POINTER (TYPE_NAME (TYPE)) :              \
138    IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TYPE))))
139
140 /* Pedantic warning on obsolete modifiers. Note: when cl is NULL,
141    flags was set artificially, such as for a interface method */
142 #define OBSOLETE_MODIFIER_WARNING(cl, flags, __modifier, arg)                \
143   {                                                                          \
144     if (flag_redundant && (cl) && ((flags) & (__modifier)))                  \
145       parse_warning_context (cl,                                             \
146      "Discouraged redundant use of `%s' modifier in declaration of %s",      \
147                              java_accstring_lookup (__modifier), arg);       \
148   }
149 #define OBSOLETE_MODIFIER_WARNING2(cl, flags, __modifier, arg1, arg2)        \
150   {                                                                          \
151     if (flag_redundant && (cl) && ((flags) & (__modifier)))                  \
152       parse_warning_context (cl,                                             \
153      "Discouraged redundant use of `%s' modifier in declaration of %s `%s'", \
154                              java_accstring_lookup (__modifier), arg1, arg2);\
155   }
156
157 /* Quickly build a temporary pointer on hypothetical type NAME. */
158 #define BUILD_PTR_FROM_NAME(ptr, name)          \
159   {                                             \
160     ptr = build (POINTER_TYPE, NULL_TREE);      \
161     TYPE_NAME (ptr) = name;                     \
162   }
163
164 #define INCOMPLETE_TYPE_P(NODE)                         \
165   ((TREE_CODE (NODE) == POINTER_TYPE)                   \
166    && !TREE_TYPE (NODE)                                 \
167    && TREE_CODE (TYPE_NAME (NODE)) == IDENTIFIER_NODE)
168
169 /* Set the EMIT_LINE_NOTE flag of a EXPR_WLF to 1 if debug information
170    are requested. Works in the context of a parser rule. */
171 #define JAVA_MAYBE_GENERATE_DEBUG_INFO(node)            \
172   (debug_info_level != DINFO_LEVEL_NONE ?               \
173     EXPR_WFL_EMIT_LINE_NOTE (node) = 1, node : node)
174
175 /* Types classification, according to the JLS, section 4.2 */
176 #define JFLOAT_TYPE_P(TYPE)      (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
177 #define JINTEGRAL_TYPE_P(TYPE)   ((TYPE)                                   \
178                                   && (TREE_CODE ((TYPE)) == INTEGER_TYPE   \
179                                       || TREE_CODE ((TYPE)) == CHAR_TYPE))
180 #define JNUMERIC_TYPE_P(TYPE)    ((TYPE)                                \
181                                   && (JFLOAT_TYPE_P ((TYPE))            \
182                                       || JINTEGRAL_TYPE_P ((TYPE))))
183 #define JPRIMITIVE_TYPE_P(TYPE)  ((TYPE)                                  \
184                                   && (JNUMERIC_TYPE_P ((TYPE))            \
185                                   || TREE_CODE ((TYPE)) == BOOLEAN_TYPE))
186
187 #define JBSC_TYPE_P(TYPE) ((TYPE) && (((TYPE) == byte_type_node)        \
188                                       || ((TYPE) == short_type_node)    \
189                                       || ((TYPE) == char_type_node)))
190
191 /* Not defined in the LRM */
192 #define JSTRING_TYPE_P(TYPE) ((TYPE)                                       \
193                               && ((TYPE) == string_type_node ||            \
194                                   (TREE_CODE (TYPE) == POINTER_TYPE &&     \
195                                    TREE_TYPE (TYPE) == string_type_node)))
196 #define JSTRING_P(NODE) ((NODE)                                         \
197                          && (TREE_CODE (NODE) == STRING_CST             \
198                              || IS_CRAFTED_STRING_BUFFER_P (NODE)       \
199                              || JSTRING_TYPE_P (TREE_TYPE (NODE))))
200
201 #define JREFERENCE_TYPE_P(TYPE) ((TYPE)                                       \
202                                  && (TREE_CODE (TYPE) == RECORD_TYPE          \
203                                      || (TREE_CODE (TYPE) == POINTER_TYPE     \
204                                          &&  TREE_CODE (TREE_TYPE (TYPE)) ==  \
205                                          RECORD_TYPE)))
206 #define JNULLP_TYPE_P(TYPE) ((TYPE) && (TREE_CODE (TYPE) == POINTER_TYPE) \
207                              && (TYPE) == TREE_TYPE (null_pointer_node))
208
209 /* Other predicates */
210 #define JDECL_P(NODE) (NODE && (TREE_CODE (NODE) == PARM_DECL           \
211                                 || TREE_CODE (NODE) == VAR_DECL         \
212                                 || TREE_CODE (NODE) == FIELD_DECL))
213
214 #define TYPE_INTERFACE_P(TYPE)                                  \
215   (CLASS_P (TYPE) && CLASS_INTERFACE (TYPE_NAME (TYPE)))
216
217 #define TYPE_CLASS_P(TYPE) (CLASS_P (TYPE)                              \
218                             && !CLASS_INTERFACE (TYPE_NAME (TYPE)))
219
220 /* Identifier business related to 1.1 language extensions.  */
221
222 #define IDENTIFIER_INNER_CLASS_OUTER_FIELD_ACCESS(NODE) \
223   (TREE_CODE (NODE) == IDENTIFIER_NODE &&               \
224    IDENTIFIER_LENGTH (NODE) >= 8 &&                     \
225    IDENTIFIER_POINTER (NODE)[7] != '0')
226
227 /* Build the string val$<O> and store it into N. The is used to
228    construct the name of inner class hidden fields used to alias outer
229    scope local variables.  */
230 #define MANGLE_OUTER_LOCAL_VARIABLE_NAME(N, O)                          \
231   {                                                                     \
232     obstack_grow (&temporary_obstack, "val$", 4);                       \
233     obstack_grow (&temporary_obstack,                                   \
234                   IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O)));   \
235     obstack_1grow (&temporary_obstack, '\0');                           \
236     (N) = obstack_finish (&temporary_obstack);                          \
237   }
238
239 /* Build the string parm$<O> and store in into the identifier N. This
240    is used to contruct the name of hidden parameters used to
241    initialize outer scope aliases.  */
242 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID(N, O)                \
243   {                                                                     \
244     obstack_grow (&temporary_obstack, "parm$", 5);                      \
245     obstack_grow (&temporary_obstack,                                   \
246                   IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O)));   \
247     obstack_1grow (&temporary_obstack, '\0');                           \
248     (N) = obstack_finish (&temporary_obstack);                          \
249   }
250
251 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR(N, S)       \
252   {                                                             \
253     obstack_grow (&temporary_obstack, "parm$", 5);              \
254     obstack_grow (&temporary_obstack, (S), strlen ((S)));       \
255     obstack_1grow (&temporary_obstack, '\0');                   \
256     (N) = obstack_finish (&temporary_obstack);                  \
257   }
258
259 /* Skip THIS and artificial parameters found in function decl M and
260    assign the result to C. We don't do that for $finit$, since it's
261    knowingly called with artificial parms.  */
262 #define SKIP_THIS_AND_ARTIFICIAL_PARMS(C,M)                     \
263   {                                                             \
264     int i;                                                      \
265     (C) = TYPE_ARG_TYPES (TREE_TYPE ((M)));                     \
266     if (!METHOD_STATIC ((M)))                                   \
267       (C) = TREE_CHAIN (C);                                     \
268     if (DECL_CONSTRUCTOR_P ((M))                                \
269         && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT ((M))))        \
270       (C) = TREE_CHAIN (C);                                     \
271     if (!DECL_FINIT_P ((M)))                                    \
272       for (i = DECL_FUNCTION_NAP ((M)); i; i--)                 \
273        (C) = TREE_CHAIN (C);                                    \
274   }
275
276 /* Mark final parameters in method M, by comparison of the argument
277    list L. This macro is used to set the flag once the method has been
278    build.  */
279 #define MARK_FINAL_PARMS(M, L)                                          \
280   {                                                                     \
281     tree current = TYPE_ARG_TYPES (TREE_TYPE ((M)));                    \
282     tree list = (L);                                                    \
283     if (!METHOD_STATIC ((M)))                                           \
284       current = TREE_CHAIN (current);                                   \
285     for (; current !=  end_params_node;                                 \
286          current = TREE_CHAIN (current), list = TREE_CHAIN (list))      \
287       ARG_FINAL_P (current) = ARG_FINAL_P (list);                       \
288     if (current != list)                                                \
289       fatal ("MARK_FINAL_PARMS");                                       \
290   }
291
292 /* Reset the ARG_FINAL_P that might have been set in method M args.  */
293 #define UNMARK_FINAL_PARMS(M)                                           \
294   {                                                                     \
295     tree current;                                                       \
296     for (current = TYPE_ARG_TYPES (TREE_TYPE ((M)));                    \
297          current != end_params_node; current = TREE_CHAIN (current))    \
298       ARG_FINAL_P (current) = 0;                                        \
299   }
300
301 /* Reverse a crafted parameter list as required.  */
302 #define CRAFTED_PARAM_LIST_FIXUP(P)             \
303   {                                             \
304     if ((P))                                    \
305       {                                         \
306         tree last = (P);                        \
307         (P) = nreverse (P);                     \
308         TREE_CHAIN (last) = end_params_node;    \
309       }                                         \
310     else                                        \
311       (P) = end_params_node;                    \
312   }
313
314 /* Modes governing the creation of a alias initializer parameter
315    lists. AIPL stands for Alias Initializer Parameter List.  */
316 enum {
317   AIPL_FUNCTION_CREATION,         /* Suitable for artificial method creation */
318   AIPL_FUNCTION_DECLARATION,      /* Suitable for declared methods */
319   AIPL_FUNCTION_CTOR_INVOCATION,  /* Invocation of constructors */
320   AIPL_FUNCTION_FINIT_INVOCATION  /* Invocation of $finit$ */
321 };
322
323 /* Standard error messages */
324 #define ERROR_CANT_CONVERT_TO_BOOLEAN(OPERATOR, NODE, TYPE)             \
325   parse_error_context ((OPERATOR),                                      \
326     "Incompatible type for `%s'. Can't convert `%s' to boolean",        \
327     operator_string ((NODE)), lang_printable_name ((TYPE),0))
328
329 #define ERROR_CANT_CONVERT_TO_NUMERIC(OPERATOR, NODE, TYPE)             \
330   parse_error_context ((OPERATOR),                                      \
331       "Incompatible type for `%s'. Can't convert `%s' to numeric type", \
332       operator_string ((NODE)), lang_printable_name ((TYPE), 0))
333
334 #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE)             \
335 do {                                                                    \
336   tree _operator = (OPERATOR), _node = (NODE), _type = (TYPE);          \
337   if (JPRIMITIVE_TYPE_P (_type))                                        \
338     parse_error_context (_operator,                                     \
339 "Incompatible type for `%s'. Explicit cast needed to convert `%s' to integral",\
340                          operator_string(_node),                        \
341                          lang_printable_name (_type, 0));               \
342   else                                                                  \
343     parse_error_context (_operator,                                     \
344       "Incompatible type for `%s'. Can't convert `%s' to integral",     \
345                          operator_string(_node),                        \
346                          lang_printable_name (_type, 0));               \
347 } while (0)
348
349 #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V)                  \
350   parse_error_context                                           \
351     ((WFL), "Variable `%s' may not have been initialized",      \
352      IDENTIFIER_POINTER (V))
353
354 /* Definition for loop handling. This is Java's own definition of a
355    loop body. See parse.y for documentation. It's valid once you hold
356    a loop's body (LOOP_EXPR_BODY) */
357
358 /* The loop main block is the one hold the condition and the loop body */
359 #define LOOP_EXPR_BODY_MAIN_BLOCK(NODE) TREE_OPERAND (NODE, 0)
360 /* And then there is the loop update block */
361 #define LOOP_EXPR_BODY_UPDATE_BLOCK(NODE) TREE_OPERAND (NODE, 1)
362
363 /* Inside the loop main block, there is the loop condition and the
364    loop body. They may be reversed if the loop being described is a
365    do-while loop. NOTE: if you use a WFL around the EXIT_EXPR so you
366    can issue debug info for it, the EXIT_EXPR will be one operand
367    further. */
368 #define LOOP_EXPR_BODY_CONDITION_EXPR(NODE, R)                  \
369   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 1 : 0))
370
371 /* Here is the labeled block the loop real body is encapsulated in */
372 #define LOOP_EXPR_BODY_LABELED_BODY(NODE, R)                    \
373   TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 0 : 1))
374 /* And here is the loop's real body */
375 #define LOOP_EXPR_BODY_BODY_EXPR(NODE, R)                       \
376   LABELED_BLOCK_BODY (LOOP_EXPR_BODY_LABELED_BODY(NODE, R))
377
378 #define PUSH_LABELED_BLOCK(B)                           \
379   {                                                     \
380     TREE_CHAIN (B) = ctxp->current_labeled_block;       \
381     ctxp->current_labeled_block = (B);                  \
382   }
383 #define POP_LABELED_BLOCK()                                             \
384   ctxp->current_labeled_block = TREE_CHAIN (ctxp->current_labeled_block)
385
386 #define PUSH_LOOP(L)                            \
387   {                                             \
388     TREE_CHAIN (L) = ctxp->current_loop;        \
389     ctxp->current_loop = (L);                   \
390   }
391 #define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
392
393 #define PUSH_EXCEPTIONS(E)                                      \
394   currently_caught_type_list =                                  \
395     tree_cons (NULL_TREE, (E), currently_caught_type_list);
396
397 #define POP_EXCEPTIONS()                                                \
398   currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
399
400 /* Check that we're inside a try block.  */
401 #define IN_TRY_BLOCK_P()                                \
402   (currently_caught_type_list                           \
403    && ((TREE_VALUE (currently_caught_type_list) !=      \
404         DECL_FUNCTION_THROWS (current_function_decl))   \
405        || TREE_CHAIN (currently_caught_type_list)))
406
407 /* Check that we have exceptions in E.  */
408 #define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
409
410 /* Anonymous array access */
411 #define ANONYMOUS_ARRAY_BASE_TYPE(N)   TREE_OPERAND ((N), 0)
412 #define ANONYMOUS_ARRAY_DIMS_SIG(N)    TREE_OPERAND ((N), 1)
413 #define ANONYMOUS_ARRAY_INITIALIZER(N) TREE_OPERAND ((N), 2)
414
415 /* Invocation modes, as returned by invocation_mode (). */
416 enum {
417   INVOKE_STATIC,
418   INVOKE_NONVIRTUAL,
419   INVOKE_SUPER,
420   INVOKE_INTERFACE,
421   INVOKE_VIRTUAL
422 };
423
424 /* We need the resolution stuff only if we compile jc1 */
425 #ifndef JC1_LITE
426
427 /* Unresolved type identifiers handling. When we process the source
428    code, we blindly accept an unknown type identifier and try to
429    resolve it later. When an unknown type identifier is encountered
430    and used, we record in a struct jdep element what the incomplete
431    type is and what it should patch. Later, java_complete_class will
432    process all classes known to have unresolved type
433    dependencies. Within each of these classes, this routine will
434    process unresolved type dependencies (JDEP_TO_RESOLVE), patch what
435    needs to be patched in the dependent tree node (JDEP_GET_PATCH,
436    JDEP_APPLY_PATCH) and perform other actions dictated by the context
437    of the patch (JDEP_KIND). The ideas are: we patch only what needs
438    to be patched, and with java_complete_class called at the right
439    time, we will start processing incomplete function bodies tree
440    nodes with everything external to function's bodies already
441    completed, it makes things much simpler. */
442
443 enum jdep_code {
444   JDEP_NO_PATCH,                /* Must be first */
445   JDEP_SUPER,                   /* Patch the type of one type
446                                    supertype. Requires some check
447                                    before it's done */
448   JDEP_FIELD,                   /* Patch the type of a class field */
449
450   /* JDEP_{METHOD,METHOD_RETURN,METHOD_END} to be kept in order */
451   JDEP_METHOD,                  /* Mark the beginning of the patching
452                                    of a method declaration, including
453                                    it's arguments */
454   JDEP_METHOD_RETURN,           /* Mark the beginning of the patching
455                                    of a method declaration. Arguments
456                                    aren't patched, only the returned
457                                    type is */
458   JDEP_METHOD_END,              /* Mark the end of the patching of a
459                                    method declaration. It indicates
460                                    that it's time to compute and
461                                    install a new signature */
462
463   JDEP_INTERFACE,               /* Patch the type of a Class/interface
464                                    extension */
465   JDEP_VARIABLE,                /* Patch the type of a variable declaration */
466   JDEP_PARM,                    /* Patch the type of a parm declaration */
467   JDEP_TYPE,                    /* Patch a random tree node type,
468                                    without the need for any specific
469                                    actions */
470   JDEP_EXCEPTION,               /* Patch exceptions specified by `throws' */
471   JDEP_ANONYMOUS                /* Patch anonymous classes
472                                    (implementation or extension.) */
473
474 };
475
476 typedef struct _jdep {
477   ENUM_BITFIELD(jdep_code) kind : 8; /* Type of patch */
478
479   int  flag0 : 1;               /* Some flags */
480   tree decl;                    /* Tied decl/or WFL */
481   tree solv;                    /* What to solve */
482   tree wfl;                     /* Where thing to resolve where found */
483   tree misc;                    /* Miscellaneous info (optional). */
484   tree enclosing;               /* The enclosing (current) class */
485   tree *patch;                  /* Address of a location to patch */
486   struct _jdep *next;           /* Linked list */
487 } jdep;
488
489
490 #define JDEP_DECL(J)          ((J)->decl)
491 #define JDEP_DECL_WFL(J)      ((J)->decl)
492 #define JDEP_KIND(J)          ((J)->kind)
493 #define JDEP_SOLV(J)          ((J)->solv)
494 #define JDEP_WFL(J)           ((J)->wfl)
495 #define JDEP_MISC(J)          ((J)->misc)
496 #define JDEP_ENCLOSING(J)     ((J)->enclosing)
497 #define JDEP_CLASS(J)         ((J)->class)
498 #define JDEP_APPLY_PATCH(J,P) (*(J)->patch = (P))
499 #define JDEP_GET_PATCH(J)     ((J)->patch)
500 #define JDEP_CHAIN(J)         ((J)->next)
501 #define JDEP_TO_RESOLVE(J)    ((J)->solv)
502 #define JDEP_RESOLVED_DECL(J) ((J)->solv)
503 #define JDEP_RESOLVED(J, D)   ((J)->solv = D)
504 #define JDEP_RESOLVED_P(J)    \
505         (!(J)->solv || TREE_CODE ((J)->solv) != POINTER_TYPE)
506
507 typedef struct _jdeplist {
508   jdep *first;
509   jdep *last;
510   struct _jdeplist *next;
511 } jdeplist;
512
513 #endif /* JC1_LITE */
514
515 #define CLASSD_FIRST(CD) ((CD)->first)
516 #define CLASSD_LAST(CD)  ((CD)->last)
517 #define CLASSD_CHAIN(CD) ((CD)->next)
518
519 #define JDEP_INSERT(L,J)                        \
520   {                                             \
521     if (!(L)->first)                            \
522       (L)->last = (L)->first = (J);             \
523     else                                        \
524       {                                         \
525         JDEP_CHAIN ((L)->last) = (J);           \
526         (L)->last = (J);                        \
527       }                                         \
528   }
529
530 /* if TYPE can't be resolved, obtain something suitable for its
531    resolution (TYPE is saved in SAVE before being changed). and set
532    CHAIN to 1. Otherwise, type is set to something usable. CHAIN is
533    usually used to determine that a new DEP must be installed on TYPE.
534    Note that when compiling java.lang.Object, references to Object are
535    java.lang.Object.  */
536 #define SET_TYPE_FOR_RESOLUTION(TYPE, SAVE, CHAIN)                      \
537   {                                                                     \
538     tree returned_type;                                                 \
539     (CHAIN) = 0;                                                        \
540     if (TREE_TYPE (ctxp->current_parsed_class) == object_type_node      \
541         && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION                  \
542         && EXPR_WFL_NODE (TYPE) == unqualified_object_id_node)          \
543       (TYPE) = object_type_node;                                        \
544     else                                                                \
545       {                                                                 \
546         if (unresolved_type_p (type, &returned_type))                   \
547           {                                                             \
548             if (returned_type)                                          \
549               (TYPE) = returned_type;                                   \
550             else                                                        \
551               {                                                         \
552                 (SAVE) = (TYPE);                                        \
553                 (TYPE) = obtain_incomplete_type (TYPE);                 \
554                 CHAIN = 1;                                              \
555               }                                                         \
556           }                                                             \
557       }                                                                 \
558   }
559 /* Promote a type if it won't be registered as a patch */
560 #define PROMOTE_RECORD_IF_COMPLETE(TYPE, IS_INCOMPLETE)         \
561   {                                                             \
562     if (!(IS_INCOMPLETE) && TREE_CODE (TYPE) == RECORD_TYPE)    \
563       (TYPE) = promote_type (TYPE);                             \
564   }
565
566 /* Insert a DECL in the current block */
567 #define BLOCK_CHAIN_DECL(NODE)                                              \
568   {                                                                         \
569     TREE_CHAIN ((NODE)) =                                                   \
570       BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl));         \
571     BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl)) = (NODE);  \
572   }
573
574 /* Return the current block, either found in the body of the currently
575    declared function or in the current static block being defined. */
576 #define GET_CURRENT_BLOCK(F) ((F) ? DECL_FUNCTION_BODY ((F)) :  \
577                              current_static_block)
578
579 /* For an artificial BLOCK (created to house a local variable declaration not
580    at the start of an existing block), the parent block;  otherwise NULL. */
581 #define BLOCK_EXPR_ORIGIN(NODE) BLOCK_ABSTRACT_ORIGIN(NODE)
582
583 /* Merge an other line to the source line number of a decl. Used to
584    remember function's end. */
585 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
586
587 /* Retrieve those two info separately. */
588 #define DECL_SOURCE_LINE_FIRST(DECL)    (DECL_SOURCE_LINE(DECL) & 0x0000ffff)
589 #define DECL_SOURCE_LINE_LAST(DECL)     (DECL_SOURCE_LINE(DECL) >> 16)
590
591 /* Retrieve line/column from a WFL. */
592 #define EXPR_WFL_GET_LINECOL(V,LINE,COL)        \
593   {                                             \
594      (LINE) = (V) >> 12;                        \
595      (COL) = (V) & 0xfff;                       \
596    }
597 /* Add X to the column number information */
598 #define EXPR_WFL_ADD_COL(V, X)                                  \
599   (V) = (((V) & 0xfffff000) | ((((V) & 0xfff) + (X)) & 0xfff))
600
601 /* Build a WFL for expression nodes */
602 #define BUILD_EXPR_WFL(NODE, WFL)                                       \
603   build_expr_wfl ((NODE), input_filename, EXPR_WFL_LINENO ((WFL)),      \
604                   EXPR_WFL_COLNO ((WFL)))
605
606 #define EXPR_WFL_QUALIFICATION(WFL) TREE_OPERAND ((WFL), 2)
607 #define QUAL_WFL(NODE) TREE_PURPOSE (NODE)
608 #define QUAL_RESOLUTION(NODE) TREE_VALUE (NODE)
609 #define QUAL_DECL_TYPE(NODE) GET_SKIP_TYPE (NODE)
610
611 #define GET_SKIP_TYPE(NODE)                             \
612   (TREE_CODE (TREE_TYPE (NODE)) == POINTER_TYPE ?       \
613    TREE_TYPE (TREE_TYPE (NODE)): TREE_TYPE (NODE))
614
615 /* Handy macros for the walk operation */
616 #define COMPLETE_CHECK_OP(NODE, N)                      \
617 {                                                       \
618   TREE_OPERAND ((NODE), (N)) =                          \
619     java_complete_tree (TREE_OPERAND ((NODE), (N)));    \
620   if (TREE_OPERAND ((NODE), (N)) == error_mark_node)    \
621     return error_mark_node;                             \
622 }
623 #define COMPLETE_CHECK_OP_0(NODE) COMPLETE_CHECK_OP(NODE, 0)
624 #define COMPLETE_CHECK_OP_1(NODE) COMPLETE_CHECK_OP(NODE, 1)
625 #define COMPLETE_CHECK_OP_2(NODE) COMPLETE_CHECK_OP(NODE, 2)
626
627 /* Building invocations: append(ARG) and StringBuffer(ARG) */
628 #define BUILD_APPEND(ARG)                                                     \
629   ((JSTRING_TYPE_P (TREE_TYPE (ARG)) || JPRIMITIVE_TYPE_P (TREE_TYPE (ARG)))  \
630    ? build_method_invocation (wfl_append,                                     \
631                               ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE)\
632    : build_method_invocation (wfl_append,                                     \
633                               ARG ? build_tree_list (NULL,                    \
634                                                      build1 (CONVERT_EXPR,    \
635                                                              object_type_node,\
636                                                              (ARG)))          \
637                               : NULL_TREE))
638 #define BUILD_STRING_BUFFER(ARG)                                              \
639   build_new_invocation (wfl_string_buffer,                                    \
640                         (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
641
642 /* For exception handling, build diverse function calls */
643 #define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO)          \
644   {                                                     \
645     (WHERE) = build (MODIFY_EXPR, void_type_node, (TO), \
646                      soft_exceptioninfo_call_node);     \
647     TREE_SIDE_EFFECTS (WHERE) = 1;                      \
648   }
649
650 #define BUILD_THROW(WHERE, WHAT)                                            \
651   {                                                                         \
652     (WHERE) =                                                               \
653       build (CALL_EXPR, void_type_node,                                     \
654              build_address_of (throw_node[exceptions_via_longjmp ? 1 : 0]), \
655              build_tree_list (NULL_TREE, (WHAT)), NULL_TREE);               \
656     TREE_SIDE_EFFECTS ((WHERE)) = 1;                                        \
657   }
658
659 /* Set wfl_operator for the most accurate error location */
660 #define SET_WFL_OPERATOR(WHICH, NODE, WFL)              \
661   EXPR_WFL_LINECOL (WHICH) =                            \
662     (TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ?       \
663      EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
664
665 #define PATCH_METHOD_RETURN_ERROR()             \
666   {                                             \
667     if (ret_decl)                               \
668       *ret_decl = NULL_TREE;                    \
669     return error_mark_node;                     \
670   }
671
672 /* Convenient macro to check. Assumes that CLASS is a CLASS_DECL.  */
673 #define CHECK_METHODS(CLASS)                    \
674   {                                             \
675     if (CLASS_INTERFACE ((CLASS)))              \
676       java_check_abstract_methods ((CLASS));    \
677     else                                        \
678       java_check_regular_methods ((CLASS));     \
679   }
680
681 /* Using and reseting the @deprecated tag flag */
682 #define CHECK_DEPRECATED(DECL)                  \
683   {                                             \
684     if (ctxp->deprecated)                       \
685       DECL_DEPRECATED (DECL) = 1;               \
686     ctxp->deprecated = 0;                       \
687   }
688
689 /* Register an import */
690 #define REGISTER_IMPORT(WHOLE, NAME)                    \
691 {                                                       \
692   IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1;     \
693   node = build_tree_list ((WHOLE), (NAME));             \
694   TREE_CHAIN (node) = ctxp->import_list;                \
695   ctxp->import_list = node;                             \
696 }
697
698 /* Macro to access the osb (opening square bracket) count */
699 #define CURRENT_OSB(C) (C)->osb_number [(C)->osb_depth]
700
701 /* Macro for the xreferencer */
702 #define DECL_END_SOURCE_LINE(DECL)       DECL_FRAME_SIZE (DECL)
703 #define DECL_INHERITED_SOURCE_LINE(DECL) (DECL_CHECK (DECL)->decl.u2.i)
704      
705 /* Parser context data structure. */
706 struct parser_ctxt {
707
708   char *filename;                   /* Current filename */
709   FILE *finput;                     /* Current file input stream */
710   struct parser_ctxt *next;
711
712   char marker_begining;              /* Marker. Should be a sub-struct */
713   struct java_line *p_line, *c_line; /* Previous and current line */
714   java_lc elc;                       /* Error's line column info */
715   unicode_t unget_utf8_value;        /* An unget utf8 value */
716   int ccb_indent;                    /* Keep track of {} indent, lexer */
717   int first_ccb_indent1;             /* First { at ident level 1 */
718   int last_ccb_indent1;              /* Last } at ident level 1 */
719   int parser_ccb_indent;             /* Keep track of {} indent, parser */
720   int osb_depth;                     /* Current depth of [ in an expression */
721   int osb_limit;                     /* Limit of this depth */
722   int *osb_number;                   /* Keep track of ['s */
723   int lineno;                        /* Current lineno */
724   char marker_end;                   /* End marker. Should be a sub-struct */
725
726   /* The flags section */
727
728   /* Indicates a context used for saving the parser status. The
729      context must be popped when the status is restored. */
730   unsigned saved_data_ctx:1;    
731   /* Indicates that a context already contains saved data and that the
732      next save operation will require a new context to be created. */
733   unsigned saved_data:1;
734   /* Integral literal overflow */
735   unsigned minus_seen:1;
736   /* Report error when true */
737   unsigned java_error_flag:1;
738   /* @deprecated tag seen */
739   unsigned deprecated:1;
740   /* Flag to report certain errors (fix this documentation. FIXME) */
741   unsigned class_err:1;
742
743   /* This section is defined only if we compile jc1 */
744 #ifndef JC1_LITE
745   tree modifier_ctx [11];           /* WFL of modifiers */
746   tree current_class;               /* Current class */
747   tree current_function_decl;       /* Current function decl, save/restore */
748
749   struct JCF *current_jcf;          /* CU jcf */
750
751   int prevent_ese;                  /* Prevent expression statement error */
752
753   int formal_parameter_number;      /* Number of parameters found */
754   int interface_number;             /* # itfs declared to extend an itf def */
755
756   tree package;                     /* Defined package ID */
757
758   /* Those two list are saved accross file traversal */
759   tree  incomplete_class;           /* List of non-complete classes */
760   tree  gclass_list;                /* All classes seen from source code */
761
762   /* These two lists won't survive file traversal */
763   tree  class_list;                 /* List of classes in a CU */
764   jdeplist *classd_list;            /* Classe dependencies in a CU */
765   
766   tree  current_parsed_class;       /* Class currently parsed */
767   tree  current_parsed_class_un;    /* Curr. parsed class unqualified name */
768
769   tree non_static_initialized;      /* List of non static initialized fields */
770   tree static_initialized;          /* List of static non final initialized */
771   tree instance_initializers;       /* List of instancei initializers stmts */
772
773   tree import_list;                 /* List of import */
774   tree import_demand_list;          /* List of import on demand */
775
776   tree current_loop;                /* List of the currently nested 
777                                        loops/switches */
778   tree current_labeled_block;       /* List of currently nested
779                                        labeled blocks. */
780
781   int pending_block;                /* Pending block to close */
782
783   int explicit_constructor_p;       /* >0 when processing an explicit
784                                        constructor. This flag is used to trap
785                                        illegal argument usage during an
786                                        explicit constructor invocation. */
787 #endif /* JC1_LITE */
788 };
789
790 /* A set of macros to push/pop/access the currently parsed class.  */
791 #define GET_CPC_LIST()     ctxp->current_parsed_class
792
793 /* Currently class being parsed is an inner class if an enclosing
794    class has been already pushed. This truth value is only valid prior
795    an inner class is pushed. After, use FIXME. */
796 #define CPC_INNER_P() GET_CPC_LIST ()
797
798 /* Get the currently parsed class DECL_TYPE node.  */
799 #define GET_CPC() TREE_VALUE (GET_CPC_LIST ())
800
801 /* Get the currently parsed class unqualified IDENTIFIER_NODE.  */
802 #define GET_CPC_UN() TREE_PURPOSE (GET_CPC_LIST ())
803
804 /* Get a parsed class unqualified IDENTIFIER_NODE from its CPC node.  */
805 #define GET_CPC_UN_NODE(N) TREE_PURPOSE (N)
806
807 /* Get the currently parsed class DECL_TYPE from its CPC node.  */
808 #define GET_CPC_DECL_NODE(N) TREE_VALUE (N)
809
810 /* The currently parsed enclosing currently parsed TREE_LIST node.  */
811 #define GET_ENCLOSING_CPC() TREE_CHAIN (GET_CPC_LIST ())
812
813 /* Get the next enclosing context.  */
814 #define GET_NEXT_ENCLOSING_CPC(C) TREE_CHAIN (C)
815
816 /* The DECL_TYPE node of the enclosing currently parsed
817    class. NULL_TREE if the currently parsed class isn't an inner
818    class.  */
819 #define GET_ENCLOSING_CPC_CONTEXT() (GET_ENCLOSING_CPC () ?                   \
820                                      TREE_VALUE (GET_ENCLOSING_CPC ()) :      \
821                                      NULL_TREE)
822
823 /* Make sure that innerclass T sits in an appropriate enclosing
824    context.  */
825 #define INNER_ENCLOSING_SCOPE_CHECK(T)                                  \
826   (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T))                 \
827    && ((current_this                                                    \
828         /* We have a this and it's not the right one */                 \
829         && (DECL_CONTEXT (TYPE_NAME ((T)))                              \
830             != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))        \
831         && !inherits_from_p (TREE_TYPE (TREE_TYPE (current_this)),      \
832                              TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T))))) \
833        /* We don't have a this. */                                      \
834        || !current_this))
835
836 /* Push macro. First argument to PUSH_CPC is a DECL_TYPE, second
837    argument is the unqualified currently parsed class name.  */
838 #define PUSH_CPC(C,R) {                                         \
839                         ctxp->current_parsed_class =            \
840                         tree_cons ((R), (C), GET_CPC_LIST ());  \
841                       }
842
843 /* In case of an error, push an error.  */
844 #define PUSH_ERROR() PUSH_CPC (error_mark_node, error_mark_node)
845
846 /* Pop macro. Before we pop, we link the current inner class decl (if any)
847    to its enclosing class.  */
848 #define POP_CPC() {                                     \
849                     link_nested_class_to_enclosing ();  \
850                     ctxp->current_parsed_class =        \
851                       TREE_CHAIN (GET_CPC_LIST ());     \
852                   }
853
854 #define DEBUG_CPC()                                             \
855   do                                                            \
856     {                                                           \
857       tree tmp =  ctxp->current_parsed_class;                   \
858       while (tmp)                                               \
859         {                                                       \
860           fprintf (stderr, "%s ",                               \
861                    IDENTIFIER_POINTER (TREE_PURPOSE (tmp)));    \
862           tmp = TREE_CHAIN (tmp);                               \
863         }                                                       \
864     }                                                           \
865   while (0);
866
867 /* Access to the various initializer statement lists */
868 #define CPC_INITIALIZER_LIST(C)          ((C)->non_static_initialized)
869 #define CPC_STATIC_INITIALIZER_LIST(C)   ((C)->static_initialized)
870 #define CPC_INSTANCE_INITIALIZER_LIST(C) ((C)->instance_initializers)
871
872 /* Access to the various initializer statements */
873 #define CPC_INITIALIZER_STMT(C) (TREE_PURPOSE (CPC_INITIALIZER_LIST (C)))
874 #define CPC_STATIC_INITIALIZER_STMT(C) \
875   (TREE_PURPOSE (CPC_STATIC_INITIALIZER_LIST (C)))
876 #define CPC_INSTANCE_INITIALIZER_STMT(C) \
877   (TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)))
878
879 /* Set various initializer statements */
880 #define SET_CPC_INITIALIZER_STMT(C,S)                   \
881   if (CPC_INITIALIZER_LIST (C))                         \
882     TREE_PURPOSE (CPC_INITIALIZER_LIST (C)) = (S);
883 #define SET_CPC_STATIC_INITIALIZER_STMT(C,S)                    \
884   if (CPC_STATIC_INITIALIZER_LIST (C))                          \
885     TREE_PURPOSE (CPC_STATIC_INITIALIZER_LIST (C)) = (S);
886 #define SET_CPC_INSTANCE_INITIALIZER_STMT(C,S)                  \
887   if (CPC_INSTANCE_INITIALIZER_LIST(C))                         \
888     TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)) = (S);
889
890 #ifndef JC1_LITE
891 void java_complete_class PARAMS ((void));
892 void java_check_circular_reference PARAMS ((void));
893 void java_fix_constructors PARAMS ((void));
894 void java_layout_classes PARAMS ((void));
895 void java_reorder_fields PARAMS ((void));
896 tree java_method_add_stmt PARAMS ((tree, tree));
897 void java_expand_switch PARAMS ((tree));
898 int java_report_errors PARAMS ((void));
899 extern tree do_resolve_class PARAMS ((tree, tree, tree, tree));
900 #endif
901 char *java_get_line_col PARAMS ((char *, int, int));
902 extern void reset_report PARAMS ((void));
903
904 /* Always in use, no matter what you compile */
905 void java_push_parser_context PARAMS ((void));
906 void java_pop_parser_context PARAMS ((int));
907 void java_init_lex PARAMS ((void));
908 extern void java_parser_context_save_global PARAMS ((void));
909 extern void java_parser_context_restore_global PARAMS ((void));
910 int yyparse PARAMS ((void));
911 extern int java_parse PARAMS ((void));
912 void yyerror PARAMS ((const char *));
913 extern void java_expand_classes PARAMS ((void));
914 #endif