예제 #1
0
 private static TreeElementType rewrite(TreeElementType apply, List <Tuple <string, TreeElementType> > variables, ITreeManipulationFacade <TreeElementType> treeManipulationFacade)
 {
     if (treeManipulationFacade.getType(apply) == ITreeManipulationFacade <TreeElementType> .EnumTreeElementType.VARIABLE)
     {
         TreeElementType variableValue = (TreeElementType)getVariableByName(variables, treeManipulationFacade.getVariableName(apply)).Clone();
         treeManipulationFacade.setType(variableValue, ITreeManipulationFacade <TreeElementType> .EnumTreeElementType.VALUE);
         return(variableValue);
     }
     else
     {
         for (int i = 0; i < treeManipulationFacade.getNumberOfChildren(apply); i++)
         {
             TreeElementType iterationApplyChildren = treeManipulationFacade.getChildren(apply, i);
             TreeElementType rewritten = rewrite(iterationApplyChildren, variables, treeManipulationFacade);
             treeManipulationFacade.setChildren(apply, i, rewritten);
         }
         return(apply);
     }
 }
예제 #2
0
        public static TreeElementType tryToApplyRulesRecursivly(List <Rule <TreeElementType> > rules, TreeElementType apply, ITreeManipulationFacade <TreeElementType> treeManipulationFacade)
        {
            TreeElementType rewritten = apply;

            foreach (Rule <TreeElementType> iterationRule in rules)
            {
                if (doesSourceConditionMatch(iterationRule.matching, apply, treeManipulationFacade))
                {
                    List <Tuple <string, TreeElementType> > variableAssignments = assignVariables(iterationRule, apply, treeManipulationFacade);

                    rewritten = rewrite(iterationRule.rewriteTarget, variableAssignments, treeManipulationFacade);
                    break;
                }
            }

            for (int i = 0; i < treeManipulationFacade.getNumberOfChildren(rewritten); i++)
            {
                TreeElementType rwrittenChildren = tryToApplyRulesRecursivly(rules, treeManipulationFacade.getChildren(rewritten, i), treeManipulationFacade);
                treeManipulationFacade.setChildren(rewritten, i, rwrittenChildren);
            }

            return(rewritten);
        }