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