@@ -164,7 +164,7 @@ public class CSharpToCppTransformer : TextTransformer
164164 // interface IDisposable { ... }
165165 // interface IDisposable {/*~start~interface~IDisposable~*/ ... /*~end~interface~IDisposable~*/}
166166 ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)interface[\t ]*(?<type>[a-zA-Z][a-zA-Z0-9]*(<[^<>\n]*>)?)[^{}]*{)(?<middle>(.|\n)*)(?<beforeEnd>(?<=\r?\n)\k<indent>)(?<end>})" ) , "${classDeclarationBegin}/*~start~interface~${type}~*/${middle}${beforeEnd}/*~end~interface~${type}~*/${end}" , 0 ) ,
167- // Inside scopes replace:
167+ // Inside the scope replace:
168168 // /*~start~interface~IDisposable~*/ ... bool IsDisposed { get; } ... /*~end~interface~IDisposable~*/
169169 // /*~start~interface~IDisposable~*/ ... virtual bool IsDisposed() = 0; /*~end~interface~IDisposable~*/
170170 ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~interface~(?<type>[^~\n\*]+)~\*/)(.|\n)+?)(?<propertyDeclaration>(?<access>(private|protected|public): )?(?<propertyType>[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)+?(?<typeScopeEnd>/\*~end~interface~\k<type>~\*/))" ) , "${before}virtual ${propertyType} ${property}() = 0;${after}" , 20 ) ,
@@ -563,7 +563,7 @@ public class CSharpToCppTransformer : TextTransformer
563563 // class Range<T> { ... };
564564 // class Range<T> {/*~start~type~Range<T>~T~*/ ... /*~end~type~Range<T>~T~*/};
565565 ( 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 ]*{)(?<middle>(.|\n)*)(?<endIndent>(?<=\r?\n)\k<indent>)(?<end>};)" ) , "${classDeclarationBegin}/*~start~type~${type}~${typeParameter}~*/${middle}${endIndent}/*~end~type~${type}~${typeParameter}~*/${end}" , 0 ) ,
566- // Inside scopes replace:
566+ // Inside the scope replace:
567567 // /*~start~namespace~Platform::Ranges~*/ ... /*~start~type~Range<T>~T~*/ ... public: override std::int32_t GetHashCode() { return {Minimum, Maximum}.GetHashCode(); } ... /*~end~type~Range<T>~T~*/ ... /*~end~namespace~Platform::Ranges~*/
568568 // /*~start~namespace~Platform::Ranges~*/ ... /*~start~type~Range<T>~T~*/ ... /*~end~type~Range<T>~T~*/ ... /*~end~namespace~Platform::Ranges~*/ namespace std { template <typename T> struct hash<Platform::Ranges::Range<T>> { std::size_t operator()(const Platform::Ranges::Range<T> &obj) const { return {Minimum, Maximum}.GetHashCode(); } }; }
569569 ( new Regex ( @"(?<namespaceScopeStart>/\*~start~namespace~(?<namespace>[^~\n\*]+)~\*/)(?<betweenStartScopes>(.|\n)+)(?<typeScopeStart>/\*~start~type~(?<type>[^~\n\*]+)~(?<typeParameter>[^~\n\*]+)~\*/)(?<before>(.|\n)+?)(?<hashMethodDeclaration>\r?\n[ \t]*(?<access>(private|protected|public): )override std::int32_t GetHashCode\(\)(\s|\n)*{\s*(?<methodBody>[^\s][^\n]+[^\s])\s*}\s*)(?<after>(.|\n)+?)(?<typeScopeEnd>/\*~end~type~\k<type>~\k<typeParameter>~\*/)(?<betweenEndScopes>(.|\n)+)(?<namespaceScopeEnd>/\*~end~namespace~\k<namespace>~\*/)}\r?\n" ) , "${namespaceScopeStart}${betweenStartScopes}${typeScopeStart}${before}${after}${typeScopeEnd}${betweenEndScopes}${namespaceScopeEnd}}" + Environment . NewLine + Environment . NewLine + "namespace std" + Environment . NewLine + "{" + Environment . NewLine + " template <typename ${typeParameter}>" + Environment . NewLine + " struct hash<${namespace}::${type}>" + Environment . NewLine + " {" + Environment . NewLine + " std::size_t operator()(const ${namespace}::${type} &obj) const" + Environment . NewLine + " {" + Environment . NewLine + " /*~start~method~*/${methodBody}/*~end~method~*/" + Environment . NewLine + " }" + Environment . NewLine + " };" + Environment . NewLine + "}" + Environment . NewLine , 10 ) ,
@@ -582,22 +582,45 @@ public class CSharpToCppTransformer : TextTransformer
582582 // class Disposable<T> : public Disposable<> { ... };
583583 // class Disposable<T> : public Disposable<> {/*~start~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/ ... /*~end~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/};
584584 ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)template[\t ]*<(?<typeParameters>[^\n]*)>[\t ]*(struct|class)[\t ]+(?<fullType>(?<type>[a-zA-Z][a-zA-Z0-9]*)(<[^<>\n]*>)?)[\t ]*:[\t ]*(?<access>(private|protected|public)[\t ]+)?(?<fullBaseType>(?<baseType>[a-zA-Z][a-zA-Z0-9]*)(<[^<>\n]*>)?)[\t ]*(\r?\n)?[\t ]*{)(?<middle>(.|\n)*)(?<beforeEnd>(?<=\r?\n)\k<indent>)(?<end>};)" ) , "${classDeclarationBegin}/*~start~type~${type}~${fullType}~${baseType}~${fullBaseType}~*/${middle}${beforeEnd}/*~end~type~${type}~${fullType}~${baseType}~${fullBaseType}~*/${end}" , 0 ) ,
585- // Inside scopes replace:
585+ // Inside the scope replace:
586586 // /*~start~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/ ... ) : base( ... /*~end~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/
587587 // /*~start~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/ ... ) : Disposable<>( /*~end~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/
588- ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~type~(?<types>(?<type>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\k<type>~(?<fullBaseType>[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)* base(?<after>\((.|\n)+?(?<typeScopeEnd>/\*~end~type~\k<types>~\*/))" ) , "${before}${fullBaseType}${after}" , 20 ) ,
589- // Inside scopes replace:
588+ ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~type~(?<types>(?<type>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\k<type>~(?<fullBaseType>[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)base(?<after>\((.|\n)+?(?<typeScopeEnd>/\*~end~type~\k<types>~\*/))" ) , "${before}${fullBaseType}${after}" , 20 ) ,
589+ // Inside the scope replace:
590590 // /*~start~type~Disposable~Disposable<T>~X~X<>~*/ ... ) : base( ... /*~end~type~Disposable~Disposable<T>~X~X<>~*/
591591 // /*~start~type~Disposable~Disposable<T>~X~X<>~*/ ... ) : X( /*~end~type~Disposable~Disposable<T>~X~X<>~*/
592- ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~type~(?<types>(?<type>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~(?<baseType>[^~\n\*]+)~(?<fullBaseType>[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)* base(?<after>\((.|\n)+?(?<typeScopeEnd>/\*~end~type~\k<types>~\*/))" ) , "${before}${baseType}${after}" , 20 ) ,
593- // Inside scopes replace:
592+ ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~type~(?<types>(?<type>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~(?<baseType>[^~\n\*]+)~(?<fullBaseType>[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)base(?<after>\((.|\n)+?(?<typeScopeEnd>/\*~end~type~\k<types>~\*/))" ) , "${before}${baseType}${after}" , 20 ) ,
593+ // Inside the scope replace:
594594 // /*~start~type~Disposable~Disposable<T>~X~X<>~*/ ... public: Disposable(T object) { Object = object; } ... public: Disposable(T object) : Disposable(object) { } ... /*~end~type~Disposable~Disposable<T>~X~X<>~*/
595595 // /*~start~type~Disposable~Disposable<T>~X~X<>~*/ ... public: Disposable(T object) { Object = object; } /*~end~type~Disposable~Disposable<T>~X~X<>~*/
596- ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~type~(?<types>(?<type>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~(?<baseType>[^~\n\*]+)~(?<fullBaseType>[^~\n\*]+))~\*/)(.|\n)+?(?<constructor>(?<access>(private|protected|public):[\t ]*)?\k<type>\((?<arguments>[^()\n]+)\)\s*{[^{}\n]+})(.|\n)+?)* (?<duplicateConstructor>(?<access>(private|protected|public):[\t ]*)?\k<type>\(\k<arguments>\)\s*:[^{}\n]+\s*{[^{}\n]+})(?<after>(.|\n)+?(?<typeScopeEnd>/\*~end~type~\k<types>~\*/))" ) , "${before}${after}" , 20 ) ,
596+ ( new Regex ( @"(?<before>(?<typeScopeStart>/\*~start~type~(?<types>(?<type>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~(?<baseType>[^~\n\*]+)~(?<fullBaseType>[^~\n\*]+))~\*/)(.|\n)+?(?<constructor>(?<access>(private|protected|public):[\t ]*)?\k<type>\((?<arguments>[^()\n]+)\)\s*{[^{}\n]+})(.|\n)+?)(?<duplicateConstructor>(?<access>(private|protected|public):[\t ]*)?\k<type>\(\k<arguments>\)\s*:[^{}\n]+\s*{[^{}\n]+})(?<after>(.|\n)+?(?<typeScopeEnd>/\*~end~type~\k<types>~\*/))" ) , "${before}${after}" , 20 ) ,
597597 // Remove scope borders.
598598 // /*~start~type~Disposable~Disposable<T>~Disposable~Disposable<>~*/
599599 //
600600 ( new Regex ( @"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/" ) , "" , 0 ) ,
601+ // Insert scope borders.
602+ // private: inline static const AppDomain _currentDomain = AppDomain.CurrentDomain;
603+ // private: inline static const AppDomain _currentDomain = AppDomain.CurrentDomain;/*~app-domain~_currentDomain~*/
604+ ( new Regex ( @"(?<declaration>(?<access>(private|protected|public):[\t ]*)?(inline[\t ]+)?(static[\t ]+)?(const[\t ]+)?AppDomain[\t ]+(?<field>[a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*AppDomain\.CurrentDomain;)" ) , "${declaration}/*~app-domain~${field}~*/" , 0 ) ,
605+ // Inside the scope replace:
606+ // /*~app-domain~_currentDomain~*/ ... _currentDomain.ProcessExit += OnProcessExit;
607+ // /*~app-domain~_currentDomain~*/ ... std::atexit(OnProcessExit);
608+ ( new Regex ( @"(?<before>(?<fieldScopeStart>/\*~app-domain~(?<field>[^~\n\*]+)~\*/)(.|\n)+?)\k<field>\.ProcessExit[\t ]*\+=[\t ]*(?<eventHandler>[a-zA-Z_][a-zA-Z0-9_]*);" ) , "${before}std::atexit(${eventHandler});/*~process-exit-handler~${eventHandler}~*/" , 20 ) ,
609+ // Inside the scope replace:
610+ // /*~app-domain~_currentDomain~*/ ... _currentDomain.ProcessExit -= OnProcessExit;
611+ // /*~app-domain~_currentDomain~*/ ... /* No translation. It is not possible to unsubscribe from std::atexit. */
612+ ( new Regex ( @"(?<before>(?<fieldScopeStart>/\*~app-domain~(?<field>[^~\n\*]+)~\*/)(.|\n)+?\r?\n[\t ]*)\k<field>\.ProcessExit[\t ]*\-=[\t ]*(?<eventHandler>[a-zA-Z_][a-zA-Z0-9_]*);" ) , "${before}/* No translation. It is not possible to unsubscribe from std::atexit. */" , 20 ) ,
613+ // Inside the scope replace:
614+ // /*~process-exit-handler~OnProcessExit~*/ ... static void OnProcessExit(void *sender, EventArgs e)
615+ // /*~process-exit-handler~OnProcessExit~*/ ... static void OnProcessExit()
616+ ( new Regex ( @"(?<before>(?<fieldScopeStart>/\*~process-exit-handler~(?<handler>[^~\n\*]+)~\*/)(.|\n)+?static[\t ]+void[\t ]+\k<handler>\()[^()\n]+\)" ) , "${before})" , 20 ) ,
617+ // Remove scope borders.
618+ // /*~app-domain~_currentDomain~*/
619+ //
620+ ( new Regex ( @"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/" ) , "" , 0 ) ,
621+ // AppDomain.CurrentDomain.ProcessExit -= OnProcessExit;
622+ // /* No translation. It is not possible to unsubscribe from std::atexit. */
623+ ( new Regex ( @"AppDomain\.CurrentDomain\.ProcessExit -= ([a-zA-Z_][a-zA-Z0-9_]*);" ) , "/* No translation. It is not possible to unsubscribe from std::atexit. */" , 0 ) ,
601624 } . Cast < ISubstitutionRule > ( ) . ToList ( ) ;
602625
603626 public static readonly IList < ISubstitutionRule > LastStage = new List < SubstitutionRule >
0 commit comments