From 12a948c37fd3687a51ee299598d8be642cd94672 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 27 Apr 2012 19:43:16 +0100 Subject: [PATCH] Switch Cecil to common git://github.com/mono/cecil.git --- .gitmodules | 3 + external/cecil | 1 + mcs/class/Mono.Cecil.Mdb/Makefile | 4 +- .../Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources | 14 +- .../Mono.Cecil.Mdb/AssemblyInfo.cs | 41 - .../Mono.Cecil.Mdb/MdbReader.cs | 213 -- .../Mono.Cecil.Mdb/MdbWriter.cs | 251 -- mcs/class/Mono.Cecil/.gitignore | 7 - mcs/class/Mono.Cecil/Mono.Cecil.Cil/Code.cs | 252 -- .../Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs | 598 ---- .../Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs | 649 ---- .../Mono.Cecil/Mono.Cecil.Cil/Document.cs | 112 - .../Mono.Cecil.Cil/ExceptionHandler.cs | 89 - .../Mono.Cecil/Mono.Cecil.Cil/ILProcessor.cs | 278 -- .../Mono.Cecil/Mono.Cecil.Cil/Instruction.cs | 321 -- .../Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs | 241 -- mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs | 455 --- .../Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs | 912 ----- .../Mono.Cecil.Cil/SequencePoint.cs | 70 - .../Mono.Cecil/Mono.Cecil.Cil/Symbols.cs | 277 -- .../Mono.Cecil.Cil/VariableDefinition.cs | 52 - .../Mono.Cecil.Cil/VariableReference.cs | 75 - .../Mono.Cecil.Metadata/BlobHeap.cs | 59 - .../Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs | 373 -- .../Mono.Cecil.Metadata/CodedIndex.cs | 46 - .../Mono.Cecil.Metadata/ElementType.cs | 73 - .../Mono.Cecil.Metadata/GuidHeap.cs | 59 - .../Mono.Cecil/Mono.Cecil.Metadata/Heap.cs | 48 - .../Mono.Cecil.Metadata/MetadataToken.cs | 105 - .../Mono.Cecil/Mono.Cecil.Metadata/Row.cs | 170 - .../Mono.Cecil.Metadata/StringHeap.cs | 81 - .../Mono.Cecil.Metadata/TableHeap.cs | 111 - .../Mono.Cecil.Metadata/TokenType.cs | 56 - .../Mono.Cecil.Metadata/UserStringHeap.cs | 59 - .../Mono.Cecil.Metadata/Utilities.cs | 529 --- .../Mono.Cecil.PE/BinaryStreamReader.cs | 51 - .../Mono.Cecil.PE/BinaryStreamWriter.cs | 96 - .../Mono.Cecil/Mono.Cecil.PE/ByteBuffer.cs | 359 -- .../ByteBufferEqualityComparer.cs | 78 - .../Mono.Cecil/Mono.Cecil.PE/DataDirectory.cs | 50 - mcs/class/Mono.Cecil/Mono.Cecil.PE/Image.cs | 160 - .../Mono.Cecil/Mono.Cecil.PE/ImageReader.cs | 679 ---- .../Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs | 823 ----- mcs/class/Mono.Cecil/Mono.Cecil.PE/Section.cs | 43 - mcs/class/Mono.Cecil/Mono.Cecil.PE/TextMap.cs | 129 - mcs/class/Mono.Cecil/Mono.Cecil.dll.sources | 254 +- mcs/class/Mono.Cecil/Mono.Cecil/ArrayType.cs | 159 - .../Mono.Cecil/AssemblyDefinition.cs | 189 - .../Mono.Cecil/Mono.Cecil/AssemblyFlags.cs | 42 - .../Mono.Cecil/AssemblyHashAlgorithm.cs | 36 - .../Mono.Cecil/Mono.Cecil/AssemblyInfo.cs | 49 - .../Mono.Cecil/AssemblyLinkedResource.cs | 57 - .../Mono.Cecil/AssemblyNameDefinition.cs | 50 - .../Mono.Cecil/AssemblyNameReference.cs | 268 -- .../Mono.Cecil/Mono.Cecil/AssemblyReader.cs | 3161 ----------------- .../Mono.Cecil/Mono.Cecil/AssemblyWriter.cs | 2571 -------------- .../Mono.Cecil/BaseAssemblyResolver.cs | 363 -- mcs/class/Mono.Cecil/Mono.Cecil/CallSite.cs | 124 - .../Mono.Cecil/Mono.Cecil/CustomAttribute.cs | 232 -- .../Mono.Cecil/DefaultAssemblyResolver.cs | 75 - .../Mono.Cecil/Mono.Cecil/EmbeddedResource.cs | 105 - .../Mono.Cecil/Mono.Cecil/EventAttributes.cs | 39 - .../Mono.Cecil/Mono.Cecil/EventDefinition.cs | 168 - .../Mono.Cecil/Mono.Cecil/EventReference.cs | 57 - .../Mono.Cecil/Mono.Cecil/ExportedType.cs | 249 -- .../Mono.Cecil/Mono.Cecil/FieldAttributes.cs | 59 - .../Mono.Cecil/Mono.Cecil/FieldDefinition.cs | 279 -- .../Mono.Cecil/Mono.Cecil/FieldReference.cs | 83 - .../Mono.Cecil/Mono.Cecil/FileAttributes.cs | 35 - .../Mono.Cecil/FunctionPointerType.cs | 128 - .../Mono.Cecil/GenericInstanceMethod.cs | 85 - .../Mono.Cecil/GenericInstanceType.cs | 83 - .../Mono.Cecil/Mono.Cecil/GenericParameter.cs | 277 -- .../Mono.Cecil/GenericParameterAttributes.cs | 45 - .../Mono.Cecil/IConstantProvider.cs | 52 - .../Mono.Cecil/ICustomAttributeProvider.cs | 60 - .../Mono.Cecil/Mono.Cecil/IGenericInstance.cs | 66 - .../Mono.Cecil/IGenericParameterProvider.cs | 73 - .../Mono.Cecil/IMarshalInfoProvider.cs | 55 - .../Mono.Cecil/IMemberDefinition.cs | 100 - .../Mono.Cecil/Mono.Cecil/IMetadataScope.cs | 41 - .../Mono.Cecil/IMetadataTokenProvider.cs | 35 - .../Mono.Cecil/Mono.Cecil/IMethodSignature.cs | 75 - mcs/class/Mono.Cecil/Mono.Cecil/Import.cs | 566 --- .../Mono.Cecil/Mono.Cecil/LinkedResource.cs | 60 - .../Mono.Cecil/ManifestResourceAttributes.cs | 39 - .../Mono.Cecil/Mono.Cecil/MarshalInfo.cs | 171 - .../Mono.Cecil/MemberDefinitionCollection.cs | 92 - .../Mono.Cecil/Mono.Cecil/MemberReference.cs | 101 - .../Mono.Cecil/Mono.Cecil/MetadataResolver.cs | 364 -- .../Mono.Cecil/Mono.Cecil/MetadataSystem.cs | 398 --- .../Mono.Cecil/Mono.Cecil/MethodAttributes.cs | 66 - .../Mono.Cecil/MethodCallingConvention.cs | 40 - .../Mono.Cecil/Mono.Cecil/MethodDefinition.cs | 487 --- .../Mono.Cecil/MethodImplAttributes.cs | 53 - .../Mono.Cecil/Mono.Cecil/MethodReference.cs | 214 -- .../Mono.Cecil/Mono.Cecil/MethodReturnType.cs | 104 - .../Mono.Cecil/MethodSemanticsAttributes.cs | 43 - .../Mono.Cecil/MethodSpecification.cs | 103 - mcs/class/Mono.Cecil/Mono.Cecil/Modifiers.cs | 137 - .../Mono.Cecil/Mono.Cecil/ModuleDefinition.cs | 1048 ------ mcs/class/Mono.Cecil/Mono.Cecil/ModuleKind.cs | 54 - .../Mono.Cecil/Mono.Cecil/ModuleReference.cs | 67 - mcs/class/Mono.Cecil/Mono.Cecil/NativeType.cs | 73 - .../Mono.Cecil/PInvokeAttributes.cs | 62 - .../Mono.Cecil/Mono.Cecil/PInvokeInfo.cs | 138 - .../Mono.Cecil/ParameterAttributes.cs | 45 - .../Mono.Cecil/ParameterDefinition.cs | 172 - .../ParameterDefinitionCollection.cs | 80 - .../Mono.Cecil/ParameterReference.cs | 75 - mcs/class/Mono.Cecil/Mono.Cecil/PinnedType.cs | 53 - .../Mono.Cecil/Mono.Cecil/PointerType.cs | 61 - .../Mono.Cecil/PropertyAttributes.cs | 41 - .../Mono.Cecil/PropertyDefinition.cs | 265 -- .../Mono.Cecil/PropertyReference.cs | 59 - .../Mono.Cecil/Mono.Cecil/ReferenceType.cs | 61 - mcs/class/Mono.Cecil/Mono.Cecil/Resource.cs | 76 - .../Mono.Cecil/SecurityDeclaration.cs | 191 - .../Mono.Cecil/Mono.Cecil/SentinelType.cs | 53 - .../Mono.Cecil/Mono.Cecil/TargetRuntime.cs | 37 - .../Mono.Cecil/Mono.Cecil/TypeAttributes.cs | 81 - .../Mono.Cecil/Mono.Cecil/TypeDefinition.cs | 517 --- .../Mono.Cecil/TypeDefinitionCollection.cs | 118 - mcs/class/Mono.Cecil/Mono.Cecil/TypeParser.cs | 555 --- .../Mono.Cecil/Mono.Cecil/TypeReference.cs | 330 -- .../Mono.Cecil/TypeSpecification.cs | 94 - mcs/class/Mono.Cecil/Mono.Cecil/TypeSystem.cs | 265 -- .../Mono.Cecil/Mono.Cecil/VariantType.cs | 53 - .../Mono.Collections.Generic/Collection.cs | 420 --- .../ReadOnlyCollection.cs | 112 - .../CryptoConvert.cs | 243 -- .../CryptoService.cs | 177 - mcs/class/Mono.Cecil/Mono/Actions.cs | 38 - mcs/class/Mono.Cecil/Mono/Empty.cs | 53 - mcs/class/Mono.Cecil/Mono/Funcs.cs | 39 - mcs/class/Mono.Cecil/NOTES.txt | 189 - mcs/class/Mono.Cecil/README | 15 - .../ExtensionAttribute.cs | 40 - mcs/class/Mono.Cecil/mono.snk | Bin 596 -> 0 bytes mcs/class/Mono.Cecil/revision | 1 - mcs/class/Mono.Cecil/update.rb | 40 - 141 files changed, 139 insertions(+), 28021 deletions(-) create mode 160000 external/cecil delete mode 100644 mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs delete mode 100644 mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs delete mode 100644 mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs delete mode 100644 mcs/class/Mono.Cecil/.gitignore delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/Code.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/Document.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/ILProcessor.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/Symbols.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Heap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Row.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/StringHeap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TableHeap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/UserStringHeap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamReader.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamWriter.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBuffer.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/DataDirectory.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/Image.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageReader.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/Section.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil.PE/TextMap.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ArrayType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyReader.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/AssemblyWriter.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/CallSite.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/CustomAttribute.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/EventAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/EventDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/EventReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ExportedType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/FieldAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/FieldDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/FieldReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/FileAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/GenericParameter.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IConstantProvider.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IGenericInstance.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IMetadataScope.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/IMethodSignature.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/Import.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/LinkedResource.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MarshalInfo.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MemberDefinitionCollection.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MemberReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MetadataResolver.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MetadataSystem.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodReturnType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/MethodSpecification.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/Modifiers.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ModuleKind.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ModuleReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/NativeType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ParameterReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PinnedType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PointerType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/PropertyReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/ReferenceType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/Resource.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/SentinelType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TargetRuntime.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeAttributes.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinition.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeParser.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeSpecification.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/TypeSystem.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Cecil/VariantType.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Collections.Generic/Collection.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Collections.Generic/ReadOnlyCollection.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoConvert.cs delete mode 100644 mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoService.cs delete mode 100644 mcs/class/Mono.Cecil/Mono/Actions.cs delete mode 100644 mcs/class/Mono.Cecil/Mono/Empty.cs delete mode 100644 mcs/class/Mono.Cecil/Mono/Funcs.cs delete mode 100644 mcs/class/Mono.Cecil/NOTES.txt delete mode 100644 mcs/class/Mono.Cecil/README delete mode 100644 mcs/class/Mono.Cecil/System.Runtime.CompilerServices/ExtensionAttribute.cs delete mode 100644 mcs/class/Mono.Cecil/mono.snk delete mode 100644 mcs/class/Mono.Cecil/revision delete mode 100644 mcs/class/Mono.Cecil/update.rb diff --git a/.gitmodules b/.gitmodules index 4f2410a17ec..aeab4b96e65 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "external/Newtonsoft.Json"] path = external/Newtonsoft.Json url = git://github.com/mono/Newtonsoft.Json.git +[submodule "external/cecil"] + path = external/cecil + url = git://github.com/mono/cecil.git diff --git a/external/cecil b/external/cecil new file mode 160000 index 00000000000..54e0a50464e --- /dev/null +++ b/external/cecil @@ -0,0 +1 @@ +Subproject commit 54e0a50464edbc254b39ea3c885ee91ada730705 diff --git a/mcs/class/Mono.Cecil.Mdb/Makefile b/mcs/class/Mono.Cecil.Mdb/Makefile index ecb9bb41d83..58d527dfed4 100644 --- a/mcs/class/Mono.Cecil.Mdb/Makefile +++ b/mcs/class/Mono.Cecil.Mdb/Makefile @@ -5,9 +5,7 @@ LIBRARY = Mono.Cecil.Mdb.dll LIBRARY_SNK = ../mono.snk LIBRARY_PACKAGE = none -CECIL = $(topdir)/class/lib/$(PROFILE)/Mono.Cecil.dll - -LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:$(CECIL) /d:CECIL -keyfile:$(LIBRARY_SNK) +LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:Mono.Cecil.dll /d:CECIL -keyfile:$(LIBRARY_SNK) NO_TEST = yes diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources index 0cd3f087cca..eedadff94e7 100644 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources +++ b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources @@ -1,7 +1,7 @@ -./Mono.Cecil.Mdb/AssemblyInfo.cs -./Mono.Cecil.Mdb/MdbReader.cs -./Mono.Cecil.Mdb/MdbWriter.cs -../Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs -../Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs -../Mono.CompilerServices.SymbolWriter/MonoSymbolWriter.cs -../Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs +../../../external/cecil/symbols/mdb/Mono.Cecil.Mdb/AssemblyInfo.cs +../../../external/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs +../../../external/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbWriter.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolWriter.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/SymbolWriterImpl.cs diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs deleted file mode 100644 index 8186b506bc6..00000000000 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// AssemblyInfo.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle ("Mono.Cecil.Mdb")] -[assembly: AssemblyProduct ("Mono.Cecil")] -[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")] - -[assembly: CLSCompliant (false)] -[assembly: ComVisible (false)] - -[assembly: AssemblyVersion ("0.9.5.0")] -[assembly: AssemblyFileVersion ("0.9.5.0")] diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs deleted file mode 100644 index 7f5d640c8ee..00000000000 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs +++ /dev/null @@ -1,213 +0,0 @@ -// -// MdbReader.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; - -using Mono.Cecil.Cil; -using Mono.Collections.Generic; -using Mono.CompilerServices.SymbolWriter; - -namespace Mono.Cecil.Mdb { - - public class MdbReaderProvider : ISymbolReaderProvider { - - public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName) - { - return new MdbReader (MonoSymbolFile.ReadSymbolFile (fileName + ".mdb", module.Mvid)); - } - - public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream) - { - throw new NotImplementedException (); - } - } - - public class MdbReader : ISymbolReader { - - readonly MonoSymbolFile symbol_file; - readonly Dictionary documents; - - public MdbReader (MonoSymbolFile symFile) - { - symbol_file = symFile; - documents = new Dictionary (); - } - - public bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header) - { - return true; - } - - public void Read (MethodBody body, InstructionMapper mapper) - { - var method_token = body.Method.MetadataToken; - var entry = symbol_file.GetMethodByToken (method_token.ToInt32 ()); - if (entry == null) - return; - - var scopes = ReadScopes (entry, body, mapper); - ReadLineNumbers (entry, mapper); - ReadLocalVariables (entry, body, scopes); - } - - static void ReadLocalVariables (MethodEntry entry, MethodBody body, Scope [] scopes) - { - var locals = entry.GetLocals (); - foreach (var local in locals) { - var variable = body.Variables [local.Index]; - variable.Name = local.Name; - - var index = local.BlockIndex; - if (index < 0 || index >= scopes.Length) - continue; - - var scope = scopes [index]; - if (scope == null) - continue; - - scope.Variables.Add (variable); - } - } - - void ReadLineNumbers (MethodEntry entry, InstructionMapper mapper) - { - Document document = null; - var table = entry.GetLineNumberTable (); - - foreach (var line in table.LineNumbers) { - var instruction = mapper (line.Offset); - if (instruction == null) - continue; - - if (document == null) - document = GetDocument (entry.CompileUnit.SourceFile); - - instruction.SequencePoint = new SequencePoint (document) { - StartLine = line.Row, - EndLine = line.Row, - }; - } - } - - Document GetDocument (SourceFileEntry file) - { - var file_name = file.FileName; - - Document document; - if (documents.TryGetValue (file_name, out document)) - return document; - - document = new Document (file_name); - documents.Add (file_name, document); - - return document; - } - - static Scope [] ReadScopes (MethodEntry entry, MethodBody body, InstructionMapper mapper) - { - var blocks = entry.GetCodeBlocks (); - var scopes = new Scope [blocks.Length]; - - foreach (var block in blocks) { - if (block.BlockType != CodeBlockEntry.Type.Lexical) - continue; - - var scope = new Scope (); - scope.Start = mapper (block.StartOffset); - scope.End = mapper (block.EndOffset); - - scopes [block.Index] = scope; - - if (body.Scope == null) - body.Scope = scope; - - if (!AddScope (body.Scope, scope)) - body.Scope = scope; - } - - return scopes; - } - - static bool AddScope (Scope provider, Scope scope) - { - foreach (var sub_scope in provider.Scopes) { - if (AddScope (sub_scope, scope)) - return true; - - if (scope.Start.Offset >= sub_scope.Start.Offset && scope.End.Offset <= sub_scope.End.Offset) { - sub_scope.Scopes.Add (scope); - return true; - } - } - - return false; - } - - public void Read (MethodSymbols symbols) - { - var entry = symbol_file.GetMethodByToken (symbols.MethodToken.ToInt32 ()); - if (entry == null) - return; - - ReadLineNumbers (entry, symbols); - ReadLocalVariables (entry, symbols); - } - - void ReadLineNumbers (MethodEntry entry, MethodSymbols symbols) - { - var table = entry.GetLineNumberTable (); - var lines = table.LineNumbers; - - var instructions = symbols.instructions = new Collection (lines.Length); - - for (int i = 0; i < lines.Length; i++) { - var line = lines [i]; - - instructions.Add (new InstructionSymbol (line.Offset, new SequencePoint (GetDocument (entry.CompileUnit.SourceFile)) { - StartLine = line.Row, - EndLine = line.Row, - })); - } - } - - static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols) - { - foreach (var local in entry.GetLocals ()) { - var variable = symbols.Variables [local.Index]; - variable.Name = local.Name; - } - } - - public void Dispose () - { - symbol_file.Dispose (); - } - } -} diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs deleted file mode 100644 index 6f4aa20e390..00000000000 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs +++ /dev/null @@ -1,251 +0,0 @@ -// -// MdbWriter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; - -using Mono.Cecil.Cil; -using Mono.Collections.Generic; -using Mono.CompilerServices.SymbolWriter; - -namespace Mono.Cecil.Mdb { - -#if !READ_ONLY - public class MdbWriterProvider : ISymbolWriterProvider { - - public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName) - { - return new MdbWriter (module.Mvid, fileName); - } - - public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream) - { - throw new NotImplementedException (); - } - } - - public class MdbWriter : ISymbolWriter { - - readonly Guid mvid; - readonly MonoSymbolWriter writer; - readonly Dictionary source_files; - - public MdbWriter (Guid mvid, string assembly) - { - this.mvid = mvid; - this.writer = new MonoSymbolWriter (assembly); - this.source_files = new Dictionary (); - } - - static Collection GetInstructions (MethodBody body) - { - var instructions = new Collection (); - foreach (var instruction in body.Instructions) - if (instruction.SequencePoint != null) - instructions.Add (instruction); - - return instructions; - } - - SourceFile GetSourceFile (Document document) - { - var url = document.Url; - - SourceFile source_file; - if (source_files.TryGetValue (url, out source_file)) - return source_file; - - var entry = writer.DefineDocument (url); - var compile_unit = writer.DefineCompilationUnit (entry); - - source_file = new SourceFile (compile_unit, entry); - source_files.Add (url, source_file); - return source_file; - } - - void Populate (Collection instructions, int [] offsets, - int [] startRows, int [] startCols, out SourceFile file) - { - SourceFile source_file = null; - - for (int i = 0; i < instructions.Count; i++) { - var instruction = instructions [i]; - offsets [i] = instruction.Offset; - - var sequence_point = instruction.SequencePoint; - if (source_file == null) - source_file = GetSourceFile (sequence_point.Document); - - startRows [i] = sequence_point.StartLine; - startCols [i] = sequence_point.StartColumn; - } - - file = source_file; - } - - public void Write (MethodBody body) - { - var method = new SourceMethod (body.Method); - - var instructions = GetInstructions (body); - int count = instructions.Count; - if (count == 0) - return; - - var offsets = new int [count]; - var start_rows = new int [count]; - var start_cols = new int [count]; - - SourceFile file; - Populate (instructions, offsets, start_rows, start_cols, out file); - - var builder = writer.OpenMethod (file.CompilationUnit, 0, method); - - for (int i = 0; i < count; i++) - builder.MarkSequencePoint ( - offsets [i], - file.CompilationUnit.SourceFile, - start_rows [i], - start_cols [i], - false); - - if (body.HasVariables) - AddVariables (body.Variables); - - writer.CloseMethod (); - } - - readonly static byte [] empty_header = new byte [0]; - - public bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header) - { - directory = new ImageDebugDirectory (); - header = empty_header; - return false; - } - - void AddVariables (IList variables) - { - for (int i = 0; i < variables.Count; i++) { - var variable = variables [i]; - writer.DefineLocalVariable (i, variable.Name); - } - } - - public void Write (MethodSymbols symbols) - { - var method = new SourceMethodSymbol (symbols); - - var file = GetSourceFile (symbols.Instructions [0].SequencePoint.Document); - var builder = writer.OpenMethod (file.CompilationUnit, 0, method); - var count = symbols.Instructions.Count; - - for (int i = 0; i < count; i++) { - var instruction = symbols.Instructions [i]; - var sequence_point = instruction.SequencePoint; - - builder.MarkSequencePoint ( - instruction.Offset, - GetSourceFile (sequence_point.Document).CompilationUnit.SourceFile, - sequence_point.StartLine, - sequence_point.EndLine, - false); - } - - if (symbols.HasVariables) - AddVariables (symbols.Variables); - - writer.CloseMethod (); - } - - public void Dispose () - { - writer.WriteSymbolFile (mvid); - } - - class SourceFile : ISourceFile { - - readonly CompileUnitEntry compilation_unit; - readonly SourceFileEntry entry; - - public SourceFileEntry Entry { - get { return entry; } - } - - public CompileUnitEntry CompilationUnit { - get { return compilation_unit; } - } - - public SourceFile (CompileUnitEntry comp_unit, SourceFileEntry entry) - { - this.compilation_unit = comp_unit; - this.entry = entry; - } - } - - class SourceMethodSymbol : IMethodDef { - - readonly string name; - readonly int token; - - public string Name { - get { return name;} - } - - public int Token { - get { return token; } - } - - public SourceMethodSymbol (MethodSymbols symbols) - { - name = symbols.MethodName; - token = symbols.MethodToken.ToInt32 (); - } - } - - class SourceMethod : IMethodDef { - - readonly MethodDefinition method; - - public string Name { - get { return method.Name; } - } - - public int Token { - get { return method.MetadataToken.ToInt32 (); } - } - - public SourceMethod (MethodDefinition method) - { - this.method = method; - } - } - } -#endif -} diff --git a/mcs/class/Mono.Cecil/.gitignore b/mcs/class/Mono.Cecil/.gitignore deleted file mode 100644 index 3629e370c51..00000000000 --- a/mcs/class/Mono.Cecil/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -bin -obj -*.suo -*.user -*.pidb -*.userprefs -*.xml diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Code.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Code.cs deleted file mode 100644 index fa88b63d67e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Code.cs +++ /dev/null @@ -1,252 +0,0 @@ -// -// Code.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public enum Code { - Nop, - Break, - Ldarg_0, - Ldarg_1, - Ldarg_2, - Ldarg_3, - Ldloc_0, - Ldloc_1, - Ldloc_2, - Ldloc_3, - Stloc_0, - Stloc_1, - Stloc_2, - Stloc_3, - Ldarg_S, - Ldarga_S, - Starg_S, - Ldloc_S, - Ldloca_S, - Stloc_S, - Ldnull, - Ldc_I4_M1, - Ldc_I4_0, - Ldc_I4_1, - Ldc_I4_2, - Ldc_I4_3, - Ldc_I4_4, - Ldc_I4_5, - Ldc_I4_6, - Ldc_I4_7, - Ldc_I4_8, - Ldc_I4_S, - Ldc_I4, - Ldc_I8, - Ldc_R4, - Ldc_R8, - Dup, - Pop, - Jmp, - Call, - Calli, - Ret, - Br_S, - Brfalse_S, - Brtrue_S, - Beq_S, - Bge_S, - Bgt_S, - Ble_S, - Blt_S, - Bne_Un_S, - Bge_Un_S, - Bgt_Un_S, - Ble_Un_S, - Blt_Un_S, - Br, - Brfalse, - Brtrue, - Beq, - Bge, - Bgt, - Ble, - Blt, - Bne_Un, - Bge_Un, - Bgt_Un, - Ble_Un, - Blt_Un, - Switch, - Ldind_I1, - Ldind_U1, - Ldind_I2, - Ldind_U2, - Ldind_I4, - Ldind_U4, - Ldind_I8, - Ldind_I, - Ldind_R4, - Ldind_R8, - Ldind_Ref, - Stind_Ref, - Stind_I1, - Stind_I2, - Stind_I4, - Stind_I8, - Stind_R4, - Stind_R8, - Add, - Sub, - Mul, - Div, - Div_Un, - Rem, - Rem_Un, - And, - Or, - Xor, - Shl, - Shr, - Shr_Un, - Neg, - Not, - Conv_I1, - Conv_I2, - Conv_I4, - Conv_I8, - Conv_R4, - Conv_R8, - Conv_U4, - Conv_U8, - Callvirt, - Cpobj, - Ldobj, - Ldstr, - Newobj, - Castclass, - Isinst, - Conv_R_Un, - Unbox, - Throw, - Ldfld, - Ldflda, - Stfld, - Ldsfld, - Ldsflda, - Stsfld, - Stobj, - Conv_Ovf_I1_Un, - Conv_Ovf_I2_Un, - Conv_Ovf_I4_Un, - Conv_Ovf_I8_Un, - Conv_Ovf_U1_Un, - Conv_Ovf_U2_Un, - Conv_Ovf_U4_Un, - Conv_Ovf_U8_Un, - Conv_Ovf_I_Un, - Conv_Ovf_U_Un, - Box, - Newarr, - Ldlen, - Ldelema, - Ldelem_I1, - Ldelem_U1, - Ldelem_I2, - Ldelem_U2, - Ldelem_I4, - Ldelem_U4, - Ldelem_I8, - Ldelem_I, - Ldelem_R4, - Ldelem_R8, - Ldelem_Ref, - Stelem_I, - Stelem_I1, - Stelem_I2, - Stelem_I4, - Stelem_I8, - Stelem_R4, - Stelem_R8, - Stelem_Ref, - Ldelem_Any, - Stelem_Any, - Unbox_Any, - Conv_Ovf_I1, - Conv_Ovf_U1, - Conv_Ovf_I2, - Conv_Ovf_U2, - Conv_Ovf_I4, - Conv_Ovf_U4, - Conv_Ovf_I8, - Conv_Ovf_U8, - Refanyval, - Ckfinite, - Mkrefany, - Ldtoken, - Conv_U2, - Conv_U1, - Conv_I, - Conv_Ovf_I, - Conv_Ovf_U, - Add_Ovf, - Add_Ovf_Un, - Mul_Ovf, - Mul_Ovf_Un, - Sub_Ovf, - Sub_Ovf_Un, - Endfinally, - Leave, - Leave_S, - Stind_I, - Conv_U, - Arglist, - Ceq, - Cgt, - Cgt_Un, - Clt, - Clt_Un, - Ldftn, - Ldvirtftn, - Ldarg, - Ldarga, - Starg, - Ldloc, - Ldloca, - Stloc, - Localloc, - Endfilter, - Unaligned, - Volatile, - Tail, - Initobj, - Constrained, - Cpblk, - Initblk, - No, - Rethrow, - Sizeof, - Refanytype, - Readonly, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs deleted file mode 100644 index 12ca5a23b11..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs +++ /dev/null @@ -1,598 +0,0 @@ -// -// CodeReader.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.PE; -using Mono.Collections.Generic; - -using RVA = System.UInt32; - -namespace Mono.Cecil.Cil { - - sealed class CodeReader : ByteBuffer { - - readonly internal MetadataReader reader; - - int start; - Section code_section; - - MethodDefinition method; - MethodBody body; - - int Offset { - get { return base.position - start; } - } - - public CodeReader (Section section, MetadataReader reader) - : base (section.Data) - { - this.code_section = section; - this.reader = reader; - } - - public MethodBody ReadMethodBody (MethodDefinition method) - { - this.method = method; - this.body = new MethodBody (method); - - reader.context = method; - - ReadMethodBody (); - - return this.body; - } - - public void MoveTo (int rva) - { - if (!IsInSection (rva)) { - code_section = reader.image.GetSectionAtVirtualAddress ((uint) rva); - Reset (code_section.Data); - } - - base.position = rva - (int) code_section.VirtualAddress; - } - - bool IsInSection (int rva) - { - return code_section.VirtualAddress <= rva && rva < code_section.VirtualAddress + code_section.SizeOfRawData; - } - - void ReadMethodBody () - { - MoveTo (method.RVA); - - var flags = ReadByte (); - switch (flags & 0x3) { - case 0x2: // tiny - body.code_size = flags >> 2; - body.MaxStackSize = 8; - ReadCode (); - break; - case 0x3: // fat - base.position--; - ReadFatMethod (); - break; - default: - throw new InvalidOperationException (); - } - - var symbol_reader = reader.module.symbol_reader; - - if (symbol_reader != null) { - var instructions = body.Instructions; - symbol_reader.Read (body, offset => GetInstruction (instructions, offset)); - } - } - - void ReadFatMethod () - { - var flags = ReadUInt16 (); - body.max_stack_size = ReadUInt16 (); - body.code_size = (int) ReadUInt32 (); - body.local_var_token = new MetadataToken (ReadUInt32 ()); - body.init_locals = (flags & 0x10) != 0; - - if (body.local_var_token.RID != 0) - body.variables = ReadVariables (body.local_var_token); - - ReadCode (); - - if ((flags & 0x8) != 0) - ReadSection (); - } - - public VariableDefinitionCollection ReadVariables (MetadataToken local_var_token) - { - var position = reader.position; - var variables = reader.ReadVariables (local_var_token); - reader.position = position; - - return variables; - } - - void ReadCode () - { - start = position; - var code_size = body.code_size; - - if (code_size < 0 || buffer.Length <= (uint) (code_size + position)) - code_size = 0; - - var end = start + code_size; - var instructions = body.instructions = new InstructionCollection ((code_size + 1) / 2); - - while (position < end) { - var offset = base.position - start; - var opcode = ReadOpCode (); - var current = new Instruction (offset, opcode); - - if (opcode.OperandType != OperandType.InlineNone) - current.operand = ReadOperand (current); - - instructions.Add (current); - } - - ResolveBranches (instructions); - } - - OpCode ReadOpCode () - { - var il_opcode = ReadByte (); - return il_opcode != 0xfe - ? OpCodes.OneByteOpCode [il_opcode] - : OpCodes.TwoBytesOpCode [ReadByte ()]; - } - - object ReadOperand (Instruction instruction) - { - switch (instruction.opcode.OperandType) { - case OperandType.InlineSwitch: - var length = ReadInt32 (); - var base_offset = Offset + (4 * length); - var branches = new int [length]; - for (int i = 0; i < length; i++) - branches [i] = base_offset + ReadInt32 (); - return branches; - case OperandType.ShortInlineBrTarget: - return ReadSByte () + Offset; - case OperandType.InlineBrTarget: - return ReadInt32 () + Offset; - case OperandType.ShortInlineI: - if (instruction.opcode == OpCodes.Ldc_I4_S) - return ReadSByte (); - - return ReadByte (); - case OperandType.InlineI: - return ReadInt32 (); - case OperandType.ShortInlineR: - return ReadSingle (); - case OperandType.InlineR: - return ReadDouble (); - case OperandType.InlineI8: - return ReadInt64 (); - case OperandType.ShortInlineVar: - return GetVariable (ReadByte ()); - case OperandType.InlineVar: - return GetVariable (ReadUInt16 ()); - case OperandType.ShortInlineArg: - return GetParameter (ReadByte ()); - case OperandType.InlineArg: - return GetParameter (ReadUInt16 ()); - case OperandType.InlineSig: - return GetCallSite (ReadToken ()); - case OperandType.InlineString: - return GetString (ReadToken ()); - case OperandType.InlineTok: - case OperandType.InlineType: - case OperandType.InlineMethod: - case OperandType.InlineField: - return reader.LookupToken (ReadToken ()); - default: - throw new NotSupportedException (); - } - } - - public string GetString (MetadataToken token) - { - return reader.image.UserStringHeap.Read (token.RID); - } - - public ParameterDefinition GetParameter (int index) - { - return body.GetParameter (index); - } - - public VariableDefinition GetVariable (int index) - { - return body.GetVariable (index); - } - - public CallSite GetCallSite (MetadataToken token) - { - return reader.ReadCallSite (token); - } - - void ResolveBranches (Collection instructions) - { - var items = instructions.items; - var size = instructions.size; - - for (int i = 0; i < size; i++) { - var instruction = items [i]; - switch (instruction.opcode.OperandType) { - case OperandType.ShortInlineBrTarget: - case OperandType.InlineBrTarget: - instruction.operand = GetInstruction ((int) instruction.operand); - break; - case OperandType.InlineSwitch: - var offsets = (int []) instruction.operand; - var branches = new Instruction [offsets.Length]; - for (int j = 0; j < offsets.Length; j++) - branches [j] = GetInstruction (offsets [j]); - - instruction.operand = branches; - break; - } - } - } - - Instruction GetInstruction (int offset) - { - return GetInstruction (body.Instructions, offset); - } - - static Instruction GetInstruction (Collection instructions, int offset) - { - var size = instructions.size; - var items = instructions.items; - if (offset < 0 || offset > items [size - 1].offset) - return null; - - int min = 0; - int max = size - 1; - while (min <= max) { - int mid = min + ((max - min) / 2); - var instruction = items [mid]; - var instruction_offset = instruction.offset; - - if (offset == instruction_offset) - return instruction; - - if (offset < instruction_offset) - max = mid - 1; - else - min = mid + 1; - } - - return null; - } - - void ReadSection () - { - Align (4); - - const byte fat_format = 0x40; - const byte more_sects = 0x80; - - var flags = ReadByte (); - if ((flags & fat_format) == 0) - ReadSmallSection (); - else - ReadFatSection (); - - if ((flags & more_sects) != 0) - ReadSection (); - } - - void ReadSmallSection () - { - var count = ReadByte () / 12; - Advance (2); - - ReadExceptionHandlers ( - count, - () => (int) ReadUInt16 (), - () => (int) ReadByte ()); - } - - void ReadFatSection () - { - position--; - var count = (ReadInt32 () >> 8) / 24; - - ReadExceptionHandlers ( - count, - ReadInt32, - ReadInt32); - } - - // inline ? - void ReadExceptionHandlers (int count, Func read_entry, Func read_length) - { - for (int i = 0; i < count; i++) { - var handler = new ExceptionHandler ( - (ExceptionHandlerType) (read_entry () & 0x7)); - - handler.TryStart = GetInstruction (read_entry ()); - handler.TryEnd = GetInstruction (handler.TryStart.Offset + read_length ()); - - handler.HandlerStart = GetInstruction (read_entry ()); - handler.HandlerEnd = GetInstruction (handler.HandlerStart.Offset + read_length ()); - - ReadExceptionHandlerSpecific (handler); - - this.body.ExceptionHandlers.Add (handler); - } - } - - void ReadExceptionHandlerSpecific (ExceptionHandler handler) - { - switch (handler.HandlerType) { - case ExceptionHandlerType.Catch: - handler.CatchType = (TypeReference) reader.LookupToken (ReadToken ()); - break; - case ExceptionHandlerType.Filter: - handler.FilterStart = GetInstruction (ReadInt32 ()); - break; - default: - Advance (4); - break; - } - } - - void Align (int align) - { - align--; - Advance (((position + align) & ~align) - position); - } - - public MetadataToken ReadToken () - { - return new MetadataToken (ReadUInt32 ()); - } - -#if !READ_ONLY - - public ByteBuffer PatchRawMethodBody (MethodDefinition method, CodeWriter writer, out MethodSymbols symbols) - { - var buffer = new ByteBuffer (); - symbols = new MethodSymbols (method.Name); - - this.method = method; - reader.context = method; - - MoveTo (method.RVA); - - var flags = ReadByte (); - - MetadataToken local_var_token; - - switch (flags & 0x3) { - case 0x2: // tiny - buffer.WriteByte (flags); - local_var_token = MetadataToken.Zero; - symbols.code_size = flags >> 2; - PatchRawCode (buffer, symbols.code_size, writer); - break; - case 0x3: // fat - base.position--; - - PatchRawFatMethod (buffer, symbols, writer, out local_var_token); - break; - default: - throw new NotSupportedException (); - } - - var symbol_reader = reader.module.symbol_reader; - if (symbol_reader != null && writer.metadata.write_symbols) { - symbols.method_token = GetOriginalToken (writer.metadata, method); - symbols.local_var_token = local_var_token; - symbol_reader.Read (symbols); - } - - return buffer; - } - - void PatchRawFatMethod (ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token) - { - var flags = ReadUInt16 (); - buffer.WriteUInt16 (flags); - buffer.WriteUInt16 (ReadUInt16 ()); - symbols.code_size = ReadInt32 (); - buffer.WriteInt32 (symbols.code_size); - local_var_token = ReadToken (); - - if (local_var_token.RID > 0) { - var variables = symbols.variables = ReadVariables (local_var_token); - buffer.WriteUInt32 (variables != null - ? writer.GetStandAloneSignature (symbols.variables).ToUInt32 () - : 0); - } else - buffer.WriteUInt32 (0); - - PatchRawCode (buffer, symbols.code_size, writer); - - if ((flags & 0x8) != 0) - PatchRawSection (buffer, writer.metadata); - } - - static MetadataToken GetOriginalToken (MetadataBuilder metadata, MethodDefinition method) - { - MetadataToken original; - if (metadata.TryGetOriginalMethodToken (method.token, out original)) - return original; - - return MetadataToken.Zero; - } - - void PatchRawCode (ByteBuffer buffer, int code_size, CodeWriter writer) - { - var metadata = writer.metadata; - buffer.WriteBytes (ReadBytes (code_size)); - var end = buffer.position; - buffer.position -= code_size; - - while (buffer.position < end) { - OpCode opcode; - var il_opcode = buffer.ReadByte (); - if (il_opcode != 0xfe) { - opcode = OpCodes.OneByteOpCode [il_opcode]; - } else { - var il_opcode2 = buffer.ReadByte (); - opcode = OpCodes.TwoBytesOpCode [il_opcode2]; - } - - switch (opcode.OperandType) { - case OperandType.ShortInlineI: - case OperandType.ShortInlineBrTarget: - case OperandType.ShortInlineVar: - case OperandType.ShortInlineArg: - buffer.position += 1; - break; - case OperandType.InlineVar: - case OperandType.InlineArg: - buffer.position += 2; - break; - case OperandType.InlineBrTarget: - case OperandType.ShortInlineR: - case OperandType.InlineI: - buffer.position += 4; - break; - case OperandType.InlineI8: - case OperandType.InlineR: - buffer.position += 8; - break; - case OperandType.InlineSwitch: - var length = buffer.ReadInt32 (); - buffer.position += length * 4; - break; - case OperandType.InlineString: - var @string = GetString (new MetadataToken (buffer.ReadUInt32 ())); - buffer.position -= 4; - buffer.WriteUInt32 ( - new MetadataToken ( - TokenType.String, - metadata.user_string_heap.GetStringIndex (@string)).ToUInt32 ()); - break; - case OperandType.InlineSig: - var call_site = GetCallSite (new MetadataToken (buffer.ReadUInt32 ())); - buffer.position -= 4; - buffer.WriteUInt32 (writer.GetStandAloneSignature (call_site).ToUInt32 ()); - break; - case OperandType.InlineTok: - case OperandType.InlineType: - case OperandType.InlineMethod: - case OperandType.InlineField: - var provider = reader.LookupToken (new MetadataToken (buffer.ReadUInt32 ())); - buffer.position -= 4; - buffer.WriteUInt32 (metadata.LookupToken (provider).ToUInt32 ()); - break; - } - } - } - - void PatchRawSection (ByteBuffer buffer, MetadataBuilder metadata) - { - var position = base.position; - Align (4); - buffer.WriteBytes (base.position - position); - - const byte fat_format = 0x40; - const byte more_sects = 0x80; - - var flags = ReadByte (); - if ((flags & fat_format) == 0) { - buffer.WriteByte (flags); - PatchRawSmallSection (buffer, metadata); - } else - PatchRawFatSection (buffer, metadata); - - if ((flags & more_sects) != 0) - PatchRawSection (buffer, metadata); - } - - void PatchRawSmallSection (ByteBuffer buffer, MetadataBuilder metadata) - { - var length = ReadByte (); - buffer.WriteByte (length); - Advance (2); - - buffer.WriteUInt16 (0); - - var count = length / 12; - - PatchRawExceptionHandlers (buffer, metadata, count, false); - } - - void PatchRawFatSection (ByteBuffer buffer, MetadataBuilder metadata) - { - position--; - var length = ReadInt32 (); - buffer.WriteInt32 (length); - - var count = (length >> 8) / 24; - - PatchRawExceptionHandlers (buffer, metadata, count, true); - } - - void PatchRawExceptionHandlers (ByteBuffer buffer, MetadataBuilder metadata, int count, bool fat_entry) - { - const int fat_entry_size = 16; - const int small_entry_size = 6; - - for (int i = 0; i < count; i++) { - ExceptionHandlerType handler_type; - if (fat_entry) { - var type = ReadUInt32 (); - handler_type = (ExceptionHandlerType) (type & 0x7); - buffer.WriteUInt32 (type); - } else { - var type = ReadUInt16 (); - handler_type = (ExceptionHandlerType) (type & 0x7); - buffer.WriteUInt16 (type); - } - - buffer.WriteBytes (ReadBytes (fat_entry ? fat_entry_size : small_entry_size)); - - switch (handler_type) { - case ExceptionHandlerType.Catch: - var exception = reader.LookupToken (ReadToken ()); - buffer.WriteUInt32 (metadata.LookupToken (exception).ToUInt32 ()); - break; - default: - buffer.WriteUInt32 (ReadUInt32 ()); - break; - } - } - } - -#endif - - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs deleted file mode 100644 index ac093cae460..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs +++ /dev/null @@ -1,649 +0,0 @@ -// -// CodeWriter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; - -using Mono.Collections.Generic; - -using Mono.Cecil.Metadata; -using Mono.Cecil.PE; - -using RVA = System.UInt32; - -#if !READ_ONLY - -namespace Mono.Cecil.Cil { - - sealed class CodeWriter : ByteBuffer { - - readonly RVA code_base; - internal readonly MetadataBuilder metadata; - readonly Dictionary standalone_signatures; - - RVA current; - MethodBody body; - - public CodeWriter (MetadataBuilder metadata) - : base (0) - { - this.code_base = metadata.text_map.GetNextRVA (TextSegment.CLIHeader); - this.current = code_base; - this.metadata = metadata; - this.standalone_signatures = new Dictionary (); - } - - public RVA WriteMethodBody (MethodDefinition method) - { - var rva = BeginMethod (); - - if (IsUnresolved (method)) { - if (method.rva == 0) - return 0; - - WriteUnresolvedMethodBody (method); - } else { - if (IsEmptyMethodBody (method.Body)) - return 0; - - WriteResolvedMethodBody (method); - } - - Align (4); - - EndMethod (); - return rva; - } - - static bool IsEmptyMethodBody (MethodBody body) - { - return body.instructions.IsNullOrEmpty () - && body.variables.IsNullOrEmpty (); - } - - static bool IsUnresolved (MethodDefinition method) - { - return method.HasBody && method.HasImage && method.body == null; - } - - void WriteUnresolvedMethodBody (MethodDefinition method) - { - var code_reader = metadata.module.Read (method, (_, reader) => reader.code); - - MethodSymbols symbols; - var buffer = code_reader.PatchRawMethodBody (method, this, out symbols); - - WriteBytes (buffer); - - if (symbols.instructions.IsNullOrEmpty ()) - return; - - symbols.method_token = method.token; - symbols.local_var_token = GetLocalVarToken (buffer, symbols); - - var symbol_writer = metadata.symbol_writer; - if (symbol_writer != null) - symbol_writer.Write (symbols); - } - - static MetadataToken GetLocalVarToken (ByteBuffer buffer, MethodSymbols symbols) - { - if (symbols.variables.IsNullOrEmpty ()) - return MetadataToken.Zero; - - buffer.position = 8; - return new MetadataToken (buffer.ReadUInt32 ()); - } - - void WriteResolvedMethodBody (MethodDefinition method) - { - body = method.Body; - ComputeHeader (); - if (RequiresFatHeader ()) - WriteFatHeader (); - else - WriteByte ((byte) (0x2 | (body.CodeSize << 2))); // tiny - - WriteInstructions (); - - if (body.HasExceptionHandlers) - WriteExceptionHandlers (); - - var symbol_writer = metadata.symbol_writer; - if (symbol_writer != null) - symbol_writer.Write (body); - } - - void WriteFatHeader () - { - var body = this.body; - byte flags = 0x3; // fat - if (body.InitLocals) - flags |= 0x10; // init locals - if (body.HasExceptionHandlers) - flags |= 0x8; // more sections - - WriteByte (flags); - WriteByte (0x30); - WriteInt16 ((short) body.max_stack_size); - WriteInt32 (body.code_size); - body.local_var_token = body.HasVariables - ? GetStandAloneSignature (body.Variables) - : MetadataToken.Zero; - WriteMetadataToken (body.local_var_token); - } - - void WriteInstructions () - { - var instructions = body.Instructions; - var items = instructions.items; - var size = instructions.size; - - for (int i = 0; i < size; i++) { - var instruction = items [i]; - WriteOpCode (instruction.opcode); - WriteOperand (instruction); - } - } - - void WriteOpCode (OpCode opcode) - { - if (opcode.Size == 1) { - WriteByte (opcode.Op2); - } else { - WriteByte (opcode.Op1); - WriteByte (opcode.Op2); - } - } - - void WriteOperand (Instruction instruction) - { - var opcode = instruction.opcode; - var operand_type = opcode.OperandType; - if (operand_type == OperandType.InlineNone) - return; - - var operand = instruction.operand; - if (operand == null) - throw new ArgumentException (); - - switch (operand_type) { - case OperandType.InlineSwitch: { - var targets = (Instruction []) operand; - WriteInt32 (targets.Length); - var diff = instruction.Offset + opcode.Size + (4 * (targets.Length + 1)); - for (int i = 0; i < targets.Length; i++) - WriteInt32 (GetTargetOffset (targets [i]) - diff); - break; - } - case OperandType.ShortInlineBrTarget: { - var target = (Instruction) operand; - WriteSByte ((sbyte) (GetTargetOffset (target) - (instruction.Offset + opcode.Size + 1))); - break; - } - case OperandType.InlineBrTarget: { - var target = (Instruction) operand; - WriteInt32 (GetTargetOffset (target) - (instruction.Offset + opcode.Size + 4)); - break; - } - case OperandType.ShortInlineVar: - WriteByte ((byte) GetVariableIndex ((VariableDefinition) operand)); - break; - case OperandType.ShortInlineArg: - WriteByte ((byte) GetParameterIndex ((ParameterDefinition) operand)); - break; - case OperandType.InlineVar: - WriteInt16 ((short) GetVariableIndex ((VariableDefinition) operand)); - break; - case OperandType.InlineArg: - WriteInt16 ((short) GetParameterIndex ((ParameterDefinition) operand)); - break; - case OperandType.InlineSig: - WriteMetadataToken (GetStandAloneSignature ((CallSite) operand)); - break; - case OperandType.ShortInlineI: - if (opcode == OpCodes.Ldc_I4_S) - WriteSByte ((sbyte) operand); - else - WriteByte ((byte) operand); - break; - case OperandType.InlineI: - WriteInt32 ((int) operand); - break; - case OperandType.InlineI8: - WriteInt64 ((long) operand); - break; - case OperandType.ShortInlineR: - WriteSingle ((float) operand); - break; - case OperandType.InlineR: - WriteDouble ((double) operand); - break; - case OperandType.InlineString: - WriteMetadataToken ( - new MetadataToken ( - TokenType.String, - GetUserStringIndex ((string) operand))); - break; - case OperandType.InlineType: - case OperandType.InlineField: - case OperandType.InlineMethod: - case OperandType.InlineTok: - WriteMetadataToken (metadata.LookupToken ((IMetadataTokenProvider) operand)); - break; - default: - throw new ArgumentException (); - } - } - - int GetTargetOffset (Instruction instruction) - { - if (instruction == null) { - var last = body.instructions [body.instructions.size - 1]; - return last.offset + last.GetSize (); - } - - return instruction.offset; - } - - uint GetUserStringIndex (string @string) - { - if (@string == null) - return 0; - - return metadata.user_string_heap.GetStringIndex (@string); - } - - static int GetVariableIndex (VariableDefinition variable) - { - return variable.Index; - } - - int GetParameterIndex (ParameterDefinition parameter) - { - if (body.method.HasThis) { - if (parameter == body.this_parameter) - return 0; - - return parameter.Index + 1; - } - - return parameter.Index; - } - - bool RequiresFatHeader () - { - var body = this.body; - return body.CodeSize >= 64 - || body.InitLocals - || body.HasVariables - || body.HasExceptionHandlers - || body.MaxStackSize > 8; - } - - void ComputeHeader () - { - int offset = 0; - var instructions = body.instructions; - var items = instructions.items; - var count = instructions.size; - var stack_size = 0; - var max_stack = 0; - Dictionary stack_sizes = null; - - if (body.HasExceptionHandlers) - ComputeExceptionHandlerStackSize (ref stack_sizes); - - for (int i = 0; i < count; i++) { - var instruction = items [i]; - instruction.offset = offset; - offset += instruction.GetSize (); - - ComputeStackSize (instruction, ref stack_sizes, ref stack_size, ref max_stack); - } - - body.code_size = offset; - body.max_stack_size = max_stack; - } - - void ComputeExceptionHandlerStackSize (ref Dictionary stack_sizes) - { - var exception_handlers = body.ExceptionHandlers; - - for (int i = 0; i < exception_handlers.Count; i++) { - var exception_handler = exception_handlers [i]; - - switch (exception_handler.HandlerType) { - case ExceptionHandlerType.Catch: - AddExceptionStackSize (exception_handler.HandlerStart, ref stack_sizes); - break; - case ExceptionHandlerType.Filter: - AddExceptionStackSize (exception_handler.FilterStart, ref stack_sizes); - AddExceptionStackSize (exception_handler.HandlerStart, ref stack_sizes); - break; - } - } - } - - static void AddExceptionStackSize (Instruction handler_start, ref Dictionary stack_sizes) - { - if (handler_start == null) - return; - - if (stack_sizes == null) - stack_sizes = new Dictionary (); - - stack_sizes [handler_start] = 1; - } - - static void ComputeStackSize (Instruction instruction, ref Dictionary stack_sizes, ref int stack_size, ref int max_stack) - { - int computed_size; - if (stack_sizes != null && stack_sizes.TryGetValue (instruction, out computed_size)) - stack_size = computed_size; - - max_stack = System.Math.Max (max_stack, stack_size); - ComputeStackDelta (instruction, ref stack_size); - max_stack = System.Math.Max (max_stack, stack_size); - - CopyBranchStackSize (instruction, ref stack_sizes, stack_size); - ComputeStackSize (instruction, ref stack_size); - } - - static void CopyBranchStackSize (Instruction instruction, ref Dictionary stack_sizes, int stack_size) - { - if (stack_size == 0) - return; - - switch (instruction.opcode.OperandType) { - case OperandType.ShortInlineBrTarget: - case OperandType.InlineBrTarget: - CopyBranchStackSize (ref stack_sizes, (Instruction) instruction.operand, stack_size); - break; - case OperandType.InlineSwitch: - var targets = (Instruction[]) instruction.operand; - for (int i = 0; i < targets.Length; i++) - CopyBranchStackSize (ref stack_sizes, targets [i], stack_size); - break; - } - } - - static void CopyBranchStackSize (ref Dictionary stack_sizes, Instruction target, int stack_size) - { - if (stack_sizes == null) - stack_sizes = new Dictionary (); - - int branch_stack_size = stack_size; - - int computed_size; - if (stack_sizes.TryGetValue (target, out computed_size)) - branch_stack_size = System.Math.Max (branch_stack_size, computed_size); - - stack_sizes [target] = branch_stack_size; - } - - static void ComputeStackSize (Instruction instruction, ref int stack_size) - { - switch (instruction.opcode.FlowControl) { - case FlowControl.Branch: - case FlowControl.Break: - case FlowControl.Throw: - case FlowControl.Return: - stack_size = 0; - break; - } - } - - static void ComputeStackDelta (Instruction instruction, ref int stack_size) - { - switch (instruction.opcode.FlowControl) { - case FlowControl.Call: { - var method = (IMethodSignature) instruction.operand; - // pop 'this' argument - if (method.HasImplicitThis() && instruction.opcode.Code != Code.Newobj) - stack_size--; - // pop normal arguments - if (method.HasParameters) - stack_size -= method.Parameters.Count; - // pop function pointer - if (instruction.opcode.Code == Code.Calli) - stack_size--; - // push return value - if (method.ReturnType.etype != ElementType.Void || instruction.opcode.Code == Code.Newobj) - stack_size++; - break; - } - default: - ComputePopDelta (instruction.opcode.StackBehaviourPop, ref stack_size); - ComputePushDelta (instruction.opcode.StackBehaviourPush, ref stack_size); - break; - } - } - - static void ComputePopDelta (StackBehaviour pop_behavior, ref int stack_size) - { - switch (pop_behavior) { - case StackBehaviour.Popi: - case StackBehaviour.Popref: - case StackBehaviour.Pop1: - stack_size--; - break; - case StackBehaviour.Pop1_pop1: - case StackBehaviour.Popi_pop1: - case StackBehaviour.Popi_popi: - case StackBehaviour.Popi_popi8: - case StackBehaviour.Popi_popr4: - case StackBehaviour.Popi_popr8: - case StackBehaviour.Popref_pop1: - case StackBehaviour.Popref_popi: - stack_size -= 2; - break; - case StackBehaviour.Popi_popi_popi: - case StackBehaviour.Popref_popi_popi: - case StackBehaviour.Popref_popi_popi8: - case StackBehaviour.Popref_popi_popr4: - case StackBehaviour.Popref_popi_popr8: - case StackBehaviour.Popref_popi_popref: - stack_size -= 3; - break; - case StackBehaviour.PopAll: - stack_size = 0; - break; - } - } - - static void ComputePushDelta (StackBehaviour push_behaviour, ref int stack_size) - { - switch (push_behaviour) { - case StackBehaviour.Push1: - case StackBehaviour.Pushi: - case StackBehaviour.Pushi8: - case StackBehaviour.Pushr4: - case StackBehaviour.Pushr8: - case StackBehaviour.Pushref: - stack_size++; - break; - case StackBehaviour.Push1_push1: - stack_size += 2; - break; - } - } - - void WriteExceptionHandlers () - { - Align (4); - - var handlers = body.ExceptionHandlers; - - if (handlers.Count < 0x15 && !RequiresFatSection (handlers)) - WriteSmallSection (handlers); - else - WriteFatSection (handlers); - } - - static bool RequiresFatSection (Collection handlers) - { - for (int i = 0; i < handlers.Count; i++) { - var handler = handlers [i]; - - if (IsFatRange (handler.TryStart, handler.TryEnd)) - return true; - - if (IsFatRange (handler.HandlerStart, handler.HandlerEnd)) - return true; - - if (handler.HandlerType == ExceptionHandlerType.Filter - && IsFatRange (handler.FilterStart, handler.HandlerStart)) - return true; - } - - return false; - } - - static bool IsFatRange (Instruction start, Instruction end) - { - if (start == null) - throw new ArgumentException (); - - if (end == null) - return true; - - return end.Offset - start.Offset > 255 || start.Offset > 65535; - } - - void WriteSmallSection (Collection handlers) - { - const byte eh_table = 0x1; - - WriteByte (eh_table); - WriteByte ((byte) (handlers.Count * 12 + 4)); - WriteBytes (2); - - WriteExceptionHandlers ( - handlers, - i => WriteUInt16 ((ushort) i), - i => WriteByte ((byte) i)); - } - - void WriteFatSection (Collection handlers) - { - const byte eh_table = 0x1; - const byte fat_format = 0x40; - - WriteByte (eh_table | fat_format); - - int size = handlers.Count * 24 + 4; - WriteByte ((byte) (size & 0xff)); - WriteByte ((byte) ((size >> 8) & 0xff)); - WriteByte ((byte) ((size >> 16) & 0xff)); - - WriteExceptionHandlers (handlers, WriteInt32, WriteInt32); - } - - void WriteExceptionHandlers (Collection handlers, Action write_entry, Action write_length) - { - for (int i = 0; i < handlers.Count; i++) { - var handler = handlers [i]; - - write_entry ((int) handler.HandlerType); - - write_entry (handler.TryStart.Offset); - write_length (GetTargetOffset (handler.TryEnd) - handler.TryStart.Offset); - - write_entry (handler.HandlerStart.Offset); - write_length (GetTargetOffset (handler.HandlerEnd) - handler.HandlerStart.Offset); - - WriteExceptionHandlerSpecific (handler); - } - } - - void WriteExceptionHandlerSpecific (ExceptionHandler handler) - { - switch (handler.HandlerType) { - case ExceptionHandlerType.Catch: - WriteMetadataToken (metadata.LookupToken (handler.CatchType)); - break; - case ExceptionHandlerType.Filter: - WriteInt32 (handler.FilterStart.Offset); - break; - default: - WriteInt32 (0); - break; - } - } - - public MetadataToken GetStandAloneSignature (Collection variables) - { - var signature = metadata.GetLocalVariableBlobIndex (variables); - - return GetStandAloneSignatureToken (signature); - } - - public MetadataToken GetStandAloneSignature (CallSite call_site) - { - var signature = metadata.GetCallSiteBlobIndex (call_site); - var token = GetStandAloneSignatureToken (signature); - call_site.MetadataToken = token; - return token; - } - - MetadataToken GetStandAloneSignatureToken (uint signature) - { - MetadataToken token; - if (standalone_signatures.TryGetValue (signature, out token)) - return token; - - token = new MetadataToken (TokenType.Signature, metadata.AddStandAloneSignature (signature)); - standalone_signatures.Add (signature, token); - return token; - } - - RVA BeginMethod () - { - return current; - } - - void WriteMetadataToken (MetadataToken token) - { - WriteUInt32 (token.ToUInt32 ()); - } - - void Align (int align) - { - align--; - WriteBytes (((position + align) & ~align) - position); - } - - void EndMethod () - { - current = (RVA) (code_base + position); - } - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Document.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Document.cs deleted file mode 100644 index 1dbdc447448..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Document.cs +++ /dev/null @@ -1,112 +0,0 @@ -// -// Document.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil.Cil { - - public enum DocumentType { - Other, - Text, - } - - public enum DocumentHashAlgorithm { - None, - MD5, - SHA1, - } - - public enum DocumentLanguage { - Other, - C, - Cpp, - CSharp, - Basic, - Java, - Cobol, - Pascal, - Cil, - JScript, - Smc, - MCpp, - FSharp, - } - - public enum DocumentLanguageVendor { - Other, - Microsoft, - } - - public sealed class Document { - - string url; - - byte type; - byte hash_algorithm; - byte language; - byte language_vendor; - - byte [] hash; - - public string Url { - get { return url; } - set { url = value; } - } - - public DocumentType Type { - get { return (DocumentType) type; } - set { type = (byte) value; } - } - - public DocumentHashAlgorithm HashAlgorithm { - get { return (DocumentHashAlgorithm) hash_algorithm; } - set { hash_algorithm = (byte) value; } - } - - public DocumentLanguage Language { - get { return (DocumentLanguage) language; } - set { language = (byte) value; } - } - - public DocumentLanguageVendor LanguageVendor { - get { return (DocumentLanguageVendor) language_vendor; } - set { language_vendor = (byte) value; } - } - - public byte [] Hash { - get { return hash; } - set { hash = value; } - } - - public Document (string url) - { - this.url = url; - this.hash = Empty.Array; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs deleted file mode 100644 index c61ff235efb..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs +++ /dev/null @@ -1,89 +0,0 @@ -// -// ExceptionHandler.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public enum ExceptionHandlerType { - Catch = 0, - Filter = 1, - Finally = 2, - Fault = 4, - } - - public sealed class ExceptionHandler { - - Instruction try_start; - Instruction try_end; - Instruction filter_start; - Instruction handler_start; - Instruction handler_end; - - TypeReference catch_type; - ExceptionHandlerType handler_type; - - public Instruction TryStart { - get { return try_start; } - set { try_start = value; } - } - - public Instruction TryEnd { - get { return try_end; } - set { try_end = value; } - } - - public Instruction FilterStart { - get { return filter_start; } - set { filter_start = value; } - } - - public Instruction HandlerStart { - get { return handler_start; } - set { handler_start = value; } - } - - public Instruction HandlerEnd { - get { return handler_end; } - set { handler_end = value; } - } - - public TypeReference CatchType { - get { return catch_type; } - set { catch_type = value; } - } - - public ExceptionHandlerType HandlerType { - get { return handler_type; } - set { handler_type = value; } - } - - public ExceptionHandler (ExceptionHandlerType handlerType) - { - this.handler_type = handlerType; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/ILProcessor.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/ILProcessor.cs deleted file mode 100644 index cd5dbb40fe6..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/ILProcessor.cs +++ /dev/null @@ -1,278 +0,0 @@ -// -// ILProcessor.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil.Cil { - - public sealed class ILProcessor { - - readonly MethodBody body; - readonly Collection instructions; - - public MethodBody Body { - get { return body; } - } - - internal ILProcessor (MethodBody body) - { - this.body = body; - this.instructions = body.Instructions; - } - - public Instruction Create (OpCode opcode) - { - return Instruction.Create (opcode); - } - - public Instruction Create (OpCode opcode, TypeReference type) - { - return Instruction.Create (opcode, type); - } - - public Instruction Create (OpCode opcode, CallSite site) - { - return Instruction.Create (opcode, site); - } - - public Instruction Create (OpCode opcode, MethodReference method) - { - return Instruction.Create (opcode, method); - } - - public Instruction Create (OpCode opcode, FieldReference field) - { - return Instruction.Create (opcode, field); - } - - public Instruction Create (OpCode opcode, string value) - { - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, sbyte value) - { - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, byte value) - { - if (opcode.OperandType == OperandType.ShortInlineVar) - return Instruction.Create (opcode, body.Variables [value]); - - if (opcode.OperandType == OperandType.ShortInlineArg) - return Instruction.Create (opcode, body.GetParameter (value)); - - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, int value) - { - if (opcode.OperandType == OperandType.InlineVar) - return Instruction.Create (opcode, body.Variables [value]); - - if (opcode.OperandType == OperandType.InlineArg) - return Instruction.Create (opcode, body.GetParameter (value)); - - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, long value) - { - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, float value) - { - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, double value) - { - return Instruction.Create (opcode, value); - } - - public Instruction Create (OpCode opcode, Instruction target) - { - return Instruction.Create (opcode, target); - } - - public Instruction Create (OpCode opcode, Instruction [] targets) - { - return Instruction.Create (opcode, targets); - } - - public Instruction Create (OpCode opcode, VariableDefinition variable) - { - return Instruction.Create (opcode, variable); - } - - public Instruction Create (OpCode opcode, ParameterDefinition parameter) - { - return Instruction.Create (opcode, parameter); - } - - public void Emit (OpCode opcode) - { - Append (Create (opcode)); - } - - public void Emit (OpCode opcode, TypeReference type) - { - Append (Create (opcode, type)); - } - - public void Emit (OpCode opcode, MethodReference method) - { - Append (Create (opcode, method)); - } - - public void Emit (OpCode opcode, CallSite site) - { - Append (Create (opcode, site)); - } - - public void Emit (OpCode opcode, FieldReference field) - { - Append (Create (opcode, field)); - } - - public void Emit (OpCode opcode, string value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, byte value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, sbyte value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, int value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, long value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, float value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, double value) - { - Append (Create (opcode, value)); - } - - public void Emit (OpCode opcode, Instruction target) - { - Append (Create (opcode, target)); - } - - public void Emit (OpCode opcode, Instruction [] targets) - { - Append (Create (opcode, targets)); - } - - public void Emit (OpCode opcode, VariableDefinition variable) - { - Append (Create (opcode, variable)); - } - - public void Emit (OpCode opcode, ParameterDefinition parameter) - { - Append (Create (opcode, parameter)); - } - - public void InsertBefore (Instruction target, Instruction instruction) - { - if (target == null) - throw new ArgumentNullException ("target"); - if (instruction == null) - throw new ArgumentNullException ("instruction"); - - var index = instructions.IndexOf (target); - if (index == -1) - throw new ArgumentOutOfRangeException ("target"); - - instructions.Insert (index, instruction); - } - - public void InsertAfter (Instruction target, Instruction instruction) - { - if (target == null) - throw new ArgumentNullException ("target"); - if (instruction == null) - throw new ArgumentNullException ("instruction"); - - var index = instructions.IndexOf (target); - if (index == -1) - throw new ArgumentOutOfRangeException ("target"); - - instructions.Insert (index + 1, instruction); - } - - public void Append (Instruction instruction) - { - if (instruction == null) - throw new ArgumentNullException ("instruction"); - - instructions.Add (instruction); - } - - public void Replace (Instruction target, Instruction instruction) - { - if (target == null) - throw new ArgumentNullException ("target"); - if (instruction == null) - throw new ArgumentNullException ("instruction"); - - InsertAfter (target, instruction); - Remove (target); - } - - public void Remove (Instruction instruction) - { - if (instruction == null) - throw new ArgumentNullException ("instruction"); - - if (!instructions.Remove (instruction)) - throw new ArgumentOutOfRangeException ("instruction"); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs deleted file mode 100644 index c28d4c99291..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs +++ /dev/null @@ -1,321 +0,0 @@ -// -// Instruction.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; - -namespace Mono.Cecil.Cil { - - public sealed class Instruction { - - internal int offset; - internal OpCode opcode; - internal object operand; - - internal Instruction previous; - internal Instruction next; - - SequencePoint sequence_point; - - public int Offset { - get { return offset; } - set { offset = value; } - } - - public OpCode OpCode { - get { return opcode; } - set { opcode = value; } - } - - public object Operand { - get { return operand; } - set { operand = value; } - } - - public Instruction Previous { - get { return previous; } - set { previous = value; } - } - - public Instruction Next { - get { return next; } - set { next = value; } - } - - public SequencePoint SequencePoint { - get { return sequence_point; } - set { sequence_point = value; } - } - - internal Instruction (int offset, OpCode opCode) - { - this.offset = offset; - this.opcode = opCode; - } - - internal Instruction (OpCode opcode, object operand) - { - this.opcode = opcode; - this.operand = operand; - } - - public int GetSize () - { - int size = opcode.Size; - - switch (opcode.OperandType) { - case OperandType.InlineSwitch: - return size + (1 + ((Instruction []) operand).Length) * 4; - case OperandType.InlineI8: - case OperandType.InlineR: - return size + 8; - case OperandType.InlineBrTarget: - case OperandType.InlineField: - case OperandType.InlineI: - case OperandType.InlineMethod: - case OperandType.InlineString: - case OperandType.InlineTok: - case OperandType.InlineType: - case OperandType.ShortInlineR: - case OperandType.InlineSig: - return size + 4; - case OperandType.InlineArg: - case OperandType.InlineVar: - return size + 2; - case OperandType.ShortInlineBrTarget: - case OperandType.ShortInlineI: - case OperandType.ShortInlineArg: - case OperandType.ShortInlineVar: - return size + 1; - default: - return size; - } - } - - public override string ToString () - { - var instruction = new StringBuilder (); - - AppendLabel (instruction, this); - instruction.Append (':'); - instruction.Append (' '); - instruction.Append (opcode.Name); - - if (operand == null) - return instruction.ToString (); - - instruction.Append (' '); - - switch (opcode.OperandType) { - case OperandType.ShortInlineBrTarget: - case OperandType.InlineBrTarget: - AppendLabel (instruction, (Instruction) operand); - break; - case OperandType.InlineSwitch: - var labels = (Instruction []) operand; - for (int i = 0; i < labels.Length; i++) { - if (i > 0) - instruction.Append (','); - - AppendLabel (instruction, labels [i]); - } - break; - case OperandType.InlineString: - instruction.Append ('\"'); - instruction.Append (operand); - instruction.Append ('\"'); - break; - default: - instruction.Append (operand); - break; - } - - return instruction.ToString (); - } - - static void AppendLabel (StringBuilder builder, Instruction instruction) - { - builder.Append ("IL_"); - builder.Append (instruction.offset.ToString ("x4")); - } - - public static Instruction Create (OpCode opcode) - { - if (opcode.OperandType != OperandType.InlineNone) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, null); - } - - public static Instruction Create (OpCode opcode, TypeReference type) - { - if (type == null) - throw new ArgumentNullException ("type"); - if (opcode.OperandType != OperandType.InlineType && - opcode.OperandType != OperandType.InlineTok) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, type); - } - - public static Instruction Create (OpCode opcode, CallSite site) - { - if (site == null) - throw new ArgumentNullException ("site"); - if (opcode.Code != Code.Calli) - throw new ArgumentException ("code"); - - return new Instruction (opcode, site); - } - - public static Instruction Create (OpCode opcode, MethodReference method) - { - if (method == null) - throw new ArgumentNullException ("method"); - if (opcode.OperandType != OperandType.InlineMethod && - opcode.OperandType != OperandType.InlineTok) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, method); - } - - public static Instruction Create (OpCode opcode, FieldReference field) - { - if (field == null) - throw new ArgumentNullException ("field"); - if (opcode.OperandType != OperandType.InlineField && - opcode.OperandType != OperandType.InlineTok) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, field); - } - - public static Instruction Create (OpCode opcode, string value) - { - if (value == null) - throw new ArgumentNullException ("value"); - if (opcode.OperandType != OperandType.InlineString) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, sbyte value) - { - if (opcode.OperandType != OperandType.ShortInlineI && - opcode != OpCodes.Ldc_I4_S) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, byte value) - { - if (opcode.OperandType != OperandType.ShortInlineI || - opcode == OpCodes.Ldc_I4_S) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, int value) - { - if (opcode.OperandType != OperandType.InlineI) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, long value) - { - if (opcode.OperandType != OperandType.InlineI8) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, float value) - { - if (opcode.OperandType != OperandType.ShortInlineR) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, double value) - { - if (opcode.OperandType != OperandType.InlineR) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, value); - } - - public static Instruction Create (OpCode opcode, Instruction target) - { - if (target == null) - throw new ArgumentNullException ("target"); - if (opcode.OperandType != OperandType.InlineBrTarget && - opcode.OperandType != OperandType.ShortInlineBrTarget) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, target); - } - - public static Instruction Create (OpCode opcode, Instruction [] targets) - { - if (targets == null) - throw new ArgumentNullException ("targets"); - if (opcode.OperandType != OperandType.InlineSwitch) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, targets); - } - - public static Instruction Create (OpCode opcode, VariableDefinition variable) - { - if (variable == null) - throw new ArgumentNullException ("variable"); - if (opcode.OperandType != OperandType.ShortInlineVar && - opcode.OperandType != OperandType.InlineVar) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, variable); - } - - public static Instruction Create (OpCode opcode, ParameterDefinition parameter) - { - if (parameter == null) - throw new ArgumentNullException ("parameter"); - if (opcode.OperandType != OperandType.ShortInlineArg && - opcode.OperandType != OperandType.InlineArg) - throw new ArgumentException ("opcode"); - - return new Instruction (opcode, parameter); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs deleted file mode 100644 index 3eefc95f35b..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs +++ /dev/null @@ -1,241 +0,0 @@ -// -// MethodBody.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil.Cil { - - public sealed class MethodBody : IVariableDefinitionProvider { - - readonly internal MethodDefinition method; - - internal ParameterDefinition this_parameter; - internal int max_stack_size; - internal int code_size; - internal bool init_locals; - internal MetadataToken local_var_token; - - internal Collection instructions; - internal Collection exceptions; - internal Collection variables; - Scope scope; - - public MethodDefinition Method { - get { return method; } - } - - public int MaxStackSize { - get { return max_stack_size; } - set { max_stack_size = value; } - } - - public int CodeSize { - get { return code_size; } - } - - public bool InitLocals { - get { return init_locals; } - set { init_locals = value; } - } - - public MetadataToken LocalVarToken { - get { return local_var_token; } - set { local_var_token = value; } - } - - public Collection Instructions { - get { return instructions ?? (instructions = new InstructionCollection ()); } - } - - public bool HasExceptionHandlers { - get { return !exceptions.IsNullOrEmpty (); } - } - - public Collection ExceptionHandlers { - get { return exceptions ?? (exceptions = new Collection ()); } - } - - public bool HasVariables { - get { return !variables.IsNullOrEmpty (); } - } - - public Collection Variables { - get { return variables ?? (variables = new VariableDefinitionCollection ()); } - } - - public Scope Scope { - get { return scope; } - set { scope = value; } - } - - public ParameterDefinition ThisParameter { - get { - if (method == null || method.DeclaringType == null) - throw new NotSupportedException (); - - if (!method.HasThis) - return null; - - if (this_parameter != null) - return this_parameter; - - var declaring_type = method.DeclaringType; - var type = declaring_type.IsValueType || declaring_type.IsPrimitive - ? new PointerType (declaring_type) - : declaring_type as TypeReference; - - return this_parameter = new ParameterDefinition (type, method); - } - } - - public MethodBody (MethodDefinition method) - { - this.method = method; - } - - public ILProcessor GetILProcessor () - { - return new ILProcessor (this); - } - } - - public interface IVariableDefinitionProvider { - bool HasVariables { get; } - Collection Variables { get; } - } - - class VariableDefinitionCollection : Collection { - - internal VariableDefinitionCollection () - { - } - - internal VariableDefinitionCollection (int capacity) - : base (capacity) - { - } - - protected override void OnAdd (VariableDefinition item, int index) - { - item.index = index; - } - - protected override void OnInsert (VariableDefinition item, int index) - { - item.index = index; - - for (int i = index; i < size; i++) - items [i].index = i + 1; - } - - protected override void OnSet (VariableDefinition item, int index) - { - item.index = index; - } - - protected override void OnRemove (VariableDefinition item, int index) - { - item.index = -1; - - for (int i = index + 1; i < size; i++) - items [i].index = i - 1; - } - } - - class InstructionCollection : Collection { - - internal InstructionCollection () - { - } - - internal InstructionCollection (int capacity) - : base (capacity) - { - } - - protected override void OnAdd (Instruction item, int index) - { - if (index == 0) - return; - - var previous = items [index - 1]; - previous.next = item; - item.previous = previous; - } - - protected override void OnInsert (Instruction item, int index) - { - if (size == 0) - return; - - var current = items [index]; - if (current == null) { - var last = items [index - 1]; - last.next = item; - item.previous = last; - return; - } - - var previous = current.previous; - if (previous != null) { - previous.next = item; - item.previous = previous; - } - - current.previous = item; - item.next = current; - } - - protected override void OnSet (Instruction item, int index) - { - var current = items [index]; - - item.previous = current.previous; - item.next = current.next; - - current.previous = null; - current.next = null; - } - - protected override void OnRemove (Instruction item, int index) - { - var previous = item.previous; - if (previous != null) - previous.next = item.next; - - var next = item.next; - if (next != null) - next.previous = item.previous; - - item.previous = null; - item.next = null; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs deleted file mode 100644 index 1a14421300d..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs +++ /dev/null @@ -1,455 +0,0 @@ -// -// OpCode.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public enum FlowControl { - Branch, - Break, - Call, - Cond_Branch, - Meta, - Next, - Phi, - Return, - Throw, - } - - public enum OpCodeType { - Annotation, - Macro, - Nternal, - Objmodel, - Prefix, - Primitive, - } - - public enum OperandType { - InlineBrTarget, - InlineField, - InlineI, - InlineI8, - InlineMethod, - InlineNone, - InlinePhi, - InlineR, - InlineSig, - InlineString, - InlineSwitch, - InlineTok, - InlineType, - InlineVar, - InlineArg, - ShortInlineBrTarget, - ShortInlineI, - ShortInlineR, - ShortInlineVar, - ShortInlineArg, - } - - public enum StackBehaviour { - Pop0, - Pop1, - Pop1_pop1, - Popi, - Popi_pop1, - Popi_popi, - Popi_popi8, - Popi_popi_popi, - Popi_popr4, - Popi_popr8, - Popref, - Popref_pop1, - Popref_popi, - Popref_popi_popi, - Popref_popi_popi8, - Popref_popi_popr4, - Popref_popi_popr8, - Popref_popi_popref, - PopAll, - Push0, - Push1, - Push1_push1, - Pushi, - Pushi8, - Pushr4, - Pushr8, - Pushref, - Varpop, - Varpush, - } - - public struct OpCode { - - readonly byte op1; - readonly byte op2; - readonly byte code; - readonly byte flow_control; - readonly byte opcode_type; - readonly byte operand_type; - readonly byte stack_behavior_pop; - readonly byte stack_behavior_push; - - public string Name { - get { return OpCodeNames.names [(int) Code]; } - } - - public int Size { - get { return op1 == 0xff ? 1 : 2; } - } - - public byte Op1 { - get { return op1; } - } - - public byte Op2 { - get { return op2; } - } - - public short Value { - get { return op1 == 0xff ? op2 : (short) ((op1 << 8) | op2); } - } - - public Code Code { - get { return (Code) code; } - } - - public FlowControl FlowControl { - get { return (FlowControl) flow_control; } - } - - public OpCodeType OpCodeType { - get { return (OpCodeType) opcode_type; } - } - - public OperandType OperandType { - get { return (OperandType) operand_type; } - } - - public StackBehaviour StackBehaviourPop { - get { return (StackBehaviour) stack_behavior_pop; } - } - - public StackBehaviour StackBehaviourPush { - get { return (StackBehaviour) stack_behavior_push; } - } - - internal OpCode (int x, int y) - { - this.op1 = (byte) ((x >> 0) & 0xff); - this.op2 = (byte) ((x >> 8) & 0xff); - this.code = (byte) ((x >> 16) & 0xff); - this.flow_control = (byte) ((x >> 24) & 0xff); - - this.opcode_type = (byte) ((y >> 0) & 0xff); - this.operand_type = (byte) ((y >> 8) & 0xff); - this.stack_behavior_pop = (byte) ((y >> 16) & 0xff); - this.stack_behavior_push = (byte) ((y >> 24) & 0xff); - - if (op1 == 0xff) - OpCodes.OneByteOpCode [op2] = this; - else - OpCodes.TwoBytesOpCode [op2] = this; - } - - public override int GetHashCode () - { - return Value; - } - - public override bool Equals (object obj) - { - if (!(obj is OpCode)) - return false; - - var opcode = (OpCode) obj; - return op1 == opcode.op1 && op2 == opcode.op2; - } - - public bool Equals (OpCode opcode) - { - return op1 == opcode.op1 && op2 == opcode.op2; - } - - public static bool operator == (OpCode one, OpCode other) - { - return one.op1 == other.op1 && one.op2 == other.op2; - } - - public static bool operator != (OpCode one, OpCode other) - { - return one.op1 != other.op1 || one.op2 != other.op2; - } - - public override string ToString () - { - return Name; - } - } - - static class OpCodeNames { - - internal static readonly string [] names; - - static OpCodeNames () - { - var table = new byte [] { - 3, 110, 111, 112, - 5, 98, 114, 101, 97, 107, - 7, 108, 100, 97, 114, 103, 46, 48, - 7, 108, 100, 97, 114, 103, 46, 49, - 7, 108, 100, 97, 114, 103, 46, 50, - 7, 108, 100, 97, 114, 103, 46, 51, - 7, 108, 100, 108, 111, 99, 46, 48, - 7, 108, 100, 108, 111, 99, 46, 49, - 7, 108, 100, 108, 111, 99, 46, 50, - 7, 108, 100, 108, 111, 99, 46, 51, - 7, 115, 116, 108, 111, 99, 46, 48, - 7, 115, 116, 108, 111, 99, 46, 49, - 7, 115, 116, 108, 111, 99, 46, 50, - 7, 115, 116, 108, 111, 99, 46, 51, - 7, 108, 100, 97, 114, 103, 46, 115, - 8, 108, 100, 97, 114, 103, 97, 46, 115, - 7, 115, 116, 97, 114, 103, 46, 115, - 7, 108, 100, 108, 111, 99, 46, 115, - 8, 108, 100, 108, 111, 99, 97, 46, 115, - 7, 115, 116, 108, 111, 99, 46, 115, - 6, 108, 100, 110, 117, 108, 108, - 9, 108, 100, 99, 46, 105, 52, 46, 109, 49, - 8, 108, 100, 99, 46, 105, 52, 46, 48, - 8, 108, 100, 99, 46, 105, 52, 46, 49, - 8, 108, 100, 99, 46, 105, 52, 46, 50, - 8, 108, 100, 99, 46, 105, 52, 46, 51, - 8, 108, 100, 99, 46, 105, 52, 46, 52, - 8, 108, 100, 99, 46, 105, 52, 46, 53, - 8, 108, 100, 99, 46, 105, 52, 46, 54, - 8, 108, 100, 99, 46, 105, 52, 46, 55, - 8, 108, 100, 99, 46, 105, 52, 46, 56, - 8, 108, 100, 99, 46, 105, 52, 46, 115, - 6, 108, 100, 99, 46, 105, 52, - 6, 108, 100, 99, 46, 105, 56, - 6, 108, 100, 99, 46, 114, 52, - 6, 108, 100, 99, 46, 114, 56, - 3, 100, 117, 112, - 3, 112, 111, 112, - 3, 106, 109, 112, - 4, 99, 97, 108, 108, - 5, 99, 97, 108, 108, 105, - 3, 114, 101, 116, - 4, 98, 114, 46, 115, - 9, 98, 114, 102, 97, 108, 115, 101, 46, 115, - 8, 98, 114, 116, 114, 117, 101, 46, 115, - 5, 98, 101, 113, 46, 115, - 5, 98, 103, 101, 46, 115, - 5, 98, 103, 116, 46, 115, - 5, 98, 108, 101, 46, 115, - 5, 98, 108, 116, 46, 115, - 8, 98, 110, 101, 46, 117, 110, 46, 115, - 8, 98, 103, 101, 46, 117, 110, 46, 115, - 8, 98, 103, 116, 46, 117, 110, 46, 115, - 8, 98, 108, 101, 46, 117, 110, 46, 115, - 8, 98, 108, 116, 46, 117, 110, 46, 115, - 2, 98, 114, - 7, 98, 114, 102, 97, 108, 115, 101, - 6, 98, 114, 116, 114, 117, 101, - 3, 98, 101, 113, - 3, 98, 103, 101, - 3, 98, 103, 116, - 3, 98, 108, 101, - 3, 98, 108, 116, - 6, 98, 110, 101, 46, 117, 110, - 6, 98, 103, 101, 46, 117, 110, - 6, 98, 103, 116, 46, 117, 110, - 6, 98, 108, 101, 46, 117, 110, - 6, 98, 108, 116, 46, 117, 110, - 6, 115, 119, 105, 116, 99, 104, - 8, 108, 100, 105, 110, 100, 46, 105, 49, - 8, 108, 100, 105, 110, 100, 46, 117, 49, - 8, 108, 100, 105, 110, 100, 46, 105, 50, - 8, 108, 100, 105, 110, 100, 46, 117, 50, - 8, 108, 100, 105, 110, 100, 46, 105, 52, - 8, 108, 100, 105, 110, 100, 46, 117, 52, - 8, 108, 100, 105, 110, 100, 46, 105, 56, - 7, 108, 100, 105, 110, 100, 46, 105, - 8, 108, 100, 105, 110, 100, 46, 114, 52, - 8, 108, 100, 105, 110, 100, 46, 114, 56, - 9, 108, 100, 105, 110, 100, 46, 114, 101, 102, - 9, 115, 116, 105, 110, 100, 46, 114, 101, 102, - 8, 115, 116, 105, 110, 100, 46, 105, 49, - 8, 115, 116, 105, 110, 100, 46, 105, 50, - 8, 115, 116, 105, 110, 100, 46, 105, 52, - 8, 115, 116, 105, 110, 100, 46, 105, 56, - 8, 115, 116, 105, 110, 100, 46, 114, 52, - 8, 115, 116, 105, 110, 100, 46, 114, 56, - 3, 97, 100, 100, - 3, 115, 117, 98, - 3, 109, 117, 108, - 3, 100, 105, 118, - 6, 100, 105, 118, 46, 117, 110, - 3, 114, 101, 109, - 6, 114, 101, 109, 46, 117, 110, - 3, 97, 110, 100, - 2, 111, 114, - 3, 120, 111, 114, - 3, 115, 104, 108, - 3, 115, 104, 114, - 6, 115, 104, 114, 46, 117, 110, - 3, 110, 101, 103, - 3, 110, 111, 116, - 7, 99, 111, 110, 118, 46, 105, 49, - 7, 99, 111, 110, 118, 46, 105, 50, - 7, 99, 111, 110, 118, 46, 105, 52, - 7, 99, 111, 110, 118, 46, 105, 56, - 7, 99, 111, 110, 118, 46, 114, 52, - 7, 99, 111, 110, 118, 46, 114, 56, - 7, 99, 111, 110, 118, 46, 117, 52, - 7, 99, 111, 110, 118, 46, 117, 56, - 8, 99, 97, 108, 108, 118, 105, 114, 116, - 5, 99, 112, 111, 98, 106, - 5, 108, 100, 111, 98, 106, - 5, 108, 100, 115, 116, 114, - 6, 110, 101, 119, 111, 98, 106, - 9, 99, 97, 115, 116, 99, 108, 97, 115, 115, - 6, 105, 115, 105, 110, 115, 116, - 9, 99, 111, 110, 118, 46, 114, 46, 117, 110, - 5, 117, 110, 98, 111, 120, - 5, 116, 104, 114, 111, 119, - 5, 108, 100, 102, 108, 100, - 6, 108, 100, 102, 108, 100, 97, - 5, 115, 116, 102, 108, 100, - 6, 108, 100, 115, 102, 108, 100, - 7, 108, 100, 115, 102, 108, 100, 97, - 6, 115, 116, 115, 102, 108, 100, - 5, 115, 116, 111, 98, 106, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 49, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 50, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 52, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 56, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 49, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 50, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 52, 46, 117, 110, - 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 56, 46, 117, 110, - 13, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 46, 117, 110, - 13, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 46, 117, 110, - 3, 98, 111, 120, - 6, 110, 101, 119, 97, 114, 114, - 5, 108, 100, 108, 101, 110, - 7, 108, 100, 101, 108, 101, 109, 97, - 9, 108, 100, 101, 108, 101, 109, 46, 105, 49, - 9, 108, 100, 101, 108, 101, 109, 46, 117, 49, - 9, 108, 100, 101, 108, 101, 109, 46, 105, 50, - 9, 108, 100, 101, 108, 101, 109, 46, 117, 50, - 9, 108, 100, 101, 108, 101, 109, 46, 105, 52, - 9, 108, 100, 101, 108, 101, 109, 46, 117, 52, - 9, 108, 100, 101, 108, 101, 109, 46, 105, 56, - 8, 108, 100, 101, 108, 101, 109, 46, 105, - 9, 108, 100, 101, 108, 101, 109, 46, 114, 52, - 9, 108, 100, 101, 108, 101, 109, 46, 114, 56, - 10, 108, 100, 101, 108, 101, 109, 46, 114, 101, 102, - 8, 115, 116, 101, 108, 101, 109, 46, 105, - 9, 115, 116, 101, 108, 101, 109, 46, 105, 49, - 9, 115, 116, 101, 108, 101, 109, 46, 105, 50, - 9, 115, 116, 101, 108, 101, 109, 46, 105, 52, - 9, 115, 116, 101, 108, 101, 109, 46, 105, 56, - 9, 115, 116, 101, 108, 101, 109, 46, 114, 52, - 9, 115, 116, 101, 108, 101, 109, 46, 114, 56, - 10, 115, 116, 101, 108, 101, 109, 46, 114, 101, 102, - 10, 108, 100, 101, 108, 101, 109, 46, 97, 110, 121, - 10, 115, 116, 101, 108, 101, 109, 46, 97, 110, 121, - 9, 117, 110, 98, 111, 120, 46, 97, 110, 121, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 49, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 49, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 50, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 50, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 52, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 52, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 56, - 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 56, - 9, 114, 101, 102, 97, 110, 121, 118, 97, 108, - 8, 99, 107, 102, 105, 110, 105, 116, 101, - 8, 109, 107, 114, 101, 102, 97, 110, 121, - 7, 108, 100, 116, 111, 107, 101, 110, - 7, 99, 111, 110, 118, 46, 117, 50, - 7, 99, 111, 110, 118, 46, 117, 49, - 6, 99, 111, 110, 118, 46, 105, - 10, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, - 10, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, - 7, 97, 100, 100, 46, 111, 118, 102, - 10, 97, 100, 100, 46, 111, 118, 102, 46, 117, 110, - 7, 109, 117, 108, 46, 111, 118, 102, - 10, 109, 117, 108, 46, 111, 118, 102, 46, 117, 110, - 7, 115, 117, 98, 46, 111, 118, 102, - 10, 115, 117, 98, 46, 111, 118, 102, 46, 117, 110, - 10, 101, 110, 100, 102, 105, 110, 97, 108, 108, 121, - 5, 108, 101, 97, 118, 101, - 7, 108, 101, 97, 118, 101, 46, 115, - 7, 115, 116, 105, 110, 100, 46, 105, - 6, 99, 111, 110, 118, 46, 117, - 7, 97, 114, 103, 108, 105, 115, 116, - 3, 99, 101, 113, - 3, 99, 103, 116, - 6, 99, 103, 116, 46, 117, 110, - 3, 99, 108, 116, - 6, 99, 108, 116, 46, 117, 110, - 5, 108, 100, 102, 116, 110, - 9, 108, 100, 118, 105, 114, 116, 102, 116, 110, - 5, 108, 100, 97, 114, 103, - 6, 108, 100, 97, 114, 103, 97, - 5, 115, 116, 97, 114, 103, - 5, 108, 100, 108, 111, 99, - 6, 108, 100, 108, 111, 99, 97, - 5, 115, 116, 108, 111, 99, - 8, 108, 111, 99, 97, 108, 108, 111, 99, - 9, 101, 110, 100, 102, 105, 108, 116, 101, 114, - 10, 117, 110, 97, 108, 105, 103, 110, 101, 100, 46, - 9, 118, 111, 108, 97, 116, 105, 108, 101, 46, - 5, 116, 97, 105, 108, 46, - 7, 105, 110, 105, 116, 111, 98, 106, - 12, 99, 111, 110, 115, 116, 114, 97, 105, 110, 101, 100, 46, - 5, 99, 112, 98, 108, 107, - 7, 105, 110, 105, 116, 98, 108, 107, - 3, 110, 111, 46, - 7, 114, 101, 116, 104, 114, 111, 119, - 6, 115, 105, 122, 101, 111, 102, - 10, 114, 101, 102, 97, 110, 121, 116, 121, 112, 101, - 9, 114, 101, 97, 100, 111, 110, 108, 121, 46, - }; - - names = new string [219]; - - for (int i = 0, p = 0; i < names.Length; i++) { - var buffer = new char [table [p++]]; - - for (int j = 0; j < buffer.Length; j++) - buffer [j] = (char) table [p++]; - - names [i] = new string (buffer); - } - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs deleted file mode 100644 index 85712ec8b82..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs +++ /dev/null @@ -1,912 +0,0 @@ -// -// OpCodes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public static class OpCodes { - - internal static readonly OpCode [] OneByteOpCode = new OpCode [0xe0 + 1]; - internal static readonly OpCode [] TwoBytesOpCode = new OpCode [0x1e + 1]; - - public static readonly OpCode Nop = new OpCode ( - 0xff << 0 | 0x00 << 8 | (byte) Code.Nop << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Break = new OpCode ( - 0xff << 0 | 0x01 << 8 | (byte) Code.Break << 16 | (byte) FlowControl.Break << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldarg_0 = new OpCode ( - 0xff << 0 | 0x02 << 8 | (byte) Code.Ldarg_0 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldarg_1 = new OpCode ( - 0xff << 0 | 0x03 << 8 | (byte) Code.Ldarg_1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldarg_2 = new OpCode ( - 0xff << 0 | 0x04 << 8 | (byte) Code.Ldarg_2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldarg_3 = new OpCode ( - 0xff << 0 | 0x05 << 8 | (byte) Code.Ldarg_3 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldloc_0 = new OpCode ( - 0xff << 0 | 0x06 << 8 | (byte) Code.Ldloc_0 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldloc_1 = new OpCode ( - 0xff << 0 | 0x07 << 8 | (byte) Code.Ldloc_1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldloc_2 = new OpCode ( - 0xff << 0 | 0x08 << 8 | (byte) Code.Ldloc_2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldloc_3 = new OpCode ( - 0xff << 0 | 0x09 << 8 | (byte) Code.Ldloc_3 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Stloc_0 = new OpCode ( - 0xff << 0 | 0x0a << 8 | (byte) Code.Stloc_0 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stloc_1 = new OpCode ( - 0xff << 0 | 0x0b << 8 | (byte) Code.Stloc_1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stloc_2 = new OpCode ( - 0xff << 0 | 0x0c << 8 | (byte) Code.Stloc_2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stloc_3 = new OpCode ( - 0xff << 0 | 0x0d << 8 | (byte) Code.Stloc_3 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldarg_S = new OpCode ( - 0xff << 0 | 0x0e << 8 | (byte) Code.Ldarg_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldarga_S = new OpCode ( - 0xff << 0 | 0x0f << 8 | (byte) Code.Ldarga_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Starg_S = new OpCode ( - 0xff << 0 | 0x10 << 8 | (byte) Code.Starg_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineArg << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldloc_S = new OpCode ( - 0xff << 0 | 0x11 << 8 | (byte) Code.Ldloc_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldloca_S = new OpCode ( - 0xff << 0 | 0x12 << 8 | (byte) Code.Ldloca_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Stloc_S = new OpCode ( - 0xff << 0 | 0x13 << 8 | (byte) Code.Stloc_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineVar << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldnull = new OpCode ( - 0xff << 0 | 0x14 << 8 | (byte) Code.Ldnull << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Ldc_I4_M1 = new OpCode ( - 0xff << 0 | 0x15 << 8 | (byte) Code.Ldc_I4_M1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_0 = new OpCode ( - 0xff << 0 | 0x16 << 8 | (byte) Code.Ldc_I4_0 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_1 = new OpCode ( - 0xff << 0 | 0x17 << 8 | (byte) Code.Ldc_I4_1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_2 = new OpCode ( - 0xff << 0 | 0x18 << 8 | (byte) Code.Ldc_I4_2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_3 = new OpCode ( - 0xff << 0 | 0x19 << 8 | (byte) Code.Ldc_I4_3 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_4 = new OpCode ( - 0xff << 0 | 0x1a << 8 | (byte) Code.Ldc_I4_4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_5 = new OpCode ( - 0xff << 0 | 0x1b << 8 | (byte) Code.Ldc_I4_5 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_6 = new OpCode ( - 0xff << 0 | 0x1c << 8 | (byte) Code.Ldc_I4_6 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_7 = new OpCode ( - 0xff << 0 | 0x1d << 8 | (byte) Code.Ldc_I4_7 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_8 = new OpCode ( - 0xff << 0 | 0x1e << 8 | (byte) Code.Ldc_I4_8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4_S = new OpCode ( - 0xff << 0 | 0x1f << 8 | (byte) Code.Ldc_I4_S << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I4 = new OpCode ( - 0xff << 0 | 0x20 << 8 | (byte) Code.Ldc_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldc_I8 = new OpCode ( - 0xff << 0 | 0x21 << 8 | (byte) Code.Ldc_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineI8 << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Ldc_R4 = new OpCode ( - 0xff << 0 | 0x22 << 8 | (byte) Code.Ldc_R4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.ShortInlineR << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushr4 << 24); - - public static readonly OpCode Ldc_R8 = new OpCode ( - 0xff << 0 | 0x23 << 8 | (byte) Code.Ldc_R8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineR << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushr8 << 24); - - public static readonly OpCode Dup = new OpCode ( - 0xff << 0 | 0x25 << 8 | (byte) Code.Dup << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push1_push1 << 24); - - public static readonly OpCode Pop = new OpCode ( - 0xff << 0 | 0x26 << 8 | (byte) Code.Pop << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Jmp = new OpCode ( - 0xff << 0 | 0x27 << 8 | (byte) Code.Jmp << 16 | (byte) FlowControl.Call << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Call = new OpCode ( - 0xff << 0 | 0x28 << 8 | (byte) Code.Call << 16 | (byte) FlowControl.Call << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Varpush << 24); - - public static readonly OpCode Calli = new OpCode ( - 0xff << 0 | 0x29 << 8 | (byte) Code.Calli << 16 | (byte) FlowControl.Call << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineSig << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Varpush << 24); - - public static readonly OpCode Ret = new OpCode ( - 0xff << 0 | 0x2a << 8 | (byte) Code.Ret << 16 | (byte) FlowControl.Return << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Br_S = new OpCode ( - 0xff << 0 | 0x2b << 8 | (byte) Code.Br_S << 16 | (byte) FlowControl.Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Brfalse_S = new OpCode ( - 0xff << 0 | 0x2c << 8 | (byte) Code.Brfalse_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Brtrue_S = new OpCode ( - 0xff << 0 | 0x2d << 8 | (byte) Code.Brtrue_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Beq_S = new OpCode ( - 0xff << 0 | 0x2e << 8 | (byte) Code.Beq_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bge_S = new OpCode ( - 0xff << 0 | 0x2f << 8 | (byte) Code.Bge_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bgt_S = new OpCode ( - 0xff << 0 | 0x30 << 8 | (byte) Code.Bgt_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ble_S = new OpCode ( - 0xff << 0 | 0x31 << 8 | (byte) Code.Ble_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Blt_S = new OpCode ( - 0xff << 0 | 0x32 << 8 | (byte) Code.Blt_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bne_Un_S = new OpCode ( - 0xff << 0 | 0x33 << 8 | (byte) Code.Bne_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bge_Un_S = new OpCode ( - 0xff << 0 | 0x34 << 8 | (byte) Code.Bge_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bgt_Un_S = new OpCode ( - 0xff << 0 | 0x35 << 8 | (byte) Code.Bgt_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ble_Un_S = new OpCode ( - 0xff << 0 | 0x36 << 8 | (byte) Code.Ble_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Blt_Un_S = new OpCode ( - 0xff << 0 | 0x37 << 8 | (byte) Code.Blt_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Br = new OpCode ( - 0xff << 0 | 0x38 << 8 | (byte) Code.Br << 16 | (byte) FlowControl.Branch << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Brfalse = new OpCode ( - 0xff << 0 | 0x39 << 8 | (byte) Code.Brfalse << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Brtrue = new OpCode ( - 0xff << 0 | 0x3a << 8 | (byte) Code.Brtrue << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Beq = new OpCode ( - 0xff << 0 | 0x3b << 8 | (byte) Code.Beq << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bge = new OpCode ( - 0xff << 0 | 0x3c << 8 | (byte) Code.Bge << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bgt = new OpCode ( - 0xff << 0 | 0x3d << 8 | (byte) Code.Bgt << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ble = new OpCode ( - 0xff << 0 | 0x3e << 8 | (byte) Code.Ble << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Blt = new OpCode ( - 0xff << 0 | 0x3f << 8 | (byte) Code.Blt << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bne_Un = new OpCode ( - 0xff << 0 | 0x40 << 8 | (byte) Code.Bne_Un << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bge_Un = new OpCode ( - 0xff << 0 | 0x41 << 8 | (byte) Code.Bge_Un << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Bgt_Un = new OpCode ( - 0xff << 0 | 0x42 << 8 | (byte) Code.Bgt_Un << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ble_Un = new OpCode ( - 0xff << 0 | 0x43 << 8 | (byte) Code.Ble_Un << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Blt_Un = new OpCode ( - 0xff << 0 | 0x44 << 8 | (byte) Code.Blt_Un << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Switch = new OpCode ( - 0xff << 0 | 0x45 << 8 | (byte) Code.Switch << 16 | (byte) FlowControl.Cond_Branch << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineSwitch << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldind_I1 = new OpCode ( - 0xff << 0 | 0x46 << 8 | (byte) Code.Ldind_I1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_U1 = new OpCode ( - 0xff << 0 | 0x47 << 8 | (byte) Code.Ldind_U1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_I2 = new OpCode ( - 0xff << 0 | 0x48 << 8 | (byte) Code.Ldind_I2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_U2 = new OpCode ( - 0xff << 0 | 0x49 << 8 | (byte) Code.Ldind_U2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_I4 = new OpCode ( - 0xff << 0 | 0x4a << 8 | (byte) Code.Ldind_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_U4 = new OpCode ( - 0xff << 0 | 0x4b << 8 | (byte) Code.Ldind_U4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_I8 = new OpCode ( - 0xff << 0 | 0x4c << 8 | (byte) Code.Ldind_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Ldind_I = new OpCode ( - 0xff << 0 | 0x4d << 8 | (byte) Code.Ldind_I << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldind_R4 = new OpCode ( - 0xff << 0 | 0x4e << 8 | (byte) Code.Ldind_R4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushr4 << 24); - - public static readonly OpCode Ldind_R8 = new OpCode ( - 0xff << 0 | 0x4f << 8 | (byte) Code.Ldind_R8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushr8 << 24); - - public static readonly OpCode Ldind_Ref = new OpCode ( - 0xff << 0 | 0x50 << 8 | (byte) Code.Ldind_Ref << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Stind_Ref = new OpCode ( - 0xff << 0 | 0x51 << 8 | (byte) Code.Stind_Ref << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_I1 = new OpCode ( - 0xff << 0 | 0x52 << 8 | (byte) Code.Stind_I1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_I2 = new OpCode ( - 0xff << 0 | 0x53 << 8 | (byte) Code.Stind_I2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_I4 = new OpCode ( - 0xff << 0 | 0x54 << 8 | (byte) Code.Stind_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_I8 = new OpCode ( - 0xff << 0 | 0x55 << 8 | (byte) Code.Stind_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi8 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_R4 = new OpCode ( - 0xff << 0 | 0x56 << 8 | (byte) Code.Stind_R4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popr4 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_R8 = new OpCode ( - 0xff << 0 | 0x57 << 8 | (byte) Code.Stind_R8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popr8 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Add = new OpCode ( - 0xff << 0 | 0x58 << 8 | (byte) Code.Add << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Sub = new OpCode ( - 0xff << 0 | 0x59 << 8 | (byte) Code.Sub << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Mul = new OpCode ( - 0xff << 0 | 0x5a << 8 | (byte) Code.Mul << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Div = new OpCode ( - 0xff << 0 | 0x5b << 8 | (byte) Code.Div << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Div_Un = new OpCode ( - 0xff << 0 | 0x5c << 8 | (byte) Code.Div_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Rem = new OpCode ( - 0xff << 0 | 0x5d << 8 | (byte) Code.Rem << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Rem_Un = new OpCode ( - 0xff << 0 | 0x5e << 8 | (byte) Code.Rem_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode And = new OpCode ( - 0xff << 0 | 0x5f << 8 | (byte) Code.And << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Or = new OpCode ( - 0xff << 0 | 0x60 << 8 | (byte) Code.Or << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Xor = new OpCode ( - 0xff << 0 | 0x61 << 8 | (byte) Code.Xor << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Shl = new OpCode ( - 0xff << 0 | 0x62 << 8 | (byte) Code.Shl << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Shr = new OpCode ( - 0xff << 0 | 0x63 << 8 | (byte) Code.Shr << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Shr_Un = new OpCode ( - 0xff << 0 | 0x64 << 8 | (byte) Code.Shr_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Neg = new OpCode ( - 0xff << 0 | 0x65 << 8 | (byte) Code.Neg << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Not = new OpCode ( - 0xff << 0 | 0x66 << 8 | (byte) Code.Not << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Conv_I1 = new OpCode ( - 0xff << 0 | 0x67 << 8 | (byte) Code.Conv_I1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_I2 = new OpCode ( - 0xff << 0 | 0x68 << 8 | (byte) Code.Conv_I2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_I4 = new OpCode ( - 0xff << 0 | 0x69 << 8 | (byte) Code.Conv_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_I8 = new OpCode ( - 0xff << 0 | 0x6a << 8 | (byte) Code.Conv_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Conv_R4 = new OpCode ( - 0xff << 0 | 0x6b << 8 | (byte) Code.Conv_R4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr4 << 24); - - public static readonly OpCode Conv_R8 = new OpCode ( - 0xff << 0 | 0x6c << 8 | (byte) Code.Conv_R8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr8 << 24); - - public static readonly OpCode Conv_U4 = new OpCode ( - 0xff << 0 | 0x6d << 8 | (byte) Code.Conv_U4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_U8 = new OpCode ( - 0xff << 0 | 0x6e << 8 | (byte) Code.Conv_U8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Callvirt = new OpCode ( - 0xff << 0 | 0x6f << 8 | (byte) Code.Callvirt << 16 | (byte) FlowControl.Call << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Varpush << 24); - - public static readonly OpCode Cpobj = new OpCode ( - 0xff << 0 | 0x70 << 8 | (byte) Code.Cpobj << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldobj = new OpCode ( - 0xff << 0 | 0x71 << 8 | (byte) Code.Ldobj << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldstr = new OpCode ( - 0xff << 0 | 0x72 << 8 | (byte) Code.Ldstr << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineString << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Newobj = new OpCode ( - 0xff << 0 | 0x73 << 8 | (byte) Code.Newobj << 16 | (byte) FlowControl.Call << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Castclass = new OpCode ( - 0xff << 0 | 0x74 << 8 | (byte) Code.Castclass << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Isinst = new OpCode ( - 0xff << 0 | 0x75 << 8 | (byte) Code.Isinst << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_R_Un = new OpCode ( - 0xff << 0 | 0x76 << 8 | (byte) Code.Conv_R_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr8 << 24); - - public static readonly OpCode Unbox = new OpCode ( - 0xff << 0 | 0x79 << 8 | (byte) Code.Unbox << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Throw = new OpCode ( - 0xff << 0 | 0x7a << 8 | (byte) Code.Throw << 16 | (byte) FlowControl.Throw << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldfld = new OpCode ( - 0xff << 0 | 0x7b << 8 | (byte) Code.Ldfld << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldflda = new OpCode ( - 0xff << 0 | 0x7c << 8 | (byte) Code.Ldflda << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Stfld = new OpCode ( - 0xff << 0 | 0x7d << 8 | (byte) Code.Stfld << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Popref_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldsfld = new OpCode ( - 0xff << 0 | 0x7e << 8 | (byte) Code.Ldsfld << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldsflda = new OpCode ( - 0xff << 0 | 0x7f << 8 | (byte) Code.Ldsflda << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Stsfld = new OpCode ( - 0xff << 0 | 0x80 << 8 | (byte) Code.Stsfld << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stobj = new OpCode ( - 0xff << 0 | 0x81 << 8 | (byte) Code.Stobj << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi_pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Conv_Ovf_I1_Un = new OpCode ( - 0xff << 0 | 0x82 << 8 | (byte) Code.Conv_Ovf_I1_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I2_Un = new OpCode ( - 0xff << 0 | 0x83 << 8 | (byte) Code.Conv_Ovf_I2_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I4_Un = new OpCode ( - 0xff << 0 | 0x84 << 8 | (byte) Code.Conv_Ovf_I4_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I8_Un = new OpCode ( - 0xff << 0 | 0x85 << 8 | (byte) Code.Conv_Ovf_I8_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Conv_Ovf_U1_Un = new OpCode ( - 0xff << 0 | 0x86 << 8 | (byte) Code.Conv_Ovf_U1_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U2_Un = new OpCode ( - 0xff << 0 | 0x87 << 8 | (byte) Code.Conv_Ovf_U2_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U4_Un = new OpCode ( - 0xff << 0 | 0x88 << 8 | (byte) Code.Conv_Ovf_U4_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U8_Un = new OpCode ( - 0xff << 0 | 0x89 << 8 | (byte) Code.Conv_Ovf_U8_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Conv_Ovf_I_Un = new OpCode ( - 0xff << 0 | 0x8a << 8 | (byte) Code.Conv_Ovf_I_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U_Un = new OpCode ( - 0xff << 0 | 0x8b << 8 | (byte) Code.Conv_Ovf_U_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Box = new OpCode ( - 0xff << 0 | 0x8c << 8 | (byte) Code.Box << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Newarr = new OpCode ( - 0xff << 0 | 0x8d << 8 | (byte) Code.Newarr << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Ldlen = new OpCode ( - 0xff << 0 | 0x8e << 8 | (byte) Code.Ldlen << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelema = new OpCode ( - 0xff << 0 | 0x8f << 8 | (byte) Code.Ldelema << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_I1 = new OpCode ( - 0xff << 0 | 0x90 << 8 | (byte) Code.Ldelem_I1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_U1 = new OpCode ( - 0xff << 0 | 0x91 << 8 | (byte) Code.Ldelem_U1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_I2 = new OpCode ( - 0xff << 0 | 0x92 << 8 | (byte) Code.Ldelem_I2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_U2 = new OpCode ( - 0xff << 0 | 0x93 << 8 | (byte) Code.Ldelem_U2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_I4 = new OpCode ( - 0xff << 0 | 0x94 << 8 | (byte) Code.Ldelem_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_U4 = new OpCode ( - 0xff << 0 | 0x95 << 8 | (byte) Code.Ldelem_U4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_I8 = new OpCode ( - 0xff << 0 | 0x96 << 8 | (byte) Code.Ldelem_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Ldelem_I = new OpCode ( - 0xff << 0 | 0x97 << 8 | (byte) Code.Ldelem_I << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldelem_R4 = new OpCode ( - 0xff << 0 | 0x98 << 8 | (byte) Code.Ldelem_R4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushr4 << 24); - - public static readonly OpCode Ldelem_R8 = new OpCode ( - 0xff << 0 | 0x99 << 8 | (byte) Code.Ldelem_R8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushr8 << 24); - - public static readonly OpCode Ldelem_Ref = new OpCode ( - 0xff << 0 | 0x9a << 8 | (byte) Code.Ldelem_Ref << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushref << 24); - - public static readonly OpCode Stelem_I = new OpCode ( - 0xff << 0 | 0x9b << 8 | (byte) Code.Stelem_I << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_I1 = new OpCode ( - 0xff << 0 | 0x9c << 8 | (byte) Code.Stelem_I1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_I2 = new OpCode ( - 0xff << 0 | 0x9d << 8 | (byte) Code.Stelem_I2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_I4 = new OpCode ( - 0xff << 0 | 0x9e << 8 | (byte) Code.Stelem_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_I8 = new OpCode ( - 0xff << 0 | 0x9f << 8 | (byte) Code.Stelem_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi8 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_R4 = new OpCode ( - 0xff << 0 | 0xa0 << 8 | (byte) Code.Stelem_R4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popr4 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_R8 = new OpCode ( - 0xff << 0 | 0xa1 << 8 | (byte) Code.Stelem_R8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popr8 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stelem_Ref = new OpCode ( - 0xff << 0 | 0xa2 << 8 | (byte) Code.Stelem_Ref << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popref << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldelem_Any = new OpCode ( - 0xff << 0 | 0xa3 << 8 | (byte) Code.Ldelem_Any << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Stelem_Any = new OpCode ( - 0xff << 0 | 0xa4 << 8 | (byte) Code.Stelem_Any << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref_popi_popref << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Unbox_Any = new OpCode ( - 0xff << 0 | 0xa5 << 8 | (byte) Code.Unbox_Any << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Conv_Ovf_I1 = new OpCode ( - 0xff << 0 | 0xb3 << 8 | (byte) Code.Conv_Ovf_I1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U1 = new OpCode ( - 0xff << 0 | 0xb4 << 8 | (byte) Code.Conv_Ovf_U1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I2 = new OpCode ( - 0xff << 0 | 0xb5 << 8 | (byte) Code.Conv_Ovf_I2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U2 = new OpCode ( - 0xff << 0 | 0xb6 << 8 | (byte) Code.Conv_Ovf_U2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I4 = new OpCode ( - 0xff << 0 | 0xb7 << 8 | (byte) Code.Conv_Ovf_I4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U4 = new OpCode ( - 0xff << 0 | 0xb8 << 8 | (byte) Code.Conv_Ovf_U4 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I8 = new OpCode ( - 0xff << 0 | 0xb9 << 8 | (byte) Code.Conv_Ovf_I8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Conv_Ovf_U8 = new OpCode ( - 0xff << 0 | 0xba << 8 | (byte) Code.Conv_Ovf_U8 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24); - - public static readonly OpCode Refanyval = new OpCode ( - 0xff << 0 | 0xc2 << 8 | (byte) Code.Refanyval << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ckfinite = new OpCode ( - 0xff << 0 | 0xc3 << 8 | (byte) Code.Ckfinite << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr8 << 24); - - public static readonly OpCode Mkrefany = new OpCode ( - 0xff << 0 | 0xc6 << 8 | (byte) Code.Mkrefany << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldtoken = new OpCode ( - 0xff << 0 | 0xd0 << 8 | (byte) Code.Ldtoken << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineTok << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_U2 = new OpCode ( - 0xff << 0 | 0xd1 << 8 | (byte) Code.Conv_U2 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_U1 = new OpCode ( - 0xff << 0 | 0xd2 << 8 | (byte) Code.Conv_U1 << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_I = new OpCode ( - 0xff << 0 | 0xd3 << 8 | (byte) Code.Conv_I << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_I = new OpCode ( - 0xff << 0 | 0xd4 << 8 | (byte) Code.Conv_Ovf_I << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Conv_Ovf_U = new OpCode ( - 0xff << 0 | 0xd5 << 8 | (byte) Code.Conv_Ovf_U << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Add_Ovf = new OpCode ( - 0xff << 0 | 0xd6 << 8 | (byte) Code.Add_Ovf << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Add_Ovf_Un = new OpCode ( - 0xff << 0 | 0xd7 << 8 | (byte) Code.Add_Ovf_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Mul_Ovf = new OpCode ( - 0xff << 0 | 0xd8 << 8 | (byte) Code.Mul_Ovf << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Mul_Ovf_Un = new OpCode ( - 0xff << 0 | 0xd9 << 8 | (byte) Code.Mul_Ovf_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Sub_Ovf = new OpCode ( - 0xff << 0 | 0xda << 8 | (byte) Code.Sub_Ovf << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Sub_Ovf_Un = new OpCode ( - 0xff << 0 | 0xdb << 8 | (byte) Code.Sub_Ovf_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Endfinally = new OpCode ( - 0xff << 0 | 0xdc << 8 | (byte) Code.Endfinally << 16 | (byte) FlowControl.Return << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Leave = new OpCode ( - 0xff << 0 | 0xdd << 8 | (byte) Code.Leave << 16 | (byte) FlowControl.Branch << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.PopAll << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Leave_S = new OpCode ( - 0xff << 0 | 0xde << 8 | (byte) Code.Leave_S << 16 | (byte) FlowControl.Branch << 24, - (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.PopAll << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Stind_I = new OpCode ( - 0xff << 0 | 0xdf << 8 | (byte) Code.Stind_I << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Conv_U = new OpCode ( - 0xff << 0 | 0xe0 << 8 | (byte) Code.Conv_U << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Arglist = new OpCode ( - 0xfe << 0 | 0x00 << 8 | (byte) Code.Arglist << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ceq = new OpCode ( - 0xfe << 0 | 0x01 << 8 | (byte) Code.Ceq << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Cgt = new OpCode ( - 0xfe << 0 | 0x02 << 8 | (byte) Code.Cgt << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Cgt_Un = new OpCode ( - 0xfe << 0 | 0x03 << 8 | (byte) Code.Cgt_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Clt = new OpCode ( - 0xfe << 0 | 0x04 << 8 | (byte) Code.Clt << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Clt_Un = new OpCode ( - 0xfe << 0 | 0x05 << 8 | (byte) Code.Clt_Un << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldftn = new OpCode ( - 0xfe << 0 | 0x06 << 8 | (byte) Code.Ldftn << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldvirtftn = new OpCode ( - 0xfe << 0 | 0x07 << 8 | (byte) Code.Ldvirtftn << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Ldarg = new OpCode ( - 0xfe << 0 | 0x09 << 8 | (byte) Code.Ldarg << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldarga = new OpCode ( - 0xfe << 0 | 0x0a << 8 | (byte) Code.Ldarga << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Starg = new OpCode ( - 0xfe << 0 | 0x0b << 8 | (byte) Code.Starg << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineArg << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Ldloc = new OpCode ( - 0xfe << 0 | 0x0c << 8 | (byte) Code.Ldloc << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24); - - public static readonly OpCode Ldloca = new OpCode ( - 0xfe << 0 | 0x0d << 8 | (byte) Code.Ldloca << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Stloc = new OpCode ( - 0xfe << 0 | 0x0e << 8 | (byte) Code.Stloc << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineVar << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Localloc = new OpCode ( - 0xfe << 0 | 0x0f << 8 | (byte) Code.Localloc << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Endfilter = new OpCode ( - 0xfe << 0 | 0x11 << 8 | (byte) Code.Endfilter << 16 | (byte) FlowControl.Return << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Unaligned = new OpCode ( - 0xfe << 0 | 0x12 << 8 | (byte) Code.Unaligned << 16 | (byte) FlowControl.Meta << 24, - (byte) OpCodeType.Prefix << 0 | (byte) OperandType.ShortInlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Volatile = new OpCode ( - 0xfe << 0 | 0x13 << 8 | (byte) Code.Volatile << 16 | (byte) FlowControl.Meta << 24, - (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Tail = new OpCode ( - 0xfe << 0 | 0x14 << 8 | (byte) Code.Tail << 16 | (byte) FlowControl.Meta << 24, - (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Initobj = new OpCode ( - 0xfe << 0 | 0x15 << 8 | (byte) Code.Initobj << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Constrained = new OpCode ( - 0xfe << 0 | 0x16 << 8 | (byte) Code.Constrained << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Cpblk = new OpCode ( - 0xfe << 0 | 0x17 << 8 | (byte) Code.Cpblk << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Initblk = new OpCode ( - 0xfe << 0 | 0x18 << 8 | (byte) Code.Initblk << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode No = new OpCode ( - 0xfe << 0 | 0x19 << 8 | (byte) Code.No << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Prefix << 0 | (byte) OperandType.ShortInlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Rethrow = new OpCode ( - 0xfe << 0 | 0x1a << 8 | (byte) Code.Rethrow << 16 | (byte) FlowControl.Throw << 24, - (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - - public static readonly OpCode Sizeof = new OpCode ( - 0xfe << 0 | 0x1c << 8 | (byte) Code.Sizeof << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Refanytype = new OpCode ( - 0xfe << 0 | 0x1d << 8 | (byte) Code.Refanytype << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24); - - public static readonly OpCode Readonly = new OpCode ( - 0xfe << 0 | 0x1e << 8 | (byte) Code.Readonly << 16 | (byte) FlowControl.Next << 24, - (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24); - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs deleted file mode 100644 index ef87e30f136..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -// SequencePoint.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public sealed class SequencePoint { - - Document document; - - int start_line; - int start_column; - int end_line; - int end_column; - - public int StartLine { - get { return start_line; } - set { start_line = value; } - } - - public int StartColumn { - get { return start_column; } - set { start_column = value; } - } - - public int EndLine { - get { return end_line; } - set { end_line = value; } - } - - public int EndColumn { - get { return end_column; } - set { end_column = value; } - } - - public Document Document { - get { return document; } - set { document = value; } - } - - public SequencePoint (Document document) - { - this.document = document; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Symbols.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Symbols.cs deleted file mode 100644 index 426c4a7e1fe..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/Symbols.cs +++ /dev/null @@ -1,277 +0,0 @@ -// -// Symbols.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Runtime.InteropServices; -using SR = System.Reflection; - -using Mono.Collections.Generic; - -namespace Mono.Cecil.Cil { - - [StructLayout (LayoutKind.Sequential)] - public struct ImageDebugDirectory { - public int Characteristics; - public int TimeDateStamp; - public short MajorVersion; - public short MinorVersion; - public int Type; - public int SizeOfData; - public int AddressOfRawData; - public int PointerToRawData; - } - - public sealed class Scope : IVariableDefinitionProvider { - - Instruction start; - Instruction end; - - Collection scopes; - Collection variables; - - public Instruction Start { - get { return start; } - set { start = value; } - } - - public Instruction End { - get { return end; } - set { end = value; } - } - - public bool HasScopes { - get { return !scopes.IsNullOrEmpty (); } - } - - public Collection Scopes { - get { - if (scopes == null) - scopes = new Collection (); - - return scopes; - } - } - - public bool HasVariables { - get { return !variables.IsNullOrEmpty (); } - } - - public Collection Variables { - get { - if (variables == null) - variables = new Collection (); - - return variables; - } - } - } - - public struct InstructionSymbol { - - public readonly int Offset; - public readonly SequencePoint SequencePoint; - - public InstructionSymbol (int offset, SequencePoint sequencePoint) - { - this.Offset = offset; - this.SequencePoint = sequencePoint; - } - } - - public sealed class MethodSymbols { - - internal int code_size; - internal string method_name; - internal MetadataToken method_token; - internal MetadataToken local_var_token; - internal Collection variables; - internal Collection instructions; - - public bool HasVariables { - get { return !variables.IsNullOrEmpty (); } - } - - public Collection Variables { - get { - if (variables == null) - variables = new Collection (); - - return variables; - } - } - - public Collection Instructions { - get { - if (instructions == null) - instructions = new Collection (); - - return instructions; - } - } - - public int CodeSize { - get { return code_size; } - } - - public string MethodName { - get { return method_name; } - } - - public MetadataToken MethodToken { - get { return method_token; } - } - - public MetadataToken LocalVarToken { - get { return local_var_token; } - } - - internal MethodSymbols (string methodName) - { - this.method_name = methodName; - } - - public MethodSymbols (MetadataToken methodToken) - { - this.method_token = methodToken; - } - } - - public delegate Instruction InstructionMapper (int offset); - - public interface ISymbolReader : IDisposable { - - bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header); - void Read (MethodBody body, InstructionMapper mapper); - void Read (MethodSymbols symbols); - } - - public interface ISymbolReaderProvider { - - ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName); - ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream); - } - - static class SymbolProvider { - - static readonly string symbol_kind = Type.GetType ("Mono.Runtime") != null ? "Mdb" : "Pdb"; - - static SR.AssemblyName GetPlatformSymbolAssemblyName () - { - var cecil_name = typeof (SymbolProvider).Assembly.GetName (); - - var name = new SR.AssemblyName { - Name = "Mono.Cecil." + symbol_kind, - Version = cecil_name.Version, - }; - - name.SetPublicKeyToken (cecil_name.GetPublicKeyToken ()); - - return name; - } - - static Type GetPlatformType (string fullname) - { - var type = Type.GetType (fullname); - if (type != null) - return type; - - var assembly_name = GetPlatformSymbolAssemblyName (); - - type = Type.GetType (fullname + ", " + assembly_name.FullName); - if (type != null) - return type; - - try { - var assembly = SR.Assembly.Load (assembly_name); - if (assembly != null) - return assembly.GetType (fullname); - } catch (FileNotFoundException) { -#if !CF - } catch (FileLoadException) { -#endif - } - - return null; - } - - static ISymbolReaderProvider reader_provider; - - public static ISymbolReaderProvider GetPlatformReaderProvider () - { - if (reader_provider != null) - return reader_provider; - - var type = GetPlatformType (GetProviderTypeName ("ReaderProvider")); - if (type == null) - return null; - - return reader_provider = (ISymbolReaderProvider) Activator.CreateInstance (type); - } - - static string GetProviderTypeName (string name) - { - return "Mono.Cecil." + symbol_kind + "." + symbol_kind + name; - } - -#if !READ_ONLY - - static ISymbolWriterProvider writer_provider; - - public static ISymbolWriterProvider GetPlatformWriterProvider () - { - if (writer_provider != null) - return writer_provider; - - var type = GetPlatformType (GetProviderTypeName ("WriterProvider")); - if (type == null) - return null; - - return writer_provider = (ISymbolWriterProvider) Activator.CreateInstance (type); - } - -#endif - } - -#if !READ_ONLY - - public interface ISymbolWriter : IDisposable { - - bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header); - void Write (MethodBody body); - void Write (MethodSymbols symbols); - } - - public interface ISymbolWriterProvider { - - ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName); - ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream); - } - -#endif -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs deleted file mode 100644 index f501bca6e72..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs +++ /dev/null @@ -1,52 +0,0 @@ -// -// VariableDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public sealed class VariableDefinition : VariableReference { - - public bool IsPinned { - get { return variable_type.IsPinned; } - } - - public VariableDefinition (TypeReference variableType) - : base (variableType) - { - } - - public VariableDefinition (string name, TypeReference variableType) - : base (name, variableType) - { - } - - public override VariableDefinition Resolve () - { - return this; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs deleted file mode 100644 index ce0b4cdb4cf..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// VariableReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Cil { - - public abstract class VariableReference { - - string name; - internal int index = -1; - protected TypeReference variable_type; - - public string Name { - get { return name; } - set { name = value; } - } - - public TypeReference VariableType { - get { return variable_type; } - set { variable_type = value; } - } - - public int Index { - get { return index; } - } - - internal VariableReference (TypeReference variable_type) - : this (string.Empty, variable_type) - { - } - - internal VariableReference (string name, TypeReference variable_type) - { - this.name = name; - this.variable_type = variable_type; - } - - public abstract VariableDefinition Resolve (); - - public override string ToString () - { - if (!string.IsNullOrEmpty (name)) - return name; - - if (index >= 0) - return "V_" + index; - - return string.Empty; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs deleted file mode 100644 index e7e2928c82a..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// BlobHeap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.PE; - -namespace Mono.Cecil.Metadata { - - sealed class BlobHeap : Heap { - - public BlobHeap (Section section, uint start, uint size) - : base (section, start, size) - { - } - - public byte [] Read (uint index) - { - if (index == 0 || index > Size - 1) - return Empty.Array; - - var data = Section.Data; - - int position = (int) (index + Offset); - int length = (int) data.ReadCompressedUInt32 (ref position); - - var buffer = new byte [length]; - - Buffer.BlockCopy (data, position, buffer, 0, length); - - return buffer; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs deleted file mode 100644 index b63412dea7a..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Buffers.cs +++ /dev/null @@ -1,373 +0,0 @@ -// -// TableHeapBuffer.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; - -using Mono.Cecil.PE; - -using RVA = System.UInt32; - -#if !READ_ONLY - -namespace Mono.Cecil.Metadata { - - sealed class TableHeapBuffer : HeapBuffer { - - readonly ModuleDefinition module; - readonly MetadataBuilder metadata; - - internal MetadataTable [] tables = new MetadataTable [45]; - - bool large_string; - bool large_blob; - readonly int [] coded_index_sizes = new int [13]; - readonly Func counter; - - public override bool IsEmpty { - get { return false; } - } - - public TableHeapBuffer (ModuleDefinition module, MetadataBuilder metadata) - : base (24) - { - this.module = module; - this.metadata = metadata; - this.counter = GetTableLength; - } - - int GetTableLength (Table table) - { - var md_table = tables [(int) table]; - return md_table != null ? md_table.Length : 0; - } - - public TTable GetTable (Table table) where TTable : MetadataTable, new () - { - var md_table = (TTable) tables [(int) table]; - if (md_table != null) - return md_table; - - md_table = new TTable (); - tables [(int) table] = md_table; - return md_table; - } - - public void WriteBySize (uint value, int size) - { - if (size == 4) - WriteUInt32 (value); - else - WriteUInt16 ((ushort) value); - } - - public void WriteBySize (uint value, bool large) - { - if (large) - WriteUInt32 (value); - else - WriteUInt16 ((ushort) value); - } - - public void WriteString (uint @string) - { - WriteBySize (@string, large_string); - } - - public void WriteBlob (uint blob) - { - WriteBySize (blob, large_blob); - } - - public void WriteRID (uint rid, Table table) - { - var md_table = tables [(int) table]; - WriteBySize (rid, md_table == null ? false : md_table.IsLarge); - } - - int GetCodedIndexSize (CodedIndex coded_index) - { - var index = (int) coded_index; - var size = coded_index_sizes [index]; - if (size != 0) - return size; - - return coded_index_sizes [index] = coded_index.GetSize (counter); - } - - public void WriteCodedRID (uint rid, CodedIndex coded_index) - { - WriteBySize (rid, GetCodedIndexSize (coded_index)); - } - - public void WriteTableHeap () - { - WriteUInt32 (0); // Reserved - WriteByte (GetTableHeapVersion ()); // MajorVersion - WriteByte (0); // MinorVersion - WriteByte (GetHeapSizes ()); // HeapSizes - WriteByte (10); // Reserved2 - WriteUInt64 (GetValid ()); // Valid - WriteUInt64 (0x0016003301fa00); // Sorted - - WriteRowCount (); - WriteTables (); - } - - void WriteRowCount () - { - for (int i = 0; i < tables.Length; i++) { - var table = tables [i]; - if (table == null || table.Length == 0) - continue; - - WriteUInt32 ((uint) table.Length); - } - } - - void WriteTables () - { - for (int i = 0; i < tables.Length; i++) { - var table = tables [i]; - if (table == null || table.Length == 0) - continue; - - table.Write (this); - } - } - - ulong GetValid () - { - ulong valid = 0; - - for (int i = 0; i < tables.Length; i++) { - var table = tables [i]; - if (table == null || table.Length == 0) - continue; - - table.Sort (); - valid |= (1UL << i); - } - - return valid; - } - - byte GetHeapSizes () - { - byte heap_sizes = 0; - - if (metadata.string_heap.IsLarge) { - large_string = true; - heap_sizes |= 0x01; - } - - if (metadata.blob_heap.IsLarge) { - large_blob = true; - heap_sizes |= 0x04; - } - - return heap_sizes; - } - - byte GetTableHeapVersion () - { - switch (module.Runtime) { - case TargetRuntime.Net_1_0: - case TargetRuntime.Net_1_1: - return 1; - default: - return 2; - } - } - - public void FixupData (RVA data_rva) - { - var table = GetTable (Table.FieldRVA); - if (table.length == 0) - return; - - var field_idx_size = GetTable (Table.Field).IsLarge ? 4 : 2; - var previous = this.position; - - base.position = table.position; - for (int i = 0; i < table.length; i++) { - var rva = ReadUInt32 (); - base.position -= 4; - WriteUInt32 (rva + data_rva); - base.position += field_idx_size; - } - - base.position = previous; - } - } - - sealed class ResourceBuffer : ByteBuffer { - - public ResourceBuffer () - : base (0) - { - } - - public uint AddResource (byte [] resource) - { - var offset = (uint) this.position; - WriteInt32 (resource.Length); - WriteBytes (resource); - return offset; - } - } - - sealed class DataBuffer : ByteBuffer { - - public DataBuffer () - : base (0) - { - } - - public RVA AddData (byte [] data) - { - var rva = (RVA) position; - WriteBytes (data); - return rva; - } - } - - abstract class HeapBuffer : ByteBuffer { - - public bool IsLarge { - get { return base.length > 65535; } - } - - public abstract bool IsEmpty { get; } - - protected HeapBuffer (int length) - : base (length) - { - } - } - - class StringHeapBuffer : HeapBuffer { - - readonly Dictionary strings = new Dictionary (StringComparer.Ordinal); - - public sealed override bool IsEmpty { - get { return length <= 1; } - } - - public StringHeapBuffer () - : base (1) - { - WriteByte (0); - } - - public uint GetStringIndex (string @string) - { - uint index; - if (strings.TryGetValue (@string, out index)) - return index; - - index = (uint) base.position; - WriteString (@string); - strings.Add (@string, index); - return index; - } - - protected virtual void WriteString (string @string) - { - WriteBytes (Encoding.UTF8.GetBytes (@string)); - WriteByte (0); - } - } - - sealed class BlobHeapBuffer : HeapBuffer { - - readonly Dictionary blobs = new Dictionary (new ByteBufferEqualityComparer ()); - - public override bool IsEmpty { - get { return length <= 1; } - } - - public BlobHeapBuffer () - : base (1) - { - WriteByte (0); - } - - public uint GetBlobIndex (ByteBuffer blob) - { - uint index; - if (blobs.TryGetValue (blob, out index)) - return index; - - index = (uint) base.position; - WriteBlob (blob); - blobs.Add (blob, index); - return index; - } - - void WriteBlob (ByteBuffer blob) - { - WriteCompressedUInt32 ((uint) blob.length); - WriteBytes (blob); - } - } - - sealed class UserStringHeapBuffer : StringHeapBuffer { - - protected override void WriteString (string @string) - { - WriteCompressedUInt32 ((uint) @string.Length * 2 + 1); - - byte special = 0; - - for (int i = 0; i < @string.Length; i++) { - var @char = @string [i]; - WriteUInt16 (@char); - - if (special == 1) - continue; - - if (@char < 0x20 || @char > 0x7e) { - if (@char > 0x7e - || (@char >= 0x01 && @char <= 0x08) - || (@char >= 0x0e && @char <= 0x1f) - || @char == 0x27 - || @char == 0x2d) { - - special = 1; - } - } - } - - WriteByte (special); - } - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs deleted file mode 100644 index 3e30fd87f95..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// CodedIndex.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Metadata { - - enum CodedIndex { - TypeDefOrRef, - HasConstant, - HasCustomAttribute, - HasFieldMarshal, - HasDeclSecurity, - MemberRefParent, - HasSemantics, - MethodDefOrRef, - MemberForwarded, - Implementation, - CustomAttributeType, - ResolutionScope, - TypeOrMethodDef - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs deleted file mode 100644 index 72fc1ccaf23..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// ElementType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil.Metadata { - - enum ElementType : byte { - None = 0x00, - Void = 0x01, - Boolean = 0x02, - Char = 0x03, - I1 = 0x04, - U1 = 0x05, - I2 = 0x06, - U2 = 0x07, - I4 = 0x08, - U4 = 0x09, - I8 = 0x0a, - U8 = 0x0b, - R4 = 0x0c, - R8 = 0x0d, - String = 0x0e, - Ptr = 0x0f, // Followed by token - ByRef = 0x10, // Followed by token - ValueType = 0x11, // Followed by token - Class = 0x12, // Followed by token - Var = 0x13, // Followed by generic parameter number - Array = 0x14, // - GenericInst = 0x15, // ... */ - TypedByRef = 0x16, - I = 0x18, // System.IntPtr - U = 0x19, // System.UIntPtr - FnPtr = 0x1b, // Followed by full method signature - Object = 0x1c, // System.Object - SzArray = 0x1d, // Single-dim array with 0 lower bound - MVar = 0x1e, // Followed by generic parameter number - CModReqD = 0x1f, // Required modifier : followed by a TypeDef or TypeRef token - CModOpt = 0x20, // Optional modifier : followed by a TypeDef or TypeRef token - Internal = 0x21, // Implemented within the CLI - Modifier = 0x40, // Or'd with following element types - Sentinel = 0x41, // Sentinel for varargs method signature - Pinned = 0x45, // Denotes a local variable that points at a pinned object - - // special undocumented constants - Type = 0x50, - Boxed = 0x51, - Enum = 0x55 - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs deleted file mode 100644 index 1adc0795ee9..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// GuidHeap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.PE; - -namespace Mono.Cecil.Metadata { - - sealed class GuidHeap : Heap { - - public GuidHeap (Section section, uint start, uint size) - : base (section, start, size) - { - } - - public Guid Read (uint index) - { - if (index == 0) - return new Guid (); - - const int guid_size = 16; - - var buffer = new byte [guid_size]; - - index--; - - Buffer.BlockCopy (Section.Data, (int) (Offset + index), buffer, 0, guid_size); - - return new Guid (buffer); - - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Heap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Heap.cs deleted file mode 100644 index bc21acde250..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Heap.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -// Heap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Cecil.PE; - -namespace Mono.Cecil.Metadata { - - abstract class Heap { - - public int IndexSize; - - public readonly Section Section; - public readonly uint Offset; - public readonly uint Size; - - protected Heap (Section section, uint offset, uint size) - { - this.Section = section; - this.Offset = offset; - this.Size = size; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs deleted file mode 100644 index bda56b0f4fa..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs +++ /dev/null @@ -1,105 +0,0 @@ -// -// MetadataToken.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public struct MetadataToken { - - readonly uint token; - - public uint RID { - get { return token & 0x00ffffff; } - } - - public TokenType TokenType { - get { return (TokenType) (token & 0xff000000); } - } - - public static readonly MetadataToken Zero = new MetadataToken ((uint) 0); - - public MetadataToken (uint token) - { - this.token = token; - } - - public MetadataToken (TokenType type) - : this (type, 0) - { - } - - public MetadataToken (TokenType type, uint rid) - { - token = (uint) type | rid; - } - - public MetadataToken (TokenType type, int rid) - { - token = (uint) type | (uint) rid; - } - - public int ToInt32 () - { - return (int) token; - } - - public uint ToUInt32 () - { - return token; - } - - public override int GetHashCode () - { - return (int) token; - } - - public override bool Equals (object obj) - { - if (obj is MetadataToken) { - var other = (MetadataToken) obj; - return other.token == token; - } - - return false; - } - - public static bool operator == (MetadataToken one, MetadataToken other) - { - return one.token == other.token; - } - - public static bool operator != (MetadataToken one, MetadataToken other) - { - return one.token != other.token; - } - - public override string ToString () - { - return string.Format ("[{0}:0x{1}]", TokenType, RID.ToString ("x4")); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Row.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Row.cs deleted file mode 100644 index dfda00a7778..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Row.cs +++ /dev/null @@ -1,170 +0,0 @@ -// -// Row.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections.Generic; - -namespace Mono.Cecil.Metadata { - - struct Row { - internal T1 Col1; - internal T2 Col2; - - public Row (T1 col1, T2 col2) - { - Col1 = col1; - Col2 = col2; - } - } - - struct Row { - internal T1 Col1; - internal T2 Col2; - internal T3 Col3; - - public Row (T1 col1, T2 col2, T3 col3) - { - Col1 = col1; - Col2 = col2; - Col3 = col3; - } - } - - struct Row { - internal T1 Col1; - internal T2 Col2; - internal T3 Col3; - internal T4 Col4; - - public Row (T1 col1, T2 col2, T3 col3, T4 col4) - { - Col1 = col1; - Col2 = col2; - Col3 = col3; - Col4 = col4; - } - } - - struct Row { - internal T1 Col1; - internal T2 Col2; - internal T3 Col3; - internal T4 Col4; - internal T5 Col5; - - public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5) - { - Col1 = col1; - Col2 = col2; - Col3 = col3; - Col4 = col4; - Col5 = col5; - } - } - - struct Row { - internal T1 Col1; - internal T2 Col2; - internal T3 Col3; - internal T4 Col4; - internal T5 Col5; - internal T6 Col6; - - public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5, T6 col6) - { - Col1 = col1; - Col2 = col2; - Col3 = col3; - Col4 = col4; - Col5 = col5; - Col6 = col6; - } - } - - struct Row { - internal T1 Col1; - internal T2 Col2; - internal T3 Col3; - internal T4 Col4; - internal T5 Col5; - internal T6 Col6; - internal T7 Col7; - internal T8 Col8; - internal T9 Col9; - - public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5, T6 col6, T7 col7, T8 col8, T9 col9) - { - Col1 = col1; - Col2 = col2; - Col3 = col3; - Col4 = col4; - Col5 = col5; - Col6 = col6; - Col7 = col7; - Col8 = col8; - Col9 = col9; - } - } - - sealed class RowEqualityComparer : IEqualityComparer>, IEqualityComparer>, IEqualityComparer> { - - public bool Equals (Row x, Row y) - { - return x.Col1 == y.Col1 - && x.Col2 == y.Col2; - } - - public int GetHashCode (Row obj) - { - string x = obj.Col1, y = obj.Col2; - return (x != null ? x.GetHashCode () : 0) ^ (y != null ? y.GetHashCode () : 0); - } - - public bool Equals (Row x, Row y) - { - return x.Col1 == y.Col1 - && x.Col2 == y.Col2; - } - - public int GetHashCode (Row obj) - { - return (int) (obj.Col1 ^ obj.Col2); - } - - public bool Equals (Row x, Row y) - { - return x.Col1 == y.Col1 - && x.Col2 == y.Col2 - && x.Col3 == y.Col3; - } - - public int GetHashCode (Row obj) - { - return (int) (obj.Col1 ^ obj.Col2 ^ obj.Col3); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/StringHeap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/StringHeap.cs deleted file mode 100644 index 4a0a0af4359..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/StringHeap.cs +++ /dev/null @@ -1,81 +0,0 @@ -// -// StringHeap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; - -using Mono.Cecil.PE; - -namespace Mono.Cecil.Metadata { - - class StringHeap : Heap { - - readonly Dictionary strings = new Dictionary (); - - public StringHeap (Section section, uint start, uint size) - : base (section, start, size) - { - } - - public string Read (uint index) - { - if (index == 0) - return string.Empty; - - string @string; - if (strings.TryGetValue (index, out @string)) - return @string; - - if (index > Size - 1) - return string.Empty; - - @string = ReadStringAt (index); - if (@string.Length != 0) - strings.Add (index, @string); - - return @string; - } - - protected virtual string ReadStringAt (uint index) - { - int length = 0; - byte [] data = Section.Data; - int start = (int) (index + Offset); - - for (int i = start; ; i++) { - if (data [i] == 0) - break; - - length++; - } - - return Encoding.UTF8.GetString (data, start, length); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TableHeap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TableHeap.cs deleted file mode 100644 index 9bc0edd36c1..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TableHeap.cs +++ /dev/null @@ -1,111 +0,0 @@ -// -// TableHeap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using Mono.Cecil.PE; - -namespace Mono.Cecil.Metadata { - - enum Table : byte { - Module = 0x00, - TypeRef = 0x01, - TypeDef = 0x02, - FieldPtr = 0x03, - Field = 0x04, - MethodPtr = 0x05, - Method = 0x06, - ParamPtr = 0x07, - Param = 0x08, - InterfaceImpl = 0x09, - MemberRef = 0x0a, - Constant = 0x0b, - CustomAttribute = 0x0c, - FieldMarshal = 0x0d, - DeclSecurity = 0x0e, - ClassLayout = 0x0f, - FieldLayout = 0x10, - StandAloneSig = 0x11, - EventMap = 0x12, - EventPtr = 0x13, - Event = 0x14, - PropertyMap = 0x15, - PropertyPtr = 0x16, - Property = 0x17, - MethodSemantics = 0x18, - MethodImpl = 0x19, - ModuleRef = 0x1a, - TypeSpec = 0x1b, - ImplMap = 0x1c, - FieldRVA = 0x1d, - EncLog = 0x1e, - EncMap = 0x1f, - Assembly = 0x20, - AssemblyProcessor = 0x21, - AssemblyOS = 0x22, - AssemblyRef = 0x23, - AssemblyRefProcessor = 0x24, - AssemblyRefOS = 0x25, - File = 0x26, - ExportedType = 0x27, - ManifestResource = 0x28, - NestedClass = 0x29, - GenericParam = 0x2a, - MethodSpec = 0x2b, - GenericParamConstraint = 0x2c, - } - - struct TableInformation { - public uint Offset; - public uint Length; - public uint RowSize; - } - - sealed class TableHeap : Heap { - - public long Valid; - public long Sorted; - - public const int TableCount = 45; - - public readonly TableInformation [] Tables = new TableInformation [TableCount]; - - public TableInformation this [Table table] { - get { return Tables [(int) table]; } - } - - public TableHeap (Section section, uint start, uint size) - : base (section, start, size) - { - } - - public bool HasTable (Table table) - { - return (Valid & (1L << (int) table)) != 0; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs deleted file mode 100644 index 2c2010ff971..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// TokenType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum TokenType : uint { - Module = 0x00000000, - TypeRef = 0x01000000, - TypeDef = 0x02000000, - Field = 0x04000000, - Method = 0x06000000, - Param = 0x08000000, - InterfaceImpl = 0x09000000, - MemberRef = 0x0a000000, - CustomAttribute = 0x0c000000, - Permission = 0x0e000000, - Signature = 0x11000000, - Event = 0x14000000, - Property = 0x17000000, - ModuleRef = 0x1a000000, - TypeSpec = 0x1b000000, - Assembly = 0x20000000, - AssemblyRef = 0x23000000, - File = 0x26000000, - ExportedType = 0x27000000, - ManifestResource = 0x28000000, - GenericParam = 0x2a000000, - MethodSpec = 0x2b000000, - String = 0x70000000, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/UserStringHeap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/UserStringHeap.cs deleted file mode 100644 index 59105087ff3..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/UserStringHeap.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// UserStringHeap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.PE; - -namespace Mono.Cecil.Metadata { - - sealed class UserStringHeap : StringHeap { - - public UserStringHeap (Section section, uint start, uint size) - : base (section, start, size) - { - } - - protected override string ReadStringAt (uint index) - { - byte [] data = Section.Data; - int start = (int) (index + Offset); - - uint length = (uint) (data.ReadCompressedUInt32 (ref start) & ~1); - if (length < 1) - return string.Empty; - - var chars = new char [length / 2]; - - for (int i = start, j = 0; i < start + length; i += 2) - chars [j++] = (char) (data [i] | (data [i + 1] << 8)); - - return new string (chars); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs b/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs deleted file mode 100644 index d752b24b110..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs +++ /dev/null @@ -1,529 +0,0 @@ -// -// Utilities.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - static partial class Mixin { - - public static uint ReadCompressedUInt32 (this byte [] data, ref int position) - { - uint integer; - if ((data [position] & 0x80) == 0) { - integer = data [position]; - position++; - } else if ((data [position] & 0x40) == 0) { - integer = (uint) (data [position] & ~0x80) << 8; - integer |= data [position + 1]; - position += 2; - } else { - integer = (uint) (data [position] & ~0xc0) << 24; - integer |= (uint) data [position + 1] << 16; - integer |= (uint) data [position + 2] << 8; - integer |= (uint) data [position + 3]; - position += 4; - } - return integer; - } - - public static MetadataToken GetMetadataToken (this CodedIndex self, uint data) - { - uint rid; - TokenType token_type; - switch (self) { - case CodedIndex.TypeDefOrRef: - rid = data >> 2; - switch (data & 3) { - case 0: - token_type = TokenType.TypeDef; goto ret; - case 1: - token_type = TokenType.TypeRef; goto ret; - case 2: - token_type = TokenType.TypeSpec; goto ret; - default: - goto exit; - } - case CodedIndex.HasConstant: - rid = data >> 2; - switch (data & 3) { - case 0: - token_type = TokenType.Field; goto ret; - case 1: - token_type = TokenType.Param; goto ret; - case 2: - token_type = TokenType.Property; goto ret; - default: - goto exit; - } - case CodedIndex.HasCustomAttribute: - rid = data >> 5; - switch (data & 31) { - case 0: - token_type = TokenType.Method; goto ret; - case 1: - token_type = TokenType.Field; goto ret; - case 2: - token_type = TokenType.TypeRef; goto ret; - case 3: - token_type = TokenType.TypeDef; goto ret; - case 4: - token_type = TokenType.Param; goto ret; - case 5: - token_type = TokenType.InterfaceImpl; goto ret; - case 6: - token_type = TokenType.MemberRef; goto ret; - case 7: - token_type = TokenType.Module; goto ret; - case 8: - token_type = TokenType.Permission; goto ret; - case 9: - token_type = TokenType.Property; goto ret; - case 10: - token_type = TokenType.Event; goto ret; - case 11: - token_type = TokenType.Signature; goto ret; - case 12: - token_type = TokenType.ModuleRef; goto ret; - case 13: - token_type = TokenType.TypeSpec; goto ret; - case 14: - token_type = TokenType.Assembly; goto ret; - case 15: - token_type = TokenType.AssemblyRef; goto ret; - case 16: - token_type = TokenType.File; goto ret; - case 17: - token_type = TokenType.ExportedType; goto ret; - case 18: - token_type = TokenType.ManifestResource; goto ret; - case 19: - token_type = TokenType.GenericParam; goto ret; - default: - goto exit; - } - case CodedIndex.HasFieldMarshal: - rid = data >> 1; - switch (data & 1) { - case 0: - token_type = TokenType.Field; goto ret; - case 1: - token_type = TokenType.Param; goto ret; - default: - goto exit; - } - case CodedIndex.HasDeclSecurity: - rid = data >> 2; - switch (data & 3) { - case 0: - token_type = TokenType.TypeDef; goto ret; - case 1: - token_type = TokenType.Method; goto ret; - case 2: - token_type = TokenType.Assembly; goto ret; - default: - goto exit; - } - case CodedIndex.MemberRefParent: - rid = data >> 3; - switch (data & 7) { - case 0: - token_type = TokenType.TypeDef; goto ret; - case 1: - token_type = TokenType.TypeRef; goto ret; - case 2: - token_type = TokenType.ModuleRef; goto ret; - case 3: - token_type = TokenType.Method; goto ret; - case 4: - token_type = TokenType.TypeSpec; goto ret; - default: - goto exit; - } - case CodedIndex.HasSemantics: - rid = data >> 1; - switch (data & 1) { - case 0: - token_type = TokenType.Event; goto ret; - case 1: - token_type = TokenType.Property; goto ret; - default: - goto exit; - } - case CodedIndex.MethodDefOrRef: - rid = data >> 1; - switch (data & 1) { - case 0: - token_type = TokenType.Method; goto ret; - case 1: - token_type = TokenType.MemberRef; goto ret; - default: - goto exit; - } - case CodedIndex.MemberForwarded: - rid = data >> 1; - switch (data & 1) { - case 0: - token_type = TokenType.Field; goto ret; - case 1: - token_type = TokenType.Method; goto ret; - default: - goto exit; - } - case CodedIndex.Implementation: - rid = data >> 2; - switch (data & 3) { - case 0: - token_type = TokenType.File; goto ret; - case 1: - token_type = TokenType.AssemblyRef; goto ret; - case 2: - token_type = TokenType.ExportedType; goto ret; - default: - goto exit; - } - case CodedIndex.CustomAttributeType: - rid = data >> 3; - switch (data & 7) { - case 2: - token_type = TokenType.Method; goto ret; - case 3: - token_type = TokenType.MemberRef; goto ret; - default: - goto exit; - } - case CodedIndex.ResolutionScope: - rid = data >> 2; - switch (data & 3) { - case 0: - token_type = TokenType.Module; goto ret; - case 1: - token_type = TokenType.ModuleRef; goto ret; - case 2: - token_type = TokenType.AssemblyRef; goto ret; - case 3: - token_type = TokenType.TypeRef; goto ret; - default: - goto exit; - } - case CodedIndex.TypeOrMethodDef: - rid = data >> 1; - switch (data & 1) { - case 0: - token_type = TokenType.TypeDef; goto ret; - case 1: - token_type = TokenType.Method; goto ret; - default: goto exit; - } - default: - goto exit; - } - ret: - return new MetadataToken (token_type, rid); - exit: - return MetadataToken.Zero; - } - -#if !READ_ONLY - public static uint CompressMetadataToken (this CodedIndex self, MetadataToken token) - { - uint ret = 0; - if (token.RID == 0) - return ret; - switch (self) { - case CodedIndex.TypeDefOrRef: - ret = token.RID << 2; - switch (token.TokenType) { - case TokenType.TypeDef: - return ret | 0; - case TokenType.TypeRef: - return ret | 1; - case TokenType.TypeSpec: - return ret | 2; - default: - goto exit; - } - case CodedIndex.HasConstant: - ret = token.RID << 2; - switch (token.TokenType) { - case TokenType.Field: - return ret | 0; - case TokenType.Param: - return ret | 1; - case TokenType.Property: - return ret | 2; - default: - goto exit; - } - case CodedIndex.HasCustomAttribute: - ret = token.RID << 5; - switch (token.TokenType) { - case TokenType.Method: - return ret | 0; - case TokenType.Field: - return ret | 1; - case TokenType.TypeRef: - return ret | 2; - case TokenType.TypeDef: - return ret | 3; - case TokenType.Param: - return ret | 4; - case TokenType.InterfaceImpl: - return ret | 5; - case TokenType.MemberRef: - return ret | 6; - case TokenType.Module: - return ret | 7; - case TokenType.Permission: - return ret | 8; - case TokenType.Property: - return ret | 9; - case TokenType.Event: - return ret | 10; - case TokenType.Signature: - return ret | 11; - case TokenType.ModuleRef: - return ret | 12; - case TokenType.TypeSpec: - return ret | 13; - case TokenType.Assembly: - return ret | 14; - case TokenType.AssemblyRef: - return ret | 15; - case TokenType.File: - return ret | 16; - case TokenType.ExportedType: - return ret | 17; - case TokenType.ManifestResource: - return ret | 18; - case TokenType.GenericParam: - return ret | 19; - default: - goto exit; - } - case CodedIndex.HasFieldMarshal: - ret = token.RID << 1; - switch (token.TokenType) { - case TokenType.Field: - return ret | 0; - case TokenType.Param: - return ret | 1; - default: - goto exit; - } - case CodedIndex.HasDeclSecurity: - ret = token.RID << 2; - switch (token.TokenType) { - case TokenType.TypeDef: - return ret | 0; - case TokenType.Method: - return ret | 1; - case TokenType.Assembly: - return ret | 2; - default: - goto exit; - } - case CodedIndex.MemberRefParent: - ret = token.RID << 3; - switch (token.TokenType) { - case TokenType.TypeDef: - return ret | 0; - case TokenType.TypeRef: - return ret | 1; - case TokenType.ModuleRef: - return ret | 2; - case TokenType.Method: - return ret | 3; - case TokenType.TypeSpec: - return ret | 4; - default: - goto exit; - } - case CodedIndex.HasSemantics: - ret = token.RID << 1; - switch (token.TokenType) { - case TokenType.Event: - return ret | 0; - case TokenType.Property: - return ret | 1; - default: - goto exit; - } - case CodedIndex.MethodDefOrRef: - ret = token.RID << 1; - switch (token.TokenType) { - case TokenType.Method: - return ret | 0; - case TokenType.MemberRef: - return ret | 1; - default: - goto exit; - } - case CodedIndex.MemberForwarded: - ret = token.RID << 1; - switch (token.TokenType) { - case TokenType.Field: - return ret | 0; - case TokenType.Method: - return ret | 1; - default: - goto exit; - } - case CodedIndex.Implementation: - ret = token.RID << 2; - switch (token.TokenType) { - case TokenType.File: - return ret | 0; - case TokenType.AssemblyRef: - return ret | 1; - case TokenType.ExportedType: - return ret | 2; - default: - goto exit; - } - case CodedIndex.CustomAttributeType: - ret = token.RID << 3; - switch (token.TokenType) { - case TokenType.Method: - return ret | 2; - case TokenType.MemberRef: - return ret | 3; - default: - goto exit; - } - case CodedIndex.ResolutionScope: - ret = token.RID << 2; - switch (token.TokenType) { - case TokenType.Module: - return ret | 0; - case TokenType.ModuleRef: - return ret | 1; - case TokenType.AssemblyRef: - return ret | 2; - case TokenType.TypeRef: - return ret | 3; - default: - goto exit; - } - case CodedIndex.TypeOrMethodDef: - ret = token.RID << 1; - switch (token.TokenType) { - case TokenType.TypeDef: - return ret | 0; - case TokenType.Method: - return ret | 1; - default: - goto exit; - } - default: - goto exit; - } - exit: - throw new ArgumentException (); - } -#endif - - public static int GetSize (this CodedIndex self, Func counter) - { - int bits; - Table [] tables; - - switch (self) { - case CodedIndex.TypeDefOrRef: - bits = 2; - tables = new [] { Table.TypeDef, Table.TypeRef, Table.TypeSpec }; - break; - case CodedIndex.HasConstant: - bits = 2; - tables = new [] { Table.Field, Table.Param, Table.Property }; - break; - case CodedIndex.HasCustomAttribute: - bits = 5; - tables = new [] { - Table.Method, Table.Field, Table.TypeRef, Table.TypeDef, Table.Param, Table.InterfaceImpl, Table.MemberRef, - Table.Module, Table.DeclSecurity, Table.Property, Table.Event, Table.StandAloneSig, Table.ModuleRef, - Table.TypeSpec, Table.Assembly, Table.AssemblyRef, Table.File, Table.ExportedType, - Table.ManifestResource, Table.GenericParam - }; - break; - case CodedIndex.HasFieldMarshal: - bits = 1; - tables = new [] { Table.Field, Table.Param }; - break; - case CodedIndex.HasDeclSecurity: - bits = 2; - tables = new [] { Table.TypeDef, Table.Method, Table.Assembly }; - break; - case CodedIndex.MemberRefParent: - bits = 3; - tables = new [] { Table.TypeDef, Table.TypeRef, Table.ModuleRef, Table.Method, Table.TypeSpec }; - break; - case CodedIndex.HasSemantics: - bits = 1; - tables = new [] { Table.Event, Table.Property }; - break; - case CodedIndex.MethodDefOrRef: - bits = 1; - tables = new [] { Table.Method, Table.MemberRef }; - break; - case CodedIndex.MemberForwarded: - bits = 1; - tables = new [] { Table.Field, Table.Method }; - break; - case CodedIndex.Implementation: - bits = 2; - tables = new [] { Table.File, Table.AssemblyRef, Table.ExportedType }; - break; - case CodedIndex.CustomAttributeType: - bits = 3; - tables = new [] { Table.Method, Table.MemberRef }; - break; - case CodedIndex.ResolutionScope: - bits = 2; - tables = new [] { Table.Module, Table.ModuleRef, Table.AssemblyRef, Table.TypeRef }; - break; - case CodedIndex.TypeOrMethodDef: - bits = 1; - tables = new [] { Table.TypeDef, Table.Method }; - break; - default: - throw new ArgumentException (); - } - - int max = 0; - - for (int i = 0; i < tables.Length; i++) { - max = System.Math.Max (counter (tables [i]), max); - } - - return max < (1 << (16 - bits)) ? 2 : 4; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamReader.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamReader.cs deleted file mode 100644 index ec2477c3ad5..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamReader.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -// BinaryStreamReader.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -namespace Mono.Cecil.PE { - - class BinaryStreamReader : BinaryReader { - - public BinaryStreamReader (Stream stream) - : base (stream) - { - } - - protected void Advance (int bytes) - { - BaseStream.Seek (bytes, SeekOrigin.Current); - } - - protected DataDirectory ReadDataDirectory () - { - return new DataDirectory (ReadUInt32 (), ReadUInt32 ()); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamWriter.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamWriter.cs deleted file mode 100644 index 2bf6cccfa19..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/BinaryStreamWriter.cs +++ /dev/null @@ -1,96 +0,0 @@ -// -// BinaryStreamWriter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -#if !READ_ONLY - -namespace Mono.Cecil.PE { - - class BinaryStreamWriter : BinaryWriter { - - public BinaryStreamWriter (Stream stream) - : base (stream) - { - } - - public void WriteByte (byte value) - { - Write (value); - } - - public void WriteUInt16 (ushort value) - { - Write (value); - } - - public void WriteInt16 (short value) - { - Write (value); - } - - public void WriteUInt32 (uint value) - { - Write (value); - } - - public void WriteInt32 (int value) - { - Write (value); - } - - public void WriteUInt64 (ulong value) - { - Write (value); - } - - public void WriteBytes (byte [] bytes) - { - Write (bytes); - } - - public void WriteDataDirectory (DataDirectory directory) - { - Write (directory.VirtualAddress); - Write (directory.Size); - } - - public void WriteBuffer (ByteBuffer buffer) - { - Write (buffer.buffer, 0, buffer.length); - } - - protected void Advance (int bytes) - { - BaseStream.Seek (bytes, SeekOrigin.Current); - } - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBuffer.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBuffer.cs deleted file mode 100644 index c7ae7aee132..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBuffer.cs +++ /dev/null @@ -1,359 +0,0 @@ -// -// ByteBuffer.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil.PE { - - class ByteBuffer { - - internal byte [] buffer; - internal int length; - internal int position; - - public ByteBuffer () - { - this.buffer = Empty.Array; - } - - public ByteBuffer (int length) - { - this.buffer = new byte [length]; - } - - public ByteBuffer (byte [] buffer) - { - this.buffer = buffer ?? Empty.Array; - this.length = this.buffer.Length; - } - - public void Reset (byte [] buffer) - { - this.buffer = buffer ?? Empty.Array; - this.length = this.buffer.Length; - } - - public void Advance (int length) - { - position += length; - } - - public byte ReadByte () - { - return buffer [position++]; - } - - public sbyte ReadSByte () - { - return (sbyte) ReadByte (); - } - - public byte [] ReadBytes (int length) - { - var bytes = new byte [length]; - Buffer.BlockCopy (buffer, position, bytes, 0, length); - position += length; - return bytes; - } - - public ushort ReadUInt16 () - { - ushort value = (ushort) (buffer [position] - | (buffer [position + 1] << 8)); - position += 2; - return value; - } - - public short ReadInt16 () - { - return (short) ReadUInt16 (); - } - - public uint ReadUInt32 () - { - uint value = (uint) (buffer [position] - | (buffer [position + 1] << 8) - | (buffer [position + 2] << 16) - | (buffer [position + 3] << 24)); - position += 4; - return value; - } - - public int ReadInt32 () - { - return (int) ReadUInt32 (); - } - - public ulong ReadUInt64 () - { - uint low = ReadUInt32 (); - uint high = ReadUInt32 (); - - return (((ulong) high) << 32) | low; - } - - public long ReadInt64 () - { - return (long) ReadUInt64 (); - } - - public uint ReadCompressedUInt32 () - { - byte first = ReadByte (); - if ((first & 0x80) == 0) - return first; - - if ((first & 0x40) == 0) - return ((uint) (first & ~0x80) << 8) - | ReadByte (); - - return ((uint) (first & ~0xc0) << 24) - | (uint) ReadByte () << 16 - | (uint) ReadByte () << 8 - | ReadByte (); - } - - public int ReadCompressedInt32 () - { - var value = (int) (ReadCompressedUInt32 () >> 1); - if ((value & 1) == 0) - return value; - if (value < 0x40) - return value - 0x40; - if (value < 0x2000) - return value - 0x2000; - if (value < 0x10000000) - return value - 0x10000000; - return value - 0x20000000; - } - - public float ReadSingle () - { - if (!BitConverter.IsLittleEndian) { - var bytes = ReadBytes (4); - Array.Reverse (bytes); - return BitConverter.ToSingle (bytes, 0); - } - - float value = BitConverter.ToSingle (buffer, position); - position += 4; - return value; - } - - public double ReadDouble () - { - if (!BitConverter.IsLittleEndian) { - var bytes = ReadBytes (8); - Array.Reverse (bytes); - return BitConverter.ToDouble (bytes, 0); - } - - double value = BitConverter.ToDouble (buffer, position); - position += 8; - return value; - } - -#if !READ_ONLY - - public void WriteByte (byte value) - { - if (position == buffer.Length) - Grow (1); - - buffer [position++] = value; - - if (position > length) - length = position; - } - - public void WriteSByte (sbyte value) - { - WriteByte ((byte) value); - } - - public void WriteUInt16 (ushort value) - { - if (position + 2 > buffer.Length) - Grow (2); - - buffer [position++] = (byte) value; - buffer [position++] = (byte) (value >> 8); - - if (position > length) - length = position; - } - - public void WriteInt16 (short value) - { - WriteUInt16 ((ushort) value); - } - - public void WriteUInt32 (uint value) - { - if (position + 4 > buffer.Length) - Grow (4); - - buffer [position++] = (byte) value; - buffer [position++] = (byte) (value >> 8); - buffer [position++] = (byte) (value >> 16); - buffer [position++] = (byte) (value >> 24); - - if (position > length) - length = position; - } - - public void WriteInt32 (int value) - { - WriteUInt32 ((uint) value); - } - - public void WriteUInt64 (ulong value) - { - if (position + 8 > buffer.Length) - Grow (8); - - buffer [position++] = (byte) value; - buffer [position++] = (byte) (value >> 8); - buffer [position++] = (byte) (value >> 16); - buffer [position++] = (byte) (value >> 24); - buffer [position++] = (byte) (value >> 32); - buffer [position++] = (byte) (value >> 40); - buffer [position++] = (byte) (value >> 48); - buffer [position++] = (byte) (value >> 56); - - if (position > length) - length = position; - } - - public void WriteInt64 (long value) - { - WriteUInt64 ((ulong) value); - } - - public void WriteCompressedUInt32 (uint value) - { - if (value < 0x80) - WriteByte ((byte) value); - else if (value < 0x4000) { - WriteByte ((byte) (0x80 | (value >> 8))); - WriteByte ((byte) (value & 0xff)); - } else { - WriteByte ((byte) ((value >> 24) | 0xc0)); - WriteByte ((byte) ((value >> 16) & 0xff)); - WriteByte ((byte) ((value >> 8) & 0xff)); - WriteByte ((byte) (value & 0xff)); - } - } - - public void WriteCompressedInt32 (int value) - { - if (value >= 0) { - WriteCompressedUInt32 ((uint) (value << 1)); - return; - } - - if (value > -0x40) - value = 0x40 + value; - else if (value >= -0x2000) - value = 0x2000 + value; - else if (value >= -0x20000000) - value = 0x20000000 + value; - - WriteCompressedUInt32 ((uint) ((value << 1) | 1)); - } - - public void WriteBytes (byte [] bytes) - { - var length = bytes.Length; - if (position + length > buffer.Length) - Grow (length); - - Buffer.BlockCopy (bytes, 0, buffer, position, length); - position += length; - - if (position > this.length) - this.length = position; - } - - public void WriteBytes (int length) - { - if (position + length > buffer.Length) - Grow (length); - - position += length; - - if (position > this.length) - this.length = position; - } - - public void WriteBytes (ByteBuffer buffer) - { - if (position + buffer.length > this.buffer.Length) - Grow (buffer.length); - - Buffer.BlockCopy (buffer.buffer, 0, this.buffer, position, buffer.length); - position += buffer.length; - - if (position > this.length) - this.length = position; - } - - public void WriteSingle (float value) - { - var bytes = BitConverter.GetBytes (value); - - if (!BitConverter.IsLittleEndian) - Array.Reverse (bytes); - - WriteBytes (bytes); - } - - public void WriteDouble (double value) - { - var bytes = BitConverter.GetBytes (value); - - if (!BitConverter.IsLittleEndian) - Array.Reverse (bytes); - - WriteBytes (bytes); - } - - void Grow (int desired) - { - var current = this.buffer; - var current_length = current.Length; - - var buffer = new byte [System.Math.Max (current_length + desired, current_length * 2)]; - Buffer.BlockCopy (current, 0, buffer, 0, current_length); - this.buffer = buffer; - } - -#endif - - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs deleted file mode 100644 index 70e89164c29..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -// ByteBufferEqualityComparer.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; - -namespace Mono.Cecil.PE { - - sealed class ByteBufferEqualityComparer : IEqualityComparer { - - public bool Equals (ByteBuffer x, ByteBuffer y) - { - if (x.length != y.length) - return false; - - var x_buffer = x.buffer; - var y_buffer = y.buffer; - - for (int i = 0; i < x.length; i++) - if (x_buffer [i] != y_buffer [i]) - return false; - - return true; - } - - public int GetHashCode (ByteBuffer buffer) - { -#if !BYTE_BUFFER_WELL_DISTRIBUTED_HASH - var hash = 0; - var bytes = buffer.buffer; - for (int i = 0; i < buffer.length; i++) - hash = (hash * 37) ^ bytes [i]; - - return hash; -#else - const uint p = 16777619; - uint hash = 2166136261; - - var bytes = buffer.buffer; - for (int i = 0; i < buffer.length; i++) - hash = (hash ^ bytes [i]) * p; - - hash += hash << 13; - hash ^= hash >> 7; - hash += hash << 3; - hash ^= hash >> 17; - hash += hash << 5; - - return (int) hash; -#endif - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/DataDirectory.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/DataDirectory.cs deleted file mode 100644 index fedd0e2ddec..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/DataDirectory.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// DataDirectory.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using RVA = System.UInt32; - -namespace Mono.Cecil.PE { - - struct DataDirectory { - - public readonly RVA VirtualAddress; - public readonly uint Size; - - public bool IsZero { - get { return VirtualAddress == 0 && Size == 0; } - } - - public DataDirectory (RVA rva, uint size) - { - this.VirtualAddress = rva; - this.Size = size; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/Image.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/Image.cs deleted file mode 100644 index e5d80752514..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/Image.cs +++ /dev/null @@ -1,160 +0,0 @@ -// -// Image.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono; -using Mono.Cecil.Cil; -using Mono.Cecil.Metadata; - -using RVA = System.UInt32; - -namespace Mono.Cecil.PE { - - sealed class Image { - - public ModuleKind Kind; - public TargetRuntime Runtime; - public TargetArchitecture Architecture; - public string FileName; - - public Section [] Sections; - - public Section MetadataSection; - - public uint EntryPointToken; - public ModuleAttributes Attributes; - - public DataDirectory Debug; - public DataDirectory Resources; - public DataDirectory StrongName; - - public StringHeap StringHeap; - public BlobHeap BlobHeap; - public UserStringHeap UserStringHeap; - public GuidHeap GuidHeap; - public TableHeap TableHeap; - - readonly int [] coded_index_sizes = new int [13]; - - readonly Func counter; - - public Image () - { - counter = GetTableLength; - } - - public bool HasTable (Table table) - { - return GetTableLength (table) > 0; - } - - public int GetTableLength (Table table) - { - return (int) TableHeap [table].Length; - } - - public int GetTableIndexSize (Table table) - { - return GetTableLength (table) < 65536 ? 2 : 4; - } - - public int GetCodedIndexSize (CodedIndex coded_index) - { - var index = (int) coded_index; - var size = coded_index_sizes [index]; - if (size != 0) - return size; - - return coded_index_sizes [index] = coded_index.GetSize (counter); - } - - public uint ResolveVirtualAddress (RVA rva) - { - var section = GetSectionAtVirtualAddress (rva); - if (section == null) - throw new ArgumentOutOfRangeException (); - - return ResolveVirtualAddressInSection (rva, section); - } - - public uint ResolveVirtualAddressInSection (RVA rva, Section section) - { - return rva + section.PointerToRawData - section.VirtualAddress; - } - - public Section GetSection (string name) - { - var sections = this.Sections; - for (int i = 0; i < sections.Length; i++) { - var section = sections [i]; - if (section.Name == name) - return section; - } - - return null; - } - - public Section GetSectionAtVirtualAddress (RVA rva) - { - var sections = this.Sections; - for (int i = 0; i < sections.Length; i++) { - var section = sections [i]; - if (rva >= section.VirtualAddress && rva < section.VirtualAddress + section.SizeOfRawData) - return section; - } - - return null; - } - - public ImageDebugDirectory GetDebugHeader (out byte [] header) - { - var section = GetSectionAtVirtualAddress (Debug.VirtualAddress); - var buffer = new ByteBuffer (section.Data); - buffer.position = (int) (Debug.VirtualAddress - section.VirtualAddress); - - var directory = new ImageDebugDirectory { - Characteristics = buffer.ReadInt32 (), - TimeDateStamp = buffer.ReadInt32 (), - MajorVersion = buffer.ReadInt16 (), - MinorVersion = buffer.ReadInt16 (), - Type = buffer.ReadInt32 (), - SizeOfData = buffer.ReadInt32 (), - AddressOfRawData = buffer.ReadInt32 (), - PointerToRawData = buffer.ReadInt32 (), - }; - - buffer.position = (int) (directory.PointerToRawData - section.PointerToRawData); - - header = new byte [directory.SizeOfData]; - Buffer.BlockCopy (buffer.buffer, buffer.position, header, 0, header.Length); - - return directory; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageReader.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageReader.cs deleted file mode 100644 index b320169192c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageReader.cs +++ /dev/null @@ -1,679 +0,0 @@ -// -// ImageReader.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -using Mono.Cecil.Metadata; - -using RVA = System.UInt32; - -namespace Mono.Cecil.PE { - - sealed class ImageReader : BinaryStreamReader { - - readonly Image image; - - DataDirectory cli; - DataDirectory metadata; - - public ImageReader (Stream stream) - : base (stream) - { - image = new Image (); - - image.FileName = stream.GetFullyQualifiedName (); - } - - void MoveTo (DataDirectory directory) - { - BaseStream.Position = image.ResolveVirtualAddress (directory.VirtualAddress); - } - - void MoveTo (uint position) - { - BaseStream.Position = position; - } - - void ReadImage () - { - if (BaseStream.Length < 128) - throw new BadImageFormatException (); - - // - DOSHeader - - // PE 2 - // Start 58 - // Lfanew 4 - // End 64 - - if (ReadUInt16 () != 0x5a4d) - throw new BadImageFormatException (); - - Advance (58); - - MoveTo (ReadUInt32 ()); - - if (ReadUInt32 () != 0x00004550) - throw new BadImageFormatException (); - - // - PEFileHeader - - // Machine 2 - image.Architecture = ReadArchitecture (); - - // NumberOfSections 2 - ushort sections = ReadUInt16 (); - - // TimeDateStamp 4 - // PointerToSymbolTable 4 - // NumberOfSymbols 4 - // OptionalHeaderSize 2 - Advance (14); - - // Characteristics 2 - ushort characteristics = ReadUInt16 (); - - ushort subsystem; - ReadOptionalHeaders (out subsystem); - ReadSections (sections); - ReadCLIHeader (); - ReadMetadata (); - - image.Kind = GetModuleKind (characteristics, subsystem); - } - - TargetArchitecture ReadArchitecture () - { - var machine = ReadUInt16 (); - switch (machine) { - case 0x014c: - return TargetArchitecture.I386; - case 0x8664: - return TargetArchitecture.AMD64; - case 0x0200: - return TargetArchitecture.IA64; - case 0x01c4: - return TargetArchitecture.ARMv7; - } - - throw new NotSupportedException (); - } - - static ModuleKind GetModuleKind (ushort characteristics, ushort subsystem) - { - if ((characteristics & 0x2000) != 0) // ImageCharacteristics.Dll - return ModuleKind.Dll; - - if (subsystem == 0x2 || subsystem == 0x9) // SubSystem.WindowsGui || SubSystem.WindowsCeGui - return ModuleKind.Windows; - - return ModuleKind.Console; - } - - void ReadOptionalHeaders (out ushort subsystem) - { - // - PEOptionalHeader - // - StandardFieldsHeader - - // Magic 2 - bool pe64 = ReadUInt16 () == 0x20b; - - // pe32 || pe64 - - // LMajor 1 - // LMinor 1 - // CodeSize 4 - // InitializedDataSize 4 - // UninitializedDataSize4 - // EntryPointRVA 4 - // BaseOfCode 4 - // BaseOfData 4 || 0 - - // - NTSpecificFieldsHeader - - // ImageBase 4 || 8 - // SectionAlignment 4 - // FileAlignement 4 - // OSMajor 2 - // OSMinor 2 - // UserMajor 2 - // UserMinor 2 - // SubSysMajor 2 - // SubSysMinor 2 - // Reserved 4 - // ImageSize 4 - // HeaderSize 4 - // FileChecksum 4 - Advance (66); - - // SubSystem 2 - subsystem = ReadUInt16 (); - - // DLLFlags 2 - // StackReserveSize 4 || 8 - // StackCommitSize 4 || 8 - // HeapReserveSize 4 || 8 - // HeapCommitSize 4 || 8 - // LoaderFlags 4 - // NumberOfDataDir 4 - - // - DataDirectoriesHeader - - // ExportTable 8 - // ImportTable 8 - // ResourceTable 8 - // ExceptionTable 8 - // CertificateTable 8 - // BaseRelocationTable 8 - - Advance (pe64 ? 90 : 74); - - // Debug 8 - image.Debug = ReadDataDirectory (); - - // Copyright 8 - // GlobalPtr 8 - // TLSTable 8 - // LoadConfigTable 8 - // BoundImport 8 - // IAT 8 - // DelayImportDescriptor8 - Advance (56); - - // CLIHeader 8 - cli = ReadDataDirectory (); - - if (cli.IsZero) - throw new BadImageFormatException (); - - // Reserved 8 - Advance (8); - } - - string ReadAlignedString (int length) - { - int read = 0; - var buffer = new char [length]; - while (read < length) { - var current = ReadByte (); - if (current == 0) - break; - - buffer [read++] = (char) current; - } - - Advance (-1 + ((read + 4) & ~3) - read); - - return new string (buffer, 0, read); - } - - string ReadZeroTerminatedString (int length) - { - int read = 0; - var buffer = new char [length]; - var bytes = ReadBytes (length); - while (read < length) { - var current = bytes [read]; - if (current == 0) - break; - - buffer [read++] = (char) current; - } - - return new string (buffer, 0, read); - } - - void ReadSections (ushort count) - { - var sections = new Section [count]; - - for (int i = 0; i < count; i++) { - var section = new Section (); - - // Name - section.Name = ReadZeroTerminatedString (8); - - // VirtualSize 4 - Advance (4); - - // VirtualAddress 4 - section.VirtualAddress = ReadUInt32 (); - // SizeOfRawData 4 - section.SizeOfRawData = ReadUInt32 (); - // PointerToRawData 4 - section.PointerToRawData = ReadUInt32 (); - - // PointerToRelocations 4 - // PointerToLineNumbers 4 - // NumberOfRelocations 2 - // NumberOfLineNumbers 2 - // Characteristics 4 - Advance (16); - - sections [i] = section; - - ReadSectionData (section); - } - - image.Sections = sections; - } - - void ReadSectionData (Section section) - { - var position = BaseStream.Position; - - MoveTo (section.PointerToRawData); - - var length = (int) section.SizeOfRawData; - var data = new byte [length]; - int offset = 0, read; - - while ((read = Read (data, offset, length - offset)) > 0) - offset += read; - - section.Data = data; - - BaseStream.Position = position; - } - - void ReadCLIHeader () - { - MoveTo (cli); - - // - CLIHeader - - // Cb 4 - // MajorRuntimeVersion 2 - // MinorRuntimeVersion 2 - Advance (8); - - // Metadata 8 - metadata = ReadDataDirectory (); - // Flags 4 - image.Attributes = (ModuleAttributes) ReadUInt32 (); - // EntryPointToken 4 - image.EntryPointToken = ReadUInt32 (); - // Resources 8 - image.Resources = ReadDataDirectory (); - // StrongNameSignature 8 - image.StrongName = ReadDataDirectory (); - // CodeManagerTable 8 - // VTableFixups 8 - // ExportAddressTableJumps 8 - // ManagedNativeHeader 8 - } - - void ReadMetadata () - { - MoveTo (metadata); - - if (ReadUInt32 () != 0x424a5342) - throw new BadImageFormatException (); - - // MajorVersion 2 - // MinorVersion 2 - // Reserved 4 - Advance (8); - - var version = ReadZeroTerminatedString (ReadInt32 ()); - image.Runtime = version.ParseRuntime (); - - // Flags 2 - Advance (2); - - var streams = ReadUInt16 (); - - var section = image.GetSectionAtVirtualAddress (metadata.VirtualAddress); - if (section == null) - throw new BadImageFormatException (); - - image.MetadataSection = section; - - for (int i = 0; i < streams; i++) - ReadMetadataStream (section); - - if (image.TableHeap != null) - ReadTableHeap (); - } - - void ReadMetadataStream (Section section) - { - // Offset 4 - uint start = metadata.VirtualAddress - section.VirtualAddress + ReadUInt32 (); // relative to the section start - - // Size 4 - uint size = ReadUInt32 (); - - var name = ReadAlignedString (16); - switch (name) { - case "#~": - case "#-": - image.TableHeap = new TableHeap (section, start, size); - break; - case "#Strings": - image.StringHeap = new StringHeap (section, start, size); - break; - case "#Blob": - image.BlobHeap = new BlobHeap (section, start, size); - break; - case "#GUID": - image.GuidHeap = new GuidHeap (section, start, size); - break; - case "#US": - image.UserStringHeap = new UserStringHeap (section, start, size); - break; - } - } - - void ReadTableHeap () - { - var heap = image.TableHeap; - - uint start = heap.Section.PointerToRawData; - - MoveTo (heap.Offset + start); - - // Reserved 4 - // MajorVersion 1 - // MinorVersion 1 - Advance (6); - - // HeapSizes 1 - var sizes = ReadByte (); - - // Reserved2 1 - Advance (1); - - // Valid 8 - heap.Valid = ReadInt64 (); - - // Sorted 8 - heap.Sorted = ReadInt64 (); - - for (int i = 0; i < TableHeap.TableCount; i++) { - if (!heap.HasTable ((Table) i)) - continue; - - heap.Tables [i].Length = ReadUInt32 (); - } - - SetIndexSize (image.StringHeap, sizes, 0x1); - SetIndexSize (image.GuidHeap, sizes, 0x2); - SetIndexSize (image.BlobHeap, sizes, 0x4); - - ComputeTableInformations (); - } - - static void SetIndexSize (Heap heap, uint sizes, byte flag) - { - if (heap == null) - return; - - heap.IndexSize = (sizes & flag) > 0 ? 4 : 2; - } - - int GetTableIndexSize (Table table) - { - return image.GetTableIndexSize (table); - } - - int GetCodedIndexSize (CodedIndex index) - { - return image.GetCodedIndexSize (index); - } - - void ComputeTableInformations () - { - uint offset = (uint) BaseStream.Position - image.MetadataSection.PointerToRawData; // header - - int stridx_size = image.StringHeap.IndexSize; - int blobidx_size = image.BlobHeap != null ? image.BlobHeap.IndexSize : 2; - - var heap = image.TableHeap; - var tables = heap.Tables; - - for (int i = 0; i < TableHeap.TableCount; i++) { - var table = (Table) i; - if (!heap.HasTable (table)) - continue; - - int size; - switch (table) { - case Table.Module: - size = 2 // Generation - + stridx_size // Name - + (image.GuidHeap.IndexSize * 3); // Mvid, EncId, EncBaseId - break; - case Table.TypeRef: - size = GetCodedIndexSize (CodedIndex.ResolutionScope) // ResolutionScope - + (stridx_size * 2); // Name, Namespace - break; - case Table.TypeDef: - size = 4 // Flags - + (stridx_size * 2) // Name, Namespace - + GetCodedIndexSize (CodedIndex.TypeDefOrRef) // BaseType - + GetTableIndexSize (Table.Field) // FieldList - + GetTableIndexSize (Table.Method); // MethodList - break; - case Table.FieldPtr: - size = GetTableIndexSize (Table.Field); // Field - break; - case Table.Field: - size = 2 // Flags - + stridx_size // Name - + blobidx_size; // Signature - break; - case Table.MethodPtr: - size = GetTableIndexSize (Table.Method); // Method - break; - case Table.Method: - size = 8 // Rva 4, ImplFlags 2, Flags 2 - + stridx_size // Name - + blobidx_size // Signature - + GetTableIndexSize (Table.Param); // ParamList - break; - case Table.ParamPtr: - size = GetTableIndexSize (Table.Param); // Param - break; - case Table.Param: - size = 4 // Flags 2, Sequence 2 - + stridx_size; // Name - break; - case Table.InterfaceImpl: - size = GetTableIndexSize (Table.TypeDef) // Class - + GetCodedIndexSize (CodedIndex.TypeDefOrRef); // Interface - break; - case Table.MemberRef: - size = GetCodedIndexSize (CodedIndex.MemberRefParent) // Class - + stridx_size // Name - + blobidx_size; // Signature - break; - case Table.Constant: - size = 2 // Type - + GetCodedIndexSize (CodedIndex.HasConstant) // Parent - + blobidx_size; // Value - break; - case Table.CustomAttribute: - size = GetCodedIndexSize (CodedIndex.HasCustomAttribute) // Parent - + GetCodedIndexSize (CodedIndex.CustomAttributeType) // Type - + blobidx_size; // Value - break; - case Table.FieldMarshal: - size = GetCodedIndexSize (CodedIndex.HasFieldMarshal) // Parent - + blobidx_size; // NativeType - break; - case Table.DeclSecurity: - size = 2 // Action - + GetCodedIndexSize (CodedIndex.HasDeclSecurity) // Parent - + blobidx_size; // PermissionSet - break; - case Table.ClassLayout: - size = 6 // PackingSize 2, ClassSize 4 - + GetTableIndexSize (Table.TypeDef); // Parent - break; - case Table.FieldLayout: - size = 4 // Offset - + GetTableIndexSize (Table.Field); // Field - break; - case Table.StandAloneSig: - size = blobidx_size; // Signature - break; - case Table.EventMap: - size = GetTableIndexSize (Table.TypeDef) // Parent - + GetTableIndexSize (Table.Event); // EventList - break; - case Table.EventPtr: - size = GetTableIndexSize (Table.Event); // Event - break; - case Table.Event: - size = 2 // Flags - + stridx_size // Name - + GetCodedIndexSize (CodedIndex.TypeDefOrRef); // EventType - break; - case Table.PropertyMap: - size = GetTableIndexSize (Table.TypeDef) // Parent - + GetTableIndexSize (Table.Property); // PropertyList - break; - case Table.PropertyPtr: - size = GetTableIndexSize (Table.Property); // Property - break; - case Table.Property: - size = 2 // Flags - + stridx_size // Name - + blobidx_size; // Type - break; - case Table.MethodSemantics: - size = 2 // Semantics - + GetTableIndexSize (Table.Method) // Method - + GetCodedIndexSize (CodedIndex.HasSemantics); // Association - break; - case Table.MethodImpl: - size = GetTableIndexSize (Table.TypeDef) // Class - + GetCodedIndexSize (CodedIndex.MethodDefOrRef) // MethodBody - + GetCodedIndexSize (CodedIndex.MethodDefOrRef); // MethodDeclaration - break; - case Table.ModuleRef: - size = stridx_size; // Name - break; - case Table.TypeSpec: - size = blobidx_size; // Signature - break; - case Table.ImplMap: - size = 2 // MappingFlags - + GetCodedIndexSize (CodedIndex.MemberForwarded) // MemberForwarded - + stridx_size // ImportName - + GetTableIndexSize (Table.ModuleRef); // ImportScope - break; - case Table.FieldRVA: - size = 4 // RVA - + GetTableIndexSize (Table.Field); // Field - break; - case Table.EncLog: - case Table.EncMap: - size = 4; - break; - case Table.Assembly: - size = 16 // HashAlgId 4, Version 4 * 2, Flags 4 - + blobidx_size // PublicKey - + (stridx_size * 2); // Name, Culture - break; - case Table.AssemblyProcessor: - size = 4; // Processor - break; - case Table.AssemblyOS: - size = 12; // Platform 4, Version 2 * 4 - break; - case Table.AssemblyRef: - size = 12 // Version 2 * 4 + Flags 4 - + (blobidx_size * 2) // PublicKeyOrToken, HashValue - + (stridx_size * 2); // Name, Culture - break; - case Table.AssemblyRefProcessor: - size = 4 // Processor - + GetTableIndexSize (Table.AssemblyRef); // AssemblyRef - break; - case Table.AssemblyRefOS: - size = 12 // Platform 4, Version 2 * 4 - + GetTableIndexSize (Table.AssemblyRef); // AssemblyRef - break; - case Table.File: - size = 4 // Flags - + stridx_size // Name - + blobidx_size; // HashValue - break; - case Table.ExportedType: - size = 8 // Flags 4, TypeDefId 4 - + (stridx_size * 2) // Name, Namespace - + GetCodedIndexSize (CodedIndex.Implementation); // Implementation - break; - case Table.ManifestResource: - size = 8 // Offset, Flags - + stridx_size // Name - + GetCodedIndexSize (CodedIndex.Implementation); // Implementation - break; - case Table.NestedClass: - size = GetTableIndexSize (Table.TypeDef) // NestedClass - + GetTableIndexSize (Table.TypeDef); // EnclosingClass - break; - case Table.GenericParam: - size = 4 // Number, Flags - + GetCodedIndexSize (CodedIndex.TypeOrMethodDef) // Owner - + stridx_size; // Name - break; - case Table.MethodSpec: - size = GetCodedIndexSize (CodedIndex.MethodDefOrRef) // Method - + blobidx_size; // Instantiation - break; - case Table.GenericParamConstraint: - size = GetTableIndexSize (Table.GenericParam) // Owner - + GetCodedIndexSize (CodedIndex.TypeDefOrRef); // Constraint - break; - default: - throw new NotSupportedException (); - } - - tables [i].RowSize = (uint) size; - tables [i].Offset = offset; - - offset += (uint) size * tables [i].Length; - } - } - - public static Image ReadImageFrom (Stream stream) - { - try { - var reader = new ImageReader (stream); - reader.ReadImage (); - return reader.image; - } catch (EndOfStreamException e) { - throw new BadImageFormatException (stream.GetFullyQualifiedName (), e); - } - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs deleted file mode 100644 index bea308c9193..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs +++ /dev/null @@ -1,823 +0,0 @@ -// -// ImageWriter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -#if !READ_ONLY - -using Mono.Cecil.Cil; -using Mono.Cecil.Metadata; - -using RVA = System.UInt32; - -namespace Mono.Cecil.PE { - - sealed class ImageWriter : BinaryStreamWriter { - - readonly ModuleDefinition module; - readonly MetadataBuilder metadata; - readonly TextMap text_map; - - ImageDebugDirectory debug_directory; - byte [] debug_data; - - ByteBuffer win32_resources; - - const uint pe_header_size = 0x178u; - const uint section_header_size = 0x28u; - const uint file_alignment = 0x200; - const uint section_alignment = 0x2000; - const ulong image_base = 0x00400000; - - internal const RVA text_rva = 0x2000; - - readonly bool pe64; - readonly uint time_stamp; - - internal Section text; - internal Section rsrc; - internal Section reloc; - - ushort sections; - - ImageWriter (ModuleDefinition module, MetadataBuilder metadata, Stream stream) - : base (stream) - { - this.module = module; - this.metadata = metadata; - this.pe64 = module.Architecture != TargetArchitecture.I386; - this.GetDebugHeader (); - this.GetWin32Resources (); - this.text_map = BuildTextMap (); - this.sections = (ushort) (pe64 ? 1 : 2); // text + reloc - this.time_stamp = (uint) DateTime.UtcNow.Subtract (new DateTime (1970, 1, 1)).TotalSeconds; - } - - void GetDebugHeader () - { - var symbol_writer = metadata.symbol_writer; - if (symbol_writer == null) - return; - - if (!symbol_writer.GetDebugHeader (out debug_directory, out debug_data)) - debug_data = Empty.Array; - } - - void GetWin32Resources () - { - var rsrc = GetImageResourceSection (); - if (rsrc == null) - return; - - var raw_resources = new byte [rsrc.Data.Length]; - Buffer.BlockCopy (rsrc.Data, 0, raw_resources, 0, rsrc.Data.Length); - win32_resources = new ByteBuffer (raw_resources); - } - - Section GetImageResourceSection () - { - if (!module.HasImage) - return null; - - const string rsrc_section = ".rsrc"; - - return module.Image.GetSection (rsrc_section); - } - - public static ImageWriter CreateWriter (ModuleDefinition module, MetadataBuilder metadata, Stream stream) - { - var writer = new ImageWriter (module, metadata, stream); - writer.BuildSections (); - return writer; - } - - void BuildSections () - { - var has_win32_resources = win32_resources != null; - if (has_win32_resources) - sections++; - - text = CreateSection (".text", text_map.GetLength (), null); - var previous = text; - - if (has_win32_resources) { - rsrc = CreateSection (".rsrc", (uint) win32_resources.length, previous); - - PatchWin32Resources (win32_resources); - previous = rsrc; - } - - if (!pe64) - reloc = CreateSection (".reloc", 12u, previous); - } - - Section CreateSection (string name, uint size, Section previous) - { - return new Section { - Name = name, - VirtualAddress = previous != null - ? previous.VirtualAddress + Align (previous.VirtualSize, section_alignment) - : text_rva, - VirtualSize = size, - PointerToRawData = previous != null - ? previous.PointerToRawData + previous.SizeOfRawData - : Align (GetHeaderSize (), file_alignment), - SizeOfRawData = Align (size, file_alignment) - }; - } - - static uint Align (uint value, uint align) - { - align--; - return (value + align) & ~align; - } - - void WriteDOSHeader () - { - Write (new byte [] { - // dos header start - 0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, - 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - // lfanew - 0x80, 0x00, 0x00, 0x00, - // dos header end - 0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, - 0xcd, 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x72, - 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x20, 0x63, - 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x62, - 0x65, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x69, - 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, 0x6d, - 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a, - 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00 - }); - } - - void WritePEFileHeader () - { - WriteUInt32 (0x00004550); // Magic - WriteUInt16 (GetMachine ()); // Machine - WriteUInt16 (sections); // NumberOfSections - WriteUInt32 (time_stamp); - WriteUInt32 (0); // PointerToSymbolTable - WriteUInt32 (0); // NumberOfSymbols - WriteUInt16 ((ushort) (!pe64 ? 0xe0 : 0xf0)); // SizeOfOptionalHeader - - // ExecutableImage | (pe64 ? 32BitsMachine : LargeAddressAware) - var characteristics = (ushort) (0x0002 | (!pe64 ? 0x0100 : 0x0020)); - if (module.Kind == ModuleKind.Dll || module.Kind == ModuleKind.NetModule) - characteristics |= 0x2000; - WriteUInt16 (characteristics); // Characteristics - } - - ushort GetMachine () - { - switch (module.Architecture) { - case TargetArchitecture.I386: - return 0x014c; - case TargetArchitecture.AMD64: - return 0x8664; - case TargetArchitecture.IA64: - return 0x0200; - } - - throw new NotSupportedException (); - } - - Section LastSection () - { - if (reloc != null) - return reloc; - - if (rsrc != null) - return rsrc; - - return text; - } - - void WriteOptionalHeaders () - { - WriteUInt16 ((ushort) (!pe64 ? 0x10b : 0x20b)); // Magic - WriteByte (8); // LMajor - WriteByte (0); // LMinor - WriteUInt32 (text.SizeOfRawData); // CodeSize - WriteUInt32 (reloc != null ? reloc.SizeOfRawData : 0 - + (rsrc != null ? rsrc.SizeOfRawData : 0)); // InitializedDataSize - WriteUInt32 (0); // UninitializedDataSize - - var startub_stub = text_map.GetRange (TextSegment.StartupStub); - WriteUInt32 (startub_stub.Length > 0 ? startub_stub.Start : 0); // EntryPointRVA - WriteUInt32 (text_rva); // BaseOfCode - - if (!pe64) { - WriteUInt32 (0); // BaseOfData - WriteUInt32 ((uint) image_base); // ImageBase - } else { - WriteUInt64 (image_base); // ImageBase - } - - WriteUInt32 (section_alignment); // SectionAlignment - WriteUInt32 (file_alignment); // FileAlignment - - WriteUInt16 (4); // OSMajor - WriteUInt16 (0); // OSMinor - WriteUInt16 (0); // UserMajor - WriteUInt16 (0); // UserMinor - WriteUInt16 (4); // SubSysMajor - WriteUInt16 (0); // SubSysMinor - WriteUInt32 (0); // Reserved - - var last_section = LastSection(); - WriteUInt32 (last_section.VirtualAddress + Align (last_section.VirtualSize, section_alignment)); // ImageSize - WriteUInt32 (text.PointerToRawData); // HeaderSize - - WriteUInt32 (0); // Checksum - WriteUInt16 (GetSubSystem ()); // SubSystem - WriteUInt16 (0x8540); // DLLFlags - - const ulong stack_reserve = 0x100000; - const ulong stack_commit = 0x1000; - const ulong heap_reserve = 0x100000; - const ulong heap_commit = 0x1000; - - if (!pe64) { - WriteUInt32 ((uint) stack_reserve); - WriteUInt32 ((uint) stack_commit); - WriteUInt32 ((uint) heap_reserve); - WriteUInt32 ((uint) heap_commit); - } else { - WriteUInt64 (stack_reserve); - WriteUInt64 (stack_commit); - WriteUInt64 (heap_reserve); - WriteUInt64 (heap_commit); - } - - WriteUInt32 (0); // LoaderFlags - WriteUInt32 (16); // NumberOfDataDir - - WriteZeroDataDirectory (); // ExportTable - WriteDataDirectory (text_map.GetDataDirectory (TextSegment.ImportDirectory)); // ImportTable - if (rsrc != null) { // ResourceTable - WriteUInt32 (rsrc.VirtualAddress); - WriteUInt32 (rsrc.VirtualSize); - } else - WriteZeroDataDirectory (); - - WriteZeroDataDirectory (); // ExceptionTable - WriteZeroDataDirectory (); // CertificateTable - WriteUInt32 (reloc != null ? reloc.VirtualAddress : 0); // BaseRelocationTable - WriteUInt32 (reloc != null ? reloc.VirtualSize : 0); - - if (text_map.GetLength (TextSegment.DebugDirectory) > 0) { - WriteUInt32 (text_map.GetRVA (TextSegment.DebugDirectory)); - WriteUInt32 (28u); - } else - WriteZeroDataDirectory (); - - WriteZeroDataDirectory (); // Copyright - WriteZeroDataDirectory (); // GlobalPtr - WriteZeroDataDirectory (); // TLSTable - WriteZeroDataDirectory (); // LoadConfigTable - WriteZeroDataDirectory (); // BoundImport - WriteDataDirectory (text_map.GetDataDirectory (TextSegment.ImportAddressTable)); // IAT - WriteZeroDataDirectory (); // DelayImportDesc - WriteDataDirectory (text_map.GetDataDirectory (TextSegment.CLIHeader)); // CLIHeader - WriteZeroDataDirectory (); // Reserved - } - - void WriteZeroDataDirectory () - { - WriteUInt32 (0); - WriteUInt32 (0); - } - - ushort GetSubSystem () - { - switch (module.Kind) { - case ModuleKind.Console: - case ModuleKind.Dll: - case ModuleKind.NetModule: - return 0x3; - case ModuleKind.Windows: - return 0x2; - default: - throw new ArgumentOutOfRangeException (); - } - } - - void WriteSectionHeaders () - { - WriteSection (text, 0x60000020); - - if (rsrc != null) - WriteSection (rsrc, 0x40000040); - - if (reloc != null) - WriteSection (reloc, 0x42000040); - } - - void WriteSection (Section section, uint characteristics) - { - var name = new byte [8]; - var sect_name = section.Name; - for (int i = 0; i < sect_name.Length; i++) - name [i] = (byte) sect_name [i]; - - WriteBytes (name); - WriteUInt32 (section.VirtualSize); - WriteUInt32 (section.VirtualAddress); - WriteUInt32 (section.SizeOfRawData); - WriteUInt32 (section.PointerToRawData); - WriteUInt32 (0); // PointerToRelocations - WriteUInt32 (0); // PointerToLineNumbers - WriteUInt16 (0); // NumberOfRelocations - WriteUInt16 (0); // NumberOfLineNumbers - WriteUInt32 (characteristics); - } - - void MoveTo (uint pointer) - { - BaseStream.Seek (pointer, SeekOrigin.Begin); - } - - void MoveToRVA (Section section, RVA rva) - { - BaseStream.Seek (section.PointerToRawData + rva - section.VirtualAddress, SeekOrigin.Begin); - } - - void MoveToRVA (TextSegment segment) - { - MoveToRVA (text, text_map.GetRVA (segment)); - } - - void WriteRVA (RVA rva) - { - if (!pe64) - WriteUInt32 (rva); - else - WriteUInt64 (rva); - } - - void WriteText () - { - MoveTo (text.PointerToRawData); - - // ImportAddressTable - - if (!pe64) { - WriteRVA (text_map.GetRVA (TextSegment.ImportHintNameTable)); - WriteRVA (0); - } - - // CLIHeader - - WriteUInt32 (0x48); - WriteUInt16 (2); - WriteUInt16 ((ushort) ((module.Runtime <= TargetRuntime.Net_1_1) ? 0 : 5)); - - WriteUInt32 (text_map.GetRVA (TextSegment.MetadataHeader)); - WriteUInt32 (GetMetadataLength ()); - WriteUInt32 ((uint) module.Attributes); - WriteUInt32 (metadata.entry_point.ToUInt32 ()); - WriteDataDirectory (text_map.GetDataDirectory (TextSegment.Resources)); - WriteDataDirectory (text_map.GetDataDirectory (TextSegment.StrongNameSignature)); - WriteZeroDataDirectory (); // CodeManagerTable - WriteZeroDataDirectory (); // VTableFixups - WriteZeroDataDirectory (); // ExportAddressTableJumps - WriteZeroDataDirectory (); // ManagedNativeHeader - - // Code - - MoveToRVA (TextSegment.Code); - WriteBuffer (metadata.code); - - // Resources - - MoveToRVA (TextSegment.Resources); - WriteBuffer (metadata.resources); - - // Data - - if (metadata.data.length > 0) { - MoveToRVA (TextSegment.Data); - WriteBuffer (metadata.data); - } - - // StrongNameSignature - // stays blank - - // MetadataHeader - - MoveToRVA (TextSegment.MetadataHeader); - WriteMetadataHeader (); - - WriteMetadata (); - - // DebugDirectory - if (text_map.GetLength (TextSegment.DebugDirectory) > 0) { - MoveToRVA (TextSegment.DebugDirectory); - WriteDebugDirectory (); - } - - if (pe64) - return; - - // ImportDirectory - MoveToRVA (TextSegment.ImportDirectory); - WriteImportDirectory (); - - // StartupStub - MoveToRVA (TextSegment.StartupStub); - WriteStartupStub (); - } - - uint GetMetadataLength () - { - return text_map.GetRVA (TextSegment.DebugDirectory) - text_map.GetRVA (TextSegment.MetadataHeader); - } - - void WriteMetadataHeader () - { - WriteUInt32 (0x424a5342); // Signature - WriteUInt16 (1); // MajorVersion - WriteUInt16 (1); // MinorVersion - WriteUInt32 (0); // Reserved - - var version = GetZeroTerminatedString (GetVersion ()); - WriteUInt32 ((uint) version.Length); - WriteBytes (version); - WriteUInt16 (0); // Flags - WriteUInt16 (GetStreamCount ()); - - uint offset = text_map.GetRVA (TextSegment.TableHeap) - text_map.GetRVA (TextSegment.MetadataHeader); - - WriteStreamHeader (ref offset, TextSegment.TableHeap, "#~"); - WriteStreamHeader (ref offset, TextSegment.StringHeap, "#Strings"); - WriteStreamHeader (ref offset, TextSegment.UserStringHeap, "#US"); - WriteStreamHeader (ref offset, TextSegment.GuidHeap, "#GUID"); - WriteStreamHeader (ref offset, TextSegment.BlobHeap, "#Blob"); - } - - string GetVersion () - { - switch (module.Runtime) { - case TargetRuntime.Net_1_0: - return "v1.0.3705"; - case TargetRuntime.Net_1_1: - return "v1.1.4322"; - case TargetRuntime.Net_2_0: - return "v2.0.50727"; - case TargetRuntime.Net_4_0: - default: - return "v4.0.30319"; - } - } - - ushort GetStreamCount () - { - return (ushort) ( - 1 // #~ - + 1 // #Strings - + (metadata.user_string_heap.IsEmpty ? 0 : 1) // #US - + 1 // GUID - + (metadata.blob_heap.IsEmpty ? 0 : 1)); // #Blob - } - - void WriteStreamHeader (ref uint offset, TextSegment heap, string name) - { - var length = (uint) text_map.GetLength (heap); - if (length == 0) - return; - - WriteUInt32 (offset); - WriteUInt32 (length); - WriteBytes (GetZeroTerminatedString (name)); - offset += length; - } - - static byte [] GetZeroTerminatedString (string @string) - { - return GetString (@string, (@string.Length + 1 + 3) & ~3); - } - - static byte [] GetSimpleString (string @string) - { - return GetString (@string, @string.Length); - } - - static byte [] GetString (string @string, int length) - { - var bytes = new byte [length]; - for (int i = 0; i < @string.Length; i++) - bytes [i] = (byte) @string [i]; - - return bytes; - } - - void WriteMetadata () - { - WriteHeap (TextSegment.TableHeap, metadata.table_heap); - WriteHeap (TextSegment.StringHeap, metadata.string_heap); - WriteHeap (TextSegment.UserStringHeap, metadata.user_string_heap); - WriteGuidHeap (); - WriteHeap (TextSegment.BlobHeap, metadata.blob_heap); - } - - void WriteHeap (TextSegment heap, HeapBuffer buffer) - { - if (buffer.IsEmpty) - return; - - MoveToRVA (heap); - WriteBuffer (buffer); - } - - void WriteGuidHeap () - { - MoveToRVA (TextSegment.GuidHeap); - WriteBytes (module.Mvid.ToByteArray ()); - } - - void WriteDebugDirectory () - { - WriteInt32 (debug_directory.Characteristics); - WriteUInt32 (time_stamp); - WriteInt16 (debug_directory.MajorVersion); - WriteInt16 (debug_directory.MinorVersion); - WriteInt32 (debug_directory.Type); - WriteInt32 (debug_directory.SizeOfData); - WriteInt32 (debug_directory.AddressOfRawData); - WriteInt32 ((int) BaseStream.Position + 4); - - WriteBytes (debug_data); - } - - void WriteImportDirectory () - { - WriteUInt32 (text_map.GetRVA (TextSegment.ImportDirectory) + 40); // ImportLookupTable - WriteUInt32 (0); // DateTimeStamp - WriteUInt32 (0); // ForwarderChain - WriteUInt32 (text_map.GetRVA (TextSegment.ImportHintNameTable) + 14); - WriteUInt32 (text_map.GetRVA (TextSegment.ImportAddressTable)); - Advance (20); - - // ImportLookupTable - WriteUInt32 (text_map.GetRVA (TextSegment.ImportHintNameTable)); - - // ImportHintNameTable - MoveToRVA (TextSegment.ImportHintNameTable); - - WriteUInt16 (0); // Hint - WriteBytes (GetRuntimeMain ()); - WriteByte (0); - WriteBytes (GetSimpleString ("mscoree.dll")); - WriteUInt16 (0); - } - - byte [] GetRuntimeMain () - { - return module.Kind == ModuleKind.Dll || module.Kind == ModuleKind.NetModule - ? GetSimpleString ("_CorDllMain") - : GetSimpleString ("_CorExeMain"); - } - - void WriteStartupStub () - { - switch (module.Architecture) { - case TargetArchitecture.I386: - WriteUInt16 (0x25ff); - WriteUInt32 ((uint) image_base + text_map.GetRVA (TextSegment.ImportAddressTable)); - return; - default: - throw new NotSupportedException (); - } - } - - void WriteRsrc () - { - MoveTo (rsrc.PointerToRawData); - WriteBuffer (win32_resources); - } - - void WriteReloc () - { - MoveTo (reloc.PointerToRawData); - - var reloc_rva = text_map.GetRVA (TextSegment.StartupStub); - reloc_rva += module.Architecture == TargetArchitecture.IA64 ? 0x20u : 2; - var page_rva = reloc_rva & ~0xfffu; - - WriteUInt32 (page_rva); // PageRVA - WriteUInt32 (0x000c); // Block Size - - switch (module.Architecture) { - case TargetArchitecture.I386: - WriteUInt32 (0x3000 + reloc_rva - page_rva); - break; - default: - throw new NotSupportedException(); - } - - WriteBytes (new byte [file_alignment - reloc.VirtualSize]); - } - - public void WriteImage () - { - WriteDOSHeader (); - WritePEFileHeader (); - WriteOptionalHeaders (); - WriteSectionHeaders (); - WriteText (); - if (rsrc != null) - WriteRsrc (); - if (reloc != null) - WriteReloc (); - } - - TextMap BuildTextMap () - { - var map = metadata.text_map; - - map.AddMap (TextSegment.Code, metadata.code.length, !pe64 ? 4 : 16); - map.AddMap (TextSegment.Resources, metadata.resources.length, 8); - map.AddMap (TextSegment.Data, metadata.data.length, 4); - if (metadata.data.length > 0) - metadata.table_heap.FixupData (map.GetRVA (TextSegment.Data)); - map.AddMap (TextSegment.StrongNameSignature, GetStrongNameLength (), 4); - - map.AddMap (TextSegment.MetadataHeader, GetMetadataHeaderLength ()); - map.AddMap (TextSegment.TableHeap, metadata.table_heap.length, 4); - map.AddMap (TextSegment.StringHeap, metadata.string_heap.length, 4); - map.AddMap (TextSegment.UserStringHeap, metadata.user_string_heap.IsEmpty ? 0 : metadata.user_string_heap.length, 4); - map.AddMap (TextSegment.GuidHeap, 16); - map.AddMap (TextSegment.BlobHeap, metadata.blob_heap.IsEmpty ? 0 : metadata.blob_heap.length, 4); - - int debug_dir_len = 0; - if (!debug_data.IsNullOrEmpty ()) { - const int debug_dir_header_len = 28; - - debug_directory.AddressOfRawData = (int) map.GetNextRVA (TextSegment.BlobHeap) + debug_dir_header_len; - debug_dir_len = debug_data.Length + debug_dir_header_len; - } - - map.AddMap (TextSegment.DebugDirectory, debug_dir_len, 4); - - if (pe64) { - var start = map.GetNextRVA (TextSegment.DebugDirectory); - map.AddMap (TextSegment.ImportDirectory, new Range (start, 0)); - map.AddMap (TextSegment.ImportHintNameTable, new Range (start, 0)); - map.AddMap (TextSegment.StartupStub, new Range (start, 0)); - return map; - } - - RVA import_dir_rva = map.GetNextRVA (TextSegment.DebugDirectory); - RVA import_hnt_rva = import_dir_rva + 48u; - import_hnt_rva = (import_hnt_rva + 15u) & ~15u; - uint import_dir_len = (import_hnt_rva - import_dir_rva) + 27u; - - RVA startup_stub_rva = import_dir_rva + import_dir_len; - startup_stub_rva = module.Architecture == TargetArchitecture.IA64 - ? (startup_stub_rva + 15u) & ~15u - : 2 + ((startup_stub_rva + 3u) & ~3u); - - map.AddMap (TextSegment.ImportDirectory, new Range (import_dir_rva, import_dir_len)); - map.AddMap (TextSegment.ImportHintNameTable, new Range (import_hnt_rva, 0)); - map.AddMap (TextSegment.StartupStub, new Range (startup_stub_rva, GetStartupStubLength ())); - - return map; - } - - uint GetStartupStubLength () - { - switch (module.Architecture) { - case TargetArchitecture.I386: - return 6; - default: - throw new NotSupportedException (); - } - } - - int GetMetadataHeaderLength () - { - return - // MetadataHeader - 40 - // #~ header - + 12 - // #Strings header - + 20 - // #US header - + (metadata.user_string_heap.IsEmpty ? 0 : 12) - // #GUID header - + 16 - // #Blob header - + (metadata.blob_heap.IsEmpty ? 0 : 16); - } - - int GetStrongNameLength () - { - if (module.Assembly == null) - return 0; - - var public_key = module.Assembly.Name.PublicKey; - - if (public_key != null) { - // in fx 2.0 the key may be from 384 to 16384 bits - // so we must calculate the signature size based on - // the size of the public key (minus the 32 byte header) - int size = public_key.Length; - if (size > 32) - return size - 32; - // note: size == 16 for the ECMA "key" which is replaced - // by the runtime with a 1024 bits key (128 bytes) - } - - return 128; // default strongname signature size - } - - public DataDirectory GetStrongNameSignatureDirectory () - { - return text_map.GetDataDirectory (TextSegment.StrongNameSignature); - } - - public uint GetHeaderSize () - { - return pe_header_size + (sections * section_header_size); - } - - void PatchWin32Resources (ByteBuffer resources) - { - PatchResourceDirectoryTable (resources); - } - - void PatchResourceDirectoryTable (ByteBuffer resources) - { - resources.Advance (12); - - var entries = resources.ReadUInt16 () + resources.ReadUInt16 (); - - for (int i = 0; i < entries; i++) - PatchResourceDirectoryEntry (resources); - } - - void PatchResourceDirectoryEntry (ByteBuffer resources) - { - resources.Advance (4); - var child = resources.ReadUInt32 (); - - var position = resources.position; - resources.position = (int) child & 0x7fffffff; - - if ((child & 0x80000000) != 0) - PatchResourceDirectoryTable (resources); - else - PatchResourceDataEntry (resources); - - resources.position = position; - } - - void PatchResourceDataEntry (ByteBuffer resources) - { - var old_rsrc = GetImageResourceSection (); - var rva = resources.ReadUInt32 (); - resources.position -= 4; - resources.WriteUInt32 (rva - old_rsrc.VirtualAddress + rsrc.VirtualAddress); - } - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/Section.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/Section.cs deleted file mode 100644 index 6a4c7bab792..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/Section.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Section.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using RVA = System.UInt32; - -namespace Mono.Cecil.PE { - - sealed class Section { - public string Name; - public RVA VirtualAddress; - public uint VirtualSize; - public uint SizeOfRawData; - public uint PointerToRawData; - public byte [] Data; - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.PE/TextMap.cs b/mcs/class/Mono.Cecil/Mono.Cecil.PE/TextMap.cs deleted file mode 100644 index 047a4c1d473..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil.PE/TextMap.cs +++ /dev/null @@ -1,129 +0,0 @@ -// -// TextMap.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -#if !READ_ONLY - -using RVA = System.UInt32; - -namespace Mono.Cecil.PE { - - enum TextSegment { - ImportAddressTable, - CLIHeader, - Code, - Resources, - Data, - StrongNameSignature, - - // Metadata - MetadataHeader, - TableHeap, - StringHeap, - UserStringHeap, - GuidHeap, - BlobHeap, - // End Metadata - - DebugDirectory, - ImportDirectory, - ImportHintNameTable, - StartupStub, - } - - sealed class TextMap { - - readonly Range [] map = new Range [16 /*Enum.GetValues (typeof (TextSegment)).Length*/]; - - public void AddMap (TextSegment segment, int length) - { - map [(int) segment] = new Range (GetStart (segment), (uint) length); - } - - public void AddMap (TextSegment segment, int length, int align) - { - align--; - - AddMap (segment, (length + align) & ~align); - } - - public void AddMap (TextSegment segment, Range range) - { - map [(int) segment] = range; - } - - public Range GetRange (TextSegment segment) - { - return map [(int) segment]; - } - - public DataDirectory GetDataDirectory (TextSegment segment) - { - var range = map [(int) segment]; - - return new DataDirectory (range.Length == 0 ? 0 : range.Start, range.Length); - } - - public RVA GetRVA (TextSegment segment) - { - return map [(int) segment].Start; - } - - public RVA GetNextRVA (TextSegment segment) - { - var i = (int) segment; - return map [i].Start + map [i].Length; - } - - public int GetLength (TextSegment segment) - { - return (int) map [(int) segment].Length; - } - - RVA GetStart (TextSegment segment) - { - var index = (int) segment; - return index == 0 ? ImageWriter.text_rva : ComputeStart (index); - } - - RVA ComputeStart (int index) - { - index--; - return map [index].Start + map [index].Length; - } - - public uint GetLength () - { - var range = map [(int) TextSegment.StartupStub]; - return range.Start - ImageWriter.text_rva + range.Length; - } - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono.Cecil.dll.sources b/mcs/class/Mono.Cecil/Mono.Cecil.dll.sources index 95bb7f35369..231d5d77bdc 100644 --- a/mcs/class/Mono.Cecil/Mono.Cecil.dll.sources +++ b/mcs/class/Mono.Cecil/Mono.Cecil.dll.sources @@ -1,127 +1,127 @@ -./Mono.Collections.Generic/Collection.cs -./Mono.Collections.Generic/ReadOnlyCollection.cs -./Mono.Cecil.PE/ImageWriter.cs -./Mono.Cecil.PE/BinaryStreamWriter.cs -./Mono.Cecil.PE/BinaryStreamReader.cs -./Mono.Cecil.PE/DataDirectory.cs -./Mono.Cecil.PE/ByteBuffer.cs -./Mono.Cecil.PE/ByteBufferEqualityComparer.cs -./Mono.Cecil.PE/TextMap.cs -./Mono.Cecil.PE/Section.cs -./Mono.Cecil.PE/Image.cs -./Mono.Cecil.PE/ImageReader.cs -./Mono.Cecil.Metadata/TableHeap.cs -./Mono.Cecil.Metadata/GuidHeap.cs -./Mono.Cecil.Metadata/Heap.cs -./Mono.Cecil.Metadata/TokenType.cs -./Mono.Cecil.Metadata/CodedIndex.cs -./Mono.Cecil.Metadata/ElementType.cs -./Mono.Cecil.Metadata/BlobHeap.cs -./Mono.Cecil.Metadata/Row.cs -./Mono.Cecil.Metadata/MetadataToken.cs -./Mono.Cecil.Metadata/UserStringHeap.cs -./Mono.Cecil.Metadata/Utilities.cs -./Mono.Cecil.Metadata/StringHeap.cs -./Mono.Cecil.Metadata/Buffers.cs -./System.Runtime.CompilerServices/ExtensionAttribute.cs -./Mono.Security.Cryptography/CryptoService.cs -./Mono.Security.Cryptography/CryptoConvert.cs -./Mono/Empty.cs -./Mono/Funcs.cs -./Mono/Actions.cs -./Mono.Cecil.Cil/ILProcessor.cs -./Mono.Cecil.Cil/VariableReference.cs -./Mono.Cecil.Cil/OpCodes.cs -./Mono.Cecil.Cil/MethodBody.cs -./Mono.Cecil.Cil/Instruction.cs -./Mono.Cecil.Cil/Code.cs -./Mono.Cecil.Cil/Symbols.cs -./Mono.Cecil.Cil/CodeWriter.cs -./Mono.Cecil.Cil/CodeReader.cs -./Mono.Cecil.Cil/SequencePoint.cs -./Mono.Cecil.Cil/Document.cs -./Mono.Cecil.Cil/OpCode.cs -./Mono.Cecil.Cil/ExceptionHandler.cs -./Mono.Cecil.Cil/VariableDefinition.cs -./Mono.Cecil/ModuleReference.cs -./Mono.Cecil/TypeParser.cs -./Mono.Cecil/LinkedResource.cs -./Mono.Cecil/IMemberDefinition.cs -./Mono.Cecil/Resource.cs -./Mono.Cecil/ICustomAttributeProvider.cs -./Mono.Cecil/MethodReference.cs -./Mono.Cecil/EventAttributes.cs -./Mono.Cecil/FieldReference.cs -./Mono.Cecil/SentinelType.cs -./Mono.Cecil/MemberReference.cs -./Mono.Cecil/AssemblyReader.cs -./Mono.Cecil/TargetRuntime.cs -./Mono.Cecil/TypeAttributes.cs -./Mono.Cecil/GenericParameter.cs -./Mono.Cecil/MethodImplAttributes.cs -./Mono.Cecil/FileAttributes.cs -./Mono.Cecil/ManifestResourceAttributes.cs -./Mono.Cecil/SecurityDeclaration.cs -./Mono.Cecil/NativeType.cs -./Mono.Cecil/EventReference.cs -./Mono.Cecil/AssemblyWriter.cs -./Mono.Cecil/Modifiers.cs -./Mono.Cecil/IGenericParameterProvider.cs -./Mono.Cecil/ParameterDefinition.cs -./Mono.Cecil/IMetadataScope.cs -./Mono.Cecil/AssemblyNameReference.cs -./Mono.Cecil/ParameterAttributes.cs -./Mono.Cecil/TypeSpecification.cs -./Mono.Cecil/IMetadataTokenProvider.cs -./Mono.Cecil/MethodAttributes.cs -./Mono.Cecil/AssemblyInfo.cs -./Mono.Cecil/IMarshalInfoProvider.cs -./Mono.Cecil/PointerType.cs -./Mono.Cecil/ArrayType.cs -./Mono.Cecil/TypeDefinition.cs -./Mono.Cecil/FunctionPointerType.cs -./Mono.Cecil/MetadataResolver.cs -./Mono.Cecil/Import.cs -./Mono.Cecil/IGenericInstance.cs -./Mono.Cecil/ExportedType.cs -./Mono.Cecil/PInvokeAttributes.cs -./Mono.Cecil/AssemblyHashAlgorithm.cs -./Mono.Cecil/MethodReturnType.cs -./Mono.Cecil/ParameterReference.cs -./Mono.Cecil/AssemblyLinkedResource.cs -./Mono.Cecil/EventDefinition.cs -./Mono.Cecil/FieldAttributes.cs -./Mono.Cecil/AssemblyNameDefinition.cs -./Mono.Cecil/ParameterDefinitionCollection.cs -./Mono.Cecil/ModuleDefinition.cs -./Mono.Cecil/MetadataSystem.cs -./Mono.Cecil/AssemblyFlags.cs -./Mono.Cecil/TypeDefinitionCollection.cs -./Mono.Cecil/CustomAttribute.cs -./Mono.Cecil/MemberDefinitionCollection.cs -./Mono.Cecil/PropertyDefinition.cs -./Mono.Cecil/GenericInstanceType.cs -./Mono.Cecil/ModuleKind.cs -./Mono.Cecil/DefaultAssemblyResolver.cs -./Mono.Cecil/MethodSemanticsAttributes.cs -./Mono.Cecil/EmbeddedResource.cs -./Mono.Cecil/PropertyAttributes.cs -./Mono.Cecil/MethodSpecification.cs -./Mono.Cecil/TypeReference.cs -./Mono.Cecil/IConstantProvider.cs -./Mono.Cecil/MethodDefinition.cs -./Mono.Cecil/PinnedType.cs -./Mono.Cecil/VariantType.cs -./Mono.Cecil/MethodCallingConvention.cs -./Mono.Cecil/TypeSystem.cs -./Mono.Cecil/IMethodSignature.cs -./Mono.Cecil/FieldDefinition.cs -./Mono.Cecil/BaseAssemblyResolver.cs -./Mono.Cecil/PropertyReference.cs -./Mono.Cecil/MarshalInfo.cs -./Mono.Cecil/GenericInstanceMethod.cs -./Mono.Cecil/ReferenceType.cs -./Mono.Cecil/PInvokeInfo.cs -./Mono.Cecil/CallSite.cs -./Mono.Cecil/AssemblyDefinition.cs -./Mono.Cecil/GenericParameterAttributes.cs +../../../external/cecil/Mono.Collections.Generic/Collection.cs +../../../external/cecil/Mono.Collections.Generic/ReadOnlyCollection.cs +../../../external/cecil/Mono.Cecil.PE/ImageWriter.cs +../../../external/cecil/Mono.Cecil.PE/BinaryStreamWriter.cs +../../../external/cecil/Mono.Cecil.PE/BinaryStreamReader.cs +../../../external/cecil/Mono.Cecil.PE/DataDirectory.cs +../../../external/cecil/Mono.Cecil.PE/ByteBuffer.cs +../../../external/cecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs +../../../external/cecil/Mono.Cecil.PE/TextMap.cs +../../../external/cecil/Mono.Cecil.PE/Section.cs +../../../external/cecil/Mono.Cecil.PE/Image.cs +../../../external/cecil/Mono.Cecil.PE/ImageReader.cs +../../../external/cecil/Mono.Cecil.Metadata/TableHeap.cs +../../../external/cecil/Mono.Cecil.Metadata/GuidHeap.cs +../../../external/cecil/Mono.Cecil.Metadata/Heap.cs +../../../external/cecil/Mono.Cecil.Metadata/TokenType.cs +../../../external/cecil/Mono.Cecil.Metadata/CodedIndex.cs +../../../external/cecil/Mono.Cecil.Metadata/ElementType.cs +../../../external/cecil/Mono.Cecil.Metadata/BlobHeap.cs +../../../external/cecil/Mono.Cecil.Metadata/Row.cs +../../../external/cecil/Mono.Cecil.Metadata/MetadataToken.cs +../../../external/cecil/Mono.Cecil.Metadata/UserStringHeap.cs +../../../external/cecil/Mono.Cecil.Metadata/Utilities.cs +../../../external/cecil/Mono.Cecil.Metadata/StringHeap.cs +../../../external/cecil/Mono.Cecil.Metadata/Buffers.cs +../../../external/cecil/System.Runtime.CompilerServices/ExtensionAttribute.cs +../../../external/cecil/Mono.Security.Cryptography/CryptoService.cs +../../../external/cecil/Mono.Security.Cryptography/CryptoConvert.cs +../../../external/cecil/Mono/Empty.cs +../../../external/cecil/Mono/Funcs.cs +../../../external/cecil/Mono/Actions.cs +../../../external/cecil/Mono.Cecil.Cil/ILProcessor.cs +../../../external/cecil/Mono.Cecil.Cil/VariableReference.cs +../../../external/cecil/Mono.Cecil.Cil/OpCodes.cs +../../../external/cecil/Mono.Cecil.Cil/MethodBody.cs +../../../external/cecil/Mono.Cecil.Cil/Instruction.cs +../../../external/cecil/Mono.Cecil.Cil/Code.cs +../../../external/cecil/Mono.Cecil.Cil/Symbols.cs +../../../external/cecil/Mono.Cecil.Cil/CodeWriter.cs +../../../external/cecil/Mono.Cecil.Cil/CodeReader.cs +../../../external/cecil/Mono.Cecil.Cil/SequencePoint.cs +../../../external/cecil/Mono.Cecil.Cil/Document.cs +../../../external/cecil/Mono.Cecil.Cil/OpCode.cs +../../../external/cecil/Mono.Cecil.Cil/ExceptionHandler.cs +../../../external/cecil/Mono.Cecil.Cil/VariableDefinition.cs +../../../external/cecil/Mono.Cecil/ModuleReference.cs +../../../external/cecil/Mono.Cecil/TypeParser.cs +../../../external/cecil/Mono.Cecil/LinkedResource.cs +../../../external/cecil/Mono.Cecil/IMemberDefinition.cs +../../../external/cecil/Mono.Cecil/Resource.cs +../../../external/cecil/Mono.Cecil/ICustomAttributeProvider.cs +../../../external/cecil/Mono.Cecil/MethodReference.cs +../../../external/cecil/Mono.Cecil/EventAttributes.cs +../../../external/cecil/Mono.Cecil/FieldReference.cs +../../../external/cecil/Mono.Cecil/SentinelType.cs +../../../external/cecil/Mono.Cecil/MemberReference.cs +../../../external/cecil/Mono.Cecil/AssemblyReader.cs +../../../external/cecil/Mono.Cecil/TargetRuntime.cs +../../../external/cecil/Mono.Cecil/TypeAttributes.cs +../../../external/cecil/Mono.Cecil/GenericParameter.cs +../../../external/cecil/Mono.Cecil/MethodImplAttributes.cs +../../../external/cecil/Mono.Cecil/FileAttributes.cs +../../../external/cecil/Mono.Cecil/ManifestResourceAttributes.cs +../../../external/cecil/Mono.Cecil/SecurityDeclaration.cs +../../../external/cecil/Mono.Cecil/NativeType.cs +../../../external/cecil/Mono.Cecil/EventReference.cs +../../../external/cecil/Mono.Cecil/AssemblyWriter.cs +../../../external/cecil/Mono.Cecil/Modifiers.cs +../../../external/cecil/Mono.Cecil/IGenericParameterProvider.cs +../../../external/cecil/Mono.Cecil/ParameterDefinition.cs +../../../external/cecil/Mono.Cecil/IMetadataScope.cs +../../../external/cecil/Mono.Cecil/AssemblyNameReference.cs +../../../external/cecil/Mono.Cecil/ParameterAttributes.cs +../../../external/cecil/Mono.Cecil/TypeSpecification.cs +../../../external/cecil/Mono.Cecil/IMetadataTokenProvider.cs +../../../external/cecil/Mono.Cecil/MethodAttributes.cs +../../../external/cecil/Mono.Cecil/AssemblyInfo.cs +../../../external/cecil/Mono.Cecil/IMarshalInfoProvider.cs +../../../external/cecil/Mono.Cecil/PointerType.cs +../../../external/cecil/Mono.Cecil/ArrayType.cs +../../../external/cecil/Mono.Cecil/TypeDefinition.cs +../../../external/cecil/Mono.Cecil/FunctionPointerType.cs +../../../external/cecil/Mono.Cecil/MetadataResolver.cs +../../../external/cecil/Mono.Cecil/Import.cs +../../../external/cecil/Mono.Cecil/IGenericInstance.cs +../../../external/cecil/Mono.Cecil/ExportedType.cs +../../../external/cecil/Mono.Cecil/PInvokeAttributes.cs +../../../external/cecil/Mono.Cecil/AssemblyHashAlgorithm.cs +../../../external/cecil/Mono.Cecil/MethodReturnType.cs +../../../external/cecil/Mono.Cecil/ParameterReference.cs +../../../external/cecil/Mono.Cecil/AssemblyLinkedResource.cs +../../../external/cecil/Mono.Cecil/EventDefinition.cs +../../../external/cecil/Mono.Cecil/FieldAttributes.cs +../../../external/cecil/Mono.Cecil/AssemblyNameDefinition.cs +../../../external/cecil/Mono.Cecil/ParameterDefinitionCollection.cs +../../../external/cecil/Mono.Cecil/ModuleDefinition.cs +../../../external/cecil/Mono.Cecil/MetadataSystem.cs +../../../external/cecil/Mono.Cecil/AssemblyFlags.cs +../../../external/cecil/Mono.Cecil/TypeDefinitionCollection.cs +../../../external/cecil/Mono.Cecil/CustomAttribute.cs +../../../external/cecil/Mono.Cecil/MemberDefinitionCollection.cs +../../../external/cecil/Mono.Cecil/PropertyDefinition.cs +../../../external/cecil/Mono.Cecil/GenericInstanceType.cs +../../../external/cecil/Mono.Cecil/ModuleKind.cs +../../../external/cecil/Mono.Cecil/DefaultAssemblyResolver.cs +../../../external/cecil/Mono.Cecil/MethodSemanticsAttributes.cs +../../../external/cecil/Mono.Cecil/EmbeddedResource.cs +../../../external/cecil/Mono.Cecil/PropertyAttributes.cs +../../../external/cecil/Mono.Cecil/MethodSpecification.cs +../../../external/cecil/Mono.Cecil/TypeReference.cs +../../../external/cecil/Mono.Cecil/IConstantProvider.cs +../../../external/cecil/Mono.Cecil/MethodDefinition.cs +../../../external/cecil/Mono.Cecil/PinnedType.cs +../../../external/cecil/Mono.Cecil/VariantType.cs +../../../external/cecil/Mono.Cecil/MethodCallingConvention.cs +../../../external/cecil/Mono.Cecil/TypeSystem.cs +../../../external/cecil/Mono.Cecil/IMethodSignature.cs +../../../external/cecil/Mono.Cecil/FieldDefinition.cs +../../../external/cecil/Mono.Cecil/BaseAssemblyResolver.cs +../../../external/cecil/Mono.Cecil/PropertyReference.cs +../../../external/cecil/Mono.Cecil/MarshalInfo.cs +../../../external/cecil/Mono.Cecil/GenericInstanceMethod.cs +../../../external/cecil/Mono.Cecil/ReferenceType.cs +../../../external/cecil/Mono.Cecil/PInvokeInfo.cs +../../../external/cecil/Mono.Cecil/CallSite.cs +../../../external/cecil/Mono.Cecil/AssemblyDefinition.cs +../../../external/cecil/Mono.Cecil/GenericParameterAttributes.cs diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ArrayType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ArrayType.cs deleted file mode 100644 index 55c59d87281..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ArrayType.cs +++ /dev/null @@ -1,159 +0,0 @@ -// -// ArrayType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; -using Mono.Collections.Generic; -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public struct ArrayDimension { - - int? lower_bound; - int? upper_bound; - - public int? LowerBound { - get { return lower_bound; } - set { lower_bound = value; } - } - - public int? UpperBound { - get { return upper_bound; } - set { upper_bound = value; } - } - - public bool IsSized { - get { return lower_bound.HasValue || upper_bound.HasValue; } - } - - public ArrayDimension (int? lowerBound, int? upperBound) - { - this.lower_bound = lowerBound; - this.upper_bound = upperBound; - } - - public override string ToString () - { - return !IsSized - ? string.Empty - : lower_bound + "..." + upper_bound; - } - } - - public sealed class ArrayType : TypeSpecification { - - Collection dimensions; - - public Collection Dimensions { - get { - if (dimensions != null) - return dimensions; - - dimensions = new Collection (); - dimensions.Add (new ArrayDimension ()); - return dimensions; - } - } - - public int Rank { - get { return dimensions == null ? 1 : dimensions.Count; } - } - - public bool IsVector { - get { - if (dimensions == null) - return true; - - if (dimensions.Count > 1) - return false; - - var dimension = dimensions [0]; - - return !dimension.IsSized; - } - } - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override string Name { - get { return base.Name + Suffix; } - } - - public override string FullName { - get { return base.FullName + Suffix; } - } - - string Suffix { - get { - if (IsVector) - return "[]"; - - var suffix = new StringBuilder (); - suffix.Append ("["); - for (int i = 0; i < dimensions.Count; i++) { - if (i > 0) - suffix.Append (","); - - suffix.Append (dimensions [i].ToString ()); - } - suffix.Append ("]"); - - return suffix.ToString (); - } - } - - public override bool IsArray { - get { return true; } - } - - public ArrayType (TypeReference type) - : base (type) - { - Mixin.CheckType (type); - this.etype = MD.ElementType.Array; - } - - public ArrayType (TypeReference type, int rank) - : this (type) - { - Mixin.CheckType (type); - - if (rank == 1) - return; - - dimensions = new Collection (rank); - for (int i = 0; i < rank; i++) - dimensions.Add (new ArrayDimension ()); - this.etype = MD.ElementType.Array; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs deleted file mode 100644 index f1b5d25e4e7..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs +++ /dev/null @@ -1,189 +0,0 @@ -// -// AssemblyDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class AssemblyDefinition : ICustomAttributeProvider, ISecurityDeclarationProvider { - - AssemblyNameDefinition name; - - internal ModuleDefinition main_module; - Collection modules; - Collection custom_attributes; - Collection security_declarations; - - public AssemblyNameDefinition Name { - get { return name; } - set { name = value; } - } - - public string FullName { - get { return name != null ? name.FullName : string.Empty; } - } - - public MetadataToken MetadataToken { - get { return new MetadataToken (TokenType.Assembly, 1); } - set { } - } - - public Collection Modules { - get { - if (modules != null) - return modules; - - if (main_module.HasImage) - return modules = main_module.Read (this, (_, reader) => reader.ReadModules ()); - - return modules = new Collection (1) { main_module }; - } - } - - public ModuleDefinition MainModule { - get { return main_module; } - } - - public MethodDefinition EntryPoint { - get { return main_module.EntryPoint; } - set { main_module.EntryPoint = value; } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (main_module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (main_module)); } - } - - public bool HasSecurityDeclarations { - get { - if (security_declarations != null) - return security_declarations.Count > 0; - - return this.GetHasSecurityDeclarations (main_module); - } - } - - public Collection SecurityDeclarations { - get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (main_module)); } - } - - internal AssemblyDefinition () - { - } - -#if !READ_ONLY - public static AssemblyDefinition CreateAssembly (AssemblyNameDefinition assemblyName, string moduleName, ModuleKind kind) - { - return CreateAssembly (assemblyName, moduleName, new ModuleParameters { Kind = kind }); - } - - public static AssemblyDefinition CreateAssembly (AssemblyNameDefinition assemblyName, string moduleName, ModuleParameters parameters) - { - if (assemblyName == null) - throw new ArgumentNullException ("assemblyName"); - if (moduleName == null) - throw new ArgumentNullException ("moduleName"); - Mixin.CheckParameters (parameters); - if (parameters.Kind == ModuleKind.NetModule) - throw new ArgumentException ("kind"); - - var assembly = ModuleDefinition.CreateModule (moduleName, parameters).Assembly; - assembly.Name = assemblyName; - - return assembly; - } -#endif - - public static AssemblyDefinition ReadAssembly (string fileName) - { - return ReadAssembly (ModuleDefinition.ReadModule (fileName)); - } - - public static AssemblyDefinition ReadAssembly (string fileName, ReaderParameters parameters) - { - return ReadAssembly (ModuleDefinition.ReadModule (fileName, parameters)); - } - - public static AssemblyDefinition ReadAssembly (Stream stream) - { - return ReadAssembly (ModuleDefinition.ReadModule (stream)); - } - - public static AssemblyDefinition ReadAssembly (Stream stream, ReaderParameters parameters) - { - return ReadAssembly (ModuleDefinition.ReadModule (stream, parameters)); - } - - static AssemblyDefinition ReadAssembly (ModuleDefinition module) - { - var assembly = module.Assembly; - if (assembly == null) - throw new ArgumentException (); - - return assembly; - } - -#if !READ_ONLY - public void Write (string fileName) - { - Write (fileName, new WriterParameters ()); - } - - public void Write (Stream stream) - { - Write (stream, new WriterParameters ()); - } - - public void Write (string fileName, WriterParameters parameters) - { - main_module.Write (fileName, parameters); - } - - public void Write (Stream stream, WriterParameters parameters) - { - main_module.Write (stream, parameters); - } -#endif - - public override string ToString () - { - return this.FullName; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs deleted file mode 100644 index 72a0eb06c20..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// AssemblyFlags.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum AssemblyAttributes : uint { - PublicKey = 0x0001, - SideBySideCompatible = 0x0000, - Retargetable = 0x0100, - WindowsRuntime = 0x0200, - DisableJITCompileOptimizer = 0x4000, - EnableJITCompileTracking = 0x8000, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs deleted file mode 100644 index 79a5699db6c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs +++ /dev/null @@ -1,36 +0,0 @@ -// -// AssemblyHashAlgorithm.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum AssemblyHashAlgorithm : uint { - None = 0x0000, - Reserved = 0x8003, // MD5 - SHA1 = 0x8004 - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs deleted file mode 100644 index 8a9f8097e10..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// AssemblyInfo.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle ("Mono.Cecil")] -[assembly: AssemblyProduct ("Mono.Cecil")] -[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")] - -[assembly: ComVisible (false)] - -[assembly: Guid ("fd225bb4-fa53-44b2-a6db-85f5e48dcb54")] - -[assembly: AssemblyVersion ("0.9.5.0")] -#if !CF -[assembly: AssemblyFileVersion ("0.9.5.0")] -#endif - -[assembly: InternalsVisibleTo ("Mono.Cecil.Pdb, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] -[assembly: InternalsVisibleTo ("Mono.Cecil.Mdb, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] -[assembly: InternalsVisibleTo ("Mono.Cecil.Rocks, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] -[assembly: InternalsVisibleTo ("Mono.Cecil.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs deleted file mode 100644 index 4d8bac0bbba..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// AssemblyLinkedResource.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public sealed class AssemblyLinkedResource : Resource { - - AssemblyNameReference reference; - - public AssemblyNameReference Assembly { - get { return reference; } - set { reference = value; } - } - - public override ResourceType ResourceType { - get { return ResourceType.AssemblyLinked; } - } - - public AssemblyLinkedResource (string name, ManifestResourceAttributes flags) - : base (name, flags) - { - } - - public AssemblyLinkedResource (string name, ManifestResourceAttributes flags, AssemblyNameReference reference) - : base (name, flags) - { - this.reference = reference; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs deleted file mode 100644 index dc6b9057f92..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// AssemblyNameDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public sealed class AssemblyNameDefinition : AssemblyNameReference { - - public override byte [] Hash { - get { return Empty.Array; } - } - - internal AssemblyNameDefinition () - { - this.token = new MetadataToken (TokenType.Assembly, 1); - } - - public AssemblyNameDefinition (string name, Version version) - : base (name, version) - { - this.token = new MetadataToken (TokenType.Assembly, 1); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs deleted file mode 100644 index 3da978057b4..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs +++ /dev/null @@ -1,268 +0,0 @@ -// -// AssemblyNameReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Globalization; -using System.Security.Cryptography; -using System.Text; - -namespace Mono.Cecil { - - public class AssemblyNameReference : IMetadataScope { - - string name; - string culture; - Version version; - uint attributes; - byte [] public_key; - byte [] public_key_token; - AssemblyHashAlgorithm hash_algorithm; - byte [] hash; - - internal MetadataToken token; - - string full_name; - - public string Name { - get { return name; } - set { - name = value; - full_name = null; - } - } - - public string Culture { - get { return culture; } - set { - culture = value; - full_name = null; - } - } - - public Version Version { - get { return version; } - set { - version = value; - full_name = null; - } - } - - public AssemblyAttributes Attributes { - get { return (AssemblyAttributes) attributes; } - set { attributes = (uint) value; } - } - - public bool HasPublicKey { - get { return attributes.GetAttributes ((uint) AssemblyAttributes.PublicKey); } - set { attributes = attributes.SetAttributes ((uint) AssemblyAttributes.PublicKey, value); } - } - - public bool IsSideBySideCompatible { - get { return attributes.GetAttributes ((uint) AssemblyAttributes.SideBySideCompatible); } - set { attributes = attributes.SetAttributes ((uint) AssemblyAttributes.SideBySideCompatible, value); } - } - - public bool IsRetargetable { - get { return attributes.GetAttributes ((uint) AssemblyAttributes.Retargetable); } - set { attributes = attributes.SetAttributes ((uint) AssemblyAttributes.Retargetable, value); } - } - - public bool IsWindowsRuntime { - get { return attributes.GetAttributes ((uint) AssemblyAttributes.WindowsRuntime); } - set { attributes = attributes.SetAttributes ((uint) AssemblyAttributes.WindowsRuntime, value); } - } - - public byte [] PublicKey { - get { return public_key; } - set { - public_key = value; - HasPublicKey = !public_key.IsNullOrEmpty (); - public_key_token = Empty.Array; - full_name = null; - } - } - - public byte [] PublicKeyToken { - get { - if (public_key_token.IsNullOrEmpty () && !public_key.IsNullOrEmpty ()) { - var hash = HashPublicKey (); - // we need the last 8 bytes in reverse order - public_key_token = new byte [8]; - Array.Copy (hash, (hash.Length - 8), public_key_token, 0, 8); - Array.Reverse (public_key_token, 0, 8); - } - return public_key_token; - } - set { - public_key_token = value; - full_name = null; - } - } - - byte [] HashPublicKey () - { - HashAlgorithm algorithm; - - switch (hash_algorithm) { - case AssemblyHashAlgorithm.Reserved: -#if SILVERLIGHT - throw new NotSupportedException (); -#else - algorithm = MD5.Create (); - break; -#endif - default: - // None default to SHA1 -#if SILVERLIGHT - algorithm = new SHA1Managed (); - break; -#else - algorithm = SHA1.Create (); - break; -#endif - } - - using (algorithm) - return algorithm.ComputeHash (public_key); - } - - public virtual MetadataScopeType MetadataScopeType { - get { return MetadataScopeType.AssemblyNameReference; } - } - - public string FullName { - get { - if (full_name != null) - return full_name; - - const string sep = ", "; - - var builder = new StringBuilder (); - builder.Append (name); - if (version != null) { - builder.Append (sep); - builder.Append ("Version="); - builder.Append (version.ToString ()); - } - builder.Append (sep); - builder.Append ("Culture="); - builder.Append (string.IsNullOrEmpty (culture) ? "neutral" : culture); - builder.Append (sep); - builder.Append ("PublicKeyToken="); - - if (this.PublicKeyToken != null && public_key_token.Length > 0) { - for (int i = 0 ; i < public_key_token.Length ; i++) { - builder.Append (public_key_token [i].ToString ("x2")); - } - } else - builder.Append ("null"); - - return full_name = builder.ToString (); - } - } - - public static AssemblyNameReference Parse (string fullName) - { - if (fullName == null) - throw new ArgumentNullException ("fullName"); - if (fullName.Length == 0) - throw new ArgumentException ("Name can not be empty"); - - var name = new AssemblyNameReference (); - var tokens = fullName.Split (','); - for (int i = 0; i < tokens.Length; i++) { - var token = tokens [i].Trim (); - - if (i == 0) { - name.Name = token; - continue; - } - - var parts = token.Split ('='); - if (parts.Length != 2) - throw new ArgumentException ("Malformed name"); - - switch (parts [0].ToLowerInvariant ()) { - case "version": - name.Version = new Version (parts [1]); - break; - case "culture": - name.Culture = parts [1]; - break; - 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++) - name.PublicKeyToken [j] = Byte.Parse (pk_token.Substring (j * 2, 2), NumberStyles.HexNumber); - - break; - } - } - - return name; - } - - public AssemblyHashAlgorithm HashAlgorithm { - get { return hash_algorithm; } - set { hash_algorithm = value; } - } - - public virtual byte [] Hash { - get { return hash; } - set { hash = value; } - } - - public MetadataToken MetadataToken { - get { return token; } - set { token = value; } - } - - internal AssemblyNameReference () - { - } - - public AssemblyNameReference (string name, Version version) - { - if (name == null) - throw new ArgumentNullException ("name"); - - this.name = name; - this.version = version; - this.hash_algorithm = AssemblyHashAlgorithm.None; - this.token = new MetadataToken (TokenType.AssemblyRef); - } - - public override string ToString () - { - return this.FullName; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyReader.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyReader.cs deleted file mode 100644 index 9aa5b13658c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyReader.cs +++ /dev/null @@ -1,3161 +0,0 @@ -// -// AssemblyReader.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -using Mono.Collections.Generic; -using Mono.Cecil.Cil; -using Mono.Cecil.Metadata; -using Mono.Cecil.PE; - -using RVA = System.UInt32; - -namespace Mono.Cecil { - - abstract class ModuleReader { - - readonly protected Image image; - readonly protected ModuleDefinition module; - - protected ModuleReader (Image image, ReadingMode mode) - { - this.image = image; - this.module = new ModuleDefinition (image); - this.module.ReadingMode = mode; - } - - protected abstract void ReadModule (); - - protected void ReadModuleManifest (MetadataReader reader) - { - reader.Populate (module); - - ReadAssembly (reader); - } - - void ReadAssembly (MetadataReader reader) - { - var name = reader.ReadAssemblyNameDefinition (); - if (name == null) { - module.kind = ModuleKind.NetModule; - return; - } - - var assembly = new AssemblyDefinition (); - assembly.Name = name; - - module.assembly = assembly; - assembly.main_module = module; - } - - public static ModuleDefinition CreateModuleFrom (Image image, ReaderParameters parameters) - { - var module = ReadModule (image, parameters); - - ReadSymbols (module, parameters); - - if (parameters.AssemblyResolver != null) - module.assembly_resolver = parameters.AssemblyResolver; - - if (parameters.MetadataResolver != null) - module.metadata_resolver = parameters.MetadataResolver; - - return module; - } - - static void ReadSymbols (ModuleDefinition module, ReaderParameters parameters) - { - var symbol_reader_provider = parameters.SymbolReaderProvider; - - if (symbol_reader_provider == null && parameters.ReadSymbols) - symbol_reader_provider = SymbolProvider.GetPlatformReaderProvider (); - - if (symbol_reader_provider != null) { - module.SymbolReaderProvider = symbol_reader_provider; - - var reader = parameters.SymbolStream != null - ? symbol_reader_provider.GetSymbolReader (module, parameters.SymbolStream) - : symbol_reader_provider.GetSymbolReader (module, module.FullyQualifiedName); - - module.ReadSymbols (reader); - } - } - - static ModuleDefinition ReadModule (Image image, ReaderParameters parameters) - { - var reader = CreateModuleReader (image, parameters.ReadingMode); - reader.ReadModule (); - return reader.module; - } - - static ModuleReader CreateModuleReader (Image image, ReadingMode mode) - { - switch (mode) { - case ReadingMode.Immediate: - return new ImmediateModuleReader (image); - case ReadingMode.Deferred: - return new DeferredModuleReader (image); - default: - throw new ArgumentException (); - } - } - } - - sealed class ImmediateModuleReader : ModuleReader { - - public ImmediateModuleReader (Image image) - : base (image, ReadingMode.Immediate) - { - } - - protected override void ReadModule () - { - this.module.Read (this.module, (module, reader) => { - ReadModuleManifest (reader); - ReadModule (module); - return module; - }); - } - - public static void ReadModule (ModuleDefinition module) - { - if (module.HasAssemblyReferences) - Read (module.AssemblyReferences); - if (module.HasResources) - Read (module.Resources); - if (module.HasModuleReferences) - Read (module.ModuleReferences); - if (module.HasTypes) - ReadTypes (module.Types); - if (module.HasExportedTypes) - Read (module.ExportedTypes); - if (module.HasCustomAttributes) - Read (module.CustomAttributes); - - var assembly = module.Assembly; - if (assembly == null) - return; - - if (assembly.HasCustomAttributes) - Read (assembly.CustomAttributes); - if (assembly.HasSecurityDeclarations) - Read (assembly.SecurityDeclarations); - } - - static void ReadTypes (Collection types) - { - for (int i = 0; i < types.Count; i++) - ReadType (types [i]); - } - - static void ReadType (TypeDefinition type) - { - ReadGenericParameters (type); - - if (type.HasInterfaces) - Read (type.Interfaces); - - if (type.HasNestedTypes) - ReadTypes (type.NestedTypes); - - if (type.HasLayoutInfo) - Read (type.ClassSize); - - if (type.HasFields) - ReadFields (type); - - if (type.HasMethods) - ReadMethods (type); - - if (type.HasProperties) - ReadProperties (type); - - if (type.HasEvents) - ReadEvents (type); - - ReadSecurityDeclarations (type); - ReadCustomAttributes (type); - } - - static void ReadGenericParameters (IGenericParameterProvider provider) - { - if (!provider.HasGenericParameters) - return; - - var parameters = provider.GenericParameters; - - for (int i = 0; i < parameters.Count; i++) { - var parameter = parameters [i]; - - if (parameter.HasConstraints) - Read (parameter.Constraints); - - if (parameter.HasCustomAttributes) - Read (parameter.CustomAttributes); - } - } - - static void ReadSecurityDeclarations (ISecurityDeclarationProvider provider) - { - if (provider.HasSecurityDeclarations) - Read (provider.SecurityDeclarations); - } - - static void ReadCustomAttributes (ICustomAttributeProvider provider) - { - if (provider.HasCustomAttributes) - Read (provider.CustomAttributes); - } - - static void ReadFields (TypeDefinition type) - { - var fields = type.Fields; - - for (int i = 0; i < fields.Count; i++) { - var field = fields [i]; - - if (field.HasConstant) - Read (field.Constant); - - if (field.HasLayoutInfo) - Read (field.Offset); - - if (field.RVA > 0) - Read (field.InitialValue); - - if (field.HasMarshalInfo) - Read (field.MarshalInfo); - - ReadCustomAttributes (field); - } - } - - static void ReadMethods (TypeDefinition type) - { - var methods = type.Methods; - - for (int i = 0; i < methods.Count; i++) { - var method = methods [i]; - - ReadGenericParameters (method); - - if (method.HasParameters) - ReadParameters (method); - - if (method.HasOverrides) - Read (method.Overrides); - - if (method.IsPInvokeImpl) - Read (method.PInvokeInfo); - - ReadSecurityDeclarations (method); - ReadCustomAttributes (method); - - var return_type = method.MethodReturnType; - if (return_type.HasConstant) - Read (return_type.Constant); - - if (return_type.HasMarshalInfo) - Read (return_type.MarshalInfo); - - ReadCustomAttributes (return_type); - } - } - - static void ReadParameters (MethodDefinition method) - { - var parameters = method.Parameters; - - for (int i = 0; i < parameters.Count; i++) { - var parameter = parameters [i]; - - if (parameter.HasConstant) - Read (parameter.Constant); - - if (parameter.HasMarshalInfo) - Read (parameter.MarshalInfo); - - ReadCustomAttributes (parameter); - } - } - - static void ReadProperties (TypeDefinition type) - { - var properties = type.Properties; - - for (int i = 0; i < properties.Count; i++) { - var property = properties [i]; - - Read (property.GetMethod); - - if (property.HasConstant) - Read (property.Constant); - - ReadCustomAttributes (property); - } - } - - static void ReadEvents (TypeDefinition type) - { - var events = type.Events; - - for (int i = 0; i < events.Count; i++) { - var @event = events [i]; - - Read (@event.AddMethod); - - ReadCustomAttributes (@event); - } - } - - static void Read (object collection) - { - } - } - - sealed class DeferredModuleReader : ModuleReader { - - public DeferredModuleReader (Image image) - : base (image, ReadingMode.Deferred) - { - } - - protected override void ReadModule () - { - this.module.Read (this.module, (module, reader) => { - ReadModuleManifest (reader); - return module; - }); - } - } - - sealed class MetadataReader : ByteBuffer { - - readonly internal Image image; - readonly internal ModuleDefinition module; - readonly internal MetadataSystem metadata; - - internal IGenericContext context; - internal CodeReader code; - - uint Position { - get { return (uint) base.position; } - set { base.position = (int) value; } - } - - public MetadataReader (ModuleDefinition module) - : base (module.Image.MetadataSection.Data) - { - this.image = module.Image; - this.module = module; - this.metadata = module.MetadataSystem; - this.code = new CodeReader (image.MetadataSection, this); - } - - int GetCodedIndexSize (CodedIndex index) - { - return image.GetCodedIndexSize (index); - } - - uint ReadByIndexSize (int size) - { - if (size == 4) - return ReadUInt32 (); - else - return ReadUInt16 (); - } - - byte [] ReadBlob () - { - var blob_heap = image.BlobHeap; - if (blob_heap == null) { - position += 2; - return Empty.Array; - } - - return blob_heap.Read (ReadBlobIndex ()); - } - - byte [] ReadBlob (uint signature) - { - var blob_heap = image.BlobHeap; - if (blob_heap == null) - return Empty.Array; - - return blob_heap.Read (signature); - } - - uint ReadBlobIndex () - { - var blob_heap = image.BlobHeap; - return ReadByIndexSize (blob_heap != null ? blob_heap.IndexSize : 2); - } - - string ReadString () - { - return image.StringHeap.Read (ReadByIndexSize (image.StringHeap.IndexSize)); - } - - uint ReadStringIndex () - { - return ReadByIndexSize (image.StringHeap.IndexSize); - } - - uint ReadTableIndex (Table table) - { - return ReadByIndexSize (image.GetTableIndexSize (table)); - } - - MetadataToken ReadMetadataToken (CodedIndex index) - { - return index.GetMetadataToken (ReadByIndexSize (GetCodedIndexSize (index))); - } - - int MoveTo (Table table) - { - var info = image.TableHeap [table]; - if (info.Length != 0) - Position = info.Offset; - - return (int) info.Length; - } - - bool MoveTo (Table table, uint row) - { - var info = image.TableHeap [table]; - var length = info.Length; - if (length == 0 || row > length) - return false; - - Position = info.Offset + (info.RowSize * (row - 1)); - return true; - } - - public AssemblyNameDefinition ReadAssemblyNameDefinition () - { - if (MoveTo (Table.Assembly) == 0) - return null; - - var name = new AssemblyNameDefinition (); - - name.HashAlgorithm = (AssemblyHashAlgorithm) ReadUInt32 (); - - PopulateVersionAndFlags (name); - - name.PublicKey = ReadBlob (); - - PopulateNameAndCulture (name); - - return name; - } - - public ModuleDefinition Populate (ModuleDefinition module) - { - if (MoveTo (Table.Module) == 0) - return module; - - Advance (2); // Generation - - module.Name = ReadString (); - module.Mvid = image.GuidHeap.Read (ReadByIndexSize (image.GuidHeap.IndexSize)); - - return module; - } - - void InitializeAssemblyReferences () - { - if (metadata.AssemblyReferences != null) - return; - - int length = MoveTo (Table.AssemblyRef); - var references = metadata.AssemblyReferences = new AssemblyNameReference [length]; - - for (uint i = 0; i < length; i++) { - var reference = new AssemblyNameReference (); - reference.token = new MetadataToken (TokenType.AssemblyRef, i + 1); - - PopulateVersionAndFlags (reference); - - var key_or_token = ReadBlob (); - - if (reference.HasPublicKey) - reference.PublicKey = key_or_token; - else - reference.PublicKeyToken = key_or_token; - - PopulateNameAndCulture (reference); - - reference.Hash = ReadBlob (); - - references [i] = reference; - } - } - - public Collection ReadAssemblyReferences () - { - InitializeAssemblyReferences (); - - return new Collection (metadata.AssemblyReferences); - } - - public MethodDefinition ReadEntryPoint () - { - if (module.Image.EntryPointToken == 0) - return null; - - var token = new MetadataToken (module.Image.EntryPointToken); - return GetMethodDefinition (token.RID); - } - - public Collection ReadModules () - { - var modules = new Collection (1); - modules.Add (this.module); - - int length = MoveTo (Table.File); - for (uint i = 1; i <= length; i++) { - var attributes = (FileAttributes) ReadUInt32 (); - var name = ReadString (); - ReadBlobIndex (); - - if (attributes != FileAttributes.ContainsMetaData) - continue; - - var parameters = new ReaderParameters { - ReadingMode = module.ReadingMode, - SymbolReaderProvider = module.SymbolReaderProvider, - }; - - modules.Add (ModuleDefinition.ReadModule ( - GetModuleFileName (name), parameters)); - } - - return modules; - } - - string GetModuleFileName (string name) - { - if (module.FullyQualifiedName == null) - throw new NotSupportedException (); - - var path = Path.GetDirectoryName (module.FullyQualifiedName); - return Path.Combine (path, name); - } - - void InitializeModuleReferences () - { - if (metadata.ModuleReferences != null) - return; - - int length = MoveTo (Table.ModuleRef); - var references = metadata.ModuleReferences = new ModuleReference [length]; - - for (uint i = 0; i < length; i++) { - var reference = new ModuleReference (ReadString ()); - reference.token = new MetadataToken (TokenType.ModuleRef, i + 1); - - references [i] = reference; - } - } - - public Collection ReadModuleReferences () - { - InitializeModuleReferences (); - - return new Collection (metadata.ModuleReferences); - } - - public bool HasFileResource () - { - int length = MoveTo (Table.File); - if (length == 0) - return false; - - for (uint i = 1; i <= length; i++) - if (ReadFileRecord (i).Col1 == FileAttributes.ContainsNoMetaData) - return true; - - return false; - } - - public Collection ReadResources () - { - int length = MoveTo (Table.ManifestResource); - var resources = new Collection (length); - - for (int i = 1; i <= length; i++) { - var offset = ReadUInt32 (); - var flags = (ManifestResourceAttributes) ReadUInt32 (); - var name = ReadString (); - var implementation = ReadMetadataToken (CodedIndex.Implementation); - - Resource resource; - - if (implementation.RID == 0) { - resource = new EmbeddedResource (name, flags, offset, this); - } else if (implementation.TokenType == TokenType.AssemblyRef) { - resource = new AssemblyLinkedResource (name, flags) { - Assembly = (AssemblyNameReference) GetTypeReferenceScope (implementation), - }; - } else if (implementation.TokenType == TokenType.File) { - var file_record = ReadFileRecord (implementation.RID); - - resource = new LinkedResource (name, flags) { - File = file_record.Col2, - hash = ReadBlob (file_record.Col3) - }; - } else - throw new NotSupportedException (); - - resources.Add (resource); - } - - return resources; - } - - Row ReadFileRecord (uint rid) - { - var position = this.position; - - if (!MoveTo (Table.File, rid)) - throw new ArgumentException (); - - var record = new Row ( - (FileAttributes) ReadUInt32 (), - ReadString (), - ReadBlobIndex ()); - - this.position = position; - - return record; - } - - public MemoryStream GetManagedResourceStream (uint offset) - { - var rva = image.Resources.VirtualAddress; - var section = image.GetSectionAtVirtualAddress (rva); - var position = (rva - section.VirtualAddress) + offset; - var buffer = section.Data; - - var length = buffer [position] - | (buffer [position + 1] << 8) - | (buffer [position + 2] << 16) - | (buffer [position + 3] << 24); - - return new MemoryStream (buffer, (int) position + 4, length); - } - - void PopulateVersionAndFlags (AssemblyNameReference name) - { - name.Version = new Version ( - ReadUInt16 (), - ReadUInt16 (), - ReadUInt16 (), - ReadUInt16 ()); - - name.Attributes = (AssemblyAttributes) ReadUInt32 (); - } - - void PopulateNameAndCulture (AssemblyNameReference name) - { - name.Name = ReadString (); - name.Culture = ReadString (); - } - - public TypeDefinitionCollection ReadTypes () - { - InitializeTypeDefinitions (); - var mtypes = metadata.Types; - var type_count = mtypes.Length - metadata.NestedTypes.Count; - var types = new TypeDefinitionCollection (module, type_count); - - for (int i = 0; i < mtypes.Length; i++) { - var type = mtypes [i]; - if (IsNested (type.Attributes)) - continue; - - types.Add (type); - } - - if (image.HasTable (Table.MethodPtr) || image.HasTable (Table.FieldPtr)) - CompleteTypes (); - - return types; - } - - void CompleteTypes () - { - var types = metadata.Types; - - for (int i = 0; i < types.Length; i++) { - var type = types [i]; - - InitializeCollection (type.Fields); - InitializeCollection (type.Methods); - } - } - - void InitializeTypeDefinitions () - { - if (metadata.Types != null) - return; - - InitializeNestedTypes (); - InitializeFields (); - InitializeMethods (); - - int length = MoveTo (Table.TypeDef); - var types = metadata.Types = new TypeDefinition [length]; - - for (uint i = 0; i < length; i++) { - if (types [i] != null) - continue; - - types [i] = ReadType (i + 1); - } - } - - static bool IsNested (TypeAttributes attributes) - { - switch (attributes & TypeAttributes.VisibilityMask) { - case TypeAttributes.NestedAssembly: - case TypeAttributes.NestedFamANDAssem: - case TypeAttributes.NestedFamily: - case TypeAttributes.NestedFamORAssem: - case TypeAttributes.NestedPrivate: - case TypeAttributes.NestedPublic: - return true; - default: - return false; - } - } - - public bool HasNestedTypes (TypeDefinition type) - { - uint [] mapping; - InitializeNestedTypes (); - - if (!metadata.TryGetNestedTypeMapping (type, out mapping)) - return false; - - return mapping.Length > 0; - } - - public Collection ReadNestedTypes (TypeDefinition type) - { - InitializeNestedTypes (); - uint [] mapping; - if (!metadata.TryGetNestedTypeMapping (type, out mapping)) - return new MemberDefinitionCollection (type); - - var nested_types = new MemberDefinitionCollection (type, mapping.Length); - - for (int i = 0; i < mapping.Length; i++) - nested_types.Add (GetTypeDefinition (mapping [i])); - - metadata.RemoveNestedTypeMapping (type); - - return nested_types; - } - - void InitializeNestedTypes () - { - if (metadata.NestedTypes != null) - return; - - var length = MoveTo (Table.NestedClass); - - metadata.NestedTypes = new Dictionary (length); - metadata.ReverseNestedTypes = new Dictionary (length); - - if (length == 0) - return; - - for (int i = 1; i <= length; i++) { - var nested = ReadTableIndex (Table.TypeDef); - var declaring = ReadTableIndex (Table.TypeDef); - - AddNestedMapping (declaring, nested); - } - } - - void AddNestedMapping (uint declaring, uint nested) - { - metadata.SetNestedTypeMapping (declaring, AddMapping (metadata.NestedTypes, declaring, nested)); - metadata.SetReverseNestedTypeMapping (nested, declaring); - } - - static TValue [] AddMapping (Dictionary cache, TKey key, TValue value) - { - TValue [] mapped; - if (!cache.TryGetValue (key, out mapped)) { - mapped = new [] { value }; - return mapped; - } - - var new_mapped = new TValue [mapped.Length + 1]; - Array.Copy (mapped, new_mapped, mapped.Length); - new_mapped [mapped.Length] = value; - return new_mapped; - } - - TypeDefinition ReadType (uint rid) - { - if (!MoveTo (Table.TypeDef, rid)) - return null; - - var attributes = (TypeAttributes) ReadUInt32 (); - var name = ReadString (); - var @namespace = ReadString (); - var type = new TypeDefinition (@namespace, name, attributes); - type.token = new MetadataToken (TokenType.TypeDef, rid); - type.scope = module; - type.module = module; - - metadata.AddTypeDefinition (type); - - this.context = type; - - type.BaseType = GetTypeDefOrRef (ReadMetadataToken (CodedIndex.TypeDefOrRef)); - - type.fields_range = ReadFieldsRange (rid); - type.methods_range = ReadMethodsRange (rid); - - if (IsNested (attributes)) - type.DeclaringType = GetNestedTypeDeclaringType (type); - - return type; - } - - TypeDefinition GetNestedTypeDeclaringType (TypeDefinition type) - { - uint declaring_rid; - if (!metadata.TryGetReverseNestedTypeMapping (type, out declaring_rid)) - return null; - - metadata.RemoveReverseNestedTypeMapping (type); - return GetTypeDefinition (declaring_rid); - } - - Range ReadFieldsRange (uint type_index) - { - return ReadListRange (type_index, Table.TypeDef, Table.Field); - } - - Range ReadMethodsRange (uint type_index) - { - return ReadListRange (type_index, Table.TypeDef, Table.Method); - } - - Range ReadListRange (uint current_index, Table current, Table target) - { - var list = new Range (); - - list.Start = ReadTableIndex (target); - - uint next_index; - var current_table = image.TableHeap [current]; - - if (current_index == current_table.Length) - next_index = image.TableHeap [target].Length + 1; - else { - var position = Position; - Position += (uint) (current_table.RowSize - image.GetTableIndexSize (target)); - next_index = ReadTableIndex (target); - Position = position; - } - - list.Length = next_index - list.Start; - - return list; - } - - public Row ReadTypeLayout (TypeDefinition type) - { - InitializeTypeLayouts (); - Row class_layout; - var rid = type.token.RID; - if (!metadata.ClassLayouts.TryGetValue (rid, out class_layout)) - return new Row (Mixin.NoDataMarker, Mixin.NoDataMarker); - - type.PackingSize = (short) class_layout.Col1; - type.ClassSize = (int) class_layout.Col2; - - metadata.ClassLayouts.Remove (rid); - - return new Row ((short) class_layout.Col1, (int) class_layout.Col2); - } - - void InitializeTypeLayouts () - { - if (metadata.ClassLayouts != null) - return; - - int length = MoveTo (Table.ClassLayout); - - var class_layouts = metadata.ClassLayouts = new Dictionary> (length); - - for (uint i = 0; i < length; i++) { - var packing_size = ReadUInt16 (); - var class_size = ReadUInt32 (); - - var parent = ReadTableIndex (Table.TypeDef); - - class_layouts.Add (parent, new Row (packing_size, class_size)); - } - } - - public TypeReference GetTypeDefOrRef (MetadataToken token) - { - return (TypeReference) LookupToken (token); - } - - public TypeDefinition GetTypeDefinition (uint rid) - { - InitializeTypeDefinitions (); - - var type = metadata.GetTypeDefinition (rid); - if (type != null) - return type; - - return ReadTypeDefinition (rid); - } - - TypeDefinition ReadTypeDefinition (uint rid) - { - if (!MoveTo (Table.TypeDef, rid)) - return null; - - return ReadType (rid); - } - - void InitializeTypeReferences () - { - if (metadata.TypeReferences != null) - return; - - metadata.TypeReferences = new TypeReference [image.GetTableLength (Table.TypeRef)]; - } - - public TypeReference GetTypeReference (string scope, string full_name) - { - InitializeTypeReferences (); - - var length = metadata.TypeReferences.Length; - - for (uint i = 1; i <= length; i++) { - var type = GetTypeReference (i); - - if (type.FullName != full_name) - continue; - - if (string.IsNullOrEmpty (scope)) - return type; - - if (type.Scope.Name == scope) - return type; - } - - return null; - } - - TypeReference GetTypeReference (uint rid) - { - InitializeTypeReferences (); - - var type = metadata.GetTypeReference (rid); - if (type != null) - return type; - - return ReadTypeReference (rid); - } - - TypeReference ReadTypeReference (uint rid) - { - if (!MoveTo (Table.TypeRef, rid)) - return null; - - TypeReference declaring_type = null; - IMetadataScope scope; - - var scope_token = ReadMetadataToken (CodedIndex.ResolutionScope); - - var name = ReadString (); - var @namespace = ReadString (); - - var type = new TypeReference ( - @namespace, - name, - module, - null); - - type.token = new MetadataToken (TokenType.TypeRef, rid); - - metadata.AddTypeReference (type); - - if (scope_token.TokenType == TokenType.TypeRef) { - declaring_type = GetTypeDefOrRef (scope_token); - - scope = declaring_type != null - ? declaring_type.Scope - : module; - } else - scope = GetTypeReferenceScope (scope_token); - - type.scope = scope; - type.DeclaringType = declaring_type; - - MetadataSystem.TryProcessPrimitiveTypeReference (type); - - return type; - } - - IMetadataScope GetTypeReferenceScope (MetadataToken scope) - { - switch (scope.TokenType) { - case TokenType.AssemblyRef: - InitializeAssemblyReferences (); - return metadata.AssemblyReferences [(int) scope.RID - 1]; - case TokenType.ModuleRef: - InitializeModuleReferences (); - return metadata.ModuleReferences [(int) scope.RID - 1]; - case TokenType.Module: - return module; - default: - throw new NotSupportedException (); - } - } - - public IEnumerable GetTypeReferences () - { - InitializeTypeReferences (); - - var length = image.GetTableLength (Table.TypeRef); - - var type_references = new TypeReference [length]; - - for (uint i = 1; i <= length; i++) - type_references [i - 1] = GetTypeReference (i); - - return type_references; - } - - TypeReference GetTypeSpecification (uint rid) - { - if (!MoveTo (Table.TypeSpec, rid)) - return null; - - var reader = ReadSignature (ReadBlobIndex ()); - var type = reader.ReadTypeSignature (); - if (type.token.RID == 0) - type.token = new MetadataToken (TokenType.TypeSpec, rid); - - return type; - } - - SignatureReader ReadSignature (uint signature) - { - return new SignatureReader (signature, this); - } - - public bool HasInterfaces (TypeDefinition type) - { - InitializeInterfaces (); - MetadataToken [] mapping; - - return metadata.TryGetInterfaceMapping (type, out mapping); - } - - public Collection ReadInterfaces (TypeDefinition type) - { - InitializeInterfaces (); - MetadataToken [] mapping; - - if (!metadata.TryGetInterfaceMapping (type, out mapping)) - return new Collection (); - - var interfaces = new Collection (mapping.Length); - - this.context = type; - - for (int i = 0; i < mapping.Length; i++) - interfaces.Add (GetTypeDefOrRef (mapping [i])); - - metadata.RemoveInterfaceMapping (type); - - return interfaces; - } - - void InitializeInterfaces () - { - if (metadata.Interfaces != null) - return; - - int length = MoveTo (Table.InterfaceImpl); - - metadata.Interfaces = new Dictionary (length); - - for (int i = 0; i < length; i++) { - var type = ReadTableIndex (Table.TypeDef); - var @interface = ReadMetadataToken (CodedIndex.TypeDefOrRef); - - AddInterfaceMapping (type, @interface); - } - } - - void AddInterfaceMapping (uint type, MetadataToken @interface) - { - metadata.SetInterfaceMapping (type, AddMapping (metadata.Interfaces, type, @interface)); - } - - public Collection ReadFields (TypeDefinition type) - { - var fields_range = type.fields_range; - if (fields_range.Length == 0) - return new MemberDefinitionCollection (type); - - var fields = new MemberDefinitionCollection (type, (int) fields_range.Length); - this.context = type; - - if (!MoveTo (Table.FieldPtr, fields_range.Start)) { - if (!MoveTo (Table.Field, fields_range.Start)) - return fields; - - for (uint i = 0; i < fields_range.Length; i++) - ReadField (fields_range.Start + i, fields); - } else - ReadPointers (Table.FieldPtr, Table.Field, fields_range, fields, ReadField); - - return fields; - } - - void ReadField (uint field_rid, Collection fields) - { - var attributes = (FieldAttributes) ReadUInt16 (); - var name = ReadString (); - var signature = ReadBlobIndex (); - - var field = new FieldDefinition (name, attributes, ReadFieldType (signature)); - field.token = new MetadataToken (TokenType.Field, field_rid); - metadata.AddFieldDefinition (field); - - if (IsDeleted (field)) - return; - - fields.Add (field); - } - - void InitializeFields () - { - if (metadata.Fields != null) - return; - - metadata.Fields = new FieldDefinition [image.GetTableLength (Table.Field)]; - } - - TypeReference ReadFieldType (uint signature) - { - var reader = ReadSignature (signature); - - const byte field_sig = 0x6; - - if (reader.ReadByte () != field_sig) - throw new NotSupportedException (); - - return reader.ReadTypeSignature (); - } - - public int ReadFieldRVA (FieldDefinition field) - { - InitializeFieldRVAs (); - var rid = field.token.RID; - - RVA rva; - if (!metadata.FieldRVAs.TryGetValue (rid, out rva)) - return 0; - - var size = GetFieldTypeSize (field.FieldType); - - if (size == 0 || rva == 0) - return 0; - - metadata.FieldRVAs.Remove (rid); - - field.InitialValue = GetFieldInitializeValue (size, rva); - - return (int) rva; - } - - byte [] GetFieldInitializeValue (int size, RVA rva) - { - var section = image.GetSectionAtVirtualAddress (rva); - if (section == null) - return Empty.Array; - - var value = new byte [size]; - Buffer.BlockCopy (section.Data, (int) (rva - section.VirtualAddress), value, 0, size); - return value; - } - - static int GetFieldTypeSize (TypeReference type) - { - int size = 0; - - switch (type.etype) { - case ElementType.Boolean: - case ElementType.U1: - case ElementType.I1: - size = 1; - break; - case ElementType.U2: - case ElementType.I2: - case ElementType.Char: - size = 2; - break; - case ElementType.U4: - case ElementType.I4: - case ElementType.R4: - size = 4; - break; - case ElementType.U8: - case ElementType.I8: - case ElementType.R8: - size = 8; - break; - case ElementType.Ptr: - case ElementType.FnPtr: - size = IntPtr.Size; - break; - case ElementType.CModOpt: - case ElementType.CModReqD: - return GetFieldTypeSize (((IModifierType) type).ElementType); - default: - var field_type = type.CheckedResolve (); - if (field_type.HasLayoutInfo) - size = field_type.ClassSize; - - break; - } - - return size; - } - - void InitializeFieldRVAs () - { - if (metadata.FieldRVAs != null) - return; - - int length = MoveTo (Table.FieldRVA); - - var field_rvas = metadata.FieldRVAs = new Dictionary (length); - - for (int i = 0; i < length; i++) { - var rva = ReadUInt32 (); - var field = ReadTableIndex (Table.Field); - - field_rvas.Add (field, rva); - } - } - - public int ReadFieldLayout (FieldDefinition field) - { - InitializeFieldLayouts (); - var rid = field.token.RID; - uint offset; - if (!metadata.FieldLayouts.TryGetValue (rid, out offset)) - return Mixin.NoDataMarker; - - metadata.FieldLayouts.Remove (rid); - - return (int) offset; - } - - void InitializeFieldLayouts () - { - if (metadata.FieldLayouts != null) - return; - - int length = MoveTo (Table.FieldLayout); - - var field_layouts = metadata.FieldLayouts = new Dictionary (length); - - for (int i = 0; i < length; i++) { - var offset = ReadUInt32 (); - var field = ReadTableIndex (Table.Field); - - field_layouts.Add (field, offset); - } - } - - public bool HasEvents (TypeDefinition type) - { - InitializeEvents (); - - Range range; - if (!metadata.TryGetEventsRange (type, out range)) - return false; - - return range.Length > 0; - } - - public Collection ReadEvents (TypeDefinition type) - { - InitializeEvents (); - Range range; - - if (!metadata.TryGetEventsRange (type, out range)) - return new MemberDefinitionCollection (type); - - var events = new MemberDefinitionCollection (type, (int) range.Length); - - metadata.RemoveEventsRange (type); - - if (range.Length == 0) - return events; - - this.context = type; - - if (!MoveTo (Table.EventPtr, range.Start)) { - if (!MoveTo (Table.Event, range.Start)) - return events; - - for (uint i = 0; i < range.Length; i++) - ReadEvent (range.Start + i, events); - } else - ReadPointers (Table.EventPtr, Table.Event, range, events, ReadEvent); - - return events; - } - - void ReadEvent (uint event_rid, Collection events) - { - var attributes = (EventAttributes) ReadUInt16 (); - var name = ReadString (); - var event_type = GetTypeDefOrRef (ReadMetadataToken (CodedIndex.TypeDefOrRef)); - - var @event = new EventDefinition (name, attributes, event_type); - @event.token = new MetadataToken (TokenType.Event, event_rid); - - if (IsDeleted (@event)) - return; - - events.Add (@event); - } - - void InitializeEvents () - { - if (metadata.Events != null) - return; - - int length = MoveTo (Table.EventMap); - - metadata.Events = new Dictionary (length); - - for (uint i = 1; i <= length; i++) { - var type_rid = ReadTableIndex (Table.TypeDef); - Range events_range = ReadEventsRange (i); - metadata.AddEventsRange (type_rid, events_range); - } - } - - Range ReadEventsRange (uint rid) - { - return ReadListRange (rid, Table.EventMap, Table.Event); - } - - public bool HasProperties (TypeDefinition type) - { - InitializeProperties (); - - Range range; - if (!metadata.TryGetPropertiesRange (type, out range)) - return false; - - return range.Length > 0; - } - - public Collection ReadProperties (TypeDefinition type) - { - InitializeProperties (); - - Range range; - - if (!metadata.TryGetPropertiesRange (type, out range)) - return new MemberDefinitionCollection (type); - - metadata.RemovePropertiesRange (type); - - var properties = new MemberDefinitionCollection (type, (int) range.Length); - - if (range.Length == 0) - return properties; - - this.context = type; - - if (!MoveTo (Table.PropertyPtr, range.Start)) { - if (!MoveTo (Table.Property, range.Start)) - return properties; - for (uint i = 0; i < range.Length; i++) - ReadProperty (range.Start + i, properties); - } else - ReadPointers (Table.PropertyPtr, Table.Property, range, properties, ReadProperty); - - return properties; - } - - void ReadProperty (uint property_rid, Collection properties) - { - var attributes = (PropertyAttributes) ReadUInt16 (); - var name = ReadString (); - var signature = ReadBlobIndex (); - - var reader = ReadSignature (signature); - const byte property_signature = 0x8; - - var calling_convention = reader.ReadByte (); - - if ((calling_convention & property_signature) == 0) - throw new NotSupportedException (); - - var has_this = (calling_convention & 0x20) != 0; - - reader.ReadCompressedUInt32 (); // count - - var property = new PropertyDefinition (name, attributes, reader.ReadTypeSignature ()); - property.HasThis = has_this; - property.token = new MetadataToken (TokenType.Property, property_rid); - - if (IsDeleted (property)) - return; - - properties.Add (property); - } - - void InitializeProperties () - { - if (metadata.Properties != null) - return; - - int length = MoveTo (Table.PropertyMap); - - metadata.Properties = new Dictionary (length); - - for (uint i = 1; i <= length; i++) { - var type_rid = ReadTableIndex (Table.TypeDef); - var properties_range = ReadPropertiesRange (i); - metadata.AddPropertiesRange (type_rid, properties_range); - } - } - - Range ReadPropertiesRange (uint rid) - { - return ReadListRange (rid, Table.PropertyMap, Table.Property); - } - - MethodSemanticsAttributes ReadMethodSemantics (MethodDefinition method) - { - InitializeMethodSemantics (); - Row row; - if (!metadata.Semantics.TryGetValue (method.token.RID, out row)) - return MethodSemanticsAttributes.None; - - var type = method.DeclaringType; - - switch (row.Col1) { - case MethodSemanticsAttributes.AddOn: - GetEvent (type, row.Col2).add_method = method; - break; - case MethodSemanticsAttributes.Fire: - GetEvent (type, row.Col2).invoke_method = method; - break; - case MethodSemanticsAttributes.RemoveOn: - GetEvent (type, row.Col2).remove_method = method; - break; - case MethodSemanticsAttributes.Getter: - GetProperty (type, row.Col2).get_method = method; - break; - case MethodSemanticsAttributes.Setter: - GetProperty (type, row.Col2).set_method = method; - break; - case MethodSemanticsAttributes.Other: - switch (row.Col2.TokenType) { - case TokenType.Event: { - var @event = GetEvent (type, row.Col2); - if (@event.other_methods == null) - @event.other_methods = new Collection (); - - @event.other_methods.Add (method); - break; - } - case TokenType.Property: { - var property = GetProperty (type, row.Col2); - if (property.other_methods == null) - property.other_methods = new Collection (); - - property.other_methods.Add (method); - - break; - } - default: - throw new NotSupportedException (); - } - break; - default: - throw new NotSupportedException (); - } - - metadata.Semantics.Remove (method.token.RID); - - return row.Col1; - } - - static EventDefinition GetEvent (TypeDefinition type, MetadataToken token) - { - if (token.TokenType != TokenType.Event) - throw new ArgumentException (); - - return GetMember (type.Events, token); - } - - static PropertyDefinition GetProperty (TypeDefinition type, MetadataToken token) - { - if (token.TokenType != TokenType.Property) - throw new ArgumentException (); - - return GetMember (type.Properties, token); - } - - static TMember GetMember (Collection members, MetadataToken token) where TMember : IMemberDefinition - { - for (int i = 0; i < members.Count; i++) { - var member = members [i]; - if (member.MetadataToken == token) - return member; - } - - throw new ArgumentException (); - } - - void InitializeMethodSemantics () - { - if (metadata.Semantics != null) - return; - - int length = MoveTo (Table.MethodSemantics); - - var semantics = metadata.Semantics = new Dictionary> (0); - - for (uint i = 0; i < length; i++) { - var attributes = (MethodSemanticsAttributes) ReadUInt16 (); - var method_rid = ReadTableIndex (Table.Method); - var association = ReadMetadataToken (CodedIndex.HasSemantics); - - semantics [method_rid] = new Row (attributes, association); - } - } - - public PropertyDefinition ReadMethods (PropertyDefinition property) - { - ReadAllSemantics (property.DeclaringType); - return property; - } - - public EventDefinition ReadMethods (EventDefinition @event) - { - ReadAllSemantics (@event.DeclaringType); - return @event; - } - - public MethodSemanticsAttributes ReadAllSemantics (MethodDefinition method) - { - ReadAllSemantics (method.DeclaringType); - - return method.SemanticsAttributes; - } - - void ReadAllSemantics (TypeDefinition type) - { - var methods = type.Methods; - for (int i = 0; i < methods.Count; i++) { - var method = methods [i]; - if (method.sem_attrs.HasValue) - continue; - - method.sem_attrs = ReadMethodSemantics (method); - } - } - - Range ReadParametersRange (uint method_rid) - { - return ReadListRange (method_rid, Table.Method, Table.Param); - } - - public Collection ReadMethods (TypeDefinition type) - { - var methods_range = type.methods_range; - if (methods_range.Length == 0) - return new MemberDefinitionCollection (type); - - var methods = new MemberDefinitionCollection (type, (int) methods_range.Length); - if (!MoveTo (Table.MethodPtr, methods_range.Start)) { - if (!MoveTo (Table.Method, methods_range.Start)) - return methods; - - for (uint i = 0; i < methods_range.Length; i++) - ReadMethod (methods_range.Start + i, methods); - } else - ReadPointers (Table.MethodPtr, Table.Method, methods_range, methods, ReadMethod); - - return methods; - } - - void ReadPointers (Table ptr, Table table, Range range, Collection members, Action> reader) - where TMember : IMemberDefinition - { - for (uint i = 0; i < range.Length; i++) { - MoveTo (ptr, range.Start + i); - - var rid = ReadTableIndex (table); - MoveTo (table, rid); - - reader (rid, members); - } - } - - static bool IsDeleted (IMemberDefinition member) - { - return member.IsSpecialName && member.Name == "_Deleted"; - } - - void InitializeMethods () - { - if (metadata.Methods != null) - return; - - metadata.Methods = new MethodDefinition [image.GetTableLength (Table.Method)]; - } - - void ReadMethod (uint method_rid, Collection methods) - { - var method = new MethodDefinition (); - method.rva = ReadUInt32 (); - method.ImplAttributes = (MethodImplAttributes) ReadUInt16 (); - method.Attributes = (MethodAttributes) ReadUInt16 (); - method.Name = ReadString (); - method.token = new MetadataToken (TokenType.Method, method_rid); - - if (IsDeleted (method)) - return; - - methods.Add (method); // attach method - - var signature = ReadBlobIndex (); - var param_range = ReadParametersRange (method_rid); - - this.context = method; - - ReadMethodSignature (signature, method); - metadata.AddMethodDefinition (method); - - if (param_range.Length == 0) - return; - - var position = base.position; - ReadParameters (method, param_range); - base.position = position; - } - - void ReadParameters (MethodDefinition method, Range param_range) - { - if (!MoveTo (Table.ParamPtr, param_range.Start)) { - if (!MoveTo (Table.Param, param_range.Start)) - return; - - for (uint i = 0; i < param_range.Length; i++) - ReadParameter (param_range.Start + i, method); - } else - ReadParameterPointers (method, param_range); - } - - void ReadParameterPointers (MethodDefinition method, Range range) - { - for (uint i = 0; i < range.Length; i++) { - MoveTo (Table.ParamPtr, range.Start + i); - - var rid = ReadTableIndex (Table.Param); - - MoveTo (Table.Param, rid); - - ReadParameter (rid, method); - } - } - - void ReadParameter (uint param_rid, MethodDefinition method) - { - var attributes = (ParameterAttributes) ReadUInt16 (); - var sequence = ReadUInt16 (); - var name = ReadString (); - - var parameter = sequence == 0 - ? method.MethodReturnType.Parameter - : method.Parameters [sequence - 1]; - - parameter.token = new MetadataToken (TokenType.Param, param_rid); - parameter.Name = name; - parameter.Attributes = attributes; - } - - void ReadMethodSignature (uint signature, IMethodSignature method) - { - var reader = ReadSignature (signature); - reader.ReadMethodSignature (method); - } - - public PInvokeInfo ReadPInvokeInfo (MethodDefinition method) - { - InitializePInvokes (); - Row row; - - var rid = method.token.RID; - - if (!metadata.PInvokes.TryGetValue (rid, out row)) - return null; - - metadata.PInvokes.Remove (rid); - - return new PInvokeInfo ( - row.Col1, - image.StringHeap.Read (row.Col2), - module.ModuleReferences [(int) row.Col3 - 1]); - } - - void InitializePInvokes () - { - if (metadata.PInvokes != null) - return; - - int length = MoveTo (Table.ImplMap); - - var pinvokes = metadata.PInvokes = new Dictionary> (length); - - for (int i = 1; i <= length; i++) { - var attributes = (PInvokeAttributes) ReadUInt16 (); - var method = ReadMetadataToken (CodedIndex.MemberForwarded); - var name = ReadStringIndex (); - var scope = ReadTableIndex (Table.File); - - if (method.TokenType != TokenType.Method) - continue; - - pinvokes.Add (method.RID, new Row (attributes, name, scope)); - } - } - - public bool HasGenericParameters (IGenericParameterProvider provider) - { - InitializeGenericParameters (); - - Range range; - if (!metadata.TryGetGenericParameterRange (provider, out range)) - return false; - - return range.Length > 0; - } - - public Collection ReadGenericParameters (IGenericParameterProvider provider) - { - InitializeGenericParameters (); - - Range range; - if (!metadata.TryGetGenericParameterRange (provider, out range) - || !MoveTo (Table.GenericParam, range.Start)) - return new GenericParameterCollection (provider); - - metadata.RemoveGenericParameterRange (provider); - - var generic_parameters = new GenericParameterCollection (provider, (int) range.Length); - - for (uint i = 0; i < range.Length; i++) { - ReadUInt16 (); // index - var flags = (GenericParameterAttributes) ReadUInt16 (); - ReadMetadataToken (CodedIndex.TypeOrMethodDef); - var name = ReadString (); - - var parameter = new GenericParameter (name, provider); - parameter.token = new MetadataToken (TokenType.GenericParam, range.Start + i); - parameter.Attributes = flags; - - generic_parameters.Add (parameter); - } - - return generic_parameters; - } - - void InitializeGenericParameters () - { - if (metadata.GenericParameters != null) - return; - - metadata.GenericParameters = InitializeRanges ( - Table.GenericParam, () => { - Advance (4); - var next = ReadMetadataToken (CodedIndex.TypeOrMethodDef); - ReadStringIndex (); - return next; - }); - } - - Dictionary InitializeRanges (Table table, Func get_next) - { - int length = MoveTo (table); - var ranges = new Dictionary (length); - - if (length == 0) - return ranges; - - MetadataToken owner = MetadataToken.Zero; - Range range = new Range (1, 0); - - for (uint i = 1; i <= length; i++) { - var next = get_next (); - - if (i == 1) { - owner = next; - range.Length++; - } else if (next != owner) { - if (owner.RID != 0) - ranges.Add (owner, range); - range = new Range (i, 1); - owner = next; - } else - range.Length++; - } - - if (owner != MetadataToken.Zero && !ranges.ContainsKey (owner)) - ranges.Add (owner, range); - - return ranges; - } - - public bool HasGenericConstraints (GenericParameter generic_parameter) - { - InitializeGenericConstraints (); - - MetadataToken [] mapping; - if (!metadata.TryGetGenericConstraintMapping (generic_parameter, out mapping)) - return false; - - return mapping.Length > 0; - } - - public Collection ReadGenericConstraints (GenericParameter generic_parameter) - { - InitializeGenericConstraints (); - - MetadataToken [] mapping; - if (!metadata.TryGetGenericConstraintMapping (generic_parameter, out mapping)) - return new Collection (); - - var constraints = new Collection (mapping.Length); - - this.context = (IGenericContext) generic_parameter.Owner; - - for (int i = 0; i < mapping.Length; i++) - constraints.Add (GetTypeDefOrRef (mapping [i])); - - metadata.RemoveGenericConstraintMapping (generic_parameter); - - return constraints; - } - - void InitializeGenericConstraints () - { - if (metadata.GenericConstraints != null) - return; - - var length = MoveTo (Table.GenericParamConstraint); - - metadata.GenericConstraints = new Dictionary (length); - - for (int i = 1; i <= length; i++) - AddGenericConstraintMapping ( - ReadTableIndex (Table.GenericParam), - ReadMetadataToken (CodedIndex.TypeDefOrRef)); - } - - void AddGenericConstraintMapping (uint generic_parameter, MetadataToken constraint) - { - metadata.SetGenericConstraintMapping ( - generic_parameter, - AddMapping (metadata.GenericConstraints, generic_parameter, constraint)); - } - - public bool HasOverrides (MethodDefinition method) - { - InitializeOverrides (); - MetadataToken [] mapping; - - if (!metadata.TryGetOverrideMapping (method, out mapping)) - return false; - - return mapping.Length > 0; - } - - public Collection ReadOverrides (MethodDefinition method) - { - InitializeOverrides (); - - MetadataToken [] mapping; - if (!metadata.TryGetOverrideMapping (method, out mapping)) - return new Collection (); - - var overrides = new Collection (mapping.Length); - - this.context = method; - - for (int i = 0; i < mapping.Length; i++) - overrides.Add ((MethodReference) LookupToken (mapping [i])); - - metadata.RemoveOverrideMapping (method); - - return overrides; - } - - void InitializeOverrides () - { - if (metadata.Overrides != null) - return; - - var length = MoveTo (Table.MethodImpl); - - metadata.Overrides = new Dictionary (length); - - for (int i = 1; i <= length; i++) { - ReadTableIndex (Table.TypeDef); - - var method = ReadMetadataToken (CodedIndex.MethodDefOrRef); - if (method.TokenType != TokenType.Method) - throw new NotSupportedException (); - - var @override = ReadMetadataToken (CodedIndex.MethodDefOrRef); - - AddOverrideMapping (method.RID, @override); - } - } - - void AddOverrideMapping (uint method_rid, MetadataToken @override) - { - metadata.SetOverrideMapping ( - method_rid, - AddMapping (metadata.Overrides, method_rid, @override)); - } - - public MethodBody ReadMethodBody (MethodDefinition method) - { - return code.ReadMethodBody (method); - } - - public CallSite ReadCallSite (MetadataToken token) - { - if (!MoveTo (Table.StandAloneSig, token.RID)) - return null; - - var signature = ReadBlobIndex (); - - var call_site = new CallSite (); - - ReadMethodSignature (signature, call_site); - - call_site.MetadataToken = token; - - return call_site; - } - - public VariableDefinitionCollection ReadVariables (MetadataToken local_var_token) - { - if (!MoveTo (Table.StandAloneSig, local_var_token.RID)) - return null; - - var reader = ReadSignature (ReadBlobIndex ()); - const byte local_sig = 0x7; - - if (reader.ReadByte () != local_sig) - throw new NotSupportedException (); - - var count = reader.ReadCompressedUInt32 (); - if (count == 0) - return null; - - var variables = new VariableDefinitionCollection ((int) count); - - for (int i = 0; i < count; i++) - variables.Add (new VariableDefinition (reader.ReadTypeSignature ())); - - return variables; - } - - public IMetadataTokenProvider LookupToken (MetadataToken token) - { - var rid = token.RID; - - if (rid == 0) - return null; - - IMetadataTokenProvider element; - var position = this.position; - var context = this.context; - - switch (token.TokenType) { - case TokenType.TypeDef: - element = GetTypeDefinition (rid); - break; - case TokenType.TypeRef: - element = GetTypeReference (rid); - break; - case TokenType.TypeSpec: - element = GetTypeSpecification (rid); - break; - case TokenType.Field: - element = GetFieldDefinition (rid); - break; - case TokenType.Method: - element = GetMethodDefinition (rid); - break; - case TokenType.MemberRef: - element = GetMemberReference (rid); - break; - case TokenType.MethodSpec: - element = GetMethodSpecification (rid); - break; - default: - return null; - } - - this.position = position; - this.context = context; - - return element; - } - - public FieldDefinition GetFieldDefinition (uint rid) - { - InitializeTypeDefinitions (); - - var field = metadata.GetFieldDefinition (rid); - if (field != null) - return field; - - return LookupField (rid); - } - - FieldDefinition LookupField (uint rid) - { - var type = metadata.GetFieldDeclaringType (rid); - if (type == null) - return null; - - InitializeCollection (type.Fields); - - return metadata.GetFieldDefinition (rid); - } - - public MethodDefinition GetMethodDefinition (uint rid) - { - InitializeTypeDefinitions (); - - var method = metadata.GetMethodDefinition (rid); - if (method != null) - return method; - - return LookupMethod (rid); - } - - MethodDefinition LookupMethod (uint rid) - { - var type = metadata.GetMethodDeclaringType (rid); - if (type == null) - return null; - - InitializeCollection (type.Methods); - - return metadata.GetMethodDefinition (rid); - } - - MethodSpecification GetMethodSpecification (uint rid) - { - if (!MoveTo (Table.MethodSpec, rid)) - return null; - - var element_method = (MethodReference) LookupToken ( - ReadMetadataToken (CodedIndex.MethodDefOrRef)); - var signature = ReadBlobIndex (); - - var method_spec = ReadMethodSpecSignature (signature, element_method); - method_spec.token = new MetadataToken (TokenType.MethodSpec, rid); - return method_spec; - } - - MethodSpecification ReadMethodSpecSignature (uint signature, MethodReference method) - { - var reader = ReadSignature (signature); - const byte methodspec_sig = 0x0a; - - var call_conv = reader.ReadByte (); - - if (call_conv != methodspec_sig) - throw new NotSupportedException (); - - var instance = new GenericInstanceMethod (method); - - reader.ReadGenericInstanceSignature (method, instance); - - return instance; - } - - MemberReference GetMemberReference (uint rid) - { - InitializeMemberReferences (); - - var member = metadata.GetMemberReference (rid); - if (member != null) - return member; - - member = ReadMemberReference (rid); - if (member != null && !member.ContainsGenericParameter) - metadata.AddMemberReference (member); - return member; - } - - MemberReference ReadMemberReference (uint rid) - { - if (!MoveTo (Table.MemberRef, rid)) - return null; - - var token = ReadMetadataToken (CodedIndex.MemberRefParent); - var name = ReadString (); - var signature = ReadBlobIndex (); - - MemberReference member; - - switch (token.TokenType) { - case TokenType.TypeDef: - case TokenType.TypeRef: - case TokenType.TypeSpec: - member = ReadTypeMemberReference (token, name, signature); - break; - case TokenType.Method: - member = ReadMethodMemberReference (token, name, signature); - break; - default: - throw new NotSupportedException (); - } - - member.token = new MetadataToken (TokenType.MemberRef, rid); - - return member; - } - - MemberReference ReadTypeMemberReference (MetadataToken type, string name, uint signature) - { - var declaring_type = GetTypeDefOrRef (type); - - if (!declaring_type.IsArray) - this.context = declaring_type; - - var member = ReadMemberReferenceSignature (signature, declaring_type); - member.Name = name; - - return member; - } - - MemberReference ReadMemberReferenceSignature (uint signature, TypeReference declaring_type) - { - var reader = ReadSignature (signature); - const byte field_sig = 0x6; - - if (reader.buffer [reader.position] == field_sig) { - reader.position++; - var field = new FieldReference (); - field.DeclaringType = declaring_type; - field.FieldType = reader.ReadTypeSignature (); - return field; - } else { - var method = new MethodReference (); - method.DeclaringType = declaring_type; - reader.ReadMethodSignature (method); - return method; - } - } - - MemberReference ReadMethodMemberReference (MetadataToken token, string name, uint signature) - { - var method = GetMethodDefinition (token.RID); - - this.context = method; - - var member = ReadMemberReferenceSignature (signature, method.DeclaringType); - member.Name = name; - - return member; - } - - void InitializeMemberReferences () - { - if (metadata.MemberReferences != null) - return; - - metadata.MemberReferences = new MemberReference [image.GetTableLength (Table.MemberRef)]; - } - - public IEnumerable GetMemberReferences () - { - InitializeMemberReferences (); - - var length = image.GetTableLength (Table.MemberRef); - - var type_system = module.TypeSystem; - - var context = new MethodReference (string.Empty, type_system.Void); - context.DeclaringType = new TypeReference (string.Empty, string.Empty, module, type_system.Corlib); - - var member_references = new MemberReference [length]; - - for (uint i = 1; i <= length; i++) { - this.context = context; - member_references [i - 1] = GetMemberReference (i); - } - - return member_references; - } - - void InitializeConstants () - { - if (metadata.Constants != null) - return; - - var length = MoveTo (Table.Constant); - - var constants = metadata.Constants = new Dictionary> (length); - - for (uint i = 1; i <= length; i++) { - var type = (ElementType) ReadUInt16 (); - var owner = ReadMetadataToken (CodedIndex.HasConstant); - var signature = ReadBlobIndex (); - - constants.Add (owner, new Row (type, signature)); - } - } - - public object ReadConstant (IConstantProvider owner) - { - InitializeConstants (); - - Row row; - if (!metadata.Constants.TryGetValue (owner.MetadataToken, out row)) - return Mixin.NoValue; - - metadata.Constants.Remove (owner.MetadataToken); - - switch (row.Col1) { - case ElementType.Class: - case ElementType.Object: - return null; - case ElementType.String: - return ReadConstantString (ReadBlob (row.Col2)); - default: - return ReadConstantPrimitive (row.Col1, row.Col2); - } - } - - static string ReadConstantString (byte [] blob) - { - var length = blob.Length; - if ((length & 1) == 1) - length--; - - return Encoding.Unicode.GetString (blob, 0, length); - } - - object ReadConstantPrimitive (ElementType type, uint signature) - { - var reader = ReadSignature (signature); - return reader.ReadConstantSignature (type); - } - - void InitializeCustomAttributes () - { - if (metadata.CustomAttributes != null) - return; - - metadata.CustomAttributes = InitializeRanges ( - Table.CustomAttribute, () => { - var next = ReadMetadataToken (CodedIndex.HasCustomAttribute); - ReadMetadataToken (CodedIndex.CustomAttributeType); - ReadBlobIndex (); - return next; - }); - } - - public bool HasCustomAttributes (ICustomAttributeProvider owner) - { - InitializeCustomAttributes (); - - Range range; - if (!metadata.TryGetCustomAttributeRange (owner, out range)) - return false; - - return range.Length > 0; - } - - public Collection ReadCustomAttributes (ICustomAttributeProvider owner) - { - InitializeCustomAttributes (); - - Range range; - if (!metadata.TryGetCustomAttributeRange (owner, out range) - || !MoveTo (Table.CustomAttribute, range.Start)) - return new Collection (); - - var custom_attributes = new Collection ((int) range.Length); - - for (int i = 0; i < range.Length; i++) { - ReadMetadataToken (CodedIndex.HasCustomAttribute); - - var constructor = (MethodReference) LookupToken ( - ReadMetadataToken (CodedIndex.CustomAttributeType)); - - var signature = ReadBlobIndex (); - - custom_attributes.Add (new CustomAttribute (signature, constructor)); - } - - metadata.RemoveCustomAttributeRange (owner); - - return custom_attributes; - } - - public byte [] ReadCustomAttributeBlob (uint signature) - { - return ReadBlob (signature); - } - - public void ReadCustomAttributeSignature (CustomAttribute attribute) - { - var reader = ReadSignature (attribute.signature); - - if (!reader.CanReadMore ()) - return; - - if (reader.ReadUInt16 () != 0x0001) - throw new InvalidOperationException (); - - var constructor = attribute.Constructor; - if (constructor.HasParameters) - reader.ReadCustomAttributeConstructorArguments (attribute, constructor.Parameters); - - if (!reader.CanReadMore ()) - return; - - var named = reader.ReadUInt16 (); - - if (named == 0) - return; - - reader.ReadCustomAttributeNamedArguments (named, ref attribute.fields, ref attribute.properties); - } - - void InitializeMarshalInfos () - { - if (metadata.FieldMarshals != null) - return; - - var length = MoveTo (Table.FieldMarshal); - - var marshals = metadata.FieldMarshals = new Dictionary (length); - - for (int i = 0; i < length; i++) { - var token = ReadMetadataToken (CodedIndex.HasFieldMarshal); - var signature = ReadBlobIndex (); - if (token.RID == 0) - continue; - - marshals.Add (token, signature); - } - } - - public bool HasMarshalInfo (IMarshalInfoProvider owner) - { - InitializeMarshalInfos (); - - return metadata.FieldMarshals.ContainsKey (owner.MetadataToken); - } - - public MarshalInfo ReadMarshalInfo (IMarshalInfoProvider owner) - { - InitializeMarshalInfos (); - - uint signature; - if (!metadata.FieldMarshals.TryGetValue (owner.MetadataToken, out signature)) - return null; - - var reader = ReadSignature (signature); - - metadata.FieldMarshals.Remove (owner.MetadataToken); - - return reader.ReadMarshalInfo (); - } - - void InitializeSecurityDeclarations () - { - if (metadata.SecurityDeclarations != null) - return; - - metadata.SecurityDeclarations = InitializeRanges ( - Table.DeclSecurity, () => { - ReadUInt16 (); - var next = ReadMetadataToken (CodedIndex.HasDeclSecurity); - ReadBlobIndex (); - return next; - }); - } - - public bool HasSecurityDeclarations (ISecurityDeclarationProvider owner) - { - InitializeSecurityDeclarations (); - - Range range; - if (!metadata.TryGetSecurityDeclarationRange (owner, out range)) - return false; - - return range.Length > 0; - } - - public Collection ReadSecurityDeclarations (ISecurityDeclarationProvider owner) - { - InitializeSecurityDeclarations (); - - Range range; - if (!metadata.TryGetSecurityDeclarationRange (owner, out range) - || !MoveTo (Table.DeclSecurity, range.Start)) - return new Collection (); - - var security_declarations = new Collection ((int) range.Length); - - for (int i = 0; i < range.Length; i++) { - var action = (SecurityAction) ReadUInt16 (); - ReadMetadataToken (CodedIndex.HasDeclSecurity); - var signature = ReadBlobIndex (); - - security_declarations.Add (new SecurityDeclaration (action, signature, module)); - } - - metadata.RemoveSecurityDeclarationRange (owner); - - return security_declarations; - } - - public byte [] ReadSecurityDeclarationBlob (uint signature) - { - return ReadBlob (signature); - } - - public void ReadSecurityDeclarationSignature (SecurityDeclaration declaration) - { - var signature = declaration.signature; - var reader = ReadSignature (signature); - - if (reader.buffer [reader.position] != '.') { - ReadXmlSecurityDeclaration (signature, declaration); - return; - } - - reader.position++; - var count = reader.ReadCompressedUInt32 (); - var attributes = new Collection ((int) count); - - for (int i = 0; i < count; i++) - attributes.Add (reader.ReadSecurityAttribute ()); - - declaration.security_attributes = attributes; - } - - void ReadXmlSecurityDeclaration (uint signature, SecurityDeclaration declaration) - { - var blob = ReadBlob (signature); - var attributes = new Collection (1); - - var attribute = new SecurityAttribute ( - module.TypeSystem.LookupType ("System.Security.Permissions", "PermissionSetAttribute")); - - attribute.properties = new Collection (1); - attribute.properties.Add ( - new CustomAttributeNamedArgument ( - "XML", - new CustomAttributeArgument ( - module.TypeSystem.String, - Encoding.Unicode.GetString (blob, 0, blob.Length)))); - - attributes.Add (attribute); - - declaration.security_attributes = attributes; - } - - public Collection ReadExportedTypes () - { - var length = MoveTo (Table.ExportedType); - if (length == 0) - return new Collection (); - - var exported_types = new Collection (length); - - for (int i = 1; i <= length; i++) { - var attributes = (TypeAttributes) ReadUInt32 (); - var identifier = ReadUInt32 (); - var name = ReadString (); - var @namespace = ReadString (); - var implementation = ReadMetadataToken (CodedIndex.Implementation); - - ExportedType declaring_type = null; - IMetadataScope scope = null; - - switch (implementation.TokenType) { - case TokenType.AssemblyRef: - case TokenType.File: - scope = GetExportedTypeScope (implementation); - break; - case TokenType.ExportedType: - // FIXME: if the table is not properly sorted - declaring_type = exported_types [(int) implementation.RID - 1]; - break; - } - - var exported_type = new ExportedType (@namespace, name, module, scope) { - Attributes = attributes, - Identifier = (int) identifier, - DeclaringType = declaring_type, - }; - exported_type.token = new MetadataToken (TokenType.ExportedType, i); - - exported_types.Add (exported_type); - } - - return exported_types; - } - - IMetadataScope GetExportedTypeScope (MetadataToken token) - { - var position = this.position; - IMetadataScope scope; - - switch (token.TokenType) { - case TokenType.AssemblyRef: - InitializeAssemblyReferences (); - scope = metadata.AssemblyReferences [(int) token.RID - 1]; - break; - case TokenType.File: - InitializeModuleReferences (); - scope = GetModuleReferenceFromFile (token); - break; - default: - throw new NotSupportedException (); - } - - this.position = position; - return scope; - } - - ModuleReference GetModuleReferenceFromFile (MetadataToken token) - { - if (!MoveTo (Table.File, token.RID)) - return null; - - ReadUInt32 (); - var file_name = ReadString (); - var modules = module.ModuleReferences; - - ModuleReference reference; - for (int i = 0; i < modules.Count; i++) { - reference = modules [i]; - if (reference.Name == file_name) - return reference; - } - - reference = new ModuleReference (file_name); - modules.Add (reference); - return reference; - } - - static void InitializeCollection (object o) - { - } - } - - sealed class SignatureReader : ByteBuffer { - - readonly MetadataReader reader; - readonly uint start, sig_length; - - TypeSystem TypeSystem { - get { return reader.module.TypeSystem; } - } - - public SignatureReader (uint blob, MetadataReader reader) - : base (reader.buffer) - { - this.reader = reader; - - MoveToBlob (blob); - - this.sig_length = ReadCompressedUInt32 (); - this.start = (uint) position; - } - - void MoveToBlob (uint blob) - { - position = (int) (reader.image.BlobHeap.Offset + blob); - } - - MetadataToken ReadTypeTokenSignature () - { - return CodedIndex.TypeDefOrRef.GetMetadataToken (ReadCompressedUInt32 ()); - } - - GenericParameter GetGenericParameter (GenericParameterType type, uint var) - { - var context = reader.context; - int index = (int) var; - - if (context == null) - return GetUnboundGenericParameter (type, index); - - IGenericParameterProvider provider; - - switch (type) { - case GenericParameterType.Type: - provider = context.Type; - break; - case GenericParameterType.Method: - provider = context.Method; - break; - default: - throw new NotSupportedException (); - } - - 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; - - for (int i = owner_parameters.Count; i <= index; i++) - owner_parameters.Add (new GenericParameter (owner)); - } - - public void ReadGenericInstanceSignature (IGenericParameterProvider provider, IGenericInstance instance) - { - var arity = ReadCompressedUInt32 (); - - if (!provider.IsDefinition) - CheckGenericContext (provider, (int) arity - 1); - - var instance_arguments = instance.GenericArguments; - - for (int i = 0; i < arity; i++) - instance_arguments.Add (ReadTypeSignature ()); - } - - ArrayType ReadArrayTypeSignature () - { - var array = new ArrayType (ReadTypeSignature ()); - - var rank = ReadCompressedUInt32 (); - - var sizes = new uint [ReadCompressedUInt32 ()]; - for (int i = 0; i < sizes.Length; i++) - sizes [i] = ReadCompressedUInt32 (); - - var low_bounds = new int [ReadCompressedUInt32 ()]; - for (int i = 0; i < low_bounds.Length; i++) - low_bounds [i] = ReadCompressedInt32 (); - - array.Dimensions.Clear (); - - for (int i = 0; i < rank; i++) { - int? lower = null, upper = null; - - if (i < low_bounds.Length) - lower = low_bounds [i]; - - if (i < sizes.Length) - upper = lower + (int) sizes [i] - 1; - - array.Dimensions.Add (new ArrayDimension (lower, upper)); - } - - return array; - } - - TypeReference GetTypeDefOrRef (MetadataToken token) - { - return reader.GetTypeDefOrRef (token); - } - - public TypeReference ReadTypeSignature () - { - return ReadTypeSignature ((ElementType) ReadByte ()); - } - - TypeReference ReadTypeSignature (ElementType etype) - { - switch (etype) { - case ElementType.ValueType: { - var value_type = GetTypeDefOrRef (ReadTypeTokenSignature ()); - value_type.IsValueType = true; - return value_type; - } - case ElementType.Class: - return GetTypeDefOrRef (ReadTypeTokenSignature ()); - case ElementType.Ptr: - return new PointerType (ReadTypeSignature ()); - case ElementType.FnPtr: { - var fptr = new FunctionPointerType (); - ReadMethodSignature (fptr); - return fptr; - } - case ElementType.ByRef: - return new ByReferenceType (ReadTypeSignature ()); - case ElementType.Pinned: - return new PinnedType (ReadTypeSignature ()); - case ElementType.SzArray: - return new ArrayType (ReadTypeSignature ()); - case ElementType.Array: - return ReadArrayTypeSignature (); - case ElementType.CModOpt: - return new OptionalModifierType ( - GetTypeDefOrRef (ReadTypeTokenSignature ()), ReadTypeSignature ()); - case ElementType.CModReqD: - return new RequiredModifierType ( - GetTypeDefOrRef (ReadTypeTokenSignature ()), ReadTypeSignature ()); - case ElementType.Sentinel: - return new SentinelType (ReadTypeSignature ()); - case ElementType.Var: - return GetGenericParameter (GenericParameterType.Type, ReadCompressedUInt32 ()); - case ElementType.MVar: - return GetGenericParameter (GenericParameterType.Method, ReadCompressedUInt32 ()); - case ElementType.GenericInst: { - var is_value_type = ReadByte () == (byte) ElementType.ValueType; - var element_type = GetTypeDefOrRef (ReadTypeTokenSignature ()); - var generic_instance = new GenericInstanceType (element_type); - - ReadGenericInstanceSignature (element_type, generic_instance); - - if (is_value_type) { - generic_instance.IsValueType = true; - element_type.GetElementType ().IsValueType = true; - } - - return generic_instance; - } - case ElementType.Object: return TypeSystem.Object; - case ElementType.Void: return TypeSystem.Void; - case ElementType.TypedByRef: return TypeSystem.TypedReference; - case ElementType.I: return TypeSystem.IntPtr; - case ElementType.U: return TypeSystem.UIntPtr; - default: return GetPrimitiveType (etype); - } - } - - public void ReadMethodSignature (IMethodSignature method) - { - var calling_convention = ReadByte (); - - const byte has_this = 0x20; - const byte explicit_this = 0x40; - - if ((calling_convention & has_this) != 0) { - method.HasThis = true; - calling_convention = (byte) (calling_convention & ~has_this); - } - - if ((calling_convention & explicit_this) != 0) { - method.ExplicitThis = true; - calling_convention = (byte) (calling_convention & ~explicit_this); - } - - method.CallingConvention = (MethodCallingConvention) calling_convention; - - var generic_context = method as MethodReference; - if (generic_context != null && !generic_context.DeclaringType.IsArray) - reader.context = generic_context; - - if ((calling_convention & 0x10) != 0) { - var arity = ReadCompressedUInt32 (); - - if (generic_context != null && !generic_context.IsDefinition) - CheckGenericContext (generic_context, (int) arity -1 ); - } - - var param_count = ReadCompressedUInt32 (); - - method.MethodReturnType.ReturnType = ReadTypeSignature (); - - if (param_count == 0) - return; - - Collection parameters; - - var method_ref = method as MethodReference; - if (method_ref != null) - parameters = method_ref.parameters = new ParameterDefinitionCollection (method, (int) param_count); - else - parameters = method.Parameters; - - for (int i = 0; i < param_count; i++) - parameters.Add (new ParameterDefinition (ReadTypeSignature ())); - } - - public object ReadConstantSignature (ElementType type) - { - return ReadPrimitiveValue (type); - } - - public void ReadCustomAttributeConstructorArguments (CustomAttribute attribute, Collection parameters) - { - var count = parameters.Count; - if (count == 0) - return; - - attribute.arguments = new Collection (count); - - for (int i = 0; i < count; i++) - attribute.arguments.Add ( - ReadCustomAttributeFixedArgument (parameters [i].ParameterType)); - } - - CustomAttributeArgument ReadCustomAttributeFixedArgument (TypeReference type) - { - if (type.IsArray) - return ReadCustomAttributeFixedArrayArgument ((ArrayType) type); - - return ReadCustomAttributeElement (type); - } - - public void ReadCustomAttributeNamedArguments (ushort count, ref Collection fields, ref Collection properties) - { - for (int i = 0; i < count; i++) - ReadCustomAttributeNamedArgument (ref fields, ref properties); - } - - void ReadCustomAttributeNamedArgument (ref Collection fields, ref Collection properties) - { - var kind = ReadByte (); - var type = ReadCustomAttributeFieldOrPropType (); - var name = ReadUTF8String (); - - Collection container; - switch (kind) { - case 0x53: - container = GetCustomAttributeNamedArgumentCollection (ref fields); - break; - case 0x54: - container = GetCustomAttributeNamedArgumentCollection (ref properties); - break; - default: - throw new NotSupportedException (); - } - - container.Add (new CustomAttributeNamedArgument (name, ReadCustomAttributeFixedArgument (type))); - } - - static Collection GetCustomAttributeNamedArgumentCollection (ref Collection collection) - { - if (collection != null) - return collection; - - return collection = new Collection (); - } - - CustomAttributeArgument ReadCustomAttributeFixedArrayArgument (ArrayType type) - { - var length = ReadUInt32 (); - - if (length == 0xffffffff) - return new CustomAttributeArgument (type, null); - - if (length == 0) - return new CustomAttributeArgument (type, Empty.Array); - - var arguments = new CustomAttributeArgument [length]; - var element_type = type.ElementType; - - for (int i = 0; i < length; i++) - arguments [i] = ReadCustomAttributeElement (element_type); - - return new CustomAttributeArgument (type, arguments); - } - - CustomAttributeArgument ReadCustomAttributeElement (TypeReference type) - { - if (type.IsArray) - return ReadCustomAttributeFixedArrayArgument ((ArrayType) type); - - return new CustomAttributeArgument ( - type, - type.etype == ElementType.Object - ? ReadCustomAttributeElement (ReadCustomAttributeFieldOrPropType ()) - : ReadCustomAttributeElementValue (type)); - } - - object ReadCustomAttributeElementValue (TypeReference type) - { - var etype = type.etype; - - switch (etype) { - case ElementType.String: - return ReadUTF8String (); - case ElementType.None: - if (type.IsTypeOf ("System", "Type")) - return ReadTypeReference (); - - return ReadCustomAttributeEnum (type); - default: - return ReadPrimitiveValue (etype); - } - } - - object ReadPrimitiveValue (ElementType type) - { - switch (type) { - case ElementType.Boolean: - return ReadByte () == 1; - case ElementType.I1: - return (sbyte) ReadByte (); - case ElementType.U1: - return ReadByte (); - case ElementType.Char: - return (char) ReadUInt16 (); - case ElementType.I2: - return ReadInt16 (); - case ElementType.U2: - return ReadUInt16 (); - case ElementType.I4: - return ReadInt32 (); - case ElementType.U4: - return ReadUInt32 (); - case ElementType.I8: - return ReadInt64 (); - case ElementType.U8: - return ReadUInt64 (); - case ElementType.R4: - return ReadSingle (); - case ElementType.R8: - return ReadDouble (); - default: - throw new NotImplementedException (type.ToString ()); - } - } - - TypeReference GetPrimitiveType (ElementType etype) - { - switch (etype) { - case ElementType.Boolean: - return TypeSystem.Boolean; - case ElementType.Char: - return TypeSystem.Char; - case ElementType.I1: - return TypeSystem.SByte; - case ElementType.U1: - return TypeSystem.Byte; - case ElementType.I2: - return TypeSystem.Int16; - case ElementType.U2: - return TypeSystem.UInt16; - case ElementType.I4: - return TypeSystem.Int32; - case ElementType.U4: - return TypeSystem.UInt32; - case ElementType.I8: - return TypeSystem.Int64; - case ElementType.U8: - return TypeSystem.UInt64; - case ElementType.R4: - return TypeSystem.Single; - case ElementType.R8: - return TypeSystem.Double; - case ElementType.String: - return TypeSystem.String; - default: - throw new NotImplementedException (etype.ToString ()); - } - } - - TypeReference ReadCustomAttributeFieldOrPropType () - { - var etype = (ElementType) ReadByte (); - - switch (etype) { - case ElementType.Boxed: - return TypeSystem.Object; - case ElementType.SzArray: - return new ArrayType (ReadCustomAttributeFieldOrPropType ()); - case ElementType.Enum: - return ReadTypeReference (); - case ElementType.Type: - return TypeSystem.LookupType ("System", "Type"); - default: - return GetPrimitiveType (etype); - } - } - - public TypeReference ReadTypeReference () - { - return TypeParser.ParseType (reader.module, ReadUTF8String ()); - } - - object ReadCustomAttributeEnum (TypeReference enum_type) - { - var type = enum_type.CheckedResolve (); - if (!type.IsEnum) - throw new ArgumentException (); - - return ReadCustomAttributeElementValue (type.GetEnumUnderlyingType ()); - } - - public SecurityAttribute ReadSecurityAttribute () - { - var attribute = new SecurityAttribute (ReadTypeReference ()); - - ReadCompressedUInt32 (); - - ReadCustomAttributeNamedArguments ( - (ushort) ReadCompressedUInt32 (), - ref attribute.fields, - ref attribute.properties); - - return attribute; - } - - public MarshalInfo ReadMarshalInfo () - { - var native = ReadNativeType (); - switch (native) { - case NativeType.Array: { - var array = new ArrayMarshalInfo (); - if (CanReadMore ()) - array.element_type = ReadNativeType (); - if (CanReadMore ()) - array.size_parameter_index = (int) ReadCompressedUInt32 (); - if (CanReadMore ()) - array.size = (int) ReadCompressedUInt32 (); - if (CanReadMore ()) - array.size_parameter_multiplier = (int) ReadCompressedUInt32 (); - return array; - } - case NativeType.SafeArray: { - var array = new SafeArrayMarshalInfo (); - if (CanReadMore ()) - array.element_type = ReadVariantType (); - return array; - } - case NativeType.FixedArray: { - var array = new FixedArrayMarshalInfo (); - if (CanReadMore ()) - array.size = (int) ReadCompressedUInt32 (); - if (CanReadMore ()) - array.element_type = ReadNativeType (); - return array; - } - case NativeType.FixedSysString: { - var sys_string = new FixedSysStringMarshalInfo (); - if (CanReadMore ()) - sys_string.size = (int) ReadCompressedUInt32 (); - return sys_string; - } - case NativeType.CustomMarshaler: { - var marshaler = new CustomMarshalInfo (); - var guid_value = ReadUTF8String (); - marshaler.guid = !string.IsNullOrEmpty (guid_value) ? new Guid (guid_value) : Guid.Empty; - marshaler.unmanaged_type = ReadUTF8String (); - marshaler.managed_type = ReadTypeReference (); - marshaler.cookie = ReadUTF8String (); - return marshaler; - } - default: - return new MarshalInfo (native); - } - } - - NativeType ReadNativeType () - { - return (NativeType) ReadByte (); - } - - VariantType ReadVariantType () - { - return (VariantType) ReadByte (); - } - - string ReadUTF8String () - { - if (buffer [position] == 0xff) { - position++; - return null; - } - - var length = (int) ReadCompressedUInt32 (); - if (length == 0) - return string.Empty; - - var @string = Encoding.UTF8.GetString (buffer, position, - buffer [position + length - 1] == 0 ? length - 1 : length); - - position += length; - return @string; - } - - public bool CanReadMore () - { - return position - start < sig_length; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyWriter.cs b/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyWriter.cs deleted file mode 100644 index bffa439c60c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/AssemblyWriter.cs +++ /dev/null @@ -1,2571 +0,0 @@ -// -// AssemblyWriter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -using Mono.Collections.Generic; -using Mono.Cecil.Cil; -using Mono.Cecil.Metadata; -using Mono.Cecil.PE; - -using RVA = System.UInt32; -using RID = System.UInt32; -using CodedRID = System.UInt32; -using StringIndex = System.UInt32; -using BlobIndex = System.UInt32; - -namespace Mono.Cecil { - -#if !READ_ONLY - - using TypeRefRow = Row; - using TypeDefRow = Row; - using FieldRow = Row; - using MethodRow = Row; - using ParamRow = Row; - using InterfaceImplRow = Row; - using MemberRefRow = Row; - using ConstantRow = Row; - using CustomAttributeRow = Row; - using FieldMarshalRow = Row; - using DeclSecurityRow = Row; - using ClassLayoutRow = Row; - using FieldLayoutRow = Row; - using EventMapRow = Row; - using EventRow = Row; - using PropertyMapRow = Row; - using PropertyRow = Row; - using MethodSemanticsRow = Row; - using MethodImplRow = Row; - using ImplMapRow = Row; - using FieldRVARow = Row; - using AssemblyRow = Row; - using AssemblyRefRow = Row; - using FileRow = Row; - using ExportedTypeRow = Row; - using ManifestResourceRow = Row; - using NestedClassRow = Row; - using GenericParamRow = Row; - using MethodSpecRow = Row; - using GenericParamConstraintRow = Row; - - static class ModuleWriter { - - public static void WriteModuleTo (ModuleDefinition module, Stream stream, WriterParameters parameters) - { - if ((module.Attributes & ModuleAttributes.ILOnly) == 0) - throw new ArgumentException (); - - if (module.HasImage && module.ReadingMode == ReadingMode.Deferred) - ImmediateModuleReader.ReadModule (module); - - module.MetadataSystem.Clear (); - - var name = module.assembly != null ? module.assembly.Name : null; - var fq_name = stream.GetFullyQualifiedName (); - var symbol_writer_provider = parameters.SymbolWriterProvider; - if (symbol_writer_provider == null && parameters.WriteSymbols) - symbol_writer_provider = SymbolProvider.GetPlatformWriterProvider (); - var symbol_writer = GetSymbolWriter (module, fq_name, symbol_writer_provider); - -#if !SILVERLIGHT && !CF - if (parameters.StrongNameKeyPair != null && name != null) { - name.PublicKey = parameters.StrongNameKeyPair.PublicKey; - module.Attributes |= ModuleAttributes.StrongNameSigned; - } -#endif - var metadata = new MetadataBuilder (module, fq_name, - symbol_writer_provider, symbol_writer); - - BuildMetadata (module, metadata); - - if (module.symbol_reader != null) - module.symbol_reader.Dispose (); - - var writer = ImageWriter.CreateWriter (module, metadata, stream); - - writer.WriteImage (); - -#if !SILVERLIGHT && !CF - if (parameters.StrongNameKeyPair != null) - CryptoService.StrongName (stream, writer, parameters.StrongNameKeyPair); -#endif - if (symbol_writer != null) - symbol_writer.Dispose (); - } - - static void BuildMetadata (ModuleDefinition module, MetadataBuilder metadata) - { - if (!module.HasImage) { - metadata.BuildMetadata (); - return; - } - - module.Read (metadata, (builder, _) => { - builder.BuildMetadata (); - return builder; - }); - } - - static ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fq_name, ISymbolWriterProvider symbol_writer_provider) - { - if (symbol_writer_provider == null) - return null; - - return symbol_writer_provider.GetSymbolWriter (module, fq_name); - } - } - - abstract class MetadataTable { - - public abstract int Length { get; } - - public bool IsLarge { - get { return Length > 65535; } - } - - public abstract void Write (TableHeapBuffer buffer); - public abstract void Sort (); - } - - abstract class OneRowTable : MetadataTable where TRow : struct { - - internal TRow row; - - public sealed override int Length { - get { return 1; } - } - - public sealed override void Sort () - { - } - } - - abstract class MetadataTable : MetadataTable where TRow : struct { - - internal TRow [] rows = new TRow [2]; - internal int length; - - public sealed override int Length { - get { return length; } - } - - public int AddRow (TRow row) - { - if (rows.Length == length) - Grow (); - - rows [length++] = row; - return length; - } - - void Grow () - { - var rows = new TRow [this.rows.Length * 2]; - Array.Copy (this.rows, rows, this.rows.Length); - this.rows = rows; - } - - public override void Sort () - { - } - } - - abstract class SortedTable : MetadataTable, IComparer where TRow : struct { - - public sealed override void Sort () - { - Array.Sort (rows, 0, length, this); - } - - protected int Compare (uint x, uint y) - { - return x == y ? 0 : x > y ? 1 : -1; - } - - public abstract int Compare (TRow x, TRow y); - } - - sealed class ModuleTable : OneRowTable { - - public override void Write (TableHeapBuffer buffer) - { - buffer.WriteUInt16 (0); // Generation - buffer.WriteString (row); // Name - buffer.WriteUInt16 (1); // Mvid - buffer.WriteUInt16 (0); // EncId - buffer.WriteUInt16 (0); // EncBaseId - } - } - - sealed class TypeRefTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteCodedRID ( - rows [i].Col1, CodedIndex.ResolutionScope); // Scope - buffer.WriteString (rows [i].Col2); // Name - buffer.WriteString (rows [i].Col3); // Namespace - } - } - } - - sealed class TypeDefTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 ((uint) rows [i].Col1); // Attributes - buffer.WriteString (rows [i].Col2); // Name - buffer.WriteString (rows [i].Col3); // Namespace - buffer.WriteCodedRID ( - rows [i].Col4, CodedIndex.TypeDefOrRef); // Extends - buffer.WriteRID (rows [i].Col5, Table.Field); // FieldList - buffer.WriteRID (rows [i].Col6, Table.Method); // MethodList - } - } - } - - sealed class FieldTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); // Attributes - buffer.WriteString (rows [i].Col2); // Name - buffer.WriteBlob (rows [i].Col3); // Signature - } - } - } - - sealed class MethodTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 (rows [i].Col1); // RVA - buffer.WriteUInt16 ((ushort) rows [i].Col2); // ImplFlags - buffer.WriteUInt16 ((ushort) rows [i].Col3); // Flags - buffer.WriteString (rows [i].Col4); // Name - buffer.WriteBlob (rows [i].Col5); // Signature - buffer.WriteRID (rows [i].Col6, Table.Param); // ParamList - } - } - } - - sealed class ParamTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); // Attributes - buffer.WriteUInt16 (rows [i].Col2); // Sequence - buffer.WriteString (rows [i].Col3); // Name - } - } - } - - sealed class InterfaceImplTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteRID (rows [i].Col1, Table.TypeDef); // Class - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.TypeDefOrRef); // Interface - } - } - - /*public override int Compare (InterfaceImplRow x, InterfaceImplRow y) - { - return (int) (x.Col1 == y.Col1 ? y.Col2 - x.Col2 : x.Col1 - y.Col1); - }*/ - } - - sealed class MemberRefTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteCodedRID (rows [i].Col1, CodedIndex.MemberRefParent); - buffer.WriteString (rows [i].Col2); - buffer.WriteBlob (rows [i].Col3); - } - } - } - - sealed class ConstantTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.HasConstant); - buffer.WriteBlob (rows [i].Col3); - } - } - - public override int Compare (ConstantRow x, ConstantRow y) - { - return Compare (x.Col2, y.Col2); - } - } - - sealed class CustomAttributeTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteCodedRID (rows [i].Col1, CodedIndex.HasCustomAttribute); // Parent - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.CustomAttributeType); // Type - buffer.WriteBlob (rows [i].Col3); - } - } - - public override int Compare (CustomAttributeRow x, CustomAttributeRow y) - { - return Compare (x.Col1, y.Col1); - } - } - - sealed class FieldMarshalTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteCodedRID (rows [i].Col1, CodedIndex.HasFieldMarshal); - buffer.WriteBlob (rows [i].Col2); - } - } - - public override int Compare (FieldMarshalRow x, FieldMarshalRow y) - { - return Compare (x.Col1, y.Col1); - } - } - - sealed class DeclSecurityTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.HasDeclSecurity); - buffer.WriteBlob (rows [i].Col3); - } - } - - public override int Compare (DeclSecurityRow x, DeclSecurityRow y) - { - return Compare (x.Col2, y.Col2); - } - } - - sealed class ClassLayoutTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 (rows [i].Col1); // PackingSize - buffer.WriteUInt32 (rows [i].Col2); // ClassSize - buffer.WriteRID (rows [i].Col3, Table.TypeDef); // Parent - } - } - - public override int Compare (ClassLayoutRow x, ClassLayoutRow y) - { - return Compare (x.Col3, y.Col3); - } - } - - sealed class FieldLayoutTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 (rows [i].Col1); // Offset - buffer.WriteRID (rows [i].Col2, Table.Field); // Parent - } - } - - public override int Compare (FieldLayoutRow x, FieldLayoutRow y) - { - return Compare (x.Col2, y.Col2); - } - } - - sealed class StandAloneSigTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) - buffer.WriteBlob (rows [i]); - } - } - - sealed class EventMapTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteRID (rows [i].Col1, Table.TypeDef); // Parent - buffer.WriteRID (rows [i].Col2, Table.Event); // EventList - } - } - } - - sealed class EventTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); // Flags - buffer.WriteString (rows [i].Col2); // Name - buffer.WriteCodedRID (rows [i].Col3, CodedIndex.TypeDefOrRef); // EventType - } - } - } - - sealed class PropertyMapTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteRID (rows [i].Col1, Table.TypeDef); // Parent - buffer.WriteRID (rows [i].Col2, Table.Property); // PropertyList - } - } - } - - sealed class PropertyTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); // Flags - buffer.WriteString (rows [i].Col2); // Name - buffer.WriteBlob (rows [i].Col3); // Type - } - } - } - - sealed class MethodSemanticsTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); // Flags - buffer.WriteRID (rows [i].Col2, Table.Method); // Method - buffer.WriteCodedRID (rows [i].Col3, CodedIndex.HasSemantics); // Association - } - } - - public override int Compare (MethodSemanticsRow x, MethodSemanticsRow y) - { - return Compare (x.Col3, y.Col3); - } - } - - sealed class MethodImplTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteRID (rows [i].Col1, Table.TypeDef); // Class - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.MethodDefOrRef); // MethodBody - buffer.WriteCodedRID (rows [i].Col3, CodedIndex.MethodDefOrRef); // MethodDeclaration - } - } - } - - sealed class ModuleRefTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) - buffer.WriteString (rows [i]); // Name - } - } - - sealed class TypeSpecTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) - buffer.WriteBlob (rows [i]); // Signature - } - } - - sealed class ImplMapTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 ((ushort) rows [i].Col1); // Flags - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.MemberForwarded); // MemberForwarded - buffer.WriteString (rows [i].Col3); // ImportName - buffer.WriteRID (rows [i].Col4, Table.ModuleRef); // ImportScope - } - } - - public override int Compare (ImplMapRow x, ImplMapRow y) - { - return Compare (x.Col2, y.Col2); - } - } - - sealed class FieldRVATable : SortedTable { - - internal int position; - - public override void Write (TableHeapBuffer buffer) - { - position = buffer.position; - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 (rows [i].Col1); // RVA - buffer.WriteRID (rows [i].Col2, Table.Field); // Field - } - } - - public override int Compare (FieldRVARow x, FieldRVARow y) - { - return Compare (x.Col2, y.Col2); - } - } - - sealed class AssemblyTable : OneRowTable { - - public override void Write (TableHeapBuffer buffer) - { - buffer.WriteUInt32 ((uint) row.Col1); // AssemblyHashAlgorithm - buffer.WriteUInt16 (row.Col2); // MajorVersion - buffer.WriteUInt16 (row.Col3); // MinorVersion - buffer.WriteUInt16 (row.Col4); // Build - buffer.WriteUInt16 (row.Col5); // Revision - buffer.WriteUInt32 ((uint) row.Col6); // Flags - buffer.WriteBlob (row.Col7); // PublicKey - buffer.WriteString (row.Col8); // Name - buffer.WriteString (row.Col9); // Culture - } - } - - sealed class AssemblyRefTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 (rows [i].Col1); // MajorVersion - buffer.WriteUInt16 (rows [i].Col2); // MinorVersion - buffer.WriteUInt16 (rows [i].Col3); // Build - buffer.WriteUInt16 (rows [i].Col4); // Revision - buffer.WriteUInt32 ((uint) rows [i].Col5); // Flags - buffer.WriteBlob (rows [i].Col6); // PublicKeyOrToken - buffer.WriteString (rows [i].Col7); // Name - buffer.WriteString (rows [i].Col8); // Culture - buffer.WriteBlob (rows [i].Col9); // Hash - } - } - } - - sealed class FileTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 ((uint) rows [i].Col1); - buffer.WriteString (rows [i].Col2); - buffer.WriteBlob (rows [i].Col3); - } - } - } - - sealed class ExportedTypeTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 ((uint) rows [i].Col1); - buffer.WriteUInt32 (rows [i].Col2); - buffer.WriteString (rows [i].Col3); - buffer.WriteString (rows [i].Col4); - buffer.WriteCodedRID (rows [i].Col5, CodedIndex.Implementation); - } - } - } - - sealed class ManifestResourceTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt32 (rows [i].Col1); - buffer.WriteUInt32 ((uint) rows [i].Col2); - buffer.WriteString (rows [i].Col3); - buffer.WriteCodedRID (rows [i].Col4, CodedIndex.Implementation); - } - } - } - - sealed class NestedClassTable : SortedTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteRID (rows [i].Col1, Table.TypeDef); // NestedClass - buffer.WriteRID (rows [i].Col2, Table.TypeDef); // EnclosingClass - } - } - - public override int Compare (NestedClassRow x, NestedClassRow y) - { - return Compare (x.Col1, y.Col1); - } - } - - sealed class GenericParamTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteUInt16 (rows [i].Col1); // Number - buffer.WriteUInt16 ((ushort) rows [i].Col2); // Flags - buffer.WriteCodedRID (rows [i].Col3, CodedIndex.TypeOrMethodDef); // Owner - buffer.WriteString (rows [i].Col4); // Name - } - } - } - - sealed class MethodSpecTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteCodedRID (rows [i].Col1, CodedIndex.MethodDefOrRef); // Method - buffer.WriteBlob (rows [i].Col2); // Instantiation - } - } - } - - sealed class GenericParamConstraintTable : MetadataTable { - - public override void Write (TableHeapBuffer buffer) - { - for (int i = 0; i < length; i++) { - buffer.WriteRID (rows [i].Col1, Table.GenericParam); // Owner - buffer.WriteCodedRID (rows [i].Col2, CodedIndex.TypeDefOrRef); // Constraint - } - } - } - - sealed class MetadataBuilder { - - readonly internal ModuleDefinition module; - readonly internal ISymbolWriterProvider symbol_writer_provider; - readonly internal ISymbolWriter symbol_writer; - readonly internal TextMap text_map; - readonly internal string fq_name; - - readonly Dictionary type_ref_map; - readonly Dictionary type_spec_map; - readonly Dictionary member_ref_map; - readonly Dictionary method_spec_map; - readonly Collection generic_parameters; - readonly Dictionary method_def_map; - - readonly internal CodeWriter code; - readonly internal DataBuffer data; - readonly internal ResourceBuffer resources; - readonly internal StringHeapBuffer string_heap; - readonly internal UserStringHeapBuffer user_string_heap; - readonly internal BlobHeapBuffer blob_heap; - readonly internal TableHeapBuffer table_heap; - - internal MetadataToken entry_point; - - RID type_rid = 1; - RID field_rid = 1; - RID method_rid = 1; - RID param_rid = 1; - RID property_rid = 1; - RID event_rid = 1; - - readonly TypeRefTable type_ref_table; - readonly TypeDefTable type_def_table; - readonly FieldTable field_table; - readonly MethodTable method_table; - readonly ParamTable param_table; - readonly InterfaceImplTable iface_impl_table; - readonly MemberRefTable member_ref_table; - readonly ConstantTable constant_table; - readonly CustomAttributeTable custom_attribute_table; - readonly DeclSecurityTable declsec_table; - readonly StandAloneSigTable standalone_sig_table; - readonly EventMapTable event_map_table; - readonly EventTable event_table; - readonly PropertyMapTable property_map_table; - readonly PropertyTable property_table; - readonly TypeSpecTable typespec_table; - readonly MethodSpecTable method_spec_table; - - readonly internal bool write_symbols; - - public MetadataBuilder (ModuleDefinition module, string fq_name, ISymbolWriterProvider symbol_writer_provider, ISymbolWriter symbol_writer) - { - this.module = module; - this.text_map = CreateTextMap (); - this.fq_name = fq_name; - this.symbol_writer_provider = symbol_writer_provider; - this.symbol_writer = symbol_writer; - this.write_symbols = symbol_writer != null; - this.code = new CodeWriter (this); - this.data = new DataBuffer (); - this.resources = new ResourceBuffer (); - this.string_heap = new StringHeapBuffer (); - this.user_string_heap = new UserStringHeapBuffer (); - this.blob_heap = new BlobHeapBuffer (); - this.table_heap = new TableHeapBuffer (module, this); - - this.type_ref_table = GetTable (Table.TypeRef); - this.type_def_table = GetTable (Table.TypeDef); - this.field_table = GetTable (Table.Field); - this.method_table = GetTable (Table.Method); - this.param_table = GetTable (Table.Param); - this.iface_impl_table = GetTable (Table.InterfaceImpl); - this.member_ref_table = GetTable (Table.MemberRef); - this.constant_table = GetTable (Table.Constant); - this.custom_attribute_table = GetTable (Table.CustomAttribute); - this.declsec_table = GetTable (Table.DeclSecurity); - this.standalone_sig_table = GetTable (Table.StandAloneSig); - this.event_map_table = GetTable (Table.EventMap); - this.event_table = GetTable (Table.Event); - this.property_map_table = GetTable (Table.PropertyMap); - this.property_table = GetTable (Table.Property); - this.typespec_table = GetTable (Table.TypeSpec); - this.method_spec_table = GetTable (Table.MethodSpec); - - var row_equality_comparer = new RowEqualityComparer (); - type_ref_map = new Dictionary (row_equality_comparer); - type_spec_map = new Dictionary (); - member_ref_map = new Dictionary (row_equality_comparer); - method_spec_map = new Dictionary (row_equality_comparer); - generic_parameters = new Collection (); - if (write_symbols) - method_def_map = new Dictionary (); - } - - TextMap CreateTextMap () - { - var map = new TextMap (); - map.AddMap (TextSegment.ImportAddressTable, module.Architecture == TargetArchitecture.I386 ? 8 : 0); - map.AddMap (TextSegment.CLIHeader, 0x48, 8); - return map; - } - - TTable GetTable (Table table) where TTable : MetadataTable, new () - { - return table_heap.GetTable (table); - } - - uint GetStringIndex (string @string) - { - if (string.IsNullOrEmpty (@string)) - return 0; - - return string_heap.GetStringIndex (@string); - } - - uint GetBlobIndex (ByteBuffer blob) - { - if (blob.length == 0) - return 0; - - return blob_heap.GetBlobIndex (blob); - } - - uint GetBlobIndex (byte [] blob) - { - if (blob.IsNullOrEmpty ()) - return 0; - - return GetBlobIndex (new ByteBuffer (blob)); - } - - public void BuildMetadata () - { - BuildModule (); - - table_heap.WriteTableHeap (); - } - - void BuildModule () - { - var table = GetTable (Table.Module); - table.row = GetStringIndex (module.Name); - - var assembly = module.Assembly; - - if (assembly != null) - BuildAssembly (); - - if (module.HasAssemblyReferences) - AddAssemblyReferences (); - - if (module.HasModuleReferences) - AddModuleReferences (); - - if (module.HasResources) - AddResources (); - - if (module.HasExportedTypes) - AddExportedTypes (); - - BuildTypes (); - - if (assembly != null) { - if (assembly.HasCustomAttributes) - AddCustomAttributes (assembly); - - if (assembly.HasSecurityDeclarations) - AddSecurityDeclarations (assembly); - } - - if (module.HasCustomAttributes) - AddCustomAttributes (module); - - if (module.EntryPoint != null) - entry_point = LookupToken (module.EntryPoint); - } - - void BuildAssembly () - { - var assembly = module.Assembly; - var name = assembly.Name; - - var table = GetTable (Table.Assembly); - - table.row = new AssemblyRow ( - name.HashAlgorithm, - (ushort) name.Version.Major, - (ushort) name.Version.Minor, - (ushort) name.Version.Build, - (ushort) name.Version.Revision, - name.Attributes, - GetBlobIndex (name.PublicKey), - GetStringIndex (name.Name), - GetStringIndex (name.Culture)); - - if (assembly.Modules.Count > 1) - BuildModules (); - } - - void BuildModules () - { - var modules = this.module.Assembly.Modules; - var table = GetTable (Table.File); - - for (int i = 0; i < modules.Count; i++) { - var module = modules [i]; - if (module.IsMain) - continue; - - var parameters = new WriterParameters { - SymbolWriterProvider = symbol_writer_provider, - }; - - var file_name = GetModuleFileName (module.Name); - module.Write (file_name, parameters); - - var hash = CryptoService.ComputeHash (file_name); - - table.AddRow (new FileRow ( - FileAttributes.ContainsMetaData, - GetStringIndex (module.Name), - GetBlobIndex (hash))); - } - } - - string GetModuleFileName (string name) - { - if (string.IsNullOrEmpty (name)) - throw new NotSupportedException (); - - var path = Path.GetDirectoryName (fq_name); - return Path.Combine (path, name); - } - - void AddAssemblyReferences () - { - var references = module.AssemblyReferences; - var table = GetTable (Table.AssemblyRef); - - for (int i = 0; i < references.Count; i++) { - var reference = references [i]; - - var key_or_token = reference.PublicKey.IsNullOrEmpty () - ? reference.PublicKeyToken - : reference.PublicKey; - - var version = reference.Version; - - var rid = table.AddRow (new AssemblyRefRow ( - (ushort) version.Major, - (ushort) version.Minor, - (ushort) version.Build, - (ushort) version.Revision, - reference.Attributes, - GetBlobIndex (key_or_token), - GetStringIndex (reference.Name), - GetStringIndex (reference.Culture), - GetBlobIndex (reference.Hash))); - - reference.token = new MetadataToken (TokenType.AssemblyRef, rid); - } - } - - void AddModuleReferences () - { - var references = module.ModuleReferences; - var table = GetTable (Table.ModuleRef); - - for (int i = 0; i < references.Count; i++) { - var reference = references [i]; - - reference.token = new MetadataToken ( - TokenType.ModuleRef, - table.AddRow (GetStringIndex (reference.Name))); - } - } - - void AddResources () - { - var resources = module.Resources; - var table = GetTable (Table.ManifestResource); - - for (int i = 0; i < resources.Count; i++) { - var resource = resources [i]; - - var row = new ManifestResourceRow ( - 0, - resource.Attributes, - GetStringIndex (resource.Name), - 0); - - switch (resource.ResourceType) { - case ResourceType.Embedded: - row.Col1 = AddEmbeddedResource ((EmbeddedResource) resource); - break; - case ResourceType.Linked: - row.Col4 = CodedIndex.Implementation.CompressMetadataToken ( - new MetadataToken ( - TokenType.File, - AddLinkedResource ((LinkedResource) resource))); - break; - case ResourceType.AssemblyLinked: - row.Col4 = CodedIndex.Implementation.CompressMetadataToken ( - ((AssemblyLinkedResource) resource).Assembly.MetadataToken); - break; - default: - throw new NotSupportedException (); - } - - table.AddRow (row); - } - } - - uint AddLinkedResource (LinkedResource resource) - { - var table = GetTable (Table.File); - - var hash = resource.Hash.IsNullOrEmpty () - ? CryptoService.ComputeHash (resource.File) - : resource.Hash; - - return (uint) table.AddRow (new FileRow ( - FileAttributes.ContainsNoMetaData, - GetStringIndex (resource.File), - GetBlobIndex (hash))); - } - - uint AddEmbeddedResource (EmbeddedResource resource) - { - return resources.AddResource (resource.GetResourceData ()); - } - - void AddExportedTypes () - { - var exported_types = module.ExportedTypes; - var table = GetTable (Table.ExportedType); - - for (int i = 0; i < exported_types.Count; i++) { - var exported_type = exported_types [i]; - - var rid = table.AddRow (new ExportedTypeRow ( - exported_type.Attributes, - (uint) exported_type.Identifier, - GetStringIndex (exported_type.Name), - GetStringIndex (exported_type.Namespace), - MakeCodedRID (GetExportedTypeScope (exported_type), CodedIndex.Implementation))); - - exported_type.token = new MetadataToken (TokenType.ExportedType, rid); - } - } - - MetadataToken GetExportedTypeScope (ExportedType exported_type) - { - if (exported_type.DeclaringType != null) - return exported_type.DeclaringType.MetadataToken; - - var scope = exported_type.Scope; - switch (scope.MetadataToken.TokenType) { - case TokenType.AssemblyRef: - return scope.MetadataToken; - case TokenType.ModuleRef: - var file_table = GetTable (Table.File); - for (int i = 0; i < file_table.length; i++) - if (file_table.rows [i].Col2 == GetStringIndex (scope.Name)) - return new MetadataToken (TokenType.File, i + 1); - - break; - } - - throw new NotSupportedException (); - } - - void BuildTypes () - { - if (!module.HasTypes) - return; - - AttachTokens (); - AddTypeDefs (); - AddGenericParameters (); - } - - void AttachTokens () - { - var types = module.Types; - - for (int i = 0; i < types.Count; i++) - AttachTypeDefToken (types [i]); - } - - void AttachTypeDefToken (TypeDefinition type) - { - type.token = new MetadataToken (TokenType.TypeDef, type_rid++); - type.fields_range.Start = field_rid; - type.methods_range.Start = method_rid; - - if (type.HasFields) - AttachFieldsDefToken (type); - - if (type.HasMethods) - AttachMethodsDefToken (type); - - if (type.HasNestedTypes) - AttachNestedTypesDefToken (type); - } - - void AttachNestedTypesDefToken (TypeDefinition type) - { - var nested_types = type.NestedTypes; - for (int i = 0; i < nested_types.Count; i++) - AttachTypeDefToken (nested_types [i]); - } - - void AttachFieldsDefToken (TypeDefinition type) - { - var fields = type.Fields; - type.fields_range.Length = (uint) fields.Count; - for (int i = 0; i < fields.Count; i++) - fields [i].token = new MetadataToken (TokenType.Field, field_rid++); - } - - void AttachMethodsDefToken (TypeDefinition type) - { - var methods = type.Methods; - type.methods_range.Length = (uint) methods.Count; - for (int i = 0; i < methods.Count; i++) { - var method = methods [i]; - var new_token = new MetadataToken (TokenType.Method, method_rid++); - - if (write_symbols && method.token != MetadataToken.Zero) - method_def_map.Add (new_token, method.token); - - method.token = new_token; - } - } - - public bool TryGetOriginalMethodToken (MetadataToken new_token, out MetadataToken original) - { - return method_def_map.TryGetValue (new_token, out original); - } - - MetadataToken GetTypeToken (TypeReference type) - { - if (type == null) - return MetadataToken.Zero; - - if (type.IsDefinition) - return type.token; - - if (type.IsTypeSpecification ()) - return GetTypeSpecToken (type); - - return GetTypeRefToken (type); - } - - MetadataToken GetTypeSpecToken (TypeReference type) - { - var row = GetBlobIndex (GetTypeSpecSignature (type)); - - MetadataToken token; - if (type_spec_map.TryGetValue (row, out token)) - return token; - - return AddTypeSpecification (type, row); - } - - MetadataToken AddTypeSpecification (TypeReference type, uint row) - { - type.token = new MetadataToken (TokenType.TypeSpec, typespec_table.AddRow (row)); - - var token = type.token; - type_spec_map.Add (row, token); - return token; - } - - MetadataToken GetTypeRefToken (TypeReference type) - { - var row = CreateTypeRefRow (type); - - MetadataToken token; - if (type_ref_map.TryGetValue (row, out token)) - return token; - - return AddTypeReference (type, row); - } - - TypeRefRow CreateTypeRefRow (TypeReference type) - { - var scope_token = type.IsNested - ? GetTypeRefToken (type.DeclaringType) - : type.Scope.MetadataToken; - - return new TypeRefRow ( - MakeCodedRID (scope_token, CodedIndex.ResolutionScope), - GetStringIndex (type.Name), - GetStringIndex (type.Namespace)); - } - - static CodedRID MakeCodedRID (IMetadataTokenProvider provider, CodedIndex index) - { - return MakeCodedRID (provider.MetadataToken, index); - } - - static CodedRID MakeCodedRID (MetadataToken token, CodedIndex index) - { - return index.CompressMetadataToken (token); - } - - MetadataToken AddTypeReference (TypeReference type, TypeRefRow row) - { - type.token = new MetadataToken (TokenType.TypeRef, type_ref_table.AddRow (row)); - - var token = type.token; - type_ref_map.Add (row, token); - return token; - } - - void AddTypeDefs () - { - var types = module.Types; - - for (int i = 0; i < types.Count; i++) - AddType (types [i]); - } - - void AddType (TypeDefinition type) - { - type_def_table.AddRow (new TypeDefRow ( - type.Attributes, - GetStringIndex (type.Name), - GetStringIndex (type.Namespace), - MakeCodedRID (GetTypeToken (type.BaseType), CodedIndex.TypeDefOrRef), - type.fields_range.Start, - type.methods_range.Start)); - - if (type.HasGenericParameters) - AddGenericParameters (type); - - if (type.HasInterfaces) - AddInterfaces (type); - - if (type.HasLayoutInfo) - AddLayoutInfo (type); - - if (type.HasFields) - AddFields (type); - - if (type.HasMethods) - AddMethods (type); - - if (type.HasProperties) - AddProperties (type); - - if (type.HasEvents) - AddEvents (type); - - if (type.HasCustomAttributes) - AddCustomAttributes (type); - - if (type.HasSecurityDeclarations) - AddSecurityDeclarations (type); - - if (type.HasNestedTypes) - AddNestedTypes (type); - } - - void AddGenericParameters (IGenericParameterProvider owner) - { - var parameters = owner.GenericParameters; - - for (int i = 0; i < parameters.Count; i++) - generic_parameters.Add (parameters [i]); - } - - sealed class GenericParameterComparer : IComparer { - - public int Compare (GenericParameter a, GenericParameter b) - { - var a_owner = MakeCodedRID (a.Owner, CodedIndex.TypeOrMethodDef); - var b_owner = MakeCodedRID (b.Owner, CodedIndex.TypeOrMethodDef); - if (a_owner == b_owner) { - var a_pos = a.Position; - var b_pos = b.Position; - return a_pos == b_pos ? 0 : a_pos > b_pos ? 1 : -1; - } - - return a_owner > b_owner ? 1 : -1; - } - } - - void AddGenericParameters () - { - var items = this.generic_parameters.items; - var size = this.generic_parameters.size; - Array.Sort (items, 0, size, new GenericParameterComparer ()); - - var generic_param_table = GetTable (Table.GenericParam); - var generic_param_constraint_table = GetTable (Table.GenericParamConstraint); - - for (int i = 0; i < size; i++) { - var generic_parameter = items [i]; - - var rid = generic_param_table.AddRow (new GenericParamRow ( - (ushort) generic_parameter.Position, - generic_parameter.Attributes, - MakeCodedRID (generic_parameter.Owner, CodedIndex.TypeOrMethodDef), - GetStringIndex (generic_parameter.Name))); - - generic_parameter.token = new MetadataToken (TokenType.GenericParam, rid); - - if (generic_parameter.HasConstraints) - AddConstraints (generic_parameter, generic_param_constraint_table); - - if (generic_parameter.HasCustomAttributes) - AddCustomAttributes (generic_parameter); - } - } - - void AddConstraints (GenericParameter generic_parameter, GenericParamConstraintTable table) - { - var constraints = generic_parameter.Constraints; - - var rid = generic_parameter.token.RID; - - for (int i = 0; i < constraints.Count; i++) - table.AddRow (new GenericParamConstraintRow ( - rid, - MakeCodedRID (GetTypeToken (constraints [i]), CodedIndex.TypeDefOrRef))); - } - - void AddInterfaces (TypeDefinition type) - { - var interfaces = type.Interfaces; - var type_rid = type.token.RID; - - for (int i = 0; i < interfaces.Count; i++) - iface_impl_table.AddRow (new InterfaceImplRow ( - type_rid, - MakeCodedRID (GetTypeToken (interfaces [i]), CodedIndex.TypeDefOrRef))); - } - - void AddLayoutInfo (TypeDefinition type) - { - var table = GetTable (Table.ClassLayout); - - table.AddRow (new ClassLayoutRow ( - (ushort) type.PackingSize, - (uint) type.ClassSize, - type.token.RID)); - } - - void AddNestedTypes (TypeDefinition type) - { - var nested_types = type.NestedTypes; - var nested_table = GetTable (Table.NestedClass); - - for (int i = 0; i < nested_types.Count; i++) { - var nested = nested_types [i]; - AddType (nested); - nested_table.AddRow (new NestedClassRow (nested.token.RID, type.token.RID)); - } - } - - void AddFields (TypeDefinition type) - { - var fields = type.Fields; - - for (int i = 0; i < fields.Count; i++) - AddField (fields [i]); - } - - void AddField (FieldDefinition field) - { - field_table.AddRow (new FieldRow ( - field.Attributes, - GetStringIndex (field.Name), - GetBlobIndex (GetFieldSignature (field)))); - - if (!field.InitialValue.IsNullOrEmpty ()) - AddFieldRVA (field); - - if (field.HasLayoutInfo) - AddFieldLayout (field); - - if (field.HasCustomAttributes) - AddCustomAttributes (field); - - if (field.HasConstant) - AddConstant (field, field.FieldType); - - if (field.HasMarshalInfo) - AddMarshalInfo (field); - } - - void AddFieldRVA (FieldDefinition field) - { - var table = GetTable (Table.FieldRVA); - table.AddRow (new FieldRVARow ( - data.AddData (field.InitialValue), - field.token.RID)); - } - - void AddFieldLayout (FieldDefinition field) - { - var table = GetTable (Table.FieldLayout); - table.AddRow (new FieldLayoutRow ((uint) field.Offset, field.token.RID)); - } - - void AddMethods (TypeDefinition type) - { - var methods = type.Methods; - - for (int i = 0; i < methods.Count; i++) - AddMethod (methods [i]); - } - - void AddMethod (MethodDefinition method) - { - method_table.AddRow (new MethodRow ( - method.HasBody ? code.WriteMethodBody (method) : 0, - method.ImplAttributes, - method.Attributes, - GetStringIndex (method.Name), - GetBlobIndex (GetMethodSignature (method)), - param_rid)); - - AddParameters (method); - - if (method.HasGenericParameters) - AddGenericParameters (method); - - if (method.IsPInvokeImpl) - AddPInvokeInfo (method); - - if (method.HasCustomAttributes) - AddCustomAttributes (method); - - if (method.HasSecurityDeclarations) - AddSecurityDeclarations (method); - - if (method.HasOverrides) - AddOverrides (method); - } - - void AddParameters (MethodDefinition method) - { - var return_parameter = method.MethodReturnType.parameter; - - if (return_parameter != null && RequiresParameterRow (return_parameter)) - AddParameter (0, return_parameter, param_table); - - if (!method.HasParameters) - return; - - var parameters = method.Parameters; - - for (int i = 0; i < parameters.Count; i++) { - var parameter = parameters [i]; - if (!RequiresParameterRow (parameter)) - continue; - - AddParameter ((ushort) (i + 1), parameter, param_table); - } - } - - void AddPInvokeInfo (MethodDefinition method) - { - var pinvoke = method.PInvokeInfo; - if (pinvoke == null) - return; - - var table = GetTable (Table.ImplMap); - table.AddRow (new ImplMapRow ( - pinvoke.Attributes, - MakeCodedRID (method, CodedIndex.MemberForwarded), - GetStringIndex (pinvoke.EntryPoint), - pinvoke.Module.MetadataToken.RID)); - } - - void AddOverrides (MethodDefinition method) - { - var overrides = method.Overrides; - var table = GetTable (Table.MethodImpl); - - for (int i = 0; i < overrides.Count; i++) { - table.AddRow (new MethodImplRow ( - method.DeclaringType.token.RID, - MakeCodedRID (method, CodedIndex.MethodDefOrRef), - MakeCodedRID (LookupToken (overrides [i]), CodedIndex.MethodDefOrRef))); - } - } - - static bool RequiresParameterRow (ParameterDefinition parameter) - { - return !string.IsNullOrEmpty (parameter.Name) - || parameter.Attributes != ParameterAttributes.None - || parameter.HasMarshalInfo - || parameter.HasConstant - || parameter.HasCustomAttributes; - } - - void AddParameter (ushort sequence, ParameterDefinition parameter, ParamTable table) - { - table.AddRow (new ParamRow ( - parameter.Attributes, - sequence, - GetStringIndex (parameter.Name))); - - parameter.token = new MetadataToken (TokenType.Param, param_rid++); - - if (parameter.HasCustomAttributes) - AddCustomAttributes (parameter); - - if (parameter.HasConstant) - AddConstant (parameter, parameter.ParameterType); - - if (parameter.HasMarshalInfo) - AddMarshalInfo (parameter); - } - - void AddMarshalInfo (IMarshalInfoProvider owner) - { - var table = GetTable (Table.FieldMarshal); - - table.AddRow (new FieldMarshalRow ( - MakeCodedRID (owner, CodedIndex.HasFieldMarshal), - GetBlobIndex (GetMarshalInfoSignature (owner)))); - } - - void AddProperties (TypeDefinition type) - { - var properties = type.Properties; - - property_map_table.AddRow (new PropertyMapRow (type.token.RID, property_rid)); - - for (int i = 0; i < properties.Count; i++) - AddProperty (properties [i]); - } - - void AddProperty (PropertyDefinition property) - { - property_table.AddRow (new PropertyRow ( - property.Attributes, - GetStringIndex (property.Name), - GetBlobIndex (GetPropertySignature (property)))); - property.token = new MetadataToken (TokenType.Property, property_rid++); - - var method = property.GetMethod; - if (method != null) - AddSemantic (MethodSemanticsAttributes.Getter, property, method); - - method = property.SetMethod; - if (method != null) - AddSemantic (MethodSemanticsAttributes.Setter, property, method); - - if (property.HasOtherMethods) - AddOtherSemantic (property, property.OtherMethods); - - if (property.HasCustomAttributes) - AddCustomAttributes (property); - - if (property.HasConstant) - AddConstant (property, property.PropertyType); - } - - void AddOtherSemantic (IMetadataTokenProvider owner, Collection others) - { - for (int i = 0; i < others.Count; i++) - AddSemantic (MethodSemanticsAttributes.Other, owner, others [i]); - } - - void AddEvents (TypeDefinition type) - { - var events = type.Events; - - event_map_table.AddRow (new EventMapRow (type.token.RID, event_rid)); - - for (int i = 0; i < events.Count; i++) - AddEvent (events [i]); - } - - void AddEvent (EventDefinition @event) - { - event_table.AddRow (new EventRow ( - @event.Attributes, - GetStringIndex (@event.Name), - MakeCodedRID (GetTypeToken (@event.EventType), CodedIndex.TypeDefOrRef))); - @event.token = new MetadataToken (TokenType.Event, event_rid++); - - var method = @event.AddMethod; - if (method != null) - AddSemantic (MethodSemanticsAttributes.AddOn, @event, method); - - method = @event.InvokeMethod; - if (method != null) - AddSemantic (MethodSemanticsAttributes.Fire, @event, method); - - method = @event.RemoveMethod; - if (method != null) - AddSemantic (MethodSemanticsAttributes.RemoveOn, @event, method); - - if (@event.HasOtherMethods) - AddOtherSemantic (@event, @event.OtherMethods); - - if (@event.HasCustomAttributes) - AddCustomAttributes (@event); - } - - void AddSemantic (MethodSemanticsAttributes semantics, IMetadataTokenProvider provider, MethodDefinition method) - { - method.SemanticsAttributes = semantics; - var table = GetTable (Table.MethodSemantics); - - table.AddRow (new MethodSemanticsRow ( - semantics, - method.token.RID, - MakeCodedRID (provider, CodedIndex.HasSemantics))); - } - - void AddConstant (IConstantProvider owner, TypeReference type) - { - var constant = owner.Constant; - var etype = GetConstantType (type, constant); - - constant_table.AddRow (new ConstantRow ( - etype, - MakeCodedRID (owner.MetadataToken, CodedIndex.HasConstant), - GetBlobIndex (GetConstantSignature (etype, constant)))); - } - - static ElementType GetConstantType (TypeReference constant_type, object constant) - { - if (constant == null) - return ElementType.Class; - - var etype = constant_type.etype; - switch (etype) { - case ElementType.None: - var type = constant_type.CheckedResolve (); - if (type.IsEnum) - return GetConstantType (type.GetEnumUnderlyingType (), constant); - - return ElementType.Class; - case ElementType.String: - return ElementType.String; - case ElementType.Object: - return GetConstantType (constant.GetType ()); - case ElementType.Array: - case ElementType.SzArray: - case ElementType.MVar: - case ElementType.Var: - return ElementType.Class; - case ElementType.GenericInst: - case ElementType.CModOpt: - case ElementType.CModReqD: - case ElementType.ByRef: - case ElementType.Sentinel: - return GetConstantType (((TypeSpecification) constant_type).ElementType, constant); - case ElementType.Boolean: - case ElementType.Char: - case ElementType.I: - case ElementType.I1: - case ElementType.I2: - case ElementType.I4: - case ElementType.I8: - case ElementType.U: - case ElementType.U1: - case ElementType.U2: - case ElementType.U4: - case ElementType.U8: - case ElementType.R4: - case ElementType.R8: - return GetConstantType (constant.GetType ()); - default: - return etype; - } - } - - static ElementType GetConstantType (Type type) - { - switch (Type.GetTypeCode (type)) { - case TypeCode.Boolean: - return ElementType.Boolean; - case TypeCode.Byte: - return ElementType.U1; - case TypeCode.SByte: - return ElementType.I1; - case TypeCode.Char: - return ElementType.Char; - case TypeCode.Int16: - return ElementType.I2; - case TypeCode.UInt16: - return ElementType.U2; - case TypeCode.Int32: - return ElementType.I4; - case TypeCode.UInt32: - return ElementType.U4; - case TypeCode.Int64: - return ElementType.I8; - case TypeCode.UInt64: - return ElementType.U8; - case TypeCode.Single: - return ElementType.R4; - case TypeCode.Double: - return ElementType.R8; - case TypeCode.String: - return ElementType.String; - default: - throw new NotSupportedException (type.FullName); - } - } - - void AddCustomAttributes (ICustomAttributeProvider owner) - { - var custom_attributes = owner.CustomAttributes; - - for (int i = 0; i < custom_attributes.Count; i++) { - var attribute = custom_attributes [i]; - - custom_attribute_table.AddRow (new CustomAttributeRow ( - MakeCodedRID (owner, CodedIndex.HasCustomAttribute), - MakeCodedRID (LookupToken (attribute.Constructor), CodedIndex.CustomAttributeType), - GetBlobIndex (GetCustomAttributeSignature (attribute)))); - } - } - - void AddSecurityDeclarations (ISecurityDeclarationProvider owner) - { - var declarations = owner.SecurityDeclarations; - - for (int i = 0; i < declarations.Count; i++) { - var declaration = declarations [i]; - - declsec_table.AddRow (new DeclSecurityRow ( - declaration.Action, - MakeCodedRID (owner, CodedIndex.HasDeclSecurity), - GetBlobIndex (GetSecurityDeclarationSignature (declaration)))); - } - } - - MetadataToken GetMemberRefToken (MemberReference member) - { - var row = CreateMemberRefRow (member); - - MetadataToken token; - if (member_ref_map.TryGetValue (row, out token)) - return token; - - AddMemberReference (member, row); - - return member.token; - } - - MemberRefRow CreateMemberRefRow (MemberReference member) - { - return new MemberRefRow ( - MakeCodedRID (GetTypeToken (member.DeclaringType), CodedIndex.MemberRefParent), - GetStringIndex (member.Name), - GetBlobIndex (GetMemberRefSignature (member))); - } - - void AddMemberReference (MemberReference member, MemberRefRow row) - { - member.token = new MetadataToken (TokenType.MemberRef, member_ref_table.AddRow (row)); - member_ref_map.Add (row, member.token); - } - - MetadataToken GetMethodSpecToken (MethodSpecification method_spec) - { - var row = CreateMethodSpecRow (method_spec); - - MetadataToken token; - if (method_spec_map.TryGetValue (row, out token)) - return token; - - AddMethodSpecification (method_spec, row); - - return method_spec.token; - } - - void AddMethodSpecification (MethodSpecification method_spec, MethodSpecRow row) - { - method_spec.token = new MetadataToken (TokenType.MethodSpec, method_spec_table.AddRow (row)); - method_spec_map.Add (row, method_spec.token); - } - - MethodSpecRow CreateMethodSpecRow (MethodSpecification method_spec) - { - return new MethodSpecRow ( - MakeCodedRID (LookupToken (method_spec.ElementMethod), CodedIndex.MethodDefOrRef), - GetBlobIndex (GetMethodSpecSignature (method_spec))); - } - - SignatureWriter CreateSignatureWriter () - { - return new SignatureWriter (this); - } - - SignatureWriter GetMethodSpecSignature (MethodSpecification method_spec) - { - if (!method_spec.IsGenericInstance) - throw new NotSupportedException (); - - var generic_instance = (GenericInstanceMethod) method_spec; - - var signature = CreateSignatureWriter (); - signature.WriteByte (0x0a); - - signature.WriteGenericInstanceSignature (generic_instance); - - return signature; - } - - public uint AddStandAloneSignature (uint signature) - { - return (uint) standalone_sig_table.AddRow (signature); - } - - public uint GetLocalVariableBlobIndex (Collection variables) - { - return GetBlobIndex (GetVariablesSignature (variables)); - } - - public uint GetCallSiteBlobIndex (CallSite call_site) - { - return GetBlobIndex (GetMethodSignature (call_site)); - } - - SignatureWriter GetVariablesSignature (Collection variables) - { - var signature = CreateSignatureWriter (); - signature.WriteByte (0x7); - signature.WriteCompressedUInt32 ((uint) variables.Count); - for (int i = 0; i < variables.Count; i++) - signature.WriteTypeSignature (variables [i].VariableType); - return signature; - } - - SignatureWriter GetFieldSignature (FieldReference field) - { - var signature = CreateSignatureWriter (); - signature.WriteByte (0x6); - signature.WriteTypeSignature (field.FieldType); - return signature; - } - - SignatureWriter GetMethodSignature (IMethodSignature method) - { - var signature = CreateSignatureWriter (); - signature.WriteMethodSignature (method); - return signature; - } - - SignatureWriter GetMemberRefSignature (MemberReference member) - { - var field = member as FieldReference; - if (field != null) - return GetFieldSignature (field); - - var method = member as MethodReference; - if (method != null) - return GetMethodSignature (method); - - throw new NotSupportedException (); - } - - SignatureWriter GetPropertySignature (PropertyDefinition property) - { - var signature = CreateSignatureWriter (); - byte calling_convention = 0x8; - if (property.HasThis) - calling_convention |= 0x20; - - uint param_count = 0; - Collection parameters = null; - - if (property.HasParameters) { - parameters = property.Parameters; - param_count = (uint) parameters.Count; - } - - signature.WriteByte (calling_convention); - signature.WriteCompressedUInt32 (param_count); - signature.WriteTypeSignature (property.PropertyType); - - if (param_count == 0) - return signature; - - for (int i = 0; i < param_count; i++) - signature.WriteTypeSignature (parameters [i].ParameterType); - - return signature; - } - - SignatureWriter GetTypeSpecSignature (TypeReference type) - { - var signature = CreateSignatureWriter (); - signature.WriteTypeSignature (type); - return signature; - } - - SignatureWriter GetConstantSignature (ElementType type, object value) - { - var signature = CreateSignatureWriter (); - - switch (type) { - case ElementType.Array: - case ElementType.SzArray: - case ElementType.Class: - case ElementType.Object: - case ElementType.Var: - case ElementType.MVar: - signature.WriteInt32 (0); - break; - case ElementType.String: - signature.WriteConstantString ((string) value); - break; - default: - signature.WriteConstantPrimitive (value); - break; - } - - return signature; - } - - SignatureWriter GetCustomAttributeSignature (CustomAttribute attribute) - { - var signature = CreateSignatureWriter (); - if (!attribute.resolved) { - signature.WriteBytes (attribute.GetBlob ()); - return signature; - } - - signature.WriteUInt16 (0x0001); - - signature.WriteCustomAttributeConstructorArguments (attribute); - - signature.WriteCustomAttributeNamedArguments (attribute); - - return signature; - } - - SignatureWriter GetSecurityDeclarationSignature (SecurityDeclaration declaration) - { - var signature = CreateSignatureWriter (); - - if (!declaration.resolved) - signature.WriteBytes (declaration.GetBlob ()); - else if (module.Runtime < TargetRuntime.Net_2_0) - signature.WriteXmlSecurityDeclaration (declaration); - else - signature.WriteSecurityDeclaration (declaration); - - return signature; - } - - SignatureWriter GetMarshalInfoSignature (IMarshalInfoProvider owner) - { - var signature = CreateSignatureWriter (); - - signature.WriteMarshalInfo (owner.MarshalInfo); - - return signature; - } - - static Exception CreateForeignMemberException (MemberReference member) - { - return new ArgumentException (string.Format ("Member '{0}' is declared in another module and needs to be imported", member)); - } - - public MetadataToken LookupToken (IMetadataTokenProvider provider) - { - if (provider == null) - throw new ArgumentNullException (); - - var member = provider as MemberReference; - if (member == null || member.Module != module) - throw CreateForeignMemberException (member); - - var token = provider.MetadataToken; - - switch (token.TokenType) { - case TokenType.TypeDef: - case TokenType.Method: - case TokenType.Field: - case TokenType.Event: - case TokenType.Property: - return token; - case TokenType.TypeRef: - case TokenType.TypeSpec: - case TokenType.GenericParam: - return GetTypeToken ((TypeReference) provider); - case TokenType.MethodSpec: - return GetMethodSpecToken ((MethodSpecification) provider); - case TokenType.MemberRef: - return GetMemberRefToken (member); - default: - throw new NotSupportedException (); - } - } - } - - sealed class SignatureWriter : ByteBuffer { - - readonly MetadataBuilder metadata; - - public SignatureWriter (MetadataBuilder metadata) - : base (6) - { - this.metadata = metadata; - } - - public void WriteElementType (ElementType element_type) - { - WriteByte ((byte) element_type); - } - - public void WriteUTF8String (string @string) - { - if (@string == null) { - WriteByte (0xff); - return; - } - - var bytes = Encoding.UTF8.GetBytes (@string); - WriteCompressedUInt32 ((uint) bytes.Length); - WriteBytes (bytes); - } - - public void WriteMethodSignature (IMethodSignature method) - { - byte calling_convention = (byte) method.CallingConvention; - if (method.HasThis) - calling_convention |= 0x20; - if (method.ExplicitThis) - calling_convention |= 0x40; - - var generic_provider = method as IGenericParameterProvider; - var generic_arity = generic_provider != null && generic_provider.HasGenericParameters - ? generic_provider.GenericParameters.Count - : 0; - - if (generic_arity > 0) - calling_convention |= 0x10; - - var param_count = method.HasParameters ? method.Parameters.Count : 0; - - WriteByte (calling_convention); - - if (generic_arity > 0) - WriteCompressedUInt32 ((uint) generic_arity); - - WriteCompressedUInt32 ((uint) param_count); - WriteTypeSignature (method.ReturnType); - - if (param_count == 0) - return; - - var parameters = method.Parameters; - - for (int i = 0; i < param_count; i++) - WriteTypeSignature (parameters [i].ParameterType); - } - - uint MakeTypeDefOrRefCodedRID (TypeReference type) - { - return CodedIndex.TypeDefOrRef.CompressMetadataToken (metadata.LookupToken (type)); - } - - public void WriteTypeSignature (TypeReference type) - { - if (type == null) - throw new ArgumentNullException (); - - var etype = type.etype; - - switch (etype) { - case ElementType.MVar: - case ElementType.Var: { - var generic_parameter = (GenericParameter) type; - - WriteElementType (etype); - var position = generic_parameter.Position; - if (position == -1) - throw new NotSupportedException (); - - WriteCompressedUInt32 ((uint) position); - break; - } - - case ElementType.GenericInst: { - var generic_instance = (GenericInstanceType) type; - WriteElementType (ElementType.GenericInst); - WriteElementType (generic_instance.IsValueType ? ElementType.ValueType : ElementType.Class); - WriteCompressedUInt32 (MakeTypeDefOrRefCodedRID (generic_instance.ElementType)); - - WriteGenericInstanceSignature (generic_instance); - break; - } - - case ElementType.Ptr: - case ElementType.ByRef: - case ElementType.Pinned: - case ElementType.Sentinel: { - var type_spec = (TypeSpecification) type; - WriteElementType (etype); - WriteTypeSignature (type_spec.ElementType); - break; - } - - case ElementType.FnPtr: { - var fptr = (FunctionPointerType) type; - WriteElementType (ElementType.FnPtr); - WriteMethodSignature (fptr); - break; - } - - case ElementType.CModOpt: - case ElementType.CModReqD: { - var modifier = (IModifierType) type; - WriteModifierSignature (etype, modifier); - break; - } - - case ElementType.Array: { - var array = (ArrayType) type; - if (!array.IsVector) { - WriteArrayTypeSignature (array); - break; - } - - WriteElementType (ElementType.SzArray); - WriteTypeSignature (array.ElementType); - break; - } - - case ElementType.None: { - WriteElementType (type.IsValueType ? ElementType.ValueType : ElementType.Class); - WriteCompressedUInt32 (MakeTypeDefOrRefCodedRID (type)); - break; - } - - default: - if (!TryWriteElementType (type)) - throw new NotSupportedException (); - - break; - - } - } - - void WriteArrayTypeSignature (ArrayType array) - { - WriteElementType (ElementType.Array); - WriteTypeSignature (array.ElementType); - - var dimensions = array.Dimensions; - var rank = dimensions.Count; - - WriteCompressedUInt32 ((uint) rank); - - var sized = 0; - var lbounds = 0; - - for (int i = 0; i < rank; i++) { - var dimension = dimensions [i]; - - if (dimension.UpperBound.HasValue) { - sized++; - lbounds++; - } else if (dimension.LowerBound.HasValue) - lbounds++; - } - - var sizes = new int [sized]; - var low_bounds = new int [lbounds]; - - for (int i = 0; i < lbounds; i++) { - var dimension = dimensions [i]; - low_bounds [i] = dimension.LowerBound.GetValueOrDefault (); - if (dimension.UpperBound.HasValue) - sizes [i] = dimension.UpperBound.Value - low_bounds [i] + 1; - } - - WriteCompressedUInt32 ((uint) sized); - for (int i = 0; i < sized; i++) - WriteCompressedUInt32 ((uint) sizes [i]); - - WriteCompressedUInt32 ((uint) lbounds); - for (int i = 0; i < lbounds; i++) - WriteCompressedInt32 (low_bounds [i]); - } - - public void WriteGenericInstanceSignature (IGenericInstance instance) - { - var generic_arguments = instance.GenericArguments; - var arity = generic_arguments.Count; - - WriteCompressedUInt32 ((uint) arity); - for (int i = 0; i < arity; i++) - WriteTypeSignature (generic_arguments [i]); - } - - void WriteModifierSignature (ElementType element_type, IModifierType type) - { - WriteElementType (element_type); - WriteCompressedUInt32 (MakeTypeDefOrRefCodedRID (type.ModifierType)); - WriteTypeSignature (type.ElementType); - } - - bool TryWriteElementType (TypeReference type) - { - var element = type.etype; - - if (element == ElementType.None) - return false; - - WriteElementType (element); - return true; - } - - public void WriteConstantString (string value) - { - WriteBytes (Encoding.Unicode.GetBytes (value)); - } - - public void WriteConstantPrimitive (object value) - { - WritePrimitiveValue (value); - } - - public void WriteCustomAttributeConstructorArguments (CustomAttribute attribute) - { - if (!attribute.HasConstructorArguments) - return; - - var arguments = attribute.ConstructorArguments; - var parameters = attribute.Constructor.Parameters; - - if (parameters.Count != arguments.Count) - throw new InvalidOperationException (); - - for (int i = 0; i < arguments.Count; i++) - WriteCustomAttributeFixedArgument (parameters [i].ParameterType, arguments [i]); - } - - void WriteCustomAttributeFixedArgument (TypeReference type, CustomAttributeArgument argument) - { - if (type.IsArray) { - WriteCustomAttributeFixedArrayArgument ((ArrayType) type, argument); - return; - } - - WriteCustomAttributeElement (type, argument); - } - - void WriteCustomAttributeFixedArrayArgument (ArrayType type, CustomAttributeArgument argument) - { - var values = argument.Value as CustomAttributeArgument []; - - if (values == null) { - WriteUInt32 (0xffffffff); - return; - } - - WriteInt32 (values.Length); - - if (values.Length == 0) - return; - - var element_type = type.ElementType; - - for (int i = 0; i < values.Length; i++) - WriteCustomAttributeElement (element_type, values [i]); - } - - void WriteCustomAttributeElement (TypeReference type, CustomAttributeArgument argument) - { - if (type.IsArray) { - WriteCustomAttributeFixedArrayArgument ((ArrayType) type, argument); - return; - } - - if (type.etype == ElementType.Object) { - argument = (CustomAttributeArgument) argument.Value; - type = argument.Type; - - WriteCustomAttributeFieldOrPropType (type); - WriteCustomAttributeElement (type, argument); - return; - } - - WriteCustomAttributeValue (type, argument.Value); - } - - void WriteCustomAttributeValue (TypeReference type, object value) - { - var etype = type.etype; - - switch (etype) { - case ElementType.String: - var @string = (string) value; - if (@string == null) - WriteByte (0xff); - else - WriteUTF8String (@string); - break; - case ElementType.None: - if (type.IsTypeOf ("System", "Type")) - WriteTypeReference ((TypeReference) value); - else - WriteCustomAttributeEnumValue (type, value); - break; - default: - WritePrimitiveValue (value); - break; - } - } - - void WritePrimitiveValue (object value) - { - if (value == null) - throw new ArgumentNullException (); - - switch (Type.GetTypeCode (value.GetType ())) { - case TypeCode.Boolean: - WriteByte ((byte) (((bool) value) ? 1 : 0)); - break; - case TypeCode.Byte: - WriteByte ((byte) value); - break; - case TypeCode.SByte: - WriteSByte ((sbyte) value); - break; - case TypeCode.Int16: - WriteInt16 ((short) value); - break; - case TypeCode.UInt16: - WriteUInt16 ((ushort) value); - break; - case TypeCode.Char: - WriteInt16 ((short) (char) value); - break; - case TypeCode.Int32: - WriteInt32 ((int) value); - break; - case TypeCode.UInt32: - WriteUInt32 ((uint) value); - break; - case TypeCode.Single: - WriteSingle ((float) value); - break; - case TypeCode.Int64: - WriteInt64 ((long) value); - break; - case TypeCode.UInt64: - WriteUInt64 ((ulong) value); - break; - case TypeCode.Double: - WriteDouble ((double) value); - break; - default: - throw new NotSupportedException (value.GetType ().FullName); - } - } - - void WriteCustomAttributeEnumValue (TypeReference enum_type, object value) - { - var type = enum_type.CheckedResolve (); - if (!type.IsEnum) - throw new ArgumentException (); - - WriteCustomAttributeValue (type.GetEnumUnderlyingType (), value); - } - - void WriteCustomAttributeFieldOrPropType (TypeReference type) - { - if (type.IsArray) { - var array = (ArrayType) type; - WriteElementType (ElementType.SzArray); - WriteCustomAttributeFieldOrPropType (array.ElementType); - return; - } - - var etype = type.etype; - - switch (etype) { - case ElementType.Object: - WriteElementType (ElementType.Boxed); - return; - case ElementType.None: - if (type.IsTypeOf ("System", "Type")) - WriteElementType (ElementType.Type); - else { - WriteElementType (ElementType.Enum); - WriteTypeReference (type); - } - return; - default: - WriteElementType (etype); - return; - } - } - - public void WriteCustomAttributeNamedArguments (CustomAttribute attribute) - { - var count = GetNamedArgumentCount (attribute); - - WriteUInt16 ((ushort) count); - - if (count == 0) - return; - - WriteICustomAttributeNamedArguments (attribute); - } - - static int GetNamedArgumentCount (ICustomAttribute attribute) - { - int count = 0; - - if (attribute.HasFields) - count += attribute.Fields.Count; - - if (attribute.HasProperties) - count += attribute.Properties.Count; - - return count; - } - - void WriteICustomAttributeNamedArguments (ICustomAttribute attribute) - { - if (attribute.HasFields) - WriteCustomAttributeNamedArguments (0x53, attribute.Fields); - - if (attribute.HasProperties) - WriteCustomAttributeNamedArguments (0x54, attribute.Properties); - } - - void WriteCustomAttributeNamedArguments (byte kind, Collection named_arguments) - { - for (int i = 0; i < named_arguments.Count; i++) - WriteCustomAttributeNamedArgument (kind, named_arguments [i]); - } - - void WriteCustomAttributeNamedArgument (byte kind, CustomAttributeNamedArgument named_argument) - { - var argument = named_argument.Argument; - - WriteByte (kind); - WriteCustomAttributeFieldOrPropType (argument.Type); - WriteUTF8String (named_argument.Name); - WriteCustomAttributeFixedArgument (argument.Type, argument); - } - - void WriteSecurityAttribute (SecurityAttribute attribute) - { - WriteTypeReference (attribute.AttributeType); - - var count = GetNamedArgumentCount (attribute); - - if (count == 0) { - WriteCompressedUInt32 (1); // length - WriteCompressedUInt32 (0); // count - return; - } - - var buffer = new SignatureWriter (metadata); - buffer.WriteCompressedUInt32 ((uint) count); - buffer.WriteICustomAttributeNamedArguments (attribute); - - WriteCompressedUInt32 ((uint) buffer.length); - WriteBytes (buffer); - } - - public void WriteSecurityDeclaration (SecurityDeclaration declaration) - { - WriteByte ((byte) '.'); - - var attributes = declaration.security_attributes; - if (attributes == null) - throw new NotSupportedException (); - - WriteCompressedUInt32 ((uint) attributes.Count); - - for (int i = 0; i < attributes.Count; i++) - WriteSecurityAttribute (attributes [i]); - } - - public void WriteXmlSecurityDeclaration (SecurityDeclaration declaration) - { - var xml = GetXmlSecurityDeclaration (declaration); - if (xml == null) - throw new NotSupportedException (); - - WriteBytes (Encoding.Unicode.GetBytes (xml)); - } - - static string GetXmlSecurityDeclaration (SecurityDeclaration declaration) - { - if (declaration.security_attributes == null || declaration.security_attributes.Count != 1) - return null; - - var attribute = declaration.security_attributes [0]; - - if (!attribute.AttributeType.IsTypeOf ("System.Security.Permissions", "PermissionSetAttribute")) - return null; - - if (attribute.properties == null || attribute.properties.Count != 1) - return null; - - var property = attribute.properties [0]; - if (property.Name != "XML") - return null; - - return (string) property.Argument.Value; - } - - void WriteTypeReference (TypeReference type) - { - WriteUTF8String (TypeParser.ToParseable (type)); - } - - public void WriteMarshalInfo (MarshalInfo marshal_info) - { - WriteNativeType (marshal_info.native); - - switch (marshal_info.native) { - case NativeType.Array: { - var array = (ArrayMarshalInfo) marshal_info; - if (array.element_type != NativeType.None) - WriteNativeType (array.element_type); - if (array.size_parameter_index > -1) - WriteCompressedUInt32 ((uint) array.size_parameter_index); - if (array.size > -1) - WriteCompressedUInt32 ((uint) array.size); - if (array.size_parameter_multiplier > -1) - WriteCompressedUInt32 ((uint) array.size_parameter_multiplier); - return; - } - case NativeType.SafeArray: { - var array = (SafeArrayMarshalInfo) marshal_info; - if (array.element_type != VariantType.None) - WriteVariantType (array.element_type); - return; - } - case NativeType.FixedArray: { - var array = (FixedArrayMarshalInfo) marshal_info; - if (array.size > -1) - WriteCompressedUInt32 ((uint) array.size); - if (array.element_type != NativeType.None) - WriteNativeType (array.element_type); - return; - } - case NativeType.FixedSysString: - var sys_string = (FixedSysStringMarshalInfo) marshal_info; - if (sys_string.size > -1) - WriteCompressedUInt32 ((uint) sys_string.size); - return; - case NativeType.CustomMarshaler: - var marshaler = (CustomMarshalInfo) marshal_info; - WriteUTF8String (marshaler.guid != Guid.Empty ? marshaler.guid.ToString () : string.Empty); - WriteUTF8String (marshaler.unmanaged_type); - WriteTypeReference (marshaler.managed_type); - WriteUTF8String (marshaler.cookie); - return; - } - } - - void WriteNativeType (NativeType native) - { - WriteByte ((byte) native); - } - - void WriteVariantType (VariantType variant) - { - WriteByte ((byte) variant); - } - } - -#endif - -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs b/mcs/class/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs deleted file mode 100644 index 10ab2c34a86..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs +++ /dev/null @@ -1,363 +0,0 @@ -// -// BaseAssemblyResolver.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public delegate AssemblyDefinition AssemblyResolveEventHandler (object sender, AssemblyNameReference reference); - - public sealed class AssemblyResolveEventArgs : EventArgs { - - readonly AssemblyNameReference reference; - - public AssemblyNameReference AssemblyReference { - get { return reference; } - } - - public AssemblyResolveEventArgs (AssemblyNameReference reference) - { - this.reference = reference; - } - } - -#if !SILVERLIGHT && !CF - [Serializable] -#endif - public class AssemblyResolutionException : FileNotFoundException { - - readonly AssemblyNameReference reference; - - public AssemblyNameReference AssemblyReference { - get { return reference; } - } - - public AssemblyResolutionException (AssemblyNameReference reference) - : base (string.Format ("Failed to resolve assembly: '{0}'", reference)) - { - this.reference = reference; - } - -#if !SILVERLIGHT && !CF - protected AssemblyResolutionException ( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) - : base (info, context) - { - } -#endif - } - - public abstract class BaseAssemblyResolver : IAssemblyResolver { - - static readonly bool on_mono = Type.GetType ("Mono.Runtime") != null; - - readonly Collection directories; - -#if !SILVERLIGHT && !CF - Collection gac_paths; -#endif - - public void AddSearchDirectory (string directory) - { - directories.Add (directory); - } - - public void RemoveSearchDirectory (string directory) - { - directories.Remove (directory); - } - - public string [] GetSearchDirectories () - { - var directories = new string [this.directories.size]; - Array.Copy (this.directories.items, directories, directories.Length); - return directories; - } - - public virtual AssemblyDefinition Resolve (string fullName) - { - return Resolve (fullName, new ReaderParameters ()); - } - - public virtual AssemblyDefinition Resolve (string fullName, ReaderParameters parameters) - { - if (fullName == null) - throw new ArgumentNullException ("fullName"); - - return Resolve (AssemblyNameReference.Parse (fullName), parameters); - } - - public event AssemblyResolveEventHandler ResolveFailure; - - protected BaseAssemblyResolver () - { - directories = new Collection (2) { ".", "bin" }; - } - - AssemblyDefinition GetAssembly (string file, ReaderParameters parameters) - { - if (parameters.AssemblyResolver == null) - parameters.AssemblyResolver = this; - - return ModuleDefinition.ReadModule (file, parameters).Assembly; - } - - public virtual AssemblyDefinition Resolve (AssemblyNameReference name) - { - return Resolve (name, new ReaderParameters ()); - } - - public virtual AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters) - { - if (name == null) - throw new ArgumentNullException ("name"); - if (parameters == null) - parameters = new ReaderParameters (); - - var assembly = SearchDirectory (name, directories, parameters); - if (assembly != null) - return assembly; - -#if !SILVERLIGHT && !CF - var framework_dir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName); - - if (IsZero (name.Version)) { - assembly = SearchDirectory (name, new [] { framework_dir }, parameters); - if (assembly != null) - return assembly; - } - - if (name.Name == "mscorlib") { - assembly = GetCorlib (name, parameters); - if (assembly != null) - return assembly; - } - - assembly = GetAssemblyInGac (name, parameters); - if (assembly != null) - return assembly; - - assembly = SearchDirectory (name, new [] { framework_dir }, parameters); - if (assembly != null) - return assembly; -#endif - - if (ResolveFailure != null) { - assembly = ResolveFailure (this, name); - if (assembly != null) - return assembly; - } - - throw new AssemblyResolutionException (name); - } - - AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable directories, ReaderParameters parameters) - { - var extensions = new [] { ".exe", ".dll" }; - foreach (var directory in directories) { - foreach (var extension in extensions) { - string file = Path.Combine (directory, name.Name + extension); - if (File.Exists (file)) - return GetAssembly (file, parameters); - } - } - - return null; - } - - static bool IsZero (Version version) - { - return version == null || (version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0); - } - -#if !SILVERLIGHT && !CF - AssemblyDefinition GetCorlib (AssemblyNameReference reference, ReaderParameters parameters) - { - var version = reference.Version; - var corlib = typeof (object).Assembly.GetName (); - - if (corlib.Version == version || IsZero (version)) - return GetAssembly (typeof (object).Module.FullyQualifiedName, parameters); - - var path = Directory.GetParent ( - Directory.GetParent ( - typeof (object).Module.FullyQualifiedName).FullName - ).FullName; - - if (on_mono) { - if (version.Major == 1) - path = Path.Combine (path, "1.0"); - else if (version.Major == 2) { - if (version.MajorRevision == 5) - path = Path.Combine (path, "2.1"); - else - path = Path.Combine (path, "2.0"); - } else if (version.Major == 4) - path = Path.Combine (path, "4.0"); - else - throw new NotSupportedException ("Version not supported: " + version); - } else { - switch (version.Major) { - case 1: - if (version.MajorRevision == 3300) - path = Path.Combine (path, "v1.0.3705"); - else - path = Path.Combine (path, "v1.0.5000.0"); - break; - case 2: - path = Path.Combine (path, "v2.0.50727"); - break; - case 4: - path = Path.Combine (path, "v4.0.30319"); - break; - default: - throw new NotSupportedException ("Version not supported: " + version); - } - } - - var file = Path.Combine (path, "mscorlib.dll"); - if (File.Exists (file)) - return GetAssembly (file, parameters); - - return null; - } - - static Collection GetGacPaths () - { - if (on_mono) - return GetDefaultMonoGacPaths (); - - var paths = new Collection (2); - var windir = Environment.GetEnvironmentVariable ("WINDIR"); - if (windir == null) - return paths; - - paths.Add (Path.Combine (windir, "assembly")); - paths.Add (Path.Combine (windir, Path.Combine ("Microsoft.NET", "assembly"))); - return paths; - } - - static Collection GetDefaultMonoGacPaths () - { - var paths = new Collection (1); - var gac = GetCurrentMonoGac (); - if (gac != null) - paths.Add (gac); - - var gac_paths_env = Environment.GetEnvironmentVariable ("MONO_GAC_PREFIX"); - if (string.IsNullOrEmpty (gac_paths_env)) - return paths; - - var prefixes = gac_paths_env.Split (Path.PathSeparator); - foreach (var prefix in prefixes) { - if (string.IsNullOrEmpty (prefix)) - continue; - - var gac_path = Path.Combine (Path.Combine (Path.Combine (prefix, "lib"), "mono"), "gac"); - if (Directory.Exists (gac_path) && !paths.Contains (gac)) - paths.Add (gac_path); - } - - return paths; - } - - static string GetCurrentMonoGac () - { - return Path.Combine ( - Directory.GetParent ( - Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName)).FullName, - "gac"); - } - - AssemblyDefinition GetAssemblyInGac (AssemblyNameReference reference, ReaderParameters parameters) - { - if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0) - return null; - - if (gac_paths == null) - gac_paths = GetGacPaths (); - - if (on_mono) - return GetAssemblyInMonoGac (reference, parameters); - - return GetAssemblyInNetGac (reference, parameters); - } - - AssemblyDefinition GetAssemblyInMonoGac (AssemblyNameReference reference, ReaderParameters parameters) - { - for (int i = 0; i < gac_paths.Count; i++) { - var gac_path = gac_paths [i]; - var file = GetAssemblyFile (reference, string.Empty, gac_path); - if (File.Exists (file)) - return GetAssembly (file, parameters); - } - - return null; - } - - AssemblyDefinition GetAssemblyInNetGac (AssemblyNameReference reference, ReaderParameters parameters) - { - var gacs = new [] { "GAC_MSIL", "GAC_32", "GAC" }; - var prefixes = new [] { string.Empty, "v4.0_" }; - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < gacs.Length; j++) { - var gac = Path.Combine (gac_paths [i], gacs [j]); - var file = GetAssemblyFile (reference, prefixes [i], gac); - if (Directory.Exists (gac) && File.Exists (file)) - return GetAssembly (file, parameters); - } - } - - return null; - } - - static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac) - { - var gac_folder = new StringBuilder () - .Append (prefix) - .Append (reference.Version) - .Append ("__"); - - for (int i = 0; i < reference.PublicKeyToken.Length; i++) - gac_folder.Append (reference.PublicKeyToken [i].ToString ("x2")); - - return Path.Combine ( - Path.Combine ( - Path.Combine (gac, reference.Name), gac_folder.ToString ()), - reference.Name + ".dll"); - } -#endif - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/CallSite.cs b/mcs/class/Mono.Cecil/Mono.Cecil/CallSite.cs deleted file mode 100644 index 2d4ed417598..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/CallSite.cs +++ /dev/null @@ -1,124 +0,0 @@ -// -// CallSite.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class CallSite : IMethodSignature { - - readonly MethodReference signature; - - public bool HasThis { - get { return signature.HasThis; } - set { signature.HasThis = value; } - } - - public bool ExplicitThis { - get { return signature.ExplicitThis; } - set { signature.ExplicitThis = value; } - } - - public MethodCallingConvention CallingConvention { - get { return signature.CallingConvention; } - set { signature.CallingConvention = value; } - } - - public bool HasParameters { - get { return signature.HasParameters; } - } - - public Collection Parameters { - get { return signature.Parameters; } - } - - public TypeReference ReturnType { - get { return signature.MethodReturnType.ReturnType; } - set { signature.MethodReturnType.ReturnType = value; } - } - - public MethodReturnType MethodReturnType { - get { return signature.MethodReturnType; } - } - - public string Name { - get { return string.Empty; } - set { throw new InvalidOperationException (); } - } - - public string Namespace { - get { return string.Empty; } - set { throw new InvalidOperationException (); } - } - - public ModuleDefinition Module { - get { return ReturnType.Module; } - } - - public IMetadataScope Scope { - get { return signature.ReturnType.Scope; } - } - - public MetadataToken MetadataToken { - get { return signature.token; } - set { signature.token = value; } - } - - public string FullName { - get { - var signature = new StringBuilder (); - signature.Append (ReturnType.FullName); - this.MethodSignatureFullName (signature); - return signature.ToString (); - } - } - - internal CallSite () - { - this.signature = new MethodReference (); - this.signature.token = new MetadataToken (TokenType.Signature, 0); - } - - public CallSite (TypeReference returnType) - : this () - { - if (returnType == null) - throw new ArgumentNullException ("returnType"); - - this.signature.ReturnType = returnType; - } - - public override string ToString () - { - return FullName; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/CustomAttribute.cs b/mcs/class/Mono.Cecil/Mono.Cecil/CustomAttribute.cs deleted file mode 100644 index 76372db0ee2..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/CustomAttribute.cs +++ /dev/null @@ -1,232 +0,0 @@ -// -// CustomAttribute.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public struct CustomAttributeArgument { - - readonly TypeReference type; - readonly object value; - - public TypeReference Type { - get { return type; } - } - - public object Value { - get { return value; } - } - - public CustomAttributeArgument (TypeReference type, object value) - { - Mixin.CheckType (type); - this.type = type; - this.value = value; - } - } - - public struct CustomAttributeNamedArgument { - - readonly string name; - readonly CustomAttributeArgument argument; - - public string Name { - get { return name; } - } - - public CustomAttributeArgument Argument { - get { return argument; } - } - - public CustomAttributeNamedArgument (string name, CustomAttributeArgument argument) - { - Mixin.CheckName (name); - this.name = name; - this.argument = argument; - } - } - - public interface ICustomAttribute { - - TypeReference AttributeType { get; } - - bool HasFields { get; } - bool HasProperties { get; } - Collection Fields { get; } - Collection Properties { get; } - } - - public sealed class CustomAttribute : ICustomAttribute { - - readonly internal uint signature; - internal bool resolved; - MethodReference constructor; - byte [] blob; - internal Collection arguments; - internal Collection fields; - internal Collection properties; - - public MethodReference Constructor { - get { return constructor; } - set { constructor = value; } - } - - public TypeReference AttributeType { - get { return constructor.DeclaringType; } - } - - public bool IsResolved { - get { return resolved; } - } - - public bool HasConstructorArguments { - get { - Resolve (); - - return !arguments.IsNullOrEmpty (); - } - } - - public Collection ConstructorArguments { - get { - Resolve (); - - return arguments ?? (arguments = new Collection ()); - } - } - - public bool HasFields { - get { - Resolve (); - - return !fields.IsNullOrEmpty (); - } - } - - public Collection Fields { - get { - Resolve (); - - return fields ?? (fields = new Collection ()); - } - } - - public bool HasProperties { - get { - Resolve (); - - return !properties.IsNullOrEmpty (); - } - } - - public Collection Properties { - get { - Resolve (); - - return properties ?? (properties = new Collection ()); - } - } - - internal bool HasImage { - get { return constructor != null && constructor.HasImage; } - } - - internal ModuleDefinition Module { - get { return constructor.Module; } - } - - internal CustomAttribute (uint signature, MethodReference constructor) - { - this.signature = signature; - this.constructor = constructor; - this.resolved = false; - } - - public CustomAttribute (MethodReference constructor) - { - this.constructor = constructor; - this.resolved = true; - } - - public CustomAttribute (MethodReference constructor, byte [] blob) - { - this.constructor = constructor; - this.resolved = false; - this.blob = blob; - } - - public byte [] GetBlob () - { - if (blob != null) - return blob; - - if (!HasImage) - throw new NotSupportedException (); - - return blob = Module.Read (this, (attribute, reader) => reader.ReadCustomAttributeBlob (attribute.signature)); - } - - void Resolve () - { - if (resolved || !HasImage) - return; - - try { - Module.Read (this, (attribute, reader) => { - reader.ReadCustomAttributeSignature (attribute); - return this; - }); - - resolved = true; - } catch (ResolutionException) { - if (arguments != null) - arguments.Clear (); - if (fields != null) - fields.Clear (); - if (properties != null) - properties.Clear (); - - resolved = false; - } - } - } - - static partial class Mixin { - - public static void CheckName (string name) - { - if (name == null) - throw new ArgumentNullException ("name"); - if (name.Length == 0) - throw new ArgumentException ("Empty name"); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs b/mcs/class/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs deleted file mode 100644 index a9faa214205..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// DefaultAssemblyResolver.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; - -namespace Mono.Cecil { - - public static class GlobalAssemblyResolver { - - public static readonly IAssemblyResolver Instance = new DefaultAssemblyResolver (); - } - - public class DefaultAssemblyResolver : BaseAssemblyResolver { - - readonly IDictionary cache; - - public DefaultAssemblyResolver () - { - cache = new Dictionary (StringComparer.Ordinal); - } - - public override AssemblyDefinition Resolve (AssemblyNameReference name) - { - if (name == null) - throw new ArgumentNullException ("name"); - - AssemblyDefinition assembly; - if (cache.TryGetValue (name.FullName, out assembly)) - return assembly; - - assembly = base.Resolve (name); - cache [name.FullName] = assembly; - - return assembly; - } - - protected void RegisterAssembly (AssemblyDefinition assembly) - { - if (assembly == null) - throw new ArgumentNullException ("assembly"); - - var name = assembly.Name.FullName; - if (cache.ContainsKey (name)) - return; - - cache [name] = assembly; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs b/mcs/class/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs deleted file mode 100644 index e12dd0b3789..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs +++ /dev/null @@ -1,105 +0,0 @@ -// -// EmbeddedResource.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -namespace Mono.Cecil { - - public sealed class EmbeddedResource : Resource { - - readonly MetadataReader reader; - - uint? offset; - byte [] data; - Stream stream; - - public override ResourceType ResourceType { - get { return ResourceType.Embedded; } - } - - public EmbeddedResource (string name, ManifestResourceAttributes attributes, byte [] data) : - base (name, attributes) - { - this.data = data; - } - - public EmbeddedResource (string name, ManifestResourceAttributes attributes, Stream stream) : - base (name, attributes) - { - this.stream = stream; - } - - internal EmbeddedResource (string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader) - : base (name, attributes) - { - this.offset = offset; - this.reader = reader; - } - - public Stream GetResourceStream () - { - if (stream != null) - return stream; - - if (data != null) - return new MemoryStream (data); - - if (offset.HasValue) - return reader.GetManagedResourceStream (offset.Value); - - throw new InvalidOperationException (); - } - - public byte [] GetResourceData () - { - if (stream != null) - return ReadStream (stream); - - if (data != null) - return data; - - if (offset.HasValue) - return reader.GetManagedResourceStream (offset.Value).ToArray (); - - throw new InvalidOperationException (); - } - - static byte [] ReadStream (Stream stream) - { - var length = (int) stream.Length; - var data = new byte [length]; - int offset = 0, read; - - while ((read = stream.Read (data, offset, length - offset)) > 0) - offset += read; - - return data; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/EventAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/EventAttributes.cs deleted file mode 100644 index 815efa57b7f..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/EventAttributes.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// EventAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum EventAttributes : ushort { - None = 0x0000, - SpecialName = 0x0200, // Event is special - RTSpecialName = 0x0400 // CLI provides 'special' behavior, depending upon the name of the event - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/EventDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/EventDefinition.cs deleted file mode 100644 index 565186c5d78..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/EventDefinition.cs +++ /dev/null @@ -1,168 +0,0 @@ -// -// EventDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class EventDefinition : EventReference, IMemberDefinition { - - ushort attributes; - - Collection custom_attributes; - - internal MethodDefinition add_method; - internal MethodDefinition invoke_method; - internal MethodDefinition remove_method; - internal Collection other_methods; - - public EventAttributes Attributes { - get { return (EventAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public MethodDefinition AddMethod { - get { - if (add_method != null) - return add_method; - - InitializeMethods (); - return add_method; - } - set { add_method = value; } - } - - public MethodDefinition InvokeMethod { - get { - if (invoke_method != null) - return invoke_method; - - InitializeMethods (); - return invoke_method; - } - set { invoke_method = value; } - } - - public MethodDefinition RemoveMethod { - get { - if (remove_method != null) - return remove_method; - - InitializeMethods (); - return remove_method; - } - set { remove_method = value; } - } - - public bool HasOtherMethods { - get { - if (other_methods != null) - return other_methods.Count > 0; - - InitializeMethods (); - return !other_methods.IsNullOrEmpty (); - } - } - - public Collection OtherMethods { - get { - if (other_methods != null) - return other_methods; - - InitializeMethods (); - - if (other_methods != null) - return other_methods; - - return other_methods = new Collection (); - } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); } - } - - #region EventAttributes - - public bool IsSpecialName { - get { return attributes.GetAttributes ((ushort) EventAttributes.SpecialName); } - set { attributes = attributes.SetAttributes ((ushort) EventAttributes.SpecialName, value); } - } - - public bool IsRuntimeSpecialName { - get { return attributes.GetAttributes ((ushort) FieldAttributes.RTSpecialName); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.RTSpecialName, value); } - } - - #endregion - - public new TypeDefinition DeclaringType { - get { return (TypeDefinition) base.DeclaringType; } - set { base.DeclaringType = value; } - } - - public override bool IsDefinition { - get { return true; } - } - - public EventDefinition (string name, EventAttributes attributes, TypeReference eventType) - : base (name, eventType) - { - this.attributes = (ushort) attributes; - this.token = new MetadataToken (TokenType.Event); - } - - void InitializeMethods () - { - if (add_method != null - || invoke_method != null - || remove_method != null) - return; - - var module = this.Module; - if (!module.HasImage ()) - return; - - module.Read (this, (@event, reader) => reader.ReadMethods (@event)); - } - - public override EventDefinition Resolve () - { - return this; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/EventReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/EventReference.cs deleted file mode 100644 index 8952002d6c2..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/EventReference.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// EventReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public abstract class EventReference : MemberReference { - - TypeReference event_type; - - public TypeReference EventType { - get { return event_type; } - set { event_type = value; } - } - - public override string FullName { - get { return event_type.FullName + " " + MemberFullName (); } - } - - protected EventReference (string name, TypeReference eventType) - : base (name) - { - if (eventType == null) - throw new ArgumentNullException ("eventType"); - - event_type = eventType; - } - - public abstract EventDefinition Resolve (); - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ExportedType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ExportedType.cs deleted file mode 100644 index c25f8d05eac..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ExportedType.cs +++ /dev/null @@ -1,249 +0,0 @@ -// -// ExportedType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public class ExportedType : IMetadataTokenProvider { - - string @namespace; - string name; - uint attributes; - IMetadataScope scope; - ModuleDefinition module; - int identifier; - ExportedType declaring_type; - internal MetadataToken token; - - public string Namespace { - get { return @namespace; } - set { @namespace = value; } - } - - public string Name { - get { return name; } - set { name = value; } - } - - public TypeAttributes Attributes { - get { return (TypeAttributes) attributes; } - set { attributes = (uint) value; } - } - - public IMetadataScope Scope { - get { - if (declaring_type != null) - return declaring_type.Scope; - - return scope; - } - } - - public ExportedType DeclaringType { - get { return declaring_type; } - set { declaring_type = value; } - } - - public MetadataToken MetadataToken { - get { return token; } - set { token = value; } - } - - public int Identifier { - get { return identifier; } - set { identifier = value; } - } - - #region TypeAttributes - - public bool IsNotPublic { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic, value); } - } - - public bool IsPublic { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public, value); } - } - - public bool IsNestedPublic { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic, value); } - } - - public bool IsNestedPrivate { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate, value); } - } - - public bool IsNestedFamily { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily, value); } - } - - public bool IsNestedAssembly { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly, value); } - } - - public bool IsNestedFamilyAndAssembly { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem, value); } - } - - public bool IsNestedFamilyOrAssembly { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem, value); } - } - - public bool IsAutoLayout { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout, value); } - } - - public bool IsSequentialLayout { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout, value); } - } - - public bool IsExplicitLayout { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout, value); } - } - - public bool IsClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class, value); } - } - - public bool IsInterface { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface, value); } - } - - public bool IsAbstract { - get { return attributes.GetAttributes ((uint) TypeAttributes.Abstract); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Abstract, value); } - } - - public bool IsSealed { - get { return attributes.GetAttributes ((uint) TypeAttributes.Sealed); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Sealed, value); } - } - - public bool IsSpecialName { - get { return attributes.GetAttributes ((uint) TypeAttributes.SpecialName); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.SpecialName, value); } - } - - public bool IsImport { - get { return attributes.GetAttributes ((uint) TypeAttributes.Import); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Import, value); } - } - - public bool IsSerializable { - get { return attributes.GetAttributes ((uint) TypeAttributes.Serializable); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Serializable, value); } - } - - public bool IsAnsiClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass, value); } - } - - public bool IsUnicodeClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass, value); } - } - - public bool IsAutoClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass, value); } - } - - public bool IsBeforeFieldInit { - get { return attributes.GetAttributes ((uint) TypeAttributes.BeforeFieldInit); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.BeforeFieldInit, value); } - } - - public bool IsRuntimeSpecialName { - get { return attributes.GetAttributes ((uint) TypeAttributes.RTSpecialName); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.RTSpecialName, value); } - } - - public bool HasSecurity { - get { return attributes.GetAttributes ((uint) TypeAttributes.HasSecurity); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.HasSecurity, value); } - } - - #endregion - - public bool IsForwarder { - get { return attributes.GetAttributes ((uint) TypeAttributes.Forwarder); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Forwarder, value); } - } - - public string FullName { - get { - if (declaring_type != null) - return declaring_type.FullName + "/" + name; - - if (string.IsNullOrEmpty (@namespace)) - return name; - - return @namespace + "." + name; - } - } - - public ExportedType (string @namespace, string name, ModuleDefinition module, IMetadataScope scope) - { - this.@namespace = @namespace; - this.name = name; - this.scope = scope; - this.module = module; - } - - public override string ToString () - { - return FullName; - } - - public TypeDefinition Resolve () - { - return module.Resolve (CreateReference ()); - } - - internal TypeReference CreateReference () - { - return new TypeReference (@namespace, name, module, scope) { - DeclaringType = declaring_type != null ? declaring_type.CreateReference () : null, - }; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/FieldAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/FieldAttributes.cs deleted file mode 100644 index dd6bf361dc1..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/FieldAttributes.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// FieldAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum FieldAttributes : ushort { - FieldAccessMask = 0x0007, - CompilerControlled = 0x0000, // Member not referenceable - Private = 0x0001, // Accessible only by the parent type - FamANDAssem = 0x0002, // Accessible by sub-types only in this assembly - Assembly = 0x0003, // Accessible by anyone in the Assembly - Family = 0x0004, // Accessible only by type and sub-types - FamORAssem = 0x0005, // Accessible by sub-types anywhere, plus anyone in the assembly - Public = 0x0006, // Accessible by anyone who has visibility to this scope field contract attributes - - Static = 0x0010, // Defined on type, else per instance - InitOnly = 0x0020, // Field may only be initialized, not written after init - Literal = 0x0040, // Value is compile time constant - NotSerialized = 0x0080, // Field does not have to be serialized when type is remoted - SpecialName = 0x0200, // Field is special - - // Interop Attributes - PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke - - // Additional flags - RTSpecialName = 0x0400, // CLI provides 'special' behavior, depending upon the name of the field - HasFieldMarshal = 0x1000, // Field has marshalling information - HasDefault = 0x8000, // Field has default - HasFieldRVA = 0x0100 // Field has RVA - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/FieldDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/FieldDefinition.cs deleted file mode 100644 index 29a1bc12cef..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/FieldDefinition.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -// FieldDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class FieldDefinition : FieldReference, IMemberDefinition, IConstantProvider, IMarshalInfoProvider { - - ushort attributes; - Collection custom_attributes; - - int offset = Mixin.NotResolvedMarker; - - internal int rva = Mixin.NotResolvedMarker; - byte [] initial_value; - - object constant = Mixin.NotResolved; - - MarshalInfo marshal_info; - - void ResolveLayout () - { - if (offset != Mixin.NotResolvedMarker) - return; - - if (!HasImage) { - offset = Mixin.NoDataMarker; - return; - } - - offset = Module.Read (this, (field, reader) => reader.ReadFieldLayout (field)); - } - - public bool HasLayoutInfo { - get { - if (offset >= 0) - return true; - - ResolveLayout (); - - return offset >= 0; - } - } - - public int Offset { - get { - if (offset >= 0) - return offset; - - ResolveLayout (); - - return offset >= 0 ? offset : -1; - } - set { offset = value; } - } - - void ResolveRVA () - { - if (rva != Mixin.NotResolvedMarker) - return; - - if (!HasImage) - return; - - rva = Module.Read (this, (field, reader) => reader.ReadFieldRVA (field)); - } - - public int RVA { - get { - if (rva > 0) - return rva; - - ResolveRVA (); - - return rva > 0 ? rva : 0; - } - } - - public byte [] InitialValue { - get { - if (initial_value != null) - return initial_value; - - ResolveRVA (); - - if (initial_value == null) - initial_value = Empty.Array; - - return initial_value; - } - set { initial_value = value; } - } - - public FieldAttributes Attributes { - get { return (FieldAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public bool HasConstant { - get { - ResolveConstant (); - - return constant != Mixin.NoValue; - } - set { if (!value) constant = Mixin.NoValue; } - } - - public object Constant { - get { return HasConstant ? constant : null; } - set { constant = value; } - } - - void ResolveConstant () - { - if (constant != Mixin.NotResolved) - return; - - this.ResolveConstant (ref constant, Module); - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); } - } - - public bool HasMarshalInfo { - get { - if (marshal_info != null) - return true; - - return this.GetHasMarshalInfo (Module); - } - } - - public MarshalInfo MarshalInfo { - get { return marshal_info ?? (marshal_info = this.GetMarshalInfo (Module)); } - set { marshal_info = value; } - } - - #region FieldAttributes - - public bool IsCompilerControlled { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.CompilerControlled); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.CompilerControlled, value); } - } - - public bool IsPrivate { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Private); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Private, value); } - } - - public bool IsFamilyAndAssembly { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamANDAssem); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamANDAssem, value); } - } - - public bool IsAssembly { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Assembly); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Assembly, value); } - } - - public bool IsFamily { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Family); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Family, value); } - } - - public bool IsFamilyOrAssembly { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamORAssem); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamORAssem, value); } - } - - public bool IsPublic { - get { return attributes.GetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Public); } - set { attributes = attributes.SetMaskedAttributes ((ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Public, value); } - } - - public bool IsStatic { - get { return attributes.GetAttributes ((ushort) FieldAttributes.Static); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.Static, value); } - } - - public bool IsInitOnly { - get { return attributes.GetAttributes ((ushort) FieldAttributes.InitOnly); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.InitOnly, value); } - } - - public bool IsLiteral { - get { return attributes.GetAttributes ((ushort) FieldAttributes.Literal); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.Literal, value); } - } - - public bool IsNotSerialized { - get { return attributes.GetAttributes ((ushort) FieldAttributes.NotSerialized); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.NotSerialized, value); } - } - - public bool IsSpecialName { - get { return attributes.GetAttributes ((ushort) FieldAttributes.SpecialName); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.SpecialName, value); } - } - - public bool IsPInvokeImpl { - get { return attributes.GetAttributes ((ushort) FieldAttributes.PInvokeImpl); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.PInvokeImpl, value); } - } - - public bool IsRuntimeSpecialName { - get { return attributes.GetAttributes ((ushort) FieldAttributes.RTSpecialName); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.RTSpecialName, value); } - } - - public bool HasDefault { - get { return attributes.GetAttributes ((ushort) FieldAttributes.HasDefault); } - set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.HasDefault, value); } - } - - #endregion - - public override bool IsDefinition { - get { return true; } - } - - public new TypeDefinition DeclaringType { - get { return (TypeDefinition) base.DeclaringType; } - set { base.DeclaringType = value; } - } - - public FieldDefinition (string name, FieldAttributes attributes, TypeReference fieldType) - : base (name, fieldType) - { - this.attributes = (ushort) attributes; - } - - public override FieldDefinition Resolve () - { - return this; - } - } - - static partial class Mixin { - - public const int NotResolvedMarker = -2; - public const int NoDataMarker = -1; - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/FieldReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/FieldReference.cs deleted file mode 100644 index be58d3d0630..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/FieldReference.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// FieldReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public class FieldReference : MemberReference { - - TypeReference field_type; - - public TypeReference FieldType { - get { return field_type; } - set { field_type = value; } - } - - public override string FullName { - get { return field_type.FullName + " " + MemberFullName (); } - } - - internal override bool ContainsGenericParameter { - get { return field_type.ContainsGenericParameter || base.ContainsGenericParameter; } - } - - internal FieldReference () - { - this.token = new MetadataToken (TokenType.MemberRef); - } - - public FieldReference (string name, TypeReference fieldType) - : base (name) - { - if (fieldType == null) - throw new ArgumentNullException ("fieldType"); - - this.field_type = fieldType; - this.token = new MetadataToken (TokenType.MemberRef); - } - - public FieldReference (string name, TypeReference fieldType, TypeReference declaringType) - : this (name, fieldType) - { - if (declaringType == null) - throw new ArgumentNullException("declaringType"); - - this.DeclaringType = declaringType; - } - - public virtual FieldDefinition Resolve () - { - var module = this.Module; - if (module == null) - throw new NotSupportedException (); - - return module.Resolve (this); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/FileAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/FileAttributes.cs deleted file mode 100644 index 4d3b6ca7ff7..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/FileAttributes.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// FileAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - enum FileAttributes : uint { - ContainsMetaData = 0x0000, // This is not a resource file - ContainsNoMetaData = 0x0001, // This is a resource file or other non-metadata-containing file - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs deleted file mode 100644 index db80f76215e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs +++ /dev/null @@ -1,128 +0,0 @@ -// -// FunctionPointerType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; -using Mono.Collections.Generic; -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class FunctionPointerType : TypeSpecification, IMethodSignature { - - readonly MethodReference function; - - public bool HasThis { - get { return function.HasThis; } - set { function.HasThis = value; } - } - - public bool ExplicitThis { - get { return function.ExplicitThis; } - set { function.ExplicitThis = value; } - } - - public MethodCallingConvention CallingConvention { - get { return function.CallingConvention; } - set { function.CallingConvention = value; } - } - - public bool HasParameters { - get { return function.HasParameters; } - } - - public Collection Parameters { - get { return function.Parameters; } - } - - public TypeReference ReturnType { - get { return function.MethodReturnType.ReturnType; } - set { function.MethodReturnType.ReturnType = value; } - } - - public MethodReturnType MethodReturnType { - get { return function.MethodReturnType; } - } - - public override string Name { - get { return function.Name; } - set { throw new InvalidOperationException (); } - } - - public override string Namespace { - get { return string.Empty; } - set { throw new InvalidOperationException (); } - } - - public override ModuleDefinition Module { - get { return ReturnType.Module; } - } - - public override IMetadataScope Scope { - get { return function.ReturnType.Scope; } - } - - public override bool IsFunctionPointer { - get { return true; } - } - - internal override bool ContainsGenericParameter { - get { return function.ContainsGenericParameter; } - } - - public override string FullName { - get { - var signature = new StringBuilder (); - signature.Append (function.Name); - signature.Append (" "); - signature.Append (function.ReturnType.FullName); - signature.Append (" *"); - this.MethodSignatureFullName (signature); - return signature.ToString (); - } - } - - public FunctionPointerType () - : base (null) - { - this.function = new MethodReference (); - this.function.Name = "method"; - this.etype = MD.ElementType.FnPtr; - } - - public override TypeDefinition Resolve () - { - return null; - } - - public override TypeReference GetElementType () - { - return this; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs b/mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs deleted file mode 100644 index dbe720df560..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -// GenericInstanceMethod.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class GenericInstanceMethod : MethodSpecification, IGenericInstance, IGenericContext { - - Collection arguments; - - public bool HasGenericArguments { - get { return !arguments.IsNullOrEmpty (); } - } - - public Collection GenericArguments { - get { return arguments ?? (arguments = new Collection ()); } - } - - public override bool IsGenericInstance { - get { return true; } - } - - IGenericParameterProvider IGenericContext.Method { - get { return ElementMethod; } - } - - IGenericParameterProvider IGenericContext.Type { - get { return ElementMethod.DeclaringType; } - } - - internal override bool ContainsGenericParameter { - get { return this.ContainsGenericParameter () || base.ContainsGenericParameter; } - } - - public override string FullName { - get { - var signature = new StringBuilder (); - var method = this.ElementMethod; - signature.Append (method.ReturnType.FullName) - .Append (" ") - .Append (method.DeclaringType.FullName) - .Append ("::") - .Append (method.Name); - this.GenericInstanceFullName (signature); - this.MethodSignatureFullName (signature); - return signature.ToString (); - - } - } - - public GenericInstanceMethod (MethodReference method) - : base (method) - { - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs deleted file mode 100644 index 6554ff0e89c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// GenericInstanceType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; - -using Mono.Collections.Generic; - -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class GenericInstanceType : TypeSpecification, IGenericInstance, IGenericContext { - - Collection arguments; - - public bool HasGenericArguments { - get { return !arguments.IsNullOrEmpty (); } - } - - public Collection GenericArguments { - get { return arguments ?? (arguments = new Collection ()); } - } - - public override TypeReference DeclaringType { - get { return ElementType.DeclaringType; } - set { throw new NotSupportedException (); } - } - - public override string FullName { - get { - var name = new StringBuilder (); - name.Append (base.FullName); - this.GenericInstanceFullName (name); - return name.ToString (); - } - } - - public override bool IsGenericInstance { - get { return true; } - } - - internal override bool ContainsGenericParameter { - get { return this.ContainsGenericParameter () || base.ContainsGenericParameter; } - } - - IGenericParameterProvider IGenericContext.Type { - get { return ElementType; } - } - - public GenericInstanceType (TypeReference type) - : base (type) - { - base.IsValueType = type.IsValueType; - this.etype = MD.ElementType.GenericInst; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/GenericParameter.cs b/mcs/class/Mono.Cecil/Mono.Cecil/GenericParameter.cs deleted file mode 100644 index d694e296d77..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/GenericParameter.cs +++ /dev/null @@ -1,277 +0,0 @@ -// -// GenericParameter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class GenericParameter : TypeReference, ICustomAttributeProvider { - - internal int position; - internal GenericParameterType type; - internal IGenericParameterProvider owner; - - ushort attributes; - Collection constraints; - Collection custom_attributes; - - public GenericParameterAttributes Attributes { - get { return (GenericParameterAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public int Position { - get { return position; } - } - - public GenericParameterType Type { - get { return type; } - } - - public IGenericParameterProvider Owner { - get { return owner; } - } - - public bool HasConstraints { - get { - if (constraints != null) - return constraints.Count > 0; - - if (HasImage) - return Module.Read (this, (generic_parameter, reader) => reader.HasGenericConstraints (generic_parameter)); - - return false; - } - } - - public Collection Constraints { - get { - if (constraints != null) - return constraints; - - if (HasImage) - return constraints = Module.Read (this, (generic_parameter, reader) => reader.ReadGenericConstraints (generic_parameter)); - - return constraints = new Collection (); - } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); } - } - - public override IMetadataScope Scope { - get { - if (owner == null) - return null; - - return owner.GenericParameterType == GenericParameterType.Method - ? ((MethodReference) owner).DeclaringType.Scope - : ((TypeReference) owner).Scope; - } - } - - public override ModuleDefinition Module { - get { return module ?? owner.Module; } - } - - public override string Name { - get { - if (!string.IsNullOrEmpty (base.Name)) - return base.Name; - - return base.Name = (type == GenericParameterType.Method ? "!!" : "!") + position; - } - } - - public override string Namespace { - get { return string.Empty; } - set { throw new InvalidOperationException (); } - } - - public override string FullName { - get { return Name; } - } - - public override bool IsGenericParameter { - get { return true; } - } - - internal override bool ContainsGenericParameter { - get { return true; } - } - - public override MetadataType MetadataType { - get { return (MetadataType) etype; } - } - - #region GenericParameterAttributes - - public bool IsNonVariant { - get { return attributes.GetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.NonVariant); } - set { attributes = attributes.SetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.NonVariant, value); } - } - - public bool IsCovariant { - get { return attributes.GetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Covariant); } - set { attributes = attributes.SetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Covariant, value); } - } - - public bool IsContravariant { - get { return attributes.GetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Contravariant); } - set { attributes = attributes.SetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Contravariant, value); } - } - - public bool HasReferenceTypeConstraint { - get { return attributes.GetAttributes ((ushort) GenericParameterAttributes.ReferenceTypeConstraint); } - set { attributes = attributes.SetAttributes ((ushort) GenericParameterAttributes.ReferenceTypeConstraint, value); } - } - - public bool HasNotNullableValueTypeConstraint { - get { return attributes.GetAttributes ((ushort) GenericParameterAttributes.NotNullableValueTypeConstraint); } - set { attributes = attributes.SetAttributes ((ushort) GenericParameterAttributes.NotNullableValueTypeConstraint, value); } - } - - public bool HasDefaultConstructorConstraint { - get { return attributes.GetAttributes ((ushort) GenericParameterAttributes.DefaultConstructorConstraint); } - set { attributes = attributes.SetAttributes ((ushort) GenericParameterAttributes.DefaultConstructorConstraint, value); } - } - - #endregion - - public GenericParameter (IGenericParameterProvider owner) - : this (string.Empty, owner) - { - } - - public GenericParameter (string name, IGenericParameterProvider owner) - : base (string.Empty, name) - { - if (owner == null) - throw new ArgumentNullException (); - - this.position = -1; - this.owner = owner; - 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 () - { - return null; - } - } - - sealed class GenericParameterCollection : Collection { - - 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; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs deleted file mode 100644 index 6d77956de39..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// GenericParameterAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum GenericParameterAttributes : ushort { - VarianceMask = 0x0003, - NonVariant = 0x0000, - Covariant = 0x0001, - Contravariant = 0x0002, - - SpecialConstraintMask = 0x001c, - ReferenceTypeConstraint = 0x0004, - NotNullableValueTypeConstraint = 0x0008, - DefaultConstructorConstraint = 0x0010 - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IConstantProvider.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IConstantProvider.cs deleted file mode 100644 index 8bcd7d7f02e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IConstantProvider.cs +++ /dev/null @@ -1,52 +0,0 @@ -// -// IConstantProvider.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public interface IConstantProvider : IMetadataTokenProvider { - - bool HasConstant { get; set; } - object Constant { get; set; } - } - - static partial class Mixin { - - internal static object NoValue = new object (); - internal static object NotResolved = new object (); - - public static void ResolveConstant ( - this IConstantProvider self, - ref object constant, - ModuleDefinition module) - { - constant = module.HasImage () - ? module.Read (self, (provider, reader) => reader.ReadConstant (provider)) - : Mixin.NoValue; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs deleted file mode 100644 index 916ba0f5415..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// ICustomAttributeProvider.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public interface ICustomAttributeProvider : IMetadataTokenProvider { - - Collection CustomAttributes { get; } - - bool HasCustomAttributes { get; } - } - - static partial class Mixin { - - public static bool GetHasCustomAttributes ( - this ICustomAttributeProvider self, - ModuleDefinition module) - { - return module.HasImage () && module.Read (self, (provider, reader) => reader.HasCustomAttributes (provider)); - } - - public static Collection GetCustomAttributes ( - this ICustomAttributeProvider self, - ModuleDefinition module) - { - return module.HasImage () - ? module.Read (self, (provider, reader) => reader.ReadCustomAttributes (provider)) - : new Collection (); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IGenericInstance.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IGenericInstance.cs deleted file mode 100644 index edc406ca10a..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IGenericInstance.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -// IGenericInstance.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public interface IGenericInstance : IMetadataTokenProvider { - - bool HasGenericArguments { get; } - Collection GenericArguments { get; } - } - - static partial class Mixin { - - public static bool ContainsGenericParameter (this IGenericInstance self) - { - var arguments = self.GenericArguments; - - for (int i = 0; i < arguments.Count; i++) - if (arguments [i].ContainsGenericParameter) - return true; - - return false; - } - - public static void GenericInstanceFullName (this IGenericInstance self, StringBuilder builder) - { - builder.Append ("<"); - var arguments = self.GenericArguments; - for (int i = 0; i < arguments.Count; i++) { - if (i > 0) - builder.Append (","); - builder.Append (arguments [i].FullName); - } - builder.Append (">"); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs deleted file mode 100644 index d41b7f6d08e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// IGenericParameterProvider.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public interface IGenericParameterProvider : IMetadataTokenProvider { - - bool HasGenericParameters { get; } - bool IsDefinition { get; } - ModuleDefinition Module { get; } - Collection GenericParameters { get; } - GenericParameterType GenericParameterType { get; } - } - - public enum GenericParameterType { - Type, - Method - } - - interface IGenericContext { - - bool IsDefinition { get; } - IGenericParameterProvider Type { get; } - IGenericParameterProvider Method { get; } - } - - static partial class Mixin { - - public static bool GetHasGenericParameters ( - this IGenericParameterProvider self, - ModuleDefinition module) - { - return module.HasImage () && module.Read (self, (provider, reader) => reader.HasGenericParameters (provider)); - } - - public static Collection GetGenericParameters ( - this IGenericParameterProvider self, - ModuleDefinition module) - { - return module.HasImage () - ? module.Read (self, (provider, reader) => reader.ReadGenericParameters (provider)) - : new GenericParameterCollection (self); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs deleted file mode 100644 index 67a53a389f2..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// IMarshalInfoProvider.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public interface IMarshalInfoProvider : IMetadataTokenProvider { - - bool HasMarshalInfo { get; } - MarshalInfo MarshalInfo { get; set; } - } - - static partial class Mixin { - - public static bool GetHasMarshalInfo ( - this IMarshalInfoProvider self, - ModuleDefinition module) - { - return module.HasImage () && module.Read (self, (provider, reader) => reader.HasMarshalInfo (provider)); - } - - public static MarshalInfo GetMarshalInfo ( - this IMarshalInfoProvider self, - ModuleDefinition module) - { - return module.HasImage () - ? module.Read (self, (provider, reader) => reader.ReadMarshalInfo (provider)) - : null; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs deleted file mode 100644 index ee73d9da49b..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs +++ /dev/null @@ -1,100 +0,0 @@ -// -// IMemberDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public interface IMemberDefinition : ICustomAttributeProvider { - - string Name { get; set; } - string FullName { get; } - - bool IsSpecialName { get; set; } - bool IsRuntimeSpecialName { get; set; } - - TypeDefinition DeclaringType { get; set; } - } - - static partial class Mixin { - - public static bool GetAttributes (this uint self, uint attributes) - { - return (self & attributes) != 0; - } - - public static uint SetAttributes (this uint self, uint attributes, bool value) - { - if (value) - return self | attributes; - - return self & ~attributes; - } - - public static bool GetMaskedAttributes (this uint self, uint mask, uint attributes) - { - return (self & mask) == attributes; - } - - public static uint SetMaskedAttributes (this uint self, uint mask, uint attributes, bool value) - { - if (value) { - self &= ~mask; - return self | attributes; - } - - return self & ~(mask & attributes); - } - - public static bool GetAttributes (this ushort self, ushort attributes) - { - return (self & attributes) != 0; - } - - public static ushort SetAttributes (this ushort self, ushort attributes, bool value) - { - if (value) - return (ushort) (self | attributes); - - return (ushort) (self & ~attributes); - } - - public static bool GetMaskedAttributes (this ushort self, ushort mask, uint attributes) - { - return (self & mask) == attributes; - } - - public static ushort SetMaskedAttributes (this ushort self, ushort mask, uint attributes, bool value) - { - if (value) { - self = (ushort) (self & ~mask); - return (ushort) (self | attributes); - } - - return (ushort) (self & ~(mask & attributes)); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IMetadataScope.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IMetadataScope.cs deleted file mode 100644 index 04a0228105c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IMetadataScope.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// IMetadataScope.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum MetadataScopeType { - AssemblyNameReference, - ModuleReference, - ModuleDefinition, - } - - public interface IMetadataScope : IMetadataTokenProvider { - MetadataScopeType MetadataScopeType { get; } - string Name { get; set; } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs deleted file mode 100644 index 6621835b293..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// IMetadataTokenProvider.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public interface IMetadataTokenProvider { - - MetadataToken MetadataToken { get; set; } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/IMethodSignature.cs b/mcs/class/Mono.Cecil/Mono.Cecil/IMethodSignature.cs deleted file mode 100644 index e3d288ba9f0..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/IMethodSignature.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// IMethodSignature.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public interface IMethodSignature : IMetadataTokenProvider { - - bool HasThis { get; set; } - bool ExplicitThis { get; set; } - MethodCallingConvention CallingConvention { get; set; } - - bool HasParameters { get; } - Collection Parameters { get; } - TypeReference ReturnType { get; set; } - MethodReturnType MethodReturnType { get; } - } - - static partial class Mixin { - - public static bool HasImplicitThis (this IMethodSignature self) - { - return self.HasThis && !self.ExplicitThis; - } - - public static void MethodSignatureFullName (this IMethodSignature self, StringBuilder builder) - { - builder.Append ("("); - - if (self.HasParameters) { - var parameters = self.Parameters; - for (int i = 0; i < parameters.Count; i++) { - var parameter = parameters [i]; - if (i > 0) - builder.Append (","); - - if (parameter.ParameterType.IsSentinel) - builder.Append ("...,"); - - builder.Append (parameter.ParameterType.FullName); - } - } - - builder.Append (")"); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/Import.cs b/mcs/class/Mono.Cecil/Mono.Cecil/Import.cs deleted file mode 100644 index 4f3ff25c4e1..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/Import.cs +++ /dev/null @@ -1,566 +0,0 @@ -// -// Import.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using SR = System.Reflection; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - enum ImportGenericKind { - Definition, - Open, - } - - class MetadataImporter { - - readonly ModuleDefinition module; - - public MetadataImporter (ModuleDefinition module) - { - this.module = module; - } - -#if !CF - static readonly Dictionary type_etype_mapping = new Dictionary (18) { - { typeof (void), ElementType.Void }, - { typeof (bool), ElementType.Boolean }, - { typeof (char), ElementType.Char }, - { typeof (sbyte), ElementType.I1 }, - { typeof (byte), ElementType.U1 }, - { typeof (short), ElementType.I2 }, - { typeof (ushort), ElementType.U2 }, - { typeof (int), ElementType.I4 }, - { typeof (uint), ElementType.U4 }, - { typeof (long), ElementType.I8 }, - { typeof (ulong), ElementType.U8 }, - { typeof (float), ElementType.R4 }, - { typeof (double), ElementType.R8 }, - { typeof (string), ElementType.String }, - { typeof (TypedReference), ElementType.TypedByRef }, - { typeof (IntPtr), ElementType.I }, - { typeof (UIntPtr), ElementType.U }, - { typeof (object), ElementType.Object }, - }; - - public TypeReference ImportType (Type type, IGenericContext context) - { - return ImportType (type, context, ImportGenericKind.Open); - } - - public TypeReference ImportType (Type type, IGenericContext context, ImportGenericKind import_kind) - { - if (IsTypeSpecification (type) || ImportOpenGenericType (type, import_kind)) - return ImportTypeSpecification (type, context); - - var reference = new TypeReference ( - string.Empty, - type.Name, - module, - ImportScope (type.Assembly), - type.IsValueType); - - reference.etype = ImportElementType (type); - - if (IsNestedType (type)) - reference.DeclaringType = ImportType (type.DeclaringType, context, import_kind); - else - reference.Namespace = type.Namespace; - - if (type.IsGenericType) - ImportGenericParameters (reference, type.GetGenericArguments ()); - - return reference; - } - - static bool ImportOpenGenericType (Type type, ImportGenericKind import_kind) - { - return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open; - } - - static bool ImportOpenGenericMethod (SR.MethodBase method, ImportGenericKind import_kind) - { - return method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ImportGenericKind.Open; - } - - static bool IsNestedType (Type type) - { -#if !SILVERLIGHT - return type.IsNested; -#else - return type.DeclaringType != null; -#endif - } - - TypeReference ImportTypeSpecification (Type type, IGenericContext context) - { - if (type.IsByRef) - return new ByReferenceType (ImportType (type.GetElementType (), context)); - - if (type.IsPointer) - return new PointerType (ImportType (type.GetElementType (), context)); - - if (type.IsArray) - return new ArrayType (ImportType (type.GetElementType (), context), type.GetArrayRank ()); - - if (type.IsGenericType) - return ImportGenericInstance (type, context); - - if (type.IsGenericParameter) - return ImportGenericParameter (type, context); - - throw new NotSupportedException (type.FullName); - } - - static TypeReference ImportGenericParameter (Type type, IGenericContext context) - { - if (context == null) - throw new InvalidOperationException (); - - var owner = type.DeclaringMethod != null - ? context.Method - : context.Type; - - if (owner == null) - throw new InvalidOperationException (); - - return owner.GenericParameters [type.GenericParameterPosition]; - } - - TypeReference ImportGenericInstance (Type type, IGenericContext context) - { - var element_type = ImportType (type.GetGenericTypeDefinition (), context, ImportGenericKind.Definition); - var instance = new GenericInstanceType (element_type); - var arguments = type.GetGenericArguments (); - var instance_arguments = instance.GenericArguments; - - for (int i = 0; i < arguments.Length; i++) - instance_arguments.Add (ImportType (arguments [i], context ?? element_type)); - - return instance; - } - - static bool IsTypeSpecification (Type type) - { - return type.HasElementType - || IsGenericInstance (type) - || type.IsGenericParameter; - } - - static bool IsGenericInstance (Type type) - { - return type.IsGenericType && !type.IsGenericTypeDefinition; - } - - static ElementType ImportElementType (Type type) - { - ElementType etype; - if (!type_etype_mapping.TryGetValue (type, out etype)) - return ElementType.None; - - return etype; - } - - AssemblyNameReference ImportScope (SR.Assembly assembly) - { - AssemblyNameReference scope; -#if !SILVERLIGHT - var name = assembly.GetName (); - - if (TryGetAssemblyNameReference (name, out scope)) - return scope; - - scope = new AssemblyNameReference (name.Name, name.Version) { - Culture = name.CultureInfo.Name, - PublicKeyToken = name.GetPublicKeyToken (), - HashAlgorithm = (AssemblyHashAlgorithm) name.HashAlgorithm, - }; - - module.AssemblyReferences.Add (scope); - - return scope; -#else - var name = AssemblyNameReference.Parse (assembly.FullName); - - if (TryGetAssemblyNameReference (name, out scope)) - return scope; - - module.AssemblyReferences.Add (name); - - return name; -#endif - } - -#if !SILVERLIGHT - bool TryGetAssemblyNameReference (SR.AssemblyName name, out AssemblyNameReference assembly_reference) - { - var references = module.AssemblyReferences; - - for (int i = 0; i < references.Count; i++) { - var reference = references [i]; - if (name.FullName != reference.FullName) // TODO compare field by field - continue; - - assembly_reference = reference; - return true; - } - - assembly_reference = null; - return false; - } -#endif - - public FieldReference ImportField (SR.FieldInfo field, IGenericContext context) - { - var declaring_type = ImportType (field.DeclaringType, context); - - if (IsGenericInstance (field.DeclaringType)) - field = ResolveFieldDefinition (field); - - return new FieldReference { - Name = field.Name, - DeclaringType = declaring_type, - FieldType = ImportType (field.FieldType, context ?? declaring_type), - }; - } - - static SR.FieldInfo ResolveFieldDefinition (SR.FieldInfo field) - { -#if !SILVERLIGHT - return field.Module.ResolveField (field.MetadataToken); -#else - return field.DeclaringType.GetGenericTypeDefinition ().GetField (field.Name, - SR.BindingFlags.Public - | SR.BindingFlags.NonPublic - | (field.IsStatic ? SR.BindingFlags.Static : SR.BindingFlags.Instance)); -#endif - } - - public MethodReference ImportMethod (SR.MethodBase method, IGenericContext context, ImportGenericKind import_kind) - { - if (IsMethodSpecification (method) || ImportOpenGenericMethod (method, import_kind)) - return ImportMethodSpecification (method, context); - - var declaring_type = ImportType (method.DeclaringType, context); - - if (IsGenericInstance (method.DeclaringType)) - method = method.Module.ResolveMethod (method.MetadataToken); - - var reference = new MethodReference { - Name = method.Name, - HasThis = HasCallingConvention (method, SR.CallingConventions.HasThis), - ExplicitThis = HasCallingConvention (method, SR.CallingConventions.ExplicitThis), - DeclaringType = ImportType (method.DeclaringType, context, ImportGenericKind.Definition), - }; - - if (HasCallingConvention (method, SR.CallingConventions.VarArgs)) - reference.CallingConvention &= MethodCallingConvention.VarArg; - - if (method.IsGenericMethod) - ImportGenericParameters (reference, method.GetGenericArguments ()); - - var method_info = method as SR.MethodInfo; - reference.ReturnType = method_info != null - ? ImportType (method_info.ReturnType, context ?? reference) - : ImportType (typeof (void), null); - - var parameters = method.GetParameters (); - var reference_parameters = reference.Parameters; - - for (int i = 0; i < parameters.Length; i++) - reference_parameters.Add ( - new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference))); - - reference.DeclaringType = declaring_type; - - return reference; - } - - static void ImportGenericParameters (IGenericParameterProvider provider, Type [] arguments) - { - var provider_parameters = provider.GenericParameters; - - for (int i = 0; i < arguments.Length; i++) - provider_parameters.Add (new GenericParameter (arguments [i].Name, provider)); - } - - static bool IsMethodSpecification (SR.MethodBase method) - { - return method.IsGenericMethod && !method.IsGenericMethodDefinition; - } - - MethodReference ImportMethodSpecification (SR.MethodBase method, IGenericContext context) - { - var method_info = method as SR.MethodInfo; - if (method_info == null) - throw new InvalidOperationException (); - - var element_method = ImportMethod (method_info.GetGenericMethodDefinition (), context, ImportGenericKind.Definition); - var instance = new GenericInstanceMethod (element_method); - var arguments = method.GetGenericArguments (); - var instance_arguments = instance.GenericArguments; - - for (int i = 0; i < arguments.Length; i++) - instance_arguments.Add (ImportType (arguments [i], context ?? element_method)); - - return instance; - } - - static bool HasCallingConvention (SR.MethodBase method, SR.CallingConventions conventions) - { - return (method.CallingConvention & conventions) != 0; - } -#endif - - public TypeReference ImportType (TypeReference type, IGenericContext context) - { - if (type.IsTypeSpecification ()) - return ImportTypeSpecification (type, context); - - var reference = new TypeReference ( - type.Namespace, - type.Name, - module, - ImportScope (type.Scope), - type.IsValueType); - - MetadataSystem.TryProcessPrimitiveTypeReference (reference); - - if (type.IsNested) - reference.DeclaringType = ImportType (type.DeclaringType, context); - - if (type.HasGenericParameters) - ImportGenericParameters (reference, type); - - return reference; - } - - IMetadataScope ImportScope (IMetadataScope scope) - { - switch (scope.MetadataScopeType) { - case MetadataScopeType.AssemblyNameReference: - return ImportAssemblyName ((AssemblyNameReference) scope); - case MetadataScopeType.ModuleDefinition: - return ImportAssemblyName (((ModuleDefinition) scope).Assembly.Name); - case MetadataScopeType.ModuleReference: - throw new NotImplementedException (); - } - - throw new NotSupportedException (); - } - - AssemblyNameReference ImportAssemblyName (AssemblyNameReference name) - { - AssemblyNameReference reference; - if (TryGetAssemblyNameReference (name, out reference)) - return reference; - - reference = new AssemblyNameReference (name.Name, name.Version) { - Culture = name.Culture, - HashAlgorithm = name.HashAlgorithm, - }; - - var pk_token = !name.PublicKeyToken.IsNullOrEmpty () - ? new byte [name.PublicKeyToken.Length] - : Empty.Array; - - if (pk_token.Length > 0) - Buffer.BlockCopy (name.PublicKeyToken, 0, pk_token, 0, pk_token.Length); - - reference.PublicKeyToken = pk_token; - - module.AssemblyReferences.Add (reference); - - return reference; - } - - bool TryGetAssemblyNameReference (AssemblyNameReference name_reference, out AssemblyNameReference assembly_reference) - { - var references = module.AssemblyReferences; - - for (int i = 0; i < references.Count; i++) { - var reference = references [i]; - if (name_reference.FullName != reference.FullName) // TODO compare field by field - continue; - - assembly_reference = reference; - return true; - } - - assembly_reference = null; - return false; - } - - static void ImportGenericParameters (IGenericParameterProvider imported, IGenericParameterProvider original) - { - var parameters = original.GenericParameters; - var imported_parameters = imported.GenericParameters; - - for (int i = 0; i < parameters.Count; i++) - imported_parameters.Add (new GenericParameter (parameters [i].Name, imported)); - } - - TypeReference ImportTypeSpecification (TypeReference type, IGenericContext context) - { - switch (type.etype) { - case ElementType.SzArray: - var vector = (ArrayType) type; - return new ArrayType (ImportType (vector.ElementType, context)); - case ElementType.Ptr: - var pointer = (PointerType) type; - return new PointerType (ImportType (pointer.ElementType, context)); - case ElementType.ByRef: - var byref = (ByReferenceType) type; - return new ByReferenceType (ImportType (byref.ElementType, context)); - case ElementType.Pinned: - var pinned = (PinnedType) type; - return new PinnedType (ImportType (pinned.ElementType, context)); - case ElementType.Sentinel: - var sentinel = (SentinelType) type; - return new SentinelType (ImportType (sentinel.ElementType, context)); - case ElementType.CModOpt: - var modopt = (OptionalModifierType) type; - return new OptionalModifierType ( - ImportType (modopt.ModifierType, context), - ImportType (modopt.ElementType, context)); - case ElementType.CModReqD: - var modreq = (RequiredModifierType) type; - return new RequiredModifierType ( - ImportType (modreq.ModifierType, context), - ImportType (modreq.ElementType, context)); - case ElementType.Array: - var array = (ArrayType) type; - var imported_array = new ArrayType (ImportType (array.ElementType, context)); - if (array.IsVector) - return imported_array; - - var dimensions = array.Dimensions; - var imported_dimensions = imported_array.Dimensions; - - imported_dimensions.Clear (); - - for (int i = 0; i < dimensions.Count; i++) { - var dimension = dimensions [i]; - - imported_dimensions.Add (new ArrayDimension (dimension.LowerBound, dimension.UpperBound)); - } - - return imported_array; - case ElementType.GenericInst: - var instance = (GenericInstanceType) type; - var element_type = ImportType (instance.ElementType, context); - var imported_instance = new GenericInstanceType (element_type); - - var arguments = instance.GenericArguments; - var imported_arguments = imported_instance.GenericArguments; - - for (int i = 0; i < arguments.Count; i++) - imported_arguments.Add (ImportType (arguments [i], context)); - - return imported_instance; - case ElementType.Var: - if (context == null || context.Type == null) - throw new InvalidOperationException (); - - return ((TypeReference) context.Type).GetElementType ().GenericParameters [((GenericParameter) type).Position]; - case ElementType.MVar: - if (context == null || context.Method == null) - throw new InvalidOperationException (); - - return context.Method.GenericParameters [((GenericParameter) type).Position]; - } - - throw new NotSupportedException (type.etype.ToString ()); - } - - public FieldReference ImportField (FieldReference field, IGenericContext context) - { - var declaring_type = ImportType (field.DeclaringType, context); - - return new FieldReference { - Name = field.Name, - DeclaringType = declaring_type, - FieldType = ImportType (field.FieldType, context ?? declaring_type), - }; - } - - public MethodReference ImportMethod (MethodReference method, IGenericContext context) - { - if (method.IsGenericInstance) - return ImportMethodSpecification (method, context); - - var declaring_type = ImportType (method.DeclaringType, context); - - var reference = new MethodReference { - Name = method.Name, - HasThis = method.HasThis, - ExplicitThis = method.ExplicitThis, - DeclaringType = declaring_type, - }; - - reference.CallingConvention = method.CallingConvention; - - if (method.HasGenericParameters) - ImportGenericParameters (reference, method); - - reference.ReturnType = ImportType (method.ReturnType, context ?? reference); - - if (!method.HasParameters) - return reference; - - var reference_parameters = reference.Parameters; - - var parameters = method.Parameters; - for (int i = 0; i < parameters.Count; i++) - reference_parameters.Add ( - new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference))); - - return reference; - } - - MethodSpecification ImportMethodSpecification (MethodReference method, IGenericContext context) - { - if (!method.IsGenericInstance) - throw new NotSupportedException (); - - var instance = (GenericInstanceMethod) method; - var element_method = ImportMethod (instance.ElementMethod, context); - var imported_instance = new GenericInstanceMethod (element_method); - - var arguments = instance.GenericArguments; - var imported_arguments = imported_instance.GenericArguments; - - for (int i = 0; i < arguments.Count; i++) - imported_arguments.Add (ImportType (arguments [i], context)); - - return imported_instance; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/LinkedResource.cs b/mcs/class/Mono.Cecil/Mono.Cecil/LinkedResource.cs deleted file mode 100644 index 16c1d59b5a0..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/LinkedResource.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// LinkedResource.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public sealed class LinkedResource : Resource { - - internal byte [] hash; - string file; - - public byte [] Hash { - get { return hash; } - } - - public string File { - get { return file; } - set { file = value; } - } - - public override ResourceType ResourceType { - get { return ResourceType.Linked; } - } - - public LinkedResource (string name, ManifestResourceAttributes flags) - : base (name, flags) - { - } - - public LinkedResource (string name, ManifestResourceAttributes flags, string file) - : base (name, flags) - { - this.file = file; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs deleted file mode 100644 index 7d6bb190f44..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// ManifestResourceAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum ManifestResourceAttributes : uint { - VisibilityMask = 0x0007, - Public = 0x0001, // The resource is exported from the Assembly - Private = 0x0002 // The resource is private to the Assembly - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MarshalInfo.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MarshalInfo.cs deleted file mode 100644 index 9d587389235..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MarshalInfo.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -// MarshalInfo.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public class MarshalInfo { - - internal NativeType native; - - public NativeType NativeType { - get { return native; } - set { native = value; } - } - - public MarshalInfo (NativeType native) - { - this.native = native; - } - } - - public sealed class ArrayMarshalInfo : MarshalInfo { - - internal NativeType element_type; - internal int size_parameter_index; - internal int size; - internal int size_parameter_multiplier; - - public NativeType ElementType { - get { return element_type; } - set { element_type = value; } - } - - public int SizeParameterIndex { - get { return size_parameter_index; } - set { size_parameter_index = value; } - } - - public int Size { - get { return size; } - set { size = value; } - } - - public int SizeParameterMultiplier { - get { return size_parameter_multiplier; } - set { size_parameter_multiplier = value; } - } - - public ArrayMarshalInfo () - : base (NativeType.Array) - { - element_type = NativeType.None; - size_parameter_index = -1; - size = -1; - size_parameter_multiplier = -1; - } - } - - public sealed class CustomMarshalInfo : MarshalInfo { - - internal Guid guid; - internal string unmanaged_type; - internal TypeReference managed_type; - internal string cookie; - - public Guid Guid { - get { return guid; } - set { guid = value; } - } - - public string UnmanagedType { - get { return unmanaged_type; } - set { unmanaged_type = value; } - } - - public TypeReference ManagedType { - get { return managed_type; } - set { managed_type = value; } - } - - public string Cookie { - get { return cookie; } - set { cookie = value; } - } - - public CustomMarshalInfo () - : base (NativeType.CustomMarshaler) - { - } - } - - public sealed class SafeArrayMarshalInfo : MarshalInfo { - - internal VariantType element_type; - - public VariantType ElementType { - get { return element_type; } - set { element_type = value; } - } - - public SafeArrayMarshalInfo () - : base (NativeType.SafeArray) - { - element_type = VariantType.None; - } - } - - public sealed class FixedArrayMarshalInfo : MarshalInfo { - - internal NativeType element_type; - internal int size; - - public NativeType ElementType { - get { return element_type; } - set { element_type = value; } - } - - public int Size { - get { return size; } - set { size = value; } - } - - public FixedArrayMarshalInfo () - : base (NativeType.FixedArray) - { - element_type = NativeType.None; - } - } - - public sealed class FixedSysStringMarshalInfo : MarshalInfo { - - internal int size; - - public int Size { - get { return size; } - set { size = value; } - } - - public FixedSysStringMarshalInfo () - : base (NativeType.FixedSysString) - { - size = -1; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MemberDefinitionCollection.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MemberDefinitionCollection.cs deleted file mode 100644 index 707f36fb97b..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MemberDefinitionCollection.cs +++ /dev/null @@ -1,92 +0,0 @@ -// -// MemberDefinitionCollection.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - class MemberDefinitionCollection : Collection where T : IMemberDefinition { - - TypeDefinition container; - - internal MemberDefinitionCollection (TypeDefinition container) - { - this.container = container; - } - - internal MemberDefinitionCollection (TypeDefinition container, int capacity) - : base (capacity) - { - this.container = container; - } - - protected override void OnAdd (T item, int index) - { - Attach (item); - } - - protected sealed override void OnSet (T item, int index) - { - Attach (item); - } - - protected sealed override void OnInsert (T item, int index) - { - Attach (item); - } - - protected sealed override void OnRemove (T item, int index) - { - Detach (item); - } - - protected sealed override void OnClear () - { - foreach (var definition in this) - Detach (definition); - } - - void Attach (T element) - { - if (element.DeclaringType == container) - return; - - if (element.DeclaringType != null) - throw new ArgumentException ("Member already attached"); - - element.DeclaringType = this.container; - } - - static void Detach (T element) - { - element.DeclaringType = null; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MemberReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MemberReference.cs deleted file mode 100644 index b658c513dee..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MemberReference.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// MemberReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public abstract class MemberReference : IMetadataTokenProvider { - - string name; - TypeReference declaring_type; - - internal MetadataToken token; - - public virtual string Name { - get { return name; } - set { name = value; } - } - - public abstract string FullName { - get; - } - - public virtual TypeReference DeclaringType { - get { return declaring_type; } - set { declaring_type = value; } - } - - public MetadataToken MetadataToken { - get { return token; } - set { token = value; } - } - - internal bool HasImage { - get { - var module = Module; - if (module == null) - return false; - - return module.HasImage; - } - } - - public virtual ModuleDefinition Module { - get { return declaring_type != null ? declaring_type.Module : null; } - } - - public virtual bool IsDefinition { - get { return false; } - } - - internal virtual bool ContainsGenericParameter { - get { return declaring_type != null && declaring_type.ContainsGenericParameter; } - } - - internal MemberReference () - { - } - - internal MemberReference (string name) - { - this.name = name ?? string.Empty; - } - - internal string MemberFullName () - { - if (declaring_type == null) - return name; - - return declaring_type.FullName + "::" + name; - } - - public override string ToString () - { - return FullName; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MetadataResolver.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MetadataResolver.cs deleted file mode 100644 index e69fcd71507..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MetadataResolver.cs +++ /dev/null @@ -1,364 +0,0 @@ -// -// MetadataResolver.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public interface IAssemblyResolver { - AssemblyDefinition Resolve (AssemblyNameReference name); - AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters); - - AssemblyDefinition Resolve (string fullName); - 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 - public class ResolutionException : Exception { - - readonly MemberReference member; - - public MemberReference Member { - get { return member; } - } - - public ResolutionException (MemberReference member) - : base ("Failed to resolve " + member.FullName) - { - this.member = member; - } - -#if !SILVERLIGHT && !CF - protected ResolutionException ( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) - : base (info, context) - { - } -#endif - } - - public class MetadataResolver : IMetadataResolver { - - 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 = assembly_resolver.Resolve ((AssemblyNameReference) scope); - if (assembly == null) - return null; - - return GetType (assembly.MainModule, type); - case MetadataScopeType.ModuleDefinition: - 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 (netmodule, type); - } - break; - } - - throw new NotSupportedException (); - } - - static TypeDefinition GetType (ModuleDefinition module, TypeReference reference) - { - var type = GetTypeDefinition (module, reference); - if (type != null) - return type; - - if (!module.HasExportedTypes) - return null; - - var exported_types = module.ExportedTypes; - - for (int i = 0; i < exported_types.Count; i++) { - var exported_type = exported_types [i]; - if (exported_type.Name != reference.Name) - continue; - - if (exported_type.Namespace != reference.Namespace) - continue; - - return exported_type.Resolve (); - } - - return null; - } - - static TypeDefinition GetTypeDefinition (ModuleDefinition module, TypeReference type) - { - if (!type.IsNested) - return module.GetType (type.Namespace, type.Name); - - var declaring_type = type.DeclaringType.Resolve (); - if (declaring_type == null) - return null; - - return declaring_type.GetNestedType (type.Name); - } - - public virtual FieldDefinition Resolve (FieldReference field) - { - if (field == null) - throw new ArgumentNullException ("field"); - - var type = Resolve (field.DeclaringType); - if (type == null) - return null; - - if (!type.HasFields) - return null; - - return GetField (type, field); - } - - FieldDefinition GetField (TypeDefinition type, FieldReference reference) - { - while (type != null) { - var field = GetField (type.Fields, reference); - if (field != null) - return field; - - if (type.BaseType == null) - return null; - - type = Resolve (type.BaseType); - } - - return null; - } - - static FieldDefinition GetField (Collection fields, FieldReference reference) - { - for (int i = 0; i < fields.Count; i++) { - var field = fields [i]; - - if (field.Name != reference.Name) - continue; - - if (!AreSame (field.FieldType, reference.FieldType)) - continue; - - return field; - } - - return null; - } - - public virtual MethodDefinition Resolve (MethodReference method) - { - if (method == null) - throw new ArgumentNullException ("method"); - - var type = Resolve (method.DeclaringType); - if (type == null) - return null; - - method = method.GetElementMethod (); - - if (!type.HasMethods) - return null; - - return GetMethod (type, method); - } - - MethodDefinition GetMethod (TypeDefinition type, MethodReference reference) - { - while (type != null) { - var method = GetMethod (type.Methods, reference); - if (method != null) - return method; - - if (type.BaseType == null) - return null; - - type = Resolve (type.BaseType); - } - - return null; - } - - public static MethodDefinition GetMethod (Collection methods, MethodReference reference) - { - for (int i = 0; i < methods.Count; i++) { - var method = methods [i]; - - if (method.Name != reference.Name) - continue; - - if (method.HasGenericParameters != reference.HasGenericParameters) - continue; - - if (method.HasGenericParameters && method.GenericParameters.Count != reference.GenericParameters.Count) - continue; - - if (!AreSame (method.ReturnType, reference.ReturnType)) - continue; - - if (method.HasParameters != reference.HasParameters) - continue; - - if (!method.HasParameters && !reference.HasParameters) - return method; - - if (!AreSame (method.Parameters, reference.Parameters)) - continue; - - return method; - } - - return null; - } - - static bool AreSame (Collection a, Collection b) - { - var count = a.Count; - - if (count != b.Count) - return false; - - if (count == 0) - return true; - - for (int i = 0; i < count; i++) - if (!AreSame (a [i].ParameterType, b [i].ParameterType)) - return false; - - return true; - } - - static bool AreSame (TypeSpecification a, TypeSpecification b) - { - if (!AreSame (a.ElementType, b.ElementType)) - return false; - - if (a.IsGenericInstance) - return AreSame ((GenericInstanceType) a, (GenericInstanceType) b); - - if (a.IsRequiredModifier || a.IsOptionalModifier) - return AreSame ((IModifierType) a, (IModifierType) b); - - if (a.IsArray) - return AreSame ((ArrayType) a, (ArrayType) b); - - return true; - } - - static bool AreSame (ArrayType a, ArrayType b) - { - if (a.Rank != b.Rank) - return false; - - // TODO: dimensions - - return true; - } - - static bool AreSame (IModifierType a, IModifierType b) - { - return AreSame (a.ModifierType, b.ModifierType); - } - - static bool AreSame (GenericInstanceType a, GenericInstanceType b) - { - if (a.GenericArguments.Count != b.GenericArguments.Count) - return false; - - for (int i = 0; i < a.GenericArguments.Count; i++) - if (!AreSame (a.GenericArguments [i], b.GenericArguments [i])) - return false; - - return true; - } - - static bool AreSame (GenericParameter a, GenericParameter b) - { - return a.Position == b.Position; - } - - static bool AreSame (TypeReference a, TypeReference b) - { - if (ReferenceEquals (a, b)) - return true; - - if (a == null || b == null) - return false; - - if (a.etype != b.etype) - return false; - - if (a.IsGenericParameter) - return AreSame ((GenericParameter) a, (GenericParameter) b); - - if (a.IsTypeSpecification ()) - return AreSame ((TypeSpecification) a, (TypeSpecification) b); - - if (a.Name != b.Name || a.Namespace != b.Namespace) - return false; - - //TODO: check scope - - return AreSame (a.DeclaringType, b.DeclaringType); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MetadataSystem.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MetadataSystem.cs deleted file mode 100644 index 693202b6bac..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MetadataSystem.cs +++ /dev/null @@ -1,398 +0,0 @@ -// -// MetadataSystem.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - struct Range { - public uint Start; - public uint Length; - - public Range (uint index, uint length) - { - this.Start = index; - this.Length = length; - } - } - - sealed class MetadataSystem { - - internal AssemblyNameReference [] AssemblyReferences; - internal ModuleReference [] ModuleReferences; - - internal TypeDefinition [] Types; - internal TypeReference [] TypeReferences; - - internal FieldDefinition [] Fields; - internal MethodDefinition [] Methods; - internal MemberReference [] MemberReferences; - - internal Dictionary NestedTypes; - internal Dictionary ReverseNestedTypes; - internal Dictionary Interfaces; - internal Dictionary> ClassLayouts; - internal Dictionary FieldLayouts; - internal Dictionary FieldRVAs; - internal Dictionary FieldMarshals; - internal Dictionary> Constants; - internal Dictionary Overrides; - internal Dictionary CustomAttributes; - internal Dictionary SecurityDeclarations; - internal Dictionary Events; - internal Dictionary Properties; - internal Dictionary> Semantics; - internal Dictionary> PInvokes; - internal Dictionary GenericParameters; - internal Dictionary GenericConstraints; - - static Dictionary> primitive_value_types; - - static void InitializePrimitives () - { - primitive_value_types = new Dictionary> (18, StringComparer.Ordinal) { - { "Void", new Row (ElementType.Void, false) }, - { "Boolean", new Row (ElementType.Boolean, true) }, - { "Char", new Row (ElementType.Char, true) }, - { "SByte", new Row (ElementType.I1, true) }, - { "Byte", new Row (ElementType.U1, true) }, - { "Int16", new Row (ElementType.I2, true) }, - { "UInt16", new Row (ElementType.U2, true) }, - { "Int32", new Row (ElementType.I4, true) }, - { "UInt32", new Row (ElementType.U4, true) }, - { "Int64", new Row (ElementType.I8, true) }, - { "UInt64", new Row (ElementType.U8, true) }, - { "Single", new Row (ElementType.R4, true) }, - { "Double", new Row (ElementType.R8, true) }, - { "String", new Row (ElementType.String, false) }, - { "TypedReference", new Row (ElementType.TypedByRef, false) }, - { "IntPtr", new Row (ElementType.I, true) }, - { "UIntPtr", new Row (ElementType.U, true) }, - { "Object", new Row (ElementType.Object, false) }, - }; - } - - public static void TryProcessPrimitiveTypeReference (TypeReference type) - { - if (type.Namespace != "System") - return; - - var scope = type.scope; - if (scope == null || scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference || scope.Name != "mscorlib") - return; - - Row primitive_data; - if (!TryGetPrimitiveData (type, out primitive_data)) - 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.Namespace != "System") - return false; - - if (!type.HasImage || !type.Module.IsCorlib ()) - return false; - - Row 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 primitive_data) - { - if (primitive_value_types == null) - InitializePrimitives (); - - return primitive_value_types.TryGetValue (type.Name, out primitive_data); - } - - public void Clear () - { - if (NestedTypes != null) NestedTypes.Clear (); - if (ReverseNestedTypes != null) ReverseNestedTypes.Clear (); - if (Interfaces != null) Interfaces.Clear (); - if (ClassLayouts != null) ClassLayouts.Clear (); - if (FieldLayouts != null) FieldLayouts.Clear (); - if (FieldRVAs != null) FieldRVAs.Clear (); - if (FieldMarshals != null) FieldMarshals.Clear (); - if (Constants != null) Constants.Clear (); - if (Overrides != null) Overrides.Clear (); - if (CustomAttributes != null) CustomAttributes.Clear (); - if (SecurityDeclarations != null) SecurityDeclarations.Clear (); - if (Events != null) Events.Clear (); - if (Properties != null) Properties.Clear (); - if (Semantics != null) Semantics.Clear (); - if (PInvokes != null) PInvokes.Clear (); - if (GenericParameters != null) GenericParameters.Clear (); - if (GenericConstraints != null) GenericConstraints.Clear (); - } - - public TypeDefinition GetTypeDefinition (uint rid) - { - if (rid < 1 || rid > Types.Length) - return null; - - return Types [rid - 1]; - } - - public void AddTypeDefinition (TypeDefinition type) - { - Types [type.token.RID - 1] = type; - } - - public TypeReference GetTypeReference (uint rid) - { - if (rid < 1 || rid > TypeReferences.Length) - return null; - - return TypeReferences [rid - 1]; - } - - public void AddTypeReference (TypeReference type) - { - TypeReferences [type.token.RID - 1] = type; - } - - public FieldDefinition GetFieldDefinition (uint rid) - { - if (rid < 1 || rid > Fields.Length) - return null; - - return Fields [rid - 1]; - } - - public void AddFieldDefinition (FieldDefinition field) - { - Fields [field.token.RID - 1] = field; - } - - public MethodDefinition GetMethodDefinition (uint rid) - { - if (rid < 1 || rid > Methods.Length) - return null; - - return Methods [rid - 1]; - } - - public void AddMethodDefinition (MethodDefinition method) - { - Methods [method.token.RID - 1] = method; - } - - public MemberReference GetMemberReference (uint rid) - { - if (rid < 1 || rid > MemberReferences.Length) - return null; - - return MemberReferences [rid - 1]; - } - - public void AddMemberReference (MemberReference member) - { - MemberReferences [member.token.RID - 1] = member; - } - - public bool TryGetNestedTypeMapping (TypeDefinition type, out uint [] mapping) - { - return NestedTypes.TryGetValue (type.token.RID, out mapping); - } - - public void SetNestedTypeMapping (uint type_rid, uint [] mapping) - { - NestedTypes [type_rid] = mapping; - } - - public void RemoveNestedTypeMapping (TypeDefinition type) - { - NestedTypes.Remove (type.token.RID); - } - - public bool TryGetReverseNestedTypeMapping (TypeDefinition type, out uint declaring) - { - return ReverseNestedTypes.TryGetValue (type.token.RID, out declaring); - } - - public void SetReverseNestedTypeMapping (uint nested, uint declaring) - { - ReverseNestedTypes.Add (nested, declaring); - } - - public void RemoveReverseNestedTypeMapping (TypeDefinition type) - { - ReverseNestedTypes.Remove (type.token.RID); - } - - public bool TryGetInterfaceMapping (TypeDefinition type, out MetadataToken [] mapping) - { - return Interfaces.TryGetValue (type.token.RID, out mapping); - } - - public void SetInterfaceMapping (uint type_rid, MetadataToken [] mapping) - { - Interfaces [type_rid] = mapping; - } - - public void RemoveInterfaceMapping (TypeDefinition type) - { - Interfaces.Remove (type.token.RID); - } - - public void AddPropertiesRange (uint type_rid, Range range) - { - Properties.Add (type_rid, range); - } - - public bool TryGetPropertiesRange (TypeDefinition type, out Range range) - { - return Properties.TryGetValue (type.token.RID, out range); - } - - public void RemovePropertiesRange (TypeDefinition type) - { - Properties.Remove (type.token.RID); - } - - public void AddEventsRange (uint type_rid, Range range) - { - Events.Add (type_rid, range); - } - - public bool TryGetEventsRange (TypeDefinition type, out Range range) - { - return Events.TryGetValue (type.token.RID, out range); - } - - public void RemoveEventsRange (TypeDefinition type) - { - Events.Remove (type.token.RID); - } - - public bool TryGetGenericParameterRange (IGenericParameterProvider owner, out Range range) - { - return GenericParameters.TryGetValue (owner.MetadataToken, out range); - } - - public void RemoveGenericParameterRange (IGenericParameterProvider owner) - { - GenericParameters.Remove (owner.MetadataToken); - } - - public bool TryGetCustomAttributeRange (ICustomAttributeProvider owner, out Range range) - { - return CustomAttributes.TryGetValue (owner.MetadataToken, out range); - } - - public void RemoveCustomAttributeRange (ICustomAttributeProvider owner) - { - CustomAttributes.Remove (owner.MetadataToken); - } - - public bool TryGetSecurityDeclarationRange (ISecurityDeclarationProvider owner, out Range range) - { - return SecurityDeclarations.TryGetValue (owner.MetadataToken, out range); - } - - public void RemoveSecurityDeclarationRange (ISecurityDeclarationProvider owner) - { - SecurityDeclarations.Remove (owner.MetadataToken); - } - - public bool TryGetGenericConstraintMapping (GenericParameter generic_parameter, out MetadataToken [] mapping) - { - return GenericConstraints.TryGetValue (generic_parameter.token.RID, out mapping); - } - - public void SetGenericConstraintMapping (uint gp_rid, MetadataToken [] mapping) - { - GenericConstraints [gp_rid] = mapping; - } - - public void RemoveGenericConstraintMapping (GenericParameter generic_parameter) - { - GenericConstraints.Remove (generic_parameter.token.RID); - } - - public bool TryGetOverrideMapping (MethodDefinition method, out MetadataToken [] mapping) - { - return Overrides.TryGetValue (method.token.RID, out mapping); - } - - public void SetOverrideMapping (uint rid, MetadataToken [] mapping) - { - Overrides [rid] = mapping; - } - - public void RemoveOverrideMapping (MethodDefinition method) - { - Overrides.Remove (method.token.RID); - } - - public TypeDefinition GetFieldDeclaringType (uint field_rid) - { - return BinaryRangeSearch (Types, field_rid, true); - } - - public TypeDefinition GetMethodDeclaringType (uint method_rid) - { - return BinaryRangeSearch (Types, method_rid, false); - } - - static TypeDefinition BinaryRangeSearch (TypeDefinition [] types, uint rid, bool field) - { - int min = 0; - int max = types.Length - 1; - while (min <= max) { - int mid = min + ((max - min) / 2); - var type = types [mid]; - var range = field ? type.fields_range : type.methods_range; - - if (rid < range.Start) - max = mid - 1; - else if (rid >= range.Start + range.Length) - min = mid + 1; - else - return type; - } - - return null; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodAttributes.cs deleted file mode 100644 index 626a97b3ea8..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodAttributes.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -// MethodAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum MethodAttributes : ushort { - MemberAccessMask = 0x0007, - CompilerControlled = 0x0000, // Member not referenceable - Private = 0x0001, // Accessible only by the parent type - FamANDAssem = 0x0002, // Accessible by sub-types only in this Assembly - Assembly = 0x0003, // Accessibly by anyone in the Assembly - Family = 0x0004, // Accessible only by type and sub-types - FamORAssem = 0x0005, // Accessibly by sub-types anywhere, plus anyone in assembly - Public = 0x0006, // Accessibly by anyone who has visibility to this scope - - Static = 0x0010, // Defined on type, else per instance - Final = 0x0020, // Method may not be overridden - Virtual = 0x0040, // Method is virtual - HideBySig = 0x0080, // Method hides by name+sig, else just by name - - VtableLayoutMask = 0x0100, // Use this mask to retrieve vtable attributes - ReuseSlot = 0x0000, // Method reuses existing slot in vtable - NewSlot = 0x0100, // Method always gets a new slot in the vtable - - CheckAccessOnOverride = 0x0200, // Method can only be overriden if also accessible - Abstract = 0x0400, // Method does not provide an implementation - SpecialName = 0x0800, // Method is special - - // Interop Attributes - PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke - UnmanagedExport = 0x0008, // Reserved: shall be zero for conforming implementations - - // Additional flags - RTSpecialName = 0x1000, // CLI provides 'special' behavior, depending upon the name of the method - HasSecurity = 0x4000, // Method has security associate with it - RequireSecObject = 0x8000 // Method calls another method containing security code - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs deleted file mode 100644 index bd7188dbec2..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// MethodCallingConvention.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum MethodCallingConvention : byte { - Default = 0x0, - C = 0x1, - StdCall = 0x2, - ThisCall = 0x3, - FastCall = 0x4, - VarArg = 0x5, - Generic = 0x10, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodDefinition.cs deleted file mode 100644 index cbda745b7ea..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodDefinition.cs +++ /dev/null @@ -1,487 +0,0 @@ -// -// MethodDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Cecil.Cil; -using Mono.Collections.Generic; - -using RVA = System.UInt32; - -namespace Mono.Cecil { - - public sealed class MethodDefinition : MethodReference, IMemberDefinition, ISecurityDeclarationProvider { - - ushort attributes; - ushort impl_attributes; - internal MethodSemanticsAttributes? sem_attrs; - Collection custom_attributes; - Collection security_declarations; - - internal RVA rva; - internal PInvokeInfo pinvoke; - Collection overrides; - - internal MethodBody body; - - public MethodAttributes Attributes { - get { return (MethodAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public MethodImplAttributes ImplAttributes { - get { return (MethodImplAttributes) impl_attributes; } - set { impl_attributes = (ushort) value; } - } - - public MethodSemanticsAttributes SemanticsAttributes { - get { - if (sem_attrs.HasValue) - return sem_attrs.Value; - - if (HasImage) { - ReadSemantics (); - return sem_attrs.Value; - } - - sem_attrs = MethodSemanticsAttributes.None; - return sem_attrs.Value; - } - set { sem_attrs = value; } - } - - internal void ReadSemantics () - { - if (sem_attrs.HasValue) - return; - - var module = this.Module; - if (module == null) - return; - - if (!module.HasImage) - return; - - module.Read (this, (method, reader) => reader.ReadAllSemantics (method)); - } - - public bool HasSecurityDeclarations { - get { - if (security_declarations != null) - return security_declarations.Count > 0; - - return this.GetHasSecurityDeclarations (Module); - } - } - - public Collection SecurityDeclarations { - get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (Module)); } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); } - } - - public int RVA { - get { return (int) rva; } - } - - public bool HasBody { - get { - return (attributes & (ushort) MethodAttributes.Abstract) == 0 && - (attributes & (ushort) MethodAttributes.PInvokeImpl) == 0 && - (impl_attributes & (ushort) MethodImplAttributes.InternalCall) == 0 && - (impl_attributes & (ushort) MethodImplAttributes.Native) == 0 && - (impl_attributes & (ushort) MethodImplAttributes.Unmanaged) == 0 && - (impl_attributes & (ushort) MethodImplAttributes.Runtime) == 0; - } - } - - public MethodBody Body { - get { - if (body != null) - return body; - - if (!HasBody) - return null; - - if (HasImage && rva != 0) - return body = Module.Read (this, (method, reader) => reader.ReadMethodBody (method)); - - return body = new MethodBody (this); - } - set { body = value; } - } - - public bool HasPInvokeInfo { - get { - if (pinvoke != null) - return true; - - return IsPInvokeImpl; - } - } - - public PInvokeInfo PInvokeInfo { - get { - if (pinvoke != null) - return pinvoke; - - if (HasImage && IsPInvokeImpl) - return pinvoke = Module.Read (this, (method, reader) => reader.ReadPInvokeInfo (method)); - - return null; - } - set { - IsPInvokeImpl = true; - pinvoke = value; - } - } - - public bool HasOverrides { - get { - if (overrides != null) - return overrides.Count > 0; - - if (HasImage) - return Module.Read (this, (method, reader) => reader.HasOverrides (method)); - - return false; - } - } - - public Collection Overrides { - get { - if (overrides != null) - return overrides; - - if (HasImage) - return overrides = Module.Read (this, (method, reader) => reader.ReadOverrides (method)); - - return overrides = new Collection (); - } - } - - public override bool HasGenericParameters { - get { - if (generic_parameters != null) - return generic_parameters.Count > 0; - - return this.GetHasGenericParameters (Module); - } - } - - public override Collection GenericParameters { - get { return generic_parameters ?? (generic_parameters = this.GetGenericParameters (Module)); } - } - - #region MethodAttributes - - public bool IsCompilerControlled { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.CompilerControlled); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.CompilerControlled, value); } - } - - public bool IsPrivate { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Private); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Private, value); } - } - - public bool IsFamilyAndAssembly { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamANDAssem); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamANDAssem, value); } - } - - public bool IsAssembly { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Assembly); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Assembly, value); } - } - - public bool IsFamily { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Family); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Family, value); } - } - - public bool IsFamilyOrAssembly { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamORAssem); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamORAssem, value); } - } - - public bool IsPublic { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Public); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Public, value); } - } - - public bool IsStatic { - get { return attributes.GetAttributes ((ushort) MethodAttributes.Static); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Static, value); } - } - - public bool IsFinal { - get { return attributes.GetAttributes ((ushort) MethodAttributes.Final); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Final, value); } - } - - public bool IsVirtual { - get { return attributes.GetAttributes ((ushort) MethodAttributes.Virtual); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Virtual, value); } - } - - public bool IsHideBySig { - get { return attributes.GetAttributes ((ushort) MethodAttributes.HideBySig); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.HideBySig, value); } - } - - public bool IsReuseSlot { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.ReuseSlot); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.ReuseSlot, value); } - } - - public bool IsNewSlot { - get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.NewSlot); } - set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.NewSlot, value); } - } - - public bool IsCheckAccessOnOverride { - get { return attributes.GetAttributes ((ushort) MethodAttributes.CheckAccessOnOverride); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.CheckAccessOnOverride, value); } - } - - public bool IsAbstract { - get { return attributes.GetAttributes ((ushort) MethodAttributes.Abstract); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Abstract, value); } - } - - public bool IsSpecialName { - get { return attributes.GetAttributes ((ushort) MethodAttributes.SpecialName); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.SpecialName, value); } - } - - public bool IsPInvokeImpl { - get { return attributes.GetAttributes ((ushort) MethodAttributes.PInvokeImpl); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.PInvokeImpl, value); } - } - - public bool IsUnmanagedExport { - get { return attributes.GetAttributes ((ushort) MethodAttributes.UnmanagedExport); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.UnmanagedExport, value); } - } - - public bool IsRuntimeSpecialName { - get { return attributes.GetAttributes ((ushort) MethodAttributes.RTSpecialName); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.RTSpecialName, value); } - } - - public bool HasSecurity { - get { return attributes.GetAttributes ((ushort) MethodAttributes.HasSecurity); } - set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.HasSecurity, value); } - } - - #endregion - - #region MethodImplAttributes - - public bool IsIL { - get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.IL); } - set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.IL, value); } - } - - public bool IsNative { - get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Native); } - set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Native, value); } - } - - public bool IsRuntime { - get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Runtime); } - set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Runtime, value); } - } - - public bool IsUnmanaged { - get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Unmanaged); } - set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Unmanaged, value); } - } - - public bool IsManaged { - get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Managed); } - set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Managed, value); } - } - - public bool IsForwardRef { - get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.ForwardRef); } - set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.ForwardRef, value); } - } - - public bool IsPreserveSig { - get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.PreserveSig); } - set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.PreserveSig, value); } - } - - public bool IsInternalCall { - get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.InternalCall); } - set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.InternalCall, value); } - } - - public bool IsSynchronized { - get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.Synchronized); } - set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.Synchronized, value); } - } - - public bool NoInlining { - get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.NoInlining); } - set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.NoInlining, value); } - } - - public bool NoOptimization { - get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.NoOptimization); } - set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.NoOptimization, value); } - } - - #endregion - - #region MethodSemanticsAttributes - - public bool IsSetter { - get { return this.GetSemantics (MethodSemanticsAttributes.Setter); } - set { this.SetSemantics (MethodSemanticsAttributes.Setter, value); } - } - - public bool IsGetter { - get { return this.GetSemantics (MethodSemanticsAttributes.Getter); } - set { this.SetSemantics (MethodSemanticsAttributes.Getter, value); } - } - - public bool IsOther { - get { return this.GetSemantics (MethodSemanticsAttributes.Other); } - set { this.SetSemantics (MethodSemanticsAttributes.Other, value); } - } - - public bool IsAddOn { - get { return this.GetSemantics (MethodSemanticsAttributes.AddOn); } - set { this.SetSemantics (MethodSemanticsAttributes.AddOn, value); } - } - - public bool IsRemoveOn { - get { return this.GetSemantics (MethodSemanticsAttributes.RemoveOn); } - set { this.SetSemantics (MethodSemanticsAttributes.RemoveOn, value); } - } - - public bool IsFire { - get { return this.GetSemantics (MethodSemanticsAttributes.Fire); } - set { this.SetSemantics (MethodSemanticsAttributes.Fire, value); } - } - - #endregion - - public new TypeDefinition DeclaringType { - get { return (TypeDefinition) base.DeclaringType; } - set { base.DeclaringType = value; } - } - - public bool IsConstructor { - get { - return this.IsRuntimeSpecialName - && this.IsSpecialName - && (this.Name == ".cctor" || this.Name == ".ctor"); - } - } - - public override bool IsDefinition { - get { return true; } - } - - internal MethodDefinition () - { - this.token = new MetadataToken (TokenType.Method); - } - - public MethodDefinition (string name, MethodAttributes attributes, TypeReference returnType) - : base (name, returnType) - { - this.attributes = (ushort) attributes; - this.HasThis = !this.IsStatic; - this.token = new MetadataToken (TokenType.Method); - } - - public override MethodDefinition Resolve () - { - return this; - } - } - - static partial class Mixin { - - public static ParameterDefinition GetParameter (this MethodBody self, int index) - { - var method = self.method; - - if (method.HasThis) { - if (index == 0) - return self.ThisParameter; - - index--; - } - - var parameters = method.Parameters; - - if (index < 0 || index >= parameters.size) - return null; - - return parameters [index]; - } - - public static VariableDefinition GetVariable (this MethodBody self, int index) - { - var variables = self.Variables; - - if (index < 0 || index >= variables.size) - return null; - - return variables [index]; - } - - public static bool GetSemantics (this MethodDefinition self, MethodSemanticsAttributes semantics) - { - return (self.SemanticsAttributes & semantics) != 0; - } - - public static void SetSemantics (this MethodDefinition self, MethodSemanticsAttributes semantics, bool value) - { - if (value) - self.SemanticsAttributes |= semantics; - else - self.SemanticsAttributes &= ~semantics; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs deleted file mode 100644 index b24fcf7047d..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// MethodImplAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum MethodImplAttributes : ushort { - CodeTypeMask = 0x0003, - IL = 0x0000, // Method impl is CIL - Native = 0x0001, // Method impl is native - OPTIL = 0x0002, // Reserved: shall be zero in conforming implementations - Runtime = 0x0003, // Method impl is provided by the runtime - - ManagedMask = 0x0004, // Flags specifying whether the code is managed or unmanaged - Unmanaged = 0x0004, // Method impl is unmanaged, otherwise managed - Managed = 0x0000, // Method impl is managed - - // Implementation info and interop - ForwardRef = 0x0010, // Indicates method is defined; used primarily in merge scenarios - PreserveSig = 0x0080, // Reserved: conforming implementations may ignore - InternalCall = 0x1000, // Reserved: shall be zero in conforming implementations - 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 - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodReference.cs deleted file mode 100644 index 0adab452ef7..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodReference.cs +++ /dev/null @@ -1,214 +0,0 @@ -// -// MethodReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public class MethodReference : MemberReference, IMethodSignature, IGenericParameterProvider, IGenericContext { - - internal ParameterDefinitionCollection parameters; - MethodReturnType return_type; - - bool has_this; - bool explicit_this; - MethodCallingConvention calling_convention; - internal Collection generic_parameters; - - public virtual bool HasThis { - get { return has_this; } - set { has_this = value; } - } - - public virtual bool ExplicitThis { - get { return explicit_this; } - set { explicit_this = value; } - } - - public virtual MethodCallingConvention CallingConvention { - get { return calling_convention; } - set { calling_convention = value; } - } - - public virtual bool HasParameters { - get { return !parameters.IsNullOrEmpty (); } - } - - public virtual Collection Parameters { - get { - if (parameters == null) - parameters = new ParameterDefinitionCollection (this); - - return parameters; - } - } - - IGenericParameterProvider IGenericContext.Type { - get { - var declaring_type = this.DeclaringType; - var instance = declaring_type as GenericInstanceType; - if (instance != null) - return instance.ElementType; - - return declaring_type; - } - } - - IGenericParameterProvider IGenericContext.Method { - get { return this; } - } - - GenericParameterType IGenericParameterProvider.GenericParameterType { - get { return GenericParameterType.Method; } - } - - public virtual bool HasGenericParameters { - get { return !generic_parameters.IsNullOrEmpty (); } - } - - public virtual Collection GenericParameters { - get { - if (generic_parameters != null) - return generic_parameters; - - return generic_parameters = new GenericParameterCollection (this); - } - } - - public TypeReference ReturnType { - get { - var return_type = MethodReturnType; - return return_type != null ? return_type.ReturnType : null; - } - set { - var return_type = MethodReturnType; - if (return_type != null) - return_type.ReturnType = value; - } - } - - public virtual MethodReturnType MethodReturnType { - get { return return_type; } - set { return_type = value; } - } - - public override string FullName { - get { - var builder = new StringBuilder (); - builder.Append (ReturnType.FullName) - .Append (" ") - .Append (MemberFullName ()); - this.MethodSignatureFullName (builder); - return builder.ToString (); - } - } - - public virtual bool IsGenericInstance { - get { return false; } - } - - internal override bool ContainsGenericParameter { - get { - if (this.ReturnType.ContainsGenericParameter || base.ContainsGenericParameter) - return true; - - var parameters = this.Parameters; - - for (int i = 0; i < parameters.Count; i++) - if (parameters [i].ParameterType.ContainsGenericParameter) - return true; - - return false; - } - } - - internal MethodReference () - { - this.return_type = new MethodReturnType (this); - this.token = new MetadataToken (TokenType.MemberRef); - } - - public MethodReference (string name, TypeReference returnType) - : base (name) - { - if (returnType == null) - throw new ArgumentNullException ("returnType"); - - this.return_type = new MethodReturnType (this); - this.return_type.ReturnType = returnType; - this.token = new MetadataToken (TokenType.MemberRef); - } - - public MethodReference (string name, TypeReference returnType, TypeReference declaringType) - : this (name, returnType) - { - if (declaringType == null) - throw new ArgumentNullException ("declaringType"); - - this.DeclaringType = declaringType; - } - - public virtual MethodReference GetElementMethod () - { - return this; - } - - public virtual MethodDefinition Resolve () - { - var module = this.Module; - if (module == null) - throw new NotSupportedException (); - - return module.Resolve (this); - } - } - - static partial class Mixin { - - public static bool IsVarArg (this IMethodSignature self) - { - return (self.CallingConvention & MethodCallingConvention.VarArg) != 0; - } - - public static int GetSentinelPosition (this IMethodSignature self) - { - if (!self.HasParameters) - return -1; - - var parameters = self.Parameters; - for (int i = 0; i < parameters.Count; i++) - if (parameters [i].ParameterType.IsSentinel) - return i; - - return -1; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodReturnType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodReturnType.cs deleted file mode 100644 index b5b3ee84faf..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodReturnType.cs +++ /dev/null @@ -1,104 +0,0 @@ -// -// MethodReturnType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class MethodReturnType : IConstantProvider, ICustomAttributeProvider, IMarshalInfoProvider { - - internal IMethodSignature method; - internal ParameterDefinition parameter; - TypeReference return_type; - - public IMethodSignature Method { - get { return method; } - } - - public TypeReference ReturnType { - get { return return_type; } - set { return_type = value; } - } - - internal ParameterDefinition Parameter { - get { return parameter ?? (parameter = new ParameterDefinition (return_type, method)); } - } - - public MetadataToken MetadataToken { - get { return Parameter.MetadataToken; } - set { Parameter.MetadataToken = value; } - } - - public ParameterAttributes Attributes { - get { return Parameter.Attributes; } - set { Parameter.Attributes = value; } - } - - public bool HasCustomAttributes { - get { return parameter != null && parameter.HasCustomAttributes; } - } - - public Collection CustomAttributes { - get { return Parameter.CustomAttributes; } - } - - public bool HasDefault { - get { return parameter != null && parameter.HasDefault; } - set { Parameter.HasDefault = value; } - } - - public bool HasConstant { - get { return parameter != null && parameter.HasConstant; } - set { Parameter.HasConstant = value; } - } - - public object Constant { - get { return Parameter.Constant; } - set { Parameter.Constant = value; } - } - - public bool HasFieldMarshal { - get { return parameter != null && parameter.HasFieldMarshal; } - set { Parameter.HasFieldMarshal = value; } - } - - public bool HasMarshalInfo { - get { return parameter != null && parameter.HasMarshalInfo; } - } - - public MarshalInfo MarshalInfo { - get { return Parameter.MarshalInfo; } - set { Parameter.MarshalInfo = value; } - } - - public MethodReturnType (IMethodSignature method) - { - this.method = method; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs deleted file mode 100644 index dd0f4742c0a..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// MethodSemanticsattributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum MethodSemanticsAttributes : ushort { - None = 0x0000, - Setter = 0x0001, // Setter for property - Getter = 0x0002, // Getter for property - Other = 0x0004, // Other method for property or event - AddOn = 0x0008, // AddOn method for event - RemoveOn = 0x0010, // RemoveOn method for event - Fire = 0x0020 // Fire method for event - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/MethodSpecification.cs b/mcs/class/Mono.Cecil/Mono.Cecil/MethodSpecification.cs deleted file mode 100644 index 73b5c14ad65..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/MethodSpecification.cs +++ /dev/null @@ -1,103 +0,0 @@ -// -// MethodSpecification.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public abstract class MethodSpecification : MethodReference { - - readonly MethodReference method; - - public MethodReference ElementMethod { - get { return method; } - } - - public override string Name { - get { return method.Name; } - set { throw new InvalidOperationException (); } - } - - public override MethodCallingConvention CallingConvention { - get { return method.CallingConvention; } - set { throw new InvalidOperationException (); } - } - - public override bool HasThis { - get { return method.HasThis; } - set { throw new InvalidOperationException (); } - } - - public override bool ExplicitThis { - get { return method.ExplicitThis; } - set { throw new InvalidOperationException (); } - } - - public override MethodReturnType MethodReturnType { - get { return method.MethodReturnType; } - set { throw new InvalidOperationException (); } - } - - public override TypeReference DeclaringType { - get { return method.DeclaringType; } - set { throw new InvalidOperationException (); } - } - - public override ModuleDefinition Module { - get { return method.Module; } - } - - public override bool HasParameters { - get { return method.HasParameters; } - } - - public override Collection Parameters { - get { return method.Parameters; } - } - - internal override bool ContainsGenericParameter { - get { return method.ContainsGenericParameter; } - } - - internal MethodSpecification (MethodReference method) - { - if (method == null) - throw new ArgumentNullException ("method"); - - this.method = method; - this.token = new MetadataToken (TokenType.MethodSpec); - } - - public sealed override MethodReference GetElementMethod () - { - return method.GetElementMethod (); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/Modifiers.cs b/mcs/class/Mono.Cecil/Mono.Cecil/Modifiers.cs deleted file mode 100644 index ad31bc04f15..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/Modifiers.cs +++ /dev/null @@ -1,137 +0,0 @@ -// -// Modifiers.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public interface IModifierType { - TypeReference ModifierType { get; } - TypeReference ElementType { get; } - } - - public sealed class OptionalModifierType : TypeSpecification, IModifierType { - - TypeReference modifier_type; - - public TypeReference ModifierType { - get { return modifier_type; } - set { modifier_type = value; } - } - - public override string Name { - get { return base.Name + Suffix; } - } - - public override string FullName { - get { return base.FullName + Suffix; } - } - - string Suffix { - get { return " modopt(" + modifier_type + ")"; } - } - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override bool IsOptionalModifier { - get { return true; } - } - - internal override bool ContainsGenericParameter { - get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; } - } - - public OptionalModifierType (TypeReference modifierType, TypeReference type) - : base (type) - { - Mixin.CheckModifier (modifierType, type); - this.modifier_type = modifierType; - this.etype = MD.ElementType.CModOpt; - } - } - - public sealed class RequiredModifierType : TypeSpecification, IModifierType { - - TypeReference modifier_type; - - public TypeReference ModifierType { - get { return modifier_type; } - set { modifier_type = value; } - } - - public override string Name { - get { return base.Name + Suffix; } - } - - public override string FullName { - get { return base.FullName + Suffix; } - } - - string Suffix { - get { return " modreq(" + modifier_type + ")"; } - } - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override bool IsRequiredModifier { - get { return true; } - } - - internal override bool ContainsGenericParameter { - get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; } - } - - public RequiredModifierType (TypeReference modifierType, TypeReference type) - : base (type) - { - Mixin.CheckModifier (modifierType, type); - this.modifier_type = modifierType; - this.etype = MD.ElementType.CModReqD; - } - - } - - static partial class Mixin { - - public static void CheckModifier (TypeReference modifierType, TypeReference type) - { - if (modifierType == null) - throw new ArgumentNullException ("modifierType"); - if (type == null) - throw new ArgumentNullException ("type"); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs deleted file mode 100644 index 66ac0270e08..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs +++ /dev/null @@ -1,1048 +0,0 @@ -// -// ModuleDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; -using SR = System.Reflection; - -using Mono.Cecil.Cil; -using Mono.Cecil.Metadata; -using Mono.Cecil.PE; -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public enum ReadingMode { - Immediate = 1, - Deferred = 2, - } - - public sealed class ReaderParameters { - - ReadingMode reading_mode; - IAssemblyResolver assembly_resolver; - IMetadataResolver metadata_resolver; - Stream symbol_stream; - ISymbolReaderProvider symbol_reader_provider; - bool read_symbols; - - public ReadingMode ReadingMode { - get { return reading_mode; } - set { reading_mode = value; } - } - - public IAssemblyResolver AssemblyResolver { - get { return assembly_resolver; } - 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; } - } - - public ISymbolReaderProvider SymbolReaderProvider { - get { return symbol_reader_provider; } - set { symbol_reader_provider = value; } - } - - public bool ReadSymbols { - get { return read_symbols; } - set { read_symbols = value; } - } - - public ReaderParameters () - : this (ReadingMode.Deferred) - { - } - - public ReaderParameters (ReadingMode readingMode) - { - this.reading_mode = readingMode; - } - } - -#if !READ_ONLY - - public sealed class ModuleParameters { - - ModuleKind kind; - TargetRuntime runtime; - TargetArchitecture architecture; - IAssemblyResolver assembly_resolver; - IMetadataResolver metadata_resolver; - - public ModuleKind Kind { - get { return kind; } - set { kind = value; } - } - - public TargetRuntime Runtime { - get { return runtime; } - set { runtime = value; } - } - - public TargetArchitecture Architecture { - get { return architecture; } - set { architecture = value; } - } - - public IAssemblyResolver AssemblyResolver { - get { return assembly_resolver; } - set { assembly_resolver = value; } - } - - public IMetadataResolver MetadataResolver { - get { return metadata_resolver; } - set { metadata_resolver = value; } - } - - public ModuleParameters () - { - this.kind = ModuleKind.Dll; - this.runtime = GetCurrentRuntime (); - this.architecture = TargetArchitecture.I386; - } - - static TargetRuntime GetCurrentRuntime () - { -#if !CF - return typeof (object).Assembly.ImageRuntimeVersion.ParseRuntime (); -#else - var corlib_version = typeof (object).Assembly.GetName ().Version; - switch (corlib_version.Major) { - case 1: - return corlib_version.Minor == 0 - ? TargetRuntime.Net_1_0 - : TargetRuntime.Net_1_1; - case 2: - return TargetRuntime.Net_2_0; - case 4: - return TargetRuntime.Net_4_0; - default: - throw new NotSupportedException (); - } -#endif - } - } - - public sealed class WriterParameters { - - Stream symbol_stream; - ISymbolWriterProvider symbol_writer_provider; - bool write_symbols; -#if !SILVERLIGHT && !CF - SR.StrongNameKeyPair key_pair; -#endif - public Stream SymbolStream { - get { return symbol_stream; } - set { symbol_stream = value; } - } - - public ISymbolWriterProvider SymbolWriterProvider { - get { return symbol_writer_provider; } - set { symbol_writer_provider = value; } - } - - public bool WriteSymbols { - get { return write_symbols; } - set { write_symbols = value; } - } -#if !SILVERLIGHT && !CF - public SR.StrongNameKeyPair StrongNameKeyPair { - get { return key_pair; } - set { key_pair = value; } - } -#endif - } - -#endif - - public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider { - - internal Image Image; - internal MetadataSystem MetadataSystem; - internal ReadingMode ReadingMode; - internal ISymbolReaderProvider SymbolReaderProvider; - - internal ISymbolReader symbol_reader; - internal IAssemblyResolver assembly_resolver; - internal IMetadataResolver metadata_resolver; - internal TypeSystem type_system; - - readonly MetadataReader reader; - readonly string fq_name; - - internal ModuleKind kind; - TargetRuntime runtime; - TargetArchitecture architecture; - ModuleAttributes attributes; - Guid mvid; - - internal AssemblyDefinition assembly; - MethodDefinition entry_point; - -#if !READ_ONLY - MetadataImporter importer; -#endif - Collection custom_attributes; - Collection references; - Collection modules; - Collection resources; - Collection exported_types; - TypeDefinitionCollection types; - - public bool IsMain { - get { return kind != ModuleKind.NetModule; } - } - - public ModuleKind Kind { - get { return kind; } - set { kind = value; } - } - - public TargetRuntime Runtime { - get { return runtime; } - set { runtime = value; } - } - - public TargetArchitecture Architecture { - get { return architecture; } - set { architecture = value; } - } - - public ModuleAttributes Attributes { - get { return attributes; } - set { attributes = value; } - } - - public string FullyQualifiedName { - get { return fq_name; } - } - - public Guid Mvid { - get { return mvid; } - set { mvid = value; } - } - - internal bool HasImage { - get { return Image != null; } - } - - public bool HasSymbols { - get { return symbol_reader != null; } - } - - public ISymbolReader SymbolReader { - get { return symbol_reader; } - } - - public override MetadataScopeType MetadataScopeType { - get { return MetadataScopeType.ModuleDefinition; } - } - - public AssemblyDefinition Assembly { - get { return assembly; } - } - -#if !READ_ONLY - internal MetadataImporter MetadataImporter { - get { return importer ?? (importer = new MetadataImporter (this)); } - } -#endif - - public IAssemblyResolver AssemblyResolver { - get { return assembly_resolver ?? (assembly_resolver = new DefaultAssemblyResolver ()); } - } - - public IMetadataResolver MetadataResolver { - get { return metadata_resolver ?? (metadata_resolver = new MetadataResolver (this.AssemblyResolver)); } - } - - public TypeSystem TypeSystem { - get { return type_system ?? (type_system = TypeSystem.CreateTypeSystem (this)); } - } - - public bool HasAssemblyReferences { - get { - if (references != null) - return references.Count > 0; - - return HasImage && Image.HasTable (Table.AssemblyRef); - } - } - - public Collection AssemblyReferences { - get { - if (references != null) - return references; - - if (HasImage) - return references = Read (this, (_, reader) => reader.ReadAssemblyReferences ()); - - return references = new Collection (); - } - } - - public bool HasModuleReferences { - get { - if (modules != null) - return modules.Count > 0; - - return HasImage && Image.HasTable (Table.ModuleRef); - } - } - - public Collection ModuleReferences { - get { - if (modules != null) - return modules; - - if (HasImage) - return modules = Read (this, (_, reader) => reader.ReadModuleReferences ()); - - return modules = new Collection (); - } - } - - public bool HasResources { - get { - if (resources != null) - return resources.Count > 0; - - if (HasImage) - return Image.HasTable (Table.ManifestResource) || Read (this, (_, reader) => reader.HasFileResource ()); - - return false; - } - } - - public Collection Resources { - get { - if (resources != null) - return resources; - - if (HasImage) - return resources = Read (this, (_, reader) => reader.ReadResources ()); - - return resources = new Collection (); - } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (this); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (this)); } - } - - public bool HasTypes { - get { - if (types != null) - return types.Count > 0; - - return HasImage && Image.HasTable (Table.TypeDef); - } - } - - public Collection Types { - get { - if (types != null) - return types; - - if (HasImage) - return types = Read (this, (_, reader) => reader.ReadTypes ()); - - return types = new TypeDefinitionCollection (this); - } - } - - public bool HasExportedTypes { - get { - if (exported_types != null) - return exported_types.Count > 0; - - return HasImage && Image.HasTable (Table.ExportedType); - } - } - - public Collection ExportedTypes { - get { - if (exported_types != null) - return exported_types; - - if (HasImage) - return exported_types = Read (this, (_, reader) => reader.ReadExportedTypes ()); - - return exported_types = new Collection (); - } - } - - public MethodDefinition EntryPoint { - get { - if (entry_point != null) - return entry_point; - - if (HasImage) - return entry_point = Read (this, (_, reader) => reader.ReadEntryPoint ()); - - return entry_point = null; - } - set { entry_point = value; } - } - - internal ModuleDefinition () - { - this.MetadataSystem = new MetadataSystem (); - this.token = new MetadataToken (TokenType.Module, 1); - } - - internal ModuleDefinition (Image image) - : this () - { - this.Image = image; - this.kind = image.Kind; - this.runtime = image.Runtime; - this.architecture = image.Architecture; - this.attributes = image.Attributes; - this.fq_name = image.FileName; - - this.reader = new MetadataReader (this); - } - - public bool HasTypeReference (string fullName) - { - return HasTypeReference (string.Empty, fullName); - } - - public bool HasTypeReference (string scope, string fullName) - { - CheckFullName (fullName); - - if (!HasImage) - return false; - - return GetTypeReference (scope, fullName) != null; - } - - public bool TryGetTypeReference (string fullName, out TypeReference type) - { - return TryGetTypeReference (string.Empty, fullName, out type); - } - - public bool TryGetTypeReference (string scope, string fullName, out TypeReference type) - { - CheckFullName (fullName); - - if (!HasImage) { - type = null; - return false; - } - - return (type = GetTypeReference (scope, fullName)) != null; - } - - TypeReference GetTypeReference (string scope, string fullname) - { - return Read (new Row (scope, fullname), (row, reader) => reader.GetTypeReference (row.Col1, row.Col2)); - } - - public IEnumerable GetTypeReferences () - { - if (!HasImage) - return Empty.Array; - - return Read (this, (_, reader) => reader.GetTypeReferences ()); - } - - public IEnumerable GetMemberReferences () - { - if (!HasImage) - return Empty.Array; - - 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); - - var position = fullName.IndexOf ('/'); - if (position > 0) - return GetNestedType (fullName); - - return ((TypeDefinitionCollection) this.Types).GetType (fullName); - } - - public TypeDefinition GetType (string @namespace, string name) - { - Mixin.CheckName (name); - - return ((TypeDefinitionCollection) this.Types).GetType (@namespace ?? string.Empty, name); - } - - public IEnumerable GetTypes () - { - return GetTypes (Types); - } - - static IEnumerable GetTypes (Collection types) - { - for (int i = 0; i < types.Count; i++) { - var type = types [i]; - - yield return type; - - if (!type.HasNestedTypes) - continue; - - foreach (var nested in GetTypes (type.NestedTypes)) - yield return nested; - } - } - - static void CheckFullName (string fullName) - { - if (fullName == null) - throw new ArgumentNullException ("fullName"); - if (fullName.Length == 0) - throw new ArgumentException (); - } - - TypeDefinition GetNestedType (string fullname) - { - var names = fullname.Split ('/'); - var type = GetType (names [0]); - - if (type == null) - return null; - - for (int i = 1; i < names.Length; i++) { - var nested_type = type.GetNestedType (names [i]); - if (nested_type == null) - return null; - - type = nested_type; - } - - return type; - } - - internal FieldDefinition Resolve (FieldReference field) - { - return MetadataResolver.Resolve (field); - } - - internal MethodDefinition Resolve (MethodReference method) - { - return MetadataResolver.Resolve (method); - } - - internal TypeDefinition Resolve (TypeReference type) - { - return MetadataResolver.Resolve (type); - } - -#if !READ_ONLY - - static void CheckType (object type) - { - if (type == null) - throw new ArgumentNullException ("type"); - } - - static void CheckField (object field) - { - if (field == null) - throw new ArgumentNullException ("field"); - } - - static void CheckMethod (object method) - { - if (method == null) - throw new ArgumentNullException ("method"); - } - - static void CheckContext (IGenericParameterProvider context, ModuleDefinition module) - { - if (context == null) - return; - - if (context.Module != module) - throw new ArgumentException (); - } - -#if !CF - public TypeReference Import (Type type) - { - CheckType (type); - - return MetadataImporter.ImportType (type, null, ImportGenericKind.Definition); - } - - public TypeReference Import (Type type, TypeReference context) - { - return Import (type, (IGenericParameterProvider) context); - } - - public TypeReference Import (Type type, MethodReference context) - { - return Import (type, (IGenericParameterProvider) context); - } - - TypeReference Import (Type type, IGenericParameterProvider context) - { - CheckType (type); - CheckContext (context, this); - - return MetadataImporter.ImportType ( - type, - (IGenericContext) context, - context != null - ? ImportGenericKind.Open - : ImportGenericKind.Definition); - } - - public FieldReference Import (SR.FieldInfo field) - { - CheckField (field); - - return MetadataImporter.ImportField (field, null); - } - - public FieldReference Import (SR.FieldInfo field, TypeReference context) - { - return Import (field, (IGenericParameterProvider) context); - } - - public FieldReference Import (SR.FieldInfo field, MethodReference context) - { - return Import (field, (IGenericParameterProvider) context); - } - - FieldReference Import (SR.FieldInfo field, IGenericParameterProvider context) - { - CheckField (field); - CheckContext (context, this); - - return MetadataImporter.ImportField (field, (IGenericContext) context); - } - - public MethodReference Import (SR.MethodBase method) - { - CheckMethod (method); - - return MetadataImporter.ImportMethod (method, null, ImportGenericKind.Definition); - } - - public MethodReference Import (SR.MethodBase method, TypeReference context) - { - return Import (method, (IGenericParameterProvider) context); - } - - public MethodReference Import (SR.MethodBase method, MethodReference context) - { - return Import (method, (IGenericParameterProvider) context); - } - - MethodReference Import (SR.MethodBase method, IGenericParameterProvider context) - { - CheckMethod (method); - CheckContext (context, this); - - return MetadataImporter.ImportMethod (method, - (IGenericContext) context, - context != null - ? ImportGenericKind.Open - : ImportGenericKind.Definition); - } -#endif - - public TypeReference Import (TypeReference type) - { - CheckType (type); - - if (type.Module == this) - return type; - - return MetadataImporter.ImportType (type, null); - } - - public TypeReference Import (TypeReference type, TypeReference context) - { - return Import (type, (IGenericParameterProvider) context); - } - - public TypeReference Import (TypeReference type, MethodReference context) - { - return Import (type, (IGenericParameterProvider) context); - } - - TypeReference Import (TypeReference type, IGenericParameterProvider context) - { - CheckType (type); - - if (type.Module == this) - return type; - - CheckContext (context, this); - - return MetadataImporter.ImportType (type, (IGenericContext) context); - } - - public FieldReference Import (FieldReference field) - { - CheckField (field); - - if (field.Module == this) - return field; - - return MetadataImporter.ImportField (field, null); - } - - public FieldReference Import (FieldReference field, TypeReference context) - { - return Import (field, (IGenericParameterProvider) context); - } - - public FieldReference Import (FieldReference field, MethodReference context) - { - return Import (field, (IGenericParameterProvider) context); - } - - FieldReference Import (FieldReference field, IGenericParameterProvider context) - { - CheckField (field); - - if (field.Module == this) - return field; - - CheckContext (context, this); - - return MetadataImporter.ImportField (field, (IGenericContext) context); - } - - public MethodReference Import (MethodReference method) - { - CheckMethod (method); - - if (method.Module == this) - return method; - - return MetadataImporter.ImportMethod (method, null); - } - - public MethodReference Import (MethodReference method, TypeReference context) - { - return Import (method, (IGenericParameterProvider) context); - } - - public MethodReference Import (MethodReference method, MethodReference context) - { - return Import (method, (IGenericParameterProvider) context); - } - - MethodReference Import (MethodReference method, IGenericParameterProvider context) - { - CheckMethod (method); - - if (method.Module == this) - return method; - - CheckContext (context, this); - - return MetadataImporter.ImportMethod (method, (IGenericContext) context); - } - -#endif - - public IMetadataTokenProvider LookupToken (int token) - { - return LookupToken (new MetadataToken ((uint) token)); - } - - public IMetadataTokenProvider LookupToken (MetadataToken token) - { - return Read (token, (t, reader) => reader.LookupToken (t)); - } - - internal TRet Read (TItem item, Func read) - { - var position = reader.position; - var context = reader.context; - - var ret = read (item, reader); - - reader.position = position; - reader.context = context; - - return ret; - } - - public bool HasDebugHeader { - get { return Image != null && !Image.Debug.IsZero; } - } - - public ImageDebugDirectory GetDebugHeader (out byte [] header) - { - if (!HasDebugHeader) - throw new InvalidOperationException (); - - return Image.GetDebugHeader (out header); - } - - void ProcessDebugHeader () - { - if (!HasDebugHeader) - return; - - byte [] header; - var directory = GetDebugHeader (out header); - - if (!symbol_reader.ProcessDebugHeader (directory, header)) - throw new InvalidOperationException (); - } - -#if !READ_ONLY - - public static ModuleDefinition CreateModule (string name, ModuleKind kind) - { - return CreateModule (name, new ModuleParameters { Kind = kind }); - } - - public static ModuleDefinition CreateModule (string name, ModuleParameters parameters) - { - Mixin.CheckName (name); - Mixin.CheckParameters (parameters); - - var module = new ModuleDefinition { - Name = name, - kind = parameters.Kind, - runtime = parameters.Runtime, - architecture = parameters.Architecture, - mvid = Guid.NewGuid (), - Attributes = ModuleAttributes.ILOnly, - }; - - 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 = CreateAssemblyName (name); - assembly.main_module = module; - } - - module.Types.Add (new TypeDefinition (string.Empty, "", TypeAttributes.NotPublic)); - - 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 () - { - if (string.IsNullOrEmpty (fq_name)) - throw new InvalidOperationException (); - - var provider = SymbolProvider.GetPlatformReaderProvider (); - if (provider == null) - throw new InvalidOperationException (); - - ReadSymbols (provider.GetSymbolReader (this, fq_name)); - } - - public void ReadSymbols (ISymbolReader reader) - { - if (reader == null) - throw new ArgumentNullException ("reader"); - - symbol_reader = reader; - - ProcessDebugHeader (); - } - - public static ModuleDefinition ReadModule (string fileName) - { - return ReadModule (fileName, new ReaderParameters (ReadingMode.Deferred)); - } - - public static ModuleDefinition ReadModule (Stream stream) - { - return ReadModule (stream, new ReaderParameters (ReadingMode.Deferred)); - } - - public static ModuleDefinition ReadModule (string fileName, ReaderParameters parameters) - { - using (var stream = GetFileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { - return ReadModule (stream, parameters); - } - } - - static void CheckStream (object stream) - { - if (stream == null) - throw new ArgumentNullException ("stream"); - } - - public static ModuleDefinition ReadModule (Stream stream, ReaderParameters parameters) - { - CheckStream (stream); - if (!stream.CanRead || !stream.CanSeek) - throw new ArgumentException (); - Mixin.CheckParameters (parameters); - - return ModuleReader.CreateModuleFrom ( - ImageReader.ReadImageFrom (stream), - parameters); - } - - static Stream GetFileStream (string fileName, FileMode mode, FileAccess access, FileShare share) - { - if (fileName == null) - throw new ArgumentNullException ("fileName"); - if (fileName.Length == 0) - throw new ArgumentException (); - - return new FileStream (fileName, mode, access, share); - } - -#if !READ_ONLY - - public void Write (string fileName) - { - Write (fileName, new WriterParameters ()); - } - - public void Write (Stream stream) - { - Write (stream, new WriterParameters ()); - } - - public void Write (string fileName, WriterParameters parameters) - { - using (var stream = GetFileStream (fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { - Write (stream, parameters); - } - } - - public void Write (Stream stream, WriterParameters parameters) - { - CheckStream (stream); - if (!stream.CanWrite || !stream.CanSeek) - throw new ArgumentException (); - Mixin.CheckParameters (parameters); - - ModuleWriter.WriteModuleTo (this, stream, parameters); - } - -#endif - - } - - static partial class Mixin { - - public static void CheckParameters (object parameters) - { - if (parameters == null) - throw new ArgumentNullException ("parameters"); - } - - public static bool HasImage (this ModuleDefinition self) - { - 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 - var file_stream = self as FileStream; - if (file_stream == null) - return string.Empty; - - return Path.GetFullPath (file_stream.Name); -#else - return string.Empty; -#endif - } - - public static TargetRuntime ParseRuntime (this string self) - { - switch (self [1]) { - case '1': - return self [3] == '0' - ? TargetRuntime.Net_1_0 - : TargetRuntime.Net_1_1; - case '2': - return TargetRuntime.Net_2_0; - case '4': - default: - return TargetRuntime.Net_4_0; - } - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ModuleKind.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ModuleKind.cs deleted file mode 100644 index bbbad72801e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ModuleKind.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// ModuleKind.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public enum ModuleKind { - Dll, - Console, - Windows, - NetModule, - } - - public enum TargetArchitecture { - I386, - AMD64, - IA64, - ARMv7, - } - - [Flags] - public enum ModuleAttributes { - ILOnly = 1, - Required32Bit = 2, - StrongNameSigned = 8, - Preferred32Bit = 0x00020000, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ModuleReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ModuleReference.cs deleted file mode 100644 index 3934b3ceb83..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ModuleReference.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -// ModuleReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public class ModuleReference : IMetadataScope { - - string name; - - internal MetadataToken token; - - public string Name { - get { return name; } - set { name = value; } - } - - public virtual MetadataScopeType MetadataScopeType { - get { return MetadataScopeType.ModuleReference; } - } - - public MetadataToken MetadataToken { - get { return token; } - set { token = value; } - } - - internal ModuleReference () - { - this.token = new MetadataToken (TokenType.ModuleRef); - } - - public ModuleReference (string name) - : this () - { - this.name = name; - } - - public override string ToString () - { - return name; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/NativeType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/NativeType.cs deleted file mode 100644 index 88da9805e87..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/NativeType.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// NativeType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum NativeType { - None = 0x66, - - Boolean = 0x02, - I1 = 0x03, - U1 = 0x04, - I2 = 0x05, - U2 = 0x06, - I4 = 0x07, - U4 = 0x08, - I8 = 0x09, - U8 = 0x0a, - R4 = 0x0b, - R8 = 0x0c, - LPStr = 0x14, - Int = 0x1f, - UInt = 0x20, - Func = 0x26, - Array = 0x2a, - - // Msft specific - Currency = 0x0f, - BStr = 0x13, - LPWStr = 0x15, - LPTStr = 0x16, - FixedSysString = 0x17, - IUnknown = 0x19, - IDispatch = 0x1a, - Struct = 0x1b, - IntF = 0x1c, - SafeArray = 0x1d, - FixedArray = 0x1e, - ByValStr = 0x22, - ANSIBStr = 0x23, - TBStr = 0x24, - VariantBool = 0x25, - ASAny = 0x28, - LPStruct = 0x2b, - CustomMarshaler = 0x2c, - Error = 0x2d, - Max = 0x50 - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs deleted file mode 100644 index bb36838253d..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// PInvokeAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum PInvokeAttributes : ushort { - NoMangle = 0x0001, // PInvoke is to use the member name as specified - - // Character set - CharSetMask = 0x0006, - CharSetNotSpec = 0x0000, - CharSetAnsi = 0x0002, - CharSetUnicode = 0x0004, - CharSetAuto = 0x0006, - - SupportsLastError = 0x0040, // Information about target function. Not relevant for fields - - // Calling convetion - CallConvMask = 0x0700, - CallConvWinapi = 0x0100, - CallConvCdecl = 0x0200, - CallConvStdCall = 0x0300, - CallConvThiscall = 0x0400, - CallConvFastcall = 0x0500, - - BestFitMask = 0x0030, - BestFitEnabled = 0x0010, - BestFitDisabled = 0x0020, - - ThrowOnUnmappableCharMask = 0x3000, - ThrowOnUnmappableCharEnabled = 0x1000, - ThrowOnUnmappableCharDisabled = 0x2000, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs deleted file mode 100644 index cfd817c8d05..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs +++ /dev/null @@ -1,138 +0,0 @@ -// -// PInvokeInfo.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public sealed class PInvokeInfo { - - ushort attributes; - string entry_point; - ModuleReference module; - - public PInvokeAttributes Attributes { - get { return (PInvokeAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public string EntryPoint { - get { return entry_point; } - set { entry_point = value; } - } - - public ModuleReference Module { - get { return module; } - set { module = value; } - } - - #region PInvokeAttributes - - public bool IsNoMangle { - get { return attributes.GetAttributes ((ushort) PInvokeAttributes.NoMangle); } - set { attributes = attributes.SetAttributes ((ushort) PInvokeAttributes.NoMangle, value); } - } - - public bool IsCharSetNotSpec { - get { return attributes.GetMaskedAttributes((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetNotSpec); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetNotSpec, value); } - } - - public bool IsCharSetAnsi { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetAnsi); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetAnsi, value); } - } - - public bool IsCharSetUnicode { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetUnicode); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetUnicode, value); } - } - - public bool IsCharSetAuto { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetAuto); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CharSetMask, (ushort) PInvokeAttributes.CharSetAuto, value); } - } - - public bool SupportsLastError { - get { return attributes.GetAttributes ((ushort) PInvokeAttributes.SupportsLastError); } - set { attributes = attributes.SetAttributes ((ushort) PInvokeAttributes.SupportsLastError, value); } - } - - public bool IsCallConvWinapi { - get { return attributes.GetMaskedAttributes((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvWinapi); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvWinapi, value); } - } - - public bool IsCallConvCdecl { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvCdecl); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvCdecl, value); } - } - - public bool IsCallConvStdCall { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvStdCall); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvStdCall, value); } - } - - public bool IsCallConvThiscall { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvThiscall); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvThiscall, value); } - } - - public bool IsCallConvFastcall { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvFastcall); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvFastcall, value); } - } - - public bool IsBestFitEnabled { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitEnabled); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitEnabled, value); } - } - - public bool IsBestFitDisabled { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitDisabled); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitDisabled, value); } - } - - public bool IsThrowOnUnmappableCharEnabled { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.ThrowOnUnmappableCharMask, (ushort) PInvokeAttributes.ThrowOnUnmappableCharEnabled); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.ThrowOnUnmappableCharMask, (ushort) PInvokeAttributes.ThrowOnUnmappableCharEnabled, value); } - } - - public bool IsThrowOnUnmappableCharDisabled { - get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.ThrowOnUnmappableCharMask, (ushort) PInvokeAttributes.ThrowOnUnmappableCharDisabled); } - set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.ThrowOnUnmappableCharMask, (ushort) PInvokeAttributes.ThrowOnUnmappableCharDisabled, value); } - } - - #endregion - - public PInvokeInfo (PInvokeAttributes attributes, string entryPoint, ModuleReference module) - { - this.attributes = (ushort) attributes; - this.entry_point = entryPoint; - this.module = module; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs deleted file mode 100644 index e0bc825d8b3..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// ParameterAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum ParameterAttributes : ushort { - None = 0x0000, - In = 0x0001, // Param is [In] - Out = 0x0002, // Param is [Out] - Lcid = 0x0004, - Retval = 0x0008, - Optional = 0x0010, // Param is optional - HasDefault = 0x1000, // Param has default value - HasFieldMarshal = 0x2000, // Param has field marshal - Unused = 0xcfe0 // Reserved: shall be zero in a conforming implementation - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs deleted file mode 100644 index 26152bd8df5..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs +++ /dev/null @@ -1,172 +0,0 @@ -// -// ParameterDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class ParameterDefinition : ParameterReference, ICustomAttributeProvider, IConstantProvider, IMarshalInfoProvider { - - ushort attributes; - - internal IMethodSignature method; - - object constant = Mixin.NotResolved; - Collection custom_attributes; - MarshalInfo marshal_info; - - public ParameterAttributes Attributes { - get { return (ParameterAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public IMethodSignature Method { - get { return method; } - } - - public int Sequence { - get { - if (method == null) - return -1; - - return method.HasImplicitThis () ? index + 1 : index; - } - } - - public bool HasConstant { - get { - ResolveConstant (); - - return constant != Mixin.NoValue; - } - set { if (!value) constant = Mixin.NoValue; } - } - - public object Constant { - get { return HasConstant ? constant : null; } - set { constant = value; } - } - - void ResolveConstant () - { - if (constant != Mixin.NotResolved) - return; - - this.ResolveConstant (ref constant, parameter_type.Module); - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (parameter_type.Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (parameter_type.Module)); } - } - - public bool HasMarshalInfo { - get { - if (marshal_info != null) - return true; - - return this.GetHasMarshalInfo (parameter_type.Module); - } - } - - public MarshalInfo MarshalInfo { - get { return marshal_info ?? (marshal_info = this.GetMarshalInfo (parameter_type.Module)); } - set { marshal_info = value; } - } - - #region ParameterAttributes - - public bool IsIn { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.In); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.In, value); } - } - - public bool IsOut { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.Out); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Out, value); } - } - - public bool IsLcid { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.Lcid); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Lcid, value); } - } - - public bool IsReturnValue { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.Retval); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Retval, value); } - } - - public bool IsOptional { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.Optional); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Optional, value); } - } - - public bool HasDefault { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasDefault); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasDefault, value); } - } - - public bool HasFieldMarshal { - get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasFieldMarshal); } - set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasFieldMarshal, value); } - } - - #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) - { - } - - public ParameterDefinition (string name, ParameterAttributes attributes, TypeReference parameterType) - : base (name, parameterType) - { - this.attributes = (ushort) attributes; - this.token = new MetadataToken (TokenType.Param); - } - - public override ParameterDefinition Resolve () - { - return this; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs deleted file mode 100644 index bd8b1c1390e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -// ParameterDefinitionCollection.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - sealed class ParameterDefinitionCollection : Collection { - - readonly IMethodSignature method; - - internal ParameterDefinitionCollection (IMethodSignature method) - { - this.method = method; - } - - internal ParameterDefinitionCollection (IMethodSignature method, int capacity) - : base (capacity) - { - this.method = method; - } - - protected override void OnAdd (ParameterDefinition item, int index) - { - item.method = method; - item.index = index; - } - - protected override void OnInsert (ParameterDefinition item, int index) - { - item.method = method; - item.index = index; - - for (int i = index; i < size; i++) - items [i].index = i + 1; - } - - protected override void OnSet (ParameterDefinition item, int index) - { - item.method = method; - item.index = index; - } - - protected override void OnRemove (ParameterDefinition item, int index) - { - item.method = null; - item.index = -1; - - for (int i = index + 1; i < size; i++) - items [i].index = i - 1; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ParameterReference.cs deleted file mode 100644 index 46b057cd9f3..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ParameterReference.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// ParameterReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - public abstract class ParameterReference : IMetadataTokenProvider { - - string name; - internal int index = -1; - protected TypeReference parameter_type; - internal MetadataToken token; - - public string Name { - get { return name; } - set { name = value; } - } - - public int Index { - get { return index; } - } - - public TypeReference ParameterType { - get { return parameter_type; } - set { parameter_type = value; } - } - - public MetadataToken MetadataToken { - get { return token; } - set { token = value; } - } - - internal ParameterReference (string name, TypeReference parameterType) - { - if (parameterType == null) - throw new ArgumentNullException ("parameterType"); - - this.name = name ?? string.Empty; - this.parameter_type = parameterType; - } - - public override string ToString () - { - return name; - } - - public abstract ParameterDefinition Resolve (); - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PinnedType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PinnedType.cs deleted file mode 100644 index ff59cfb7e18..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PinnedType.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// PinnedType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class PinnedType : TypeSpecification { - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override bool IsPinned { - get { return true; } - } - - public PinnedType (TypeReference type) - : base (type) - { - Mixin.CheckType (type); - this.etype = MD.ElementType.Pinned; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PointerType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PointerType.cs deleted file mode 100644 index a142e144095..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PointerType.cs +++ /dev/null @@ -1,61 +0,0 @@ -// -// PointerType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class PointerType : TypeSpecification { - - public override string Name { - get { return base.Name + "*"; } - } - - public override string FullName { - get { return base.FullName + "*"; } - } - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override bool IsPointer { - get { return true; } - } - - public PointerType (TypeReference type) - : base (type) - { - Mixin.CheckType (type); - this.etype = MD.ElementType.Ptr; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs deleted file mode 100644 index 1be0413f287..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// PropertyAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum PropertyAttributes : ushort { - None = 0x0000, - SpecialName = 0x0200, // Property is special - RTSpecialName = 0x0400, // Runtime(metadata internal APIs) should check name encoding - HasDefault = 0x1000, // Property has default - Unused = 0xe9ff // Reserved: shall be zero in a conforming implementation - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs deleted file mode 100644 index 42878a0948a..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs +++ /dev/null @@ -1,265 +0,0 @@ -// -// PropertyDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Text; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class PropertyDefinition : PropertyReference, IMemberDefinition, IConstantProvider { - - bool? has_this; - ushort attributes; - - Collection custom_attributes; - - internal MethodDefinition get_method; - internal MethodDefinition set_method; - internal Collection other_methods; - - object constant = Mixin.NotResolved; - - public PropertyAttributes Attributes { - get { return (PropertyAttributes) attributes; } - set { attributes = (ushort) value; } - } - - public bool HasThis { - get { - if (has_this.HasValue) - return has_this.Value; - - if (GetMethod != null) - return get_method.HasThis; - - if (SetMethod != null) - return set_method.HasThis; - - return false; - } - set { has_this = value; } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); } - } - - public MethodDefinition GetMethod { - get { - if (get_method != null) - return get_method; - - InitializeMethods (); - return get_method; - } - set { get_method = value; } - } - - public MethodDefinition SetMethod { - get { - if (set_method != null) - return set_method; - - InitializeMethods (); - return set_method; - } - set { set_method = value; } - } - - public bool HasOtherMethods { - get { - if (other_methods != null) - return other_methods.Count > 0; - - InitializeMethods (); - return !other_methods.IsNullOrEmpty (); - } - } - - public Collection OtherMethods { - get { - if (other_methods != null) - return other_methods; - - InitializeMethods (); - - if (other_methods != null) - return other_methods; - - return other_methods = new Collection (); - } - } - - public bool HasParameters { - get { - InitializeMethods (); - - if (get_method != null) - return get_method.HasParameters; - - if (set_method != null) - return set_method.HasParameters && set_method.Parameters.Count > 1; - - return false; - } - } - - public override Collection Parameters { - get { - InitializeMethods (); - - if (get_method != null) - return MirrorParameters (get_method, 0); - - if (set_method != null) - return MirrorParameters (set_method, 1); - - return new Collection (); - } - } - - static Collection MirrorParameters (MethodDefinition method, int bound) - { - var parameters = new Collection (); - if (!method.HasParameters) - return parameters; - - var original_parameters = method.Parameters; - var end = original_parameters.Count - bound; - - for (int i = 0; i < end; i++) - parameters.Add (original_parameters [i]); - - return parameters; - } - - public bool HasConstant { - get { - ResolveConstant (); - - return constant != Mixin.NoValue; - } - set { if (!value) constant = Mixin.NoValue; } - } - - public object Constant { - get { return HasConstant ? constant : null; } - set { constant = value; } - } - - void ResolveConstant () - { - if (constant != Mixin.NotResolved) - return; - - this.ResolveConstant (ref constant, Module); - } - - #region PropertyAttributes - - public bool IsSpecialName { - get { return attributes.GetAttributes ((ushort) PropertyAttributes.SpecialName); } - set { attributes = attributes.SetAttributes ((ushort) PropertyAttributes.SpecialName, value); } - } - - public bool IsRuntimeSpecialName { - get { return attributes.GetAttributes ((ushort) PropertyAttributes.RTSpecialName); } - set { attributes = attributes.SetAttributes ((ushort) PropertyAttributes.RTSpecialName, value); } - } - - public bool HasDefault { - get { return attributes.GetAttributes ((ushort) PropertyAttributes.HasDefault); } - set { attributes = attributes.SetAttributes ((ushort) PropertyAttributes.HasDefault, value); } - } - - #endregion - - public new TypeDefinition DeclaringType { - get { return (TypeDefinition) base.DeclaringType; } - set { base.DeclaringType = value; } - } - - public override bool IsDefinition { - get { return true; } - } - - public override string FullName { - get { - var builder = new StringBuilder (); - builder.Append (PropertyType.ToString ()); - builder.Append (' '); - builder.Append (MemberFullName ()); - builder.Append ('('); - if (HasParameters) { - var parameters = Parameters; - for (int i = 0; i < parameters.Count; i++) { - if (i > 0) - builder.Append (','); - builder.Append (parameters [i].ParameterType.FullName); - } - } - builder.Append (')'); - return builder.ToString (); - } - } - - public PropertyDefinition (string name, PropertyAttributes attributes, TypeReference propertyType) - : base (name, propertyType) - { - this.attributes = (ushort) attributes; - this.token = new MetadataToken (TokenType.Property); - } - - void InitializeMethods () - { - if (get_method != null || set_method != null) - return; - - var module = this.Module; - if (!module.HasImage ()) - return; - - module.Read (this, (property, reader) => reader.ReadMethods (property)); - } - - public override PropertyDefinition Resolve () - { - return this; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/PropertyReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/PropertyReference.cs deleted file mode 100644 index 0dcfc952fef..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/PropertyReference.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// PropertyReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public abstract class PropertyReference : MemberReference { - - TypeReference property_type; - - public TypeReference PropertyType { - get { return property_type; } - set { property_type = value; } - } - - public abstract Collection Parameters { - get; - } - - internal PropertyReference (string name, TypeReference propertyType) - : base (name) - { - if (propertyType == null) - throw new ArgumentNullException ("propertyType"); - - property_type = propertyType; - } - - public abstract PropertyDefinition Resolve (); - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/ReferenceType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/ReferenceType.cs deleted file mode 100644 index 7940c617c78..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/ReferenceType.cs +++ /dev/null @@ -1,61 +0,0 @@ -// -// ByReferenceType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class ByReferenceType : TypeSpecification { - - public override string Name { - get { return base.Name + "&"; } - } - - public override string FullName { - get { return base.FullName + "&"; } - } - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override bool IsByReference { - get { return true; } - } - - public ByReferenceType (TypeReference type) - : base (type) - { - Mixin.CheckType (type); - this.etype = MD.ElementType.ByRef; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/Resource.cs b/mcs/class/Mono.Cecil/Mono.Cecil/Resource.cs deleted file mode 100644 index eff7f41aa1c..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/Resource.cs +++ /dev/null @@ -1,76 +0,0 @@ -// -// ResourceType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum ResourceType { - Linked, - Embedded, - AssemblyLinked, - } - - public abstract class Resource { - - string name; - uint attributes; - - public string Name { - get { return name; } - set { name = value; } - } - - public ManifestResourceAttributes Attributes { - get { return (ManifestResourceAttributes) attributes; } - set { attributes = (uint) value; } - } - - public abstract ResourceType ResourceType { - get; - } - - #region ManifestResourceAttributes - - public bool IsPublic { - get { return attributes.GetMaskedAttributes ((uint) ManifestResourceAttributes.VisibilityMask, (uint) ManifestResourceAttributes.Public); } - set { attributes = attributes.SetMaskedAttributes ((uint) ManifestResourceAttributes.VisibilityMask, (uint) ManifestResourceAttributes.Public, value); } - } - - public bool IsPrivate { - get { return attributes.GetMaskedAttributes ((uint) ManifestResourceAttributes.VisibilityMask, (uint) ManifestResourceAttributes.Private); } - set { attributes = attributes.SetMaskedAttributes ((uint) ManifestResourceAttributes.VisibilityMask, (uint) ManifestResourceAttributes.Private, value); } - } - - #endregion - - internal Resource (string name, ManifestResourceAttributes attributes) - { - this.name = name; - this.attributes = (uint) attributes; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs b/mcs/class/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs deleted file mode 100644 index 837472a1199..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs +++ /dev/null @@ -1,191 +0,0 @@ -// -// SecurityDeclaration.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public enum SecurityAction : ushort { - Request = 1, - Demand = 2, - Assert = 3, - Deny = 4, - PermitOnly = 5, - LinkDemand = 6, - InheritDemand = 7, - RequestMinimum = 8, - RequestOptional = 9, - RequestRefuse = 10, - PreJitGrant = 11, - PreJitDeny = 12, - NonCasDemand = 13, - NonCasLinkDemand = 14, - NonCasInheritance = 15 - } - - public interface ISecurityDeclarationProvider : IMetadataTokenProvider { - - bool HasSecurityDeclarations { get; } - Collection SecurityDeclarations { get; } - } - - public sealed class SecurityAttribute : ICustomAttribute { - - TypeReference attribute_type; - - internal Collection fields; - internal Collection properties; - - public TypeReference AttributeType { - get { return attribute_type; } - set { attribute_type = value; } - } - - public bool HasFields { - get { return !fields.IsNullOrEmpty (); } - } - - public Collection Fields { - get { return fields ?? (fields = new Collection ()); } - } - - public bool HasProperties { - get { return !properties.IsNullOrEmpty (); } - } - - public Collection Properties { - get { return properties ?? (properties = new Collection ()); } - } - - public SecurityAttribute (TypeReference attributeType) - { - this.attribute_type = attributeType; - } - } - - public sealed class SecurityDeclaration { - - readonly internal uint signature; - byte [] blob; - readonly ModuleDefinition module; - - internal bool resolved; - SecurityAction action; - internal Collection security_attributes; - - public SecurityAction Action { - get { return action; } - set { action = value; } - } - - public bool HasSecurityAttributes { - get { - Resolve (); - - return !security_attributes.IsNullOrEmpty (); - } - } - - public Collection SecurityAttributes { - get { - Resolve (); - - return security_attributes ?? (security_attributes = new Collection ()); - } - } - - internal bool HasImage { - get { return module != null && module.HasImage; } - } - - internal SecurityDeclaration (SecurityAction action, uint signature, ModuleDefinition module) - { - this.action = action; - this.signature = signature; - this.module = module; - } - - public SecurityDeclaration (SecurityAction action) - { - this.action = action; - 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 blob = module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationBlob (declaration.signature)); - } - - void Resolve () - { - if (resolved || !HasImage) - return; - - module.Read (this, (declaration, reader) => { - reader.ReadSecurityDeclarationSignature (declaration); - return this; - }); - - resolved = true; - } - } - - static partial class Mixin { - - public static bool GetHasSecurityDeclarations ( - this ISecurityDeclarationProvider self, - ModuleDefinition module) - { - return module.HasImage () && module.Read (self, (provider, reader) => reader.HasSecurityDeclarations (provider)); - } - - public static Collection GetSecurityDeclarations ( - this ISecurityDeclarationProvider self, - ModuleDefinition module) - { - return module.HasImage () - ? module.Read (self, (provider, reader) => reader.ReadSecurityDeclarations (provider)) - : new Collection (); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/SentinelType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/SentinelType.cs deleted file mode 100644 index 664d75bfd89..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/SentinelType.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// SentinelType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using MD = Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public sealed class SentinelType : TypeSpecification { - - public override bool IsValueType { - get { return false; } - set { throw new InvalidOperationException (); } - } - - public override bool IsSentinel { - get { return true; } - } - - public SentinelType (TypeReference type) - : base (type) - { - Mixin.CheckType (type); - this.etype = MD.ElementType.Sentinel; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TargetRuntime.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TargetRuntime.cs deleted file mode 100644 index 9b49a5f77e2..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TargetRuntime.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// TargetRuntime.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum TargetRuntime { - Net_1_0, - Net_1_1, - Net_2_0, - Net_4_0, - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeAttributes.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeAttributes.cs deleted file mode 100644 index 86fbc4dba5e..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeAttributes.cs +++ /dev/null @@ -1,81 +0,0 @@ -// -// TypeAttributes.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Cecil { - - [Flags] - public enum TypeAttributes : uint { - // Visibility attributes - VisibilityMask = 0x00000007, // Use this mask to retrieve visibility information - NotPublic = 0x00000000, // Class has no public scope - Public = 0x00000001, // Class has public scope - NestedPublic = 0x00000002, // Class is nested with public visibility - NestedPrivate = 0x00000003, // Class is nested with private visibility - NestedFamily = 0x00000004, // Class is nested with family visibility - NestedAssembly = 0x00000005, // Class is nested with assembly visibility - NestedFamANDAssem = 0x00000006, // Class is nested with family and assembly visibility - NestedFamORAssem = 0x00000007, // Class is nested with family or assembly visibility - - // Class layout attributes - LayoutMask = 0x00000018, // Use this mask to retrieve class layout information - AutoLayout = 0x00000000, // Class fields are auto-laid out - SequentialLayout = 0x00000008, // Class fields are laid out sequentially - ExplicitLayout = 0x00000010, // Layout is supplied explicitly - - // Class semantics attributes - ClassSemanticMask = 0x00000020, // Use this mask to retrieve class semantics information - Class = 0x00000000, // Type is a class - Interface = 0x00000020, // Type is an interface - - // Special semantics in addition to class semantics - Abstract = 0x00000080, // Class is abstract - Sealed = 0x00000100, // Class cannot be extended - SpecialName = 0x00000400, // Class name is special - - // Implementation attributes - Import = 0x00001000, // Class/Interface is imported - Serializable = 0x00002000, // Class is serializable - WindowsRuntime = 0x00004000, // Windows Runtime type - - // String formatting attributes - StringFormatMask = 0x00030000, // Use this mask to retrieve string information for native interop - AnsiClass = 0x00000000, // LPSTR is interpreted as ANSI - UnicodeClass = 0x00010000, // LPSTR is interpreted as Unicode - AutoClass = 0x00020000, // LPSTR is interpreted automatically - - // Class initialization attributes - BeforeFieldInit = 0x00100000, // Initialize the class before first static field access - - // Additional flags - RTSpecialName = 0x00000800, // CLI provides 'special' behavior, depending upon the name of the Type - HasSecurity = 0x00040000, // Type has security associate with it - Forwarder = 0x00200000, // Exported type is a type forwarder - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinition.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinition.cs deleted file mode 100644 index 4079406d405..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinition.cs +++ /dev/null @@ -1,517 +0,0 @@ -// -// TypeDefinition.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using Mono.Cecil.Metadata; -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public sealed class TypeDefinition : TypeReference, IMemberDefinition, ISecurityDeclarationProvider { - - uint attributes; - TypeReference base_type; - internal Range fields_range; - internal Range methods_range; - - short packing_size = Mixin.NotResolvedMarker; - int class_size = Mixin.NotResolvedMarker; - - Collection interfaces; - Collection nested_types; - Collection methods; - Collection fields; - Collection events; - Collection properties; - Collection custom_attributes; - Collection security_declarations; - - public TypeAttributes Attributes { - get { return (TypeAttributes) attributes; } - set { attributes = (uint) value; } - } - - public TypeReference BaseType { - get { return base_type; } - set { base_type = value; } - } - - void ResolveLayout () - { - if (packing_size != Mixin.NotResolvedMarker || class_size != Mixin.NotResolvedMarker) - return; - - if (!HasImage) { - packing_size = Mixin.NoDataMarker; - class_size = Mixin.NoDataMarker; - return; - } - - var row = Module.Read (this, (type, reader) => reader.ReadTypeLayout (type)); - - packing_size = row.Col1; - class_size = row.Col2; - } - - public bool HasLayoutInfo { - get { - if (packing_size >= 0 || class_size >= 0) - return true; - - ResolveLayout (); - - return packing_size >= 0 || class_size >= 0; - } - } - - public short PackingSize { - get { - if (packing_size >= 0) - return packing_size; - - ResolveLayout (); - - return packing_size >= 0 ? packing_size : (short) -1; - } - set { packing_size = value; } - } - - public int ClassSize { - get { - if (class_size >= 0) - return class_size; - - ResolveLayout (); - - return class_size >= 0 ? class_size : -1; - } - set { class_size = value; } - } - - public bool HasInterfaces { - get { - if (interfaces != null) - return interfaces.Count > 0; - - if (HasImage) - return Module.Read (this, (type, reader) => reader.HasInterfaces (type)); - - return false; - } - } - - public Collection Interfaces { - get { - if (interfaces != null) - return interfaces; - - if (HasImage) - return interfaces = Module.Read (this, (type, reader) => reader.ReadInterfaces (type)); - - return interfaces = new Collection (); - } - } - - public bool HasNestedTypes { - get { - if (nested_types != null) - return nested_types.Count > 0; - - if (HasImage) - return Module.Read (this, (type, reader) => reader.HasNestedTypes (type)); - - return false; - } - } - - public Collection NestedTypes { - get { - if (nested_types != null) - return nested_types; - - if (HasImage) - return nested_types = Module.Read (this, (type, reader) => reader.ReadNestedTypes (type)); - - return nested_types = new MemberDefinitionCollection (this); - } - } - - public bool HasMethods { - get { - if (methods != null) - return methods.Count > 0; - - if (HasImage) - return methods_range.Length > 0; - - return false; - } - } - - public Collection Methods { - get { - if (methods != null) - return methods; - - if (HasImage) - return methods = Module.Read (this, (type, reader) => reader.ReadMethods (type)); - - return methods = new MemberDefinitionCollection (this); - } - } - - public bool HasFields { - get { - if (fields != null) - return fields.Count > 0; - - if (HasImage) - return fields_range.Length > 0; - - return false; - } - } - - public Collection Fields { - get { - if (fields != null) - return fields; - - if (HasImage) - return fields = Module.Read (this, (type, reader) => reader.ReadFields (type)); - - return fields = new MemberDefinitionCollection (this); - } - } - - public bool HasEvents { - get { - if (events != null) - return events.Count > 0; - - if (HasImage) - return Module.Read (this, (type, reader) => reader.HasEvents (type)); - - return false; - } - } - - public Collection Events { - get { - if (events != null) - return events; - - if (HasImage) - return events = Module.Read (this, (type, reader) => reader.ReadEvents (type)); - - return events = new MemberDefinitionCollection (this); - } - } - - public bool HasProperties { - get { - if (properties != null) - return properties.Count > 0; - - if (HasImage) - return Module.Read (this, (type, reader) => reader.HasProperties (type)); - - return false; - } - } - - public Collection Properties { - get { - if (properties != null) - return properties; - - if (HasImage) - return properties = Module.Read (this, (type, reader) => reader.ReadProperties (type)); - - return properties = new MemberDefinitionCollection (this); - } - } - - public bool HasSecurityDeclarations { - get { - if (security_declarations != null) - return security_declarations.Count > 0; - - return this.GetHasSecurityDeclarations (Module); - } - } - - public Collection SecurityDeclarations { - get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (Module)); } - } - - public bool HasCustomAttributes { - get { - if (custom_attributes != null) - return custom_attributes.Count > 0; - - return this.GetHasCustomAttributes (Module); - } - } - - public Collection CustomAttributes { - get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); } - } - - public override bool HasGenericParameters { - get { - if (generic_parameters != null) - return generic_parameters.Count > 0; - - return this.GetHasGenericParameters (Module); - } - } - - public override Collection GenericParameters { - get { return generic_parameters ?? (generic_parameters = this.GetGenericParameters (Module)); } - } - - #region TypeAttributes - - public bool IsNotPublic { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic, value); } - } - - public bool IsPublic { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public, value); } - } - - public bool IsNestedPublic { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic, value); } - } - - public bool IsNestedPrivate { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate, value); } - } - - public bool IsNestedFamily { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily, value); } - } - - public bool IsNestedAssembly { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly, value); } - } - - public bool IsNestedFamilyAndAssembly { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem, value); } - } - - public bool IsNestedFamilyOrAssembly { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem, value); } - } - - public bool IsAutoLayout { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout, value); } - } - - public bool IsSequentialLayout { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout, value); } - } - - public bool IsExplicitLayout { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout, value); } - } - - public bool IsClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class, value); } - } - - public bool IsInterface { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface, value); } - } - - public bool IsAbstract { - get { return attributes.GetAttributes ((uint) TypeAttributes.Abstract); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Abstract, value); } - } - - public bool IsSealed { - get { return attributes.GetAttributes ((uint) TypeAttributes.Sealed); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Sealed, value); } - } - - public bool IsSpecialName { - get { return attributes.GetAttributes ((uint) TypeAttributes.SpecialName); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.SpecialName, value); } - } - - public bool IsImport { - get { return attributes.GetAttributes ((uint) TypeAttributes.Import); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Import, value); } - } - - public bool IsSerializable { - get { return attributes.GetAttributes ((uint) TypeAttributes.Serializable); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Serializable, value); } - } - - public bool IsWindowsRuntime { - get { return attributes.GetAttributes ((uint) TypeAttributes.WindowsRuntime); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.WindowsRuntime, value); } - } - - public bool IsAnsiClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass, value); } - } - - public bool IsUnicodeClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass, value); } - } - - public bool IsAutoClass { - get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass); } - set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass, value); } - } - - public bool IsBeforeFieldInit { - get { return attributes.GetAttributes ((uint) TypeAttributes.BeforeFieldInit); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.BeforeFieldInit, value); } - } - - public bool IsRuntimeSpecialName { - get { return attributes.GetAttributes ((uint) TypeAttributes.RTSpecialName); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.RTSpecialName, value); } - } - - public bool HasSecurity { - get { return attributes.GetAttributes ((uint) TypeAttributes.HasSecurity); } - set { attributes = attributes.SetAttributes ((uint) TypeAttributes.HasSecurity, value); } - } - - #endregion - - public bool IsEnum { - get { return base_type != null && base_type.IsTypeOf ("System", "Enum"); } - } - - public override bool IsValueType { - get { - if (base_type == null) - return false; - - return base_type.IsTypeOf ("System", "Enum") || (base_type.IsTypeOf ("System", "ValueType") && !this.IsTypeOf ("System", "Enum")); - } - } - - 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; } - } - - public new TypeDefinition DeclaringType { - get { return (TypeDefinition) base.DeclaringType; } - set { base.DeclaringType = value; } - } - - public TypeDefinition (string @namespace, string name, TypeAttributes attributes) - : base (@namespace, name) - { - this.attributes = (uint) attributes; - this.token = new MetadataToken (TokenType.TypeDef); - } - - public TypeDefinition (string @namespace, string name, TypeAttributes attributes, TypeReference baseType) : - this (@namespace, name, attributes) - { - this.BaseType = baseType; - } - - public override TypeDefinition Resolve () - { - return this; - } - } - - static partial class Mixin { - - public static TypeReference GetEnumUnderlyingType (this TypeDefinition self) - { - var fields = self.Fields; - - for (int i = 0; i < fields.Count; i++) { - var field = fields [i]; - if (!field.IsStatic) - return field.FieldType; - } - - throw new ArgumentException (); - } - - public static TypeDefinition GetNestedType (this TypeDefinition self, string name) - { - if (!self.HasNestedTypes) - return null; - - var nested_types = self.NestedTypes; - - for (int i = 0; i < nested_types.Count; i++) { - var nested_type = nested_types [i]; - if (nested_type.Name == name) - return nested_type; - } - - return null; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs deleted file mode 100644 index eae712282f9..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs +++ /dev/null @@ -1,118 +0,0 @@ -// -// TypeDefinitionCollection.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; - -using Mono.Cecil.Metadata; - -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - using Slot = Row; - - sealed class TypeDefinitionCollection : Collection { - - readonly ModuleDefinition container; - readonly Dictionary name_cache; - - internal TypeDefinitionCollection (ModuleDefinition container) - { - this.container = container; - this.name_cache = new Dictionary (new RowEqualityComparer ()); - } - - internal TypeDefinitionCollection (ModuleDefinition container, int capacity) - : base (capacity) - { - this.container = container; - this.name_cache = new Dictionary (capacity, new RowEqualityComparer ()); - } - - protected override void OnAdd (TypeDefinition item, int index) - { - Attach (item); - } - - protected override void OnSet (TypeDefinition item, int index) - { - Attach (item); - } - - protected override void OnInsert (TypeDefinition item, int index) - { - Attach (item); - } - - protected override void OnRemove (TypeDefinition item, int index) - { - Detach (item); - } - - protected override void OnClear () - { - foreach (var type in this) - Detach (type); - } - - void Attach (TypeDefinition type) - { - if (type.Module != null && type.Module != container) - throw new ArgumentException ("Type already attached"); - - type.module = container; - type.scope = container; - name_cache [new Slot (type.Namespace, type.Name)] = type; - } - - void Detach (TypeDefinition type) - { - type.module = null; - type.scope = null; - name_cache.Remove (new Slot (type.Namespace, type.Name)); - } - - public TypeDefinition GetType (string fullname) - { - string @namespace, name; - TypeParser.SplitFullName (fullname, out @namespace, out name); - - return GetType (@namespace, name); - } - - public TypeDefinition GetType (string @namespace, string name) - { - TypeDefinition type; - if (name_cache.TryGetValue (new Slot (@namespace, name), out type)) - return type; - - return null; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeParser.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeParser.cs deleted file mode 100644 index 06dc935a584..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeParser.cs +++ /dev/null @@ -1,555 +0,0 @@ -// -// TypeParser.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Text; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - class TypeParser { - - class Type { - public const int Ptr = -1; - public const int ByRef = -2; - public const int SzArray = -3; - - public string type_fullname; - public string [] nested_names; - public int arity; - public int [] specs; - public Type [] generic_arguments; - public string assembly; - } - - readonly string fullname; - readonly int length; - - int position; - - TypeParser (string fullname) - { - this.fullname = fullname; - this.length = fullname.Length; - } - - Type ParseType (bool fq_name) - { - var type = new Type (); - type.type_fullname = ParsePart (); - - type.nested_names = ParseNestedNames (); - - if (TryGetArity (type)) - type.generic_arguments = ParseGenericArguments (type.arity); - - type.specs = ParseSpecs (); - - if (fq_name) - type.assembly = ParseAssemblyName (); - - return type; - } - - static bool TryGetArity (Type type) - { - int arity = 0; - - TryAddArity (type.type_fullname, ref arity); - - var nested_names = type.nested_names; - if (!nested_names.IsNullOrEmpty ()) { - for (int i = 0; i < nested_names.Length; i++) - TryAddArity (nested_names [i], ref arity); - } - - type.arity = arity; - return arity > 0; - } - - static bool TryGetArity (string name, out int arity) - { - arity = 0; - var index = name.LastIndexOf ('`'); - if (index == -1) - return false; - - return ParseInt32 (name.Substring (index + 1), out arity); - } - - static bool ParseInt32 (string value, out int result) - { -#if CF - try { - result = int.Parse (value); - return true; - } catch { - result = 0; - return false; - } -#else - return int.TryParse (value, out result); -#endif - } - - static void TryAddArity (string name, ref int arity) - { - int type_arity; - if (!TryGetArity (name, out type_arity)) - return; - - arity += type_arity; - } - - string ParsePart () - { - int start = position; - while (position < length && !IsDelimiter (fullname [position])) - position++; - - return fullname.Substring (start, position - start); - } - - static bool IsDelimiter (char chr) - { - return "+,[]*&".IndexOf (chr) != -1; - } - - void TryParseWhiteSpace () - { - while (position < length && Char.IsWhiteSpace (fullname [position])) - position++; - } - - string [] ParseNestedNames () - { - string [] nested_names = null; - while (TryParse ('+')) - Add (ref nested_names, ParsePart ()); - - return nested_names; - } - - bool TryParse (char chr) - { - if (position < length && fullname [position] == chr) { - position++; - return true; - } - - return false; - } - - static void Add (ref T [] array, T item) - { - if (array == null) { - array = new [] { item }; - return; - } - -#if !CF - Array.Resize (ref array, array.Length + 1); -#else - var copy = new T [array.Length + 1]; - Array.Copy (array, copy, array.Length); - array = copy; -#endif - array [array.Length - 1] = item; - } - - int [] ParseSpecs () - { - int [] specs = null; - - while (position < length) { - switch (fullname [position]) { - case '*': - position++; - Add (ref specs, Type.Ptr); - break; - case '&': - position++; - Add (ref specs, Type.ByRef); - break; - case '[': - position++; - switch (fullname [position]) { - case ']': - position++; - Add (ref specs, Type.SzArray); - break; - case '*': - position++; - Add (ref specs, 1); - break; - default: - var rank = 1; - while (TryParse (',')) - rank++; - - Add (ref specs, rank); - - TryParse (']'); - break; - } - break; - default: - return specs; - } - } - - return specs; - } - - Type [] ParseGenericArguments (int arity) - { - Type [] generic_arguments = null; - - if (position == length || fullname [position] != '[') - return generic_arguments; - - TryParse ('['); - - for (int i = 0; i < arity; i++) { - var fq_argument = TryParse ('['); - Add (ref generic_arguments, ParseType (fq_argument)); - if (fq_argument) - TryParse (']'); - - TryParse (','); - TryParseWhiteSpace (); - } - - TryParse (']'); - - return generic_arguments; - } - - string ParseAssemblyName () - { - if (!TryParse (',')) - return string.Empty; - - TryParseWhiteSpace (); - - var start = position; - while (position < length) { - var chr = fullname [position]; - if (chr == '[' || chr == ']') - break; - - position++; - } - - return fullname.Substring (start, position - start); - } - - public static TypeReference ParseType (ModuleDefinition module, string fullname) - { - if (fullname == null) - return null; - - var parser = new TypeParser (fullname); - return GetTypeReference (module, parser.ParseType (true)); - } - - static TypeReference GetTypeReference (ModuleDefinition module, Type type_info) - { - TypeReference type; - if (!TryGetDefinition (module, type_info, out type)) - type = CreateReference (type_info, module, GetMetadataScope (module, type_info)); - - return CreateSpecs (type, type_info); - } - - static TypeReference CreateSpecs (TypeReference type, Type type_info) - { - type = TryCreateGenericInstanceType (type, type_info); - - var specs = type_info.specs; - if (specs.IsNullOrEmpty ()) - return type; - - for (int i = 0; i < specs.Length; i++) { - switch (specs [i]) { - case Type.Ptr: - type = new PointerType (type); - break; - case Type.ByRef: - type = new ByReferenceType (type); - break; - case Type.SzArray: - type = new ArrayType (type); - break; - default: - var array = new ArrayType (type); - array.Dimensions.Clear (); - - for (int j = 0; j < specs [i]; j++) - array.Dimensions.Add (new ArrayDimension ()); - - type = array; - break; - } - } - - return type; - } - - static TypeReference TryCreateGenericInstanceType (TypeReference type, Type type_info) - { - var generic_arguments = type_info.generic_arguments; - if (generic_arguments.IsNullOrEmpty ()) - return type; - - var instance = new GenericInstanceType (type); - var instance_arguments = instance.GenericArguments; - - for (int i = 0; i < generic_arguments.Length; i++) - instance_arguments.Add (GetTypeReference (type.Module, generic_arguments [i])); - - return instance; - } - - public static void SplitFullName (string fullname, out string @namespace, out string name) - { - var last_dot = fullname.LastIndexOf ('.'); - - if (last_dot == -1) { - @namespace = string.Empty; - name = fullname; - } else { - @namespace = fullname.Substring (0, last_dot); - name = fullname.Substring (last_dot + 1); - } - } - - static TypeReference CreateReference (Type type_info, ModuleDefinition module, IMetadataScope scope) - { - string @namespace, name; - SplitFullName (type_info.type_fullname, out @namespace, out name); - - var type = new TypeReference (@namespace, name, module, scope); - MetadataSystem.TryProcessPrimitiveTypeReference (type); - - AdjustGenericParameters (type); - - var nested_names = type_info.nested_names; - if (nested_names.IsNullOrEmpty ()) - return type; - - for (int i = 0; i < nested_names.Length; i++) { - type = new TypeReference (string.Empty, nested_names [i], module, null) { - DeclaringType = type, - }; - - AdjustGenericParameters (type); - } - - return type; - } - - static void AdjustGenericParameters (TypeReference type) - { - int arity; - if (!TryGetArity (type.Name, out arity)) - return; - - for (int i = 0; i < arity; i++) - type.GenericParameters.Add (new GenericParameter (type)); - } - - static IMetadataScope GetMetadataScope (ModuleDefinition module, Type type_info) - { - if (string.IsNullOrEmpty (type_info.assembly)) - return module.TypeSystem.Corlib; - - return MatchReference (module, AssemblyNameReference.Parse (type_info.assembly)); - } - - static AssemblyNameReference MatchReference (ModuleDefinition module, AssemblyNameReference pattern) - { - var references = module.AssemblyReferences; - - for (int i = 0; i < references.Count; i++) { - var reference = references [i]; - if (reference.FullName == pattern.FullName) - return reference; - } - - return pattern; - } - - static bool TryGetDefinition (ModuleDefinition module, Type type_info, out TypeReference type) - { - type = null; - if (!TryCurrentModule (module, type_info)) - return false; - - var typedef = module.GetType (type_info.type_fullname); - if (typedef == null) - return false; - - var nested_names = type_info.nested_names; - if (!nested_names.IsNullOrEmpty ()) { - for (int i = 0; i < nested_names.Length; i++) - typedef = typedef.GetNestedType (nested_names [i]); - } - - type = typedef; - return true; - } - - static bool TryCurrentModule (ModuleDefinition module, Type type_info) - { - if (string.IsNullOrEmpty (type_info.assembly)) - return true; - - if (module.assembly != null && module.assembly.Name.FullName == type_info.assembly) - return true; - - return false; - } - - public static string ToParseable (TypeReference type) - { - if (type == null) - return null; - - var name = new StringBuilder (); - AppendType (type, name, true, true); - return name.ToString (); - } - - static void AppendType (TypeReference type, StringBuilder name, bool fq_name, bool top_level) - { - var declaring_type = type.DeclaringType; - if (declaring_type != null) { - AppendType (declaring_type, name, false, top_level); - name.Append ('+'); - } - - var @namespace = type.Namespace; - if (!string.IsNullOrEmpty (@namespace)) { - name.Append (@namespace); - name.Append ('.'); - } - - name.Append (type.GetElementType ().Name); - - if (!fq_name) - return; - - if (type.IsTypeSpecification ()) - AppendTypeSpecification ((TypeSpecification) type, name); - - if (RequiresFullyQualifiedName (type, top_level)) { - name.Append (", "); - name.Append (GetScopeFullName (type)); - } - } - - static string GetScopeFullName (TypeReference type) - { - var scope = type.Scope; - switch (scope.MetadataScopeType) { - case MetadataScopeType.AssemblyNameReference: - return ((AssemblyNameReference) scope).FullName; - case MetadataScopeType.ModuleDefinition: - return ((ModuleDefinition) scope).Assembly.Name.FullName; - } - - throw new ArgumentException (); - } - - static void AppendTypeSpecification (TypeSpecification type, StringBuilder name) - { - if (type.ElementType.IsTypeSpecification ()) - AppendTypeSpecification ((TypeSpecification) type.ElementType, name); - - switch (type.etype) { - case ElementType.Ptr: - name.Append ('*'); - break; - case ElementType.ByRef: - name.Append ('&'); - break; - case ElementType.SzArray: - case ElementType.Array: - var array = (ArrayType) type; - if (array.IsVector) { - name.Append ("[]"); - } else { - name.Append ('['); - for (int i = 1; i < array.Rank; i++) - name.Append (','); - name.Append (']'); - } - break; - case ElementType.GenericInst: - var instance = (GenericInstanceType) type; - var arguments = instance.GenericArguments; - - name.Append ('['); - - for (int i = 0; i < arguments.Count; i++) { - if (i > 0) - name.Append (','); - - var argument = arguments [i]; - var requires_fqname = argument.Scope != argument.Module; - - if (requires_fqname) - name.Append ('['); - - AppendType (argument, name, true, false); - - if (requires_fqname) - name.Append (']'); - } - - name.Append (']'); - break; - default: - return; - } - } - - static bool RequiresFullyQualifiedName (TypeReference type, bool top_level) - { - if (type.Scope == type.Module) - return false; - - if (type.Scope.Name == "mscorlib" && top_level) - return false; - - return true; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs deleted file mode 100644 index ff28c636fe8..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs +++ /dev/null @@ -1,330 +0,0 @@ -// -// TypeReference.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.Metadata; -using Mono.Collections.Generic; - -namespace Mono.Cecil { - - public enum MetadataType : byte { - Void = ElementType.Void, - Boolean = ElementType.Boolean, - Char = ElementType.Char, - SByte = ElementType.I1, - Byte = ElementType.U1, - Int16 = ElementType.I2, - UInt16 = ElementType.U2, - Int32 = ElementType.I4, - UInt32 = ElementType.U4, - Int64 = ElementType.I8, - UInt64 = ElementType.U8, - Single = ElementType.R4, - Double = ElementType.R8, - String = ElementType.String, - Pointer = ElementType.Ptr, - ByReference = ElementType.ByRef, - ValueType = ElementType.ValueType, - Class = ElementType.Class, - Var = ElementType.Var, - Array = ElementType.Array, - GenericInstance = ElementType.GenericInst, - TypedByReference = ElementType.TypedByRef, - IntPtr = ElementType.I, - UIntPtr = ElementType.U, - FunctionPointer = ElementType.FnPtr, - Object = ElementType.Object, - MVar = ElementType.MVar, - RequiredModifier = ElementType.CModReqD, - OptionalModifier = ElementType.CModOpt, - Sentinel = ElementType.Sentinel, - Pinned = ElementType.Pinned, - } - - public class TypeReference : MemberReference, IGenericParameterProvider, IGenericContext { - - string @namespace; - bool value_type; - internal IMetadataScope scope; - internal ModuleDefinition module; - - internal ElementType etype = ElementType.None; - - string fullname; - - protected Collection generic_parameters; - - public override string Name { - get { return base.Name; } - set { - base.Name = value; - fullname = null; - } - } - - public virtual string Namespace { - get { return @namespace; } - set { - @namespace = value; - fullname = null; - } - } - - public virtual bool IsValueType { - get { return value_type; } - set { value_type = value; } - } - - public override ModuleDefinition Module { - get { - if (module != null) - return module; - - var declaring_type = this.DeclaringType; - if (declaring_type != null) - return declaring_type.Module; - - return null; - } - } - - IGenericParameterProvider IGenericContext.Type { - get { return this; } - } - - IGenericParameterProvider IGenericContext.Method { - get { return null; } - } - - GenericParameterType IGenericParameterProvider.GenericParameterType { - get { return GenericParameterType.Type; } - } - - public virtual bool HasGenericParameters { - get { return !generic_parameters.IsNullOrEmpty (); } - } - - public virtual Collection GenericParameters { - get { - if (generic_parameters != null) - return generic_parameters; - - return generic_parameters = new GenericParameterCollection (this); - } - } - - public virtual IMetadataScope Scope { - get { - var declaring_type = this.DeclaringType; - if (declaring_type != null) - return declaring_type.Scope; - - return scope; - } - } - - public bool IsNested { - get { return this.DeclaringType != null; } - } - - public override TypeReference DeclaringType { - get { return base.DeclaringType; } - set { - base.DeclaringType = value; - fullname = null; - } - } - - public override string FullName { - get { - if (fullname != null) - return fullname; - - if (IsNested) - return fullname = DeclaringType.FullName + "/" + Name; - - if (string.IsNullOrEmpty (@namespace)) - return fullname = Name; - - return fullname = @namespace + "." + Name; - } - } - - public virtual bool IsByReference { - get { return false; } - } - - public virtual bool IsPointer { - get { return false; } - } - - public virtual bool IsSentinel { - get { return false; } - } - - public virtual bool IsArray { - get { return false; } - } - - public virtual bool IsGenericParameter { - get { return false; } - } - - public virtual bool IsGenericInstance { - get { return false; } - } - - public virtual bool IsRequiredModifier { - get { return false; } - } - - public virtual bool IsOptionalModifier { - get { return false; } - } - - public virtual bool IsPinned { - get { return false; } - } - - public virtual bool IsFunctionPointer { - get { return false; } - } - - public virtual bool IsPrimitive { - get { return etype.IsPrimitive (); } - } - - public virtual MetadataType MetadataType { - get { - switch (etype) { - case ElementType.None: - return IsValueType ? MetadataType.ValueType : MetadataType.Class; - default: - return (MetadataType) etype; - } - } - } - - protected TypeReference (string @namespace, string name) - : base (name) - { - this.@namespace = @namespace ?? string.Empty; - this.token = new MetadataToken (TokenType.TypeRef, 0); - } - - public TypeReference (string @namespace, string name, ModuleDefinition module, IMetadataScope scope) - : this (@namespace, name) - { - this.module = module; - this.scope = scope; - } - - public TypeReference (string @namespace, string name, ModuleDefinition module, IMetadataScope scope, bool valueType) : - this (@namespace, name, module, scope) - { - value_type = valueType; - } - - public virtual TypeReference GetElementType () - { - return this; - } - - public virtual TypeDefinition Resolve () - { - var module = this.Module; - if (module == null) - throw new NotSupportedException (); - - return module.Resolve (this); - } - } - - 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 - && self.Namespace == @namespace; - } - - public static bool IsTypeSpecification (this TypeReference type) - { - switch (type.etype) { - case ElementType.Array: - case ElementType.ByRef: - case ElementType.CModOpt: - case ElementType.CModReqD: - case ElementType.FnPtr: - case ElementType.GenericInst: - case ElementType.MVar: - case ElementType.Pinned: - case ElementType.Ptr: - case ElementType.SzArray: - case ElementType.Sentinel: - case ElementType.Var: - return true; - } - - return false; - } - - public static TypeDefinition CheckedResolve (this TypeReference self) - { - var type = self.Resolve (); - if (type == null) - throw new ResolutionException (self); - - return type; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeSpecification.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeSpecification.cs deleted file mode 100644 index aa9b653f07a..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeSpecification.cs +++ /dev/null @@ -1,94 +0,0 @@ -// -// TypeSpecification.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public abstract class TypeSpecification : TypeReference { - - readonly TypeReference element_type; - - public TypeReference ElementType { - get { return element_type; } - } - - public override string Name { - get { return element_type.Name; } - set { throw new NotSupportedException (); } - } - - public override string Namespace { - get { return element_type.Namespace; } - set { throw new NotSupportedException (); } - } - - public override IMetadataScope Scope { - get { return element_type.Scope; } - } - - public override ModuleDefinition Module { - get { return element_type.Module; } - } - - public override string FullName { - get { return element_type.FullName; } - } - - internal override bool ContainsGenericParameter { - get { return element_type.ContainsGenericParameter; } - } - - public override MetadataType MetadataType { - get { return (MetadataType) etype; } - } - - internal TypeSpecification (TypeReference type) - : base (null, null) - { - this.element_type = type; - this.token = new MetadataToken (TokenType.TypeSpec); - } - - public override TypeReference GetElementType () - { - return element_type.GetElementType (); - } - } - - static partial class Mixin { - - public static void CheckType (TypeReference type) - { - if (type == null) - throw new ArgumentNullException ("type"); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/TypeSystem.cs b/mcs/class/Mono.Cecil/Mono.Cecil/TypeSystem.cs deleted file mode 100644 index 60ccae4e5dd..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/TypeSystem.cs +++ /dev/null @@ -1,265 +0,0 @@ -// -// TypeSystem.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -using Mono.Cecil.Metadata; - -namespace Mono.Cecil { - - public abstract class TypeSystem { - - sealed class CorlibTypeSystem : TypeSystem { - - public CorlibTypeSystem (ModuleDefinition module) - : base (module) - { - } - - internal override TypeReference LookupType (string @namespace, string name) - { - var metadata = module.MetadataSystem; - if (metadata.Types == null) - Initialize (module.Types); - - return module.Read (new Row (@namespace, name), (row, reader) => { - var types = reader.metadata.Types; - - for (int i = 0; i < types.Length; i++) { - if (types [i] == null) - types [i] = reader.GetTypeDefinition ((uint) i + 1); - - var type = types [i]; - - if (type.Name == row.Col2 && type.Namespace == row.Col1) - return type; - } - - return null; - }); - } - - static void Initialize (object obj) - { - } - } - - sealed class CommonTypeSystem : TypeSystem { - - AssemblyNameReference corlib; - - public CommonTypeSystem (ModuleDefinition module) - : base (module) - { - } - - internal override TypeReference LookupType (string @namespace, string name) - { - return CreateTypeReference (@namespace, name); - } - - public AssemblyNameReference GetCorlibReference () - { - if (corlib != null) - return corlib; - - const string mscorlib = "mscorlib"; - - var references = module.AssemblyReferences; - - for (int i = 0; i < references.Count; i++) { - var reference = references [i]; - if (reference.Name == mscorlib) - return corlib = reference; - } - - corlib = new AssemblyNameReference { - Name = mscorlib, - Version = GetCorlibVersion (), - PublicKeyToken = new byte [] { 0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89 }, - }; - - references.Add (corlib); - - return corlib; - } - - Version GetCorlibVersion () - { - switch (module.Runtime) { - case TargetRuntime.Net_1_0: - case TargetRuntime.Net_1_1: - return new Version (1, 0, 0, 0); - case TargetRuntime.Net_2_0: - return new Version (2, 0, 0, 0); - case TargetRuntime.Net_4_0: - return new Version (4, 0, 0, 0); - default: - throw new NotSupportedException (); - } - } - - TypeReference CreateTypeReference (string @namespace, string name) - { - return new TypeReference (@namespace, name, module, GetCorlibReference ()); - } - } - - readonly ModuleDefinition module; - - TypeReference type_object; - TypeReference type_void; - TypeReference type_bool; - TypeReference type_char; - TypeReference type_sbyte; - TypeReference type_byte; - TypeReference type_int16; - TypeReference type_uint16; - TypeReference type_int32; - TypeReference type_uint32; - TypeReference type_int64; - TypeReference type_uint64; - TypeReference type_single; - TypeReference type_double; - TypeReference type_intptr; - TypeReference type_uintptr; - TypeReference type_string; - TypeReference type_typedref; - - TypeSystem (ModuleDefinition module) - { - this.module = module; - } - - internal static TypeSystem CreateTypeSystem (ModuleDefinition module) - { - if (module.IsCorlib ()) - return new CorlibTypeSystem (module); - - return new CommonTypeSystem (module); - } - - internal abstract TypeReference LookupType (string @namespace, string name); - - TypeReference LookupSystemType (string name, ElementType element_type) - { - var type = LookupType ("System", name); - type.etype = element_type; - return type; - } - - TypeReference LookupSystemValueType (string name, ElementType element_type) - { - var type = LookupSystemType (name, element_type); - type.IsValueType = true; - return type; - } - - public IMetadataScope Corlib { - get { - var common = this as CommonTypeSystem; - if (common == null) - return module; - - return common.GetCorlibReference (); - } - } - - public TypeReference Object { - get { return type_object ?? (type_object = LookupSystemType ("Object", ElementType.Object)); } - } - - public TypeReference Void { - get { return type_void ?? (type_void = LookupSystemType ("Void", ElementType.Void)); } - } - - public TypeReference Boolean { - get { return type_bool ?? (type_bool = LookupSystemValueType ("Boolean", ElementType.Boolean)); } - } - - public TypeReference Char { - get { return type_char ?? (type_char = LookupSystemValueType ("Char", ElementType.Char)); } - } - - public TypeReference SByte { - get { return type_sbyte ?? (type_sbyte = LookupSystemValueType ("SByte", ElementType.I1)); } - } - - public TypeReference Byte { - get { return type_byte ?? (type_byte = LookupSystemValueType ("Byte", ElementType.U1)); } - } - - public TypeReference Int16 { - get { return type_int16 ?? (type_int16 = LookupSystemValueType ("Int16", ElementType.I2)); } - } - - public TypeReference UInt16 { - get { return type_uint16 ?? (type_uint16 = LookupSystemValueType ("UInt16", ElementType.U2)); } - } - - public TypeReference Int32 { - get { return type_int32 ?? (type_int32 = LookupSystemValueType ("Int32", ElementType.I4)); } - } - - public TypeReference UInt32 { - get { return type_uint32 ?? (type_uint32 = LookupSystemValueType ("UInt32", ElementType.U4)); } - } - - public TypeReference Int64 { - get { return type_int64 ?? (type_int64 = LookupSystemValueType ("Int64", ElementType.I8)); } - } - - public TypeReference UInt64 { - get { return type_uint64 ?? (type_uint64 = LookupSystemValueType ("UInt64", ElementType.U8)); } - } - - public TypeReference Single { - get { return type_single ?? (type_single = LookupSystemValueType ("Single", ElementType.R4)); } - } - - public TypeReference Double { - get { return type_double ?? (type_double = LookupSystemValueType ("Double", ElementType.R8)); } - } - - public TypeReference IntPtr { - get { return type_intptr ?? (type_intptr = LookupSystemValueType ("IntPtr", ElementType.I)); } - } - - public TypeReference UIntPtr { - get { return type_uintptr ?? (type_uintptr = LookupSystemValueType ("UIntPtr", ElementType.U)); } - } - - public TypeReference String { - get { return type_string ?? (type_string = LookupSystemType ("String", ElementType.String)); } - } - - public TypeReference TypedReference { - get { return type_typedref ?? (type_typedref = LookupSystemValueType ("TypedReference", ElementType.TypedByRef)); } - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Cecil/VariantType.cs b/mcs/class/Mono.Cecil/Mono.Cecil/VariantType.cs deleted file mode 100644 index 76562f6e6f7..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Cecil/VariantType.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// VariantType.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace Mono.Cecil { - - public enum VariantType { - None = 0, - I2 = 2, - I4 = 3, - R4 = 4, - R8 = 5, - CY = 6, - Date = 7, - BStr = 8, - Dispatch = 9, - Error = 10, - Bool = 11, - Variant = 12, - Unknown = 13, - Decimal = 14, - I1 = 16, - UI1 = 17, - UI2 = 18, - UI4 = 19, - Int = 22, - UInt = 23 - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Collections.Generic/Collection.cs b/mcs/class/Mono.Cecil/Mono.Collections.Generic/Collection.cs deleted file mode 100644 index 4d927176081..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Collections.Generic/Collection.cs +++ /dev/null @@ -1,420 +0,0 @@ -// -// Collection.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace Mono.Collections.Generic { - - public class Collection : IList, IList { - - internal T [] items; - internal int size; - int version; - - public int Count { - get { return size; } - } - - public T this [int index] { - get { - if (index >= size) - throw new ArgumentOutOfRangeException (); - - return items [index]; - } - set { - CheckIndex (index); - if (index == size) - throw new ArgumentOutOfRangeException (); - - OnSet (value, index); - - items [index] = value; - } - } - - bool ICollection.IsReadOnly { - get { return false; } - } - - bool IList.IsFixedSize { - get { return false; } - } - - bool IList.IsReadOnly { - get { return false; } - } - - object IList.this [int index] { - get { return this [index]; } - set { - CheckIndex (index); - - try { - this [index] = (T) value; - return; - } catch (InvalidCastException) { - } catch (NullReferenceException) { - } - - throw new ArgumentException (); - } - } - - int ICollection.Count { - get { return Count; } - } - - bool ICollection.IsSynchronized { - get { return false; } - } - - object ICollection.SyncRoot { - get { return this; } - } - - public Collection () - { - items = Empty.Array; - } - - public Collection (int capacity) - { - if (capacity < 0) - throw new ArgumentOutOfRangeException (); - - items = new T [capacity]; - } - - public Collection (ICollection items) - { - if (items == null) - throw new ArgumentNullException ("items"); - - this.items = new T [items.Count]; - items.CopyTo (this.items, 0); - this.size = this.items.Length; - } - - public void Add (T item) - { - if (size == items.Length) - Grow (1); - - OnAdd (item, size); - - items [size++] = item; - version++; - } - - public bool Contains (T item) - { - return IndexOf (item) != -1; - } - - public int IndexOf (T item) - { - return Array.IndexOf (items, item, 0, size); - } - - public void Insert (int index, T item) - { - CheckIndex (index); - if (size == items.Length) - Grow (1); - - OnInsert (item, index); - - Shift (index, 1); - items [index] = item; - version++; - } - - public void RemoveAt (int index) - { - if (index < 0 || index >= size) - throw new ArgumentOutOfRangeException (); - - var item = items [index]; - - OnRemove (item, index); - - Shift (index, -1); - Array.Clear (items, size, 1); - version++; - } - - public bool Remove (T item) - { - var index = IndexOf (item); - if (index == -1) - return false; - - OnRemove (item, index); - - Shift (index, -1); - Array.Clear (items, size, 1); - version++; - - return true; - } - - public void Clear () - { - OnClear (); - - Array.Clear (items, 0, size); - size = 0; - version++; - } - - public void CopyTo (T [] array, int arrayIndex) - { - Array.Copy (items, 0, array, arrayIndex, size); - } - - public T [] ToArray () - { - var array = new T [size]; - Array.Copy (items, 0, array, 0, size); - return array; - } - - void CheckIndex (int index) - { - if (index < 0 || index > size) - throw new ArgumentOutOfRangeException (); - } - - void Shift (int start, int delta) - { - if (delta < 0) - start -= delta; - - if (start < size) - Array.Copy (items, start, items, start + delta, size - start); - - size += delta; - - if (delta < 0) - Array.Clear (items, size, -delta); - } - - protected virtual void OnAdd (T item, int index) - { - } - - protected virtual void OnInsert (T item, int index) - { - } - - protected virtual void OnSet (T item, int index) - { - } - - protected virtual void OnRemove (T item, int index) - { - } - - protected virtual void OnClear () - { - } - - internal virtual void Grow (int desired) - { - int new_size = size + desired; - if (new_size <= items.Length) - return; - - const int default_capacity = 4; - - new_size = System.Math.Max ( - System.Math.Max (items.Length * 2, default_capacity), - new_size); - -#if !CF - Array.Resize (ref items, new_size); -#else - var array = new T [new_size]; - Array.Copy (items, array, size); - items = array; -#endif - } - - int IList.Add (object value) - { - try { - Add ((T) value); - return size - 1; - } catch (InvalidCastException) { - } catch (NullReferenceException) { - } - - throw new ArgumentException (); - } - - void IList.Clear () - { - Clear (); - } - - bool IList.Contains (object value) - { - return ((IList) this).IndexOf (value) > -1; - } - - int IList.IndexOf (object value) - { - try { - return IndexOf ((T) value); - } catch (InvalidCastException) { - } catch (NullReferenceException) { - } - - return -1; - } - - void IList.Insert (int index, object value) - { - CheckIndex (index); - - try { - Insert (index, (T) value); - return; - } catch (InvalidCastException) { - } catch (NullReferenceException) { - } - - throw new ArgumentException (); - } - - void IList.Remove (object value) - { - try { - Remove ((T) value); - } catch (InvalidCastException) { - } catch (NullReferenceException) { - } - } - - void IList.RemoveAt (int index) - { - RemoveAt (index); - } - - void ICollection.CopyTo (Array array, int index) - { - Array.Copy (items, 0, array, index, size); - } - - public Enumerator GetEnumerator () - { - return new Enumerator (this); - } - - IEnumerator IEnumerable.GetEnumerator () - { - return new Enumerator (this); - } - - IEnumerator IEnumerable.GetEnumerator () - { - return new Enumerator (this); - } - - public struct Enumerator : IEnumerator, IDisposable { - - Collection collection; - T current; - - int next; - readonly int version; - - public T Current { - get { return current; } - } - - object IEnumerator.Current { - get { - CheckState (); - - if (next <= 0) - throw new InvalidOperationException (); - - return current; - } - } - - internal Enumerator (Collection collection) - : this () - { - this.collection = collection; - this.version = collection.version; - } - - public bool MoveNext () - { - CheckState (); - - if (next < 0) - return false; - - if (next < collection.size) { - current = collection.items [next++]; - return true; - } - - next = -1; - return false; - } - - public void Reset () - { - CheckState (); - - next = 0; - } - - void CheckState () - { - if (collection == null) - throw new ObjectDisposedException (GetType ().FullName); - - if (version != collection.version) - throw new InvalidOperationException (); - } - - public void Dispose () - { - collection = null; - } - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Collections.Generic/ReadOnlyCollection.cs b/mcs/class/Mono.Cecil/Mono.Collections.Generic/ReadOnlyCollection.cs deleted file mode 100644 index 7f24df699e2..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Collections.Generic/ReadOnlyCollection.cs +++ /dev/null @@ -1,112 +0,0 @@ -// -// ReadOnlyCollection.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System .Collections.Generic; - -namespace Mono.Collections.Generic { - - public sealed class ReadOnlyCollection : Collection, ICollection, IList { - - static ReadOnlyCollection empty; - - public static ReadOnlyCollection Empty { - get { return empty ?? (empty = new ReadOnlyCollection ()); } - } - - bool ICollection.IsReadOnly { - get { return true; } - } - - bool IList.IsFixedSize { - get { return true; } - } - - bool IList.IsReadOnly { - get { return true; } - } - - private ReadOnlyCollection () - { - } - - public ReadOnlyCollection (T [] array) - { - if (array == null) - throw new ArgumentNullException (); - - Initialize (array, array.Length); - } - - public ReadOnlyCollection (Collection collection) - { - if (collection == null) - throw new ArgumentNullException (); - - Initialize (collection.items, collection.size); - } - - void Initialize (T [] items, int size) - { - this.items = new T [size]; - Array.Copy (items, 0, this.items, 0, size); - this.size = size; - } - - internal override void Grow (int desired) - { - throw new InvalidOperationException (); - } - - protected override void OnAdd (T item, int index) - { - throw new InvalidOperationException (); - } - - protected override void OnClear () - { - throw new InvalidOperationException (); - } - - protected override void OnInsert (T item, int index) - { - throw new InvalidOperationException (); - } - - protected override void OnRemove (T item, int index) - { - throw new InvalidOperationException (); - } - - protected override void OnSet (T item, int index) - { - throw new InvalidOperationException (); - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoConvert.cs b/mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoConvert.cs deleted file mode 100644 index 26a4ba25b66..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoConvert.cs +++ /dev/null @@ -1,243 +0,0 @@ -// -// CryptoConvert.cs - Crypto Convertion Routines -// -// Author: -// Sebastien Pouliot -// -// (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// Copyright (C) 2004-2006 Novell Inc. (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Security.Cryptography; - -#if !(SILVERLIGHT || READ_ONLY) - -namespace Mono.Security.Cryptography { - - static class CryptoConvert { - - static private int ToInt32LE (byte [] bytes, int offset) - { - return (bytes [offset+3] << 24) | (bytes [offset+2] << 16) | (bytes [offset+1] << 8) | bytes [offset]; - } - - static private uint ToUInt32LE (byte [] bytes, int offset) - { - return (uint)((bytes [offset+3] << 24) | (bytes [offset+2] << 16) | (bytes [offset+1] << 8) | bytes [offset]); - } - - static private byte[] Trim (byte[] array) - { - for (int i=0; i < array.Length; i++) { - if (array [i] != 0x00) { - byte[] result = new byte [array.Length - i]; - Buffer.BlockCopy (array, i, result, 0, result.Length); - return result; - } - } - return null; - } - - static RSA FromCapiPrivateKeyBlob (byte[] blob, int offset) - { - RSAParameters rsap = new RSAParameters (); - try { - if ((blob [offset] != 0x07) || // PRIVATEKEYBLOB (0x07) - (blob [offset+1] != 0x02) || // Version (0x02) - (blob [offset+2] != 0x00) || // Reserved (word) - (blob [offset+3] != 0x00) || - (ToUInt32LE (blob, offset+8) != 0x32415352)) // DWORD magic = RSA2 - throw new CryptographicException ("Invalid blob header"); - - // ALGID (CALG_RSA_SIGN, CALG_RSA_KEYX, ...) - // int algId = ToInt32LE (blob, offset+4); - - // DWORD bitlen - int bitLen = ToInt32LE (blob, offset+12); - - // DWORD public exponent - byte[] exp = new byte [4]; - Buffer.BlockCopy (blob, offset+16, exp, 0, 4); - Array.Reverse (exp); - rsap.Exponent = Trim (exp); - - int pos = offset+20; - // BYTE modulus[rsapubkey.bitlen/8]; - int byteLen = (bitLen >> 3); - rsap.Modulus = new byte [byteLen]; - Buffer.BlockCopy (blob, pos, rsap.Modulus, 0, byteLen); - Array.Reverse (rsap.Modulus); - pos += byteLen; - - // BYTE prime1[rsapubkey.bitlen/16]; - int byteHalfLen = (byteLen >> 1); - rsap.P = new byte [byteHalfLen]; - Buffer.BlockCopy (blob, pos, rsap.P, 0, byteHalfLen); - Array.Reverse (rsap.P); - pos += byteHalfLen; - - // BYTE prime2[rsapubkey.bitlen/16]; - rsap.Q = new byte [byteHalfLen]; - Buffer.BlockCopy (blob, pos, rsap.Q, 0, byteHalfLen); - Array.Reverse (rsap.Q); - pos += byteHalfLen; - - // BYTE exponent1[rsapubkey.bitlen/16]; - rsap.DP = new byte [byteHalfLen]; - Buffer.BlockCopy (blob, pos, rsap.DP, 0, byteHalfLen); - Array.Reverse (rsap.DP); - pos += byteHalfLen; - - // BYTE exponent2[rsapubkey.bitlen/16]; - rsap.DQ = new byte [byteHalfLen]; - Buffer.BlockCopy (blob, pos, rsap.DQ, 0, byteHalfLen); - Array.Reverse (rsap.DQ); - pos += byteHalfLen; - - // BYTE coefficient[rsapubkey.bitlen/16]; - rsap.InverseQ = new byte [byteHalfLen]; - Buffer.BlockCopy (blob, pos, rsap.InverseQ, 0, byteHalfLen); - Array.Reverse (rsap.InverseQ); - pos += byteHalfLen; - - // ok, this is hackish but CryptoAPI support it so... - // note: only works because CRT is used by default - // http://bugzilla.ximian.com/show_bug.cgi?id=57941 - rsap.D = new byte [byteLen]; // must be allocated - if (pos + byteLen + offset <= blob.Length) { - // BYTE privateExponent[rsapubkey.bitlen/8]; - Buffer.BlockCopy (blob, pos, rsap.D, 0, byteLen); - Array.Reverse (rsap.D); - } - } - catch (Exception e) { - throw new CryptographicException ("Invalid blob.", e); - } - - RSA rsa = null; - try { - rsa = RSA.Create (); - rsa.ImportParameters (rsap); - } - catch (CryptographicException ce) { - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - try { - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (rsap); - } - catch { - // rethrow original, not the later, exception if this fails - throw ce; - } - } - return rsa; - } - - static RSA FromCapiPublicKeyBlob (byte[] blob, int offset) - { - try { - if ((blob [offset] != 0x06) || // PUBLICKEYBLOB (0x06) - (blob [offset+1] != 0x02) || // Version (0x02) - (blob [offset+2] != 0x00) || // Reserved (word) - (blob [offset+3] != 0x00) || - (ToUInt32LE (blob, offset+8) != 0x31415352)) // DWORD magic = RSA1 - throw new CryptographicException ("Invalid blob header"); - - // ALGID (CALG_RSA_SIGN, CALG_RSA_KEYX, ...) - // int algId = ToInt32LE (blob, offset+4); - - // DWORD bitlen - int bitLen = ToInt32LE (blob, offset+12); - - // DWORD public exponent - RSAParameters rsap = new RSAParameters (); - rsap.Exponent = new byte [3]; - rsap.Exponent [0] = blob [offset+18]; - rsap.Exponent [1] = blob [offset+17]; - rsap.Exponent [2] = blob [offset+16]; - - int pos = offset+20; - // BYTE modulus[rsapubkey.bitlen/8]; - int byteLen = (bitLen >> 3); - rsap.Modulus = new byte [byteLen]; - Buffer.BlockCopy (blob, pos, rsap.Modulus, 0, byteLen); - Array.Reverse (rsap.Modulus); - - RSA rsa = null; - try { - rsa = RSA.Create (); - rsa.ImportParameters (rsap); - } - catch (CryptographicException) { - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (rsap); - } - return rsa; - } - catch (Exception e) { - throw new CryptographicException ("Invalid blob.", e); - } - } - - // PRIVATEKEYBLOB - // PUBLICKEYBLOB - static public RSA FromCapiKeyBlob (byte[] blob) - { - return FromCapiKeyBlob (blob, 0); - } - - static public RSA FromCapiKeyBlob (byte[] blob, int offset) - { - if (blob == null) - throw new ArgumentNullException ("blob"); - if (offset >= blob.Length) - throw new ArgumentException ("blob is too small."); - - switch (blob [offset]) { - case 0x00: - // this could be a public key inside an header - // like "sn -e" would produce - if (blob [offset + 12] == 0x06) { - return FromCapiPublicKeyBlob (blob, offset + 12); - } - break; - case 0x06: - return FromCapiPublicKeyBlob (blob, offset); - case 0x07: - return FromCapiPrivateKeyBlob (blob, offset); - } - throw new CryptographicException ("Unknown blob format."); - } - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoService.cs b/mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoService.cs deleted file mode 100644 index 58b6cfabc6d..00000000000 --- a/mcs/class/Mono.Cecil/Mono.Security.Cryptography/CryptoService.cs +++ /dev/null @@ -1,177 +0,0 @@ -// -// CryptoService.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Reflection; -using System.Security.Cryptography; - -#if !READ_ONLY - -#if !SILVERLIGHT && !CF -using System.Runtime.Serialization; -using Mono.Security.Cryptography; -#endif - -using Mono.Cecil.PE; - -namespace Mono.Cecil { - - // Most of this code has been adapted - // from Jeroen Frijters' fantastic work - // in IKVM.Reflection.Emit. Thanks! - - static class CryptoService { - -#if !SILVERLIGHT && !CF - public static void StrongName (Stream stream, ImageWriter writer, StrongNameKeyPair key_pair) - { - int strong_name_pointer; - - var strong_name = CreateStrongName (key_pair, HashStream (stream, writer, out strong_name_pointer)); - PatchStrongName (stream, strong_name_pointer, strong_name); - } - - static void PatchStrongName (Stream stream, int strong_name_pointer, byte [] strong_name) - { - stream.Seek (strong_name_pointer, SeekOrigin.Begin); - stream.Write (strong_name, 0, strong_name.Length); - } - - static byte [] CreateStrongName (StrongNameKeyPair key_pair, byte [] hash) - { - const string hash_algo = "SHA1"; - - using (var rsa = key_pair.CreateRSA ()) { - var formatter = new RSAPKCS1SignatureFormatter (rsa); - formatter.SetHashAlgorithm (hash_algo); - - byte [] signature = formatter.CreateSignature (hash); - Array.Reverse (signature); - - return signature; - } - } - - static byte [] HashStream (Stream stream, ImageWriter writer, out int strong_name_pointer) - { - const int buffer_size = 8192; - - var text = writer.text; - var header_size = (int) writer.GetHeaderSize (); - var text_section_pointer = (int) text.PointerToRawData; - var strong_name_directory = writer.GetStrongNameSignatureDirectory (); - - if (strong_name_directory.Size == 0) - throw new InvalidOperationException (); - - strong_name_pointer = (int) (text_section_pointer - + (strong_name_directory.VirtualAddress - text.VirtualAddress)); - var strong_name_length = (int) strong_name_directory.Size; - - var sha1 = new SHA1Managed (); - var buffer = new byte [buffer_size]; - using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) { - - stream.Seek (0, SeekOrigin.Begin); - CopyStreamChunk (stream, crypto_stream, buffer, header_size); - - stream.Seek (text_section_pointer, SeekOrigin.Begin); - CopyStreamChunk (stream, crypto_stream, buffer, (int) strong_name_pointer - text_section_pointer); - - stream.Seek (strong_name_length, SeekOrigin.Current); - CopyStreamChunk (stream, crypto_stream, buffer, (int) (stream.Length - (strong_name_pointer + strong_name_length))); - } - - return sha1.Hash; - } -#endif - static void CopyStreamChunk (Stream stream, Stream dest_stream, byte [] buffer, int length) - { - while (length > 0) { - int read = stream.Read (buffer, 0, System.Math.Min (buffer.Length, length)); - dest_stream.Write (buffer, 0, read); - length -= read; - } - } - - public static byte [] ComputeHash (string file) - { - if (!File.Exists (file)) - return Empty.Array; - - const int buffer_size = 8192; - - var sha1 = new SHA1Managed (); - - using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read)) { - - var buffer = new byte [buffer_size]; - - using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) - CopyStreamChunk (stream, crypto_stream, buffer, (int) stream.Length); - } - - return sha1.Hash; - } - } - -#if !SILVERLIGHT && !CF - static partial class Mixin { - - public static RSA CreateRSA (this StrongNameKeyPair key_pair) - { - byte [] key; - string key_container; - - if (!TryGetKeyContainer (key_pair, out key, out key_container)) - return CryptoConvert.FromCapiKeyBlob (key); - - var parameters = new CspParameters { - Flags = CspProviderFlags.UseMachineKeyStore, - KeyContainerName = key_container, - KeyNumber = 2, - }; - - return new RSACryptoServiceProvider (parameters); - } - - static bool TryGetKeyContainer (ISerializable key_pair, out byte [] key, out string key_container) - { - var info = new SerializationInfo (typeof (StrongNameKeyPair), new FormatterConverter ()); - key_pair.GetObjectData (info, new StreamingContext ()); - - key = (byte []) info.GetValue ("_keyPairArray", typeof (byte [])); - key_container = info.GetString ("_keyPairContainer"); - return key_container != null; - } - } -#endif -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono/Actions.cs b/mcs/class/Mono.Cecil/Mono/Actions.cs deleted file mode 100644 index 756438f84e3..00000000000 --- a/mcs/class/Mono.Cecil/Mono/Actions.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// Actions.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -#if !NET_3_5 && !NET_4_0 - -namespace Mono { - //delegate void Action (); - delegate void Action (T1 arg1, T2 arg2); - //delegate void Action (T1 arg1, T2 arg2, T3 arg3); - //delegate void Action (T1 arg1, T2 arg2, T3 arg3, T4 arg4); -} - -#endif diff --git a/mcs/class/Mono.Cecil/Mono/Empty.cs b/mcs/class/Mono.Cecil/Mono/Empty.cs deleted file mode 100644 index d043a35fa5d..00000000000 --- a/mcs/class/Mono.Cecil/Mono/Empty.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Empty.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using Mono.Collections.Generic; - -namespace Mono { - - static class Empty { - - public static readonly T [] Array = new T [0]; - } -} - -namespace Mono.Cecil { - - static partial class Mixin { - - public static bool IsNullOrEmpty (this T [] self) - { - return self == null || self.Length == 0; - } - - public static bool IsNullOrEmpty (this Collection self) - { - return self == null || self.size == 0; - } - } -} diff --git a/mcs/class/Mono.Cecil/Mono/Funcs.cs b/mcs/class/Mono.Cecil/Mono/Funcs.cs deleted file mode 100644 index 87bc6e97730..00000000000 --- a/mcs/class/Mono.Cecil/Mono/Funcs.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// Funcs.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -#if !NET_3_5 && !NET_4_0 - -namespace Mono { - delegate TResult Func (); - delegate TResult Func (T arg1); - delegate TResult Func (T1 arg1, T2 arg2); - //delegate TResult Func (T1 arg1, T2 arg2, T3 arg3); - //delegate TResult Func (T1 arg1, T2 arg2, T3 arg3, T4 arg4); -} - -#endif diff --git a/mcs/class/Mono.Cecil/NOTES.txt b/mcs/class/Mono.Cecil/NOTES.txt deleted file mode 100644 index 6f3618bccf0..00000000000 --- a/mcs/class/Mono.Cecil/NOTES.txt +++ /dev/null @@ -1,189 +0,0 @@ -namespaces: - - Mono.Cecil.Binary: deleted, - Mono.Cecil.Metadata: metadata table/rows: deleted. - -collections: - - * Cecil now only exposes Collection of T as a public collection API. - -types: - -Mono.Cecil - - - AssemblyFactory: - Use static Read methods on ModuleDefinition and AssemblyDefinition - to get them. - - + ReadingMode: - specifies if the assembly is either loaded in a deffered - or immediate fashion. - - + ReaderParameters - + ReadingMode - + ISymbolReaderProvider - - + WriterParameters - + ISymbolWriterProvider - - * AssemblyDefinition: - - * Runtime, Kind: moved to ModuleDefiniton - - * ModuleDefinition: - - properties: - - - Image - - MemberReferences - - TypeReferences - - ExternTypes - - * Main -> IsMain. (set removed) : bool - + FullyQualifiedName : string - + Kind : ModuleKind - + Runtime : TargetRuntime - + Architecture : TargetArchitecture - + Attributes : ModuleAttributes - + HasSymbols : bool - + HasExportedTypes : bool - + ExportedTypes : ExportedTypeCollection - - * Types: doesn't contain NestedTypes anymore. - - - AssemblyKind: - renamed to ModuleKind. - - + ModuleKind: - + NetModule - - + TargetArchitecture: - + I386 - + AMD64 - + IA64 - - + ModuleAttributes: - + ILOnly - + Required32Bit - + StrongNameSigned - - * FieldDefinition: - - * RVA : int - - * IMethodSignature: - * ReturnType : TypeReference - + MethodReturnType : MethodReturnType - - * TypeDefinition: - - HasConstructors - - Constructors - * ctor: swapped namespace and name parameter. - - * ParameterDefinition: - * Method : IMethodSignature - * Sequence -> Index : int (0 based instead of 1) - - * ArrayType: - * IsSizedArray -> IsVector : bool - - * IHasConstant -> IConstantProvider - * IHasSecurity -> ISecurityDeclarationProvider - * IHasMarshal -> IMarshalInfoProvider - - * MemberReference - + Module : ModuleDefinition - - * MethodDefinition: - - This: moved to MethodBody - + HasPInvokeInfo : bool - - * PInvokeInfo: - - Method - - * MarshalSpec -> MarshalInfo - - - ModType - - * ModifierRequiredType -> RequiredModifierType - * ModifierOptionalType -> OptionalModifierType - * ReferenceType -> ByReferenceType - - * TypeReference - + IsArray : bool - + IsPointer : bool - + IsByReference : bool - + IsRequiredModifier : bool - + IsOptionalModifier : bool - + IsSentinel : bool - + IsGenericInstance : bool - + IsGenericParameter : bool - + IsPinned : bool - + IsFunctionPointer : bool - + IsDefinition : bool - - * GetOriginalType -> GetElementType - * ctor: swapped namespace and name parameter. - - * MethodReference - + IsGenericInstance : bool - + IsDefinition : bool - - * GetOriginalMethod -> GetElementMethod - - * FieldReference - + IsDefinition : bool - - + CustomAttributeArgument - + Type : TypeReference - + Value : object - - * CustomAttribute - * ConstructorParameters -> ConstructorArguments : CustomAttributeArgumentCollection - * Properties : CustomAttributeNamedArgumentCollection - * Fields : CustomAttributeNamedArgumentCollection - - * SecurityDeclaration - - PermissionSet - + SecurityAttributes : SecurityAttributeCollection - - + SecurityAttribute - + AttributeType : TypeReference - + Fields : CustomAttributeNamedArgumentCollection - + Properties : CustomAttributeNamedArgumentCollection - - * IMetadataScope - + MetadataScopeType - - + MetadataScopeType - + AssemblyNameReference - + ModuleDefinition - + ModuleReference - -Mono.Cecil.Cil: - - * ExceptionHandler - * Type -> HandlerType : TypeReference - - * VariableDefinition - - Method - - * Document* : from Guid to enums, the reader/writers are responsible for assigning them. - - * MethodBody - * LocalVarToken : MetadataToken - * MaxStack -> MaxStackSize : int - + ThisParameter: from MethodDefinition - - * OperandType - * ShortInlineParam : ShortInlineArg - * InlineParam : InlineArg - - * CilWorker -> ILProcessor - -TODO: - - * Mono.Cecil.Rocks - * ILGenerator - - * HOWTOs diff --git a/mcs/class/Mono.Cecil/README b/mcs/class/Mono.Cecil/README deleted file mode 100644 index 3f796704ec4..00000000000 --- a/mcs/class/Mono.Cecil/README +++ /dev/null @@ -1,15 +0,0 @@ -This copy of Mono.Cecil is a snapshot of the upstream Mono.Cecil located at: - - http://github.com/jbevain/cecil - -To update the snapshot, simply run: - - ruby update.rb - -in mono/mcs/class/Mono.Cecil. You need to have an updated clone of the upstream -cecil in a sibling folder of your mono clone. You may have to update - - mono/data/cecil.pc.in - -if Cecil's assembly version changed since the last update. This gets -picked up by mono-tools to locate Cecil. diff --git a/mcs/class/Mono.Cecil/System.Runtime.CompilerServices/ExtensionAttribute.cs b/mcs/class/Mono.Cecil/System.Runtime.CompilerServices/ExtensionAttribute.cs deleted file mode 100644 index bb24f980d2e..00000000000 --- a/mcs/class/Mono.Cecil/System.Runtime.CompilerServices/ExtensionAttribute.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// ExtensionAttribute.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -#if !NET_3_5 && !NET_4_0 - -namespace System.Runtime.CompilerServices { - - [AttributeUsage (AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)] - sealed class ExtensionAttribute : Attribute { - } -} - -#endif diff --git a/mcs/class/Mono.Cecil/mono.snk b/mcs/class/Mono.Cecil/mono.snk deleted file mode 100644 index 380116c18fc37e37caee38d5c7f00553381fbf9e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50097b6`6O^&^nH5>Uu78=+UptljwyRbd@W# zfT1jrG)GMY1|&zrehz5BfKzYJJU_lK`N?_CnS^!a2I$U$-CGYe4Z#kRzb@|2hf5@P z3{ZjF>U2l_+WIGZBHl;V|LR1Rbfo$G&xFxXX$X^mC{4Z7Uq;RU5~00#T8$V?4 zm0(Z@pa!7K?(Fv6`Sy%zIG6>&?npz0UV%?bgx!7tH#C%jM34vHZxVr2-GyqR){Wb_ z{XsWBT$ZExT8-J6M|x?bD~-_)p-JamyVJi9497FdEQ65@I<~MMyg{tluUqokqOaxj zlhqj9JtQiyyKdy8TBK}e2S{tm<$7FGKad_^`^?rYM0;cj^51yOyC%wV#(=?x_-cVmn-um!xGBCj903_NLpqj#fY94K!%&o7 zw|E3wgmzMa{N+PDQQ4BhoE7KBA!Hxyi2D5IJ4civ7g7A4#@Va i>Ut2fuAI+%0QCxKtaJZ4tp|R<30%KGIZqYwf2q$ "Mono.Cecil", - "Mono.Cecil.Cil/*.cs" => "Mono.Cecil.Cil", - "Mono.Cecil.Metadata/*.cs" => "Mono.Cecil.Metadata", - "Mono.Cecil.PE/*.cs" => "Mono.Cecil.PE", - "Mono.Collections.Generic/*.cs" => "Mono.Collections.Generic", - "Mono.Security.Cryptography/*.cs" => "Mono.Security.Cryptography", - "Mono/*.cs" => "Mono", - "System.Runtime.CompilerServices/*.cs" => "System.Runtime.CompilerServices", - "NOTES.txt" => ".", - - "symbols/mdb/Mono.Cecil.Mdb/*.cs" => "../Mono.Cecil.Mdb/Mono.Cecil.Mdb/", -} - -require "ftools" - -sources.each { |source, destination| - Dir[File::join(repository, source)].each { |file| - #puts "copying #{file} to #{destination}" - File.copy(file, destination) - } -} - -dir = Dir.pwd - -begin - Dir.chdir(repository) - - log = IO.popen("git log -n1") - - Dir.chdir(dir) - - File.open("revision", File::WRONLY|File::TRUNC|File::CREAT, 0644) do |f| - f << log.gets[("commit ".length)..-1] - end -rescue - Dir.chdir(dir) -end -- 2.25.1