/// <summary> /// Initializes a new instance of the <see cref="ParameterSignature" /> class. /// </summary> /// <param name="name">The parameter name.</param> /// <param name="parameterType">The parameter type.</param> /// <param name="isOutParameter">if set to <c>true</c>, this is an out parameter.</param> /// <param name="isRefParameter">if set to <c>true</c>, this is a reference parameter.</param> public ParameterSignature(string name, TypeSignature parameterType, bool isOutParameter, bool isRefParameter) { Name = name; ParameterType = parameterType; IsOutParameter = isOutParameter; IsRefParameter = isRefParameter; }
/// <summary> /// Initializes a new instance of the <see cref="PropertySignature"/> class. /// </summary> /// <param name="identity">The Identity.</param> /// <param name="name">The name of the property.</param> /// <param name="declaringType">The declaring type.</param> /// <param name="propertyType">The property type.</param> public PropertySignature( string identity, string name, TypeSignature declaringType, TypeSignature propertyType) { Identity = identity; Name = name; DeclaringType = declaringType; PropertyType = propertyType; }
/// <summary> /// Initializes a new instance of the <see cref="PropertySignature"/> class. /// </summary> /// <param name="identity">The Identity.</param> /// <param name="name">The name of the property.</param> /// <param name="declaringType">The declaring type.</param> /// <param name="propertyType">The property type.</param> public PropertySignature( string identity, string name, TypeSignature declaringType, TypeSignature propertyType) { _identity = identity; _name = name; _declaringType = declaringType; _propertyType = propertyType; }
/// <summary> /// Gets the type of the dynamic object builder. /// </summary> /// <param name="properties">The properties.</param> /// <returns></returns> public static Type GetDynamicObjectBuilderType(IEnumerable<SLDataColumn> properties) { Type type; var signature = new TypeSignature(properties); if (!TypesCache.TryGetValue(signature, out type)) { type = CreateDynamicObjectBuilderType(properties); TypesCache.Add(signature, type); } return type; }
internal static Type GetDynamicObjectBuilderType(ThrowingHashSet<IPropertyInfo> properties) { lock (SyncRoot) { TypeSignature signature = new TypeSignature(properties); Type type; if (!TypesCache.TryGetValue(signature, out type)) { type = CreateDynamicObjectBuilderType(properties); TypesCache.Add(signature, type); } return type; } }
/// <summary> /// Creates a method signature for an instance method that has a number of parameters. /// </summary> /// <param name="returnType">The return type of the method.</param> /// <param name="parameterTypes">The parameter types.</param> /// <returns>The signature.</returns> public static MethodSignature CreateInstance(TypeSignature returnType, IEnumerable <TypeSignature> parameterTypes) => new MethodSignature(CallingConventionAttributes.HasThis, returnType, parameterTypes);
/// <summary> /// Creates a method signature for a static method that has a number of parameters. /// </summary> /// <param name="returnType">The return type of the method.</param> /// <param name="parameterTypes">The parameter types.</param> /// <returns>The signature.</returns> public static MethodSignature CreateStatic(TypeSignature returnType, IEnumerable <TypeSignature> parameterTypes) => new MethodSignature(0, returnType, parameterTypes);
/// <summary> /// Creates a new parameter-less method signature for a static method. /// </summary> /// <param name="returnType">The return type of the method.</param> /// <returns>The signature.</returns> public static MethodSignature CreateStatic(TypeSignature returnType) => new MethodSignature(0, returnType, Enumerable.Empty <TypeSignature>());
internal ParameterSignature(TypeSignature type, bool isByRef) { Type = type; IsByRef = isByRef; }
public FunctionSignatureBuilder WithReturnType([NotNull] TypeSignature newReturnType) { _newReturnType = newReturnType; return(this); }
/// <summary> /// Creates a new field by type signature. /// </summary> internal FieldEntity CreateField(string name, TypeSignature signature, bool isStatic = false, bool prepare = false) { var fe = createFieldCore(name, isStatic, prepare); fe.TypeSignature = signature; return fe; }
internal static ArrayTypeSignature Array(TypeSignature elementType, int rank) { return new ArrayTypeSignature(elementType, rank); }
internal static PointerTypeSignature Pointer(TypeSignature pointedAtType) { return new PointerTypeSignature(pointedAtType); }
public DefaultOperatorNode(TypeSignature type = null) { TypeSignature = type; }
internal static QualifiedTypeSignature Qualified(TypeSignature left, string right) { return new QualifiedTypeSignature(left, right); }
/// <summary> /// Returns a handle to a helper function for creating a new Object instance from the /// keys and values on the stack. This is used for the newobject ABC instruction. The keys /// must be of the String type and the values must be of the "any" type. /// </summary> /// <param name="size">The size argument to the newarray instruction, i.e. the number of /// key-value pairs on the stack.</param> /// <param name="handle">If a helper function is available or can be emitted, a handle to /// the function is set to this argument.</param> /// <returns>True if a helper function is available or can be created, otherwise false.</returns> public bool tryGetNewObjectHelper(int size, out EntityHandle handle) { handle = default; if (size > newObjectHelperMaxSize) { return(false); } if (m_newObjectHelperMethods[size] != null) { handle = m_newObjectHelperMethods[size].handle; return(true); } _createContainerTypeIfNotCreated(); TypeSignature[] parameterTypes = new TypeSignature[size * 2]; var typeSigForString = TypeSignature.forPrimitiveType(PrimitiveTypeCode.String); var typeSigForAny = m_assemblyBuilder.metadataContext.getTypeSignature(typeof(ASAny)); for (int i = 0; i < parameterTypes.Length; i++) { parameterTypes[i] = ((i & 1) == 0) ? typeSigForString : typeSigForAny; } string methodName = "newobject" + size.ToString(CultureInfo.InvariantCulture); var methodBuilder = m_containerType !.defineMethod( methodName, MethodAttributes.Public | MethodAttributes.Static, m_assemblyBuilder.metadataContext.getTypeSignature(typeof(ASObject)), parameterTypes ); m_ilBuilder.reset(); var objLocal = m_ilBuilder.declareLocal(typeof(ASObject)); var dpLocal = m_ilBuilder.declareLocal(typeof(DynamicPropertyCollection)); m_ilBuilder.emit(ILOp.newobj, KnownMembers.objectCtor); m_ilBuilder.emit(ILOp.dup); m_ilBuilder.emit(ILOp.call, KnownMembers.getObjectDynamicPropCollection, 0); m_ilBuilder.emit(ILOp.stloc, dpLocal); m_ilBuilder.emit(ILOp.stloc, objLocal); // Object properties are set in top-to-bottom stack order. // So for example if the arguments are "a", 1, "b", 2, "a", 3 then the value of the property // "a" in the created object is 1, not 3. for (int i = size - 1; i >= 0; i--) { m_ilBuilder.emit(ILOp.ldloc, dpLocal); m_ilBuilder.emit(ILOp.ldarg, 2 * i); m_ilBuilder.emit(ILOp.ldarg, 2 * i + 1); m_ilBuilder.emit(ILOp.ldc_i4_1); // isEnum = true m_ilBuilder.emit(ILOp.call, KnownMembers.dynamicPropCollectionSet, -4); } m_ilBuilder.emit(ILOp.ldloc, objLocal); m_ilBuilder.emit(ILOp.ret); methodBuilder.setMethodBody(m_ilBuilder.createMethodBody()); m_newObjectHelperMethods[size] = methodBuilder; handle = methodBuilder.handle; return(true); }
public static Func <E.TypeDef, E.TypeDef> ImplementTraversable(TypeSignature declaringType, (TypeField schema, FieldReference field)[] fields)
public Function(TypeSignature ret, string name, List <Argument> args) { ReturnTypeSignature = ret; Name = name; ArgumentsList = args; }
private void UnsupportedArgumentType(TypeSignature argumentType) { _context.DiagnosticBag.RegisterException( new NotSupportedException($"Invalid or unsupported argument type {argumentType.FullName}.")); }
/// <summary> /// Creates a new security attribute with the provided type. /// </summary> /// <param name="type">The security attribute type.</param> public SecurityAttribute(TypeSignature type) { AttributeType = type; }
WildcardTypeSignature(TypeSignatureKind typeSignatureKind, TypeSignature bound) : super(typeSignatureKind, "*") {
private static TDescriptor BuildAppWithDescriptor <TDescriptor>(WindowsAssembly assembly, TypeSignature fieldType, TDescriptor descriptor, bool saveToDisk) where TDescriptor : MarshalDescriptor { const string fieldName = "MyField"; // set up temp assembly. var tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>(); var fieldTable = tableStream.GetTable <FieldDefinition>(); var fieldMarshalTable = tableStream.GetTable <FieldMarshal>(); // create temp field. var field = new FieldDefinition(fieldName, FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.HasFieldRva, new FieldSignature(fieldType)); fieldTable.Add(field); // create field marshal. var marshal = new FieldMarshal(field, descriptor); field.FieldMarshal = marshal; fieldMarshalTable.Add(marshal); // build and validate. assembly = Utilities.RebuildNetAssembly(assembly, saveToDisk); tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>(); fieldTable = tableStream.GetTable <FieldDefinition>(); field = fieldTable.FirstOrDefault(x => x.Name == fieldName); Assert.IsNotNull(field); Assert.IsNotNull(field.FieldMarshal); Assert.AreEqual(descriptor.NativeType, field.FieldMarshal.MarshalDescriptor.NativeType); Assert.IsInstanceOfType(field.FieldMarshal.MarshalDescriptor, typeof(TDescriptor)); return((TDescriptor)field.FieldMarshal.MarshalDescriptor); }
/// <summary> /// Creates a new method with argument types given by function arguments. /// </summary> internal MethodEntity CreateMethod(string name, TypeSignature returnType, IEnumerable<FunctionArgument> args = null, bool isStatic = false, bool isVirtual = false, bool prepare = true) { return createMethodCore(name, isStatic, isVirtual, prepare, me => { me.Arguments = new HashList<FunctionArgument>(args, x => x.Name); me.ReturnTypeSignature = returnType; } ); }
public TypeDesc(Type pt, TypeSignature ts, int b) { PinType = pt; TypeSig = ts; Size = b; }
/// <summary> /// Creates a new method with argument types given by function arguments. /// </summary> internal MethodEntity CreateMethod(string name, TypeSignature returnType, IEnumerable<FunctionArgument> args = null, bool isStatic = false, bool isVirtual = false, bool prepare = false) { var argHash = new HashList<FunctionArgument>(); if(args != null) foreach (var curr in args) argHash.Add(curr.Name, curr); var me = createMethodCore(name, isStatic, isVirtual, prepare); me.ReturnTypeSignature = returnType; me.Arguments = argHash; return me; }
private static QualifiedTypeSignature Qualified(TypeSignature left, string right) { return(new QualifiedTypeSignature(left, right)); }
/// <summary> /// Initializes a new member signature. /// </summary> /// <param name="attributes">The attributes of the signature.</param> /// <param name="memberReturnType">The type of the object this member returns or contains.</param> protected MemberSignature(CallingConventionAttributes attributes, TypeSignature memberReturnType) : base(attributes) { MemberReturnType = memberReturnType; }
private static ArrayTypeSignature Array(TypeSignature elementType, int rank) { return(new ArrayTypeSignature(elementType, rank)); }
/// <summary> /// Creates a new method signature with the provided return and parameter types. /// </summary> /// <param name="attributes">The attributes.</param> /// <param name="returnType">The return type of the method.</param> /// <param name="parameterTypes">The types of the parameter the method defines.</param> public MethodSignature(CallingConventionAttributes attributes, TypeSignature returnType, IEnumerable <TypeSignature> parameterTypes) : base(attributes, returnType, parameterTypes) { }
private static PointerTypeSignature Pointer(TypeSignature pointedAtType) { return(new PointerTypeSignature(pointedAtType)); }
/// <summary> /// Creates a method signature for a static method that has a number of parameters. /// </summary> /// <param name="returnType">The return type of the method.</param> /// <param name="parameterTypes">The parameter types.</param> /// <returns>The signature.</returns> public static MethodSignature CreateStatic(TypeSignature returnType, params TypeSignature[] parameterTypes) => new MethodSignature(0, returnType, parameterTypes);
public virtual TypeSignature ImportTypeSignature(TypeSignature signature) { if (signature is MsCorLibTypeSignature) { return(signature); } var typeDefOrRef = signature as TypeDefOrRefSignature; if (typeDefOrRef != null) { return(ImportTypeDefOrRefSignature(typeDefOrRef)); } var arrayType = signature as ArrayTypeSignature; if (arrayType != null) { return(ImportArrayTypeSignature(arrayType)); } var boxedType = signature as BoxedTypeSignature; if (boxedType != null) { return(ImportBoxedTypeSignature(boxedType)); } var byRefType = signature as ByReferenceTypeSignature; if (byRefType != null) { return(ImportByRefTypeSignature(byRefType)); } var functionPtrType = signature as FunctionPointerTypeSignature; if (functionPtrType != null) { return(ImportFunctionPointerTypeSignature(functionPtrType)); } var genericType = signature as GenericInstanceTypeSignature; if (genericType != null) { return(ImportGenericInstanceTypeSignature(genericType)); } var modOptType = signature as OptionalModifierSignature; if (modOptType != null) { return(ImportOptionalModifierSignature(modOptType)); } var pinnedType = signature as PinnedTypeSignature; if (pinnedType != null) { return(ImportPinnedTypeSignature(pinnedType)); } var pointerType = signature as PointerTypeSignature; if (pointerType != null) { return(ImportPointerTypeSignature(pointerType)); } var modReqType = signature as RequiredModifierSignature; if (modReqType != null) { return(ImportRequiredModifierSignature(modReqType)); } var sentinelType = signature as SentinelTypeSignature; if (sentinelType != null) { return(ImportSentinelTypeSignature(sentinelType)); } var szArrayType = signature as SzArrayTypeSignature; if (szArrayType != null) { return(ImportSzArrayTypeSignature(szArrayType)); } var genericParameter = signature as GenericParameterSignature; if (genericParameter != null) { return(ImportGenericParameterSignature(genericParameter)); } throw new NotSupportedException("Invalid or unsupported type signature."); }
/// <summary> /// Creates a new parameter-less method signature for an instance method. /// </summary> /// <param name="returnType">The return type of the method.</param> /// <returns>The signature.</returns> public static MethodSignature CreateInstance(TypeSignature returnType) => new MethodSignature(CallingConventionAttributes.HasThis, returnType, Enumerable.Empty <TypeSignature>());
public void ParameterDefaultValues() { var type = TypeSignature.Interface("MyInterface2", ns, Accessibility.APublic); var method1 = MethodSignature.Instance("StringMethod", type, Accessibility.APublic, TypeSignature.Int32, new MethodParameter(TypeSignature.String, "myParameter").WithDefault("default value")); var method2 = MethodSignature.Instance("ValueTypeMethod", type, Accessibility.APublic, TypeSignature.Int32, new MethodParameter(TypeSignature.FromType(typeof(Guid)), "myParameter").WithDefault(null)); var typeDef = TypeDef.Empty(type) .AddMember(MethodDef.InterfaceDef(method1)) .AddMember(MethodDef.InterfaceDef(method2)); cx.AddType(typeDef); check.CheckOutput(cx); }
/// <summary> /// Builds up an assembly qualified type name. /// </summary> /// <param name="signature">The type to convert to a string.</param> /// <returns>The built up type name.</returns> public static string GetAssemblyQualifiedName(TypeSignature signature) => GetAssemblyQualifiedName(signature, true);
private TypeSignature ParseByReferenceTypeSpec(TypeSignature typeName) { Expect(TypeNameTerminal.Ampersand); return(new ByReferenceTypeSignature(typeName)); }
private void WriteElement(TypeSignature argumentType, object element) { var writer = _context.Writer; if (argumentType.IsTypeOf("System", "Type")) { writer.WriteSerString(TypeNameBuilder.GetAssemblyQualifiedName((TypeSignature)element)); return; } switch (argumentType.ElementType) { case ElementType.Boolean: writer.WriteByte((byte)((bool)element ? 1 : 0)); break; case ElementType.Char: writer.WriteUInt16((char)element); break; case ElementType.I1: writer.WriteSByte((sbyte)element); break; case ElementType.U1: writer.WriteByte((byte)element); break; case ElementType.I2: writer.WriteInt16((short)element); break; case ElementType.U2: writer.WriteUInt16((ushort)element); break; case ElementType.I4: writer.WriteInt32((int)element); break; case ElementType.U4: writer.WriteUInt32((uint)element); break; case ElementType.I8: writer.WriteInt64((long)element); break; case ElementType.U8: writer.WriteUInt64((ulong)element); break; case ElementType.R4: writer.WriteSingle((float)element); break; case ElementType.R8: writer.WriteDouble((double)element); break; case ElementType.String: writer.WriteSerString(element as string); break; case ElementType.Object: TypeSignature innerTypeSig; object value; if (element is null) { // Most efficient way to store "null" is writing null as a string (two bytes). innerTypeSig = argumentType.Module.CorLibTypeFactory.String; value = null; } else if (element is BoxedArgument boxedArgument) { // Write the boxed argument. innerTypeSig = boxedArgument.Type; value = boxedArgument.Value; } else { _context.DiagnosticBag.RegisterException(new NotSupportedException( $"Object elements in a custom attribute signature should be either 'null' or an instance of {nameof(BoxedArgument)}.")); // Write null as a recovery. innerTypeSig = argumentType.Module.CorLibTypeFactory.String; value = null; } TypeSignature.WriteFieldOrPropType(writer, innerTypeSig); WriteElement(innerTypeSig, value); break; case ElementType.SzArray: WriteArrayElement( (SzArrayTypeSignature)argumentType, element as IList <object> ?? new object[0], element == null); break; case ElementType.Class: case ElementType.Enum: case ElementType.ValueType: WriteEnumValue(argumentType, element); break; default: UnsupportedArgumentType(argumentType); break; } }
private TypeSignature ParsePointerTypeSpec(TypeSignature typeName) { Expect(TypeNameTerminal.Star); return(new PointerTypeSignature(typeName)); }
private static TagDataEntry GetEntry(TypeSignature type, int idx, ICCHeader header) { switch (type) { case TypeSignature.chromaticity: return new chromaticityTagDataEntry(idx); case TypeSignature.colorantOrder: return new colorantOrderTagDataEntry(idx); case TypeSignature.colorantTable: return new colorantTableTagDataEntry(idx); case TypeSignature.curve: return new curveTagDataEntry(idx); case TypeSignature.data: return new dataTagDataEntry(idx); case TypeSignature.dateTime: return new dateTimeTagDataEntry(idx); case TypeSignature.lut16: return new lut16TagDataEntry(idx); case TypeSignature.lut8: return new lut8TagDataEntry(idx); case TypeSignature.lutAToB: return new lutAToBTagDataEntry(idx); case TypeSignature.lutBToA: return new lutBToATagDataEntry(idx); case TypeSignature.measurement: return new measurementTagDataEntry(idx); case TypeSignature.multiLocalizedUnicode: return new multiLocalizedUnicodeTagDataEntry(idx, false); case TypeSignature.multiProcessElements: return new multiProcessElementsTagDataEntry(idx); case TypeSignature.namedColor2: return new namedColor2TagDataEntry(idx); case TypeSignature.parametricCurve: return new parametricCurveTagDataEntry(idx); case TypeSignature.profileSequenceDesc: return new profileSequenceDescTagDataEntry(idx, header); case TypeSignature.profileSequenceIdentifier: return new profileSequenceIdentifierTagDataEntry(idx); case TypeSignature.responseCurveSet16: return new responseCurveSet16TagDataEntry(idx); case TypeSignature.s15Fixed16Array: return new s15Fixed16ArrayTagDataEntry(idx); case TypeSignature.signature: return new signatureTagDataEntry(idx); case TypeSignature.text: return new textTagDataEntry(idx); case TypeSignature.u16Fixed16Array: return new u16Fixed16ArrayTagDataEntry(idx); case TypeSignature.uInt16Array: return new uInt16ArrayTagDataEntry(idx); case TypeSignature.uInt32Array: return new uInt32ArrayTagDataEntry(idx); case TypeSignature.uInt64Array: return new uInt64ArrayTagDataEntry(idx); case TypeSignature.uInt8Array: return new uInt8ArrayTagDataEntry(idx); case TypeSignature.viewingConditions: return new viewingConditionsTagDataEntry(idx); case TypeSignature.XYZ: return new XYZTagDataEntry(idx); default: return new TagDataEntry(); } }
private void PrintTypeSig(TypeSignature typeSig) { switch (typeSig.ElementCode) { case TypeElementCode.Array: { if (typeSig.ElementType != null) { PrintTypeSig(typeSig.ElementType); } PrintArrayDimensions(typeSig.ArrayDimensions); } break; case TypeElementCode.ByRef: { if (typeSig.ElementType != null) { PrintTypeSig(typeSig.ElementType); } _builder.Append("&"); } break; case TypeElementCode.CustomModifier: { if (typeSig.ElementType != null) { PrintTypeSig(typeSig.ElementType); } } break; case TypeElementCode.FunctionPointer: { var callSite = ((FunctionPointer)typeSig).CallSite; PrintTypeSig(callSite.ReturnType); _builder.Append(" *"); PrintMethodArguments(callSite.Arguments); } break; case TypeElementCode.GenericParameter: { PrintGenericParameterType((GenericParameterType)typeSig); } break; case TypeElementCode.GenericType: { PrintTypeRef(typeSig.DeclaringType, typeSig.GenericArguments.Count > 0); PrintGenericArguments(typeSig.GenericArguments); } break; case TypeElementCode.Pinned: { if (typeSig.ElementType != null) { PrintTypeSig(typeSig.ElementType); } } break; case TypeElementCode.Pointer: { if (typeSig.ElementType != null) { PrintTypeSig(typeSig.ElementType); } _builder.Append("*"); } break; case TypeElementCode.DeclaringType: PrintTypeRef((TypeReference)typeSig); break; default: throw new InvalidOperationException(); } }
internal ParameterSignature(TypeSignature type, bool isByRef) { Type = type; IsByRef = isByRef; }
: super(typeSignatureKind, "*") { this.bound = bound; }
/// <summary> /// Creates a new field by type signature. /// </summary> internal FieldEntity CreateField(string name, TypeSignature signature, bool isStatic = false, bool prepare = true) { return createFieldCore(name, isStatic, prepare, fe => fe.TypeSignature = signature); }
/// <summary> /// Creates a new method with argument types given by signatures. /// </summary> internal MethodEntity CreateMethod(string name, TypeSignature returnType, string[] argTypes = null, bool isStatic = false, bool isVirtual = false, bool prepare = true) { var args = argTypes?.Select((a, idx) => new FunctionArgument("arg" + idx.ToString(), a)).ToArray(); return(CreateMethod(name, returnType, args, isStatic, isVirtual, prepare)); }
/// <summary> /// Creates a new method with argument types given by signatures. /// </summary> internal MethodEntity CreateMethod(string name, TypeSignature returnType, string[] argTypes = null, bool isStatic = false, bool isVirtual = false, bool prepare = false) { var args = argTypes == null ? null : argTypes.Select((a, idx) => new FunctionArgument("arg" + idx.ToString(), a)).ToArray(); return CreateMethod(name, returnType, args, isStatic, isVirtual, prepare); }
public ParameterSignatureBuilder WithType([NotNull] TypeSignature newType) { _newType = newType; return(this); }
/// <summary> /// Creates a new field by type signature. /// </summary> internal FieldEntity CreateField(string name, TypeSignature signature, bool isStatic = false, bool prepare = true) { return(CreateFieldCore(name, isStatic, prepare, fe => fe.TypeSignature = signature)); }
ArrayTypeSignature(TypeSignature elementType) : super(TypeSignatureKind.ArrayType, "[" + elementType.Name) {