Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -3,7 +3,6 @@ thisdir = tools
net_4_5_dirs := \
al \
linker \
tuner \
culevel \
genxs \
mkbundle \
@@ -45,6 +44,7 @@ net_4_5_dirs := \
cccheck \
security \
mdbrebase \
mdb2ppdb \
ikdasm \
mono-symbolicate \
linker-analyzer

View File

@@ -7,4 +7,8 @@ NO_INSTALL = yes
LIB_REFS = System Mono.Cecil
ifdef MCS_MODE
LIB_REFS += Mono.Cecil.Mdb
endif
include ../../build/executable.make

View File

@@ -100,14 +100,19 @@ public class Program
static void RewriteAssembly (string assemblyLocation, Dictionary<string, string> resourcesStrings, CmdOptions options)
{
var readerParameters = new ReaderParameters { ReadSymbols = true, ReadWrite = true };
var readerParameters = new ReaderParameters {
ReadSymbols = true,
ReadWrite = true,
SymbolReaderProvider = new DefaultSymbolReaderProvider (false)
};
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyLocation, readerParameters)) {
foreach (var module in assembly.Modules) {
foreach (var type in module.GetTypes ()) {
foreach (var method in type.Methods) {
if (!method.HasBody)
continue;
foreach (var instr in method.Body.Instructions) {
if (instr.OpCode != OpCodes.Ldstr)
continue;
@@ -125,7 +130,10 @@ public class Program
}
}
var writerParameters = new WriterParameters { WriteSymbols = true };
var writerParameters = new WriterParameters () {
WriteSymbols = assembly.MainModule.HasSymbols
};
assembly.Write (writerParameters);
}
}

View File

@@ -38,9 +38,15 @@ namespace Mono {
static string target_host;
static int target_port;
static string agent;
static string [] script_args;
public static string [] ScriptArgs => script_args;
static int Main (string [] args)
{
if (!SplitDriverAndScriptArguments (ref args, out script_args))
return 1;
var cmd = new CommandLineParser (Console.Out);
cmd.UnknownOptionHandler += HandleExtraArguments;
@@ -55,7 +61,7 @@ namespace Mono {
var startup_files = new string [settings.SourceFiles.Count];
int i = 0;
foreach (var source in settings.SourceFiles)
startup_files [i++] = source.FullPathName;
startup_files [i++] = source.OriginalFullPathName;
settings.SourceFiles.Clear ();
TextWriter agent_stderr = null;
@@ -90,6 +96,55 @@ namespace Mono {
return shell.Run (startup_files);
}
static bool SplitDriverAndScriptArguments (ref string [] driver_args, out string [] script_args)
{
// split command line arguments into two groups:
// - anything before '--' or '-s' goes to the mcs driver, which may
// call back into the csharp driver for further processing
// - anything after '--' or '-s' is made available to the REPL/script
// via the 'Args' global, similar to csi.
// - if '-s' is used, the argument immediately following it will
// also be processed by the mcs driver (e.g. a source file)
int driver_args_count = 0;
int script_args_offset = 0;
string script_file = null;
while (driver_args_count < driver_args.Length && script_args_offset == 0) {
switch (driver_args [driver_args_count]) {
case "--":
script_args_offset = driver_args_count + 1;
break;
case "-s":
if (driver_args_count + 1 >= driver_args.Length) {
script_args = null;
Console.Error.WriteLine ("usage is: -s SCRIPT_FILE");
return false;
}
driver_args_count++;
script_file = driver_args [driver_args_count];
script_args_offset = driver_args_count + 1;
break;
default:
driver_args_count++;
break;
}
}
if (script_args_offset > 0) {
int script_args_count = driver_args.Length - script_args_offset;
script_args = new string [script_args_count];
Array.Copy (driver_args, script_args_offset, script_args, 0, script_args_count);
} else
script_args = Array.Empty<string> ();
Array.Resize (ref driver_args, driver_args_count);
if (script_file != null)
driver_args [driver_args_count - 1] = script_file;
return true;
}
static int HandleExtraArguments (string [] args, int pos)
{
switch (args [pos]) {
@@ -163,9 +218,13 @@ namespace Mono {
public static new string help {
get {
return InteractiveBase.help +
" TabAtStartCompletes - Whether tab will complete even on empty lines\n";
" TabAtStartCompletes - Whether tab will complete even on empty lines\n" +
" Args - Any command line arguments passed to csharp\n" +
" after the '--' (stop processing) argument";
}
}
public static string [] Args => Driver.ScriptArgs;
}
public class CSharpShell {

View File

@@ -2,8 +2,8 @@ thisdir = tools/gacutil
SUBDIRS =
include ../../build/rules.make
LIB_REFS = Mono.Security
LOCAL_MCS_FLAGS = -unsafe
LIB_REFS = System Mono.Security System.Security
LOCAL_MCS_FLAGS = -unsafe -define:NO_SYMBOL_WRITER
PROGRAM = gacutil.exe

View File

@@ -14,7 +14,6 @@ using System;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Globalization;
using System.Runtime.InteropServices;
@@ -23,6 +22,8 @@ using System.Security.Cryptography;
using Mono.Security;
using Mono.Security.Cryptography;
using IKVM.Reflection;
namespace Mono.Tools {
public class Driver {
@@ -48,6 +49,7 @@ namespace Mono.Tools {
private static bool silent;
static bool in_bootstrap;
private static Universe _universe;
public static int Main (string [] args)
{
@@ -244,7 +246,7 @@ namespace Mono.Tools {
AssemblyName an = null;
try {
assembly = Assembly.LoadFrom (name);
assembly = ReflectionOnlyLoadFrom (name);
} catch {
WriteLine (string.Format (failure_msg, name) + "The file specified is not a valid assembly.");
return false;
@@ -744,12 +746,27 @@ namespace Mono.Tools {
}
}
private static Universe GetUniverse () {
if (_universe == null) {
_universe = new Universe (UniverseOptions.MetadataOnly);
}
return _universe;
}
private static Assembly ReflectionOnlyLoadFrom (string fileName)
{
return GetUniverse ().LoadFile (fileName);
}
private static AssemblyName GetCorlibName ()
{
return GetUniverse ().Mscorlib.GetName ();
}
private static bool CheckReferencedAssemblies (AssemblyName an)
{
AppDomain d = null;
try {
Assembly a = Assembly.LoadFrom (an.CodeBase);
AssemblyName corlib = typeof (object).Assembly.GetName ();
Assembly a = ReflectionOnlyLoadFrom (an.CodeBase);
AssemblyName corlib = GetCorlibName ();
foreach (AssemblyName ref_an in a.GetReferencedAssemblies ()) {
if (ref_an.Name == corlib.Name) // Just do a string compare so we can install on diff versions
@@ -763,12 +780,6 @@ namespace Mono.Tools {
} catch (Exception e) {
WriteLine (e.ToString ()); // This should be removed pre beta3
return false;
} finally {
if (d != null) {
try {
AppDomain.Unload (d);
} catch { }
}
}
return true;
@@ -800,8 +811,8 @@ namespace Mono.Tools {
static bool LoadConfig (bool quiet)
{
MethodInfo config = typeof (System.Environment).GetMethod ("GetMachineConfigPath",
BindingFlags.Static | BindingFlags.NonPublic);
System.Reflection.MethodInfo config = typeof (System.Environment).GetMethod ("GetMachineConfigPath",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
if (config != null) {
string path = (string) config.Invoke (null, null);
@@ -832,7 +843,7 @@ namespace Mono.Tools {
// Note: MustVerify is based on the original token (by design). Public key
// remapping won't affect if the assembly is verified or not.
if (StrongNameManager.MustVerify (an)) {
if (StrongNameManager.MustVerify (new System.Reflection.AssemblyName (an.FullName))) {
RSA rsa = CryptoConvert.FromCapiPublicKeyBlob (publicKey, 12);
StrongName sn = new StrongName (rsa);
if (sn.Verify (assemblyFile)) {
@@ -899,20 +910,20 @@ namespace Mono.Tools {
public static extern int symlink (string oldpath, string newpath);
private static string GetGacDir () {
PropertyInfo gac = typeof (System.Environment).GetProperty ("GacPath",
BindingFlags.Static|BindingFlags.NonPublic);
System.Reflection.PropertyInfo gac = typeof (System.Environment).GetProperty ("GacPath",
System.Reflection.BindingFlags.Static|System.Reflection.BindingFlags.NonPublic);
if (gac == null) {
WriteLine ("ERROR: Mono runtime not detected, please use " +
"the mono runtime for gacutil.exe");
Environment.Exit (1);
}
MethodInfo get_gac = gac.GetGetMethod (true);
System.Reflection.MethodInfo get_gac = gac.GetGetMethod (true);
return (string) get_gac.Invoke (null, null);
}
private static string GetLibDir () {
MethodInfo libdir = typeof (System.Environment).GetMethod ("internalGetGacPath",
BindingFlags.Static|BindingFlags.NonPublic);
System.Reflection.MethodInfo libdir = typeof (System.Environment).GetMethod ("internalGetGacPath",
System.Reflection.BindingFlags.Static|System.Reflection.BindingFlags.NonPublic);
if (libdir == null) {
WriteLine ("ERROR: Mono runtime not detected, please use " +
"the mono runtime for gacutil.exe");

View File

@@ -1,2 +1,9 @@
driver.cs
../security/StrongNameManager.cs
../../../external/ikvm/reflect/*.cs
../../../external/ikvm/reflect/Metadata/*.cs
../../../external/ikvm/reflect/Emit/*.cs
../../../external/ikvm/reflect/Reader/*.cs
../../../external/ikvm/reflect/Writer/*.cs
../../../external/ikvm/reflect/Impl/ITypeOwner.cs
../../../external/ikvm/reflect/Impl/SymbolSupport.cs

View File

@@ -153,6 +153,10 @@
<type fullname="System.Collections.Generic.ICollection`1" />
<type fullname="System.Collections.Generic.IEnumerable`1" />
<type fullname="System.Collections.Generic.IEnumerator`1" />
<type fullname="System.Collections.Generic.IReadOnlyList`1" />
<type fullname="System.Collections.Generic.IReadOnlyCollection`1" />
<type fullname="System.Collections.Generic.IList`1" />
<type fullname="System.Collections.Generic.GenericEqualityComparer`1">
<method name=".ctor" />
@@ -219,8 +223,6 @@
<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" />
@@ -262,6 +264,7 @@
<type fullname="System.Reflection.Emit.MethodBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.ModuleBuilder" preserve="fields">
<method name="Mono_GetGuid" />
<method name="RuntimeResolve" />
</type>
<type fullname="System.Reflection.Emit.MonoResource" preserve="fields" />
<type fullname="System.Reflection.Emit.MonoWin32Resource" preserve="fields" />

View File

@@ -1,77 +0,0 @@
//
// 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

@@ -1,132 +0,0 @@
//
// 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;
using System.Linq;
using System.IO;
using System.Reflection;
using System.Xml;
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 (!name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase) || !IsReferenced (GetAssemblyName (name)))
continue;
try {
if (Context.LogInternalExceptions)
Console.WriteLine ("Processing resource linker descriptor: {0}", name);
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetResolveStep (name));
} catch (XmlException ex) {
/* This could happen if some broken XML file is included. */
if (Context.LogInternalExceptions)
Console.WriteLine ("Error processing {0}: {1}", name, ex);
}
}
foreach (var asm in Context.GetAssemblies ()) {
foreach (var rsc in asm.Modules
.SelectMany (mod => mod.Resources)
.Where (res => res.ResourceType == ResourceType.Embedded)
.Where (res => res.Name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase))
.Where (res => IsReferenced (GetAssemblyName (res.Name)))
.Cast<EmbeddedResource> ()) {
try {
if (Context.LogInternalExceptions)
Console.WriteLine ("Processing embedded resource linker descriptor: {0}", rsc.Name);
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc, asm));
} catch (XmlException ex) {
/* This could happen if some broken XML file is embedded. */
if (Context.LogInternalExceptions)
Console.WriteLine ("Error processing {0}: {1}", rsc.Name, ex);
}
}
}
}
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 GetExternalResolveStep (EmbeddedResource resource, AssemblyDefinition assembly)
{
return new ResolveFromXmlStep (GetExternalDescriptor (resource), "resource " + resource.Name + " in " + assembly.FullName);
}
static ResolveFromXmlStep GetResolveStep (string descriptor)
{
return new ResolveFromXmlStep (GetDescriptor (descriptor), "descriptor " + descriptor + " from " + Assembly.GetExecutingAssembly ().FullName);
}
static XPathDocument GetExternalDescriptor (EmbeddedResource resource)
{
using (var sr = new StreamReader (resource.GetResourceStream ())) {
return new XPathDocument (new StringReader (sr.ReadToEnd ()));
}
}
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

@@ -1,108 +0,0 @@
//
// 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

@@ -1,34 +0,0 @@
//
// 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

@@ -1,102 +0,0 @@
//
// 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

@@ -1,55 +0,0 @@
//
// 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

@@ -1,159 +0,0 @@
//
// 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 ();
Annotations.SaveDependencies ();
}
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:
Context.Annotations.AddDependency (assembly);
assembly.Write (GetAssemblyFileName (assembly, directory), SaveSymbols (assembly));
break;
case AssemblyAction.Copy:
Context.Annotations.AddDependency (assembly);
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.FileName);
}
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

@@ -1,48 +0,0 @@
//
// 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

@@ -1,137 +0,0 @@
//
// 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);
break;
default:
ProcessExecutable (assembly);
break;
}
}
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);
context.Annotations.Push (assembly);
foreach (TypeDefinition type in assembly.MainModule.Types)
MarkType (context, type);
context.Annotations.Pop ();
}
static void MarkType (LinkContext context, TypeDefinition type)
{
context.Annotations.Mark (type);
context.Annotations.Push (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);
context.Annotations.Pop ();
}
void ProcessExecutable (AssemblyDefinition assembly)
{
SetAction (Context, assembly, AssemblyAction.Link);
Annotations.Push (assembly);
Annotations.Mark (assembly.EntryPoint.DeclaringType);
MarkMethod (Context, assembly.EntryPoint, MethodAction.Parse);
Annotations.Pop ();
}
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

@@ -1,139 +0,0 @@
//
// 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

@@ -1,403 +0,0 @@
//
// 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 XmlResolutionException : Exception {
public XmlResolutionException (string message, Exception innerException)
: base (message, innerException)
{
}
}
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;
string _xmlDocumentLocation;
public ResolveFromXmlStep (XPathDocument document, string xmlDocumentLocation = "<unspecified>")
{
_document = document;
_xmlDocumentLocation = xmlDocumentLocation;
}
protected override void Process ()
{
XPathNavigator nav = _document.CreateNavigator ();
nav.MoveToFirstChild ();
// This step can be created with XML files that aren't necessarily
// linker descriptor files. So bail if we don't have a <linker> element.
if (nav.LocalName != "linker")
return;
try {
ProcessAssemblies (Context, nav.SelectChildren ("assembly", _ns));
} catch (Exception ex) {
throw new XmlResolutionException (string.Format ("Failed to process XML description: {0}", _xmlDocumentLocation), ex);
}
}
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 MatchType (TypeDefinition type, Regex regex, XPathNavigator nav)
{
if (regex.Match (type.FullName).Success)
ProcessType (type, nav);
if (!type.HasNestedTypes)
return;
foreach (var nt in type.NestedTypes)
MatchType (nt, regex, nav);
}
void ProcessTypePattern (string fullname, AssemblyDefinition assembly, XPathNavigator nav)
{
Regex regex = CreateRegexFromPattern (fullname);
foreach (TypeDefinition type in assembly.MainModule.Types) {
MatchType (type, regex, nav);
}
}
void ProcessType (TypeDefinition type, XPathNavigator nav)
{
TypePreserve preserve = GetTypePreserve (nav);
if (!IsRequired (nav)) {
Annotations.SetPreserve (type, preserve);
return;
}
Annotations.Mark (type);
if (type.IsNested) {
var parent = type;
while (parent.IsNested) {
parent = parent.DeclaringType;
Annotations.Mark (parent);
}
}
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