Imported Upstream version 5.8.0.88

Former-commit-id: 4b7216ffda08448e562271ce733688e761120fc5
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-11-28 19:36:51 +00:00
parent 7d05485754
commit 6123a772ed
277 changed files with 4817 additions and 941 deletions

View File

@@ -156,7 +156,6 @@ namespace Mono.Cecil {
this.module.Read (this.module, (module, reader) => {
ReadModuleManifest (reader);
ReadModule (module, resolve_attributes: true);
return module;
});
}
@@ -422,10 +421,7 @@ namespace Mono.Cecil {
protected override void ReadModule ()
{
this.module.Read (this.module, (module, reader) => {
ReadModuleManifest (reader);
return module;
});
this.module.Read (this.module, (_, reader) => ReadModuleManifest (reader));
}
public override void ReadSymbols (ModuleDefinition module)
@@ -943,8 +939,8 @@ namespace Mono.Cecil {
type.BaseType = GetTypeDefOrRef (ReadMetadataToken (CodedIndex.TypeDefOrRef));
type.fields_range = ReadFieldsRange (rid);
type.methods_range = ReadMethodsRange (rid);
type.fields_range = ReadListRange (rid, Table.TypeDef, Table.Field);
type.methods_range = ReadListRange (rid, Table.TypeDef, Table.Method);
if (IsNested (attributes))
type.DeclaringType = GetNestedTypeDeclaringType (type);
@@ -965,21 +961,13 @@ namespace Mono.Cecil {
return GetTypeDefinition (declaring_rid);
}
Range ReadFieldsRange (uint type_index)
{
return ReadListRange (type_index, Table.TypeDef, Table.Field);
}
Range ReadMethodsRange (uint type_index)
{
return ReadListRange (type_index, Table.TypeDef, Table.Method);
}
Range ReadListRange (uint current_index, Table current, Table target)
{
var list = new Range ();
list.Start = ReadTableIndex (target);
var start = ReadTableIndex (target);
if (start == 0)
return list;
uint next_index;
var current_table = image.TableHeap [current];
@@ -993,7 +981,8 @@ namespace Mono.Cecil {
this.position = position;
}
list.Length = next_index - list.Start;
list.Start = start;
list.Length = next_index - start;
return list;
}
@@ -1496,16 +1485,11 @@ namespace Mono.Cecil {
for (uint i = 1; i <= length; i++) {
var type_rid = ReadTableIndex (Table.TypeDef);
Range events_range = ReadEventsRange (i);
Range events_range = ReadListRange (i, Table.EventMap, Table.Event);
metadata.AddEventsRange (type_rid, events_range);
}
}
Range ReadEventsRange (uint rid)
{
return ReadListRange (rid, Table.EventMap, Table.Event);
}
public bool HasProperties (TypeDefinition type)
{
InitializeProperties ();
@@ -1585,16 +1569,11 @@ namespace Mono.Cecil {
for (uint i = 1; i <= length; i++) {
var type_rid = ReadTableIndex (Table.TypeDef);
var properties_range = ReadPropertiesRange (i);
var properties_range = ReadListRange (i, Table.PropertyMap, Table.Property);
metadata.AddPropertiesRange (type_rid, properties_range);
}
}
Range ReadPropertiesRange (uint rid)
{
return ReadListRange (rid, Table.PropertyMap, Table.Property);
}
MethodSemanticsAttributes ReadMethodSemantics (MethodDefinition method)
{
InitializeMethodSemantics ();
@@ -1697,23 +1676,19 @@ namespace Mono.Cecil {
}
}
public PropertyDefinition ReadMethods (PropertyDefinition property)
public void ReadMethods (PropertyDefinition property)
{
ReadAllSemantics (property.DeclaringType);
return property;
}
public EventDefinition ReadMethods (EventDefinition @event)
public void ReadMethods (EventDefinition @event)
{
ReadAllSemantics (@event.DeclaringType);
return @event;
}
public MethodSemanticsAttributes ReadAllSemantics (MethodDefinition method)
public void ReadAllSemantics (MethodDefinition method)
{
ReadAllSemantics (method.DeclaringType);
return method.SemanticsAttributes;
}
void ReadAllSemantics (TypeDefinition type)
@@ -1729,11 +1704,6 @@ namespace Mono.Cecil {
}
}
Range ReadParametersRange (uint method_rid)
{
return ReadListRange (method_rid, Table.Method, Table.Param);
}
public Collection<MethodDefinition> ReadMethods (TypeDefinition type)
{
var methods_range = type.methods_range;
@@ -1794,7 +1764,7 @@ namespace Mono.Cecil {
methods.Add (method); // attach method
var signature = ReadBlobIndex ();
var param_range = ReadParametersRange (method_rid);
var param_range = ReadListRange (method_rid, Table.Method, Table.Param);
this.context = method;
@@ -2121,6 +2091,11 @@ namespace Mono.Cecil {
return code.ReadMethodBody (method);
}
public int ReadCodeSize (MethodDefinition method)
{
return code.ReadCodeSize (method);
}
public CallSite ReadCallSite (MetadataToken token)
{
if (!MoveTo (Table.StandAloneSig, token.RID))
@@ -2387,8 +2362,8 @@ namespace Mono.Cecil {
var type_system = module.TypeSystem;
var context = new MethodReference (string.Empty, type_system.Void);
context.DeclaringType = new TypeReference (string.Empty, string.Empty, module, type_system.CoreLibrary);
var context = new MethodDefinition (string.Empty, MethodAttributes.Static, type_system.Void);
context.DeclaringType = new TypeDefinition (string.Empty, string.Empty, TypeAttributes.Public);
var member_references = new MemberReference [length];
@@ -3183,25 +3158,36 @@ namespace Mono.Cecil {
for (int i = 0; i < rows.Length; i++) {
if (rows [i].Col1 == StateMachineScopeDebugInformation.KindIdentifier) {
var signature = ReadSignature (rows [i].Col2);
infos.Add (new StateMachineScopeDebugInformation (signature.ReadInt32 (), signature.ReadInt32 ()));
var scopes = new Collection<StateMachineScope> ();
while (signature.CanReadMore ()) {
var start = signature.ReadInt32 ();
var end = start + signature.ReadInt32 ();
scopes.Add (new StateMachineScope (start, end));
}
var state_machine = new StateMachineScopeDebugInformation ();
state_machine.scopes = scopes;
infos.Add (state_machine);
} else if (rows [i].Col1 == AsyncMethodBodyDebugInformation.KindIdentifier) {
var signature = ReadSignature (rows [i].Col2);
var catch_offset = signature.ReadInt32 () - 1;
var yields = new Collection<InstructionOffset> ();
var resumes = new Collection<InstructionOffset> ();
uint move_next_rid = 0;
var resume_methods = new Collection<MethodDefinition> ();
while (signature.CanReadMore ()) {
yields.Add (new InstructionOffset (signature.ReadInt32 ()));
resumes.Add (new InstructionOffset (signature.ReadInt32 ()));
move_next_rid = signature.ReadCompressedUInt32 ();
resume_methods.Add (GetMethodDefinition (signature.ReadCompressedUInt32 ()));
}
var async_body = new AsyncMethodBodyDebugInformation (catch_offset);
async_body.yields = yields;
async_body.resumes = resumes;
async_body.move_next = GetMethodDefinition (move_next_rid);
async_body.resume_methods = resume_methods;
infos.Add (async_body);
} else if (rows [i].Col1 == EmbeddedSourceDebugInformation.KindIdentifier) {
@@ -3370,7 +3356,7 @@ namespace Mono.Cecil {
switch (etype) {
case ElementType.ValueType: {
var value_type = GetTypeDefOrRef (ReadTypeTokenSignature ());
value_type.IsValueType = true;
value_type.KnownValueType ();
return value_type;
}
case ElementType.Class:
@@ -3410,8 +3396,8 @@ namespace Mono.Cecil {
ReadGenericInstanceSignature (element_type, generic_instance);
if (is_value_type) {
generic_instance.IsValueType = true;
element_type.GetElementType ().IsValueType = true;
generic_instance.KnownValueType ();
element_type.GetElementType ().KnownValueType ();
}
return generic_instance;

View File

@@ -2392,13 +2392,19 @@ namespace Mono.Cecil {
var method_info = ((MethodDefinition) provider).DebugInformation;
var signature = CreateSignatureWriter ();
signature.WriteUInt32 ((uint) state_machine_scope.Start.Offset);
var end_offset = state_machine_scope.End.IsEndOfMethod
? method_info.code_size
: state_machine_scope.End.Offset;
var scopes = state_machine_scope.Scopes;
signature.WriteUInt32 ((uint) (end_offset - state_machine_scope.Start.Offset));
for (int i = 0; i < scopes.Count; i++) {
var scope = scopes [i];
signature.WriteUInt32 ((uint) scope.Start.Offset);
var end_offset = scope.End.IsEndOfMethod
? method_info.code_size
: scope.End.Offset;
signature.WriteUInt32 ((uint) (end_offset - scope.Start.Offset));
}
AddCustomDebugInformation (provider, state_machine_scope, signature);
}
@@ -2411,7 +2417,7 @@ namespace Mono.Cecil {
for (int i = 0; i < async_method.yields.Count; i++) {
signature.WriteUInt32 ((uint) async_method.yields [i].Offset);
signature.WriteUInt32 ((uint) async_method.resumes [i].Offset);
signature.WriteCompressedUInt32 (async_method.move_next.MetadataToken.RID);
signature.WriteCompressedUInt32 (async_method.resume_methods [i].MetadataToken.RID);
}
AddCustomDebugInformation (provider, async_method, signature);

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Mono.Collections.Generic;
@@ -65,14 +66,19 @@ namespace Mono.Cecil {
#endif
}
#if !NET_CORE
public abstract class BaseAssemblyResolver : IAssemblyResolver {
static readonly bool on_mono = Type.GetType ("Mono.Runtime") != null;
readonly Collection<string> directories;
#if NET_CORE
// Maps file names of available trusted platform assemblies to their full paths.
// Internal for testing.
internal static readonly Lazy<Dictionary<string, string>> TrustedPlatformAssemblies = new Lazy<Dictionary<string, string>> (CreateTrustedPlatformAssemblyMap);
#else
Collection<string> gac_paths;
#endif
public void AddSearchDirectory (string directory)
{
@@ -127,6 +133,11 @@ namespace Mono.Cecil {
};
}
#if NET_CORE
assembly = SearchTrustedPlatformAssemblies (name, parameters);
if (assembly != null)
return assembly;
#else
var framework_dir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName);
var framework_dirs = on_mono
? new [] { framework_dir, Path.Combine (framework_dir, "Facades") }
@@ -151,7 +162,7 @@ namespace Mono.Cecil {
assembly = SearchDirectory (name, framework_dirs, parameters);
if (assembly != null)
return assembly;
#endif
if (ResolveFailure != null) {
assembly = ResolveFailure (this, name);
if (assembly != null)
@@ -161,7 +172,45 @@ namespace Mono.Cecil {
throw new AssemblyResolutionException (name);
}
AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
#if NET_CORE
AssemblyDefinition SearchTrustedPlatformAssemblies (AssemblyNameReference name, ReaderParameters parameters)
{
if (name.IsWindowsRuntime)
return null;
if (TrustedPlatformAssemblies.Value.TryGetValue (name.Name, out string path))
return GetAssembly (path, parameters);
return null;
}
static Dictionary<string, string> CreateTrustedPlatformAssemblyMap ()
{
var result = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
string paths;
try {
// AppContext is only available on platforms that implement .NET Standard 1.6
var appContextType = Type.GetType ("System.AppContext, System.AppContext, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
var getData = appContextType?.GetTypeInfo ().GetDeclaredMethod ("GetData");
paths = (string) getData?.Invoke (null, new [] { "TRUSTED_PLATFORM_ASSEMBLIES" });
} catch {
paths = null;
}
if (paths == null)
return result;
foreach (var path in paths.Split (Path.PathSeparator))
if (string.Equals (Path.GetExtension (path), ".dll", StringComparison.OrdinalIgnoreCase))
result [Path.GetFileNameWithoutExtension (path)] = path;
return result;
}
#endif
protected virtual AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
{
var extensions = name.IsWindowsRuntime ? new [] { ".winmd", ".dll" } : new [] { ".exe", ".dll" };
foreach (var directory in directories) {
@@ -185,11 +234,11 @@ namespace Mono.Cecil {
return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0;
}
#if !NET_CORE
AssemblyDefinition GetCorlib (AssemblyNameReference reference, ReaderParameters parameters)
{
var version = reference.Version;
var corlib = typeof (object).Assembly.GetName ();
if (corlib.Version == version || IsZero (version))
return GetAssembly (typeof (object).Module.FullyQualifiedName, parameters);
@@ -325,7 +374,7 @@ namespace Mono.Cecil {
return null;
}
#endif
static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
var gac_folder = new StringBuilder ()
@@ -352,5 +401,4 @@ namespace Mono.Cecil {
{
}
}
#endif
}

View File

@@ -62,8 +62,10 @@ namespace Mono.Cecil {
bool HasFields { get; }
bool HasProperties { get; }
bool HasConstructorArguments { get; }
Collection<CustomAttributeNamedArgument> Fields { get; }
Collection<CustomAttributeNamedArgument> Properties { get; }
Collection<CustomAttributeArgument> ConstructorArguments { get; }
}
public sealed class CustomAttribute : ICustomAttribute {
@@ -196,7 +198,6 @@ namespace Mono.Cecil {
resolved = false;
}
return this;
});
}
}

View File

@@ -8,8 +8,6 @@
// Licensed under the MIT/X11 license.
//
#if !NET_CORE
using System;
using System.Collections.Generic;
@@ -61,5 +59,3 @@ namespace Mono.Cecil {
}
}
}
#endif

View File

@@ -143,9 +143,9 @@ namespace Mono.Cecil {
public MethodBody Body {
get {
MethodBody localBody = this.body;
if (localBody != null)
return localBody;
var local = this.body;
if (local != null)
return local;
if (!HasBody)
return null;

View File

@@ -418,13 +418,11 @@ namespace Mono.Cecil {
public IAssemblyResolver AssemblyResolver {
get {
#if !NET_CORE
if (assembly_resolver.value == null) {
lock (module_lock) {
assembly_resolver = Disposable.Owned (new DefaultAssemblyResolver () as IAssemblyResolver);
}
}
#endif
return assembly_resolver.value;
}
@@ -754,28 +752,16 @@ namespace Mono.Cecil {
internal FieldDefinition Resolve (FieldReference field)
{
#if NET_CORE
if (MetadataResolver == null)
throw new NotSupportedException ();
#endif
return MetadataResolver.Resolve (field);
}
internal MethodDefinition Resolve (MethodReference method)
{
#if NET_CORE
if (MetadataResolver == null)
throw new NotSupportedException ();
#endif
return MetadataResolver.Resolve (method);
}
internal TypeDefinition Resolve (TypeReference type)
{
#if NET_CORE
if (MetadataResolver == null)
throw new NotSupportedException ();
#endif
return MetadataResolver.Resolve (type);
}
@@ -970,6 +956,19 @@ namespace Mono.Cecil {
get { return module_lock; }
}
internal void Read<TItem> (TItem item, Action<TItem, MetadataReader> read)
{
lock (module_lock) {
var position = reader.position;
var context = reader.context;
read (item, reader);
reader.position = position;
reader.context = context;
}
}
internal TRet Read<TItem, TRet> (TItem item, Func<TItem, MetadataReader, TRet> read)
{
lock (module_lock) {
@@ -1321,6 +1320,9 @@ namespace Mono.Cecil {
public static TargetRuntime ParseRuntime (this string self)
{
if (string.IsNullOrEmpty (self))
return TargetRuntime.Net_4_0;
switch (self [1]) {
case '1':
return self [3] == '0'

View File

@@ -70,6 +70,14 @@ namespace Mono.Cecil {
{
this.attribute_type = attributeType;
}
bool ICustomAttribute.HasConstructorArguments {
get { return false; }
}
Collection<CustomAttributeArgument> ICustomAttribute.ConstructorArguments {
get { throw new NotSupportedException (); }
}
}
public sealed class SecurityDeclaration {
@@ -143,11 +151,7 @@ namespace Mono.Cecil {
if (resolved || !HasImage)
return;
module.Read (this, (declaration, reader) => {
reader.ReadSecurityDeclarationSignature (declaration);
return this;
});
module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationSignature (declaration));
resolved = true;
}
}

View File

@@ -416,6 +416,9 @@ namespace Mono.Cecil {
return base_type.IsTypeOf ("System", "Enum") || (base_type.IsTypeOf ("System", "ValueType") && !this.IsTypeOf ("System", "Enum"));
}
set {
throw new NotSupportedException ();
}
}
public override bool IsPrimitive {

View File

@@ -184,7 +184,7 @@ namespace Mono.Cecil {
return typeRef;
var type = LookupType ("System", name);
type.etype = element_type;
type.IsValueType = true;
type.KnownValueType ();
return typeRef = type;
}
}
@@ -313,6 +313,12 @@ namespace Mono.Cecil {
return true;
}
public static void KnownValueType (this TypeReference type)
{
if (!type.IsDefinition)
type.IsValueType = true;
}
static bool IsCoreLibrary (AssemblyNameReference reference)
{
var name = reference.Name;