Пример #1
0
        private IType ResolveClass(TypeDefinition definition)
        {
            if (_resolvedTypes.ContainsKey(definition))
            {
                return(_resolvedTypes[definition]);
            }
            Console.WriteLine("Loading " + definition.FullName + " (class)");
            ClassType type = new ClassType(definition.FullName);

            _resolvedTypes.Add(definition, type);

            if (definition.BaseType != null)
            {
                type.Parent = ResolveType(definition.BaseType);
            }

            foreach (FieldDefinition field in definition.Fields)
            {
                if (field.InitialValue.Length != 0)
                {
                    throw new NotSupportedException("Initial values not supported!");
                }

                if (field.HasConstant)
                {
                    type.AddField(field, new ConstantField(type, ResolveType(field.FieldType), field.Name,
                                                           field.Constant));
                }
                else if (field.IsStatic)
                {
                    type.AddField(field, new StaticField(type, ResolveType(field.FieldType), field.Name));
                }
                else
                {
                    type.AddField(field, new LocalField(type, ResolveType(field.FieldType), field.Name));
                }
            }

            foreach (MethodDefinition method in definition.Methods)
            {
                IType[] args = method.Parameters.Select(p => ResolveType(p.ParameterType).GetStackType()).ToArray();
                type.AddMethod(method, new StandardMethod(type, method.Name, method.IsStatic,
                                                          !method.IsStatic && !method.IsVirtual && !method.IsAbstract, method.IsVirtual,
                                                          method.HasThis && !method.ExplicitThis, ResolveType(method.ReturnType), args, method.Body));
            }

            type.Init();

            return(type);
        }
Пример #2
0
        protected void BuildField(ClassType classType, FieldInfo fieldInfo)
        {
            var fieldType = storage.GetType(ConvertMSILNames(fieldInfo.FieldType));

            if (fieldType != null)
            {
                classType.AddField(fieldInfo.Name, fieldType);
            }
        }
Пример #3
0
    ClassType FillIn(ClassType t, System.Type type)
    {
        foreach (System.Type x in type.GetNestedTypes(flags))
        {
            GetType(x);
        }
        foreach (FieldInfo x in type.GetFields(BindingFlags.Instance | BindingFlags.Static | flags))
        {
            Field f = t.AddField(new InputElement(x.Name), msg);
            f.Modifiers = GetFieldModifiers(x);
            f.Type      = GetType(x.FieldType);
        }
        foreach (ConstructorInfo x in type.GetConstructors(BindingFlags.Instance | BindingFlags.Static | flags))
        {
            GetMethod(t.AddConstructor(new InputElement(t.Name), msg), x);
        }
        foreach (MethodInfo x in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | flags))
        {
            if (x.Name == "get_Item" || x.Name == "set_Item" ||
                type.FullName == "System.String" && x.Name == "get_Chars")
            {
                GetMethod(t, x.Name, x);                        // indexer
            }
            else if (x.Name.StartsWith("get_") || x.Name.StartsWith("set_"))
            {
                string   name = x.Name.Substring(4);
                Property p    = t.members[name] as Property;
                if (p == null)
                {
                    p = t.AddProperty(new InputElement(name), msg);
                }
                p.Modifiers = GetMethodModifiers(x);
                Method m;
                if (x.Name.StartsWith("get_"))
                {
                    m      = p.AddGet(new InputElement(name));
                    p.Type = GetType(x.ReturnType);
                }
                else
                {
                    m      = p.AddSet(new InputElement(name));
                    m.Type = global.Types.Void;
                    p.Type = GetType(x.GetParameters()[0].ParameterType);
                }
            }
            else
            {
                GetMethod(t, x.Name, x);
            }
        }
        t.Modifiers = GetTypeModifiers(type);
        IList baseinterfaces;

        if (type.BaseType != null)
        {
            t.baseClass    = (ClassType)GetType(type.BaseType);
            baseinterfaces = type.BaseType.GetInterfaces();
        }
        else
        {
            baseinterfaces = new System.Type[0];
        }
        if (type.DeclaringType != null)
        {
            t.enclosingType = (ClassType)GetType(type.DeclaringType);
        }
        foreach (System.Type x in type.GetInterfaces())
        {
            if (!baseinterfaces.Contains(x))
            {
                t.interfaces.Add((InterfaceType)GetType(x));
            }
        }
        return(t);
    }
Пример #4
0
 ClassType FillIn(ClassType t, MetaDataTypeDefinition d, string path)
 {
     foreach (MetaDataTypeDefinition x in d.NestedClasses)
     {
         GetSymbol(x, path);
     }
     foreach (MetaDataField x in d.Fields)
     {
         Field f = t.AddField(new InputElement(x.Name), msg);
         f.Modifiers = GetFieldModifiers(x);
         f.Type      = GetType(x.Signature.FieldType, path);
     }
     foreach (MetaDataMethod x in d.Methods)
     {
         if (x.Name == "get_Item" || x.Name == "set_Item" ||
             d.FullName == "System.String" && x.Name == "get_Chars")
         {
             GetMethod(t, x.Name, x, path);  // indexer
         }
         else if (x.Name.StartsWith("get_") || x.Name.StartsWith("set_"))
         {
             Property p;
             string   name = x.Name.Substring(4);
             if (t.members.Contains(name))
             {
                 p = (Property)t.members[name];
             }
             else
             {
                 p = t.AddProperty(new InputElement(name), msg);
             }
             p.Modifiers = GetMethodModifiers(x);
             Method m;
             if (x.Name.StartsWith("get_"))
             {
                 m      = p.AddGet(new InputElement(name));
                 m.Type = GetType(x.Signature.ReturnType, path);
             }
             else
             {
                 m      = p.AddSet(new InputElement(name));
                 p.Type = GetType(x.Signature.Parameters[0].Type, path);
                 m.Type = global.Types.Void;
             }
             m.Modifiers = p.Modifiers;
         }
         else if (x.Name == ".ctor")
         {
             GetMethod(t.AddConstructor(new InputElement(t.Name), msg), x, path);
         }
         else if (x.Name == ".cctor")
         {
             Constructor m = new Constructor(new InputElement(t.Name), t.members);
             GetMethod(m, x, path);
         }
         else
         {
             GetMethod(t, x.Name, x, path);
         }
     }
     t.Modifiers     = GetTypeModifiers(d);
     t.baseClass     = (ClassType)ResolveTypeRef(d.Extends, path);
     t.enclosingType = (ClassType)ResolveTypeRef(d.EnclosingClass, path);
     foreach (MetaDataObject x in d.Interfaces)
     {
         InterfaceType f = ResolveTypeRef(x, path) as InterfaceType;
         if (f != null)
         {
             t.interfaces.Add(f);
         }
     }
     return(t);
 }