Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -3,3 +3,9 @@ root = true
[*.cs]
indent_style = tab
csharp_space_between_method_declaration_name_and_open_parenthesis = true
csharp_space_between_method_call_name_and_opening_parenthesis = true
csharp_space_before_open_square_brackets = true
csharp_new_line_before_open_brace = methods
csharp_new_line_before_else = false
csharp_indent_switch_labels = false

View File

@@ -775,7 +775,7 @@ namespace Mono.Cecil {
}
}
sealed class CustomDebugInformationTable : MetadataTable<CustomDebugInformationRow> {
sealed class CustomDebugInformationTable : SortedTable<CustomDebugInformationRow> {
public override void Write (TableHeapBuffer buffer)
{
@@ -785,6 +785,11 @@ namespace Mono.Cecil {
buffer.WriteBlob (rows [i].Col3); // Value
}
}
public override int Compare (CustomDebugInformationRow x, CustomDebugInformationRow y)
{
return Compare(x.Col1, y.Col1);
}
}
sealed class MetadataBuilder {

View File

@@ -24,6 +24,7 @@ namespace Mono.Cecil {
}
public interface IMetadataImporter {
AssemblyNameReference ImportReference (AssemblyNameReference reference);
TypeReference ImportReference (TypeReference type, IGenericParameterProvider context);
FieldReference ImportReference (FieldReference field, IGenericParameterProvider context);
MethodReference ImportReference (MethodReference method, IGenericParameterProvider context);
@@ -34,6 +35,7 @@ namespace Mono.Cecil {
}
public interface IReflectionImporter {
AssemblyNameReference ImportReference (SR.AssemblyName reference);
TypeReference ImportReference (Type type, IGenericParameterProvider context);
FieldReference ImportReference (SR.FieldInfo field, IGenericParameterProvider context);
MethodReference ImportReference (SR.MethodBase method, IGenericParameterProvider context);
@@ -122,11 +124,11 @@ namespace Mono.Cecil {
}
}
public class ReflectionImporter : IReflectionImporter {
public class DefaultReflectionImporter : IReflectionImporter {
readonly ModuleDefinition module;
readonly protected ModuleDefinition module;
public ReflectionImporter (ModuleDefinition module)
public DefaultReflectionImporter (ModuleDefinition module)
{
Mixin.CheckModule (module);
@@ -294,14 +296,19 @@ namespace Mono.Cecil {
AssemblyNameReference ImportScope (SR.Assembly assembly)
{
AssemblyNameReference scope;
return ImportReference (assembly.GetName ());
}
var name = assembly.GetName ();
public virtual AssemblyNameReference ImportReference (SR.AssemblyName name)
{
Mixin.CheckName (name);
if (TryGetAssemblyNameReference (name, out scope))
return scope;
AssemblyNameReference reference;
if (TryGetAssemblyNameReference (name, out reference))
return reference;
scope = new AssemblyNameReference (name.Name, name.Version) {
reference = new AssemblyNameReference (name.Name, name.Version)
{
PublicKeyToken = name.GetPublicKeyToken (),
#if !NET_CORE
Culture = name.CultureInfo.Name,
@@ -309,9 +316,9 @@ namespace Mono.Cecil {
#endif
};
module.AssemblyReferences.Add (scope);
module.AssemblyReferences.Add (reference);
return scope;
return reference;
}
bool TryGetAssemblyNameReference (SR.AssemblyName name, out AssemblyNameReference assembly_reference)
@@ -477,11 +484,11 @@ namespace Mono.Cecil {
}
}
public class MetadataImporter : IMetadataImporter {
public class DefaultMetadataImporter : IMetadataImporter {
readonly ModuleDefinition module;
readonly protected ModuleDefinition module;
public MetadataImporter (ModuleDefinition module)
public DefaultMetadataImporter (ModuleDefinition module)
{
Mixin.CheckModule (module);
@@ -515,10 +522,10 @@ namespace Mono.Cecil {
{
switch (scope.MetadataScopeType) {
case MetadataScopeType.AssemblyNameReference:
return ImportAssemblyName ((AssemblyNameReference) scope);
return ImportReference ((AssemblyNameReference) scope);
case MetadataScopeType.ModuleDefinition:
if (scope == module) return scope;
return ImportAssemblyName (((ModuleDefinition) scope).Assembly.Name);
return ImportReference (((ModuleDefinition) scope).Assembly.Name);
case MetadataScopeType.ModuleReference:
throw new NotImplementedException ();
}
@@ -526,8 +533,10 @@ namespace Mono.Cecil {
throw new NotSupportedException ();
}
internal virtual AssemblyNameReference ImportAssemblyName (AssemblyNameReference name)
public virtual AssemblyNameReference ImportReference (AssemblyNameReference name)
{
Mixin.CheckName (name);
AssemblyNameReference reference;
if (module.TryGetAssemblyNameReference (name, out reference))
return reference;

View File

@@ -416,6 +416,11 @@ namespace Mono.Cecil {
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.NoOptimization, value); }
}
public bool AggressiveInlining {
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.AggressiveInlining); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.AggressiveInlining, value); }
}
#endregion
#region MethodSemanticsAttributes

View File

@@ -31,5 +31,6 @@ namespace Mono.Cecil {
Synchronized = 0x0020, // Method is single threaded through the body
NoOptimization = 0x0040, // Method is not optimized by the JIT.
NoInlining = 0x0008, // Method may not be inlined
AggressiveInlining = 0x0100, // Method should be inlined, if possible.
}
}

View File

@@ -388,7 +388,7 @@ namespace Mono.Cecil {
internal IReflectionImporter ReflectionImporter {
get {
if (reflection_importer == null)
Interlocked.CompareExchange (ref reflection_importer, new ReflectionImporter (this), null);
Interlocked.CompareExchange (ref reflection_importer, new DefaultReflectionImporter (this), null);
return reflection_importer;
}
@@ -397,13 +397,13 @@ namespace Mono.Cecil {
internal IMetadataImporter MetadataImporter {
get {
if (metadata_importer == null)
Interlocked.CompareExchange (ref metadata_importer, new MetadataImporter (this), null);
Interlocked.CompareExchange (ref metadata_importer, new DefaultMetadataImporter (this), null);
return metadata_importer;
}
}
internal void SetMetadataImporter (MetadataImporter importer)
internal void SetMetadataImporter (IMetadataImporter importer)
{
if (this.metadata_importer != null)
throw new InvalidOperationException ();

View File

@@ -251,6 +251,10 @@ namespace Mono.Cecil.Tests {
static string WinSdkTool (string tool)
{
var sdks = new [] {
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools",
@"Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools",
@"Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools",
@"Microsoft SDKs\Windows\v7.0A\Bin",

View File

@@ -399,13 +399,26 @@ namespace Mono.Cecil.Tests {
var symbol = method.DebugInformation;
Assert.IsNotNull (symbol);
Assert.AreEqual(1, symbol.Scope.Constants.Count);
Assert.AreEqual (1, symbol.Scope.Constants.Count);
var a = symbol.Scope.Constants [0];
Assert.AreEqual ("a", a.Name);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
[Test]
public void InvalidConstantRecord ()
{
using (var module = GetResourceModule ("mylib.dll", new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
var type = module.GetType ("mylib.Say");
var method = type.GetMethod ("hello");
var symbol = method.DebugInformation;
Assert.IsNotNull (symbol);
Assert.AreEqual (0, symbol.Scope.Constants.Count);
}
}
[Test]
public void SourceLink ()
{

Binary file not shown.

View File

@@ -58,10 +58,5 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
});
}
static string Normalize (string s)
{
return s.Replace ("\n", "").Replace ("\r", "");
}
}
}

View File

@@ -684,6 +684,7 @@ namespace Mono.CompilerServices.SymbolWriter
byte[] hash;
bool creating;
bool auto_generated;
readonly string sourceFile;
public static int Size {
get { return 8; }
@@ -698,11 +699,17 @@ namespace Mono.CompilerServices.SymbolWriter
creating = true;
}
public SourceFileEntry (MonoSymbolFile file, string file_name, byte[] guid, byte[] checksum)
: this (file, file_name)
public SourceFileEntry (MonoSymbolFile file, string sourceFile, byte [] guid, byte [] checksum)
: this (file, sourceFile, sourceFile, guid, checksum)
{
}
public SourceFileEntry (MonoSymbolFile file, string fileName, string sourceFile, byte[] guid, byte[] checksum)
: this (file, fileName)
{
this.guid = guid;
this.hash = checksum;
this.sourceFile = sourceFile;
}
public byte[] Checksum {
@@ -719,29 +726,22 @@ namespace Mono.CompilerServices.SymbolWriter
if (guid == null)
guid = new byte[16];
if (hash == null)
hash = ComputeHash ();
if (hash == null) {
try {
using (FileStream fs = new FileStream (sourceFile, FileMode.Open, FileAccess.Read)) {
MD5 md5 = MD5.Create ();
hash = md5.ComputeHash (fs);
}
} catch {
hash = new byte [16];
}
}
bw.Write (guid);
bw.Write (hash);
bw.Write ((byte) (auto_generated ? 1 : 0));
}
private byte [] ComputeHash ()
{
if (!File.Exists (file_name))
return new byte [16];
try {
using (FileStream fs = new FileStream (file_name, FileMode.Open, FileAccess.Read)) {
MD5 md5 = MD5.Create ();
return md5.ComputeHash (fs);
}
} catch {
return new byte [16];
}
}
internal void Write (BinaryWriter bw)
{
bw.Write (Index);
@@ -758,7 +758,7 @@ namespace Mono.CompilerServices.SymbolWriter
int old_pos = (int) reader.BaseStream.Position;
reader.BaseStream.Position = DataOffset;
file_name = reader.ReadString ();
sourceFile = file_name = reader.ReadString ();
guid = reader.ReadBytes (16);
hash = reader.ReadBytes (16);
auto_generated = reader.ReadByte () == 1;
@@ -787,7 +787,7 @@ namespace Mono.CompilerServices.SymbolWriter
public bool CheckChecksum ()
{
try {
using (FileStream fs = new FileStream (file_name, FileMode.Open)) {
using (FileStream fs = new FileStream (sourceFile, FileMode.Open)) {
MD5 md5 = MD5.Create ();
byte[] data = md5.ComputeHash (fs);
for (int i = 0; i < 16; i++)

View File

@@ -28,6 +28,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
namespace Mono.CompilerServices.SymbolWriter
@@ -89,6 +90,11 @@ namespace Mono.CompilerServices.SymbolWriter
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset)
{
StartBlock (type, start_offset, _blocks == null ? 1 : _blocks.Count + 1);
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset, int scopeIndex)
{
if (_block_stack == null) {
_block_stack = new Stack<CodeBlockEntry> ();
@@ -100,7 +106,7 @@ namespace Mono.CompilerServices.SymbolWriter
int parent = CurrentBlock != null ? CurrentBlock.Index : -1;
CodeBlockEntry block = new CodeBlockEntry (
_blocks.Count + 1, parent, type, start_offset);
scopeIndex, parent, type, start_offset);
_block_stack.Push (block);
_blocks.Add (block);
@@ -180,9 +186,59 @@ namespace Mono.CompilerServices.SymbolWriter
public void DefineMethod (MonoSymbolFile file, int token)
{
MethodEntry entry = new MethodEntry (
var blocks = Blocks;
if (blocks.Length > 0) {
//
// When index is provided by user it can be inserted in
// any order but mdb format does not store its value. It
// uses stored order as the index instead.
//
var sorted = new List<CodeBlockEntry> (blocks.Length);
int max_index = 0;
for (int i = 0; i < blocks.Length; ++i) {
max_index = System.Math.Max (max_index, blocks [i].Index);
}
for (int i = 0; i < max_index; ++i) {
var scope_index = i + 1;
//
// Common fast path
//
if (i < blocks.Length && blocks [i].Index == scope_index) {
sorted.Add (blocks [i]);
continue;
}
bool found = false;
for (int ii = 0; ii < blocks.Length; ++ii) {
if (blocks [ii].Index == scope_index) {
sorted.Add (blocks [ii]);
found = true;
break;
}
}
if (found)
continue;
//
// Ideally this should never happen but with current design we can
// generate scope index for unreachable code before reachable code
//
sorted.Add (new CodeBlockEntry (scope_index, -1, CodeBlockEntry.Type.CompilerGenerated, 0));
}
blocks = sorted.ToArray ();
//for (int i = 0; i < blocks.Length; ++i) {
// if (blocks [i].Index - 1 != i)
// throw new ArgumentException ("CodeBlocks cannot be converted to mdb format");
//}
}
var entry = new MethodEntry (
file, _comp_unit.Entry, token, ScopeVariables,
Locals, method_lines.ToArray (), Blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);
Locals, method_lines.ToArray (), blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);
file.AddMethod (entry);
}