コード例 #1
0
 public override Expression CreateExpressionTree(ResolveContext ec)
 {
     throw new NotImplementedException("ET");
 }
コード例 #2
0
 public override Expression CreateExpressionTree(ResolveContext ec)
 {
     return(base.CreateExpressionTree(ec));
 }
コード例 #3
0
        public void EmitPrologue(EmitContext ec)
        {
            awaiter = ((AsyncTaskStorey)machine_initializer.Storey).AddAwaiter(expr.Type, loc);

            var fe_awaiter = new FieldExpr(awaiter, loc);

            fe_awaiter.InstanceExpression = new CompilerGeneratedThis(ec.CurrentType, loc);

            //
            // awaiter = expr.GetAwaiter ();
            //
            using (ec.With(BuilderContext.Options.OmitDebugInfo, true)) {
                fe_awaiter.EmitAssign(ec, expr, false, false);
            }

            Label skip_continuation = ec.DefineLabel();

            Expression completed_expr;

            if (IsDynamic)
            {
                var rc = new ResolveContext(ec.MemberContext);

                Arguments dargs = new Arguments(1);
                dargs.Add(new Argument(fe_awaiter));
                completed_expr = new DynamicMemberBinder("IsCompleted", dargs, loc).Resolve(rc);

                dargs = new Arguments(1);
                dargs.Add(new Argument(completed_expr));
                completed_expr = new DynamicConversion(ec.Module.Compiler.BuiltinTypes.Bool, 0, dargs, loc).Resolve(rc);
            }
            else
            {
                var pe = PropertyExpr.CreatePredefined(awaiter_definition.IsCompleted, loc);
                pe.InstanceExpression = fe_awaiter;
                completed_expr        = pe;
            }

            completed_expr.EmitBranchable(ec, skip_continuation, true);

            base.DoEmit(ec);

            //
            // The stack has to be empty before calling await continuation. We handle this
            // by lifting values which would be left on stack into class fields. The process
            // is quite complicated and quite hard to test because any expression can possibly
            // leave a value on the stack.
            //
            // Following assert fails when some of expression called before is missing EmitToField
            // or parent expression fails to find await in children expressions
            //
            ec.AssertEmptyStack();

            var storey = (AsyncTaskStorey)machine_initializer.Storey;

            if (IsDynamic)
            {
                storey.EmitAwaitOnCompletedDynamic(ec, fe_awaiter);
            }
            else
            {
                storey.EmitAwaitOnCompleted(ec, fe_awaiter);
            }

            // Return ok
            machine_initializer.EmitLeave(ec, unwind_protect);

            ec.MarkLabel(resume_point);
            ec.MarkLabel(skip_continuation);
        }
コード例 #4
0
 void Error_WrongAwaiterPattern(ResolveContext rc, TypeSpec awaiter)
 {
     rc.Report.Error(4011, loc, "The awaiter type `{0}' must have suitable IsCompleted and GetResult members",
                     awaiter.GetSignatureForError());
 }
コード例 #5
0
 protected override void Error_TypeDoesNotContainDefinition(ResolveContext rc, TypeSpec type, string name)
 {
     Error_OperatorCannotBeApplied(rc, type);
 }