Skip to content

Commit 6866cf4

Browse files
committed
Version 0.1.6. Using nullptr instead of NULL in C++. Added rule to support translation of .Invoke method of EventHandler. Small tweeks and fixes.
1 parent 81c82ee commit 6866cf4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,19 @@ public class CSharpToCppTransformer : Transformer
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),
231231
// public: static event EventHandler<std::exception> ExceptionIgnored = OnExceptionIgnored; ... };
232232
// ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored; };
233-
(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 + "${halfIndent}${halfIndent}${access}static inline Platform::Delegates::MulticastDelegate<void(void*, const ${argumentType}&)> ${name} = ${defaultDelegate};${end}", null, 0),
233+
(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 + "${halfIndent}${halfIndent}${access}static inline Platform::Delegates::MulticastDelegate<void(void*, const ${argumentType}&)> ${name} = ${defaultDelegate};${end}", null, 0),
234+
// Insert scope borders.
235+
// class IgnoredExceptions { ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored;
236+
// class IgnoredExceptions {/*~ExceptionIgnored~*/ ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored;
237+
(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),
238+
// Inside the scope of ~!ExceptionIgnored!~ replace:
239+
// ExceptionIgnored.Invoke(NULL, exception);
240+
// ExceptionIgnored(NULL, exception);
241+
(new Regex(@"(?<scope>/\*~(?<eventName>[a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<eventName>~\*/)(.|\n))*?)\k<eventName>\.Invoke"), "${scope}${separator}${before}${eventName}", null, 10),
242+
// Remove scope borders.
243+
// /*~ExceptionIgnored~*/
244+
//
245+
(new Regex(@"/\*~[a-zA-Z0-9]+~\*/"), "", null, 0),
234246
// Insert scope borders.
235247
// auto added = new StringBuilder();
236248
// /*~sb~*/std::string added;
@@ -254,7 +266,7 @@ public class CSharpToCppTransformer : Transformer
254266
// Remove scope borders.
255267
// /*~sb~*/
256268
//
257-
(new Regex(@"/\*~(?<pointer>[a-zA-Z0-9]+)~\*/"), "", null, 0),
269+
(new Regex(@"/\*~[a-zA-Z0-9]+~\*/"), "", null, 0),
258270
// Insert scope borders.
259271
// auto added = new HashSet<TElement>();
260272
// ~!added!~std::unordered_set<TElement> added;
@@ -273,7 +285,7 @@ public class CSharpToCppTransformer : Transformer
273285
// Remove scope borders.
274286
// ~!added!~
275287
//
276-
(new Regex(@"~!(?<pointer>[a-zA-Z0-9]+)!~"), "", null, 5),
288+
(new Regex(@"~![a-zA-Z0-9]+!~"), "", null, 5),
277289
// Insert scope borders.
278290
// auto random = new System.Random(0);
279291
// std::srand(0);
@@ -285,7 +297,7 @@ public class CSharpToCppTransformer : Transformer
285297
// Remove scope borders.
286298
// ~!random!~
287299
//
288-
(new Regex(@"~!(?<pointer>[a-zA-Z0-9]+)!~"), "", null, 5),
300+
(new Regex(@"~![a-zA-Z0-9]+!~"), "", null, 5),
289301
// Insert method body scope starts.
290302
// void PrintNodes(TElement node, StringBuilder sb, int level) {
291303
// void PrintNodes(TElement node, StringBuilder sb, int level) {/*method-start*/
@@ -332,8 +344,8 @@ public class CSharpToCppTransformer : Transformer
332344
// return &_elements[node];
333345
(new Regex(@"return ref ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9\*]+)\];"), "return &$1[$2];", null, 0),
334346
// null
335-
// NULL
336-
(new Regex(@"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)null(?<after>\W)"), "${before}NULL${after}", null, 10),
347+
// nullptr
348+
(new Regex(@"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)null(?<after>\W)"), "${before}nullptr{after}", null, 10),
337349
// default
338350
// 0
339351
(new Regex(@"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)default(?<after>\W)"), "${before}0${after}", null, 10),

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.5</VersionPrefix>
7+
<VersionPrefix>0.1.6</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>One NewLine is enough in static event rule substitution.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Using nullptr instead of NULL in C++. Added rule to support translation of .Invoke method of EventHandler. Small tweeks and fixes.</PackageReleaseNotes>
2828
</PropertyGroup>
2929

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

0 commit comments

Comments
 (0)