33
44using System . Collections . Generic ;
55using System . Reflection . Metadata ;
6+ using System . Reflection . Metadata . Ecma335 ;
7+ using System . Linq ;
8+
9+ using Internal . TypeSystem ;
610
711namespace ILTrim . DependencyAnalysis
812{
@@ -20,20 +24,44 @@ public StandaloneSignatureNode(EcmaModule module, StandaloneSignatureHandle hand
2024
2125 public override IEnumerable < DependencyListEntry > GetStaticDependencies ( NodeFactory factory )
2226 {
23- // TODO: the signature might depend on other tokens
27+ // @TODO: These need to go EcmaSignatureParser
28+ // Cannot think of a design that can move this logic to that struct
29+
30+ MetadataReader reader = _module . MetadataReader ;
31+
32+ StandaloneSignature standaloneSig = reader . GetStandaloneSignature ( Handle ) ;
33+
34+ BlobReader signatureReader = reader . GetBlobReader ( standaloneSig . Signature ) ;
35+
36+ if ( signatureReader . ReadSignatureHeader ( ) . Kind != SignatureKind . LocalVariables )
37+ ThrowHelper . ThrowInvalidProgramException ( ) ;
38+
39+ int count = signatureReader . ReadCompressedInteger ( ) ;
40+
41+ for ( int i = 0 ; i < count ; i ++ )
42+ {
43+ SignatureTypeCode typeCode = signatureReader . ReadSignatureTypeCode ( ) ;
44+ switch ( typeCode )
45+ {
46+ case SignatureTypeCode . TypeHandle :
47+ TypeDefinitionHandle typeDefHandle = ( TypeDefinitionHandle ) signatureReader . ReadTypeHandle ( ) ;
48+ yield return new DependencyListEntry ( factory . TypeDefinition ( _module , typeDefHandle ) , "Local variable type" ) ;
49+ break ;
50+ }
51+ }
52+
2453 yield break ;
2554 }
2655
2756 protected override EntityHandle WriteInternal ( ModuleWritingContext writeContext )
2857 {
29- MetadataReader reader = _module . MetadataReader ;
30- StandaloneSignature standaloneSig = reader . GetStandaloneSignature ( Handle ) ;
58+ EcmaSignatureParser signatureParser = new EcmaSignatureParser ( _module . MetadataReader , writeContext . TokenMap ) ;
59+ byte [ ] blobBytes = signatureParser . GetLocalVariableBlob ( Handle ) ;
3160
32- // TODO: the signature might have tokens we need to rewrite
3361 var builder = writeContext . MetadataBuilder ;
3462 return builder . AddStandaloneSignature (
35- builder . GetOrAddBlob ( reader . GetBlobBytes ( standaloneSig . Signature ) )
36- ) ;
63+ builder . GetOrAddBlob ( blobBytes ) ) ;
64+
3765 }
3866
3967 public override string ToString ( )
0 commit comments