コード例 #1
0
ファイル: DoWhile.cs プロジェクト: lulzzz/sito
        public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary <string, VariableDescriptor> variables, CodeContext codeContext, InternalCompilerMessageCallback message, FunctionInfo stats, Options opts)
        {
            expressionDepth = Math.Max(1, expressionDepth);
            Parser.Build(ref body, expressionDepth, variables, codeContext | CodeContext.InLoop, message, stats, opts);
            Parser.Build(ref condition, 2, variables, codeContext | CodeContext.InLoop | CodeContext.InExpression, message, stats, opts);
            try
            {
                if (allowRemove &&
                    (opts & Options.SuppressUselessExpressionsElimination) == 0 &&
                    (condition is Constant || (condition as Expression).ContextIndependent))
                {
                    if ((bool)condition.Evaluate(null))
                    {
                        _this = new InfinityLoop(body, labels);
                    }
                    else if (labels.Length == 0)
                    {
                        _this = body;
                    }
                    condition.Eliminated = true;
                }
            }

#if (PORTABLE)
            catch
            {
コード例 #2
0
ファイル: While.cs プロジェクト: lulzzz/sito
        public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary <string, VariableDescriptor> variables, CodeContext codeContext, InternalCompilerMessageCallback message, FunctionInfo stats, Options opts)
        {
            expressionDepth = Math.Max(1, expressionDepth);
            Parser.Build(ref body, expressionDepth, variables, codeContext | CodeContext.Conditional | CodeContext.InLoop, message, stats, opts);
            Parser.Build(ref condition, 2, variables, codeContext | CodeContext.InLoop | CodeContext.InExpression, message, stats, opts);
            if ((opts & Options.SuppressUselessExpressionsElimination) == 0 && condition is ConvertToBoolean)
            {
                message?.Invoke(MessageLevel.Warning, condition.Position, 2, "Useless conversion. Remove double negation in condition");
                condition = (condition as Expression)._left;
            }
            try
            {
                if (allowRemove && (condition is Constant || (condition is Expression && (condition as Expression).ContextIndependent)))
                {
                    Eliminated = true;
                    if ((bool)condition.Evaluate(null))
                    {
                        if ((opts & Options.SuppressUselessExpressionsElimination) == 0 && body != null)
                        {
                            _this = new InfinityLoop(body, labels);
                        }
                    }
                    else if ((opts & Options.SuppressUselessStatementsElimination) == 0)
                    {
                        _this = null;
                        if (body != null)
                        {
                            body.Eliminated = true;
                        }
                    }
                    condition.Eliminated = true;
                }
                else if ((opts & Options.SuppressUselessExpressionsElimination) == 0 &&
                         ((condition is ObjectDefinition && (condition as ObjectDefinition).FieldNames.Length == 0) ||
                          (condition is ArrayDefinition && (condition as ArrayDefinition).Elements.Length == 0)))
                {
                    _this = new InfinityLoop(body, labels);
                    condition.Eliminated = true;
                }
            }
#if (PORTABLE)
            catch
            {