public override void Init(AstContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            foreach (var node in treeNode.ChildNodes)
            {
                if (node.AstNode is AuxiliaryNode)
                {
                    var constants = (node.AstNode as AuxiliaryNode).ChildNodes.OfType <Const>();
                    var variables = (node.AstNode as AuxiliaryNode).ChildNodes.OfType <Variable>();

                    foreach (var constant in constants)
                    {
                        Constants.Add(constant);
                        constant.Parent = this;
                    }

                    foreach (var variable in variables)
                    {
                        Variables.Add(variable);
                        variable.Parent = this;
                    }
                }
                else if (node.AstNode is DefaultProperties)
                {
                    DefaultProperties        = (node.AstNode as DefaultProperties);
                    DefaultProperties.Parent = this;
                }
            }
        }
Example #2
0
        void PrepareConstantBuilders([CanBeNull] ZilModelObject lastObject)
        {
            // builders and values for constants (which may refer to vocabulary,
            // routines, tables, objects, properties, or flags)
            foreach (var constant in Context.ZEnvironment.Constants)
            {
                IOperand value;
                if (constant.Name.StdAtom == StdAtom.LAST_OBJECT && lastObject != null)
                {
                    value = Objects[lastObject.Name];
                }
                else
                {
                    value = CompileConstant(constant.Value);
                }

                if (value == null)
                {
                    Context.HandleError(new CompilerError(
                                            constant,
                                            CompilerMessages.Nonconstant_Initializer_For_0_1_2,
                                            "constant",
                                            constant.Name,
                                            constant.Value.ToStringContext(Context, false)));
                    value = Game.Zero;
                }

                Constants.Add(constant.Name, Game.DefineConstant(constant.Name.Text, value));
            }
        }
Example #3
0
        /// <summary>
        /// Imports the specified module into the sprite.
        /// </summary>
        /// <param name="module">The module to import.</param>
        public void Import(ModuleDeclaration module)
        {
            // Constants
            foreach (ConstDeclaration constant in module.Constants)
            {
                Constants.Add(constant);
            }

            // Variables
            foreach (GlobalVarDeclaration variable in module.Variables)
            {
                Variables.Add(variable);
            }

            // Lists
            foreach (GlobalListDeclaration list in module.Lists)
            {
                Lists.Add(list);
            }

            // Event handlers
            foreach (EventHandler scope in module.EventHandlers)
            {
                EventHandlers.Add(scope);
            }

            // Methods
            foreach (MethodDeclaration method in module.Methods)
            {
                Methods.Add(method);
            }
        }
Example #4
0
 void DefineFlagAlias([NotNull] ZilAtom alias, [NotNull] ZilAtom original)
 {
     if (!Flags.ContainsKey(alias))
     {
         var fb = Flags[original];
         Constants.Add(alias, fb);
     }
 }
Example #5
0
        Action ValidateAction([NotNull] Dictionary <ZilAtom, Action> actions, [NotNull] Syntax line)
        {
            try
            {
                using (DiagnosticContext.Push(line.SourceLine))
                {
                    if (actions.TryGetValue(line.ActionName, out var act) == false)
                    {
                        if (Routines.TryGetValue(line.Action, out var routine) == false)
                        {
                            throw new CompilerError(CompilerMessages.Undefined_0_1, "action routine", line.Action);
                        }

                        IRoutineBuilder preRoutine = null;
                        if (line.Preaction != null &&
                            Routines.TryGetValue(line.Preaction, out preRoutine) == false)
                        {
                            throw new CompilerError(CompilerMessages.Undefined_0_1, "preaction routine", line.Preaction);
                        }

                        var actionName = line.ActionName;
                        int index      = Context.ZEnvironment.NextAction++;

                        if (index >= Context.ZEnvironment.VocabFormat.MaxActionCount)
                        {
                            throw new InterpreterError(
                                      InterpreterMessages.Too_Many_0_Only_1_Allowed_In_This_Vocab_Format,
                                      "actions",
                                      Context.ZEnvironment.VocabFormat.MaxActionCount);
                        }

                        var number   = Game.MakeOperand(index);
                        var constant = Game.DefineConstant(actionName.Text, number);
                        Constants.Add(actionName, constant);
                        if (WantDebugInfo)
                        {
                            Debug.Assert(Game.DebugFile != null);
                            Game.DebugFile.MarkAction(constant, actionName.Text);
                        }

                        act = new Action(index, constant, routine, preRoutine, line.Action, line.Preaction);
                        actions.Add(actionName, act);
                    }
                    else
                    {
                        WarnIfActionRoutineDiffers(line, "action routine", line.Action, act.RoutineName);
                        WarnIfActionRoutineDiffers(line, "preaction routine", line.Preaction, act.PreRoutineName);
                    }

                    return(act);
                }
            }
            catch (ZilError ex)
            {
                Context.HandleError(ex);
                return(null);
            }
        }
Example #6
0
 public Defconst <T> CreateConstant <T>(string name, T value)
 {
     if (Constants.Contains(name))
     {
         throw new System.InvalidOperationException($"Constant '{name}' has already been defined.");
     }
     Constants.Add(name);
     return(new Defconst <T>(name, value));
 }
Example #7
0
 public EParse()
 {
     base.Operations = new OperationList();
     base.Operations.Add(Operators.Plus);
     base.Operations.Add(Operators.Minus);
     base.Operations.Add(Operators.Multiply);
     base.Operations.Add(Operators.Divide);
     base.Operations.Add(Operators.Mod);
     base.Operations.Add(Operators.Pow);
     base.Operations.Add(Operators.Equal);
     base.Operations.Add(Operators.Unequal);
     base.Operations.Add(Operators.Bigger);
     base.Operations.Add(Operators.Smaller);
     base.Operations.Add(Operators.NotBigger);
     base.Operations.Add(Operators.NotSmaller);
     base.Operations.Add(Operators.Factorial);
     base.Operations.Add(Operators.Not);
     base.Operations.Add(iExpr.Exprs.Core.CoreOperations.Lambda);
     base.Operations.Add(iExpr.Exprs.Core.CoreOperations.In);
     base.VariableChecker   = new VariableTokenChecker();
     base.BasicTokenChecker = new BasicTokenChecker();
     base.Constants         = new ConstantList();
     Constants.Add(new ConstantToken("e", new ReadOnlyConcreteValue(System.Math.E)));
     Constants.Add(new ConstantToken("pi", new ReadOnlyConcreteValue(System.Math.PI)));
     Constants.AddFunction(Operators.Abs);
     Constants.AddFunction(Operators.Sin);
     Constants.AddFunction(Operators.Cos);
     Constants.AddFunction(Operators.Tan);
     Constants.AddFunction(Operators.ArcSin);
     Constants.AddFunction(Operators.ArcCos);
     Constants.AddFunction(Operators.ArcTan);
     Constants.AddFunction(Operators.Ceil);
     Constants.AddFunction(Operators.Floor);
     Constants.AddFunction(Operators.Round);
     Constants.AddFunction(Operators.Sign);
     Constants.AddFunction(Operators.Exp);
     Constants.AddFunction(Operators.Ln);
     Constants.AddFunction(Operators.Log);
     Constants.AddFunction(iExpr.Exprs.Core.CoreOperations.Length);
     Constants.AddFunction(iExpr.Exprs.Core.CoreOperations.HasVariable);
     Constants.AddFunction(iExpr.Exprs.Core.CoreOperations.List);
     Constants.AddFunction(iExpr.Exprs.Core.CoreOperations.Set);
     Constants.AddFunction(iExpr.Exprs.Core.CoreOperations.Tuple);
     Constants.AddFunction(iExpr.Exprs.Math.StatsOperations.Maximum);
     Constants.AddFunction(iExpr.Exprs.Math.StatsOperations.Minimum);
     Constants.AddFunction(iExpr.Exprs.Math.StatsOperations.Mean);
     Constants.AddFunction(iExpr.Exprs.Math.StatsOperations.Total);
     Constants.AddFunction(iExpr.Exprs.Math.StatsOperations.Sum);
     Constants.AddFunction(iExpr.Exprs.Math.StatsOperations.Product);
     Constants.AddFunction(iExpr.Exprs.Math.NumberTheoryOperations.Gcd);
     Constants.AddFunction(iExpr.Exprs.Math.NumberTheoryOperations.Lcm);
     Constants.AddFunction(iExpr.Exprs.Math.SetOperations.Cap);
     Constants.AddFunction(iExpr.Exprs.Math.SetOperations.Cup);
     Constants.AddFunction(iExpr.Exprs.Math.SetOperations.Dif);
     base.BuildOpt();
 }
        public override void AddConstant(string name, string value)
        {
            if (Constants.ContainsKey(name))
            {
                return;
            }

            Constants.Add(name, value);
            Header.AddConstant(new ConstantDeclarationSection(name, value));
        }
Example #9
0
 internal void AddAlias(string from, string to)
 {
     if (GetAlias(to) != null || CheckConstant(to) || GetAlias(from) != null || Resolve(from) == null ||
         Variables.ContainsKey(to))
     {
         return;
     }
     Aliases[to] = from;
     Constants.Add(to);
 }
Example #10
0
        public ObjectBuilder Constant(string name, Type type, object value, object source, Action <ConstantBuilder> configure = null)
        {
            var constantBuilder = new ConstantBuilder(Context, name, type, value, source);

            configure?.Invoke(constantBuilder);

            Constants.Add(constantBuilder);

            return(this);
        }
Example #11
0
        private BaseNode ProcessNode(XElement element)
        {
            string name = element.Name.ToString();

            switch (name)
            {
            case "content":
            case "example":
            case "tag":
            case "caption":
            case "type":
            case "name":
            case "keywords":
                return(null);

            case "styles":
                StyleNode = element;
                return(null);

            case "parameter":
                element = XmlCompliantConverter.ParseNameValueToElement(element);
                return(null);
            }
            element = XmlCompliantConverter.ParseNameValueToElement(element);
            var children = new List <BaseNode>();

            foreach (var e in element.Elements())
            {
                var n = ProcessNode(e);
                if (n != null)
                {
                    children.Add(n);
                }
            }
            BaseNode node = BaseNode.GetNode(element);

            if (!string.IsNullOrEmpty(node.Key)) // it's a page
            {
                node.Children = children;
                PageNodes.Add(node);
            }

            if (node.Keywords != null)
            {
                foreach (var s in node.Keywords)
                {
                    if (!Constants.Contains(s))
                    {
                        Constants.Add(s);
                    }
                }
            }

            return(node);
        }
Example #12
0
 void PrepareLongWordTableBuilder([CanBeNull] out ITableBuilder longWordTable)
 {
     if (Context.GetCompilationFlagOption(StdAtom.LONG_WORDS))
     {
         longWordTable = Game.DefineTable("LONG-WORD-TABLE", true);
         Constants.Add(Context.GetStdAtom(StdAtom.LONG_WORD_TABLE), longWordTable);
     }
     else
     {
         longWordTable = null;
     }
 }
Example #13
0
        void DefineFlag([NotNull] ZilAtom flag)
        {
            if (!Flags.ContainsKey(flag))
            {
                // create flag builder
                var fb = Game.DefineFlag(flag.Text);
                Flags.Add(flag, fb);
                UniqueFlags++;

                // create constant
                Constants.Add(flag, fb);
            }
        }
Example #14
0
        void PrepareLateSyntaxTableBuilders()
        {
            // constants and builders for late syntax tables
            foreach (var name in Context.ZEnvironment.VocabFormat.GetLateSyntaxTableNames())
            {
                var tb   = Game.DefineTable(name, true);
                var atom = Context.RootObList[name];
                Constants.Add(atom, tb);

                // this hack lets macros use it as a compile-time value, as long as they don't access its contents
                Context.SetGlobalVal(atom, atom);
            }
        }
Example #15
0
        public int Constant(object value)
        {
            if (value is bool)
            {
                //doing this is faster than storing this as state
                _expressions.Add(new IlBool((bool)value));
                return(_expressions.Count - 1);
            }

            _expressions.Add(new IlRuntimeConstant(value, Constants.Count));
            Constants.Add(value);
            return(_expressions.Count - 1);
        }
Example #16
0
 public static ConstantCache Lookup(EContext context)
 {
     if (!Constants.TryGetValue(context, out var cache))
     {
         lock (Constants)
             if (!Constants.TryGetValue(context, out cache))
             {
                 cache = new ConstantCache(context);
                 Constants.Add(context, cache);
             }
     }
     return(cache);
 }
Example #17
0
        private void SetDataSchema()
        {
            Constants.Add(
                new LDF_Constant("Magic String", "", 0, 8, LDF_Constant.String, "LDF File", "Magic string to identify LDF"));
            Constants.Add(
                new LDF_Constant("Version", "", 9, 6, LDF_Constant.String, "001E07", "LDF version"));
            Constants.Add(
                new LDF_Constant("Date", "", 16, 17, LDF_Constant.String, "01-Jan-1900 00:00", "Recording date and time"));
            Constants.Add(
                new LDF_Constant("Origin", "", 34, 11, LDF_Constant.String, "Petronode", "Producing software"));
            Constants.Add(
                new LDF_Constant("Along Trace Dimension", "", 46, 6, LDF_Constant.String, "TIME#2", "Type of measurement along trace (TIME,DEPT)"));
            Constants.Add(
                new LDF_Constant("Across Trace Dimension", "", 53, 6, LDF_Constant.String, "NODIM1", "Type of measurement scross trace (NODIM,VOLTS,M/S)"));
            Constants.Add(
                new LDF_Constant("Sampling Rate", "ms", 60, 4, LDF_Constant.Float32, "1.0", "Sampling rate in ms"));
            Constants.Add(
                new LDF_Constant("Number of Samples", "", 64, 4, LDF_Constant.Int32, "1000", "Number of samples in each trace"));
            Constants.Add(
                new LDF_Constant("Number of Levels", "", 68, 4, LDF_Constant.Int32, "0", "Number of levels in file"));
            Constants.Add(
                new LDF_Constant("Undefined Float", "", 72, 4, LDF_Constant.Float32, UndefinedFloat.ToString(), "Value to use as undefined float"));
            Constants.Add(
                new LDF_Constant("Undefined Int", "", 76, 4, LDF_Constant.Int32, UndefinedInt.ToString(), "Value to use as undefined int"));
            Constants.Add(
                new LDF_Constant("Mystery 1", "", 80, 4, LDF_Constant.Float32, "0.0", ""));
            Constants.Add(
                new LDF_Constant("Mystery 2", "", 84, 4, LDF_Constant.Float32, "0.0", ""));
            Constants.Add(
                new LDF_Constant("Global Shift", "ms", 88, 4, LDF_Constant.Float32, "0.0", ""));
            Constants.Add(
                new LDF_Constant("Across Header ID", "", 92, 4, LDF_Constant.Int32, "21", "Nobody knows; irrelevant; apparently always 21"));
            Constants.Add(
                new LDF_Constant("Along Label", "", 96, 49, LDF_Constant.String, "Time", "Along-trace label"));
            Constants.Add(
                new LDF_Constant("Along Measurement", "", 146, 49, LDF_Constant.String, "ms", "Along-trace measurement string"));
            Constants.Add(
                new LDF_Constant("Across Label", "", 196, 49, LDF_Constant.String, "Depth", "Across-trace label"));
            Constants.Add(
                new LDF_Constant("Across Measurement", "", 246, 49, LDF_Constant.String, "m", "Across-trace measurement string"));
            Constants.Add(
                new LDF_Constant("Trace Label", "", 296, 49, LDF_Constant.String, "Amplitude", "Trace label"));
            Constants.Add(
                new LDF_Constant("Trace Measurement", "", 346, 49, LDF_Constant.String, "unitless", "Trace measurement string"));
            Constants.Add(
                new LDF_Constant("Code", "", 396, 49, LDF_Constant.String, "Profile", "Survey Code"));

            // Officially unused last part of the LDF header starts from byte 446 (578 bytes)
            // It probably can be used to record part of the EBCDIC header, but currently we record the
            // EBCDIC after the trace info, so the information is placed into the processing history
        }
Example #18
0
        private void NumberOut(StringBuilder sb)
        {
            var str = sb.ToString();

            if (Constants.ContainsKey(str)) //handle existing user identifier
            {
                Output.Add(Constants[str]);
            }
            else //create new identifier
            {
                Constants.Add(str);
                Output.Add(Constants[str]);
            }
        }
Example #19
0
        /// <summary>
        /// Generates a constant.
        /// </summary>
        /// <param name="constObj">The constant object.</param>
        private async Task GenerateConst(GenericTypes.UEConst constObj)
        {
            var name = await NameValidator.MakeUniqueCppName(constObj);

            if (name.Contains("Default__") ||
                name.Contains("PLACEHOLDER-CLASS"))
            {
                return;
            }

            Constants.Add(new Constant {
                Name = name, Value = constObj.GetValue()
            });
        }
Example #20
0
        void DefineProperty([NotNull] ZilAtom prop)
        {
            if (!Properties.ContainsKey(prop))
            {
                // create property builder
                var pb = Game.DefineProperty(prop.Text);
                Properties.Add(prop, pb);

                // create constant
                string propConstName = "P?" + prop.Text;
                var    propAtom      = ZilAtom.Parse(propConstName, Context);
                Constants.Add(propAtom, pb);
            }
        }
Example #21
0
        public override Expression VisitConstant([NotNull] ConstantContext context)
        {
            if (!IsPredefined(context.index()))
            {
                throw new UnsupportedSyntaxException("User-defined constants", context.index().Start);
            }

            var predefinedTypeIndex = int.Parse(context.index().NUMBER().ToString());
            var constantExpression  = PredefinedObjects.GetConstantExpressionOfType(predefinedTypeIndex);

            Constants.Add(constantExpression);

            return(null);
        }
Example #22
0
        /// <summary>
        /// Sets the LAS constant by name, adding a new parameter if necessary
        /// </summary>
        /// <param name="name">Constant name</param>
        /// <param name="unit">Constant unit</param>
        /// <param name="value">Constant value</param>
        /// <param name="value">Description</param>
        public override void SetConstant(string name, string unit, string value, string description)
        {
            foreach (LAS_Constant lc in Constants)
            {
                if (lc.Name != name)
                {
                    continue;
                }
                lc.Value = value;
                return;
            }
            LAS_Constant newP = new LAS_Constant(name, unit, value, description);

            Constants.Add(newP);
        }
Example #23
0
        private bool TryAddAsConstant(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacConstant;

            if (symbol == null)
            {
                return(false);
            }

            Constants.Add(symbolName, symbol);

            NamedValues.Add(symbolName, symbol);

            return(true);
        }
        private void AddConstant(string value)
        {
            if (Constants.Any(e => e.Name.Equals(value)))
            {
                return;
            }

            int index = Constants.Count + 1;

            Constants.Add(new Constant()
            {
                Index = index,
                Name  = value
            }
                          );
        }
        public Constant NewConstant(string text, string name, float value)
        {
            UserContext.Rights.CheckRole(AccountRole.Admin);
            Try.Condition(!Constants.ContainsKey(name), $"Эта константа уже существует: {name}.");
            var c = new Constant
            {
                Description = text,
                Value       = value,
                Name        = name
            };

            Constants.Add(name, c);
            UserContext.Data.Constants.Add(c);
            UserContext.Data.SaveChanges();
            return(c);
        }
Example #26
0
        /// <summary>
        /// Reads properties of "Constant" metadata objects
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="conf"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        private async Task ReadConstantsAsync(DbConnection connection, BracketsFileNode conf, CancellationToken ct)
        {
            var objectGuids = GetMetadataObjectGuids(conf.GetNode(4, 1, 1, 3));

            foreach (var objectGuid in objectGuids)
            {
                var objectInfo = BracketsFileParser.Parse(await GetStringConfigFileDataAsync(connection, objectGuid, ct));

                var obj = ReadMetadataObject <Constant>(objectInfo.GetNode(1, 1, 1, 1), objectGuid);

                var typesNode = objectInfo.GetNode(1, 1, 1, 2);
                obj.Types = ReadTypesInfo(typesNode);

                Constants.Add(obj);
            }
        }
Example #27
0
        private void defineLexem()
        {
            bool f = false;

            switch (currentState)
            {
            case State.Identifier:
                f = searchInTable(Keywords);
                if (!f)
                {
                    f = searchInTable(Identifiers);
                    nextLexem.type = LexemType.Identifier;
                    nextLexem.code = lastId++;
                    Identifiers.Add(currentLexemString.ToString(), nextLexem.code);
                    nextLexem.type = LexemType.Identifier;
                }
                else
                {
                    nextLexem.type = LexemType.Keyword;
                }
                outputLexem();
                break;

            case State.Constant:
                f = searchInTable(Constants);
                if (!f)
                {
                    nextLexem.code = lastConst++;
                    Constants.Add(currentLexemString.ToString(), nextLexem.code);
                }
                nextLexem.type = LexemType.Constant;
                outputLexem();
                break;

            case State.Delimiter:
                f = searchInTable(Delimiters);
                nextLexem.type   = LexemType.Delimiter;
                nextLexem.line   = CurrentLine;
                nextLexem.column = CurrentColumn;
                outputLexem();
                break;

            case State.WhiteSpace:
                break;
            }
        }
Example #28
0
        protected virtual void LoadConstants(TypeInfo typeInfo)
        {
            foreach (var fieldInfo in GetFields(typeInfo))
            {
                if (fieldInfo.IsPublic && TryGetConstant(fieldInfo, out VariableValue constantValue))
                {
                    Constants.Add(fieldInfo.Name, constantValue);
                }
            }

            foreach (var propertyInfo in GetProperties(typeInfo))
            {
                if (propertyInfo.GetGetMethod() is not null && TryGetConstant(propertyInfo, out VariableValue constantValue))
                {
                    Constants.Add(propertyInfo.Name, constantValue);
                }
            }
        }
Example #29
0
        public TheConstant(CsConstantDeclaration pCsConstantDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator)
        {
            Modifiers.AddRange(Helpers.GetModifiers(pCsConstantDeclaration.modifiers));

            foreach (CsConstantDeclarator declarator in pCsConstantDeclaration.declarators)
            {
                Constant v = new Constant {
                    //RealName = declarator.identifier.identifier,
                    //Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
                    Name        = declarator.identifier.identifier,
                    Initializer = pCreator.Parse(declarator.expression),
                    ReturnType  = Helpers.GetType(declarator.entity.type)
                };

                v.Modifiers.AddRange(Modifiers);
                Constants.Add(v);
            }
        }
Example #30
0
        void BuildEarlySyntaxTables()
        {
            var dict = new Dictionary <string, ITableBuilder>();

            // TODO: encapsulate this in the VocabFormat classes
            if (Context.GetGlobalOption(StdAtom.NEW_PARSER_P))
            {
                BuildNewFormatSyntaxTables(dict);
            }
            else
            {
                BuildOldFormatSyntaxTables(dict);
            }

            foreach (var pair in dict)
            {
                Constants.Add(Context.RootObList[pair.Key], pair.Value);
            }
        }