private void InitializeSzArray(Cts.ArrayType entity, TypeSpecification record) { record.Signature = new SZArraySignature { ElementType = HandleType(entity.ElementType), }; }
protected override RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForNonPointerArrayType(ArrayType type) { if (_arrayOfTRuntimeInterfacesAlgorithm == null) { _arrayOfTRuntimeInterfacesAlgorithm = new ArrayOfTRuntimeInterfacesAlgorithm(SystemModule.GetType("System", "Array`1")); } return _arrayOfTRuntimeInterfacesAlgorithm; }
private void InitializeArray(Cts.ArrayType entity, TypeSpecification record) { record.Signature = new ArraySignature { ElementType = HandleType(entity.ElementType), Rank = entity.Rank, // TODO: LowerBounds // TODO: Sizes }; }
public override void AppendName(StringBuilder sb, ArrayType type) { AppendName(sb, type.ElementType); sb.Append('['); // NOTE: We're ignoring difference between SzArray and MdArray rank 1 for SigFormat.cpp compat. sb.Append(',', type.Rank - 1); sb.Append(']'); }
public override void AppendName(StringBuilder sb, ArrayType type) { AppendNameWithValueClassPrefix(sb, type.ElementType); sb.Append('['); sb.Append(',', type.Rank - 1); sb.Append(']'); }
private MetadataRecord HandleCustomAttributeConstantArray( Cts.ArrayType type, ImmutableArray <Ecma.CustomAttributeTypedArgument <Cts.TypeDesc> > value) { Cts.TypeDesc elementType = type.ElementType; switch (elementType.UnderlyingType.Category) { case Cts.TypeFlags.Boolean: return(new ConstantBooleanArray { Value = GetCustomAttributeConstantArrayElements <bool>(value) }); case Cts.TypeFlags.Byte: return(new ConstantByteArray { Value = GetCustomAttributeConstantArrayElements <byte>(value) }); case Cts.TypeFlags.Char: return(new ConstantCharArray { Value = GetCustomAttributeConstantArrayElements <char>(value) }); case Cts.TypeFlags.Double: return(new ConstantDoubleArray { Value = GetCustomAttributeConstantArrayElements <double>(value) }); case Cts.TypeFlags.Int16: return(new ConstantInt16Array { Value = GetCustomAttributeConstantArrayElements <short>(value) }); case Cts.TypeFlags.Int32: return(new ConstantInt32Array { Value = GetCustomAttributeConstantArrayElements <int>(value) }); case Cts.TypeFlags.Int64: return(new ConstantInt64Array { Value = GetCustomAttributeConstantArrayElements <long>(value) }); case Cts.TypeFlags.SByte: return(new ConstantSByteArray { Value = GetCustomAttributeConstantArrayElements <sbyte>(value) }); case Cts.TypeFlags.Single: return(new ConstantSingleArray { Value = GetCustomAttributeConstantArrayElements <float>(value) }); case Cts.TypeFlags.UInt16: return(new ConstantUInt16Array { Value = GetCustomAttributeConstantArrayElements <ushort>(value) }); case Cts.TypeFlags.UInt32: return(new ConstantUInt32Array { Value = GetCustomAttributeConstantArrayElements <uint>(value) }); case Cts.TypeFlags.UInt64: return(new ConstantUInt64Array { Value = GetCustomAttributeConstantArrayElements <ulong>(value) }); } if (elementType.IsString) { var record = new ConstantStringArray(); record.Value.Capacity = value.Length; foreach (var element in value) { MetadataRecord elementRecord = element.Value == null ? (MetadataRecord) new ConstantReferenceValue() : HandleString((string)element.Value); record.Value.Add(elementRecord); } return(record); } var result = new ConstantHandleArray(); result.Value.Capacity = value.Length; for (int i = 0; i < value.Length; i++) { MetadataRecord elementRecord = HandleCustomAttributeConstantValue(value[i].Type, value[i].Value); if (value[i].Type.IsEnum) { elementRecord = new ConstantBoxedEnumValue { Value = elementRecord, Type = HandleType(value[i].Type) }; } result.Value.Add(elementRecord); } return(result); }
public abstract void AppendName(StringBuilder sb, ArrayType type);
protected override RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForNonPointerArrayType(ArrayType type) { // At runtime, we're instantiating an Array<T> instantiation as the template, so we know we'll always have // a NativeLayoutInterfacesAlgorithm to work with return s_nativeLayoutInterfacesAlgorithm; }
/// <summary> /// Replace some of the types in a type's construction with a new set of types. This function does not /// support any situation where there is an instantiated generic that is not represented by an /// InstantiatedType. Does not replace the open generics that may be instantiated over in this type. /// /// For instance, Given MyType<object, int[]>, /// an array of types to replace such as {int,object}, and /// an array of replacement types such as {string,__Canon}. /// The result shall be MyType<__Canon, string[]> /// /// This function cannot be used to replace MyType in the above example. /// </summary> public static TypeDesc ReplaceTypesInConstructionOfType(this TypeDesc type, TypeDesc[] typesToReplace, TypeDesc[] replacementTypes) { int directReplacementIndex = Array.IndexOf(typesToReplace, type); if (directReplacementIndex != -1) { return(replacementTypes[directReplacementIndex]); } if (type.HasInstantiation) { TypeDesc[] newInstantiation = null; Debug.Assert(type is InstantiatedType); int instantiationIndex = 0; for (; instantiationIndex < type.Instantiation.Length; instantiationIndex++) { TypeDesc oldType = type.Instantiation[instantiationIndex]; TypeDesc newType = oldType.ReplaceTypesInConstructionOfType(typesToReplace, replacementTypes); if ((oldType != newType) || (newInstantiation != null)) { if (newInstantiation == null) { newInstantiation = new TypeDesc[type.Instantiation.Length]; for (int i = 0; i < instantiationIndex; i++) { newInstantiation[i] = type.Instantiation[i]; } } newInstantiation[instantiationIndex] = newType; } } if (newInstantiation != null) { return(type.Context.GetInstantiatedType((MetadataType)type.GetTypeDefinition(), new Instantiation(newInstantiation))); } } else if (type.IsParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType)type; TypeDesc oldParameter = parameterizedType.ParameterType; TypeDesc newParameter = oldParameter.ReplaceTypesInConstructionOfType(typesToReplace, replacementTypes); if (oldParameter != newParameter) { if (type.IsArray) { ArrayType arrayType = (ArrayType)type; if (arrayType.IsSzArray) { return(type.Context.GetArrayType(newParameter)); } else { return(type.Context.GetArrayType(newParameter, arrayType.Rank)); } } else if (type.IsPointer) { return(type.Context.GetPointerType(newParameter)); } else if (type.IsByRef) { return(type.Context.GetByRefType(newParameter)); } Debug.Fail("Unknown form of type"); } } else if (type.IsFunctionPointer) { MethodSignature oldSig = ((FunctionPointerType)type).Signature; MethodSignatureBuilder sigBuilder = new MethodSignatureBuilder(oldSig); sigBuilder.ReturnType = oldSig.ReturnType.ReplaceTypesInConstructionOfType(typesToReplace, replacementTypes); for (int paramIndex = 0; paramIndex < oldSig.Length; paramIndex++) { sigBuilder[paramIndex] = oldSig[paramIndex].ReplaceTypesInConstructionOfType(typesToReplace, replacementTypes); } MethodSignature newSig = sigBuilder.ToSignature(); if (newSig != oldSig) { return(type.Context.GetFunctionPointerType(newSig)); } } return(type); }
public override RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForNonPointerArrayType(ArrayType type) { throw new NotImplementedException(); }
/// <summary> /// Abstraction to allow the type system context to control the interfaces /// algorithm used by single dimensional array types. /// </summary> protected virtual RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForNonPointerArrayType(ArrayType type) { // Type system contexts that support computing runtime interfaces need to override this. throw new NotSupportedException(); }
/// <summary> /// Abstraction to allow the type system context to control the interfaces /// algorithm used by single dimensional array types. /// </summary> public abstract RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForNonPointerArrayType(ArrayType type);
/// <summary> /// Marshals an array. Expects the array reference on the stack. Pushes a pinned /// managed reference to the first element on the stack or null if the array was /// null or empty. /// </summary> /// <returns>Type the array was marshalled into.</returns> private TypeDesc EmitArrayMarshalling(ArrayType arrayType) { Debug.Assert(arrayType.IsSzArray); ILLocalVariable vPinnedFirstElement = _emitter.NewLocal(arrayType.ParameterType.MakeByRefType(), true); ILLocalVariable vArray = _emitter.NewLocal(arrayType); ILCodeLabel lNullArray = _emitter.NewCodeLabel(); // Check for null array, or 0 element array. _marshallingCodeStream.Emit(ILOpcode.dup); _marshallingCodeStream.EmitStLoc(vArray); _marshallingCodeStream.Emit(ILOpcode.brfalse, lNullArray); _marshallingCodeStream.EmitLdLoc(vArray); _marshallingCodeStream.Emit(ILOpcode.ldlen); _marshallingCodeStream.Emit(ILOpcode.conv_i4); _marshallingCodeStream.Emit(ILOpcode.brfalse, lNullArray); // Array has elements. _marshallingCodeStream.EmitLdLoc(vArray); _marshallingCodeStream.EmitLdc(0); _marshallingCodeStream.Emit(ILOpcode.ldelema, _emitter.NewToken(arrayType.ElementType)); _marshallingCodeStream.EmitStLoc(vPinnedFirstElement); // Fall through. If array didn't have elements, vPinnedFirstElement is zeroinit. _marshallingCodeStream.EmitLabel(lNullArray); _marshallingCodeStream.EmitLdLoc(vPinnedFirstElement); _marshallingCodeStream.Emit(ILOpcode.conv_i); return _context.GetWellKnownType(WellKnownType.IntPtr); }
public string FormatName(ArrayType type) { StringBuilder sb = new StringBuilder(); AppendName(sb, type); return sb.ToString(); }
internal ArrayMethod(ArrayType owningType, ArrayMethodKind kind) { _owningType = owningType; _kind = kind; }