Beispiel #1
0
                //
                // Creates an invoke call on invocable expression
                //
                public override System.Linq.Expressions.Expression MakeExpression(Compiler.BuilderContext ctx)
                {
                    var invokeBinder = invoke.invokeBinder;
                    var binder       = Binder.Invoke(invokeBinder.flags, invokeBinder.callingContext, invokeBinder.argumentInfo);

                    var args      = invoke.Arguments;
                    var args_expr = new SLE.Expression[invokeBinder.argumentInfo.Count];

                    var types = new Type [args_expr.Length + 2];

                    // Required by MakeDynamic
                    types[0] = typeof(System.Runtime.CompilerServices.CallSite);
                    types[1] = expr.Type.GetMetaInfo();

                    args_expr[0] = expr.MakeExpression(ctx);

                    for (int i = 0; i < args.Count; ++i)
                    {
                        args_expr[i + 1] = args[i].Expr.MakeExpression(ctx);

                        int type_index = i + 2;
                        types[type_index] = args[i].Type.GetMetaInfo();
                        if (args[i].IsByRef)
                        {
                            types[type_index] = types[type_index].MakeByRefType();
                        }
                    }

                    // Return type goes last
                    bool void_result = (invokeBinder.flags & CSharpBinderFlags.ResultDiscarded) != 0;

                    types[types.Length - 1] = void_result ? typeof(void) : invokeBinder.ReturnType;

                    //
                    // Much easier to use Expression.Dynamic cannot be used because it ignores ByRef arguments
                    // and it always generates either Func or Action and any value type argument is lost
                    //
                    Type delegateType = SLE.Expression.GetDelegateType(types);

                    return(SLE.Expression.MakeDynamic(delegateType, binder, args_expr));
                }
Beispiel #2
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return SLE.Expression.Block (expr.MakeExpression (ctx), SLE.Expression.Default (type.GetMetaInfo ()));
 }
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
			return System.Linq.Expressions.Expression.Constant (GetValue ());
		}
Beispiel #4
0
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
#if STATIC
			return base.MakeExpression (ctx);
#else
			return SLE.Expression.Block (expr.MakeExpression (ctx), SLE.Expression.Default (type.GetMetaInfo ()));
#endif
		}
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
			if (typed && obj.Expression.Type != type)
				return System.Linq.Expressions.Expression.Convert (obj.Expression, type);

			return obj.Expression;
		}
Beispiel #6
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return orig_expr.MakeExpression (ctx);
 }
Beispiel #7
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return SLE.Expression.Field (InstanceExpression.MakeExpression (ctx), spec.GetMetaInfo ());
 }
Beispiel #8
0
			internal FlagsHandle (BuilderContext ec, Options mask, Options val)
			{
				this.ec = ec;
				invmask = ~mask;
				oldval = ec.flags & mask;
				ec.flags = (ec.flags & invmask) | (val & mask);
			}
Beispiel #9
0
 public override System.Linq.Expressions.Expression MakeExpression(BuilderContext ctx)
 {
     return(System.Linq.Expressions.Expression.Constant(null));
 }
Beispiel #10
0
        public static System.Linq.Expressions.Expression[] MakeExpression(Arguments args, BuilderContext ctx)
        {
            if (args == null || args.Count == 0)
            {
                return(null);
            }

            var exprs = new System.Linq.Expressions.Expression [args.Count];

            for (int i = 0; i < exprs.Length; ++i)
            {
                Argument a = args.args [i];
                exprs[i] = a.Expr.MakeExpression(ctx);
            }

            return(exprs);
        }
		public static System.Linq.Expressions.Expression[] MakeExpression (Arguments args, BuilderContext ctx)
		{
			if (args == null || args.Count == 0)
				return null;

			// TODO: implement
			if (args.reordered != null)
				throw new NotImplementedException ();

			var exprs = new System.Linq.Expressions.Expression [args.Count];
			for (int i = 0; i < exprs.Length; ++i) {
				Argument a = (Argument) args.args [i];
				exprs[i] = a.Expr.MakeExpression (ctx);
			}

			return exprs;
		}
Beispiel #12
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return(MakeExpression(ctx, mg.InstanceExpression, mg.BestCandidate, arguments));
 }
Beispiel #13
0
        public static System.Linq.Expressions.Expression[] MakeExpression(Arguments args, BuilderContext ctx)
        {
            if (args == null || args.Count == 0)
            {
                return(null);
            }

            // TODO: implement
            if (args.reordered != null)
            {
                throw new NotImplementedException();
            }

            var exprs = new System.Linq.Expressions.Expression [args.Count];

            for (int i = 0; i < exprs.Length; ++i)
            {
                Argument a = (Argument)args.args [i];
                exprs[i] = a.Expr.MakeExpression(ctx);
            }

            return(exprs);
        }
Beispiel #14
0
		public static SLE.Expression MakeExpression (BuilderContext ctx, Expression instance, MethodSpec mi, Arguments args)
		{
			#if STATIC
			throw new NotSupportedException ();
			#else
			var instance_expr = instance == null ? null : instance.MakeExpression (ctx);
			return SLE.Expression.Call (instance_expr, (MethodInfo) mi.GetMetaInfo (), Arguments.MakeExpression (args, ctx));
			#endif
		}
Beispiel #15
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return SLE.Expression.Convert (obj.Expression, type.GetMetaInfo ());
 }
Beispiel #16
0
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
			return System.Linq.Expressions.Expression.Constant (GetTypedValue (), type.GetMetaInfo ());
		}
Beispiel #17
0
 public SLE.Expression MakeAssignExpression(BuilderContext ctx, Expression source)
 {
     return(obj.Expression);
 }
Beispiel #18
0
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
			return MakeExpression (ctx, mg.InstanceExpression, mg.BestCandidate, arguments);
		}
Beispiel #19
0
 public override System.Linq.Expressions.Expression MakeExpression(BuilderContext ctx)
 {
     return(Invocation.MakeExpression(ctx, InstanceExpr, method, arguments));
 }
Beispiel #20
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), (MethodInfo) spec.Get.GetMetaInfo ());
 }
Beispiel #21
0
 public FlagsHandle(BuilderContext ec, Options flagsToSet)
     : this(ec, flagsToSet, flagsToSet)
 {
 }
Beispiel #22
0
 public override SLE.Expression MakeExpression(BuilderContext ctx)
 {
     return ctx.HasSet (BuilderContext.Options.CheckedScope) ?
         SLE.Expression.ConvertChecked (child.MakeExpression (ctx), type.GetMetaInfo ()) :
         SLE.Expression.Convert (child.MakeExpression (ctx), type.GetMetaInfo ());
 }
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
			var le = left.MakeExpression (ctx);
			var re = right.MakeExpression (ctx);
			bool is_checked = ctx.HasSet (BuilderContext.Options.CheckedScope);

			switch (oper) {
			case Operator.Addition:
				return is_checked ? SLE.Expression.AddChecked (le, re) : SLE.Expression.Add (le, re);
			case Operator.BitwiseAnd:
				return SLE.Expression.And (le, re);
			case Operator.BitwiseOr:
				return SLE.Expression.Or (le, re);
			case Operator.Division:
				return SLE.Expression.Divide (le, re);
			case Operator.Equality:
				return SLE.Expression.Equal (le, re);
			case Operator.ExclusiveOr:
				return SLE.Expression.ExclusiveOr (le, re);
			case Operator.GreaterThan:
				return SLE.Expression.GreaterThan (le, re);
			case Operator.GreaterThanOrEqual:
				return SLE.Expression.GreaterThanOrEqual (le, re);
			case Operator.Inequality:
				return SLE.Expression.NotEqual (le, re);
			case Operator.LeftShift:
				return SLE.Expression.LeftShift (le, re);
			case Operator.LessThan:
				return SLE.Expression.LessThan (le, re);
			case Operator.LessThanOrEqual:
				return SLE.Expression.LessThanOrEqual (le, re);
			case Operator.LogicalAnd:
				return SLE.Expression.AndAlso (le, re);
			case Operator.LogicalOr:
				return SLE.Expression.OrElse (le, re);
			case Operator.Modulus:
				return SLE.Expression.Modulo (le, re);
			case Operator.Multiply:
				return is_checked ? SLE.Expression.MultiplyChecked (le, re) : SLE.Expression.Multiply (le, re);
			case Operator.RightShift:
				return SLE.Expression.RightShift (le, re);
			case Operator.Subtraction:
				return is_checked ? SLE.Expression.SubtractChecked (le, re) : SLE.Expression.Subtract (le, re);
			default:
				throw new NotImplementedException (oper.ToString ());
			}
		}
Beispiel #24
0
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
#if STATIC
			return base.MakeExpression (ctx);
#else

				if (type.IsStruct && !obj.Expression.Type.IsValueType)
					return SLE.Expression.Unbox (obj.Expression, type.GetMetaInfo ());

				if (obj.Expression.NodeType == SLE.ExpressionType.Parameter) {
					if (((SLE.ParameterExpression) obj.Expression).IsByRef)
						return obj.Expression;
				}

				return SLE.Expression.Convert (obj.Expression, type.GetMetaInfo ());
#endif
		}
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
			if (arguments.Count != 2)
				throw new NotImplementedException ("arguments.Count != 2");

			var concat = TypeManager.string_type.GetMethod ("Concat", new[] { typeof (object), typeof (object) });
			return SLE.Expression.Add (arguments[0].Expr.MakeExpression (ctx), arguments[1].Expr.MakeExpression (ctx), concat);
		}
Beispiel #26
0
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
			return Invocation.MakeExpression (ctx, InstanceExpr, method, arguments);
		}
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
			return SLE.Expression.Call ((MethodInfo) mg, Arguments.MakeExpression (arguments, ctx));
		}
Beispiel #28
0
		public static System.Linq.Expressions.Expression[] MakeExpression (Arguments args, BuilderContext ctx)
		{
			if (args == null || args.Count == 0)
				return null;

			var exprs = new System.Linq.Expressions.Expression [args.Count];
			for (int i = 0; i < exprs.Length; ++i) {
				Argument a = args.args [i];
				exprs[i] = a.Expr.MakeExpression (ctx);
			}

			return exprs;
		}
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
			using (ctx.With (BuilderContext.Options.AllCheckStateFlags, true)) {
				return Expr.MakeExpression (ctx);
			}
		}
Beispiel #30
0
 public SLE.Expression MakeAssignExpression(BuilderContext ctx)
 {
     return obj.Expression;
 }
		public override SLE.Expression MakeExpression (BuilderContext ctx)
		{
			return SLE.Expression.Convert (source.MakeExpression (ctx), type, method);
		}
Beispiel #32
0
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
			var tassign = target as IDynamicAssign;
			if (tassign == null)
				throw new InternalErrorException (target.GetType () + " does not support dynamic assignment");

			var target_object = tassign.MakeAssignExpression (ctx, source);

			//
			// Some hacking is needed as DLR does not support void type and requires
			// always have object convertible return type to support caching and chaining
			//
			// We do this by introducing an explicit block which returns RHS value when
			// available or null
			//
			if (target_object.NodeType == System.Linq.Expressions.ExpressionType.Block)
				return target_object;

			System.Linq.Expressions.UnaryExpression source_object;
			if (ctx.HasSet (BuilderContext.Options.CheckedScope)) {
				source_object = System.Linq.Expressions.Expression.ConvertChecked (source.MakeExpression (ctx), target_object.Type);
			} else {
				source_object = System.Linq.Expressions.Expression.Convert (source.MakeExpression (ctx), target_object.Type);
			}

			return System.Linq.Expressions.Expression.Assign (target_object, source_object);
		}
Beispiel #33
0
 //
 // Implemented by all expressions which support conversion from
 // compiler expression to invokable runtime expression. Used by
 // dynamic C# binder.
 //
 public virtual SLE.Expression MakeExpression(BuilderContext ctx)
 {
     throw new NotImplementedException ("MakeExpression for " + GetType ());
 }
Beispiel #34
0
			public FlagsHandle (BuilderContext ec, Options flagsToSet)
				: this (ec, flagsToSet, flagsToSet)
			{
			}
Beispiel #35
0
 public SLE.Expression MakeAssignExpression(BuilderContext ctx)
 {
     return MakeExpression (ctx);
 }
Beispiel #36
0
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
#if STATIC
			return base.MakeExpression (ctx);
#else
			return System.Linq.Expressions.Expression.Constant (GetTypedValue (), type.GetMetaInfo ());
#endif
		}
		public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
		{
			var target_object = target.MakeExpression (ctx);
			var source_object = System.Linq.Expressions.Expression.Convert (source.MakeExpression (ctx), target_object.Type);
			return System.Linq.Expressions.Expression.Assign (target_object, source_object);
		}