Esempio n. 1
0
 public override TypeNode VisitTypeParameter(TypeNode typeParameter)
 {
     if (typeParameter == null)
     {
         return(null);
     }
     if (TargetPlatform.UseGenerics)
     {
         InterfaceList interfaces = typeParameter.Interfaces;
         if (interfaces == null || interfaces.Count == 0)
         {
             return(typeParameter);
         }
         TypeNode baseType = this.VisitTypeReference(interfaces[0]);
         if (baseType is Interface)
         {
             typeParameter.Interfaces = this.VisitInterfaceReferenceList(typeParameter.Interfaces);
         }
         else
         {
             typeParameter = this.ConvertToClassParameter(baseType, typeParameter);
         }
         return(typeParameter);
     }
     else
     {
         typeParameter.Interfaces = this.VisitInterfaceReferenceList(typeParameter.Interfaces);
         return(null);
     }
 }
Esempio n. 2
0
        private TypeNode ConvertToClassParameter(TypeNode baseType, TypeNode /*!*/ typeParameter)
        {
            ClassParameter result;

            if (typeParameter is MethodTypeParameter)
            {
                result = new MethodClassParameter();
            }
            else if (typeParameter is TypeParameter)
            {
                result = new ClassParameter
                {
                    DeclaringType = typeParameter.DeclaringType
                };
            }
            else
            {
                return(typeParameter); //give up
            }
            result.SourceContext      = typeParameter.SourceContext;
            result.TypeParameterFlags = ((ITypeParameter)typeParameter).TypeParameterFlags;

            result.Name            = typeParameter.Name;
            result.Namespace       = StandardIds.ClassParameter;
            result.BaseClass       = baseType is Class c ? c : CoreSystemTypes.Object;
            result.DeclaringMember = ((ITypeParameter)typeParameter).DeclaringMember;
            result.DeclaringModule = typeParameter.DeclaringModule;
            result.Flags           = typeParameter.Flags & ~TypeFlags.Interface;

            //InterfaceList constraints = result.Interfaces = new InterfaceList();
            InterfaceList interfaces = typeParameter.Interfaces;

            for (int i = 1, n = interfaces == null ? 0 : interfaces.Count; i < n; i++)
            {
                //^ assert interfaces != null;
                interfaces.Add(this.VisitInterfaceReference(interfaces[i]));
            }
            return(result);
        }