Ejemplo n.º 1
0
        /// <summary>
        /// Removes duplicate alternatives from a UnionType.
        /// </summary>
        /// <param name="u"></param>
        /// <returns>A (possibly) simplified UnionType.</returns>
        public UnionType FactorDuplicateAlternatives(UnionType u)
        {
            UnionType uNew = new UnionType(u.Name, u.PreferredType);

            foreach (UnionAlternative a in u.Alternatives.Values)
            {
                if (a.DataType.ResolveAs <UnionType>() == u)
                {
                    continue;       //$HACK gets rid of (union "foo" (int) (union "foo"))
                }
                unifier.UnifyIntoUnion(uNew, a.DataType);
            }
            return(uNew);
        }
Ejemplo n.º 2
0
        public void UnifyWordMemptr()
        {
            TypeVariable  tv  = new TypeVariable(1);
            TypeVariable  tv2 = new TypeVariable(2);
            TypeVariable  tv3 = new TypeVariable(3);
            MemberPointer mp2 = new MemberPointer(tv, tv2, 0);
            MemberPointer mp3 = new MemberPointer(tv, tv3, 0);
            UnionType     ut  = new UnionType(null, null);

            un.UnifyIntoUnion(ut, mp2);
            un.UnifyIntoUnion(ut, mp3);
            un.UnifyIntoUnion(ut, PrimitiveType.Word16);

            Assert.AreEqual("(union ((memptr T_1 T_2) u0) ((memptr T_1 T_3) u1))", ut.ToString());
        }