Beispiel #1
0
        public BlockContext(ResolveContext rc, ExplicitBlock block, TypeSpec returnType)
            : this(rc.MemberContext, block, returnType)
        {
            if (rc.IsUnsafe)
            {
                flags |= ResolveContext.Options.UnsafeScope;
            }

            if (rc.HasSet(ResolveContext.Options.CheckedScope))
            {
                flags |= ResolveContext.Options.CheckedScope;
            }

            if (rc.IsInProbingMode)
            {
                flags |= ResolveContext.Options.ProbingMode;
            }

            if (rc.HasSet(ResolveContext.Options.FieldInitializerScope))
            {
                flags |= ResolveContext.Options.FieldInitializerScope;
            }

            if (rc.HasSet(ResolveContext.Options.ExpressionTreeConversion))
            {
                flags |= ResolveContext.Options.ExpressionTreeConversion;
            }

            if (rc.HasSet(ResolveContext.Options.BaseInitializer))
            {
                flags |= ResolveContext.Options.BaseInitializer;
            }
        }
Beispiel #2
0
        protected override Expression DoResolve(ResolveContext rc)
        {
            if (rc.HasSet(ResolveContext.Options.LockScope))
            {
                rc.Report.Error(1996, loc,
                                "The `await' operator cannot be used in the body of a lock statement");
            }

            if (rc.IsUnsafe)
            {
                rc.Report.Error(4004, loc,
                                "The `await' operator cannot be used in an unsafe context");
            }

            var bc = (BlockContext)rc;

            stmt = new AwaitStatement(expr, loc);
            if (!stmt.Resolve(bc))
            {
                return(null);
            }

            type   = stmt.ResultType;
            eclass = ExprClass.Variable;
            return(this);
        }
        public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args)
        {
            Arguments binder_args = new Arguments(3);

            flags |= ec.HasSet(ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;

            binder_args.Add(new Argument(new BinderFlags(flags, this)));
            binder_args.Add(new Argument(new TypeOf(type, loc)));
            binder_args.Add(new Argument(new TypeOf(ec.CurrentType, loc)));
            return(new Invocation(GetBinder("Convert", loc), binder_args));
        }
        public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args)
        {
            Arguments binder_args = new Arguments(4);

            MemberAccess sle = new MemberAccess(new MemberAccess(
                                                    new QualifiedAliasMember(QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);

            var flags = ec.HasSet(ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;

            binder_args.Add(new Argument(new BinderFlags(flags, this)));
            binder_args.Add(new Argument(new MemberAccess(new MemberAccess(sle, "ExpressionType", loc), name, loc)));
            binder_args.Add(new Argument(new TypeOf(ec.CurrentType, loc)));
            binder_args.Add(new Argument(new ImplicitlyTypedArrayCreation(args.CreateDynamicBinderArguments(ec), loc)));

            return(new Invocation(GetBinder("UnaryOperation", loc), binder_args));
        }
        protected override Expression DoResolve(ResolveContext ec)
        {
            right = right.Resolve(ec);
            if (right == null)
            {
                return(null);
            }

            MemberAccess ma = target as MemberAccess;

            using (ec.Set(ResolveContext.Options.CompoundAssignmentScope)) {
                target = target.Resolve(ec);
            }

            if (target == null)
            {
                return(null);
            }

            if (target is MethodGroupExpr)
            {
                ec.Report.Error(1656, loc,
                                "Cannot assign to `{0}' because it is a `{1}'",
                                ((MethodGroupExpr)target).Name, target.ExprClassName);
                return(null);
            }

            var event_expr = target as EventExpr;

            if (event_expr != null)
            {
                source = Convert.ImplicitConversionRequired(ec, right, target.Type, loc);
                if (source == null)
                {
                    return(null);
                }

                Expression rside;
                if (op == Binary.Operator.Addition)
                {
                    rside = EmptyExpression.EventAddition;
                }
                else if (op == Binary.Operator.Subtraction)
                {
                    rside = EmptyExpression.EventSubtraction;
                }
                else
                {
                    rside = null;
                }

                target = target.ResolveLValue(ec, rside);
                if (target == null)
                {
                    return(null);
                }

                eclass = ExprClass.Value;
                type   = event_expr.Operator.ReturnType;
                return(this);
            }

            //
            // Only now we can decouple the original source/target
            // into a tree, to guarantee that we do not have side
            // effects.
            //
            if (left == null)
            {
                left = new TargetExpression(target);
            }

            source = new Binary(op, left, right, true);

            if (target is DynamicMemberAssignable)
            {
                Arguments targs = ((DynamicMemberAssignable)target).Arguments;
                source = source.Resolve(ec);

                Arguments args = new Arguments(targs.Count + 1);
                args.AddRange(targs);
                args.Add(new Argument(source));

                var binder_flags = CSharpBinderFlags.ValueFromCompoundAssignment;

                //
                // Compound assignment does target conversion using additional method
                // call, set checked context as the binary operation can overflow
                //
                if (ec.HasSet(ResolveContext.Options.CheckedScope))
                {
                    binder_flags |= CSharpBinderFlags.CheckedContext;
                }

                if (target is DynamicMemberBinder)
                {
                    source = new DynamicMemberBinder(ma.Name, binder_flags, args, loc).Resolve(ec);

                    // Handles possible event addition/subtraction
                    if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction)
                    {
                        args = new Arguments(targs.Count + 1);
                        args.AddRange(targs);
                        args.Add(new Argument(right));
                        string method_prefix = op == Binary.Operator.Addition ?
                                               Event.AEventAccessor.AddPrefix : Event.AEventAccessor.RemovePrefix;

                        var invoke = DynamicInvocation.CreateSpecialNameInvoke(
                            new MemberAccess(right, method_prefix + ma.Name, loc), args, loc).Resolve(ec);

                        args = new Arguments(targs.Count);
                        args.AddRange(targs);
                        source = new DynamicEventCompoundAssign(ma.Name, args,
                                                                (ExpressionStatement)source, (ExpressionStatement)invoke, loc).Resolve(ec);
                    }
                }
                else
                {
                    source = new DynamicIndexBinder(binder_flags, args, loc).Resolve(ec);
                }

                return(source);
            }

            return(base.DoResolve(ec));
        }