diff --git a/generator/HaikuApiGenerator/Passes/ProcessConstantsAndEnumerationsPass.cs b/generator/HaikuApiGenerator/Passes/ProcessConstantsAndEnumerationsPass.cs index 47a2af6..b66b3b1 100644 --- a/generator/HaikuApiGenerator/Passes/ProcessConstantsAndEnumerationsPass.cs +++ b/generator/HaikuApiGenerator/Passes/ProcessConstantsAndEnumerationsPass.cs @@ -40,6 +40,11 @@ public override bool VisitEnumItemDecl(Enumeration.Item decl) goto skip; } + if (decl.Namespace.Namespace is Class) + { + goto skip; + } + var symbolsClass = GetSymbolsClass(decl); if (decl.Namespace == symbolsClass) { diff --git a/generator/HaikuApiGenerator/Program.cs b/generator/HaikuApiGenerator/Program.cs index c56b5bd..5146015 100644 --- a/generator/HaikuApiGenerator/Program.cs +++ b/generator/HaikuApiGenerator/Program.cs @@ -90,6 +90,20 @@ contents = Regex.Replace(contents, @"(_QuitDelegateHook\([^\)]*?\)[^}]*?\{[^}]*?(^\s*)[^}]*?BLooper[^}]*)(^\s+\})", "$1$2__target.__ownsNativeInstance = false;\n$2__target.Dispose(false, callNativeDtor: false );\n$3", RegexOptions.Multiline); + // Looks for `BAlignment` constructor calls affected by https://github.com/mono/CppSharp/issues/1822. + contents = Regex.Replace(contents, @"new global::Haiku\.Interface\.BAlignment\(B_([A-Za-z0-9_]*)[,\s]*B_([A-Za-z0-9_]*)\)", (match) => + { + // Then patch the enum items. + return Regex.Replace(match.Value, @"B_([A-Za-z0-9_]*)[,\s]*B_([A-Za-z0-9_]*)", (match1) => + { + var names = ((IList)match1.Groups).Skip(1).Select(g => string.Join("", + g.Value.Split('_') + .Select(token => token[0].ToString().ToUpperInvariant() + token[1..].ToLowerInvariant())) + ).ToArray(); + return $"global::Haiku.Interface.Alignment.{names[0]}, global::Haiku.Interface.VerticalAlignment.{names[1]}"; + }); + }); + File.WriteAllText(file, contents); }