예제 #1
0
        FlowGraphNode ParseIf(Dictionary <string, object> item)
        {
            IfNode node = new IfNode(Id++);
            List <FlowGraphNode>        left     = new List <FlowGraphNode>();
            List <FlowGraphNode>        right    = new List <FlowGraphNode>();
            Dictionary <string, object> leftarr  = (Dictionary <string, object>)item["iffalse"];
            Dictionary <string, object> rightarr = (Dictionary <string, object>)item["iftrue"];

            if (leftarr != null)
            {
                if ("Compound" == leftarr["_nodetype"].ToString())
                {
                    ArrayList functionflow = (ArrayList)leftarr["block_items"];
                    if (functionflow != null)
                    {
                        foreach (Dictionary <string, object> argument in functionflow)
                        {
                            left.Add(ParseNode(argument));
                        }
                    }
                }
                else
                {
                    left.Add(ParseNode(leftarr));
                }
            }
            if (rightarr != null)
            {
                if ("Compound" == rightarr["_nodetype"].ToString())
                {
                    ArrayList functionflow = (ArrayList)rightarr["block_items"];
                    if (functionflow != null)
                    {
                        foreach (Dictionary <string, object> argument in functionflow)
                        {
                            right.Add(ParseNode(argument));
                        }
                    }
                }
                else
                {
                    right.Add(ParseNode(rightarr));
                }
            }
            node.left      = left;
            node.right     = right;
            node.condition = ParseNode((Dictionary <string, object>)item["cond"]);
            return(node);
        }
예제 #2
0
        public List <System.Windows.UIElement> generateShapes(List <FlowGraphNode> nodes, int x, ref int y, List <FlowGraphNode> path)
        {
            List <System.Windows.UIElement> shapes = new List <System.Windows.UIElement>();

            foreach (FlowGraphNode node in nodes)
            {
                switch (node.getNodeType())
                {
                case NodeType.E_WHILE:
                {
                    int       whiley    = 0;
                    WhileNode whilenode = (WhileNode)node;
                    grids.Add(getNextDiamond(x, y, node, path));
                    System.Windows.UIElement el = getNextDiamond(x, y, node, path);
                    el.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
                    System.Windows.Size size = el.DesiredSize;

                    y     += (int)size.Height + 20;
                    whiley = y - ((int)size.Height + 20) / 2;
                    shapes.AddRange(getNextLine(x, y));
                    y += 20;
                    shapes.AddRange(generateShapes(whilenode.loop, x, ref y, path));
                    shapes.Add(new Line()
                        {
                            X1 = x, X2 = x - 150, Y1 = y + 20, Y2 = y + 20, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x - 150, X2 = x - 150, Y1 = y + 20, Y2 = whiley, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x - 150, X2 = x, Y1 = whiley, Y2 = whiley, Stroke = Brushes.LightBlue
                        });

                    shapes.Add(new Line()
                        {
                            X1 = x, X2 = x + 150, Y1 = y - 10, Y2 = y - 10, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x + 150, X2 = x + 150, Y1 = y - 10, Y2 = whiley, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x + 150, X2 = x, Y1 = whiley, Y2 = whiley, Stroke = Brushes.LightBlue
                        });
                    shapes.AddRange(getArrows(x + (int)size.Width / 2 - 20, whiley, Direction.E_RIGHT));
                    if (NodeType.E_FOR == whilenode.loop.Last().getNodeType() ||
                        NodeType.E_WHILE == whilenode.loop.Last().getNodeType())
                    {
                    }
                    else
                    {
                        shapes.AddRange(getNextLine(x, y));
                        y += 20;
                    }
                    break;
                }

                case NodeType.E_FOR:
                {
                    int     whiley    = 0;
                    ForNode whilenode = (ForNode)node;
                    grids.Add(getNextDiamond(x, y, node, path));
                    System.Windows.UIElement el = getNextDiamond(x, y, node, path);
                    el.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
                    System.Windows.Size size = el.DesiredSize;

                    y     += (int)size.Height + 20;
                    whiley = y - ((int)size.Height + 20) / 2;
                    shapes.AddRange(getNextLine(x, y));
                    y += 20;
                    shapes.AddRange(generateShapes(whilenode.loop, x, ref y, path));
                    shapes.Add(new Line()
                        {
                            X1 = x, X2 = x - 150, Y1 = y + 20, Y2 = y + 20, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x - 150, X2 = x - 150, Y1 = y + 20, Y2 = whiley, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x - 150, X2 = x, Y1 = whiley, Y2 = whiley, Stroke = Brushes.LightBlue
                        });

                    shapes.Add(new Line()
                        {
                            X1 = x, X2 = x + 150, Y1 = y - 10, Y2 = y - 10, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x + 150, X2 = x + 150, Y1 = y - 10, Y2 = whiley, Stroke = Brushes.LightBlue
                        });
                    shapes.Add(new Line()
                        {
                            X1 = x + 150, X2 = x, Y1 = whiley, Y2 = whiley, Stroke = Brushes.LightBlue
                        });
                    shapes.AddRange(getArrows(x + (int)size.Width / 2, whiley, Direction.E_RIGHT));
                    if (NodeType.E_FOR == whilenode.loop.Last().getNodeType() ||
                        NodeType.E_WHILE == whilenode.loop.Last().getNodeType())
                    {
                    }
                    else
                    {
                        shapes.AddRange(getNextLine(x, y));
                        y += 20;
                    }
                    break;
                }

                case NodeType.E_IF:
                {
                    IfNode ifnode = (IfNode)node;
                    grids.Add(getNextDiamond(x, y, node, path));
                    int x1 = x;
                    int x2 = x;
                    y += 50;
                    int y1 = y;
                    int y2 = y;
                    if (ifnode.left.Count > 0)
                    {
                        x1 = x + 300;
                        shapes.AddRange(getNextifLine(x, y, x + 300));
                    }
                    if (ifnode.right.Count > 0)
                    {
                        x2 = x - 300;
                        shapes.AddRange(getNextifLine(x, y, x - 300));
                    }
                    y += 20;
                    int tmp = y;
                    if (ifnode.left.Count > 0)
                    {
                        shapes.AddRange(generateShapes(ifnode.left, x + 300, ref y, path));
                        y1 = y;
                        y += 20;
                    }
                    if (ifnode.right.Count > 0)
                    {
                        shapes.AddRange(generateShapes(ifnode.right, x - 300, ref tmp, path));
                        y2   = tmp;
                        tmp += 20;
                    }
                    if (y < tmp)
                    {
                        y = tmp;
                    }
                    if (ifnode.left.Count > 0)
                    {
                        if (NodeType.E_RETURN != ifnode.left.Last().getNodeType())
                        {
                            shapes.Add(new Line()
                                {
                                    X1 = x1, X2 = x, Y1 = y1, Y2 = y, Stroke = Brushes.LightBlue
                                });
                        }
                    }
                    else
                    {
                        shapes.Add(new Line()
                            {
                                X1 = x1, X2 = x, Y1 = y1, Y2 = y, Stroke = Brushes.LightBlue
                            });
                    }
                    if (ifnode.right.Count > 0)
                    {
                        if (NodeType.E_RETURN != ifnode.right.Last().getNodeType())
                        {
                            shapes.Add(new Line()
                                {
                                    X1 = x2, X2 = x, Y1 = y2, Y2 = y, Stroke = Brushes.LightBlue
                                });
                        }
                    }
                    else
                    {
                        shapes.Add(new Line()
                            {
                                X1 = x2, X2 = x, Y1 = y2, Y2 = y, Stroke = Brushes.LightBlue
                            });
                    }
                    break;
                }

                default:
                {
                    grids.Add(getNextRect(x, y, node, path));
                    System.Windows.UIElement el = getNextRect(x, y, node, path);
                    el.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
                    System.Windows.Size size = el.DesiredSize;
                    y += (int)size.Height;
                    if (node != nodes.Last())
                    {
                        shapes.AddRange(getNextLine(x, y));
                        y += 20;
                    }
                    break;
                }
                }
            }
            return(shapes);
        }
예제 #3
0
        public List <List <FlowGraphNode> > CalculateAllPathes(List <FlowGraphNode> nodes)
        {
            List <List <FlowGraphNode> > Pathes = new List <List <FlowGraphNode> >();

            foreach (FlowGraphNode node in nodes)
            {
                switch (node.getNodeType())
                {
                case NodeType.E_FOR:
                {
                    ForNode whilenode = (ForNode)node;
                    if (Pathes.Count == 0)
                    {
                        Pathes.Add(new List <FlowGraphNode>()
                            {
                                whilenode
                            });
                    }
                    else
                    {
                        for (int i = 0; i < Pathes.Count; i++)
                        {
                            if (NodeType.E_RETURN != Pathes[i].Last().getNodeType())
                            {
                                Pathes[i].Add(whilenode);
                            }
                        }
                    }
                    List <List <FlowGraphNode> > dublicate = new List <List <FlowGraphNode> >();
                    foreach (List <FlowGraphNode> ls in Pathes)
                    {
                        if (NodeType.E_RETURN != ls.Last().getNodeType())
                        {
                            List <FlowGraphNode> tmp = new List <FlowGraphNode>();
                            tmp.AddRange(ls);
                            dublicate.Add(tmp);
                        }
                    }
                    if (whilenode.loop != null)
                    {
                        List <List <FlowGraphNode> > recursive = CalculateAllPathes(whilenode.loop);

                        foreach (List <FlowGraphNode> ls in recursive)
                        {
                            for (int j = 0; j < Pathes.Count; j++)
                            {
                                if (NodeType.E_RETURN != Pathes[j].Last().getNodeType())
                                {
                                    Pathes[j].AddRange(ls);
                                }
                            }
                        }
                    }
                    foreach (List <FlowGraphNode> ls in dublicate)
                    {
                        Pathes.Add(ls);
                    }
                    break;
                }

                case NodeType.E_WHILE:
                {
                    WhileNode whilenode = (WhileNode)node;
                    if (Pathes.Count == 0)
                    {
                        Pathes.Add(new List <FlowGraphNode>()
                            {
                                whilenode
                            });
                    }
                    else
                    {
                        for (int i = 0; i < Pathes.Count; i++)
                        {
                            if (NodeType.E_RETURN != Pathes[i].Last().getNodeType())
                            {
                                Pathes[i].Add(whilenode);
                            }
                        }
                    }
                    List <List <FlowGraphNode> > dublicate = new List <List <FlowGraphNode> >();
                    foreach (List <FlowGraphNode> ls in Pathes)
                    {
                        if (NodeType.E_RETURN != ls.Last().getNodeType())
                        {
                            List <FlowGraphNode> tmp = new List <FlowGraphNode>();
                            tmp.AddRange(ls);
                            dublicate.Add(tmp);
                        }
                    }
                    if (whilenode.loop != null)
                    {
                        List <List <FlowGraphNode> > recursive = CalculateAllPathes(whilenode.loop);

                        foreach (List <FlowGraphNode> ls in recursive)
                        {
                            for (int j = 0; j < Pathes.Count; j++)
                            {
                                if (NodeType.E_RETURN != Pathes[j].Last().getNodeType())
                                {
                                    Pathes[j].AddRange(ls);
                                }
                            }
                        }
                    }
                    foreach (List <FlowGraphNode> ls in dublicate)
                    {
                        Pathes.Add(ls);
                    }
                    break;
                }

                case NodeType.E_IF:
                {
                    IfNode ifnode = (IfNode)node;
                    if (Pathes.Count == 0)
                    {
                        Pathes.Add(new List <FlowGraphNode>()
                            {
                                ifnode
                            });
                    }
                    else
                    {
                        for (int i = 0; i < Pathes.Count; i++)
                        {
                            if (NodeType.E_RETURN != Pathes[i].Last().getNodeType())
                            {
                                Pathes[i].Add(node);
                            }
                        }
                    }
                    List <List <FlowGraphNode> > dublicate = new List <List <FlowGraphNode> >();
                    foreach (List <FlowGraphNode> ls in Pathes)
                    {
                        if (NodeType.E_RETURN != ls.Last().getNodeType())
                        {
                            List <FlowGraphNode> tmp = new List <FlowGraphNode>();
                            tmp.AddRange(ls);
                            dublicate.Add(tmp);
                        }
                    }
                    if (ifnode.left != null)
                    {
                        List <List <FlowGraphNode> > recursive = CalculateAllPathes(ifnode.left);

                        foreach (List <FlowGraphNode> ls in recursive)
                        {
                            for (int j = 0; j < Pathes.Count; j++)
                            {
                                if (NodeType.E_RETURN != Pathes[j].Last().getNodeType())
                                {
                                    Pathes[j].AddRange(ls);
                                }
                            }
                        }
                    }
                    if (ifnode.right != null)
                    {
                        List <List <FlowGraphNode> > recursive = CalculateAllPathes(ifnode.right);

                        foreach (List <FlowGraphNode> ls in recursive)
                        {
                            for (int j = 0; j < dublicate.Count; j++)
                            {
                                if (NodeType.E_RETURN != dublicate[j].Last().getNodeType())
                                {
                                    dublicate[j].AddRange(ls);
                                }
                            }
                        }
                    }
                    foreach (List <FlowGraphNode> ls in dublicate)
                    {
                        Pathes.Add(ls);
                    }
                    break;
                }

                default:
                {
                    if (Pathes.Count == 0)
                    {
                        Pathes.Add(new List <FlowGraphNode>()
                            {
                                node
                            });
                    }
                    else
                    {
                        for (int i = 0; i < Pathes.Count; i++)
                        {
                            if (NodeType.E_RETURN != Pathes[i].Last().getNodeType())
                            {
                                Pathes[i].Add(node);
                            }
                        }
                    }
                    break;
                }
                }
            }
            return(Pathes);
        }