├── .github
├── dependabot.yml
└── workflows
│ ├── AutoMerge.yml
│ └── csharp.yml
├── python
├── cs2cpp
│ ├── __init__.py
│ └── cs2cpp.py
├── README.md
├── setup.py
└── test.py
├── csharp
├── Platform.RegularExpressions.Transformer.CSharpToCpp.Tests
│ ├── Platform.RegularExpressions.Transformer.CSharpToCpp.Tests.csproj
│ └── CSharpToCppTransformerTests.cs
├── Platform.RegularExpressions.Transformer.CSharpToCpp.sln
└── Platform.RegularExpressions.Transformer.CSharpToCpp
│ ├── Platform.RegularExpressions.Transformer.CSharpToCpp.csproj
│ └── CSharpToCppTransformer.cs
├── LICENSE
├── README.md
└── .gitignore
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: nuget
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | open-pull-requests-limit: 10
8 |
--------------------------------------------------------------------------------
/python/cs2cpp/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from .cs2cpp import CSharpToCpp
4 |
5 | __version__ = "0.2.0"
6 | __copyright__ = "2022"
7 | __authors__ = ["Ethosa", "Konard"]
8 |
--------------------------------------------------------------------------------
/.github/workflows/AutoMerge.yml:
--------------------------------------------------------------------------------
1 | name: auto-merge
2 |
3 | on:
4 | pull_request_target:
5 |
6 | jobs:
7 | auto-merge:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v2
11 | - uses: ahmadnassri/action-dependabot-auto-merge@v2
12 | with:
13 | target: minor
14 | github-token: ${{ secrets.DEPENDABOT_AUTO_MERGE_TOKEN }}
15 |
--------------------------------------------------------------------------------
/python/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # CSharpToCpp
4 | ### Simple C# to C++ translator written in Python
5 |
6 |
7 |
8 |
9 | ## Get Started
10 | ### Install
11 | ```pip install --upgrade cs2cpp```
12 |
13 | ### Usage
14 | ```python
15 | from cs2cpp import CSharpToCpp
16 |
17 | cscpp = CSharpToCpp()
18 | sourceCode = """using System;
19 | // This is hello world program.
20 | class Program
21 | {
22 | public static void Main(string[] args)
23 | {
24 | var myFirstString = "ban";
25 | char*[] args = {"1", "2"};
26 | Console.WriteLine("Hello, world!");
27 | }
28 | }"""
29 | print(cscpp.translate(sourceCode)) # translate code from C# to C++!
30 | ```
31 |
--------------------------------------------------------------------------------
/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8
5 | false
6 | latest
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
--------------------------------------------------------------------------------
/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/CSharpToCppTransformerTests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Platform.RegularExpressions.Transformer.CSharpToCpp.Tests
4 | {
5 | public class CSharpToCppTransformerTests
6 | {
7 | [Fact]
8 | public void EmptyLineTest()
9 | {
10 | // This test can help to test basic problems with regular expressions like incorrect syntax
11 | var transformer = new CSharpToCppTransformer();
12 | var actualResult = transformer.Transform("");
13 | Assert.Equal("", actualResult);
14 | }
15 |
16 | [Fact]
17 | public void HelloWorldTest()
18 | {
19 | const string helloWorldCode = @"using System;
20 | class Program
21 | {
22 | public static void Main(string[] args)
23 | {
24 | Console.WriteLine(""Hello, world!"");
25 | }
26 | }";
27 | const string expectedResult = @"class Program
28 | {
29 | public: static void Main(std::string args[])
30 | {
31 | printf(""Hello, world!\n"");
32 | }
33 | };";
34 | var transformer = new CSharpToCppTransformer();
35 | var actualResult = transformer.Transform(helloWorldCode);
36 | Assert.Equal(expectedResult, actualResult);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/python/setup.py:
--------------------------------------------------------------------------------
1 | import setuptools
2 |
3 | with open("README.md", "r") as fh:
4 | long_description = fh.read()
5 |
6 | setuptools.setup(
7 | name="cs2cpp",
8 | version="0.2.0",
9 | author="Ethosa",
10 | author_email="social.ethosa@gmail.com",
11 | description="Csharp to Cpp code translator",
12 | long_description=long_description,
13 | long_description_content_type="text/markdown",
14 | url="https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python",
15 | packages=setuptools.find_packages(),
16 | license="LGPLv3",
17 | keywords="csharp cpp cs2cpp links platform ethosa konard",
18 | classifiers=[
19 | "Development Status :: 4 - Beta",
20 | "Programming Language :: Python :: 3",
21 | "Programming Language :: Python :: 3.4",
22 | "Programming Language :: Python :: 3.5",
23 | "Programming Language :: Python :: 3.6",
24 | "Programming Language :: Python :: 3.7",
25 | "Programming Language :: Python :: 3.8",
26 | "Programming Language :: Python :: 3.9",
27 | "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
28 | "Operating System :: OS Independent",
29 | ],
30 | project_urls={
31 | "Github": "https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python",
32 | "Documentation": "https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python",
33 | },
34 | python_requires=">=3",
35 | install_requires=["retranslator >= 0.2.0"]
36 | )
37 |
--------------------------------------------------------------------------------
/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29326.143
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Platform.RegularExpressions.Transformer.CSharpToCpp", "Platform.RegularExpressions.Transformer.CSharpToCpp\Platform.RegularExpressions.Transformer.CSharpToCpp.csproj", "{4CC673F5-B97D-441D-8D74-6F40A93F1454}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.RegularExpressions.Transformer.CSharpToCpp.Tests", "Platform.RegularExpressions.Transformer.CSharpToCpp.Tests\Platform.RegularExpressions.Transformer.CSharpToCpp.Tests.csproj", "{03D93E29-4D6F-44DD-AFCC-F220154C1CF0}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {70937F8A-7518-405A-9A61-6C116D17481D}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/python/test.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from unittest import main, TestCase
3 |
4 | from cs2cpp import CSharpToCpp
5 |
6 |
7 | class CSharpToCppTest(TestCase):
8 | translator = CSharpToCpp()
9 |
10 | def test_translate_hello_world(self):
11 | print(
12 | self.translator.translate(
13 | ('''
14 | using System;
15 | // This is hello world program.
16 | class Program
17 | {
18 | public static void Main(string[] args)
19 | {
20 | var myFirstString = "ban";
21 | char*[] args = {"1", "2"};
22 | Console.WriteLine("Hello, world!");
23 | }
24 | }''')))
25 |
26 | def test_some(self):
27 | print(
28 | self.translator.translate(
29 | ('''
30 | namespace Platform.Interfaces
31 | {
32 | ///
33 | /// Defines a factory that produces instances of a specific type.
34 | /// Определяет фабрику, которая производит экземпляры определенного типа.
35 | ///
36 | /// Type of produced instances.Тип производимых экземпляров.
37 | public interface IFactory
38 | {
39 | ///
40 | /// Creates an instance of TProduct type.
41 | /// Создает экземпляр типа TProduct.
42 | ///
43 | /// The instance of TProduct type.Экземпляр типа TProduct.
44 | TProduct Create();
45 | }
46 | }''')))
47 |
48 | if __name__ == '__main__':
49 | main(verbosity=2)
50 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/actions?workflow=CD)
2 | [](https://www.codacy.com/manual/drakonard/RegularExpressions.Transformer.CSharpToCpp?utm_source=github.com&utm_medium=referral&utm_content=linksplatform/RegularExpressions.Transformer.CSharpToCpp&utm_campaign=Badge_Grade)
3 | [](https://www.codefactor.io/repository/github/linksplatform/regularexpressions.transformer.csharptocpp)
4 |
5 | | [](https://www.nuget.org/packages/Platform.RegularExpressions.Transformer.CSharpToCpp) | C# |
6 | |-|-|
7 | | [](https://badge.fury.io/py/cs2cpp) | __Python__ |
8 |
9 | # [RegularExpressions.Transformer.CSharpToCpp](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp)
10 |
11 | LinksPlatform's Platform.RegularExpressions.Transformer.CSharpToCpp Class Library.
12 |
13 | Namespace: [Platform.RegularExpressions.Transformer.CSharpToCpp](https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp/csharp/api/Platform.RegularExpressions.Transformer.CSharpToCpp.html)
14 |
15 | Forked from: [LinksPlatform/Collections.Methods/CSharpToCppTranslator](https://github.com/linksplatform/Collections.Methods/tree/93bdb700f81cae341164da6a78e1b770814d0eba/CSharpToCppTranslator)
16 |
17 | NuGet package: [Platform.RegularExpressions.Transformer.CSharpToCpp](https://www.nuget.org/packages/Platform.RegularExpressions.Transformer.CSharpToCpp)
18 |
19 | Python version: [cs2cpp](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python)
20 |
21 | ## [Documentation](https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp)
22 | [PDF file](https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.pdf) with code for e-readers.
23 |
24 | ## Depend on
25 | * [Platform.RegularExpressions.Transformer](https://github.com/linksplatform/RegularExpressions.Transformer)
26 |
--------------------------------------------------------------------------------
/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/Platform.RegularExpressions.Transformer.CSharpToCpp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LinksPlatform's Platform.RegularExpressions.Transformer.CSharpToCpp Class Library
5 | Konstantin Diachenko
6 | Platform.RegularExpressions.Transformer.CSharpToCpp
7 | 0.3.0
8 | Konstantin Diachenko
9 | net8
10 | Platform.RegularExpressions.Transformer.CSharpToCpp
11 | Platform.RegularExpressions.Transformer.CSharpToCpp
12 | LinksPlatform;RegularExpressions.Transformer.CSharpToCpp;CSharpToCppTransformer
13 | https://raw.githubusercontent.com/linksplatform/Documentation/18469f4d033ee9a5b7b84caab9c585acab2ac519/doc/Avatar-rainbow-icon-64x64.png
14 | https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp
15 | Unlicensed
16 | git
17 | git://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp
18 | false
19 | false
20 | true
21 | true
22 | true
23 | true
24 | snupkg
25 | latest
26 | Update target framework from net7 to net8.
27 | enable
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/.github/workflows/csharp.yml:
--------------------------------------------------------------------------------
1 | name: csharp
2 |
3 | on:
4 | push:
5 | branches: main
6 | paths:
7 | - 'csharp/**'
8 | - '.github/workflows/csharp.yml'
9 | env:
10 | NUGETTOKEN: ${{ secrets.NUGET_TOKEN }}
11 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 | SCRIPTS_BASE_URL: https://raw.githubusercontent.com/linksplatform/Scripts/main/MultiProjectRepository
13 |
14 | defaults:
15 | run:
16 | working-directory: csharp
17 |
18 | jobs:
19 | test:
20 | runs-on: ubuntu-latest
21 | steps:
22 | - uses: actions/checkout@v1
23 | with:
24 | submodules: true
25 | - name: Test
26 | run: |
27 | dotnet test -c Release -f net8
28 | pushNuGetPackageToGitHubPackageRegistry:
29 | needs: test
30 | runs-on: ubuntu-latest
31 | steps:
32 | - uses: actions/checkout@v1
33 | with:
34 | submodules: true
35 | - uses: nuget/setup-nuget@v1
36 | - name: Publish NuGet package to GitHub Package Registry
37 | run: |
38 | dotnet build -c Release
39 | dotnet pack -c Release
40 | nuget source Add -Name "GitHub" -Source "https://nuget.pkg.github.com/linksplatform/index.json" -UserName linksplatform -Password ${{ secrets.GITHUB_TOKEN }}
41 | nuget push **/*.nupkg -Source "GitHub" -SkipDuplicate
42 | pusnToNuget:
43 | runs-on: ubuntu-latest
44 | needs: test
45 | steps:
46 | - uses: actions/checkout@v1
47 | with:
48 | submodules: true
49 | - name: Read project information
50 | run: |
51 | export REPOSITORY_NAME=$(basename ${{ github.repository }})
52 | wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh"
53 | bash ./read_csharp_package_info.sh
54 | - name: Publish NuGet package
55 | run: |
56 | export REPOSITORY_NAME=$(basename ${{ github.repository }})
57 | wget "$SCRIPTS_BASE_URL/push-csharp-nuget.sh"
58 | bash ./push-csharp-nuget.sh
59 | publiseRelease:
60 | runs-on: ubuntu-latest
61 | needs: test
62 | steps:
63 | - uses: actions/checkout@v1
64 | with:
65 | submodules: true
66 | - name: Read project information
67 | if: ${{ github.event_name == 'push' }}
68 | run: |
69 | export REPOSITORY_NAME=$(basename ${{ github.repository }})
70 | wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh"
71 | bash ./read_csharp_package_info.sh
72 | - name: Publish release
73 | run: |
74 | export REPOSITORY_NAME=$(basename ${{ github.repository }})
75 | wget "$SCRIPTS_BASE_URL/publish-release.sh"
76 | chmod +x ./publish-release.sh
77 | wget "$SCRIPTS_BASE_URL/publish-csharp-release.sh"
78 | bash ./publish-csharp-release.sh
79 | findChangedCsFiles:
80 | runs-on: ubuntu-latest
81 | needs: test
82 | outputs:
83 | isCsFilesChanged: ${{ steps.setIsCsFilesChangedOutput.outputs.isCsFilesChanged }}
84 | steps:
85 | - uses: actions/checkout@v3
86 | with:
87 | fetch-depth: 0
88 | - name: Get changed files using defaults
89 | id: changed-files
90 | uses: tj-actions/changed-files@v21
91 | - name: Set output isCsFilesChanged
92 | id: setIsCsFilesChangedOutput
93 | run: |
94 | isCsFilesChanged='false'
95 | echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
96 | for changedFile in ${{ steps.changed-files.outputs.all_changed_files }}; do
97 | if [[ $changedFile == *.cs ]]
98 | then
99 | echo "isCsFilesChanged='true'"
100 | isCsFilesChanged='true'
101 | fi
102 | done
103 | echo "::set-output name=isCsFilesChanged::${isCsFilesChanged}"
104 | echo "isCsFilesChanged: ${isCsFilesChanged}"
105 | generatePdfWithCode:
106 | runs-on: ubuntu-latest
107 | needs: [findChangedCsFiles]
108 | if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }}
109 | steps:
110 | - uses: actions/checkout@v1
111 | with:
112 | submodules: true
113 | - name: Generate PDF with code
114 | run: |
115 | export REPOSITORY_NAME=$(basename ${{ github.repository }})
116 | wget "$SCRIPTS_BASE_URL/format-csharp-files.py"
117 | wget "$SCRIPTS_BASE_URL/format-csharp-document.sh"
118 | wget "$SCRIPTS_BASE_URL/generate-csharp-pdf.sh"
119 | bash ./generate-csharp-pdf.sh
120 | publishDocumentation:
121 | runs-on: ubuntu-latest
122 | needs: [findChangedCsFiles]
123 | if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }}
124 | steps:
125 | - uses: actions/checkout@v1
126 | with:
127 | submodules: true
128 | - name: Publish documentation to gh-pages branch
129 | run: |
130 | export REPOSITORY_NAME=$(basename ${{ github.repository }})
131 | wget "$SCRIPTS_BASE_URL/docfx.json"
132 | wget "$SCRIPTS_BASE_URL/filter.yml"
133 | wget "$SCRIPTS_BASE_URL/toc.yml"
134 | wget "$SCRIPTS_BASE_URL/publish-csharp-docs.sh"
135 | bash ./publish-csharp-docs.sh
136 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/python/cs2cpp/cs2cpp.py:
--------------------------------------------------------------------------------
1 | # -*- coding utf-8 -*-
2 | # authors: Ethosa, Konard
3 | from typing import NoReturn, Optional, List
4 |
5 | from retranslator import Translator, SubRule, SteppedTranslator
6 | from regex import search, sub
7 |
8 |
9 | class CSharpToCpp(Translator):
10 | def __init__(
11 | self,
12 | extra: List[SubRule] = []
13 | ) -> NoReturn:
14 | """Initializes class
15 |
16 | :param extra: include your own rules
17 | """
18 | # create little magic ...
19 | self.rules = CSharpToCpp.FIRST_RULES[:]
20 | self.rules.extend(extra)
21 | self.rules.extend(CSharpToCpp.LAST_RULES)
22 | Translator.__init__(self, self.rules)
23 |
24 | # Rules for translate code
25 | FIRST_RULES = [
26 | # // ...
27 | #
28 | SubRule(r"(\r?\n)?[ \t]+//+.+", r"", max_repeat=0),
29 | # #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
30 | #
31 | SubRule(r"^\s*?\#pragma[\sa-zA-Z0-9]+$", r"", max_repeat=0),
32 | # {\n\n\n
33 | # {
34 | SubRule(r"{\s+[\r\n]+", r"{\n", max_repeat=0),
35 | # Platform.Collections.Methods.Lists
36 | # Platform::Collections::Methods::Lists
37 | SubRule(r"(namespace[^\r\n]+?)\.([^\r\n]+?)", r"\1::\2", max_repeat=20),
38 | # nameof(numbers)
39 | # "numbers"
40 | SubRule(r"(?P\W)nameof\(([^)\n]+\.)?(?P[a-zA-Z0-9_]+)(<[^)\n]+>)?\)", r"\g\"\g\"", max_repeat=0),
41 | # Insert markers
42 | # EqualityComparer _equalityComparer = EqualityComparer.Default;
43 | # EqualityComparer _equalityComparer = EqualityComparer.Default;/*~_comparer~*/
44 | SubRule(r"(?PEqualityComparer<(?P[^>\n]+)> (?P[a-zA-Z0-9_]+) = EqualityComparer<\k>\.Default;)", r"\g/*~\g~*/", max_repeat=0),
45 | # /*~_equalityComparer~*/..._equalityComparer.Equals(Minimum, value)
46 | # /*~_equalityComparer~*/...Minimum == value
47 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9_]+)~\*/(.|\n)+\W)\k\.Equals\((?P[^,\n]+), (?P[^)\n]+)\)", r"\g\g == \g", max_repeat=50),
48 | # Remove markers
49 | # /*~_equalityComparer~*/
50 | #
51 | SubRule(r"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/", r"", max_repeat=10),
52 | # Insert markers
53 | # Comparer _comparer = Comparer.Default;
54 | # Comparer _comparer = Comparer.Default;/*~_comparer~*/
55 | SubRule(r"(?PComparer<(?P[^>\n]+)> (?P[a-zA-Z0-9_]+) = Comparer<\k>\.Default;)", r"\g/*~\g~*/", max_repeat=0),
56 | # /*~_comparer~*/..._comparer.Compare(Minimum, value) <= 0
57 | # /*~_comparer~*/...Minimum <= value
58 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9_]+)~\*/(.|\n)+\W)\k\.Compare\((?P[^,\n]+), (?P[^)\n]+)\)\s*(?P[<>=]=?)\s*0(?P\D)", r"\g\g \g \g\g", max_repeat=50),
59 | # Remove markers
60 | # private static readonly Comparer _comparer = Comparer.Default;/*~_comparer~*/
61 | #
62 | SubRule(r"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/", r"", max_repeat=10),
63 | # Comparer.Default.Compare(maximumArgument, minimumArgument) < 0
64 | # maximumArgument < minimumArgument
65 | SubRule(r"Comparer<[^>\n]+>\.Default\.Compare\(\s*(?P[^,)\n]+),\s*(?P[^\)\n]+)\s*\)\s*(?P[<>=]=?)\s*0(?P\D)", r"\g \g \g\g", max_repeat=0),
66 | # public static bool operator ==(Range left, Range right) => left.Equals(right);
67 | #
68 | SubRule(r"\r?\n[^\n]+bool operator ==\((?P[^\n]+) (?P[a-zA-Z0-9]+), \k (?P[a-zA-Z0-9]+)\) => (\k|\k)\.Equals\((\k|\k)\);", r"", max_repeat=10),
69 | # public static bool operator !=(Range left, Range right) => !(left == right);
70 | #
71 | SubRule(r"\r?\n[^\n]+bool operator !=\((?P[^\n]+) (?P[a-zA-Z0-9]+), \k (?P[a-zA-Z0-9]+)\) => !\((\k|\k) == (\k|\k)\);", r"", max_repeat=10),
72 | # public override bool Equals(object obj) => obj is Range range ? Equals(range) : false;
73 | #
74 | SubRule(r"\r?\n[^\n]+override bool Equals\((System\.)?[Oo]bject (?P[a-zA-Z0-9]+)\) => \k is [^\n]+ (?P[a-zA-Z0-9]+) \? Equals\(\k\) : false;", r"", max_repeat=10),
75 | # out TProduct
76 | # TProduct
77 | SubRule(r"(?P(<|, ))(in|out) (?P[a-zA-Z0-9]+)(?P(>|,))", r"\g\g\g", max_repeat=10),
78 | # public ...
79 | # public: ...
80 | SubRule(r"(?P\r?\n?[ \t]*)(?P[^\{\(\r\n]*)(?Pprivate|protected|public)[ \t]+(?![^\{\(\r\n]*((?<=\s)|\W)(interface|class|struct)(\W)[^\{\(\r\n]*[\{\(\r\n])", r"\g\g: \g", max_repeat=0),
81 | # public: static bool CollectExceptions { get; set; }
82 | # public: inline static bool CollectExceptions;
83 | SubRule(r"(?P(private|protected|public): )(?P(static )?[^\r\n]+ )(?P[a-zA-Z0-9]+) {[^;}]*(?<=\W)get;[^;}]*(?<=\W)set;[^;}]*}", r"\ginline \g\g;", max_repeat=0),
84 | # public abstract class
85 | # class
86 | SubRule(r"((public|protected|private|internal|abstract|static) )*(?Pinterface|class|struct)", r"\g", max_repeat=0),
87 | # class GenericCollectionMethodsBase {
88 | # template class GenericCollectionMethodsBase {
89 | SubRule(r"(?P\r?\n)(?P[ \t]*)(?Pclass|struct) (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate \g \g;\n" + "\gtemplate > \g \g<\g>\g{", max_repeat=0),
90 | # static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root)
91 | # template static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root)
92 | SubRule(r"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)\r\n]+)\)", r"template static \1 \2(\4)", max_repeat=0),
93 | # interface IFactory {
94 | # template class IFactory;\ntemplate class IFactory
95 | SubRule(r"(?P\r?\n)(?P[ \t]*)interface (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate class \g;\n" + "\gtemplate > class \g<\g>\g{\n" + " public:", max_repeat=0),
96 | # template
97 | # template
98 | SubRule(r"(?Ptemplate <((, )?typename [a-zA-Z0-9]+)+, )(?P[a-zA-Z0-9]+)(?P(,|>))", r"\gtypename \g\g", max_repeat=10),
99 | # Insert markers
100 | # private: static void BuildExceptionString(this StringBuilder sb, Exception exception, int level)
101 | # /*~extensionMethod~BuildExceptionString~*/private: static void BuildExceptionString(this StringBuilder sb, Exception exception, int level)
102 | SubRule(r"private: static [^\r\n]+ (?P[a-zA-Z0-9]+)\(this [^\)\r\n]+\)", r"/*~extensionMethod~\g~*/\0", max_repeat=0),
103 | # Move all markers to the beginning of the file.
104 | SubRule(r"\A(?P[^\r\n]+\r?\n(.|\n)+)(?P/\*~extensionMethod~(?P[a-zA-Z0-9]+)~\*/)", r"\g\g", max_repeat=10),
105 | # /*~extensionMethod~BuildExceptionString~*/...sb.BuildExceptionString(exception.InnerException, level + 1);
106 | # /*~extensionMethod~BuildExceptionString~*/...BuildExceptionString(sb, exception.InnerException, level + 1);
107 | SubRule(r"(?P/\*~extensionMethod~(?P[a-zA-Z0-9]+)~\*/(.|\n)+\W)(?P[_a-zA-Z0-9]+)\.\k\(", r"\g\g(\g, ", max_repeat=50),
108 | # Remove markers
109 | # /*~extensionMethod~BuildExceptionString~*/
110 | #
111 | SubRule(r"/\*~extensionMethod~[a-zA-Z0-9]+~\*/", r"", max_repeat=0),
112 | # (this
113 | # (
114 | SubRule(r"\(this ", r"(", max_repeat=0),
115 | # private: static readonly Disposal _emptyDelegate = (manual, wasDisposed) => { };
116 | # private: inline static std::function _emptyDelegate = [](auto manual, auto wasDisposed) { };
117 | SubRule(r"(?P(private|protected|public): )?static readonly (?P[a-zA-Z][a-zA-Z0-9]*) (?P[a-zA-Z_][a-zA-Z0-9_]*) = \((?P[a-zA-Z_][a-zA-Z0-9_]*), (?P[a-zA-Z_][a-zA-Z0-9_]*)\) => {\s*};", r"\ginline static std::function<\g> \g = [](auto \g, auto \g) { };", max_repeat=0),
118 | # public: static readonly EnsureAlwaysExtensionRoot Always = new EnsureAlwaysExtensionRoot();
119 | # public: inline static EnsureAlwaysExtensionRoot Always;
120 | SubRule(r"(?P(private|protected|public): )?static readonly (?P[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?P[a-zA-Z0-9_]+) = new \k\(\);", r"\ginline static \g \g;", max_repeat=0),
121 | # public: static readonly Range SByte = new Range(std::numeric_limits::min(), std::numeric_limits::max());
122 | # public: inline static Range SByte = Range(std::numeric_limits::min(), std::numeric_limits::max());
123 | SubRule(r"(?P(private|protected|public): )?static readonly (?P[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?P[a-zA-Z0-9_]+) = new \k\((?P[^\n]+)\);", r"\ginline static \g \g = \g(\g);", max_repeat=0),
124 | # public: static readonly string ExceptionContentsSeparator = "---";
125 | # public: inline static std::string ExceptionContentsSeparator = "---";
126 | SubRule(r"(?P(private|protected|public): )?(const|static readonly) string (?P[a-zA-Z0-9_]+) = \"\"(?P(\\\"\"|[^\"\"\r\n])+)\"\";", r"\ginline static std::string \g = \"\g\";", max_repeat=0),
127 | # private: const int MaxPath = 92;
128 | # private: inline static const int MaxPath = 92;
129 | SubRule(r"(?P(private|protected|public): )?(const|static readonly) (?P[a-zA-Z0-9]+) (?P[_a-zA-Z0-9]+) = (?P[^;\r\n]+);", r"\ginline static const \g \g = \g;", max_repeat=0),
130 | # ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument argument) where TArgument : class
131 | # ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument* argument)
132 | SubRule(r"(?P [a-zA-Z]+\(([a-zA-Z *,]+, |))(?P[a-zA-Z]+)(?P(| [a-zA-Z *,]+)\))[ \r\n]+where \k : class", r"\g\g*\g", max_repeat=0),
133 | # protected: abstract TElement GetFirst();
134 | # protected: virtual TElement GetFirst() = 0;
135 | SubRule(r"(?P(private|protected|public): )?abstract (?P[^;\r\n]+);", r"\gvirtual \g = 0;", max_repeat=0),
136 | # TElement GetFirst();
137 | # virtual TElement GetFirst() = 0;
138 | SubRule(r"(?P[\r\n]+[ ]+)(?P(?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)\r\n]*\))(?P;[ ]*[\r\n]+)", r"\gvirtual \g = 0\g", max_repeat=1),
139 | # protected: readonly TreeElement[] _elements;
140 | # protected: TreeElement _elements[N];
141 | SubRule(r"(?P(private|protected|public): )?readonly (?P[a-zA-Z<>0-9]+)([\[\]]+) (?P[_a-zA-Z0-9]+);", r"\g\g \g[N];", max_repeat=0),
142 | # protected: readonly TElement Zero;
143 | # protected: TElement Zero;
144 | SubRule(r"(?P(private|protected|public): )?readonly (?P[a-zA-Z<>0-9]+) (?P[_a-zA-Z0-9]+);", r"\g\g \g;", max_repeat=0),
145 | # internal
146 | #
147 | SubRule(r"(\W)internal\s+", r"\1", max_repeat=0),
148 | # static void NotImplementedException(ThrowExtensionRoot root) => throw new NotImplementedException();
149 | # static void NotImplementedException(ThrowExtensionRoot root) { return throw new NotImplementedException(); }
150 | SubRule(r"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+throw([^;\r\n]+);", r"\1\2\3\4\5\6\7\8(\9) { throw\10; }", max_repeat=0),
151 | # SizeBalancedTree(int capacity) => a = b;
152 | # SizeBalancedTree(int capacity) { a = b; }
153 | SubRule(r"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?(void )?([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);", r"\1\2\3\4\5\6\7\8(\9) { \10; }", max_repeat=0),
154 | # int SizeBalancedTree(int capacity) => a;
155 | # int SizeBalancedTree(int capacity) { return a; }
156 | SubRule(r"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);", r"\1\2\3\4\5\6\7\8(\9) { return \10; }", max_repeat=0),
157 | # OnDispose = (manual, wasDisposed) =>
158 | # OnDispose = [&](auto manual, auto wasDisposed)
159 | SubRule(r"(?P[a-zA-Z_][a-zA-Z0-9_]*)(?P\s*\+?=\s*)\((?P[a-zA-Z_][a-zA-Z0-9_]*), (?P[a-zA-Z_][a-zA-Z0-9_]*)\)\s*=>", r"\g\g[&](auto \g, auto \g