Exemplo n.º 1
0
        public void Visit(WhileStatement statement)
        {
            statement.Condition.Accept(this);

            EnsureIdentifierIsDefined(Result);

            while (Result.ToBoolean()) {
                statement.Statement.Accept(this);

                ResetContinueIfPresent(statement.Label);

                if (StopStatementFlow()) {
                    if (breakStatement != null && statement.Label == breakStatement.Label) {
                        breakStatement = null;
                    }

                    return;
                }

                statement.Condition.Accept(this);
            }
        }
Exemplo n.º 2
0
		public void Visit(BreakStatement expression)
		{
			Builder.Append("break;");
		}
Exemplo n.º 3
0
        public void Visit(ForStatement statement)
        {
            if (statement.InitialisationStatement != null)
                statement.InitialisationStatement.Accept(this);

            if (statement.ConditionExpression != null)
                statement.ConditionExpression.Accept(this);
            else
                Result = Global.BooleanClass.New(true);

            EnsureIdentifierIsDefined(Result);

            while (Result.ToBoolean()) {
                statement.Statement.Accept(this);

                ResetContinueIfPresent(statement.Label);

                if (StopStatementFlow()) {
                    if (breakStatement != null && statement.Label == breakStatement.Label) {
                        breakStatement = null;
                    }

                    return;
                }

                // Goes back in the scopes so that the variables are accessible after the statement
                if (statement.IncrementExpression != null)
                    statement.IncrementExpression.Accept(this);

                if (statement.ConditionExpression != null)
                    statement.ConditionExpression.Accept(this);
                else
                    Result = Global.BooleanClass.New(true);

            }
        }
Exemplo n.º 4
0
        public void Visit(SwitchStatement statement)
        {
            CurrentStatement = statement.Expression;

            bool found = false;
            if (statement.CaseClauses != null) {
                foreach (var clause in statement.CaseClauses) {
                    CurrentStatement = clause.Expression;

                    if (found) {
                        // jumping from one case to the next one
                        clause.Statements.Accept(this);
                        if (exit)
                            break;
                    } else {
                        new BinaryExpression(BinaryExpressionType.Equal, (Expression)statement.Expression, clause.Expression).Accept(this);
                        if (Result.ToBoolean()) {
                            clause.Statements.Accept(this);
                            found = true;
                            if (exit)
                                break;
                        }
                    }

                    if (breakStatement != null) {
                        breakStatement = null;
                        break;
                    }
                }
            }

            if (!found && statement.DefaultStatements!= null) {
                statement.DefaultStatements.Accept(this);

                // handle break statements in default case by clearing it
                if (breakStatement != null) {
                    breakStatement = null;
                }
            }
        }
Exemplo n.º 5
0
        public void Visit(ForEachInStatement statement)
        {
            // todo: may be declare own property in the current scope if not a globalDeclaration?
            bool globalDeclaration = true;
            string identifier = String.Empty;

            if (statement.InitialisationStatement is VariableDeclarationStatement) {
                globalDeclaration = ((VariableDeclarationStatement)statement.InitialisationStatement).Global;
                identifier = ((VariableDeclarationStatement)statement.InitialisationStatement).Identifier;
            }
            else if (statement.InitialisationStatement is Identifier) {
                globalDeclaration = true;
                identifier = ((Identifier)statement.InitialisationStatement).Text;
            }
            else {
                throw new NotSupportedException("Only variable declaration are allowed in a for in loop");
            }

            statement.Expression.Accept(this);

            var dictionary = Result as JsDictionaryObject;

            if (Result.Value is IEnumerable) {
                foreach (object value in (IEnumerable)Result.Value) {
                    CurrentScope[identifier] = Global.WrapClr(value);

                    statement.Statement.Accept(this);

                    ResetContinueIfPresent(statement.Label);

                    if (StopStatementFlow()) {
                        if (breakStatement != null && statement.Label == breakStatement.Label) {
                            breakStatement = null;
                        }

                        return;
                    }

                    ResetContinueIfPresent(statement.Label);
                }
            }
            else if (dictionary != null) {
                List<string> keys = new List<string>(dictionary.GetKeys());

                // Uses a for loop as it might be changed by the inner statements
                for (int i = 0; i < keys.Count; i++) {
                    string value = keys[i];

                    CurrentScope[identifier] = Global.StringClass.New(value);

                    statement.Statement.Accept(this);

                    ResetContinueIfPresent(statement.Label);

                    if (StopStatementFlow()) {
                        if (breakStatement != null && statement.Label == breakStatement.Label) {
                            breakStatement = null;
                        }

                        return;
                    }

                    ResetContinueIfPresent(statement.Label);
                }
            }
            else {
                throw new InvalidOperationException("The property can't be enumerated");
            }
        }
Exemplo n.º 6
0
 public void Visit(BreakStatement statement)
 {
     breakStatement = statement;
 }
Exemplo n.º 7
0
        public void Visit(WhileStatement statement)
        {
            JsObject scope = new JsObject();
            EnterScope(scope);
            try
            {
                statement.Condition.Accept(this);

                while (Result.ToBoolean())
                {
                    statement.Statement.Accept(this);

                    ResetContinueIfPresent(statement.Label);

                    if (StopStatementFlow())
                    {
                        if (breakStatement != null && statement.Label == breakStatement.Label)
                        {
                            breakStatement = null;
                        }

                        return;
                    }

                    statement.Condition.Accept(this);
                }
            }
            finally
            {
                ExitScope();
            }
        }
Exemplo n.º 8
0
 void Analyze(BreakStatement Stmt)
 {
     SetCurrentLineAndCharNos(Stmt);
 }
Exemplo n.º 9
0
        public void Visit(DoWhileStatement statement)
        {
            /*JsObject scope = new JsObject();
            EnterScope(scope);
            try {*/
                do {
                    statement.Statement.Accept(this);

                    ResetContinueIfPresent(statement.Label);

                    if (StopStatementFlow()) {
                        if (breakStatement != null && statement.Label == breakStatement.Label) {
                            breakStatement = null;
                        }

                        //ExitScope();
                        return;
                    }

                    statement.Condition.Accept(this);

                    EnsureIdentifierIsDefined(Result);

                } while (Result.ToBoolean());
            /*}
            finally {
                ExitScope();
            }*/
        }