コード例 #1
0
ファイル: PluginView.axaml.cs プロジェクト: nilaoda/Toolbox
        public PluginViewModel(
            PluginView view)
        {
            _view = view;

            IPluginService pluginService = Locator.Current.GetService <IPluginService>();

            _operationService = Locator.Current.GetService <OperationService>();

            OperationsCount = pluginService.OperationCollection.Count;

            OperationsList = new(
                pluginService.OperationCollection
                .GroupBy(x => x.OperationAttribute.Category)
                .Select(x =>
            {
                // Create OperationModel
                ObservableCollectionEx <OperationModel> models = new(
                    x.Select(y => new OperationModel
                {
                    Id = y.OperationAttribute.Id,
                    Name = y.OperationAttribute.Name,
                    Description = y.OperationAttribute.Description,
                    Rate = y.OperationAttribute.Rate,
                    Category = y.OperationAttribute.Category,
                    Author = y.OperationMeta.Author,
                    Type = y.OperationType
                }));

                // Create SearchStorage
                SearchStorage <OperationModel> searchStorage = new()
                {
                    Mode = CharParseMode.EnablePinyinSearch
                };
                searchStorage.Add(models, y => y.Name);

                return(new OperationModel
                {
                    Name = x.Key,
                    Children = models,
                    SearchStorage = searchStorage
                });
            }));

            this
            .ObservableForProperty(x => x.OperationSearchText)
            .Throttle(TimeSpan.FromSeconds(1))
            .Subscribe(x => OperationsList
                       .ForEach(y => y.Children.Reset(
                                    y.SearchStorage.Search(x.Value))));

            this
            .ObservableForProperty(x => x.OperationSearchText)
            .Subscribe(_ => ExpendTree());

            _isOperationSelected = this
                                   .WhenAnyValue(x => x.SelectedOperation)
                                   .Select(x => x?.Type != null)
                                   .ToProperty(this, x => x.IsOperationSelected);
        }
コード例 #2
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <summary>
        /// Dumps search program
        /// </summary>
        public override void Dump(SourceBuilder builder)
        {
            // first dump local content
            builder.AppendFrontFormat("Search program {0} of alternative case\n", Parallel ? Name + "_parallelized" : Name);

            // then nested content
            if (OperationsList != null)
            {
                builder.Indent();
                OperationsList.Dump(builder);
                builder.Unindent();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
        public override BlockSyntax GenerateMethodBody()
        {
            var whileStatement = new SyntaxList <StatementSyntax>()
                                 .Add(SF.ParseStatement("if (!reader.TryGetByte(out var bsonType)) { return false; }"))
                                 .Add(SF.ParseStatement("if (!reader.TryGetCStringAsSpan(out var bsonName)) { return false; } "))
                                 .AddRange(OperationsList.CreateReadOperations(ClassSymbol, Members).Generate())
                                 .Add(SF.ParseStatement(@$ "throw new ArgumentException($" "{ClassSymbol.Name}.TryParse  with bson type number {{bsonType}} and name {{System.Text.Encoding.UTF8.GetString(bsonName)}}" ");"));

            return(SF.Block(
                       SF.ExpressionStatement(SF.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, Basics.TryParseOutVariableIdentifier, Basics.ObjectCreationWitoutArgs(ClassSymbol))),
                       SF.ParseStatement("if (!reader.TryGetInt32(out var docLength)) { return false; }"),
                       SF.ParseStatement("var unreaded = reader.Remaining + sizeof(int);"),
                       SF.WhileStatement(
                           attributeLists: default,
コード例 #5
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <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");
        }
コード例 #6
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <summary>
        /// Dumps search program followed by missing preset search subprograms
        /// </summary>
        public override void Dump(SourceBuilder builder)
        {
            // first dump local content
            builder.AppendFrontFormat("Search program {0} of action \n", Name);

            // then nested content
            if (OperationsList != null)
            {
                builder.Indent();
                OperationsList.Dump(builder);
                builder.Unindent();
            }

            // then next missing preset search subprogram
            if (Next != null)
            {
                Next.Dump(builder);
            }
        }
コード例 #7
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");
        }
コード例 #8
0
 public static void Cancel()
 {
     StopTask = Task.Factory.StartNew(() => OperationsList.ForEach(x => x?.Abort()));
 }
コード例 #9
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <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");
        }
コード例 #10
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <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);
        }
コード例 #11
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <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.AppendFront("\n");
            sourceCode.AppendFrontFormat("public {0} {1}("
                                         + "GRGEN_LGSP.LGSPActionExecutionEnvironment actionEnv, int maxMatches{2})\n", matchesType, Name, Parameters);
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            //sourceCode.AppendFrontFormat("Console.WriteLine(\"called matcher for {0}\");\n", PatternName);
            sourceCode.AppendFront("GRGEN_LGSP.LGSPGraph graph = actionEnv.graph;\n");
            sourceCode.AppendFront("matches.Clear();\n");
            sourceCode.AppendFront("int isoSpace = 0;\n");
            sourceCode.AppendFront("actionEnvParallel = actionEnv;\n");
            sourceCode.AppendFront("maxMatchesParallel = maxMatches;\n");
            sourceCode.AppendFront("graph.EnsureSufficientIsomorphySpacesForParallelizedMatchingAreAvailable(numWorkerThreads);\n");
            sourceCode.AppendFront("List<ushort> flagsPerElement0 = graph.flagsPerThreadPerElement[0];\n");
            sourceCode.AppendFront("int numThreadsSignaled = 0;\n");

            if (EmitProfiling)
            {
                sourceCode.AppendFront("actionEnv.PerformanceInfo.ResetStepsPerThread(numWorkerThreads);\n");
                sourceCode.AppendFront("bool parallelMatcherUsed = false;\n");

                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.AppendFront("if(parallelMatcherUsed)\n");
                sourceCode.AppendFront("{\n");
                sourceCode.Indent();
                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.AppendFront("for(int i=0; i<numThreadsSignaled; ++i)\n");
                sourceCode.AppendFront("{\n");
                sourceCode.Indent();
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[i].searchStepsTotal += actionEnv.PerformanceInfo.SearchStepsPerThread[i];\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].searchStepsTotal += actionEnv.PerformanceInfo.SearchStepsPerThread[i];\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.SearchSteps += actionEnv.PerformanceInfo.SearchStepsPerThread[i];\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].averagesPerThread[i].loopStepsTotal += actionEnv.PerformanceInfo.LoopStepsPerThread[i];\n", PackagePrefixedPatternName);
                sourceCode.AppendFrontFormat("actionEnv.PerformanceInfo.ActionProfiles[\"{0}\"].loopStepsTotal += actionEnv.PerformanceInfo.LoopStepsPerThread[i];\n", PackagePrefixedPatternName);
                sourceCode.Unindent();
                sourceCode.AppendFront("}\n");
                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);
            }
        }
コード例 #12
0
ファイル: SearchProgram.cs プロジェクト: tmaierhofer/grgen
        /// <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);
            }
        }
コード例 #13
0
ファイル: Processor.cs プロジェクト: Confirmit/Students
 public Processor(AbstractOperationFactory operationFactory)
 {
     OperationList=new OperationsList();
     _operationFactory = operationFactory;
 }
コード例 #14
0
ファイル: Processor.cs プロジェクト: taler0n/Students
 public Processor(AbstractOperationFactory operationFactory)
 {
     OperationList     = new OperationsList();
     _operationFactory = operationFactory;
 }