1 /* Language parser definitions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
31 /* Extern global variable declarations */
32 extern int java_error_count;
33 extern struct obstack temporary_obstack;
34 extern struct obstack permanent_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
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 #define INTERFACE_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
82 #define INTERFACE_INNER_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_ABSTRACT|ACC_STATIC
83 #define INTERFACE_METHOD_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
84 #define INTERFACE_FIELD_MODIFIERS ACC_PUBLIC|ACC_STATIC|ACC_FINAL
86 /* Getting a modifier WFL */
87 #define MODIFIER_WFL(M) (ctxp->modifier_ctx [(M) - PUBLIC_TK])
89 /* Check on modifiers */
90 #define THIS_MODIFIER_ONLY(f, m, v, count, l) \
93 tree node = MODIFIER_WFL (v); \
95 && ((EXPR_WFL_COLNO (node) > EXPR_WFL_COLNO (l)) \
96 || (EXPR_WFL_LINENO (node) > EXPR_WFL_LINENO (l)))) \
103 #define ABSTRACT_CHECK(FLAG, V, CL, S) \
105 parse_error_context ((CL), "%s method can't be abstract", (S));
107 #define JCONSTRUCTOR_CHECK(FLAG, V, CL, S) \
109 parse_error_context ((CL), "Constructor can't be %s", (S)); \
112 #define exit_java_complete_class() \
117 #define CLASS_OR_INTERFACE(decl, s1, s2) \
119 ((get_access_flags_from_decl (TYPE_NAME (TREE_TYPE (decl))) \
121 s2 : s1) : ((s1 [0]=='S'|| s1 [0]=='s') ? \
122 (s1 [0]=='S' ? "Supertype" : "supertype") : \
123 (s1 [0] > 'A' ? "Type" : "type")))
125 #define GET_REAL_TYPE(TYPE) \
126 (TREE_CODE (TYPE) == TREE_LIST ? TREE_PURPOSE (TYPE) : TYPE)
128 /* Get TYPE name string, regardless whether TYPE is a class or an
130 #define GET_TYPE_NAME(TYPE) \
131 (TREE_CODE (TYPE_NAME (TYPE)) == IDENTIFIER_NODE ? \
132 IDENTIFIER_POINTER (TYPE_NAME (TYPE)) : \
133 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TYPE))))
135 /* Pedantic warning on obsolete modifiers. Note: when cl is NULL,
136 flags was set artificially, such as for a interface method */
137 #define OBSOLETE_MODIFIER_WARNING(cl, flags, __modifier, arg) \
139 if (flag_redundant && (cl) && ((flags) & (__modifier))) \
140 parse_warning_context (cl, \
141 "Discouraged redundant use of `%s' modifier in declaration of %s", \
142 java_accstring_lookup (__modifier), arg); \
144 #define OBSOLETE_MODIFIER_WARNING2(cl, flags, __modifier, arg1, arg2) \
146 if (flag_redundant && (cl) && ((flags) & (__modifier))) \
147 parse_warning_context (cl, \
148 "Discouraged redundant use of `%s' modifier in declaration of %s `%s'", \
149 java_accstring_lookup (__modifier), arg1, arg2);\
152 /* Quickly build a temporary pointer on hypothetical type NAME. */
153 #define BUILD_PTR_FROM_NAME(ptr, name) \
155 ptr = build (POINTER_TYPE, NULL_TREE); \
156 TYPE_NAME (ptr) = name; \
159 #define INCOMPLETE_TYPE_P(NODE) \
160 ((TREE_CODE (NODE) == POINTER_TYPE) \
161 && !TREE_TYPE (NODE) \
162 && TREE_CODE (TYPE_NAME (NODE)) == IDENTIFIER_NODE)
164 /* Set the EMIT_LINE_NOTE flag of a EXPR_WLF to 1 if debug information
165 are requested. Works in the context of a parser rule. */
166 #define JAVA_MAYBE_GENERATE_DEBUG_INFO(node) \
167 (debug_info_level != DINFO_LEVEL_NONE ? \
168 EXPR_WFL_EMIT_LINE_NOTE (node) = 1, node : node)
170 /* Types classification, according to the JLS, section 4.2 */
171 #define JFLOAT_TYPE_P(TYPE) (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
172 #define JINTEGRAL_TYPE_P(TYPE) ((TYPE) \
173 && (TREE_CODE ((TYPE)) == INTEGER_TYPE \
174 || TREE_CODE ((TYPE)) == CHAR_TYPE))
175 #define JNUMERIC_TYPE_P(TYPE) ((TYPE) \
176 && (JFLOAT_TYPE_P ((TYPE)) \
177 || JINTEGRAL_TYPE_P ((TYPE))))
178 #define JPRIMITIVE_TYPE_P(TYPE) ((TYPE) \
179 && (JNUMERIC_TYPE_P ((TYPE)) \
180 || TREE_CODE ((TYPE)) == BOOLEAN_TYPE))
182 #define JBSC_TYPE_P(TYPE) ((TYPE) && (((TYPE) == byte_type_node) \
183 || ((TYPE) == short_type_node) \
184 || ((TYPE) == char_type_node)))
186 /* Not defined in the LRM */
187 #define JSTRING_TYPE_P(TYPE) ((TYPE) \
188 && ((TYPE) == string_type_node || \
189 (TREE_CODE (TYPE) == POINTER_TYPE && \
190 TREE_TYPE (TYPE) == string_type_node)))
191 #define JSTRING_P(NODE) ((NODE) \
192 && (TREE_CODE (NODE) == STRING_CST \
193 || IS_CRAFTED_STRING_BUFFER_P (NODE) \
194 || JSTRING_TYPE_P (TREE_TYPE (NODE))))
196 #define JREFERENCE_TYPE_P(TYPE) ((TYPE) \
197 && (TREE_CODE (TYPE) == RECORD_TYPE \
198 || (TREE_CODE (TYPE) == POINTER_TYPE \
199 && TREE_CODE (TREE_TYPE (TYPE)) == \
201 #define JNULLP_TYPE_P(TYPE) ((TYPE) && (TREE_CODE (TYPE) == POINTER_TYPE) \
202 && (TYPE) == TREE_TYPE (null_pointer_node))
204 /* Other predicates */
205 #define JDECL_P(NODE) (NODE && (TREE_CODE (NODE) == PARM_DECL \
206 || TREE_CODE (NODE) == VAR_DECL \
207 || TREE_CODE (NODE) == FIELD_DECL))
209 #define TYPE_INTERFACE_P(TYPE) \
210 (CLASS_P (TYPE) && CLASS_INTERFACE (TYPE_NAME (TYPE)))
212 #define TYPE_CLASS_P(TYPE) (CLASS_P (TYPE) \
213 && !CLASS_INTERFACE (TYPE_NAME (TYPE)))
215 /* Identifier business related to 1.1 language extensions. */
217 #define IDENTIFIER_INNER_CLASS_OUTER_FIELD_ACCESS(NODE) \
218 (TREE_CODE (NODE) == IDENTIFIER_NODE && \
219 IDENTIFIER_LENGTH (NODE) >= 8 && \
220 IDENTIFIER_POINTER (NODE)[7] != '0')
222 /* Build the string val$<O> and store it into N. The is used to
223 construct the name of inner class hidden fields used to alias outer
224 scope local variables. */
225 #define MANGLE_OUTER_LOCAL_VARIABLE_NAME(N, O) \
227 char *mangled_name; \
228 obstack_grow (&temporary_obstack, "val$", 4); \
229 obstack_grow (&temporary_obstack, \
230 IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O))); \
231 obstack_1grow (&temporary_obstack, '\0'); \
232 mangled_name = obstack_finish (&temporary_obstack); \
233 (N) = get_identifier (mangled_name); \
234 obstack_free (&temporary_obstack, mangled_name); \
237 /* Build the string parm$<O> and store in into the identifier N. This
238 is used to contruct the name of hidden parameters used to
239 initialize outer scope aliases. */
240 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID(N, O) \
242 char *mangled_name; \
243 obstack_grow (&temporary_obstack, "parm$", 5); \
244 obstack_grow (&temporary_obstack, \
245 IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O))); \
246 obstack_1grow (&temporary_obstack, '\0'); \
247 mangled_name = obstack_finish (&temporary_obstack); \
248 (N) = get_identifier (mangled_name); \
249 obstack_free (&temporary_obstack, mangled_name); \
252 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR(N, S) \
254 char *mangled_name; \
255 obstack_grow (&temporary_obstack, "parm$", 5); \
256 obstack_grow (&temporary_obstack, (S), strlen ((S))); \
257 obstack_1grow (&temporary_obstack, '\0'); \
258 mangled_name = obstack_finish (&temporary_obstack); \
259 (N) = get_identifier (mangled_name); \
260 obstack_free (&temporary_obstack, mangled_name); \
263 /* Skip THIS and artificial parameters found in function decl M and
264 assign the result to C. We don't do that for $finit$, since it's
265 knowingly called with artificial parms. */
266 #define SKIP_THIS_AND_ARTIFICIAL_PARMS(C,M) \
269 (C) = TYPE_ARG_TYPES (TREE_TYPE ((M))); \
270 if (!METHOD_STATIC ((M))) \
271 (C) = TREE_CHAIN (C); \
272 if (DECL_CONSTRUCTOR_P ((M)) \
273 && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT ((M)))) \
274 (C) = TREE_CHAIN (C); \
275 if (!DECL_FINIT_P ((M))) \
276 for (i = DECL_FUNCTION_NAP ((M)); i; i--) \
277 (C) = TREE_CHAIN (C); \
280 /* Mark final parameters in method M, by comparison of the argument
281 list L. This macro is used to set the flag once the method has been
283 #define MARK_FINAL_PARMS(M, L) \
285 tree current = TYPE_ARG_TYPES (TREE_TYPE ((M))); \
287 if (!METHOD_STATIC ((M))) \
288 current = TREE_CHAIN (current); \
289 for (; current != end_params_node; \
290 current = TREE_CHAIN (current), list = TREE_CHAIN (list)) \
291 ARG_FINAL_P (current) = ARG_FINAL_P (list); \
292 if (current != list) \
293 fatal ("MARK_FINAL_PARMS"); \
296 /* Reset the ARG_FINAL_P that might have been set in method M args. */
297 #define UNMARK_FINAL_PARMS(M) \
300 for (current = TYPE_ARG_TYPES (TREE_TYPE ((M))); \
301 current != end_params_node; current = TREE_CHAIN (current)) \
302 ARG_FINAL_P (current) = 0; \
305 /* Reverse a crafted parameter list as required. */
306 #define CRAFTED_PARAM_LIST_FIXUP(P) \
311 (P) = nreverse (P); \
312 TREE_CHAIN (last) = end_params_node; \
315 (P) = end_params_node; \
318 /* Modes governing the creation of a alias initializer parameter
319 lists. AIPL stands for Alias Initializer Parameter List. */
321 AIPL_FUNCTION_CREATION, /* Suitable for artificial method creation */
322 AIPL_FUNCTION_DECLARATION, /* Suitable for declared methods */
323 AIPL_FUNCTION_CTOR_INVOCATION, /* Invocation of constructors */
324 AIPL_FUNCTION_FINIT_INVOCATION /* Invocation of $finit$ */
327 /* Standard error messages */
328 #define ERROR_CANT_CONVERT_TO_BOOLEAN(OPERATOR, NODE, TYPE) \
329 parse_error_context ((OPERATOR), \
330 "Incompatible type for `%s'. Can't convert `%s' to boolean", \
331 operator_string ((NODE)), lang_printable_name ((TYPE),0))
333 #define ERROR_CANT_CONVERT_TO_NUMERIC(OPERATOR, NODE, TYPE) \
334 parse_error_context ((OPERATOR), \
335 "Incompatible type for `%s'. Can't convert `%s' to numeric type", \
336 operator_string ((NODE)), lang_printable_name ((TYPE), 0))
338 #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE) \
340 tree _operator = (OPERATOR), _node = (NODE), _type = (TYPE); \
341 if (JPRIMITIVE_TYPE_P (_type)) \
342 parse_error_context (_operator, \
343 "Incompatible type for `%s'. Explicit cast needed to convert `%s' to integral",\
344 operator_string(_node), \
345 lang_printable_name (_type, 0)); \
347 parse_error_context (_operator, \
348 "Incompatible type for `%s'. Can't convert `%s' to integral", \
349 operator_string(_node), \
350 lang_printable_name (_type, 0)); \
353 #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V) \
354 parse_error_context \
355 ((WFL), "Variable `%s' may not have been initialized", \
356 IDENTIFIER_POINTER (V))
358 /* Definition for loop handling. This is Java's own definition of a
359 loop body. See parse.y for documentation. It's valid once you hold
360 a loop's body (LOOP_EXPR_BODY) */
362 /* The loop main block is the one hold the condition and the loop body */
363 #define LOOP_EXPR_BODY_MAIN_BLOCK(NODE) TREE_OPERAND (NODE, 0)
364 /* And then there is the loop update block */
365 #define LOOP_EXPR_BODY_UPDATE_BLOCK(NODE) TREE_OPERAND (NODE, 1)
367 /* Inside the loop main block, there is the loop condition and the
368 loop body. They may be reversed if the loop being described is a
369 do-while loop. NOTE: if you use a WFL around the EXIT_EXPR so you
370 can issue debug info for it, the EXIT_EXPR will be one operand
372 #define LOOP_EXPR_BODY_CONDITION_EXPR(NODE, R) \
373 TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 1 : 0))
375 /* Here is the labeled block the loop real body is encapsulated in */
376 #define LOOP_EXPR_BODY_LABELED_BODY(NODE, R) \
377 TREE_OPERAND (LOOP_EXPR_BODY_MAIN_BLOCK (NODE), (R ? 0 : 1))
378 /* And here is the loop's real body */
379 #define LOOP_EXPR_BODY_BODY_EXPR(NODE, R) \
380 LABELED_BLOCK_BODY (LOOP_EXPR_BODY_LABELED_BODY(NODE, R))
382 #define PUSH_LABELED_BLOCK(B) \
384 TREE_CHAIN (B) = ctxp->current_labeled_block; \
385 ctxp->current_labeled_block = (B); \
387 #define POP_LABELED_BLOCK() \
388 ctxp->current_labeled_block = TREE_CHAIN (ctxp->current_labeled_block)
390 #define PUSH_LOOP(L) \
392 TREE_CHAIN (L) = ctxp->current_loop; \
393 ctxp->current_loop = (L); \
395 #define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
397 #define PUSH_EXCEPTIONS(E) \
398 currently_caught_type_list = \
399 tree_cons (NULL_TREE, (E), currently_caught_type_list);
401 #define POP_EXCEPTIONS() \
402 currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
404 /* Check that we're inside a try block. */
405 #define IN_TRY_BLOCK_P() \
406 (currently_caught_type_list \
407 && ((TREE_VALUE (currently_caught_type_list) != \
408 DECL_FUNCTION_THROWS (current_function_decl)) \
409 || TREE_CHAIN (currently_caught_type_list)))
411 /* Check that we have exceptions in E. */
412 #define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
414 /* Anonymous array access */
415 #define ANONYMOUS_ARRAY_BASE_TYPE(N) TREE_OPERAND ((N), 0)
416 #define ANONYMOUS_ARRAY_DIMS_SIG(N) TREE_OPERAND ((N), 1)
417 #define ANONYMOUS_ARRAY_INITIALIZER(N) TREE_OPERAND ((N), 2)
419 /* Invocation modes, as returned by invocation_mode (). */
428 /* We need the resolution stuff only if we compile jc1 */
431 /* Unresolved type identifiers handling. When we process the source
432 code, we blindly accept an unknown type identifier and try to
433 resolve it later. When an unknown type identifier is encountered
434 and used, we record in a struct jdep element what the incomplete
435 type is and what it should patch. Later, java_complete_class will
436 process all classes known to have unresolved type
437 dependencies. Within each of these classes, this routine will
438 process unresolved type dependencies (JDEP_TO_RESOLVE), patch what
439 needs to be patched in the dependent tree node (JDEP_GET_PATCH,
440 JDEP_APPLY_PATCH) and perform other actions dictated by the context
441 of the patch (JDEP_KIND). The ideas are: we patch only what needs
442 to be patched, and with java_complete_class called at the right
443 time, we will start processing incomplete function bodies tree
444 nodes with everything external to function's bodies already
445 completed, it makes things much simpler. */
448 JDEP_NO_PATCH, /* Must be first */
449 JDEP_SUPER, /* Patch the type of one type
450 supertype. Requires some check
452 JDEP_FIELD, /* Patch the type of a class field */
454 /* JDEP_{METHOD,METHOD_RETURN,METHOD_END} to be kept in order */
455 JDEP_METHOD, /* Mark the beginning of the patching
456 of a method declaration, including
458 JDEP_METHOD_RETURN, /* Mark the beginning of the patching
459 of a method declaration. Arguments
460 aren't patched, only the returned
462 JDEP_METHOD_END, /* Mark the end of the patching of a
463 method declaration. It indicates
464 that it's time to compute and
465 install a new signature */
467 JDEP_INTERFACE, /* Patch the type of a Class/interface
469 JDEP_VARIABLE, /* Patch the type of a variable declaration */
470 JDEP_PARM, /* Patch the type of a parm declaration */
471 JDEP_TYPE, /* Patch a random tree node type,
472 without the need for any specific
474 JDEP_EXCEPTION, /* Patch exceptions specified by `throws' */
475 JDEP_ANONYMOUS /* Patch anonymous classes
476 (implementation or extension.) */
480 typedef struct _jdep {
481 ENUM_BITFIELD(jdep_code) kind : 8; /* Type of patch */
483 int flag0 : 1; /* Some flags */
484 tree decl; /* Tied decl/or WFL */
485 tree solv; /* What to solve */
486 tree wfl; /* Where thing to resolve where found */
487 tree misc; /* Miscellaneous info (optional). */
488 tree enclosing; /* The enclosing (current) class */
489 tree *patch; /* Address of a location to patch */
490 struct _jdep *next; /* Linked list */
494 #define JDEP_DECL(J) ((J)->decl)
495 #define JDEP_DECL_WFL(J) ((J)->decl)
496 #define JDEP_KIND(J) ((J)->kind)
497 #define JDEP_SOLV(J) ((J)->solv)
498 #define JDEP_WFL(J) ((J)->wfl)
499 #define JDEP_MISC(J) ((J)->misc)
500 #define JDEP_ENCLOSING(J) ((J)->enclosing)
501 #define JDEP_CLASS(J) ((J)->class)
502 #define JDEP_APPLY_PATCH(J,P) (*(J)->patch = (P))
503 #define JDEP_GET_PATCH(J) ((J)->patch)
504 #define JDEP_CHAIN(J) ((J)->next)
505 #define JDEP_TO_RESOLVE(J) ((J)->solv)
506 #define JDEP_RESOLVED_DECL(J) ((J)->solv)
507 #define JDEP_RESOLVED(J, D) ((J)->solv = D)
508 #define JDEP_RESOLVED_P(J) \
509 (!(J)->solv || TREE_CODE ((J)->solv) != POINTER_TYPE)
511 typedef struct _jdeplist {
514 struct _jdeplist *next;
517 #endif /* JC1_LITE */
519 #define CLASSD_FIRST(CD) ((CD)->first)
520 #define CLASSD_LAST(CD) ((CD)->last)
521 #define CLASSD_CHAIN(CD) ((CD)->next)
523 #define JDEP_INSERT(L,J) \
526 (L)->last = (L)->first = (J); \
529 JDEP_CHAIN ((L)->last) = (J); \
534 /* if TYPE can't be resolved, obtain something suitable for its
535 resolution (TYPE is saved in SAVE before being changed). and set
536 CHAIN to 1. Otherwise, type is set to something usable. CHAIN is
537 usually used to determine that a new DEP must be installed on TYPE.
538 Note that when compiling java.lang.Object, references to Object are
540 #define SET_TYPE_FOR_RESOLUTION(TYPE, SAVE, CHAIN) \
542 tree _returned_type; \
544 if (TREE_TYPE (GET_CPC ()) == object_type_node \
545 && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION \
546 && EXPR_WFL_NODE (TYPE) == unqualified_object_id_node) \
547 (TYPE) = object_type_node; \
550 if (unresolved_type_p (type, &_returned_type)) \
552 if (_returned_type) \
553 (TYPE) = _returned_type; \
557 WFL_STRIP_BRACKET (_type, TYPE); \
559 (TYPE) = obtain_incomplete_type (TYPE); \
566 #define WFL_STRIP_BRACKET(TARGET, TYPE) \
568 tree __type = (TYPE); \
569 if (TYPE && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION) \
571 tree _node = EXPR_WFL_NODE (TYPE); \
572 const char *_ptr = IDENTIFIER_POINTER (_node); \
573 const char *_ref = _ptr; \
574 while (_ptr[0] == '[') \
578 tree _new = copy_node (TYPE); \
579 EXPR_WFL_NODE (_new) = get_identifier (_ptr); \
586 /* Promote a type if it won't be registered as a patch */
587 #define PROMOTE_RECORD_IF_COMPLETE(TYPE, IS_INCOMPLETE) \
589 if (!(IS_INCOMPLETE) && TREE_CODE (TYPE) == RECORD_TYPE) \
590 (TYPE) = promote_type (TYPE); \
593 /* Insert a DECL in the current block */
594 #define BLOCK_CHAIN_DECL(NODE) \
596 TREE_CHAIN ((NODE)) = \
597 BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl)); \
598 BLOCK_EXPR_DECLS (GET_CURRENT_BLOCK (current_function_decl)) = (NODE); \
601 /* Return the current block, either found in the body of the currently
602 declared function or in the current static block being defined. */
603 #define GET_CURRENT_BLOCK(F) ((F) ? DECL_FUNCTION_BODY ((F)) : \
604 current_static_block)
606 /* For an artificial BLOCK (created to house a local variable declaration not
607 at the start of an existing block), the parent block; otherwise NULL. */
608 #define BLOCK_EXPR_ORIGIN(NODE) BLOCK_ABSTRACT_ORIGIN(NODE)
610 /* Merge an other line to the source line number of a decl. Used to
611 remember function's end. */
612 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
614 /* Retrieve those two info separately. */
615 #define DECL_SOURCE_LINE_FIRST(DECL) (DECL_SOURCE_LINE(DECL) & 0x0000ffff)
616 #define DECL_SOURCE_LINE_LAST(DECL) (DECL_SOURCE_LINE(DECL) >> 16)
618 /* Retrieve line/column from a WFL. */
619 #define EXPR_WFL_GET_LINECOL(V,LINE,COL) \
621 (LINE) = (V) >> 12; \
622 (COL) = (V) & 0xfff; \
624 /* Add X to the column number information */
625 #define EXPR_WFL_ADD_COL(V, X) \
626 (V) = (((V) & 0xfffff000) | ((((V) & 0xfff) + (X)) & 0xfff))
628 /* Build a WFL for expression nodes */
629 #define BUILD_EXPR_WFL(NODE, WFL) \
630 build_expr_wfl ((NODE), input_filename, EXPR_WFL_LINENO ((WFL)), \
631 EXPR_WFL_COLNO ((WFL)))
633 #define EXPR_WFL_QUALIFICATION(WFL) TREE_OPERAND ((WFL), 2)
634 #define QUAL_WFL(NODE) TREE_PURPOSE (NODE)
635 #define QUAL_RESOLUTION(NODE) TREE_VALUE (NODE)
636 #define QUAL_DECL_TYPE(NODE) GET_SKIP_TYPE (NODE)
638 #define GET_SKIP_TYPE(NODE) \
639 (TREE_CODE (TREE_TYPE (NODE)) == POINTER_TYPE ? \
640 TREE_TYPE (TREE_TYPE (NODE)): TREE_TYPE (NODE))
642 /* Handy macros for the walk operation */
643 #define COMPLETE_CHECK_OP(NODE, N) \
645 TREE_OPERAND ((NODE), (N)) = \
646 java_complete_tree (TREE_OPERAND ((NODE), (N))); \
647 if (TREE_OPERAND ((NODE), (N)) == error_mark_node) \
648 return error_mark_node; \
650 #define COMPLETE_CHECK_OP_0(NODE) COMPLETE_CHECK_OP(NODE, 0)
651 #define COMPLETE_CHECK_OP_1(NODE) COMPLETE_CHECK_OP(NODE, 1)
652 #define COMPLETE_CHECK_OP_2(NODE) COMPLETE_CHECK_OP(NODE, 2)
654 /* Building invocations: append(ARG) and StringBuffer(ARG) */
655 #define BUILD_APPEND(ARG) \
656 ((JSTRING_TYPE_P (TREE_TYPE (ARG)) || JPRIMITIVE_TYPE_P (TREE_TYPE (ARG))) \
657 ? build_method_invocation (wfl_append, \
658 ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE)\
659 : build_method_invocation (wfl_append, \
660 ARG ? build_tree_list (NULL, \
661 build1 (CONVERT_EXPR, \
665 #define BUILD_STRING_BUFFER(ARG) \
666 build_new_invocation (wfl_string_buffer, \
667 (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
669 /* For exception handling, build diverse function calls */
670 #define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO) \
672 (WHERE) = build (MODIFY_EXPR, void_type_node, (TO), \
673 soft_exceptioninfo_call_node); \
674 TREE_SIDE_EFFECTS (WHERE) = 1; \
677 #define BUILD_THROW(WHERE, WHAT) \
680 build (CALL_EXPR, void_type_node, \
681 build_address_of (throw_node[exceptions_via_longjmp ? 1 : 0]), \
682 build_tree_list (NULL_TREE, (WHAT)), NULL_TREE); \
683 TREE_SIDE_EFFECTS ((WHERE)) = 1; \
686 /* Set wfl_operator for the most accurate error location */
687 #define SET_WFL_OPERATOR(WHICH, NODE, WFL) \
688 EXPR_WFL_LINECOL (WHICH) = \
689 (TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ? \
690 EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
692 #define PATCH_METHOD_RETURN_ERROR() \
695 *ret_decl = NULL_TREE; \
696 return error_mark_node; \
699 /* Convenient macro to check. Assumes that CLASS is a CLASS_DECL. */
700 #define CHECK_METHODS(CLASS) \
702 if (CLASS_INTERFACE ((CLASS))) \
703 java_check_abstract_methods ((CLASS)); \
705 java_check_regular_methods ((CLASS)); \
708 /* Using and reseting the @deprecated tag flag */
709 #define CHECK_DEPRECATED(DECL) \
711 if (ctxp->deprecated) \
712 DECL_DEPRECATED (DECL) = 1; \
713 ctxp->deprecated = 0; \
716 /* Register an import */
717 #define REGISTER_IMPORT(WHOLE, NAME) \
719 IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1; \
720 ctxp->import_list = chainon (ctxp->import_list, \
721 build_tree_list ((WHOLE), (NAME))); \
724 /* Macro to access the osb (opening square bracket) count */
725 #define CURRENT_OSB(C) (C)->osb_number [(C)->osb_depth]
727 /* Macro for the xreferencer */
728 #define DECL_END_SOURCE_LINE(DECL) DECL_FRAME_SIZE (DECL)
729 #define DECL_INHERITED_SOURCE_LINE(DECL) (DECL_CHECK (DECL)->decl.u2.i)
731 /* Parser context data structure. */
734 const char *filename; /* Current filename */
735 struct parser_ctxt *next;
737 java_lexer *lexer; /* Current lexer state */
738 char marker_begining; /* Marker. Should be a sub-struct */
739 struct java_line *p_line, *c_line; /* Previous and current line */
740 java_lc elc; /* Error's line column info */
741 int ccb_indent; /* Keep track of {} indent, lexer */
742 int first_ccb_indent1; /* First { at ident level 1 */
743 int last_ccb_indent1; /* Last } at ident level 1 */
744 int parser_ccb_indent; /* Keep track of {} indent, parser */
745 int osb_depth; /* Current depth of [ in an expression */
746 int osb_limit; /* Limit of this depth */
747 int *osb_number; /* Keep track of ['s */
748 int lineno; /* Current lineno */
749 char marker_end; /* End marker. Should be a sub-struct */
751 /* The flags section */
753 /* Indicates a context used for saving the parser status. The
754 context must be popped when the status is restored. */
755 unsigned saved_data_ctx:1;
756 /* Indicates that a context already contains saved data and that the
757 next save operation will require a new context to be created. */
758 unsigned saved_data:1;
759 /* Integral literal overflow */
760 unsigned minus_seen:1;
761 /* Report error when true */
762 unsigned java_error_flag:1;
763 /* @deprecated tag seen */
764 unsigned deprecated:1;
765 /* Flag to report certain errors (fix this documentation. FIXME) */
766 unsigned class_err:1;
768 /* This section is defined only if we compile jc1 */
770 tree modifier_ctx [11]; /* WFL of modifiers */
771 tree class_type; /* Current class */
772 tree function_decl; /* Current function decl, save/restore */
774 struct JCF *current_jcf; /* CU jcf */
776 int prevent_ese; /* Prevent expression statement error */
778 int formal_parameter_number; /* Number of parameters found */
779 int interface_number; /* # itfs declared to extend an itf def */
781 tree package; /* Defined package ID */
783 /* Those two list are saved accross file traversal */
784 tree incomplete_class; /* List of non-complete classes */
785 tree gclass_list; /* All classes seen from source code */
787 /* These two lists won't survive file traversal */
788 tree class_list; /* List of classes in a CU */
789 jdeplist *classd_list; /* Classe dependencies in a CU */
791 tree current_parsed_class; /* Class currently parsed */
792 tree current_parsed_class_un; /* Curr. parsed class unqualified name */
794 tree non_static_initialized; /* List of non static initialized fields */
795 tree static_initialized; /* List of static non final initialized */
796 tree instance_initializers; /* List of instancei initializers stmts */
798 tree import_list; /* List of import */
799 tree import_demand_list; /* List of import on demand */
801 tree current_loop; /* List of the currently nested
803 tree current_labeled_block; /* List of currently nested
806 int pending_block; /* Pending block to close */
808 int explicit_constructor_p; /* >0 when processing an explicit
809 constructor. This flag is used to trap
810 illegal argument usage during an
811 explicit constructor invocation. */
812 #endif /* JC1_LITE */
815 /* A set of macros to push/pop/access the currently parsed class. */
816 #define GET_CPC_LIST() ctxp->current_parsed_class
818 /* Currently class being parsed is an inner class if an enclosing
819 class has been already pushed. This truth value is only valid prior
820 an inner class is pushed. After, use FIXME. */
821 #define CPC_INNER_P() GET_CPC_LIST ()
823 /* Get the currently parsed class DECL_TYPE node. */
824 #define GET_CPC() TREE_VALUE (GET_CPC_LIST ())
826 /* Get the currently parsed class unqualified IDENTIFIER_NODE. */
827 #define GET_CPC_UN() TREE_PURPOSE (GET_CPC_LIST ())
829 /* Get a parsed class unqualified IDENTIFIER_NODE from its CPC node. */
830 #define GET_CPC_UN_NODE(N) TREE_PURPOSE (N)
832 /* Get the currently parsed class DECL_TYPE from its CPC node. */
833 #define GET_CPC_DECL_NODE(N) TREE_VALUE (N)
835 /* The currently parsed enclosing currently parsed TREE_LIST node. */
836 #define GET_ENCLOSING_CPC() TREE_CHAIN (GET_CPC_LIST ())
838 /* Get the next enclosing context. */
839 #define GET_NEXT_ENCLOSING_CPC(C) TREE_CHAIN (C)
841 /* The DECL_TYPE node of the enclosing currently parsed
842 class. NULL_TREE if the currently parsed class isn't an inner
844 #define GET_ENCLOSING_CPC_CONTEXT() (GET_ENCLOSING_CPC () ? \
845 TREE_VALUE (GET_ENCLOSING_CPC ()) : \
848 /* Make sure that innerclass T sits in an appropriate enclosing
850 #define INNER_ENCLOSING_SCOPE_CHECK(T) \
851 (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T)) \
853 /* We have a this and it's not the right one */ \
854 && (DECL_CONTEXT (TYPE_NAME ((T))) \
855 != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this)))) \
856 && !inherits_from_p (TREE_TYPE (TREE_TYPE (current_this)), \
857 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T)))) \
858 && !common_enclosing_context_p (TREE_TYPE (TREE_TYPE (current_this)), \
860 && INNER_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (current_this))) \
861 && !inherits_from_p \
862 (TREE_TYPE (DECL_CONTEXT \
863 (TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))),\
864 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T))))) \
865 /* We don't have a this. */ \
868 /* Push macro. First argument to PUSH_CPC is a DECL_TYPE, second
869 argument is the unqualified currently parsed class name. */
870 #define PUSH_CPC(C,R) { \
871 ctxp->current_parsed_class = \
872 tree_cons ((R), (C), GET_CPC_LIST ()); \
875 /* In case of an error, push an error. */
876 #define PUSH_ERROR() PUSH_CPC (error_mark_node, error_mark_node)
878 /* Pop macro. Before we pop, we link the current inner class decl (if any)
879 to its enclosing class. */
880 #define POP_CPC() { \
881 link_nested_class_to_enclosing (); \
882 ctxp->current_parsed_class = \
883 TREE_CHAIN (GET_CPC_LIST ()); \
886 #define DEBUG_CPC() \
889 tree tmp = ctxp->current_parsed_class; \
892 fprintf (stderr, "%s ", \
893 IDENTIFIER_POINTER (TREE_PURPOSE (tmp))); \
894 tmp = TREE_CHAIN (tmp); \
899 /* Access to the various initializer statement lists */
900 #define CPC_INITIALIZER_LIST(C) ((C)->non_static_initialized)
901 #define CPC_STATIC_INITIALIZER_LIST(C) ((C)->static_initialized)
902 #define CPC_INSTANCE_INITIALIZER_LIST(C) ((C)->instance_initializers)
904 /* Access to the various initializer statements */
905 #define CPC_INITIALIZER_STMT(C) (TREE_PURPOSE (CPC_INITIALIZER_LIST (C)))
906 #define CPC_STATIC_INITIALIZER_STMT(C) \
907 (TREE_PURPOSE (CPC_STATIC_INITIALIZER_LIST (C)))
908 #define CPC_INSTANCE_INITIALIZER_STMT(C) \
909 (TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)))
911 /* Set various initializer statements */
912 #define SET_CPC_INITIALIZER_STMT(C,S) \
913 if (CPC_INITIALIZER_LIST (C)) \
914 TREE_PURPOSE (CPC_INITIALIZER_LIST (C)) = (S);
915 #define SET_CPC_STATIC_INITIALIZER_STMT(C,S) \
916 if (CPC_STATIC_INITIALIZER_LIST (C)) \
917 TREE_PURPOSE (CPC_STATIC_INITIALIZER_LIST (C)) = (S);
918 #define SET_CPC_INSTANCE_INITIALIZER_STMT(C,S) \
919 if (CPC_INSTANCE_INITIALIZER_LIST(C)) \
920 TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)) = (S);
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 void java_expand_switch PARAMS ((tree));
930 int java_report_errors PARAMS ((void));
931 extern tree do_resolve_class PARAMS ((tree, tree, tree, tree));
933 char *java_get_line_col PARAMS ((const char *, int, int));
934 extern void reset_report PARAMS ((void));
936 /* Always in use, no matter what you compile */
937 void java_push_parser_context PARAMS ((void));
938 void java_pop_parser_context PARAMS ((int));
939 void java_init_lex PARAMS ((FILE *, const char *));
940 extern void java_parser_context_save_global PARAMS ((void));
941 extern void java_parser_context_restore_global PARAMS ((void));
942 int yyparse PARAMS ((void));
943 extern int java_parse PARAMS ((void));
944 extern void yyerror PARAMS ((const char *))
949 extern void java_expand_classes PARAMS ((void));