Ejemplo n.º 1
0
        internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
            MSAst.Expression test = ag.TransformAndDynamicConvert(_testExpr, typeof(bool));
            MSAst.Expression ifTrue = ag.TransformAndDynamicConvert(_trueExpr, type);
            MSAst.Expression ifFalse = ag.TransformAndDynamicConvert(_falseExpr, type);

            // Convert both to "type" ... since they are assignable already
            // it is really just a cosmetic cast.
            ifTrue = AstUtils.Convert(ifTrue, type);
            ifFalse = AstUtils.Convert(ifFalse, type);

            return Ast.Condition(test, ifTrue, ifFalse);
        }
Ejemplo n.º 2
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.Expression result;

            if (_else != null) {
                result = ag.Transform(_else);
            } else {
                result = AstUtils.Empty();
            }

            // Now build from the inside out
            int i = _tests.Length;
            while (i-- > 0) {
                IfStatementTest ist = _tests[i];

                result = ag.AddDebugInfoAndVoid(
                    Ast.Condition(
                        ag.TransformAndDynamicConvert(ist.Test, typeof(bool)),
                        ag.TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start), 
                        result
                    ),
                    new SourceSpan(ist.Start, ist.Header)
                );
            }

            return result;
        }
Ejemplo n.º 3
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.MethodCallExpression call;

            if (_locals == null && _globals == null) {
                // exec code
                call = Ast.Call(
                    AstGenerator.GetHelperMethod("UnqualifiedExec"), 
                    AstUtils.CodeContext(), 
                    ag.TransformAsObject(_code)
                );
            } else {
                // exec code in globals [ , locals ]
                // We must have globals now (locals is last and may be absent)
                Debug.Assert(_globals != null);
                call = Ast.Call(
                    AstGenerator.GetHelperMethod("QualifiedExec"), 
                    AstUtils.CodeContext(), 
                    ag.TransformAsObject(_code), 
                    ag.TransformAndDynamicConvert(_globals, typeof(IAttributesCollection)), 
                    ag.TransformOrConstantNull(_locals, typeof(object))
                );
            }

            return ag.AddDebugInfo(call, Span);
        }
Ejemplo n.º 4
0
 internal override MSAst.Expression Transform(AstGenerator ag, MSAst.Expression body) {
     return ag.AddDebugInfoAndVoid(
         AstUtils.If(
             ag.TransformAndDynamicConvert(_test, typeof(bool)),
             body
         ),
         Span
     );
 }
Ejemplo n.º 5
0
 internal override MSAst.Expression Transform(AstGenerator ag) {
     // Only the body is "in the loop" for the purposes of break/continue
     // The "else" clause is outside
     MSAst.LabelTarget breakLabel, continueLabel;
     MSAst.Expression body = ag.TransformLoopBody(_body, out breakLabel, out continueLabel);
     return AstUtils.While(
         ag.AddDebugInfo(
             ag.TransformAndDynamicConvert(_test, typeof(bool)),
             Header
         ),
         body, 
         ag.Transform(_else),
         breakLabel,
         continueLabel
     );
 }
Ejemplo n.º 6
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            // If debugging is off, return empty statement
            if (ag.Optimize) {
                return AstUtils.Empty();
            }

            // Transform into:
            // if (_test) {
            // } else {
            //     RaiseAssertionError(_message);
            // }
            return ag.AddDebugInfoAndVoid(
                AstUtils.Unless(                                 // if
                    ag.TransformAndDynamicConvert(_test, typeof(bool)), // _test
                    Ast.Call(                                           // else branch
                        AstGenerator.GetHelperMethod("RaiseAssertionError"),
                        ag.TransformOrConstantNull(_message, typeof(object))
                    )
                ),
                Span
            );
        }
Ejemplo n.º 7
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            // Only the body is "in the loop" for the purposes of break/continue
            // The "else" clause is outside
            MSAst.LabelTarget breakLabel, continueLabel;

            ConstantExpression constTest = _test as ConstantExpression;
            if (constTest != null && constTest.Value is int) {
                // while 0: / while 1:
                int val = (int)constTest.Value;
                if (val == 0) {
                    // completely optimize the loop away
                    if (_else == null) {
                        return MSAst.Expression.Empty();
                    } else {
                        return ag.Transform(_else);
                    }
                }

                MSAst.Expression test = MSAst.Expression.Constant(true);
                MSAst.Expression res = AstUtils.While(
                    test,
                    ag.TransformLoopBody(_body, SourceLocation.Invalid, out breakLabel, out continueLabel),
                    ag.Transform(_else),
                    breakLabel,
                    continueLabel
                );

                if (_test.Start.Line != _body.Start.Line) {
                    res = ag.AddDebugInfo(res, _test.Span);
                }

                return res;
            }

            return AstUtils.While(
                ag.AddDebugInfo(
                    ag.TransformAndDynamicConvert(_test, typeof(bool)),
                    Header
                ),
                ag.TransformLoopBody(_body, _test.Start, out breakLabel, out continueLabel), 
                ag.Transform(_else),
                breakLabel,
                continueLabel
            );
        }