// Kreira duplikat fragmenta! Dakle, svih čvorova u fragmentu!
        public static LabeledNode DuplicateFragment(this LabeledNode labeledNode)
        {
            var nodeDuplicate = labeledNode.CreateSimpleDuplicate();

            if (labeledNode.Parent != null)
            {
                var parentDuplicate = labeledNode.Parent.CreateSimpleDuplicate();
                nodeDuplicate.Parent = parentDuplicate;
            }

            foreach (var child in labeledNode.Children)
            {
                if (!child.IsFragmentRoot)
                {
                    nodeDuplicate.AddChild(DuplicateFragment(child));
                }
                else
                {
                    var childDuplicate = child.CreateSimpleDuplicate();
                    nodeDuplicate.AddChild(childDuplicate);
                }
            }

            return(nodeDuplicate);
        }
        private static void WriteFragmentString(LabeledNode labeledNode, StringWriter stringWriter)
        {
            // var fragmentString = $"({labeledNode.STInfo})";
            stringWriter.Write($"({labeledNode.STInfo} ");

            if (labeledNode.Children.Count > 0)
            {
                // var childrenString = "";

                foreach (var child in labeledNode.Children)
                {
                    if ((child.IsFragmentRoot) || !child.CanHaveType)
                    {
                        stringWriter.Write($"({child.STInfo}) ");
                    }
                    else
                    {
                        //childrenString += GetFragmentString(child);
                        WriteFragmentString(child, stringWriter);
                    }
                }

                // fragmentString = $"({labeledNode.STInfo} {childrenString} ) ";
            }

            stringWriter.Write(" ) ");
        }
        public static string GetFragmentString(this LabeledNode labeledNode)
        {
            var stringWriter = new StringWriter();

            WriteFragmentString(labeledNode, stringWriter);

            var retVal = stringWriter.ToString();

            stringWriter.Dispose();
            return(retVal);
        }
 // Finds nearest fragment root above, if such could exist.
 // Else, returns given node (assumption is that given node is root node, then)
 public static LabeledNode FindFullFragmentRoot(this LabeledNode labeledNode)
 {
     if (labeledNode.Parent != null)
     {
         return(labeledNode.Parent.FindFragmentRoot());
     }
     else
     {
         return(labeledNode);
     }
 }
示例#5
0
        public void VisitLabeledNode(LabeledNode a)
        {
            string label = Mark(a);

            _nodes.AppendLine($"{label}  [label = \"Labeled: {a.Label.Name}, statement\"]");

            a.Label.Visit(this);
            a.Stat.Visit(this);

            _edges.AppendLine($"{label} -> {Mark(a.Label)}");
            _edges.AppendLine($"{label} -> {Mark(a.Stat)}");
        }
 public bool CheckIfRelationshipsAreOK(LabeledNode node)
 {
     foreach (var child in node.Children)
     {
         if (child.Parent != node)
         {
             return(false);
         }
         if (!CheckIfRelationshipsAreOK(child))
         {
             return(false);
         }
     }
     return(true);
 }
        public static LabeledNode FindFragmentRoot(this LabeledNode labeledNode)
        {
            var fragmentRoot = labeledNode;

            while (!fragmentRoot.IsFragmentRoot)
            {
                if (fragmentRoot.IsTreeRoot())
                {
                    return(fragmentRoot);
                }

                fragmentRoot = fragmentRoot.Parent;
            }

            return(fragmentRoot);
        }
 /// <summary>
 /// Посещение узла с меткой
 /// </summary>
 /// <param name="l">Узел LabeledNode</param>
 public virtual void VisitLabeledNode(LabeledNode l)
 {
     Text += IndentStr();
     l.Label.Visit(this);
     Text += ":" + Environment.NewLine;
     if (!(l.Stat is BlockNode))
     {
         IndentPlus();
         l.Stat.Visit(this);
         Text += ";" + Environment.NewLine;
         IndentMinus();
     }
     else
     {
         l.Stat.Visit(this);
     }
 }
示例#9
0
        private LabeledNode FindMethod1(LabeledNode node)
        {
            foreach (var child in node.Children)
            {
                if (child.STInfo == "Method1")
                {
                    return(child);
                }
                else
                {
                    var descendant = FindMethod1(child);
                    if (descendant != null)
                    {
                        return(descendant);
                    }
                }
            }

            return(null);
        }
        public int WidthOfBinaryTree(TreeNode root)
        {
            if (root == null)
            {
                return(0);
            }
            var max   = 1;
            var queue = new Queue <LabeledNode>();

            queue.Enqueue(new LabeledNode(root, 1));
            while (queue.Count > 0)
            {
                var         queueSize = queue.Count;
                LabeledNode firstNode = null;
                while (queueSize > 0)
                {
                    var actual = queue.Dequeue();
                    if (actual.Node.left != null)
                    {
                        queue.Enqueue(new LabeledNode(actual.Node.left, actual.Position * 2));
                    }
                    if (actual.Node.right != null)
                    {
                        queue.Enqueue(new LabeledNode(actual.Node.right, (actual.Position * 2) + 1));
                    }
                    if (firstNode == null)
                    {
                        firstNode = actual;
                    }
                    else if (queueSize == 1)
                    {
                        max = Math.Max(max, actual.Position - firstNode.Position + 1);
                    }
                    queueSize--;
                }
            }

            return(max);
        }
        public override void VisitLabeledNode(LabeledNode l)
        {
            string labelName = l.Label.Name;
            // Создаем пустой оператор и указываем, что на него есть переход по метке
            var labeledNop = GetEmptyLabeledNode(labelName);

            // Добавляем метку и помеченный оператор в список помеченных операторов (это всегда нужно делать,
            // т.к. дальше по тексту могут оказаться goto на данную метку)
            labeledTANodes.Add(labelName, labeledNop);

            // Проверяем, не было ли по этой метке переходов, преобразованных ранее
            if (forwardGotos.ContainsKey(labelName))
            {
                // Если были, заполняем их поля меток и удаляем из списка ожидания
                foreach (var ta_goto in forwardGotos[labelName])
                {
                    ta_goto.TargetLabel = labeledNop.Label;
                }
                forwardGotos.Remove(labelName);
            }

            // Продолжаем отдельно разбор помеченного оператора как обычного
            l.Stat.Visit(this);
        }
示例#12
0
        public override void AddNodeType(LabeledNodeType givenType, LabeledNode node)
        {
            var trueType = LabeledNode.GetType(node);

            if (trueType.FullFragment != givenType.FullFragment ||
                trueType.Part1Fragment != givenType.Part1Fragment ||
                trueType.Part2Fragment != givenType.Part2Fragment)
            {
                throw new ArgumentException("Given type does not equal true type.");
            }

            if (!UsedTypes.ContainsKey(givenType.GetQuasiUniqueRepresentation()))
            {
                TypeNodes.Add(givenType, new List <LabeledNode>(10));
                UsedTypes.Add(givenType.GetQuasiUniqueRepresentation(), givenType);
                node.Type = givenType;
            }
            else
            {
                node.Type = UsedTypes[givenType.GetQuasiUniqueRepresentation()];
            }

            TypeNodes[node.Type].Add(node);
        }
示例#13
0
        static void Main(string[] args)
        {
            var drawingGraph = new Graph();

            drawingGraph.AddNode(new ComponentNode("Foo"));
            drawingGraph.AddNode(new ComponentNode("Bar", "Bar Component", "[Azure Functions]", "This is the Bar component, really really important!"));
            drawingGraph.AddNode(new ComponentNode("Component01", "First Component", null, "Bizar"));
            drawingGraph.AddNode(new ComponentNode("Component02"));
            drawingGraph.AddNode(new LabeledNode("Component05", new System.Collections.Generic.List <string> {
                "Component Nr. 5"
            }));
            drawingGraph.AddNode(new ComponentNode("Component06"));
            drawingGraph.AddNode(new ComponentNode("Component08"));

            drawingGraph.AddNode(new ComponentNode("Component03"));
            drawingGraph.AddNode(new ComponentNode("Component04"));
            drawingGraph.AddNode(new ComponentNode("Component07"));

            var subGraph = new Subgraph("Section01");

            subGraph.AddNode(drawingGraph.FindNode("Component02"));
            subGraph.AddNode(drawingGraph.FindNode("Component07"));
            subGraph.AddNode(drawingGraph.FindNode("Bar"));
            subGraph.AddNode(drawingGraph.FindNode("Component01"));
            drawingGraph.RootSubgraph.AddSubgraph(subGraph);


            var labels = new List <Svg.Label> {
                new Svg.Label("Component Nr. 9")
                {
                    Font  = new System.Drawing.Font("Consolas", 20f, System.Drawing.FontStyle.Bold),
                    Color = Color.Azure
                },
                new Svg.Label("This is the description. It can become quite large and if all goes to plan; it will wrap itself.")
                {
                    Color = Color.MediumOrchid
                }
            };
            var labeledNode = new LabeledNode("Component09", labels);

            labeledNode.SvgElement.BackgroundColor = Color.Maroon;
            drawingGraph.AddNode(labeledNode);

            drawingGraph.AddEdge("Foo", "Something", "Bar");
            drawingGraph.AddEdge("Bar", "Bar_Component01", "Component01");
            drawingGraph.AddEdge("Bar", "Bar_Component02", "Component02");
            drawingGraph.AddEdge("Component01", "Bar_Component01", "Component03");
            drawingGraph.AddEdge("Component01", "Bar_Component01", "Component02");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component04");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component05");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component06");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component07");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component08");
            drawingGraph.AddEdge("Component03", "Bar_Component01", "Component09");


            var doc = new Diagram(drawingGraph);

            doc.Run();
            System.Console.WriteLine(doc.ToString());
            TextCopy.ClipboardService.SetText(doc.ToString());
        }
        internal static string Example01()
        {
            var drawingGraph = new Graph();

            drawingGraph.AddNode(new ComponentNode("Foo"));
            drawingGraph.AddNode(new ComponentNode("Bar", "Bar Component", "[Azure Functions]", "This is the Bar component, really really important!"));
            drawingGraph.AddNode(new ComponentNode("Component01", "First Component", null, "Bizar"));
            drawingGraph.AddNode(new ComponentNode("Component02"));
            drawingGraph.AddNode(new LabeledNode("Component05", new List <string> {
                "Component Nr. 5"
            }));
            drawingGraph.AddNode(new ComponentNode("Component06"));
            drawingGraph.AddNode(new ComponentNode("Component08"));

            drawingGraph.AddNode(new ComponentNode("Component03"));
            drawingGraph.AddNode(new ComponentNode("Component04"));
            drawingGraph.AddNode(new ComponentNode("Component07"));

            var subGraph = new Subgraph("Section01");

            subGraph.AddNode(drawingGraph.FindNode("Component02"));
            subGraph.AddNode(drawingGraph.FindNode("Component07"));
            subGraph.AddNode(drawingGraph.FindNode("Bar"));
            subGraph.AddNode(drawingGraph.FindNode("Component01"));
            drawingGraph.RootSubgraph.AddSubgraph(subGraph);


            var labels = new List <SvgLabel> {
                new SvgLabel("Component Nr. 9")
                {
                    Font  = new System.Drawing.Font("Consolas", 20f, System.Drawing.FontStyle.Bold),
                    Color = Color.Azure
                },
                new SvgLabel("This is the description. It can become quite large and if all goes to plan; it will wrap itself.")
                {
                    Color = Color.MediumOrchid
                }
            };
            var labeledNode = new LabeledNode("Component09", labels);

            labeledNode.SvgElement.BackgroundColor = Color.Maroon;
            drawingGraph.AddNode(labeledNode);

            drawingGraph.AddEdge("Foo", "Something", "Bar");
            drawingGraph.AddEdge("Bar", "Bar_Component01", "Component01");
            drawingGraph.AddEdge("Bar", "Bar_Component02", "Component02");
            drawingGraph.AddEdge("Component01", "Bar_Component01", "Component03");
            drawingGraph.AddEdge("Component01", "Bar_Component01", "Component02");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component04");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component05");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component06");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component07");
            drawingGraph.AddEdge("Component02", "Bar_Component01", "Component08");
            drawingGraph.AddEdge("Component03", "Bar_Component01", "Component09");


            var diagram = new Diagram(drawingGraph);

            diagram.Run();
            return(diagram.ToString());
        }
        public static (LabeledNode full, LabeledNode part1, LabeledNode part2) GetRootNodesForTypeFragments(this LabeledNode labeledNode)
        {
            var oldIsFragmentRoot = labeledNode.IsFragmentRoot;

            labeledNode.IsFragmentRoot = false;
            var fragmentRoot = labeledNode.FindFragmentRoot();
            var full         = fragmentRoot.DuplicateFragment();

            labeledNode.IsFragmentRoot = true;
            var part1 = fragmentRoot.DuplicateFragment();
            var part2 = labeledNode.DuplicateFragment();

            labeledNode.IsFragmentRoot = oldIsFragmentRoot;

            return(full : full, part1 : part1, part2 : part2);
        }
 public virtual void VisitLabeledNode(LabeledNode l)
 {
 }
 public virtual void VisitLabeledNode(LabeledNode l)
 {
     l.Label.Visit(this);
     l.Stat.Visit(this);
 }