1 /* Language parser definitions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
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)
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
32 /* Extern global variable declarations */
33 extern int java_error_count;
34 extern struct obstack temporary_obstack;
35 extern int quiet_flag;
38 /* Function extern to java/ */
39 extern int int_fits_type_p PARAMS ((tree, tree));
40 extern tree stabilize_reference PARAMS ((tree));
43 /* Macros for verbose debug info */
44 #ifdef VERBOSE_SKELETON
45 #define RULE( rule ) printf ( "jv_yacc:%d: rule %s\n", lineno, rule )
50 #ifdef VERBOSE_SKELETON
51 #undef SOURCE_FRONTEND_DEBUG
52 #define SOURCE_FRONTEND_DEBUG(X) \
53 {if (!quiet_flag) {printf ("* "); printf X; putchar ('\n');} }
55 #define SOURCE_FRONTEND_DEBUG(X)
58 /* Macro for error recovering */
61 { if (!quiet_flag) {printf ("** Recovered\n");} }
62 #define DRECOVERED(s) \
63 { if (!quiet_flag) {printf ("** Recovered (%s)\n", #s);}}
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 != lineno)
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| \
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 #define THIS_MODIFIER_ONLY(f, m, v, count, l) \
95 tree node = MODIFIER_WFL (v); \
97 && ((EXPR_WFL_COLNO (node) > EXPR_WFL_COLNO (l)) \
98 || (EXPR_WFL_LINENO (node) > EXPR_WFL_LINENO (l)))) \
105 #define ABSTRACT_CHECK(FLAG, V, CL, S) \
107 parse_error_context ((CL), "%s method can't be abstract", (S));
109 #define JCONSTRUCTOR_CHECK(FLAG, V, CL, S) \
111 parse_error_context ((CL), "Constructor can't be %s", (S)); \
114 #define exit_java_complete_class() \
119 #define CLASS_OR_INTERFACE(decl, s1, s2) \
121 ((get_access_flags_from_decl (TYPE_NAME (TREE_TYPE (decl))) \
123 s2 : s1) : ((s1 [0]=='S'|| s1 [0]=='s') ? \
124 (s1 [0]=='S' ? "Supertype" : "supertype") : \
125 (s1 [0] > 'A' ? "Type" : "type")))
127 #define GET_REAL_TYPE(TYPE) \
128 (TREE_CODE (TYPE) == TREE_LIST ? TREE_PURPOSE (TYPE) : TYPE)
130 /* Get TYPE name string, regardless whether TYPE is a class or an
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))))
137 /* Pedantic warning on obsolete modifiers. Note: when cl is NULL,
138 flags was set artificially, such as for a interface method */
139 #define OBSOLETE_MODIFIER_WARNING(cl, flags, __modifier, arg) \
141 if (flag_redundant && (cl) && ((flags) & (__modifier))) \
142 parse_warning_context (cl, \
143 "Discouraged redundant use of `%s' modifier in declaration of %s", \
144 java_accstring_lookup (__modifier), arg); \
146 #define OBSOLETE_MODIFIER_WARNING2(cl, flags, __modifier, arg1, arg2) \
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);\
154 /* Quickly build a temporary pointer on hypothetical type NAME. */
155 #define BUILD_PTR_FROM_NAME(ptr, name) \
157 ptr = build (POINTER_TYPE, NULL_TREE); \
158 TYPE_NAME (ptr) = name; \
161 #define INCOMPLETE_TYPE_P(NODE) \
162 ((TREE_CODE (NODE) == POINTER_TYPE) \
163 && !TREE_TYPE (NODE) \
164 && TREE_CODE (TYPE_NAME (NODE)) == IDENTIFIER_NODE)
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)
172 /* Types classification, according to the JLS, section 4.2 */
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))
184 #define JBSC_TYPE_P(TYPE) ((TYPE) && (((TYPE) == byte_type_node) \
185 || ((TYPE) == short_type_node) \
186 || ((TYPE) == char_type_node)))
188 /* Not defined in the LRM */
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))))
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)) == \
203 #define JNULLP_TYPE_P(TYPE) ((TYPE) && (TREE_CODE (TYPE) == POINTER_TYPE) \
204 && (TYPE) == TREE_TYPE (null_pointer_node))
206 /* Other predicates */
207 #define JDECL_P(NODE) (NODE && (TREE_CODE (NODE) == PARM_DECL \
208 || TREE_CODE (NODE) == VAR_DECL \
209 || TREE_CODE (NODE) == FIELD_DECL))
211 #define TYPE_INTERFACE_P(TYPE) \
212 (CLASS_P (TYPE) && CLASS_INTERFACE (TYPE_NAME (TYPE)))
214 #define TYPE_CLASS_P(TYPE) (CLASS_P (TYPE) \
215 && !CLASS_INTERFACE (TYPE_NAME (TYPE)))
217 /* Identifier business related to 1.1 language extensions. */
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')
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) \
229 char *mangled_name; \
230 obstack_grow (&temporary_obstack, "val$", 4); \
231 obstack_grow (&temporary_obstack, \
232 IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O))); \
233 obstack_1grow (&temporary_obstack, '\0'); \
234 mangled_name = obstack_finish (&temporary_obstack); \
235 (N) = get_identifier (mangled_name); \
236 obstack_free (&temporary_obstack, mangled_name); \
239 /* Build the string parm$<O> and store in into the identifier N. This
240 is used to construct the name of hidden parameters used to
241 initialize outer scope aliases. */
242 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID(N, O) \
244 char *mangled_name; \
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'); \
249 mangled_name = obstack_finish (&temporary_obstack); \
250 (N) = get_identifier (mangled_name); \
251 obstack_free (&temporary_obstack, mangled_name); \
254 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR(N, S) \
256 char *mangled_name; \
257 obstack_grow (&temporary_obstack, "parm$", 5); \
258 obstack_grow (&temporary_obstack, (S), strlen ((S))); \
259 obstack_1grow (&temporary_obstack, '\0'); \
260 mangled_name = obstack_finish (&temporary_obstack); \
261 (N) = get_identifier (mangled_name); \
262 obstack_free (&temporary_obstack, mangled_name); \
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) \
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); \
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
285 #define MARK_FINAL_PARMS(M, L) \
287 tree current = TYPE_ARG_TYPES (TREE_TYPE ((M))); \
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) \
298 /* Reset the ARG_FINAL_P that might have been set in method M args. */
299 #define UNMARK_FINAL_PARMS(M) \
302 for (current = TYPE_ARG_TYPES (TREE_TYPE ((M))); \
303 current != end_params_node; current = TREE_CHAIN (current)) \
304 ARG_FINAL_P (current) = 0; \
307 /* Reverse a crafted parameter list as required. */
308 #define CRAFTED_PARAM_LIST_FIXUP(P) \
313 (P) = nreverse (P); \
314 TREE_CHAIN (last) = end_params_node; \
317 (P) = end_params_node; \
320 /* Modes governing the creation of a alias initializer parameter
321 lists. AIPL stands for Alias Initializer Parameter List. */
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$ */
329 /* Standard error messages */
330 #define ERROR_CANT_CONVERT_TO_BOOLEAN(OPERATOR, NODE, TYPE) \
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))
335 #define ERROR_CANT_CONVERT_TO_NUMERIC(OPERATOR, NODE, TYPE) \
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))
340 #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE) \
342 tree _operator = (OPERATOR), _node = (NODE), _type = (TYPE); \
343 if (JPRIMITIVE_TYPE_P (_type)) \
344 parse_error_context (_operator, \
345 "Incompatible type for `%s'. Explicit cast needed to convert `%s' to integral",\
346 operator_string(_node), \
347 lang_printable_name (_type, 0)); \
349 parse_error_context (_operator, \
350 "Incompatible type for `%s'. Can't convert `%s' to integral", \
351 operator_string(_node), \
352 lang_printable_name (_type, 0)); \
355 #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V) \
356 parse_error_context \
357 ((WFL), "Variable `%s' may not have been initialized", \
358 IDENTIFIER_POINTER (V))
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) */
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)
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
374 #define LOOP_EXPR_BODY_CONDITION_EXPR(NODE, R) \
375 TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 1 : 0))
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))
384 #define PUSH_LABELED_BLOCK(B) \
386 TREE_CHAIN (B) = ctxp->current_labeled_block; \
387 ctxp->current_labeled_block = (B); \
389 #define POP_LABELED_BLOCK() \
390 ctxp->current_labeled_block = TREE_CHAIN (ctxp->current_labeled_block)
392 #define PUSH_LOOP(L) \
394 TREE_CHAIN (L) = ctxp->current_loop; \
395 ctxp->current_loop = (L); \
397 #define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
399 #define PUSH_EXCEPTIONS(E) \
400 currently_caught_type_list = \
401 tree_cons (NULL_TREE, (E), currently_caught_type_list);
403 #define POP_EXCEPTIONS() \
404 currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
406 /* Check that we're inside a try block. */
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)))
413 /* Check that we have exceptions in E. */
414 #define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
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)
421 /* Invocation modes, as returned by invocation_mode (). */
430 /* We need the resolution stuff only if we compile jc1 */
433 /* Unresolved type identifiers handling. When we process the source
434 code, we blindly accept an unknown type identifier and try to
435 resolve it later. When an unknown type identifier is encountered
436 and used, we record in a struct jdep element what the incomplete
437 type is and what it should patch. Later, java_complete_class will
438 process all classes known to have unresolved type
439 dependencies. Within each of these classes, this routine will
440 process unresolved type dependencies (JDEP_TO_RESOLVE), patch what
441 needs to be patched in the dependent tree node (JDEP_GET_PATCH,
442 JDEP_APPLY_PATCH) and perform other actions dictated by the context
443 of the patch (JDEP_KIND). The ideas are: we patch only what needs
444 to be patched, and with java_complete_class called at the right
445 time, we will start processing incomplete function bodies tree
446 nodes with everything external to function's bodies already
447 completed, it makes things much simpler. */
450 JDEP_NO_PATCH, /* Must be first */
451 JDEP_SUPER, /* Patch the type of one type
452 supertype. Requires some check
454 JDEP_FIELD, /* Patch the type of a class field */
456 /* JDEP_{METHOD,METHOD_RETURN,METHOD_END} to be kept in order */
457 JDEP_METHOD, /* Mark the beginning of the patching
458 of a method declaration, including
460 JDEP_METHOD_RETURN, /* Mark the beginning of the patching
461 of a method declaration. Arguments
462 aren't patched, only the returned
464 JDEP_METHOD_END, /* Mark the end of the patching of a
465 method declaration. It indicates
466 that it's time to compute and
467 install a new signature */
469 JDEP_INTERFACE, /* Patch the type of a Class/interface
471 JDEP_VARIABLE, /* Patch the type of a variable declaration */
472 JDEP_PARM, /* Patch the type of a parm declaration */
473 JDEP_TYPE, /* Patch a random tree node type,
474 without the need for any specific
476 JDEP_EXCEPTION, /* Patch exceptions specified by `throws' */
477 JDEP_ANONYMOUS /* Patch anonymous classes
478 (implementation or extension.) */
482 typedef struct _jdep {
483 ENUM_BITFIELD(jdep_code) kind : 8; /* Type of patch */
485 int flag0 : 1; /* Some flags */
486 tree decl; /* Tied decl/or WFL */
487 tree solv; /* What to solve */
488 tree wfl; /* Where thing to resolve where found */
489 tree misc; /* Miscellaneous info (optional). */
490 tree enclosing; /* The enclosing (current) class */
491 tree *patch; /* Address of a location to patch */
492 struct _jdep *next; /* Linked list */
496 #define JDEP_DECL(J) ((J)->decl)
497 #define JDEP_DECL_WFL(J) ((J)->decl)
498 #define JDEP_KIND(J) ((J)->kind)
499 #define JDEP_WFL(J) ((J)->wfl)
500 #define JDEP_MISC(J) ((J)->misc)
501 #define JDEP_ENCLOSING(J) ((J)->enclosing)
502 #define JDEP_CLASS(J) ((J)->class)
503 #define JDEP_APPLY_PATCH(J,P) (*(J)->patch = (P))
504 #define JDEP_GET_PATCH(J) ((J)->patch)
505 #define JDEP_CHAIN(J) ((J)->next)
506 #define JDEP_TO_RESOLVE(J) ((J)->solv)
507 #define JDEP_RESOLVED_DECL(J) ((J)->solv)
508 #define JDEP_RESOLVED(J, D) ((J)->solv = D)
509 #define JDEP_RESOLVED_P(J) \
510 (!(J)->solv || TREE_CODE ((J)->solv) != POINTER_TYPE)
512 typedef struct _jdeplist {
515 struct _jdeplist *next;
518 #endif /* JC1_LITE */
520 #define CLASSD_FIRST(CD) ((CD)->first)
521 #define CLASSD_LAST(CD) ((CD)->last)
522 #define CLASSD_CHAIN(CD) ((CD)->next)
524 #define JDEP_INSERT(L,J) \
527 (L)->last = (L)->first = (J); \
530 JDEP_CHAIN ((L)->last) = (J); \
535 /* if TYPE can't be resolved, obtain something suitable for its
536 resolution (TYPE is saved in SAVE before being changed). and set
537 CHAIN to 1. Otherwise, type is set to something usable. CHAIN is
538 usually used to determine that a new DEP must be installed on TYPE.
539 Note that when compiling java.lang.Object, references to Object are
541 #define SET_TYPE_FOR_RESOLUTION(TYPE, SAVE, CHAIN) \
543 tree _returned_type; \
545 if (TREE_TYPE (GET_CPC ()) == object_type_node \
546 && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION \
547 && EXPR_WFL_NODE (TYPE) == unqualified_object_id_node) \
548 (TYPE) = object_type_node; \
551 if (unresolved_type_p (type, &_returned_type)) \
553 if (_returned_type) \
554 (TYPE) = _returned_type; \
558 WFL_STRIP_BRACKET (_type, TYPE); \
560 (TYPE) = obtain_incomplete_type (TYPE); \
567 #define WFL_STRIP_BRACKET(TARGET, TYPE) \
569 tree __type = (TYPE); \
570 if (TYPE && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION) \
573 if (build_type_name_from_array_name (EXPR_WFL_NODE (TYPE), &_node)) \
575 tree _new = copy_node (TYPE); \
576 EXPR_WFL_NODE (_new) = _node; \
583 /* If NAME contains one or more trailing []s, NAMELEN will be the
584 adjusted to be the index of the last non bracket character in
585 NAME. ARRAY_DIMS will contain the number of []s found. */
587 #define STRING_STRIP_BRACKETS(NAME, NAMELEN, ARRAY_DIMS) \
590 while (NAMELEN >= 2 && (NAME)[NAMELEN - 1] == ']') \
597 /* Promote a type if it won't be registered as a patch */
598 #define PROMOTE_RECORD_IF_COMPLETE(TYPE, IS_INCOMPLETE) \
600 if (!(IS_INCOMPLETE) && TREE_CODE (TYPE) == RECORD_TYPE) \
601 (TYPE) = promote_type (TYPE); \
604 /* Insert a DECL in the current block */
605 #define BLOCK_CHAIN_DECL(NODE) \
607 TREE_CHAIN ((NODE)) = \
608 BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl)); \
609 BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl)) = (NODE); \
612 /* Return the current block, either found in the body of the currently
613 declared function or in the current static block being defined. */
614 #define GET_CURRENT_BLOCK(F) ((F) ? DECL_FUNCTION_BODY ((F)) : \
615 current_static_block)
617 /* Merge an other line to the source line number of a decl. Used to
618 remember function's end. */
619 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
621 /* Retrieve those two info separately. */
622 #define DECL_SOURCE_LINE_FIRST(DECL) (DECL_SOURCE_LINE(DECL) & 0x0000ffff)
623 #define DECL_SOURCE_LINE_LAST(DECL) (DECL_SOURCE_LINE(DECL) >> 16)
625 /* Retrieve line/column from a WFL. */
626 #define EXPR_WFL_GET_LINECOL(V,LINE,COL) \
628 (LINE) = (V) >> 12; \
629 (COL) = (V) & 0xfff; \
631 /* Add X to the column number information */
632 #define EXPR_WFL_ADD_COL(V, X) \
633 (V) = (((V) & 0xfffff000) | ((((V) & 0xfff) + (X)) & 0xfff))
635 /* Build a WFL for expression nodes */
636 #define BUILD_EXPR_WFL(NODE, WFL) \
637 build_expr_wfl ((NODE), input_filename, EXPR_WFL_LINENO ((WFL)), \
638 EXPR_WFL_COLNO ((WFL)))
640 #define EXPR_WFL_QUALIFICATION(WFL) TREE_OPERAND ((WFL), 2)
641 #define QUAL_WFL(NODE) TREE_PURPOSE (NODE)
642 #define QUAL_RESOLUTION(NODE) TREE_VALUE (NODE)
643 #define QUAL_DECL_TYPE(NODE) GET_SKIP_TYPE (NODE)
645 #define GET_SKIP_TYPE(NODE) \
646 (TREE_CODE (TREE_TYPE (NODE)) == POINTER_TYPE ? \
647 TREE_TYPE (TREE_TYPE (NODE)): TREE_TYPE (NODE))
649 /* Handy macros for the walk operation */
650 #define COMPLETE_CHECK_OP(NODE, N) \
652 TREE_OPERAND ((NODE), (N)) = \
653 java_complete_tree (TREE_OPERAND ((NODE), (N))); \
654 if (TREE_OPERAND ((NODE), (N)) == error_mark_node) \
655 return error_mark_node; \
657 #define COMPLETE_CHECK_OP_0(NODE) COMPLETE_CHECK_OP(NODE, 0)
658 #define COMPLETE_CHECK_OP_1(NODE) COMPLETE_CHECK_OP(NODE, 1)
659 #define COMPLETE_CHECK_OP_2(NODE) COMPLETE_CHECK_OP(NODE, 2)
661 /* Building invocations: append(ARG) and StringBuffer(ARG) */
662 #define BUILD_APPEND(ARG) \
663 ((JSTRING_TYPE_P (TREE_TYPE (ARG)) || JPRIMITIVE_TYPE_P (TREE_TYPE (ARG))) \
664 ? build_method_invocation (wfl_append, \
665 ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE)\
666 : build_method_invocation (wfl_append, \
667 ARG ? build_tree_list (NULL, \
668 build1 (CONVERT_EXPR, \
672 #define BUILD_STRING_BUFFER(ARG) \
673 build_new_invocation (wfl_string_buffer, \
674 (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
676 #define BUILD_THROW(WHERE, WHAT) \
679 build (CALL_EXPR, void_type_node, \
680 build_address_of (throw_node), \
681 build_tree_list (NULL_TREE, (WHAT)), NULL_TREE); \
682 TREE_SIDE_EFFECTS ((WHERE)) = 1; \
685 /* Set wfl_operator for the most accurate error location */
686 #define SET_WFL_OPERATOR(WHICH, NODE, WFL) \
687 EXPR_WFL_LINECOL (WHICH) = \
688 (TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ? \
689 EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
691 #define PATCH_METHOD_RETURN_ERROR() \
694 *ret_decl = NULL_TREE; \
695 return error_mark_node; \
698 /* Convenient macro to check. Assumes that CLASS is a CLASS_DECL. */
699 #define CHECK_METHODS(CLASS) \
701 if (CLASS_INTERFACE ((CLASS))) \
702 java_check_abstract_methods ((CLASS)); \
704 java_check_regular_methods ((CLASS)); \
707 /* Using and reseting the @deprecated tag flag */
708 #define CHECK_DEPRECATED(DECL) \
710 if (ctxp->deprecated) \
711 DECL_DEPRECATED (DECL) = 1; \
712 ctxp->deprecated = 0; \
715 /* Register an import */
716 #define REGISTER_IMPORT(WHOLE, NAME) \
718 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1; \
719 ctxp->import_list = tree_cons ((WHOLE), (NAME), ctxp->import_list); \
722 /* Macro to access the osb (opening square bracket) count */
723 #define CURRENT_OSB(C) (C)->osb_number [(C)->osb_depth]
725 /* Macro for the xreferencer */
726 #define DECL_END_SOURCE_LINE(DECL) (DECL_CHECK (DECL)->decl.u1.i)
727 #define DECL_INHERITED_SOURCE_LINE(DECL) (DECL_CHECK (DECL)->decl.u2.i)
729 /* Parser context data structure. */
732 const char *filename; /* Current filename */
733 struct parser_ctxt *next;
735 java_lexer *lexer; /* Current lexer state */
736 char marker_begining; /* Marker. Should be a sub-struct */
737 struct java_line *p_line, *c_line; /* Previous and current line */
738 java_lc elc; /* Error's line column info */
739 int ccb_indent; /* Keep track of {} indent, lexer */
740 int first_ccb_indent1; /* First { at ident level 1 */
741 int last_ccb_indent1; /* Last } at ident level 1 */
742 int parser_ccb_indent; /* Keep track of {} indent, parser */
743 int osb_depth; /* Current depth of [ in an expression */
744 int osb_limit; /* Limit of this depth */
745 int *osb_number; /* Keep track of ['s */
746 int lineno; /* Current lineno */
747 char marker_end; /* End marker. Should be a sub-struct */
749 /* The flags section */
751 /* Indicates a context used for saving the parser status. The
752 context must be popped when the status is restored. */
753 unsigned saved_data_ctx:1;
754 /* Indicates that a context already contains saved data and that the
755 next save operation will require a new context to be created. */
756 unsigned saved_data:1;
757 /* Report error when true */
758 unsigned java_error_flag:1;
759 /* @deprecated tag seen */
760 unsigned deprecated:1;
761 /* Flag to report certain errors (fix this documentation. FIXME) */
762 unsigned class_err:1;
764 /* This section is defined only if we compile jc1 */
766 tree modifier_ctx [12]; /* WFL of modifiers */
767 tree class_type; /* Current class */
768 tree function_decl; /* Current function decl, save/restore */
770 struct JCF *current_jcf; /* CU jcf */
772 int prevent_ese; /* Prevent expression statement error */
774 int formal_parameter_number; /* Number of parameters found */
775 int interface_number; /* # itfs declared to extend an itf def */
777 tree package; /* Defined package ID */
779 /* These two lists won't survive file traversal */
780 tree class_list; /* List of classes in a CU */
781 jdeplist *classd_list; /* Classe dependencies in a CU */
783 tree current_parsed_class; /* Class currently parsed */
784 tree current_parsed_class_un; /* Curr. parsed class unqualified name */
786 tree non_static_initialized; /* List of non static initialized fields */
787 tree static_initialized; /* List of static non final initialized */
788 tree instance_initializers; /* List of instance initializers stmts */
790 tree import_list; /* List of import */
791 tree import_demand_list; /* List of import on demand */
793 tree current_loop; /* List of the currently nested
795 tree current_labeled_block; /* List of currently nested
798 int pending_block; /* Pending block to close */
800 int explicit_constructor_p; /* >0 when processing an explicit
801 constructor. This flag is used to trap
802 illegal argument usage during an
803 explicit constructor invocation. */
804 #endif /* JC1_LITE */
807 /* A set of macros to push/pop/access the currently parsed class. */
808 #define GET_CPC_LIST() ctxp->current_parsed_class
810 /* Currently class being parsed is an inner class if an enclosing
811 class has been already pushed. This truth value is only valid prior
812 an inner class is pushed. After, use FIXME. */
813 #define CPC_INNER_P() GET_CPC_LIST ()
815 /* Get the currently parsed class DECL_TYPE node. */
816 #define GET_CPC() TREE_VALUE (GET_CPC_LIST ())
818 /* Get the currently parsed class unqualified IDENTIFIER_NODE. */
819 #define GET_CPC_UN() TREE_PURPOSE (GET_CPC_LIST ())
821 /* Get a parsed class unqualified IDENTIFIER_NODE from its CPC node. */
822 #define GET_CPC_UN_NODE(N) TREE_PURPOSE (N)
824 /* Get the currently parsed class DECL_TYPE from its CPC node. */
825 #define GET_CPC_DECL_NODE(N) TREE_VALUE (N)
827 /* The currently parsed enclosing currently parsed TREE_LIST node. */
828 #define GET_ENCLOSING_CPC() TREE_CHAIN (GET_CPC_LIST ())
830 /* Get the next enclosing context. */
831 #define GET_NEXT_ENCLOSING_CPC(C) TREE_CHAIN (C)
833 /* The DECL_TYPE node of the enclosing currently parsed
834 class. NULL_TREE if the currently parsed class isn't an inner
836 #define GET_ENCLOSING_CPC_CONTEXT() (GET_ENCLOSING_CPC () ? \
837 TREE_VALUE (GET_ENCLOSING_CPC ()) : \
840 /* Make sure that innerclass T sits in an appropriate enclosing
842 #define INNER_ENCLOSING_SCOPE_CHECK(T) \
843 (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T)) \
845 /* We have a this and it's not the right one */ \
846 && (DECL_CONTEXT (TYPE_NAME ((T))) \
847 != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this)))) \
848 && !inherits_from_p (TREE_TYPE (TREE_TYPE (current_this)), \
849 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T)))) \
850 && !common_enclosing_context_p (TREE_TYPE (TREE_TYPE (current_this)), \
852 && INNER_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (current_this))) \
853 && !inherits_from_p \
854 (TREE_TYPE (DECL_CONTEXT \
855 (TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))),\
856 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T))))) \
857 /* We don't have a this, which is OK if the current function is \
860 && current_function_decl \
861 && ! METHOD_STATIC (current_function_decl))))
863 /* Push macro. First argument to PUSH_CPC is a DECL_TYPE, second
864 argument is the unqualified currently parsed class name. */
865 #define PUSH_CPC(C,R) { \
866 ctxp->current_parsed_class = \
867 tree_cons ((R), (C), GET_CPC_LIST ()); \
870 /* In case of an error, push an error. */
871 #define PUSH_ERROR() PUSH_CPC (error_mark_node, error_mark_node)
873 /* Pop macro. Before we pop, we link the current inner class decl (if any)
874 to its enclosing class. */
875 #define POP_CPC() { \
876 link_nested_class_to_enclosing (); \
877 ctxp->current_parsed_class = \
878 TREE_CHAIN (GET_CPC_LIST ()); \
881 #define DEBUG_CPC() \
884 tree tmp = ctxp->current_parsed_class; \
887 fprintf (stderr, "%s ", \
888 IDENTIFIER_POINTER (TREE_PURPOSE (tmp))); \
889 tmp = TREE_CHAIN (tmp); \
894 /* Access to the various initializer statement lists */
895 #define CPC_INITIALIZER_LIST(C) ((C)->non_static_initialized)
896 #define CPC_STATIC_INITIALIZER_LIST(C) ((C)->static_initialized)
897 #define CPC_INSTANCE_INITIALIZER_LIST(C) ((C)->instance_initializers)
899 /* Access to the various initializer statements */
900 #define CPC_INITIALIZER_STMT(C) (TREE_PURPOSE (CPC_INITIALIZER_LIST (C)))
901 #define CPC_STATIC_INITIALIZER_STMT(C) \
902 (TREE_PURPOSE (CPC_STATIC_INITIALIZER_LIST (C)))
903 #define CPC_INSTANCE_INITIALIZER_STMT(C) \
904 (TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)))
906 /* Set various initializer statements */
907 #define SET_CPC_INITIALIZER_STMT(C,S) \
908 if (CPC_INITIALIZER_LIST (C)) \
909 TREE_PURPOSE (CPC_INITIALIZER_LIST (C)) = (S);
910 #define SET_CPC_STATIC_INITIALIZER_STMT(C,S) \
911 if (CPC_STATIC_INITIALIZER_LIST (C)) \
912 TREE_PURPOSE (CPC_STATIC_INITIALIZER_LIST (C)) = (S);
913 #define SET_CPC_INSTANCE_INITIALIZER_STMT(C,S) \
914 if (CPC_INSTANCE_INITIALIZER_LIST(C)) \
915 TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)) = (S);
917 /* This is used by the lexer to communicate with the parser. It is
918 set on an integer constant if the radix is 10, so that the parser
919 can correctly diagnose a numeric overflow. */
920 #define JAVA_RADIX10_FLAG(NODE) TREE_LANG_FLAG_0(NODE)
923 void java_complete_class PARAMS ((void));
924 void java_check_circular_reference PARAMS ((void));
925 void java_fix_constructors PARAMS ((void));
926 void java_layout_classes PARAMS ((void));
927 void java_reorder_fields PARAMS ((void));
928 tree java_method_add_stmt PARAMS ((tree, tree));
929 int java_report_errors PARAMS ((void));
930 extern tree do_resolve_class PARAMS ((tree, tree, tree, tree));
932 char *java_get_line_col PARAMS ((const char *, int, int));
933 extern void reset_report PARAMS ((void));
935 /* Always in use, no matter what you compile */
936 void java_push_parser_context PARAMS ((void));
937 void java_pop_parser_context PARAMS ((int));
938 void java_init_lex PARAMS ((FILE *, const char *));
939 extern void java_parser_context_save_global PARAMS ((void));
940 extern void java_parser_context_restore_global PARAMS ((void));
941 int yyparse PARAMS ((void));
942 extern int java_parse PARAMS ((void));
943 extern void yyerror PARAMS ((const char *))
948 extern void java_expand_classes PARAMS ((void));
950 extern struct parser_ctxt *ctxp;
951 extern struct parser_ctxt *ctxp_for_generation;
953 #endif /* ! GCC_JAVA_PARSE_H */