Ejemplo n.º 1
0
 public CILantroMethodInfo(CILMethod cilMethod, CILProgramInstance programInstance, Type declaringType)
 {
     _cilMethod       = cilMethod;
     _programInstance = programInstance;
     _declaringType   = declaringType;
     Method           = cilMethod;
 }
Ejemplo n.º 2
0
 public VMValue_ftn MakeFtnValue(CILMethod method)
 {
     VMValue_ftn ret = new VMValue_ftn(nextguid, method);
     allValues.Add(nextguid, ret);
     nextguid++;
     return ret;
 }
Ejemplo n.º 3
0
 protected virtual void EmitEventModificationMethodForStronglyReferencedEvents(
     CILField eventField,
     MethodIL il,
     CILMethod modificationMethod
     )
 {
     // Code for modifying events:
     // public void Event<idx>Add/Remove( <event type> evt )
     // {
     //    <event type> current = this.<event field>;
     //    <event type> oldCurrent, combined;
     //    do
     //    {
     //       oldCurrent = current;
     //       combined = (EventHandler<EventArgs>) Delegate.Combine( oldCurrent, evt ); <- or Delegate.Remove in case of removal
     //       current = Interlocked.CompareExchange( ref this.<event field>, combined, oldCurrent );
     //    } while ( !Object.ReferenceEquals( current, oldCurrent ) ); <- replace ReferenceEquals with OpCodes.bne.un.s.
     // }
     il.EmitInterlockedCompareExchangeFieldSettingLoop(
         eventField,
         (il2, oldCurrentB) => il2
         .EmitLoadLocal(oldCurrentB)
         .EmitLoadArg(1)
         .EmitCall(modificationMethod)
         .EmitCastToType(modificationMethod.GetReturnType(), eventField.FieldType)
         )
     .EmitReturn();
 }
Ejemplo n.º 4
0
        private CILMethod MapMethod(CILMethod method)
        {
            return(this._methodCache.GetOrAdd(method, methodArg =>
            {
                var gArgsCount = method.GenericArguments.Count;
                var gArgs = gArgsCount > 0 && !method.IsGenericDefinition() ? method.GenericArguments : null;
                var methodToUse = methodArg;
                if (gArgs != null)
                {
                    methodToUse = methodToUse.GenericDefinition;
                }
                var mapped = this.MapType(methodArg.DeclaringType);
                var result = mapped.Equals(methodToUse.DeclaringType) ?
                             methodToUse :
                             mapped.DeclaredMethods.FirstOrDefault(
                    m => String.Equals(m.Name, methodToUse.Name) &&
                    m.GenericArguments.Count == gArgsCount &&
                    MatchParameterTypes(methodToUse.ReturnParameter.ParameterType, m.ReturnParameter.ParameterType) &&
                    this.MatchMethodAttrsAndParameters(methodToUse, m));

                if (result == null)
                {
                    throw new InvalidOperationException("Failed to map method " + methodToUse + " of declaring type " + methodToUse.DeclaringType + ".");
                }

                if (gArgs != null)
                {
                    result = result.MakeGenericMethod(gArgs.Select(gArg => this.MapTypeBase(gArg)).ToArray());
                }

                return result;
            }));
        }
Ejemplo n.º 5
0
 private void EmitWithMethod(OpCode code, CILMethod method, Boolean useGDefIfPossible)
 {
     ArgumentValidator.ValidateNotNull("Method", method);
     this.BeforeEmittingOpCode();
     this.EmitOpCode(code);
     this.UpdateStackSize(code, method, null);
     this.AddInt32(this._metaData.GetTokenFor(method, useGDefIfPossible && code.OperandType == OperandType.InlineTok));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new <see cref="OpCodeInfoForNormalOrVirtual"/> with specified values.
        /// </summary>
        /// <param name="method">The <see cref="CILMethod"/> to use as operand.</param>
        /// <param name="normal">The <see cref="OpCode"/> to emit when the method will not be virtual.</param>
        /// <param name="aVirtual">The <see cref="OpCode"/> to emit when the method will be virtual.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
        public OpCodeInfoForNormalOrVirtual(CILMethod method, OpCode normal, OpCode aVirtual)
        {
            ArgumentValidator.ValidateNotNull("Method", method);

            this._method  = method;
            this._normal  = normal;
            this._virtual = aVirtual;
            this._minSize = Math.Min(normal.Size, aVirtual.Size) + OpCodeInfoWithFixedSizeOperand.TOKEN_SIZE;
            this._maxSize = Math.Max(normal.Size, aVirtual.Size) + OpCodeInfoWithFixedSizeOperand.TOKEN_SIZE;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds the method defiend by its CECIL (Mono.Cecil) representation.
        /// </summary>
        /// <param name="methodPath">The method path.</param>
        /// <param name="sourceMethod">The source method.</param>
        /// <param name="description">The description of method signature.</param>
        /// <returns>TestingAssembly.</returns>
        public TestingAssembly AddMethod(string methodPath, MethodDefinition sourceMethod, MethodDescription description)
        {
            var methodInfo = buildDescription(description, methodPath);

            var source = new CILMethod(sourceMethod, methodInfo);
            var method = new CILGenerator(methodInfo, source, TypeServices);

            addMethod(method, methodInfo, description.Implemented);

            return(this);
        }
Ejemplo n.º 8
0
        protected override void generate(EmitterBase emitter)
        {
            if (_method == null)
            {
                //nothing to emit
                return;
            }

            var method = new CILMethod(_method, _info);

            Compiler.GenerateInstructions(method, _info, emitter, _services);
        }
Ejemplo n.º 9
0
 public VMLocalVariableBlock(ThreadState threadState, CILMethod method)
 {
     this.threadState = threadState;
     IEnumerator iter = method.GetLocalVariableEnumerator();
     while(iter.MoveNext())
     {
         CILVariable variable = (CILVariable)iter.Current;
         VMValue v = threadState.SystemState.Values.MakeValue(variable);
         v.IsThreadLocal = true;
         v.IsConcrete = true;
         variables.Add(v.GUID);
     }
 }
Ejemplo n.º 10
0
        public override CILClass BuildNode(ParseTreeNode node)
        {
            CILMethod cilMethod = null;

            var classDeclarationsNode = node.GetChildClassDeclarationsNode();
            var classDeclarationNode  = classDeclarationsNode.GetChildClassDeclarationNode();

            cilMethod = _methodBuilder.BuildNode(classDeclarationNode);

            return(new CILClass
            {
                Method = cilMethod
            });
        }
Ejemplo n.º 11
0
        public CILGenerator(TypeMethodInfo info, CILMethod source, TypeServices services)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            Source    = source;
            Info      = info;
            _services = services;
        }
Ejemplo n.º 12
0
 protected virtual void EmitEventInvocationWithTryCatchIfNeeded(
     EventInvocation invocationStyle,
     Type exceptionType,
     CompositeMethodGenerationInfo invokeMethod,
     CILMethod eventMethodToInvoke,
     Action <MethodIL> loadEventAction,
     Boolean storeResult
     )
 {
     invokeMethod.IL.EmitTryCatch(
         EXCEPTION_TYPE,
         il2 =>
     {
         loadEventAction(il2);
         for (Int32 idx = 0; idx < invokeMethod.Parameters.Count; ++idx)
         {
             il2.EmitLoadArg(invokeMethod.Parameters[idx].Position + 1);
         }
         il2.EmitCall(eventMethodToInvoke);
         if (storeResult && !VOID_TYPE.Equals(eventMethodToInvoke.GetReturnType()))
         {
             var resultB = invokeMethod.GetOrCreateLocal(LB_RESULT, invokeMethod.ReturnType);
             il2.EmitStoreLocal(resultB);
         }
     },
         EventInvocation.INVOKE_DIRECTLY.Equals(invocationStyle) ? (Action <MethodIL>)null : il2 =>
     {
         if (exceptionType != null)
         {
             this.EmitStoreExceptionListWithinCatch(invokeMethod);
         }
         else
         {
             throw new InternalException("Non-direct event invocation style, but no exception type specified.");
         }
     },
         false
         );
 }
        protected virtual void EmitPropertyExchangeMethod(
            PropertyModel propertyModel,
            CompositeTypeGenerationInfo thisGenerationInfo,
            CILField propertyField,
            CILTypeBase fieldType,
            CILTypeBase propertyType,
            CILMethod propertySetter,
            CompositeMethodGenerationInfo methodGenInfo,
            Action <CILField, MethodIL> exchangeAction
            )
        {
            var il = methodGenInfo.IL;

            this.EmitThrowIfApplicationNotActiveWithoutLocalVariable(thisGenerationInfo, il);

            this.EmitCheckPropertyImmutability(propertyModel, thisGenerationInfo, il);

            exchangeAction(propertyField, il);
            il
            .EmitCastToType(fieldType, propertyType)
            .EmitReturn();
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Checks whether method is generic method definition.
 /// </summary>
 /// <param name="method">Method to check.</param>
 /// <returns><c>true</c> if <paramref name="method"/> is non-<c>null</c> and generic method definition; <c>false</c> otherwise.</returns>
 /// <seealso cref="System.Reflection.MethodBase.IsGenericMethodDefinition"/>
 public static Boolean IsGenericMethodDefinition(this CILMethod method)
 {
     return(method != null && Object.ReferenceEquals(method, method.GenericDefinition));
 }
Ejemplo n.º 15
0
 public ReturnAddress(CILMethod theMethod, CILInstruction thePC)
 {
     this.theMethod = theMethod;
     this.thePC = thePC;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Performs initialization of data structure for a newly created thread
        /// It sets up the environment for the first method that runs the thread
        /// </summary>
        /// <param name="threadID">Thread id, which is the guid of the thread object</param>
        /// <param name="startingObject">The object from which the thread is started</param>
        /// <param name="startingMethod">The thread function</param>
        private void InitializeThread(int threadID, VMValue_object startingObject, CILMethod startingMethod)
        {
            this.threadID = threadID;
            currentMethod = startingMethod;
            syncState = SyncState.RUNNING;

            localVariableBlocks.Push(new VMLocalVariableBlock(this, startingMethod));
            if(startingObject != null)
                localVariableBlocks.Peek().AddArgumentFront(startingObject);
            pc = currentMethod.GetFirstInstruction();
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Returns a method representing the constructed method based on this generic method definition.
 /// </summary>
 /// <param name="method">The method </param>
 /// <param name="args">The types to substitute the type parameters of this generic method definition.</param>
 /// <returns>A method representing the constructed method based on this generic method definition.</returns>
 /// <exception cref="InvalidOperationException">The <paramref name="args"/> are non-<c>null</c> or contain at least one element, and the <paramref name="method"/> is not generic method definition, that is, <see cref="E_CIL.IsGenericMethodDefinition" /> returns <c>false</c> for <paramref name="method"/>.</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.-or-<paramref name="args" /> is <c>null</c>.-or- Any element of <paramref name="args" /> is <c>null</c>. </exception>
 /// <exception cref="ArgumentException">The number of elements in <paramref name="args" /> is not the same as the number of type parameters of the current generic method definition.</exception>
 public static CILMethod MakeGenericMethod(this CILMethod method, params CILTypeBase[] args)
 {
     ArgumentValidator.ValidateNotNull("Method", method);
     return(((CILReflectionContextImpl)method.ReflectionContext).Cache.MakeGenericMethod(method, method.GenericDefinition, args));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates a new instance of <see cref="OpCodeInfoWithMethodToken"/> with specified values.
 /// </summary>
 /// <param name="opCode">The <see cref="OpCode"/> to emit.</param>
 /// <param name="method">The <see cref="CILMethod"/> to use as operand.</param>
 /// <param name="useGDefIfPossible">
 /// If this is <c>true</c>, and the declaring type of <paramref name="method"/> is generic type definition, and the declaring type of method containing this IL is declaring type of <paramref name="method"/>, then a TypeDef-token will be used instead of TypeSpec when emitting declaring type of the method.
 /// The default behaviour in such scenario is to emit TypeSpec token.
 /// </param>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
 public OpCodeInfoWithMethodToken(OpCode opCode, CILMethod method, Boolean useGDefIfPossible = false)
     : base(opCode, useGDefIfPossible)
 {
     ArgumentValidator.ValidateNotNull("Method", method);
     this._method = method;
 }
Ejemplo n.º 19
0
        public override CILInstructionInstance Execute(CILInstructionInstance instructionInstance, CILProgramState state, CILProgramInstance programInstance, Stack <CILInstructionInstance> callStack)
        {
            var reflectedType   = TypeSpecification.GetTypeSpecified(programInstance);
            var reflectedMethod = (MethodBase)reflectedType.GetMethod(MethodName, GetMethodArgumentRuntimeTypes(programInstance).ToArray());

            if (reflectedMethod == null && MethodName.Equals(".ctor") && ParentMethod.IsConstructor)
            {
                return(instructionInstance.GetNextInstructionInstance());
            }

            var methodArguments = new List <object>();

            for (int i = 0; i < MethodArgumentTypes.Count; i++)
            {
                var argumentType = GetMethodArgumentRuntimeTypes(programInstance)[MethodArgumentTypes.Count - i - 1];

                var argument       = state.Stack.Pop();
                var methodArgument = ConvertHelper.ConvertIfPossible(argument, argumentType);
                methodArguments.Add(methodArgument);
            }
            methodArguments.Reverse();



            object methodObject = null;

            if (CallConvention.Instance)
            {
                methodObject = state.Stack.Pop();

                if (methodObject is Guid)
                {
                    var objectAddress = (Guid)methodObject;
                    methodObject = ParentMethod.GetLocalByAddress(objectAddress);
                }
            }

            var methodObjectToCall = methodObject;

            if (methodObjectToCall is CILClassInstance)
            {
                methodObjectToCall = (methodObjectToCall as CILClassInstance).BaseInstance;
            }

            if (methodObject is CILClassInstance)
            {
                var cilClass  = (methodObject as CILClassInstance)._cilClass;
                var cilMethod = cilClass.Methods.SingleOrDefault(m => m.MethodName == this.MethodName && CILantroType.CompareArgumentTypes(m.ArgumentTypes.Select(at => at.GetRuntimeType(programInstance)).ToArray(), this.GetMethodArgumentRuntimeTypes(programInstance).ToArray()));
                while (cilClass != null && cilMethod == null)
                {
                    cilClass = cilClass.ExtendsClass;
                    if (cilClass != null)
                    {
                        cilMethod = cilClass.Methods.SingleOrDefault(m => m.MethodName == this.MethodName && CILantroType.CompareArgumentTypes(m.ArgumentTypes.Select(at => at.GetRuntimeType(programInstance)).ToArray(), this.GetMethodArgumentRuntimeTypes(programInstance).ToArray()));
                    }
                }

                if (cilMethod != null)
                {
                    var newMethodInfo = new CILantroMethodInfo(cilMethod, programInstance, cilMethod.ReturnType.GetRuntimeType(programInstance));
                    reflectedMethod = newMethodInfo;
                }
            }

            if (reflectedMethod is CILantroMethodInfo)
            {
                callStack.Push(instructionInstance.GetNextInstructionInstance());

                var       cilantroMethodInfo = reflectedMethod as CILantroMethodInfo;
                CILMethod methodToCall       = null;

                object obj = methodObject;
                //object obj = null;
                if (CallConvention.Instance)
                {
                    //obj = state.Stack.Pop();
                    var cilClassInstance = obj as CILClassInstance;
                    var cilClass         = cilClassInstance._cilClass;

                    while (cilClass != null)
                    {
                        var matchingMethod = cilClass.Methods.FirstOrDefault(m => m.MethodName.Equals(MethodName) && CILantroType.CompareArgumentTypes(GetMethodArgumentRuntimeTypes(programInstance).ToArray(), m.ArgumentTypes.Select(ct => ct.GetRuntimeType(programInstance)).ToArray()));
                        if (matchingMethod != null)
                        {
                            methodToCall = matchingMethod;
                            break;
                        }

                        cilClass = programInstance.Program.Classes.FirstOrDefault(c => c.ClassName.UniqueName == cilClass.Extends.UniqueName);
                    }
                }

                if (methodToCall == null)
                {
                    methodToCall = cilantroMethodInfo.Method;
                }

                return(methodToCall.CreateInstance(obj, methodArguments.ToArray()).GetFirstInstructionInstance());
            }

            var methodResult = reflectedMethod.Invoke(methodObjectToCall, methodArguments.ToArray());

            if (MethodReturnType.GetRuntimeType(programInstance) != typeof(void))
            {
                state.Stack.Push(methodResult);
            }

            return(instructionInstance.GetNextInstructionInstance());
        }
Ejemplo n.º 20
0
 public CILMethodInstance(CILMethod method, CILClassInstance thisInstance, OrderedDictionary arguments)
 {
     Method    = method;
     This      = thisInstance;
     Arguments = arguments;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Retrieves the <see cref="CILMethod"/> which is generic method definition, if applicable, and is contained in a type which is generic type definition, if applicable.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <returns>The 'true' generic definition of the method; that is, its <see cref="CILElementInstantiable.IsTrueDefinition"/> returns <c>true</c>.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
 public static CILMethod GetTrueGenericDefinition(this CILMethod method)
 {
     ArgumentValidator.ValidateNotNull("Method", method);
     return(method.HasGenericArguments() ? ((CILTypeParameter)method.GenericDefinition.GenericArguments[0]).DeclaringMethod : (method.DeclaringType.IsGenericType() ? method.ChangeDeclaringType(method.DeclaringType.GenericDefinition.GenericArguments.ToArray()) : method));
 }
Ejemplo n.º 22
0
 public override void CopyInternalData(VMValue other)
 {
     base.CopyInternalData(other);
     method = ((VMValue_ftn)other).method;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates new instance of <see cref="OpCodeInfoForNormalOrVirtual"/> which will emit either <see cref="OpCodes.Call"/> or <see cref="OpCodes.Callvirt"/> for the specified method.
 /// </summary>
 /// <param name="method">The method to emit call to.</param>
 /// <returns>New instance of <see cref="OpCodeInfoForNormalOrVirtual"/> which will emit either <see cref="OpCodes.Call"/> or <see cref="OpCodes.Callvirt"/> for the specified method.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
 public static OpCodeInfoForNormalOrVirtual OpCodeInfoForCall(CILMethod method)
 {
     return(new OpCodeInfoForNormalOrVirtual(method, OpCodes.Call, OpCodes.Callvirt));
 }
Ejemplo n.º 24
0
 internal void EmitNormalOrVirtual(CILMethod method, OpCode normalCode, OpCode virtualCode)
 {
     method = this._assemblyMapper.TryMapMethod(method);
     this.EmitWithMethod(method.Attributes.IsVirtual() && !method.DeclaringType.IsValueType() ? virtualCode : normalCode, method, false);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Convenience method to get the return type of the method.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <returns>The return type of the <paramref name="method"/>.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
 /// <seealso cref="System.Reflection.MethodInfo.ReturnType"/>
 public static CILTypeBase GetReturnType(this CILMethod method)
 {
     ArgumentValidator.ValidateNotNull("Method", method);
     return(method.ReturnParameter.ParameterType);
 }
        protected virtual void EmitPropertyRelatedThings(
            CompositeCodeGenerationInfo codeGenerationInfo,
            CompositeTypeGenerationInfo publicCompositeGenInfo,
            CompositeTypeGenerationInfo thisGenerationInfo,
            CompositeMethodGenerationInfo thisMethodGenerationInfo,
            PropertyModel propertyModel,
            Type genericPropertyMixinType
            )
        {
            var nPropertyInfo = propertyModel.NativeInfo;
            var propertyInfo  = nPropertyInfo.NewWrapper(this.ctx);

            if (this.IsCompositeGeneratedProperty(thisGenerationInfo, propertyModel, genericPropertyMixinType))
            {
                var propertyIdx  = thisGenerationInfo.AutoGeneratedPropertyInfos.Count;
                var propertyType = TypeGenerationUtils.CreateTypeForEmitting(propertyInfo.GetPropertyType(), thisGenerationInfo.GenericArguments, null);

                CILTypeBase fieldType;
                Action <CILField, MethodIL> readMethod;
                Action <CILField, MethodIL> read32Method;
                Action <CILField, MethodIL> writeMethod;
                Action <CILField, MethodIL> compareExchangeMethodEmitter;
                this.GetReadAndWriteMethods(propertyType, out readMethod, out read32Method, out writeMethod, out compareExchangeMethodEmitter, out fieldType);

                // Field:
                // private <property type or Object> _property<idx>;
                var propertyField = thisGenerationInfo.Builder.AddField(
                    PROPERTY_FIELD_PREFIX + propertyIdx,
                    fieldType,
                    FieldAttributes.Private
                    );

                // Field getter
                var getter = thisGenerationInfo.Builder.AddMethod(
                    PROPERTY_METHOD_PREFIX + propertyIdx + PROPERTY_GETTER_POSTFIX,
                    MethodAttributes.Private | MethodAttributes.HideBySig,
                    CallingConventions.HasThis);
                this.EmitPropertyGetterMethod(codeGenerationInfo, propertyModel, publicCompositeGenInfo, thisGenerationInfo, propertyField, propertyType, (CompositeMethodGenerationInfo) new CompositeMethodGenerationInfoImpl(getter, null, null).WithReturnType(propertyType) /*.WithParameters( propertyInfo.GetIndexParameters().Select( p => Tuple.Create( p.ParameterType, p.Attributes ) ) )*/, readMethod);

                // Field getter for 32-bit processes, if required
                CILMethod getter32 = null;
                if (read32Method != null)
                {
                    getter32 = thisGenerationInfo.Builder.AddMethod(
                        PROPERTY_METHOD_PREFIX + propertyIdx + PROPERTY_GETTER32_POSTFIX,
                        MethodAttributes.Private | MethodAttributes.HideBySig,
                        CallingConventions.HasThis);
                    this.EmitPropertyGetterMethod(codeGenerationInfo, propertyModel, publicCompositeGenInfo, thisGenerationInfo, propertyField, propertyType, (CompositeMethodGenerationInfo) new CompositeMethodGenerationInfoImpl(getter32, null, null).WithReturnType(propertyType) /*.WithParameters( propertyInfo.GetIndexParameters().Select( p => Tuple.Create( p.ParameterType, p.Attributes ) ) )*/, read32Method);
                }
                // Field setter
                var setter = thisGenerationInfo.Builder.AddMethod(
                    PROPERTY_METHOD_PREFIX + propertyIdx + PROPERTY_SETTER_POSTFIX,
                    MethodAttributes.Public | MethodAttributes.HideBySig, // TODO MethodAttributes.Assembly when [InternalsVisibleTo(...)] attribute will be applied to all generated assemblies.
                    CallingConventions.HasThis);
                this.EmitPropertySetterMethod(codeGenerationInfo, propertyModel, publicCompositeGenInfo, thisGenerationInfo, propertyField, fieldType, propertyType, (CompositeMethodGenerationInfo) new CompositeMethodGenerationInfoImpl(setter, null, null).WithParameters(Enumerable.Repeat(Tuple.Create(propertyType, ParameterAttributes.None), 1)), writeMethod);

                // Exchange method
                var exchangeMethod = thisGenerationInfo.Builder.AddMethod(
                    PROPERTY_METHOD_PREFIX + propertyIdx + PROPERTY_EXCHANGE_POSTFIX,
                    MethodAttributes.Private | MethodAttributes.HideBySig,
                    CallingConventions.HasThis);
                this.EmitPropertyExchangeMethod(propertyModel, thisGenerationInfo, propertyField, fieldType, propertyType, setter, (CompositeMethodGenerationInfo) new CompositeMethodGenerationInfoImpl(exchangeMethod, null, null).WithReturnType(propertyType).WithParameters(Enumerable.Repeat(Tuple.Create(propertyType, ParameterAttributes.None), 1)), writeMethod);

                // CompareExchange method
                var compareExchangeMethod = thisGenerationInfo.Builder.AddMethod(
                    PROPERTY_METHOD_PREFIX + propertyIdx + PROPERTY_COMPARE_EXCHANGE_POSTFIX,
                    MethodAttributes.Private | MethodAttributes.HideBySig,
                    CallingConventions.HasThis);
                this.EmitPropertyCompareExchangeMethod(propertyModel, thisGenerationInfo, propertyField, (CompositeMethodGenerationInfo) new CompositeMethodGenerationInfoImpl(compareExchangeMethod, null, null).WithReturnType(propertyType).WithParameters(Enumerable.Repeat(Tuple.Create(propertyType, ParameterAttributes.None), 2)), compareExchangeMethodEmitter);

                thisGenerationInfo.AutoGeneratedPropertyInfos.Add(nPropertyInfo, new PropertyGenerationInfo(
                                                                      this.EmitRefMethodForPropertyOrEvent(propertyField, PROPERTY_METHOD_PREFIX + propertyIdx + REF_INVOKER_METHOD_SUFFIX),
                                                                      propertyModel,
                                                                      propertyField,
                                                                      getter,
                                                                      getter32,
                                                                      setter,
                                                                      exchangeMethod,
                                                                      compareExchangeMethod,
                                                                      propertyType
                                                                      ));
            }

            if (this.NeedToEmitAdditionalMemberInfo(thisGenerationInfo, propertyInfo.Name, (parent, name) => parent.DeclaredProperties.FirstOrDefault(p => Object.Equals(p.Name, name))))
            {
                // Need to define property if we inherit property directly from interface
                var name = propertyInfo.Name;
                if (thisGenerationInfo.RawPropertyInfos.Keys.Any(pInfo => pInfo.Name.Equals(name)))
                {
                    // We already have property with the same name from different type
                    name = QualifiedName.FromMemberInfo(nPropertyInfo).ToString();
                }

                CILProperty pBuilder;
                if (!thisGenerationInfo.RawPropertyInfos.TryGetValue(nPropertyInfo, out pBuilder))
                {
                    pBuilder = thisGenerationInfo.Builder.AddProperty(
                        name,
                        propertyInfo.Attributes
                        );
                    thisGenerationInfo.RawPropertyInfos.Add(nPropertyInfo, pBuilder);
                }

                if (thisMethodGenerationInfo.MethodFromModel.Equals(propertyInfo.GetMethod))
                {
                    pBuilder.GetMethod = thisMethodGenerationInfo.Builder;
                }
                else if (thisMethodGenerationInfo.MethodFromModel.Equals(propertyInfo.SetMethod))
                {
                    pBuilder.SetMethod = thisMethodGenerationInfo.Builder;
                }
                else
                {
                    throw new InternalException("Found a property, but neither setter nor getter matched the method being emitted. Property is " + propertyInfo + ", method is " + thisMethodGenerationInfo.MethodFromModel + ".");
                }
            }
        }
Ejemplo n.º 27
0
 public CILantroConstructorInfo(CILMethod cilMethod, CILProgramInstance programInstance)
 {
     _programInstance = programInstance;
     Method           = cilMethod;
 }
Ejemplo n.º 28
0
        protected virtual void EmitEventInvocationMethodCore(
            EventModel eventModel,
            CompositeTypeGenerationInfo thisGenerationInfo,
            CILField eventField,
            CILTypeBase fieldType,
            CompositeMethodGenerationInfo invokeMethod,
            CILMethod eventMethodToInvoke,
            Action <LocalBuilder, EventInvocation, Type> actualEventInvoking
            )
        {
            var eventInfo = eventModel.NativeInfo;
            var il        = invokeMethod.IL;

            var eventLB             = il.DeclareLocal(fieldType);
            var afterNullCheckLabel = il.DefineLabel();

            il
            .EmitLoadThisField(eventField)
            .EmitStoreLocal(eventLB)
            .EmitLoadLocal(eventLB)
            .EmitBranch(BranchType.IF_FALSE, afterNullCheckLabel);

            EventInvocation invocationStyle;
            Type            exceptionType;

            this.GetEventInvocationStyle(eventModel, out invocationStyle, out exceptionType);

            actualEventInvoking(eventLB, invocationStyle, exceptionType);

            // Throw exception if needed
            if (EventInvocation.INVOKE_ALL.Equals(invocationStyle))
            {
                // TODO TODO TODO
                this.EmitThrowIfExceptionListHasAny(invokeMethod, exceptionType.GetConstructor(EXCEPTION_ENUMERABLE_ARRAY).NewWrapper(this.ctx));
            }

            if (!VOID_TYPE.Equals(eventMethodToInvoke.GetReturnType()))
            {
                //LocalBuilder amountOfDeadB;
                //if ( invokeMethod.TryGetLocal( LB_AMOUNT_OF_DEAD_EVENT_INFOS, out amountOfDeadB ) )
                //{
                //   il
                //      .EmitLoadLocal( amountOfDeadB )
                //      .EmitBranch( BranchType.IF_FALSE, afterNullCheckLabel );
                //}
                LocalBuilder resultB;
                if (invokeMethod.TryGetLocal(LB_RESULT, out resultB))
                {
                    il.EmitLoadLocal(resultB);
                }
                var returnLabel = il.DefineLabel();
                il
                .EmitBranch(BranchType.ALWAYS, returnLabel)
                .MarkLabel(afterNullCheckLabel)
                .EmitLoadString("The event " + eventInfo.Name + " in ")
                .EmitReflectionObjectOf(TypeGenerationUtils.CreateTypeForEmitting(eventInfo.DeclaringType.NewWrapper(this.ctx), thisGenerationInfo.GenericArguments, null))
                .EmitCall(TO_STRING_METHOD)
                .EmitLoadString(" is not set.")
                .EmitCall(STRING_CONCAT_METHOD_3)
                .EmitThrowNewException(INVALID_OPERATION_EXCEPTION_CTOR_WITH_STRING)
                .MarkLabel(returnLabel);
            }
            else
            {
                il.MarkLabel(afterNullCheckLabel);
            }

            il.EmitReturn();
        }
Ejemplo n.º 29
0
 public VMValue_ftn(int guid, CILMethod method)
     : base(guid)
 {
     this.method = method;
 }
Ejemplo n.º 30
0
 public override void CopyFrom(VMValue other)
 {
     this.method = ((VMValue_ftn)other).method;
 }
Ejemplo n.º 31
0
        //protected virtual void EmitEventCheckMethodForWeaklyReferencedEvents(
        //   CILField eventField,
        //   MethodIL il
        //   )
        //{
        //   il.EmitLoadThisField( eventField )
        //     .EmitCall( WEAK_EVENT_ARRAY_CLEANUP_METHOD )
        //     .EmitLoadNull()
        //     .EmitCeq()
        //     .EmitLoadInt32( 0 )
        //     .EmitCeq()
        //     .EmitReturn();
        //}

        protected virtual void EmitEventInvocationMethodForStronglyReferencedEvents(
            EventModel eventModel,
            CompositeTypeGenerationInfo thisGenerationInfo,
            CILField eventField,
            CILTypeBase eventType,
            CompositeMethodGenerationInfo invokeMethod,
            CILMethod eventMethodToInvoke
            )
        {
            this.EmitEventInvocationMethodCore(
                eventModel,
                thisGenerationInfo,
                eventField,
                eventType,
                invokeMethod,
                eventMethodToInvoke,
                (eventLB, invocationStyle, exceptionType) =>
            {
                if (EventInvocation.INVOKE_DIRECTLY.Equals(invocationStyle))
                {
                    // Invocation method:
                    // private <return-type> Event<idx>Invoke(<args>)
                    // {
                    //    <event-type> evt = this._event<idx>;
                    //    if (evt != null)
                    //    {
                    //       (return) this._event<idx>(<args>);
                    //    } else <if has return type other than void>
                    //    {
                    //       throw new InvalidOperationException("The event " + <event name> + " is not set.");
                    //    }
                    // }
                    this.EmitEventInvocationWithTryCatchIfNeeded(
                        invocationStyle,
                        exceptionType,
                        invokeMethod,
                        eventMethodToInvoke,
                        il => il.EmitLoadLocal(eventLB),
                        false
                        );
                }
                else
                {
                    var il = invokeMethod.IL;
                    //  foreach ( Delegate handler in evt.GetInvocationList() )
                    //  {
                    //    try
                    //    {
                    //       result = handler(<args>);
                    //    }
                    //    catch ( Exception exc )
                    //    {
                    //      if ( exceptions == null )
                    //      {
                    //         exceptions = new LinkedList<Exception>();
                    //      }
                    //      exceptions.AddLast( exc );
                    //    }
                    //  }
                    var handlersB = invokeMethod.GetOrCreateLocal(LB_EVENT_HANDLERS);
                    il
                    .EmitLoadLocal(eventLB)
                    .EmitCall(GET_INVOCATION_LIST_METHOD)
                    .EmitStoreLocal(handlersB)

                    .EmitSimpleForLoop(
                        il2 =>
                    {
                        // Int32 index = 0;
                        var idxB = invokeMethod.GetOrCreateLocal(LB_INDEX);
                        il2
                        .EmitLoadInt32(0)
                        .EmitStoreLocal(idxB);
                        return(idxB);
                    },
                        (il2, idxB, loopBodyStartLabel) =>
                    {
                        // index < list.Length
                        il2
                        .EmitLoadLocal(idxB)
                        .EmitLoadLocal(handlersB)
                        .EmitLoadArrayLength()
                        .EmitNumericConversion(CILTypeCode.UInt32, CILTypeCode.Int32, false)
                        .EmitBranch(BranchType.IF_FIRST_LESSER_THAN_SECOND, loopBodyStartLabel);
                    },
                        E_MethodIL.EmitLeftPlusPlus,
                        (il2, idxB) =>
                    {
                        this.EmitEventInvocationWithTryCatchIfNeeded(
                            invocationStyle,
                            exceptionType,
                            invokeMethod,
                            eventMethodToInvoke,
                            il3 =>
                        {
                            il3
                            .EmitLoadLocal(handlersB)
                            .EmitLoadLocal(idxB)
                            .EmitLoadElement(handlersB.LocalType)
                            .EmitCastToType(handlersB.LocalType.GetElementType(), eventType);
                        },
                            true
                            );
                    }
                        );
                }
            });
        }
Ejemplo n.º 32
0
        public CILInstruction CallFunction(CILMethod theMethod)
        {
            ReturnAddress ra = new ReturnAddress(currentMethod, pc);
            returnAddresses.Push(ra);

            VMLocalVariableBlock vBlock = new VMLocalVariableBlock(this, theMethod);
            localVariableBlocks.Push(vBlock);
            // The first argument is the object itself
            for(int i = -1; i < theMethod.ParameterCount; i++)
                vBlock.AddArgumentFront(GetValue(threadStack.Pop()));
            currentMethod = theMethod;

            return theMethod.GetFirstInstruction();
        }
Ejemplo n.º 33
0
        protected AbstractCompositeModelTypeCodeGenerator(Boolean isSilverlight, CILReflectionContext aCtx)
        {
            this.isSilverLight = isSilverlight;
            this.ctx           = aCtx;

            this.COMPOSITE_CTOR_PROPERTIES_PARAM_TYPE = COMPOSITE_CTOR_PROPERTIES_PARAM_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.COMPOSITE_CTOR_EVENTS_PARAM_TYPE     = COMPOSITE_CTOR_EVENTS_PARAM_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.ACTION_REF_TYPE       = ACTION_REF_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.ACTION_REF_TYPES_1    = ACTION_REF_TYPES_1_NATIVE.Select(t => t.NewWrapperAsType(ctx)).ToArray();
            this.ACTION_REF_TYPES_2    = ACTION_REF_TYPES_2_NATIVE.Select(t => t.NewWrapperAsType(ctx)).ToArray();
            this.CHECK_STATE_FUNC_TYPE = CHECK_STATE_FUNC_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.PUBLIC_COMPOSITE_CTOR_ADDITTIONAL_PARAM_TYPES = PUBLIC_COMPOSITE_CTOR_ADDITTIONAL_PARAM_TYPES_NATIVE.Select(t => t.NewWrapperAsType(ctx)).ToArray();
            this.ACTION_TYPE                 = ACTION_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.FRAGMENT_DEPENDANT_TYPE     = FRAGMENT_DEPENDANT_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.FIELD_MODEL_TYPE            = FIELD_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.CONSTRUCTOR_MODEL_TYPE      = CONSTRUCTOR_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.PARAMETER_MODEL_TYPE        = PARAMETER_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.SPECIAL_METHOD_MODEL_TYPE   = SPECIAL_METHOD_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.COMPOSITE_METHOD_MODEL_TYPE = COMPOSITE_METHOD_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.CONSTRAINT_MODEL_TYPE       = CONSTRAINT_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.VOID_TYPE      = VOID_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.OBJECT_TYPE    = OBJECT_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.ATTRIBUTE_TYPE = ATTRIBUTE_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.TYPE_TYPE      = TYPE_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.ABSTRACT_INJECTABLE_MODEL_TYPE = ABSTRACT_INJECTABLE_MODEL_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.CONSTRAINT_TYPE = CONSTRAINT_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.INT32_TYPE      = INT32_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.UINT32_TYPE     = UINT32_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.INT64_TYPE      = INT64_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.BOOLEAN_TYPE    = BOOLEAN_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.SINGLE_TYPE     = SINGLE_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.DOUBLE_TYPE     = DOUBLE_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.INT_PTR_TYPE    = INT_PTR_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.STRING_TYPE     = STRING_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.EXCEPTION_TYPE  = EXCEPTION_TYPE_NATIVE.NewWrapperAsType(ctx);
            //this.WEAK_EVENT_WRAPPER_TYPE = WEAK_EVENT_WRAPPER_TYPE_NATIVE.NewWrapperAsType( ctx );
            //this.STRONG_EVENT_WRAPPER_TYPE = STRONG_EVENT_WRAPPER_TYPE_NATIVE.NewWrapperAsType( ctx );
            this.IENUMERABLE_GDEF_TYPE       = IENUMERABLE_GDEF_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.IENUMERABLE_NO_GDEF_TYPE    = IENUMERABLE_NO_GDEF_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.USE_DEFAULTS_ATTRIBUTE_TYPE = USE_DEFAULTS_ATTRIBUTE_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.COMPOSITE_FACTORY_TYPE      = COMPOSITE_FACTORY_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.REF_ACTION_TYPE             = REF_ACTION_TYPE_NATIVE.NewWrapperAsType(ctx);
            this.REF_FUNCTION_TYPE           = REF_FUNCTION_TYPE_NATIVE.NewWrapperAsType(ctx);

            this.APPLICATION_GETTER_METHOD                = APPLICATION_GETTER_METHOD_NATIVE.NewWrapper(ctx);
            this.STRUCTURE_OWNER_GETTER_METHOD            = STRUCTURE_OWNER_GETTER_METHOD_NATIVE.NewWrapper(ctx);
            this.APPLICATION_IS_PASSIVE_GETTER_METHOD     = APPLICATION_IS_PASSIVE_GETTER_METHOD_NATIVE.NewWrapper(ctx);
            this.INJECTION_SERVICE_GETTER_METHOD          = INJECTION_SERVICE_GETTER_METHOD_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_METHOD_MODEL_PARAMETERS_GETTER = COMPOSITE_METHOD_MODEL_PARAMETERS_GETTER_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_METHOD_RESULT_GETTER           = COMPOSITE_METHOD_RESULT_GETTER_NATIVE.NewWrapper(ctx);
            //this.INJECTABLE_MODEL_INJECTION_SCOPES_GETTER = INJECTABLE_MODEL_INJECTION_SCOPES_GETTER_NATIVE.NewWrapper( ctx );
            this.INJECTION_CONTEXT_PROVIDER_METHOD = INJECTION_CONTEXT_PROVIDER_METHOD_NATIVE.NewWrapper(ctx);
            this.OPTIONAL_ATTRIBUTE_FIELD          = OPTIONAL_ATTRIBUTE_FIELD_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_MODELS_GETTER          = CONSTRAINT_MODELS_GETTER_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_ATTRIBUTE_GETTER       = CONSTRAINT_ATTRIBUTE_GETTER_NATIVE.NewWrapper(ctx);
            this.VIOLATIONS_LIST_COUNT_GETTER      = VIOLATIONS_LIST_COUNT_GETTER_NATIVE.NewWrapper(ctx);
            this.METHOD_INFO_NATIVE_GETTER         = METHOD_INFO_NATIVE_GETTER_NATIVE.NewWrapper(ctx);
            this.MODEL_INFO_GETTER = MODEL_INFO_GETTER_NATIVE.NewWrapper(ctx);
            this.MODEL_GETTER      = MODEL_GETTER_NATIVE.NewWrapper(ctx);
            this.C_METHODS_GETTER  = C_METHODS_GETTER_NATIVE.NewWrapper(ctx);
            this.GET_FRAGMENT_INSTANCE_POOL_METHOD = GET_FRAGMENT_INSTANCE_POOL_METHOD_NATIVE.NewWrapper(ctx);
            this.GET_FRAGMENT_INSTANCE_METHOD      = GET_FRAGMENT_INSTANCE_METHOD_NATIVE.NewWrapper(ctx);
            this.TAKE_FRAGMENT_INSTANCE_METHOD     = TAKE_FRAGMENT_INSTANCE_METHOD_NATIVE.NewWrapper(ctx);
            this.RETURN_FRAGMENT_INSTANCE_METHOD   = RETURN_FRAGMENT_INSTANCE_METHOD_NATIVE.NewWrapper(ctx);
            this.SPECIAL_METHODS_GETTER            = SPECIAL_METHODS_GETTER_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_GETTER                              = FRAGMENT_GETTER_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_SETTER                              = FRAGMENT_SETTER_NATIVE.NewWrapper(ctx);
            this.COMPOSITES_GETTER                            = COMPOSITES_GETTER_NATIVE.NewWrapper(ctx);
            this.COMPOSITES_GETTER_INDEXER                    = COMPOSITES_GETTER_INDEXER_NATIVE.NewWrapper(ctx);
            this.TYPE_OBJECT_DICTIONARY_GET_METHOD            = TYPE_OBJECT_DICTIONARY_GET_METHOD_NATIVE.NewWrapper(ctx);
            this.GENERIC_FRAGMENT_METHOD                      = GENERIC_FRAGMENT_METHOD_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_VIOLATION_CONSTRUCTOR             = CONSTRAINT_VIOLATION_CONSTRUCTOR_NATIVE.NewWrapper(ctx);
            this.ADD_CONSTRAINT_VIOLATION_METHOD              = ADD_CONSTRAINT_VIOLATION_METHOD_NATIVE.NewWrapper(ctx);
            this.F_INSTANCE_SET_NEXT_INFO_METHOD              = F_INSTANCE_SET_NEXT_INFO_METHOD_NATIVE.NewWrapper(ctx);
            this.F_INSTANCE_SET_METHOD_RESULT_METHOD          = F_INSTANCE_SET_METHOD_RESULT_METHOD_NATIVE.NewWrapper(ctx);
            this.F_INSTANCE_GET_NEXT_INFO_METHOD              = F_INSTANCE_GET_NEXT_INFO_METHOD_NATIVE.NewWrapper(ctx);
            this.F_INSTANCE_GET_METHOD_RESULT_METHOD          = F_INSTANCE_GET_METHOD_RESULT_METHOD_NATIVE.NewWrapper(ctx);
            this.STRING_CONCAT_METHOD_3                       = STRING_CONCAT_METHOD_3_NATIVE.NewWrapper(ctx);
            this.STRING_CONCAT_METHOD_2                       = STRING_CONCAT_METHOD_2_NATIVE.NewWrapper(ctx);
            this.METHOD_INFO_GET_GARGS_METHOD                 = METHOD_INFO_GET_GARGS_METHOD_NATIVE.NewWrapper(ctx);
            this.MAKE_GENERIC_METHOD_METHOD                   = MAKE_GENERIC_METHOD_METHOD_NATIVE.NewWrapper(ctx);
            this.INVOKE_METHOD_METHOD                         = INVOKE_METHOD_METHOD_NATIVE.NewWrapper(ctx);
            this.GET_METHDO_GDEF                              = GET_METHDO_GDEF_NATIVE.NewWrapper(ctx);
            this.GET_CTOR_INDEX_METHOD                        = GET_CTOR_INDEX_METHOD_NATIVE.NewWrapper(ctx);
            this.APPLICATION_NOT_ACTIVE_EXCEPTION_CONSTRUCTOR = APPLICATION_NOT_ACTIVE_EXCEPTION_CONSTRUCTOR_NATIVE.NewWrapper(ctx);
            this.GET_CONSTRAINT_INSTANCE_POOL_METHOD          = GET_CONSTRAINT_INSTANCE_POOL_METHOD_NATIVE.NewWrapper(ctx);
            this.TAKE_CONSTRAINT_INSTANCE_METHOD              = TAKE_CONSTRAINT_INSTANCE_METHOD_NATIVE.NewWrapper(ctx);
            this.RETURN_CONSTRAINT_INSTANCE_METHOD            = RETURN_CONSTRAINT_INSTANCE_METHOD_NATIVE.NewWrapper(ctx);
            this.IS_VALID_METHOD                              = IS_VALID_METHOD_NATIVE.NewWrapper(ctx);
            this.TO_STRING_METHOD                             = TO_STRING_METHOD_NATIVE.NewWrapper(ctx);
            this.RETURN_CONCERN_INVOCATION_METHOD             = RETURN_CONCERN_INVOCATION_METHOD_NATIVE.NewWrapper(ctx);
            this.RETURN_SIDE_EFFECT_INVOCATION_METHOD         = RETURN_SIDE_EFFECT_INVOCATION_METHOD_NATIVE.NewWrapper(ctx);
            this.EMPTY_OBJECTS_FIELD                          = EMPTY_OBJECTS_FIELD_NATIVE.NewWrapper(ctx);
            this.LIST_QUERY_ITEM_GETTER                       = LIST_QUERY_ITEM_GETTER_NATIVE.NewWrapper(ctx);
            this.FIELDS_GETTER                                = FIELDS_GETTER_NATIVE.NewWrapper(ctx);
            this.FIELD_SET_VALUE_METHOD                       = FIELD_SET_VALUE_METHOD_NATIVE.NewWrapper(ctx);
            this.PROTOTYPE_ACTION_CONSTRUCTOR                 = PROTOTYPE_ACTION_CONSTRUCTOR_NATIVE.NewWrapper(ctx);
            this.EQUALS_METHOD                                = EQUALS_METHOD_NATIVE.NewWrapper(ctx);
            this.HASH_CODE_METHOD                             = HASH_CODE_METHOD_NATIVE.NewWrapper(ctx);
            this.REFERENCE_EQUALS_METHOD                      = REFERENCE_EQUALS_METHOD_NATIVE.NewWrapper(ctx);
            this.GET_TYPE_METHOD                              = GET_TYPE_METHOD_NATIVE.NewWrapper(ctx);
            this.DELEGATE_COMBINE_METHOD                      = DELEGATE_COMBINE_METHOD_NATIVE.NewWrapper(ctx);
            this.DELEGATE_REMOVE_METHOD                       = DELEGATE_REMOVE_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_METHOD_GDEF     = INTERLOCKED_COMPARE_EXCHANGE_METHOD_GDEF_NATIVE.NewWrapper(ctx);
            this.GET_EVENT_INFO_METHOD                        = GET_EVENT_INFO_METHOD_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_EVENT_CTOR                         = COMPOSITE_EVENT_CTOR_NATIVE.NewWrapper(ctx);
            this.INVALID_OPERATION_EXCEPTION_CTOR_WITH_STRING = INVALID_OPERATION_EXCEPTION_CTOR_WITH_STRING_NATIVE.NewWrapper(ctx);
            this.QNAME_FROM_TYPE_AND_NAME                     = QNAME_FROM_TYPE_AND_NAME_NATIVE.NewWrapper(ctx);
            this.IS_PROTOTYPE_GETTER                          = IS_PROTOTYPE_GETTER_NATIVE.NewWrapper(ctx);
            this.GET_PROPERTY_INFO_METHOD                     = GET_PROPERTY_INFO_METHOD_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_METHODS_INDEXER                    = COMPOSITE_METHODS_INDEXER_NATIVE.NewWrapper(ctx);
            this.EVENT_MODEL_GETTER                           = EVENT_MODEL_GETTER_NATIVE.NewWrapper(ctx);
            this.PROPERTY_MODEL_GETTER                        = PROPERTY_MODEL_GETTER_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_PROPERTY_CTOR                      = COMPOSITE_PROPERTY_CTOR_NATIVE.NewWrapper(ctx);
            this.INVOCATION_INFO_GETTER                       = INVOCATION_INFO_GETTER_NATIVE.NewWrapper(ctx);
            this.INVOCATION_INFO_SETTER                       = INVOCATION_INFO_SETTER_NATIVE.NewWrapper(ctx);
            this.INVOCATION_INFO_CREATOR_CTOR                 = INVOCATION_INFO_CREATOR_CTOR_NATIVE.NewWrapper(ctx);
            this.INVOCATION_INFO_METHOD_GETTER                = INVOCATION_INFO_METHOD_GETTER_NATIVE.NewWrapper(ctx);
            this.INVOCATION_INFO_FRAGMENT_METHOD_MODEL_GETTER = INVOCATION_INFO_FRAGMENT_METHOD_MODEL_GETTER_NATIVE.NewWrapper(ctx);
            this.INVOCATION_INFO_FRAGMENT_METHOD_MODEL_SETTER = INVOCATION_INFO_FRAGMENT_METHOD_MODEL_SETTER_NATIVE.NewWrapper(ctx);
            this.CONCERN_MODELS_GETTER                        = CONCERN_MODELS_GETTER_NATIVE.NewWrapper(ctx);
            this.CONCERN_MODELS_INDEXER                       = CONCERN_MODELS_INDEXER_NATIVE.NewWrapper(ctx);
            this.MIXIN_MODEL_GETTER                           = MIXIN_MODEL_GETTER_NATIVE.NewWrapper(ctx);
            this.SIDE_EFFECT_MODELS_GETTER                    = SIDE_EFFECT_MODELS_GETTER_NATIVE.NewWrapper(ctx);
            this.SIDE_EFFECT_MODELS_INDEXER                   = SIDE_EFFECT_MODELS_INDEXER_NATIVE.NewWrapper(ctx);
            this.COLLECTION_ADD_ONLY_ADD_METHOD               = COLLECTION_ADD_ONLY_ADD_METHOD_NATIVE.NewWrapper(ctx);
            this.ACTION_0_CTOR                                = ACTION_0_CTOR_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_METHOD_GDEF             = INTERLOCKED_EXCHANGE_METHOD_GDEF_NATIVE.NewWrapper(ctx);
            this.GET_INVOCATION_LIST_METHOD                   = GET_INVOCATION_LIST_METHOD_NATIVE.NewWrapper(ctx);
            this.ADD_LAST_METHOD                              = ADD_LAST_METHOD_NATIVE.NewWrapper(ctx);
            //this.WEAK_EVENT_ARRAY_WRAPPER_ARRAY_GETTER = WEAK_EVENT_ARRAY_WRAPPER_ARRAY_GETTER_NATIVE.NewWrapper( ctx );
            //this.WEAK_EVENT_ARRAY_WRAPPER_COUNT_GETTER = WEAK_EVENT_ARRAY_WRAPPER_COUNT_GETTER_NATIVE.NewWrapper( ctx );
            //this.WEAK_EVENT_ARRAY_CLEANUP_METHOD = WEAK_EVENT_ARRAY_CLEANUP_METHOD_NATIVE.NewWrapper( ctx );
            //this.WEAK_EVENT_ARRAY_COMBINE_METHOD = WEAK_EVENT_ARRAY_COMBINE_METHOD_NATIVE.NewWrapper( ctx );
            //this.WEAK_EVENT_ARRAY_REMOVE_METHOD = WEAK_EVENT_ARRAY_REMOVE_METHOD_NATIVE.NewWrapper( ctx );
            //this.IS_EVENT_INFO_DEAD_METHOD = IS_EVENT_INFO_DEAD_METHOD_NATIVE.NewWrapper( ctx );
            //this.EVENT_INFO_TARGET_GETTER = EVENT_INFO_TARGET_GETTER_NATIVE.NewWrapper( ctx );
            //this.EVENT_INFO_METHOD_GETTER = EVENT_INFO_METHOD_GETTER_NATIVE.NewWrapper( ctx );
            //this.EVENT_INFO_CTOR = EVENT_INFO_CTOR_NATIVE.NewWrapper( ctx );
            this.Q_NAME_GET_BARE_TYPE_NAME_METHOD       = Q_NAME_GET_BARE_TYPE_NAME_METHOD_NATIVE.NewWrapper(ctx);
            this.Q_NAME_FROM_MEMBER_INFO_METHOD         = Q_NAME_FROM_MEMBER_INFO_METHOD_NATIVE.NewWrapper(ctx);
            this.INJECTION_EXCEPTION_CTOR               = INJECTION_EXCEPTION_CTOR_NATIVE.NewWrapper(ctx);
            this.CHECK_STATE_METHOD_SIG                 = CHECK_STATE_METHOD_SIG_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_EXCEPTION_VIOLATIONS_GETTER = CONSTRAINT_EXCEPTION_VIOLATIONS_GETTER_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_VIOLATIONS_DIC_ADD_METHOD   = CONSTRAINT_VIOLATIONS_DIC_ADD_METHOD_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_VIOLATIONS_DIC_CTOR         = CONSTRAINT_VIOLATIONS_DIC_CTOR_NATIVE.NewWrapper(ctx);
            this.CHECK_ACTION_FUNC_CTOR                 = CHECK_ACTION_FUNC_CTOR_NATIVE.NewWrapper(ctx);
            this.SET_DEFAULTS_METHOD_SIG                = SET_DEFAULTS_METHOD_SIG_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_VIOLATIONS_LIST_CTOR        = CONSTRAINT_VIOLATIONS_LIST_CTOR_NATIVE.NewWrapper(ctx);
            this.EXCEPTION_LIST_CTOR = EXCEPTION_LIST_CTOR_NATIVE.NewWrapper(ctx);
            this.FUNC_1_CTOR         = FUNC_1_CTOR_NATIVE.NewWrapper(ctx);
            this.FUNC_2_CTOR         = FUNC_2_CTOR_NATIVE.NewWrapper(ctx);
            this.FUNC_3_CTOR         = FUNC_3_CTOR_NATIVE.NewWrapper(ctx);
            this.ACTION_1_CTOR       = ACTION_1_CTOR_NATIVE.NewWrapper(ctx);
            this.LAZY_GDEF_CTOR      = LAZY_GDEF_CTOR_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_INSTANCE_CTOR_NO_PARAMS   = FRAGMENT_INSTANCE_CTOR_NO_PARAMS_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_INSTANCE_CTOR_WITH_PARAMS = FRAGMENT_INSTANCE_CTOR_WITH_PARAMS_NATIVE.NewWrapper(ctx);
            this.MODEL_CTORS_GETTER                 = MODEL_CTORS_GETTER_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_DEPENDANT_GETTER          = FRAGMENT_DEPENDANT_GETTER_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_DEPENDANT_SETTER          = FRAGMENT_DEPENDANT_SETTER_NATIVE.NewWrapper(ctx);
            this.FRAGMENT_DEPENDANT_PROPERTY        = FRAGMENT_DEPENDANT_PROPERTY_NATIVE.NewWrapper(ctx);
            this.CONCERN_INVOCATION_INFO_ITEM_1     = CONCERN_INVOCATION_INFO_ITEM_1_NATIVE.NewWrapper(ctx);
            this.CONCERN_INVOCATION_INFO_ITEM_2     = CONCERN_INVOCATION_INFO_ITEM_2_NATIVE.NewWrapper(ctx);
            this.SIDE_EFFECT_INVOCATION_INFO_ITEM_1 = SIDE_EFFECT_INVOCATION_INFO_ITEM_1_NATIVE.NewWrapper(ctx);
            this.SIDE_EFFECT_INVOCATION_INFO_ITEM_2 = SIDE_EFFECT_INVOCATION_INFO_ITEM_2_NATIVE.NewWrapper(ctx);
            this.SIDE_EFFECT_INVOCATION_INFO_ITEM_3 = SIDE_EFFECT_INVOCATION_INFO_ITEM_3_NATIVE.NewWrapper(ctx);
            this.OBJECT_CTOR             = OBJECT_CTOR_NATIVE.NewWrapper(ctx);
            this.NULLABLE_CTOR           = NULLABLE_CTOR_NATIVE.NewWrapper(ctx);
            this.DEFAULT_CREATOR_GETTER  = DEFAULT_CREATOR_GETTER_NATIVE.NewWrapper(ctx);
            this.DEFAULT_CREATOR_INVOKER = DEFAULT_CREATOR_INVOKER_NATIVE.NewWrapper(ctx);
            this.NO_POOL_ATTRIBUTE_CTOR  = NO_POOL_ATTRIBUTE_CTOR_NATIVE.NewWrapper(ctx);
            this.MAIN_PUBLIC_COMPOSITE_TYPE_ATTRIBUTE_CTOR = MAIN_PUBLIC_COMPOSITE_TYPE_ATTRIBUTE_CTOR_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_VIOLATION_LIST_CTOR            = CONSTRAINT_VIOLATION_LIST_CTOR_NATIVE.NewWrapper(ctx);
            this.CONSTRAINT_VIOLATION_EXCEPTION_CTOR       = CONSTRAINT_VIOLATION_EXCEPTION_CTOR_NATIVE.NewWrapper(ctx);
            this.INTERNAL_EXCEPTION_CTOR = INTERNAL_EXCEPTION_CTOR_NATIVE.NewWrapper(ctx);
            this.AGGREGATE_EXCEPTION_EXCEPTION_ENUMERABLE_CTOR = AGGREGATE_EXCEPTION_EXCEPTION_ENUMERABLE_CTOR_NATIVE.NewWrapper(ctx);
            this.DEBUGGER_DISPLAY_ATTRIBUTE_STRING_CTOR        = DEBUGGER_DISPLAY_ATTRIBUTE_STRING_CTOR_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_READ_I64_METHOD                 = INTERLOCKED_READ_I64_METHOD_NATIVE == null ? null : INTERLOCKED_READ_I64_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_I32_METHOD             = INTERLOCKED_EXCHANGE_I32_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_I64_METHOD             = INTERLOCKED_EXCHANGE_I64_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_R32_METHOD             = INTERLOCKED_EXCHANGE_R32_METHOD_NATIVE == null ? null : INTERLOCKED_EXCHANGE_R32_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_R64_METHOD             = INTERLOCKED_EXCHANGE_R64_METHOD_NATIVE == null ? null : INTERLOCKED_EXCHANGE_R64_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_INT_PTR_METHOD         = INTERLOCKED_EXCHANGE_INT_PTR_METHOD_NATIVE == null ? null : INTERLOCKED_EXCHANGE_INT_PTR_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_EXCHANGE_OBJECT_METHOD          = INTERLOCKED_EXCHANGE_OBJECT_METHOD_NATIVE == null ? null : INTERLOCKED_EXCHANGE_OBJECT_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_I32_METHOD     = INTERLOCKED_COMPARE_EXCHANGE_I32_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_I64_METHOD     = INTERLOCKED_COMPARE_EXCHANGE_I64_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_R32_METHOD     = INTERLOCKED_COMPARE_EXCHANGE_R32_METHOD_NATIVE == null ? null : INTERLOCKED_COMPARE_EXCHANGE_R32_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_R64_METHOD     = INTERLOCKED_COMPARE_EXCHANGE_R64_METHOD_NATIVE == null ? null : INTERLOCKED_COMPARE_EXCHANGE_R64_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_INT_PTR_METHOD = INTERLOCKED_COMPARE_EXCHANGE_INT_PTR_METHOD_NATIVE == null ? null : INTERLOCKED_COMPARE_EXCHANGE_INT_PTR_METHOD_NATIVE.NewWrapper(ctx);
            this.INTERLOCKED_COMPARE_EXCHANGE_OBJECT_METHOD  = INTERLOCKED_COMPARE_EXCHANGE_OBJECT_METHOD_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_TYPE_ID_CTOR   = COMPOSITE_TYPE_ID_CTOR_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_FACTORY_METHOD = COMPOSITE_FACTORY_METHOD_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_CALLBACK_GET_COMPOSITE_METHOD_METHOD = COMPOSITE_CALLBACK_GET_COMPOSITE_METHOD_METHOD_NATIVE.NewWrapper(ctx);
            this.ARGUMENT_EXCEPTION_STRING_CTOR         = ARGUMENT_EXCEPTION_STRING_CTOR_NATIVE.NewWrapper(ctx);
            this.MAKE_GENERIC_TYPE_METHOD               = MAKE_GENERIC_TYPE_METHOD_NATIVE.NewWrapper(ctx);
            this.GET_FIRST_INSTANCE_CTOR                = GET_FIRST_INSTANCE_CTOR_NATIVE.NewWrapper(ctx);
            this.CONSTRUCTOR_INVOKE_METHOD              = CONSTRUCTOR_INVOKE_METHOD_NATIVE.NewWrapper(ctx);
            this.INT_PTR_SIZE_GETTER                    = INT_PTR_SIZE_GETTER_NATIVE.NewWrapper(ctx);
            this.REF_ACTION_INVOKER                     = REF_ACTION_INVOKER_NATIVE.NewWrapper(ctx);
            this.REF_FUNCTION_INVOKER                   = REF_FUNCTION_INVOKER_NATIVE.NewWrapper(ctx);
            this.REF_INVOKER_CALLBACK_CTOR              = REF_INVOKER_CALLBACK_CTOR_NATIVE.NewWrapper(ctx);
            this.COMPOSITE_METHOD_MODEL_INDEX_ATTRIBUTE = COMPOSITE_METHOD_MODEL_INDEX_ATTRIBUTE_NATIVE.NewWrapper(ctx);
            this.SPECIAL_METHOD_MODEL_INDEX_ATTRIBUTE   = SPECIAL_METHOD_MODEL_INDEX_ATTRIBUTE_NATIVE.NewWrapper(ctx);
            this.CONSTRUCTOR_MODEL_INDEX_ATTRIBUTE      = CONSTRUCTOR_MODEL_INDEX_ATTRIBUTE_NATIVE.NewWrapper(ctx);
            this.DOUBLE_BITS_TO_INT64                   = DOUBLE_BITS_TO_INT64_NATIVE.NewWrapper(ctx);
            this.INT64_BITS_TO_DOUBLE                   = INT64_BITS_TO_DOUBLE_NATIVE.NewWrapper(ctx);
            this.GET_BYTES_INT32  = GET_BYTES_INT32_NATIVE.NewWrapper(ctx);
            this.GET_BYTES_SINGLE = GET_BYTES_INT32_NATIVE.NewWrapper(ctx);
            this.BYTES_TO_INT32   = GET_BYTES_INT32_NATIVE.NewWrapper(ctx);
            this.BYTES_TO_SINGLE  = GET_BYTES_INT32_NATIVE.NewWrapper(ctx);
        }
Ejemplo n.º 34
0
 public CILInstruction MethodReturn()
 {
     localVariableBlocks.Pop();
     if(returnAddresses.Count == 0)
     {
         return null;
     }
     else
     {
         ReturnAddress ra = returnAddresses.Pop();
         currentMethod = ra.theMethod;
         pc = currentMethod.GetNextInstruction(ra.thePC);
         return pc;
     }
 }
Ejemplo n.º 35
0
 internal void Emit(OpCode code, CILMethod method, Boolean useGDefIfPossible)
 {
     this.EmitWithMethod(code, this._assemblyMapper.TryMapMethod(method), useGDefIfPossible);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Checks whether the method has any generic arguments, that is, its <see cref="CILElementWithGenericArguments{T}.GenericArguments"/> property has at least one item.
 /// </summary>
 /// <param name="method">The method to check.</param>
 /// <returns><c>true</c> if the <paramref name="method"/> is non-<c>null</c> and has any generic arguments; <c>false</c> otherwise.</returns>
 public static Boolean HasGenericArguments(this CILMethod method)
 {
     return(method != null && method.GenericArguments.Any());
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Creates new instance of <see cref="OpCodeInfoForNormalOrVirtual"/> which will emit either <see cref="OpCodes.Ldftn"/> or <see cref="OpCodes.Ldvirtftn"/> for the specified method.
 /// </summary>
 /// <param name="method">The method to emit loading function pointer to.</param>
 /// <returns>New instance of <see cref="OpCodeInfoForNormalOrVirtual"/> which will emit either <see cref="OpCodes.Ldftn"/> or <see cref="OpCodes.Ldvirtftn"/> for the specified method.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
 public static OpCodeInfoForNormalOrVirtual OpCodeInfoForLdFtn(CILMethod method)
 {
     return(new OpCodeInfoForNormalOrVirtual(method, OpCodes.Ldftn, OpCodes.Ldvirtftn));
 }
 public ServiceModelTypeCodeGenerator(Boolean isSilverlight, CILReflectionContext ctx)
     : base(isSilverlight, ctx)
 {
     this.SERVICE_COMPOSITE_ACTIVATE_IF_NEEDED_METHOD = SERVICE_COMPOSITE_ACTIVATE_IF_NEEDED_METHOD_NATIVE.NewWrapper(this.ctx);
     this.METHOD_GENERIC_ARGUMENTS_INFO_CTOR          = METHOD_GENERIC_ARGUMENTS_INFO_CTOR_NATIVE.NewWrapper(this.ctx);
 }