Ejemplo n.º 1
0
        public static TypeNode NewEqualTypeParameter(Duplicator dup, ITypeParameter itp, TypeNode declaringType, int index)
        {
            ClassParameter cp = itp as ClassParameter;
            if (cp != null)
            {
                ClassParameter mcp = new ClassParameter();
                
                mcp.Interfaces = dup.VisitInterfaceReferenceList(cp.Interfaces);
                mcp.BaseClass = cp.BaseClass;
                
                mcp.TypeParameterFlags = cp.TypeParameterFlags & ~TypeParameterFlags.VarianceMask;
                mcp.DeclaringType = declaringType;
                mcp.DeclaringModule = declaringType.DeclaringModule;
                
                mcp.Name = cp.Name;
                mcp.ParameterListIndex = index;
                mcp.DeclaringMember = declaringType;

                return mcp;
            }

            TypeParameter tp = itp as TypeParameter;
            if (tp != null)
            {
                TypeParameter mp = new TypeParameter();

                mp.Interfaces = dup.VisitInterfaceReferenceList(tp.Interfaces);
                mp.TypeParameterFlags = tp.TypeParameterFlags & ~TypeParameterFlags.VarianceMask;
                
                mp.DeclaringType = declaringType;
                mp.DeclaringModule = declaringType.DeclaringModule;
                
                mp.Name = tp.Name;
                mp.ParameterListIndex = index;
                mp.DeclaringMember = declaringType;

                return mp;
            }

            throw new NotImplementedException("unexpected type parameter kind");
        }
Ejemplo 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();
                result.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 ? (Class)baseType : 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;
        }
Ejemplo n.º 3
0
 public override TypeNode VisitTypeParameter(TypeNode typeParameter)
 {
     if(typeParameter == null)
         return null;
     TypeNode result = (TypeNode)this.DuplicateFor[typeParameter.UniqueKey];
     if(result != null)
         return result;
     MethodTypeParameter mtp = typeParameter as MethodTypeParameter;
     if(mtp != null)
     {
         TypeParameter tp = new TypeParameter();
         this.DuplicateFor[typeParameter.UniqueKey] = tp;
         tp.Name = mtp.Name;
         tp.Interfaces = this.VisitInterfaceReferenceList(mtp.Interfaces);
         tp.TypeParameterFlags = mtp.TypeParameterFlags;
         tp.DeclaringModule = mtp.DeclaringModule;
         tp.DeclaringMember = this.TargetType;
         result = tp;
     }
     else
     {
         MethodClassParameter mcp = typeParameter as MethodClassParameter;
         if(mcp != null)
         {
             ClassParameter cp = new ClassParameter();
             this.DuplicateFor[typeParameter.UniqueKey] = cp;
             cp.Name = mcp.Name;
             cp.BaseClass = (Class)this.VisitTypeReference(mcp.BaseClass);
             cp.Interfaces = this.VisitInterfaceReferenceList(mcp.Interfaces);
             cp.TypeParameterFlags = mcp.TypeParameterFlags;
             cp.DeclaringModule = mcp.DeclaringModule;
             cp.DeclaringMember = this.TargetType;
             result = cp;
         }
     }
     if(result == null)
         return typeParameter;
     return result;
 }