/// <summary> /// Inserts code to check whether iteration came to an end (pattern not found (again)) /// and code to handle that case /// </summary> private SearchProgramOperation insertEndOfIterationHandling(SearchProgramOperation insertionPoint) { Debug.Assert(NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()) == ""); PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); // check whether the pattern was not found / the null match was found // if yes the iteration came to an end, handle that case CheckContinueMatchingIteratedPatternNonNullMatchFound iteratedPatternFound = new CheckContinueMatchingIteratedPatternNonNullMatchFound(patternGraph.isIterationBreaking); SearchProgramOperation continuationPoint = insertionPoint.Append(iteratedPatternFound); iteratedPatternFound.CheckFailedOperations = new SearchProgramList(iteratedPatternFound); insertionPoint = iteratedPatternFound.CheckFailedOperations; // ---- initialize task/result-pushdown handling in subpattern matcher for end of iteration InitializeSubpatternMatching initialize = new InitializeSubpatternMatching(InitializeFinalizeSubpatternMatchingType.EndOfIteration); insertionPoint = insertionPoint.Append(initialize); // ---- ---- iteration pattern may be the last to be matched - handle that case CheckContinueMatchingTasksLeft tasksLeft = new CheckContinueMatchingTasksLeft(); SearchProgramOperation continuationPointAfterTasksLeft = insertionPoint.Append(tasksLeft); tasksLeft.CheckFailedOperations = new SearchProgramList(tasksLeft); insertionPoint = tasksLeft.CheckFailedOperations; // ---- ---- check failed, no tasks left, leaf subpattern was matched string inlinedPatternClassName = rulePatternClassName; string pathPrefixInInlinedPatternClass = patternGraph.pathPrefix; string unprefixedNameInInlinedPatternClass = patternGraph.name; if(patternGraph.originalPatternGraph != null) { inlinedPatternClassName = patternGraph.originalSubpatternEmbedding.matchingPatternOfEmbeddedGraph.GetType().Name; pathPrefixInInlinedPatternClass = patternGraph.originalPatternGraph.pathPrefix; unprefixedNameInInlinedPatternClass = patternGraph.originalPatternGraph.name; } LeafSubpatternMatched leafMatched = new LeafSubpatternMatched( inlinedPatternClassName, pathPrefixInInlinedPatternClass + unprefixedNameInInlinedPatternClass, true); insertionPoint = insertionPoint.Append(leafMatched); leafMatched.MatchBuildingOperations = new SearchProgramList(leafMatched); // empty, no match object // ---- ---- finalize task/result-pushdown handling in subpattern matcher for end of iteration FinalizeSubpatternMatching finalize = new FinalizeSubpatternMatching(InitializeFinalizeSubpatternMatchingType.EndOfIteration); insertionPoint = insertionPoint.Append(finalize); FinalizeSubpatternMatching finalizeIteration = new FinalizeSubpatternMatching(InitializeFinalizeSubpatternMatchingType.Iteration); insertionPoint = insertionPoint.Append(finalizeIteration); ContinueOperation leave = new ContinueOperation(ContinueOperationType.ByReturn, false, parallelized && indexOfSchedule == 1); insertionPoint = insertionPoint.Append(leave); // ---- nesting level up insertionPoint = continuationPointAfterTasksLeft; // ---- we execute the open subpattern matching tasks MatchSubpatterns matchSubpatterns = new MatchSubpatterns("", parallelized); insertionPoint = insertionPoint.Append(matchSubpatterns); // ---- check whether the open subpattern matching task succeeded, with null match building insertionPoint = insertCheckForSubpatternsFound(insertionPoint, true); // ---- finalize task/result-pushdown handling in subpattern matcher for end of iteration finalize = new FinalizeSubpatternMatching(InitializeFinalizeSubpatternMatchingType.EndOfIteration); insertionPoint = insertionPoint.Append(finalize); finalizeIteration = new FinalizeSubpatternMatching(InitializeFinalizeSubpatternMatchingType.Iteration); insertionPoint = insertionPoint.Append(finalizeIteration); leave = new ContinueOperation(ContinueOperationType.ByReturn, false, parallelized && indexOfSchedule == 1); insertionPoint = insertionPoint.Append(leave); // ---- nesting level up insertionPoint = continuationPoint; return insertionPoint; }
/// <summary> /// Inserts code to check whether there are open tasks to handle left and code for case there are none /// at the given position, returns position after inserted operations /// </summary> private SearchProgramOperation insertCheckForTasksLeft(SearchProgramOperation insertionPoint) { PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); CheckContinueMatchingTasksLeft tasksLeft = new CheckContinueMatchingTasksLeft(); SearchProgramOperation continuationPointAfterTasksLeft = insertionPoint.Append(tasksLeft); tasksLeft.CheckFailedOperations = new SearchProgramList(tasksLeft); insertionPoint = tasksLeft.CheckFailedOperations; // ---- check failed, no tasks left, leaf subpattern was matched string inlinedPatternClassName = rulePatternClassName; string pathPrefixInInlinedPatternClass = patternGraph.pathPrefix; string unprefixedNameInInlinedPatternClass = patternGraph.name; if(patternGraph.originalPatternGraph != null) { inlinedPatternClassName = patternGraph.originalSubpatternEmbedding.matchingPatternOfEmbeddedGraph.GetType().Name; pathPrefixInInlinedPatternClass = patternGraph.originalPatternGraph.pathPrefix; unprefixedNameInInlinedPatternClass = patternGraph.originalPatternGraph.name; } LeafSubpatternMatched leafMatched = new LeafSubpatternMatched( inlinedPatternClassName, pathPrefixInInlinedPatternClass+unprefixedNameInInlinedPatternClass, false); SearchProgramOperation continuationPointAfterLeafMatched = insertionPoint.Append(leafMatched); leafMatched.MatchBuildingOperations = new SearchProgramList(leafMatched); insertionPoint = leafMatched.MatchBuildingOperations; // ---- ---- fill the match object with the candidates // ---- ---- which have passed all the checks for being a match insertionPoint = insertInlinedMatchObjectCreation(insertionPoint, patternGraph, MatchObjectType.Normal); insertionPoint = insertMatchObjectBuilding(insertionPoint, patternGraph, MatchObjectType.Normal, false); insertionPoint = insertMatchObjectBuilding(insertionPoint, patternGraph, MatchObjectType.Normal, true); // if an independent was inlined, we have to insert the local match into a set used for duplicate checking if(wasIndependentInlined(patternGraph, indexOfSchedule)) insertionPoint = insertFillForDuplicateMatchChecking(insertionPoint); // ---- nesting level up insertionPoint = continuationPointAfterLeafMatched; // ---- check max matches reached will be inserted here by completion pass // nesting level up insertionPoint = continuationPointAfterTasksLeft; return insertionPoint; }