Example #1
0
 public override void Emit(SourceBuilder sourceCode)
 {
     sourceCode.AppendFrontFormat("{0}.{1} match_{2} = new {0}.{1}();\n",
                                  RulePatternClassName, NamesOfEntities.MatchClassName(PatternName), MatchName);
     sourceCode.AppendFrontFormat("match_{0}.SetMatchOfEnclosingPattern({1});\n",
                                  MatchName, MatchOfEnclosingPatternName);
 }
 public override void Emit(SourceBuilder sourceCode)
 {
     sourceCode.AppendFrontFormat("// build match of {0} for patternpath checks\n",
                                  PatternGraphName);
     sourceCode.AppendFrontFormat("if({0}==null) {0} = new {1}.{2}();\n",
                                  NamesOfEntities.PatternpathMatch(PatternGraphName),
                                  RulePatternClassName,
                                  NamesOfEntities.MatchClassName(PatternGraphName));
     sourceCode.AppendFrontFormat("{0}._matchOfEnclosingPattern = {1};\n",
                                  NamesOfEntities.PatternpathMatch(PatternGraphName), MatchOfNestingPattern);
 }
Example #3
0
        public override void Emit(SourceBuilder sourceCode)
        {
            sourceCode.AppendFrontFormat("if({0} != null)\n", NamesOfEntities.FoundMatchesForFilteringVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit check whether hash is contained in found matches hash map
            sourceCode.AppendFrontFormat("if(!{0}.ContainsKey({1}))\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // if not, just insert it
            sourceCode.AppendFrontFormat("{0}[{1}] = match;\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());

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

            // otherwise loop till end of collision list of the hash set, insert there
            sourceCode.AppendFrontFormat("{0} {1} = {2}[{3}];\n",
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName),
                                         NamesOfEntities.DuplicateMatchCandidateVariable(),
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFrontFormat("while({0}.nextWithSameHash != null) {0} = {0}.nextWithSameHash;\n",
                                         NamesOfEntities.DuplicateMatchCandidateVariable());

            sourceCode.AppendFrontFormat("{0}.nextWithSameHash = match;\n",
                                         NamesOfEntities.DuplicateMatchCandidateVariable());

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

            if (ParallelizedAction)
            {
                sourceCode.AppendFrontFormat("match.{0} = {0};\n",
                                             NamesOfEntities.DuplicateMatchHashVariable());
            }

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Example #4
0
        /// <summary>
        /// Emits the matcher source code for the search program
        /// head, search program operations list in depth first walk over search program operations list, tail
        /// </summary>
        public override void Emit(SourceBuilder sourceCode)
        {
#if RANDOM_LOOKUP_LIST_START
            sourceCode.AppendFront("private Random random = new Random(13795661);\n");
#endif

            if (Parallel)
            {
                sourceCode.AppendFront("public override void " + Name + "_parallelized"
                                       + "(List<Stack<GRGEN_LIBGR.IMatch>> foundPartialMatches, "
                                       + "int maxMatches, int isoSpace, int threadId)\n");
            }
            else
            {
                sourceCode.AppendFront("public override void " + Name
                                       + "(List<Stack<GRGEN_LIBGR.IMatch>> foundPartialMatches, "
                                       + "int maxMatches, int isoSpace)\n");
            }
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            sourceCode.AppendFront("GRGEN_LGSP.LGSPGraph graph = actionEnv.graph;\n");
            if (Parallel)
            {
                sourceCode.AppendFront("List<ushort> flagsPerElement = graph.flagsPerThreadPerElement[threadId];\n");
                sourceCode.AppendFront("List<ushort> flagsPerElement0 = graph.flagsPerThreadPerElement[0];\n");
                sourceCode.AppendFront("List<ushort> flagsPerElementGlobal = graph.flagsPerThreadPerElement[threadId];\n");
            }

            foreach (string graphsOnPath in NamesOfPatternGraphsOnPathToEnclosedPatternpath)
            {
                sourceCode.AppendFrontFormat("{0}.{1} {2} = null;\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(graphsOnPath),
                                             NamesOfEntities.PatternpathMatch(graphsOnPath));
            }

            GenerateIndependentsMatchObjects(sourceCode);

            OperationsList.Emit(sourceCode);

            sourceCode.AppendFront("return;\n");
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Example #5
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether a duplicate match to be purged was found or will be found\n");
            }

            // emit hash variable declaration
            sourceCode.AppendFrontFormat("int {0} = 0;\n", NamesOfEntities.DuplicateMatchHashVariable());

            // only do the rest if more than one match is requested
            sourceCode.AppendFront("if(maxMatches!=1) {\n");
            sourceCode.Indent();

            // emit found matches hash map initialization as needed
            sourceCode.AppendFrontFormat("if({0}==null) {0} = new Dictionary<int, {1}>();\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName));

            // emit hash variable initialization with result of hash computation
            sourceCode.AppendFrontFormat("{0} = unchecked(",
                                         NamesOfEntities.DuplicateMatchHashVariable());
            EmitHashComputation(sourceCode, NeededElements.Length - 1);
            sourceCode.Append(");\n");

            // emit check whether hash is contained in found matches hash map
            sourceCode.AppendFrontFormat("if({0}.ContainsKey({1}))\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit check whether one of the matches in the hash map with same hash is equal to the locally matched elements
            sourceCode.AppendFrontFormat("{0} {1} = {2}[{3}];\n",
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName),
                                         NamesOfEntities.DuplicateMatchCandidateVariable(),
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("do {\n");
            sourceCode.Indent();

            // emit check for same elements
            sourceCode.AppendFront("if(");
            for (int i = 0; i < NeededElements.Length; ++i)
            {
                if (i != 0)
                {
                    sourceCode.Append(" && ");
                }
                sourceCode.AppendFormat("{0}._{1} == {2}",
                                        NamesOfEntities.DuplicateMatchCandidateVariable() + MatchObjectPaths[i],
                                        NamesOfEntities.MatchName(NeededElementsUnprefixedName[i], NeededElementsIsNode[i] ? BuildMatchObjectType.Node : BuildMatchObjectType.Edge),
                                        NamesOfEntities.CandidateVariable(NeededElements[i]));
            }
            sourceCode.Append(")\n");

            // emit check failed code, i.e. the current local match is equivalent to one of the already found ones, a duplicate
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // close "emit check whether one of the matches in the hash map with same hash is equal to the locally matched elements"
            // switching to next match with the same hash, if available
            sourceCode.Unindent();
            sourceCode.AppendFront("} ");
            sourceCode.AppendFormat("while(({0} = {0}.nextWithSameHash) != null);\n",
                                    NamesOfEntities.DuplicateMatchCandidateVariable());

            // close "emit check whether hash is contained in found matches hash map"
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // close "only do the rest if more than one match is requested"
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Example #6
0
        /// <summary>
        /// Emits the matcher source code for the search program
        /// head, search program operations list in depth first walk over search program operations list, tail
        /// </summary>
        public override void Emit(SourceBuilder sourceCode)
        {
#if RANDOM_LOOKUP_LIST_START
            sourceCode.AppendFront("private Random random = new Random(13795661);\n");
#endif

            if (Parallel)
            {
                sourceCode.AppendFront("public override void " + Name + "_parallelized"
                                       + "(List<Stack<GRGEN_LIBGR.IMatch>> foundPartialMatches, "
                                       + "int maxMatches, int isoSpace, int threadId)\n");
            }
            else
            {
                sourceCode.AppendFront("public override void " + Name
                                       + "(List<Stack<GRGEN_LIBGR.IMatch>> foundPartialMatches, "
                                       + "int maxMatches, int isoSpace)\n");
            }
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            sourceCode.AppendFront("bool patternFound = false;\n");
            sourceCode.AppendFront("GRGEN_LGSP.LGSPGraph graph = actionEnv.graph;\n");
            if (Parallel)
            {
                sourceCode.AppendFront("List<ushort> flagsPerElement = graph.flagsPerThreadPerElement[threadId];\n");
                sourceCode.AppendFront("List<ushort> flagsPerElement0 = graph.flagsPerThreadPerElement[0];\n");
                sourceCode.AppendFront("List<ushort> flagsPerElementGlobal = graph.flagsPerThreadPerElement[threadId];\n");
            }

            foreach (string graphsOnPath in NamesOfPatternGraphsOnPathToEnclosedPatternpath)
            {
                sourceCode.AppendFrontFormat("{0}.{1} {2} = null;\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(graphsOnPath),
                                             NamesOfEntities.PatternpathMatch(graphsOnPath));
            }

            GenerateIndependentsMatchObjects(sourceCode);

            if (WasIndependentInlined)
            {
                sourceCode.AppendFrontFormat("Dictionary<int, {0}> {1} = null;\n",
                                             RulePatternClassName + "." + NamesOfEntities.MatchClassName(IterPathPrefix + IterPatternName),
                                             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(IterPathPrefix + IterPatternName),
                                             NamesOfEntities.FoundMatchesForFilteringVariable());

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

            sourceCode.AppendFront("return;\n");
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Example #7
0
        /// <summary>
        /// Generates match objects of independents
        /// </summary>
        protected void GenerateIndependentsMatchObjects(SourceBuilder sourceCode)
        {
            for (int i = 0; i < MatchingPatternClassTypeName.Count; ++i)
            {
                if (NestedIndependents[i] == null)
                {
                    continue;
                }

                foreach (KeyValuePair <PatternGraph, bool> nestedIndependent in NestedIndependents[i])
                {
                    if (nestedIndependent.Value == false)
                    {
                        continue; // if independent is not nested in iterated with potentially more than one match then matcher-class-based match variables are sufficient, only one match is living at a time
                    }
                    if (nestedIndependent.Key.originalPatternGraph != null)
                    {
                        sourceCode.AppendFrontFormat("{0} {1} = new {0}();\n",
                                                     nestedIndependent.Key.originalSubpatternEmbedding.matchingPatternOfEmbeddedGraph.GetType().Name + "." + NamesOfEntities.MatchClassName(nestedIndependent.Key.originalPatternGraph.pathPrefix + nestedIndependent.Key.originalPatternGraph.name),
                                                     NamesOfEntities.MatchedIndependentVariable(nestedIndependent.Key.pathPrefix + nestedIndependent.Key.name));
                    }
                    else
                    {
                        sourceCode.AppendFrontFormat("{0} {1} = new {0}();\n",
                                                     MatchingPatternClassTypeName[i] + "." + NamesOfEntities.MatchClassName(nestedIndependent.Key.pathPrefix + nestedIndependent.Key.name),
                                                     NamesOfEntities.MatchedIndependentVariable(nestedIndependent.Key.pathPrefix + nestedIndependent.Key.name));
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Emits the matcher source code for all search programs
        /// first head of matching function of the current search program
        /// then the search program operations list in depth first walk over search program operations list
        /// then tail of matching function of the current search program
        /// and finally continues in missing preset search program list by emitting following search program
        /// </summary>
        public override void Emit(SourceBuilder sourceCode)
        {
            string matchType   = RulePatternClassName + "." + NamesOfEntities.MatchInterfaceName(PatternName);
            string matchesType = "GRGEN_LIBGR.IMatchesExact<" + matchType + ">";

            sourceCode.AppendFront("\n");
            sourceCode.AppendFrontFormat("private void {0}()\n", Name);
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            sourceCode.AppendFront("threadId = GRGEN_LGSP.WorkerPool.ThreadId;\n");
            //sourceCode.AppendFrontFormat("Console.WriteLine(\"start work for {0} at threadId \" + threadId);\n", PatternName);
            sourceCode.AppendFront("GRGEN_LGSP.LGSPActionExecutionEnvironment actionEnv = actionEnvParallel;\n");
            sourceCode.AppendFront("int maxMatches = maxMatchesParallel;\n");
            sourceCode.AppendFront("GRGEN_LGSP.LGSPGraph graph = actionEnv.graph;\n");
            sourceCode.AppendFront("List<ushort> flagsPerElement = graph.flagsPerThreadPerElement[threadId];\n");
            sourceCode.AppendFront("List<ushort> flagsPerElement0 = graph.flagsPerThreadPerElement[0];\n");
            sourceCode.AppendFront("List<ushort> flagsPerElementGlobal = graph.flagsPerThreadPerElement[threadId];\n");
            sourceCode.AppendFront("int isoSpace = 0;\n");

            if (NamesOfPatternGraphsOnPathToEnclosedPatternpath.Count > 0)
            {
                sourceCode.AppendFront("bool searchPatternpath = false;\n");
            }
            foreach (string graphsOnPath in NamesOfPatternGraphsOnPathToEnclosedPatternpath)
            {
                sourceCode.AppendFrontFormat("{0}.{1} {2} = null;\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(graphsOnPath),
                                             NamesOfEntities.PatternpathMatch(graphsOnPath));
            }

            if (SetupSubpatternMatching)
            {
                sourceCode.AppendFront("Stack<GRGEN_LGSP.LGSPSubpatternAction> openTasks = new Stack<"
                                       + "GRGEN_LGSP.LGSPSubpatternAction>();\n");
                sourceCode.AppendFront("List<Stack<GRGEN_LIBGR.IMatch>> foundPartialMatches = new List<Stack<"
                                       + "GRGEN_LIBGR.IMatch>>();\n");
                sourceCode.AppendFront("List<Stack<GRGEN_LIBGR.IMatch>> matchesList = foundPartialMatches;\n");
            }

            GenerateIndependentsMatchObjects(sourceCode);

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

            if (EmitProfiling)
            {
                sourceCode.AppendFront("long searchStepsAtLoopStepBegin;\n");
            }

            OperationsList.Emit(sourceCode);

            //sourceCode.AppendFrontFormat("Console.WriteLine(\"work done for {0} at threadId \" + threadId);\n", PatternName);
            if (EmitProfiling)
            {
                sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsSingle.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]);\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsMultiple.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]);\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].loopStepsSingle.Add(actionEnv.PerformanceInfo.LoopStepsPerThread[threadId]);\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].loopStepsMultiple.Add(actionEnv.PerformanceInfo.LoopStepsPerThread[threadId]);\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("if(maxMatches==1) actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsPerLoopStepSingle.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId] - searchStepsAtLoopStepBegin);\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("else actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[threadId].searchStepsPerLoopStepMultiple.Add(actionEnv.PerformanceInfo.SearchStepsPerThread[threadId] - searchStepsAtLoopStepBegin);\n", PackagePrefixedPatternName);
            }

            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(PatternName),
                                             NamesOfEntities.FoundMatchesForFilteringVariable());

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

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

            Debug.Assert(Next == null);
        }
Example #9
0
        /// <summary>
        /// Emits the matcher source code for all search programs
        /// first head of matching function of the current search program
        /// then the search program operations list in depth first walk over search program operations list
        /// then tail of matching function of the current search program
        /// and finally continues in missing preset search program list by emitting following search program
        /// </summary>
        public override void Emit(SourceBuilder sourceCode)
        {
#if RANDOM_LOOKUP_LIST_START
            sourceCode.AppendFront("private Random random = new Random(13795661);\n");
#endif
            string matchType   = RulePatternClassName + "." + NamesOfEntities.MatchInterfaceName(PatternName);
            string matchesType = "GRGEN_LIBGR.IMatchesExact<" + matchType + ">";
            sourceCode.AppendFrontFormat("public {0} {1}("
                                         + "GRGEN_LGSP.LGSPActionExecutionEnvironment actionEnv, int maxMatches{2})\n", matchesType, Name, Parameters);
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            if (Arguments != null)
            {
                sourceCode.AppendFront("// maybe null dispatching\n");
                EmitMaybeNullDispatching(sourceCode, 0, 0);
            }

            sourceCode.AppendFront("GRGEN_LGSP.LGSPGraph graph = actionEnv.graph;\n");
            sourceCode.AppendFront("matches.Clear();\n");
            sourceCode.AppendFront("int isoSpace = 0;\n");

            if (NamesOfPatternGraphsOnPathToEnclosedPatternpath.Count > 0)
            {
                sourceCode.AppendFront("bool searchPatternpath = false;\n");
            }
            foreach (string graphsOnPath in NamesOfPatternGraphsOnPathToEnclosedPatternpath)
            {
                sourceCode.AppendFrontFormat("{0}.{1} {2} = null;\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(graphsOnPath),
                                             NamesOfEntities.PatternpathMatch(graphsOnPath));
            }

            if (SetupSubpatternMatching)
            {
                sourceCode.AppendFront("Stack<GRGEN_LGSP.LGSPSubpatternAction> openTasks = new Stack<"
                                       + "GRGEN_LGSP.LGSPSubpatternAction>();\n");
                sourceCode.AppendFront("List<Stack<GRGEN_LIBGR.IMatch>> foundPartialMatches = new List<Stack<"
                                       + "GRGEN_LIBGR.IMatch>>();\n");
                sourceCode.AppendFront("List<Stack<GRGEN_LIBGR.IMatch>> matchesList = foundPartialMatches;\n");
            }

            GenerateIndependentsMatchObjects(sourceCode);

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

            if (EmitProfiling)
            {
                sourceCode.AppendFront("long searchStepsAtBegin = actionEnv.PerformanceInfo.SearchSteps;\n");
                sourceCode.AppendFront("long searchStepsAtLoopStepBegin = searchStepsAtBegin;\n");
                sourceCode.AppendFront("int loopSteps = 0;\n");
            }

            OperationsList.Emit(sourceCode);

            if (EmitProfiling)
            {
                sourceCode.AppendFrontFormat("++actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].callsTotal;\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].searchStepsTotal += actionEnv.PerformanceInfo.SearchSteps - searchStepsAtBegin;\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].loopStepsTotal += loopSteps;\n", PackagePrefixedPatternName);

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

            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(PatternName),
                                             NamesOfEntities.FoundMatchesForFilteringVariable());

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

#if ENSURE_FLAGS_IN_GRAPH_ARE_EMPTY_AT_LEAVING_TOP_LEVEL_MATCHING_ACTION
            sourceCode.AppendFront("graph.CheckEmptyFlags();\n");
#endif
            sourceCode.AppendFront("return matches;\n");
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // emit search subprograms
            if (Next != null)
            {
                Next.Emit(sourceCode);
            }
        }
Example #10
0
        public override void Emit(SourceBuilder sourceCode)
        {
            string matchName = NamesOfEntities.MatchName(PatternElementUnprefixedName, Type);

            if (Type == BuildMatchObjectType.Node || Type == BuildMatchObjectType.Edge)
            {
                string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);
                sourceCode.AppendFrontFormat("{0}._{1} = {2};\n",
                                             MatchObjectName, matchName, variableContainingCandidate);
            }
            else if (Type == BuildMatchObjectType.Variable)
            {
                string variableName = NamesOfEntities.Variable(PatternElementName);
                sourceCode.AppendFrontFormat("{0}._{1} = {2};\n",
                                             MatchObjectName, matchName, variableName);
            }
            else if (Type == BuildMatchObjectType.Subpattern)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = (@{2})currentFoundPartialMatch.Pop();\n",
                                             MatchObjectName, matchName, PatternElementType);
                sourceCode.AppendFrontFormat("{0}._{1}._matchOfEnclosingPattern = {0};\n",
                                             MatchObjectName, matchName);
            }
            else if (Type == BuildMatchObjectType.InlinedSubpattern)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = match_{2};\n",
                                             MatchObjectName, matchName, PatternElementName);
            }
            else if (Type == BuildMatchObjectType.Iteration)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = new GRGEN_LGSP.LGSPMatchesList<{2}.{3}, {2}.{4}>(null);\n",
                                             MatchObjectName, matchName,
                                             RulePatternClassName, NamesOfEntities.MatchClassName(PatternElementType), NamesOfEntities.MatchInterfaceName(PatternElementType));
                sourceCode.AppendFrontFormat("while(currentFoundPartialMatch.Count>0 && currentFoundPartialMatch.Peek() is {0}.{1}) ",
                                             RulePatternClassName, NamesOfEntities.MatchInterfaceName(PatternElementType));
                sourceCode.Append("{\n");
                sourceCode.Indent();
                sourceCode.AppendFrontFormat("{0}.{1} cfpm = ({0}.{1})currentFoundPartialMatch.Pop();\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(PatternElementType));
                sourceCode.AppendFront("if(cfpm.IsNullMatch) break;\n");
                sourceCode.AppendFrontFormat("cfpm.SetMatchOfEnclosingPattern({0});\n",
                                             MatchObjectName);
                sourceCode.AppendFrontFormat("{0}._{1}.Add(cfpm);\n",
                                             MatchObjectName, matchName);
                sourceCode.Unindent();
                sourceCode.AppendFront("}\n");
            }
            else if (Type == BuildMatchObjectType.Alternative)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = ({2}.{3})currentFoundPartialMatch.Pop();\n",
                                             MatchObjectName, matchName, RulePatternClassName, NamesOfEntities.MatchInterfaceName(PatternElementType));
                sourceCode.AppendFrontFormat("{0}._{1}.SetMatchOfEnclosingPattern({0});\n",
                                             MatchObjectName, matchName);
            }
            else //if(Type == BuildMatchObjectType.Independent)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = {2};\n",
                                             MatchObjectName, matchName, NamesOfEntities.MatchedIndependentVariable(PatternElementName));
                sourceCode.AppendFrontFormat("{0} = new {1}({0});\n",
                                             NamesOfEntities.MatchedIndependentVariable(PatternElementName),
                                             RulePatternClassName + "." + NamesOfEntities.MatchClassName(MatchClassName));
                sourceCode.AppendFrontFormat("{0}._{1}.SetMatchOfEnclosingPattern({0});\n",
                                             MatchObjectName, matchName);
            }
        }