internal PETypeParameterSymbol( PEModuleSymbol moduleSymbol, PEMethodSymbol definingMethod, ushort ordinal, GenericParameterHandle handle) : this(moduleSymbol, (Symbol)definingMethod, ordinal, handle) { }
private MetadataDecoder(PEModuleSymbol moduleSymbol, PENamedTypeSymbol typeContextOpt, PEMethodSymbol methodContextOpt) // TODO (tomat): if the containing assembly is a source assembly and we are about to decode assembly level attributes, we run into a cycle, // so for now ignore the assembly identity. : base(moduleSymbol.Module, (moduleSymbol.ContainingAssembly is PEAssemblySymbol) ? moduleSymbol.ContainingAssembly.Identity : null, SymbolFactory.Instance, moduleSymbol) { Debug.Assert((object)moduleSymbol != null); _typeContextOpt = typeContextOpt; _methodContextOpt = methodContextOpt; }
public MetadataDecoder( PEModuleSymbol moduleSymbol, PEMethodSymbol context) : this(moduleSymbol, (PENamedTypeSymbol)context.ContainingType, context) { }
private ImmutableArray <TypeSymbol> GetDeclaredConstraintTypes() { PEMethodSymbol containingMethod = null; PENamedTypeSymbol containingType; if (_containingSymbol.Kind == SymbolKind.Method) { containingMethod = (PEMethodSymbol)_containingSymbol; containingType = (PENamedTypeSymbol)containingMethod.ContainingSymbol; } else { containingType = (PENamedTypeSymbol)_containingSymbol; } var moduleSymbol = containingType.ContainingPEModule; var metadataReader = moduleSymbol.Module.MetadataReader; GenericParameterConstraintHandleCollection constraints; try { constraints = metadataReader.GetGenericParameter(_handle).GetConstraints(); } catch (BadImageFormatException) { constraints = default(GenericParameterConstraintHandleCollection); //Interlocked.CompareExchange(ref _lazyConstraintsUseSiteErrorInfo, new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this), CSDiagnosticInfo.EmptyErrorInfo); } if (constraints.Count > 0) { var symbolsBuilder = ArrayBuilder <TypeSymbol> .GetInstance(); MetadataDecoder tokenDecoder; if ((object)containingMethod != null) { tokenDecoder = new MetadataDecoder(moduleSymbol, containingMethod); } else { tokenDecoder = new MetadataDecoder(moduleSymbol, containingType); } foreach (var constraintHandle in constraints) { var constraint = metadataReader.GetGenericParameterConstraint(constraintHandle); var typeSymbol = tokenDecoder.DecodeGenericParameterConstraint(constraint.Type, out _); // Drop 'System.Object' constraint type. if (typeSymbol.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object) { continue; } // Drop 'System.ValueType' constraint type if the 'valuetype' constraint was also specified. if (((_flags & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) && (typeSymbol.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_ValueType)) { continue; } symbolsBuilder.Add(typeSymbol); } return(symbolsBuilder.ToImmutableAndFree()); } else { return(ImmutableArray <TypeSymbol> .Empty); } }
internal PEPropertySymbol( PEModuleSymbol moduleSymbol, PENamedTypeSymbol containingType, PropertyDefinitionHandle handle, PEMethodSymbol getMethod, PEMethodSymbol setMethod) { Debug.Assert((object)moduleSymbol != null); Debug.Assert((object)containingType != null); Debug.Assert(!handle.IsNil); _containingType = containingType; var module = moduleSymbol.Module; PropertyAttributes mdFlags = 0; BadImageFormatException mrEx = null; try { module.GetPropertyDefPropsOrThrow(handle, out _name, out mdFlags); } catch (BadImageFormatException e) { mrEx = e; if ((object)_name == null) { _name = string.Empty; } } _getMethod = getMethod; _setMethod = setMethod; _handle = handle; var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType); SignatureHeader callingConvention; BadImageFormatException propEx; var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx); Debug.Assert(propertyParams.Length > 0); SignatureHeader unusedCallingConvention; BadImageFormatException getEx = null; var getMethodParams = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx); BadImageFormatException setEx = null; var setMethodParams = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx); // NOTE: property parameter names are not recorded in metadata, so we have to // use the parameter names from one of the indexers. // NB: prefer setter names to getter names if both are present. bool isBad; _parameters = GetParameters(moduleSymbol, this, propertyParams, setMethodParams ?? getMethodParams, out isBad); //if (propEx != null || getEx != null || setEx != null || mrEx != null || isBad) //{ // _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this); //} _typeCustomModifiers = CSharpCustomModifier.Convert(propertyParams[0].CustomModifiers); // CONSIDER: Can we make parameter type computation lazy? TypeSymbol originalPropertyType = propertyParams[0].Type; _propertyType = originalPropertyType; // DynamicTypeDecoder.TransformType(originalPropertyType, _typeCustomModifiers.Length, handle, moduleSymbol); //// Dynamify object type if necessary //_propertyType = _propertyType.AsDynamicIfNoPia(_containingType); // A property is bogus and must be accessed by calling its accessors directly if the // accessor signatures do not agree, both with each other and with the property, // or if it has parameters and is not an indexer or indexed property. bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, _getMethod, getMethodParams, _setMethod, setMethodParams) || MustCallMethodsDirectlyCore(); if (!callMethodsDirectly) { //if ((object)_getMethod != null) //{ // _getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet); //} //if ((object)_setMethod != null) //{ // _setMethod.SetAssociatedProperty(this, MethodKind.PropertySet); //} } if (callMethodsDirectly) { _flags |= Flags.CallMethodsDirectly; } if ((mdFlags & PropertyAttributes.SpecialName) != 0) { _flags |= Flags.IsSpecialName; } if ((mdFlags & PropertyAttributes.RTSpecialName) != 0) { _flags |= Flags.IsRuntimeSpecialName; } }
private static bool DoSignaturesMatch( PEModule module, MetadataDecoder metadataDecoder, ParamInfo<TypeSymbol>[] propertyParams, PEMethodSymbol getMethod, ParamInfo<TypeSymbol>[] getMethodParams, PEMethodSymbol setMethod, ParamInfo<TypeSymbol>[] setMethodParams) { Debug.Assert((getMethodParams == null) == ((object)getMethod == null)); Debug.Assert((setMethodParams == null) == ((object)setMethod == null)); bool hasGetMethod = getMethodParams != null; bool hasSetMethod = setMethodParams != null; if (hasGetMethod && !metadataDecoder.DoPropertySignaturesMatch(propertyParams, getMethodParams, comparingToSetter: false, compareParamByRef: true, compareReturnType: true)) { return false; } if (hasSetMethod && !metadataDecoder.DoPropertySignaturesMatch(propertyParams, setMethodParams, comparingToSetter: true, compareParamByRef: true, compareReturnType: true)) { return false; } if (hasGetMethod && hasSetMethod) { var lastPropertyParamIndex = propertyParams.Length - 1; var getHandle = getMethodParams[lastPropertyParamIndex].Handle; var setHandle = setMethodParams[lastPropertyParamIndex].Handle; var getterHasParamArray = !getHandle.IsNil && module.HasParamsAttribute(getHandle); var setterHasParamArray = !setHandle.IsNil && module.HasParamsAttribute(setHandle); if (getterHasParamArray != setterHasParamArray) { return false; } if ((getMethod.IsExtern != setMethod.IsExtern) || // (getMethod.IsAbstract != setMethod.IsAbstract) || // NOTE: Dev10 accepts one abstract accessor (getMethod.IsSealed != setMethod.IsSealed) || (getMethod.IsOverride != setMethod.IsOverride) || (getMethod.IsStatic != setMethod.IsStatic)) { return false; } } return true; }
internal static PEParameterSymbol Create( PEModuleSymbol moduleSymbol, PEMethodSymbol containingSymbol, int ordinal, ParamInfo<TypeSymbol> parameter, out bool isBad) { return Create(moduleSymbol, containingSymbol, ordinal, parameter.IsByRef, parameter.CountOfCustomModifiersPrecedingByRef, parameter.Type, parameter.Handle, parameter.CustomModifiers, out isBad); }