1 /* src/vm/jit/verify/typeinfo.c - type system used by the type checker
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Edwin Steiner
29 $Id: typeinfo.c 2750 2005-06-20 15:11:47Z edwin $
36 #include "mm/memory.h"
37 #include "toolbox/logging.h"
39 #include "vm/loader.h"
40 #include "vm/tables.h"
41 #include "vm/jit/jit.h"
42 #include "vm/jit/verify/typeinfo.h"
43 #include "vm/descriptor.h"
44 #include "vm/resolve.h"
47 /* check if a linked class is an array class. Only use for linked classes! */
48 #define CLASSINFO_IS_ARRAY(clsinfo) ((clsinfo)->vftbl->arraydesc != NULL)
50 #define CLASSINFO_IMPLEMENTS_INTERFACE(cls,index) \
51 ( ((index) < (cls)->vftbl->interfacetablelength) \
52 && (VFTBLINTERFACETABLE((cls)->vftbl,(index)) != NULL) )
54 /******************************************************************************/
56 /******************************************************************************/
59 #define TYPEINFO_ASSERT(cond) assert(cond)
61 #define TYPEINFO_ASSERT(cond)
64 /**********************************************************************/
65 /* TYPEVECTOR FUNCTIONS */
66 /**********************************************************************/
69 typevectorset_copy(typevector *src,int k,int size)
71 typevector *dst = DNEW_TYPEVECTOR(size);
73 memcpy(dst,src,TYPEVECTOR_SIZE(size));
76 dst->alt = typevectorset_copy(src->alt,k+1,size);
81 typevectorset_checktype(typevector *vec,int index,int type)
84 if (vec->td[index].type != type)
86 } while ((vec = vec->alt) != NULL);
91 typevectorset_checkreference(typevector *vec,int index)
94 if (!TYPEDESC_IS_REFERENCE(vec->td[index]))
96 } while ((vec = vec->alt) != NULL);
101 typevectorset_checkretaddr(typevector *vec,int index)
104 if (!TYPEDESC_IS_RETURNADDRESS(vec->td[index]))
106 } while ((vec = vec->alt) != NULL);
111 typevectorset_copymergedtype(typevector *vec,int index,typeinfo *dst)
116 td = vec->td + index;
118 TYPEINFO_COPY(td->info,*dst);
123 primitive = TYPEINFO_IS_PRIMITIVE(*dst) ? 1 : 0;
125 while ((vec = vec->alt) != NULL) {
126 td = vec->td + index;
127 if (type != td->type)
130 if (type == TYPE_ADDRESS) {
131 if ((TYPEINFO_IS_PRIMITIVE(td->info) ? 1 : 0) != primitive)
133 typeinfo_merge(dst,&(td->info));
141 typevectorset_mergedtype(typevector *vec,int index,typeinfo *temp,typeinfo **result)
145 return typevectorset_copymergedtype(vec,index,temp);
148 *result = &(vec->td[index].info);
149 return vec->td[index].type;
153 typevectorset_mergedtypeinfo(typevector *vec,int index,typeinfo *temp)
156 int type = typevectorset_mergedtype(vec,index,temp,&result);
157 return (type == TYPE_ADDRESS) ? result : NULL;
161 typevectorset_store(typevector *vec,int index,int type,typeinfo *info)
164 vec->td[index].type = type;
166 TYPEINFO_COPY(*info,vec->td[index].info);
167 if (index > 0 && IS_2_WORD_TYPE(vec->td[index-1].type))
168 vec->td[index-1].type = TYPE_VOID;
169 } while ((vec = vec->alt) != NULL);
173 typevectorset_store_retaddr(typevector *vec,int index,typeinfo *info)
175 typeinfo_retaddr_set *adr;
177 adr = (typeinfo_retaddr_set*) TYPEINFO_RETURNADDRESS(*info);
179 vec->td[index].type = TYPE_ADDRESS;
180 TYPEINFO_INIT_RETURNADDRESS(vec->td[index].info,adr->addr);
181 if (index > 0 && IS_2_WORD_TYPE(vec->td[index-1].type))
182 vec->td[index-1].type = TYPE_VOID;
184 } while ((vec = vec->alt) != NULL);
188 typevectorset_store_twoword(typevector *vec,int index,int type)
191 vec->td[index].type = type;
192 vec->td[index+1].type = TYPE_VOID;
193 if (index > 0 && IS_2_WORD_TYPE(vec->td[index-1].type))
194 vec->td[index-1].type = TYPE_VOID;
195 } while ((vec = vec->alt) != NULL);
199 typevectorset_init_object(typevector *set,void *ins,
200 classref_or_classinfo initclass,
205 for (;set; set=set->alt) {
206 for (i=0; i<size; ++i) {
207 if (set->td[i].type == TYPE_ADR
208 && TYPEINFO_IS_NEWOBJECT(set->td[i].info)
209 && TYPEINFO_NEWOBJECT_INSTRUCTION(set->td[i].info) == ins)
211 TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(set->td[i].info,initclass);
218 typevector_merge(typevector *dst,typevector *y,int size)
220 bool changed = false;
222 typedescriptor *a = dst->td;
223 typedescriptor *b = y->td;
225 if (a->type != TYPE_VOID && a->type != b->type) {
229 else if (a->type == TYPE_ADDRESS) {
230 if (TYPEINFO_IS_PRIMITIVE(a->info)) {
231 /* 'a' is a returnAddress */
232 if (!TYPEINFO_IS_PRIMITIVE(b->info)
233 || (TYPEINFO_RETURNADDRESS(a->info)
234 != TYPEINFO_RETURNADDRESS(b->info)))
241 /* 'a' is a reference */
242 if (TYPEINFO_IS_PRIMITIVE(b->info)) {
247 changed |= typeinfo_merge(&(a->info),&(b->info));
258 typevector_separable_from(typevector *a,typevector *b,int size)
260 typedescriptor *tda = a->td;
261 typedescriptor *tdb = b->td;
262 for (;size--; tda++,tdb++) {
263 if (TYPEDESC_IS_RETURNADDRESS(*tda)
264 && TYPEDESC_IS_RETURNADDRESS(*tdb)
265 && TYPEINFO_RETURNADDRESS(tda->info)
266 != TYPEINFO_RETURNADDRESS(tdb->info))
273 typevectorset_add(typevector *dst,typevector *v,int size)
277 dst->alt = DNEW_TYPEVECTOR(size);
278 memcpy(dst->alt,v,TYPEVECTOR_SIZE(size));
279 dst->alt->alt = NULL;
280 dst->alt->k = dst->k + 1;
284 typevectorset_select(typevector **set,int retindex,void *retaddr)
286 typevector *selected;
288 if (!*set) return NULL;
290 if (TYPEINFO_RETURNADDRESS((*set)->td[retindex].info) == retaddr) {
292 *set = selected->alt;
293 selected->alt = typevectorset_select(set,retindex,retaddr);
296 selected = typevectorset_select(&((*set)->alt),retindex,retaddr);
302 typevectorset_separable_with(typevector *set,typevector *add,int size)
309 for (i=0; i<size; ++i) {
310 if (!TYPEDESC_IS_RETURNADDRESS(add->td[i]))
312 addr = TYPEINFO_RETURNADDRESS(add->td[i].info);
317 if (!TYPEDESC_IS_RETURNADDRESS(v->td[i]))
319 if (TYPEINFO_RETURNADDRESS(v->td[i].info) != addr)
322 if (!v && separable) return true;
331 typevectorset_collapse(typevector *dst,int size)
333 bool changed = false;
336 typevector_merge(dst,dst->alt,size);
337 dst->alt = dst->alt->alt;
343 /**********************************************************************/
344 /* READ-ONLY FUNCTIONS */
345 /* The following functions don't change typeinfo data. */
346 /**********************************************************************/
349 typeinfo_is_array(typeinfo *info)
351 TYPEINFO_ASSERT(info);
352 return TYPEINFO_IS_ARRAY(*info);
356 typeinfo_is_primitive_array(typeinfo *info,int arraytype)
358 TYPEINFO_ASSERT(info);
359 return TYPEINFO_IS_PRIMITIVE_ARRAY(*info,arraytype);
363 typeinfo_is_array_of_refs(typeinfo *info)
365 TYPEINFO_ASSERT(info);
366 return TYPEINFO_IS_ARRAY_OF_REFS(*info);
370 interface_extends_interface(classinfo *cls,classinfo *interf)
374 TYPEINFO_ASSERT(cls);
375 TYPEINFO_ASSERT(interf);
376 TYPEINFO_ASSERT((interf->flags & ACC_INTERFACE) != 0);
377 TYPEINFO_ASSERT((cls->flags & ACC_INTERFACE) != 0);
378 TYPEINFO_ASSERT(cls->linked);
380 /* first check direct superinterfaces */
381 for (i=0; i<cls->interfacescount; ++i) {
382 if (cls->interfaces[i].cls == interf)
386 /* check indirect superinterfaces */
387 for (i=0; i<cls->interfacescount; ++i) {
388 if (interface_extends_interface(cls->interfaces[i].cls,interf))
396 classinfo_implements_interface(classinfo *cls,classinfo *interf)
398 TYPEINFO_ASSERT(cls);
399 TYPEINFO_ASSERT(interf);
400 TYPEINFO_ASSERT((interf->flags & ACC_INTERFACE) != 0);
403 if (!link_class(cls)) /* XXX */
406 if (cls->flags & ACC_INTERFACE) {
407 /* cls is an interface */
411 /* check superinterfaces */
412 return interface_extends_interface(cls,interf);
415 return CLASSINFO_IMPLEMENTS_INTERFACE(cls,interf->index);
419 mergedlist_implements_interface(typeinfo_mergedlist *merged,
423 classref_or_classinfo *mlist;
425 TYPEINFO_ASSERT(interf);
426 TYPEINFO_ASSERT((interf->flags & ACC_INTERFACE) != 0);
428 /* Check if there is an non-empty mergedlist. */
432 /* If all classinfos in the (non-empty) merged array implement the
433 * interface return true, otherwise false.
435 mlist = merged->list;
438 if (IS_CLASSREF(*mlist)) {
441 if (!classinfo_implements_interface((mlist++)->cls,interf))
448 merged_implements_interface(classinfo *typeclass,typeinfo_mergedlist *merged,
451 /* primitive types don't support interfaces. */
455 /* the null type can be cast to any interface type. */
456 if (typeclass == pseudo_class_Null)
459 /* check if typeclass implements the interface. */
460 if (classinfo_implements_interface(typeclass,interf))
463 /* check the mergedlist */
464 return (merged && mergedlist_implements_interface(merged,interf));
468 typeinfo_is_assignable(typeinfo *value,typeinfo *dest)
470 TYPEINFO_ASSERT(value);
471 TYPEINFO_ASSERT(dest);
472 TYPEINFO_ASSERT(dest->merged == NULL);
474 return typeinfo_is_assignable_to_class(value,dest->typeclass);
478 typeinfo_is_assignable_to_class(typeinfo *value,classref_or_classinfo dest)
480 classref_or_classinfo c;
484 TYPEINFO_ASSERT(value);
486 c = value->typeclass;
488 /* assignments of primitive values are not checked here. */
489 if (!c.any && !dest.any)
492 /* primitive and reference types are not assignment compatible. */
493 if (!c.any || !dest.any)
496 /* the null type can be assigned to any type */
497 if (TYPEINFO_IS_NULLTYPE(*value))
500 /* uninitialized objects are not assignable */
501 if (TYPEINFO_IS_NEWOBJECT(*value))
504 if (IS_CLASSREF(c)) {
505 /* The value type is an unresolved class reference. */
506 classname = c.ref->name;
509 classname = c.cls->name;
512 if (IS_CLASSREF(dest)) {
513 /* the destination type is an unresolved class reference */
514 /* In this case we cannot tell a lot about assignability. */
516 /* the common case of value and dest type having the same classname */
517 if (dest.ref->name == classname && !value->merged)
520 /* we cannot tell if value is assignable to dest, so we */
521 /* leave it up to the resolving code to check this */
525 /* { we know that dest is a loaded class } */
527 if (IS_CLASSREF(c)) {
528 /* the value type is an unresolved class reference */
530 /* the common case of value and dest type having the same classname */
531 if (dest.cls->name == classname)
534 /* we cannot tell if value is assignable to dest, so we */
535 /* leave it up to the resolving code to check this */
539 /* { we know that both c and dest are loaded classes } */
541 TYPEINFO_ASSERT(!IS_CLASSREF(c));
542 TYPEINFO_ASSERT(!IS_CLASSREF(dest));
546 TYPEINFO_ASSERT(cls->loaded);
547 TYPEINFO_ASSERT(dest.cls->loaded);
549 /* maybe we need to link the classes */
551 link_class(cls); /* XXX */
552 if (!dest.cls->linked)
553 link_class(dest.cls); /* XXX */
555 /* { we know that both c and dest are linked classes } */
556 TYPEINFO_ASSERT(cls->linked);
557 TYPEINFO_ASSERT(dest.cls->linked);
559 if (dest.cls->flags & ACC_INTERFACE) {
560 /* We are assigning to an interface type. */
561 return merged_implements_interface(cls,value->merged,dest.cls);
564 if (CLASSINFO_IS_ARRAY(dest.cls)) {
565 arraydescriptor *arraydesc = dest.cls->vftbl->arraydesc;
566 int dimension = arraydesc->dimension;
567 classinfo *elementclass = (arraydesc->elementvftbl)
568 ? arraydesc->elementvftbl->class : NULL;
570 /* We are assigning to an array type. */
571 if (!TYPEINFO_IS_ARRAY(*value))
574 /* {Both value and dest.cls are array types.} */
576 /* value must have at least the dimension of dest.cls. */
577 if (value->dimension < dimension)
580 if (value->dimension > dimension) {
581 /* value has higher dimension so we need to check
582 * if its component array can be assigned to the
583 * element type of dest.cls */
585 if (!elementclass) return false;
587 if (elementclass->flags & ACC_INTERFACE) {
588 /* We are assigning to an interface type. */
589 return classinfo_implements_interface(pseudo_class_Arraystub,
593 /* We are assigning to a class type. */
594 return class_issubclass(pseudo_class_Arraystub,elementclass);
597 /* {value and dest.cls have the same dimension} */
599 if (value->elementtype != arraydesc->elementtype)
602 if (value->elementclass.any) {
603 /* We are assigning an array of objects so we have to
604 * check if the elements are assignable.
607 if (elementclass->flags & ACC_INTERFACE) {
608 /* We are assigning to an interface type. */
610 return merged_implements_interface(value->elementclass.cls,
615 /* We are assigning to a class type. */
616 return class_issubclass(value->elementclass.cls,elementclass);
622 /* {dest.cls is not an array} */
623 /* {dest.cls is a loaded class} */
625 /* If there are any unresolved references in the merged list, we cannot */
626 /* tell if the assignment will be ok. */
627 /* This can only happen when cls is java.lang.Object */
628 if (cls == class_java_lang_Object && value->merged) {
629 classref_or_classinfo *mlist = value->merged->list;
630 int i = value->merged->count;
632 if (IS_CLASSREF(*mlist++))
636 /* We are assigning to a class type */
637 if (cls->flags & ACC_INTERFACE)
638 cls = class_java_lang_Object;
640 return class_issubclass(cls,dest.cls);
643 /**********************************************************************/
644 /* INITIALIZATION FUNCTIONS */
645 /* The following functions fill in uninitialized typeinfo structures. */
646 /**********************************************************************/
649 typeinfo_init_class(typeinfo *info,classref_or_classinfo c)
655 TYPEINFO_ASSERT(c.any);
656 TYPEINFO_ASSERT(info);
658 /* if necessary, try to resolve lazily */
659 if (!resolve_classref_or_classinfo(NULL /* XXX should now method */,
660 c,resolveLazy,true,&cls))
662 log_text("XXX could not resolve class reference"); /* XXX */
668 TYPEINFO_INIT_CLASSINFO(*info,cls);
672 /* {the type could no be resolved lazily} */
674 info->typeclass.ref = c.ref;
675 info->elementclass.any = NULL;
679 /* handle array type references */
680 utf_ptr = c.ref->name->text;
681 len = c.ref->name->blength;
682 if (*utf_ptr == '[') {
683 /* count dimensions */
684 while (*utf_ptr == '[') {
689 if (*utf_ptr == 'L') {
692 info->elementtype = ARRAYTYPE_OBJECT;
693 info->elementclass.ref = class_get_classref(c.ref->referer,utf_new(utf_ptr,len));
696 /* an array with primitive element type */
697 /* should have been resolved above */
698 TYPEINFO_ASSERT(false);
705 typeinfo_init_from_typedesc(typedesc *desc,u1 *type,typeinfo *info)
707 TYPEINFO_ASSERT(desc);
709 #ifdef TYPEINFO_VERBOSE
710 fprintf(stderr,"typeinfo_init_from_typedesc(");
711 descriptor_debug_print_typedesc(stderr,desc);
712 fprintf(stderr,")\n");
719 if (desc->type == TYPE_ADR) {
720 TYPEINFO_ASSERT(desc->classref);
721 TYPEINFO_INIT_CLASSREF(*info,desc->classref);
724 TYPEINFO_INIT_PRIMITIVE(*info);
730 typeinfo_init_from_methoddesc(methoddesc *desc,u1 *typebuf,typeinfo *infobuf,
731 int buflen,bool twoword,
732 u1 *returntype,typeinfo *returntypeinfo)
737 TYPEINFO_ASSERT(desc);
738 TYPEINFO_ASSERT(typebuf);
739 TYPEINFO_ASSERT(infobuf);
741 #ifdef TYPEINFO_VERBOSE
742 fprintf(stderr,"typeinfo_init_from_methoddesc(");
743 descriptor_debug_print_methoddesc(stderr,desc);
744 fprintf(stderr,")\n");
747 /* check arguments */
748 for (i=0; i<desc->paramcount; ++i) {
749 if (++args > buflen) {
750 log_text("Buffer too small for method arguments."); /* XXX */
754 typeinfo_init_from_typedesc(desc->paramtypes + i,typebuf++,infobuf++);
756 if (twoword && (typebuf[-1] == TYPE_LONG || typebuf[-1] == TYPE_DOUBLE)) {
757 if (++args > buflen) {
758 log_text("Buffer too small for method arguments."); /* XXX */
762 *typebuf++ = TYPE_VOID;
763 TYPEINFO_INIT_PRIMITIVE(*infobuf);
768 /* check returntype */
770 typeinfo_init_from_typedesc(&(desc->returntype),returntype,returntypeinfo);
775 typedescriptor_init_from_typedesc(typedescriptor *td,
778 td->type = desc->type;
779 if (td->type == TYPE_ADR) {
780 TYPEINFO_INIT_CLASSREF(td->info,desc->classref);
783 TYPEINFO_INIT_PRIMITIVE(td->info);
788 typedescriptors_init_from_methoddesc(typedescriptor *td,
790 int buflen,bool twoword,int startindex,
791 typedescriptor *returntype)
796 /* check arguments */
797 for (i=startindex; i<desc->paramcount; ++i) {
798 if (++args > buflen) {
799 log_text("Buffer too small for method arguments."); /* XXX */
803 typedescriptor_init_from_typedesc(td,desc->paramtypes + i);
806 if (twoword && (td[-1].type == TYPE_LONG || td[-1].type == TYPE_DOUBLE)) {
807 if (++args > buflen) {
808 log_text("Buffer too small for method arguments."); /* XXX */
812 td->type = TYPE_VOID;
813 TYPEINFO_INIT_PRIMITIVE(td->info);
818 /* check returntype */
820 typedescriptor_init_from_typedesc(returntype,&(desc->returntype));
827 typeinfo_init_component(typeinfo *srcarray,typeinfo *dst)
829 if (TYPEINFO_IS_NULLTYPE(*srcarray)) {
830 TYPEINFO_INIT_NULLTYPE(*dst);
834 if (!TYPEINFO_IS_ARRAY(*srcarray)) {
835 log_text("Trying to access component of non-array"); /* XXX throw exception */
839 if (IS_CLASSREF(srcarray->typeclass)) {
840 constant_classref *comp;
841 comp = class_get_classref_component_of(srcarray->typeclass.ref);
844 TYPEINFO_INIT_CLASSREF(*dst,comp);
846 TYPEINFO_INIT_PRIMITIVE(*dst);
851 if (!srcarray->typeclass.cls->linked) {
852 if (!link_class(srcarray->typeclass.cls)) {
853 log_text("XXX could not link class");
858 TYPEINFO_ASSERT(srcarray->typeclass.cls->vftbl);
859 TYPEINFO_ASSERT(srcarray->typeclass.cls->vftbl->arraydesc);
861 comp = srcarray->typeclass.cls->vftbl->arraydesc->componentvftbl;
863 TYPEINFO_INIT_CLASSINFO(*dst,comp->class);
865 TYPEINFO_INIT_PRIMITIVE(*dst);
868 dst->merged = srcarray->merged; /* XXX should we do a deep copy? */
872 typeinfo_clone(typeinfo *src,typeinfo *dest)
875 classref_or_classinfo *srclist,*destlist;
883 count = src->merged->count;
884 TYPEINFO_ALLOCMERGED(dest->merged,count);
885 dest->merged->count = count;
887 srclist = src->merged->list;
888 destlist = dest->merged->list;
890 *destlist++ = *srclist++;
894 /**********************************************************************/
895 /* MISCELLANEOUS FUNCTIONS */
896 /**********************************************************************/
899 typeinfo_free(typeinfo *info)
901 TYPEINFO_FREEMERGED_IF_ANY(info->merged);
905 /**********************************************************************/
906 /* MERGING FUNCTIONS */
907 /* The following functions are used to merge the types represented by */
908 /* two typeinfo structures into one typeinfo structure. */
909 /**********************************************************************/
913 typeinfo_merge_error(char *str,typeinfo *x,typeinfo *y) {
914 #ifdef TYPEINFO_VERBOSE
915 fprintf(stderr,"Error in typeinfo_merge: %s\n",str);
916 fprintf(stderr,"Typeinfo x:\n");
917 typeinfo_print(stderr,x,1);
918 fprintf(stderr,"Typeinfo y:\n");
919 typeinfo_print(stderr,y,1);
922 log_text(str); /* XXX throw an exception */
926 /* Condition: clsx != clsy. */
927 /* Returns: true if dest was changed (currently always true). */
930 typeinfo_merge_two(typeinfo *dest,classref_or_classinfo clsx,classref_or_classinfo clsy)
932 TYPEINFO_ASSERT(dest);
933 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
934 TYPEINFO_ALLOCMERGED(dest->merged,2);
935 dest->merged->count = 2;
937 TYPEINFO_ASSERT(clsx.any != clsy.any);
939 if (clsx.any < clsy.any) {
940 dest->merged->list[0] = clsx;
941 dest->merged->list[1] = clsy;
944 dest->merged->list[0] = clsy;
945 dest->merged->list[1] = clsx;
951 /* Returns: true if dest was changed. */
954 typeinfo_merge_add(typeinfo *dest,typeinfo_mergedlist *m,classref_or_classinfo cls)
957 typeinfo_mergedlist *newmerged;
958 classref_or_classinfo *mlist,*newlist;
963 /* Check if cls is already in the mergedlist m. */
965 if ((mlist++)->any == cls.any) { /* XXX check equal classrefs? */
966 /* cls is in the list, so m is the resulting mergedlist */
967 if (dest->merged == m)
970 /* We have to copy the mergedlist */
971 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
973 TYPEINFO_ALLOCMERGED(dest->merged,count);
974 dest->merged->count = count;
975 newlist = dest->merged->list;
978 *newlist++ = *mlist++;
984 /* Add cls to the mergedlist. */
986 TYPEINFO_ALLOCMERGED(newmerged,count+1);
987 newmerged->count = count+1;
988 newlist = newmerged->list;
991 if (mlist->any > cls.any)
993 *newlist++ = *mlist++;
998 *newlist++ = *mlist++;
1001 /* Put the new mergedlist into dest. */
1002 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
1003 dest->merged = newmerged;
1008 /* Returns: true if dest was changed. */
1011 typeinfo_merge_mergedlists(typeinfo *dest,typeinfo_mergedlist *x,
1012 typeinfo_mergedlist *y)
1016 typeinfo_mergedlist *temp,*result;
1017 classref_or_classinfo *clsx,*clsy,*newlist;
1019 /* count the elements that will be in the resulting list */
1020 /* (Both lists are sorted, equal elements are counted only once.) */
1025 while (countx && county) {
1026 if (clsx->any == clsy->any) {
1032 else if (clsx->any < clsy->any) {
1042 count += countx + county;
1044 /* {The new mergedlist will have count entries.} */
1046 if ((x->count != count) && (y->count == count)) {
1047 temp = x; x = y; y = temp;
1049 /* {If one of x,y is already the result it is x.} */
1050 if (x->count == count) {
1051 /* x->merged is equal to the result */
1052 if (x == dest->merged)
1055 if (!dest->merged || dest->merged->count != count) {
1056 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
1057 TYPEINFO_ALLOCMERGED(dest->merged,count);
1058 dest->merged->count = count;
1061 newlist = dest->merged->list;
1064 *newlist++ = *clsx++;
1069 /* {We have to merge two lists.} */
1071 /* allocate the result list */
1072 TYPEINFO_ALLOCMERGED(result,count);
1073 result->count = count;
1074 newlist = result->list;
1076 /* merge the sorted lists */
1081 while (countx && county) {
1082 if (clsx->any == clsy->any) {
1083 *newlist++ = *clsx++;
1088 else if (clsx->any < clsy->any) {
1089 *newlist++ = *clsx++;
1093 *newlist++ = *clsy++;
1098 *newlist++ = *clsx++;
1100 *newlist++ = *clsy++;
1102 /* replace the list in dest with the result list */
1103 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
1104 dest->merged = result;
1111 typeinfo_merge_nonarrays(typeinfo *dest,
1112 classref_or_classinfo *result,
1113 classref_or_classinfo x,classref_or_classinfo y,
1114 typeinfo_mergedlist *mergedx,
1115 typeinfo_mergedlist *mergedy)
1117 classref_or_classinfo t;
1118 classinfo *tcls,*common;
1119 typeinfo_mergedlist *tmerged;
1124 TYPEINFO_ASSERT(dest && result && x.any && y.any);
1125 TYPEINFO_ASSERT(x.cls != pseudo_class_Null);
1126 TYPEINFO_ASSERT(y.cls != pseudo_class_Null);
1127 TYPEINFO_ASSERT(x.cls != pseudo_class_New);
1128 TYPEINFO_ASSERT(y.cls != pseudo_class_New);
1130 /*--------------------------------------------------*/
1132 /*--------------------------------------------------*/
1134 /* Common case 1: x and y are the same class or class reference */
1135 /* (This case is very simple unless *both* x and y really represent
1136 * merges of subclasses of clsx==clsy.)
1138 if ( (x.any == y.any) && (!mergedx || !mergedy) ) {
1140 /* DEBUG */ /* log_text("return simple x"); */
1141 changed = (dest->merged != NULL);
1142 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
1143 dest->merged = NULL;
1145 /* DEBUG */ /* log_text("returning"); */
1149 xname = (IS_CLASSREF(x)) ? x.ref->name : x.cls->name;
1150 yname = (IS_CLASSREF(y)) ? y.ref->name : y.cls->name;
1152 /* Common case 2: xname == yname, at least one unresolved */
1153 if ((IS_CLASSREF(x) || IS_CLASSREF(y)) && (xname == yname))
1155 /* use the loaded one if any */
1156 if (!IS_CLASSREF(y))
1158 goto return_simple_x;
1161 /*--------------------------------------------------*/
1162 /* non-trivial cases */
1163 /*--------------------------------------------------*/
1165 #ifdef TYPEINFO_VERBOSE
1168 fprintf(stderr,"merge_nonarrays:\n");
1169 fprintf(stderr," ");if(IS_CLASSREF(x))fprintf(stderr,"<ref>");utf_fprint(stderr,xname);fprintf(stderr,"\n");
1170 fprintf(stderr," ");if(IS_CLASSREF(y))fprintf(stderr,"<ref>");utf_fprint(stderr,yname);fprintf(stderr,"\n");
1172 TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(dbgx,x);
1173 dbgx.merged = mergedx;
1174 TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(dbgy,y);
1175 dbgy.merged = mergedy;
1176 typeinfo_print(stderr,&dbgx,4);
1177 fprintf(stderr," with:\n");
1178 typeinfo_print(stderr,&dbgy,4);
1182 TYPEINFO_ASSERT(IS_CLASSREF(x) || x.cls->loaded);
1183 TYPEINFO_ASSERT(IS_CLASSREF(y) || y.cls->loaded);
1185 /* If y is unresolved or an interface, swap x and y. */
1186 if (IS_CLASSREF(y) || (!IS_CLASSREF(x) && y.cls->flags & ACC_INTERFACE))
1188 t = x; x = y; y = t;
1189 tmerged = mergedx; mergedx = mergedy; mergedy = tmerged;
1192 /* {We know: If only one of x,y is unresolved it is x,} */
1193 /* { If both x,y are resolved and only one of x,y is an interface it is x.} */
1195 if (IS_CLASSREF(x)) {
1196 /* {We know: x and y have different class names} */
1198 /* Check if we are merging an unresolved type with java.lang.Object */
1199 if (y.cls == class_java_lang_Object && !mergedy) {
1201 goto return_simple_x;
1204 common = class_java_lang_Object;
1205 goto merge_with_simple_x;
1208 /* {We know: both x and y are resolved} */
1209 /* {We know: If only one of x,y is an interface it is x.} */
1211 TYPEINFO_ASSERT(!IS_CLASSREF(x) && !IS_CLASSREF(y));
1212 TYPEINFO_ASSERT(x.cls->loaded);
1213 TYPEINFO_ASSERT(y.cls->loaded);
1215 /* Handle merging of interfaces: */
1216 if (x.cls->flags & ACC_INTERFACE) {
1217 /* {x.cls is an interface and mergedx == NULL.} */
1219 if (y.cls->flags & ACC_INTERFACE) {
1220 /* We are merging two interfaces. */
1221 /* {mergedy == NULL} */
1223 /* {We know that x.cls!=y.cls (see common case at beginning.)} */
1224 result->cls = class_java_lang_Object;
1225 return typeinfo_merge_two(dest,x,y);
1228 /* {We know: x is an interface, y is a class.} */
1230 /* Check if we are merging an interface with java.lang.Object */
1231 if (y.cls == class_java_lang_Object && !mergedy) {
1233 goto return_simple_x;
1236 /* If the type y implements x then the result of the merge
1237 * is x regardless of mergedy.
1240 /* we may have to link the classes */
1242 link_class(x.cls); /* XXX */
1244 link_class(y.cls); /* XXX */
1246 TYPEINFO_ASSERT(x.cls->linked);
1247 TYPEINFO_ASSERT(y.cls->linked);
1249 if (CLASSINFO_IMPLEMENTS_INTERFACE(y.cls,x.cls->index)
1250 || mergedlist_implements_interface(mergedy,x.cls))
1252 /* y implements x, so the result of the merge is x. */
1253 goto return_simple_x;
1256 /* {We know: x is an interface, the type y a class or a merge
1257 * of subclasses and does not implement x.} */
1259 /* There may still be superinterfaces of x which are implemented
1260 * by y, too, so we have to add x.cls to the mergedlist.
1263 /* if x has no superinterfaces we could return a simple java.lang.Object */
1265 common = class_java_lang_Object;
1266 goto merge_with_simple_x;
1269 /* {We know: x and y are classes (not interfaces).} */
1271 /* we may have to link the classes */
1273 link_class(x.cls); /* XXX */
1275 link_class(y.cls); /* XXX */
1277 TYPEINFO_ASSERT(x.cls->linked);
1278 TYPEINFO_ASSERT(y.cls->linked);
1280 /* If *x is deeper in the inheritance hierarchy swap x and y. */
1281 if (x.cls->index > y.cls->index) {
1282 t = x; x = y; y = t;
1283 tmerged = mergedx; mergedx = mergedy; mergedy = tmerged;
1286 /* {We know: y is at least as deep in the hierarchy as x.} */
1288 /* Find nearest common anchestor for the classes. */
1291 while (tcls->index > common->index)
1292 tcls = tcls->super.cls;
1293 while (common != tcls) {
1294 common = common->super.cls;
1295 tcls = tcls->super.cls;
1298 /* {common == nearest common anchestor of x and y.} */
1300 /* If x.cls==common and x is a whole class (not a merge of subclasses)
1301 * then the result of the merge is x.
1303 if (x.cls == common && !mergedx) {
1304 goto return_simple_x;
1308 result->cls = common;
1310 return typeinfo_merge_mergedlists(dest,mergedx,mergedy);
1312 return typeinfo_merge_add(dest,mergedx,y);
1315 merge_with_simple_x:
1316 result->cls = common;
1318 return typeinfo_merge_add(dest,mergedy,x);
1320 return typeinfo_merge_two(dest,x,y);
1323 /* Condition: *dest must be a valid initialized typeinfo. */
1324 /* Condition: dest != y. */
1325 /* Returns: true if dest was changed. */
1327 typeinfo_merge(typeinfo *dest,typeinfo* y)
1331 classref_or_classinfo common;
1332 classref_or_classinfo elementclass;
1337 /*--------------------------------------------------*/
1339 /*--------------------------------------------------*/
1341 /* Merging something with itself is a nop */
1345 /* Merging two returnAddress types is ok. */
1346 /* Merging two different returnAddresses never happens, as the verifier */
1347 /* keeps them separate in order to check all the possible return paths */
1348 /* from JSR subroutines. */
1349 if (!dest->typeclass.any && !y->typeclass.any) {
1350 TYPEINFO_ASSERT(TYPEINFO_RETURNADDRESS(*dest) == TYPEINFO_RETURNADDRESS(*y));
1354 /* Primitive types cannot be merged with reference types */
1355 /* XXX only check this in debug mode? */
1356 if (!dest->typeclass.any || !y->typeclass.any)
1357 typeinfo_merge_error("Trying to merge primitive types.",dest,y);
1359 /* handle uninitialized object types */
1360 if (TYPEINFO_IS_NEWOBJECT(*dest) || TYPEINFO_IS_NEWOBJECT(*y)) {
1361 if (!TYPEINFO_IS_NEWOBJECT(*dest) || !TYPEINFO_IS_NEWOBJECT(*y))
1362 typeinfo_merge_error("Trying to merge uninitialized object type.",dest,y);
1363 if (TYPEINFO_NEWOBJECT_INSTRUCTION(*dest)
1364 != TYPEINFO_NEWOBJECT_INSTRUCTION(*y))
1365 typeinfo_merge_error("Trying to merge different uninitialized objects.",dest,y);
1369 /*--------------------------------------------------*/
1371 /*--------------------------------------------------*/
1373 /* Common case: dest and y are the same class or class reference */
1374 /* (This case is very simple unless *both* dest and y really represent
1375 * merges of subclasses of class dest==class y.)
1377 if ((dest->typeclass.any == y->typeclass.any) && (!dest->merged || !y->merged)) {
1379 changed = (dest->merged != NULL);
1380 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
1381 dest->merged = NULL;
1385 /* Handle null types: */
1386 if (TYPEINFO_IS_NULLTYPE(*y)) {
1389 if (TYPEINFO_IS_NULLTYPE(*dest)) {
1390 TYPEINFO_FREEMERGED_IF_ANY(dest->merged);
1391 TYPEINFO_CLONE(*y,*dest);
1395 /* Common case: two types with the same name, at least one unresolved */
1396 if (IS_CLASSREF(dest->typeclass)) {
1397 if (IS_CLASSREF(y->typeclass)) {
1398 if (dest->typeclass.ref->name == y->typeclass.ref->name)
1402 /* XXX should we take y instead of dest here? */
1403 if (dest->typeclass.ref->name == y->typeclass.cls->name)
1408 if (IS_CLASSREF(y->typeclass)
1409 && (dest->typeclass.cls->name == y->typeclass.ref->name))
1415 /*--------------------------------------------------*/
1416 /* non-trivial cases */
1417 /*--------------------------------------------------*/
1419 #ifdef TYPEINFO_VERBOSE
1420 fprintf(stderr,"merge:\n");
1421 typeinfo_print(stderr,dest,4);
1422 typeinfo_print(stderr,y,4);
1425 /* This function uses x internally, so x and y can be swapped
1426 * without changing dest. */
1430 /* Handle merging of arrays: */
1431 if (TYPEINFO_IS_ARRAY(*x) && TYPEINFO_IS_ARRAY(*y)) {
1433 /* Make x the one with lesser dimension */
1434 if (x->dimension > y->dimension) {
1435 tmp = x; x = y; y = tmp;
1438 /* If one array (y) has higher dimension than the other,
1439 * interpret it as an array (same dim. as x) of Arraystubs. */
1440 if (x->dimension < y->dimension) {
1441 dimension = x->dimension;
1442 elementtype = ARRAYTYPE_OBJECT;
1443 elementclass.cls = pseudo_class_Arraystub;
1446 dimension = y->dimension;
1447 elementtype = y->elementtype;
1448 elementclass = y->elementclass;
1451 /* {The arrays are of the same dimension.} */
1453 if (x->elementtype != elementtype) {
1454 /* Different element types are merged, so the resulting array
1455 * type has one accessible dimension less. */
1456 if (--dimension == 0) {
1457 common.cls = pseudo_class_Arraystub;
1459 elementclass.any = NULL;
1462 common.cls = class_multiarray_of(dimension,pseudo_class_Arraystub,true);
1464 log_text("XXX Coult not create array class");
1468 elementtype = ARRAYTYPE_OBJECT;
1469 elementclass.cls = pseudo_class_Arraystub;
1473 /* {The arrays have the same dimension and elementtype.} */
1475 if (elementtype == ARRAYTYPE_OBJECT) {
1476 /* The elements are references, so their respective
1477 * types must be merged.
1479 changed |= typeinfo_merge_nonarrays(dest,
1483 x->merged,y->merged);
1485 /* DEBUG */ /* log_text("finding resulting array class: "); */
1486 if (IS_CLASSREF(elementclass))
1487 common.ref = class_get_classref_multiarray_of(dimension,elementclass.ref);
1489 common.cls = class_multiarray_of(dimension,elementclass.cls,true);
1491 log_text("XXX Coult not create array class");
1495 /* DEBUG */ /* utf_display(common->name); printf("\n"); */
1498 common.any = y->typeclass.any;
1503 /* {We know that at least one of x or y is no array, so the
1504 * result cannot be an array.} */
1506 changed |= typeinfo_merge_nonarrays(dest,
1508 x->typeclass,y->typeclass,
1509 x->merged,y->merged);
1513 elementclass.any = NULL;
1516 /* Put the new values into dest if neccessary. */
1518 if (dest->typeclass.any != common.any) {
1519 dest->typeclass.any = common.any;
1522 if (dest->dimension != dimension) {
1523 dest->dimension = dimension;
1526 if (dest->elementtype != elementtype) {
1527 dest->elementtype = elementtype;
1530 if (dest->elementclass.any != elementclass.any) {
1531 dest->elementclass.any = elementclass.any;
1539 /**********************************************************************/
1540 /* DEBUGGING HELPERS */
1541 /**********************************************************************/
1543 #ifdef TYPEINFO_DEBUG
1547 typeinfo_test_compare(classref_or_classinfo *a,classref_or_classinfo *b)
1549 if (a->any == b->any) return 0;
1550 if (a->any < b->any) return -1;
1555 typeinfo_test_parse(typeinfo *info,char *str)
1562 utf *desc = utf_new_char(str);
1564 num = typeinfo_count_method_args(desc,false);
1566 typebuf = DMNEW(u1,num);
1567 infobuf = DMNEW(typeinfo,num);
1569 typeinfo_init_from_method_args(desc,typebuf,infobuf,num,false,
1572 TYPEINFO_ALLOCMERGED(info->merged,num);
1573 info->merged->count = num;
1575 for (i=0; i<num; ++i) {
1576 if (typebuf[i] != TYPE_ADDRESS) {
1577 log_text("non-reference type in mergedlist");
1581 info->merged->list[i].any = infobuf[i].typeclass.any;
1583 qsort(info->merged->list,num,sizeof(classref_or_classinfo),
1584 (int(*)(const void *,const void *))&typeinfo_test_compare);
1587 typeinfo_init_from_method_args(desc,NULL,NULL,0,false,
1593 #define TYPEINFO_TEST_BUFLEN 4000
1596 typeinfo_equal(typeinfo *x,typeinfo *y)
1600 if (x->typeclass.any != y->typeclass.any) return false;
1601 if (x->dimension != y->dimension) return false;
1603 if (x->elementclass.any != y->elementclass.any) return false;
1604 if (x->elementtype != y->elementtype) return false;
1607 if (TYPEINFO_IS_NEWOBJECT(*x))
1608 if (TYPEINFO_NEWOBJECT_INSTRUCTION(*x)
1609 != TYPEINFO_NEWOBJECT_INSTRUCTION(*y))
1612 if (x->merged || y->merged) {
1613 if (!(x->merged && y->merged)) return false;
1614 if (x->merged->count != y->merged->count) return false;
1615 for (i=0; i<x->merged->count; ++i)
1616 if (x->merged->list[i].any != y->merged->list[i].any)
1623 typeinfo_testmerge(typeinfo *a,typeinfo *b,typeinfo *result,int *failed)
1626 bool changed,changed_should_be;
1628 TYPEINFO_CLONE(*a,dest);
1631 typeinfo_print_short(stdout,&dest);
1633 typeinfo_print_short(stdout,b);
1636 changed = (typeinfo_merge(&dest,b)) ? 1 : 0;
1637 changed_should_be = (!typeinfo_equal(&dest,a)) ? 1 : 0;
1639 printf(" %s\n",(changed) ? "changed" : "=");
1641 if (typeinfo_equal(&dest,result)) {
1643 typeinfo_print_short(stdout,&dest);
1645 if (changed != changed_should_be) {
1646 printf("WRONG RETURN VALUE!\n");
1652 typeinfo_print_short(stdout,&dest);
1654 printf("SHOULD BE ");
1655 typeinfo_print_short(stdout,result);
1663 typeinfo_inc_dimension(typeinfo *info)
1665 if (info->dimension++ == 0) {
1666 info->elementtype = ARRAYTYPE_OBJECT;
1667 info->elementclass = info->typeclass;
1669 info->typeclass = class_array_of(info->typeclass,true);
1673 #define TYPEINFO_TEST_MAXDIM 10
1676 typeinfo_testrun(char *filename)
1678 char buf[TYPEINFO_TEST_BUFLEN];
1679 char bufa[TYPEINFO_TEST_BUFLEN];
1680 char bufb[TYPEINFO_TEST_BUFLEN];
1681 char bufc[TYPEINFO_TEST_BUFLEN];
1685 FILE *file = fopen(filename,"rt");
1689 log_text("could not open typeinfo test file");
1693 while (fgets(buf,TYPEINFO_TEST_BUFLEN,file)) {
1694 if (buf[0] == '#' || !strlen(buf))
1697 res = sscanf(buf,"%s\t%s\t%s\n",bufa,bufb,bufc);
1698 if (res != 3 || !strlen(bufa) || !strlen(bufb) || !strlen(bufc)) {
1699 log_text("Invalid line in typeinfo test file (none of empty, comment or test)");
1704 typeinfo_test_parse(&a,bufa);
1705 typeinfo_test_parse(&b,bufb);
1706 typeinfo_test_parse(&c,bufc);
1711 typeinfo_testmerge(&a,&b,&c,&failed); /* check result */
1712 typeinfo_testmerge(&b,&a,&c,&failed); /* check commutativity */
1714 if (TYPEINFO_IS_NULLTYPE(a)) break;
1715 if (TYPEINFO_IS_NULLTYPE(b)) break;
1716 if (TYPEINFO_IS_NULLTYPE(c)) break;
1718 maxdim = a.dimension;
1719 if (b.dimension > maxdim) maxdim = b.dimension;
1720 if (c.dimension > maxdim) maxdim = c.dimension;
1723 if (maxdim < TYPEINFO_TEST_MAXDIM) {
1724 typeinfo_inc_dimension(&a);
1725 typeinfo_inc_dimension(&b);
1726 typeinfo_inc_dimension(&c);
1728 } while (maxdim < TYPEINFO_TEST_MAXDIM);
1735 fprintf(stderr,"Failed typeinfo_merge tests: %d\n",failed);
1736 log_text("Failed test");
1744 log_text("Running typeinfo test file...");
1745 typeinfo_testrun("typeinfo.tst");
1746 log_text("Finished typeinfo test file.");
1751 typeinfo_init_from_fielddescriptor(typeinfo *info,char *desc)
1753 typeinfo_init_from_descriptor(info,desc,desc+strlen(desc));
1757 #define TYPEINFO_MAXINDENT 80
1760 typeinfo_print_class(FILE *file,classref_or_classinfo c)
1762 /*fprintf(file,"<class %p>",c.any);*/
1765 fprintf(file,"<null>");
1768 if (IS_CLASSREF(c)) {
1769 fprintf(file,"<ref>");
1770 utf_fprint(file,c.ref->name);
1773 utf_fprint(file,c.cls->name);
1779 typeinfo_print(FILE *file,typeinfo *info,int indent)
1782 char ind[TYPEINFO_MAXINDENT + 1];
1786 if (indent > TYPEINFO_MAXINDENT) indent = TYPEINFO_MAXINDENT;
1788 for (i=0; i<indent; ++i)
1792 if (TYPEINFO_IS_PRIMITIVE(*info)) {
1793 bptr = (basicblock*) TYPEINFO_RETURNADDRESS(*info);
1795 fprintf(file,"%sreturnAddress (L%03d)\n",ind,bptr->debug_nr);
1797 fprintf(file,"%sprimitive\n",ind);
1801 if (TYPEINFO_IS_NULLTYPE(*info)) {
1802 fprintf(file,"%snull\n",ind);
1806 if (TYPEINFO_IS_NEWOBJECT(*info)) {
1807 ins = (instruction *)TYPEINFO_NEWOBJECT_INSTRUCTION(*info);
1809 fprintf(file,"%sNEW(%p):",ind,(void*)ins);
1810 typeinfo_print_class(file,CLASSREF_OR_CLASSINFO(ins[-1].val.a));
1814 fprintf(file,"%sNEW(this)",ind);
1819 fprintf(file,"%sClass: ",ind);
1820 typeinfo_print_class(file,info->typeclass);
1823 if (TYPEINFO_IS_ARRAY(*info)) {
1824 fprintf(file,"%sDimension: %d",ind,(int)info->dimension);
1825 fprintf(file,"\n%sElements: ",ind);
1826 switch (info->elementtype) {
1827 case ARRAYTYPE_INT : fprintf(file,"int\n"); break;
1828 case ARRAYTYPE_LONG : fprintf(file,"long\n"); break;
1829 case ARRAYTYPE_FLOAT : fprintf(file,"float\n"); break;
1830 case ARRAYTYPE_DOUBLE : fprintf(file,"double\n"); break;
1831 case ARRAYTYPE_BYTE : fprintf(file,"byte\n"); break;
1832 case ARRAYTYPE_CHAR : fprintf(file,"char\n"); break;
1833 case ARRAYTYPE_SHORT : fprintf(file,"short\n"); break;
1834 case ARRAYTYPE_BOOLEAN : fprintf(file,"boolean\n"); break;
1836 case ARRAYTYPE_OBJECT:
1837 typeinfo_print_class(file,info->elementclass);
1842 fprintf(file,"INVALID ARRAYTYPE!\n");
1847 fprintf(file,"%sMerged: ",ind);
1848 for (i=0; i<info->merged->count; ++i) {
1849 if (i) fprintf(file,", ");
1850 typeinfo_print_class(file,info->merged->list[i]);
1857 typeinfo_print_short(FILE *file,typeinfo *info)
1863 /*fprintf(file,"<typeinfo %p>",info);*/
1866 fprintf(file,"(typeinfo*)NULL");
1870 if (TYPEINFO_IS_PRIMITIVE(*info)) {
1871 bptr = (basicblock*) TYPEINFO_RETURNADDRESS(*info);
1873 fprintf(file,"ret(L%03d)",bptr->debug_nr);
1875 fprintf(file,"primitive");
1879 if (TYPEINFO_IS_NULLTYPE(*info)) {
1880 fprintf(file,"null");
1884 if (TYPEINFO_IS_NEWOBJECT(*info)) {
1885 ins = (instruction *)TYPEINFO_NEWOBJECT_INSTRUCTION(*info);
1887 /*fprintf(file,"<ins %p>",ins);*/
1888 fprintf(file,"NEW(%p):",(void*)ins);
1889 typeinfo_print_class(file,CLASSREF_OR_CLASSINFO(ins[-1].val.a));
1892 fprintf(file,"NEW(this)");
1896 typeinfo_print_class(file,info->typeclass);
1900 for (i=0; i<info->merged->count; ++i) {
1901 if (i) fprintf(file,",");
1902 typeinfo_print_class(file,info->merged->list[i]);
1909 typeinfo_print_type(FILE *file,int type,typeinfo *info)
1912 case TYPE_VOID: fprintf(file,"V"); break;
1913 case TYPE_INT: fprintf(file,"I"); break;
1914 case TYPE_FLOAT: fprintf(file,"F"); break;
1915 case TYPE_DOUBLE: fprintf(file,"D"); break;
1916 case TYPE_LONG: fprintf(file,"J"); break;
1918 typeinfo_print_short(file,info);
1927 typeinfo_print_stacktype(FILE *file,int type,typeinfo *info)
1929 TYPEINFO_ASSERT(file);
1930 TYPEINFO_ASSERT(type != TYPE_ADDRESS || info != NULL);
1931 if (type == TYPE_ADDRESS && TYPEINFO_IS_PRIMITIVE(*info)) {
1932 typeinfo_retaddr_set *set = (typeinfo_retaddr_set*)
1933 TYPEINFO_RETURNADDRESS(*info);
1935 fprintf(file,"ret(L%03d",((basicblock*)(set->addr))->debug_nr);
1938 fprintf(file,"|L%03d",((basicblock*)(set->addr))->debug_nr);
1943 fprintf(file,"ret(<NULL>");
1948 typeinfo_print_type(file,type,info);
1952 typedescriptor_print(FILE *file,typedescriptor *td)
1954 typeinfo_print_type(file,td->type,&(td->info));
1958 typevector_print(FILE *file,typevector *vec,int size)
1962 fprintf(file,"[%d]",vec->k);
1963 for (i=0; i<size; ++i) {
1964 fprintf(file," %d=",i);
1965 typedescriptor_print(file,vec->td + i);
1970 typevectorset_print(FILE *file,typevector *set,int size)
1975 fprintf(file,"[%d",set->k);
1978 fprintf(file,"|%d",vec->k);
1983 for (i=0; i<size; ++i) {
1984 fprintf(file," %d=",i);
1985 typedescriptor_print(file,set->td + i);
1989 typedescriptor_print(file,vec->td + i);
1995 #endif /* TYPEINFO_DEBUG */
1999 * These are local overrides for various environment variables in Emacs.
2000 * Please do not remove this and leave it at the end of the file, where
2001 * Emacs will automagically detect them.
2002 * ---------------------------------------------------------------------
2005 * indent-tabs-mode: t