Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate custom attributes from metadata instead of type system #100763

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantBoxedEnumValue</Target>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumValue</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantBoxedEnumValueHandle</Target>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumValueHandle</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public static bool IsConstructor(ref Method method, MetadataReader reader)
return nameHandle.StringEquals(ConstructorInfo.ConstructorName, reader) || nameHandle.StringEquals(ConstructorInfo.TypeConstructorName, reader);
}

private static Exception ParseBoxedEnumConstantValue(this ConstantBoxedEnumValueHandle handle, MetadataReader reader, out object value)
private static Exception ParseEnumConstantValue(this ConstantEnumValueHandle handle, MetadataReader reader, out object value)
{
ConstantBoxedEnumValue record = handle.GetConstantBoxedEnumValue(reader);
ConstantEnumValue record = handle.GetConstantEnumValue(reader);

Exception? exception = null;
Type? enumType = record.Type.TryResolve(reader, new TypeContext(null, null), ref exception)?.ToType();
Expand Down Expand Up @@ -317,9 +317,9 @@ public static Exception TryParseConstantValue(this Handle handle, MetadataReader
case HandleType.ConstantReferenceValue:
value = null;
return null;
case HandleType.ConstantBoxedEnumValue:
case HandleType.ConstantEnumValue:
{
return handle.ToConstantBoxedEnumValueHandle(reader).ParseBoxedEnumConstantValue(reader, out value);
return handle.ToConstantEnumValueHandle(reader).ParseEnumConstantValue(reader, out value);
}
default:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ from primitiveType in PrimitiveTypes
members: new MemberDef[] {
new MemberDef(name: "Value", typeName: "string")
}
),
new RecordDef(
name: "ConstantEnumValue",
members: new MemberDef[] {
new MemberDef("Value", EnumConstantValue, MemberDefFlags.RecordRef | MemberDefFlags.Child),
new MemberDef("Type", TypeDefOrRefOrSpec, MemberDefFlags.RecordRef)
}
)
}
)
Expand Down Expand Up @@ -630,13 +637,6 @@ from primitiveType in PrimitiveTypes
new MemberDef("Value", TypeDefOrRefOrSpecOrConstant, MemberDefFlags.RecordRef),
}
),
new RecordDef(
name: "ConstantBoxedEnumValue",
members: new MemberDef[] {
new MemberDef("Value", EnumConstantValue, MemberDefFlags.RecordRef | MemberDefFlags.Child),
new MemberDef("Type", TypeDefOrRefOrSpec, MemberDefFlags.RecordRef)
}
),
new RecordDef(
name: "GenericParameter",
members: new MemberDef[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,6 @@ public static uint Read(this NativeReader reader, uint offset, out ConstantBoole
return offset;
} // Read

public static uint Read(this NativeReader reader, uint offset, out ConstantBoxedEnumValueHandle handle)
{
uint value;
offset = reader.DecodeUnsigned(offset, out value);
handle = new ConstantBoxedEnumValueHandle((int)value);
handle._Validate();
return offset;
} // Read

public static uint Read(this NativeReader reader, uint offset, out ConstantByteArrayHandle handle)
{
uint value;
Expand Down Expand Up @@ -372,6 +363,15 @@ public static uint Read(this NativeReader reader, uint offset, out ConstantEnumA
return offset;
} // Read

public static uint Read(this NativeReader reader, uint offset, out ConstantEnumValueHandle handle)
{
uint value;
offset = reader.DecodeUnsigned(offset, out value);
handle = new ConstantEnumValueHandle((int)value);
handle._Validate();
return offset;
} // Read

public static uint Read(this NativeReader reader, uint offset, out ConstantHandleArrayHandle handle)
{
uint value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public enum HandleType : byte
ByReferenceSignature = 0x2,
ConstantBooleanArray = 0x3,
ConstantBooleanValue = 0x4,
ConstantBoxedEnumValue = 0x5,
ConstantByteArray = 0x6,
ConstantByteValue = 0x7,
ConstantCharArray = 0x8,
ConstantCharValue = 0x9,
ConstantDoubleArray = 0xa,
ConstantDoubleValue = 0xb,
ConstantEnumArray = 0xc,
ConstantByteArray = 0x5,
ConstantByteValue = 0x6,
ConstantCharArray = 0x7,
ConstantCharValue = 0x8,
ConstantDoubleArray = 0x9,
ConstantDoubleValue = 0xa,
ConstantEnumArray = 0xb,
ConstantEnumValue = 0xc,
ConstantHandleArray = 0xd,
ConstantInt16Array = 0xe,
ConstantInt16Value = 0xf,
Expand Down
Loading
Loading