Beispiel #1
0
 private bool If(IGraphElement element, IGraphProcessingEnvironment procEnv)
 {
     if (ifClause != null)
     {
         object oldThis = procEnv.GetVariableValue("this");
         procEnv.SetVariableValue("this", element);
         bool result = (bool)ifClause.Evaluate(procEnv);
         procEnv.SetVariableValue("this", oldThis);
         return(result);
     }
     return(true);
 }
Beispiel #2
0
        // sets the variable value, decides whether to update the graph-global or the sequence-lokal variables
        public void SetVariableValue(object value, IGraphProcessingEnvironment procEnv)
        {
            if (Type == "")
            {
                procEnv.SetVariableValue(name, value);
            }
            else
            {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                this.value = value;
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        // sets the variable value, decides whether to update the graph-global or the sequence-lokal variables
        public void SetVariableValue(object value, IGraphProcessingEnvironment procEnv)
        {
            if(Type == "") {
                procEnv.SetVariableValue(name, value);
            } else {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                this.value = value;
            }
        }
Beispiel #5
0
 private bool If(IGraphElement element, IGraphProcessingEnvironment procEnv)
 {
     if(ifClause != null)
     {
         object oldThis = procEnv.GetVariableValue("this");
         procEnv.SetVariableValue("this", element);
         bool result = (bool)ifClause.Evaluate(procEnv);
         procEnv.SetVariableValue("this", oldThis);
         return result;
     }
     return true;
 }
Beispiel #6
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;
            }
        }