Ejemplo n.º 1
0
        public void initialize()
        {
            foreach (var kv in getMovedTypes())
            {
                var structType = kv.Key;
                structToOwners.add(structType, kv.Value);

                foreach (var ownerType in kv.Value)
                {
                    foreach (var ownerField in ownerType.Fields)
                    {
                        if (DotNetUtils.getType(module, ownerField.FieldType) != structType)
                        {
                            continue;
                        }
                        structFieldsToFix.add(ownerField, true);
                        break;
                    }

                    var fieldsDict = new FieldDefinitionAndDeclaringTypeDict <FieldDefinition>();
                    typeToFieldsDict.add(ownerType, fieldsDict);
                    foreach (var structField in structType.Fields)
                    {
                        var newField = DotNetUtils.createFieldDefinition(structField.Name, structField.Attributes, structField.FieldType);
                        ownerType.Fields.Add(newField);
                        fieldsDict.add(structField, newField);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        IEnumerable <FieldDefinition> getPossibleFields(TypeDefinition type)
        {
            var typeToFields = new TypeDefinitionDict <List <FieldDefinition> >();

            foreach (var field in type.Fields)
            {
                if (field.Attributes != FieldAttributes.Private)
                {
                    continue;
                }
                var fieldType = DotNetUtils.getType(module, field.FieldType);
                if (fieldType == null)
                {
                    continue;
                }
                if (!checkBaseType(fieldType))
                {
                    continue;
                }
                var list = typeToFields.find(fieldType);
                if (list == null)
                {
                    typeToFields.add(fieldType, list = new List <FieldDefinition>());
                }
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues())
            {
                if (list.Count == 1)
                {
                    yield return(list[0]);
                }
            }
        }
Ejemplo n.º 3
0
 void initializeMethodsTypes()
 {
     foreach (var type in module.GetTypes())
     {
         if (checkMethodsType(type))
         {
             methodsTypes.add(type, true);
         }
     }
 }
Ejemplo n.º 4
0
 void initTokenToType()
 {
     moduleType = DotNetUtils.getModuleType(moduleDefinition);
     foreach (var typeDefinition in moduleDefinition.GetTypes())
     {
         int  token = typeDefinition.MetadataToken.ToInt32();
         Type type;
         try {
             type = module.ResolveType(token);
         }
         catch {
             tokenToType[token] = null;
             typeReferenceToType.add(typeDefinition, null);
             continue;
         }
         var mtype = new MType(type, typeDefinition);
         tokenToType[token] = mtype;
         typeReferenceToType.add(typeDefinition, mtype);
     }
 }
Ejemplo n.º 5
0
        void initialize(TypeDefinition type)
        {
            if (type.HasEvents || type.HasProperties)
            {
                return;
            }

            if (!type.IsValueType)
            {
                return;
            }
            if (type.Methods.Count != 1)
            {
                return;
            }
            var ctor = type.Methods[0];

            if (ctor.Name != ".ctor" || ctor.Body == null || ctor.IsStatic)
            {
                return;
            }
            if (ctor.Parameters.Count != 1)
            {
                return;
            }
            var ctorParam = ctor.Parameters[0];

            if (type.Fields.Count != 1)
            {
                return;
            }
            var typeField = type.Fields[0];

            if (typeField.IsStatic)
            {
                return;
            }
            if (!MemberReferenceHelper.compareTypes(ctorParam.ParameterType, typeField.FieldType))
            {
                return;
            }

            typeToInfo.add(ctor.DeclaringType, new Info(ctor.DeclaringType, typeField.FieldType));
        }
Ejemplo n.º 6
0
        public TypeDefinitionDict <bool> getInlinedTypes(IEnumerable <MethodDefinition> unusedMethods)
        {
            var unused = new MethodDefinitionAndDeclaringTypeDict <bool>();

            foreach (var method in unusedMethods)
            {
                unused.add(method, true);
            }

            var types = new TypeDefinitionDict <bool>();

            foreach (var type in methodsTypes.getKeys())
            {
                if (checkAllMethodsUnused(unused, type))
                {
                    types.add(type, true);
                }
            }
            return(types);
        }
Ejemplo n.º 7
0
        public TypeDefinitionDict<bool> getInlinedTypes(IEnumerable<MethodDefinition> unusedMethods)
        {
            var unused = new MethodDefinitionAndDeclaringTypeDict<bool>();
            foreach (var method in unusedMethods)
                unused.add(method, true);

            var types = new TypeDefinitionDict<bool>();
            foreach (var type in methodsTypes.getKeys()) {
                if (checkAllMethodsUnused(unused, type))
                    types.add(type, true);
            }
            return types;
        }
Ejemplo n.º 8
0
        IEnumerable<FieldDefinition> getPossibleFields(TypeDefinition type)
        {
            var typeToFields = new TypeDefinitionDict<List<FieldDefinition>>();
            foreach (var field in type.Fields) {
                if (field.Attributes != FieldAttributes.Private)
                    continue;
                var fieldType = DotNetUtils.getType(module, field.FieldType);
                if (fieldType == null || !fieldType.IsValueType)
                    continue;
                var list = typeToFields.find(fieldType);
                if (list == null)
                    typeToFields.add(fieldType, list = new List<FieldDefinition>());
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues()) {
                if (list.Count == 1)
                    yield return list[0];
            }
        }
Ejemplo n.º 9
0
 public void add(TypeDefinition type)
 {
     types.add(type, true);
 }