コード例 #1
0
        public override void Emit(SourceBuilder sourceCode)
        {
            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));
            }

            // emit match building operations
            MatchBuildingOperations.Emit(sourceCode);

            if (InParallelizedBody)
            {
                sourceCode.AppendFront("match.IterationNumber = currentIterationNumber;\n");
                sourceCode.AppendFront("parallelTaskMatches[threadId].PositionWasFilledFixIt();\n");
            }
            else
            {
                sourceCode.AppendFront("matches.PositionWasFilledFixIt();\n");
            }
        }
        public override void Emit(SourceBuilder sourceCode)
        {
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);
            string variableContainingBackupOfMappedMemberGlobalSome =
                NamesOfEntities.VariableWithBackupOfIsMatchedGlobalInSomePatternBit(PatternElementName, NegativeIndependentNamePrefix);
            string isMatchedInSomePatternBit = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED_BY_SOME_ENCLOSING_PATTERN";

            sourceCode.AppendFrontFormat("{0}.lgspFlags = {0}.lgspFlags & ~({1}) | {2};\n",
                                         variableContainingCandidate, isMatchedInSomePatternBit, variableContainingBackupOfMappedMemberGlobalSome);
        }
コード例 #3
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFrontFormat("// Lookup {0} \n", PatternElementName);
            }

            string variableContainingTypeIDForCandidate =
                NamesOfEntities.TypeIdForCandidateVariable(PatternElementName);

            sourceCode.AppendFrontFormat("int {0} = {1};\n",
                                         variableContainingTypeIDForCandidate, TypeID);
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        public override void Emit(SourceBuilder sourceCode)
        {
            sourceCode.AppendFront("Stack<GRGEN_LIBGR.IMatch> currentFoundPartialMatch = new Stack<GRGEN_LIBGR.IMatch>();\n");
            sourceCode.AppendFront("foundPartialMatches.Add(currentFoundPartialMatch);\n");

            sourceCode.AppendFrontFormat("{0}.{1} match = new {0}.{1}();\n",
                                         RulePatternClassName, NamesOfEntities.MatchClassName(PatternName));
            if (IsIteratedNullMatch)
            {
                sourceCode.AppendFront("match._isNullMatch = true; // null match of iterated pattern\n");
            }
            else
            {
                MatchBuildingOperations.Emit(sourceCode); // emit match building operations
            }
            sourceCode.AppendFront("currentFoundPartialMatch.Push(match);\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");
        }
コード例 #7
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.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");
                }
            }
        }
        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");
                }
            }
        }