public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers) { for (int i = 0; i < arguments.Length; i++) { __AddArgument(arguments[i], false, CustomModifiers.FromReqOpt(requiredCustomModifiers[i], optionalCustomModifiers[i])); } }
internal LocalVariableInfo(int index, Type type, bool pinned, CustomModifiers customModifiers) { this.index = index; this.type = type; this.pinned = pinned; this.customModifiers = customModifiers; }
void WriteInlineType(LineWriter lw, int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) { CustomModifiers mods = new CustomModifiers(); if (metadataToken >> 24 == 0x1B) { mods = module.__ResolveTypeSpecCustomModifiers(metadataToken, genericTypeArguments, genericMethodArguments); } if (!mods.IsEmpty) { lw.Write("class "); } Type type = ResolveType(metadataToken, genericTypeArguments, genericMethodArguments); if (type.HasElementType) { WriteSignatureType(lw, type); } else if (!type.__IsMissing && type.IsGenericType) { WriteSignatureType(lw, type, TypeLocation.General); } else { WriteTypeDefOrRef(lw, type); } if (!mods.IsEmpty) { WriteCustomModifiers(lw, mods); } }
public FieldBuilder __DefineField(string fieldName, Type type, CustomModifiers customModifiers, FieldAttributes attributes) { FieldBuilder fb = new FieldBuilder(this, fieldName, type, customModifiers, attributes); fields.Add(fb); return(fb); }
public void SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers) { method.signature = new MethodSignature( returnType ?? method.Module.universe.System_Void, Util.Copy(parameterTypes), PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, parameterTypes.Length), method.signature.CallingConvention, method.signature.GenericParameterCount); }
public static SignatureHelper GetPropertySigHelper(Module mod, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers) { SignatureHelper sig = new SignatureHelper(mod as ModuleBuilder, Signature.PROPERTY); sig.callingConvention = callingConvention; sig.returnType = returnType; sig.returnTypeCustomModifiers = CustomModifiers.FromReqOpt(requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers); sig.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers); return(sig); }
// this adds the custom modifiers in the same order as the normal SRE APIs // (the advantage over using the SRE APIs is that a CustomModifiers object is slightly more efficient, // because unlike the Type arrays it doesn't need to be copied) public void Add(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers) { foreach (CustomModifiers.Entry entry in CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers)) { Item item; item.type = entry.Type; item.required = entry.IsRequired; list.Add(item); } }
public LocalBuilder __DeclareLocal(Type localType, bool pinned, CustomModifiers customModifiers) { LocalBuilder local = new LocalBuilder(localType, localsCount++, pinned); locals.__AddArgument(localType, pinned, customModifiers); if (scope != null) { scope.locals.Add(local); } return local; }
public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers) { if (arguments != null) { for (int i = 0; i < arguments.Length; i++) { __AddArgument(arguments[i], false, CustomModifiers.FromReqOpt(Util.NullSafeElementAt(requiredCustomModifiers, i), Util.NullSafeElementAt(optionalCustomModifiers, i))); } } }
internal FieldBuilder(TypeBuilder type, string name, Type fieldType, CustomModifiers customModifiers, FieldAttributes attribs) { this.typeBuilder = type; this.name = name; this.pseudoToken = type.ModuleBuilder.AllocPseudoToken(); this.nameIndex = type.ModuleBuilder.Strings.Add(name); this.fieldSig = FieldSignature.Create(fieldType, customModifiers); ByteBuffer sig = new ByteBuffer(5); fieldSig.WriteSig(this.typeBuilder.ModuleBuilder, sig); this.signature = this.typeBuilder.ModuleBuilder.Blobs.Add(sig); this.attribs = attribs; this.typeBuilder.ModuleBuilder.Field.AddVirtualRecord(); }
internal static PackedCustomModifiers CreateFromExternal(CustomModifiers returnTypeCustomModifiers, CustomModifiers[] parameterTypeCustomModifiers, int parameterCount) { CustomModifiers[] customModifiers = null; Pack(ref customModifiers, 0, returnTypeCustomModifiers, parameterCount + 1); if (parameterTypeCustomModifiers != null) { for (int i = 0; i < parameterCount; i++) { Pack(ref customModifiers, i + 1, parameterTypeCustomModifiers[i], parameterCount + 1); } } return new PackedCustomModifiers(customModifiers); }
public override void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers) { if (pinned) { bb.Write(Signature.ELEMENT_TYPE_PINNED); } foreach (CustomModifiers.Entry mod in customModifiers) { bb.Write(mod.IsRequired ? Signature.ELEMENT_TYPE_CMOD_REQD : Signature.ELEMENT_TYPE_CMOD_OPT); Signature.WriteTypeSpec(module, bb, mod.Type); } Signature.WriteTypeSpec(module, bb, argument ?? module.universe.System_Void); paramCount++; }
public override void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers) { if (pinned) { args.Add(MarkerType.Pinned); } foreach (CustomModifiers.Entry mod in customModifiers) { args.Add(mod.IsRequired ? MarkerType.ModReq : MarkerType.ModOpt); args.Add(mod.Type); } args.Add(argument); paramCount++; }
public void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers) { if (type == Signature.LOCAL_SIG) { locals.Add(new LocalBuilder(argument, 0, pinned)); } else if (optional) { this.optionalArgs.Add(argument); } else { this.args.Add(argument); } this.customModifiers.Add(customModifiers); }
public override CustomModifiers[] __GetGenericParameterConstraintCustomModifiers() { IGenericContext context = (this.DeclaringMethod as IGenericContext) ?? this.DeclaringType; List <CustomModifiers> list = new List <CustomModifiers>(); foreach (int i in module.GenericParamConstraint.Filter(this.MetadataToken)) { CustomModifiers mods = new CustomModifiers(); int metadataToken = module.GenericParamConstraint.records[i].Constraint; if ((metadataToken >> 24) == TypeSpecTable.Index) { int index = (metadataToken & 0xFFFFFF) - 1; mods = CustomModifiers.Read(module, module.GetBlob(module.TypeSpec.records[index]), context); } list.Add(mods); } return(list.ToArray()); }
public LocalBuilder __DeclareLocal(Type localType, bool pinned, CustomModifiers customModifiers) { if (!customModifiers.IsEmpty) { if (localCustomModifiers == null) { localCustomModifiers = new List <CustomModifiers>(); } // we lazily fill up the list (to sync with the locals list) and we don't need to // make sure that the list has the same length as the locals list, because // Signature.WriteLocalVarSig() can tolerate that. while (localCustomModifiers.Count < locals.Count) { localCustomModifiers.Add(new CustomModifiers()); } localCustomModifiers.Add(customModifiers); } return(DeclareLocal(localType, pinned)); }
public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers) { SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes))); }
internal static Type Make(Type type, CustomModifiers mods) { return type.Universe.CanonicalizeType(new PointerType(type, mods)); }
public PropertyBuilder __DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers) { return DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes))); }
public abstract void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers);
public FieldBuilder __DefineField(string fieldName, Type type, CustomModifiers customModifiers, FieldAttributes attributes) { FieldBuilder fb = new FieldBuilder(this, fieldName, type, customModifiers, attributes); fields.Add(fb); return fb; }
internal LocalBuilder(Type localType, int index, bool pinned, CustomModifiers customModifiers) : base(index, localType, pinned, customModifiers) { }
private PackedCustomModifiers(CustomModifiers[] customModifiers) { this.customModifiers = customModifiers; }
internal static PackedCustomModifiers Wrap(CustomModifiers[] modifiers) { return new PackedCustomModifiers(modifiers); }
internal static FieldSignature Create(Type fieldType, CustomModifiers customModifiers) { return new FieldSignature(fieldType, customModifiers); }
protected override Type Wrap(Type type, CustomModifiers mods) { return Make(type, mods); }
internal LocalVariableInfo(int index, Type type, bool pinned, CustomModifiers customModifiers) : this(index, type, pinned) { this.customModifiers = customModifiers; }
internal static Type Make(Type type, Type[] typeArguments, CustomModifiers[] mods) { bool identity = true; if (type is TypeBuilder || type is BakedType || type.__IsMissing) { // a TypeBuiler identity must be instantiated identity = false; } else { // we must not instantiate the identity instance, because typeof(Foo<>).MakeGenericType(typeof(Foo<>).GetGenericArguments()) == typeof(Foo<>) for (int i = 0; i < typeArguments.Length; i++) { if (typeArguments[i] != type.GetGenericTypeArgument(i) || !IsEmpty(mods, i)) { identity = false; break; } } } if (identity) { return type; } else { return type.Universe.CanonicalizeType(new GenericTypeInstance(type, typeArguments, mods)); } }
private FieldSignature(Type fieldType, CustomModifiers mods) { this.fieldType = fieldType; this.mods = mods; }
public void AddArgument(Type argument, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers) { __AddArgument(argument, false, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers)); }
public abstract Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers);
// this reads just the optional parameter types, from a MethodRefSig internal static Type[] ReadOptionalParameterTypes(ModuleReader module, ByteReader br, IGenericContext context, out CustomModifiers[] customModifiers) { br.ReadByte(); int paramCount = br.ReadCompressedUInt(); CustomModifiers.Skip(br); ReadRetType(module, br, context); for (int i = 0; i < paramCount; i++) { if (br.PeekByte() == SENTINEL) { br.ReadByte(); Type[] types = new Type[paramCount - i]; customModifiers = new CustomModifiers[types.Length]; for (int j = 0; j < types.Length; j++) { customModifiers[j] = CustomModifiers.Read(module, br, context); types[j] = ReadType(module, br, context); } return types; } CustomModifiers.Skip(br); ReadType(module, br, context); } customModifiers = Empty<CustomModifiers>.Array; return Type.EmptyTypes; }
public sealed override Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers) { throw ArgumentOutOfRangeException(); }
public FieldBuilder DefineField(string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes) { return(__DefineField(fieldName, type, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers), attributes)); }
internal void WriteMethodRefSig(ModuleBuilder module, ByteBuffer bb, Type[] optionalParameterTypes, CustomModifiers[] customModifiers) { WriteSigImpl(module, bb, parameterTypes.Length + optionalParameterTypes.Length); if (optionalParameterTypes.Length > 0) { bb.Write(SENTINEL); for (int i = 0; i < optionalParameterTypes.Length; i++) { WriteCustomModifiers(module, bb, Util.NullSafeElementAt(customModifiers, i)); WriteType(module, bb, optionalParameterTypes[i]); } } }
public PropertyBuilder __DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers) { return(DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)))); }
internal PackedCustomModifiers Bind(IGenericBinder binder) { if (customModifiers == null) { return new PackedCustomModifiers(); } CustomModifiers[] expanded = new CustomModifiers[customModifiers.Length]; for (int i = 0; i < customModifiers.Length; i++) { expanded[i] = customModifiers[i].Bind(binder); } return new PackedCustomModifiers(expanded); }
private static bool IsEmpty(CustomModifiers[] mods, int i) { // we need to be extra careful, because mods doesn't not need to be in canonical format // (Signature.ReadGenericInst() calls Make() directly, without copying the modifier arrays) return mods == null || mods[i].IsEmpty; }
internal static void Pack(ref CustomModifiers[] array, int index, CustomModifiers mods, int count) { if (!mods.IsEmpty) { if (array == null) { array = new CustomModifiers[count]; } array[index] = mods; } }
public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers) { methodBuilder.__SetSignature(returnType, returnTypeCustomModifiers, parameterTypes, parameterTypeCustomModifiers); }
protected static void WriteCustomModifiers(ModuleBuilder module, ByteBuffer bb, CustomModifiers modifiers) { foreach (CustomModifiers.Entry entry in modifiers) { bb.Write(entry.IsRequired ? ELEMENT_TYPE_CMOD_REQD : ELEMENT_TYPE_CMOD_OPT); bb.WriteTypeDefOrRefEncoded(module.GetTypeTokenForMemberRef(entry.Type)); } }
private PointerType(Type type, CustomModifiers mods) : base(type, mods) { }
private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context) { Type type; switch (br.ReadByte()) { case ELEMENT_TYPE_CLASS: type = ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType(); break; case ELEMENT_TYPE_VALUETYPE: type = ReadTypeDefOrRefEncoded(module, br, context).MarkValueType(); break; default: throw new BadImageFormatException(); } if (!type.__IsMissing && !type.IsGenericTypeDefinition) { throw new BadImageFormatException(); } int genArgCount = br.ReadCompressedUInt(); Type[] args = new Type[genArgCount]; CustomModifiers[] mods = null; for (int i = 0; i < genArgCount; i++) { // LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it CustomModifiers cm = CustomModifiers.Read(module, br, context); if (!cm.IsEmpty) { if (mods == null) { mods = new CustomModifiers[genArgCount]; } mods[i] = cm; } args[i] = ReadType(module, br, context); } return GenericTypeInstance.Make(type, args, mods); }
private static CustomModifiers ReadCustomModifiers(ModuleReader module, ByteReader br, IGenericContext context) { CustomModifiers mods = new CustomModifiers(); byte b = br.PeekByte(); if (IsCustomModifier(b)) { List<Type> required = new List<Type>(); List<Type> optional = new List<Type>(); while (IsCustomModifier(b)) { bool req = br.ReadByte() == ELEMENT_TYPE_CMOD_REQD; Type type = ReadTypeDefOrRefEncoded(module, br, context); (req ? required : optional).Add(type); b = br.PeekByte(); } mods.required = required.ToArray(); mods.optional = optional.ToArray(); } return mods; }
public override Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers) { int index = (metadataToken & 0xFFFFFF) - 1; if (index < 0) { throw TokenOutOfRangeException(metadataToken); } else if ((metadataToken >> 24) == MemberRefTable.Index && index < MemberRef.RowCount) { int sig = MemberRef.records[index].Signature; return Signature.ReadOptionalParameterTypes(this, GetBlob(sig), new GenericContext(genericTypeArguments, genericMethodArguments), out customModifiers); } else if ((metadataToken >> 24) == MethodDefTable.Index && index < MethodDef.RowCount) { // for convenience, we support passing a MethodDef token as well, because in some places // it makes sense to have a vararg method that is referred to by its methoddef (e.g. ldftn). // Note that MethodSpec doesn't make sense, because generic methods cannot be vararg. customModifiers = Empty<CustomModifiers>.Array; return Type.EmptyTypes; } else { throw TokenOutOfRangeException(metadataToken); } }
private GenericTypeInstance(Type type, Type[] args, CustomModifiers[] mods) { this.type = type; this.args = args; this.mods = mods; }