Repository navigation
Expand file tree
/
Copy pathdecl.c
More file actions
2079 lines (1752 loc) · 66.4 KB
/
Copy pathdecl.c
File metadata and controls
2079 lines (1752 loc) · 66.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Process declarations and variables for the GNU compiler for the
Java(TM) language.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "diagnostic-core.h"
#include "toplev.h"
#include "flags.h"
#include "java-tree.h"
#include "jcf.h"
#include "libfuncs.h"
#include "java-except.h"
#include "ggc.h"
#include "cgraph.h"
#include "tree-inline.h"
#include "target.h"
#include "version.h"
#include "tree-iterator.h"
#include "langhooks.h"
#include "cgraph.h"
#if defined (DEBUG_JAVA_BINDING_LEVELS)
extern void indent (void);
#endif
static tree push_jvm_slot (int, tree);
static tree lookup_name_current_level (tree);
static tree push_promoted_type (const char *, tree);
static struct binding_level *make_binding_level (void);
static tree create_primitive_vtable (const char *);
static tree check_local_unnamed_variable (tree, tree, tree);
static void parse_version (void);
/* The following ABI flags are used in the high-order bits of the version
ID field. The version ID number itself should never be larger than
0xfffff, so it should be safe to use top 12 bits for these flags. */
#define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
#define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
should be loaded by the bootstrap
loader. */
/* If an ABI change is made within a GCC release series, rendering current
binaries incompatible with the old runtimes, this number must be set to
enforce the compatibility rules. */
#define MINOR_BINARYCOMPAT_ABI_VERSION 1
/* The runtime may recognize a variety of BC ABIs (objects generated by
different version of gcj), but will probably always require strict
matching for the ordinary (C++) ABI. */
/* The version ID of the BC ABI that we generate. This must be kept in
sync with parse_version(), libgcj, and reality (if the BC format changes,
this must change). */
#define GCJ_CURRENT_BC_ABI_VERSION \
(4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
/* The ABI version number. */
tree gcj_abi_version;
/* Name of the Cloneable class. */
tree java_lang_cloneable_identifier_node;
/* Name of the Serializable class. */
tree java_io_serializable_identifier_node;
/* The DECL_MAP is a mapping from (index, type) to a decl node.
If index < max_locals, it is the index of a local variable.
if index >= max_locals, then index-max_locals is a stack slot.
The DECL_MAP mapping is represented as a TREE_VEC whose elements
are a list of decls (VAR_DECL or PARM_DECL) chained by
DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
we search the chain for a decl with a matching TREE_TYPE. */
static GTY(()) tree decl_map;
/* The base_decl_map is contains one variable of ptr_type: this is
used to contain every variable of reference type that is ever
stored in a local variable slot. */
static GTY(()) tree base_decl_map;
/* An index used to make temporary identifiers unique. */
static int uniq;
/* A list of local variables VAR_DECLs for this method that we have seen
debug information, but we have not reached their starting (byte) PC yet. */
static GTY(()) tree pending_local_decls;
/* The decl for "_Jv_ResolvePoolEntry". */
tree soft_resolvepoolentry_node;
/* The decl for the .constants field of an instance of Class. */
tree constants_field_decl_node;
/* The decl for the .data field of an instance of Class. */
tree constants_data_field_decl_node;
#if defined(DEBUG_JAVA_BINDING_LEVELS)
int binding_depth = 0;
int is_class_level = 0;
int current_pc;
void
indent (void)
{
int i;
for (i = 0; i < binding_depth*2; i++)
putc (' ', stderr);
}
#endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
/* True if decl is a named local variable, i.e. if it is an alias
that's used only for debugging purposes. */
static bool
debug_variable_p (tree decl)
{
if (TREE_CODE (decl) == PARM_DECL)
return false;
if (LOCAL_SLOT_P (decl))
return false;
return true;
}
static tree
push_jvm_slot (int index, tree decl)
{
DECL_CONTEXT (decl) = current_function_decl;
layout_decl (decl, 0);
/* Now link the decl into the decl_map. */
if (DECL_LANG_SPECIFIC (decl) == NULL)
{
MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
DECL_LOCAL_START_PC (decl) = 0;
DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
DECL_LOCAL_SLOT_NUMBER (decl) = index;
}
DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
TREE_VEC_ELT (decl_map, index) = decl;
return decl;
}
/* Find the best declaration based upon type. If 'decl' fits 'type' better
than 'best', return 'decl'. Otherwise return 'best'. */
static tree
check_local_unnamed_variable (tree best, tree decl, tree type)
{
tree decl_type = TREE_TYPE (decl);
gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
/* Use the same decl for all integer types <= 32 bits. This is
necessary because sometimes a value is stored as (for example)
boolean but loaded as int. */
if (decl_type == type
|| (INTEGRAL_TYPE_P (decl_type)
&& INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (decl_type) <= 32
&& TYPE_PRECISION (type) <= 32
&& TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
/* ptr_type_node is used for null pointers, which are
assignment compatible with everything. */
|| (TREE_CODE (decl_type) == POINTER_TYPE
&& type == ptr_type_node)
/* Whenever anyone wants to use a slot that is initially
occupied by a PARM_DECL of pointer type they must get that
decl, even if they asked for a pointer to a different type.
However, if someone wants a scalar variable in a slot that
initially held a pointer arg -- or vice versa -- we create a
new VAR_DECL.
???: As long as verification is correct, this will be a
compatible type. But maybe we should create a dummy variable
and replace all references to it with the DECL and a
NOP_EXPR.
*/
|| (TREE_CODE (decl_type) == POINTER_TYPE
&& TREE_CODE (decl) == PARM_DECL
&& TREE_CODE (type) == POINTER_TYPE))
{
if (best == NULL_TREE
|| (decl_type == type && TREE_TYPE (best) != type))
return decl;
}
return best;
}
/* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
that is valid at PC (or -1 if any pc).
If there is no existing matching decl, allocate one. */
tree
find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
{
tree tmp = TREE_VEC_ELT (decl_map, index);
tree decl = NULL_TREE;
/* Scan through every declaration that has been created in this
slot. We're only looking for variables that correspond to local
index declarations and PARM_DECLs, not named variables: such
local variables are used only for debugging information. */
while (tmp != NULL_TREE)
{
if (! debug_variable_p (tmp))
decl = check_local_unnamed_variable (decl, tmp, type);
tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
}
/* gcj has a function called promote_type(), which is used by both
the bytecode compiler and the source compiler. Unfortunately,
the type systems for the Java VM and the Java language are not
the same: a boolean in the VM promotes to an int, not to a wide
boolean. If our caller wants something to hold a boolean, that
had better be an int, because that slot might be re-used
later in integer context. */
if (TREE_CODE (type) == BOOLEAN_TYPE)
type = integer_type_node;
/* If we don't find a match, create one with the type passed in.
The name of the variable is #n#m, which n is the variable index
in the local variable area and m is a dummy identifier for
uniqueness -- multiple variables may share the same local
variable index. We don't call pushdecl() to push pointer types
into a binding expr because they'll all be replaced by a single
variable that is used for every reference in that local variable
slot. */
if (! decl)
{
char buf[64];
tree name;
sprintf (buf, "#slot#%d#%d", index, uniq++);
name = get_identifier (buf);
decl = build_decl (input_location, VAR_DECL, name, type);
DECL_IGNORED_P (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
decl = push_jvm_slot (index, decl);
LOCAL_SLOT_P (decl) = 1;
if (TREE_CODE (type) != POINTER_TYPE)
pushdecl_function_level (decl);
}
/* As well as creating a local variable that matches the type, we
also create a base variable (of ptr_type) that will hold all its
aliases. */
if (TREE_CODE (type) == POINTER_TYPE
&& ! TREE_VEC_ELT (base_decl_map, index))
{
char buf[64];
tree name;
tree base_decl;
sprintf (buf, "#ref#%d#%d", index, uniq++);
name = get_identifier (buf);
base_decl
= TREE_VEC_ELT (base_decl_map, index)
= build_decl (input_location, VAR_DECL, name, ptr_type_node);
pushdecl_function_level (base_decl);
DECL_IGNORED_P (base_decl) = 1;
DECL_ARTIFICIAL (base_decl) = 1;
}
return decl;
}
/* Called during genericization for every variable. If the variable
is a temporary of pointer type, replace it with a common variable
thath is used to hold all pointer types that are ever stored in
that slot. Set WANT_LVALUE if you want a variable that is to be
written to. */
static tree
java_replace_reference (tree var_decl, bool want_lvalue)
{
tree decl_type;
if (! base_decl_map)
return var_decl;
decl_type = TREE_TYPE (var_decl);
if (TREE_CODE (decl_type) == POINTER_TYPE)
{
if (DECL_LANG_SPECIFIC (var_decl)
&& LOCAL_SLOT_P (var_decl))
{
int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
tree base_decl = TREE_VEC_ELT (base_decl_map, index);
gcc_assert (base_decl);
if (! want_lvalue)
base_decl = build1 (NOP_EXPR, decl_type, base_decl);
return base_decl;
}
}
return var_decl;
}
/* Helper for java_genericize. */
tree
java_replace_references (tree *tp, int *walk_subtrees,
void *data ATTRIBUTE_UNUSED)
{
if (TREE_CODE (*tp) == MODIFY_EXPR)
{
source_location loc = EXPR_LOCATION (*tp);
tree lhs = TREE_OPERAND (*tp, 0);
/* This is specific to the bytecode compiler. If a variable has
LOCAL_SLOT_P set, replace an assignment to it with an assignment
to the corresponding variable that holds all its aliases. */
if (TREE_CODE (lhs) == VAR_DECL
&& DECL_LANG_SPECIFIC (lhs)
&& LOCAL_SLOT_P (lhs)
&& TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
{
tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
TREE_OPERAND (*tp, 1));
tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
new_lhs, new_rhs);
*tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
SET_EXPR_LOCATION (tem, loc);
SET_EXPR_LOCATION (new_rhs, loc);
SET_EXPR_LOCATION (*tp, loc);
}
}
if (TREE_CODE (*tp) == VAR_DECL)
{
*tp = java_replace_reference (*tp, /* want_lvalue */ false);
*walk_subtrees = 0;
}
return NULL_TREE;
}
/* Same as find_local_index, except that INDEX is a stack index. */
tree
find_stack_slot (int index, tree type)
{
return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
type, -1);
}
struct GTY(())
binding_level {
/* A chain of _DECL nodes for all variables, constants, functions,
* and typedef types. These are in the reverse of the order supplied.
*/
tree names;
/* For each level, a list of shadowed outer-level local definitions
to be restored when this level is popped.
Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
tree shadowed;
/* For each level (except not the global one),
a chain of BLOCK nodes for all the levels
that were entered and exited one level down. */
tree blocks;
/* The binding level which this one is contained in (inherits from). */
struct binding_level *level_chain;
/* The bytecode PC that marks the end of this level. */
int end_pc;
/* The bytecode PC that marks the start of this level. */
int start_pc;
/* The statements in this binding level. */
tree stmts;
/* An exception range associated with this binding level. */
struct eh_range * GTY((skip (""))) exception_range;
/* Binding depth at which this level began. Used only for debugging. */
unsigned binding_depth;
/* The location at which this level began. */
source_location loc;
};
#define NULL_BINDING_LEVEL (struct binding_level *) NULL
/* The binding level currently in effect. */
static GTY(()) struct binding_level *current_binding_level;
/* A chain of binding_level structures awaiting reuse. */
static GTY(()) struct binding_level *free_binding_level;
/* The outermost binding level, for names of file scope.
This is created when the compiler is started and exists
through the entire run. */
static GTY(()) struct binding_level *global_binding_level;
/* The binding level that holds variables declared at the outermost
level within a function body. */
static struct binding_level *function_binding_level;
/* A PC value bigger than any PC value we may ever may encounter. */
#define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
/* Binding level structures are initialized by copying this one. */
static const struct binding_level clear_binding_level
= {
NULL_TREE, /* names */
NULL_TREE, /* shadowed */
NULL_TREE, /* blocks */
NULL_BINDING_LEVEL, /* level_chain */
LARGEST_PC, /* end_pc */
0, /* start_pc */
NULL, /* stmts */
NULL, /* exception_range */
0, /* binding_depth */
0, /* loc */
};
tree java_global_trees[JTI_MAX];
/* Build (and pushdecl) a "promoted type" for all standard
types shorter than int. */
static tree
push_promoted_type (const char *name, tree actual_type)
{
tree type = make_node (TREE_CODE (actual_type));
#if 1
tree in_min = TYPE_MIN_VALUE (int_type_node);
tree in_max = TYPE_MAX_VALUE (int_type_node);
#else
tree in_min = TYPE_MIN_VALUE (actual_type);
tree in_max = TYPE_MAX_VALUE (actual_type);
#endif
TYPE_MIN_VALUE (type) = copy_node (in_min);
TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
TYPE_MAX_VALUE (type) = copy_node (in_max);
TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
layout_type (type);
pushdecl (build_decl (input_location,
TYPE_DECL, get_identifier (name), type));
return type;
}
/* Return tree that represents a vtable for a primitive array. */
static tree
create_primitive_vtable (const char *name)
{
tree r;
char buf[50];
sprintf (buf, "_Jv_%sVTable", name);
r = build_decl (input_location,
VAR_DECL, get_identifier (buf), ptr_type_node);
DECL_EXTERNAL (r) = 1;
return r;
}
/* Parse the version string and compute the ABI version number. */
static void
parse_version (void)
{
const char *p = version_string;
unsigned int major = 0, minor = 0;
unsigned int abi_version;
/* Skip leading junk. */
while (*p && !ISDIGIT (*p))
++p;
gcc_assert (*p);
/* Extract major version. */
while (ISDIGIT (*p))
{
major = major * 10 + *p - '0';
++p;
}
gcc_assert (*p == '.' && ISDIGIT (p[1]));
++p;
/* Extract minor version. */
while (ISDIGIT (*p))
{
minor = minor * 10 + *p - '0';
++p;
}
if (flag_indirect_dispatch)
{
abi_version = GCJ_CURRENT_BC_ABI_VERSION;
abi_version |= FLAG_BINARYCOMPAT_ABI;
}
else /* C++ ABI */
{
/* Implicit in this computation is the idea that we won't break the
old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
4.0.1). */
abi_version = 100000 * major + 1000 * minor;
}
if (flag_bootstrap_classes)
abi_version |= FLAG_BOOTSTRAP_LOADER;
gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
}
void
java_init_decl_processing (void)
{
tree field = NULL_TREE;
tree t;
init_class_processing ();
current_function_decl = NULL;
current_binding_level = NULL_BINDING_LEVEL;
free_binding_level = NULL_BINDING_LEVEL;
pushlevel (0); /* make the binding_level structure for global names */
global_binding_level = current_binding_lev
10BC8
el;
/* Build common tree nodes, Java has an unsigned char. */
build_common_tree_nodes (false, false);
/* ??? Now we continue and override some of the built types again
with Java specific types. As the above generated types are
supposed to match the targets C ABI this isn't really the way
to go and any Java specifics should _not_ use those global types
if the Java ABI does not match the C one. */
byte_type_node = make_signed_type (8);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("byte"), byte_type_node));
short_type_node = make_signed_type (16);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("short"), short_type_node));
int_type_node = make_signed_type (32);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("int"), int_type_node));
long_type_node = make_signed_type (64);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("long"), long_type_node));
unsigned_byte_type_node = make_unsigned_type (8);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("unsigned byte"),
unsigned_byte_type_node));
unsigned_short_type_node = make_unsigned_type (16);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("unsigned short"),
unsigned_short_type_node));
unsigned_int_type_node = make_unsigned_type (32);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("unsigned int"),
unsigned_int_type_node));
unsigned_long_type_node = make_unsigned_type (64);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("unsigned long"),
unsigned_long_type_node));
/* Define these next since types below may used them. */
integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
integer_zero_node = build_int_cst (NULL_TREE, 0);
integer_one_node = build_int_cst (NULL_TREE, 1);
integer_two_node = build_int_cst (NULL_TREE, 2);
integer_three_node = build_int_cst (NULL_TREE, 3);
integer_four_node = build_int_cst (NULL_TREE, 4);
integer_minus_one_node = build_int_cst (NULL_TREE, -1);
/* A few values used for range checking in the lexer. */
decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
decimal_long_max
= double_int_to_tree (unsigned_long_type_node,
double_int_setbit (double_int_zero, 64));
long_zero_node = build_int_cst (long_type_node, 0);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("void"), void_type_node));
t = make_node (VOID_TYPE);
layout_type (t); /* Uses size_zero_node */
return_address_type_node = build_pointer_type (t);
char_type_node = make_unsigned_type (16);
TYPE_STRING_FLAG (char_type_node) = 1;
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("char"), char_type_node));
boolean_type_node = make_unsigned_type (1);
TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("boolean"),
boolean_type_node));
boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
promoted_byte_type_node
= push_promoted_type ("promoted_byte", byte_type_node);
promoted_short_type_node
= push_promoted_type ("promoted_short", short_type_node);
promoted_char_type_node
= push_promoted_type ("promoted_char", char_type_node);
promoted_boolean_type_node
= push_promoted_type ("promoted_boolean", boolean_type_node);
float_type_node = make_node (REAL_TYPE);
TYPE_PRECISION (float_type_node) = 32;
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("float"),
float_type_node));
layout_type (float_type_node);
double_type_node = make_node (REAL_TYPE);
TYPE_PRECISION (double_type_node) = 64;
pushdecl (build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("double"),
double_type_node));
layout_type (double_type_node);
float_zero_node = build_real (float_type_node, dconst0);
double_zero_node = build_real (double_type_node, dconst0);
/* These are the vtables for arrays of primitives. */
boolean_array_vtable = create_primitive_vtable ("boolean");
byte_array_vtable = create_primitive_vtable ("byte");
char_array_vtable = create_primitive_vtable ("char");
short_array_vtable = create_primitive_vtable ("short");
int_array_vtable = create_primitive_vtable ("int");
long_array_vtable = create_primitive_vtable ("long");
float_array_vtable = create_primitive_vtable ("float");
double_array_vtable = create_primitive_vtable ("double");
one_elt_array_domain_type = build_index_type (integer_one_node);
utf8const_type = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
utf8const_type, field, "hash", unsigned_short_type_node);
PUSH_FIELD (input_location,
utf8const_type, field, "length", unsigned_short_type_node);
FINISH_RECORD (utf8const_type);
utf8const_ptr_type = build_pointer_type (utf8const_type);
atable_type = build_array_type (ptr_type_node,
one_elt_array_domain_type);
TYPE_NONALIASED_COMPONENT (atable_type) = 1;
atable_ptr_type = build_pointer_type (atable_type);
itable_type = build_array_type (ptr_type_node,
one_elt_array_domain_type);
TYPE_NONALIASED_COMPONENT (itable_type) = 1;
itable_ptr_type = build_pointer_type (itable_type);
symbol_type = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
symbol_type, field, "clname", utf8const_ptr_type);
PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
PUSH_FIELD (input_location,
symbol_type, field, "signature", utf8const_ptr_type);
FINISH_RECORD (symbol_type);
symbols_array_type = build_array_type (symbol_type,
one_elt_array_domain_type);
symbols_array_ptr_type = build_pointer_type (symbols_array_type);
assertion_entry_type = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
assertion_entry_type, field, "assertion_code", integer_type_node);
PUSH_FIELD (input_location,
assertion_entry_type, field, "op1", utf8const_ptr_type);
PUSH_FIELD (input_location,
assertion_entry_type, field, "op2", utf8const_ptr_type);
FINISH_RECORD (assertion_entry_type);
assertion_table_type = build_array_type (assertion_entry_type,
one_elt_array_domain_type);
/* As you're adding items here, please update the code right after
this section, so that the filename containing the source code of
the pre-defined class gets registered correctly. */
unqualified_object_id_node = get_identifier ("Object");
object_type_node = lookup_class (get_identifier ("java.lang.Object"));
object_ptr_type_node = promote_type (object_type_node);
string_type_node = lookup_class (get_identifier ("java.lang.String"));
string_ptr_type_node = promote_type (string_type_node);
class_type_node = lookup_class (get_identifier ("java.lang.Class"));
throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
runtime_exception_type_node =
lookup_class (get_identifier ("java.lang.RuntimeException"));
error_exception_type_node =
lookup_class (get_identifier ("java.lang.Error"));
rawdata_ptr_type_node
= promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
add_predefined_file (get_identifier ("java/lang/Class.java"));
add_predefined_file (get_identifier ("java/lang/Error.java"));
add_predefined_file (get_identifier ("java/lang/Object.java"));
add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
add_predefined_file (get_identifier ("java/lang/String.java"));
add_predefined_file (get_identifier ("java/lang/Throwable.java"));
add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
add_predefined_file (get_identifier ("java/lang/Exception.java"));
add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
methodtable_type = make_node (RECORD_TYPE);
layout_type (methodtable_type);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
methodtable_ptr_type = build_pointer_type (methodtable_type);
TYPE_identifier_node = get_identifier ("TYPE");
init_identifier_node = get_identifier ("<init>");
clinit_identifier_node = get_identifier ("<clinit>");
void_signature_node = get_identifier ("()V");
finalize_identifier_node = get_identifier ("finalize");
this_identifier_node = get_identifier ("this");
java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
java_io_serializable_identifier_node =
get_identifier ("java.io.Serializable");
/* for lack of a better place to put this stub call */
init_expr_processing();
constants_type_node = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
constants_type_node, field, "size", unsigned_int_type_node);
PUSH_FIELD (input_location,
constants_type_node, field, "tags", ptr_type_node);
PUSH_FIELD (input_location,
constants_type_node, field, "data", ptr_type_node);
constants_data_field_decl_node = field;
FINISH_RECORD (constants_type_node);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("constants"), constants_type_node);
access_flags_type_node = unsigned_short_type_node;
dtable_type = make_node (RECORD_TYPE);
dtable_ptr_type = build_pointer_type (dtable_type);
otable_type = build_array_type (integer_type_node,
one_elt_array_domain_type);
TYPE_NONALIASED_COMPONENT (otable_type) = 1;
otable_ptr_type = build_pointer_type (otable_type);
PUSH_FIELD (input_location,
object_type_node, field, "vtable", dtable_ptr_type);
DECL_FCONTEXT (field) = object_type_node;
TYPE_VFIELD (object_type_node) = field;
/* This isn't exactly true, but it is what we have in the source.
There is an unresolved issue here, which is whether the vtable
should be marked by the GC. */
if (! flag_hash_synchronization)
PUSH_FIELD (input_location, object_type_node, field, "sync_info",
build_pointer_type (object_type_node));
for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
FIELD_PRIVATE (t) = 1;
FINISH_RECORD (object_type_node);
field_type_node = make_node (RECORD_TYPE);
field_ptr_type_node = build_pointer_type (field_type_node);
method_type_node = make_node (RECORD_TYPE);
method_ptr_type_node = build_pointer_type (method_type_node);
set_super_info (0, class_type_node, object_type_node, 0);
set_super_info (0, string_type_node, object_type_node, 0);
class_ptr_type = build_pointer_type (class_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "next_or_version", class_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "name", utf8const_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "accflags", access_flags_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "superclass", class_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "constants", constants_type_node);
constants_field_decl_node = field;
PUSH_FIELD (input_location,
class_type_node, field, "methods", method_ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "method_count", short_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "vtable_method_count", short_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "fields", field_ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "size_in_bytes", int_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "field_count", short_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "static_field_count", short_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "vtable", dtable_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "otable", otable_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "otable_syms",
symbols_array_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "atable", atable_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "atable_syms",
symbols_array_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "itable", itable_ptr_type);
PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
symbols_array_ptr_type);
PUSH_FIELD (input_location,
class_type_node, field, "catch_classes", ptr_type_node);
PUSH_FIELD (input_location, class_type_node, field, "interfaces",
build_pointer_type (class_ptr_type));
PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "interface_count", short_type_node);
PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "depth", short_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "ancestors", ptr_type_node);
PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "arrayclass", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "protectionDomain", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "assertion_table", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "hack_signers", ptr_type_node);
PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "aux_info", ptr_type_node);
PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
PUSH_FIELD (input_location,
class_type_node, field, "reflection_data", ptr_type_node);
for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
FIELD_PRIVATE (t) = 1;
push_super_field (class_type_node, object_type_node);
FINISH_RECORD (class_type_node);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("Class"), class_type_node);
field_info_union_node = make_node (UNION_TYPE);
PUSH_FIELD (input_location,
field_info_union_node, field, "boffset", int_type_node);
PUSH_FIELD (input_location,
field_info_union_node, field, "addr", ptr_type_node);
layout_type (field_info_union_node);
PUSH_FIELD (input_location,
field_type_node, field, "name", utf8const_ptr_type);
PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
PUSH_FIELD (input_location,
field_type_node, field, "accflags", access_flags_type_node);
PUSH_FIELD (input_location,
field_type_node, field, "bsize", unsigned_short_type_node);
PUSH_FIELD (input_location,
field_type_node, field, "info", field_info_union_node);
FINISH_RECORD (field_type_node);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("Field"), field_type_node);
nativecode_ptr_array_type_node
= build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
PUSH_FIELD (input_location,
dtable_type, field, "class", class_ptr_type);
PUSH_FIELD (input_location,
dtable_type, field, "methods", nativecode_ptr_array_type_node);
FINISH_RECORD (dtable_type);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
jexception_type = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
jexception_type, field, "start_pc", ptr_type_node);
PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
PUSH_FIELD (input_location,
jexception_type, field, "handler_pc", ptr_type_node);
PUSH_FIELD (input_location,
jexception_type, field, "catch_type", class_ptr_type);
FINISH_RECORD (jexception_type);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("jexception"), field_type_node);
jexception_ptr_type = build_pointer_type (jexception_type);
lineNumberEntry_type = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
PUSH_FIELD (input_location,
lineNumberEntry_type, field, "start_pc", ptr_type_node);
FINISH_RECORD (lineNumberEntry_type);
lineNumbers_type = make_node (RECORD_TYPE);
PUSH_FIELD (input_location,
lineNumbers_type, field, "length", unsigned_int_type_node);
FINISH_RECORD (lineNumbers_type);
PUSH_FIELD (input_location,
method_type_node, field, "name", utf8const_ptr_type);
PUSH_FIELD (input_location,
method_type_node, field, "signature", utf8const_ptr_type);
PUSH_FIELD (input_location,
method_type_node, field, "accflags", access_flags_type_node);
PUSH_FIELD (input_location,
method_type_node, field, "index", unsigned_short_type_node);
PUSH_FIELD (input_location,
method_type_node, field, "ncode", nativecode_ptr_type_node);
PUSH_FIELD (input_location,
method_type_node, field, "throws", ptr_type_node);
FINISH_RECORD (method_type_node);
build_decl (BUILTINS_LOCATION,
TYPE_DECL, get_identifier ("Method"), method_type_node);
end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE);
alloc_object_node = add_builtin_function ("_Jv_AllocObject", t,
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (alloc_object_node) = 1;
alloc_no_finalizer_node =
add_builtin_function ("_Jv_AllocObjectNoFinalizer", t,
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
soft_initclass_node = add_builtin_function ("_Jv_InitClass", t,
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = build_function_type_list (ptr_type_node,
class_ptr_type, int_type_node, NULL_TREE);
soft_resolvepoolentry_node
= add_builtin_function ("_Jv_ResolvePoolEntry", t,
0,NOT_BUILT_IN, NULL, NULL_TREE);
DECL_PURE_P (soft_resolvepoolentry_node) = 1;
t = build_function_type_list (void_type_node,
class_ptr_type, int_type_node, NULL_TREE);
throw_node = add_builtin_function ("_Jv_Throw", t,
0, NOT_BUILT_IN, NULL, NULL_TREE);
/* Mark throw_nodes as `noreturn' functions with side effects. */
TREE_THIS_VOLATILE (throw_node) = 1;
TREE_SIDE_EFFECTS (throw_node) = 1;
t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
soft_monitorenter_node
= add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
NULL, NULL_TREE);