Ejemplo n.º 1
0
        public EnvironmentDomain <Key, Val> Meet(EnvironmentDomain <Key, Val> that)
        {
            if (map == that.map)
            {
                return(this);
            }

            if (this.IsTop)
            {
                return(that);
            }
            if (that.IsTop)
            {
                return(this);
            }
            if (this.IsBottom)
            {
                return(this);
            }
            if (that.IsBottom)
            {
                return(that);
            }

            Contract.Assume(map != null);

            // compare pointwise
            IFunctionalMap <Key, Val> smaller;
            IFunctionalMap <Key, Val> larger;

            if (map.Count < that.map.Count)
            {
                smaller = map;
                larger  = that.map;
            }
            else
            {
                smaller = that.map;
                larger  = map;
            }
            IFunctionalMap <Key, Val> result = larger;

            foreach (Key k in smaller.Keys)
            {
                if (larger.Contains(k))
                {
                    // must meet the values
                    Val meet = smaller[k].Meet(larger[k]);
                    result = result.Add(k, meet);
                }
                else
                {
                    // just add the value to the result
                    result = result.Add(k, smaller[k]);
                }
            }

            return(new EnvironmentDomain <Key, Val>(result));
        }
Ejemplo n.º 2
0
        public override Element /*!*/ NontrivialJoin(Element /*!*/ first, Element /*!*/ second)
        {
            //Contract.Requires(second != null);
            //Contract.Requires(first != null);
            Contract.Ensures(Contract.Result <Element>() != null);
            Elt a = (Elt)first;
            Elt b = (Elt)second;

            IFunctionalMap newMap = FunctionalHashtable.Empty;

            foreach (IVariable /*!*/ key in a.Variables)
            {
                Contract.Assert(key != null);
                Element aValue = a[key];
                Element bValue = b[key];

                if (aValue != null && bValue != null)
                {
                    // Keep only the variables known to both elements.
                    Element newValue = this.microLattice.Join(aValue, bValue);
                    newMap = newMap.Add(key, newValue);
                }
            }
            Elt /*!*/ join = new Elt(newMap);

            Contract.Assert(join != null);

            // System.Console.WriteLine("{0} join {1} = {2} ", this.ToString(a), ToString(b), ToString(join));

            return(join);
        }
Ejemplo n.º 3
0
        public EnvironmentDomain <Key, Val> Add(Key key, Val val)
        {
            if (map == null)
            {
                throw new InvalidOperationException();
            }

            return(new EnvironmentDomain <Key, Val>(map.Add(key, val)));
        }
Ejemplo n.º 4
0
        public override Element /*!*/ NontrivialMeet(Element /*!*/ first, Element /*!*/ second)
        {
            //Contract.Requires(second != null);
            //Contract.Requires(first != null);
            Contract.Ensures(Contract.Result <Element>() != null);
            Elt a = (Elt)first;
            Elt b = (Elt)second;

            IFunctionalMap newMap = FunctionalHashtable.Empty;

            foreach (IVariable /*!*/ key in a.Variables)
            {
                Contract.Assert(key != null);
                Element /*!*/ aValue = cce.NonNull(a[key]);
                Element       bValue = b[key];

                Element newValue =
                    bValue == null ? aValue :
                    this.microLattice.Meet(aValue, bValue);

                newMap = newMap.Add(key, newValue);
            }
            foreach (IVariable /*!*/ key in b.Variables)
            {
                Contract.Assert(key != null);
                Element aValue = a[key];
                Element bValue = b[key];
                Debug.Assert(bValue != null);

                if (aValue == null)
                {
                    // It's a variable we didn't cover in the last loop.
                    newMap = newMap.Add(key, bValue);
                }
            }
            return(new Elt(newMap));
        }
Ejemplo n.º 5
0
            public Elt /*!*/ Rename(IVariable /*!*/ oldName, IVariable /*!*/ newName, MicroLattice /*!*/ microLattice)
            {
                Contract.Requires(microLattice != null);
                Contract.Requires(newName != null);
                Contract.Requires(oldName != null);
                Contract.Requires((!this.IsBottom));
                Contract.Ensures(Contract.Result <Elt>() != null);
                Element value = this[oldName];

                if (value == null)
                {
                    return(this);
                } // 'oldName' isn't in the map, so neither will be 'newName'
                Contract.Assume(this.constraints != null);
                IFunctionalMap newMap = this.constraints.Remove(oldName);

                newMap = newMap.Add(newName, value);
                return(new Elt(newMap));
            }
Ejemplo n.º 6
0
        /// <summary>
        /// Perform the pointwise widening of the elements in the map
        /// </summary>
        public override Element /*!*/ Widen(Element /*!*/ first, Element /*!*/ second)
        {
            //Contract.Requires((second != null));
            //Contract.Requires((first != null));
            Contract.Ensures(Contract.Result <Element>() != null);
            Elt a = (Elt)first;
            Elt b = (Elt)second;

            // Note we have to add those cases as we do not have a "NonTrivialWiden" method
            if (a.IsBottom)
            {
                return(new Elt(b.Constraints));
            }
            if (b.IsBottom)
            {
                return(new Elt(a.Constraints));
            }

            IFunctionalMap newMap = FunctionalHashtable.Empty;

            foreach (IVariable /*!*/ key in a.Variables)
            {
                Contract.Assert(key != null);
                Element aValue = a[key];
                Element bValue = b[key];

                if (aValue != null && bValue != null)
                {
                    // Keep only the variables known to both elements.
                    Element newValue = this.microLattice.Widen(aValue, bValue);
                    newMap = newMap.Add(key, newValue);
                }
            }
            Element /*!*/ widen = new Elt(newMap);

            Contract.Assert(widen != null);
            // System.Console.WriteLine("{0} widen {1} = {2} ", this.ToString(a), ToString(b), ToString(widen));

            return(widen);
        }
Ejemplo n.º 7
0
        public EnvironmentDomain <Key, Val> Join(EnvironmentDomain <Key, Val> newState, out bool weaker, bool widen)
        {
            if (map == newState.map)
            {
                weaker = false; return(this);
            }

            bool resultWeaker = false;

            if (this.IsTop)
            {
                weaker = false; return(this);
            }
            if (newState.IsTop)
            {
                weaker = !this.IsTop; return(newState);
            }
            if (this.IsBottom)
            {
                weaker = !newState.IsBottom; return(newState);
            }
            if (newState.IsBottom)
            {
                weaker = false; return(this);
            }

            // compare pointwise
            IFunctionalMap <Key, Val> smaller;
            IFunctionalMap <Key, Val> larger;

            if (map.Count < newState.map.Count)
            {
                smaller = map;
                larger  = newState.map;
            }
            else
            {
                smaller = newState.map;
                larger  = map;
            }
            IFunctionalMap <Key, Val> result = smaller;

            foreach (Key k in smaller.Keys)
            {
                if (!larger.Contains(k))
                {
                    result = result.Remove(k);
                }
                else
                {
                    bool joinWeaker;
                    Val  join = smaller[k].Join(larger[k], out joinWeaker, widen);
                    if (joinWeaker)
                    {
                        resultWeaker = true;
                        if (join.IsTop)
                        {
                            result = result.Remove(k);
                        }
                        else
                        {
                            result = result.Add(k, join);
                        }
                    }
                }
            }
            weaker = resultWeaker || (result.Count < map.Count);
            return(new EnvironmentDomain <Key, Val>(result));
        }