diff --git a/.editorconfig b/.editorconfig index 1909f880..97af5d1d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -244,7 +244,7 @@ dotnet_style_qualification_for_method = false:error dotnet_style_qualification_for_property = false:error dotnet_style_readonly_field = true:error -dotnet_style_require_accessibility_modifiers = always:error +dotnet_style_require_accessibility_modifiers = for_non_interface_members:error ############################################################################### # Set dotnet style options to: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ed9517c..8d0d4eda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,36 +25,46 @@ jobs: path: | ./artifacts/bin/**/* ./artifacts/log/**/* - ./artifacts/pkg/**/* ./artifacts/tst/**/* if-no-files-found: error - linux-x64: - runs-on: ${{ matrix.os }}-latest + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}_pkg + path: | + ./artifacts/pkg/**/* + if-no-files-found: error + windows-arm64: + runs-on: ${{ matrix.os }}-11-arm strategy: matrix: - architecture: [ x64 ] + architecture: [ arm64 ] configuration: [ debug, release ] - os: [ ubuntu ] + os: [ windows ] steps: - uses: actions/checkout@v4 - - run: ./scripts/cibuild.sh --configuration ${{ matrix.configuration }} --architecture ${{ matrix.architecture }} - shell: bash + - run: ./scripts/cibuild.cmd -configuration ${{ matrix.configuration }} -architecture ${{ matrix.architecture }} + shell: cmd - uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }} path: | ./artifacts/bin/**/* ./artifacts/log/**/* - ./artifacts/pkg/**/* ./artifacts/tst/**/* if-no-files-found: error - macos-x64: + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}_pkg + path: | + ./artifacts/pkg/**/*.win-arm64.* + if-no-files-found: error + linux-x64: runs-on: ${{ matrix.os }}-latest strategy: matrix: architecture: [ x64 ] configuration: [ debug, release ] - os: [ macos ] + os: [ ubuntu ] steps: - uses: actions/checkout@v4 - run: ./scripts/cibuild.sh --configuration ${{ matrix.configuration }} --architecture ${{ matrix.architecture }} @@ -65,100 +75,103 @@ jobs: path: | ./artifacts/bin/**/* ./artifacts/log/**/* - ./artifacts/pkg/**/* ./artifacts/tst/**/* if-no-files-found: error - build-nuget-preview: - runs-on: windows-latest + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}_pkg + path: | + ./artifacts/pkg/**/*.linux-x64.* + if-no-files-found: error + linux-arm64: + runs-on: ${{ matrix.os }}-24.04-arm + strategy: + matrix: + architecture: [ arm64 ] + configuration: [ debug, release ] + os: [ ubuntu ] steps: - uses: actions/checkout@v4 - - run: ./scripts/cibuild.cmd -configuration release -architecture x64 - shell: cmd - env: - EXCLUDE_RUN_ID_FROM_PACKAGE: true - EXCLUDE_SUFFIX_FROM_VERSION: false + - run: ./scripts/cibuild.sh --configuration ${{ matrix.configuration }} --architecture ${{ matrix.architecture }} + shell: bash - uses: actions/upload-artifact@v4 with: - name: nuget_preview + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }} path: | ./artifacts/bin/**/* ./artifacts/log/**/* - ./artifacts/pkg/**/* ./artifacts/tst/**/* if-no-files-found: error - sign-nuget-preview: - runs-on: windows-latest - if: ${{ github.event_name == 'push' }} - needs: [ build-nuget-preview ] - permissions: - id-token: write - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: - name: nuget_preview - path: ./artifacts - - uses: actions/setup-dotnet@v4 - with: - global-json-file: ./global.json - - run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3 - - run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --timestamp-url "http://timestamp.digicert.com" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "ClangSharp" --description-url "https://github.com/dotnet/clangsharp" --azure-key-vault-certificate "${{ secrets.SC_KEY_VAULT_CERTIFICATE_ID }}" --azure-key-vault-client-id "${{ secrets.SC_AZURE_CLIENT_ID }}" --azure-key-vault-client-secret "${{ secrets.SC_AZURE_CLIENT_SECRET }}" --azure-key-vault-tenant-id "${{ secrets.SC_AZURE_TENANT_ID }}" --azure-key-vault-url "${{ secrets.SC_KEY_VAULT_URL }}" - uses: actions/upload-artifact@v4 with: - name: sign_nuget_preview + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}_pkg path: | - ./artifacts/pkg/**/* + ./artifacts/pkg/**/*.linux-arm64.* if-no-files-found: error - build-nuget-release: - runs-on: windows-latest + macos-arm64: + runs-on: ${{ matrix.os }}-latest + strategy: + matrix: + architecture: [ arm64 ] + configuration: [ debug, release ] + os: [ macos ] steps: - uses: actions/checkout@v4 - - run: ./scripts/cibuild.cmd -configuration release -architecture x64 - shell: cmd - env: - EXCLUDE_RUN_ID_FROM_PACKAGE: true - EXCLUDE_SUFFIX_FROM_VERSION: true + - run: ./scripts/cibuild.sh --configuration ${{ matrix.configuration }} --architecture ${{ matrix.architecture }} + shell: bash - uses: actions/upload-artifact@v4 with: - name: nuget_release + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }} path: | ./artifacts/bin/**/* ./artifacts/log/**/* - ./artifacts/pkg/**/* ./artifacts/tst/**/* if-no-files-found: error - sign-nuget-release: + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}_pkg + path: | + ./artifacts/pkg/**/*.osx-arm64.* + if-no-files-found: error + sign-nuget: runs-on: windows-latest if: ${{ github.event_name == 'push' }} - needs: [ build-nuget-release ] + needs: [ windows-x64, windows-arm64, linux-x64, linux-arm64, macos-arm64 ] permissions: id-token: write steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: - name: nuget_release - path: ./artifacts + merge-multiple: true + path: ./artifacts/pkg + pattern: "*_release_*_pkg" - uses: actions/setup-dotnet@v4 with: global-json-file: ./global.json - - run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3 - - run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --timestamp-url "http://timestamp.digicert.com" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "ClangSharp" --description-url "https://github.com/dotnet/clangsharp" --azure-key-vault-certificate "${{ secrets.SC_KEY_VAULT_CERTIFICATE_ID }}" --azure-key-vault-client-id "${{ secrets.SC_AZURE_CLIENT_ID }}" --azure-key-vault-client-secret "${{ secrets.SC_AZURE_CLIENT_SECRET }}" --azure-key-vault-tenant-id "${{ secrets.SC_AZURE_TENANT_ID }}" --azure-key-vault-url "${{ secrets.SC_KEY_VAULT_URL }}" + - run: dotnet tool install --tool-path ./artifacts/tools --prerelease sign + - uses: azure/login@v2 + with: + allow-no-subscriptions: true + client-id: "${{ secrets.AZURE_CLIENT_ID }}" + tenant-id: "${{ secrets.AZURE_TENANT_ID }}" + - run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "ClangSharp" --description-url "https://github.com/dotnet/clangsharp" --azure-credential-type "azure-cli" --azure-key-vault-url "${{ secrets.KEY_VAULT_URL }}" --azure-key-vault-certificate "${{ secrets.KEY_VAULT_CERTIFICATE_ID }}" + shell: pwsh - uses: actions/upload-artifact@v4 with: - name: sign_nuget_release + name: sign_nuget path: | ./artifacts/pkg/**/* if-no-files-found: error publish-nightlies-azure: runs-on: ubuntu-latest if: ${{ github.event_name == 'push' }} - needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ] + needs: [ sign-nuget ] steps: - uses: actions/download-artifact@v4 with: - name: windows_release_x64 - path: ./artifacts + name: sign_nuget + path: ./artifacts/pkg - uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' @@ -169,12 +182,12 @@ jobs: publish-nightlies-github: runs-on: ubuntu-latest if: false - needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ] + needs: [ sign-nuget ] steps: - uses: actions/download-artifact@v4 with: - name: windows_release_x64 - path: ./artifacts + name: sign_nuget + path: ./artifacts/pkg - uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' diff --git a/CMakeLists.txt b/CMakeLists.txt index 047dec3d..8175a78b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.13) -project(ClangSharp VERSION 18.1.3) +project(ClangSharp VERSION 20.1.2) set(CMAKE_CXX_STANDARD 17) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/Directory.Build.props b/Directory.Build.props index 39a8f51d..af219597 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -43,12 +43,12 @@ .NET Foundation true true - $(BaseArtifactsPath)pkg/$(Configuration)/ + $(BaseArtifactsPath)pkg/$(Configuration)/$(PACKAGE_PUBLISH_MODE) 17.0.0 ClangSharp ClangSharp - 18.1.0.4 - rc1 + 20.1.2.3 + rc1 pr diff --git a/Directory.Build.targets b/Directory.Build.targets index db24925f..bd6fed59 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -17,7 +17,7 @@ - $(Version).$(GITHUB_RUN_ID) + $(Version).$(GITHUB_RUN_ID) @@ -31,10 +31,9 @@ true - - + + $(NETCoreSdkRuntimeIdentifier) - $(OVERRIDE_RUNTIME_IDENTIFIER) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6704befd..b9a02164 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -12,11 +12,11 @@ - - - - - + + + + + diff --git a/README.md b/README.md index 795e325a..df4ca5f2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A convenience package which provides the native libClang library for several pla A helper package which exposes many Clang APIs missing from libClang is provided here: https://www.nuget.org/packages/libClangSharp -**NOTE:** libclang and libClangSharp are meta-packages which point to the platform-specific runtime packages ([e.g.](https://www.nuget.org/packages/libClangSharp.runtime.win-x64/18.1.3); see others owned by [tannergooding](https://www.nuget.org/profiles/tannergooding)). Several manual steps may be required to use them, see discussion in [#46](https://github.com/dotnet/ClangSharp/issues/46) and [#118](https://github.com/dotnet/ClangSharp/issues/118). +**NOTE:** libclang and libClangSharp are meta-packages which point to the platform-specific runtime packages ([e.g.](https://www.nuget.org/packages/libClangSharp.runtime.win-x64/20.1.2); see others owned by [tannergooding](https://www.nuget.org/profiles/tannergooding)). Several manual steps may be required to use them, see discussion in [#46](https://github.com/dotnet/ClangSharp/issues/46) and [#118](https://github.com/dotnet/ClangSharp/issues/118). Nightly packages are available via the NuGet Feed URL: https://pkgs.clangsharp.dev/index.json @@ -55,7 +55,7 @@ See [LICENSE.md](LICENSE.md) in the repository root for more information. ### Building Managed -ClangSharp requires the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) and can be built simply with `dotnet build -c Release`. +ClangSharp requires the [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) and can be built simply with `dotnet build -c Release`. You can reproduce what the CI environment does by running `./scripts/cibuild.cmd` on Windows or `./scripts.cibuild.sh` on Unix. This will download the required .NET SDK locally and use that to build the repo; it will also run through all available actions in the appropriate order. @@ -77,14 +77,14 @@ To successfully build `libClangSharp` you must first build Clang (https://clang. The process done on Windows is roughly: ```cmd -git clone --single-branch --branch llvmorg-18.1.3 https://github.com/llvm/llvm-project +git clone --single-branch --branch llvmorg-20.1.2 https://github.com/llvm/llvm-project cd llvm-project mkdir artifacts/bin cd artifacts/bin cmake -DCMAKE_INSTALL_PREFIX=../install -DLLVM_ENABLE_PROJECTS=clang -G "Visual Studio 17 2022" -A x64 -Thost=x64 ../../llvm ``` -You can then open `LLVM.sln` in Visual Studio, change the configuration to `Release` and build the `install` project. +You can then open `LLVM.sln` in Visual Studio, change the configuration to `Release` and build the `INSTALL` project. You may need to build the `ALL_BUILD` first. Afterwards, you can then build `libClangSharp` where the process followed is roughly: ```cmd @@ -92,16 +92,16 @@ git clone https://github.com/dotnet/clangsharp cd clangsharp mkdir artifacts/bin/native cd artifacts/bin/native -cmake -DCMAKE_INSTALL_PREFIX=../install -DPATH_TO_LLVM=../../../../llvm-project/artifacts/install -G "Visual Studio 17 2022" -A x64 -Thost=x64 ../../.. +cmake -DCMAKE_INSTALL_PREFIX=../install -DPATH_TO_LLVM=absolute/path/to/repos/llvm-project/artifacts/install -G "Visual Studio 17 2022" -A x64 -Thost=x64 ../../.. ``` -You can then open `libClangSharp.sln` in Visual Studio, change the configuration to `Release` and build the `install` project. +You can then open `libClangSharp.sln` in Visual Studio, change the configuration to `Release` and build the `INSTALL` project. #### Linux The process done on Linux is roughly: ```bash -git clone --single-branch --branch llvmorg-18.1.3 https://github.com/llvm/llvm-project +git clone --single-branch --branch llvmorg-20.1.2 https://github.com/llvm/llvm-project cd llvm-project mkdir -p artifacts/bin cd artifacts/bin @@ -133,7 +133,7 @@ This program will take a given set of C or C++ header files and generate C# bind The simplest and recommended setup is to install the generator as a .NET tool and then use response files: ``` -dotnet tool install --global ClangSharpPInvokeGenerator --version 18.1.0 +dotnet tool install --global ClangSharpPInvokeGenerator ClangSharpPInvokeGenerator @generate.rsp ``` @@ -202,9 +202,9 @@ Options: # Codegen Options compatible-codegen Bindings should be generated with .NET Standard 2.0 compatibility. Setting this disables preview code generation. - default-codegen Bindings should be generated for the previous LTS version of .NET/C#. This is currently .NET 6/C# 10. - latest-codegen Bindings should be generated for the current LTS/STS version of .NET/C#. This is currently .NET 8/C# 12. - preview-codegen Bindings should be generated for the preview version of .NET/C#. This is currently .NET 9/C# 13. + default-codegen Bindings should be generated for the previous LTS version of .NET/C#. This is currently .NET 8/C# 12. + latest-codegen Bindings should be generated for the current LTS/STS version of .NET/C#. This is currently .NET 10/C# 14. + preview-codegen Bindings should be generated for the preview version of .NET/C#. This is currently .NET 10/C# 14. # File Options diff --git a/global.json b/global.json index 61d88a71..ff239fd9 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.100", + "version": "10.0.100-preview", "allowPrerelease": true, "rollForward": "latestFeature" } diff --git a/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec b/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec index 3396ab28..460b0606 100644 --- a/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.linux-arm64 - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.linux-x64/libClangSharp.runtime.linux-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.linux-x64/libClangSharp.runtime.linux-x64.nuspec index 4a4dff09..1ea7b854 100644 --- a/packages/libClangSharp/libClangSharp.runtime.linux-x64/libClangSharp.runtime.linux-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.linux-x64/libClangSharp.runtime.linux-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.linux-x64 - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.osx-arm64/libClangSharp.runtime.osx-arm64.nuspec b/packages/libClangSharp/libClangSharp.runtime.osx-arm64/libClangSharp.runtime.osx-arm64.nuspec index 640f6a12..1b64e045 100644 --- a/packages/libClangSharp/libClangSharp.runtime.osx-arm64/libClangSharp.runtime.osx-arm64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.osx-arm64/libClangSharp.runtime.osx-arm64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.osx-arm64 - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec deleted file mode 100644 index 42f41600..00000000 --- a/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - libClangSharp.runtime.osx-x64 - 18.1.3.1 - .NET Foundation and Contributors - .NET Foundation and Contributors - true - MIT - https://github.com/dotnet/clangsharp - osx x64 native library for libClangSharp. - Copyright © .NET Foundation and Contributors - - - - - - - - diff --git a/packages/libClangSharp/libClangSharp.runtime.win-arm64/libClangSharp.runtime.win-arm64.nuspec b/packages/libClangSharp/libClangSharp.runtime.win-arm64/libClangSharp.runtime.win-arm64.nuspec index f3c2fda8..e133ee34 100644 --- a/packages/libClangSharp/libClangSharp.runtime.win-arm64/libClangSharp.runtime.win-arm64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.win-arm64/libClangSharp.runtime.win-arm64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.win-arm64 - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec index 728a54bd..19c92c46 100644 --- a/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.win-x64 - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true diff --git a/packages/libClangSharp/libClangSharp/libClangSharp.nuspec b/packages/libClangSharp/libClangSharp/libClangSharp.nuspec index abc1c087..a74da320 100644 --- a/packages/libClangSharp/libClangSharp/libClangSharp.nuspec +++ b/packages/libClangSharp/libClangSharp/libClangSharp.nuspec @@ -2,7 +2,7 @@ libClangSharp - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true diff --git a/packages/libClangSharp/libClangSharp/runtime.json b/packages/libClangSharp/libClangSharp/runtime.json index 0d562838..1e1c054a 100644 --- a/packages/libClangSharp/libClangSharp/runtime.json +++ b/packages/libClangSharp/libClangSharp/runtime.json @@ -2,32 +2,27 @@ "runtimes": { "linux-arm64": { "libClangSharp": { - "libClangSharp.runtime.linux-arm64": "18.1.3.1" + "libClangSharp.runtime.linux-arm64": "20.1.2" } }, "linux-x64": { "libClangSharp": { - "libClangSharp.runtime.linux-x64": "18.1.3.1" + "libClangSharp.runtime.linux-x64": "20.1.2" } }, "osx-arm64": { "libClangSharp": { - "libClangSharp.runtime.osx-arm64": "18.1.3.1" - } - }, - "osx-x64": { - "libClangSharp": { - "libClangSharp.runtime.osx-x64": "18.1.3.1" + "libClangSharp.runtime.osx-arm64": "20.1.2" } }, "win-arm64": { "libClangSharp": { - "libClangSharp.runtime.win-arm64": "18.1.3.1" + "libClangSharp.runtime.win-arm64": "20.1.2" } }, "win-x64": { "libClangSharp": { - "libClangSharp.runtime.win-x64": "18.1.3.1" + "libClangSharp.runtime.win-x64": "20.1.2" } } } diff --git a/packages/libclang/libclang.runtime.linux-arm64/libclang.runtime.linux-arm64.nuspec b/packages/libclang/libclang.runtime.linux-arm64/libclang.runtime.linux-arm64.nuspec index 503bd138..8184b9c1 100644 --- a/packages/libclang/libclang.runtime.linux-arm64/libclang.runtime.linux-arm64.nuspec +++ b/packages/libclang/libclang.runtime.linux-arm64/libclang.runtime.linux-arm64.nuspec @@ -2,7 +2,7 @@ libclang.runtime.linux-arm64 - 18.1.3.2 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true @@ -10,7 +10,7 @@ https://github.com/dotnet/clangsharp linux arm64 native library for libclang. Copyright © LLVM Project - + diff --git a/packages/libclang/libclang.runtime.linux-x64/libclang.runtime.linux-x64.nuspec b/packages/libclang/libclang.runtime.linux-x64/libclang.runtime.linux-x64.nuspec index 3c428c7a..dc6fce53 100644 --- a/packages/libclang/libclang.runtime.linux-x64/libclang.runtime.linux-x64.nuspec +++ b/packages/libclang/libclang.runtime.linux-x64/libclang.runtime.linux-x64.nuspec @@ -2,7 +2,7 @@ libclang.runtime.linux-x64 - 18.1.3.2 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true @@ -10,7 +10,7 @@ https://github.com/dotnet/clangsharp linux x64 native library for libclang. Copyright © LLVM Project - + diff --git a/packages/libclang/libclang.runtime.osx-arm64/libclang.runtime.osx-arm64.nuspec b/packages/libclang/libclang.runtime.osx-arm64/libclang.runtime.osx-arm64.nuspec index 8baa43b3..e6221d5d 100644 --- a/packages/libclang/libclang.runtime.osx-arm64/libclang.runtime.osx-arm64.nuspec +++ b/packages/libclang/libclang.runtime.osx-arm64/libclang.runtime.osx-arm64.nuspec @@ -2,7 +2,7 @@ libclang.runtime.osx-arm64 - 18.1.3 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true @@ -10,7 +10,7 @@ https://github.com/dotnet/clangsharp osx arm64 native library for libclang. Copyright © LLVM Project - + diff --git a/packages/libclang/libclang.runtime.osx-x64/libclang.runtime.osx-x64.nuspec b/packages/libclang/libclang.runtime.osx-x64/libclang.runtime.osx-x64.nuspec deleted file mode 100644 index 79dd4e31..00000000 --- a/packages/libclang/libclang.runtime.osx-x64/libclang.runtime.osx-x64.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - libclang.runtime.osx-x64 - 18.1.3 - .NET Foundation and Contributors - .NET Foundation and Contributors - true - Apache-2.0 WITH LLVM-exception - https://github.com/dotnet/clangsharp - osx x64 native library for libclang. - Copyright © LLVM Project - - - - - - - diff --git a/packages/libclang/libclang.runtime.win-arm64/libclang.runtime.win-arm64.nuspec b/packages/libclang/libclang.runtime.win-arm64/libclang.runtime.win-arm64.nuspec index 2facf612..88e92023 100644 --- a/packages/libclang/libclang.runtime.win-arm64/libclang.runtime.win-arm64.nuspec +++ b/packages/libclang/libclang.runtime.win-arm64/libclang.runtime.win-arm64.nuspec @@ -2,7 +2,7 @@ libclang.runtime.win-arm64 - 18.1.3.1 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true @@ -10,7 +10,7 @@ https://github.com/dotnet/clangsharp win arm64 native library for libclang. Copyright © LLVM Project - + diff --git a/packages/libclang/libclang.runtime.win-x64/libclang.runtime.win-x64.nuspec b/packages/libclang/libclang.runtime.win-x64/libclang.runtime.win-x64.nuspec index df20a858..a032f9d0 100644 --- a/packages/libclang/libclang.runtime.win-x64/libclang.runtime.win-x64.nuspec +++ b/packages/libclang/libclang.runtime.win-x64/libclang.runtime.win-x64.nuspec @@ -2,7 +2,7 @@ libclang.runtime.win-x64 - 18.1.3.2 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true @@ -10,7 +10,7 @@ https://github.com/dotnet/clangsharp win x64 native library for libclang. Copyright © LLVM Project - + diff --git a/packages/libclang/libclang/libclang.nuspec b/packages/libclang/libclang/libclang.nuspec index 17113d9e..087f647d 100644 --- a/packages/libclang/libclang/libclang.nuspec +++ b/packages/libclang/libclang/libclang.nuspec @@ -2,7 +2,7 @@ libclang - 18.1.3.2 + 20.1.2 .NET Foundation and Contributors .NET Foundation and Contributors true @@ -10,7 +10,7 @@ https://github.com/dotnet/clangsharp Multi-platform native library for libclang. Copyright © LLVM Project - + diff --git a/packages/libclang/libclang/runtime.json b/packages/libclang/libclang/runtime.json index 6ef3f32b..b4d12cee 100644 --- a/packages/libclang/libclang/runtime.json +++ b/packages/libclang/libclang/runtime.json @@ -2,32 +2,27 @@ "runtimes": { "linux-arm64": { "libclang": { - "libclang.runtime.linux-arm64": "18.1.3.2" + "libclang.runtime.linux-arm64": "20.1.2" } }, "linux-x64": { "libclang": { - "libclang.runtime.linux-x64": "18.1.3.2" + "libclang.runtime.linux-x64": "20.1.2" } }, "osx-arm64": { "libclang": { - "libclang.runtime.osx-arm64": "18.1.3" - } - }, - "osx-x64": { - "libclang": { - "libclang.runtime.osx-x64": "18.1.3" + "libclang.runtime.osx-arm64": "20.1.2" } }, "win-arm64": { "libclang": { - "libclang.runtime.win-arm64": "18.1.3.1" + "libclang.runtime.win-arm64": "20.1.2" } }, "win-x64": { "libclang": { - "libclang.runtime.win-x64": "18.1.3.2" + "libclang.runtime.win-x64": "20.1.2" } } } diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 882eba52..89ae10f3 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -56,8 +56,18 @@ function Help() { } function Pack() { - $logFile = Join-Path -Path $LogDir -ChildPath "$configuration\pack.binlog" - & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err $properties "$solution" + $logFile = Join-Path -Path $LogDir -ChildPath "$configuration\pack" + + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.binlog" /err $properties "$solution" + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true $properties "$solution" + + if ($ci) { + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.preview.binlog" /err /p:PACKAGE_PUBLISH_MODE=preview $properties "$solution" + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.stable.binlog" /err /p:PACKAGE_PUBLISH_MODE=stable $properties "$solution" + + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.preview.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true /p:PACKAGE_PUBLISH_MODE=preview $properties "$solution" + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.stable.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true /p:PACKAGE_PUBLISH_MODE=stable $properties "$solution" + } if ($LastExitCode -ne 0) { throw "'Pack' failed for '$solution'" @@ -172,7 +182,7 @@ try { $DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet" Create-Directory -Path $DotNetInstallDirectory - & $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture + & $DotNetInstallScript -Channel 10.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture $env:PATH="$DotNetInstallDirectory;$env:PATH" } diff --git a/scripts/build.sh b/scripts/build.sh index c435695f..81d483ba 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -115,14 +115,32 @@ function Help { } function Pack { - logFile="$LogDir/$configuration/pack.binlog" + logFile="$LogDir/$configuration/pack" if [[ -z "$properties" ]]; then - dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.binlog" /err "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true "$solution" else - dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "${properties[@]}" "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.binlog" /err "${properties[@]}" "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true "${properties[@]}" "$solution" fi +if $ci; then + if [[ -z "$properties" ]]; then + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.preview.binlog" /err /p:PACKAGE_PUBLISH_MODE=preview "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.stable.binlog" /err /p:PACKAGE_PUBLISH_MODE=stable "$solution" + + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.preview.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true /p:PACKAGE_PUBLISH_MODE=preview "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.stable.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true /p:PACKAGE_PUBLISH_MODE=stable "$solution" + else + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.preview.binlog" /err /p:PACKAGE_PUBLISH_MODE=preview "${properties[@]}" "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.stable.binlog" /err /p:PACKAGE_PUBLISH_MODE=stable "${properties[@]}" "$solution" + + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.preview.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true /p:PACKAGE_PUBLISH_MODE=preview "${properties[@]}" "$solution" + dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile.agnostic.stable.binlog" /err /p:SKIP_USE_CURRENT_RUNTIME=true /p:PACKAGE_PUBLISH_MODE=stable "${properties[@]}" "$solution" + fi +fi + LASTEXITCODE=$? if [ "$LASTEXITCODE" != 0 ]; then @@ -204,7 +222,7 @@ if [[ ! -z "$architecture" ]]; then DotNetInstallDirectory="$ArtifactsDir/dotnet" CreateDirectory "$DotNetInstallDirectory" - . "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" + . "$DotNetInstallScript" --channel 10.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" PATH="$DotNetInstallDirectory:$PATH:" fi diff --git a/sources/ClangSharp.Interop/ClangSharp.Interop.csproj b/sources/ClangSharp.Interop/ClangSharp.Interop.csproj index 0e1fe8a1..dd01281b 100644 --- a/sources/ClangSharp.Interop/ClangSharp.Interop.csproj +++ b/sources/ClangSharp.Interop/ClangSharp.Interop.csproj @@ -2,7 +2,7 @@ - net8.0 + net10.0 diff --git a/sources/ClangSharp.Interop/Extensions/CXCursor.cs b/sources/ClangSharp.Interop/Extensions/CXCursor.cs index 11963608..0cccb0b3 100644 --- a/sources/ClangSharp.Interop/Extensions/CXCursor.cs +++ b/sources/ClangSharp.Interop/Extensions/CXCursor.cs @@ -37,7 +37,7 @@ public readonly string AttrKindSpelling Debug.Assert(CX_AttrKind_FirstTypeAttr == CX_AttrKind_AddressSpace); Debug.Assert(CX_AttrKind_LastTypeAttr == CX_AttrKind_WebAssemblyFuncref); - Debug.Assert(CX_AttrKind_FirstStmtAttr == CX_AttrKind_CodeAlign); + Debug.Assert(CX_AttrKind_FirstStmtAttr == CX_AttrKind_CXXAssume); Debug.Assert(CX_AttrKind_LastStmtAttr == CX_AttrKind_Unlikely); Debug.Assert(CX_AttrKind_FirstDeclOrStmtAttr == CX_AttrKind_AlwaysInline); @@ -49,19 +49,21 @@ public readonly string AttrKindSpelling Debug.Assert(CX_AttrKind_FirstDeclOrTypeAttr == CX_AttrKind_AArch64SVEPcs); Debug.Assert(CX_AttrKind_LastDeclOrTypeAttr == CX_AttrKind_VectorCall); - Debug.Assert(CX_AttrKind_FirstInheritableParamAttr == CX_AttrKind_SwiftAsyncContext); + Debug.Assert(CX_AttrKind_FirstInheritableParamAttr == CX_AttrKind_Annotate); Debug.Assert(CX_AttrKind_LastInheritableParamAttr == CX_AttrKind_UseHandle); - Debug.Assert(CX_AttrKind_FirstParameterABIAttr == CX_AttrKind_SwiftAsyncContext); + Debug.Assert(CX_AttrKind_FirstParameterABIAttr == CX_AttrKind_HLSLParamModifier); Debug.Assert(CX_AttrKind_LastParameterABIAttr == CX_AttrKind_SwiftIndirectResult); - Debug.Assert(CX_AttrKind_FirstHLSLAnnotationAttr == CX_AttrKind_HLSLSV_DispatchThreadID); - Debug.Assert(CX_AttrKind_LastHLSLAnnotationAttr == CX_AttrKind_HLSLSV_GroupIndex); + Debug.Assert(CX_AttrKind_FirstHLSLAnnotationAttr == CX_AttrKind_HLSLPackOffset); + Debug.Assert(CX_AttrKind_LastHLSLAnnotationAttr == CX_AttrKind_HLSLSV_GroupThreadID); return AttrKind switch { CX_AttrKind_Invalid => "Invalid", CX_AttrKind_AddressSpace => "AddressSpace", + CX_AttrKind_Allocating => "Allocating", CX_AttrKind_AnnotateType => "AnnotateType", + CX_AttrKind_ArmAgnostic => "ArmAgnostic", CX_AttrKind_ArmIn => "ArmIn", CX_AttrKind_ArmInOut => "ArmInOut", CX_AttrKind_ArmMveStrictPolymorphism => "ArmMveStrictPolymorphism", @@ -70,10 +72,16 @@ public readonly string AttrKindSpelling CX_AttrKind_ArmStreaming => "ArmStreaming", CX_AttrKind_ArmStreamingCompatible => "ArmStreamingCompatible", CX_AttrKind_BTFTypeTag => "BTFTypeTag", + CX_AttrKind_Blocking => "Blocking", CX_AttrKind_CmseNSCall => "CmseNSCall", + CX_AttrKind_HLSLContainedType => "HLSLContainedType", CX_AttrKind_HLSLGroupSharedAddressSpace => "HLSLGroupSharedAddressSpace", - CX_AttrKind_HLSLParamModifier => "HLSLParamModifier", + CX_AttrKind_HLSLROV => "HLSLROV", + CX_AttrKind_HLSLRawBuffer => "HLSLRawBuffer", + CX_AttrKind_HLSLResourceClass => "HLSLResourceClass", CX_AttrKind_NoDeref => "NoDeref", + CX_AttrKind_NonAllocating => "NonAllocating", + CX_AttrKind_NonBlocking => "NonBlocking", CX_AttrKind_ObjCGC => "ObjCGC", CX_AttrKind_ObjCInertUnsafeUnretained => "ObjCInertUnsafeUnretained", CX_AttrKind_ObjCKindOf => "ObjCKindOf", @@ -89,12 +97,14 @@ public readonly string AttrKindSpelling CX_AttrKind_SPtr => "SPtr", CX_AttrKind_TypeNonNull => "TypeNonNull", CX_AttrKind_TypeNullUnspecified => "TypeNullUnspecified", - CX_AttrKind_TypeNullable => "TypeNullable", CX_AttrKind_TypeNullableResult => "TypeNullableResult", CX_AttrKind_UPtr => "UPtr", CX_AttrKind_WebAssemblyFuncref => "WebAssemblyFuncref", + CX_AttrKind_CXXAssume => "CXXAssume", CX_AttrKind_CodeAlign => "CodeAlign", CX_AttrKind_FallThrough => "FallThrough", + CX_AttrKind_HLSLControlFlowHint => "HLSLControlFlowHint", + CX_AttrKind_HLSLLoopHint => "HLSLLoopHint", CX_AttrKind_Likely => "Likely", CX_AttrKind_MustTail => "MustTail", CX_AttrKind_OpenCLUnrollHint => "OpenCLUnrollHint", @@ -109,9 +119,12 @@ public readonly string AttrKindSpelling CX_AttrKind_AcquireHandle => "AcquireHandle", CX_AttrKind_AnyX86NoCfCheck => "AnyX86NoCfCheck", CX_AttrKind_CDecl => "CDecl", + CX_AttrKind_CountedBy => "CountedBy", + CX_AttrKind_CountedByOrNull => "CountedByOrNull", CX_AttrKind_FastCall => "FastCall", CX_AttrKind_IntelOclBicc => "IntelOclBicc", CX_AttrKind_LifetimeBound => "LifetimeBound", + CX_AttrKind_LifetimeCaptureBy => "LifetimeCaptureBy", CX_AttrKind_M68kRTD => "M68kRTD", CX_AttrKind_MSABI => "MSABI", CX_AttrKind_NSReturnsRetained => "NSReturnsRetained", @@ -120,18 +133,25 @@ public readonly string AttrKindSpelling CX_AttrKind_Pcs => "Pcs", CX_AttrKind_PreserveAll => "PreserveAll", CX_AttrKind_PreserveMost => "PreserveMost", + CX_AttrKind_PreserveNone => "PreserveNone", + CX_AttrKind_RISCVVectorCC => "RISCVVectorCC", CX_AttrKind_RegCall => "RegCall", + CX_AttrKind_SizedBy => "SizedBy", + CX_AttrKind_SizedByOrNull => "SizedByOrNull", CX_AttrKind_StdCall => "StdCall", CX_AttrKind_SwiftAsyncCall => "SwiftAsyncCall", + CX_AttrKind_SwiftAttr => "SwiftAttr", CX_AttrKind_SwiftCall => "SwiftCall", CX_AttrKind_SysVABI => "SysVABI", CX_AttrKind_ThisCall => "ThisCall", + CX_AttrKind_TypeNullable => "TypeNullable", CX_AttrKind_VectorCall => "VectorCall", + CX_AttrKind_Annotate => "Annotate", + CX_AttrKind_HLSLParamModifier => "HLSLParamModifier", CX_AttrKind_SwiftAsyncContext => "SwiftAsyncContext", CX_AttrKind_SwiftContext => "SwiftContext", CX_AttrKind_SwiftErrorResult => "SwiftErrorResult", CX_AttrKind_SwiftIndirectResult => "SwiftIndirectResult", - CX_AttrKind_Annotate => "Annotate", CX_AttrKind_CFConsumed => "CFConsumed", CX_AttrKind_CarriesDependency => "CarriesDependency", CX_AttrKind_NSConsumed => "NSConsumed", @@ -140,9 +160,13 @@ public readonly string AttrKindSpelling CX_AttrKind_PassObjectSize => "PassObjectSize", CX_AttrKind_ReleaseHandle => "ReleaseHandle", CX_AttrKind_UseHandle => "UseHandle", + CX_AttrKind_HLSLPackOffset => "HLSLPackOffset", CX_AttrKind_HLSLSV_DispatchThreadID => "HLSLSV_DispatchThreadID", + CX_AttrKind_HLSLSV_GroupID => "HLSLSV_GroupID", CX_AttrKind_HLSLSV_GroupIndex => "HLSLSV_GroupIndex", + CX_AttrKind_HLSLSV_GroupThreadID => "HLSLSV_GroupThreadID", CX_AttrKind_AMDGPUFlatWorkGroupSize => "AMDGPUFlatWorkGroupSize", + CX_AttrKind_AMDGPUMaxNumWorkGroups => "AMDGPUMaxNumWorkGroups", CX_AttrKind_AMDGPUNumSGPR => "AMDGPUNumSGPR", CX_AttrKind_AMDGPUNumVGPR => "AMDGPUNumVGPR", CX_AttrKind_AMDGPUWavesPerEU => "AMDGPUWavesPerEU", @@ -172,9 +196,9 @@ public readonly string AttrKindSpelling CX_AttrKind_AssertExclusiveLock => "AssertExclusiveLock", CX_AttrKind_AssertSharedLock => "AssertSharedLock", CX_AttrKind_AssumeAligned => "AssumeAligned", - CX_AttrKind_Assumption => "Assumption", CX_AttrKind_Availability => "Availability", CX_AttrKind_AvailableOnlyInDefaultEvalMethod => "AvailableOnlyInDefaultEvalMethod", + CX_AttrKind_BPFFastCall => "BPFFastCall", CX_AttrKind_BPFPreserveAccessIndex => "BPFPreserveAccessIndex", CX_AttrKind_BPFPreserveStaticOffset => "BPFPreserveStaticOffset", CX_AttrKind_BTFDeclTag => "BTFDeclTag", @@ -194,6 +218,7 @@ public readonly string AttrKindSpelling CX_AttrKind_CUDADeviceBuiltinSurfaceType => "CUDADeviceBuiltinSurfaceType", CX_AttrKind_CUDADeviceBuiltinTextureType => "CUDADeviceBuiltinTextureType", CX_AttrKind_CUDAGlobal => "CUDAGlobal", + CX_AttrKind_CUDAGridConstant => "CUDAGridConstant", CX_AttrKind_CUDAHost => "CUDAHost", CX_AttrKind_CUDAInvalidTarget => "CUDAInvalidTarget", CX_AttrKind_CUDALaunchBounds => "CUDALaunchBounds", @@ -204,6 +229,7 @@ public readonly string AttrKindSpelling CX_AttrKind_Capability => "Capability", CX_AttrKind_CapturedRecord => "CapturedRecord", CX_AttrKind_Cleanup => "Cleanup", + CX_AttrKind_ClspvLibclcBuiltin => "ClspvLibclcBuiltin", CX_AttrKind_CmseNSEntry => "CmseNSEntry", CX_AttrKind_CodeModel => "CodeModel", CX_AttrKind_CodeSeg => "CodeSeg", @@ -216,12 +242,13 @@ public readonly string AttrKindSpelling CX_AttrKind_ConsumableAutoCast => "ConsumableAutoCast", CX_AttrKind_ConsumableSetOnRead => "ConsumableSetOnRead", CX_AttrKind_Convergent => "Convergent", + CX_AttrKind_CoroAwaitElidable => "CoroAwaitElidable", + CX_AttrKind_CoroAwaitElidableArgument => "CoroAwaitElidableArgument", CX_AttrKind_CoroDisableLifetimeBound => "CoroDisableLifetimeBound", CX_AttrKind_CoroLifetimeBound => "CoroLifetimeBound", CX_AttrKind_CoroOnlyDestroyWhenComplete => "CoroOnlyDestroyWhenComplete", CX_AttrKind_CoroReturnType => "CoroReturnType", CX_AttrKind_CoroWrapper => "CoroWrapper", - CX_AttrKind_CountedBy => "CountedBy", CX_AttrKind_DLLExport => "DLLExport", CX_AttrKind_DLLExportStaticLocal => "DLLExportStaticLocal", CX_AttrKind_DLLImport => "DLLImport", @@ -240,6 +267,7 @@ public readonly string AttrKindSpelling CX_AttrKind_Error => "Error", CX_AttrKind_ExcludeFromExplicitInstantiation => "ExcludeFromExplicitInstantiation", CX_AttrKind_ExclusiveTrylockFunction => "ExclusiveTrylockFunction", + CX_AttrKind_ExplicitInit => "ExplicitInit", CX_AttrKind_ExternalSourceSymbol => "ExternalSourceSymbol", CX_AttrKind_Final => "Final", CX_AttrKind_FlagEnum => "FlagEnum", @@ -255,7 +283,9 @@ public readonly string AttrKindSpelling CX_AttrKind_HLSLResource => "HLSLResource", CX_AttrKind_HLSLResourceBinding => "HLSLResourceBinding", CX_AttrKind_HLSLShader => "HLSLShader", + CX_AttrKind_HLSLWaveSize => "HLSLWaveSize", CX_AttrKind_Hot => "Hot", + CX_AttrKind_HybridPatchable => "HybridPatchable", CX_AttrKind_IBAction => "IBAction", CX_AttrKind_IBOutlet => "IBOutlet", CX_AttrKind_IBOutletCollection => "IBOutletCollection", @@ -293,6 +323,7 @@ public readonly string AttrKindSpelling CX_AttrKind_Naked => "Naked", CX_AttrKind_NoAlias => "NoAlias", CX_AttrKind_NoCommon => "NoCommon", + CX_AttrKind_NoConvergent => "NoConvergent", CX_AttrKind_NoDebug => "NoDebug", CX_AttrKind_NoDestroy => "NoDestroy", CX_AttrKind_NoDuplicate => "NoDuplicate", @@ -303,15 +334,18 @@ public readonly string AttrKindSpelling CX_AttrKind_NoRandomizeLayout => "NoRandomizeLayout", CX_AttrKind_NoReturn => "NoReturn", CX_AttrKind_NoSanitize => "NoSanitize", + CX_AttrKind_NoSpecializations => "NoSpecializations", CX_AttrKind_NoSpeculativeLoadHardening => "NoSpeculativeLoadHardening", CX_AttrKind_NoSplitStack => "NoSplitStack", CX_AttrKind_NoStackProtector => "NoStackProtector", CX_AttrKind_NoThreadSafetyAnalysis => "NoThreadSafetyAnalysis", CX_AttrKind_NoThrow => "NoThrow", + CX_AttrKind_NoTrivialAutoVarInit => "NoTrivialAutoVarInit", CX_AttrKind_NoUniqueAddress => "NoUniqueAddress", CX_AttrKind_NoUwtable => "NoUwtable", CX_AttrKind_NotTailCalled => "NotTailCalled", CX_AttrKind_OMPAllocateDecl => "OMPAllocateDecl", + CX_AttrKind_OMPAssume => "OMPAssume", CX_AttrKind_OMPCaptureNoInit => "OMPCaptureNoInit", CX_AttrKind_OMPDeclareTargetDecl => "OMPDeclareTargetDecl", CX_AttrKind_OMPDeclareVariant => "OMPDeclareVariant", @@ -369,6 +403,7 @@ public readonly string AttrKindSpelling CX_AttrKind_ReturnsNonNull => "ReturnsNonNull", CX_AttrKind_ReturnsTwice => "ReturnsTwice", CX_AttrKind_SYCLKernel => "SYCLKernel", + CX_AttrKind_SYCLKernelEntryPoint => "SYCLKernelEntryPoint", CX_AttrKind_SYCLSpecialClass => "SYCLSpecialClass", CX_AttrKind_ScopedLockable => "ScopedLockable", CX_AttrKind_Section => "Section", @@ -383,7 +418,6 @@ public readonly string AttrKindSpelling CX_AttrKind_SwiftAsync => "SwiftAsync", CX_AttrKind_SwiftAsyncError => "SwiftAsyncError", CX_AttrKind_SwiftAsyncName => "SwiftAsyncName", - CX_AttrKind_SwiftAttr => "SwiftAttr", CX_AttrKind_SwiftBridge => "SwiftBridge", CX_AttrKind_SwiftBridgedTypedef => "SwiftBridgedTypedef", CX_AttrKind_SwiftError => "SwiftError", @@ -409,6 +443,7 @@ public readonly string AttrKindSpelling CX_AttrKind_Used => "Used", CX_AttrKind_UsingIfExists => "UsingIfExists", CX_AttrKind_Uuid => "Uuid", + CX_AttrKind_VTablePointerAuthentication => "VTablePointerAuthentication", CX_AttrKind_VecReturn => "VecReturn", CX_AttrKind_VecTypeHint => "VecTypeHint", CX_AttrKind_Visibility => "Visibility", @@ -451,7 +486,6 @@ public readonly string AttrKindSpelling CX_AttrKind_ObjCRuntimeVisible => "ObjCRuntimeVisible", CX_AttrKind_OpenCLAccess => "OpenCLAccess", CX_AttrKind_Overloadable => "Overloadable", - CX_AttrKind_RenderScriptKernel => "RenderScriptKernel", CX_AttrKind_SwiftObjCMembers => "SwiftObjCMembers", CX_AttrKind_SwiftVersionedAddition => "SwiftVersionedAddition", CX_AttrKind_SwiftVersionedRemoval => "SwiftVersionedRemoval", @@ -1319,7 +1353,7 @@ public readonly string StmtClassSpelling Debug.Assert(CX_StmtClass_LastSwitchCase == CX_StmtClass_CaseStmt); Debug.Assert(CX_StmtClass_FirstOMPLoopTransformationDirective == CX_StmtClass_OMPUnrollDirective); - Debug.Assert(CX_StmtClass_LastOMPLoopTransformationDirective == CX_StmtClass_OMPTileDirective); + Debug.Assert(CX_StmtClass_LastOMPLoopTransformationDirective == CX_StmtClass_OMPInterchangeDirective); Debug.Assert(CX_StmtClass_FirstOMPLoopDirective == CX_StmtClass_OMPTeamsGenericLoopDirective); Debug.Assert(CX_StmtClass_LastOMPLoopDirective == CX_StmtClass_OMPDistributeDirective); @@ -1328,7 +1362,7 @@ public readonly string StmtClassSpelling Debug.Assert(CX_StmtClass_LastOMPLoopBasedDirective == CX_StmtClass_OMPDistributeDirective); Debug.Assert(CX_StmtClass_FirstOMPExecutableDirective == CX_StmtClass_OMPTeamsDirective); - Debug.Assert(CX_StmtClass_LastOMPExecutableDirective == CX_StmtClass_OMPAtomicDirective); + Debug.Assert(CX_StmtClass_LastOMPExecutableDirective == CX_StmtClass_OMPAssumeDirective); Debug.Assert(CX_StmtClass_FirstAsmStmt == CX_StmtClass_MSAsmStmt); Debug.Assert(CX_StmtClass_LastAsmStmt == CX_StmtClass_GCCAsmStmt); @@ -1381,7 +1415,7 @@ public readonly string StmtClassSpelling CX_StmtClass_ObjCArrayLiteral => "ObjCArrayLiteral", CX_StmtClass_OMPIteratorExpr => "OMPIteratorExpr", CX_StmtClass_OMPArrayShapingExpr => "OMPArrayShapingExpr", - CX_StmtClass_OMPArraySectionExpr => "OMPArraySectionExpr", + CX_StmtClass_ArraySectionExpr => "ArraySectionExpr", CX_StmtClass_NoInitExpr => "NoInitExpr", CX_StmtClass_MemberExpr => "MemberExpr", CX_StmtClass_MatrixSubscriptExpr => "MatrixSubscriptExpr", @@ -1439,6 +1473,7 @@ public readonly string StmtClassSpelling CX_StmtClass_CXXRewrittenBinaryOperator => "CXXRewrittenBinaryOperator", CX_StmtClass_CXXPseudoDestructorExpr => "CXXPseudoDestructorExpr", CX_StmtClass_CXXParenListInitExpr => "CXXParenListInitExpr", + CX_StmtClass_PackIndexingExpr => "PackIndexingExpr", CX_StmtClass_CXXNullPtrLiteralExpr => "CXXNullPtrLiteralExpr", CX_StmtClass_CXXNoexceptExpr => "CXXNoexceptExpr", CX_StmtClass_CXXNewExpr => "CXXNewExpr", diff --git a/sources/ClangSharp.Interop/Extensions/CXUnsavedFile.cs b/sources/ClangSharp.Interop/Extensions/CXUnsavedFile.cs index 3f61354a..cf2bce27 100644 --- a/sources/ClangSharp.Interop/Extensions/CXUnsavedFile.cs +++ b/sources/ClangSharp.Interop/Extensions/CXUnsavedFile.cs @@ -46,6 +46,41 @@ public static CXUnsavedFile Create(string filename, string contents) }; } + public static CXUnsavedFile Create(string filename, CXTranslationUnit translationUnit, CXFile baseFile, string additionalContents) + { + sbyte* pFilename, pContents; + nuint contentsLength; + + if (string.IsNullOrEmpty(filename)) + { + pFilename = null; + } + else + { + var maxFilenameLength = Encoding.UTF8.GetMaxByteCount(filename.Length); + pFilename = (sbyte*)NativeMemory.Alloc((uint)maxFilenameLength + 1); + var filenameLength = (uint)Encoding.UTF8.GetBytes(filename, new Span(pFilename, maxFilenameLength)); + pFilename[filenameLength] = 0; + } + + var baseFileContents = translationUnit.GetFileContents(baseFile, out _); + var maxContentsLength = baseFileContents.Length + Encoding.UTF8.GetMaxByteCount((additionalContents?.Length).GetValueOrDefault()); + + pContents = (sbyte*)NativeMemory.Alloc((uint)maxContentsLength + 1); + + var contents = new Span(pContents, maxContentsLength); + baseFileContents.CopyTo(contents); + + contentsLength = (uint)(baseFileContents.Length + Encoding.UTF8.GetBytes(additionalContents, contents[baseFileContents.Length..])); + pContents[contentsLength] = 0; + + return new CXUnsavedFile() { + Filename = pFilename, + Contents = pContents, + Length = contentsLength + }; + } + public void Dispose() { if (Filename != null) diff --git a/sources/ClangSharp.Interop/Manual/CXAPISetImpl.cs b/sources/ClangSharp.Interop/Manual/CXAPISetImpl.cs index 3a31c17d..612f51cd 100644 --- a/sources/ClangSharp.Interop/Manual/CXAPISetImpl.cs +++ b/sources/ClangSharp.Interop/Manual/CXAPISetImpl.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/Manual/CXCursorSetImpl.cs b/sources/ClangSharp.Interop/Manual/CXCursorSetImpl.cs index 13ee87e4..11d42ea3 100644 --- a/sources/ClangSharp.Interop/Manual/CXCursorSetImpl.cs +++ b/sources/ClangSharp.Interop/Manual/CXCursorSetImpl.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/Manual/CXCursorVisitor.cs b/sources/ClangSharp.Interop/Manual/CXCursorVisitor.cs index e4a1aeda..84a4ebed 100644 --- a/sources/ClangSharp.Interop/Manual/CXCursorVisitor.cs +++ b/sources/ClangSharp.Interop/Manual/CXCursorVisitor.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.InteropServices; diff --git a/sources/ClangSharp.Interop/Manual/CXFieldVisitor.cs b/sources/ClangSharp.Interop/Manual/CXFieldVisitor.cs index bf4f22de..8806d8a2 100644 --- a/sources/ClangSharp.Interop/Manual/CXFieldVisitor.cs +++ b/sources/ClangSharp.Interop/Manual/CXFieldVisitor.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.InteropServices; diff --git a/sources/ClangSharp.Interop/Manual/CXInclusionVisitor.cs b/sources/ClangSharp.Interop/Manual/CXInclusionVisitor.cs index 318e7588..6c2a355b 100644 --- a/sources/ClangSharp.Interop/Manual/CXInclusionVisitor.cs +++ b/sources/ClangSharp.Interop/Manual/CXInclusionVisitor.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.InteropServices; diff --git a/sources/ClangSharp.Interop/Manual/CXModuleMapDescriptorImpl.cs b/sources/ClangSharp.Interop/Manual/CXModuleMapDescriptorImpl.cs index 398c18c0..bb24b593 100644 --- a/sources/ClangSharp.Interop/Manual/CXModuleMapDescriptorImpl.cs +++ b/sources/ClangSharp.Interop/Manual/CXModuleMapDescriptorImpl.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/Manual/CXTargetInfoImpl.cs b/sources/ClangSharp.Interop/Manual/CXTargetInfoImpl.cs index 68102601..27af3182 100644 --- a/sources/ClangSharp.Interop/Manual/CXTargetInfoImpl.cs +++ b/sources/ClangSharp.Interop/Manual/CXTargetInfoImpl.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/Manual/CXTranslationUnitImpl.cs b/sources/ClangSharp.Interop/Manual/CXTranslationUnitImpl.cs index fe344762..b1f182a8 100644 --- a/sources/ClangSharp.Interop/Manual/CXTranslationUnitImpl.cs +++ b/sources/ClangSharp.Interop/Manual/CXTranslationUnitImpl.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/Manual/CXVirtualFileOverlayImpl.cs b/sources/ClangSharp.Interop/Manual/CXVirtualFileOverlayImpl.cs index 49e9b937..063f079c 100644 --- a/sources/ClangSharp.Interop/Manual/CXVirtualFileOverlayImpl.cs +++ b/sources/ClangSharp.Interop/Manual/CXVirtualFileOverlayImpl.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang.cs b/sources/ClangSharp.Interop/clang.cs index b6546231..037ab5b1 100644 --- a/sources/ClangSharp.Interop/clang.cs +++ b/sources/ClangSharp.Interop/clang.cs @@ -41,8 +41,8 @@ private static bool TryResolveClang(Assembly assembly, DllImportSearchPath? sear { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - return NativeLibrary.TryLoad("libclang.so.18", assembly, searchPath, out nativeLibrary) - || NativeLibrary.TryLoad("libclang-18", assembly, searchPath, out nativeLibrary) + return NativeLibrary.TryLoad("libclang.so.20", assembly, searchPath, out nativeLibrary) + || NativeLibrary.TryLoad("libclang-20", assembly, searchPath, out nativeLibrary) || NativeLibrary.TryLoad("libclang.so.1", assembly, searchPath, out nativeLibrary); } diff --git a/sources/ClangSharp.Interop/clang/CXAvailabilityKind.cs b/sources/ClangSharp.Interop/clang/CXAvailabilityKind.cs index 8957cf6e..d12d154d 100644 --- a/sources/ClangSharp.Interop/clang/CXAvailabilityKind.cs +++ b/sources/ClangSharp.Interop/clang/CXAvailabilityKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXBinaryOperatorKind.cs b/sources/ClangSharp.Interop/clang/CXBinaryOperatorKind.cs index 6b49fc03..9a82a8a7 100644 --- a/sources/ClangSharp.Interop/clang/CXBinaryOperatorKind.cs +++ b/sources/ClangSharp.Interop/clang/CXBinaryOperatorKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCallingConv.cs b/sources/ClangSharp.Interop/clang/CXCallingConv.cs index c54eb79f..363b8de9 100644 --- a/sources/ClangSharp.Interop/clang/CXCallingConv.cs +++ b/sources/ClangSharp.Interop/clang/CXCallingConv.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; @@ -28,6 +28,8 @@ public enum CXCallingConv CXCallingConv_SwiftAsync = 17, CXCallingConv_AArch64SVEPCS = 18, CXCallingConv_M68kRTD = 19, + CXCallingConv_PreserveNone = 20, + CXCallingConv_RISCVVectorCall = 21, CXCallingConv_Invalid = 100, CXCallingConv_Unexposed = 200, } diff --git a/sources/ClangSharp.Interop/clang/CXChildVisitResult.cs b/sources/ClangSharp.Interop/clang/CXChildVisitResult.cs index 703f2628..fec57984 100644 --- a/sources/ClangSharp.Interop/clang/CXChildVisitResult.cs +++ b/sources/ClangSharp.Interop/clang/CXChildVisitResult.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXChoice.cs b/sources/ClangSharp.Interop/clang/CXChoice.cs index 4b1f9269..92214e7b 100644 --- a/sources/ClangSharp.Interop/clang/CXChoice.cs +++ b/sources/ClangSharp.Interop/clang/CXChoice.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCodeCompleteResults.cs b/sources/ClangSharp.Interop/clang/CXCodeCompleteResults.cs index db791bf3..2182d5dd 100644 --- a/sources/ClangSharp.Interop/clang/CXCodeCompleteResults.cs +++ b/sources/ClangSharp.Interop/clang/CXCodeCompleteResults.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCodeComplete_Flags.cs b/sources/ClangSharp.Interop/clang/CXCodeComplete_Flags.cs index 531a940f..8cadfc19 100644 --- a/sources/ClangSharp.Interop/clang/CXCodeComplete_Flags.cs +++ b/sources/ClangSharp.Interop/clang/CXCodeComplete_Flags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXComment.cs b/sources/ClangSharp.Interop/clang/CXComment.cs index cb17ef6c..70f16530 100644 --- a/sources/ClangSharp.Interop/clang/CXComment.cs +++ b/sources/ClangSharp.Interop/clang/CXComment.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCommentInlineCommandRenderKind.cs b/sources/ClangSharp.Interop/clang/CXCommentInlineCommandRenderKind.cs index a0a66953..e5cd9292 100644 --- a/sources/ClangSharp.Interop/clang/CXCommentInlineCommandRenderKind.cs +++ b/sources/ClangSharp.Interop/clang/CXCommentInlineCommandRenderKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCommentKind.cs b/sources/ClangSharp.Interop/clang/CXCommentKind.cs index 3ec91725..db9b1594 100644 --- a/sources/ClangSharp.Interop/clang/CXCommentKind.cs +++ b/sources/ClangSharp.Interop/clang/CXCommentKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCommentParamPassDirection.cs b/sources/ClangSharp.Interop/clang/CXCommentParamPassDirection.cs index 4ba704d3..20f89f03 100644 --- a/sources/ClangSharp.Interop/clang/CXCommentParamPassDirection.cs +++ b/sources/ClangSharp.Interop/clang/CXCommentParamPassDirection.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCompilationDatabase_Error.cs b/sources/ClangSharp.Interop/clang/CXCompilationDatabase_Error.cs index 9be2b02d..738908f5 100644 --- a/sources/ClangSharp.Interop/clang/CXCompilationDatabase_Error.cs +++ b/sources/ClangSharp.Interop/clang/CXCompilationDatabase_Error.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCompletionChunkKind.cs b/sources/ClangSharp.Interop/clang/CXCompletionChunkKind.cs index ea3a04eb..0282ea5f 100644 --- a/sources/ClangSharp.Interop/clang/CXCompletionChunkKind.cs +++ b/sources/ClangSharp.Interop/clang/CXCompletionChunkKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCompletionContext.cs b/sources/ClangSharp.Interop/clang/CXCompletionContext.cs index a5558c5b..017094fc 100644 --- a/sources/ClangSharp.Interop/clang/CXCompletionContext.cs +++ b/sources/ClangSharp.Interop/clang/CXCompletionContext.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCompletionResult.cs b/sources/ClangSharp.Interop/clang/CXCompletionResult.cs index a21df104..69772ba2 100644 --- a/sources/ClangSharp.Interop/clang/CXCompletionResult.cs +++ b/sources/ClangSharp.Interop/clang/CXCompletionResult.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCursor.cs b/sources/ClangSharp.Interop/clang/CXCursor.cs index 074538d8..5fcdeecf 100644 --- a/sources/ClangSharp.Interop/clang/CXCursor.cs +++ b/sources/ClangSharp.Interop/clang/CXCursor.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXCursorAndRangeVisitor.cs b/sources/ClangSharp.Interop/clang/CXCursorAndRangeVisitor.cs index 2ac3caff..1efa3078 100644 --- a/sources/ClangSharp.Interop/clang/CXCursorAndRangeVisitor.cs +++ b/sources/ClangSharp.Interop/clang/CXCursorAndRangeVisitor.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXCursorKind.cs b/sources/ClangSharp.Interop/clang/CXCursorKind.cs index 42a586b2..532cf187 100644 --- a/sources/ClangSharp.Interop/clang/CXCursorKind.cs +++ b/sources/ClangSharp.Interop/clang/CXCursorKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; @@ -115,7 +115,7 @@ public enum CXCursorKind CXCursor_LambdaExpr = 144, CXCursor_ObjCBoolLiteralExpr = 145, CXCursor_ObjCSelfExpr = 146, - CXCursor_OMPArraySectionExpr = 147, + CXCursor_ArraySectionExpr = 147, CXCursor_ObjCAvailabilityCheckExpr = 148, CXCursor_FixedPointLiteral = 149, CXCursor_OMPArrayShapingExpr = 150, @@ -124,7 +124,8 @@ public enum CXCursorKind CXCursor_ConceptSpecializationExpr = 153, CXCursor_RequiresExpr = 154, CXCursor_CXXParenListInitExpr = 155, - CXCursor_LastExpr = CXCursor_CXXParenListInitExpr, + CXCursor_PackIndexingExpr = 156, + CXCursor_LastExpr = CXCursor_PackIndexingExpr, CXCursor_FirstStmt = 200, CXCursor_UnexposedStmt = 200, CXCursor_LabelStmt = 201, @@ -234,7 +235,22 @@ public enum CXCursorKind CXCursor_OMPParallelMaskedTaskLoopSimdDirective = 304, CXCursor_OMPErrorDirective = 305, CXCursor_OMPScopeDirective = 306, - CXCursor_LastStmt = CXCursor_OMPScopeDirective, + CXCursor_OMPReverseDirective = 307, + CXCursor_OMPInterchangeDirective = 308, + CXCursor_OMPAssumeDirective = 309, + CXCursor_OpenACCComputeConstruct = 320, + CXCursor_OpenACCLoopConstruct = 321, + CXCursor_OpenACCCombinedConstruct = 322, + CXCursor_OpenACCDataConstruct = 323, + CXCursor_OpenACCEnterDataConstruct = 324, + CXCursor_OpenACCExitDataConstruct = 325, + CXCursor_OpenACCHostDataConstruct = 326, + CXCursor_OpenACCWaitConstruct = 327, + CXCursor_OpenACCInitConstruct = 328, + CXCursor_OpenACCShutdownConstruct = 329, + CXCursor_OpenACCSetConstruct = 330, + CXCursor_OpenACCUpdateConstruct = 331, + CXCursor_LastStmt = CXCursor_OpenACCUpdateConstruct, CXCursor_TranslationUnit = 350, CXCursor_FirstAttr = 400, CXCursor_UnexposedAttr = 400, diff --git a/sources/ClangSharp.Interop/clang/CXCursor_ExceptionSpecificationKind.cs b/sources/ClangSharp.Interop/clang/CXCursor_ExceptionSpecificationKind.cs index 5c1d53fb..aa55f164 100644 --- a/sources/ClangSharp.Interop/clang/CXCursor_ExceptionSpecificationKind.cs +++ b/sources/ClangSharp.Interop/clang/CXCursor_ExceptionSpecificationKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXDiagnosticDisplayOptions.cs b/sources/ClangSharp.Interop/clang/CXDiagnosticDisplayOptions.cs index a1f3752d..c648dcd6 100644 --- a/sources/ClangSharp.Interop/clang/CXDiagnosticDisplayOptions.cs +++ b/sources/ClangSharp.Interop/clang/CXDiagnosticDisplayOptions.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXDiagnosticSeverity.cs b/sources/ClangSharp.Interop/clang/CXDiagnosticSeverity.cs index f580c249..e9249172 100644 --- a/sources/ClangSharp.Interop/clang/CXDiagnosticSeverity.cs +++ b/sources/ClangSharp.Interop/clang/CXDiagnosticSeverity.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXErrorCode.cs b/sources/ClangSharp.Interop/clang/CXErrorCode.cs index 1e4023ae..b0c2c1d9 100644 --- a/sources/ClangSharp.Interop/clang/CXErrorCode.cs +++ b/sources/ClangSharp.Interop/clang/CXErrorCode.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXEvalResultKind.cs b/sources/ClangSharp.Interop/clang/CXEvalResultKind.cs index dc000cfc..0bd792bc 100644 --- a/sources/ClangSharp.Interop/clang/CXEvalResultKind.cs +++ b/sources/ClangSharp.Interop/clang/CXEvalResultKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXFileUniqueID.cs b/sources/ClangSharp.Interop/clang/CXFileUniqueID.cs index 08541baa..5f7d908d 100644 --- a/sources/ClangSharp.Interop/clang/CXFileUniqueID.cs +++ b/sources/ClangSharp.Interop/clang/CXFileUniqueID.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXGlobalOptFlags.cs b/sources/ClangSharp.Interop/clang/CXGlobalOptFlags.cs index ddea536b..46da52be 100644 --- a/sources/ClangSharp.Interop/clang/CXGlobalOptFlags.cs +++ b/sources/ClangSharp.Interop/clang/CXGlobalOptFlags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxAttrInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxAttrInfo.cs index 3def5799..8682ae90 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxAttrInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxAttrInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxAttrKind.cs b/sources/ClangSharp.Interop/clang/CXIdxAttrKind.cs index f461126b..ee79d830 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxAttrKind.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxAttrKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxBaseClassInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxBaseClassInfo.cs index 0dcee248..991c3521 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxBaseClassInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxBaseClassInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxCXXClassDeclInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxCXXClassDeclInfo.cs index b9d7472c..2ef567b2 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxCXXClassDeclInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxCXXClassDeclInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxContainerInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxContainerInfo.cs index 4f7c4f3f..159f66c1 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxContainerInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxContainerInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxDeclInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxDeclInfo.cs index ad8a7b1a..849e7947 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxDeclInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxDeclInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxDeclInfoFlags.cs b/sources/ClangSharp.Interop/clang/CXIdxDeclInfoFlags.cs index 15bcfabc..229a7c9d 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxDeclInfoFlags.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxDeclInfoFlags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxEntityCXXTemplateKind.cs b/sources/ClangSharp.Interop/clang/CXIdxEntityCXXTemplateKind.cs index 9da7c26f..7e622172 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxEntityCXXTemplateKind.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxEntityCXXTemplateKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxEntityInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxEntityInfo.cs index 82304b8b..5f712b9e 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxEntityInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxEntityInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxEntityKind.cs b/sources/ClangSharp.Interop/clang/CXIdxEntityKind.cs index ca3cc6e9..adf4f7cc 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxEntityKind.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxEntityKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxEntityLanguage.cs b/sources/ClangSharp.Interop/clang/CXIdxEntityLanguage.cs index 0fde7af2..123de8ab 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxEntityLanguage.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxEntityLanguage.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxEntityRefInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxEntityRefInfo.cs index d60d98bf..45d0ed79 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxEntityRefInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxEntityRefInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxEntityRefKind.cs b/sources/ClangSharp.Interop/clang/CXIdxEntityRefKind.cs index 3f1daa21..a271f72a 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxEntityRefKind.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxEntityRefKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxIBOutletCollectionAttrInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxIBOutletCollectionAttrInfo.cs index 786daf83..398b6300 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxIBOutletCollectionAttrInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxIBOutletCollectionAttrInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxImportedASTFileInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxImportedASTFileInfo.cs index d0b1ba35..4fc5480d 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxImportedASTFileInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxImportedASTFileInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxIncludedFileInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxIncludedFileInfo.cs index 9de436d2..42f9654e 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxIncludedFileInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxIncludedFileInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxLoc.cs b/sources/ClangSharp.Interop/clang/CXIdxLoc.cs index 2309fc5b..d9194845 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxLoc.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxLoc.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCCategoryDeclInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCCategoryDeclInfo.cs index ed95f7b1..60bae0f4 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCCategoryDeclInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCCategoryDeclInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCContainerDeclInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCContainerDeclInfo.cs index 580e5caa..6f2fea81 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCContainerDeclInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCContainerDeclInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCContainerKind.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCContainerKind.cs index d92df8f7..2260185d 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCContainerKind.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCContainerKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCInterfaceDeclInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCInterfaceDeclInfo.cs index 61b95173..9eecef17 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCInterfaceDeclInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCInterfaceDeclInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCPropertyDeclInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCPropertyDeclInfo.cs index 65edc889..0591027a 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCPropertyDeclInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCPropertyDeclInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefInfo.cs index e8ca74cd..c3a90497 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefListInfo.cs b/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefListInfo.cs index cb02880d..9270b920 100644 --- a/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefListInfo.cs +++ b/sources/ClangSharp.Interop/clang/CXIdxObjCProtocolRefListInfo.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIndexOptFlags.cs b/sources/ClangSharp.Interop/clang/CXIndexOptFlags.cs index 3c2dd327..b4e41413 100644 --- a/sources/ClangSharp.Interop/clang/CXIndexOptFlags.cs +++ b/sources/ClangSharp.Interop/clang/CXIndexOptFlags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXIndexOptions.cs b/sources/ClangSharp.Interop/clang/CXIndexOptions.cs index 859e06c8..48f1d577 100644 --- a/sources/ClangSharp.Interop/clang/CXIndexOptions.cs +++ b/sources/ClangSharp.Interop/clang/CXIndexOptions.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXLanguageKind.cs b/sources/ClangSharp.Interop/clang/CXLanguageKind.cs index 790fd346..b27a35c0 100644 --- a/sources/ClangSharp.Interop/clang/CXLanguageKind.cs +++ b/sources/ClangSharp.Interop/clang/CXLanguageKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXLinkageKind.cs b/sources/ClangSharp.Interop/clang/CXLinkageKind.cs index cbb05f8f..21dad4ee 100644 --- a/sources/ClangSharp.Interop/clang/CXLinkageKind.cs +++ b/sources/ClangSharp.Interop/clang/CXLinkageKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXLoadDiag_Error.cs b/sources/ClangSharp.Interop/clang/CXLoadDiag_Error.cs index f142982b..e9500782 100644 --- a/sources/ClangSharp.Interop/clang/CXLoadDiag_Error.cs +++ b/sources/ClangSharp.Interop/clang/CXLoadDiag_Error.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXNameRefFlags.cs b/sources/ClangSharp.Interop/clang/CXNameRefFlags.cs index b6293159..c7b3479b 100644 --- a/sources/ClangSharp.Interop/clang/CXNameRefFlags.cs +++ b/sources/ClangSharp.Interop/clang/CXNameRefFlags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXObjCDeclQualifierKind.cs b/sources/ClangSharp.Interop/clang/CXObjCDeclQualifierKind.cs index ff264cc8..468a4755 100644 --- a/sources/ClangSharp.Interop/clang/CXObjCDeclQualifierKind.cs +++ b/sources/ClangSharp.Interop/clang/CXObjCDeclQualifierKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXObjCPropertyAttrKind.cs b/sources/ClangSharp.Interop/clang/CXObjCPropertyAttrKind.cs index 0ec758d4..b75706da 100644 --- a/sources/ClangSharp.Interop/clang/CXObjCPropertyAttrKind.cs +++ b/sources/ClangSharp.Interop/clang/CXObjCPropertyAttrKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXPlatformAvailability.cs b/sources/ClangSharp.Interop/clang/CXPlatformAvailability.cs index 2f39fd87..3061a5d4 100644 --- a/sources/ClangSharp.Interop/clang/CXPlatformAvailability.cs +++ b/sources/ClangSharp.Interop/clang/CXPlatformAvailability.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXPrintingPolicyProperty.cs b/sources/ClangSharp.Interop/clang/CXPrintingPolicyProperty.cs index d983f321..af01b92a 100644 --- a/sources/ClangSharp.Interop/clang/CXPrintingPolicyProperty.cs +++ b/sources/ClangSharp.Interop/clang/CXPrintingPolicyProperty.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXRefQualifierKind.cs b/sources/ClangSharp.Interop/clang/CXRefQualifierKind.cs index ffa81942..e9a684bd 100644 --- a/sources/ClangSharp.Interop/clang/CXRefQualifierKind.cs +++ b/sources/ClangSharp.Interop/clang/CXRefQualifierKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXReparse_Flags.cs b/sources/ClangSharp.Interop/clang/CXReparse_Flags.cs index bfcad337..4f063c26 100644 --- a/sources/ClangSharp.Interop/clang/CXReparse_Flags.cs +++ b/sources/ClangSharp.Interop/clang/CXReparse_Flags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXResult.cs b/sources/ClangSharp.Interop/clang/CXResult.cs index 0806c12f..b5fc88ef 100644 --- a/sources/ClangSharp.Interop/clang/CXResult.cs +++ b/sources/ClangSharp.Interop/clang/CXResult.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXSaveError.cs b/sources/ClangSharp.Interop/clang/CXSaveError.cs index 553d709a..12a8b2f6 100644 --- a/sources/ClangSharp.Interop/clang/CXSaveError.cs +++ b/sources/ClangSharp.Interop/clang/CXSaveError.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXSaveTranslationUnit_Flags.cs b/sources/ClangSharp.Interop/clang/CXSaveTranslationUnit_Flags.cs index 07bdc501..d4b398f6 100644 --- a/sources/ClangSharp.Interop/clang/CXSaveTranslationUnit_Flags.cs +++ b/sources/ClangSharp.Interop/clang/CXSaveTranslationUnit_Flags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXSourceLocation.cs b/sources/ClangSharp.Interop/clang/CXSourceLocation.cs index 2f613f31..3134152c 100644 --- a/sources/ClangSharp.Interop/clang/CXSourceLocation.cs +++ b/sources/ClangSharp.Interop/clang/CXSourceLocation.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXSourceRange.cs b/sources/ClangSharp.Interop/clang/CXSourceRange.cs index fcdb87c3..09124d32 100644 --- a/sources/ClangSharp.Interop/clang/CXSourceRange.cs +++ b/sources/ClangSharp.Interop/clang/CXSourceRange.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXSourceRangeList.cs b/sources/ClangSharp.Interop/clang/CXSourceRangeList.cs index 991b2a33..015691cf 100644 --- a/sources/ClangSharp.Interop/clang/CXSourceRangeList.cs +++ b/sources/ClangSharp.Interop/clang/CXSourceRangeList.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXString.cs b/sources/ClangSharp.Interop/clang/CXString.cs index 3b871724..63ba5c14 100644 --- a/sources/ClangSharp.Interop/clang/CXString.cs +++ b/sources/ClangSharp.Interop/clang/CXString.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXStringSet.cs b/sources/ClangSharp.Interop/clang/CXStringSet.cs index edaa94d0..64d8e53d 100644 --- a/sources/ClangSharp.Interop/clang/CXStringSet.cs +++ b/sources/ClangSharp.Interop/clang/CXStringSet.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXSymbolRole.cs b/sources/ClangSharp.Interop/clang/CXSymbolRole.cs index c9acc0e8..b96c7040 100644 --- a/sources/ClangSharp.Interop/clang/CXSymbolRole.cs +++ b/sources/ClangSharp.Interop/clang/CXSymbolRole.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTLSKind.cs b/sources/ClangSharp.Interop/clang/CXTLSKind.cs index 81aa2fda..e0e678a2 100644 --- a/sources/ClangSharp.Interop/clang/CXTLSKind.cs +++ b/sources/ClangSharp.Interop/clang/CXTLSKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTUResourceUsage.cs b/sources/ClangSharp.Interop/clang/CXTUResourceUsage.cs index f0a74664..e929e89f 100644 --- a/sources/ClangSharp.Interop/clang/CXTUResourceUsage.cs +++ b/sources/ClangSharp.Interop/clang/CXTUResourceUsage.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTUResourceUsageEntry.cs b/sources/ClangSharp.Interop/clang/CXTUResourceUsageEntry.cs index fb2fc8ec..958967e7 100644 --- a/sources/ClangSharp.Interop/clang/CXTUResourceUsageEntry.cs +++ b/sources/ClangSharp.Interop/clang/CXTUResourceUsageEntry.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTUResourceUsageKind.cs b/sources/ClangSharp.Interop/clang/CXTUResourceUsageKind.cs index 423bfe71..f19fadf7 100644 --- a/sources/ClangSharp.Interop/clang/CXTUResourceUsageKind.cs +++ b/sources/ClangSharp.Interop/clang/CXTUResourceUsageKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTemplateArgumentKind.cs b/sources/ClangSharp.Interop/clang/CXTemplateArgumentKind.cs index 1375e56b..0fc7cb36 100644 --- a/sources/ClangSharp.Interop/clang/CXTemplateArgumentKind.cs +++ b/sources/ClangSharp.Interop/clang/CXTemplateArgumentKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXToken.cs b/sources/ClangSharp.Interop/clang/CXToken.cs index c7729f34..3a1da283 100644 --- a/sources/ClangSharp.Interop/clang/CXToken.cs +++ b/sources/ClangSharp.Interop/clang/CXToken.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXTokenKind.cs b/sources/ClangSharp.Interop/clang/CXTokenKind.cs index 48170e30..1d9ae19c 100644 --- a/sources/ClangSharp.Interop/clang/CXTokenKind.cs +++ b/sources/ClangSharp.Interop/clang/CXTokenKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTranslationUnit_Flags.cs b/sources/ClangSharp.Interop/clang/CXTranslationUnit_Flags.cs index 57ec6324..33ddd3c6 100644 --- a/sources/ClangSharp.Interop/clang/CXTranslationUnit_Flags.cs +++ b/sources/ClangSharp.Interop/clang/CXTranslationUnit_Flags.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXType.cs b/sources/ClangSharp.Interop/clang/CXType.cs index ba107bfd..447288d8 100644 --- a/sources/ClangSharp.Interop/clang/CXType.cs +++ b/sources/ClangSharp.Interop/clang/CXType.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/sources/ClangSharp.Interop/clang/CXTypeKind.cs b/sources/ClangSharp.Interop/clang/CXTypeKind.cs index ce97a87a..710c1c7c 100644 --- a/sources/ClangSharp.Interop/clang/CXTypeKind.cs +++ b/sources/ClangSharp.Interop/clang/CXTypeKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; @@ -133,4 +133,6 @@ public enum CXTypeKind CXType_ExtVector = 176, CXType_Atomic = 177, CXType_BTFTagAttributed = 178, + CXType_HLSLResource = 179, + CXType_HLSLAttributedResource = 180, } diff --git a/sources/ClangSharp.Interop/clang/CXTypeLayoutError.cs b/sources/ClangSharp.Interop/clang/CXTypeLayoutError.cs index 963e824b..13e9ef80 100644 --- a/sources/ClangSharp.Interop/clang/CXTypeLayoutError.cs +++ b/sources/ClangSharp.Interop/clang/CXTypeLayoutError.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXTypeNullabilityKind.cs b/sources/ClangSharp.Interop/clang/CXTypeNullabilityKind.cs index 58f5075b..b181dd1c 100644 --- a/sources/ClangSharp.Interop/clang/CXTypeNullabilityKind.cs +++ b/sources/ClangSharp.Interop/clang/CXTypeNullabilityKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXUnaryOperatorKind.cs b/sources/ClangSharp.Interop/clang/CXUnaryOperatorKind.cs index e4abc5eb..51ee1741 100644 --- a/sources/ClangSharp.Interop/clang/CXUnaryOperatorKind.cs +++ b/sources/ClangSharp.Interop/clang/CXUnaryOperatorKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXUnsavedFile.cs b/sources/ClangSharp.Interop/clang/CXUnsavedFile.cs index a4c5130e..f32048da 100644 --- a/sources/ClangSharp.Interop/clang/CXUnsavedFile.cs +++ b/sources/ClangSharp.Interop/clang/CXUnsavedFile.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXVersion.cs b/sources/ClangSharp.Interop/clang/CXVersion.cs index c04fefd2..88cf9ede 100644 --- a/sources/ClangSharp.Interop/clang/CXVersion.cs +++ b/sources/ClangSharp.Interop/clang/CXVersion.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXVisibilityKind.cs b/sources/ClangSharp.Interop/clang/CXVisibilityKind.cs index 9901eba3..b49c89d4 100644 --- a/sources/ClangSharp.Interop/clang/CXVisibilityKind.cs +++ b/sources/ClangSharp.Interop/clang/CXVisibilityKind.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CXVisitorResult.cs b/sources/ClangSharp.Interop/clang/CXVisitorResult.cs index 0af560b7..5abbdcc5 100644 --- a/sources/ClangSharp.Interop/clang/CXVisitorResult.cs +++ b/sources/ClangSharp.Interop/clang/CXVisitorResult.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CX_BinaryOperatorKind.cs b/sources/ClangSharp.Interop/clang/CX_BinaryOperatorKind.cs new file mode 100644 index 00000000..650102f0 --- /dev/null +++ b/sources/ClangSharp.Interop/clang/CX_BinaryOperatorKind.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c +// Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. + +namespace ClangSharp.Interop; + +public enum CX_BinaryOperatorKind +{ + CX_BO_Invalid = 0, + CX_BO_PtrMemD = 1, + CX_BO_PtrMemI = 2, + CX_BO_Mul = 3, + CX_BO_Div = 4, + CX_BO_Rem = 5, + CX_BO_Add = 6, + CX_BO_Sub = 7, + CX_BO_Shl = 8, + CX_BO_Shr = 9, + CX_BO_Cmp = 10, + CX_BO_LT = 11, + CX_BO_GT = 12, + CX_BO_LE = 13, + CX_BO_GE = 14, + CX_BO_EQ = 15, + CX_BO_NE = 16, + CX_BO_And = 17, + CX_BO_Xor = 18, + CX_BO_Or = 19, + CX_BO_LAnd = 20, + CX_BO_LOr = 21, + CX_BO_Assign = 22, + CX_BO_MulAssign = 23, + CX_BO_DivAssign = 24, + CX_BO_RemAssign = 25, + CX_BO_AddAssign = 26, + CX_BO_SubAssign = 27, + CX_BO_ShlAssign = 28, + CX_BO_ShrAssign = 29, + CX_BO_AndAssign = 30, + CX_BO_XorAssign = 31, + CX_BO_OrAssign = 32, + CX_BO_Comma = 33, + CX_BO_LAST = CX_BO_Comma, +} diff --git a/sources/ClangSharp.Interop/clang/CX_CXXAccessSpecifier.cs b/sources/ClangSharp.Interop/clang/CX_CXXAccessSpecifier.cs index 104284df..861e0eaf 100644 --- a/sources/ClangSharp.Interop/clang/CX_CXXAccessSpecifier.cs +++ b/sources/ClangSharp.Interop/clang/CX_CXXAccessSpecifier.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/CX_StorageClass.cs b/sources/ClangSharp.Interop/clang/CX_StorageClass.cs index 53854116..fd9388d0 100644 --- a/sources/ClangSharp.Interop/clang/CX_StorageClass.cs +++ b/sources/ClangSharp.Interop/clang/CX_StorageClass.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/IndexerCallbacks.cs b/sources/ClangSharp.Interop/clang/IndexerCallbacks.cs index 9c461643..84600c29 100644 --- a/sources/ClangSharp.Interop/clang/IndexerCallbacks.cs +++ b/sources/ClangSharp.Interop/clang/IndexerCallbacks.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. namespace ClangSharp.Interop; diff --git a/sources/ClangSharp.Interop/clang/clang.cs b/sources/ClangSharp.Interop/clang/clang.cs index 5d1d1abb..66a93eaf 100644 --- a/sources/ClangSharp.Interop/clang/clang.cs +++ b/sources/ClangSharp.Interop/clang/clang.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. using System; @@ -194,6 +194,10 @@ public static unsafe partial class @clang [return: NativeTypeName("unsigned int")] public static extern uint equalLocations(CXSourceLocation loc1, CXSourceLocation loc2); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_isBeforeInTranslationUnit", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint isBeforeInTranslationUnit(CXSourceLocation loc1, CXSourceLocation loc2); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_Location_isInSystemHeader", ExactSpelling = true)] public static extern int Location_isInSystemHeader(CXSourceLocation location); @@ -893,10 +897,21 @@ public static unsafe partial class @clang [return: NativeTypeName("unsigned int")] public static extern uint isVirtualBase(CXCursor param0); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_getOffsetOfBase", ExactSpelling = true)] + [return: NativeTypeName("long long")] + public static extern long getOffsetOfBase(CXCursor Parent, CXCursor Base); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_getCXXAccessSpecifier", ExactSpelling = true)] [return: NativeTypeName("enum CX_CXXAccessSpecifier")] public static extern CX_CXXAccessSpecifier getCXXAccessSpecifier(CXCursor param0); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_Cursor_getBinaryOpcode", ExactSpelling = true)] + [return: NativeTypeName("enum CX_BinaryOperatorKind")] + public static extern CX_BinaryOperatorKind Cursor_getBinaryOpcode(CXCursor C); + + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_Cursor_getBinaryOpcodeStr", ExactSpelling = true)] + public static extern CXString Cursor_getBinaryOpcodeStr([NativeTypeName("enum CX_BinaryOperatorKind")] CX_BinaryOperatorKind Op); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_Cursor_getStorageClass", ExactSpelling = true)] [return: NativeTypeName("enum CX_StorageClass")] public static extern CX_StorageClass Cursor_getStorageClass(CXCursor param0); @@ -963,6 +978,9 @@ public static unsafe partial class @clang [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_getCursorPrettyPrinted", ExactSpelling = true)] public static extern CXString getCursorPrettyPrinted(CXCursor Cursor, [NativeTypeName("CXPrintingPolicy")] void* Policy); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_getTypePrettyPrinted", ExactSpelling = true)] + public static extern CXString getTypePrettyPrinted(CXType CT, [NativeTypeName("CXPrintingPolicy")] void* cxPolicy); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_getCursorDisplayName", ExactSpelling = true)] public static extern CXString getCursorDisplayName(CXCursor param0); @@ -1399,6 +1417,10 @@ public static unsafe partial class @clang [return: NativeTypeName("unsigned int")] public static extern uint Type_visitFields(CXType T, [NativeTypeName("CXFieldVisitor")] delegate* unmanaged[Cdecl] visitor, [NativeTypeName("CXClientData")] void* client_data); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_visitCXXBaseClasses", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint visitCXXBaseClasses(CXType T, [NativeTypeName("CXFieldVisitor")] delegate* unmanaged[Cdecl] visitor, [NativeTypeName("CXClientData")] void* client_data); + [DllImport("libclang", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clang_getBinaryOperatorKindSpelling", ExactSpelling = true)] public static extern CXString getBinaryOperatorKindSpelling([NativeTypeName("enum CXBinaryOperatorKind")] CXBinaryOperatorKind kind); diff --git a/sources/ClangSharp.Interop/clangsharp/CX_AtomicOperatorKind.cs b/sources/ClangSharp.Interop/clangsharp/CX_AtomicOperatorKind.cs index 8afe0084..94781f63 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_AtomicOperatorKind.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_AtomicOperatorKind.cs @@ -6,91 +6,93 @@ namespace ClangSharp.Interop; public enum CX_AtomicOperatorKind { CX_AO_Invalid, - CX_AO__c11_atomic_init, - CX_AO__c11_atomic_load, - CX_AO__c11_atomic_store, - CX_AO__c11_atomic_exchange, - CX_AO__c11_atomic_compare_exchange_strong, - CX_AO__c11_atomic_compare_exchange_weak, - CX_AO__c11_atomic_fetch_add, - CX_AO__c11_atomic_fetch_sub, - CX_AO__c11_atomic_fetch_and, - CX_AO__c11_atomic_fetch_or, - CX_AO__c11_atomic_fetch_xor, - CX_AO__c11_atomic_fetch_nand, - CX_AO__c11_atomic_fetch_max, - CX_AO__c11_atomic_fetch_min, - CX_AO__atomic_load, - CX_AO__atomic_load_n, - CX_AO__atomic_store, - CX_AO__atomic_store_n, - CX_AO__atomic_exchange, - CX_AO__atomic_exchange_n, + CX_AO__atomic_add_fetch, + CX_AO__atomic_and_fetch, + CX_AO__atomic_clear, CX_AO__atomic_compare_exchange, CX_AO__atomic_compare_exchange_n, + CX_AO__atomic_exchange, + CX_AO__atomic_exchange_n, CX_AO__atomic_fetch_add, - CX_AO__atomic_fetch_sub, CX_AO__atomic_fetch_and, + CX_AO__atomic_fetch_max, + CX_AO__atomic_fetch_min, + CX_AO__atomic_fetch_nand, CX_AO__atomic_fetch_or, + CX_AO__atomic_fetch_sub, CX_AO__atomic_fetch_xor, - CX_AO__atomic_fetch_nand, - CX_AO__atomic_add_fetch, - CX_AO__atomic_sub_fetch, - CX_AO__atomic_and_fetch, - CX_AO__atomic_or_fetch, - CX_AO__atomic_xor_fetch, + CX_AO__atomic_load, + CX_AO__atomic_load_n, CX_AO__atomic_max_fetch, CX_AO__atomic_min_fetch, CX_AO__atomic_nand_fetch, - CX_AO__scoped_atomic_load, - CX_AO__scoped_atomic_load_n, - CX_AO__scoped_atomic_store, - CX_AO__scoped_atomic_store_n, - CX_AO__scoped_atomic_exchange, - CX_AO__scoped_atomic_exchange_n, + CX_AO__atomic_or_fetch, + CX_AO__atomic_store, + CX_AO__atomic_store_n, + CX_AO__atomic_sub_fetch, + CX_AO__atomic_test_and_set, + CX_AO__atomic_xor_fetch, + CX_AO__c11_atomic_compare_exchange_strong, + CX_AO__c11_atomic_compare_exchange_weak, + CX_AO__c11_atomic_exchange, + CX_AO__c11_atomic_fetch_add, + CX_AO__c11_atomic_fetch_and, + CX_AO__c11_atomic_fetch_max, + CX_AO__c11_atomic_fetch_min, + CX_AO__c11_atomic_fetch_nand, + CX_AO__c11_atomic_fetch_or, + CX_AO__c11_atomic_fetch_sub, + CX_AO__c11_atomic_fetch_xor, + CX_AO__c11_atomic_init, + CX_AO__c11_atomic_load, + CX_AO__c11_atomic_store, + CX_AO__hip_atomic_compare_exchange_strong, + CX_AO__hip_atomic_compare_exchange_weak, + CX_AO__hip_atomic_exchange, + CX_AO__hip_atomic_fetch_add, + CX_AO__hip_atomic_fetch_and, + CX_AO__hip_atomic_fetch_max, + CX_AO__hip_atomic_fetch_min, + CX_AO__hip_atomic_fetch_or, + CX_AO__hip_atomic_fetch_sub, + CX_AO__hip_atomic_fetch_xor, + CX_AO__hip_atomic_load, + CX_AO__hip_atomic_store, + CX_AO__opencl_atomic_compare_exchange_strong, + CX_AO__opencl_atomic_compare_exchange_weak, + CX_AO__opencl_atomic_exchange, + CX_AO__opencl_atomic_fetch_add, + CX_AO__opencl_atomic_fetch_and, + CX_AO__opencl_atomic_fetch_max, + CX_AO__opencl_atomic_fetch_min, + CX_AO__opencl_atomic_fetch_or, + CX_AO__opencl_atomic_fetch_sub, + CX_AO__opencl_atomic_fetch_xor, + CX_AO__opencl_atomic_init, + CX_AO__opencl_atomic_load, + CX_AO__opencl_atomic_store, + CX_AO__scoped_atomic_add_fetch, + CX_AO__scoped_atomic_and_fetch, CX_AO__scoped_atomic_compare_exchange, CX_AO__scoped_atomic_compare_exchange_n, + CX_AO__scoped_atomic_exchange, + CX_AO__scoped_atomic_exchange_n, CX_AO__scoped_atomic_fetch_add, - CX_AO__scoped_atomic_fetch_sub, CX_AO__scoped_atomic_fetch_and, + CX_AO__scoped_atomic_fetch_max, + CX_AO__scoped_atomic_fetch_min, + CX_AO__scoped_atomic_fetch_nand, CX_AO__scoped_atomic_fetch_or, + CX_AO__scoped_atomic_fetch_sub, CX_AO__scoped_atomic_fetch_xor, - CX_AO__scoped_atomic_fetch_nand, - CX_AO__scoped_atomic_add_fetch, - CX_AO__scoped_atomic_sub_fetch, - CX_AO__scoped_atomic_and_fetch, - CX_AO__scoped_atomic_or_fetch, - CX_AO__scoped_atomic_xor_fetch, + CX_AO__scoped_atomic_load, + CX_AO__scoped_atomic_load_n, CX_AO__scoped_atomic_max_fetch, CX_AO__scoped_atomic_min_fetch, CX_AO__scoped_atomic_nand_fetch, - CX_AO__scoped_atomic_fetch_min, - CX_AO__scoped_atomic_fetch_max, - CX_AO__opencl_atomic_init, - CX_AO__opencl_atomic_load, - CX_AO__opencl_atomic_store, - CX_AO__opencl_atomic_exchange, - CX_AO__opencl_atomic_compare_exchange_strong, - CX_AO__opencl_atomic_compare_exchange_weak, - CX_AO__opencl_atomic_fetch_add, - CX_AO__opencl_atomic_fetch_sub, - CX_AO__opencl_atomic_fetch_and, - CX_AO__opencl_atomic_fetch_or, - CX_AO__opencl_atomic_fetch_xor, - CX_AO__opencl_atomic_fetch_min, - CX_AO__opencl_atomic_fetch_max, - CX_AO__atomic_fetch_min, - CX_AO__atomic_fetch_max, - CX_AO__hip_atomic_load, - CX_AO__hip_atomic_store, - CX_AO__hip_atomic_compare_exchange_weak, - CX_AO__hip_atomic_compare_exchange_strong, - CX_AO__hip_atomic_exchange, - CX_AO__hip_atomic_fetch_add, - CX_AO__hip_atomic_fetch_sub, - CX_AO__hip_atomic_fetch_and, - CX_AO__hip_atomic_fetch_or, - CX_AO__hip_atomic_fetch_xor, - CX_AO__hip_atomic_fetch_min, - CX_AO__hip_atomic_fetch_max, + CX_AO__scoped_atomic_or_fetch, + CX_AO__scoped_atomic_store, + CX_AO__scoped_atomic_store_n, + CX_AO__scoped_atomic_sub_fetch, + CX_AO__scoped_atomic_xor_fetch, } diff --git a/sources/ClangSharp.Interop/clangsharp/CX_AttrKind.cs b/sources/ClangSharp.Interop/clangsharp/CX_AttrKind.cs index 5468ac8e..a42e0ce2 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_AttrKind.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_AttrKind.cs @@ -7,7 +7,9 @@ public enum CX_AttrKind { CX_AttrKind_Invalid, CX_AttrKind_AddressSpace, + CX_AttrKind_Allocating, CX_AttrKind_AnnotateType, + CX_AttrKind_ArmAgnostic, CX_AttrKind_ArmIn, CX_AttrKind_ArmInOut, CX_AttrKind_ArmMveStrictPolymorphism, @@ -16,10 +18,16 @@ public enum CX_AttrKind CX_AttrKind_ArmStreaming, CX_AttrKind_ArmStreamingCompatible, CX_AttrKind_BTFTypeTag, + CX_AttrKind_Blocking, CX_AttrKind_CmseNSCall, + CX_AttrKind_HLSLContainedType, CX_AttrKind_HLSLGroupSharedAddressSpace, - CX_AttrKind_HLSLParamModifier, + CX_AttrKind_HLSLROV, + CX_AttrKind_HLSLRawBuffer, + CX_AttrKind_HLSLResourceClass, CX_AttrKind_NoDeref, + CX_AttrKind_NonAllocating, + CX_AttrKind_NonBlocking, CX_AttrKind_ObjCGC, CX_AttrKind_ObjCInertUnsafeUnretained, CX_AttrKind_ObjCKindOf, @@ -35,12 +43,14 @@ public enum CX_AttrKind CX_AttrKind_SPtr, CX_AttrKind_TypeNonNull, CX_AttrKind_TypeNullUnspecified, - CX_AttrKind_TypeNullable, CX_AttrKind_TypeNullableResult, CX_AttrKind_UPtr, CX_AttrKind_WebAssemblyFuncref, + CX_AttrKind_CXXAssume, CX_AttrKind_CodeAlign, CX_AttrKind_FallThrough, + CX_AttrKind_HLSLControlFlowHint, + CX_AttrKind_HLSLLoopHint, CX_AttrKind_Likely, CX_AttrKind_MustTail, CX_AttrKind_OpenCLUnrollHint, @@ -55,9 +65,12 @@ public enum CX_AttrKind CX_AttrKind_AcquireHandle, CX_AttrKind_AnyX86NoCfCheck, CX_AttrKind_CDecl, + CX_AttrKind_CountedBy, + CX_AttrKind_CountedByOrNull, CX_AttrKind_FastCall, CX_AttrKind_IntelOclBicc, CX_AttrKind_LifetimeBound, + CX_AttrKind_LifetimeCaptureBy, CX_AttrKind_M68kRTD, CX_AttrKind_MSABI, CX_AttrKind_NSReturnsRetained, @@ -66,18 +79,25 @@ public enum CX_AttrKind CX_AttrKind_Pcs, CX_AttrKind_PreserveAll, CX_AttrKind_PreserveMost, + CX_AttrKind_PreserveNone, + CX_AttrKind_RISCVVectorCC, CX_AttrKind_RegCall, + CX_AttrKind_SizedBy, + CX_AttrKind_SizedByOrNull, CX_AttrKind_StdCall, CX_AttrKind_SwiftAsyncCall, + CX_AttrKind_SwiftAttr, CX_AttrKind_SwiftCall, CX_AttrKind_SysVABI, CX_AttrKind_ThisCall, + CX_AttrKind_TypeNullable, CX_AttrKind_VectorCall, + CX_AttrKind_Annotate, + CX_AttrKind_HLSLParamModifier, CX_AttrKind_SwiftAsyncContext, CX_AttrKind_SwiftContext, CX_AttrKind_SwiftErrorResult, CX_AttrKind_SwiftIndirectResult, - CX_AttrKind_Annotate, CX_AttrKind_CFConsumed, CX_AttrKind_CarriesDependency, CX_AttrKind_NSConsumed, @@ -86,9 +106,13 @@ public enum CX_AttrKind CX_AttrKind_PassObjectSize, CX_AttrKind_ReleaseHandle, CX_AttrKind_UseHandle, + CX_AttrKind_HLSLPackOffset, CX_AttrKind_HLSLSV_DispatchThreadID, + CX_AttrKind_HLSLSV_GroupID, CX_AttrKind_HLSLSV_GroupIndex, + CX_AttrKind_HLSLSV_GroupThreadID, CX_AttrKind_AMDGPUFlatWorkGroupSize, + CX_AttrKind_AMDGPUMaxNumWorkGroups, CX_AttrKind_AMDGPUNumSGPR, CX_AttrKind_AMDGPUNumVGPR, CX_AttrKind_AMDGPUWavesPerEU, @@ -118,9 +142,9 @@ public enum CX_AttrKind CX_AttrKind_AssertExclusiveLock, CX_AttrKind_AssertSharedLock, CX_AttrKind_AssumeAligned, - CX_AttrKind_Assumption, CX_AttrKind_Availability, CX_AttrKind_AvailableOnlyInDefaultEvalMethod, + CX_AttrKind_BPFFastCall, CX_AttrKind_BPFPreserveAccessIndex, CX_AttrKind_BPFPreserveStaticOffset, CX_AttrKind_BTFDeclTag, @@ -140,6 +164,7 @@ public enum CX_AttrKind CX_AttrKind_CUDADeviceBuiltinSurfaceType, CX_AttrKind_CUDADeviceBuiltinTextureType, CX_AttrKind_CUDAGlobal, + CX_AttrKind_CUDAGridConstant, CX_AttrKind_CUDAHost, CX_AttrKind_CUDAInvalidTarget, CX_AttrKind_CUDALaunchBounds, @@ -150,6 +175,7 @@ public enum CX_AttrKind CX_AttrKind_Capability, CX_AttrKind_CapturedRecord, CX_AttrKind_Cleanup, + CX_AttrKind_ClspvLibclcBuiltin, CX_AttrKind_CmseNSEntry, CX_AttrKind_CodeModel, CX_AttrKind_CodeSeg, @@ -162,12 +188,13 @@ public enum CX_AttrKind CX_AttrKind_ConsumableAutoCast, CX_AttrKind_ConsumableSetOnRead, CX_AttrKind_Convergent, + CX_AttrKind_CoroAwaitElidable, + CX_AttrKind_CoroAwaitElidableArgument, CX_AttrKind_CoroDisableLifetimeBound, CX_AttrKind_CoroLifetimeBound, CX_AttrKind_CoroOnlyDestroyWhenComplete, CX_AttrKind_CoroReturnType, CX_AttrKind_CoroWrapper, - CX_AttrKind_CountedBy, CX_AttrKind_DLLExport, CX_AttrKind_DLLExportStaticLocal, CX_AttrKind_DLLImport, @@ -186,6 +213,7 @@ public enum CX_AttrKind CX_AttrKind_Error, CX_AttrKind_ExcludeFromExplicitInstantiation, CX_AttrKind_ExclusiveTrylockFunction, + CX_AttrKind_ExplicitInit, CX_AttrKind_ExternalSourceSymbol, CX_AttrKind_Final, CX_AttrKind_FlagEnum, @@ -201,7 +229,9 @@ public enum CX_AttrKind CX_AttrKind_HLSLResource, CX_AttrKind_HLSLResourceBinding, CX_AttrKind_HLSLShader, + CX_AttrKind_HLSLWaveSize, CX_AttrKind_Hot, + CX_AttrKind_HybridPatchable, CX_AttrKind_IBAction, CX_AttrKind_IBOutlet, CX_AttrKind_IBOutletCollection, @@ -239,6 +269,7 @@ public enum CX_AttrKind CX_AttrKind_Naked, CX_AttrKind_NoAlias, CX_AttrKind_NoCommon, + CX_AttrKind_NoConvergent, CX_AttrKind_NoDebug, CX_AttrKind_NoDestroy, CX_AttrKind_NoDuplicate, @@ -249,15 +280,18 @@ public enum CX_AttrKind CX_AttrKind_NoRandomizeLayout, CX_AttrKind_NoReturn, CX_AttrKind_NoSanitize, + CX_AttrKind_NoSpecializations, CX_AttrKind_NoSpeculativeLoadHardening, CX_AttrKind_NoSplitStack, CX_AttrKind_NoStackProtector, CX_AttrKind_NoThreadSafetyAnalysis, CX_AttrKind_NoThrow, + CX_AttrKind_NoTrivialAutoVarInit, CX_AttrKind_NoUniqueAddress, CX_AttrKind_NoUwtable, CX_AttrKind_NotTailCalled, CX_AttrKind_OMPAllocateDecl, + CX_AttrKind_OMPAssume, CX_AttrKind_OMPCaptureNoInit, CX_AttrKind_OMPDeclareTargetDecl, CX_AttrKind_OMPDeclareVariant, @@ -315,6 +349,7 @@ public enum CX_AttrKind CX_AttrKind_ReturnsNonNull, CX_AttrKind_ReturnsTwice, CX_AttrKind_SYCLKernel, + CX_AttrKind_SYCLKernelEntryPoint, CX_AttrKind_SYCLSpecialClass, CX_AttrKind_ScopedLockable, CX_AttrKind_Section, @@ -329,7 +364,6 @@ public enum CX_AttrKind CX_AttrKind_SwiftAsync, CX_AttrKind_SwiftAsyncError, CX_AttrKind_SwiftAsyncName, - CX_AttrKind_SwiftAttr, CX_AttrKind_SwiftBridge, CX_AttrKind_SwiftBridgedTypedef, CX_AttrKind_SwiftError, @@ -355,6 +389,7 @@ public enum CX_AttrKind CX_AttrKind_Used, CX_AttrKind_UsingIfExists, CX_AttrKind_Uuid, + CX_AttrKind_VTablePointerAuthentication, CX_AttrKind_VecReturn, CX_AttrKind_VecTypeHint, CX_AttrKind_Visibility, @@ -397,7 +432,6 @@ public enum CX_AttrKind CX_AttrKind_ObjCRuntimeVisible, CX_AttrKind_OpenCLAccess, CX_AttrKind_Overloadable, - CX_AttrKind_RenderScriptKernel, CX_AttrKind_SwiftObjCMembers, CX_AttrKind_SwiftVersionedAddition, CX_AttrKind_SwiftVersionedRemoval, @@ -406,7 +440,7 @@ public enum CX_AttrKind CX_AttrKind_LastAttr = CX_AttrKind_Thread, CX_AttrKind_FirstTypeAttr = CX_AttrKind_AddressSpace, CX_AttrKind_LastTypeAttr = CX_AttrKind_WebAssemblyFuncref, - CX_AttrKind_FirstStmtAttr = CX_AttrKind_CodeAlign, + CX_AttrKind_FirstStmtAttr = CX_AttrKind_CXXAssume, CX_AttrKind_LastStmtAttr = CX_AttrKind_Unlikely, CX_AttrKind_FirstDeclOrStmtAttr = CX_AttrKind_AlwaysInline, CX_AttrKind_LastDeclOrStmtAttr = CX_AttrKind_Suppress, @@ -414,10 +448,12 @@ public enum CX_AttrKind CX_AttrKind_LastInheritableAttr = CX_AttrKind_ZeroCallUsedRegs, CX_AttrKind_FirstDeclOrTypeAttr = CX_AttrKind_AArch64SVEPcs, CX_AttrKind_LastDeclOrTypeAttr = CX_AttrKind_VectorCall, - CX_AttrKind_FirstInheritableParamAttr = CX_AttrKind_SwiftAsyncContext, + CX_AttrKind_FirstInheritableParamAttr = CX_AttrKind_Annotate, CX_AttrKind_LastInheritableParamAttr = CX_AttrKind_UseHandle, - CX_AttrKind_FirstParameterABIAttr = CX_AttrKind_SwiftAsyncContext, + CX_AttrKind_FirstInheritableParamOrStmtAttr = CX_AttrKind_Annotate, + CX_AttrKind_LastInheritableParamOrStmtAttr = CX_AttrKind_Annotate, + CX_AttrKind_FirstParameterABIAttr = CX_AttrKind_HLSLParamModifier, CX_AttrKind_LastParameterABIAttr = CX_AttrKind_SwiftIndirectResult, - CX_AttrKind_FirstHLSLAnnotationAttr = CX_AttrKind_HLSLSV_DispatchThreadID, - CX_AttrKind_LastHLSLAnnotationAttr = CX_AttrKind_HLSLSV_GroupIndex, + CX_AttrKind_FirstHLSLAnnotationAttr = CX_AttrKind_HLSLPackOffset, + CX_AttrKind_LastHLSLAnnotationAttr = CX_AttrKind_HLSLSV_GroupThreadID, } diff --git a/sources/ClangSharp.Interop/clangsharp/CX_CastKind.cs b/sources/ClangSharp.Interop/clangsharp/CX_CastKind.cs index 443be8fb..1ddd91d1 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_CastKind.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_CastKind.cs @@ -71,4 +71,6 @@ public enum CX_CastKind CX_CK_ZeroToOCLOpaqueType, CX_CK_AddressSpaceConversion, CX_CK_IntToOCLSampler, + CX_CK_HLSLVectorTruncation, + CX_CK_HLSLArrayRValue, } diff --git a/sources/ClangSharp.Interop/clangsharp/CX_DeclKind.cs b/sources/ClangSharp.Interop/clangsharp/CX_DeclKind.cs index 3e3dbbe6..4b54d0c8 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_DeclKind.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_DeclKind.cs @@ -7,13 +7,14 @@ public enum CX_DeclKind { CX_DeclKind_Invalid, CX_DeclKind_TranslationUnit, + CX_DeclKind_TopLevelStmt, CX_DeclKind_RequiresExprBody, + CX_DeclKind_OutlinedFunction, CX_DeclKind_LinkageSpec, CX_DeclKind_ExternCContext, CX_DeclKind_Export, CX_DeclKind_Captured, CX_DeclKind_Block, - CX_DeclKind_TopLevelStmt, CX_DeclKind_StaticAssert, CX_DeclKind_PragmaDetectMismatch, CX_DeclKind_PragmaComment, diff --git a/sources/ClangSharp.Interop/clangsharp/CX_FloatingSemantics.cs b/sources/ClangSharp.Interop/clangsharp/CX_FloatingSemantics.cs index e76a082d..4cf9f909 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_FloatingSemantics.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_FloatingSemantics.cs @@ -12,12 +12,19 @@ public enum CX_FloatingSemantics CX_FLK_IEEEdouble, CX_FLK_IEEEquad, CX_FLK_PPCDoubleDouble, + CX_FLK_PPCDoubleDoubleLegacy, CX_FLK_Float8E5M2, CX_FLK_Float8E5M2FNUZ, + CX_FLK_Float8E4M3, CX_FLK_Float8E4M3FN, CX_FLK_Float8E4M3FNUZ, CX_FLK_Float8E4M3B11FNUZ, + CX_FLK_Float8E3M4, CX_FLK_FloatTF32, + CX_FLK_Float8E8M0FNU, + CX_FLK_Float6E3M2FN, + CX_FLK_Float6E2M3FN, + CX_FLK_Float4E2M1FN, CX_FLK_x87DoubleExtended, CX_FLK_MaxSemantics = CX_FLK_x87DoubleExtended, } diff --git a/sources/ClangSharp.Interop/clangsharp/CX_StmtClass.cs b/sources/ClangSharp.Interop/clangsharp/CX_StmtClass.cs index 0c5dba6f..3d4cfc6d 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_StmtClass.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_StmtClass.cs @@ -27,11 +27,13 @@ public enum CX_StmtClass CX_StmtClass_PredefinedExpr, CX_StmtClass_ParenListExpr, CX_StmtClass_ParenExpr, + CX_StmtClass_PackIndexingExpr, CX_StmtClass_PackExpansionExpr, CX_StmtClass_UnresolvedMemberExpr, CX_StmtClass_UnresolvedLookupExpr, CX_StmtClass_FirstOverloadExpr = CX_StmtClass_UnresolvedMemberExpr, CX_StmtClass_LastOverloadExpr = CX_StmtClass_UnresolvedLookupExpr, + CX_StmtClass_OpenACCAsteriskSizeExpr, CX_StmtClass_OpaqueValueExpr, CX_StmtClass_OffsetOfExpr, CX_StmtClass_ObjCSubscriptRefExpr, @@ -51,7 +53,6 @@ public enum CX_StmtClass CX_StmtClass_ObjCArrayLiteral, CX_StmtClass_OMPIteratorExpr, CX_StmtClass_OMPArrayShapingExpr, - CX_StmtClass_OMPArraySectionExpr, CX_StmtClass_NoInitExpr, CX_StmtClass_MemberExpr, CX_StmtClass_MatrixSubscriptExpr, @@ -63,6 +64,7 @@ public enum CX_StmtClass CX_StmtClass_InitListExpr, CX_StmtClass_ImplicitValueInitExpr, CX_StmtClass_ImaginaryLiteral, + CX_StmtClass_HLSLOutArgExpr, CX_StmtClass_GenericSelectionExpr, CX_StmtClass_GNUNullExpr, CX_StmtClass_FunctionParmPackExpr, @@ -74,6 +76,7 @@ public enum CX_StmtClass CX_StmtClass_FixedPointLiteral, CX_StmtClass_ExtVectorElementExpr, CX_StmtClass_ExpressionTraitExpr, + CX_StmtClass_EmbedExpr, CX_StmtClass_DesignatedInitUpdateExpr, CX_StmtClass_DesignatedInitExpr, CX_StmtClass_DependentScopeDeclRefExpr, @@ -145,6 +148,7 @@ public enum CX_StmtClass CX_StmtClass_AsTypeExpr, CX_StmtClass_ArrayTypeTraitExpr, CX_StmtClass_ArraySubscriptExpr, + CX_StmtClass_ArraySectionExpr, CX_StmtClass_ArrayInitLoopExpr, CX_StmtClass_ArrayInitIndexExpr, CX_StmtClass_AddrLabelExpr, @@ -162,11 +166,28 @@ public enum CX_StmtClass CX_StmtClass_CaseStmt, CX_StmtClass_FirstSwitchCase = CX_StmtClass_DefaultStmt, CX_StmtClass_LastSwitchCase = CX_StmtClass_CaseStmt, + CX_StmtClass_SYCLKernelCallStmt, CX_StmtClass_SEHTryStmt, CX_StmtClass_SEHLeaveStmt, CX_StmtClass_SEHFinallyStmt, CX_StmtClass_SEHExceptStmt, CX_StmtClass_ReturnStmt, + CX_StmtClass_OpenACCWaitConstruct, + CX_StmtClass_OpenACCUpdateConstruct, + CX_StmtClass_OpenACCShutdownConstruct, + CX_StmtClass_OpenACCSetConstruct, + CX_StmtClass_OpenACCInitConstruct, + CX_StmtClass_OpenACCExitDataConstruct, + CX_StmtClass_OpenACCEnterDataConstruct, + CX_StmtClass_OpenACCLoopConstruct, + CX_StmtClass_OpenACCHostDataConstruct, + CX_StmtClass_OpenACCDataConstruct, + CX_StmtClass_OpenACCComputeConstruct, + CX_StmtClass_OpenACCCombinedConstruct, + CX_StmtClass_FirstOpenACCAssociatedStmtConstruct = CX_StmtClass_OpenACCLoopConstruct, + CX_StmtClass_LastOpenACCAssociatedStmtConstruct = CX_StmtClass_OpenACCCombinedConstruct, + CX_StmtClass_FirstOpenACCConstructStmt = CX_StmtClass_OpenACCWaitConstruct, + CX_StmtClass_LastOpenACCConstructStmt = CX_StmtClass_OpenACCCombinedConstruct, CX_StmtClass_ObjCForCollectionStmt, CX_StmtClass_ObjCAutoreleasePoolStmt, CX_StmtClass_ObjCAtTryStmt, @@ -202,8 +223,10 @@ public enum CX_StmtClass CX_StmtClass_OMPMaskedDirective, CX_StmtClass_OMPUnrollDirective, CX_StmtClass_OMPTileDirective, + CX_StmtClass_OMPReverseDirective, + CX_StmtClass_OMPInterchangeDirective, CX_StmtClass_FirstOMPLoopTransformationDirective = CX_StmtClass_OMPUnrollDirective, - CX_StmtClass_LastOMPLoopTransformationDirective = CX_StmtClass_OMPTileDirective, + CX_StmtClass_LastOMPLoopTransformationDirective = CX_StmtClass_OMPInterchangeDirective, CX_StmtClass_OMPTeamsGenericLoopDirective, CX_StmtClass_OMPTeamsDistributeSimdDirective, CX_StmtClass_OMPTeamsDistributeParallelForSimdDirective, @@ -252,8 +275,9 @@ public enum CX_StmtClass CX_StmtClass_OMPCancelDirective, CX_StmtClass_OMPBarrierDirective, CX_StmtClass_OMPAtomicDirective, + CX_StmtClass_OMPAssumeDirective, CX_StmtClass_FirstOMPExecutableDirective = CX_StmtClass_OMPTeamsDirective, - CX_StmtClass_LastOMPExecutableDirective = CX_StmtClass_OMPAtomicDirective, + CX_StmtClass_LastOMPExecutableDirective = CX_StmtClass_OMPAssumeDirective, CX_StmtClass_OMPCanonicalLoop, CX_StmtClass_NullStmt, CX_StmtClass_MSDependentExistsStmt, diff --git a/sources/ClangSharp.Interop/clangsharp/CX_TemplateNameKind.cs b/sources/ClangSharp.Interop/clangsharp/CX_TemplateNameKind.cs index e0358a00..32a7bace 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_TemplateNameKind.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_TemplateNameKind.cs @@ -14,4 +14,5 @@ public enum CX_TemplateNameKind CX_TNK_SubstTemplateTemplateParm, CX_TNK_SubstTemplateTemplateParmPack, CX_TNK_UsingTemplate, + CX_TNK_DeducedTemplate, } diff --git a/sources/ClangSharp.Interop/clangsharp/CX_TypeClass.cs b/sources/ClangSharp.Interop/clangsharp/CX_TypeClass.cs index f6a7e4c7..81708516 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_TypeClass.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_TypeClass.cs @@ -9,6 +9,7 @@ public enum CX_TypeClass CX_TypeClass_Adjusted, CX_TypeClass_Decayed, CX_TypeClass_ConstantArray, + CX_TypeClass_ArrayParameter, CX_TypeClass_DependentSizedArray, CX_TypeClass_IncompleteArray, CX_TypeClass_VariableArray, @@ -17,6 +18,7 @@ public enum CX_TypeClass CX_TypeClass_BTFTagAttributed, CX_TypeClass_BitInt, CX_TypeClass_BlockPointer, + CX_TypeClass_CountAttributed, CX_TypeClass_Builtin, CX_TypeClass_Complex, CX_TypeClass_Decltype, @@ -31,6 +33,7 @@ public enum CX_TypeClass CX_TypeClass_Elaborated, CX_TypeClass_FunctionNoProto, CX_TypeClass_FunctionProto, + CX_TypeClass_HLSLAttributedResource, CX_TypeClass_InjectedClassName, CX_TypeClass_MacroQualified, CX_TypeClass_ConstantMatrix, @@ -41,6 +44,7 @@ public enum CX_TypeClass CX_TypeClass_ObjCInterface, CX_TypeClass_ObjCTypeParam, CX_TypeClass_PackExpansion, + CX_TypeClass_PackIndexing, CX_TypeClass_Paren, CX_TypeClass_Pipe, CX_TypeClass_Pointer, diff --git a/sources/ClangSharp.Interop/clangsharp/CX_UnaryExprOrTypeTrait.cs b/sources/ClangSharp.Interop/clangsharp/CX_UnaryExprOrTypeTrait.cs index 24a2b68c..68e94aed 100644 --- a/sources/ClangSharp.Interop/clangsharp/CX_UnaryExprOrTypeTrait.cs +++ b/sources/ClangSharp.Interop/clangsharp/CX_UnaryExprOrTypeTrait.cs @@ -10,8 +10,9 @@ public enum CX_UnaryExprOrTypeTrait CX_UETT_DataSizeOf, CX_UETT_AlignOf, CX_UETT_PreferredAlignOf, + CX_UETT_PtrAuthTypeDiscriminator, CX_UETT_VecStep, CX_UETT_OpenMPRequiredSimdAlign, CX_UETT_VectorElements, - CX_UETT_Last = -1 + 1 + 1 + 1 + 1 + 1 + 1 + 1, + CX_UETT_Last = -1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1, } diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs index 0a33d680..8a369cb9 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs @@ -66,6 +66,21 @@ readonly get } } + public bool IsReadOnly + { + readonly get + { + return (Flags & FunctionOrDelegateFlags.IsReadOnly) != 0; + } + + set + { + Flags = value + ? Flags | FunctionOrDelegateFlags.IsReadOnly + : Flags & ~FunctionOrDelegateFlags.IsReadOnly; + } + } + public bool HasFnPtrCodeGen { readonly get diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs index 522d5c79..7ffda523 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs @@ -89,7 +89,7 @@ public void WriteIid(string name, Guid value) WriteIndented("ReadOnlySpan data = "); - if (_generator.Config.GenerateLatestCode) + if (!_generator.Config.GenerateCompatibleCode) { WriteLine('['); } @@ -124,7 +124,7 @@ public void WriteIid(string name, Guid value) WriteNewline(); DecreaseIndentation(); - if (_generator.Config.GenerateLatestCode) + if (!_generator.Config.GenerateCompatibleCode) { WriteIndented(']'); } diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index 8380a582..5060f29d 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -517,6 +517,11 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM Write("new "); } + if (desc.IsReadOnly) + { + Write("readonly "); + } + if (desc.IsUnsafe) { if (!desc.IsCtxCxxRecord) @@ -808,7 +813,7 @@ public void BeginStruct(in StructDesc desc) Write(".Interface"); } - if ((desc.Uuid is not null) && _generator.Config.GenerateGuidMember && _generator.Config.GenerateLatestCode) + if ((desc.Uuid is not null) && _generator.Config.GenerateGuidMember && !_generator.Config.GenerateCompatibleCode) { Write(desc.HasVtbl ? ", " : " : "); Write("INativeGuid"); diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs index 30b8ccc1..f6d52daa 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs @@ -18,8 +18,8 @@ internal sealed partial class CSharpOutputBuilder(string name, PInvokeGenerator private readonly PInvokeGenerator _generator = generator; private readonly List _contents = []; private readonly StringBuilder _currentLine = new StringBuilder(); - private readonly SortedSet _usingDirectives = []; - private readonly SortedSet _staticUsingDirectives = []; + private readonly SortedSet _usingDirectives = new SortedSet(StringComparer.Ordinal); + private readonly SortedSet _staticUsingDirectives = new SortedSet(StringComparer.Ordinal); private readonly string _indentationString = indentationString; private readonly bool _isTestOutput = isTestOutput; @@ -80,6 +80,8 @@ public void WriteBlockEnd() public void Write(T value) => _ = _currentLine.Append(value); + public void Write(ReadOnlySpan value) => _ = _currentLine.Append(value); + public void WriteIndentation() { WriteNewlineIfNeeded(); @@ -102,6 +104,31 @@ public void WriteIndentedLine(T value) WriteLine(value); } + public void WriteLabel(string name) + { + if (_currentLine.Length >= _indentationString.Length) + { + var match = true; + + for (var i = 0; i < _indentationString.Length; i++) + { + if (_currentLine[_currentLine.Length - i - 1] != _indentationString[_indentationString.Length - 1 - i]) + { + match = false; + break; + } + } + + if (match) + { + _ = _currentLine.Remove(_currentLine.Length - _indentationString.Length, _indentationString.Length); + } + } + + Write(name); + WriteLine(':'); + } + public void WriteLine(T value) { Write(value); diff --git a/sources/ClangSharp.PInvokeGenerator/ClangSharp.PInvokeGenerator.csproj b/sources/ClangSharp.PInvokeGenerator/ClangSharp.PInvokeGenerator.csproj index a8c82d4a..bfdcb5f6 100644 --- a/sources/ClangSharp.PInvokeGenerator/ClangSharp.PInvokeGenerator.csproj +++ b/sources/ClangSharp.PInvokeGenerator/ClangSharp.PInvokeGenerator.csproj @@ -3,7 +3,7 @@ ClangSharp - net8.0 + net10.0 diff --git a/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs b/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs index aeb0eab6..3f4d5396 100644 --- a/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs +++ b/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs @@ -21,4 +21,5 @@ internal enum FunctionOrDelegateFlags NeedsReturnFixup = 1 << 13, IsCxxConstructor = 1 << 14, IsManualImport = 1 << 15, + IsReadOnly = 1 << 16, } diff --git a/sources/ClangSharp.PInvokeGenerator/OutputBuilderFactory.cs b/sources/ClangSharp.PInvokeGenerator/OutputBuilderFactory.cs index 5aa2100f..de4693e7 100644 --- a/sources/ClangSharp.PInvokeGenerator/OutputBuilderFactory.cs +++ b/sources/ClangSharp.PInvokeGenerator/OutputBuilderFactory.cs @@ -12,7 +12,7 @@ namespace ClangSharp; internal sealed class OutputBuilderFactory(PInvokeGenerator generator) { private readonly bool _writeSourceLocation = generator.Config.GenerateSourceLocationAttribute; - private readonly Dictionary _outputBuilders = []; + private readonly Dictionary _outputBuilders = new Dictionary(StringComparer.Ordinal); public IEnumerable OutputBuilders => _outputBuilders.Values; diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 2e37bb02..88992629 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -7,11 +7,9 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; -using System.Text.RegularExpressions; using ClangSharp.Abstractions; using ClangSharp.CSharp; using static ClangSharp.Interop.CX_CastKind; -using static ClangSharp.Interop.CX_CharacterKind; using static ClangSharp.Interop.CX_DeclKind; using static ClangSharp.Interop.CX_StmtClass; using static ClangSharp.Interop.CX_StorageClass; @@ -374,8 +372,7 @@ private void VisitEnumDecl(EnumDecl enumDecl) { var typeName = GetRemappedTypeName(enumDecl, context: null, enumDecl.IntegerType, out var nativeTypeName); - desc = new EnumDesc() - { + desc = new EnumDesc() { AccessSpecifier = accessSpecifier, TypeName = typeName, EscapedName = escapedName, @@ -608,6 +605,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) IsCxx = cxxMethodDecl is not null, IsStatic = isDllImport || (cxxMethodDecl is null) || cxxMethodDecl.IsStatic, NeedsNewKeyword = NeedsNewKeyword(escapedName, functionDecl.Parameters), + IsReadOnly = IsReadonly(cxxMethodDecl), IsUnsafe = IsUnsafe(functionDecl), IsCtxCxxRecord = cxxRecordDecl is not null, IsCxxRecordCtxUnsafe = cxxRecordDecl is not null && IsUnsafe(cxxRecordDecl), @@ -628,7 +626,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) } }, CustomAttrGeneratorData = (functionDecl, _outputBuilder, this), - ParameterTypes = overloadCount > 1 ? functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray() : null, + ParameterTypes = overloadCount > 1 ? [.. functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _))] : null, }; Debug.Assert(_outputBuilder is not null); @@ -662,8 +660,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) if (needsReturnFixup) { _outputBuilder.WriteParameterSeparator(); - parameterDesc = new() - { + parameterDesc = new() { Name = "_result", Type = $"{returnTypeName}*" }; @@ -685,8 +682,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) { _outputBuilder.WriteParameterSeparator(); } - var parameterDesc = new ParameterDesc - { + var parameterDesc = new ParameterDesc { Name = "", Type = "__arglist" }; @@ -815,9 +811,11 @@ void VisitCtorInitializers(CXXConstructorDecl cxxConstructorDecl, int firstCtorI { continue; } - - var memberRef = (Ref)cxxConstructorDecl.CursorChildren[i]; - var memberInit = (Stmt)cxxConstructorDecl.CursorChildren[++i]; + if (cxxConstructorDecl.CursorChildren[i] is not Ref memberRef + || cxxConstructorDecl.CursorChildren[++i] is not Stmt memberInit) + { + continue; + } if (memberInit is ImplicitValueInitExpr) { @@ -827,7 +825,7 @@ void VisitCtorInitializers(CXXConstructorDecl cxxConstructorDecl, int firstCtorI var memberRefName = GetRemappedCursorName(memberRef.Referenced); var memberInitName = memberInit.Spelling; - if (memberInit is CastExpr {SubExprAsWritten: DeclRefExpr declRefExpr}) + if (memberInit is CastExpr { SubExprAsWritten: DeclRefExpr declRefExpr }) { memberInitName = GetRemappedCursorName(declRefExpr.Decl); } @@ -859,6 +857,7 @@ void VisitCtorInitializers(CXXConstructorDecl cxxConstructorDecl, int firstCtorI { _outputBuilder.EndConstructorInitializer(); } + } } } @@ -872,7 +871,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) return; } - if (IsPrevContextDecl(out var prevContext, out _) && prevContext.IsAnonymous) + if (IsPrevContextDecl(out var prevContext, out _) && prevContext.IsAnonymousStructOrUnion) { // We shouldn't process indirect fields where the prev context is an anonymous record decl return; @@ -887,7 +886,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) var contextNameParts = new Stack(); var contextTypeParts = new Stack(); - while (rootRecordDecl.IsAnonymous && (rootRecordDecl.Parent is RecordDecl parentRecordDecl)) + while (rootRecordDecl.IsAnonymousStructOrUnion && (rootRecordDecl.Parent is RecordDecl parentRecordDecl)) { // The name of a field of an anonymous type should be same as the type's name minus the // type kind tag at the end and the leading `_`. @@ -944,7 +943,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) ParentName = GetRemappedCursorName(parent), Offset = null, NeedsNewKeyword = false, - NeedsUnscopedRef = _config.GenerateLatestCode && !fieldDecl.IsBitField, + NeedsUnscopedRef = !_config.GenerateCompatibleCode && !fieldDecl.IsBitField, Location = fieldDecl.Location, HasBody = true, WriteCustomAttrs = static context => { @@ -1110,13 +1109,13 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) code.Write(arraySize); code.Write(')'); } - else if (!_config.GenerateLatestCode || arraySize == 1) + else if (_config.GenerateCompatibleCode || arraySize == 1) { code.Write(".AsSpan("); if (arraySize == 1) { - if (TryGetRemappedValue(indirectFieldDecl, _config.WithLengths, out var length)) + if (TryGetRemappedValue(indirectFieldDecl, _config._withLengths, out var length)) { code.Write(length); } @@ -1319,8 +1318,7 @@ void ForTypedefDecl(ParmVarDecl parmVarDecl, TypedefDecl typedefDecl) escapedName += index; } - var desc = new ParameterDesc - { + var desc = new ParameterDesc { Name = escapedName, Type = typeName, NativeTypeName = nativeTypeName, @@ -1391,7 +1389,7 @@ private void VisitRecordDecl(RecordDecl recordDecl) var maxAlignm = recordDecl.Fields.Any() ? recordDecl.Fields.Max((fieldDecl) => Math.Max(fieldDecl.Type.Handle.AlignOf, 1)) : alignment; var isTopLevelStruct = _config.WithTypes.TryGetValue(name, out var withType) && withType.Equals("struct", StringComparison.Ordinal); - var generateTestsClass = !recordDecl.IsAnonymous && recordDecl.DeclContext is not RecordDecl; + var generateTestsClass = !recordDecl.IsAnonymousStructOrUnion && recordDecl.DeclContext is not RecordDecl; var testOutputStarted = false; var nullableUuid = (Guid?)null; @@ -1511,7 +1509,7 @@ private void VisitRecordDecl(RecordDecl recordDecl) baseTypeNames = [.. baseTypeNamesBuilder]; } - if (!TryGetRemappedValue(recordDecl, _config.WithPackings, out var pack)) + if (!TryGetRemappedValue(recordDecl, _config._withPackings, out var pack)) { pack = alignment < maxAlignm ? alignment.ToString(CultureInfo.InvariantCulture) : null; } @@ -1559,7 +1557,7 @@ private void VisitRecordDecl(RecordDecl recordDecl) if (!_topLevelClassUsings.TryGetValue(name, out var withUsings)) { - withUsings = []; + withUsings = new HashSet(StringComparer.Ordinal); } if (desc.LayoutAttribute is not null) @@ -1658,9 +1656,23 @@ private void VisitRecordDecl(RecordDecl recordDecl) _outputBuilder.BeginValue(in valueDesc); var code = _outputBuilder.BeginCSharpCode(); - code.Write("(Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in "); + + code.Write("(Guid*)Unsafe.AsPointer("); + + if (!_config.GenerateLatestCode) + { + code.Write("ref Unsafe.AsRef("); + } + + code.Write("in "); code.Write(usableUuidName); - code.Write("))"); + code.Write(')'); + + if (!_config.GenerateLatestCode) + { + code.Write(')'); + } + _outputBuilder.EndCSharpCode(code); _outputBuilder.EndValue(in valueDesc); @@ -2139,8 +2151,7 @@ void OutputVtblEntry(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl) var remappedName = FixupNameForMultipleHits(cxxMethodDecl); var escapedName = EscapeAndStripMethodName(remappedName); - var desc = new FieldDesc - { + var desc = new FieldDesc { AccessSpecifier = AccessSpecifier.Public, NativeTypeName = nativeTypeName, EscapedName = escapedName, @@ -2215,6 +2226,7 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod HasFnPtrCodeGen = !_config.ExcludeFnptrCodegen, IsCtxCxxRecord = true, IsCxxRecordCtxUnsafe = IsUnsafe(cxxRecordDecl), + IsReadOnly = IsReadonly(cxxMethodDecl), IsUnsafe = true, NeedsReturnFixup = needsReturnFixup, ReturnType = returnTypeName, @@ -2337,7 +2349,27 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod { body.Write('('); body.Write(escapedCXXRecordDeclName); - body.Write("*)Unsafe.AsPointer(ref this)"); + body.Write("*)Unsafe.AsPointer("); + + if (IsReadonly(cxxMethodDecl)) + { + if (!_config.GenerateLatestCode) + { + body.Write("ref Unsafe.AsRef("); + } + + body.Write("in this"); + + if (!_config.GenerateLatestCode) + { + body.Write(')'); + } + } + else + { + body.Write("ref this"); + } + body.Write(')'); } body.EndMarker("param"); @@ -2716,204 +2748,282 @@ void VisitBitfieldDecl(FieldDecl fieldDecl, BitfieldDesc[] bitfieldDescs, Record _outputBuilder.BeginField(in desc); _outputBuilder.WriteRegularField(typeName, escapedName); _outputBuilder.BeginBody(); - _outputBuilder.BeginGetter(_config.GenerateAggressiveInlining, isReadOnly: !Config.GenerateCompatibleCode); - var code = _outputBuilder.BeginCSharpCode(); - - code.WriteIndented("return "); var recordDeclName = GetCursorName(recordDecl); - var isSmallType = currentSize < 4; - var isRemappedToSelf = _config.RemappedNames.TryGetValue(typeName, out var remappedTypeName) && typeName.Equals(remappedTypeName, StringComparison.Ordinal); - var isTypeMismatch = type != builtinTypeBacking; - var isUnsignedToSigned = !isTypeBackingSigned && isTypeSigned; + // Small types become uint32/int32s after shifting + var isSmallType = fieldDecl.Type.Handle.SizeOf < 4; + var isSmallTypeBacking = currentSize < 4; - var needsCast = isSmallType || isRemappedToSelf || isTypeMismatch || isUnsignedToSigned; - var needsParenFirst = !isSmallType && isUnsignedToSigned; - var needsParenSecond = !needsParenFirst || isRemappedToSelf; + // Check if field/backing types match + var isTypeMismatch = type != builtinTypeBacking; + // Signed types are sign extended when shifted + var isUnsignedToSigned = !isTypeBackingSigned && isTypeSigned; + + // Check if type is directly shiftable/maskable + // Remapped types are not guaranteed to be shiftable or maskable + // Enums are maskable, but not shiftable + var isTypeLikelyRemapped = !isTypeMismatch && (typeName != typeNameBacking); + var isTypeAnEnum = IsType(fieldDecl); + + // Main cases: // backing int, current int (value << cns) >> cns // backing int, current uint (uint)((value >> cns) & msk) - // backing uint, current int ((int)value << cns) >> cns + // backing uint, current int (int)(value << cns) >> cns // backing uint, current uint (value >> cns) & msk // backing uint, current byte (byte)((value >> cns) & msk) - // backing uint, current sbyte (sbyte)((value << cns) >> cns) + // backing uint, current sbyte (sbyte)((sbyte)(value << cns) >> cns) - if (needsCast) + // Getter { - code.Write('('); - code.BeginMarker("typeName"); - code.Write(typeName); - code.EndMarker("typeName"); - code.Write(")("); - } + _outputBuilder.BeginGetter(_config.GenerateAggressiveInlining, + isReadOnly: !Config.GenerateCompatibleCode); + var code = _outputBuilder.BeginCSharpCode(); - if ((!needsParenFirst && (bitfieldOffset != 0)) || (!isUnsignedToSigned && isTypeSigned)) - { - code.Write('('); - } + code.WriteIndented("return "); - if (!string.IsNullOrWhiteSpace(contextName)) - { - code.BeginMarker("contextName"); - code.Write(contextName); - code.EndMarker("contextName"); - code.Write('.'); - } + var needsCastToFinal = (isSmallType || isTypeMismatch || isUnsignedToSigned) && !isTypeAnEnum; - code.BeginMarker("bitfieldName"); - code.Write(bitfieldName); - code.EndMarker("bitfieldName"); + // This is to handle the "backing uint, current sbyte" case + var needsCastToFinalAgain = isUnsignedToSigned && isSmallType; + if (needsCastToFinalAgain) + { + code.Write('('); + code.BeginMarker("typeName"); + code.Write(typeName); + code.EndMarker("typeName"); + code.Write(")("); + } - if (isTypeSigned) - { - code.Write(" << "); - code.BeginMarker("remainingBitsMinusBitWidth"); - code.Write(remainingBits - fieldDecl.BitWidthValue); - code.EndMarker("remainingBitsMinusBitWidth"); - code.Write(')'); + if (needsCastToFinal) + { + code.Write('('); + code.BeginMarker("typeName"); + code.Write(typeName); + code.EndMarker("typeName"); + code.Write(")"); + } - code.Write(" >> "); - code.BeginMarker("currentSizeMinusBitWidth"); - code.Write((currentSize * 8) - fieldDecl.BitWidthValue); - code.EndMarker("currentSizeMinusBitWidth"); - } - else - { - if (bitfieldOffset != 0) + var needsCastToFinalParen = needsCastToFinal && !isUnsignedToSigned; + if (needsCastToFinalParen) { - code.Write(" >> "); - code.BeginMarker("bitfieldOffset"); - code.Write(bitfieldOffset); - code.EndMarker("bitfieldOffset"); + code.Write('('); + } + + var needsCastBeforeOp = isTypeLikelyRemapped || isTypeAnEnum; + if (needsCastBeforeOp) + { + code.Write('('); + code.BeginMarker("typeName"); + code.Write(typeName); + code.EndMarker("typeName"); + code.Write(")("); + } + + if (isTypeSigned) + { + code.Write('('); + + if (!string.IsNullOrWhiteSpace(contextName)) + { + code.BeginMarker("contextName"); + code.Write(contextName); + code.EndMarker("contextName"); + code.Write('.'); + } + + code.BeginMarker("bitfieldName"); + code.Write(bitfieldName); + code.EndMarker("bitfieldName"); + + code.Write(" << "); + code.BeginMarker("remainingBitsMinusBitWidth"); + code.Write(remainingBits - fieldDecl.BitWidthValue); + code.EndMarker("remainingBitsMinusBitWidth"); + code.Write(')'); + + code.Write(" >> "); + code.BeginMarker("currentSizeMinusBitWidth"); + code.Write((currentSize * 8) - fieldDecl.BitWidthValue); + code.EndMarker("currentSizeMinusBitWidth"); } + else + { + var needsOffset = bitfieldOffset != 0; + if (needsOffset) + { + code.Write('('); + } - code.Write(" & 0x"); - code.BeginMarker("bitwidthHexStringBacking"); - code.Write(bitwidthHexStringBacking); - code.EndMarker("bitwidthHexStringBacking"); - } + if (!string.IsNullOrWhiteSpace(contextName)) + { + code.BeginMarker("contextName"); + code.Write(contextName); + code.EndMarker("contextName"); + code.Write('.'); + } - if (needsCast && needsParenSecond) - { - code.Write(')'); - } + code.BeginMarker("bitfieldName"); + code.Write(bitfieldName); + code.EndMarker("bitfieldName"); - code.WriteSemicolon(); - code.WriteNewline(); - _outputBuilder.EndCSharpCode(code); - _outputBuilder.EndGetter(); + if (needsOffset) + { + code.Write(" >> "); + code.BeginMarker("bitfieldOffset"); + code.Write(bitfieldOffset); + code.EndMarker("bitfieldOffset"); - _outputBuilder.BeginSetter(_config.GenerateAggressiveInlining); - code = _outputBuilder.BeginCSharpCode(); - code.WriteIndentation(); + code.Write(')'); + } - if (!string.IsNullOrWhiteSpace(contextName)) - { - code.BeginMarker("contextName"); - code.Write(contextName); - code.EndMarker("contextName"); - code.Write('.'); - } + code.Write(" & 0x"); + code.BeginMarker("bitwidthHexStringBacking"); + code.Write(bitwidthHexStringBacking); + code.EndMarker("bitwidthHexStringBacking"); + } - code.BeginMarker("bitfieldName"); - code.Write(bitfieldName); - code.EndMarker("bitfieldName"); + if (needsCastBeforeOp) + { + code.Write(')'); + } - code.Write(" = "); + if (needsCastToFinalParen) + { + code.Write(')'); + } - if (currentSize < 4) - { - code.Write('('); - code.BeginMarker("typeNameBacking"); - code.Write(typeNameBacking); - code.EndMarker("typeNameBacking"); - code.Write(")("); - } + if (needsCastToFinalAgain) + { + code.Write(')'); + } - code.Write('('); + code.WriteSemicolon(); + code.WriteNewline(); + _outputBuilder.EndCSharpCode(code); + _outputBuilder.EndGetter(); + } - if (!string.IsNullOrWhiteSpace(contextName)) + // Setter { - code.Write(contextName); - code.Write('.'); - } + _outputBuilder.BeginSetter(_config.GenerateAggressiveInlining); + var code = _outputBuilder.BeginCSharpCode(); + code.WriteIndentation(); - code.Write(bitfieldName); + if (!string.IsNullOrWhiteSpace(contextName)) + { + code.BeginMarker("contextName"); + code.Write(contextName); + code.EndMarker("contextName"); + code.Write('.'); + } - code.Write(" & ~"); + code.BeginMarker("bitfieldName"); + code.Write(bitfieldName); + code.EndMarker("bitfieldName"); - if (bitfieldOffset != 0) - { + code.Write(" = "); + + var needsCastToFinal = isSmallTypeBacking; + if (needsCastToFinal) + { + code.Write('('); + code.BeginMarker("typeNameBacking"); + code.Write(typeNameBacking); + code.EndMarker("typeNameBacking"); + code.Write(")("); + } + + // Zero out target bits code.Write('('); - } - code.Write("0x"); - code.BeginMarker("bitwidthHexStringBacking"); - code.Write(bitwidthHexStringBacking); - code.EndMarker("bitwidthHexStringBacking"); + if (!string.IsNullOrWhiteSpace(contextName)) + { + code.Write(contextName); + code.Write('.'); + } - if (bitfieldOffset != 0) - { - code.Write(" << "); - code.BeginMarker("bitfieldOffset"); - code.Write(bitfieldOffset); - code.EndMarker("bitfieldOffset"); - code.Write(')'); - } + code.Write(bitfieldName); - code.Write(") | "); + code.Write(" & ~"); - if ((builtinType != builtinTypeBacking) && !IsType(fieldDecl)) - { - code.Write('('); - code.Write(typeNameBacking); - code.Write(')'); - } + if (bitfieldOffset != 0) + { + code.Write('('); + } - code.Write('('); + code.Write("0x"); + code.BeginMarker("bitwidthHexStringBacking"); + code.Write(bitwidthHexStringBacking); + code.EndMarker("bitwidthHexStringBacking"); - if (bitfieldOffset != 0) - { - code.Write('('); - } + if (bitfieldOffset != 0) + { + code.Write(" << "); + code.BeginMarker("bitfieldOffset"); + code.Write(bitfieldOffset); + code.EndMarker("bitfieldOffset"); + code.Write(')'); + } + + // Write to target bits + code.Write(") | "); + + var needsCastBeforeLogicalOr = isTypeMismatch && !isTypeAnEnum; + if (needsCastBeforeLogicalOr) + { + code.Write('('); + code.Write(typeNameBacking); + code.Write(")"); + } - if (IsType(fieldDecl) || isRemappedToSelf) - { code.Write('('); - code.Write(typeNameBacking); - code.Write(")(value)"); - } - else - { - code.Write("value"); - } - code.Write(" & 0x"); - code.BeginMarker("bitwidthHexString"); - code.Write(bitwidthHexString); - code.EndMarker("bitwidthHexString"); + if (bitfieldOffset != 0) + { + code.Write('('); + } - if (bitfieldOffset != 0) - { - code.Write(") << "); - code.Write(bitfieldOffset); - } + var needsCastBeforeOp = isTypeLikelyRemapped || isTypeAnEnum; + if (needsCastBeforeOp) + { + code.Write('('); + code.Write(typeNameBacking); + code.Write(")(value)"); + } + else + { + code.Write("value"); + } - code.Write(')'); + code.Write(" & 0x"); + code.BeginMarker("bitwidthHexString"); + code.Write(bitwidthHexString); + code.EndMarker("bitwidthHexString"); + + if (bitfieldOffset != 0) + { + code.Write(") << "); + code.Write(bitfieldOffset); + } - if (currentSize < 4) - { code.Write(')'); + + if (needsCastToFinal) + { + code.Write(')'); + } + + code.WriteSemicolon(); + code.WriteNewline(); + _outputBuilder.EndCSharpCode(code); + _outputBuilder.EndSetter(); } - code.WriteSemicolon(); - code.WriteNewline(); - _outputBuilder.EndCSharpCode(code); - _outputBuilder.EndSetter(); _outputBuilder.EndBody(); _outputBuilder.EndField(in desc); _outputBuilder.WriteDivider(); @@ -2954,7 +3064,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co var arraySize = Math.Max((arrayType as ConstantArrayType)?.Size ?? 0, 1); var totalSize = arraySize; var totalSizeString = $"{arraySize}"; - var sizePerDimension = new List<(long index, long size)>() {(0, arraySize) }; + var sizePerDimension = new List<(long index, long size)>() { (0, arraySize) }; while (IsTypeConstantOrIncompleteArray(recordDecl, elementType, out var subArrayType)) { @@ -2976,7 +3086,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co AddDiagnostic(DiagnosticLevel.Info, $"{escapedName} (constant array field) has a size of 0", constantOrIncompleteArray); } - if (!_config.GenerateLatestCode || (totalSize <= 1) || isUnsafeElementType) + if (_config.GenerateCompatibleCode || (totalSize <= 1) || isUnsafeElementType) { totalSizeString = null; } @@ -3102,7 +3212,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co } else if (totalSizeString is null) { - _outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: _config.GenerateLatestCode); + _outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: !_config.GenerateCompatibleCode); _outputBuilder.WriteIndexer($"ref {arrayTypeName}"); _outputBuilder.BeginIndexerParameters(); var param = new ParameterDesc { @@ -3123,6 +3233,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co if (arraySize == 1) { + code.AddUsingDirective("System.Runtime.CompilerServices"); code.Write("Unsafe.Add(ref e0, index)"); } else @@ -3147,7 +3258,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co ReturnType = $"Span<{arrayTypeName}>", Location = constantOrIncompleteArray.Location, HasBody = true, - NeedsUnscopedRef = _config.GenerateLatestCode, + NeedsUnscopedRef = !_config.GenerateCompatibleCode, }; var isUnsafe = false; @@ -3312,7 +3423,7 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHa { if (!_allValidNameRemappings.TryGetValue(underlyingName, out var allRemappings)) { - allRemappings = []; + allRemappings = new HashSet(QualifiedNameComparer.Default); _allValidNameRemappings[underlyingName] = allRemappings; } _ = allRemappings.Add(typedefName); @@ -3322,7 +3433,7 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHa { if (!_traversedValidNameRemappings.TryGetValue(underlyingName, out var traversedRemappings)) { - traversedRemappings = []; + traversedRemappings = new HashSet(QualifiedNameComparer.Default); _traversedValidNameRemappings[underlyingName] = traversedRemappings; } _ = traversedRemappings.Add(typedefName); @@ -3464,7 +3575,7 @@ private void VisitVarDecl(VarDecl varDecl) case CX_SLK_UTF32: { - typeName = (_config.GenerateLatestCode && flags.HasFlag(ValueFlags.Constant)) ? "ReadOnlySpan" : "uint[]"; + typeName = (!_config.GenerateCompatibleCode && flags.HasFlag(ValueFlags.Constant)) ? "ReadOnlySpan" : "uint[]"; break; } @@ -3875,7 +3986,7 @@ private bool IsConstant(string targetTypeName, Expr initExpr) } // case CX_StmtClass_NoInitExpr: - // case CX_StmtClass_OMPArraySectionExpr: + // case CX_StmtClass_ArraySectionExpr: // case CX_StmtClass_ObjCArrayLiteral: // case CX_StmtClass_ObjCAvailabilityCheckExpr: // case CX_StmtClass_ObjCBoolLiteralExpr: diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index 3fd39a09..5eaf6372 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -41,7 +41,60 @@ private void VisitBinaryOperator(BinaryOperator binaryOperator) outputBuilder.Write(' '); outputBuilder.Write(binaryOperator.OpcodeStr); outputBuilder.Write(' '); - Visit(binaryOperator.RHS); + + if (binaryOperator.IsShiftOp || binaryOperator.IsShiftAssignOp) + { + // RHS of shift operation in C# must be an int + + // Negative shifts are undefined behavior in C/C++, but still needs to have a compilable output + var isNegated = binaryOperator.RHS is UnaryOperator { Opcode: CXUnaryOperator_Minus }; + var sign = isNegated ? -1 : 1; + + var rhs = isNegated ? ((UnaryOperator)binaryOperator.RHS).SubExpr : binaryOperator.RHS; + switch (rhs) + { + case IntegerLiteral literal: + { + var value = sign * literal.Value; + if (value is > int.MaxValue or < int.MinValue) + { + // Literal is in int32 range + outputBuilder.Write("(int)("); + outputBuilder.Write(sign * literal.Value); + outputBuilder.Write(")"); + } + else + { + // Literal is not in int32 range + outputBuilder.Write(sign * literal.Value); + } + + break; + } + // Already the correct type or implicitly castable + case { Type.Kind: CXType_Int or CXType_UShort or CXType_Short or CXType_Char_U or CXType_Char_S or CXType_UChar or CXType_SChar }: + case { Type.Kind: CXType_Long } when _config is { GenerateUnixTypes: false }: + case { Type.Kind: CXType_Char16 } when _config is { GenerateDisableRuntimeMarshalling: false }: + case { Type.Kind: CXType_WChar } when _config is { GenerateDisableRuntimeMarshalling: false, GenerateUnixTypes: false }: + { + Visit(binaryOperator.RHS); + break; + } + // Fallback + default: + { + outputBuilder.Write("(int)("); + Visit(binaryOperator.RHS); + outputBuilder.Write(")"); + break; + } + } + } + else + { + Visit(binaryOperator.RHS); + } + StopCSharpCode(); } @@ -194,7 +247,7 @@ private void VisitCallExpr(CallExpr callExpr) { var args = callExpr.Args; - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { outputBuilder.AddUsingDirective("System.Runtime.InteropServices"); outputBuilder.Write("NativeMemory.Copy"); @@ -253,13 +306,13 @@ private void VisitCallExpr(CallExpr callExpr) break; } - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { args = [args[0], args[2], args[1]]; } } - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { outputBuilder.AddUsingDirective("System.Runtime.InteropServices"); outputBuilder.Write("NativeMemory.Fill"); @@ -356,7 +409,27 @@ void VisitArgs(CallExpr callExpr, IReadOnlyList? args = null) outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); outputBuilder.Write('('); outputBuilder.Write(referenceTypeName); - outputBuilder.Write(")Unsafe.AsPointer(ref this)"); + outputBuilder.Write(")Unsafe.AsPointer("); + + if (referenceType.IsLocalConstQualified) + { + if (!_config.GenerateLatestCode) + { + outputBuilder.Write("ref Unsafe.AsRef("); + } + + outputBuilder.Write("in this"); + + if (!_config.GenerateLatestCode) + { + outputBuilder.Write(')'); + } + } + else + { + outputBuilder.Write("ref this"); + } + outputBuilder.Write(')'); needsComma = true; continue; @@ -379,7 +452,27 @@ void VisitArgs(CallExpr callExpr, IReadOnlyList? args = null) else if (IsStmtAsWritten(arg, out _) && (functionName == "memcpy")) { outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); - outputBuilder.Write("Unsafe.AsPointer(ref this)"); + outputBuilder.Write("Unsafe.AsPointer("); + + if (functionProtoType.ParamTypes[i].IsLocalConstQualified) + { + if (!_config.GenerateLatestCode) + { + outputBuilder.Write("ref Unsafe.AsRef("); + } + + outputBuilder.Write("in this"); + + if (!_config.GenerateLatestCode) + { + outputBuilder.Write(')'); + } + } + else + { + outputBuilder.Write("ref this"); + } + outputBuilder.Write(')'); needsComma = true; continue; @@ -751,7 +844,7 @@ private void VisitCXXOperatorCallExpr(CXXOperatorCallExpr cxxOperatorCallExpr) { Visit(args[0]); outputBuilder.Write(' '); - outputBuilder.Write(functionDeclName[8..]); + outputBuilder.Write(functionDeclName.AsSpan()[8..]); outputBuilder.Write(' '); Visit(args[1]); StopCSharpCode(); @@ -760,7 +853,7 @@ private void VisitCXXOperatorCallExpr(CXXOperatorCallExpr cxxOperatorCallExpr) case "operator~": { - outputBuilder.Write(functionDeclName[8..]); + outputBuilder.Write(functionDeclName.AsSpan()[8..]); Visit(args[0]); StopCSharpCode(); return; @@ -1108,7 +1201,7 @@ private void VisitFloatingLiteral(FloatingLiteral floatingLiteral) var outputBuilder = StartCSharpCode(); if (floatingLiteral.ValueString.EndsWith(".f", StringComparison.Ordinal)) { - outputBuilder.Write(floatingLiteral.ValueString[0..^1]); + outputBuilder.Write(floatingLiteral.ValueString.AsSpan()[..^1]); outputBuilder.Write("0f"); } else @@ -1703,7 +1796,7 @@ void HandleUnmanagedConstant(CSharpOutputBuilder outputBuilder, InitListExpr ini outputBuilder.WriteIndented("ReadOnlySpan data = "); - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.WriteLine("["); } @@ -1719,7 +1812,7 @@ void HandleUnmanagedConstant(CSharpOutputBuilder outputBuilder, InitListExpr ini outputBuilder.WriteNewline(); outputBuilder.DecreaseIndentation(); - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.WriteIndented(']'); } @@ -1901,76 +1994,83 @@ void HandleUnmanagedConstant(CSharpOutputBuilder outputBuilder, InitListExpr ini private void VisitIntegerLiteral(IntegerLiteral integerLiteral) { - var valueString = integerLiteral.ValueString; + var valueString = integerLiteral.ValueString.AsSpan(); + var valueSuffix = ""; if (valueString.EndsWith("ui8", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^3]; + valueString = valueString[..^3]; } else if (valueString.EndsWith("i8", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^2]; + valueString = valueString[..^2]; } else if (valueString.EndsWith("ui16", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^4]; + valueString = valueString[..^4]; } else if (valueString.EndsWith("i16", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^3]; + valueString = valueString[..^3]; } else if (valueString.EndsWith("ui32", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^4] + "U"; + valueString = valueString[..^4]; + valueSuffix = "U"; } else if (valueString.EndsWith("i32", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^3]; + valueString = valueString[..^3]; } else if (valueString.EndsWith("ui64", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^4] + "UL"; + valueString = valueString[..^4]; + valueSuffix = "UL"; } else if (valueString.EndsWith("i64", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^3] + "L"; + valueString = valueString[..^3]; + valueSuffix = "L"; } else if ( valueString.EndsWith("ull", StringComparison.OrdinalIgnoreCase) || valueString.EndsWith("llu", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^3] + "UL"; + valueString = valueString[..^3]; + valueSuffix = "UL"; } else if (valueString.EndsWith("ll", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^2] + "L"; + valueString = valueString[..^2]; + valueSuffix = "L"; } else if ( valueString.EndsWith("ul", StringComparison.OrdinalIgnoreCase) || valueString.EndsWith("lu", StringComparison.OrdinalIgnoreCase)) { - valueString = valueString[0..^2] + "U"; + valueString = valueString[..^2]; + valueSuffix = "U"; } else if (valueString.EndsWith('u') || valueString.EndsWith('U')) { - valueString = valueString[0..^1] + "U"; + valueString = valueString[..^1]; + valueSuffix = "U"; } else if (valueString.EndsWith('l') || valueString.EndsWith('L')) { - valueString = valueString[0..^1]; + valueString = valueString[..^1]; } var outputBuilder = StartCSharpCode(); outputBuilder.Write(valueString); + outputBuilder.Write(valueSuffix); StopCSharpCode(); } private void VisitLabelStmt(LabelStmt labelStmt) { var outputBuilder = StartCSharpCode(); - - outputBuilder.Write(labelStmt.Decl.Name); - outputBuilder.WriteLine(':'); + outputBuilder.WriteLabel(labelStmt.Decl.Name); outputBuilder.WriteIndentation(); Visit(labelStmt.SubStmt); @@ -2128,7 +2228,27 @@ private void VisitReturnStmt(ReturnStmt returnStmt) outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); outputBuilder.Write('('); outputBuilder.Write(referenceTypeName); - outputBuilder.Write(")Unsafe.AsPointer(ref this)"); + outputBuilder.Write(")Unsafe.AsPointer("); + + if (referenceType.IsLocalConstQualified) + { + if (!_config.GenerateLatestCode) + { + outputBuilder.Write("ref Unsafe.AsRef("); + } + + outputBuilder.Write("in this"); + + if (!_config.GenerateLatestCode) + { + outputBuilder.Write(')'); + } + } + else + { + outputBuilder.Write("ref this"); + } + outputBuilder.Write(')'); StopCSharpCode(); return; @@ -2555,7 +2675,7 @@ private void VisitStmt(Stmt stmt) } // case CX_StmtClass_NoInitExpr: - // case CX_StmtClass_OMPArraySectionExpr: + // case CX_StmtClass_ArraySectionExpr: // case CX_StmtClass_ObjCArrayLiteral: // case CX_StmtClass_ObjCAvailabilityCheckExpr: // case CX_StmtClass_ObjCBoolLiteralExpr: @@ -2731,7 +2851,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral) case CX_SLK_Ordinary: case CX_SLK_UTF8: { - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { outputBuilder.Write('"'); outputBuilder.Write(EscapeString(stringLiteral.String)); @@ -2789,7 +2909,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral) case CX_SLK_UTF32: { - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.Write('['); } @@ -2810,7 +2930,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral) outputBuilder.Write("0x00000000"); - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.Write(']'); } @@ -2944,12 +3064,12 @@ private void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr unaryExprOrT { if ((parentType.Handle.SizeOf == 8) && IsPrevContextDecl(out var varDecl, out _)) { - var cursorName = GetCursorName(varDecl); + var cursorName = GetCursorName(varDecl).AsSpan(); if (cursorName.StartsWith("ClangSharpMacro_", StringComparison.Ordinal)) { cursorName = cursorName["ClangSharpMacro_".Length..]; - parentTypeIsVariableSized |= _config.WithTypes.TryGetValue(cursorName, out var remappedTypeName) && (remappedTypeName.Equals("int", StringComparison.Ordinal) || remappedTypeName.Equals("uint", StringComparison.Ordinal)); + parentTypeIsVariableSized |= _config._withTypes.GetAlternateLookup>().TryGetValue(cursorName, out var remappedTypeName) && (remappedTypeName.Equals("int", StringComparison.Ordinal) || remappedTypeName.Equals("uint", StringComparison.Ordinal)); } } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index d3a32d63..01eb5810 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; @@ -15,17 +16,17 @@ using ClangSharp.Interop; using ClangSharp.XML; using static ClangSharp.Interop.CX_AttrKind; -using static ClangSharp.Interop.CXBinaryOperatorKind; using static ClangSharp.Interop.CX_CXXAccessSpecifier; using static ClangSharp.Interop.CX_StmtClass; using static ClangSharp.Interop.CX_UnaryExprOrTypeTrait; -using static ClangSharp.Interop.CXUnaryOperatorKind; +using static ClangSharp.Interop.CXBinaryOperatorKind; using static ClangSharp.Interop.CXCallingConv; using static ClangSharp.Interop.CXDiagnosticSeverity; using static ClangSharp.Interop.CXEvalResultKind; using static ClangSharp.Interop.CXTemplateArgumentKind; using static ClangSharp.Interop.CXTranslationUnit_Flags; using static ClangSharp.Interop.CXTypeKind; +using static ClangSharp.Interop.CXUnaryOperatorKind; namespace ClangSharp; @@ -37,8 +38,8 @@ public sealed partial class PInvokeGenerator : IDisposable private static readonly string[] s_doubleColonSeparator = ["::"]; private static readonly char[] s_doubleQuoteSeparator = ['"']; - private const string ExpectedClangVersion = "version 18.1"; - private const string ExpectedClangSharpVersion = "version 18.1"; + private const string ExpectedClangVersion = "version 20.1"; + private const string ExpectedClangSharpVersion = "version 20.1"; private readonly CXIndex _index; private readonly OutputBuilderFactory _outputBuilderFactory; @@ -61,6 +62,7 @@ public sealed partial class PInvokeGenerator : IDisposable private readonly Dictionary _topLevelClassIsUnsafe; private readonly Dictionary> _topLevelClassUsings; private readonly Dictionary> _topLevelClassAttributes; + private readonly Dictionary _fileContents; private readonly HashSet _topLevelClassNames; private readonly HashSet _usedRemappings; private readonly string _placeholderMacroType; @@ -136,30 +138,31 @@ public PInvokeGenerator(PInvokeGeneratorConfiguration config, Func(StringComparer.Ordinal); _diagnostics = []; _context = new LinkedList<(Cursor, object?)>(); - _uuidsToGenerate = []; - _generatedUuids = []; + _uuidsToGenerate = new Dictionary(StringComparer.Ordinal); + _generatedUuids = new HashSet(StringComparer.Ordinal); _cursorNames = []; _cursorQualifiedNames = []; _typeNames = []; - _allValidNameRemappings = new Dictionary>() { + _allValidNameRemappings = new Dictionary>(QualifiedNameComparer.Default) { ["intptr_t"] = ["IntPtr", "nint"], ["ptrdiff_t"] = ["IntPtr", "nint"], ["size_t"] = ["UIntPtr", "nuint"], ["uintptr_t"] = ["UIntPtr", "nuint"], ["_GUID"] = ["Guid"], }; - _traversedValidNameRemappings = []; + _traversedValidNameRemappings = new Dictionary>(StringComparer.Ordinal); _overloadIndices = []; _isExcluded = []; - _topLevelClassHasGuidMember = []; - _topLevelClassIsUnsafe = []; - _topLevelClassNames = []; - _topLevelClassAttributes = []; - _topLevelClassUsings = []; - _usedRemappings = []; + _topLevelClassHasGuidMember = new Dictionary(StringComparer.Ordinal); + _topLevelClassIsUnsafe = new Dictionary(StringComparer.Ordinal); + _topLevelClassNames = new HashSet(StringComparer.Ordinal); + _topLevelClassAttributes = new Dictionary>(StringComparer.Ordinal); + _fileContents = []; + _topLevelClassUsings = new Dictionary>(StringComparer.Ordinal); + _usedRemappings = new HashSet(StringComparer.Ordinal); _filePath = ""; _clangCommandLineArgs = []; _placeholderMacroType = GetPlaceholderMacroType(); @@ -212,8 +215,8 @@ public void Close() Stream? stream = null; Stream? testStream = null; - var methodClassOutputBuilders = new Dictionary(); - var methodClassTestOutputBuilders = new Dictionary(); + var methodClassOutputBuilders = new Dictionary(StringComparer.Ordinal); + var methodClassTestOutputBuilders = new Dictionary(StringComparer.Ordinal); var emitNamespaceDeclaration = true; var leaveStreamOpen = false; @@ -1409,7 +1412,7 @@ static void GenerateTransparentStructs(PInvokeGenerator generator, Stream? strea sw.Write(indentString); sw.WriteLine(" {"); sw.Write(indentString); - sw.Write(" if (obj is "); + sw.Write(" if (obj is "); sw.Write(name); sw.WriteLine(" other)"); sw.Write(indentString); @@ -1697,14 +1700,8 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s { if (_config.GenerateMacroBindings) { - var translationUnitHandle = translationUnit.Handle; - - var file = translationUnitHandle.GetFile(_filePath); - var fileContents = translationUnitHandle.GetFileContents(file, out var size); var fileContentsBuilder = _fileContentsBuilder; - _ = fileContentsBuilder.Append(Encoding.UTF8.GetString(fileContents)); - foreach (var cursor in translationUnit.TranslationUnitDecl.CursorChildren) { if (cursor is PreprocessedEntity preprocessedEntity) @@ -1716,7 +1713,10 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s var unsavedFileContents = fileContentsBuilder.ToString(); _ = fileContentsBuilder.Clear(); - using var unsavedFile = CXUnsavedFile.Create(_filePath, unsavedFileContents); + var translationUnitHandle = translationUnit.Handle; + var file = translationUnitHandle.GetFile(_filePath); + + using var unsavedFile = CXUnsavedFile.Create(_filePath, translationUnitHandle, file, unsavedFileContents); var unsavedFiles = new CXUnsavedFile[] { unsavedFile }; translationFlags = _translationFlags & ~CXTranslationUnit_DetailedPreprocessingRecord; @@ -1734,53 +1734,61 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s { foreach (var kvp in _traversedValidNameRemappings) { - var name = kvp.Key; + var name = kvp.Key.AsSpan(); var remappings = kvp.Value; - if (name.Contains('<', StringComparison.OrdinalIgnoreCase)) + if (name.Contains('<')) { var parts = name.Split('<'); - if (parts.Length >= 2) + if (parts.MoveNext()) { - name = parts[0]; + var part = parts.Current; + + if (parts.MoveNext()) + { + name = name[part]; + } } } - if (!_config.RemappedNames.TryGetValue(name, out _)) + var remappedNamesLookup = _config._remappedNames.GetAlternateLookup>(); + + if (!remappedNamesLookup.TryGetValue(name, out _)) { - var addDiag = false; + var addDiag = true; - var altName = name; var smlName = name; + var lastSeparatorIndex = smlName.LastIndexOf("::", StringComparison.Ordinal); - if (name.Contains("::", StringComparison.Ordinal)) + if (lastSeparatorIndex != -1) { - altName = name.Replace("::", ".", StringComparison.Ordinal); - smlName = altName.Split('.')[^1]; + smlName = smlName[(lastSeparatorIndex + 2)..]; + addDiag = false; } - else if (name.Contains('.', StringComparison.Ordinal)) + + lastSeparatorIndex = smlName.LastIndexOf('.'); + + if (lastSeparatorIndex != -1) { - altName = name.Replace(".", "::", StringComparison.Ordinal); - smlName = altName.Split("::")[^1]; + smlName = smlName[(lastSeparatorIndex + 1)..]; + addDiag = false; } - else + + if (!addDiag && !remappedNamesLookup.TryGetValue(smlName, out _)) { addDiag = true; } - if (!addDiag && !_config.RemappedNames.TryGetValue(altName, out _)) + if (addDiag) { - if (!_config.RemappedNames.TryGetValue(smlName, out _)) + var remappingsLookup = remappings.GetAlternateLookup>(); + + if (!remappingsLookup.Contains(name) && !remappingsLookup.Contains(smlName)) { - addDiag = true; + AddDiagnostic(DiagnosticLevel.Info, $"Potential missing remapping '{name}'. {GetFoundRemappingString(name, remappings)}"); } } - - if (addDiag && !remappings.Contains(altName) && !remappings.Contains(smlName)) - { - AddDiagnostic(DiagnosticLevel.Info, $"Potential missing remapping '{name}'. {GetFoundRemappingString(name, remappings)}"); - } } } @@ -1789,34 +1797,32 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s var name = kvp.Key; var remappings = kvp.Value; - if (_config.RemappedNames.TryGetValue(name, out var remappedName) && !remappings.Contains(remappedName) && (name != remappedName) && !_config.ForceRemappedNames.Contains(name)) + var remappedNamesLookup = _config._remappedNames.GetAlternateLookup>(); + + if (remappedNamesLookup.TryGetValue(name, out var remappedName) && !remappings.Contains(remappedName) && (name != remappedName) && !_config.ForceRemappedNames.Contains(name)) { - var addDiag = false; + var addDiag = true; - var altName = name; var smlName = name; + var lastSeparatorIndex = smlName.LastIndexOf("::", StringComparison.Ordinal); - if (name.Contains("::", StringComparison.Ordinal)) + if (lastSeparatorIndex != -1) { - altName = name.Replace("::", ".", StringComparison.Ordinal); - smlName = altName.Split('.')[^1]; + smlName = smlName[(lastSeparatorIndex + 2)..]; + addDiag = false; } - else if (name.Contains('.', StringComparison.Ordinal)) - { - altName = name.Replace(".", "::", StringComparison.Ordinal); - smlName = altName.Split("::")[^1]; - } - else + + lastSeparatorIndex = smlName.LastIndexOf('.'); + + if (lastSeparatorIndex != -1) { - addDiag = true; + smlName = smlName[(lastSeparatorIndex + 1)..]; + addDiag = false; } - if (!addDiag && _config.RemappedNames.TryGetValue(altName, out remappedName) && !remappings.Contains(remappedName) && (altName != remappedName) && !_config.ForceRemappedNames.Contains(altName)) + if (!addDiag && remappedNamesLookup.TryGetValue(smlName, out remappedName) && !remappings.Contains(remappedName) && (smlName != remappedName) && !_config.ForceRemappedNames.Contains(smlName)) { - if (_config.RemappedNames.TryGetValue(smlName, out remappedName) && !remappings.Contains(remappedName) && (smlName != remappedName) && !_config.ForceRemappedNames.Contains(smlName)) - { - addDiag = true; - } + addDiag = true; } if (addDiag) @@ -1830,34 +1836,32 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s { var remappedName = _config.RemappedNames[name]; - if (!_allValidNameRemappings.ContainsKey(name) && (name != remappedName) && !_config.ForceRemappedNames.Contains(name)) + var allValidNameRemappingsLookup = _allValidNameRemappings.GetAlternateLookup>(); + + if (!allValidNameRemappingsLookup.ContainsKey(name) && (name != remappedName) && !_config.ForceRemappedNames.Contains(name)) { - var addDiag = false; + var addDiag = true; - var altName = name; var smlName = name; + var lastSeparatorIndex = smlName.LastIndexOf("::", StringComparison.Ordinal); - if (name.Contains("::", StringComparison.Ordinal)) - { - altName = name.Replace("::", ".", StringComparison.Ordinal); - smlName = altName.Split('.')[^1]; - } - else if (name.Contains('.', StringComparison.Ordinal)) + if (lastSeparatorIndex != -1) { - altName = name.Replace(".", "::", StringComparison.Ordinal); - smlName = altName.Split("::")[^1]; + smlName = smlName[(lastSeparatorIndex + 2)..]; + addDiag = false; } - else + + lastSeparatorIndex = smlName.LastIndexOf('.'); + + if (lastSeparatorIndex != -1) { - addDiag = true; + smlName = smlName[(lastSeparatorIndex + 1)..]; + addDiag = false; } - if (!addDiag && !_allValidNameRemappings.ContainsKey(altName) && (altName != remappedName) && !_config.ForceRemappedNames.Contains(altName)) + if (!addDiag && !allValidNameRemappingsLookup.ContainsKey(smlName) && (smlName != remappedName) && !_config.ForceRemappedNames.Contains(smlName)) { - if (!_allValidNameRemappings.ContainsKey(smlName) && (smlName != remappedName) && !_config.ForceRemappedNames.Contains(smlName)) - { - addDiag = true; - } + addDiag = true; } if (addDiag) @@ -1867,62 +1871,71 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s } } - static string GetFoundRemappingString(string name, HashSet remappings) + static ReadOnlySpan GetFoundRemappingString(ReadOnlySpan name, HashSet remappings) { - var recommendedRemapping = ""; + var recommendedRemappingString = ""; + var recommendedRemapping = recommendedRemappingString.AsSpan(); if (remappings.Count == 1) { - recommendedRemapping = remappings.Single(); + recommendedRemappingString = remappings.Single(); + recommendedRemapping = recommendedRemappingString; } - if (string.IsNullOrEmpty(recommendedRemapping) && name.StartsWith('_')) + var remappingsLookup = remappings.GetAlternateLookup>(); + + if (recommendedRemapping.IsWhiteSpace() && name.StartsWith('_')) { var remapping = name[1..]; - if (remappings.Contains(remapping)) + if (remappingsLookup.Contains(remapping)) { recommendedRemapping = remapping; + recommendedRemappingString = null; } } - if (string.IsNullOrEmpty(recommendedRemapping) && name.StartsWith("tag", StringComparison.Ordinal)) + if (recommendedRemapping.IsWhiteSpace() && name.StartsWith("tag", StringComparison.Ordinal)) { var remapping = name[3..]; - if (remappings.Contains(remapping)) + if (remappingsLookup.Contains(remapping)) { recommendedRemapping = remapping; + recommendedRemappingString = null; } } - if (string.IsNullOrEmpty(recommendedRemapping) && name.EndsWith('_')) + if (recommendedRemapping.IsWhiteSpace() && name.EndsWith('_')) { - var remapping = name[0..^1]; + var remapping = name[..^1]; - if (remappings.Contains(remapping)) + if (remappingsLookup.Contains(remapping)) { recommendedRemapping = remapping; + recommendedRemappingString = null; } } - if (string.IsNullOrEmpty(recommendedRemapping) && name.EndsWith("tag", StringComparison.Ordinal)) + if (recommendedRemapping.IsWhiteSpace() && name.EndsWith("tag", StringComparison.Ordinal)) { - var remapping = name[0..^3]; + var remapping = name[..^3]; - if (remappings.Contains(remapping)) + if (remappingsLookup.Contains(remapping)) { recommendedRemapping = remapping; + recommendedRemappingString = null; } } - if (string.IsNullOrEmpty(recommendedRemapping)) + if (recommendedRemapping.IsWhiteSpace()) { - var remapping = name.ToUpperInvariant(); + var remapping = name.ToString().ToUpperInvariant(); - if (remappings.Contains(remapping)) + if (remappingsLookup.Contains(remapping)) { - recommendedRemapping = remapping; + recommendedRemappingString = remapping; + recommendedRemapping = recommendedRemappingString; } } @@ -1930,7 +1943,7 @@ static string GetFoundRemappingString(string name, HashSet remappings) var remainingRemappings = (IEnumerable)remappings; var remainingString = "Found"; - if (!string.IsNullOrEmpty(recommendedRemapping)) + if (!recommendedRemapping.IsWhiteSpace()) { result += $"Recommended remapping: '{name}={recommendedRemapping}'."; @@ -1941,7 +1954,7 @@ static string GetFoundRemappingString(string name, HashSet remappings) else { result += ' '; - remainingRemappings = remappings.Except([recommendedRemapping]); + remainingRemappings = remappings.Except([recommendedRemappingString ?? recommendedRemapping.ToString()]); remainingString = "Other"; } } @@ -2036,9 +2049,9 @@ private void CloseOutputBuilder(Stream stream, IOutputBuilder outputBuilder, boo if (isMethodClass) { - var nonTestName = outputBuilder.IsTestOutput ? outputBuilder.Name[0..^5] : outputBuilder.Name; + var nonTestName = outputBuilder.IsTestOutput ? outputBuilder.Name.AsSpan()[..^5] : outputBuilder.Name; - if (_topLevelClassUsings.TryGetValue(nonTestName, out var withUsings)) + if (_topLevelClassUsings.GetAlternateLookup>().TryGetValue(nonTestName, out var withUsings)) { foreach (var withUsing in withUsings) { @@ -2101,17 +2114,17 @@ private void CloseOutputBuilder(Stream stream, IOutputBuilder outputBuilder, boo } } - void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) + void ForCSharp(CSharpOutputBuilder outputBuilder) { - var indentationString = csharpOutputBuilder.IndentationString; - var nonTestName = outputBuilder.IsTestOutput ? outputBuilder.Name[0..^5] : outputBuilder.Name; + var indentationString = outputBuilder.IndentationString; + var nonTestName = outputBuilder.IsTestOutput ? outputBuilder.Name.AsSpan()[..^5] : outputBuilder.Name; if (emitNamespaceDeclaration) { sw.Write("namespace "); sw.Write(GetNamespace(nonTestName)); - if (csharpOutputBuilder.IsTestOutput) + if (outputBuilder.IsTestOutput) { sw.Write(".UnitTests"); } @@ -2135,7 +2148,7 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) if (isMethodClass) { - var isTopLevelStruct = _config.WithTypes.TryGetValue(nonTestName, out var withType) && withType.Equals("struct", StringComparison.Ordinal); + var isTopLevelStruct = _config._withTypes.GetAlternateLookup>().TryGetValue(nonTestName, out var withType) && withType.Equals("struct", StringComparison.Ordinal); if (outputBuilder.IsTestOutput) { @@ -2156,7 +2169,7 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) sw.WriteLine("."); } - if (_topLevelClassAttributes.TryGetValue(nonTestName, out var withAttributes)) + if (_topLevelClassAttributes.GetAlternateLookup>().TryGetValue(nonTestName, out var withAttributes)) { if (withAttributes.Count != 0) { @@ -2184,7 +2197,7 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) sw.Write("static "); } - if ((_topLevelClassIsUnsafe.TryGetValue(nonTestName, out var isUnsafe) && isUnsafe) || (outputBuilder.IsTestOutput && isTopLevelStruct)) + if ((_topLevelClassIsUnsafe.GetAlternateLookup>().TryGetValue(nonTestName, out var isUnsafe) && isUnsafe) || (outputBuilder.IsTestOutput && isTopLevelStruct)) { sw.Write("unsafe "); } @@ -2211,15 +2224,15 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) sw.Write(indentationString); sw.Write('{'); - if ((!outputBuilder.IsTestOutput && !isTopLevelStruct) || !string.IsNullOrEmpty(csharpOutputBuilder.Contents.First())) + if ((!outputBuilder.IsTestOutput && !isTopLevelStruct) || !string.IsNullOrEmpty(outputBuilder.Contents.First())) { sw.WriteLine(); } - indentationString += csharpOutputBuilder.IndentationString; + indentationString += outputBuilder.IndentationString; } - foreach (var line in csharpOutputBuilder.Contents) + foreach (var line in outputBuilder.Contents) { if (string.IsNullOrWhiteSpace(line)) { @@ -2234,7 +2247,7 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) if (isMethodClass) { - indentationString = indentationString[..^csharpOutputBuilder.IndentationString.Length]; + indentationString = indentationString[..^outputBuilder.IndentationString.Length]; sw.Write(indentationString); sw.WriteLine('}'); @@ -2246,7 +2259,7 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) } } - void ForXml(XmlOutputBuilder xmlOutputBuilder) + void ForXml(XmlOutputBuilder outputBuilder) { const string Indent = " "; var indentationString = Indent; @@ -2255,7 +2268,7 @@ void ForXml(XmlOutputBuilder xmlOutputBuilder) { sw.Write(indentationString); sw.Write(""); } @@ -2265,10 +2278,10 @@ void ForXml(XmlOutputBuilder xmlOutputBuilder) { sw.Write(indentationString); sw.Write(" value.Replace(@"\0", "\0", private AccessSpecifier GetAccessSpecifier(NamedDecl namedDecl, bool matchStar) { - if (!TryGetRemappedValue(namedDecl, _config.WithAccessSpecifiers, out var accessSpecifier, matchStar) || (accessSpecifier == AccessSpecifier.None)) + if (!TryGetRemappedValue(namedDecl, _config._withAccessSpecifiers, out var accessSpecifier, matchStar) || (accessSpecifier == AccessSpecifier.None)) { switch (namedDecl.Access) { @@ -2629,7 +2642,7 @@ private CallConv GetCallingConvention(Cursor? cursor, Cursor? context, Type type if (cursor is NamedDecl namedDecl) { - if (TryGetRemappedValue(namedDecl, _config.WithCallConvs, out var callConv, matchStar: true)) + if (TryGetRemappedValue(namedDecl, _config._withCallConvs, out var callConv, matchStar: true)) { if (Enum.TryParse(callConv, true, out var remappedCallingConvention)) { @@ -2773,22 +2786,26 @@ private CallConv GetCallingConvention(Cursor? cursor, Cursor? context, Type type private string GetCursorName(NamedDecl namedDecl) { - if (!_cursorNames.TryGetValue(namedDecl, out var name)) + if (!_cursorNames.TryGetValue(namedDecl, out var nameString)) { - name = namedDecl.Name.NormalizePath(); + nameString = namedDecl.Name.NormalizePath(); + var name = nameString.AsSpan(); // strip the prefix if (name.StartsWith("enum ", StringComparison.Ordinal)) { name = name[5..]; + nameString = null; } else if (name.StartsWith("struct ", StringComparison.Ordinal)) { name = name[7..]; + nameString = null; } else if (name.StartsWith("union ", StringComparison.Ordinal)) { name = name[6..]; + nameString = null; } var anonymousNameStartIndex = name.IndexOf("::(", StringComparison.Ordinal); @@ -2797,21 +2814,26 @@ private string GetCursorName(NamedDecl namedDecl) { anonymousNameStartIndex += 2; name = name[anonymousNameStartIndex..]; + nameString = null; } if (namedDecl is CXXConstructorDecl cxxConstructorDecl) { var parent = cxxConstructorDecl.Parent; Debug.Assert(parent is not null); - name = GetCursorName(parent); + + nameString = GetCursorName(parent); + name = nameString; } else if (namedDecl is CXXDestructorDecl cxxDestructorDecl) { var parent = cxxDestructorDecl.Parent; Debug.Assert(parent is not null); - name = $"~{GetCursorName(parent)}"; + + nameString = $"~{GetCursorName(parent)}"; + name = nameString; } - else if (string.IsNullOrWhiteSpace(name) || name.StartsWith('(')) + else if (name.IsWhiteSpace() || name.StartsWith('(')) { #if DEBUG if (name.StartsWith('(')) @@ -2829,17 +2851,20 @@ private string GetCursorName(NamedDecl namedDecl) if (namedDecl is TypeDecl typeDecl) { - name = (typeDecl is TagDecl tagDecl) && tagDecl.Handle.IsAnonymous - ? GetAnonymousName(tagDecl, tagDecl.TypeForDecl.KindSpelling) - : GetTypeName(namedDecl, context: null, type: typeDecl.TypeForDecl, ignoreTransparentStructsWhereRequired: false, isTemplate: false, nativeTypeName: out _); + nameString = (typeDecl is TagDecl tagDecl) && tagDecl.Handle.IsAnonymous + ? GetAnonymousName(tagDecl, tagDecl.TypeForDecl.KindSpelling) + : GetTypeName(namedDecl, context: null, type: typeDecl.TypeForDecl, ignoreTransparentStructsWhereRequired: false, isTemplate: false, nativeTypeName: out _); + name = nameString; } else if (namedDecl is ParmVarDecl) { - name = "param"; + nameString = "param"; + name = nameString; } else if (namedDecl is FieldDecl fieldDecl) { - name = GetAnonymousName(fieldDecl, fieldDecl.CursorKindSpelling); + nameString = GetAnonymousName(fieldDecl, fieldDecl.CursorKindSpelling); + name = nameString; } else { @@ -2847,11 +2872,12 @@ private string GetCursorName(NamedDecl namedDecl) } } - _cursorNames[namedDecl] = name; + nameString ??= name.ToString(); + _cursorNames[namedDecl] = nameString; } - Debug.Assert(!string.IsNullOrWhiteSpace(name)); - return name; + Debug.Assert(!string.IsNullOrWhiteSpace(nameString)); + return nameString; } private string GetCursorQualifiedName(NamedDecl namedDecl, bool truncateParameters = false) @@ -3156,15 +3182,6 @@ private string GetRemappedCursorName(NamedDecl namedDecl, out string nativeTypeN return remappedName; } - name = name.Replace("::", ".", StringComparison.Ordinal); - remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); - - if (wasRemapped) - { - return remappedName; - } - - name = GetCursorQualifiedName(namedDecl, truncateParameters: true); remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); @@ -3173,14 +3190,6 @@ private string GetRemappedCursorName(NamedDecl namedDecl, out string nativeTypeN return remappedName; } - name = name.Replace("::", ".", StringComparison.Ordinal); - remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); - - if (wasRemapped) - { - return remappedName; - } - name = GetCursorName(namedDecl); remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); @@ -3201,7 +3210,7 @@ private string GetRemappedCursorName(NamedDecl namedDecl, out string nativeTypeN } else if ((namedDecl is FieldDecl fieldDecl) && name.StartsWith("__AnonymousFieldDecl_", StringComparison.Ordinal)) { - if (fieldDecl.Type.AsCXXRecordDecl?.IsAnonymous == true) + if (fieldDecl.Type.AsCXXRecordDecl?.IsAnonymousStructOrUnion == true) { // For fields of anonymous types, use the name of the type but clean off the type // kind tag at the end. @@ -3233,12 +3242,65 @@ private string GetRemappedCursorName(NamedDecl namedDecl, out string nativeTypeN return remappedName; } + private static int GetAnonymousRecordIndex(RecordDecl recordDecl, RecordDecl parentRecordDecl) + { + var index = -1; + var parentAnonRecordCount = parentRecordDecl.AnonymousRecords.Count; + + if (parentAnonRecordCount != 0) + { + index = parentRecordDecl.AnonymousRecords.IndexOf(recordDecl); + + if (index != -1) + { + if (parentAnonRecordCount > 1) + { + index++; + } + + if (parentRecordDecl.Parent is RecordDecl grandparentRecordDecl) + { + var parentIndex = GetAnonymousRecordIndex(parentRecordDecl, grandparentRecordDecl); + + // We can't have the nested anonymous record have the same name as the parent + // so skip that index and just go one higher instead. This could still conflict + // with another anonymous record at a different level, but that is less likely + // and will still be unambiguous in total. + + if ((parentIndex == index) || ((parentIndex > 0) && (index > parentIndex))) + { + if (recordDecl.IsUnion == parentRecordDecl.IsUnion) + { + index++; + } + } + } + } + } + + return index; + } + private string GetRemappedNameForAnonymousRecord(RecordDecl recordDecl) { if (recordDecl.Parent is RecordDecl parentRecordDecl) { var remappedNameBuilder = new StringBuilder(); - var matchingField = parentRecordDecl.Fields.Where((fieldDecl) => fieldDecl.Type.CanonicalType == recordDecl.TypeForDecl.CanonicalType).FirstOrDefault(); + var matchingField = null as FieldDecl; + + if (!recordDecl.IsAnonymousStructOrUnion) + { + matchingField = parentRecordDecl.Fields.Where((fieldDecl) => { + var fieldType = fieldDecl.Type.CanonicalType; + + if (fieldType is ArrayType arrayType) + { + fieldType = arrayType.ElementType.CanonicalType; + } + + return fieldType == recordDecl.TypeForDecl.CanonicalType; + }).FirstOrDefault(); + } if ((matchingField is not null) && !matchingField.IsAnonymousField) { @@ -3249,28 +3311,11 @@ private string GetRemappedNameForAnonymousRecord(RecordDecl recordDecl) { _ = remappedNameBuilder.Append("_Anonymous"); - // If there is more than one anonymous type, then add a numeral to differentiate. - if (parentRecordDecl.AnonymousRecords.Count > 1) - { - var index = parentRecordDecl.AnonymousRecords.IndexOf(recordDecl) + 1; - Debug.Assert(index > 0); - _ = remappedNameBuilder.Append(index); - } + var index = GetAnonymousRecordIndex(recordDecl, parentRecordDecl); - // C# doesn't allow a nested type to have the same name as the parent, so if the - // parent is also anonymous, add the nesting depth as a way to avoid conflicts with - // the parent's name. - if (parentRecordDecl.IsAnonymous) + if (index != 0) { - var depth = 1; - var currentParent = parentRecordDecl.Parent; - while ((currentParent is RecordDecl currentParentRecordDecl) && currentParentRecordDecl.IsAnonymous) - { - depth++; - currentParent = currentParentRecordDecl.Parent; - } - _ = remappedNameBuilder.Append('_'); - _ = remappedNameBuilder.Append(depth); + _ = remappedNameBuilder.Append(index); } } @@ -3290,7 +3335,9 @@ private string GetRemappedName(string name, Cursor? cursor, bool tryRemapOperato private string GetRemappedName(string name, Cursor? cursor, bool tryRemapOperatorName, out bool wasRemapped, bool skipUsing, bool skipUsingIfNotRemapped) { - if (_config.RemappedNames.TryGetValue(name, out var remappedName)) + var remappedNamesLookup = _config._remappedNames.GetAlternateLookup>(); + + if (remappedNamesLookup.TryGetValue(name, out var remappedName)) { wasRemapped = true; _ = _usedRemappings.Add(name); @@ -3299,13 +3346,13 @@ private string GetRemappedName(string name, Cursor? cursor, bool tryRemapOperato if (name.StartsWith("const ", StringComparison.Ordinal)) { - var tmpName = name[6..]; + var tmpName = name.AsSpan()[6..]; - if (_config.RemappedNames.TryGetValue(tmpName, out remappedName)) + if (remappedNamesLookup.TryGetValue(tmpName, out remappedName)) { wasRemapped = true; - _ = _usedRemappings.Add(tmpName); + _ = _usedRemappings.Add(tmpName.ToString()); return AddUsingDirectiveIfNeeded(_outputBuilder, remappedName, skipUsing); } } @@ -3363,38 +3410,32 @@ private string GetRemappedTypeName(Cursor? cursor, Cursor? context, Type type, o if (!wasRemapped) { - nameToCheck = nameToCheck.Replace("::", ".", StringComparison.Ordinal); - remappedName = GetRemappedName(nameToCheck, cursor, tryRemapOperatorName: false, out wasRemapped, skipUsing, skipUsingIfNotRemapped: true); + nameToCheck = name; + remappedName = GetRemappedName(nameToCheck, cursor, tryRemapOperatorName: false, out wasRemapped, skipUsing); if (!wasRemapped) { - nameToCheck = name; - remappedName = GetRemappedName(nameToCheck, cursor, tryRemapOperatorName: false, out wasRemapped, skipUsing); - - if (!wasRemapped) + if (IsTypeConstantOrIncompleteArray(cursor, type, out var arrayType) && IsType(cursor, arrayType.ElementType)) { - if (IsTypeConstantOrIncompleteArray(cursor, type, out var arrayType) && IsType(cursor, arrayType.ElementType)) - { - type = arrayType.ElementType; - } + type = arrayType.ElementType; + } - if (IsType(cursor, type, out var recordType) && remappedName.StartsWith("__AnonymousRecord_", StringComparison.Ordinal)) - { - var recordDecl = recordType.Decl; - remappedName = GetRemappedNameForAnonymousRecord(recordDecl); - } - else if (IsType(cursor, type, out var enumType) && remappedName.StartsWith("__AnonymousEnum_", StringComparison.Ordinal)) - { - remappedName = GetRemappedTypeName(enumType.Decl, context: null, enumType.Decl.IntegerType, out _, skipUsing); - } - else if (cursor is EnumDecl enumDecl) - { - // Even though some types have entries with names like *_FORCE_DWORD or *_FORCE_UINT - // MSVC and Clang both still treat this as "signed" values and thus we don't want - // to specially handle it as uint, as that can break ABI handling on some platforms. + if (IsType(cursor, type, out var recordType) && remappedName.StartsWith("__AnonymousRecord_", StringComparison.Ordinal)) + { + var recordDecl = recordType.Decl; + remappedName = GetRemappedNameForAnonymousRecord(recordDecl); + } + else if (IsType(cursor, type, out var enumType) && remappedName.StartsWith("__AnonymousEnum_", StringComparison.Ordinal)) + { + remappedName = GetRemappedTypeName(enumType.Decl, context: null, enumType.Decl.IntegerType, out _, skipUsing); + } + else if (cursor is EnumDecl enumDecl) + { + // Even though some types have entries with names like *_FORCE_DWORD or *_FORCE_UINT + // MSVC and Clang both still treat this as "signed" values and thus we don't want + // to specially handle it as uint, as that can break ABI handling on some platforms. - WithType(enumDecl, ref remappedName, ref nativeTypeName); - } + WithType(enumDecl, ref remappedName, ref nativeTypeName); } } } @@ -3418,7 +3459,19 @@ private string GetRemappedTypeName(Cursor? cursor, Cursor? context, Type type, o return remappedName; } - private static string GetSourceRangeContents(CXTranslationUnit translationUnit, CXSourceRange sourceRange) + private unsafe ReadOnlySpan GetFileContents(CXTranslationUnit translationUnit, CXFile file) + { + if (!_fileContents.TryGetValue(file, out var fileContentsMetadata)) + { + var fileContents = translationUnit.GetFileContents(file, out _); + fileContentsMetadata = ((nuint)Unsafe.AsPointer(ref MemoryMarshal.GetReference(fileContents)), (uint)fileContents.Length); + _fileContents.Add(file, fileContentsMetadata); + } + + return new ReadOnlySpan((byte*)fileContentsMetadata.Address, (int)fileContentsMetadata.Length); + } + + private string GetSourceRangeContents(CXTranslationUnit translationUnit, CXSourceRange sourceRange) { sourceRange.Start.GetFileLocation(out var startFile, out _, out _, out var startOffset); sourceRange.End.GetFileLocation(out var endFile, out _, out _, out var endOffset); @@ -3428,9 +3481,9 @@ private static string GetSourceRangeContents(CXTranslationUnit translationUnit, return string.Empty; } - var fileContents = translationUnit.GetFileContents(startFile, out _); - fileContents = fileContents.Slice(unchecked((int)startOffset), unchecked((int)(endOffset - startOffset))); - return Encoding.UTF8.GetString(fileContents); + var contents = GetFileContents(translationUnit, startFile); + contents = contents.Slice(unchecked((int)startOffset), unchecked((int)(endOffset - startOffset))); + return Encoding.UTF8.GetString(contents); } private string GetTargetTypeName(Cursor cursor, out string nativeTypeName) @@ -3466,13 +3519,13 @@ private string GetTargetTypeName(Cursor cursor, out string nativeTypeName) else { var type = varDecl.Type; - var cursorName = GetCursorName(varDecl); + var cursorName = GetCursorName(varDecl).AsSpan(); if (cursorName.StartsWith("ClangSharpMacro_", StringComparison.Ordinal)) { cursorName = cursorName["ClangSharpMacro_".Length..]; - if (_config.WithTypes.TryGetValue(cursorName, out targetTypeName)) + if (_config._withTypes.GetAlternateLookup>().TryGetValue(cursorName, out targetTypeName)) { return targetTypeName; } @@ -4586,7 +4639,7 @@ private void GetTypeSize(Cursor cursor, Type type, ref long alignment32, ref lon } private bool HasSuppressGCTransition(Cursor? cursor) - => (cursor is NamedDecl namedDecl) && HasRemapping(namedDecl, _config.WithSuppressGCTransitions); + => (cursor is NamedDecl namedDecl) && HasRemapping(namedDecl, _config._withSuppressGCTransitions); private bool HasBaseField(CXXRecordDecl cxxRecordDecl) { @@ -4608,7 +4661,7 @@ private bool HasBaseField(CXXRecordDecl cxxRecordDecl) private bool HasField(RecordDecl recordDecl) { - var hasField = recordDecl.Fields.Any() || recordDecl.Decls.Any((decl) => (decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymous && HasField(nestedRecordDecl)); + var hasField = recordDecl.Fields.Any() || recordDecl.Decls.Any((decl) => (decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion && HasField(nestedRecordDecl)); if (!hasField && (recordDecl is CXXRecordDecl cxxRecordDecl)) { @@ -4865,9 +4918,7 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue) } } - var dottedQualifiedName = qualifiedName.Replace("::", ".", StringComparison.Ordinal); - - if (_config.ExcludedNames.Contains(qualifiedName) || _config.ExcludedNames.Contains(dottedQualifiedName)) + if (_config.ExcludedNames.Contains(qualifiedName)) { if (_config.LogExclusions) { @@ -4887,9 +4938,7 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue) return true; } - var dottedQualifiedNameWithoutParameters = qualifiedNameWithoutParameters.Replace("::", ".", StringComparison.Ordinal); - - if (_config.ExcludedNames.Contains(qualifiedNameWithoutParameters) || _config.ExcludedNames.Contains(dottedQualifiedNameWithoutParameters) || _config.ExcludedNames.Contains(name)) + if (_config.ExcludedNames.Contains(qualifiedNameWithoutParameters) || _config.ExcludedNames.Contains(name)) { if (_config.LogExclusions) { @@ -4919,9 +4968,7 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue) } if (_config.IncludedNames.Count != 0 && !_config.IncludedNames.Contains(qualifiedName) - && !_config.IncludedNames.Contains(dottedQualifiedName) && !_config.IncludedNames.Contains(qualifiedNameWithoutParameters) - && !_config.IncludedNames.Contains(dottedQualifiedNameWithoutParameters) && !_config.IncludedNames.Contains(name)) { var semanticParentCursor = cursor.SemanticParentCursor; @@ -5159,7 +5206,7 @@ bool IsEmptyRecord(RecordDecl recordDecl) foreach (var decl in recordDecl.Decls) { - if ((decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymous && !IsEmptyRecord(nestedRecordDecl)) + if ((decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion && !IsEmptyRecord(nestedRecordDecl)) { return false; } @@ -5210,9 +5257,7 @@ private bool IsBaseExcluded(CXXRecordDecl cxxRecordDecl, CXXRecordDecl baseCxxRe baseFieldName = GetRemappedName(baseFieldName, cxxBaseSpecifier, tryRemapOperatorName: true, out _, skipUsing: true); var qualifiedName = $"{GetCursorQualifiedName(cxxRecordDecl)}::{baseFieldName}"; - var dottedQualifiedName = qualifiedName.Replace("::", ".", StringComparison.Ordinal); - - return _config.ExcludedNames.Contains(qualifiedName) || _config.ExcludedNames.Contains(dottedQualifiedName); + return _config.ExcludedNames.Contains(qualifiedName); } private bool IsFixedSize(Cursor cursor, Type type) @@ -5350,6 +5395,15 @@ private bool IsPrevContextStmt([MaybeNullWhen(false)] out T cursor, out objec } } + private bool IsReadonly(CXXMethodDecl? cxxMethodDecl) + { + if (cxxMethodDecl is not null) + { + return cxxMethodDecl.IsConst || HasRemapping(cxxMethodDecl, _config._withReadonlys, matchStar: true); + } + return false; + } + private static bool IsStmtAsWritten(Cursor cursor, [MaybeNullWhen(false)] out T value, bool removeParens = false) where T : Stmt { @@ -5536,7 +5590,7 @@ internal bool IsSupportedFixedSizedBufferType(string typeName) case "ulong": { // We want to prefer InlineArray in modern code, as it is safer and supports more features - return !Config.GenerateLatestCode; + return Config.GenerateCompatibleCode; } default: @@ -5803,7 +5857,7 @@ private bool IsUnchecked(string targetTypeName, Stmt stmt) } // case CX_StmtClass_NoInitExpr: - // case CX_StmtClass_OMPArraySectionExpr: + // case CX_StmtClass_ArraySectionExpr: // case CX_StmtClass_ObjCArrayLiteral: // case CX_StmtClass_ObjCAvailabilityCheckExpr: // case CX_StmtClass_ObjCBoolLiteralExpr: @@ -6186,7 +6240,7 @@ private bool IsUnsafe(RecordDecl recordDecl) { return true; } - else if ((decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymous && (IsUnsafe(nestedRecordDecl) || Config.GenerateCompatibleCode)) + else if ((decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion && (IsUnsafe(nestedRecordDecl) || Config.GenerateCompatibleCode)) { return true; } @@ -6473,7 +6527,7 @@ private void StopUsingOutputBuilder() private bool TryGetUuid(RecordDecl recordDecl, out Guid uuid) { - if (TryGetRemappedValue(recordDecl, _config.WithGuids, out var guid)) + if (TryGetRemappedValue(recordDecl, _config._withGuids, out var guid)) { uuid = guid; return true; @@ -6807,7 +6861,7 @@ private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform = var outputBuilder = isTestOutput ? _testOutputBuilder : _outputBuilder; Debug.Assert(outputBuilder is not null); - if (TryGetRemappedValue(namedDecl, _config.WithAttributes, out var attributes, matchStar: true)) + if (TryGetRemappedValue(namedDecl, _config._withAttributes, out var attributes, matchStar: true)) { foreach (var attribute in attributes.Where((a) => !onlySupportedOSPlatform || a.StartsWith("SupportedOSPlatform(", StringComparison.Ordinal))) { @@ -6907,16 +6961,16 @@ private string GetClass(string remappedName, bool disallowPrefixMatch = false) return className; } - private bool TryGetClass(string remappedName, [MaybeNullWhen(false)] out string className, bool disallowPrefixMatch = false) + private bool TryGetClass(ReadOnlySpan remappedName, [MaybeNullWhen(false)] out string className, bool disallowPrefixMatch = false) { - var index = remappedName.IndexOf('*', StringComparison.Ordinal); + var index = remappedName.IndexOf('*'); if (index != -1) { remappedName = remappedName[..index]; } - if (_config.WithClasses.TryGetValue(remappedName, out className)) + if (_config._withClasses.GetAlternateLookup>().TryGetValue(remappedName, out className)) { _ = _topLevelClassNames.Add(className); _ = _topLevelClassNames.Add($"{className}Tests"); @@ -6928,14 +6982,14 @@ private bool TryGetClass(string remappedName, [MaybeNullWhen(false)] out string return false; } - foreach (var withClass in _config.WithClasses) + foreach (var withClass in _config._withClasses) { if (!withClass.Key.EndsWith('*')) { continue; } - var prefix = withClass.Key[0..^1]; + var prefix = withClass.Key.AsSpan()[..^1]; if (remappedName.StartsWith(prefix, StringComparison.Ordinal)) { @@ -6948,7 +7002,7 @@ private bool TryGetClass(string remappedName, [MaybeNullWhen(false)] out string return false; } - private string GetNamespace(string remappedName, NamedDecl? namedDecl = null) + private string GetNamespace(ReadOnlySpan remappedName, NamedDecl? namedDecl = null) { if (!TryGetNamespace(remappedName, out var namespaceName)) { @@ -6965,37 +7019,32 @@ private string GetNamespace(string remappedName, NamedDecl? namedDecl = null) return namespaceName; } - private bool TryGetNamespace(string remappedName, [MaybeNullWhen(false)] out string namespaceName) + private bool TryGetNamespace(ReadOnlySpan remappedName, [MaybeNullWhen(false)] out string namespaceName) { - var index = remappedName.IndexOf('*', StringComparison.Ordinal); + var index = remappedName.IndexOf('*'); if (index != -1) { remappedName = remappedName[..index]; } - return _config.WithNamespaces.TryGetValue(remappedName, out namespaceName); + return _config._withNamespaces.GetAlternateLookup>().TryGetValue(remappedName, out namespaceName); } - private bool GetSetLastError(NamedDecl namedDecl) => HasRemapping(namedDecl, _config.WithSetLastErrors, matchStar: true); + private bool GetSetLastError(NamedDecl namedDecl) => HasRemapping(namedDecl, _config._withSetLastErrors, matchStar: true); - private bool HasRemapping(NamedDecl namedDecl, IReadOnlyCollection entries, bool matchStar = false) + private bool HasRemapping(NamedDecl namedDecl, HashSet entries, bool matchStar = false) { - var name = GetCursorQualifiedName(namedDecl); + var name = GetCursorQualifiedName(namedDecl).AsSpan(); if (name.StartsWith("ClangSharpMacro_", StringComparison.Ordinal)) { name = name["ClangSharpMacro_".Length..]; } - if (entries.Contains(name)) - { - return true; - } - - name = name.Replace("::", ".", StringComparison.Ordinal); + var entriesLookup = entries.GetAlternateLookup>(); - if (entries.Contains(name)) + if (entriesLookup.Contains(name)) { return true; } @@ -7007,14 +7056,7 @@ private bool HasRemapping(NamedDecl namedDecl, IReadOnlyCollection entri name = name["ClangSharpMacro_".Length..]; } - if (entries.Contains(name)) - { - return true; - } - - name = name.Replace("::", ".", StringComparison.Ordinal); - - if (entries.Contains(name)) + if (entriesLookup.Contains(name)) { return true; } @@ -7026,26 +7068,21 @@ private bool HasRemapping(NamedDecl namedDecl, IReadOnlyCollection entri name = name["ClangSharpMacro_".Length..]; } - return entries.Contains(name) || (matchStar && entries.Contains("*")); + return entriesLookup.Contains(name) || (matchStar && entriesLookup.Contains("*")); } - private bool TryGetRemappedValue(NamedDecl namedDecl, IReadOnlyDictionary remappings, [MaybeNullWhen(false)] out T value, bool matchStar = false) + private bool TryGetRemappedValue(NamedDecl namedDecl, Dictionary remappings, [MaybeNullWhen(false)] out T value, bool matchStar = false) { - var name = GetCursorQualifiedName(namedDecl); + var name = GetCursorQualifiedName(namedDecl).AsSpan(); if (name.StartsWith("ClangSharpMacro_", StringComparison.Ordinal)) { name = name["ClangSharpMacro_".Length..]; } - if (remappings.TryGetValue(name, out value)) - { - return true; - } + var remappingsLookup = remappings.GetAlternateLookup>(); - name = name.Replace("::", ".", StringComparison.Ordinal); - - if (remappings.TryGetValue(name, out value)) + if (remappingsLookup.TryGetValue(name, out value)) { return true; } @@ -7057,14 +7094,7 @@ private bool TryGetRemappedValue(NamedDecl namedDecl, IReadOnlyDictionary(NamedDecl namedDecl, IReadOnlyDictionary _excludedNames; - private readonly SortedSet _forceRemappedNames; - private readonly SortedSet _includedNames; - private readonly SortedSet _nativeTypeNamesToStrip; - private readonly SortedSet _withManualImports; - private readonly SortedSet _traversalNames; - private readonly SortedSet _withSetLastErrors; - private readonly SortedSet _withSuppressGCTransitions; - - private readonly SortedDictionary _remappedNames; - private readonly SortedDictionary _withAccessSpecifiers; - private readonly SortedDictionary> _withAttributes; - private readonly SortedDictionary _withCallConvs; - private readonly SortedDictionary _withClasses; - private readonly SortedDictionary _withGuids; - private readonly SortedDictionary _withLengths; - private readonly SortedDictionary _withLibraryPaths; - private readonly SortedDictionary _withNamespaces; - private readonly SortedDictionary _withTransparentStructs; - private readonly SortedDictionary _withTypes; - private readonly SortedDictionary> _withUsings; - private readonly SortedDictionary _withPackings; + internal readonly HashSet _excludedNames; + private readonly HashSet _forceRemappedNames; + private readonly HashSet _includedNames; + private readonly HashSet _nativeTypeNamesToStrip; + private readonly HashSet _withManualImports; + private readonly HashSet _traversalNames; + internal readonly HashSet _withReadonlys; + internal readonly HashSet _withSetLastErrors; + internal readonly HashSet _withSuppressGCTransitions; + + internal readonly Dictionary _remappedNames; + internal readonly Dictionary _withAccessSpecifiers; + internal readonly Dictionary> _withAttributes; + internal readonly Dictionary _withCallConvs; + internal readonly Dictionary _withClasses; + internal readonly Dictionary _withGuids; + internal readonly Dictionary _withLengths; + private readonly Dictionary _withLibraryPaths; + internal readonly Dictionary _withNamespaces; + private readonly Dictionary _withTransparentStructs; + internal readonly Dictionary _withTypes; + internal readonly Dictionary> _withUsings; + internal readonly Dictionary _withPackings; private PInvokeGeneratorConfigurationOptions _options; @@ -81,28 +82,29 @@ public PInvokeGeneratorConfiguration(string language, string languageStandard, s _methodPrefixToStrip = DefaultMethodPrefixToStripValue; _testOutputLocation = DefaultTestOutputLocationValue; - _excludedNames = []; - _forceRemappedNames = []; - _includedNames = []; - _nativeTypeNamesToStrip = []; - _withManualImports = []; - _traversalNames = []; - _withSetLastErrors = []; - _withSuppressGCTransitions = []; - - _remappedNames = []; - _withAccessSpecifiers = []; - _withAttributes = []; - _withCallConvs = []; - _withClasses = []; - _withGuids = []; - _withLengths = []; - _withLibraryPaths = []; - _withNamespaces = []; - _withTransparentStructs = []; - _withTypes = []; - _withUsings = []; - _withPackings = []; + _excludedNames = new HashSet(QualifiedNameComparer.Default); + _forceRemappedNames = new HashSet(QualifiedNameComparer.Default); + _includedNames = new HashSet(QualifiedNameComparer.Default); + _nativeTypeNamesToStrip = new HashSet(StringComparer.Ordinal); + _withManualImports = new HashSet(StringComparer.Ordinal); + _traversalNames = new HashSet(StringComparer.Ordinal); + _withReadonlys = new HashSet(QualifiedNameComparer.Default); + _withSetLastErrors = new HashSet(QualifiedNameComparer.Default); + _withSuppressGCTransitions = new HashSet(QualifiedNameComparer.Default); + + _remappedNames = new Dictionary(QualifiedNameComparer.Default); + _withAccessSpecifiers = new Dictionary(QualifiedNameComparer.Default); + _withAttributes = new Dictionary>(QualifiedNameComparer.Default); + _withCallConvs = new Dictionary(QualifiedNameComparer.Default); + _withClasses = new Dictionary(StringComparer.Ordinal); + _withGuids = new Dictionary(QualifiedNameComparer.Default); + _withLengths = new Dictionary(QualifiedNameComparer.Default); + _withLibraryPaths = new Dictionary(StringComparer.Ordinal); + _withNamespaces = new Dictionary(StringComparer.Ordinal); + _withTransparentStructs = new Dictionary(StringComparer.Ordinal); + _withTypes = new Dictionary(QualifiedNameComparer.Default); + _withUsings = new Dictionary>(QualifiedNameComparer.Default); + _withPackings = new Dictionary(QualifiedNameComparer.Default); if ((outputMode == PInvokeGeneratorOutputMode.Xml) && !options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateMultipleFiles) && (options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateTestsNUnit) || options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateTestsXUnit))) { @@ -516,6 +518,20 @@ public IReadOnlyDictionary WithNamespaces } } + [AllowNull] + public IReadOnlyCollection WithReadonlys + { + get + { + return _withReadonlys; + } + + init + { + AddRange(_withReadonlys, value); + } + } + [AllowNull] public IReadOnlyCollection WithSetLastErrors { @@ -612,7 +628,7 @@ public static AccessSpecifier ConvertStringToAccessSpecifier(string input) : input.Equals("public", StringComparison.OrdinalIgnoreCase) ? AccessSpecifier.Public : AccessSpecifier.None; } - private static void AddRange(SortedDictionary dictionary, IEnumerable>? keyValuePairs) + private static void AddRange(Dictionary dictionary, IEnumerable>? keyValuePairs) { if (keyValuePairs != null) { @@ -625,7 +641,7 @@ private static void AddRange(SortedDictionary dictionary } } - private static void AddRange(SortedDictionary dictionary, IEnumerable>? keyValuePairs, Func convert) + private static void AddRange(Dictionary dictionary, IEnumerable>? keyValuePairs, Func convert) { if (keyValuePairs != null) { @@ -638,7 +654,7 @@ private static void AddRange(SortedDictionary di } } - private static void AddRange(SortedSet hashSet, IEnumerable? keys) + private static void AddRange(HashSet hashSet, IEnumerable? keys) { if (keys != null) { @@ -649,7 +665,7 @@ private static void AddRange(SortedSet hashSet, IEnumerable(SortedSet hashSet, IEnumerable? keys, Func convert) + private static void AddRange(HashSet hashSet, IEnumerable? keys, Func convert) { if (keys != null) { @@ -660,7 +676,7 @@ private static void AddRange(SortedSet hashSet, IEnumera } } - private static void AddRange(SortedSet hashSet, IEnumerable>? keyValuePairs, Func shouldAdd) + private static void AddRange(HashSet hashSet, IEnumerable>? keyValuePairs, Func shouldAdd) { if (keyValuePairs != null) { diff --git a/sources/ClangSharp.PInvokeGenerator/QualifiedNameComparer.cs b/sources/ClangSharp.PInvokeGenerator/QualifiedNameComparer.cs new file mode 100644 index 00000000..820522ac --- /dev/null +++ b/sources/ClangSharp.PInvokeGenerator/QualifiedNameComparer.cs @@ -0,0 +1,105 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace ClangSharp; + +internal class QualifiedNameComparer : IEqualityComparer, IAlternateEqualityComparer, string> +{ + public static readonly QualifiedNameComparer Default = new QualifiedNameComparer(); + + public string Create(ReadOnlySpan alternate) => alternate.ToString(); + + public bool Equals(ReadOnlySpan alternate, string other) => Equals(alternate, other.AsSpan()); + + public static bool Equals(ReadOnlySpan alternate, ReadOnlySpan other) + { + while ((alternate.Length != 0) && (other.Length != 0)) + { + if (alternate.StartsWith("::", StringComparison.Ordinal)) + { + if (other.StartsWith('.')) + { + alternate = alternate[2..]; + other = other[1..]; + } + else + { + return false; + } + } + else if (alternate.StartsWith('.')) + { + if (other.StartsWith("::", StringComparison.Ordinal)) + { + alternate = alternate[1..]; + other = other[2..]; + } + else + { + return false; + } + } + + var prefixLength = alternate.CommonPrefixLength(other); + + if (prefixLength == 0) + { + break; + } + + alternate = alternate[prefixLength..]; + other = other[prefixLength..]; + } + + return (alternate.Length == 0) && (other.Length == 0); + } + + public bool Equals(string? x, string? y) => Equals(x.AsSpan(), y.AsSpan()); + + public int GetHashCode(ReadOnlySpan alternate) + { + var hashCode = new HashCode(); + + while (alternate.Length != 0) + { + var part = alternate; + var separatorLength = 0; + + var colonSeparatorIndex = part.IndexOf("::", StringComparison.Ordinal); + + if (colonSeparatorIndex != -1) + { + part = part[..colonSeparatorIndex]; + separatorLength = 2; + } + + var dotSeparatorIndex = part.IndexOf('.'); + + if (dotSeparatorIndex != -1) + { + part = part[..dotSeparatorIndex]; + separatorLength = 1; + } + + hashCode.Add(string.GetHashCode(part, StringComparison.Ordinal)); + + if (separatorLength != 0) + { + hashCode.Add('.'); + alternate = alternate[(part.Length + separatorLength)..]; + } + else + { + alternate = alternate[part.Length..]; + } + } + + return hashCode.ToHashCode(); + } + + public int GetHashCode([DisallowNull] string obj) => GetHashCode(obj.AsSpan()); +} diff --git a/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs index 4b9ca7a2..6a4a6f4a 100644 --- a/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs @@ -142,6 +142,11 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM _ = _sb.Append(" static=\"true\""); } + if (desc.IsReadOnly) + { + _ = _sb.Append(" readonly=\"true\""); + } + if (desc.IsUnsafe) { _ = _sb.Append(" unsafe=\"true\""); diff --git a/sources/ClangSharp/ClangSharp.csproj b/sources/ClangSharp/ClangSharp.csproj index d5fee39f..919628d5 100644 --- a/sources/ClangSharp/ClangSharp.csproj +++ b/sources/ClangSharp/ClangSharp.csproj @@ -2,14 +2,15 @@ - net8.0 + net10.0 - $(NoWarn);CA1034;CA1040;CA1720 + + $(NoWarn);CA1034;CA1040;CA1720;IDE0130 diff --git a/sources/ClangSharp/Cursors/Attrs/Attr.cs b/sources/ClangSharp/Cursors/Attrs/Attr.cs index 435f3832..95d1bcfb 100644 --- a/sources/ClangSharp/Cursors/Attrs/Attr.cs +++ b/sources/ClangSharp/Cursors/Attrs/Attr.cs @@ -18,371 +18,406 @@ private protected Attr(CXCursor handle) : base(handle, handle.Kind) internal static new Attr Create(CXCursor handle) => handle.AttrKind switch { CX_AttrKind_Invalid => new Attr(handle), - CX_AttrKind_AddressSpace => new TypeAttr(handle), - CX_AttrKind_AnnotateType => new TypeAttr(handle), - CX_AttrKind_ArmIn => new TypeAttr(handle), - CX_AttrKind_ArmInOut => new TypeAttr(handle), - CX_AttrKind_ArmMveStrictPolymorphism => new TypeAttr(handle), - CX_AttrKind_ArmOut => new TypeAttr(handle), - CX_AttrKind_ArmPreserves => new TypeAttr(handle), - CX_AttrKind_ArmStreaming => new TypeAttr(handle), - CX_AttrKind_ArmStreamingCompatible => new TypeAttr(handle), - CX_AttrKind_BTFTypeTag => new TypeAttr(handle), - CX_AttrKind_CmseNSCall => new TypeAttr(handle), - CX_AttrKind_HLSLGroupSharedAddressSpace => new TypeAttr(handle), - CX_AttrKind_HLSLParamModifier => new TypeAttr(handle), - CX_AttrKind_NoDeref => new TypeAttr(handle), - CX_AttrKind_ObjCGC => new TypeAttr(handle), - CX_AttrKind_ObjCInertUnsafeUnretained => new TypeAttr(handle), - CX_AttrKind_ObjCKindOf => new TypeAttr(handle), - CX_AttrKind_OpenCLConstantAddressSpace => new TypeAttr(handle), - CX_AttrKind_OpenCLGenericAddressSpace => new TypeAttr(handle), - CX_AttrKind_OpenCLGlobalAddressSpace => new TypeAttr(handle), - CX_AttrKind_OpenCLGlobalDeviceAddressSpace => new TypeAttr(handle), - CX_AttrKind_OpenCLGlobalHostAddressSpace => new TypeAttr(handle), - CX_AttrKind_OpenCLLocalAddressSpace => new TypeAttr(handle), - CX_AttrKind_OpenCLPrivateAddressSpace => new TypeAttr(handle), - CX_AttrKind_Ptr32 => new TypeAttr(handle), - CX_AttrKind_Ptr64 => new TypeAttr(handle), - CX_AttrKind_SPtr => new TypeAttr(handle), - CX_AttrKind_TypeNonNull => new TypeAttr(handle), - CX_AttrKind_TypeNullUnspecified => new TypeAttr(handle), - CX_AttrKind_TypeNullable => new TypeAttr(handle), - CX_AttrKind_TypeNullableResult => new TypeAttr(handle), - CX_AttrKind_UPtr => new TypeAttr(handle), - CX_AttrKind_WebAssemblyFuncref => new TypeAttr(handle), - CX_AttrKind_CodeAlign => new StmtAttr(handle), - CX_AttrKind_FallThrough => new StmtAttr(handle), - CX_AttrKind_Likely => new StmtAttr(handle), - CX_AttrKind_MustTail => new StmtAttr(handle), - CX_AttrKind_OpenCLUnrollHint => new StmtAttr(handle), - CX_AttrKind_Unlikely => new StmtAttr(handle), - CX_AttrKind_AlwaysInline => new DeclOrStmtAttr(handle), - CX_AttrKind_NoInline => new DeclOrStmtAttr(handle), - CX_AttrKind_NoMerge => new DeclOrStmtAttr(handle), - CX_AttrKind_Suppress => new DeclOrStmtAttr(handle), - CX_AttrKind_AArch64SVEPcs => new InheritableAttr(handle), - CX_AttrKind_AArch64VectorPcs => new InheritableAttr(handle), - CX_AttrKind_AMDGPUKernelCall => new InheritableAttr(handle), - CX_AttrKind_AcquireHandle => new InheritableAttr(handle), - CX_AttrKind_AnyX86NoCfCheck => new InheritableAttr(handle), - CX_AttrKind_CDecl => new InheritableAttr(handle), - CX_AttrKind_FastCall => new InheritableAttr(handle), - CX_AttrKind_IntelOclBicc => new InheritableAttr(handle), - CX_AttrKind_LifetimeBound => new InheritableAttr(handle), - CX_AttrKind_M68kRTD => new InheritableAttr(handle), - CX_AttrKind_MSABI => new InheritableAttr(handle), - CX_AttrKind_NSReturnsRetained => new InheritableAttr(handle), - CX_AttrKind_ObjCOwnership => new InheritableAttr(handle), - CX_AttrKind_Pascal => new InheritableAttr(handle), - CX_AttrKind_Pcs => new InheritableAttr(handle), - CX_AttrKind_PreserveAll => new InheritableAttr(handle), - CX_AttrKind_PreserveMost => new InheritableAttr(handle), - CX_AttrKind_RegCall => new InheritableAttr(handle), - CX_AttrKind_StdCall => new InheritableAttr(handle), - CX_AttrKind_SwiftAsyncCall => new InheritableAttr(handle), - CX_AttrKind_SwiftCall => new InheritableAttr(handle), - CX_AttrKind_SysVABI => new InheritableAttr(handle), - CX_AttrKind_ThisCall => new InheritableAttr(handle), - CX_AttrKind_VectorCall => new InheritableAttr(handle), - CX_AttrKind_SwiftAsyncContext => new ParameterABIAttr(handle), - CX_AttrKind_SwiftContext => new ParameterABIAttr(handle), - CX_AttrKind_SwiftErrorResult => new ParameterABIAttr(handle), - CX_AttrKind_SwiftIndirectResult => new ParameterABIAttr(handle), - CX_AttrKind_Annotate => new InheritableParamAttr(handle), - CX_AttrKind_CFConsumed => new InheritableParamAttr(handle), - CX_AttrKind_CarriesDependency => new InheritableParamAttr(handle), - CX_AttrKind_NSConsumed => new InheritableParamAttr(handle), - CX_AttrKind_NonNull => new InheritableParamAttr(handle), - CX_AttrKind_OSConsumed => new InheritableParamAttr(handle), - CX_AttrKind_PassObjectSize => new InheritableParamAttr(handle), - CX_AttrKind_ReleaseHandle => new InheritableParamAttr(handle), - CX_AttrKind_UseHandle => new InheritableParamAttr(handle), - CX_AttrKind_HLSLSV_DispatchThreadID => new HLSLAnnotationAttr(handle), - CX_AttrKind_HLSLSV_GroupIndex => new HLSLAnnotationAttr(handle), - CX_AttrKind_AMDGPUFlatWorkGroupSize => new InheritableAttr(handle), - CX_AttrKind_AMDGPUNumSGPR => new InheritableAttr(handle), - CX_AttrKind_AMDGPUNumVGPR => new InheritableAttr(handle), - CX_AttrKind_AMDGPUWavesPerEU => new InheritableAttr(handle), - CX_AttrKind_ARMInterrupt => new InheritableAttr(handle), - CX_AttrKind_AVRInterrupt => new InheritableAttr(handle), - CX_AttrKind_AVRSignal => new InheritableAttr(handle), - CX_AttrKind_AcquireCapability => new InheritableAttr(handle), - CX_AttrKind_AcquiredAfter => new InheritableAttr(handle), - CX_AttrKind_AcquiredBefore => new InheritableAttr(handle), - CX_AttrKind_AlignMac68k => new InheritableAttr(handle), - CX_AttrKind_AlignNatural => new InheritableAttr(handle), - CX_AttrKind_Aligned => new InheritableAttr(handle), - CX_AttrKind_AllocAlign => new InheritableAttr(handle), - CX_AttrKind_AllocSize => new InheritableAttr(handle), - CX_AttrKind_AlwaysDestroy => new InheritableAttr(handle), - CX_AttrKind_AnalyzerNoReturn => new InheritableAttr(handle), - CX_AttrKind_AnyX86Interrupt => new InheritableAttr(handle), - CX_AttrKind_AnyX86NoCallerSavedRegisters => new InheritableAttr(handle), - CX_AttrKind_ArcWeakrefUnavailable => new InheritableAttr(handle), - CX_AttrKind_ArgumentWithTypeTag => new InheritableAttr(handle), - CX_AttrKind_ArmBuiltinAlias => new InheritableAttr(handle), - CX_AttrKind_ArmLocallyStreaming => new InheritableAttr(handle), - CX_AttrKind_ArmNew => new InheritableAttr(handle), - CX_AttrKind_Artificial => new InheritableAttr(handle), - CX_AttrKind_AsmLabel => new InheritableAttr(handle), - CX_AttrKind_AssertCapability => new InheritableAttr(handle), - CX_AttrKind_AssertExclusiveLock => new InheritableAttr(handle), - CX_AttrKind_AssertSharedLock => new InheritableAttr(handle), - CX_AttrKind_AssumeAligned => new InheritableAttr(handle), - CX_AttrKind_Assumption => new InheritableAttr(handle), - CX_AttrKind_Availability => new InheritableAttr(handle), - CX_AttrKind_AvailableOnlyInDefaultEvalMethod => new InheritableAttr(handle), - CX_AttrKind_BPFPreserveAccessIndex => new InheritableAttr(handle), - CX_AttrKind_BPFPreserveStaticOffset => new InheritableAttr(handle), - CX_AttrKind_BTFDeclTag => new InheritableAttr(handle), - CX_AttrKind_Blocks => new InheritableAttr(handle), - CX_AttrKind_Builtin => new InheritableAttr(handle), - CX_AttrKind_C11NoReturn => new InheritableAttr(handle), - CX_AttrKind_CFAuditedTransfer => new InheritableAttr(handle), - CX_AttrKind_CFGuard => new InheritableAttr(handle), - CX_AttrKind_CFICanonicalJumpTable => new InheritableAttr(handle), - CX_AttrKind_CFReturnsNotRetained => new InheritableAttr(handle), - CX_AttrKind_CFReturnsRetained => new InheritableAttr(handle), - CX_AttrKind_CFUnknownTransfer => new InheritableAttr(handle), - CX_AttrKind_CPUDispatch => new InheritableAttr(handle), - CX_AttrKind_CPUSpecific => new InheritableAttr(handle), - CX_AttrKind_CUDAConstant => new InheritableAttr(handle), - CX_AttrKind_CUDADevice => new InheritableAttr(handle), - CX_AttrKind_CUDADeviceBuiltinSurfaceType => new InheritableAttr(handle), - CX_AttrKind_CUDADeviceBuiltinTextureType => new InheritableAttr(handle), - CX_AttrKind_CUDAGlobal => new InheritableAttr(handle), - CX_AttrKind_CUDAHost => new InheritableAttr(handle), - CX_AttrKind_CUDAInvalidTarget => new InheritableAttr(handle), - CX_AttrKind_CUDALaunchBounds => new InheritableAttr(handle), - CX_AttrKind_CUDAShared => new InheritableAttr(handle), - CX_AttrKind_CXX11NoReturn => new InheritableAttr(handle), - CX_AttrKind_CallableWhen => new InheritableAttr(handle), - CX_AttrKind_Callback => new InheritableAttr(handle), - CX_AttrKind_Capability => new InheritableAttr(handle), - CX_AttrKind_CapturedRecord => new InheritableAttr(handle), - CX_AttrKind_Cleanup => new InheritableAttr(handle), - CX_AttrKind_CmseNSEntry => new InheritableAttr(handle), - CX_AttrKind_CodeModel => new InheritableAttr(handle), - CX_AttrKind_CodeSeg => new InheritableAttr(handle), - CX_AttrKind_Cold => new InheritableAttr(handle), - CX_AttrKind_Common => new InheritableAttr(handle), - CX_AttrKind_Const => new InheritableAttr(handle), - CX_AttrKind_ConstInit => new InheritableAttr(handle), - CX_AttrKind_Constructor => new InheritableAttr(handle), - CX_AttrKind_Consumable => new InheritableAttr(handle), - CX_AttrKind_ConsumableAutoCast => new InheritableAttr(handle), - CX_AttrKind_ConsumableSetOnRead => new InheritableAttr(handle), - CX_AttrKind_Convergent => new InheritableAttr(handle), - CX_AttrKind_CoroDisableLifetimeBound => new InheritableAttr(handle), - CX_AttrKind_CoroLifetimeBound => new InheritableAttr(handle), - CX_AttrKind_CoroOnlyDestroyWhenComplete => new InheritableAttr(handle), - CX_AttrKind_CoroReturnType => new InheritableAttr(handle), - CX_AttrKind_CoroWrapper => new InheritableAttr(handle), - CX_AttrKind_CountedBy => new InheritableAttr(handle), - CX_AttrKind_DLLExport => new InheritableAttr(handle), - CX_AttrKind_DLLExportStaticLocal => new InheritableAttr(handle), - CX_AttrKind_DLLImport => new InheritableAttr(handle), - CX_AttrKind_DLLImportStaticLocal => new InheritableAttr(handle), - CX_AttrKind_Deprecated => new InheritableAttr(handle), - CX_AttrKind_Destructor => new InheritableAttr(handle), - CX_AttrKind_DiagnoseAsBuiltin => new InheritableAttr(handle), - CX_AttrKind_DiagnoseIf => new InheritableAttr(handle), - CX_AttrKind_DisableSanitizerInstrumentation => new InheritableAttr(handle), - CX_AttrKind_DisableTailCalls => new InheritableAttr(handle), - CX_AttrKind_EmptyBases => new InheritableAttr(handle), - CX_AttrKind_EnableIf => new InheritableAttr(handle), - CX_AttrKind_EnforceTCB => new InheritableAttr(handle), - CX_AttrKind_EnforceTCBLeaf => new InheritableAttr(handle), - CX_AttrKind_EnumExtensibility => new InheritableAttr(handle), - CX_AttrKind_Error => new InheritableAttr(handle), - CX_AttrKind_ExcludeFromExplicitInstantiation => new InheritableAttr(handle), - CX_AttrKind_ExclusiveTrylockFunction => new InheritableAttr(handle), - CX_AttrKind_ExternalSourceSymbol => new InheritableAttr(handle), - CX_AttrKind_Final => new InheritableAttr(handle), - CX_AttrKind_FlagEnum => new InheritableAttr(handle), - CX_AttrKind_Flatten => new InheritableAttr(handle), - CX_AttrKind_Format => new InheritableAttr(handle), - CX_AttrKind_FormatArg => new InheritableAttr(handle), - CX_AttrKind_FunctionReturnThunks => new InheritableAttr(handle), - CX_AttrKind_GNUInline => new InheritableAttr(handle), - CX_AttrKind_GuardedBy => new InheritableAttr(handle), - CX_AttrKind_GuardedVar => new InheritableAttr(handle), - CX_AttrKind_HIPManaged => new InheritableAttr(handle), - CX_AttrKind_HLSLNumThreads => new InheritableAttr(handle), - CX_AttrKind_HLSLResource => new InheritableAttr(handle), - CX_AttrKind_HLSLResourceBinding => new InheritableAttr(handle), - CX_AttrKind_HLSLShader => new InheritableAttr(handle), - CX_AttrKind_Hot => new InheritableAttr(handle), - CX_AttrKind_IBAction => new InheritableAttr(handle), - CX_AttrKind_IBOutlet => new InheritableAttr(handle), - CX_AttrKind_IBOutletCollection => new InheritableAttr(handle), - CX_AttrKind_InitPriority => new InheritableAttr(handle), - CX_AttrKind_InternalLinkage => new InheritableAttr(handle), - CX_AttrKind_LTOVisibilityPublic => new InheritableAttr(handle), - CX_AttrKind_LayoutVersion => new InheritableAttr(handle), - CX_AttrKind_Leaf => new InheritableAttr(handle), - CX_AttrKind_LockReturned => new InheritableAttr(handle), - CX_AttrKind_LocksExcluded => new InheritableAttr(handle), - CX_AttrKind_M68kInterrupt => new InheritableAttr(handle), - CX_AttrKind_MIGServerRoutine => new InheritableAttr(handle), - CX_AttrKind_MSAllocator => new InheritableAttr(handle), - CX_AttrKind_MSConstexpr => new InheritableAttr(handle), - CX_AttrKind_MSInheritance => new InheritableAttr(handle), - CX_AttrKind_MSNoVTable => new InheritableAttr(handle), - CX_AttrKind_MSP430Interrupt => new InheritableAttr(handle), - CX_AttrKind_MSStruct => new InheritableAttr(handle), - CX_AttrKind_MSVtorDisp => new InheritableAttr(handle), - CX_AttrKind_MaxFieldAlignment => new InheritableAttr(handle), - CX_AttrKind_MayAlias => new InheritableAttr(handle), - CX_AttrKind_MaybeUndef => new InheritableAttr(handle), - CX_AttrKind_MicroMips => new InheritableAttr(handle), - CX_AttrKind_MinSize => new InheritableAttr(handle), - CX_AttrKind_MinVectorWidth => new InheritableAttr(handle), - CX_AttrKind_Mips16 => new InheritableAttr(handle), - CX_AttrKind_MipsInterrupt => new InheritableAttr(handle), - CX_AttrKind_MipsLongCall => new InheritableAttr(handle), - CX_AttrKind_MipsShortCall => new InheritableAttr(handle), - CX_AttrKind_NSConsumesSelf => new InheritableAttr(handle), - CX_AttrKind_NSErrorDomain => new InheritableAttr(handle), - CX_AttrKind_NSReturnsAutoreleased => new InheritableAttr(handle), - CX_AttrKind_NSReturnsNotRetained => new InheritableAttr(handle), - CX_AttrKind_NVPTXKernel => new InheritableAttr(handle), - CX_AttrKind_Naked => new InheritableAttr(handle), - CX_AttrKind_NoAlias => new InheritableAttr(handle), - CX_AttrKind_NoCommon => new InheritableAttr(handle), - CX_AttrKind_NoDebug => new InheritableAttr(handle), - CX_AttrKind_NoDestroy => new InheritableAttr(handle), - CX_AttrKind_NoDuplicate => new InheritableAttr(handle), - CX_AttrKind_NoInstrumentFunction => new InheritableAttr(handle), - CX_AttrKind_NoMicroMips => new InheritableAttr(handle), - CX_AttrKind_NoMips16 => new InheritableAttr(handle), - CX_AttrKind_NoProfileFunction => new InheritableAttr(handle), - CX_AttrKind_NoRandomizeLayout => new InheritableAttr(handle), - CX_AttrKind_NoReturn => new InheritableAttr(handle), - CX_AttrKind_NoSanitize => new InheritableAttr(handle), - CX_AttrKind_NoSpeculativeLoadHardening => new InheritableAttr(handle), - CX_AttrKind_NoSplitStack => new InheritableAttr(handle), - CX_AttrKind_NoStackProtector => new InheritableAttr(handle), - CX_AttrKind_NoThreadSafetyAnalysis => new InheritableAttr(handle), - CX_AttrKind_NoThrow => new InheritableAttr(handle), - CX_AttrKind_NoUniqueAddress => new InheritableAttr(handle), - CX_AttrKind_NoUwtable => new InheritableAttr(handle), - CX_AttrKind_NotTailCalled => new InheritableAttr(handle), - CX_AttrKind_OMPAllocateDecl => new InheritableAttr(handle), - CX_AttrKind_OMPCaptureNoInit => new InheritableAttr(handle), - CX_AttrKind_OMPDeclareTargetDecl => new InheritableAttr(handle), - CX_AttrKind_OMPDeclareVariant => new InheritableAttr(handle), - CX_AttrKind_OMPThreadPrivateDecl => new InheritableAttr(handle), - CX_AttrKind_OSConsumesThis => new InheritableAttr(handle), - CX_AttrKind_OSReturnsNotRetained => new InheritableAttr(handle), - CX_AttrKind_OSReturnsRetained => new InheritableAttr(handle), - CX_AttrKind_OSReturnsRetainedOnNonZero => new InheritableAttr(handle), - CX_AttrKind_OSReturnsRetainedOnZero => new InheritableAttr(handle), - CX_AttrKind_ObjCBridge => new InheritableAttr(handle), - CX_AttrKind_ObjCBridgeMutable => new InheritableAttr(handle), - CX_AttrKind_ObjCBridgeRelated => new InheritableAttr(handle), - CX_AttrKind_ObjCException => new InheritableAttr(handle), - CX_AttrKind_ObjCExplicitProtocolImpl => new InheritableAttr(handle), - CX_AttrKind_ObjCExternallyRetained => new InheritableAttr(handle), - CX_AttrKind_ObjCIndependentClass => new InheritableAttr(handle), - CX_AttrKind_ObjCMethodFamily => new InheritableAttr(handle), - CX_AttrKind_ObjCNSObject => new InheritableAttr(handle), - CX_AttrKind_ObjCPreciseLifetime => new InheritableAttr(handle), - CX_AttrKind_ObjCRequiresPropertyDefs => new InheritableAttr(handle), - CX_AttrKind_ObjCRequiresSuper => new InheritableAttr(handle), - CX_AttrKind_ObjCReturnsInnerPointer => new InheritableAttr(handle), - CX_AttrKind_ObjCRootClass => new InheritableAttr(handle), - CX_AttrKind_ObjCSubclassingRestricted => new InheritableAttr(handle), - CX_AttrKind_OpenCLIntelReqdSubGroupSize => new InheritableAttr(handle), - CX_AttrKind_OpenCLKernel => new InheritableAttr(handle), - CX_AttrKind_OptimizeNone => new InheritableAttr(handle), - CX_AttrKind_Override => new InheritableAttr(handle), - CX_AttrKind_Owner => new InheritableAttr(handle), - CX_AttrKind_Ownership => new InheritableAttr(handle), - CX_AttrKind_Packed => new InheritableAttr(handle), - CX_AttrKind_ParamTypestate => new InheritableAttr(handle), - CX_AttrKind_PatchableFunctionEntry => new InheritableAttr(handle), - CX_AttrKind_Pointer => new InheritableAttr(handle), - CX_AttrKind_PragmaClangBSSSection => new InheritableAttr(handle), - CX_AttrKind_PragmaClangDataSection => new InheritableAttr(handle), - CX_AttrKind_PragmaClangRelroSection => new InheritableAttr(handle), - CX_AttrKind_PragmaClangRodataSection => new InheritableAttr(handle), - CX_AttrKind_PragmaClangTextSection => new InheritableAttr(handle), - CX_AttrKind_PreferredName => new InheritableAttr(handle), - CX_AttrKind_PreferredType => new InheritableAttr(handle), - CX_AttrKind_PtGuardedBy => new InheritableAttr(handle), - CX_AttrKind_PtGuardedVar => new InheritableAttr(handle), - CX_AttrKind_Pure => new InheritableAttr(handle), - CX_AttrKind_RISCVInterrupt => new InheritableAttr(handle), - CX_AttrKind_RandomizeLayout => new InheritableAttr(handle), - CX_AttrKind_ReadOnlyPlacement => new InheritableAttr(handle), - CX_AttrKind_Reinitializes => new InheritableAttr(handle), - CX_AttrKind_ReleaseCapability => new InheritableAttr(handle), - CX_AttrKind_ReqdWorkGroupSize => new InheritableAttr(handle), - CX_AttrKind_RequiresCapability => new InheritableAttr(handle), - CX_AttrKind_Restrict => new InheritableAttr(handle), - CX_AttrKind_Retain => new InheritableAttr(handle), - CX_AttrKind_ReturnTypestate => new InheritableAttr(handle), - CX_AttrKind_ReturnsNonNull => new InheritableAttr(handle), - CX_AttrKind_ReturnsTwice => new InheritableAttr(handle), - CX_AttrKind_SYCLKernel => new InheritableAttr(handle), - CX_AttrKind_SYCLSpecialClass => new InheritableAttr(handle), - CX_AttrKind_ScopedLockable => new InheritableAttr(handle), - CX_AttrKind_Section => new InheritableAttr(handle), - CX_AttrKind_SelectAny => new InheritableAttr(handle), - CX_AttrKind_Sentinel => new InheritableAttr(handle), - CX_AttrKind_SetTypestate => new InheritableAttr(handle), - CX_AttrKind_SharedTrylockFunction => new InheritableAttr(handle), - CX_AttrKind_SpeculativeLoadHardening => new InheritableAttr(handle), - CX_AttrKind_StandaloneDebug => new InheritableAttr(handle), - CX_AttrKind_StrictFP => new InheritableAttr(handle), - CX_AttrKind_StrictGuardStackCheck => new InheritableAttr(handle), - CX_AttrKind_SwiftAsync => new InheritableAttr(handle), - CX_AttrKind_SwiftAsyncError => new InheritableAttr(handle), - CX_AttrKind_SwiftAsyncName => new InheritableAttr(handle), - CX_AttrKind_SwiftAttr => new InheritableAttr(handle), - CX_AttrKind_SwiftBridge => new InheritableAttr(handle), - CX_AttrKind_SwiftBridgedTypedef => new InheritableAttr(handle), - CX_AttrKind_SwiftError => new InheritableAttr(handle), - CX_AttrKind_SwiftImportAsNonGeneric => new InheritableAttr(handle), - CX_AttrKind_SwiftImportPropertyAsAccessors => new InheritableAttr(handle), - CX_AttrKind_SwiftName => new InheritableAttr(handle), - CX_AttrKind_SwiftNewType => new InheritableAttr(handle), - CX_AttrKind_SwiftPrivate => new InheritableAttr(handle), - CX_AttrKind_TLSModel => new InheritableAttr(handle), - CX_AttrKind_Target => new InheritableAttr(handle), - CX_AttrKind_TargetClones => new InheritableAttr(handle), - CX_AttrKind_TargetVersion => new InheritableAttr(handle), - CX_AttrKind_TestTypestate => new InheritableAttr(handle), - CX_AttrKind_TransparentUnion => new InheritableAttr(handle), - CX_AttrKind_TrivialABI => new InheritableAttr(handle), - CX_AttrKind_TryAcquireCapability => new InheritableAttr(handle), - CX_AttrKind_TypeTagForDatatype => new InheritableAttr(handle), - CX_AttrKind_TypeVisibility => new InheritableAttr(handle), - CX_AttrKind_Unavailable => new InheritableAttr(handle), - CX_AttrKind_Uninitialized => new InheritableAttr(handle), - CX_AttrKind_UnsafeBufferUsage => new InheritableAttr(handle), - CX_AttrKind_Unused => new InheritableAttr(handle), - CX_AttrKind_Used => new InheritableAttr(handle), - CX_AttrKind_UsingIfExists => new InheritableAttr(handle), - CX_AttrKind_Uuid => new InheritableAttr(handle), - CX_AttrKind_VecReturn => new InheritableAttr(handle), - CX_AttrKind_VecTypeHint => new InheritableAttr(handle), - CX_AttrKind_Visibility => new InheritableAttr(handle), - CX_AttrKind_WarnUnused => new InheritableAttr(handle), - CX_AttrKind_WarnUnusedResult => new InheritableAttr(handle), - CX_AttrKind_Weak => new InheritableAttr(handle), - CX_AttrKind_WeakImport => new InheritableAttr(handle), - CX_AttrKind_WeakRef => new InheritableAttr(handle), - CX_AttrKind_WebAssemblyExportName => new InheritableAttr(handle), - CX_AttrKind_WebAssemblyImportModule => new InheritableAttr(handle), - CX_AttrKind_WebAssemblyImportName => new InheritableAttr(handle), - CX_AttrKind_WorkGroupSizeHint => new InheritableAttr(handle), - CX_AttrKind_X86ForceAlignArgPointer => new InheritableAttr(handle), - CX_AttrKind_XRayInstrument => new InheritableAttr(handle), - CX_AttrKind_XRayLogArgs => new InheritableAttr(handle), - CX_AttrKind_ZeroCallUsedRegs => new InheritableAttr(handle), + CX_AttrKind_AddressSpace => new Attr(handle), + CX_AttrKind_Allocating => new Attr(handle), + CX_AttrKind_AnnotateType => new Attr(handle), + CX_AttrKind_ArmAgnostic => new Attr(handle), + CX_AttrKind_ArmIn => new Attr(handle), + CX_AttrKind_ArmInOut => new Attr(handle), + CX_AttrKind_ArmMveStrictPolymorphism => new Attr(handle), + CX_AttrKind_ArmOut => new Attr(handle), + CX_AttrKind_ArmPreserves => new Attr(handle), + CX_AttrKind_ArmStreaming => new Attr(handle), + CX_AttrKind_ArmStreamingCompatible => new Attr(handle), + CX_AttrKind_BTFTypeTag => new Attr(handle), + CX_AttrKind_Blocking => new Attr(handle), + CX_AttrKind_CmseNSCall => new Attr(handle), + CX_AttrKind_HLSLContainedType => new Attr(handle), + CX_AttrKind_HLSLGroupSharedAddressSpace => new Attr(handle), + CX_AttrKind_HLSLROV => new Attr(handle), + CX_AttrKind_HLSLRawBuffer => new Attr(handle), + CX_AttrKind_HLSLResourceClass => new Attr(handle), + CX_AttrKind_NoDeref => new Attr(handle), + CX_AttrKind_NonAllocating => new Attr(handle), + CX_AttrKind_NonBlocking => new Attr(handle), + CX_AttrKind_ObjCGC => new Attr(handle), + CX_AttrKind_ObjCInertUnsafeUnretained => new Attr(handle), + CX_AttrKind_ObjCKindOf => new Attr(handle), + CX_AttrKind_OpenCLConstantAddressSpace => new Attr(handle), + CX_AttrKind_OpenCLGenericAddressSpace => new Attr(handle), + CX_AttrKind_OpenCLGlobalAddressSpace => new Attr(handle), + CX_AttrKind_OpenCLGlobalDeviceAddressSpace => new Attr(handle), + CX_AttrKind_OpenCLGlobalHostAddressSpace => new Attr(handle), + CX_AttrKind_OpenCLLocalAddressSpace => new Attr(handle), + CX_AttrKind_OpenCLPrivateAddressSpace => new Attr(handle), + CX_AttrKind_Ptr32 => new Attr(handle), + CX_AttrKind_Ptr64 => new Attr(handle), + CX_AttrKind_SPtr => new Attr(handle), + CX_AttrKind_TypeNonNull => new Attr(handle), + CX_AttrKind_TypeNullUnspecified => new Attr(handle), + CX_AttrKind_TypeNullableResult => new Attr(handle), + CX_AttrKind_UPtr => new Attr(handle), + CX_AttrKind_WebAssemblyFuncref => new Attr(handle), + CX_AttrKind_CXXAssume => new Attr(handle), + CX_AttrKind_CodeAlign => new Attr(handle), + CX_AttrKind_FallThrough => new Attr(handle), + CX_AttrKind_HLSLControlFlowHint => new Attr(handle), + CX_AttrKind_HLSLLoopHint => new Attr(handle), + CX_AttrKind_Likely => new Attr(handle), + CX_AttrKind_MustTail => new Attr(handle), + CX_AttrKind_OpenCLUnrollHint => new Attr(handle), + CX_AttrKind_Unlikely => new Attr(handle), + CX_AttrKind_AlwaysInline => new Attr(handle), + CX_AttrKind_NoInline => new Attr(handle), + CX_AttrKind_NoMerge => new Attr(handle), + CX_AttrKind_Suppress => new Attr(handle), + CX_AttrKind_AArch64SVEPcs => new Attr(handle), + CX_AttrKind_AArch64VectorPcs => new Attr(handle), + CX_AttrKind_AMDGPUKernelCall => new Attr(handle), + CX_AttrKind_AcquireHandle => new Attr(handle), + CX_AttrKind_AnyX86NoCfCheck => new Attr(handle), + CX_AttrKind_CDecl => new Attr(handle), + CX_AttrKind_CountedBy => new Attr(handle), + CX_AttrKind_CountedByOrNull => new Attr(handle), + CX_AttrKind_FastCall => new Attr(handle), + CX_AttrKind_IntelOclBicc => new Attr(handle), + CX_AttrKind_LifetimeBound => new Attr(handle), + CX_AttrKind_LifetimeCaptureBy => new Attr(handle), + CX_AttrKind_M68kRTD => new Attr(handle), + CX_AttrKind_MSABI => new Attr(handle), + CX_AttrKind_NSReturnsRetained => new Attr(handle), + CX_AttrKind_ObjCOwnership => new Attr(handle), + CX_AttrKind_Pascal => new Attr(handle), + CX_AttrKind_Pcs => new Attr(handle), + CX_AttrKind_PreserveAll => new Attr(handle), + CX_AttrKind_PreserveMost => new Attr(handle), + CX_AttrKind_PreserveNone => new Attr(handle), + CX_AttrKind_RISCVVectorCC => new Attr(handle), + CX_AttrKind_RegCall => new Attr(handle), + CX_AttrKind_SizedBy => new Attr(handle), + CX_AttrKind_SizedByOrNull => new Attr(handle), + CX_AttrKind_StdCall => new Attr(handle), + CX_AttrKind_SwiftAsyncCall => new Attr(handle), + CX_AttrKind_SwiftAttr => new Attr(handle), + CX_AttrKind_SwiftCall => new Attr(handle), + CX_AttrKind_SysVABI => new Attr(handle), + CX_AttrKind_ThisCall => new Attr(handle), + CX_AttrKind_TypeNullable => new Attr(handle), + CX_AttrKind_VectorCall => new Attr(handle), + CX_AttrKind_Annotate => new Attr(handle), + CX_AttrKind_HLSLParamModifier => new Attr(handle), + CX_AttrKind_SwiftAsyncContext => new Attr(handle), + CX_AttrKind_SwiftContext => new Attr(handle), + CX_AttrKind_SwiftErrorResult => new Attr(handle), + CX_AttrKind_SwiftIndirectResult => new Attr(handle), + CX_AttrKind_CFConsumed => new Attr(handle), + CX_AttrKind_CarriesDependency => new Attr(handle), + CX_AttrKind_NSConsumed => new Attr(handle), + CX_AttrKind_NonNull => new Attr(handle), + CX_AttrKind_OSConsumed => new Attr(handle), + CX_AttrKind_PassObjectSize => new Attr(handle), + CX_AttrKind_ReleaseHandle => new Attr(handle), + CX_AttrKind_UseHandle => new Attr(handle), + CX_AttrKind_HLSLPackOffset => new Attr(handle), + CX_AttrKind_HLSLSV_DispatchThreadID => new Attr(handle), + CX_AttrKind_HLSLSV_GroupID => new Attr(handle), + CX_AttrKind_HLSLSV_GroupIndex => new Attr(handle), + CX_AttrKind_HLSLSV_GroupThreadID => new Attr(handle), + CX_AttrKind_AMDGPUFlatWorkGroupSize => new Attr(handle), + CX_AttrKind_AMDGPUMaxNumWorkGroups => new Attr(handle), + CX_AttrKind_AMDGPUNumSGPR => new Attr(handle), + CX_AttrKind_AMDGPUNumVGPR => new Attr(handle), + CX_AttrKind_AMDGPUWavesPerEU => new Attr(handle), + CX_AttrKind_ARMInterrupt => new Attr(handle), + CX_AttrKind_AVRInterrupt => new Attr(handle), + CX_AttrKind_AVRSignal => new Attr(handle), + CX_AttrKind_AcquireCapability => new Attr(handle), + CX_AttrKind_AcquiredAfter => new Attr(handle), + CX_AttrKind_AcquiredBefore => new Attr(handle), + CX_AttrKind_AlignMac68k => new Attr(handle), + CX_AttrKind_AlignNatural => new Attr(handle), + CX_AttrKind_Aligned => new Attr(handle), + CX_AttrKind_AllocAlign => new Attr(handle), + CX_AttrKind_AllocSize => new Attr(handle), + CX_AttrKind_AlwaysDestroy => new Attr(handle), + CX_AttrKind_AnalyzerNoReturn => new Attr(handle), + CX_AttrKind_AnyX86Interrupt => new Attr(handle), + CX_AttrKind_AnyX86NoCallerSavedRegisters => new Attr(handle), + CX_AttrKind_ArcWeakrefUnavailable => new Attr(handle), + CX_AttrKind_ArgumentWithTypeTag => new Attr(handle), + CX_AttrKind_ArmBuiltinAlias => new Attr(handle), + CX_AttrKind_ArmLocallyStreaming => new Attr(handle), + CX_AttrKind_ArmNew => new Attr(handle), + CX_AttrKind_Artificial => new Attr(handle), + CX_AttrKind_AsmLabel => new Attr(handle), + CX_AttrKind_AssertCapability => new Attr(handle), + CX_AttrKind_AssertExclusiveLock => new Attr(handle), + CX_AttrKind_AssertSharedLock => new Attr(handle), + CX_AttrKind_AssumeAligned => new Attr(handle), + CX_AttrKind_Availability => new Attr(handle), + CX_AttrKind_AvailableOnlyInDefaultEvalMethod => new Attr(handle), + CX_AttrKind_BPFFastCall => new Attr(handle), + CX_AttrKind_BPFPreserveAccessIndex => new Attr(handle), + CX_AttrKind_BPFPreserveStaticOffset => new Attr(handle), + CX_AttrKind_BTFDeclTag => new Attr(handle), + CX_AttrKind_Blocks => new Attr(handle), + CX_AttrKind_Builtin => new Attr(handle), + CX_AttrKind_C11NoReturn => new Attr(handle), + CX_AttrKind_CFAuditedTransfer => new Attr(handle), + CX_AttrKind_CFGuard => new Attr(handle), + CX_AttrKind_CFICanonicalJumpTable => new Attr(handle), + CX_AttrKind_CFReturnsNotRetained => new Attr(handle), + CX_AttrKind_CFReturnsRetained => new Attr(handle), + CX_AttrKind_CFUnknownTransfer => new Attr(handle), + CX_AttrKind_CPUDispatch => new Attr(handle), + CX_AttrKind_CPUSpecific => new Attr(handle), + CX_AttrKind_CUDAConstant => new Attr(handle), + CX_AttrKind_CUDADevice => new Attr(handle), + CX_AttrKind_CUDADeviceBuiltinSurfaceType => new Attr(handle), + CX_AttrKind_CUDADeviceBuiltinTextureType => new Attr(handle), + CX_AttrKind_CUDAGlobal => new Attr(handle), + CX_AttrKind_CUDAGridConstant => new Attr(handle), + CX_AttrKind_CUDAHost => new Attr(handle), + CX_AttrKind_CUDAInvalidTarget => new Attr(handle), + CX_AttrKind_CUDALaunchBounds => new Attr(handle), + CX_AttrKind_CUDAShared => new Attr(handle), + CX_AttrKind_CXX11NoReturn => new Attr(handle), + CX_AttrKind_CallableWhen => new Attr(handle), + CX_AttrKind_Callback => new Attr(handle), + CX_AttrKind_Capability => new Attr(handle), + CX_AttrKind_CapturedRecord => new Attr(handle), + CX_AttrKind_Cleanup => new Attr(handle), + CX_AttrKind_ClspvLibclcBuiltin => new Attr(handle), + CX_AttrKind_CmseNSEntry => new Attr(handle), + CX_AttrKind_CodeModel => new Attr(handle), + CX_AttrKind_CodeSeg => new Attr(handle), + CX_AttrKind_Cold => new Attr(handle), + CX_AttrKind_Common => new Attr(handle), + CX_AttrKind_Const => new Attr(handle), + CX_AttrKind_ConstInit => new Attr(handle), + CX_AttrKind_Constructor => new Attr(handle), + CX_AttrKind_Consumable => new Attr(handle), + CX_AttrKind_ConsumableAutoCast => new Attr(handle), + CX_AttrKind_ConsumableSetOnRead => new Attr(handle), + CX_AttrKind_Convergent => new Attr(handle), + CX_AttrKind_CoroAwaitElidable => new Attr(handle), + CX_AttrKind_CoroAwaitElidableArgument => new Attr(handle), + CX_AttrKind_CoroDisableLifetimeBound => new Attr(handle), + CX_AttrKind_CoroLifetimeBound => new Attr(handle), + CX_AttrKind_CoroOnlyDestroyWhenComplete => new Attr(handle), + CX_AttrKind_CoroReturnType => new Attr(handle), + CX_AttrKind_CoroWrapper => new Attr(handle), + CX_AttrKind_DLLExport => new Attr(handle), + CX_AttrKind_DLLExportStaticLocal => new Attr(handle), + CX_AttrKind_DLLImport => new Attr(handle), + CX_AttrKind_DLLImportStaticLocal => new Attr(handle), + CX_AttrKind_Deprecated => new Attr(handle), + CX_AttrKind_Destructor => new Attr(handle), + CX_AttrKind_DiagnoseAsBuiltin => new Attr(handle), + CX_AttrKind_DiagnoseIf => new Attr(handle), + CX_AttrKind_DisableSanitizerInstrumentation => new Attr(handle), + CX_AttrKind_DisableTailCalls => new Attr(handle), + CX_AttrKind_EmptyBases => new Attr(handle), + CX_AttrKind_EnableIf => new Attr(handle), + CX_AttrKind_EnforceTCB => new Attr(handle), + CX_AttrKind_EnforceTCBLeaf => new Attr(handle), + CX_AttrKind_EnumExtensibility => new Attr(handle), + CX_AttrKind_Error => new Attr(handle), + CX_AttrKind_ExcludeFromExplicitInstantiation => new Attr(handle), + CX_AttrKind_ExclusiveTrylockFunction => new Attr(handle), + CX_AttrKind_ExplicitInit => new Attr(handle), + CX_AttrKind_ExternalSourceSymbol => new Attr(handle), + CX_AttrKind_Final => new Attr(handle), + CX_AttrKind_FlagEnum => new Attr(handle), + CX_AttrKind_Flatten => new Attr(handle), + CX_AttrKind_Format => new Attr(handle), + CX_AttrKind_FormatArg => new Attr(handle), + CX_AttrKind_FunctionReturnThunks => new Attr(handle), + CX_AttrKind_GNUInline => new Attr(handle), + CX_AttrKind_GuardedBy => new Attr(handle), + CX_AttrKind_GuardedVar => new Attr(handle), + CX_AttrKind_HIPManaged => new Attr(handle), + CX_AttrKind_HLSLNumThreads => new Attr(handle), + CX_AttrKind_HLSLResource => new Attr(handle), + CX_AttrKind_HLSLResourceBinding => new Attr(handle), + CX_AttrKind_HLSLShader => new Attr(handle), + CX_AttrKind_HLSLWaveSize => new Attr(handle), + CX_AttrKind_Hot => new Attr(handle), + CX_AttrKind_HybridPatchable => new Attr(handle), + CX_AttrKind_IBAction => new Attr(handle), + CX_AttrKind_IBOutlet => new Attr(handle), + CX_AttrKind_IBOutletCollection => new Attr(handle), + CX_AttrKind_InitPriority => new Attr(handle), + CX_AttrKind_InternalLinkage => new Attr(handle), + CX_AttrKind_LTOVisibilityPublic => new Attr(handle), + CX_AttrKind_LayoutVersion => new Attr(handle), + CX_AttrKind_Leaf => new Attr(handle), + CX_AttrKind_LockReturned => new Attr(handle), + CX_AttrKind_LocksExcluded => new Attr(handle), + CX_AttrKind_M68kInterrupt => new Attr(handle), + CX_AttrKind_MIGServerRoutine => new Attr(handle), + CX_AttrKind_MSAllocator => new Attr(handle), + CX_AttrKind_MSConstexpr => new Attr(handle), + CX_AttrKind_MSInheritance => new Attr(handle), + CX_AttrKind_MSNoVTable => new Attr(handle), + CX_AttrKind_MSP430Interrupt => new Attr(handle), + CX_AttrKind_MSStruct => new Attr(handle), + CX_AttrKind_MSVtorDisp => new Attr(handle), + CX_AttrKind_MaxFieldAlignment => new Attr(handle), + CX_AttrKind_MayAlias => new Attr(handle), + CX_AttrKind_MaybeUndef => new Attr(handle), + CX_AttrKind_MicroMips => new Attr(handle), + CX_AttrKind_MinSize => new Attr(handle), + CX_AttrKind_MinVectorWidth => new Attr(handle), + CX_AttrKind_Mips16 => new Attr(handle), + CX_AttrKind_MipsInterrupt => new Attr(handle), + CX_AttrKind_MipsLongCall => new Attr(handle), + CX_AttrKind_MipsShortCall => new Attr(handle), + CX_AttrKind_NSConsumesSelf => new Attr(handle), + CX_AttrKind_NSErrorDomain => new Attr(handle), + CX_AttrKind_NSReturnsAutoreleased => new Attr(handle), + CX_AttrKind_NSReturnsNotRetained => new Attr(handle), + CX_AttrKind_NVPTXKernel => new Attr(handle), + CX_AttrKind_Naked => new Attr(handle), + CX_AttrKind_NoAlias => new Attr(handle), + CX_AttrKind_NoCommon => new Attr(handle), + CX_AttrKind_NoConvergent => new Attr(handle), + CX_AttrKind_NoDebug => new Attr(handle), + CX_AttrKind_NoDestroy => new Attr(handle), + CX_AttrKind_NoDuplicate => new Attr(handle), + CX_AttrKind_NoInstrumentFunction => new Attr(handle), + CX_AttrKind_NoMicroMips => new Attr(handle), + CX_AttrKind_NoMips16 => new Attr(handle), + CX_AttrKind_NoProfileFunction => new Attr(handle), + CX_AttrKind_NoRandomizeLayout => new Attr(handle), + CX_AttrKind_NoReturn => new Attr(handle), + CX_AttrKind_NoSanitize => new Attr(handle), + CX_AttrKind_NoSpecializations => new Attr(handle), + CX_AttrKind_NoSpeculativeLoadHardening => new Attr(handle), + CX_AttrKind_NoSplitStack => new Attr(handle), + CX_AttrKind_NoStackProtector => new Attr(handle), + CX_AttrKind_NoThreadSafetyAnalysis => new Attr(handle), + CX_AttrKind_NoThrow => new Attr(handle), + CX_AttrKind_NoTrivialAutoVarInit => new Attr(handle), + CX_AttrKind_NoUniqueAddress => new Attr(handle), + CX_AttrKind_NoUwtable => new Attr(handle), + CX_AttrKind_NotTailCalled => new Attr(handle), + CX_AttrKind_OMPAllocateDecl => new Attr(handle), + CX_AttrKind_OMPAssume => new Attr(handle), + CX_AttrKind_OMPCaptureNoInit => new Attr(handle), + CX_AttrKind_OMPDeclareTargetDecl => new Attr(handle), + CX_AttrKind_OMPDeclareVariant => new Attr(handle), + CX_AttrKind_OMPThreadPrivateDecl => new Attr(handle), + CX_AttrKind_OSConsumesThis => new Attr(handle), + CX_AttrKind_OSReturnsNotRetained => new Attr(handle), + CX_AttrKind_OSReturnsRetained => new Attr(handle), + CX_AttrKind_OSReturnsRetainedOnNonZero => new Attr(handle), + CX_AttrKind_OSReturnsRetainedOnZero => new Attr(handle), + CX_AttrKind_ObjCBridge => new Attr(handle), + CX_AttrKind_ObjCBridgeMutable => new Attr(handle), + CX_AttrKind_ObjCBridgeRelated => new Attr(handle), + CX_AttrKind_ObjCException => new Attr(handle), + CX_AttrKind_ObjCExplicitProtocolImpl => new Attr(handle), + CX_AttrKind_ObjCExternallyRetained => new Attr(handle), + CX_AttrKind_ObjCIndependentClass => new Attr(handle), + CX_AttrKind_ObjCMethodFamily => new Attr(handle), + CX_AttrKind_ObjCNSObject => new Attr(handle), + CX_AttrKind_ObjCPreciseLifetime => new Attr(handle), + CX_AttrKind_ObjCRequiresPropertyDefs => new Attr(handle), + CX_AttrKind_ObjCRequiresSuper => new Attr(handle), + CX_AttrKind_ObjCReturnsInnerPointer => new Attr(handle), + CX_AttrKind_ObjCRootClass => new Attr(handle), + CX_AttrKind_ObjCSubclassingRestricted => new Attr(handle), + CX_AttrKind_OpenCLIntelReqdSubGroupSize => new Attr(handle), + CX_AttrKind_OpenCLKernel => new Attr(handle), + CX_AttrKind_OptimizeNone => new Attr(handle), + CX_AttrKind_Override => new Attr(handle), + CX_AttrKind_Owner => new Attr(handle), + CX_AttrKind_Ownership => new Attr(handle), + CX_AttrKind_Packed => new Attr(handle), + CX_AttrKind_ParamTypestate => new Attr(handle), + CX_AttrKind_PatchableFunctionEntry => new Attr(handle), + CX_AttrKind_Pointer => new Attr(handle), + CX_AttrKind_PragmaClangBSSSection => new Attr(handle), + CX_AttrKind_PragmaClangDataSection => new Attr(handle), + CX_AttrKind_PragmaClangRelroSection => new Attr(handle), + CX_AttrKind_PragmaClangRodataSection => new Attr(handle), + CX_AttrKind_PragmaClangTextSection => new Attr(handle), + CX_AttrKind_PreferredName => new Attr(handle), + CX_AttrKind_PreferredType => new Attr(handle), + CX_AttrKind_PtGuardedBy => new Attr(handle), + CX_AttrKind_PtGuardedVar => new Attr(handle), + CX_AttrKind_Pure => new Attr(handle), + CX_AttrKind_RISCVInterrupt => new Attr(handle), + CX_AttrKind_RandomizeLayout => new Attr(handle), + CX_AttrKind_ReadOnlyPlacement => new Attr(handle), + CX_AttrKind_Reinitializes => new Attr(handle), + CX_AttrKind_ReleaseCapability => new Attr(handle), + CX_AttrKind_ReqdWorkGroupSize => new Attr(handle), + CX_AttrKind_RequiresCapability => new Attr(handle), + CX_AttrKind_Restrict => new Attr(handle), + CX_AttrKind_Retain => new Attr(handle), + CX_AttrKind_ReturnTypestate => new Attr(handle), + CX_AttrKind_ReturnsNonNull => new Attr(handle), + CX_AttrKind_ReturnsTwice => new Attr(handle), + CX_AttrKind_SYCLKernel => new Attr(handle), + CX_AttrKind_SYCLKernelEntryPoint => new Attr(handle), + CX_AttrKind_SYCLSpecialClass => new Attr(handle), + CX_AttrKind_ScopedLockable => new Attr(handle), + CX_AttrKind_Section => new Attr(handle), + CX_AttrKind_SelectAny => new Attr(handle), + CX_AttrKind_Sentinel => new Attr(handle), + CX_AttrKind_SetTypestate => new Attr(handle), + CX_AttrKind_SharedTrylockFunction => new Attr(handle), + CX_AttrKind_SpeculativeLoadHardening => new Attr(handle), + CX_AttrKind_StandaloneDebug => new Attr(handle), + CX_AttrKind_StrictFP => new Attr(handle), + CX_AttrKind_StrictGuardStackCheck => new Attr(handle), + CX_AttrKind_SwiftAsync => new Attr(handle), + CX_AttrKind_SwiftAsyncError => new Attr(handle), + CX_AttrKind_SwiftAsyncName => new Attr(handle), + CX_AttrKind_SwiftBridge => new Attr(handle), + CX_AttrKind_SwiftBridgedTypedef => new Attr(handle), + CX_AttrKind_SwiftError => new Attr(handle), + CX_AttrKind_SwiftImportAsNonGeneric => new Attr(handle), + CX_AttrKind_SwiftImportPropertyAsAccessors => new Attr(handle), + CX_AttrKind_SwiftName => new Attr(handle), + CX_AttrKind_SwiftNewType => new Attr(handle), + CX_AttrKind_SwiftPrivate => new Attr(handle), + CX_AttrKind_TLSModel => new Attr(handle), + CX_AttrKind_Target => new Attr(handle), + CX_AttrKind_TargetClones => new Attr(handle), + CX_AttrKind_TargetVersion => new Attr(handle), + CX_AttrKind_TestTypestate => new Attr(handle), + CX_AttrKind_TransparentUnion => new Attr(handle), + CX_AttrKind_TrivialABI => new Attr(handle), + CX_AttrKind_TryAcquireCapability => new Attr(handle), + CX_AttrKind_TypeTagForDatatype => new Attr(handle), + CX_AttrKind_TypeVisibility => new Attr(handle), + CX_AttrKind_Unavailable => new Attr(handle), + CX_AttrKind_Uninitialized => new Attr(handle), + CX_AttrKind_UnsafeBufferUsage => new Attr(handle), + CX_AttrKind_Unused => new Attr(handle), + CX_AttrKind_Used => new Attr(handle), + CX_AttrKind_UsingIfExists => new Attr(handle), + CX_AttrKind_Uuid => new Attr(handle), + CX_AttrKind_VTablePointerAuthentication => new Attr(handle), + CX_AttrKind_VecReturn => new Attr(handle), + CX_AttrKind_VecTypeHint => new Attr(handle), + CX_AttrKind_Visibility => new Attr(handle), + CX_AttrKind_WarnUnused => new Attr(handle), + CX_AttrKind_WarnUnusedResult => new Attr(handle), + CX_AttrKind_Weak => new Attr(handle), + CX_AttrKind_WeakImport => new Attr(handle), + CX_AttrKind_WeakRef => new Attr(handle), + CX_AttrKind_WebAssemblyExportName => new Attr(handle), + CX_AttrKind_WebAssemblyImportModule => new Attr(handle), + CX_AttrKind_WebAssemblyImportName => new Attr(handle), + CX_AttrKind_WorkGroupSizeHint => new Attr(handle), + CX_AttrKind_X86ForceAlignArgPointer => new Attr(handle), + CX_AttrKind_XRayInstrument => new Attr(handle), + CX_AttrKind_XRayLogArgs => new Attr(handle), + CX_AttrKind_ZeroCallUsedRegs => new Attr(handle), CX_AttrKind_AbiTag => new Attr(handle), CX_AttrKind_Alias => new Attr(handle), CX_AttrKind_AlignValue => new Attr(handle), @@ -409,7 +444,6 @@ private protected Attr(CXCursor handle) : base(handle, handle.Kind) CX_AttrKind_ObjCRuntimeVisible => new Attr(handle), CX_AttrKind_OpenCLAccess => new Attr(handle), CX_AttrKind_Overloadable => new Attr(handle), - CX_AttrKind_RenderScriptKernel => new Attr(handle), CX_AttrKind_SwiftObjCMembers => new Attr(handle), CX_AttrKind_SwiftVersionedAddition => new Attr(handle), CX_AttrKind_SwiftVersionedRemoval => new Attr(handle), diff --git a/sources/ClangSharp/Cursors/Cursor.cs b/sources/ClangSharp/Cursors/Cursor.cs index 95783bcb..4a60a899 100644 --- a/sources/ClangSharp/Cursors/Cursor.cs +++ b/sources/ClangSharp/Cursors/Cursor.cs @@ -13,11 +13,11 @@ namespace ClangSharp; [DebuggerDisplay("{Handle.DebuggerDisplayString,nq}")] public unsafe class Cursor : IEquatable { - private readonly Lazy _kindSpelling; - private readonly Lazy _lexicalParentCursor; - private readonly Lazy _semanticParentCursor; - private readonly Lazy _spelling; - private readonly Lazy _translationUnit; + private readonly ValueLazy _kindSpelling; + private readonly ValueLazy _lexicalParentCursor; + private readonly ValueLazy _semanticParentCursor; + private readonly ValueLazy _spelling; + private readonly ValueLazy _translationUnit; private List? _cursorChildren; private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind) @@ -28,11 +28,11 @@ private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind) } Handle = handle; - _kindSpelling = new Lazy(Handle.KindSpelling.ToString); - _lexicalParentCursor = new Lazy(() => !Handle.LexicalParent.IsNull ? TranslationUnit.GetOrCreate(Handle.LexicalParent) : null); - _semanticParentCursor = new Lazy(() => !Handle.SemanticParent.IsNull ? TranslationUnit.GetOrCreate(Handle.SemanticParent) : null); - _spelling = new Lazy(Handle.Spelling.ToString); - _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit)); + _kindSpelling = new ValueLazy(Handle.KindSpelling.ToString); + _lexicalParentCursor = new ValueLazy(() => !Handle.LexicalParent.IsNull ? TranslationUnit.GetOrCreate(Handle.LexicalParent) : null); + _semanticParentCursor = new ValueLazy(() => !Handle.SemanticParent.IsNull ? TranslationUnit.GetOrCreate(Handle.SemanticParent) : null); + _spelling = new ValueLazy(Handle.Spelling.ToString); + _translationUnit = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit)); } public IReadOnlyList CursorChildren diff --git a/sources/ClangSharp/Cursors/Decls/BindingDecl.cs b/sources/ClangSharp/Cursors/Decls/BindingDecl.cs index 512aacbd..21c7a630 100644 --- a/sources/ClangSharp/Cursors/Decls/BindingDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/BindingDecl.cs @@ -9,15 +9,15 @@ namespace ClangSharp; public sealed class BindingDecl : ValueDecl { - private readonly Lazy _binding; - private readonly Lazy _decomposedDecl; - private readonly Lazy _holdingVar; + private readonly ValueLazy _binding; + private readonly ValueLazy _decomposedDecl; + private readonly ValueLazy _holdingVar; internal BindingDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Binding) { - _binding = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BindingExpr)); - _decomposedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DecomposedDecl)); - _holdingVar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _binding = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.BindingExpr)); + _decomposedDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DecomposedDecl)); + _holdingVar = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); } public Expr Binding => _binding.Value; diff --git a/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs b/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs index 6394f7ee..d56eb53f 100644 --- a/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs +++ b/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs @@ -10,16 +10,16 @@ public sealed class Capture { private readonly Decl _parentDecl; private readonly uint _index; - private readonly Lazy _copyExpr; - private readonly Lazy _variable; + private readonly ValueLazy _copyExpr; + private readonly ValueLazy _variable; internal Capture(Decl parentDecl, uint index) { _parentDecl = parentDecl; _index = index; - _copyExpr = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureCopyExpr(_index))); - _variable = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureVariable(_index))); + _copyExpr = new ValueLazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureCopyExpr(_index))); + _variable = new ValueLazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureVariable(_index))); } public Expr CopyExpr => _copyExpr.Value; diff --git a/sources/ClangSharp/Cursors/Decls/BlockDecl.cs b/sources/ClangSharp/Cursors/Decls/BlockDecl.cs index b52ad9a1..25d59bc8 100644 --- a/sources/ClangSharp/Cursors/Decls/BlockDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/BlockDecl.cs @@ -1,46 +1,24 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; -using static ClangSharp.Interop.CX_DeclKind; using System; using System.Collections.Generic; +using ClangSharp.Interop; +using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed partial class BlockDecl : Decl, IDeclContext { - private readonly Lazy _blockManglingContextDecl; - private readonly Lazy> _captures; - private readonly Lazy> _parameters; + private readonly ValueLazy _blockManglingContextDecl; + private readonly LazyList _captures; + private readonly LazyList _parameters; internal BlockDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Block) { - _blockManglingContextDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BlockManglingContextDecl)); - _captures = new Lazy>(() => { - var captureCount = Handle.NumCaptures; - var captures = new List(captureCount); - - for (var i = 0; i < captureCount; i++) - { - var capture = new Capture(this, unchecked((uint)i)); - captures.Add(capture); - } - - return captures; - }); - _parameters = new Lazy>(() => { - var parameterCount = Handle.NumArguments; - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); + _blockManglingContextDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.BlockManglingContextDecl)); + _captures = LazyList.Create(Handle.NumCaptures, (i) => new Capture(this, unchecked((uint)i))); + _parameters = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); } public Decl BlockManglingContextDecl => _blockManglingContextDecl.Value; @@ -49,7 +27,7 @@ internal BlockDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_De public bool BlockMissingReturnType => Handle.BlockMissingReturnType; - public IReadOnlyList Captures => _captures.Value; + public IReadOnlyList Captures => _captures; public bool CanAvoidCopyToHeap() => Handle.CanAvoidCopyToHeap; @@ -69,7 +47,7 @@ internal BlockDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_De public uint NumParams => unchecked((uint)Handle.NumArguments); - public IReadOnlyList Parameters => _parameters.Value; + public IReadOnlyList Parameters => _parameters; public bool ParamEmpty => ParamSize == 0; diff --git a/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs index 6781c882..6dd894fa 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs @@ -3,38 +3,27 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class CXXConstructorDecl : CXXMethodDecl { - private readonly Lazy _inheritedConstructor; - private readonly Lazy> _initExprs; + private readonly ValueLazy _inheritedConstructor; + private readonly LazyList _initExprs; internal CXXConstructorDecl(CXCursor handle) : base(handle, CXCursor_Constructor, CX_DeclKind_CXXConstructor) { - _inheritedConstructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InheritedConstructor)); - _initExprs = new Lazy>(() => { - var numInitExprs = Handle.NumExprs; - var initExprs = new List(numInitExprs); - - for (var i = 0; i < numInitExprs; i++) - { - var initExpr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); - initExprs.Add(initExpr); - } - - return initExprs; - }); + _inheritedConstructor = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InheritedConstructor)); + _initExprs = LazyList.Create(Handle.NumExprs , (i) => TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i)))); } public new CXXConstructorDecl CanonicalDecl => (CXXConstructorDecl)base.CanonicalDecl; public CXXConstructorDecl InheritedConstructor => _inheritedConstructor.Value; - public IReadOnlyList InitExprs => _initExprs.Value; + public IReadOnlyList InitExprs => _initExprs; public bool IsConvertingConstructor => Handle.CXXConstructor_IsConvertingConstructor; diff --git a/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs index 096f4cef..8c76cc36 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class CXXConversionDecl : CXXMethodDecl { - private readonly Lazy _conversionType; + private readonly ValueLazy _conversionType; internal CXXConversionDecl(CXCursor handle) : base(handle, CXCursor_ConversionFunction, CX_DeclKind_CXXConversion) { - _conversionType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _conversionType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public new CXXConversionDecl CanonicalDecl => (CXXConversionDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs index 2c4850b5..92243736 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class CXXDeductionGuideDecl : FunctionDecl { - private readonly Lazy _deducedTemplate; + private readonly ValueLazy _deducedTemplate; internal CXXDeductionGuideDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_CXXDeductionGuide) { - _deducedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(handle.TemplatedDecl)); + _deducedTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.TemplatedDecl)); } public bool IsExplicit => !Handle.IsImplicit; diff --git a/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs index e90b4dca..f47ee3b2 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class CXXDestructorDecl : CXXMethodDecl { - private readonly Lazy _operatorDelete; - private readonly Lazy _operatorDeleteThisArg; + private readonly ValueLazy _operatorDelete; + private readonly ValueLazy _operatorDeleteThisArg; internal CXXDestructorDecl(CXCursor handle) : base(handle, CXCursor_Destructor, CX_DeclKind_CXXDestructor) { - _operatorDelete = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _operatorDeleteThisArg = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _operatorDelete = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _operatorDeleteThisArg = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } public new CXXDestructorDecl CanonicalDecl => (CXXDestructorDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs index 05f669a4..204a22cc 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs @@ -3,16 +3,16 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public class CXXMethodDecl : FunctionDecl { - private readonly Lazy> _overriddenMethods; - private readonly Lazy _thisType; - private readonly Lazy _thisObjectType; + private readonly LazyList _overriddenMethods; + private readonly ValueLazy _thisType; + private readonly ValueLazy _thisObjectType; internal CXXMethodDecl(CXCursor handle) : this(handle, CXCursor_CXXMethod, CX_DeclKind_CXXMethod) { @@ -25,21 +25,9 @@ private protected CXXMethodDecl(CXCursor handle, CXCursorKind expectedCursorKind throw new ArgumentOutOfRangeException(nameof(handle)); } - _overriddenMethods = new Lazy>(() => { - var numOverriddenMethods = Handle.NumMethods; - var overriddenMethods = new List(numOverriddenMethods); - - for (var i = 0; i < numOverriddenMethods; i++) - { - var overriddenMethod = TranslationUnit.GetOrCreate(Handle.GetMethod(unchecked((uint)i))); - overriddenMethods.Add(overriddenMethod); - } - - return overriddenMethods; - }); - - _thisType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisType)); - _thisObjectType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisObjectType)); + _overriddenMethods = LazyList.Create(Handle.NumMethods, (i) => TranslationUnit.GetOrCreate(Handle.GetMethod(unchecked((uint)i)))); + _thisType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ThisType)); + _thisObjectType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ThisObjectType)); } public new CXXMethodDecl CanonicalDecl => (CXXMethodDecl)base.CanonicalDecl; @@ -54,7 +42,7 @@ private protected CXXMethodDecl(CXCursor handle, CXCursorKind expectedCursorKind public new CXXMethodDecl MostRecentDecl => (CXXMethodDecl)base.MostRecentDecl; - public IReadOnlyList OverriddenMethods => _overriddenMethods.Value; + public IReadOnlyList OverriddenMethods => _overriddenMethods; public new CXXRecordDecl? Parent => (CXXRecordDecl?)(base.Parent ?? ThisObjectType.AsCXXRecordDecl); diff --git a/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs index a508f38a..b4c5bce3 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs @@ -10,19 +10,19 @@ namespace ClangSharp; public class CXXRecordDecl : RecordDecl { - private readonly Lazy> _bases; - private readonly Lazy> _ctors; - private readonly Lazy _dependentLambdaCallOperator; - private readonly Lazy _describedClassTemplate; - private readonly Lazy _destructor; - private readonly Lazy> _friends; - private readonly Lazy _instantiatedFromMemberClass; - private readonly Lazy _lambdaCallOperator; - private readonly Lazy _lambdaContextDecl; - private readonly Lazy _lambdaStaticInvoker; - private readonly Lazy> _methods; - private readonly Lazy _templateInstantiationPattern; - private readonly Lazy> _vbases; + private readonly LazyList _bases; + private readonly LazyList _ctors; + private readonly ValueLazy _dependentLambdaCallOperator; + private readonly ValueLazy _describedClassTemplate; + private readonly ValueLazy _destructor; + private readonly LazyList _friends; + private readonly ValueLazy _instantiatedFromMemberClass; + private readonly ValueLazy _lambdaCallOperator; + private readonly ValueLazy _lambdaContextDecl; + private readonly ValueLazy _lambdaStaticInvoker; + private readonly LazyList _methods; + private readonly ValueLazy _templateInstantiationPattern; + private readonly LazyList _vbases; internal CXXRecordDecl(CXCursor handle) : this(handle, handle.Kind, CX_DeclKind_CXXRecord) { @@ -35,93 +35,31 @@ private protected CXXRecordDecl(CXCursor handle, CXCursorKind expectedCursorKind throw new ArgumentOutOfRangeException(nameof(handle)); } - _bases = new Lazy>(() => { - var numBases = Handle.NumBases; - var bases = new List(numBases); - - for (var i = 0; i < numBases; i++) - { - var @base = TranslationUnit.GetOrCreate(Handle.GetBase(unchecked((uint)i))); - bases.Add(@base); - } - - return bases; - }); - - _ctors = new Lazy>(() => { - var numCtors = Handle.NumCtors; - var ctors = new List(numCtors); - - for (var i = 0; i < numCtors; i++) - { - var ctor = TranslationUnit.GetOrCreate(Handle.GetCtor(unchecked((uint)i))); - ctors.Add(ctor); - } - - return ctors; - }); - - _dependentLambdaCallOperator = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DependentLambdaCallOperator)); - _describedClassTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedCursorTemplate)); - _destructor = new Lazy(() => { + _bases = LazyList.Create(Handle.NumBases, (i) => TranslationUnit.GetOrCreate(Handle.GetBase(unchecked((uint)i)))); + _ctors = LazyList.Create(Handle.NumCtors, (i) => TranslationUnit.GetOrCreate(Handle.GetCtor(unchecked((uint)i)))); + _dependentLambdaCallOperator = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DependentLambdaCallOperator)); + _describedClassTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DescribedCursorTemplate)); + _destructor = new ValueLazy(() => { var destructor = Handle.Destructor; return destructor.IsNull ? null : TranslationUnit.GetOrCreate(Handle.Destructor); }); - - _friends = new Lazy>(() => { - var numFriends = Handle.NumFriends; - var friends = new List(numFriends); - - for (var i = 0; i < numFriends; i++) - { - var friend = TranslationUnit.GetOrCreate(Handle.GetFriend(unchecked((uint)i))); - friends.Add(friend); - } - - return friends; - }); - - _instantiatedFromMemberClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); - _lambdaCallOperator = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LambdaCallOperator)); - _lambdaContextDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LambdaContextDecl)); - _lambdaStaticInvoker = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LambdaStaticInvoker)); - - _methods = new Lazy>(() => { - var numMethods = Handle.NumMethods; - var methods = new List(numMethods); - - for (var i = 0; i < numMethods; i++) - { - var method = TranslationUnit.GetOrCreate(Handle.GetMethod(unchecked((uint)i))); - methods.Add(method); - } - - return methods; - }); - - _templateInstantiationPattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); - - _vbases = new Lazy>(() => { - var numVBases = Handle.NumVBases; - var vbases = new List(numVBases); - - for (var i = 0; i < numVBases; i++) - { - var vbase = TranslationUnit.GetOrCreate(Handle.GetVBase(unchecked((uint)i))); - vbases.Add(vbase); - } - - return vbases; - }); + _friends = LazyList.Create(Handle.NumFriends, (i) => TranslationUnit.GetOrCreate(Handle.GetFriend(unchecked((uint)i)))); + _instantiatedFromMemberClass = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _lambdaCallOperator = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.LambdaCallOperator)); + _lambdaContextDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.LambdaContextDecl)); + _lambdaStaticInvoker = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.LambdaStaticInvoker)); + _methods = LazyList.Create(Handle.NumMethods, (i) => TranslationUnit.GetOrCreate(Handle.GetMethod(unchecked((uint)i)))); + _templateInstantiationPattern = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); + _vbases = LazyList.Create(Handle.NumVBases, (i) => TranslationUnit.GetOrCreate(Handle.GetVBase(unchecked((uint)i)))); } public bool IsAbstract => Handle.CXXRecord_IsAbstract; - public IReadOnlyList Bases => _bases.Value; + public IReadOnlyList Bases => _bases; public new CXXRecordDecl CanonicalDecl => (CXXRecordDecl)base.CanonicalDecl; - public IReadOnlyList Ctors => _ctors.Value; + public IReadOnlyList Ctors => _ctors; public new CXXRecordDecl? Definition => (CXXRecordDecl?)base.Definition; @@ -131,7 +69,7 @@ private protected CXXRecordDecl(CXCursor handle, CXCursorKind expectedCursorKind public CXXDestructorDecl? Destructor => _destructor.Value; - public IReadOnlyList Friends => _friends.Value; + public IReadOnlyList Friends => _friends; public bool HasDefinition => Definition is not null; @@ -159,7 +97,7 @@ private protected CXXRecordDecl(CXCursor handle, CXCursorKind expectedCursorKind public CXXMethodDecl LambdaStaticInvoker => _lambdaStaticInvoker.Value; - public IReadOnlyList Methods => _methods.Value; + public IReadOnlyList Methods => _methods; public new CXXRecordDecl MostRecentDecl => (CXXRecordDecl)base.MostRecentDecl; @@ -189,5 +127,5 @@ public CXXRecordDecl MostRecentNonInjectedDecl public CXXRecordDecl TemplateInstantiationPattern => _templateInstantiationPattern.Value; - public IReadOnlyList VBases => _vbases.Value; + public IReadOnlyList VBases => _vbases; } diff --git a/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs b/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs index 299793a7..29a077dd 100644 --- a/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs @@ -1,33 +1,22 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; -using static ClangSharp.Interop.CX_DeclKind; using System; using System.Collections.Generic; +using ClangSharp.Interop; +using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class CapturedDecl : Decl, IDeclContext { - private readonly Lazy _contextParam; - private readonly Lazy> _parameters; + private readonly ValueLazy _contextParam; + private readonly LazyList _parameters; internal CapturedDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Captured) { - _contextParam = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ContextParam)); - _parameters = new Lazy>(() => { - var parameterCount = Handle.NumArguments; - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); + _contextParam = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ContextParam)); + _parameters = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); } public ImplicitParamDecl ContextParam => _contextParam.Value; @@ -38,5 +27,5 @@ internal CapturedDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX public uint NumParams => unchecked((uint)Handle.NumArguments); - public IReadOnlyList Parameters => _parameters.Value; + public IReadOnlyList Parameters => _parameters; } diff --git a/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs index e6233e9c..8fa808c8 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs @@ -3,32 +3,20 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ClassTemplateDecl : RedeclarableTemplateDecl { - private readonly Lazy _injectedClassNameSpecialization; - private readonly Lazy> _specializations; + private readonly ValueLazy _injectedClassNameSpecialization; + private readonly LazyList _specializations; internal ClassTemplateDecl(CXCursor handle) : base(handle, CXCursor_ClassTemplate, CX_DeclKind_ClassTemplate) { - _injectedClassNameSpecialization = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); - - _specializations = new Lazy>(() => { - var numSpecializations = Handle.NumSpecializations; - var specializations = new List(numSpecializations); - - for (var i = 0; i (Handle.GetSpecialization(unchecked((uint)i))); - specializations.Add(specialization); - } - - return specializations; - }); + _injectedClassNameSpecialization = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); + _specializations = LazyList.Create(Handle.NumSpecializations, (i) => TranslationUnit.GetOrCreate(Handle.GetSpecialization(unchecked((uint)i)))); } public new ClassTemplateDecl CanonicalDecl => (ClassTemplateDecl)base.CanonicalDecl; @@ -43,7 +31,7 @@ internal ClassTemplateDecl(CXCursor handle) : base(handle, CXCursor_ClassTemplat public new ClassTemplateDecl PreviousDecl => (ClassTemplateDecl)base.PreviousDecl; - public IReadOnlyList Specializations => _specializations.Value; + public IReadOnlyList Specializations => _specializations; public new CXXRecordDecl TemplatedDecl => (CXXRecordDecl)base.TemplatedDecl; } diff --git a/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs index 51062f2f..fd3dfc98 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs @@ -10,44 +10,20 @@ namespace ClangSharp; public sealed class ClassTemplatePartialSpecializationDecl : ClassTemplateSpecializationDecl { - private readonly Lazy> _associatedConstraints; - private readonly Lazy _injectedSpecializationType; - private readonly Lazy _instantiatedFromMember; - private readonly Lazy> _templateParameters; + private readonly LazyList _associatedConstraints; + private readonly ValueLazy _injectedSpecializationType; + private readonly ValueLazy _instantiatedFromMember; + private readonly LazyList _templateParameters; internal ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, CXCursor_ClassTemplatePartialSpecialization, CX_DeclKind_ClassTemplatePartialSpecialization) { - _associatedConstraints = new Lazy>(() => { - var associatedConstraintCount = Handle.NumAssociatedConstraints; - var associatedConstraints = new List(associatedConstraintCount); - - for (var i = 0; i < associatedConstraintCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i))); - associatedConstraints.Add(parameter); - } - - return associatedConstraints; - }); - - _injectedSpecializationType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); - _instantiatedFromMember = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); - - _templateParameters = new Lazy>(() => { - var parameterCount = Handle.GetNumTemplateParameters(0); - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); + _associatedConstraints = LazyList.Create(Handle.NumAssociatedConstraints, (i) => TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i)))); + _injectedSpecializationType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); + _instantiatedFromMember = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _templateParameters = LazyList.Create(Handle.GetNumTemplateParameters(0), (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i)))); } - public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; + public IReadOnlyList AssociatedConstraints => _associatedConstraints; public bool HasAssociatedConstraints => Handle.NumAssociatedConstraints != 0; @@ -61,5 +37,5 @@ internal ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, public new ClassTemplatePartialSpecializationDecl MostRecentDecl => (ClassTemplatePartialSpecializationDecl)base.MostRecentDecl; - public IReadOnlyList TemplateParameters => _templateParameters.Value; + public IReadOnlyList TemplateParameters => _templateParameters; } diff --git a/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs index b3ae1ced..f666ad59 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs @@ -11,24 +11,13 @@ namespace ClangSharp; public class ClassTemplateSpecializationDecl : CXXRecordDecl { - private readonly Lazy _specializedTemplate; - private readonly Lazy> _templateArgs; + private readonly ValueLazy _specializedTemplate; + private readonly LazyList _templateArgs; internal ClassTemplateSpecializationDecl(CXCursor handle) : this(handle, handle.Kind, CX_DeclKind_ClassTemplateSpecialization) { - _specializedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _specializedTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } private protected ClassTemplateSpecializationDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) @@ -38,19 +27,8 @@ private protected ClassTemplateSpecializationDecl(CXCursor handle, CXCursorKind throw new ArgumentOutOfRangeException(nameof(handle)); } - _specializedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _specializedTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } public bool IsClassScopeExplicitSpecialization => IsExplicitSpecialization && (LexicalDeclContext is CXXRecordDecl); @@ -88,5 +66,5 @@ public bool IsExplicitInstantiationOrSpecialization public ClassTemplateDecl SpecializedTemplate => _specializedTemplate.Value; - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs b/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs index 13b106eb..90007682 100644 --- a/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class ConceptDecl : TemplateDecl, IMergeable { - private readonly Lazy _constraintExpr; + private readonly ValueLazy _constraintExpr; internal ConceptDecl(CXCursor handle) : base(handle, CXCursor_ConceptDecl, CX_DeclKind_Concept) { - _constraintExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConstraintExpr)); + _constraintExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ConstraintExpr)); } public new ConceptDecl CanonicalDecl => (ConceptDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs b/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs index 2a66c1b8..e3020162 100644 --- a/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs @@ -9,17 +9,17 @@ namespace ClangSharp; public sealed class ConstructorUsingShadowDecl : UsingShadowDecl { - private readonly Lazy _constructedBaseClass; - private readonly Lazy _constructedBaseClassShadowDecl; - private readonly Lazy _nominatedBaseClass; - private readonly Lazy _nominatedBaseClassShadowDecl; + private readonly ValueLazy _constructedBaseClass; + private readonly ValueLazy _constructedBaseClassShadowDecl; + private readonly ValueLazy _nominatedBaseClass; + private readonly ValueLazy _nominatedBaseClassShadowDecl; internal ConstructorUsingShadowDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_ConstructorUsingShadow) { - _constructedBaseClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConstructedBaseClass)); - _constructedBaseClassShadowDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConstructedBaseClassShadowDecl)); - _nominatedBaseClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NominatedBaseClass)); - _nominatedBaseClassShadowDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NominatedBaseClassShadowDecl)); + _constructedBaseClass = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ConstructedBaseClass)); + _constructedBaseClassShadowDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ConstructedBaseClassShadowDecl)); + _nominatedBaseClass = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NominatedBaseClass)); + _nominatedBaseClassShadowDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NominatedBaseClassShadowDecl)); } public CXXRecordDecl ConstructedBaseClass => _constructedBaseClass.Value; diff --git a/sources/ClangSharp/Cursors/Decls/Decl.cs b/sources/ClangSharp/Cursors/Decls/Decl.cs index 741afb59..cc9b1429 100644 --- a/sources/ClangSharp/Cursors/Decls/Decl.cs +++ b/sources/ClangSharp/Cursors/Decls/Decl.cs @@ -10,19 +10,19 @@ namespace ClangSharp; public class Decl : Cursor { - private readonly Lazy _asFunction; - private readonly Lazy> _attrs; - private readonly Lazy _body; - private readonly Lazy _canonicalDecl; - private readonly Lazy> _decls; - private readonly Lazy _describedTemplate; - private readonly Lazy _mostRecentDecl; - private readonly Lazy _nextDeclInContext; - private readonly Lazy _nonClosureContext; - private readonly Lazy _parentFunctionOrMethod; - private readonly Lazy _previousDecl; - private readonly Lazy _redeclContext; - private readonly Lazy _translationUnitDecl; + private readonly ValueLazy _asFunction; + private readonly LazyList _attrs; + private readonly ValueLazy _body; + private readonly ValueLazy _canonicalDecl; + private readonly LazyList _decls; + private readonly ValueLazy _describedTemplate; + private readonly ValueLazy _mostRecentDecl; + private readonly ValueLazy _nextDeclInContext; + private readonly ValueLazy _nonClosureContext; + private readonly ValueLazy _parentFunctionOrMethod; + private readonly ValueLazy _previousDecl; + private readonly ValueLazy _redeclContext; + private readonly ValueLazy _translationUnitDecl; private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind) { @@ -31,56 +31,29 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl throw new ArgumentOutOfRangeException(nameof(handle)); } - _asFunction = new Lazy(() => TranslationUnit.GetOrCreate(Handle.AsFunction)); - - _attrs = new Lazy>(() => { - var attrCount = Handle.NumAttrs; - var attrs = new List(attrCount); - - for (var i = 0; i < attrCount; i++) - { - var attr = TranslationUnit.GetOrCreate(Handle.GetAttr(unchecked((uint)i))); - attrs.Add(attr); - } - - return attrs; - }); - - _body = new Lazy(() => !Handle.Body.IsNull ? TranslationUnit.GetOrCreate(Handle.Body) : null); - _canonicalDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CanonicalCursor)); - - _decls = new Lazy>(() => { - var declCount = Handle.NumDecls; - var decls = new List(declCount); - - for (var i = 0; i < declCount; i++) - { - var decl = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); - decls.Add(decl); - } - - return decls; - }); -; - _describedTemplate = new Lazy(() => - { - CXCursor describedTemplate = Handle.DescribedTemplate; + _asFunction = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AsFunction)); + _attrs = LazyList.Create(Handle.NumAttrs, (i) => TranslationUnit.GetOrCreate(Handle.GetAttr(unchecked((uint)i)))); + _body = new ValueLazy(() => !Handle.Body.IsNull ? TranslationUnit.GetOrCreate(Handle.Body) : null); + _canonicalDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.CanonicalCursor)); + _decls = LazyList.Create(Handle.NumDecls, (i) => TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i)))); + _describedTemplate = new ValueLazy(() => { + var describedTemplate = Handle.DescribedTemplate; return describedTemplate.IsNull ? null : TranslationUnit.GetOrCreate(describedTemplate); }); - _mostRecentDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.MostRecentDecl)); - _nextDeclInContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NextDeclInContext)); - _nonClosureContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NonClosureContext)); - _parentFunctionOrMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ParentFunctionOrMethod) as IDeclContext); - _previousDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PreviousDecl)); - _redeclContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RedeclContext) as IDeclContext); - _translationUnitDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit.Cursor)); + _mostRecentDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.MostRecentDecl)); + _nextDeclInContext = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NextDeclInContext)); + _nonClosureContext = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NonClosureContext)); + _parentFunctionOrMethod = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ParentFunctionOrMethod) as IDeclContext); + _previousDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.PreviousDecl)); + _redeclContext = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.RedeclContext) as IDeclContext); + _translationUnitDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit.Cursor)); } public CX_CXXAccessSpecifier Access => Handle.CXXAccessSpecifier; public FunctionDecl AsFunction => _asFunction.Value; - public IReadOnlyList Attrs => _attrs.Value; + public IReadOnlyList Attrs => _attrs; public CXAvailabilityKind Availability => Handle.Availability; @@ -92,7 +65,7 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl public string DeclKindName => Handle.DeclKindSpelling; - public IReadOnlyList Decls => _decls.Value; + public IReadOnlyList Decls => _decls; /// /// Per clang documentation: This returns null for partial specializations, because they are not modeled as TemplateDecls. diff --git a/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs b/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs index a73b80f5..d45b5969 100644 --- a/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs @@ -9,8 +9,8 @@ namespace ClangSharp; public class DeclaratorDecl : ValueDecl { - private readonly Lazy>> _templateParameterLists; - private readonly Lazy _trailingRequiresClause; + private readonly LazyList> _templateParameterLists; + private readonly ValueLazy _trailingRequiresClause; private protected DeclaratorDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -19,33 +19,16 @@ private protected DeclaratorDecl(CXCursor handle, CXCursorKind expectedCursorKin throw new ArgumentOutOfRangeException(nameof(handle)); } - _templateParameterLists = new Lazy>>(() => { - var numTemplateParameterLists = Handle.NumTemplateParameterLists; - var templateParameterLists = new List>(numTemplateParameterLists); - - for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) - { - var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); - var templateParameterList = new List(numTemplateParameters); - - for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) - { - var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); - templateParameterList.Add(templateParameter); - } - - templateParameterLists.Add(templateParameterList); - } - - return templateParameterLists; + _templateParameterLists = LazyList.Create>(Handle.NumTemplateParameterLists, (listIndex) => { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + return LazyList.Create(numTemplateParameters, (parameterIndex) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex)))); }); - - _trailingRequiresClause = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TrailingRequiresClause)); + _trailingRequiresClause = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TrailingRequiresClause)); } public uint NumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); - public IReadOnlyList> TemplateParameterLists => _templateParameterLists.Value; + public IReadOnlyList> TemplateParameterLists => _templateParameterLists; public Expr TrailingRequiresClause => _trailingRequiresClause.Value; } diff --git a/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs b/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs index ba7d97c7..7259760f 100644 --- a/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs @@ -1,32 +1,20 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class DecompositionDecl : VarDecl { - private readonly Lazy> _bindings; + private readonly LazyList _bindings; internal DecompositionDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Decomposition) { - _bindings = new Lazy>(() => { - var numBindings = Handle.NumBindings; - var bindings = new List(numBindings); - - for (var i = 0; i < numBindings; i++) - { - var binding = TranslationUnit.GetOrCreate(Handle.GetBindingDecl(unchecked((uint)i))); - bindings.Add(binding); - } - - return bindings; - }); + _bindings = LazyList.Create(Handle.NumBindings, (i) => TranslationUnit.GetOrCreate(Handle.GetBindingDecl(unchecked((uint)i)))); } - public IReadOnlyList Bindings => _bindings.Value; + public IReadOnlyList Bindings => _bindings; } diff --git a/sources/ClangSharp/Cursors/Decls/EnumConstantDecl.cs b/sources/ClangSharp/Cursors/Decls/EnumConstantDecl.cs index 6f19ce36..9a6e7188 100644 --- a/sources/ClangSharp/Cursors/Decls/EnumConstantDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/EnumConstantDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class EnumConstantDecl : ValueDecl, IMergeable { - private readonly Lazy _initExpr; + private readonly ValueLazy _initExpr; internal EnumConstantDecl(CXCursor handle) : base(handle, CXCursor_EnumConstantDecl, CX_DeclKind_EnumConstant) { - _initExpr = new Lazy(() => !Handle.InitExpr.IsNull ? TranslationUnit.GetOrCreate(Handle.InitExpr) : null); + _initExpr = new ValueLazy(() => !Handle.InitExpr.IsNull ? TranslationUnit.GetOrCreate(Handle.InitExpr) : null); } public new EnumConstantDecl CanonicalDecl => (EnumConstantDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/EnumDecl.cs b/sources/ClangSharp/Cursors/Decls/EnumDecl.cs index 707e9f5f..49442166 100644 --- a/sources/ClangSharp/Cursors/Decls/EnumDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/EnumDecl.cs @@ -10,38 +10,26 @@ namespace ClangSharp; public sealed class EnumDecl : TagDecl { - private readonly Lazy> _enumerators; - private readonly Lazy _instantiatedFromMemberEnum; - private readonly Lazy _integerType; - private readonly Lazy _promotionType; - private readonly Lazy _templateInstantiationPattern; + private readonly LazyList _enumerators; + private readonly ValueLazy _instantiatedFromMemberEnum; + private readonly ValueLazy _integerType; + private readonly ValueLazy _promotionType; + private readonly ValueLazy _templateInstantiationPattern; internal EnumDecl(CXCursor handle) : base(handle, CXCursor_EnumDecl, CX_DeclKind_Enum) { - _enumerators = new Lazy>(() => { - var numEnumerators = Handle.NumEnumerators; - var enumerators = new List(numEnumerators); - - for (var i = 0; i < numEnumerators; i++) - { - var enumerator = TranslationUnit.GetOrCreate(Handle.GetEnumerator(unchecked((uint)i))); - enumerators.Add(enumerator); - } - - return enumerators; - }); - - _instantiatedFromMemberEnum = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); - _integerType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.EnumDecl_IntegerType)); - _promotionType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.EnumDecl_PromotionType)); - _templateInstantiationPattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); + _enumerators = LazyList.Create(Handle.NumEnumerators, (i) => TranslationUnit.GetOrCreate(Handle.GetEnumerator(unchecked((uint)i)))); + _instantiatedFromMemberEnum = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _integerType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.EnumDecl_IntegerType)); + _promotionType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.EnumDecl_PromotionType)); + _templateInstantiationPattern = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); } public new EnumDecl CanonicalDecl => (EnumDecl)base.CanonicalDecl; public new EnumDecl? Definition => (EnumDecl?)base.Definition; - public IReadOnlyList Enumerators => _enumerators.Value; + public IReadOnlyList Enumerators => _enumerators; public EnumDecl InstantiatedFromMemberEnum => _instantiatedFromMemberEnum.Value; diff --git a/sources/ClangSharp/Cursors/Decls/FieldDecl.cs b/sources/ClangSharp/Cursors/Decls/FieldDecl.cs index 35448425..0d2f5592 100644 --- a/sources/ClangSharp/Cursors/Decls/FieldDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FieldDecl.cs @@ -10,9 +10,9 @@ namespace ClangSharp; public class FieldDecl : DeclaratorDecl, IMergeable { - private readonly Lazy _bitWidth; - private readonly Lazy _inClassInitializer; - private readonly Lazy _isAnonymousField; + private readonly ValueLazy _bitWidth; + private readonly ValueLazy _inClassInitializer; + private readonly ValueLazy _isAnonymousField; internal FieldDecl(CXCursor handle) : this(handle, CXCursor_FieldDecl, CX_DeclKind_Field) { @@ -25,12 +25,12 @@ private protected FieldDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX throw new ArgumentOutOfRangeException(nameof(handle)); } - _bitWidth = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BitWidth)); - _inClassInitializer = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InClassInitializer)); - _isAnonymousField = new Lazy(() => { - var name = Name; + _bitWidth = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.BitWidth)); + _inClassInitializer = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InClassInitializer)); + _isAnonymousField = new ValueLazy(() => { + var name = Name.AsSpan(); - if (string.IsNullOrWhiteSpace(name)) + if (name.IsWhiteSpace()) { return true; } diff --git a/sources/ClangSharp/Cursors/Decls/FriendDecl.cs b/sources/ClangSharp/Cursors/Decls/FriendDecl.cs index c19be2a2..45c4aadc 100644 --- a/sources/ClangSharp/Cursors/Decls/FriendDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FriendDecl.cs @@ -10,32 +10,15 @@ namespace ClangSharp; public sealed class FriendDecl : Decl { - private readonly Lazy _friendNamedDecl; - private readonly Lazy>> _friendTypeTemplateParameterLists; + private readonly ValueLazy _friendNamedDecl; + private readonly LazyList> _friendTypeTemplateParameterLists; internal FriendDecl(CXCursor handle) : base(handle, CXCursor_FriendDecl, CX_DeclKind_Friend) { - _friendNamedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FriendDecl)); - - _friendTypeTemplateParameterLists = new Lazy>>(() => { - var numTemplateParameterLists = Handle.NumTemplateParameterLists; - var templateParameterLists = new List>(numTemplateParameterLists); - - for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) - { - var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); - var templateParameterList = new List(numTemplateParameters); - - for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) - { - var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); - templateParameterList.Add(templateParameter); - } - - templateParameterLists.Add(templateParameterList); - } - - return templateParameterLists; + _friendNamedDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.FriendDecl)); + _friendTypeTemplateParameterLists = LazyList.Create>(Handle.NumTemplateParameterLists, (listIndex) => { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + return LazyList.Create(numTemplateParameters, (parameterIndex) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex)))); }); } @@ -45,5 +28,5 @@ internal FriendDecl(CXCursor handle) : base(handle, CXCursor_FriendDecl, CX_Decl public uint FriendTypeNumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); - public IReadOnlyList> FriendTypeTemplateParameterLists => _friendTypeTemplateParameterLists.Value; + public IReadOnlyList> FriendTypeTemplateParameterLists => _friendTypeTemplateParameterLists; } diff --git a/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs index 7da60792..ae486c38 100644 --- a/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs @@ -3,41 +3,24 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class FriendTemplateDecl : Decl { - private readonly Lazy _friendDecl; - private readonly Lazy _friendType; - private readonly Lazy>> _templateParameterLists; + private readonly ValueLazy _friendDecl; + private readonly ValueLazy _friendType; + private readonly LazyList> _templateParameterLists; internal FriendTemplateDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_FriendTemplate) { - _friendDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FriendDecl)); - _friendType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - - _templateParameterLists = new Lazy>>(() => { - var numTemplateParameterLists = Handle.NumTemplateParameterLists; - var templateParameterLists = new List>(numTemplateParameterLists); - - for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) - { - var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); - var templateParameterList = new List(numTemplateParameters); - - for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) - { - var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); - templateParameterList.Add(templateParameter); - } - - templateParameterLists.Add(templateParameterList); - } - - return templateParameterLists; + _friendDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.FriendDecl)); + _friendType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _templateParameterLists = LazyList.Create>(Handle.NumTemplateParameterLists, (listIndex) => { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + return LazyList.Create(numTemplateParameters, (parameterIndex) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex)))); }); } @@ -47,5 +30,5 @@ internal FriendTemplateDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDe public uint NumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); - public IReadOnlyList> TemplateParameterLists => _templateParameterLists.Value; + public IReadOnlyList> TemplateParameterLists => _templateParameterLists; } diff --git a/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs b/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs index c1054c26..2e1aaca7 100644 --- a/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs @@ -3,23 +3,23 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public class FunctionDecl : DeclaratorDecl, IDeclContext, IRedeclarable { - private readonly Lazy _callResultType; - private readonly Lazy _declaredReturnType; - private readonly Lazy _definition; - private readonly Lazy _describedFunctionDecl; - private readonly Lazy _instantiatedFromMemberFunction; - private readonly Lazy> _parameters; - private readonly Lazy _primaryTemplate; - private readonly Lazy _returnType; - private readonly Lazy _templateInstantiationPattern; - private readonly Lazy> _templateSpecializationArgs; + private readonly ValueLazy _callResultType; + private readonly ValueLazy _declaredReturnType; + private readonly ValueLazy _definition; + private readonly ValueLazy _describedFunctionDecl; + private readonly ValueLazy _instantiatedFromMemberFunction; + private readonly LazyList _parameters; + private readonly ValueLazy _primaryTemplate; + private readonly ValueLazy _returnType; + private readonly ValueLazy _templateInstantiationPattern; + private readonly LazyList _templateSpecializationArgs; internal FunctionDecl(CXCursor handle) : this(handle, CXCursor_FunctionDecl, CX_DeclKind_Function) { @@ -32,41 +32,16 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, throw new ArgumentOutOfRangeException(nameof(handle)); } - _callResultType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CallResultType)); - _declaredReturnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DeclaredReturnType)); - _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); - _describedFunctionDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedCursorTemplate)); - _instantiatedFromMemberFunction = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); - - _parameters = new Lazy>(() => { - var parameterCount = Handle.NumArguments; - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); - - _primaryTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PrimaryTemplate)); - _returnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); - _templateInstantiationPattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); - - _templateSpecializationArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _callResultType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.CallResultType)); + _declaredReturnType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DeclaredReturnType)); + _definition = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _describedFunctionDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DescribedCursorTemplate)); + _instantiatedFromMemberFunction = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _parameters = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); + _primaryTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.PrimaryTemplate)); + _returnType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); + _templateInstantiationPattern = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); + _templateSpecializationArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } public Type CallResultType => _callResultType.Value; @@ -123,7 +98,7 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, public CX_OverloadedOperatorKind OverloadedOperator => Handle.OverloadedOperatorKind; - public IReadOnlyList Parameters => _parameters.Value; + public IReadOnlyList Parameters => _parameters; public FunctionTemplateDecl PrimaryTemplate => _primaryTemplate.Value; @@ -133,7 +108,7 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, public FunctionDecl TemplateInstantiationPattern => _templateInstantiationPattern.Value; - public IReadOnlyList TemplateSpecializationArgs => _templateSpecializationArgs.Value; + public IReadOnlyList TemplateSpecializationArgs => _templateSpecializationArgs; public CX_TemplateSpecializationKind TemplateSpecializationKind => Handle.TemplateSpecializationKind; } diff --git a/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs index 7077354e..3bcac8d5 100644 --- a/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs @@ -1,6 +1,5 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; @@ -10,41 +9,18 @@ namespace ClangSharp; public sealed class FunctionTemplateDecl : RedeclarableTemplateDecl { - private readonly Lazy> _injectedTemplateArgs; - private readonly Lazy> _specializations; + private readonly LazyList _injectedTemplateArgs; + private readonly LazyList _specializations; internal FunctionTemplateDecl(CXCursor handle) : base(handle, CXCursor_FunctionTemplate, CX_DeclKind_FunctionTemplate) { - _injectedTemplateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); - - _specializations = new Lazy>(() => { - var numSpecializations = Handle.NumSpecializations; - var specializations = new List(numSpecializations); - - for (var i = 0; i < numSpecializations; i++) - { - var specialization = TranslationUnit.GetOrCreate(Handle.GetSpecialization(unchecked((uint)i))); - specializations.Add(specialization); - } - - return specializations; - }); + _injectedTemplateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); + _specializations = LazyList.Create(Handle.NumSpecializations, (i) => TranslationUnit.GetOrCreate(Handle.GetSpecialization(unchecked((uint)i)))); } public new FunctionTemplateDecl CanonicalDecl => (FunctionTemplateDecl)base.CanonicalDecl; - public IReadOnlyList InjectedTemplateArgs => _injectedTemplateArgs.Value; + public IReadOnlyList InjectedTemplateArgs => _injectedTemplateArgs; public new FunctionTemplateDecl InstantiatedFromMemberTemplate => (FunctionTemplateDecl)base.InstantiatedFromMemberTemplate; @@ -54,7 +30,7 @@ internal FunctionTemplateDecl(CXCursor handle) : base(handle, CXCursor_FunctionT public new FunctionTemplateDecl PreviousDecl => (FunctionTemplateDecl)base.PreviousDecl; - public IReadOnlyList Specializations => _specializations.Value; + public IReadOnlyList Specializations => _specializations; public new FunctionDecl TemplatedDecl => (FunctionDecl)base.TemplatedDecl; } diff --git a/sources/ClangSharp/Cursors/Decls/ImplicitConceptSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/ImplicitConceptSpecializationDecl.cs index 0b65981c..9d6fe8b7 100644 --- a/sources/ClangSharp/Cursors/Decls/ImplicitConceptSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ImplicitConceptSpecializationDecl.cs @@ -1,6 +1,5 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; using static ClangSharp.Interop.CX_DeclKind; @@ -10,25 +9,14 @@ namespace ClangSharp; public sealed class ImplicitConceptSpecializationDecl : Decl { - private readonly Lazy> _templateArgs; + private readonly LazyList _templateArgs; internal ImplicitConceptSpecializationDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_ImplicitConceptSpecialization) { - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i)))); } public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs b/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs index 43102770..0908a98b 100644 --- a/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class IndirectFieldDecl : ValueDecl, IMergeable { - private readonly Lazy _anonField; - private readonly Lazy _varDecl; + private readonly ValueLazy _anonField; + private readonly ValueLazy _varDecl; internal IndirectFieldDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_IndirectField) { - _anonField = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _varDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _anonField = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _varDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } public FieldDecl AnonField => _anonField.Value; diff --git a/sources/ClangSharp/Cursors/Decls/LabelDecl.cs b/sources/ClangSharp/Cursors/Decls/LabelDecl.cs index 6156f766..7ccbfb16 100644 --- a/sources/ClangSharp/Cursors/Decls/LabelDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/LabelDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class LabelDecl : NamedDecl { - private readonly Lazy _stmt; + private readonly ValueLazy _stmt; internal LabelDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Label) { - _stmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _stmt = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } public LabelStmt Stmt => _stmt.Value; diff --git a/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs b/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs index d2c24a95..4a9bb1f0 100644 --- a/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class LifetimeExtendedTemporaryDecl : Decl, IMergeable { - private readonly Lazy _extendingDecl; - private readonly Lazy _temporaryExpr; + private readonly ValueLazy _extendingDecl; + private readonly ValueLazy _temporaryExpr; internal LifetimeExtendedTemporaryDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_LifetimeExtendedTemporary) { - _extendingDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); - _temporaryExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _extendingDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _temporaryExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } public ValueDecl ExtendingDecl => _extendingDecl.Value; diff --git a/sources/ClangSharp/Cursors/Decls/NamedDecl.cs b/sources/ClangSharp/Cursors/Decls/NamedDecl.cs index d28aff21..dc78fe78 100644 --- a/sources/ClangSharp/Cursors/Decls/NamedDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NamedDecl.cs @@ -8,7 +8,7 @@ namespace ClangSharp; public class NamedDecl : Decl { - private readonly Lazy _underlyingDecl; + private readonly ValueLazy _underlyingDecl; private protected NamedDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -17,7 +17,7 @@ private protected NamedDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX throw new ArgumentOutOfRangeException(nameof(handle)); } - _underlyingDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingDecl)); + _underlyingDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingDecl)); } public CXLinkageKind LinkageInternal => Handle.Linkage; diff --git a/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs b/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs index fbff0e97..7bd52219 100644 --- a/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class NamespaceAliasDecl : NamedDecl, IRedeclarable { - private readonly Lazy _aliasedNamespace; - private readonly Lazy _namespace; + private readonly ValueLazy _aliasedNamespace; + private readonly ValueLazy _namespace; internal NamespaceAliasDecl(CXCursor handle) : base(handle, CXCursor_NamespaceAlias, CX_DeclKind_NamespaceAlias) { - _aliasedNamespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _namespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _aliasedNamespace = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _namespace = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } public NamedDecl AliasedNamespace => _aliasedNamespace.Value; diff --git a/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs b/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs index 65b7c6f3..dc6536f6 100644 --- a/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class NamespaceDecl : NamedDecl, IDeclContext, IRedeclarable { - private readonly Lazy _anonymousNamespace; - private readonly Lazy _originalNamespace; + private readonly ValueLazy _anonymousNamespace; + private readonly ValueLazy _originalNamespace; internal NamespaceDecl(CXCursor handle) : base(handle, CXCursor_Namespace, CX_DeclKind_Namespace) { - _anonymousNamespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _originalNamespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _anonymousNamespace = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _originalNamespace = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } public NamespaceDecl AnonymousNamespace => _anonymousNamespace.Value; diff --git a/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs b/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs index d188b482..f49e3425 100644 --- a/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs @@ -3,52 +3,27 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class NonTypeTemplateParmDecl : DeclaratorDecl, ITemplateParmPosition { - private readonly Lazy> _associatedConstraints; - private readonly Lazy _defaultArgument; - private readonly Lazy> _expansionTypes; - private readonly Lazy _placeholderTypeConstraint; + private readonly LazyList _associatedConstraints; + private readonly ValueLazy _defaultArgument; + private readonly LazyList _expansionTypes; + private readonly ValueLazy _placeholderTypeConstraint; internal NonTypeTemplateParmDecl(CXCursor handle) : base(handle, CXCursor_NonTypeTemplateParameter, CX_DeclKind_NonTypeTemplateParm) { - _associatedConstraints = new Lazy>(() => { - var associatedConstraintCount = Handle.NumAssociatedConstraints; - var associatedConstraints = new List(associatedConstraintCount); - - for (var i = 0; i < associatedConstraintCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i))); - associatedConstraints.Add(parameter); - } - - return associatedConstraints; - }); - - _defaultArgument = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DefaultArg)); - - _expansionTypes = new Lazy>(() => { - var numExpansionTypes = Handle.NumExpansionTypes; - var expansionTypes = new List(numExpansionTypes); - - for (var i = 0; i < numExpansionTypes; i++) - { - var expansionType = TranslationUnit.GetOrCreate(Handle.GetExpansionType(unchecked((uint)i))); - expansionTypes.Add(expansionType); - } - - return expansionTypes; - }); - - _placeholderTypeConstraint = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PlaceholderTypeConstraint)); + _associatedConstraints = LazyList.Create(Handle.NumAssociatedConstraints, (i) => TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i)))); + _defaultArgument = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DefaultArg)); + _expansionTypes = LazyList.Create(Handle.NumExpansionTypes, (i) => TranslationUnit.GetOrCreate(Handle.GetExpansionType(unchecked((uint)i)))); + _placeholderTypeConstraint = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.PlaceholderTypeConstraint)); } - public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; + public IReadOnlyList AssociatedConstraints => _associatedConstraints; public Expr DefaultArgument => _defaultArgument.Value; @@ -56,7 +31,7 @@ internal NonTypeTemplateParmDecl(CXCursor handle) : base(handle, CXCursor_NonTyp public uint Depth => unchecked((uint)Handle.TemplateTypeParmDepth); - public IReadOnlyList ExpansionTypes => _expansionTypes.Value; + public IReadOnlyList ExpansionTypes => _expansionTypes; public bool HasDefaultArgument => Handle.HasDefaultArg; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs index 5f3535ba..4c8abea5 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs @@ -4,54 +4,30 @@ using System.Collections.Generic; using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ObjCCategoryDecl : ObjCContainerDecl { - private readonly Lazy _classInterface; - private readonly Lazy _implementation; - private readonly Lazy> _ivars; - private readonly Lazy _nextClassCategory; - private readonly Lazy _nextClassCategoryRaw; - private readonly Lazy> _protocols; - private readonly Lazy> _typeParamList; + private readonly ValueLazy _classInterface; + private readonly ValueLazy _implementation; + private readonly ValueLazy> _ivars; + private readonly ValueLazy _nextClassCategory; + private readonly ValueLazy _nextClassCategoryRaw; + private readonly LazyList _protocols; + private readonly LazyList _typeParamList; internal ObjCCategoryDecl(CXCursor handle) : base(handle, CXCursor_ObjCCategoryDecl, CX_DeclKind_ObjCCategory) { - _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _implementation = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); - _ivars = new Lazy>(() => Decls.OfType().ToList()); - _nextClassCategory = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); - _nextClassCategoryRaw = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(3))); - - _protocols = new Lazy>(() => { - var numProtocols = Handle.NumProtocols; - var protocols = new List(numProtocols); - - for (var i = 0; i < numProtocols; i++) - { - var protocol = TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i))); - protocols.Add(protocol); - } - - return protocols; - }); - - _typeParamList = new Lazy>(() => { - var numTypeParams = Handle.NumArguments; - var typeParams = new List(numTypeParams); - - for (var i = 0; i < numTypeParams; i++) - { - var typeParam = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - typeParams.Add(typeParam); - } - - return typeParams; - }); + _classInterface = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _implementation = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _ivars = new ValueLazy>(() => [.. Decls.OfType()]); + _nextClassCategory = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _nextClassCategoryRaw = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(3))); + _protocols = LazyList.Create(Handle.NumProtocols, (i) => TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i)))); + _typeParamList = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); } public ObjCInterfaceDecl ClassInterface => _classInterface.Value; @@ -66,9 +42,9 @@ internal ObjCCategoryDecl(CXCursor handle) : base(handle, CXCursor_ObjCCategoryD public ObjCCategoryDecl NextClassCategoryRaw => _nextClassCategoryRaw.Value; - public IReadOnlyList Protocols => _protocols.Value; + public IReadOnlyList Protocols => _protocols; public IReadOnlyList ReferencedProtocols => Protocols; - public IReadOnlyList TypeParamList => _typeParamList.Value; + public IReadOnlyList TypeParamList => _typeParamList; } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs index 56f93db9..3c13b54a 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class ObjCCategoryImplDecl : ObjCImplDecl { - private readonly Lazy _categoryDecl; + private readonly ValueLazy _categoryDecl; internal ObjCCategoryImplDecl(CXCursor handle) : base(handle, CXCursor_ObjCCategoryImplDecl, CX_DeclKind_ObjCCategoryImpl) { - _categoryDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _categoryDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } public ObjCCategoryDecl CategoryDecl => _categoryDecl.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs index 246c93df..9c146939 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs @@ -9,12 +9,12 @@ namespace ClangSharp; public sealed class ObjCCompatibleAliasDecl : NamedDecl { - private readonly Lazy _classInterface; + private readonly ValueLazy _classInterface; internal ObjCCompatibleAliasDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_ObjCCompatibleAlias) { - _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _classInterface = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); } public ObjCInterfaceDecl ClassInterface => _classInterface.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs index fe510167..798d159c 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public class ObjCContainerDecl : NamedDecl, IDeclContext { - private readonly Lazy> _classMethods; - private readonly Lazy> _classProperties; - private readonly Lazy> _instanceMethods; - private readonly Lazy> _instanceProperties; - private readonly Lazy> _methods; - private readonly Lazy> _properties; + private readonly ValueLazy> _classMethods; + private readonly ValueLazy> _classProperties; + private readonly ValueLazy> _instanceMethods; + private readonly ValueLazy> _instanceProperties; + private readonly ValueLazy> _methods; + private readonly ValueLazy> _properties; private protected ObjCContainerDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -24,12 +24,12 @@ private protected ObjCContainerDecl(CXCursor handle, CXCursorKind expectedCursor throw new ArgumentOutOfRangeException(nameof(handle)); } - _classMethods = new Lazy>(() => Methods.Where((method) => method.IsClassMethod).ToList()); - _classProperties = new Lazy>(() => Properties.Where((property) => property.IsClassProperty).ToList()); - _instanceMethods = new Lazy>(() => Methods.Where((method) => method.IsInstanceMethod).ToList()); - _instanceProperties = new Lazy>(() => Properties.Where((property) => property.IsInstanceProperty).ToList()); - _methods = new Lazy>(() => Decls.OfType().ToList()); - _properties = new Lazy>(() => Decls.OfType().ToList()); + _classMethods = new ValueLazy>(() => [.. Methods.Where((method) => method.IsClassMethod)]); + _classProperties = new ValueLazy>(() => [.. Properties.Where((property) => property.IsClassProperty)]); + _instanceMethods = new ValueLazy>(() => [.. Methods.Where((method) => method.IsInstanceMethod)]); + _instanceProperties = new ValueLazy>(() => [.. Properties.Where((property) => property.IsInstanceProperty)]); + _methods = new ValueLazy>(() => [.. Decls.OfType()]); + _properties = new ValueLazy>(() => [.. Decls.OfType()]); } public IReadOnlyList ClassMethods => _classMethods.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs index 4bd00393..8e2cb00f 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs @@ -10,8 +10,8 @@ namespace ClangSharp; public class ObjCImplDecl : ObjCContainerDecl { - private readonly Lazy _classInterface; - private readonly Lazy> _propertyImpls; + private readonly ValueLazy _classInterface; + private readonly ValueLazy> _propertyImpls; private protected ObjCImplDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -20,8 +20,8 @@ private protected ObjCImplDecl(CXCursor handle, CXCursorKind expectedCursorKind, throw new ArgumentOutOfRangeException(nameof(handle)); } - _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _propertyImpls = new Lazy>(() => Decls.OfType().ToList()); + _classInterface = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _propertyImpls = new ValueLazy>(() => [.. Decls.OfType()]); } public ObjCInterfaceDecl ClassInterface => _classInterface.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs index 6fb29d0f..209ea33f 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs @@ -1,40 +1,28 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System.Collections.Generic; using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; -using System.Linq; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ObjCImplementationDecl : ObjCImplDecl { - private readonly Lazy> _initExprs; - private readonly Lazy> _ivars; - private readonly Lazy _superClass; + private readonly LazyList _initExprs; + private readonly ValueLazy> _ivars; + private readonly ValueLazy _superClass; internal ObjCImplementationDecl(CXCursor handle) : base(handle, CXCursor_ObjCImplementationDecl, CX_DeclKind_ObjCImplementation) { - _initExprs = new Lazy>(() => { - var numInitExprs = Handle.NumExprs; - var initExprs = new List(numInitExprs); - - for (var i = 0; i < numInitExprs; i++) - { - var initExpr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); - initExprs.Add(initExpr); - } - - return initExprs; - }); - - _ivars = new Lazy>(() => Decls.OfType().ToList()); - _superClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _initExprs = LazyList.Create(Handle.NumExprs, (i) => TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i)))); + _ivars = new ValueLazy>(() => [.. Decls.OfType()]); + _superClass = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } - public IReadOnlyList InitExprs => _initExprs.Value; + public IReadOnlyList InitExprs => _initExprs; public IReadOnlyList Ivars => _ivars.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs index c76f8c3e..270fe3fe 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs @@ -1,32 +1,32 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System.Collections.Generic; using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; -using System.Linq; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ObjCInterfaceDecl : ObjCContainerDecl, IRedeclarable { - private readonly Lazy> _categoryList; - private readonly Lazy _definition; - private readonly Lazy _implementation; - private readonly Lazy> _ivars; - private readonly Lazy> _knownExtensions; - private readonly Lazy> _protocols; - private readonly Lazy _superClass; - private readonly Lazy _superClassType; - private readonly Lazy _typeForDecl; - private readonly Lazy> _typeParamList; - private readonly Lazy> _visibleCategories; - private readonly Lazy> _visibleExtensions; + private readonly ValueLazy> _categoryList; + private readonly ValueLazy _definition; + private readonly ValueLazy _implementation; + private readonly ValueLazy> _ivars; + private readonly ValueLazy> _knownExtensions; + private readonly LazyList _protocols; + private readonly ValueLazy _superClass; + private readonly ValueLazy _superClassType; + private readonly ValueLazy _typeForDecl; + private readonly LazyList _typeParamList; + private readonly ValueLazy> _visibleCategories; + private readonly ValueLazy> _visibleExtensions; internal ObjCInterfaceDecl(CXCursor handle) : base(handle, CXCursor_ObjCInterfaceDecl, CX_DeclKind_ObjCInterface) { - _categoryList = new Lazy>(() => { + _categoryList = new ValueLazy>(() => { var categories = new List(); var category = TranslationUnit.GetOrCreate(handle.GetSubDecl(0)); @@ -40,43 +40,17 @@ internal ObjCInterfaceDecl(CXCursor handle) : base(handle, CXCursor_ObjCInterfac return categories; }); - _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); - _implementation = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); - _ivars = new Lazy>(() => Decls.OfType().ToList()); - _knownExtensions = new Lazy>(() => CategoryList.Where((category) => category.IsClassExtension).ToList()); - - _protocols = new Lazy>(() => { - var numProtocols = Handle.NumProtocols; - var protocols = new List(numProtocols); - - for (var i = 0; i < numProtocols; i++) - { - var protocol = TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i))); - protocols.Add(protocol); - } - - return protocols; - }); - - _superClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); - _superClassType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - _typeForDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisType)); - - _typeParamList = new Lazy>(() => { - var numTypeParams = Handle.NumArguments; - var typeParams = new List(numTypeParams); - - for (var i = 0; i < numTypeParams; i++) - { - var typeParam = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - typeParams.Add(typeParam); - } - - return typeParams; - }); - - _visibleCategories = new Lazy>(() => CategoryList.Where((category) => category.IsUnconditionallyVisible).ToList()); - _visibleExtensions = new Lazy>(() => CategoryList.Where((category) => category.IsClassExtension && category.IsUnconditionallyVisible).ToList()); + _definition = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _implementation = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _ivars = new ValueLazy>(() => [.. Decls.OfType()]); + _knownExtensions = new ValueLazy>(() => [.. CategoryList.Where((category) => category.IsClassExtension)]); + _protocols = LazyList.Create(Handle.NumProtocols, (i) => TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i)))); + _superClass = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _superClassType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _typeForDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ThisType)); + _typeParamList = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); + _visibleCategories = new ValueLazy>(() => [.. CategoryList.Where((category) => category.IsUnconditionallyVisible)]); + _visibleExtensions = new ValueLazy>(() => [.. CategoryList.Where((category) => category.IsClassExtension && category.IsUnconditionallyVisible)]); } public new ObjCInterfaceDecl CanonicalDecl => (ObjCInterfaceDecl)base.CanonicalDecl; @@ -99,11 +73,11 @@ internal ObjCInterfaceDecl(CXCursor handle) : base(handle, CXCursor_ObjCInterfac public ObjCObjectType SuperClassType => _superClassType.Value; - public IReadOnlyList Protocols => _protocols.Value; + public IReadOnlyList Protocols => _protocols; public IReadOnlyList ReferencedProtocols => Protocols; - public IReadOnlyList TypeParamList => _typeParamList.Value; + public IReadOnlyList TypeParamList => _typeParamList; public Type TypeForDecl => _typeForDecl.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs index b4b90c20..0b05a131 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class ObjCIvarDecl : FieldDecl { - private readonly Lazy _containingInterface; - private readonly Lazy _nextIvar; + private readonly ValueLazy _containingInterface; + private readonly ValueLazy _nextIvar; internal ObjCIvarDecl(CXCursor handle) : base(handle, CXCursor_ObjCIvarDecl, CX_DeclKind_ObjCIvar) { - _containingInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _nextIvar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _containingInterface = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _nextIvar = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } public ObjCInterfaceDecl ContainingInterface => _containingInterface.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs index c60de569..4bc028f7 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs @@ -3,19 +3,19 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ObjCMethodDecl : NamedDecl, IDeclContext { - private readonly Lazy _classInterface; - private readonly Lazy _cmdDecl; - private readonly Lazy> _parameters; - private readonly Lazy _returnType; - private readonly Lazy _selfDecl; - private readonly Lazy _sendResultType; + private readonly ValueLazy _classInterface; + private readonly ValueLazy _cmdDecl; + private readonly LazyList _parameters; + private readonly ValueLazy _returnType; + private readonly ValueLazy _selfDecl; + private readonly ValueLazy _sendResultType; internal ObjCMethodDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind_ObjCMethod) { @@ -24,25 +24,12 @@ internal ObjCMethodDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind throw new ArgumentOutOfRangeException(nameof(handle)); } - _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _cmdDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); - - _parameters = new Lazy>(() => { - var parameterCount = Handle.NumArguments; - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); - - _selfDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); - _returnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); - _sendResultType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _classInterface = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _cmdDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _parameters = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); + _selfDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _returnType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); + _sendResultType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public new ObjCMethodDecl CanonicalDecl => (ObjCMethodDecl)base.CanonicalDecl; @@ -59,7 +46,7 @@ internal ObjCMethodDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind public CXObjCDeclQualifierKind ObjCDeclQualifier => Handle.ObjCDeclQualifiers; - public IReadOnlyList Parameters => _parameters.Value; + public IReadOnlyList Parameters => _parameters; public Type ReturnType => _returnType.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs index c36a93b9..faec7053 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs @@ -9,17 +9,17 @@ namespace ClangSharp; public sealed class ObjCPropertyDecl : NamedDecl { - private readonly Lazy _getterMethodDecl; - private readonly Lazy _propertyIvarDecl; - private readonly Lazy _setterMethodDecl; - private readonly Lazy _type; + private readonly ValueLazy _getterMethodDecl; + private readonly ValueLazy _propertyIvarDecl; + private readonly ValueLazy _setterMethodDecl; + private readonly ValueLazy _type; internal ObjCPropertyDecl(CXCursor handle) : base(handle, CXCursor_ObjCPropertyDecl, CX_DeclKind_ObjCProperty) { - _getterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _propertyIvarDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); - _setterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); - _type = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); + _getterMethodDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _propertyIvarDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _setterMethodDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _type = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); } public ObjCMethodDecl GetterMethodDecl => _getterMethodDecl.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs index 4beab8d3..c52502bf 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs @@ -9,12 +9,12 @@ namespace ClangSharp; public sealed class ObjCPropertyImplDecl : Decl { - private readonly Lazy _getterCXXConstructor; - private readonly Lazy _getterMethodDecl; - private readonly Lazy _propertyDecl; - private readonly Lazy _propertyIvarDecl; - private readonly Lazy _setterMethodDecl; - private readonly Lazy _setterCXXAssignment; + private readonly ValueLazy _getterCXXConstructor; + private readonly ValueLazy _getterMethodDecl; + private readonly ValueLazy _propertyDecl; + private readonly ValueLazy _propertyIvarDecl; + private readonly ValueLazy _setterMethodDecl; + private readonly ValueLazy _setterCXXAssignment; internal ObjCPropertyImplDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind_ObjCPropertyImpl) { @@ -23,12 +23,12 @@ internal ObjCPropertyImplDecl(CXCursor handle) : base(handle, handle.Kind, CX_De throw new ArgumentOutOfRangeException(nameof(handle)); } - _getterCXXConstructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); - _getterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); - _propertyDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); - _propertyIvarDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); - _setterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(3))); - _setterCXXAssignment = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(1))); + _getterCXXConstructor = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _getterMethodDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _propertyDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _propertyIvarDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _setterMethodDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(3))); + _setterCXXAssignment = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(1))); } public Expr GetterCXXConstructor => _getterCXXConstructor.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs index f06e6fee..790f5992 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs @@ -3,32 +3,20 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ObjCProtocolDecl : ObjCContainerDecl, IRedeclarable { - private readonly Lazy _definition; - private readonly Lazy> _protocols; + private readonly ValueLazy _definition; + private readonly LazyList _protocols; internal ObjCProtocolDecl(CXCursor handle) : base(handle, CXCursor_ObjCProtocolDecl, CX_DeclKind_ObjCProtocol) { - _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); - - _protocols = new Lazy>(() => { - var numProtocols = Handle.NumProtocols; - var protocols = new List(numProtocols); - - for (var i = 0; i < numProtocols; i++) - { - var protocol = TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i))); - protocols.Add(protocol); - } - - return protocols; - }); + _definition = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _protocols = LazyList.Create(Handle.NumProtocols, (i) => TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i)))); } public new ObjCProtocolDecl CanonicalDecl => (ObjCProtocolDecl)base.CanonicalDecl; @@ -39,7 +27,7 @@ internal ObjCProtocolDecl(CXCursor handle) : base(handle, CXCursor_ObjCProtocolD public string ObjCRuntimeNameAsString => Handle.Name.CString; - public IReadOnlyList Protocols => _protocols.Value; + public IReadOnlyList Protocols => _protocols; public uint ProtocolSize => unchecked((uint)Handle.NumProtocols); diff --git a/sources/ClangSharp/Cursors/Decls/ParmVarDecl.cs b/sources/ClangSharp/Cursors/Decls/ParmVarDecl.cs index d8d64f90..9064be5e 100644 --- a/sources/ClangSharp/Cursors/Decls/ParmVarDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ParmVarDecl.cs @@ -9,15 +9,15 @@ namespace ClangSharp; public sealed class ParmVarDecl : VarDecl { - private readonly Lazy _defaultArg; - private readonly Lazy _originalType; - private readonly Lazy _uninstantiatedDefaultArg; + private readonly ValueLazy _defaultArg; + private readonly ValueLazy _originalType; + private readonly ValueLazy _uninstantiatedDefaultArg; internal ParmVarDecl(CXCursor handle) : base(handle, CXCursor_ParmDecl, CX_DeclKind_ParmVar) { - _defaultArg = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DefaultArg)); - _originalType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); - _uninstantiatedDefaultArg = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UninstantiatedDefaultArg)); + _defaultArg = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DefaultArg)); + _originalType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _uninstantiatedDefaultArg = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UninstantiatedDefaultArg)); } public Expr DefaultArg => _defaultArg.Value; diff --git a/sources/ClangSharp/Cursors/Decls/RecordDecl.cs b/sources/ClangSharp/Cursors/Decls/RecordDecl.cs index 3ad5689a..f92e00d1 100644 --- a/sources/ClangSharp/Cursors/Decls/RecordDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/RecordDecl.cs @@ -4,18 +4,18 @@ using System.Collections.Generic; using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public class RecordDecl : TagDecl { - private readonly Lazy> _anonymousFields; - private readonly Lazy> _anonymousRecords; - private readonly Lazy> _fields; - private readonly Lazy> _indirectFields; - private readonly Lazy _injectedClassName; + private readonly ValueLazy> _anonymousFields; + private readonly ValueLazy> _anonymousRecords; + private readonly LazyList _fields; + private readonly ValueLazy> _indirectFields; + private readonly ValueLazy _injectedClassName; internal RecordDecl(CXCursor handle) : this(handle, handle.Kind, CX_DeclKind_Record) @@ -34,26 +34,14 @@ private protected RecordDecl(CXCursor handle, CXCursorKind expectedCursorKind, C throw new ArgumentOutOfRangeException(nameof(handle)); } - _fields = new Lazy>(() => { - var numFields = Handle.NumFields; - var fields = new List(numFields); - - for (var i = 0; i < numFields; i++) - { - var field = TranslationUnit.GetOrCreate(Handle.GetField(unchecked((uint)i))); - fields.Add(field); - } - - return fields; - }); - - _anonymousFields = new Lazy>(() => Decls.OfType().Where(decl => decl.IsAnonymousField).ToList()); - _anonymousRecords = new Lazy>(() => Decls.OfType().Where(decl => decl.IsAnonymous && !decl.IsInjectedClassName).ToList()); - _indirectFields = new Lazy>(() => Decls.OfType().ToList()); - _injectedClassName = new Lazy(() => Decls.OfType().Where(decl => decl.IsInjectedClassName).SingleOrDefault()); + _fields = LazyList.Create(Handle.NumFields, (i) => TranslationUnit.GetOrCreate(Handle.GetField(unchecked((uint)i)))); + _anonymousFields = new ValueLazy>(() => [.. Decls.OfType().Where(decl => decl.IsAnonymousField)]); + _anonymousRecords = new ValueLazy>(() => [.. Decls.OfType().Where(decl => decl.IsAnonymousStructOrUnion && !decl.IsInjectedClassName)]); + _indirectFields = new ValueLazy>(() => [.. Decls.OfType()]); + _injectedClassName = new ValueLazy(() => Decls.OfType().Where(decl => decl.IsInjectedClassName).SingleOrDefault()); } - public bool IsAnonymous => Handle.IsAnonymous; + public bool IsAnonymousStructOrUnion => Handle.IsAnonymousStructOrUnion; public IReadOnlyList AnonymousFields => _anonymousFields.Value; @@ -61,7 +49,7 @@ private protected RecordDecl(CXCursor handle, CXCursorKind expectedCursorKind, C public new RecordDecl? Definition => (RecordDecl?)base.Definition; - public IReadOnlyList Fields => _fields.Value; + public IReadOnlyList Fields => _fields; public IReadOnlyList IndirectFields => _indirectFields.Value; diff --git a/sources/ClangSharp/Cursors/Decls/RedeclarableTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/RedeclarableTemplateDecl.cs index 76b6eda4..8e209db1 100644 --- a/sources/ClangSharp/Cursors/Decls/RedeclarableTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/RedeclarableTemplateDecl.cs @@ -8,7 +8,7 @@ namespace ClangSharp; public class RedeclarableTemplateDecl : TemplateDecl, IRedeclarable { - private readonly Lazy _instantiatedFromMemberTemplate; + private readonly ValueLazy _instantiatedFromMemberTemplate; private protected RedeclarableTemplateDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -17,7 +17,7 @@ private protected RedeclarableTemplateDecl(CXCursor handle, CXCursorKind expecte throw new ArgumentOutOfRangeException(nameof(handle)); } - _instantiatedFromMemberTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); + _instantiatedFromMemberTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); } public new RedeclarableTemplateDecl CanonicalDecl => (RedeclarableTemplateDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs b/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs index d0ab0657..7d6b8c0b 100644 --- a/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class StaticAssertDecl : Decl { - private readonly Lazy _assertExpr; - private readonly Lazy _message; + private readonly ValueLazy _assertExpr; + private readonly ValueLazy _message; internal StaticAssertDecl(CXCursor handle) : base(handle, CXCursor_StaticAssert, CX_DeclKind_StaticAssert) { - _assertExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); - _message = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(1))); + _assertExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _message = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(1))); } public Expr AssertExpr => _assertExpr.Value; diff --git a/sources/ClangSharp/Cursors/Decls/TagDecl.cs b/sources/ClangSharp/Cursors/Decls/TagDecl.cs index 85fa287a..fd19d049 100644 --- a/sources/ClangSharp/Cursors/Decls/TagDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TagDecl.cs @@ -3,16 +3,16 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public unsafe class TagDecl : TypeDecl, IDeclContext, IRedeclarable { - private readonly Lazy _definition; - private readonly Lazy>> _templateParameterLists; - private readonly Lazy _typedefNameForAnonDecl; + private readonly ValueLazy _definition; + private readonly LazyList> _templateParameterLists; + private readonly ValueLazy _typedefNameForAnonDecl; private protected TagDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -21,30 +21,12 @@ private protected TagDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_D throw new ArgumentOutOfRangeException(nameof(handle)); } - _definition = new Lazy(() => !Handle.Definition.IsNull ? TranslationUnit.GetOrCreate(Handle.Definition) : null); - - _templateParameterLists = new Lazy>>(() => { - var numTemplateParameterLists = Handle.NumTemplateParameterLists; - var templateParameterLists = new List>(numTemplateParameterLists); - - for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) - { - var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); - var templateParameterList = new List(numTemplateParameters); - - for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) - { - var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); - templateParameterList.Add(templateParameter); - } - - templateParameterLists.Add(templateParameterList); - } - - return templateParameterLists; + _definition = new ValueLazy(() => !Handle.Definition.IsNull ? TranslationUnit.GetOrCreate(Handle.Definition) : null); + _templateParameterLists = LazyList.Create>(Handle.NumTemplateParameterLists, (listIndex) => { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + return LazyList.Create(numTemplateParameters, (parameterIndex) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex)))); }); - - _typedefNameForAnonDecl = new Lazy(() => !Handle.TypedefNameForAnonDecl.IsNull ? TranslationUnit.GetOrCreate(Handle.TypedefNameForAnonDecl) : null); + _typedefNameForAnonDecl = new ValueLazy(() => !Handle.TypedefNameForAnonDecl.IsNull ? TranslationUnit.GetOrCreate(Handle.TypedefNameForAnonDecl) : null); } public new TagDecl CanonicalDecl => (TagDecl)base.CanonicalDecl; @@ -65,7 +47,7 @@ private protected TagDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_D public uint NumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); - public IReadOnlyList> TemplateParameterLists => _templateParameterLists.Value; + public IReadOnlyList> TemplateParameterLists => _templateParameterLists; public TypedefNameDecl? TypedefNameForAnonDecl => _typedefNameForAnonDecl.Value; } diff --git a/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs index 706d1ebb..6e146b16 100644 --- a/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs @@ -1,17 +1,17 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using ClangSharp.Interop; -using static ClangSharp.Interop.CX_DeclKind; using System; using System.Collections.Generic; +using ClangSharp.Interop; +using static ClangSharp.Interop.CX_DeclKind; namespace ClangSharp; public class TemplateDecl : NamedDecl { - private readonly Lazy> _associatedConstraints; - private readonly Lazy _templatedDecl; - private readonly Lazy> _templateParameters; + private readonly LazyList _associatedConstraints; + private readonly ValueLazy _templatedDecl; + private readonly LazyList _templateParameters; private protected TemplateDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -20,38 +20,16 @@ private protected TemplateDecl(CXCursor handle, CXCursorKind expectedCursorKind, throw new ArgumentOutOfRangeException(nameof(handle)); } - _associatedConstraints = new Lazy>(() => { - var associatedConstraintCount = Handle.NumAssociatedConstraints; - var associatedConstraints = new List(associatedConstraintCount); - - for (var i = 0; i < associatedConstraintCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i))); - associatedConstraints.Add(parameter); - } - - return associatedConstraints; - }); - _templatedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplatedDecl)); - _templateParameters = new Lazy>(() => { - var parameterCount = Handle.GetNumTemplateParameters(0); - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); + _associatedConstraints = LazyList.Create(Handle.NumAssociatedConstraints, (i) => TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i)))); + _templatedDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplatedDecl)); + _templateParameters = LazyList.Create(Handle.GetNumTemplateParameters(0), (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i)))); } - public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; + public IReadOnlyList AssociatedConstraints => _associatedConstraints; public bool HasAssociatedConstraints => AssociatedConstraints.Count != 0; public NamedDecl TemplatedDecl => _templatedDecl.Value; - public IReadOnlyList TemplateParameters => _templateParameters.Value; + public IReadOnlyList TemplateParameters => _templateParameters; } diff --git a/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs b/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs index 5a8bd14b..f308d79a 100644 --- a/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class TemplateTemplateParmDecl : TemplateDecl, ITemplateParmPosition { - private readonly Lazy _defaultArgument; + private readonly ValueLazy _defaultArgument; internal TemplateTemplateParmDecl(CXCursor handle) : base(handle, CXCursor_TemplateTemplateParameter, CX_DeclKind_TemplateTemplateParm) { - _defaultArgument = new Lazy(() => TranslationUnit.GetOrCreate(handle.GetTemplateArgumentLoc(0))); + _defaultArgument = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.GetTemplateArgumentLoc(0))); } public TemplateArgumentLoc DefaultArgument => _defaultArgument.Value; diff --git a/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs b/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs index ca0f4b1f..a118b9bc 100644 --- a/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs @@ -3,38 +3,27 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed class TemplateTypeParmDecl : TypeDecl { - private readonly Lazy> _associatedConstraints; - private readonly Lazy _defaultArgument; + private readonly LazyList _associatedConstraints; + private readonly ValueLazy _defaultArgument; internal TemplateTypeParmDecl(CXCursor handle) : base(handle, CXCursor_TemplateTypeParameter, CX_DeclKind_TemplateTypeParm) { - _associatedConstraints = new Lazy>(() => { - var associatedConstraintCount = Handle.NumAssociatedConstraints; - var associatedConstraints = new List(associatedConstraintCount); - - for (var i = 0; i < associatedConstraintCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i))); - associatedConstraints.Add(parameter); - } - - return associatedConstraints; - }); - _defaultArgument = new Lazy(() => { - CXType defaultArgType = Handle.DefaultArgType; + _associatedConstraints = LazyList.Create(Handle.NumAssociatedConstraints, (i) => TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i)))); + _defaultArgument = new ValueLazy(() => { + var defaultArgType = Handle.DefaultArgType; return defaultArgType.kind == CXType_Invalid ? null : TranslationUnit.GetOrCreate(defaultArgType); }); } - public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; + public IReadOnlyList AssociatedConstraints => _associatedConstraints; public Type? DefaultArgument => _defaultArgument.Value; diff --git a/sources/ClangSharp/Cursors/Decls/TopLevelStmtDecl.cs b/sources/ClangSharp/Cursors/Decls/TopLevelStmtDecl.cs index a171987d..fd455390 100644 --- a/sources/ClangSharp/Cursors/Decls/TopLevelStmtDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TopLevelStmtDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class TopLevelStmtDecl : Decl { - private readonly Lazy _stmt; + private readonly ValueLazy _stmt; internal TopLevelStmtDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_TopLevelStmt) { - _stmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _stmt = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } public LabelStmt Stmt => _stmt.Value; diff --git a/sources/ClangSharp/Cursors/Decls/TypeDecl.cs b/sources/ClangSharp/Cursors/Decls/TypeDecl.cs index a282ec7f..b6044083 100644 --- a/sources/ClangSharp/Cursors/Decls/TypeDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TypeDecl.cs @@ -8,7 +8,7 @@ namespace ClangSharp; public class TypeDecl : NamedDecl { - private readonly Lazy _typeForDecl; + private readonly ValueLazy _typeForDecl; private protected TypeDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -17,7 +17,7 @@ private protected TypeDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_ throw new ArgumentOutOfRangeException(nameof(handle)); } - _typeForDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Type)); + _typeForDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Type)); } public Type TypeForDecl => _typeForDecl.Value; diff --git a/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs b/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs index 4c43d75e..540e541e 100644 --- a/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs @@ -8,7 +8,7 @@ namespace ClangSharp; public class TypedefNameDecl : TypeDecl, IRedeclarable { - private readonly Lazy _underlyingType; + private readonly ValueLazy _underlyingType; private protected TypedefNameDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -17,7 +17,7 @@ private protected TypedefNameDecl(CXCursor handle, CXCursorKind expectedCursorKi throw new ArgumentOutOfRangeException(nameof(handle)); } - _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypedefDeclUnderlyingType)); + _underlyingType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypedefDeclUnderlyingType)); } public new TypedefNameDecl CanonicalDecl => (TypedefNameDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/UsingEnumDecl.cs b/sources/ClangSharp/Cursors/Decls/UsingEnumDecl.cs index 5888d423..42c7d757 100644 --- a/sources/ClangSharp/Cursors/Decls/UsingEnumDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/UsingEnumDecl.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class UsingEnumDecl : BaseUsingDecl, IMergeable { - private readonly Lazy _enumDecl; + private readonly ValueLazy _enumDecl; internal UsingEnumDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_UsingEnum) { - _enumDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _enumDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); } public new UsingEnumDecl CanonicalDecl => (UsingEnumDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/ValueDecl.cs b/sources/ClangSharp/Cursors/Decls/ValueDecl.cs index 13b97501..60729590 100644 --- a/sources/ClangSharp/Cursors/Decls/ValueDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ValueDecl.cs @@ -8,7 +8,7 @@ namespace ClangSharp; public class ValueDecl : NamedDecl { - private readonly Lazy _type; + private readonly ValueLazy _type; private protected ValueDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -17,7 +17,7 @@ private protected ValueDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX throw new ArgumentOutOfRangeException(nameof(handle)); } - _type = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Type)); + _type = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Type)); } public Type Type => _type.Value; diff --git a/sources/ClangSharp/Cursors/Decls/VarDecl.cs b/sources/ClangSharp/Cursors/Decls/VarDecl.cs index b68067b7..d406867b 100644 --- a/sources/ClangSharp/Cursors/Decls/VarDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/VarDecl.cs @@ -9,9 +9,9 @@ namespace ClangSharp; public class VarDecl : DeclaratorDecl, IRedeclarable { - private readonly Lazy _definition; - private readonly Lazy _init; - private readonly Lazy _instantiatedFromStaticDataMember; + private readonly ValueLazy _definition; + private readonly ValueLazy _init; + private readonly ValueLazy _instantiatedFromStaticDataMember; internal VarDecl(CXCursor handle) : this(handle, CXCursor_VarDecl, CX_DeclKind_Var) { @@ -24,9 +24,9 @@ private protected VarDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_D throw new ArgumentOutOfRangeException(nameof(handle)); } - _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); - _init = new Lazy(() => TranslationUnit.GetOrCreate(handle.InitExpr)); - _instantiatedFromStaticDataMember = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _definition = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _init = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.InitExpr)); + _instantiatedFromStaticDataMember = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); } public new VarDecl CanonicalDecl => (VarDecl)base.CanonicalDecl; diff --git a/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs index d44d7087..37f3da16 100644 --- a/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs @@ -3,51 +3,29 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public class VarTemplatePartialSpecializationDecl : VarDecl { - private readonly Lazy> _associatedConstraints; - private readonly Lazy _instantiatedFromMember; - private readonly Lazy> _templateParameters; + private readonly LazyList _associatedConstraints; + private readonly ValueLazy _instantiatedFromMember; + private readonly LazyList _templateParameters; internal VarTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_VarTemplatePartialSpecialization) { - _associatedConstraints = new Lazy>(() => { - var associatedConstraintCount = Handle.NumAssociatedConstraints; - var associatedConstraints = new List(associatedConstraintCount); - - for (var i = 0; i < associatedConstraintCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i))); - associatedConstraints.Add(parameter); - } - - return associatedConstraints; - }); - _instantiatedFromMember = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); - _templateParameters = new Lazy>(() => { - var parameterCount = Handle.GetNumTemplateParameters(0); - var parameters = new List(parameterCount); - - for (var i = 0; i < parameterCount; i++) - { - var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i))); - parameters.Add(parameter); - } - - return parameters; - }); + _associatedConstraints = LazyList.Create(Handle.NumAssociatedConstraints, (i) => TranslationUnit.GetOrCreate(Handle.GetAssociatedConstraint(unchecked((uint)i)))); + _instantiatedFromMember = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _templateParameters = LazyList.Create(Handle.GetNumTemplateParameters(0), (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i)))); } - public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; + public IReadOnlyList AssociatedConstraints => _associatedConstraints; public VarTemplatePartialSpecializationDecl InstantiatedFromMember => _instantiatedFromMember.Value; public new VarTemplatePartialSpecializationDecl MostRecentDecl => (VarTemplatePartialSpecializationDecl)base.MostRecentDecl; - public IReadOnlyList TemplateParameters => _templateParameters.Value; + public IReadOnlyList TemplateParameters => _templateParameters; } diff --git a/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs index 9aed8a7f..2544dab8 100644 --- a/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs @@ -3,15 +3,15 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public class VarTemplateSpecializationDecl : VarDecl { - private readonly Lazy _specializedTemplate; - private readonly Lazy> _templateArgs; + private readonly ValueLazy _specializedTemplate; + private readonly LazyList _templateArgs; internal VarTemplateSpecializationDecl(CXCursor handle) : this(handle, CXCursor_UnexposedDecl, CX_DeclKind_VarTemplateSpecialization) { @@ -24,24 +24,13 @@ private protected VarTemplateSpecializationDecl(CXCursor handle, CXCursorKind ex throw new ArgumentOutOfRangeException(nameof(handle)); } - _specializedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _specializedTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } public new VarTemplateSpecializationDecl MostRecentDecl => (VarTemplateSpecializationDecl)base.MostRecentDecl; public VarTemplateDecl SpecializedTemplate => _specializedTemplate.Value; - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs b/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs index 9f81c1ed..6e282a8a 100644 --- a/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class AddrLabelExpr : Expr { - private readonly Lazy _label; + private readonly ValueLazy _label; internal AddrLabelExpr(CXCursor handle) : base(handle, CXCursor_AddrLabelExpr, CX_StmtClass_AddrLabelExpr) { Debug.Assert(NumChildren is 0); - _label = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _label = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public LabelDecl Label => _label.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/OMPArraySectionExpr.cs b/sources/ClangSharp/Cursors/Exprs/ArraySectionExpr.cs similarity index 65% rename from sources/ClangSharp/Cursors/Exprs/OMPArraySectionExpr.cs rename to sources/ClangSharp/Cursors/Exprs/ArraySectionExpr.cs index 57149e2e..b5ab3979 100644 --- a/sources/ClangSharp/Cursors/Exprs/OMPArraySectionExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ArraySectionExpr.cs @@ -6,9 +6,9 @@ namespace ClangSharp; -public sealed class OMPArraySectionExpr : Expr +public sealed class ArraySectionExpr : Expr { - internal OMPArraySectionExpr(CXCursor handle) : base(handle, CXCursor_OMPArraySectionExpr, CX_StmtClass_OMPArraySectionExpr) + internal ArraySectionExpr(CXCursor handle) : base(handle, CXCursor_ArraySectionExpr, CX_StmtClass_ArraySectionExpr) { } } diff --git a/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs b/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs index a7fd1919..1220a135 100644 --- a/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_AtomicOperatorKind; @@ -12,13 +11,13 @@ namespace ClangSharp; public sealed class AtomicExpr : Expr { - private readonly Lazy> _subExprs; - private readonly Lazy _valueType; + private readonly LazyList _subExprs; + private readonly ValueLazy _valueType; internal AtomicExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_AtomicExpr) { - _subExprs = new Lazy>(() => Children.Cast().ToList()); - _valueType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _subExprs = LazyList.Create(_children); + _valueType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public CX_AtomicOperatorKind Op => Handle.AtomicOperatorKind; @@ -31,9 +30,11 @@ internal AtomicExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_S public Expr Ptr => SubExprs[0]; - public Expr? Scope => (Op is >= CX_AO__opencl_atomic_load and <= CX_AO__opencl_atomic_fetch_max) ? SubExprs[(int)(NumSubExprs - 1)] : null; + public Expr? Scope => (Op is (>= CX_AO__opencl_atomic_compare_exchange_strong and <= CX_AO__opencl_atomic_store and not CX_AO__opencl_atomic_init) + or (>= CX_AO__hip_atomic_compare_exchange_strong and <= CX_AO__hip_atomic_store) + or (>= CX_AO__scoped_atomic_add_fetch and <= CX_AO__scoped_atomic_xor_fetch)) ? SubExprs[(int)(NumSubExprs - 1)] : null; - public IReadOnlyList SubExprs => _subExprs.Value; + public IReadOnlyList SubExprs => _subExprs; public Expr? Val1 { diff --git a/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs b/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs index 3de99d52..64ae75bc 100644 --- a/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class BinaryConditionalOperator : AbstractConditionalOperator { - private readonly Lazy _opaqueValue; + private readonly ValueLazy _opaqueValue; internal BinaryConditionalOperator(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_BinaryConditionalOperator) { Debug.Assert(NumChildren is 4); - _opaqueValue = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OpaqueValue)); + _opaqueValue = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OpaqueValue)); } public Expr Common => (Expr)Children[0]; diff --git a/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs b/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs index c1ed5c95..4346a97e 100644 --- a/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class BlockExpr : Expr { - private readonly Lazy _blockDecl; + private readonly ValueLazy _blockDecl; internal BlockExpr(CXCursor handle) : base(handle, CXCursor_BlockExpr, CX_StmtClass_BlockExpr) { Debug.Assert(NumChildren is 0); - _blockDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _blockDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public BlockDecl BlockDecl => _blockDecl.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs index 108c5d1a..e706c6fd 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs @@ -11,13 +11,13 @@ namespace ClangSharp; public sealed class CXXBoolLiteralExpr : Expr { - private readonly Lazy _valueString; + private readonly ValueLazy _valueString; internal CXXBoolLiteralExpr(CXCursor handle) : base(handle, CXCursor_CXXBoolLiteralExpr, CX_StmtClass_CXXBoolLiteralExpr) { Debug.Assert(NumChildren is 0); - _valueString = new Lazy(() => { + _valueString = new ValueLazy(() => { var tokens = Handle.TranslationUnit.Tokenize(Handle.SourceRange); if ((tokens.Length == 0) || (tokens[0].Kind is not CXToken_Keyword and not CXToken_Identifier)) diff --git a/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs index b24c706f..03c749e7 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -12,8 +11,8 @@ namespace ClangSharp; public class CXXConstructExpr : Expr { - private readonly Lazy> _args; - private readonly Lazy _constructor; + private readonly LazyList _args; + private readonly ValueLazy _constructor; internal CXXConstructExpr(CXCursor handle) : this(handle, CXCursor_CallExpr, CX_StmtClass_CXXConstructExpr) { @@ -27,11 +26,11 @@ private protected CXXConstructExpr(CXCursor handle, CXCursorKind expectedCursorK } Debug.Assert(NumChildren == NumArgs); - _args = new Lazy>(() => Children.Cast().ToList()); - _constructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _args = LazyList.Create(_children); + _constructor = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } - public IReadOnlyList Args => _args.Value; + public IReadOnlyList Args => _args; public CXXConstructorDecl Constructor => _constructor.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs index c4180a7d..b3b48670 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs @@ -10,15 +10,15 @@ namespace ClangSharp; public sealed class CXXDefaultArgExpr : Expr { - private readonly Lazy _param; - private readonly Lazy _usedContext; + private readonly ValueLazy _param; + private readonly ValueLazy _usedContext; internal CXXDefaultArgExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_CXXDefaultArgExpr) { Debug.Assert(NumChildren is 0); - _param = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _usedContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UsedContext) as IDeclContext); + _param = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _usedContext = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UsedContext) as IDeclContext); } public ParmVarDecl Param => _param.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs index 0d1e0609..0b1908e4 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs @@ -10,15 +10,15 @@ namespace ClangSharp; public sealed class CXXDefaultInitExpr : Expr { - private readonly Lazy _field; - private readonly Lazy _usedContext; + private readonly ValueLazy _field; + private readonly ValueLazy _usedContext; internal CXXDefaultInitExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_CXXDefaultInitExpr) { Debug.Assert(NumChildren is 0); - _field = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _usedContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UsedContext) as IDeclContext); + _field = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _usedContext = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UsedContext) as IDeclContext); } public Expr Expr => Field.InClassInitializer; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs index 5b7ce069..6c1272cb 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs @@ -10,15 +10,15 @@ namespace ClangSharp; public sealed class CXXDeleteExpr : Expr { - private readonly Lazy _destroyedType; - private readonly Lazy _operatorDelete; + private readonly ValueLazy _destroyedType; + private readonly ValueLazy _operatorDelete; internal CXXDeleteExpr(CXCursor handle) : base(handle, CXCursor_CXXDeleteExpr, CX_StmtClass_CXXDeleteExpr) { Debug.Assert(NumChildren is 1); - _destroyedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - _operatorDelete = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _destroyedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _operatorDelete = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public Expr Argument => (Expr)Children[0]; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs index 1e85bc6f..41998327 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs @@ -5,35 +5,24 @@ using System.Diagnostics; using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class CXXDependentScopeMemberExpr : Expr { - private readonly Lazy _baseType; - private readonly Lazy _firstQualifierFoundInScope; - private readonly Lazy> _templateArgs; + private readonly ValueLazy _baseType; + private readonly ValueLazy _firstQualifierFoundInScope; + private readonly LazyList _templateArgs; internal CXXDependentScopeMemberExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_StmtClass_CXXDependentScopeMemberExpr) { Debug.Assert(NumChildren is 0 or 1); - _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - _firstQualifierFoundInScope = new Lazy(() => TranslationUnit.GetOrCreate(handle.Referenced)); - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _baseType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _firstQualifierFoundInScope = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.Referenced)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i)))); } public Expr? Base => (Expr?)Children.SingleOrDefault(); @@ -54,5 +43,5 @@ internal CXXDependentScopeMemberExpr(CXCursor handle) : base(handle, CXCursor_Me public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs index 9f49018c..a32fd684 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs @@ -11,12 +11,12 @@ namespace ClangSharp; public sealed class CXXInheritedCtorInitExpr : Expr { - private readonly Lazy _constructor; + private readonly ValueLazy _constructor; internal CXXInheritedCtorInitExpr(CXCursor handle) : base(handle, CXCursor_CallExpr, CX_StmtClass_CXXInheritedCtorInitExpr) { Debug.Assert(NumChildren is 0); - _constructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _constructor = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public CX_ConstructionKind ConstructionKind => ConstructsVBase ? CX_CK_VirtualBase : CX_CK_NonVirtualBase; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs index bb2d5970..27fc2039 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,15 +10,15 @@ namespace ClangSharp; public sealed class CXXNewExpr : Expr { - private readonly Lazy _operatorDelete; - private readonly Lazy _operatorNew; - private readonly Lazy> _placementArgs; + private readonly ValueLazy _operatorDelete; + private readonly ValueLazy _operatorNew; + private readonly LazyList _placementArgs; internal CXXNewExpr(CXCursor handle) : base(handle, CXCursor_CXXNewExpr, CX_StmtClass_CXXNewExpr) { - _operatorDelete = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(0))); - _operatorNew = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(1))); - _placementArgs = new Lazy>(() => Children.Skip(PlacementNewArgsOffset).Cast().ToList()); + _operatorDelete = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(0))); + _operatorNew = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(1))); + _placementArgs = LazyList.Create(_children, skip: PlacementNewArgsOffset); } public Type AllocatedType => ((PointerType)Type).PointeeType; @@ -44,7 +43,7 @@ internal CXXNewExpr(CXCursor handle) : base(handle, CXCursor_CXXNewExpr, CX_Stmt public FunctionDecl OperatorNew => _operatorNew.Value; - public IReadOnlyList PlacementArgs => _placementArgs.Value; + public IReadOnlyList PlacementArgs => _placementArgs; private static int ArraySizeOffset => 0; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXParenListInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXParenListInitExpr.cs index a850d718..3d118c5a 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXParenListInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXParenListInitExpr.cs @@ -1,53 +1,31 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System.Collections.Generic; using System; +using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class CXXParenListInitExpr : Expr { - private readonly Lazy _arrayFillerOrUnionFieldInit; - private readonly Lazy> _initExprs; - private readonly Lazy> _userSpecifiedInitExprs; + private readonly ValueLazy _arrayFillerOrUnionFieldInit; + private readonly LazyList _initExprs; + private readonly LazyList _userSpecifiedInitExprs; internal CXXParenListInitExpr(CXCursor handle) : base(handle, CXCursor_CXXParenListInitExpr, CX_StmtClass_CXXParenListInitExpr) { - _arrayFillerOrUnionFieldInit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); - _initExprs = new Lazy>(() => { - var numInitExprs = Handle.NumExprs; - var initExprs = new List(numInitExprs); - - for (var i = 0; i < numInitExprs; i++) - { - var initExpr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); - initExprs.Add(initExpr); - } - - return initExprs; - }); - _userSpecifiedInitExprs = new Lazy>(() => { - var numUserSpecifiedInitExprs = Handle.NumExprsOther; - var userSpecifiedInitExprs = new List(numUserSpecifiedInitExprs); - - for (var i = 0; i < numUserSpecifiedInitExprs; i++) - { - var initExpr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); - userSpecifiedInitExprs.Add(initExpr); - } - - return userSpecifiedInitExprs; - }); + _arrayFillerOrUnionFieldInit = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + _initExprs = LazyList.Create(Handle.NumExprs, (i) => TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i)))); + _userSpecifiedInitExprs = LazyList.Create(Handle.NumExprsOther, (i) => TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i)))); } public Expr? ArrayFiller => _arrayFillerOrUnionFieldInit.Value as Expr; - public IReadOnlyList InitExprs => _initExprs.Value; + public IReadOnlyList InitExprs => _initExprs; public FieldDecl? InitializedFieldInUnion => _arrayFillerOrUnionFieldInit.Value as FieldDecl; - public IReadOnlyList UserSpecifiedInitExprs => _userSpecifiedInitExprs.Value; + public IReadOnlyList UserSpecifiedInitExprs => _userSpecifiedInitExprs; } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs index 9ae182cb..2786d77c 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class CXXPseudoDestructorExpr : Expr { - private readonly Lazy _destroyedType; + private readonly ValueLazy _destroyedType; internal CXXPseudoDestructorExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_StmtClass_CXXPseudoDestructorExpr) { Debug.Assert(NumChildren is 1); - _destroyedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _destroyedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public Expr Base => (Expr)Children[0]; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs b/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs index d1de6a59..425b307b 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs @@ -10,15 +10,15 @@ namespace ClangSharp; public sealed class CXXRewrittenBinaryOperator : Expr { - private readonly Lazy _lhs; - private readonly Lazy _rhs; + private readonly ValueLazy _lhs; + private readonly ValueLazy _rhs; internal CXXRewrittenBinaryOperator(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_CXXRewrittenBinaryOperator) { Debug.Assert(NumChildren is 1); - _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); - _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); + _lhs = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); + _rhs = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); } public Expr LHS => _lhs.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs index 4a79e38b..3ea071f6 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class CXXScalarValueInitExpr : Expr { - private readonly Lazy _typeSourceInfoType; + private readonly ValueLazy _typeSourceInfoType; internal CXXScalarValueInitExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_CXXScalarValueInitExpr) { Debug.Assert(NumChildren is 0); - _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _typeSourceInfoType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public Type TypeSourceInfoType => _typeSourceInfoType.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs index 31e25694..ded5561d 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class CXXTemporaryObjectExpr : CXXConstructExpr { - private readonly Lazy _typeSourceInfoType; + private readonly ValueLazy _typeSourceInfoType; internal CXXTemporaryObjectExpr(CXCursor handle) : base(handle, CXCursor_CallExpr, CX_StmtClass_CXXTemporaryObjectExpr) { - _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _typeSourceInfoType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public Type TypeSourceInfoType => _typeSourceInfoType.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs index b90efcdc..a6e9249c 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs @@ -11,12 +11,12 @@ namespace ClangSharp; public sealed class CXXTypeidExpr : Expr { - private readonly Lazy _typeOperand; + private readonly ValueLazy _typeOperand; internal CXXTypeidExpr(CXCursor handle) : base(handle, CXCursor_CXXTypeidExpr, CX_StmtClass_CXXTypeidExpr) { Debug.Assert(NumChildren is 0 or 1); - _typeOperand = new Lazy(() => TranslationUnit.GetOrCreate(handle.TypeOperand)); + _typeOperand = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.TypeOperand)); } public Expr? ExprOperand => (Expr?)Children.SingleOrDefault(); diff --git a/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs index 1d1bdf40..82558693 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,16 +10,16 @@ namespace ClangSharp; public sealed class CXXUnresolvedConstructExpr : Expr { - private readonly Lazy> _args; - private readonly Lazy _typeAsWritten; + private readonly LazyList _args; + private readonly ValueLazy _typeAsWritten; internal CXXUnresolvedConstructExpr(CXCursor handle) : base(handle, CXCursor_CallExpr, CX_StmtClass_CXXUnresolvedConstructExpr) { - _args = new Lazy>(() => Children.Cast().ToList()); - _typeAsWritten = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _args = LazyList.Create(_children); + _typeAsWritten = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } - public IReadOnlyList Args => _args.Value; + public IReadOnlyList Args => _args; public bool IsListInitialization => Handle.IsListInitialization; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs index 5873afa4..19ac1b64 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs @@ -11,15 +11,15 @@ namespace ClangSharp; public sealed class CXXUuidofExpr : Expr { - private readonly Lazy _typeOperand; - private readonly Lazy _guidDecl; + private readonly ValueLazy _typeOperand; + private readonly ValueLazy _guidDecl; internal CXXUuidofExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_CXXUuidofExpr) { Debug.Assert(NumChildren is 0 or 1); - _typeOperand = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - _guidDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _typeOperand = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _guidDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public Expr? ExprOperand => (Expr?)Children.SingleOrDefault(); diff --git a/sources/ClangSharp/Cursors/Exprs/CallExpr.cs b/sources/ClangSharp/Cursors/Exprs/CallExpr.cs index 0fb2f058..9f2076e7 100644 --- a/sources/ClangSharp/Cursors/Exprs/CallExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CallExpr.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -12,8 +11,8 @@ namespace ClangSharp; public class CallExpr : Expr { - private readonly Lazy> _args; - private readonly Lazy _calleeDecl; + private readonly LazyList _args; + private readonly ValueLazy _calleeDecl; internal CallExpr(CXCursor handle) : this(handle, CXCursor_CallExpr, CX_StmtClass_CallExpr) { @@ -28,11 +27,11 @@ private protected CallExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_ Debug.Assert(NumChildren >= 1); - _args = new Lazy>(() => Children.Skip(1).Take((int)NumArgs).Cast().ToList()); - _calleeDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _args = LazyList.Create(_children, skip: 1, take: (int)NumArgs); + _calleeDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } - public IReadOnlyList Args => _args.Value; + public IReadOnlyList Args => _args; public Expr Callee => (Expr)Children[0]; diff --git a/sources/ClangSharp/Cursors/Exprs/CastExpr.cs b/sources/ClangSharp/Cursors/Exprs/CastExpr.cs index e69580a8..c5d56d51 100644 --- a/sources/ClangSharp/Cursors/Exprs/CastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CastExpr.cs @@ -11,8 +11,8 @@ namespace ClangSharp; public class CastExpr : Expr { - private readonly Lazy> _path; - private readonly Lazy _targetUnionField; + private readonly LazyList _path; + private readonly ValueLazy _targetUnionField; private protected CastExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { @@ -23,19 +23,8 @@ private protected CastExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_ Debug.Assert(NumChildren is 1); - _path = new Lazy>(() => { - var pathSize = Handle.NumArguments; - var path = new List(pathSize); - - for (var i = 0; i < pathSize; i++) - { - var item = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - path.Add(item); - } - - return path; - }); - _targetUnionField = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TargetUnionField)); + _path = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); + _targetUnionField = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TargetUnionField)); } public CX_CastKind CastKind => Handle.CastKind; @@ -72,7 +61,7 @@ public NamedDecl? ConversionFunction public bool PathEmpty => PathSize == 0; - public IReadOnlyList Path => _path.Value; + public IReadOnlyList Path => _path; public uint PathSize => unchecked((uint)Handle.NumArguments); diff --git a/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs b/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs index 3741af7f..7f3addf1 100644 --- a/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs @@ -12,13 +12,13 @@ namespace ClangSharp; public sealed class CharacterLiteral : Expr { - private readonly Lazy _valueString; + private readonly ValueLazy _valueString; internal CharacterLiteral(CXCursor handle) : base(handle, CXCursor_CharacterLiteral, CX_StmtClass_CharacterLiteral) { Debug.Assert(NumChildren is 0); - _valueString = new Lazy(() => { + _valueString = new ValueLazy(() => { var tokens = Handle.TranslationUnit.Tokenize(Handle.SourceRange); if ((tokens.Length == 0) || (tokens[0].Kind is not CXToken_Literal and not CXToken_Identifier)) diff --git a/sources/ClangSharp/Cursors/Exprs/CompoundAssignOperator.cs b/sources/ClangSharp/Cursors/Exprs/CompoundAssignOperator.cs index 435b09b2..d3903c7a 100644 --- a/sources/ClangSharp/Cursors/Exprs/CompoundAssignOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/CompoundAssignOperator.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class CompoundAssignOperator : BinaryOperator { - private readonly Lazy _computationLHSType; - private readonly Lazy _computationResultType; + private readonly ValueLazy _computationLHSType; + private readonly ValueLazy _computationResultType; internal CompoundAssignOperator(CXCursor handle) : base(handle, CXCursor_CompoundAssignOperator, CX_StmtClass_CompoundAssignOperator) { - _computationLHSType = new Lazy(() => TranslationUnit.GetOrCreate(handle.ComputationLhsType)); - _computationResultType = new Lazy(() => TranslationUnit.GetOrCreate(handle.ComputationResultType)); + _computationLHSType = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.ComputationLhsType)); + _computationResultType = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.ComputationResultType)); } public Type ComputationLHSType => _computationLHSType.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs b/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs index 5cb661d6..3316992c 100644 --- a/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class CompoundLiteralExpr : Expr { - private readonly Lazy _typeSourceInfoType; + private readonly ValueLazy _typeSourceInfoType; internal CompoundLiteralExpr(CXCursor handle) : base(handle, CXCursor_CompoundLiteralExpr, CX_StmtClass_CompoundLiteralExpr) { Debug.Assert(NumChildren is 1); - _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _typeSourceInfoType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public bool IsFileScope => Handle.IsFileScope; diff --git a/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs index 826e1cdd..83915f4a 100644 --- a/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs @@ -4,16 +4,16 @@ using System.Collections.Generic; using System.Diagnostics; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class DeclRefExpr : Expr { - private readonly Lazy _decl; - private readonly Lazy _foundDecl; - private readonly Lazy> _templateArgs; + private readonly ValueLazy _decl; + private readonly ValueLazy _foundDecl; + private readonly LazyList _templateArgs; internal DeclRefExpr(CXCursor handle) : base(handle, handle.Kind, CX_StmtClass_DeclRefExpr) { @@ -24,21 +24,9 @@ internal DeclRefExpr(CXCursor handle) : base(handle, handle.Kind, CX_StmtClass_D Debug.Assert(NumChildren is 0); - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _foundDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FoundDecl)); - - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _foundDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.FoundDecl)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i)))); } public ValueDecl Decl => _decl.Value; @@ -55,5 +43,5 @@ internal DeclRefExpr(CXCursor handle) : base(handle, handle.Kind, CX_StmtClass_D public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs index 6798c20a..793df4cf 100644 --- a/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs @@ -1,34 +1,21 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using System.Diagnostics; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class DependentScopeDeclRefExpr : Expr { - private readonly Lazy> _templateArgs; + private readonly LazyList _templateArgs; internal DependentScopeDeclRefExpr(CXCursor handle) : base(handle, CXCursor_DeclRefExpr, CX_StmtClass_DependentScopeDeclRefExpr) { Debug.Assert(NumChildren is 0); - - _templateArgs = new Lazy>(() => { - var numTemplateArgs = Handle.NumTemplateArguments; - var templateArgs = new List(numTemplateArgs); - - for (var i = 0; i < numTemplateArgs; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i)))); } public string DeclName => Handle.Name.CString; @@ -37,5 +24,5 @@ internal DependentScopeDeclRefExpr(CXCursor handle) : base(handle, CXCursor_Decl public bool HasTemplateKeyword => Handle.HasTemplateKeyword; - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs index 6c066bab..1dc88bec 100644 --- a/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs @@ -8,7 +8,7 @@ namespace ClangSharp; public class ExplicitCastExpr : CastExpr { - private readonly Lazy _typeAsWritten; + private readonly ValueLazy _typeAsWritten; private protected ExplicitCastExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { @@ -17,7 +17,7 @@ private protected ExplicitCastExpr(CXCursor handle, CXCursorKind expectedCursorK throw new ArgumentOutOfRangeException(nameof(handle)); } - _typeAsWritten = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _typeAsWritten = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public Type TypeAsWritten => _typeAsWritten.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/Expr.cs b/sources/ClangSharp/Cursors/Exprs/Expr.cs index 331ca03a..4d5debe7 100644 --- a/sources/ClangSharp/Cursors/Exprs/Expr.cs +++ b/sources/ClangSharp/Cursors/Exprs/Expr.cs @@ -57,7 +57,7 @@ public class Expr : ValueStmt return e; }; - private readonly Lazy _type; + private readonly ValueLazy _type; private protected Expr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { @@ -66,7 +66,7 @@ private protected Expr(CXCursor handle, CXCursorKind expectedCursorKind, CX_Stmt throw new ArgumentOutOfRangeException(nameof(handle)); } - _type = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Type)); + _type = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Type)); } public bool ContainsErrors => (Dependence & CX_ED_Error) != 0; diff --git a/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs b/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs index ddc57336..648cd5a4 100644 --- a/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs +++ b/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs @@ -1,34 +1,22 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ExprWithCleanups : FullExpr { - private readonly Lazy> _objects; + private readonly LazyList _objects; internal ExprWithCleanups(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_ExprWithCleanups) { - _objects = new Lazy>(() => { - var numObjects = Handle.NumArguments; - var objects = new List(numObjects); - - for (var i = 0; i < numObjects; i++) - { - var obj = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - objects.Add(obj); - } - - return objects; - }); + _objects = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); } public uint NumObjects => unchecked((uint)Handle.NumArguments); - public IReadOnlyList Objects => _objects.Value; + public IReadOnlyList Objects => _objects; } diff --git a/sources/ClangSharp/Cursors/Exprs/FloatingLiteral.cs b/sources/ClangSharp/Cursors/Exprs/FloatingLiteral.cs index b99fbeb6..fd6d4afc 100644 --- a/sources/ClangSharp/Cursors/Exprs/FloatingLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/FloatingLiteral.cs @@ -12,11 +12,11 @@ namespace ClangSharp; public sealed class FloatingLiteral : Expr { - private readonly Lazy _valueString; + private readonly ValueLazy _valueString; internal FloatingLiteral(CXCursor handle) : base(handle, CXCursor_FloatingLiteral, CX_StmtClass_FloatingLiteral) { - _valueString = new Lazy(() => { + _valueString = new ValueLazy(() => { var tokens = Handle.TranslationUnit.Tokenize(Handle.SourceRange); if ((tokens.Length == 0) || (tokens[0].Kind is not CXToken_Literal and not CXToken_Identifier)) diff --git a/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs b/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs index f406b5b7..fee590ae 100644 --- a/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs @@ -4,36 +4,25 @@ using System.Collections.Generic; using System.Diagnostics; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class FunctionParmPackExpr : Expr { - private readonly Lazy> _expansions; - private readonly Lazy _parameterPack; + private readonly LazyList _expansions; + private readonly ValueLazy _parameterPack; internal FunctionParmPackExpr(CXCursor handle) : base(handle, CXCursor_DeclRefExpr, CX_StmtClass_FunctionParmPackExpr) { Debug.Assert(NumChildren is 0); - _expansions = new Lazy>(() => { - var numExpansions = Handle.NumDecls; - var expansions = new List(numExpansions); - - for (var i = 0; i < numExpansions; i++) - { - var expansion = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); - expansions.Add(expansion); - } - - return expansions; - }); - _parameterPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _expansions = LazyList.Create(Handle.NumDecls, (i) => TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i)))); + _parameterPack = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } - public IReadOnlyList Expansions => _expansions.Value; + public IReadOnlyList Expansions => _expansions; public uint NumExpansions => unchecked((uint)Handle.NumDecls); diff --git a/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs b/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs index c1d1db04..aa1ec431 100644 --- a/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,14 +9,14 @@ namespace ClangSharp; public sealed class GenericSelectionExpr : Expr { - private readonly Lazy> _assocExprs; + private readonly LazyList _assocExprs; internal GenericSelectionExpr(CXCursor handle) : base(handle, CXCursor_GenericSelectionExpr, CX_StmtClass_GenericSelectionExpr) { - _assocExprs = new Lazy>(() => Children.Skip(1).Take((int)NumAssocs).Cast().ToList()); + _assocExprs = LazyList.Create(_children, skip: 1, take: (int)NumAssocs); } - public IReadOnlyList AssocExprs => _assocExprs.Value; + public IReadOnlyList AssocExprs => _assocExprs; public Expr ControllingExpr => (Expr)Children[0]; diff --git a/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs b/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs index aa3a9742..72850454 100644 --- a/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,15 +10,15 @@ namespace ClangSharp; public sealed class InitListExpr : Expr { - private readonly Lazy _arrayFiller; - private readonly Lazy _initializedFieldInUnion; - private readonly Lazy> _inits; + private readonly ValueLazy _arrayFiller; + private readonly ValueLazy _initializedFieldInUnion; + private readonly LazyList _inits; internal InitListExpr(CXCursor handle) : base(handle, CXCursor_InitListExpr, CX_StmtClass_InitListExpr) { - _arrayFiller = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); - _initializedFieldInUnion = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _inits = new Lazy>(() => Children.Cast().ToList()); + _arrayFiller = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + _initializedFieldInUnion = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _inits = LazyList.Create(_children); } public Expr ArrayFiller => _arrayFiller.Value; @@ -28,7 +27,7 @@ internal InitListExpr(CXCursor handle) : base(handle, CXCursor_InitListExpr, CX_ public FieldDecl InitializedFieldInUnion => _initializedFieldInUnion.Value; - public IReadOnlyList Inits => _inits.Value; + public IReadOnlyList Inits => _inits; public bool IsExplicit => !Handle.IsImplicit; diff --git a/sources/ClangSharp/Cursors/Exprs/IntegerLiteral.cs b/sources/ClangSharp/Cursors/Exprs/IntegerLiteral.cs index 976c965a..beb9c67b 100644 --- a/sources/ClangSharp/Cursors/Exprs/IntegerLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/IntegerLiteral.cs @@ -12,11 +12,11 @@ namespace ClangSharp; public sealed class IntegerLiteral : Expr { - private readonly Lazy _valueString; + private readonly ValueLazy _valueString; internal IntegerLiteral(CXCursor handle) : base(handle, CXCursor_IntegerLiteral, CX_StmtClass_IntegerLiteral) { - _valueString = new Lazy(() => { + _valueString = new ValueLazy(() => { var tokens = Handle.TranslationUnit.Tokenize(Handle.SourceRange); if ((tokens.Length == 0) || (tokens[0].Kind is not CXToken_Literal and not CXToken_Identifier)) diff --git a/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs b/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs index 82a3cfc2..48d96376 100644 --- a/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class MaterializeTemporaryExpr : Expr { - private readonly Lazy _lifetimeExtendedTemporaryDecl; + private readonly ValueLazy _lifetimeExtendedTemporaryDecl; internal MaterializeTemporaryExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_MaterializeTemporaryExpr) { - _lifetimeExtendedTemporaryDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _lifetimeExtendedTemporaryDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public ValueDecl ExtendingDecl => LifetimeExtendedTemporaryDecl.ExtendingDecl; diff --git a/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs b/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs index 465f0a40..61388818 100644 --- a/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs @@ -4,33 +4,22 @@ using System.Collections.Generic; using System.Diagnostics; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class MemberExpr : Expr { - private readonly Lazy _memberDecl; - private readonly Lazy> _templateArgs; + private readonly ValueLazy _memberDecl; + private readonly LazyList _templateArgs; internal MemberExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_StmtClass_MemberExpr) { Debug.Assert(NumChildren is 1); - _memberDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _memberDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i)))); } public Expr Base => (Expr)Children[0]; @@ -51,5 +40,5 @@ internal MemberExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_S public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs b/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs index b3433a04..a9e55a10 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,18 +10,18 @@ namespace ClangSharp; public sealed class ObjCArrayLiteral : Expr { - private readonly Lazy _arrayWithObjectsMethod; - private readonly Lazy> _elements; + private readonly ValueLazy _arrayWithObjectsMethod; + private readonly LazyList _elements; internal ObjCArrayLiteral(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_ObjCArrayLiteral) { - _arrayWithObjectsMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _elements = new Lazy>(() => Children.Cast().ToList()); + _arrayWithObjectsMethod = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _elements = LazyList.Create(_children); } public ObjCMethodDecl ArrayWithObjectsMethod => _arrayWithObjectsMethod.Value; - public IReadOnlyList Elements => _elements.Value; + public IReadOnlyList Elements => _elements; public uint NumElements => NumChildren; } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs index 0537c4a2..9088c34d 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class ObjCBoxedExpr : Expr { - private readonly Lazy _boxingMethod; + private readonly ValueLazy _boxingMethod; internal ObjCBoxedExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_ObjCBoxedExpr) { Debug.Assert(NumChildren is 1); - _boxingMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _boxingMethod = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public ObjCMethodDecl BoxingMethod => _boxingMethod.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs b/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs index c77597cf..820c4d6c 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs @@ -11,15 +11,15 @@ namespace ClangSharp; public sealed class ObjCDictionaryLiteral : Expr { - private readonly Lazy _dictWithObjectsMethod; - private readonly Lazy> _keyValueElements; + private readonly ValueLazy _dictWithObjectsMethod; + private readonly ValueLazy> _keyValueElements; internal ObjCDictionaryLiteral(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_ObjCDictionaryLiteral) { Debug.Assert((NumChildren % 2) == 0); - _dictWithObjectsMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _dictWithObjectsMethod = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _keyValueElements = new Lazy>(() => { + _keyValueElements = new ValueLazy>(() => { var numChildren = Handle.NumChildren; var keyValueElements = new List<(Expr Key, Expr Value)>(numChildren / 2); diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs index 79e1918d..69273d6e 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class ObjCEncodeExpr : Expr { - private readonly Lazy _encodedType; + private readonly ValueLazy _encodedType; internal ObjCEncodeExpr(CXCursor handle) : base(handle, CXCursor_ObjCEncodeExpr, CX_StmtClass_ObjCEncodeExpr) { Debug.Assert(NumChildren is 0); - _encodedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _encodedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public Type EncodedType => _encodedType.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs index cd186a8d..e3e8fad5 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class ObjCIvarRefExpr : Expr { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal ObjCIvarRefExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_StmtClass_ObjCIvarRefExpr) { Debug.Assert(NumChildren is 1); - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public Expr Base => (Expr)Children[0]; diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs index b8c75891..2ed3d7e6 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs @@ -3,43 +3,31 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class ObjCMessageExpr : Expr { - private readonly Lazy> _args; - private readonly Lazy _classReceiver; - private readonly Lazy _instanceReceiver; - private readonly Lazy _methodDecl; - private readonly Lazy _receiverType; - private readonly Lazy _superType; + private readonly LazyList _args; + private readonly ValueLazy _classReceiver; + private readonly ValueLazy _instanceReceiver; + private readonly ValueLazy _methodDecl; + private readonly ValueLazy _receiverType; + private readonly ValueLazy _superType; internal ObjCMessageExpr(CXCursor handle) : base(handle, CXCursor_ObjCMessageExpr, CX_StmtClass_ObjCMessageExpr) { - _args = new Lazy>(() => { - var numArgs = Handle.NumArguments; - var args = new List(numArgs); - - for (var i = 0; i < numArgs; i++) - { - var arg = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); - args.Add(arg); - } - - return args; - }); - - _classReceiver = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - _instanceReceiver = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); - _methodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _receiverType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReceiverType)); - _superType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisObjectType)); + _args = LazyList.Create(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i)))); + _classReceiver = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _instanceReceiver = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _methodDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _receiverType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ReceiverType)); + _superType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ThisObjectType)); } - public IReadOnlyList Args => _args.Value; + public IReadOnlyList Args => _args; public Type ClassReceiver => _classReceiver.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs index 28b277fa..4851c323 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs @@ -9,21 +9,21 @@ namespace ClangSharp; public sealed class ObjCPropertyRefExpr : Expr { - private readonly Lazy _base; - private readonly Lazy _classReceiver; - private readonly Lazy _explicitProperty; - private readonly Lazy _implicitPropertyGetter; - private readonly Lazy _implicitPropertySetter; - private readonly Lazy _superReceiverType; + private readonly ValueLazy _base; + private readonly ValueLazy _classReceiver; + private readonly ValueLazy _explicitProperty; + private readonly ValueLazy _implicitPropertyGetter; + private readonly ValueLazy _implicitPropertySetter; + private readonly ValueLazy _superReceiverType; internal ObjCPropertyRefExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_StmtClass_ObjCPropertyRefExpr) { - _base = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); - _classReceiver = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(0))); - _explicitProperty = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(1))); - _implicitPropertyGetter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(2))); - _implicitPropertySetter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(3))); - _superReceiverType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _base = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _classReceiver = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(0))); + _explicitProperty = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(1))); + _implicitPropertyGetter = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(2))); + _implicitPropertySetter = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(3))); + _superReceiverType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs index 53304d90..0e312de8 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class ObjCProtocolExpr : Expr { - private readonly Lazy _protocol; + private readonly ValueLazy _protocol; internal ObjCProtocolExpr(CXCursor handle) : base(handle, CXCursor_ObjCProtocolExpr, CX_StmtClass_ObjCProtocolExpr) { Debug.Assert(NumChildren is 0); - _protocol = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _protocol = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public ObjCProtocolDecl Protocol => _protocol.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs index 8d95aa35..c7fe326f 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class ObjCSubscriptRefExpr : Expr { - private readonly Lazy _atIndexMethodDecl; + private readonly ValueLazy _atIndexMethodDecl; internal ObjCSubscriptRefExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_ObjCSubscriptRefExpr) { Debug.Assert(NumChildren is 2); - _atIndexMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _atIndexMethodDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public ObjCMethodDecl AtIndexMethodDecl => _atIndexMethodDecl.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs b/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs index 75c9f639..1d078c0a 100644 --- a/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,18 +10,18 @@ namespace ClangSharp; public sealed class OffsetOfExpr : Expr { - private readonly Lazy> _indexExprs; - private readonly Lazy _referenced; - private readonly Lazy _typeSourceInfoType; + private readonly LazyList _indexExprs; + private readonly ValueLazy _referenced; + private readonly ValueLazy _typeSourceInfoType; internal OffsetOfExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_OffsetOfExpr) { - _indexExprs = new Lazy>(() => Children.Cast().ToList()); - _referenced = new Lazy(() => !Handle.Referenced.IsNull ? TranslationUnit.GetOrCreate(Handle.Referenced) : null); - _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _indexExprs = LazyList.Create(_children); + _referenced = new ValueLazy(() => !Handle.Referenced.IsNull ? TranslationUnit.GetOrCreate(Handle.Referenced) : null); + _typeSourceInfoType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } - public IReadOnlyList IndexExprs => _indexExprs.Value; + public IReadOnlyList IndexExprs => _indexExprs; public uint NumExpressions => NumChildren; diff --git a/sources/ClangSharp/Cursors/Exprs/OpaqueValueExpr.cs b/sources/ClangSharp/Cursors/Exprs/OpaqueValueExpr.cs index 742cce12..66347db2 100644 --- a/sources/ClangSharp/Cursors/Exprs/OpaqueValueExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/OpaqueValueExpr.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class OpaqueValueExpr : Expr { - private readonly Lazy _sourceExpr; + private readonly ValueLazy _sourceExpr; internal OpaqueValueExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_OpaqueValueExpr) { - _sourceExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.SubExpr)); + _sourceExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.SubExpr)); } public Expr SourceExpr => _sourceExpr.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs b/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs index 0a7e4640..ce3f4951 100644 --- a/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs @@ -9,9 +9,9 @@ namespace ClangSharp; public class OverloadExpr : Expr { - private readonly Lazy> _decls; - private readonly Lazy _namingClass; - private readonly Lazy> _templateArgs; + private readonly LazyList _decls; + private readonly ValueLazy _namingClass; + private readonly LazyList _templateArgs; private protected OverloadExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { @@ -20,36 +20,12 @@ private protected OverloadExpr(CXCursor handle, CXCursorKind expectedCursorKind, throw new ArgumentOutOfRangeException(nameof(handle)); } - _decls = new Lazy>(() => { - var numDecls = Handle.NumDecls; - var decls = new List(numDecls); - - for (var i = 0; i < numDecls; i++) - { - var decl = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); - decls.Add(decl); - } - - return decls; - }); - - _namingClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _decls = LazyList.Create(Handle.NumDecls, (i) => TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i)))); + _namingClass = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i)))); } - public IReadOnlyList Decls => _decls.Value; + public IReadOnlyList Decls => _decls; public bool HasExplicitTemplateArgs => Handle.HasExplicitTemplateArgs; @@ -63,5 +39,5 @@ private protected OverloadExpr(CXCursor handle, CXCursorKind expectedCursorKind, public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); - public IReadOnlyList TemplateArgs => _templateArgs.Value; + public IReadOnlyList TemplateArgs => _templateArgs; } diff --git a/sources/ClangSharp/Cursors/Exprs/PackIndexingExpr.cs b/sources/ClangSharp/Cursors/Exprs/PackIndexingExpr.cs new file mode 100644 index 00000000..081afefe --- /dev/null +++ b/sources/ClangSharp/Cursors/Exprs/PackIndexingExpr.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using ClangSharp.Interop; +using static ClangSharp.Interop.CXCursorKind; +using static ClangSharp.Interop.CX_StmtClass; + +namespace ClangSharp; + +public sealed class PackIndexingExpr : Expr +{ + internal PackIndexingExpr(CXCursor handle) : base(handle, CXCursor_PackIndexingExpr, CX_StmtClass_PackIndexingExpr) + { + } +} diff --git a/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs b/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs index 034b1d29..d2ca3b95 100644 --- a/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,14 +9,14 @@ namespace ClangSharp; public sealed class ParenListExpr : Expr { - private readonly Lazy> _exprs; + private readonly LazyList _exprs; internal ParenListExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_ParenListExpr) { - _exprs = new Lazy>(() => Children.Cast().ToList()); + _exprs = LazyList.Create(_children); } - public IReadOnlyList Exprs => _exprs.Value; + public IReadOnlyList Exprs => _exprs; public uint NumExprs => NumChildren; } diff --git a/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs b/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs index 667efb19..3b5ba34e 100644 --- a/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -12,12 +10,12 @@ namespace ClangSharp; public sealed class PseudoObjectExpr : Expr { - private readonly Lazy> _semantics; + private readonly LazyList _semantics; internal PseudoObjectExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_PseudoObjectExpr) { Debug.Assert(NumChildren >= 1); - _semantics = new Lazy>(() => Children.Skip(1).Cast().ToList()); + _semantics = LazyList.Create(_children, skip: 1); } public uint NumSemanticExprs => NumChildren - 1; @@ -26,7 +24,7 @@ internal PseudoObjectExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr public uint ResultExprIndex => unchecked((uint)Handle.ResultIndex); - public IReadOnlyList Semantics => _semantics.Value; + public IReadOnlyList Semantics => _semantics; public Expr SyntacticForm => (Expr)Children[0]; } diff --git a/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs b/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs index c821a900..8dbae0e9 100644 --- a/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -11,12 +9,12 @@ namespace ClangSharp; public sealed class RecoveryExpr : Expr { - private readonly Lazy> _subExpressions; + private readonly LazyList _subExpressions; internal RecoveryExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_RecoveryExpr) { - _subExpressions = new Lazy>(() => Children.Cast().ToList()); + _subExpressions = LazyList.Create(_children); } - public IReadOnlyList SubExpressions => _subExpressions.Value; + public IReadOnlyList SubExpressions => _subExpressions; } diff --git a/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs b/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs index 5117791d..909ccf3b 100644 --- a/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs @@ -3,31 +3,20 @@ using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class SizeOfPackExpr : Expr { - private readonly Lazy _pack; - private readonly Lazy> _partialArguments; + private readonly ValueLazy _pack; + private readonly LazyList _partialArguments; internal SizeOfPackExpr(CXCursor handle) : base(handle, CXCursor_SizeOfPackExpr, CX_StmtClass_SizeOfPackExpr) { - _pack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _partialArguments = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _pack = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _partialArguments = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } public NamedDecl Pack => _pack.Value; @@ -36,5 +25,5 @@ internal SizeOfPackExpr(CXCursor handle) : base(handle, CXCursor_SizeOfPackExpr, public bool IsPartiallySubstituted => Handle.IsPartiallySubstituted; - public IReadOnlyList PartialArguments => _partialArguments.Value; + public IReadOnlyList PartialArguments => _partialArguments; } diff --git a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs index 59c908a9..2f4dc90c 100644 --- a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class SubstNonTypeTemplateParmExpr : Expr { - private readonly Lazy _parameter; + private readonly ValueLazy _parameter; internal SubstNonTypeTemplateParmExpr(CXCursor handle) : base(handle, CXCursor_DeclRefExpr, CX_StmtClass_SubstNonTypeTemplateParmExpr) { Debug.Assert(NumChildren is 1); - _parameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _parameter = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public NonTypeTemplateParmDecl Parameter => _parameter.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs index 002ed4b7..f1685281 100644 --- a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs @@ -10,15 +10,15 @@ namespace ClangSharp; public sealed class SubstNonTypeTemplateParmPackExpr : Expr { - private readonly Lazy _argumentPack; - private readonly Lazy _parameterPack; + private readonly ValueLazy _argumentPack; + private readonly ValueLazy _parameterPack; internal SubstNonTypeTemplateParmPackExpr(CXCursor handle) : base(handle, CXCursor_DeclRefExpr, CX_StmtClass_SubstNonTypeTemplateParmPackExpr) { Debug.Assert(NumChildren is 0); - _argumentPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(0))); - _parameterPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _argumentPack = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(0))); + _parameterPack = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public TemplateArgument ArgumentPack => _argumentPack.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/UnaryExprOrTypeTraitExpr.cs b/sources/ClangSharp/Cursors/Exprs/UnaryExprOrTypeTraitExpr.cs index c31604f9..8d572adb 100644 --- a/sources/ClangSharp/Cursors/Exprs/UnaryExprOrTypeTraitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/UnaryExprOrTypeTraitExpr.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class UnaryExprOrTypeTraitExpr : Expr { - private readonly Lazy _argumentExpr; - private readonly Lazy _argumentType; + private readonly ValueLazy _argumentExpr; + private readonly ValueLazy _argumentType; internal UnaryExprOrTypeTraitExpr(CXCursor handle) : base(handle, CXCursor_UnaryExpr, CX_StmtClass_UnaryExprOrTypeTraitExpr) { - _argumentExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); - _argumentType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ArgumentType)); + _argumentExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + _argumentType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ArgumentType)); } public Expr ArgumentExpr => _argumentExpr.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs b/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs index eab67a04..83253ef3 100644 --- a/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs @@ -11,12 +11,12 @@ namespace ClangSharp; public sealed class UnresolvedMemberExpr : OverloadExpr { - private readonly Lazy _baseType; + private readonly ValueLazy _baseType; internal UnresolvedMemberExpr(CXCursor handle) : base(handle, CXCursor_MemberRefExpr, CX_StmtClass_UnresolvedMemberExpr) { Debug.Assert(NumChildren is 0 or 1); - _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _baseType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public Expr? Base => (Expr?)Children.SingleOrDefault(); diff --git a/sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs b/sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs index 313ad512..25305c3b 100644 --- a/sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs +++ b/sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs @@ -8,11 +8,11 @@ namespace ClangSharp; public sealed class MacroExpansion : PreprocessedEntity { - private readonly Lazy _definition; + private readonly ValueLazy _definition; internal MacroExpansion(CXCursor handle) : base(handle, CXCursor_MacroExpansion) { - _definition = new Lazy(() => TranslationUnit.GetOrCreate(handle.Referenced)); + _definition = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.Referenced)); } public MacroDefinitionRecord Definition => _definition.Value; diff --git a/sources/ClangSharp/Cursors/Refs/OverloadedDeclRef.cs b/sources/ClangSharp/Cursors/Refs/OverloadedDeclRef.cs index 47e82638..a91749f7 100644 --- a/sources/ClangSharp/Cursors/Refs/OverloadedDeclRef.cs +++ b/sources/ClangSharp/Cursors/Refs/OverloadedDeclRef.cs @@ -10,16 +10,15 @@ namespace ClangSharp; public sealed class OverloadedDeclRef : Ref { - private readonly Lazy> _overloadedDecls; + private readonly ValueLazy> _overloadedDecls; internal OverloadedDeclRef(CXCursor handle) : base(handle, CXCursor_OverloadedDeclRef) { - _overloadedDecls = new Lazy>(() => { + _overloadedDecls = new ValueLazy>(() => { var num = Handle.NumOverloadedDecls; - return Enumerable.Range(0, (int)num) + return [.. Enumerable.Range(0, (int)num) .Select(i => Handle.GetOverloadedDecl((uint)i)) - .Select(c => TranslationUnit.GetOrCreate(c)) - .ToArray(); + .Select(c => TranslationUnit.GetOrCreate(c))]; }); } diff --git a/sources/ClangSharp/Cursors/Refs/Ref.cs b/sources/ClangSharp/Cursors/Refs/Ref.cs index 8a8901fb..8cfa820d 100644 --- a/sources/ClangSharp/Cursors/Refs/Ref.cs +++ b/sources/ClangSharp/Cursors/Refs/Ref.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public class Ref : Cursor { - private readonly Lazy _referenced; - private readonly Lazy _type; + private readonly ValueLazy _referenced; + private readonly ValueLazy _type; private protected Ref(CXCursor handle, CXCursorKind expectedCursorKind) : base(handle, expectedCursorKind) { - _referenced = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _type = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Type)); + _referenced = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _type = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Type)); } public NamedDecl Referenced => _referenced.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs b/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs index 325dc2af..7ecb9250 100644 --- a/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs @@ -1,37 +1,25 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using System.Diagnostics; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class AttributedStmt : ValueStmt { - private readonly Lazy> _attrs; + private readonly LazyList _attrs; internal AttributedStmt(CXCursor handle) : base(handle, CXCursor_UnexposedStmt, CX_StmtClass_AttributedStmt) { Debug.Assert(NumChildren == 1); - _attrs = new Lazy>(() => { - var numAttrs = Handle.NumAttrs; - var attrs = new List(numAttrs); - - for (var i = 0; i < numAttrs; i++) - { - var attr = TranslationUnit.GetOrCreate(Handle.GetAttr(unchecked((uint)i))); - attrs.Add(attr); - } - - return attrs; - }); + _attrs = LazyList.Create(Handle.NumAttrs, (i) => TranslationUnit.GetOrCreate(Handle.GetAttr(unchecked((uint)i)))); } - public IReadOnlyList Attrs => _attrs.Value; + public IReadOnlyList Attrs => _attrs; public Stmt SubStmt => Children[0]; } diff --git a/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs b/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs index 53f825d1..277b31fb 100644 --- a/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs @@ -10,15 +10,15 @@ namespace ClangSharp; public sealed class CXXCatchStmt : Stmt { - private readonly Lazy _caughtType; - private readonly Lazy _exceptionDecl; + private readonly ValueLazy _caughtType; + private readonly ValueLazy _exceptionDecl; internal CXXCatchStmt(CXCursor handle) : base(handle, CXCursor_CXXCatchStmt, CX_StmtClass_CXXCatchStmt) { Debug.Assert(NumChildren is 1); - _caughtType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); - _exceptionDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _caughtType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _exceptionDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public Type CaughtType => _caughtType.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs b/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs index f08daccc..4317033c 100644 --- a/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -12,15 +10,15 @@ namespace ClangSharp; public sealed class CXXTryStmt : Stmt { - private readonly Lazy> _handlers; + private readonly LazyList _handlers; internal CXXTryStmt(CXCursor handle) : base(handle, CXCursor_CXXTryStmt, CX_StmtClass_CXXTryStmt) { Debug.Assert(NumChildren is >= 1); - _handlers = new Lazy>(() => Children.Skip(1).Cast().ToList()); + _handlers = LazyList.Create(_children, skip: 1); } - public IReadOnlyList Handlers => _handlers.Value; + public IReadOnlyList Handlers => _handlers; public uint NumHandlers => (uint)(Children.Count - 1); diff --git a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs index cb54e9d1..6b9f8176 100644 --- a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs +++ b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs @@ -12,14 +12,14 @@ public sealed class Capture { private readonly CapturedStmt _parentStmt; private readonly uint _index; - private readonly Lazy _capturedVar; + private readonly ValueLazy _capturedVar; internal Capture(CapturedStmt parentStmt, uint index) { _parentStmt = parentStmt; _index = index; - _capturedVar = new Lazy(() => _parentStmt.TranslationUnit.GetOrCreate(_parentStmt.Handle.GetCapturedVar(_index))); + _capturedVar = new ValueLazy(() => _parentStmt.TranslationUnit.GetOrCreate(_parentStmt.Handle.GetCapturedVar(_index))); } public VarDecl CapturedVar => _capturedVar.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs index b194370d..4a266e63 100644 --- a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs @@ -2,41 +2,27 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed partial class CapturedStmt : Stmt { - private readonly Lazy _capturedDecl; - private readonly Lazy _capturedRecordDecl; - private readonly Lazy _captureStmt; - private readonly Lazy> _captures; - private readonly Lazy> _captureInits; + private readonly ValueLazy _capturedDecl; + private readonly ValueLazy _capturedRecordDecl; + private readonly ValueLazy _captureStmt; + private readonly LazyList _captures; + private readonly LazyList _captureInits; internal CapturedStmt(CXCursor handle) : base(handle, CXCursor_UnexposedStmt, CX_StmtClass_CapturedStmt) { - _capturedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CapturedDecl)); - _capturedRecordDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CapturedRecordDecl)); - _captureStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CapturedStmt)); - - _captures = new Lazy>(() => { - var numCaptures = Handle.NumCaptures; - var captures = new List(numCaptures); - - for (var i = 0; i < numCaptures; i++) - { - var capture = new Capture(this, unchecked((uint)i)); - captures.Add(capture); - } - - return captures; - }); - - _captureInits = new Lazy>(() => Children.Cast().ToList()); + _capturedDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.CapturedDecl)); + _capturedRecordDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.CapturedRecordDecl)); + _captureStmt = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.CapturedStmt)); + _captures = LazyList.Create(Handle.NumCaptures, (i) => new Capture(this, unchecked((uint)i))); + _captureInits = LazyList.Create(_children); } public CapturedDecl CapturedDecl => _capturedDecl.Value; @@ -47,11 +33,11 @@ internal CapturedStmt(CXCursor handle) : base(handle, CXCursor_UnexposedStmt, CX public Stmt CaptureStmt => _captureStmt.Value; - public IReadOnlyList Captures => _captures.Value; + public IReadOnlyList Captures => _captures; public uint CaptureSize => unchecked((uint)Handle.NumCaptures); - public IReadOnlyList CaptureInits => _captureInits.Value; + public IReadOnlyList CaptureInits => _captureInits; public bool CapturesVariable(VarDecl var) { diff --git a/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs b/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs index 4aebe8c5..c0d4f3c0 100644 --- a/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs @@ -1,35 +1,23 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using System.Linq; using ClangSharp.Interop; -using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; +using static ClangSharp.Interop.CXCursorKind; namespace ClangSharp; public sealed class DeclStmt : Stmt { - private readonly Lazy> _decls; + private readonly LazyList _decls; internal DeclStmt(CXCursor handle) : base(handle, CXCursor_DeclStmt, CX_StmtClass_DeclStmt) { - _decls = new Lazy>(() => { - var numDecls = Handle.NumDecls; - var decls = new List(numDecls); - - for (var i = 0; i < numDecls; i++) - { - var decl = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); - decls.Add(decl); - } - - return decls; - }); + _decls = LazyList.Create(Handle.NumDecls, (i) => TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i)))); } - public IReadOnlyList Decls => _decls.Value; + public IReadOnlyList Decls => _decls; public bool IsSingleDecl => Decls.Count == 1; diff --git a/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs b/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs index 310a23a1..9672b2aa 100644 --- a/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class GotoStmt : Stmt { - private readonly Lazy _label; + private readonly ValueLazy _label; internal GotoStmt(CXCursor handle) : base(handle, CXCursor_GotoStmt, CX_StmtClass_GotoStmt) { Debug.Assert(NumChildren is 0); - _label = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _label = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public LabelDecl Label => _label.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs b/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs index 38eeaf1b..ac9ad30b 100644 --- a/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class IndirectGotoStmt : Stmt { - private readonly Lazy _constantTarget; + private readonly ValueLazy _constantTarget; internal IndirectGotoStmt(CXCursor handle) : base(handle, CXCursor_IndirectGotoStmt, CX_StmtClass_IndirectGotoStmt) { Debug.Assert(NumChildren is 1); - _constantTarget = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _constantTarget = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public LabelDecl ConstantTarget => _constantTarget.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs b/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs index 90b11473..48b0e8dc 100644 --- a/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class LabelStmt : ValueStmt { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal LabelStmt(CXCursor handle) : base(handle, CXCursor_LabelStmt, CX_StmtClass_LabelStmt) { Debug.Assert(NumChildren is 1); - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public LabelDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs index 02ce7c63..0187a8bd 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class ObjCAtCatchStmt : Stmt { - private readonly Lazy _catchParamDecl; + private readonly ValueLazy _catchParamDecl; internal ObjCAtCatchStmt(CXCursor handle) : base(handle, CXCursor_ObjCAtCatchStmt, CX_StmtClass_ObjCAtCatchStmt) { Debug.Assert(NumChildren is 1); - _catchParamDecl = new Lazy(() => !Handle.Referenced.IsNull ? TranslationUnit.GetOrCreate(Handle.Referenced) : null); + _catchParamDecl = new ValueLazy(() => !Handle.Referenced.IsNull ? TranslationUnit.GetOrCreate(Handle.Referenced) : null); } public Stmt CatchBody => Children[0]; diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs index 84a0cd67..fe97d351 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_StmtClass; @@ -12,25 +11,27 @@ namespace ClangSharp; public sealed class ObjCAtTryStmt : Stmt { - private readonly Lazy> _catchStmts; - private readonly Lazy _finallyStmt; + private readonly ValueLazy> _catchStmts; + private readonly ValueLazy _finallyStmt; internal ObjCAtTryStmt(CXCursor handle) : base(handle, CXCursor_ObjCAtTryStmt, CX_StmtClass_ObjCAtTryStmt) { Debug.Assert(NumChildren is >= 1); - _catchStmts = new Lazy>(() => { - var children = Children; + _catchStmts = new ValueLazy>(() => { + var children = _children; var skipLast = 0; - if (children[children.Count - 1] is ObjCAtFinallyStmt) { + if (children[children.Count - 1] is ObjCAtFinallyStmt) + { skipLast++; } - return children.Skip(1).Take((int)(NumChildren - 1 - skipLast)).Cast().ToList(); + var take = (int)(NumChildren - 1 - skipLast); + return LazyList.Create(_children, skip: 1, take); }); - _finallyStmt = new Lazy(() => { + _finallyStmt = new ValueLazy(() => { var children = Children; return (children[children.Count - 1] is ObjCAtFinallyStmt finallyStmt) ? finallyStmt : null; diff --git a/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs b/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs index 628b5ebe..d5efac5f 100644 --- a/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs @@ -10,13 +10,13 @@ namespace ClangSharp; public sealed class ReturnStmt : Stmt { - private readonly Lazy _nrvoCandidate; + private readonly ValueLazy _nrvoCandidate; internal ReturnStmt(CXCursor handle) : base(handle, CXCursor_ReturnStmt, CX_StmtClass_ReturnStmt) { Debug.Assert(NumChildren is 0 or 1); - _nrvoCandidate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _nrvoCandidate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } public VarDecl NRVOCandidate => _nrvoCandidate.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/Stmt.cs b/sources/ClangSharp/Cursors/Stmts/Stmt.cs index bab15c8e..fe8a77bd 100644 --- a/sources/ClangSharp/Cursors/Stmts/Stmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/Stmt.cs @@ -10,8 +10,8 @@ namespace ClangSharp; public class Stmt : Cursor { - private readonly Lazy> _children; - private readonly Lazy _declContext; + private protected readonly LazyList _children; + private readonly ValueLazy _declContext; private protected Stmt(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind) { @@ -20,21 +20,11 @@ private protected Stmt(CXCursor handle, CXCursorKind expectedCursorKind, CX_Stmt throw new ArgumentOutOfRangeException(nameof(handle)); } - _children = new Lazy>(() => { - var numChildren = Handle.NumChildren; - var children = new List(numChildren); - - for (var i = 0; i < numChildren; i++) - { - var childHandle = Handle.GetChild(unchecked((uint)i)); - var child = !childHandle.IsNull ? TranslationUnit.GetOrCreate(childHandle) : null; - children.Add(child); - } - - return children; + _children = LazyList.Create(Handle.NumChildren, (i) => { + var childHandle = Handle.GetChild(unchecked((uint)i)); + return !childHandle.IsNull ? TranslationUnit.GetOrCreate(childHandle) : null!; }); - - _declContext = new Lazy(() => { + _declContext = new ValueLazy(() => { var semanticParent = TranslationUnit.GetOrCreate(Handle.SemanticParent); while (semanticParent is not IDeclContext and not null) @@ -47,7 +37,7 @@ private protected Stmt(CXCursor handle, CXCursorKind expectedCursorKind, CX_Stmt }); } - public IReadOnlyList Children => _children.Value!; + public IReadOnlyList Children => _children; public IDeclContext DeclContext => _declContext.Value; @@ -167,7 +157,7 @@ public Stmt StripLabelLikeStatements() CX_StmtClass_ObjCArrayLiteral => new ObjCArrayLiteral(handle), CX_StmtClass_OMPIteratorExpr => new OMPIteratorExpr(handle), CX_StmtClass_OMPArrayShapingExpr => new OMPArrayShapingExpr(handle), - CX_StmtClass_OMPArraySectionExpr => new OMPArraySectionExpr(handle), + CX_StmtClass_ArraySectionExpr => new ArraySectionExpr(handle), CX_StmtClass_NoInitExpr => new NoInitExpr(handle), CX_StmtClass_MemberExpr => new MemberExpr(handle), CX_StmtClass_MatrixSubscriptExpr => new MatrixSubscriptExpr(handle), @@ -225,6 +215,7 @@ public Stmt StripLabelLikeStatements() CX_StmtClass_CXXRewrittenBinaryOperator => new CXXRewrittenBinaryOperator(handle), CX_StmtClass_CXXPseudoDestructorExpr => new CXXPseudoDestructorExpr(handle), CX_StmtClass_CXXParenListInitExpr => new CXXParenListInitExpr(handle), + CX_StmtClass_PackIndexingExpr => new PackIndexingExpr(handle), CX_StmtClass_CXXNullPtrLiteralExpr => new CXXNullPtrLiteralExpr(handle), CX_StmtClass_CXXNoexceptExpr => new CXXNoexceptExpr(handle), CX_StmtClass_CXXNewExpr => new CXXNewExpr(handle), diff --git a/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs b/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs index 1dbbd90b..59a07753 100644 --- a/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs +++ b/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs @@ -9,7 +9,7 @@ namespace ClangSharp; public class SwitchCase : Stmt { - private readonly Lazy _nextSwitchCase; + private readonly ValueLazy _nextSwitchCase; private protected SwitchCase(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { @@ -18,7 +18,7 @@ private protected SwitchCase(CXCursor handle, CXCursorKind expectedCursorKind, C throw new ArgumentOutOfRangeException(nameof(handle)); } - _nextSwitchCase = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NextSwitchCase)); + _nextSwitchCase = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NextSwitchCase)); } public SwitchCase NextSwitchCase => _nextSwitchCase.Value; diff --git a/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs b/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs index 66121d69..72bccd3a 100644 --- a/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs @@ -10,12 +10,12 @@ namespace ClangSharp; public sealed class SwitchStmt : Stmt { - private readonly Lazy _switchCaseList; + private readonly ValueLazy _switchCaseList; internal SwitchStmt(CXCursor handle) : base(handle, CXCursor_SwitchStmt, CX_StmtClass_SwitchStmt) { Debug.Assert(NumChildren is >= 2 and <= 4); - _switchCaseList = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); + _switchCaseList = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } public Stmt Body => Children[BodyOffset]; diff --git a/sources/ClangSharp/LazyList.cs b/sources/ClangSharp/LazyList.cs new file mode 100644 index 00000000..463005d0 --- /dev/null +++ b/sources/ClangSharp/LazyList.cs @@ -0,0 +1,26 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace ClangSharp; + +internal static class LazyList +{ + public static LazyList Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T>(int count, Func valueFactory) + where T : class + { + if (count <= 0) + { + return LazyList.Empty; + } + return new LazyList(count, valueFactory); + } + + public static LazyList Create(LazyList list, int skip = -1, int take = -1) + where T : class, TBase + where TBase : class + { + return new LazyList(list, skip, take); + } +} diff --git a/sources/ClangSharp/LazyList`1.cs b/sources/ClangSharp/LazyList`1.cs new file mode 100644 index 00000000..507eeceb --- /dev/null +++ b/sources/ClangSharp/LazyList`1.cs @@ -0,0 +1,165 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace ClangSharp; + +internal sealed class LazyList<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T> : IList, IReadOnlyList + where T : class +{ + internal readonly T[] _items; + internal readonly Func _valueFactory; + + public static readonly LazyList Empty = new LazyList(0, _ => null!); + + public LazyList(int count, Func valueFactory) + { + _items = (count <= 0) ? [] : new T[count]; + _valueFactory = valueFactory; + } + + public T this[int index] + { + get + { + var items = _items.AsSpan(); + var item = items[index]; + + if (item is null) + { + item = _valueFactory(index); + items[index] = item; + } + + return item; + } + } + + public int Count => _items.Length; + + public bool IsReadOnly => true; + + public bool Contains(T item) => IndexOf(item) >= 0; + + public void CopyTo(T[] array, int arrayIndex) + { + var items = _items; + ArgumentNullException.ThrowIfNull(array); + + if ((arrayIndex < 0) || (arrayIndex > array.Length) || ((array.Length - arrayIndex) < items.Length)) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + + for (var i = 0; i < items.Length; i++) + { + var currentItem = items[i]; + + if (currentItem is null) + { + currentItem = _valueFactory(i); + items[i] = currentItem; + } + + array[arrayIndex + i] = currentItem; + } + } + + public Enumerator GetEnumerator() => new Enumerator(this); + + public int IndexOf(T item) + { + var items = _items; + + for (var i = 0; i < items.Length; i++) + { + var currentItem = items[i]; + + if (currentItem is null) + { + currentItem = _valueFactory(i); + items[i] = currentItem; + } + + if (EqualityComparer.Default.Equals(currentItem, item)) + { + return i; + } + } + + return -1; + } + + T IList.this[int index] + { + get + { + return this[index]; + } + + set + { + throw new NotSupportedException(); + } + } + + void ICollection.Add(T item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + bool ICollection.Remove(T item) => throw new NotSupportedException(); + + void IList.Insert(int index, T item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator : IEnumerator + { + private readonly LazyList _list; + + private int _index; + private T? _current; + + internal Enumerator(LazyList list) + { + _list = list; + } + + public readonly void Dispose() + { + } + + public bool MoveNext() + { + var localList = _list; + + if ((uint)_index < (uint)localList.Count) + { + _current = localList[_index]; + _index++; + return true; + } + + _current = default; + _index = -1; + return false; + } + + public readonly T Current => _current!; + + readonly object? IEnumerator.Current => Current; + + void IEnumerator.Reset() + { + _index = 0; + _current = default; + } + } +} diff --git a/sources/ClangSharp/LazyList`2.cs b/sources/ClangSharp/LazyList`2.cs new file mode 100644 index 00000000..0e40def2 --- /dev/null +++ b/sources/ClangSharp/LazyList`2.cs @@ -0,0 +1,173 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace ClangSharp; + +internal sealed class LazyList : IList, IReadOnlyList + where T : class, TBase + where TBase : class +{ + internal readonly TBase[] _items; + internal readonly Func _valueFactory; + + private readonly int _start; + private readonly int _count; + + public LazyList(LazyList list, int skip = -1, int take = -1) + { + skip = (skip < 0) ? 0 : skip; + take = (take < 0) ? (list.Count - skip) : take; + + _items = list._items; + _valueFactory = list._valueFactory; + + _start = skip; + _count = take; + } + + public T this[int index] + { + get + { + var items = _items.AsSpan(_start, _count); + var item = items[index]; + + if (item is null) + { + item = _valueFactory(index + _start); + items[index] = item; + } + + return (T)item; + } + } + + public int Count => _count; + + public bool IsReadOnly => true; + + public bool Contains(T item) => IndexOf(item) >= 0; + + public void CopyTo(T[] array, int arrayIndex) + { + var items = _items.AsSpan(_start, _count); + ArgumentNullException.ThrowIfNull(array); + + if ((arrayIndex < 0) || (arrayIndex > array.Length) || ((array.Length - arrayIndex) < items.Length)) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + + for (var i = 0; i < _count; i++) + { + var currentItem = items[i]; + + if (currentItem is null) + { + currentItem = _valueFactory(i + _start); + items[i] = currentItem; + } + + array[arrayIndex + i] = (T)currentItem; + } + } + + public Enumerator GetEnumerator() => new Enumerator(this); + + public int IndexOf(T item) + { + var items = _items.AsSpan(_start, _count); + + for (var i = 0; i < items.Length; i++) + { + var currentItem = items[i]; + + if (currentItem is null) + { + currentItem = _valueFactory(i + _start); + items[i] = currentItem; + } + + if (EqualityComparer.Default.Equals((T)currentItem, item)) + { + return i; + } + } + + return -1; + } + + T IList.this[int index] + { + get + { + return this[index]; + } + + set + { + throw new NotSupportedException(); + } + } + + void ICollection.Add(T item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + bool ICollection.Remove(T item) => throw new NotSupportedException(); + + void IList.Insert(int index, T item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator : IEnumerator + { + private readonly LazyList _list; + + private int _index; + private T? _current; + + internal Enumerator(LazyList list) + { + _list = list; + } + + public readonly void Dispose() + { + } + + public bool MoveNext() + { + var localList = _list; + + if ((uint)_index < (uint)localList.Count) + { + _current = localList[_index]; + _index++; + return true; + } + + _current = default; + _index = -1; + return false; + } + + public readonly T Current => _current!; + + readonly object? IEnumerator.Current => Current; + + void IEnumerator.Reset() + { + _index = 0; + _current = default; + } + } +} diff --git a/sources/ClangSharp/TemplateArgument.cs b/sources/ClangSharp/TemplateArgument.cs index 7ca67eb3..5f450f19 100644 --- a/sources/ClangSharp/TemplateArgument.cs +++ b/sources/ClangSharp/TemplateArgument.cs @@ -4,56 +4,43 @@ using System.Collections.Generic; using System.Diagnostics; using ClangSharp.Interop; -using static ClangSharp.Interop.CXTemplateArgumentKind; using static ClangSharp.Interop.CX_TemplateArgumentDependence; +using static ClangSharp.Interop.CXTemplateArgumentKind; namespace ClangSharp; public sealed unsafe class TemplateArgument : IDisposable { - private readonly Lazy _asDecl; - private readonly Lazy _asExpr; - private readonly Lazy _asTemplate; - private readonly Lazy _asTemplateOrTemplatePattern; - private readonly Lazy _asType; - private readonly Lazy _integralType; - private readonly Lazy _nonTypeTemplateArgumentType; - private readonly Lazy _nullPtrType; - private readonly Lazy> _packElements; - private readonly Lazy _packExpansionPattern; - private readonly Lazy _paramTypeForDecl; - private readonly Lazy _translationUnit; + private readonly ValueLazy _asDecl; + private readonly ValueLazy _asExpr; + private readonly ValueLazy _asTemplate; + private readonly ValueLazy _asTemplateOrTemplatePattern; + private readonly ValueLazy _asType; + private readonly ValueLazy _integralType; + private readonly ValueLazy _nonTypeTemplateArgumentType; + private readonly ValueLazy _nullPtrType; + private readonly LazyList _packElements; + private readonly ValueLazy _packExpansionPattern; + private readonly ValueLazy _paramTypeForDecl; + private readonly ValueLazy _translationUnit; internal TemplateArgument(CX_TemplateArgument handle) { Handle = handle; - _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.tu)); - - _asDecl = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsDecl)); - _asExpr = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsExpr)); - _asTemplate = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplate)); - _asTemplateOrTemplatePattern = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplateOrTemplatePattern)); - _asType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsType)); - _integralType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.IntegralType)); - _nonTypeTemplateArgumentType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.NonTypeTemplateArgumentType)); - _nullPtrType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.NullPtrType)); - _packExpansionPattern = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.PackExpansionPattern)); - - _packElements = new Lazy>(() => { - var numPackElements = Handle.NumPackElements; - var packElements = new List(numPackElements); - - for (var i = 0; i < numPackElements; i++) - { - var packElement = _translationUnit.Value.GetOrCreate(Handle.GetPackElement(unchecked((uint)i))); - packElements.Add(packElement); - } - - return packElements; - }); - - _paramTypeForDecl = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.ParamTypeForDecl)); + _translationUnit = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.tu)); + + _asDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AsDecl)); + _asExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AsExpr)); + _asTemplate = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AsTemplate)); + _asTemplateOrTemplatePattern = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AsTemplateOrTemplatePattern)); + _asType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AsType)); + _integralType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.IntegralType)); + _nonTypeTemplateArgumentType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NonTypeTemplateArgumentType)); + _nullPtrType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NullPtrType)); + _packExpansionPattern = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.PackExpansionPattern)); + _packElements = LazyList.Create(Handle.NumPackElements, (i) => TranslationUnit.GetOrCreate(Handle.GetPackElement(unchecked((uint)i)))); + _paramTypeForDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ParamTypeForDecl)); } ~TemplateArgument() => Dispose(isDisposing: false); @@ -127,7 +114,7 @@ public bool IsPackExpansion public Type NullPtrType => _nullPtrType.Value; - public IReadOnlyList PackElements => _packElements.Value; + public IReadOnlyList PackElements => _packElements; public TemplateArgument PackExpansionPattern => _packExpansionPattern.Value; diff --git a/sources/ClangSharp/TemplateArgumentLoc.cs b/sources/ClangSharp/TemplateArgumentLoc.cs index 8b0f380f..845b83d3 100644 --- a/sources/ClangSharp/TemplateArgumentLoc.cs +++ b/sources/ClangSharp/TemplateArgumentLoc.cs @@ -7,24 +7,24 @@ namespace ClangSharp; public sealed unsafe class TemplateArgumentLoc { - private readonly Lazy _argument; - private readonly Lazy _sourceDeclExpression; - private readonly Lazy _sourceExpression; - private readonly Lazy _sourceIntegralExpression; - private readonly Lazy _sourceNullPtrExpression; - private readonly Lazy _translationUnit; + private readonly ValueLazy _argument; + private readonly ValueLazy _sourceDeclExpression; + private readonly ValueLazy _sourceExpression; + private readonly ValueLazy _sourceIntegralExpression; + private readonly ValueLazy _sourceNullPtrExpression; + private readonly ValueLazy _translationUnit; internal TemplateArgumentLoc(CX_TemplateArgumentLoc handle) { Handle = handle; - _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.tu)); + _translationUnit = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.tu)); - _argument = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.Argument)); - _sourceDeclExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceDeclExpression)); - _sourceExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceExpression)); - _sourceIntegralExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceIntegralExpression)); - _sourceNullPtrExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceNullPtrExpression)); + _argument = new ValueLazy(() => _translationUnit.Value.GetOrCreate(Handle.Argument)); + _sourceDeclExpression = new ValueLazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceDeclExpression)); + _sourceExpression = new ValueLazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceExpression)); + _sourceIntegralExpression = new ValueLazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceIntegralExpression)); + _sourceNullPtrExpression = new ValueLazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceNullPtrExpression)); } public TemplateArgument Argument => _argument.Value; diff --git a/sources/ClangSharp/TemplateName.cs b/sources/ClangSharp/TemplateName.cs index 2a8bc1a5..71ea0240 100644 --- a/sources/ClangSharp/TemplateName.cs +++ b/sources/ClangSharp/TemplateName.cs @@ -7,15 +7,15 @@ namespace ClangSharp; public sealed unsafe class TemplateName { - private readonly Lazy _asTemplateDecl; - private readonly Lazy _translationUnit; + private readonly ValueLazy _asTemplateDecl; + private readonly ValueLazy _translationUnit; internal TemplateName(CX_TemplateName handle) { Handle = handle; - _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.tu)); - _asTemplateDecl = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplateDecl)); + _translationUnit = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.tu)); + _asTemplateDecl = new ValueLazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplateDecl)); } public TemplateDecl AsTemplateDecl => _asTemplateDecl.Value; diff --git a/sources/ClangSharp/TranslationUnit.cs b/sources/ClangSharp/TranslationUnit.cs index 41f16045..6f9ca963 100644 --- a/sources/ClangSharp/TranslationUnit.cs +++ b/sources/ClangSharp/TranslationUnit.cs @@ -4,24 +4,25 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Threading; using ClangSharp.Interop; -using static ClangSharp.Interop.CXTypeKind; -using static ClangSharp.Interop.CXTemplateArgumentKind; using static ClangSharp.Interop.CX_TemplateNameKind; +using static ClangSharp.Interop.CXTemplateArgumentKind; +using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed unsafe class TranslationUnit : IDisposable, IEquatable { private static readonly ConcurrentDictionary> s_createdTranslationUnits = new ConcurrentDictionary>(); - private static readonly object s_createTranslationUnitLock = new object(); + private static readonly Lock s_createTranslationUnitLock = new Lock(); private readonly Dictionary> _createdCursors; private readonly Dictionary> _createdTemplateArguments; private readonly Dictionary> _createdTemplateArgumentLocs; private readonly Dictionary> _createdTemplateNames; private readonly Dictionary> _createdTypes; - private readonly Lazy _translationUnitDecl; + private readonly ValueLazy _translationUnitDecl; private bool _isDisposed; @@ -35,7 +36,7 @@ private TranslationUnit(CXTranslationUnit handle) _createdTemplateNames = []; _createdTypes = []; - _translationUnitDecl = new Lazy(() => GetOrCreate(Handle.Cursor)); + _translationUnitDecl = new ValueLazy(() => GetOrCreate(Handle.Cursor)); } ~TranslationUnit() @@ -94,7 +95,7 @@ internal TCursor GetOrCreate(CXCursor handle) if (handle.IsNull) { - Debug.Assert(!handle.IsNull); + // Debug.Assert(!handle.IsNull); return null!; } else if (!_createdCursors.TryGetValue(handle, out cursorRef)) diff --git a/sources/ClangSharp/Types/AdjustedType.cs b/sources/ClangSharp/Types/AdjustedType.cs index cd6c2d31..8a8f1bed 100644 --- a/sources/ClangSharp/Types/AdjustedType.cs +++ b/sources/ClangSharp/Types/AdjustedType.cs @@ -9,8 +9,8 @@ namespace ClangSharp; public class AdjustedType : Type { - private readonly Lazy _adjustedType; - private readonly Lazy _originalType; + private readonly ValueLazy _adjustedType; + private readonly ValueLazy _originalType; internal AdjustedType(CXType handle) : this(handle, CXType_Unexposed, CX_TypeClass_Adjusted) { @@ -18,8 +18,8 @@ internal AdjustedType(CXType handle) : this(handle, CXType_Unexposed, CX_TypeCla private protected AdjustedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _adjustedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.AdjustedType)); - _originalType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _adjustedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AdjustedType)); + _originalType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public Type GetAdjustedType => _adjustedType.Value; diff --git a/sources/ClangSharp/Types/ArrayType.cs b/sources/ClangSharp/Types/ArrayType.cs index adb43ed4..75626a17 100644 --- a/sources/ClangSharp/Types/ArrayType.cs +++ b/sources/ClangSharp/Types/ArrayType.cs @@ -7,11 +7,11 @@ namespace ClangSharp; public class ArrayType : Type { - private readonly Lazy _elementType; + private readonly ValueLazy _elementType; private protected ArrayType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ArrayElementType)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ArrayElementType)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/Types/AtomicType.cs b/sources/ClangSharp/Types/AtomicType.cs index 9e26c1de..5c174e51 100644 --- a/sources/ClangSharp/Types/AtomicType.cs +++ b/sources/ClangSharp/Types/AtomicType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class AtomicType : Type { - private readonly Lazy _valueType; + private readonly ValueLazy _valueType; internal AtomicType(CXType handle) : base(handle, CXType_Atomic, CX_TypeClass_Atomic) { - _valueType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ValueType)); + _valueType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ValueType)); } public Type ValueType => _valueType.Value; diff --git a/sources/ClangSharp/Types/AttributedType.cs b/sources/ClangSharp/Types/AttributedType.cs index a7a56aca..2a867e0b 100644 --- a/sources/ClangSharp/Types/AttributedType.cs +++ b/sources/ClangSharp/Types/AttributedType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class AttributedType : Type { - private readonly Lazy _equivalentType; - private readonly Lazy _modifiedType; + private readonly ValueLazy _equivalentType; + private readonly ValueLazy _modifiedType; internal AttributedType(CXType handle) : base(handle, CXType_Attributed, CX_TypeClass_Attributed) { - _equivalentType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.EquivalentType)); - _modifiedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ModifiedType)); + _equivalentType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.EquivalentType)); + _modifiedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ModifiedType)); } public CX_AttrKind AttrKind => Handle.AttrKind; diff --git a/sources/ClangSharp/Types/AutoType.cs b/sources/ClangSharp/Types/AutoType.cs index 8b7613ae..9e1a30ea 100644 --- a/sources/ClangSharp/Types/AutoType.cs +++ b/sources/ClangSharp/Types/AutoType.cs @@ -1,32 +1,20 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXTypeKind; using static ClangSharp.Interop.CX_TypeClass; +using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed class AutoType : DeducedType { - private readonly Lazy> _templateArgs; + private readonly LazyList _templateArgs; internal AutoType(CXType handle) : base(handle, CXType_Auto, CX_TypeClass_Auto) { - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } - public IReadOnlyList Args => _templateArgs.Value; + public IReadOnlyList Args => _templateArgs; } diff --git a/sources/ClangSharp/Types/ComplexType.cs b/sources/ClangSharp/Types/ComplexType.cs index 4998f44f..0f45d043 100644 --- a/sources/ClangSharp/Types/ComplexType.cs +++ b/sources/ClangSharp/Types/ComplexType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class ComplexType : Type { - private readonly Lazy _elementType; + private readonly ValueLazy _elementType; internal ComplexType(CXType handle) : base(handle, CXType_Complex, CX_TypeClass_Complex) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/Types/ConstantArrayType.cs b/sources/ClangSharp/Types/ConstantArrayType.cs index dc2e556b..012ca250 100644 --- a/sources/ClangSharp/Types/ConstantArrayType.cs +++ b/sources/ClangSharp/Types/ConstantArrayType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class ConstantArrayType : ArrayType { - private readonly Lazy _sizeExpr; + private readonly ValueLazy _sizeExpr; internal ConstantArrayType(CXType handle) : base(handle, CXType_ConstantArray, CX_TypeClass_ConstantArray) { - _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); + _sizeExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } public long Size => Handle.ArraySize; diff --git a/sources/ClangSharp/Types/DecayedType.cs b/sources/ClangSharp/Types/DecayedType.cs index d826e5da..99fc54a9 100644 --- a/sources/ClangSharp/Types/DecayedType.cs +++ b/sources/ClangSharp/Types/DecayedType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class DecayedType : AdjustedType { - private readonly Lazy _decayedType; + private readonly ValueLazy _decayedType; internal DecayedType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_Decayed) { - _decayedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DecayedType)); + _decayedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DecayedType)); } public Type GetDecayedType => _decayedType.Value; diff --git a/sources/ClangSharp/Types/DecltypeType.cs b/sources/ClangSharp/Types/DecltypeType.cs index da4047f7..b4272015 100644 --- a/sources/ClangSharp/Types/DecltypeType.cs +++ b/sources/ClangSharp/Types/DecltypeType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class DecltypeType : Type { - private readonly Lazy _underlyingExpr; - private readonly Lazy _underlyingType; + private readonly ValueLazy _underlyingExpr; + private readonly ValueLazy _underlyingType; internal DecltypeType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_Decltype) { - _underlyingExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingExpr)); - _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _underlyingExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingExpr)); + _underlyingType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } public Expr UnderlyingExpr => _underlyingExpr.Value; diff --git a/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs b/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs index 89bab893..6d893a63 100644 --- a/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs +++ b/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class DeducedTemplateSpecializationType : DeducedType { - private readonly Lazy _templateName; + private readonly ValueLazy _templateName; internal DeducedTemplateSpecializationType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DeducedTemplateSpecialization) { - _templateName = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); + _templateName = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); } public TemplateName TemplateName => _templateName.Value; diff --git a/sources/ClangSharp/Types/DeducedType.cs b/sources/ClangSharp/Types/DeducedType.cs index 4c77aa5a..fc630fe6 100644 --- a/sources/ClangSharp/Types/DeducedType.cs +++ b/sources/ClangSharp/Types/DeducedType.cs @@ -7,11 +7,11 @@ namespace ClangSharp; public class DeducedType : Type { - private readonly Lazy _deducedType; + private readonly ValueLazy _deducedType; private protected DeducedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _deducedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DeducedType)); + _deducedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.DeducedType)); } public Type GetDeducedType => _deducedType.Value; diff --git a/sources/ClangSharp/Types/DependentAddressSpaceType.cs b/sources/ClangSharp/Types/DependentAddressSpaceType.cs index 07470cb8..6f8bc6ff 100644 --- a/sources/ClangSharp/Types/DependentAddressSpaceType.cs +++ b/sources/ClangSharp/Types/DependentAddressSpaceType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class DependentAddressSpaceType : Type { - private readonly Lazy _addrSpaceExpr; + private readonly ValueLazy _addrSpaceExpr; internal DependentAddressSpaceType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DependentAddressSpace) { - _addrSpaceExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.AddrSpaceExpr)); + _addrSpaceExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.AddrSpaceExpr)); } public Expr AddrSpaceExpr => _addrSpaceExpr.Value; diff --git a/sources/ClangSharp/Types/DependentBitIntType.cs b/sources/ClangSharp/Types/DependentBitIntType.cs index 859c80ad..d0cb756a 100644 --- a/sources/ClangSharp/Types/DependentBitIntType.cs +++ b/sources/ClangSharp/Types/DependentBitIntType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class DependentBitIntType : Type { - private readonly Lazy _numBitsExpr; + private readonly ValueLazy _numBitsExpr; internal DependentBitIntType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DependentBitInt) { - _numBitsExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.NumBitsExpr)); + _numBitsExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.NumBitsExpr)); } public bool IsSigned => Handle.IsSigned; diff --git a/sources/ClangSharp/Types/DependentSizedArrayType.cs b/sources/ClangSharp/Types/DependentSizedArrayType.cs index bb35f032..7ab68928 100644 --- a/sources/ClangSharp/Types/DependentSizedArrayType.cs +++ b/sources/ClangSharp/Types/DependentSizedArrayType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class DependentSizedArrayType : ArrayType { - private readonly Lazy _sizeExpr; + private readonly ValueLazy _sizeExpr; internal DependentSizedArrayType(CXType handle) : base(handle, CXType_DependentSizedArray, CX_TypeClass_DependentSizedArray) { - _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); + _sizeExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } public Expr SizeExpr => _sizeExpr.Value; diff --git a/sources/ClangSharp/Types/DependentSizedExtVectorType.cs b/sources/ClangSharp/Types/DependentSizedExtVectorType.cs index c527be0b..3d3a63fc 100644 --- a/sources/ClangSharp/Types/DependentSizedExtVectorType.cs +++ b/sources/ClangSharp/Types/DependentSizedExtVectorType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class DependentSizedExtVectorType : Type { - private readonly Lazy _elementType; - private readonly Lazy _sizeExpr; + private readonly ValueLazy _elementType; + private readonly ValueLazy _sizeExpr; internal DependentSizedExtVectorType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DependentSizedExtVector) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); - _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); + _sizeExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/Types/DependentSizedMatrixType.cs b/sources/ClangSharp/Types/DependentSizedMatrixType.cs index 6e61861b..cb1ad796 100644 --- a/sources/ClangSharp/Types/DependentSizedMatrixType.cs +++ b/sources/ClangSharp/Types/DependentSizedMatrixType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class DependentSizedMatrixType : MatrixType { - private readonly Lazy _rowExpr; - private readonly Lazy _columnExpr; + private readonly ValueLazy _rowExpr; + private readonly ValueLazy _columnExpr; internal DependentSizedMatrixType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DependentSizedMatrix) { - _rowExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.RowExpr)); - _columnExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.ColumnExpr)); + _rowExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.RowExpr)); + _columnExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.ColumnExpr)); } public Expr ColumnExpr => _columnExpr.Value; diff --git a/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs b/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs index b63182c5..05957f8f 100644 --- a/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs +++ b/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs @@ -1,32 +1,20 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXTypeKind; using static ClangSharp.Interop.CX_TypeClass; +using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed class DependentTemplateSpecializationType : TypeWithKeyword { - private readonly Lazy> _templateArgs; + private readonly LazyList _templateArgs; internal DependentTemplateSpecializationType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DependentTemplateSpecialization) { - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); } - public IReadOnlyList Args => _templateArgs.Value; + public IReadOnlyList Args => _templateArgs; } diff --git a/sources/ClangSharp/Types/DependentVectorType.cs b/sources/ClangSharp/Types/DependentVectorType.cs index ff267692..6b050677 100644 --- a/sources/ClangSharp/Types/DependentVectorType.cs +++ b/sources/ClangSharp/Types/DependentVectorType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class DependentVectorType : Type { - private readonly Lazy _elementType; - private readonly Lazy _sizeExpr; + private readonly ValueLazy _elementType; + private readonly ValueLazy _sizeExpr; internal DependentVectorType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_DependentVector) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); - _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); + _sizeExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/Types/ElaboratedType.cs b/sources/ClangSharp/Types/ElaboratedType.cs index d8514fdb..ef004efb 100644 --- a/sources/ClangSharp/Types/ElaboratedType.cs +++ b/sources/ClangSharp/Types/ElaboratedType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class ElaboratedType : TypeWithKeyword { - private readonly Lazy _namedType; - private readonly Lazy _ownedTagDecl; + private readonly ValueLazy _namedType; + private readonly ValueLazy _ownedTagDecl; internal ElaboratedType(CXType handle) : base(handle, CXType_Elaborated, CX_TypeClass_Elaborated) { - _namedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NamedType)); - _ownedTagDecl = new Lazy(() => !Handle.OwnedTagDecl.IsNull ?TranslationUnit.GetOrCreate(Handle.OwnedTagDecl) : null); + _namedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.NamedType)); + _ownedTagDecl = new ValueLazy(() => !Handle.OwnedTagDecl.IsNull ?TranslationUnit.GetOrCreate(Handle.OwnedTagDecl) : null); } public Type NamedType => _namedType.Value; diff --git a/sources/ClangSharp/Types/FunctionProtoType.cs b/sources/ClangSharp/Types/FunctionProtoType.cs index f87af112..771fd8b8 100644 --- a/sources/ClangSharp/Types/FunctionProtoType.cs +++ b/sources/ClangSharp/Types/FunctionProtoType.cs @@ -1,31 +1,19 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; using System.Collections.Generic; using ClangSharp.Interop; -using static ClangSharp.Interop.CXTypeKind; using static ClangSharp.Interop.CX_TypeClass; +using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed class FunctionProtoType : FunctionType { - private readonly Lazy> _paramTypes; + private readonly LazyList _paramTypes; internal FunctionProtoType(CXType handle) : base(handle, CXType_FunctionProto, CX_TypeClass_FunctionProto) { - _paramTypes = new Lazy>(() => { - var paramTypeCount = Handle.NumArgTypes; - var paramTypes = new List(paramTypeCount); - - for (var i = 0; i < paramTypeCount; i++) - { - var paramType = TranslationUnit.GetOrCreate(Handle.GetArgType(unchecked((uint)i))); - paramTypes.Add(paramType); - } - - return paramTypes; - }); + _paramTypes = LazyList.Create(Handle.NumArgTypes, (i) => TranslationUnit.GetOrCreate(Handle.GetArgType(unchecked((uint)i)))); } public CXCursor_ExceptionSpecificationKind ExceptionSpecType => Handle.ExceptionSpecificationType; @@ -34,7 +22,7 @@ internal FunctionProtoType(CXType handle) : base(handle, CXType_FunctionProto, C public uint NumParams => (uint)Handle.NumArgTypes; - public IReadOnlyList ParamTypes => _paramTypes.Value; + public IReadOnlyList ParamTypes => _paramTypes; public CXRefQualifierKind RefQualifier => Handle.CXXRefQualifier; } diff --git a/sources/ClangSharp/Types/FunctionType.cs b/sources/ClangSharp/Types/FunctionType.cs index 343ce3de..00af1eee 100644 --- a/sources/ClangSharp/Types/FunctionType.cs +++ b/sources/ClangSharp/Types/FunctionType.cs @@ -7,11 +7,11 @@ namespace ClangSharp; public class FunctionType : Type { - private readonly Lazy _returnType; + private readonly ValueLazy _returnType; private protected FunctionType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _returnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ResultType)); + _returnType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ResultType)); } public CXCallingConv CallConv => Handle.FunctionTypeCallingConv; diff --git a/sources/ClangSharp/Types/InjectedClassNameType.cs b/sources/ClangSharp/Types/InjectedClassNameType.cs index a29ea665..429d0c9a 100644 --- a/sources/ClangSharp/Types/InjectedClassNameType.cs +++ b/sources/ClangSharp/Types/InjectedClassNameType.cs @@ -9,17 +9,17 @@ namespace ClangSharp; public sealed class InjectedClassNameType : Type { - private readonly Lazy _decl; - private readonly Lazy _injectedSpecializationType; - private readonly Lazy _injectedTST; - private readonly Lazy _templateName; + private readonly ValueLazy _decl; + private readonly ValueLazy _injectedSpecializationType; + private readonly ValueLazy _injectedTST; + private readonly ValueLazy _templateName; internal InjectedClassNameType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_InjectedClassName) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(handle.Declaration)); - _injectedSpecializationType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); - _injectedTST = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedTST)); - _templateName = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.Declaration)); + _injectedSpecializationType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); + _injectedTST = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.InjectedTST)); + _templateName = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); } public CXXRecordDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/MacroQualifiedType.cs b/sources/ClangSharp/Types/MacroQualifiedType.cs index 855fea8e..3cd17380 100644 --- a/sources/ClangSharp/Types/MacroQualifiedType.cs +++ b/sources/ClangSharp/Types/MacroQualifiedType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class MacroQualifiedType : Type { - private readonly Lazy _modifiedType; - private readonly Lazy _underlyingType; + private readonly ValueLazy _modifiedType; + private readonly ValueLazy _underlyingType; internal MacroQualifiedType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_MacroQualified) { - _modifiedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ModifiedType)); - _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _modifiedType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ModifiedType)); + _underlyingType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } public Type ModifiedType => _modifiedType.Value; diff --git a/sources/ClangSharp/Types/MatrixType.cs b/sources/ClangSharp/Types/MatrixType.cs index b5098601..54c906d3 100644 --- a/sources/ClangSharp/Types/MatrixType.cs +++ b/sources/ClangSharp/Types/MatrixType.cs @@ -7,11 +7,11 @@ namespace ClangSharp; public class MatrixType : Type { - private readonly Lazy _elementType; + private readonly ValueLazy _elementType; private protected MatrixType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(handle.ElementType)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.ElementType)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/Types/ObjCInterfaceType.cs b/sources/ClangSharp/Types/ObjCInterfaceType.cs index f2295836..f762af11 100644 --- a/sources/ClangSharp/Types/ObjCInterfaceType.cs +++ b/sources/ClangSharp/Types/ObjCInterfaceType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class ObjCInterfaceType : ObjCObjectType { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal ObjCInterfaceType(CXType handle) : base(handle, CXType_ObjCObject, CX_TypeClass_ObjCInterface) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public ObjCInterfaceDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/ObjCObjectPointerType.cs b/sources/ClangSharp/Types/ObjCObjectPointerType.cs index d6f2b9c8..e992c99d 100644 --- a/sources/ClangSharp/Types/ObjCObjectPointerType.cs +++ b/sources/ClangSharp/Types/ObjCObjectPointerType.cs @@ -10,13 +10,13 @@ namespace ClangSharp; public sealed class ObjCObjectPointerType : Type { - private readonly Lazy _interfaceType; - private readonly Lazy _superClassType; + private readonly ValueLazy _interfaceType; + private readonly ValueLazy _superClassType; internal ObjCObjectPointerType(CXType handle) : base(handle, CXType_ObjCObjectPointer, CX_TypeClass_ObjCObjectPointer) { - _interfaceType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); - _superClassType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _interfaceType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _superClassType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } public ObjCInterfaceDecl InterfaceDecl => ObjectType.Interface; diff --git a/sources/ClangSharp/Types/ObjCObjectType.cs b/sources/ClangSharp/Types/ObjCObjectType.cs index 64c696cf..ec0c6287 100644 --- a/sources/ClangSharp/Types/ObjCObjectType.cs +++ b/sources/ClangSharp/Types/ObjCObjectType.cs @@ -10,11 +10,11 @@ namespace ClangSharp; public class ObjCObjectType : Type { - private readonly Lazy _baseType; - private readonly Lazy _interface; - private readonly Lazy> _protocols; - private readonly Lazy _superClassType; - private readonly Lazy> _typeArgs; + private readonly ValueLazy _baseType; + private readonly ValueLazy _interface; + private readonly LazyList _protocols; + private readonly ValueLazy _superClassType; + private readonly LazyList _typeArgs; internal ObjCObjectType(CXType handle) : this(handle, CXType_ObjCObject, CX_TypeClass_ObjCObject) { @@ -22,44 +22,20 @@ internal ObjCObjectType(CXType handle) : this(handle, CXType_ObjCObject, CX_Type private protected ObjCObjectType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ObjCObjectBaseType)); - _interface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); - - _protocols = new Lazy>(() => { - var numProtocols = unchecked((int)Handle.NumObjCProtocolRefs); - var protocols = new List(numProtocols); - - for (var i = 0; i < numProtocols; i++) - { - var protocol = TranslationUnit.GetOrCreate(Handle.GetObjCProtocolDecl(unchecked((uint)i))); - protocols.Add(protocol); - } - - return protocols; - }); - - _superClassType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); - _typeArgs = new Lazy>(() => { - var numTypeArgs = unchecked((int)Handle.NumObjCTypeArgs); - var typeArgs = new List(numTypeArgs); - - for (var i = 0; i < numTypeArgs; i++) - { - var typeArg = TranslationUnit.GetOrCreate(Handle.GetObjCTypeArg(unchecked((uint)i))); - typeArgs.Add(typeArg); - } - - return typeArgs; - }); + _baseType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ObjCObjectBaseType)); + _interface = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _protocols = LazyList.Create(unchecked((int)Handle.NumObjCProtocolRefs), (i) => TranslationUnit.GetOrCreate(Handle.GetObjCProtocolDecl(unchecked((uint)i)))); + _superClassType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _typeArgs = LazyList.Create(unchecked((int)Handle.NumObjCTypeArgs), (i) => TranslationUnit.GetOrCreate(Handle.GetObjCTypeArg(unchecked((uint)i)))); } public Type BaseType => _baseType.Value; public ObjCInterfaceDecl Interface => _interface.Value; - public IReadOnlyList Protocols => _protocols.Value; + public IReadOnlyList Protocols => _protocols; public Type SuperClassType => _superClassType.Value; - public IReadOnlyList TypeArgs => _typeArgs.Value; + public IReadOnlyList TypeArgs => _typeArgs; } diff --git a/sources/ClangSharp/Types/ObjCTypeParamType.cs b/sources/ClangSharp/Types/ObjCTypeParamType.cs index ca8f139b..9c42cba0 100644 --- a/sources/ClangSharp/Types/ObjCTypeParamType.cs +++ b/sources/ClangSharp/Types/ObjCTypeParamType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class ObjCTypeParamType : Type { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal ObjCTypeParamType(CXType handle) : base(handle, CXType_ObjCTypeParam, CX_TypeClass_ObjCTypeParam) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public ObjCTypeParamDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/PackExpansionType.cs b/sources/ClangSharp/Types/PackExpansionType.cs index 34201091..e2c64c11 100644 --- a/sources/ClangSharp/Types/PackExpansionType.cs +++ b/sources/ClangSharp/Types/PackExpansionType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class PackExpansionType : Type { - private readonly Lazy _pattern; + private readonly ValueLazy _pattern; internal PackExpansionType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_PackExpansion) { - _pattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _pattern = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public Type Pattern => _pattern.Value; diff --git a/sources/ClangSharp/Types/PipeType.cs b/sources/ClangSharp/Types/PipeType.cs index 429608be..58727e23 100644 --- a/sources/ClangSharp/Types/PipeType.cs +++ b/sources/ClangSharp/Types/PipeType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class PipeType : Type { - private readonly Lazy _elementType; + private readonly ValueLazy _elementType; internal PipeType(CXType handle) : base(handle, CXType_Pipe, CX_TypeClass_Pipe) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs b/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs index dd4672e4..e7ae53f3 100644 --- a/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs +++ b/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs @@ -9,13 +9,13 @@ namespace ClangSharp; public sealed class SubstTemplateTypeParmPackType : Type { - private readonly Lazy _argumentPack; - private readonly Lazy _replacedParameter; + private readonly ValueLazy _argumentPack; + private readonly ValueLazy _replacedParameter; internal SubstTemplateTypeParmPackType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_SubstTemplateTypeParmPack) { - _argumentPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(0))); - _replacedParameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _argumentPack = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(0))); + _replacedParameter = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public TemplateArgument ArgumentPack => _argumentPack.Value; diff --git a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs index d09e2a5c..68c9a92f 100644 --- a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs +++ b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs @@ -9,16 +9,16 @@ namespace ClangSharp; public sealed class SubstTemplateTypeParmType : Type { - private readonly Lazy _associatedDecl; - private readonly Lazy _replacedParameter; + private readonly ValueLazy _associatedDecl; + private readonly ValueLazy _replacedParameter; internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_SubstTemplateTypeParm) { - _associatedDecl = new Lazy(() => { - CXCursor cursor = clangsharp.Type_getSubstTemplateTypeParamAssociatedDecl(Handle); + _associatedDecl = new ValueLazy(() => { + var cursor = clangsharp.Type_getSubstTemplateTypeParamAssociatedDecl(Handle); return cursor.IsNull ? null : TranslationUnit.GetOrCreate(cursor); }); - _replacedParameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _replacedParameter = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public TemplateTypeParmType ReplacedParameter => _replacedParameter.Value; diff --git a/sources/ClangSharp/Types/TagType.cs b/sources/ClangSharp/Types/TagType.cs index 52c25460..70ee8f95 100644 --- a/sources/ClangSharp/Types/TagType.cs +++ b/sources/ClangSharp/Types/TagType.cs @@ -7,11 +7,11 @@ namespace ClangSharp; public class TagType : Type { - private readonly Lazy _decl; + private readonly ValueLazy _decl; private protected TagType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public TagDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/TemplateSpecializationType.cs b/sources/ClangSharp/Types/TemplateSpecializationType.cs index b83317d5..c78075e6 100644 --- a/sources/ClangSharp/Types/TemplateSpecializationType.cs +++ b/sources/ClangSharp/Types/TemplateSpecializationType.cs @@ -4,37 +4,25 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using ClangSharp.Interop; -using static ClangSharp.Interop.CXTypeKind; using static ClangSharp.Interop.CX_TypeClass; +using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed class TemplateSpecializationType : Type { - private readonly Lazy> _templateArgs; - private readonly Lazy _templateName; + private readonly LazyList _templateArgs; + private readonly ValueLazy _templateName; internal TemplateSpecializationType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_TemplateSpecialization) { - _templateArgs = new Lazy>(() => { - var templateArgCount = Handle.NumTemplateArguments; - var templateArgs = new List(templateArgCount); - - for (var i = 0; i < templateArgCount; i++) - { - var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); - templateArgs.Add(templateArg); - } - - return templateArgs; - }); - - _templateName = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); + _templateArgs = LazyList.Create(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i)))); + _templateName = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); } public Type? AliasedType => IsTypeAlias ? Desugar : null; - public IReadOnlyList Args => _templateArgs.Value; + public IReadOnlyList Args => _templateArgs; [MemberNotNullWhen(true, nameof(AliasedType))] public bool IsTypeAlias => Handle.IsTypeAlias; diff --git a/sources/ClangSharp/Types/TemplateTypeParmType.cs b/sources/ClangSharp/Types/TemplateTypeParmType.cs index 37adda7b..ca3a626d 100644 --- a/sources/ClangSharp/Types/TemplateTypeParmType.cs +++ b/sources/ClangSharp/Types/TemplateTypeParmType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class TemplateTypeParmType : Type { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal TemplateTypeParmType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_TemplateTypeParm) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public TemplateTypeParmDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/Type.cs b/sources/ClangSharp/Types/Type.cs index a5653549..0c54d5bf 100644 --- a/sources/ClangSharp/Types/Type.cs +++ b/sources/ClangSharp/Types/Type.cs @@ -11,12 +11,12 @@ namespace ClangSharp; [DebuggerDisplay("{Handle.DebuggerDisplayString,nq}")] public unsafe class Type : IEquatable { - private readonly Lazy _asString; - private readonly Lazy _canonicalType; - private readonly Lazy _desugar; - private readonly Lazy _kindSpelling; - private readonly Lazy _pointeeType; - private readonly Lazy _translationUnit; + private readonly ValueLazy _asString; + private readonly ValueLazy _canonicalType; + private readonly ValueLazy _desugar; + private readonly ValueLazy _kindSpelling; + private readonly ValueLazy _pointeeType; + private readonly ValueLazy _translationUnit; protected Type(CXType handle, CXTypeKind expectedKind, CX_TypeClass expectedTypeClass) { @@ -31,12 +31,12 @@ protected Type(CXType handle, CXTypeKind expectedKind, CX_TypeClass expectedType } Handle = handle; - _asString = new Lazy(Handle.Spelling.ToString); - _canonicalType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CanonicalType)); - _desugar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar)); - _kindSpelling = new Lazy(Handle.KindSpelling.ToString); - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); - _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate((CXTranslationUnit)Handle.data[1])); + _asString = new ValueLazy(Handle.Spelling.ToString); + _canonicalType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.CanonicalType)); + _desugar = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Desugar)); + _kindSpelling = new ValueLazy(Handle.KindSpelling.ToString); + _pointeeType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); + _translationUnit = new ValueLazy(() => TranslationUnit.GetOrCreate((CXTranslationUnit)Handle.data[1])); } public CXXRecordDecl? AsCXXRecordDecl => AsTagDecl as CXXRecordDecl; diff --git a/sources/ClangSharp/Types/TypeOfExprType.cs b/sources/ClangSharp/Types/TypeOfExprType.cs index 2d9ef803..98759484 100644 --- a/sources/ClangSharp/Types/TypeOfExprType.cs +++ b/sources/ClangSharp/Types/TypeOfExprType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class TypeOfExprType : Type { - private readonly Lazy _underlyingExpr; + private readonly ValueLazy _underlyingExpr; internal TypeOfExprType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_TypeOfExpr) { - _underlyingExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.UnderlyingExpr)); + _underlyingExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.UnderlyingExpr)); } public Expr UnderlyingExpr => _underlyingExpr.Value; diff --git a/sources/ClangSharp/Types/TypeOfType.cs b/sources/ClangSharp/Types/TypeOfType.cs index 114cc3a2..e2572208 100644 --- a/sources/ClangSharp/Types/TypeOfType.cs +++ b/sources/ClangSharp/Types/TypeOfType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class TypeOfType : Type { - private readonly Lazy _underlyingType; + private readonly ValueLazy _underlyingType; internal TypeOfType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_TypeOf) { - _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _underlyingType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } public Type UnderlyingType => _underlyingType.Value; diff --git a/sources/ClangSharp/Types/TypedefType.cs b/sources/ClangSharp/Types/TypedefType.cs index 1846c071..2f0082db 100644 --- a/sources/ClangSharp/Types/TypedefType.cs +++ b/sources/ClangSharp/Types/TypedefType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class TypedefType : Type { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal TypedefType(CXType handle) : base(handle, CXType_Typedef, CX_TypeClass_Typedef) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public TypedefNameDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/UnaryTransformType.cs b/sources/ClangSharp/Types/UnaryTransformType.cs index ac0283c7..52c9d266 100644 --- a/sources/ClangSharp/Types/UnaryTransformType.cs +++ b/sources/ClangSharp/Types/UnaryTransformType.cs @@ -9,8 +9,8 @@ namespace ClangSharp; public class UnaryTransformType : Type { - private readonly Lazy _baseType; - private readonly Lazy _underlyingType; + private readonly ValueLazy _baseType; + private readonly ValueLazy _underlyingType; internal UnaryTransformType(CXType handle) : this(handle, CXType_Unexposed, CX_TypeClass_UnaryTransform) { @@ -18,8 +18,8 @@ internal UnaryTransformType(CXType handle) : this(handle, CXType_Unexposed, CX_T private protected UnaryTransformType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BaseType)); - _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _baseType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.BaseType)); + _underlyingType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } public Type BaseType => _baseType.Value; diff --git a/sources/ClangSharp/Types/UnresolvedUsingType.cs b/sources/ClangSharp/Types/UnresolvedUsingType.cs index 1072a548..460fb453 100644 --- a/sources/ClangSharp/Types/UnresolvedUsingType.cs +++ b/sources/ClangSharp/Types/UnresolvedUsingType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class UnresolvedUsingType : Type { - private readonly Lazy _decl; + private readonly ValueLazy _decl; internal UnresolvedUsingType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_UnresolvedUsing) { - _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _decl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public UnresolvedUsingTypenameDecl Decl => _decl.Value; diff --git a/sources/ClangSharp/Types/UsingType.cs b/sources/ClangSharp/Types/UsingType.cs index 78662422..bcf149c8 100644 --- a/sources/ClangSharp/Types/UsingType.cs +++ b/sources/ClangSharp/Types/UsingType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class UsingType : Type { - private readonly Lazy _foundDecl; + private readonly ValueLazy _foundDecl; internal UsingType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_Using) { - _foundDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + _foundDecl = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } public UsingShadowDecl FoundDecl => _foundDecl.Value; diff --git a/sources/ClangSharp/Types/VariableArrayType.cs b/sources/ClangSharp/Types/VariableArrayType.cs index ac154804..33c745ed 100644 --- a/sources/ClangSharp/Types/VariableArrayType.cs +++ b/sources/ClangSharp/Types/VariableArrayType.cs @@ -9,11 +9,11 @@ namespace ClangSharp; public sealed class VariableArrayType : ArrayType { - private readonly Lazy _sizeExpr; + private readonly ValueLazy _sizeExpr; internal VariableArrayType(CXType handle) : base(handle, CXType_VariableArray, CX_TypeClass_VariableArray) { - _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.SizeExpr)); + _sizeExpr = new ValueLazy(() => TranslationUnit.GetOrCreate(handle.SizeExpr)); } public Expr SizeExpr => _sizeExpr.Value; diff --git a/sources/ClangSharp/Types/VectorType.cs b/sources/ClangSharp/Types/VectorType.cs index 6f93a1ef..2f2ef8fc 100644 --- a/sources/ClangSharp/Types/VectorType.cs +++ b/sources/ClangSharp/Types/VectorType.cs @@ -9,7 +9,7 @@ namespace ClangSharp; public class VectorType : Type { - private readonly Lazy _elementType; + private readonly ValueLazy _elementType; internal VectorType(CXType handle) : this(handle, CXType_Vector, CX_TypeClass_Vector) { @@ -17,7 +17,7 @@ internal VectorType(CXType handle) : this(handle, CXType_Vector, CX_TypeClass_Ve private protected VectorType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); + _elementType = new ValueLazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); } public Type ElementType => _elementType.Value; diff --git a/sources/ClangSharp/ValueLazy`1.cs b/sources/ClangSharp/ValueLazy`1.cs new file mode 100644 index 00000000..645aacbb --- /dev/null +++ b/sources/ClangSharp/ValueLazy`1.cs @@ -0,0 +1,67 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// This file includes code based on the Lazy class from https://github.com/dotnet/runtime/ +// The original code is Copyright © .NET Foundation and Contributors. All rights reserved. Licensed under the MIT License (MIT). + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace ClangSharp; + +internal partial struct ValueLazy<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T> : IEquatable> +{ + private Func? _factory; + private T _value; + + public ValueLazy(Func factory) + { + Unsafe.SkipInit(out this); + Reset(factory); + } + + public readonly bool IsValueCreated => _factory is null; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public T Value + { + get + { + if (_factory is Func factory) + { + _value = factory(); + _factory = null; + } + return _value; + } + } + + public static bool operator ==(ValueLazy left, ValueLazy right) + => (left._factory == right._factory) + && EqualityComparer.Default.Equals(left._value, right._value); + + public static bool operator !=(ValueLazy left, ValueLazy right) => !(left == right); + + public override readonly bool Equals([NotNullWhen(true)] object? obj) => (obj is ValueLazy other) && Equals(other); + + public readonly bool Equals(ValueLazy other) => this == other; + + public override readonly int GetHashCode() => HashCode.Combine(_factory, _value); + + public void Reset(Func factory) + { + ArgumentNullException.ThrowIfNull(factory); + _factory = factory; + } + + public override readonly string ToString() + { + if (!IsValueCreated || (_value is not T value)) + { + return string.Empty; + } + return value.ToString() ?? string.Empty; + } +} diff --git a/sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj b/sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj index 9f8590ea..cb6bf71a 100644 --- a/sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj +++ b/sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj @@ -4,9 +4,13 @@ Exe true - win-x64 - - net8.0 + true + linux-arm64;linux-x64;osx-arm64;win-arm64;win-x64 + net10.0 + + + + false @@ -14,8 +18,6 @@ - - @@ -30,13 +32,12 @@ libclang libClangSharp - libLLVM C:\Program Files\LLVM\include - /usr/lib/llvm-18/include + /usr/lib/llvm-20/include diff --git a/sources/ClangSharpPInvokeGenerator/Program.cs b/sources/ClangSharpPInvokeGenerator/Program.cs index 8bad0657..742c0290 100644 --- a/sources/ClangSharpPInvokeGenerator/Program.cs +++ b/sources/ClangSharpPInvokeGenerator/Program.cs @@ -20,7 +20,7 @@ namespace ClangSharp; -public static class Program +internal static class Program { private static readonly string[] s_additionalOptionAliases = ["--additional", "-a"]; private static readonly string[] s_configOptionAliases = ["--config", "-c"]; @@ -54,6 +54,7 @@ public static class Program private static readonly string[] s_withManualImportOptionAliases = ["--with-manual-import", "-wmi"]; private static readonly string[] s_withNamespaceOptionAliases = ["--with-namespace", "-wn"]; private static readonly string[] s_withPackingOptionAliases = ["--with-packing", "-wp"]; + private static readonly string[] s_withReadonlyOptionAliases = ["--with-readonly", "-wro"]; private static readonly string[] s_withSetLastErrorOptionAliases = ["--with-setlasterror", "-wsle"]; private static readonly string[] s_withSuppressGCTransitionOptionAliases = ["--with-suppressgctransition", "-wsgct"]; private static readonly string[] s_withTransparentStructOptionAliases = ["--with-transparent-struct", "-wts"]; @@ -92,6 +93,7 @@ public static class Program private static readonly Option s_withManualImports = GetWithManualImportOption(); private static readonly Option s_withNamespaceNameValuePairs = GetWithNamespaceOption(); private static readonly Option s_withPackingNameValuePairs = GetWithPackingOption(); + private static readonly Option s_withReadonlys = GetWithReadonlyOption(); private static readonly Option s_withSetLastErrors = GetWithSetLastErrorOption(); private static readonly Option s_withSuppressGCTransitions = GetWithSuppressGCTransitionOption(); private static readonly Option s_withTransparentStructNameValuePairs = GetWithTransparentStructOption(); @@ -109,9 +111,9 @@ public static class Program new TwoColumnHelpRow("", ""), new TwoColumnHelpRow("compatible-codegen", "Bindings should be generated with .NET Standard 2.0 compatibility. Setting this disables preview code generation."), - new TwoColumnHelpRow("default-codegen", "Bindings should be generated for the current LTS version of .NET/C#. This is currently .NET 6/C# 10."), - new TwoColumnHelpRow("latest-codegen", "Bindings should be generated for the current STS version of .NET/C#. This is currently .NET 7/C# 11."), - new TwoColumnHelpRow("preview-codegen", "Bindings should be generated for the preview version of .NET/C#. This is currently .NET 8/C# 12."), + new TwoColumnHelpRow("default-codegen", "Bindings should be generated for the current LTS version of .NET/C#. This is currently .NET 8/C# 12."), + new TwoColumnHelpRow("latest-codegen", "Bindings should be generated for the current STS version of .NET/C#. This is currently .NET 10/C# 14."), + new TwoColumnHelpRow("preview-codegen", "Bindings should be generated for the preview version of .NET/C#. This is currently .NET 10/C# 14."), new TwoColumnHelpRow("", ""), new TwoColumnHelpRow("# File Options", ""), @@ -255,6 +257,7 @@ public static void Run(InvocationContext context) var withLibraryPathNameValuePairs = context.ParseResult.GetValueForOption(s_withLibraryPathNameValuePairs) ?? []; var withManualImports = context.ParseResult.GetValueForOption(s_withManualImports) ?? []; var withNamespaceNameValuePairs = context.ParseResult.GetValueForOption(s_withNamespaceNameValuePairs) ?? []; + var withReadonlys = context.ParseResult.GetValueForOption(s_withReadonlys) ?? []; var withSetLastErrors = context.ParseResult.GetValueForOption(s_withSetLastErrors) ?? []; var withSuppressGCTransitions = context.ParseResult.GetValueForOption(s_withSuppressGCTransitions) ?? []; var withTransparentStructNameValuePairs = context.ParseResult.GetValueForOption(s_withTransparentStructNameValuePairs) ?? []; @@ -266,7 +269,7 @@ public static void Run(InvocationContext context) if (versionResult is not null) { - context.Console.WriteLine($"{s_rootCommand.Description} version 18.1.3"); + context.Console.WriteLine($"{s_rootCommand.Description} version 20.1.2"); context.Console.WriteLine($" {clang.getClangVersion()}"); context.Console.WriteLine($" {clangsharp.getVersion()}"); context.ExitCode = -1; @@ -729,6 +732,7 @@ public static void Run(InvocationContext context) WithLibraryPaths = withLibraryPaths, WithManualImports = withManualImports, WithNamespaces = withNamespaces, + WithReadonlys = withReadonlys, WithSetLastErrors = withSetLastErrors, WithSuppressGCTransitions = withSuppressGCTransitions, WithTransparentStructs = withTransparentStructs, @@ -1202,6 +1206,7 @@ private static RootCommand GetRootCommand() s_withManualImports, s_withNamespaceNameValuePairs, s_withPackingNameValuePairs, + s_withReadonlys, s_withSetLastErrors, s_withSuppressGCTransitions, s_withTransparentStructNameValuePairs, @@ -1350,6 +1355,17 @@ private static Option GetWithNamespaceOption() }; } + private static Option GetWithReadonlyOption() + { + return new Option( + aliases: s_withReadonlyOptionAliases, + description: "Add the readonly modifier to a given instance method. Supports wildcards.", + getDefaultValue: Array.Empty + ) { + AllowMultipleArgumentsPerToken = true + }; + } + private static Option GetWithSetLastErrorOption() { return new Option( diff --git a/sources/ClangSharpPInvokeGenerator/Properties/GenerateClang-LICENSE.txt b/sources/ClangSharpPInvokeGenerator/Properties/GenerateClang-LICENSE.txt index 21246cb4..83233f6d 100644 --- a/sources/ClangSharpPInvokeGenerator/Properties/GenerateClang-LICENSE.txt +++ b/sources/ClangSharpPInvokeGenerator/Properties/GenerateClang-LICENSE.txt @@ -1,4 +1,4 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/include/clang-c +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/include/clang-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. diff --git a/sources/ClangSharpPInvokeGenerator/Properties/GenerateLLVM-LICENSE.txt b/sources/ClangSharpPInvokeGenerator/Properties/GenerateLLVM-LICENSE.txt deleted file mode 100644 index 37cc4487..00000000 --- a/sources/ClangSharpPInvokeGenerator/Properties/GenerateLLVM-LICENSE.txt +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/llvm/include/llvm-c -// Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. diff --git a/sources/ClangSharpPInvokeGenerator/Properties/GenerateLLVM.rsp b/sources/ClangSharpPInvokeGenerator/Properties/GenerateLLVM.rsp deleted file mode 100644 index e54d8869..00000000 --- a/sources/ClangSharpPInvokeGenerator/Properties/GenerateLLVM.rsp +++ /dev/null @@ -1,101 +0,0 @@ ---additional --m64 ---config -exclude-com-proxies -exclude-empty-records -exclude-enum-operators -generate-aggressive-inlining -generate-callconv-member-function -generate-cpp-attributes -generate-disable-runtime-marshalling -generate-file-scoped-namespaces -generate-guid-member -generate-macro-bindings -generate-marker-interfaces -generate-native-inheritance-attribute -generate-setslastsystemerror-attribute -generate-tests-nunit -generate-unmanaged-constants -generate-vtbl-index-attribute -log-potential-typedef-remappings -multi-file -preview-codegen -trimmable-vtbls -unix-types ---exclude -LLVMInitializeNativeAsmParser -LLVMInitializeNativeAsmPrinter -LLVMInitializeNativeDisassembler -LLVMInitializeNativeTarget -LLVM_ATTRIBUTE_C_DEPRECATED -LLVM_DECLARE_VALUE_CAST -LLVM_FOR_EACH_VALUE_SUBCLASS ---file -llvm-c/Analysis.h -llvm-c/BitReader.h -llvm-c/BitWriter.h -llvm-c/blake3.h -llvm-c/Comdat.h -llvm-c/Core.h -llvm-c/DataTypes.h -llvm-c/DebugInfo.h -llvm-c/Deprecated.h -llvm-c/Disassembler.h -llvm-c/DisassemblerTypes.h -llvm-c/Error.h -llvm-c/ErrorHandling.h -llvm-c/ExecutionEngine.h -llvm-c/ExternC.h -llvm-c/IRReader.h -llvm-c/Linker.h -llvm-c/LLJIT.h -llvm-c/lto.h -llvm-c/Object.h -llvm-c/Orc.h -llvm-c/OrcEE.h -llvm-c/Remarks.h -llvm-c/Support.h -llvm-c/Target.h -llvm-c/TargetMachine.h -llvm-c/Types.h -llvm-c/Transforms/PassBuilder.h ---headerFile -./Properties/GenerateLLVM-LICENSE.txt ---methodClassName -LLVM ---namespace -LLVMSharp.Interop ---output -./sources/LLVMSharp/Interop ---prefixStrip -LLVM ---remap -LLVMAttributeIndex=LLVMAttributeIndex -LLVM_BLAKE3_BLOCK_LEN=@BLAKE3_BLOCK_LEN -LLVM_BLAKE3_CHUNK_LEN=@BLAKE3_CHUNK_LEN -llvm_blake3_hasher_finalize=@blake3_hasher_finalize -llvm_blake3_hasher_finalize_seek=@blake3_hasher_finalize_seek -llvm_blake3_hasher_init=@blake3_hasher_init -llvm_blake3_hasher_init_derive_key=@blake3_hasher_init_derive_key -llvm_blake3_hasher_init_derive_key_raw=@blake3_hasher_init_derive_key_raw -llvm_blake3_hasher_init_keyed=@blake3_hasher_init_keyed -llvm_blake3_hasher_reset=@blake3_hasher_reset -llvm_blake3_hasher_update=@blake3_hasher_update -LLVM_BLAKE3_KEY_LEN=@BLAKE3_KEY_LEN -LLVM_BLAKE3_MAX_DEPTH=@BLAKE3_MAX_DEPTH -LLVM_BLAKE3_OUT_LEN=@BLAKE3_OUT_LEN -llvm_blake3_version=@blake3_version -LLVM_BLAKE3_VERSION_STRING=@BLAKE3_VERSION_STRING -LLVMOpaqueValueMetadataEntry=LLVMValueMetadataEntry -LLVMOpaqueModuleFlagEntry=LLVMModuleFlagEntry -__AnonymousEnum_Core_L462_C1=@LLVMAttributeIndex -__AnonymousEnum_Core_L486_C1=@LLVMFastMathFlags -__AnonymousEnum_DebugInfo_L147_C1=@LLVMMetadataKind ---test-output -./tests/LLVMSharp.UnitTests/Interop ---with-attribute -LLVMDIFlags=Flags -LLVMJITSymbolGenericFlags=Flags -LLVMFastMathFlags=Flags -LLVMOrcJITDylibLookupFlags=Flags -LLVMOrcSymbolLookupFlags=Flags diff --git a/sources/ClangSharpPInvokeGenerator/Properties/launchSettings.json b/sources/ClangSharpPInvokeGenerator/Properties/launchSettings.json index 922ee360..b961eec5 100644 --- a/sources/ClangSharpPInvokeGenerator/Properties/launchSettings.json +++ b/sources/ClangSharpPInvokeGenerator/Properties/launchSettings.json @@ -9,14 +9,10 @@ "commandName": "Project", "commandLineArgs": "\"@$(MSBuildProjectDirectory)/Properties/GenerateClangSharp.rsp\" --file-directory \"$(MSBuildProjectDirectory)/..\" --include-directory \"$(LLVMIncludePath)\" --libraryPath $(LibClangSharpName)" }, - "GenerateLLVM": { - "commandName": "Project", - "commandLineArgs": "\"@$(MSBuildProjectDirectory)/Properties/GenerateLLVM.rsp\" --file-directory \"$(LLVMIncludePath)\" --include-directory \"$(LLVMIncludePath)\" --libraryPath $(LibLLVMName)" - }, "GenerateLocal": { "commandName": "Project", "commandLineArgs": "@generate.rsp", - "workingDirectory": "D:\\Users\\tagoo\\source\\repos\\terrafx.interop.windows\\generation\\Windows\\um\\sapi" + "workingDirectory": "D:\\repos\\terrafx.interop.windows\\generation\\windows\\um\\winioctl" } } } diff --git a/sources/libClangSharp/CIndexDiagnostic.cpp b/sources/libClangSharp/CIndexDiagnostic.cpp index 28196bfc..632ebf1c 100644 --- a/sources/libClangSharp/CIndexDiagnostic.cpp +++ b/sources/libClangSharp/CIndexDiagnostic.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "CIndexDiagnostic.h" diff --git a/sources/libClangSharp/CIndexDiagnostic.h b/sources/libClangSharp/CIndexDiagnostic.h index fc64b057..06e03bfe 100644 --- a/sources/libClangSharp/CIndexDiagnostic.h +++ b/sources/libClangSharp/CIndexDiagnostic.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CINDEXDIAGNOSTIC_H diff --git a/sources/libClangSharp/CXCursor.cpp b/sources/libClangSharp/CXCursor.cpp index 40bcd24a..85dcf558 100644 --- a/sources/libClangSharp/CXCursor.cpp +++ b/sources/libClangSharp/CXCursor.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "ClangSharp.h" @@ -512,6 +512,9 @@ namespace clang::cxcursor { case Stmt::ObjCSubscriptRefExprClass: case Stmt::RecoveryExprClass: case Stmt::SYCLUniqueStableNameExprClass: + case Stmt::EmbedExprClass: + case Stmt::HLSLOutArgExprClass: + case Stmt::OpenACCAsteriskSizeExprClass: K = CXCursor_UnexposedExpr; break; @@ -550,6 +553,10 @@ namespace clang::cxcursor { K = CXCursor_UnexposedStmt; break; + case Stmt::SYCLKernelCallStmtClass: + K = CXCursor_UnexposedStmt; + break; + case Stmt::IntegerLiteralClass: K = CXCursor_IntegerLiteral; break; @@ -600,8 +607,8 @@ namespace clang::cxcursor { K = CXCursor_UnexposedExpr; break; - case Stmt::OMPArraySectionExprClass: - K = CXCursor_OMPArraySectionExpr; + case Stmt::ArraySectionExprClass: + K = CXCursor_ArraySectionExpr; break; case Stmt::OMPArrayShapingExprClass: @@ -744,6 +751,10 @@ namespace clang::cxcursor { K = CXCursor_SizeOfPackExpr; break; + case Stmt::PackIndexingExprClass: + K = CXCursor_PackIndexingExpr; + break; + case Stmt::DeclRefExprClass: if (const ImplicitParamDecl* IPD = dyn_cast_or_null(cast(S)->getDecl())) { if (const ObjCMethodDecl* MD = dyn_cast(IPD->getDeclContext())) { @@ -854,6 +865,12 @@ namespace clang::cxcursor { case Stmt::OMPUnrollDirectiveClass: K = CXCursor_OMPUnrollDirective; break; + case Stmt::OMPReverseDirectiveClass: + K = CXCursor_OMPReverseDirective; + break; + case Stmt::OMPInterchangeDirectiveClass: + K = CXCursor_OMPTileDirective; + break; case Stmt::OMPForDirectiveClass: K = CXCursor_OMPForDirective; break; @@ -866,6 +883,9 @@ namespace clang::cxcursor { case Stmt::OMPSectionDirectiveClass: K = CXCursor_OMPSectionDirective; break; + case Stmt::OMPScopeDirectiveClass: + K = CXCursor_OMPScopeDirective; + break; case Stmt::OMPSingleDirectiveClass: K = CXCursor_OMPSingleDirective; break; @@ -1049,11 +1069,51 @@ namespace clang::cxcursor { case Stmt::OMPParallelGenericLoopDirectiveClass: K = CXCursor_OMPParallelGenericLoopDirective; break; + case Stmt::OpenACCComputeConstructClass: + K = CXCursor_OpenACCComputeConstruct; + break; + case Stmt::OpenACCLoopConstructClass: + K = CXCursor_OpenACCLoopConstruct; + break; + case Stmt::OpenACCCombinedConstructClass: + K = CXCursor_OpenACCCombinedConstruct; + break; + case Stmt::OpenACCDataConstructClass: + K = CXCursor_OpenACCDataConstruct; + break; + case Stmt::OpenACCEnterDataConstructClass: + K = CXCursor_OpenACCEnterDataConstruct; + break; + case Stmt::OpenACCExitDataConstructClass: + K = CXCursor_OpenACCExitDataConstruct; + break; + case Stmt::OpenACCHostDataConstructClass: + K = CXCursor_OpenACCHostDataConstruct; + break; + case Stmt::OpenACCWaitConstructClass: + K = CXCursor_OpenACCWaitConstruct; + break; + case Stmt::OpenACCInitConstructClass: + K = CXCursor_OpenACCInitConstruct; + break; + case Stmt::OpenACCShutdownConstructClass: + K = CXCursor_OpenACCShutdownConstruct; + break; + case Stmt::OpenACCSetConstructClass: + K = CXCursor_OpenACCSetConstruct; + break; + case Stmt::OpenACCUpdateConstructClass: + K = CXCursor_OpenACCUpdateConstruct; + break; case Stmt::OMPTargetParallelGenericLoopDirectiveClass: K = CXCursor_OMPTargetParallelGenericLoopDirective; break; case Stmt::BuiltinBitCastExprClass: K = CXCursor_BuiltinBitCastExpr; + break; + case Stmt::OMPAssumeDirectiveClass: + K = CXCursor_OMPAssumeDirective; + break; } CXCursor C = { diff --git a/sources/libClangSharp/CXCursor.h b/sources/libClangSharp/CXCursor.h index 9056296e..d959dcb0 100644 --- a/sources/libClangSharp/CXCursor.h +++ b/sources/libClangSharp/CXCursor.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CXCURSOR_H diff --git a/sources/libClangSharp/CXLoadedDiagnostic.cpp b/sources/libClangSharp/CXLoadedDiagnostic.cpp index 01061133..a35652af 100644 --- a/sources/libClangSharp/CXLoadedDiagnostic.cpp +++ b/sources/libClangSharp/CXLoadedDiagnostic.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "CXLoadedDiagnostic.h" diff --git a/sources/libClangSharp/CXLoadedDiagnostic.h b/sources/libClangSharp/CXLoadedDiagnostic.h index d5e38c2f..898236c0 100644 --- a/sources/libClangSharp/CXLoadedDiagnostic.h +++ b/sources/libClangSharp/CXLoadedDiagnostic.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CXLOADEDDIAGNOSTIC_H diff --git a/sources/libClangSharp/CXSourceLocation.cpp b/sources/libClangSharp/CXSourceLocation.cpp index f87eb701..58241e51 100644 --- a/sources/libClangSharp/CXSourceLocation.cpp +++ b/sources/libClangSharp/CXSourceLocation.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "ClangSharp.h" diff --git a/sources/libClangSharp/CXSourceLocation.h b/sources/libClangSharp/CXSourceLocation.h index b81c055c..7eaf7843 100644 --- a/sources/libClangSharp/CXSourceLocation.h +++ b/sources/libClangSharp/CXSourceLocation.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CXSOURCELOCATION_H diff --git a/sources/libClangSharp/CXString.cpp b/sources/libClangSharp/CXString.cpp index 189b97db..b7113178 100644 --- a/sources/libClangSharp/CXString.cpp +++ b/sources/libClangSharp/CXString.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "CXString.h" diff --git a/sources/libClangSharp/CXString.h b/sources/libClangSharp/CXString.h index 320f2a2b..a1e93913 100644 --- a/sources/libClangSharp/CXString.h +++ b/sources/libClangSharp/CXString.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CXSTRING_H diff --git a/sources/libClangSharp/CXTranslationUnit.cpp b/sources/libClangSharp/CXTranslationUnit.cpp index 67f9d3d0..69fecdb2 100644 --- a/sources/libClangSharp/CXTranslationUnit.cpp +++ b/sources/libClangSharp/CXTranslationUnit.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "CXTranslationUnit.h" diff --git a/sources/libClangSharp/CXTranslationUnit.h b/sources/libClangSharp/CXTranslationUnit.h index 41c29247..e9087cc4 100644 --- a/sources/libClangSharp/CXTranslationUnit.h +++ b/sources/libClangSharp/CXTranslationUnit.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CXTRANSLATIONUNIT_H diff --git a/sources/libClangSharp/CXType.cpp b/sources/libClangSharp/CXType.cpp index 78de4834..2446a2df 100644 --- a/sources/libClangSharp/CXType.cpp +++ b/sources/libClangSharp/CXType.cpp @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "ClangSharp.h" @@ -69,6 +69,8 @@ namespace clang::cxtype { BTCASE(OCLEvent); BTCASE(OCLQueue); BTCASE(OCLReserveID); +#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) BTCASE(Id); +#include "clang/Basic/HLSLIntangibleTypes.def" default: return CXType_Unexposed; } diff --git a/sources/libClangSharp/CXType.h b/sources/libClangSharp/CXType.h index 9d5bf292..73ef66ce 100644 --- a/sources/libClangSharp/CXType.h +++ b/sources/libClangSharp/CXType.h @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.3/clang/tools/libclang +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/clang/tools/libclang // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #ifndef LIBCLANGSHARP_CXTYPE_H diff --git a/sources/libClangSharp/ClangSharp.cpp b/sources/libClangSharp/ClangSharp.cpp index d0f0c8a9..dce9af1f 100644 --- a/sources/libClangSharp/ClangSharp.cpp +++ b/sources/libClangSharp/ClangSharp.cpp @@ -1025,7 +1025,7 @@ CXCursor clangsharp_Cursor_getDefaultArg(CXCursor C) { const Decl* D = getCursorDecl(C); if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { - return MakeCXCursor(NTTPD->getDefaultArgument(), NTTPD, getCursorTU(C)); + return MakeCXCursor(NTTPD->getDefaultArgument().getSourceExpression(), NTTPD, getCursorTU(C)); } if (const ParmVarDecl* PVD = dyn_cast(D)) { @@ -1044,7 +1044,7 @@ CXType clangsharp_Cursor_getDefaultArgType(CXCursor C) { if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { if (TTPD->hasDefaultArgument()) { - QT = TTPD->getDefaultArgument(); + QT = TTPD->getDefaultArgument().getTypeSourceInfo()->getType(); } } } @@ -2783,7 +2783,7 @@ unsigned clangsharp_Cursor_getIsUnnamedBitfield(CXCursor C) { const Decl* D = getCursorDecl(C); if (const FieldDecl* FD = dyn_cast(D)) { - return FD->isUnnamedBitfield(); + return FD->isUnnamedBitField(); } } @@ -3465,7 +3465,7 @@ int clangsharp_Cursor_getNumTemplateArguments(CXCursor C) { } if (FunctionTemplateDecl* FTD = const_cast(dyn_cast(D))) { - return FTD->getInjectedTemplateArgs().size(); + return FTD->getInjectedTemplateArgs(getCursorContext(C)).size(); } if (const ImplicitConceptSpecializationDecl* ICSD = const_cast(dyn_cast(D))) { @@ -4061,7 +4061,7 @@ CXCursor clangsharp_Cursor_getSubDecl(CXCursor C, unsigned i) { return MakeCXCursor(ND->getAnonymousNamespace(), getCursorTU(C)); } else if (i == 1) { - return MakeCXCursor(ND->getOriginalNamespace(), getCursorTU(C)); + return MakeCXCursor(ND->getFirstDecl(), getCursorTU(C)); } } @@ -4263,8 +4263,8 @@ CX_TemplateArgument clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i } if (FunctionTemplateDecl* FTD = const_cast(dyn_cast(D))) { - if (i < FTD->getInjectedTemplateArgs().size()) { - const TemplateArgument* TA = &FTD->getInjectedTemplateArgs()[i]; + if (i < FTD->getInjectedTemplateArgs(getCursorContext(C)).size()) { + const TemplateArgument* TA = &FTD->getInjectedTemplateArgs(getCursorContext(C))[i]; return MakeCXTemplateArgument(TA, getCursorTU(C)); } } @@ -4819,7 +4819,7 @@ int64_t clangsharp_Cursor_getVtblIdx(CXCursor C) { } CXString clangsharp_getVersion() { - return cxstring::createDup("clangsharp version 18.1.3"); + return cxstring::createDup("clangsharp version 20.1.2"); } void clangsharp_TemplateArgument_dispose(CX_TemplateArgument T) { diff --git a/sources/libClangSharp/ClangSharp.h b/sources/libClangSharp/ClangSharp.h index b7ea675a..3b152c39 100644 --- a/sources/libClangSharp/ClangSharp.h +++ b/sources/libClangSharp/ClangSharp.h @@ -32,7 +32,7 @@ enum CX_AtomicOperatorKind { CX_AO_Invalid, #define BUILTIN(ID, TYPE, ATTRS) #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) CX_AO##ID, -#include +#include }; enum CX_AttrKind { @@ -106,12 +106,19 @@ enum CX_FloatingSemantics { CX_FLK_IEEEdouble = llvm::APFloatBase::S_IEEEdouble + 1, CX_FLK_IEEEquad = llvm::APFloatBase::S_IEEEquad + 1, CX_FLK_PPCDoubleDouble = llvm::APFloatBase::S_PPCDoubleDouble + 1, + CX_FLK_PPCDoubleDoubleLegacy = llvm::APFloatBase::S_PPCDoubleDoubleLegacy + 1, CX_FLK_Float8E5M2 = llvm::APFloatBase::S_Float8E5M2 + 1, CX_FLK_Float8E5M2FNUZ = llvm::APFloatBase::S_Float8E5M2FNUZ + 1, + CX_FLK_Float8E4M3 = llvm::APFloatBase::S_Float8E4M3 + 1, CX_FLK_Float8E4M3FN = llvm::APFloatBase::S_Float8E4M3FN + 1, CX_FLK_Float8E4M3FNUZ = llvm::APFloatBase::S_Float8E4M3FNUZ + 1, CX_FLK_Float8E4M3B11FNUZ = llvm::APFloatBase::S_Float8E4M3B11FNUZ + 1, + CX_FLK_Float8E3M4 = llvm::APFloatBase::S_Float8E3M4 + 1, CX_FLK_FloatTF32 = llvm::APFloatBase::S_FloatTF32 + 1, + CX_FLK_Float8E8M0FNU = llvm::APFloatBase::S_Float8E8M0FNU + 1, + CX_FLK_Float6E3M2FN = llvm::APFloatBase::S_Float6E3M2FN + 1, + CX_FLK_Float6E2M3FN = llvm::APFloatBase::S_Float6E2M3FN + 1, + CX_FLK_Float4E2M1FN = llvm::APFloatBase::S_Float4E2M1FN + 1, CX_FLK_x87DoubleExtended = llvm::APFloatBase::S_x87DoubleExtended + 1, CX_FLK_MaxSemantics = llvm::APFloatBase::S_MaxSemantics + 1, }; @@ -162,6 +169,7 @@ enum CX_TemplateNameKind { CX_TNK_SubstTemplateTemplateParm = clang::TemplateName::SubstTemplateTemplateParm + 1, CX_TNK_SubstTemplateTemplateParmPack = clang::TemplateName::SubstTemplateTemplateParmPack + 1, CX_TNK_UsingTemplate = clang::TemplateName::UsingTemplate + 1, + CX_TNK_DeducedTemplate = clang::TemplateName::DeducedTemplate + 1, }; enum CX_TemplateSpecializationKind { diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs index afc4704c..5a363544 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs @@ -905,7 +905,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -929,7 +929,7 @@ public unsafe partial struct MyStruct public delegate void _MyVoidMethod(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public delegate sbyte _MyInt8Method(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] @@ -946,7 +946,7 @@ public void MyVoidMethod() }} }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ fixed (MyStruct* pThis = &this) @@ -983,7 +983,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1007,7 +1007,7 @@ public unsafe partial struct MyStruct public delegate void _MyVoidMethod(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public delegate sbyte _MyInt8Method(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] @@ -1026,7 +1026,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ fixed (MyStruct* pThis = &this) diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/StructDeclarationTest.cs index 67053b19..a3aa64ce 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/StructDeclarationTest.cs @@ -1161,7 +1161,7 @@ public ref {expectedManagedType} value1 {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous2_1_e__Struct* pField = &Anonymous.Anonymous2_1) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct* pField = &Anonymous.Anonymous1) {{ return ref pField->value1; }} @@ -1172,7 +1172,7 @@ public ref {expectedManagedType} value {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous2_1_e__Struct._Anonymous_2_e__Struct* pField = &Anonymous.Anonymous2_1.Anonymous_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous_e__Struct* pField = &Anonymous.Anonymous1.Anonymous) {{ return ref pField->value; }} @@ -1183,7 +1183,7 @@ public ref {expectedManagedType} value2 {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous3_1_e__Union* pField = &Anonymous.Anonymous3_1) + fixed (_Anonymous_e__Struct._Anonymous2_e__Union* pField = &Anonymous.Anonymous2) {{ return ref pField->value2; }} @@ -1231,10 +1231,10 @@ public unsafe partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; @@ -1249,21 +1249,21 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public unsafe partial struct _Anonymous2_1_e__Struct + public unsafe partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; @@ -1342,7 +1342,7 @@ public ref int w { get { - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -1353,12 +1353,12 @@ public int o0_b0_16 { get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1366,12 +1366,12 @@ public int o0_b16_4 { get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1380,9 +1380,9 @@ public unsafe partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -2032,7 +2032,7 @@ struct { int Second; } MyArray[2]; public unsafe partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; @@ -2041,33 +2041,33 @@ public ref int First { get { - fixed (_Anonymous1_e__Struct* pField = &Anonymous1) + fixed (_Anonymous_e__Struct* pField = &Anonymous) { return ref pField->First; } } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; - public _Anonymous2_e__Struct e1; + public _MyArray_e__Struct e0; + public _MyArray_e__Struct e1; - public unsafe ref _Anonymous2_e__Struct this[int index] + public unsafe ref _MyArray_e__Struct this[int index] { get { - fixed (_Anonymous2_e__Struct* pThis = &e0) + fixed (_MyArray_e__Struct* pThis = &e0) { return ref pThis[index]; } @@ -2102,7 +2102,7 @@ public ref int Value1 { get { - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous1_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous1_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous2_e__Struct* pField = &Anonymous.Anonymous1.Anonymous2) { return ref pField->Value1; } @@ -2113,7 +2113,7 @@ public ref int Value2 { get { - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous2_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous2_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous3_e__Struct* pField = &Anonymous.Anonymous1.Anonymous3) { return ref pField->Value2; } @@ -2123,22 +2123,22 @@ public ref int Value2 public unsafe partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public unsafe partial struct _Anonymous_1_e__Struct + public unsafe partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/UnionDeclarationTest.cs index 873019f8..0202a10e 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/UnionDeclarationTest.cs @@ -918,7 +918,7 @@ public ref int w { get { - fixed (_Anonymous_e__Union._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Union._Anonymous1_e__Union* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -929,12 +929,12 @@ public int o0_b0_16 { get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -942,12 +942,12 @@ public int o0_b16_4 { get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -959,10 +959,10 @@ public unsafe partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -1504,22 +1504,22 @@ public ref IntPtr First }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->A; }} }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->B; }} @@ -1532,10 +1532,10 @@ public unsafe partial struct _Anonymous_e__Struct public IntPtr First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs index 14249777..88bd0b5e 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs @@ -900,7 +900,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -924,7 +924,7 @@ public unsafe partial struct MyStruct public delegate void _MyVoidMethod(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public delegate sbyte _MyInt8Method(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] @@ -941,7 +941,7 @@ public void MyVoidMethod() }} }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ fixed (MyStruct* pThis = &this) @@ -978,7 +978,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1002,7 +1002,7 @@ public unsafe partial struct MyStruct public delegate void _MyVoidMethod(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public delegate sbyte _MyInt8Method(MyStruct* pThis); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] @@ -1021,7 +1021,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ fixed (MyStruct* pThis = &this) diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/StructDeclarationTest.cs index 495d50d6..f3b68211 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/StructDeclarationTest.cs @@ -1169,7 +1169,7 @@ public ref {expectedManagedType} value1 {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous2_1_e__Struct* pField = &Anonymous.Anonymous2_1) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct* pField = &Anonymous.Anonymous1) {{ return ref pField->value1; }} @@ -1180,7 +1180,7 @@ public ref {expectedManagedType} value {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous2_1_e__Struct._Anonymous_2_e__Struct* pField = &Anonymous.Anonymous2_1.Anonymous_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous_e__Struct* pField = &Anonymous.Anonymous1.Anonymous) {{ return ref pField->value; }} @@ -1191,7 +1191,7 @@ public ref {expectedManagedType} value2 {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous3_1_e__Union* pField = &Anonymous.Anonymous3_1) + fixed (_Anonymous_e__Struct._Anonymous2_e__Union* pField = &Anonymous.Anonymous2) {{ return ref pField->value2; }} @@ -1239,10 +1239,10 @@ public unsafe partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; @@ -1257,21 +1257,21 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public unsafe partial struct _Anonymous2_1_e__Struct + public unsafe partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; @@ -1350,7 +1350,7 @@ public ref int w { get { - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -1361,12 +1361,12 @@ public int o0_b0_16 { get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1374,12 +1374,12 @@ public int o0_b16_4 { get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1388,9 +1388,9 @@ public unsafe partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -2038,7 +2038,7 @@ struct { int Second; } MyArray[2]; public unsafe partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; @@ -2047,33 +2047,33 @@ public ref int First { get { - fixed (_Anonymous1_e__Struct* pField = &Anonymous1) + fixed (_Anonymous_e__Struct* pField = &Anonymous) { return ref pField->First; } } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; - public _Anonymous2_e__Struct e1; + public _MyArray_e__Struct e0; + public _MyArray_e__Struct e1; - public unsafe ref _Anonymous2_e__Struct this[int index] + public unsafe ref _MyArray_e__Struct this[int index] { get { - fixed (_Anonymous2_e__Struct* pThis = &e0) + fixed (_MyArray_e__Struct* pThis = &e0) { return ref pThis[index]; } @@ -2108,7 +2108,7 @@ public ref int Value1 { get { - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous1_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous1_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous2_e__Struct* pField = &Anonymous.Anonymous1.Anonymous2) { return ref pField->Value1; } @@ -2119,7 +2119,7 @@ public ref int Value2 { get { - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous2_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous2_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous3_e__Struct* pField = &Anonymous.Anonymous1.Anonymous3) { return ref pField->Value2; } @@ -2129,22 +2129,22 @@ public ref int Value2 public unsafe partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public unsafe partial struct _Anonymous_1_e__Struct + public unsafe partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/UnionDeclarationTest.cs index 2bbdbdc3..372e97f2 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/UnionDeclarationTest.cs @@ -925,7 +925,7 @@ public ref int w { get { - fixed (_Anonymous_e__Union._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Union._Anonymous1_e__Union* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -936,12 +936,12 @@ public int o0_b0_16 { get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -949,12 +949,12 @@ public int o0_b16_4 { get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -966,10 +966,10 @@ public unsafe partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -1510,22 +1510,22 @@ public ref int First }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->A; }} }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->B; }} @@ -1538,10 +1538,10 @@ public unsafe partial struct _Anonymous_e__Struct public int First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/CXXMethodDeclarationTest.cs index 47e77d51..9049cd5d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/CXXMethodDeclarationTest.cs @@ -844,7 +844,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -868,7 +868,7 @@ public void MyVoidMethod() ((delegate* unmanaged[Thiscall])(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this)); }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -896,7 +896,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -922,7 +922,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs index a375ba77..0f287186 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs @@ -1428,7 +1428,8 @@ void MyFunction() } "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1439,11 +1440,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs index ff9ca176..45bfaec5 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs @@ -19,17 +19,39 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[]"")] - public fixed {expectedManagedType} x[1]; + public _x_e__FixedBuffer x; + + public partial struct _x_e__FixedBuffer + {{ + public {expectedManagedType} e0; + + [UnscopedRef] + public ref {expectedManagedType} this[int index] + {{ + get + {{ + return ref Unsafe.Add(ref e0, index); + }} + }} + + [UnscopedRef] + public Span<{expectedManagedType}> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length); + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -55,7 +77,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -80,7 +102,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -109,7 +131,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -318,7 +340,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -538,7 +560,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -568,14 +590,14 @@ public static partial class Methods } } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -591,8 +613,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -606,27 +627,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -642,8 +652,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -657,59 +666,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyStruct[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0_0_0_0; - public MyStruct e1_0_0_0; - - public MyStruct e0_0_1_0; - public MyStruct e1_0_1_0; - - public MyStruct e0_0_2_0; - public MyStruct e1_0_2_0; - - public MyStruct e0_0_0_1; - public MyStruct e1_0_0_1; - - public MyStruct e0_0_1_1; - public MyStruct e1_0_1_1; - - public MyStruct e0_0_2_1; - public MyStruct e1_0_2_1; - - public MyStruct e0_0_0_2; - public MyStruct e1_0_0_2; - - public MyStruct e0_0_1_2; - public MyStruct e1_0_1_2; - - public MyStruct e0_0_2_2; - public MyStruct e1_0_2_2; - - public MyStruct e0_0_0_3; - public MyStruct e1_0_0_3; - - public MyStruct e0_0_1_3; - public MyStruct e1_0_1_3; - - public MyStruct e0_0_2_3; - public MyStruct e1_0_2_3; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -727,8 +693,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -742,27 +707,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -778,8 +732,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -794,27 +747,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -853,7 +795,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -864,17 +806,25 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -885,17 +835,25 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -908,17 +866,25 @@ struct MyStruct }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -968,7 +934,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1022,7 +988,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1077,7 +1043,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1123,6 +1089,8 @@ struct MyStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1134,7 +1102,7 @@ public partial struct MyUnion public {expectedManagedType} value; }} - public unsafe partial struct MyStruct + public partial struct MyStruct {{ public {expectedManagedType} x; @@ -1143,71 +1111,79 @@ public unsafe partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref {expectedManagedType} z {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._w_e__Struct w {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; }} }} + [UnscopedRef] public ref {expectedManagedType} value1 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2_1.value1, 1)); + return ref Anonymous.Anonymous1.value1; }} }} + [UnscopedRef] public ref {expectedManagedType} value {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2_1.Anonymous_2.value, 1)); + return ref Anonymous.Anonymous1.Anonymous.value; }} }} + [UnscopedRef] public ref {expectedManagedType} value2 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous3_1.value2, 1)); + return ref Anonymous.Anonymous2.value2; }} }} + [UnscopedRef] public ref MyUnion u {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer1 {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; }} }} + [UnscopedRef] public Span buffer2 {{ get {{ - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; }} }} - public unsafe partial struct _Anonymous_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} z; @@ -1215,15 +1191,15 @@ public unsafe partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer1[4]; + public _buffer1_e__FixedBuffer buffer1; [NativeTypeName(""MyUnion[4]"")] public _buffer2_e__FixedBuffer buffer2; @@ -1233,49 +1209,43 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public partial struct _Anonymous2_1_e__Struct + public partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; }} + [InlineArray(4)] + public partial struct _buffer1_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} + + [InlineArray(4)] public partial struct _buffer2_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - public MyUnion e3; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1299,7 +1269,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1312,19 +1282,21 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -1332,12 +1304,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1345,12 +1317,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1359,9 +1331,9 @@ public partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -1400,7 +1372,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1445,7 +1417,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1497,7 +1469,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1534,7 +1506,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1548,7 +1520,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() @@ -1607,7 +1579,7 @@ public unsafe partial struct MyStruct1 }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1628,7 +1600,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1652,7 +1624,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1668,7 +1640,7 @@ public partial struct MyStruct "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1685,7 +1657,7 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1700,11 +1672,12 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1720,7 +1693,7 @@ public partial struct _Anonymous_e__Struct ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1748,7 +1721,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1765,7 +1738,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1796,7 +1769,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1827,7 +1800,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1862,7 +1835,7 @@ public void MyMethod() } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1917,7 +1890,7 @@ public partial struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1930,7 +1903,7 @@ struct MyStruct }; "; - const string ExpectedOutputContents = @"using System; + const string ExpectedOutputContents = @"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1941,20 +1914,10 @@ public partial struct MyStruct [NativeTypeName(""size_t[2]"")] public _FixedBuffer_e__FixedBuffer FixedBuffer; + [InlineArray(2)] public partial struct _FixedBuffer_e__FixedBuffer { public nuint e0; - public nuint e1; - - public ref nuint this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); } } } @@ -1963,7 +1926,7 @@ public ref nuint this[int index] var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1993,7 +1956,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -2002,59 +1965,51 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; - var expectedOutputContents = @"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace ClangSharp.Test { public partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; + [UnscopedRef] public ref int First { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous1.First, 1)); + return ref Anonymous.First; } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } + [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; - public _Anonymous2_e__Struct e1; - - public ref _Anonymous2_e__Struct this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span<_Anonymous2_e__Struct> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); + public _MyArray_e__Struct e0; } } } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2067,7 +2022,7 @@ struct { int Value2; }; }; }; } MyStruct;"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -2076,41 +2031,43 @@ public partial struct _MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int Value1 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous1_2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } + [UnscopedRef] public ref int Value2 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous2_2.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } public partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } @@ -2120,6 +2077,6 @@ public partial struct _Anonymous2_2_e__Struct } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs index 7ae3ffc3..19eb4459 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs @@ -39,7 +39,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -70,7 +70,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -105,7 +105,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -327,14 +327,14 @@ readonly get }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -350,7 +350,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -369,27 +369,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -405,7 +394,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -424,59 +413,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyUnion[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0_0_0_0; - public MyUnion e1_0_0_0; - - public MyUnion e0_0_1_0; - public MyUnion e1_0_1_0; - - public MyUnion e0_0_2_0; - public MyUnion e1_0_2_0; - - public MyUnion e0_0_0_1; - public MyUnion e1_0_0_1; - - public MyUnion e0_0_1_1; - public MyUnion e1_0_1_1; - - public MyUnion e0_0_2_1; - public MyUnion e1_0_2_1; - - public MyUnion e0_0_0_2; - public MyUnion e1_0_0_2; - - public MyUnion e0_0_1_2; - public MyUnion e1_0_1_2; - - public MyUnion e0_0_2_2; - public MyUnion e1_0_2_2; - - public MyUnion e0_0_0_3; - public MyUnion e1_0_0_3; - - public MyUnion e0_0_1_3; - public MyUnion e1_0_1_3; - - public MyUnion e0_0_2_3; - public MyUnion e1_0_2_3; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -494,7 +440,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -513,27 +459,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -549,7 +484,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -569,27 +504,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -632,7 +556,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -643,21 +567,28 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -668,21 +599,28 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -695,21 +633,28 @@ union MyUnion }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -762,7 +707,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -789,6 +734,8 @@ union MyUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -799,7 +746,7 @@ public partial struct MyStruct }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] public {expectedManagedType} r; @@ -814,32 +761,35 @@ public unsafe partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref {expectedManagedType} a {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; }} }} + [UnscopedRef] public ref MyStruct s {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; }} }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _Anonymous_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] public {expectedManagedType} a; @@ -849,13 +799,19 @@ public unsafe partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer[4]; + public _buffer_e__FixedBuffer buffer; + + [InlineArray(4)] + public partial struct _buffer_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -879,7 +835,8 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -896,19 +853,21 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -916,12 +875,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -929,12 +888,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -946,10 +905,10 @@ public partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -990,7 +949,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } @@ -1047,7 +1006,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1110,7 +1069,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1157,7 +1116,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1174,7 +1133,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1200,7 +1159,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1229,7 +1188,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1248,7 +1207,7 @@ public partial struct MyUnion "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1265,7 +1224,8 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1285,11 +1245,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1307,7 +1268,7 @@ public partial struct _Anonymous_e__Union ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1341,7 +1302,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1361,7 +1322,7 @@ public partial struct MyUnion } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1398,7 +1359,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1435,7 +1396,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1461,7 +1422,8 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() }}; }} MY_UNION;"; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1477,27 +1439,30 @@ public partial struct _MY_UNION [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref nint First {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + [UnscopedRef] + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.A, 1)); + return ref Anonymous.Anonymous.A; }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + [UnscopedRef] + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.B, 1)); + return ref Anonymous.Anonymous.B; }} }} @@ -1507,10 +1472,10 @@ public partial struct _Anonymous_e__Struct public nint First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] @@ -1534,25 +1499,15 @@ public partial struct _B_e__Struct }} }} + [InlineArray(2)] public partial struct _AsArray_e__FixedBuffer {{ public nint e0; - public nint e1; - - public ref nint this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs index 611048ea..3ec691d8 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs @@ -22,7 +22,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -39,7 +39,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -67,7 +67,7 @@ public static partial class Methods "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -88,7 +88,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -106,14 +106,14 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -127,12 +127,12 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""#define MyMacro1 \""Test\0\\\r\n\t\""\"""")] - public static ReadOnlySpan MyMacro1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyMacro1 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -149,7 +149,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -158,23 +158,25 @@ protected override Task WideStringLiteralConstTestImpl() const wchar_t* MyConst2 = L""Test\0\\\r\n\t\""""; const wchar_t* const MyConst3 = L""Test\0\\\r\n\t\"""";"; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System; + +namespace ClangSharp.Test {{ public static partial class Methods {{ [NativeTypeName(""const wchar_t[11]"")] - public static readonly uint[] MyConst1 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }}; + public static ReadOnlySpan MyConst1 => [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000]; [NativeTypeName(""const wchar_t *"")] - public static uint[] MyConst2 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }}; + public static uint[] MyConst2 = [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000]; [NativeTypeName(""const wchar_t *const"")] - public static readonly uint[] MyConst3 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }}; + public static ReadOnlySpan MyConst3 => [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000]; }} }} "; - return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -190,18 +192,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -242,18 +244,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -274,7 +276,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -291,7 +293,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -310,7 +312,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -327,7 +329,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -344,7 +346,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -373,7 +375,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -393,6 +395,6 @@ public static partial class Methods "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/CXXMethodDeclarationTest.cs index 01f769a5..a668f2c1 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/CXXMethodDeclarationTest.cs @@ -849,7 +849,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -873,7 +873,7 @@ public void MyVoidMethod() ((delegate* unmanaged[Thiscall])(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this)); }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -901,7 +901,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -927,7 +927,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs index ce5e2d6d..410f1f44 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs @@ -1428,7 +1428,8 @@ void MyFunction() } "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1439,11 +1440,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs index 784090e1..3c646741 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs @@ -19,17 +19,39 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[]"")] - public fixed {expectedManagedType} x[1]; + public _x_e__FixedBuffer x; + + public partial struct _x_e__FixedBuffer + {{ + public {expectedManagedType} e0; + + [UnscopedRef] + public ref {expectedManagedType} this[int index] + {{ + get + {{ + return ref Unsafe.Add(ref e0, index); + }} + }} + + [UnscopedRef] + public Span<{expectedManagedType}> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length); + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -55,7 +77,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -80,7 +102,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -109,7 +131,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -322,7 +344,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -546,7 +568,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -576,14 +598,14 @@ public static partial class Methods } } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -599,8 +621,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -614,27 +635,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -650,8 +660,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -665,59 +674,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyStruct[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0_0_0_0; - public MyStruct e1_0_0_0; - - public MyStruct e0_0_1_0; - public MyStruct e1_0_1_0; - - public MyStruct e0_0_2_0; - public MyStruct e1_0_2_0; - - public MyStruct e0_0_0_1; - public MyStruct e1_0_0_1; - - public MyStruct e0_0_1_1; - public MyStruct e1_0_1_1; - - public MyStruct e0_0_2_1; - public MyStruct e1_0_2_1; - - public MyStruct e0_0_0_2; - public MyStruct e1_0_0_2; - - public MyStruct e0_0_1_2; - public MyStruct e1_0_1_2; - - public MyStruct e0_0_2_2; - public MyStruct e1_0_2_2; - - public MyStruct e0_0_0_3; - public MyStruct e1_0_0_3; - - public MyStruct e0_0_1_3; - public MyStruct e1_0_1_3; - - public MyStruct e0_0_2_3; - public MyStruct e1_0_2_3; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -735,8 +701,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -750,27 +715,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -786,8 +740,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -802,27 +755,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -861,7 +803,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -872,17 +814,25 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -893,17 +843,25 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -916,17 +874,25 @@ struct MyStruct }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -976,7 +942,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1030,7 +996,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1085,7 +1051,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1131,6 +1097,8 @@ struct MyStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1142,7 +1110,7 @@ public partial struct MyUnion public {expectedManagedType} value; }} - public unsafe partial struct MyStruct + public partial struct MyStruct {{ public {expectedManagedType} x; @@ -1151,71 +1119,79 @@ public unsafe partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref {expectedManagedType} z {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._w_e__Struct w {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; }} }} + [UnscopedRef] public ref {expectedManagedType} value1 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2_1.value1, 1)); + return ref Anonymous.Anonymous1.value1; }} }} + [UnscopedRef] public ref {expectedManagedType} value {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2_1.Anonymous_2.value, 1)); + return ref Anonymous.Anonymous1.Anonymous.value; }} }} + [UnscopedRef] public ref {expectedManagedType} value2 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous3_1.value2, 1)); + return ref Anonymous.Anonymous2.value2; }} }} + [UnscopedRef] public ref MyUnion u {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer1 {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; }} }} + [UnscopedRef] public Span buffer2 {{ get {{ - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; }} }} - public unsafe partial struct _Anonymous_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} z; @@ -1223,15 +1199,15 @@ public unsafe partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer1[4]; + public _buffer1_e__FixedBuffer buffer1; [NativeTypeName(""MyUnion[4]"")] public _buffer2_e__FixedBuffer buffer2; @@ -1241,49 +1217,43 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public partial struct _Anonymous2_1_e__Struct + public partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; }} + [InlineArray(4)] + public partial struct _buffer1_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} + + [InlineArray(4)] public partial struct _buffer2_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - public MyUnion e3; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1307,7 +1277,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1320,19 +1290,21 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -1340,12 +1312,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1353,12 +1325,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1367,9 +1339,9 @@ public partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -1408,7 +1380,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1453,7 +1425,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1505,7 +1477,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1542,7 +1514,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1556,7 +1528,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() @@ -1615,7 +1587,7 @@ public unsafe partial struct MyStruct1 }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1636,7 +1608,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1660,7 +1632,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1676,7 +1648,7 @@ public partial struct MyStruct "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1693,7 +1665,7 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1708,11 +1680,12 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1728,7 +1701,7 @@ public partial struct _Anonymous_e__Struct ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1756,7 +1729,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1773,7 +1746,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1804,7 +1777,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1835,7 +1808,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1870,7 +1843,7 @@ public void MyMethod() } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1925,7 +1898,7 @@ public partial struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1936,7 +1909,7 @@ protected override Task WithPackingTestImpl() }; "; - const string ExpectedOutputContents = @"using System; + const string ExpectedOutputContents = @"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1947,20 +1920,10 @@ public partial struct MyStruct [NativeTypeName(""size_t[2]"")] public _FixedBuffer_e__FixedBuffer FixedBuffer; + [InlineArray(2)] public partial struct _FixedBuffer_e__FixedBuffer { public nuint e0; - public nuint e1; - - public ref nuint this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); } } } @@ -1969,7 +1932,7 @@ public ref nuint this[int index] var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1999,7 +1962,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -2008,59 +1971,51 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; - var expectedOutputContents = @"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace ClangSharp.Test { public partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; + [UnscopedRef] public ref int First { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous1.First, 1)); + return ref Anonymous.First; } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } + [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; - public _Anonymous2_e__Struct e1; - - public ref _Anonymous2_e__Struct this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span<_Anonymous2_e__Struct> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); + public _MyArray_e__Struct e0; } } } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2073,7 +2028,7 @@ struct { int Value2; }; }; }; } MyStruct;"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -2082,41 +2037,43 @@ public partial struct _MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int Value1 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous1_2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } + [UnscopedRef] public ref int Value2 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous2_2.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } public partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } @@ -2126,6 +2083,6 @@ public partial struct _Anonymous2_2_e__Struct } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs index 443169e0..76398156 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs @@ -39,7 +39,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -70,7 +70,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -105,7 +105,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -333,14 +333,14 @@ readonly get }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -356,7 +356,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -375,27 +375,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -411,7 +400,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -430,59 +419,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyUnion[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0_0_0_0; - public MyUnion e1_0_0_0; - - public MyUnion e0_0_1_0; - public MyUnion e1_0_1_0; - - public MyUnion e0_0_2_0; - public MyUnion e1_0_2_0; - - public MyUnion e0_0_0_1; - public MyUnion e1_0_0_1; - - public MyUnion e0_0_1_1; - public MyUnion e1_0_1_1; - - public MyUnion e0_0_2_1; - public MyUnion e1_0_2_1; - - public MyUnion e0_0_0_2; - public MyUnion e1_0_0_2; - - public MyUnion e0_0_1_2; - public MyUnion e1_0_1_2; - - public MyUnion e0_0_2_2; - public MyUnion e1_0_2_2; - - public MyUnion e0_0_0_3; - public MyUnion e1_0_0_3; - - public MyUnion e0_0_1_3; - public MyUnion e1_0_1_3; - - public MyUnion e0_0_2_3; - public MyUnion e1_0_2_3; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -500,7 +446,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -519,27 +465,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -555,7 +490,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -575,27 +510,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -638,7 +562,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -649,21 +573,28 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -674,21 +605,28 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -701,21 +639,28 @@ union MyUnion }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -768,7 +713,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -795,6 +740,8 @@ union MyUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -805,7 +752,7 @@ public partial struct MyStruct }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] public {expectedManagedType} r; @@ -820,32 +767,35 @@ public unsafe partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref {expectedManagedType} a {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; }} }} + [UnscopedRef] public ref MyStruct s {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; }} }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _Anonymous_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] public {expectedManagedType} a; @@ -855,13 +805,19 @@ public unsafe partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer[4]; + public _buffer_e__FixedBuffer buffer; + + [InlineArray(4)] + public partial struct _buffer_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -885,7 +841,8 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -902,19 +859,21 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -922,12 +881,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -935,12 +894,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -952,10 +911,10 @@ public partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -996,7 +955,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } @@ -1053,7 +1012,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1116,7 +1075,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1163,7 +1122,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1180,7 +1139,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1206,7 +1165,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1235,7 +1194,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1254,7 +1213,7 @@ public partial struct MyUnion "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1271,7 +1230,8 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1291,11 +1251,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1313,7 +1274,7 @@ public partial struct _Anonymous_e__Union ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1347,7 +1308,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1367,7 +1328,7 @@ public partial struct MyUnion } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1404,7 +1365,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1441,7 +1402,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1467,42 +1428,47 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() }}; }} MY_UNION;"; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _MY_UNION + public partial struct _MY_UNION {{ [FieldOffset(0)] [NativeTypeName(""long[2]"")] - public fixed int AsArray[2]; + public _AsArray_e__FixedBuffer AsArray; [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int First {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + [UnscopedRef] + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.A, 1)); + return ref Anonymous.Anonymous.A; }} }} - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + [UnscopedRef] + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.B, 1)); + return ref Anonymous.Anonymous.B; }} }} @@ -1512,10 +1478,10 @@ public partial struct _Anonymous_e__Struct public int First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] @@ -1538,10 +1504,16 @@ public partial struct _B_e__Struct }} }} }} + + [InlineArray(2)] + public partial struct _AsArray_e__FixedBuffer + {{ + public int e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs index bc82da08..63d7d276 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs @@ -22,7 +22,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -39,7 +39,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -67,7 +67,7 @@ public static partial class Methods "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -88,7 +88,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -106,14 +106,14 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -127,12 +127,12 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""#define MyMacro1 \""Test\0\\\r\n\t\""\"""")] - public static ReadOnlySpan MyMacro1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyMacro1 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -149,7 +149,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -174,7 +174,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -190,18 +190,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -226,7 +226,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralStaticConstTestImpl() @@ -242,18 +242,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -274,7 +274,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -291,7 +291,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -310,7 +310,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -327,7 +327,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -344,7 +344,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -373,7 +373,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -393,6 +393,6 @@ public static partial class Methods "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs index 9ac0558a..6d422c23 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs @@ -844,7 +844,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -868,7 +868,7 @@ public void MyVoidMethod() ((delegate* unmanaged[Thiscall])(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this)); }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -896,7 +896,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -922,7 +922,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs index caccbc5e..936165db 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1133,7 +1134,7 @@ public ref {expectedManagedType} value1 {{ get {{ - return ref Anonymous.Anonymous2_1.value1; + return ref Anonymous.Anonymous1.value1; }} }} @@ -1142,7 +1143,7 @@ public ref {expectedManagedType} value {{ get {{ - return ref Anonymous.Anonymous2_1.Anonymous_2.value; + return ref Anonymous.Anonymous1.Anonymous.value; }} }} @@ -1151,7 +1152,7 @@ public ref {expectedManagedType} value2 {{ get {{ - return ref Anonymous.Anonymous3_1.value2; + return ref Anonymous.Anonymous2.value2; }} }} @@ -1190,10 +1191,10 @@ public partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; @@ -1208,21 +1209,21 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public partial struct _Anonymous2_1_e__Struct + public partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; @@ -1295,7 +1296,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -1303,12 +1304,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1316,12 +1317,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1330,9 +1331,9 @@ public partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -1975,7 +1976,7 @@ namespace ClangSharp.Test public partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; @@ -1985,16 +1986,16 @@ public ref int First { get { - return ref Anonymous1.First; + return ref Anonymous.First; } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } @@ -2002,7 +2003,7 @@ public partial struct _Anonymous2_e__Struct [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; + public _MyArray_e__Struct e0; } } } @@ -2035,7 +2036,7 @@ public ref int Value1 { get { - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } @@ -2044,29 +2045,29 @@ public ref int Value2 { get { - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } public partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs index 849143f5..64f424df 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs @@ -867,7 +867,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -875,12 +875,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -888,12 +888,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -905,10 +905,10 @@ public partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -1449,20 +1449,20 @@ public ref nint First }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; }} }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; }} }} @@ -1472,10 +1472,10 @@ public partial struct _Anonymous_e__Struct public nint First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs index e37b13e8..731613c9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs @@ -844,7 +844,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -868,7 +868,7 @@ public void MyVoidMethod() ((delegate* unmanaged[Thiscall])(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this)); }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -896,7 +896,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -922,7 +922,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs index 5ce7bebe..9661e535 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1141,7 +1142,7 @@ public ref {expectedManagedType} value1 {{ get {{ - return ref Anonymous.Anonymous2_1.value1; + return ref Anonymous.Anonymous1.value1; }} }} @@ -1150,7 +1151,7 @@ public ref {expectedManagedType} value {{ get {{ - return ref Anonymous.Anonymous2_1.Anonymous_2.value; + return ref Anonymous.Anonymous1.Anonymous.value; }} }} @@ -1159,7 +1160,7 @@ public ref {expectedManagedType} value2 {{ get {{ - return ref Anonymous.Anonymous3_1.value2; + return ref Anonymous.Anonymous2.value2; }} }} @@ -1198,10 +1199,10 @@ public partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; @@ -1216,21 +1217,21 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public partial struct _Anonymous2_1_e__Struct + public partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; @@ -1303,7 +1304,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -1311,12 +1312,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1324,12 +1325,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1338,9 +1339,9 @@ public partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -1981,7 +1982,7 @@ namespace ClangSharp.Test public partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; @@ -1991,16 +1992,16 @@ public ref int First { get { - return ref Anonymous1.First; + return ref Anonymous.First; } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } @@ -2008,7 +2009,7 @@ public partial struct _Anonymous2_e__Struct [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; + public _MyArray_e__Struct e0; } } } @@ -2041,7 +2042,7 @@ public ref int Value1 { get { - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } @@ -2050,29 +2051,29 @@ public ref int Value2 { get { - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } public partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs index 84003513..72bbf228 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs @@ -873,7 +873,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -881,12 +881,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -894,12 +894,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -911,10 +911,10 @@ public partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -1455,20 +1455,20 @@ public ref int First }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; }} }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; }} }} @@ -1478,10 +1478,10 @@ public partial struct _Anonymous_e__Struct public int First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/CXXMethodDeclarationTest.cs index e9f3cb58..d0e056f3 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/CXXMethodDeclarationTest.cs @@ -844,7 +844,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -868,7 +868,7 @@ public void MyVoidMethod() ((delegate* unmanaged[Thiscall])(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this)); }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -896,7 +896,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -922,7 +922,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs index 854c5546..4e438509 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1133,7 +1134,7 @@ public ref {expectedManagedType} value1 {{ get {{ - return ref Anonymous.Anonymous2_1.value1; + return ref Anonymous.Anonymous1.value1; }} }} @@ -1142,7 +1143,7 @@ public ref {expectedManagedType} value {{ get {{ - return ref Anonymous.Anonymous2_1.Anonymous_2.value; + return ref Anonymous.Anonymous1.Anonymous.value; }} }} @@ -1151,7 +1152,7 @@ public ref {expectedManagedType} value2 {{ get {{ - return ref Anonymous.Anonymous3_1.value2; + return ref Anonymous.Anonymous2.value2; }} }} @@ -1190,10 +1191,10 @@ public partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; @@ -1208,21 +1209,21 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public partial struct _Anonymous2_1_e__Struct + public partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; @@ -1295,7 +1296,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -1303,12 +1304,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1316,12 +1317,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1330,9 +1331,9 @@ public partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -1974,7 +1975,7 @@ namespace ClangSharp.Test public partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; @@ -1984,16 +1985,16 @@ public ref int First { get { - return ref Anonymous1.First; + return ref Anonymous.First; } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } @@ -2001,7 +2002,7 @@ public partial struct _Anonymous2_e__Struct [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; + public _MyArray_e__Struct e0; } } } @@ -2034,7 +2035,7 @@ public ref int Value1 { get { - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } @@ -2043,29 +2044,29 @@ public ref int Value2 { get { - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } public partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs index f5434e8e..4d0ae17f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs @@ -867,7 +867,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -875,12 +875,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -888,12 +888,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -905,10 +905,10 @@ public partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -1449,20 +1449,20 @@ public ref nint First }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; }} }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; }} }} @@ -1472,10 +1472,10 @@ public partial struct _Anonymous_e__Struct public nint First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/CXXMethodDeclarationTest.cs index 28f1de68..a49a18d3 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/CXXMethodDeclarationTest.cs @@ -844,7 +844,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -868,7 +868,7 @@ public void MyVoidMethod() ((delegate* unmanaged[Thiscall])(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this)); }} - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -896,7 +896,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -922,7 +922,7 @@ public void MyVoidMethod() }} [VtblIndex(1)] - [return: NativeTypeName(""char"")] + [return: NativeTypeName(""signed char"")] public sbyte MyInt8Method() {{ return ((delegate* unmanaged[Thiscall])(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs index 5bf9a1e2..d3e05c78 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1141,7 +1142,7 @@ public ref {expectedManagedType} value1 {{ get {{ - return ref Anonymous.Anonymous2_1.value1; + return ref Anonymous.Anonymous1.value1; }} }} @@ -1150,7 +1151,7 @@ public ref {expectedManagedType} value {{ get {{ - return ref Anonymous.Anonymous2_1.Anonymous_2.value; + return ref Anonymous.Anonymous1.Anonymous.value; }} }} @@ -1159,7 +1160,7 @@ public ref {expectedManagedType} value2 {{ get {{ - return ref Anonymous.Anonymous3_1.value2; + return ref Anonymous.Anonymous2.value2; }} }} @@ -1198,10 +1199,10 @@ public partial struct _Anonymous_e__Struct public _w_e__Struct w; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L19_C9"")] - public _Anonymous2_1_e__Struct Anonymous2_1; + public _Anonymous1_e__Struct Anonymous1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L29_C9"")] - public _Anonymous3_1_e__Union Anonymous3_1; + public _Anonymous2_e__Union Anonymous2; public MyUnion u; @@ -1216,21 +1217,21 @@ public partial struct _w_e__Struct public {expectedManagedType} value; }} - public partial struct _Anonymous2_1_e__Struct + public partial struct _Anonymous1_e__Struct {{ public {expectedManagedType} value1; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L23_C13"")] - public _Anonymous_2_e__Struct Anonymous_2; + public _Anonymous_e__Struct Anonymous; - public partial struct _Anonymous_2_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} value; }} }} [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous3_1_e__Union + public partial struct _Anonymous2_e__Union {{ [FieldOffset(0)] public {expectedManagedType} value2; @@ -1303,7 +1304,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -1311,12 +1312,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -1324,12 +1325,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -1338,9 +1339,9 @@ public partial struct _Anonymous_e__Struct public int z; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { public int w; @@ -1980,7 +1981,7 @@ namespace ClangSharp.Test public partial struct _MyStruct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] - public _Anonymous1_e__Struct Anonymous1; + public _Anonymous_e__Struct Anonymous; [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; @@ -1990,16 +1991,16 @@ public ref int First { get { - return ref Anonymous1.First; + return ref Anonymous.First; } } - public partial struct _Anonymous1_e__Struct + public partial struct _Anonymous_e__Struct { public int First; } - public partial struct _Anonymous2_e__Struct + public partial struct _MyArray_e__Struct { public int Second; } @@ -2007,7 +2008,7 @@ public partial struct _Anonymous2_e__Struct [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { - public _Anonymous2_e__Struct e0; + public _MyArray_e__Struct e0; } } } @@ -2040,7 +2041,7 @@ public ref int Value1 { get { - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } @@ -2049,29 +2050,29 @@ public ref int Value2 { get { - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } public partial struct _Anonymous_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C14"")] - public _Anonymous_1_e__Struct Anonymous_1; + public _Anonymous1_e__Struct Anonymous1; - public partial struct _Anonymous_1_e__Struct + public partial struct _Anonymous1_e__Struct { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C9"")] - public _Anonymous1_2_e__Struct Anonymous1_2; + public _Anonymous2_e__Struct Anonymous2; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L5_C9"")] - public _Anonymous2_2_e__Struct Anonymous2_2; + public _Anonymous3_e__Struct Anonymous3; - public partial struct _Anonymous1_2_e__Struct + public partial struct _Anonymous2_e__Struct { public int Value1; } - public partial struct _Anonymous2_2_e__Struct + public partial struct _Anonymous3_e__Struct { public int Value2; } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs index 195a8d91..1cca78ca 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs @@ -873,7 +873,7 @@ public ref int w { get { - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; } } @@ -881,12 +881,12 @@ public int o0_b0_16 { readonly get { - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; } set { - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; } } @@ -894,12 +894,12 @@ public int o0_b16_4 { readonly get { - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; } set { - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; } } @@ -911,10 +911,10 @@ public partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L10_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous1_e__Union Anonymous1; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous1_e__Union { [FieldOffset(0)] public int w; @@ -1455,20 +1455,20 @@ public ref int First }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct A + public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; }} }} [UnscopedRef] - public ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct B + public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; }} }} @@ -1478,10 +1478,10 @@ public partial struct _Anonymous_e__Struct public int First; [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C9"")] - public _Anonymous_1_e__Union Anonymous_1; + public _Anonymous_e__Union Anonymous; [StructLayout(LayoutKind.Explicit)] - public partial struct _Anonymous_1_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L9_C13"")] diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs index ff794b8b..22d264a7 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs @@ -1,5 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading.Tasks; using NUnit.Framework; @@ -197,7 +198,7 @@ public partial struct __anonymousStructField1_e__Struct } } - public unsafe partial struct _MyStructWithAnonymousUnion + public partial struct _MyStructWithAnonymousUnion { [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L21_C5"")] public _union1_e__Union union1; @@ -279,4 +280,726 @@ public static partial class Methods return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); } + + [Test] + public Task UnsignedIntBitshiftTest() + { + var inputContents = @" +const int Signed = 1; +const long SignedLong = 1; +const unsigned int Unsigned = 1; + +const int ShiftSigned = 1 << Signed; +const int ShiftSignedLong = 1 << SignedLong; +const int ShiftUnsigned = 1 << Unsigned; + +const int Char = 1 << 'a'; + +const int Byte = 1 << (signed char)1; +const int UByte = 1 << (unsigned char)1; + +const int CInt = 1 << 1; +const int CUint = 1 << 1U; + +const int Negative = 1 << -1; + +const int OutOfRangePos = 1 << 10000000000; +const int OutOfRangeNeg = 1 << -10000000000; + +const int IntMax = 1 << 2147483647; +const int IntMin = 1 << -2147483648; + +const int LongMax = 1 << 9223372036854775807; +const int LongMin = 1 << -9223372036854775808; + +const int ULongMax = 1 << 18446744073709551615; + +const int Hexadecimal = 1 << 0x01; + +#define Left 1 << 1U +#define Right 1 >> 1U + +#define Int 1 << 1 +#define Long 1 << 1L +#define LongLong 1 << 1LL +#define ULong 1 << 1UL +#define ULongLong 1 << 1ULL + +#define Complex ((((unsigned int)(0)) << 29U) | (((unsigned int)(1)) << 22U) | (((unsigned int)(0)) << 12U) | ((unsigned int)(0))) +"; + + // Non-ideal cases: + // UByte + // IntMin + // ULongMax + // Hexadecimal + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + [NativeTypeName(""const int"")] + public const int Signed = 1; + + [NativeTypeName(""const long"")] + public const int SignedLong = 1; + + [NativeTypeName(""const unsigned int"")] + public const uint Unsigned = 1; + + [NativeTypeName(""const int"")] + public const int ShiftSigned = 1 << Signed; + + [NativeTypeName(""const int"")] + public const int ShiftSignedLong = 1 << SignedLong; + + [NativeTypeName(""const int"")] + public const int ShiftUnsigned = 1 << (int)(Unsigned); + + [NativeTypeName(""const int"")] + public const int Char = 1 << (sbyte)('a'); + + [NativeTypeName(""const int"")] + public const int Byte = 1 << (sbyte)(1); + + [NativeTypeName(""const int"")] + public const int UByte = unchecked(1 << (byte)(1)); + + [NativeTypeName(""const int"")] + public const int CInt = 1 << 1; + + [NativeTypeName(""const int"")] + public const int CUint = 1 << 1; + + [NativeTypeName(""const int"")] + public const int Negative = 1 << -1; + + [NativeTypeName(""const int"")] + public const int OutOfRangePos = unchecked(1 << (int)(10000000000)); + + [NativeTypeName(""const int"")] + public const int OutOfRangeNeg = unchecked(1 << (int)(-10000000000)); + + [NativeTypeName(""const int"")] + public const int IntMax = 1 << 2147483647; + + [NativeTypeName(""const int"")] + public const int IntMin = unchecked(1 << -2147483648); + + [NativeTypeName(""const int"")] + public const int LongMax = unchecked(1 << (int)(9223372036854775807)); + + [NativeTypeName(""const int"")] + public const int LongMin = unchecked(1 << (int)(-9223372036854775808)); + + [NativeTypeName(""const int"")] + public const int ULongMax = 1 << -1; + + [NativeTypeName(""const int"")] + public const int Hexadecimal = 1 << 1; + + [NativeTypeName(""#define Left 1 << 1U"")] + public const int Left = 1 << 1; + + [NativeTypeName(""#define Right 1 >> 1U"")] + public const int Right = 1 >> 1; + + [NativeTypeName(""#define Int 1 << 1"")] + public const int Int = 1 << 1; + + [NativeTypeName(""#define Long 1 << 1L"")] + public const int Long = 1 << 1; + + [NativeTypeName(""#define LongLong 1 << 1LL"")] + public const int LongLong = 1 << 1; + + [NativeTypeName(""#define ULong 1 << 1UL"")] + public const int ULong = 1 << 1; + + [NativeTypeName(""#define ULongLong 1 << 1ULL"")] + public const int ULongLong = 1 << 1; + + [NativeTypeName(""#define Complex ((((unsigned int)(0)) << 29U) | (((unsigned int)(1)) << 22U) | (((unsigned int)(0)) << 12U) | ((unsigned int)(0)))"")] + public const uint Complex = ((((uint)(0)) << 29) | (((uint)(1)) << 22) | (((uint)(0)) << 12) | ((uint)(0))); + } +} +"; + + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + + [Test] + public Task UnsignedIntBitshiftTestUnix() + { + var inputContents = @" +const long SignedLong = 1; +const int ShiftSignedLong = 1 << SignedLong; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + [NativeTypeName(""const long"")] + public const nint SignedLong = 1; + + [NativeTypeName(""const int"")] + public const int ShiftSignedLong = 1 << (int)(SignedLong); + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("unix")] + public Task BitfieldEnumPropertySmallBackingTypeTestUnix() + { + // This test is here mainly to ensure that the sbyte case gets coverage + if (RuntimeInformation.ProcessArchitecture != Architecture.X64) + { + Assert.Ignore("This test is only valid for Unix x64"); + } + + var inputContents = @" +typedef struct Bitfield { + unsigned char bits1 : 8; + char bits2 : 8; + unsigned char bits3 : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public partial struct Bitfield + { + public byte _bitfield1; + + [NativeTypeName(""unsigned char : 8"")] + public byte bits1 + { + readonly get + { + return (byte)(_bitfield1 & 0xFFu); + } + + set + { + _bitfield1 = (byte)((_bitfield1 & ~0xFFu) | (value & 0xFFu)); + } + } + + public sbyte _bitfield2; + + [NativeTypeName(""char : 8"")] + public sbyte bits2 + { + readonly get + { + return (sbyte)((_bitfield2 << 0) >> 0); + } + + set + { + _bitfield2 = (sbyte)((_bitfield2 & ~0xFF) | (value & 0xFF)); + } + } + + public byte _bitfield3; + + [NativeTypeName(""unsigned char : 8"")] + public byte bits3 + { + readonly get + { + return (byte)(_bitfield3 & 0xFFu); + } + + set + { + _bitfield3 = (byte)((_bitfield3 & ~0xFFu) | (value & 0xFFu)); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("unix")] + public Task BitfieldEnumPropertyBackingTypeTestUnix() + { + // This test is here mainly to ensure that the sbyte case gets coverage + if (RuntimeInformation.ProcessArchitecture != Architecture.X64) + { + Assert.Ignore("This test is only valid for Unix x64"); + } + + var inputContents = @" +typedef struct IntBitfield { + int bits : 8; + unsigned int bits2 : 8; +} IntBitfield; + +typedef struct UIntBitfield { + unsigned int bits1 : 8; + int bits2 : 8; + unsigned char bits3 : 8; + char bits4 : 8; +} UIntBitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public partial struct IntBitfield + { + public int _bitfield; + + [NativeTypeName(""int : 8"")] + public int bits + { + readonly get + { + return (_bitfield << 24) >> 24; + } + + set + { + _bitfield = (_bitfield & ~0xFF) | (value & 0xFF); + } + } + + [NativeTypeName(""unsigned int : 8"")] + public uint bits2 + { + readonly get + { + return (uint)((_bitfield >> 8) & 0xFF); + } + + set + { + _bitfield = (_bitfield & ~(0xFF << 8)) | (int)((value & 0xFFu) << 8); + } + } + } + + public partial struct UIntBitfield + { + public uint _bitfield; + + [NativeTypeName(""unsigned int : 8"")] + public uint bits1 + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + + [NativeTypeName(""int : 8"")] + public int bits2 + { + readonly get + { + return (int)(_bitfield << 16) >> 24; + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 8)) | (uint)((value & 0xFF) << 8); + } + } + + [NativeTypeName(""unsigned char : 8"")] + public byte bits3 + { + readonly get + { + return (byte)((_bitfield >> 16) & 0xFFu); + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 16)) | (uint)((value & 0xFFu) << 16); + } + } + + [NativeTypeName(""char : 8"")] + public sbyte bits4 + { + readonly get + { + return (sbyte)((sbyte)(_bitfield << 0) >> 24); + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 24)) | (uint)((value & 0xFF) << 24); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("unix")] + public Task BitfieldEnumPropertyTypeCastTestUnix() + { + var inputContents = @" +typedef enum Flags { + Member = 0x7FFFFFFF +} Flags; + +typedef struct Bitfield { + unsigned int bits : 8; + Flags flags : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + [NativeTypeName(""unsigned int"")] + public enum Flags : uint + { + Member = 0x7FFFFFFF, + } + + public partial struct Bitfield + { + public uint _bitfield; + + [NativeTypeName(""unsigned int : 8"")] + public uint bits + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + + [NativeTypeName(""Flags : 8"")] + public Flags flags + { + readonly get + { + return (Flags)((_bitfield >> 8) & 0xFFu); + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 8)) | (((uint)(value) & 0xFFu) << 8); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("unix")] + public Task BitfieldTypeDefTypeCastTestUnix() + { + var inputContents = @" +typedef unsigned int Number; + +typedef struct Bitfield { + Number bits : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public partial struct Bitfield + { + public uint _bitfield; + + [NativeTypeName(""Number : 8"")] + public uint bits + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("win")] // This test has slight platform-specific differences + public Task BitfieldEnumPropertyTypeCastTestWindows() + { + var inputContents = @" +typedef enum Flags { + Member = 0x7FFFFFFF +} Flags; + +typedef struct Bitfield { + unsigned int bits : 8; + Flags flags : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public enum Flags + { + Member = 0x7FFFFFFF, + } + + public partial struct Bitfield + { + public uint _bitfield; + + [NativeTypeName(""unsigned int : 8"")] + public uint bits + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + + [NativeTypeName(""Flags : 8"")] + public Flags flags + { + readonly get + { + return (Flags)((_bitfield << 16) >> 24); + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 8)) | (((uint)(value) & 0xFF) << 8); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("unix")] // This test has slight platform-specific differences + public Task BitfieldEnumTypeDefPropertyTypeCast() + { + var inputContents = @" +typedef enum FlagBits { + Member = 0x7FFFFFFF +} FlagBits; +typedef unsigned int Flags; + +typedef struct Bitfield { + unsigned int bits : 8; + Flags flags : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + [NativeTypeName(""unsigned int"")] + public enum FlagBits : uint + { + Member = 0x7FFFFFFF, + } + + public partial struct Bitfield + { + public uint _bitfield; + + [NativeTypeName(""unsigned int : 8"")] + public uint bits + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + + [NativeTypeName(""Flags : 8"")] + public uint flags + { + readonly get + { + return (_bitfield >> 8) & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 8)) | ((value & 0xFFu) << 8); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard); + } + + [Test] + [Platform("unix")] // This test has slight platform-specific differences + public Task BitfieldEnumTypeDefPropertyTypeCastWithRemappingTest() + { + var inputContents = @" +typedef enum FlagBits { + Member = 0x7FFFFFFF +} FlagBits; +typedef unsigned int Flags; + +typedef struct Bitfield { + unsigned int bits : 8; + Flags flags : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + [NativeTypeName(""unsigned int"")] + public enum FlagBits : uint + { + Member = 0x7FFFFFFF, + } + + public partial struct Bitfield + { + public uint _bitfield; + + [NativeTypeName(""unsigned int : 8"")] + public uint bits + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + + [NativeTypeName(""Flags : 8"")] + public FlagBits flags + { + readonly get + { + return (FlagBits)((_bitfield >> 8) & 0xFFu); + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 8)) | (((uint)(value) & 0xFFu) << 8); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, + commandLineArgs: DefaultCClangCommandLineArgs, + language: "c", + languageStandard: DefaultCStandard, + remappedNames: new Dictionary() + { + { "Flags", "FlagBits" } + }); + } + + [Test] + [Platform("unix")] // This test has slight platform-specific differences + public Task BitfieldEnumTypeDefPropertyTypeCastWithSelfRemappingTest() + { + var inputContents = @" +typedef unsigned int Flags; + +typedef struct Bitfield { + unsigned int bits : 8; + Flags flags : 8; +} Bitfield; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public partial struct Bitfield + { + public uint _bitfield; + + [NativeTypeName(""unsigned int : 8"")] + public uint bits + { + readonly get + { + return _bitfield & 0xFFu; + } + + set + { + _bitfield = (_bitfield & ~0xFFu) | (value & 0xFFu); + } + } + + [NativeTypeName(""Flags : 8"")] + public Flags flags + { + readonly get + { + return (Flags)((_bitfield >> 8) & 0xFFu); + } + + set + { + _bitfield = (_bitfield & ~(0xFFu << 8)) | (((uint)(value) & 0xFFu) << 8); + } + } + } +} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, + commandLineArgs: DefaultCClangCommandLineArgs, + language: "c", + languageStandard: DefaultCStandard, + remappedNames: new Dictionary() + { + { "Flags", "Flags" } + }); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/ClangSharp.PInvokeGenerator.UnitTests.csproj b/tests/ClangSharp.PInvokeGenerator.UnitTests/ClangSharp.PInvokeGenerator.UnitTests.csproj index cfdb757b..1b0f3bb7 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/ClangSharp.PInvokeGenerator.UnitTests.csproj +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/ClangSharp.PInvokeGenerator.UnitTests.csproj @@ -3,13 +3,15 @@ ClangSharp.UnitTests - net8.0 + net10.0 + - $(NoWarn);CA1707;CA1711 + + $(NoWarn);CA1515;CA1707;CA1711;IDE0130 diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs index 0403f89d..7485d37c 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs @@ -1099,7 +1099,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1124,7 +1124,7 @@ virtual char MyInt8Method() - sbyte + sbyte MyStruct* @@ -1151,7 +1151,7 @@ virtual char MyInt8Method() - sbyte + sbyte fixed (MyStruct* pThis = &this) {{ @@ -1191,7 +1191,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1216,7 +1216,7 @@ virtual char MyInt8Method() - sbyte + sbyte MyStruct* @@ -1243,7 +1243,7 @@ virtual char MyInt8Method() - sbyte + sbyte fixed (MyStruct* pThis = &this) {{ diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/StructDeclarationTest.cs index 54f56e1d..daca2be6 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/StructDeclarationTest.cs @@ -1280,7 +1280,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -1289,29 +1289,29 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1996,45 +1996,45 @@ struct { int Second; } MyArray[2]; - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - fixed (_Anonymous1_e__Struct* pField = &Anonymous1) + fixed (_Anonymous_e__Struct* pField = &Anonymous) { return ref pField->First; } - + int - + int - _Anonymous2_e__Struct + _MyArray_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct - ref _Anonymous2_e__Struct + ref _MyArray_e__Struct int - fixed (_Anonymous2_e__Struct* pThis = &e0) + fixed (_MyArray_e__Struct* pThis = &e0) { return ref pThis[index]; } @@ -2069,7 +2069,7 @@ struct { int Value2; }; ref int - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous1_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous1_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous2_e__Struct* pField = &Anonymous.Anonymous1.Anonymous2) { return ref pField->Value1; } @@ -2078,29 +2078,29 @@ struct { int Value2; }; ref int - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous2_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous2_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous3_e__Struct* pField = &Anonymous.Anonymous1.Anonymous3) { return ref pField->Value2; } - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/UnionDeclarationTest.cs index 4015963e..31e57bb9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/UnionDeclarationTest.cs @@ -868,7 +868,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - fixed (_Anonymous_e__Union._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Union._Anonymous1_e__Union* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -877,29 +877,29 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -1386,18 +1386,18 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->A; }} - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->B; }} @@ -1407,10 +1407,10 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() IntPtr - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs index 20c1ee5c..bcdda1f4 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs @@ -1100,7 +1100,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1125,7 +1125,7 @@ virtual char MyInt8Method() - sbyte + sbyte MyStruct* @@ -1152,7 +1152,7 @@ virtual char MyInt8Method() - sbyte + sbyte fixed (MyStruct* pThis = &this) {{ @@ -1192,7 +1192,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1217,7 +1217,7 @@ virtual char MyInt8Method() - sbyte + sbyte MyStruct* @@ -1244,7 +1244,7 @@ virtual char MyInt8Method() - sbyte + sbyte fixed (MyStruct* pThis = &this) {{ diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/StructDeclarationTest.cs index 3b6cf393..c443c420 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/StructDeclarationTest.cs @@ -1292,7 +1292,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -1301,29 +1301,29 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -2005,45 +2005,45 @@ struct { int Second; } MyArray[2]; - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - fixed (_Anonymous1_e__Struct* pField = &Anonymous1) + fixed (_Anonymous_e__Struct* pField = &Anonymous) { return ref pField->First; } - + int - + int - _Anonymous2_e__Struct + _MyArray_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct - ref _Anonymous2_e__Struct + ref _MyArray_e__Struct int - fixed (_Anonymous2_e__Struct* pThis = &e0) + fixed (_MyArray_e__Struct* pThis = &e0) { return ref pThis[index]; } @@ -2078,7 +2078,7 @@ struct { int Value2; }; ref int - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous1_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous1_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous2_e__Struct* pField = &Anonymous.Anonymous1.Anonymous2) { return ref pField->Value1; } @@ -2087,29 +2087,29 @@ struct { int Value2; }; ref int - fixed (_Anonymous_e__Struct._Anonymous_1_e__Struct._Anonymous2_2_e__Struct* pField = &Anonymous.Anonymous_1.Anonymous2_2) + fixed (_Anonymous_e__Struct._Anonymous1_e__Struct._Anonymous3_e__Struct* pField = &Anonymous.Anonymous1.Anonymous3) { return ref pField->Value2; } - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/UnionDeclarationTest.cs index 88a911bd..13f0d054 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/UnionDeclarationTest.cs @@ -874,7 +874,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - fixed (_Anonymous_e__Union._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Union._Anonymous1_e__Union* pField = &Anonymous.Anonymous1) { return ref pField->w; } @@ -883,29 +883,29 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -1392,18 +1392,18 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->A; }} - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - fixed (_Anonymous_e__Struct._Anonymous_1_e__Union* pField = &Anonymous.Anonymous_1) + fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {{ return ref pField->B; }} @@ -1413,10 +1413,10 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() int - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/CXXMethodDeclarationTest.cs index a27fcb0a..5a4859f9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/CXXMethodDeclarationTest.cs @@ -992,7 +992,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1017,7 +1017,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -1048,7 +1048,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1073,7 +1073,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs index f54f80ff..d4d7654f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs @@ -1618,7 +1618,7 @@ void MyFunction() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs index c9022cdb..a137a9f1 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs @@ -22,16 +22,37 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@" - + {expectedManagedType} + + + {expectedManagedType} + + + ref {expectedManagedType} + + int + + + return ref Unsafe.Add(ref e0, index); + + + + Span<{expectedManagedType}> + + int + + MemoryMarshal.CreateSpan(ref e0, length); + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -62,7 +83,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -92,7 +113,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -123,7 +144,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -294,7 +315,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -476,7 +497,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -505,14 +526,14 @@ typedef struct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -541,35 +562,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -598,98 +601,17 @@ struct MyOtherStruct MyStruct + InlineArray(2 * 1 * 3 * 4) MyStruct - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -720,35 +642,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -777,35 +681,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -851,7 +737,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -865,16 +751,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -888,16 +780,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -913,16 +811,22 @@ struct MyStruct var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -967,7 +871,7 @@ struct DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyStruct2 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1028,7 +932,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1089,7 +993,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1127,7 +1031,7 @@ struct MyStruct {expectedManagedType} - + {expectedManagedType} @@ -1140,34 +1044,34 @@ struct MyStruct ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref _Anonymous_e__Struct._w_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; ref MyUnion - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; Span<MyUnion> - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; - + {expectedManagedType} @@ -1188,32 +1092,17 @@ struct MyStruct {expectedManagedType} - + + InlineArray(4) - MyUnion - - - MyUnion - - - MyUnion + {expectedManagedType} - + + + InlineArray(4) + MyUnion - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 4); - @@ -1221,7 +1110,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1261,41 +1150,41 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1329,7 +1218,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1382,7 +1271,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1435,7 +1324,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1481,7 +1370,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1495,7 +1384,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() { @@ -1549,7 +1438,7 @@ struct MyStruct2 { "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1574,7 +1463,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1601,7 +1490,7 @@ struct example_s { "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1617,7 +1506,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1653,7 +1542,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1670,7 +1559,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1703,7 +1592,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1720,7 +1609,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1753,7 +1642,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1786,7 +1675,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1821,7 +1710,7 @@ struct MyStruct1B : MyStruct1A "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1882,7 +1771,7 @@ struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1903,25 +1792,10 @@ struct MyStruct nuint + InlineArray(2) nuint - - nuint - - - ref nuint - - int - - - return ref AsSpan()[index]; - - - - Span<nuint> - MemoryMarshal.CreateSpan(ref e0, 2); - @@ -1931,7 +1805,7 @@ struct MyStruct var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedXmlLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1962,7 +1836,7 @@ protected override Task SourceLocationAttributeTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedXmlLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -1971,61 +1845,47 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous1.First, 1)); + return ref Anonymous.First; - + int - + int + InlineArray(2) - _Anonymous2_e__Struct - - - _Anonymous2_e__Struct + _MyArray_e__Struct - - ref _Anonymous2_e__Struct - - int - - - return ref AsSpan()[index]; - - - - Span<_Anonymous2_e__Struct> - MemoryMarshal.CreateSpan(ref e0, 2); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2036,7 +1896,8 @@ struct { struct { struct { int Value1; }; struct { int Value2; }; }; }; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" @@ -2048,32 +1909,32 @@ struct { int Value2; }; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous1_2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous2_2.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int @@ -2085,6 +1946,6 @@ struct { int Value2; }; "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs index 759f8ca0..51afb019 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs @@ -38,7 +38,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -68,7 +68,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -99,7 +99,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -272,14 +272,14 @@ union MyUnion3 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -308,35 +308,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -365,98 +347,17 @@ union MyOtherUnion MyUnion + InlineArray(2 * 1 * 3 * 4) MyUnion - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -487,35 +388,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -544,35 +427,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -618,7 +483,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -632,16 +497,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -655,16 +526,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -680,16 +557,22 @@ union MyUnion var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -733,7 +616,7 @@ union DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyUnion2 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -767,7 +650,7 @@ union MyUnion {expectedManagedType} - + {expectedManagedType} @@ -783,22 +666,22 @@ union MyUnion ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; ref MyStruct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; - + {expectedManagedType} @@ -808,13 +691,19 @@ union MyUnion {expectedManagedType} + + InlineArray(4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -854,41 +743,41 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -922,7 +811,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } @@ -976,7 +865,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1029,7 +918,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1075,7 +964,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1089,7 +978,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1114,7 +1003,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1141,7 +1030,7 @@ union example_s { "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1157,7 +1046,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1193,7 +1082,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1210,7 +1099,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1243,7 +1132,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1260,7 +1149,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1293,7 +1182,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1326,7 +1215,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1365,29 +1254,29 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() ref nint - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.A, 1)); + return ref Anonymous.Anonymous.A; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.B, 1)); + return ref Anonymous.Anonymous.B; nint - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct @@ -1407,31 +1296,16 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() + InlineArray(2) nint - - nint - - - ref nint - - int - - - return ref AsSpan()[index]; - - - - Span<nint> - MemoryMarshal.CreateSpan(ref e0, 2); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs index 26aa0acf..f321d031 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs @@ -28,7 +28,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -50,7 +50,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -81,7 +81,7 @@ protected override Task GuidMacroTestImpl() "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -110,7 +110,7 @@ protected override Task MacroTestImpl(string nativeValue, string expectedManaged "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -133,14 +133,14 @@ protected override Task MultilineMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -154,7 +154,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -162,7 +162,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -184,7 +184,7 @@ protected override Task Utf16StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -198,21 +198,21 @@ protected override Task WideStringLiteralConstTestImpl() - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] uint[] - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] @@ -220,7 +220,7 @@ protected override Task WideStringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -236,19 +236,19 @@ protected override Task StringLiteralConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -256,7 +256,7 @@ protected override Task StringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -270,21 +270,21 @@ protected override Task WideStringLiteralStaticConstTestImpl() - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] uint[] - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] @@ -292,7 +292,7 @@ protected override Task WideStringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralStaticConstTestImpl() @@ -308,19 +308,19 @@ protected override Task StringLiteralStaticConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -328,7 +328,7 @@ protected override Task StringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -365,7 +365,7 @@ protected override Task UncheckedConversionMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -391,7 +391,7 @@ protected override Task UncheckedFunctionLikeCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -417,7 +417,7 @@ protected override Task UncheckedConversionMacroTest2Impl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -441,7 +441,7 @@ protected override Task UncheckedPointerMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -467,7 +467,7 @@ protected override Task UncheckedReinterpretCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -501,7 +501,7 @@ protected override Task MultidimensionlArrayTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -528,6 +528,6 @@ protected override Task ConditionalDefineConstTestImpl() "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/CXXMethodDeclarationTest.cs index 68d12ca2..85afa10c 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/CXXMethodDeclarationTest.cs @@ -992,7 +992,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1017,7 +1017,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -1048,7 +1048,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1073,7 +1073,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs index 00348ce7..406a488f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs @@ -1618,7 +1618,7 @@ void MyFunction() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs index a1633f78..324ffced 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs @@ -22,16 +22,37 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@" - + {expectedManagedType} + + + {expectedManagedType} + + + ref {expectedManagedType} + + int + + + return ref Unsafe.Add(ref e0, index); + + + + Span<{expectedManagedType}> + + int + + MemoryMarshal.CreateSpan(ref e0, length); + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -62,7 +83,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -92,7 +113,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -123,7 +144,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -300,7 +321,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -488,7 +509,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -517,14 +538,14 @@ typedef struct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -553,35 +574,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -610,98 +613,17 @@ struct MyOtherStruct MyStruct + InlineArray(2 * 1 * 3 * 4) MyStruct - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -732,35 +654,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -789,35 +693,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -863,7 +749,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -877,16 +763,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -900,16 +792,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -925,16 +823,22 @@ struct MyStruct var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -979,7 +883,7 @@ struct DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyStruct2 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1040,7 +944,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1101,7 +1005,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1139,7 +1043,7 @@ struct MyStruct {expectedManagedType} - + {expectedManagedType} @@ -1152,34 +1056,34 @@ struct MyStruct ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref _Anonymous_e__Struct._w_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; ref MyUnion - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; Span<MyUnion> - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; - + {expectedManagedType} @@ -1200,32 +1104,17 @@ struct MyStruct {expectedManagedType} - + + InlineArray(4) - MyUnion - - - MyUnion - - - MyUnion + {expectedManagedType} - + + + InlineArray(4) + MyUnion - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 4); - @@ -1233,7 +1122,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1273,41 +1162,41 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1341,7 +1230,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1394,7 +1283,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1447,7 +1336,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1493,7 +1382,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1507,7 +1396,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() { @@ -1561,7 +1450,7 @@ struct MyStruct2 { "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1586,7 +1475,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1613,7 +1502,7 @@ struct example_s { "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1629,7 +1518,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1665,7 +1554,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1682,7 +1571,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1715,7 +1604,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1732,7 +1621,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1765,7 +1654,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1798,7 +1687,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1833,7 +1722,7 @@ struct MyStruct1B : MyStruct1A "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1894,7 +1783,7 @@ struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1913,25 +1802,10 @@ protected override Task WithPackingTestImpl() nuint + InlineArray(2) nuint - - nuint - - - ref nuint - - int - - - return ref AsSpan()[index]; - - - - Span<nuint> - MemoryMarshal.CreateSpan(ref e0, 2); - @@ -1941,7 +1815,7 @@ protected override Task WithPackingTestImpl() var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1972,7 +1846,7 @@ protected override Task SourceLocationAttributeTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -1981,61 +1855,47 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous1.First, 1)); + return ref Anonymous.First; - + int - + int + InlineArray(2) - _Anonymous2_e__Struct - - - _Anonymous2_e__Struct + _MyArray_e__Struct - - ref _Anonymous2_e__Struct - - int - - - return ref AsSpan()[index]; - - - - Span<_Anonymous2_e__Struct> - MemoryMarshal.CreateSpan(ref e0, 2); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2046,7 +1906,8 @@ struct { struct { struct { int Value1; }; struct { int Value2; }; }; }; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" @@ -2058,32 +1919,32 @@ struct { int Value2; }; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous1_2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.Anonymous2_2.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int @@ -2095,6 +1956,6 @@ struct { int Value2; }; "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs index ea283874..ee8d74a8 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs @@ -38,7 +38,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -68,7 +68,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -99,7 +99,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -278,14 +278,14 @@ union MyUnion3 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -314,35 +314,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -371,98 +353,17 @@ union MyOtherUnion MyUnion + InlineArray(2 * 1 * 3 * 4) MyUnion - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -493,35 +394,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -550,35 +433,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -624,7 +489,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -638,16 +503,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -661,16 +532,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -686,16 +563,22 @@ union MyUnion var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -739,7 +622,7 @@ union DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyUnion2 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -773,7 +656,7 @@ union MyUnion {expectedManagedType} - + {expectedManagedType} @@ -789,22 +672,22 @@ union MyUnion ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; ref MyStruct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; - + {expectedManagedType} @@ -814,13 +697,19 @@ union MyUnion {expectedManagedType} + + InlineArray(4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -860,41 +749,41 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.w, 1)); + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -928,7 +817,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } @@ -982,7 +871,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1035,7 +924,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1081,7 +970,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1095,7 +984,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1120,7 +1009,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1147,7 +1036,7 @@ union example_s { "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1163,7 +1052,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1199,7 +1088,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1216,7 +1105,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1249,7 +1138,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1266,7 +1155,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1299,7 +1188,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1332,7 +1221,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1361,7 +1250,7 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() var expectedOutputContents = $@" - + int @@ -1371,29 +1260,29 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.A, 1)); + return ref Anonymous.Anonymous.A; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous_1.B, 1)); + return ref Anonymous.Anonymous.B; int - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct @@ -1412,11 +1301,17 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() + + InlineArray(2) + + int + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs index 32a1e7f7..cc815988 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs @@ -28,7 +28,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -50,7 +50,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -81,7 +81,7 @@ protected override Task GuidMacroTestImpl() "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -110,7 +110,7 @@ protected override Task MacroTestImpl(string nativeValue, string expectedManaged "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -133,14 +133,14 @@ protected override Task MultilineMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -154,7 +154,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -162,7 +162,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -184,7 +184,7 @@ protected override Task Utf16StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -220,7 +220,7 @@ protected override Task WideStringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -236,19 +236,19 @@ protected override Task StringLiteralConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -256,7 +256,7 @@ protected override Task StringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -292,7 +292,7 @@ protected override Task WideStringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralStaticConstTestImpl() @@ -308,19 +308,19 @@ protected override Task StringLiteralStaticConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -328,7 +328,7 @@ protected override Task StringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -365,7 +365,7 @@ protected override Task UncheckedConversionMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -391,7 +391,7 @@ protected override Task UncheckedFunctionLikeCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -417,7 +417,7 @@ protected override Task UncheckedConversionMacroTest2Impl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -441,7 +441,7 @@ protected override Task UncheckedPointerMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -467,7 +467,7 @@ protected override Task UncheckedReinterpretCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -501,7 +501,7 @@ protected override Task MultidimensionlArrayTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -528,6 +528,6 @@ protected override Task ConditionalDefineConstTestImpl() "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs index 6f9e9e76..b843483e 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs @@ -992,7 +992,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1017,7 +1017,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -1048,7 +1048,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1073,7 +1073,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs index 0c2bb56b..5fd0fe60 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs @@ -1156,35 +1156,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1852,24 +1852,24 @@ struct { int Second; } MyArray[2]; - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - return ref Anonymous1.First; + return ref Anonymous.First; - + int - + int @@ -1877,7 +1877,7 @@ struct { int Second; } MyArray[2]; InlineArray(2) - _Anonymous2_e__Struct + _MyArray_e__Struct @@ -1909,32 +1909,32 @@ struct { int Value2; }; ref int - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs index ff57349b..16ab4377 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs @@ -749,35 +749,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -1258,25 +1258,25 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; nint - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs index 56aa6a01..d22ffa78 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs @@ -992,7 +992,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1017,7 +1017,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -1048,7 +1048,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1073,7 +1073,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs index 9df5bd6d..b79079b9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs @@ -1168,35 +1168,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1862,24 +1862,24 @@ struct { int Second; } MyArray[2]; - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - return ref Anonymous1.First; + return ref Anonymous.First; - + int - + int @@ -1887,7 +1887,7 @@ struct { int Second; } MyArray[2]; InlineArray(2) - _Anonymous2_e__Struct + _MyArray_e__Struct @@ -1919,32 +1919,32 @@ struct { int Value2; }; ref int - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs index 6ca7f65a..dcf645cf 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs @@ -755,35 +755,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -1264,25 +1264,25 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; int - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/CXXMethodDeclarationTest.cs index 6f753d62..fd20ea07 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/CXXMethodDeclarationTest.cs @@ -990,7 +990,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1015,7 +1015,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -1046,7 +1046,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1071,7 +1071,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs index 524c2eb5..4c4c8307 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs @@ -1156,35 +1156,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1851,24 +1851,24 @@ struct { int Second; } MyArray[2]; - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - return ref Anonymous1.First; + return ref Anonymous.First; - + int - + int @@ -1876,7 +1876,7 @@ struct { int Second; } MyArray[2]; InlineArray(2) - _Anonymous2_e__Struct + _MyArray_e__Struct @@ -1907,32 +1907,32 @@ struct { int Value2; }; ref int - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs index 37ef8238..11c40cec 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs @@ -749,35 +749,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -1258,25 +1258,25 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; nint - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/CXXMethodDeclarationTest.cs index e942b31a..7fa773bb 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/CXXMethodDeclarationTest.cs @@ -991,7 +991,7 @@ protected override Task VirtualTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1016,7 +1016,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); @@ -1047,7 +1047,7 @@ protected override Task VirtualWithVtblIndexAttributeTestImpl() { virtual void MyVoidMethod() = 0; - virtual char MyInt8Method() + virtual signed char MyInt8Method() { return 0; } @@ -1072,7 +1072,7 @@ virtual char MyInt8Method() - sbyte + sbyte return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this)); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs index 5e938aeb..3bb5c851 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs @@ -1168,35 +1168,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - + int @@ -1861,24 +1861,24 @@ struct { int Second; } MyArray[2]; - - _Anonymous1_e__Struct + + _Anonymous_e__Struct - _Anonymous2_e__Struct + _MyArray_e__Struct ref int - return ref Anonymous1.First; + return ref Anonymous.First; - + int - + int @@ -1886,7 +1886,7 @@ struct { int Second; } MyArray[2]; InlineArray(2) - _Anonymous2_e__Struct + _MyArray_e__Struct @@ -1917,32 +1917,32 @@ struct { int Value2; }; ref int - return ref Anonymous.Anonymous_1.Anonymous1_2.Value1; + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref Anonymous.Anonymous_1.Anonymous2_2.Value2; + return ref Anonymous.Anonymous1.Anonymous3.Value2; - - _Anonymous_1_e__Struct + + _Anonymous1_e__Struct - - - _Anonymous1_2_e__Struct + + + _Anonymous2_e__Struct - - _Anonymous2_2_e__Struct + + _Anonymous3_e__Struct - + int - + int diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs index 5600903f..e24fadc9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs @@ -755,35 +755,35 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref Anonymous.Anonymous_1.w; + return ref Anonymous.Anonymous1.w; int - return Anonymous.Anonymous_1.o0_b0_16; + return Anonymous.Anonymous1.o0_b0_16; - Anonymous.Anonymous_1.o0_b0_16 = value; + Anonymous.Anonymous1.o0_b0_16 = value; int - return Anonymous.Anonymous_1.o0_b16_4; + return Anonymous.Anonymous1.o0_b16_4; - Anonymous.Anonymous_1.o0_b16_4 = value; + Anonymous.Anonymous1.o0_b16_4 = value; int - - _Anonymous_1_e__Union + + _Anonymous1_e__Union - + int @@ -1264,25 +1264,25 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() - ref _Anonymous_e__Struct._Anonymous_1_e__Union._A_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref Anonymous.Anonymous_1.A; + return ref Anonymous.Anonymous.A; - ref _Anonymous_e__Struct._Anonymous_1_e__Union._B_e__Struct + ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref Anonymous.Anonymous_1.B; + return ref Anonymous.Anonymous.B; int - - _Anonymous_1_e__Union + + _Anonymous_e__Union - + _A_e__Struct diff --git a/tests/ClangSharp.UnitTests/ClangSharp.UnitTests.csproj b/tests/ClangSharp.UnitTests/ClangSharp.UnitTests.csproj index 837ec2d8..96f00b0a 100644 --- a/tests/ClangSharp.UnitTests/ClangSharp.UnitTests.csproj +++ b/tests/ClangSharp.UnitTests/ClangSharp.UnitTests.csproj @@ -2,12 +2,14 @@ - net8.0 + net10.0 + - $(NoWarn);CA1707 + + $(NoWarn);CA1515;CA1707;IDE0130