Beispiel #1
0
        public override void SurroundWith(Environment environment)
        {
            base.SurroundWith(environment);
            // FEATURE #1
            var conditionType = Condition.GetExpressionType().ToString();

            if (!string.Equals(conditionType, PrimaryType.BoolType, StringComparison.Ordinal))
            {
                Errors.Add(
                    $"{MetaData.GetErrorHeader()}expected a bool as the \"if\" statement\'s condition, found {conditionType}");
            }
            IfStatementList.SurroundWith(new Environment(Env));
            ElseStatementList.SurroundWith(new Environment(Env));
            // FEATURE #17
            if (Pragma.KeepAll || !(Condition is BoolLiteralExpression boolean))
            {
                return;
            }
            if (boolean.Value)
            {
                ElseStatementList.Statements = new List <Statement>(0);
                Optimized = 1;
            }
            else
            {
                IfStatementList.Statements = new List <Statement>(0);
                Optimized = 2;
            }
        }
Beispiel #2
0
        public override void SurroundWith(Environment environment)
        {
            base.SurroundWith(environment);
            var jmp = new JumpLabelDeclaration(MetaData, "");

            jmp.SurroundWith(Env);
            EndLabel.SurroundWith(Env);
            // FEATURE #16
            var conditionType = Condition.GetExpressionType().ToString();

            if (!string.Equals(conditionType, PrimaryType.BoolType, StringComparison.Ordinal))
            {
                Errors.Add(
                    $"{MetaData.GetErrorHeader()}expected a bool as the \"while\" statement\'s condition, " +
                    $"found {conditionType}");
            }
            OkStatementList.Statements.Add(jmp);
            var bodyEnv = new Environment(Env);

            bodyEnv.Declarations.Add(EndLabel);
            OkStatementList.SurroundWith(bodyEnv);
            // FEATURE #17
            if (Pragma.KeepAll || !(Condition is BoolLiteralExpression boolean) || boolean.Value)
            {
                return;
            }
            OptimizedStatementList = new StatementList(MetaData);
            Optimized = 1;
        }