diff --git a/.appveyor.yml b/.appveyor.yml
index 2127ceec8..1b48736c0 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -1,5 +1,5 @@
version: '{build}'
-image: Visual Studio 2019
+image: Visual Studio 2022
environment:
matrix:
@@ -44,7 +44,4 @@ before_test:
}
test_script:
- - nunit3-console
- src\test\tests\bin\Release\Uno.TestRunner.Tests.dll
- src\ux\tests\bin\Release\Uno.UX.Markup.Tests.dll
- npm test %TARGET%
diff --git a/.unoconfig b/.unoconfig
index ba2e4b21f..52fad0fb9 100644
--- a/.unoconfig
+++ b/.unoconfig
@@ -1,16 +1,15 @@
// Core config
-AppLoader.Mac: bin/mac
-AppLoader.Windows: bin/win
-Uno.Exe: bin/uno.exe
+AppLoader.Mac: bin/mac/net6.0
+AppLoader.Windows: bin/win/net6.0-windows
if WIN32 {
- AppLoader.Exe: bin/win/uno-app.exe
- Uno.Command: bin/uno.exe
+ AppLoader.Assembly: bin/win/net6.0-windows/uno-app.dll
+ Uno.Command: bin/net6.0/uno.exe
} else if MAC {
- AppLoader.Exe: bin/mac/uno-app.exe
+ AppLoader.Assembly: bin/mac/net6.0/uno-app.dll
Uno.Command: bin/uno.js
} else {
- AppLoader.Exe: bin/generic/uno-app.exe
+ AppLoader.Assembly: bin/generic/net6.0/uno-app.dll
Uno.Command: bin/uno.js
}
diff --git a/disasm.sln b/disasm.sln
index 096043f8d..58071caab 100644
--- a/disasm.sln
+++ b/disasm.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
-VisualStudioVersion = 16.0.30002.166
+VisualStudioVersion = 25.0.1703.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "disasm-wpf", "src\disasm\wpf\disasm-wpf.csproj", "{E9E95DD1-03F6-45A3-945F-E1CC82E6B8D4}"
EndProject
diff --git a/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.Test/Uno.Net.Http.Implementation.Test.csproj b/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.Test/Uno.Net.Http.Implementation.Test.csproj
index dd742f964..36ae7daa9 100644
--- a/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.Test/Uno.Net.Http.Implementation.Test.csproj
+++ b/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.Test/Uno.Net.Http.Implementation.Test.csproj
@@ -1,64 +1,12 @@
-
-
-
+
+
- Debug
- AnyCPU
- {9AA47731-A7CE-4113-9A78-C8FAD8862D90}
+ net6.0
Exe
- Properties
Uno.Net.Http.Implementation.Test
- Uno.Net.Http.Implementation.Test
- v4.5
- 512
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {d20c6ce2-b067-4911-acb1-3ee928c297a6}
- Uno.Net.Http.Implementation
-
+
-
-
-
\ No newline at end of file
+
diff --git a/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.sln b/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.sln
index 0bd63a416..6fe5c3661 100644
--- a/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.sln
+++ b/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation.sln
@@ -1,7 +1,6 @@
-
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30324.0
+# Visual Studio Version 16
+VisualStudioVersion = 25.0.1703.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Uno.Net.Http.Implementation", "Uno.Net.Http.Implementation\Uno.Net.Http.Implementation.csproj", "{D20C6CE2-B067-4911-ACB1-3EE928C297A6}"
EndProject
diff --git a/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation/Uno.Net.Http.Implementation.csproj b/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation/Uno.Net.Http.Implementation.csproj
index f06d08638..8a8bee90f 100644
--- a/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation/Uno.Net.Http.Implementation.csproj
+++ b/lib/Uno.Net.Http/cil/Uno.Net.Http.Implementation/Uno.Net.Http.Implementation.csproj
@@ -1,58 +1,8 @@
-
-
-
+
+
- Debug
- AnyCPU
- {D20C6CE2-B067-4911-ACB1-3EE928C297A6}
- Library
- Properties
+ net6.0
Uno.Net.Http.Implementation
- Uno.Net.Http.Implementation
- v4.5
- 512
-
- true
- full
- false
- ..\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
diff --git a/lib/UnoCore/cil/config.cil.uxl b/lib/UnoCore/cil/config.cil.uxl
index a0b8041d0..499288526 100644
--- a/lib/UnoCore/cil/config.cil.uxl
+++ b/lib/UnoCore/cil/config.cil.uxl
@@ -25,5 +25,9 @@
+
+
+
+
diff --git a/lib/UnoCore/cil/exe.cil.uxl b/lib/UnoCore/cil/exe.cil.uxl
index 77c7483af..f3fec7c01 100644
--- a/lib/UnoCore/cil/exe.cil.uxl
+++ b/lib/UnoCore/cil/exe.cil.uxl
@@ -2,13 +2,13 @@
-
+
-
+
@@ -16,7 +16,7 @@
-
+
diff --git a/package-lock.json b/package-lock.json
index 972409637..64bcb6a04 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "@fuse-open/uno",
- "version": "2.4.1",
+ "version": "3.0.0-beta.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -20,9 +20,9 @@
"integrity": "sha512-7BaCfTRlUg8HBe64aG2VqE3vb8VKqNzpEvVfu5jE27nrYcUoM+RgztDiawuuZT1AjieTb/PhQnMuRKaaElZbpQ=="
},
"dotnet-run": {
- "version": "1.5.0",
- "resolved": "https://registry.npmjs.org/dotnet-run/-/dotnet-run-1.5.0.tgz",
- "integrity": "sha512-Huwx7vUQzlCx59+JdcRRltSXnhyqCoBh2LmhmDbaTxFMaKBgKeYgkEy6Cx4Cb2Pr+DomHKuHmwFBksLLiD9VnA=="
+ "version": "2.0.0-beta.0",
+ "resolved": "https://registry.npmjs.org/dotnet-run/-/dotnet-run-2.0.0-beta.0.tgz",
+ "integrity": "sha512-YD6KaKTuUl2oif1Ycp1UkR+jZmzJ0I9sxqZKHvVEIlX/DfnNHVGfgljeVxgZXQllI7+LobmHQh4jWClcVhvG6A=="
},
"filecompare": {
"version": "1.0.4",
diff --git a/package.json b/package.json
index b9c59b5e4..2515afb3f 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,12 @@
{
"name": "@fuse-open/uno",
- "version": "2.4.1",
+ "version": "3.0.0-beta.0",
"description": "Extremely fast, native C#-dialect and powerful tooling for mobile and desktop developers.",
"dependencies": {
"@fuse-open/opentk": "^3.2.0",
"@fuse-open/transpiler": "^1.17.3",
"@fuse-open/xamarin-mac": "^8.8.0",
- "dotnet-run": "^1.5.0"
+ "dotnet-run": "^2.0.0-beta.0"
},
"devDependencies": {
"filecompare": "^1.0.4",
@@ -19,7 +19,7 @@
"prepack": "bash scripts/pack.sh",
"test": "bash scripts/test.sh",
"version": "bash scripts/version.sh",
- "uno": "dotnet-run bin/uno.exe"
+ "uno": "dotnet-run bin/net6.0/uno.dll"
},
"bin": {
"uno": "bin/uno.js"
diff --git a/runtime.sln b/runtime.sln
index 33dd9f730..f3dc1b13a 100644
--- a/runtime.sln
+++ b/runtime.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
-VisualStudioVersion = 16.0.30002.166
+VisualStudioVersion = 25.0.1703.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "app-win", "src\runtime\win\app-win.csproj", "{21D956DB-8735-4EE6-BA7E-1D6CD77521F4}"
EndProject
diff --git a/scripts/build.sh b/scripts/build.sh
index 53b4f3bd1..9835a9adc 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -23,24 +23,25 @@ if [ -z "$CONFIGURATION" ]; then
CONFIGURATION="Debug"
fi
-if [ ! -d packages/ ]; then
- INSTALL=1
-elif [ ! -d node_modules/ ]; then
+if [ -z "$VERBOSITY" ]; then
+ VERBOSITY="minimal"
+fi
+
+if [ ! -d node_modules/ ]; then
INSTALL=1
fi
if [ "$INSTALL" = 1 ]; then
- h1 "Installing dependencies"
- nuget restore uno.sln
+ h1 "Installing modules"
npm install
fi
h1 "Building uno"
-csharp-build uno.sln
+dotnet build --configuration $CONFIGURATION --verbosity $VERBOSITY uno.sln
h1 "Building runtime"
-uno build lib/UnoCore -DLIBRARY
-csharp-build runtime.sln
+uno build lib/UnoCore -DLIBRARY --trace
+dotnet build --configuration $CONFIGURATION --verbosity $VERBOSITY runtime.sln
h1 "Building lib"
uno doctor -ec$CONFIGURATION lib "$@"
diff --git a/scripts/clean.sh b/scripts/clean.sh
index 8c832a2c6..aac6d68bd 100755
--- a/scripts/clean.sh
+++ b/scripts/clean.sh
@@ -15,9 +15,11 @@ done
# Clean tests
uno clean --recursive tests
-# Clean C# solutions
-csharp-clean runtime.sln 1> /dev/null
-csharp-clean uno.sln 1> /dev/null
+# Clean .NET solutions
+dotnet clean --configuration Debug runtime.sln 1> /dev/null
+dotnet clean --configuration Release runtime.sln 1> /dev/null
+dotnet clean --configuration Debug uno.sln 1> /dev/null
+dotnet clean --configuration Release uno.sln 1> /dev/null
# Clean other artifacts
rm -rf bin packages
diff --git a/scripts/common.sh b/scripts/common.sh
index 27cebceb7..df718cea7 100644
--- a/scripts/common.sh
+++ b/scripts/common.sh
@@ -1,46 +1,8 @@
#!/bin/bash
set -e
-function find-msbuild {
- powershell -ExecutionPolicy ByPass -File scripts/find-msbuild.ps1
-}
-
-function csharp-build {
- if [ -z "$CONFIGURATION" ]; then
- CONFIGURATION="Debug"
- fi
-
- if [ "$OSTYPE" = msys ]; then
- msbuild=`find-msbuild`
- if [ $? != 0 ]; then
- exit $?
- fi
- "$msbuild" //m //p:Configuration=$CONFIGURATION //v:minimal "$@"
- else
- msbuild /m /property:Configuration=$CONFIGURATION /verbosity:minimal "$@"
- fi
-}
-
-function csharp-clean {
- if [ "$OSTYPE" = msys ]; then
- msbuild=`find-msbuild`
- if [ $? != 0 ]; then
- exit $?
- fi
- "$msbuild" //m //t:Clean //p:Configuration=Debug "$@"
- "$msbuild" //m //t:Clean //p:Configuration=Release "$@"
- else
- msbuild /m /target:Clean /property:Configuration=Debug "$@"
- msbuild /m /target:Clean /property:Configuration=Release "$@"
- fi
-}
-
-function dotnet-run {
- node_modules/.bin/dotnet-run "$@"
-}
-
function uno {
- dotnet-run bin/uno.exe "$@"
+ dotnet bin/net6.0/uno.dll "$@"
}
function h1 {
diff --git a/scripts/find-msbuild.ps1 b/scripts/find-msbuild.ps1
deleted file mode 100644
index 689dde8f4..000000000
--- a/scripts/find-msbuild.ps1
+++ /dev/null
@@ -1,43 +0,0 @@
-$env:Path += ";${env:ProgramFiles}\Microsoft Visual Studio\Installer"
-$env:Path += ";${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
-
-If (Get-Command "vswhere.exe" -ErrorAction SilentlyContinue)
-{
- vswhere.exe | Out-String -Stream | Select-String -SimpleMatch "installationPath:" | ForEach {
- $installationPath = $_ -Replace "^installationPath: ", ""
- $msbuild = "$installationPath\MSBuild\Current\bin\msbuild.exe"
- If (Test-Path $msbuild)
- {
- Write-Output $msbuild
- exit 0
- }
- $msbuild = "$installationPath\MSBuild\15.0\bin\msbuild.exe"
- If (Test-Path $msbuild)
- {
- Write-Output $msbuild
- exit 0
- }
- }
-}
-
-$msbuild1="${env:ProgramFiles}\MSBuild\14.0\bin\MSBuild.exe"
-$msbuild2="${env:ProgramFiles(x86)}\MSBuild\14.0\bin\MSBuild.exe"
-If (Test-Path $msbuild1)
-{
- Write-Output $msbuild1
- exit 0
-}
-ElseIf (Test-Path $msbuild2)
-{
- Write-Output $msbuild2
- exit 0
-}
-
-Write-Error -Message @"
-ERROR: Microsoft Build Tools 2015+ not installed (C# 6/.NET 4.5 support)
-(not found) vswhere / Visual Studio 2019
-(not found) vswhere / Visual Studio 2017
-(not found) $msbuild1"
-(not found) $msbuild2"
-"@
-exit 1
diff --git a/scripts/net6-upgrade.js b/scripts/net6-upgrade.js
new file mode 100644
index 000000000..351f531a5
--- /dev/null
+++ b/scripts/net6-upgrade.js
@@ -0,0 +1,111 @@
+const fs = require("fs")
+const path = require("path")
+const { resolve } = require('path')
+const { readdir } = require('fs').promises
+
+function upgradeCsproj(filename) {
+ const properties = []
+ const projectReferences = []
+ const packageReferences = []
+ const embeddedResources = []
+
+ for (const line of fs.readFileSync(filename).toString().split("\n")) {
+ if (line.includes("")) {
+ properties.push(line.trim())
+ } else if (line.includes("Exe")) {
+ properties.push(line.trim())
+ } else if (line.includes("", "\" />").trim())
+ } else if (line.includes("", "\" />").trim())
+ } else if (line.includes("", "\" />").trim())
+ }
+ }
+
+ const parentDir = path.dirname(filename)
+ const packagesFile = path.join(parentDir, "packages.config")
+
+ if (fs.existsSync(packagesFile)) {
+ for (const line of fs.readFileSync(packagesFile).toString().split("\n")) {
+ if (line.includes("`)
+ }
+ }
+
+ fs.rmSync(packagesFile)
+ }
+
+ console.log(`Upgrading ${filename}`)
+ fs.writeFileSync(filename, `
+
+
+ net6.0
+ ${properties.join("\n ")}
+
+${projectReferences.length > 0
+ ? `\n
+ ${projectReferences.join("\n ")}
+ `
+ : ""}${packageReferences.length > 0
+ ? `\n
+ ${packageReferences.join("\n ")}
+ `
+ : ""}${embeddedResources.length > 0
+ ? `\n
+ ${embeddedResources.join("\n ")}
+ `
+ : ""}
+
+`)
+}
+
+function upgradeSln(filename) {
+ const sln = fs.readFileSync(filename).toString()
+ const start = sln.indexOf("Project(")
+ console.log(`Upgrading ${filename}`)
+ fs.writeFileSync(filename, `Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 25.0.1703.0
+MinimumVisualStudioVersion = 10.0.40219.1
+${sln.substring(start).trim()}
+`)
+}
+
+async function* getFiles(dir) {
+ const dirents = await readdir(dir, { withFileTypes: true })
+ for (const dirent of dirents) {
+ const res = resolve(dir, dirent.name)
+ if (dirent.isDirectory()) {
+ yield* getFiles(res)
+ } else {
+ yield res
+ }
+ }
+}
+
+async function main() {
+ const root = process.argv[2]
+ console.log(`Scanning ${root}`)
+
+ for await (const file of getFiles(root)) {
+ if (file.endsWith(".csproj")) {
+ upgradeCsproj(file)
+ } else if (file.endsWith(".sln")) {
+ upgradeSln(file)
+ }
+ }
+}
+
+main()
+ .then(() => {
+ process.exit(0)
+ })
+ .catch(error => {
+ console.error(error)
+ process.exit(1)
+ })
diff --git a/scripts/test.sh b/scripts/test.sh
index 87e348c94..600ecd556 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -24,14 +24,14 @@ fi
# Run compiler tests
function uno-compiler-test {
for config in Debug Release; do
- exe=src/test/compiler-test/bin/$config/uno-compiler-test.exe
+ dll=src/test/compiler-test/bin/$config/net6.0/uno-compiler-test.dll
if [ -f $exe ]; then
- dotnet-run $exe
+ dotnet $dll
return $?
fi
done
- echo "ERROR: uno-compiler-test.exe was not found"
+ echo "ERROR: uno-compiler-test.dll was not found"
return 1
}
@@ -41,3 +41,10 @@ fi
# Check that all packages build without errors
uno build $TARGET --no-strip tests/pkgtest
+
+h1 "Running dotnet tests"
+#########################
+
+dotnet test \
+ src/test/tests/bin/Release/net6.0/Uno.TestRunner.Tests.dll \
+ src/ux/tests/bin/Release/net6.0/Uno.UX.Markup.Tests.dll
diff --git a/src/GlobalAssemblyInfo.cs b/src/GlobalAssemblyInfo.cs
index e675dc076..7cc520f44 100644
--- a/src/GlobalAssemblyInfo.cs
+++ b/src/GlobalAssemblyInfo.cs
@@ -13,15 +13,7 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("d159dc86-f510-4fcf-9573-e339bdd6d166")]
-
// Version information.
-[assembly: AssemblyVersion("2.4.1.0")]
-[assembly: AssemblyFileVersion("2.4.1.0")]
-[assembly: AssemblyInformationalVersion("2.4.1")]
+[assembly: AssemblyVersion("3.0.0.0")]
+[assembly: AssemblyFileVersion("3.0.0.0")]
+[assembly: AssemblyInformationalVersion("3.0.0-beta.0")]
diff --git a/src/GlobalAssemblyInfo.targets b/src/GlobalAssemblyInfo.props
similarity index 79%
rename from src/GlobalAssemblyInfo.targets
rename to src/GlobalAssemblyInfo.props
index 59a86cb6a..d36d79d04 100644
--- a/src/GlobalAssemblyInfo.targets
+++ b/src/GlobalAssemblyInfo.props
@@ -1,4 +1,9 @@
-
+
+
+
+ false
+
+
Properties\GlobalAssemblyInfo.cs
@@ -7,4 +12,4 @@
Properties\GlobalAssemblyInfo.Override.cs
-
\ No newline at end of file
+
diff --git a/src/common/CLI/Command.cs b/src/common/CLI/Command.cs
index 655ca0770..76db43f05 100644
--- a/src/common/CLI/Command.cs
+++ b/src/common/CLI/Command.cs
@@ -251,13 +251,6 @@ protected void WriteProductInfo()
WriteHead(".NET runtime", 10, 0);
WriteRow("OSVersion", Environment.OSVersion.VersionString);
WriteRow("Version", Environment.Version);
-
- // Mono version
- if (MonoInfo.IsRunningMono)
- {
- WriteHead("Mono", 10, 0);
- WriteRow("Version", MonoInfo.GetVersion());
- }
}
protected bool Confirm(string question)
diff --git a/src/common/Diagnostics/MonoInfo.cs b/src/common/Diagnostics/MonoInfo.cs
deleted file mode 100644
index f40c9291a..000000000
--- a/src/common/Diagnostics/MonoInfo.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-using Uno.Logging;
-
-namespace Uno.Diagnostics
-{
- public static class MonoInfo
- {
- public static bool IsRunningMono => Type.GetType("Mono.Runtime") != null;
-
- public static string GetVersion()
- {
- var mono = Type.GetType("Mono.Runtime");
- var displayName = mono?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
- return displayName?.Invoke(null, null)?.ToString();
- }
- }
-}
diff --git a/src/common/Diagnostics/PlatformDetection.cs b/src/common/Diagnostics/PlatformDetection.cs
index bf6246d2c..2f08d512d 100644
--- a/src/common/Diagnostics/PlatformDetection.cs
+++ b/src/common/Diagnostics/PlatformDetection.cs
@@ -1,23 +1,13 @@
using System;
-using System.IO;
using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
using Microsoft.Win32;
using Uno.CLI;
-using Uno.Logging;
-
-#pragma warning disable 649
-#pragma warning disable 169
namespace Uno.Diagnostics
{
public static class PlatformDetection
{
- public static readonly bool IsWindows;
- public static readonly bool IsLinux;
- public static readonly bool IsMac;
- public static readonly bool IsArm;
- public static readonly bool Is64Bit;
-
public static string HomeDirectory
{
get
@@ -26,7 +16,7 @@ public static string HomeDirectory
if (!string.IsNullOrEmpty(home))
return home;
- if (IsWindows)
+ if (OperatingSystem.IsWindows())
{
var userProfile = Environment.GetEnvironmentVariable("USERPROFILE");
if (!string.IsNullOrEmpty(userProfile))
@@ -46,25 +36,35 @@ public static string SystemString
{
get
{
- if (IsWindows)
+ var arch = RuntimeInformation.OSArchitecture;
+
+ if (OperatingSystem.IsWindows())
return WindowsVersion + " " + (
- Is64Bit
+ arch == Architecture.Arm
+ ? "ARM" :
+ arch == Architecture.Arm64
+ ? "ARM64" :
+ IntPtr.Size == 8
? "x64"
: "x86"
);
- if (IsMac)
+ if (OperatingSystem.IsMacOS())
return "macOS " + MacVersion + " " + (
- IsArm
- ? "ARM" + (Is64Bit ? "64" : null) :
- Is64Bit
+ arch == Architecture.Arm
+ ? "ARM" :
+ arch == Architecture.Arm64
+ ? "ARM64" :
+ IntPtr.Size == 8
? "x86_64"
: "i386"
);
- if (IsLinux)
+ if (OperatingSystem.IsLinux())
return "Linux " + Environment.OSVersion.Version.ToString(2) + " " + (
- IsArm
- ? "ARM" + (Is64Bit ? "64" : null) :
- Is64Bit
+ arch == Architecture.Arm
+ ? "ARM" :
+ arch == Architecture.Arm64
+ ? "ARM64" :
+ IntPtr.Size == 8
? "x86_64"
: "x86_32"
);
@@ -72,6 +72,7 @@ public static string SystemString
}
}
+ [SupportedOSPlatform("macOS")]
static string MacVersion
{
get
@@ -87,6 +88,7 @@ static string MacVersion
}
}
+ [SupportedOSPlatform("windows")]
static string WindowsVersion
{
get
@@ -106,55 +108,5 @@ static string WindowsVersion
}
}
}
-
- static PlatformDetection()
- {
- IsWindows = Path.DirectorySeparatorChar == '\\';
- Is64Bit = IntPtr.Size == 8;
-
- if (IsWindows)
- return;
-
- try
- {
- _Utsname utsname;
- if (Mono_Posix_Syscall_uname(out utsname) == 0)
- {
- try
- {
- var sysname = Marshal.PtrToStringAnsi(utsname.sysname);
- var machine = Marshal.PtrToStringAnsi(utsname.machine);
- IsLinux = sysname == "Linux";
- IsMac = sysname == "Darwin";
- IsArm = machine.StartsWith("arm", StringComparison.InvariantCulture);
- }
- finally
- {
- free(utsname._buf_);
- }
- }
- }
- catch (Exception e)
- {
- Log.Default.Warning("uname() failed: " + e.Message);
- }
- }
-
- struct _Utsname
- {
- public IntPtr sysname;
- public IntPtr nodename;
- public IntPtr release;
- public IntPtr version;
- public IntPtr machine;
- public IntPtr domainname;
- public IntPtr _buf_;
- }
-
- [DllImport("MonoPosixHelper", SetLastError = true)]
- static extern int Mono_Posix_Syscall_uname(out _Utsname buf);
-
- [DllImport("msvcrt", CallingConvention = CallingConvention.Cdecl)]
- static extern void free(IntPtr ptr);
}
}
diff --git a/src/common/Diagnostics/ProcessExtensions.cs b/src/common/Diagnostics/ProcessExtensions.cs
index 9c9b615dc..b793746c2 100644
--- a/src/common/Diagnostics/ProcessExtensions.cs
+++ b/src/common/Diagnostics/ProcessExtensions.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using System.Runtime.Versioning;
using Uno.Logging;
namespace Uno.Diagnostics
@@ -10,56 +11,64 @@ public static class ProcessExtensions
{
private static string FindIndexedProcessName(int pid)
{
- try
+ if (OperatingSystem.IsWindows())
{
- var processName = Process.GetProcessById(pid).ProcessName;
- var processesByName = Process.GetProcessesByName(processName);
+ try
+ {
+ var processName = Process.GetProcessById(pid).ProcessName;
+ var processesByName = Process.GetProcessesByName(processName);
- for (var index = 0; index < processesByName.Length; index++)
+ for (var index = 0; index < processesByName.Length; index++)
+ {
+ var indexedName = index == 0 ? processName : processName + "#" + index;
+ var processId = new PerformanceCounter("Process", "ID Process", indexedName);
+ if ((int)processId.NextSample().RawValue == pid)
+ return indexedName;
+ }
+ }
+ catch (InvalidOperationException e)
{
- var indexedName = index == 0 ? processName : processName + "#" + index;
- var processId = new PerformanceCounter("Process", "ID Process", indexedName);
- if ((int)processId.NextSample().RawValue == pid)
- return indexedName;
+ Log.Default.Warning(
+ "Exception in FindIndexedProcessName(): " + e.Message + "\n\n" +
+ "This may be resolved when resetting performance counters in Windows.\n" +
+ "To do this type the following in cmd.exe:\n" +
+ " lodctr /R\n" +
+ " lodctr \"C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.20506\\corperfmonsymbols.ini\"\n" +
+ "(Source: http://stackoverflow.com/questions/1540777/performancecounters-on-net-4-0-windows-7 )\n");
}
}
- catch (InvalidOperationException e)
- {
- Log.Default.Warning(
- "Exception in FindIndexedProcessName(): " + e.Message + "\n\n" +
- "This may be resolved when resetting performance counters in Windows.\n" +
- "To do this type the following in cmd.exe:\n" +
- " lodctr /R\n" +
- " lodctr \"C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.20506\\corperfmonsymbols.ini\"\n" +
- "(Source: http://stackoverflow.com/questions/1540777/performancecounters-on-net-4-0-windows-7 )\n");
- }
return null;
}
public static Process GetParent(this Process process)
{
- var indexedProcessName = FindIndexedProcessName(process.Id);
+ if (OperatingSystem.IsWindows())
+ {
+ var indexedProcessName = FindIndexedProcessName(process.Id);
- if (indexedProcessName == null)
- return null;
+ if (indexedProcessName == null)
+ return null;
- var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName);
- var pid = parentId.NextSample().RawValue;
- return Process
- .GetProcesses()
- .FirstOrDefault(
- p =>
- {
- try
- {
- return p.Id == pid && p.StartTime <= process.StartTime;
- }
- catch
+ var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName);
+ var pid = parentId.NextSample().RawValue;
+ return Process
+ .GetProcesses()
+ .FirstOrDefault(
+ p =>
{
- return false;
- }
- });
+ try
+ {
+ return p.Id == pid && p.StartTime <= process.StartTime;
+ }
+ catch
+ {
+ return false;
+ }
+ });
+ }
+
+ return null;
}
public static List GetParents(this Process process)
diff --git a/src/common/Diagnostics/ProcessTreeKiller.cs b/src/common/Diagnostics/ProcessTreeKiller.cs
index 174605811..c8e73767a 100644
--- a/src/common/Diagnostics/ProcessTreeKiller.cs
+++ b/src/common/Diagnostics/ProcessTreeKiller.cs
@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Management;
+using System.Runtime.Versioning;
namespace Uno.Diagnostics
{
@@ -9,13 +10,13 @@ public static class ProcessTreeKiller
{
public static void KillTree(int pid)
{
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
{
KillWindowsTree(pid);
}
- else if (PlatformDetection.IsMac)
+ else if (OperatingSystem.IsMacOS())
{
- KillOsxTree(pid);
+ KillMacTree(pid);
}
else
{
@@ -24,6 +25,7 @@ public static void KillTree(int pid)
}
//http://stackoverflow.com/a/10402906/7084
+ [SupportedOSPlatform("windows")]
private static void KillWindowsTree(int pid)
{
var searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
@@ -46,10 +48,11 @@ private static void KillWindowsTree(int pid)
}
}
- private static void KillOsxTree(int pid)
+ [SupportedOSPlatform("macOS")]
+ private static void KillMacTree(int pid)
{
const string scriptPath = "/tmp/uno_kill_script.sh";
- File.WriteAllText(scriptPath, (OsxKillScript.Replace("PID_GOES_HERE", pid.ToString())).Replace("\r", ""));
+ File.WriteAllText(scriptPath, (MacKillScript.Replace("PID_GOES_HERE", pid.ToString())).Replace("\r", ""));
var p = new Process
{
StartInfo =
@@ -62,7 +65,8 @@ private static void KillOsxTree(int pid)
p.Start();
}
- private const string OsxKillScript = @"#!/bin/sh
+ [SupportedOSPlatform("macOS")]
+ private const string MacKillScript = @"#!/bin/sh
kill_tree() {
ps -o pid,ppid | while read line; do
diff --git a/src/common/Diagnostics/Shell.cs b/src/common/Diagnostics/Shell.cs
index 5589d5b56..5337443a9 100644
--- a/src/common/Diagnostics/Shell.cs
+++ b/src/common/Diagnostics/Shell.cs
@@ -27,9 +27,9 @@ public void Open(string filename, string args = "")
{
var command = GetCommand(filename, args, null);
- if (PlatformDetection.IsMac)
+ if (OperatingSystem.IsMacOS())
Run("open", command);
- else if (PlatformDetection.IsWindows && string.IsNullOrEmpty(args))
+ else if (OperatingSystem.IsWindows() && string.IsNullOrEmpty(args))
Run("explorer", command);
else
{
@@ -250,7 +250,7 @@ static void InitTimer()
// When pressing CTRL+C at this point, the signal is handled by the first cmd.exe which doesn't kill the entire
// process tree, leaving dangling processes around unless we detect that the parent process has exited.
- if (PlatformDetection.IsWindows && !_timerInited)
+ if (OperatingSystem.IsWindows() && !_timerInited)
{
lock (Lock)
{
diff --git a/src/common/Diagnostics/UnoVersion.cs b/src/common/Diagnostics/UnoVersion.cs
index 5404cb447..5aa23edae 100644
--- a/src/common/Diagnostics/UnoVersion.cs
+++ b/src/common/Diagnostics/UnoVersion.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using System;
+using System.Diagnostics;
using System.Linq;
using System.Reflection;
@@ -50,7 +51,7 @@ public static string Copyright
var copyright = GetAttribute()?.Copyright;
return string.IsNullOrEmpty(copyright)
? "(no copyright information)" :
- PlatformDetection.IsWindows // The Windows shell can't print the © character
+ OperatingSystem.IsWindows() // The Windows shell can't print the © character
? copyright.Replace("©", "(C)")
: copyright;
}
diff --git a/src/common/IO/Disk.cs b/src/common/IO/Disk.cs
index 2543f8e52..d77f81a81 100644
--- a/src/common/IO/Disk.cs
+++ b/src/common/IO/Disk.cs
@@ -148,7 +148,7 @@ public void DeleteDirectory(string dirName, bool knownToExist = false)
public void MakeExecutable(string filename)
{
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
return;
try
diff --git a/src/common/IO/Extensions.cs b/src/common/IO/Extensions.cs
index 8104976b7..bfdfc109f 100644
--- a/src/common/IO/Extensions.cs
+++ b/src/common/IO/Extensions.cs
@@ -84,7 +84,7 @@ public static string ToRelativePath(this string filename, string parentDir = nul
}
}
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
{
// Convert drive letters to uppercase to avoid bugs
if (filename.Length > 1 && filename[1] == ':' && char.IsLower(filename[0]))
diff --git a/src/common/Logging/LogState.cs b/src/common/Logging/LogState.cs
index 80e302b49..88ac9c5b8 100644
--- a/src/common/Logging/LogState.cs
+++ b/src/common/Logging/LogState.cs
@@ -20,13 +20,13 @@ static int GetNumberOfSpaces()
{
return Math.Max(Console.WindowWidth - 1, 0);
}
- catch (System.IO.IOException)
+ catch (IOException)
{
return 80; // not attached to a terminal?
}
}
- static readonly string _spinner = PlatformDetection.IsWindows
+ static readonly string _spinner = OperatingSystem.IsWindows()
? "|/-\\" // The Windows shell can't print the dot characters
: "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
static readonly Stopwatch _w = Stopwatch.StartNew();
diff --git a/src/common/Uno.Common.csproj b/src/common/Uno.Common.csproj
index 919b480ca..bd1349f9a 100644
--- a/src/common/Uno.Common.csproj
+++ b/src/common/Uno.Common.csproj
@@ -1,94 +1,13 @@
-
-
+
+
+
- Debug
- AnyCPU
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Library
- Properties
+ net6.0
Uno
- Uno.Common
- v4.5
- 512
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/api/Uno.Compiler.API.csproj b/src/compiler/api/Uno.Compiler.API.csproj
index b8c3a872d..70a73774f 100644
--- a/src/compiler/api/Uno.Compiler.API.csproj
+++ b/src/compiler/api/Uno.Compiler.API.csproj
@@ -1,450 +1,12 @@
-
-
+
+
+
- Debug
- AnyCPU
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Library
- Properties
+ net6.0
Uno.Compiler.API
- Uno.Compiler.API
- v4.5
- 512
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/backend/cil/CilLinker.cs b/src/compiler/backend/cil/CilLinker.cs
index b6675c4c3..5c812a4cd 100644
--- a/src/compiler/backend/cil/CilLinker.cs
+++ b/src/compiler/backend/cil/CilLinker.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Runtime.CompilerServices;
using IKVM.Reflection;
using IKVM.Reflection.Emit;
@@ -9,6 +10,7 @@
using Uno.Compiler.API.Domain.IL.Members;
using Uno.Compiler.API.Domain.IL.Types;
using Uno.Logging;
+using ResolveEventArgs = IKVM.Reflection.ResolveEventArgs;
using Type = IKVM.Reflection.Type;
namespace Uno.Compiler.Backends.CIL
@@ -56,6 +58,7 @@ public CilLinker(Log log, IEssentials essentials, bool isReferenceAssembly = fal
{
_essentials = essentials;
_isReferenceAssembly = isReferenceAssembly;
+ Universe.AssemblyResolve += ResolveAssemblyEvent;
System_Object = Universe.Import(typeof(object));
System_String = Universe.Import(typeof(string));
System_ValueType = Universe.Import(typeof(ValueType));
@@ -74,6 +77,17 @@ public CilLinker(Log log, IEssentials essentials, bool isReferenceAssembly = fal
_types.Add(DataType.Void, System_Void);
}
+ Assembly ResolveAssemblyEvent(object sender, ResolveEventArgs args)
+ {
+ var name = args.Name;
+ var end = name.IndexOf(", Version=");
+
+ if (end != -1)
+ name = name.Substring(0, end);
+
+ return Universe.LoadFile(Path.Combine(DotNet.RuntimeDirectory, name + ".dll"));
+ }
+
public Assembly AddAssemblyFile(string filename, bool copyToOutputDir = false)
{
var asm = Universe.LoadFile(filename);
diff --git a/src/compiler/backend/cil/DotNet.cs b/src/compiler/backend/cil/DotNet.cs
new file mode 100644
index 000000000..615e4e592
--- /dev/null
+++ b/src/compiler/backend/cil/DotNet.cs
@@ -0,0 +1,51 @@
+using System.IO;
+using System.Runtime.InteropServices;
+using System;
+
+namespace Uno.Compiler.Backends.CIL
+{
+ public static class DotNet
+ {
+ public static readonly string RefAssemblyDirectory = GetRefAssemblyDirectory();
+
+ public static readonly string RuntimeDirectory = GetRuntimeDirectory();
+
+ // Returns something like:
+ // * /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Ref/6.0.8/ref/net6.0
+ // * C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.9\ref\net6.0
+ static string GetRefAssemblyDirectory()
+ {
+ string version;
+ var dotnetDir = GetDotNetDirectory(out version);
+ return Path.Combine(
+ dotnetDir,
+ "packs",
+ "Microsoft.NETCore.App.Ref",
+ version,
+ "ref",
+ "net6.0"
+ );
+ }
+
+ // Returns something like:
+ // * /usr/local/share/dotnet and 6.0.8
+ // * C:\Program Files\dotnet and 6.0.9
+ static string GetDotNetDirectory(out string version)
+ {
+ var runtimeDir = GetRuntimeDirectory();
+ version = Path.GetFileName(runtimeDir);
+ var packageDir = Path.GetDirectoryName(runtimeDir);
+ var sharedDir = Path.GetDirectoryName(packageDir);
+ return Path.GetDirectoryName(sharedDir);
+ }
+
+ // Returns something like:
+ // * /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.8
+ // * C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.9
+ static string GetRuntimeDirectory()
+ {
+ return RuntimeEnvironment.GetRuntimeDirectory()
+ .TrimEnd(Path.DirectorySeparatorChar);
+ }
+ }
+}
diff --git a/src/compiler/backend/cil/Uno.Compiler.Backends.CIL.csproj b/src/compiler/backend/cil/Uno.Compiler.Backends.CIL.csproj
index 75ae4e3b7..ec5ddf3ae 100644
--- a/src/compiler/backend/cil/Uno.Compiler.Backends.CIL.csproj
+++ b/src/compiler/backend/cil/Uno.Compiler.Backends.CIL.csproj
@@ -1,99 +1,17 @@
-
-
+
+
+
- Debug
- AnyCPU
- {B3B455C8-DD3D-4655-B10C-3C6BE878911E}
- Library
- Properties
+ net6.0
Uno.Compiler.Backends.CIL
- Uno.Compiler.Backends.CIL
- v4.5
- 512
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
- ..\..\..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.dll
-
-
- ..\..\..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.Mdb.dll
-
-
- ..\..\..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.Pdb.dll
-
-
- ..\..\..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.Rocks.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {4cb170ef-dfe6-4a56-9e1b-a85449e827a7}
- IKVM.Reflection
-
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
+
+
-
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/backend/cil/packages.config b/src/compiler/backend/cil/packages.config
deleted file mode 100644
index 1febd1f42..000000000
--- a/src/compiler/backend/cil/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/compiler/backend/cpp/Uno.Compiler.Backends.CPlusPlus.csproj b/src/compiler/backend/cpp/Uno.Compiler.Backends.CPlusPlus.csproj
index aa532e446..3f9ab11c3 100644
--- a/src/compiler/backend/cpp/Uno.Compiler.Backends.CPlusPlus.csproj
+++ b/src/compiler/backend/cpp/Uno.Compiler.Backends.CPlusPlus.csproj
@@ -1,82 +1,13 @@
-
-
+
+
+
- Debug
- AnyCPU
- {9E0318A1-528E-4AFD-AB87-C8D58E0CD060}
- Library
- Properties
+ net6.0
Uno.Compiler.Backends.CPlusPlus
- Uno.Compiler.Backends.CPlusPlus
- v4.5
- 512
-
- ..\..\..\
- true
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
+
-
-
diff --git a/src/compiler/backend/ikvm/AmbiguousMatchException.cs b/src/compiler/backend/ikvm/AmbiguousMatchException.cs
index 6a43621b5..74eabdae6 100644
--- a/src/compiler/backend/ikvm/AmbiguousMatchException.cs
+++ b/src/compiler/backend/ikvm/AmbiguousMatchException.cs
@@ -25,9 +25,7 @@ Jeroen Frijters
namespace IKVM.Reflection
{
-#if !CORECLR
[Serializable]
-#endif
public sealed class AmbiguousMatchException : Exception
{
public AmbiguousMatchException()
@@ -44,11 +42,9 @@ public AmbiguousMatchException(string message, Exception inner)
{
}
-#if !CORECLR
private AmbiguousMatchException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
-#endif
}
}
diff --git a/src/compiler/backend/ikvm/Assembly.cs b/src/compiler/backend/ikvm/Assembly.cs
index 990c4088e..184ec481e 100644
--- a/src/compiler/backend/ikvm/Assembly.cs
+++ b/src/compiler/backend/ikvm/Assembly.cs
@@ -26,239 +26,241 @@ Jeroen Frijters
namespace IKVM.Reflection
{
- public delegate Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
-
- public abstract class Assembly : ICustomAttributeProvider
- {
- internal readonly Universe universe;
- protected string fullName; // AssemblyBuilder needs access to this field to clear it when the name changes
- protected List resolvers;
-
- internal Assembly(Universe universe)
- {
- this.universe = universe;
- }
-
- public sealed override string ToString()
- {
- return FullName;
- }
-
- public event ModuleResolveEventHandler ModuleResolve
- {
- add
- {
- if (resolvers == null)
- {
- resolvers = new List();
- }
- resolvers.Add(value);
- }
- remove
- {
- resolvers.Remove(value);
- }
- }
-
- public abstract Type[] GetTypes();
- public abstract AssemblyName GetName();
- public abstract string ImageRuntimeVersion { get; }
- public abstract Module ManifestModule { get; }
- public abstract MethodInfo EntryPoint { get; }
- public abstract string Location { get; }
- public abstract AssemblyName[] GetReferencedAssemblies();
- public abstract Module[] GetModules(bool getResourceModules);
- public abstract Module[] GetLoadedModules(bool getResourceModules);
- public abstract Module GetModule(string name);
- public abstract string[] GetManifestResourceNames();
- public abstract ManifestResourceInfo GetManifestResourceInfo(string resourceName);
- public abstract System.IO.Stream GetManifestResourceStream(string name);
-
- internal abstract Type FindType(TypeName name);
- internal abstract Type FindTypeIgnoreCase(TypeName lowerCaseName);
-
- // The differences between ResolveType and FindType are:
- // - ResolveType is only used when a type is assumed to exist (because another module's metadata claims it)
- // - ResolveType can return a MissingType
- internal Type ResolveType(Module requester, TypeName typeName)
- {
- return FindType(typeName) ?? universe.GetMissingTypeOrThrow(requester, this.ManifestModule, null, typeName);
- }
-
- public string FullName
- {
- get { return fullName ?? (fullName = GetName().FullName); }
- }
-
- public Module[] GetModules()
- {
- return GetModules(true);
- }
-
- public IEnumerable Modules
- {
- get { return GetLoadedModules(); }
- }
-
- public Module[] GetLoadedModules()
- {
- return GetLoadedModules(true);
- }
-
- public AssemblyName GetName(bool copiedName)
- {
- return GetName();
- }
-
- public bool ReflectionOnly
- {
- get { return true; }
- }
-
- public Type[] GetExportedTypes()
- {
- List list = new List();
- foreach (Type type in GetTypes())
- {
- if (type.IsVisible)
- {
- list.Add(type);
- }
- }
- return list.ToArray();
- }
-
- public IEnumerable ExportedTypes
- {
- get { return GetExportedTypes(); }
- }
-
- public IEnumerable DefinedTypes
- {
- get
- {
- Type[] types = GetTypes();
- TypeInfo[] typeInfos = new TypeInfo[types.Length];
- for (int i = 0; i < types.Length; i++)
- {
- typeInfos[i] = types[i].GetTypeInfo();
- }
- return typeInfos;
- }
- }
-
- public Type GetType(string name)
- {
- return GetType(name, false);
- }
-
- public Type GetType(string name, bool throwOnError)
- {
- return GetType(name, throwOnError, false);
- }
-
- public Type GetType(string name, bool throwOnError, bool ignoreCase)
- {
- TypeNameParser parser = TypeNameParser.Parse(name, throwOnError);
- if (parser.Error)
- {
- return null;
- }
- if (parser.AssemblyName != null)
- {
- if (throwOnError)
- {
- throw new ArgumentException("Type names passed to Assembly.GetType() must not specify an assembly.");
- }
- else
- {
- return null;
- }
- }
- TypeName typeName = TypeName.Split(TypeNameParser.Unescape(parser.FirstNamePart));
- Type type = ignoreCase
- ? FindTypeIgnoreCase(typeName.ToLowerInvariant())
- : FindType(typeName);
- if (type == null && __IsMissing)
- {
- throw new MissingAssemblyException((MissingAssembly)this);
- }
- return parser.Expand(type, this.ManifestModule, throwOnError, name, false, ignoreCase);
- }
-
- public virtual Module LoadModule(string moduleName, byte[] rawModule)
- {
- throw new NotSupportedException();
- }
-
- public Module LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore)
- {
- return LoadModule(moduleName, rawModule);
- }
-
- public bool IsDefined(Type attributeType, bool inherit)
- {
- return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
- }
-
- public IList __GetCustomAttributes(Type attributeType, bool inherit)
- {
- return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
- }
-
- public IList GetCustomAttributesData()
- {
- return CustomAttributeData.GetCustomAttributes(this);
- }
-
- public IEnumerable CustomAttributes
- {
- get { return GetCustomAttributesData(); }
- }
-
- public static string CreateQualifiedName(string assemblyName, string typeName)
- {
- return typeName + ", " + assemblyName;
- }
-
- public static Assembly GetAssembly(Type type)
- {
- return type.Assembly;
- }
-
- public string CodeBase
- {
- get
- {
- string path = this.Location.Replace(System.IO.Path.DirectorySeparatorChar, '/');
- if (!path.StartsWith("/"))
- {
- path = "/" + path;
- }
- return "file://" + path;
- }
- }
-
- public virtual bool IsDynamic
- {
- get { return false; }
- }
-
- public virtual bool __IsMissing
- {
- get { return false; }
- }
-
- public AssemblyNameFlags __AssemblyFlags
- {
- get { return GetAssemblyFlags(); }
- }
-
- protected virtual AssemblyNameFlags GetAssemblyFlags()
- {
- return GetName().Flags;
- }
-
- internal abstract IList GetCustomAttributesData(Type attributeType);
- }
+
+ public delegate Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
+
+ public abstract class Assembly : ICustomAttributeProvider
+ {
+
+ internal readonly Universe universe;
+ protected string fullName; // AssemblyBuilder needs access to this field to clear it when the name changes
+ protected List resolvers;
+
+ internal Assembly(Universe universe)
+ {
+ this.universe = universe;
+ }
+
+ public sealed override string ToString()
+ {
+ return FullName;
+ }
+
+ public event ModuleResolveEventHandler ModuleResolve
+ {
+ add
+ {
+ if (resolvers == null)
+ {
+ resolvers = new List();
+ }
+ resolvers.Add(value);
+ }
+ remove
+ {
+ resolvers.Remove(value);
+ }
+ }
+
+ public abstract Type[] GetTypes();
+ public abstract AssemblyName GetName();
+ public abstract string ImageRuntimeVersion { get; }
+ public abstract Module ManifestModule { get; }
+ public abstract MethodInfo EntryPoint { get; }
+ public abstract string Location { get; }
+ public abstract AssemblyName[] GetReferencedAssemblies();
+ public abstract Module[] GetModules(bool getResourceModules);
+ public abstract Module[] GetLoadedModules(bool getResourceModules);
+ public abstract Module GetModule(string name);
+ public abstract string[] GetManifestResourceNames();
+ public abstract ManifestResourceInfo GetManifestResourceInfo(string resourceName);
+ public abstract System.IO.Stream GetManifestResourceStream(string name);
+
+ internal abstract Type FindType(TypeName name);
+ internal abstract Type FindTypeIgnoreCase(TypeName lowerCaseName);
+
+ // The differences between ResolveType and FindType are:
+ // - ResolveType is only used when a type is assumed to exist (because another module's metadata claims it)
+ // - ResolveType can return a MissingType
+ internal Type ResolveType(Module requester, TypeName typeName)
+ {
+ return FindType(typeName) ?? universe.GetMissingTypeOrThrow(requester, this.ManifestModule, null, typeName);
+ }
+
+ public string FullName
+ {
+ get { return fullName ?? (fullName = GetName().FullName); }
+ }
+
+ public Module[] GetModules()
+ {
+ return GetModules(true);
+ }
+
+ public IEnumerable Modules
+ {
+ get { return GetLoadedModules(); }
+ }
+
+ public Module[] GetLoadedModules()
+ {
+ return GetLoadedModules(true);
+ }
+
+ public AssemblyName GetName(bool copiedName)
+ {
+ return GetName();
+ }
+
+ public bool ReflectionOnly
+ {
+ get { return true; }
+ }
+
+ public Type[] GetExportedTypes()
+ {
+ List list = new List();
+ foreach (Type type in GetTypes())
+ {
+ if (type.IsVisible)
+ {
+ list.Add(type);
+ }
+ }
+ return list.ToArray();
+ }
+
+ public IEnumerable ExportedTypes
+ {
+ get { return GetExportedTypes(); }
+ }
+
+ public IEnumerable DefinedTypes
+ {
+ get
+ {
+ Type[] types = GetTypes();
+ TypeInfo[] typeInfos = new TypeInfo[types.Length];
+ for (int i = 0; i < types.Length; i++)
+ {
+ typeInfos[i] = types[i].GetTypeInfo();
+ }
+ return typeInfos;
+ }
+ }
+
+ public Type GetType(string name)
+ {
+ return GetType(name, false);
+ }
+
+ public Type GetType(string name, bool throwOnError)
+ {
+ return GetType(name, throwOnError, false);
+ }
+
+ public Type GetType(string name, bool throwOnError, bool ignoreCase)
+ {
+ TypeNameParser parser = TypeNameParser.Parse(name, throwOnError);
+ if (parser.Error)
+ {
+ return null;
+ }
+ if (parser.AssemblyName != null)
+ {
+ if (throwOnError)
+ {
+ throw new ArgumentException("Type names passed to Assembly.GetType() must not specify an assembly.");
+ }
+ else
+ {
+ return null;
+ }
+ }
+ TypeName typeName = TypeName.Split(TypeNameParser.Unescape(parser.FirstNamePart));
+ Type type = ignoreCase
+ ? FindTypeIgnoreCase(typeName.ToLowerInvariant())
+ : FindType(typeName);
+ if (type == null && __IsMissing)
+ {
+ throw new MissingAssemblyException((MissingAssembly)this);
+ }
+ return parser.Expand(type, this.ManifestModule, throwOnError, name, false, ignoreCase);
+ }
+
+ public virtual Module LoadModule(string moduleName, byte[] rawModule)
+ {
+ throw new NotSupportedException();
+ }
+
+ public Module LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore)
+ {
+ return LoadModule(moduleName, rawModule);
+ }
+
+ public bool IsDefined(Type attributeType, bool inherit)
+ {
+ return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
+ }
+
+ public IList __GetCustomAttributes(Type attributeType, bool inherit)
+ {
+ return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
+ }
+
+ public IList GetCustomAttributesData()
+ {
+ return CustomAttributeData.GetCustomAttributes(this);
+ }
+
+ public IEnumerable CustomAttributes
+ {
+ get { return GetCustomAttributesData(); }
+ }
+
+ public static string CreateQualifiedName(string assemblyName, string typeName)
+ {
+ return typeName + ", " + assemblyName;
+ }
+
+ public static Assembly GetAssembly(Type type)
+ {
+ return type.Assembly;
+ }
+
+ public string CodeBase
+ {
+ get
+ {
+ string path = this.Location.Replace(System.IO.Path.DirectorySeparatorChar, '/');
+ if (!path.StartsWith("/"))
+ {
+ path = "/" + path;
+ }
+ return "file://" + path;
+ }
+ }
+
+ public virtual bool IsDynamic
+ {
+ get { return false; }
+ }
+
+ public virtual bool __IsMissing
+ {
+ get { return false; }
+ }
+
+ public AssemblyNameFlags __AssemblyFlags
+ {
+ get { return GetAssemblyFlags(); }
+ }
+
+ protected virtual AssemblyNameFlags GetAssemblyFlags()
+ {
+ return GetName().Flags;
+ }
+
+ internal abstract IList GetCustomAttributesData(Type attributeType);
+ }
}
diff --git a/src/compiler/backend/ikvm/AssemblyName.cs b/src/compiler/backend/ikvm/AssemblyName.cs
index ce2a96b73..bd8b68411 100644
--- a/src/compiler/backend/ikvm/AssemblyName.cs
+++ b/src/compiler/backend/ikvm/AssemblyName.cs
@@ -32,9 +32,7 @@ Jeroen Frijters
namespace IKVM.Reflection
{
public sealed class AssemblyName
-#if !CORECLR
: ICloneable
-#endif
{
private string name;
private string culture;
@@ -174,11 +172,6 @@ public CultureInfo CultureInfo
}
public string CultureName
- {
- get { return culture; }
- }
-
- internal string Culture
{
get { return culture; }
set { culture = value; }
@@ -202,7 +195,6 @@ public string CodeBase
set { codeBase = value; }
}
-#if !CORECLR
public string EscapedCodeBase
{
get
@@ -213,7 +205,6 @@ public string EscapedCodeBase
return tmp.EscapedCodeBase;
}
}
-#endif
public ProcessorArchitecture ProcessorArchitecture
{
@@ -402,16 +393,17 @@ internal static byte[] ComputePublicKeyToken(byte[] publicKey)
{
return publicKey;
}
- using (var sha1 = SHA1.Create())
+ byte[] hash;
+ using (SHA1 sha1 = SHA1.Create())
{
- byte[] hash = sha1.ComputeHash(publicKey);
- byte[] token = new byte[8];
- for (int i = 0; i < token.Length; i++)
- {
- token[i] = hash[hash.Length - 1 - i];
- }
- return token;
+ hash = sha1.ComputeHash(publicKey);
+ }
+ byte[] token = new byte[8];
+ for (int i = 0; i < token.Length; i++)
+ {
+ token[i] = hash[hash.Length - 1 - i];
}
+ return token;
}
internal static string ComputePublicKeyToken(string publicKey)
@@ -454,13 +446,11 @@ private static byte[] Copy(byte[] b)
return b == null || b.Length == 0 ? b : (byte[])b.Clone();
}
-#if !CORECLR
public static bool ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition)
{
// HACK use the real AssemblyName to implement the (broken) ReferenceMatchesDefinition method
return System.Reflection.AssemblyName.ReferenceMatchesDefinition(new System.Reflection.AssemblyName(reference.FullName), new System.Reflection.AssemblyName(definition.FullName));
}
-#endif
public static AssemblyName GetAssemblyName(string path)
{
diff --git a/src/compiler/backend/ikvm/BadImageFormatException.cs b/src/compiler/backend/ikvm/BadImageFormatException.cs
index 570443496..9abe4f606 100644
--- a/src/compiler/backend/ikvm/BadImageFormatException.cs
+++ b/src/compiler/backend/ikvm/BadImageFormatException.cs
@@ -25,9 +25,7 @@ Jeroen Frijters
namespace IKVM.Reflection
{
-#if !CORECLR
[Serializable]
-#endif
public sealed class BadImageFormatException : Exception
{
public BadImageFormatException()
@@ -44,11 +42,9 @@ public BadImageFormatException(string message, Exception inner)
{
}
-#if !CORECLR
private BadImageFormatException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
-#endif
}
}
diff --git a/src/compiler/backend/ikvm/Binder.cs b/src/compiler/backend/ikvm/Binder.cs
index ca12f6b72..ef8e35885 100644
--- a/src/compiler/backend/ikvm/Binder.cs
+++ b/src/compiler/backend/ikvm/Binder.cs
@@ -109,7 +109,7 @@ private static bool MatchParameterTypes(ParameterInfo[] parameters, Type[] types
private static void SelectBestMatch(MethodBase candidate, Type[] types, ref MethodBase currentBest, ref bool ambiguous)
{
- switch (MatchSignatures(currentBest.MethodSignature, candidate.MethodSignature, types))
+ switch (MatchSignatures(currentBest, candidate, types))
{
case 1:
return;
@@ -149,12 +149,16 @@ private static int GetInheritanceDepth(Type type)
return depth;
}
- private static int MatchSignatures(MethodSignature sig1, MethodSignature sig2, Type[] types)
+ private static int MatchSignatures(MethodBase mb1, MethodBase mb2, Type[] types)
{
+ MethodSignature sig1 = mb1.MethodSignature;
+ MethodSignature sig2 = mb2.MethodSignature;
+ IGenericBinder gb1 = mb1 as IGenericBinder ?? mb1.DeclaringType;
+ IGenericBinder gb2 = mb2 as IGenericBinder ?? mb2.DeclaringType;
for (int i = 0; i < sig1.GetParameterCount(); i++)
{
- Type type1 = sig1.GetParameterType(i);
- Type type2 = sig2.GetParameterType(i);
+ Type type1 = sig1.GetParameterType(gb1, i);
+ Type type2 = sig2.GetParameterType(gb2, i);
if (type1 != type2)
{
return MatchTypes(type1, type2, types[i]);
diff --git a/src/compiler/backend/ikvm/CustomAttributeData.cs b/src/compiler/backend/ikvm/CustomAttributeData.cs
index 9da38ce6c..b9574d563 100644
--- a/src/compiler/backend/ikvm/CustomAttributeData.cs
+++ b/src/compiler/backend/ikvm/CustomAttributeData.cs
@@ -412,7 +412,7 @@ private static CustomAttributeTypedArgument ReadFixedArg(Module context, ByteRea
}
else
{
- throw new InvalidOperationException(type.ToString());
+ throw new InvalidOperationException();
}
}
diff --git a/src/compiler/backend/ikvm/Emit/AssemblyBuilder.cs b/src/compiler/backend/ikvm/Emit/AssemblyBuilder.cs
index 349dfc1dc..e2707c9bc 100644
--- a/src/compiler/backend/ikvm/Emit/AssemblyBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/AssemblyBuilder.cs
@@ -23,21 +23,19 @@ Jeroen Frijters
*/
using System;
using System.Collections.Generic;
-using System.Configuration.Assemblies;
using System.IO;
-using System.Diagnostics;
-using System.Globalization;
using System.Resources;
using System.Security.Cryptography;
-using System.Security;
+
using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Impl;
using IKVM.Reflection.Writer;
namespace IKVM.Reflection.Emit
{
- public sealed class AssemblyBuilder : Assembly
+
+ public sealed class AssemblyBuilder : Assembly
{
+
private readonly string name;
private ushort majorVersion;
private ushort minorVersion;
@@ -82,9 +80,7 @@ private struct ResourceFile
internal string Name;
internal string FileName;
internal ResourceAttributes Attributes;
-#if !CORECLR
internal ResourceWriter Writer;
-#endif
}
internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, IEnumerable customAttributes)
@@ -92,9 +88,9 @@ internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, IEnum
{
this.name = name.Name;
SetVersionHelper(name.Version);
- if (!string.IsNullOrEmpty(name.Culture))
+ if (!string.IsNullOrEmpty(name.CultureName))
{
- this.culture = name.Culture;
+ this.culture = name.CultureName;
}
this.flags = name.RawFlags;
this.hashAlgorithm = name.HashAlgorithm;
@@ -120,13 +116,13 @@ internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, IEnum
{
this.customAttributes.AddRange(customAttributes);
}
- if (universe.HasMscorlib && !universe.Mscorlib.__IsMissing && universe.Mscorlib.ImageRuntimeVersion != null)
+ if (universe.HasCoreLib && !universe.CoreLib.__IsMissing && universe.CoreLib.ImageRuntimeVersion != null)
{
- this.imageRuntimeVersion = universe.Mscorlib.ImageRuntimeVersion;
+ this.imageRuntimeVersion = universe.CoreLib.ImageRuntimeVersion;
}
else
{
- this.imageRuntimeVersion = typeof(object).Assembly.ImageRuntimeVersion;
+ this.imageRuntimeVersion = TypeUtil.GetAssembly(typeof(object)).ImageRuntimeVersion;
}
universe.RegisterDynamicAssembly(this);
}
@@ -225,7 +221,7 @@ public override AssemblyName GetName()
AssemblyName n = new AssemblyName();
n.Name = name;
n.Version = new Version(majorVersion, minorVersion, buildVersion, revisionVersion);
- n.Culture = culture ?? "";
+ n.CultureName = culture ?? "";
n.HashAlgorithm = hashAlgorithm;
n.RawFlags = flags;
n.SetPublicKey(publicKey != null ? (byte[])publicKey.Clone() : Empty.Array);
@@ -415,13 +411,11 @@ private void SaveImpl(string assemblyFileName, Stream streamOrNull, PortableExec
foreach (ResourceFile resfile in resourceFiles)
{
-#if !CORECLR
if (resfile.Writer != null)
{
resfile.Writer.Generate();
resfile.Writer.Close();
}
-#endif
int fileToken = AddFile(manifestModule, resfile.FileName, 1 /*ContainsNoMetaData*/);
ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
rec.Offset = 0;
@@ -472,23 +466,18 @@ private void SaveImpl(string assemblyFileName, Stream streamOrNull, PortableExec
private int AddFile(ModuleBuilder manifestModule, string fileName, int flags)
{
- using (var hash = SHA1.Create())
+ string fullPath = fileName;
+ if (dir != null)
{
- string fullPath = fileName;
- if (dir != null)
- {
- fullPath = Path.Combine(dir, fileName);
- }
- using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
- {
- using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
- {
- byte[] buf = new byte[8192];
- ModuleWriter.HashChunk(fs, cs, buf, (int)fs.Length);
- }
- }
- return manifestModule.__AddModule(flags, Path.GetFileName(fileName), hash.Hash);
+ fullPath = Path.Combine(dir, fileName);
+ }
+ byte[] hash;
+ using (SHA1 sha1 = SHA1.Create())
+ using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
+ {
+ hash = sha1.ComputeHash(fs);
}
+ return manifestModule.__AddModule(flags, Path.GetFileName(fileName), hash);
}
public void AddResourceFile(string name, string fileName)
@@ -505,7 +494,6 @@ public void AddResourceFile(string name, string fileName, ResourceAttributes att
resourceFiles.Add(resfile);
}
-#if !CORECLR
public IResourceWriter DefineResource(string name, string description, string fileName)
{
return DefineResource(name, description, fileName, ResourceAttributes.Public);
@@ -529,7 +517,6 @@ public IResourceWriter DefineResource(string name, string description, string fi
resourceFiles.Add(resfile);
return rw;
}
-#endif
public void DefineVersionInfoResource()
{
diff --git a/src/compiler/backend/ikvm/Emit/ConstructorBuilder.cs b/src/compiler/backend/ikvm/Emit/ConstructorBuilder.cs
index d54041f1f..2c9541bed 100644
--- a/src/compiler/backend/ikvm/Emit/ConstructorBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/ConstructorBuilder.cs
@@ -77,12 +77,13 @@ public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
methodBuilder.__AddDeclarativeSecurity(customBuilder);
}
-#if !CORECLR
- public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
+#if NET6_0_OR_GREATER
+ [Obsolete]
+#endif
+ public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
methodBuilder.AddDeclarativeSecurity(securityAction, permissionSet);
}
-#endif
public void SetImplementationFlags(MethodImplAttributes attributes)
{
diff --git a/src/compiler/backend/ikvm/Emit/CustomAttributeBuilder.cs b/src/compiler/backend/ikvm/Emit/CustomAttributeBuilder.cs
index 938752487..a76ac6326 100644
--- a/src/compiler/backend/ikvm/Emit/CustomAttributeBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/CustomAttributeBuilder.cs
@@ -318,7 +318,7 @@ private void WriteTypeName(Type type)
private void GetTypeName(StringBuilder sb, Type type, bool isTypeParam)
{
bool v1 = !assembly.ManifestModule.__IsMissing && assembly.ManifestModule.MDStreamVersion < 0x20000;
- bool includeAssemblyName = type.Assembly != assembly && (!v1 || type.Assembly != type.Module.universe.Mscorlib);
+ bool includeAssemblyName = type.Assembly != assembly && (!v1 || type.Assembly != type.Module.universe.CoreLib);
if (isTypeParam && includeAssemblyName)
{
sb.Append('[');
@@ -501,7 +501,7 @@ internal int ConstructorArgumentCount
}
else if (val != null)
{
- if (typeof(T).IsEnum)
+ if (TypeUtil.IsEnum(typeof(T)))
{
Debug.Assert(Enum.GetUnderlyingType(typeof(T)) == val.GetType());
return (T)Enum.ToObject(typeof(T), val);
@@ -673,7 +673,13 @@ internal KnownCA KnownCA
{
get
{
- TypeName typeName = con.DeclaringType.TypeName;
+ Type attributeType = con.DeclaringType;
+ if (attributeType.IsConstructedGenericType)
+ {
+ // a constructed generic type doesn't have a TypeName and we already know it's not a Known CA
+ return KnownCA.Unknown;
+ }
+ TypeName typeName = attributeType.TypeName;
switch (typeName.Namespace)
{
case "System":
diff --git a/src/compiler/backend/ikvm/Emit/EnumBuilder.cs b/src/compiler/backend/ikvm/Emit/EnumBuilder.cs
index d396ae2bc..9854d750b 100644
--- a/src/compiler/backend/ikvm/Emit/EnumBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/EnumBuilder.cs
@@ -111,6 +111,11 @@ public override Type GetEnumUnderlyingType()
return fieldBuilder.FieldType;
}
+ protected override bool IsValueTypeImpl
+ {
+ get { return true; }
+ }
+
internal override bool IsBaked
{
get { return typeBuilder.IsBaked; }
diff --git a/src/compiler/backend/ikvm/Emit/ExceptionHandler.cs b/src/compiler/backend/ikvm/Emit/ExceptionHandler.cs
index 013f92591..af1502d8e 100644
--- a/src/compiler/backend/ikvm/Emit/ExceptionHandler.cs
+++ b/src/compiler/backend/ikvm/Emit/ExceptionHandler.cs
@@ -28,6 +28,7 @@ namespace IKVM.Reflection.Emit
{
public struct ExceptionHandler : IEquatable
{
+
private readonly int tryOffset;
private readonly int tryLength;
private readonly int filterOffset;
diff --git a/src/compiler/backend/ikvm/Emit/ILGenerator.cs b/src/compiler/backend/ikvm/Emit/ILGenerator.cs
index 885e64973..3028615d2 100644
--- a/src/compiler/backend/ikvm/Emit/ILGenerator.cs
+++ b/src/compiler/backend/ikvm/Emit/ILGenerator.cs
@@ -22,17 +22,16 @@ Jeroen Frijters
*/
using System;
-using System.Runtime.InteropServices;
using System.Collections.Generic;
-#if !NO_SYMBOL_WRITER
-using System.Diagnostics.SymbolStore;
-#endif
using System.Diagnostics;
+using System.Diagnostics.SymbolStore;
+using System.Runtime.InteropServices;
+
using IKVM.Reflection.Writer;
namespace IKVM.Reflection.Emit
{
- public struct Label
+ public struct Label
{
// 1-based here, to make sure that an uninitialized Label isn't valid
private readonly int index1;
@@ -104,6 +103,7 @@ public void SetLocalSymInfo(string name, int startOffset, int endOffset)
public sealed class ILGenerator
{
+
private readonly ModuleBuilder moduleBuilder;
private readonly ByteBuffer code;
private readonly SignatureHelper locals;
@@ -112,9 +112,7 @@ public sealed class ILGenerator
private readonly List labels = new List();
private readonly List labelStackHeight = new List();
private readonly List labelFixups = new List();
-#if !NO_SYMBOL_WRITER
private readonly List sequencePoints = new List();
-#endif
private readonly List exceptions = new List();
private readonly Stack exceptionStack = new Stack();
private ushort maxStack;
@@ -187,14 +185,12 @@ int IComparer.Compare(ExceptionBlock x, ExceptionBlock y)
private struct SequencePoint
{
-#if !NO_SYMBOL_WRITER
internal ISymbolDocumentWriter document;
internal int offset;
internal int startLine;
internal int startColumn;
internal int endLine;
internal int endColumn;
-#endif
}
private sealed class Scope
@@ -202,6 +198,7 @@ private sealed class Scope
internal readonly Scope parent;
internal readonly List children = new List();
internal readonly List locals = new List();
+ internal readonly List namespaces = new List();
internal int startOffset;
internal int endOffset;
@@ -408,12 +405,10 @@ public void BeginScope()
public void UsingNamespace(string usingNamespace)
{
-#if !NO_SYMBOL_WRITER
- if (moduleBuilder.symbolWriter != null)
+ if (scope != null)
{
- moduleBuilder.symbolWriter.UsingNamespace(usingNamespace);
+ scope.namespaces.Add(usingNamespace);
}
-#endif
}
public LocalBuilder DeclareLocal(Type localType)
@@ -831,13 +826,13 @@ public void EmitWriteLine(string text)
{
Universe u = moduleBuilder.universe;
Emit(OpCodes.Ldstr, text);
- Emit(OpCodes.Call, u.Import(typeof(Console)).GetMethod("WriteLine", new Type[] { u.System_String }));
+ Emit(OpCodes.Call, u.System_Console.GetMethod("WriteLine", new Type[] { u.System_String }));
}
public void EmitWriteLine(FieldInfo field)
{
Universe u = moduleBuilder.universe;
- Emit(OpCodes.Call, u.Import(typeof(Console)).GetMethod("get_Out"));
+ Emit(OpCodes.Call, u.System_Console.GetMethod("get_Out"));
if (field.IsStatic)
{
Emit(OpCodes.Ldsfld, field);
@@ -847,15 +842,15 @@ public void EmitWriteLine(FieldInfo field)
Emit(OpCodes.Ldarg_0);
Emit(OpCodes.Ldfld, field);
}
- Emit(OpCodes.Callvirt, u.Import(typeof(System.IO.TextWriter)).GetMethod("WriteLine", new Type[] { field.FieldType }));
+ Emit(OpCodes.Callvirt, u.System_IO_TextWriter.GetMethod("WriteLine", new Type[] { field.FieldType }));
}
public void EmitWriteLine(LocalBuilder local)
{
Universe u = moduleBuilder.universe;
- Emit(OpCodes.Call, u.Import(typeof(Console)).GetMethod("get_Out"));
+ Emit(OpCodes.Call, u.System_Console.GetMethod("get_Out"));
Emit(OpCodes.Ldloc, local);
- Emit(OpCodes.Callvirt, u.Import(typeof(System.IO.TextWriter)).GetMethod("WriteLine", new Type[] { local.LocalType }));
+ Emit(OpCodes.Callvirt, u.System_IO_TextWriter.GetMethod("WriteLine", new Type[] { local.LocalType }));
}
public void EndScope()
@@ -890,7 +885,6 @@ public void MarkLabel(Label loc)
}
}
-#if !NO_SYMBOL_WRITER
public void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn)
{
SequencePoint sp = new SequencePoint();
@@ -902,7 +896,6 @@ public void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int
sp.endColumn = endColumn;
sequencePoints.Add(sp);
}
-#endif
public void ThrowException(Type excType)
{
@@ -938,7 +931,6 @@ internal int WriteBody(bool initLocals)
rva = WriteFatHeaderAndCode(bb, localVarSigTok, initLocals);
}
-#if !NO_SYMBOL_WRITER
if (moduleBuilder.symbolWriter != null)
{
if (sequencePoints.Count != 0)
@@ -966,7 +958,6 @@ internal int WriteBody(bool initLocals)
WriteScope(scope, localVarSigTok);
}
-#endif
return rva;
}
@@ -1123,7 +1114,6 @@ internal static void AddTokenFixups(int codeOffset, List tokenFixupOffsets,
}
}
-#if !NO_SYMBOL_WRITER
private void WriteScope(Scope scope, int localVarSigTok)
{
moduleBuilder.symbolWriter.OpenScope(scope.startOffset);
@@ -1141,12 +1131,15 @@ private void WriteScope(Scope scope, int localVarSigTok)
moduleBuilder.symbolWriter.DefineLocalVariable2(local.name, 0, localVarSigTok, SymAddressKind.ILOffset, local.LocalIndex, 0, 0, startOffset, endOffset);
}
}
+ foreach (string ns in scope.namespaces)
+ {
+ moduleBuilder.symbolWriter.UsingNamespace(ns);
+ }
foreach (Scope child in scope.children)
{
WriteScope(child, localVarSigTok);
}
moduleBuilder.symbolWriter.CloseScope(scope.endOffset);
}
-#endif
}
}
diff --git a/src/compiler/backend/ikvm/Emit/MethodBuilder.cs b/src/compiler/backend/ikvm/Emit/MethodBuilder.cs
index a7f724d88..069bc7ecb 100644
--- a/src/compiler/backend/ikvm/Emit/MethodBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/MethodBuilder.cs
@@ -22,761 +22,755 @@ Jeroen Frijters
*/
using System;
-using System.IO;
-using System.Diagnostics;
using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
-#endif
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
using IKVM.Reflection.Metadata;
using IKVM.Reflection.Writer;
namespace IKVM.Reflection.Emit
{
- public sealed class MethodBuilder : MethodInfo
- {
- private readonly TypeBuilder typeBuilder;
- private readonly string name;
- private readonly int pseudoToken;
- private int nameIndex;
- private int signature;
- private Type returnType;
- private Type[] parameterTypes;
- private PackedCustomModifiers customModifiers;
- private MethodAttributes attributes;
- private MethodImplAttributes implFlags;
- private ILGenerator ilgen;
- private int rva = -1;
- private CallingConventions callingConvention;
- private List parameters;
- private GenericTypeParameterBuilder[] gtpb;
- private List declarativeSecurity;
- private MethodSignature methodSignature;
- private bool initLocals = true;
-
- internal MethodBuilder(TypeBuilder typeBuilder, string name, MethodAttributes attributes, CallingConventions callingConvention)
- {
- this.typeBuilder = typeBuilder;
- this.name = name;
- this.pseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
- this.attributes = attributes;
- if ((attributes & MethodAttributes.Static) == 0)
- {
- callingConvention |= CallingConventions.HasThis;
- }
- this.callingConvention = callingConvention;
- }
-
- public ILGenerator GetILGenerator()
- {
- return GetILGenerator(16);
- }
-
- public ILGenerator GetILGenerator(int streamSize)
- {
- if (rva != -1)
- {
- throw new InvalidOperationException();
- }
- if (ilgen == null)
- {
- ilgen = new ILGenerator(typeBuilder.ModuleBuilder, streamSize);
- }
- return ilgen;
- }
-
- public void __ReleaseILGenerator()
- {
- if (ilgen != null)
- {
-#if !NO_SYMBOL_WRITER
- if (this.ModuleBuilder.symbolWriter != null)
- {
- this.ModuleBuilder.symbolWriter.OpenMethod(new SymbolToken(-pseudoToken | 0x06000000), this);
- }
-#endif
- rva = ilgen.WriteBody(initLocals);
-#if !NO_SYMBOL_WRITER
- if (this.ModuleBuilder.symbolWriter != null)
- {
- this.ModuleBuilder.symbolWriter.CloseMethod();
- }
+ public sealed class MethodBuilder : MethodInfo
+ {
+ private readonly TypeBuilder typeBuilder;
+ private readonly string name;
+ private readonly int pseudoToken;
+ private int nameIndex;
+ private int signature;
+ private Type returnType;
+ private Type[] parameterTypes;
+ private PackedCustomModifiers customModifiers;
+ private MethodAttributes attributes;
+ private MethodImplAttributes implFlags;
+ private ILGenerator ilgen;
+ private int rva = -1;
+ private CallingConventions callingConvention;
+ private List parameters;
+ private GenericTypeParameterBuilder[] gtpb;
+ private List declarativeSecurity;
+ private MethodSignature methodSignature;
+ private bool initLocals = true;
+
+ internal MethodBuilder(TypeBuilder typeBuilder, string name, MethodAttributes attributes, CallingConventions callingConvention)
+ {
+ this.typeBuilder = typeBuilder;
+ this.name = name;
+ this.pseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
+ this.attributes = attributes;
+ if ((attributes & MethodAttributes.Static) == 0)
+ {
+ callingConvention |= CallingConventions.HasThis;
+ }
+ this.callingConvention = callingConvention;
+ }
+
+ public ILGenerator GetILGenerator()
+ {
+ return GetILGenerator(16);
+ }
+
+ public ILGenerator GetILGenerator(int streamSize)
+ {
+ if (rva != -1)
+ {
+ throw new InvalidOperationException();
+ }
+ if (ilgen == null)
+ {
+ ilgen = new ILGenerator(typeBuilder.ModuleBuilder, streamSize);
+ }
+ return ilgen;
+ }
+
+ public void __ReleaseILGenerator()
+ {
+ if (ilgen != null)
+ {
+ if (this.ModuleBuilder.symbolWriter != null)
+ {
+ this.ModuleBuilder.symbolWriter.OpenMethod(new SymbolToken(-pseudoToken | 0x06000000), this);
+ }
+ rva = ilgen.WriteBody(initLocals);
+ if (this.ModuleBuilder.symbolWriter != null)
+ {
+ this.ModuleBuilder.symbolWriter.CloseMethod();
+ }
+ ilgen = null;
+ }
+ }
+
+ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
+ {
+ SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
+ }
+
+ private void SetDllImportPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
+ {
+ CallingConvention? callingConvention = customBuilder.GetFieldValue("CallingConvention");
+ CharSet? charSet = customBuilder.GetFieldValue("CharSet");
+ SetDllImportPseudoCustomAttribute((string)customBuilder.GetConstructorArgument(0),
+ (string)customBuilder.GetFieldValue("EntryPoint"),
+ callingConvention,
+ charSet,
+ (bool?)customBuilder.GetFieldValue("BestFitMapping"),
+ (bool?)customBuilder.GetFieldValue("ThrowOnUnmappableChar"),
+ (bool?)customBuilder.GetFieldValue("SetLastError"),
+ (bool?)customBuilder.GetFieldValue("PreserveSig"),
+ (bool?)customBuilder.GetFieldValue("ExactSpelling"));
+ }
+
+ internal void SetDllImportPseudoCustomAttribute(string dllName, string entryName, CallingConvention? nativeCallConv, CharSet? nativeCharSet,
+ bool? bestFitMapping, bool? throwOnUnmappableChar, bool? setLastError, bool? preserveSig, bool? exactSpelling)
+ {
+ const short NoMangle = 0x0001;
+ const short CharSetMask = 0x0006;
+ const short CharSetNotSpec = 0x0000;
+ const short CharSetAnsi = 0x0002;
+ const short CharSetUnicode = 0x0004;
+ const short CharSetAuto = 0x0006;
+ const short SupportsLastError = 0x0040;
+ const short CallConvMask = 0x0700;
+ const short CallConvWinapi = 0x0100;
+ const short CallConvCdecl = 0x0200;
+ const short CallConvStdcall = 0x0300;
+ const short CallConvThiscall = 0x0400;
+ const short CallConvFastcall = 0x0500;
+ // non-standard flags
+ const short BestFitOn = 0x0010;
+ const short BestFitOff = 0x0020;
+ const short CharMapErrorOn = 0x1000;
+ const short CharMapErrorOff = 0x2000;
+ short flags = CharSetNotSpec | CallConvWinapi;
+ if (bestFitMapping.HasValue)
+ {
+ flags |= bestFitMapping.Value ? BestFitOn : BestFitOff;
+ }
+ if (throwOnUnmappableChar.HasValue)
+ {
+ flags |= throwOnUnmappableChar.Value ? CharMapErrorOn : CharMapErrorOff;
+ }
+ if (nativeCallConv.HasValue)
+ {
+ flags &= ~CallConvMask;
+ switch (nativeCallConv.Value)
+ {
+ case System.Runtime.InteropServices.CallingConvention.Cdecl:
+ flags |= CallConvCdecl;
+ break;
+ case System.Runtime.InteropServices.CallingConvention.FastCall:
+ flags |= CallConvFastcall;
+ break;
+ case System.Runtime.InteropServices.CallingConvention.StdCall:
+ flags |= CallConvStdcall;
+ break;
+ case System.Runtime.InteropServices.CallingConvention.ThisCall:
+ flags |= CallConvThiscall;
+ break;
+ case System.Runtime.InteropServices.CallingConvention.Winapi:
+ flags |= CallConvWinapi;
+ break;
+ }
+ }
+ if (nativeCharSet.HasValue)
+ {
+ flags &= ~CharSetMask;
+ switch (nativeCharSet.Value)
+ {
+ case CharSet.Ansi:
+ case CharSet.None:
+ flags |= CharSetAnsi;
+ break;
+ case CharSet.Auto:
+ flags |= CharSetAuto;
+ break;
+ case CharSet.Unicode:
+ flags |= CharSetUnicode;
+ break;
+ }
+ }
+ if (exactSpelling.HasValue && exactSpelling.Value)
+ {
+ flags |= NoMangle;
+ }
+ if (!preserveSig.HasValue || preserveSig.Value)
+ {
+ implFlags |= MethodImplAttributes.PreserveSig;
+ }
+ if (setLastError.HasValue && setLastError.Value)
+ {
+ flags |= SupportsLastError;
+ }
+ ImplMapTable.Record rec = new ImplMapTable.Record();
+ rec.MappingFlags = flags;
+ rec.MemberForwarded = pseudoToken;
+ rec.ImportName = this.ModuleBuilder.Strings.Add(entryName ?? name);
+ rec.ImportScope = this.ModuleBuilder.ModuleRef.FindOrAddRecord(dllName == null ? 0 : this.ModuleBuilder.Strings.Add(dllName));
+ this.ModuleBuilder.ImplMap.AddRecord(rec);
+ }
+
+ private void SetMethodImplAttribute(CustomAttributeBuilder customBuilder)
+ {
+ MethodImplOptions opt;
+ switch (customBuilder.Constructor.ParameterCount)
+ {
+ case 0:
+ opt = 0;
+ break;
+ case 1:
+ {
+ object val = customBuilder.GetConstructorArgument(0);
+ if (val is short)
+ {
+ opt = (MethodImplOptions)(short)val;
+ }
+ else if (val is int)
+ {
+ opt = (MethodImplOptions)(int)val;
+ }
+ else
+ {
+ opt = (MethodImplOptions)val;
+ }
+ break;
+ }
+ default:
+ throw new NotSupportedException();
+ }
+ implFlags = (MethodImplAttributes)opt;
+ MethodCodeType? type = customBuilder.GetFieldValue("MethodCodeType");
+ if (type.HasValue)
+ {
+ implFlags |= (MethodImplAttributes)type;
+ }
+ }
+
+ public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
+ {
+ switch (customBuilder.KnownCA)
+ {
+ case KnownCA.DllImportAttribute:
+ SetDllImportPseudoCustomAttribute(customBuilder.DecodeBlob(this.Module.Assembly));
+ attributes |= MethodAttributes.PinvokeImpl;
+ break;
+ case KnownCA.MethodImplAttribute:
+ SetMethodImplAttribute(customBuilder.DecodeBlob(this.Module.Assembly));
+ break;
+ case KnownCA.PreserveSigAttribute:
+ implFlags |= MethodImplAttributes.PreserveSig;
+ break;
+ case KnownCA.SpecialNameAttribute:
+ attributes |= MethodAttributes.SpecialName;
+ break;
+ case KnownCA.SuppressUnmanagedCodeSecurityAttribute:
+ attributes |= MethodAttributes.HasSecurity;
+ goto default;
+ default:
+ this.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder);
+ break;
+ }
+ }
+
+ public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
+ {
+ attributes |= MethodAttributes.HasSecurity;
+ if (declarativeSecurity == null)
+ {
+ declarativeSecurity = new List();
+ }
+ declarativeSecurity.Add(customBuilder);
+ }
+
+#if NET6_0_OR_GREATER
+ [Obsolete]
#endif
- ilgen = null;
- }
- }
-
- public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
- {
- SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
- }
-
- private void SetDllImportPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
- {
- CallingConvention? callingConvention = customBuilder.GetFieldValue("CallingConvention");
- CharSet? charSet = customBuilder.GetFieldValue("CharSet");
- SetDllImportPseudoCustomAttribute((string)customBuilder.GetConstructorArgument(0),
- (string)customBuilder.GetFieldValue("EntryPoint"),
- callingConvention,
- charSet,
- (bool?)customBuilder.GetFieldValue("BestFitMapping"),
- (bool?)customBuilder.GetFieldValue("ThrowOnUnmappableChar"),
- (bool?)customBuilder.GetFieldValue("SetLastError"),
- (bool?)customBuilder.GetFieldValue("PreserveSig"),
- (bool?)customBuilder.GetFieldValue("ExactSpelling"));
- }
-
- internal void SetDllImportPseudoCustomAttribute(string dllName, string entryName, CallingConvention? nativeCallConv, CharSet? nativeCharSet,
- bool? bestFitMapping, bool? throwOnUnmappableChar, bool? setLastError, bool? preserveSig, bool? exactSpelling)
- {
- const short NoMangle = 0x0001;
- const short CharSetMask = 0x0006;
- const short CharSetNotSpec = 0x0000;
- const short CharSetAnsi = 0x0002;
- const short CharSetUnicode = 0x0004;
- const short CharSetAuto = 0x0006;
- const short SupportsLastError = 0x0040;
- const short CallConvMask = 0x0700;
- const short CallConvWinapi = 0x0100;
- const short CallConvCdecl = 0x0200;
- const short CallConvStdcall = 0x0300;
- const short CallConvThiscall = 0x0400;
- const short CallConvFastcall = 0x0500;
- // non-standard flags
- const short BestFitOn = 0x0010;
- const short BestFitOff = 0x0020;
- const short CharMapErrorOn = 0x1000;
- const short CharMapErrorOff = 0x2000;
- short flags = CharSetNotSpec | CallConvWinapi;
- if (bestFitMapping.HasValue)
- {
- flags |= bestFitMapping.Value ? BestFitOn : BestFitOff;
- }
- if (throwOnUnmappableChar.HasValue)
- {
- flags |= throwOnUnmappableChar.Value ? CharMapErrorOn : CharMapErrorOff;
- }
- if (nativeCallConv.HasValue)
- {
- flags &= ~CallConvMask;
- switch (nativeCallConv.Value)
- {
- case System.Runtime.InteropServices.CallingConvention.Cdecl:
- flags |= CallConvCdecl;
- break;
- case System.Runtime.InteropServices.CallingConvention.FastCall:
- flags |= CallConvFastcall;
- break;
- case System.Runtime.InteropServices.CallingConvention.StdCall:
- flags |= CallConvStdcall;
- break;
- case System.Runtime.InteropServices.CallingConvention.ThisCall:
- flags |= CallConvThiscall;
- break;
- case System.Runtime.InteropServices.CallingConvention.Winapi:
- flags |= CallConvWinapi;
- break;
- }
- }
- if (nativeCharSet.HasValue)
- {
- flags &= ~CharSetMask;
- switch (nativeCharSet.Value)
- {
- case CharSet.Ansi:
- case CharSet.None:
- flags |= CharSetAnsi;
- break;
- case CharSet.Auto:
- flags |= CharSetAuto;
- break;
- case CharSet.Unicode:
- flags |= CharSetUnicode;
- break;
- }
- }
- if (exactSpelling.HasValue && exactSpelling.Value)
- {
- flags |= NoMangle;
- }
- if (!preserveSig.HasValue || preserveSig.Value)
- {
- implFlags |= MethodImplAttributes.PreserveSig;
- }
- if (setLastError.HasValue && setLastError.Value)
- {
- flags |= SupportsLastError;
- }
- ImplMapTable.Record rec = new ImplMapTable.Record();
- rec.MappingFlags = flags;
- rec.MemberForwarded = pseudoToken;
- rec.ImportName = this.ModuleBuilder.Strings.Add(entryName ?? name);
- rec.ImportScope = this.ModuleBuilder.ModuleRef.FindOrAddRecord(dllName == null ? 0 : this.ModuleBuilder.Strings.Add(dllName));
- this.ModuleBuilder.ImplMap.AddRecord(rec);
- }
-
- private void SetMethodImplAttribute(CustomAttributeBuilder customBuilder)
- {
- MethodImplOptions opt;
- switch (customBuilder.Constructor.ParameterCount)
- {
- case 0:
- opt = 0;
- break;
- case 1:
- {
- object val = customBuilder.GetConstructorArgument(0);
- if (val is short)
- {
- opt = (MethodImplOptions)(short)val;
- }
- else if (val is int)
- {
- opt = (MethodImplOptions)(int)val;
- }
- else
- {
- opt = (MethodImplOptions)val;
- }
- break;
- }
- default:
- throw new NotSupportedException();
- }
- MethodCodeType? type = customBuilder.GetFieldValue("MethodCodeType");
- implFlags = (MethodImplAttributes)opt;
- if (type.HasValue)
- {
- implFlags |= (MethodImplAttributes)type;
- }
- }
-
- public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
- {
- switch (customBuilder.KnownCA)
- {
- case KnownCA.DllImportAttribute:
- SetDllImportPseudoCustomAttribute(customBuilder.DecodeBlob(this.Module.Assembly));
- attributes |= MethodAttributes.PinvokeImpl;
- break;
- case KnownCA.MethodImplAttribute:
- SetMethodImplAttribute(customBuilder.DecodeBlob(this.Module.Assembly));
- break;
- case KnownCA.PreserveSigAttribute:
- implFlags |= MethodImplAttributes.PreserveSig;
- break;
- case KnownCA.SpecialNameAttribute:
- attributes |= MethodAttributes.SpecialName;
- break;
- case KnownCA.SuppressUnmanagedCodeSecurityAttribute:
- attributes |= MethodAttributes.HasSecurity;
- goto default;
- default:
- this.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder);
- break;
- }
- }
-
- public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
- {
- attributes |= MethodAttributes.HasSecurity;
- if (declarativeSecurity == null)
- {
- declarativeSecurity = new List();
- }
- declarativeSecurity.Add(customBuilder);
- }
-
-#if !CORECLR
- public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
- {
- this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, securityAction, permissionSet);
- this.attributes |= MethodAttributes.HasSecurity;
- }
-#endif
-
- public void SetImplementationFlags(MethodImplAttributes attributes)
- {
- implFlags = attributes;
- }
-
- public ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, string strParamName)
- {
- if (parameters == null)
- {
- parameters = new List();
- }
- this.ModuleBuilder.Param.AddVirtualRecord();
- ParameterBuilder pb = new ParameterBuilder(this.ModuleBuilder, position, attributes, strParamName);
- if (parameters.Count == 0 || position >= parameters[parameters.Count - 1].Position)
- {
- parameters.Add(pb);
- }
- else
- {
- for (int i = 0; i < parameters.Count; i++)
- {
- if (parameters[i].Position > position)
- {
- parameters.Insert(i, pb);
- break;
- }
- }
- }
- return pb;
- }
-
- private void CheckSig()
- {
- if (methodSignature != null)
- {
- throw new InvalidOperationException("The method signature can not be modified after it has been used.");
- }
- }
-
- public void SetParameters(params Type[] parameterTypes)
- {
- CheckSig();
- this.parameterTypes = Util.Copy(parameterTypes);
- }
-
- public void SetReturnType(Type returnType)
- {
- CheckSig();
- this.returnType = returnType ?? this.Module.universe.System_Void;
- }
-
- public void SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
- {
- SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
- parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
- }
-
- public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
- {
- SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
- }
-
- private void SetSignature(Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
- {
- CheckSig();
- this.returnType = returnType ?? this.Module.universe.System_Void;
- this.parameterTypes = Util.Copy(parameterTypes);
- this.customModifiers = customModifiers;
- }
-
- public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
- {
- CheckSig();
- if (gtpb != null)
- {
- throw new InvalidOperationException("Generic parameters already defined.");
- }
- gtpb = new GenericTypeParameterBuilder[names.Length];
- for (int i = 0; i < names.Length; i++)
- {
- gtpb[i] = new GenericTypeParameterBuilder(names[i], this, i);
- }
- return (GenericTypeParameterBuilder[])gtpb.Clone();
- }
-
- public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
- {
- return new GenericMethodInstance(typeBuilder, this, typeArguments);
- }
-
- public override MethodInfo GetGenericMethodDefinition()
- {
- if (gtpb == null)
- {
- throw new InvalidOperationException();
- }
- return this;
- }
-
- public override Type[] GetGenericArguments()
- {
- return Util.Copy(gtpb);
- }
-
- internal override Type GetGenericMethodArgument(int index)
- {
- return gtpb[index];
- }
-
- internal override int GetGenericMethodArgumentCount()
- {
- return gtpb == null ? 0 : gtpb.Length;
- }
-
- public override Type ReturnType
- {
- get { return returnType; }
- }
-
- public override ParameterInfo ReturnParameter
- {
- get { return new ParameterInfoImpl(this, -1); }
- }
-
- public override MethodAttributes Attributes
- {
- get { return attributes; }
- }
-
- public void __SetAttributes(MethodAttributes attributes)
- {
- this.attributes = attributes;
- }
-
- public void __SetCallingConvention(CallingConventions callingConvention)
- {
- this.callingConvention = callingConvention;
- this.methodSignature = null;
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags()
- {
- return implFlags;
- }
-
- private sealed class ParameterInfoImpl : ParameterInfo
- {
- private readonly MethodBuilder method;
- private readonly int parameter;
-
- internal ParameterInfoImpl(MethodBuilder method, int parameter)
- {
- this.method = method;
- this.parameter = parameter;
- }
-
- private ParameterBuilder ParameterBuilder
- {
- get
- {
- if (method.parameters != null)
- {
- foreach (ParameterBuilder pb in method.parameters)
- {
- // ParameterBuilder.Position is 1-based
- if (pb.Position - 1 == parameter)
- {
- return pb;
- }
- }
- }
- return null;
- }
- }
-
- public override string Name
- {
- get
- {
- ParameterBuilder pb = this.ParameterBuilder;
- return pb != null ? pb.Name : null;
- }
- }
-
- public override Type ParameterType
- {
- get { return parameter == -1 ? method.returnType : method.parameterTypes[parameter]; }
- }
-
- public override ParameterAttributes Attributes
- {
- get
- {
- ParameterBuilder pb = this.ParameterBuilder;
- return pb != null ? (ParameterAttributes)pb.Attributes : ParameterAttributes.None;
- }
- }
-
- public override int Position
- {
- get { return parameter; }
- }
-
- public override object RawDefaultValue
- {
- get
- {
- ParameterBuilder pb = this.ParameterBuilder;
- if (pb != null && (pb.Attributes & (int)ParameterAttributes.HasDefault) != 0)
- {
- return method.ModuleBuilder.Constant.GetRawConstantValue(method.ModuleBuilder, pb.PseudoToken);
- }
- if (pb != null && (pb.Attributes & (int)ParameterAttributes.Optional) != 0)
- {
- return Missing.Value;
- }
- return null;
- }
- }
-
- public override CustomModifiers __GetCustomModifiers()
- {
- return method.customModifiers.GetParameterCustomModifiers(parameter);
- }
-
- public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
- {
- fieldMarshal = new FieldMarshal();
- return false;
- }
-
- public override MemberInfo Member
- {
- get { return method; }
- }
-
- public override int MetadataToken
- {
- get
- {
- ParameterBuilder pb = this.ParameterBuilder;
- return pb != null ? pb.PseudoToken : 0x08000000;
- }
- }
-
- internal override Module Module
- {
- get { return method.Module; }
- }
- }
-
- public override ParameterInfo[] GetParameters()
- {
- ParameterInfo[] parameters = new ParameterInfo[parameterTypes.Length];
- for (int i = 0; i < parameters.Length; i++)
- {
- parameters[i] = new ParameterInfoImpl(this, i);
- }
- return parameters;
- }
-
- internal override int ParameterCount
- {
- get { return parameterTypes.Length; }
- }
-
- public override Type DeclaringType
- {
- get { return typeBuilder.IsModulePseudoType ? null : typeBuilder; }
- }
-
- public override string Name
- {
- get { return name; }
- }
-
- public override CallingConventions CallingConvention
- {
- get { return callingConvention; }
- }
-
- public override int MetadataToken
- {
- get { return pseudoToken; }
- }
-
- public override bool IsGenericMethod
- {
- get { return gtpb != null; }
- }
-
- public override bool IsGenericMethodDefinition
- {
- get { return gtpb != null; }
- }
-
- public override Module Module
- {
- get { return typeBuilder.Module; }
- }
-
- public Module GetModule()
- {
- return typeBuilder.Module;
- }
-
- public MethodToken GetToken()
- {
- return new MethodToken(pseudoToken);
- }
-
- public override MethodBody GetMethodBody()
- {
- throw new NotSupportedException();
- }
-
- public override int __MethodRVA
- {
- get { throw new NotImplementedException(); }
- }
-
- public bool InitLocals
- {
- get { return initLocals; }
- set { initLocals = value; }
- }
-
- public void __AddUnmanagedExport(string name, int ordinal)
- {
- this.ModuleBuilder.AddUnmanagedExport(name, ordinal, this, new RelativeVirtualAddress(0xFFFFFFFF));
- }
-
- public void CreateMethodBody(byte[] il, int count)
- {
- if (il == null)
- {
- throw new NotSupportedException();
- }
- if (il.Length != count)
- {
- Array.Resize(ref il, count);
- }
- SetMethodBody(il, 16, null, null, null);
- }
-
- public void SetMethodBody(byte[] il, int maxStack, byte[] localSignature, IEnumerable exceptionHandlers, IEnumerable tokenFixups)
- {
- ByteBuffer bb = this.ModuleBuilder.methodBodies;
-
- if (localSignature == null && exceptionHandlers == null && maxStack <= 8 && il.Length < 64)
- {
- rva = bb.Position;
- ILGenerator.WriteTinyHeader(bb, il.Length);
- }
- else
- {
- // fat headers require 4-byte alignment
- bb.Align(4);
- rva = bb.Position;
- ILGenerator.WriteFatHeader(bb, initLocals, exceptionHandlers != null, (ushort)maxStack, il.Length,
- localSignature == null ? 0 : this.ModuleBuilder.GetSignatureToken(localSignature, localSignature.Length).Token);
- }
-
- if (tokenFixups != null)
- {
- ILGenerator.AddTokenFixups(bb.Position, this.ModuleBuilder.tokenFixupOffsets, tokenFixups);
- }
- bb.Write(il);
-
- if (exceptionHandlers != null)
- {
- List exceptions = new List();
- foreach (ExceptionHandler block in exceptionHandlers)
- {
- exceptions.Add(new ILGenerator.ExceptionBlock(block));
- }
- ILGenerator.WriteExceptionHandlers(bb, exceptions);
- }
- }
-
- internal void Bake()
- {
- this.nameIndex = this.ModuleBuilder.Strings.Add(name);
- this.signature = this.ModuleBuilder.GetSignatureBlobIndex(this.MethodSignature);
-
- __ReleaseILGenerator();
-
- if (declarativeSecurity != null)
- {
- this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, declarativeSecurity);
- }
- }
-
- internal ModuleBuilder ModuleBuilder
- {
- get { return typeBuilder.ModuleBuilder; }
- }
-
- internal void WriteMethodDefRecord(int baseRVA, MetadataWriter mw, ref int paramList)
- {
- if (rva != -1)
- {
- mw.Write(rva + baseRVA);
- }
- else
- {
- mw.Write(0);
- }
- mw.Write((short)implFlags);
- mw.Write((short)attributes);
- mw.WriteStringIndex(nameIndex);
- mw.WriteBlobIndex(signature);
- mw.WriteParam(paramList);
- if (parameters != null)
- {
- paramList += parameters.Count;
- }
- }
-
- internal void WriteParamRecords(MetadataWriter mw)
- {
- if (parameters != null)
- {
- foreach (ParameterBuilder pb in parameters)
- {
- pb.WriteParamRecord(mw);
- }
- }
- }
-
- internal void FixupToken(int token, ref int parameterToken)
- {
- typeBuilder.ModuleBuilder.RegisterTokenFixup(this.pseudoToken, token);
- if (parameters != null)
- {
- foreach (ParameterBuilder pb in parameters)
- {
- pb.FixupToken(parameterToken++);
- }
- }
- }
-
- internal override MethodSignature MethodSignature
- {
- get
- {
- if (methodSignature == null)
- {
- methodSignature = MethodSignature.MakeFromBuilder(returnType ?? typeBuilder.Universe.System_Void, parameterTypes ?? Type.EmptyTypes,
- customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
- }
- return methodSignature;
- }
- }
-
- internal override int ImportTo(ModuleBuilder other)
- {
- return other.ImportMethodOrField(typeBuilder, name, this.MethodSignature);
- }
-
- internal void CheckBaked()
- {
- typeBuilder.CheckBaked();
- }
-
- internal override int GetCurrentToken()
- {
- if (typeBuilder.ModuleBuilder.IsSaved)
- {
- return typeBuilder.ModuleBuilder.ResolvePseudoToken(pseudoToken);
- }
- else
- {
- return pseudoToken;
- }
- }
-
- internal override bool IsBaked
- {
- get { return typeBuilder.IsBaked; }
- }
- }
+ public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
+ {
+ this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, securityAction, permissionSet);
+ this.attributes |= MethodAttributes.HasSecurity;
+ }
+
+ public void SetImplementationFlags(MethodImplAttributes attributes)
+ {
+ implFlags = attributes;
+ }
+
+ public ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, string strParamName)
+ {
+ if (parameters == null)
+ {
+ parameters = new List();
+ }
+ this.ModuleBuilder.Param.AddVirtualRecord();
+ ParameterBuilder pb = new ParameterBuilder(this.ModuleBuilder, position, attributes, strParamName);
+ if (parameters.Count == 0 || position >= parameters[parameters.Count - 1].Position)
+ {
+ parameters.Add(pb);
+ }
+ else
+ {
+ for (int i = 0; i < parameters.Count; i++)
+ {
+ if (parameters[i].Position > position)
+ {
+ parameters.Insert(i, pb);
+ break;
+ }
+ }
+ }
+ return pb;
+ }
+
+ private void CheckSig()
+ {
+ if (methodSignature != null)
+ {
+ throw new InvalidOperationException("The method signature can not be modified after it has been used.");
+ }
+ }
+
+ public void SetParameters(params Type[] parameterTypes)
+ {
+ CheckSig();
+ this.parameterTypes = Util.Copy(parameterTypes);
+ }
+
+ public void SetReturnType(Type returnType)
+ {
+ CheckSig();
+ this.returnType = returnType ?? this.Module.universe.System_Void;
+ }
+
+ public void SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
+ {
+ SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
+ parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
+ }
+
+ public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
+ {
+ SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
+ }
+
+ private void SetSignature(Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
+ {
+ CheckSig();
+ this.returnType = returnType ?? this.Module.universe.System_Void;
+ this.parameterTypes = Util.Copy(parameterTypes);
+ this.customModifiers = customModifiers;
+ }
+
+ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
+ {
+ CheckSig();
+ if (gtpb != null)
+ {
+ throw new InvalidOperationException("Generic parameters already defined.");
+ }
+ gtpb = new GenericTypeParameterBuilder[names.Length];
+ for (int i = 0; i < names.Length; i++)
+ {
+ gtpb[i] = new GenericTypeParameterBuilder(names[i], this, i);
+ }
+ return (GenericTypeParameterBuilder[])gtpb.Clone();
+ }
+
+ public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
+ {
+ return new GenericMethodInstance(typeBuilder, this, typeArguments);
+ }
+
+ public override MethodInfo GetGenericMethodDefinition()
+ {
+ if (gtpb == null)
+ {
+ throw new InvalidOperationException();
+ }
+ return this;
+ }
+
+ public override Type[] GetGenericArguments()
+ {
+ return Util.Copy(gtpb);
+ }
+
+ internal override Type GetGenericMethodArgument(int index)
+ {
+ return gtpb[index];
+ }
+
+ internal override int GetGenericMethodArgumentCount()
+ {
+ return gtpb == null ? 0 : gtpb.Length;
+ }
+
+ public override Type ReturnType
+ {
+ get { return returnType; }
+ }
+
+ public override ParameterInfo ReturnParameter
+ {
+ get { return new ParameterInfoImpl(this, -1); }
+ }
+
+ public override MethodAttributes Attributes
+ {
+ get { return attributes; }
+ }
+
+ public void __SetAttributes(MethodAttributes attributes)
+ {
+ this.attributes = attributes;
+ }
+
+ public void __SetCallingConvention(CallingConventions callingConvention)
+ {
+ this.callingConvention = callingConvention;
+ this.methodSignature = null;
+ }
+
+ public override MethodImplAttributes GetMethodImplementationFlags()
+ {
+ return implFlags;
+ }
+
+ private sealed class ParameterInfoImpl : ParameterInfo
+ {
+ private readonly MethodBuilder method;
+ private readonly int parameter;
+
+ internal ParameterInfoImpl(MethodBuilder method, int parameter)
+ {
+ this.method = method;
+ this.parameter = parameter;
+ }
+
+ private ParameterBuilder ParameterBuilder
+ {
+ get
+ {
+ if (method.parameters != null)
+ {
+ foreach (ParameterBuilder pb in method.parameters)
+ {
+ // ParameterBuilder.Position is 1-based
+ if (pb.Position - 1 == parameter)
+ {
+ return pb;
+ }
+ }
+ }
+ return null;
+ }
+ }
+
+ public override string Name
+ {
+ get
+ {
+ ParameterBuilder pb = this.ParameterBuilder;
+ return pb != null ? pb.Name : null;
+ }
+ }
+
+ public override Type ParameterType
+ {
+ get { return parameter == -1 ? method.returnType : method.parameterTypes[parameter]; }
+ }
+
+ public override ParameterAttributes Attributes
+ {
+ get
+ {
+ ParameterBuilder pb = this.ParameterBuilder;
+ return pb != null ? (ParameterAttributes)pb.Attributes : ParameterAttributes.None;
+ }
+ }
+
+ public override int Position
+ {
+ get { return parameter; }
+ }
+
+ public override object RawDefaultValue
+ {
+ get
+ {
+ ParameterBuilder pb = this.ParameterBuilder;
+ if (pb != null && (pb.Attributes & (int)ParameterAttributes.HasDefault) != 0)
+ {
+ return method.ModuleBuilder.Constant.GetRawConstantValue(method.ModuleBuilder, pb.PseudoToken);
+ }
+ if (pb != null && (pb.Attributes & (int)ParameterAttributes.Optional) != 0)
+ {
+ return Missing.Value;
+ }
+ return null;
+ }
+ }
+
+ public override CustomModifiers __GetCustomModifiers()
+ {
+ return method.customModifiers.GetParameterCustomModifiers(parameter);
+ }
+
+ public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
+ {
+ fieldMarshal = new FieldMarshal();
+ return false;
+ }
+
+ public override MemberInfo Member
+ {
+ get { return method; }
+ }
+
+ public override int MetadataToken
+ {
+ get
+ {
+ ParameterBuilder pb = this.ParameterBuilder;
+ return pb != null ? pb.PseudoToken : 0x08000000;
+ }
+ }
+
+ internal override Module Module
+ {
+ get { return method.Module; }
+ }
+ }
+
+ public override ParameterInfo[] GetParameters()
+ {
+ ParameterInfo[] parameters = new ParameterInfo[parameterTypes.Length];
+ for (int i = 0; i < parameters.Length; i++)
+ {
+ parameters[i] = new ParameterInfoImpl(this, i);
+ }
+ return parameters;
+ }
+
+ internal override int ParameterCount
+ {
+ get { return parameterTypes.Length; }
+ }
+
+ public override Type DeclaringType
+ {
+ get { return typeBuilder.IsModulePseudoType ? null : typeBuilder; }
+ }
+
+ public override string Name
+ {
+ get { return name; }
+ }
+
+ public override CallingConventions CallingConvention
+ {
+ get { return callingConvention; }
+ }
+
+ public override int MetadataToken
+ {
+ get { return pseudoToken; }
+ }
+
+ public override bool IsGenericMethod
+ {
+ get { return gtpb != null; }
+ }
+
+ public override bool IsGenericMethodDefinition
+ {
+ get { return gtpb != null; }
+ }
+
+ public override Module Module
+ {
+ get { return typeBuilder.Module; }
+ }
+
+ public Module GetModule()
+ {
+ return typeBuilder.Module;
+ }
+
+ public MethodToken GetToken()
+ {
+ return new MethodToken(pseudoToken);
+ }
+
+ public override MethodBody GetMethodBody()
+ {
+ throw new NotSupportedException();
+ }
+
+ public override int __MethodRVA
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public bool InitLocals
+ {
+ get { return initLocals; }
+ set { initLocals = value; }
+ }
+
+ public void __AddUnmanagedExport(string name, int ordinal)
+ {
+ this.ModuleBuilder.AddUnmanagedExport(name, ordinal, this, new RelativeVirtualAddress(0xFFFFFFFF));
+ }
+
+ public void CreateMethodBody(byte[] il, int count)
+ {
+ if (il == null)
+ {
+ throw new NotSupportedException();
+ }
+ if (il.Length != count)
+ {
+ Array.Resize(ref il, count);
+ }
+ SetMethodBody(il, 16, null, null, null);
+ }
+
+ public void SetMethodBody(byte[] il, int maxStack, byte[] localSignature, IEnumerable exceptionHandlers, IEnumerable tokenFixups)
+ {
+ ByteBuffer bb = this.ModuleBuilder.methodBodies;
+
+ if (localSignature == null && exceptionHandlers == null && maxStack <= 8 && il.Length < 64)
+ {
+ rva = bb.Position;
+ ILGenerator.WriteTinyHeader(bb, il.Length);
+ }
+ else
+ {
+ // fat headers require 4-byte alignment
+ bb.Align(4);
+ rva = bb.Position;
+ ILGenerator.WriteFatHeader(bb, initLocals, exceptionHandlers != null, (ushort)maxStack, il.Length,
+ localSignature == null ? 0 : this.ModuleBuilder.GetSignatureToken(localSignature, localSignature.Length).Token);
+ }
+
+ if (tokenFixups != null)
+ {
+ ILGenerator.AddTokenFixups(bb.Position, this.ModuleBuilder.tokenFixupOffsets, tokenFixups);
+ }
+ bb.Write(il);
+
+ if (exceptionHandlers != null)
+ {
+ List exceptions = new List();
+ foreach (ExceptionHandler block in exceptionHandlers)
+ {
+ exceptions.Add(new ILGenerator.ExceptionBlock(block));
+ }
+ ILGenerator.WriteExceptionHandlers(bb, exceptions);
+ }
+ }
+
+ internal void Bake()
+ {
+ this.nameIndex = this.ModuleBuilder.Strings.Add(name);
+ this.signature = this.ModuleBuilder.GetSignatureBlobIndex(this.MethodSignature);
+
+ __ReleaseILGenerator();
+
+ if (declarativeSecurity != null)
+ {
+ this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, declarativeSecurity);
+ }
+ }
+
+ internal ModuleBuilder ModuleBuilder
+ {
+ get { return typeBuilder.ModuleBuilder; }
+ }
+
+ internal void WriteMethodDefRecord(int baseRVA, MetadataWriter mw, ref int paramList)
+ {
+ if (rva != -1)
+ {
+ mw.Write(rva + baseRVA);
+ }
+ else
+ {
+ mw.Write(0);
+ }
+ mw.Write((short)implFlags);
+ mw.Write((short)attributes);
+ mw.WriteStringIndex(nameIndex);
+ mw.WriteBlobIndex(signature);
+ mw.WriteParam(paramList);
+ if (parameters != null)
+ {
+ paramList += parameters.Count;
+ }
+ }
+
+ internal void WriteParamRecords(MetadataWriter mw)
+ {
+ if (parameters != null)
+ {
+ foreach (ParameterBuilder pb in parameters)
+ {
+ pb.WriteParamRecord(mw);
+ }
+ }
+ }
+
+ internal void FixupToken(int token, ref int parameterToken)
+ {
+ typeBuilder.ModuleBuilder.RegisterTokenFixup(this.pseudoToken, token);
+ if (parameters != null)
+ {
+ foreach (ParameterBuilder pb in parameters)
+ {
+ pb.FixupToken(parameterToken++);
+ }
+ }
+ }
+
+ internal override MethodSignature MethodSignature
+ {
+ get
+ {
+ if (methodSignature == null)
+ {
+ methodSignature = MethodSignature.MakeFromBuilder(returnType ?? typeBuilder.Universe.System_Void, parameterTypes ?? Type.EmptyTypes,
+ customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
+ }
+ return methodSignature;
+ }
+ }
+
+ internal override int ImportTo(ModuleBuilder other)
+ {
+ return other.ImportMethodOrField(typeBuilder, name, this.MethodSignature);
+ }
+
+ internal void CheckBaked()
+ {
+ typeBuilder.CheckBaked();
+ }
+
+ internal override int GetCurrentToken()
+ {
+ if (typeBuilder.ModuleBuilder.IsSaved)
+ {
+ return typeBuilder.ModuleBuilder.ResolvePseudoToken(pseudoToken);
+ }
+ else
+ {
+ return pseudoToken;
+ }
+ }
+
+ internal override bool IsBaked
+ {
+ get { return typeBuilder.IsBaked; }
+ }
+ }
}
diff --git a/src/compiler/backend/ikvm/Emit/ModuleBuilder.cs b/src/compiler/backend/ikvm/Emit/ModuleBuilder.cs
index b3940bc18..136a3b2af 100644
--- a/src/compiler/backend/ikvm/Emit/ModuleBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/ModuleBuilder.cs
@@ -23,22 +23,19 @@ Jeroen Frijters
*/
using System;
using System.Collections.Generic;
-using System.IO;
using System.Diagnostics;
-#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
-#endif
-using System.Security.Cryptography;
+using System.IO;
using System.Resources;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+
using IKVM.Reflection.Impl;
using IKVM.Reflection.Metadata;
using IKVM.Reflection.Writer;
namespace IKVM.Reflection.Emit
{
- public sealed class ModuleBuilder : Module, ITypeOwner
+ public sealed class ModuleBuilder : Module, ITypeOwner
{
private static readonly bool usePublicKeyAssemblyReference = false;
private Guid mvid;
@@ -79,23 +76,14 @@ public sealed class ModuleBuilder : Module, ITypeOwner
private struct ResourceWriterRecord
{
private readonly string name;
-#if !CORECLR
private readonly ResourceWriter rw;
-#endif
private readonly Stream stream;
private readonly ResourceAttributes attributes;
-#if CORECLR
- internal ResourceWriterRecord(string name, Stream stream, ResourceAttributes attributes)
- {
- this.name = name;
- this.stream = stream;
- this.attributes = attributes;
- }
-#else
internal ResourceWriterRecord(string name, Stream stream, ResourceAttributes attributes)
: this(name, null, stream, attributes)
{
+
}
internal ResourceWriterRecord(string name, ResourceWriter rw, Stream stream, ResourceAttributes attributes)
@@ -105,16 +93,14 @@ internal ResourceWriterRecord(string name, ResourceWriter rw, Stream stream, Res
this.stream = stream;
this.attributes = attributes;
}
-#endif
internal void Emit(ModuleBuilder mb, int offset)
{
-#if !CORECLR
if (rw != null)
{
rw.Generate();
}
-#endif
+
ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
rec.Offset = offset;
rec.Flags = (int)attributes;
@@ -142,12 +128,10 @@ internal void Write(MetadataWriter mw)
internal void Close()
{
-#if !CORECLR
if (rw != null)
{
rw.Close();
}
-#endif
}
}
@@ -516,13 +500,14 @@ private void AddDeclSecurityRecord(int token, int action, int blob)
this.DeclSecurity.AddRecord(rec);
}
-#if !CORECLR
- internal void AddDeclarativeSecurity(int token, System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
+#if NET6_0_OR_GREATER
+ [Obsolete]
+#endif
+ internal void AddDeclarativeSecurity(int token, System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
// like Ref.Emit, we're using the .NET 1.x xml format
AddDeclSecurityRecord(token, (int)securityAction, this.Blobs.Add(ByteBuffer.Wrap(System.Text.Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString()))));
}
-#endif
internal void AddDeclarativeSecurity(int token, List declarativeSecurity)
{
@@ -533,7 +518,11 @@ internal void AddDeclarativeSecurity(int token, List dec
// check for HostProtectionAttribute without SecurityAction
if (cab.ConstructorArgumentCount == 0)
{
+#if NET6_0_OR_GREATER
+ action = 6;
+#else
action = (int)System.Security.Permissions.SecurityAction.LinkDemand;
+#endif
}
else
{
@@ -580,7 +569,6 @@ public void DefineManifestResource(string name, Stream stream, ResourceAttribute
resourceWriters.Add(new ResourceWriterRecord(name, stream, attribute));
}
-#if !CORECLR
public IResourceWriter DefineResource(string name, string description)
{
return DefineResource(name, description, ResourceAttributes.Public);
@@ -595,7 +583,6 @@ public IResourceWriter DefineResource(string name, string description, ResourceA
resourceWriters.Add(new ResourceWriterRecord(name, rw, mem, attribute));
return rw;
}
-#endif
internal void EmitResources()
{
@@ -685,12 +672,10 @@ internal override void GetTypesImpl(List list)
}
}
-#if !NO_SYMBOL_WRITER
public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
{
return symbolWriter.DefineDocument(url, language, languageVendor, documentType);
}
-#endif
public int __GetAssemblyToken(Assembly assembly)
{
@@ -946,6 +931,13 @@ internal void FillAssemblyRefTable()
private int FindOrAddAssemblyRef(AssemblyName name, bool alwaysAdd)
{
+#if NET6_0_OR_GREATER
+ // Don't reference private assemblies since our assembly becomes unusable
+ if (name.Name == "System.Private.CoreLib")
+ {
+ name = universe.CoreLib.GetName();
+ }
+#endif
AssemblyRefTable.Record rec = new AssemblyRefTable.Record();
Version ver = name.Version ?? new Version(0, 0, 0, 0);
rec.MajorVersion = (ushort)ver.Major;
@@ -979,7 +971,7 @@ private int FindOrAddAssemblyRef(AssemblyName name, bool alwaysAdd)
}
rec.PublicKeyOrToken = this.Blobs.Add(ByteBuffer.Wrap(publicKeyOrToken));
rec.Name = this.Strings.Add(name.Name);
- rec.Culture = name.Culture == null ? 0 : this.Strings.Add(name.Culture);
+ rec.Culture = name.CultureName == null ? 0 : this.Strings.Add(name.CultureName);
if (name.hash != null)
{
rec.HashValue = this.Blobs.Add(ByteBuffer.Wrap(name.hash));
@@ -1462,12 +1454,10 @@ public override string ScopeName
get { return moduleName; }
}
-#if !NO_SYMBOL_WRITER
public ISymbolWriter GetSymWriter()
{
return symbolWriter;
}
-#endif
public void DefineUnmanagedResource(string resourceFileName)
{
@@ -1489,12 +1479,10 @@ public void SetUserEntryPoint(MethodInfo entryPoint)
{
token = -token | 0x06000000;
}
-#if !NO_SYMBOL_WRITER
if (symbolWriter != null)
{
symbolWriter.SetUserEntryPoint(new SymbolToken(token));
}
-#endif
}
public StringToken GetStringConstant(string str)
@@ -1532,11 +1520,6 @@ internal override IKVM.Reflection.Reader.ByteReader GetBlob(int blobIndex)
return Blobs.GetBlob(blobIndex);
}
- internal sealed override Guid GetGuid(int guidIndex)
- {
- throw new NotImplementedException();
- }
-
internal int GetSignatureBlobIndex(Signature sig)
{
ByteBuffer bb = new ByteBuffer(16);
@@ -1634,7 +1617,7 @@ private void SaveImpl(Stream streamOrNull, PortableExecutableKinds portableExecu
IList attributes = asm.GetCustomAttributesData(null);
if (attributes.Count > 0)
{
- int mscorlib = ImportAssemblyRef(universe.Mscorlib);
+ int mscorlib = ImportAssemblyRef(universe.CoreLib);
int[] placeholderTokens = new int[4];
string[] placeholderTypeNames = new string[] { "AssemblyAttributesGoHere", "AssemblyAttributesGoHereM", "AssemblyAttributesGoHereS", "AssemblyAttributesGoHereSM" };
foreach (CustomAttributeData cad in attributes)
diff --git a/src/compiler/backend/ikvm/Emit/TypeBuilder.cs b/src/compiler/backend/ikvm/Emit/TypeBuilder.cs
index ebd513b10..1d0681093 100644
--- a/src/compiler/backend/ikvm/Emit/TypeBuilder.cs
+++ b/src/compiler/backend/ikvm/Emit/TypeBuilder.cs
@@ -72,7 +72,7 @@ public override string AssemblyQualifiedName
get { return null; }
}
- public override bool IsValueType
+ protected override bool IsValueTypeImpl
{
get { return (this.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0; }
}
@@ -567,7 +567,7 @@ public void __SetLayout(int packingSize, int typesize)
{
this.pack = (short)packingSize;
this.size = typesize;
- this.hasLayout = pack != 0 || size != 0;
+ this.hasLayout = true;
}
private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
@@ -655,13 +655,14 @@ public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
declarativeSecurity.Add(customBuilder);
}
-#if !CORECLR
- public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
+#if NET6_0_OR_GREATER
+ [Obsolete]
+#endif
+ public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
this.ModuleBuilder.AddDeclarativeSecurity(token, securityAction, permissionSet);
this.attribs |= TypeAttributes.HasSecurity;
}
-#endif
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
{
@@ -1070,6 +1071,30 @@ internal override bool IsBaked
{
get { return IsCreated(); }
}
+
+ protected override bool IsValueTypeImpl
+ {
+ get
+ {
+ Type baseType = this.BaseType;
+ if (baseType != null && baseType.IsEnumOrValueType && !this.IsEnumOrValueType)
+ {
+ if (IsCreated())
+ {
+ typeFlags |= TypeFlags.ValueType;
+ }
+ return true;
+ }
+ else
+ {
+ if (IsCreated())
+ {
+ typeFlags |= TypeFlags.NotValueType;
+ }
+ return false;
+ }
+ }
+ }
}
sealed class BakedType : TypeInfo
@@ -1204,5 +1229,10 @@ internal override bool IsBaked
{
get { return true; }
}
+
+ protected override bool IsValueTypeImpl
+ {
+ get { return underlyingType.IsValueType; }
+ }
}
}
diff --git a/src/compiler/backend/ikvm/Enums.cs b/src/compiler/backend/ikvm/Enums.cs
index 9fcbb6d04..a58801cf0 100644
--- a/src/compiler/backend/ikvm/Enums.cs
+++ b/src/compiler/backend/ikvm/Enums.cs
@@ -41,6 +41,20 @@ public enum AssemblyContentType
WindowsRuntime = 1,
}
+ public enum AssemblyHashAlgorithm
+ {
+ None = 0,
+ MD5 = 0x8003,
+ SHA1 = 0x8004,
+ }
+
+ public enum AssemblyVersionCompatibility
+ {
+ SameMachine = 1,
+ SameProcess = 2,
+ SameDomain = 3,
+ }
+
[Flags]
public enum BindingFlags
{
diff --git a/src/compiler/backend/ikvm/FunctionPointerType.cs b/src/compiler/backend/ikvm/FunctionPointerType.cs
new file mode 100644
index 000000000..1b9f8fbd5
--- /dev/null
+++ b/src/compiler/backend/ikvm/FunctionPointerType.cs
@@ -0,0 +1,115 @@
+/*
+ Copyright (C) 2009-2015 Jeroen Frijters
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jeroen Frijters
+ jeroen@frijters.net
+
+*/
+using System;
+
+namespace IKVM.Reflection
+{
+
+ sealed class FunctionPointerType : TypeInfo
+ {
+
+ private readonly Universe universe;
+ private readonly __StandAloneMethodSig sig;
+
+ internal static Type Make(Universe universe, __StandAloneMethodSig sig)
+ {
+ return universe.CanonicalizeType(new FunctionPointerType(universe, sig));
+ }
+
+ private FunctionPointerType(Universe universe, __StandAloneMethodSig sig)
+ : base(Signature.ELEMENT_TYPE_FNPTR)
+ {
+ this.universe = universe;
+ this.sig = sig;
+ }
+
+ public override bool Equals(object obj)
+ {
+ FunctionPointerType other = obj as FunctionPointerType;
+ return other != null
+ && other.universe == universe
+ && other.sig.Equals(sig);
+ }
+
+ public override int GetHashCode()
+ {
+ return sig.GetHashCode();
+ }
+
+ public override __StandAloneMethodSig __MethodSignature
+ {
+ get { return sig; }
+ }
+
+ public override Type BaseType
+ {
+ get { return null; }
+ }
+
+ public override TypeAttributes Attributes
+ {
+ get { return 0; }
+ }
+
+ public override string Name
+ {
+ get { throw new InvalidOperationException(); }
+ }
+
+ public override string FullName
+ {
+ get { throw new InvalidOperationException(); }
+ }
+
+ public override Module Module
+ {
+ get { throw new InvalidOperationException(); }
+ }
+
+ internal override Universe Universe
+ {
+ get { return universe; }
+ }
+
+ public override string ToString()
+ {
+ return "";
+ }
+
+ protected override bool ContainsMissingTypeImpl
+ {
+ get { return sig.ContainsMissingType; }
+ }
+
+ internal override bool IsBaked
+ {
+ get { return true; }
+ }
+
+ protected override bool IsValueTypeImpl
+ {
+ get { return false; }
+ }
+ }
+}
diff --git a/src/compiler/backend/ikvm/Fusion.cs b/src/compiler/backend/ikvm/Fusion.cs
index 009f29623..69a00b9f4 100644
--- a/src/compiler/backend/ikvm/Fusion.cs
+++ b/src/compiler/backend/ikvm/Fusion.cs
@@ -29,38 +29,37 @@ Jeroen Frijters
namespace IKVM.Reflection
{
- struct ParsedAssemblyName
- {
- internal string Name;
- internal string Version;
- internal string Culture;
- internal string PublicKeyToken;
- internal bool? Retargetable;
- internal ProcessorArchitecture ProcessorArchitecture;
- internal bool HasPublicKey;
- internal bool WindowsRuntime;
- }
-
- enum ParseAssemblyResult
- {
- OK,
- GenericError,
- DuplicateKey,
- }
-
- static class Fusion
- {
- static readonly Version FrameworkVersion = new Version(4, 0, 0, 0);
- static readonly Version FrameworkVersionNext = new Version(4, 1, 0, 0);
- static readonly Version SilverlightVersion = new Version(2, 0, 5, 0);
- static readonly Version SilverlightVersionMinimum = new Version(2, 0, 0, 0);
- static readonly Version SilverlightVersionMaximum = new Version(5, 9, 0, 0);
- const string PublicKeyTokenEcma = "b77a5c561934e089";
- const string PublicKeyTokenMicrosoft = "b03f5f7f11d50a3a";
- const string PublicKeyTokenSilverlight = "7cec85d7bea7798e";
- const string PublicKeyTokenWinFX = "31bf3856ad364e35";
-
-#if !CORECLR
+ struct ParsedAssemblyName
+ {
+ internal string Name;
+ internal string Version;
+ internal string Culture;
+ internal string PublicKeyToken;
+ internal bool? Retargetable;
+ internal ProcessorArchitecture ProcessorArchitecture;
+ internal bool HasPublicKey;
+ internal bool WindowsRuntime;
+ }
+
+ enum ParseAssemblyResult
+ {
+ OK,
+ GenericError,
+ DuplicateKey,
+ }
+
+ static class Fusion
+ {
+ static readonly Version FrameworkVersion = new Version(4, 0, 0, 0);
+ static readonly Version FrameworkVersionNext = new Version(5, 0, 0, 0);
+ static readonly Version SilverlightVersion = new Version(2, 0, 5, 0);
+ static readonly Version SilverlightVersionMinimum = new Version(2, 0, 0, 0);
+ static readonly Version SilverlightVersionMaximum = new Version(5, 9, 0, 0);
+ const string PublicKeyTokenEcma = "b77a5c561934e089";
+ const string PublicKeyTokenMicrosoft = "b03f5f7f11d50a3a";
+ const string PublicKeyTokenSilverlight = "7cec85d7bea7798e";
+ const string PublicKeyTokenWinFX = "31bf3856ad364e35";
+
internal static bool CompareAssemblyIdentityNative(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
{
bool equivalent;
@@ -70,750 +69,754 @@ internal static bool CompareAssemblyIdentityNative(string assemblyIdentity1, boo
[DllImport("fusion", CharSet = CharSet.Unicode)]
private static extern int CompareAssemblyIdentity(string pwzAssemblyIdentity1, bool fUnified1, string pwzAssemblyIdentity2, bool fUnified2, out bool pfEquivalent, out AssemblyComparisonResult pResult);
-#endif
-
- // internal for use by mcs
- internal static bool CompareAssemblyIdentityPure(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
- {
- ParsedAssemblyName name1;
- ParsedAssemblyName name2;
-
- ParseAssemblyResult r1 = ParseAssemblyName(assemblyIdentity1, out name1);
- ParseAssemblyResult r2 = ParseAssemblyName(assemblyIdentity2, out name2);
-
- Version version1;
- if (unified1)
- {
- if (name1.Name == null || !ParseVersion(name1.Version, out version1) || version1 == null || version1.Revision == -1
- || name1.Culture == null || name1.PublicKeyToken == null || name1.PublicKeyToken.Length < 2)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- throw new ArgumentException();
- }
- }
-
- Version version2 = null;
- if (!ParseVersion(name2.Version, out version2) || version2 == null || version2.Revision == -1
- || name2.Culture == null || name2.PublicKeyToken == null || name2.PublicKeyToken.Length < 2)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- throw new ArgumentException();
- }
-
- if (name2.Name != null && name2.Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase))
- {
- if (name1.Name != null && name1.Name.Equals(name2.Name, StringComparison.OrdinalIgnoreCase))
- {
- result = AssemblyComparisonResult.EquivalentFullMatch;
- return true;
- }
- else
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
- }
-
- if (r1 != ParseAssemblyResult.OK)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- switch (r1)
- {
- case ParseAssemblyResult.DuplicateKey:
- throw new System.IO.FileLoadException();
- case ParseAssemblyResult.GenericError:
- default:
- throw new ArgumentException();
- }
- }
-
- if (r2 != ParseAssemblyResult.OK)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- switch (r2)
- {
- case ParseAssemblyResult.DuplicateKey:
- throw new System.IO.FileLoadException();
- case ParseAssemblyResult.GenericError:
- default:
- throw new ArgumentException();
- }
- }
-
- if (!ParseVersion(name1.Version, out version1))
- {
- result = AssemblyComparisonResult.NonEquivalent;
- throw new ArgumentException();
- }
-
- bool partial = IsPartial(name1, version1);
-
- if (partial && name1.Retargetable.HasValue)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- throw new System.IO.FileLoadException();
- }
- if ((partial && unified1) || IsPartial(name2, version2))
- {
- result = AssemblyComparisonResult.NonEquivalent;
- throw new ArgumentException();
- }
- if (!name1.Name.Equals(name2.Name, StringComparison.OrdinalIgnoreCase))
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
- if (partial && name1.Culture == null)
- {
- }
- else if (!name1.Culture.Equals(name2.Culture, StringComparison.OrdinalIgnoreCase))
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
-
- if (!name1.Retargetable.GetValueOrDefault() && name2.Retargetable.GetValueOrDefault())
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
-
- // HACK handle the case "System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes"
- // compared with "System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=No"
- if (name1.PublicKeyToken == name2.PublicKeyToken
- && version1 != null
- && name1.Retargetable.GetValueOrDefault()
- && !name2.Retargetable.GetValueOrDefault()
- && GetRemappedPublicKeyToken(ref name1, version1) != null)
- {
- name1.Retargetable = false;
- }
-
- string remappedPublicKeyToken1 = null;
- string remappedPublicKeyToken2 = null;
- if (version1 != null && (remappedPublicKeyToken1 = GetRemappedPublicKeyToken(ref name1, version1)) != null)
- {
- name1.PublicKeyToken = remappedPublicKeyToken1;
- version1 = FrameworkVersion;
- }
- if ((remappedPublicKeyToken2 = GetRemappedPublicKeyToken(ref name2, version2)) != null)
- {
- name2.PublicKeyToken = remappedPublicKeyToken2;
- version2 = FrameworkVersion;
- }
- if (name1.Retargetable.GetValueOrDefault())
- {
- if (name2.Retargetable.GetValueOrDefault())
- {
- if (remappedPublicKeyToken1 != null ^ remappedPublicKeyToken2 != null)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
- }
- else if (remappedPublicKeyToken1 == null || remappedPublicKeyToken2 != null)
- {
- result = AssemblyComparisonResult.Unknown;
- return false;
- }
- }
-
- bool fxUnified = false;
-
- // build and revision numbers are ignored
- bool fxVersionMatch = version1.Major == version2.Major && version1.Minor == version2.Minor;
- if (IsFrameworkAssembly(name1))
- {
- fxUnified |= !fxVersionMatch;
- version1 = FrameworkVersion;
- }
- if (IsFrameworkAssembly(name2) && version2 < FrameworkVersionNext)
- {
- fxUnified |= !fxVersionMatch;
- version2 = FrameworkVersion;
- }
-
- if (IsStrongNamed(name2))
- {
- if (name1.PublicKeyToken != null && name1.PublicKeyToken != name2.PublicKeyToken)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
- else if (version1 == null)
- {
- result = AssemblyComparisonResult.EquivalentPartialMatch;
- return true;
- }
- else if (version1.Revision == -1 || version2.Revision == -1)
- {
- result = AssemblyComparisonResult.NonEquivalent;
- throw new ArgumentException();
- }
- else if (version1 < version2)
- {
- if (unified2)
- {
- result = partial ? AssemblyComparisonResult.EquivalentPartialUnified : AssemblyComparisonResult.EquivalentUnified;
- return true;
- }
- else
- {
- result = partial ? AssemblyComparisonResult.NonEquivalentPartialVersion : AssemblyComparisonResult.NonEquivalentVersion;
- return false;
- }
- }
- else if (version1 > version2)
- {
- if (unified1)
- {
- result = partial ? AssemblyComparisonResult.EquivalentPartialUnified : AssemblyComparisonResult.EquivalentUnified;
- return true;
- }
- else
- {
- result = partial ? AssemblyComparisonResult.NonEquivalentPartialVersion : AssemblyComparisonResult.NonEquivalentVersion;
- return false;
- }
- }
- else if (fxUnified || version1 != version2)
- {
- result = partial ? AssemblyComparisonResult.EquivalentPartialFXUnified : AssemblyComparisonResult.EquivalentFXUnified;
- return true;
- }
- else
- {
- result = partial ? AssemblyComparisonResult.EquivalentPartialMatch : AssemblyComparisonResult.EquivalentFullMatch;
- return true;
- }
- }
- else if (IsStrongNamed(name1))
- {
- result = AssemblyComparisonResult.NonEquivalent;
- return false;
- }
- else
- {
- result = partial ? AssemblyComparisonResult.EquivalentPartialWeakNamed : AssemblyComparisonResult.EquivalentWeakNamed;
- return true;
- }
- }
-
- static bool IsFrameworkAssembly(ParsedAssemblyName name)
- {
- // Framework assemblies use different unification rules, so when
- // a new framework is released the new assemblies need to be added.
- switch (name.Name)
- {
- case "System":
- case "System.Core":
- case "System.Data":
- case "System.Data.DataSetExtensions":
- case "System.Data.Linq":
- case "System.Data.OracleClient":
- case "System.Data.Services":
- case "System.Data.Services.Client":
- case "System.IdentityModel":
- case "System.IdentityModel.Selectors":
- case "System.IO.Compression":
- case "System.IO.Compression.FileSystem":
- case "System.Numerics":
- case "System.Reflection.Context":
- case "System.Runtime.Remoting":
- case "System.Runtime.Serialization":
- case "System.Runtime.WindowsRuntime":
- case "System.Runtime.WindowsRuntime.UI.Xaml":
- case "System.ServiceModel":
- case "System.Transactions":
- case "System.Windows.Forms":
- case "System.Xml":
- case "System.Xml.Linq":
- case "System.Xml.Serialization":
- return name.PublicKeyToken == PublicKeyTokenEcma;
-
- case "Microsoft.CSharp":
- case "Microsoft.VisualBasic":
- case "System.Collections":
- case "System.Collections.Concurrent":
- case "System.ComponentModel":
- case "System.ComponentModel.Annotations":
- case "System.ComponentModel.EventBasedAsync":
- case "System.Configuration":
- case "System.Configuration.Install":
- case "System.Design":
- case "System.Diagnostics.Contracts":
- case "System.Diagnostics.Debug":
- case "System.Diagnostics.Tools":
- case "System.Diagnostics.Tracing":
- case "System.DirectoryServices":
- case "System.Drawing":
- case "System.Drawing.Design":
- case "System.Dynamic.Runtime":
- case "System.EnterpriseServices":
- case "System.Globalization":
- case "System.IO":
- case "System.Linq":
- case "System.Linq.Expressions":
- case "System.Linq.Parallel":
- case "System.Linq.Queryable":
- case "System.Management":
- case "System.Messaging":
- case "System.Net":
- case "System.Net.Http":
- case "System.Net.Http.Rtc":
- case "System.Net.NetworkInformation":
- case "System.Net.Primitives":
- case "System.Net.Requests":
- case "System.Numerics.Vectors":
- case "System.ObjectModel":
- case "System.Reflection":
- case "System.Reflection.Emit":
- case "System.Reflection.Emit.ILGeneration":
- case "System.Reflection.Emit.Lightweight":
- case "System.Reflection.Extensions":
- case "System.Reflection.Primitives":
- case "System.Resources.ResourceManager":
- case "System.Runtime":
- case "System.Runtime.Extensions":
- case "System.Runtime.Handles":
- case "System.Runtime.InteropServices":
- case "System.Runtime.InteropServices.WindowsRuntime":
- case "System.Runtime.Numerics":
- case "System.Runtime.Serialization.Formatters.Soap":
- case "System.Runtime.Serialization.Json":
- case "System.Runtime.Serialization.Primitives":
- case "System.Runtime.Serialization.Xml":
- case "System.Security":
- case "System.Security.Principal":
- case "System.ServiceModel.Duplex":
- case "System.ServiceModel.Http":
- case "System.ServiceModel.NetTcp":
- case "System.ServiceModel.Primitives":
- case "System.ServiceModel.Security":
- case "System.ServiceProcess":
- case "System.Text.Encoding":
- case "System.Text.Encoding.Extensions":
- case "System.Text.RegularExpressions":
- case "System.Threading":
- case "System.Threading.Tasks":
- case "System.Threading.Tasks.Parallel":
- case "System.Threading.Timer":
- case "System.Web":
- case "System.Web.Mobile":
- case "System.Web.Services":
- case "System.Windows":
- case "System.Xml.ReaderWriter":
- case "System.Xml.XDocument":
- case "System.Xml.XmlSerializer":
- return name.PublicKeyToken == PublicKeyTokenMicrosoft;
-
- case "System.ComponentModel.DataAnnotations":
- case "System.ServiceModel.Web":
- case "System.Web.Abstractions":
- case "System.Web.Extensions":
- case "System.Web.Extensions.Design":
- case "System.Web.DynamicData":
- case "System.Web.Routing":
- return name.PublicKeyToken == PublicKeyTokenWinFX;
- }
-
- return false;
- }
-
- static string GetRemappedPublicKeyToken(ref ParsedAssemblyName name, Version version)
- {
- if (name.Retargetable.GetValueOrDefault() && version < SilverlightVersion)
- {
- return null;
- }
- if (name.PublicKeyToken == "ddd0da4d3e678217" && name.Name == "System.ComponentModel.DataAnnotations" && name.Retargetable.GetValueOrDefault())
- {
- return PublicKeyTokenWinFX;
- }
- if (SilverlightVersionMinimum <= version && version <= SilverlightVersionMaximum)
- {
- switch (name.PublicKeyToken)
- {
- case PublicKeyTokenSilverlight:
- switch (name.Name)
- {
- case "System":
- case "System.Core":
- return PublicKeyTokenEcma;
- }
- if (name.Retargetable.GetValueOrDefault())
- {
- switch (name.Name)
- {
- case "System.Runtime.Serialization":
- case "System.Xml":
- return PublicKeyTokenEcma;
- case "System.Net":
- case "System.Windows":
- return PublicKeyTokenMicrosoft;
- case "System.ServiceModel.Web":
- return PublicKeyTokenWinFX;
- }
- }
- break;
- case PublicKeyTokenWinFX:
- switch (name.Name)
- {
- case "System.ComponentModel.Composition":
- return PublicKeyTokenEcma;
- }
- if (name.Retargetable.GetValueOrDefault())
- {
- switch (name.Name)
- {
- case "Microsoft.CSharp":
- return PublicKeyTokenMicrosoft;
- case "System.Numerics":
- case "System.ServiceModel":
- case "System.Xml.Serialization":
- case "System.Xml.Linq":
- return PublicKeyTokenEcma;
- }
- }
- break;
- }
- }
- return null;
- }
-
- internal static ParseAssemblyResult ParseAssemblySimpleName(string fullName, out int pos, out string simpleName)
- {
- pos = 0;
- if (!TryParse(fullName, ref pos, out simpleName) || simpleName.Length == 0)
- {
- return ParseAssemblyResult.GenericError;
- }
- if (pos == fullName.Length && fullName[fullName.Length - 1] == ',')
- {
- return ParseAssemblyResult.GenericError;
- }
- return ParseAssemblyResult.OK;
- }
-
- private static bool TryParse(string fullName, ref int pos, out string value)
- {
- value = null;
- StringBuilder sb = new StringBuilder();
- while (pos < fullName.Length && char.IsWhiteSpace(fullName[pos]))
- {
- pos++;
- }
- int quote = -1;
- if (pos < fullName.Length && (fullName[pos] == '"' || fullName[pos] == '\''))
- {
- quote = fullName[pos++];
- }
- for (; pos < fullName.Length; pos++)
- {
- char ch = fullName[pos];
- if (ch == '\\')
- {
- if (++pos == fullName.Length)
- {
- return false;
- }
- ch = fullName[pos];
- if (ch == '\\')
- {
- return false;
- }
- }
- else if (ch == quote)
- {
- for (pos++; pos != fullName.Length; pos++)
- {
- ch = fullName[pos];
- if (ch == ',' || ch == '=')
- {
- break;
- }
- if (!char.IsWhiteSpace(ch))
- {
- return false;
- }
- }
- break;
- }
- else if (quote == -1 && (ch == '"' || ch == '\''))
- {
- return false;
- }
- else if (quote == -1 && (ch == ',' || ch == '='))
- {
- break;
- }
- sb.Append(ch);
- }
- value = sb.ToString().Trim();
- return value.Length != 0 || quote != -1;
- }
-
- private static bool TryConsume(string fullName, char ch, ref int pos)
- {
- if (pos < fullName.Length && fullName[pos] == ch)
- {
- pos++;
- return true;
- }
- return false;
- }
-
- private static bool TryParseAssemblyAttribute(string fullName, ref int pos, ref string key, ref string value)
- {
- return TryConsume(fullName, ',', ref pos)
- && TryParse(fullName, ref pos, out key)
- && TryConsume(fullName, '=', ref pos)
- && TryParse(fullName, ref pos, out value);
- }
-
- internal static ParseAssemblyResult ParseAssemblyName(string fullName, out ParsedAssemblyName parsedName)
- {
- parsedName = new ParsedAssemblyName();
- int pos;
- ParseAssemblyResult res = ParseAssemblySimpleName(fullName, out pos, out parsedName.Name);
- if (res != ParseAssemblyResult.OK)
- {
- return res;
- }
- else
- {
- const int ERROR_SXS_IDENTITIES_DIFFERENT = unchecked((int)0x80073716);
- System.Collections.Generic.Dictionary unknownAttributes = null;
- bool hasProcessorArchitecture = false;
- bool hasContentType = false;
- bool hasPublicKeyToken = false;
- string publicKeyToken;
- while (pos != fullName.Length)
- {
- string key = null;
- string value = null;
- if (!TryParseAssemblyAttribute(fullName, ref pos, ref key, ref value))
- {
- return ParseAssemblyResult.GenericError;
- }
- key = key.ToLowerInvariant();
- switch (key)
- {
- case "version":
- if (parsedName.Version != null)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- parsedName.Version = value;
- break;
- case "culture":
- if (parsedName.Culture != null)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- if (!ParseCulture(value, out parsedName.Culture))
- {
- return ParseAssemblyResult.GenericError;
- }
- break;
- case "publickeytoken":
- if (hasPublicKeyToken)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- if (!ParsePublicKeyToken(value, out publicKeyToken))
- {
- return ParseAssemblyResult.GenericError;
- }
- if (parsedName.HasPublicKey && parsedName.PublicKeyToken != publicKeyToken)
- {
- Marshal.ThrowExceptionForHR(ERROR_SXS_IDENTITIES_DIFFERENT);
- }
- parsedName.PublicKeyToken = publicKeyToken;
- hasPublicKeyToken = true;
- break;
- case "publickey":
- if (parsedName.HasPublicKey)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- if (!ParsePublicKey(value, out publicKeyToken))
- {
- return ParseAssemblyResult.GenericError;
- }
- if (hasPublicKeyToken && parsedName.PublicKeyToken != publicKeyToken)
- {
- Marshal.ThrowExceptionForHR(ERROR_SXS_IDENTITIES_DIFFERENT);
- }
- parsedName.PublicKeyToken = publicKeyToken;
- parsedName.HasPublicKey = true;
- break;
- case "retargetable":
- if (parsedName.Retargetable.HasValue)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- switch (value.ToLowerInvariant())
- {
- case "yes":
- parsedName.Retargetable = true;
- break;
- case "no":
- parsedName.Retargetable = false;
- break;
- default:
- return ParseAssemblyResult.GenericError;
- }
- break;
- case "processorarchitecture":
- if (hasProcessorArchitecture)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- hasProcessorArchitecture = true;
- switch (value.ToLowerInvariant())
- {
- case "none":
- parsedName.ProcessorArchitecture = ProcessorArchitecture.None;
- break;
- case "msil":
- parsedName.ProcessorArchitecture = ProcessorArchitecture.MSIL;
- break;
- case "x86":
- parsedName.ProcessorArchitecture = ProcessorArchitecture.X86;
- break;
- case "ia64":
- parsedName.ProcessorArchitecture = ProcessorArchitecture.IA64;
- break;
- case "amd64":
- parsedName.ProcessorArchitecture = ProcessorArchitecture.Amd64;
- break;
- case "arm":
- parsedName.ProcessorArchitecture = ProcessorArchitecture.Arm;
- break;
- default:
- return ParseAssemblyResult.GenericError;
- }
- break;
- case "contenttype":
- if (hasContentType)
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- hasContentType = true;
- if (!value.Equals("windowsruntime", StringComparison.OrdinalIgnoreCase))
- {
- return ParseAssemblyResult.GenericError;
- }
- parsedName.WindowsRuntime = true;
- break;
- default:
- if (key.Length == 0)
- {
- return ParseAssemblyResult.GenericError;
- }
- if (unknownAttributes == null)
- {
- unknownAttributes = new System.Collections.Generic.Dictionary();
- }
- if (unknownAttributes.ContainsKey(key))
- {
- return ParseAssemblyResult.DuplicateKey;
- }
- unknownAttributes.Add(key, null);
- break;
- }
- }
- return ParseAssemblyResult.OK;
- }
- }
- private static bool ParseVersion(string str, out Version version)
- {
- if (str == null)
- {
- version = null;
- return true;
- }
- string[] parts = str.Split('.');
- if (parts.Length < 2 || parts.Length > 4)
- {
- version = null;
- ushort dummy;
- // if the version consists of a single integer, it is invalid, but not invalid enough to fail the parse of the whole assembly name
- return parts.Length == 1 && ushort.TryParse(parts[0], System.Globalization.NumberStyles.Integer, null, out dummy);
- }
- if (parts[0] == "" || parts[1] == "")
- {
- // this is a strange scenario, the version is invalid, but not invalid enough to fail the parse of the whole assembly name
- version = null;
- return true;
- }
- ushort major, minor, build = 65535, revision = 65535;
- if (ushort.TryParse(parts[0], System.Globalization.NumberStyles.Integer, null, out major)
- && ushort.TryParse(parts[1], System.Globalization.NumberStyles.Integer, null, out minor)
- && (parts.Length <= 2 || parts[2] == "" || ushort.TryParse(parts[2], System.Globalization.NumberStyles.Integer, null, out build))
- && (parts.Length <= 3 || parts[3] == "" || (parts[2] != "" && ushort.TryParse(parts[3], System.Globalization.NumberStyles.Integer, null, out revision))))
- {
- if (parts.Length == 4 && parts[3] != "" && parts[2] != "")
- {
- version = new Version(major, minor, build, revision);
- }
- else if (parts.Length == 3 && parts[2] != "")
- {
- version = new Version(major, minor, build);
- }
- else
- {
- version = new Version(major, minor);
- }
- return true;
- }
- version = null;
- return false;
- }
-
- private static bool ParseCulture(string str, out string culture)
- {
- if (str == null)
- {
- culture = null;
- return false;
- }
- culture = str;
- return true;
- }
-
- private static bool ParsePublicKeyToken(string str, out string publicKeyToken)
- {
- if (str == null)
- {
- publicKeyToken = null;
- return false;
- }
- publicKeyToken = str.ToLowerInvariant();
- return true;
- }
-
- private static bool ParsePublicKey(string str, out string publicKeyToken)
- {
- if (str == null)
- {
- publicKeyToken = null;
- return false;
- }
- publicKeyToken = AssemblyName.ComputePublicKeyToken(str);
- return true;
- }
-
- private static bool IsPartial(ParsedAssemblyName name, Version version)
- {
- return version == null || name.Culture == null || name.PublicKeyToken == null;
- }
-
- private static bool IsStrongNamed(ParsedAssemblyName name)
- {
- return name.PublicKeyToken != null && name.PublicKeyToken != "null";
- }
- }
+ // internal for use by mcs
+ internal static bool CompareAssemblyIdentityPure(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
+ {
+ ParsedAssemblyName name1;
+ ParsedAssemblyName name2;
+
+ ParseAssemblyResult r1 = ParseAssemblyName(assemblyIdentity1, out name1);
+ ParseAssemblyResult r2 = ParseAssemblyName(assemblyIdentity2, out name2);
+
+ Version version1;
+ if (unified1)
+ {
+ if (name1.Name == null || !ParseVersion(name1.Version, out version1) || version1 == null || version1.Revision == -1
+ || name1.Culture == null || name1.PublicKeyToken == null || name1.PublicKeyToken.Length < 2)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ throw new ArgumentException();
+ }
+ }
+
+ Version version2 = null;
+ if (!ParseVersion(name2.Version, out version2) || version2 == null || version2.Revision == -1
+ || name2.Culture == null || name2.PublicKeyToken == null || name2.PublicKeyToken.Length < 2)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ throw new ArgumentException();
+ }
+
+ if (name2.Name != null && name2.Name.Equals(Universe.CoreLibName, StringComparison.OrdinalIgnoreCase))
+ {
+ if (name1.Name != null && name1.Name.Equals(name2.Name, StringComparison.OrdinalIgnoreCase))
+ {
+ result = AssemblyComparisonResult.EquivalentFullMatch;
+ return true;
+ }
+ else
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+ }
+
+ if (r1 != ParseAssemblyResult.OK)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ switch (r1)
+ {
+ case ParseAssemblyResult.DuplicateKey:
+ throw new System.IO.FileLoadException();
+ case ParseAssemblyResult.GenericError:
+ default:
+ throw new ArgumentException();
+ }
+ }
+
+ if (r2 != ParseAssemblyResult.OK)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ switch (r2)
+ {
+ case ParseAssemblyResult.DuplicateKey:
+ throw new System.IO.FileLoadException();
+ case ParseAssemblyResult.GenericError:
+ default:
+ throw new ArgumentException();
+ }
+ }
+
+ if (!ParseVersion(name1.Version, out version1))
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ throw new ArgumentException();
+ }
+
+ bool partial = IsPartial(name1, version1);
+
+ if (partial && name1.Retargetable.HasValue)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ throw new System.IO.FileLoadException();
+ }
+ if ((partial && unified1) || IsPartial(name2, version2))
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ throw new ArgumentException();
+ }
+ if (!name1.Name.Equals(name2.Name, StringComparison.OrdinalIgnoreCase))
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+ if (partial && name1.Culture == null)
+ {
+ }
+ else if (!name1.Culture.Equals(name2.Culture, StringComparison.OrdinalIgnoreCase))
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+
+ if (!name1.Retargetable.GetValueOrDefault() && name2.Retargetable.GetValueOrDefault())
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+
+ // HACK handle the case "System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes"
+ // compared with "System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=No"
+ if (name1.PublicKeyToken == name2.PublicKeyToken
+ && version1 != null
+ && name1.Retargetable.GetValueOrDefault()
+ && !name2.Retargetable.GetValueOrDefault()
+ && GetRemappedPublicKeyToken(ref name1, version1) != null)
+ {
+ name1.Retargetable = false;
+ }
+
+ string remappedPublicKeyToken1 = null;
+ string remappedPublicKeyToken2 = null;
+ if (version1 != null && (remappedPublicKeyToken1 = GetRemappedPublicKeyToken(ref name1, version1)) != null)
+ {
+ name1.PublicKeyToken = remappedPublicKeyToken1;
+ version1 = FrameworkVersion;
+ }
+ if ((remappedPublicKeyToken2 = GetRemappedPublicKeyToken(ref name2, version2)) != null)
+ {
+ name2.PublicKeyToken = remappedPublicKeyToken2;
+ version2 = FrameworkVersion;
+ }
+ if (name1.Retargetable.GetValueOrDefault())
+ {
+ if (name2.Retargetable.GetValueOrDefault())
+ {
+ if (remappedPublicKeyToken1 != null ^ remappedPublicKeyToken2 != null)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+ }
+ else if (remappedPublicKeyToken1 == null || remappedPublicKeyToken2 != null)
+ {
+ result = AssemblyComparisonResult.Unknown;
+ return false;
+ }
+ }
+
+ bool fxUnified = false;
+
+ if (version1 == null)
+ {
+ result = AssemblyComparisonResult.Unknown;
+ return false;
+ }
+
+ if (version2 == null)
+ {
+ result = AssemblyComparisonResult.Unknown;
+ return false;
+ }
+
+ // build and revision numbers are ignored
+ bool fxVersionMatch = version1.Major == version2.Major && version1.Minor == version2.Minor;
+ if (IsFrameworkAssembly(name1))
+ {
+ fxUnified |= !fxVersionMatch;
+ version1 = FrameworkVersion;
+ }
+ if (IsFrameworkAssembly(name2) && version2 < FrameworkVersionNext)
+ {
+ fxUnified |= !fxVersionMatch;
+ version2 = FrameworkVersion;
+ }
+
+ if (IsStrongNamed(name2))
+ {
+ if (name1.PublicKeyToken != null && name1.PublicKeyToken != name2.PublicKeyToken)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+ else if (version1 == null)
+ {
+ result = AssemblyComparisonResult.EquivalentPartialMatch;
+ return true;
+ }
+ else if (version1.Revision == -1 || version2.Revision == -1)
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ throw new ArgumentException();
+ }
+ else if (version1 < version2)
+ {
+ if (unified2)
+ {
+ result = partial ? AssemblyComparisonResult.EquivalentPartialUnified : AssemblyComparisonResult.EquivalentUnified;
+ return true;
+ }
+ else
+ {
+ result = partial ? AssemblyComparisonResult.NonEquivalentPartialVersion : AssemblyComparisonResult.NonEquivalentVersion;
+ return false;
+ }
+ }
+ else if (version1 > version2)
+ {
+ if (unified1)
+ {
+ result = partial ? AssemblyComparisonResult.EquivalentPartialUnified : AssemblyComparisonResult.EquivalentUnified;
+ return true;
+ }
+ else
+ {
+ result = partial ? AssemblyComparisonResult.NonEquivalentPartialVersion : AssemblyComparisonResult.NonEquivalentVersion;
+ return false;
+ }
+ }
+ else if (fxUnified || version1 != version2)
+ {
+ result = partial ? AssemblyComparisonResult.EquivalentPartialFXUnified : AssemblyComparisonResult.EquivalentFXUnified;
+ return true;
+ }
+ else
+ {
+ result = partial ? AssemblyComparisonResult.EquivalentPartialMatch : AssemblyComparisonResult.EquivalentFullMatch;
+ return true;
+ }
+ }
+ else if (IsStrongNamed(name1))
+ {
+ result = AssemblyComparisonResult.NonEquivalent;
+ return false;
+ }
+ else
+ {
+ result = partial ? AssemblyComparisonResult.EquivalentPartialWeakNamed : AssemblyComparisonResult.EquivalentWeakNamed;
+ return true;
+ }
+ }
+
+ static bool IsFrameworkAssembly(ParsedAssemblyName name)
+ {
+ // Framework assemblies use different unification rules, so when
+ // a new framework is released the new assemblies need to be added.
+ switch (name.Name)
+ {
+ case "System":
+ case "System.Core":
+ case "System.Data":
+ case "System.Data.DataSetExtensions":
+ case "System.Data.Linq":
+ case "System.Data.OracleClient":
+ case "System.Data.Services":
+ case "System.Data.Services.Client":
+ case "System.IdentityModel":
+ case "System.IdentityModel.Selectors":
+ case "System.IO.Compression":
+ case "System.Numerics":
+ case "System.Reflection.Context":
+ case "System.Runtime.Remoting":
+ case "System.Runtime.Serialization":
+ case "System.Runtime.WindowsRuntime":
+ case "System.Runtime.WindowsRuntime.UI.Xaml":
+ case "System.ServiceModel":
+ case "System.Transactions":
+ case "System.Windows.Forms":
+ case "System.Xml":
+ case "System.Xml.Linq":
+ case "System.Xml.Serialization":
+ return name.PublicKeyToken == PublicKeyTokenEcma;
+
+ case "Microsoft.CSharp":
+ case "Microsoft.VisualBasic":
+ case "System.Collections":
+ case "System.Collections.Concurrent":
+ case "System.ComponentModel":
+ case "System.ComponentModel.Annotations":
+ case "System.ComponentModel.EventBasedAsync":
+ case "System.Configuration":
+ case "System.Configuration.Install":
+ case "System.Design":
+ case "System.Diagnostics.Contracts":
+ case "System.Diagnostics.Debug":
+ case "System.Diagnostics.Tools":
+ case "System.Diagnostics.Tracing":
+ case "System.DirectoryServices":
+ case "System.Drawing":
+ case "System.Drawing.Design":
+ case "System.Dynamic.Runtime":
+ case "System.EnterpriseServices":
+ case "System.Globalization":
+ case "System.IO":
+ case "System.Linq":
+ case "System.Linq.Expressions":
+ case "System.Linq.Parallel":
+ case "System.Linq.Queryable":
+ case "System.Management":
+ case "System.Messaging":
+ case "System.Net":
+ case "System.Net.Http":
+ case "System.Net.Http.Rtc":
+ case "System.Net.NetworkInformation":
+ case "System.Net.Primitives":
+ case "System.Net.Requests":
+ case "System.ObjectModel":
+ case "System.Reflection":
+ case "System.Reflection.Extensions":
+ case "System.Reflection.Primitives":
+ case "System.Resources.ResourceManager":
+ case "System.Runtime":
+ case "System.Runtime.Extensions":
+ case "System.Runtime.InteropServices":
+ case "System.Runtime.InteropServices.WindowsRuntime":
+ case "System.Runtime.Numerics":
+ case "System.Runtime.Serialization.Formatters.Soap":
+ case "System.Runtime.Serialization.Json":
+ case "System.Runtime.Serialization.Primitives":
+ case "System.Runtime.Serialization.Xml":
+ case "System.Security":
+ case "System.Security.Principal":
+ case "System.ServiceModel.Duplex":
+ case "System.ServiceModel.Http":
+ case "System.ServiceModel.NetTcp":
+ case "System.ServiceModel.Primitives":
+ case "System.ServiceModel.Security":
+ case "System.ServiceProcess":
+ case "System.Text.Encoding":
+ case "System.Text.Encoding.Extensions":
+ case "System.Text.RegularExpressions":
+ case "System.Threading":
+ case "System.Threading.Tasks":
+ case "System.Threading.Tasks.Parallel":
+ case "System.Web":
+ case "System.Web.Mobile":
+ case "System.Web.Services":
+ case "System.Windows":
+ case "System.Xml.ReaderWriter":
+ case "System.Xml.XDocument":
+ case "System.Xml.XmlSerializer":
+ return name.PublicKeyToken == PublicKeyTokenMicrosoft;
+
+ case "System.ComponentModel.DataAnnotations":
+ case "System.ServiceModel.Web":
+ case "System.Web.Abstractions":
+ case "System.Web.Extensions":
+ case "System.Web.Extensions.Design":
+ case "System.Web.DynamicData":
+ case "System.Web.Routing":
+ return name.PublicKeyToken == PublicKeyTokenWinFX;
+ }
+
+ return false;
+ }
+
+ static string GetRemappedPublicKeyToken(ref ParsedAssemblyName name, Version version)
+ {
+ if (name.Retargetable.GetValueOrDefault() && version < SilverlightVersion)
+ {
+ return null;
+ }
+ if (name.PublicKeyToken == "ddd0da4d3e678217" && name.Name == "System.ComponentModel.DataAnnotations" && name.Retargetable.GetValueOrDefault())
+ {
+ return PublicKeyTokenWinFX;
+ }
+ if (SilverlightVersionMinimum <= version && version <= SilverlightVersionMaximum)
+ {
+ switch (name.PublicKeyToken)
+ {
+ case PublicKeyTokenSilverlight:
+ switch (name.Name)
+ {
+ case "System":
+ case "System.Core":
+ return PublicKeyTokenEcma;
+ }
+ if (name.Retargetable.GetValueOrDefault())
+ {
+ switch (name.Name)
+ {
+ case "System.Runtime.Serialization":
+ case "System.Xml":
+ return PublicKeyTokenEcma;
+ case "System.Net":
+ case "System.Windows":
+ return PublicKeyTokenMicrosoft;
+ case "System.ServiceModel.Web":
+ return PublicKeyTokenWinFX;
+ }
+ }
+ break;
+ case PublicKeyTokenWinFX:
+ switch (name.Name)
+ {
+ case "System.ComponentModel.Composition":
+ return PublicKeyTokenEcma;
+ }
+ if (name.Retargetable.GetValueOrDefault())
+ {
+ switch (name.Name)
+ {
+ case "Microsoft.CSharp":
+ return PublicKeyTokenMicrosoft;
+ case "System.Numerics":
+ case "System.ServiceModel":
+ case "System.Xml.Serialization":
+ case "System.Xml.Linq":
+ return PublicKeyTokenEcma;
+ }
+ }
+ break;
+ }
+ }
+ return null;
+ }
+
+ internal static ParseAssemblyResult ParseAssemblySimpleName(string fullName, out int pos, out string simpleName)
+ {
+ pos = 0;
+ if (!TryParse(fullName, ref pos, out simpleName) || simpleName.Length == 0)
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ if (pos == fullName.Length && fullName[fullName.Length - 1] == ',')
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ return ParseAssemblyResult.OK;
+ }
+
+ private static bool TryParse(string fullName, ref int pos, out string value)
+ {
+ value = null;
+ StringBuilder sb = new StringBuilder();
+ while (pos < fullName.Length && char.IsWhiteSpace(fullName[pos]))
+ {
+ pos++;
+ }
+ int quote = -1;
+ if (pos < fullName.Length && (fullName[pos] == '"' || fullName[pos] == '\''))
+ {
+ quote = fullName[pos++];
+ }
+ for (; pos < fullName.Length; pos++)
+ {
+ char ch = fullName[pos];
+ if (ch == '\\')
+ {
+ if (++pos == fullName.Length)
+ {
+ return false;
+ }
+ ch = fullName[pos];
+ if (ch == '\\')
+ {
+ return false;
+ }
+ }
+ else if (ch == quote)
+ {
+ for (pos++; pos != fullName.Length; pos++)
+ {
+ ch = fullName[pos];
+ if (ch == ',' || ch == '=')
+ {
+ break;
+ }
+ if (!char.IsWhiteSpace(ch))
+ {
+ return false;
+ }
+ }
+ break;
+ }
+ else if (quote == -1 && (ch == '"' || ch == '\''))
+ {
+ return false;
+ }
+ else if (quote == -1 && (ch == ',' || ch == '='))
+ {
+ break;
+ }
+ sb.Append(ch);
+ }
+ value = sb.ToString().Trim();
+ return value.Length != 0 || quote != -1;
+ }
+
+ private static bool TryConsume(string fullName, char ch, ref int pos)
+ {
+ if (pos < fullName.Length && fullName[pos] == ch)
+ {
+ pos++;
+ return true;
+ }
+ return false;
+ }
+
+ private static bool TryParseAssemblyAttribute(string fullName, ref int pos, ref string key, ref string value)
+ {
+ return TryConsume(fullName, ',', ref pos)
+ && TryParse(fullName, ref pos, out key)
+ && TryConsume(fullName, '=', ref pos)
+ && TryParse(fullName, ref pos, out value);
+ }
+
+ internal static ParseAssemblyResult ParseAssemblyName(string fullName, out ParsedAssemblyName parsedName)
+ {
+ parsedName = new ParsedAssemblyName();
+ int pos;
+ ParseAssemblyResult res = ParseAssemblySimpleName(fullName, out pos, out parsedName.Name);
+ if (res != ParseAssemblyResult.OK)
+ {
+ return res;
+ }
+ else
+ {
+ const int ERROR_SXS_IDENTITIES_DIFFERENT = unchecked((int)0x80073716);
+ System.Collections.Generic.Dictionary unknownAttributes = null;
+ bool hasProcessorArchitecture = false;
+ bool hasContentType = false;
+ bool hasPublicKeyToken = false;
+ string publicKeyToken;
+ while (pos != fullName.Length)
+ {
+ string key = null;
+ string value = null;
+ if (!TryParseAssemblyAttribute(fullName, ref pos, ref key, ref value))
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ key = key.ToLowerInvariant();
+ switch (key)
+ {
+ case "version":
+ if (parsedName.Version != null)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ parsedName.Version = value;
+ break;
+ case "culture":
+ if (parsedName.Culture != null)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ if (!ParseCulture(value, out parsedName.Culture))
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ break;
+ case "publickeytoken":
+ if (hasPublicKeyToken)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ if (!ParsePublicKeyToken(value, out publicKeyToken))
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ if (parsedName.HasPublicKey && parsedName.PublicKeyToken != publicKeyToken)
+ {
+ Marshal.ThrowExceptionForHR(ERROR_SXS_IDENTITIES_DIFFERENT);
+ }
+ parsedName.PublicKeyToken = publicKeyToken;
+ hasPublicKeyToken = true;
+ break;
+ case "publickey":
+ if (parsedName.HasPublicKey)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ if (!ParsePublicKey(value, out publicKeyToken))
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ if (hasPublicKeyToken && parsedName.PublicKeyToken != publicKeyToken)
+ {
+ Marshal.ThrowExceptionForHR(ERROR_SXS_IDENTITIES_DIFFERENT);
+ }
+ parsedName.PublicKeyToken = publicKeyToken;
+ parsedName.HasPublicKey = true;
+ break;
+ case "retargetable":
+ if (parsedName.Retargetable.HasValue)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ switch (value.ToLowerInvariant())
+ {
+ case "yes":
+ parsedName.Retargetable = true;
+ break;
+ case "no":
+ parsedName.Retargetable = false;
+ break;
+ default:
+ return ParseAssemblyResult.GenericError;
+ }
+ break;
+ case "processorarchitecture":
+ if (hasProcessorArchitecture)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ hasProcessorArchitecture = true;
+ switch (value.ToLowerInvariant())
+ {
+ case "none":
+ parsedName.ProcessorArchitecture = ProcessorArchitecture.None;
+ break;
+ case "msil":
+ parsedName.ProcessorArchitecture = ProcessorArchitecture.MSIL;
+ break;
+ case "x86":
+ parsedName.ProcessorArchitecture = ProcessorArchitecture.X86;
+ break;
+ case "ia64":
+ parsedName.ProcessorArchitecture = ProcessorArchitecture.IA64;
+ break;
+ case "amd64":
+ parsedName.ProcessorArchitecture = ProcessorArchitecture.Amd64;
+ break;
+ case "arm":
+ parsedName.ProcessorArchitecture = ProcessorArchitecture.Arm;
+ break;
+ default:
+ return ParseAssemblyResult.GenericError;
+ }
+ break;
+ case "contenttype":
+ if (hasContentType)
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ hasContentType = true;
+ if (!value.Equals("windowsruntime", StringComparison.OrdinalIgnoreCase))
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ parsedName.WindowsRuntime = true;
+ break;
+ default:
+ if (key.Length == 0)
+ {
+ return ParseAssemblyResult.GenericError;
+ }
+ if (unknownAttributes == null)
+ {
+ unknownAttributes = new System.Collections.Generic.Dictionary();
+ }
+ if (unknownAttributes.ContainsKey(key))
+ {
+ return ParseAssemblyResult.DuplicateKey;
+ }
+ unknownAttributes.Add(key, null);
+ break;
+ }
+ }
+ return ParseAssemblyResult.OK;
+ }
+ }
+
+ private static bool ParseVersion(string str, out Version version)
+ {
+ if (str == null)
+ {
+ version = null;
+ return true;
+ }
+ string[] parts = str.Split('.');
+ if (parts.Length < 2 || parts.Length > 4)
+ {
+ version = null;
+ ushort dummy;
+ // if the version consists of a single integer, it is invalid, but not invalid enough to fail the parse of the whole assembly name
+ return parts.Length == 1 && ushort.TryParse(parts[0], System.Globalization.NumberStyles.Integer, null, out dummy);
+ }
+ if (parts[0] == "" || parts[1] == "")
+ {
+ // this is a strange scenario, the version is invalid, but not invalid enough to fail the parse of the whole assembly name
+ version = null;
+ return true;
+ }
+ ushort major, minor, build = 65535, revision = 65535;
+ if (ushort.TryParse(parts[0], System.Globalization.NumberStyles.Integer, null, out major)
+ && ushort.TryParse(parts[1], System.Globalization.NumberStyles.Integer, null, out minor)
+ && (parts.Length <= 2 || parts[2] == "" || ushort.TryParse(parts[2], System.Globalization.NumberStyles.Integer, null, out build))
+ && (parts.Length <= 3 || parts[3] == "" || (parts[2] != "" && ushort.TryParse(parts[3], System.Globalization.NumberStyles.Integer, null, out revision))))
+ {
+ if (parts.Length == 4 && parts[3] != "" && parts[2] != "")
+ {
+ version = new Version(major, minor, build, revision);
+ }
+ else if (parts.Length == 3 && parts[2] != "")
+ {
+ version = new Version(major, minor, build);
+ }
+ else
+ {
+ version = new Version(major, minor);
+ }
+ return true;
+ }
+ version = null;
+ return false;
+ }
+
+ private static bool ParseCulture(string str, out string culture)
+ {
+ if (str == null)
+ {
+ culture = null;
+ return false;
+ }
+ culture = str;
+ return true;
+ }
+
+ private static bool ParsePublicKeyToken(string str, out string publicKeyToken)
+ {
+ if (str == null)
+ {
+ publicKeyToken = null;
+ return false;
+ }
+ publicKeyToken = str.ToLowerInvariant();
+ return true;
+ }
+
+ private static bool ParsePublicKey(string str, out string publicKeyToken)
+ {
+ if (str == null)
+ {
+ publicKeyToken = null;
+ return false;
+ }
+ publicKeyToken = AssemblyName.ComputePublicKeyToken(str);
+ return true;
+ }
+
+ private static bool IsPartial(ParsedAssemblyName name, Version version)
+ {
+ return version == null || name.Culture == null || name.PublicKeyToken == null;
+ }
+
+ private static bool IsStrongNamed(ParsedAssemblyName name)
+ {
+ return name.PublicKeyToken != null && name.PublicKeyToken != "null";
+ }
+ }
}
diff --git a/src/compiler/backend/ikvm/IKVM.Reflection.csproj b/src/compiler/backend/ikvm/IKVM.Reflection.csproj
index e84127189..2da5dfb7f 100644
--- a/src/compiler/backend/ikvm/IKVM.Reflection.csproj
+++ b/src/compiler/backend/ikvm/IKVM.Reflection.csproj
@@ -1,148 +1,17 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {4CB170EF-DFE6-4A56-9E1B-A85449E827A7}
- Library
- Properties
- IKVM.Reflection
- IKVM.Reflection
- v4.5
- 512
-
-
-
-
-
-
-
-
-
-
-
-
- true
- full
- false
- bin\Debug\
- TRACE;DEBUG;NET_4_0
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE;NET_4_0
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net6.0
+ IKVM implementation of System.Reflection[.Emit]
+ $(DefineConstants);EMITTERS
+
+
+
+
+
+
+
+
+
+
diff --git a/src/compiler/backend/ikvm/Impl/DummyWriter.cs b/src/compiler/backend/ikvm/Impl/DummyWriter.cs
new file mode 100644
index 000000000..07eebd8d8
--- /dev/null
+++ b/src/compiler/backend/ikvm/Impl/DummyWriter.cs
@@ -0,0 +1,155 @@
+/*
+ Copyright (C) 2008, 2009 Jeroen Frijters
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jeroen Frijters
+ jeroen@frijters.net
+
+*/
+#if NET6_0_OR_GREATER
+using System;
+using System.Diagnostics.SymbolStore;
+
+namespace IKVM.Reflection.Impl
+{
+ class DummyWriter : ISymbolWriterImpl
+ {
+ public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
+ {
+ }
+
+ public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
+ {
+ return new DummyDocumentWriter();
+ }
+
+ public void SetUserEntryPoint(SymbolToken entryMethod)
+ {
+ }
+
+ public void OpenMethod(SymbolToken method)
+ {
+ }
+
+ public void CloseMethod()
+ {
+ }
+
+ public void DefineSequencePoints(ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines,
+ int[] endColumns)
+ {
+ }
+
+ public int OpenScope(int startOffset)
+ {
+ return 0;
+ }
+
+ public void CloseScope(int endOffset)
+ {
+ }
+
+ public void SetScopeRange(int scopeID, int startOffset, int endOffset)
+ {
+ }
+
+ public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1,
+ int addr2, int addr3, int startOffset, int endOffset)
+ {
+ }
+
+ public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1,
+ int addr2, int addr3)
+ {
+ }
+
+ public void DefineField(SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind,
+ int addr1, int addr2, int addr3)
+ {
+ }
+
+ public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1,
+ int addr2, int addr3)
+ {
+ }
+
+ public void Close()
+ {
+ }
+
+ public void SetSymAttribute(SymbolToken parent, string name, byte[] data)
+ {
+ }
+
+ public void OpenNamespace(string name)
+ {
+ }
+
+ public void CloseNamespace()
+ {
+ }
+
+ public void UsingNamespace(string fullName)
+ {
+ }
+
+ public void SetMethodSourceRange(ISymbolDocumentWriter startDoc, int startLine, int startColumn, ISymbolDocumentWriter endDoc,
+ int endLine, int endColumn)
+ {
+ }
+
+ public void SetUnderlyingWriter(IntPtr underlyingWriter)
+ {
+ }
+
+ public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
+ {
+ return new byte[0];
+ }
+
+ public void RemapToken(int oldToken, int newToken)
+ {
+ }
+
+ public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1,
+ int addr2, int addr3, int startOffset, int endOffset)
+ {
+ }
+
+ public void OpenMethod(SymbolToken symbolToken, MethodBase mb)
+ {
+ }
+
+ public bool IsDeterministic
+ {
+ get { return false; }
+ }
+ }
+
+ class DummyDocumentWriter : ISymbolDocumentWriter
+ {
+ public void SetSource(byte[] source)
+ {
+ }
+
+ public void SetCheckSum(Guid algorithmId, byte[] checkSum)
+ {
+ }
+ }
+}
+#endif // NET6_0_OR_GREATER
diff --git a/src/compiler/backend/ikvm/Impl/PdbWriter.cs b/src/compiler/backend/ikvm/Impl/PdbWriter.cs
index 4d8fc1d88..0be07a302 100644
--- a/src/compiler/backend/ikvm/Impl/PdbWriter.cs
+++ b/src/compiler/backend/ikvm/Impl/PdbWriter.cs
@@ -21,1173 +21,1176 @@ Jeroen Frijters
jeroen@frijters.net
*/
+#if !NET6_0_OR_GREATER
using System;
using System.Collections.Generic;
-using System.Runtime.InteropServices;
using System.Diagnostics.SymbolStore;
+using System.Runtime.InteropServices;
+
using IKVM.Reflection.Emit;
namespace IKVM.Reflection.Impl
{
- [Guid("7dac8207-d3ae-4c75-9b67-92801a497d44")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- interface IMetaDataImport
- {
- void PlaceHolder_CloseEnum();
- void PlaceHolder_CountEnum();
- void PlaceHolder_ResetEnum();
- void PlaceHolder_EnumTypeDefs();
- void PlaceHolder_EnumInterfaceImpls();
- void PlaceHolder_EnumTypeRefs();
- void PlaceHolder_FindTypeDefByName();
- void PlaceHolder_GetScopeProps();
- void PlaceHolder_GetModuleFromScope();
-
- void GetTypeDefProps(
- int td, // [IN] TypeDef token for inquiry.
- IntPtr szTypeDef, // [OUT] Put name here.
- int cchTypeDef, // [IN] size of name buffer in wide chars.
- IntPtr pchTypeDef, // [OUT] put size of name (wide chars) here.
- IntPtr pdwTypeDefFlags, // [OUT] Put flags here.
- IntPtr ptkExtends); // [OUT] Put base class TypeDef/TypeRef here.
-
- void PlaceHolder_GetInterfaceImplProps();
- void PlaceHolder_GetTypeRefProps();
- void PlaceHolder_ResolveTypeRef();
- void PlaceHolder_EnumMembers();
- void PlaceHolder_EnumMembersWithName();
- void PlaceHolder_EnumMethods();
- void PlaceHolder_EnumMethodsWithName();
- void PlaceHolder_EnumFields();
- void PlaceHolder_EnumFieldsWithName();
- void PlaceHolder_EnumParams();
- void PlaceHolder_EnumMemberRefs();
- void PlaceHolder_EnumMethodImpls();
- void PlaceHolder_EnumPermissionSets();
- void PlaceHolder_FindMember();
- void PlaceHolder_FindMethod();
- void PlaceHolder_FindField();
- void PlaceHolder_FindMemberRef();
-
- void GetMethodProps(
- int mb, // The method for which to get props.
- IntPtr pClass, // Put method's class here.
- IntPtr szMethod, // Put method's name here.
- int cchMethod, // Size of szMethod buffer in wide chars.
- IntPtr pchMethod, // Put actual size here
- IntPtr pdwAttr, // Put flags here.
- IntPtr ppvSigBlob, // [OUT] point to the blob value of meta data
- IntPtr pcbSigBlob, // [OUT] actual size of signature blob
- IntPtr pulCodeRVA, // [OUT] codeRVA
- IntPtr pdwImplFlags); // [OUT] Impl. Flags
-
- void PlaceHolder_GetMemberRefProps();
- void PlaceHolder_EnumProperties();
- void PlaceHolder_EnumEvents();
- void PlaceHolder_GetEventProps();
- void PlaceHolder_EnumMethodSemantics();
- void PlaceHolder_GetMethodSemantics();
- void PlaceHolder_GetClassLayout();
- void PlaceHolder_GetFieldMarshal();
- void PlaceHolder_GetRVA();
- void PlaceHolder_GetPermissionSetProps();
- void PlaceHolder_GetSigFromToken();
- void PlaceHolder_GetModuleRefProps();
- void PlaceHolder_EnumModuleRefs();
- void PlaceHolder_GetTypeSpecFromToken();
- void PlaceHolder_GetNameFromToken();
- void PlaceHolder_EnumUnresolvedMethods();
- void PlaceHolder_GetUserString();
- void PlaceHolder_GetPinvokeMap();
- void PlaceHolder_EnumSignatures();
- void PlaceHolder_EnumTypeSpecs();
- void PlaceHolder_EnumUserStrings();
- void PlaceHolder_GetParamForMethodIndex();
- void PlaceHolder_EnumCustomAttributes();
- void PlaceHolder_GetCustomAttributeProps();
- void PlaceHolder_FindTypeRef();
- void PlaceHolder_GetMemberProps();
- void PlaceHolder_GetFieldProps();
- void PlaceHolder_GetPropertyProps();
- void PlaceHolder_GetParamProps();
- void PlaceHolder_GetCustomAttributeByName();
- void PlaceHolder_IsValidToken();
-
- void GetNestedClassProps(
- int tdNestedClass, // [IN] NestedClass token.
- IntPtr ptdEnclosingClass); // [OUT] EnclosingClass token.
-
- void PlaceHolder_GetNativeCallConvFromSig();
- void PlaceHolder_IsGlobal();
- }
-
- [Guid("ba3fee4c-ecb9-4e41-83b7-183fa41cd859")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- interface IMetaDataEmit
- {
- void PlaceHolder_SetModuleProps();
- void PlaceHolder_Save();
- void PlaceHolder_SaveToStream();
- void PlaceHolder_GetSaveSize();
- void PlaceHolder_DefineTypeDef();
- void PlaceHolder_DefineNestedType();
- void PlaceHolder_SetHandler();
- void PlaceHolder_DefineMethod();
- void PlaceHolder_DefineMethodImpl();
- void PlaceHolder_DefineTypeRefByName();
- void PlaceHolder_DefineImportType();
- void PlaceHolder_DefineMemberRef();
- void PlaceHolder_DefineImportMember();
- void PlaceHolder_DefineEvent();
- void PlaceHolder_SetClassLayout();
- void PlaceHolder_DeleteClassLayout();
- void PlaceHolder_SetFieldMarshal();
- void PlaceHolder_DeleteFieldMarshal();
- void PlaceHolder_DefinePermissionSet();
- void PlaceHolder_SetRVA();
- void PlaceHolder_GetTokenFromSig();
- void PlaceHolder_DefineModuleRef();
- void PlaceHolder_SetParent();
- void PlaceHolder_GetTokenFromTypeSpec();
- void PlaceHolder_SaveToMemory();
- void PlaceHolder_DefineUserString();
- void PlaceHolder_DeleteToken();
- void PlaceHolder_SetMethodProps();
- void PlaceHolder_SetTypeDefProps();
- void PlaceHolder_SetEventProps();
- void PlaceHolder_SetPermissionSetProps();
- void PlaceHolder_DefinePinvokeMap();
- void PlaceHolder_SetPinvokeMap();
- void PlaceHolder_DeletePinvokeMap();
- void PlaceHolder_DefineCustomAttribute();
- void PlaceHolder_SetCustomAttributeValue();
- void PlaceHolder_DefineField();
- void PlaceHolder_DefineProperty();
- void PlaceHolder_DefineParam();
- void PlaceHolder_SetFieldProps();
- void PlaceHolder_SetPropertyProps();
- void PlaceHolder_SetParamProps();
- void PlaceHolder_DefineSecurityAttributeSet();
- void PlaceHolder_ApplyEditAndContinue();
- void PlaceHolder_TranslateSigWithScope();
- void PlaceHolder_SetMethodImplFlags();
- void PlaceHolder_SetFieldRVA();
- void PlaceHolder_Merge();
- void PlaceHolder_MergeEnd();
- }
-
- [Guid("B01FAFEB-C450-3A4D-BEEC-B4CEEC01E006")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- internal interface ISymUnmanagedDocumentWriter { }
-
- [Guid("0b97726e-9e6d-4f05-9a26-424022093caa")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- [CoClass(typeof(CorSymWriterClass))]
- interface ISymUnmanagedWriter2
- {
- ISymUnmanagedDocumentWriter DefineDocument(string url, ref Guid language, ref Guid languageVendor, ref Guid documentType);
- void PlaceHolder_SetUserEntryPoint();
- void OpenMethod(int method);
- void CloseMethod();
- int OpenScope(int startOffset);
- void CloseScope(int endOffset);
- void PlaceHolder_SetScopeRange();
- void DefineLocalVariable(string name, int attributes, int cSig, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] signature, int addrKind, int addr1, int addr2, int startOffset, int endOffset);
- void PlaceHolder_DefineParameter();
- void PlaceHolder_DefineField();
- void PlaceHolder_DefineGlobalVariable();
- void Close();
- void PlaceHolder_SetSymAttribute();
- void PlaceHolder_OpenNamespace();
- void PlaceHolder_CloseNamespace();
- void PlaceHolder_UsingNamespace();
- void PlaceHolder_SetMethodSourceRange();
- void Initialize([MarshalAs(UnmanagedType.IUnknown)] object emitter, string filename, [MarshalAs(UnmanagedType.IUnknown)] object pIStream, bool fFullBuild);
-
- void GetDebugInfo(
- [In, Out] ref IMAGE_DEBUG_DIRECTORY pIDD,
- [In] uint cData,
- [Out] out uint pcData,
- [Out, MarshalAs(UnmanagedType.LPArray)] byte[] data);
-
- void DefineSequencePoints(ISymUnmanagedDocumentWriter document, int spCount,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] offsets,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] lines,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] columns,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endLines,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endColumns);
-
- void RemapToken(
- [In] int oldToken,
- [In] int newToken);
-
- void PlaceHolder_Initialize2();
- void PlaceHolder_DefineConstant();
- void PlaceHolder_Abort();
-
- void DefineLocalVariable2(string name, int attributes, int token, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
-
- void PlaceHolder_DefineGlobalVariable2();
- void PlaceHolder_DefineConstant2();
- }
-
- [Guid("108296c1-281e-11d3-bd22-0000f80849bd")]
- [ComImport]
- class CorSymWriterClass { }
-
- sealed class PdbWriter : ISymbolWriterImpl, IMetaDataEmit, IMetaDataImport
- {
- private readonly ModuleBuilder moduleBuilder;
- private ISymUnmanagedWriter2 symUnmanagedWriter;
- private readonly Dictionary documents = new Dictionary();
- private readonly List methods = new List();
- private readonly Dictionary remap = new Dictionary();
- private readonly Dictionary reversemap = new Dictionary();
- private readonly Dictionary methodMap = new Dictionary();
- private Method currentMethod;
-
- internal PdbWriter(ModuleBuilder moduleBuilder)
- {
- this.moduleBuilder = moduleBuilder;
- }
-
- private sealed class Document : ISymbolDocumentWriter
- {
- internal readonly string url;
- private Guid language;
- private Guid languageVendor;
- private Guid documentType;
- private ISymUnmanagedDocumentWriter unmanagedDocument;
-
- internal Document(string url, Guid language, Guid languageVendor, Guid documentType)
- {
- this.url = url;
- this.language = language;
- this.languageVendor = languageVendor;
- this.documentType = documentType;
- }
-
- public void SetCheckSum(Guid algorithmId, byte[] checkSum)
- {
- throw new NotImplementedException();
- }
-
- public void SetSource(byte[] source)
- {
- throw new NotImplementedException();
- }
-
- internal ISymUnmanagedDocumentWriter GetUnmanagedDocument(ISymUnmanagedWriter2 symUnmanagedWriter)
- {
- if (unmanagedDocument == null)
- {
- unmanagedDocument = symUnmanagedWriter.DefineDocument(url, ref language, ref languageVendor, ref documentType);
- }
- return unmanagedDocument;
- }
-
- internal void Release()
- {
- if (unmanagedDocument != null)
- {
- Marshal.ReleaseComObject(unmanagedDocument);
- unmanagedDocument = null;
- }
- }
- }
-
- private sealed class LocalVar
- {
- internal readonly FieldAttributes attributes;
- internal readonly int signature;
- internal readonly SymAddressKind addrKind;
- internal readonly int addr1;
- internal readonly int addr2;
- internal readonly int addr3;
- internal readonly int startOffset;
- internal readonly int endOffset;
-
- internal LocalVar(FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
- {
- this.attributes = attributes;
- this.signature = signature;
- this.addrKind = addrKind;
- this.addr1 = addr1;
- this.addr2 = addr2;
- this.addr3 = addr3;
- this.startOffset = startOffset;
- this.endOffset = endOffset;
- }
- }
-
- private sealed class Scope
- {
- internal readonly int startOffset;
- internal int endOffset;
- internal readonly List scopes = new List();
- internal readonly Dictionary locals = new Dictionary();
-
- internal Scope(int startOffset)
- {
- this.startOffset = startOffset;
- }
-
- internal void Do(ISymUnmanagedWriter2 symUnmanagedWriter)
- {
- symUnmanagedWriter.OpenScope(startOffset);
- foreach (KeyValuePair kv in locals)
- {
- symUnmanagedWriter.DefineLocalVariable2(kv.Key, (int)kv.Value.attributes, kv.Value.signature, (int)kv.Value.addrKind, kv.Value.addr1, kv.Value.addr2, kv.Value.addr3, kv.Value.startOffset, kv.Value.endOffset);
- }
- foreach (Scope scope in scopes)
- {
- scope.Do(symUnmanagedWriter);
- }
- symUnmanagedWriter.CloseScope(endOffset);
- }
- }
-
- private sealed class Method
- {
- internal readonly int token;
- internal Document document;
- internal int[] offsets;
- internal int[] lines;
- internal int[] columns;
- internal int[] endLines;
- internal int[] endColumns;
- internal readonly List scopes = new List();
- internal readonly Stack scopeStack = new Stack();
-
- internal Method(int token)
- {
- this.token = token;
- }
- }
-
- public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
- {
- Document doc;
- if (!documents.TryGetValue(url, out doc))
- {
- doc = new Document(url, language, languageVendor, documentType);
- documents.Add(url, doc);
- }
- return doc;
- }
-
- public void OpenMethod(SymbolToken method)
- {
- throw new NotImplementedException();
- }
-
- public void OpenMethod(SymbolToken method, MethodBase mb)
- {
- int token = method.GetToken();
- currentMethod = new Method(token);
- methodMap.Add(token, mb);
- }
-
- public void CloseMethod()
- {
- methods.Add(currentMethod);
- currentMethod = null;
- }
-
- public void DefineSequencePoints(ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
- {
- currentMethod.document = (Document)document;
- currentMethod.offsets = offsets;
- currentMethod.lines = lines;
- currentMethod.columns = columns;
- currentMethod.endLines = endLines;
- currentMethod.endColumns = endColumns;
- }
-
- public int OpenScope(int startOffset)
- {
- Scope scope = new Scope(startOffset);
- if (currentMethod.scopeStack.Count == 0)
- {
- currentMethod.scopes.Add(scope);
- }
- else
- {
- currentMethod.scopeStack.Peek().scopes.Add(scope);
- }
- currentMethod.scopeStack.Push(scope);
- return 0;
- }
-
- public void CloseScope(int endOffset)
- {
- currentMethod.scopeStack.Pop().endOffset = endOffset;
- }
-
- public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
- {
- currentMethod.scopeStack.Peek().locals[name] = new LocalVar(attributes, signature, addrKind, addr1, addr2, addr3, startOffset, endOffset);
- }
-
- private void InitWriter()
- {
- if (symUnmanagedWriter == null)
- {
- string fileName = System.IO.Path.ChangeExtension(moduleBuilder.FullyQualifiedName, ".pdb");
- // pro-actively delete the .pdb to get a meaningful IOException, instead of COMInteropException if the file can't be overwritten (or is corrupt, or who knows what)
- System.IO.File.Delete(fileName);
- symUnmanagedWriter = new ISymUnmanagedWriter2();
- symUnmanagedWriter.Initialize(this, fileName, null, true);
- }
- }
-
- public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
- {
- InitWriter();
- uint cData;
- symUnmanagedWriter.GetDebugInfo(ref idd, 0, out cData, null);
- byte[] buf = new byte[cData];
- symUnmanagedWriter.GetDebugInfo(ref idd, (uint)buf.Length, out cData, buf);
- return buf;
- }
-
- public void RemapToken(int oldToken, int newToken)
- {
- remap.Add(oldToken, newToken);
- reversemap.Add(newToken, oldToken);
- }
-
- public void Close()
- {
- InitWriter();
-
- foreach (Method method in methods)
- {
- int remappedToken = method.token;
- remap.TryGetValue(remappedToken, out remappedToken);
- symUnmanagedWriter.OpenMethod(remappedToken);
- if (method.document != null)
- {
- ISymUnmanagedDocumentWriter doc = method.document.GetUnmanagedDocument(symUnmanagedWriter);
- symUnmanagedWriter.DefineSequencePoints(doc, method.offsets.Length, method.offsets, method.lines, method.columns, method.endLines, method.endColumns);
- }
- foreach (Scope scope in method.scopes)
- {
- scope.Do(symUnmanagedWriter);
- }
- symUnmanagedWriter.CloseMethod();
- }
-
- foreach (Document doc in documents.Values)
- {
- doc.Release();
- }
-
- symUnmanagedWriter.Close();
- Marshal.ReleaseComObject(symUnmanagedWriter);
- symUnmanagedWriter = null;
- documents.Clear();
- methods.Clear();
- remap.Clear();
- reversemap.Clear();
- }
-
- public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
- {
- throw new NotImplementedException();
- }
-
- public void CloseNamespace()
- {
- throw new NotImplementedException();
- }
-
- public void DefineField(SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3)
- {
- throw new NotImplementedException();
- }
-
- public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3)
- {
- throw new NotImplementedException();
- }
-
- public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1, int addr2, int addr3)
- {
- throw new NotImplementedException();
- }
-
- public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
- {
- throw new NotImplementedException();
- }
-
- public void OpenNamespace(string name)
- {
- throw new NotImplementedException();
- }
-
- public void SetMethodSourceRange(ISymbolDocumentWriter startDoc, int startLine, int startColumn, ISymbolDocumentWriter endDoc, int endLine, int endColumn)
- {
- throw new NotImplementedException();
- }
-
- public void SetScopeRange(int scopeID, int startOffset, int endOffset)
- {
- throw new NotImplementedException();
- }
-
- public void SetSymAttribute(SymbolToken parent, string name, byte[] data)
- {
- throw new NotImplementedException();
- }
-
- public void SetUnderlyingWriter(IntPtr underlyingWriter)
- {
- throw new NotImplementedException();
- }
-
- public void SetUserEntryPoint(SymbolToken entryMethod)
- {
- throw new NotImplementedException();
- }
-
- public void UsingNamespace(string fullName)
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_CloseEnum()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_CountEnum()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_ResetEnum()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumTypeDefs()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumInterfaceImpls()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumTypeRefs()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_FindTypeDefByName()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetScopeProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetModuleFromScope()
- {
- throw new NotImplementedException();
- }
-
- private static void WriteString(IntPtr ptrString, IntPtr ptrLength, string str, int length)
- {
- if (ptrString != IntPtr.Zero)
- {
- for (int i = 0; i < Math.Min(length, str.Length); i++)
- {
- Marshal.WriteInt16(ptrString, i, str[i]);
- }
- }
- if (ptrLength != IntPtr.Zero)
- {
- Marshal.WriteInt32(ptrLength, str.Length);
- }
- }
-
- private static void WriteToken(IntPtr ptr, MemberInfo member)
- {
- if (ptr != IntPtr.Zero)
- {
- Marshal.WriteInt32(ptr, member == null ? 0 : member.MetadataToken);
- }
- }
-
- private static void WriteInt32(IntPtr ptr, int value)
- {
- if (ptr != IntPtr.Zero)
- {
- Marshal.WriteInt32(ptr, value);
- }
- }
-
- public void GetTypeDefProps(
- int td, // [IN] TypeDef token for inquiry.
- IntPtr szTypeDef, // [OUT] Put name here.
- int cchTypeDef, // [IN] size of name buffer in wide chars.
- IntPtr pchTypeDef, // [OUT] put size of name (wide chars) here.
- IntPtr pdwTypeDefFlags, // [OUT] Put flags here.
- IntPtr ptkExtends) // [OUT] Put base class TypeDef/TypeRef here.
- {
- if (td == 0)
- {
- // why are we being called with an invalid token?
- WriteString(szTypeDef, pchTypeDef, "", cchTypeDef);
- WriteInt32(pdwTypeDefFlags, 0);
- WriteToken(ptkExtends, null);
- }
- else
- {
- Type type = moduleBuilder.ResolveType(td);
- WriteString(szTypeDef, pchTypeDef, type.FullName, cchTypeDef);
- WriteInt32(pdwTypeDefFlags, (int)type.Attributes);
- WriteToken(ptkExtends, type.BaseType);
- }
- }
-
- public void PlaceHolder_GetInterfaceImplProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetTypeRefProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_ResolveTypeRef()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMembers()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMembersWithName()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMethods()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMethodsWithName()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumFields()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumFieldsWithName()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumParams()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMemberRefs()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMethodImpls()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumPermissionSets()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_FindMember()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_FindMethod()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_FindField()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_FindMemberRef()
- {
- throw new NotImplementedException();
- }
-
- public void GetMethodProps(
- int mb, // The method for which to get props.
- IntPtr pClass, // [OUT] Put method's class here.
- IntPtr szMethod, // [OUT] Put method's name here.
- int cchMethod, // Size of szMethod buffer in wide chars.
- IntPtr pchMethod, // [OUT] Put actual size here
- IntPtr pdwAttr, // [OUT] Put flags here.
- IntPtr ppvSigBlob, // [OUT] point to the blob value of meta data
- IntPtr pcbSigBlob, // [OUT] actual size of signature blob
- IntPtr pulCodeRVA, // [OUT] codeRVA
- IntPtr pdwImplFlags) // [OUT] Impl. Flags
- {
- if (pdwAttr != IntPtr.Zero || ppvSigBlob != IntPtr.Zero || pcbSigBlob != IntPtr.Zero || pulCodeRVA != IntPtr.Zero || pdwImplFlags != IntPtr.Zero)
- {
- throw new NotImplementedException();
- }
- MethodBase method = methodMap[reversemap[mb]];
- WriteToken(pClass, method.DeclaringType);
- WriteString(szMethod, pchMethod, method.Name, cchMethod);
- }
-
- public void PlaceHolder_GetMemberRefProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumProperties()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumEvents()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetEventProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumMethodSemantics()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetMethodSemantics()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetClassLayout()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetFieldMarshal()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetRVA()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetPermissionSetProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetSigFromToken()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetModuleRefProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumModuleRefs()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetTypeSpecFromToken()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetNameFromToken()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumUnresolvedMethods()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetUserString()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetPinvokeMap()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumSignatures()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumTypeSpecs()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumUserStrings()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetParamForMethodIndex()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_EnumCustomAttributes()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetCustomAttributeProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_FindTypeRef()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetMemberProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetFieldProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetPropertyProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetParamProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetCustomAttributeByName()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_IsValidToken()
- {
- throw new NotImplementedException();
- }
-
- public void GetNestedClassProps(
- int tdNestedClass, // [IN] NestedClass token.
- IntPtr ptdEnclosingClass) // [OUT] EnclosingClass token.
- {
- Type type = moduleBuilder.ResolveType(tdNestedClass);
- WriteToken(ptdEnclosingClass, type.DeclaringType);
- }
-
- public void PlaceHolder_GetNativeCallConvFromSig()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_IsGlobal()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetModuleProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_Save()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SaveToStream()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetSaveSize()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineTypeDef()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineNestedType()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetHandler()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineMethod()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineMethodImpl()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineTypeRefByName()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineImportType()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineMemberRef()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineImportMember()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineEvent()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetClassLayout()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DeleteClassLayout()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetFieldMarshal()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DeleteFieldMarshal()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefinePermissionSet()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetRVA()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetTokenFromSig()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineModuleRef()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetParent()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_GetTokenFromTypeSpec()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SaveToMemory()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineUserString()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DeleteToken()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetMethodProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetTypeDefProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetEventProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetPermissionSetProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefinePinvokeMap()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetPinvokeMap()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DeletePinvokeMap()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineCustomAttribute()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetCustomAttributeValue()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineField()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineProperty()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineParam()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetFieldProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetPropertyProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetParamProps()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_DefineSecurityAttributeSet()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_ApplyEditAndContinue()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_TranslateSigWithScope()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetMethodImplFlags()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_SetFieldRVA()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_Merge()
- {
- throw new NotImplementedException();
- }
-
- public void PlaceHolder_MergeEnd()
- {
- throw new NotImplementedException();
- }
-
- public bool IsDeterministic
- {
- get { return false; }
- }
- }
+ [Guid("7dac8207-d3ae-4c75-9b67-92801a497d44")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [ComImport]
+ interface IMetaDataImport
+ {
+ void PlaceHolder_CloseEnum();
+ void PlaceHolder_CountEnum();
+ void PlaceHolder_ResetEnum();
+ void PlaceHolder_EnumTypeDefs();
+ void PlaceHolder_EnumInterfaceImpls();
+ void PlaceHolder_EnumTypeRefs();
+ void PlaceHolder_FindTypeDefByName();
+ void PlaceHolder_GetScopeProps();
+ void PlaceHolder_GetModuleFromScope();
+
+ void GetTypeDefProps(
+ int td, // [IN] TypeDef token for inquiry.
+ IntPtr szTypeDef, // [OUT] Put name here.
+ int cchTypeDef, // [IN] size of name buffer in wide chars.
+ IntPtr pchTypeDef, // [OUT] put size of name (wide chars) here.
+ IntPtr pdwTypeDefFlags, // [OUT] Put flags here.
+ IntPtr ptkExtends); // [OUT] Put base class TypeDef/TypeRef here.
+
+ void PlaceHolder_GetInterfaceImplProps();
+ void PlaceHolder_GetTypeRefProps();
+ void PlaceHolder_ResolveTypeRef();
+ void PlaceHolder_EnumMembers();
+ void PlaceHolder_EnumMembersWithName();
+ void PlaceHolder_EnumMethods();
+ void PlaceHolder_EnumMethodsWithName();
+ void PlaceHolder_EnumFields();
+ void PlaceHolder_EnumFieldsWithName();
+ void PlaceHolder_EnumParams();
+ void PlaceHolder_EnumMemberRefs();
+ void PlaceHolder_EnumMethodImpls();
+ void PlaceHolder_EnumPermissionSets();
+ void PlaceHolder_FindMember();
+ void PlaceHolder_FindMethod();
+ void PlaceHolder_FindField();
+ void PlaceHolder_FindMemberRef();
+
+ void GetMethodProps(
+ int mb, // The method for which to get props.
+ IntPtr pClass, // Put method's class here.
+ IntPtr szMethod, // Put method's name here.
+ int cchMethod, // Size of szMethod buffer in wide chars.
+ IntPtr pchMethod, // Put actual size here
+ IntPtr pdwAttr, // Put flags here.
+ IntPtr ppvSigBlob, // [OUT] point to the blob value of meta data
+ IntPtr pcbSigBlob, // [OUT] actual size of signature blob
+ IntPtr pulCodeRVA, // [OUT] codeRVA
+ IntPtr pdwImplFlags); // [OUT] Impl. Flags
+
+ void PlaceHolder_GetMemberRefProps();
+ void PlaceHolder_EnumProperties();
+ void PlaceHolder_EnumEvents();
+ void PlaceHolder_GetEventProps();
+ void PlaceHolder_EnumMethodSemantics();
+ void PlaceHolder_GetMethodSemantics();
+ void PlaceHolder_GetClassLayout();
+ void PlaceHolder_GetFieldMarshal();
+ void PlaceHolder_GetRVA();
+ void PlaceHolder_GetPermissionSetProps();
+ void PlaceHolder_GetSigFromToken();
+ void PlaceHolder_GetModuleRefProps();
+ void PlaceHolder_EnumModuleRefs();
+ void PlaceHolder_GetTypeSpecFromToken();
+ void PlaceHolder_GetNameFromToken();
+ void PlaceHolder_EnumUnresolvedMethods();
+ void PlaceHolder_GetUserString();
+ void PlaceHolder_GetPinvokeMap();
+ void PlaceHolder_EnumSignatures();
+ void PlaceHolder_EnumTypeSpecs();
+ void PlaceHolder_EnumUserStrings();
+ void PlaceHolder_GetParamForMethodIndex();
+ void PlaceHolder_EnumCustomAttributes();
+ void PlaceHolder_GetCustomAttributeProps();
+ void PlaceHolder_FindTypeRef();
+ void PlaceHolder_GetMemberProps();
+ void PlaceHolder_GetFieldProps();
+ void PlaceHolder_GetPropertyProps();
+ void PlaceHolder_GetParamProps();
+ void PlaceHolder_GetCustomAttributeByName();
+ void PlaceHolder_IsValidToken();
+
+ void GetNestedClassProps(
+ int tdNestedClass, // [IN] NestedClass token.
+ IntPtr ptdEnclosingClass); // [OUT] EnclosingClass token.
+
+ void PlaceHolder_GetNativeCallConvFromSig();
+ void PlaceHolder_IsGlobal();
+ }
+
+ [Guid("ba3fee4c-ecb9-4e41-83b7-183fa41cd859")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [ComImport]
+ interface IMetaDataEmit
+ {
+ void PlaceHolder_SetModuleProps();
+ void PlaceHolder_Save();
+ void PlaceHolder_SaveToStream();
+ void PlaceHolder_GetSaveSize();
+ void PlaceHolder_DefineTypeDef();
+ void PlaceHolder_DefineNestedType();
+ void PlaceHolder_SetHandler();
+ void PlaceHolder_DefineMethod();
+ void PlaceHolder_DefineMethodImpl();
+ void PlaceHolder_DefineTypeRefByName();
+ void PlaceHolder_DefineImportType();
+ void PlaceHolder_DefineMemberRef();
+ void PlaceHolder_DefineImportMember();
+ void PlaceHolder_DefineEvent();
+ void PlaceHolder_SetClassLayout();
+ void PlaceHolder_DeleteClassLayout();
+ void PlaceHolder_SetFieldMarshal();
+ void PlaceHolder_DeleteFieldMarshal();
+ void PlaceHolder_DefinePermissionSet();
+ void PlaceHolder_SetRVA();
+ void PlaceHolder_GetTokenFromSig();
+ void PlaceHolder_DefineModuleRef();
+ void PlaceHolder_SetParent();
+ void PlaceHolder_GetTokenFromTypeSpec();
+ void PlaceHolder_SaveToMemory();
+ void PlaceHolder_DefineUserString();
+ void PlaceHolder_DeleteToken();
+ void PlaceHolder_SetMethodProps();
+ void PlaceHolder_SetTypeDefProps();
+ void PlaceHolder_SetEventProps();
+ void PlaceHolder_SetPermissionSetProps();
+ void PlaceHolder_DefinePinvokeMap();
+ void PlaceHolder_SetPinvokeMap();
+ void PlaceHolder_DeletePinvokeMap();
+ void PlaceHolder_DefineCustomAttribute();
+ void PlaceHolder_SetCustomAttributeValue();
+ void PlaceHolder_DefineField();
+ void PlaceHolder_DefineProperty();
+ void PlaceHolder_DefineParam();
+ void PlaceHolder_SetFieldProps();
+ void PlaceHolder_SetPropertyProps();
+ void PlaceHolder_SetParamProps();
+ void PlaceHolder_DefineSecurityAttributeSet();
+ void PlaceHolder_ApplyEditAndContinue();
+ void PlaceHolder_TranslateSigWithScope();
+ void PlaceHolder_SetMethodImplFlags();
+ void PlaceHolder_SetFieldRVA();
+ void PlaceHolder_Merge();
+ void PlaceHolder_MergeEnd();
+ }
+
+ [Guid("B01FAFEB-C450-3A4D-BEEC-B4CEEC01E006")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [ComImport]
+ internal interface ISymUnmanagedDocumentWriter { }
+
+ [Guid("0b97726e-9e6d-4f05-9a26-424022093caa")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [ComImport]
+ [CoClass(typeof(CorSymWriterClass))]
+ interface ISymUnmanagedWriter2
+ {
+ ISymUnmanagedDocumentWriter DefineDocument(string url, ref Guid language, ref Guid languageVendor, ref Guid documentType);
+ void PlaceHolder_SetUserEntryPoint();
+ void OpenMethod(int method);
+ void CloseMethod();
+ int OpenScope(int startOffset);
+ void CloseScope(int endOffset);
+ void PlaceHolder_SetScopeRange();
+ void DefineLocalVariable(string name, int attributes, int cSig, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] signature, int addrKind, int addr1, int addr2, int startOffset, int endOffset);
+ void PlaceHolder_DefineParameter();
+ void PlaceHolder_DefineField();
+ void PlaceHolder_DefineGlobalVariable();
+ void Close();
+ void PlaceHolder_SetSymAttribute();
+ void PlaceHolder_OpenNamespace();
+ void PlaceHolder_CloseNamespace();
+ void PlaceHolder_UsingNamespace();
+ void PlaceHolder_SetMethodSourceRange();
+ void Initialize([MarshalAs(UnmanagedType.IUnknown)] object emitter, string filename, [MarshalAs(UnmanagedType.IUnknown)] object pIStream, bool fFullBuild);
+
+ void GetDebugInfo(
+ [In, Out] ref IMAGE_DEBUG_DIRECTORY pIDD,
+ [In] uint cData,
+ [Out] out uint pcData,
+ [Out, MarshalAs(UnmanagedType.LPArray)] byte[] data);
+
+ void DefineSequencePoints(ISymUnmanagedDocumentWriter document, int spCount,
+ [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] offsets,
+ [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] lines,
+ [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] columns,
+ [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endLines,
+ [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endColumns);
+
+ void RemapToken(
+ [In] int oldToken,
+ [In] int newToken);
+
+ void PlaceHolder_Initialize2();
+ void PlaceHolder_DefineConstant();
+ void PlaceHolder_Abort();
+
+ void DefineLocalVariable2(string name, int attributes, int token, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
+
+ void PlaceHolder_DefineGlobalVariable2();
+ void PlaceHolder_DefineConstant2();
+ }
+
+ [Guid("108296c1-281e-11d3-bd22-0000f80849bd")]
+ [ComImport]
+ class CorSymWriterClass { }
+
+ sealed class PdbWriter : ISymbolWriterImpl, IMetaDataEmit, IMetaDataImport
+ {
+ private readonly ModuleBuilder moduleBuilder;
+ private ISymUnmanagedWriter2 symUnmanagedWriter;
+ private readonly Dictionary documents = new Dictionary();
+ private readonly List methods = new List();
+ private readonly Dictionary remap = new Dictionary();
+ private readonly Dictionary reversemap = new Dictionary();
+ private readonly Dictionary methodMap = new Dictionary();
+ private Method currentMethod;
+
+ internal PdbWriter(ModuleBuilder moduleBuilder)
+ {
+ this.moduleBuilder = moduleBuilder;
+ }
+
+ private sealed class Document : ISymbolDocumentWriter
+ {
+ internal readonly string url;
+ private Guid language;
+ private Guid languageVendor;
+ private Guid documentType;
+ private ISymUnmanagedDocumentWriter unmanagedDocument;
+
+ internal Document(string url, Guid language, Guid languageVendor, Guid documentType)
+ {
+ this.url = url;
+ this.language = language;
+ this.languageVendor = languageVendor;
+ this.documentType = documentType;
+ }
+
+ public void SetCheckSum(Guid algorithmId, byte[] checkSum)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetSource(byte[] source)
+ {
+ throw new NotImplementedException();
+ }
+
+ internal ISymUnmanagedDocumentWriter GetUnmanagedDocument(ISymUnmanagedWriter2 symUnmanagedWriter)
+ {
+ if (unmanagedDocument == null)
+ {
+ unmanagedDocument = symUnmanagedWriter.DefineDocument(url, ref language, ref languageVendor, ref documentType);
+ }
+ return unmanagedDocument;
+ }
+
+ internal void Release()
+ {
+ if (unmanagedDocument != null)
+ {
+ Marshal.ReleaseComObject(unmanagedDocument);
+ unmanagedDocument = null;
+ }
+ }
+ }
+
+ private sealed class LocalVar
+ {
+ internal readonly FieldAttributes attributes;
+ internal readonly int signature;
+ internal readonly SymAddressKind addrKind;
+ internal readonly int addr1;
+ internal readonly int addr2;
+ internal readonly int addr3;
+ internal readonly int startOffset;
+ internal readonly int endOffset;
+
+ internal LocalVar(FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
+ {
+ this.attributes = attributes;
+ this.signature = signature;
+ this.addrKind = addrKind;
+ this.addr1 = addr1;
+ this.addr2 = addr2;
+ this.addr3 = addr3;
+ this.startOffset = startOffset;
+ this.endOffset = endOffset;
+ }
+ }
+
+ private sealed class Scope
+ {
+ internal readonly int startOffset;
+ internal int endOffset;
+ internal readonly List scopes = new List();
+ internal readonly Dictionary locals = new Dictionary();
+
+ internal Scope(int startOffset)
+ {
+ this.startOffset = startOffset;
+ }
+
+ internal void Do(ISymUnmanagedWriter2 symUnmanagedWriter)
+ {
+ symUnmanagedWriter.OpenScope(startOffset);
+ foreach (KeyValuePair kv in locals)
+ {
+ symUnmanagedWriter.DefineLocalVariable2(kv.Key, (int)kv.Value.attributes, kv.Value.signature, (int)kv.Value.addrKind, kv.Value.addr1, kv.Value.addr2, kv.Value.addr3, kv.Value.startOffset, kv.Value.endOffset);
+ }
+ foreach (Scope scope in scopes)
+ {
+ scope.Do(symUnmanagedWriter);
+ }
+ symUnmanagedWriter.CloseScope(endOffset);
+ }
+ }
+
+ private sealed class Method
+ {
+ internal readonly int token;
+ internal Document document;
+ internal int[] offsets;
+ internal int[] lines;
+ internal int[] columns;
+ internal int[] endLines;
+ internal int[] endColumns;
+ internal readonly List scopes = new List();
+ internal readonly Stack scopeStack = new Stack();
+
+ internal Method(int token)
+ {
+ this.token = token;
+ }
+ }
+
+ public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
+ {
+ Document doc;
+ if (!documents.TryGetValue(url, out doc))
+ {
+ doc = new Document(url, language, languageVendor, documentType);
+ documents.Add(url, doc);
+ }
+ return doc;
+ }
+
+ public void OpenMethod(SymbolToken method)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OpenMethod(SymbolToken method, MethodBase mb)
+ {
+ int token = method.GetToken();
+ currentMethod = new Method(token);
+ methodMap.Add(token, mb);
+ }
+
+ public void CloseMethod()
+ {
+ methods.Add(currentMethod);
+ currentMethod = null;
+ }
+
+ public void DefineSequencePoints(ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
+ {
+ currentMethod.document = (Document)document;
+ currentMethod.offsets = offsets;
+ currentMethod.lines = lines;
+ currentMethod.columns = columns;
+ currentMethod.endLines = endLines;
+ currentMethod.endColumns = endColumns;
+ }
+
+ public int OpenScope(int startOffset)
+ {
+ Scope scope = new Scope(startOffset);
+ if (currentMethod.scopeStack.Count == 0)
+ {
+ currentMethod.scopes.Add(scope);
+ }
+ else
+ {
+ currentMethod.scopeStack.Peek().scopes.Add(scope);
+ }
+ currentMethod.scopeStack.Push(scope);
+ return 0;
+ }
+
+ public void CloseScope(int endOffset)
+ {
+ currentMethod.scopeStack.Pop().endOffset = endOffset;
+ }
+
+ public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
+ {
+ currentMethod.scopeStack.Peek().locals[name] = new LocalVar(attributes, signature, addrKind, addr1, addr2, addr3, startOffset, endOffset);
+ }
+
+ private void InitWriter()
+ {
+ if (symUnmanagedWriter == null)
+ {
+ string fileName = System.IO.Path.ChangeExtension(moduleBuilder.FullyQualifiedName, ".pdb");
+ // pro-actively delete the .pdb to get a meaningful IOException, instead of COMInteropException if the file can't be overwritten (or is corrupt, or who knows what)
+ System.IO.File.Delete(fileName);
+ symUnmanagedWriter = new ISymUnmanagedWriter2();
+ symUnmanagedWriter.Initialize(this, fileName, null, true);
+ }
+ }
+
+ public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
+ {
+ InitWriter();
+ uint cData;
+ symUnmanagedWriter.GetDebugInfo(ref idd, 0, out cData, null);
+ byte[] buf = new byte[cData];
+ symUnmanagedWriter.GetDebugInfo(ref idd, (uint)buf.Length, out cData, buf);
+ return buf;
+ }
+
+ public void RemapToken(int oldToken, int newToken)
+ {
+ remap.Add(oldToken, newToken);
+ reversemap.Add(newToken, oldToken);
+ }
+
+ public void Close()
+ {
+ InitWriter();
+
+ foreach (Method method in methods)
+ {
+ int remappedToken = method.token;
+ remap.TryGetValue(remappedToken, out remappedToken);
+ symUnmanagedWriter.OpenMethod(remappedToken);
+ if (method.document != null)
+ {
+ ISymUnmanagedDocumentWriter doc = method.document.GetUnmanagedDocument(symUnmanagedWriter);
+ symUnmanagedWriter.DefineSequencePoints(doc, method.offsets.Length, method.offsets, method.lines, method.columns, method.endLines, method.endColumns);
+ }
+ foreach (Scope scope in method.scopes)
+ {
+ scope.Do(symUnmanagedWriter);
+ }
+ symUnmanagedWriter.CloseMethod();
+ }
+
+ foreach (Document doc in documents.Values)
+ {
+ doc.Release();
+ }
+
+ symUnmanagedWriter.Close();
+ Marshal.ReleaseComObject(symUnmanagedWriter);
+ symUnmanagedWriter = null;
+ documents.Clear();
+ methods.Clear();
+ remap.Clear();
+ reversemap.Clear();
+ }
+
+ public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void CloseNamespace()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void DefineField(SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1, int addr2, int addr3)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OpenNamespace(string name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetMethodSourceRange(ISymbolDocumentWriter startDoc, int startLine, int startColumn, ISymbolDocumentWriter endDoc, int endLine, int endColumn)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetScopeRange(int scopeID, int startOffset, int endOffset)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetSymAttribute(SymbolToken parent, string name, byte[] data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetUnderlyingWriter(IntPtr underlyingWriter)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetUserEntryPoint(SymbolToken entryMethod)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void UsingNamespace(string fullName)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_CloseEnum()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_CountEnum()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_ResetEnum()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumTypeDefs()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumInterfaceImpls()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumTypeRefs()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_FindTypeDefByName()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetScopeProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetModuleFromScope()
+ {
+ throw new NotImplementedException();
+ }
+
+ private static void WriteString(IntPtr ptrString, IntPtr ptrLength, string str, int length)
+ {
+ if (ptrString != IntPtr.Zero)
+ {
+ for (int i = 0; i < Math.Min(length, str.Length); i++)
+ {
+ Marshal.WriteInt16(ptrString, i, str[i]);
+ }
+ }
+ if (ptrLength != IntPtr.Zero)
+ {
+ Marshal.WriteInt32(ptrLength, str.Length);
+ }
+ }
+
+ private static void WriteToken(IntPtr ptr, MemberInfo member)
+ {
+ if (ptr != IntPtr.Zero)
+ {
+ Marshal.WriteInt32(ptr, member == null ? 0 : member.MetadataToken);
+ }
+ }
+
+ private static void WriteInt32(IntPtr ptr, int value)
+ {
+ if (ptr != IntPtr.Zero)
+ {
+ Marshal.WriteInt32(ptr, value);
+ }
+ }
+
+ public void GetTypeDefProps(
+ int td, // [IN] TypeDef token for inquiry.
+ IntPtr szTypeDef, // [OUT] Put name here.
+ int cchTypeDef, // [IN] size of name buffer in wide chars.
+ IntPtr pchTypeDef, // [OUT] put size of name (wide chars) here.
+ IntPtr pdwTypeDefFlags, // [OUT] Put flags here.
+ IntPtr ptkExtends) // [OUT] Put base class TypeDef/TypeRef here.
+ {
+ if (td == 0)
+ {
+ // why are we being called with an invalid token?
+ WriteString(szTypeDef, pchTypeDef, "", cchTypeDef);
+ WriteInt32(pdwTypeDefFlags, 0);
+ WriteToken(ptkExtends, null);
+ }
+ else
+ {
+ Type type = moduleBuilder.ResolveType(td);
+ WriteString(szTypeDef, pchTypeDef, type.FullName, cchTypeDef);
+ WriteInt32(pdwTypeDefFlags, (int)type.Attributes);
+ WriteToken(ptkExtends, type.BaseType);
+ }
+ }
+
+ public void PlaceHolder_GetInterfaceImplProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetTypeRefProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_ResolveTypeRef()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMembers()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMembersWithName()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMethods()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMethodsWithName()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumFields()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumFieldsWithName()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumParams()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMemberRefs()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMethodImpls()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumPermissionSets()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_FindMember()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_FindMethod()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_FindField()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_FindMemberRef()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void GetMethodProps(
+ int mb, // The method for which to get props.
+ IntPtr pClass, // [OUT] Put method's class here.
+ IntPtr szMethod, // [OUT] Put method's name here.
+ int cchMethod, // Size of szMethod buffer in wide chars.
+ IntPtr pchMethod, // [OUT] Put actual size here
+ IntPtr pdwAttr, // [OUT] Put flags here.
+ IntPtr ppvSigBlob, // [OUT] point to the blob value of meta data
+ IntPtr pcbSigBlob, // [OUT] actual size of signature blob
+ IntPtr pulCodeRVA, // [OUT] codeRVA
+ IntPtr pdwImplFlags) // [OUT] Impl. Flags
+ {
+ if (pdwAttr != IntPtr.Zero || ppvSigBlob != IntPtr.Zero || pcbSigBlob != IntPtr.Zero || pulCodeRVA != IntPtr.Zero || pdwImplFlags != IntPtr.Zero)
+ {
+ throw new NotImplementedException();
+ }
+ MethodBase method = methodMap[reversemap[mb]];
+ WriteToken(pClass, method.DeclaringType);
+ WriteString(szMethod, pchMethod, method.Name, cchMethod);
+ }
+
+ public void PlaceHolder_GetMemberRefProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumProperties()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumEvents()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetEventProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumMethodSemantics()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetMethodSemantics()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetClassLayout()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetFieldMarshal()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetRVA()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetPermissionSetProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetSigFromToken()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetModuleRefProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumModuleRefs()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetTypeSpecFromToken()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetNameFromToken()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumUnresolvedMethods()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetUserString()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetPinvokeMap()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumSignatures()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumTypeSpecs()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumUserStrings()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetParamForMethodIndex()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_EnumCustomAttributes()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetCustomAttributeProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_FindTypeRef()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetMemberProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetFieldProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetPropertyProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetParamProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetCustomAttributeByName()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_IsValidToken()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void GetNestedClassProps(
+ int tdNestedClass, // [IN] NestedClass token.
+ IntPtr ptdEnclosingClass) // [OUT] EnclosingClass token.
+ {
+ Type type = moduleBuilder.ResolveType(tdNestedClass);
+ WriteToken(ptdEnclosingClass, type.DeclaringType);
+ }
+
+ public void PlaceHolder_GetNativeCallConvFromSig()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_IsGlobal()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetModuleProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_Save()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SaveToStream()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetSaveSize()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineTypeDef()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineNestedType()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetHandler()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineMethod()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineMethodImpl()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineTypeRefByName()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineImportType()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineMemberRef()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineImportMember()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineEvent()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetClassLayout()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DeleteClassLayout()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetFieldMarshal()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DeleteFieldMarshal()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefinePermissionSet()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetRVA()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetTokenFromSig()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineModuleRef()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetParent()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_GetTokenFromTypeSpec()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SaveToMemory()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineUserString()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DeleteToken()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetMethodProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetTypeDefProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetEventProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetPermissionSetProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefinePinvokeMap()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetPinvokeMap()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DeletePinvokeMap()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineCustomAttribute()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetCustomAttributeValue()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineField()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineProperty()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineParam()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetFieldProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetPropertyProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetParamProps()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_DefineSecurityAttributeSet()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_ApplyEditAndContinue()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_TranslateSigWithScope()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetMethodImplFlags()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_SetFieldRVA()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_Merge()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void PlaceHolder_MergeEnd()
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool IsDeterministic
+ {
+ get { return false; }
+ }
+ }
}
+#endif // !NET6_0_OR_GREATER
diff --git a/src/compiler/backend/ikvm/Impl/SymbolSupport.cs b/src/compiler/backend/ikvm/Impl/SymbolSupport.cs
index 49f30c52f..f57a1742d 100644
--- a/src/compiler/backend/ikvm/Impl/SymbolSupport.cs
+++ b/src/compiler/backend/ikvm/Impl/SymbolSupport.cs
@@ -22,204 +22,66 @@ Jeroen Frijters
*/
using System;
-using System.Runtime.InteropServices;
-#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
-#endif
+using System.Runtime.InteropServices;
+
using IKVM.Reflection.Emit;
namespace IKVM.Reflection.Impl
{
- [StructLayout(LayoutKind.Sequential)]
- struct IMAGE_DEBUG_DIRECTORY
- {
- public uint Characteristics;
- public uint TimeDateStamp;
- public ushort MajorVersion;
- public ushort MinorVersion;
- public uint Type;
- public uint SizeOfData;
- public uint AddressOfRawData;
- public uint PointerToRawData;
- }
-
-#if NO_SYMBOL_WRITER
- struct SymbolToken
- {
- internal SymbolToken(int value) { }
- }
+ [StructLayout(LayoutKind.Sequential)]
+ struct IMAGE_DEBUG_DIRECTORY
+ {
+ public uint Characteristics;
+ public uint TimeDateStamp;
+ public ushort MajorVersion;
+ public ushort MinorVersion;
+ public uint Type;
+ public uint SizeOfData;
+ public uint AddressOfRawData;
+ public uint PointerToRawData;
+ }
- interface ISymbolWriterImpl
- {
- byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
- void RemapToken(int oldToken, int newToken);
- void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
- void OpenMethod(SymbolToken symbolToken, MethodBase mb);
- bool IsDeterministic { get; }
- }
-#else
- interface ISymbolWriterImpl : ISymbolWriter
- {
- byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
- void RemapToken(int oldToken, int newToken);
- void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
- void OpenMethod(SymbolToken symbolToken, MethodBase mb);
- bool IsDeterministic { get; }
- }
-#endif
+ interface ISymbolWriterImpl : ISymbolWriter
+ {
+ byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
+ void RemapToken(int oldToken, int newToken);
+ void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
+ void OpenMethod(SymbolToken symbolToken, MethodBase mb);
+ bool IsDeterministic { get; }
+ }
- static class SymbolSupport
- {
- internal static ISymbolWriterImpl CreateSymbolWriterFor(ModuleBuilder moduleBuilder)
- {
-#if NO_SYMBOL_WRITER
- throw new NotSupportedException("IKVM.Reflection compiled with NO_SYMBOL_WRITER does not support writing debugging symbols.");
-#else
- if (Universe.MonoRuntime)
- {
+ static class SymbolSupport
+ {
+ internal static ISymbolWriterImpl CreateSymbolWriterFor(ModuleBuilder moduleBuilder)
+ {
+ if (Universe.MonoRuntime)
+ {
#if MONO
return new MdbWriter(moduleBuilder);
#else
- return new DummySymbolWriter();
+ throw new NotSupportedException("IKVM.Reflection must be compiled with MONO defined to support writing Mono debugging symbols.");
#endif
- }
- else
- {
- return new PdbWriter(moduleBuilder);
- }
+ }
+ else
+ {
+#if NET6_0_OR_GREATER
+ // COM isn't supported on .NET 6, so use a dummy instead (FIXME)
+ return new DummyWriter();
+#else
+ return new PdbWriter(moduleBuilder);
#endif
- }
-
- internal static byte[] GetDebugInfo(ISymbolWriterImpl writer, ref IMAGE_DEBUG_DIRECTORY idd)
- {
- return writer.GetDebugInfo(ref idd);
- }
-
- internal static void RemapToken(ISymbolWriterImpl writer, int oldToken, int newToken)
- {
- writer.RemapToken(oldToken, newToken);
- }
- }
-
- class DummySymbolDocumentWriter : ISymbolDocumentWriter
- {
- public void SetSource(byte[] source)
- {
- }
-
- public void SetCheckSum(Guid algorithmId, byte[] checkSum)
- {
- }
- }
-
- class DummySymbolWriter : ISymbolWriterImpl
- {
- public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
- {
- }
-
- public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
- {
- return new DummySymbolDocumentWriter();
- }
-
- public void SetUserEntryPoint(SymbolToken entryMethod)
- {
- }
-
- public void OpenMethod(SymbolToken method)
- {
- }
-
- public void CloseMethod()
- {
- }
-
- public void DefineSequencePoints(ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines,
- int[] endColumns)
- {
- }
-
- public int OpenScope(int startOffset)
- {
- return 0;
+ }
}
- public void CloseScope(int endOffset)
+ internal static byte[] GetDebugInfo(ISymbolWriterImpl writer, ref IMAGE_DEBUG_DIRECTORY idd)
{
+ return writer.GetDebugInfo(ref idd);
}
- public void SetScopeRange(int scopeID, int startOffset, int endOffset)
+ internal static void RemapToken(ISymbolWriterImpl writer, int oldToken, int newToken)
{
+ writer.RemapToken(oldToken, newToken);
}
-
- public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1,
- int addr2, int addr3, int startOffset, int endOffset)
- {
- }
-
- public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1,
- int addr2, int addr3)
- {
- }
-
- public void DefineField(SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind,
- int addr1, int addr2, int addr3)
- {
- }
-
- public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1,
- int addr2, int addr3)
- {
- }
-
- public void Close()
- {
- }
-
- public void SetSymAttribute(SymbolToken parent, string name, byte[] data)
- {
- }
-
- public void OpenNamespace(string name)
- {
- }
-
- public void CloseNamespace()
- {
- }
-
- public void UsingNamespace(string fullName)
- {
- }
-
- public void SetMethodSourceRange(ISymbolDocumentWriter startDoc, int startLine, int startColumn, ISymbolDocumentWriter endDoc,
- int endLine, int endColumn)
- {
- }
-
- public void SetUnderlyingWriter(IntPtr underlyingWriter)
- {
- }
-
- public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
- {
- return new byte[0];
- }
-
- public void RemapToken(int oldToken, int newToken)
- {
- }
-
- public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1,
- int addr2, int addr3, int startOffset, int endOffset)
- {
- }
-
- public void OpenMethod(SymbolToken symbolToken, MethodBase mb)
- {
- }
-
- public bool IsDeterministic => true;
}
}
diff --git a/src/compiler/backend/ikvm/LICENSE b/src/compiler/backend/ikvm/LICENSE
deleted file mode 100644
index 4c8867424..000000000
--- a/src/compiler/backend/ikvm/LICENSE
+++ /dev/null
@@ -1,425 +0,0 @@
-IMPORTANT NOTICE
-
- Copyright (C) 1998-2008 Free Software Foundation, Inc.
- Copyright (C) 1996-2011 Oracle and/or its affiliates
- Copyright (C) 2002-2011 Jeroen Frijters
-
- Some files in this distribution are part of GNU Classpath or OpenJDK and
- are licensed under the GNU General Public License (GPL) version 2
- with "Classpath" exception. This applies in particular to:
- - IKVM.OpenJDK.*.dll
- - some of the *.java files (see each file header for license)
-
- See http://www.gnu.org/software/classpath/ for information on the
- GNU Classpath license and "Classpath" exception.
-
- See below for a full copy of the GPL license and the Sun version of the
- "Classpath" exception.
-
------------------------------------------------------------------------------
-
- Copyright (C) 2002-2011 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
------------------------------------------------------------------------------
-
-The GNU General Public License (GPL)
-
-Version 2, June 1991
-
-Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-Everyone is permitted to copy and distribute verbatim copies of this license
-document, but changing it is not allowed.
-
-Preamble
-
-The licenses for most software are designed to take away your freedom to share
-and change it. By contrast, the GNU General Public License is intended to
-guarantee your freedom to share and change free software--to make sure the
-software is free for all its users. This General Public License applies to
-most of the Free Software Foundation's software and to any other program whose
-authors commit to using it. (Some other Free Software Foundation software is
-covered by the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
-When we speak of free software, we are referring to freedom, not price. Our
-General Public Licenses are designed to make sure that you have the freedom to
-distribute copies of free software (and charge for this service if you wish),
-that you receive source code or can get it if you want it, that you can change
-the software or use pieces of it in new free programs; and that you know you
-can do these things.
-
-To protect your rights, we need to make restrictions that forbid anyone to deny
-you these rights or to ask you to surrender the rights. These restrictions
-translate to certain responsibilities for you if you distribute copies of the
-software, or if you modify it.
-
-For example, if you distribute copies of such a program, whether gratis or for
-a fee, you must give the recipients all the rights that you have. You must
-make sure that they, too, receive or can get the source code. And you must
-show them these terms so they know their rights.
-
-We protect your rights with two steps: (1) copyright the software, and (2)
-offer you this license which gives you legal permission to copy, distribute
-and/or modify the software.
-
-Also, for each author's protection and ours, we want to make certain that
-everyone understands that there is no warranty for this free software. If the
-software is modified by someone else and passed on, we want its recipients to
-know that what they have is not the original, so that any problems introduced
-by others will not reflect on the original authors' reputations.
-
-Finally, any free program is threatened constantly by software patents. We
-wish to avoid the danger that redistributors of a free program will
-individually obtain patent licenses, in effect making the program proprietary.
-To prevent this, we have made it clear that any patent must be licensed for
-everyone's free use or not licensed at all.
-
-The precise terms and conditions for copying, distribution and modification
-follow.
-
-TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-0. This License applies to any program or other work which contains a notice
-placed by the copyright holder saying it may be distributed under the terms of
-this General Public License. The "Program", below, refers to any such program
-or work, and a "work based on the Program" means either the Program or any
-derivative work under copyright law: that is to say, a work containing the
-Program or a portion of it, either verbatim or with modifications and/or
-translated into another language. (Hereinafter, translation is included
-without limitation in the term "modification".) Each licensee is addressed as
-"you".
-
-Activities other than copying, distribution and modification are not covered by
-this License; they are outside its scope. The act of running the Program is
-not restricted, and the output from the Program is covered only if its contents
-constitute a work based on the Program (independent of having been made by
-running the Program). Whether that is true depends on what the Program does.
-
-1. You may copy and distribute verbatim copies of the Program's source code as
-you receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice and
-disclaimer of warranty; keep intact all the notices that refer to this License
-and to the absence of any warranty; and give any other recipients of the
-Program a copy of this License along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and you may
-at your option offer warranty protection in exchange for a fee.
-
-2. You may modify your copy or copies of the Program or any portion of it, thus
-forming a work based on the Program, and copy and distribute such modifications
-or work under the terms of Section 1 above, provided that you also meet all of
-these conditions:
-
- a) You must cause the modified files to carry prominent notices stating
- that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in whole or
- in part contains or is derived from the Program or any part thereof, to be
- licensed as a whole at no charge to all third parties under the terms of
- this License.
-
- c) If the modified program normally reads commands interactively when run,
- you must cause it, when started running for such interactive use in the
- most ordinary way, to print or display an announcement including an
- appropriate copyright notice and a notice that there is no warranty (or
- else, saying that you provide a warranty) and that users may redistribute
- the program under these conditions, and telling the user how to view a copy
- of this License. (Exception: if the Program itself is interactive but does
- not normally print such an announcement, your work based on the Program is
- not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If identifiable
-sections of that work are not derived from the Program, and can be reasonably
-considered independent and separate works in themselves, then this License, and
-its terms, do not apply to those sections when you distribute them as separate
-works. But when you distribute the same sections as part of a whole which is a
-work based on the Program, the distribution of the whole must be on the terms
-of this License, whose permissions for other licensees extend to the entire
-whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest your
-rights to work written entirely by you; rather, the intent is to exercise the
-right to control the distribution of derivative or collective works based on
-the Program.
-
-In addition, mere aggregation of another work not based on the Program with the
-Program (or with a work based on the Program) on a volume of a storage or
-distribution medium does not bring the other work under the scope of this
-License.
-
-3. You may copy and distribute the Program (or a work based on it, under
-Section 2) in object code or executable form under the terms of Sections 1 and
-2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable source
- code, which must be distributed under the terms of Sections 1 and 2 above
- on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three years, to
- give any third party, for a charge no more than your cost of physically
- performing source distribution, a complete machine-readable copy of the
- corresponding source code, to be distributed under the terms of Sections 1
- and 2 above on a medium customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer to
- distribute corresponding source code. (This alternative is allowed only
- for noncommercial distribution and only if you received the program in
- object code or executable form with such an offer, in accord with
- Subsection b above.)
-
-The source code for a work means the preferred form of the work for making
-modifications to it. For an executable work, complete source code means all
-the source code for all modules it contains, plus any associated interface
-definition files, plus the scripts used to control compilation and installation
-of the executable. However, as a special exception, the source code
-distributed need not include anything that is normally distributed (in either
-source or binary form) with the major components (compiler, kernel, and so on)
-of the operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the source
-code from the same place counts as distribution of the source code, even though
-third parties are not compelled to copy the source along with the object code.
-
-4. You may not copy, modify, sublicense, or distribute the Program except as
-expressly provided under this License. Any attempt otherwise to copy, modify,
-sublicense or distribute the Program is void, and will automatically terminate
-your rights under this License. However, parties who have received copies, or
-rights, from you under this License will not have their licenses terminated so
-long as such parties remain in full compliance.
-
-5. You are not required to accept this License, since you have not signed it.
-However, nothing else grants you permission to modify or distribute the Program
-or its derivative works. These actions are prohibited by law if you do not
-accept this License. Therefore, by modifying or distributing the Program (or
-any work based on the Program), you indicate your acceptance of this License to
-do so, and all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-6. Each time you redistribute the Program (or any work based on the Program),
-the recipient automatically receives a license from the original licensor to
-copy, distribute or modify the Program subject to these terms and conditions.
-You may not impose any further restrictions on the recipients' exercise of the
-rights granted herein. You are not responsible for enforcing compliance by
-third parties to this License.
-
-7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues), conditions
-are imposed on you (whether by court order, agreement or otherwise) that
-contradict the conditions of this License, they do not excuse you from the
-conditions of this License. If you cannot distribute so as to satisfy
-simultaneously your obligations under this License and any other pertinent
-obligations, then as a consequence you may not distribute the Program at all.
-For example, if a patent license would not permit royalty-free redistribution
-of the Program by all those who receive copies directly or indirectly through
-you, then the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply and
-the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any patents or
-other property right claims or to contest validity of any such claims; this
-section has the sole purpose of protecting the integrity of the free software
-distribution system, which is implemented by public license practices. Many
-people have made generous contributions to the wide range of software
-distributed through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing to
-distribute software through any other system and a licensee cannot impose that
-choice.
-
-This section is intended to make thoroughly clear what is believed to be a
-consequence of the rest of this License.
-
-8. If the distribution and/or use of the Program is restricted in certain
-countries either by patents or by copyrighted interfaces, the original
-copyright holder who places the Program under this License may add an explicit
-geographical distribution limitation excluding those countries, so that
-distribution is permitted only in or among countries not thus excluded. In
-such case, this License incorporates the limitation as if written in the body
-of this License.
-
-9. The Free Software Foundation may publish revised and/or new versions of the
-General Public License from time to time. Such new versions will be similar in
-spirit to the present version, but may differ in detail to address new problems
-or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any later
-version", you have the option of following the terms and conditions either of
-that version or of any later version published by the Free Software Foundation.
-If the Program does not specify a version number of this License, you may
-choose any version ever published by the Free Software Foundation.
-
-10. If you wish to incorporate parts of the Program into other free programs
-whose distribution conditions are different, write to the author to ask for
-permission. For software which is copyrighted by the Free Software Foundation,
-write to the Free Software Foundation; we sometimes make exceptions for this.
-Our decision will be guided by the two goals of preserving the free status of
-all derivatives of our free software and of promoting the sharing and reuse of
-software generally.
-
-NO WARRANTY
-
-11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
-THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
-STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
-PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
-PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
-YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
-12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
-ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
-PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
-INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
-BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
-OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-END OF TERMS AND CONDITIONS
-
-How to Apply These Terms to Your New Programs
-
-If you develop a new program, and you want it to be of the greatest possible
-use to the public, the best way to achieve this is to make it free software
-which everyone can redistribute and change under these terms.
-
-To do so, attach the following notices to the program. It is safest to attach
-them to the start of each source file to most effectively convey the exclusion
-of warranty; and each file should have at least the "copyright" line and a
-pointer to where the full notice is found.
-
- One line to give the program's name and a brief idea of what it does.
-
- Copyright (C)
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2 of the License, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc., 59
- Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this when it
-starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
- with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
- software, and you are welcome to redistribute it under certain conditions;
- type 'show c' for details.
-
-The hypothetical commands 'show w' and 'show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may be
-called something other than 'show w' and 'show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your school,
-if any, to sign a "copyright disclaimer" for the program, if necessary. Here
-is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- 'Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- signature of Ty Coon, 1 April 1989
-
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General Public
-License instead of this License.
-
-
-"CLASSPATH" EXCEPTION TO THE GPL
-
-Certain source files distributed by Oracle America and/or its affiliates are
-subject to the following clarification and special exception to the GPL, but
-only where Oracle has expressly included in the particular source file's header
-the words "Oracle designates this particular file as subject to the "Classpath"
-exception as provided by Oracle in the LICENSE file that accompanied this code."
-
- Linking this library statically or dynamically with other modules is making
- a combined work based on this library. Thus, the terms and conditions of
- the GNU General Public License cover the whole combination.
-
- As a special exception, the copyright holders of this library give you
- permission to link this library with independent modules to produce an
- executable, regardless of the license terms of these independent modules,
- and to copy and distribute the resulting executable under terms of your
- choice, provided that you also meet, for each linked independent module,
- the terms and conditions of the license of that module. An independent
- module is a module which is not derived from or based on this library. If
- you modify this library, you may extend this exception to your version of
- the library, but you are not obligated to do so. If you do not wish to do
- so, delete this exception statement from your version.
-
------------------------------------------------------------------------------
-
- -------------------------------------------------------------------------
- $Id$
- -------------------------------------------------------------------------
- Copyright (c) 1999 Visual Numerics Inc. All Rights Reserved.
-
- Permission to use, copy, modify, and distribute this software is freely
- granted by Visual Numerics, Inc., provided that the copyright notice
- above and the following warranty disclaimer are preserved in human
- readable form.
-
- Because this software is licenses free of charge, it is provided
- "AS IS", with NO WARRANTY. TO THE EXTENT PERMITTED BY LAW, VNI
- DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- TO ITS PERFORMANCE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- VNI WILL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING OUT OF THE USE
- OF OR INABILITY TO USE THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT,
- INDIRECT, SPECIAL, CONSEQUENTIAL, PUNITIVE, AND EXEMPLARY DAMAGES, EVEN
- IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
- This Java code is based on C code in the package fdlibm,
- which can be obtained from www.netlib.org.
- The original fdlibm C code contains the following notice.
-
- Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
-
- Developed at SunSoft, a Sun Microsystems, Inc. business.
- Permission to use, copy, modify, and distribute this
- software is freely granted, provided that this notice
- is preserved.
-
------------------------------------------------------------------------------
diff --git a/src/compiler/backend/ikvm/LICENSE.md b/src/compiler/backend/ikvm/LICENSE.md
new file mode 100644
index 000000000..cffb3c54e
--- /dev/null
+++ b/src/compiler/backend/ikvm/LICENSE.md
@@ -0,0 +1,342 @@
+IMPORTANT NOTICE
+==========================
+
+ Copyright (C) 1998-2022 Free Software Foundation, Inc.\
+ Copyright (C) 1996-2022 Oracle and/or its affiliates\
+ Copyright (C) 2002-2022 Jeroen Frijters, Windward Studios, Jerome Haltom,
+ Shad Storhaug, and contributors.
+
+ Some files in this distribution are part of GNU Classpath or OpenJDK and
+ are licensed under the GNU General Public License (GPL) version 2
+ with "Classpath" exception. This applies in particular to:
+ - IKVM.Java.dll
+ - some of the *.java files (see each file header for license)
+
+ See http://www.gnu.org/software/classpath/ for information on the
+ GNU Classpath license and "Classpath" exception.
+
+ See below for a full copy of the GPL license and the Sun version of the
+ "Classpath" exception.
+
+IKVM
+==========================
+
+Copyright (C) 2002-2022 Jeroen Frijters, Windward Studios, Jerome Haltom,
+ Shad Storhaug, and contributors.
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+GNU General Public License
+==========================
+
+_Version 2, June 1991_
+_Copyright © 1989, 1991 Free Software Foundation, Inc.,_
+_51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA_
+
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+
+### Preamble
+
+The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+We protect your rights with two steps: **(1)** copyright the software, and
+**(2)** offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+The precise terms and conditions for copying, distribution and
+modification follow.
+
+### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+**0.** This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The “Program”, below,
+refers to any such program or work, and a “work based on the Program”
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term “modification”.) Each licensee is addressed as “you”.
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+**1.** You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+**2.** You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+* **a)** You must cause the modified files to carry prominent notices
+stating that you changed the files and the date of any change.
+* **b)** You must cause any work that you distribute or publish, that in
+whole or in part contains or is derived from the Program or any
+part thereof, to be licensed as a whole at no charge to all third
+parties under the terms of this License.
+* **c)** If the modified program normally reads commands interactively
+when run, you must cause it, when started running for such
+interactive use in the most ordinary way, to print or display an
+announcement including an appropriate copyright notice and a
+notice that there is no warranty (or else, saying that you provide
+a warranty) and that users may redistribute the program under
+these conditions, and telling the user how to view a copy of this
+License. (Exception: if the Program itself is interactive but
+does not normally print such an announcement, your work based on
+the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+**3.** You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+* **a)** Accompany it with the complete corresponding machine-readable
+source code, which must be distributed under the terms of Sections
+1 and 2 above on a medium customarily used for software interchange; or,
+* **b)** Accompany it with a written offer, valid for at least three
+years, to give any third party, for a charge no more than your
+cost of physically performing source distribution, a complete
+machine-readable copy of the corresponding source code, to be
+distributed under the terms of Sections 1 and 2 above on a medium
+customarily used for software interchange; or,
+* **c)** Accompany it with the information you received as to the offer
+to distribute corresponding source code. (This alternative is
+allowed only for noncommercial distribution and only if you
+received the program in object code or executable form with such
+an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+**4.** You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+**5.** You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+**6.** Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+**7.** If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+**8.** If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+**9.** The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and “any
+later version”, you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+**10.** If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+### NO WARRANTY
+
+**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+
+"CLASSPATH" EXCEPTION TO THE GPL
+
+Certain source files distributed by Oracle America and/or its affiliates are
+subject to the following clarification and special exception to the GPL, but
+only where Oracle has expressly included in the particular source file's header
+the words "Oracle designates this particular file as subject to the "Classpath"
+exception as provided by Oracle in the LICENSE file that accompanied this code."
+
+ Linking this library statically or dynamically with other modules is making
+ a combined work based on this library. Thus, the terms and conditions of
+ the GNU General Public License cover the whole combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent modules,
+ and to copy and distribute the resulting executable under terms of your
+ choice, provided that you also meet, for each linked independent module,
+ the terms and conditions of the license of that module. An independent
+ module is a module which is not derived from or based on this library. If
+ you modify this library, you may extend this exception to your version of
+ the library, but you are not obligated to do so. If you do not wish to do
+ so, delete this exception statement from your version.
+
diff --git a/src/compiler/backend/ikvm/MarshalSpec.cs b/src/compiler/backend/ikvm/MarshalSpec.cs
index 0370ada16..5e6bb67e9 100644
--- a/src/compiler/backend/ikvm/MarshalSpec.cs
+++ b/src/compiler/backend/ikvm/MarshalSpec.cs
@@ -21,19 +21,20 @@ Jeroen Frijters
jeroen@frijters.net
*/
-using System;
-using System.Collections.Generic;
+
using System.Runtime.InteropServices;
using System.Text;
+
using IKVM.Reflection.Emit;
+using IKVM.Reflection.Metadata;
using IKVM.Reflection.Reader;
using IKVM.Reflection.Writer;
-using IKVM.Reflection.Metadata;
namespace IKVM.Reflection
{
- public struct FieldMarshal
+ public struct FieldMarshal
{
+ private const UnmanagedType UnmanagedType_CustomMarshaler = (UnmanagedType)0x2c;
private const UnmanagedType NATIVE_TYPE_MAX = (UnmanagedType)0x50;
public UnmanagedType UnmanagedType;
public UnmanagedType? ArraySubType;
@@ -105,7 +106,7 @@ internal static bool ReadFieldMarshal(Module module, int token, out FieldMarshal
fm.IidParameterIndex = blob.ReadCompressedUInt();
}
}
- else if (fm.UnmanagedType == UnmanagedType.CustomMarshaler)
+ else if (fm.UnmanagedType == UnmanagedType_CustomMarshaler)
{
blob.ReadCompressedUInt();
blob.ReadCompressedUInt();
@@ -210,7 +211,7 @@ private static int WriteMarshallingDescriptor(ModuleBuilder module, CustomAttrib
bb.WriteCompressedUInt(iidParameterIndex.Value);
}
}
- else if (unmanagedType == UnmanagedType.CustomMarshaler)
+ else if (unmanagedType == UnmanagedType_CustomMarshaler)
{
bb.WriteCompressedUInt(0);
bb.WriteCompressedUInt(0);
diff --git a/src/compiler/backend/ikvm/Metadata/MetadataRW.cs b/src/compiler/backend/ikvm/Metadata/MetadataRW.cs
index d03c8d628..c498d28d7 100644
--- a/src/compiler/backend/ikvm/Metadata/MetadataRW.cs
+++ b/src/compiler/backend/ikvm/Metadata/MetadataRW.cs
@@ -73,8 +73,8 @@ protected MetadataRW(Module module, bool bigStrings, bool bigGuids, bool bigBlob
this.bigMemberRefParent = IsBig(3, module.TypeDef, module.TypeRef, module.ModuleRef, module.MethodDef, module.TypeSpec);
this.bigMethodDefOrRef = IsBig(1, module.MethodDef, module.MemberRef);
this.bigHasCustomAttribute = IsBig(5, module.MethodDef, module.Field, module.TypeRef, module.TypeDef, module.Param, module.InterfaceImpl, module.MemberRef,
- module.ModuleTable, /*module.Permission,*/ module.Property, module.Event, module.StandAloneSig, module.ModuleRef, module.TypeSpec, module.AssemblyTable,
- module.AssemblyRef, module.File, module.ExportedType, module.ManifestResource);
+ module.ModuleTable, module.DeclSecurity, module.Property, module.Event, module.StandAloneSig, module.ModuleRef, module.TypeSpec, module.AssemblyTable,
+ module.AssemblyRef, module.File, module.ExportedType, module.ManifestResource, module.GenericParam, module.GenericParamConstraint, module.MethodSpec);
this.bigCustomAttributeType = IsBig(3, module.MethodDef, module.MemberRef);
this.bigHasConstant = IsBig(2, module.Field, module.Param, module.Property);
this.bigHasSemantics = IsBig(1, module.Event, module.Property);
diff --git a/src/compiler/backend/ikvm/Metadata/Tables.cs b/src/compiler/backend/ikvm/Metadata/Tables.cs
index 32b6be086..2d53d0c70 100644
--- a/src/compiler/backend/ikvm/Metadata/Tables.cs
+++ b/src/compiler/backend/ikvm/Metadata/Tables.cs
@@ -450,28 +450,20 @@ public Enumerator GetEnumerator()
{
return new Enumerator(records, table.RowCount - 1, -1, token);
}
- var maskedToken = token & 0xFFFFFF;
- int index = BinarySearch(records, table.RowCount, maskedToken);
-
+ int index = BinarySearch(records, table.RowCount, token & 0xFFFFFF);
if (index < 0)
{
return new Enumerator(null, 0, 1, -1);
}
int start = index;
- while (start > 0)
+ while (start > 0 && (records[start - 1].FilterKey & 0xFFFFFF) == (token & 0xFFFFFF))
{
- var maskedFilterKey = records [start - 1].FilterKey & 0xFFFFFF;
- if (maskedFilterKey != maskedToken && maskedFilterKey != 0)
- break;
start--;
}
int end = index;
int max = table.RowCount - 1;
- while (end < max)
+ while (end < max && (records[end + 1].FilterKey & 0xFFFFFF) == (token & 0xFFFFFF))
{
- var maskedFilterKey = records [end + 1].FilterKey & 0xFFFFFF;
- if (maskedFilterKey != maskedToken && maskedFilterKey != 0)
- break;
end++;
}
return new Enumerator(records, end, start - 1, token);
@@ -489,13 +481,6 @@ private static int BinarySearch(T[] records, int length, int maskedToken)
{
return mid;
}
- else if (maskedValue == 0)
- {
- if (min > 0)
- min--;
- if (max < length - 1)
- max++;
- }
else if (maskedToken < maskedValue)
{
max = mid - 1;
@@ -1212,6 +1197,8 @@ internal void Fixup(ModuleBuilder moduleBuilder)
{
records[i].Parent = (GenericParamTable.Index << 24) + genericParamFixup[(records[i].Parent & 0xFFFFFF) - 1] + 1;
}
+ // TODO if we ever add support for custom attributes on DeclSecurity or GenericParamConstraint
+ // we need to fix them up here (because they are sorted tables, like GenericParam)
}
Sort();
}
@@ -1236,7 +1223,10 @@ internal static int EncodeHasCustomAttribute(int token)
return (token & 0xFFFFFF) << 5 | 6;
case ModuleTable.Index:
return (token & 0xFFFFFF) << 5 | 7;
- // Permission (8) table doesn't exist in the spec
+ // LAMESPEC spec calls this Permission table
+ case DeclSecurityTable.Index:
+ //return (token & 0xFFFFFF) << 5 | 8;
+ throw new NotImplementedException();
case PropertyTable.Index:
return (token & 0xFFFFFF) << 5 | 9;
case EventTable.Index:
@@ -1260,7 +1250,10 @@ internal static int EncodeHasCustomAttribute(int token)
case GenericParamTable.Index:
return (token & 0xFFFFFF) << 5 | 19;
case GenericParamConstraintTable.Index:
- return (token & 0xFFFFFF) << 5 | 20;
+ //return (token & 0xFFFFFF) << 5 | 20;
+ throw new NotImplementedException();
+ case MethodSpecTable.Index:
+ return (token & 0xFFFFFF) << 5 | 21;
default:
throw new InvalidOperationException();
}
@@ -2736,287 +2729,4 @@ internal void Fixup(ModuleBuilder moduleBuilder)
Sort();
}
}
-
- // Portable PDB
- sealed class DocumentTable : Table
- {
- internal const int Index = 0x30;
-
- internal static Guid SHA1Guid = new Guid("ff1816ec-aa5e-4d10-87f7-6f4963833460");
- internal static Guid CSharpGuid = new Guid("3f5162f8-07c6-11d3-9053-00c04fa302a1");
-
- internal struct Record
- {
- internal int Name; // -> StringHeap
- internal int HashAlgorithm; // -> GuidHeap
- internal int Hash; // -> BlobHeap
- internal int Language; // -> GuidHeap
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- records[i].Name = mr.ReadBlobIndex();
- records[i].HashAlgorithm = mr.ReadGuidIndex();
- records[i].Hash = mr.ReadBlobIndex();
- records[i].Language = mr.ReadGuidIndex();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- return rsc
- .WriteStringIndex()
- .WriteGuidIndex()
- .WriteBlobIndex()
- .WriteGuidIndex()
- .Value;
- }
- }
-
- // Portable PDB
- sealed class MethodDebugInformationTable : Table
- {
- internal const int Index = 0x31;
-
- internal struct Record
- {
- internal int Document; // -> Document table
- internal int SequencePoints; // -> BlobHeap
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- // FIXME: Token size
- records[i].Document = mr.ReadInt16 ();
- records[i].SequencePoints = mr.ReadBlobIndex();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- return rsc
- .WriteBlobIndex()
- .Value;
- }
- }
-
- // Portable PDB
- // FIXME: Sorted
- sealed class LocalScopeTable : Table
- {
- internal const int Index = 0x32;
-
- internal struct Record
- {
- internal int Method;
- internal int ImportScope;
- internal int VariableList;
- internal int ConstantList;
- internal uint StartOffset;
- internal uint Length;
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- // FIXME: Token sizes ?
- records[i].Method = mr.ReadInt16();
- records[i].ImportScope = mr.ReadInt16();
- records[i].VariableList = mr.ReadInt16();
- records[i].ConstantList = mr.ReadInt16();
- records[i].StartOffset = (uint)mr.ReadInt32();
- records[i].Length = (uint)mr.ReadInt32();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- throw new NotImplementedException();
- }
- }
-
- // Portable PDB
- sealed class LocalVariableTable : Table
- {
- internal const int Index = 0x33;
-
- internal enum LocalVariableAttributes {
- DebuggerHidden = 0x1
- }
-
- internal struct Record
- {
- internal int Attributes;
- internal int Index;
- internal int Name; // -> StringHeap
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- records[i].Attributes = mr.ReadInt16();
- records[i].Index = mr.ReadInt16();
- records[i].Name = mr.ReadStringIndex();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- throw new NotImplementedException();
- }
- }
-
- // Portable PDB
- sealed class LocalConstantTable : Table
- {
- internal const int Index = 0x34;
-
- internal struct Record
- {
- internal int Name; // -> StringHeap
- internal int Signature; // -> BlobHeap
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- records[i].Name = mr.ReadStringIndex();
- records[i].Signature = mr.ReadBlobIndex();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- throw new NotImplementedException();
- }
- }
-
- // Portable PDB
- sealed class ImportScopeTable : Table
- {
- internal const int Index = 0x35;
-
- internal struct Record
- {
- internal int Parent;
- internal int Imports; // -> BlobHeap
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- // FIXME: Token size
- records[i].Parent = mr.ReadUInt16();
- records[i].Imports = mr.ReadBlobIndex();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- throw new NotImplementedException();
- }
- }
-
- // Portable PDB
- sealed class StateMachineTable : Table
- {
- internal const int Index = 0x36;
-
- internal struct Record
- {
- internal int MoveNextMethod;
- internal int KickoffMethod;
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- records[i].MoveNextMethod = mr.ReadUInt16();
- records[i].KickoffMethod = mr.ReadUInt16();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- throw new NotImplementedException();
- }
- }
-
- // Portable PDB
- sealed class CustomDebugInformationTable : Table
- {
- internal const int Index = 0x37;
-
- internal struct Record
- {
- internal int Parent;
- internal int Kind; // -> GuidHeap
- internal int Value; // -> BlobHeap
- }
-
- internal override void Read(MetadataReader mr)
- {
- for (int i = 0; i < records.Length; i++)
- {
- // FIXME: Token size
- records[i].Parent = mr.ReadUInt16();
- records[i].Kind = mr.ReadBlobIndex();
- records[i].Value = mr.ReadBlobIndex();
- }
- }
-
- internal override void Write(MetadataWriter mw)
- {
- throw new NotImplementedException ();
- }
-
- protected override int GetRowSize(RowSizeCalc rsc)
- {
- throw new NotImplementedException();
- }
- }
}
diff --git a/src/compiler/backend/ikvm/MethodSignature.cs b/src/compiler/backend/ikvm/MethodSignature.cs
index 1d51421f2..189f13b28 100644
--- a/src/compiler/backend/ikvm/MethodSignature.cs
+++ b/src/compiler/backend/ikvm/MethodSignature.cs
@@ -146,7 +146,7 @@ internal static __StandAloneMethodSig ReadStandAloneMethodSig(ModuleReader modul
System.Runtime.InteropServices.CallingConvention unmanagedCallingConvention = 0;
bool unmanaged;
byte flags = br.ReadByte();
- switch (flags & 0xf)
+ switch (flags & 7)
{
case DEFAULT:
callingConvention = CallingConventions.Standard;
@@ -168,10 +168,6 @@ internal static __StandAloneMethodSig ReadStandAloneMethodSig(ModuleReader modul
unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
unmanaged = true;
break;
- case 0x09: // UNMANAGED
- unmanagedCallingConvention = (System.Runtime.InteropServices.CallingConvention)0x9;
- unmanaged = true;
- break;
case VARARG:
callingConvention = CallingConventions.VarArgs;
unmanaged = false;
diff --git a/src/compiler/backend/ikvm/Missing.cs b/src/compiler/backend/ikvm/Missing.cs
index 9510ded3d..5f6eb7880 100644
--- a/src/compiler/backend/ikvm/Missing.cs
+++ b/src/compiler/backend/ikvm/Missing.cs
@@ -27,14 +27,10 @@ Jeroen Frijters
namespace IKVM.Reflection
{
-#if !CORECLR
[Serializable]
-#endif
public sealed class MissingAssemblyException : InvalidOperationException
{
-#if !CORECLR
[NonSerialized]
-#endif
private readonly MissingAssembly assembly;
internal MissingAssemblyException(MissingAssembly assembly)
@@ -43,12 +39,10 @@ internal MissingAssemblyException(MissingAssembly assembly)
this.assembly = assembly;
}
-#if !CORECLR
private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
-#endif
public Assembly Assembly
{
@@ -56,14 +50,10 @@ public Assembly Assembly
}
}
-#if !CORECLR
[Serializable]
-#endif
public sealed class MissingModuleException : InvalidOperationException
{
-#if !CORECLR
[NonSerialized]
-#endif
private readonly MissingModule module;
internal MissingModuleException(MissingModule module)
@@ -72,12 +62,10 @@ internal MissingModuleException(MissingModule module)
this.module = module;
}
-#if !CORECLR
private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
-#endif
public Module Module
{
@@ -85,14 +73,10 @@ public Module Module
}
}
-#if !CORECLR
[Serializable]
-#endif
public sealed class MissingMemberException : InvalidOperationException
{
-#if !CORECLR
[NonSerialized]
-#endif
private readonly MemberInfo member;
internal MissingMemberException(MemberInfo member)
@@ -101,12 +85,10 @@ internal MissingMemberException(MemberInfo member)
this.member = member;
}
-#if !CORECLR
private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
-#endif
public MemberInfo MemberInfo
{
@@ -399,6 +381,7 @@ sealed class MissingType : Type
private int token;
private int flags;
private bool cyclicTypeForwarder;
+ private bool cyclicTypeSpec;
internal MissingType(Module module, Type declaringType, string ns, string name)
{
@@ -479,7 +462,7 @@ public override int MetadataToken
get { return token; }
}
- public override bool IsValueType
+ protected override bool IsValueTypeImpl
{
get
{
@@ -621,6 +604,12 @@ internal override Type SetCyclicTypeForwarder()
return this;
}
+ internal override Type SetCyclicTypeSpec()
+ {
+ this.cyclicTypeSpec = true;
+ return this;
+ }
+
internal override bool IsBaked
{
get { throw new MissingMemberException(this); }
@@ -636,6 +625,11 @@ public override bool __IsCyclicTypeForwarder
{
get { return cyclicTypeForwarder; }
}
+
+ public override bool __IsCyclicTypeSpec
+ {
+ get { return cyclicTypeSpec; }
+ }
}
sealed class MissingTypeParameter : IKVM.Reflection.Reader.TypeParameterType
diff --git a/src/compiler/backend/ikvm/Module.cs b/src/compiler/backend/ikvm/Module.cs
index 23c14057a..f6a2aa9b8 100644
--- a/src/compiler/backend/ikvm/Module.cs
+++ b/src/compiler/backend/ikvm/Module.cs
@@ -156,16 +156,8 @@ public abstract class Module : ICustomAttributeProvider
internal readonly GenericParamTable GenericParam = new GenericParamTable();
internal readonly MethodSpecTable MethodSpec = new MethodSpecTable();
internal readonly GenericParamConstraintTable GenericParamConstraint = new GenericParamConstraintTable();
- internal readonly DocumentTable Document = new DocumentTable();
- internal readonly MethodDebugInformationTable MethodDebugInformation = new MethodDebugInformationTable();
- internal readonly LocalScopeTable LocalScope = new LocalScopeTable();
- internal readonly LocalVariableTable LocalVariable = new LocalVariableTable();
- internal readonly LocalConstantTable LocalConstant = new LocalConstantTable();
- internal readonly ImportScopeTable ImportScope = new ImportScopeTable();
- internal readonly StateMachineTable StateMachine = new StateMachineTable();
- internal readonly CustomDebugInformationTable CustomDebugInformation = new CustomDebugInformationTable();
- protected Module(Universe universe)
+ internal Module(Universe universe)
{
this.universe = universe;
}
@@ -212,14 +204,6 @@ internal Table[] GetTables()
tables[GenericParamTable.Index] = GenericParam;
tables[MethodSpecTable.Index] = MethodSpec;
tables[GenericParamConstraintTable.Index] = GenericParamConstraint;
- tables[DocumentTable.Index] = Document;
- tables[MethodDebugInformationTable.Index] = MethodDebugInformation;
- tables[LocalScopeTable.Index] = LocalScope;
- tables[LocalVariableTable.Index] = LocalVariable;
- tables[LocalConstantTable.Index] = LocalConstant;
- tables[ImportScopeTable.Index] = ImportScope;
- tables[StateMachineTable.Index] = StateMachine;
- tables[CustomDebugInformationTable.Index] = CustomDebugInformation;
return tables;
}
@@ -568,11 +552,6 @@ public virtual string __ImageRuntimeVersion
get { throw new NotSupportedException(); }
}
- public virtual bool __IsMetadataOnly
- {
- get { throw new NotSupportedException(); }
- }
-
public IEnumerable __EnumerateCustomAttributeTable()
{
List list = new List(CustomAttribute.RowCount);
@@ -615,8 +594,6 @@ public virtual System.Security.Cryptography.X509Certificates.X509Certificate Get
internal abstract ByteReader GetBlob(int blobIndex);
- internal abstract Guid GetGuid(int guidIndex);
-
internal IList GetDeclarativeSecurity(int metadataToken)
{
List list = new List();
@@ -673,11 +650,6 @@ internal sealed override ByteReader GetBlob(int blobIndex)
throw InvalidOperationException();
}
- internal sealed override Guid GetGuid(int guidIndex)
- {
- throw InvalidOperationException();
- }
-
public sealed override AssemblyName[] __GetReferencedAssemblies()
{
throw NotSupportedException();
diff --git a/src/compiler/backend/ikvm/Projection.cs b/src/compiler/backend/ikvm/Projection.cs
index d38f9e2bd..49c7ad99c 100644
--- a/src/compiler/backend/ikvm/Projection.cs
+++ b/src/compiler/backend/ikvm/Projection.cs
@@ -159,7 +159,7 @@ internal static void Patch(ModuleReader module, Dictionary strings,
}
else
{
- Assembly mscorlib = module.universe.Mscorlib;
+ Assembly mscorlib = module.universe.CoreLib;
imageRuntimeVersion = mscorlib.__IsMissing ? "v4.0.30319" : mscorlib.ImageRuntimeVersion;
}
@@ -454,7 +454,7 @@ private int GetString(string str)
private Version GetMscorlibVersion()
{
- Assembly mscorlib = module.universe.Mscorlib;
+ Assembly mscorlib = module.universe.CoreLib;
return mscorlib.__IsMissing ? new Version(4, 0, 0, 0) : mscorlib.GetName().Version;
}
diff --git a/src/compiler/backend/ikvm/Properties/AssemblyInfo.cs b/src/compiler/backend/ikvm/Properties/AssemblyInfo.cs
deleted file mode 100644
index f453241e6..000000000
--- a/src/compiler/backend/ikvm/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- Copyright (C) 2008 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
-using System.Reflection;
-
-[assembly: AssemblyTitle("IKVM.Reflection")]
-[assembly: AssemblyDescription("Alternative implementation of System.Reflection[.Emit]")]
diff --git a/src/compiler/backend/ikvm/Reader/AssemblyReader.cs b/src/compiler/backend/ikvm/Reader/AssemblyReader.cs
index 868ec2c71..11dc8569d 100644
--- a/src/compiler/backend/ikvm/Reader/AssemblyReader.cs
+++ b/src/compiler/backend/ikvm/Reader/AssemblyReader.cs
@@ -29,8 +29,10 @@ Jeroen Frijters
namespace IKVM.Reflection.Reader
{
+
sealed class AssemblyReader : Assembly
{
+
private const int ContainsNoMetaData = 0x0001;
private readonly string location;
private readonly ModuleReader manifestModule;
@@ -69,11 +71,11 @@ private AssemblyName GetNameImpl(ref AssemblyTable.Record rec)
}
if (rec.Culture != 0)
{
- name.Culture = manifestModule.GetString(rec.Culture);
+ name.CultureName = manifestModule.GetString(rec.Culture);
}
else
{
- name.Culture = "";
+ name.CultureName = "";
}
name.HashAlgorithm = (AssemblyHashAlgorithm)rec.HashAlgId;
name.CodeBase = this.CodeBase;
diff --git a/src/compiler/backend/ikvm/Reader/Authenticode.cs b/src/compiler/backend/ikvm/Reader/Authenticode.cs
index 5dff8cfb7..ab17dfdb9 100644
--- a/src/compiler/backend/ikvm/Reader/Authenticode.cs
+++ b/src/compiler/backend/ikvm/Reader/Authenticode.cs
@@ -75,8 +75,7 @@ internal static X509Certificate GetSignerCertificate(Stream stream)
{
return null;
}
- byte[] buf = new byte[certificateTableLength - 8];
- stream.Read(buf, 0, buf.Length);
+ byte[] buf = br.ReadBytes(certificateTableLength - 8);
SignedCms cms = new SignedCms();
try
@@ -113,32 +112,14 @@ internal static X509Certificate GetSignerCertificate(Stream stream)
private static byte[] ComputeHashWithSkip(Stream stream, string hashAlgorithm, int[] skipOffsets, int[] skipLengths)
{
- using (HashAlgorithm hash = HashAlgorithm.Create(hashAlgorithm))
+ stream.Position = 0;
+ for (int i = skipOffsets.Length - 1; i >= 0; i--)
{
- using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
- {
- stream.Seek(0, SeekOrigin.Begin);
- byte[] buf = new byte[8192];
- HashChunk(stream, cs, buf, skipOffsets[0]);
- stream.Seek(skipLengths[0], SeekOrigin.Current);
- for (int i = 1; i < skipOffsets.Length; i++)
- {
- HashChunk(stream, cs, buf, skipOffsets[i] - (skipOffsets[i - 1] + skipLengths[i - 1]));
- stream.Seek(skipLengths[i], SeekOrigin.Current);
- }
- HashChunk(stream, cs, buf, (int)stream.Length - (skipOffsets[skipOffsets.Length - 1] + skipLengths[skipLengths.Length - 1]));
- }
- return hash.Hash;
+ stream = new IKVM.Reflection.Writer.SkipStream(stream, skipOffsets[i], skipLengths[i]);
}
- }
-
- private static void HashChunk(Stream stream, CryptoStream cs, byte[] buf, int length)
- {
- while (length > 0)
+ using (HashAlgorithm hash = HashAlgorithm.Create(hashAlgorithm))
{
- int read = stream.Read(buf, 0, Math.Min(buf.Length, length));
- cs.Write(buf, 0, read);
- length -= read;
+ return hash.ComputeHash(stream);
}
}
diff --git a/src/compiler/backend/ikvm/Reader/GenericTypeParameter.cs b/src/compiler/backend/ikvm/Reader/GenericTypeParameter.cs
index e03056690..805d5b2c0 100644
--- a/src/compiler/backend/ikvm/Reader/GenericTypeParameter.cs
+++ b/src/compiler/backend/ikvm/Reader/GenericTypeParameter.cs
@@ -40,7 +40,7 @@ public sealed override string AssemblyQualifiedName
get { return null; }
}
- public sealed override bool IsValueType
+ protected sealed override bool IsValueTypeImpl
{
get { return (this.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0; }
}
diff --git a/src/compiler/backend/ikvm/Reader/MetadataReader.cs b/src/compiler/backend/ikvm/Reader/MetadataReader.cs
index 7d7cf6692..420c2cddc 100644
--- a/src/compiler/backend/ikvm/Reader/MetadataReader.cs
+++ b/src/compiler/backend/ikvm/Reader/MetadataReader.cs
@@ -203,7 +203,7 @@ internal int ReadHasCustomAttribute()
case 7:
return (ModuleTable.Index << 24) + (codedIndex >> 5);
case 8:
- throw new BadImageFormatException();
+ return (DeclSecurityTable.Index << 24) + (codedIndex >> 5);
case 9:
return (PropertyTable.Index << 24) + (codedIndex >> 5);
case 10:
@@ -228,6 +228,8 @@ internal int ReadHasCustomAttribute()
return (GenericParamTable.Index << 24) + (codedIndex >> 5);
case 20:
return (GenericParamConstraintTable.Index << 24) + (codedIndex >> 5);
+ case 21:
+ return (MethodSpecTable.Index << 24) + (codedIndex >> 5);
default:
throw new BadImageFormatException();
}
diff --git a/src/compiler/backend/ikvm/Reader/Method.cs b/src/compiler/backend/ikvm/Reader/Method.cs
index d94f0197f..fbbe16be5 100644
--- a/src/compiler/backend/ikvm/Reader/Method.cs
+++ b/src/compiler/backend/ikvm/Reader/Method.cs
@@ -139,7 +139,7 @@ public override Type ReturnType
{
get
{
- return this.ReturnParameter.ParameterType;
+ return this.MethodSignature.GetReturnType(this);
}
}
diff --git a/src/compiler/backend/ikvm/Reader/ModuleReader.cs b/src/compiler/backend/ikvm/Reader/ModuleReader.cs
index acfda64e3..fb2d6e863 100644
--- a/src/compiler/backend/ikvm/Reader/ModuleReader.cs
+++ b/src/compiler/backend/ikvm/Reader/ModuleReader.cs
@@ -52,13 +52,6 @@ internal void Read(BinaryReader br)
}
}
- // FIXME: Put this somewhere else
- class PdbStream {
- public int EntryPoint { get; set; }
- public ulong ReferencedTables { get; set; }
- public int[] TableSizes { get; set; }
- }
-
sealed class ModuleReader : Module
{
private readonly Stream stream;
@@ -85,7 +78,6 @@ sealed class ModuleReader : Module
private Dictionary strings = new Dictionary();
private Dictionary types = new Dictionary();
private Dictionary forwardedTypes = new Dictionary();
- private bool isMetadataOnly;
private sealed class LazyForwardedType
{
@@ -100,14 +92,14 @@ internal LazyForwardedType(int index)
internal Type GetType(ModuleReader module)
{
// guard against circular type forwarding
- if (type == MarkerType.Pinned)
+ if (type == MarkerType.LazyResolveInProgress)
{
TypeName typeName = module.GetTypeName(module.ExportedType.records[index].TypeNamespace, module.ExportedType.records[index].TypeName);
return module.universe.GetMissingTypeOrThrow(module, module, null, typeName).SetCyclicTypeForwarder();
}
else if (type == null)
{
- type = MarkerType.Pinned;
+ type = MarkerType.LazyResolveInProgress;
type = module.ResolveExportedType(index);
}
return type;
@@ -134,23 +126,10 @@ internal ModuleReader(AssemblyReader assembly, Universe universe, Stream stream,
private void Read(Stream stream, bool mapped)
{
BinaryReader br = new BinaryReader(stream);
-
- long pos = stream.Position;
- uint header = br.ReadUInt32();
- stream.Seek(pos, SeekOrigin.Begin);
-
- if (header == 0x424a5342)
- {
- // Naked metadata file (enc/portable pdb)
- this.isMetadataOnly = true;
- }
- else
- {
- peFile.Read(br, mapped);
- stream.Seek(peFile.RvaToFileOffset(peFile.GetComDescriptorVirtualAddress()), SeekOrigin.Begin);
- cliHeader.Read(br);
- stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress), SeekOrigin.Begin);
- }
+ peFile.Read(br, mapped);
+ stream.Seek(peFile.RvaToFileOffset(peFile.GetComDescriptorVirtualAddress()), SeekOrigin.Begin);
+ cliHeader.Read(br);
+ stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress), SeekOrigin.Begin);
foreach (StreamHeader sh in ReadStreamHeaders(br, out imageRuntimeVersion))
{
switch (sh.Name)
@@ -170,26 +149,9 @@ private void Read(Stream stream, bool mapped)
break;
case "#~":
case "#-":
- if (isMetadataOnly)
- {
- stream.Seek(sh.Offset, SeekOrigin.Begin);
- }
- else
- {
- stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + sh.Offset), SeekOrigin.Begin);
- }
+ stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + sh.Offset), SeekOrigin.Begin);
ReadTables(br);
break;
- case "#Pdb":
- var entryPoint = br.ReadInt32 ();
- var referencedTables = br.ReadUInt64 ();
- var tableSizes = new int [64];
- for (int i = 0; i < 64; ++i) {
- if ((referencedTables & ((ulong)1 << i)) != 0)
- tableSizes [i] = (int)br.ReadUInt32 ();
- }
- /*pdbStream =*/ new PdbStream () { EntryPoint = entryPoint, ReferencedTables = referencedTables, TableSizes = tableSizes };
- break;
default:
// we ignore unknown streams, because the CLR does so too
// (and some obfuscators add bogus streams)
@@ -242,10 +204,6 @@ private void ReadTables(BinaryReader br)
{
if ((Valid & (1UL << i)) != 0)
{
- if (tables[i] == null)
- {
- throw new NotImplementedException ("Unknown table " + i);
- }
tables[i].Sorted = (Sorted & (1UL << i)) != 0;
tables[i].RowCount = br.ReadInt32();
}
@@ -267,14 +225,7 @@ private void ReadTables(BinaryReader br)
private byte[] ReadHeap(Stream stream, uint offset, uint size)
{
byte[] buf = new byte[size];
- if (isMetadataOnly)
- {
- stream.Seek(offset, SeekOrigin.Begin);
- }
- else
- {
- stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + offset), SeekOrigin.Begin);
- }
+ stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + offset), SeekOrigin.Begin);
for (int pos = 0; pos < buf.Length; )
{
int read = stream.Read(buf, pos, buf.Length - pos);
@@ -398,13 +349,6 @@ internal override ByteReader GetBlob(int blobIndex)
return ByteReader.FromBlob(blobHeap, blobIndex);
}
- internal override Guid GetGuid(int guidIndex)
- {
- byte[] buf = new byte[16];
- Buffer.BlockCopy(guidHeap, 16 * (guidIndex - 1), buf, 0, 16);
- return new Guid(buf);
- }
-
public override string ResolveString(int metadataToken)
{
string str;
@@ -508,12 +452,30 @@ internal override Type ResolveType(int metadataToken, IGenericContext context)
if (type == null)
{
TrackingGenericContext tc = context == null ? null : new TrackingGenericContext(context);
- type = Signature.ReadTypeSpec(this, ByteReader.FromBlob(blobHeap, TypeSpec.records[index]), tc);
+ typeSpecs[index] = MarkerType.LazyResolveInProgress;
+ try
+ {
+ type = Signature.ReadTypeSpec(this, ByteReader.FromBlob(blobHeap, TypeSpec.records[index]), tc);
+ }
+ finally
+ {
+ typeSpecs[index] = null;
+ }
if (tc == null || !tc.IsUsed)
{
typeSpecs[index] = type;
}
}
+ else if (type == MarkerType.LazyResolveInProgress)
+ {
+ if (universe.MissingMemberResolution)
+ {
+ return universe.GetMissingTypeOrThrow(this, this, null, new TypeName(null, "Cyclic TypeSpec " + metadataToken.ToString("X")))
+ .SetCyclicTypeSpec()
+ .SetMetadataTokenForMissing(metadataToken, 0);
+ }
+ throw new BadImageFormatException("Cyclic TypeSpec " + metadataToken.ToString("X"));
+ }
return type;
}
else
@@ -931,11 +893,7 @@ private MemberInfo ResolveTypeMemberRef(Type type, string name, ByteReader sig)
{
return field;
}
-#if CORECLR
- throw new MissingFieldException(org.ToString() + "." + name);
-#else
throw new MissingFieldException(org.ToString(), name);
-#endif
}
else
{
@@ -954,11 +912,7 @@ private MemberInfo ResolveTypeMemberRef(Type type, string name, ByteReader sig)
{
return method;
}
-#if CORECLR
- throw new MissingMethodException(org.ToString() + "." + name);
-#else
throw new MissingMethodException(org.ToString(), name);
-#endif
}
}
@@ -1051,7 +1005,7 @@ internal Stream GetManifestResourceStream(string resourceName)
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
if (fs.Length == 0)
{
- fs.Close();
+ fs.Dispose();
return null;
}
return fs;
@@ -1108,11 +1062,11 @@ public override AssemblyName[] __GetReferencedAssemblies()
}
if (AssemblyRef.records[i].Culture != 0)
{
- name.Culture = GetString(AssemblyRef.records[i].Culture);
+ name.CultureName = GetString(AssemblyRef.records[i].Culture);
}
else
{
- name.Culture = "";
+ name.CultureName = "";
}
if (AssemblyRef.records[i].HashValue != 0)
{
@@ -1205,17 +1159,8 @@ public override int MDStreamVersion
get { return metadataStreamVersion; }
}
- public override bool __IsMetadataOnly
- {
- get { return isMetadataOnly; }
- }
-
public override void __GetDataDirectoryEntry(int index, out int rva, out int length)
{
- if (isMetadataOnly)
- {
- throw new NotSupportedException();
- }
peFile.GetDataDirectoryEntry(index, out rva, out length);
}
@@ -1319,7 +1264,7 @@ internal override void Dispose()
{
if (stream != null)
{
- stream.Close();
+ stream.Dispose();
}
}
diff --git a/src/compiler/backend/ikvm/Reader/TypeDefImpl.cs b/src/compiler/backend/ikvm/Reader/TypeDefImpl.cs
index 61880851c..094620774 100644
--- a/src/compiler/backend/ikvm/Reader/TypeDefImpl.cs
+++ b/src/compiler/backend/ikvm/Reader/TypeDefImpl.cs
@@ -41,8 +41,7 @@ internal TypeDefImpl(ModuleReader module, int index)
{
this.module = module;
this.index = index;
- // empty typeName is not allowed, but obfuscators...
- this.typeName = module.GetString(module.TypeDef.records[index].TypeName) ?? "";
+ this.typeName = module.GetString(module.TypeDef.records[index].TypeName);
this.typeNamespace = module.GetString(module.TypeDef.records[index].TypeNamespace);
MarkKnownType(typeNamespace, typeName);
}
@@ -374,5 +373,23 @@ internal override bool IsBaked
{
get { return true; }
}
+
+ protected override bool IsValueTypeImpl
+ {
+ get
+ {
+ Type baseType = this.BaseType;
+ if (baseType != null && baseType.IsEnumOrValueType && !this.IsEnumOrValueType)
+ {
+ typeFlags |= TypeFlags.ValueType;
+ return true;
+ }
+ else
+ {
+ typeFlags |= TypeFlags.NotValueType;
+ return false;
+ }
+ }
+ }
}
}
diff --git a/src/compiler/backend/ikvm/StrongNameKeyPair.cs b/src/compiler/backend/ikvm/StrongNameKeyPair.cs
index 1e17bc4e8..cf088d9e7 100644
--- a/src/compiler/backend/ikvm/StrongNameKeyPair.cs
+++ b/src/compiler/backend/ikvm/StrongNameKeyPair.cs
@@ -23,11 +23,12 @@ Jeroen Frijters
*/
using System;
using System.IO;
+using System.Runtime.Versioning;
using System.Security.Cryptography;
namespace IKVM.Reflection
{
- public sealed class StrongNameKeyPair
+ public sealed class StrongNameKeyPair
{
private readonly byte[] keyPairArray;
private readonly string keyPairContainer;
@@ -38,10 +39,12 @@ public StrongNameKeyPair(string keyPairContainer)
{
throw new ArgumentNullException("keyPairContainer");
}
+
if (Universe.MonoRuntime && Environment.OSVersion.Platform == PlatformID.Win32NT)
{
throw new NotSupportedException("IKVM.Reflection does not support key containers when running on Mono");
}
+
this.keyPairContainer = keyPairContainer;
}
@@ -74,7 +77,7 @@ public byte[] PublicKey
{
get
{
-#if !CORECLR
+#if !NET6_0_OR_GREATER
if (Universe.MonoRuntime)
{
// MONOBUG workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=5299
@@ -83,7 +86,8 @@ public byte[] PublicKey
#endif
using (RSACryptoServiceProvider rsa = CreateRSA())
{
- byte[] cspBlob = rsa.ExportCspBlob(false);
+ var rsaParameters = rsa.ExportParameters(false);
+ byte[] cspBlob = ExportPublicKey(rsaParameters);
byte[] publicKey = new byte[12 + cspBlob.Length];
Buffer.BlockCopy(cspBlob, 0, publicKey, 12, cspBlob.Length);
publicKey[1] = 36;
@@ -105,9 +109,17 @@ internal RSACryptoServiceProvider CreateRSA()
if (keyPairArray != null)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
- rsa.ImportCspBlob(keyPairArray);
+ // we import from parameters, as using ImportCspBlob
+ // causes the exception "KeySet not found" when signing a hash later.
+ rsa.ImportParameters(RSAParametersFromByteArray(keyPairArray));
return rsa;
}
+#if NET6_0_OR_GREATER
+ else if (!OperatingSystem.IsWindows())
+ {
+ throw new NotSupportedException();
+ }
+#endif
else
{
CspParameters parm = new CspParameters();
@@ -127,8 +139,114 @@ internal RSACryptoServiceProvider CreateRSA()
}
}
-#if !CORECLR
- [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
+ // helper functions ExportPublicKey, RSAParametersFromStream and RSAParametersFromByteArray
+ // based on code in the following article:-
+ // https://www.developerfusion.com/article/84422/the-key-to-strong-names/
+ static byte[] ExportPublicKey(RSAParameters rsaParameters)
+ {
+ if (rsaParameters.Modulus == null || rsaParameters.Exponent == null)
+ {
+ throw new ArgumentNullException(nameof(rsaParameters));
+ }
+
+ using (MemoryStream ms = new MemoryStream())
+ {
+ using (BinaryWriter bw = new BinaryWriter(ms))
+ {
+ var keyBitLength = rsaParameters.Modulus.Length * 8;
+ bw.Write((byte)0x06);
+ bw.Write((byte)0x02);
+ bw.Write((UInt16)0x0000);
+ bw.Write((UInt32)0x2400);
+ bw.Write("RSA1".ToCharArray());
+ bw.Write((UInt32)keyBitLength);
+ bw.Write(rsaParameters.Exponent);
+ bw.Write((byte)0x00);
+ byte[] modulus = (byte[])rsaParameters.Modulus.Clone();
+ Array.Reverse(modulus);
+ bw.Write(modulus);
+
+ return ms.ToArray();
+ }
+ }
+ }
+
+ static RSAParameters RSAParametersFromByteArray(byte[] array)
+ {
+ using (MemoryStream ms = new MemoryStream(array))
+ {
+ return RSAParametersFromStream(ms);
+ }
+ }
+
+ static RSAParameters RSAParametersFromStream(Stream str)
+ {
+ RSAParameters rsaParameters = new RSAParameters();
+
+ using (var br = new BinaryReader(str))
+ {
+ // Read BLOBHEADER
+ byte keyType = br.ReadByte();
+ if (keyType != 6 && keyType != 7)
+ {
+ throw new CryptographicException("SNK file not in correct format");
+ }
+ byte blobVersion = br.ReadByte();
+ UInt16 reserverd = br.ReadUInt16();
+ UInt32 algorithmID = br.ReadUInt32();
+ // Read RSAPUBKEY
+ string magic = new string(br.ReadChars(4));
+ if (!magic.Equals("RSA1") && !magic.Equals("RSA2"))
+ {
+ throw new CryptographicException("SNK file not in correct format");
+ }
+ UInt32 keyBitLength = br.ReadUInt32();
+ byte[] publicExponent = br.ReadBytes(3);
+ br.ReadByte();
+ rsaParameters.Exponent = publicExponent;
+
+ // Read Modulus
+ byte[] modulus = br.ReadBytes(
+ (int)keyBitLength / 8);
+ Array.Reverse(modulus);
+ rsaParameters.Modulus = modulus;
+
+ if (keyType == 7)
+ {
+ // Read Private Key Parameters
+ byte[] prime1 = br.ReadBytes(
+ (int)keyBitLength / 16);
+ byte[] prime2 = br.ReadBytes(
+ (int)keyBitLength / 16);
+ byte[] exponent1 = br.ReadBytes(
+ (int)keyBitLength / 16);
+ byte[] exponent2 = br.ReadBytes(
+ (int)keyBitLength / 16);
+ byte[] coefficient = br.ReadBytes(
+ (int)keyBitLength / 16);
+ byte[] privateExponent = br.ReadBytes(
+ (int)keyBitLength / 8);
+
+ Array.Reverse(prime1);
+ Array.Reverse(prime2);
+ Array.Reverse(exponent1);
+ Array.Reverse(exponent2);
+ Array.Reverse(coefficient);
+ Array.Reverse(privateExponent);
+ rsaParameters.P = prime1;
+ rsaParameters.Q = prime2;
+ rsaParameters.DP = exponent1;
+ rsaParameters.DQ = exponent2;
+ rsaParameters.InverseQ = coefficient;
+ rsaParameters.D = privateExponent;
+ }
+ }
+
+ return rsaParameters;
+ }
+
+#if !NET6_0_OR_GREATER
+ [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private byte[] MonoGetPublicKey()
{
return keyPairArray != null
@@ -136,5 +254,5 @@ private byte[] MonoGetPublicKey()
: new System.Reflection.StrongNameKeyPair(keyPairContainer).PublicKey;
}
#endif
- }
+ }
}
diff --git a/src/compiler/backend/ikvm/Type.cs b/src/compiler/backend/ikvm/Type.cs
index 0bf1a5aa1..d4e865f1e 100644
--- a/src/compiler/backend/ikvm/Type.cs
+++ b/src/compiler/backend/ikvm/Type.cs
@@ -58,7 +58,7 @@ protected enum TypeFlags : ushort
HasNestedTypes = 2,
Baked = 4,
- // for use by MissingType
+ // for use by IsValueType to cache result of IsValueTypeImpl
ValueType = 8,
NotValueType = 16,
@@ -222,17 +222,26 @@ public bool __IsFunctionPointer
get { return sigElementType == Signature.ELEMENT_TYPE_FNPTR; }
}
- public virtual bool IsValueType
+ public bool IsValueType
{
get
{
- Type baseType = this.BaseType;
- return baseType != null
- && baseType.IsEnumOrValueType
- && !this.IsEnumOrValueType;
+ // MissingType sets both flags for WinRT projection types
+ switch (typeFlags & (TypeFlags.ValueType | TypeFlags.NotValueType))
+ {
+ case 0:
+ case TypeFlags.ValueType | TypeFlags.NotValueType:
+ return IsValueTypeImpl;
+ }
+ return (typeFlags & TypeFlags.ValueType) != 0;
}
}
+ protected abstract bool IsValueTypeImpl
+ {
+ get;
+ }
+
public bool IsGenericParameter
{
get { return sigElementType == Signature.ELEMENT_TYPE_VAR || sigElementType == Signature.ELEMENT_TYPE_MVAR; }
@@ -525,7 +534,6 @@ public string[] GetEnumNames()
return names.ToArray();
}
-#if !CORECLR
public string GetEnumName(object value)
{
if (!IsEnum)
@@ -538,7 +546,7 @@ public string GetEnumName(object value)
}
try
{
- value = Convert.ChangeType(value, GetTypeCode(GetEnumUnderlyingType()));
+ value = Convert.ChangeType(value, __GetSystemType(GetTypeCode(GetEnumUnderlyingType())));
}
catch (FormatException)
{
@@ -561,7 +569,6 @@ public string GetEnumName(object value)
}
return null;
}
-#endif
public bool IsEnumDefined(object value)
{
@@ -577,7 +584,7 @@ public bool IsEnumDefined(object value)
{
throw new ArgumentNullException();
}
- if (System.Type.GetTypeCode(value.GetType()) != GetTypeCode(GetEnumUnderlyingType()))
+ if (value.GetType() != __GetSystemType(GetTypeCode(GetEnumUnderlyingType())))
{
throw new ArgumentException();
}
@@ -1042,7 +1049,6 @@ public ConstructorInfo GetConstructor(Type[] types)
public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
{
ConstructorInfo ci1 = null;
- bindingAttr |= BindingFlags.DeclaredOnly;
if ((bindingAttr & BindingFlags.Instance) != 0)
{
ci1 = GetConstructorImpl(ConstructorInfo.ConstructorName, bindingAttr, binder, types, modifiers);
@@ -1405,17 +1411,15 @@ public bool IsCOMObject
get { return IsClass && IsImport; }
}
-#if !CORECLR
public bool IsContextful
{
- get { return IsSubclassOf(this.Module.universe.Import(typeof(ContextBoundObject))); }
+ get { return IsSubclassOf(this.Module.universe.System_ContextBoundObject); }
}
public bool IsMarshalByRef
{
- get { return IsSubclassOf(this.Module.universe.Import(typeof(MarshalByRefObject))); }
+ get { return IsSubclassOf(this.Module.universe.System_MarshalByRefObject); }
}
-#endif
public virtual bool IsVisible
{
@@ -2159,6 +2163,11 @@ internal virtual Type SetCyclicTypeForwarder()
return this;
}
+ internal virtual Type SetCyclicTypeSpec()
+ {
+ return this;
+ }
+
protected void MarkKnownType(string typeNamespace, string typeName)
{
// we assume that mscorlib won't have nested types with these names,
@@ -2197,10 +2206,10 @@ protected void MarkKnownType(string typeNamespace, string typeName)
private bool ResolvePotentialEnumOrValueType()
{
- if (this.Assembly == this.Universe.Mscorlib
+ if (this.Assembly == this.Universe.CoreLib
|| this.Assembly.GetName().Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase)
// check if mscorlib forwards the type (.NETCore profile reference mscorlib forwards System.Enum and System.ValueType to System.Runtime.dll)
- || this.Universe.Mscorlib.FindType(TypeName) == this)
+ || this.Universe.CoreLib.FindType(TypeName) == this)
{
typeFlags = (typeFlags & ~TypeFlags.PotentialEnumOrValueType) | TypeFlags.EnumOrValueType;
return true;
@@ -2212,7 +2221,7 @@ private bool ResolvePotentialEnumOrValueType()
}
}
- private bool IsEnumOrValueType
+ internal bool IsEnumOrValueType
{
get
{
@@ -2267,6 +2276,11 @@ public virtual bool __IsCyclicTypeForwarder
{
get { return false; }
}
+
+ public virtual bool __IsCyclicTypeSpec
+ {
+ get { return false; }
+ }
}
abstract class ElementHolderType : TypeInfo
@@ -2360,6 +2374,11 @@ protected sealed override bool ContainsMissingTypeImpl
}
}
+ protected sealed override bool IsValueTypeImpl
+ {
+ get { return false; }
+ }
+
internal sealed override Type BindTypeParameters(IGenericBinder binder)
{
Type type = elementType.BindTypeParameters(binder);
@@ -2875,7 +2894,7 @@ public override Type BaseType
}
}
- public override bool IsValueType
+ protected override bool IsValueTypeImpl
{
get { return type.IsValueType; }
}
@@ -3134,87 +3153,6 @@ internal override bool IsBaked
}
}
- sealed class FunctionPointerType : TypeInfo
- {
- private readonly Universe universe;
- private readonly __StandAloneMethodSig sig;
-
- internal static Type Make(Universe universe, __StandAloneMethodSig sig)
- {
- return universe.CanonicalizeType(new FunctionPointerType(universe, sig));
- }
-
- private FunctionPointerType(Universe universe, __StandAloneMethodSig sig)
- : base(Signature.ELEMENT_TYPE_FNPTR)
- {
- this.universe = universe;
- this.sig = sig;
- }
-
- public override bool Equals(object obj)
- {
- FunctionPointerType other = obj as FunctionPointerType;
- return other != null
- && other.universe == universe
- && other.sig.Equals(sig);
- }
-
- public override int GetHashCode()
- {
- return sig.GetHashCode();
- }
-
- public override __StandAloneMethodSig __MethodSignature
- {
- get { return sig; }
- }
-
- public override Type BaseType
- {
- get { return null; }
- }
-
- public override TypeAttributes Attributes
- {
- get { return 0; }
- }
-
- public override string Name
- {
- get { throw new InvalidOperationException(); }
- }
-
- public override string FullName
- {
- get { throw new InvalidOperationException(); }
- }
-
- public override Module Module
- {
- get { throw new InvalidOperationException(); }
- }
-
- internal override Universe Universe
- {
- get { return universe; }
- }
-
- public override string ToString()
- {
- return "";
- }
-
- protected override bool ContainsMissingTypeImpl
- {
- get { return sig.ContainsMissingType; }
- }
-
- internal override bool IsBaked
- {
- get { return true; }
- }
- }
-
sealed class MarkerType : Type
{
// used by CustomModifiers and SignatureHelper
@@ -3223,6 +3161,8 @@ sealed class MarkerType : Type
// used by SignatureHelper
internal static readonly Type Sentinel = new MarkerType(Signature.SENTINEL);
internal static readonly Type Pinned = new MarkerType(Signature.ELEMENT_TYPE_PINNED);
+ // used by ModuleReader.LazyForwardedType and TypeSpec resolution
+ internal static readonly Type LazyResolveInProgress = new MarkerType(0xFF);
private MarkerType(byte sigElementType)
: base(sigElementType)
@@ -3263,5 +3203,10 @@ public override bool __IsMissing
{
get { return false; }
}
+
+ protected override bool IsValueTypeImpl
+ {
+ get { throw new InvalidOperationException(); }
+ }
}
}
diff --git a/src/compiler/backend/ikvm/TypeNameParser.cs b/src/compiler/backend/ikvm/TypeNameParser.cs
index 1d31952a7..33dd92bb4 100644
--- a/src/compiler/backend/ikvm/TypeNameParser.cs
+++ b/src/compiler/backend/ikvm/TypeNameParser.cs
@@ -499,15 +499,15 @@ internal Type GetType(Universe universe, Module context, bool throwOnError, stri
{
if (resolve)
{
- type = universe.Mscorlib.ResolveType(context, name);
+ type = universe.CoreLib.ResolveType(context, name);
}
else if (ignoreCase)
{
- type = universe.Mscorlib.FindTypeIgnoreCase(name.ToLowerInvariant());
+ type = universe.CoreLib.FindTypeIgnoreCase(name.ToLowerInvariant());
}
else
{
- type = universe.Mscorlib.FindType(name);
+ type = universe.CoreLib.FindType(name);
}
}
else
@@ -521,22 +521,22 @@ internal Type GetType(Universe universe, Module context, bool throwOnError, stri
{
type = context.FindType(name);
}
- if (type == null && context != universe.Mscorlib.ManifestModule)
+ if (type == null && context != universe.CoreLib.ManifestModule)
{
if (ignoreCase)
{
- type = universe.Mscorlib.FindTypeIgnoreCase(name);
+ type = universe.CoreLib.FindTypeIgnoreCase(name);
}
else
{
- type = universe.Mscorlib.FindType(name);
+ type = universe.CoreLib.FindType(name);
}
}
if (type == null && resolve)
{
- if (universe.Mscorlib.__IsMissing && !context.__IsMissing)
+ if (universe.CoreLib.__IsMissing && !context.__IsMissing)
{
- type = universe.Mscorlib.ResolveType(context, name);
+ type = universe.CoreLib.ResolveType(context, name);
}
else
{
diff --git a/src/compiler/backend/ikvm/Universe.cs b/src/compiler/backend/ikvm/Universe.cs
index 01043a487..56544e737 100644
--- a/src/compiler/backend/ikvm/Universe.cs
+++ b/src/compiler/backend/ikvm/Universe.cs
@@ -26,60 +26,62 @@ Jeroen Frijters
using System.IO;
using System.Security;
using System.Text;
-using System.Diagnostics;
-using IKVM.Reflection.Reader;
+
using IKVM.Reflection.Emit;
+using IKVM.Reflection.Reader;
namespace IKVM.Reflection
{
- public sealed class ResolveEventArgs : EventArgs
- {
- private readonly string name;
- private readonly Assembly requestingAssembly;
-
- public ResolveEventArgs(string name)
- : this(name, null)
- {
- }
-
- public ResolveEventArgs(string name, Assembly requestingAssembly)
- {
- this.name = name;
- this.requestingAssembly = requestingAssembly;
- }
-
- public string Name
- {
- get { return name; }
- }
-
- public Assembly RequestingAssembly
- {
- get { return requestingAssembly; }
- }
- }
-
- public enum AssemblyComparisonResult
- {
- Unknown = 0,
- EquivalentFullMatch = 1,
- EquivalentWeakNamed = 2,
- EquivalentFXUnified = 3,
- EquivalentUnified = 4,
- NonEquivalentVersion = 5,
- NonEquivalent = 6,
- EquivalentPartialMatch = 7,
- EquivalentPartialWeakNamed = 8,
- EquivalentPartialUnified = 9,
- EquivalentPartialFXUnified = 10,
- NonEquivalentPartialVersion = 11,
- }
-
- public delegate Assembly ResolveEventHandler(object sender, ResolveEventArgs args);
-
- public delegate void ResolvedMissingMemberHandler(Module requestingModule, MemberInfo member);
-
- /*
+
+ public sealed class ResolveEventArgs : EventArgs
+ {
+
+ private readonly string name;
+ private readonly Assembly requestingAssembly;
+
+ public ResolveEventArgs(string name)
+ : this(name, null)
+ {
+ }
+
+ public ResolveEventArgs(string name, Assembly requestingAssembly)
+ {
+ this.name = name;
+ this.requestingAssembly = requestingAssembly;
+ }
+
+ public string Name
+ {
+ get { return name; }
+ }
+
+ public Assembly RequestingAssembly
+ {
+ get { return requestingAssembly; }
+ }
+ }
+
+ public enum AssemblyComparisonResult
+ {
+ Unknown = 0,
+ EquivalentFullMatch = 1,
+ EquivalentWeakNamed = 2,
+ EquivalentFXUnified = 3,
+ EquivalentUnified = 4,
+ NonEquivalentVersion = 5,
+ NonEquivalent = 6,
+ EquivalentPartialMatch = 7,
+ EquivalentPartialWeakNamed = 8,
+ EquivalentPartialUnified = 9,
+ EquivalentPartialFXUnified = 10,
+ NonEquivalentPartialVersion = 11,
+ }
+
+ public delegate Assembly ResolveEventHandler(object sender, ResolveEventArgs args);
+
+ public delegate void ResolvedMissingMemberHandler(Module requestingModule, MemberInfo member);
+
+ /*
* UniverseOptions:
*
* None
@@ -123,651 +125,679 @@ public enum AssemblyComparisonResult
* This option can not be used in combination with PDB file generation.
*/
- [Flags]
- public enum UniverseOptions
- {
- None = 0,
- EnableFunctionPointers = 1,
- DisableFusion = 2,
- DisablePseudoCustomAttributeRetrieval = 4,
- DontProvideAutomaticDefaultConstructor = 8,
- MetadataOnly = 16,
- ResolveMissingMembers = 32,
- DisableWindowsRuntimeProjection = 64,
- DecodeVersionInfoAttributeBlobs = 128,
- DeterministicOutput = 256,
- DisableDefaultAssembliesLookup = 512,
- }
-
- public sealed class Universe : IDisposable
- {
- internal static readonly bool MonoRuntime = System.Type.GetType("Mono.Runtime") != null;
- private readonly Dictionary canonicalizedTypes = new Dictionary();
- private readonly List assemblies = new List();
- private readonly List dynamicAssemblies = new List();
- private readonly Dictionary assembliesByName = new Dictionary();
- private readonly Dictionary importedTypes = new Dictionary();
- private Dictionary missingTypes;
- private bool resolveMissingMembers;
- private readonly bool enableFunctionPointers;
- private readonly bool useNativeFusion;
- private readonly bool returnPseudoCustomAttributes;
- private readonly bool automaticallyProvideDefaultConstructor;
- private readonly UniverseOptions options;
- private Type typeof_System_Object;
- private Type typeof_System_ValueType;
- private Type typeof_System_Enum;
- private Type typeof_System_Void;
- private Type typeof_System_Boolean;
- private Type typeof_System_Char;
- private Type typeof_System_SByte;
- private Type typeof_System_Byte;
- private Type typeof_System_Int16;
- private Type typeof_System_UInt16;
- private Type typeof_System_Int32;
- private Type typeof_System_UInt32;
- private Type typeof_System_Int64;
- private Type typeof_System_UInt64;
- private Type typeof_System_Single;
- private Type typeof_System_Double;
- private Type typeof_System_String;
- private Type typeof_System_IntPtr;
- private Type typeof_System_UIntPtr;
- private Type typeof_System_TypedReference;
- private Type typeof_System_Type;
- private Type typeof_System_Array;
- private Type typeof_System_DateTime;
- private Type typeof_System_DBNull;
- private Type typeof_System_Decimal;
- private Type typeof_System_AttributeUsageAttribute;
- private Type typeof_System_Runtime_InteropServices_DllImportAttribute;
- private Type typeof_System_Runtime_InteropServices_FieldOffsetAttribute;
- private Type typeof_System_Runtime_InteropServices_MarshalAsAttribute;
- private Type typeof_System_Runtime_InteropServices_UnmanagedType;
- private Type typeof_System_Runtime_InteropServices_VarEnum;
- private Type typeof_System_Runtime_InteropServices_PreserveSigAttribute;
- private Type typeof_System_Runtime_InteropServices_CallingConvention;
- private Type typeof_System_Runtime_InteropServices_CharSet;
- private Type typeof_System_Runtime_CompilerServices_DecimalConstantAttribute;
- private Type typeof_System_Reflection_AssemblyCopyrightAttribute;
- private Type typeof_System_Reflection_AssemblyTrademarkAttribute;
- private Type typeof_System_Reflection_AssemblyProductAttribute;
- private Type typeof_System_Reflection_AssemblyCompanyAttribute;
- private Type typeof_System_Reflection_AssemblyDescriptionAttribute;
- private Type typeof_System_Reflection_AssemblyTitleAttribute;
- private Type typeof_System_Reflection_AssemblyInformationalVersionAttribute;
- private Type typeof_System_Reflection_AssemblyFileVersionAttribute;
- private Type typeof_System_Security_Permissions_CodeAccessSecurityAttribute;
- private Type typeof_System_Security_Permissions_PermissionSetAttribute;
- private Type typeof_System_Security_Permissions_SecurityAction;
- private List resolvers = new List();
- private Predicate missingTypeIsValueType;
-
- public Universe()
- : this(UniverseOptions.None)
- {
- }
-
- public Universe(UniverseOptions options)
- {
- this.options = options;
- enableFunctionPointers = (options & UniverseOptions.EnableFunctionPointers) != 0;
- useNativeFusion = (options & UniverseOptions.DisableFusion) == 0 && GetUseNativeFusion();
- returnPseudoCustomAttributes = (options & UniverseOptions.DisablePseudoCustomAttributeRetrieval) == 0;
- automaticallyProvideDefaultConstructor = (options & UniverseOptions.DontProvideAutomaticDefaultConstructor) == 0;
- resolveMissingMembers = (options & UniverseOptions.ResolveMissingMembers) != 0;
- }
-
- private static bool GetUseNativeFusion()
- {
- try
- {
- return Environment.OSVersion.Platform == PlatformID.Win32NT
- && !MonoRuntime
- && Environment.GetEnvironmentVariable("IKVM_DISABLE_FUSION") == null;
- }
- catch (System.Security.SecurityException)
- {
- return false;
- }
- }
+ [Flags]
+ public enum UniverseOptions
+ {
+ None = 0,
+ EnableFunctionPointers = 1,
+ DisableFusion = 2,
+ DisablePseudoCustomAttributeRetrieval = 4,
+ DontProvideAutomaticDefaultConstructor = 8,
+ MetadataOnly = 16,
+ ResolveMissingMembers = 32,
+ DisableWindowsRuntimeProjection = 64,
+ DecodeVersionInfoAttributeBlobs = 128,
+ DeterministicOutput = 256,
+ DisableDefaultAssembliesLookup = 512,
+ }
- internal Assembly Mscorlib
- {
- get { return Load("mscorlib"); }
- }
+ public sealed class Universe : IDisposable
+ {
- private Type ImportMscorlibType(string ns, string name)
- {
- if (Mscorlib.__IsMissing)
- {
- return Mscorlib.ResolveType(null, new TypeName(ns, name));
- }
- // We use FindType instead of ResolveType here, because on some versions of mscorlib some of
- // the special types we use/support are missing and the type properties are defined to
- // return null in that case.
- // Note that we don't have to unescape type.Name here, because none of the names contain special characters.
- return Mscorlib.FindType(new TypeName(ns, name));
- }
-
- private Type ResolvePrimitive(string name)
- {
- // Primitive here means that these types have a special metadata encoding, which means that
- // there can be references to them without referring to them by name explicitly.
- // We want these types to be usable even when they don't exist in mscorlib or there is no mscorlib loaded.
- return Mscorlib.FindType(new TypeName("System", name)) ?? GetMissingType(null, Mscorlib.ManifestModule, null, new TypeName("System", name));
- }
-
- internal Type System_Object
- {
- get { return typeof_System_Object ?? (typeof_System_Object = ResolvePrimitive("Object")); }
- }
-
- internal Type System_ValueType
- {
- // System.ValueType is not a primitive, but generic type parameters can have a ValueType constraint
- // (we also don't want to return null here)
- get { return typeof_System_ValueType ?? (typeof_System_ValueType = ResolvePrimitive("ValueType")); }
- }
-
- internal Type System_Enum
- {
- // System.Enum is not a primitive, but we don't want to return null
- get { return typeof_System_Enum ?? (typeof_System_Enum = ResolvePrimitive("Enum")); }
- }
-
- internal Type System_Void
- {
- get { return typeof_System_Void ?? (typeof_System_Void = ResolvePrimitive("Void")); }
- }
-
- internal Type System_Boolean
- {
- get { return typeof_System_Boolean ?? (typeof_System_Boolean = ResolvePrimitive("Boolean")); }
- }
-
- internal Type System_Char
- {
- get { return typeof_System_Char ?? (typeof_System_Char = ResolvePrimitive("Char")); }
- }
-
- internal Type System_SByte
- {
- get { return typeof_System_SByte ?? (typeof_System_SByte = ResolvePrimitive("SByte")); }
- }
-
- internal Type System_Byte
- {
- get { return typeof_System_Byte ?? (typeof_System_Byte = ResolvePrimitive("Byte")); }
- }
-
- internal Type System_Int16
- {
- get { return typeof_System_Int16 ?? (typeof_System_Int16 = ResolvePrimitive("Int16")); }
- }
-
- internal Type System_UInt16
- {
- get { return typeof_System_UInt16 ?? (typeof_System_UInt16 = ResolvePrimitive("UInt16")); }
- }
-
- internal Type System_Int32
- {
- get { return typeof_System_Int32 ?? (typeof_System_Int32 = ResolvePrimitive("Int32")); }
- }
-
- internal Type System_UInt32
- {
- get { return typeof_System_UInt32 ?? (typeof_System_UInt32 = ResolvePrimitive("UInt32")); }
- }
-
- internal Type System_Int64
- {
- get { return typeof_System_Int64 ?? (typeof_System_Int64 = ResolvePrimitive("Int64")); }
- }
-
- internal Type System_UInt64
- {
- get { return typeof_System_UInt64 ?? (typeof_System_UInt64 = ResolvePrimitive("UInt64")); }
- }
-
- internal Type System_Single
- {
- get { return typeof_System_Single ?? (typeof_System_Single = ResolvePrimitive("Single")); }
- }
-
- internal Type System_Double
- {
- get { return typeof_System_Double ?? (typeof_System_Double = ResolvePrimitive("Double")); }
- }
-
- internal Type System_String
- {
- get { return typeof_System_String ?? (typeof_System_String = ResolvePrimitive("String")); }
- }
-
- internal Type System_IntPtr
- {
- get { return typeof_System_IntPtr ?? (typeof_System_IntPtr = ResolvePrimitive("IntPtr")); }
- }
-
- internal Type System_UIntPtr
- {
- get { return typeof_System_UIntPtr ?? (typeof_System_UIntPtr = ResolvePrimitive("UIntPtr")); }
- }
-
- internal Type System_TypedReference
- {
- get { return typeof_System_TypedReference ?? (typeof_System_TypedReference = ResolvePrimitive("TypedReference")); }
- }
-
- internal Type System_Type
- {
- // System.Type is not a primitive, but it does have a special encoding in custom attributes
- get { return typeof_System_Type ?? (typeof_System_Type = ResolvePrimitive("Type")); }
- }
-
- internal Type System_Array
- {
- // System.Array is not a primitive, but it used as a base type for array types (that are primitives)
- get { return typeof_System_Array ?? (typeof_System_Array = ResolvePrimitive("Array")); }
- }
-
- internal Type System_DateTime
- {
- get { return typeof_System_DateTime ?? (typeof_System_DateTime = ImportMscorlibType("System", "DateTime")); }
- }
-
- internal Type System_DBNull
- {
- get { return typeof_System_DBNull ?? (typeof_System_DBNull = ImportMscorlibType("System", "DBNull")); }
- }
-
- internal Type System_Decimal
- {
- get { return typeof_System_Decimal ?? (typeof_System_Decimal = ImportMscorlibType("System", "Decimal")); }
- }
-
- internal Type System_AttributeUsageAttribute
- {
- get { return typeof_System_AttributeUsageAttribute ?? (typeof_System_AttributeUsageAttribute = ImportMscorlibType("System", "AttributeUsageAttribute")); }
- }
-
- internal Type System_Runtime_InteropServices_DllImportAttribute
- {
- get { return typeof_System_Runtime_InteropServices_DllImportAttribute ?? (typeof_System_Runtime_InteropServices_DllImportAttribute = ImportMscorlibType("System.Runtime.InteropServices", "DllImportAttribute")); }
- }
-
- internal Type System_Runtime_InteropServices_FieldOffsetAttribute
- {
- get { return typeof_System_Runtime_InteropServices_FieldOffsetAttribute ?? (typeof_System_Runtime_InteropServices_FieldOffsetAttribute = ImportMscorlibType("System.Runtime.InteropServices", "FieldOffsetAttribute")); }
- }
-
- internal Type System_Runtime_InteropServices_MarshalAsAttribute
- {
- get { return typeof_System_Runtime_InteropServices_MarshalAsAttribute ?? (typeof_System_Runtime_InteropServices_MarshalAsAttribute = ImportMscorlibType("System.Runtime.InteropServices", "MarshalAsAttribute")); }
- }
-
- internal Type System_Runtime_InteropServices_UnmanagedType
- {
- get { return typeof_System_Runtime_InteropServices_UnmanagedType ?? (typeof_System_Runtime_InteropServices_UnmanagedType = ImportMscorlibType("System.Runtime.InteropServices", "UnmanagedType")); }
- }
-
- internal Type System_Runtime_InteropServices_VarEnum
- {
- get { return typeof_System_Runtime_InteropServices_VarEnum ?? (typeof_System_Runtime_InteropServices_VarEnum = ImportMscorlibType("System.Runtime.InteropServices", "VarEnum")); }
- }
-
- internal Type System_Runtime_InteropServices_PreserveSigAttribute
- {
- get { return typeof_System_Runtime_InteropServices_PreserveSigAttribute ?? (typeof_System_Runtime_InteropServices_PreserveSigAttribute = ImportMscorlibType("System.Runtime.InteropServices", "PreserveSigAttribute")); }
- }
-
- internal Type System_Runtime_InteropServices_CallingConvention
- {
- get { return typeof_System_Runtime_InteropServices_CallingConvention ?? (typeof_System_Runtime_InteropServices_CallingConvention = ImportMscorlibType("System.Runtime.InteropServices", "CallingConvention")); }
- }
-
- internal Type System_Runtime_InteropServices_CharSet
- {
- get { return typeof_System_Runtime_InteropServices_CharSet ?? (typeof_System_Runtime_InteropServices_CharSet = ImportMscorlibType("System.Runtime.InteropServices", "CharSet")); }
- }
-
- internal Type System_Runtime_CompilerServices_DecimalConstantAttribute
- {
- get { return typeof_System_Runtime_CompilerServices_DecimalConstantAttribute ?? (typeof_System_Runtime_CompilerServices_DecimalConstantAttribute = ImportMscorlibType("System.Runtime.CompilerServices", "DecimalConstantAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyCopyrightAttribute
- {
- get { return typeof_System_Reflection_AssemblyCopyrightAttribute ?? (typeof_System_Reflection_AssemblyCopyrightAttribute = ImportMscorlibType("System.Reflection", "AssemblyCopyrightAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyTrademarkAttribute
- {
- get { return typeof_System_Reflection_AssemblyTrademarkAttribute ?? (typeof_System_Reflection_AssemblyTrademarkAttribute = ImportMscorlibType("System.Reflection", "AssemblyTrademarkAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyProductAttribute
- {
- get { return typeof_System_Reflection_AssemblyProductAttribute ?? (typeof_System_Reflection_AssemblyProductAttribute = ImportMscorlibType("System.Reflection", "AssemblyProductAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyCompanyAttribute
- {
- get { return typeof_System_Reflection_AssemblyCompanyAttribute ?? (typeof_System_Reflection_AssemblyCompanyAttribute = ImportMscorlibType("System.Reflection", "AssemblyCompanyAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyDescriptionAttribute
- {
- get { return typeof_System_Reflection_AssemblyDescriptionAttribute ?? (typeof_System_Reflection_AssemblyDescriptionAttribute = ImportMscorlibType("System.Reflection", "AssemblyDescriptionAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyTitleAttribute
- {
- get { return typeof_System_Reflection_AssemblyTitleAttribute ?? (typeof_System_Reflection_AssemblyTitleAttribute = ImportMscorlibType("System.Reflection", "AssemblyTitleAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyInformationalVersionAttribute
- {
- get { return typeof_System_Reflection_AssemblyInformationalVersionAttribute ?? (typeof_System_Reflection_AssemblyInformationalVersionAttribute = ImportMscorlibType("System.Reflection", "AssemblyInformationalVersionAttribute")); }
- }
-
- internal Type System_Reflection_AssemblyFileVersionAttribute
- {
- get { return typeof_System_Reflection_AssemblyFileVersionAttribute ?? (typeof_System_Reflection_AssemblyFileVersionAttribute = ImportMscorlibType("System.Reflection", "AssemblyFileVersionAttribute")); }
- }
-
- internal Type System_Security_Permissions_CodeAccessSecurityAttribute
- {
- get { return typeof_System_Security_Permissions_CodeAccessSecurityAttribute ?? (typeof_System_Security_Permissions_CodeAccessSecurityAttribute = ImportMscorlibType("System.Security.Permissions", "CodeAccessSecurityAttribute")); }
- }
-
- internal Type System_Security_Permissions_PermissionSetAttribute
- {
- get { return typeof_System_Security_Permissions_PermissionSetAttribute ?? (typeof_System_Security_Permissions_PermissionSetAttribute = ImportMscorlibType("System.Security.Permissions", "PermissionSetAttribute")); }
- }
-
- internal Type System_Security_Permissions_SecurityAction
- {
- get { return typeof_System_Security_Permissions_SecurityAction ?? (typeof_System_Security_Permissions_SecurityAction = ImportMscorlibType("System.Security.Permissions", "SecurityAction")); }
- }
-
- internal bool HasMscorlib
- {
- get { return GetLoadedAssembly("mscorlib") != null; }
- }
-
- public event ResolveEventHandler AssemblyResolve
- {
- add { resolvers.Add(value); }
- remove { resolvers.Remove(value); }
- }
-
- public Type Import(System.Type type)
- {
- Type imported;
- if (!importedTypes.TryGetValue(type, out imported))
- {
- imported = ImportImpl(type);
- if (imported != null)
- {
- importedTypes.Add(type, imported);
- }
- }
- return imported;
- }
+#if NETCOREAPP3_1_OR_GREATER
- private Type ImportImpl(System.Type type)
- {
- if (type.Assembly == typeof(IKVM.Reflection.Type).Assembly)
- {
- throw new ArgumentException("Did you really want to import " + type.FullName + "?");
- }
- if (type.HasElementType)
- {
- if (type.IsArray)
- {
- if (type.Name.EndsWith("[]"))
- {
- return Import(type.GetElementType()).MakeArrayType();
- }
- else
- {
- return Import(type.GetElementType()).MakeArrayType(type.GetArrayRank());
- }
- }
- else if (type.IsByRef)
- {
- return Import(type.GetElementType()).MakeByRefType();
- }
- else if (type.IsPointer)
- {
- return Import(type.GetElementType()).MakePointerType();
- }
- else
- {
- throw new InvalidOperationException();
- }
- }
- else if (type.IsGenericParameter)
- {
- if (type.DeclaringMethod != null)
- {
- throw new NotImplementedException();
- }
- else
- {
- return Import(type.DeclaringType).GetGenericArguments()[type.GenericParameterPosition];
- }
- }
- else if (type.IsGenericType && !type.IsGenericTypeDefinition)
- {
- System.Type[] args = type.GetGenericArguments();
- Type[] importedArgs = new Type[args.Length];
- for (int i = 0; i < args.Length; i++)
- {
- importedArgs[i] = Import(args[i]);
- }
- return Import(type.GetGenericTypeDefinition()).MakeGenericType(importedArgs);
- }
- else if (type.Assembly == typeof(object).Assembly)
- {
- // make sure mscorlib types always end up in our mscorlib
- return ResolveType(Mscorlib, type.FullName);
- }
- else
- {
- // FXBUG we parse the FullName here, because type.Namespace and type.Name are both broken on the CLR
- return ResolveType(Import(type.Assembly), type.FullName);
- }
- }
-
- private Assembly Import(System.Reflection.Assembly asm)
- {
- return Load(asm.FullName);
- }
-
- public RawModule OpenRawModule(string path)
- {
- path = Path.GetFullPath(path);
- FileStream fs = null;
- RawModule module;
- try
- {
- fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
- module = OpenRawModule(fs, path);
- if (!MetadataOnly)
- {
- fs = null;
- }
- }
- finally
- {
- if (fs != null)
- {
- fs.Close();
- }
- }
- return module;
- }
-
- public RawModule OpenRawModule(Stream stream, string location)
- {
- return OpenRawModule(stream, location, false);
- }
-
- public RawModule OpenMappedRawModule(Stream stream, string location)
- {
- return OpenRawModule(stream, location, true);
- }
-
- private RawModule OpenRawModule(Stream stream, string location, bool mapped)
- {
- if (!stream.CanRead || !stream.CanSeek || stream.Position != 0)
- {
- throw new ArgumentException("Stream must support read/seek and current position must be zero.", "stream");
- }
- return new RawModule(new ModuleReader(null, this, stream, location, mapped));
- }
-
- public Assembly LoadAssembly(RawModule module)
- {
- string refname = module.GetAssemblyName().FullName;
- Assembly asm = GetLoadedAssembly(refname);
- if (asm == null)
- {
- AssemblyReader asm1 = module.ToAssembly();
- assemblies.Add(asm1);
- asm = asm1;
- }
- return asm;
- }
+ public static readonly string CoreLibName = "netstandard";
- public Assembly LoadFile(string path)
- {
- try
- {
- using (RawModule module = OpenRawModule(path))
- {
- return LoadAssembly(module);
- }
- }
- catch (IOException x)
- {
- throw new FileNotFoundException(x.Message, x);
- }
- catch (UnauthorizedAccessException x)
- {
- throw new FileNotFoundException(x.Message, x);
- }
- }
- private static string GetSimpleAssemblyName(string refname)
- {
- int pos;
- string name;
- if (Fusion.ParseAssemblySimpleName(refname, out pos, out name) != ParseAssemblyResult.OK)
- {
- throw new ArgumentException();
- }
- return name;
- }
+#elif NETFRAMEWORK || MONO
- private Assembly GetLoadedAssembly(string refname)
- {
- Assembly asm;
- if (!assembliesByName.TryGetValue(refname, out asm) && (options & UniverseOptions.DisableDefaultAssembliesLookup) == 0)
- {
- string simpleName = GetSimpleAssemblyName(refname);
- for (int i = 0; i < assemblies.Count; i++)
- {
- AssemblyComparisonResult result;
- if (simpleName.Equals(assemblies[i].Name, StringComparison.OrdinalIgnoreCase)
- && CompareAssemblyIdentity(refname, false, assemblies[i].FullName, false, out result))
- {
- asm = assemblies[i];
- assembliesByName.Add(refname, asm);
- break;
- }
- }
- }
- return asm;
- }
+ public static readonly string CoreLibName = "mscorlib";
- private Assembly GetDynamicAssembly(string refname)
- {
- string simpleName = GetSimpleAssemblyName(refname);
- foreach (AssemblyBuilder asm in dynamicAssemblies)
- {
- AssemblyComparisonResult result;
- if (simpleName.Equals(asm.Name, StringComparison.OrdinalIgnoreCase)
- && CompareAssemblyIdentity(refname, false, asm.FullName, false, out result))
- {
- return asm;
- }
- }
- return null;
- }
-
- public Assembly Load(string refname)
- {
- return Load(refname, null, true);
- }
-
- internal Assembly Load(string refname, Module requestingModule, bool throwOnError)
- {
- Assembly asm = GetLoadedAssembly(refname);
- if (asm != null)
- {
- return asm;
- }
- if (resolvers.Count == 0)
- {
- asm = DefaultResolver(refname, throwOnError);
- }
- else
- {
- ResolveEventArgs args = new ResolveEventArgs(refname, requestingModule == null ? null : requestingModule.Assembly);
- foreach (ResolveEventHandler evt in resolvers)
- {
- asm = evt(this, args);
- if (asm != null)
- {
- break;
- }
- }
- if (asm == null)
- {
- asm = GetDynamicAssembly(refname);
- }
- }
- if (asm != null)
- {
- string defname = asm.FullName;
- if (refname != defname)
- {
- assembliesByName.Add(refname, asm);
- }
- return asm;
- }
- if (throwOnError)
- {
- throw new FileNotFoundException(refname);
- }
- return null;
- }
+#endif
- public Assembly DefaultResolver(string refname, bool throwOnError)
- {
- Assembly asm = GetDynamicAssembly(refname);
- if (asm != null)
- {
- return asm;
- }
-#if CORECLR
- return null;
+ internal static readonly bool MonoRuntime = System.Type.GetType("Mono.Runtime") != null;
+#if NET461
+ internal static readonly bool CoreRuntime = false;
#else
+ internal static readonly bool CoreRuntime = true;
+#endif
+ private readonly Dictionary canonicalizedTypes = new Dictionary();
+ private readonly List assemblies = new List();
+ private readonly List dynamicAssemblies = new List();
+ private readonly Dictionary assembliesByName = new Dictionary();
+ private readonly Dictionary importedTypes = new Dictionary();
+ private Dictionary missingTypes;
+ private bool resolveMissingMembers;
+ private readonly bool enableFunctionPointers;
+ private readonly bool useNativeFusion;
+ private readonly bool returnPseudoCustomAttributes;
+ private readonly bool automaticallyProvideDefaultConstructor;
+ private readonly UniverseOptions options;
+ private Type typeof_System_Object;
+ private Type typeof_System_ValueType;
+ private Type typeof_System_Enum;
+ private Type typeof_System_Void;
+ private Type typeof_System_Boolean;
+ private Type typeof_System_Char;
+ private Type typeof_System_SByte;
+ private Type typeof_System_Byte;
+ private Type typeof_System_Int16;
+ private Type typeof_System_UInt16;
+ private Type typeof_System_Int32;
+ private Type typeof_System_UInt32;
+ private Type typeof_System_Int64;
+ private Type typeof_System_UInt64;
+ private Type typeof_System_Single;
+ private Type typeof_System_Double;
+ private Type typeof_System_String;
+ private Type typeof_System_IntPtr;
+ private Type typeof_System_UIntPtr;
+ private Type typeof_System_TypedReference;
+ private Type typeof_System_Type;
+ private Type typeof_System_Array;
+ private Type typeof_System_DateTime;
+ private Type typeof_System_DBNull;
+ private Type typeof_System_Decimal;
+ private Type typeof_System_AttributeUsageAttribute;
+ private Type typeof_System_ContextBoundObject;
+ private Type typeof_System_MarshalByRefObject;
+ private Type typeof_System_Console;
+ private Type typeof_System_IO_TextWriter;
+ private Type typeof_System_Runtime_InteropServices_DllImportAttribute;
+ private Type typeof_System_Runtime_InteropServices_FieldOffsetAttribute;
+ private Type typeof_System_Runtime_InteropServices_MarshalAsAttribute;
+ private Type typeof_System_Runtime_InteropServices_UnmanagedType;
+ private Type typeof_System_Runtime_InteropServices_VarEnum;
+ private Type typeof_System_Runtime_InteropServices_PreserveSigAttribute;
+ private Type typeof_System_Runtime_InteropServices_CallingConvention;
+ private Type typeof_System_Runtime_InteropServices_CharSet;
+ private Type typeof_System_Runtime_CompilerServices_DecimalConstantAttribute;
+ private Type typeof_System_Reflection_AssemblyCopyrightAttribute;
+ private Type typeof_System_Reflection_AssemblyTrademarkAttribute;
+ private Type typeof_System_Reflection_AssemblyProductAttribute;
+ private Type typeof_System_Reflection_AssemblyCompanyAttribute;
+ private Type typeof_System_Reflection_AssemblyDescriptionAttribute;
+ private Type typeof_System_Reflection_AssemblyTitleAttribute;
+ private Type typeof_System_Reflection_AssemblyInformationalVersionAttribute;
+ private Type typeof_System_Reflection_AssemblyFileVersionAttribute;
+ private Type typeof_System_Security_Permissions_CodeAccessSecurityAttribute;
+ private Type typeof_System_Security_Permissions_PermissionSetAttribute;
+ private Type typeof_System_Security_Permissions_SecurityAction;
+ private List resolvers = new List();
+ private Predicate missingTypeIsValueType;
+
+ public Universe()
+ : this(UniverseOptions.None)
+ {
+ }
+
+ public Universe(UniverseOptions options)
+ {
+ this.options = options;
+ enableFunctionPointers = (options & UniverseOptions.EnableFunctionPointers) != 0;
+ useNativeFusion = (options & UniverseOptions.DisableFusion) == 0 && GetUseNativeFusion();
+ returnPseudoCustomAttributes = (options & UniverseOptions.DisablePseudoCustomAttributeRetrieval) == 0;
+ automaticallyProvideDefaultConstructor = (options & UniverseOptions.DontProvideAutomaticDefaultConstructor) == 0;
+ resolveMissingMembers = (options & UniverseOptions.ResolveMissingMembers) != 0;
+ }
+
+ private static bool GetUseNativeFusion()
+ {
+ try
+ {
+ return Environment.OSVersion.Platform == PlatformID.Win32NT && !MonoRuntime && !CoreRuntime && Environment.GetEnvironmentVariable("IKVM_DISABLE_FUSION") == null;
+ }
+ catch (System.Security.SecurityException)
+ {
+ return false;
+ }
+ }
+
+ internal Assembly CoreLib
+ {
+ get { return Load(CoreLibName); }
+ }
+
+ ///
+ /// Attempts to import the type from the core library.
+ ///
+ ///
+ ///
+ ///
+ Type ImportCoreLibType(string ns, string name)
+ {
+ if (CoreLib.__IsMissing)
+ return CoreLib.ResolveType(null, new TypeName(ns, name));
+
+ // We use FindType instead of ResolveType here, because on some versions of mscorlib some of
+ // the special types we use/support are missing and the type properties are defined to
+ // return null in that case.
+ // Note that we don't have to unescape type.Name here, because none of the names contain special characters.
+ return CoreLib.FindType(new TypeName(ns, name));
+ }
+
+ private Type ResolvePrimitive(string name)
+ {
+ // Primitive here means that these types have a special metadata encoding, which means that
+ // there can be references to them without referring to them by name explicitly.
+ // We want these types to be usable even when they don't exist in mscorlib or there is no mscorlib loaded.
+ return CoreLib.FindType(new TypeName("System", name)) ?? GetMissingType(null, CoreLib.ManifestModule, null, new TypeName("System", name));
+ }
+
+ internal Type System_Object
+ {
+ get { return typeof_System_Object ?? (typeof_System_Object = ResolvePrimitive("Object")); }
+ }
+
+ internal Type System_ValueType
+ {
+ // System.ValueType is not a primitive, but generic type parameters can have a ValueType constraint
+ // (we also don't want to return null here)
+ get { return typeof_System_ValueType ?? (typeof_System_ValueType = ResolvePrimitive("ValueType")); }
+ }
+
+ internal Type System_Enum
+ {
+ // System.Enum is not a primitive, but we don't want to return null
+ get { return typeof_System_Enum ?? (typeof_System_Enum = ResolvePrimitive("Enum")); }
+ }
+
+ internal Type System_Void
+ {
+ get { return typeof_System_Void ?? (typeof_System_Void = ResolvePrimitive("Void")); }
+ }
+
+ internal Type System_Boolean
+ {
+ get { return typeof_System_Boolean ?? (typeof_System_Boolean = ResolvePrimitive("Boolean")); }
+ }
+
+ internal Type System_Char
+ {
+ get { return typeof_System_Char ?? (typeof_System_Char = ResolvePrimitive("Char")); }
+ }
+
+ internal Type System_SByte
+ {
+ get { return typeof_System_SByte ?? (typeof_System_SByte = ResolvePrimitive("SByte")); }
+ }
+
+ internal Type System_Byte
+ {
+ get { return typeof_System_Byte ?? (typeof_System_Byte = ResolvePrimitive("Byte")); }
+ }
+
+ internal Type System_Int16
+ {
+ get { return typeof_System_Int16 ?? (typeof_System_Int16 = ResolvePrimitive("Int16")); }
+ }
+
+ internal Type System_UInt16
+ {
+ get { return typeof_System_UInt16 ?? (typeof_System_UInt16 = ResolvePrimitive("UInt16")); }
+ }
+
+ internal Type System_Int32
+ {
+ get { return typeof_System_Int32 ?? (typeof_System_Int32 = ResolvePrimitive("Int32")); }
+ }
+
+ internal Type System_UInt32
+ {
+ get { return typeof_System_UInt32 ?? (typeof_System_UInt32 = ResolvePrimitive("UInt32")); }
+ }
+
+ internal Type System_Int64
+ {
+ get { return typeof_System_Int64 ?? (typeof_System_Int64 = ResolvePrimitive("Int64")); }
+ }
+
+ internal Type System_UInt64
+ {
+ get { return typeof_System_UInt64 ?? (typeof_System_UInt64 = ResolvePrimitive("UInt64")); }
+ }
+
+ internal Type System_Single
+ {
+ get { return typeof_System_Single ?? (typeof_System_Single = ResolvePrimitive("Single")); }
+ }
+
+ internal Type System_Double
+ {
+ get { return typeof_System_Double ?? (typeof_System_Double = ResolvePrimitive("Double")); }
+ }
+
+ internal Type System_String
+ {
+ get { return typeof_System_String ?? (typeof_System_String = ResolvePrimitive("String")); }
+ }
+
+ internal Type System_IntPtr
+ {
+ get { return typeof_System_IntPtr ?? (typeof_System_IntPtr = ResolvePrimitive("IntPtr")); }
+ }
+
+ internal Type System_UIntPtr
+ {
+ get { return typeof_System_UIntPtr ?? (typeof_System_UIntPtr = ResolvePrimitive("UIntPtr")); }
+ }
+
+ internal Type System_TypedReference
+ {
+ get { return typeof_System_TypedReference ?? (typeof_System_TypedReference = ResolvePrimitive("TypedReference")); }
+ }
+
+ internal Type System_Type
+ {
+ // System.Type is not a primitive, but it does have a special encoding in custom attributes
+ get { return typeof_System_Type ?? (typeof_System_Type = ResolvePrimitive("Type")); }
+ }
+
+ internal Type System_Array
+ {
+ // System.Array is not a primitive, but it used as a base type for array types (that are primitives)
+ get { return typeof_System_Array ?? (typeof_System_Array = ResolvePrimitive("Array")); }
+ }
+
+ internal Type System_DateTime
+ {
+ get { return typeof_System_DateTime ?? (typeof_System_DateTime = ImportCoreLibType("System", "DateTime")); }
+ }
+
+ internal Type System_DBNull
+ {
+ get { return typeof_System_DBNull ?? (typeof_System_DBNull = ImportCoreLibType("System", "DBNull")); }
+ }
+
+ internal Type System_Decimal
+ {
+ get { return typeof_System_Decimal ?? (typeof_System_Decimal = ImportCoreLibType("System", "Decimal")); }
+ }
+
+ internal Type System_AttributeUsageAttribute
+ {
+ get { return typeof_System_AttributeUsageAttribute ?? (typeof_System_AttributeUsageAttribute = ImportCoreLibType("System", "AttributeUsageAttribute")); }
+ }
+
+ internal Type System_ContextBoundObject
+ {
+ get { return typeof_System_ContextBoundObject ?? (typeof_System_ContextBoundObject = ImportCoreLibType("System", "ContextBoundObject")); }
+ }
+
+ internal Type System_MarshalByRefObject
+ {
+ get { return typeof_System_MarshalByRefObject ?? (typeof_System_MarshalByRefObject = ImportCoreLibType("System", "MarshalByRefObject")); }
+ }
+
+ internal Type System_Console
+ {
+ get { return typeof_System_Console ?? (typeof_System_Console = ImportCoreLibType("System", "Console")); }
+ }
+
+ internal Type System_IO_TextWriter
+ {
+ get { return typeof_System_IO_TextWriter ?? (typeof_System_IO_TextWriter = ImportCoreLibType("System.IO", "TextWriter")); }
+ }
+
+ internal Type System_Runtime_InteropServices_DllImportAttribute
+ {
+ get { return typeof_System_Runtime_InteropServices_DllImportAttribute ?? (typeof_System_Runtime_InteropServices_DllImportAttribute = ImportCoreLibType("System.Runtime.InteropServices", "DllImportAttribute")); }
+ }
+
+ internal Type System_Runtime_InteropServices_FieldOffsetAttribute
+ {
+ get { return typeof_System_Runtime_InteropServices_FieldOffsetAttribute ?? (typeof_System_Runtime_InteropServices_FieldOffsetAttribute = ImportCoreLibType("System.Runtime.InteropServices", "FieldOffsetAttribute")); }
+ }
+
+ internal Type System_Runtime_InteropServices_MarshalAsAttribute
+ {
+ get { return typeof_System_Runtime_InteropServices_MarshalAsAttribute ?? (typeof_System_Runtime_InteropServices_MarshalAsAttribute = ImportCoreLibType("System.Runtime.InteropServices", "MarshalAsAttribute")); }
+ }
+
+ internal Type System_Runtime_InteropServices_UnmanagedType
+ {
+ get { return typeof_System_Runtime_InteropServices_UnmanagedType ?? (typeof_System_Runtime_InteropServices_UnmanagedType = ImportCoreLibType("System.Runtime.InteropServices", "UnmanagedType")); }
+ }
+
+ internal Type System_Runtime_InteropServices_VarEnum
+ {
+ get { return typeof_System_Runtime_InteropServices_VarEnum ?? (typeof_System_Runtime_InteropServices_VarEnum = ImportCoreLibType("System.Runtime.InteropServices", "VarEnum")); }
+ }
+
+ internal Type System_Runtime_InteropServices_PreserveSigAttribute
+ {
+ get { return typeof_System_Runtime_InteropServices_PreserveSigAttribute ?? (typeof_System_Runtime_InteropServices_PreserveSigAttribute = ImportCoreLibType("System.Runtime.InteropServices", "PreserveSigAttribute")); }
+ }
+
+ internal Type System_Runtime_InteropServices_CallingConvention
+ {
+ get { return typeof_System_Runtime_InteropServices_CallingConvention ?? (typeof_System_Runtime_InteropServices_CallingConvention = ImportCoreLibType("System.Runtime.InteropServices", "CallingConvention")); }
+ }
+
+ internal Type System_Runtime_InteropServices_CharSet
+ {
+ get { return typeof_System_Runtime_InteropServices_CharSet ?? (typeof_System_Runtime_InteropServices_CharSet = ImportCoreLibType("System.Runtime.InteropServices", "CharSet")); }
+ }
+
+ internal Type System_Runtime_CompilerServices_DecimalConstantAttribute
+ {
+ get { return typeof_System_Runtime_CompilerServices_DecimalConstantAttribute ?? (typeof_System_Runtime_CompilerServices_DecimalConstantAttribute = ImportCoreLibType("System.Runtime.CompilerServices", "DecimalConstantAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyCopyrightAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyCopyrightAttribute ?? (typeof_System_Reflection_AssemblyCopyrightAttribute = ImportCoreLibType("System.Reflection", "AssemblyCopyrightAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyTrademarkAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyTrademarkAttribute ?? (typeof_System_Reflection_AssemblyTrademarkAttribute = ImportCoreLibType("System.Reflection", "AssemblyTrademarkAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyProductAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyProductAttribute ?? (typeof_System_Reflection_AssemblyProductAttribute = ImportCoreLibType("System.Reflection", "AssemblyProductAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyCompanyAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyCompanyAttribute ?? (typeof_System_Reflection_AssemblyCompanyAttribute = ImportCoreLibType("System.Reflection", "AssemblyCompanyAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyDescriptionAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyDescriptionAttribute ?? (typeof_System_Reflection_AssemblyDescriptionAttribute = ImportCoreLibType("System.Reflection", "AssemblyDescriptionAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyTitleAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyTitleAttribute ?? (typeof_System_Reflection_AssemblyTitleAttribute = ImportCoreLibType("System.Reflection", "AssemblyTitleAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyInformationalVersionAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyInformationalVersionAttribute ?? (typeof_System_Reflection_AssemblyInformationalVersionAttribute = ImportCoreLibType("System.Reflection", "AssemblyInformationalVersionAttribute")); }
+ }
+
+ internal Type System_Reflection_AssemblyFileVersionAttribute
+ {
+ get { return typeof_System_Reflection_AssemblyFileVersionAttribute ?? (typeof_System_Reflection_AssemblyFileVersionAttribute = ImportCoreLibType("System.Reflection", "AssemblyFileVersionAttribute")); }
+ }
+
+ internal Type System_Security_Permissions_CodeAccessSecurityAttribute
+ {
+ get { return typeof_System_Security_Permissions_CodeAccessSecurityAttribute ?? (typeof_System_Security_Permissions_CodeAccessSecurityAttribute = ImportCoreLibType("System.Security.Permissions", "CodeAccessSecurityAttribute")); }
+ }
+
+ internal Type System_Security_Permissions_PermissionSetAttribute
+ {
+ get { return typeof_System_Security_Permissions_PermissionSetAttribute ?? (typeof_System_Security_Permissions_PermissionSetAttribute = ImportCoreLibType("System.Security.Permissions", "PermissionSetAttribute")); }
+ }
+
+ internal Type System_Security_Permissions_SecurityAction
+ {
+ get { return typeof_System_Security_Permissions_SecurityAction ?? (typeof_System_Security_Permissions_SecurityAction = ImportCoreLibType("System.Security.Permissions", "SecurityAction")); }
+ }
+
+ internal bool HasCoreLib
+ {
+ get { return GetLoadedAssembly(CoreLibName) != null; }
+ }
+
+ public event ResolveEventHandler AssemblyResolve
+ {
+ add { resolvers.Add(value); }
+ remove { resolvers.Remove(value); }
+ }
+
+ public Type Import(System.Type type)
+ {
+ if (!importedTypes.TryGetValue(type, out var imported))
+ {
+ imported = ImportImpl(type);
+ if (imported != null)
+ importedTypes.Add(type, imported);
+ }
+
+ return imported;
+ }
+
+ ///
+ /// Imports the specified type into the environment.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Type ImportImpl(System.Type type)
+ {
+ // caller should not attempt to import a custom reflection type
+ if (TypeUtil.GetAssembly(type) == TypeUtil.GetAssembly(typeof(IKVM.Reflection.Type)))
+ throw new ArgumentException("Did you really want to import " + type.FullName + "?");
+
+ // array, pointer, or reference type
+ if (type.HasElementType)
+ {
+ if (type.IsArray)
+ {
+ // type has no rank
+ if (type.Name.EndsWith("[]"))
+ return Import(type.GetElementType()).MakeArrayType();
+ else
+ return Import(type.GetElementType()).MakeArrayType(type.GetArrayRank());
+ }
+
+ // reimport the underlying element type and convert to byref
+ if (type.IsByRef)
+ return Import(type.GetElementType()).MakeByRefType();
+
+ // reimport the underlying element type and convert to pointer
+ if (type.IsPointer)
+ return Import(type.GetElementType()).MakePointerType();
+
+ throw new InvalidOperationException();
+ }
+
+ // type represents a generic parameter of a generic method definition
+ if (type.IsGenericParameter)
+ {
+ if (TypeUtil.GetDeclaringMethod(type) != null)
+ throw new NotImplementedException();
+
+ return Import(type.DeclaringType).GetGenericArguments()[type.GenericParameterPosition];
+ }
+
+ if (TypeUtil.IsGenericType(type) && !TypeUtil.IsGenericTypeDefinition(type))
+ {
+ System.Type[] args = TypeUtil.GetGenericArguments(type);
+ Type[] importedArgs = new Type[args.Length];
+ for (int i = 0; i < args.Length; i++)
+ importedArgs[i] = Import(args[i]);
+
+ return Import(type.GetGenericTypeDefinition()).MakeGenericType(importedArgs);
+ }
+
+ if (TypeUtil.GetAssembly(type) == TypeUtil.GetAssembly(typeof(object)))
+ // make sure mscorlib types always end up in our mscorlib
+ return ResolveType(CoreLib, type.FullName);
+
+ // FXBUG we parse the FullName here, because type.Namespace and type.Name are both broken on the CLR
+ return ResolveType(Import(TypeUtil.GetAssembly(type)), type.FullName);
+ }
+
+ private Assembly Import(System.Reflection.Assembly asm)
+ {
+ return Load(asm.FullName);
+ }
+
+ public RawModule OpenRawModule(string path)
+ {
+ path = Path.GetFullPath(path);
+ FileStream fs = null;
+ RawModule module;
+ try
+ {
+ fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
+ module = OpenRawModule(fs, path);
+ if (!MetadataOnly)
+ {
+ fs = null;
+ }
+ }
+ finally
+ {
+ if (fs != null)
+ {
+ fs.Dispose();
+ }
+ }
+ return module;
+ }
+
+ public RawModule OpenRawModule(Stream stream, string location)
+ {
+ return OpenRawModule(stream, location, false);
+ }
+
+ public RawModule OpenMappedRawModule(Stream stream, string location)
+ {
+ return OpenRawModule(stream, location, true);
+ }
+
+ private RawModule OpenRawModule(Stream stream, string location, bool mapped)
+ {
+ if (!stream.CanRead || !stream.CanSeek || stream.Position != 0)
+ {
+ throw new ArgumentException("Stream must support read/seek and current position must be zero.", "stream");
+ }
+ return new RawModule(new ModuleReader(null, this, stream, location, mapped));
+ }
+
+ public Assembly LoadAssembly(RawModule module)
+ {
+ string refname = module.GetAssemblyName().FullName;
+ Assembly asm = GetLoadedAssembly(refname);
+ if (asm == null)
+ {
+ AssemblyReader asm1 = module.ToAssembly();
+ assemblies.Add(asm1);
+ asm = asm1;
+ }
+ return asm;
+ }
+
+ public Assembly LoadFile(string path)
+ {
+ try
+ {
+ using (RawModule module = OpenRawModule(path))
+ {
+ return LoadAssembly(module);
+ }
+ }
+ catch (IOException x)
+ {
+ throw new FileNotFoundException(x.Message, x);
+ }
+ catch (UnauthorizedAccessException x)
+ {
+ throw new FileNotFoundException(x.Message, x);
+ }
+ }
+
+ private static string GetSimpleAssemblyName(string refname)
+ {
+ int pos;
+ string name;
+ if (Fusion.ParseAssemblySimpleName(refname, out pos, out name) != ParseAssemblyResult.OK)
+ {
+ throw new ArgumentException();
+ }
+ return name;
+ }
+
+ Assembly GetLoadedAssembly(string refname)
+ {
+ if (!assembliesByName.TryGetValue(refname, out var asm) && (options & UniverseOptions.DisableDefaultAssembliesLookup) == 0)
+ {
+ var simpleName = GetSimpleAssemblyName(refname);
+ for (int i = 0; i < assemblies.Count; i++)
+ {
+ if (simpleName.Equals(assemblies[i].Name, StringComparison.OrdinalIgnoreCase) && CompareAssemblyIdentity(refname, false, assemblies[i].FullName, false, out var result))
+ {
+ asm = assemblies[i];
+ assembliesByName.Add(refname, asm);
+ break;
+ }
+ }
+ }
+
+ return asm;
+ }
+
+ Assembly GetDynamicAssembly(string refname)
+ {
+ var simpleName = GetSimpleAssemblyName(refname);
+ foreach (var asm in dynamicAssemblies)
+ if (simpleName.Equals(asm.Name, StringComparison.OrdinalIgnoreCase) && CompareAssemblyIdentity(refname, false, asm.FullName, false, out var result))
+ return asm;
+
+ return null;
+ }
+
+ public Assembly Load(string refname)
+ {
+ return Load(refname, null, true);
+ }
+
+ internal Assembly Load(string refname, Module requestingModule, bool throwOnError)
+ {
+ var asm = GetLoadedAssembly(refname);
+ if (asm != null)
+ return asm;
+
+ if (resolvers.Count == 0)
+ {
+ asm = DefaultResolver(refname, throwOnError);
+ }
+ else
+ {
+ var args = new ResolveEventArgs(refname, requestingModule == null ? null : requestingModule.Assembly);
+ foreach (var evt in resolvers)
+ {
+ asm = evt(this, args);
+ if (asm != null)
+ break;
+ }
+
+ if (asm == null)
+ asm = GetDynamicAssembly(refname);
+ }
+
+ if (asm != null)
+ {
+ var defname = asm.FullName;
+ if (refname != defname)
+ assembliesByName.Add(refname, asm);
+
+ return asm;
+ }
+
+ if (throwOnError)
+ throw new FileNotFoundException(refname);
+
+ return null;
+ }
+
+ private Assembly DefaultResolver(string refname, bool throwOnError)
+ {
+ Assembly asm = GetDynamicAssembly(refname);
+ if (asm != null)
+ return asm;
+
+#if NETFRAMEWORK
+
string fileName;
if (throwOnError)
{
@@ -797,454 +827,442 @@ public Assembly DefaultResolver(string refname, bool throwOnError)
return null;
}
}
- return LoadFile(fileName);
-#endif
- }
-
- public Type GetType(string assemblyQualifiedTypeName)
- {
- // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
- // import that assembly and pass it as the context, but implicitly importing is considered evil
- return GetType(null, assemblyQualifiedTypeName, false, false);
- }
-
- public Type GetType(string assemblyQualifiedTypeName, bool throwOnError)
- {
- // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
- // import that assembly and pass it as the context, but implicitly importing is considered evil
- return GetType(null, assemblyQualifiedTypeName, throwOnError, false);
- }
-
- public Type GetType(string assemblyQualifiedTypeName, bool throwOnError, bool ignoreCase)
- {
- // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
- // import that assembly and pass it as the context, but implicitly importing is considered evil
- return GetType(null, assemblyQualifiedTypeName, throwOnError, ignoreCase);
- }
-
- // note that context is slightly different from the calling assembly (System.Type.GetType),
- // because context is passed to the AssemblyResolve event as the RequestingAssembly
- public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError)
- {
- return GetType(context, assemblyQualifiedTypeName, throwOnError, false);
- }
-
- // note that context is slightly different from the calling assembly (System.Type.GetType),
- // because context is passed to the AssemblyResolve event as the RequestingAssembly
- public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError, bool ignoreCase)
- {
- TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, throwOnError);
- if (parser.Error)
- {
- return null;
- }
- return parser.GetType(this, context == null ? null : context.ManifestModule, throwOnError, assemblyQualifiedTypeName, false, ignoreCase);
- }
-
- // this is similar to GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError),
- // but instead it assumes that the type must exist (i.e. if EnableMissingMemberResolution is enabled
- // it will create a missing type)
- public Type ResolveType(Assembly context, string assemblyQualifiedTypeName)
- {
- TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, false);
- if (parser.Error)
- {
- return null;
- }
- return parser.GetType(this, context == null ? null : context.ManifestModule, false, assemblyQualifiedTypeName, true, false);
- }
- public Type GetBuiltInType(string ns, string name)
- {
- if (ns != "System")
- {
- return null;
- }
- switch (name)
- {
- case "Boolean":
- return System_Boolean;
- case "Char":
- return System_Char;
- case "Object":
- return System_Object;
- case "String":
- return System_String;
- case "Single":
- return System_Single;
- case "Double":
- return System_Double;
- case "SByte":
- return System_SByte;
- case "Int16":
- return System_Int16;
- case "Int32":
- return System_Int32;
- case "Int64":
- return System_Int64;
- case "IntPtr":
- return System_IntPtr;
- case "UIntPtr":
- return System_UIntPtr;
- case "TypedReference":
- return System_TypedReference;
- case "Byte":
- return System_Byte;
- case "UInt16":
- return System_UInt16;
- case "UInt32":
- return System_UInt32;
- case "UInt64":
- return System_UInt64;
- case "Void":
- return System_Void;
- default:
- return null;
- }
- }
-
- public Assembly[] GetAssemblies()
- {
- Assembly[] array = new Assembly[assemblies.Count + dynamicAssemblies.Count];
- for (int i = 0; i < assemblies.Count; i++)
- {
- array[i] = assemblies[i];
- }
- for (int i = 0, j = assemblies.Count; j < array.Length; i++, j++)
- {
- array[j] = dynamicAssemblies[i];
- }
- return array;
- }
-
- // this is equivalent to the Fusion CompareAssemblyIdentity API
- public bool CompareAssemblyIdentity(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
- {
-#if CORECLR
- return Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
-#else
- return useNativeFusion
- ? Fusion.CompareAssemblyIdentityNative(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result)
- : Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
-#endif
- }
-
- public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
- {
- return new AssemblyBuilder(this, name, null, null);
- }
-
- public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable assemblyAttributes)
- {
- return new AssemblyBuilder(this, name, null, assemblyAttributes);
- }
-
- public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir)
- {
- return new AssemblyBuilder(this, name, dir, null);
- }
-
-#if !CORECLR
-#if NET_4_0
- [Obsolete]
-#endif
- public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
- {
- AssemblyBuilder ab = new AssemblyBuilder(this, name, dir, null);
- AddLegacyPermissionSet(ab, requiredPermissions, System.Security.Permissions.SecurityAction.RequestMinimum);
- AddLegacyPermissionSet(ab, optionalPermissions, System.Security.Permissions.SecurityAction.RequestOptional);
- AddLegacyPermissionSet(ab, refusedPermissions, System.Security.Permissions.SecurityAction.RequestRefuse);
- return ab;
- }
-
- private static void AddLegacyPermissionSet(AssemblyBuilder ab, PermissionSet permissionSet, System.Security.Permissions.SecurityAction action)
- {
- if (permissionSet != null)
- {
- ab.__AddDeclarativeSecurity(CustomAttributeBuilder.__FromBlob(CustomAttributeBuilder.LegacyPermissionSet, (int)action, Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString())));
- }
- }
-#endif
-
- internal void RegisterDynamicAssembly(AssemblyBuilder asm)
- {
- dynamicAssemblies.Add(asm);
- }
-
- internal void RenameAssembly(Assembly assembly, AssemblyName oldName)
- {
- List remove = new List();
- foreach (KeyValuePair kv in assembliesByName)
- {
- if (kv.Value == assembly)
- {
- remove.Add(kv.Key);
- }
- }
- foreach (string key in remove)
- {
- assembliesByName.Remove(key);
- }
- }
-
- public void Dispose()
- {
- foreach (Assembly asm in assemblies)
- {
- foreach (Module mod in asm.GetLoadedModules())
- {
- mod.Dispose();
- }
- }
- foreach (AssemblyBuilder asm in dynamicAssemblies)
- {
- foreach (Module mod in asm.GetLoadedModules())
- {
- mod.Dispose();
- }
- }
- }
-
- public Assembly CreateMissingAssembly(string assemblyName)
- {
- Assembly asm = new MissingAssembly(this, assemblyName);
- string name = asm.FullName;
- if (!assembliesByName.ContainsKey(name))
- {
- assembliesByName.Add(name, asm);
- }
- return asm;
- }
-
- [Obsolete("Please set UniverseOptions.ResolveMissingMembers instead.")]
- public void EnableMissingMemberResolution()
- {
- resolveMissingMembers = true;
- }
-
- internal bool MissingMemberResolution
- {
- get { return resolveMissingMembers; }
- }
-
- internal bool EnableFunctionPointers
- {
- get { return enableFunctionPointers; }
- }
-
- private struct ScopedTypeName : IEquatable
- {
- private readonly object scope;
- private readonly TypeName name;
-
- internal ScopedTypeName(object scope, TypeName name)
- {
- this.scope = scope;
- this.name = name;
- }
-
- public override bool Equals(object obj)
- {
- ScopedTypeName? other = obj as ScopedTypeName?;
- return other != null && ((IEquatable)other.Value).Equals(this);
- }
-
- public override int GetHashCode()
- {
- return scope.GetHashCode() * 7 + name.GetHashCode();
- }
-
- bool IEquatable.Equals(ScopedTypeName other)
- {
- return other.scope == scope && other.name == name;
- }
- }
-
- private Type GetMissingType(Module requester, Module module, Type declaringType, TypeName typeName)
- {
- if (missingTypes == null)
- {
- missingTypes = new Dictionary();
- }
- ScopedTypeName stn = new ScopedTypeName(declaringType ?? (object)module, typeName);
- Type type;
- if (!missingTypes.TryGetValue(stn, out type))
- {
- type = new MissingType(module, declaringType, typeName.Namespace, typeName.Name);
- missingTypes.Add(stn, type);
- }
- if (ResolvedMissingMember != null && !module.Assembly.__IsMissing)
- {
- ResolvedMissingMember(requester, type);
- }
- return type;
- }
-
- internal Type GetMissingTypeOrThrow(Module requester, Module module, Type declaringType, TypeName typeName)
- {
- if (resolveMissingMembers || module.Assembly.__IsMissing)
- {
- return GetMissingType(requester, module, declaringType, typeName);
- }
- string fullName = TypeNameParser.Escape(typeName.ToString());
- if (declaringType != null)
- {
- fullName = declaringType.FullName + "+" + fullName;
- }
- throw new TypeLoadException(String.Format("Type '{0}' not found in assembly '{1}'", fullName, module.Assembly.FullName));
- }
-
- internal MethodBase GetMissingMethodOrThrow(Module requester, Type declaringType, string name, MethodSignature signature)
- {
- if (resolveMissingMembers)
- {
- MethodBase method = new MissingMethod(declaringType, name, signature);
- if (name == ".ctor")
- {
- method = new ConstructorInfoImpl((MethodInfo)method);
- }
- if (ResolvedMissingMember != null)
- {
- ResolvedMissingMember(requester, method);
- }
- return method;
- }
-#if CORECLR
- throw new MissingMethodException(declaringType.ToString() + "." + name);
-#else
- throw new MissingMethodException(declaringType.ToString(), name);
-#endif
- }
-
- internal FieldInfo GetMissingFieldOrThrow(Module requester, Type declaringType, string name, FieldSignature signature)
- {
- if (resolveMissingMembers)
- {
- FieldInfo field = new MissingField(declaringType, name, signature);
- if (ResolvedMissingMember != null)
- {
- ResolvedMissingMember(requester, field);
- }
- return field;
- }
-#if CORECLR
- throw new MissingFieldException(declaringType.ToString() + "." + name);
+ return LoadFile(fileName);
#else
- throw new MissingFieldException(declaringType.ToString(), name);
+ return null;
#endif
- }
-
- internal PropertyInfo GetMissingPropertyOrThrow(Module requester, Type declaringType, string name, PropertySignature propertySignature)
- {
- // HACK we need to check __IsMissing here, because Type doesn't have a FindProperty API
- // since properties are never resolved, except by custom attributes
- if (resolveMissingMembers || declaringType.__IsMissing)
- {
- PropertyInfo property = new MissingProperty(declaringType, name, propertySignature);
- if (ResolvedMissingMember != null && !declaringType.__IsMissing)
- {
- ResolvedMissingMember(requester, property);
- }
- return property;
- }
-#if CORECLR
- throw new System.MissingMemberException(declaringType.ToString() + "." + name);
-#else
- throw new System.MissingMemberException(declaringType.ToString(), name);
+ }
+
+ public Type GetType(string assemblyQualifiedTypeName)
+ {
+ // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
+ // import that assembly and pass it as the context, but implicitly importing is considered evil
+ return GetType(null, assemblyQualifiedTypeName, false, false);
+ }
+
+ public Type GetType(string assemblyQualifiedTypeName, bool throwOnError)
+ {
+ // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
+ // import that assembly and pass it as the context, but implicitly importing is considered evil
+ return GetType(null, assemblyQualifiedTypeName, throwOnError, false);
+ }
+
+ public Type GetType(string assemblyQualifiedTypeName, bool throwOnError, bool ignoreCase)
+ {
+ // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
+ // import that assembly and pass it as the context, but implicitly importing is considered evil
+ return GetType(null, assemblyQualifiedTypeName, throwOnError, ignoreCase);
+ }
+
+ // note that context is slightly different from the calling assembly (System.Type.GetType),
+ // because context is passed to the AssemblyResolve event as the RequestingAssembly
+ public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError)
+ {
+ return GetType(context, assemblyQualifiedTypeName, throwOnError, false);
+ }
+
+ // note that context is slightly different from the calling assembly (System.Type.GetType),
+ // because context is passed to the AssemblyResolve event as the RequestingAssembly
+ public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError, bool ignoreCase)
+ {
+ TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, throwOnError);
+ if (parser.Error)
+ {
+ return null;
+ }
+ return parser.GetType(this, context == null ? null : context.ManifestModule, throwOnError, assemblyQualifiedTypeName, false, ignoreCase);
+ }
+
+ // this is similar to GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError),
+ // but instead it assumes that the type must exist (i.e. if EnableMissingMemberResolution is enabled
+ // it will create a missing type)
+ public Type ResolveType(Assembly context, string assemblyQualifiedTypeName)
+ {
+ TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, false);
+ if (parser.Error)
+ {
+ return null;
+ }
+ return parser.GetType(this, context == null ? null : context.ManifestModule, false, assemblyQualifiedTypeName, true, false);
+ }
+
+ public Type GetBuiltInType(string ns, string name)
+ {
+ if (ns != "System")
+ {
+ return null;
+ }
+ switch (name)
+ {
+ case "Boolean":
+ return System_Boolean;
+ case "Char":
+ return System_Char;
+ case "Object":
+ return System_Object;
+ case "String":
+ return System_String;
+ case "Single":
+ return System_Single;
+ case "Double":
+ return System_Double;
+ case "SByte":
+ return System_SByte;
+ case "Int16":
+ return System_Int16;
+ case "Int32":
+ return System_Int32;
+ case "Int64":
+ return System_Int64;
+ case "IntPtr":
+ return System_IntPtr;
+ case "UIntPtr":
+ return System_UIntPtr;
+ case "TypedReference":
+ return System_TypedReference;
+ case "Byte":
+ return System_Byte;
+ case "UInt16":
+ return System_UInt16;
+ case "UInt32":
+ return System_UInt32;
+ case "UInt64":
+ return System_UInt64;
+ case "Void":
+ return System_Void;
+ default:
+ return null;
+ }
+ }
+
+ public Assembly[] GetAssemblies()
+ {
+ Assembly[] array = new Assembly[assemblies.Count + dynamicAssemblies.Count];
+ for (int i = 0; i < assemblies.Count; i++)
+ {
+ array[i] = assemblies[i];
+ }
+ for (int i = 0, j = assemblies.Count; j < array.Length; i++, j++)
+ {
+ array[j] = dynamicAssemblies[i];
+ }
+ return array;
+ }
+
+ public bool CompareAssemblyIdentity(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
+ {
+ return useNativeFusion
+ ? Fusion.CompareAssemblyIdentityNative(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result)
+ : Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
+ }
+
+ public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
+ {
+ return new AssemblyBuilder(this, name, null, null);
+ }
+
+ public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable assemblyAttributes)
+ {
+ return new AssemblyBuilder(this, name, null, assemblyAttributes);
+ }
+
+ public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir)
+ {
+ return new AssemblyBuilder(this, name, dir, null);
+ }
+
+ [Obsolete]
+ public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
+ {
+ AssemblyBuilder ab = new AssemblyBuilder(this, name, dir, null);
+ AddLegacyPermissionSet(ab, requiredPermissions, System.Security.Permissions.SecurityAction.RequestMinimum);
+ AddLegacyPermissionSet(ab, optionalPermissions, System.Security.Permissions.SecurityAction.RequestOptional);
+ AddLegacyPermissionSet(ab, refusedPermissions, System.Security.Permissions.SecurityAction.RequestRefuse);
+ return ab;
+ }
+
+#if NET6_0_OR_GREATER
+ [Obsolete]
#endif
- }
-
- internal Type CanonicalizeType(Type type)
- {
- Type canon;
- if (!canonicalizedTypes.TryGetValue(type, out canon))
- {
- canon = type;
- canonicalizedTypes.Add(canon, canon);
- }
- return canon;
- }
-
- public Type MakeFunctionPointer(__StandAloneMethodSig sig)
- {
- return FunctionPointerType.Make(this, sig);
- }
-
- public __StandAloneMethodSig MakeStandAloneMethodSig(System.Runtime.InteropServices.CallingConvention callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
- {
- return new __StandAloneMethodSig(true, callingConvention, 0, returnType ?? this.System_Void, Util.Copy(parameterTypes), Type.EmptyTypes,
- PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
- }
-
- public __StandAloneMethodSig MakeStandAloneMethodSig(CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, Type[] optionalParameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
- {
- return new __StandAloneMethodSig(false, 0, callingConvention, returnType ?? this.System_Void, Util.Copy(parameterTypes), Util.Copy(optionalParameterTypes),
- PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes) + Util.NullSafeLength(optionalParameterTypes)));
- }
-
- public event ResolvedMissingMemberHandler ResolvedMissingMember;
-
- public event Predicate MissingTypeIsValueType
- {
- add
- {
- if (missingTypeIsValueType != null)
- {
- throw new InvalidOperationException("Only a single MissingTypeIsValueType handler can be registered.");
- }
- missingTypeIsValueType = value;
- }
- remove
- {
- if (value.Equals(missingTypeIsValueType))
- {
- missingTypeIsValueType = null;
- }
- }
- }
-
- public static Universe FromAssembly(Assembly assembly)
- {
- return assembly.universe;
- }
-
- internal bool ResolveMissingTypeIsValueType(MissingType missingType)
- {
- if (missingTypeIsValueType != null)
- {
- return missingTypeIsValueType(missingType);
- }
- throw new MissingMemberException(missingType);
- }
-
- internal bool ReturnPseudoCustomAttributes
- {
- get { return returnPseudoCustomAttributes; }
- }
-
- internal bool AutomaticallyProvideDefaultConstructor
- {
- get { return automaticallyProvideDefaultConstructor; }
- }
-
- internal bool MetadataOnly
- {
- get { return (options & UniverseOptions.MetadataOnly) != 0; }
- }
-
- internal bool WindowsRuntimeProjection
- {
- get { return (options & UniverseOptions.DisableWindowsRuntimeProjection) == 0; }
- }
-
- internal bool DecodeVersionInfoAttributeBlobs
- {
- get { return (options & UniverseOptions.DecodeVersionInfoAttributeBlobs) != 0; }
- }
-
- internal bool Deterministic
- {
- get { return (options & UniverseOptions.DeterministicOutput) != 0; }
- }
- }
+ private static void AddLegacyPermissionSet(AssemblyBuilder ab, PermissionSet permissionSet, System.Security.Permissions.SecurityAction action)
+ {
+ if (permissionSet != null)
+ {
+ ab.__AddDeclarativeSecurity(CustomAttributeBuilder.__FromBlob(CustomAttributeBuilder.LegacyPermissionSet, (int)action, Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString())));
+ }
+ }
+
+ internal void RegisterDynamicAssembly(AssemblyBuilder asm)
+ {
+ dynamicAssemblies.Add(asm);
+ }
+
+ internal void RenameAssembly(Assembly assembly, AssemblyName oldName)
+ {
+ List remove = new List();
+ foreach (KeyValuePair kv in assembliesByName)
+ {
+ if (kv.Value == assembly)
+ {
+ remove.Add(kv.Key);
+ }
+ }
+ foreach (string key in remove)
+ {
+ assembliesByName.Remove(key);
+ }
+ }
+
+ public void Dispose()
+ {
+ foreach (Assembly asm in assemblies)
+ {
+ foreach (Module mod in asm.GetLoadedModules())
+ {
+ mod.Dispose();
+ }
+ }
+ foreach (AssemblyBuilder asm in dynamicAssemblies)
+ {
+ foreach (Module mod in asm.GetLoadedModules())
+ {
+ mod.Dispose();
+ }
+ }
+ }
+
+ public Assembly CreateMissingAssembly(string assemblyName)
+ {
+ Assembly asm = new MissingAssembly(this, assemblyName);
+ string name = asm.FullName;
+ if (!assembliesByName.ContainsKey(name))
+ {
+ assembliesByName.Add(name, asm);
+ }
+ return asm;
+ }
+
+ [Obsolete("Please set UniverseOptions.ResolveMissingMembers instead.")]
+ public void EnableMissingMemberResolution()
+ {
+ resolveMissingMembers = true;
+ }
+
+ internal bool MissingMemberResolution
+ {
+ get { return resolveMissingMembers; }
+ }
+
+ internal bool EnableFunctionPointers
+ {
+ get { return enableFunctionPointers; }
+ }
+
+ private struct ScopedTypeName : IEquatable
+ {
+ private readonly object scope;
+ private readonly TypeName name;
+
+ internal ScopedTypeName(object scope, TypeName name)
+ {
+ this.scope = scope;
+ this.name = name;
+ }
+
+ public override bool Equals(object obj)
+ {
+ ScopedTypeName? other = obj as ScopedTypeName?;
+ return other != null && ((IEquatable)other.Value).Equals(this);
+ }
+
+ public override int GetHashCode()
+ {
+ return scope.GetHashCode() * 7 + name.GetHashCode();
+ }
+
+ bool IEquatable.Equals(ScopedTypeName other)
+ {
+ return other.scope == scope && other.name == name;
+ }
+ }
+
+ private Type GetMissingType(Module requester, Module module, Type declaringType, TypeName typeName)
+ {
+ if (missingTypes == null)
+ {
+ missingTypes = new Dictionary();
+ }
+ ScopedTypeName stn = new ScopedTypeName(declaringType ?? (object)module, typeName);
+ Type type;
+ if (!missingTypes.TryGetValue(stn, out type))
+ {
+ type = new MissingType(module, declaringType, typeName.Namespace, typeName.Name);
+ missingTypes.Add(stn, type);
+ }
+ if (ResolvedMissingMember != null && !module.Assembly.__IsMissing)
+ {
+ ResolvedMissingMember(requester, type);
+ }
+ return type;
+ }
+
+ internal Type GetMissingTypeOrThrow(Module requester, Module module, Type declaringType, TypeName typeName)
+ {
+ if (resolveMissingMembers || module.Assembly.__IsMissing)
+ {
+ return GetMissingType(requester, module, declaringType, typeName);
+ }
+ string fullName = TypeNameParser.Escape(typeName.ToString());
+ if (declaringType != null)
+ {
+ fullName = declaringType.FullName + "+" + fullName;
+ }
+ throw new TypeLoadException(String.Format("Type '{0}' not found in assembly '{1}'", fullName, module.Assembly.FullName));
+ }
+
+ internal MethodBase GetMissingMethodOrThrow(Module requester, Type declaringType, string name, MethodSignature signature)
+ {
+ if (resolveMissingMembers)
+ {
+ MethodBase method = new MissingMethod(declaringType, name, signature);
+ if (name == ".ctor")
+ {
+ method = new ConstructorInfoImpl((MethodInfo)method);
+ }
+ if (ResolvedMissingMember != null)
+ {
+ ResolvedMissingMember(requester, method);
+ }
+ return method;
+ }
+
+ throw new MissingMethodException(declaringType.ToString(), name);
+ }
+
+ internal FieldInfo GetMissingFieldOrThrow(Module requester, Type declaringType, string name, FieldSignature signature)
+ {
+ if (resolveMissingMembers)
+ {
+ FieldInfo field = new MissingField(declaringType, name, signature);
+ if (ResolvedMissingMember != null)
+ {
+ ResolvedMissingMember(requester, field);
+ }
+ return field;
+ }
+
+ throw new MissingFieldException(declaringType.ToString(), name);
+ }
+
+ internal PropertyInfo GetMissingPropertyOrThrow(Module requester, Type declaringType, string name, PropertySignature propertySignature)
+ {
+ // HACK we need to check __IsMissing here, because Type doesn't have a FindProperty API
+ // since properties are never resolved, except by custom attributes
+ if (resolveMissingMembers || declaringType.__IsMissing)
+ {
+ PropertyInfo property = new MissingProperty(declaringType, name, propertySignature);
+ if (ResolvedMissingMember != null && !declaringType.__IsMissing)
+ {
+ ResolvedMissingMember(requester, property);
+ }
+ return property;
+ }
+
+ throw new System.MissingMemberException(declaringType.ToString(), name);
+ }
+
+ internal Type CanonicalizeType(Type type)
+ {
+ Type canon;
+ if (!canonicalizedTypes.TryGetValue(type, out canon))
+ {
+ canon = type;
+ canonicalizedTypes.Add(canon, canon);
+ }
+ return canon;
+ }
+
+ public Type MakeFunctionPointer(__StandAloneMethodSig sig)
+ {
+ return FunctionPointerType.Make(this, sig);
+ }
+
+ public __StandAloneMethodSig MakeStandAloneMethodSig(System.Runtime.InteropServices.CallingConvention callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
+ {
+ return new __StandAloneMethodSig(true, callingConvention, 0, returnType ?? this.System_Void, Util.Copy(parameterTypes), Type.EmptyTypes,
+ PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
+ }
+
+ public __StandAloneMethodSig MakeStandAloneMethodSig(CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, Type[] optionalParameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
+ {
+ return new __StandAloneMethodSig(false, 0, callingConvention, returnType ?? this.System_Void, Util.Copy(parameterTypes), Util.Copy(optionalParameterTypes),
+ PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes) + Util.NullSafeLength(optionalParameterTypes)));
+ }
+
+ public event ResolvedMissingMemberHandler ResolvedMissingMember;
+
+ public event Predicate MissingTypeIsValueType
+ {
+ add
+ {
+ if (missingTypeIsValueType != null)
+ {
+ throw new InvalidOperationException("Only a single MissingTypeIsValueType handler can be registered.");
+ }
+ missingTypeIsValueType = value;
+ }
+ remove
+ {
+ if (value.Equals(missingTypeIsValueType))
+ {
+ missingTypeIsValueType = null;
+ }
+ }
+ }
+
+ public static Universe FromAssembly(Assembly assembly)
+ {
+ return assembly.universe;
+ }
+
+ internal bool ResolveMissingTypeIsValueType(MissingType missingType)
+ {
+ if (missingTypeIsValueType != null)
+ {
+ return missingTypeIsValueType(missingType);
+ }
+ throw new MissingMemberException(missingType);
+ }
+
+ internal bool ReturnPseudoCustomAttributes
+ {
+ get { return returnPseudoCustomAttributes; }
+ }
+
+ internal bool AutomaticallyProvideDefaultConstructor
+ {
+ get { return automaticallyProvideDefaultConstructor; }
+ }
+
+ internal bool MetadataOnly
+ {
+ get { return (options & UniverseOptions.MetadataOnly) != 0; }
+ }
+
+ internal bool WindowsRuntimeProjection
+ {
+ get { return (options & UniverseOptions.DisableWindowsRuntimeProjection) == 0; }
+ }
+
+ internal bool DecodeVersionInfoAttributeBlobs
+ {
+ get { return (options & UniverseOptions.DecodeVersionInfoAttributeBlobs) != 0; }
+ }
+
+ internal bool Deterministic
+ {
+ get { return (options & UniverseOptions.DeterministicOutput) != 0; }
+ }
+ }
}
diff --git a/src/compiler/backend/ikvm/Util.cs b/src/compiler/backend/ikvm/Util.cs
index 7ca6a0f86..b6bb5c424 100644
--- a/src/compiler/backend/ikvm/Util.cs
+++ b/src/compiler/backend/ikvm/Util.cs
@@ -26,15 +26,13 @@ Jeroen Frijters
namespace IKVM.Reflection
{
- public interface ICustomAttributeProvider
+ public interface ICustomAttributeProvider
{
bool IsDefined(Type attributeType, bool inherit);
IList __GetCustomAttributes(Type attributeType, bool inherit);
}
-#if !CORECLR
[Serializable]
-#endif
public sealed class FileFormatLimitationExceededException : InvalidOperationException
{
public const int META_E_STRINGSPACE_FULL = unchecked((int)0x80131198);
@@ -45,12 +43,10 @@ public FileFormatLimitationExceededException(string message, int hresult)
this.HResult = hresult;
}
-#if !CORECLR
private FileFormatLimitationExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
-#endif
public int ErrorCode
{
@@ -58,19 +54,14 @@ public int ErrorCode
}
}
-#if !CORECLR
[Serializable]
-#endif
public sealed class Missing
-#if !CORECLR
: System.Runtime.Serialization.ISerializable
-#endif
{
public static readonly Missing Value = new Missing();
private Missing() { }
-#if !CORECLR
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
{
info.SetType(typeof(SingletonSerializationHelper));
@@ -84,7 +75,6 @@ public object GetRealObject(System.Runtime.Serialization.StreamingContext contex
return Value;
}
}
-#endif
}
static class Empty
@@ -263,4 +253,37 @@ internal static float Int32BitsToSingle(int v)
return c.f;
}
}
+
+ static class TypeUtil
+ {
+ internal static bool IsEnum(System.Type type)
+ {
+ return type.IsEnum;
+ }
+
+ internal static System.Reflection.Assembly GetAssembly(System.Type type)
+ {
+ return type.Assembly;
+ }
+
+ internal static System.Reflection.MethodBase GetDeclaringMethod(System.Type type)
+ {
+ return type.DeclaringMethod;
+ }
+
+ internal static bool IsGenericType(System.Type type)
+ {
+ return type.IsGenericType;
+ }
+
+ internal static bool IsGenericTypeDefinition(System.Type type)
+ {
+ return type.IsGenericTypeDefinition;
+ }
+
+ internal static System.Type[] GetGenericArguments(System.Type type)
+ {
+ return type.GetGenericArguments();
+ }
+ }
}
diff --git a/src/compiler/backend/ikvm/Writer/ModuleWriter.cs b/src/compiler/backend/ikvm/Writer/ModuleWriter.cs
index 8edaecf6c..26eaa3cc1 100644
--- a/src/compiler/backend/ikvm/Writer/ModuleWriter.cs
+++ b/src/compiler/backend/ikvm/Writer/ModuleWriter.cs
@@ -352,13 +352,11 @@ private static void WriteModuleImpl(StrongNameKeyPair keyPair, byte[] publicKey,
StrongName(stream, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength);
}
-#if !NO_SYMBOL_WRITER
if (moduleBuilder.symbolWriter != null)
{
moduleBuilder.WriteSymbolTokenMap();
moduleBuilder.symbolWriter.Close();
}
-#endif
}
private static int ComputeStrongNameSignatureLength(byte[] publicKey)
@@ -382,86 +380,162 @@ private static int ComputeStrongNameSignatureLength(byte[] publicKey)
private static void StrongName(Stream stream, StrongNameKeyPair keyPair, uint headerLength, uint textSectionFileOffset, uint strongNameSignatureFileOffset, uint strongNameSignatureLength)
{
- using (var hash = SHA1.Create())
+ byte[] hash;
+ using (SHA1 sha1 = SHA1.Create())
{
- using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
- {
- stream.Seek(0, SeekOrigin.Begin);
- byte[] buf = new byte[8192];
- HashChunk(stream, cs, buf, (int)headerLength);
- stream.Seek(textSectionFileOffset, SeekOrigin.Begin);
- HashChunk(stream, cs, buf, (int)(strongNameSignatureFileOffset - textSectionFileOffset));
- stream.Seek(strongNameSignatureLength, SeekOrigin.Current);
- HashChunk(stream, cs, buf, (int)(stream.Length - (strongNameSignatureFileOffset + strongNameSignatureLength)));
- }
- using (RSA rsa = keyPair.CreateRSA())
+ stream.Seek(0, SeekOrigin.Begin);
+ Stream skipStream = new SkipStream(stream, strongNameSignatureFileOffset, strongNameSignatureLength);
+ skipStream = new SkipStream(skipStream, headerLength, textSectionFileOffset - headerLength);
+ hash = sha1.ComputeHash(skipStream);
+ }
+ using (RSACryptoServiceProvider rsa = keyPair.CreateRSA())
+ {
+ byte[] signature = rsa.SignHash(hash, "1.3.14.3.2.26");
+ Array.Reverse(signature);
+ if (signature.Length != strongNameSignatureLength)
{
- RSAPKCS1SignatureFormatter sign = new RSAPKCS1SignatureFormatter(rsa);
- byte[] signature = sign.CreateSignature(hash);
- Array.Reverse(signature);
- if (signature.Length != strongNameSignatureLength)
- {
- throw new InvalidOperationException("Signature length mismatch");
- }
- stream.Seek(strongNameSignatureFileOffset, SeekOrigin.Begin);
- stream.Write(signature, 0, signature.Length);
+ throw new InvalidOperationException("Signature length mismatch");
}
+ stream.Seek(strongNameSignatureFileOffset, SeekOrigin.Begin);
+ stream.Write(signature, 0, signature.Length);
+ }
+
+ // compute the PE checksum
+ stream.Seek(0, SeekOrigin.Begin);
+ int count = (int)stream.Length / 4;
+ BinaryReader br = new BinaryReader(stream);
+ long sum = 0;
+ for (int i = 0; i < count; i++)
+ {
+ sum += br.ReadUInt32();
+ int carry = (int)(sum >> 32);
+ sum &= 0xFFFFFFFFU;
+ sum += carry;
+ }
+ while ((sum >> 16) != 0)
+ {
+ sum = (sum & 0xFFFF) + (sum >> 16);
+ }
+ sum += stream.Length;
+
+ // write the PE checksum, note that it is always at offset 0xD8 in the file
+ ByteBuffer bb = new ByteBuffer(4);
+ bb.Write((int)sum);
+ stream.Seek(0xD8, SeekOrigin.Begin);
+ bb.WriteTo(stream);
+ }
- // compute the PE checksum
+ private static Guid GenerateModuleVersionId(Stream stream)
+ {
+ byte[] hash;
+ using (SHA1 sha1 = SHA1.Create())
+ {
stream.Seek(0, SeekOrigin.Begin);
- int count = (int)stream.Length / 4;
- BinaryReader br = new BinaryReader(stream);
- long sum = 0;
- for (int i = 0; i < count; i++)
- {
- sum += br.ReadUInt32();
- int carry = (int)(sum >> 32);
- sum &= 0xFFFFFFFFU;
- sum += carry;
- }
- while ((sum >> 16) != 0)
- {
- sum = (sum & 0xFFFF) + (sum >> 16);
- }
- sum += stream.Length;
+ hash = sha1.ComputeHash(stream);
+ }
+ byte[] bytes = new byte[16];
+ Buffer.BlockCopy(hash, 0, bytes, 0, bytes.Length);
+ // set GUID type to "version 4" (random)
+ bytes[7] &= 0x0F;
+ bytes[7] |= 0x40;
+ bytes[8] &= 0x3F;
+ bytes[8] |= 0x80;
+ return new Guid(bytes);
+ }
+ }
+
+ sealed class SkipStream : Stream
+ {
+ private readonly Stream stream;
+ private long skipOffset;
+ private long skipLength;
- // write the PE checksum, note that it is always at offset 0xD8 in the file
- ByteBuffer bb = new ByteBuffer(4);
- bb.Write((int)sum);
- stream.Seek(0xD8, SeekOrigin.Begin);
- bb.WriteTo(stream);
+ internal SkipStream(Stream stream, long skipOffset, long skipLength)
+ {
+ if (skipOffset < 0 || skipLength < 0)
+ {
+ throw new ArgumentOutOfRangeException();
}
+ this.stream = stream;
+ this.skipOffset = skipOffset;
+ this.skipLength = skipLength;
}
- internal static void HashChunk(Stream stream, CryptoStream cs, byte[] buf, int length)
+ protected override void Dispose(bool disposing)
{
- while (length > 0)
+ if (disposing)
{
- int read = stream.Read(buf, 0, Math.Min(buf.Length, length));
- cs.Write(buf, 0, read);
- length -= read;
+ stream.Dispose();
}
}
- private static Guid GenerateModuleVersionId(Stream stream)
+ public override bool CanRead
+ {
+ get { return stream.CanRead; }
+ }
+
+ public override bool CanSeek
+ {
+ get { return false; }
+ }
+
+ public override bool CanWrite
+ {
+ get { return false; }
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
{
- using (var hash = SHA1.Create())
+ if (skipLength != 0 && skipOffset < count)
{
- using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
+ if (skipOffset != 0)
{
- stream.Seek(0, SeekOrigin.Begin);
- byte[] buf = new byte[8192];
- HashChunk(stream, cs, buf, (int)stream.Length);
+ count = (int)skipOffset;
+ }
+ else
+ {
+ // note that we loop forever if the skipped part lies beyond EOF
+ while (skipLength != 0)
+ {
+ // use the output buffer as scratch space
+ skipLength -= stream.Read(buffer, offset, (int)Math.Min(count, skipLength));
+ }
}
- byte[] bytes = new byte[16];
- Buffer.BlockCopy(hash.Hash, 0, bytes, 0, bytes.Length);
- // set GUID type to "version 4" (random)
- bytes[7] &= 0x0F;
- bytes[7] |= 0x40;
- bytes[8] &= 0x3F;
- bytes[8] |= 0x80;
- return new Guid(bytes);
}
+ int totalBytesRead = stream.Read(buffer, offset, count);
+ skipOffset -= totalBytesRead;
+ return totalBytesRead;
+ }
+
+ public override long Length
+ {
+ get { throw new NotSupportedException(); }
+ }
+
+ public override long Position
+ {
+ get { throw new NotSupportedException(); }
+ set { throw new NotSupportedException(); }
+ }
+
+ public override void Flush()
+ {
+ throw new NotSupportedException();
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ throw new NotSupportedException();
}
}
}
diff --git a/src/compiler/backend/ikvm/Writer/VersionInfo.cs b/src/compiler/backend/ikvm/Writer/VersionInfo.cs
index efb65ce2b..a9c39752e 100644
--- a/src/compiler/backend/ikvm/Writer/VersionInfo.cs
+++ b/src/compiler/backend/ikvm/Writer/VersionInfo.cs
@@ -22,155 +22,152 @@ Jeroen Frijters
*/
using System;
-using System.Globalization;
+
using IKVM.Reflection.Emit;
namespace IKVM.Reflection.Writer
{
- sealed class VersionInfo
- {
- private AssemblyName name;
- private string fileName;
- internal string copyright;
- internal string trademark;
- internal string product;
- internal string company;
- private string description;
- private string title;
- internal string informationalVersion;
- private string fileVersion;
+ sealed class VersionInfo
+ {
+ private AssemblyName name;
+ private string fileName;
+ internal string copyright;
+ internal string trademark;
+ internal string product;
+ internal string company;
+ private string description;
+ private string title;
+ internal string informationalVersion;
+ private string fileVersion;
+
+ internal void SetName(AssemblyName name)
+ {
+ this.name = name;
+ }
- internal void SetName(AssemblyName name)
- {
- this.name = name;
- }
+ internal void SetFileName(string assemblyFileName)
+ {
+ this.fileName = System.IO.Path.GetFileName(assemblyFileName);
+ }
- internal void SetFileName(string assemblyFileName)
- {
- this.fileName = System.IO.Path.GetFileName(assemblyFileName);
- }
+ internal void SetAttribute(AssemblyBuilder asm, CustomAttributeBuilder cab)
+ {
+ Universe u = cab.Constructor.Module.universe;
+ Type type = cab.Constructor.DeclaringType;
+ if (copyright == null && type == u.System_Reflection_AssemblyCopyrightAttribute)
+ {
+ copyright = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (trademark == null && type == u.System_Reflection_AssemblyTrademarkAttribute)
+ {
+ trademark = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (product == null && type == u.System_Reflection_AssemblyProductAttribute)
+ {
+ product = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (company == null && type == u.System_Reflection_AssemblyCompanyAttribute)
+ {
+ company = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (description == null && type == u.System_Reflection_AssemblyDescriptionAttribute)
+ {
+ description = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (title == null && type == u.System_Reflection_AssemblyTitleAttribute)
+ {
+ title = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (informationalVersion == null && type == u.System_Reflection_AssemblyInformationalVersionAttribute)
+ {
+ informationalVersion = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ else if (fileVersion == null && type == u.System_Reflection_AssemblyFileVersionAttribute)
+ {
+ fileVersion = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
+ }
+ }
- internal void SetAttribute(AssemblyBuilder asm, CustomAttributeBuilder cab)
- {
- Universe u = cab.Constructor.Module.universe;
- Type type = cab.Constructor.DeclaringType;
- if (copyright == null && type == u.System_Reflection_AssemblyCopyrightAttribute)
- {
- copyright = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (trademark == null && type == u.System_Reflection_AssemblyTrademarkAttribute)
- {
- trademark = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (product == null && type == u.System_Reflection_AssemblyProductAttribute)
- {
- product = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (company == null && type == u.System_Reflection_AssemblyCompanyAttribute)
- {
- company = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (description == null && type == u.System_Reflection_AssemblyDescriptionAttribute)
- {
- description = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (title == null && type == u.System_Reflection_AssemblyTitleAttribute)
- {
- title = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (informationalVersion == null && type == u.System_Reflection_AssemblyInformationalVersionAttribute)
- {
- informationalVersion = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- else if (fileVersion == null && type == u.System_Reflection_AssemblyFileVersionAttribute)
- {
- fileVersion = (string)cab.DecodeBlob(asm).GetConstructorArgument(0);
- }
- }
+ internal void Write(ByteBuffer bb)
+ {
+ if (fileVersion == null)
+ {
+ if (name.Version != null)
+ {
+ fileVersion = name.Version.ToString();
+ }
+ else
+ {
+ fileVersion = "0.0.0.0";
+ }
+ }
- internal void Write(ByteBuffer bb)
- {
- if (fileVersion == null)
- {
- if (name.Version != null)
- {
- fileVersion = name.Version.ToString();
- }
- else
- {
- fileVersion = "0.0.0.0";
- }
- }
+ int codepage = 1200; // Unicode codepage
- int codepage = 1200; // Unicode codepage
- int lcid = 0x7f;
- try
- {
- if (name.CultureInfo != null)
- {
-#if CORECLR
- throw new NotImplementedException();
-#else
- lcid = name.CultureInfo.LCID;
-#endif
- }
- }
- catch (ArgumentException)
- {
- // AssemblyName.CultureInfo throws an ArgumentException if AssemblyBuilder.__SetAssemblyCulture() was used to specify a non-existing culture
- }
+ int lcid = 0x7f;
+ try
+ {
+ if (name.CultureInfo != null)
+ {
+ lcid = name.CultureInfo.LCID;
+ }
+ }
+ catch (ArgumentException)
+ {
+ // AssemblyName.CultureInfo throws an ArgumentException if AssemblyBuilder.__SetAssemblyCulture() was used to specify a non-existing culture
+ }
- Version filever = ParseVersionRobust(fileVersion);
- int fileVersionMajor = filever.Major;
- int fileVersionMinor = filever.Minor;
- int fileVersionBuild = filever.Build;
- int fileVersionRevision = filever.Revision;
+ Version filever = ParseVersionRobust(fileVersion);
+ int fileVersionMajor = filever.Major;
+ int fileVersionMinor = filever.Minor;
+ int fileVersionBuild = filever.Build;
+ int fileVersionRevision = filever.Revision;
- int productVersionMajor = fileVersionMajor;
- int productVersionMinor = fileVersionMinor;
- int productVersionBuild = fileVersionBuild;
- int productVersionRevision = fileVersionRevision;
- if (informationalVersion != null)
- {
- Version productver = ParseVersionRobust(informationalVersion);
- productVersionMajor = productver.Major;
- productVersionMinor = productver.Minor;
- productVersionBuild = productver.Build;
- productVersionRevision = productver.Revision;
- }
+ int productVersionMajor = fileVersionMajor;
+ int productVersionMinor = fileVersionMinor;
+ int productVersionBuild = fileVersionBuild;
+ int productVersionRevision = fileVersionRevision;
+ if (informationalVersion != null)
+ {
+ Version productver = ParseVersionRobust(informationalVersion);
+ productVersionMajor = productver.Major;
+ productVersionMinor = productver.Minor;
+ productVersionBuild = productver.Build;
+ productVersionRevision = productver.Revision;
+ }
- ByteBuffer stringTable = new ByteBuffer(512);
- stringTable.Write((short)0); // wLength (placeholder)
- stringTable.Write((short)0); // wValueLength
- stringTable.Write((short)1); // wType
- WriteUTF16Z(stringTable, string.Format("{0:x4}{1:x4}", lcid, codepage));
- stringTable.Align(4);
+ ByteBuffer stringTable = new ByteBuffer(512);
+ stringTable.Write((short)0); // wLength (placeholder)
+ stringTable.Write((short)0); // wValueLength
+ stringTable.Write((short)1); // wType
+ WriteUTF16Z(stringTable, string.Format("{0:x4}{1:x4}", lcid, codepage));
+ stringTable.Align(4);
- WriteString(stringTable, "Comments", description);
- WriteString(stringTable, "CompanyName", company);
- WriteString(stringTable, "FileDescription", title);
- WriteString(stringTable, "FileVersion", fileVersion);
- WriteString(stringTable, "InternalName", name.Name);
- WriteString(stringTable, "LegalCopyright", copyright);
- WriteString(stringTable, "LegalTrademarks", trademark);
- WriteString(stringTable, "OriginalFilename", fileName);
- WriteString(stringTable, "ProductName", product);
- WriteString(stringTable, "ProductVersion", informationalVersion);
+ WriteString(stringTable, "Comments", description);
+ WriteString(stringTable, "CompanyName", company);
+ WriteString(stringTable, "FileDescription", title);
+ WriteString(stringTable, "FileVersion", fileVersion);
+ WriteString(stringTable, "InternalName", name.Name);
+ WriteString(stringTable, "LegalCopyright", copyright);
+ WriteString(stringTable, "LegalTrademarks", trademark);
+ WriteString(stringTable, "OriginalFilename", fileName);
+ WriteString(stringTable, "ProductName", product);
+ WriteString(stringTable, "ProductVersion", informationalVersion);
- stringTable.Position = 0;
- stringTable.Write((short)stringTable.Length);
+ stringTable.Position = 0;
+ stringTable.Write((short)stringTable.Length);
- ByteBuffer stringFileInfo = new ByteBuffer(512);
- stringFileInfo.Write((short)0); // wLength (placeholder)
- stringFileInfo.Write((short)0); // wValueLength
- stringFileInfo.Write((short)1); // wType
- WriteUTF16Z(stringFileInfo, "StringFileInfo");
- stringFileInfo.Align(4);
- stringFileInfo.Write(stringTable);
- stringFileInfo.Position = 0;
- stringFileInfo.Write((short)stringFileInfo.Length);
+ ByteBuffer stringFileInfo = new ByteBuffer(512);
+ stringFileInfo.Write((short)0); // wLength (placeholder)
+ stringFileInfo.Write((short)0); // wValueLength
+ stringFileInfo.Write((short)1); // wType
+ WriteUTF16Z(stringFileInfo, "StringFileInfo");
+ stringFileInfo.Align(4);
+ stringFileInfo.Write(stringTable);
+ stringFileInfo.Position = 0;
+ stringFileInfo.Write((short)stringFileInfo.Length);
- byte[] preamble1 = new byte[] {
+ byte[] preamble1 = new byte[] {
// VS_VERSIONINFO (platform SDK)
0x34, 0x00, // wValueLength
0x00, 0x00, // wType
@@ -180,8 +177,8 @@ internal void Write(ByteBuffer bb)
0xBD, 0x04, 0xEF, 0xFE, // dwSignature (0xFEEF04BD)
0x00, 0x00, 0x01, 0x00, // dwStrucVersion
};
- byte[] preamble2 = new byte[] {
- 0x3F, 0x00, 0x00, 0x00, // dwFileFlagsMask (??)
+ byte[] preamble2 = new byte[] {
+ 0x3F, 0x00, 0x00, 0x00, // dwFileFlagsMask (??)
0x00, 0x00, 0x00, 0x00, // dwFileFlags (??)
0x04, 0x00, 0x00, 0x00, // dwFileOS
0x02, 0x00, 0x00, 0x00, // dwFileType
@@ -202,81 +199,81 @@ internal void Write(ByteBuffer bb)
0x54, 0x00, 0x72, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00, // "Translation\0"
0x00, 0x00, // Padding (32 bit alignment)
};
- bb.Write((short)(2 + preamble1.Length + 8 + 8 + preamble2.Length + 4 + stringFileInfo.Length));
- bb.Write(preamble1);
- bb.Write((short)fileVersionMinor);
- bb.Write((short)fileVersionMajor);
- bb.Write((short)fileVersionRevision);
- bb.Write((short)fileVersionBuild);
- bb.Write((short)productVersionMinor);
- bb.Write((short)productVersionMajor);
- bb.Write((short)productVersionRevision);
- bb.Write((short)productVersionBuild);
- bb.Write(preamble2);
- bb.Write((short)lcid);
- bb.Write((short)codepage);
- bb.Write(stringFileInfo);
- }
+ bb.Write((short)(2 + preamble1.Length + 8 + 8 + preamble2.Length + 4 + stringFileInfo.Length));
+ bb.Write(preamble1);
+ bb.Write((short)fileVersionMinor);
+ bb.Write((short)fileVersionMajor);
+ bb.Write((short)fileVersionRevision);
+ bb.Write((short)fileVersionBuild);
+ bb.Write((short)productVersionMinor);
+ bb.Write((short)productVersionMajor);
+ bb.Write((short)productVersionRevision);
+ bb.Write((short)productVersionBuild);
+ bb.Write(preamble2);
+ bb.Write((short)lcid);
+ bb.Write((short)codepage);
+ bb.Write(stringFileInfo);
+ }
- private static void WriteUTF16Z(ByteBuffer bb, string str)
- {
- foreach (char c in str)
- {
- bb.Write((short)c);
- }
- bb.Write((short)0);
- }
+ private static void WriteUTF16Z(ByteBuffer bb, string str)
+ {
+ foreach (char c in str)
+ {
+ bb.Write((short)c);
+ }
+ bb.Write((short)0);
+ }
- private static void WriteString(ByteBuffer bb, string name, string value)
- {
- value = value ?? " ";
- int pos = bb.Position;
- bb.Write((short)0); // wLength (placeholder)
- bb.Write((short)(value.Length + 1));// wValueLength
- bb.Write((short)1); // wType
- WriteUTF16Z(bb, name);
- bb.Align(4);
- WriteUTF16Z(bb, value);
- bb.Align(4);
- int savedPos = bb.Position;
- bb.Position = pos;
- bb.Write((short)(savedPos - pos));
- bb.Position = savedPos;
- }
+ private static void WriteString(ByteBuffer bb, string name, string value)
+ {
+ value = value ?? " ";
+ int pos = bb.Position;
+ bb.Write((short)0); // wLength (placeholder)
+ bb.Write((short)(value.Length + 1));// wValueLength
+ bb.Write((short)1); // wType
+ WriteUTF16Z(bb, name);
+ bb.Align(4);
+ WriteUTF16Z(bb, value);
+ bb.Align(4);
+ int savedPos = bb.Position;
+ bb.Position = pos;
+ bb.Write((short)(savedPos - pos));
+ bb.Position = savedPos;
+ }
- private static Version ParseVersionRobust(string ver)
- {
- int index = 0;
- ushort major = ParseVersionPart(ver, ref index);
- ushort minor = ParseVersionPart(ver, ref index);
- ushort build = ParseVersionPart(ver, ref index);
- ushort revision = ParseVersionPart(ver, ref index);
- return new Version(major, minor, build, revision);
- }
+ private static Version ParseVersionRobust(string ver)
+ {
+ int index = 0;
+ ushort major = ParseVersionPart(ver, ref index);
+ ushort minor = ParseVersionPart(ver, ref index);
+ ushort build = ParseVersionPart(ver, ref index);
+ ushort revision = ParseVersionPart(ver, ref index);
+ return new Version(major, minor, build, revision);
+ }
- private static ushort ParseVersionPart(string str, ref int pos)
- {
- ushort value = 0;
- while (pos < str.Length)
- {
- char c = str[pos];
- if (c == '.')
- {
- pos++;
- break;
- }
- else if (c >= '0' && c <= '9')
- {
- value *= 10;
- value += (ushort)(c - '0');
- pos++;
- }
- else
- {
- break;
- }
- }
- return value;
- }
- }
+ private static ushort ParseVersionPart(string str, ref int pos)
+ {
+ ushort value = 0;
+ while (pos < str.Length)
+ {
+ char c = str[pos];
+ if (c == '.')
+ {
+ pos++;
+ break;
+ }
+ else if (c >= '0' && c <= '9')
+ {
+ value *= 10;
+ value += (ushort)(c - '0');
+ pos++;
+ }
+ else
+ {
+ break;
+ }
+ }
+ return value;
+ }
+ }
}
diff --git a/src/compiler/backend/ikvm/coreclr.cs b/src/compiler/backend/ikvm/coreclr.cs
deleted file mode 100644
index 999fd3abc..000000000
--- a/src/compiler/backend/ikvm/coreclr.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- Copyright (C) 2015 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
-using System;
-
-#if CORECLR
-namespace System.Diagnostics
-{
- static class Debug
- {
- [Conditional("DEBUG")]
- internal static void Assert(bool cond)
- {
- if (!cond)
- {
- Environment.FailFast("assertion failed");
- }
- }
- }
-}
-
-namespace System.Collections.Generic
-{
- sealed class Stack
- {
- private readonly List items = new List();
-
- internal void Push(T value)
- {
- items.Add(value);
- }
-
- internal T Peek()
- {
- if (items.Count == 0)
- {
- throw new InvalidOperationException();
- }
- return items[items.Count - 1];
- }
-
- internal T Pop()
- {
- T value = Peek();
- items.RemoveAt(items.Count - 1);
- return value;
- }
- }
-}
-#endif
diff --git a/src/compiler/backend/unodoc/Uno.Compiler.Backends.UnoDoc.csproj b/src/compiler/backend/unodoc/Uno.Compiler.Backends.UnoDoc.csproj
index 6ffc74fca..3c3618f5c 100644
--- a/src/compiler/backend/unodoc/Uno.Compiler.Backends.UnoDoc.csproj
+++ b/src/compiler/backend/unodoc/Uno.Compiler.Backends.UnoDoc.csproj
@@ -1,159 +1,16 @@
-
-
+
+
+
- Debug
- AnyCPU
- {EB7A1BF1-F78F-41EC-933D-E3A44C021E3D}
- Library
- Properties
+ net6.0
Uno.Compiler.Backends.UnoDoc
- Uno.Compiler.Backends.UnoDoc
- v4.5
- 512
- ..\..\..\..\
- true
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
- ..\..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
+
-
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/backend/unodoc/packages.config b/src/compiler/backend/unodoc/packages.config
deleted file mode 100644
index 093dcd239..000000000
--- a/src/compiler/backend/unodoc/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/compiler/core/Syntax/UxlProcessor.cs b/src/compiler/core/Syntax/UxlProcessor.cs
index 226c9c817..4ad263ef5 100644
--- a/src/compiler/core/Syntax/UxlProcessor.cs
+++ b/src/compiler/core/Syntax/UxlProcessor.cs
@@ -640,7 +640,7 @@ void WriteImageFile(ImageFile f)
Log.Event(IOEvent.Write, dst);
_disk.CreateDirectory(Path.GetDirectoryName(dst));
- using (var originalImg = Image.FromFile(src))
+ /*using (var originalImg = Image.FromFile(src))
{
if (_env.IsDefined("iOS") && Image.IsAlphaPixelFormat(originalImg.PixelFormat) )
{
@@ -661,7 +661,7 @@ void WriteImageFile(ImageFile f)
resizedImg.Save(dst);
}
}
- }
+ }*/
}
catch (Exception e)
{
diff --git a/src/compiler/core/Uno.Compiler.Core.csproj b/src/compiler/core/Uno.Compiler.Core.csproj
index 05c687f07..ba073c191 100644
--- a/src/compiler/core/Uno.Compiler.Core.csproj
+++ b/src/compiler/core/Uno.Compiler.Core.csproj
@@ -1,244 +1,14 @@
-
-
+
+
+
- Debug
- AnyCPU
- {C4CF7639-0705-4093-B16D-3261A92F6260}
- Library
- Properties
+ net6.0
Uno.Compiler.Core
- Uno.Compiler.Core
- 512
- ..\..\..\..\
- true
- v4.5
-
-
- true
- bin\Debug\
- DEBUG;TRACE
- full
- AnyCPU
- prompt
- false
- 4
- false
-
-
- bin\Release\
- TRACE
- true
- pdbonly
- AnyCPU
- prompt
- false
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {660301A9-D14E-48C0-A757-2DBD2D4D0E3F}
- Uno.Compiler.Frontend
-
-
+
-
+
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/foreign/Uno.Compiler.Foreign.csproj b/src/compiler/foreign/Uno.Compiler.Foreign.csproj
index 0fbac1e54..a918c87eb 100644
--- a/src/compiler/foreign/Uno.Compiler.Foreign.csproj
+++ b/src/compiler/foreign/Uno.Compiler.Foreign.csproj
@@ -1,90 +1,17 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {853ABAB6-9FFD-4749-9D32-0A205C5E72B3}
- Library
- Properties
+ net6.0
Uno.Compiler.Foreign
- Uno.Compiler.Foreign
- v4.5
- 512
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
- ..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {9e0318a1-528e-4afd-ab87-c8d58e0cd060}
- Uno.Compiler.Backends.CPlusPlus
-
+
+
+
-
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/foreign/packages.config b/src/compiler/foreign/packages.config
deleted file mode 100644
index 093dcd239..000000000
--- a/src/compiler/foreign/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/compiler/frontend/Uno.Compiler.Frontend.csproj b/src/compiler/frontend/Uno.Compiler.Frontend.csproj
index 2e1219359..a0d4cb220 100644
--- a/src/compiler/frontend/Uno.Compiler.Frontend.csproj
+++ b/src/compiler/frontend/Uno.Compiler.Frontend.csproj
@@ -1,82 +1,13 @@
-
-
+
+
+
- Debug
- AnyCPU
- {660301A9-D14E-48C0-A757-2DBD2D4D0E3F}
- Library
- Properties
+ net6.0
Uno.Compiler.Frontend
- Uno.Compiler.Frontend
- v4.5
- 512
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/compiler/graphics/opengl/Uno.Compiler.Graphics.OpenGL.csproj b/src/compiler/graphics/opengl/Uno.Compiler.Graphics.OpenGL.csproj
index 427e937c0..91dffaf1c 100644
--- a/src/compiler/graphics/opengl/Uno.Compiler.Graphics.OpenGL.csproj
+++ b/src/compiler/graphics/opengl/Uno.Compiler.Graphics.OpenGL.csproj
@@ -1,62 +1,13 @@
-
-
+
+
+
- Debug
- AnyCPU
- {AFCAAF4E-198D-45F5-A019-ACED9CDCCADF}
- Library
- Properties
+ net6.0
Uno.Compiler.Graphics.OpenGL
- Uno.Compiler.Graphics.OpenGL
- v4.5
- 512
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
+
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/disasm/core/BuildService.cs b/src/disasm/core/BuildService.cs
index 1411ffd2c..d014a31ae 100644
--- a/src/disasm/core/BuildService.cs
+++ b/src/disasm/core/BuildService.cs
@@ -93,7 +93,7 @@ bool SetBuildArgs(IEnumerable args)
try
{
_args = BuildCommand.Parse(args, _log);
- _args.Options.Native = false;
+ _args.Options.NativeBuild = false;
_args.Options.PrintInternals = true;
_view.OnProjectChanged(_args.ProjectFile);
return true;
diff --git a/src/disasm/core/ILView/Commands/CopyFullPath.cs b/src/disasm/core/ILView/Commands/CopyFullPath.cs
index 4cd9bad3e..25105cdd6 100644
--- a/src/disasm/core/ILView/Commands/CopyFullPath.cs
+++ b/src/disasm/core/ILView/Commands/CopyFullPath.cs
@@ -1,4 +1,5 @@
-using System.Windows.Forms;
+//using System.Windows.Forms;
+using System;
using Uno.Diagnostics;
namespace Uno.Disasm.ILView.Commands
@@ -9,13 +10,13 @@ public class CopyFullPath : ILCommand
public override bool CanShow(ILItem item)
{
- return PlatformDetection.IsWindows && item is IFile;
+ return OperatingSystem.IsWindows() && item is IFile;
}
public override void Execute(ILItem item)
{
var file = (IFile)item;
- Clipboard.SetText(file.FullName);
+ //Clipboard.SetText(file.FullName);
}
}
}
\ No newline at end of file
diff --git a/src/disasm/core/ILView/Commands/OpenWith.cs b/src/disasm/core/ILView/Commands/OpenWith.cs
index 95161a41b..7cb42c3a0 100644
--- a/src/disasm/core/ILView/Commands/OpenWith.cs
+++ b/src/disasm/core/ILView/Commands/OpenWith.cs
@@ -1,3 +1,4 @@
+using System;
using System.Diagnostics;
using System.IO;
using Uno.Diagnostics;
@@ -21,7 +22,7 @@ public override ILIcon GetIcon(ILItem item)
public override bool CanShow(ILItem item)
{
- return PlatformDetection.IsWindows && item is IFile && !(item is FolderBase);
+ return OperatingSystem.IsWindows() && item is IFile && !(item is FolderBase);
}
public override bool CanExecute(ILItem item)
diff --git a/src/disasm/core/ILView/Commands/ShowInExplorer.cs b/src/disasm/core/ILView/Commands/ShowInExplorer.cs
index 01acf87ac..03f05b978 100644
--- a/src/disasm/core/ILView/Commands/ShowInExplorer.cs
+++ b/src/disasm/core/ILView/Commands/ShowInExplorer.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using System;
+using System.Diagnostics;
using System.IO;
using Uno.Diagnostics;
@@ -15,7 +16,7 @@ public override ILIcon GetIcon(ILItem item)
public override bool CanShow(ILItem item)
{
- return PlatformDetection.IsWindows && item is IFile;
+ return OperatingSystem.IsWindows() && item is IFile;
}
public override bool CanExecute(ILItem item)
diff --git a/src/disasm/core/Uno.Disasm.csproj b/src/disasm/core/Uno.Disasm.csproj
index ed573e784..ccb7f70bd 100644
--- a/src/disasm/core/Uno.Disasm.csproj
+++ b/src/disasm/core/Uno.Disasm.csproj
@@ -1,367 +1,16 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {9E26C610-B4BE-4548-82B0-70CFF33267C9}
- Library
- Properties
+ net6.0
Uno.Disasm
- Uno.Disasm
- v4.5
- 512
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {6C4066B0-F7EA-41B1-B103-0A4F1C3A77D5}
- Uno.ProjectFormat
-
-
- {EE7B3E9E-C1AF-41A1-8B71-42213DAB19F4}
- Uno.Build
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {5813CAEE-0804-45C2-A0C7-E30720EFBB45}
- uno
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/disasm/wpf/disasm-wpf.csproj b/src/disasm/wpf/disasm-wpf.csproj
index 09dc2582c..2bbfa30d9 100644
--- a/src/disasm/wpf/disasm-wpf.csproj
+++ b/src/disasm/wpf/disasm-wpf.csproj
@@ -1,146 +1,21 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {E9E95DD1-03F6-45A3-945F-E1CC82E6B8D4}
- WinExe
- Properties
+ net6.0-windows
Uno.Disasm
- uno-disasm
- v4.5
- 512
- {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 4
- ..\..\..\
- true
+ true
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
- UnoIcon.ico
-
-
-
- ..\..\..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll
-
-
- ..\..\..\packages\AvalonEdit.6.0.1\lib\net45\ICSharpCode.AvalonEdit.dll
-
-
- ..\..\..\packages\MahApps.Metro.1.6.5\lib\net45\MahApps.Metro.dll
- True
-
-
- ..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
-
-
-
-
- ..\..\..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll
- True
-
-
-
-
- 4.0
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Designer
-
-
- MSBuild:Compile
- Designer
-
-
- App.xaml
-
-
-
-
-
-
- MainWindow.xaml
-
-
-
-
- True
- True
- Resources.resx
-
-
- True
- Settings.settings
- True
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
-
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
-
- {ee7b3e9e-c1af-41a1-8b71-42213dab19f4}
- Uno.Build
-
-
- {d159dc86-f510-4fcf-9573-e339bdd6d166}
- Uno.Common
-
-
- {9e26c610-b4be-4548-82b0-70cff33267c9}
- Uno.Disasm
-
+
+
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/disasm/wpf/packages.config b/src/disasm/wpf/packages.config
deleted file mode 100644
index 94ff6efc2..000000000
--- a/src/disasm/wpf/packages.config
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/runtime/generic/App.config b/src/runtime/generic/App.config
deleted file mode 100644
index bc3672dbc..000000000
--- a/src/runtime/generic/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/runtime/generic/app-generic.csproj b/src/runtime/generic/app-generic.csproj
index f273731bc..19955d67a 100644
--- a/src/runtime/generic/app-generic.csproj
+++ b/src/runtime/generic/app-generic.csproj
@@ -1,62 +1,16 @@
-
-
-
+
+
+
- true
- Debug
- AnyCPU
- {196B010D-AD36-4947-95AA-14FC4A27BD18}
- Exe
- Properties
+ net6.0
Uno.AppLoader
uno-app
- v4.5
- 512
- true
- ..\..\..\..\
- true
-
-
- true
- true
- full
- false
- $(SolutionDir)bin\generic\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- true
- pdbonly
- true
- $(SolutionDir)bin\generic\
- TRACE
- prompt
- 4
- false
+ $(SolutionDir)bin\generic
+
-
-
..\..\..\lib\UnoCore\build\dotnet\debug\UnoCore.dll
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
diff --git a/src/runtime/mac/App.config b/src/runtime/mac/App.config
deleted file mode 100644
index bc3672dbc..000000000
--- a/src/runtime/mac/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/runtime/mac/app-mac.csproj b/src/runtime/mac/app-mac.csproj
index cc2e7e1cf..18a964fec 100644
--- a/src/runtime/mac/app-mac.csproj
+++ b/src/runtime/mac/app-mac.csproj
@@ -1,111 +1,26 @@
-
-
-
-
+
+
+
- true
- Debug
- AnyCPU
- {C919203A-A0FD-41E4-A8D7-3E1B1C12DDAE}
- Exe
- Properties
+ net6.0
Uno.AppLoader
uno-app
- v4.5
- 512
- true
- ..\..\..\..\
- true
-
-
-
-
- x86
- true
- full
- false
- $(SolutionDir)bin\mac\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- x86
- pdbonly
- true
- $(SolutionDir)bin\mac\
- TRACE
- prompt
- 4
- false
+ $(SolutionDir)bin\mac
+ true
+
+
+
+
- ..\..\..\node_modules\@fuse-open\xamarin-mac\OpenTK.dll
+ ..\..\..\node_modules\%40fuse-open\xamarin-mac\OpenTK.dll
-
-
-
- ..\..\..\node_modules\@fuse-open\xamarin-mac\System.Drawing.Common.dll
+
+ ..\..\..\node_modules\%40fuse-open\xamarin-mac\Xamarin.Mac.dll
..\..\..\lib\UnoCore\build\dotnet\debug\UnoCore.dll
-
- ..\..\..\node_modules\@fuse-open\xamarin-mac\Xamarin.Mac.dll
-
-
-
-
-
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
- True
- Resources.resx
- True
-
-
- PreserveNewest
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
- True
- Settings.settings
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Designer
-
-
-
-
\ No newline at end of file
+
diff --git a/src/runtime/win/App.config b/src/runtime/win/App.config
deleted file mode 100644
index bc3672dbc..000000000
--- a/src/runtime/win/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/runtime/win/app-win.csproj b/src/runtime/win/app-win.csproj
index 93213ec9e..5541dc6c1 100644
--- a/src/runtime/win/app-win.csproj
+++ b/src/runtime/win/app-win.csproj
@@ -1,125 +1,22 @@
-
-
-
-
+
+
+
- true
- Debug
- AnyCPU
- {21D956DB-8735-4EE6-BA7E-1D6CD77521F4}
- WinExe
- Properties
+ net6.0-windows
Uno.AppLoader
uno-app
- v4.5
- 512
- true
- ..\..\..\..\
- true
-
-
+ $(SolutionDir)bin\win
true
- x86
- true
- full
- false
- $(SolutionDir)bin\win\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- true
- x86
- pdbonly
- true
- $(SolutionDir)bin\win\
- TRACE
- prompt
- 4
- false
-
-
- app.manifest
+ true
+ true
+
- ..\..\..\node_modules\@fuse-open\opentk\OpenTK.dll
+ ..\..\..\node_modules\%40fuse-open\opentk\OpenTK.dll
-
-
-
-
..\..\..\lib\UnoCore\build\dotnet\debug\UnoCore.dll
-
-
-
-
-
- Form
-
-
- MainForm.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
- MainForm.cs
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
- True
- Resources.resx
- True
-
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
- True
- Settings.settings
- True
-
-
-
-
- UserControl
-
-
-
-
-
-
-
-
- Designer
-
-
-
-
-
\ No newline at end of file
+
diff --git a/src/test/compiler-test/compiler-test.csproj b/src/test/compiler-test/compiler-test.csproj
index 6f74eda74..b73f1e691 100644
--- a/src/test/compiler-test/compiler-test.csproj
+++ b/src/test/compiler-test/compiler-test.csproj
@@ -1,77 +1,15 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {452AD3C8-8B77-4188-B70F-C9AFF210F45C}
- Exe
- Properties
+ net6.0
Uno.CompilerTestRunner
- uno-compiler-test
- v4.5
- 512
-
- ..\..\..\..\
- true
-
- true
- bin\Debug\
- DEBUG;TRACE
- full
- AnyCPU
- prompt
- false
- 4
- false
-
-
- bin\Release\
- TRACE
- true
- pdbonly
- AnyCPU
- prompt
- false
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {EE7B3E9E-C1AF-41A1-8B71-42213DAB19F4}
- Uno.Build
-
-
- {6C4066B0-F7EA-41B1-B103-0A4F1C3A77D5}
- Uno.ProjectFormat
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {26b75fbd-dbf7-4ebe-8b7b-5b04acc28f13}
- Uno.TestRunner
-
+
+
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/test/runner/Loggers/FileHelpers.cs b/src/test/runner/Loggers/FileHelpers.cs
index 827746836..af2db2b7b 100644
--- a/src/test/runner/Loggers/FileHelpers.cs
+++ b/src/test/runner/Loggers/FileHelpers.cs
@@ -1,14 +1,14 @@
using System;
using System.Diagnostics;
using System.IO;
-using System.Runtime.Remoting.Contexts;
+//using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace Uno.TestRunner.Loggers
{
- [Synchronization]
+ //[Synchronization]
public class FileHelpers
{
private static readonly object FileLock = new object();
diff --git a/src/test/runner/Uno.TestRunner.csproj b/src/test/runner/Uno.TestRunner.csproj
index 911d46395..e817cd59a 100644
--- a/src/test/runner/Uno.TestRunner.csproj
+++ b/src/test/runner/Uno.TestRunner.csproj
@@ -1,80 +1,14 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {26B75FBD-DBF7-4EBE-8B7B-5B04ACC28F13}
- Library
- Properties
+ net6.0
Uno.TestRunner
- Uno.TestRunner
- v4.5
- 512
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {EE7B3E9E-C1AF-41A1-8B71-42213DAB19F4}
- Uno.Build
-
-
- {6C4066B0-F7EA-41B1-B103-0A4F1C3A77D5}
- Uno.ProjectFormat
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
+
+
+
-
-
-
-
\ No newline at end of file
+
diff --git a/src/test/tests/TestRunTests.cs b/src/test/tests/TestRunTests.cs
index 6aef02d82..3bdbf1293 100644
--- a/src/test/tests/TestRunTests.cs
+++ b/src/test/tests/TestRunTests.cs
@@ -17,7 +17,7 @@ public void ThrowsOnIncorrectState()
Assert.Throws(() => run.EventOccured(MakeReadyEvent(1)));
run.Start();
- Assert.AreEqual(TestRun.State.WaitingForReady, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.WaitingForReady));
Assert.Throws(() => run.EventOccured(MakeTestPassedEvent("foo")));
Assert.Throws(() => run.EventOccured(MakeTestAssertedEvent("foo")));
@@ -29,15 +29,15 @@ public void ThrowsOnIncorrectState()
public void StartupSequenceIsCorrect()
{
var run = new TestRun(new Mock().Object);
- Assert.AreEqual(TestRun.State.NotStarted, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.NotStarted));
run.Start();
- Assert.AreEqual(TestRun.State.WaitingForReady, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.WaitingForReady));
run.EventOccured(MakeReadyEvent(1));
- Assert.AreEqual(TestRun.State.Ready, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.Ready));
run.EventOccured(MakeTestStartedEvent("foo"));
- Assert.AreEqual(TestRun.State.Running, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.Running));
run.EventOccured(MakeTestPassedEvent("foo"));
- Assert.AreEqual(TestRun.State.Finished, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.Finished));
}
[Test]
@@ -50,10 +50,10 @@ public void RunsAllTestsInCorrectOrder()
run.EventOccured(MakeTestPassedEvent("foo"));
run.EventOccured(MakeTestStartedEvent("bar"));
run.EventOccured(MakeTestAssertedEvent("bar"));
- Assert.AreEqual(TestRun.State.Finished, run.CurrentState);
+ Assert.That(run.CurrentState, Is.EqualTo(TestRun.State.Finished));
var result = run.WaitUntilFinished();
- Assert.AreEqual(new string[]{ "foo", "bar" }, result.Select(test => test.Name));
+ Assert.That(result.Select(test => test.Name), Is.EqualTo(new string[]{ "foo", "bar" }));
}
private static NameValueCollection MakeReadyEvent(int testCount)
diff --git a/src/test/tests/Uno.TestRunner.Tests.csproj b/src/test/tests/Uno.TestRunner.Tests.csproj
index 0a0b7e90a..5c31b6b10 100644
--- a/src/test/tests/Uno.TestRunner.Tests.csproj
+++ b/src/test/tests/Uno.TestRunner.Tests.csproj
@@ -1,90 +1,27 @@
-
-
-
-
+
+
+
- Debug
- AnyCPU
- {CD586CDD-BA3B-4673-ABE8-97C867B8445A}
- Library
- Properties
+ net6.0
Uno.TestRunner.Tests
- Uno.TestRunner.Tests
- v4.5
- 512
- ..\
- true
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
- ..\..\..\packages\Castle.Core.4.4.1\lib\net45\Castle.Core.dll
-
-
- ..\..\..\packages\Moq.4.15.1\lib\net45\Moq.dll
-
-
- ..\..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll
-
-
-
-
- ..\..\..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll
-
-
- ..\..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll
-
-
- ..\..\..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll
-
-
-
-
- {26B75FBD-DBF7-4EBE-8B7B-5B04ACC28F13}
- Uno.TestRunner
-
-
+
-
+
-
-
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
-
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
\ No newline at end of file
+
diff --git a/src/test/tests/app.config b/src/test/tests/app.config
deleted file mode 100644
index 6c543d8cc..000000000
--- a/src/test/tests/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/tests/packages.config b/src/test/tests/packages.config
deleted file mode 100644
index 1669ecb4e..000000000
--- a/src/test/tests/packages.config
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/tool/cli/Android/LaunchApk.cs b/src/tool/cli/Android/LaunchApk.cs
index c96c74d0b..83a6dc5de 100644
--- a/src/tool/cli/Android/LaunchApk.cs
+++ b/src/tool/cli/Android/LaunchApk.cs
@@ -159,7 +159,7 @@ static void NdkStack(string input, string symbolDir)
{
var filename = Path.Combine(NdkDirectory, "ndk-stack");
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
filename = File.Exists(filename + ".exe")
? filename + ".exe"
: filename + ".cmd";
diff --git a/src/tool/cli/Program.cs b/src/tool/cli/Program.cs
index 80ec686d3..439005119 100644
--- a/src/tool/cli/Program.cs
+++ b/src/tool/cli/Program.cs
@@ -173,19 +173,10 @@ static void WritePage(params string[] args)
Log.WriteLine();
}
- [SuppressMessage("ReSharper", "EmptyGeneralCatchClause")]
static Program()
{
- try
- {
- CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
- CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
- }
- catch
- {
- //Not supported until Mono 3.2.7
- }
-
+ CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
+ CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
}
diff --git a/src/tool/cli/Properties/launchSettings.json b/src/tool/cli/Properties/launchSettings.json
new file mode 100644
index 000000000..cf8e0dbe3
--- /dev/null
+++ b/src/tool/cli/Properties/launchSettings.json
@@ -0,0 +1,9 @@
+{
+ "profiles": {
+ "uno": {
+ "commandName": "Project",
+ "commandLineArgs": "build lib/UnoCore -DLIBRARY",
+ "workingDirectory": "C:\\uno"
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/tool/cli/System/Open.cs b/src/tool/cli/System/Open.cs
index 78a74e97e..d23519f57 100644
--- a/src/tool/cli/System/Open.cs
+++ b/src/tool/cli/System/Open.cs
@@ -48,7 +48,7 @@ public override void Execute(IEnumerable args)
void Start(string filename, string app, string exe, string title, bool newWindow)
{
- if (PlatformDetection.IsMac)
+ if (OperatingSystem.IsMacOS())
{
var args = new List();
@@ -62,7 +62,7 @@ void Start(string filename, string app, string exe, string title, bool newWindow
return;
}
- if (PlatformDetection.IsWindows && (
+ if (OperatingSystem.IsWindows() && (
!string.IsNullOrEmpty(app) ||
!string.IsNullOrEmpty(exe)
))
diff --git a/src/tool/cli/packages.config b/src/tool/cli/packages.config
deleted file mode 100644
index 73a9ceae6..000000000
--- a/src/tool/cli/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/tool/cli/uno b/src/tool/cli/uno
index f49168d66..0227278d4 100755
--- a/src/tool/cli/uno
+++ b/src/tool/cli/uno
@@ -1,15 +1,9 @@
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
-while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
- [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+ [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
done
-if [ "$OSTYPE" = msys ]; then
- exec "`dirname "$SOURCE"`/uno.exe" "$@"
-elif which mono64 > /dev/null 2>&1; then
- exec mono64 "`dirname "$SOURCE"`/uno.exe" "$@"
-else
- exec mono "`dirname "$SOURCE"`/uno.exe" "$@"
-fi
+exec dotnet "`dirname "$SOURCE"`/uno.dll" "$@"
diff --git a/src/tool/cli/uno.csproj b/src/tool/cli/uno.csproj
index d0f82621b..f5a73a552 100644
--- a/src/tool/cli/uno.csproj
+++ b/src/tool/cli/uno.csproj
@@ -1,112 +1,23 @@
-
-
+
+
+
- Debug
- AnyCPU
- {5813CAEE-0804-45C2-A0C7-E30720EFBB45}
- Exe
- Properties
+ net6.0
Uno.CLI
- uno
- v4.5
- 512
- ..\..\..\..\
- true
-
-
- true
- full
- false
- $(SolutionDir)bin\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- $(SolutionDir)bin\
- TRACE
- prompt
- 4
- false
+ $(SolutionDir)bin
+ Exe
+
-
- ..\..\..\packages\Mono.Options.6.6.0.161\lib\net40\Mono.Options.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {b819b724-1a1f-458e-a4af-4a5bb330c2c4}
- Uno.Compiler.API
-
-
- {26b75fbd-dbf7-4ebe-8b7b-5b04acc28f13}
- Uno.TestRunner
-
-
- {6C4066B0-F7EA-41B1-B103-0A4F1C3A77D5}
- Uno.ProjectFormat
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {EE7B3E9E-C1AF-41A1-8B71-42213DAB19F4}
- Uno.Build
-
-
- {95E969AF-23A7-46DE-8EEF-DF1BDDCA55D6}
- Uno.Configuration
-
-
- {660301A9-D14E-48C0-A757-2DBD2D4D0E3F}
- Uno.Compiler.Frontend
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
- PreserveNewest
-
-
- PreserveNewest
-
+
-
-
-
\ No newline at end of file
+
diff --git a/src/tool/cli/uno.js b/src/tool/cli/uno.js
index 299d69e74..0880e632b 100755
--- a/src/tool/cli/uno.js
+++ b/src/tool/cli/uno.js
@@ -2,6 +2,6 @@
const path = require('path');
const run = require('dotnet-run');
-run(path.join(__dirname, 'uno.exe'),
+run(path.join(__dirname, 'uno.dll'),
process.argv.slice(2),
process.exit);
diff --git a/src/tool/config/Format/StuffFile.cs b/src/tool/config/Format/StuffFile.cs
index 3367f2347..ef2d77863 100644
--- a/src/tool/config/Format/StuffFile.cs
+++ b/src/tool/config/Format/StuffFile.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using Uno.Diagnostics;
using Uno.IO;
@@ -14,16 +15,17 @@ public class StuffFile : List
public static readonly Dictionary DefaultConstants = new Dictionary
{
- {"WINDOWS", PlatformDetection.IsWindows},
- {"WIN32", PlatformDetection.IsWindows},
- {"OSX", PlatformDetection.IsMac},
- {"DARWIN", PlatformDetection.IsMac},
- {"MAC", PlatformDetection.IsMac},
- {"LINUX", PlatformDetection.IsLinux},
- {"UNIX", !PlatformDetection.IsWindows},
- {"ARM", PlatformDetection.IsArm},
- {"X86", !PlatformDetection.IsArm && IntPtr.Size == 4},
- {"X64", !PlatformDetection.IsArm && IntPtr.Size == 8}
+ {"WINDOWS", OperatingSystem.IsWindows()},
+ {"WIN32", OperatingSystem.IsWindows()},
+ {"OSX", OperatingSystem.IsMacOS()},
+ {"DARWIN", OperatingSystem.IsMacOS()},
+ {"MAC", OperatingSystem.IsMacOS()},
+ {"LINUX", OperatingSystem.IsLinux()},
+ {"UNIX", !OperatingSystem.IsWindows()},
+ {"ARM", RuntimeInformation.OSArchitecture == Architecture.Arm},
+ {"ARM64", RuntimeInformation.OSArchitecture == Architecture.Arm64},
+ {"X86", RuntimeInformation.OSArchitecture == Architecture.X86},
+ {"X64", RuntimeInformation.OSArchitecture == Architecture.X64}
};
public readonly string Filename;
diff --git a/src/tool/config/Uno.Configuration.csproj b/src/tool/config/Uno.Configuration.csproj
index 7d155aebe..b36cfb067 100644
--- a/src/tool/config/Uno.Configuration.csproj
+++ b/src/tool/config/Uno.Configuration.csproj
@@ -1,70 +1,12 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {95E969AF-23A7-46DE-8EEF-DF1BDDCA55D6}
- Library
- Properties
+ net6.0
Uno.Configuration
- Uno.Configuration
- v4.5
- 512
- ..\..\..\
- true
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {d159dc86-f510-4fcf-9573-e339bdd6d166}
- Uno.Common
-
+
-
-
-
\ No newline at end of file
+
diff --git a/src/tool/config/UnoConfig.cs b/src/tool/config/UnoConfig.cs
index 853c13689..548dc6482 100644
--- a/src/tool/config/UnoConfig.cs
+++ b/src/tool/config/UnoConfig.cs
@@ -277,7 +277,7 @@ void LoadRecursive(string dir)
return;
// Convert drive letter to uppercase to avoid mixed case bugs
- if (PlatformDetection.IsWindows && dir.Length >= 2 && dir[1] == ':' && char.IsLower(dir[0]))
+ if (OperatingSystem.IsWindows() && dir.Length >= 2 && dir[1] == ':' && char.IsLower(dir[0]))
dir = char.ToUpper(dir[0]) + dir.Substring(1);
if (_visitedDirectories.Contains(dir))
@@ -356,9 +356,7 @@ public static string GetAssemblyDirectory(Assembly asm)
{
if (asm == null)
return null;
- var uri = new UriBuilder(asm.CodeBase);
- var path = Uri.UnescapeDataString(uri.Path);
- return Path.GetDirectoryName(path);
+ return Path.GetDirectoryName(asm.Location);
}
public override string ToString()
diff --git a/src/tool/engine/Adb/AdbRunner.cs b/src/tool/engine/Adb/AdbRunner.cs
index 9d9aa8595..edbb2b665 100644
--- a/src/tool/engine/Adb/AdbRunner.cs
+++ b/src/tool/engine/Adb/AdbRunner.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -14,7 +15,7 @@ public class AdbRunner
readonly Shell _shell;
public readonly string Location = Path.Combine(SdkDirectory, "platform-tools",
- PlatformDetection.IsWindows ? "adb.exe" : "adb");
+ OperatingSystem.IsWindows() ? "adb.exe" : "adb");
public AdbRunner(Shell shell)
{
diff --git a/src/tool/engine/Stuff/Disk.cs b/src/tool/engine/Stuff/Disk.cs
index 1532f2ab0..43a251834 100644
--- a/src/tool/engine/Stuff/Disk.cs
+++ b/src/tool/engine/Stuff/Disk.cs
@@ -10,14 +10,14 @@ public static class Disk
{
public static void CreateDirectory(Log log, string path)
{
- var dirExists = PlatformDetection.IsWindows ? LongPathDisk.DirectoryExists(path) : Directory.Exists(path);
+ var dirExists = OperatingSystem.IsWindows() ? LongPathDisk.DirectoryExists(path) : Directory.Exists(path);
if (path.Length > 1 && !dirExists)
{
CreateDirectory(log, Path.GetDirectoryName(path));
log.Event(IOEvent.MkDir, path);
var isHidden = Path.GetFileName(path).StartsWith(".");
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
{
LongPathDisk.CreateDirectory(path);
if (isHidden)
@@ -36,14 +36,14 @@ public static void CreateDirectory(Log log, string path)
public static void DeleteFile(Log log, string name)
{
- var fileExists = PlatformDetection.IsWindows ? LongPathDisk.FileExists(name) : File.Exists(name);
+ var fileExists = OperatingSystem.IsWindows() ? LongPathDisk.FileExists(name) : File.Exists(name);
if (!fileExists)
return;
try
{
log.Event(IOEvent.Rm, name);
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
LongPathDisk.DeleteFile(name);
else
File.Delete(name);
@@ -56,7 +56,7 @@ public static void DeleteFile(Log log, string name)
public static void DeleteDirectory(Log log, string name)
{
- var directoryExists = PlatformDetection.IsWindows ? LongPathDisk.DirectoryExists(name) : Directory.Exists(name);
+ var directoryExists = OperatingSystem.IsWindows() ? LongPathDisk.DirectoryExists(name) : Directory.Exists(name);
if (!directoryExists)
return;
@@ -64,7 +64,7 @@ public static void DeleteDirectory(Log log, string name)
{
log.Event(IOEvent.RmDir, name);
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
LongPathDisk.DeleteDirectory(name, true);
else
Directory.Delete(name, true);
diff --git a/src/tool/engine/Stuff/Installer.cs b/src/tool/engine/Stuff/Installer.cs
index 524ff64be..1cb00d98b 100644
--- a/src/tool/engine/Stuff/Installer.cs
+++ b/src/tool/engine/Stuff/Installer.cs
@@ -190,7 +190,7 @@ void InstallItem(KeyValuePair item)
try
{
- if (PlatformDetection.IsWindows)
+ if (OperatingSystem.IsWindows())
LongPathZipFile.ExtractToDirectory(file, targetDir);
else
{
diff --git a/src/tool/engine/Targets/Generators/XcodeGenerator.cs b/src/tool/engine/Targets/Generators/XcodeGenerator.cs
index 80faca8cd..4a6bafc00 100644
--- a/src/tool/engine/Targets/Generators/XcodeGenerator.cs
+++ b/src/tool/engine/Targets/Generators/XcodeGenerator.cs
@@ -207,7 +207,7 @@ internal static void Configure(IEnvironment env, IEnumerable bundleF
static string FindCodeSigningDevelopmentTeam()
{
// Can only run on Mac
- if (!PlatformDetection.IsMac)
+ if (!OperatingSystem.IsMacOS())
{
Log.Default.Warning("Finding a development team for signing failed: This operation is only supported on macOS.");
return null;
diff --git a/src/tool/engine/Uno.Build.csproj b/src/tool/engine/Uno.Build.csproj
index 02a74541a..435ad28c4 100644
--- a/src/tool/engine/Uno.Build.csproj
+++ b/src/tool/engine/Uno.Build.csproj
@@ -1,170 +1,31 @@
-
-
-
-
+
+
+
- Debug
- AnyCPU
- {EE7B3E9E-C1AF-41A1-8B71-42213DAB19F4}
- Library
- Properties
+ net6.0
Uno.Build
- Uno.Build
- 512
- ..\..\..\..\
- true
- v4.5
-
-
-
- true
- bin\Debug\
- DEBUG;TRACE
- full
- AnyCPU
- prompt
- false
- 4
- false
-
-
- bin\Release\
- TRACE
- true
- pdbonly
- AnyCPU
- prompt
- false
- 4
+
-
- ..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
-
-
- ..\..\..\node_modules\@fuse-open\xamarin-mac\Xamarin.Mac.dll
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Component
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {B819B724-1A1F-458E-A4AF-4A5BB330C2C4}
- Uno.Compiler.API
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {b3b455c8-dd3d-4655-b10c-3c6be878911e}
- Uno.Compiler.Backends.CIL
-
-
- {9e0318a1-528e-4afd-ab87-c8d58e0cd060}
- Uno.Compiler.Backends.CPlusPlus
-
-
- {afcaaf4e-198d-45f5-a019-aced9cdccadf}
- Uno.Compiler.Graphics.OpenGL
-
-
- {eb7a1bf1-f78f-41ec-933d-e3a44c021e3d}
- Uno.Compiler.Backends.UnoDoc
-
-
- {853abab6-9ffd-4749-9d32-0a205c5e72b3}
- Uno.Compiler.Foreign
-
-
- {660301A9-D14E-48C0-A757-2DBD2D4D0E3F}
- Uno.Compiler.Frontend
-
-
- {C4CF7639-0705-4093-B16D-3261A92F6260}
- Uno.Compiler.Core
-
-
- {05538951-c4a9-4298-bba7-fe9f96e3ddc1}
- Uno.UX.Markup
-
-
- {6C4066B0-F7EA-41B1-B103-0A4F1C3A77D5}
- Uno.ProjectFormat
-
-
- {95E969AF-23A7-46DE-8EEF-DF1BDDCA55D6}
- Uno.Configuration
-
-
-
-
+
+ ..\..\..\node_modules\%40fuse-open\xamarin-mac\Xamarin.Mac.dll
+
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
\ No newline at end of file
+
diff --git a/src/tool/engine/packages.config b/src/tool/engine/packages.config
deleted file mode 100644
index 093dcd239..000000000
--- a/src/tool/engine/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/tool/project/Uno.ProjectFormat.csproj b/src/tool/project/Uno.ProjectFormat.csproj
index 83d51838b..43d6f8742 100644
--- a/src/tool/project/Uno.ProjectFormat.csproj
+++ b/src/tool/project/Uno.ProjectFormat.csproj
@@ -1,89 +1,20 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {6C4066B0-F7EA-41B1-B103-0A4F1C3A77D5}
- Library
- Properties
+ net6.0
Uno.ProjectFormat
- Uno.ProjectFormat
- v4.5
- 512
- ..\..\..\
- true
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\..\..\packages\Minimatch.2.0.0\lib\netstandard1.0\Minimatch.dll
- True
-
-
- ..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
-
-
-
-
-
- ..\..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {95E969AF-23A7-46DE-8EEF-DF1BDDCA55D6}
- Uno.Configuration
-
+
+
-
+
+
+
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/tool/project/packages.config b/src/tool/project/packages.config
deleted file mode 100644
index 417dca783..000000000
--- a/src/tool/project/packages.config
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ux/markup/Uno.UX.Markup.csproj b/src/ux/markup/Uno.UX.Markup.csproj
index e9e66071f..0ce121a86 100644
--- a/src/ux/markup/Uno.UX.Markup.csproj
+++ b/src/ux/markup/Uno.UX.Markup.csproj
@@ -1,130 +1,17 @@
-
-
-
+
+
+
- Debug
- AnyCPU
- {05538951-C4A9-4298-BBA7-FE9F96E3DDC1}
- Library
- Properties
+ net6.0
Uno.UX.Markup
- Uno.UX.Markup
- v4.5
- 512
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {660301a9-d14e-48c0-a757-2dbd2d4d0e3f}
- Uno.Compiler.Frontend
-
-
- {D159DC86-F510-4FCF-9573-E339BDD6D166}
- Uno.Common
-
-
- {b819b724-1a1f-458e-a4af-4a5bb330c2c4}
- Uno.Compiler.API
-
-
- {afcaaf4e-198d-45f5-a019-aced9cdccadf}
- Uno.Compiler.Graphics.OpenGL
-
-
- {c4cf7639-0705-4093-b16d-3261a92f6260}
- Uno.Compiler.Core
-
-
- {853abab6-9ffd-4749-9d32-0a205c5e72b3}
- Uno.Compiler.Foreign
-
+
+
+
+
+
+
-
-
-
\ No newline at end of file
+
diff --git a/src/ux/tests/Expressions/ExpressionTests.cs b/src/ux/tests/Expressions/ExpressionTests.cs
index f7806ea78..9f30ec39e 100644
--- a/src/ux/tests/Expressions/ExpressionTests.cs
+++ b/src/ux/tests/Expressions/ExpressionTests.cs
@@ -14,7 +14,7 @@ public void ThisExpression()
var e = new ThisExpression();
Assert.IsTrue(e.IsTrivial);
- Assert.AreEqual("this", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("this"));
}
[Test]
@@ -23,7 +23,7 @@ public void Literal()
var e = new Literal("abcd");
Assert.IsTrue(e.IsTrivial);
- Assert.AreEqual("abcd", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("abcd"));
}
[Test]
@@ -32,7 +32,7 @@ public void StringLiteral()
var e = new StringLiteral("hi");
Assert.IsTrue(e.IsTrivial);
- Assert.AreEqual("\"hi\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("\"hi\""));
}
[Test]
@@ -41,7 +41,7 @@ public void Identifier()
var e = new Identifier("hello");
Assert.IsTrue(e.IsTrivial);
- Assert.AreEqual("hello", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("hello"));
}
[Test]
@@ -50,7 +50,7 @@ public void Binding1()
var e = new Binding(new Identifier("a"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("{a}", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("{a}"));
}
[Test]
@@ -59,7 +59,7 @@ public void Binding2()
var e = new Binding(new Literal("17"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("{17}", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("{17}"));
}
[Test]
@@ -68,7 +68,7 @@ public void ModeExpression1()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.Clear);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("Clear \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("Clear \"xyz\""));
}
[Test]
@@ -77,7 +77,7 @@ public void ModeExpression2()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.Read);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("Read \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("Read \"xyz\""));
}
[Test]
@@ -86,7 +86,7 @@ public void ModeExpression3()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.Write);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("Write \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("Write \"xyz\""));
}
[Test]
@@ -95,7 +95,7 @@ public void ModeExpression4()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.ReadClear);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("ReadClear \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("ReadClear \"xyz\""));
}
[Test]
@@ -104,7 +104,7 @@ public void ModeExpression5()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.WriteClear);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("WriteClear \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("WriteClear \"xyz\""));
}
[Test]
@@ -113,7 +113,7 @@ public void ModeExpression6()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.ReadWrite);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("Default \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("Default \"xyz\""));
}
[Test]
@@ -122,7 +122,7 @@ public void ModeExpression7()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.ReadWriteClear);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("ReadWriteClear \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("ReadWriteClear \"xyz\""));
}
[Test]
@@ -131,7 +131,7 @@ public void ModeExpression8()
var e = new ModeExpression(new StringLiteral("xyz"), Modifier.Default);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("Default \"xyz\"", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("Default \"xyz\""));
}
[Test]
@@ -144,7 +144,7 @@ public void ModeExpression9()
// parsed to the tree above. We could do some magic when printing the expression string, but it makes most sense with other cases
// (such as "WriteClear this") to just always add the extra space between the mode and the ModeExpression's Expression, at the expense
// of ModeExpression + UserDefinedUnaryOperator looking slightly different.
- Assert.AreEqual("WriteClear Property this", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("WriteClear Property this"));
}
[Test]
@@ -153,7 +153,7 @@ public void RawExpression1()
var e = new RawExpression(new Literal("a"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("{= a}", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("{= a}"));
}
[Test]
@@ -162,7 +162,7 @@ public void RawExpression2()
var e = new RawExpression(new StringLiteral("a"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("{= \"a\"}", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("{= \"a\"}"));
}
[Test]
@@ -171,7 +171,7 @@ public void UserDefinedUnaryOperator()
var e = new UserDefinedUnaryOperator("MyOp", new Literal("1337"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("MyOp 1337", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("MyOp 1337"));
}
[Test]
@@ -180,7 +180,7 @@ public void MemberExpression1()
var e = new MemberExpression(new Literal("a"), "xyz");
Assert.IsTrue(e.IsTrivial);
- Assert.AreEqual("a.xyz", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("a.xyz"));
}
[Test]
@@ -189,7 +189,7 @@ public void MemberExpression2()
var e = new MemberExpression(new Literal("xyz"), "a");
Assert.IsTrue(e.IsTrivial);
- Assert.AreEqual("xyz.a", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("xyz.a"));
}
[Test]
@@ -198,7 +198,7 @@ public void MemberExpression3()
var e = new MemberExpression(new RawExpression(new StringLiteral("xyz")), "a");
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("{= \"xyz\"}.a", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("{= \"xyz\"}.a"));
}
[Test]
@@ -207,7 +207,7 @@ public void LookUpExpression1()
var e = new LookUpExpression(new Literal("a"), new Literal("b"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("a[b]", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("a[b]"));
}
[Test]
@@ -216,7 +216,7 @@ public void LookUpExpression2()
var e = new LookUpExpression(new StringLiteral("123"), new StringLiteral("abc"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("\"123\"[\"abc\"]", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("\"123\"[\"abc\"]"));
}
[Test]
@@ -225,7 +225,7 @@ public void ConditionalExpression()
var e = new ConditionalExpression(new Literal("true"), new Literal("yes"), new Literal("no"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(true ? yes : no)", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(true ? yes : no)"));
}
[Test]
@@ -234,8 +234,8 @@ public void AddExpression()
var e = new AddExpression(new StringLiteral("wheee"), new Literal("6"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(\"wheee\"+6)", e.ToString());
- Assert.AreEqual("Add", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(\"wheee\"+6)"));
+ Assert.That(e.Name, Is.EqualTo("Add"));
}
[Test]
@@ -244,8 +244,8 @@ public void SubtractExpression()
var e = new SubtractExpression(new Literal("6"), new StringLiteral("wheee"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(6-\"wheee\")", e.ToString());
- Assert.AreEqual("Subtract", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(6-\"wheee\")"));
+ Assert.That(e.Name, Is.EqualTo("Subtract"));
}
[Test]
@@ -254,8 +254,8 @@ public void MultiplyExpression()
var e = new MultiplyExpression(new StringLiteral("hi"), new StringLiteral("bye"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(\"hi\"*\"bye\")", e.ToString());
- Assert.AreEqual("Multiply", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(\"hi\"*\"bye\")"));
+ Assert.That(e.Name, Is.EqualTo("Multiply"));
}
[Test]
@@ -264,8 +264,8 @@ public void DivideExpression()
var e = new DivideExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13/37)", e.ToString());
- Assert.AreEqual("Divide", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13/37)"));
+ Assert.That(e.Name, Is.EqualTo("Divide"));
}
[Test]
@@ -274,8 +274,8 @@ public void LessThanExpression()
var e = new LessThanExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13<37)", e.ToString());
- Assert.AreEqual("LessThan", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13<37)"));
+ Assert.That(e.Name, Is.EqualTo("LessThan"));
}
[Test]
@@ -284,8 +284,8 @@ public void LessOrEqualExpression()
var e = new LessOrEqualExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13<=37)", e.ToString());
- Assert.AreEqual("LessOrEqual", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13<=37)"));
+ Assert.That(e.Name, Is.EqualTo("LessOrEqual"));
}
[Test]
@@ -294,8 +294,8 @@ public void GreaterThanExpression()
var e = new GreaterThanExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13>37)", e.ToString());
- Assert.AreEqual("GreaterThan", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13>37)"));
+ Assert.That(e.Name, Is.EqualTo("GreaterThan"));
}
[Test]
@@ -304,8 +304,8 @@ public void GreaterOrEqualExpression()
var e = new GreaterOrEqualExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13>=37)", e.ToString());
- Assert.AreEqual("GreaterOrEqual", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13>=37)"));
+ Assert.That(e.Name, Is.EqualTo("GreaterOrEqual"));
}
[Test]
@@ -314,8 +314,8 @@ public void EqualExpression()
var e = new EqualExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13==37)", e.ToString());
- Assert.AreEqual("Equal", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13==37)"));
+ Assert.That(e.Name, Is.EqualTo("Equal"));
}
[Test]
@@ -324,8 +324,8 @@ public void NotEqualExpression()
var e = new NotEqualExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13!=37)", e.ToString());
- Assert.AreEqual("NotEqual", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13!=37)"));
+ Assert.That(e.Name, Is.EqualTo("NotEqual"));
}
[Test]
@@ -334,8 +334,8 @@ public void LogicalOrExpression()
var e = new LogicalOrExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13||37)", e.ToString());
- Assert.AreEqual("LogicalOr", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13||37)"));
+ Assert.That(e.Name, Is.EqualTo("LogicalOr"));
}
[Test]
@@ -344,8 +344,8 @@ public void LogicalAndExpression()
var e = new LogicalAndExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13&&37)", e.ToString());
- Assert.AreEqual("LogicalAnd", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13&&37)"));
+ Assert.That(e.Name, Is.EqualTo("LogicalAnd"));
}
[Test]
@@ -354,8 +354,8 @@ public void NullCoalesceExpression()
var e = new NullCoalesceExpression(new Literal("13"), new Literal("37"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(13??37)", e.ToString());
- Assert.AreEqual("NullCoalesce", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(13??37)"));
+ Assert.That(e.Name, Is.EqualTo("NullCoalesce"));
}
[Test]
@@ -374,7 +374,7 @@ public void VectorExpression2()
var e = new VectorExpression(new Literal("a"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(a)", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(a)"));
AssertExtensions.AreEqualValues(new Literal("a"), e.TryFold());
}
@@ -384,7 +384,7 @@ public void VectorExpression3()
var e = new VectorExpression(new StringLiteral("a"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(\"a\")", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(\"a\")"));
AssertExtensions.AreEqualValues(e, e.TryFold());
}
@@ -394,7 +394,7 @@ public void VectorExpression4()
var e = new VectorExpression(new Literal("a"), new StringLiteral("b"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(a, \"b\")", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(a, \"b\")"));
AssertExtensions.AreEqualValues(e, e.TryFold());
}
@@ -404,7 +404,7 @@ public void VectorExpression5()
var e = new VectorExpression(new Literal("a"), new Literal("b"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(a, b)", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(a, b)"));
AssertExtensions.AreEqualValues(new Literal("a, b"), e.TryFold());
}
@@ -414,7 +414,7 @@ public void VectorExpression6()
var e = new VectorExpression(new Literal("a"), new Literal("b"), new StringLiteral("c"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(a, b, \"c\")", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(a, b, \"c\")"));
AssertExtensions.AreEqualValues(e, e.TryFold());
}
@@ -424,7 +424,7 @@ public void VectorExpression7()
var e = new VectorExpression(new Literal("a"), new Literal("b"), new Literal("c"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(a, b, c)", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(a, b, c)"));
AssertExtensions.AreEqualValues(new Literal("a, b, c"), e.TryFold());
}
@@ -434,7 +434,7 @@ public void NameValuePairExpression()
var e = new NameValuePairExpression(new Literal("Fuse"), new Literal("1337"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(Fuse: 1337)", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("(Fuse: 1337)"));
AssertExtensions.AreEqualValues(e.Name, new Literal("Fuse"));
AssertExtensions.AreEqualValues(e.Value, new Literal("1337"));
}
@@ -445,8 +445,8 @@ public void LogicalNotExpression()
var e = new LogicalNotExpression(new StringLiteral("lol"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(!\"lol\")", e.ToString());
- Assert.AreEqual("LogicalNot", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(!\"lol\")"));
+ Assert.That(e.Name, Is.EqualTo("LogicalNot"));
}
[Test]
@@ -455,8 +455,8 @@ public void NegateExpression()
var e = new NegateExpression(new StringLiteral("lol"));
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("(-\"lol\")", e.ToString());
- Assert.AreEqual("Negate", e.Name);
+ Assert.That(e.ToString(), Is.EqualTo("(-\"lol\")"));
+ Assert.That(e.Name, Is.EqualTo("Negate"));
}
[Test]
@@ -465,7 +465,7 @@ public void FunctionCallExpression1()
var e = new FunctionCallExpression("someFunc", new Expression[0]);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("someFunc()", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("someFunc()"));
}
[Test]
@@ -474,7 +474,7 @@ public void FunctionCallExpression2()
var e = new FunctionCallExpression("", new Expression[0]);
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("()", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("()"));
}
[Test]
@@ -483,7 +483,7 @@ public void FunctionCallExpression3()
var e = new FunctionCallExpression("f", new[] { (Expression)new Literal("x") });
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("f(x)", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("f(x)"));
}
[Test]
@@ -492,7 +492,7 @@ public void FunctionCallExpression4()
var e = new FunctionCallExpression("f", new [] { (Expression)new Literal("x"), new StringLiteral("y") });
Assert.IsFalse(e.IsTrivial);
- Assert.AreEqual("f(x, \"y\")", e.ToString());
+ Assert.That(e.ToString(), Is.EqualTo("f(x, \"y\")"));
}
}
}
diff --git a/src/ux/tests/ParserTests/SimpleAstTests.cs b/src/ux/tests/ParserTests/SimpleAstTests.cs
index 0ce0684ab..6dde8958b 100644
--- a/src/ux/tests/ParserTests/SimpleAstTests.cs
+++ b/src/ux/tests/ParserTests/SimpleAstTests.cs
@@ -28,7 +28,7 @@ public void SingleElementWithSingleProperty()
var element = TestHelpers.Parse(docName, docCode);
AssertElement(element, ElementType.Object, "TheElement", new FileSourceInfo(docName, 1), typeof(UnspecifiedGenerator), 0);
- Assert.AreEqual(1, element.Properties.Count());
+ Assert.That(element.Properties.Count(), Is.EqualTo(1));
var prop = element.Properties.ElementAt(0);
AssertProperty(prop, "SomeProp", "SomeValue");
@@ -78,18 +78,18 @@ public void SingleElementWithSingleDependency()
void AssertElement(Element element, ElementType elementType, string typeName, FileSourceInfo source, Type generatorType, int childCount)
{
- Assert.AreEqual(elementType, element.ElementType);
- Assert.AreEqual(typeName, element.TypeName);
- Assert.AreEqual(source, element.Source);
- Assert.AreEqual(generatorType, element.Generator.GetType());
- Assert.AreEqual(childCount, element.Children.Count());
+ Assert.That(element.ElementType, Is.EqualTo(elementType));
+ Assert.That(element.TypeName, Is.EqualTo(typeName));
+ Assert.That(element.Source, Is.EqualTo(source));
+ Assert.That(element.Generator.GetType(), Is.EqualTo(generatorType));
+ Assert.That(element.Children.Count(), Is.EqualTo(childCount));
}
void AssertProperty(Property prop, string name, string value, string ns = "")
{
- Assert.AreEqual(name, prop.Name);
- Assert.AreEqual(value, prop.Value);
- Assert.AreEqual(ns, prop.Namespace);
+ Assert.That(prop.Name, Is.EqualTo(name));
+ Assert.That(prop.Value, Is.EqualTo(value));
+ Assert.That(prop.Namespace, Is.EqualTo(ns));
}
}
}
diff --git a/src/ux/tests/Uno.UX.Markup.Tests.csproj b/src/ux/tests/Uno.UX.Markup.Tests.csproj
index 457e8239a..7848904cc 100644
--- a/src/ux/tests/Uno.UX.Markup.Tests.csproj
+++ b/src/ux/tests/Uno.UX.Markup.Tests.csproj
@@ -1,82 +1,24 @@
-
-
-
-
+
+
+
- Debug
- AnyCPU
- {5FBF0E14-E093-47D7-A331-B3709A63D409}
- Library
- Properties
+ net6.0
Uno.UX.Markup.Tests
- Uno.UX.Markup.Tests
- v4.5
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
- ..\..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
-
- {d159dc86-f510-4fcf-9573-e339bdd6d166}
- Uno.Common
-
-
- {c4cf7639-0705-4093-b16d-3261a92f6260}
- Uno.Compiler.Core
-
-
- {05538951-c4a9-4298-bba7-fe9f96e3ddc1}
- Uno.UX.Markup
-
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
-
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
\ No newline at end of file
+
diff --git a/src/ux/tests/packages.config b/src/ux/tests/packages.config
deleted file mode 100644
index dba42d19d..000000000
--- a/src/ux/tests/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/uno.sln b/uno.sln
index 8c8e4881c..758f07282 100644
--- a/uno.sln
+++ b/uno.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
-VisualStudioVersion = 16.0.30002.166
+VisualStudioVersion = 25.0.1703.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "uno", "src\tool\cli\uno.csproj", "{5813CAEE-0804-45C2-A0C7-E30720EFBB45}"
EndProject