Skip to content

Commit 6780f2d

Browse files
committed
Version 0.1.9. Added support for ConcurrentBag translation.
1 parent 2cf7c6f commit 6780f2d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,44 @@ public class CSharpToCppTransformer : Transformer
228228
// auto path = new TElement[MaxPath];
229229
// TElement path[MaxPath] = { {0} };
230230
(new Regex(@"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];"), "$1$3 $2[$4] = { {0} };", null, 0),
231+
// private: static readonly ConcurrentBag<std::exception> _exceptionsBag = new ConcurrentBag<std::exception>();
232+
// private: static std::mutex _exceptionsBag_mutex; \n\n private: static std::vector<std::exception> _exceptionsBag;
233+
(new Regex(@"(?<begin>\r?\n?(?<indent>[ \t]+))(?<access>(private|protected|public): )?static readonly ConcurrentBag<(?<argumentType>[^;\r\n]+)> (?<name>[_a-zA-Z0-9]+) = new ConcurrentBag<\k<argumentType>>\(\);"), "${begin}private: static std::mutex ${name}_mutex;" + Environment.NewLine + Environment.NewLine + "${indent}${access}static std::vector<${argumentType}> ${name};", null, 0),
234+
// public: static IReadOnlyCollection<std::exception> GetCollectedExceptions() { return _exceptionsBag; }
235+
// public: static std::vector<std::exception> GetCollectedExceptions() { return std::vector<std::exception>(_exceptionsBag); }
236+
(new Regex(@"(?<access>(private|protected|public): )?static IReadOnlyCollection<(?<argumentType>[^;\r\n]+)> (?<methodName>[_a-zA-Z0-9]+)\(\) { return (?<fieldName>[_a-zA-Z0-9]+); }"), "${access}static std::vector<${argumentType}> ${methodName}() { return std::vector<${argumentType}>(${fieldName}); }", null, 0),
231237
// public: static event EventHandler<std::exception> ExceptionIgnored = OnExceptionIgnored; ... };
232238
// ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored; };
233239
(new Regex(@"(?<begin>\r?\n(\r?\n)?(?<halfIndent>[ \t]+)\k<halfIndent>)(?<access>(private|protected|public): )?static event EventHandler<(?<argumentType>[^;\r\n]+)> (?<name>[_a-zA-Z0-9]+) = (?<defaultDelegate>[_a-zA-Z0-9]+);(?<middle>(.|\n)+?)(?<end>\r?\n\k<halfIndent>};)"), "${middle}" + Environment.NewLine + Environment.NewLine + "${halfIndent}${halfIndent}${access}static inline Platform::Delegates::MulticastDelegate<void(void*, const ${argumentType}&)> ${name} = ${defaultDelegate};${end}", null, 0),
234240
// Insert scope borders.
241+
// class IgnoredExceptions { ... private: static std::vector<std::exception> _exceptionsBag;
242+
// class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: static std::vector<std::exception> _exceptionsBag;
243+
(new Regex(@"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?<middle>((?!class).|\n)+?)(?<vectorFieldDeclaration>(?<access>(private|protected|public): )static std::vector<(?<argumentType>[^;\r\n]+)> (?<fieldName>[_a-zA-Z0-9]+);)"), "${classDeclarationBegin}/*~${fieldName}~*/${middle}${vectorFieldDeclaration}", null, 0),
244+
// Inside the scope of ~!_exceptionsBag!~ replace:
245+
// _exceptionsBag.Add(exception);
246+
// _exceptionsBag.push_back(exception);
247+
(new Regex(@"(?<scope>/\*~(?<fieldName>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<fieldName>~\*/)(.|\n))*?)\k<fieldName>\.Add"), "${scope}${separator}${before}${fieldName}.push_back", null, 10),
248+
// Remove scope borders.
249+
// /*~_exceptionsBag~*/
250+
//
251+
(new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", null, 0),
252+
// Insert scope borders.
253+
// class IgnoredExceptions { ... private: static std::mutex _exceptionsBag_mutex;
254+
// class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: static std::mutex _exceptionsBag_mutex;
255+
(new Regex(@"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?<middle>((?!class).|\n)+?)(?<mutexDeclaration>private: static std::mutex (?<fieldName>[_a-zA-Z0-9]+)_mutex;)"), "${classDeclarationBegin}/*~${fieldName}~*/${middle}${mutexDeclaration}", null, 0),
256+
// Inside the scope of ~!_exceptionsBag!~ replace:
257+
// return std::vector<std::exception>(_exceptionsBag);
258+
// std::lock_guard<std::mutex> guard(_exceptionsBag_mutex); return std::vector<std::exception>(_exceptionsBag);
259+
(new Regex(@"(?<scope>/\*~(?<fieldName>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<fieldName>~\*/)(.|\n))*?){(?<after>((?!lock_guard)[^{};\r\n])*\k<fieldName>[^;}\r\n]*;)"), "${scope}${separator}${before}{ std::lock_guard<std::mutex> guard(${fieldName}_mutex);${after}", null, 10),
260+
// Inside the scope of ~!_exceptionsBag!~ replace:
261+
// _exceptionsBag.Add(exception);
262+
// std::lock_guard<std::mutex> guard(_exceptionsBag_mutex); \r\n _exceptionsBag.Add(exception);
263+
(new Regex(@"(?<scope>/\*~(?<fieldName>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<fieldName>~\*/)(.|\n))*?){(?<after>((?!lock_guard)([^{};]|\n))*?\r?\n(?<indent>[ \t]*)\k<fieldName>[^;}\r\n]*;)"), "${scope}${separator}${before}{" + Environment.NewLine + "${indent}std::lock_guard<std::mutex> guard(${fieldName}_mutex);${after}", null, 10),
264+
// Remove scope borders.
265+
// /*~_exceptionsBag~*/
266+
//
267+
(new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", null, 0),
268+
// Insert scope borders.
235269
// class IgnoredExceptions { ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored;
236270
// class IgnoredExceptions {/*~ExceptionIgnored~*/ ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored;
237271
(new Regex(@"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?<middle>((?!class).|\n)+?)(?<eventDeclaration>(?<access>(private|protected|public): )static inline Platform::Delegates::MulticastDelegate<(?<argumentType>[^;\r\n]+)> (?<name>[_a-zA-Z0-9]+) = (?<defaultDelegate>[_a-zA-Z0-9]+);)"), "${classDeclarationBegin}/*~${name}~*/${middle}${eventDeclaration}", null, 0),

csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/Platform.RegularExpressions.Transformer.CSharpToCpp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>LinksPlatform's Platform.RegularExpressions.Transformer.CSharpToCpp Class Library</Description>
55
<Copyright>Konstantin Diachenko</Copyright>
66
<AssemblyTitle>Platform.RegularExpressions.Transformer.CSharpToCpp</AssemblyTitle>
7-
<VersionPrefix>0.1.8</VersionPrefix>
7+
<VersionPrefix>0.1.9</VersionPrefix>
88
<Authors>Konstantin Diachenko</Authors>
99
<TargetFrameworks>net471;netstandard2.0;netstandard2.1</TargetFrameworks>
1010
<AssemblyName>Platform.RegularExpressions.Transformer.CSharpToCpp</AssemblyName>
@@ -24,7 +24,7 @@
2424
<IncludeSymbols>true</IncludeSymbols>
2525
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2626
<LangVersion>latest</LangVersion>
27-
<PackageReleaseNotes>Pattern for setting scope for event fixed.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Added support for ConcurrentBag translation.</PackageReleaseNotes>
2828
</PropertyGroup>
2929

3030
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'">

0 commit comments

Comments
 (0)