Browse Source

Update Cecil (jbevain/threadsafe2 at b66b74f1874b7f713e7385c7fa7c32a926214230)

pull/308/merge
Jb Evain 15 years ago committed by Daniel Grunwald
parent
commit
bbe06cbe7a
  1. 1
      Mono.Cecil/.gitignore
  2. 3
      Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs
  3. 1
      Mono.Cecil/Mono.Cecil.Cil/Document.cs
  4. 19
      Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs
  5. 2
      Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs
  6. 2
      Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs
  7. 2
      Mono.Cecil/Mono.Cecil.nuspec
  8. 2
      Mono.Cecil/Mono.Cecil/AssemblyInfo.cs
  9. 14
      Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs
  10. 36
      Mono.Cecil/Mono.Cecil/AssemblyReader.cs
  11. 2
      Mono.Cecil/Mono.Cecil/AssemblyWriter.cs
  12. 4
      Mono.Cecil/Mono.Cecil/CustomAttribute.cs
  13. 2
      Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs
  14. 104
      Mono.Cecil/Mono.Cecil/GenericParameter.cs
  15. 4
      Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs
  16. 6
      Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs
  17. 4
      Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs
  18. 2
      Mono.Cecil/Mono.Cecil/Import.cs
  19. 72
      Mono.Cecil/Mono.Cecil/MetadataResolver.cs
  20. 43
      Mono.Cecil/Mono.Cecil/MetadataSystem.cs
  21. 2
      Mono.Cecil/Mono.Cecil/MethodDefinition.cs
  22. 1
      Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs
  23. 2
      Mono.Cecil/Mono.Cecil/MethodReference.cs
  24. 15
      Mono.Cecil/Mono.Cecil/MethodReturnType.cs
  25. 72
      Mono.Cecil/Mono.Cecil/ModuleDefinition.cs
  26. 6
      Mono.Cecil/Mono.Cecil/ParameterDefinition.cs
  27. 17
      Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs
  28. 18
      Mono.Cecil/Mono.Cecil/TypeDefinition.cs
  29. 2
      Mono.Cecil/Mono.Cecil/TypeParser.cs
  30. 49
      Mono.Cecil/Mono.Cecil/TypeReference.cs
  31. 10
      Mono.Cecil/Mono.Cecil/TypeSystem.cs
  32. 19
      Mono.Cecil/Test/Mono.Cecil.Tests.csproj
  33. 8
      Mono.Cecil/Test/Mono.Cecil.Tests/Addin.cs
  34. 2
      Mono.Cecil/Test/Mono.Cecil.Tests/AssemblyInfo.cs
  35. 10
      Mono.Cecil/Test/Mono.Cecil.Tests/AssemblyTests.cs
  36. 8
      Mono.Cecil/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
  37. 8
      Mono.Cecil/Test/Mono.Cecil.Tests/FieldTests.cs
  38. 6
      Mono.Cecil/Test/Mono.Cecil.Tests/Formatter.cs
  39. 40
      Mono.Cecil/Test/Mono.Cecil.Tests/ImageReadTests.cs
  40. 49
      Mono.Cecil/Test/Mono.Cecil.Tests/MethodBodyTests.cs
  41. 8
      Mono.Cecil/Test/Mono.Cecil.Tests/MethodTests.cs
  42. 10
      Mono.Cecil/Test/Mono.Cecil.Tests/ModuleTests.cs
  43. 34
      Mono.Cecil/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs
  44. 34
      Mono.Cecil/Test/Mono.Cecil.Tests/TypeParserTests.cs
  45. 42
      Mono.Cecil/Test/Mono.Cecil.Tests/TypeTests.cs
  46. BIN
      Mono.Cecil/Test/Resources/assemblies/cscgpbug.dll
  47. 7
      Mono.Cecil/Test/Resources/cs/Generics.cs
  48. 12
      Mono.Cecil/Test/Resources/il/types.il
  49. BIN
      Mono.Cecil/Test/libs/nunit-2.4.8/nunit.core.dll
  50. BIN
      Mono.Cecil/Test/libs/nunit-2.4.8/nunit.core.interfaces.dll
  51. BIN
      Mono.Cecil/Test/libs/nunit-2.4.8/nunit.framework.dll
  52. BIN
      Mono.Cecil/Test/libs/nunit-2.5.10/nunit.core.dll
  53. BIN
      Mono.Cecil/Test/libs/nunit-2.5.10/nunit.core.interfaces.dll
  54. BIN
      Mono.Cecil/Test/libs/nunit-2.5.10/nunit.framework.dll
  55. 2
      Mono.Cecil/rocks/Mono.Cecil.Rocks/AssemblyInfo.cs
  56. 12
      Mono.Cecil/rocks/Test/Mono.Cecil.Rocks.Tests.csproj
  57. 18
      Mono.Cecil/rocks/Test/Mono.Cecil.Tests/TypeReferenceRocksTests.cs
  58. 0
      Mono.Cecil/rocks/Test/Resources/cs/Types.cs
  59. 2
      Mono.Cecil/symbols/mdb/Mono.Cecil.Mdb/AssemblyInfo.cs
  60. 12
      Mono.Cecil/symbols/mdb/Test/Mono.Cecil.Mdb.Tests.csproj
  61. 98
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs
  62. 69
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs
  63. 109
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs
  64. 95
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs
  65. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs
  66. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs
  67. 11
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs
  68. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs
  69. 262
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs
  70. 21
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs
  71. 12
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs
  72. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs
  73. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs
  74. 72
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs
  75. 88
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
  76. 123
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs
  77. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs
  78. 7
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs
  79. 13
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs
  80. 32
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs
  81. 15
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs
  82. 13
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs
  83. 129
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs
  84. 33
      Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs
  85. 3
      Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb.csproj
  86. 2
      Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/AssemblyInfo.cs
  87. 101
      Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/ModuleMetadata.cs
  88. 1
      Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/PdbHelper.cs
  89. 8
      Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/PdbReader.cs
  90. 16
      Mono.Cecil/symbols/pdb/Test/Mono.Cecil.Pdb.Tests.csproj
  91. 36
      Mono.Cecil/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs
  92. BIN
      Mono.Cecil/symbols/pdb/Test/Resources/assemblies/VBConsApp.exe
  93. BIN
      Mono.Cecil/symbols/pdb/Test/Resources/assemblies/VBConsApp.pdb
  94. BIN
      Mono.Cecil/symbols/pdb/Test/Resources/assemblies/fsapp.exe
  95. BIN
      Mono.Cecil/symbols/pdb/Test/Resources/assemblies/fsapp.pdb

1
Mono.Cecil/.gitignore vendored

@ -7,3 +7,4 @@ obj @@ -7,3 +7,4 @@ obj
*.xml
*.nupkg
**/test-results/*
*Resharper*

3
Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs

@ -519,6 +519,9 @@ namespace Mono.Cecil.Cil { @@ -519,6 +519,9 @@ namespace Mono.Cecil.Cil {
static bool IsFatRange (Instruction start, Instruction end)
{
if (start == null)
throw new ArgumentException ();
if (end == null)
return true;

1
Mono.Cecil/Mono.Cecil.Cil/Document.cs

@ -54,6 +54,7 @@ namespace Mono.Cecil.Cil { @@ -54,6 +54,7 @@ namespace Mono.Cecil.Cil {
JScript,
Smc,
MCpp,
FSharp,
}
public enum DocumentLanguageVendor {

19
Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs

@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
//
using System;
using System.Threading;
using Mono.Collections.Generic;
@ -100,10 +101,26 @@ namespace Mono.Cecil.Cil { @@ -100,10 +101,26 @@ namespace Mono.Cecil.Cil {
if (method == null || method.DeclaringType == null)
throw new NotSupportedException ();
return this_parameter ?? (this_parameter = new ParameterDefinition ("0", ParameterAttributes.None, method.DeclaringType));
if (!method.HasThis)
return null;
if (this_parameter == null)
Interlocked.CompareExchange (ref this_parameter, ThisParameterFor (method), null);
return this_parameter;
}
}
static ParameterDefinition ThisParameterFor (MethodDefinition method)
{
var declaring_type = method.DeclaringType;
var type = declaring_type.IsValueType || declaring_type.IsPrimitive
? new PointerType (declaring_type)
: declaring_type as TypeReference;
return new ParameterDefinition (type, method);
}
public MethodBody (MethodDefinition method)
{
this.method = method;

2
Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs

@ -274,7 +274,7 @@ namespace Mono.Cecil.Metadata { @@ -274,7 +274,7 @@ namespace Mono.Cecil.Metadata {
class StringHeapBuffer : HeapBuffer {
readonly Dictionary<string, uint> strings = new Dictionary<string, uint> ();
readonly Dictionary<string, uint> strings = new Dictionary<string, uint> (StringComparer.Ordinal);
public sealed override bool IsEmpty {
get { return length <= 1; }

2
Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs

@ -71,11 +71,11 @@ namespace Mono.Cecil.PE { @@ -71,11 +71,11 @@ namespace Mono.Cecil.PE {
{
this.module = module;
this.metadata = metadata;
this.pe64 = module.Architecture != TargetArchitecture.I386;
this.GetDebugHeader ();
this.GetWin32Resources ();
this.text_map = BuildTextMap ();
this.sections = 2; // text + reloc
this.pe64 = module.Architecture != TargetArchitecture.I386;
this.time_stamp = (uint) DateTime.UtcNow.Subtract (new DateTime (1970, 1, 1)).TotalSeconds;
}

2
Mono.Cecil/Mono.Cecil.nuspec

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Mono.Cecil</id>
<version>0.9.5.0</version>
<version>0.9.5.2</version>
<title>Mono.Cecil</title>
<authors>Jb Evain</authors>
<owners>Jb Evain</owners>

2
Mono.Cecil/Mono.Cecil/AssemblyInfo.cs

@ -32,7 +32,7 @@ using System.Runtime.InteropServices; @@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2010 Jb Evain")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")]
[assembly: ComVisible (false)]

14
Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs

@ -203,22 +203,22 @@ namespace Mono.Cecil { @@ -203,22 +203,22 @@ namespace Mono.Cecil {
if (parts.Length != 2)
throw new ArgumentException ("Malformed name");
switch (parts [0]) {
case "Version":
switch (parts [0].ToLowerInvariant ()) {
case "version":
name.Version = new Version (parts [1]);
break;
case "Culture":
case "culture":
name.Culture = parts [1];
break;
case "PublicKeyToken":
string pk_token = parts [1];
case "publickeytoken":
var pk_token = parts [1];
if (pk_token == "null")
break;
name.PublicKeyToken = new byte [pk_token.Length / 2];
for (int j = 0; j < name.PublicKeyToken.Length; j++) {
for (int j = 0; j < name.PublicKeyToken.Length; j++)
name.PublicKeyToken [j] = Byte.Parse (pk_token.Substring (j * 2, 2), NumberStyles.HexNumber);
}
break;
}
}

36
Mono.Cecil/Mono.Cecil/AssemblyReader.cs

@ -85,6 +85,9 @@ namespace Mono.Cecil { @@ -85,6 +85,9 @@ namespace Mono.Cecil {
if (parameters.AssemblyResolver != null)
module.assembly_resolver = parameters.AssemblyResolver;
if (parameters.MetadataResolver != null)
module.metadata_resolver = parameters.MetadataResolver;
return module;
}
@ -525,11 +528,10 @@ namespace Mono.Cecil { @@ -525,11 +528,10 @@ namespace Mono.Cecil {
public MethodDefinition ReadEntryPoint ()
{
if (module.Kind != ModuleKind.Console && module.Kind != ModuleKind.Windows)
if (module.Image.EntryPointToken == 0)
return null;
var token = new MetadataToken (module.Image.EntryPointToken);
return GetMethodDefinition (token.RID);
}
@ -1031,7 +1033,7 @@ namespace Mono.Cecil { @@ -1031,7 +1033,7 @@ namespace Mono.Cecil {
type.scope = scope;
type.DeclaringType = declaring_type;
MetadataSystem.TryProcessPrimitiveType (type);
MetadataSystem.TryProcessPrimitiveTypeReference (type);
return type;
}
@ -1796,11 +1798,11 @@ namespace Mono.Cecil { @@ -1796,11 +1798,11 @@ namespace Mono.Cecil {
Range range;
if (!metadata.TryGetGenericParameterRange (provider, out range)
|| !MoveTo (Table.GenericParam, range.Start))
return new Collection<GenericParameter> ();
return new GenericParameterCollection (provider);
metadata.RemoveGenericParameterRange (provider);
var generic_parameters = new Collection<GenericParameter> ((int) range.Length);
var generic_parameters = new GenericParameterCollection (provider, (int) range.Length);
for (uint i = 0; i < range.Length; i++) {
ReadUInt16 (); // index
@ -2186,7 +2188,8 @@ namespace Mono.Cecil { @@ -2186,7 +2188,8 @@ namespace Mono.Cecil {
{
var declaring_type = GetTypeDefOrRef (type);
this.context = declaring_type;
if (!declaring_type.IsArray)
this.context = declaring_type;
var member = ReadMemberReferenceSignature (signature, declaring_type);
member.Name = name;
@ -2368,8 +2371,12 @@ namespace Mono.Cecil { @@ -2368,8 +2371,12 @@ namespace Mono.Cecil {
public void ReadCustomAttributeSignature (CustomAttribute attribute)
{
var reader = ReadSignature (attribute.signature);
if (!reader.CanReadMore ())
return;
if (reader.ReadUInt16 () != 0x0001)
throw new InvalidOperationException ();
throw new InvalidOperationException ();
var constructor = attribute.Constructor;
if (constructor.HasParameters)
@ -2645,9 +2652,10 @@ namespace Mono.Cecil { @@ -2645,9 +2652,10 @@ namespace Mono.Cecil {
GenericParameter GetGenericParameter (GenericParameterType type, uint var)
{
var context = reader.context;
int index = (int) var;
if (context == null)
throw new NotSupportedException ();
return GetUnboundGenericParameter (type, index);
IGenericParameterProvider provider;
@ -2662,14 +2670,20 @@ namespace Mono.Cecil { @@ -2662,14 +2670,20 @@ namespace Mono.Cecil {
throw new NotSupportedException ();
}
int index = (int) var;
if (!context.IsDefinition)
CheckGenericContext (provider, index);
if (index >= provider.GenericParameters.Count)
return GetUnboundGenericParameter (type, index);
return provider.GenericParameters [index];
}
GenericParameter GetUnboundGenericParameter (GenericParameterType type, int index)
{
return new GenericParameter (index, type, reader.module);
}
static void CheckGenericContext (IGenericParameterProvider owner, int index)
{
var owner_parameters = owner.GenericParameters;
@ -2812,7 +2826,7 @@ namespace Mono.Cecil { @@ -2812,7 +2826,7 @@ namespace Mono.Cecil {
method.CallingConvention = (MethodCallingConvention) calling_convention;
var generic_context = method as MethodReference;
if (generic_context != null)
if (generic_context != null && !generic_context.DeclaringType.IsArray)
reader.context = generic_context;
if ((calling_convention & 0x10) != 0) {

2
Mono.Cecil/Mono.Cecil/AssemblyWriter.cs

@ -1458,7 +1458,7 @@ namespace Mono.Cecil { @@ -1458,7 +1458,7 @@ namespace Mono.Cecil {
{
var pinvoke = method.PInvokeInfo;
if (pinvoke == null)
throw new ArgumentException ();
return;
var table = GetTable<ImplMapTable> (Table.ImplMap);
table.AddRow (new ImplMapRow (

4
Mono.Cecil/Mono.Cecil/CustomAttribute.cs

@ -188,7 +188,7 @@ namespace Mono.Cecil { @@ -188,7 +188,7 @@ namespace Mono.Cecil {
if (blob != null)
return blob;
if (!HasImage || signature == 0)
if (!HasImage)
throw new NotSupportedException ();
return Module.Read (ref blob, this, (attribute, reader) => reader.ReadCustomAttributeBlob (attribute.signature));
@ -210,7 +210,7 @@ namespace Mono.Cecil { @@ -210,7 +210,7 @@ namespace Mono.Cecil {
fields.Clear ();
if (properties != null)
properties.Clear ();
resolved = false;
}
return this;

2
Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs

@ -42,7 +42,7 @@ namespace Mono.Cecil { @@ -42,7 +42,7 @@ namespace Mono.Cecil {
public DefaultAssemblyResolver ()
{
cache = new Dictionary<string, AssemblyDefinition> ();
cache = new Dictionary<string, AssemblyDefinition> (StringComparer.Ordinal);
}
public override AssemblyDefinition Resolve (AssemblyNameReference name)

104
Mono.Cecil/Mono.Cecil/GenericParameter.cs

@ -36,7 +36,9 @@ namespace Mono.Cecil { @@ -36,7 +36,9 @@ namespace Mono.Cecil {
public sealed class GenericParameter : TypeReference, ICustomAttributeProvider {
readonly IGenericParameterProvider owner;
internal int position;
internal GenericParameterType type;
internal IGenericParameterProvider owner;
ushort attributes;
Collection<TypeReference> constraints;
@ -48,12 +50,11 @@ namespace Mono.Cecil { @@ -48,12 +50,11 @@ namespace Mono.Cecil {
}
public int Position {
get {
if (owner == null)
return -1;
get { return position; }
}
return owner.GenericParameters.IndexOf (this);
}
public GenericParameterType Type {
get { return type; }
}
public IGenericParameterProvider Owner {
@ -99,15 +100,17 @@ namespace Mono.Cecil { @@ -99,15 +100,17 @@ namespace Mono.Cecil {
public override IMetadataScope Scope {
get {
if (owner.GenericParameterType == GenericParameterType.Method)
return ((MethodReference) owner).DeclaringType.Scope;
if (owner == null)
return null;
return ((TypeReference) owner).Scope;
return owner.GenericParameterType == GenericParameterType.Method
? ((MethodReference) owner).DeclaringType.Scope
: ((TypeReference) owner).Scope;
}
}
public override ModuleDefinition Module {
get { return ((MemberReference) owner).Module; }
get { return module ?? owner.Module; }
}
public override string Name {
@ -115,7 +118,7 @@ namespace Mono.Cecil { @@ -115,7 +118,7 @@ namespace Mono.Cecil {
if (!string.IsNullOrEmpty (base.Name))
return base.Name;
return base.Name = (owner.GenericParameterType == GenericParameterType.Type ? "!" : "!!") + Position;
return base.Name = (type == GenericParameterType.Method ? "!!" : "!") + position;
}
}
@ -185,8 +188,34 @@ namespace Mono.Cecil { @@ -185,8 +188,34 @@ namespace Mono.Cecil {
if (owner == null)
throw new ArgumentNullException ();
this.position = -1;
this.owner = owner;
this.etype = owner.GenericParameterType == GenericParameterType.Type ? ElementType.Var : ElementType.MVar;
this.type = owner.GenericParameterType;
this.etype = ConvertGenericParameterType (this.type);
}
public GenericParameter (int position, GenericParameterType type, ModuleDefinition module)
: base (string.Empty, string.Empty)
{
if (module == null)
throw new ArgumentNullException ();
this.position = position;
this.type = type;
this.etype = ConvertGenericParameterType (type);
this.module = module;
}
static ElementType ConvertGenericParameterType (GenericParameterType type)
{
switch (type) {
case GenericParameterType.Type:
return ElementType.Var;
case GenericParameterType.Method:
return ElementType.MVar;
}
throw new ArgumentOutOfRangeException ();
}
public override TypeDefinition Resolve ()
@ -194,4 +223,55 @@ namespace Mono.Cecil { @@ -194,4 +223,55 @@ namespace Mono.Cecil {
return null;
}
}
sealed class GenericParameterCollection : Collection<GenericParameter> {
readonly IGenericParameterProvider owner;
internal GenericParameterCollection (IGenericParameterProvider owner)
{
this.owner = owner;
}
internal GenericParameterCollection (IGenericParameterProvider owner, int capacity)
: base (capacity)
{
this.owner = owner;
}
protected override void OnAdd (GenericParameter item, int index)
{
UpdateGenericParameter (item, index);
}
protected override void OnInsert (GenericParameter item, int index)
{
UpdateGenericParameter (item, index);
for (int i = index; i < size; i++)
items[i].position = i + 1;
}
protected override void OnSet (GenericParameter item, int index)
{
UpdateGenericParameter (item, index);
}
void UpdateGenericParameter (GenericParameter item, int index)
{
item.owner = owner;
item.position = index;
item.type = owner.GenericParameterType;
}
protected override void OnRemove (GenericParameter item, int index)
{
item.owner = null;
item.position = -1;
item.type = GenericParameterType.Type;
for (int i = index + 1; i < size; i++)
items[i].position = i - 1;
}
}
}

4
Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs

@ -44,9 +44,7 @@ namespace Mono.Cecil { @@ -44,9 +44,7 @@ namespace Mono.Cecil {
this ICustomAttributeProvider self,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.HasCustomAttributes (provider))
: false;
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasCustomAttributes (provider));
}
public static Collection<CustomAttribute> GetCustomAttributes (

6
Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs

@ -58,9 +58,7 @@ namespace Mono.Cecil { @@ -58,9 +58,7 @@ namespace Mono.Cecil {
this IGenericParameterProvider self,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.HasGenericParameters (provider))
: false;
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasGenericParameters (provider));
}
public static Collection<GenericParameter> GetGenericParameters (
@ -70,7 +68,7 @@ namespace Mono.Cecil { @@ -70,7 +68,7 @@ namespace Mono.Cecil {
{
return module.HasImage ()
? module.Read (ref collection, self, (provider, reader) => reader.ReadGenericParameters (provider))
: collection = new Collection<GenericParameter> ();
: collection = new GenericParameterCollection (self);
}
}
}

4
Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs

@ -40,9 +40,7 @@ namespace Mono.Cecil { @@ -40,9 +40,7 @@ namespace Mono.Cecil {
this IMarshalInfoProvider self,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.HasMarshalInfo (provider))
: false;
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasMarshalInfo (provider));
}
public static MarshalInfo GetMarshalInfo (

2
Mono.Cecil/Mono.Cecil/Import.cs

@ -351,7 +351,7 @@ namespace Mono.Cecil { @@ -351,7 +351,7 @@ namespace Mono.Cecil {
ImportScope (type.Scope),
type.IsValueType);
MetadataSystem.TryProcessPrimitiveType (reference);
MetadataSystem.TryProcessPrimitiveTypeReference (reference);
if (type.IsNested)
reference.DeclaringType = ImportType (type.DeclaringType, context);

72
Mono.Cecil/Mono.Cecil/MetadataResolver.cs

@ -27,7 +27,6 @@ @@ -27,7 +27,6 @@
//
using System;
using System.Collections.Generic;
using Mono.Collections.Generic;
@ -41,6 +40,12 @@ namespace Mono.Cecil { @@ -41,6 +40,12 @@ namespace Mono.Cecil {
AssemblyDefinition Resolve (string fullName, ReaderParameters parameters);
}
public interface IMetadataResolver {
TypeDefinition Resolve (TypeReference type);
FieldDefinition Resolve (FieldReference field);
MethodDefinition Resolve (MethodReference method);
}
#if !SILVERLIGHT && !CF
[Serializable]
#endif
@ -68,29 +73,46 @@ namespace Mono.Cecil { @@ -68,29 +73,46 @@ namespace Mono.Cecil {
#endif
}
static class MetadataResolver {
public class MetadataResolver : IMetadataResolver {
public static TypeDefinition Resolve (IAssemblyResolver resolver, TypeReference type)
readonly IAssemblyResolver assembly_resolver;
public IAssemblyResolver AssemblyResolver {
get { return assembly_resolver; }
}
public MetadataResolver (IAssemblyResolver assemblyResolver)
{
if (assemblyResolver == null)
throw new ArgumentNullException ("assemblyResolver");
assembly_resolver = assemblyResolver;
}
public virtual TypeDefinition Resolve (TypeReference type)
{
if (type == null)
throw new ArgumentNullException ("type");
type = type.GetElementType ();
var scope = type.Scope;
switch (scope.MetadataScopeType) {
case MetadataScopeType.AssemblyNameReference:
var assembly = resolver.Resolve ((AssemblyNameReference) scope);
var assembly = assembly_resolver.Resolve ((AssemblyNameReference) scope);
if (assembly == null)
return null;
return GetType (resolver, assembly.MainModule, type);
return GetType (assembly.MainModule, type);
case MetadataScopeType.ModuleDefinition:
return GetType (resolver, (ModuleDefinition) scope, type);
return GetType ((ModuleDefinition) scope, type);
case MetadataScopeType.ModuleReference:
var modules = type.Module.Assembly.Modules;
var module_ref = (ModuleReference) scope;
for (int i = 0; i < modules.Count; i++) {
var netmodule = modules [i];
if (netmodule.Name == module_ref.Name)
return GetType (resolver, netmodule, type);
return GetType (netmodule, type);
}
break;
}
@ -98,9 +120,9 @@ namespace Mono.Cecil { @@ -98,9 +120,9 @@ namespace Mono.Cecil {
throw new NotSupportedException ();
}
static TypeDefinition GetType (IAssemblyResolver resolver, ModuleDefinition module, TypeReference reference)
static TypeDefinition GetType (ModuleDefinition module, TypeReference reference)
{
var type = GetType (module, reference);
var type = GetTypeDefinition (module, reference);
if (type != null)
return type;
@ -123,7 +145,7 @@ namespace Mono.Cecil { @@ -123,7 +145,7 @@ namespace Mono.Cecil {
return null;
}
static TypeDefinition GetType (ModuleDefinition module, TypeReference type)
static TypeDefinition GetTypeDefinition (ModuleDefinition module, TypeReference type)
{
if (!type.IsNested)
return module.GetType (type.Namespace, type.Name);
@ -135,19 +157,22 @@ namespace Mono.Cecil { @@ -135,19 +157,22 @@ namespace Mono.Cecil {
return declaring_type.GetNestedType (type.Name);
}
public static FieldDefinition Resolve (IAssemblyResolver resolver, FieldReference field)
public virtual FieldDefinition Resolve (FieldReference field)
{
var type = Resolve (resolver, field.DeclaringType);
if (field == null)
throw new ArgumentNullException ("field");
var type = Resolve (field.DeclaringType);
if (type == null)
return null;
if (!type.HasFields)
return null;
return GetField (resolver, type, field);
return GetField (type, field);
}
static FieldDefinition GetField (IAssemblyResolver resolver, TypeDefinition type, FieldReference reference)
FieldDefinition GetField (TypeDefinition type, FieldReference reference)
{
while (type != null) {
var field = GetField (type.Fields, reference);
@ -157,13 +182,13 @@ namespace Mono.Cecil { @@ -157,13 +182,13 @@ namespace Mono.Cecil {
if (type.BaseType == null)
return null;
type = Resolve (resolver, type.BaseType);
type = Resolve (type.BaseType);
}
return null;
}
static FieldDefinition GetField (IList<FieldDefinition> fields, FieldReference reference)
static FieldDefinition GetField (Collection<FieldDefinition> fields, FieldReference reference)
{
for (int i = 0; i < fields.Count; i++) {
var field = fields [i];
@ -180,9 +205,12 @@ namespace Mono.Cecil { @@ -180,9 +205,12 @@ namespace Mono.Cecil {
return null;
}
public static MethodDefinition Resolve (IAssemblyResolver resolver, MethodReference method)
public virtual MethodDefinition Resolve (MethodReference method)
{
var type = Resolve (resolver, method.DeclaringType);
if (method == null)
throw new ArgumentNullException ("method");
var type = Resolve (method.DeclaringType);
if (type == null)
return null;
@ -191,10 +219,10 @@ namespace Mono.Cecil { @@ -191,10 +219,10 @@ namespace Mono.Cecil {
if (!type.HasMethods)
return null;
return GetMethod (resolver, type, method);
return GetMethod (type, method);
}
static MethodDefinition GetMethod (IAssemblyResolver resolver, TypeDefinition type, MethodReference reference)
MethodDefinition GetMethod (TypeDefinition type, MethodReference reference)
{
while (type != null) {
var method = GetMethod (type.Methods, reference);
@ -204,13 +232,13 @@ namespace Mono.Cecil { @@ -204,13 +232,13 @@ namespace Mono.Cecil {
if (type.BaseType == null)
return null;
type = Resolve (resolver, type.BaseType);
type = Resolve (type.BaseType);
}
return null;
}
public static MethodDefinition GetMethod (IList<MethodDefinition> methods, MethodReference reference)
public static MethodDefinition GetMethod (Collection<MethodDefinition> methods, MethodReference reference)
{
for (int i = 0; i < methods.Count; i++) {
var method = methods [i];

43
Mono.Cecil/Mono.Cecil/MetadataSystem.cs

@ -78,7 +78,7 @@ namespace Mono.Cecil { @@ -78,7 +78,7 @@ namespace Mono.Cecil {
static void InitializePrimitives ()
{
primitive_value_types = new Dictionary<string, Row<ElementType, bool>> (18) {
primitive_value_types = new Dictionary<string, Row<ElementType, bool>> (18, StringComparer.Ordinal) {
{ "Void", new Row<ElementType, bool> (ElementType.Void, false) },
{ "Boolean", new Row<ElementType, bool> (ElementType.Boolean, true) },
{ "Char", new Row<ElementType, bool> (ElementType.Char, true) },
@ -100,30 +100,47 @@ namespace Mono.Cecil { @@ -100,30 +100,47 @@ namespace Mono.Cecil {
};
}
public static void TryProcessPrimitiveType (TypeReference type)
public static void TryProcessPrimitiveTypeReference (TypeReference type)
{
var scope = type.scope;
if (scope == null)
if (scope == null || scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference || scope.Name != "mscorlib")
return;
if (scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference)
Row<ElementType, bool> primitive_data;
if (!TryGetPrimitiveData (type, out primitive_data))
return;
if (scope.Name != "mscorlib")
return;
type.etype = primitive_data.Col1;
type.IsValueType = primitive_data.Col2;
}
public static bool TryGetPrimitiveElementType (TypeDefinition type, out ElementType etype)
{
etype = ElementType.None;
if (!type.HasImage || !type.Module.IsCorlib ())
return false;
Row<ElementType, bool> primitive_data;
if (TryGetPrimitiveData (type, out primitive_data) && primitive_data.Col1.IsPrimitive ()) {
etype = primitive_data.Col1;
return true;
}
return false;
}
static bool TryGetPrimitiveData (TypeReference type, out Row<ElementType, bool> primitive_data)
{
primitive_data = new Row<ElementType, bool> ();
if (type.Namespace != "System")
return;
return false;
if (primitive_value_types == null)
InitializePrimitives ();
Row<ElementType, bool> primitive_data;
if (!primitive_value_types.TryGetValue (type.Name, out primitive_data))
return;
type.etype = primitive_data.Col1;
type.IsValueType = primitive_data.Col2;
return primitive_value_types.TryGetValue (type.Name, out primitive_data);
}
public void Clear ()

2
Mono.Cecil/Mono.Cecil/MethodDefinition.cs

@ -145,7 +145,7 @@ namespace Mono.Cecil { @@ -145,7 +145,7 @@ namespace Mono.Cecil {
return body = new MethodBody (this);
}
set {
set {
// we reset Body to null in ILSpy to save memory; so we need that operation to be thread-safe
lock (Module.SyncRoot) {
body = value;

1
Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs

@ -49,6 +49,5 @@ namespace Mono.Cecil { @@ -49,6 +49,5 @@ 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
MaxMethodImplVal = 0xffff // Range check value
}
}

2
Mono.Cecil/Mono.Cecil/MethodReference.cs

@ -99,7 +99,7 @@ namespace Mono.Cecil { @@ -99,7 +99,7 @@ namespace Mono.Cecil {
if (generic_parameters != null)
return generic_parameters;
return generic_parameters = new Collection<GenericParameter> ();
return generic_parameters = new GenericParameterCollection (this);
}
}

15
Mono.Cecil/Mono.Cecil/MethodReturnType.cs

@ -26,6 +26,8 @@ @@ -26,6 +26,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Threading;
using Mono.Collections.Generic;
namespace Mono.Cecil {
@ -46,8 +48,12 @@ namespace Mono.Cecil { @@ -46,8 +48,12 @@ namespace Mono.Cecil {
}
internal ParameterDefinition Parameter {
get { return parameter ?? (parameter = new ParameterDefinition (return_type)); }
set { parameter = value; }
get {
if (parameter == null)
Interlocked.CompareExchange (ref parameter, new ParameterDefinition (return_type, method), null);
return parameter;
}
}
public MetadataToken MetadataToken {
@ -55,6 +61,11 @@ namespace Mono.Cecil { @@ -55,6 +61,11 @@ namespace Mono.Cecil {
set { Parameter.MetadataToken = value; }
}
public ParameterAttributes Attributes {
get { return Parameter.Attributes; }
set { Parameter.Attributes = value; }
}
public bool HasCustomAttributes {
get { return parameter != null && parameter.HasCustomAttributes; }
}

72
Mono.Cecil/Mono.Cecil/ModuleDefinition.cs

@ -47,6 +47,7 @@ namespace Mono.Cecil { @@ -47,6 +47,7 @@ namespace Mono.Cecil {
ReadingMode reading_mode;
IAssemblyResolver assembly_resolver;
IMetadataResolver metadata_resolver;
Stream symbol_stream;
ISymbolReaderProvider symbol_reader_provider;
bool read_symbols;
@ -61,6 +62,11 @@ namespace Mono.Cecil { @@ -61,6 +62,11 @@ namespace Mono.Cecil {
set { assembly_resolver = value; }
}
public IMetadataResolver MetadataResolver {
get { return metadata_resolver; }
set { metadata_resolver = value; }
}
public Stream SymbolStream {
get { return symbol_stream; }
set { symbol_stream = value; }
@ -95,6 +101,7 @@ namespace Mono.Cecil { @@ -95,6 +101,7 @@ namespace Mono.Cecil {
TargetRuntime runtime;
TargetArchitecture architecture;
IAssemblyResolver assembly_resolver;
IMetadataResolver metadata_resolver;
public ModuleKind Kind {
get { return kind; }
@ -116,6 +123,11 @@ namespace Mono.Cecil { @@ -116,6 +123,11 @@ namespace Mono.Cecil {
set { assembly_resolver = value; }
}
public IMetadataResolver MetadataResolver {
get { return metadata_resolver; }
set { metadata_resolver = value; }
}
public ModuleParameters ()
{
this.kind = ModuleKind.Dll;
@ -186,6 +198,7 @@ namespace Mono.Cecil { @@ -186,6 +198,7 @@ namespace Mono.Cecil {
internal ISymbolReader SymbolReader;
internal IAssemblyResolver assembly_resolver;
internal IMetadataResolver metadata_resolver;
internal TypeSystem type_system;
readonly MetadataReader reader;
@ -263,7 +276,7 @@ namespace Mono.Cecil { @@ -263,7 +276,7 @@ namespace Mono.Cecil {
internal MetadataImporter MetadataImporter {
get {
if (importer == null)
Interlocked.CompareExchange(ref importer, new MetadataImporter(this), null);
Interlocked.CompareExchange (ref importer, new MetadataImporter (this), null);
return importer;
}
}
@ -273,10 +286,19 @@ namespace Mono.Cecil { @@ -273,10 +286,19 @@ namespace Mono.Cecil {
get { return assembly_resolver; }
}
public IMetadataResolver MetadataResolver {
get {
if (metadata_resolver == null)
Interlocked.CompareExchange (ref metadata_resolver, new MetadataResolver (assembly_resolver), null);
return metadata_resolver;
}
}
public TypeSystem TypeSystem {
get {
if (type_system == null)
Interlocked.CompareExchange(ref type_system, TypeSystem.CreateTypeSystem (this), null);
Interlocked.CompareExchange (ref type_system, TypeSystem.CreateTypeSystem (this), null);
return type_system;
}
}
@ -488,6 +510,13 @@ namespace Mono.Cecil { @@ -488,6 +510,13 @@ namespace Mono.Cecil {
return Read (this, (_, reader) => reader.GetMemberReferences ());
}
public TypeReference GetType (string fullName, bool runtimeName)
{
return runtimeName
? TypeParser.ParseType (this, fullName)
: GetType (fullName);
}
public TypeDefinition GetType (string fullName)
{
CheckFullName (fullName);
@ -555,17 +584,17 @@ namespace Mono.Cecil { @@ -555,17 +584,17 @@ namespace Mono.Cecil {
internal FieldDefinition Resolve (FieldReference field)
{
return MetadataResolver.Resolve (AssemblyResolver, field);
return MetadataResolver.Resolve (field);
}
internal MethodDefinition Resolve (MethodReference method)
{
return MetadataResolver.Resolve (AssemblyResolver, method);
return MetadataResolver.Resolve (method);
}
internal TypeDefinition Resolve (TypeReference type)
{
return MetadataResolver.Resolve (AssemblyResolver, type);
return MetadataResolver.Resolve (type);
}
#if !READ_ONLY
@ -790,7 +819,7 @@ namespace Mono.Cecil { @@ -790,7 +819,7 @@ namespace Mono.Cecil {
{
return Read (token, (t, reader) => reader.LookupToken (t));
}
readonly object module_lock = new object();
internal object SyncRoot {
@ -811,13 +840,13 @@ namespace Mono.Cecil { @@ -811,13 +840,13 @@ namespace Mono.Cecil {
return ret;
}
}
internal TRet Read<TItem, TRet> (ref TRet variable, TItem item, Func<TItem, MetadataReader, TRet> read) where TRet : class
{
lock (module_lock) {
if (variable != null)
return variable;
var position = reader.position;
var context = reader.context;
@ -866,10 +895,13 @@ namespace Mono.Cecil { @@ -866,10 +895,13 @@ namespace Mono.Cecil {
if (parameters.AssemblyResolver != null)
module.assembly_resolver = parameters.AssemblyResolver;
if (parameters.MetadataResolver != null)
module.metadata_resolver = parameters.MetadataResolver;
if (parameters.Kind != ModuleKind.NetModule) {
var assembly = new AssemblyDefinition ();
module.assembly = assembly;
module.assembly.Name = new AssemblyNameDefinition (name, new Version (0, 0));
module.assembly.Name = CreateAssemblyName (name);
assembly.main_module = module;
}
@ -878,6 +910,14 @@ namespace Mono.Cecil { @@ -878,6 +910,14 @@ namespace Mono.Cecil {
return module;
}
static AssemblyNameDefinition CreateAssemblyName (string name)
{
if (name.EndsWith (".dll") || name.EndsWith (".exe"))
name = name.Substring (0, name.Length - 4);
return new AssemblyNameDefinition (name, new Version (0, 0, 0, 0));
}
#endif
public void ReadSymbols ()
@ -886,10 +926,10 @@ namespace Mono.Cecil { @@ -886,10 +926,10 @@ namespace Mono.Cecil {
throw new InvalidOperationException ();
var provider = SymbolProvider.GetPlatformReaderProvider ();
if (provider == null)
throw new InvalidOperationException ();
SymbolReader = provider.GetSymbolReader (this, fq_name);
ProcessDebugHeader ();
ReadSymbols (provider.GetSymbolReader (this, fq_name));
}
public void ReadSymbols (ISymbolReader reader)
@ -993,6 +1033,14 @@ namespace Mono.Cecil { @@ -993,6 +1033,14 @@ namespace Mono.Cecil {
return self != null && self.HasImage;
}
public static bool IsCorlib (this ModuleDefinition module)
{
if (module.Assembly == null)
return false;
return module.Assembly.Name.Name == "mscorlib";
}
public static string GetFullyQualifiedName (this Stream self)
{
#if !SILVERLIGHT

6
Mono.Cecil/Mono.Cecil/ParameterDefinition.cs

@ -138,6 +138,12 @@ namespace Mono.Cecil { @@ -138,6 +138,12 @@ namespace Mono.Cecil {
#endregion
internal ParameterDefinition (TypeReference parameterType, IMethodSignature method)
: this (string.Empty, ParameterAttributes.None, parameterType)
{
this.method = method;
}
public ParameterDefinition (TypeReference parameterType)
: this (string.Empty, ParameterAttributes.None, parameterType)
{

17
Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs

@ -93,6 +93,7 @@ namespace Mono.Cecil { @@ -93,6 +93,7 @@ namespace Mono.Cecil {
public sealed class SecurityDeclaration {
readonly internal uint signature;
byte [] blob;
readonly ModuleDefinition module;
internal bool resolved;
@ -137,12 +138,22 @@ namespace Mono.Cecil { @@ -137,12 +138,22 @@ namespace Mono.Cecil {
this.resolved = true;
}
public SecurityDeclaration (SecurityAction action, byte [] blob)
{
this.action = action;
this.resolved = false;
this.blob = blob;
}
public byte [] GetBlob ()
{
if (blob != null)
return blob;
if (!HasImage || signature == 0)
throw new NotSupportedException ();
return module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationBlob (declaration.signature));
return blob = module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationBlob (declaration.signature));
}
void Resolve ()
@ -165,9 +176,7 @@ namespace Mono.Cecil { @@ -165,9 +176,7 @@ namespace Mono.Cecil {
this ISecurityDeclarationProvider self,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.HasSecurityDeclarations (provider))
: false;
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasSecurityDeclarations (provider));
}
public static Collection<SecurityDeclaration> GetSecurityDeclarations (

18
Mono.Cecil/Mono.Cecil/TypeDefinition.cs

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
using System;
using Mono.Cecil.Metadata;
using Mono.Collections.Generic;
namespace Mono.Cecil {
@ -433,6 +434,23 @@ namespace Mono.Cecil { @@ -433,6 +434,23 @@ namespace Mono.Cecil {
}
}
public override bool IsPrimitive {
get {
ElementType primitive_etype;
return MetadataSystem.TryGetPrimitiveElementType (this, out primitive_etype);
}
}
public override MetadataType MetadataType {
get {
ElementType primitive_etype;
if (MetadataSystem.TryGetPrimitiveElementType (this, out primitive_etype))
return (MetadataType) primitive_etype;
return base.MetadataType;
}
}
public override bool IsDefinition {
get { return true; }
}

2
Mono.Cecil/Mono.Cecil/TypeParser.cs

@ -356,7 +356,7 @@ namespace Mono.Cecil { @@ -356,7 +356,7 @@ namespace Mono.Cecil {
SplitFullName (type_info.type_fullname, out @namespace, out name);
var type = new TypeReference (@namespace, name, module, scope);
MetadataSystem.TryProcessPrimitiveType (type);
MetadataSystem.TryProcessPrimitiveTypeReference (type);
AdjustGenericParameters (type);

49
Mono.Cecil/Mono.Cecil/TypeReference.cs

@ -135,7 +135,7 @@ namespace Mono.Cecil { @@ -135,7 +135,7 @@ namespace Mono.Cecil {
if (generic_parameters != null)
return generic_parameters;
return generic_parameters = new Collection<GenericParameter> ();
return generic_parameters = new GenericParameterCollection (this);
}
}
@ -216,28 +216,8 @@ namespace Mono.Cecil { @@ -216,28 +216,8 @@ namespace Mono.Cecil {
get { return false; }
}
public bool IsPrimitive {
get {
switch (etype) {
case ElementType.Boolean:
case ElementType.Char:
case ElementType.I:
case ElementType.U:
case ElementType.I1:
case ElementType.U1:
case ElementType.I2:
case ElementType.U2:
case ElementType.I4:
case ElementType.U4:
case ElementType.I8:
case ElementType.U8:
case ElementType.R4:
case ElementType.R8:
return true;
default:
return false;
}
}
public virtual bool IsPrimitive {
get { return etype.IsPrimitive (); }
}
public virtual MetadataType MetadataType {
@ -288,6 +268,29 @@ namespace Mono.Cecil { @@ -288,6 +268,29 @@ namespace Mono.Cecil {
static partial class Mixin {
public static bool IsPrimitive (this ElementType self)
{
switch (self) {
case ElementType.Boolean:
case ElementType.Char:
case ElementType.I:
case ElementType.U:
case ElementType.I1:
case ElementType.U1:
case ElementType.I2:
case ElementType.U2:
case ElementType.I4:
case ElementType.U4:
case ElementType.I8:
case ElementType.U8:
case ElementType.R4:
case ElementType.R8:
return true;
default:
return false;
}
}
public static bool IsTypeOf (this TypeReference self, string @namespace, string name)
{
return self.Name == name

10
Mono.Cecil/Mono.Cecil/TypeSystem.cs

@ -158,20 +158,12 @@ namespace Mono.Cecil { @@ -158,20 +158,12 @@ namespace Mono.Cecil {
internal static TypeSystem CreateTypeSystem (ModuleDefinition module)
{
if (IsCorlib (module))
if (module.IsCorlib ())
return new CorlibTypeSystem (module);
return new CommonTypeSystem (module);
}
static bool IsCorlib (ModuleDefinition module)
{
if (module.Assembly == null)
return false;
return module.Assembly.Name.Name == "mscorlib";
}
internal abstract TypeReference LookupType (string @namespace, string name);
TypeReference LookupSystemType (ref TypeReference typeRef, string name, ElementType element_type)

19
Mono.Cecil/Test/Mono.Cecil.Tests.csproj

@ -75,17 +75,17 @@ @@ -75,17 +75,17 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>libs\nunit-2.4.8\nunit.core.dll</HintPath>
<HintPath>libs\nunit-2.5.10\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core.interfaces, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>libs\nunit-2.4.8\nunit.core.interfaces.dll</HintPath>
<HintPath>libs\nunit-2.5.10\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>libs\nunit-2.4.8\nunit.framework.dll</HintPath>
<HintPath>libs\nunit-2.5.10\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
@ -141,9 +141,14 @@ @@ -141,9 +141,14 @@
<ItemGroup>
<Content Include="Resources\assemblies\boxedoptarg.dll" />
<Content Include="Resources\assemblies\catch.exe" />
<Content Include="Resources\assemblies\cppcli.dll" />
<Content Include="Resources\assemblies\cscgpbug.dll" />
<Content Include="Resources\assemblies\decsec-att.dll" />
<Content Include="Resources\assemblies\decsec-xml.dll" />
<Content Include="Resources\assemblies\decsec1-xml.dll" />
<Content Include="Resources\assemblies\empty-decsec-att.dll" />
<Content Include="Resources\assemblies\fptr.exe" />
<Content Include="Resources\assemblies\gifaceref.exe" />
<Content Include="Resources\assemblies\hello.anycpu.exe" />
<Content Include="Resources\assemblies\hello.exe" />
<Content Include="Resources\assemblies\hello.ia64.exe" />
@ -154,7 +159,9 @@ @@ -154,7 +159,9 @@
<Content Include="Resources\assemblies\iterator.exe" />
<Content Include="Resources\assemblies\libhello.dll" />
<Content Include="Resources\assemblies\libres.dll" />
<Content Include="Resources\assemblies\marshal.dll" />
<Content Include="Resources\assemblies\mma.exe" />
<Content Include="Resources\assemblies\noblob.dll" />
<Content Include="Resources\assemblies\pinvoke.exe" />
<Content Include="Resources\assemblies\switch.exe" />
<Content Include="Resources\assemblies\text_file.txt" />

8
Mono.Cecil/Test/Mono.Cecil.Tests/Addin.cs

@ -173,15 +173,17 @@ namespace Mono.Cecil.Tests { @@ -173,15 +173,17 @@ namespace Mono.Cecil.Tests {
return ModuleDefinition.ReadModule (rt_module, reader_parameters);
}
public override void RunTestMethod (TestCaseResult testResult)
public override TestResult RunTest ()
{
var result = new TestResult (TestName);
var module = GetModule ();
if (module == null)
return;
return result;
Reflect.InvokeMethod (Method, Fixture, new object [] { module });
testResult.Success ();
result.Success ();
return result;
}
}

2
Mono.Cecil/Test/Mono.Cecil.Tests/AssemblyInfo.cs

@ -4,7 +4,7 @@ using System.Runtime.InteropServices; @@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Tests")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2010 Jb Evain")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")]
[assembly: ComVisible (false)]

10
Mono.Cecil/Test/Mono.Cecil.Tests/AssemblyTests.cs

@ -21,5 +21,15 @@ namespace Mono.Cecil.Tests { @@ -21,5 +21,15 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (new Version (0, 0, 0, 0), name.Version);
Assert.AreEqual (AssemblyHashAlgorithm.SHA1, name.HashAlgorithm);
}
[Test]
public void ParseLowerCaseNameParts()
{
var name = AssemblyNameReference.Parse ("Foo, version=2.0.0.0, culture=fr-FR");
Assert.AreEqual ("Foo", name.Name);
Assert.AreEqual (2, name.Version.Major);
Assert.AreEqual (0, name.Version.Minor);
Assert.AreEqual ("fr-FR", name.Culture);
}
}
}

8
Mono.Cecil/Test/Mono.Cecil.Tests/CustomAttributesTests.cs

@ -342,6 +342,14 @@ namespace Mono.Cecil.Tests { @@ -342,6 +342,14 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("System.Collections.Generic.Dictionary`2<System.String,OpenGeneric`2<Machin,System.Int32>[,]>", type.FullName);
}
[TestIL ("types.il")]
public void EmptyBlob (ModuleDefinition module)
{
var attribute = module.GetType ("CustomAttribute");
Assert.AreEqual (1, attribute.CustomAttributes.Count);
Assert.AreEqual (0, attribute.CustomAttributes [0].ConstructorArguments.Count);
}
[Test]
public void DefineCustomAttributeFromBlob ()
{

8
Mono.Cecil/Test/Mono.Cecil.Tests/FieldTests.cs

@ -245,25 +245,25 @@ namespace Mono.Cecil.Tests { @@ -245,25 +245,25 @@ namespace Mono.Cecil.Tests {
var field = fields.GetField ("int32_int16");
Assert.AreEqual ("System.Int32", field.FieldType.FullName);
Assert.IsTrue (field.HasConstant);
Assert.IsInstanceOfType (typeof (short), field.Constant);
Assert.IsInstanceOf (typeof (short), field.Constant);
Assert.AreEqual ((short) 1, field.Constant);
field = fields.GetField ("int16_int32");
Assert.AreEqual ("System.Int16", field.FieldType.FullName);
Assert.IsTrue (field.HasConstant);
Assert.IsInstanceOfType (typeof (int), field.Constant);
Assert.IsInstanceOf (typeof (int), field.Constant);
Assert.AreEqual (1, field.Constant);
field = fields.GetField ("char_int16");
Assert.AreEqual ("System.Char", field.FieldType.FullName);
Assert.IsTrue (field.HasConstant);
Assert.IsInstanceOfType (typeof (short), field.Constant);
Assert.IsInstanceOf (typeof (short), field.Constant);
Assert.AreEqual ((short) 1, field.Constant);
field = fields.GetField ("int16_char");
Assert.AreEqual ("System.Int16", field.FieldType.FullName);
Assert.IsTrue (field.HasConstant);
Assert.IsInstanceOfType (typeof (char), field.Constant);
Assert.IsInstanceOf (typeof (char), field.Constant);
Assert.AreEqual ('s', field.Constant);
}

6
Mono.Cecil/Test/Mono.Cecil.Tests/Formatter.cs

@ -115,6 +115,12 @@ namespace Mono.Cecil.Tests { @@ -115,6 +115,12 @@ namespace Mono.Cecil.Tests {
return;
}
var parameter = operand as ParameterDefinition;
if (parameter != null) {
writer.Write (ToInvariantCultureString (parameter.Sequence));
return;
}
s = ToInvariantCultureString (operand);
writer.Write (s);
}

40
Mono.Cecil/Test/Mono.Cecil.Tests/ImageReadTests.cs

@ -88,40 +88,32 @@ namespace Mono.Cecil.Tests { @@ -88,40 +88,32 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (1, heap [Table.AssemblyRef].Length);
}
[Test]
public void ReadX64Image ()
[TestModule ("hello.x64.exe")]
public void X64Module (ModuleDefinition module)
{
var image = GetResourceImage ("hello.x64.exe");
Assert.AreEqual (TargetArchitecture.AMD64, image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes);
Assert.AreEqual (TargetArchitecture.AMD64, module.Image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes);
}
[Test]
public void ReadIA64Image ()
[TestModule ("hello.ia64.exe")]
public void IA64Module (ModuleDefinition module)
{
var image = GetResourceImage ("hello.ia64.exe");
Assert.AreEqual (TargetArchitecture.IA64, image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes);
Assert.AreEqual (TargetArchitecture.IA64, module.Image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes);
}
[Test]
public void ReadX86Image ()
[TestModule ("hello.x86.exe")]
public void X86Module (ModuleDefinition module)
{
var image = GetResourceImage ("hello.x86.exe");
Assert.AreEqual (TargetArchitecture.I386, image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly | ModuleAttributes.Required32Bit, image.Attributes);
Assert.AreEqual (TargetArchitecture.I386, module.Image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly | ModuleAttributes.Required32Bit, module.Image.Attributes);
}
[Test]
public void ReadAnyCpuImage ()
[TestModule ("hello.anycpu.exe")]
public void AnyCpuModule (ModuleDefinition module)
{
var image = GetResourceImage ("hello.anycpu.exe");
Assert.AreEqual (TargetArchitecture.I386, image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes);
Assert.AreEqual (TargetArchitecture.I386, module.Image.Architecture);
Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes);
}
}
}

49
Mono.Cecil/Test/Mono.Cecil.Tests/MethodBodyTests.cs

@ -201,9 +201,58 @@ namespace Mono.Cecil.Tests { @@ -201,9 +201,58 @@ namespace Mono.Cecil.Tests {
IL_0005: ret
", method);
Assert.AreEqual (method.Body.ThisParameter.ParameterType, type);
Assert.AreEqual (method.Body.ThisParameter, method.Body.Instructions [0].Operand);
}
[Test]
public void ThisParameterStaticMethod ()
{
var static_method = typeof (ModuleDefinition).ToDefinition ().Methods.Where (m => m.IsStatic).First ();
Assert.IsNull (static_method.Body.ThisParameter);
}
[Test]
public void ThisParameterPrimitive ()
{
var int32 = typeof (int).ToDefinition ();
var int_to_string = int32.Methods.Where (m => m.Name == "ToString" && m.Parameters.Count == 0).First();
Assert.IsNotNull (int_to_string);
var this_parameter_type = int_to_string.Body.ThisParameter.ParameterType;
Assert.IsTrue (this_parameter_type.IsPointer);
var element_type = ((PointerType) this_parameter_type).ElementType;
Assert.AreEqual (int32, element_type);
}
[Test]
public void ThisParameterValueType ()
{
var token = typeof (MetadataToken).ToDefinition ();
var token_to_string = token.Methods.Where (m => m.Name == "ToString" && m.Parameters.Count == 0).First ();
Assert.IsNotNull (token_to_string);
var this_parameter_type = token_to_string.Body.ThisParameter.ParameterType;
Assert.IsTrue (this_parameter_type.IsPointer);
var element_type = ((PointerType) this_parameter_type).ElementType;
Assert.AreEqual (token, element_type);
}
[Test]
public void ThisParameterObject ()
{
var module = typeof (MethodBodyTests).ToDefinition ().Module;
var @object = module.TypeSystem.Object.Resolve ();
var method = @object.Methods.Where (m => m.HasBody).First ();
var type = method.Body.ThisParameter.ParameterType;
Assert.IsFalse (type.IsValueType);
Assert.IsFalse (type.IsPrimitive);
Assert.IsFalse (type.IsPointer);
}
[TestIL ("hello.il")]
public void FilterMaxStack (ModuleDefinition module)
{

8
Mono.Cecil/Test/Mono.Cecil.Tests/MethodTests.cs

@ -189,5 +189,13 @@ namespace Mono.Cecil.Tests { @@ -189,5 +189,13 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("System.Collections.Generic.List`1<TBeta>", new_list_beta.DeclaringType.FullName);
Assert.AreEqual ("System.Collections.Generic.List`1<TCharlie>", new_list_charlie.DeclaringType.FullName);
}
[Test]
public void ReturnParameterMethod ()
{
var method = typeof (MethodTests).ToDefinition ().GetMethod ("ReturnParameterMethod");
Assert.IsNotNull (method);
Assert.AreEqual (method, method.MethodReturnType.Parameter.Method);
}
}
}

10
Mono.Cecil/Test/Mono.Cecil.Tests/ModuleTests.cs

@ -12,6 +12,16 @@ namespace Mono.Cecil.Tests { @@ -12,6 +12,16 @@ namespace Mono.Cecil.Tests {
[TestFixture]
public class ModuleTests : BaseTestFixture {
[Test]
public void CreateModuleEscapesAssemblyName ()
{
var module = ModuleDefinition.CreateModule ("Test.dll", ModuleKind.Dll);
Assert.AreEqual ("Test", module.Assembly.Name.Name);
module = ModuleDefinition.CreateModule ("Test.exe", ModuleKind.Console);
Assert.AreEqual ("Test", module.Assembly.Name.Name);
}
[TestModule ("hello.exe")]
public void SingleModule (ModuleDefinition module)
{

34
Mono.Cecil/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
@ -88,6 +89,39 @@ namespace Mono.Cecil.Tests { @@ -88,6 +89,39 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (permission_set, argument.Value);
}
[Test]
public void DefineSecurityDeclarationByBlob ()
{
var file = Path.Combine(Path.GetTempPath(), "SecDecBlob.dll");
var module = ModuleDefinition.CreateModule ("SecDecBlob.dll", new ModuleParameters { Kind = ModuleKind.Dll, Runtime = TargetRuntime.Net_2_0 });
const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe"
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permis"
+ "sions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture"
+ "=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFla"
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
var declaration = new SecurityDeclaration (SecurityAction.Deny, Encoding.Unicode.GetBytes (permission_set));
module.Assembly.SecurityDeclarations.Add (declaration);
module.Write (file);
module = ModuleDefinition.ReadModule (file);
declaration = module.Assembly.SecurityDeclarations [0];
Assert.AreEqual (SecurityAction.Deny, declaration.Action);
Assert.AreEqual (1, declaration.SecurityAttributes.Count);
var attribute = declaration.SecurityAttributes [0];
Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName);
Assert.AreEqual (1, attribute.Properties.Count);
var named_argument = attribute.Properties [0];
Assert.AreEqual ("XML", named_argument.Name);
var argument = named_argument.Argument;
Assert.AreEqual ("System.String", argument.Type.FullName);
Assert.AreEqual (permission_set, argument.Value);
}
[TestModule ("empty-decsec-att.dll")]
public void SecurityDeclarationWithoutAttributes (ModuleDefinition module)
{

34
Mono.Cecil/Test/Mono.Cecil.Tests/TypeParserTests.cs

@ -24,7 +24,7 @@ namespace Mono.Cecil.Tests { @@ -24,7 +24,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("String", type.Name);
Assert.AreEqual (MetadataType.String, type.MetadataType);
Assert.IsFalse (type.IsValueType);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
}
[Test]
@ -43,7 +43,7 @@ namespace Mono.Cecil.Tests { @@ -43,7 +43,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("Int32", type.Name);
Assert.AreEqual (MetadataType.Int32, type.MetadataType);
Assert.IsTrue (type.IsValueType);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
}
[Test]
@ -59,7 +59,7 @@ namespace Mono.Cecil.Tests { @@ -59,7 +59,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("Mono.Cecil.Tests", type.Namespace);
Assert.AreEqual ("TypeParserTests", type.Name);
Assert.IsInstanceOfType (typeof (TypeDefinition), type);
Assert.IsInstanceOf (typeof (TypeDefinition), type);
}
[Test]
@ -72,7 +72,7 @@ namespace Mono.Cecil.Tests { @@ -72,7 +72,7 @@ namespace Mono.Cecil.Tests {
var type = TypeParser.ParseType (module, fullname);
Assert.IsInstanceOfType (typeof (ByReferenceType), type);
Assert.IsInstanceOf (typeof (ByReferenceType), type);
type = ((ByReferenceType) type).ElementType;
@ -81,7 +81,7 @@ namespace Mono.Cecil.Tests { @@ -81,7 +81,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("System", type.Namespace);
Assert.AreEqual ("String", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
}
[Test]
@ -98,7 +98,7 @@ namespace Mono.Cecil.Tests { @@ -98,7 +98,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("Mono.Cecil", type.Namespace);
Assert.AreEqual ("TypeDefinition", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
}
[Test]
@ -115,7 +115,7 @@ namespace Mono.Cecil.Tests { @@ -115,7 +115,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("System.Collections.Generic", type.Namespace);
Assert.AreEqual ("Dictionary`2", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
Assert.AreEqual (2, type.GenericParameters.Count);
}
@ -156,7 +156,7 @@ namespace Mono.Cecil.Tests { @@ -156,7 +156,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("", type.Namespace);
Assert.AreEqual ("Baz`1", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
Assert.AreEqual (1, type.GenericParameters.Count);
type = type.DeclaringType;
@ -166,7 +166,7 @@ namespace Mono.Cecil.Tests { @@ -166,7 +166,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("", type.Namespace);
Assert.AreEqual ("Bar`1", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
Assert.AreEqual (1, type.GenericParameters.Count);
type = type.DeclaringType;
@ -176,7 +176,7 @@ namespace Mono.Cecil.Tests { @@ -176,7 +176,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("Bingo", type.Namespace);
Assert.AreEqual ("Foo`1", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
Assert.AreEqual (1, type.GenericParameters.Count);
}
@ -203,7 +203,7 @@ namespace Mono.Cecil.Tests { @@ -203,7 +203,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("Bingo", type.Namespace);
Assert.AreEqual ("Gazonk", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
}
[Test]
@ -227,7 +227,7 @@ namespace Mono.Cecil.Tests { @@ -227,7 +227,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("Bingo", type.Namespace);
Assert.AreEqual ("Gazonk", type.Name);
Assert.IsInstanceOfType (typeof (TypeReference), type);
Assert.IsInstanceOf (typeof (TypeReference), type);
}
[Test]
@ -290,7 +290,7 @@ namespace Mono.Cecil.Tests { @@ -290,7 +290,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (2, type.GenericParameters.Count);
var argument = instance.GenericArguments [0];
Assert.IsInstanceOfType (typeof (TypeDefinition), argument);
Assert.IsInstanceOf (typeof (TypeDefinition), argument);
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("Mono.Cecil.Tests", argument.Namespace);
Assert.AreEqual ("TypeParserTests", argument.Name);
@ -332,13 +332,13 @@ namespace Mono.Cecil.Tests { @@ -332,13 +332,13 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("", argument.Namespace);
Assert.AreEqual ("Bar", argument.Name);
Assert.IsInstanceOfType (typeof (TypeDefinition), argument);
Assert.IsInstanceOf (typeof (TypeDefinition), argument);
argument = instance.GenericArguments [1];
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("", argument.Namespace);
Assert.AreEqual ("Bar", argument.Name);
Assert.IsInstanceOfType (typeof (TypeDefinition), argument);
Assert.IsInstanceOf (typeof (TypeDefinition), argument);
}
[Test]
@ -376,13 +376,13 @@ namespace Mono.Cecil.Tests { @@ -376,13 +376,13 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (2, instance.GenericArguments.Count);
Assert.AreEqual (module, instance.Module);
Assert.AreEqual ("Mono.Cecil.Tests.TypeParserTests/Foo`2", instance.ElementType.FullName);
Assert.IsInstanceOfType (typeof (TypeDefinition), instance.ElementType);
Assert.IsInstanceOf (typeof (TypeDefinition), instance.ElementType);
argument = instance.GenericArguments [0];
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("Mono.Cecil.Tests", argument.Namespace);
Assert.AreEqual ("TypeParserTests", argument.Name);
Assert.IsInstanceOfType (typeof (TypeDefinition), argument);
Assert.IsInstanceOf (typeof (TypeDefinition), argument);
argument = instance.GenericArguments [1];
Assert.AreEqual ("mscorlib", argument.Scope.Name);

42
Mono.Cecil/Test/Mono.Cecil.Tests/TypeTests.cs

@ -167,5 +167,47 @@ namespace Mono.Cecil.Tests { @@ -167,5 +167,47 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (1, instance.GenericArguments.Count);
Assert.AreEqual (1, owner.GenericParameters.Count);
}
[TestModule ("cscgpbug.dll", Verify = false)]
public void UnboundGenericParameter (ModuleDefinition module)
{
var type = module.GetType ("ListViewModel");
var method = type.GetMethod ("<>n__FabricatedMethod1");
var parameter = method.ReturnType as GenericParameter;
Assert.IsNotNull (parameter);
Assert.AreEqual (0, parameter.Position);
Assert.IsNull (parameter.Owner);
}
[TestCSharp ("Generics.cs")]
public void GenericMultidimensionalArray (ModuleDefinition module)
{
var type = module.GetType ("LaMatrix");
var method = type.GetMethod ("At");
var call = method.Body.Instructions.Where (i => i.Operand is MethodReference).First ();
var get = (MethodReference) call.Operand;
Assert.IsNotNull (get);
Assert.AreEqual (0, get.GenericParameters.Count);
Assert.AreEqual (MethodCallingConvention.Default, get.CallingConvention);
Assert.AreEqual (method.GenericParameters [0], get.ReturnType);
}
[Test]
public void CorlibPrimitive ()
{
var module = typeof (TypeTests).ToDefinition ().Module;
var int32 = module.TypeSystem.Int32;
Assert.IsTrue (int32.IsPrimitive);
Assert.AreEqual (MetadataType.Int32, int32.MetadataType);
var int32_def = int32.Resolve ();
Assert.IsTrue (int32_def.IsPrimitive);
Assert.AreEqual (MetadataType.Int32, int32_def.MetadataType);
}
}
}

BIN
Mono.Cecil/Test/Resources/assemblies/cscgpbug.dll

Binary file not shown.

7
Mono.Cecil/Test/Resources/cs/Generics.cs

@ -112,3 +112,10 @@ public class DoubleFuncClass<X> { @@ -112,3 +112,10 @@ public class DoubleFuncClass<X> {
public void Test<T> () { Test<X, int> (); Test<T, X> (); }
public void Test<T, T1> () { Test<T1> (); Test<T1, T> (); }
}
public class LaMatrix {
public static T At<T> (T[,] m, int i, int j)
{
return m [i, j];
}
}

12
Mono.Cecil/Test/Resources/il/types.il

@ -44,3 +44,15 @@ @@ -44,3 +44,15 @@
.field private static literal int16 int16_char = char(0x0073)
.field private static literal int32 int32_nullref = nullref
}
.class public auto ansi CustomAttribute extends [mscorlib]System.Attribute
{
.custom instance void CustomAttribute::.ctor() = ()
.method public hidebysig specialname rtspecialname instance void .ctor()
{
ldarg.0
call instance void [mscorlib]System.Attribute::.ctor()
ret
}
}

BIN
Mono.Cecil/Test/libs/nunit-2.4.8/nunit.core.dll

Binary file not shown.

BIN
Mono.Cecil/Test/libs/nunit-2.4.8/nunit.core.interfaces.dll

Binary file not shown.

BIN
Mono.Cecil/Test/libs/nunit-2.4.8/nunit.framework.dll

Binary file not shown.

BIN
Mono.Cecil/Test/libs/nunit-2.5.10/nunit.core.dll

Binary file not shown.

BIN
Mono.Cecil/Test/libs/nunit-2.5.10/nunit.core.interfaces.dll

Binary file not shown.

BIN
Mono.Cecil/Test/libs/nunit-2.5.10/nunit.framework.dll

Binary file not shown.

2
Mono.Cecil/rocks/Mono.Cecil.Rocks/AssemblyInfo.cs

@ -32,7 +32,7 @@ using System.Runtime.InteropServices; @@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Rocks")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2010 Jb Evain")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]

12
Mono.Cecil/rocks/Test/Mono.Cecil.Rocks.Tests.csproj

@ -51,17 +51,17 @@ @@ -51,17 +51,17 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Test\libs\nunit-2.4.8\nunit.core.dll</HintPath>
<HintPath>..\..\Test\libs\nunit-2.5.10\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core.interfaces, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Test\libs\nunit-2.4.8\nunit.core.interfaces.dll</HintPath>
<HintPath>..\..\Test\libs\nunit-2.5.10\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Test\libs\nunit-2.4.8\nunit.framework.dll</HintPath>
<HintPath>..\..\Test\libs\nunit-2.5.10\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">

18
Mono.Cecil/rocks/Test/Mono.Cecil.Tests/TypeReferenceRocksTests.cs

@ -16,7 +16,7 @@ namespace Mono.Cecil.Tests { @@ -16,7 +16,7 @@ namespace Mono.Cecil.Tests {
var string_array = @string.MakeArrayType ();
Assert.IsInstanceOfType (typeof (ArrayType), string_array);
Assert.IsInstanceOf (typeof (ArrayType), string_array);
Assert.AreEqual (1, string_array.Rank);
}
@ -27,7 +27,7 @@ namespace Mono.Cecil.Tests { @@ -27,7 +27,7 @@ namespace Mono.Cecil.Tests {
var string_array = @string.MakeArrayType (3);
Assert.IsInstanceOfType (typeof (ArrayType), string_array);
Assert.IsInstanceOf (typeof (ArrayType), string_array);
Assert.AreEqual (3, string_array.Rank);
}
@ -38,7 +38,7 @@ namespace Mono.Cecil.Tests { @@ -38,7 +38,7 @@ namespace Mono.Cecil.Tests {
var string_ptr = @string.MakePointerType ();
Assert.IsInstanceOfType (typeof (PointerType), string_ptr);
Assert.IsInstanceOf (typeof (PointerType), string_ptr);
}
[Test]
@ -48,7 +48,7 @@ namespace Mono.Cecil.Tests { @@ -48,7 +48,7 @@ namespace Mono.Cecil.Tests {
var string_byref = @string.MakeByReferenceType ();
Assert.IsInstanceOfType (typeof (ByReferenceType), string_byref);
Assert.IsInstanceOf (typeof (ByReferenceType), string_byref);
}
class OptionalModifier {}
@ -61,7 +61,7 @@ namespace Mono.Cecil.Tests { @@ -61,7 +61,7 @@ namespace Mono.Cecil.Tests {
var string_modopt = @string.MakeOptionalModifierType (modopt);
Assert.IsInstanceOfType (typeof (OptionalModifierType), string_modopt);
Assert.IsInstanceOf (typeof (OptionalModifierType), string_modopt);
Assert.AreEqual (modopt, string_modopt.ModifierType);
}
@ -75,7 +75,7 @@ namespace Mono.Cecil.Tests { @@ -75,7 +75,7 @@ namespace Mono.Cecil.Tests {
var string_modreq = @string.MakeRequiredModifierType (modreq);
Assert.IsInstanceOfType (typeof (RequiredModifierType), string_modreq);
Assert.IsInstanceOf (typeof (RequiredModifierType), string_modreq);
Assert.AreEqual (modreq, string_modreq.ModifierType);
}
@ -86,7 +86,7 @@ namespace Mono.Cecil.Tests { @@ -86,7 +86,7 @@ namespace Mono.Cecil.Tests {
var pinned_byte_array = byte_array.MakePinnedType ();
Assert.IsInstanceOfType (typeof (PinnedType), pinned_byte_array);
Assert.IsInstanceOf (typeof (PinnedType), pinned_byte_array);
}
[Test]
@ -96,7 +96,7 @@ namespace Mono.Cecil.Tests { @@ -96,7 +96,7 @@ namespace Mono.Cecil.Tests {
var string_sentinel = @string.MakeSentinelType ();
Assert.IsInstanceOfType (typeof (SentinelType), string_sentinel);
Assert.IsInstanceOf (typeof (SentinelType), string_sentinel);
}
class Foo<T1, T2> {}
@ -110,7 +110,7 @@ namespace Mono.Cecil.Tests { @@ -110,7 +110,7 @@ namespace Mono.Cecil.Tests {
var foo_string_int = foo.MakeGenericInstanceType (@string, @int);
Assert.IsInstanceOfType (typeof (GenericInstanceType), foo_string_int);
Assert.IsInstanceOf (typeof (GenericInstanceType), foo_string_int);
Assert.AreEqual (2, foo_string_int.GenericArguments.Count);
Assert.AreEqual (@string, foo_string_int.GenericArguments [0]);
Assert.AreEqual (@int, foo_string_int.GenericArguments [1]);

0
Mono.Cecil/rocks/Test/Resources/cs/Types.cs

2
Mono.Cecil/symbols/mdb/Mono.Cecil.Mdb/AssemblyInfo.cs

@ -32,7 +32,7 @@ using System.Runtime.InteropServices; @@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Mdb")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2010 Jb Evain")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]

12
Mono.Cecil/symbols/mdb/Test/Mono.Cecil.Mdb.Tests.csproj

@ -95,17 +95,17 @@ @@ -95,17 +95,17 @@
<Content Include="Resources\assemblies\hello.exe.mdb" />
</ItemGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.4.8\nunit.core.dll</HintPath>
<HintPath>..\..\..\Test\libs\nunit-2.5.10\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core.interfaces, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.4.8\nunit.core.interfaces.dll</HintPath>
<HintPath>..\..\..\Test\libs\nunit-2.5.10\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.4.8\nunit.framework.dll</HintPath>
<HintPath>..\..\..\Test\libs\nunit-2.5.10\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

98
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -12,7 +17,6 @@ namespace Microsoft.Cci.Pdb { @@ -12,7 +17,6 @@ namespace Microsoft.Cci.Pdb {
internal BitAccess(int capacity) {
this.buffer = new byte[capacity];
this.offset = 0;
}
internal byte[] Buffer {
@ -26,15 +30,26 @@ namespace Microsoft.Cci.Pdb { @@ -26,15 +30,26 @@ namespace Microsoft.Cci.Pdb {
offset = 0;
}
internal void Append(Stream stream, int count) {
int newCapacity = offset + count;
if (buffer.Length < newCapacity) {
byte[] newBuffer = new byte[newCapacity];
Array.Copy(buffer, newBuffer, buffer.Length);
buffer = newBuffer;
}
stream.Read(buffer, offset, count);
offset += count;
}
internal int Position {
get { return offset; }
set { offset = value; }
}
private int offset;
internal void WriteBuffer(Stream stream, int count) {
stream.Write(buffer, 0, count);
}
//internal void WriteBuffer(Stream stream, int count) {
// stream.Write(buffer, 0, count);
//}
internal void MinCapacity(int capacity) {
if (buffer.Length < capacity) {
@ -49,25 +64,25 @@ namespace Microsoft.Cci.Pdb { @@ -49,25 +64,25 @@ namespace Microsoft.Cci.Pdb {
}
}
internal void WriteInt32(int value) {
buffer[offset + 0] = (byte)value;
buffer[offset + 1] = (byte)(value >> 8);
buffer[offset + 2] = (byte)(value >> 16);
buffer[offset + 3] = (byte)(value >> 24);
offset += 4;
}
//internal void WriteInt32(int value) {
// buffer[offset + 0] = (byte)value;
// buffer[offset + 1] = (byte)(value >> 8);
// buffer[offset + 2] = (byte)(value >> 16);
// buffer[offset + 3] = (byte)(value >> 24);
// offset += 4;
//}
internal void WriteInt32(int[] values) {
for (int i = 0; i < values.Length; i++) {
WriteInt32(values[i]);
}
}
//internal void WriteInt32(int[] values) {
// for (int i = 0; i < values.Length; i++) {
// WriteInt32(values[i]);
// }
//}
internal void WriteBytes(byte[] bytes) {
for (int i = 0; i < bytes.Length; i++) {
buffer[offset++] = bytes[i];
}
}
//internal void WriteBytes(byte[] bytes) {
// for (int i = 0; i < bytes.Length; i++) {
// buffer[offset++] = bytes[i];
// }
//}
internal void ReadInt16(out short value) {
value = (short)((buffer[offset + 0] & 0xFF) |
@ -75,6 +90,11 @@ namespace Microsoft.Cci.Pdb { @@ -75,6 +90,11 @@ namespace Microsoft.Cci.Pdb {
offset += 2;
}
internal void ReadInt8(out sbyte value) {
value = (sbyte)buffer[offset];
offset += 1;
}
internal void ReadInt32(out int value) {
value = (int)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
@ -84,14 +104,14 @@ namespace Microsoft.Cci.Pdb { @@ -84,14 +104,14 @@ namespace Microsoft.Cci.Pdb {
}
internal void ReadInt64(out long value) {
value = (long)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) |
(buffer[offset + 3] << 24) |
(buffer[offset + 4] << 32) |
(buffer[offset + 5] << 40) |
(buffer[offset + 6] << 48) |
(buffer[offset + 7] << 56));
value = (long)(((ulong)buffer[offset + 0] & 0xFF) |
((ulong)buffer[offset + 1] << 8) |
((ulong)buffer[offset + 2] << 16) |
((ulong)buffer[offset + 3] << 24) |
((ulong)buffer[offset + 4] << 32) |
((ulong)buffer[offset + 5] << 40) |
((ulong)buffer[offset + 6] << 48) |
((ulong)buffer[offset + 7] << 56));
offset += 8;
}
@ -115,14 +135,14 @@ namespace Microsoft.Cci.Pdb { @@ -115,14 +135,14 @@ namespace Microsoft.Cci.Pdb {
}
internal void ReadUInt64(out ulong value) {
value = (ulong)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) |
(buffer[offset + 3] << 24) |
(buffer[offset + 4] << 32) |
(buffer[offset + 5] << 40) |
(buffer[offset + 6] << 48) |
(buffer[offset + 7] << 56));
value = (ulong)(((ulong)buffer[offset + 0] & 0xFF) |
((ulong)buffer[offset + 1] << 8) |
((ulong)buffer[offset + 2] << 16) |
((ulong)buffer[offset + 3] << 24) |
((ulong)buffer[offset + 4] << 32) |
((ulong)buffer[offset + 5] << 40) |
((ulong)buffer[offset + 6] << 48) |
((ulong)buffer[offset + 7] << 56));
offset += 8;
}
@ -159,7 +179,7 @@ namespace Microsoft.Cci.Pdb { @@ -159,7 +179,7 @@ namespace Microsoft.Cci.Pdb {
internal decimal ReadDecimal() {
int[] bits = new int[4];
this.ReadInt32(bits);
return new decimal(bits);
return new decimal(bits[2], bits[3], bits[1], bits[0] < 0, (byte)((bits[0] & 0x00FF0000) >> 16));
}
internal void ReadBString(out string value) {

69
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -13,10 +18,10 @@ namespace Microsoft.Cci.Pdb { @@ -13,10 +18,10 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt32(words);
}
internal BitSet(int size) {
this.size = size;
words = new uint[size];
}
//internal BitSet(int size) {
// this.size = size;
// words = new uint[size];
//}
internal bool IsSet(int index) {
int word = index / 32;
@ -24,43 +29,43 @@ namespace Microsoft.Cci.Pdb { @@ -24,43 +29,43 @@ namespace Microsoft.Cci.Pdb {
return ((words[word] & GetBit(index)) != 0);
}
internal void Set(int index) {
int word = index / 32;
if (word >= this.size) return;
words[word] |= GetBit(index);
}
//internal void Set(int index) {
// int word = index / 32;
// if (word >= this.size) return;
// words[word] |= GetBit(index);
//}
internal void Clear(int index) {
int word = index / 32;
if (word >= this.size) return;
words[word] &= ~GetBit(index);
}
//internal void Clear(int index) {
// int word = index / 32;
// if (word >= this.size) return;
// words[word] &= ~GetBit(index);
//}
private uint GetBit(int index) {
private static uint GetBit(int index) {
return ((uint)1 << (index % 32));
}
private uint ReverseBits(uint value) {
uint o = 0;
for (int i = 0; i < 32; i++) {
o = (o << 1) | (value & 1);
value >>= 1;
}
return o;
}
//private static uint ReverseBits(uint value) {
// uint o = 0;
// for (int i = 0; i < 32; i++) {
// o = (o << 1) | (value & 1);
// value >>= 1;
// }
// return o;
//}
internal bool IsEmpty {
get { return size == 0; }
}
internal bool GetWord(int index, out uint word) {
if (index < size) {
word = ReverseBits(words[index]);
return true;
}
word = 0;
return false;
}
//internal bool GetWord(int index, out uint word) {
// if (index < size) {
// word = ReverseBits(words[index]);
// return true;
// }
// word = 0;
// return false;
//}
private int size;
private uint[] words;

109
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
//
@ -163,67 +168,67 @@ namespace Microsoft.Cci.Pdb { @@ -163,67 +168,67 @@ namespace Microsoft.Cci.Pdb {
// function to extract primitive mode, type and size
internal static CV_prmode CV_MODE(TYPE_ENUM typ) {
return (CV_prmode)((((uint)typ) & CV_MMASK) >> CV_MSHIFT);
}
//internal static CV_prmode CV_MODE(TYPE_ENUM typ) {
// return (CV_prmode)((((uint)typ) & CV_MMASK) >> CV_MSHIFT);
//}
internal static CV_type CV_TYPE(TYPE_ENUM typ) {
return (CV_type)((((uint)typ) & CV_TMASK) >> CV_TSHIFT);
}
//internal static CV_type CV_TYPE(TYPE_ENUM typ) {
// return (CV_type)((((uint)typ) & CV_TMASK) >> CV_TSHIFT);
//}
internal static uint CV_SUBT(TYPE_ENUM typ) {
return ((((uint)typ) & CV_SMASK) >> CV_SSHIFT);
}
//internal static uint CV_SUBT(TYPE_ENUM typ) {
// return ((((uint)typ) & CV_SMASK) >> CV_SSHIFT);
//}
// functions to check the type of a primitive
internal static bool CV_TYP_IS_DIRECT(TYPE_ENUM typ) {
return (CV_MODE(typ) == CV_prmode.CV_TM_DIRECT);
}
internal static bool CV_TYP_IS_PTR(TYPE_ENUM typ) {
return (CV_MODE(typ) != CV_prmode.CV_TM_DIRECT);
}
internal static bool CV_TYP_IS_SIGNED(TYPE_ENUM typ) {
return
(((CV_TYPE(typ) == CV_type.CV_SIGNED) && CV_TYP_IS_DIRECT(typ)) ||
(typ == TYPE_ENUM.T_INT1) ||
(typ == TYPE_ENUM.T_INT2) ||
(typ == TYPE_ENUM.T_INT4) ||
(typ == TYPE_ENUM.T_INT8) ||
(typ == TYPE_ENUM.T_INT16) ||
(typ == TYPE_ENUM.T_RCHAR));
}
internal static bool CV_TYP_IS_UNSIGNED(TYPE_ENUM typ) {
return (((CV_TYPE(typ) == CV_type.CV_UNSIGNED) && CV_TYP_IS_DIRECT(typ)) ||
(typ == TYPE_ENUM.T_UINT1) ||
(typ == TYPE_ENUM.T_UINT2) ||
(typ == TYPE_ENUM.T_UINT4) ||
(typ == TYPE_ENUM.T_UINT8) ||
(typ == TYPE_ENUM.T_UINT16));
}
internal static bool CV_TYP_IS_REAL(TYPE_ENUM typ) {
return ((CV_TYPE(typ) == CV_type.CV_REAL) && CV_TYP_IS_DIRECT(typ));
}
//internal static bool CV_TYP_IS_DIRECT(TYPE_ENUM typ) {
// return (CV_MODE(typ) == CV_prmode.CV_TM_DIRECT);
//}
//internal static bool CV_TYP_IS_PTR(TYPE_ENUM typ) {
// return (CV_MODE(typ) != CV_prmode.CV_TM_DIRECT);
//}
//internal static bool CV_TYP_IS_SIGNED(TYPE_ENUM typ) {
// return
// (((CV_TYPE(typ) == CV_type.CV_SIGNED) && CV_TYP_IS_DIRECT(typ)) ||
// (typ == TYPE_ENUM.T_INT1) ||
// (typ == TYPE_ENUM.T_INT2) ||
// (typ == TYPE_ENUM.T_INT4) ||
// (typ == TYPE_ENUM.T_INT8) ||
// (typ == TYPE_ENUM.T_INT16) ||
// (typ == TYPE_ENUM.T_RCHAR));
//}
//internal static bool CV_TYP_IS_UNSIGNED(TYPE_ENUM typ) {
// return (((CV_TYPE(typ) == CV_type.CV_UNSIGNED) && CV_TYP_IS_DIRECT(typ)) ||
// (typ == TYPE_ENUM.T_UINT1) ||
// (typ == TYPE_ENUM.T_UINT2) ||
// (typ == TYPE_ENUM.T_UINT4) ||
// (typ == TYPE_ENUM.T_UINT8) ||
// (typ == TYPE_ENUM.T_UINT16));
//}
//internal static bool CV_TYP_IS_REAL(TYPE_ENUM typ) {
// return ((CV_TYPE(typ) == CV_type.CV_REAL) && CV_TYP_IS_DIRECT(typ));
//}
const uint CV_FIRST_NONPRIM = 0x1000;
internal static bool CV_IS_PRIMITIVE(TYPE_ENUM typ) {
return ((uint)(typ) < CV_FIRST_NONPRIM);
}
//internal static bool CV_IS_PRIMITIVE(TYPE_ENUM typ) {
// return ((uint)(typ) < CV_FIRST_NONPRIM);
//}
internal static bool CV_TYP_IS_COMPLEX(TYPE_ENUM typ) {
return ((CV_TYPE(typ) == CV_type.CV_COMPLEX) && CV_TYP_IS_DIRECT(typ));
}
//internal static bool CV_TYP_IS_COMPLEX(TYPE_ENUM typ) {
// return ((CV_TYPE(typ) == CV_type.CV_COMPLEX) && CV_TYP_IS_DIRECT(typ));
//}
internal static bool CV_IS_INTERNAL_PTR(TYPE_ENUM typ) {
return (CV_IS_PRIMITIVE(typ) &&
CV_TYPE(typ) == CV_type.CV_CVRESERVED &&
CV_TYP_IS_PTR(typ));
}
//internal static bool CV_IS_INTERNAL_PTR(TYPE_ENUM typ) {
// return (CV_IS_PRIMITIVE(typ) &&
// CV_TYPE(typ) == CV_type.CV_CVRESERVED &&
// CV_TYP_IS_PTR(typ));
//}
}
// selected values for type_index - for a more complete definition, see

95
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -9,8 +14,6 @@ using System.IO; @@ -9,8 +14,6 @@ using System.IO;
namespace Microsoft.Cci.Pdb {
internal class DataStream {
internal DataStream() {
this.contentSize = 0;
this.pages = null;
}
internal DataStream(int contentSize, BitAccess bits, int count) {
@ -72,73 +75,35 @@ namespace Microsoft.Cci.Pdb { @@ -72,73 +75,35 @@ namespace Microsoft.Cci.Pdb {
}
}
internal void Write(PdbWriter writer, byte[] bytes) {
Write(writer, bytes, bytes.Length);
}
internal void Write(PdbWriter writer, byte[] bytes, int data) {
if (bytes == null || data == 0) {
return;
}
int left = data;
int used = 0;
int rema = contentSize % writer.pageSize;
if (rema != 0) {
int todo = writer.pageSize - rema;
if (todo > left) {
todo = left;
}
int lastPage = pages[pages.Length - 1];
writer.Seek(lastPage, rema);
writer.Write(bytes, used, todo);
used += todo;
left -= todo;
}
if (left > 0) {
int count = (left + writer.pageSize - 1) / writer.pageSize;
int page0 = writer.AllocatePages(count);
writer.Seek(page0, 0);
writer.Write(bytes, used, left);
AddPages(page0, count);
}
contentSize += data;
}
private void AddPages(int page0, int count) {
if (pages == null) {
pages = new int[count];
for (int i = 0; i < count; i++) {
pages[i] = page0 + i;
}
} else {
int[] old = pages;
int used = old.Length;
pages = new int[used + count];
Array.Copy(old, pages, used);
for (int i = 0; i < count; i++) {
pages[used + i] = page0 + i;
}
}
}
internal int Pages {
get { return pages == null ? 0 : pages.Length; }
}
//private void AddPages(int page0, int count) {
// if (pages == null) {
// pages = new int[count];
// for (int i = 0; i < count; i++) {
// pages[i] = page0 + i;
// }
// } else {
// int[] old = pages;
// int used = old.Length;
// pages = new int[used + count];
// Array.Copy(old, pages, used);
// for (int i = 0; i < count; i++) {
// pages[used + i] = page0 + i;
// }
// }
//}
//internal int Pages {
// get { return pages == null ? 0 : pages.Length; }
//}
internal int Length {
get { return contentSize; }
}
internal int GetPage(int index) {
return pages[index];
}
//internal int GetPage(int index) {
// return pages[index];
//}
internal int contentSize;
internal int[] pages;

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

11
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -9,7 +14,7 @@ namespace Microsoft.Cci.Pdb { @@ -9,7 +14,7 @@ namespace Microsoft.Cci.Pdb {
internal class DbiModuleInfo {
internal DbiModuleInfo(BitAccess bits, bool readStrings) {
bits.ReadInt32(out opened);
section = new DbiSecCon(bits);
new DbiSecCon(bits);
bits.ReadUInt16(out flags);
bits.ReadInt16(out stream);
bits.ReadInt32(out cbSyms);
@ -35,7 +40,7 @@ namespace Microsoft.Cci.Pdb { @@ -35,7 +40,7 @@ namespace Microsoft.Cci.Pdb {
}
internal int opened; // 0..3
internal DbiSecCon section; // 4..31
//internal DbiSecCon section; // 4..31
internal ushort flags; // 32..33
internal short stream; // 34..35
internal int cbSyms; // 36..39

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

262
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -54,7 +59,7 @@ namespace Microsoft.Cci.Pdb { @@ -54,7 +59,7 @@ namespace Microsoft.Cci.Pdb {
// By Brian Grunkemeyer, algorithm by Patrick Dussud.
// Version 1.30 2/20/2000
//| <include path='docs/doc[@for="IntHashTable"]/*' />
internal class IntHashTable : IEnumerable {
internal class IntHashTable {//: IEnumerable {
/*
Implementation Notes:
@ -125,7 +130,7 @@ namespace Microsoft.Cci.Pdb { @@ -125,7 +130,7 @@ namespace Microsoft.Cci.Pdb {
187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263,
1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369};
private int GetPrime(int minSize) {
private static int GetPrime(int minSize) {
if (minSize < 0) {
throw new ArgumentException("Arg_HTCapacityOverflow");
}
@ -168,17 +173,17 @@ namespace Microsoft.Cci.Pdb { @@ -168,17 +173,17 @@ namespace Microsoft.Cci.Pdb {
: this(0, 100) {
}
// Constructs a new hashtable with the given initial capacity and a load
// factor of 1.0. The capacity argument serves as an indication of
// the number of entries the hashtable will contain. When this number (or
// an approximation) is known, specifying it in the constructor can
// eliminate a number of resizing operations that would otherwise be
// performed when elements are added to the hashtable.
//
//| <include path='docs/doc[@for="IntHashTable.IntHashTable1"]/*' />
internal IntHashTable(int capacity)
: this(capacity, 100) {
}
//// Constructs a new hashtable with the given initial capacity and a load
//// factor of 1.0. The capacity argument serves as an indication of
//// the number of entries the hashtable will contain. When this number (or
//// an approximation) is known, specifying it in the constructor can
//// eliminate a number of resizing operations that would otherwise be
//// performed when elements are added to the hashtable.
////
////| <include path='docs/doc[@for="IntHashTable.IntHashTable1"]/*' />
//internal IntHashTable(int capacity)
// : this(capacity, 100) {
//}
// Constructs a new hashtable with the given initial capacity and load
// factor. The capacity argument serves as an indication of the
@ -213,7 +218,7 @@ namespace Microsoft.Cci.Pdb { @@ -213,7 +218,7 @@ namespace Microsoft.Cci.Pdb {
// The out parameter seed is h1(key), while the out parameter
// incr is h2(key, hashSize). Callers of this function should
// add incr each time through a loop.
private uint InitHash(int key, int hashsize, out uint seed, out uint incr) {
private static uint InitHash(int key, int hashsize, out uint seed, out uint incr) {
// Hashcode must be positive. Also, we must not use the sign bit, since
// that is used for the collision bit.
uint hashcode = (uint)key & 0x7FFFFFFF;
@ -236,52 +241,52 @@ namespace Microsoft.Cci.Pdb { @@ -236,52 +241,52 @@ namespace Microsoft.Cci.Pdb {
Insert(key, value, true);
}
// Removes all entries from this hashtable.
//| <include path='docs/doc[@for="IntHashTable.Clear"]/*' />
internal void Clear() {
if (count == 0)
return;
//// Removes all entries from this hashtable.
////| <include path='docs/doc[@for="IntHashTable.Clear"]/*' />
//internal void Clear() {
// if (count == 0)
// return;
for (int i = 0; i < buckets.Length; i++) {
buckets[i].hash_coll = 0;
buckets[i].key = -1;
buckets[i].val = null;
}
// for (int i = 0; i < buckets.Length; i++) {
// buckets[i].hash_coll = 0;
// buckets[i].key = -1;
// buckets[i].val = null;
// }
count = 0;
occupancy = 0;
}
// count = 0;
// occupancy = 0;
//}
// Checks if this hashtable contains an entry with the given key. This is
// an O(1) operation.
//
//| <include path='docs/doc[@for="IntHashTable.Contains"]/*' />
internal bool Contains(int key) {
if (key < 0) {
throw new ArgumentException("Argument_KeyLessThanZero");
}
uint seed;
uint incr;
// Take a snapshot of buckets, in case another thread resizes table
bucket[] lbuckets = buckets;
uint hashcode = InitHash(key, lbuckets.Length, out seed, out incr);
int ntry = 0;
bucket b;
do {
int bucketNumber = (int)(seed % (uint)lbuckets.Length);
b = lbuckets[bucketNumber];
if (b.val == null) {
return false;
}
if (((b.hash_coll & 0x7FFFFFFF) == hashcode) && b.key == key) {
return true;
}
seed += incr;
} while (b.hash_coll < 0 && ++ntry < lbuckets.Length);
return false;
}
//internal bool Contains(int key) {
// if (key < 0) {
// throw new ArgumentException("Argument_KeyLessThanZero");
// }
// uint seed;
// uint incr;
// // Take a snapshot of buckets, in case another thread resizes table
// bucket[] lbuckets = buckets;
// uint hashcode = InitHash(key, lbuckets.Length, out seed, out incr);
// int ntry = 0;
// bucket b;
// do {
// int bucketNumber = (int)(seed % (uint)lbuckets.Length);
// b = lbuckets[bucketNumber];
// if (b.val == null) {
// return false;
// }
// if (((b.hash_coll & 0x7FFFFFFF) == hashcode) && b.key == key) {
// return true;
// }
// seed += incr;
// } while (b.hash_coll < 0 && ++ntry < lbuckets.Length);
// return false;
//}
// Returns the value associated with the given key. If an entry with the
// given key is not found, the returned value is null.
@ -313,9 +318,9 @@ namespace Microsoft.Cci.Pdb { @@ -313,9 +318,9 @@ namespace Microsoft.Cci.Pdb {
} while (b.hash_coll < 0 && ++ntry < lbuckets.Length);
return null;
}
set {
Insert(key, value, false);
}
//set {
// Insert(key, value, false);
//}
}
// Increases the bucket count of this hashtable. This method is called from
@ -374,9 +379,9 @@ namespace Microsoft.Cci.Pdb { @@ -374,9 +379,9 @@ namespace Microsoft.Cci.Pdb {
// enumerator will throw an exception.
//
//| <include path='docs/doc[@for="IntHashTable.IEnumerable.GetEnumerator"]/*' />
IEnumerator IEnumerable.GetEnumerator() {
return new IntHashTableEnumerator(this);
}
//IEnumerator IEnumerable.GetEnumerator() {
// return new IntHashTableEnumerator(this);
//}
// Internal method to compare two keys.
//
@ -502,78 +507,77 @@ namespace Microsoft.Cci.Pdb { @@ -502,78 +507,77 @@ namespace Microsoft.Cci.Pdb {
// Returns the number of associations in this hashtable.
//
//| <include path='docs/doc[@for="IntHashTable.Count"]/*' />
internal int Count {
get { return count; }
}
//internal int Count {
// get { return count; }
//}
// Implements an enumerator for a hashtable. The enumerator uses the
// internal version number of the hashtabke to ensure that no modifications
// are made to the hashtable while an enumeration is in progress.
private class IntHashTableEnumerator : IEnumerator {
private IntHashTable hashtable;
private int bucket;
private int version;
private bool current;
private int currentKey;
private Object currentValue;
internal IntHashTableEnumerator(IntHashTable hashtable) {
this.hashtable = hashtable;
bucket = hashtable.buckets.Length;
version = hashtable.version;
current = false;
}
public bool MoveNext() {
if (version != hashtable.version)
throw new InvalidOperationException("InvalidOperation_EnumFailedVersion");
while (bucket > 0) {
bucket--;
Object val = hashtable.buckets[bucket].val;
if (val != null) {
currentKey = hashtable.buckets[bucket].key;
currentValue = val;
current = true;
return true;
}
}
current = false;
return false;
}
internal int Key {
get {
if (current == false)
throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen");
return currentKey;
}
}
public Object Current {
get {
if (current == false)
throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen");
return currentValue;
}
}
public Object Value {
get {
if (version != hashtable.version)
throw new InvalidOperationException("InvalidOperation_EnumFailedVersion");
if (current == false)
throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen");
return currentValue;
}
}
public void Reset() {
if (version != hashtable.version) throw new InvalidOperationException("InvalidOperation_EnumFailedVersion");
current = false;
bucket = hashtable.buckets.Length;
currentKey = -1;
currentValue = null;
}
}
//private class IntHashTableEnumerator : IEnumerator {
// private IntHashTable hashtable;
// private int bucket;
// private int version;
// private bool current;
// //private int currentKey;
// private Object currentValue;
// internal IntHashTableEnumerator(IntHashTable hashtable) {
// this.hashtable = hashtable;
// bucket = hashtable.buckets.Length;
// version = hashtable.version;
// }
// public bool MoveNext() {
// if (version != hashtable.version)
// throw new InvalidOperationException("InvalidOperation_EnumFailedVersion");
// while (bucket > 0) {
// bucket--;
// Object val = hashtable.buckets[bucket].val;
// if (val != null) {
// //currentKey = hashtable.buckets[bucket].key;
// currentValue = val;
// current = true;
// return true;
// }
// }
// current = false;
// return false;
// }
// //internal int Key {
// // get {
// // if (current == false)
// // throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen");
// // return currentKey;
// // }
// //}
// public Object Current {
// get {
// if (current == false)
// throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen");
// return currentValue;
// }
// }
// //public Object Value {
// // get {
// // if (version != hashtable.version)
// // throw new InvalidOperationException("InvalidOperation_EnumFailedVersion");
// // if (current == false)
// // throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen");
// // return currentValue;
// // }
// //}
// public void Reset() {
// if (version != hashtable.version) throw new InvalidOperationException("InvalidOperation_EnumFailedVersion");
// current = false;
// bucket = hashtable.buckets.Length;
// //currentKey = -1;
// currentValue = null;
// }
//}
}
}

21
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -8,12 +13,20 @@ using System; @@ -8,12 +13,20 @@ using System;
namespace Microsoft.Cci.Pdb {
internal class MsfDirectory {
internal MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits) {
bits.MinCapacity(head.directorySize);
int pages = reader.PagesFromSize(head.directorySize);
// 0..n in page of directory pages.
reader.Seek(head.directoryRoot, 0);
bits.FillBuffer(reader.reader, pages * 4);
bits.MinCapacity(head.directorySize);
int directoryRootPages = head.directoryRoot.Length;
int pagesPerPage = head.pageSize / 4;
int pagesToGo = pages;
for (int i = 0; i < directoryRootPages; i++) {
int pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage;
reader.Seek(head.directoryRoot[i], 0);
bits.Append(reader.reader, pagesInThisPage * 4);
pagesToGo -= pagesInThisPage;
}
bits.Position = 0;
DataStream stream = new DataStream(head.directorySize, bits, pages);
bits.MinCapacity(head.directorySize);

12
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -22,6 +27,11 @@ namespace Microsoft.Cci.Pdb { @@ -22,6 +27,11 @@ namespace Microsoft.Cci.Pdb {
this.value = tag1;
} else if (tag2 == 0x80) {
switch (tag1) {
case 0x00: //sbyte
sbyte sb;
bits.ReadInt8(out sb);
this.value = sb;
break;
case 0x01: //short
short s;
bits.ReadInt16(out s);

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

72
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -21,7 +26,7 @@ namespace Microsoft.Cci.Pdb { @@ -21,7 +26,7 @@ namespace Microsoft.Cci.Pdb {
bits.ReadGuid(out doctype);
}
static Dictionary<string,int> LoadNameIndex(BitAccess bits, out int age, out Guid guid) {
static Dictionary<string, int> LoadNameIndex(BitAccess bits, out int age, out Guid guid) {
Dictionary<string, int> result = new Dictionary<string, int>();
int ver;
int sig;
@ -30,9 +35,9 @@ namespace Microsoft.Cci.Pdb { @@ -30,9 +35,9 @@ namespace Microsoft.Cci.Pdb {
bits.ReadInt32(out age); // 8..11 Age
bits.ReadGuid(out guid); // 12..27 GUID
if (ver != 20000404) {
throw new PdbDebugException("Unsupported PDB Stream version {0}", ver);
}
//if (ver != 20000404) {
// throw new PdbDebugException("Unsupported PDB Stream version {0}", ver);
//}
// Read string buffer.
int buf;
@ -70,7 +75,7 @@ namespace Microsoft.Cci.Pdb { @@ -70,7 +75,7 @@ namespace Microsoft.Cci.Pdb {
bits.ReadCString(out name);
bits.Position = saved;
result.Add(name, ni);
result.Add(name.ToUpperInvariant(), ni);
j++;
}
}
@ -128,15 +133,11 @@ namespace Microsoft.Cci.Pdb { @@ -128,15 +133,11 @@ namespace Microsoft.Cci.Pdb {
private static PdbFunction match = new PdbFunction();
private static PdbFunction FindFunction(PdbFunction[] funcs, ushort sec, uint off) {
private static int FindFunction(PdbFunction[] funcs, ushort sec, uint off) {
match.segment = sec;
match.address = off;
int item = Array.BinarySearch(funcs, match, PdbFunction.byAddress);
if (item >= 0) {
return funcs[item];
}
return null;
return Array.BinarySearch(funcs, match, PdbFunction.byAddress);
}
static void LoadManagedLines(PdbFunction[] funcs,
@ -146,7 +147,7 @@ namespace Microsoft.Cci.Pdb { @@ -146,7 +147,7 @@ namespace Microsoft.Cci.Pdb {
Dictionary<string, int> nameIndex,
PdbReader reader,
uint limit) {
Array.Sort(funcs, PdbFunction.byAddress);
Array.Sort(funcs, PdbFunction.byAddressAndToken);
IntHashTable checks = new IntHashTable();
// Read the files first
@ -172,15 +173,15 @@ namespace Microsoft.Cci.Pdb { @@ -172,15 +173,15 @@ namespace Microsoft.Cci.Pdb {
string name = (string)names[(int)chk.name];
int guidStream;
Guid doctypeGuid = SymDocumentType.Text;
Guid languageGuid = SymLanguageType.CSharp;
Guid vendorGuid = SymLanguageVendor.Microsoft;
if (nameIndex.TryGetValue("/src/files/"+name, out guidStream)) {
Guid languageGuid = Guid.Empty;
Guid vendorGuid = Guid.Empty;
if (nameIndex.TryGetValue("/SRC/FILES/"+name.ToUpperInvariant(), out guidStream)) {
var guidBits = new BitAccess(0x100);
dir.streams[guidStream].Read(reader, guidBits);
LoadGuidStream(guidBits, out doctypeGuid, out languageGuid, out vendorGuid);
}
PdbSource src = new PdbSource((uint)ni, name, doctypeGuid, languageGuid, vendorGuid);
PdbSource src = new PdbSource(/*(uint)ni,*/ name, doctypeGuid, languageGuid, vendorGuid);
checks.Add(ni, src);
bits.Position += chk.len;
bits.Align(4);
@ -211,8 +212,25 @@ namespace Microsoft.Cci.Pdb { @@ -211,8 +212,25 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt16(out sec.sec);
bits.ReadUInt16(out sec.flags);
bits.ReadUInt32(out sec.cod);
PdbFunction func = FindFunction(funcs, sec.sec, sec.off);
if (func == null) break;
int funcIndex = FindFunction(funcs, sec.sec, sec.off);
if (funcIndex < 0) break;
var func = funcs[funcIndex];
if (func.lines == null) {
while (funcIndex > 0) {
var f = funcs[funcIndex-1];
if (f.lines != null || f.segment != sec.sec || f.address != sec.off) break;
func = f;
funcIndex--;
}
} else {
while (funcIndex < funcs.Length-1 && func.lines != null) {
var f = funcs[funcIndex+1];
if (f.segment != sec.sec || f.address != sec.off) break;
func = f;
funcIndex++;
}
}
if (func.lines != null) break;
// Count the line blocks.
int begSym = bits.Position;
@ -255,7 +273,7 @@ namespace Microsoft.Cci.Pdb { @@ -255,7 +273,7 @@ namespace Microsoft.Cci.Pdb {
uint lineBegin = line.flags & (uint)CV_Line_Flags.linenumStart;
uint delta = (line.flags & (uint)CV_Line_Flags.deltaLineEnd) >> 24;
bool statement = ((line.flags & (uint)CV_Line_Flags.fStatement) == 0);
//bool statement = ((line.flags & (uint)CV_Line_Flags.fStatement) == 0);
if ((sec.flags & 1) != 0) {
bits.Position = pcol + 4 * i;
bits.ReadUInt16(out column.offColumnStart);
@ -295,7 +313,7 @@ namespace Microsoft.Cci.Pdb { @@ -295,7 +313,7 @@ namespace Microsoft.Cci.Pdb {
bits.Position = 4;
// Console.WriteLine("{0}:", info.moduleName);
funcs = PdbFunction.LoadManagedFunctions(info.moduleName,
funcs = PdbFunction.LoadManagedFunctions(/*info.moduleName,*/
bits, (uint)info.cbSyms,
readStrings);
if (funcs != null) {
@ -316,10 +334,10 @@ namespace Microsoft.Cci.Pdb { @@ -316,10 +334,10 @@ namespace Microsoft.Cci.Pdb {
DbiHeader dh = new DbiHeader(bits);
header = new DbiDbgHdr();
if (dh.sig != -1 || dh.ver != 19990903) {
throw new PdbException("Unsupported DBI Stream version, sig={0}, ver={1}",
dh.sig, dh.ver);
}
//if (dh.sig != -1 || dh.ver != 19990903) {
// throw new PdbException("Unsupported DBI Stream version, sig={0}, ver={1}",
// dh.sig, dh.ver);
//}
// Read gpmod section.
ArrayList modList = new ArrayList();
@ -377,7 +395,7 @@ namespace Microsoft.Cci.Pdb { @@ -377,7 +395,7 @@ namespace Microsoft.Cci.Pdb {
dir.streams[1].Read(reader, bits);
Dictionary<string, int> nameIndex = LoadNameIndex(bits, out age, out guid);
int nameStream;
if (!nameIndex.TryGetValue("/names", out nameStream)) {
if (!nameIndex.TryGetValue("/NAMES", out nameStream)) {
throw new PdbException("No `name' stream");
}
@ -413,7 +431,7 @@ namespace Microsoft.Cci.Pdb { @@ -413,7 +431,7 @@ namespace Microsoft.Cci.Pdb {
}
//
Array.Sort(funcs, PdbFunction.byAddress);
Array.Sort(funcs, PdbFunction.byAddressAndToken);
//Array.Sort(funcs, PdbFunction.byToken);
return funcs;
}

88
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -9,21 +14,20 @@ using System.Text; @@ -9,21 +14,20 @@ using System.Text;
namespace Microsoft.Cci.Pdb {
internal class PdbFileHeader {
internal PdbFileHeader(int pageSize) {
this.magic = new byte[32] {
0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
};
this.pageSize = pageSize;
this.zero = 0;
}
//internal PdbFileHeader(int pageSize) {
// this.magic = new byte[32] {
// 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
// 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
// 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
// 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
// };
// this.pageSize = pageSize;
//}
internal PdbFileHeader(Stream reader, BitAccess bits) {
bits.MinCapacity(56);
reader.Seek(0, SeekOrigin.Begin);
bits.FillBuffer(reader, 56);
bits.FillBuffer(reader, 52);
this.magic = new byte[32];
bits.ReadBytes(this.magic); // 0..31
@ -32,41 +36,45 @@ namespace Microsoft.Cci.Pdb { @@ -32,41 +36,45 @@ namespace Microsoft.Cci.Pdb {
bits.ReadInt32(out this.pagesUsed); // 40..43
bits.ReadInt32(out this.directorySize); // 44..47
bits.ReadInt32(out this.zero); // 48..51
bits.ReadInt32(out this.directoryRoot); // 52..55
}
internal string Magic {
get { return StringFromBytesUTF8(magic); }
int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
this.directoryRoot = new int[directoryPages];
bits.FillBuffer(reader, directoryPages * 4);
bits.ReadInt32(this.directoryRoot);
}
internal void Write(Stream writer, BitAccess bits) {
bits.MinCapacity(56);
bits.WriteBytes(magic); // 0..31
bits.WriteInt32(pageSize); // 32..35
bits.WriteInt32(freePageMap); // 36..39
bits.WriteInt32(pagesUsed); // 40..43
bits.WriteInt32(directorySize); // 44..47
bits.WriteInt32(zero); // 48..51
bits.WriteInt32(directoryRoot); // 52..55
//internal string Magic {
// get { return StringFromBytesUTF8(magic); }
//}
writer.Seek(0, SeekOrigin.Begin);
bits.WriteBuffer(writer, 56);
}
//internal void Write(Stream writer, BitAccess bits) {
// bits.MinCapacity(pageSize);
// bits.WriteBytes(magic); // 0..31
// bits.WriteInt32(pageSize); // 32..35
// bits.WriteInt32(freePageMap); // 36..39
// bits.WriteInt32(pagesUsed); // 40..43
// bits.WriteInt32(directorySize); // 44..47
// bits.WriteInt32(zero); // 48..51
// bits.WriteInt32(directoryRoot); // 52..55
// writer.Seek(0, SeekOrigin.Begin);
// bits.WriteBuffer(writer, pageSize);
//}
//////////////////////////////////////////////////// Helper Functions.
//
internal string StringFromBytesUTF8(byte[] bytes) {
return StringFromBytesUTF8(bytes, 0, bytes.Length);
}
//internal static string StringFromBytesUTF8(byte[] bytes) {
// return StringFromBytesUTF8(bytes, 0, bytes.Length);
//}
internal string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
for (int i = 0; i < length; i++) {
if (bytes[offset + i] < ' ') {
length = i;
}
}
return Encoding.UTF8.GetString(bytes, offset, length);
}
//internal static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
// for (int i = 0; i < length; i++) {
// if (bytes[offset + i] < ' ') {
// length = i;
// }
// }
// return Encoding.UTF8.GetString(bytes, offset, length);
//}
////////////////////////////////////////////////////////////// Fields.
//
@ -76,7 +84,7 @@ namespace Microsoft.Cci.Pdb { @@ -76,7 +84,7 @@ namespace Microsoft.Cci.Pdb {
internal int pagesUsed;
internal int directorySize;
internal readonly int zero;
internal int directoryRoot;
internal int[] directoryRoot;
}
}

123
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -12,20 +17,24 @@ namespace Microsoft.Cci.Pdb { @@ -12,20 +17,24 @@ namespace Microsoft.Cci.Pdb {
static internal readonly Guid msilMetaData = new Guid(0xc6ea3fc9, 0x59b3, 0x49d6, 0xbc, 0x25,
0x09, 0x02, 0xbb, 0xab, 0xb4, 0x60);
static internal readonly IComparer byAddress = new PdbFunctionsByAddress();
static internal readonly IComparer byToken = new PdbFunctionsByToken();
static internal readonly IComparer byAddressAndToken = new PdbFunctionsByAddressAndToken();
//static internal readonly IComparer byToken = new PdbFunctionsByToken();
internal uint token;
internal uint slotToken;
internal string name;
internal string module;
internal ushort flags;
//internal string name;
//internal string module;
//internal ushort flags;
internal uint segment;
internal uint address;
internal uint length;
//internal uint length;
//internal byte[] metadata;
internal PdbScope[] scopes;
internal PdbSlot[] slots;
internal PdbConstant[] constants;
internal string[] usedNamespaces;
internal PdbLines[] lines;
internal ushort[]/*?*/ usingCounts;
internal IEnumerable<INamespaceScope>/*?*/ namespaceScopes;
@ -41,10 +50,10 @@ namespace Microsoft.Cci.Pdb { @@ -41,10 +50,10 @@ namespace Microsoft.Cci.Pdb {
}
internal static PdbFunction[] LoadManagedFunctions(string module,
internal static PdbFunction[] LoadManagedFunctions(/*string module,*/
BitAccess bits, uint limit,
bool readStrings) {
string mod = StripNamespace(module);
//string mod = StripNamespace(module);
int begin = bits.Position;
int count = 0;
@ -101,7 +110,7 @@ namespace Microsoft.Cci.Pdb { @@ -101,7 +110,7 @@ namespace Microsoft.Cci.Pdb {
case SYM.S_GMANPROC:
case SYM.S_LMANPROC:
ManProcSym proc;
int offset = bits.Position;
//int offset = bits.Position;
bits.ReadUInt32(out proc.parent);
bits.ReadUInt32(out proc.end);
@ -122,7 +131,7 @@ namespace Microsoft.Cci.Pdb { @@ -122,7 +131,7 @@ namespace Microsoft.Cci.Pdb {
//Console.WriteLine("token={0:X8} [{1}::{2}]", proc.token, module, proc.name);
bits.Position = stop;
funcs[func++] = new PdbFunction(module, proc, bits);
funcs[func++] = new PdbFunction(/*module,*/ proc, bits);
break;
default: {
@ -190,15 +199,14 @@ namespace Microsoft.Cci.Pdb { @@ -190,15 +199,14 @@ namespace Microsoft.Cci.Pdb {
internal PdbFunction() {
}
internal PdbFunction(string module, ManProcSym proc, BitAccess bits) {
internal PdbFunction(/*string module, */ManProcSym proc, BitAccess bits) {
this.token = proc.token;
this.module = module;
this.name = proc.name;
this.flags = proc.flags;
//this.module = module;
//this.name = proc.name;
//this.flags = proc.flags;
this.segment = proc.seg;
this.address = proc.off;
this.length = proc.len;
this.slotToken = 0;
//this.length = proc.len;
if (proc.seg != 1) {
throw new PdbDebugException("Segment is {0}, not 1.", proc.seg);
@ -207,18 +215,27 @@ namespace Microsoft.Cci.Pdb { @@ -207,18 +215,27 @@ namespace Microsoft.Cci.Pdb {
throw new PdbDebugException("Warning parent={0}, next={1}",
proc.parent, proc.next);
}
if (proc.dbgStart != 0 || proc.dbgEnd != 0) {
throw new PdbDebugException("Warning DBG start={0}, end={1}",
proc.dbgStart, proc.dbgEnd);
}
//if (proc.dbgStart != 0 || proc.dbgEnd != 0) {
// throw new PdbDebugException("Warning DBG start={0}, end={1}",
// proc.dbgStart, proc.dbgEnd);
//}
int constantCount;
int scopeCount;
int slotCount;
int usedNamespacesCount;
CountScopesAndSlots(bits, proc.end, out constantCount, out scopeCount, out slotCount, out usedNamespacesCount);
scopes = new PdbScope[scopeCount];
int scope = 0;
int scope = constantCount > 0 || slotCount > 0 || usedNamespacesCount > 0 ? 1 : 0;
int slot = 0;
int constant = 0;
int usedNs = 0;
scopes = new PdbScope[scopeCount+scope];
slots = new PdbSlot[slotCount];
constants = new PdbConstant[constantCount];
usedNamespaces = new string[usedNamespacesCount];
if (scope > 0)
scopes[0] = new PdbScope(this.address, proc.len, slots, constants, usedNamespaces);
while (bits.Position < proc.end) {
ushort siz;
@ -266,17 +283,29 @@ namespace Microsoft.Cci.Pdb { @@ -266,17 +283,29 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt32(out block.parent);
bits.ReadUInt32(out block.end);
bits.ReadUInt32(out block.len);
bits.ReadUInt32(out this.address);
bits.ReadUInt32(out block.off);
bits.ReadUInt16(out block.seg);
bits.SkipCString(out block.name);
bits.Position = stop;
scopes[scope] = new PdbScope(block, bits, out slotToken);
scopes[scope++] = new PdbScope(this.address, block, bits, out slotToken);
bits.Position = (int)block.end;
break;
}
case SYM.S_MANSLOT:
uint typind;
slots[slot++] = new PdbSlot(bits, out typind);
bits.Position = stop;
break;
case SYM.S_MANCONSTANT:
constants[constant++] = new PdbConstant(bits);
bits.Position = stop;
break;
case SYM.S_UNAMESPACE:
bits.ReadCString(out usedNamespaces[usedNs++]);
bits.Position = stop;
break;
@ -320,8 +349,8 @@ namespace Microsoft.Cci.Pdb { @@ -320,8 +349,8 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt32(out numberOfBytesInItem);
switch (kind) {
case 0: this.ReadUsingInfo(bits); break;
case 1: this.ReadForwardInfo(bits); break;
case 2: this.ReadForwardedToModuleInfo(bits); break;
case 1: break; // this.ReadForwardInfo(bits); break;
case 2: break; // this.ReadForwardedToModuleInfo(bits); break;
case 3: this.ReadIteratorLocals(bits); break;
case 4: this.ReadForwardIterator(bits); break;
default: throw new PdbDebugException("Unknown custom metadata item kind: {0}", kind);
@ -346,11 +375,11 @@ namespace Microsoft.Cci.Pdb { @@ -346,11 +375,11 @@ namespace Microsoft.Cci.Pdb {
}
}
private void ReadForwardedToModuleInfo(BitAccess bits) {
}
//private void ReadForwardedToModuleInfo(BitAccess bits) {
//}
private void ReadForwardInfo(BitAccess bits) {
}
//private void ReadForwardInfo(BitAccess bits) {
//}
private void ReadUsingInfo(BitAccess bits) {
ushort numberOfNamespaces;
@ -380,20 +409,44 @@ namespace Microsoft.Cci.Pdb { @@ -380,20 +409,44 @@ namespace Microsoft.Cci.Pdb {
}
}
internal class PdbFunctionsByToken : IComparer {
internal class PdbFunctionsByAddressAndToken : IComparer {
public int Compare(Object x, Object y) {
PdbFunction fx = (PdbFunction)x;
PdbFunction fy = (PdbFunction)y;
if (fx.token < fy.token) {
if (fx.segment < fy.segment) {
return -1;
} else if (fx.segment > fy.segment) {
return 1;
} else if (fx.address < fy.address) {
return -1;
} else if (fx.token > fy.token) {
} else if (fx.address > fy.address) {
return 1;
} else {
return 0;
if (fx.token < fy.token)
return -1;
else if (fx.token > fy.token)
return 1;
else
return 0;
}
}
}
//internal class PdbFunctionsByToken : IComparer {
// public int Compare(Object x, Object y) {
// PdbFunction fx = (PdbFunction)x;
// PdbFunction fy = (PdbFunction)y;
// if (fx.token < fy.token) {
// return -1;
// } else if (fx.token > fy.token) {
// return 1;
// } else {
// return 0;
// }
// }
//}
}
}

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

7
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;

13
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -25,9 +30,9 @@ namespace Microsoft.Cci.Pdb { @@ -25,9 +30,9 @@ namespace Microsoft.Cci.Pdb {
return (size + pageSize - 1) / (pageSize);
}
internal int PageSize {
get { return pageSize; }
}
//internal int PageSize {
// get { return pageSize; }
//}
internal readonly int pageSize;
internal readonly Stream reader;

32
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -12,13 +17,25 @@ namespace Microsoft.Cci.Pdb { @@ -12,13 +17,25 @@ namespace Microsoft.Cci.Pdb {
internal PdbScope[] scopes;
internal string[] usedNamespaces;
internal uint segment;
//internal uint segment;
internal uint address;
internal uint offset;
internal uint length;
internal PdbScope(BlockSym32 block, BitAccess bits, out uint typind) {
this.segment = block.seg;
internal PdbScope(uint address, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces) {
this.constants = constants;
this.slots = slots;
this.scopes = new PdbScope[0];
this.usedNamespaces = usedNamespaces;
this.address = address;
this.offset = 0;
this.length = length;
}
internal PdbScope(uint funcOffset, BlockSym32 block, BitAccess bits, out uint typind) {
//this.segment = block.seg;
this.address = block.off;
this.offset = block.off - funcOffset;
this.length = block.len;
typind = 0;
@ -58,7 +75,7 @@ namespace Microsoft.Cci.Pdb { @@ -58,7 +75,7 @@ namespace Microsoft.Cci.Pdb {
bits.SkipCString(out sub.name);
bits.Position = stop;
scopes[scope++] = new PdbScope(sub, bits, out typind);
scopes[scope++] = new PdbScope(funcOffset, sub, bits, out typind);
break;
}
@ -82,8 +99,9 @@ namespace Microsoft.Cci.Pdb { @@ -82,8 +99,9 @@ namespace Microsoft.Cci.Pdb {
break;
default:
throw new PdbException("Unknown SYM in scope {0}", (SYM)rec);
// bits.Position = stop;
//throw new PdbException("Unknown SYM in scope {0}", (SYM)rec);
bits.Position = stop;
break;
}
}

15
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
@ -10,8 +15,8 @@ namespace Microsoft.Cci.Pdb { @@ -10,8 +15,8 @@ namespace Microsoft.Cci.Pdb {
internal uint slot;
internal string name;
internal ushort flags;
internal uint segment;
internal uint address;
//internal uint segment;
//internal uint address;
internal PdbSlot(BitAccess bits, out uint typind) {
AttrSlotSym slot;
@ -26,8 +31,8 @@ namespace Microsoft.Cci.Pdb { @@ -26,8 +31,8 @@ namespace Microsoft.Cci.Pdb {
this.slot = slot.index;
this.name = slot.name;
this.flags = slot.flags;
this.segment = slot.segCod;
this.address = slot.offCod;
//this.segment = slot.segCod;
//this.address = slot.offCod;
typind = slot.typind;
}

13
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs

@ -1,20 +1,25 @@ @@ -1,20 +1,25 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal class PdbSource {
internal uint index;
//internal uint index;
internal string name;
internal Guid doctype;
internal Guid language;
internal Guid vendor;
internal PdbSource(uint index, string name, Guid doctype, Guid language, Guid vendor) {
this.index = index;
internal PdbSource(/*uint index, */string name, Guid doctype, Guid language, Guid vendor) {
//this.index = index;
this.name = name;
this.doctype = doctype;
this.language = language;

129
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs

@ -1,129 +0,0 @@ @@ -1,129 +0,0 @@
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
namespace Microsoft.Cci.Pdb {
internal class PdbWriter {
internal PdbWriter(Stream writer, int pageSize) {
this.pageSize = pageSize;
this.usedBytes = pageSize * 3;
this.writer = writer;
writer.SetLength(usedBytes);
}
internal void WriteMeta(DataStream[] streams, BitAccess bits) {
PdbFileHeader head = new PdbFileHeader(pageSize);
WriteDirectory(streams,
out head.directoryRoot,
out head.directorySize,
bits);
WriteFreeMap();
head.freePageMap = 2;
head.pagesUsed = usedBytes / pageSize;
writer.Seek(0, SeekOrigin.Begin);
head.Write(writer, bits);
}
private void WriteDirectory(DataStream[] streams,
out int directoryRoot,
out int directorySize,
BitAccess bits) {
DataStream directory = new DataStream();
int pages = 0;
for (int s = 0; s < streams.Length; s++) {
if (streams[s].Length > 0) {
pages += streams[s].Pages;
}
}
int use = 4 * (1 + streams.Length + pages);
bits.MinCapacity(use);
bits.WriteInt32(streams.Length);
for (int s = 0; s < streams.Length; s++) {
bits.WriteInt32(streams[s].Length);
}
for (int s = 0; s < streams.Length; s++) {
if (streams[s].Length > 0) {
bits.WriteInt32(streams[s].pages);
}
}
directory.Write(this, bits.Buffer, use);
directorySize = directory.Length;
use = 4 * directory.Pages;
bits.MinCapacity(use);
bits.WriteInt32(directory.pages);
DataStream ddir = new DataStream();
ddir.Write(this, bits.Buffer, use);
directoryRoot = ddir.pages[0];
}
private void WriteFreeMap() {
byte[] buffer = new byte[pageSize];
// We configure the old free map with only the first 3 pages allocated.
buffer[0] = 0xf8;
for (int i = 1; i < pageSize; i++) {
buffer[i] = 0xff;
}
Seek(1, 0);
Write(buffer, 0, pageSize);
// We configure the new free map with all of the used pages gone.
int count = usedBytes / pageSize;
int full = count / 8;
for (int i = 0; i < full; i++) {
buffer[i] = 0;
}
int rema = count % 8;
buffer[full] = (byte)(0xff << rema);
Seek(2, 0);
Write(buffer, 0, pageSize);
}
internal int AllocatePages(int count) {
int begin = usedBytes;
usedBytes += count * pageSize;
writer.SetLength(usedBytes);
if (usedBytes > pageSize * pageSize * 8) {
throw new Exception("PdbWriter does not support multiple free maps.");
}
return begin / pageSize;
}
internal void Seek(int page, int offset) {
writer.Seek(page * pageSize + offset, SeekOrigin.Begin);
}
internal void Write(byte[] bytes, int offset, int count) {
writer.Write(bytes, offset, count);
}
//////////////////////////////////////////////////////////////////////
//
internal int PageSize {
get { return pageSize; }
}
//////////////////////////////////////////////////////////////////////
//
internal readonly int pageSize;
private Stream writer;
private int usedBytes;
}
}

33
Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs

@ -13,38 +13,6 @@ using System.Diagnostics.SymbolStore; @@ -13,38 +13,6 @@ using System.Diagnostics.SymbolStore;
namespace Microsoft.Cci {
internal sealed class UsedNamespace : IUsedNamespace {
internal UsedNamespace(IName alias, IName namespaceName) {
this.alias = alias;
this.namespaceName = namespaceName;
}
public IName Alias {
get { return this.alias; }
}
readonly IName alias;
public IName NamespaceName {
get { return this.namespaceName; }
}
readonly IName namespaceName;
}
internal class NamespaceScope : INamespaceScope {
internal NamespaceScope(IEnumerable<IUsedNamespace> usedNamespaces) {
this.usedNamespaces = usedNamespaces;
}
public IEnumerable<IUsedNamespace> UsedNamespaces {
get { return this.usedNamespaces; }
}
readonly IEnumerable<IUsedNamespace> usedNamespaces;
}
internal sealed class PdbIteratorScope : ILocalScope {
internal PdbIteratorScope(uint offset, uint length) {
@ -61,6 +29,5 @@ namespace Microsoft.Cci { @@ -61,6 +29,5 @@ namespace Microsoft.Cci {
get { return this.length; }
}
uint length;
}
}

3
Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
@ -108,7 +108,6 @@ @@ -108,7 +108,6 @@
<Compile Include="Microsoft.Cci.Pdb\PdbScope.cs" />
<Compile Include="Microsoft.Cci.Pdb\PdbSlot.cs" />
<Compile Include="Microsoft.Cci.Pdb\PdbSource.cs" />
<Compile Include="Microsoft.Cci.Pdb\PdbWriter.cs" />
<Compile Include="Microsoft.Cci.Pdb\SourceLocationProvider.cs" />
<Compile Include="Mono.Cecil.Pdb\AssemblyInfo.cs" />
<Compile Include="Mono.Cecil.Pdb\ISymUnmanagedDocumentWriter.cs" />

2
Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/AssemblyInfo.cs

@ -32,7 +32,7 @@ using System.Runtime.InteropServices; @@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Pdb")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2010 Jb Evain")]
[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]

101
Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/ModuleMetadata.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
@ -75,7 +76,7 @@ namespace Mono.Cecil.Pdb { @@ -75,7 +76,7 @@ namespace Mono.Cecil.Pdb {
uint FindTypeDefByName (string szTypeDef, uint tkEnclosingClass);
Guid GetScopeProps (StringBuilder szName, uint cchName, out uint pchName);
uint GetModuleFromScope ();
uint GetTypeDefProps (uint td, IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, ref uint pdwTypeDefFlags);
uint GetTypeDefProps (uint td, IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, IntPtr pdwTypeDefFlags);
uint GetInterfaceImplProps (uint iiImpl, out uint pClass);
uint GetTypeRefProps (uint tr, out uint ptkResolutionScope, StringBuilder szName, uint cchName);
uint ResolveTypeRef (uint tr, [In] ref Guid riid, [MarshalAs (UnmanagedType.Interface)] out object ppIScope);
@ -95,8 +96,7 @@ namespace Mono.Cecil.Pdb { @@ -95,8 +96,7 @@ namespace Mono.Cecil.Pdb {
uint FindMethod (uint td, string szName, [MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 3)] byte [] pvSigBlob, uint cbSigBlob);
uint FindField (uint td, string szName, [MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 3)] byte [] pvSigBlob, uint cbSigBlob);
uint FindMemberRef (uint td, string szName, [MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 3)] byte [] pvSigBlob, uint cbSigBlob);
uint GetMethodProps (uint mb, out uint pClass, IntPtr szMethod, uint cchMethod, out uint pchMethod, IntPtr pdwAttr,
IntPtr ppvSigBlob, IntPtr pcbSigBlob, IntPtr pulCodeRVA);
uint GetMethodProps (uint mb, out uint pClass, IntPtr szMethod, uint cchMethod, out uint pchMethod, IntPtr pdwAttr, IntPtr ppvSigBlob, IntPtr pcbSigBlob, IntPtr pulCodeRVA);
uint GetMemberRefProps (uint mr, ref uint ptk, StringBuilder szMember, uint cchMember, out uint pchMember, out IntPtr /* byte* */ ppvSigBlob);
uint EnumProperties (ref uint phEnum, uint td, IntPtr /* uint* */ rProperties, uint cMax);
uint EnumEvents (ref uint phEnum, uint td, IntPtr /* uint* */ rEvents, uint cMax);
@ -147,11 +147,47 @@ namespace Mono.Cecil.Pdb { @@ -147,11 +147,47 @@ namespace Mono.Cecil.Pdb {
readonly ModuleDefinition module;
Dictionary<uint, TypeDefinition> types;
Dictionary<uint, MethodDefinition> methods;
public ModuleMetadata (ModuleDefinition module)
{
this.module = module;
}
bool TryGetType (uint token, out TypeDefinition type)
{
if (types == null)
InitializeMetadata (module);
return types.TryGetValue (token, out type);
}
bool TryGetMethod (uint token, out MethodDefinition method)
{
if (methods == null)
InitializeMetadata (module);
return methods.TryGetValue (token, out method);
}
void InitializeMetadata (ModuleDefinition module)
{
types = new Dictionary<uint, TypeDefinition> ();
methods = new Dictionary<uint, MethodDefinition> ();
foreach (var type in module.GetTypes ()) {
types.Add (type.MetadataToken.ToUInt32 (), type);
InitializeMethods (type);
}
}
void InitializeMethods (TypeDefinition type)
{
foreach (var method in type.Methods)
methods.Add (method.MetadataToken.ToUInt32 (), method);
}
public void SetModuleProps (string szName)
{
throw new NotImplementedException ();
@ -442,10 +478,40 @@ namespace Mono.Cecil.Pdb { @@ -442,10 +478,40 @@ namespace Mono.Cecil.Pdb {
throw new NotImplementedException ();
}
public uint GetTypeDefProps (uint td, IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, ref uint pdwTypeDefFlags)
public uint GetTypeDefProps (uint td, IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, IntPtr pdwTypeDefFlags)
{
TypeDefinition type;
if (!TryGetType (td, out type)) {
Marshal.WriteInt16 (szTypeDef, 0);
pchTypeDef = 1;
return 0;
}
WriteString (type.Name, szTypeDef, cchTypeDef, out pchTypeDef);
WriteIntPtr (pdwTypeDefFlags, (uint) type.Attributes);
return type.BaseType != null ? type.BaseType.MetadataToken.ToUInt32 () : 0;
}
static void WriteIntPtr (IntPtr ptr, uint value)
{
pchTypeDef = 0;
return td;
if (ptr == IntPtr.Zero)
return;
Marshal.WriteInt32 (ptr, (int) value);
}
static void WriteString (string str, IntPtr buffer, uint bufferSize, out uint chars)
{
var length = str.Length + 1 >= bufferSize ? bufferSize - 1 : (uint) str.Length;
chars = length + 1;
var offset = 0;
for (int i = 0; i < length; i++) {
Marshal.WriteInt16 (buffer, offset, str [i]);
offset += 2;
}
Marshal.WriteInt16 (buffer, offset, 0);
}
public uint GetInterfaceImplProps (uint iiImpl, out uint pClass)
@ -535,9 +601,20 @@ namespace Mono.Cecil.Pdb { @@ -535,9 +601,20 @@ namespace Mono.Cecil.Pdb {
public uint GetMethodProps (uint mb, out uint pClass, IntPtr szMethod, uint cchMethod, out uint pchMethod, IntPtr pdwAttr, IntPtr ppvSigBlob, IntPtr pcbSigBlob, IntPtr pulCodeRVA)
{
pClass = 0;
pchMethod = 0;
return mb;
MethodDefinition method;
if (!TryGetMethod (mb, out method)) {
Marshal.WriteInt16 (szMethod, 0);
pchMethod = 1;
pClass = 0;
return 0;
}
pClass = method.DeclaringType.MetadataToken.ToUInt32 ();
WriteString (method.Name, szMethod, cchMethod, out pchMethod);
WriteIntPtr (pdwAttr, (uint) method.Attributes);
WriteIntPtr (pulCodeRVA, (uint) method.RVA);
return (uint) method.ImplAttributes;
}
public uint GetMemberRefProps (uint mr, ref uint ptk, StringBuilder szMember, uint cchMember, out uint pchMember, out IntPtr ppvSigBlob)
@ -697,7 +774,11 @@ namespace Mono.Cecil.Pdb { @@ -697,7 +774,11 @@ namespace Mono.Cecil.Pdb {
public uint GetNestedClassProps (uint tdNestedClass)
{
throw new NotImplementedException ();
TypeDefinition type;
if (!TryGetType (tdNestedClass, out type))
return 0;
return type.IsNested ? type.DeclaringType.MetadataToken.ToUInt32 () : 0;
}
public uint GetNativeCallConvFromSig (IntPtr pvSig, uint cbSig)

1
Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/PdbHelper.cs

@ -104,6 +104,7 @@ namespace Mono.Cecil.Pdb { @@ -104,6 +104,7 @@ namespace Mono.Cecil.Pdb {
AddMapping (DocumentLanguage.JScript, new Guid (0x3a12d0b6, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2));
AddMapping (DocumentLanguage.Smc, new Guid (0xd9b9f7b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x0, 0x0, 0xf8, 0x8, 0x49, 0xbd));
AddMapping (DocumentLanguage.MCpp, new Guid (0x4b35fde8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1));
AddMapping (DocumentLanguage.FSharp, new Guid (0xab4f38c9, 0xb6e6, 0x43ba, 0xbe, 0x3b, 0x58, 0x08, 0x0b, 0x2c, 0xcc, 0xe3));
}
static void AddMapping (DocumentLanguage language, Guid guid)

8
Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb/PdbReader.cs

@ -90,12 +90,8 @@ namespace Mono.Cecil.Pdb { @@ -90,12 +90,8 @@ namespace Mono.Cecil.Pdb {
Guid guid;
var funcs = PdbFile.LoadFunctions (pdb_file, true, out age, out guid);
if (this.age != 0) {
if (this.age != age)
return false;
if (this.guid != guid)
return false;
}
if (this.age != 0 && this.guid != guid)
return false;
foreach (PdbFunction function in funcs)
functions.Add (function.token, function);

16
Mono.Cecil/symbols/pdb/Test/Mono.Cecil.Pdb.Tests.csproj

@ -92,21 +92,25 @@ @@ -92,21 +92,25 @@
<Compile Include="Mono.Cecil.Tests\PdbTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\assemblies\fsapp.exe" />
<Content Include="Resources\assemblies\fsapp.pdb" />
<Content Include="Resources\assemblies\test.exe" />
<Content Include="Resources\assemblies\test.pdb" />
<Content Include="Resources\assemblies\VBConsApp.exe" />
<Content Include="Resources\assemblies\VBConsApp.pdb" />
</ItemGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.4.8\nunit.core.dll</HintPath>
<HintPath>..\..\..\Test\libs\nunit-2.5.10\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.core.interfaces, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.4.8\nunit.core.interfaces.dll</HintPath>
<HintPath>..\..\..\Test\libs\nunit-2.5.10\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.4.8\nunit.framework.dll</HintPath>
<HintPath>..\..\..\Test\libs\nunit-2.5.10\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

36
Mono.Cecil/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs

@ -76,6 +76,42 @@ namespace Mono.Cecil.Tests { @@ -76,6 +76,42 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
[TestModule ("VBConsApp.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))]
public void BasicDocument (ModuleDefinition module)
{
var type = module.GetType ("VBConsApp.Program");
var method = type.GetMethod ("Main");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\tmp\VBConsApp\Program.vb", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.Basic, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
[TestModule ("fsapp.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))]
public void FSharpDocument (ModuleDefinition module)
{
var type = module.GetType ("Program");
var method = type.GetMethod ("fact");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\tmp\fsapp\Program.fs", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.FSharp, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
[Test]
public void CreateMethodFromScratch ()
{

BIN
Mono.Cecil/symbols/pdb/Test/Resources/assemblies/VBConsApp.exe

Binary file not shown.

BIN
Mono.Cecil/symbols/pdb/Test/Resources/assemblies/VBConsApp.pdb

Binary file not shown.

BIN
Mono.Cecil/symbols/pdb/Test/Resources/assemblies/fsapp.exe

Binary file not shown.

BIN
Mono.Cecil/symbols/pdb/Test/Resources/assemblies/fsapp.pdb

Binary file not shown.
Loading…
Cancel
Save