Beispiel #1
0
        /// <summary>
        /// Processes the all global declarations in program.
        /// This method creates objects (ILGlobal) for global variables,
        /// and adds it the global context
        /// </summary>
        /// <param name="declare">The declare.</param>
        private void ProcessGlobalDeclare(Declare declare)
        {
            TypeEntity type  = new TypeEntity(declare.Type);
            int        index = 0;

            foreach (Variable var in declare)
            {
                new ILGlobal(type, var.Name, this);
                if (declare.GetInitExpression(index++) != null)
                {
                    throw new AnalizeException("Can't initialize global variable", declare);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates the IL code for declaration construction
        /// </summary>
        /// <param name="This">The declaration node.</param>
        void IStatementVisitor.Visit(Declare This)
        {
            TypeEntity type  = new TypeEntity(This.Type);
            int        index = 0;

            foreach (Variable var in This)
            {
                ILLocal    local = new ILLocal(type, var.Name, generator);
                Expression init  = This.GetInitExpression(index++);
                if (init != null)
                {
                    try
                    {
                        local.GenerateStore(generator.ExprEvaluator.Create(init));
                    }
                    catch (AnalizeException e)
                    {
                        throw new AnalizeException(e.Message, This);
                    }
                    IL.Emit(OpCodes.Pop);
                }
            }
        }