From 0bb0a4e4fc40384491a3e0f4ad8cd9e6a2e46d41 Mon Sep 17 00:00:00 2001 From: Rune Date: Thu, 28 May 2026 15:47:49 +0200 Subject: [PATCH] increase custamizability --- src/ClangC.bf | 4 ++-- src/Generator.bf | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/ClangC.bf b/src/ClangC.bf index 6547d0a..9faa11f 100644 --- a/src/ClangC.bf +++ b/src/ClangC.bf @@ -157,8 +157,8 @@ static class Program StreamWriter includeAll = scope .()..Create("clang-c.h"); for (let file in clangFiles) { - //if (system(scope $"curl -o {clangHeaders}/{file}.h https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/main/clang/include/clang-c/{file}.h") != 0) - // Runtime.FatalError(scope $"Failed to download clang-c/{file}"); + if (system(scope $"wget -O {clangHeaders}/{file}.h https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/main/clang/include/clang-c/{file}.h") != 0) + Runtime.FatalError(scope $"Failed to download clang-c/{file}"); includeAll.Write($"#include \n"); } } diff --git a/src/Generator.bf b/src/Generator.bf index d609505..5ee3860 100644 --- a/src/Generator.bf +++ b/src/Generator.bf @@ -169,6 +169,7 @@ abstract class Cpp2BeefGenerator case .FieldDecl: BeginCursor(cursor); FieldDecl(cursor); case .VarDecl: BeginCursor(cursor); VarDecl(cursor); + case .EnumConstantDecl: BeginCursor(cursor); EnumConstantDecl(cursor); case .MacroDefinition: if (Clang.Cursor_IsMacroFunctionLike(cursor) != 0) return; @@ -444,7 +445,8 @@ abstract class Cpp2BeefGenerator for (; i < file.Length && file[i].IsWhiteSpace; i++) outString.Append(file[i]); } - protected virtual void AllWhiteSpaceUntil(CXSourceLocation from, enum { NoNewLines, YesNewLines } newlineMode) + protected enum WhiteSpaceNewLineMode { NoNewLines, YesNewLines } + protected virtual void AllWhiteSpaceUntil(CXSourceLocation from, WhiteSpaceNewLineMode newlineMode) { StringView file; uint32 offset; @@ -779,7 +781,7 @@ abstract class Cpp2BeefGenerator str.Append(')'); } - protected void AccessSpecifier(CXCursor cursor) + protected virtual void AccessSpecifier(CXCursor cursor) { switch (Clang.GetCXXAccessSpecifier(cursor)) { @@ -790,6 +792,11 @@ abstract class Cpp2BeefGenerator } } + protected virtual bool IsEmptyStructOpaque(CXCursor cursor) + { + return true; + } + protected mixin BeginBody(CXCursor cursor) { fileInfo.prevEnd = GetCursorAnchor(cursor); @@ -817,6 +824,8 @@ abstract class Cpp2BeefGenerator switch (cursor.kind) { case .StructDecl, .UnionDecl, .ClassDecl: + if (!IsEmptyStructOpaque(cursor)) + fallthrough; str.Append(';'); default: str.Append(" {}"); @@ -1392,18 +1401,21 @@ abstract class Cpp2BeefGenerator { Self self = (.)Internal.UnsafeCastToObject(client_data); Runtime.Assert(cursor.kind == .EnumConstantDecl); - - self.BeginCursor(cursor); - self.WriteCustomAttributes(cursor); - self.GetNameInBindings(cursor, self.str); - self.WriteTokensAfterEquals(cursor); - //Clang.GetEnumConstantDeclValue(cursor).ToString(self.str); - self.str.Append(','); - + self.HandleCursor(cursor); return .Continue; }, Internal.UnsafeCastToPtr(this)); } + protected virtual void EnumConstantDecl(CXCursor cursor) + { + BeginCursor(cursor); + WriteCustomAttributes(cursor); + GetNameInBindings(cursor, str); + WriteTokensAfterEquals(cursor); + //Clang.GetEnumConstantDeclValue(cursor).ToString(str); + str.Append(','); + } + protected virtual void TypeAlias(CXCursor cursor) { CXType type;