private MethodSymbol LoadMethod( AggregateSymbol type, int[] signature, int cMethodTyVars, Name methodName, ACCESS methodAccess, bool isStatic, bool isVirtual ) { Debug.Assert(signature != null); Debug.Assert(cMethodTyVars >= 0); Debug.Assert(methodName != null); Debug.Assert(type != null); TypeArray classTyVars = type.GetTypeVarsAll(); int index = 0; CType returnType = LoadTypeFromSignature(signature, ref index, classTyVars); Debug.Assert(returnType != null); TypeArray argumentTypes = LoadTypeArrayFromSignature(signature, ref index, classTyVars); Debug.Assert(argumentTypes != null); MethodSymbol ret = LookupMethodWhileLoading(type, cMethodTyVars, methodName, methodAccess, isStatic, isVirtual, returnType, argumentTypes); if (ret == null) { RuntimeBinderSymbolTable.AddPredefinedMethodToSymbolTable(type, methodName); ret = LookupMethodWhileLoading(type, cMethodTyVars, methodName, methodAccess, isStatic, isVirtual, returnType, argumentTypes); } return(ret); }
public AggregateType GetAggregate(AggregateSymbol agg, TypeArray typeArgsAll) { Debug.Assert(typeArgsAll != null && typeArgsAll.Count == agg.GetTypeVarsAll().Count); if (typeArgsAll.Count == 0) { return(agg.getThisType()); } AggregateSymbol aggOuter = agg.GetOuterAgg(); if (aggOuter == null) { return(GetAggregate(agg, null, typeArgsAll)); } int cvarOuter = aggOuter.GetTypeVarsAll().Count; Debug.Assert(cvarOuter <= typeArgsAll.Count); TypeArray typeArgsOuter = _BSymmgr.AllocParams(cvarOuter, typeArgsAll, 0); TypeArray typeArgsInner = _BSymmgr.AllocParams(agg.GetTypeVars().Count, typeArgsAll, cvarOuter); AggregateType atsOuter = GetAggregate(aggOuter, typeArgsOuter); return(GetAggregate(agg, atsOuter, typeArgsInner)); }
////////////////////////////////////////////////////////////////////////////// private static bool HasVariantConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null); Debug.Assert(pDest != null); if (pSource == pDest) { return(true); } AggregateSymbol pAggSym = pSource.OwningAggregate; if (pAggSym != pDest.OwningAggregate) { return(false); } TypeArray pTypeParams = pAggSym.GetTypeVarsAll(); TypeArray pSourceArgs = pSource.TypeArgsAll; TypeArray pDestArgs = pDest.TypeArgsAll; Debug.Assert(pTypeParams.Count == pSourceArgs.Count); Debug.Assert(pTypeParams.Count == pDestArgs.Count); for (int iParam = 0; iParam < pTypeParams.Count; ++iParam) { CType pSourceArg = pSourceArgs[iParam]; CType pDestArg = pDestArgs[iParam]; // If they're identical then this one is automatically good, so skip it. if (pSourceArg == pDestArg) { continue; } TypeParameterType pParam = (TypeParameterType)pTypeParams[iParam]; if (pParam.Invariant) { return(false); } if (pParam.Covariant) { if (!HasImplicitReferenceConversion(pSourceArg, pDestArg)) { return(false); } } if (pParam.Contravariant) { if (!HasImplicitReferenceConversion(pDestArg, pSourceArg)) { return(false); } } } return(true); }
////////////////////////////////////////////////////////////////////////////// bool HasVariantConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null); Debug.Assert(pDest != null); if (pSource == pDest) { return(true); } AggregateSymbol pAggSym = pSource.getAggregate(); if (pAggSym != pDest.getAggregate()) { return(false); } TypeArray pTypeParams = pAggSym.GetTypeVarsAll(); TypeArray pSourceArgs = pSource.GetTypeArgsAll(); TypeArray pDestArgs = pDest.GetTypeArgsAll(); Debug.Assert(pTypeParams.size == pSourceArgs.size); Debug.Assert(pTypeParams.size == pDestArgs.size); for (int iParam = 0; iParam < pTypeParams.size; ++iParam) { CType pSourceArg = pSourceArgs.Item(iParam); CType pDestArg = pDestArgs.Item(iParam); // If they're identical then this one is automatically good, so skip it. if (pSourceArg == pDestArg) { continue; } TypeParameterType pParam = pTypeParams.Item(iParam).AsTypeParameterType(); if (pParam.Invariant) { return(false); } if (pParam.Covariant) { if (!HasImplicitReferenceConversion(pSourceArg, pDestArg)) { return(false); } } if (pParam.Contravariant) { if (!HasImplicitReferenceConversion(pDestArg, pSourceArg)) { return(false); } } } return(true); }
private AggregateSymbol FindPredefinedTypeCore(Name name, NamespaceOrAggregateSymbol bag, KAID aid, AggKindEnum aggKind, int arity, out AggregateSymbol paggAmbig, out AggregateSymbol paggBad) { AggregateSymbol aggFound = null; paggAmbig = null; paggBad = null; for (AggregateSymbol aggCur = _pBSymmgr.LookupGlobalSymCore(name, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); aggCur != null; aggCur = BSYMMGR.LookupNextSym(aggCur, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol()) { if (!aggCur.InAlias(aid) || aggCur.GetTypeVarsAll().size != arity) { continue; } if (aggCur.AggKind() != aggKind) { if (paggBad == null) { paggBad = aggCur; } continue; } if (aggFound != null) { Debug.Assert(paggAmbig == null); paggAmbig = aggCur; break; } aggFound = aggCur; if (paggAmbig == null) { break; } } return(aggFound); }
private MethodSymbol LoadMethod( AggregateSymbol type, int[] signature, int cMethodTyVars, Name methodName, ACCESS methodAccess, bool isStatic, bool isVirtual ) { Debug.Assert(signature != null); Debug.Assert(cMethodTyVars >= 0); Debug.Assert(methodName != null); if (type == null) { return null; } TypeArray classTyVars = type.GetTypeVarsAll(); int index = 0; CType returnType = LoadTypeFromSignature(signature, ref index, classTyVars); if (returnType == null) { return null; } TypeArray argumentTypes = LoadTypeArrayFromSignature(signature, ref index, classTyVars); if (argumentTypes == null) { return null; } TypeArray standardMethodTyVars = GetTypeManager().GetStdMethTyVarArray(cMethodTyVars); MethodSymbol ret = LookupMethodWhileLoading(type, cMethodTyVars, methodName, methodAccess, isStatic, isVirtual, returnType, argumentTypes); if (ret == null) { RuntimeBinderSymbolTable.AddPredefinedMethodToSymbolTable(type, methodName); ret = LookupMethodWhileLoading(type, cMethodTyVars, methodName, methodAccess, isStatic, isVirtual, returnType, argumentTypes); } return ret; }
public bool computeManagedType(SymbolLoader symbolLoader) { if (this.IsVoidType()) { return(false); } switch (this.fundType()) { case FUNDTYPE.FT_NONE: case FUNDTYPE.FT_REF: case FUNDTYPE.FT_VAR: return(true); case FUNDTYPE.FT_STRUCT: if (this.IsNullableType()) { return(true); } else { AggregateSymbol aggT = this.getAggregate(); // See if we already know. if (aggT.IsKnownManagedStructStatus()) { return(aggT.IsManagedStruct()); } // Generics are always managed. if (aggT.GetTypeVarsAll().size > 0) { aggT.SetManagedStruct(true); return(true); } // If the struct layout has an error, dont recurse its children. if (aggT.IsLayoutError()) { aggT.SetUnmanagedStruct(true); return(false); } // at this point we can only determine the managed status // if we have members defined, otherwise we don't know the result if (symbolLoader != null) { for (Symbol ps = aggT.firstChild; ps != null; ps = ps.nextChild) { if (ps.IsFieldSymbol() && !ps.AsFieldSymbol().isStatic) { CType type = ps.AsFieldSymbol().GetType(); if (type.computeManagedType(symbolLoader)) { aggT.SetManagedStruct(true); return(true); } } } aggT.SetUnmanagedStruct(true); } return(false); } default: return(false); } }
public AggregateType GetAggregate(AggregateSymbol agg, TypeArray typeArgsAll) { Debug.Assert(typeArgsAll != null && typeArgsAll.Size == agg.GetTypeVarsAll().Size); if (typeArgsAll.size == 0) return agg.getThisType(); AggregateSymbol aggOuter = agg.GetOuterAgg(); if (aggOuter == null) return GetAggregate(agg, null, typeArgsAll); int cvarOuter = aggOuter.GetTypeVarsAll().Size; Debug.Assert(cvarOuter <= typeArgsAll.Size); TypeArray typeArgsOuter = _BSymmgr.AllocParams(cvarOuter, typeArgsAll, 0); TypeArray typeArgsInner = _BSymmgr.AllocParams(agg.GetTypeVars().Size, typeArgsAll, cvarOuter); AggregateType atsOuter = GetAggregate(aggOuter, typeArgsOuter); return GetAggregate(agg, atsOuter, typeArgsInner); }