Skip to content

Commit a63a2c6

Browse files
authored
Fix processing exclusion attrib with TypeSpecs (#200)
***NO_CI***
1 parent 89fca38 commit a63a2c6

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

MetadataProcessor.Shared/Extensions/TypeReferenceExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,12 @@ public static string FixedName(this TypeReference value)
381381
{
382382
return nanoHelpers.FixTypeNames(value.Name);
383383
}
384+
385+
public static bool IsToExclude(this TypeReference value)
386+
{
387+
return nanoTablesContext.ClassNamesToExclude.Contains(value.FullName) ||
388+
nanoTablesContext.ClassNamesToExclude.Contains(value.Name) ||
389+
nanoTablesContext.ClassNamesToExclude.Contains(value.DeclaringType?.FullName);
390+
}
384391
}
385392
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Mono.Cecil;
5+
6+
namespace nanoFramework.Tools.MetadataProcessor.Core.Extensions
7+
{
8+
internal static class TypeSpecificationExtensions
9+
{
10+
public static bool IsToExclude(this TypeSpecification value)
11+
{
12+
return nanoTablesContext.ClassNamesToExclude.Contains(value.FullName) ||
13+
nanoTablesContext.ClassNamesToExclude.Contains(value.Name) ||
14+
nanoTablesContext.ClassNamesToExclude.Contains(value.ElementType.FullName) ||
15+
nanoTablesContext.ClassNamesToExclude.Contains(value.DeclaringType?.FullName);
16+
}
17+
}
18+
}

MetadataProcessor.Shared/MetadataProcessor.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<Compile Include="$(MSBuildThisFileDirectory)Extensions\MethodSpecificationExtensions.cs" />
3838
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ParameterDefintionExtensions.cs" />
3939
<Compile Include="$(MSBuildThisFileDirectory)Extensions\TypeDefinitionExtensions.cs" />
40+
<Compile Include="..\MetadataProcessor.Shared\Extensions\TypeSpecificationExtensions.cs" />
4041
<Compile Include="$(MSBuildThisFileDirectory)Extensions\TypeReferenceExtensions.cs" />
4142
<Compile Include="$(MSBuildThisFileDirectory)InanoTable.cs" />
4243
<Compile Include="$(MSBuildThisFileDirectory)Mono.Cecil\CodeWriter.cs" />

MetadataProcessor.Shared/Tables/nanoTypeSpecificationsTable.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Linq;
1010
using Mono.Cecil;
1111
using Mono.Cecil.Cil;
12+
using nanoFramework.Tools.MetadataProcessor.Core.Extensions;
1213

1314
namespace nanoFramework.Tools.MetadataProcessor
1415
{
@@ -223,15 +224,18 @@ private void FillTypeSpecsFromMemberReferences()
223224
throw new ArgumentException($".NET nanoFramework doesn't have support for multidimensional arrays. Unable to parse {m.DeclaringType.FullName}.");
224225
}
225226

226-
typeSpecs.Add(m.DeclaringType as TypeSpecification);
227+
if (!(m.DeclaringType as TypeSpecification).IsToExclude())
228+
{
229+
typeSpecs.Add(m.DeclaringType as TypeSpecification);
227230

228-
// get index of signature for the TypeSpecification
229-
ushort signatureId = _context.SignaturesTable.GetOrCreateSignatureId(m.DeclaringType);
231+
// get index of signature for the TypeSpecification
232+
ushort signatureId = _context.SignaturesTable.GetOrCreateSignatureId(m.DeclaringType);
230233

231-
if (!_idByTypeSpecifications.TryGetValue(m.DeclaringType, out ushort referenceId))
232-
{
233-
// is not on the list yet, add it
234-
_idByTypeSpecifications.Add(m.DeclaringType, signatureId);
234+
if (!_idByTypeSpecifications.TryGetValue(m.DeclaringType, out ushort referenceId))
235+
{
236+
// is not on the list yet, add it
237+
_idByTypeSpecifications.Add(m.DeclaringType, signatureId);
238+
}
235239
}
236240
}
237241
}
@@ -240,7 +244,7 @@ private void FillTypeSpecsFromMemberReferences()
240244
// that may have come in via the TypeReferencesTable.
241245
foreach (GenericInstanceType genericInstanceType in _context.TypeReferencesTable.Items.OfType<GenericInstanceType>())
242246
{
243-
if (!_idByTypeSpecifications.ContainsKey(genericInstanceType))
247+
if (!_idByTypeSpecifications.ContainsKey(genericInstanceType) && !genericInstanceType.IsToExclude())
244248
{
245249
// create or get the signature ID for this instanced type
246250
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(genericInstanceType);
@@ -249,7 +253,7 @@ private void FillTypeSpecsFromMemberReferences()
249253
// (and don’t forget to pull in any nested generic-parameter args)
250254
foreach (GenericParameter arg in genericInstanceType.GenericArguments.OfType<GenericParameter>())
251255
{
252-
if (!_idByTypeSpecifications.ContainsKey(arg))
256+
if (!_idByTypeSpecifications.ContainsKey(arg) && !arg.IsToExclude())
253257
{
254258
ushort argSig = _context.SignaturesTable.GetOrCreateSignatureId(arg);
255259
_idByTypeSpecifications.Add(arg, argSig);
@@ -270,7 +274,7 @@ private void FillTypeSpecsFromMemberReferences()
270274

271275
foreach (TypeReference typeRefItem in allGenericInstances)
272276
{
273-
if (!_idByTypeSpecifications.ContainsKey(typeRefItem))
277+
if (!_idByTypeSpecifications.ContainsKey(typeRefItem) && !typeRefItem.IsToExclude())
274278
{
275279
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(typeRefItem);
276280
_idByTypeSpecifications.Add(typeRefItem, sigId);
@@ -312,7 +316,9 @@ private void FillTypeSpecsFromTypes()
312316
else if (instr.Operand is GenericInstanceMethod genericInstanceMethod)
313317
{
314318
GenericInstanceType genericInstanceType = genericInstanceMethod.DeclaringType as GenericInstanceType;
315-
if (genericInstanceType != null && !_idByTypeSpecifications.ContainsKey(genericInstanceType))
319+
if (genericInstanceType != null
320+
&& !_idByTypeSpecifications.ContainsKey(genericInstanceType)
321+
&& !genericInstanceType.IsToExclude())
316322
{
317323
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(genericInstanceType);
318324
_idByTypeSpecifications.Add(genericInstanceType, sigId);
@@ -419,7 +425,8 @@ private void AddIfNew(
419425
TypeReference tr,
420426
ushort sigId)
421427
{
422-
if (!_idByTypeSpecifications.ContainsKey(tr))
428+
if (!_idByTypeSpecifications.ContainsKey(tr)
429+
&& !tr.IsToExclude())
423430
{
424431
_idByTypeSpecifications.Add(tr, sigId);
425432
}

0 commit comments

Comments
 (0)