fix wrapper.cpp

This commit is contained in:
Rune
2026-03-06 18:39:22 +01:00
parent 09748b9eeb
commit 8766c55bbb

View File

@@ -279,27 +279,26 @@ abstract class Cpp2BeefGenerator
ParsingFailed ParsingFailed
} }
public Result<void, GenerationError> Generate(char8* headerPath, StringView wrapperPath) public Result<void, GenerationError> Generate(char8* headerPath, StringView wrapperPath = null)
{ {
unitMacros.Clear(); unitMacros.Clear();
fileInfos.Clear(); fileInfos.Clear();
lastRecordOrEnum = Clang.GetNullCursor(); lastRecordOrEnum = Clang.GetNullCursor();
wrapperWritter = scope .();
if (!wrapperPath.IsNull) if (!wrapperPath.IsNull)
{
wrapperWritter = scope:: .();
wrapperWritter.Create(wrapperPath); wrapperWritter.Create(wrapperPath);
else
wrapperWritter = null;
WrapperFilePath = wrapperPath; WrapperFilePath = wrapperPath;
wrapperBuf.Set(""" wrapperBuf.Set("""
#define private public #define private public
#define protected public #define protected public
#include < #include "
"""); """);
wrapperBuf.Append(headerPath); Path.GetFileName(.(headerPath), wrapperBuf);
wrapperBuf.Append(""" wrapperBuf.Append("""
> "
#include <stdint.h> #include <stdint.h>
template <typename T> template <typename T>
@@ -309,6 +308,10 @@ abstract class Cpp2BeefGenerator
{ {
"""); """);
FlushWrapper();
}
else
wrapperWritter = null;
let args = Args; let args = Args;
#if DEBUG #if DEBUG
@@ -1045,25 +1048,25 @@ abstract class Cpp2BeefGenerator
//TODO: move to custom utils //TODO: move to custom utils
/* // This formats the tokens instead of copying the format 1:1 /* // This formats the tokens instead of copying the format 1:1
const CXTokenKind Unary = (.)-1; * const CXTokenKind Unary = (.)-1;
var prevKind; * var prevKind;
for (let token in tokens) * for (let token in tokens)
{ * {
let spelling = ScopeCXString!(Clang.GetTokenSpelling(unit, token)); * let spelling = ScopeCXString!(Clang.GetTokenSpelling(unit, token));
let kind = Clang.GetTokenKind(token); * let kind = Clang.GetTokenKind(token);
token: switch (kind) * token: switch (kind)
{ * {
case .Keyword, .Identifier, .Literal: * case .Keyword, .Identifier, .Literal:
if (prevKind == .Keyword || prevKind == .Identifier || prevKind == .Punctuation) * if (prevKind == .Keyword || prevKind == .Identifier || prevKind == .Punctuation)
str.Append(' '); * str.Append(' ');
if (kind == .Identifier) do * if (kind == .Identifier) do
{ * {
var cursor = Clang.GetCursor(unit, Clang.GetTokenLocation(unit, token)); * var cursor = Clang.GetCursor(unit, Clang.GetTokenLocation(unit, token));
if (Clang.Cursor_IsNull(cursor) != 0) break; * if (Clang.Cursor_IsNull(cursor) != 0) break;
cursor = Clang.GetCursorDefinition(cursor); * cursor = Clang.GetCursorDefinition(cursor);
if (Clang.Cursor_IsNull(cursor) != 0) break; * if (Clang.Cursor_IsNull(cursor) != 0) break;
GetNameInBindings(cursor, str); * GetNameInBindings(cursor, str);
break token; * break token;
} }
str.Append(spelling); str.Append(spelling);
if (kind == .Literal && str.EndsWith("LL")) if (kind == .Literal && str.EndsWith("LL"))
@@ -1404,17 +1407,17 @@ abstract class Cpp2BeefGenerator
BeginBody!(cursor); BeginBody!(cursor);
//TODO //TODO
/*Clang.VisitChildren(cursor, (cursor, parent, client_data) => /*Clang.VisitChildren(cursor, (cursor, parent, client_data) =>
{ * {
Self self = (.)Internal.UnsafeCastToObject(client_data); * Self self = (.)Internal.UnsafeCastToObject(client_data);
switch (cursor.kind) * switch (cursor.kind)
{ * {
case .FieldDecl, .CXXMethod, .Constructor, .Destructor, .ConversionFunction, .FunctionDecl, .VarDecl, * case .FieldDecl, .CXXMethod, .Constructor, .Destructor, .ConversionFunction, .FunctionDecl, .VarDecl,
.FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl, .StructDecl, .ClassDecl, * .FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl, .StructDecl, .ClassDecl,
.UnionDecl, .EnumDecl, .TypeAliasDecl, .TypedefDecl: * .UnionDecl, .EnumDecl, .TypeAliasDecl, .TypedefDecl:
self.WriteComments(cursor); * self.WriteComments(cursor);
return .Break; * return .Break;
default: * default:
return .Continue; * return .Continue;
} }
}, Internal.UnsafeCastToPtr(this));*/ }, Internal.UnsafeCastToPtr(this));*/
@@ -1442,12 +1445,12 @@ abstract class Cpp2BeefGenerator
str.Append(">\";\n", cursorIndent); str.Append(">\";\n", cursorIndent);
str.Append("private const String __template_chain = CppWrapperF($\"", wrapperTemplateChain, "\");\n\n", cursorIndent); str.Append("private const String __template_chain = CppWrapperF($\"", wrapperTemplateChain, "\");\n\n", cursorIndent);
/*str.Append("[CppWriteToWrapper<\"", WrapperFilePath, "\">(\"\\ntemplate "); /*str.Append("[CppWriteToWrapper<\"", WrapperFilePath, "\">(\"\\ntemplate ");
switch (cursor.kind) * switch (cursor.kind)
{ * {
case .StructDecl: str.Append("struct "); * case .StructDecl: str.Append("struct ");
case . ClassDecl: str.Append("class " ); * case . ClassDecl: str.Append("class " );
case . UnionDecl: str.Append("union " ); * case . UnionDecl: str.Append("union " );
default: Runtime.FatalError(); * default: Runtime.FatalError();
} }
str.Append("\" + __cpp_type + \";\\n\")]\n\n", indent);*/ str.Append("\" + __cpp_type + \";\\n\")]\n\n", indent);*/
} }