Example #1
0
        private static int BuildIdentToCodeBlockIdentStatement(Node node, Node nodeI, List <Node> nodes, AST statementList, int j)
        {
            Block block = nodeI as Block;

            Validity.Assert(block != null);

            // Comment Jun: Check if the codeblock is a single ident
            string lhs = block.LHS;

            if (string.IsNullOrEmpty(lhs))
            {
                lhs = block.TrimName();
            }

            Assignment a = new Assignment((IdentNode)node, new IdentNode(lhs, block.Guid));

            if (statementList.nodeMap.ContainsKey(a.Guid))
            {
                int index = statementList.nodeList.IndexOf(statementList.GetNode(a.Guid));
                statementList.RemoveNode(statementList.GetNode(a.Guid));

                statementList.nodeList.Insert(index, a);
                statementList.nodeMap.Add(a.Guid, a);
            }
            else
            {
                statementList.AddNode(a);
            }

            return(++j);
        }
Example #2
0
        private static void BuildBlockToFuncStatement(Node node, Node nodeFunc, AST statementList)
        {
            Validity.Assert(node is Block);

            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                Assignment funcCall = (Assignment)statementList.GetNode(nodeFunc.Guid);

                Block block = node as Block;

                string lhs           = string.Empty;
                string content       = string.Empty;
                bool   isSingleIdent = string.IsNullOrEmpty(block.LHS);
                if (isSingleIdent)
                {
                    lhs = block.TrimName();

                    // Create the cnontents of the new block.
                    // The rhs of the block is the rhs of the function call statement
                    content = lhs + '=' + funcCall.left.Name;
                }
                else
                {
                    lhs     = block.LHS;
                    content = block.Name;
                }


                // Comment Jun: Remove the current codeblock first
                // Codeblock removal is guid dependent
                Node nodeToRemove = statementList.GetNode(node.Guid);
                int  index        = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                // Comment Jun: Create a new block using the current guid
                // This new codeblock represents the new contents
                // Comment Tron: Insert the new node into the index where the removed node was originally
                Block block2 = new Block(content, node.Guid);
                statementList.nodeList.Insert(index, block2);
                statementList.nodeMap.Add(block2.Guid, block2);

                // Comment Jun: Reflect the new changes to the original block
                (node as Block).SetData(block2.LHS, content);
            }
        }
Example #3
0
        private static void BuildBlockToBlockStatement(Node node, Node nodeI, AST statementList)
        {
            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                string content = string.Empty;
                Block  block   = nodeI as Block;
                Validity.Assert(block != null);
                Assignment a1 = null;
                Node       n1 = statementList.GetNode(node.Guid);
                if (n1 is Assignment)
                {
                    a1 = n1 as Assignment;

                    //
                    // Comment Jun:
                    // This condition basically checks if the single line codeblock is either a full expression or a single ident
                    // For now, in order to check for single ident, we check if the LHS if empty
                    // This needs refinement
                    bool isSingleIdent = string.IsNullOrEmpty((((Block)node).LHS));
                    if (isSingleIdent)
                    {
                        // This single line codeblock is a single identifier
                        a1.right.Name = block.LHS != "" ? block.LHS : block.Name.Replace(";", "").Trim();
                        content       = a1.ToScript();
                    }
                    else
                    {
                        // This single line codeblock is a full expression
                        content = ((Block)node).Name;
                    }

                    // Comment Jun: Create a new block that represents the new contents
                    Block block2 = new Block(content, node.Guid);
                    int   index  = statementList.nodeList.IndexOf(a1);
                    statementList.RemoveNode(a1);


                    statementList.nodeList.Insert(index, block2);
                    statementList.nodeMap.Add(block2.Guid, block2);

                    // Comment Jun: Reflect the new changes to the original block
                    (node as Block).SetData(block2.LHS, content);
                }
            }
        }
Example #4
0
        private static void BuildBlockToBlockStatement(Node node, Node nodeI, AST statementList)
        {
            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                string content = string.Empty;
                Block block = nodeI as Block;
                Validity.Assert(block != null);
                Assignment a1 = null;
                Node n1 = statementList.GetNode(node.Guid);
                if (n1 is Assignment)
                {
                    a1 = n1 as Assignment;

                    //
                    // Comment Jun:
                    // This condition basically checks if the single line codeblock is either a full expression or a single ident
                    // For now, in order to check for single ident, we check if the LHS if empty
                    // This needs refinement
                    bool isSingleIdent = string.IsNullOrEmpty((((Block)node).LHS));
                    if (isSingleIdent)
                    {
                        // This single line codeblock is a single identifier
                        a1.right.Name = block.LHS != "" ? block.LHS : block.Name.Replace(";", "").Trim();
                        content = a1.ToScript();
                    }
                    else
                    {
                        // This single line codeblock is a full expression
                        content = ((Block)node).Name;
                    }

                    // Comment Jun: Create a new block that represents the new contents
                    Block block2 = new Block(content, node.Guid);
                    int index = statementList.nodeList.IndexOf(a1);
                    statementList.RemoveNode(a1);

                    statementList.nodeList.Insert(index, block2);
                    statementList.nodeMap.Add(block2.Guid, block2);

                    // Comment Jun: Reflect the new changes to the original block
                    (node as Block).SetData(block2.LHS, content);
                }
            }
        }
Example #5
0
        private static void BuildBlockToIdentStatement(Node node, Node nodeIdent, AST statementList)
        {
            Validity.Assert(node is Block);

            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                IdentNode identNode = nodeIdent as IdentNode;
                Validity.Assert(null != identNode);

                Block block = node as Block;

                string lhs           = string.Empty;
                string content       = string.Empty;
                bool   isSingleIdent = string.IsNullOrEmpty(block.LHS);
                if (isSingleIdent)
                {
                    lhs = block.TrimName();
                }
                else
                {
                    lhs = block.LHS;
                }

                // Create the cnontents of the new block.
                content = lhs + '=' + identNode.Name;

                // Comment Jun: Remove the current codeblock first
                // Codeblock removal is guid dependent
                Node nodeToRemove = statementList.GetNode(node.Guid);
                int  index        = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                // Comment Jun: Create a new block using the current guid
                // This new codeblock represents the new contents
                Block block2 = new Block(content, node.Guid);
                statementList.nodeList.Insert(index, block2);
                statementList.nodeMap.Add(block2.Guid, block2);
                statementList.AddNode(block2);


                // Comment Jun: Reflect the new changes to the original block
                (node as Block).SetData(block2.LHS, content);
            }
        }
Example #6
0
        private static void BuildIdentToIdentStatement(Node node, Node nodeI, AST statementList)
        {
            Assignment a = new Assignment((IdentNode)node, (IdentNode)nodeI);

            if (statementList.nodeMap.ContainsKey(node.Guid))
            {
                Node nodeToRemove = statementList.GetNode(a.Guid);
                int  index        = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                statementList.nodeList.Insert(index, a);
                statementList.nodeMap.Add(a.Guid, a);
            }
            else
            {
                statementList.AddNode(a);
            }
        }
Example #7
0
        private static void BuildIdentToOperatorStatement(Node node, AST statementList, Node nodeI)
        {
            Assignment a2 = (Assignment)statementList.GetNode(nodeI.Guid);
            Assignment a  = new Assignment((IdentNode)node, (IdentNode)a2.left);

            if (statementList.nodeMap.ContainsKey(a.Guid))
            {
                Node nodeToRemove = statementList.GetNode(a.Guid);
                int  index        = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                statementList.nodeList.Insert(index, a);
                statementList.nodeMap.Add(a.Guid, a);
            }
            else
            {
                statementList.AddNode(a);
            }
        }
Example #8
0
        private static void BuildIdentToOperatorStatement(Node node, AST statementList, Node nodeI)
        {
            Assignment a2 = (Assignment)statementList.GetNode(nodeI.Guid);
            Assignment a = new Assignment((IdentNode)node, (IdentNode)a2.left);
            if (statementList.nodeMap.ContainsKey(a.Guid))
            {
                Node nodeToRemove = statementList.GetNode(a.Guid);
                int index = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                statementList.nodeList.Insert(index, a);
                statementList.nodeMap.Add(a.Guid, a);
            }
            else
                statementList.AddNode(a);
        }
Example #9
0
        private static void BuildIdentToIdentStatement(Node node, Node nodeI, AST statementList)
        {
            Assignment a = new Assignment((IdentNode)node, (IdentNode)nodeI);
            if (statementList.nodeMap.ContainsKey(node.Guid))
            {
                Node nodeToRemove = statementList.GetNode(a.Guid);
                int index = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                statementList.nodeList.Insert(index, a);
                statementList.nodeMap.Add(a.Guid, a);
            }
            else
                statementList.AddNode(a);
        }
Example #10
0
        private static int BuildIdentToCodeBlockIdentStatement(Node node, Node nodeI, List<Node> nodes, AST statementList, int j)
        {
            Block block = nodeI as Block;
            Validity.Assert(block != null);

            // Comment Jun: Check if the codeblock is a single ident
            string lhs = block.LHS;
            if (string.IsNullOrEmpty(lhs))
            {
                lhs = block.TrimName();
            }

            Assignment a = new Assignment((IdentNode)node, new IdentNode(lhs, block.Guid));
            if (statementList.nodeMap.ContainsKey(a.Guid))
            {
                int index = statementList.nodeList.IndexOf(statementList.GetNode(a.Guid));
                statementList.RemoveNode(statementList.GetNode(a.Guid));

                statementList.nodeList.Insert(index, a);
                statementList.nodeMap.Add(a.Guid, a);
            }
            else
            {
                statementList.AddNode(a);
            }
                
            return ++j;
        }
Example #11
0
        private static void BuildBlockToFuncStatement(Node node, Node nodeFunc, AST statementList)
        {
            Validity.Assert(node is Block);

            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                Assignment funcCall = (Assignment)statementList.GetNode(nodeFunc.Guid);

                Block block = node as Block;

                string lhs = string.Empty;
                string content = string.Empty;
                bool isSingleIdent = string.IsNullOrEmpty(block.LHS);
                if (isSingleIdent)
                {
                    lhs = block.TrimName();

                    // Create the cnontents of the new block. 
                    // The rhs of the block is the rhs of the function call statement
                    content = lhs + '=' + funcCall.left.Name;
                }
                else
                {
                    lhs = block.LHS;
                    content = block.Name;
                }


                // Comment Jun: Remove the current codeblock first
                // Codeblock removal is guid dependent
                Node nodeToRemove = statementList.GetNode(node.Guid);
                int index = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);
                
                // Comment Jun: Create a new block using the current guid
                // This new codeblock represents the new contents
                // Comment Tron: Insert the new node into the index where the removed node was originally
                Block block2 = new Block(content, node.Guid);
                statementList.nodeList.Insert(index, block2);
                statementList.nodeMap.Add(block2.Guid, block2);

                // Comment Jun: Reflect the new changes to the original block
                (node as Block).SetData(block2.LHS, content);
            }
        }
Example #12
0
        private static void BuildBlockToIdentStatement(Node node, Node nodeIdent, AST statementList)
        {
            Validity.Assert(node is Block);

            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                IdentNode identNode = nodeIdent as IdentNode;
                Validity.Assert(null != identNode);

                Block block = node as Block;

                string lhs = string.Empty;
                string content = string.Empty;
                bool isSingleIdent = string.IsNullOrEmpty(block.LHS);
                if (isSingleIdent)
                {
                    lhs = block.TrimName();
                }
                else
                {
                    lhs = block.LHS;
                }

                // Create the cnontents of the new block. 
                content = lhs + '=' + identNode.Name;

                // Comment Jun: Remove the current codeblock first
                // Codeblock removal is guid dependent
                Node nodeToRemove = statementList.GetNode(node.Guid);
                int index = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                // Comment Jun: Create a new block using the current guid
                // This new codeblock represents the new contents
                Block block2 = new Block(content, node.Guid);
                statementList.nodeList.Insert(index, block2);
                statementList.nodeMap.Add(block2.Guid, block2);
                statementList.AddNode(block2);


                // Comment Jun: Reflect the new changes to the original block
                (node as Block).SetData(block2.LHS, content);
            }
        }