public ExprBoundLambda CreateAnonymousMethod(AggregateType delegateType) { Debug.Assert(delegateType == null || delegateType.isDelegateType()); ExprBoundLambda rval = new ExprBoundLambda(delegateType); return(rval); }
public ExprBoundLambda(AggregateType type, Scope argumentScope, Expr expression) : base(ExpressionKind.BoundLambda, type) { Debug.Assert(type != null); Debug.Assert(type.isDelegateType()); Debug.Assert(argumentScope != null); ArgumentScope = argumentScope; Expression = expression; }
// UNDONE: Rename to CreateBoundAnonymousFunction public EXPRBOUNDLAMBDA CreateAnonymousMethod(AggregateType delegateType) { Debug.Assert(delegateType == null || delegateType.isDelegateType()); EXPRBOUNDLAMBDA rval = new EXPRBOUNDLAMBDA(); rval.kind = ExpressionKind.EK_BOUNDLAMBDA; rval.type = delegateType; rval.flags = 0; Debug.Assert(rval != null); return(rval); }
public ExprBoundLambda CreateAnonymousMethod(AggregateType delegateType) { Debug.Assert(delegateType == null || delegateType.isDelegateType()); ExprBoundLambda rval = new ExprBoundLambda(); rval.Kind = ExpressionKind.EK_BOUNDLAMBDA; rval.Type = delegateType; rval.Flags = 0; Debug.Assert(rval != null); return(rval); }
//////////////////////////////////////////////////////////////////////////////// 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; }
private bool TryVarianceAdjustmentToGetAccessibleType(CSemanticChecker semanticChecker, BindingContext bindingContext, AggregateType typeSrc, out CType typeDst) { Debug.Assert(typeSrc != null); Debug.Assert(typeSrc.isInterfaceType() || typeSrc.isDelegateType()); typeDst = null; AggregateSymbol aggSym = typeSrc.GetOwningAggregate(); AggregateType aggOpenType = aggSym.getThisType(); if (!semanticChecker.CheckTypeAccess(aggOpenType, bindingContext.ContextForMemberLookup)) { // if the aggregate symbol itself is not accessible, then forget it, there is no // variance that will help us arrive at an accessible type. return(false); } TypeArray typeArgs = typeSrc.GetTypeArgsThis(); TypeArray typeParams = aggOpenType.GetTypeArgsThis(); CType[] newTypeArgsTemp = new CType[typeArgs.Count]; for (int i = 0; i < typeArgs.Count; i++) { if (semanticChecker.CheckTypeAccess(typeArgs[i], bindingContext.ContextForMemberLookup)) { // we have an accessible argument, this position is not a problem. newTypeArgsTemp[i] = typeArgs[i]; continue; } if (!typeArgs[i].IsRefType() || !((TypeParameterType)typeParams[i]).Covariant) { // This guy is inaccessible, and we are not going to be able to vary him, so we need to fail. return(false); } CType intermediateTypeArg; if (GetBestAccessibleType(semanticChecker, bindingContext, typeArgs[i], out intermediateTypeArg)) { // now we either have a value type (which must be accessible due to the above // check, OR we have an inaccessible type (which must be a ref type). In either // case, the recursion worked out and we are OK to vary this argument. newTypeArgsTemp[i] = intermediateTypeArg; continue; } else { Debug.Assert(false, "GetBestAccessibleType unexpectedly failed on a type that was used as a type parameter"); return(false); } } TypeArray newTypeArgs = semanticChecker.getBSymmgr().AllocParams(typeArgs.Count, newTypeArgsTemp); CType intermediateType = this.GetAggregate(aggSym, typeSrc.outerType, newTypeArgs); // All type arguments were varied successfully, which means now we must be accessible. But we could // have violated constraints. Let's check that out. if (!TypeBind.CheckConstraints(semanticChecker, null /*ErrorHandling*/, intermediateType, CheckConstraintsFlags.NoErrors)) { return(false); } typeDst = intermediateType; Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup)); return(true); }
private bool TryVarianceAdjustmentToGetAccessibleType(CSemanticChecker semanticChecker, BindingContext bindingContext, AggregateType typeSrc, out CType typeDst) { Debug.Assert(typeSrc != null); Debug.Assert(typeSrc.isInterfaceType() || typeSrc.isDelegateType()); typeDst = null; AggregateSymbol aggSym = typeSrc.GetOwningAggregate(); AggregateType aggOpenType = aggSym.getThisType(); if (!semanticChecker.CheckTypeAccess(aggOpenType, bindingContext.ContextForMemberLookup())) { // if the aggregate symbol itself is not accessible, then forget it, there is no // variance that will help us arrive at an accessible type. return false; } TypeArray typeArgs = typeSrc.GetTypeArgsThis(); TypeArray typeParams = aggOpenType.GetTypeArgsThis(); CType[] newTypeArgsTemp = new CType[typeArgs.size]; for (int i = 0; i < typeArgs.size; i++) { if (semanticChecker.CheckTypeAccess(typeArgs.Item(i), bindingContext.ContextForMemberLookup())) { // we have an accessible argument, this position is not a problem. newTypeArgsTemp[i] = typeArgs.Item(i); continue; } if (!typeArgs.Item(i).IsRefType() || !typeParams.Item(i).AsTypeParameterType().Covariant) { // This guy is inaccessible, and we are not going to be able to vary him, so we need to fail. return false; } CType intermediateTypeArg; if (GetBestAccessibleType(semanticChecker, bindingContext, typeArgs.Item(i), out intermediateTypeArg)) { // now we either have a value type (which must be accessible due to the above // check, OR we have an inaccessible type (which must be a ref type). In either // case, the recursion worked out and we are OK to vary this argument. newTypeArgsTemp[i] = intermediateTypeArg; continue; } else { Debug.Assert(false, "GetBestAccessibleType unexpectedly failed on a type that was used as a type parameter"); return false; } } TypeArray newTypeArgs = semanticChecker.getBSymmgr().AllocParams(typeArgs.size, newTypeArgsTemp); CType intermediateType = this.GetAggregate(aggSym, typeSrc.outerType, newTypeArgs); // All type arguments were varied successfully, which means now we must be accessible. But we could // have violated constraints. Let's check that out. if (!TypeBind.CheckConstraints(semanticChecker, null/*ErrorHandling*/, intermediateType, CheckConstraintsFlags.NoErrors)) { return false; } typeDst = intermediateType; Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup())); return true; }
////////////////////////////////////////////////////////////////////////////// private bool HasDelegateConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null && pSource.isDelegateType()); Debug.Assert(pDest != null && pDest.isDelegateType()); return(HasVariantConversion(pSource, pDest)); }
////////////////////////////////////////////////////////////////////////////// private bool HasDelegateConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null && pSource.isDelegateType()); Debug.Assert(pDest != null && pDest.isDelegateType()); return HasVariantConversion(pSource, pDest); }
public EXPRBOUNDLAMBDA CreateAnonymousMethod(AggregateType delegateType) { Debug.Assert(delegateType == null || delegateType.isDelegateType()); EXPRBOUNDLAMBDA rval = new EXPRBOUNDLAMBDA(); rval.kind = ExpressionKind.EK_BOUNDLAMBDA; rval.type = delegateType; rval.flags = 0; Debug.Assert(rval != null); return (rval); }