Esempio n. 1
0
        public static ReadOnlyCollection <ControlFlowEdge> AlienBackEdges(this BaseControlFlowGraph cfg, IEnumerable <ControlFlowBlock> vertices)
        {
            var allEdges   = cfg.BackEdges(vertices, null).Concat(cfg.BackEdges(null, vertices));
            var innerEdges = cfg.BackEdges(vertices, vertices);

            return(allEdges.Except(innerEdges).ToReadOnly());
        }
Esempio n. 2
0
        protected void Initialize(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter, IEnumerable <ControlFlowEdge> edges, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
        {
            _hardcodedEdges = edges == null ? null : edges.ToHashSet();
            var edgeFilter = edges == null ? (e => true) : ((Func <ControlFlowEdge, bool>)(e => _hardcodedEdges.Contains(e)));

            InitializeCore(source, vertexFilter, edgeFilter, onAlienEdge);
        }
Esempio n. 3
0
        protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, Func <ControlFlowEdge, bool> edgeFilter, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
        {
            _hardcodedVertices = vertices == null ? null : vertices.ToHashSet();
            var vertexFilter = _hardcodedVertices == null ? (cfb => true) : (Func <ControlFlowBlock, bool>)(cfb => _hardcodedVertices.Contains(cfb));

            InitializeCore(source, vertexFilter, edgeFilter, onAlienEdge);
        }
Esempio n. 4
0
        protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, IEnumerable <ControlFlowEdge> edges, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
        {
            _hardcodedVertices = vertices != null?vertices.ToHashSet() :
                                     (edges != null ? edges.SelectMany(e => new [] { e.Source, e.Target }).ToHashSet() : null);

            var vertexFilter = _hardcodedVertices == null ? (cfb => true) : (Func <ControlFlowBlock, bool>)(cfb => _hardcodedVertices.Contains(cfb));

            _hardcodedEdges = edges == null ? null : edges.ToHashSet();
            var edgeFilter = edges == null ? (e => true) : ((Func <ControlFlowEdge, bool>)(e => _hardcodedEdges.Contains(e)));

            InitializeCore(source, vertexFilter, edgeFilter, onAlienEdge);
        }
        public ControlFlowGraph(BaseControlFlowGraph proto, bool deep)
            : base(proto, deep)
        {
            _start  = proto.Start;
            _finish = proto.Finish;

            _allTimeVertexCounter = __vertices.Count();
            if (_start == null)
            {
                _allTimeVertexCounter++;
            }
            if (_finish == null)
            {
                _allTimeVertexCounter++;
            }
            HookUpVertexPostprocessors();
        }
Esempio n. 6
0
 public ViewOfControlFlowGraph(BaseControlFlowGraph source, Func <ControlFlowEdge, bool> edgeFilter)
 {
     Initialize(source, edgeFilter);
 }
Esempio n. 7
0
 protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, IEnumerable <ControlFlowEdge> edges)
 {
     Initialize(source, vertices, edges, (e, _) => { throw AssertionHelper.Fail(); });
 }
Esempio n. 8
0
 public ViewOfControlFlowGraph(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, IEnumerable <ControlFlowEdge> edges, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
 {
     Initialize(source, vertices, edges, onAlienEdge);
 }
Esempio n. 9
0
 protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowEdge> edges, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
 {
     Initialize(source, (IEnumerable <ControlFlowBlock>)null, edges, onAlienEdge);
 }
Esempio n. 10
0
 public ViewOfControlFlowGraph(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, IEnumerable <ControlFlowEdge> edges)
 {
     Initialize(source, vertices, edges);
 }
 public DebugView(BaseControlFlowGraph g)
 {
     _g = g;
 }
Esempio n. 12
0
        // hybrids

        public ViewOfControlFlowGraph(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter, IEnumerable <ControlFlowEdge> edges)
        {
            Initialize(source, vertexFilter, edges);
        }
Esempio n. 13
0
 protected void Initialize(BaseControlFlowGraph source, Func <ControlFlowEdge, bool> edgeFilter)
 {
     Initialize(source, (IEnumerable <ControlFlowBlock>)null, edgeFilter);
 }
Esempio n. 14
0
 protected void Initialize(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
 {
     Initialize(source, vertexFilter, (IEnumerable <ControlFlowEdge>)null, onAlienEdge);
 }
Esempio n. 15
0
 public ViewOfControlFlowGraph(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, Func <ControlFlowEdge, bool> edgeFilter)
 {
     Initialize(source, vertices, edgeFilter);
 }
Esempio n. 16
0
 protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices, Func <ControlFlowEdge, bool> edgeFilter)
 {
     Initialize(source, vertices, edgeFilter, (v, _) => { throw AssertionHelper.Fail(); });
 }
Esempio n. 17
0
 public ViewOfControlFlowGraph(BaseControlFlowGraph source, Func <ControlFlowEdge, bool> edgeFilter, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
 {
     Initialize(source, edgeFilter, onAlienEdge);
 }
Esempio n. 18
0
 public ViewOfControlFlowGraph(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter, IEnumerable <ControlFlowEdge> edges, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
 {
     Initialize(source, vertexFilter, edges, onAlienEdge);
 }
Esempio n. 19
0
 protected void Initialize(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter, IEnumerable <ControlFlowEdge> edges)
 {
     Initialize(source, vertexFilter, edges, (e, _) => { throw AssertionHelper.Fail(); });
 }
Esempio n. 20
0
        // functions

        public ViewOfControlFlowGraph(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter)
        {
            Initialize(source, vertexFilter);
        }
Esempio n. 21
0
 protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowBlock> vertices)
 {
     Initialize(source, vertices, (IEnumerable <ControlFlowEdge>)null);
 }
 protected BaseControlFlowGraph(BaseControlFlowGraph proto, bool deep)
     : this()
 {
     proto.Vertices.ForEach(v => AddVertex(v));
     proto.Edges().ForEach(e => AddEdge(deep ? e.ShallowClone() : e));
 }
Esempio n. 23
0
 protected void Initialize(BaseControlFlowGraph source, IEnumerable <ControlFlowEdge> edges)
 {
     Initialize(source, (IEnumerable <ControlFlowBlock>)null, edges);
 }
Esempio n. 24
0
 public static ReadOnlyCollection <ControlFlowEdge> AlienBackEdges(this BaseControlFlowGraph cfg, Func <ControlFlowBlock, bool> vertices)
 {
     return(cfg.AlienBackEdges(cfg.Vertices.Where(vertices)));
 }
Esempio n. 25
0
 protected void Initialize(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter, Func <ControlFlowEdge, bool> edgeFilter, Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
 {
     vertexFilter = vertexFilter ?? (cfb => true);
     edgeFilter   = edgeFilter ?? (e => true);
     InitializeCore(source, vertexFilter, edgeFilter, onAlienEdge);
 }
Esempio n. 26
0
        private void InitializeCore(
            BaseControlFlowGraph source,
            Func <ControlFlowBlock, bool> vertexFilter,
            Func <ControlFlowEdge, bool> edgeFilter,
            Action <ControlFlowEdge, ViewOfControlFlowGraph> onAlienEdge)
        {
            Source = source.AssertNotNull();
            HookUpVertexPostprocessors();

            _vertexFilter = vertexFilter.AssertNotNull();
            _edgeFilter   = edgeFilter.AssertNotNull();

            _cachedVertices = _hardcodedVertices != null ? null : source.Vertices.Where(_vertexFilter).ToList();
            (_cachedVertices ?? _hardcodedVertices.AsEnumerable()).ForEach(OnVertexAdded);

            ReadOnlyCollection <ControlFlowEdge> alienEdges = null;

            if (_hardcodedEdges != null)
            {
                var edgeVertices = _hardcodedEdges.SelectMany(e => new [] { e.Source, e.Target }).ToHashSet();
                edgeVertices.ExceptWith(_cachedVertices ?? _hardcodedVertices.AsEnumerable());
                edgeVertices.AssertEmpty();
            }
            else
            {
                _edgeFilter = e => edgeFilter(e) && _vertexFilter(e.Source) && _vertexFilter(e.Target);

                var relatedEdges = source.Edges(_vertexFilter, null).Concat(source.Edges(null, _vertexFilter)).Distinct();
                var parts        = relatedEdges.GroupBy(e => _edgeFilter(e)).ToDictionary(g => g.Key, g => g.AsEnumerable());
                _cachedEdges = (parts.GetOrDefault(true, Seq.Empty <ControlFlowEdge>)).ToList();
                alienEdges   = parts.GetOrDefault(false, Seq.Empty <ControlFlowEdge>).ToReadOnly();
            }
            (_cachedEdges ?? _hardcodedEdges.AsEnumerable()).ForEach(OnEdgeAdded);

            Action <ControlFlowBlock> cacheVertex = v => { if (_cachedVertices != null)
                                                           {
                                                               _cachedVertices.Add(v);
                                                           }
                                                           else
                                                           {
                                                               throw AssertionHelper.Fail();
                                                           } };
            Action <ControlFlowBlock> uncacheVertex = v => { if (_cachedVertices != null)
                                                             {
                                                                 _cachedVertices.Remove(v);
                                                             }
                                                             else
                                                             {
                                                                 _hardcodedVertices.Remove(v);
                                                             } };

            source.VertexAdded += v => { if (_vertexFilter(v))
                                         {
                                             cacheVertex(v); OnVertexAdded(v);
                                         }
            };
            source.VertexRemoved += v => { if (_vertexFilter(v))
                                           {
                                               uncacheVertex(v); OnVertexRemoved(v);
                                           }
            };

            Action <ControlFlowEdge> cacheEdge = e => { if (_cachedEdges != null)
                                                        {
                                                            _cachedEdges.Add(e);
                                                        }
                                                        else
                                                        {
                                                            throw AssertionHelper.Fail();
                                                        } };
            Action <ControlFlowEdge> uncacheEdge = e => { if (_cachedEdges != null)
                                                          {
                                                              _cachedEdges.Remove(e);
                                                          }
                                                          else
                                                          {
                                                              _hardcodedEdges.Remove(e);
                                                          } };

            source.EdgeAdded += e => { if (_edgeFilter(e))
                                       {
                                           cacheEdge(e); OnEdgeAdded(e);
                                       }
            };
            source.EdgeRemoved += e => { if (_edgeFilter(e))
                                         {
                                             uncacheEdge(e); OnEdgeRemoved(e);
                                         }
            };

            __vertices = new VirtualList <ControlFlowBlock>(
                () => (_hardcodedVertices ?? (IEnumerable <ControlFlowBlock>)_cachedVertices).Concat(_eigenVertices),
                (i, v) =>
            {
                if (_eigenVertices.Contains(v))
                {
                    // do nothing - the vertex has just been created by AddEigenVertex
                }
                else
                {
                    _vertexFilter(v).AssertTrue();
                    (_cachedVertices != null && i == _cachedVertices.Count()).AssertTrue();
                    Source.AddVertex(v);
                }
            },
                (i, v) => { _vertexFilter(v).AssertTrue(); throw AssertionHelper.Fail(); },
                i =>
            {
                if (i < _cachedEdges.Count())
                {
                    var v = _cachedVertices[i];
                    Source.RemoveVertex(v);
                }
                else
                {
                    throw AssertionHelper.Fail();
                }
            });

            __edges = new VirtualList <ControlFlowEdge>(
                () => (_hardcodedEdges ?? (IEnumerable <ControlFlowEdge>)_cachedEdges).Concat(_eigenEdges),
                (i, e) =>
            {
                if (_eigenEdges.Contains(e))
                {
                    // do nothing - the edge has just been created by AddEigenEdge
                }
                else
                {
                    _edgeFilter(e).AssertTrue();
                    (_cachedEdges != null && i == _cachedEdges.Count()).AssertTrue();
                    Source.AddEdge(e);
                }
            },
                (i, e) => { _edgeFilter(e).AssertTrue(); throw AssertionHelper.Fail(); },
                i =>
            {
                if (i < _cachedEdges.Count())
                {
                    var e = _cachedEdges[i];
                    Source.RemoveEdge(e);
                }
                else
                {
                    var e = _eigenEdges[i - _cachedEdges.Count()];
                    _eigenEdges.Remove(e);
                }
            });

            try { _allowAutoCreateStartAndFinish = true; alienEdges.ForEach(e => onAlienEdge(e, this)); }
            finally { _allowAutoCreateStartAndFinish = false; }
        }
Esempio n. 27
0
 protected void Initialize(BaseControlFlowGraph source, Func <ControlFlowBlock, bool> vertexFilter)
 {
     Initialize(source, vertexFilter, (IEnumerable <ControlFlowEdge>)null);
 }