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