Ejemplo n.º 1
0
        protected override bool ApplyImpl(IGraphProcessingEnvironment procEnv)
        {
            bool res;
            try
            {
#if LOG_SEQUENCE_EXECUTION
                procEnv.Recorder.WriteLine("Applying rule " + GetRuleCallString(procEnv));
#endif
                res = procEnv.ApplyRewrite(ParamBindings, 0, 1, Special, Test, Filters) > 0;
            }
            catch (NullReferenceException)
            {
                System.Console.Error.WriteLine("Null reference exception during rule execution (null parameter?): " + Symbol);
                throw;
            }

#if LOG_SEQUENCE_EXECUTION
            if(res)
            {
                procEnv.Recorder.WriteLine("Matched/Applied " + Symbol);
                procEnv.Recorder.Flush();
            }
#endif
            return res;
        }
Ejemplo n.º 2
0
        protected override bool ApplyImpl(IGraphProcessingEnvironment procEnv)
        {
            if(!ChooseRandom)
            {
                bool res;
                try
                {
#if LOG_SEQUENCE_EXECUTION
                    procEnv.Recorder.WriteLine("Applying rule all " + GetRuleCallString(procEnv));
#endif
                    res = procEnv.ApplyRewrite(ParamBindings, -1, -1, Special, Test, Filters) > 0;
                }
                catch (NullReferenceException)
                {
                    System.Console.Error.WriteLine("Null reference exception during rule execution (null parameter?): " + Symbol);
                    throw;
                }
#if LOG_SEQUENCE_EXECUTION
                if(res)
                {
                    procEnv.Recorder.WriteLine("Matched/Applied " + Symbol);
                    procEnv.Recorder.Flush();
                }
#endif
                return res;
            }
            else
            {
                // TODO: Code duplication! Compare with BaseGraph.ApplyRewrite.

                int curMaxMatches = procEnv.MaxMatches;

                object[] parameters;
                if(ParamBindings.ArgumentExpressions.Length > 0)
                {
                    parameters = ParamBindings.Arguments;
                    for(int i = 0; i < ParamBindings.ArgumentExpressions.Length; i++)
                    {
                        if(ParamBindings.ArgumentExpressions[i] != null)
                            parameters[i] = ParamBindings.ArgumentExpressions[i].Evaluate(procEnv);
                    }
                }
                else parameters = null;

                if(ParamBindings.Subgraph!=null)
                    procEnv.SwitchToSubgraph((IGraph)ParamBindings.Subgraph.GetVariableValue(procEnv));

#if DEBUGACTIONS || MATCHREWRITEDETAIL
                procEnv.PerformanceInfo.StartLocal();
#endif
                IMatches matches;
                try
                {
                    matches = ParamBindings.Action.Match(procEnv, curMaxMatches, parameters);
                    for(int i = 0; i < Filters.Count; ++i)
                        ParamBindings.Action.Filter(procEnv, matches, Filters[i]);
                }
                catch (NullReferenceException)
                {
                    System.Console.Error.WriteLine("Null reference exception during rule execution (null parameter?): " + Symbol);
                    throw;
                }
#if DEBUGACTIONS || MATCHREWRITEDETAIL
                procEnv.PerformanceInfo.StopMatch(); // total match time does NOT include listeners anymore
#endif
                procEnv.PerformanceInfo.MatchesFound += matches.Count;

                procEnv.Matched(matches, null, Special);

                bool result = Rewrite(procEnv, matches, null);

                if(ParamBindings.Subgraph != null)
                    procEnv.ReturnFromSubgraph();
                
                return result;
            }
        }
Ejemplo n.º 3
0
        protected override bool ApplyImpl(IGraphProcessingEnvironment procEnv)
        {
            int res = 0;
            try
            {
#if LOG_SEQUENCE_EXECUTION
                procEnv.Recorder.WriteLine("Applying rule all " + GetRuleCallString(procEnv));
#endif
                res = procEnv.ApplyRewrite(ParamBindings, -1, -1, Special, Test, Filters);
            }
            catch(NullReferenceException)
            {
                System.Console.Error.WriteLine("Null reference exception during rule execution (null parameter?): " + Symbol);
                throw;
            }
            CountResult.SetVariableValue(res, procEnv);
#if LOG_SEQUENCE_EXECUTION
            if(res > 0)
            {
                procEnv.Recorder.WriteLine("Matched/Applied " + Symbol + " yielding " + res + " matches");
                procEnv.Recorder.Flush();
            }
#endif
            return res > 0;
        }