Exemplo n.º 1
0
        public virtual bool Match(CFGNode node, CFGPatternMatchFlags flags)
        {
            CFGPatternMatchFlags currentFlags = SpecialFlags == null ? SpecialFlags.Value : flags;
            if (FlowControl != null)
            {
                if (FlowControl.Value != node.FlowControl)
                {
                    return false;
                }
            }
            foreach (Predicate<CFGNode> predicate in Predicates)
            {
                if (!predicate(node))
                {
                    return false;
                }
            }
            if ((currentFlags & CFGPatternMatchFlags.PerfectMatch) > 0)
            {

                if (Pattern.OutDegree(this) != node.Graph.OutDegree(node))
                {
                    return false;
                }
            }

            // find a match for each edge
            List<CFGPatternEdge> patternEdges = new List<CFGPatternEdge>();
            foreach (QuickGraph.Concepts.IEdge edge in this.Pattern.OutEdges(this))
            {
                patternEdges.Add((CFGPatternEdge)edge);
            }
            List<CFGEdge> edges = new List<CFGEdge>();
            foreach (QuickGraph.Concepts.IEdge edge in node.Graph.OutEdges(node))
            {
                edges.Add((CFGEdge)edge);
            }
            while (patternEdges.Count > 0)
            {
                foreach (CFGPatternEdge patternEdge in patternEdges)
                {
                    bool foundMatch = false;
                    foreach (CFGEdge edge in edges)
                    {
                        if (patternEdge.Match(edge, flags))
                        {
                            foundMatch = true;
                            patternEdges.Remove(patternEdge);
                            edges.Remove(edge);
                            break;
                        }
                    }
                    if (!foundMatch)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
Exemplo n.º 2
0
 public virtual bool Match(CFG graph, CFGPatternMatchFlags flags)
 {
     return Root.Match(graph.Root, flags);
 }
Exemplo n.º 3
0
 public virtual bool Match(CFGEdge edge, CFGPatternMatchFlags flags)
 {
     throw new NotImplementedException();
 }