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