Skip to content

Commit c260cb2

Browse files
committed
[C#] Version 0.2.18. Added support for conversion of implicit operators.
1 parent 4309dac commit c260cb2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ public class CSharpToCppTransformer : TextTransformer
313313
(new Regex(@"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)(struct|class) (?<type>[a-zA-Z0-9]+(<((?!\s*:\s*)[^{\n])+>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?<middle>((?!class|struct).|\n)+?)(?<toStringDeclaration>(?<access>(private|protected|public): )override const char\* ToString\(\))"), "${classDeclarationBegin}/*~${type}~*/${middle}${toStringDeclaration}", 0),
314314
// Inside the scope of ~!_exceptionsBag!~ replace:
315315
// public: override const char* ToString() { return ...; }
316-
// public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator << (std::ostream &out, const A &obj) { return out << (std::string)obj; }
317-
(new Regex(@"(?<scope>/\*~(?<type>[_a-zA-Z0-9<>:]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<type>~\*/)(.|\n))*?)(?<toStringDeclaration>\r?\n(?<indent>[ \t]*)(?<access>(private|protected|public): )override const char\* ToString\(\) (?<toStringMethodBody>{[^}\n]+}))"), "${scope}${separator}${before}" + Environment.NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment.NewLine + Environment.NewLine + "${indent}${access}friend std::ostream & operator << (std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }", 0),
316+
// public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator <<(std::ostream &out, const A &obj) { return out << (std::string)obj; }
317+
(new Regex(@"(?<scope>/\*~(?<type>[_a-zA-Z0-9<>:]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<type>~\*/)(.|\n))*?)(?<toStringDeclaration>\r?\n(?<indent>[ \t]*)(?<access>(private|protected|public): )override const char\* ToString\(\) (?<toStringMethodBody>{[^}\n]+}))"), "${scope}${separator}${before}" + Environment.NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment.NewLine + Environment.NewLine + "${indent}${access}friend std::ostream & operator <<(std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }", 0),
318318
// Remove scope borders.
319319
// /*~Range~*/
320320
//
@@ -471,14 +471,30 @@ public class CSharpToCppTransformer : TextTransformer
471471
// const std::string& message
472472
// const std::string& message/*~message~*/
473473
(new Regex(@"(?<before>\(| )(?<variableDefinition>(const )?((std::)?string&?|char\*) (?<variable>[_a-zA-Z0-9]+))(?<after>\W)"), "${before}${variableDefinition}/*~${variable}~*/${after}", 0),
474-
// Inside the scope of ~!message!~ replace:
474+
// Inside the scope of /*~message~*/ replace:
475475
// Platform::Converters::To<std::string>(message)
476476
// message
477477
(new Regex(@"(?<scope>/\*~(?<variable>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<variable>~\*/)(.|\n))*?)Platform::Converters::To<std::string>\(\k<variable>\)"), "${scope}${separator}${before}${variable}", 10),
478478
// Remove scope borders.
479479
// /*~ex~*/
480480
//
481481
(new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", 0),
482+
// Insert scope borders.
483+
// class Range<T> {
484+
// class Range<T> {/*~type~Range~*/
485+
(new Regex(@"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)(struct|class) (?<type>[a-zA-Z0-9]+(<((?!\s*:\s*)[^{\n])+>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)"), "${classDeclarationBegin}/*~type~${type}~*/", 0),
486+
// Inside the scope of /*~type~Range<T>~*/ insert inner scope and replace:
487+
// public: static implicit operator std::tuple<T, T>(Range<T> range)
488+
// public: operator std::tuple<T, T>(Range<T> range) {/*~variable~Range<T>~*/
489+
(new Regex(@"(?<scope>/\*~type~(?<type>[^~\n\*]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<type>~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (?<targetType>[^\(\n]+)\((?<argumentDeclaration>\k<type> (?<variable>[a-zA-Z0-9]+))(?<after>\)\s*\n?\s*{)"), "${scope}${separator}${before}${access}operator ${targetType}(${argumentDeclaration}${after}/*~variable~${variable}~*/", 10),
490+
// Inside the scope of /*~variable~range~*/ replace:
491+
// range.Minimum
492+
// this->Minimum
493+
(new Regex(@"(?<scope>{/\*~variable~(?<variable>[^~\n]+)~\*/)(?<separator>.|\n)(?<before>(?<beforeExpression>(?<bracket>{)|(?<-bracket>})|[^{}]|\n)*?)\k<variable>\.(?<field>[_a-zA-Z0-9]+)(?<after>(,|;|}| |\))(?<afterExpression>(?<bracket>{)|(?<-bracket>})|[^{}]|\n)*?})"), "${scope}${separator}${before}this->${field}${after}", 10),
494+
// Remove scope borders.
495+
// /*~ex~*/
496+
//
497+
(new Regex(@"/\*~[^~\n]+~[^~\n]+~\*/"), "", 0),
482498
}.Cast<ISubstitutionRule>().ToList();
483499

484500
public static readonly IList<ISubstitutionRule> LastStage = new List<SubstitutionRule>

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.2.17</VersionPrefix>
7+
<VersionPrefix>0.2.18</VersionPrefix>
88
<Authors>Konstantin Diachenko</Authors>
99
<TargetFrameworks>net472;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>Better support for strings translation.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Added support for conversion of implicit operators.</PackageReleaseNotes>
2828
</PropertyGroup>
2929

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

0 commit comments

Comments
 (0)