GetChildren() public static method

public static GetChildren ( Production parent ) : ArrayList
parent Production
return System.Collections.ArrayList
Exemplo n.º 1
0
        public override Node ExitStatement(Production node)
        {
            if (replaceReturn == false)
            {
                return(node);
            }

            Node n = GrammaticaNodeUtils.FindChildOf(node, new string[1] {
                "Return_Statement"
            });

            if (n != null)
            {
                Node returnStatement = GrammaticaNodeUtils.FindChildOf(n, new string[1] {
                    "RETURN"
                });

                if (returnStatement != null)
                {
                    ArrayList returnStatementChildren = GrammaticaNodeUtils.GetChildren((Production)n);
                    returnStatementChildren.Insert(1, GrammaticaNodeUtils.CreateEqualToken());
                    returnStatementChildren.Insert(1, GrammaticaNodeUtils.CreateSpaceToken());
                }
            }
            return(node);
        }
Exemplo n.º 2
0
        public Node RemoveTypeFromMain(Production node)
        {
            Production tempType = (Production)GrammaticaNodeUtils.FindChildOf(node, "Type");
            ArrayList  tempVoid = GrammaticaNodeUtils.GetChildren(tempType);

            if (tempVoid != null)
            {
                tempVoid.RemoveAt(0);
                tempVoid.Insert(0, GrammaticaNodeUtils.CreateVoidToken());
            }

            return(node);
        }
Exemplo n.º 3
0
        public Node RemoveSemanticParams(Production node)
        {
            ArrayList lista = GrammaticaNodeUtils.GetChildren(node);
            ArrayList trash = new ArrayList();

            for (int i = 0; i < lista.Count; i++)
            {
                if ((((Node)lista[i]).GetName().Equals("DOUBLE_DOT")))
                {
                    trash.Add(lista[i]);
                }
                if ((((Node)lista[i]).GetName().Equals("SemanticalParameters")))
                {
                    trash.Add(lista[i]);
                }
                if ((((Node)lista[i]).GetName().Equals("Register_Func")))
                {
                    trash.Add(lista[i]);
                }
                if ((((Node)lista[i]).GetName().Equals("Packoffset_Func")))
                {
                    trash.Add(lista[i]);
                }
            }

            for (int j = 0; j < trash.Count; j++)
            {
                lista.Remove(trash[j]);
            }
            trash = new ArrayList();

            // Remove spaces left
            for (int i = lista.Count - 1; i >= 0; i--)
            {
                if ((((Node)lista[i]).GetName().Equals("WS")))
                {
                    trash.Add(lista[i]);
                }
                else
                {
                    break;
                }
            }

            for (int j = 0; j < trash.Count; j++)
            {
                lista.Remove(trash[j]);
            }

            return(node);
        }
Exemplo n.º 4
0
        // Dado um nodo pai, e o índice do nodo filho, esta função busca em índeces anteriores e posteriores
        // os comentários pertinentes e move para dentro do nodeToPut.
        // O objetivo desta função é preparar os nodos para serem movidos, levando consigo seus comentários.
        public static void MovePreviousLineRelatedCommentToInsideANode(Production nodeToSearch, int indexOfTheRelatedInstruction, Production nodeToPut)
        {
            ArrayList whereSearch = GrammaticaNodeUtils.GetChildren(nodeToSearch);
            ArrayList wherePut    = GrammaticaNodeUtils.GetChildren(nodeToPut);

            int WSPos = indexOfTheRelatedInstruction - 1;           // WS is always one before Function_Param

            if (WSPos >= 0)
            {
                Production WS = (Production)whereSearch[WSPos];
                if (WS.GetName().Equals("WS"))                   // WS is optional
                {
                    ArrayList tokens = GrammaticaNodeUtils.GetChildren(WS);

                    // Search the first newline
                    int afterTheFirstNewLine = tokens.Count;
                    for (int j = tokens.Count - 3; j > 0; j--)
                    {
                        if (((Token)tokens[j]).GetName().Equals("NEWLINE") ||
                            ((Token)tokens[j]).GetName().Equals("NEWLINE2") ||
                            ((Token)tokens[j]).GetName().Equals("NEWLINE3"))
                        {
                            afterTheFirstNewLine = j;
                            break;
                        }
                    }

                    // add all after the first newline to variable declaration
                    ArrayList toRemove = new ArrayList();
                    for (int j = afterTheFirstNewLine; j < tokens.Count; j++)
                    {
                        // adds to param childrens which will be moved to outside the function
                        if (!((Token)tokens[j]).GetName().Equals("WHITESPACE") &&
                            !((Token)tokens[j]).GetName().Equals("TAB"))
                        {
                            wherePut.Insert(0, tokens[j]);
                            toRemove.Add(tokens[j]);
                        }
                    }

                    for (int j = 0; j < toRemove.Count; j++)
                    {
                        tokens.Remove(toRemove[j]);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override Node ExitParameters(Production node)
        {
            ArrayList listOfParams = GrammaticaNodeUtils.GetChildren(node);
            ArrayList trash        = new ArrayList();

            for (int i = 0; i < listOfParams.Count; i++)
            {
                if ((((Node)listOfParams[i]).GetName().Equals("WS")))
                {
                    trash.Add(listOfParams[i]);
                }
            }

            for (int j = 0; j < trash.Count; j++)
            {
                listOfParams.Remove(trash[j]);
            }
            return(node);
        }
Exemplo n.º 6
0
        public bool MarkIfNodeIsFuncSemanticalParameter(Production node, string tokenType, string to)
        {
            ArrayList lista = GrammaticaNodeUtils.GetChildren(node);

            for (int i = 0; i < lista.Count; i++)
            {
                if ((((Node)lista[i]).GetName().Equals("SemanticalParameters")))
                {
                    Token name = (Token)GrammaticaNodeUtils.FindChildOf(node, new string[3] {
                        "SemanticalParameters", "InOutSemanticalParameters", tokenType
                    });
                    if (name != null)
                    {
                        replaceReturnFor = to;
                        return(true);
                    }
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        /**
         * Move the global vars to outside function declaration.
         */
        public override Node ExitFile(Production node)
        {
            ArrayList lista = GrammaticaNodeUtils.GetChildren(node);

            Node mainFunction = null;

            for (int i = 0; i < lista.Count; i++)
            {
                mainFunction = (Node)lista[i];

                if (mainFunction.GetName().Equals("Function_OR_Variable_Declaration"))
                {
                    // move related comment in previous line to inside this function.
                    GrammaticaNodeUtils.MovePreviousLineRelatedCommentToInsideANode(node, i, (Production)mainFunction);
                }
            }

            // search for the first main function.
            for (int i = 0; i < lista.Count; i++)
            {
                mainFunction = (Node)lista[i];
                if (mainFunction.GetName().Equals("Function_OR_Variable_Declaration"))
                {
                    if (mainFunctions.Contains(((Token)GrammaticaNodeUtils.FindChildOf(mainFunction, "IDENTIFIER")).GetImage()))
                    {
                        break;
                    }
                }
            }

            // put the global vars before the first MainFunction
            foreach (Node var in globalVars)
            {
                lista.Insert(lista.IndexOf(mainFunction), var);
                //GrammaticaNodeUtils.SetParent(var, node);
            }

            return(node);
        }
Exemplo n.º 8
0
        // Dado um nodo pai, e o índice do nodo filho, esta função busca em índeces anteriores e posteriores
        // os comentários pertinentes e move para dentro do nodeToPut.
        // O objetivo desta função é preparar os nodos para serem movidos, levando consigo seus comentários.
        public static void MoveSameLineRelatedCommentToInsideANode(Production nodeToSearch, int indexOfTheRelatedInstruction, Production nodeToPut)
        {
            ArrayList whereSearch = GrammaticaNodeUtils.GetChildren(nodeToSearch);
            ArrayList wherePut    = GrammaticaNodeUtils.GetChildren(nodeToPut);

            // find related comment after the comma and before the \n
            Production relatedWS    = null;
            Token      relatedComma = null;
            // PARAM [WS] COMMA [WS]
            int WSPos = indexOfTheRelatedInstruction + 2;           // WS is always one before Function_Param

            if (WSPos <= whereSearch.Count)
            {
                relatedWS = (Production)whereSearch[WSPos];
                if (!relatedWS.GetName().Equals("WS"))                   // First WS is optional
                {
                    relatedWS    = null;
                    relatedComma = (Token)whereSearch[WSPos];

                    WSPos++;
                    if (WSPos <= whereSearch.Count)
                    {
                        relatedWS = (Production)whereSearch[WSPos];
                    }
                }
                else
                {
                    relatedComma = (Token)whereSearch[WSPos - 1];
                }
            }

            // move to related comment after the comma and before the \n
            if (relatedWS != null)
            {
                ArrayList toRemove = new ArrayList();
                // add all after the comma and before newline
                ArrayList tokens = GrammaticaNodeUtils.GetChildren(relatedWS);
                for (int j = 0; j < tokens.Count; j++)
                {
                    // adds to param childrens which will be moved to outside the function
                    if (((Token)tokens[j]).GetName().Equals("NEWLINE") ||
                        ((Token)tokens[j]).GetName().Equals("NEWLINE2") ||
                        ((Token)tokens[j]).GetName().Equals("NEWLINE3"))
                    {
                        wherePut.Add(tokens[j]);
                        toRemove.Add(tokens[j]);
                        break;
                    }
                    wherePut.Add(tokens[j]);
                    toRemove.Add(tokens[j]);
                }
                tokens.Clear();
                for (int j = 0; j < toRemove.Count; j++)
                {
                    tokens.Remove(toRemove[j]);
                }
            }

            // remove comma
            whereSearch.Remove(relatedComma);
        }
Exemplo n.º 9
0
        // For each param in every main HLSL function
        // Move the uniform and varying params outside the function with his own comments
        public override Node ExitListOfParams(Production node)
        {
            ArrayList listOfParams = GrammaticaNodeUtils.GetChildren(node);

            // Only main mainFunctions.
            // Based on the presence of in, out or inout keywords

            if (!isMain)
            {
                return(node);
            }

            isMain = false;
            // Searching params that will be removed at ExitFunctionParam
            for (int i = 0; i < listOfParams.Count; i++)
            {
                if (!(listOfParams[i] is Production))
                {
                    continue;
                }


                Production functionParam = (Production)listOfParams[i];

                functionParam = (Production)CheckIfThisNodeIsSemanticAndRemoveIfItIs(functionParam);


                // Only uniform params are moved
                Node n = GrammaticaNodeUtils.FindChildOf(functionParam,
                                                         new string[1] {
                    "Variable_Declaration"
                });

                if (n != null)                   // Param found
                // Getting childrens of it


                {
                    Production variableDeclaration = (Production)n;
                    variableDeclaration = (Production)RemoveSemanticParams(variableDeclaration);


                    ArrayList variableDeclarationChildren = GrammaticaNodeUtils.GetChildren(variableDeclaration);

                    // add dot_comma and new line
                    variableDeclarationChildren.Add(GrammaticaNodeUtils.CreateDotCommaToken());

                    // move related comment in previous line to inside this param.
                    GrammaticaNodeUtils.MovePreviousLineRelatedCommentToInsideANode(node, i, variableDeclaration);
                    // move related commnet in the same line after the comma but before \n to this param.
                    GrammaticaNodeUtils.MoveSameLineRelatedCommentToInsideANode(node, i, variableDeclaration);

                    // add varying to all non-uniform parameters
                    Node hasUniform = GrammaticaNodeUtils.FindChildOf(variableDeclaration,
                                                                      new string[2] {
                        "Storage_Class", "UNIFORM"
                    });

                    if (hasUniform == null)
                    {
                        GrammaticaNodeUtils.GetChildren(variableDeclaration).Insert(0, GrammaticaNodeUtils.CreateSpaceToken());
                        GrammaticaNodeUtils.GetChildren(variableDeclaration).Insert(0, GrammaticaNodeUtils.CreateVaryingToken());
                        GrammaticaNodeUtils.GetChildren(variableDeclaration).Insert(0, GrammaticaNodeUtils.CreateNewLineToken());
                    }

                    // move uniform to outside.
                    globalVars.Add(variableDeclaration);

                    // remove from param.
                    GrammaticaNodeUtils.GetChildren(functionParam).Remove(variableDeclaration);
                }
            }

            ArrayList trash = new ArrayList();

            // cleaning the trash: Spaces, commas and newlines before the ) of the function
            for (int i = listOfParams.Count - 1; i >= 0; i--)
            {
                if (listOfParams[i] is Production)
                {
                    if (((Production)listOfParams[i]).GetChildCount() == 0 ||
                        ((Production)listOfParams[i]).GetName().Equals("WS"))
                    {
                        trash.Add(listOfParams[i]);
                    }
                    else
                    {
                        break;
                    }
                }

                if (listOfParams[i] is Token)
                {
                    if (((Token)listOfParams[i]).GetName().Equals("COMMA"))
                    {
                        trash.Add(listOfParams[i]);
                    }
                }
            }

            for (int j = 0; j < trash.Count; j++)
            {
                listOfParams.Remove(trash[j]);
            }


            return(node);
        }
Exemplo n.º 10
0
        public override Node ExitFunctionConstructorCallOrVariableDeclaration(Production node)
        {
            Token identifier = (Token)GrammaticaNodeUtils.FindChildOf(node, new string[2] {
                "Type", "IDENTIFIER"
            });

            if (identifier == null)
            {
                return(node);
            }

            replaceIntrinsicFunc(identifier);

            // mul(term, term) => term * term
            if (identifier.GetImage().Equals("mul"))
            {
                identifier.AddValue("");

                Node virgula = GrammaticaNodeUtils.FindChildOf(node, new string[2] {
                    "PartOf_Constructor_Call", "COMMA"
                });
                virgula.AddValue(" * ");
            }

            // cross(T,N) => cross(N,T).
            if (identifier.GetImage().Equals("cross"))
            {
                Production listOfParam = (Production)GrammaticaNodeUtils.FindChildOf(node, "PartOf_Constructor_Call");

                Node exp1 = GrammaticaNodeUtils.FindChildOf(listOfParam, "Expression", 1);
                Node exp2 = GrammaticaNodeUtils.FindChildOf(listOfParam, "Expression", 2);

                GrammaticaNodeUtils.SwapChildrenPosition(listOfParam, exp1, exp2);
            }

            // saturate(x) => clamp(x,0.0,1.0).
            if (identifier.GetImage().Equals("saturate"))
            {
                identifier.AddValue("clamp");

                var listOfParam = (Production)GrammaticaNodeUtils.FindChildOf(node, "PartOf_Constructor_Call");
                var children    = GrammaticaNodeUtils.GetChildren(listOfParam);
                children.Insert(2, GrammaticaNodeUtils.CreateCommaToken());
                children.Insert(3, GrammaticaNodeUtils.CreateNumberToken(0.0f));
                children.Insert(4, GrammaticaNodeUtils.CreateCommaToken());
                children.Insert(5, GrammaticaNodeUtils.CreateNumberToken(1.0f));
            }

            // add dependent function
            Node n = GrammaticaNodeUtils.FindChildOf(node, "PartOf_Constructor_Call");

            if (n != null && identifier != null && functionScope != null)
            {
                // function call or constructor call.

                dependencyGraph.SearchDependant(identifier.GetImage()).AddCallsBy(functionScope);
            }

            // Adds only globalVars.

            if (!scopeVars.Contains(identifier.GetImage()))
            {
                dependencyGraph.SearchDependant(identifier.GetImage()).AddCallsBy(functionScope);
            }


            return(node);
        }