Xamarin Public Jenkins (auto-signing) 8fc30896db Imported Upstream version 5.12.0.220
Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
2018-04-24 09:31:23 +00:00

50 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace ILLink.CustomSteps
{
public class ClearInitLocalsStep : BaseStep
{
HashSet<string> _assemblies;
protected override void Process ()
{
string parameterName = "ClearInitLocalsAssemblies";
if (Context.HasParameter (parameterName)) {
string parameter = Context.GetParameter (parameterName);
_assemblies = new HashSet<string> (parameter.Split(','), StringComparer.OrdinalIgnoreCase);
}
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if ((_assemblies != null) && (!_assemblies.Contains (assembly.Name.Name))) {
return;
}
bool changed = false;
foreach (ModuleDefinition module in assembly.Modules) {
foreach (TypeDefinition type in module.Types) {
foreach (MethodDefinition method in type.Methods) {
if (method.Body != null) {
if (method.Body.InitLocals) {
method.Body.InitLocals = false;
changed = true;
}
}
}
}
}
if (changed && (Annotations.GetAction (assembly) == AssemblyAction.Copy))
Annotations.SetAction (assembly, AssemblyAction.Save);
}
}
}