Skip to content

Commit d20947b

Browse files
committed
Added new rules to support translation of Interfaces.
1 parent 6cbcbd5 commit d20947b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs

+15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class CSharpToCppTransformer : Transformer
2323
// Platform.Collections.Methods.Lists
2424
// Platform::Collections::Methods::Lists
2525
(new Regex(@"(namespace[^\r\n]+?)\.([^\r\n]+?)"), "$1::$2", null, 20),
26+
// out TProduct
27+
// TProduct
28+
(new Regex(@"(?<before>(<|, ))(in|out) (?<typeParameter>[a-zA-Z0-9]+)(?<after>(>|,))"), "${before}${typeParameter}${after}", null, 10),
2629
// public abstract class
2730
// class
2831
(new Regex(@"(public abstract|static) class"), "class", null, 0),
@@ -35,6 +38,12 @@ public class CSharpToCppTransformer : Transformer
3538
// static void TestMultipleCreationsAndDeletions<TElement>(SizedBinaryTreeMethodsBase<TElement> tree, TElement* root)
3639
// template<typename T> static void TestMultipleCreationsAndDeletions<TElement>(SizedBinaryTreeMethodsBase<TElement> tree, TElement* root)
3740
(new Regex(@"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)]+)\)"), "template <typename $3> static $1 $2($4)", null, 0),
41+
// interface IFactory<out TProduct> {
42+
// template <typename TProduct> class IFactory { public:
43+
(new Regex(@"interface (?<interface>[a-zA-Z0-9]+)<(?<typeParameters>[a-zA-Z0-9 ,]+)>(?<whitespace>[^{]+){"), "template <typename ${typeParameters}> class ${interface}${whitespace}{" + Environment.NewLine + " public:", null, 0),
44+
// template <typename TObject, TProperty, TValue>
45+
// template <typename TObject, typename TProperty, TValue>
46+
(new Regex(@"(?<before>template <((, )?typename [a-zA-Z0-9]+)+, )(?<typeParameter>[a-zA-Z0-9]+)(?<after>(,|>))"), "${before}typename ${typeParameter}${after}", null, 10),
3847
// (this
3948
// (
4049
(new Regex(@"\(this "), "(", null, 0),
@@ -53,6 +62,9 @@ public class CSharpToCppTransformer : Transformer
5362
// protected abstract TElement GetFirst();
5463
// virtual TElement GetFirst() = 0;
5564
(new Regex(@"protected abstract ([^;]+);"), "virtual $1 = 0;", null, 0),
65+
// protected abstract TElement GetFirst();
66+
// virtual TElement GetFirst() = 0;
67+
(new Regex(@"([a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)]*\));"), "virtual $1 = 0;", null, 0),
5668
// public virtual
5769
// virtual
5870
(new Regex(@"public virtual"), "virtual", null, 0),
@@ -128,6 +140,9 @@ public class CSharpToCppTransformer : Transformer
128140
// class SizedBinaryTreeMethodsBase : GenericCollectionMethodsBase
129141
// class SizedBinaryTreeMethodsBase : public GenericCollectionMethodsBase
130142
(new Regex(@"class ([a-zA-Z0-9]+) : ([a-zA-Z0-9]+)"), "class $1 : public $2", null, 0),
143+
// class IProperty : ISetter<TValue, TObject>, IProvider<TValue, TObject>
144+
// class IProperty : public ISetter<TValue, TObject>, IProvider<TValue, TObject>
145+
(new Regex(@"(?<before>class [a-zA-Z0-9]+ : ((public [a-zA-Z0-9]+(<[a-zA-Z0-9 ,]+>)?, )+)?)(?<inheritedType>(?!public)[a-zA-Z0-9]+(<[a-zA-Z0-9 ,]+>)?)(?<after>(, [a-zA-Z0-9]+(?!>)|[ \r\n]+))"), "${before}public ${inheritedType}${after}", null, 10),
131146
// Insert scope borders.
132147
// ref TElement root
133148
// ~!root!~ref TElement root

0 commit comments

Comments
 (0)