Beispiel #1
0
        public DataType VisitUnion(UnionType ut)
        {
            // Do not transform user-defined types
            if (ut.UserDefined)
            {
                return(ut);
            }
            foreach (var alt in ut.Alternatives.Values)
            {
                alt.DataType = alt.DataType.Accept(this);
            }

            var upsm = new UnionPointersStructuresMatcher();

            if (upsm.Match(ut))
            {
                StructureMerger sm = new StructureMerger(upsm.Structures, upsm.EquivalenceClasses);
                sm.Merge();
                Changed = true;
                return(new Pointer(sm.MergedClass, upsm.PointerBitSize));
            }

            UnionType utNew = FactorDuplicateAlternatives(ut);
            var       dt    = utNew.Simplify();

            Changed |= (!(dt is UnionType utNew2) ||
                        utNew2.Alternatives.Count != ut.Alternatives.Count);
            return(dt);
        }
Beispiel #2
0
        public DataType VisitUnion(UnionType ut)
        {
            foreach (var alt in ut.Alternatives.Values)
            {
                alt.DataType = alt.DataType.Accept(this);
            }

            var upsm = new UnionPointersStructuresMatcher();

            if (upsm.Match(ut))
            {
                StructureMerger sm = new StructureMerger(upsm.Structures, upsm.EquivalenceClasses);
                sm.Merge();
                Changed = true;
                return(new Pointer(sm.MergedClass, upsm.PointerSize));
            }

            UnionType utNew = FactorDuplicateAlternatives(ut);
            var       dt    = utNew.Simplify();

            utNew = dt as UnionType;
            if (utNew == null || utNew.Alternatives.Count != ut.Alternatives.Count)
            {
                Changed = true;
            }
            return(dt);
        }
        public void NotMatch()
        {
            TypeVariable t1 = new TypeVariable(1);
            TypeVariable t2 = new TypeVariable(2);
            EquivalenceClass c1 = new EquivalenceClass(t1);
            EquivalenceClass c2 = new EquivalenceClass(t2);
            c1.DataType = new StructureType{ Fields = { { 4, PrimitiveType.Word16 } } };
            c2.DataType = new StructureType { Fields = { { 20, PrimitiveType.Word32 } } };
            t1.Class = c1;
            t2.Class = c2;

            UnionType u = new UnionType(null, null);
            u.Alternatives.Add(new Pointer(c1, 4));
            u.Alternatives.Add(new Pointer(PrimitiveType.Word16, 4));

            UnionPointersStructuresMatcher upsm = new UnionPointersStructuresMatcher();
            Assert.IsFalse(upsm.Match(u));
        }