private FunctionPointerTypeSymbol SubstituteFunctionPointerType(FunctionPointerTypeSymbol f) { var substitutedReturnType = f.Signature.ReturnTypeWithAnnotations.SubstituteType(this); var refCustomModifiers = f.Signature.RefCustomModifiers; var substitutedRefCustomModifiers = SubstituteCustomModifiers(refCustomModifiers); var parameterTypesWithAnnotations = f.Signature.ParameterTypesWithAnnotations; ImmutableArray <TypeWithAnnotations> substitutedParamTypes = SubstituteTypes( parameterTypesWithAnnotations ); ImmutableArray <ImmutableArray <CustomModifier> > substitutedParamModifiers = default; var paramCount = f.Signature.Parameters.Length; if (paramCount > 0) { var builder = ArrayBuilder <ImmutableArray <CustomModifier> > .GetInstance(paramCount); bool didSubstitute = false; foreach (var param in f.Signature.Parameters) { var substituted = SubstituteCustomModifiers(param.RefCustomModifiers); builder.Add(substituted); if (substituted != param.RefCustomModifiers) { didSubstitute = true; } } if (didSubstitute) { substitutedParamModifiers = builder.ToImmutableAndFree(); } else { builder.Free(); } } if ( substitutedParamTypes != parameterTypesWithAnnotations || !substitutedParamModifiers.IsDefault || !f.Signature.ReturnTypeWithAnnotations.IsSameAs(substitutedReturnType) || substitutedRefCustomModifiers != refCustomModifiers ) { f = f.SubstituteTypeSymbol( substitutedReturnType, substitutedParamTypes, refCustomModifiers, substitutedParamModifiers ); } return(f); }
internal bool MethodEqualityChecks( FunctionPointerParameterSymbol other, TypeCompareKind compareKind ) => FunctionPointerTypeSymbol.RefKindEquals(compareKind, RefKind, other.RefKind) && ( (compareKind & TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds) != 0 || RefCustomModifiers.SequenceEqual(other.RefCustomModifiers) ) && TypeWithAnnotations.Equals(other.TypeWithAnnotations, compareKind);
public static FunctionPointerMethodSymbol CreateFromSource(FunctionPointerTypeSyntax syntax, Binder typeBinder, DiagnosticBag diagnostics, ConsList <TypeSymbol> basesBeingResolved, bool suppressUseSiteDiagnostics) { var(callingConvention, conventionIsValid) = FunctionPointerTypeSymbol.GetCallingConvention(syntax.CallingConvention.Text); if (!conventionIsValid) { // '{0}' is not a valid calling convention for a function pointer. Valid conventions are 'cdecl', 'managed', 'thiscall', and 'stdcall'. diagnostics.Add(ErrorCode.ERR_InvalidFunctionPointerCallingConvention, syntax.CallingConvention.GetLocation(), syntax.CallingConvention.Text); } RefKind refKind = RefKind.None; TypeWithAnnotations returnType; var refReadonlyModifiers = ImmutableArray <CustomModifier> .Empty; if (syntax.Parameters.Count == 0) { returnType = TypeWithAnnotations.Create(typeBinder.CreateErrorType()); } else { var returnTypeParameter = syntax.Parameters[^ 1];
internal int MethodHashCode() => Hash.Combine(TypeWithAnnotations.GetHashCode(), FunctionPointerTypeSymbol.GetRefKindForHashCode(RefKind).GetHashCode());