-/* typevector_separable_from ***************************************************
-
- Check if two typevectors are separable. Two typevectors are considered
- separable if there is an index i for which both typevectors contain a
- returnAddress type and the return addresses of the types are different.
- The typevectors must have the same number of components.
-
- IN:
- a................the first typevector
- b................the second typevector
- size.............number of elements per typevector
-
- RETURN VALUE:
- true.............typevectors are separable
- false............typevectors are not separable
-
-*******************************************************************************/
-
-bool
-typevector_separable_from(typevector *a,typevector *b,int size)
-{
- typedescriptor *tda = a->td;
- typedescriptor *tdb = b->td;
- for (;size--; tda++,tdb++) {
- if (TYPEDESC_IS_RETURNADDRESS(*tda)
- && TYPEDESC_IS_RETURNADDRESS(*tdb)
- && TYPEINFO_RETURNADDRESS(tda->info)
- != TYPEINFO_RETURNADDRESS(tdb->info))
- return true;
- }
- return false;
-}
-
-/* typevectorset_add ***********************************************************
-
- Add a typevector to a typevector set. The typevector is added at the end of
- the set and the k-index of the typevector is set accordingly.
-
- IN:
- dst..............the typevector set to modify
- v................the typevector to add
- size.............number of elements per typevector
-
-*******************************************************************************/
-
-void
-typevectorset_add(typevector *dst,typevector *v,int size)
-{
- TYPEINFO_ASSERT(dst);
- TYPEINFO_ASSERT(v);
-
- while (dst->alt)
- dst = dst->alt;
- dst->alt = DNEW_TYPEVECTOR(size);
- memcpy(dst->alt,v,TYPEVECTOR_SIZE(size));
- dst->alt->alt = NULL;
- dst->alt->k = dst->k + 1;
-}
-
-/* typevectorset_select ********************************************************
-
- Pick the typevectors from a set which contain a given return address.
-
- IN:
- set..............points to the location containing the typevector set.
- *set may be NULL.
- index............index to check against the return address. All
- typevectors must contain a returnAddress type at
- this index.
- retaddr..........the return address to select
-
- OUT:
- *set.............receives the typevector set after removing the
- selected typevectors.
-
- RETURN VALUE:
- a typevector set consisting of the selected typevectors.
-
-*******************************************************************************/
-
-typevector *
-typevectorset_select(typevector **set,int index,void *retaddr)
-{
- typevector *selected;
-
- if (!*set) return NULL;
-
- if (TYPEINFO_RETURNADDRESS((*set)->td[index].info) == retaddr) {
- selected = *set;
- *set = selected->alt;
- selected->alt = typevectorset_select(set,index,retaddr);
- }
- else {
- selected = typevectorset_select(&((*set)->alt),index,retaddr);
- }
- return selected;
-}
-
-/* typevector_separable_with ***************************************************
-
- Check if a typevector set would be separable after adding a given
- typevector. A typevector set is considered separable if there is an
- index i for which all typevectors in the set contain a returnAddress type,
- and at least two different return addresses occurr at index i.
- The typevectors must have the same number of components.
-
- IN:
- set..............the typevector set
- add..............the typevector
- size.............number of elements per typevector
-
- RETURN VALUE:
- true.............result would be separable
- false............result would not be separable
-
-*******************************************************************************/
-
-bool
-typevectorset_separable_with(typevector *set,typevector *add,int size)
-{
- int i;
- typevector *v;
- void *addr;
- bool separable;
-
- TYPEINFO_ASSERT(set);
- TYPEINFO_ASSERT(add);
-
- for (i=0; i<size; ++i) {
- if (!TYPEDESC_IS_RETURNADDRESS(add->td[i]))
- continue;
- addr = TYPEINFO_RETURNADDRESS(add->td[i].info);
-
- v = set;
- separable = false;
- do {
- if (!TYPEDESC_IS_RETURNADDRESS(v->td[i]))
- goto next_index;
- if (TYPEINFO_RETURNADDRESS(v->td[i].info) != addr)
- separable = true;
- v = v->alt;
- } while (v);
- if (separable) return true;
- next_index:
- ;
- }
- return false;
-}
-
-/* typevectorset_collapse ******************************************************
-
- Collapse a typevector set into a single typevector by merging the
- components of the typevectors at each index.
-
- IN:
- dst..............the type vector set
- size.............number of elements per typevector
-
- OUT:
- *dst.............the resulting typevector set (a single typevector)
-
- RETURN VALUE:
- typecheck_TRUE...dst has been modified
- typecheck_FALSE..dst has not been modified
- typecheck_FAIL...an exception has been thrown
-
-*******************************************************************************/
-
-typecheck_result
-typevectorset_collapse(methodinfo *m,typevector *dst,int size)
-{
- bool changed = false;
-
- TYPEINFO_ASSERT(dst);
-
- while (dst->alt) {
- if (typevector_merge(m,dst,dst->alt,size) == typecheck_FAIL)
- return typecheck_FAIL;
- dst->alt = dst->alt->alt;
- changed = true;
- }
- return changed;
-}
-