Example #1
0
        public override TypeNode VisitTypeReference(TypeNode type)
        { //TODO: break up this method
            if (type == null)
            {
                return(null);
            }
            TypeNodeList pars = this.pars;
            TypeNodeList args = this.args;

            switch (type.NodeType)
            {
            case NodeType.ArrayType:
                ArrayType arrType  = (ArrayType)type;
                TypeNode  elemType = this.VisitTypeReference(arrType.ElementType);
                if (elemType == arrType.ElementType || elemType == null)
                {
                    return(arrType);
                }
                if (arrType.IsSzArray())
                {
                    return(elemType.GetArrayType(1));
                }
                return(elemType.GetArrayType(arrType.Rank, arrType.Sizes, arrType.LowerBounds));

            case NodeType.DelegateNode:
            {
                FunctionType ftype = type as FunctionType;
                if (ftype == null)
                {
                    goto default;
                }
                TypeNode referringType = ftype.DeclaringType == null ? this.CurrentType : this.VisitTypeReference(ftype.DeclaringType);
                return(FunctionType.For(this.VisitTypeReference(ftype.ReturnType), this.VisitParameterList(ftype.Parameters), referringType));
            }

            case NodeType.Pointer:
                Pointer pType = (Pointer)type;
                elemType = this.VisitTypeReference(pType.ElementType);
                if (elemType == pType.ElementType || elemType == null)
                {
                    return(pType);
                }
                return(elemType.GetPointerType());

            case NodeType.Reference:
                Reference rType = (Reference)type;
                elemType = this.VisitTypeReference(rType.ElementType);
                if (elemType == rType.ElementType || elemType == null)
                {
                    return(rType);
                }
                return(elemType.GetReferenceType());

            case NodeType.ArrayTypeExpression:
                ArrayTypeExpression aExpr = (ArrayTypeExpression)type;
                aExpr.ElementType = this.VisitTypeReference(aExpr.ElementType);
                return(aExpr);

            case NodeType.BoxedTypeExpression:
                BoxedTypeExpression bExpr = (BoxedTypeExpression)type;
                bExpr.ElementType = this.VisitTypeReference(bExpr.ElementType);
                return(bExpr);

            case NodeType.ClassExpression:
            {
                ClassExpression cExpr = (ClassExpression)type;
                cExpr.Expression = this.VisitTypeExpression(cExpr.Expression);

                //Could happen if the expression is a template parameter
                if (cExpr.Expression is Literal lit)
                {
                    return(lit.Value as TypeNode);
                }

                cExpr.TemplateArguments = this.VisitTypeReferenceList(cExpr.TemplateArguments);
                return(cExpr);
            }

            case NodeType.ClassParameter:
            case NodeType.TypeParameter:
                int key = type.UniqueKey;
                for (int i = 0, n = pars == null ? 0 : pars.Count, m = args == null ? 0 : args.Count; i < n && i < m; i++)
                {
                    //^ assert pars != null && args != null;
                    TypeNode tp = pars[i];
                    if (tp == null)
                    {
                        continue;
                    }
                    if (tp.UniqueKey == key)
                    {
                        return(args[i]);
                    }
                    if (tp.Name.UniqueIdKey == type.Name.UniqueIdKey && (tp is ClassParameter && type is TypeParameter))
                    {
                        //This shouldn't really happen, but in practice it does. Hack past it.
                        return(args[i]);
                    }
                }
                return(type);

            case NodeType.FlexArrayTypeExpression:
                FlexArrayTypeExpression flExpr = (FlexArrayTypeExpression)type;
                flExpr.ElementType = this.VisitTypeReference(flExpr.ElementType);
                return(flExpr);

            case NodeType.FunctionTypeExpression:
                FunctionTypeExpression ftExpr = (FunctionTypeExpression)type;
                ftExpr.Parameters = this.VisitParameterList(ftExpr.Parameters);
                ftExpr.ReturnType = this.VisitTypeReference(ftExpr.ReturnType);
                return(ftExpr);

            case NodeType.InvariantTypeExpression:
                InvariantTypeExpression invExpr = (InvariantTypeExpression)type;
                invExpr.ElementType = this.VisitTypeReference(invExpr.ElementType);
                return(invExpr);

            case NodeType.InterfaceExpression:
                InterfaceExpression iExpr = (InterfaceExpression)type;
                if (iExpr.Expression == null)
                {
                    goto default;
                }
                iExpr.Expression        = this.VisitTypeExpression(iExpr.Expression);
                iExpr.TemplateArguments = this.VisitTypeReferenceList(iExpr.TemplateArguments);
                return(iExpr);

            case NodeType.NonEmptyStreamTypeExpression:
                NonEmptyStreamTypeExpression neExpr = (NonEmptyStreamTypeExpression)type;
                neExpr.ElementType = this.VisitTypeReference(neExpr.ElementType);
                return(neExpr);

            case NodeType.NonNullTypeExpression:
                NonNullTypeExpression nnExpr = (NonNullTypeExpression)type;
                nnExpr.ElementType = this.VisitTypeReference(nnExpr.ElementType);
                return(nnExpr);

            case NodeType.NonNullableTypeExpression:
                NonNullableTypeExpression nbExpr = (NonNullableTypeExpression)type;
                nbExpr.ElementType = this.VisitTypeReference(nbExpr.ElementType);
                return(nbExpr);

            case NodeType.NullableTypeExpression:
                NullableTypeExpression nuExpr = (NullableTypeExpression)type;
                nuExpr.ElementType = this.VisitTypeReference(nuExpr.ElementType);
                return(nuExpr);

            case NodeType.OptionalModifier:
            {
                TypeModifier modType      = (TypeModifier)type;
                TypeNode     modifiedType = this.VisitTypeReference(modType.ModifiedType);
                TypeNode     modifierType = this.VisitTypeReference(modType.Modifier);
                if (modifiedType == null || modifierType == null)
                {
                    return(type);
                }

                return(OptionalModifier.For(modifierType, modifiedType));
            }

            case NodeType.RequiredModifier:
            {
                TypeModifier modType      = (TypeModifier)type;
                TypeNode     modifiedType = this.VisitTypeReference(modType.ModifiedType);
                TypeNode     modifierType = this.VisitTypeReference(modType.Modifier);
                if (modifiedType == null || modifierType == null)
                {
                    Debug.Fail(""); return(type);
                }
                return(RequiredModifier.For(modifierType, modifiedType));
            }

            case NodeType.OptionalModifierTypeExpression:
                OptionalModifierTypeExpression optmodType = (OptionalModifierTypeExpression)type;
                optmodType.ModifiedType = this.VisitTypeReference(optmodType.ModifiedType);
                optmodType.Modifier     = this.VisitTypeReference(optmodType.Modifier);
                return(optmodType);

            case NodeType.RequiredModifierTypeExpression:
                RequiredModifierTypeExpression reqmodType = (RequiredModifierTypeExpression)type;
                reqmodType.ModifiedType = this.VisitTypeReference(reqmodType.ModifiedType);
                reqmodType.Modifier     = this.VisitTypeReference(reqmodType.Modifier);
                return(reqmodType);

            case NodeType.PointerTypeExpression:
                PointerTypeExpression pExpr = (PointerTypeExpression)type;
                pExpr.ElementType = this.VisitTypeReference(pExpr.ElementType);
                return(pExpr);

            case NodeType.ReferenceTypeExpression:
                ReferenceTypeExpression rExpr = (ReferenceTypeExpression)type;
                rExpr.ElementType = this.VisitTypeReference(rExpr.ElementType);
                return(rExpr);

            case NodeType.StreamTypeExpression:
                StreamTypeExpression sExpr = (StreamTypeExpression)type;
                sExpr.ElementType = this.VisitTypeReference(sExpr.ElementType);
                return(sExpr);

            case NodeType.TupleTypeExpression:
                TupleTypeExpression tuExpr = (TupleTypeExpression)type;
                tuExpr.Domains = this.VisitFieldList(tuExpr.Domains);
                return(tuExpr);

            case NodeType.TypeExpression:
            {
                TypeExpression tExpr = (TypeExpression)type;
                tExpr.Expression = this.VisitTypeExpression(tExpr.Expression);
                if (tExpr.Expression is Literal)
                {
                    return(type);
                }
                tExpr.TemplateArguments = this.VisitTypeReferenceList(tExpr.TemplateArguments);
                return(tExpr);
            }

            case NodeType.TypeIntersectionExpression:
                TypeIntersectionExpression tiExpr = (TypeIntersectionExpression)type;
                tiExpr.Types = this.VisitTypeReferenceList(tiExpr.Types);
                return(tiExpr);

            case NodeType.TypeUnionExpression:
                TypeUnionExpression tyuExpr = (TypeUnionExpression)type;
                tyuExpr.Types = this.VisitTypeReferenceList(tyuExpr.Types);
                return(tyuExpr);

            default:
                TypeNode declaringType = this.VisitTypeReference(type.DeclaringType);
                if (declaringType != null)
                {
                    Identifier tname = type.Name;
                    if (type.Template != null && type.IsGeneric)
                    {
                        tname = type.Template.Name;
                    }
                    TypeNode nt = declaringType.GetNestedType(tname);
                    if (nt != null)
                    {
                        TypeNodeList arguments = type.TemplateArguments;
                        type = nt;
                        if (TargetPlatform.UseGenerics)
                        {
                            if (arguments != null && arguments.Count > 0 && nt.ConsolidatedTemplateParameters != null && nt.ConsolidatedTemplateParameters.Count > 0)
                            {
                                type = nt.GetTemplateInstance(this.TargetModule, this.CurrentType, declaringType, arguments);
                            }
                        }
                    }
                }

                if (type.Template != null && (type.ConsolidatedTemplateParameters == null || type.ConsolidatedTemplateParameters.Count == 0))
                {
                    if (!type.IsNotFullySpecialized && (!type.IsNormalized ||
                                                        (this.CurrentType != null && type.DeclaringModule == this.CurrentType.DeclaringModule)))
                    {
                        return(type);
                    }

                    // Type is a template instance, but some of its arguments were themselves parameters.
                    // See if any of these parameters are to be specialized by this specializer.
                    bool         mustSpecializeFurther = false;
                    TypeNodeList targs   = type.TemplateArguments;
                    int          numArgs = targs == null ? 0 : targs.Count;

                    if (targs != null)
                    {
                        targs = new TypeNodeList(targs);

                        for (int i = 0; i < numArgs; i++)
                        {
                            TypeNode targ = targs[i];

                            if (targ is ITypeParameter tparg)
                            {
                                for (int j = 0, np = pars == null ? 0 : pars.Count, m = args == null ? 0 : args.Count; j < np && j < m; j++)
                                {
                                    //^ assert pars != null && args != null;
                                    if (TargetPlatform.UseGenerics)
                                    {
                                        if (!(pars[j] is ITypeParameter par))
                                        {
                                            continue;
                                        }

                                        if (tparg == par || (tparg.ParameterListIndex == par.ParameterListIndex && tparg.DeclaringMember == par.DeclaringMember))
                                        {
                                            targ = this.args[j];
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        if (targ == pars[j])
                                        {
                                            targ = this.args[j];
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (targ != type)
                                {
                                    targ = this.VisitTypeReference(targ);
                                }

                                if (targ == type)
                                {
                                    continue;
                                }
                            }

                            mustSpecializeFurther |= targs[i] != targ;
                            targs[i] = targ;
                        }
                    }

                    if (targs == null || !mustSpecializeFurther)
                    {
                        return(type);
                    }

                    return(type.Template.GetTemplateInstance(this.TargetModule, this.CurrentType, declaringType, targs));
                }

                TypeNodeList tPars = type.TemplateParameters;
                if (tPars == null || tPars.Count == 0)
                {
                    return(type);                                       //Not a parameterized type. No need to get an instance.
                }
                TypeNodeList tArgs = new TypeNodeList();
                for (int i = 0, n = tPars.Count; i < n; i++)
                {
                    TypeNode tPar = tPars[i];
                    tArgs.Add(tPar);     //Leave parameter in place if there is no match
                    if (tPar == null || tPar.Name == null)
                    {
                        continue;
                    }
                    int idKey = tPar.Name.UniqueIdKey;
                    for (int j = 0, m = pars == null ? 0 : pars.Count, k = args == null ? 0 : args.Count; j < m && j < k; j++)
                    {
                        //^ assert pars != null && args != null;
                        TypeNode par = pars[j];
                        if (par == null || par.Name == null)
                        {
                            continue;
                        }
                        if (par.Name.UniqueIdKey == idKey)
                        {
                            tArgs[i] = args[j];
                            break;
                        }
                    }
                }
                return(type.GetTemplateInstance(this.TargetModule, this.CurrentType, this.VisitTypeReference(type.DeclaringType), tArgs));
            }
        }
Example #2
0
        public override TypeNode VisitTypeReference(TypeNode type)
        {
            if (type == null)
            {
                return(null);
            }
            Class cl = type as Class;

            if (cl != null)
            {
                this.VisitTypeReference(cl.BaseClass);
            }
            if (this.MembersToFind[type.UniqueKey] != null)
            {
                this.FoundMembers[type.UniqueKey] = type;
                if (!this.insideMethodBody)
                {
                    this.AllReferencesAreConfinedToMethodBodies = false;
                }
                return(type);
            }
            switch (type.NodeType)
            {
            case NodeType.ArrayType:
                ArrayType arrType = (ArrayType)type;
                this.VisitTypeReference(arrType.ElementType);
                return(type);

            case NodeType.DelegateNode: {
                FunctionType ftype = type as FunctionType;
                if (ftype == null)
                {
                    goto default;
                }
                this.VisitTypeReference(ftype.ReturnType);
                this.VisitParameterList(ftype.Parameters);
                return(type);
            }

            case NodeType.Pointer:
                Pointer pType = (Pointer)type;
                this.VisitTypeReference(pType.ElementType);
                return(type);

            case NodeType.Reference:
                Reference rType = (Reference)type;
                this.VisitTypeReference(rType.ElementType);
                return(type);

            case NodeType.TupleType: {
                TupleType  tType   = (TupleType)type;
                MemberList members = tType.Members;
                int        n       = members == null ? 0 : members.Count;
                for (int i = 0; i < n; i++)
                {
                    Field f = members[i] as Field;
                    if (f == null)
                    {
                        continue;
                    }
                    this.VisitTypeReference(f.Type);
                }
                return(type);
            }

            case NodeType.TypeIntersection:
                TypeIntersection tIntersect = (TypeIntersection)type;
                this.VisitTypeReferenceList(tIntersect.Types);
                return(type);

            case NodeType.TypeUnion:
                TypeUnion tUnion = (TypeUnion)type;
                this.VisitTypeReferenceList(tUnion.Types);
                return(type);

            case NodeType.ArrayTypeExpression:
                ArrayTypeExpression aExpr = (ArrayTypeExpression)type;
                this.VisitTypeReference(aExpr.ElementType);
                return(type);

            case NodeType.BoxedTypeExpression:
                BoxedTypeExpression bExpr = (BoxedTypeExpression)type;
                this.VisitTypeReference(bExpr.ElementType);
                return(type);

            case NodeType.ClassExpression:
                ClassExpression cExpr = (ClassExpression)type;
                this.VisitExpression(cExpr.Expression);
                this.VisitTypeReferenceList(cExpr.TemplateArguments);
                return(type);

            case NodeType.ClassParameter:
            case NodeType.TypeParameter:
                return(type);

            case NodeType.ConstrainedType:
                ConstrainedType conType = (ConstrainedType)type;
                this.VisitTypeReference(conType.UnderlyingType);
                this.VisitExpression(conType.Constraint);
                return(type);

            case NodeType.FlexArrayTypeExpression:
                FlexArrayTypeExpression flExpr = (FlexArrayTypeExpression)type;
                this.VisitTypeReference(flExpr.ElementType);
                return(type);

            case NodeType.FunctionTypeExpression:
                FunctionTypeExpression ftExpr = (FunctionTypeExpression)type;
                this.VisitParameterList(ftExpr.Parameters);
                this.VisitTypeReference(ftExpr.ReturnType);
                return(type);

            case NodeType.InvariantTypeExpression:
                InvariantTypeExpression invExpr = (InvariantTypeExpression)type;
                this.VisitTypeReference(invExpr.ElementType);
                return(type);

            case NodeType.InterfaceExpression:
                InterfaceExpression iExpr = (InterfaceExpression)type;
                this.VisitExpression(iExpr.Expression);
                this.VisitTypeReferenceList(iExpr.TemplateArguments);
                return(type);

            case NodeType.NonEmptyStreamTypeExpression:
                NonEmptyStreamTypeExpression neExpr = (NonEmptyStreamTypeExpression)type;
                this.VisitTypeReference(neExpr.ElementType);
                return(type);

            case NodeType.NonNullTypeExpression:
                NonNullTypeExpression nnExpr = (NonNullTypeExpression)type;
                this.VisitTypeReference(nnExpr.ElementType);
                return(type);

            case NodeType.NonNullableTypeExpression:
                NonNullableTypeExpression nbExpr = (NonNullableTypeExpression)type;
                this.VisitTypeReference(nbExpr.ElementType);
                return(type);

            case NodeType.NullableTypeExpression:
                NullableTypeExpression nuExpr = (NullableTypeExpression)type;
                this.VisitTypeReference(nuExpr.ElementType);
                return(type);

            case NodeType.OptionalModifier:
            case NodeType.RequiredModifier:
                TypeModifier modType = (TypeModifier)type;
                this.VisitTypeReference(modType.ModifiedType);
                this.VisitTypeReference(modType.Modifier);
                return(type);

            case NodeType.PointerTypeExpression:
                PointerTypeExpression pExpr = (PointerTypeExpression)type;
                this.VisitTypeReference(pExpr.ElementType);
                return(type);

            case NodeType.ReferenceTypeExpression:
                ReferenceTypeExpression rExpr = (ReferenceTypeExpression)type;
                this.VisitTypeReference(rExpr.ElementType);
                return(type);

            case NodeType.StreamTypeExpression:
                StreamTypeExpression sExpr = (StreamTypeExpression)type;
                this.VisitTypeReference(sExpr.ElementType);
                return(type);

            case NodeType.TupleTypeExpression:
                TupleTypeExpression tuExpr = (TupleTypeExpression)type;
                this.VisitFieldList(tuExpr.Domains);
                return(type);

            case NodeType.TypeExpression:
                TypeExpression tExpr = (TypeExpression)type;
                this.VisitExpression(tExpr.Expression);
                this.VisitTypeReferenceList(tExpr.TemplateArguments);
                return(type);

            case NodeType.TypeIntersectionExpression:
                TypeIntersectionExpression tiExpr = (TypeIntersectionExpression)type;
                this.VisitTypeReferenceList(tiExpr.Types);
                return(type);

            case NodeType.TypeUnionExpression:
                TypeUnionExpression tyuExpr = (TypeUnionExpression)type;
                this.VisitTypeReferenceList(tyuExpr.Types);
                return(type);

            default:
                if (type.Template != null && type.TemplateArguments != null)
                {
                    this.VisitTypeReference(type.Template);
                    this.VisitTypeReferenceList(type.TemplateArguments);
                }
                return(type);
            }
        }
Example #3
0
 protected virtual MemberList GetMembers(int line, int col, InterfaceExpression iExpr, Scope scope) {
   MemberList members = this.languageService.GetTypesNamespacesAndPrefixes(scope, false, false);
   if (members == null) return null;
   return this.GetInterfacesAndNamespacesThatContainThem(scope, members);
 }
Example #4
0
 private TypeNode ParseTypeSignature(MemoryCursor/*!*/ sigReader, ref bool pinned, ref bool isTypeArgument)
 {
     TypeNode elementType;
     ElementType tok = (ElementType)sigReader.ReadCompressedInt();
     if (tok == ElementType.Pinned)
     {
         pinned = true;
         tok = (ElementType)sigReader.ReadCompressedInt();
     }
     switch (tok)
     {
         case ElementType.Boolean: return CoreSystemTypes.Boolean;
         case ElementType.Char: return CoreSystemTypes.Char;
         case ElementType.Double: return CoreSystemTypes.Double;
         case ElementType.Int16: return CoreSystemTypes.Int16;
         case ElementType.Int32: return CoreSystemTypes.Int32;
         case ElementType.Int64: return CoreSystemTypes.Int64;
         case ElementType.Int8: return CoreSystemTypes.Int8;
         case ElementType.IntPtr: return CoreSystemTypes.IntPtr;
         case ElementType.BoxedEnum:
         case ElementType.Object: return CoreSystemTypes.Object;
         case ElementType.Single: return CoreSystemTypes.Single;
         case ElementType.String: return CoreSystemTypes.String;
         case ElementType.DynamicallyTypedReference: return CoreSystemTypes.DynamicallyTypedReference;
         case ElementType.UInt16: return CoreSystemTypes.UInt16;
         case ElementType.UInt32: return CoreSystemTypes.UInt32;
         case ElementType.UInt64: return CoreSystemTypes.UInt64;
         case ElementType.UInt8: return CoreSystemTypes.UInt8;
         case ElementType.UIntPtr: return CoreSystemTypes.UIntPtr;
         case ElementType.Void: return CoreSystemTypes.Void;
         case ElementType.Pointer:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             if (elementType == null) return null;
             return elementType.GetPointerType();
         case ElementType.Reference:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             return elementType.GetReferenceType();
         case ElementType.FunctionPointer:
             return this.ParseFunctionPointer(sigReader);
         case ElementType.OptionalModifier:
         case ElementType.RequiredModifier:
             TypeNode modifier = this.DecodeAndGetTypeDefOrRefOrSpec(sigReader.ReadCompressedInt());
             if (modifier == null) modifier = CoreSystemTypes.Object;
             TypeNode modified = this.ParseTypeSignature(sigReader, ref pinned);
             if (modified == null) modified = CoreSystemTypes.Object;
             if (modified == null || modified == null) return null;
             if (tok == ElementType.RequiredModifier)
                 return RequiredModifier.For(modifier, modified);
             else
                 return OptionalModifier.For(modifier, modified);
         case ElementType.Class:
             return this.DecodeAndGetTypeDefOrRefOrSpec(sigReader.ReadCompressedInt());
         case ElementType.ValueType:
             return this.DecodeAndGetTypeDefOrRefOrSpec(sigReader.ReadCompressedInt(), true);
         case ElementType.TypeParameter:
             TypeNode tPar = null;
             int pnum = sigReader.ReadCompressedInt();
             if (this.currentTypeParameters != null && this.currentTypeParameters.Count > pnum)
                 tPar = this.currentTypeParameters[pnum];
             if (tPar == null)
             {
                 HandleError(this.module, String.Format(CultureInfo.CurrentCulture,
                     ExceptionStrings.BadTypeParameterInPositionForType, pnum, this.currentType == null ? "" : this.currentType.FullName));
                 tPar = new TypeParameter();
                 tPar.Name = Identifier.For("Bad type parameter in position " + pnum);
                 tPar.DeclaringModule = this.module;
             }
             isTypeArgument = true;
             return tPar;
         case ElementType.MethodParameter:
             TypeNode mTPar = null;
             pnum = sigReader.ReadCompressedInt();
             if (this.currentMethodTypeParameters != null && this.currentMethodTypeParameters.Count > pnum)
                 mTPar = this.currentMethodTypeParameters[pnum];
             if (mTPar == null)
             {
                 HandleError(this.module, String.Format(CultureInfo.CurrentCulture,
                     ExceptionStrings.BadMethodTypeParameterInPosition, pnum));
                 mTPar = new MethodTypeParameter();
                 mTPar.Name = Identifier.For("Bad method type parameter in position " + pnum);
             }
             isTypeArgument = true;
             return mTPar;
         case ElementType.GenericTypeInstance:
             TypeNodeList savedCurrentTypeParameters = this.currentTypeParameters;
             TypeNode template = this.ParseTypeSignature(sigReader, ref pinned);
             this.currentTypeParameters = savedCurrentTypeParameters;
             if (template == null || template.ConsolidatedTemplateParameters == null) return template; //Likely a dummy type
             if (CoreSystemTypes.Initialized)
             {
                 if (this.currentTypeParameters == null || this.currentTypeParameters.Count == 0)
                     this.currentTypeParameters = template.ConsolidatedTemplateParameters;
                 TypeNodeList genArgs = this.ParseTypeList(sigReader);
                 if (this.module == null) return null;
                 TypeNode genInst = template.GetGenericTemplateInstance(this.module, genArgs);
                 this.currentTypeParameters = savedCurrentTypeParameters;
                 return genInst;
             }
             InterfaceExpression ifaceExpr = new InterfaceExpression(null);
             ifaceExpr.Template = template;
             ifaceExpr.Namespace = template.Namespace;
             ifaceExpr.Name = template.Name;
             ifaceExpr.TemplateArguments = this.ParseTypeList(sigReader);
             this.currentTypeParameters = savedCurrentTypeParameters;
             return ifaceExpr;
         case ElementType.SzArray:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             if (elementType == null) return null;
             return elementType.GetArrayType(1);
         case ElementType.Array:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             if (elementType == null) return null;
             int rank = sigReader.ReadCompressedInt();
             int numSizes = sigReader.ReadCompressedInt();
             int[] sizes = new int[numSizes];
             for (int i = 0; i < numSizes; i++) sizes[i] = sigReader.ReadCompressedInt();
             int numLoBounds = sigReader.ReadCompressedInt();
             int[] loBounds = new int[numLoBounds];
             for (int i = 0; i < numLoBounds; i++) loBounds[i] = sigReader.ReadCompressedInt();
             return elementType.GetArrayType(rank, numSizes, numLoBounds, sizes, loBounds);
         case ElementType.Sentinel: return null;
         case ElementType.Type: return CoreSystemTypes.Type;
         case ElementType.Enum: return this.GetTypeFromSerializedName(ReadSerString(sigReader));
     }
     throw new InvalidMetadataException(ExceptionStrings.MalformedSignature);
 }
 public virtual Interface LookupInterface(InterfaceExpression iexpr){
   if (iexpr == null) return null;
   iexpr.TemplateArguments = this.VisitTypeReferenceList(iexpr.TemplateArguments);
   int numTemplArgs = iexpr.TemplateArgumentExpressions == null ? 0 : iexpr.TemplateArgumentExpressions.Count;
   TypeNode t = this.LookupType(iexpr.Expression, false, numTemplArgs);
   if (t == null){
     this.HandleTypeExpected(iexpr.Expression);
     return null;
   }
   Interface i = t as Interface;
   if (i != null){
     if (iexpr.TemplateArguments != null){           
       for (int j = 0, n = iexpr.TemplateArguments.Count; j < n; j++){
         TypeNode arg = iexpr.TemplateArguments[j];
         if (arg == null) return null;
       }
       t = i.GetTemplateInstance(this.currentType, iexpr.TemplateArguments);
       t.TemplateExpression = iexpr;
       this.AddTemplateInstanceToList(t);
       return (Interface)t;
     }else
       return i;
   }
   this.HandleError(iexpr, Error.NotAnInterface, this.GetTypeName(t));
   this.HandleRelatedError(t);
   return null;
 }
Example #6
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);
        }