public void DoUndo(IGraphProcessingEnvironment procEnv) { procEnv.ReturnFromSubgraph(); procEnv.SwitchToSubgraph(_oldGraph); }
public void DoUndo(IGraphProcessingEnvironment procEnv) { procEnv.ReturnFromSubgraph(); procEnv.SwitchToSubgraph(_oldGraph); }
protected override bool ApplyImpl(IGraphProcessingEnvironment procEnv) { IGraph subgraph; if(AttributeName == null) subgraph = (IGraph)SubgraphVar.Value; else { IGraphElement elem = (IGraphElement)SubgraphVar.Value; subgraph = (IGraph)elem.GetAttribute(AttributeName); } procEnv.SwitchToSubgraph(subgraph); bool res = Seq.Apply(procEnv); procEnv.ReturnFromSubgraph(); return res; }
protected override bool ApplyImpl(IGraphProcessingEnvironment procEnv) { if(!ChooseRandom) { bool res; try { #if LOG_SEQUENCE_EXECUTION procEnv.Recorder.WriteLine("Applying rule all " + GetRuleCallString(procEnv)); #endif res = procEnv.ApplyRewrite(ParamBindings, -1, -1, Special, Test, Filters) > 0; } catch (NullReferenceException) { System.Console.Error.WriteLine("Null reference exception during rule execution (null parameter?): " + Symbol); throw; } #if LOG_SEQUENCE_EXECUTION if(res) { procEnv.Recorder.WriteLine("Matched/Applied " + Symbol); procEnv.Recorder.Flush(); } #endif return res; } else { // TODO: Code duplication! Compare with BaseGraph.ApplyRewrite. int curMaxMatches = procEnv.MaxMatches; object[] parameters; if(ParamBindings.ArgumentExpressions.Length > 0) { parameters = ParamBindings.Arguments; for(int i = 0; i < ParamBindings.ArgumentExpressions.Length; i++) { if(ParamBindings.ArgumentExpressions[i] != null) parameters[i] = ParamBindings.ArgumentExpressions[i].Evaluate(procEnv); } } else parameters = null; if(ParamBindings.Subgraph!=null) procEnv.SwitchToSubgraph((IGraph)ParamBindings.Subgraph.GetVariableValue(procEnv)); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StartLocal(); #endif IMatches matches; try { matches = ParamBindings.Action.Match(procEnv, curMaxMatches, parameters); for(int i = 0; i < Filters.Count; ++i) ParamBindings.Action.Filter(procEnv, matches, Filters[i]); } catch (NullReferenceException) { System.Console.Error.WriteLine("Null reference exception during rule execution (null parameter?): " + Symbol); throw; } #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StopMatch(); // total match time does NOT include listeners anymore #endif procEnv.PerformanceInfo.MatchesFound += matches.Count; procEnv.Matched(matches, null, Special); bool result = Rewrite(procEnv, matches, null); if(ParamBindings.Subgraph != null) procEnv.ReturnFromSubgraph(); return result; } }
// applies the sequence of/in the sequence definition protected bool ApplyImpl(SequenceInvocationParameterBindings sequenceInvocation, IGraphProcessingEnvironment procEnv) { if(sequenceInvocation.ArgumentExpressions.Length != InputVariables.Length) throw new Exception("Number of input parameters given and expected differ for " + Symbol); if(sequenceInvocation.ReturnVars.Length != OutputVariables.Length) throw new Exception("Number of output parameters given and expected differ for " + Symbol); // prefill the local input variables with the invocation values, read from parameter variables of the caller for(int i=0; i<sequenceInvocation.ArgumentExpressions.Length; ++i) { if(sequenceInvocation.ArgumentExpressions[i] != null) InputVariables[i].SetVariableValue(sequenceInvocation.ArgumentExpressions[i].Evaluate(procEnv), procEnv); else InputVariables[i].SetVariableValue(sequenceInvocation.Arguments[i], procEnv); } if(sequenceInvocation.Subgraph != null) procEnv.SwitchToSubgraph((IGraph)sequenceInvocation.Subgraph.GetVariableValue(procEnv)); bool success = Seq.Apply(procEnv); if(sequenceInvocation.Subgraph != null) procEnv.ReturnFromSubgraph(); if(success) { // postfill the return-to variables of the caller with the return values, read from the local output variables for(int i = 0; i < sequenceInvocation.ReturnVars.Length; i++) sequenceInvocation.ReturnVars[i].SetVariableValue(OutputVariables[i].GetVariableValue(procEnv), procEnv); } return success; }