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