Example #1
0
 public ILDoWhile(ILCoder coding)
     : base(coding)
 {
     base.BeginLabel = this.Generator.DefineLabel();
     base.EndLabel   = this.Generator.DefineLabel();
     this.Generator.MarkLabel(base.BeginLabel);
 }
Example #2
0
        public void CodingAsDefault()
        {
            if (this._getMethodBuilder == null || this._setMethodBuilder == null)
            {
                throw new BuildException("Varsayılan özellik için öncelikle Get ve Set metotları tanımlanmalı.");
            }

            if (this._getCoder != null || this._setCoder != null)
            {
                throw new BuildException("Get veya Set metodundan herhangi birisinin gövdesi oluşturulmuş. Varsayılan olarak atanamaz.");
            }

            string          defaultFieldName = "<k>__" + this.Name;
            FieldAttributes fieldAttributes  = this.IsStatic ? FieldAttributes.Static | FieldAttributes.Private : FieldAttributes.Private;

            if (this._defaultField == null)
            {
                this._defaultField = this.ILTypeBuilder.DefineField(this.PropertyType, defaultFieldName, fieldAttributes);
            }

            ILCoder getCoding = this.GetGetCoder();
            ILField getField  = this.IsStatic ? getCoding.GetStaticField(defaultFieldName) : getCoding.This.GetField(defaultFieldName);

            getCoding.Return(getField);

            ILCoder setCoding = GetSetCoder();
            ILField setField  = this.IsStatic ? setCoding.GetStaticField(defaultFieldName) : setCoding.This.GetField(defaultFieldName);

            setField.AssignFrom(setCoding.Arg0);
            setCoding.Return();

            this.IsDefaultProperty = true;
        }
Example #3
0
 public ILLazyLoadElement(ILCoder coding, ILVariable array, ILData index)
     : base(coding)
 {
     this._array   = array;
     this._index   = -1;
     this._ilIndex = index;
 }
Example #4
0
 public ILLazyPrimitiveOperator(ILCoder coding, ILData operand, SingleOperators singleOperator)
     : base(coding)
 {
     this._isSingle  = true;
     this._right     = operand;
     this._sOperator = singleOperator;
 }
Example #5
0
        public override ILCoder GetCoder()
        {
            if (this._isBuild)
            {
                throw new CodingException("Metodun tanımlandığı tip derlenmiş. Derlenmiş metotların gövdesi yeniden yazılamaz.");
            }

            if (this._coder == null)
            {
                this.ConstructorBuilder = base.ILTypeBuilder.TypeBuilder.DefineConstructor(this._methodAttributes, this._conventions, this.GetParameterTypes());
                for (int i = 0; i < this._parameters.Count; i++)
                {
                    ILParameterInfo parameter = this._parameters[i];
                    parameter.Builder = this.ConstructorBuilder.DefineParameter(i + 1, parameter.Attributes, parameter.ParameterName);

                    if (parameter.OptionalValue != null)
                    {
                        parameter.Builder.SetConstant(parameter.OptionalValue);
                    }
                }
                return(this._coder = new ILCoder(this, this.ConstructorBuilder.GetILGenerator()));
            }
            else
            {
                return(this._coder);
            }
        }
        public override ILCoder GetCoder()
        {
            if (this._isBuild)
            {
                throw new CodingException("Metot daha önce derlenmiş. Derlenmiş metotların gövdesi yeniden yazılamaz.");
            }

            if (this._coder == null)
            {
                this._isImplemented = true;
                this._dynMethod     = new DynamicMethod(this.Name, this._attributes, this._conventions, this.ReturnType, this.GetParameterTypes(), this.DeclaringType, false);
                for (int i = 0; i < this._parameters.Count; i++)
                {
                    ILParameterInfo parameter = this._parameters[i];
                    parameter.Builder = this.DynamicMethod.DefineParameter(i + 1, parameter.Attributes, parameter.ParameterName);

                    if (parameter.OptionalValue != null)
                    {
                        parameter.Builder.SetConstant(parameter.OptionalValue);
                    }
                }
                return(this._coder = new ILCoder(this, this.DynamicMethod.GetILGenerator()));
            }
            else
            {
                return(this._coder);
            }
        }
Example #7
0
 internal ILLazyPrimitiveComparer(ILCoder coding, ILData left, Comparisons comparer, ILData right)
     : base(coding)
 {
     this._left     = left;
     this._right    = right;
     this._comparer = comparer;
 }
Example #8
0
 public ILTry(ILCoder coding)
 {
     this.Coding                 = coding;
     this.Generator              = coding.Generator;
     this.FinallyLabel           = this.Generator.BeginExceptionBlock();
     this.OuterTryBlock          = this.Coding.CurrentTryBlock;
     this.Coding.CurrentTryBlock = this;
 }
Example #9
0
 public ILLazyPrimitiveOperator(ILCoder coding, ILData left, DoubleOperators doubleOperator, ILData right, Type opResultType)
     : base(coding)
 {
     this._left      = left;
     this._right     = right;
     this._dOperator = doubleOperator;
     this._dOpType   = opResultType;
 }
 internal ILLazyInvoke(ILCoder coding, ILVariable instance, ILMethodBuilder methodBuilder, Type[] genericArgs, ILData[] parameters)
     : base(coding)
 {
     this._instance      = instance;
     this._methodBuilder = methodBuilder;
     this._parameters    = parameters;
     this._genericArgs   = genericArgs;
     this._method        = null;
 }
Example #11
0
        internal ILLocal(ILCoder coding, LocalBuilder local)
            : base(coding)
        {
            if (local == null)
            {
                throw new ArgumentNullException("local");
            }

            this.EmitLocal = local;
        }
Example #12
0
        internal ILForeach(ILCoder coding, ILVariable enumerable)
            : base(coding)
        {
            this._current     = coding.Null.ToLocal();
            this._enumerator  = enumerable.Invoke(ILForeach.getEnumerator, null, null).ToLocal();
            this._currentProp = this._enumerator.GetProperty("Current");
            this._moveNext    = this._enumerator.Invoke(ILForeach.moveNext, null, null);

            this._innerWhile = coding.While(this._moveNext);
            this.Item.AssignFrom(this._currentProp.Get());
        }
Example #13
0
        internal ILArgument(ILCoder coding, Type thisType) //ILThis or ILBase.
            : base(coding)
        {
            if (coding.CurrentMethod.IsStatic)
            {
                throw new InvalidOperationException("This method is not instance.");
            }

            this._argNo   = 0;
            this._argType = thisType;
        }
Example #14
0
        internal ILProperty(ILCoder coding, ILVariable instance, ILPropertyBuilder propertyBuilder)
        {
            this.Coding            = coding;
            this._instance         = instance;
            this._getMethodBuilder = propertyBuilder.GetMethod;
            this._setMethodBuilder = propertyBuilder.SetMethod;
            this.PropertyType      = propertyBuilder.PropertyType;

            this.GetModifier = propertyBuilder.GetMethod == null ? AccessModifiers.Private : propertyBuilder.GetModifier;
            this.SetModifier = propertyBuilder.SetMethod == null ? AccessModifiers.Private : propertyBuilder.SetModifier;
        }
        public ILCodeBlock(ILCoder coding)
        {
            this.Coding         = coding;
            this.Generator      = coding.Generator;
            this._beginLabel    = this.Generator.DefineLabel();
            this._continueLabel = this.Generator.DefineLabel();
            this._endLabel      = this.Generator.DefineLabel();

            this.Generator.Emit(OpCodes.Br_S, this._endLabel);
            this.Generator.MarkLabel(this._beginLabel);
        }
Example #16
0
 internal ILFor(ILCoder coding, ILLocal i, ILLazy comparer, ILLazy operating)
     : base(coding, comparer)
 {
     if (comparer.ILType == typeof(bool))
     {
         this.I         = i;
         this.Comparer  = comparer;
         this._operator = operating;
     }
     else
     {
         throw new InvalidOperationException("Comparer type must be Boolean.");
     }
 }
Example #17
0
        public ILLazyCasting(ILCoder coding, ILData value, CastOperations operations, Type related)
            : base(coding)
        {
            this._op    = operations;
            this._value = value;

            if (operations == CastOperations.Box)
            {
                this._castType = typeof(object);
            }
            else
            {
                this._castType = related;
            }
        }
Example #18
0
        void IBuilder.OnBuild()
        {
            if (this._coder == null)
            {
                throw new BuildException("Soyut veya arabirim olmayan metotlar gövde içermelidir. Kurucu metodun gövdesi tanımlanmamış. Derleme yapılamaz.");
            }

            ((IBuilder)this._coder).OnBuild();
            this._isBuild = true;
            this._coder   = null;
            this._parameters.Clear();
            this._parameters = null;
            this._nameToIndex.Clear();
            this._nameToIndex = null;
            this._parameterTypes.Clear();
            this._parameterTypes = null;
        }
        internal ILIfStatement(ILCoder coding, ILData comparer)
        {
            this.Coding                = coding;
            this.Generator             = coding.Generator;
            this.OuterIfStatement      = this.Coding.CurrentIfBlock;
            this.Coding.CurrentIfBlock = this;
            this._blocks               = new List <Block>();
            this._endIf                = this.Generator.DefineLabel();
            this._localComparerResult  = this.Generator.DeclareLocal(typeof(bool));
            this.Generator.Emit(OpCodes.Ldc_I4_0);
            this.Generator.Emit(OpCodes.Stloc, this._localComparerResult);

            Block thisBlock = this.getNewBlock(comparer);

            ((IILPusher)comparer).Push();
            this.Generator.Emit(OpCodes.Brfalse_S, thisBlock.EndBlock);
            this.Generator.Emit(OpCodes.Ldc_I4_1);
            this.Generator.Emit(OpCodes.Stloc, this._localComparerResult);
        }
Example #20
0
        internal ILWhile(ILCoder coding, ILLazy comparer)
        {
            this.Coding    = coding;
            this.Generator = coding.Generator;
            this.Comparer  = comparer;

            if (comparer.ILType == typeof(bool))
            {
                this.BeginLabel = this.Coding.DefineLabel();
                this.EndLabel   = this.Coding.DefineLabel();

                this.Generator.MarkLabel(this.BeginLabel);
                ((IILPusher)this.Comparer).Push();
                this.Generator.Emit(OpCodes.Brfalse_S, this.EndLabel);
            }
            else
            {
                throw new InvalidOperationException("Comparer type must be Boolean.");
            }
        }
Example #21
0
 public ILCoder GetSetCoder()
 {
     if (this._setCoder == null)
     {
         if (this.IsDefaultProperty)
         {
             throw new BuildException("Varsayılan olarak atanmış özelliklerin gövdesi oluşturulamaz.");
         }
         if (this._setMethodBuilder == null)
         {
             throw new CodingException("Set metodu tanımlanmamış.");
         }
         else
         {
             return(this._setCoder = this._setMethodBuilder.GetCoder());
         }
     }
     else
     {
         return(this._setCoder);
     }
 }
        public override ILCoder GetCoder()
        {
            if (this._isBuild)
            {
                throw new CodingException("Metodun tanımlandığı tip derlenmiş. Derlenmiş metotların gövdesi yeniden yazılamaz.");
            }
            if (this.IsAbstract)
            {
                throw new CodingException("Soyut metotların gövdesi tanımlanamaz.");
            }

            if (this._coder == null)
            {
                this.MethodBuilder.SetParameters(this._parameterTypes.ToArray());
                this.MethodBuilder.SetReturnType(this.ReturnType);
                for (int i = 0; i < this._parameterTypes.Count; i++)
                {
                    ILParameterInfo param = this._parameters[i];
                    if (this.MethodBuilder.IsStatic)
                    {
                        param.Builder = this.MethodBuilder.DefineParameter(i, param.Attributes, param.ParameterName);
                    }
                    else
                    {
                        param.Builder = this.MethodBuilder.DefineParameter(i + 1, param.Attributes, param.ParameterName);
                    }

                    if (param.OptionalValue != null)
                    {
                        param.Builder.SetConstant(param.OptionalValue);
                    }
                }
                this._coder = new ILCoder(this, this.MethodBuilder.GetILGenerator());
            }
            return(this._coder);
        }
Example #23
0
        internal ILArgument(ILCoder coding, int argNo, Type argumentType)
            : base(coding)
        {
            this._parameterInfo = coding.CurrentMethod.GetParameterInfo(argNo);
            this._isByRef       = argumentType.IsByRef;

            if (coding.CurrentMethod.IsStatic)
            {
                this._argNo = argNo;
            }
            else
            {
                this._argNo = argNo + 1;
            }

            if (this._isByRef)
            {
                this._argType = argumentType.GetElementType();
            }
            else
            {
                this._argType = argumentType;
            }
        }
Example #24
0
        internal ILProperty(ILCoder coding, ILVariable instance, PropertyInfo propertyInfo)
        {
            this.Coding       = coding;
            this._instance    = instance;
            this._getMethod   = propertyInfo.GetGetMethod();
            this._setMethod   = propertyInfo.GetSetMethod();
            this.PropertyType = propertyInfo.PropertyType;

            if (this._getMethod != null)
            {
                if ((this._getMethod.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
                {
                    this.GetModifier = AccessModifiers.Public;
                }
                else if (((this._getMethod.Attributes & MethodAttributes.FamANDAssem) == MethodAttributes.FamANDAssem))
                {
                    this.GetModifier = AccessModifiers.Protected;
                }
                else if (((this._getMethod.Attributes & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem))
                {
                    this.GetModifier = AccessModifiers.ProtectedInternal;
                }
                else if (((this._getMethod.Attributes & MethodAttributes.Assembly) == MethodAttributes.Assembly))
                {
                    this.GetModifier = AccessModifiers.Internal;
                }
                else if (((this._getMethod.Attributes & MethodAttributes.Family) == MethodAttributes.Family))
                {
                    this.GetModifier = AccessModifiers.Protected;
                }
                else
                {
                    this.GetModifier = AccessModifiers.Private;
                }
            }

            if (this._setMethod != null)
            {
                if ((this._setMethod.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
                {
                    this.SetModifier = AccessModifiers.Public;
                }
                else if (((this._setMethod.Attributes & MethodAttributes.FamANDAssem) == MethodAttributes.FamANDAssem))
                {
                    this.SetModifier = AccessModifiers.Protected;
                }
                else if (((this._setMethod.Attributes & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem))
                {
                    this.SetModifier = AccessModifiers.ProtectedInternal;
                }
                else if (((this._setMethod.Attributes & MethodAttributes.Assembly) == MethodAttributes.Assembly))
                {
                    this.SetModifier = AccessModifiers.Internal;
                }
                else if (((this._setMethod.Attributes & MethodAttributes.Family) == MethodAttributes.Family))
                {
                    this.SetModifier = AccessModifiers.Protected;
                }
                else
                {
                    this.SetModifier = AccessModifiers.Private;
                }
            }
        }
 internal ILThis(ILCoder coding)
     : base(coding, coding.CurrentMethod.ILTypeBuilder.TypeBuilder)
 {
 }
Example #26
0
 internal ILData(ILCoder coding)
 {
     this.Coding    = coding;
     this.Generator = coding.Generator;
 }
Example #27
0
 public ILConstant(ILCoder coding, bool value)
     : base(coding)
 {
     this._const     = value;
     this._stackType = value.GetType();
 }
Example #28
0
 internal ILConstant(ILCoder coding, Type value)
     : base(coding)
 {
     this._const     = value;
     this._stackType = value.GetType();
 }
 internal ILLazyConstructor(ILCoder coding, ConstructorInfo constructor, ILData[] parameters)
     : base(coding)
 {
     this._constructor = constructor;
     this._parameters  = parameters;
 }
Example #30
0
 internal ILField(ILCoder coding, FieldInfo info, ILVariable instance)
     : base(coding)
 {
     this.FieldInfo = info;
     this._instance = instance;
 }