diff options
author | Marek Safar <marek.safar@gmail.com> | 2017-08-31 14:25:31 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-08-31 14:25:31 +0300 |
commit | b88f3ebf1494c2abea3f9565af689ecc51cf748b (patch) | |
tree | 9869e09d53d57dfc7c4630907f7b3ac56cf0766a | |
parent | 14e17dfbebf5651b5ce70c7fb317e388f8a3a271 (diff) | |
parent | 6ca33bf7fad842a056f4ab0c766d7399d7553f8e (diff) |
Merge remote-tracking branch 'upstream/master'
-rw-r--r-- | .editorconfig | 6 | ||||
-rw-r--r-- | Mono.Cecil/AssemblyReader.cs | 14 | ||||
-rw-r--r-- | Mono.Cecil/Import.cs | 41 | ||||
-rw-r--r-- | Mono.Cecil/MethodDefinition.cs | 5 | ||||
-rw-r--r-- | Mono.Cecil/MethodImplAttributes.cs | 1 | ||||
-rw-r--r-- | Mono.Cecil/ModuleDefinition.cs | 4 | ||||
-rw-r--r-- | Test/Mono.Cecil.Tests/PortablePdbTests.cs | 15 | ||||
-rw-r--r-- | Test/Resources/assemblies/mylib.dll | bin | 0 -> 4608 bytes | |||
-rw-r--r-- | Test/Resources/assemblies/mylib.pdb | bin | 0 -> 416 bytes |
9 files changed, 63 insertions, 23 deletions
diff --git a/.editorconfig b/.editorconfig index 7c2b956..6868a57 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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
\ No newline at end of file diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index 8217bc0..02d7787 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -2954,14 +2954,20 @@ namespace Mono.Cecil { if (record.Col2.Length > 0) { scope.variables = new Collection<VariableDebugInformation> ((int) record.Col2.Length); - for (uint i = 0; i < record.Col2.Length; i++) - scope.variables.Add (ReadLocalVariable (record.Col2.Start + i)); + for (uint i = 0; i < record.Col2.Length; i++) { + var variable = ReadLocalVariable (record.Col2.Start + i); + if (variable != null) + scope.variables.Add (variable); + } } if (record.Col3.Length > 0) { scope.constants = new Collection<ConstantDebugInformation> ((int) record.Col3.Length); - for (uint i = 0; i < record.Col3.Length; i++) - scope.constants.Add (ReadLocalConstant (record.Col3.Start + i)); + for (uint i = 0; i < record.Col3.Length; i++) { + var constant = ReadLocalConstant (record.Col3.Start + i); + if (constant != null) + scope.constants.Add (constant); + } } return scope; diff --git a/Mono.Cecil/Import.cs b/Mono.Cecil/Import.cs index e22e507..3d4d5bb 100644 --- a/Mono.Cecil/Import.cs +++ b/Mono.Cecil/Import.cs @@ -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; diff --git a/Mono.Cecil/MethodDefinition.cs b/Mono.Cecil/MethodDefinition.cs index 7fb5e65..71de613 100644 --- a/Mono.Cecil/MethodDefinition.cs +++ b/Mono.Cecil/MethodDefinition.cs @@ -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 diff --git a/Mono.Cecil/MethodImplAttributes.cs b/Mono.Cecil/MethodImplAttributes.cs index 7d48b33..2f1f018 100644 --- a/Mono.Cecil/MethodImplAttributes.cs +++ b/Mono.Cecil/MethodImplAttributes.cs @@ -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. } } diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs index 4550537..6888bbb 100644 --- a/Mono.Cecil/ModuleDefinition.cs +++ b/Mono.Cecil/ModuleDefinition.cs @@ -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,7 +397,7 @@ 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; } diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs index 3e1634e..2e73eec 100644 --- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs +++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs @@ -399,7 +399,7 @@ 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); @@ -407,6 +407,19 @@ namespace Mono.Cecil.Tests { } [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 () { TestModule ("TargetLib.dll", module => { diff --git a/Test/Resources/assemblies/mylib.dll b/Test/Resources/assemblies/mylib.dll Binary files differnew file mode 100644 index 0000000..8d48251 --- /dev/null +++ b/Test/Resources/assemblies/mylib.dll diff --git a/Test/Resources/assemblies/mylib.pdb b/Test/Resources/assemblies/mylib.pdb Binary files differnew file mode 100644 index 0000000..2f0dfdf --- /dev/null +++ b/Test/Resources/assemblies/mylib.pdb |