Beispiel #1
0
 public TypeInfo(TypeDef typeDef, MemberInfos memberInfos)
     : base(typeDef)
 {
     this.type = typeDef;
     this.memberInfos = memberInfos;
     oldNamespace = typeDef.TypeDefinition.Namespace;
 }
Beispiel #2
0
 public MethodDef(MethodDefinition methodDefinition, TypeDef owner, int index)
     : base(methodDefinition, owner, index)
 {
     genericParams = GenericParamDef.createGenericParamDefList(MethodDefinition.GenericParameters);
     for (int i = 0; i < methodDefinition.Parameters.Count; i++) {
         var param = methodDefinition.Parameters[i];
         paramDefs.Add(new ParamDef(param, i));
     }
 }
Beispiel #3
0
        void findInitializeComponentMethod(TypeDef type, MethodDef possibleInitMethod)
        {
            foreach (var methodDef in type.AllMethods) {
                if (methodDef.MethodDefinition.Name != ".ctor")
                    continue;
                if (methodDef.MethodDefinition.Body == null)
                    continue;
                foreach (var instr in methodDef.MethodDefinition.Body.Instructions) {
                    if (instr.OpCode.Code != Code.Call && instr.OpCode.Code != Code.Callvirt)
                        continue;
                    if (!MemberReferenceHelper.compareMethodReferenceAndDeclaringType(possibleInitMethod.MethodDefinition, instr.Operand as MethodReference))
                        continue;

                    memberInfos.method(possibleInitMethod).suggestedName = "InitializeComponent";
                    return;
                }
            }
        }
Beispiel #4
0
 public PropertyDef(PropertyDefinition propertyDefinition, TypeDef owner, int index)
     : base(propertyDefinition, owner, index)
 {
 }
Beispiel #5
0
 public TypeInfo(TypeReference typeReference, TypeDef typeDef)
 {
     this.typeReference = typeReference;
     this.typeDef = typeDef;
 }
Beispiel #6
0
 public void addBaseType(TypeDef baseDef, TypeReference baseRef)
 {
     if (baseDef == null || baseRef == null)
         return;
     baseType = new TypeInfo(baseRef, baseDef);
 }
		public void RemoveTypeDef(TypeDef td) {
			if (!TypeDefs.Remove(td))
				throw new ApplicationException(string.Format("Could not remove TypeDef: {0}", td));
		}
Beispiel #8
0
 void mergeState(TypeDef other)
 {
     if (other == null)
         return;
     TypeInfo otherInfo;
     if (!memberInfos.tryGetType(other, out otherInfo))
         return;
     variableNameState.merge(otherInfo.variableNameState);
 }
Beispiel #9
0
            void merge(TypeDef type)
            {
                if (visited.ContainsKey(type))
                    return;
                visited[type] = true;

                TypeInfo info;
                if (!memberInfos.tryGetType(type, out info))
                    return;

                if (type.baseType != null)
                    merge(type.baseType.typeDef);
                foreach (var ifaceInfo in type.interfaces)
                    merge(ifaceInfo.typeDef);

                if (type.baseType != null)
                    merge(info, type.baseType.typeDef);
                foreach (var ifaceInfo in type.interfaces)
                    merge(info, ifaceInfo.typeDef);
            }
Beispiel #10
0
            void visit(TypeDef type)
            {
                if (visited.ContainsKey(type))
                    return;
                visited[type] = true;

                if (type.baseType != null)
                    visit(type.baseType.typeDef);
                foreach (var ifaceInfo in type.interfaces)
                    visit(ifaceInfo.typeDef);

                TypeInfo info;
                if (!memberInfos.tryGetType(type, out info))
                    return;

                foreach (var method in type.AllMethodsSorted) {
                    MethodNameGroup group;
                    if (!methodToGroup.TryGetValue(method, out group))
                        continue;
                    foreach (var m in group.Methods)
                        methodToGroup.Remove(m);
                    func(group);
                }
            }
Beispiel #11
0
        void renameMembers(TypeDef type)
        {
            var info = memberInfos.type(type);

            Log.v("Type: {0}", Utils.removeNewlines(info.type.TypeDefinition.FullName));
            Log.indent();

            renameFields(info);
            renameProperties(info);
            renameEvents(info);
            renameMethods(info);

            Log.deIndent();
        }
Beispiel #12
0
        void rename(TypeDef type)
        {
            var typeDefinition = type.TypeDefinition;
            var info = memberInfos.type(type);

            Log.v("Type: {0} ({1:X8})", Utils.removeNewlines(typeDefinition.FullName), typeDefinition.MetadataToken.ToUInt32());
            Log.indent();

            renameGenericParams(type.GenericParams);

            if (RenameTypes && info.gotNewName()) {
                var old = typeDefinition.Name;
                typeDefinition.Name = info.newName;
                Log.v("Name: {0} => {1}", Utils.removeNewlines(old), Utils.removeNewlines(typeDefinition.Name));
            }

            if (RenameNamespaces && info.newNamespace != null) {
                var old = typeDefinition.Namespace;
                typeDefinition.Namespace = info.newNamespace;
                Log.v("Namespace: {0} => {1}", Utils.removeNewlines(old), Utils.removeNewlines(typeDefinition.Namespace));
            }

            Log.deIndent();
        }
Beispiel #13
0
		public MTypeDef(TypeDef typeDef, Module module, int index)
			: base(typeDef, null, index) {
			this.module = module;
			genericParams = MGenericParamDef.CreateGenericParamDefList(TypeDef.GenericParameters);
		}
Beispiel #14
0
 protected Ref(MemberReference memberReference, TypeDef owner, int index)
 {
     this.memberReference = memberReference;
     Owner = owner;
     Index = index;
 }
Beispiel #15
0
        string findWindowsFormsClassName(TypeDef type)
        {
            foreach (var methodDef in type.AllMethods) {
                if (methodDef.MethodDefinition.Body == null)
                    continue;
                if (methodDef.MethodDefinition.IsStatic || methodDef.MethodDefinition.IsVirtual)
                    continue;
                var instructions = methodDef.MethodDefinition.Body.Instructions;
                for (int i = 2; i < instructions.Count; i++) {
                    var call = instructions[i];
                    if (call.OpCode.Code != Code.Call && call.OpCode.Code != Code.Callvirt)
                        continue;
                    if (!isWindowsFormsSetNameMethod(call.Operand as MethodReference))
                        continue;

                    var ldstr = instructions[i - 1];
                    if (ldstr.OpCode.Code != Code.Ldstr)
                        continue;
                    var className = ldstr.Operand as string;
                    if (className == null)
                        continue;

                    if (DotNetUtils.getArgIndex(instructions[i - 2]) != 0)
                        continue;

                    findInitializeComponentMethod(type, methodDef);
                    return className;
                }
            }
            return null;
        }
Beispiel #16
0
            void merge(TypeInfo info, TypeDef other)
            {
                TypeInfo otherInfo;
                if (!memberInfos.tryGetType(other, out otherInfo))
                    return;

                if ((flags & MergeStateFlags.Methods) != MergeStateFlags.None)
                    info.variableNameState.mergeMethods(otherInfo.variableNameState);
                if ((flags & MergeStateFlags.Properties) != MergeStateFlags.None)
                    info.variableNameState.mergeProperties(otherInfo.variableNameState);
                if ((flags & MergeStateFlags.Events) != MergeStateFlags.None)
                    info.variableNameState.mergeEvents(otherInfo.variableNameState);
            }
Beispiel #17
0
            void prepare(TypeDef type)
            {
                if (prepareMethodCalled.ContainsKey(type))
                    return;
                prepareMethodCalled[type] = true;

                foreach (var ifaceInfo in type.interfaces)
                    prepare(ifaceInfo.typeDef);
                if (type.baseType != null)
                    prepare(type.baseType.typeDef);

                TypeInfo info;
                if (memberInfos.tryGetType(type, out info))
                    func(info);
            }
Beispiel #18
0
 void Add(TypeDef td)
 {
     if (td == null || typeDefs.ContainsKey(td))
         return;
     if (td.Module != validModule)
         return;
     typeDefs[td] = true;
     Push(td.BaseType);
     Add(td.Fields);
     Add(td.Methods);
     Add(td.GenericParameters);
     Add(td.Interfaces);
     Add(td.DeclSecurities);
     Add(td.DeclaringType);
     Add(td.Events);
     Add(td.Properties);
     Add(td.NestedTypes);
     Add(td.CustomAttributes);
 }
Beispiel #19
0
        EventDef createEvent(TypeDef ownerType, string name, TypeReference eventType)
        {
            if (string.IsNullOrEmpty(name) || eventType == null || eventType.FullName == "System.Void")
                return null;
            var newEvent = DotNetUtils.createEventDefinition(name, eventType);
            var eventDef = ownerType.findAny(newEvent);
            if (eventDef != null)
                return eventDef;

            eventDef = ownerType.create(newEvent);
            memberInfos.add(eventDef);
            Log.v("Restoring event: {0}", Utils.removeNewlines(newEvent));
            return eventDef;
        }
Beispiel #20
0
 public void add(TypeDef t)
 {
     types.add(t);
 }
Beispiel #21
0
        PropertyDef createProperty(TypeDef ownerType, string name, TypeReference propType, MethodDefinition getter, MethodDefinition setter)
        {
            if (string.IsNullOrEmpty(name) || propType.FullName == "System.Void")
                return null;
            var newProp = DotNetUtils.createPropertyDefinition(name, propType, getter, setter);
            var propDef = ownerType.findAny(newProp);
            if (propDef != null)
                return propDef;

            propDef = ownerType.create(newProp);
            memberInfos.add(propDef);
            Log.v("Restoring property: {0}", Utils.removeNewlines(newProp));
            return propDef;
        }
Beispiel #22
0
 public void addInterface(TypeDef ifaceDef, TypeReference iface)
 {
     if (ifaceDef == null || iface == null)
         return;
     interfaces.Add(new TypeInfo(iface, ifaceDef));
 }
Beispiel #23
0
 void fixClsTypeNames(TypeDef nesting, TypeDef nested)
 {
     int nestingCount = nesting == null ? 0 : nesting.GenericParams.Count;
     int arity = nested.GenericParams.Count - nestingCount;
     var nestedInfo = memberInfos.type(nested);
     if (nestedInfo.renamed && arity > 0)
         nestedInfo.newName += "`" + arity;
     foreach (var nestedType in nested.NestedTypes)
         fixClsTypeNames(nested, nestedType);
 }
Beispiel #24
0
 public TypeInfo(TypeInfo other, GenericInstanceType git)
 {
     this.typeReference = TypeReferenceInstance.make(other.typeReference, git);
     this.typeDef = other.typeDef;
 }
Beispiel #25
0
 public EventDef(EventDefinition eventDefinition, TypeDef owner, int index)
     : base(eventDefinition, owner, index)
 {
 }