private static void HandleTypeInitializers(Dictionary <MethodInterpreterKey, MethodInterpreter> result,
                                                   List <MethodInterpreter> toAdd, CrRuntimeLibrary crRuntime)
        {
            foreach (var it in toAdd)
            {
                var declaringType = it.Method.DeclaringType;
                if (declaringType == null)
                {
                    continue;
                }
                declaringType = crRuntime.GetMappedType(declaringType);
                if (declaringType == null)
                {
                    continue;
                }
                declaringType = declaringType.GetReversedType(crRuntime);
                if (declaringType.TypeInitializer == null)
                {
                    continue;
                }
                var info = declaringType.TypeInitializer;

                var interpreter = info.GetInterpreter(crRuntime);
                if (interpreter != null)
                {
                    result[interpreter.ToKey()] = interpreter;
                    UpdateMethodEntryClosure(interpreter, result, crRuntime);
                }
            }
        }
Beispiel #2
0
        public void NewObject(ConstructorInfo constructorInfo, CrRuntimeLibrary crRuntime)
        {
            if (constructorInfo.DeclaringType == typeof(object))
            {
                return;
            }
            var mappedType = crRuntime.GetMappedType(constructorInfo.DeclaringType);

            if (mappedType != null && mappedType != constructorInfo.DeclaringType)
            {
                constructorInfo = crRuntime.GetMappedConstructor(constructorInfo);
            }
            constructorInfo.Register();
            var result = SetNewVReg();

            result.FixedType = new TypeDescription(constructorInfo.DeclaringType);
            var constructedObject = new NewConstructedObject(constructorInfo);
            var assignment        = new Assignment
            {
                AssignedTo = result,
                Right      = constructedObject
            };

            AddOperation(OperationKind.NewObject, assignment);

            var interpreter = constructedObject.Info.Register(crRuntime);
            var methodData  = new MethodData(interpreter);

            CallMethodData(constructedObject.Info, methodData, OperationKind.Call, crRuntime);
            var vreg = SetNewVReg();

            vreg.FixedType = new TypeDescription(methodData.Info.DeclaringType);
            var assign = new Assignment
            {
                AssignedTo = vreg,
                Right      = methodData.Parameters.First()
            };

            AddOperation(OperationKind.Assignment, assign);
        }
Beispiel #3
0
        private static HashSet <Type> BuildScannedDictionaryFromTypesAndInstructions(HashSet <Type> typesSet,
                                                                                     CrRuntimeLibrary crRuntime)
        {
            bool isAdded;

            do
            {
                var toAdd = new HashSet <Type>(typesSet);
                foreach (var type in typesSet)
                {
                    AddBaseTypesToHash(type, toAdd);
                    var mappedType = crRuntime.GetMappedType(type);
                    if (type.IsPrimitive)
                    {
                        continue;
                    }

                    var fieldTypes = UsedTypeList.GetFieldTypeDependencies(type);
                    toAdd.AddRange(fieldTypes);
                    var fields = mappedType.GetFields().ToList();

                    fields.AddRange(mappedType.GetFields(
                                        BindingFlags.NonPublic
                                        | BindingFlags.Instance
                                        | BindingFlags.Static));
                    foreach (var fieldInfo in fields)
                    {
                        var fieldType = fieldInfo.FieldType;
                        if (fieldType.IsInterface)
                        {
                            continue;
                        }
                        if (fieldType.IsSubclassOf(typeof(Array)))
                        {
                            fieldType = fieldType.GetElementType();
                        }
                        if (fieldType.IsPointer || fieldType.IsByRef)
                        {
                            fieldType = fieldType.GetElementType();
                        }

                        var typeDesc = UsedTypeList.Set(type, crRuntime);
                        if (typeDesc == null)
                        {
                            continue;
                        }
                        toAdd.Add(fieldType);
                        AddBaseTypesToHash(fieldType, toAdd);
                    }
                }
                isAdded  = (toAdd.Count != typesSet.Count);
                typesSet = toAdd;
            } while (isAdded);
            var typesClosure = typesSet.Where(t =>
                                              IsRefClassType(t) && !t.IsInterface).ToList();

            foreach (var type in typesClosure)
            {
                UsedTypeList.Set(type, crRuntime);
            }

            typesSet.Remove(typeof(void));
            typesSet.Remove(typeof(IntPtr));
            typesSet.Remove(typeof(Array));

            typesSet.RemoveWhere(t => t.IsInterface);
            typesSet.RemoveWhere(t => t.IsPrimitive);
            typesSet.RemoveWhere(t => t.IsSubclassOf(typeof(Array)));
            typesSet.RemoveWhere(t => t.GetMappedType() == t && string.IsNullOrEmpty(t.FullName));
            return(typesSet);
        }