@@ -144,19 +144,31 @@ public class CSharpToCppTransformer : TextTransformer
144144 ( new Regex ( @"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);" ) , "$1$2$3$4$5$6$7$8($9) { return $10; }" , 0 ) ,
145145 // OnDispose = (manual, wasDisposed) =>
146146 // OnDispose = [&](auto manual, auto wasDisposed)
147- ( new Regex ( @"(?<variable>[a-zA-Z_][a-zA-Z0-9_]*)(?<operator>\s*=\s*)\((?<firstArgument>[a-zA-Z_][a-zA-Z0-9_]*), (?<secondArgument>[a-zA-Z_][a-zA-Z0-9_]*)\)\s*=>" ) , "${variable}${operator}[&](auto ${firstArgument}, auto ${secondArgument})" , 0 ) ,
147+ ( new Regex ( @"(?<variable>[a-zA-Z_][a-zA-Z0-9_]*)(?<operator>\s*\+? =\s*)\((?<firstArgument>[a-zA-Z_][a-zA-Z0-9_]*), (?<secondArgument>[a-zA-Z_][a-zA-Z0-9_]*)\)\s*=>" ) , "${variable}${operator}[&](auto ${firstArgument}, auto ${secondArgument})" , 0 ) ,
148148 // () => Integer<TElement>.Zero,
149149 // () { return Integer<TElement>.Zero; },
150150 ( new Regex ( @"\(\)\s+=>\s+(?<expression>[^(),;\r\n]+(\(((?<parenthesis>\()|(?<-parenthesis>\))|[^();\r\n]*?)*?\))?[^(),;\r\n]*)(?<after>,|\);)" ) , "() { return ${expression}; }${after}" , 0 ) ,
151+ // ~DisposableBase() => Destruct();
152+ // ~DisposableBase() { Destruct(); }
153+ ( new Regex ( @"~(?<class>[a-zA-Z_][a-zA-Z0-9_]*)\(\)\s+=>\s+([^;\r\n]+?);" ) , "~${class}() { $1; }" , 0 ) ,
151154 // => Integer<TElement>.Zero;
152155 // { return Integer<TElement>.Zero; }
153156 ( new Regex ( @"\)\s+=>\s+([^;\r\n]+?);" ) , ") { return $1; }" , 0 ) ,
154157 // () { return avlTree.Count; }
155158 // [&]()-> auto { return avlTree.Count; }
156159 ( new Regex ( @"(?<before>, |\()\(\) { return (?<expression>[^;\r\n]+); }" ) , "${before}[&]()-> auto { return ${expression}; }" , 0 ) ,
157160 // Count => GetSizeOrZero(Root);
158- // GetCount() { return GetSizeOrZero(Root); }
159- ( new Regex ( @"(\W)([A-Z][a-zA-Z]+)\s+=>\s+([^;\r\n]+);" ) , "$1Get$2() { return $3; }" , 0 ) ,
161+ // Count() { return GetSizeOrZero(Root); }
162+ ( new Regex ( @"(\W)([A-Z][a-zA-Z]+)\s+=>\s+([^;\r\n]+);" ) , "$1$2() { return $3; }" , 0 ) ,
163+ // public: T Object { get; }
164+ // public: const T Object;
165+ ( new Regex ( @"(?<before>[^\r]\r?\n[ \t]*)(?<access>(private|protected|public): )?(?<type>[a-zA-Z_][a-zA-Z0-9_:<>]*) (?<property>[a-zA-Z_][a-zA-Z0-9_]*)(?<blockOpen>[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get;(?<blockClose>[\n\s]*})(?<after>[\n\s]*)" ) , "${before}${access}const ${type} ${property};${after}" , 2 ) ,
166+ // public: bool IsDisposed { get => _disposed > 0; }
167+ // public: bool IsDisposed() { return _disposed > 0; }
168+ ( new Regex ( @"(?<before>[^\r]\r?\n[ \t]*)(?<access>(private|protected|public): )?(?<virtual>virtual )?bool (?<property>[a-zA-Z_][a-zA-Z0-9_]*)(?<blockOpen>[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get\s*=>\s*(?<expression>[^\n]+);(?<blockClose>[\n\s]*}[\n\s]*)" ) , "${before}${access}${virtual}bool ${property}()${blockOpen}return ${expression};${blockClose}" , 2 ) ,
169+ // protected: virtual std::string ObjectName { get => GetType().Name; }
170+ // protected: virtual std::string ObjectName() { return GetType().Name; }
171+ ( new Regex ( @"(?<before>[^\r]\r?\n[ \t]*)(?<access>(private|protected|public): )?(?<virtual>virtual )?(?<type>[a-zA-Z_][a-zA-Z0-9_:<>]*) (?<property>[a-zA-Z_][a-zA-Z0-9_]*)(?<blockOpen>[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get\s*=>\s*(?<expression>[^\n]+);(?<blockClose>[\n\s]*}[\n\s]*)" ) , "${before}${access}${virtual}${type} ${property}()${blockOpen}return ${expression};${blockClose}" , 2 ) ,
160172 // ArgumentInRange(string message) { string messageBuilder() { return message; }
161173 // ArgumentInRange(string message) { auto messageBuilder = [&]() -> string { return message; };
162174 ( new Regex ( @"(?<before>\W[_a-zA-Z0-9]+\([^\)\n]*\)[\s\n]*{[\s\n]*([^{}]|\n)*?(\r?\n)?[ \t]*)(?<returnType>[_a-zA-Z0-9*:]+[_a-zA-Z0-9*: ]*) (?<methodName>[_a-zA-Z0-9]+)\((?<arguments>[^\)\n]*)\)\s*{(?<body>(""[^""\n]+""|[^}]|\n)+?)}" ) , "${before}auto ${methodName} = [&]() -> ${returnType} {${body}};" , 10 ) ,
@@ -166,9 +178,18 @@ public class CSharpToCppTransformer : TextTransformer
166178 // Action<TElement> free
167179 // std::function<void(TElement)> free
168180 ( new Regex ( @"Action<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)" ) , "std::function<void($1)> $2" , 0 ) ,
181+ // Action<TPrimary, TAuxiliary> action
182+ // std::function<void(TPrimary, TAuxiliary)> action
183+ ( new Regex ( @"Action<([a-zA-Z0-9]+), ([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)" ) , "std::function<void($1, $2)> $3" , 0 ) ,
184+ // , Action<TPrimary, TAuxiliary>>
185+ // , std::function<void(TPrimary, TAuxiliary)>>
186+ ( new Regex ( @"(, )Action<([a-zA-Z0-9]+), ([a-zA-Z0-9]+)>(>)" ) , "$1std::function<void($2, $3)>$4" , 0 ) ,
169187 // Action action
170188 // std::function<void()> action
171189 ( new Regex ( @"Action ([a-zA-Z0-9]+)" ) , "std::function<void()> $1" , 0 ) ,
190+ // , Action>
191+ // ,std::function<void()>>
192+ ( new Regex ( @"(, )Action(>)" ) , "$1std::function<void()>$2" , 0 ) ,
172193 // Predicate<TArgument> predicate
173194 // std::function<bool(TArgument)> predicate
174195 ( new Regex ( @"Predicate<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)" ) , "std::function<bool($1)> $2" , 0 ) ,
@@ -466,6 +487,9 @@ public class CSharpToCppTransformer : TextTransformer
466487 // /*~ex~*/
467488 //
468489 ( new Regex ( @"/\*~[_a-zA-Z0-9]+~\*/" ) , "" , 0 ) ,
490+ // throw ObjectDisposedException(objectName, message);
491+ // throw std::runtime_error(std::string("Attempt to access disposed object [").append(objectName).append("]: ").append(message).append("."));
492+ ( new Regex ( @"throw ObjectDisposedException\((?<objectName>[a-zA-Z_][a-zA-Z0-9_]*), (?<message>[a-zA-Z0-9_]*[Mm]essage[a-zA-Z0-9_]*(\(\))?|[a-zA-Z_][a-zA-Z0-9_]*)\);" ) , "throw std::runtime_error(std::string(\" Attempt to access disposed object [\" ).append(${objectName}).append(\" ]: \" ).append(${message}).append(\" .\" ));" , 0 ) ,
469493 // throw ArgumentNullException(argumentName, message);
470494 // throw std::invalid_argument(std::string("Argument ").append(argumentName).append(" is null: ").append(message).append("."));
471495 ( new Regex ( @"throw ArgumentNullException\((?<argument>[a-zA-Z]*[Aa]rgument[a-zA-Z]*), (?<message>[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?)\);" ) , "throw std::invalid_argument(std::string(\" Argument \" ).append(${argument}).append(\" is null: \" ).append(${message}).append(\" .\" ));" , 0 ) ,
@@ -508,15 +532,15 @@ public class CSharpToCppTransformer : TextTransformer
508532 // Insert scope borders.
509533 // class Range<T> {
510534 // class Range<T> {/*~type~Range<T>~*/
511- ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)template <typename (?<typeParameter>[^ \n]+)> (struct|class) (?<type> [a-zA-Z0-9]+<\k<typeParameter>>) (\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)" ) , "${classDeclarationBegin}/*~type~${type }~*/" , 0 ) ,
535+ ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)( template\s*<[^<> \n]*> )? (struct|class) (?<fullType>(?<typeName> [a-zA-Z0-9]+)(<[^:\n]*>)?) (\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)" ) , "${classDeclarationBegin}/*~type~${typeName}~${fullType }~*/" , 0 ) ,
512536 // Inside the scope of /*~type~Range<T>~*/ insert inner scope and replace:
513537 // public: static implicit operator std::tuple<T, T>(Range<T> range)
514538 // public: operator std::tuple<T, T>() const {/*~variable~Range<T>~*/
515- ( 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}() const${after}/*~variable~${variable}~*/" , 10 ) ,
539+ ( new Regex ( @"(?<scope>/\*~type~(?<typeName >[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\* /)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<typeName >~\k<fullType>~\ */)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (?<targetType>[^\(\n]+)\((?<argumentDeclaration>\k<fullType > (?<variable>[a-zA-Z0-9]+))\)(?<after>\s*\n?\s*{)" ) , "${scope}${separator}${before}${access}operator ${targetType}() const${after}/*~variable~${variable}~*/" , 10 ) ,
516540 // Inside the scope of /*~type~Range<T>~*/ replace:
517541 // public: static implicit operator Range<T>(std::tuple<T, T> tuple) { return new Range<T>(std::get<1-1>(tuple), std::get<2-1>(tuple)); }
518542 // public: Range(std::tuple<T, T> tuple) : Range(std::get<1-1>(tuple), std::get<2-1>(tuple)) { }
519- ( new Regex ( @"(?<scope>/\*~type~(?<type>(?< typeName>[_a-zA-Z0-9 ]+)[^~\n\*]* )~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<type >~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator \k<type>\ ((?<arguments>[^{}\n]+)\)(\s|\n)*{(\s|\n)*return (new )?\k<type> \((?<passedArguments>[^\n]+)\);(\s|\n)*}" ) , "${scope}${separator}${before}${access}${typeName}(${arguments}) : ${typeName}(${passedArguments}) { }" , 10 ) ,
543+ ( new Regex ( @"(?<scope>/\*~type~(?<typeName>[^~\n\* ]+)~(?<fullType> [^~\n\*]+ )~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<typeName >~\k<fullType>~\ */)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator ( \k<fullType>|\k<typeName>)\ ((?<arguments>[^{}\n]+)\)(\s|\n)*{(\s|\n)*return (new )?( \k<fullType>|\k<typeName>) \((?<passedArguments>[^\n]+)\);(\s|\n)*}" ) , "${scope}${separator}${before}${access}${typeName}(${arguments}) : ${typeName}(${passedArguments}) { }" , 10 ) ,
520544 // Inside the scope of /*~variable~range~*/ replace:
521545 // range.Minimum
522546 // this->Minimum
@@ -594,6 +618,9 @@ public class CSharpToCppTransformer : TextTransformer
594618 // @object
595619 // object
596620 ( new Regex ( @"@([_a-zA-Z0-9]+)" ) , "$1" , 0 ) ,
621+ // this->GetType().Name
622+ // typeid(this).name()
623+ ( new Regex ( @"(this)->GetType\(\)\.Name" ) , "typeid($1).name()" , 0 ) ,
597624 // ArgumentNullException
598625 // std::invalid_argument
599626 ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(System\.)?ArgumentNullException(?<after>\W)" ) , "${before}std::invalid_argument${after}" , 10 ) ,
0 commit comments