Skip to content

Commit

Permalink
fix: Fix build after haiku/haiku@ba9a9ce
Browse files Browse the repository at this point in the history
- Only put top-level enums into the `Symbols` class. Otherwise, name
clashes may occur. Furthermore, it does not make sense to allow direct
access to nested enums in C# code, as they require entering the class
scope in the original C++ code.
- Add some regex hacks for mono/CppSharp#1822.

Everything should build again after
https://review.haiku-os.org/c/haiku/+/7377 gets merged into Haiku.
  • Loading branch information
trungnt2910 committed Jan 29, 2024
1 parent 21a33e6 commit 93eb74c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 14 additions & 0 deletions generator/HaikuApiGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group>)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);
}

Expand Down

0 comments on commit 93eb74c

Please sign in to comment.