2016-04-21 15:57:02 +03:00
|
|
|
using System;
|
|
|
|
using Mono.Cecil;
|
|
|
|
using Mono.Tuner;
|
|
|
|
|
|
|
|
namespace Xamarin.Linker {
|
|
|
|
|
|
|
|
public class MobileRemoveAttributes : RemoveAttributesBase {
|
|
|
|
|
|
|
|
protected virtual bool DebugBuild {
|
|
|
|
get { return context.LinkSymbols; }
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool IsRemovedAttribute (CustomAttribute attribute)
|
|
|
|
{
|
|
|
|
// note: this also avoid calling FullName (which allocates a string)
|
|
|
|
var attr_type = attribute.Constructor.DeclaringType;
|
|
|
|
switch (attr_type.Name) {
|
|
|
|
case "ObsoleteAttribute":
|
|
|
|
// System.Mono*Attribute from mono/mcs/build/common/MonoTODOAttribute.cs
|
|
|
|
case "MonoDocumentationNoteAttribute":
|
|
|
|
case "MonoExtensionAttribute":
|
|
|
|
case "MonoInternalNoteAttribute":
|
|
|
|
case "MonoLimitationAttribute":
|
|
|
|
case "MonoNotSupportedAttribute":
|
|
|
|
case "MonoTODOAttribute":
|
|
|
|
return attr_type.Namespace == "System";
|
|
|
|
case "MonoFIXAttribute":
|
|
|
|
return attr_type.Namespace == "System.Xml";
|
|
|
|
// remove debugging-related attributes if we're not linking symbols (i.e. we're building release builds)
|
|
|
|
case "DebuggableAttribute":
|
|
|
|
case "DebuggerBrowsableAttribute":
|
|
|
|
case "DebuggerDisplayAttribute":
|
|
|
|
case "DebuggerHiddenAttribute":
|
|
|
|
case "DebuggerNonUserCodeAttribute":
|
|
|
|
case "DebuggerStepperBoundaryAttribute":
|
|
|
|
case "DebuggerStepThroughAttribute":
|
|
|
|
case "DebuggerTypeProxyAttribute":
|
|
|
|
case "DebuggerVisualizerAttribute":
|
|
|
|
return !DebugBuild && attr_type.Namespace == "System.Diagnostics";
|
2020-04-07 18:00:15 +03:00
|
|
|
// compiler nullability attributes are not used at runtime so they can be removed by the linker
|
|
|
|
case "NullableAttribute":
|
|
|
|
case "NullableContextAttribute":
|
|
|
|
return attr_type.Namespace == "System.Runtime.CompilerServices";
|
|
|
|
// _manual_ nullability attributes are not used at runtime so they can be removed by the linker
|
|
|
|
case "AllowNullAttribute":
|
|
|
|
case "DisallowNullAttribute":
|
|
|
|
case "DoesNotReturnAttribute":
|
|
|
|
case "DoesNotReturnIfAttribute":
|
|
|
|
case "ExcludeFromCodeCoverageAttribute":
|
|
|
|
case "MaybeNullAttribute":
|
|
|
|
case "MaybeNullWhenAttribute":
|
|
|
|
case "NotNullAttribute":
|
|
|
|
case "NotNullIfNotNullAttribute":
|
|
|
|
case "NotNullWhenAttribute":
|
|
|
|
return attr_type.Namespace == "System.Diagnostics.CodeAnalysis";
|
2016-04-21 15:57:02 +03:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|