OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [java/] [decl.c] - Blame information for rev 715

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.