示例#1
0
        private void ResolveProperty(MosaProperty property)
        {
            GenericArgumentResolver resolver = new GenericArgumentResolver();

            if (property.DeclaringType.GenericArguments.Count > 0)
            {
                resolver.PushTypeGenericArguments(property.DeclaringType.GenericArguments.GetGenericArguments());
            }

            using (var mosaProperty = metadata.Controller.MutateProperty(property))
            {
                mosaProperty.PropertyType = metadata.Loader.GetType(resolver.Resolve(property.GetPropertySig().RetType));

                ResolveCustomAttributes(mosaProperty, property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >().Definition);
            }
        }
示例#2
0
        private void ResolveField(MosaField field)
        {
            var resolver = new GenericArgumentResolver();

            if (field.DeclaringType.GenericArguments.Count > 0)
            {
                resolver.PushTypeGenericArguments(field.DeclaringType.GenericArguments.GetGenericArguments());
            }

            using (var mosaField = metadata.Controller.MutateField(field))
            {
                mosaField.FieldType = metadata.Loader.GetType(resolver.Resolve(field.GetFieldSig().Type));

                mosaField.HasOpenGenericParams = field.DeclaringType.HasOpenGenericParams ||
                                                 field.FieldType.GetTypeSig().HasOpenGenericParameter();

                ResolveCustomAttributes(mosaField, field.GetUnderlyingObject <UnitDesc <FieldDef, FieldSig> >().Definition);
            }
        }
示例#3
0
        private void ResolveType(MosaType type)
        {
            GenericArgumentResolver resolver = new GenericArgumentResolver();

            MosaType srcType = type;

            if (type.GenericArguments.Count > 0)
            {
                resolver.PushTypeGenericArguments(type.GenericArguments.GetGenericArguments());
                srcType = type.ElementType;
                Debug.Assert(srcType != null);
            }

            using (var mosaType = metadata.Controller.MutateType(type))
            {
                if (srcType.BaseType != null)
                {
                    mosaType.BaseType = metadata.Loader.GetType(resolver.Resolve(srcType.BaseType.GetTypeSig()));
                }

                if (srcType.DeclaringType != null)
                {
                    mosaType.DeclaringType = metadata.Loader.GetType(resolver.Resolve(srcType.DeclaringType.GetTypeSig()));
                    mosaType.Namespace     = srcType.DeclaringType.Namespace;
                }

                var ifaces = new List <MosaType>(srcType.Interfaces);
                mosaType.Interfaces.Clear();
                for (int i = 0; i < ifaces.Count; i++)
                {
                    mosaType.Interfaces.Add(metadata.Loader.GetType(resolver.Resolve(ifaces[i].GetTypeSig())));
                }

                mosaType.HasOpenGenericParams = type.GetTypeSig().HasOpenGenericParameter();

                ResolveCustomAttributes(mosaType, srcType.GetUnderlyingObject <UnitDesc <TypeDef, TypeSig> >().Definition);
            }

            // Add type again to make it easier to find
            metadata.Controller.AddType(type);
        }
示例#4
0
        private void ResolveMethod(MosaMethod method)
        {
            GenericArgumentResolver resolver = new GenericArgumentResolver();
            bool hasOpening = method.DeclaringType.HasOpenGenericParams;

            if (method.DeclaringType.GenericArguments.Count > 0)
            {
                foreach (var i in method.DeclaringType.GenericArguments.GetGenericArguments())
                {
                    hasOpening |= i.HasOpenGenericParameter();
                }
                resolver.PushTypeGenericArguments(method.DeclaringType.GenericArguments.GetGenericArguments());
            }

            if (method.GenericArguments.Count > 0)
            {
                foreach (var i in method.GenericArguments.GetGenericArguments())
                {
                    hasOpening |= i.HasOpenGenericParameter();
                }
                resolver.PushMethodGenericArguments(method.GenericArguments.GetGenericArguments());
            }

            using (var mosaMethod = metadata.Controller.MutateMethod(method))
            {
                var desc = method.GetUnderlyingObject <UnitDesc <MethodDef, MethodSig> >();

                MosaType returnType = metadata.Loader.GetType(resolver.Resolve(desc.Signature.RetType));
                hasOpening |= returnType.HasOpenGenericParams;
                List <MosaParameter> pars = new List <MosaParameter>();

                Debug.Assert(desc.Signature.GetParamCount() + (desc.Signature.HasThis ? 1 : 0) == desc.Definition.Parameters.Count);
                foreach (var param in desc.Definition.Parameters)
                {
                    if (!param.IsNormalMethodParameter)
                    {
                        continue;
                    }
                    var paramType = metadata.Loader.GetType(resolver.Resolve(desc.Signature.Params[param.MethodSigIndex]));
                    var parameter = metadata.Controller.CreateParameter();

                    using (var mosaParameter = metadata.Controller.MutateParameter(parameter))
                    {
                        mosaParameter.Name = param.Name;
                        mosaParameter.ParameterAttributes = (MosaParameterAttributes)param.ParamDef.Attributes;
                        mosaParameter.ParameterType       = paramType;
                        mosaParameter.DeclaringMethod     = method;
                        ResolveCustomAttributes(mosaParameter, param.ParamDef);
                    }

                    pars.Add(parameter);
                    hasOpening |= paramType.HasOpenGenericParams;
                }

                mosaMethod.Signature = new MosaMethodSignature(returnType, pars);

                foreach (var methodImpl in desc.Definition.Overrides)
                {
                    Debug.Assert(methodImpl.MethodBody == desc.Definition);
                    mosaMethod.Overrides.Add(ResolveMethodOperand(methodImpl.MethodDeclaration, null));
                }

                if (desc.Definition.HasBody)
                {
                    ResolveBody(desc.Definition, mosaMethod, desc.Definition.Body, resolver);
                }

                mosaMethod.HasOpenGenericParams = hasOpening;

                ResolveCustomAttributes(mosaMethod, desc.Definition);
            }
        }
        private MosaType LoadGenericTypeInstanceSig(GenericInstSig typeSig)
        {
            //Debug.Assert(false, typeSig.FullName);
            MosaType origin = GetType(typeSig.GenericType);
            MosaType result = metadata.Controller.CreateType(origin);
            var      desc   = result.GetUnderlyingObject <UnitDesc <TypeDef, TypeSig> >();

            using (var resultType = metadata.Controller.MutateType(result))
            {
                resultType.UnderlyingObject = desc.Clone(typeSig);
                resultType.ElementType      = origin;

                foreach (var genericArg in typeSig.GenericArguments)
                {
                    resultType.GenericArguments.Add(GetType(genericArg));
                }

                metadata.Resolver.EnqueueForResolve(result);

                GenericArgumentResolver resolver = new GenericArgumentResolver();
                resolver.PushTypeGenericArguments(typeSig.GenericArguments);

                for (int i = 0; i < result.Methods.Count; i++)
                {
                    MosaMethod method = metadata.Controller.CreateMethod(result.Methods[i]);

                    using (var mosaMethod = metadata.Controller.MutateMethod(method))
                    {
                        mosaMethod.DeclaringType    = result;
                        mosaMethod.UnderlyingObject = method.GetUnderlyingObject <UnitDesc <MethodDef, MethodSig> >();
                    }

                    resultType.Methods[i] = method;
                    metadata.Resolver.EnqueueForResolve(method);
                }

                for (int i = 0; i < result.Fields.Count; i++)
                {
                    MosaField field = metadata.Controller.CreateField(result.Fields[i]);

                    using (var mosaField = metadata.Controller.MutateField(field))
                    {
                        mosaField.DeclaringType    = result;
                        mosaField.UnderlyingObject = field.GetUnderlyingObject <UnitDesc <FieldDef, FieldSig> >();
                    }

                    resultType.Fields[i] = field;
                    metadata.Resolver.EnqueueForResolve(field);
                }

                for (int i = 0; i < result.Properties.Count; i++)
                {
                    MosaProperty property = metadata.Controller.CreateProperty(result.Properties[i]);

                    PropertySig newSig = property.GetPropertySig().Clone();
                    newSig.RetType = resolver.Resolve(newSig.RetType);
                    using (var mosaProperty = metadata.Controller.MutateProperty(property))
                    {
                        mosaProperty.DeclaringType    = result;
                        mosaProperty.UnderlyingObject = property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >();
                    }

                    resultType.Properties[i] = property;
                    metadata.Resolver.EnqueueForResolve(property);
                }

                resultType.HasOpenGenericParams = typeSig.HasOpenGenericParameter();
            }

            metadata.Controller.AddType(result);

            return(result);
        }