Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #3
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);
            }
        }