Ejemplo n.º 1
0
		public ConditionExpression( OpCode operation, Expression left, Expression right )
		{
			_trueStmts = new ArrayList();
			_falseStmts = new ArrayList();

			_operation = operation;
			_left = left;
			_right = right;
		}
Ejemplo n.º 2
0
		public static Expression[] ConvertArgumentReferenceToExpression(ArgumentReference[] args)
		{
			Expression[] expressions = new Expression[args.Length];
			
			for(int i=0; i < args.Length; ++i)
			{
				expressions[i] = args[i].ToExpression();
			}

			return expressions;
		}
Ejemplo n.º 3
0
		public BinaryExpression( OpCode operation, Expression left, Expression right )
		{
			_operation = operation;
			_left = left;
			_right = right;
		}
Ejemplo n.º 4
0
        private void GenerateCall()
        {
            ArgumentReference arg = new ArgumentReference( typeof(object[]) );
            _callmethod = CreateMethod( "Call",
                new ReturnReferenceExpression(typeof(object)), arg );

            // LocalReference localRef = method.CodeBuilder.DeclareLocal( typeof(object) );

            TypeReference[] dereferencedArguments = IndirectReference.WrapIfByRef(_args);
            LocalReference[] localCopies = new LocalReference[_args.Length];
            Expression[] invocationArguments = new Expression[_args.Length];

            // Load arguments from the object array.
            for (int i = 0; i < _args.Length; i++)
            {
                if (_args[i].Type.IsByRef)
                {
                    localCopies[i] = _callmethod.CodeBuilder.DeclareLocal(dereferencedArguments[i].Type);

                    _callmethod.CodeBuilder.AddStatement(new AssignStatement(localCopies[i],
                        new ConvertExpression(dereferencedArguments[i].Type,
                            new LoadRefArrayElementExpression(i, arg))));

                    invocationArguments[i] = localCopies[i].ToAddressOfExpression();
                }
                else
                {
                    invocationArguments[i] = new ConvertExpression(dereferencedArguments[i].Type,
                        new LoadRefArrayElementExpression(i, arg));
                }
            }

            // Invoke the method.
            MethodInvocationExpression methodInv = new MethodInvocationExpression(
                _invokeMethod,
                invocationArguments );

            Expression result = null;
            if (_returnType.Type == typeof(void))
            {
                _callmethod.CodeBuilder.AddStatement(new ExpressionStatement(methodInv));
                result = NullExpression.Instance;
            }
            else
            {
                LocalReference resultLocal = _callmethod.CodeBuilder.DeclareLocal(typeof(object));

                _callmethod.CodeBuilder.AddStatement(new AssignStatement(resultLocal,
                    new ConvertExpression(typeof(object), _returnType.Type, methodInv)));

                result = resultLocal.ToExpression();
            }

            // Save ByRef arguments into the object array.
            for (int i = 0; i < _args.Length; i++)
            {
                if (_args[i].Type.IsByRef)
                {
                    _callmethod.CodeBuilder.AddStatement(new AssignArrayStatement(arg, i,
                        new ConvertExpression(typeof(object), dereferencedArguments[i].Type,
                            localCopies[i].ToExpression())));
                }
            }

            // Return.
            _callmethod.CodeBuilder.AddStatement( new ReturnStatement( result ) );
        }
Ejemplo n.º 5
0
		public ConditionExpression( OpCode operation, Expression left ) : this(operation, left, null)
		{
		}
Ejemplo n.º 6
0
		public ConditionExpression( Expression left ) : this(OpCodes.Brfalse_S, left)
		{
		}
Ejemplo n.º 7
0
        protected virtual MethodInfo GenerateCallbackMethodIfNecessary(MethodInfo method, Reference invocationTarget)
        {
            if (Context.HasMixins && _interface2mixinIndex.Contains(method.DeclaringType))
            {
                return method;
            }

            String name = String.Format("callback__{0}", method.Name);

            ParameterInfo[] parameters = method.GetParameters();

            ArgumentReference[] args = new ArgumentReference[parameters.Length];

            for(int i = 0; i < args.Length; i++)
            {
                args[i] = new ArgumentReference(parameters[i].ParameterType);
            }

            EasyMethod easymethod = MainTypeBuilder.CreateMethod(name,
                                                                 new ReturnReferenceExpression(method.ReturnType),
                                                                 MethodAttributes.HideBySig | MethodAttributes.Public, args);

            Expression[] exps = new Expression[parameters.Length];

            for(int i = 0; i < args.Length; i++)
            {
                exps[i] = args[i].ToExpression();
            }

            if (invocationTarget == null)
            {
                easymethod.CodeBuilder.AddStatement(
                    new ReturnStatement(
                        new MethodInvocationExpression(method, exps)));
            }
            else
            {
                easymethod.CodeBuilder.AddStatement(
                    new ReturnStatement(
                        new MethodInvocationExpression(invocationTarget, method, exps)));
            }

            return easymethod.MethodBuilder;
        }
Ejemplo n.º 8
0
		public AssignArrayStatement( Reference targetArray, int targetPosition, Expression value )
		{
			_targetArray = targetArray;
			_targetPosition = targetPosition;
			_value = value;
		}
Ejemplo n.º 9
0
		public ReturnStatement( Expression expression )
		{
			_expression = expression;
		}
Ejemplo n.º 10
0
		public ConvertExpression( Type targetType, Type fromType, Expression right )
		{
			_target = targetType;
			_fromType = fromType;
			_right = right;
		}
Ejemplo n.º 11
0
		public ConvertExpression( Type targetType, Expression right ) : this(targetType, typeof(object), right)
		{
		}
Ejemplo n.º 12
0
		public AssignStatement( Reference target, Expression expression )
		{
			_target = target;
			_expression = expression;
		}
Ejemplo n.º 13
0
		public ExpressionStatement( Expression expression )
		{
			_expression = expression;
		}