]>
Commit | Line | Data |
---|---|---|
377029eb | 1 | /* Process declarations and variables for the GNU compiler for the |
2 | Java(TM) language. | |
d353bf18 | 3 | Copyright (C) 1996-2015 Free Software Foundation, Inc. |
377029eb | 4 | |
7d82ed5e | 5 | This file is part of GCC. |
377029eb | 6 | |
7d82ed5e | 7 | GCC is free software; you can redistribute it and/or modify |
377029eb | 8 | it under the terms of the GNU General Public License as published by |
e4b52719 | 9 | the Free Software Foundation; either version 3, or (at your option) |
377029eb | 10 | any later version. |
11 | ||
7d82ed5e | 12 | GCC is distributed in the hope that it will be useful, |
377029eb | 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 | |
e4b52719 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. | |
377029eb | 20 | |
21 | Java and all Java-based marks are trademarks or registered trademarks | |
22 | of Sun Microsystems, Inc. in the United States and other countries. | |
23 | The Free Software Foundation is independent of Sun Microsystems, Inc. */ | |
24 | ||
25 | /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */ | |
26 | ||
27 | #include "config.h" | |
014e6e0c | 28 | #include "system.h" |
805e22b2 | 29 | #include "coretypes.h" |
b20a8bb4 | 30 | #include "alias.h" |
377029eb | 31 | #include "tree.h" |
9ef16211 | 32 | #include "options.h" |
9ed99284 | 33 | #include "stor-layout.h" |
34 | #include "stringpool.h" | |
35 | #include "varasm.h" | |
0b205f4c | 36 | #include "diagnostic-core.h" |
c1b6623d | 37 | #include "toplev.h" |
38 | #include "flags.h" | |
377029eb | 39 | #include "java-tree.h" |
40 | #include "jcf.h" | |
c1b6623d | 41 | #include "java-except.h" |
1140c305 | 42 | #include "tm.h" |
43 | #include "hard-reg-set.h" | |
1140c305 | 44 | #include "function.h" |
4ee9c684 | 45 | #include "cgraph.h" |
53d20e65 | 46 | #include "tree-inline.h" |
82ac3699 | 47 | #include "target.h" |
420091c2 | 48 | #include "version.h" |
93777d07 | 49 | #include "tree-iterator.h" |
54be5d7e | 50 | #include "langhooks.h" |
c1b6623d | 51 | |
52 | #if defined (DEBUG_JAVA_BINDING_LEVELS) | |
6852521a | 53 | extern void indent (void); |
c1b6623d | 54 | #endif |
377029eb | 55 | |
6852521a | 56 | static tree push_jvm_slot (int, tree); |
57 | static tree lookup_name_current_level (tree); | |
58 | static tree push_promoted_type (const char *, tree); | |
59 | static struct binding_level *make_binding_level (void); | |
60 | static tree create_primitive_vtable (const char *); | |
6852521a | 61 | static tree check_local_unnamed_variable (tree, tree, tree); |
420091c2 | 62 | static void parse_version (void); |
63 | ||
420091c2 | 64 | |
dba0f8ce | 65 | /* The following ABI flags are used in the high-order bits of the version |
66 | ID field. The version ID number itself should never be larger than | |
67 | 0xfffff, so it should be safe to use top 12 bits for these flags. */ | |
fffadcfa | 68 | |
dba0f8ce | 69 | #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */ |
70 | ||
71 | #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that | |
72 | should be loaded by the bootstrap | |
73 | loader. */ | |
74 | ||
75 | /* If an ABI change is made within a GCC release series, rendering current | |
65bf3316 | 76 | binaries incompatible with the old runtimes, this number must be set to |
dba0f8ce | 77 | enforce the compatibility rules. */ |
65bf3316 | 78 | #define MINOR_BINARYCOMPAT_ABI_VERSION 1 |
dba0f8ce | 79 | |
80 | /* The runtime may recognize a variety of BC ABIs (objects generated by | |
81 | different version of gcj), but will probably always require strict | |
82 | matching for the ordinary (C++) ABI. */ | |
83 | ||
84 | /* The version ID of the BC ABI that we generate. This must be kept in | |
85 | sync with parse_version(), libgcj, and reality (if the BC format changes, | |
86 | this must change). */ | |
22d320f5 | 87 | #define GCJ_CURRENT_BC_ABI_VERSION \ |
dba0f8ce | 88 | (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION) |
22d320f5 | 89 | |
420091c2 | 90 | /* The ABI version number. */ |
91 | tree gcj_abi_version; | |
003019ba | 92 | |
ecb1637c | 93 | /* Name of the Cloneable class. */ |
94 | tree java_lang_cloneable_identifier_node; | |
95 | ||
96 | /* Name of the Serializable class. */ | |
97 | tree java_io_serializable_identifier_node; | |
98 | ||
377029eb | 99 | /* The DECL_MAP is a mapping from (index, type) to a decl node. |
100 | If index < max_locals, it is the index of a local variable. | |
101 | if index >= max_locals, then index-max_locals is a stack slot. | |
102 | The DECL_MAP mapping is represented as a TREE_VEC whose elements | |
103 | are a list of decls (VAR_DECL or PARM_DECL) chained by | |
104 | DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then | |
105 | we search the chain for a decl with a matching TREE_TYPE. */ | |
106 | ||
1f3233d1 | 107 | static GTY(()) tree decl_map; |
377029eb | 108 | |
469e4af3 | 109 | /* The base_decl_map is contains one variable of ptr_type: this is |
110 | used to contain every variable of reference type that is ever | |
111 | stored in a local variable slot. */ | |
112 | ||
113 | static GTY(()) tree base_decl_map; | |
114 | ||
115 | /* An index used to make temporary identifiers unique. */ | |
116 | static int uniq; | |
117 | ||
377029eb | 118 | /* A list of local variables VAR_DECLs for this method that we have seen |
119 | debug information, but we have not reached their starting (byte) PC yet. */ | |
120 | ||
1f3233d1 | 121 | static GTY(()) tree pending_local_decls; |
377029eb | 122 | |
f53ce661 | 123 | /* The decl for "_Jv_ResolvePoolEntry". */ |
124 | tree soft_resolvepoolentry_node; | |
125 | ||
2934c6b5 | 126 | /* The decl for the .constants field of an instance of Class. */ |
127 | tree constants_field_decl_node; | |
128 | ||
129 | /* The decl for the .data field of an instance of Class. */ | |
130 | tree constants_data_field_decl_node; | |
131 | ||
c1b6623d | 132 | #if defined(DEBUG_JAVA_BINDING_LEVELS) |
133 | int binding_depth = 0; | |
134 | int is_class_level = 0; | |
135 | int current_pc; | |
136 | ||
137 | void | |
2883a3ed | 138 | indent (void) |
c1b6623d | 139 | { |
4ee9c684 | 140 | int i; |
c1b6623d | 141 | |
142 | for (i = 0; i < binding_depth*2; i++) | |
143 | putc (' ', stderr); | |
144 | } | |
145 | #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */ | |
146 | ||
469e4af3 | 147 | /* True if decl is a named local variable, i.e. if it is an alias |
148 | that's used only for debugging purposes. */ | |
149 | ||
150 | static bool | |
151 | debug_variable_p (tree decl) | |
152 | { | |
153 | if (TREE_CODE (decl) == PARM_DECL) | |
154 | return false; | |
155 | ||
156 | if (LOCAL_SLOT_P (decl)) | |
157 | return false; | |
158 | ||
159 | return true; | |
160 | } | |
161 | ||
003019ba | 162 | static tree |
2883a3ed | 163 | push_jvm_slot (int index, tree decl) |
377029eb | 164 | { |
377029eb | 165 | DECL_CONTEXT (decl) = current_function_decl; |
166 | layout_decl (decl, 0); | |
167 | ||
377029eb | 168 | /* Now link the decl into the decl_map. */ |
169 | if (DECL_LANG_SPECIFIC (decl) == NULL) | |
170 | { | |
146d1460 | 171 | MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl); |
377029eb | 172 | DECL_LOCAL_START_PC (decl) = 0; |
173 | DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl); | |
174 | DECL_LOCAL_SLOT_NUMBER (decl) = index; | |
175 | } | |
176 | DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index); | |
177 | TREE_VEC_ELT (decl_map, index) = decl; | |
4ee9c684 | 178 | |
377029eb | 179 | return decl; |
180 | } | |
181 | ||
f4386e82 | 182 | /* Find the best declaration based upon type. If 'decl' fits 'type' better |
183 | than 'best', return 'decl'. Otherwise return 'best'. */ | |
184 | ||
185 | static tree | |
2883a3ed | 186 | check_local_unnamed_variable (tree best, tree decl, tree type) |
f4386e82 | 187 | { |
469e4af3 | 188 | tree decl_type = TREE_TYPE (decl); |
189 | ||
bc031ffe | 190 | gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl)); |
469e4af3 | 191 | |
192 | /* Use the same decl for all integer types <= 32 bits. This is | |
193 | necessary because sometimes a value is stored as (for example) | |
194 | boolean but loaded as int. */ | |
195 | if (decl_type == type | |
196 | || (INTEGRAL_TYPE_P (decl_type) | |
197 | && INTEGRAL_TYPE_P (type) | |
198 | && TYPE_PRECISION (decl_type) <= 32 | |
a4ccc41f | 199 | && TYPE_PRECISION (type) <= 32 |
469e4af3 | 200 | && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type)) |
a4ccc41f | 201 | /* ptr_type_node is used for null pointers, which are |
202 | assignment compatible with everything. */ | |
203 | || (TREE_CODE (decl_type) == POINTER_TYPE | |
204 | && type == ptr_type_node) | |
205 | /* Whenever anyone wants to use a slot that is initially | |
206 | occupied by a PARM_DECL of pointer type they must get that | |
207 | decl, even if they asked for a pointer to a different type. | |
208 | However, if someone wants a scalar variable in a slot that | |
209 | initially held a pointer arg -- or vice versa -- we create a | |
210 | new VAR_DECL. | |
211 | ||
8e83ca69 | 212 | ???: As long as verification is correct, this will be a |
42bf5d89 | 213 | compatible type. But maybe we should create a dummy variable |
a4ccc41f | 214 | and replace all references to it with the DECL and a |
8e83ca69 | 215 | NOP_EXPR. |
a4ccc41f | 216 | */ |
217 | || (TREE_CODE (decl_type) == POINTER_TYPE | |
218 | && TREE_CODE (decl) == PARM_DECL | |
8e83ca69 | 219 | && TREE_CODE (type) == POINTER_TYPE)) |
a4ccc41f | 220 | { |
221 | if (best == NULL_TREE | |
469e4af3 | 222 | || (decl_type == type && TREE_TYPE (best) != type)) |
a4ccc41f | 223 | return decl; |
224 | } | |
f4386e82 | 225 | |
a4ccc41f | 226 | return best; |
f4386e82 | 227 | } |
228 | ||
229 | ||
377029eb | 230 | /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE, |
231 | that is valid at PC (or -1 if any pc). | |
22f87b66 | 232 | If there is no existing matching decl, allocate one. */ |
377029eb | 233 | |
234 | tree | |
469e4af3 | 235 | find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED) |
377029eb | 236 | { |
469e4af3 | 237 | tree tmp = TREE_VEC_ELT (decl_map, index); |
238 | tree decl = NULL_TREE; | |
22f87b66 | 239 | |
469e4af3 | 240 | /* Scan through every declaration that has been created in this |
241 | slot. We're only looking for variables that correspond to local | |
242 | index declarations and PARM_DECLs, not named variables: such | |
243 | local variables are used only for debugging information. */ | |
244 | while (tmp != NULL_TREE) | |
377029eb | 245 | { |
469e4af3 | 246 | if (! debug_variable_p (tmp)) |
247 | decl = check_local_unnamed_variable (decl, tmp, type); | |
248 | tmp = DECL_LOCAL_SLOT_CHAIN (tmp); | |
377029eb | 249 | } |
f4386e82 | 250 | |
8e83ca69 | 251 | /* gcj has a function called promote_type(), which is used by both |
252 | the bytecode compiler and the source compiler. Unfortunately, | |
253 | the type systems for the Java VM and the Java language are not | |
254 | the same: a boolean in the VM promotes to an int, not to a wide | |
255 | boolean. If our caller wants something to hold a boolean, that | |
256 | had better be an int, because that slot might be re-used | |
257 | later in integer context. */ | |
258 | if (TREE_CODE (type) == BOOLEAN_TYPE) | |
259 | type = integer_type_node; | |
260 | ||
4ee9c684 | 261 | /* If we don't find a match, create one with the type passed in. |
469e4af3 | 262 | The name of the variable is #n#m, which n is the variable index |
4ee9c684 | 263 | in the local variable area and m is a dummy identifier for |
264 | uniqueness -- multiple variables may share the same local | |
469e4af3 | 265 | variable index. We don't call pushdecl() to push pointer types |
266 | into a binding expr because they'll all be replaced by a single | |
267 | variable that is used for every reference in that local variable | |
268 | slot. */ | |
269 | if (! decl) | |
a4ccc41f | 270 | { |
271 | char buf[64]; | |
272 | tree name; | |
469e4af3 | 273 | sprintf (buf, "#slot#%d#%d", index, uniq++); |
274 | name = get_identifier (buf); | |
e60a6f7b | 275 | decl = build_decl (input_location, VAR_DECL, name, type); |
469e4af3 | 276 | DECL_IGNORED_P (decl) = 1; |
277 | DECL_ARTIFICIAL (decl) = 1; | |
278 | decl = push_jvm_slot (index, decl); | |
279 | LOCAL_SLOT_P (decl) = 1; | |
280 | ||
281 | if (TREE_CODE (type) != POINTER_TYPE) | |
282 | pushdecl_function_level (decl); | |
283 | } | |
4ee9c684 | 284 | |
469e4af3 | 285 | /* As well as creating a local variable that matches the type, we |
286 | also create a base variable (of ptr_type) that will hold all its | |
287 | aliases. */ | |
288 | if (TREE_CODE (type) == POINTER_TYPE | |
289 | && ! TREE_VEC_ELT (base_decl_map, index)) | |
290 | { | |
291 | char buf[64]; | |
292 | tree name; | |
293 | tree base_decl; | |
294 | sprintf (buf, "#ref#%d#%d", index, uniq++); | |
295 | name = get_identifier (buf); | |
296 | base_decl | |
297 | = TREE_VEC_ELT (base_decl_map, index) | |
e60a6f7b | 298 | = build_decl (input_location, VAR_DECL, name, ptr_type_node); |
469e4af3 | 299 | pushdecl_function_level (base_decl); |
300 | DECL_IGNORED_P (base_decl) = 1; | |
301 | DECL_ARTIFICIAL (base_decl) = 1; | |
302 | } | |
303 | ||
304 | return decl; | |
305 | } | |
306 | ||
bfec3452 | 307 | /* Called during genericization for every variable. If the variable |
469e4af3 | 308 | is a temporary of pointer type, replace it with a common variable |
309 | thath is used to hold all pointer types that are ever stored in | |
310 | that slot. Set WANT_LVALUE if you want a variable that is to be | |
311 | written to. */ | |
312 | ||
bfec3452 | 313 | static tree |
469e4af3 | 314 | java_replace_reference (tree var_decl, bool want_lvalue) |
315 | { | |
316 | tree decl_type; | |
317 | ||
318 | if (! base_decl_map) | |
319 | return var_decl; | |
320 | ||
321 | decl_type = TREE_TYPE (var_decl); | |
322 | ||
323 | if (TREE_CODE (decl_type) == POINTER_TYPE) | |
324 | { | |
325 | if (DECL_LANG_SPECIFIC (var_decl) | |
326 | && LOCAL_SLOT_P (var_decl)) | |
327 | { | |
328 | int index = DECL_LOCAL_SLOT_NUMBER (var_decl); | |
329 | tree base_decl = TREE_VEC_ELT (base_decl_map, index); | |
330 | ||
bc031ffe | 331 | gcc_assert (base_decl); |
469e4af3 | 332 | if (! want_lvalue) |
333 | base_decl = build1 (NOP_EXPR, decl_type, base_decl); | |
334 | ||
335 | return base_decl; | |
336 | } | |
337 | } | |
338 | ||
339 | return var_decl; | |
377029eb | 340 | } |
341 | ||
bfec3452 | 342 | /* Helper for java_genericize. */ |
343 | ||
344 | tree | |
345 | java_replace_references (tree *tp, int *walk_subtrees, | |
346 | void *data ATTRIBUTE_UNUSED) | |
347 | { | |
348 | if (TREE_CODE (*tp) == MODIFY_EXPR) | |
349 | { | |
444e42cc | 350 | source_location loc = EXPR_LOCATION (*tp); |
bfec3452 | 351 | tree lhs = TREE_OPERAND (*tp, 0); |
352 | /* This is specific to the bytecode compiler. If a variable has | |
353 | LOCAL_SLOT_P set, replace an assignment to it with an assignment | |
354 | to the corresponding variable that holds all its aliases. */ | |
355 | if (TREE_CODE (lhs) == VAR_DECL | |
356 | && DECL_LANG_SPECIFIC (lhs) | |
357 | && LOCAL_SLOT_P (lhs) | |
358 | && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE) | |
359 | { | |
360 | tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true); | |
361 | tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs), | |
362 | TREE_OPERAND (*tp, 1)); | |
444e42cc | 363 | tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs), |
364 | new_lhs, new_rhs); | |
365 | *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem); | |
366 | SET_EXPR_LOCATION (tem, loc); | |
367 | SET_EXPR_LOCATION (new_rhs, loc); | |
368 | SET_EXPR_LOCATION (*tp, loc); | |
bfec3452 | 369 | } |
370 | } | |
371 | if (TREE_CODE (*tp) == VAR_DECL) | |
372 | { | |
373 | *tp = java_replace_reference (*tp, /* want_lvalue */ false); | |
374 | *walk_subtrees = 0; | |
375 | } | |
376 | ||
377 | return NULL_TREE; | |
378 | } | |
377029eb | 379 | |
380 | /* Same as find_local_index, except that INDEX is a stack index. */ | |
381 | ||
382 | tree | |
2883a3ed | 383 | find_stack_slot (int index, tree type) |
377029eb | 384 | { |
385 | return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl), | |
386 | type, -1); | |
387 | } | |
388 | ||
fb1e4f4a | 389 | struct GTY(()) |
390 | binding_level { | |
377029eb | 391 | /* A chain of _DECL nodes for all variables, constants, functions, |
392 | * and typedef types. These are in the reverse of the order supplied. | |
393 | */ | |
394 | tree names; | |
395 | ||
396 | /* For each level, a list of shadowed outer-level local definitions | |
397 | to be restored when this level is popped. | |
398 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
399 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
400 | tree shadowed; | |
401 | ||
402 | /* For each level (except not the global one), | |
403 | a chain of BLOCK nodes for all the levels | |
404 | that were entered and exited one level down. */ | |
405 | tree blocks; | |
406 | ||
377029eb | 407 | /* The binding level which this one is contained in (inherits from). */ |
408 | struct binding_level *level_chain; | |
409 | ||
377029eb | 410 | /* The bytecode PC that marks the end of this level. */ |
411 | int end_pc; | |
ad9a56c8 | 412 | /* The bytecode PC that marks the start of this level. */ |
c1b6623d | 413 | int start_pc; |
414 | ||
4ee9c684 | 415 | /* The statements in this binding level. */ |
416 | tree stmts; | |
417 | ||
310b3906 | 418 | /* An exception range associated with this binding level. */ |
419 | struct eh_range * GTY((skip (""))) exception_range; | |
420 | ||
d9e96462 | 421 | /* Binding depth at which this level began. Used only for debugging. */ |
c1b6623d | 422 | unsigned binding_depth; |
444e42cc | 423 | |
424 | /* The location at which this level began. */ | |
425 | source_location loc; | |
377029eb | 426 | }; |
427 | ||
428 | #define NULL_BINDING_LEVEL (struct binding_level *) NULL | |
429 | ||
430 | /* The binding level currently in effect. */ | |
431 | ||
d9e96462 | 432 | static GTY(()) struct binding_level *current_binding_level; |
377029eb | 433 | |
434 | /* A chain of binding_level structures awaiting reuse. */ | |
435 | ||
d9e96462 | 436 | static GTY(()) struct binding_level *free_binding_level; |
377029eb | 437 | |
438 | /* The outermost binding level, for names of file scope. | |
439 | This is created when the compiler is started and exists | |
440 | through the entire run. */ | |
441 | ||
d9e96462 | 442 | static GTY(()) struct binding_level *global_binding_level; |
377029eb | 443 | |
469e4af3 | 444 | /* The binding level that holds variables declared at the outermost |
445 | level within a function body. */ | |
446 | ||
447 | static struct binding_level *function_binding_level; | |
448 | ||
c1b6623d | 449 | /* A PC value bigger than any PC value we may ever may encounter. */ |
450 | ||
451 | #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1) | |
452 | ||
377029eb | 453 | /* Binding level structures are initialized by copying this one. */ |
454 | ||
b14b6cce | 455 | static const struct binding_level clear_binding_level |
310b3906 | 456 | = { |
457 | NULL_TREE, /* names */ | |
458 | NULL_TREE, /* shadowed */ | |
459 | NULL_TREE, /* blocks */ | |
310b3906 | 460 | NULL_BINDING_LEVEL, /* level_chain */ |
461 | LARGEST_PC, /* end_pc */ | |
462 | 0, /* start_pc */ | |
463 | NULL, /* stmts */ | |
464 | NULL, /* exception_range */ | |
465 | 0, /* binding_depth */ | |
444e42cc | 466 | 0, /* loc */ |
310b3906 | 467 | }; |
377029eb | 468 | |
48c9f822 | 469 | tree java_global_trees[JTI_MAX]; |
444e42cc | 470 | |
377029eb | 471 | /* Build (and pushdecl) a "promoted type" for all standard |
472 | types shorter than int. */ | |
473 | ||
474 | static tree | |
2883a3ed | 475 | push_promoted_type (const char *name, tree actual_type) |
377029eb | 476 | { |
477 | tree type = make_node (TREE_CODE (actual_type)); | |
478 | #if 1 | |
479 | tree in_min = TYPE_MIN_VALUE (int_type_node); | |
480 | tree in_max = TYPE_MAX_VALUE (int_type_node); | |
481 | #else | |
482 | tree in_min = TYPE_MIN_VALUE (actual_type); | |
483 | tree in_max = TYPE_MAX_VALUE (actual_type); | |
484 | #endif | |
5d844ba2 | 485 | TYPE_MIN_VALUE (type) = copy_node (in_min); |
377029eb | 486 | TREE_TYPE (TYPE_MIN_VALUE (type)) = type; |
5d844ba2 | 487 | TYPE_MAX_VALUE (type) = copy_node (in_max); |
377029eb | 488 | TREE_TYPE (TYPE_MAX_VALUE (type)) = type; |
489 | TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node); | |
ea347d91 | 490 | TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type); |
377029eb | 491 | layout_type (type); |
e60a6f7b | 492 | pushdecl (build_decl (input_location, |
493 | TYPE_DECL, get_identifier (name), type)); | |
377029eb | 494 | return type; |
495 | } | |
496 | ||
79cbb875 | 497 | /* Return tree that represents a vtable for a primitive array. */ |
498 | static tree | |
2883a3ed | 499 | create_primitive_vtable (const char *name) |
79cbb875 | 500 | { |
501 | tree r; | |
502 | char buf[50]; | |
503 | ||
504 | sprintf (buf, "_Jv_%sVTable", name); | |
e60a6f7b | 505 | r = build_decl (input_location, |
506 | VAR_DECL, get_identifier (buf), ptr_type_node); | |
79cbb875 | 507 | DECL_EXTERNAL (r) = 1; |
79cbb875 | 508 | return r; |
509 | } | |
510 | ||
420091c2 | 511 | /* Parse the version string and compute the ABI version number. */ |
512 | static void | |
513 | parse_version (void) | |
514 | { | |
515 | const char *p = version_string; | |
516 | unsigned int major = 0, minor = 0; | |
517 | unsigned int abi_version; | |
518 | ||
519 | /* Skip leading junk. */ | |
520 | while (*p && !ISDIGIT (*p)) | |
521 | ++p; | |
522 | gcc_assert (*p); | |
523 | ||
524 | /* Extract major version. */ | |
525 | while (ISDIGIT (*p)) | |
526 | { | |
527 | major = major * 10 + *p - '0'; | |
528 | ++p; | |
529 | } | |
530 | ||
531 | gcc_assert (*p == '.' && ISDIGIT (p[1])); | |
532 | ++p; | |
533 | ||
534 | /* Extract minor version. */ | |
535 | while (ISDIGIT (*p)) | |
536 | { | |
537 | minor = minor * 10 + *p - '0'; | |
538 | ++p; | |
539 | } | |
540 | ||
420091c2 | 541 | if (flag_indirect_dispatch) |
dba0f8ce | 542 | { |
543 | abi_version = GCJ_CURRENT_BC_ABI_VERSION; | |
544 | abi_version |= FLAG_BINARYCOMPAT_ABI; | |
545 | } | |
546 | else /* C++ ABI */ | |
547 | { | |
548 | /* Implicit in this computation is the idea that we won't break the | |
549 | old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to | |
550 | 4.0.1). */ | |
551 | abi_version = 100000 * major + 1000 * minor; | |
552 | } | |
fffadcfa | 553 | if (flag_bootstrap_classes) |
dba0f8ce | 554 | abi_version |= FLAG_BOOTSTRAP_LOADER; |
420091c2 | 555 | |
556 | gcj_abi_version = build_int_cstu (ptr_type_node, abi_version); | |
557 | } | |
757f6c6c | 558 | |
377029eb | 559 | void |
2883a3ed | 560 | java_init_decl_processing (void) |
377029eb | 561 | { |
a1b71f21 | 562 | tree field = NULL_TREE; |
377029eb | 563 | tree t; |
564 | ||
44710af9 | 565 | init_class_processing (); |
566 | ||
377029eb | 567 | current_function_decl = NULL; |
568 | current_binding_level = NULL_BINDING_LEVEL; | |
569 | free_binding_level = NULL_BINDING_LEVEL; | |
570 | pushlevel (0); /* make the binding_level structure for global names */ | |
571 | global_binding_level = current_binding_level; | |
572 | ||
35c2230f | 573 | /* Build common tree nodes, Java has an unsigned char. */ |
c38a75b7 | 574 | build_common_tree_nodes (false, false); |
35c2230f | 575 | |
576 | /* ??? Now we continue and override some of the built types again | |
577 | with Java specific types. As the above generated types are | |
578 | supposed to match the targets C ABI this isn't really the way | |
579 | to go and any Java specifics should _not_ use those global types | |
580 | if the Java ABI does not match the C one. */ | |
377029eb | 581 | |
582 | byte_type_node = make_signed_type (8); | |
e60a6f7b | 583 | pushdecl (build_decl (BUILTINS_LOCATION, |
584 | TYPE_DECL, get_identifier ("byte"), byte_type_node)); | |
377029eb | 585 | short_type_node = make_signed_type (16); |
e60a6f7b | 586 | pushdecl (build_decl (BUILTINS_LOCATION, |
587 | TYPE_DECL, get_identifier ("short"), short_type_node)); | |
377029eb | 588 | int_type_node = make_signed_type (32); |
e60a6f7b | 589 | pushdecl (build_decl (BUILTINS_LOCATION, |
590 | TYPE_DECL, get_identifier ("int"), int_type_node)); | |
377029eb | 591 | long_type_node = make_signed_type (64); |
e60a6f7b | 592 | pushdecl (build_decl (BUILTINS_LOCATION, |
593 | TYPE_DECL, get_identifier ("long"), long_type_node)); | |
377029eb | 594 | |
595 | unsigned_byte_type_node = make_unsigned_type (8); | |
e60a6f7b | 596 | pushdecl (build_decl (BUILTINS_LOCATION, |
597 | TYPE_DECL, get_identifier ("unsigned byte"), | |
377029eb | 598 | unsigned_byte_type_node)); |
599 | unsigned_short_type_node = make_unsigned_type (16); | |
e60a6f7b | 600 | pushdecl (build_decl (BUILTINS_LOCATION, |
601 | TYPE_DECL, get_identifier ("unsigned short"), | |
377029eb | 602 | unsigned_short_type_node)); |
603 | unsigned_int_type_node = make_unsigned_type (32); | |
e60a6f7b | 604 | pushdecl (build_decl (BUILTINS_LOCATION, |
605 | TYPE_DECL, get_identifier ("unsigned int"), | |
377029eb | 606 | unsigned_int_type_node)); |
607 | unsigned_long_type_node = make_unsigned_type (64); | |
e60a6f7b | 608 | pushdecl (build_decl (BUILTINS_LOCATION, |
609 | TYPE_DECL, get_identifier ("unsigned long"), | |
377029eb | 610 | unsigned_long_type_node)); |
611 | ||
eff5f036 | 612 | /* Define these next since types below may used them. */ |
771d21fa | 613 | integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0); |
7016c612 | 614 | integer_zero_node = build_int_cst (NULL_TREE, 0); |
615 | integer_one_node = build_int_cst (NULL_TREE, 1); | |
616 | integer_two_node = build_int_cst (NULL_TREE, 2); | |
07e17c57 | 617 | integer_three_node = build_int_cst (NULL_TREE, 3); |
7016c612 | 618 | integer_four_node = build_int_cst (NULL_TREE, 4); |
619 | integer_minus_one_node = build_int_cst (NULL_TREE, -1); | |
377029eb | 620 | |
0bfb37bc | 621 | /* A few values used for range checking in the lexer. */ |
7016c612 | 622 | decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000); |
0f363ae8 | 623 | decimal_long_max |
624 | = double_int_to_tree (unsigned_long_type_node, | |
d67b7119 | 625 | double_int_zero.set_bit (64)); |
0bfb37bc | 626 | |
7016c612 | 627 | long_zero_node = build_int_cst (long_type_node, 0); |
95651291 | 628 | |
e60a6f7b | 629 | pushdecl (build_decl (BUILTINS_LOCATION, |
630 | TYPE_DECL, get_identifier ("void"), void_type_node)); | |
9cfddb70 | 631 | |
377029eb | 632 | t = make_node (VOID_TYPE); |
633 | layout_type (t); /* Uses size_zero_node */ | |
634 | return_address_type_node = build_pointer_type (t); | |
635 | ||
35c2230f | 636 | char_type_node = make_unsigned_type (16); |
ea347d91 | 637 | TYPE_STRING_FLAG (char_type_node) = 1; |
e60a6f7b | 638 | pushdecl (build_decl (BUILTINS_LOCATION, |
639 | TYPE_DECL, get_identifier ("char"), char_type_node)); | |
377029eb | 640 | |
35c2230f | 641 | boolean_type_node = make_unsigned_type (1); |
642 | TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); | |
e60a6f7b | 643 | pushdecl (build_decl (BUILTINS_LOCATION, |
644 | TYPE_DECL, get_identifier ("boolean"), | |
377029eb | 645 | boolean_type_node)); |
646 | boolean_false_node = TYPE_MIN_VALUE (boolean_type_node); | |
647 | boolean_true_node = TYPE_MAX_VALUE (boolean_type_node); | |
648 | ||
649 | promoted_byte_type_node | |
650 | = push_promoted_type ("promoted_byte", byte_type_node); | |
651 | promoted_short_type_node | |
652 | = push_promoted_type ("promoted_short", short_type_node); | |
653 | promoted_char_type_node | |
654 | = push_promoted_type ("promoted_char", char_type_node); | |
655 | promoted_boolean_type_node | |
656 | = push_promoted_type ("promoted_boolean", boolean_type_node); | |
657 | ||
658 | float_type_node = make_node (REAL_TYPE); | |
659 | TYPE_PRECISION (float_type_node) = 32; | |
e60a6f7b | 660 | pushdecl (build_decl (BUILTINS_LOCATION, |
661 | TYPE_DECL, get_identifier ("float"), | |
377029eb | 662 | float_type_node)); |
663 | layout_type (float_type_node); | |
664 | ||
665 | double_type_node = make_node (REAL_TYPE); | |
666 | TYPE_PRECISION (double_type_node) = 64; | |
e60a6f7b | 667 | pushdecl (build_decl (BUILTINS_LOCATION, |
668 | TYPE_DECL, get_identifier ("double"), | |
377029eb | 669 | double_type_node)); |
670 | layout_type (double_type_node); | |
671 | ||
95651291 | 672 | float_zero_node = build_real (float_type_node, dconst0); |
673 | double_zero_node = build_real (double_type_node, dconst0); | |
674 | ||
79cbb875 | 675 | /* These are the vtables for arrays of primitives. */ |
676 | boolean_array_vtable = create_primitive_vtable ("boolean"); | |
677 | byte_array_vtable = create_primitive_vtable ("byte"); | |
678 | char_array_vtable = create_primitive_vtable ("char"); | |
679 | short_array_vtable = create_primitive_vtable ("short"); | |
680 | int_array_vtable = create_primitive_vtable ("int"); | |
681 | long_array_vtable = create_primitive_vtable ("long"); | |
682 | float_array_vtable = create_primitive_vtable ("float"); | |
683 | double_array_vtable = create_primitive_vtable ("double"); | |
684 | ||
757f6c6c | 685 | one_elt_array_domain_type = build_index_type (integer_one_node); |
686 | utf8const_type = make_node (RECORD_TYPE); | |
e60a6f7b | 687 | PUSH_FIELD (input_location, |
688 | utf8const_type, field, "hash", unsigned_short_type_node); | |
689 | PUSH_FIELD (input_location, | |
690 | utf8const_type, field, "length", unsigned_short_type_node); | |
757f6c6c | 691 | FINISH_RECORD (utf8const_type); |
692 | utf8const_ptr_type = build_pointer_type (utf8const_type); | |
693 | ||
694 | atable_type = build_array_type (ptr_type_node, | |
695 | one_elt_array_domain_type); | |
696 | TYPE_NONALIASED_COMPONENT (atable_type) = 1; | |
697 | atable_ptr_type = build_pointer_type (atable_type); | |
698 | ||
a4ccc41f | 699 | itable_type = build_array_type (ptr_type_node, |
700 | one_elt_array_domain_type); | |
701 | TYPE_NONALIASED_COMPONENT (itable_type) = 1; | |
702 | itable_ptr_type = build_pointer_type (itable_type); | |
703 | ||
757f6c6c | 704 | symbol_type = make_node (RECORD_TYPE); |
e60a6f7b | 705 | PUSH_FIELD (input_location, |
706 | symbol_type, field, "clname", utf8const_ptr_type); | |
707 | PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type); | |
708 | PUSH_FIELD (input_location, | |
709 | symbol_type, field, "signature", utf8const_ptr_type); | |
757f6c6c | 710 | FINISH_RECORD (symbol_type); |
711 | ||
712 | symbols_array_type = build_array_type (symbol_type, | |
713 | one_elt_array_domain_type); | |
714 | symbols_array_ptr_type = build_pointer_type (symbols_array_type); | |
715 | ||
a4ccc41f | 716 | assertion_entry_type = make_node (RECORD_TYPE); |
e60a6f7b | 717 | PUSH_FIELD (input_location, |
718 | assertion_entry_type, field, "assertion_code", integer_type_node); | |
719 | PUSH_FIELD (input_location, | |
720 | assertion_entry_type, field, "op1", utf8const_ptr_type); | |
721 | PUSH_FIELD (input_location, | |
722 | assertion_entry_type, field, "op2", utf8const_ptr_type); | |
a4ccc41f | 723 | FINISH_RECORD (assertion_entry_type); |
724 | ||
725 | assertion_table_type = build_array_type (assertion_entry_type, | |
726 | one_elt_array_domain_type); | |
727 | ||
79cbb875 | 728 | /* As you're adding items here, please update the code right after |
53bd31b5 | 729 | this section, so that the filename containing the source code of |
730 | the pre-defined class gets registered correctly. */ | |
6b0c8920 | 731 | unqualified_object_id_node = get_identifier ("Object"); |
377029eb | 732 | object_type_node = lookup_class (get_identifier ("java.lang.Object")); |
733 | object_ptr_type_node = promote_type (object_type_node); | |
734 | string_type_node = lookup_class (get_identifier ("java.lang.String")); | |
dd82eabd | 735 | string_ptr_type_node = promote_type (string_type_node); |
377029eb | 736 | class_type_node = lookup_class (get_identifier ("java.lang.Class")); |
737 | throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable")); | |
6eb95932 | 738 | exception_type_node = lookup_class (get_identifier ("java.lang.Exception")); |
f757ce2b | 739 | runtime_exception_type_node = |
740 | lookup_class (get_identifier ("java.lang.RuntimeException")); | |
741 | error_exception_type_node = | |
742 | lookup_class (get_identifier ("java.lang.Error")); | |
6eb95932 | 743 | |
9d45d2f2 | 744 | rawdata_ptr_type_node |
745 | = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData"))); | |
377029eb | 746 | |
fcffb974 | 747 | add_predefined_file (get_identifier ("java/lang/Class.java")); |
748 | add_predefined_file (get_identifier ("java/lang/Error.java")); | |
749 | add_predefined_file (get_identifier ("java/lang/Object.java")); | |
750 | add_predefined_file (get_identifier ("java/lang/RuntimeException.java")); | |
751 | add_predefined_file (get_identifier ("java/lang/String.java")); | |
752 | add_predefined_file (get_identifier ("java/lang/Throwable.java")); | |
753 | add_predefined_file (get_identifier ("gnu/gcj/RawData.java")); | |
754 | add_predefined_file (get_identifier ("java/lang/Exception.java")); | |
755 | add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java")); | |
756 | add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java")); | |
53bd31b5 | 757 | |
377029eb | 758 | methodtable_type = make_node (RECORD_TYPE); |
759 | layout_type (methodtable_type); | |
e60a6f7b | 760 | build_decl (BUILTINS_LOCATION, |
761 | TYPE_DECL, get_identifier ("methodtable"), methodtable_type); | |
377029eb | 762 | methodtable_ptr_type = build_pointer_type (methodtable_type); |
763 | ||
764 | TYPE_identifier_node = get_identifier ("TYPE"); | |
765 | init_identifier_node = get_identifier ("<init>"); | |
766 | clinit_identifier_node = get_identifier ("<clinit>"); | |
377029eb | 767 | void_signature_node = get_identifier ("()V"); |
a8f5ddb8 | 768 | finalize_identifier_node = get_identifier ("finalize"); |
377029eb | 769 | this_identifier_node = get_identifier ("this"); |
377029eb | 770 | |
ecb1637c | 771 | java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable"); |
772 | java_io_serializable_identifier_node = | |
773 | get_identifier ("java.io.Serializable"); | |
774 | ||
377029eb | 775 | /* for lack of a better place to put this stub call */ |
776 | init_expr_processing(); | |
777 | ||
377029eb | 778 | constants_type_node = make_node (RECORD_TYPE); |
e60a6f7b | 779 | PUSH_FIELD (input_location, |
780 | constants_type_node, field, "size", unsigned_int_type_node); | |
781 | PUSH_FIELD (input_location, | |
782 | constants_type_node, field, "tags", ptr_type_node); | |
783 | PUSH_FIELD (input_location, | |
784 | constants_type_node, field, "data", ptr_type_node); | |
2934c6b5 | 785 | constants_data_field_decl_node = field; |
377029eb | 786 | FINISH_RECORD (constants_type_node); |
e60a6f7b | 787 | build_decl (BUILTINS_LOCATION, |
788 | TYPE_DECL, get_identifier ("constants"), constants_type_node); | |
377029eb | 789 | |
790 | access_flags_type_node = unsigned_short_type_node; | |
791 | ||
792 | dtable_type = make_node (RECORD_TYPE); | |
793 | dtable_ptr_type = build_pointer_type (dtable_type); | |
794 | ||
8f60923d | 795 | otable_type = build_array_type (integer_type_node, |
796 | one_elt_array_domain_type); | |
cb0593ad | 797 | TYPE_NONALIASED_COMPONENT (otable_type) = 1; |
bee0e6ed | 798 | otable_ptr_type = build_pointer_type (otable_type); |
e164eae7 | 799 | |
e60a6f7b | 800 | PUSH_FIELD (input_location, |
801 | object_type_node, field, "vtable", dtable_ptr_type); | |
eab4ad60 | 802 | DECL_FCONTEXT (field) = object_type_node; |
803 | TYPE_VFIELD (object_type_node) = field; | |
804 | ||
61cac2b4 | 805 | /* This isn't exactly true, but it is what we have in the source. |
806 | There is an unresolved issue here, which is whether the vtable | |
807 | should be marked by the GC. */ | |
af5b2568 | 808 | if (! flag_hash_synchronization) |
e60a6f7b | 809 | PUSH_FIELD (input_location, object_type_node, field, "sync_info", |
af5b2568 | 810 | build_pointer_type (object_type_node)); |
1767a056 | 811 | for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t)) |
377029eb | 812 | FIELD_PRIVATE (t) = 1; |
813 | FINISH_RECORD (object_type_node); | |
814 | ||
377029eb | 815 | field_type_node = make_node (RECORD_TYPE); |
816 | field_ptr_type_node = build_pointer_type (field_type_node); | |
817 | method_type_node = make_node (RECORD_TYPE); | |
818 | method_ptr_type_node = build_pointer_type (method_type_node); | |
819 | ||
820 | set_super_info (0, class_type_node, object_type_node, 0); | |
821 | set_super_info (0, string_type_node, object_type_node, 0); | |
822 | class_ptr_type = build_pointer_type (class_type_node); | |
823 | ||
e60a6f7b | 824 | PUSH_FIELD (input_location, |
825 | class_type_node, field, "next_or_version", class_ptr_type); | |
826 | PUSH_FIELD (input_location, | |
827 | class_type_node, field, "name", utf8const_ptr_type); | |
828 | PUSH_FIELD (input_location, | |
829 | class_type_node, field, "accflags", access_flags_type_node); | |
830 | PUSH_FIELD (input_location, | |
831 | class_type_node, field, "superclass", class_ptr_type); | |
832 | PUSH_FIELD (input_location, | |
833 | class_type_node, field, "constants", constants_type_node); | |
2934c6b5 | 834 | constants_field_decl_node = field; |
e60a6f7b | 835 | PUSH_FIELD (input_location, |
836 | class_type_node, field, "methods", method_ptr_type_node); | |
837 | PUSH_FIELD (input_location, | |
838 | class_type_node, field, "method_count", short_type_node); | |
839 | PUSH_FIELD (input_location, | |
840 | class_type_node, field, "vtable_method_count", short_type_node); | |
841 | PUSH_FIELD (input_location, | |
842 | class_type_node, field, "fields", field_ptr_type_node); | |
843 | PUSH_FIELD (input_location, | |
844 | class_type_node, field, "size_in_bytes", int_type_node); | |
845 | PUSH_FIELD (input_location, | |
846 | class_type_node, field, "field_count", short_type_node); | |
847 | PUSH_FIELD (input_location, | |
848 | class_type_node, field, "static_field_count", short_type_node); | |
849 | PUSH_FIELD (input_location, | |
850 | class_type_node, field, "vtable", dtable_ptr_type); | |
851 | PUSH_FIELD (input_location, | |
852 | class_type_node, field, "otable", otable_ptr_type); | |
853 | PUSH_FIELD (input_location, | |
854 | class_type_node, field, "otable_syms", | |
891214a7 | 855 | symbols_array_ptr_type); |
e60a6f7b | 856 | PUSH_FIELD (input_location, |
857 | class_type_node, field, "atable", atable_ptr_type); | |
858 | PUSH_FIELD (input_location, | |
859 | class_type_node, field, "atable_syms", | |
891214a7 | 860 | symbols_array_ptr_type); |
e60a6f7b | 861 | PUSH_FIELD (input_location, |
862 | class_type_node, field, "itable", itable_ptr_type); | |
863 | PUSH_FIELD (input_location, class_type_node, field, "itable_syms", | |
a4ccc41f | 864 | symbols_array_ptr_type); |
e60a6f7b | 865 | PUSH_FIELD (input_location, |
866 | class_type_node, field, "catch_classes", ptr_type_node); | |
867 | PUSH_FIELD (input_location, class_type_node, field, "interfaces", | |
377029eb | 868 | build_pointer_type (class_ptr_type)); |
e60a6f7b | 869 | PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node); |
870 | PUSH_FIELD (input_location, | |
871 | class_type_node, field, "interface_count", short_type_node); | |
872 | PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node); | |
873 | PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node); | |
874 | PUSH_FIELD (input_location, | |
875 | class_type_node, field, "depth", short_type_node); | |
876 | PUSH_FIELD (input_location, | |
877 | class_type_node, field, "ancestors", ptr_type_node); | |
878 | PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node); | |
879 | PUSH_FIELD (input_location, | |
880 | class_type_node, field, "arrayclass", ptr_type_node); | |
881 | PUSH_FIELD (input_location, | |
882 | class_type_node, field, "protectionDomain", ptr_type_node); | |
883 | PUSH_FIELD (input_location, | |
884 | class_type_node, field, "assertion_table", ptr_type_node); | |
885 | PUSH_FIELD (input_location, | |
886 | class_type_node, field, "hack_signers", ptr_type_node); | |
887 | PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node); | |
888 | PUSH_FIELD (input_location, | |
889 | class_type_node, field, "aux_info", ptr_type_node); | |
890 | PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node); | |
891 | PUSH_FIELD (input_location, | |
892 | class_type_node, field, "reflection_data", ptr_type_node); | |
1767a056 | 893 | for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t)) |
377029eb | 894 | FIELD_PRIVATE (t) = 1; |
895 | push_super_field (class_type_node, object_type_node); | |
bee0e6ed | 896 | |
377029eb | 897 | FINISH_RECORD (class_type_node); |
e60a6f7b | 898 | build_decl (BUILTINS_LOCATION, |
899 | TYPE_DECL, get_identifier ("Class"), class_type_node); | |
377029eb | 900 | |
901 | field_info_union_node = make_node (UNION_TYPE); | |
e60a6f7b | 902 | PUSH_FIELD (input_location, |
903 | field_info_union_node, field, "boffset", int_type_node); | |
904 | PUSH_FIELD (input_location, | |
905 | field_info_union_node, field, "addr", ptr_type_node); | |
377029eb | 906 | layout_type (field_info_union_node); |
907 | ||
e60a6f7b | 908 | PUSH_FIELD (input_location, |
909 | field_type_node, field, "name", utf8const_ptr_type); | |
910 | PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type); | |
911 | PUSH_FIELD (input_location, | |
912 | field_type_node, field, "accflags", access_flags_type_node); | |
913 | PUSH_FIELD (input_location, | |
914 | field_type_node, field, "bsize", unsigned_short_type_node); | |
915 | PUSH_FIELD (input_location, | |
916 | field_type_node, field, "info", field_info_union_node); | |
377029eb | 917 | FINISH_RECORD (field_type_node); |
e60a6f7b | 918 | build_decl (BUILTINS_LOCATION, |
919 | TYPE_DECL, get_identifier ("Field"), field_type_node); | |
377029eb | 920 | |
377029eb | 921 | nativecode_ptr_array_type_node |
922 | = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type); | |
923 | ||
e60a6f7b | 924 | PUSH_FIELD (input_location, |
925 | dtable_type, field, "class", class_ptr_type); | |
926 | PUSH_FIELD (input_location, | |
927 | dtable_type, field, "methods", nativecode_ptr_array_type_node); | |
377029eb | 928 | FINISH_RECORD (dtable_type); |
e60a6f7b | 929 | build_decl (BUILTINS_LOCATION, |
930 | TYPE_DECL, get_identifier ("dispatchTable"), dtable_type); | |
377029eb | 931 | |
377029eb | 932 | jexception_type = make_node (RECORD_TYPE); |
e60a6f7b | 933 | PUSH_FIELD (input_location, |
934 | jexception_type, field, "start_pc", ptr_type_node); | |
935 | PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node); | |
936 | PUSH_FIELD (input_location, | |
937 | jexception_type, field, "handler_pc", ptr_type_node); | |
938 | PUSH_FIELD (input_location, | |
939 | jexception_type, field, "catch_type", class_ptr_type); | |
377029eb | 940 | FINISH_RECORD (jexception_type); |
e60a6f7b | 941 | build_decl (BUILTINS_LOCATION, |
942 | TYPE_DECL, get_identifier ("jexception"), field_type_node); | |
377029eb | 943 | jexception_ptr_type = build_pointer_type (jexception_type); |
944 | ||
945 | lineNumberEntry_type = make_node (RECORD_TYPE); | |
e60a6f7b | 946 | PUSH_FIELD (input_location, |
947 | lineNumberEntry_type, field, "line_nr", unsigned_short_type_node); | |
948 | PUSH_FIELD (input_location, | |
949 | lineNumberEntry_type, field, "start_pc", ptr_type_node); | |
377029eb | 950 | FINISH_RECORD (lineNumberEntry_type); |
951 | ||
952 | lineNumbers_type = make_node (RECORD_TYPE); | |
e60a6f7b | 953 | PUSH_FIELD (input_location, |
954 | lineNumbers_type, field, "length", unsigned_int_type_node); | |
377029eb | 955 | FINISH_RECORD (lineNumbers_type); |
956 | ||
e60a6f7b | 957 | PUSH_FIELD (input_location, |
958 | method_type_node, field, "name", utf8const_ptr_type); | |
959 | PUSH_FIELD (input_location, | |
960 | method_type_node, field, "signature", utf8const_ptr_type); | |
961 | PUSH_FIELD (input_location, | |
962 | method_type_node, field, "accflags", access_flags_type_node); | |
963 | PUSH_FIELD (input_location, | |
964 | method_type_node, field, "index", unsigned_short_type_node); | |
965 | PUSH_FIELD (input_location, | |
966 | method_type_node, field, "ncode", nativecode_ptr_type_node); | |
967 | PUSH_FIELD (input_location, | |
968 | method_type_node, field, "throws", ptr_type_node); | |
377029eb | 969 | FINISH_RECORD (method_type_node); |
e60a6f7b | 970 | build_decl (BUILTINS_LOCATION, |
971 | TYPE_DECL, get_identifier ("Method"), method_type_node); | |
377029eb | 972 | |
bfa624b3 | 973 | end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE); |
3f1158be | 974 | |
bfa624b3 | 975 | t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE); |
976 | alloc_object_node = add_builtin_function ("_Jv_AllocObject", t, | |
54be5d7e | 977 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
d70dd33d | 978 | DECL_IS_MALLOC (alloc_object_node) = 1; |
54be5d7e | 979 | alloc_no_finalizer_node = |
bfa624b3 | 980 | add_builtin_function ("_Jv_AllocObjectNoFinalizer", t, |
54be5d7e | 981 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
a8f5ddb8 | 982 | DECL_IS_MALLOC (alloc_no_finalizer_node) = 1; |
47efb553 | 983 | |
bfa624b3 | 984 | t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); |
985 | soft_initclass_node = add_builtin_function ("_Jv_InitClass", t, | |
54be5d7e | 986 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
bfa624b3 | 987 | t = build_function_type_list (ptr_type_node, |
988 | class_ptr_type, int_type_node, NULL_TREE); | |
54be5d7e | 989 | soft_resolvepoolentry_node |
bfa624b3 | 990 | = add_builtin_function ("_Jv_ResolvePoolEntry", t, |
54be5d7e | 991 | 0,NOT_BUILT_IN, NULL, NULL_TREE); |
9c2a0c05 | 992 | DECL_PURE_P (soft_resolvepoolentry_node) = 1; |
bfa624b3 | 993 | t = build_function_type_list (void_type_node, |
994 | class_ptr_type, int_type_node, NULL_TREE); | |
995 | throw_node = add_builtin_function ("_Jv_Throw", t, | |
54be5d7e | 996 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
37c32b0a | 997 | /* Mark throw_nodes as `noreturn' functions with side effects. */ |
d3ab4940 | 998 | TREE_THIS_VOLATILE (throw_node) = 1; |
999 | TREE_SIDE_EFFECTS (throw_node) = 1; | |
df4b504c | 1000 | |
bfa624b3 | 1001 | t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); |
54be5d7e | 1002 | soft_monitorenter_node |
1003 | = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN, | |
1004 | NULL, NULL_TREE); | |
1005 | soft_monitorexit_node | |
1006 | = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN, | |
1007 | NULL, NULL_TREE); | |
1008 | ||
bfa624b3 | 1009 | t = build_function_type_list (ptr_type_node, |
1010 | ptr_type_node, int_type_node, NULL_TREE); | |
377029eb | 1011 | soft_newarray_node |
bfa624b3 | 1012 | = add_builtin_function ("_Jv_NewPrimArray", t, |
54be5d7e | 1013 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
d70dd33d | 1014 | DECL_IS_MALLOC (soft_newarray_node) = 1; |
377029eb | 1015 | |
bfa624b3 | 1016 | t = build_function_type_list (ptr_type_node, |
1017 | int_type_node, class_ptr_type, | |
1018 | object_ptr_type_node, NULL_TREE); | |
377029eb | 1019 | soft_anewarray_node |
bfa624b3 | 1020 | = add_builtin_function ("_Jv_NewObjectArray", t, |
54be5d7e | 1021 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
d70dd33d | 1022 | DECL_IS_MALLOC (soft_anewarray_node) = 1; |
377029eb | 1023 | |
bfa624b3 | 1024 | t = build_varargs_function_type_list (ptr_type_node, |
1025 | ptr_type_node, int_type_node, | |
1026 | NULL_TREE); | |
377029eb | 1027 | soft_multianewarray_node |
bfa624b3 | 1028 | = add_builtin_function ("_Jv_NewMultiArray", t, |
54be5d7e | 1029 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
d70dd33d | 1030 | DECL_IS_MALLOC (soft_multianewarray_node) = 1; |
377029eb | 1031 | |
bfa624b3 | 1032 | t = build_function_type_list (void_type_node, int_type_node, NULL_TREE); |
377029eb | 1033 | soft_badarrayindex_node |
54be5d7e | 1034 | = add_builtin_function ("_Jv_ThrowBadArrayIndex", t, |
1035 | 0, NOT_BUILT_IN, NULL, NULL_TREE); | |
d70dd33d | 1036 | /* Mark soft_badarrayindex_node as a `noreturn' function with side |
1037 | effects. */ | |
377029eb | 1038 | TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1; |
1039 | TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1; | |
1040 | ||
bfa624b3 | 1041 | t = build_function_type_list (void_type_node, NULL_TREE); |
d31bba8b | 1042 | soft_nullpointer_node |
bfa624b3 | 1043 | = add_builtin_function ("_Jv_ThrowNullPointerException", t, |
54be5d7e | 1044 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
d31bba8b | 1045 | /* Mark soft_nullpointer_node as a `noreturn' function with side |
1046 | effects. */ | |
1047 | TREE_THIS_VOLATILE (soft_nullpointer_node) = 1; | |
1048 | TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1; | |
1049 | ||
beb3619b | 1050 | soft_abstractmethod_node |
bfa624b3 | 1051 | = add_builtin_function ("_Jv_ThrowAbstractMethodError", t, |
54be5d7e | 1052 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
beb3619b | 1053 | /* Mark soft_abstractmethod_node as a `noreturn' function with side |
1054 | effects. */ | |
1055 | TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1; | |
1056 | TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1; | |
1057 | ||
f39bebdb | 1058 | soft_nosuchfield_node |
bfa624b3 | 1059 | = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t, |
54be5d7e | 1060 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
f39bebdb | 1061 | /* Mark soft_nosuchfield_node as a `noreturn' function with side |
1062 | effects. */ | |
1063 | TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1; | |
1064 | TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1; | |
1065 | ||
bfa624b3 | 1066 | t = build_function_type_list (ptr_type_node, |
1067 | class_ptr_type, object_ptr_type_node, | |
1068 | NULL_TREE); | |
377029eb | 1069 | soft_checkcast_node |
bfa624b3 | 1070 | = add_builtin_function ("_Jv_CheckCast", t, |
54be5d7e | 1071 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
bfa624b3 | 1072 | t = build_function_type_list (boolean_type_node, |
1073 | object_ptr_type_node, class_ptr_type, | |
1074 | NULL_TREE); | |
377029eb | 1075 | soft_instanceof_node |
bfa624b3 | 1076 | = add_builtin_function ("_Jv_IsInstanceOf", t, |
54be5d7e | 1077 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
9c2a0c05 | 1078 | DECL_PURE_P (soft_instanceof_node) = 1; |
bfa624b3 | 1079 | t = build_function_type_list (void_type_node, |
1080 | object_ptr_type_node, object_ptr_type_node, | |
1081 | NULL_TREE); | |
377029eb | 1082 | soft_checkarraystore_node |
bfa624b3 | 1083 | = add_builtin_function ("_Jv_CheckArrayStore", t, |
54be5d7e | 1084 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
bfa624b3 | 1085 | t = build_function_type_list (ptr_type_node, |
1086 | ptr_type_node, ptr_type_node, int_type_node, | |
1087 | NULL_TREE); | |
54be5d7e | 1088 | soft_lookupinterfacemethod_node |
bfa624b3 | 1089 | = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t, |
54be5d7e | 1090 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
9c2a0c05 | 1091 | DECL_PURE_P (soft_lookupinterfacemethod_node) = 1; |
bfa624b3 | 1092 | |
1093 | t = build_function_type_list (ptr_type_node, | |
1094 | ptr_type_node, ptr_type_node, ptr_type_node, | |
1095 | NULL_TREE); | |
54be5d7e | 1096 | soft_lookupinterfacemethodbyname_node |
bfa624b3 | 1097 | = add_builtin_function ("_Jv_LookupInterfaceMethod", t, |
54be5d7e | 1098 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
bfa624b3 | 1099 | t = build_function_type_list (ptr_type_node, |
1100 | object_ptr_type_node, ptr_type_node, | |
1101 | ptr_type_node, int_type_node, NULL_TREE); | |
47efb553 | 1102 | soft_lookupjnimethod_node |
bfa624b3 | 1103 | = add_builtin_function ("_Jv_LookupJNIMethod", t, |
54be5d7e | 1104 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
bfa624b3 | 1105 | t = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE); |
47efb553 | 1106 | soft_getjnienvnewframe_node |
bfa624b3 | 1107 | = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t, |
54be5d7e | 1108 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
bfa624b3 | 1109 | t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); |
47efb553 | 1110 | soft_jnipopsystemframe_node |
bfa624b3 | 1111 | = add_builtin_function ("_Jv_JNI_PopSystemFrame", t, |
54be5d7e | 1112 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
279ecc98 | 1113 | |
bfa624b3 | 1114 | t = build_function_type_list (object_ptr_type_node, |
1115 | object_ptr_type_node, NULL_TREE); | |
279ecc98 | 1116 | soft_unwrapjni_node |
bfa624b3 | 1117 | = add_builtin_function ("_Jv_UnwrapJNIweakReference", t, |
54be5d7e | 1118 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
47efb553 | 1119 | |
bfa624b3 | 1120 | t = build_function_type_list (int_type_node, |
1121 | int_type_node, int_type_node, NULL_TREE); | |
e2416019 | 1122 | soft_idiv_node |
bfa624b3 | 1123 | = add_builtin_function ("_Jv_divI", t, |
54be5d7e | 1124 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
e2416019 | 1125 | |
1126 | soft_irem_node | |
bfa624b3 | 1127 | = add_builtin_function ("_Jv_remI", t, |
54be5d7e | 1128 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
e2416019 | 1129 | |
bfa624b3 | 1130 | t = build_function_type_list (long_type_node, |
1131 | long_type_node, long_type_node, NULL_TREE); | |
e2416019 | 1132 | soft_ldiv_node |
bfa624b3 | 1133 | = add_builtin_function ("_Jv_divJ", t, |
54be5d7e | 1134 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
e2416019 | 1135 | |
1136 | soft_lrem_node | |
bfa624b3 | 1137 | = add_builtin_function ("_Jv_remJ", t, |
54be5d7e | 1138 | 0, NOT_BUILT_IN, NULL, NULL_TREE); |
b2b288ca | 1139 | |
fcffb974 | 1140 | initialize_builtins (); |
e38def9c | 1141 | |
b9a16870 | 1142 | soft_fmod_node = builtin_decl_explicit (BUILT_IN_FMOD); |
420091c2 | 1143 | |
1144 | parse_version (); | |
377029eb | 1145 | } |
1146 | ||
1147 | ||
1148 | /* Look up NAME in the current binding level and its superiors | |
1149 | in the namespace of variables, functions and typedefs. | |
1150 | Return a ..._DECL node of some kind representing its definition, | |
1151 | or return 0 if it is undefined. */ | |
1152 | ||
1153 | tree | |
2883a3ed | 1154 | lookup_name (tree name) |
377029eb | 1155 | { |
fdbb243d | 1156 | tree val; |
377029eb | 1157 | if (current_binding_level != global_binding_level |
1158 | && IDENTIFIER_LOCAL_VALUE (name)) | |
1159 | val = IDENTIFIER_LOCAL_VALUE (name); | |
1160 | else | |
1161 | val = IDENTIFIER_GLOBAL_VALUE (name); | |
1162 | return val; | |
1163 | } | |
1164 | ||
1165 | /* Similar to `lookup_name' but look only at current binding level and | |
7a974467 | 1166 | the previous one if it's the parameter level. */ |
377029eb | 1167 | |
003019ba | 1168 | static tree |
2883a3ed | 1169 | lookup_name_current_level (tree name) |
377029eb | 1170 | { |
fdbb243d | 1171 | tree t; |
377029eb | 1172 | |
1173 | if (current_binding_level == global_binding_level) | |
1174 | return IDENTIFIER_GLOBAL_VALUE (name); | |
1175 | ||
1176 | if (IDENTIFIER_LOCAL_VALUE (name) == 0) | |
1177 | return 0; | |
1178 | ||
1767a056 | 1179 | for (t = current_binding_level->names; t; t = DECL_CHAIN (t)) |
377029eb | 1180 | if (DECL_NAME (t) == name) |
1181 | break; | |
1182 | ||
1183 | return t; | |
1184 | } | |
1185 | ||
377029eb | 1186 | /* Record a decl-node X as belonging to the current lexical scope. |
1187 | Check for errors (such as an incompatible declaration for the same | |
1188 | name already seen in the same scope). | |
1189 | ||
1190 | Returns either X or an old decl for the same name. | |
1191 | If an old decl is returned, it may have been smashed | |
1192 | to agree with what X says. */ | |
1193 | ||
1194 | tree | |
2883a3ed | 1195 | pushdecl (tree x) |
377029eb | 1196 | { |
fdbb243d | 1197 | tree t; |
1198 | tree name = DECL_NAME (x); | |
1199 | struct binding_level *b = current_binding_level; | |
4654e794 | 1200 | |
1201 | if (TREE_CODE (x) != TYPE_DECL) | |
1202 | DECL_CONTEXT (x) = current_function_decl; | |
377029eb | 1203 | if (name) |
1204 | { | |
377029eb | 1205 | t = lookup_name_current_level (name); |
1206 | if (t != 0 && t == error_mark_node) | |
1207 | /* error_mark_node is 0 for a while during initialization! */ | |
1208 | { | |
1209 | t = 0; | |
3cf8b391 | 1210 | error ("%q+D used prior to declaration", x); |
377029eb | 1211 | } |
1212 | ||
377029eb | 1213 | /* If we're naming a hitherto-unnamed type, set its TYPE_NAME |
1214 | to point to the TYPE_DECL. | |
1215 | Since Java does not have typedefs, a type can only have | |
1216 | one (true) name, given by a class, interface, or builtin. */ | |
1217 | if (TREE_CODE (x) == TYPE_DECL | |
1218 | && TYPE_NAME (TREE_TYPE (x)) == 0 | |
1219 | && TREE_TYPE (x) != error_mark_node) | |
1220 | { | |
1221 | TYPE_NAME (TREE_TYPE (x)) = x; | |
1222 | TYPE_STUB_DECL (TREE_TYPE (x)) = x; | |
1223 | } | |
1224 | ||
1225 | /* This name is new in its binding level. | |
1226 | Install the new declaration and return it. */ | |
1227 | if (b == global_binding_level) | |
1228 | { | |
1229 | /* Install a global value. */ | |
1230 | ||
1231 | IDENTIFIER_GLOBAL_VALUE (name) = x; | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | /* Here to install a non-global value. */ | |
1236 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
377029eb | 1237 | IDENTIFIER_LOCAL_VALUE (name) = x; |
1238 | ||
377029eb | 1239 | /* If storing a local value, there may already be one (inherited). |
1240 | If so, record it for restoration when this binding level ends. */ | |
1241 | if (oldlocal != 0) | |
1242 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
1243 | } | |
1244 | } | |
1245 | ||
1246 | /* Put decls on list in reverse order. | |
1247 | We will reverse them later if necessary. */ | |
1767a056 | 1248 | DECL_CHAIN (x) = b->names; |
377029eb | 1249 | b->names = x; |
1250 | ||
1251 | return x; | |
1252 | } | |
af5b2568 | 1253 | |
377029eb | 1254 | void |
2883a3ed | 1255 | pushdecl_force_head (tree x) |
377029eb | 1256 | { |
1257 | current_binding_level->names = x; | |
1258 | } | |
1259 | ||
1260 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ | |
1261 | ||
1262 | tree | |
2883a3ed | 1263 | pushdecl_top_level (tree x) |
377029eb | 1264 | { |
fdbb243d | 1265 | tree t; |
1266 | struct binding_level *b = current_binding_level; | |
377029eb | 1267 | |
1268 | current_binding_level = global_binding_level; | |
1269 | t = pushdecl (x); | |
1270 | current_binding_level = b; | |
1271 | return t; | |
1272 | } | |
1273 | ||
469e4af3 | 1274 | /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */ |
1275 | ||
1276 | tree | |
1277 | pushdecl_function_level (tree x) | |
1278 | { | |
1279 | tree t; | |
1280 | struct binding_level *b = current_binding_level; | |
1281 | ||
1282 | current_binding_level = function_binding_level; | |
1283 | t = pushdecl (x); | |
1284 | current_binding_level = b; | |
1285 | return t; | |
1286 | } | |
1287 | ||
1d2bb655 | 1288 | /* Return true if we are in the global binding level. */ |
377029eb | 1289 | |
1d2bb655 | 1290 | bool |
2883a3ed | 1291 | global_bindings_p (void) |
377029eb | 1292 | { |
1293 | return current_binding_level == global_binding_level; | |
1294 | } | |
1295 | ||
1296 | /* Return the list of declarations of the current level. | |
1297 | Note that this list is in reverse order unless/until | |
1298 | you nreverse it; and when you do nreverse it, you must | |
1299 | store the result back using `storedecls' or you will lose. */ | |
1300 | ||
1301 | tree | |
2883a3ed | 1302 | getdecls (void) |
377029eb | 1303 | { |
1304 | return current_binding_level->names; | |
1305 | } | |
1306 | ||
1307 | /* Create a new `struct binding_level'. */ | |
1308 | ||
af5b2568 | 1309 | static struct binding_level * |
2883a3ed | 1310 | make_binding_level (void) |
377029eb | 1311 | { |
1312 | /* NOSTRICT */ | |
25a27413 | 1313 | return ggc_cleared_alloc<binding_level> (); |
377029eb | 1314 | } |
1315 | ||
1316 | void | |
2883a3ed | 1317 | pushlevel (int unused ATTRIBUTE_UNUSED) |
377029eb | 1318 | { |
fdbb243d | 1319 | struct binding_level *newlevel = NULL_BINDING_LEVEL; |
377029eb | 1320 | |
377029eb | 1321 | /* Reuse or create a struct for this binding level. */ |
1322 | ||
1323 | if (free_binding_level) | |
1324 | { | |
1325 | newlevel = free_binding_level; | |
1326 | free_binding_level = free_binding_level->level_chain; | |
1327 | } | |
1328 | else | |
1329 | { | |
1330 | newlevel = make_binding_level (); | |
1331 | } | |
1332 | ||
1333 | /* Add this level to the front of the chain (stack) of levels that | |
1334 | are active. */ | |
1335 | ||
1336 | *newlevel = clear_binding_level; | |
1337 | newlevel->level_chain = current_binding_level; | |
444e42cc | 1338 | newlevel->loc = input_location; |
1339 | current_binding_level = newlevel; | |
c1b6623d | 1340 | #if defined(DEBUG_JAVA_BINDING_LEVELS) |
1341 | newlevel->binding_depth = binding_depth; | |
1342 | indent (); | |
4ee9c684 | 1343 | fprintf (stderr, "push %s level %p pc %d\n", |
c1b6623d | 1344 | (is_class_level) ? "class" : "block", newlevel, current_pc); |
1345 | is_class_level = 0; | |
1346 | binding_depth++; | |
1347 | #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */ | |
377029eb | 1348 | } |
1349 | ||
1350 | /* Exit a binding level. | |
1351 | Pop the level off, and restore the state of the identifier-decl mappings | |
1352 | that were in effect when this level was entered. | |
1353 | ||
1354 | If KEEP is nonzero, this level had explicit declarations, so | |
1355 | and create a "block" (a BLOCK node) for the level | |
1356 | to record its declarations and subblocks for symbol table output. | |
1357 | ||
1358 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
1359 | so create a block as if KEEP were set and also clear out all | |
1360 | label names. | |
1361 | ||
1362 | If REVERSE is nonzero, reverse the order of decls before putting | |
1363 | them into the BLOCK. */ | |
1364 | ||
1365 | tree | |
2883a3ed | 1366 | poplevel (int keep, int reverse, int functionbody) |
377029eb | 1367 | { |
fdbb243d | 1368 | tree link; |
377029eb | 1369 | /* The chain of decls was accumulated in reverse order. |
1370 | Put it into forward order, just for cleanliness. */ | |
1371 | tree decls; | |
1372 | tree subblocks = current_binding_level->blocks; | |
1373 | tree block = 0; | |
1374 | tree decl; | |
4ee9c684 | 1375 | tree bind = 0; |
377029eb | 1376 | |
c1b6623d | 1377 | #if defined(DEBUG_JAVA_BINDING_LEVELS) |
1378 | binding_depth--; | |
1379 | indent (); | |
1380 | if (current_binding_level->end_pc != LARGEST_PC) | |
4ee9c684 | 1381 | fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n", |
c1b6623d | 1382 | (is_class_level) ? "class" : "block", current_binding_level, current_pc, |
1383 | current_binding_level->end_pc); | |
1384 | else | |
4ee9c684 | 1385 | fprintf (stderr, "pop %s level %p pc %d\n", |
c1b6623d | 1386 | (is_class_level) ? "class" : "block", current_binding_level, current_pc); |
c1b6623d | 1387 | #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */ |
1388 | ||
377029eb | 1389 | /* Get the decls in the order they were written. |
1390 | Usually current_binding_level->names is in reverse order. | |
1391 | But parameter decls were previously put in forward order. */ | |
1392 | ||
1393 | if (reverse) | |
1394 | current_binding_level->names | |
1395 | = decls = nreverse (current_binding_level->names); | |
1396 | else | |
1397 | decls = current_binding_level->names; | |
1398 | ||
1767a056 | 1399 | for (decl = decls; decl; decl = DECL_CHAIN (decl)) |
4ee9c684 | 1400 | if (TREE_CODE (decl) == VAR_DECL |
1401 | && DECL_LANG_SPECIFIC (decl) != NULL | |
1402 | && DECL_LOCAL_SLOT_NUMBER (decl)) | |
1403 | LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1; | |
377029eb | 1404 | |
1405 | /* If there were any declarations in that level, | |
1406 | or if this level is a function body, | |
1407 | create a BLOCK to record them for the life of this function. */ | |
1408 | ||
1409 | block = 0; | |
d458bdd7 | 1410 | if (keep || functionbody) |
027fc6ef | 1411 | block = make_node (BLOCK); |
4ee9c684 | 1412 | |
310b3906 | 1413 | if (current_binding_level->exception_range) |
1414 | expand_end_java_handler (current_binding_level->exception_range); | |
1415 | ||
377029eb | 1416 | if (block != 0) |
1417 | { | |
4ee9c684 | 1418 | /* If any statements have been generated at this level, create a |
1419 | BIND_EXPR to hold them and copy the variables to it. This | |
1420 | only applies to the bytecode compiler. */ | |
1421 | if (current_binding_level->stmts) | |
1422 | { | |
1423 | tree decl = decls; | |
1424 | tree *var = &BLOCK_VARS (block); | |
1425 | ||
1426 | /* Copy decls from names list, ignoring labels. */ | |
1427 | while (decl) | |
1428 | { | |
1767a056 | 1429 | tree next = DECL_CHAIN (decl); |
4ee9c684 | 1430 | if (TREE_CODE (decl) != LABEL_DECL) |
1431 | { | |
1432 | *var = decl; | |
1767a056 | 1433 | var = &DECL_CHAIN (decl); |
4ee9c684 | 1434 | } |
1435 | decl = next; | |
1436 | } | |
1437 | *var = NULL; | |
1438 | ||
027fc6ef | 1439 | bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block), |
4ee9c684 | 1440 | BLOCK_EXPR_BODY (block), block); |
4ee9c684 | 1441 | BIND_EXPR_BODY (bind) = current_binding_level->stmts; |
1442 | ||
1443 | if (BIND_EXPR_BODY (bind) | |
1444 | && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind))) | |
1445 | TREE_SIDE_EFFECTS (bind) = 1; | |
1446 | ||
1447 | /* FIXME: gimplifier brain damage. */ | |
1448 | if (BIND_EXPR_BODY (bind) == NULL) | |
1449 | BIND_EXPR_BODY (bind) = build_java_empty_stmt (); | |
1450 | ||
444e42cc | 1451 | SET_EXPR_LOCATION (bind, current_binding_level->loc); |
1452 | ||
4ee9c684 | 1453 | current_binding_level->stmts = NULL; |
1454 | } | |
1455 | else | |
1456 | { | |
1457 | BLOCK_VARS (block) = decls; | |
1458 | } | |
377029eb | 1459 | BLOCK_SUBBLOCKS (block) = subblocks; |
4ee9c684 | 1460 | } |
377029eb | 1461 | |
1462 | /* In each subblock, record that this is its superior. */ | |
1463 | ||
2149d019 | 1464 | for (link = subblocks; link; link = BLOCK_CHAIN (link)) |
377029eb | 1465 | BLOCK_SUPERCONTEXT (link) = block; |
1466 | ||
1467 | /* Clear out the meanings of the local variables of this level. */ | |
1468 | ||
1767a056 | 1469 | for (link = decls; link; link = DECL_CHAIN (link)) |
377029eb | 1470 | { |
1471 | tree name = DECL_NAME (link); | |
1472 | if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link) | |
1473 | { | |
1474 | /* If the ident. was used or addressed via a local extern decl, | |
1475 | don't forget that fact. */ | |
1476 | if (DECL_EXTERNAL (link)) | |
1477 | { | |
1478 | if (TREE_USED (link)) | |
1479 | TREE_USED (name) = 1; | |
1480 | if (TREE_ADDRESSABLE (link)) | |
1481 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1482 | } | |
1483 | IDENTIFIER_LOCAL_VALUE (name) = 0; | |
1484 | } | |
1485 | } | |
1486 | ||
1487 | /* Restore all name-meanings of the outer levels | |
1488 | that were shadowed by this level. */ | |
1489 | ||
1490 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1491 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1492 | ||
1493 | /* If the level being exited is the top level of a function, | |
1494 | check over all the labels, and clear out the current | |
1495 | (function local) meanings of their names. */ | |
1496 | ||
1497 | if (functionbody) | |
1498 | { | |
1499 | /* If this is the top level block of a function, | |
1500 | the vars are the function's parameters. | |
1501 | Don't leave them in the BLOCK because they are | |
1502 | found in the FUNCTION_DECL instead. */ | |
1503 | ||
1504 | BLOCK_VARS (block) = 0; | |
377029eb | 1505 | } |
1506 | ||
1507 | /* Pop the current level, and free the structure for reuse. */ | |
1508 | ||
1509 | { | |
fdbb243d | 1510 | struct binding_level *level = current_binding_level; |
377029eb | 1511 | current_binding_level = current_binding_level->level_chain; |
1512 | ||
1513 | level->level_chain = free_binding_level; | |
1514 | free_binding_level = level; | |
1515 | } | |
1516 | ||
1517 | /* Dispose of the block that we just made inside some higher level. */ | |
1518 | if (functionbody) | |
4ee9c684 | 1519 | { |
1520 | DECL_INITIAL (current_function_decl) = block; | |
1521 | DECL_SAVED_TREE (current_function_decl) = bind; | |
1522 | } | |
310b3906 | 1523 | else |
377029eb | 1524 | { |
310b3906 | 1525 | if (block) |
1526 | { | |
d458bdd7 | 1527 | current_binding_level->blocks |
2149d019 | 1528 | = block_chainon (current_binding_level->blocks, block); |
310b3906 | 1529 | } |
1530 | /* If we did not make a block for the level just exited, | |
1531 | any blocks made for inner levels | |
1532 | (since they cannot be recorded as subblocks in that level) | |
1533 | must be carried forward so they will later become subblocks | |
1534 | of something else. */ | |
1535 | else if (subblocks) | |
1536 | current_binding_level->blocks | |
2149d019 | 1537 | = block_chainon (current_binding_level->blocks, subblocks); |
310b3906 | 1538 | |
1539 | if (bind) | |
1540 | java_add_stmt (bind); | |
377029eb | 1541 | } |
310b3906 | 1542 | |
377029eb | 1543 | if (block) |
1544 | TREE_USED (block) = 1; | |
1545 | return block; | |
1546 | } | |
1547 | ||
1548 | void | |
2883a3ed | 1549 | maybe_pushlevels (int pc) |
377029eb | 1550 | { |
c1b6623d | 1551 | #if defined(DEBUG_JAVA_BINDING_LEVELS) |
1552 | current_pc = pc; | |
1553 | #endif | |
1554 | ||
377029eb | 1555 | while (pending_local_decls != NULL_TREE && |
1556 | DECL_LOCAL_START_PC (pending_local_decls) <= pc) | |
1557 | { | |
1558 | tree *ptr = &pending_local_decls; | |
4ee9c684 | 1559 | tree decl = *ptr, next; |
377029eb | 1560 | int end_pc = DECL_LOCAL_END_PC (decl); |
1561 | ||
1562 | while (*ptr != NULL_TREE | |
1563 | && DECL_LOCAL_START_PC (*ptr) <= pc | |
1564 | && DECL_LOCAL_END_PC (*ptr) == end_pc) | |
1767a056 | 1565 | ptr = &DECL_CHAIN (*ptr); |
377029eb | 1566 | pending_local_decls = *ptr; |
1567 | *ptr = NULL_TREE; | |
1568 | ||
469e4af3 | 1569 | /* Force non-nested range to be nested in current range by |
1570 | truncating variable lifetimes. */ | |
377029eb | 1571 | if (end_pc > current_binding_level->end_pc) |
469e4af3 | 1572 | { |
210e7748 | 1573 | tree t; |
469e4af3 | 1574 | end_pc = current_binding_level->end_pc; |
1767a056 | 1575 | for (t = decl; t != NULL_TREE; t = DECL_CHAIN (t)) |
210e7748 | 1576 | DECL_LOCAL_END_PC (t) = end_pc; |
469e4af3 | 1577 | } |
377029eb | 1578 | |
c1b6623d | 1579 | maybe_start_try (pc, end_pc); |
1580 | ||
377029eb | 1581 | pushlevel (1); |
c1b6623d | 1582 | |
377029eb | 1583 | current_binding_level->end_pc = end_pc; |
c1b6623d | 1584 | current_binding_level->start_pc = pc; |
4ee9c684 | 1585 | current_binding_level->names = NULL; |
1586 | for ( ; decl != NULL_TREE; decl = next) | |
377029eb | 1587 | { |
208ca064 | 1588 | int index = DECL_LOCAL_SLOT_NUMBER (decl); |
1589 | tree base_decl; | |
1767a056 | 1590 | next = DECL_CHAIN (decl); |
208ca064 | 1591 | push_jvm_slot (index, decl); |
469e4af3 | 1592 | pushdecl (decl); |
208ca064 | 1593 | base_decl |
1594 | = find_local_variable (index, TREE_TYPE (decl), pc); | |
1595 | if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE) | |
1596 | base_decl = TREE_VEC_ELT (base_decl_map, index); | |
1597 | SET_DECL_VALUE_EXPR (decl, base_decl); | |
1598 | DECL_HAS_VALUE_EXPR_P (decl) = 1; | |
377029eb | 1599 | } |
c1b6623d | 1600 | } |
1601 | ||
1602 | maybe_start_try (pc, 0); | |
377029eb | 1603 | } |
1604 | ||
1605 | void | |
2883a3ed | 1606 | maybe_poplevels (int pc) |
377029eb | 1607 | { |
c1b6623d | 1608 | #if defined(DEBUG_JAVA_BINDING_LEVELS) |
1609 | current_pc = pc; | |
1610 | #endif | |
1611 | ||
9a878e5e | 1612 | /* FIXME: I'm pretty sure that this is wrong. Variable scopes are |
1613 | inclusive, so a variable is live if pc == end_pc. Here, we | |
1614 | terminate a range if the current pc is equal to the end of the | |
1615 | range, and this is *before* we have generated code for the | |
1616 | instruction at end_pc. We're closing a binding level one | |
1617 | instruction too early.*/ | |
377029eb | 1618 | while (current_binding_level->end_pc <= pc) |
310b3906 | 1619 | poplevel (1, 0, 0); |
c1b6623d | 1620 | } |
1621 | ||
1622 | /* Terminate any binding which began during the range beginning at | |
1623 | start_pc. This tidies up improperly nested local variable ranges | |
1624 | and exception handlers; a variable declared within an exception | |
1625 | range is forcibly terminated when that exception ends. */ | |
1626 | ||
1627 | void | |
2883a3ed | 1628 | force_poplevels (int start_pc) |
c1b6623d | 1629 | { |
1630 | while (current_binding_level->start_pc > start_pc) | |
1631 | { | |
c1b6623d | 1632 | if (pedantic && current_binding_level->start_pc > start_pc) |
3cf8b391 | 1633 | warning (0, "In %+D: overlapped variable and exception ranges at %d", |
1634 | current_function_decl, | |
9bc3739f | 1635 | current_binding_level->start_pc); |
377029eb | 1636 | poplevel (1, 0, 0); |
1637 | } | |
1638 | } | |
1639 | ||
377029eb | 1640 | /* integrate_decl_tree calls this function. */ |
1641 | ||
1642 | void | |
2883a3ed | 1643 | java_dup_lang_specific_decl (tree node) |
377029eb | 1644 | { |
dbc42b78 | 1645 | int lang_decl_size; |
1646 | struct lang_decl *x; | |
1647 | ||
1648 | if (!DECL_LANG_SPECIFIC (node)) | |
1649 | return; | |
1650 | ||
1f3233d1 | 1651 | lang_decl_size = sizeof (struct lang_decl); |
25a27413 | 1652 | x = ggc_alloc<struct lang_decl> (); |
b1b63592 | 1653 | memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size); |
377029eb | 1654 | DECL_LANG_SPECIFIC (node) = x; |
1655 | } | |
1656 | ||
377029eb | 1657 | void |
2883a3ed | 1658 | give_name_to_locals (JCF *jcf) |
377029eb | 1659 | { |
1660 | int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl); | |
bc099162 | 1661 | int code_offset = DECL_CODE_OFFSET (current_function_decl); |
377029eb | 1662 | tree parm; |
1663 | pending_local_decls = NULL_TREE; | |
1664 | if (n == 0) | |
1665 | return; | |
1666 | JCF_SEEK (jcf, n); | |
1667 | n = JCF_readu2 (jcf); | |
1668 | for (i = 0; i < n; i++) | |
1669 | { | |
1670 | int start_pc = JCF_readu2 (jcf); | |
1671 | int length = JCF_readu2 (jcf); | |
1672 | int name_index = JCF_readu2 (jcf); | |
1673 | int signature_index = JCF_readu2 (jcf); | |
1674 | int slot = JCF_readu2 (jcf); | |
1675 | tree name = get_name_constant (jcf, name_index); | |
8f4b76a7 | 1676 | tree type = parse_signature (jcf, signature_index); |
377029eb | 1677 | if (slot < DECL_ARG_SLOT_COUNT (current_function_decl) |
1678 | && start_pc == 0 | |
1679 | && length == DECL_CODE_LENGTH (current_function_decl)) | |
1680 | { | |
1681 | tree decl = TREE_VEC_ELT (decl_map, slot); | |
1682 | DECL_NAME (decl) = name; | |
377029eb | 1683 | if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type) |
c3ceba8e | 1684 | warning (0, "bad type in parameter debug info"); |
377029eb | 1685 | } |
1686 | else | |
1687 | { | |
1688 | tree *ptr; | |
1689 | int end_pc = start_pc + length; | |
e60a6f7b | 1690 | tree decl = build_decl (input_location, VAR_DECL, name, type); |
377029eb | 1691 | if (end_pc > DECL_CODE_LENGTH (current_function_decl)) |
1692 | { | |
3cf8b391 | 1693 | warning (0, "bad PC range for debug info for local %q+D", |
1694 | decl); | |
377029eb | 1695 | end_pc = DECL_CODE_LENGTH (current_function_decl); |
1696 | } | |
bc099162 | 1697 | |
1698 | /* Adjust start_pc if necessary so that the local's first | |
1699 | store operation will use the relevant DECL as a | |
1700 | destination. Fore more information, read the leading | |
1701 | comments for expr.c:maybe_adjust_start_pc. */ | |
1702 | start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot); | |
1703 | ||
146d1460 | 1704 | MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl); |
377029eb | 1705 | DECL_LOCAL_SLOT_NUMBER (decl) = slot; |
1706 | DECL_LOCAL_START_PC (decl) = start_pc; | |
1707 | DECL_LOCAL_END_PC (decl) = end_pc; | |
1708 | ||
1709 | /* Now insert the new decl in the proper place in | |
1710 | pending_local_decls. We are essentially doing an insertion sort, | |
1711 | which works fine, since the list input will normally already | |
1712 | be sorted. */ | |
1713 | ptr = &pending_local_decls; | |
1714 | while (*ptr != NULL_TREE | |
1715 | && (DECL_LOCAL_START_PC (*ptr) > start_pc | |
1716 | || (DECL_LOCAL_START_PC (*ptr) == start_pc | |
1717 | && DECL_LOCAL_END_PC (*ptr) < end_pc))) | |
1767a056 | 1718 | ptr = &DECL_CHAIN (*ptr); |
1719 | DECL_CHAIN (decl) = *ptr; | |
377029eb | 1720 | *ptr = decl; |
1721 | } | |
1722 | } | |
1723 | ||
1724 | pending_local_decls = nreverse (pending_local_decls); | |
1725 | ||
1726 | /* Fill in default names for the parameters. */ | |
1727 | for (parm = DECL_ARGUMENTS (current_function_decl), i = 0; | |
1767a056 | 1728 | parm != NULL_TREE; parm = DECL_CHAIN (parm), i++) |
377029eb | 1729 | { |
1730 | if (DECL_NAME (parm) == NULL_TREE) | |
1731 | { | |
1732 | int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i; | |
1733 | if (arg_i == 0) | |
1734 | DECL_NAME (parm) = get_identifier ("this"); | |
1735 | else | |
1736 | { | |
1737 | char buffer[12]; | |
1738 | sprintf (buffer, "ARG_%d", arg_i); | |
1739 | DECL_NAME (parm) = get_identifier (buffer); | |
1740 | } | |
377029eb | 1741 | } |
1742 | } | |
1743 | } | |
1744 | ||
caa63dd7 | 1745 | tree |
2883a3ed | 1746 | build_result_decl (tree fndecl) |
377029eb | 1747 | { |
8f4b76a7 | 1748 | tree restype = TREE_TYPE (TREE_TYPE (fndecl)); |
53d20e65 | 1749 | tree result = DECL_RESULT (fndecl); |
1750 | if (! result) | |
1751 | { | |
e60a6f7b | 1752 | result = build_decl (DECL_SOURCE_LOCATION (fndecl), |
1753 | RESULT_DECL, NULL_TREE, restype); | |
540edea7 | 1754 | DECL_ARTIFICIAL (result) = 1; |
1755 | DECL_IGNORED_P (result) = 1; | |
53d20e65 | 1756 | DECL_CONTEXT (result) = fndecl; |
1757 | DECL_RESULT (fndecl) = result; | |
1758 | } | |
1759 | return result; | |
caa63dd7 | 1760 | } |
377029eb | 1761 | |
377029eb | 1762 | void |
2883a3ed | 1763 | start_java_method (tree fndecl) |
377029eb | 1764 | { |
1765 | tree tem, *ptr; | |
1766 | int i; | |
1767 | ||
469e4af3 | 1768 | uniq = 0; |
1769 | ||
377029eb | 1770 | current_function_decl = fndecl; |
1771 | announce_function (fndecl); | |
1772 | ||
1773 | i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl); | |
1774 | decl_map = make_tree_vec (i); | |
469e4af3 | 1775 | base_decl_map = make_tree_vec (i); |
25a1c410 | 1776 | type_map = XRESIZEVEC (tree, type_map, i); |
377029eb | 1777 | |
c1b6623d | 1778 | #if defined(DEBUG_JAVA_BINDING_LEVELS) |
96554925 | 1779 | fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2)); |
c1b6623d | 1780 | current_pc = 0; |
1781 | #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */ | |
377029eb | 1782 | pushlevel (1); /* Push parameters. */ |
1783 | ||
1784 | ptr = &DECL_ARGUMENTS (fndecl); | |
1785 | for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0; | |
3f1158be | 1786 | tem != end_params_node; tem = TREE_CHAIN (tem), i++) |
377029eb | 1787 | { |
1788 | tree parm_name = NULL_TREE, parm_decl; | |
8f4b76a7 | 1789 | tree parm_type = TREE_VALUE (tem); |
bc031ffe | 1790 | gcc_assert (i < DECL_MAX_LOCALS (fndecl)); |
377029eb | 1791 | |
e60a6f7b | 1792 | parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type); |
377029eb | 1793 | DECL_CONTEXT (parm_decl) = fndecl; |
82ac3699 | 1794 | if (targetm.calls.promote_prototypes (parm_type) |
bf5e6700 | 1795 | && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node) |
8f4b76a7 | 1796 | && INTEGRAL_TYPE_P (parm_type)) |
1797 | parm_type = integer_type_node; | |
8f4b76a7 | 1798 | DECL_ARG_TYPE (parm_decl) = parm_type; |
377029eb | 1799 | |
1800 | *ptr = parm_decl; | |
1767a056 | 1801 | ptr = &DECL_CHAIN (parm_decl); |
377029eb | 1802 | |
1803 | /* Add parm_decl to the decl_map. */ | |
1804 | push_jvm_slot (i, parm_decl); | |
00075d55 | 1805 | |
1806 | /* The this parameter of methods is artificial. */ | |
1807 | if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0) | |
1808 | DECL_ARTIFICIAL (parm_decl) = 1; | |
377029eb | 1809 | |
1810 | type_map[i] = TREE_TYPE (parm_decl); | |
1811 | if (TYPE_IS_WIDE (TREE_TYPE (parm_decl))) | |
1812 | { | |
1813 | i++; | |
1814 | type_map[i] = void_type_node; | |
1815 | } | |
1816 | } | |
1817 | *ptr = NULL_TREE; | |
1818 | DECL_ARG_SLOT_COUNT (current_function_decl) = i; | |
1819 | ||
1820 | while (i < DECL_MAX_LOCALS(fndecl)) | |
1821 | type_map[i++] = NULL_TREE; | |
1822 | ||
caa63dd7 | 1823 | build_result_decl (fndecl); |
444e42cc | 1824 | DECL_SOURCE_LOCATION (fndecl) = input_location; |
4ee9c684 | 1825 | |
1826 | /* Push local variables. */ | |
1827 | pushlevel (2); | |
469e4af3 | 1828 | |
1829 | function_binding_level = current_binding_level; | |
377029eb | 1830 | } |
1831 | ||
1832 | void | |
2883a3ed | 1833 | end_java_method (void) |
377029eb | 1834 | { |
1835 | tree fndecl = current_function_decl; | |
1836 | ||
377029eb | 1837 | /* pop out of function */ |
1838 | poplevel (1, 1, 0); | |
1839 | ||
1840 | /* pop out of its parameters */ | |
1841 | poplevel (1, 0, 1); | |
1842 | ||
1843 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; | |
549839e7 | 1844 | |
1845 | if (DECL_SAVED_TREE (fndecl)) | |
1846 | { | |
1847 | tree fbody, block_body; | |
1848 | /* Before we check initialization, attached all class initialization | |
1849 | variable to the block_body */ | |
1850 | fbody = DECL_SAVED_TREE (fndecl); | |
1851 | block_body = BIND_EXPR_BODY (fbody); | |
2ef51f0e | 1852 | hash_table<treetreehasher> *ht = DECL_FUNCTION_INIT_TEST_TABLE (fndecl); |
1853 | ht->traverse<tree, attach_init_test_initialization_flags> (block_body); | |
549839e7 | 1854 | } |
377029eb | 1855 | |
4ee9c684 | 1856 | finish_method (fndecl); |
377029eb | 1857 | |
1858 | current_function_decl = NULL_TREE; | |
bfec3452 | 1859 | base_decl_map = NULL_TREE; |
377029eb | 1860 | } |
a4e59c31 | 1861 | |
4ee9c684 | 1862 | /* Prepare a method for expansion. */ |
9d5ed6b3 | 1863 | |
1864 | void | |
4ee9c684 | 1865 | finish_method (tree fndecl) |
9d5ed6b3 | 1866 | { |
4ee9c684 | 1867 | tree *tp = &DECL_SAVED_TREE (fndecl); |
9d5ed6b3 | 1868 | |
4ee9c684 | 1869 | /* Wrap body of synchronized methods in a monitorenter, |
1870 | plus monitorexit cleanup. */ | |
1871 | if (METHOD_SYNCHRONIZED (fndecl)) | |
9d5ed6b3 | 1872 | { |
4ee9c684 | 1873 | tree enter, exit, lock; |
1874 | if (METHOD_STATIC (fndecl)) | |
1875 | lock = build_class_ref (DECL_CONTEXT (fndecl)); | |
1876 | else | |
1877 | lock = DECL_ARGUMENTS (fndecl); | |
1878 | BUILD_MONITOR_ENTER (enter, lock); | |
1879 | BUILD_MONITOR_EXIT (exit, lock); | |
e3f81426 | 1880 | *tp = build2 (COMPOUND_EXPR, void_type_node, enter, |
1881 | build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit)); | |
9d5ed6b3 | 1882 | } |
1883 | ||
4ee9c684 | 1884 | /* Convert function tree to GENERIC prior to inlining. */ |
1885 | java_genericize (fndecl); | |
9d5ed6b3 | 1886 | |
4ee9c684 | 1887 | /* Store the end of the function, so that we get good line number |
1888 | info for the epilogue. */ | |
1889 | if (DECL_STRUCT_FUNCTION (fndecl)) | |
87d4aa85 | 1890 | set_cfun (DECL_STRUCT_FUNCTION (fndecl)); |
4ee9c684 | 1891 | else |
80f2ef47 | 1892 | allocate_struct_function (fndecl, false); |
784bf0a0 | 1893 | cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl); |
9d5ed6b3 | 1894 | |
4ee9c684 | 1895 | /* Defer inlining and expansion to the cgraph optimizers. */ |
35ee1c66 | 1896 | cgraph_node::finalize_function (fndecl, false); |
4ee9c684 | 1897 | } |
1898 | ||
a82984ec | 1899 | /* We pessimistically marked all methods and fields external until we |
1900 | knew what set of classes we were planning to compile. Now mark those | |
1901 | associated with CLASS to be generated locally as not external. */ | |
1902 | ||
1903 | static void | |
1904 | java_mark_decl_local (tree decl) | |
1905 | { | |
1906 | DECL_EXTERNAL (decl) = 0; | |
1907 | ||
6329636b | 1908 | #ifdef ENABLE_CHECKING |
1909 | /* Double check that we didn't pass the function to the callgraph early. */ | |
1910 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
924de091 | 1911 | { |
415d1b9a | 1912 | struct cgraph_node *node = cgraph_node::get (decl); |
02774f2d | 1913 | gcc_assert (!node || !node->definition); |
924de091 | 1914 | } |
6329636b | 1915 | #endif |
1916 | gcc_assert (!DECL_RTL_SET_P (decl)); | |
a82984ec | 1917 | } |
1918 | ||
dc5e5216 | 1919 | /* Given appropriate target support, G++ will emit hidden aliases for native |
1920 | methods. Using this hidden name is required for proper operation of | |
1921 | _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for | |
1922 | proper target support, then mark the method for aliasing. */ | |
1923 | ||
1924 | static void | |
1925 | java_mark_cni_decl_local (tree decl) | |
1926 | { | |
dc5e5216 | 1927 | #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF) |
1928 | return; | |
1929 | #endif | |
1930 | ||
1931 | DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; | |
1932 | DECL_LOCAL_CNI_METHOD_P (decl) = 1; | |
699a0022 | 1933 | |
1934 | /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the | |
1935 | mangler. We might have already referenced this native method and | |
1936 | therefore created its name, but even if we have it won't hurt. | |
1937 | We'll just go via its externally visible name, rather than its | |
1938 | hidden alias. However, we must force things so that the correct | |
1939 | mangling is done. */ | |
1940 | ||
1941 | if (DECL_ASSEMBLER_NAME_SET_P (decl)) | |
1942 | java_mangle_decl (decl); | |
1943 | if (DECL_RTL_SET_P (decl)) | |
1944 | { | |
1945 | SET_DECL_RTL (decl, 0); | |
1946 | make_decl_rtl (decl); | |
1947 | } | |
dc5e5216 | 1948 | } |
1949 | ||
7a974467 | 1950 | /* Use the preceding two functions and mark all members of the class. */ |
dc5e5216 | 1951 | |
a82984ec | 1952 | void |
ead29d98 | 1953 | java_mark_class_local (tree klass) |
a82984ec | 1954 | { |
1955 | tree t; | |
1956 | ||
1767a056 | 1957 | for (t = TYPE_FIELDS (klass); t ; t = DECL_CHAIN (t)) |
a82984ec | 1958 | if (FIELD_STATIC (t)) |
3a1c9df2 | 1959 | java_mark_decl_local (t); |
a82984ec | 1960 | |
1767a056 | 1961 | for (t = TYPE_METHODS (klass); t ; t = DECL_CHAIN (t)) |
dc5e5216 | 1962 | if (!METHOD_ABSTRACT (t)) |
1963 | { | |
1964 | if (METHOD_NATIVE (t) && !flag_jni) | |
1965 | java_mark_cni_decl_local (t); | |
1966 | else | |
1967 | java_mark_decl_local (t); | |
1968 | } | |
a82984ec | 1969 | } |
1970 | ||
4ee9c684 | 1971 | /* Add a statement to a compound_expr. */ |
1972 | ||
1973 | tree | |
83a070d0 | 1974 | add_stmt_to_compound (tree existing, tree type, tree stmt) |
4ee9c684 | 1975 | { |
1976 | if (!stmt) | |
1977 | return existing; | |
1978 | else if (existing) | |
1979 | { | |
e3f81426 | 1980 | tree expr = build2 (COMPOUND_EXPR, type, existing, stmt); |
1981 | TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing) | |
1982 | | TREE_SIDE_EFFECTS (stmt); | |
4ee9c684 | 1983 | return expr; |
1984 | } | |
1985 | else | |
1986 | return stmt; | |
1987 | } | |
1988 | ||
444e42cc | 1989 | /* If this node is an expr, mark its input location. Called from |
1990 | walk_tree(). */ | |
1991 | ||
1992 | static tree | |
1993 | set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, | |
1994 | void *data ATTRIBUTE_UNUSED) | |
1995 | { | |
1996 | tree t = *tp; | |
1997 | ||
1998 | if (CAN_HAVE_LOCATION_P (t)) | |
1999 | { | |
2000 | if (EXPR_HAS_LOCATION(t)) | |
2001 | return t; /* Don't walk any further into this expr. */ | |
2002 | else | |
2003 | SET_EXPR_LOCATION (t, input_location); | |
2004 | } | |
2005 | ||
2006 | return NULL_TREE; /* Continue walking this expr. */ | |
2007 | } | |
2008 | ||
93777d07 | 2009 | /* Add a statement to the statement_list currently being constructed. |
2010 | If the statement_list is null, we don't create a singleton list. | |
2011 | This is necessary because poplevel() assumes that adding a | |
2012 | statement to a null statement_list returns the statement. */ | |
4ee9c684 | 2013 | |
2014 | tree | |
93777d07 | 2015 | java_add_stmt (tree new_stmt) |
4ee9c684 | 2016 | { |
93777d07 | 2017 | tree stmts = current_binding_level->stmts; |
2018 | tree_stmt_iterator i; | |
2019 | ||
3df42822 | 2020 | if (LOCATION_FILE (input_location)) |
444e42cc | 2021 | walk_tree (&new_stmt, set_input_location, NULL, NULL); |
2022 | ||
93777d07 | 2023 | if (stmts == NULL) |
2024 | return current_binding_level->stmts = new_stmt; | |
2025 | ||
2026 | /* Force STMTS to be a statement_list. */ | |
2027 | if (TREE_CODE (stmts) != STATEMENT_LIST) | |
2028 | { | |
2029 | tree t = make_node (STATEMENT_LIST); | |
2030 | i = tsi_last (t); | |
2031 | tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING); | |
2032 | stmts = t; | |
2033 | } | |
2034 | ||
2035 | i = tsi_last (stmts); | |
2036 | tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING); | |
f8166f6f | 2037 | TREE_TYPE (stmts) = void_type_node; |
93777d07 | 2038 | |
2039 | return current_binding_level->stmts = stmts; | |
4ee9c684 | 2040 | } |
2041 | ||
2042 | /* Add a variable to the current scope. */ | |
2043 | ||
2044 | tree | |
2045 | java_add_local_var (tree decl) | |
2046 | { | |
2047 | tree *vars = ¤t_binding_level->names; | |
2048 | tree next = *vars; | |
1767a056 | 2049 | DECL_CHAIN (decl) = next; |
4ee9c684 | 2050 | *vars = decl; |
2051 | DECL_CONTEXT (decl) = current_function_decl; | |
2052 | MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl); | |
2053 | return decl; | |
2054 | } | |
2055 | ||
2056 | /* Return a pointer to the compound_expr currently being | |
2057 | constructed. */ | |
2058 | ||
2059 | tree * | |
2060 | get_stmts (void) | |
2061 | { | |
2062 | return ¤t_binding_level->stmts; | |
2063 | } | |
2064 | ||
310b3906 | 2065 | /* Register an exception range as belonging to the current binding |
2066 | level. There may only be one: if there are more, we'll create more | |
2067 | binding levels. However, each range can have multiple handlers, | |
2068 | and these are expanded when we call expand_end_java_handler(). */ | |
2069 | ||
2070 | void | |
2071 | register_exception_range (struct eh_range *range, int pc, int end_pc) | |
2072 | { | |
bc031ffe | 2073 | gcc_assert (! current_binding_level->exception_range); |
310b3906 | 2074 | current_binding_level->exception_range = range; |
2075 | current_binding_level->end_pc = end_pc; | |
2076 | current_binding_level->start_pc = pc; | |
2077 | } | |
4ee9c684 | 2078 | |
1f3233d1 | 2079 | #include "gt-java-decl.h" |