Skip to content

Commit

Permalink
Add support for parsing and working with CustomModifiers in field sig…
Browse files Browse the repository at this point in the history
…natures and make TypeSystemMetadataEmitter more flexible (#70593)

- Update TypeSystemMetadataEmitter to be able to generate a field signature given an appropriate array of EmbeddedSignatureData[]
- Add api to FieldDesc to allow the custom modifier data to be handled using the same scheme as custom modifier data on method signatures
- Adjust TypeSystemMetadataEmitter to be able to generate metadata not just for the Mibc emitter
  - The current implementation has some default behavior around creating metadata that is in the constructor. Break that out into helper functions so that other scenarios don't need to run that code.
  - Add an entrypoint for generating metadata for an arbitrary TypeSystemEntity
  - Add a feature to allow it the ResolutionScope of a non-nested type to be managed specially. This will be needed by #68919
  • Loading branch information
davidwrighton authored Jun 10, 2022
1 parent 08692dc commit 83bd401
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 50 deletions.
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

0 comments on commit 83bd401

Please sign in to comment.