コード例 #1
0
        /// <summary>
        /// move outwards from starting point on until operation to continue at is found
        /// appending restore isomorphy at insertion point for isomorphy written on the way
        /// returns operation to continue at
        /// </summary>
        private static SearchProgramOperation MoveOutwardsAppendingRemoveIsomorphy(
            SearchProgramOperation startingPoint,
            ref SearchProgramOperation insertionPoint,
            string[] neededElementsForCheckOperation,
            SearchProgramOperation outermostOperation,
            SearchProgram topLevelSearchProgram)
        {
            // currently focused operation on our way outwards
            SearchProgramOperation op = startingPoint;
            // move outwards until operation to continue at is found
            bool creationPointOfDominatingElementFound = false;
            bool iterationReached = false;

            do
            {
                op = op.Previous;

                // insert code to clean up isomorphy information written by candidate acceptance
                // in between the operation to continue and the check operation
                if (op is AcceptCandidate)
                {
                    AcceptCandidate writeIsomorphy =
                        op as AcceptCandidate;
                    AbandonCandidate restoreIsomorphy =
                        new AbandonCandidate(
                            writeIsomorphy.PatternElementName,
                            writeIsomorphy.NegativeIndependentNamePrefix,
                            writeIsomorphy.IsNode,
                            writeIsomorphy.NeverAboveMaxIsoSpace,
                            writeIsomorphy.Parallel,
                            writeIsomorphy.LockForAllThreads);
                    insertionPoint = insertionPoint.Append(restoreIsomorphy);
                }
                // insert code to clean up isomorphy information written by global candidate acceptance
                // in between the operation to continue and the check operation
                if (op is AcceptCandidateGlobal)
                {
                    AcceptCandidateGlobal writeIsomorphy =
                        op as AcceptCandidateGlobal;
                    AbandonCandidateGlobal removeIsomorphy =
                        new AbandonCandidateGlobal(
                            writeIsomorphy.PatternElementName,
                            writeIsomorphy.NegativeIndependentNamePrefix,
                            writeIsomorphy.IsNode,
                            writeIsomorphy.NeverAboveMaxIsoSpace,
                            writeIsomorphy.Parallel);
                    insertionPoint = insertionPoint.Append(removeIsomorphy);
                }
                // insert code to clean up isomorphy information written by patternpath candidate acceptance
                // in between the operation to continue and the check operation
                if (op is AcceptCandidatePatternpath)
                {
                    AcceptCandidatePatternpath writeIsomorphy =
                        op as AcceptCandidatePatternpath;
                    AbandonCandidatePatternpath removeIsomorphy =
                        new AbandonCandidatePatternpath(
                            writeIsomorphy.PatternElementName,
                            writeIsomorphy.NegativeIndependentNamePrefix,
                            writeIsomorphy.IsNode);
                    insertionPoint = insertionPoint.Append(removeIsomorphy);
                }
                // insert code to remove iterated pattern acceptance
                if (op is AcceptIterated)
                {
                    AcceptIterated acceptIterated =
                        op as AcceptIterated;
                    AbandonIterated abandonIterated =
                        new AbandonIterated();
                    insertionPoint = insertionPoint.Append(abandonIterated);
                }
                // insert code to undo subpattern matching initialization if we leave the subpattern matching method
                if (op is InitializeSubpatternMatching)
                {
                    InitializeSubpatternMatching initialize =
                        op as InitializeSubpatternMatching;
                    FinalizeSubpatternMatching finalize =
                        new FinalizeSubpatternMatching(initialize.Type);
                    insertionPoint = insertionPoint.Append(finalize);
                }
                // insert code to undo negative/independent matching initialization if we leave the negative/independent matching method
                if (op is InitializeNegativeIndependentMatching)
                {
                    InitializeNegativeIndependentMatching initialize =
                        op as InitializeNegativeIndependentMatching;
                    FinalizeNegativeIndependentMatching finalize =
                        new FinalizeNegativeIndependentMatching(initialize.NeverAboveMaxIsoSpace, initialize.Parallel);
                    insertionPoint = insertionPoint.Append(finalize);
                }

                // determine operation to continue at
                // found by looking at the graph elements
                // the check operation depends on / is dominated by
                // its the first element iteration on our way outwards the search program
                // after or at the point of a get element operation
                // of some dominating element the check depends on
                // (or the outermost operation if no iteration is found until it is reached)
                if (op is GetCandidate || op is BothDirectionsIteration)
                {
                    if (creationPointOfDominatingElementFound == false)
                    {
                        if (neededElementsForCheckOperation != null)
                        {
                            foreach (string dominating in neededElementsForCheckOperation)
                            {
                                GetCandidate            getCandidate   = op as GetCandidate;
                                BothDirectionsIteration bothDirections = op as BothDirectionsIteration;
                                if (getCandidate != null && getCandidate.PatternElementName == dominating ||
                                    bothDirections != null && bothDirections.PatternElementName == dominating)
                                {
                                    creationPointOfDominatingElementFound = true;
                                    iterationReached = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // needed elements == null means everything fits,
                            // take first element iteration on our way outwards the search program
                            // (or the outermost operation if no iteration is found until it is reached)
                            creationPointOfDominatingElementFound = true;
                            iterationReached = false;
                        }
                    }
                    if (op is GetCandidateByIteration || op is GetCandidateByIterationParallel || op is BothDirectionsIteration)
                    {
                        iterationReached = true;
                    }
                }
            }while(!(creationPointOfDominatingElementFound && iterationReached) &&
                   op != outermostOperation);

            return(op);
        }
コード例 #2
0
        /// <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);
        }