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

Add support for parsing and working with CustomModifiers in field signatures and make TypeSystemMetadataEmitter more flexible #70593

Merged
merged 2 commits into from
Jun 10, 2022
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 @@ -39,6 +39,8 @@ public override TypeDesc FieldType
}
}

public override EmbeddedSignatureData[] GetEmbeddedSignatureData() => null;

public override bool HasRva
{
get
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public abstract TypeDesc FieldType
get;
}

// Get the embedded signature data used to hold custom modifiers and such within a field signature
public abstract EmbeddedSignatureData[] GetEmbeddedSignatureData();

public abstract bool IsStatic
{
get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public override TypeDesc FieldType
}
}

public override EmbeddedSignatureData[] GetEmbeddedSignatureData()
{
return _fieldDef.GetEmbeddedSignatureData();
}

public override bool IsStatic
{
get
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ public override TypeDesc FieldType
}
}

// This is extremely rarely needed. Don't cache it at all.
public override EmbeddedSignatureData[] GetEmbeddedSignatureData()
{
var metadataReader = MetadataReader;
BlobReader signatureReader = metadataReader.GetBlobReader(metadataReader.GetFieldDefinition(_handle).Signature);

EcmaSignatureParser parser = new EcmaSignatureParser(Module, signatureReader, NotFoundBehavior.Throw);
var fieldType = parser.ParseFieldSignature(out var embeddedSig);
Debug.Assert(fieldType == FieldType);
return embeddedSig;
}


[MethodImpl(MethodImplOptions.NoInlining)]
private int InitializeFieldFlags(int mask)
{
Expand Down
19 changes: 19 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Ecma/EcmaSignatureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,25 @@ public TypeDesc ParseFieldSignature()
return ParseType();
}

public TypeDesc ParseFieldSignature(out EmbeddedSignatureData[] embeddedSigData)
{
try
{
_indexStack = new Stack<int>();
_indexStack.Push(1);
_indexStack.Push(0);
_embeddedSignatureDataList = new List<EmbeddedSignatureData>();
TypeDesc parsedType = ParseFieldSignature();
embeddedSigData = _embeddedSignatureDataList.Count == 0 ? null : _embeddedSignatureDataList.ToArray();
return parsedType;
}
finally
{
_indexStack = null;
_embeddedSignatureDataList = null;
}
}

public LocalVariableDefinition[] ParseLocalsSignature()
{
if (_reader.ReadSignatureHeader().Kind != SignatureKind.LocalVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public override TypeDesc FieldType
}
}

public override EmbeddedSignatureData[] GetEmbeddedSignatureData() => null;

public override bool HasRva
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ public override TypeDesc FieldType
return _owningType.ElementType;
}
}
public override EmbeddedSignatureData[] GetEmbeddedSignatureData() => null;

public override bool HasRva
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public override TypeDesc FieldType
}
}

public override EmbeddedSignatureData[] GetEmbeddedSignatureData() => null;

public override bool HasRva
{
get
Expand Down
Loading