/// <summary>
        /// Instantiated type computation for runtime interfaces. Instantiated types
        /// must have the same count of interfaces across all possible instantiations
        /// so the algorithm works by computing the uninstantiated form, and then
        /// specializing each interface as needed.
        /// </summary>
        private DefType[] ComputeRuntimeInterfacesForInstantiatedType(InstantiatedType instantiatedType)
        {
            MetadataType uninstantiatedType = (MetadataType)instantiatedType.GetTypeDefinition();

            DefType[] genericTypeDefinitionInterfaces = uninstantiatedType.RuntimeInterfaces;

            return InstantiatedType.InstantiateTypeArray(uninstantiatedType.RuntimeInterfaces, instantiatedType.Instantiation, new Instantiation());
        }
Beispiel #2
0
        private void InitializeTypeInstance(Cts.InstantiatedType entity, TypeSpecification record)
        {
            var sig = new TypeInstantiationSignature
            {
                GenericType = HandleType(entity.GetTypeDefinition()),
            };

            for (int i = 0; i < entity.Instantiation.Length; i++)
            {
                sig.GenericTypeArguments.Add(HandleType(entity.Instantiation[i]));
            }

            record.Signature = sig;
        }
Beispiel #3
0
        private void InitializeTypeInstance(Cts.InstantiatedType entity, TypeSpecification record)
        {
            var args = new List <MetadataRecord>(entity.Instantiation.Length);

            for (int i = 0; i < entity.Instantiation.Length; i++)
            {
                args.Add(HandleType(entity.Instantiation[i]));
            }

            record.Signature = new TypeInstantiationSignature
            {
                GenericType          = HandleType(entity.GetTypeDefinition()),
                GenericTypeArguments = args
            };
        }
Beispiel #4
0
        /// <summary>
        /// Resolve a virtual function call (to a virtual method, not an interface method)
        /// </summary>
        /// <param name="targetMethod"></param>
        /// <param name="objectType"></param>
        /// <returns>The override of the virtual method that should be called</returns>
        private static MethodDesc FindVirtualFunctionTargetMethodOnObjectType(MethodDesc targetMethod, MetadataType objectType)
        {
            // Step 1, convert objectType to uninstantiated form
            MetadataType     uninstantiatedType      = objectType;
            MethodDesc       initialTargetMethod     = targetMethod;
            InstantiatedType initialInstantiatedType = objectType as InstantiatedType;

            if (initialInstantiatedType != null)
            {
                uninstantiatedType = (MetadataType)initialInstantiatedType.GetTypeDefinition();
            }

            // Step 2, convert targetMethod to method in type hierarchy of uninstantiated form
            targetMethod = targetMethod.GetMethodDefinition();
            if (uninstantiatedType != objectType)
            {
                targetMethod = uninstantiatedType.FindMethodOnTypeWithMatchingTypicalMethod(targetMethod);
            }

            // Step 3, find unification group of target method
            UnificationGroup group = new UnificationGroup(FindSlotDefiningMethodForVirtualMethod(targetMethod));

            FindBaseUnificationGroup(uninstantiatedType, group);

            // Step 4, name/sig match virtual function resolve
            MethodDesc resolutionTarget = FindNameSigOverrideForVirtualMethod(group.DefiningMethod, uninstantiatedType);

            if (resolutionTarget == null)
            {
                return(null);
            }

            // Step 5, convert resolution target from uninstantiated form target to objecttype target,
            // and instantiate as appropriate
            if (uninstantiatedType != objectType)
            {
                resolutionTarget = objectType.FindMethodOnTypeWithMatchingTypicalMethod(resolutionTarget);
            }
            if (initialTargetMethod.HasInstantiation)
            {
                resolutionTarget = resolutionTarget.MakeInstantiatedMethod(initialTargetMethod.Instantiation);
            }

            return(resolutionTarget);
        }
 public FieldForInstantiatedTypeKey(FieldDesc fieldDef, InstantiatedType instantiatedType)
 {
     _fieldDef         = fieldDef;
     _instantiatedType = instantiatedType;
 }
 public MethodForInstantiatedTypeKey(MethodDesc typicalMethodDef, InstantiatedType instantiatedType)
 {
     _typicalMethodDef = typicalMethodDef;
     _instantiatedType = instantiatedType;
     _hashcode         = TypeHashingAlgorithms.ComputeMethodHashCode(instantiatedType.GetHashCode(), TypeHashingAlgorithms.ComputeNameHashCode(typicalMethodDef.Name));
 }
 // This constructor is a performance optimization - it allows supplying the hash code if it has already
 // been computed prior to the allocation of this type. The supplied hash code still has to match the
 // hash code this type would compute on it's own (and we assert to enforce that).
 internal MethodForInstantiatedType(MethodDesc typicalMethodDef, InstantiatedType instantiatedType, int hashcode)
     : this(typicalMethodDef, instantiatedType)
 {
     SetHashCode(hashcode);
 }
 internal MethodForInstantiatedType(MethodDesc typicalMethodDef, InstantiatedType instantiatedType)
 {
     _typicalMethodDef = typicalMethodDef;
     _instantiatedType = instantiatedType;
 }
 // This constructor is a performance optimization - it allows supplying the hash code if it has already
 // been computed prior to the allocation of this type. The supplied hash code still has to match the
 // hash code this type would compute on it's own (and we assert to enforce that).
 internal MethodForInstantiatedType(MethodDesc typicalMethodDef, InstantiatedType instantiatedType, int hashcode)
     : this(typicalMethodDef, instantiatedType)
 {
     SetHashCode(hashcode);
 }
 internal MethodForInstantiatedType(MethodDesc typicalMethodDef, InstantiatedType instantiatedType)
 {
     _typicalMethodDef = typicalMethodDef;
     _instantiatedType = instantiatedType;
 }
Beispiel #11
0
 internal FieldForInstantiatedType(FieldDesc fieldDef, InstantiatedType instantiatedType)
 {
     Debug.Assert(fieldDef.GetTypicalFieldDefinition() == fieldDef);
     _fieldDef         = fieldDef;
     _instantiatedType = instantiatedType;
 }
Beispiel #12
0
 internal MethodForInstantiatedType(MethodDesc typicalMethodDef, InstantiatedType instantiatedType)
 {
     Debug.Assert(typicalMethodDef.GetTypicalMethodDefinition() == typicalMethodDef);
     _typicalMethodDef = typicalMethodDef;
     _instantiatedType = instantiatedType;
 }
Beispiel #13
0
 public string FormatName(InstantiatedType type)
 {
     StringBuilder sb = new StringBuilder();
     AppendNameForInstantiatedType(sb, type);
     return sb.ToString();
 }
 internal FieldForInstantiatedType(FieldDesc fieldDef, InstantiatedType instantiatedType)
 {
     _fieldDef = fieldDef;
     _instantiatedType = instantiatedType;
 }
 public FieldDesc GetFieldForInstantiatedType(FieldDesc fieldDef, InstantiatedType instantiatedType)
 {
     return(_fieldForInstantiatedTypes.GetOrCreateValue(new FieldForInstantiatedTypeKey(fieldDef, instantiatedType)));
 }
 internal FieldForInstantiatedType(FieldDesc fieldDef, InstantiatedType instantiatedType)
 {
     _fieldDef         = fieldDef;
     _instantiatedType = instantiatedType;
 }
Beispiel #17
0
 public MethodForInstantiatedTypeKey(MethodDesc typicalMethodDef, InstantiatedType instantiatedType)
 {
     _typicalMethodDef = typicalMethodDef;
     _instantiatedType = instantiatedType;
 }