Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

639
mcs/tools/linker/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="Mono.Posix">
<type fullname="Mono.Posix.UnixEndPoint" />
</assembly>
</linker>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System.Core">
<type fullname="System.Runtime.CompilerServices.CallSiteOps" preserve="methods" feature="dynamic" />
</assembly>
</linker>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System.Drawing">
<type fullname="System.Drawing.Imaging.BitmapData" preserve="fields" />
</assembly>
</linker>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System.Web">
<type fullname="System.Web.Util.ICalls" />
</assembly>
</linker>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System">
<type fullname="System.Configuration.DefaultConfig" />
<type fullname="System.Diagnostics.DefaultTraceListener" />
<type fullname="System.Diagnostics.FileVersionInfo" />
<type fullname="System.Diagnostics.Process" />
<type fullname="System.Diagnostics.ProcessModule" />
<type fullname="System.IO.FAMWatcher" />
<type fullname="System.IO.FileSystemWatcher" />
<type fullname="System.IO.InotifyWatcher" />
<type fullname="System.Net.Dns" />
<type fullname="System.Net.SocketAddress" />
<type fullname="System.Net.Sockets.LingerOption" />
<type fullname="System.Net.Sockets.Socket" />
<type fullname="System.Net.Sockets.Socket/SocketAsyncResult" preserve="fields" />
<type fullname="System.Net.Sockets.SocketException" />
</assembly>
</linker>

View File

@@ -0,0 +1,366 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="mscorlib">
<type fullname="System.AppDomain" preserve="fields">
<method name="DoDomainUnload" />
<method name="DoTypeResolve" />
<method name="DoAssemblyResolve" />
<method name="DoAssemblyLoad" />
<method name="DoDomainUnload" />
<method name="InternalSetContext" />
</type>
<type fullname="System.AppDomainSetup" preserve="fields" />
<type fullname="System.AppDomainUnloadedException" />
<type fullname="System.ApplicationException" />
<type fullname="System.ArgIterator" />
<type fullname="System.ArgumentException" />
<type fullname="System.ArgumentNullException" />
<type fullname="System.ArgumentOutOfRangeException" />
<type fullname="System.ArithmeticException" />
<type fullname="System.Array">
<method name="InternalArray__ICollection_get_Count" />
<method name="InternalArray__ICollection_get_IsReadOnly" />
<method name="InternalArray__IEnumerable_GetEnumerator" />
<method name="InternalArray__ICollection_Clear" />
<method name="InternalArray__ICollection_Add" />
<method name="InternalArray__ICollection_Remove" />
<method name="InternalArray__ICollection_Contains" />
<method name="InternalArray__ICollection_CopyTo" />
<method name="InternalArray__Insert" />
<method name="InternalArray__RemoveAt" />
<method name="InternalArray__IndexOf" />
<method name="InternalArray__get_Item" />
<method name="InternalArray__set_Item" />
<method name="InternalArray__IReadOnlyList_get_Item" />
<method name="InternalArray__IReadOnlyCollection_get_Count" />
</type>
<type fullname="System.ArrayTypeMismatchException" />
<type fullname="System.Attribute" />
<type fullname="System.BadImageFormatException" />
<type fullname="System.Boolean" preserve="fields" />
<type fullname="System.Byte" preserve="fields" />
<type fullname="System.CannotUnloadAppDomainException" />
<type fullname="System.Char" preserve="fields" />
<type fullname="System.Console" preserve="fields" />
<type fullname="System.ConsoleDriver" preserve="fields" />
<type fullname="System.ContextBoundObject" preserve="fields" />
<!-- <type fullname="System.Convert" /> -->
<type fullname="System.CurrentSystemTimeZone" />
<type fullname="System.DateTime" preserve="fields" />
<type fullname="System.DBNull" preserve="fields" />
<type fullname="System.Decimal" preserve="fields" />
<type fullname="System.Delegate" preserve="fields" />
<type fullname="System.Diagnostics.StackFrame" />
<type fullname="System.Diagnostics.StackTrace" />
<type fullname="System.DivideByZeroException" />
<type fullname="System.DllNotFoundException" />
<type fullname="System.Double" preserve="fields" />
<type fullname="System.Enum" preserve="fields">
<method name="GetValues" />
</type>
<type fullname="System.EntryPointNotFoundException" />
<type fullname="System.Environment">
<field name="mono_corlib_version" />
<method name="get_StackTrace" />
</type>
<type fullname="System.Exception" />
<type fullname="System.ExecutionEngineException" />
<type fullname="System.FieldAccessException" />
<type fullname="System.FormatException" />
<type fullname="System.GC" />
<type fullname="System.IndexOutOfRangeException" />
<type fullname="System.Int16" preserve="fields" />
<type fullname="System.Int32" preserve="fields" />
<type fullname="System.Int64" preserve="fields" />
<type fullname="System.IntPtr" preserve="fields" />
<type fullname="System.InvalidCastException" />
<type fullname="System.InvalidOperationException" />
<type fullname="System.InvalidProgramException" />
<type fullname="System.MarshalByRefObject" preserve="fields" feature="remoting" />
<type fullname="System.MethodAccessException" />
<type fullname="System.Missing" preserve="fields" />
<type fullname="System.MissingFieldException" />
<type fullname="System.MissingMethodException" />
<type fullname="System.MonoAsyncCall" preserve="fields" />
<type fullname="System.MonoCustomAttrs" preserve="fields" />
<type fullname="System.MonoCustomAttrs/AttributeInfo" preserve="fields" />
<type fullname="System.MonoCQItem" preserve="all" />
<type fullname="System.MonoEnumInfo" preserve="fields" />
<type fullname="System.MonoListItem" preserve="fields" />
<type fullname="System.MonoType" preserve="fields" />
<type fullname="System.MulticastDelegate" preserve="fields" />
<type fullname="System.NotImplementedException" />
<type fullname="System.NotSupportedException" />
<type fullname="System.NullReferenceException" />
<type fullname="System.Nullable`1" preserve="fields">
<method name="Box" />
<method name="Unbox" />
</type>
<type fullname="System.Object" />
<type fullname="System.OutOfMemoryException" />
<type fullname="System.RuntimeArgumentHandle" preserve="fields" />
<type fullname="System.RuntimeFieldHandle" preserve="fields" />
<type fullname="System.RuntimeMethodHandle" preserve="fields" />
<type fullname="System.RuntimeTypeHandle" preserve="fields" />
<type fullname="System.SByte" preserve="fields" />
<type fullname="System.Single" preserve="fields" />
<type fullname="System.StackOverflowException" />
<type fullname="System.STAThreadAttribute" />
<type fullname="System.String" preserve="fields">
<method name="CreateString" />
<method name="InternalAllocateStr" />
<method name="memcpy" />
<method name="memset" />
</type>
<type fullname="System.SystemException" />
<type fullname="System.Type" preserve="fields">
<method name="GetTypeFromHandle" />
</type>
<type fullname="System.TypeInitializationException" />
<type fullname="System.TypeLoadException" />
<type fullname="System.TypedReference" preserve="fields" />
<type fullname="System.UInt16" preserve="fields" />
<type fullname="System.UInt32" preserve="fields" />
<type fullname="System.UInt64" preserve="fields" />
<type fullname="System.UIntPtr" preserve="fields" />
<type fullname="System.UnhandledExceptionEventArgs" />
<type fullname="System.ValueType" preserve="fields" />
<type fullname="System.Variant" preserve="fields" feature="com">
<method name="Clear" />
</type>
<type fullname="System.Version" />
<type fullname="System.Void" />
<type fullname="System.__ComObject" feature="com" />
<type fullname="System.Collections.Generic.ICollection`1" />
<type fullname="System.Collections.Generic.IEnumerable`1" />
<type fullname="System.Collections.Generic.IList`1" />
<type fullname="System.Collections.Generic.GenericEqualityComparer`1">
<method name=".ctor" />
</type>
<type fullname="System.Collections.Generic.GenericComparer`1">
<method name=".ctor" />
</type>
<type fullname="System.Globalization.DateTimeFormatInfo" preserve="fields" />
<type fullname="System.Globalization.CompareInfo" preserve="fields" />
<type fullname="System.Globalization.CultureInfo" preserve="fields">
<method name="CreateCulture" />
</type>
<type fullname="System.Globalization.NumberFormatInfo" preserve="fields" />
<type fullname="System.Globalization.RegionInfo" preserve="fields" />
<type fullname="System.Globalization.SortKey" preserve="fields" />
<!--
<type fullname="System.IO.FileMode" />
<type fullname="System.IO.FileNotFoundException" />
<type fullname="System.IO.FileLoadException" />
<type fullname="System.IO.FileStreamAsyncResult" />
<type fullname="System.IO.IOException" />
<type fullname="System.IO.MonoIO" preserve="fields" />
<type fullname="System.IO.Path" />
<type fullname="System.IO.StreamReader" />
-->
<type fullname="System.Reflection.MonoAssembly">
<method name=".ctor" />
</type>
<type fullname="System.Reflection.MonoModule">
<method name=".ctor" />
</type>
<type fullname="System.Reflection.Assembly" preserve="fields">
<method name="MonoDebugger_GetMethodToken" feature="sre" />
<method name="GetNamespaces" feature="sre" />
</type>
<type fullname="System.Reflection.AssemblyName" preserve="fields" />
<type fullname="System.Reflection.ConstructorInfo" preserve="fields" />
<type fullname="System.Reflection.CustomAttributeData" preserve="fields" />
<type fullname="System.Reflection.CustomAttributeNamedArgument" preserve="fields" />
<type fullname="System.Reflection.CustomAttributeTypedArgument" preserve="fields" />
<type fullname="System.Reflection.EventInfo" preserve="fields">
<method name="AddEventFrame" />
<method name="StaticAddEventAdapterFrame" />
</type>
<type fullname="System.Reflection.ExceptionHandlingClause" preserve="fields" />
<type fullname="System.Reflection.FieldInfo" preserve="fields" />
<type fullname="System.Reflection.LocalVariableInfo" preserve="fields" />
<type fullname="System.Reflection.ManifestResourceInfo" preserve="fields" />
<type fullname="System.Reflection.MethodBase" preserve="fields" />
<type fullname="System.Reflection.MethodBody" preserve="fields" />
<type fullname="System.Reflection.MethodInfo" preserve="fields" />
<type fullname="System.Reflection.Module" preserve="fields">
<method name="Mono_GetGuid" feature="sre" />
</type>
<type fullname="System.Reflection.MonoArrayMethod" preserve="fields" />
<type fullname="System.Reflection.MonoCMethod" preserve="fields" />
<type fullname="System.Reflection.MonoEvent" preserve="fields" />
<type fullname="System.Reflection.MonoEventInfo" preserve="fields" />
<type fullname="System.Reflection.MonoField" preserve="fields" />
<type fullname="System.Reflection.MonoGenericClass" preserve="fields" />
<type fullname="System.Reflection.MonoGenericMethod" preserve="fields" />
<type fullname="System.Reflection.MonoGenericCMethod" preserve="fields" />
<type fullname="System.Reflection.MonoMethod" preserve="fields" />
<type fullname="System.Reflection.MonoMethodInfo" preserve="fields" />
<type fullname="System.Reflection.MonoPropertyInfo" preserve="fields" />
<type fullname="System.Reflection.MonoProperty" preserve="fields">
<method name="GetterAdapterFrame" />
<method name="StaticGetterAdapterFrame" />
</type>
<type fullname="System.Reflection.ParameterInfo" preserve="fields" />
<type fullname="System.Reflection.PropertyInfo" preserve="fields" />
<type fullname="System.Reflection.ReflectionTypeLoadException" />
<type fullname="System.Reflection.TargetException" />
<type fullname="System.Reflection.TargetParameterCountException" />
<type fullname="System.Reflection.Emit.AssemblyBuilder" preserve="fields">
<method name="AddPermissionRequests" />
<method name="AddModule" />
<method name="DefineIconResource" />
<method name="AddTypeForwarder" />
<method name="EmbedResourceFile" />
</type>
<type fullname="System.Reflection.Emit.ConstructorBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.CustomAttributeBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.DynamicMethod" preserve="fields" />
<type fullname="System.Reflection.Emit.EnumBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.EventBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.FieldBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.GenericTypeParameterBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.ILExceptionBlock" preserve="fields" />
<type fullname="System.Reflection.Emit.ILExceptionInfo" preserve="fields" />
<type fullname="System.Reflection.Emit.ILGenerator" preserve="fields">
<method name="Mono_GetCurrentOffset" />
</type>
<type fullname="System.Reflection.Emit.LocalBuilder" preserve="fields">
<method name="Mono_GetLocalIndex" />
</type>
<type fullname="System.Reflection.Emit.MethodBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.ModuleBuilder" preserve="fields">
<method name="Mono_GetGuid" />
</type>
<type fullname="System.Reflection.Emit.MonoResource" preserve="fields" />
<type fullname="System.Reflection.Emit.MonoWin32Resource" preserve="fields" />
<type fullname="System.Reflection.Emit.ParameterBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.PropertyBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.SignatureHelper" preserve="fields" />
<type fullname="System.Reflection.Emit.TypeBuilder" preserve="fields">
<method name="SetCharSet" />
</type>
<type fullname="System.Reflection.Emit.UnmanagedMarshal" preserve="fields">
<method name="DefineCustom" />
<method name="DefineLPArrayInternal" />
</type>
<!--
<type fullname="System.Runtime.CompilerServices.CallConvCdecl" />
<type fullname="System.Runtime.CompilerServices.CallConvStdcall" />
<type fullname="System.Runtime.CompilerServices.CallConvFastcall" />
<type fullname="System.Runtime.CompilerServices.CallConvThiscall" />
-->
<type fullname="System.Runtime.CompilerServices.InternalsVisibleToAttribute" />
<!-- <type fullname="System.Runtime.CompilerServices.RequiredAttributeAttribute" />
<type fullname="System.Runtime.CompilerServices.RuntimeHelpers" />
<type fullname="System.Runtime.CompilerServices.TypeForwardedToAttribute" /> -->
<!-- <type fullname="System.Runtime.InteropServices.DllImportAttribute" /> -->
<type fullname="System.Runtime.InteropServices.GCHandle" />
<!-- <type fullname="System.Runtime.InteropServices.GuidAttribute" /> -->
<type fullname="System.Runtime.InteropServices.HandleRef" />
<type fullname="System.Runtime.InteropServices.ICustomMarshaler" />
<!--<type fullname="System.Runtime.InteropServices.InterfaceTypeAttribute" /> -->
<type fullname="System.Runtime.InteropServices.Marshal" />
<!-- <type fullname="System.Runtime.InteropServices.MarshalDirectiveException" />
<type fullname="System.Runtime.InteropServices.SafeHandle" />
<type fullname="System.Runtime.InteropServices.StructLayoutAttribute" />
<type fullname="System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute" />-->
<!-- <type fullname="System.Runtime.Remoting.Activation.ActivationServices" /> -->
<type fullname="System.Runtime.Remoting.Contexts.Context" preserve="fields">
<method name="get_NeedsContextSink" />
</type>
<type fullname="System.Runtime.Remoting.Channels.CrossAppDomainSink" />
<type fullname="System.Runtime.Remoting.IRemotingTypeInfo">
<method name="CanCastTo" />
</type>
<type fullname="System.Runtime.Remoting.Messaging.AsyncResult" preserve="fields" />
<type fullname="System.Runtime.Remoting.Messaging.CallContext">
<method name="SetCurrentCallContext" />
</type>
<type fullname="System.Runtime.Remoting.Messaging.MonoMethodMessage" preserve="fields" />
<type fullname="System.Runtime.Remoting.Proxies.RealProxy" preserve="fields">
<method name="PrivateInvoke" />
<method name="GetAppDomainTarget" />
</type>
<type fullname="System.Runtime.Remoting.Proxies.TransparentProxy" preserve="fields" />
<type fullname="System.Runtime.Remoting.RemotingServices">
<method name="SerializeCallData" />
<method name="DeserializeCallData" />
<method name="SerializeExceptionData" />
</type>
<!--
<type fullname="System.Runtime.Serialization.ISerializable" />
<type fullname="System.Runtime.Serialization.SerializationException" />
<type fullname="System.Runtime.Serialization.SerializationInfo" />
<type fullname="System.Runtime.Serialization.StreamingContext" />
-->
<type fullname="System.Threading.ExecutionContext" />
<type fullname="System.Threading.Interlocked">
<method name="CompareExchange" />
</type>
<type fullname="System.Threading.Monitor">
<method name="Enter" />
<method name="Exit" />
</type>
<!--
<type fullname="System.Threading.Mutex" />
<type fullname="System.Threading.NativeEventCalls" />
<type fullname="System.Threading.Semaphore" />
-->
<type fullname="System.Threading.SynchronisationLockException" />
<type fullname="System.Threading.Thread" preserve="fields">
<method name="get_CurrentContext" />
</type>
<type fullname="System.Threading.InternalThread" preserve="fields" />
<type fullname="System.Threading.ThreadAbortException" />
<type fullname="System.Threading.ThreadInterruptedException" />
<!--<type fullname="System.Threading.ThreadPool" />-->
<type fullname="System.Threading.ThreadState" preserve="fields" />
<type fullname="System.Threading.ThreadStateException" />
<type fullname="System.Threading.WaitHandle" preserve="fields">
<method name="set_Handle" />
</type>
<type fullname="System.Text.StringBuilder" preserve="fields" />
<type fullname="System.Security.AllowPartiallyTrustedCallersAttribute" />
<type fullname="System.Security.Policy.Evidence" />
<!--
<type fullname="System.Security.Principal.WindowsIdentity" />
<type fullname="System.Security.Principal.WindowsImpersonationContext" />
<type fullname="System.Security.Principal.WindowsPrincipal" />
<type fullname="System.Security.RuntimeSecurityFrame" />
<type fullname="System.Security.SecurityCriticalAttribute" />
<type fullname="System.Security.SecurityException" />
-->
<type fullname="System.Security.SecurityManager" />
<!--
<type fullname="System.Security.SuppressUnmanagedCodeSecurityAttribute" />
<type fullname="System.Security.VerificationException" />
-->
<namespace fullname="System.Security.Cryptography" feature="crypto" />
<type fullname="Mono.Interop.ComInteropProxy" feature="com" />
<type fullname="Mono.Interop.IDispatch" feature="com" />
<type fullname="Mono.Interop.IUnknown" feature="com" />
</assembly>
</linker>

25
mcs/tools/linker/Makefile Normal file
View File

@@ -0,0 +1,25 @@
thisdir = tools/linker
SUBDIRS =
include ../../build/rules.make
PROGRAM_SNK = ../../class/mono.snk
CECIL = $(topdir)/class/lib/$(PROFILE)/Mono.Cecil.dll
RESOURCES = \
Descriptors/mscorlib.xml \
Descriptors/System.xml \
Descriptors/System.Core.xml \
Descriptors/System.Drawing.xml \
Descriptors/System.Web.xml \
Descriptors/Mono.Posix.xml \
PROGRAM = monolinker.exe
$(PROGRAM): $(RESOURCES)
LOCAL_MCS_FLAGS = /r:$(CECIL) /r:System.Xml.dll -keyfile:$(PROGRAM_SNK) $(RESOURCES:%=-resource:%)
EXTRA_DISTFILES = $(RESOURCES)
include ../../build/executable.make

View File

@@ -0,0 +1,77 @@
//
// BaseStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Mono.Cecil;
namespace Mono.Linker.Steps {
public abstract class BaseStep : IStep {
private LinkContext _context;
public LinkContext Context {
get { return _context; }
}
public AnnotationStore Annotations {
get { return _context.Annotations; }
}
public void Process (LinkContext context)
{
_context = context;
if (!ConditionToProcess ())
return;
Process ();
foreach (AssemblyDefinition assembly in context.GetAssemblies ())
ProcessAssembly (assembly);
EndProcess ();
}
protected virtual bool ConditionToProcess ()
{
return true;
}
protected virtual void Process ()
{
}
protected virtual void EndProcess ()
{
}
protected virtual void ProcessAssembly (AssemblyDefinition assembly)
{
}
}
}

View File

@@ -0,0 +1,89 @@
//
// Blacklist.cs
//
// Author:
// Jb Evain (jb@nurv.fr)
//
// (C) 2007 Novell Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
using System.Reflection;
using System.Xml.XPath;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class BlacklistStep : BaseStep {
protected override bool ConditionToProcess()
{
return Context.CoreAction == AssemblyAction.Link;
}
protected override void Process ()
{
foreach (string name in Assembly.GetExecutingAssembly ().GetManifestResourceNames ()) {
if (!IsReferenced (GetAssemblyName (name)))
continue;
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetResolveStep (name));
}
}
static string GetAssemblyName (string descriptor)
{
int pos = descriptor.LastIndexOf ('.');
if (pos == -1)
return descriptor;
return descriptor.Substring (0, pos);
}
bool IsReferenced (string name)
{
foreach (AssemblyDefinition assembly in Context.GetAssemblies ())
if (assembly.Name.Name == name)
return true;
return false;
}
static ResolveFromXmlStep GetResolveStep (string descriptor)
{
return new ResolveFromXmlStep (GetDescriptor (descriptor));
}
static XPathDocument GetDescriptor (string descriptor)
{
using (StreamReader sr = new StreamReader (GetResource (descriptor))) {
return new XPathDocument (new StringReader (sr.ReadToEnd ()));
}
}
static Stream GetResource (string descriptor)
{
return Assembly.GetExecutingAssembly ().GetManifestResourceStream (descriptor);
}
}
}

View File

@@ -0,0 +1,108 @@
//
// CleanStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class CleanStep : BaseStep {
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) == AssemblyAction.Link)
CleanAssembly (assembly);
}
static void CleanAssembly (AssemblyDefinition asm)
{
foreach (TypeDefinition type in asm.MainModule.Types)
CleanType (type);
}
static void CleanType (TypeDefinition type)
{
if (type.HasProperties)
CleanProperties (type);
if (type.HasEvents)
CleanEvents (type);
if (type.HasNestedTypes)
foreach (var nested in type.NestedTypes)
CleanType (nested);
}
static MethodDefinition CheckMethod (TypeDefinition type, MethodDefinition method)
{
if (method == null)
return null;
return type.Methods.Contains (method) ? method : null;
}
static void CleanEvents (TypeDefinition type)
{
var events = type.Events;
for (int i = 0; i < events.Count; i++) {
var evt = events [i];
evt.AddMethod = CheckMethod (type, evt.AddMethod);
evt.InvokeMethod = CheckMethod (type, evt.InvokeMethod);
evt.RemoveMethod = CheckMethod (type, evt.RemoveMethod);
if (!IsEventUsed (evt))
events.RemoveAt (i--);
}
}
static bool IsEventUsed (EventDefinition evt)
{
return evt.AddMethod != null || evt.InvokeMethod != null || evt.RemoveMethod != null;
}
static void CleanProperties (TypeDefinition type)
{
var properties = type.Properties;
for (int i = 0; i < properties.Count; i++) {
var prop = properties [i];
prop.GetMethod = CheckMethod (type, prop.GetMethod);
prop.SetMethod = CheckMethod (type, prop.SetMethod);
if (!IsPropertyUsed (prop))
properties.RemoveAt (i--);
}
}
static bool IsPropertyUsed (PropertyDefinition prop)
{
return prop.GetMethod != null || prop.SetMethod != null;
}
}
}

View File

@@ -0,0 +1,34 @@
//
// IStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Linker.Steps {
public interface IStep {
void Process (LinkContext context);
}
}

View File

@@ -0,0 +1,102 @@
//
// LoadI18nAssemblies.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class LoadI18nAssemblies : BaseStep {
static readonly byte [] _pktoken = new byte [] {0x07, 0x38, 0xeb, 0x9f, 0x13, 0x2e, 0xd7, 0x56};
I18nAssemblies _assemblies;
public LoadI18nAssemblies (I18nAssemblies assemblies)
{
_assemblies = assemblies;
}
protected override bool ConditionToProcess ()
{
return _assemblies != I18nAssemblies.None &&
Type.GetType ("System.MonoType") != null;
}
protected override void Process()
{
LoadAssembly (GetAssemblyName (I18nAssemblies.Base));
LoadI18nAssembly (I18nAssemblies.CJK);
LoadI18nAssembly (I18nAssemblies.MidEast);
LoadI18nAssembly (I18nAssemblies.Other);
LoadI18nAssembly (I18nAssemblies.Rare);
LoadI18nAssembly (I18nAssemblies.West);
}
bool ShouldCopyAssembly (I18nAssemblies current)
{
return (current & _assemblies) != 0;
}
void LoadI18nAssembly (I18nAssemblies asm)
{
if (!ShouldCopyAssembly (asm))
return;
AssemblyNameReference name = GetAssemblyName (asm);
LoadAssembly (name);
}
void LoadAssembly (AssemblyNameReference name)
{
AssemblyDefinition assembly = Context.Resolve (name);
ResolveFromAssemblyStep.ProcessLibrary (Context, assembly);
}
AssemblyNameReference GetAssemblyName (I18nAssemblies assembly)
{
AssemblyNameReference name = new AssemblyNameReference ("I18N", GetCorlibVersion ());
if (assembly != I18nAssemblies.Base)
name.Name += "." + assembly;
name.PublicKeyToken = _pktoken;
return name;
}
Version GetCorlibVersion ()
{
foreach (AssemblyDefinition assembly in Context.GetAssemblies ())
if (assembly.Name.Name == "mscorlib")
return assembly.Name.Version;
return new Version ();
}
}
}

View File

@@ -0,0 +1,55 @@
//
// LoadReferencesStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class LoadReferencesStep : BaseStep {
IDictionary _references = new Hashtable ();
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
ProcessReferences (assembly);
}
void ProcessReferences (AssemblyDefinition assembly)
{
if (_references.Contains (assembly.Name))
return;
_references.Add (assembly.Name, assembly);
foreach (AssemblyNameReference reference in assembly.MainModule.AssemblyReferences)
ProcessReferences (Context.Resolve (reference));
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,156 @@
//
// OutputStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Mono.Linker.Steps {
public class OutputStep : BaseStep {
protected override void Process ()
{
CheckOutputDirectory ();
}
void CheckOutputDirectory ()
{
if (Directory.Exists (Context.OutputDirectory))
return;
Directory.CreateDirectory (Context.OutputDirectory);
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
OutputAssembly (assembly);
}
void OutputAssembly (AssemblyDefinition assembly)
{
string directory = Context.OutputDirectory;
CopyConfigFileIfNeeded (assembly, directory);
switch (Annotations.GetAction (assembly)) {
case AssemblyAction.Save:
case AssemblyAction.Link:
assembly.Write (GetAssemblyFileName (assembly, directory), SaveSymbols (assembly));
break;
case AssemblyAction.Copy:
CloseSymbols (assembly);
CopyAssembly (GetOriginalAssemblyFileInfo (assembly), directory, Context.LinkSymbols);
break;
case AssemblyAction.Delete:
CloseSymbols (assembly);
var target = GetAssemblyFileName (assembly, directory);
if (File.Exists (target)) {
File.Delete (target);
File.Delete (target + ".mdb");
File.Delete (GetConfigFile (target));
}
break;
default:
CloseSymbols (assembly);
break;
}
}
void CloseSymbols (AssemblyDefinition assembly)
{
Annotations.CloseSymbolReader (assembly);
}
WriterParameters SaveSymbols (AssemblyDefinition assembly)
{
var parameters = new WriterParameters ();
if (!Context.LinkSymbols)
return parameters;
if (!assembly.MainModule.HasSymbols)
return parameters;
if (Context.SymbolWriterProvider != null)
parameters.SymbolWriterProvider = Context.SymbolWriterProvider;
else
parameters.WriteSymbols = true;
return parameters;
}
static void CopyConfigFileIfNeeded (AssemblyDefinition assembly, string directory)
{
string config = GetConfigFile (GetOriginalAssemblyFileInfo (assembly).FullName);
if (!File.Exists (config))
return;
string target = Path.GetFullPath (GetConfigFile (GetAssemblyFileName (assembly, directory)));
if (config == target)
return;
File.Copy (config, GetConfigFile (GetAssemblyFileName (assembly, directory)), true);
}
static string GetConfigFile (string assembly)
{
return assembly + ".config";
}
static FileInfo GetOriginalAssemblyFileInfo (AssemblyDefinition assembly)
{
return new FileInfo (assembly.MainModule.FullyQualifiedName);
}
static void CopyAssembly (FileInfo fi, string directory, bool symbols)
{
string target = Path.GetFullPath (Path.Combine (directory, fi.Name));
string source = fi.FullName;
if (source == target)
return;
File.Copy (source, target, true);
if (!symbols)
return;
source += ".mdb";
if (!File.Exists (source))
return;
File.Copy (source, target + ".mdb", true);
}
static string GetAssemblyFileName (AssemblyDefinition assembly, string directory)
{
string file = assembly.Name.Name + (assembly.MainModule.Kind == ModuleKind.Dll ? ".dll" : ".exe");
return Path.Combine (directory, file);
}
}
}

View File

@@ -0,0 +1,48 @@
//
// CleanStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class RegenerateGuidStep : BaseStep {
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) == AssemblyAction.Link)
RegenerateGuid (assembly);
}
static void RegenerateGuid (AssemblyDefinition asm)
{
asm.MainModule.Mvid = Guid.NewGuid ();
}
}
}

View File

@@ -0,0 +1,125 @@
//
// ResolveFromAssemblyStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class ResolveFromAssemblyStep : ResolveStep {
AssemblyDefinition _assembly;
string _file;
public ResolveFromAssemblyStep (string assembly)
{
_file = assembly;
}
public ResolveFromAssemblyStep (AssemblyDefinition assembly)
{
_assembly = assembly;
}
protected override void Process ()
{
if (_assembly != null)
Context.Resolver.CacheAssembly (_assembly);
AssemblyDefinition assembly = _assembly ?? Context.Resolve (_file);
switch (assembly.MainModule.Kind) {
case ModuleKind.Dll:
ProcessLibrary (Context, assembly);
return;
default:
ProcessExecutable (assembly);
return;
}
}
static void SetAction (LinkContext context, AssemblyDefinition assembly, AssemblyAction action)
{
TryReadSymbols (context, assembly);
context.Annotations.SetAction (assembly, action);
}
static void TryReadSymbols (LinkContext context, AssemblyDefinition assembly)
{
context.SafeReadSymbols (assembly);
}
public static void ProcessLibrary (LinkContext context, AssemblyDefinition assembly)
{
SetAction (context, assembly, AssemblyAction.Copy);
foreach (TypeDefinition type in assembly.MainModule.Types)
MarkType (context, type);
}
static void MarkType (LinkContext context, TypeDefinition type)
{
context.Annotations.Mark (type);
if (type.HasFields)
MarkFields (context, type.Fields);
if (type.HasMethods)
MarkMethods (context, type.Methods);
if (type.HasNestedTypes)
foreach (var nested in type.NestedTypes)
MarkType (context, nested);
}
void ProcessExecutable (AssemblyDefinition assembly)
{
SetAction (Context, assembly, AssemblyAction.Link);
Annotations.Mark (assembly.EntryPoint.DeclaringType);
MarkMethod (Context, assembly.EntryPoint, MethodAction.Parse);
}
static void MarkFields (LinkContext context, ICollection fields)
{
foreach (FieldDefinition field in fields)
context.Annotations.Mark (field);
}
static void MarkMethods (LinkContext context, ICollection methods)
{
foreach (MethodDefinition method in methods)
MarkMethod (context, method, MethodAction.ForceParse);
}
static void MarkMethod (LinkContext context, MethodDefinition method, MethodAction action)
{
context.Annotations.Mark (method);
context.Annotations.SetAction (method, action);
}
}
}

View File

@@ -0,0 +1,139 @@
//
// ResolveFromXApiStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Xml.XPath;
using Mono.Linker;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class ResolveFromXApiStep : ResolveStep, IXApiVisitor {
static readonly string _name = "name";
static readonly string _ns = string.Empty;
XPathDocument _document;
public ResolveFromXApiStep (XPathDocument document)
{
_document = document;
}
protected override void Process ()
{
XApiReader reader = new XApiReader (_document, this);
reader.Process (Context);
}
public void OnAssembly (XPathNavigator nav, AssemblyDefinition assembly)
{
}
public void OnAttribute (XPathNavigator nav)
{
string name = GetName (nav);
TypeDefinition type = Context.GetType (name);
if (type != null)
MarkType (type);
}
public void OnClass (XPathNavigator nav, TypeDefinition type)
{
MarkType (type);
}
public void OnInterface (XPathNavigator nav, TypeDefinition type)
{
MarkType (type);
}
public void OnField (XPathNavigator nav, FieldDefinition field)
{
MarkField (field);
}
public void OnMethod (XPathNavigator nav, MethodDefinition method)
{
MarkMethod (method);
}
public void OnConstructor (XPathNavigator nav, MethodDefinition method)
{
MarkMethod (method);
}
public void OnProperty (XPathNavigator nav, PropertyDefinition property)
{
}
public void OnEvent (XPathNavigator nav, EventDefinition evt)
{
if (evt.AddMethod != null)
MarkMethod (evt.AddMethod);
if (evt.InvokeMethod != null)
MarkMethod (evt.InvokeMethod);
if (evt.RemoveMethod != null)
MarkMethod (evt.RemoveMethod);
}
static string GetName (XPathNavigator nav)
{
return GetAttribute (nav, _name);
}
static string GetAttribute (XPathNavigator nav, string attribute)
{
return nav.GetAttribute (attribute, _ns);
}
void MarkType (TypeDefinition type)
{
InternalMark (type);
}
void MarkField (FieldDefinition field)
{
InternalMark (field);
}
void InternalMark (IMetadataTokenProvider provider)
{
Annotations.Mark (provider);
Annotations.SetPublic (provider);
}
void MarkMethod (MethodDefinition method)
{
InternalMark (method);
Annotations.SetAction (method, MethodAction.Parse);
}
}
}

View File

@@ -0,0 +1,367 @@
//
// ResolveFromXmlStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
// (C) 2007 Novell, Inc.
// Copyright 2013 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using SR = System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.XPath;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class ResolveFromXmlStep : ResolveStep {
static readonly string _signature = "signature";
static readonly string _fullname = "fullname";
static readonly string _required = "required";
static readonly string _preserve = "preserve";
static readonly string _ns = string.Empty;
XPathDocument _document;
public ResolveFromXmlStep (XPathDocument document)
{
_document = document;
}
protected override void Process ()
{
XPathNavigator nav = _document.CreateNavigator ();
nav.MoveToFirstChild ();
ProcessAssemblies (Context, nav.SelectChildren ("assembly", _ns));
}
void ProcessAssemblies (LinkContext context, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
AssemblyDefinition assembly = GetAssembly (context, GetFullName (iterator.Current));
ProcessTypes (assembly, iterator.Current.SelectChildren ("type", _ns));
ProcessNamespaces (assembly, iterator.Current.SelectChildren ("namespace", _ns));
}
}
void ProcessNamespaces (AssemblyDefinition assembly, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
string fullname = GetFullName (iterator.Current);
foreach (TypeDefinition type in assembly.MainModule.Types) {
if (type.Namespace != fullname)
continue;
MarkAndPreserveAll (type);
}
}
}
void MarkAndPreserveAll (TypeDefinition type)
{
Annotations.Mark (type);
Annotations.SetPreserve (type, TypePreserve.All);
if (!type.HasNestedTypes)
return;
foreach (TypeDefinition nested in type.NestedTypes)
MarkAndPreserveAll (nested);
}
void ProcessTypes (AssemblyDefinition assembly, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
XPathNavigator nav = iterator.Current;
string fullname = GetFullName (nav);
if (IsTypePattern (fullname)) {
ProcessTypePattern (fullname, assembly, nav);
continue;
}
TypeDefinition type = assembly.MainModule.GetType (fullname);
if (type == null)
continue;
ProcessType (type, nav);
}
}
static bool IsTypePattern (string fullname)
{
return fullname.IndexOf ("*") != -1;
}
static Regex CreateRegexFromPattern (string pattern)
{
return new Regex (pattern.Replace(".", @"\.").Replace("*", "(.*)"));
}
void ProcessTypePattern (string fullname, AssemblyDefinition assembly, XPathNavigator nav)
{
Regex regex = CreateRegexFromPattern (fullname);
foreach (TypeDefinition type in assembly.MainModule.Types) {
if (!regex.Match (type.FullName).Success)
continue;
ProcessType (type, nav);
}
}
void ProcessType (TypeDefinition type, XPathNavigator nav)
{
TypePreserve preserve = GetTypePreserve (nav);
if (!IsRequired (nav)) {
Annotations.SetPreserve (type, preserve);
return;
}
Annotations.Mark (type);
switch (preserve) {
case TypePreserve.Nothing:
if (!nav.HasChildren)
Annotations.SetPreserve (type, TypePreserve.All);
break;
default:
Annotations.SetPreserve (type, preserve);
break;
}
if (nav.HasChildren) {
MarkSelectedFields (nav, type);
MarkSelectedMethods (nav, type);
}
}
void MarkSelectedFields (XPathNavigator nav, TypeDefinition type)
{
XPathNodeIterator fields = nav.SelectChildren ("field", _ns);
if (fields.Count == 0)
return;
ProcessFields (type, fields);
}
void MarkSelectedMethods (XPathNavigator nav, TypeDefinition type)
{
XPathNodeIterator methods = nav.SelectChildren ("method", _ns);
if (methods.Count == 0)
return;
ProcessMethods (type, methods);
}
static TypePreserve GetTypePreserve (XPathNavigator nav)
{
string attribute = GetAttribute (nav, _preserve);
if (attribute == null || attribute.Length == 0)
return TypePreserve.Nothing;
try {
return (TypePreserve) Enum.Parse (typeof (TypePreserve), attribute, true);
} catch {
return TypePreserve.Nothing;
}
}
void ProcessFields (TypeDefinition type, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
string value = GetSignature (iterator.Current);
if (!String.IsNullOrEmpty (value))
ProcessFieldSignature (type, value);
value = GetAttribute (iterator.Current, "name");
if (!String.IsNullOrEmpty (value))
ProcessFieldName (type, value);
}
}
void ProcessFieldSignature (TypeDefinition type, string signature)
{
FieldDefinition field = GetField (type, signature);
MarkField (type, field, signature);
}
void MarkField (TypeDefinition type, FieldDefinition field, string signature)
{
if (field != null)
Annotations.Mark (field);
else
AddUnresolveMarker (string.Format ("T: {0}; F: {1}", type, signature));
}
void ProcessFieldName (TypeDefinition type, string name)
{
if (!type.HasFields)
return;
foreach (FieldDefinition field in type.Fields)
if (field.Name == name)
MarkField (type, field, name);
}
static FieldDefinition GetField (TypeDefinition type, string signature)
{
if (!type.HasFields)
return null;
foreach (FieldDefinition field in type.Fields)
if (signature == GetFieldSignature (field))
return field;
return null;
}
static string GetFieldSignature (FieldDefinition field)
{
return field.FieldType.FullName + " " + field.Name;
}
void ProcessMethods (TypeDefinition type, XPathNodeIterator iterator)
{
while (iterator.MoveNext()) {
string value = GetSignature (iterator.Current);
if (!String.IsNullOrEmpty (value))
ProcessMethodSignature (type, value);
value = GetAttribute (iterator.Current, "name");
if (!String.IsNullOrEmpty (value))
ProcessMethodName (type, value);
}
}
void ProcessMethodSignature (TypeDefinition type, string signature)
{
MethodDefinition meth = GetMethod (type, signature);
MarkMethod (type, meth, signature);
}
void MarkMethod (TypeDefinition type, MethodDefinition method, string signature)
{
if (method != null) {
Annotations.Mark (method);
Annotations.SetAction (method, MethodAction.Parse);
} else
AddUnresolveMarker (string.Format ("T: {0}; M: {1}", type, signature));
}
void ProcessMethodName (TypeDefinition type, string name)
{
if (!type.HasMethods)
return;
foreach (MethodDefinition method in type.Methods)
if (name == method.Name)
MarkMethod (type, method, name);
}
static MethodDefinition GetMethod (TypeDefinition type, string signature)
{
if (type.HasMethods)
foreach (MethodDefinition meth in type.Methods)
if (signature == GetMethodSignature (meth))
return meth;
return null;
}
static string GetMethodSignature (MethodDefinition meth)
{
StringBuilder sb = new StringBuilder ();
sb.Append (meth.ReturnType.FullName);
sb.Append (" ");
sb.Append (meth.Name);
sb.Append ("(");
if (meth.HasParameters) {
for (int i = 0; i < meth.Parameters.Count; i++) {
if (i > 0)
sb.Append (",");
sb.Append (meth.Parameters [i].ParameterType.FullName);
}
}
sb.Append (")");
return sb.ToString ();
}
static AssemblyDefinition GetAssembly (LinkContext context, string assemblyName)
{
AssemblyNameReference reference = AssemblyNameReference.Parse (assemblyName);
AssemblyDefinition assembly;
assembly = context.Resolve (reference);
ProcessReferences (assembly, context);
return assembly;
}
static void ProcessReferences (AssemblyDefinition assembly, LinkContext context)
{
foreach (AssemblyNameReference name in assembly.MainModule.AssemblyReferences)
context.Resolve (name);
}
static bool IsRequired (XPathNavigator nav)
{
string attribute = GetAttribute (nav, _required);
if (attribute == null || attribute.Length == 0)
return true;
return TryParseBool (attribute);
}
static bool TryParseBool (string s)
{
try {
return bool.Parse (s);
} catch {
return false;
}
}
static string GetSignature (XPathNavigator nav)
{
return GetAttribute (nav, _signature);
}
static string GetFullName (XPathNavigator nav)
{
return GetAttribute (nav, _fullname);
}
static string GetAttribute (XPathNavigator nav, string attribute)
{
return nav.GetAttribute (attribute, _ns);
}
}
}

Some files were not shown because too many files have changed in this diff Show More