public IMatches[] MatchForQuery(params ActionCall[] actions) { IMatches[] matchesArray = new IMatches[actions.Length]; #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StartLocal(); #endif int matchesFound = 0; for (int i = 0; i < actions.Length; ++i) { ActionCall actionCall = actions[i]; IMatches matches = actionCall.Action.Match(this, actionCall.MaxMatches, actionCall.Arguments); matchesFound += matches.Count; matches = matches.Clone(); // must be cloned before the next iteration step, as that could be the same action matchesArray[i] = matches; } #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopMatch(); #endif PerformanceInfo.MatchesFound += matchesFound; if (matchesFound > 0) { PreMatched(matchesArray); } return(matchesArray); }
public IMatches[] MatchWithoutEvent(params ActionCall[] actions) { IMatches[] matchesArray = new IMatches[actions.Length]; #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StartLocal(); #endif int matchesFound = 0; for (int i = 0; i < actions.Length; ++i) { ActionCall actionCall = actions[i]; IMatches matches = actionCall.Action.Match(this, actionCall.MaxMatches, actionCall.Arguments); matchesFound += matches.Count; matchesArray[i] = matches; } #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopMatch(); #endif PerformanceInfo.MatchesFound += matchesFound; if (matchesFound > 0) { PreMatched(matchesArray); } return(matchesArray); }
/// <summary> /// Searches for a symmetric partner for the match at the index in this /// Returns true if it was possible in the end to map every match in this to a match in that /// </summary> private static bool AreIterationsSymmetric(IMatches this_, IMatches that, IGraph graph, int index) { if (index >= this_.Count) { return(true); } for (int j = 0; j < that.Count; ++j) { if (that.GetMatch(j).IsMarked()) { continue; } if (!AreSymmetric(this_.GetMatch(index), that.GetMatch(j), graph)) { continue; } that.GetMatch(j).Mark(true); bool wereSymmetric = AreIterationsSymmetric(this_, that, graph, index + 1); that.GetMatch(j).Mark(false); if (wereSymmetric) { return(true); } } return(false); }
void AfterFinish(IMatches matches, bool special) { foreach (RecordingState recordingState in recordings.Values) { recordingState.writer.WriteLine("# ..rewritten " + matches.Producer.Name); } }
void AssertAllUnmappedAfterMatch(IMatches matches, bool special) { foreach (INode node in graph.GetCompatibleNodes(graph.Model.NodeModel.RootType)) { LGSPNode lnode = (LGSPNode)node; if (lnode.mappedTo != 0) { throw new Exception("Node \"" + graph.GetElementName(lnode) + "\" not unmapped by action \"" + matches.Producer.Name + "\"!"); } if (lnode.negMappedTo != 0) { throw new Exception("Node \"" + graph.GetElementName(lnode) + "\" not neg-unmapped by action \"" + matches.Producer.Name + "\"!"); } } foreach (IEdge edge in graph.GetCompatibleEdges(graph.Model.EdgeModel.RootType)) { LGSPEdge ledge = (LGSPEdge)edge; if (ledge.mappedTo != 0) { throw new Exception("Edge \"" + graph.GetElementName(ledge) + "\" not unmapped by action \"" + matches.Producer.Name + "\"!"); } if (ledge.negMappedTo != 0) { throw new Exception("Edge \"" + graph.GetElementName(ledge) + "\" not neg-unmapped by action \"" + matches.Producer.Name + "\"!"); } } }
public void Finished(IMatches matches, bool special) { if (OnFinished != null) { OnFinished(matches, special); } }
public MatchAddController(IMatchAdd AddMatch, IMatches match, IPlayers iPlayers, IMatchParticipant iMP) { _AddMatch = AddMatch; _match = match; _allPlayers = iPlayers; _allMP = iMP; }
public void Finishing(IMatches matches, bool special) { if (OnFinishing != null) { OnFinishing(matches, special); } }
public IMatches MatchForQuery(IAction action, object[] arguments, int localMaxMatches) { IMatches matches = MatchWithoutEvent(action, arguments, localMaxMatches); matches = matches.Clone(); return(matches); }
public void Matched(IMatches matches, IMatch match, bool special) { if (OnMatched != null) { OnMatched(matches, match, special); } }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='uscId'> /// </param> /// <param name='match'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> PostAsync(this IMatches operations, string uscId, USCPEApiDTOExploreHostingMatch match, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostWithHttpMessagesAsync(uscId, match, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public void FilterAssign(IMatches matches, FilterCallWithLambdaExpression filterCall) { if (filterCall.arrayAccess != null) { List <IMatch> matchListCopy = new List <IMatch>(); foreach (IMatch match in matches) { matchListCopy.Add(match.Clone()); } filterCall.arrayAccess.SetVariableValue(matchListCopy, this); } int index = 0; foreach (IMatch match in matches) { if (filterCall.index != null) { filterCall.index.SetVariableValue(index, this); } filterCall.element.SetVariableValue(match, this); object result = filterCall.lambdaExpression.Evaluate(this); match.SetMember(filterCall.Entity, result); ++index; } }
public void FilterRemoveIf(IMatches matches, FilterCallWithLambdaExpression filterCall) { List <IMatch> matchList = matches.ToList(); if (filterCall.arrayAccess != null) { List <IMatch> matchListCopy = new List <IMatch>(matchList); filterCall.arrayAccess.SetVariableValue(matchListCopy, this); } for (int index = 0; index < matchList.Count; ++index) { if (filterCall.index != null) { filterCall.index.SetVariableValue(index, this); } IMatch match = matchList[index]; filterCall.element.SetVariableValue(match, this); object result = filterCall.lambdaExpression.Evaluate(this); if ((bool)result) { matchList[index] = null; } } matches.FromList(); }
public string ToString(object data, INamedGraph graph, params object[] additionalData) { StringBuilder sb = new StringBuilder(); sb.Append(ToString(debuggingEvent)); sb.Append(" "); switch (debuggingEvent) { case SubruleDebuggingEvent.Add: case SubruleDebuggingEvent.Rem: case SubruleDebuggingEvent.Emit: case SubruleDebuggingEvent.Halt: case SubruleDebuggingEvent.Highlight: { string message = (string)data; sb.Append("\""); sb.Append(message); sb.Append("\""); for (int i = 0; i < additionalData.Length; ++i) { sb.Append(" "); sb.Append(EmitHelper.Clip(EmitHelper.ToStringAutomatic(additionalData[i], graph, false, null, null), 120)); } break; } case SubruleDebuggingEvent.Match: { IMatches matches = (IMatches)data; sb.Append(matches.Producer.PackagePrefixedName); break; } case SubruleDebuggingEvent.New: case SubruleDebuggingEvent.Delete: case SubruleDebuggingEvent.Retype: case SubruleDebuggingEvent.SetAttributes: { IGraphElement elem = (IGraphElement)data; sb.Append(graph.GetElementName(elem)); sb.Append(":"); sb.Append(elem.Type.Name); if (additionalData.Length > 0) { sb.Append("."); // the attribute name sb.Append((string)additionalData[0]); } break; } default: return("INTERNAL FAILURE, unknown SubruleDebuggingConfigurationRule"); } sb.Append(" triggers "); sb.Append(ToString()); return(sb.ToString()); }
//////////////////////////////////////////////////////////////////////// void BeforeFinish(IMatches matches, bool special) { foreach (RecordingState recordingState in recordings.Values) { recordingState.writer.WriteLine("# rewriting " + matches.Producer.Name + ".."); } }
public IMatches Match(IAction action, object[] arguments, int localMaxMatches, bool special, List <FilterCall> filters) { int curMaxMatches = (localMaxMatches > 0) ? localMaxMatches : MaxMatches; #if DEBUGACTIONS || MATCHREWRITEDETAIL // spread over multiple files now, search for the corresponding defines to reactivate PerformanceInfo.StartLocal(); #endif IMatches matches = action.Match(this, curMaxMatches, arguments); #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopMatch(); #endif PerformanceInfo.MatchesFound += matches.Count; for (int i = 0; i < filters.Count; ++i) { action.Filter(this, matches, filters[i]); } if (matches.Count > 0) // ensure that Matched is only called when a match exists { Matched(matches, null, special); } return(matches); }
void DoEdge1() { graph = new StdGraph(); actions = new edge1Actions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // use graph rewrite sequence procEnv.ApplyGraphRewriteSequence("init3"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); // use old inexact interface IMatches matches = actions.GetAction("findTripleCircle").Match(procEnv, 0, null); Console.WriteLine(matches.Count + " matches found."); // use new exact interface IMatchesExact <Rule_findTripleCircle.IMatch_findTripleCircle> matchesExact = actions.findTripleCircle.Match(procEnv, 0); Console.WriteLine(matchesExact.Count + " matches found."); actions.findTripleCircle.Modify(procEnv, matchesExact.FirstExact); // rewrite first match (largely nop, as findTripleCircle is a test) }
public void PreMatched(IMatches matches) { singleElementMatchesArray[0] = matches; if (OnPreMatched != null) { OnPreMatched(singleElementMatchesArray); } }
/// <summary> /// Checks whether the iterated matches are symmetric, /// i.e. are covering the same spot in the graph with a permutation of the single matches /// </summary> private static bool AreIterationsSymmetric(IMatches this_, IMatches that, IGraph graph) { if (this_.Count != that.Count) { return(false); } return(AreIterationsSymmetric(this_, that, graph, 0)); }
public void Finishing(IMatches matches, bool special) { BeforeFinishHandler handler = OnFinishing; if (handler != null) { handler(matches, special); } }
public void Finished(IMatches matches, bool special) { AfterFinishHandler handler = OnFinished; if (handler != null) { handler(matches, special); } }
public void Matched(IMatches matches, IMatch match, bool special) { AfterMatchHandler handler = OnMatched; if (handler != null) { handler(matches, match, special); } }
public static bool ChooseMatch(IDebuggerEnvironment env, int matchToApply, IMatches matches, int numFurtherMatchesToApply, Sequence seq, out int newMatchToRewrite) { newMatchToRewrite = matchToApply; do { ConsoleKeyInfo key = env.ReadKeyWithCancel(); switch (key.KeyChar) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': int num = key.KeyChar - '0'; if (num >= matches.Count) { Console.WriteLine("You must specify a number between 0 and " + (matches.Count - 1) + "!"); break; } newMatchToRewrite = num; return(false); case 'e': Console.Write("Enter number of match to show: "); String numStr = Console.ReadLine(); if (int.TryParse(numStr, out num)) { if (num < 0 || num >= matches.Count) { Console.WriteLine("You must specify a number between 0 and " + (matches.Count - 1) + "!"); break; } newMatchToRewrite = num; return(false); } Console.WriteLine("You must enter a valid integer number!"); return(false); case 's': case 'n': return(true); default: Console.WriteLine("Illegal choice (Key = " + key.Key + ")! Only (0)...(9), (e)nter number, (s)/(n) to commit and continue allowed! "); break; } }while(true); }
public MatchesController( CricketContext context, UserManager <IdentityUser <int> > userManager, IMatches matches, IMapper mapper, IHostingEnvironment env) { _context = context; _userManager = userManager; _mapper = mapper; _matches = matches; _env = env; }
public MatchesController( CricketContext context, UserManager <ApplicationUser> userManager, IMatches matches, IMapper mapper, IHostingEnvironment env, IHostingEnvironment hosting) { _context = context; _userManager = userManager; _mapper = mapper; _matches = matches; _env = env; _hosting = hosting; }
private void DumpOnFinishing(IMatches matches, bool special) { int i = 1; impl.debugOut.WriteLine("Matched " + matches.Producer.Name + " rule:"); foreach (IMatch match in matches) { impl.debugOut.WriteLine(" - " + i + ". match:"); DumpMatch(match, " "); ++i; } }
public List <object[]> Replace(IMatches matches, int which) { List <object[]> returns; object[] retElems; if (which != -1) { if (which < 0 || which >= matches.Count) { throw new ArgumentOutOfRangeException("\"which\" is out of range!"); } returns = matches.Producer.Reserve(0); retElems = matches.Producer.Modify(this, matches.GetMatch(which)); returns.Add(retElems); ++PerformanceInfo.RewritesPerformed; } else { returns = matches.Producer.Reserve(matches.Count); int curResultNum = 0; bool first = true; foreach (IMatch match in matches) { if (first) { first = false; } else if (OnRewritingNextMatch != null) { OnRewritingNextMatch(); } retElems = matches.Producer.Modify(this, match); object[] curResult = returns[curResultNum]; retElems.CopyTo(curResult, 0); ++PerformanceInfo.RewritesPerformed; ++curResultNum; } } return(returns); }
public List <object[]> ApplyRewrite(IAction action, IGraph subgraph, object[] arguments, int which, int localMaxMatches, bool special, bool test, List <FilterCall> filters, out int numMatches) { if (subgraph != null) { SwitchToSubgraph(subgraph); } IMatches matches = Match(action, arguments, localMaxMatches, special, filters); if (matches.Count == 0) { if (subgraph != null) { ReturnFromSubgraph(); } numMatches = 0; return(emptyList); } if (test) { if (subgraph != null) { ReturnFromSubgraph(); } numMatches = matches.Count; return(emptyList); } Finishing(matches, special); #if DEBUGACTIONS || MATCHREWRITEDETAIL // spread over multiple files now, search for the corresponding defines to reactivate PerformanceInfo.StartLocal(); #endif List <object[]> retElemsList = Replace(matches, which); #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopRewrite(); #endif Finished(matches, special); if (subgraph != null) { ReturnFromSubgraph(); } numMatches = matches.Count; return(retElemsList); }
public IMatches MatchWithoutEvent(IAction action, object[] arguments, int localMaxMatches) { int curMaxMatches = (localMaxMatches > 0) ? localMaxMatches : MaxMatches; #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StartLocal(); #endif IMatches matches = action.Match(this, curMaxMatches, arguments); #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopMatch(); #endif PerformanceInfo.MatchesFound += matches.Count; return(matches); }
public List <object[]> Replace(IMatches matches, int which) { List <object[]> returns; object[] retElems = null; if (which != -1) { if (which < 0 || which >= matches.Count) { throw new ArgumentOutOfRangeException("\"which\" is out of range!"); } returns = matches.Producer.Reserve(0); retElems = matches.Producer.Modify(this, matches.GetMatch(which)); returns.Add(retElems); PerformanceInfo.RewritesPerformed++; } else { bool first = true; returns = matches.Producer.Reserve(matches.Count); int curResultNum = 0; foreach (IMatch match in matches) { if (first) { first = false; } else if (OnRewritingNextMatch != null) { OnRewritingNextMatch(); } retElems = matches.Producer.Modify(this, match); object[] curResult = returns[curResultNum]; for (int i = 0; i < retElems.Length; ++i) { curResult[i] = retElems[i]; } PerformanceInfo.RewritesPerformed++; curResultNum++; } if (retElems == null) { retElems = Sequence.NoElems; } } return(returns); }
//////////////////////////////////////////////////////////////////////// void BeforeFinish(IMatches matches, bool special) { foreach(RecordingState recordingState in recordings.Values) recordingState.writer.WriteLine("# rewriting " + matches.Producer.Name + ".."); }
/// <summary> /// Dumps the given matches. /// </summary> /// <param name="dumper">The graph dumper to be used.</param> /// <param name="dumpInfo">Specifies how the graph shall be dumped.</param> /// <param name="matches">An IMatches object containing the matches.</param> /// <param name="which">Which match to dump, or AllMatches for dumping all matches /// adding connections between them, or OnlyMatches to dump the matches only</param> public static void DumpMatchOnly(IDumper dumper, DumpInfo dumpInfo, IMatches matches, DumpMatchSpecial which, ref Set<INode> matchedNodes, ref Set<INode> multiMatchedNodes, ref Set<IEdge> matchedEdges, ref Set<IEdge> multiMatchedEdges) { matchedNodes = new Set<INode>(); matchedEdges = new Set<IEdge>(); if((int)which >= 0 && (int)which < matches.Count) { // Show exactly one match IMatch match = matches.GetMatch((int)which); matchedNodes.Add(match.Nodes); matchedEdges.Add(match.Edges); } else { GrColor vnodeColor = dumpInfo.GetNodeDumpTypeColor(GrElemDumpType.VirtualMatch); GrColor vedgeColor = dumpInfo.GetEdgeDumpTypeColor(GrElemDumpType.VirtualMatch); GrColor vnodeBorderColor = dumpInfo.GetNodeDumpTypeBorderColor(GrElemDumpType.VirtualMatch); GrColor vnodeTextColor = dumpInfo.GetNodeDumpTypeTextColor(GrElemDumpType.VirtualMatch); GrColor vedgeTextColor = dumpInfo.GetEdgeDumpTypeTextColor(GrElemDumpType.VirtualMatch); GrNodeShape vnodeShape = dumpInfo.GetNodeDumpTypeShape(GrElemDumpType.VirtualMatch); GrLineStyle vedgeLineStyle = dumpInfo.GetEdgeDumpTypeLineStyle(GrElemDumpType.VirtualMatch); int vedgeThickness = dumpInfo.GetEdgeDumpTypeThickness(GrElemDumpType.VirtualMatch); multiMatchedNodes = new Set<INode>(); multiMatchedEdges = new Set<IEdge>(); // TODO: May edges to nodes be dumped before those nodes exist?? // TODO: Should indices in strings start at 0 or 1? (original: 0) // Dump all matches with virtual nodes int i = 0; foreach(IMatch match in matches) { VirtualNode virtNode = new VirtualNode(-i - 1); dumper.DumpNode(virtNode, String.Format("{0}. match of {1}", i + 1, matches.Producer.Name), null, vnodeTextColor, vnodeColor, vnodeBorderColor, vnodeShape); int j = 1; foreach(INode node in match.Nodes) { dumper.DumpEdge(virtNode, node, String.Format("node {0}", j++), null, vedgeTextColor, vedgeColor, vedgeLineStyle, vedgeThickness); if(matchedNodes.Contains(node)) multiMatchedNodes.Add(node); else matchedNodes.Add(node); } // Collect matched edges foreach(IEdge edge in match.Edges) { if(matchedEdges.Contains(edge)) multiMatchedEdges.Add(edge); else matchedEdges.Add(edge); } i++; } if(which == DumpMatchSpecial.OnlyMatches) { // Dump the matches only // First dump the matched nodes foreach(INode node in matchedNodes) { GrElemDumpType dumpType; if(multiMatchedNodes.Contains(node)) dumpType = GrElemDumpType.MultiMatched; else dumpType = GrElemDumpType.SingleMatched; DumpNode(node, dumpInfo.GetNodeDumpTypeTextColor(dumpType), dumpInfo.GetNodeDumpTypeColor(dumpType), dumpInfo.GetNodeDumpTypeBorderColor(dumpType), dumpInfo.GetNodeDumpTypeShape(dumpType), dumper, dumpInfo); } // Now add the matched edges (possibly including "Not matched" nodes) foreach(IEdge edge in matchedEdges) { if(!matchedNodes.Contains(edge.Source)) DumpNode(edge.Source, dumpInfo.GetNodeTypeTextColor(edge.Source.Type), dumpInfo.GetNodeTypeColor(edge.Source.Type), dumpInfo.GetNodeTypeBorderColor(edge.Source.Type), dumpInfo.GetNodeTypeShape(edge.Source.Type), dumper, dumpInfo); if(!matchedNodes.Contains(edge.Target)) DumpNode(edge.Target, dumpInfo.GetNodeTypeTextColor(edge.Target.Type), dumpInfo.GetNodeTypeColor(edge.Target.Type), dumpInfo.GetNodeTypeBorderColor(edge.Target.Type), dumpInfo.GetNodeTypeShape(edge.Target.Type), dumper, dumpInfo); GrElemDumpType dumpType; if(multiMatchedEdges.Contains(edge)) dumpType = GrElemDumpType.MultiMatched; else dumpType = GrElemDumpType.SingleMatched; DumpEdge(edge, dumpInfo.GetEdgeDumpTypeTextColor(dumpType), dumpInfo.GetEdgeDumpTypeColor(dumpType), dumpInfo.GetEdgeDumpTypeLineStyle(dumpType), dumpInfo.GetEdgeDumpTypeThickness(dumpType), dumper, dumpInfo); } return; } } }
void AfterFinish(IMatches matches, bool special) { foreach(RecordingState recordingState in recordings.Values) recordingState.writer.WriteLine("# ..rewritten " + matches.Producer.Name); }
void AssertAllUnmappedAfterMatch(IMatches matches, bool special) { foreach(INode node in graph.GetCompatibleNodes(graph.Model.NodeModel.RootType)) { LGSPNode lnode = (LGSPNode) node; if(lnode.mappedTo != 0) { throw new Exception("Node \"" + graph.GetElementName(lnode) + "\" not unmapped by action \"" + matches.Producer.Name + "\"!"); } if(lnode.negMappedTo != 0) { throw new Exception("Node \"" + graph.GetElementName(lnode) + "\" not neg-unmapped by action \"" + matches.Producer.Name + "\"!"); } } foreach(IEdge edge in graph.GetCompatibleEdges(graph.Model.EdgeModel.RootType)) { LGSPEdge ledge = (LGSPEdge) edge; if(ledge.mappedTo != 0) { throw new Exception("Edge \"" + graph.GetElementName(ledge) + "\" not unmapped by action \"" + matches.Producer.Name + "\"!"); } if(ledge.negMappedTo != 0) { throw new Exception("Edge \"" + graph.GetElementName(ledge) + "\" not neg-unmapped by action \"" + matches.Producer.Name + "\"!"); } } }
public int ChooseMatch(int matchToApply, IMatches matches, int numFurtherMatchesToApply, Sequence seq) { return matchToApply; }
/// <summary> /// returns the maybe user altered match to apply next for the sequence given /// the randomly chosen match is supplied; the object with all available matches is supplied /// </summary> public int ChooseMatch(int matchToApply, IMatches matches, int numFurtherMatchesToApply, Sequence seq) { context.highlightSeq = seq; context.choice = true; PrintSequence(debugSequences.Peek(), context, debugSequences.Count); Console.WriteLine(); context.choice = false; if(matches.Count <= 1 + numFurtherMatchesToApply && lazyChoice) { context.workaround.PrintHighlighted("Skipping choicepoint ", HighlightingMode.Choicepoint); Console.WriteLine("as no choice needed (use the (l) command to toggle this behaviour)."); return matchToApply; } context.workaround.PrintHighlighted("Please choose: Which match to apply?", HighlightingMode.Choicepoint); Console.WriteLine(" Showing the match chosen by random. (" + numFurtherMatchesToApply + " following)"); Console.WriteLine("Press (0)...(9) to show the corresponding match or (e) to enter the number of the match to show." + " Press (s) or (n) to commit to the currently shown match and continue."); if(detailedMode) { MarkMatches(matches, null, null); AnnotateMatches(matches, false); } ycompClient.UpdateDisplay(); ycompClient.Sync(); int newMatchToRewrite = matchToApply; while(true) { MarkMatch(matches.GetMatch(matchToApply), null, null); AnnotateMatch(matches.GetMatch(matchToApply), false); matchToApply = newMatchToRewrite; MarkMatch(matches.GetMatch(matchToApply), realizers.MatchedNodeRealizer, realizers.MatchedEdgeRealizer); AnnotateMatch(matches.GetMatch(matchToApply), true); ycompClient.UpdateDisplay(); ycompClient.Sync(); Console.WriteLine("Showing match " + matchToApply + " (of " + matches.Count + " matches available)"); ConsoleKeyInfo key = ReadKeyWithCancel(); switch(key.KeyChar) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': int num = key.KeyChar - '0'; if(num >= matches.Count) { Console.WriteLine("You must specify a number between 0 and " + (matches.Count - 1) + "!"); break; } newMatchToRewrite = num; break; case 'e': Console.Write("Enter number of match to show: "); String numStr = Console.ReadLine(); if(int.TryParse(numStr, out num)) { if(num < 0 || num >= matches.Count) { Console.WriteLine("You must specify a number between 0 and " + (matches.Count - 1) + "!"); break; } newMatchToRewrite = num; break; } Console.WriteLine("You must enter a valid integer number!"); break; case 's': case 'n': MarkMatch(matches.GetMatch(matchToApply), null, null); AnnotateMatch(matches.GetMatch(matchToApply), false); ycompClient.UpdateDisplay(); ycompClient.Sync(); return matchToApply; default: Console.WriteLine("Illegal choice (Key = " + key.Key + ")! Only (0)...(9), (e)nter number, (s)/(n) to commit and continue allowed! "); break; } } }
void DebugFinished(IMatches matches, bool special) { // integrate matched actions into subrule traces stack if(matches != null) RemoveUpToEntryForExit(matches.Producer.Name); if(outOfDetailedMode && (computationsEnteredStack.Count <= outOfDetailedModeTarget || computationsEnteredStack.Count==0)) { detailedMode = true; outOfDetailedMode = false; outOfDetailedModeTarget = -1; return; } if(!detailedMode) return; ycompClient.UpdateDisplay(); ycompClient.Sync(); QueryContinueOrTrace(false); foreach(INode node in addedNodes.Keys) { ycompClient.ChangeNode(node, null); ycompClient.AnnotateElement(node, null); } foreach(IEdge edge in addedEdges.Keys) { ycompClient.ChangeEdge(edge, null); ycompClient.AnnotateElement(edge, null); } foreach(String edgeName in deletedEdges) ycompClient.DeleteEdge(edgeName); foreach(String nodeName in deletedNodes) ycompClient.DeleteNode(nodeName); foreach(INode node in retypedNodes.Keys) ycompClient.ChangeNode(node, null); foreach(IEdge edge in retypedEdges.Keys) ycompClient.ChangeEdge(edge, null); foreach(INode node in annotatedNodes.Keys) ycompClient.AnnotateElement(node, null); foreach(IEdge edge in annotatedEdges.Keys) ycompClient.AnnotateElement(edge, null); ycompClient.NodeRealizerOverride = null; ycompClient.EdgeRealizerOverride = null; addedNodes.Clear(); addedEdges.Clear(); deletedEdges.Clear(); deletedNodes.Clear(); recordMode = false; matchDepth--; }
void DebugMatched(IMatches matches, IMatch match, bool special) { if(matches.Count == 0) // happens e.g. from compiled sequences firing the event always, but the Finishing only comes in case of Count!=0 return; // integrate matched actions into subrule traces stack computationsEnteredStack.Add(new SubruleComputation(matches.Producer.Name)); SubruleDebuggingConfigurationRule cr; SubruleDebuggingDecision d = shellProcEnv.SubruleDebugConfig.Decide(SubruleDebuggingEvent.Match, matches, shellProcEnv.ProcEnv, out cr); if(d == SubruleDebuggingDecision.Break) InternalHalt(cr, matches); else if(d == SubruleDebuggingDecision.Continue) { recentlyMatched = lastlyEntered; if(!detailedMode) return; if(recordMode) { DebugFinished(null, false); matchDepth++; annotatedNodes.Clear(); annotatedEdges.Clear(); } return; } if(dynamicStepMode && !skipMode) { skipMode = true; ycompClient.UpdateDisplay(); ycompClient.Sync(); context.highlightSeq = lastlyEntered; context.success = true; PrintSequence(debugSequences.Peek(), context, debugSequences.Count); Console.WriteLine(); if(!QueryUser(lastlyEntered)) { recentlyMatched = lastlyEntered; return; } } recentlyMatched = lastlyEntered; if(!detailedMode) return; if(recordMode) { DebugFinished(null, false); matchDepth++; if(outOfDetailedMode) { annotatedNodes.Clear(); annotatedEdges.Clear(); return; } } if(matchDepth++ > 0 || computationsEnteredStack.Count > 0) Console.WriteLine("Matched " + matches.Producer.Name); annotatedNodes.Clear(); annotatedEdges.Clear(); curRulePattern = matches.Producer.RulePattern; if(ycompClient.dumpInfo.IsExcludedGraph()) { if(!recordMode) { ycompClient.ClearGraph(); excludedGraphNodesIncluded.Clear(); excludedGraphEdgesIncluded.Clear(); } // add all elements from match to graph and excludedGraphElementsIncluded if(match != null) AddNeededGraphElements(match); else AddNeededGraphElements(matches); AddNeighboursAndParentsOfNeededGraphElements(); } if(match!=null) MarkMatch(match, realizers.MatchedNodeRealizer, realizers.MatchedEdgeRealizer); else MarkMatches(matches, realizers.MatchedNodeRealizer, realizers.MatchedEdgeRealizer); if(match!=null) AnnotateMatch(match, true); else AnnotateMatches(matches, true); ycompClient.UpdateDisplay(); ycompClient.Sync(); Console.WriteLine("Press any key to apply rewrite..."); ReadKeyWithCancel(); if(match!=null) MarkMatch(match, null, null); else MarkMatches(matches, null, null); recordMode = true; ycompClient.NodeRealizerOverride = realizers.NewNodeRealizer; ycompClient.EdgeRealizerOverride = realizers.NewEdgeRealizer; nextAddedNodeIndex = 0; nextAddedEdgeIndex = 0; }
/// <summary> /// Searches for a symmetric partner for the match at the index in this /// Returns true if it was possible in the end to map every match in this to a match in that /// </summary> private static bool AreIterationsSymmetric(IMatches this_, IMatches that, IGraph graph, int index) { if(index >= this_.Count) return true; for(int j = 0; j < that.Count; ++j) { if(that.GetMatch(j).IsMarked()) continue; if(!AreSymmetric(this_.GetMatch(index), that.GetMatch(j), graph)) continue; that.GetMatch(j).Mark(true); bool wereSymmetric = AreIterationsSymmetric(this_, that, graph, index + 1); that.GetMatch(j).Mark(false); if(wereSymmetric) return true; } return false; }
/// <summary> /// Checks whether the iterated matches are symmetric, /// i.e. are covering the same spot in the graph with a permutation of the single matches /// </summary> private static bool AreIterationsSymmetric(IMatches this_, IMatches that, IGraph graph) { if(this_.Count != that.Count) return false; return AreIterationsSymmetric(this_, that, graph, 0); }
public override bool Rewrite(IGraphProcessingEnvironment procEnv, IMatches matches, IMatch chosenMatch) { if (matches.Count == 0) return false; if (Test) return false; if (MinSpecified) { if(!(MinVarChooseRandom.GetVariableValue(procEnv) is int)) throw new InvalidOperationException("The variable '" + MinVarChooseRandom + "' is not of type int!"); if(matches.Count < (int)MinVarChooseRandom.GetVariableValue(procEnv)) return false; } procEnv.Finishing(matches, Special); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StartLocal(); #endif object[] retElems = null; if (!ChooseRandom) { if (chosenMatch!=null) throw new InvalidOperationException("Chosen match given although all matches should get rewritten"); IEnumerator<IMatch> matchesEnum = matches.GetEnumerator(); while (matchesEnum.MoveNext()) { IMatch match = matchesEnum.Current; if (match != matches.First) procEnv.RewritingNextMatch(); retElems = matches.Producer.Modify(procEnv, match); procEnv.PerformanceInfo.RewritesPerformed++; } if (retElems == null) retElems = NoElems; } else { object val = MaxVarChooseRandom != null ? MaxVarChooseRandom.GetVariableValue(procEnv) : (MinSpecified ? 2147483647 : 1); if (!(val is int)) throw new InvalidOperationException("The variable '" + MaxVarChooseRandom.Name + "' is not of type int!"); int numChooseRandom = (int)val; if (matches.Count < numChooseRandom) numChooseRandom = matches.Count; for (int i = 0; i < numChooseRandom; i++) { if (i != 0) procEnv.RewritingNextMatch(); int matchToApply = randomGenerator.Next(matches.Count); if (Choice) matchToApply = procEnv.UserProxy.ChooseMatch(matchToApply, matches, numChooseRandom - 1 - i, this); IMatch match = matches.RemoveMatch(matchToApply); if (chosenMatch != null) match = chosenMatch; retElems = matches.Producer.Modify(procEnv, match); procEnv.PerformanceInfo.RewritesPerformed++; } if (retElems == null) retElems = NoElems; } for(int i = 0; i < ParamBindings.ReturnVars.Length; i++) ParamBindings.ReturnVars[i].SetVariableValue(retElems[i], procEnv); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StopRewrite(); // total rewrite time does NOT include listeners anymore #endif procEnv.Finished(matches, Special); #if LOG_SEQUENCE_EXECUTION procEnv.Recorder.WriteLine("Matched/Applied " + Symbol); procEnv.Recorder.Flush(); #endif return true; }
public override bool Rewrite(IGraphProcessingEnvironment procEnv, IMatches matches, IMatch chosenMatch) { CountResult.SetVariableValue(matches.Count, procEnv); if(matches.Count == 0) return false; if(Test) return false; procEnv.Finishing(matches, Special); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StartLocal(); #endif object[] retElems = null; IEnumerator<IMatch> matchesEnum = matches.GetEnumerator(); while(matchesEnum.MoveNext()) { IMatch match = matchesEnum.Current; if(match != matches.First) procEnv.RewritingNextMatch(); retElems = matches.Producer.Modify(procEnv, match); procEnv.PerformanceInfo.RewritesPerformed++; } if(retElems == null) retElems = NoElems; for(int i = 0; i < ParamBindings.ReturnVars.Length; i++) ParamBindings.ReturnVars[i].SetVariableValue(retElems[i], procEnv); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StopRewrite(); // total rewrite time does NOT include listeners anymore #endif procEnv.Finished(matches, Special); #if LOG_SEQUENCE_EXECUTION procEnv.Recorder.WriteLine("Matched/Applied " + Symbol); procEnv.Recorder.Flush(); #endif return true; }
protected bool ApplyRule(SequenceRuleCall rule, IGraphProcessingEnvironment procEnv, IMatches matches, IMatch match) { bool result; procEnv.EnteringSequence(rule); rule.executionState = SequenceExecutionState.Underway; #if LOG_SEQUENCE_EXECUTION procEnv.Recorder.WriteLine("Before executing sequence " + rule.Id + ": " + rule.Symbol); #endif procEnv.Matched(matches, null, rule.Special); result = rule.Rewrite(procEnv, matches, match); #if LOG_SEQUENCE_EXECUTION procEnv.Recorder.WriteLine("After executing sequence " + rule.Id + ": " + rule.Symbol + " result " + result); #endif rule.executionState = result ? SequenceExecutionState.Success : SequenceExecutionState.Fail; procEnv.ExitingSequence(rule); return result; }
public virtual bool Rewrite(IGraphProcessingEnvironment procEnv, IMatches matches, IMatch chosenMatch) { if(matches.Count == 0) return false; if(Test) return false; IMatch match = chosenMatch!=null ? chosenMatch : matches.First; procEnv.Finishing(matches, Special); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StartLocal(); #endif object[] retElems = null; retElems = matches.Producer.Modify(procEnv, match); procEnv.PerformanceInfo.RewritesPerformed++; if(retElems == null) retElems = NoElems; for(int i = 0; i < ParamBindings.ReturnVars.Length; i++) ParamBindings.ReturnVars[i].SetVariableValue(retElems[i], procEnv); #if DEBUGACTIONS || MATCHREWRITEDETAIL procEnv.PerformanceInfo.StopRewrite(); // total rewrite time does NOT include listeners anymore #endif procEnv.Finished(matches, Special); #if LOG_SEQUENCE_EXECUTION procEnv.Recorder.WriteLine("Matched/Applied " + Symbol); procEnv.Recorder.Flush(); #endif return true; }
/// <summary> /// Dumps one or more matches with a given graph dumper. /// </summary> /// <param name="graph">The graph to be dumped.</param> /// <param name="dumper">The graph dumper to be used.</param> /// <param name="dumpInfo">Specifies how the graph shall be dumped.</param> /// <param name="matches">An IMatches object containing the matches.</param> /// <param name="which">Which match to dump, or AllMatches for dumping all matches /// adding connections between them, or OnlyMatches to dump the matches only</param> public static void DumpMatch(IGraph graph, IDumper dumper, DumpInfo dumpInfo, IMatches matches, DumpMatchSpecial which) { Set<INode> matchedNodes = null; Set<INode> multiMatchedNodes = null; Set<IEdge> matchedEdges = null; Set<IEdge> multiMatchedEdges = null; if(matches != null) { DumpMatchOnly(dumper, dumpInfo, matches, which, ref matchedNodes, ref multiMatchedNodes, ref matchedEdges, ref multiMatchedEdges); } // Dump the graph, but color the matches if any exist DumpContext dc = new DumpContext(dumper, dumpInfo, matchedNodes, multiMatchedNodes, matchedEdges, multiMatchedEdges); foreach(NodeType nodeType in graph.Model.NodeModel.Types) { if(dumpInfo.IsExcludedNodeType(nodeType)) continue; dc.Nodes.Add(graph.GetExactNodes(nodeType)); } dc.InitialNodes = new Set<INode>(dc.Nodes); Set<INode> nodes = new Set<INode>(dc.Nodes); DumpGroups(graph, nodes, dc); }