OSDN Git Service

Tue Dec 1 13:53:24 1998 Alexandre Petit-Bianco <apbianco@cygnus.com>
[pf3gnuchains/gcc-fork.git] / gcc / java / java-tree.h
1 /* Definitions for parsing and type checking for the GNU compiler for
2    the Java(TM) language.
3    Copyright (C) 1997, 1998 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
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)
10 any later version.
11
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.
16
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.  
21
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.  */
25
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
27
28 /* Java language-specific tree codes.  */
29 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
30 enum java_tree_code {
31   __DUMMY = LAST_AND_UNUSED_TREE_CODE,
32 #include "java-tree.def"
33   LAST_JAVA_TREE_CODE
34 };
35 #undef DEFTREECODE
36
37 struct JCF;
38
39 /* Usage of TREE_LANG_FLAG_?:
40    0: IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (in IDENTIFIER_NODE)
41       RESOLVE_EXPRESSION_NAME_P (in EXPR_WITH_FILE_LOCATION)
42       IS_FOR_LOOP_P (in LOOP_EXPR)
43    1: CLASS_HAS_SUPER_FLAG (in TREE_VEC).
44       IS_A_CLASSFILE_NAME (in IDENTIFIER_NODE)
45       COMPOUND_ASSIGN_P (in EXPR (binop_*))
46    2: RETURN_MAP_ADJUSTED (in TREE_VEC).
47       QUALIFIED_P (in IDENTIFIER_NODE)
48       PRIMARY_P (in EXPR_WITH_FILE_LOCATION)
49       MODIFY_EXPR_FROM_INITIALIZATION_P (in MODIFY_EXPR)
50    3: IS_AN_IMPORT_ON_DEMAND_P (in IDENTIFIER_NODE)
51       RESOLVE_PACKAGE_NAME_P (in EXPR_WITH_FILE_LOCATION)
52       SWITCH_HAS_DEFAULT (in SWITCH_EXPR)
53    4: IS_A_COMMAND_LINE_FILENAME_P (in IDENTIFIER_NODE)
54       RESOLVE_TYPE_NAME_P (in EXPR_WITH_FILE_LOCATION)
55    5: HAS_BEEN_ALREADY_PARSED_P (in IDENTIFIER_NODE)
56       IS_BREAK_STMT_P (in EXPR_WITH_FILE_LOCATION)
57       IS_CRAFTED_STRING_BUFFER_P (in CALL_EXPR)
58    6: CAN_COMPLETE_NORMALLY (in statement nodes).
59
60    Usage of TYPE_LANG_FLAG_?:
61    1: TYPE_ARRAY_P (in RECORD_TYPE).
62    2: CLASS_LOADED_P (in RECORD_TYPE).
63    3: CLASS_FROM_SOURCE_P (in RECORD_TYPE).
64    4: CLASS_P (in RECORD_TYPE).
65    5: CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (in RECORD_TYPE)
66    6: CLASS_HAS_FINIT_P (in RECORD_TYPE)
67
68    Usage of DECL_LANG_FLAG_?:
69    0: METHOD_DEPRECATED (in FUNCTION_DECL).
70       FIELD_DEPRECATED (in FIELD_DECL).
71       CLASS_DEPRECATED (in TYPE_DECL).
72    1: METHOD_PUBLIC (in FUNCTION_DECL).
73       FIELD_PUBLIC (in FIELD_DECL).
74       CLASS_PUBLIC (in TYPE_DECL).
75    2: METHOD_STATIC (in FUNCTION_DECL).
76       (But note that FIELD_STATIC uses TREE_STATIC!)
77       CLASS_COMPLETE_P (in TYPE_DECL)
78    3: METHOD_FINAL (in FUNCTION_DECL)
79       FIELD_FINAL (in FIELD_DECL)
80       CLASS_FINAL (in TYPE_DECL)
81    4: METHOD_SYNCHRONIZED (in FUNCTION_DECL).
82       LABEL_IN_SUBR (in LABEL_DECL)
83       CLASS_INTERFACE (in TYPE_DECL)
84       FIELD_VOLATILE (int FIELD_DECL)
85    5: METHOD_ABSTRACT (in FUNCTION_DECL).
86       LABEL_IS_SUBR_START (in LABEL_DECL)
87       CLASS_ABSTRACT (in TYPE_DECL)
88       FIELD_TRANSIENT (in FIELD_DECL)
89    6: METHOD_TRANSIENT (in FUNCTION_DECL)
90       LABEL_CHANGED (in LABEL_DECL)
91       CLASS_SUPER (in TYPE_DECL, ACC_SUPER flag)
92       INITIALIZED_P (in FIELD_DECL, VAR_DECL, PARM_DECL)
93    7: DECL_CONSTRUCTOR_P (in FUNCTION_DECL).
94 */
95
96 /* True if the class whose TYPE_BINFO this is has a superclass.
97    (True of all classes except Object.) */
98 #define CLASS_HAS_SUPER_FLAG(BINFO) TREE_LANG_FLAG_1(BINFO)
99 #define CLASS_HAS_SUPER(TYPE) CLASS_HAS_SUPER_FLAG (TYPE_BINFO (TYPE))
100
101 /* Return the supertype of class TYPE, or NULL_TREE is it has none. */
102 #define CLASSTYPE_SUPER(TYPE) (CLASS_HAS_SUPER (TYPE) ? \
103   BINFO_TYPE (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (TYPE), 0)) : NULL_TREE)
104
105 /* True if the class we are compiling is a .java source file;
106    false if it is a .class bytecode file. */
107 extern int compiling_from_source;
108
109 /* The class defined by the actual (main) file we are compiling. */
110 extern tree main_class;
111
112 /* The class we are currently processing. */
113 extern tree current_class;
114
115 /* List of all class DECLs seen so far.  */
116 extern tree all_class_list;
117
118 /* Nonzero if we want to automatically do array bounds checking;
119    on by default.  Use -fno-bounds-check to disable.  */
120
121 extern int flag_bounds_check;
122
123 /* Nonzero if we should make is_compiled_class always return 1 for
124    appropriate classes that we're referencing.  */
125
126 extern int flag_assume_compiled;
127
128 extern int flag_emit_class_files;
129
130 /* Turned to 1 if -Wall was encountered. See lang.c for their meanings.  */
131 extern int flag_wall;
132 extern int flag_redundant;
133 extern int flag_not_overriding;
134 extern int flag_static_local_jdk1_1;
135
136 /* The Java .class file that provides main_class;  the main input file. */
137 extern struct JCF main_jcf[1], *current_jcf;
138
139 typedef struct CPool constant_pool;
140
141 #define CONSTANT_ResolvedFlag 16
142
143 /* The cpool->data[i] for a ResolvedString points to a STRING_CST. */
144 #define CONSTANT_ResolvedString    (CONSTANT_String+CONSTANT_ResolvedFlag)
145
146 /* The cpool->data[i] for a ResolvedClass points to a RECORD_TYPE. */
147 #define CONSTANT_ResolvedClass     (CONSTANT_Class+CONSTANT_ResolvedFlag)
148
149 #define CPOOL_UTF(CPOOL, INDEX) ((tree) (CPOOL)->data[INDEX])
150
151 /* A NameAndType constant is represented as a TREE_LIST.
152    The type is the signature string (as an IDENTIFIER_NODE).  */
153
154 #define NAME_AND_TYPE_NAME(CPOOL, IDX) \
155   CPOOL_UTF(CPOOL, CPOOL_USHORT1(CPOOL, IDX))
156 #define NAME_AND_TYPE_SIGNATURE(CPOOL, IDX) \
157   CPOOL_UTF(CPOOL, CPOOL_USHORT2(CPOOL, IDX))
158
159 /* A FieldRef, MethodRef or InterfaceMethodRef constant
160    is represented as a TREE_LIST. */
161
162 #define COMPONENT_REF_CLASS_INDEX(CPOOL, IDX) CPOOL_USHORT1(CPOOL, IDX)
163 #define COMPONENT_REF_NAME_AND_TYPE(CPOOL, IDX) CPOOL_USHORT2(CPOOL, IDX)
164 #define COMPONENT_REF_NAME(CPOOL, IDX) \
165   NAME_AND_TYPE_NAME (CPOOL, COMPONENT_REF_NAME_AND_TYPE(CPOOL, IDX))
166 #define COMPONENT_REF_SIGNATURE(CPOOL, IDX) \
167   NAME_AND_TYPE_SIGNATURE (CPOOL, COMPONENT_REF_NAME_AND_TYPE(CPOOL, IDX))
168
169 /* "Promoted types" that are used for primitive types smaller
170    than int.  We could use int_type_node, but then we would lose
171    type information (such as needed for debugging). */
172 extern tree promoted_byte_type_node;
173 extern tree promoted_short_type_node;
174 extern tree promoted_char_type_node;
175 extern tree promoted_boolean_type_node;
176
177 extern tree byte_type_node;
178 extern tree short_type_node;
179 extern tree int_type_node;
180 extern tree long_type_node;
181
182 extern tree unsigned_byte_type_node;
183 extern tree unsigned_short_type_node;
184 extern tree unsigned_int_type_node;
185 extern tree unsigned_long_type_node;
186
187 extern tree boolean_type_node;
188 extern tree char_type_node;
189 extern tree float_type_node;
190 extern tree double_type_node;
191
192 extern tree object_type_node;
193 extern tree unqualified_object_id_node;
194 extern tree object_ptr_type_node;
195 extern tree string_type_node;
196 extern tree throwable_type_node;
197 extern tree runtime_exception_type_node;
198 extern tree error_exception_type_node;
199
200 extern tree byte_array_type_node;
201 extern tree short_array_type_node;
202 extern tree int_array_type_node;
203 extern tree long_array_type_node;
204 extern tree boolean_array_type_node;
205 extern tree char_array_type_node;
206 extern tree double_array_type_node;
207 extern tree float_array_type_node;
208 extern tree array_array_type_node;
209 extern tree object_array_type_node;
210 extern tree string_array_type_node;
211 extern tree TYPE_identifier_node;      /* "TYPE" */
212 extern tree init_identifier_node;      /* "<init>" */
213 extern tree clinit_identifier_node;      /* "<clinit>" */
214 extern tree finit_identifier_node;      /* "<finit>" */
215 extern tree void_signature_node;       /* "()V" */
216 extern tree length_identifier_node;  /* "length" */
217 extern tree this_identifier_node;  /* "this" */
218 extern tree super_identifier_node;  /* "super" */
219 extern tree one_elt_array_domain_type;
220 extern tree void_type_node;
221 extern tree ptr_type_node;
222 /* The type of the return address of a subroutine. */
223 extern tree return_address_type_node;
224
225 /* Nodes for boolean constants TRUE and FALSE. */
226 extern tree boolean_true_node, boolean_false_node;
227
228 /* Integer constants not declared in tree.h. */
229 extern tree integer_negative_one_node;
230 extern tree integer_two_node;
231 extern tree integer_four_node;
232 extern tree empty_stmt_node;
233
234 /* The type for struct methodtable. */
235 extern tree methodtable_type;
236 extern tree methodtable_ptr_type;
237
238 extern tree utf8const_type;
239 extern tree utf8const_ptr_type;
240
241 extern tree class_type_node;
242 extern tree class_ptr_type;
243 extern tree field_type_node;
244 extern tree constants_type_node;
245 extern tree dtable_type, dtable_ptr_type;
246 extern tree field_ptr_type_node;
247 extern tree field_info_union_node;
248 extern tree method_type_node;
249 extern tree method_ptr_type_node;
250 #define nativecode_ptr_type_node ptr_type_node
251
252 extern tree end_params_node;
253
254 /* References to internal libjava functions we use. */
255 extern tree alloc_object_node;
256 extern tree soft_instanceof_node;
257 extern tree soft_checkcast_node;
258 extern tree soft_initclass_node;
259 extern tree soft_newarray_node;
260 extern tree soft_anewarray_node;
261 extern tree soft_multianewarray_node;
262 extern tree soft_badarrayindex_node;
263 extern tree throw_node;
264 extern tree soft_checkarraystore_node;
265 extern tree soft_monitorenter_node;
266 extern tree soft_monitorexit_node;
267 extern tree soft_lookupinterfacemethod_node;
268 extern tree soft_fmod_node;
269 extern tree soft_exceptioninfo_call_node;
270
271 extern tree access_flags_type_node;
272
273 extern tree class_dtable_decl;
274
275 /* They need to be reset before processing each class */
276 extern struct CPool *outgoing_cpool; 
277 extern tree current_constant_pool_data_ref;
278
279 extern tree wfl_operator;
280
281 struct lang_identifier
282 {
283   struct tree_identifier ignore;
284   tree global_value, local_value;
285
286   /* If non-NULL:  An ADDR_REF to a VAR_DECL that contains
287    * the Utf8Const representation of the identifier.  */
288   tree utf8_ref;
289 };
290
291 /* Macros for access to language-specific slots in an identifier.  */
292 /* UNless specifide, each of these slots contains a DECL node or null.  */
293
294 /* This represents the value which the identifier has in the
295    file-scope namespace.  */
296 #define IDENTIFIER_GLOBAL_VALUE(NODE)   \
297   (((struct lang_identifier *)(NODE))->global_value)
298 /* This represents the value which the identifier has in the current
299    scope.  */
300 #define IDENTIFIER_LOCAL_VALUE(NODE)    \
301   (((struct lang_identifier *)(NODE))->local_value)
302
303 /* Given an identifier NODE, get the corresponding (non-handle) class.
304    For get_identifier ("java.lang.Number"), the result is
305    the struct whose DECL_ASSEMBLER_NAME is "Classjava_lang_Number". */
306 #define IDENTIFIER_CLASS_VALUE(NODE) IDENTIFIER_GLOBAL_VALUE(NODE)
307
308 /* Given an identifier NODE, get the corresponding handle class.
309    For get_identifier ("java.lang.Number"), the result is
310    the struct whose DECL_ASSEMBLER_NAME is "Hjava_lang_Number". */
311 #define IDENTIFIER_HANDLECLASS_VALUE(NODE) ???
312
313 /* Given a signature of a reference (or array) type, or a method, return the
314    corresponding type (if one has been allocated).
315    Do not use for primitive types, since they may be ambiguous.
316    (E.g. is "I" a signature or a class name?) */
317 #define IDENTIFIER_SIGNATURE_TYPE(NODE) IDENTIFIER_GLOBAL_VALUE(NODE)
318
319 /* If non-NULL:  An ADDR_REF to a VAR_DECL that contains
320    the Utf8Const representation of the identifier.  */
321 #define IDENTIFIER_UTF8_REF(NODE) \
322   (((struct lang_identifier *)(NODE))->utf8_ref)
323
324 #define IDENTIFIER_UTF8_DECL(NODE) \
325   TREE_OPERAND((((struct lang_identifier *)(NODE))->utf8_ref), 0)
326
327 /* For a FUNCTION_DECL, if we are compiling a .class file, then this is
328    the position in the .class file of the method code.
329    Specifically, this is the code itself, not the code attribute. */
330 #define DECL_CODE_OFFSET(DECL) (DECL_LANG_SPECIFIC(DECL)->code_offset)
331 /* Similarly, the length of the bytecode. */
332 #define DECL_CODE_LENGTH(DECL) (DECL_LANG_SPECIFIC(DECL)->code_length)
333 /* Similarly, the position of the LineNumberTable attribute. */
334 #define DECL_LINENUMBERS_OFFSET(DECL) \
335   (DECL_LANG_SPECIFIC(DECL)->linenumbers_offset)
336 /* Similarly, the position of the LocalVariableTable attribute
337    (following the standard attribute header). */
338 #define DECL_LOCALVARIABLES_OFFSET(DECL) \
339   (DECL_LANG_SPECIFIC(DECL)->localvariables_offset)
340
341 #define DECL_MAX_LOCALS(DECL) (DECL_LANG_SPECIFIC(DECL)->max_locals)
342 #define DECL_MAX_STACK(DECL) (DECL_LANG_SPECIFIC(DECL)->max_stack)
343 /* Number of local variable slots needed for the arguments of this function. */
344 #define DECL_ARG_SLOT_COUNT(DECL) (DECL_LANG_SPECIFIC(DECL)->arg_slot_count)
345 /* List of checked thrown exceptions, as specified with the `throws'
346    keyword */
347 #define DECL_FUNCTION_THROWS(DECL) (DECL_LANG_SPECIFIC(DECL)->throws_list)
348 /* List of other constructors of the same class that this constructor
349    calls */
350 #define DECL_CONSTRUCTOR_CALLS(DECL) \
351   (DECL_LANG_SPECIFIC(DECL)->called_constructor)
352 /* Pointer to the function's current's COMPOUND_EXPR tree (while
353    completing its body) or the function's block */
354 #define DECL_FUNCTION_BODY(DECL) (DECL_LANG_SPECIFIC(DECL)->function_decl_body)
355 /* How specific the function is (for method selection - Java source
356    code front-end */
357 #define DECL_SPECIFIC_COUNT(DECL) DECL_ARG_SLOT_COUNT(DECL)
358
359 /* In a LABEL_DECL, a TREE_VEC that saves the type_map at that point. */
360 #define LABEL_TYPE_STATE(NODE) (DECL_INITIAL (NODE))
361
362 /* In the label of a subroutine, a dummy label that records the
363    state following a merge of all the ret instructions in this subroutine. */
364 #define LABEL_RETURN_LABEL(DECL) DECL_ARGUMENTS(DECL)
365
366 /* In the label of a sub-routine, records the type state at return.
367  * A local may be TYPE_UNUSED, which means that the local is not
368  * used (stored to or loaded from) in this subroutine - at least for
369  * code that we have verified so far. */
370 #define LABEL_RETURN_TYPE_STATE(NODE) LABEL_TYPE_STATE (LABEL_RETURN_LABEL (NODE))
371
372 /* In a TREE_VEC for a LABEL_RETURN_TYPE_STATE, notes that
373    TREE_VEC_LENGTH has been adjust to the correct stack size. */
374 #define RETURN_MAP_ADJUSTED(NODE) TREE_LANG_FLAG_2(NODE)
375
376 /* In the label of a sub-routine, a chain of the return location labels. */
377 #define LABEL_RETURN_LABELS(node) DECL_RESULT (LABEL_RETURN_LABEL(node))
378
379 /* In a LABEL_DECL, the next pending label.
380    See pending_blocks in expr.c. */
381 #define LABEL_PENDING_CHAIN(NODE) DECL_RESULT(NODE)
382
383 /* In a LABEL_DECL, the corresponding bytecode program counter. */
384 #define LABEL_PC(NODE) ((NODE)->decl.saved_insns.i)
385
386 /* Used during verification to mark the label has "changed". (See JVM Spec). */
387 #define LABEL_CHANGED(NODE) DECL_LANG_FLAG_6(NODE)
388
389 /* In a LABEL_DECL, true if we have verified instructions starting here. */
390 #define LABEL_VERIFIED(NODE) (instruction_bits[LABEL_PC(NODE)]&BCODE_VERIFIED)
391
392 /* True if this code is within a subroutine (target of a jsr). */
393 #define LABEL_IN_SUBR(NODE) DECL_LANG_FLAG_4(NODE)
394 /* True if this code is the start of a subroutine (target of a jsr). */
395 #define LABEL_IS_SUBR_START(NODE) DECL_LANG_FLAG_5(NODE)
396
397 /* In a LABEL_DECL, if LABEL_IN_SUBR(NODE), points to start of subroutine. */
398 #define LABEL_SUBR_START(NODE) DECL_ABSTRACT_ORIGIN(NODE)
399
400 /* In a LABEL_DECL that has LABEL_IS_SUBR_START, this points to the start
401    of surrounding subroutine in the case of a nested subroutine,
402    and NULL_TREE otherwise. */
403 #define LABEL_SUBR_CONTEXT(NODE) DECL_CONTEXT (LABEL_RETURN_LABEL (NODE))
404
405 /* The slot number for this local variable. */
406 #define DECL_LOCAL_SLOT_NUMBER(NODE) \
407   (((struct lang_decl_var*)DECL_LANG_SPECIFIC(NODE))->slot_number)
408 /* The start (bytecode) pc for the valid range of this local variable. */
409 #define DECL_LOCAL_START_PC(NODE) \
410   (((struct lang_decl_var*)DECL_LANG_SPECIFIC(NODE))->start_pc)
411 /* The end (bytecode) pc for the valid range of this local variable. */
412 #define DECL_LOCAL_END_PC(NODE) \
413   (((struct lang_decl_var*)DECL_LANG_SPECIFIC(NODE))->end_pc)
414 /* For a VAR_DECLor PARM_DECL, used to chain decls with the same
415    slot_number in decl_map. */
416 #define DECL_LOCAL_SLOT_CHAIN(NODE) \
417   (((struct lang_decl_var*)DECL_LANG_SPECIFIC(NODE))->slot_chain)
418 /* For a static field seen from the parser, it holds its associated
419    value, the one returned when the field is looked up. */
420 #define DECL_LOCAL_STATIC_VALUE(NODE) DECL_LOCAL_SLOT_CHAIN (NODE)
421
422 /* DECL_LANG_SPECIFIC for FUNCTION_DECLs. */
423 struct lang_decl
424 {
425   /*  tree chain; not yet used. */
426   long code_offset;
427   int code_length;
428   long linenumbers_offset;
429   long localvariables_offset;
430   int arg_slots;
431   int max_locals, max_stack, arg_slot_count;
432   tree throws_list;             /* Exception specified by `throws' */
433   tree function_decl_body;      /* Hold all function's statements */
434   tree called_constructor;      /* When decl is a constructor, the
435                                    list of other constructor it calls. */
436 };
437
438 /* DECL_LANG_SPECIFIC for VAR_DECL and PARM_DECL. */
439 struct lang_decl_var
440 {
441   int slot_number;
442   int start_pc;
443   int end_pc;
444   tree slot_chain;
445 };
446
447 struct lang_type
448 {
449   tree signature;
450   struct JCF *jcf;
451 };
452
453 #ifdef JAVA_USE_HANDLES
454 /* TYPE_BINFO_HANDLE points from a handle-class to its corresponding
455    non-handle-class, and vice verse. */
456
457 #define BINFO_HANDLE(NODE) TREE_VEC_ELT ((NODE), 6)
458
459 /* Given a RECORD_TYPE for a handle type, return the corresponding class. */
460 #define HANDLE_TO_CLASS_TYPE(HTYPE) BINFO_HANDLE (TYPE_BINFO (HTYPE))
461
462 /* Given a RECORD_TYPE for a class, return the corresponding handle type. */
463 #define CLASS_TO_HANDLE_TYPE(TYPE) BINFO_HANDLE (TYPE_BINFO (TYPE))
464 #else
465 #define HANDLE_TO_CLASS_TYPE(HTYPE) (HTYPE)
466 #define CLASS_TO_HANDLE_TYPE(TYPE) (TYPE)
467 #endif
468
469 #define JCF_u4 unsigned long
470 #define JCF_u2 unsigned short
471
472 extern tree lookup_class PROTO ((tree));
473 extern tree lookup_java_constructor PROTO ((tree, tree));
474 extern tree lookup_java_method PROTO ((tree, tree, tree));
475 extern tree lookup_argument_method PROTO ((tree, tree, tree));
476 extern tree promote_type PROTO ((tree));
477 extern tree get_constant PROTO ((struct JCF*, int));
478 extern tree get_name_constant PROTO ((struct JCF*, int));
479 extern tree get_class_constant PROTO ((struct JCF*, int));
480 extern tree parse_signature PROTO ((struct JCF *jcf, int sig_index));
481 extern void jcf_parse PROTO ((struct JCF*));
482 extern tree add_field PROTO ((tree, tree, tree, int));
483 extern tree add_method PROTO ((tree, int, tree, tree));
484 extern tree add_method_1 PROTO ((tree, int, tree, tree));
485 extern tree make_class ();
486 extern tree push_class PROTO ((tree, tree));
487 extern tree unmangle_classname PROTO ((const char *name, int name_length));
488 extern tree parse_signature_string PROTO ((const unsigned char *, int));
489 extern tree get_type_from_signature PROTO ((tree));
490 extern void layout_class PROTO ((tree));
491 extern tree layout_class_method PROTO ((tree, tree, tree, tree));
492 extern void layout_class_methods PROTO ((tree));
493 extern tree make_class ();
494 extern tree build_class_ref PROTO ((tree));
495 extern tree build_dtable_decl PROTO ((tree));
496 extern tree build_internal_class_name PROTO ((tree));
497 extern tree build_constants_constructor ();
498 extern tree build_ref_from_constant_pool PROTO ((int));
499 extern tree build_utf8_ref PROTO ((tree));
500 extern tree ident_subst PROTO ((const char*, int,
501                                 const char*, int, int, const char*));
502 extern tree identifier_subst PROTO ((const tree,
503                                      const char *, int, int, const char *));
504 extern tree build_java_signature PROTO ((tree));
505 extern tree build_java_argument_signature PROTO ((tree));
506 extern void set_java_signature PROTO ((tree, tree));
507 extern tree build_static_field_ref PROTO ((tree));
508 extern tree build_address_of PROTO ((tree));
509 extern tree find_local_variable PROTO ((int index, tree type, int pc));
510 extern tree find_stack_slot PROTO ((int index, tree type));
511 extern tree build_prim_array_type PROTO ((tree, HOST_WIDE_INT));
512 extern tree build_java_array_type PROTO ((tree, HOST_WIDE_INT));
513 extern int is_compiled_class PROTO ((tree));
514 extern tree mangled_classname PROTO ((char*, tree));
515 extern tree lookup_label PROTO ((int));
516 extern tree pop_type PROTO ((tree));
517 extern void pop_argument_types PROTO ((tree));
518 extern tree decode_newarray_type PROTO ((int));
519 extern tree lookup_field PROTO ((tree*, tree));
520 extern int is_array_type_p PROTO ((tree));
521 extern HOST_WIDE_INT java_array_type_length PROTO ((tree));
522 extern void load_class PROTO ((tree, int));
523
524 extern tree lookup_name PROTO ((tree));
525 extern tree build_known_method_ref PROTO ((tree, tree, tree, tree, tree));
526 extern tree build_class_init PROTO ((tree, tree));
527 extern tree build_invokevirtual PROTO ((tree, tree));
528 extern tree build_invokeinterface PROTO ((tree, tree, tree));
529 extern tree invoke_build_dtable PROTO ((int, tree));
530 extern tree build_field_ref PROTO ((tree, tree, tree));
531 extern void pushdecl_force_head PROTO ((tree));
532 extern tree build_java_binop PROTO ((enum tree_code, tree, tree, tree));
533 extern tree binary_numeric_promotion PROTO ((tree, tree, tree *, tree *));
534 extern tree build_java_arrayaccess PROTO ((tree, tree, tree));
535 extern tree build_newarray PROTO ((int, tree));
536 extern tree build_anewarray PROTO ((tree, tree));
537 extern tree build_java_array_length_access PROTO ((tree));
538 extern tree build_java_arraynull_check PROTO ((tree, tree, tree));
539 extern tree create_label_decl PROTO ((tree));
540 extern void push_labeled_block PROTO ((tree));
541 extern tree prepare_eh_table_type PROTO ((tree));
542 extern void java_set_exception_lang_code PROTO (());
543 extern tree generate_name PROTO ((void));
544 extern void pop_labeled_block PROTO (());
545 extern char *lang_printable_name PROTO ((tree, int));
546 extern tree maybe_add_interface PROTO ((tree, tree));
547 extern void set_super_info PROTO ((int, tree, tree, int));
548 extern int get_access_flags_from_decl PROTO ((tree));
549 extern int interface_of_p PROTO ((tree, tree));
550 extern int inherits_from_p PROTO ((tree, tree));
551 extern void complete_start_java_method PROTO ((tree));
552 extern void emit_handlers PROTO (());
553 extern void init_outgoing_cpool PROTO (());
554 extern void make_class_data PROTO ((tree));
555 extern void register_class PROTO (());
556 extern int alloc_name_constant PROTO ((int, tree));
557 extern void emit_register_classes PROTO (());
558 extern void lang_init_source PROTO ((int));
559 extern void write_classfile PROTO ((tree));
560 extern char *print_int_node PROTO ((tree));
561 extern void parse_error_context VPROTO ((tree cl, char *msg, ...));
562 extern tree build_primtype_type_ref PROTO ((char *));
563 extern tree java_get_real_method_name PROTO ((tree));
564 extern void finish_class PROTO ((tree));
565
566 /* Access flags etc for a method (a FUNCTION_DECL): */
567
568 #define METHOD_PUBLIC(DECL) DECL_LANG_FLAG_1 (DECL)
569 #define METHOD_PRIVATE(DECL) TREE_PRIVATE (DECL)
570 #define METHOD_PROTECTED(DECL) TREE_PROTECTED (DECL)
571 #define METHOD_STATIC(DECL) DECL_LANG_FLAG_2 (DECL)
572 #define METHOD_FINAL(DECL) DECL_LANG_FLAG_3 (DECL)
573 #define METHOD_SYNCHRONIZED(DECL) DECL_LANG_FLAG_4 (DECL)
574 #define METHOD_NATIVE(DECL) DECL_EXTERNAL(DECL)
575 #define METHOD_ABSTRACT(DECL) DECL_LANG_FLAG_5 (DECL)
576 #define METHOD_TRANSIENT(DECL) DECL_LANG_FLAG_6 (DECL)
577
578 #define DECL_CONSTRUCTOR_P(DECL) DECL_LANG_FLAG_7(DECL)
579
580 /* Access flags etc for a variable/field (a FIELD_DECL): */
581
582 #define FIELD_PRIVATE(DECL) TREE_PRIVATE (DECL)
583 #define FIELD_PROTECTED(DECL) TREE_PROTECTED (DECL)
584 #define FIELD_PUBLIC(DECL) DECL_LANG_FLAG_1 (DECL)
585 #define FIELD_STATIC(DECL) TREE_STATIC (DECL)
586 #define FIELD_FINAL(DECL) DECL_LANG_FLAG_3 (DECL)
587 #define FIELD_VOLATILE(DECL) DECL_LANG_FLAG_4 (DECL)
588 #define FIELD_TRANSIENT(DECL) DECL_LANG_FLAG_5 (DECL)
589
590 /* Initialized flag on variable/field/parm decl */
591
592 #define INITIALIZED_P(DECL) DECL_LANG_FLAG_6 (DECL)
593
594 /* Access flags etc for a class (a TYPE_DECL): */
595
596 #define CLASS_PUBLIC(DECL) DECL_LANG_FLAG_1 (DECL)
597 #define CLASS_FINAL(DECL) DECL_LANG_FLAG_3 (DECL)
598 #define CLASS_INTERFACE(DECL) DECL_LANG_FLAG_4 (DECL)
599 #define CLASS_ABSTRACT(DECL) DECL_LANG_FLAG_5 (DECL)
600 #define CLASS_SUPER(DECL) DECL_LANG_FLAG_6 (DECL)
601
602 /* @deprecated marker flag on methods, fields and classes */
603
604 #define METHOD_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
605 #define FIELD_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
606 #define CLASS_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
607 #define DECL_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
608
609 /* The number of virtual methods in this class's dispatch table.
610  Does not include initial two dummy entries (one points to the
611  Class object, and the other is for G++ -fvtable-thunks compatibility). */
612 #define TYPE_NVIRTUALS(TYPE) TYPE_BINFO_VIRTUALS (TYPE)
613
614 /* A TREE_VEC (indexed by DECL_VINDEX) containing this class's
615    virtual methods. */
616 #define TYPE_VTABLE(TYPE) TYPE_BINFO_VTABLE(TYPE)
617
618 /* Use CLASS_LOADED_P? FIXME */
619 #define CLASS_COMPLETE_P(DECL) DECL_LANG_FLAG_2 (DECL) 
620
621 /* This maps a bytecode offset (PC) to various flags,
622    listed below (starting with BCODE_). */
623 extern char *instruction_bits;
624
625 /* True iff the byte is the start of an instruction. */
626 #define BCODE_INSTRUCTION_START 1
627
628 /* True iff there is a jump to this location. */
629 #define BCODE_JUMP_TARGET 2
630
631 /* True iff there is a return to this location.
632    (I.e. the preceedng instruction was a call.) */
633 #define BCODE_RETURN_TARGET 4
634
635 /* True iff this is the start of an exception handler. */
636 #define BCODE_EXCEPTION_TARGET 16
637
638 /* True iff there is a jump to this location (and it needs a label). */
639 #define BCODE_TARGET \
640   (BCODE_JUMP_TARGET|BCODE_RETURN_TARGET \
641    | BCODE_EXCEPTION_TARGET)
642
643 /* True iff there is an entry in the linenumber table for this location. */
644 #define BCODE_HAS_LINENUMBER 32
645
646 /* True iff there is more than one entry in the linenumber table for
647    this location.  (This probably does not make much sense.)  */
648 #define BCODE_HAS_MULTI_LINENUMBERS 64
649
650 /* True if this instruction has been verified. */
651 #define BCODE_VERIFIED 8
652
653 /* A pointer to the line number table of the current method. */
654 extern unsigned char *linenumber_table;
655 /* The length (in items) of the line number table. */
656 extern int linenumber_count;
657
658 /* In type_map, means that slot is uninitialized or otherwise unusable. */
659 #define TYPE_UNKNOWN NULL_TREE
660
661 /* In type_map, means the second half of a 64-bit double or long. */
662 #define TYPE_SECOND void_type_node
663
664 /* In type_map, means the null type (i.e. type of a null reference). */ 
665 #define TYPE_NULL ptr_type_node
666
667 /* In a type map means the type the address subroutine return address. */
668 #define TYPE_RETURN_ADDR return_address_type_node
669
670 /* In a subroutine's return type map, indicates that the slot was neither
671    used nor set in the subroutine. */
672 #define TYPE_UNUSED error_mark_node
673
674 /* A array mapping variable/stack slot index to the type current
675    in that variable/stack slot.
676    TYPE_UNKNOWN, TYPE_SECOND, and TYPE_NULL are special cases. */
677 extern tree *type_map;
678
679 /* Map a stack index to the type currently in that slot. */
680 #define stack_type_map (type_map+DECL_MAX_LOCALS(current_function_decl))
681
682 /* True iff TYPE takes two variable/stack slots. */
683 #define TYPE_IS_WIDE(TYPE) \
684   ((TYPE) == double_type_node || (TYPE) == long_type_node)
685
686 /* True iff TYPE is a Java array type. */
687 #define TYPE_ARRAY_P(TYPE) TYPE_LANG_FLAG_1 (TYPE)
688
689 /* If FUNCTION_TYPE or METHOD_TYPE: cache for build_java_argument_signature. */
690 #define TYPE_ARGUMENT_SIGNATURE(TYPE) TYPE_VFIELD(TYPE)
691
692 /* Given an array type, give the type of the elements. */
693 /* FIXME this use of TREE_TYPE conflicts with something or other. */
694 #define TYPE_ARRAY_ELEMENT(ATYPE) TREE_TYPE(ATYPE)
695
696 /* True if class TYPE has been loaded. */
697 #define CLASS_LOADED_P(TYPE) TYPE_LANG_FLAG_2 (TYPE)
698
699 /* True if class TYPE was defined in Java source code. */
700 #define CLASS_FROM_SOURCE_P(TYPE) TYPE_LANG_FLAG_3 (TYPE)
701
702 /* True of a RECORD_TYPE of a class/interface type (not array type) */
703 #define CLASS_P(TYPE) TYPE_LANG_FLAG_4 (TYPE)
704
705 /* True if class TYPE was defined in a Java source file compiled. */
706 #define CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P(TYPE) \
707   TYPE_LANG_FLAG_5 (TYPE)
708
709 /* True if class TYPE has a field initializer <finit> function */
710 #define CLASS_HAS_FINIT_P(TYPE) TYPE_LANG_FLAG_6 (TYPE)
711
712 /* True if identifier ID was seen while processing a single type import stmt */
713 #define IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P(ID) TREE_LANG_FLAG_0 (ID)
714
715 /* True if identifier ID was seen while processing an import statement */
716 #define IS_A_CLASSFILE_NAME(ID) TREE_LANG_FLAG_1 (ID)
717
718 /* True if ID is a qualified named (contains . or /) */
719 #define QUALIFIED_P(ID) TREE_LANG_FLAG_2 (ID)
720
721 /* True if ID is an already processed import on demand */
722 #define IS_AN_IMPORT_ON_DEMAND_P(ID) TREE_LANG_FLAG_3 (ID)
723
724 /* True if ID is a command-line specified filename */
725 #define IS_A_COMMAND_LINE_FILENAME_P(ID) TREE_LANG_FLAG_4 (ID)
726
727 /* True if filename ID has already been parsed */
728 #define HAS_BEEN_ALREADY_PARSED_P(ID) TREE_LANG_FLAG_5 (ID)
729
730 /* True if EXPR is RHS sub-tree of a compound assign expression */
731 #define COMPOUND_ASSIGN_P(EXPR) TREE_LANG_FLAG_1 (EXPR)
732
733 /* True if a SWITCH_EXPR has a DEFAULT_EXPR. */
734 #define SWITCH_HAS_DEFAULT(NODE) TREE_LANG_FLAG_3 (NODE)
735
736 /* True if EXPR (a WFL in that case) was created after the
737    reduction of PRIMARY . XXX */
738 #define PRIMARY_P(EXPR) TREE_LANG_FLAG_2 (EXPR)
739
740 /* True if EXPR (a MODIFY_EXPR in that case) is the result of variable
741    initialization during its declaration */
742 #define MODIFY_EXPR_FROM_INITIALIZATION_P(EXPR) TREE_LANG_FLAG_2 (EXPR)
743
744 /* True if EXPR (a WFL in that case) resolves into an expression name */
745 #define RESOLVE_EXPRESSION_NAME_P(WFL) TREE_LANG_FLAG_0 (WFL)
746
747 /* True if EXPR (a LOOP_EXPR in that case) is part of a for statement */
748 #define IS_FOR_LOOP_P(EXPR) TREE_LANG_FLAG_0 (EXPR)
749
750 /* True if EXPR (a WFL in that case) resolves into a package name */
751 #define RESOLVE_PACKAGE_NAME_P(WFL) TREE_LANG_FLAG_3 (WFL)
752
753 /* True if EXPR (a WFL in that case) resolves into a type name */
754 #define RESOLVE_TYPE_NAME_P(WFL) TREE_LANG_FLAG_4 (WFL)
755
756 /* True if STMT (a WFL in that case) holds a BREAK statement */
757 #define IS_BREAK_STMT_P(WFL) TREE_LANG_FLAG_5 (WFL)
758
759 /* True if EXPR (a CALL_EXPR in that case) is a crafted StringBuffer */
760 #define IS_CRAFTED_STRING_BUFFER_P(EXPR) TREE_LANG_FLAG_5 (EXPR)
761
762 /* True if NODE (a statement) can complete normally. */
763 #define CAN_COMPLETE_NORMALLY(NODE) TREE_LANG_FLAG_6(NODE)
764
765 /* Add a FIELD_DECL to RECORD_TYPE RTYPE.
766    The field has name NAME (a char*), and type FTYPE.
767    Unless this is the first field, FIELD most hold the previous field.
768    FIELD is set to the newly created FIELD_DECL.
769
770    We set DECL_ARTIFICIAL so these fields get skipped by make_class_data
771    if compiling java.lang.Object or java.lang.Class. */
772
773 #define PUSH_FIELD(RTYPE, FIELD, NAME, FTYPE) \
774 { tree tmp_field = build_decl (FIELD_DECL, get_identifier(NAME), FTYPE); \
775   if (TYPE_FIELDS (RTYPE) == NULL_TREE) TYPE_FIELDS (RTYPE) = tmp_field; \
776   else TREE_CHAIN(FIELD) = tmp_field; \
777   DECL_CONTEXT (tmp_field) = RTYPE; \
778   DECL_ARTIFICIAL (tmp_field) = 1; \
779   FIELD = tmp_field; }
780
781 #define FINISH_RECORD(RTYPE) layout_type (RTYPE)
782
783 /* Start building a RECORD_TYPE constructor with a given TYPE in CONS. */
784 #define START_RECORD_CONSTRUCTOR(CONS, CTYPE) { \
785   CONS = build (CONSTRUCTOR, CTYPE, NULL_TREE, NULL_TREE);\
786   TREE_CHAIN(CONS) = TYPE_FIELDS (CTYPE); }
787
788 /* Append a field initializer to CONS for the dummy field for the inherited
789    fields.  The dummy field has the given VALUE, and the same type as the
790    super-class.   Must be specified before calls to PUSH_FIELD_VALUE. */
791
792 #define PUSH_SUPER_VALUE(CONS, VALUE) {\
793   tree field = TREE_CHAIN(CONS);\
794   if (DECL_NAME (field) != NULL_TREE) abort();\
795   CONSTRUCTOR_ELTS(CONS) = tree_cons (field, VALUE, CONSTRUCTOR_ELTS(CONS));\
796   TREE_CHAIN(CONS) = TREE_CHAIN (field); }
797
798 /* Append a field initializer to CONS for a field with the given VALUE.
799    NAME is a char* string used for error checking;
800    the initializer must be specified in order. */
801 #define PUSH_FIELD_VALUE(CONS, NAME, VALUE) {\
802   tree field = TREE_CHAIN(CONS);\
803   if (strcmp (IDENTIFIER_POINTER (DECL_NAME (field)), NAME) != 0) abort();\
804   CONSTRUCTOR_ELTS(CONS) = tree_cons (field, VALUE, CONSTRUCTOR_ELTS(CONS));\
805   TREE_CHAIN(CONS) = TREE_CHAIN (field); }
806
807 /* Finish creating a record CONSTRUCTOR CONS. */
808 #define FINISH_RECORD_CONSTRUCTOR(CONS) \
809   CONSTRUCTOR_ELTS(CONS) = nreverse (CONSTRUCTOR_ELTS(CONS))
810
811 /* Macros on constructors invocations.  */
812 #define CALL_CONSTRUCTOR_P(NODE)                \
813   (TREE_CODE (NODE) == NEW_CLASS_EXPR || CALL_EXPLICIT_CONSTRUCTOR_P (NODE))
814
815 #define CALL_EXPLICIT_CONSTRUCTOR_P(NODE)                               \
816   (CALL_THIS_CONSTRUCTOR_P (NODE) || CALL_SUPER_CONSTRUCTOR_P (NODE))
817
818 #define CALL_THIS_CONSTRUCTOR_P(NODE)                                   \
819   (TREE_CODE (NODE) == CALL_EXPR                                        \
820    && EXPR_WFL_NODE (TREE_OPERAND (NODE, 0)) == this_identifier_node)
821
822 #define CALL_SUPER_CONSTRUCTOR_P(NODE)                                  \
823   (TREE_CODE (NODE) == CALL_EXPR                                        \
824    && EXPR_WFL_NODE (TREE_OPERAND (NODE, 0)) == super_identifier_node)
825
826 /* Using a FINALLY_EXPR node */
827 #define FINALLY_EXPR_LABEL(NODE) TREE_OPERAND ((NODE), 0)
828 #define FINALLY_EXPR_BLOCK(NODE) TREE_OPERAND ((NODE), 1)
829
830 /* Using a CATCH_EXPR node */
831 #define CATCH_EXPR_GET_EXPR(NODE, V) (V ? LABELED_BLOCK_BODY (NODE) : (NODE))
832
833 /* Non zero if TYPE is an unchecked exception */
834 #define IS_UNCHECKED_EXCEPTION_P(TYPE)                          \
835   (inherits_from_p ((TYPE), runtime_exception_type_node)        \
836    || inherits_from_p ((TYPE), error_exception_type_node))
837
838 /* Make the current function where this macro is invoked report error
839    messages and and return, if any */
840 #define java_parse_abort_on_error()                                     \
841   {                                                                     \
842      extern int java_error_count;                                       \
843      if (java_error_count)                                              \
844        return;                                                          \
845    }
846
847 #define LAYOUT_SEEN_CLASS_METHODS()                                         \
848   {                                                                         \
849     tree current;                                                           \
850     for (current = all_class_list; current; current = TREE_CHAIN (current)) \
851       layout_class_methods (TREE_TYPE (TREE_VALUE (current)));              \
852   }