コード例 #1
0
        public bool LessEqual(EnvironmentDomain <Key, Val> that)
        {
            if (that.IsTop)
            {
                return(true);
            }
            if (this.IsBottom)
            {
                return(true);
            }
            if (this.IsTop)
            {
                return(false);
            }
            if (that.IsBottom)
            {
                return(false);
            }
            if (map.Count < that.map.Count)
            {
                return(false);
            }

            // pointwise
            foreach (Key k in that.map.Keys)
            {
                if (!map.Contains(k) || !map[k].LessEqual(that.map[k]))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
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));
        }
コード例 #3
0
                /// <summary>
                /// Here's where the actual work is. We get passed a list of pairs (source,targets) representing
                /// the assignments t = source for each t in targets.
                ///
                /// For our domain, we thus add new mappings for all targets by looking up the bounds of the source and map the source bounds to new target bounds.
                /// </summary>
                public Domain ParallelAssign(Pair <Label, Label> edge, IFunctionalMap <Variable, FList <Variable> > sourceTargetMap, Domain state)
                {
                    EnvironmentDomain <Variable, SetDomain <Variable> > originalState = state.Value;
                    EnvironmentDomain <Variable, SetDomain <Variable> > newState      = originalState;

                    foreach (Variable source in sourceTargetMap.Keys)
                    {
                        FList <Variable> targets = sourceTargetMap[source];

                        // 1) for each target in this assignment, assign it the same bounds as source.
                        // 2) since we also have to map the source bounds, we assign it actually the union of all targets of all bounds of the source.
                        SetDomain <Variable> targetBounds = SetDomain <Variable> .TopValue;
                        if (originalState.Contains(source))
                        {
                            SetDomain <Variable> originalBounds = originalState[source];
                            foreach (Variable origBound in originalBounds.Elements)
                            {
                                FList <Variable> targetBoundNames = sourceTargetMap[origBound];
                                while (targetBoundNames != null)
                                {
                                    targetBounds     = targetBounds.Add(targetBoundNames.Head);
                                    targetBoundNames = targetBoundNames.Tail;
                                }
                            }
                        }
                        if (targetBounds.IsTop)
                        {
                            // have no bounds, so havoc all targets
                            while (targets != null)
                            {
                                newState = newState.Remove(targets.Head);
                                targets  = targets.Tail;
                            }
                        }
                        else
                        {
                            while (targets != null)
                            {
                                newState = newState.Add(targets.Head, targetBounds);
                                targets  = targets.Tail;
                            }
                        }
                    }
                    return(new Domain(newState));
                }
コード例 #4
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));
        }
コード例 #5
0
 public Domain(EnvironmentDomain <Variable, SetDomain <Variable> > value)
 {
     this.Value = value;
 }
コード例 #6
0
 public Domain InitialValue(Converter <Variable, int> keyNumber)
 {
     return(new Domain(EnvironmentDomain <Variable, SetDomain <Variable> > .TopValue(keyNumber)));
 }