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