public static MovePreviousLineRelatedCommentToInsideANode ( Production nodeToSearch, int indexOfTheRelatedInstruction, Production nodeToPut ) : void | ||
nodeToSearch | Production | |
indexOfTheRelatedInstruction | int | |
nodeToPut | Production | |
return | void |
/** * 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); }
// 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); }