Exemple #1
0
 private ClassParameter ConvertToClassParameter(TypeNode typeParameter, InterfaceList interfaces, Class baseClass, ClassExpression cExpr){
   ClassParameter cParam = typeParameter is MethodTypeParameter ? new MethodClassParameter() : new ClassParameter();
   this.typeParamToClassParamMap[typeParameter.UniqueKey] = cParam;
   cParam.SourceContext = typeParameter.SourceContext;
   cParam.TypeParameterFlags = ((ITypeParameter)typeParameter).TypeParameterFlags;
   if (typeParameter.IsUnmanaged) { cParam.SetIsUnmanaged(); }
   cParam.Name = typeParameter.Name;
   cParam.Namespace = StandardIds.ClassParameter;
   cParam.BaseClass = baseClass == null ? SystemTypes.Object : baseClass;
   cParam.BaseClassExpression = cExpr;
   cParam.DeclaringMember = ((ITypeParameter)typeParameter).DeclaringMember;
   cParam.DeclaringModule = typeParameter.DeclaringModule;
   cParam.DeclaringType = typeParameter is MethodTypeParameter ? null : typeParameter.DeclaringType;
   cParam.Flags = typeParameter.Flags & ~TypeFlags.Interface;
   cParam.ParameterListIndex = ((ITypeParameter)typeParameter).ParameterListIndex;
   MemberList mems = cParam.DeclaringType == null ? null : cParam.DeclaringType.Members;
   int n = mems == null ? 0 : mems.Count;
   for (int i = 0; i < n; i++){
     if ((mems[i] as TypeNode) == typeParameter){
       mems[i] = cParam;
       break;
     }
   }
   if (cExpr != null){
     n = interfaces.Count - 1;
     InterfaceList actualInterfaces = new InterfaceList(n);
     for (int i = 0; i < n; i++)
       actualInterfaces.Add(interfaces[i + 1]);
     cParam.Interfaces = actualInterfaces;
   }else
     cParam.Interfaces = interfaces;
   if (cExpr != null) cParam.BaseClass = this.VisitClassExpression(cExpr);
   return cParam;
 }
Exemple #2
0
 public override TypeNode VisitTypeParameter(TypeNode typeParameter){
   if (typeParameter == null) return null;
   InterfaceList interfaces = typeParameter.Interfaces;
   if (interfaces != null && interfaces.Count > 0){
     Class baseClass = null;
     ClassExpression cExpr = null;
     Interface iface = interfaces[0];
     InterfaceExpression ifExpr = iface as InterfaceExpression;
     if (ifExpr != null && ifExpr.Expression != null){
       cExpr = new ClassExpression(ifExpr.Expression, ifExpr.TemplateArguments, ifExpr.Expression.SourceContext);
       baseClass = this.VisitClassExpression(cExpr);
       if (baseClass != null && baseClass.Name == Looker.NotFound){
         baseClass = null; cExpr = null;
       }else if (baseClass == null) {
         TypeParameter tp = this.LookupType(ifExpr.Expression, false, 0) as TypeParameter;
         if (tp != null && (tp.TypeParameterFlags & TypeParameterFlags.ReferenceTypeConstraint) != 0)
           baseClass = cExpr;
         else if ((((ITypeParameter)typeParameter).TypeParameterFlags & TypeParameterFlags.ReferenceTypeConstraint) != 0) {
           baseClass = SystemTypes.Object; cExpr = null;
         } else if ((((ITypeParameter)typeParameter).TypeParameterFlags & TypeParameterFlags.ValueTypeConstraint) != 0) {
           baseClass = SystemTypes.ValueType; cExpr = null;
         } else {
           cExpr = null;
         }
       }
     }
     if (baseClass != null)
       typeParameter = this.ConvertToClassParameter(typeParameter, interfaces, baseClass, cExpr);
     else if ((((ITypeParameter)typeParameter).TypeParameterFlags & TypeParameterFlags.ValueTypeConstraint) != 0)
       typeParameter = this.ConvertToClassParameter(typeParameter, interfaces, SystemTypes.ValueType, null);
   }else if ((((ITypeParameter)typeParameter).TypeParameterFlags & TypeParameterFlags.ReferenceTypeConstraint) != 0)
     typeParameter = this.ConvertToClassParameter(typeParameter, interfaces, null, null);
   else if ((((ITypeParameter)typeParameter).TypeParameterFlags & TypeParameterFlags.ValueTypeConstraint) != 0)
     typeParameter = this.ConvertToClassParameter(typeParameter, interfaces, SystemTypes.ValueType, null);
   return typeParameter;
 }