示例#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);
        }
示例#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);
        }
示例#3
0
 public void Merge1()
 {
     TypeVariable tv1 = new TypeVariable(1);
     TypeVariable tv2 = new TypeVariable(2);
     StructureType s1 = new StructureType { Fields = { { 4, PrimitiveType.Pointer32 } } };
     StructureType s2 = new StructureType { Fields = { { 4, PrimitiveType.Pointer32 } } };
     EquivalenceClass c1 = new EquivalenceClass(tv1);
     EquivalenceClass c2 = new EquivalenceClass(tv2);
     c1.DataType = s1;
     c2.DataType = s2;
     StructureMerger sm = new StructureMerger(new StructureType[] { s1, s2 }, new EquivalenceClass[] { c1, c2 } );
     sm.Merge();
     Assert.AreEqual("(struct (4 ptr32 ptr0004))", c1.DataType.ToString());
 }