/// <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> /// Search program operations completing the matching process /// after all pattern elements have been found are created and inserted into the program /// </summary> private SearchProgramOperation buildMatchComplete( SearchProgramOperation insertionPoint) { PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraph); // is subpattern gives information about type of top level enclosing pattern (action vs. subpattern) // contains subpatterns gives informations about current pattern graph (might be negative, independent itself, too) bool isSubpattern = programType == SearchProgramType.Subpattern || programType == SearchProgramType.AlternativeCase || programType == SearchProgramType.Iterated; bool existsNonInlinedSubpattern = false; foreach(PatternGraphEmbedding sub in patternGraph.embeddedGraphsPlusInlined) if(!sub.inlined) existsNonInlinedSubpattern = true; bool containsSubpatterns = existsNonInlinedSubpattern || patternGraph.alternativesPlusInlined.Length >= 1 || patternGraph.iteratedsPlusInlined.Length >= 1; // increase iterated matched counter if it is iterated if(programType==SearchProgramType.Iterated) { AcceptIterated acceptIterated = new AcceptIterated(); insertionPoint = insertionPoint.Append(acceptIterated); } // push subpattern tasks (in case there are some) if(containsSubpatterns) insertionPoint = insertPushSubpatternTasks(insertionPoint); // if this is a subpattern without subpatterns // it may be the last to be matched - handle that case if(!containsSubpatterns && isSubpattern && programType!=SearchProgramType.Iterated && negativeIndependentNamePrefix=="") insertionPoint = insertCheckForTasksLeft(insertionPoint); // if this is a subpattern or a top-level pattern which contains subpatterns if(containsSubpatterns || isSubpattern && negativeIndependentNamePrefix=="") { // we do the global accept of all candidate elements (write isomorphy information) insertionPoint = insertGlobalAccept(insertionPoint); // and execute the open subpattern matching tasks MatchSubpatterns matchSubpatterns = new MatchSubpatterns(negativeIndependentNamePrefix, parallelized); insertionPoint = insertionPoint.Append(matchSubpatterns); } // pop subpattern tasks (in case there are/were some) if(containsSubpatterns) insertionPoint = insertPopSubpatternTasks(insertionPoint); // handle matched or not matched subpatterns, matched local pattern if(negativeIndependentNamePrefix == "") { // subpattern or top-level pattern which contains subpatterns if(containsSubpatterns || isSubpattern) insertionPoint = insertCheckForSubpatternsFound(insertionPoint, false); else // top-level-pattern of action without subpatterns insertionPoint = insertPatternFound(insertionPoint); } else { // negative/independent contains subpatterns if(containsSubpatterns) insertionPoint = insertCheckForSubpatternsFoundNegativeIndependent(insertionPoint); else insertionPoint = insertPatternFoundNegativeIndependent(insertionPoint); } // global abandon of all accepted candidate elements (remove isomorphy information) if(containsSubpatterns || isSubpattern && negativeIndependentNamePrefix=="") insertionPoint = insertGlobalAbandon(insertionPoint); // decrease iterated matched counter again if it is iterated if(programType == SearchProgramType.Iterated) { AbandonIterated abandonIterated = new AbandonIterated(); insertionPoint = insertionPoint.Append(abandonIterated); } return insertionPoint; }