IronLua.Compiler.Scope.AllLocals C# (CSharp) Method

AllLocals() public method

public AllLocals ( ) : ParamExpr[]
return ParamExpr[]
        public ParamExpr[] AllLocals()
        {
            var values = variables.Values;
            var array = new ParamExpr[values.Count];
            values.CopyTo(array, 0);
            return array;
        }

Usage Example

Example #1
0
        Expr Visit(Block block)
        {
            var parentScope = scope;

            scope = Scope.CreateChild(parentScope);

            var statementExprs = block.Statements.Select(s => s.Visit(this)).ToList();

            if (block.LastStatement != null)
            {
                statementExprs.Add(block.LastStatement.Visit(this));
            }
            var locals = scope.AllLocals();

            // Don't output blocks if we don't declare any locals and it's a single statement
            var expr = locals.Length == 0 && statementExprs.Count == 1
                           ? statementExprs[0]
                           : Expr.Block(locals, statementExprs);

            scope = parentScope;
            return(expr);
        }