Exemplo n.º 1
0
 public void AddFunction(BlitlineFunction function)
 {
     Functions.Add(function);
 }
Exemplo n.º 2
0
 private void OnAddFunction(ClassNode newProperty)
 {
     Functions.Add(new Property {
         Name = "Function1()"
     });
 }
Exemplo n.º 3
0
 public void AddFunction(FunctionInfo fi)
 {
     Functions.Add(fi);
 }
Exemplo n.º 4
0
        public void Add(object item)
        {
            if (IgnoreDecl)
            {
                return;
            }

            if (item is P_Root.MachineCreates)
            {
                MachineCreates.Add(item as P_Root.MachineCreates);
            }
            else if (item is P_Root.MachineSends)
            {
                MachineSends.Add(item as P_Root.MachineSends);
            }
            else if (item is P_Root.MachineReceives)
            {
                MachineReceives.Add(item as P_Root.MachineReceives);
            }
            else if (item is P_Root.MachineProtoDecl)
            {
                MachineProtoDecls.Add(item as P_Root.MachineProtoDecl);
            }
            else if (item is P_Root.FunProtoDecl)
            {
                FunProtoDecls.Add(item as P_Root.FunProtoDecl);
            }
            else if (item is P_Root.MachineExports)
            {
                MachineExports.Add(item as P_Root.MachineExports);
            }
            else if (item is P_Root.EventSetContains)
            {
                EventSetContains.Add(item as P_Root.EventSetContains);
            }
            else if (item is P_Root.EventSetDecl)
            {
                EventSetDecl.Add(item as P_Root.EventSetDecl);
            }
            else if (item is P_Root.InterfaceTypeDef)
            {
                InterfaceTypeDef.Add(item as P_Root.InterfaceTypeDef);
            }
            else if (item is P_Root.ObservesDecl)
            {
                Observes.Add(item as P_Root.ObservesDecl);
            }
            else if (item is P_Root.Annotation)
            {
                Annotations.Add(item as P_Root.Annotation);
            }
            else if (item is P_Root.DoDecl)
            {
                Dos.Add(item as P_Root.DoDecl);
            }
            else if (item is P_Root.AnonFunDecl)
            {
                AnonFunctions.Add(item as P_Root.AnonFunDecl);
            }
            else if (item is P_Root.FunDecl)
            {
                Functions.Add(item as P_Root.FunDecl);
            }
            else if (item is P_Root.TransDecl)
            {
                Transitions.Add(item as P_Root.TransDecl);
            }
            else if (item is P_Root.VarDecl)
            {
                Variables.Add(item as P_Root.VarDecl);
            }
            else if (item is P_Root.StateDecl)
            {
                States.Add(item as P_Root.StateDecl);
            }
            else if (item is P_Root.MachineDecl)
            {
                Machines.Add(item as P_Root.MachineDecl);
            }
            else if (item is P_Root.EventDecl)
            {
                Events.Add(item as P_Root.EventDecl);
            }
            else if (item is P_Root.ModelType)
            {
                ModelTypes.Add(item as P_Root.ModelType);
            }
            else if (item is P_Root.EnumTypeDef)
            {
                EnumTypeDefs.Add(item as P_Root.EnumTypeDef);
            }
            else if (item is P_Root.TypeDef)
            {
                TypeDefs.Add(item as P_Root.TypeDef);
            }
            else if (item is P_Root.DependsOn)
            {
                DependsOn.Add(item as P_Root.DependsOn);
            }
            else
            {
                throw new Exception("Cannot add into the Program : " + item.ToString());
            }
        }
Exemplo n.º 5
0
        protected QuerySyntax() : base(false)
        {
            SyntaxChars.Add(new Dictionary <int, TokenType>
            {
                { '-', TokenType.Negate },
                { '(', TokenType.LParen },
                { ')', TokenType.RParen },
                { '^', TokenType.Pow },
                { '!', TokenType.LogicalNot },
                { '=', TokenType.Equal },
                { '<', TokenType.LessThan },
                { '>', TokenType.GreaterThan },
                { '~', TokenType.Has },
                { '%', TokenType.Mod },
                { '/', TokenType.Div },
                { '*', TokenType.Mul },
                { '+', TokenType.Add },
                { ',', TokenType.Delimiter },
                { '.', TokenType.IdentifierDelimiter },
                { '@', TokenType.SyntaxEscape }
            });

            Constants.Add(new Dictionary <string, object>
            {
                { "PI", Math.PI },
                { "E", Math.E },
                { "null", null },
                { "true", true },
                { "false", false },
                { "NaN", double.NaN },
                { "INF", double.PositiveInfinity }
            });


            Symbols.Add(new Dictionary <string, TokenType>
            {
                { "-", TokenType.Sub },
                { "like", TokenType.Like },
                { "and", TokenType.LogicalAnd },
                { "or", TokenType.LogicalOr },
                { "==", TokenType.Equal },
                { "!=", TokenType.NotEqual },
                { "<>", TokenType.NotEqual },
                { "<=", TokenType.LessThanOrEqual },
                { ">=", TokenType.GreaterThanOrEqual }
            });

            Functions.Add(new List <FunctionMap>
            {
                new FunctionMap("cast", new CastBuilder()),
                new FunctionMap("isof", new IsofBuilder()),
                new FunctionMap("format", new FormatBuilder()),

                new FunctionMap("contains", MemberTokens.String.Contains),
                new FunctionMap("startswith", MemberTokens.String.StartsWith),
                new FunctionMap("endswith", MemberTokens.String.EndsWith),
                new FunctionMap("concat", MemberTokens.String.Concat),
                new FunctionMap("indexof", MemberTokens.String.IndexOf),
                new FunctionMap("length", MemberTokens.String.Length),
                new FunctionMap("substring", MemberTokens.String.Substring1),
                new FunctionMap("substring", MemberTokens.String.Substring2), // overload
                new FunctionMap("toupper", MemberTokens.String.ToUpper),
                new FunctionMap("tolower", MemberTokens.String.ToLower),
                new FunctionMap("trim", MemberTokens.String.Trim),

                new FunctionMap("floor", MemberTokens.Math.FloorDecimal),
                new FunctionMap("floor", MemberTokens.Math.FloorDouble),
                new FunctionMap("round", MemberTokens.Math.RoundDecimalZeroDigits),
                new FunctionMap("round", MemberTokens.Math.RoundDoubleZeroDigits),
                new FunctionMap("ceiling", MemberTokens.Math.CeilingDecimal),
                new FunctionMap("ceiling", MemberTokens.Math.CeilingDouble),
                new FunctionMap("pow", MemberTokens.Math.Pow),


                new FunctionMap("year", MemberTokens.DateTime.Year),
                new FunctionMap("year", MemberTokens.DateTimeOffset.Year),

                new FunctionMap("month", MemberTokens.DateTime.Month),
                new FunctionMap("month", MemberTokens.DateTimeOffset.Month),

                new FunctionMap("day", MemberTokens.DateTime.Day),
                new FunctionMap("day", MemberTokens.DateTimeOffset.Day),
                new FunctionMap("day", MemberTokens.TimeSpan.Days),

                new FunctionMap("hour", MemberTokens.DateTime.Hour),
                new FunctionMap("hour", MemberTokens.DateTimeOffset.Hour),
                new FunctionMap("hour", MemberTokens.TimeSpan.Hours),

                new FunctionMap("minute", MemberTokens.DateTime.Minute),
                new FunctionMap("minute", MemberTokens.DateTimeOffset.Minute),
                new FunctionMap("minute", MemberTokens.TimeSpan.Minutes),

                new FunctionMap("second", MemberTokens.DateTime.Second),
                new FunctionMap("second", MemberTokens.DateTimeOffset.Second),
                new FunctionMap("second", MemberTokens.TimeSpan.Seconds),

                new FunctionMap("fractionalseconds", MemberTokens.DateTime.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.DateTimeOffset.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.TimeSpan.Milliseconds),

                new FunctionMap("totalfractionalseconds", MemberTokens.TimeSpan.TotalMilliseconds),
                new FunctionMap("totalseconds", MemberTokens.TimeSpan.TotalSeconds),
                new FunctionMap("totalminutes", MemberTokens.TimeSpan.TotalMinutes),
                new FunctionMap("totalhours", MemberTokens.TimeSpan.TotalHours),
                new FunctionMap("totaldays", MemberTokens.TimeSpan.TotalDays),
                new FunctionMap("totaloffsetminutes", new TotalOffsetMinutesBuilder()),

                new FunctionMap("date", MemberTokens.DateTimeOffset.Date),
                new FunctionMap("time", MemberTokens.DateTimeOffset.TimeOfDay),
                new FunctionMap("time", MemberTokens.DateTime.TimeOfDay),
                new FunctionMap("now", MemberTokens.DateTimeOffset.Now),
                new FunctionMap("utcnow", MemberTokens.DateTimeOffset.UtcNow),

                new FunctionMap("mindatetime", MemberTokens.DateTimeOffset.MinValue),
                new FunctionMap("maxdatetime", MemberTokens.DateTimeOffset.MaxValue),


                new FunctionMap("dow", MemberTokens.DateTimeOffset.DayOfWeek),
                new FunctionMap("dow", MemberTokens.DateTime.DayOfWeek)
            });



            KnownTypes.Add(new Dictionary <string, TypeParser>
            {
                { "X", new TypeParser(typeof(byte[]), lex => lex.ParseBinary()) },
                { "string", new TypeParser(typeof(string), lex => lex) },
                { "bool", new TypeParser(typeof(bool), lex => bool.Parse(lex)) },
                { "byte", new TypeParser(typeof(byte), lex => byte.Parse(lex)) },
                { "dt", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "decimal", new TypeParser(typeof(decimal), lex => decimal.Parse(lex)) },
                { "double", new TypeParser(typeof(double), lex => double.Parse(lex)) },
                { "float", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "guid", new TypeParser(typeof(Guid), lex => Guid.Parse(lex)) },
                { "int16", new TypeParser(typeof(Int16), lex => Int16.Parse(lex)) },
                { "int32", new TypeParser(typeof(Int32), lex => int.Parse(lex)) },
                { "int64", new TypeParser(typeof(Int64), lex => long.Parse(lex)) },
                { "sbyte", new TypeParser(typeof(sbyte), lex => sbyte.Parse(lex)) },
                { "ts", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "dto", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) }
            });

            CompleteInitialization();
        }
Exemplo n.º 6
0
 private void OnAddFunction(InterfaceNode newProperty)
 {
     Functions.Add(new Property {
         Name = "Function1()"
     });
 }
Exemplo n.º 7
0
        public Results(string directory, SourceType type)
        {
            Type = type;

            using (var probs = new StreamReader(directory + FileNames.ProbName))
            {
                try
                {
                    TimeTaken = int.Parse(probs.ReadLine());
                }
                catch (ArgumentNullException)
                {
                    TimeTaken = -1;
                }

                while (!probs.EndOfStream)
                {
                    Function function = new Function
                    {
                        Prob = double.Parse(probs.ReadLine())
                    };

                    Functions.Add(function);
                }
            }

            using (var hex = new StreamReader(directory + FileNames.HexName))
            {
                for (int i = 0; !hex.EndOfStream; ++i)
                {
                    foreach (string value in hex.ReadLine().Split(","))
                    {
                        Functions[i].HexCode.Add(value);
                    }
                }
            }

            using (var asm = new StreamReader(directory + FileNames.AsmName))
            {
                for (int i = 0; !asm.EndOfStream; ++i)
                {
                    bool   ignoringComma = false;
                    string temp          = "";

                    foreach (char c in asm.ReadLine())
                    {
                        if (c == '"')
                        {
                            ignoringComma = !ignoringComma;
                        }
                        else
                        {
                            if ((c != ',') || ignoringComma)
                            {
                                temp += c;
                            }
                            else
                            {
                                Functions[i].AsmCode.Add(temp);

                                temp = "";
                            }
                        }
                    }

                    Functions[i].AsmCode.Add(temp);
                }
            }
        }
Exemplo n.º 8
0
 public FileHandleClass(IOperationCodeFactory factory, IValueFactory valueFactory) : base(".file",
                                                                                          SpecialVariables.Global)
 {
     CtorForMembersWithValues.Write(factory.Pop()); // pop self instance used for 'me' variable
     CtorForMembersWithValues.Write(factory.Return());
     Functions.Add("close",
                   new MemberFunction("close", Module, new List <string> {
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.Reference(valueFactory.String(SpecialVariables.Disposable))),
             new Bytecode(factory.Dispose()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("clear",
                   new MemberFunction("clear", Module, new List <string> {
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.FileClear()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("writeln",
                   new MemberFunction("writeln", Module, new List <string> {
         "line"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.FileWrite(true)),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("write",
                   new MemberFunction("write", Module, new List <string> {
         "line"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.FileWrite()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("readln",
                   new MemberFunction("readln", Module, new List <string> {
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.FileRead(true)),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("read",
                   new MemberFunction("read", Module, new List <string> {
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.FileRead()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("is_eof",
                   new MemberFunction("is_eof", Module, new List <string> {
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),     // pops unused argument count
             new Bytecode(factory.FileEOF()),
             new Bytecode(factory.Return())
         }
     });
 }
Exemplo n.º 9
0
 public ListClass(IOperationCodeFactory factory) : base(SpecialVariables.List, SpecialVariables.Global)
 {
     CtorForMembersWithValues.Write(factory.Return());
     Functions.Add("len", new MemberFunction("len", Module, new List <string>(), this)
     {
         Code =
         {
             new Bytecode(factory.Pop()), // pops unused argument count
             new Bytecode(factory.ListLength()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("add", new MemberFunction("add", Module, new List <string> {
         "item"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListAdd()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("remove", new MemberFunction("remove", Module, new List <string> {
         "item"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListRemove()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("remove_at", new MemberFunction("remove_at", Module, new List <string> {
         "index"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListRemoveAt()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("idx_get", new MemberFunction("idx_get", Module, new List <string> {
         "index"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListIndexerGet()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("idx_set", new MemberFunction("idx_set", Module, new List <string> {
         "index", "item"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListIndexerSet()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("clear", new MemberFunction("clear", Module, new List <string>(), this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListClear()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("insert", new MemberFunction("insert", Module, new List <string> {
         "index", "item"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListInsert()),
             new Bytecode(factory.Return())
         }
     });
     Functions.Add("skip", new MemberFunction("skip", Module, new List <string> {
         "count"
     }, this)
     {
         Code =
         {
             new Bytecode(factory.Pop()),
             new Bytecode(factory.ListSkip()),
             new Bytecode(factory.Return())
         }
     });
 }
Exemplo n.º 10
0
 /// <summary>
 /// Adds a function the the class
 /// </summary>
 /// <param name="AccessModifier">Access modifier</param>
 /// <param name="Modifier">Modifier</param>
 /// <param name="Type">Type returned by the function</param>
 /// <param name="Name">Name of the function</param>
 /// <param name="Body">Body of the function</param>
 /// <param name="ParameterList">Parameter list</param>
 public virtual void AddFunction(AccessModifier AccessModifier, Modifiers Modifier, string Type,
                                 string Name, string Body, IParameter[] ParameterList)
 {
     Functions.Add(new Function(AccessModifier, Modifier, Type, Name, ParameterList, Body, Parser));
 }
Exemplo n.º 11
0
        private void FunctionDefinitions()
        {
            foreach (var file in Files.Keys)
            {
                var elements = Files[file];

                for (int i = 0; i < elements.Count; i++)
                {
                    var element = elements[i];

                    if (element.ActualCode.StartsWith("#function"))
                    {
                        var pieces        = element.Pieces;
                        var function_name = pieces[1];

                        Assert.That(!Functions.ContainsKey(function_name), $"In file {file}: Function already exists: {element.Code}");

                        var function_elements = new List <Element>();

                        function_elements.Add(Element.Create(";" + element.Code));
                        function_elements.Add(Element.Create(""));
                        for (int j = 2; j < pieces.Count; j++)
                        {
                            function_elements.Add(Element.Create("#deflocal " + pieces[j]));
                        }
                        function_elements.Add(Element.Create(""));

                        var setup = new StringBuilder();
                        setup.AppendLine("(defrule ; function setup");
                        setup.AppendLine("\t(true)");
                        setup.AppendLine("=>");
                        for (int j = 2; j < pieces.Count; j++)
                        {
                            setup.AppendLine($"\t(up-modify-goal {pieces[j]} g:= glx-param-{(j - 1).ToString().Trim()})");
                        }

                        if (pieces.Count == 2)
                        {
                            setup.AppendLine($"\t(do-nothing)");
                        }
                        setup.Append(")");

                        function_elements.Add(Element.Create(setup.ToString()));

                        elements.RemoveAt(i);

                        while (!elements[i].ActualCode.StartsWith("#return"))
                        {
                            Assert.That(!elements[i].ActualCode.StartsWith("#function"), "Previous function not returned yet: " + elements[i].Code);

                            function_elements.Add(elements[i]);
                            elements.RemoveAt(i);
                        }

                        var goal = elements[i].Pieces[1];

                        function_elements.Add(Element.Create($"(defrule ; return from function\n\t(true)\n=>\n\t(up-modify-goal glx-return-value g:= {goal})\n)"));
                        elements.RemoveAt(i);

                        Functions.Add(function_name, function_elements);

                        Trace.WriteLine("Function: " + function_name);
                    }
                }
            }
        }
Exemplo n.º 12
0
        //TODO : this stuff seems too complex. Make it look simler.
        private void Functions_CollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            var function = (IFunction)e.Item;

            switch (e.Action)
            {
            case NotifyCollectionChangeAction.Add:

                FunctionValues.Add(null);
                /* Get the components of a function. Not of variables */
                if (!(function is IVariable))
                {
                    foreach (IVariable component in function.Components)
                    {
                        if (Functions.Contains(component))
                        {
                            continue;
                        }
                        Functions.Add(component);
                    }
                }

                foreach (IVariable argument in function.Arguments)
                {
                    if (argument.Store != this)
                    {
                        if (Functions.Contains(argument))
                        {
                            continue;
                        }
                        Functions.Add(argument);
                    }
                }

                if (function is IVariable)
                {
                    var variable = (IVariable)function;

                    var variableValues = variable.FixedSize == 0 ? null : variable.Values;

                    // avoid unnecessary calls for better performance
                    var array = (variableValues == null || variableValues.Count == 0)
                            ? variable.CreateStorageArray()
                            : variable.CreateStorageArray(variable.Values);

                    FunctionValues[e.Index] = array;

                    variable.CachedValues = array;

                    SubscribeToArray(array);

                    // register all variables which for the newly added is an argument
                    IEnumerable <IFunction> dependendFunctions =
                        functions.Where(f => f.Arguments.Contains(variable) && f is IVariable);
                    foreach (IVariable dependentVariable in dependendFunctions)
                    {
                        //DependentVariables[variable].Add(dependentVariable);
                        UpdateVariableSize(dependentVariable);
                    }
                }

                function.Store = this;

                break;

            case NotifyCollectionChangeAction.Remove:

                IMultiDimensionalArray multiDimensionalArray = FunctionValues[e.Index];
                UnsubscribeFromArray(multiDimensionalArray);

                FunctionValues.RemoveAt(e.Index);

                //evict the function from the store. Reset arguments and components list to prevent synchronization.

                function.Arguments  = new EventedList <IVariable>();
                function.Components = new EventedList <IVariable>();
                function.Store      = null;

                //IFunctionStore newStore = new MemoryFunctionStore();
                //newStore.Functions.Add(function);
                break;

            case NotifyCollectionChangeAction.Replace:
                throw new NotSupportedException();
            }
            UpdateAutoSortOnArrays();
            UpdateDependentVariables();
        }