@@ -228,10 +228,44 @@ public class CSharpToCppTransformer : Transformer
228228 // auto path = new TElement[MaxPath];
229229 // TElement path[MaxPath] = { {0} };
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 ) ,
231+ // private: static readonly ConcurrentBag<std::exception> _exceptionsBag = new ConcurrentBag<std::exception>();
232+ // private: static std::mutex _exceptionsBag_mutex; \n\n private: static std::vector<std::exception> _exceptionsBag;
233+ ( new Regex ( @"(?<begin>\r?\n?(?<indent>[ \t]+))(?<access>(private|protected|public): )?static readonly ConcurrentBag<(?<argumentType>[^;\r\n]+)> (?<name>[_a-zA-Z0-9]+) = new ConcurrentBag<\k<argumentType>>\(\);" ) , "${begin}private: static std::mutex ${name}_mutex;" + Environment . NewLine + Environment . NewLine + "${indent}${access}static std::vector<${argumentType}> ${name};" , null , 0 ) ,
234+ // public: static IReadOnlyCollection<std::exception> GetCollectedExceptions() { return _exceptionsBag; }
235+ // public: static std::vector<std::exception> GetCollectedExceptions() { return std::vector<std::exception>(_exceptionsBag); }
236+ ( new Regex ( @"(?<access>(private|protected|public): )?static IReadOnlyCollection<(?<argumentType>[^;\r\n]+)> (?<methodName>[_a-zA-Z0-9]+)\(\) { return (?<fieldName>[_a-zA-Z0-9]+); }" ) , "${access}static std::vector<${argumentType}> ${methodName}() { return std::vector<${argumentType}>(${fieldName}); }" , null , 0 ) ,
231237 // public: static event EventHandler<std::exception> ExceptionIgnored = OnExceptionIgnored; ... };
232238 // ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored; };
233239 ( 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 + Environment . NewLine + "${halfIndent}${halfIndent}${access}static inline Platform::Delegates::MulticastDelegate<void(void*, const ${argumentType}&)> ${name} = ${defaultDelegate};${end}" , null , 0 ) ,
234240 // Insert scope borders.
241+ // class IgnoredExceptions { ... private: static std::vector<std::exception> _exceptionsBag;
242+ // class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: static std::vector<std::exception> _exceptionsBag;
243+ ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?<middle>((?!class).|\n)+?)(?<vectorFieldDeclaration>(?<access>(private|protected|public): )static std::vector<(?<argumentType>[^;\r\n]+)> (?<fieldName>[_a-zA-Z0-9]+);)" ) , "${classDeclarationBegin}/*~${fieldName}~*/${middle}${vectorFieldDeclaration}" , null , 0 ) ,
244+ // Inside the scope of ~!_exceptionsBag!~ replace:
245+ // _exceptionsBag.Add(exception);
246+ // _exceptionsBag.push_back(exception);
247+ ( new Regex ( @"(?<scope>/\*~(?<fieldName>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<fieldName>~\*/)(.|\n))*?)\k<fieldName>\.Add" ) , "${scope}${separator}${before}${fieldName}.push_back" , null , 10 ) ,
248+ // Remove scope borders.
249+ // /*~_exceptionsBag~*/
250+ //
251+ ( new Regex ( @"/\*~[_a-zA-Z0-9]+~\*/" ) , "" , null , 0 ) ,
252+ // Insert scope borders.
253+ // class IgnoredExceptions { ... private: static std::mutex _exceptionsBag_mutex;
254+ // class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: static std::mutex _exceptionsBag_mutex;
255+ ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?<middle>((?!class).|\n)+?)(?<mutexDeclaration>private: static std::mutex (?<fieldName>[_a-zA-Z0-9]+)_mutex;)" ) , "${classDeclarationBegin}/*~${fieldName}~*/${middle}${mutexDeclaration}" , null , 0 ) ,
256+ // Inside the scope of ~!_exceptionsBag!~ replace:
257+ // return std::vector<std::exception>(_exceptionsBag);
258+ // std::lock_guard<std::mutex> guard(_exceptionsBag_mutex); return std::vector<std::exception>(_exceptionsBag);
259+ ( new Regex ( @"(?<scope>/\*~(?<fieldName>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<fieldName>~\*/)(.|\n))*?){(?<after>((?!lock_guard)[^{};\r\n])*\k<fieldName>[^;}\r\n]*;)" ) , "${scope}${separator}${before}{ std::lock_guard<std::mutex> guard(${fieldName}_mutex);${after}" , null , 10 ) ,
260+ // Inside the scope of ~!_exceptionsBag!~ replace:
261+ // _exceptionsBag.Add(exception);
262+ // std::lock_guard<std::mutex> guard(_exceptionsBag_mutex); \r\n _exceptionsBag.Add(exception);
263+ ( new Regex ( @"(?<scope>/\*~(?<fieldName>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<fieldName>~\*/)(.|\n))*?){(?<after>((?!lock_guard)([^{};]|\n))*?\r?\n(?<indent>[ \t]*)\k<fieldName>[^;}\r\n]*;)" ) , "${scope}${separator}${before}{" + Environment . NewLine + "${indent}std::lock_guard<std::mutex> guard(${fieldName}_mutex);${after}" , null , 10 ) ,
264+ // Remove scope borders.
265+ // /*~_exceptionsBag~*/
266+ //
267+ ( new Regex ( @"/\*~[_a-zA-Z0-9]+~\*/" ) , "" , null , 0 ) ,
268+ // Insert scope borders.
235269 // class IgnoredExceptions { ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored;
236270 // class IgnoredExceptions {/*~ExceptionIgnored~*/ ... public: static inline Platform::Delegates::MulticastDelegate<void(void*, const std::exception&)> ExceptionIgnored = OnExceptionIgnored;
237271 ( 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 ) ,
0 commit comments