/// <summary> /// move outwards from check succeeded operation until check partial match by independent is found /// appending restore isomorphy for isomorphy written on the way /// and final jump to operation right after the independent failed operation of the check partial match by independent /// </summary> private static void MoveRightAfterCorrespondingIndependentFailedAppendingRemoveIsomorphyAndJump( CheckContinueMatchingOfIndependentSucceeded checkSucceeded, CheckPartialMatchByIndependent enclosingIndependent, SearchProgram topLevelSearchProgram) { // insertion point for candidate failed operations SearchProgramOperation insertionPoint = checkSucceeded.CheckFailedOperations; while (insertionPoint.Next != null) // needed? { insertionPoint = insertionPoint.Next; } // move outwards, append remove isomorphy string[] neededElements = new string[0]; SearchProgramOperation continuationPoint = MoveOutwardsAppendingRemoveIsomorphy( checkSucceeded, ref insertionPoint, neededElements, enclosingIndependent, topLevelSearchProgram); // move to check failed operation of check independent operation while (!(continuationPoint is CheckContinueMatchingOfIndependentFailed)) { continuationPoint = continuationPoint.Next; } CheckContinueMatchingOfIndependentFailed checkFailed = (CheckContinueMatchingOfIndependentFailed)continuationPoint; // insert label right thereafter, append jump there at insertion point GotoLabel gotoLabel = new GotoLabel(); checkFailed.Insert(gotoLabel); ContinueOperation continueByGoto = new ContinueOperation( ContinueOperationType.ByGoto, gotoLabel.LabelName); insertionPoint.Append(continueByGoto); }
/// <summary> /// move outwards from check operation until operation to continue at is found /// appending restore isomorphy for isomorphy written on the way /// and final jump to operation to continue at /// </summary> private static void MoveOutwardsAppendingRemoveIsomorphyAndJump( CheckOperation checkOperation, string[] neededElementsForCheckOperation, SearchProgramOperation outermostOperation, SearchProgram topLevelSearchProgram) { // insertion point for candidate failed operations SearchProgramOperation insertionPoint = checkOperation.CheckFailedOperations; while (insertionPoint.Next != null) { insertionPoint = insertionPoint.Next; } // set outermost to iterated matching dummy loop if iterated if (outermostOperation is SearchProgramOfIterated) { SearchProgramOperation cur = checkOperation; while (!(cur is IteratedMatchingDummyLoop)) { cur = cur.Previous; } outermostOperation = cur; } SearchProgramOperation continuationPoint = MoveOutwardsAppendingRemoveIsomorphy( checkOperation, ref insertionPoint, neededElementsForCheckOperation, outermostOperation, topLevelSearchProgram); // decide on type of continuing operation, then insert it // continue at top nesting level -> return SearchProgramOperation op = continuationPoint; while (!(op is SearchProgram)) { op = op.Previous; } SearchProgram searchProgramRoot = op as SearchProgram; if (continuationPoint == searchProgramRoot) { ContinueOperation continueByReturn = new ContinueOperation( ContinueOperationType.ByReturn, searchProgramRoot is SearchProgramOfAction || searchProgramRoot is SearchProgramOfActionParallelizationHead, searchProgramRoot is SearchProgramOfActionParallelizationBody ); insertionPoint.Append(continueByReturn); return; } // continue at directly enclosing nesting level -> continue op = checkOperation; do { op = op.Previous; }while(!op.IsSearchNestingOperation()); SearchProgramOperation directlyEnclosingOperation = op; if (continuationPoint == directlyEnclosingOperation // (check negative/independent is enclosing, but not a loop, thus continue wouldn't work) && !(directlyEnclosingOperation is CheckPartialMatchByNegative) && !(directlyEnclosingOperation is CheckPartialMatchByIndependent) // (check partial match for duplicate contains an internal loop in checking, thus continue wouldn't work) && !(checkOperation is CheckPartialMatchForDuplicate)) { ContinueOperation continueByContinue = new ContinueOperation(ContinueOperationType.ByContinue, directlyEnclosingOperation is GetCandidateByIterationParallel); insertionPoint.Append(continueByContinue); return; } // otherwise -> goto label string gotoLabelName; // if our continuation point is a candidate iteration // -> append label at the end of the loop body of the candidate iteration loop if (continuationPoint is GetCandidateByIteration) { GetCandidateByIteration candidateIteration = continuationPoint as GetCandidateByIteration; op = candidateIteration.NestedOperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is a candidate iteration parallel // -> append label at the end of the loop body of the candidate iteration loop else if (continuationPoint is GetCandidateByIterationParallel) { GetCandidateByIterationParallel candidateIteration = continuationPoint as GetCandidateByIterationParallel; op = candidateIteration.NestedOperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is a both directions iteration // -> append label at the end of the loop body of the both directions iteration loop else if (continuationPoint is BothDirectionsIteration) { BothDirectionsIteration bothDirections = continuationPoint as BothDirectionsIteration; op = bothDirections.NestedOperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is an alternative case // -> append label at the end of the alternative case operations else if (continuationPoint is AlternativeCaseMatching) { AlternativeCaseMatching alternativeCase = continuationPoint as AlternativeCaseMatching; op = alternativeCase.OperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is the dummy loop of an iterated operation // -> we just jump to the label maxMatchesIterReached directly after the loop else if (continuationPoint is IteratedMatchingDummyLoop) { gotoLabelName = "maxMatchesIterReached"; } // otherwise our continuation point is a check negative/independent operation // -> insert label directly after the check negative/independent operation else { CheckPartialMatchByNegativeOrIndependent checkNegativeIndependent = continuationPoint as CheckPartialMatchByNegativeOrIndependent; GotoLabel gotoLabel = new GotoLabel(); checkNegativeIndependent.Insert(gotoLabel); gotoLabelName = gotoLabel.LabelName; } ContinueOperation continueByGoto = new ContinueOperation( ContinueOperationType.ByGoto, gotoLabelName); // ByGoto due to parameters insertionPoint.Append(continueByGoto); }
/// <summary> /// move outwards from check operation until operation to continue at is found /// appending restore isomorphy for isomorphy written on the way /// and final jump to operation to continue at /// </summary> private void MoveOutwardsAppendingRemoveIsomorphyAndJump( CheckOperation checkOperation, string[] neededElementsForCheckOperation, SearchProgramOperation outermostOperation, SearchProgram topLevelSearchProgram) { // insertion point for candidate failed operations SearchProgramOperation insertionPoint = checkOperation.CheckFailedOperations; while (insertionPoint.Next != null) { insertionPoint = insertionPoint.Next; } // set outermost to iterated dummy iteration if iterated if (outermostOperation is SearchProgramOfIterated) { SearchProgramOperation cur = checkOperation; while (!(cur is ReturnPreventingDummyIteration)) { cur = cur.Previous; } outermostOperation = cur; } SearchProgramOperation continuationPoint = MoveOutwardsAppendingRemoveIsomorphy( checkOperation, ref insertionPoint, neededElementsForCheckOperation, outermostOperation, topLevelSearchProgram); // decide on type of continuing operation, then insert it // continue at top nesting level -> return SearchProgramOperation op = continuationPoint; while (!(op is SearchProgram)) { op = op.Previous; } SearchProgram searchProgramRoot = op as SearchProgram; if (continuationPoint == searchProgramRoot) { ContinueOperation continueByReturn = new ContinueOperation( ContinueOperationType.ByReturn, searchProgramRoot is SearchProgramOfAction || searchProgramRoot is SearchProgramOfActionParallelizationHead, searchProgramRoot is SearchProgramOfActionParallelizationBody ); insertionPoint.Append(continueByReturn); return; } // continue at directly enclosing nesting level -> continue op = checkOperation; do { op = op.Previous; } while (!op.IsSearchNestingOperation()); SearchProgramOperation directlyEnclosingOperation = op; if (continuationPoint == directlyEnclosingOperation // (check negative/independent is enclosing, but not a loop, thus continue wouldn't work) && !(directlyEnclosingOperation is CheckPartialMatchByNegative) && !(directlyEnclosingOperation is CheckPartialMatchByIndependent) // (check partial match for duplicate contains an internal loop in checking, thus continue wouldn't work) && !(checkOperation is CheckPartialMatchForDuplicate)) { ContinueOperation continueByContinue = new ContinueOperation(ContinueOperationType.ByContinue, directlyEnclosingOperation is GetCandidateByIterationParallel); insertionPoint.Append(continueByContinue); return; } // otherwise -> goto label string gotoLabelName; // if our continuation point is a candidate iteration // -> append label at the end of the loop body of the candidate iteration loop if (continuationPoint is GetCandidateByIteration) { GetCandidateByIteration candidateIteration = continuationPoint as GetCandidateByIteration; op = candidateIteration.NestedOperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is a candidate iteration parallel // -> append label at the end of the loop body of the candidate iteration loop else if (continuationPoint is GetCandidateByIterationParallel) { GetCandidateByIterationParallel candidateIteration = continuationPoint as GetCandidateByIterationParallel; op = candidateIteration.NestedOperationsList; while(op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is a both directions iteration // -> append label at the end of the loop body of the both directions iteration loop else if (continuationPoint is BothDirectionsIteration) { BothDirectionsIteration bothDirections = continuationPoint as BothDirectionsIteration; op = bothDirections.NestedOperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is an alternative // -> append label at the end of the alternative operations else if (continuationPoint is GetPartialMatchOfAlternative) { GetPartialMatchOfAlternative getAlternative = continuationPoint as GetPartialMatchOfAlternative; op = getAlternative.OperationsList; while (op.Next != null) { op = op.Next; } GotoLabel gotoLabel = new GotoLabel(); op.Append(gotoLabel); gotoLabelName = gotoLabel.LabelName; } // if our continuation point is the dummy loop of an iterated operation // -> we just jump to the label maxMatchesIterReached directly after the loop else if (continuationPoint is ReturnPreventingDummyIteration) { gotoLabelName = "maxMatchesIterReached"; } // otherwise our continuation point is a check negative/independent operation // -> insert label directly after the check negative/independent operation else { CheckPartialMatchByNegativeOrIndependent checkNegativeIndependent = continuationPoint as CheckPartialMatchByNegativeOrIndependent; GotoLabel gotoLabel = new GotoLabel(); checkNegativeIndependent.Insert(gotoLabel); gotoLabelName = gotoLabel.LabelName; } ContinueOperation continueByGoto = new ContinueOperation( ContinueOperationType.ByGoto, gotoLabelName); // ByGoto due to parameters insertionPoint.Append(continueByGoto); }
/// <summary> /// move outwards from check succeeded operation until check partial match by independent is found /// appending restore isomorphy for isomorphy written on the way /// and final jump to operation right after the independent failed operation of the check partial match by independent /// </summary> private void MoveRightAfterCorrespondingIndependentFailedAppendingRemoveIsomorphyAndJump( CheckContinueMatchingOfIndependentSucceeded checkSucceeded, CheckPartialMatchByIndependent enclosingIndependent, SearchProgram topLevelSearchProgram) { // insertion point for candidate failed operations SearchProgramOperation insertionPoint = checkSucceeded.CheckFailedOperations; while (insertionPoint.Next != null) // needed? { insertionPoint = insertionPoint.Next; } // move outwards, append remove isomorphy string[] neededElements = new string[0]; SearchProgramOperation continuationPoint = MoveOutwardsAppendingRemoveIsomorphy( checkSucceeded, ref insertionPoint, neededElements, enclosingIndependent, topLevelSearchProgram); // move to check failed operation of check independent operation while (!(continuationPoint is CheckContinueMatchingOfIndependentFailed)) { continuationPoint = continuationPoint.Next; } CheckContinueMatchingOfIndependentFailed checkFailed = (CheckContinueMatchingOfIndependentFailed)continuationPoint; // insert label right thereafter, append jump there at insertion point GotoLabel gotoLabel = new GotoLabel(); checkFailed.Insert(gotoLabel); ContinueOperation continueByGoto = new ContinueOperation( ContinueOperationType.ByGoto, gotoLabel.LabelName); insertionPoint.Append(continueByGoto); }
/// <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; }