Exemple #1
0
        public override DataType Eval(Event context)
        {
            switch (name)
            {
            case "freshid":
                int max    = -1;
                var events = context.Root().Descendants();
                foreach (Event e in events)
                {
                    if (e.marking.value != null && e.marking.value.GetType() == typeof(IntType))
                    {
                        max = Math.Max(max, ((IntType)e.marking.value).value);
                    }
                }
                return(new IntType(max + 1));

            case "count":
                var a1 = arguments[0].Eval(context);
                if (!(a1.GetType() == typeof(EventSet)))
                {
                    throw new Exception("Value of not an event set.");
                }
                var arg1 = (EventSet)a1;
                return(new IntType(arg1.value.Count));

            default:
                throw new NotImplementedException(name);
            }

            throw new Exception("bla");
            DataExpression c = null;

            //var c = child.Eval(context);
            if (!(c.GetType() == typeof(EventSet)))
            {
                throw new Exception("Value of not an event set.");
            }
            EventSet s = (EventSet)c;

            if (s.value.Count > 1)
            {
                throw new Exception("Value of multiple events.");
            }

            if (s.value.ElementAt(0).marking.value == null)
            {
                return(new Unit());
            }
            else
            {
                return(s.value.ElementAt(0).marking.value);
            }
        }
Exemple #2
0
        public override DataType Eval(Event context)
        {
            var c = child.Eval(context);

            if (!(c.GetType() == typeof(EventSet)))
            {
                throw new Exception("Value of not an event set.");
            }
            EventSet s = (EventSet)c;

            if (s.value.Count < 1)
            {
                throw new Exception("Value of non-existent event.");
            }

            if (s.value.Count > 1)
            {
                var result = new HashSet <DataType>();
                foreach (Event e in s.value)
                {
                    if (e.marking.value == null)
                    {
                        result.Add(new Unit());
                    }
                    else
                    {
                        result.Add(e.marking.value);
                    }
                }
                return(new DataSet(result));
            }
            else
            {
                if (s.value.ElementAt(0).marking.value == null)
                {
                    return(new Unit());
                }
                else
                {
                    return(s.value.ElementAt(0).marking.value);
                }
            }
        }
Exemple #3
0
        public override DataType Eval(Event context)
        {
            var c = child.Eval(context);

            if (!(c.GetType() == typeof(EventSet)))
            {
                throw new Exception("IsPending of not an event set.");
            }
            EventSet s = (EventSet)c;

            if (s.value.Count > 1)
            {
                throw new Exception("IsPending of multiple events.");
            }

            if (s.value.ElementAt(0).marking == null)
            {
                return(new Unit());
            }
            else
            {
                return(new BoolType(s.value.ElementAt(0).marking.pending));
            }
        }