Esempio n. 1
0
 /// <summary>
 /// Create type info for given reference in given context.
 /// </summary>
 /// <param name="typeReference">Reference of created type.</param>
 /// <param name="context">Context of transcription.</param>
 /// <returns>Created type descriptor.</returns>
 private TypeDescriptor createTypeInfo(TypeReference typeReference, TranscriptionContext context)
 {
     if (typeReference == null)
     {
         return(null);
     }
     return(context.TypeHelper.BuildDescriptor(typeReference));
 }
Esempio n. 2
0
        /// <summary>
        /// Create CILMethod from MethodInfo representation. Is used for
        /// creating methods from runtime .NET methods.
        /// </summary>
        /// <param name="method">Runtime .NET method representation.</param>
        /// <param name="methodInfo">The method information.</param>
        public CILMethod(MethodInfo method, TypeMethodInfo methodInfo)
        {
            //TODO: Reflection methods doesnt support now context generic parameters
            Context           = new TranscriptionContext(methodInfo, new GenericParameter[0]);
            Name              = method.Name;
            MethodDescription = method.ToString();
            var reader = new ILReader(method);

            Instructions = from instruction in reader.Instructions select new CILInstruction(instruction, Context);
        }
Esempio n. 3
0
        /// <summary>
        /// Resolves that field is static.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if field is static, <c>false</c> otherwise.</returns>
        private bool resolveIsStatic(FieldReference field, TranscriptionContext context)
        {
            var definition = field as FieldDefinition;

            if (definition == null)
            {
                return(false);
            }

            return(definition.IsStatic);
        }
Esempio n. 4
0
        /// <summary>
        /// Create CILInstruction from Mono.Cecil instruction representation of instruction.
        /// </summary>
        /// <param name="instruction">Mono.Cecil representation of instruction.</param>
        /// <param name="context">The context of transcription.</param>
        internal CILInstruction(Instruction instruction, TranscriptionContext context)
        {
            Address = instruction.Offset;
            Data    = instruction.Operand;

            OpCode               = instruction.OpCode;
            MethodOperand        = CreateMethodInfo(Data as MethodReference, needsDynamicResolving(OpCode), context);
            BranchAddressOperand = getBranchOffset(Data as Instruction);

            SetterOperand = createSetter(Data as FieldReference, context);
            GetterOperand = createGetter(Data as FieldReference, context);
            TypeOperand   = createTypeInfo(Data as TypeReference, context);
        }
Esempio n. 5
0
        /// <summary>
        /// Create CILInstruction from runtime .NET representation of instruction.
        /// </summary>
        /// <param name="instruction">Runtime .NET representation of instruction.</param>
        /// <param name="context">The context of transcription.</param>
        internal CILInstruction(ILInstruction instruction, TranscriptionContext context)
        {
            Address = instruction.Address;
            Data    = instruction.Data;

            OpCode = OpCodesTable[instruction.OpCode.Name];

            MethodOperand        = createMethodInfo(Data as MethodInfo);
            BranchAddressOperand = getBranchOffset(instruction);
            SetterOperand        = createSetter(Data as FieldInfo);
            GetterOperand        = createGetter(Data as FieldInfo);

            TypeOperand = null;
        }
Esempio n. 6
0
        /// <summary>
        /// Create getter info for given field.
        /// </summary>
        /// <param name="field">Field which getter is needed.</param>
        /// <param name="context">Context of transcription.</param>
        /// <returns>Created getter.</returns>
        private TypeMethodInfo createGetter(FieldReference field, TranscriptionContext context)
        {
            if (field == null)
            {
                return(null);
            }

            var name          = Naming.GetterPrefix + field.Name;
            var declaringType = createTypeInfo(field.DeclaringType, context);
            var fieldType     = createTypeInfo(field.FieldType, context);
            var isStatic      = resolveIsStatic(field, context);

            return(new TypeMethodInfo(declaringType,
                                      name, fieldType, ParameterTypeInfo.NoParams,
                                      isStatic, TypeDescriptor.NoDescriptors));
        }
Esempio n. 7
0
        /// <summary>
        /// Create CILMethod from MethodDefinition representation. Is used for
        /// creating methods from methods loaded by Mono.Cecil.
        /// </summary>
        /// <param name="method">Mono.Cecil method.</param>
        /// <param name="methodInfo">The method information.</param>
        public CILMethod(MethodDefinition method, TypeMethodInfo methodInfo)
        {
            var genericTypeParameters   = method.DeclaringType.GenericParameters;
            var genericMethodParameters = method.GenericParameters;

            Context = new TranscriptionContext(methodInfo, genericTypeParameters.Concat(genericMethodParameters));
            if (method == null || method.Body == null)
            {
                //empty method
                Instructions = new CILInstruction[0];
            }
            else
            {
                //wrap instructions
                Instructions = from instruction in method.Body.Instructions select new CILInstruction(instruction, Context);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates method info for given method.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="needsDynamicResolution">if set to <c>true</c> [needs dynamic resolution].</param>
        /// <param name="context">The context.</param>
        /// <returns>TypeMethodInfo.</returns>
        internal static TypeMethodInfo CreateMethodInfo(MethodReference method, bool needsDynamicResolution, TranscriptionContext context)
        {
            if (method == null)
            {
                return(null);
            }

            //Get available type helper
            var typeHelper = context == null ? new TypeReferenceHelper() : context.TypeHelper;

            var builder = new MethodInfoBuilder(method, typeHelper);

            builder.NeedsDynamicResolving = needsDynamicResolution;

            return(builder.Build());
        }