-
Notifications
You must be signed in to change notification settings - Fork 533
/
PreserveExportedTypes.cs
85 lines (72 loc) · 2.14 KB
/
PreserveExportedTypes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
using Microsoft.Android.Sdk.ILLink;
namespace Mono.Tuner {
public class PreserveExportedTypes : BaseSubStep {
public override SubStepTargets Targets {
get {
return SubStepTargets.Field
| SubStepTargets.Method
| SubStepTargets.Property
;
}
}
public override bool IsActiveFor (AssemblyDefinition assembly)
{
return !Profile.IsSdkAssembly (assembly);
}
public override void ProcessField (FieldDefinition field)
{
ProcessExports (field);
}
public override void ProcessMethod (MethodDefinition method)
{
ProcessExports (method);
}
public override void ProcessProperty (PropertyDefinition property)
{
ProcessExports (property.GetMethod);
ProcessExports (property.SetMethod);
}
public override void ProcessEvent (EventDefinition @event)
{
}
void ProcessExports (ICustomAttributeProvider provider)
{
if (provider == null)
return;
if (!provider.HasCustomAttributes)
return;
var attributes = provider.CustomAttributes;
for (int i = 0; i < attributes.Count; i++) {
var attribute = attributes [i];
switch (attribute.Constructor.DeclaringType.FullName) {
case "Java.Interop.ExportAttribute":
Annotations.Mark (provider);
if (!attribute.HasProperties)
break;
var throwsAtt = attribute.Properties.FirstOrDefault (p => p.Name == "Throws");
var thrownTypesArgs = throwsAtt.Argument.Value != null ? (CustomAttributeArgument []) throwsAtt.Argument.Value : null;
if (thrownTypesArgs != null)
foreach (var attArg in thrownTypesArgs)
Annotations.Mark (((TypeReference) attArg.Value).Resolve ());
break;
case "Java.Interop.ExportFieldAttribute":
Annotations.Mark (provider);
break;
default:
continue;
}
if (provider is MemberReference)
Annotations.Mark (((MemberReference) provider).DeclaringType.Resolve ());
if (provider is MethodDefinition)
Annotations.SetAction (((MethodDefinition) provider), MethodAction.ForceParse);
}
}
}
}