Ejemplo n.º 1
0
        private IImmutableSet <Subroutine> GetInheritedRequires(Method method)
        {
            IImmutableSet <Subroutine> result = ImmutableSet <Subroutine> .Empty();

            if (MetaDataProvider.IsVirtual(method) && ContractProvider.CanInheritContracts(method))
            {
                Method rootMethod;
                if (MetaDataProvider.TryGetRootMethod(method, out rootMethod))
                {
                    Subroutine sub = Get(MetaDataProvider.Unspecialized(method));
                    if (sub != null)
                    {
                        result = result.Add(sub);
                    }
                }
                foreach (Method implMethod in MetaDataProvider.ImplementedMethods(method))
                {
                    Subroutine sub = Get(MetaDataProvider.Unspecialized(implMethod));
                    if (sub != null)
                    {
                        result = result.Add(sub);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private IImmutableSet <Subroutine> GetInheritedEnsures(Method method)
        {
            IImmutableSet <Subroutine> result = ImmutableSet <Subroutine> .Empty();

            if (MetaDataProvider.IsVirtual(method) && ContractProvider.CanInheritContracts(method))
            {
                foreach (Method implementedMethod in MetaDataProvider.OverridenAndImplementedMethods(method))
                {
                    Subroutine subroutine = Get(MetaDataProvider.Unspecialized(implementedMethod));
                    if (subroutine != null)
                    {
                        result = result.Add(subroutine);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public MergeInfo(SymGraph <TFunc, TADomain> result,
                         SymGraph <TFunc, TADomain> g1,
                         SymGraph <TFunc, TADomain> g2, bool widen)
        {
            this.mappings = DoubleImmutableMap <SymValue, SymValue, SymValue> .Empty(SymValue.GetUniqueKey);

            this.visited_key1 = ImmutableSet <SymValue> .Empty(SymValue.GetUniqueKey);

            this.visited_multi_edges = new HashSet <Tuple <SymValue, SymValue, MultiEdge <TFunc, TADomain> > > ();
            this.pending_counts      = new DoubleDictionary <SymValue, SymValue, int> ();
            this.manifested          = new HashSet <SymValue> ();

            this.LastCommonVariable = result.IdGenerator;
            this.Widen  = widen;
            this.Result = result;
            this.Graph1 = g1;
            this.Graph2 = g2;

            this.Changed = false;
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public SetDomain(Func <T, int> keyConverter)
 {
     this.set = ImmutableSet <T> .Empty(keyConverter);
 }