Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2021-03-15 22:06:28 +0300
committerMarek Safar <marek.safar@gmail.com>2021-03-15 22:06:28 +0300
commite069cd8d25d5b61b0e28fe65e75959c20af7aa80 (patch)
tree29dbd0329e51715722f005ce269646cc14fb2ed1
parent2f9b2fb759c50e756f9c6580b9fb8518581020c0 (diff)
parent553506adb74b1edbc12a8fb8cd681dcc93f180cf (diff)
Merge remote-tracking branch 'upstream/master' into main
-rw-r--r--Mono.Cecil/AssemblyReader.cs2
-rw-r--r--Mono.Cecil/AssemblyWriter.cs60
-rw-r--r--Mono.Cecil/ModuleDefinition.cs9
-rw-r--r--Mono.Cecil/WindowsRuntimeProjections.cs2
-rw-r--r--Test/Mono.Cecil.Tests/ModuleTests.cs21
-rw-r--r--Test/Mono.Cecil.Tests/PortablePdbTests.cs18
-rw-r--r--Test/Mono.Cecil.Tests/TypeParserTests.cs2
-rw-r--r--Test/Mono.Cecil.Tests/TypeTests.cs13
-rw-r--r--Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs18
-rw-r--r--Test/Resources/assemblies/ManagedWinmd.winmdbin8704 -> 10240 bytes
-rw-r--r--Test/Resources/assemblies/ReproConstGenericInst.dllbin0 -> 4608 bytes
-rw-r--r--Test/Resources/assemblies/ReproConstGenericInst.pdbbin0 -> 9564 bytes
12 files changed, 98 insertions, 47 deletions
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs
index d18a51e..2a59358 100644
--- a/Mono.Cecil/AssemblyReader.cs
+++ b/Mono.Cecil/AssemblyReader.cs
@@ -3013,7 +3013,7 @@ namespace Mono.Cecil {
value = new decimal (signature.ReadInt32 (), signature.ReadInt32 (), signature.ReadInt32 (), (b & 0x80) != 0, (byte) (b & 0x7f));
} else if (type.IsTypeOf ("System", "DateTime")) {
value = new DateTime (signature.ReadInt64());
- } else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class || type.etype == ElementType.Array) {
+ } else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class || type.etype == ElementType.Array || type.etype == ElementType.GenericInst) {
value = null;
} else
value = signature.ReadConstantSignature (type.etype);
diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs
index 41b53ae..f14ce1b 100644
--- a/Mono.Cecil/AssemblyWriter.cs
+++ b/Mono.Cecil/AssemblyWriter.cs
@@ -1441,7 +1441,8 @@ namespace Mono.Cecil {
if (type.HasInterfaces)
AddInterfaces (type);
- AddLayoutInfo (type);
+ if (type.HasLayoutInfo)
+ AddLayoutInfo (type);
if (type.HasFields)
AddFields (type);
@@ -1560,36 +1561,12 @@ namespace Mono.Cecil {
void AddLayoutInfo (TypeDefinition type)
{
- if (type.HasLayoutInfo) {
- var table = GetTable<ClassLayoutTable> (Table.ClassLayout);
+ var table = GetTable<ClassLayoutTable> (Table.ClassLayout);
- table.AddRow (new ClassLayoutRow (
- (ushort) type.PackingSize,
- (uint) type.ClassSize,
- type.token.RID));
-
- return;
- }
-
- if (type.IsValueType && HasNoInstanceField (type)) {
- var table = GetTable<ClassLayoutTable> (Table.ClassLayout);
-
- table.AddRow (new ClassLayoutRow (0, 1, type.token.RID));
- }
- }
-
- static bool HasNoInstanceField (TypeDefinition type)
- {
- if (!type.HasFields)
- return true;
-
- var fields = type.Fields;
-
- for (int i = 0; i < fields.Count; i++)
- if (!fields [i].IsStatic)
- return false;
-
- return true;
+ table.AddRow (new ClassLayoutRow (
+ (ushort) type.PackingSize,
+ (uint) type.ClassSize,
+ type.token.RID));
}
void AddNestedTypes (TypeDefinition type)
@@ -2994,7 +2971,7 @@ namespace Mono.Cecil {
break;
case ElementType.None:
if (type.IsTypeOf ("System", "Type"))
- WriteTypeReference ((TypeReference) value);
+ WriteCustomAttributeTypeValue ((TypeReference) value);
else
WriteCustomAttributeEnumValue (type, value);
break;
@@ -3004,6 +2981,27 @@ namespace Mono.Cecil {
}
}
+ private void WriteCustomAttributeTypeValue (TypeReference value)
+ {
+ var typeDefinition = value as TypeDefinition;
+
+ if (typeDefinition != null) {
+ TypeDefinition outermostDeclaringType = typeDefinition;
+ while (outermostDeclaringType.DeclaringType != null)
+ outermostDeclaringType = outermostDeclaringType.DeclaringType;
+
+ // In CLR .winmd files, custom attribute arguments reference unmangled type names (rather than <CLR>Name)
+ if (WindowsRuntimeProjections.IsClrImplementationType (outermostDeclaringType)) {
+ WindowsRuntimeProjections.Project (outermostDeclaringType);
+ WriteTypeReference (value);
+ WindowsRuntimeProjections.RemoveProjection (outermostDeclaringType);
+ return;
+ }
+ }
+
+ WriteTypeReference (value);
+ }
+
void WritePrimitiveValue (object value)
{
if (value == null)
diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs
index 1e5f4d0..fce2777 100644
--- a/Mono.Cecil/ModuleDefinition.cs
+++ b/Mono.Cecil/ModuleDefinition.cs
@@ -957,6 +957,15 @@ namespace Mono.Cecil {
{
return Read (token, (t, reader) => reader.LookupToken (t));
}
+
+ public void ImmediateRead ()
+ {
+ if (!HasImage)
+ return;
+ ReadingMode = ReadingMode.Immediate;
+ var moduleReader = new ImmediateModuleReader (Image);
+ moduleReader.ReadModule (this, resolve_attributes: true);
+ }
readonly object module_lock = new object();
diff --git a/Mono.Cecil/WindowsRuntimeProjections.cs b/Mono.Cecil/WindowsRuntimeProjections.cs
index 946116b..6e83ba6 100644
--- a/Mono.Cecil/WindowsRuntimeProjections.cs
+++ b/Mono.Cecil/WindowsRuntimeProjections.cs
@@ -389,7 +389,7 @@ namespace Mono.Cecil {
return true;
}
- static bool IsClrImplementationType (TypeDefinition type)
+ public static bool IsClrImplementationType (TypeDefinition type)
{
if ((type.Attributes & (TypeAttributes.VisibilityMask | TypeAttributes.SpecialName)) != TypeAttributes.SpecialName)
return false;
diff --git a/Test/Mono.Cecil.Tests/ModuleTests.cs b/Test/Mono.Cecil.Tests/ModuleTests.cs
index 5e4bee7..5af2a65 100644
--- a/Test/Mono.Cecil.Tests/ModuleTests.cs
+++ b/Test/Mono.Cecil.Tests/ModuleTests.cs
@@ -283,6 +283,27 @@ namespace Mono.Cecil.Tests {
}
}
+
+ [Test]
+ public void OpenModuleDeferredAndThenPerformImmediateRead ()
+ {
+ using (var module = GetResourceModule ("hello.exe", ReadingMode.Deferred)) {
+ Assert.AreEqual (ReadingMode.Deferred, module.ReadingMode);
+ module.ImmediateRead ();
+ Assert.AreEqual (ReadingMode.Immediate, module.ReadingMode);
+ }
+ }
+
+ [Test]
+ public void ImmediateReadDoesNothingForModuleWithNoImage ()
+ {
+ using (var module = new ModuleDefinition ()) {
+ var initialReadingMode = module.ReadingMode;
+ module.ImmediateRead ();
+ Assert.AreEqual (initialReadingMode, module.ReadingMode);
+ }
+ }
+
[Test]
public void OwnedStreamModuleFileName ()
{
diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs
index fc0516e..b0c1f32 100644
--- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs
+++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs
@@ -457,6 +457,24 @@ namespace Mono.Cecil.Tests {
}
[Test]
+ public void GenericInstConstantRecord ()
+ {
+ using (var module = GetResourceModule ("ReproConstGenericInst.dll", new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
+ var type = module.GetType ("ReproConstGenericInst.Program");
+ var method = type.GetMethod ("Main");
+ var symbol = method.DebugInformation;
+
+ Assert.IsNotNull (symbol);
+ Assert.AreEqual (1, symbol.Scope.Constants.Count);
+
+ var list = symbol.Scope.Constants [0];
+ Assert.AreEqual ("list", list.Name);
+
+ Assert.AreEqual ("System.Collections.Generic.List`1<System.String>", list.ConstantType.FullName);
+ }
+ }
+
+ [Test]
public void SourceLink ()
{
TestModule ("TargetLib.dll", module => {
diff --git a/Test/Mono.Cecil.Tests/TypeParserTests.cs b/Test/Mono.Cecil.Tests/TypeParserTests.cs
index a838c07..4845771 100644
--- a/Test/Mono.Cecil.Tests/TypeParserTests.cs
+++ b/Test/Mono.Cecil.Tests/TypeParserTests.cs
@@ -88,7 +88,7 @@ namespace Mono.Cecil.Tests {
public void FullyQualifiedTypeReference ()
{
var module = GetCurrentModule ();
- var cecil = module.AssemblyReferences.Where (reference => reference.Name == "Mono.Cecil").First ();
+ var cecil = module.AssemblyReferences.Where (reference => reference.Name != typeof (TypeDefinition).Assembly.GetName ().Name).First ();
var fullname = "Mono.Cecil.TypeDefinition, " + cecil.FullName;
diff --git a/Test/Mono.Cecil.Tests/TypeTests.cs b/Test/Mono.Cecil.Tests/TypeTests.cs
index 8d7f3fa..fddc8e6 100644
--- a/Test/Mono.Cecil.Tests/TypeTests.cs
+++ b/Test/Mono.Cecil.Tests/TypeTests.cs
@@ -31,19 +31,6 @@ namespace Mono.Cecil.Tests {
}
[Test]
- public void EmptyStructLayout ()
- {
- TestModule ("hello.exe", module =>
- {
- var foo = new TypeDefinition ("", "Foo",
- TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit | TypeAttributes.SequentialLayout,
- module.ImportReference (typeof (ValueType))) ;
-
- module.Types.Add (foo) ;
- }) ;
- }
-
- [Test]
public void SimpleInterfaces ()
{
TestIL ("types.il", module => {
diff --git a/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs b/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs
index bac85cf..5387273 100644
--- a/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs
+++ b/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs
@@ -131,6 +131,24 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (TypeDefinitionTreatment.PrefixWindowsRuntimeName, winrtSomeOtherClassType.WindowsRuntimeProjection.Treatment);
}, verify: false, assemblyResolver: WindowsRuntimeAssemblyResolver.CreateInstance (), applyWindowsRuntimeProjections: true);
}
+
+ [Test]
+ public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnmangledTypeName()
+ {
+ if (Platform.OnMono)
+ return;
+
+ TestModule(ModuleName, (module) =>
+ {
+ var type = module.Types.Single(t => t.Name == "ClassWithAsyncMethod");
+ var method = type.Methods.Single(m => m.Name == "DoStuffAsync");
+
+ var attribute = method.CustomAttributes.Single(a => a.AttributeType.Name == "AsyncStateMachineAttribute");
+ var attributeArgument = (TypeReference)attribute.ConstructorArguments[0].Value;
+
+ Assert.AreEqual("ManagedWinmd.ClassWithAsyncMethod/<DoStuffAsync>d__0", attributeArgument.FullName);
+ }, verify: false, assemblyResolver: WindowsRuntimeAssemblyResolver.CreateInstance(), applyWindowsRuntimeProjections: true);
+ }
}
[TestFixture]
diff --git a/Test/Resources/assemblies/ManagedWinmd.winmd b/Test/Resources/assemblies/ManagedWinmd.winmd
index 070ba28..f6e1d4f 100644
--- a/Test/Resources/assemblies/ManagedWinmd.winmd
+++ b/Test/Resources/assemblies/ManagedWinmd.winmd
Binary files differ
diff --git a/Test/Resources/assemblies/ReproConstGenericInst.dll b/Test/Resources/assemblies/ReproConstGenericInst.dll
new file mode 100644
index 0000000..4fce084
--- /dev/null
+++ b/Test/Resources/assemblies/ReproConstGenericInst.dll
Binary files differ
diff --git a/Test/Resources/assemblies/ReproConstGenericInst.pdb b/Test/Resources/assemblies/ReproConstGenericInst.pdb
new file mode 100644
index 0000000..7e564b5
--- /dev/null
+++ b/Test/Resources/assemblies/ReproConstGenericInst.pdb
Binary files differ