示例#1
0
        /// <summary>
        /// Returns if one node is an immediate child of the other
        /// </summary>
        /// <param name="fromguid"></param>
        /// <param name="toguid"></param>
        /// <returns></returns>
        public Boolean HasEdge(uint fromguid, uint toguid, int index)
        {
            Node n1 = GetNode(fromguid);
            Node n2 = GetNode(toguid);
            Dictionary <int, Node> d = n1.GetChildrenWithIndices();
            Node n;
            bool b = false;

            if (d.TryGetValue(index, out n))
            {
                if (n.Guid == n2.Guid)
                {
                    b = true;
                }
            }
            return(b);
        }
示例#2
0
        //
        // TODO Jun: Re-evaluate the topsort implementation
        //
        static void DFSVisit(Node node, Dictionary <Node, int> nodeStateMap, List <Node> list, AST statementList)
        {
            nodeStateMap.Add(node, VISITING);
            List <Node>            nodes   = node.GetChildren();
            Dictionary <int, Node> nodeDic = node.GetChildrenWithIndices();
            IEnumerable            iter    = nodes;
            int j = 0;

            foreach (Node nodeI in iter)
            {
                if (node is IdentNode && nodeI is LiteralNode)
                {
                    BuildIdentToLiteralStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is IdentNode)
                {
                    BuildIdentToIdentStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is Block)
                {
                    Block blocknode = (Block)nodeI;
                    if (GraphUtilities.AnalyzeString(blocknode.Name) == SnapshotNodeType.Literal)
                    {
                        LiteralNode literal = new LiteralNode(blocknode.content, nodeI.Guid);
                        BuildIdentToLiteralStatement(node, literal, statementList);
                    }
                    else
                    {
                        j = BuildIdentToCodeBlockIdentStatement(node, nodeI, nodes, statementList, j);
                    }
                }
                else if (node is Operator && nodeI is Block)
                {
                    j = BuildOperatorToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Block)
                {
                    j = BuildFuncToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is IdentNode)
                {
                    j = BuildFuncToIdentStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Operator)
                {
                    BuildIdentToOperatorStatement(node, statementList, nodeI);
                }
                else if (node is Operator && nodeI is Operator)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Func)
                {
                    BuildIdentToFuncStatement(node, nodeI, statementList);
                }
                else if (node is Func && nodeI is Func)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Operator && nodeI is Func)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Operator)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Operator && nodeI is ArrayNode) || (node is Operator && nodeI is LiteralNode))
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Func && nodeI is ArrayNode) || (node is Func && nodeI is LiteralNode))
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Block && nodeI is Block))
                {
                    BuildBlockToBlockStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Func))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Operator))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is IdentNode))
                {
                    BuildBlockToIdentStatement(node, nodeI, statementList);
                }
                /*Block to Operator*/
                else if (node is Block && nodeI is Operator)
                {
                    //BuildBlockToOperatorStatement(node, nodeI, statementList);
                }
                //else if ((node is Block && nodeI is Func))
                //{
                //    BuildBlockToBlockStatement(node, nodeI, statementList);
                //}
                else
                {
                    if (node is Operator)
                    {
                        if (nodes.IndexOf(nodeI, j) == 0)
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).left = nodeI;
                            ++j;
                        }
                        else
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).right = nodeI;
                        }
                    }
                    else if (node is Func)
                    {
                        Assignment   a = (Assignment)statementList.GetNode(node.Guid);
                        FunctionCall f = ((FunctionCall)a.right);
                        f.parameters[nodes.IndexOf(nodeI, j)] = nodeI;
                        j = 0;
                    }
                }

                if (IsNotVisited(nodeI, nodeStateMap))
                {
                    DFSVisit(nodeI, nodeStateMap, list, statementList);
                }
            }
            nodeStateMap[node] = VISITED;
            list.Add(node);
        }
示例#3
0
        //
        // TODO Jun: Re-evaluate the topsort implementation
        //
        static void DFSVisit(Node node, Dictionary<Node, int> nodeStateMap, List<Node> list, AST statementList)
        {
            nodeStateMap.Add(node, VISITING);
            List<Node> nodes = node.GetChildren();
            Dictionary<int, Node> nodeDic = node.GetChildrenWithIndices();
            IEnumerable iter = nodes;
            int j = 0;
            foreach (Node nodeI in iter)
            {
                if (node is IdentNode && nodeI is LiteralNode)
                {
                    BuildIdentToLiteralStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is IdentNode)
                {
                    BuildIdentToIdentStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is Block)
                {
                    Block blocknode = (Block)nodeI;
                    if (GraphBuilder.AnalyzeString(blocknode.Name) == SnapshotNodeType.Literal)
                    {
                        LiteralNode literal = new LiteralNode(blocknode.content, nodeI.Guid);
                        BuildIdentToLiteralStatement(node, literal, statementList);
                    }
                    else
                    {
                        j = BuildIdentToCodeBlockIdentStatement(node, nodeI, nodes, statementList, j);
                    }
                }
                else if (node is Operator && nodeI is Block)
                {
                    j = BuildOperatorToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Block)
                {
                    j = BuildFuncToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is IdentNode)
                {
                    j = BuildFuncToIdentStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Operator)
                {
                    BuildIdentToOperatorStatement(node, statementList, nodeI);
                }
                else if (node is Operator && nodeI is Operator)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Func)
                {
                    BuildIdentToFuncStatement(node, nodeI, statementList);
                }
                else if (node is Func && nodeI is Func)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Operator && nodeI is Func)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Operator)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Operator && nodeI is ArrayNode) || (node is Operator && nodeI is LiteralNode))
                { 
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Func && nodeI is ArrayNode) || (node is Func && nodeI is LiteralNode))
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Block && nodeI is Block))
                {
                    BuildBlockToBlockStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Func))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Operator))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is IdentNode))
                {
                    BuildBlockToIdentStatement(node, nodeI, statementList);
                }
                /*Block to Operator*/
                else if (node is Block && nodeI is Operator)
                {
                    //BuildBlockToOperatorStatement(node, nodeI, statementList);
                }
                //else if ((node is Block && nodeI is Func))
                //{
                //    BuildBlockToBlockStatement(node, nodeI, statementList);
                //}
                else
                {
                    if (node is Operator)
                    {
                        if (nodes.IndexOf(nodeI, j) == 0)
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).left = nodeI;
                            ++j;
                        }
                        else
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).right = nodeI;
                        }
                    }
                    else if (node is Func)
                    {
                        Assignment a = (Assignment)statementList.GetNode(node.Guid);
                        FunctionCall f = ((FunctionCall)a.right);
                        f.parameters[nodes.IndexOf(nodeI, j)] = nodeI;
                        j = 0;
                    }
                }

                if (IsNotVisited(nodeI, nodeStateMap))
                {
                    DFSVisit(nodeI, nodeStateMap, list, statementList);
                }
            }
            nodeStateMap[node] = VISITED;
            list.Add(node);
        }