コード例 #1
0
        public string ToString(SubruleDebuggingEvent evt)
        {
            switch (evt)
            {
            case SubruleDebuggingEvent.Add: return("add");

            case SubruleDebuggingEvent.Rem: return("rem");

            case SubruleDebuggingEvent.Emit: return("emit");

            case SubruleDebuggingEvent.Halt: return("halt");

            case SubruleDebuggingEvent.Highlight: return("highlight");

            case SubruleDebuggingEvent.Match: return("match");

            case SubruleDebuggingEvent.New: return("new");

            case SubruleDebuggingEvent.Delete: return("delete");

            case SubruleDebuggingEvent.Retype: return("retype");

            case SubruleDebuggingEvent.SetAttributes: return("set attributes");

            default: return("INTERNAL FAILURE, unknown SubruleDebuggingEvent");
            }
        }
コード例 #2
0
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, string graphElementName,
                                          SubruleDebuggingDecision sdd, SequenceExpression ifClause)
 {
     this.debuggingEvent  = sde;
     this.nameToMatch     = graphElementName;
     this.decisionOnMatch = sdd;
     this.ifClause        = ifClause;
 }
コード例 #3
0
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, string message,
                                          SubruleMesssageMatchingMode smmm, SubruleDebuggingDecision sdd)
 {
     this.debuggingEvent      = sde;
     this.messageMatchingMode = smmm;
     this.messageToMatch      = message;
     this.decisionOnMatch     = sdd;
 }
コード例 #4
0
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, IAction action,
                                          SubruleDebuggingDecision sdd, SequenceExpression ifClause)
 {
     this.debuggingEvent  = sde;
     this.actionToMatch   = action;
     this.decisionOnMatch = sdd;
     this.ifClause        = ifClause;
 }
コード例 #5
0
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, GrGenType graphElementType,
                                          bool only, SubruleDebuggingDecision sdd, SequenceExpression ifClause)
 {
     this.debuggingEvent  = sde;
     this.typeToMatch     = graphElementType;
     this.onlyThisType    = only;
     this.decisionOnMatch = sdd;
     this.ifClause        = ifClause;
 }
コード例 #6
0
 public SubruleDebuggingDecision Decide(SubruleDebuggingEvent sde, object data, IGraphProcessingEnvironment procEnv, out SubruleDebuggingConfigurationRule cr)
 {
     foreach (SubruleDebuggingConfigurationRule rule in configurationRules)
     {
         SubruleDebuggingDecision result = rule.Decide(sde, data, procEnv);
         if (result != SubruleDebuggingDecision.Undefined)
         {
             cr = rule;
             return(result);
         }
     }
     cr = null;
     return(SubruleDebuggingDecision.Undefined);
 }
コード例 #7
0
        public SubruleDebuggingDecision Decide(SubruleDebuggingEvent sde, object data, IGraphProcessingEnvironment procEnv)
        {
            if (!enabled)
            {
                return(SubruleDebuggingDecision.Undefined);
            }
            if (debuggingEvent != sde)
            {
                return(SubruleDebuggingDecision.Undefined);
            }

            switch (sde)
            {
            case SubruleDebuggingEvent.Add:
            case SubruleDebuggingEvent.Rem:
            case SubruleDebuggingEvent.Emit:
            case SubruleDebuggingEvent.Halt:
            case SubruleDebuggingEvent.Highlight:
            {
                string message = (string)data;
                switch (messageMatchingMode)
                {
                case SubruleMesssageMatchingMode.Equals:
                    if (message == messageToMatch)
                    {
                        return(decisionOnMatch);
                    }
                    break;

                case SubruleMesssageMatchingMode.StartsWith:
                    if (message.StartsWith(messageToMatch))
                    {
                        return(decisionOnMatch);
                    }
                    break;

                case SubruleMesssageMatchingMode.EndsWith:
                    if (message.EndsWith(messageToMatch))
                    {
                        return(decisionOnMatch);
                    }
                    break;

                case SubruleMesssageMatchingMode.Contains:
                    if (message.Contains(messageToMatch))
                    {
                        return(decisionOnMatch);
                    }
                    break;

                default:
                    throw new Exception("INTERNAL FAILURE: unkonwn message matching mode");
                }
            }
                return(SubruleDebuggingDecision.Undefined);

            case SubruleDebuggingEvent.Match:
            {
                IMatches matches = (IMatches)data;
                if (matches.Producer == actionToMatch)
                {
                    if (ifClause != null)
                    {
                        object oldThis = procEnv.GetVariableValue("this");
                        bool   result  = false;
                        foreach (IMatch match in matches)
                        {
                            procEnv.SetVariableValue("this", match);
                            if ((bool)ifClause.Evaluate(procEnv))
                            {
                                result = true;
                                break;
                            }
                        }
                        procEnv.SetVariableValue("this", oldThis);
                        if (result)
                        {
                            return(decisionOnMatch);
                        }
                    }
                    else
                    {
                        return(decisionOnMatch);
                    }
                }
                return(SubruleDebuggingDecision.Undefined);
            }

            case SubruleDebuggingEvent.New:
            case SubruleDebuggingEvent.Delete:
            case SubruleDebuggingEvent.Retype:
            case SubruleDebuggingEvent.SetAttributes:
            {
                IGraphElement elem = (IGraphElement)data;
                if (nameToMatch != null)
                {
                    if (procEnv.NamedGraph.GetElementName(elem) == nameToMatch)
                    {
                        if (If(elem, procEnv))
                        {
                            return(decisionOnMatch);
                        }
                    }
                }
                if (typeToMatch != null)
                {
                    if (elem.Type is NodeType && typeToMatch is NodeType && elem.Type.IsA(typeToMatch) ||
                        elem.Type is EdgeType && typeToMatch is EdgeType && elem.Type.IsA(typeToMatch))
                    {
                        if (onlyThisType)
                        {
                            if (typeToMatch.IsA(elem.Type))
                            {
                                if (If(elem, procEnv))
                                {
                                    return(decisionOnMatch);
                                }
                            }
                        }
                        else
                        {
                            if (If(elem, procEnv))
                            {
                                return(decisionOnMatch);
                            }
                        }
                    }
                }
                return(SubruleDebuggingDecision.Undefined);
            }

            default:
                return(SubruleDebuggingDecision.Undefined);
            }
        }
コード例 #8
0
        private SubruleDebuggingConfigurationRule EditOrCreateRule(SubruleDebuggingConfigurationRule cr)
        {
            // edit or keep type
            SubruleDebuggingEvent sde = DetermineEventTypeToConfigure(cr);

            if (sde == SubruleDebuggingEvent.Undefined)
            {
                return(null);
            }

            // for Add, Rem, Emit, Halt, Highlight
            string message = null;
            SubruleMesssageMatchingMode smmm = SubruleMesssageMatchingMode.Undefined;

            // for Match
            IAction action = null;

            // for New, Delete, Retype, SetAttributes
            string    graphElementName = null;
            GrGenType graphElementType = null;
            bool      only             = false;

            if (sde == SubruleDebuggingEvent.Add || sde == SubruleDebuggingEvent.Rem || sde == SubruleDebuggingEvent.Emit ||
                sde == SubruleDebuggingEvent.Halt || sde == SubruleDebuggingEvent.Highlight)
            {
                // edit or keep message matching mode and message
                smmm = DetermineMessageAndMessageMatchingMode(cr,
                                                              out message);
                if (smmm == SubruleMesssageMatchingMode.Undefined)
                {
                    return(null);
                }
            }
            else if (sde == SubruleDebuggingEvent.Match)
            {
                // edit ok keep action name
                action = DetermineAction(cr);
                if (action == null)
                {
                    return(null);
                }
            }
            else if (sde == SubruleDebuggingEvent.New || sde == SubruleDebuggingEvent.Delete ||
                     sde == SubruleDebuggingEvent.Retype || sde == SubruleDebuggingEvent.SetAttributes)
            {
                // edit or keep choice of type, exact type, name
                bool abort = DetermineMatchGraphElementMode(cr,
                                                            out graphElementName, out graphElementType, out only);
                if (abort)
                {
                    return(null);
                }
            }

            // edit or keep decision action
            SubruleDebuggingDecision sdd = DetermineDecisionAction(cr);

            if (sdd == SubruleDebuggingDecision.Undefined)
            {
                return(null);
            }

            // edit or keep condition if type action or graph change
            SequenceExpression ifClause = null;

            if (sde != SubruleDebuggingEvent.Add && sde != SubruleDebuggingEvent.Rem && sde != SubruleDebuggingEvent.Retype &&
                sde != SubruleDebuggingEvent.Halt && sde != SubruleDebuggingEvent.Highlight)
            {
                ifClause = DetermineCondition(cr, sde, action, graphElementType);
            }

            if (sde == SubruleDebuggingEvent.Add || sde == SubruleDebuggingEvent.Rem || sde == SubruleDebuggingEvent.Emit ||
                sde == SubruleDebuggingEvent.Halt || sde == SubruleDebuggingEvent.Highlight)
            {
                return(new SubruleDebuggingConfigurationRule(sde, message, smmm, sdd));
            }
            else if (sde == SubruleDebuggingEvent.Match)
            {
                return(new SubruleDebuggingConfigurationRule(sde, action, sdd, ifClause));
            }
            else if (sde == SubruleDebuggingEvent.New || sde == SubruleDebuggingEvent.Delete ||
                     sde == SubruleDebuggingEvent.Retype || sde == SubruleDebuggingEvent.SetAttributes)
            {
                if (graphElementName != null)
                {
                    return(new SubruleDebuggingConfigurationRule(sde, graphElementName, sdd, ifClause));
                }
                else
                {
                    return(new SubruleDebuggingConfigurationRule(sde, graphElementType, only, sdd, ifClause));
                }
            }

            return(null);
        }
コード例 #9
0
        private SequenceExpression DetermineCondition(SubruleDebuggingConfigurationRule cr,
                                                      SubruleDebuggingEvent sde, IAction action, GrGenType graphElementType)
        {
            // edit or keep condition if type action or graph change
            do
            {
                Console.WriteLine("Conditional rule via sequence expression?");
                if (cr != null && cr.IfClause != null)
                {
                    Console.WriteLine("Press enter to take over " + cr.IfClause.Symbol + ", enter \"-\" to clear the condition, otherwise enter the sequence expression to apply.");
                }
                else
                {
                    Console.WriteLine("Press enter if you don't want to add an if part, otherwise enter the sequence expression to apply.");
                }

                String ifClauseStr = Console.ReadLine();
                if (ifClauseStr.Length == 0)
                {
                    if (cr != null)
                    {
                        return(cr.IfClause);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (ifClauseStr == "-")
                {
                    return(null);
                }

                Dictionary <String, String> predefinedVariables = new Dictionary <String, String>();
                predefinedVariables.Add("this", "");
                string ruleOfMatchThis = null;
                if (sde == SubruleDebuggingEvent.Match)
                {
                    ruleOfMatchThis = action.Name;
                }
                string typeOfGraphElementThis = null;
                if (sde == SubruleDebuggingEvent.New || sde == SubruleDebuggingEvent.Delete ||
                    sde == SubruleDebuggingEvent.Retype || sde == SubruleDebuggingEvent.SetAttributes)
                {
                    typeOfGraphElementThis = "";
                    if (graphElementType != null)
                    {
                        typeOfGraphElementThis = graphElementType.PackagePrefixedName;
                    }
                }
                try
                {
                    SequenceParserEnvironmentInterpretedDebugEventCondition parserEnv = new SequenceParserEnvironmentInterpretedDebugEventCondition(shellProcEnv.ProcEnv.Actions, ruleOfMatchThis, typeOfGraphElementThis);
                    List <String>      warnings = new List <String>();
                    SequenceExpression ifClause = SequenceParser.ParseSequenceExpression(ifClauseStr, predefinedVariables, parserEnv, warnings);
                    foreach (string warning in warnings)
                    {
                        Console.WriteLine("The sequence expression for the if clause reported back: " + warning);
                    }
                    return(ifClause);
                }
                catch (SequenceParserException ex)
                {
                    Console.WriteLine("Unable to parse sequence expression");
                    env.HandleSequenceParserException(ex);
                }
                catch (de.unika.ipd.grGen.libGr.sequenceParser.ParseException ex)
                {
                    Console.WriteLine("Unable to parse sequence expression: " + ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unable to parse sequence expression : " + ex);
                }
            }while(true);
        }
コード例 #10
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
 public string ToString(SubruleDebuggingEvent evt)
 {
     switch(evt)
     {
         case SubruleDebuggingEvent.Add: return "add";
         case SubruleDebuggingEvent.Rem: return "rem";
         case SubruleDebuggingEvent.Emit: return "emit";
         case SubruleDebuggingEvent.Halt: return "halt";
         case SubruleDebuggingEvent.Highlight: return "highlight";
         case SubruleDebuggingEvent.Match: return "match";
         case SubruleDebuggingEvent.New: return "new";
         case SubruleDebuggingEvent.Delete: return "delete";
         case SubruleDebuggingEvent.Retype: return "retype";
         case SubruleDebuggingEvent.SetAttributes: return "set attributes";
         default: return "INTERNAL FAILURE, unknown SubruleDebuggingEvent";
     }
 }
コード例 #11
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
 public SubruleDebuggingDecision Decide(SubruleDebuggingEvent sde, object data, IGraphProcessingEnvironment procEnv, out SubruleDebuggingConfigurationRule cr)
 {
     foreach(SubruleDebuggingConfigurationRule rule in configurationRules)
     {
         SubruleDebuggingDecision result = rule.Decide(sde, data, procEnv);
         if(result != SubruleDebuggingDecision.Undefined)
         {
             cr = rule;
             return result;
         }
     }
     cr = null;
     return SubruleDebuggingDecision.Undefined;
 }
コード例 #12
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
        public SubruleDebuggingDecision Decide(SubruleDebuggingEvent sde, object data, IGraphProcessingEnvironment procEnv)
        {
            if(!enabled)
                return SubruleDebuggingDecision.Undefined;
            if(debuggingEvent != sde)
                return SubruleDebuggingDecision.Undefined;

            switch(sde)
            {
                case SubruleDebuggingEvent.Add:
                case SubruleDebuggingEvent.Rem:
                case SubruleDebuggingEvent.Emit:
                case SubruleDebuggingEvent.Halt:
                case SubruleDebuggingEvent.Highlight:
                    {
                        string message = (string)data;
                        switch(messageMatchingMode)
                        {
                            case SubruleMesssageMatchingMode.Equals:
                                if(message == messageToMatch)
                                    return decisionOnMatch;
                                break;
                            case SubruleMesssageMatchingMode.StartsWith:
                                if(message.StartsWith(messageToMatch))
                                    return decisionOnMatch;
                                break;
                            case SubruleMesssageMatchingMode.EndsWith:
                                if(message.EndsWith(messageToMatch))
                                    return decisionOnMatch;
                                break;
                            case SubruleMesssageMatchingMode.Contains:
                                if(message.Contains(messageToMatch))
                                    return decisionOnMatch;
                                break;
                            default:
                                throw new Exception("INTERNAL FAILURE: unkonwn message matching mode");
                        }
                    }
                    return SubruleDebuggingDecision.Undefined;

                case SubruleDebuggingEvent.Match:
                    {
                        IMatches matches = (IMatches)data;
                        if(matches.Producer == actionToMatch)
                        {
                            if(ifClause != null)
                            {
                                object oldThis = procEnv.GetVariableValue("this");
                                bool result = false;
                                foreach(IMatch match in matches)
                                {
                                    procEnv.SetVariableValue("this", match);
                                    if((bool)ifClause.Evaluate(procEnv))
                                    {
                                        result = true;
                                        break;
                                    }
                                }
                                procEnv.SetVariableValue("this", oldThis);
                                if(result)
                                    return decisionOnMatch;
                            }
                            else
                                return decisionOnMatch;
                        }
                        return SubruleDebuggingDecision.Undefined;
                    }

                case SubruleDebuggingEvent.New:
                case SubruleDebuggingEvent.Delete:
                case SubruleDebuggingEvent.Retype:
                case SubruleDebuggingEvent.SetAttributes:
                    {
                        IGraphElement elem = (IGraphElement)data;
                        if(nameToMatch != null)
                        {
                            if(procEnv.NamedGraph.GetElementName(elem) == nameToMatch)
                            {
                                if(If(elem, procEnv))
                                    return decisionOnMatch;
                            }
                        }
                        if(typeToMatch != null)
                        {
                            if(elem.Type is NodeType && typeToMatch is NodeType && elem.Type.IsA(typeToMatch)
                                || elem.Type is EdgeType && typeToMatch is EdgeType && elem.Type.IsA(typeToMatch))
                            {
                                if(onlyThisType)
                                {
                                    if(typeToMatch.IsA(elem.Type))
                                    {
                                        if(If(elem, procEnv))
                                            return decisionOnMatch;
                                    }
                                }
                                else
                                {
                                    if(If(elem, procEnv))
                                        return decisionOnMatch;
                                }
                            }
                        }
                        return SubruleDebuggingDecision.Undefined;
                    }

                default:
                    return SubruleDebuggingDecision.Undefined;
            }
        }
コード例 #13
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, GrGenType graphElementType,
     bool only, SubruleDebuggingDecision sdd, SequenceExpression ifClause)
 {
     this.debuggingEvent = sde;
     this.typeToMatch = graphElementType;
     this.onlyThisType = only;
     this.decisionOnMatch = sdd;
     this.ifClause = ifClause;
 }
コード例 #14
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, string graphElementName,
     SubruleDebuggingDecision sdd, SequenceExpression ifClause)
 {
     this.debuggingEvent = sde;
     this.nameToMatch = graphElementName;
     this.decisionOnMatch = sdd;
     this.ifClause = ifClause;
 }
コード例 #15
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, IAction action,
     SubruleDebuggingDecision sdd, SequenceExpression ifClause)
 {
     this.debuggingEvent = sde;
     this.actionToMatch = action;
     this.decisionOnMatch = sdd;
     this.ifClause = ifClause;
 }
コード例 #16
0
ファイル: DebuggerHelper.cs プロジェクト: jblomer/GrGen.NET
 public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, string message, 
     SubruleMesssageMatchingMode smmm, SubruleDebuggingDecision sdd)
 {
     this.debuggingEvent = sde;
     this.messageMatchingMode = smmm;
     this.messageToMatch = message;
     this.decisionOnMatch = sdd;
 }