public TypeArray SubstTypeArray(TypeArray taSrc, SubstContext ctx) { if (taSrc != null && taSrc.Count != 0 && ctx != null && !ctx.FNop()) { CType[] srcs = taSrc.Items; for (int i = 0; i < srcs.Length; i++) { CType src = srcs[i]; CType dst = SubstTypeCore(src, ctx); if (src != dst) { CType[] dsts = new CType[srcs.Length]; Array.Copy(srcs, dsts, i); dsts[i] = dst; while (++i < srcs.Length) { dsts[i] = SubstTypeCore(srcs[i], ctx); } return(_BSymmgr.AllocParams(dsts)); } } } return(taSrc); }
private CType SubstType(CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, bool denormMeth) { Debug.Assert(typeSrc != null); SubstContext ctx = new SubstContext(typeArgsCls, typeArgsMeth, denormMeth); return(ctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, ctx)); }
public AggregateType SubstType(AggregateType typeSrc, TypeArray typeArgsCls) { Debug.Assert(typeSrc != null); SubstContext ctx = new SubstContext(typeArgsCls, null, false); return(ctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, ctx)); }
private CType SubstType(CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { if (typeSrc == null) { return(null); } var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); return(ctx.FNop() ? typeSrc : SubstTypeCore(typeSrc, ctx)); }
public bool SubstEqualTypes(CType typeDst, CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { if (typeDst.Equals(typeSrc)) { Debug.Assert(typeDst.Equals(SubstType(typeSrc, typeArgsCls, typeArgsMeth, grfst))); return(true); } var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); return(!ctx.FNop() && SubstEqualTypesCore(typeDst, typeSrc, ctx)); }
public bool SubstEqualTypes(CType typeDst, CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, bool denormMeth) { if (typeDst.Equals(typeSrc)) { Debug.Assert(typeDst.Equals(SubstType(typeSrc, typeArgsCls, typeArgsMeth, denormMeth))); return(true); } SubstContext ctx = new SubstContext(typeArgsCls, typeArgsMeth, denormMeth); return(!ctx.IsNop && SubstEqualTypesCore(typeDst, typeSrc, ctx)); }
public AggregateType SubstType(AggregateType typeSrc, TypeArray typeArgsCls) { if (typeSrc != null) { SubstContext ctx = new SubstContext(typeArgsCls, null, SubstTypeFlags.NormNone); if (!ctx.FNop()) { return(SubstTypeCore(typeSrc, ctx)); } } return(typeSrc); }
public TypeArray SubstTypeArray(TypeArray taSrc, SubstContext pctx) { if (taSrc == null || taSrc.Count == 0 || pctx == null || pctx.FNop()) { return(taSrc); } CType[] prgpts = new CType[taSrc.Count]; for (int ipts = 0; ipts < taSrc.Count; ipts++) { prgpts[ipts] = this.SubstTypeCore(taSrc[ipts], pctx); } return(_BSymmgr.AllocParams(taSrc.Count, prgpts)); }
private AggregateType SubstTypeCore(AggregateType type, SubstContext ctx) { TypeArray args = type.GetTypeArgsAll(); if (args.Count > 0) { TypeArray typeArgs = SubstTypeArray(args, ctx); if (args != typeArgs) { return(GetAggregate(type.getAggregate(), typeArgs)); } } return(type); }
private TypeArray SubstTypeArray(TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { if (taSrc == null || taSrc.Count == 0) { return(taSrc); } var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); if (ctx.FNop()) { return(taSrc); } CType[] prgpts = new CType[taSrc.Count]; for (int ipts = 0; ipts < taSrc.Count; ipts++) { prgpts[ipts] = SubstTypeCore(taSrc[ipts], ctx); } return(_BSymmgr.AllocParams(taSrc.Count, prgpts)); }
public bool SubstEqualTypeArrays(TypeArray taDst, TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { // Handle the simple common cases first. if (taDst == taSrc || (taDst != null && taDst.Equals(taSrc))) { // The following assertion is not always true and indicates a problem where // the signature of override method does not match the one inherited from // the base class. The method match we have found does not take the type // arguments of the base class into account. So actually we are not overriding // the method that we "intend" to. // Debug.Assert(taDst == SubstTypeArray(taSrc, typeArgsCls, typeArgsMeth, grfst)); return(true); } if (taDst.Count != taSrc.Count) { return(false); } if (taDst.Count == 0) { return(true); } var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); if (ctx.FNop()) { return(false); } for (int i = 0; i < taDst.Count; i++) { if (!SubstEqualTypesCore(taDst[i], taSrc[i], ctx)) { return(false); } } return(true); }
protected void ErrAppendParentCore(Symbol parent, SubstContext pctx) { if (null == parent) return; if (parent == getBSymmgr().GetRootNS()) return; if (pctx != null && !pctx.FNop() && parent.IsAggregateSymbol() && 0 != parent.AsAggregateSymbol().GetTypeVarsAll().size) { CType pType = GetTypeManager().SubstType(parent.AsAggregateSymbol().getThisType(), pctx); ErrAppendType(pType, null); } else { ErrAppendSym(parent, null); } ErrAppendChar('.'); }
public CType SubstType(CType typeSrc, SubstContext pctx) { return((pctx == null || pctx.FNop()) ? typeSrc : SubstTypeCore(typeSrc, pctx)); }
protected void ErrAppendIndexer(IndexerSymbol indexer, SubstContext pctx) { ErrAppendString("this["); ErrAppendParamList(GetTypeManager().SubstTypeArray(indexer.Params, pctx), false, indexer.isParamArray); ErrAppendChar(']'); }
protected void ErrAppendTypeParameters(TypeArray @params, SubstContext pctx, bool forClass) { if (@params != null && @params.size != 0) { ErrAppendChar('<'); ErrAppendType(@params.Item(0), pctx); for (int i = 1; i < @params.size; i++) { ErrAppendString(","); ErrAppendType(@params.Item(i), pctx); } ErrAppendChar('>'); } }
protected void ErrAppendMethodParentSym(MethodSymbol sym, SubstContext pcxt, out TypeArray substMethTyParams) { substMethTyParams = null; ErrAppendParentSym(sym, pcxt); }
public bool SubstEqualTypeArrays(TypeArray taDst, TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { // Handle the simple common cases first. if (taDst == taSrc || (taDst != null && taDst.Equals(taSrc))) { // The following assertion is not always true and indicates a problem where // the signature of override method does not match the one inherited from // the base class. The method match we have found does not take the type // arguments of the base class into account. So actually we are not overriding // the method that we "intend" to. // Debug.Assert(taDst == SubstTypeArray(taSrc, typeArgsCls, typeArgsMeth, grfst)); return true; } if (taDst.Size != taSrc.Size) return false; if (taDst.Size == 0) return true; var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); if (ctx.FNop()) return false; for (int i = 0; i < taDst.size; i++) { if (!SubstEqualTypesCore(taDst.Item(i), taSrc.Item(i), ctx)) return false; } return true; }
private CType SubstTypeCore(CType type, SubstContext pctx) { CType typeSrc; CType typeDst; switch (type.GetTypeKind()) { default: Debug.Assert(false); return type; case TypeKind.TK_NullType: case TypeKind.TK_VoidType: case TypeKind.TK_OpenTypePlaceholderType: case TypeKind.TK_MethodGroupType: case TypeKind.TK_BoundLambdaType: case TypeKind.TK_UnboundLambdaType: case TypeKind.TK_NaturalIntegerType: case TypeKind.TK_ArgumentListType: return type; case TypeKind.TK_ParameterModifierType: typeDst = SubstTypeCore(typeSrc = type.AsParameterModifierType().GetParameterType(), pctx); return (typeDst == typeSrc) ? type : GetParameterModifier(typeDst, type.AsParameterModifierType().isOut); case TypeKind.TK_ArrayType: typeDst = SubstTypeCore(typeSrc = type.AsArrayType().GetElementType(), pctx); return (typeDst == typeSrc) ? type : GetArray(typeDst, type.AsArrayType().rank); case TypeKind.TK_PointerType: typeDst = SubstTypeCore(typeSrc = type.AsPointerType().GetReferentType(), pctx); return (typeDst == typeSrc) ? type : GetPointer(typeDst); case TypeKind.TK_NullableType: typeDst = SubstTypeCore(typeSrc = type.AsNullableType().GetUnderlyingType(), pctx); return (typeDst == typeSrc) ? type : GetNullable(typeDst); case TypeKind.TK_AggregateType: if (type.AsAggregateType().GetTypeArgsAll().size > 0) { AggregateType ats = type.AsAggregateType(); TypeArray typeArgs = SubstTypeArray(ats.GetTypeArgsAll(), pctx); if (ats.GetTypeArgsAll() != typeArgs) return GetAggregate(ats.getAggregate(), typeArgs); } return type; case TypeKind.TK_ErrorType: if (type.AsErrorType().HasParent()) { ErrorType err = type.AsErrorType(); Debug.Assert(err.nameText != null && err.typeArgs != null); CType pParentType = null; if (err.HasTypeParent()) { pParentType = SubstTypeCore(err.GetTypeParent(), pctx); } TypeArray typeArgs = SubstTypeArray(err.typeArgs, pctx); if (typeArgs != err.typeArgs || (err.HasTypeParent() && pParentType != err.GetTypeParent())) { return GetErrorType(pParentType, err.GetNSParent(), err.nameText, typeArgs); } } return type; case TypeKind.TK_TypeParameterType: { TypeParameterSymbol tvs = type.AsTypeParameterType().GetTypeParameterSymbol(); int index = tvs.GetIndexInTotalParameters(); if (tvs.IsMethodTypeParameter()) { if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null) return type; Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters()); if (index < pctx.ctypeMeth) { Debug.Assert(pctx.prgtypeMeth != null); return pctx.prgtypeMeth[index]; } else { return ((pctx.grfst & SubstTypeFlags.NormMeth) != 0 ? GetStdMethTypeVar(index) : type); } } if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null) return type; return index < pctx.ctypeCls ? pctx.prgtypeCls[index] : ((pctx.grfst & SubstTypeFlags.NormClass) != 0 ? GetStdClsTypeVar(index) : type); } } }
public void ErrAppendType(CType pType, SubstContext pctx, bool fArgs) { if (pctx != null) { if (!pctx.FNop()) { pType = GetTypeManager().SubstType(pType, pctx); } // We shouldn't use the SubstContext again so set it to NULL. pctx = null; } switch (pType.GetTypeKind()) { case TypeKind.TK_AggregateType: { AggregateType pAggType = pType.AsAggregateType(); // Check for a predefined class with a special "nice" name for // error reported. string text = PredefinedTypes.GetNiceName(pAggType.getAggregate()); if (text != null) { // Found a nice name. ErrAppendString(text); } else if (pAggType.getAggregate().IsAnonymousType()) { ErrAppendPrintf("AnonymousType#{0}", GetTypeID(pAggType)); break; } else { if (pAggType.outerType != null) { ErrAppendType(pAggType.outerType, pctx); ErrAppendChar('.'); } else { // In a namespace. ErrAppendParentSym(pAggType.getAggregate(), pctx); } ErrAppendName(pAggType.getAggregate().name); } ErrAppendTypeParameters(pAggType.GetTypeArgsThis(), pctx, true); break; } case TypeKind.TK_TypeParameterType: if (null == pType.GetName()) { // It's a standard type variable. if (pType.AsTypeParameterType().IsMethodTypeParameter()) { ErrAppendChar('!'); } ErrAppendChar('!'); ErrAppendPrintf("{0}", pType.AsTypeParameterType().GetIndexInTotalParameters()); } else { ErrAppendName(pType.GetName()); } break; case TypeKind.TK_ErrorType: if (pType.AsErrorType().HasParent()) { Debug.Assert(pType.AsErrorType().nameText != null && pType.AsErrorType().typeArgs != null); ErrAppendParentType(pType, pctx); ErrAppendName(pType.AsErrorType().nameText); ErrAppendTypeParameters(pType.AsErrorType().typeArgs, pctx, true); } else { // Load the string "<error>". Debug.Assert(null == pType.AsErrorType().typeArgs); ErrAppendId(MessageID.ERRORSYM); } break; case TypeKind.TK_NullType: // Load the string "<null>". ErrAppendId(MessageID.NULL); break; case TypeKind.TK_OpenTypePlaceholderType: // Leave blank. break; case TypeKind.TK_BoundLambdaType: ErrAppendId(MessageID.AnonMethod); break; case TypeKind.TK_UnboundLambdaType: ErrAppendId(MessageID.Lambda); break; case TypeKind.TK_MethodGroupType: ErrAppendId(MessageID.MethodGroup); break; case TypeKind.TK_ArgumentListType: ErrAppendString(TokenFacts.GetText(TokenKind.ArgList)); break; case TypeKind.TK_ArrayType: { CType elementType = pType.AsArrayType().GetBaseElementType(); int rank; if (null == elementType) { Debug.Assert(false, "No element type"); break; } ErrAppendType(elementType, pctx); for (elementType = pType; elementType != null && elementType.IsArrayType(); elementType = elementType.AsArrayType().GetElementType()) { rank = elementType.AsArrayType().rank; // Add [] with (rank-1) commas inside ErrAppendChar('['); #if ! CSEE // known rank. if (rank > 1) { ErrAppendChar('*'); } #endif for (int i = rank; i > 1; --i) { ErrAppendChar(','); #if ! CSEE ErrAppendChar('*'); #endif } ErrAppendChar(']'); } break; } case TypeKind.TK_VoidType: ErrAppendName(GetNameManager().Lookup(TokenFacts.GetText(TokenKind.Void))); break; case TypeKind.TK_ParameterModifierType: // add ref or out ErrAppendString(pType.AsParameterModifierType().isOut ? "out " : "ref "); // add base type name ErrAppendType(pType.AsParameterModifierType().GetParameterType(), pctx); break; case TypeKind.TK_PointerType: // Generate the base type. ErrAppendType(pType.AsPointerType().GetReferentType(), pctx); { // add the trailing * ErrAppendChar('*'); } break; case TypeKind.TK_NullableType: ErrAppendType(pType.AsNullableType().GetUnderlyingType(), pctx); ErrAppendChar('?'); break; case TypeKind.TK_NaturalIntegerType: default: // Shouldn't happen. Debug.Assert(false, "Bad type kind"); break; } }
public void ErrAppendType(CType pType, SubstContext pCtx) { ErrAppendType(pType, pCtx, true); }
public void ErrAppendSym(Symbol sym, SubstContext pctx, bool fArgs) { switch (sym.getKind()) { case SYMKIND.SK_NamespaceDeclaration: // for namespace declarations just convert the namespace ErrAppendSym(sym.AsNamespaceDeclaration().NameSpace(), null); break; case SYMKIND.SK_GlobalAttributeDeclaration: ErrAppendName(sym.name); break; case SYMKIND.SK_AggregateDeclaration: ErrAppendSym(sym.AsAggregateDeclaration().Agg(), pctx); break; case SYMKIND.SK_AggregateSymbol: { // Check for a predefined class with a special "nice" name for // error reported. string text = PredefinedTypes.GetNiceName(sym.AsAggregateSymbol()); if (text != null) { // Found a nice name. ErrAppendString(text); } else if (sym.AsAggregateSymbol().IsAnonymousType()) { ErrAppendId(MessageID.AnonymousType); break; } else { ErrAppendParentSym(sym, pctx); ErrAppendName(sym.name); ErrAppendTypeParameters(sym.AsAggregateSymbol().GetTypeVars(), pctx, true); } break; } case SYMKIND.SK_MethodSymbol: ErrAppendMethod(sym.AsMethodSymbol(), pctx, fArgs); break; case SYMKIND.SK_PropertySymbol: ErrAppendProperty(sym.AsPropertySymbol(), pctx); break; case SYMKIND.SK_EventSymbol: ErrAppendEvent(sym.AsEventSymbol(), pctx); break; case SYMKIND.SK_AssemblyQualifiedNamespaceSymbol: case SYMKIND.SK_NamespaceSymbol: if (sym == getBSymmgr().GetRootNS()) { ErrAppendId(MessageID.GlobalNamespace); } else { ErrAppendParentSym(sym, null); ErrAppendName(sym.name); } break; case SYMKIND.SK_FieldSymbol: ErrAppendParentSym(sym, pctx); ErrAppendName(sym.name); break; case SYMKIND.SK_TypeParameterSymbol: if (null == sym.name) { // It's a standard type variable. if (sym.AsTypeParameterSymbol().IsMethodTypeParameter()) ErrAppendChar('!'); ErrAppendChar('!'); ErrAppendPrintf("{0}", sym.AsTypeParameterSymbol().GetIndexInTotalParameters()); } else ErrAppendName(sym.name); break; case SYMKIND.SK_LocalVariableSymbol: case SYMKIND.SK_LabelSymbol: case SYMKIND.SK_TransparentIdentifierMemberSymbol: // Generate symbol name. ErrAppendName(sym.name); break; case SYMKIND.SK_Scope: case SYMKIND.SK_LambdaScope: default: // Shouldn't happen. Debug.Assert(false, "Bad symbol kind"); break; } }
/* * Create a fill-in string describing a symbol. */ public void ErrAppendSym(Symbol sym, SubstContext pctx) { ErrAppendSym(sym, pctx, true); }
protected void ErrAppendEvent(EventSymbol @event, SubstContext pctx) { }
protected void ErrAppendProperty(PropertySymbol prop, SubstContext pctx) { ErrAppendParentSym(prop, pctx); if (prop.IsExpImpl() && prop.swtSlot.Sym != null) { SubstContext ctx = new SubstContext(GetTypeManager().SubstType(prop.swtSlot.GetType(), pctx).AsAggregateType()); ErrAppendSym(prop.swtSlot.Sym, ctx); } else if (prop.IsExpImpl()) { if (prop.errExpImpl != null) ErrAppendType(prop.errExpImpl, pctx, false); if (prop.isIndexer()) { ErrAppendChar('.'); ErrAppendIndexer(prop.AsIndexerSymbol(), pctx); } } else if (prop.isIndexer()) { ErrAppendIndexer(prop.AsIndexerSymbol(), pctx); } else { ErrAppendName(prop.name); } }
public TypeArray SubstTypeArray(TypeArray taSrc, SubstContext pctx) { if (taSrc == null || taSrc.Size == 0 || pctx == null || pctx.FNop()) return taSrc; CType[] prgpts = new CType[taSrc.Size]; for (int ipts = 0; ipts < taSrc.Size; ipts++) { prgpts[ipts] = this.SubstTypeCore(taSrc.Item(ipts), pctx); } return _BSymmgr.AllocParams(taSrc.size, prgpts); }
public TypeArray SubstTypeArray(TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { if (taSrc == null || taSrc.Size == 0) return taSrc; var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); if (ctx.FNop()) return taSrc; CType[] prgpts = new CType[taSrc.Size]; for (int ipts = 0; ipts < taSrc.Size; ipts++) { prgpts[ipts] = SubstTypeCore(taSrc.Item(ipts), ctx); } return _BSymmgr.AllocParams(taSrc.Size, prgpts); }
// Returns true if the argument could be converted to a string. public bool ErrArgToString(out string psz, ErrArg parg, out bool fUserStrings) { fUserStrings = false; psz = null; bool result = true; switch (parg.eak) { case ErrArgKind.Ids: ErrId(out psz, parg.ids); break; case ErrArgKind.SymKind: ErrSK(out psz, parg.sk); break; case ErrArgKind.Type: BeginString(); ErrAppendType(parg.pType, null); EndString(out psz); fUserStrings = true; break; case ErrArgKind.Sym: BeginString(); ErrAppendSym(parg.sym, null); EndString(out psz); fUserStrings = true; break; case ErrArgKind.Name: if (parg.name == GetNameManager().GetPredefinedName(PredefinedName.PN_INDEXERINTERNAL)) { psz = "this"; } else { psz = parg.name.Text; } break; case ErrArgKind.Str: psz = parg.psz; break; case ErrArgKind.PredefName: BeginString(); ErrAppendName(GetNameManager().GetPredefName(parg.pdn)); EndString(out psz); break; case ErrArgKind.SymWithType: { SubstContext ctx = new SubstContext(parg.swtMemo.ats, null); BeginString(); ErrAppendSym(parg.swtMemo.sym, ctx, true); EndString(out psz); fUserStrings = true; break; } case ErrArgKind.MethWithInst: { SubstContext ctx = new SubstContext(parg.mpwiMemo.ats, parg.mpwiMemo.typeArgs); BeginString(); ErrAppendSym(parg.mpwiMemo.sym, ctx, true); EndString(out psz); fUserStrings = true; break; } default: result = false; break; } return result; }
public bool SubstEqualTypes(CType typeDst, CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { if (typeDst.Equals(typeSrc)) { Debug.Assert(typeDst.Equals(SubstType(typeSrc, typeArgsCls, typeArgsMeth, grfst))); return true; } var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); return !ctx.FNop() && SubstEqualTypesCore(typeDst, typeSrc, ctx); }
private CType SubstTypeCore(CType type, SubstContext pctx) { CType typeSrc; CType typeDst; switch (type.TypeKind) { default: Debug.Assert(false); return(type); case TypeKind.TK_NullType: case TypeKind.TK_VoidType: case TypeKind.TK_MethodGroupType: case TypeKind.TK_ArgumentListType: return(type); case TypeKind.TK_ParameterModifierType: ParameterModifierType mod = (ParameterModifierType)type; typeDst = SubstTypeCore(typeSrc = mod.ParameterType, pctx); return((typeDst == typeSrc) ? type : GetParameterModifier(typeDst, mod.IsOut)); case TypeKind.TK_ArrayType: var arr = (ArrayType)type; typeDst = SubstTypeCore(typeSrc = arr.ElementType, pctx); return((typeDst == typeSrc) ? type : GetArray(typeDst, arr.Rank, arr.IsSZArray)); case TypeKind.TK_PointerType: typeDst = SubstTypeCore(typeSrc = ((PointerType)type).ReferentType, pctx); return((typeDst == typeSrc) ? type : GetPointer(typeDst)); case TypeKind.TK_NullableType: typeDst = SubstTypeCore(typeSrc = ((NullableType)type).UnderlyingType, pctx); return((typeDst == typeSrc) ? type : GetNullable(typeDst)); case TypeKind.TK_AggregateType: return(SubstTypeCore((AggregateType)type, pctx)); case TypeKind.TK_TypeParameterType: { TypeParameterSymbol tvs = ((TypeParameterType)type).Symbol; int index = tvs.GetIndexInTotalParameters(); if (tvs.IsMethodTypeParameter()) { if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null) { return(type); } Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters()); if (index < pctx.ctypeMeth) { Debug.Assert(pctx.prgtypeMeth != null); return(pctx.prgtypeMeth[index]); } else { return((pctx.grfst & SubstTypeFlags.NormMeth) != 0 ? GetStdMethTypeVar(index) : type); } } if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null) { return(type); } return(index < pctx.ctypeCls ? pctx.prgtypeCls[index] : ((pctx.grfst & SubstTypeFlags.NormClass) != 0 ? GetStdClsTypeVar(index) : type)); } } }
public bool SubstEqualTypesCore(CType typeDst, CType typeSrc, SubstContext pctx) { LRecurse: // Label used for "tail" recursion. if (typeDst == typeSrc || typeDst.Equals(typeSrc)) { return true; } switch (typeSrc.GetTypeKind()) { default: Debug.Assert(false, "Bad Symbol kind in SubstEqualTypesCore"); return false; case TypeKind.TK_NullType: case TypeKind.TK_VoidType: case TypeKind.TK_OpenTypePlaceholderType: // There should only be a single instance of these. Debug.Assert(typeDst.GetTypeKind() != typeSrc.GetTypeKind()); return false; case TypeKind.TK_ArrayType: if (typeDst.GetTypeKind() != TypeKind.TK_ArrayType || typeDst.AsArrayType().rank != typeSrc.AsArrayType().rank) return false; goto LCheckBases; case TypeKind.TK_ParameterModifierType: if (typeDst.GetTypeKind() != TypeKind.TK_ParameterModifierType || ((pctx.grfst & SubstTypeFlags.NoRefOutDifference) == 0 && typeDst.AsParameterModifierType().isOut != typeSrc.AsParameterModifierType().isOut)) return false; goto LCheckBases; case TypeKind.TK_PointerType: case TypeKind.TK_NullableType: if (typeDst.GetTypeKind() != typeSrc.GetTypeKind()) return false; LCheckBases: typeSrc = typeSrc.GetBaseOrParameterOrElementType(); typeDst = typeDst.GetBaseOrParameterOrElementType(); goto LRecurse; case TypeKind.TK_AggregateType: if (typeDst.GetTypeKind() != TypeKind.TK_AggregateType) return false; { // BLOCK AggregateType atsSrc = typeSrc.AsAggregateType(); AggregateType atsDst = typeDst.AsAggregateType(); if (atsSrc.getAggregate() != atsDst.getAggregate()) return false; Debug.Assert(atsSrc.GetTypeArgsAll().Size == atsDst.GetTypeArgsAll().Size); // All the args must unify. for (int i = 0; i < atsSrc.GetTypeArgsAll().Size; i++) { if (!SubstEqualTypesCore(atsDst.GetTypeArgsAll().Item(i), atsSrc.GetTypeArgsAll().Item(i), pctx)) return false; } } return true; case TypeKind.TK_ErrorType: if (!typeDst.IsErrorType() || !typeSrc.AsErrorType().HasParent() || !typeDst.AsErrorType().HasParent()) return false; { ErrorType errSrc = typeSrc.AsErrorType(); ErrorType errDst = typeDst.AsErrorType(); Debug.Assert(errSrc.nameText != null && errSrc.typeArgs != null); Debug.Assert(errDst.nameText != null && errDst.typeArgs != null); if (errSrc.nameText != errDst.nameText || errSrc.typeArgs.Size != errDst.typeArgs.Size) return false; if (errSrc.HasTypeParent() != errDst.HasTypeParent()) { return false; } if (errSrc.HasTypeParent()) { if (errSrc.GetTypeParent() != errDst.GetTypeParent()) { return false; } if (!SubstEqualTypesCore(errDst.GetTypeParent(), errSrc.GetTypeParent(), pctx)) { return false; } } else { if (errSrc.GetNSParent() != errDst.GetNSParent()) { return false; } } // All the args must unify. for (int i = 0; i < errSrc.typeArgs.Size; i++) { if (!SubstEqualTypesCore(errDst.typeArgs.Item(i), errSrc.typeArgs.Item(i), pctx)) return false; } } return true; case TypeKind.TK_TypeParameterType: { // BLOCK TypeParameterSymbol tvs = typeSrc.AsTypeParameterType().GetTypeParameterSymbol(); int index = tvs.GetIndexInTotalParameters(); if (tvs.IsMethodTypeParameter()) { if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null) { // typeDst == typeSrc was handled above. Debug.Assert(typeDst != typeSrc); return false; } Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters()); Debug.Assert(pctx.prgtypeMeth == null || tvs.GetIndexInTotalParameters() < pctx.ctypeMeth); if (index < pctx.ctypeMeth && pctx.prgtypeMeth != null) { return typeDst == pctx.prgtypeMeth[index]; } if ((pctx.grfst & SubstTypeFlags.NormMeth) != 0) { return typeDst == GetStdMethTypeVar(index); } } else { if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null) { // typeDst == typeSrc was handled above. Debug.Assert(typeDst != typeSrc); return false; } Debug.Assert(pctx.prgtypeCls == null || tvs.GetIndexInTotalParameters() < pctx.ctypeCls); if (index < pctx.ctypeCls) return typeDst == pctx.prgtypeCls[index]; if ((pctx.grfst & SubstTypeFlags.NormClass) != 0) return typeDst == GetStdClsTypeVar(index); } } return false; } }
protected void ErrAppendParentSym(Symbol sym, SubstContext pctx) { ErrAppendParentCore(sym.parent, pctx); }
public CType SubstType(CType typeSrc, SubstContext pctx) => pctx == null || pctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, pctx);
private CType SubstTypeCore(CType type, SubstContext pctx) { CType typeSrc; CType typeDst; switch (type.GetTypeKind()) { default: Debug.Assert(false); return(type); case TypeKind.TK_NullType: case TypeKind.TK_VoidType: case TypeKind.TK_MethodGroupType: case TypeKind.TK_ArgumentListType: return(type); case TypeKind.TK_ParameterModifierType: ParameterModifierType mod = (ParameterModifierType)type; typeDst = SubstTypeCore(typeSrc = mod.GetParameterType(), pctx); return((typeDst == typeSrc) ? type : GetParameterModifier(typeDst, mod.isOut)); case TypeKind.TK_ArrayType: var arr = (ArrayType)type; typeDst = SubstTypeCore(typeSrc = arr.GetElementType(), pctx); return((typeDst == typeSrc) ? type : GetArray(typeDst, arr.rank, arr.IsSZArray)); case TypeKind.TK_PointerType: typeDst = SubstTypeCore(typeSrc = ((PointerType)type).GetReferentType(), pctx); return((typeDst == typeSrc) ? type : GetPointer(typeDst)); case TypeKind.TK_NullableType: typeDst = SubstTypeCore(typeSrc = ((NullableType)type).GetUnderlyingType(), pctx); return((typeDst == typeSrc) ? type : GetNullable(typeDst)); case TypeKind.TK_AggregateType: AggregateType ats = (AggregateType)type; if (ats.GetTypeArgsAll().Count > 0) { TypeArray typeArgs = SubstTypeArray(ats.GetTypeArgsAll(), pctx); if (ats.GetTypeArgsAll() != typeArgs) { return(GetAggregate(ats.getAggregate(), typeArgs)); } } return(type); case TypeKind.TK_ErrorType: ErrorType err = (ErrorType)type; if (err.HasParent) { Debug.Assert(err.nameText != null && err.typeArgs != null); TypeArray typeArgs = SubstTypeArray(err.typeArgs, pctx); if (typeArgs != err.typeArgs) { return(GetErrorType(err.nameText, typeArgs)); } } return(type); case TypeKind.TK_TypeParameterType: { TypeParameterSymbol tvs = ((TypeParameterType)type).GetTypeParameterSymbol(); int index = tvs.GetIndexInTotalParameters(); if (tvs.IsMethodTypeParameter()) { if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null) { return(type); } Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters()); if (index < pctx.ctypeMeth) { Debug.Assert(pctx.prgtypeMeth != null); return(pctx.prgtypeMeth[index]); } else { return((pctx.grfst & SubstTypeFlags.NormMeth) != 0 ? GetStdMethTypeVar(index) : type); } } if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null) { return(type); } return(index < pctx.ctypeCls ? pctx.prgtypeCls[index] : ((pctx.grfst & SubstTypeFlags.NormClass) != 0 ? GetStdClsTypeVar(index) : type)); } } }
public AggregateType SubstType(AggregateType typeSrc, SubstContext ctx) => ctx == null || ctx.FNop() ? typeSrc : SubstTypeCore(typeSrc, ctx);
protected void ErrAppendMethod(MethodSymbol meth, SubstContext pctx, bool fArgs) { if (meth.IsExpImpl() && meth.swtSlot) { ErrAppendParentSym(meth, pctx); // Get the type args from the explicit impl type and substitute using pctx (if there is one). SubstContext ctx = new SubstContext(GetTypeManager().SubstType(meth.swtSlot.GetType(), pctx).AsAggregateType()); ErrAppendSym(meth.swtSlot.Sym, ctx, fArgs); // args already added return; } if (meth.isPropertyAccessor()) { PropertySymbol prop = meth.getProperty(); // this includes the parent class ErrAppendSym(prop, pctx); // add accessor name if (prop.methGet == meth) { ErrAppendString(".get"); } else { Debug.Assert(meth == prop.methSet); ErrAppendString(".set"); } // args already added return; } if (meth.isEventAccessor()) { EventSymbol @event = meth.getEvent(); // this includes the parent class ErrAppendSym(@event, pctx); // add accessor name if (@event.methAdd == meth) { ErrAppendString(".add"); } else { Debug.Assert(meth == @event.methRemove); ErrAppendString(".remove"); } // args already added return; } TypeArray replacementTypeArray = null; ErrAppendMethodParentSym(meth, pctx, out replacementTypeArray); if (meth.IsConstructor()) { // Use the name of the parent class instead of the name "<ctor>". ErrAppendName(meth.getClass().name); } else if (meth.IsDestructor()) { // Use the name of the parent class instead of the name "Finalize". ErrAppendChar('~'); ErrAppendName(meth.getClass().name); } else if (meth.isConversionOperator()) { // implicit/explicit ErrAppendString(meth.isImplicit() ? "implicit" : "explicit"); ErrAppendString(" operator "); // destination type name ErrAppendType(meth.RetType, pctx); } else if (meth.isOperator) { // handle user defined operators // map from CLS predefined names to "operator <X>" ErrAppendString("operator "); // // This is kinda slow, but the alternative is to add bits to methsym. // string operatorName; OperatorKind op = Operators.OperatorOfMethodName(GetNameManager(), meth.name); if (Operators.HasDisplayName(op)) { operatorName = Operators.GetDisplayName(op); } else { // // either equals or compare // if (meth.name == GetNameManager().GetPredefName(PredefinedName.PN_OPEQUALS)) { operatorName = "equals"; } else { Debug.Assert(meth.name == GetNameManager().GetPredefName(PredefinedName.PN_OPCOMPARE)); operatorName = "compare"; } } ErrAppendString(operatorName); } else if (meth.IsExpImpl()) { if (meth.errExpImpl != null) ErrAppendType(meth.errExpImpl, pctx, fArgs); } else { // regular method ErrAppendName(meth.name); } if (null == replacementTypeArray) { ErrAppendTypeParameters(meth.typeVars, pctx, false); } if (fArgs) { // append argument types ErrAppendChar('('); if (!meth.computeCurrentBogusState()) { ErrAppendParamList(GetTypeManager().SubstTypeArray(meth.Params, pctx), meth.isVarargs, meth.isParamArray); } ErrAppendChar(')'); } }
private bool SubstEqualTypesCore(CType typeDst, CType typeSrc, SubstContext pctx) { LRecurse: // Label used for "tail" recursion. if (typeDst == typeSrc || typeDst.Equals(typeSrc)) { return(true); } switch (typeSrc.TypeKind) { default: Debug.Assert(false, "Bad Symbol kind in SubstEqualTypesCore"); return(false); case TypeKind.TK_NullType: case TypeKind.TK_VoidType: // There should only be a single instance of these. Debug.Assert(typeDst.TypeKind != typeSrc.TypeKind); return(false); case TypeKind.TK_ArrayType: ArrayType arrSrc = (ArrayType)typeSrc; if (!(typeDst is ArrayType arrDst) || arrDst.Rank != arrSrc.Rank || arrDst.IsSZArray != arrSrc.IsSZArray) { return(false); } goto LCheckBases; case TypeKind.TK_ParameterModifierType: if (!(typeDst is ParameterModifierType modDest) || modDest.IsOut != ((ParameterModifierType)typeSrc).IsOut) { return(false); } goto LCheckBases; case TypeKind.TK_PointerType: case TypeKind.TK_NullableType: if (typeDst.TypeKind != typeSrc.TypeKind) { return(false); } LCheckBases: typeSrc = typeSrc.BaseOrParameterOrElementType; typeDst = typeDst.BaseOrParameterOrElementType; goto LRecurse; case TypeKind.TK_AggregateType: if (!(typeDst is AggregateType atsDst)) { return(false); } { // BLOCK AggregateType atsSrc = (AggregateType)typeSrc; if (atsSrc.OwningAggregate != atsDst.OwningAggregate) { return(false); } Debug.Assert(atsSrc.TypeArgsAll.Count == atsDst.TypeArgsAll.Count); // All the args must unify. for (int i = 0; i < atsSrc.TypeArgsAll.Count; i++) { if (!SubstEqualTypesCore(atsDst.TypeArgsAll[i], atsSrc.TypeArgsAll[i], pctx)) { return(false); } } } return(true); case TypeKind.TK_TypeParameterType: { // BLOCK TypeParameterSymbol tvs = ((TypeParameterType)typeSrc).Symbol; int index = tvs.GetIndexInTotalParameters(); if (tvs.IsMethodTypeParameter()) { if (pctx.DenormMeth && tvs.parent != null) { // typeDst == typeSrc was handled above. Debug.Assert(typeDst != typeSrc); return(false); } Debug.Assert(tvs.GetIndexInOwnParameters() == index); Debug.Assert(tvs.GetIndexInTotalParameters() < pctx.MethodTypes.Length); if (index < pctx.MethodTypes.Length) { return(typeDst == pctx.MethodTypes[index]); } } else { Debug.Assert(index < pctx.ClassTypes.Length); if (index < pctx.ClassTypes.Length) { return(typeDst == pctx.ClassTypes[index]); } } } return(false); } }
public CType SubstType(CType typeSrc, SubstContext pctx) { return (pctx == null || pctx.FNop()) ? typeSrc : SubstTypeCore(typeSrc, pctx); }
private bool SubstEqualTypesCore(CType typeDst, CType typeSrc, SubstContext pctx) { LRecurse: // Label used for "tail" recursion. if (typeDst == typeSrc || typeDst.Equals(typeSrc)) { return(true); } switch (typeSrc.GetTypeKind()) { default: Debug.Assert(false, "Bad Symbol kind in SubstEqualTypesCore"); return(false); case TypeKind.TK_NullType: case TypeKind.TK_VoidType: // There should only be a single instance of these. Debug.Assert(typeDst.GetTypeKind() != typeSrc.GetTypeKind()); return(false); case TypeKind.TK_ArrayType: ArrayType arrSrc = (ArrayType)typeSrc; if (!(typeDst is ArrayType arrDst) || arrDst.rank != arrSrc.rank || arrDst.IsSZArray != arrSrc.IsSZArray) { return(false); } goto LCheckBases; case TypeKind.TK_ParameterModifierType: if (!(typeDst is ParameterModifierType modDest) || ((pctx.grfst & SubstTypeFlags.NoRefOutDifference) == 0 && modDest.isOut != ((ParameterModifierType)typeSrc).isOut)) { return(false); } goto LCheckBases; case TypeKind.TK_PointerType: case TypeKind.TK_NullableType: if (typeDst.GetTypeKind() != typeSrc.GetTypeKind()) { return(false); } LCheckBases: typeSrc = typeSrc.GetBaseOrParameterOrElementType(); typeDst = typeDst.GetBaseOrParameterOrElementType(); goto LRecurse; case TypeKind.TK_AggregateType: if (!(typeDst is AggregateType atsDst)) { return(false); } { // BLOCK AggregateType atsSrc = (AggregateType)typeSrc; if (atsSrc.getAggregate() != atsDst.getAggregate()) { return(false); } Debug.Assert(atsSrc.GetTypeArgsAll().Count == atsDst.GetTypeArgsAll().Count); // All the args must unify. for (int i = 0; i < atsSrc.GetTypeArgsAll().Count; i++) { if (!SubstEqualTypesCore(atsDst.GetTypeArgsAll()[i], atsSrc.GetTypeArgsAll()[i], pctx)) { return(false); } } } return(true); case TypeKind.TK_ErrorType: ErrorType errSrc = (ErrorType)typeSrc; if (!(typeDst is ErrorType errDst) || !errSrc.HasParent || !errDst.HasParent) { return(false); } { Debug.Assert(errSrc.nameText != null && errSrc.typeArgs != null); Debug.Assert(errDst.nameText != null && errDst.typeArgs != null); if (errSrc.nameText != errDst.nameText || errSrc.typeArgs.Count != errDst.typeArgs.Count || errSrc.HasParent != errDst.HasParent) { return(false); } // All the args must unify. for (int i = 0; i < errSrc.typeArgs.Count; i++) { if (!SubstEqualTypesCore(errDst.typeArgs[i], errSrc.typeArgs[i], pctx)) { return(false); } } } return(true); case TypeKind.TK_TypeParameterType: { // BLOCK TypeParameterSymbol tvs = ((TypeParameterType)typeSrc).GetTypeParameterSymbol(); int index = tvs.GetIndexInTotalParameters(); if (tvs.IsMethodTypeParameter()) { if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null) { // typeDst == typeSrc was handled above. Debug.Assert(typeDst != typeSrc); return(false); } Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters()); Debug.Assert(pctx.prgtypeMeth == null || tvs.GetIndexInTotalParameters() < pctx.ctypeMeth); if (index < pctx.ctypeMeth && pctx.prgtypeMeth != null) { return(typeDst == pctx.prgtypeMeth[index]); } if ((pctx.grfst & SubstTypeFlags.NormMeth) != 0) { return(typeDst == GetStdMethTypeVar(index)); } } else { if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null) { // typeDst == typeSrc was handled above. Debug.Assert(typeDst != typeSrc); return(false); } Debug.Assert(pctx.prgtypeCls == null || tvs.GetIndexInTotalParameters() < pctx.ctypeCls); if (index < pctx.ctypeCls) { return(typeDst == pctx.prgtypeCls[index]); } if ((pctx.grfst & SubstTypeFlags.NormClass) != 0) { return(typeDst == GetStdClsTypeVar(index)); } } } return(false); } }
public CType SubstType(CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst) { if (typeSrc == null) return null; var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst); return ctx.FNop() ? typeSrc : SubstTypeCore(typeSrc, ctx); }
//////////////////////////////////////////////////////////////////////////////// private TypeArray GetFixedDelegateParameters(AggregateType pDelegateType) { Debug.Assert(pDelegateType.isDelegateType()); // We have a delegate where the input types use no unfixed parameters. Create // a substitution context; we can substitute unfixed parameters for themselves // since they don't actually occur in the inputs. (They may occur in the outputs, // or there may be input parameters fixed to _unfixed_ method CType variables. // Both of those scenarios are legal.) CType[] ppMethodParameters = new CType[_pMethodTypeParameters.size]; for (int iParam = 0; iParam < _pMethodTypeParameters.size; iParam++) { TypeParameterType pParam = _pMethodTypeParameters.ItemAsTypeParameterType(iParam); ppMethodParameters[iParam] = IsUnfixed(iParam) ? pParam : _pFixedResults[iParam]; } SubstContext subsctx = new SubstContext(_pClassTypeArguments.ToArray(), _pClassTypeArguments.size, ppMethodParameters, _pMethodTypeParameters.size); AggregateType pFixedDelegateType = GetTypeManager().SubstType(pDelegateType, subsctx).AsAggregateType(); TypeArray pFixedDelegateParams = pFixedDelegateType.GetDelegateParameters(GetSymbolLoader()); return pFixedDelegateParams; }
protected void ErrAppendParentType(CType pType, SubstContext pctx) { if (pType.IsErrorType()) { if (pType.AsErrorType().HasTypeParent()) { ErrAppendType(pType.AsErrorType().GetTypeParent(), null); ErrAppendChar('.'); } else { ErrAppendParentCore(pType.AsErrorType().GetNSParent(), pctx); } } else if (pType.IsAggregateType()) { ErrAppendParentCore(pType.AsAggregateType().GetOwningAggregate(), pctx); } else if (pType.GetBaseOrParameterOrElementType() != null) { ErrAppendType(pType.GetBaseOrParameterOrElementType(), null); ErrAppendChar('.'); } }