Esempio n. 1
0
 public override void Emit(SourceBuilder sourceCode)
 {
     // TODO: why is the clear needed? is it needed at all? the set being empty must be ensured at this point.
     if (Parallel)
     {
         if (!NeverAboveMaxIsoSpace)
         {
             sourceCode.AppendFront("if(isoSpace >= (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE) {\n");
             sourceCode.Indent();
             sourceCode.AppendFront("graph.perThreadInIsoSpaceMatchedElements[threadId][isoSpace - "
                                    + "(int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE].Clear();\n");
             sourceCode.AppendFront("graph.perThreadInIsoSpaceMatchedElementsGlobal[threadId][isoSpace - "
                                    + "(int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE].Clear();\n");
             sourceCode.Unindent();
             sourceCode.AppendFront("}\n");
         }
     }
     else
     {
         if (!NeverAboveMaxIsoSpace)
         {
             sourceCode.AppendFront("if(isoSpace >= (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE) {\n");
             sourceCode.Indent();
             sourceCode.AppendFront("graph.inIsoSpaceMatchedElements[isoSpace - "
                                    + "(int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE].Clear();\n");
             sourceCode.AppendFront("graph.inIsoSpaceMatchedElementsGlobal[isoSpace - "
                                    + "(int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE].Clear();\n");
             sourceCode.Unindent();
             sourceCode.AppendFront("}\n");
         }
     }
     sourceCode.AppendFront("--isoSpace;\n");
 }
Esempio n. 2
0
        public override void Dump(SourceBuilder builder)
        {
            // first dump check
            if (Type == CheckMaximumMatchesType.Action)
            {
                builder.AppendFront("CheckContinueMatching MaximumMatchesReached at Action level ");
            }
            else if (Type == CheckMaximumMatchesType.Subpattern)
            {
                builder.AppendFront("CheckContinueMatching MaximumMatchesReached at Subpattern level ");
            }
            else if (Type == CheckMaximumMatchesType.Iterated)
            {
                builder.AppendFront("CheckContinueMatching MaximumMatchesReached if Iterated ");
            }
            if (ListHeadAdjustment)
            {
                builder.Append("ListHeadAdjustment ");
            }
            if (InParallelizedBody)
            {
                builder.Append("InParallelizedBody ");
            }
            builder.Append("\n");

            // then operations for case check failed
            if (CheckFailedOperations != null)
            {
                builder.Indent();
                CheckFailedOperations.Dump(builder);
                builder.Unindent();
            }
        }
Esempio n. 3
0
        public override void Dump(SourceBuilder builder)
        {
            builder.AppendFrontFormat("LeafSubpatternMatched {0}\n", IsIteratedNullMatch ? "IteratedNullMatch " : "");

            if (MatchBuildingOperations != null)
            {
                builder.Indent();
                MatchBuildingOperations.Dump(builder);
                builder.Unindent();
            }
        }
Esempio n. 4
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckContinueMatching TasksLeft\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Esempio n. 5
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckContinueMatching OfIndependentSucceeded \n");
     // then operations for case check failed .. wording a bit rotten
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Esempio n. 6
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFrontFormat("// Alternative case {0}{1} \n", PathPrefix, CaseName);
            }

            sourceCode.AppendFront("do {\n");
            sourceCode.Indent();
            string whichCase = RulePatternClassName + "." + PathPrefix + "CaseNums.@" + CaseName;

            sourceCode.AppendFrontFormat("patternGraph = patternGraphs[(int){0}];\n", whichCase);

            if (WasIndependentInlined)
            {
                sourceCode.AppendFrontFormat("Dictionary<int, {0}> {1} = null;\n",
                                             RulePatternClassName + "." + NamesOfEntities.MatchClassName(PathPrefix + CaseName),
                                             NamesOfEntities.FoundMatchesForFilteringVariable());
            }

            OperationsList.Emit(sourceCode);

            if (WasIndependentInlined)
            {
                sourceCode.AppendFrontFormat("if({0} != null)\n",
                                             NamesOfEntities.FoundMatchesForFilteringVariable());
                sourceCode.AppendFront("{\n");
                sourceCode.Indent();

                sourceCode.AppendFrontFormat("foreach({0} toClean in {1}.Values) toClean.CleanNextWithSameHash();\n",
                                             RulePatternClassName + "." + NamesOfEntities.MatchClassName(PathPrefix + CaseName),
                                             NamesOfEntities.FoundMatchesForFilteringVariable());

                sourceCode.Unindent();
                sourceCode.AppendFront("}\n");
            }

            sourceCode.Unindent();
            sourceCode.AppendFront("} while(false);\n");
        }
Esempio n. 7
0
        public override void Dump(SourceBuilder builder)
        {
            // first dump local content
            builder.AppendFrontFormat("AlternativeCaseMatching {0}{1}\n", PathPrefix, CaseName);

            // then nested content
            if (OperationsList != null)
            {
                builder.Indent();
                OperationsList.Dump(builder);
                builder.Unindent();
            }
        }
Esempio n. 8
0
        public override void Emit(SourceBuilder sourceCode)
        {
            sourceCode.AppendFront("++isoSpace;\n");
            if (Parallel)
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.AppendFront("if(isoSpace >= (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE && " +
                                           "isoSpace - (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE + 1 > graph.perThreadInIsoSpaceMatchedElements[threadId].Count) {\n");
                    sourceCode.Indent();
                    sourceCode.AppendFront("graph.AllocateFurtherIsomorphySpaceNestingLevelForParallelizedMatching(threadId);\n");
                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");
                }
            }
            else
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.AppendFront("if(isoSpace >= (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE && "
                                           + "isoSpace - (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE + 1 > graph.inIsoSpaceMatchedElements.Count) {\n");
                    sourceCode.Indent();
                    sourceCode.AppendFront("graph.inIsoSpaceMatchedElements.Add(new Dictionary<GRGEN_LIBGR.IGraphElement, GRGEN_LIBGR.IGraphElement>());\n");
                    sourceCode.AppendFront("graph.inIsoSpaceMatchedElementsGlobal.Add(new Dictionary<GRGEN_LIBGR.IGraphElement, GRGEN_LIBGR.IGraphElement>());\n");
                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");
                }
            }

            if (SetupSubpatternMatching)
            {
                sourceCode.AppendFrontFormat("Stack<GRGEN_LGSP.LGSPSubpatternAction> {0}openTasks ="
                                             + " new Stack<GRGEN_LGSP.LGSPSubpatternAction>();\n", NegativeIndependentNamePrefix);
                sourceCode.AppendFrontFormat("List<Stack<GRGEN_LIBGR.IMatch>> {0}foundPartialMatches ="
                                             + " new List<Stack<GRGEN_LIBGR.IMatch>>();\n", NegativeIndependentNamePrefix);
                sourceCode.AppendFrontFormat("List<Stack<GRGEN_LIBGR.IMatch>> {0}matchesList ="
                                             + " {0}foundPartialMatches;\n", NegativeIndependentNamePrefix);
            }
        }
Esempio n. 9
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckContinueMatching OfIndependentFailed ");
     builder.Append(IsIterationBreaking ? "IterationBreaking\n" : "\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Esempio n. 10
0
        public override void Dump(SourceBuilder builder)
        {
            // first dump local content
            builder.AppendFront("IteratedMatchingDummyLoopPreventingReturn \n");

            // then nested content
            if (NestedOperationsList != null)
            {
                builder.Indent();
                NestedOperationsList.Dump(builder);
                builder.Unindent();
            }
        }
Esempio n. 11
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFrontFormat("CheckContinueMatching IteratedPatternFound {0}\n",
                               IsIterationBreaking ? "IterationBreaking" : "");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Esempio n. 12
0
        public override void Dump(SourceBuilder builder)
        {
            builder.AppendFront("PositivePatternMatched \n");
            if (InParallelizedBody)
            {
                builder.AppendFront("InParallelizedBody \n");
            }

            if (MatchBuildingOperations != null)
            {
                builder.Indent();
                MatchBuildingOperations.Dump(builder);
                builder.Unindent();
            }
        }
Esempio n. 13
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether there are subpattern matching tasks left to execute\n");
            }

            sourceCode.AppendFront("if(openTasks.Count==0)\n");
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            CheckFailedOperations.Emit(sourceCode);

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFrontFormat("// Lookup {0} \n", PatternElementName);
            }

            // todo: randomisierte auswahl des typen wenn RANDOM_LOOKUP_LIST_START ?

            // emit type iteration loop header
            string typeOfVariableContainingType       = NamesOfEntities.TypeOfVariableContainingType(IsNode);
            string variableContainingTypeForCandidate =
                NamesOfEntities.TypeForCandidateVariable(PatternElementName);
            string containerWithAvailableTypes;

            if (Type == GetTypeByIterationType.ExplicitelyGiven)
            {
                containerWithAvailableTypes = TypeName
                                              + "." + PatternElementName + "_AllowedTypes";
            }
            else //(Type == GetTypeByIterationType.AllCompatible)
            {
                containerWithAvailableTypes = RulePatternTypeName
                                              + ".typeVar.SubOrSameTypes";
            }

            sourceCode.AppendFrontFormat("foreach({0} {1} in {2})\n",
                                         typeOfVariableContainingType, variableContainingTypeForCandidate,
                                         containerWithAvailableTypes);

            // open loop
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit type id setting and loop body
            string variableContainingTypeIDForCandidate =
                NamesOfEntities.TypeIdForCandidateVariable(PatternElementName);

            sourceCode.AppendFrontFormat("int {0} = {1}.TypeID;\n",
                                         variableContainingTypeIDForCandidate, variableContainingTypeForCandidate);

            NestedOperationsList.Emit(sourceCode);

            // close loop
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Esempio n. 15
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// dummy loop for iterated matching return prevention\n");
            }

            // open loop
            sourceCode.AppendFront("do\n");
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit loop body
            NestedOperationsList.Emit(sourceCode);

            // close loop
            sourceCode.Unindent();
            sourceCode.AppendFront("} while(false);\n");
        }
Esempio n. 16
0
        public override void Dump(SourceBuilder builder)
        {
            builder.AppendFront("PatternAndSubpatternsMatched ");
            if (InParallelizedBody)
            {
                builder.Append("InParallelizedBody ");
            }
            switch (Type)
            {
            case PatternAndSubpatternsMatchedType.Action:
                builder.Append("Action \n");
                break;

            case PatternAndSubpatternsMatchedType.Iterated:
                builder.Append("Iterated \n");
                break;

            case PatternAndSubpatternsMatchedType.IteratedNullMatch:
                builder.Append("IteratedNullMatch \n");
                break;

            case PatternAndSubpatternsMatchedType.SubpatternOrAlternative:
                builder.Append("SubpatternOrAlternative \n");
                break;

            default:
                builder.Append("INTERNAL ERROR\n");
                break;
            }

            if (MatchBuildingOperations != null)
            {
                builder.Indent();
                MatchBuildingOperations.Dump(builder);
                builder.Unindent();
            }
        }
 public override void Dump(SourceBuilder builder)
 {
     // first dump local content
     builder.AppendFront("GetType ByIteration ");
     if (Type == GetTypeByIterationType.ExplicitelyGiven)
     {
         builder.Append("ExplicitelyGiven ");
         builder.AppendFormat("on {0} in {1} node:{2}\n",
                              PatternElementName, TypeName, IsNode);
     }
     else // Type==GetTypeByIterationType.AllCompatible
     {
         builder.Append("AllCompatible ");
         builder.AppendFormat("on {0} in {1} node:{2}\n",
                              PatternElementName, RulePatternTypeName, IsNode);
     }
     // then nested content
     if (NestedOperationsList != null)
     {
         builder.Indent();
         NestedOperationsList.Dump(builder);
         builder.Unindent();
     }
 }
Esempio n. 18
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether the iterated pattern null match was found\n");
            }

            sourceCode.Append("maxMatchesIterReached:\n");
            if (IsIterationBreaking)
            {
                sourceCode.AppendFront("if(!patternFound && numMatchesIter>=minMatchesIter && !breakIteration)\n");
            }
            else
            {
                sourceCode.AppendFront("if(!patternFound && numMatchesIter>=minMatchesIter)\n");
            }
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            CheckFailedOperations.Emit(sourceCode);

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Esempio n. 19
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// if enough matches were found, we leave\n");
            }

            if (Type == CheckMaximumMatchesType.Action)
            {
                if (InParallelizedBody)
                {
                    sourceCode.AppendFront("if(maxMatches > 0 && parallelTaskMatches[threadId].Count >= maxMatches)\n");
                }
                else
                {
                    sourceCode.AppendFront("if(maxMatches > 0 && matches.Count >= maxMatches)\n");
                }
            }
            else if (Type == CheckMaximumMatchesType.Subpattern)
            {
                sourceCode.AppendFront("if(maxMatches > 0 && foundPartialMatches.Count >= maxMatches)\n");
            }
            else if (Type == CheckMaximumMatchesType.Iterated)
            {
                sourceCode.AppendFront("if(true) // as soon as there's a match, it's enough for iterated\n");
            }

            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            if (Type == CheckMaximumMatchesType.Action && InParallelizedBody)
            {
                sourceCode.AppendFront("maxMatchesFound = true;\n");
            }

            if (EmitProfiling)
            {
                if (InParallelizedBody)
                {
                    sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsSingle.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsMultiple.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].loopStepsSingle.Add(actionEnv.PerformanceInfo.LoopStepsPerThread[threadId]);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].loopStepsMultiple.Add(actionEnv.PerformanceInfo.LoopStepsPerThread[threadId]);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsPerLoopStepSingle.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId] - searchStepsAtLoopStepBegin);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsPerLoopStepMultiple.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId] - searchStepsAtLoopStepBegin);\n", PackagePrefixedActionName);
                }
                else
                {
                    sourceCode.AppendFrontFormat("++actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].callsTotal;\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].searchStepsTotal += actionEnv.PerformanceInfo.SearchSteps - searchStepsAtBegin;\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].loopStepsTotal += loopSteps;\n", PackagePrefixedActionName);

                    sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].searchStepsTotal += actionEnv.PerformanceInfo.SearchSteps - searchStepsAtBegin;\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].loopStepsTotal += loopSteps;\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].searchStepsSingle.Add(actionEnv.PerformanceInfo.SearchSteps - searchStepsAtBegin);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].searchStepsMultiple.Add(actionEnv.PerformanceInfo.SearchSteps - searchStepsAtBegin);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].loopStepsSingle.Add(loopSteps);\n", PackagePrefixedActionName);
                    sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].loopStepsMultiple.Add(loopSteps);\n", PackagePrefixedActionName);

                    if (EmitFirstLoopProfiling)
                    {
                        sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].searchStepsPerLoopStepSingle.Add(actionEnv.PerformanceInfo.SearchSteps - searchStepsAtLoopStepBegin);\n", PackagePrefixedActionName);
                        sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[0].searchStepsPerLoopStepMultiple.Add(actionEnv.PerformanceInfo.SearchSteps - searchStepsAtLoopStepBegin);\n", PackagePrefixedActionName);
                    }
                }
            }

            CheckFailedOperations.Emit(sourceCode);

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
        public override void Emit(SourceBuilder sourceCode)
        {
            string variableContainingBackupOfMappedMember = NamesOfEntities.VariableWithBackupOfIsMatchedGlobalBit(
                PatternElementName, NegativeIndependentNamePrefix);
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);

            if (Parallel)
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.AppendFront("if(isoSpace < (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE) {\n");
                    sourceCode.Indent();
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlagsParallel.IS_MATCHED_BY_ENCLOSING_PATTERN << isoSpace";
                sourceCode.AppendFrontFormat("flagsPerElementGlobal[{0}.uniqueId] &= (ushort)(~({1}) | {2});\n",
                                             variableContainingCandidate,
                                             isMatchedBit,
                                             variableContainingBackupOfMappedMember);

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Unindent();
                    sourceCode.AppendFront("} else { \n");
                    sourceCode.Indent();

                    sourceCode.AppendFrontFormat("if({0} == 0) {{\n", variableContainingBackupOfMappedMember);
                    sourceCode.Indent();
                    sourceCode.AppendFrontFormat(
                        "graph.perThreadInIsoSpaceMatchedElementsGlobal[threadId][isoSpace - (int)GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE]"
                        + ".Remove({0});\n", variableContainingCandidate);
                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");

                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");
                }
            }
            else
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.AppendFront("if(isoSpace < (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE) {\n");
                    sourceCode.Indent();
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED_BY_ENCLOSING_PATTERN << isoSpace";
                sourceCode.AppendFrontFormat("{0}.lgspFlags = {0}.lgspFlags & ~({1}) | {2};\n",
                                             variableContainingCandidate, isMatchedBit, variableContainingBackupOfMappedMember);

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Unindent();
                    sourceCode.AppendFront("} else { \n");
                    sourceCode.Indent();

                    sourceCode.AppendFrontFormat("if({0} == 0) {{\n", variableContainingBackupOfMappedMember);
                    sourceCode.Indent();
                    sourceCode.AppendFrontFormat(
                        "graph.inIsoSpaceMatchedElementsGlobal[isoSpace - (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE]"
                        + ".Remove({0});\n", variableContainingCandidate);
                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");

                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");
                }
            }
        }
Esempio n. 21
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (Type == PatternAndSubpatternsMatchedType.Iterated)
            {
                sourceCode.AppendFront("patternFound = true;\n");
            }

            if (Type != PatternAndSubpatternsMatchedType.Action)
            {
                if (sourceCode.CommentSourceCode)
                {
                    sourceCode.AppendFront("// subpatterns/alternatives were found, extend the partial matches by our local match object\n");
                }
                sourceCode.AppendFront("foreach(Stack<GRGEN_LIBGR.IMatch> currentFoundPartialMatch in matchesList)\n");
                sourceCode.AppendFront("{\n");
                sourceCode.Indent();

                sourceCode.AppendFrontFormat("{0}.{1} match = new {0}.{1}();\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(PatternName));
                if (Type == PatternAndSubpatternsMatchedType.IteratedNullMatch)
                {
                    sourceCode.AppendFront("match._isNullMatch = true; // null match of iterated pattern\n");
                }

                MatchBuildingOperations.Emit(sourceCode); // emit match building operations
                sourceCode.AppendFront("currentFoundPartialMatch.Push(match);\n");

                sourceCode.Unindent();
                sourceCode.AppendFront("}\n");
            }
            else // top-level pattern with subpatterns/alternatives
            {
                if (sourceCode.CommentSourceCode)
                {
                    sourceCode.AppendFront("// subpatterns/alternatives were found, extend the partial matches by our local match object, becoming a complete match object and save it\n");
                }
                sourceCode.AppendFront("foreach(Stack<GRGEN_LIBGR.IMatch> currentFoundPartialMatch in matchesList)\n");
                sourceCode.AppendFront("{\n");
                sourceCode.Indent();

                if (InParallelizedBody)
                {
                    sourceCode.AppendFrontFormat("{0}.{1} match = parallelTaskMatches[threadId].GetNextUnfilledPosition();\n",
                                                 RulePatternClassName, NamesOfEntities.MatchClassName(PatternName));
                }
                else
                {
                    sourceCode.AppendFrontFormat("{0}.{1} match = matches.GetNextUnfilledPosition();\n",
                                                 RulePatternClassName, NamesOfEntities.MatchClassName(PatternName));
                }
                MatchBuildingOperations.Emit(sourceCode); // emit match building operations
                if (InParallelizedBody)
                {
                    sourceCode.AppendFront("match.IterationNumber = currentIterationNumber;\n");
                    sourceCode.AppendFront("parallelTaskMatches[threadId].PositionWasFilledFixIt();\n");
                }
                else
                {
                    sourceCode.AppendFront("matches.PositionWasFilledFixIt();\n");
                }

                sourceCode.Unindent();
                sourceCode.AppendFront("}\n");
                sourceCode.AppendFront("matchesList.Clear();\n");
            }
        }
        public override void Emit(SourceBuilder sourceCode)
        {
            string variableContainingBackupOfMappedMember =
                NamesOfEntities.VariableWithBackupOfIsMatchedBit(PatternElementName, NegativeIndependentNamePrefix);
            string variableContainingCandidate =
                NamesOfEntities.CandidateVariable(PatternElementName);

            sourceCode.AppendFrontFormat("uint {0};\n", variableContainingBackupOfMappedMember);

            if (Parallel)
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.AppendFront("if(isoSpace < (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE) {\n");
                    sourceCode.Indent();
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlagsParallel.IS_MATCHED << isoSpace";
                if (LockForAllThreads)
                {
                    sourceCode.AppendFrontFormat("{0} = flagsPerElement0[{1}.uniqueId] & {2};\n",
                                                 variableContainingBackupOfMappedMember,
                                                 variableContainingCandidate,
                                                 isMatchedBit);
                    sourceCode.AppendFrontFormat("for(int i=0; i<numWorkerThreads; ++i) graph.flagsPerThreadPerElement[i][{0}.uniqueId] |= (ushort)({1});\n",
                                                 variableContainingCandidate,
                                                 isMatchedBit);
                }
                else
                {
                    sourceCode.AppendFrontFormat("{0} = flagsPerElement[{1}.uniqueId] & {2};\n",
                                                 variableContainingBackupOfMappedMember,
                                                 variableContainingCandidate,
                                                 isMatchedBit);
                    sourceCode.AppendFrontFormat("flagsPerElement[{0}.uniqueId] |= (ushort)({1});\n",
                                                 variableContainingCandidate,
                                                 isMatchedBit);
                }

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Unindent();
                    sourceCode.AppendFront("} else {\n");
                    sourceCode.Indent();

                    if (LockForAllThreads)
                    {
                        sourceCode.AppendFrontFormat("{0} = graph.perThreadInIsoSpaceMatchedElements[0][isoSpace - (int)"
                                                     + "GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE].ContainsKey({1}) ? 1U : 0U;\n",
                                                     variableContainingBackupOfMappedMember, variableContainingCandidate);
                        sourceCode.AppendFrontFormat("if({0} == 0) for(int i=0; i<numWorkerThreads; ++i) graph.perThreadInIsoSpaceMatchedElements[i][isoSpace - (int)"
                                                     + "GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE].Add({1},{1});\n",
                                                     variableContainingBackupOfMappedMember, variableContainingCandidate);
                    }
                    else
                    {
                        sourceCode.AppendFrontFormat("{0} = graph.perThreadInIsoSpaceMatchedElements[threadId][isoSpace - (int)"
                                                     + "GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE].ContainsKey({1}) ? 1U : 0U;\n",
                                                     variableContainingBackupOfMappedMember, variableContainingCandidate);
                        sourceCode.AppendFrontFormat("if({0} == 0) graph.perThreadInIsoSpaceMatchedElements[threadId][isoSpace - (int)"
                                                     + "GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE].Add({1},{1});\n",
                                                     variableContainingBackupOfMappedMember, variableContainingCandidate);
                    }

                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");
                }
            }
            else
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.AppendFront("if(isoSpace < (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE) {\n");
                    sourceCode.Indent();
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED << isoSpace";
                sourceCode.AppendFrontFormat("{0} = {1}.lgspFlags & {2};\n",
                                             variableContainingBackupOfMappedMember, variableContainingCandidate, isMatchedBit);
                sourceCode.AppendFrontFormat("{0}.lgspFlags |= {1};\n",
                                             variableContainingCandidate, isMatchedBit);

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Unindent();
                    sourceCode.AppendFront("} else {\n");
                    sourceCode.Indent();

                    sourceCode.AppendFrontFormat("{0} = graph.inIsoSpaceMatchedElements[isoSpace - (int) "
                                                 + "GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE].ContainsKey({1}) ? 1U : 0U;\n",
                                                 variableContainingBackupOfMappedMember, variableContainingCandidate);
                    sourceCode.AppendFrontFormat("if({0} == 0) graph.inIsoSpaceMatchedElements[isoSpace - (int) "
                                                 + "GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE].Add({1},{1});\n",
                                                 variableContainingBackupOfMappedMember, variableContainingCandidate);

                    sourceCode.Unindent();
                    sourceCode.AppendFront("}\n");
                }
            }
        }