示例#1
0
        public AstNode HoistVariables(VarStatement stmnt)
        {
            Block ret = new InlineBlock();

            foreach (DataPair <string, ExpressionNode> Var in stmnt.Vars)
            {
                Variable ScopeVar = FunctionScope.Define(Var.Key);
                if (ScopeVar == null)
                {
                    stmnt.Error("Double declaration of variable");
                }
                if (Var.Value != null)
                {
                    ret.Statements.Add(new ExpressionStatement
                    {
                        Expression = new AssignmentExpression
                        {
                            Token = TokenType.ASSIGN,
                            Left  = new VariableExpression
                            {
                                Value = Var.Key
                            },
                            Right = Var.Value
                        }
                    });
                }
            }
            return(ret);
        }
示例#2
0
        private void RebuildBody()
        {
            Block newBody = new InlineBlock();

            foreach (Statement s in Body.Statements)
            {
                if (s is VoidStatement)
                {
                    continue;
                }
                if (s is InlineBlock)
                {
                    foreach (Statement t in ((InlineBlock)s).Statements)
                    {
                        newBody.Statements.Add(t);
                    }
                }
                else
                {
                    newBody.Statements.Add(s);
                }
            }
            Body = newBody;
        }