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