コード例 #1
0
        /// <inheritdoc/>
        public override void GenerateCode(MethodBodyGenerator generator, MethodCompileOption options)
        {
            if (Arguments != null)
            {
                var conversions = ArgumentConversions;
                for (int i = 0; i < Arguments.Count; i++)
                {
                    Arguments[i].GenerateCode(generator);
                    var conversion = conversions[i];
                    if (conversion != null)
                    {
                        generator.EmitConvert(conversion);
                    }
                }
            }
            generator.NewObject(Constructor);

            int length = Expressions.Count;

            if (length > 0)
            {
                var variable = generator.DeclareVariable(Type);
                generator.StoreVariable(variable);
                generator.LoadVariable(variable);
                var conversions = ArrayConversions;
                generator.LoadInt32(length);
                Type type = ElementType;
                generator.NewArray(type);
                for (int i = 0; i < length; i++)
                {
                    generator.Duplicate();
                    generator.LoadInt32(i);
                    var expression = Expressions[i];
                    expression.GenerateCode(generator);
                    if (expression.Type.IsValueType && type.IsValueType == false)
                    {
                        generator.Box(expression.Type);
                    }
                    var convertion = conversions[i];
                    if (convertion != null)
                    {
                        generator.EmitConvert(convertion);
                    }

                    generator.StoreArrayElement(type);
                }
                var m = Type.GetMethod("AddRange", Utils.ReflectionUtils.PublicInstance);
                generator.Call(m);
                generator.LoadVariable(variable);
            }
        }
コード例 #2
0
        public override void GenerateCode(MethodBodyGenerator generator, MethodCompileOption options)
        {
            // Find the result type.
            var resultType = Type;
            var firstType  = Second.Type;
            var secondType = Third.Type;

            First.GenerateCode(generator, MethodCompileOption.Return);
            if (Conversions != null && Conversions.Count > 0)
            {
                generator.EmitConvert(Conversions[0]);
            }
            // Branch if the condition is false.
            var startOfElse = generator.CreateLabel();

            generator.BranchIfFalse(startOfElse);
            Second.GenerateCode(generator, options);
            if (resultType != firstType)
            {
                generator.Call(ExpressionConversion);
            }
            // Branch to the end.
            var end = generator.CreateLabel();

            generator.Branch(end);
            generator.DefineLabelPosition(startOfElse);

            Third.GenerateCode(generator, options);
            if (resultType != secondType)
            {
                generator.Call(ExpressionConversion);
            }
            generator.DefineLabelPosition(end);
        }
コード例 #3
0
 public override void GenerateCode(MethodBodyGenerator generator, MethodCompileOption option)
 {
     if (Left.NodeType == ExpressionType.Identifier)
     {
         var exp    = (NameExpression)Left;
         var binder = exp.Binder;
         // binder is null create new local variable
         if (binder is null)
         {
             exp.Binder = binder = new Binders.VariableBinder(generator.DeclareVariable(Right.Type, exp.Name));
         }
         if ((binder.Attributes & Binders.BindingAttributes.HasThis) != 0)
         {
             generator.LoadArgument(0);
         }
         Right.GenerateCode(generator, Option);
         if (Conversion != null)
         {
             generator.EmitConvert(Conversion);
         }
         binder.GenerateSet(Right, generator, option);
     }
     else if (Left.NodeType == ExpressionType.MemberAccess)
     {
         var exp = (MemberExpression)Left;
         exp.Target.GenerateCode(generator);
         // member assign for dynamic to be Any
         if ((exp.Binder.Attributes & Binders.BindingAttributes.Dynamic) == Binders.BindingAttributes.Dynamic)
         {
             generator.Box(TypeProvider.AnyType);
         }
         Right.GenerateCode(generator, Option);
         if (Conversion != null)
         {
             generator.EmitConvert(Conversion);
         }
         exp.Binder.GenerateSet(Right, generator, option);
     }
     else if (Left.NodeType == ExpressionType.Indexer)
     {
         GenerateIndexer(generator);
     }
 }
コード例 #4
0
 public override void GenerateCode(MethodBodyGenerator generator, MethodCompileOption options)
 {
     if (Method != null)
     {
         var conversions = Conversions;
         Left.GenerateCode(generator, options);
         var first = conversions[0];
         if (first != null)
         {
             generator.EmitConvert(first);
         }
         Right.GenerateCode(generator, options);
         var second = conversions[1];
         if (second != null)
         {
             generator.EmitConvert(second);
         }
         generator.Call(Method);
         return;
     }
     throw new InvalidOperationException("Operator method missing");
 }
コード例 #5
0
        public void GenerateIndexer(MethodBodyGenerator generator)
        {
            var exp         = (IndexExpression)Left;
            var conversions = exp.Conversions;
            var arguments   = exp.Arguments;

            exp.Target.GenerateCode(generator, MethodCompileOption.EmitStartAddress);
            var argLength = arguments.Count;

            for (int index = 0; index < argLength; index++)
            {
                var arg  = arguments[index];
                var conv = conversions[index];
                if (conv != null)
                {
                    if (conv.ConversionType == ConversionType.Normal)
                    {
                        arg.GenerateCode(generator, AssignOption);
                        generator.EmitConvert(conv);
                    }
                    else if (conv.ConversionType == ConversionType.ParamArray)
                    {
                        var args = new Expression[arguments.Count - index];
                        arguments.CopyTo(args, conv.Index);
                        generator.EmitConvert((ParamArrayConversion)conv, args);
                    }
                }
                else
                {
                    arg.GenerateCode(generator, AssignOption);
                }
            }
            Right.GenerateCode(generator, MethodCompileOption.Dupplicate);
            // value convert if any
            generator.EmitConvert(conversions[argLength]);
            generator.Call(exp.Setter);
        }
コード例 #6
0
 public override void GenerateCode(MethodBodyGenerator generator, MethodCompileOption options)
 {
     if (Target.Type.IsValueType)
     {
         options |= MethodCompileOption.EmitStartAddress;
     }
     Target.GenerateCode(generator, options);
     Arguments.ForEach((arg, index) =>
     {
         arg.GenerateCode(generator);
         generator.EmitConvert(Conversions[index]);
     });
     // todo indexer parmas argument convert
     generator.Call(Getter);
 }