Beispiel #1
0
        private void DrainEqualityWorkList(WorkList <EqualityPair <TFunc, TADomain> > workList)
        {
            while (!workList.IsEmpty())
            {
                EqualityPair <TFunc, TADomain> equalityPair = workList.Pull();
                SymValue sv1 = Find(equalityPair.Sv1);
                SymValue sv2 = Find(equalityPair.Sv2);
                if (sv1 != sv2)
                {
                    if (sv1.UniqueId < sv2.UniqueId)
                    {
                        SymValue tmp = sv1;
                        sv1 = sv2;
                        sv2 = tmp;
                    }

                    foreach (TFunc function in Functions(sv1))
                    {
                        SymValue v2 = LookupWithoutManifesting(sv2, function);
                        if (v2 == null)
                        {
                            this [sv2, function] = this [sv1, function];
                        }
                        else
                        {
                            TryPushEquality(workList, this [sv1, function], v2);
                        }
                    }
                    TADomain thisValue = this [sv1];
                    TADomain thatValue = this [sv2];
                    foreach (var elem in EqualTermsMap[sv1].AsEnumerable())
                    {
                        EqualTermsMap = EqualTermsMap.Add(sv2, EqualTermsMap [sv2].Cons(elem));
                    }

                    this.forw_map = this.forw_map.Add(sv1, sv2);
                    this [sv2]    = thisValue.Meet(thatValue);
                }
            }
        }
Beispiel #2
0
        private static bool InternalLessEqual(SymGraph <TFunc, TADomain> thisG, SymGraph <TFunc, TADomain> thatG,
                                              out IImmutableMap <SymValue, Sequence <SymValue> > forward,
                                              out IImmutableMap <SymValue, SymValue> backward)
        {
            int updateSize;
            SymGraph <TFunc, TADomain> commonTail = ComputeCommonTail(thisG, thatG, out updateSize);

            if (thisG.IsImmutable)
            {
                thisG = thisG.Clone();
            }

            var workList = new WorkList <EqualityPair <TFunc, TADomain> > ();

            workList.Add(new EqualityPair <TFunc, TADomain> (thisG.const_root, thatG.const_root));
            IImmutableSet <SymValue> backwardManifested = ImmutableSet <SymValue> .Empty(SymValue.GetUniqueKey);

            IImmutableMap <SymValue, SymValue> backwardMap = ImmutableIntKeyMap <SymValue, SymValue> .Empty(SymValue.GetUniqueKey);

            IImmutableMap <SymValue, Sequence <SymValue> > forwardMap = ImmutableIntKeyMap <SymValue, Sequence <SymValue> > .Empty(SymValue.GetUniqueKey);

            IImmutableMap <SymValue, int> triggers = ImmutableIntKeyMap <SymValue, int> .Empty(SymValue.GetUniqueKey);

            while (!workList.IsEmpty())
            {
                EqualityPair <TFunc, TADomain> equalityPair = workList.Pull();
                SymValue sv1 = equalityPair.Sv1;
                SymValue sv2 = equalityPair.Sv2;

                SymValue s;
                if (VisitedBefore(sv2, backwardManifested, backwardMap, out s))
                {
                    if (s != null && s == sv1)
                    {
                        continue;
                    }

                    if (DebugOptions.Debug)
                    {
                        Console.WriteLine("---LessEqual fails due to pre-existing relation: {0} <- {1}", s, sv2);
                    }
                    forward  = null;
                    backward = null;
                    return(false);
                }

                TADomain val1 = sv1 == null?thisG.UnderlyingTopValue.ForManifestedField() : thisG [sv1];

                TADomain val2 = thatG [sv2];
                if (!val1.LessEqual(val2))
                {
                    if (DebugOptions.Debug)
                    {
                        Console.WriteLine("---LessEqual fails due to abstract values: !({0} <= {1})", val1, val2);
                    }
                    forward  = null;
                    backward = null;
                    return(false);
                }
                if (sv1 != null)
                {
                    backwardMap = backwardMap.Add(sv2, sv1);
                    forwardMap  = forwardMap.Add(sv1, forwardMap [sv1].Cons(sv2));
                }
                else
                {
                    backwardManifested = backwardManifested.Add(sv2);
                }
                if (thisG.HasAllBottomFields(sv1))
                {
                    continue;
                }
                if (thatG.HasAllBottomFields(sv2))
                {
                    if (DebugOptions.Debug)
                    {
                        Console.WriteLine("---LessEqual fails due to bottom field difference");
                    }
                    forward  = null;
                    backward = null;
                    return(false);
                }

                foreach (TFunc function in thatG.Functions(sv2))
                {
                    SymValue v1 = thisG [function, sv1];
                    SymValue v2 = thatG [function, sv2];
                    if (DebugOptions.Debug)
                    {
                        Console.WriteLine("    {0}-{1}->{2} <=? {3}-{4}->{5}", sv1, function, v1, sv2, function, v2);
                    }
                    workList.Add(new EqualityPair <TFunc, TADomain> (v1, v2));
                }

                foreach (var e in thatG.MultiEdges(sv2))
                {
                    foreach (SymValue sv in thatG.MultiEdgeMap[sv2, e].AsEnumerable())
                    {
                        if (!UpdateTrigger(sv, e, ref triggers))
                        {
                            continue;
                        }

                        SymGraphTerm <TFunc> term = thatG.EqualMultiTermsMap [sv];
                        var args = new SymValue[term.Args.Length];
                        for (int i = 0; i < args.Length; i++)
                        {
                            args [i] = backwardMap [term.Args [i]];
                        }

                        SymValue v1 = thisG.LookupWithoutManifesting(args, e.Function);
                        if (v1 == null)
                        {
                            if (DebugOptions.Debug)
                            {
                                Console.WriteLine("---LessEqual fails due to missing multi term {0}({1})",
                                                  e.Function,
                                                  string.Join(", ", term.Args.Select(it => it.ToString())));
                            }
                            forward  = null;
                            backward = null;
                            return(false);
                        }

                        workList.Add(new EqualityPair <TFunc, TADomain> (v1, sv));
                    }
                }
            }
            forward  = forwardMap;
            backward = CompleteWithCommon(backwardMap, thisG, commonTail.IdGenerator);
            return(true);
        }
Beispiel #3
0
 public bool Equals(EqualityPair <TFunc, TAbstractDomain> other)
 {
     return(this.Sv1 == other.Sv1 && this.Sv2 == other.Sv2);
 }