fixing struct bug
This commit is contained in:
parent
46566f5244
commit
abf1f52643
3 changed files with 54 additions and 19 deletions
|
@ -10,10 +10,10 @@ class Binding
|
|||
public static List<BindingEnum> Enums = new .() ~ DeleteContainerAndItems!(_);
|
||||
public static List<BindingStruct> Structs = new .() ~ DeleteContainerAndItems!(_);
|
||||
public static BindingOptions Options = new .() ~ delete _;
|
||||
public static Dictionary<CXCursorKind, function void(CXCursor)> CursorHandlers = new .() {
|
||||
public static Dictionary<CXCursorKind, function void(CXCursor*)> CursorHandlers = new .() {
|
||||
(.CXCursor_FunctionDecl, => HandleFunctionDecl),
|
||||
(.CXCursor_StructDecl, => HandleStructDecl),
|
||||
//(.CXCursor_, => HandleFieldDecl),
|
||||
(.CXCursor_FieldDecl, => HandleFieldDecl),
|
||||
(.CXCursor_EnumDecl, => HandleEnumDecl),
|
||||
(.CXCursor_EnumConstantDecl, => HandleEnumConstDecl),
|
||||
(.CXCursor_ParmDecl, => DoNothing),
|
||||
|
@ -40,10 +40,46 @@ class Binding
|
|||
cursor,
|
||||
(cursor, parent, client_data) => {
|
||||
|
||||
switch(clang_getCursorKind(cursor))
|
||||
{
|
||||
case .CXCursor_FunctionDecl:
|
||||
var name = clang_getCursorSpelling(cursor);
|
||||
BindingFunction func = new .(name.text, clang_getCursorResultType(cursor));
|
||||
var count = clang_Cursor_getNumArguments(cursor);
|
||||
for(int i < count)
|
||||
{
|
||||
var arg = clang_Cursor_getArgument(cursor, (.)i);
|
||||
var argType = clang_getCursorType(arg);
|
||||
var argName = clang_getCursorSpelling(arg);
|
||||
func.Args.Add(new .(argName.text, argType));
|
||||
}
|
||||
Function.Add(func);
|
||||
case .CXCursor_StructDecl:
|
||||
var name = clang_getCursorSpelling(cursor);
|
||||
BindingStruct strct = new .(name.text);
|
||||
Structs.Add(strct);
|
||||
case .CXCursor_FieldDecl:
|
||||
if(Structs.Count > 0)
|
||||
Structs[Structs.Count-1].Fields.Add(new .(clang_getCursorSpelling(cursor).text, clang_getCursorType(cursor)));
|
||||
case .CXCursor_EnumDecl:
|
||||
var name = clang_getCursorSpelling(cursor);
|
||||
BindingEnum enm = new .(name.text);
|
||||
Enums.Add(enm);
|
||||
case .CXCursor_EnumConstantDecl:
|
||||
if(Enums.Count > 0)
|
||||
Enums[Enums.Count-1].Entries.Add(new .(clang_getCursorSpelling(cursor).text, (.)clang_getEnumConstantDeclValue(cursor)));
|
||||
case .CXCursor_ParmDecl:
|
||||
DoNothing(&cursor);
|
||||
default:
|
||||
Console.WriteLine(scope $"{clang_getCursorKind(cursor)} {clang_getCursorSpelling(cursor).text}");
|
||||
}
|
||||
|
||||
/*
|
||||
if(CursorHandlers.ContainsKey(clang_getCursorKind(cursor)))
|
||||
CursorHandlers[clang_getCursorKind(cursor)](cursor);
|
||||
CursorHandlers[clang_getCursorKind(cursor)](&cursor);
|
||||
else
|
||||
Console.WriteLine(scope $"{clang_getCursorKind(cursor)} {clang_getCursorSpelling(cursor).text}");
|
||||
*/
|
||||
|
||||
|
||||
return CXChildVisitResult.CXChildVisit_Recurse;
|
||||
|
@ -54,15 +90,15 @@ class Binding
|
|||
clang_disposeIndex(index);
|
||||
}
|
||||
|
||||
public static void HandleFunctionDecl(CXCursor cursor)
|
||||
public static void HandleFunctionDecl(CXCursor* cursor)
|
||||
{
|
||||
var name = clang_getCursorSpelling(cursor);
|
||||
BindingFunction func = new .(name.text, clang_getCursorResultType(cursor));
|
||||
var name = clang_getCursorSpelling(*cursor);
|
||||
BindingFunction func = new .(name.text, clang_getCursorResultType(*cursor));
|
||||
|
||||
var count = clang_Cursor_getNumArguments(cursor);
|
||||
var count = clang_Cursor_getNumArguments(*cursor);
|
||||
for(int i < count)
|
||||
{
|
||||
var arg = clang_Cursor_getArgument(cursor, (.)i);
|
||||
var arg = clang_Cursor_getArgument(*cursor, (.)i);
|
||||
var argType = clang_getCursorType(arg);
|
||||
var argName = clang_getCursorSpelling(arg);
|
||||
func.Args.Add(new .(argName.text, argType));
|
||||
|
@ -70,35 +106,35 @@ class Binding
|
|||
Function.Add(func);
|
||||
}
|
||||
|
||||
public static void HandleStructDecl(CXCursor cursor)
|
||||
public static void HandleStructDecl(CXCursor* cursor)
|
||||
{
|
||||
var name = clang_getCursorSpelling(cursor);
|
||||
var name = clang_getCursorSpelling(*cursor);
|
||||
BindingStruct strct = new .(name.text);
|
||||
Structs.Add(strct);
|
||||
}
|
||||
|
||||
public static void HandleFieldDecl(CXCursor cursor)
|
||||
public static void HandleFieldDecl(CXCursor* cursor)
|
||||
{
|
||||
if(Structs.Count > 0)
|
||||
Structs[Structs.Count-1].Fields.Add(new .(clang_getCursorSpelling(cursor).text, clang_getCursorType(cursor)));
|
||||
Structs[Structs.Count-1].Fields.Add(new .(clang_getCursorSpelling(*cursor).text, clang_getCursorType(*cursor)));
|
||||
}
|
||||
|
||||
public static void HandleEnumDecl(CXCursor cursor)
|
||||
public static void HandleEnumDecl(CXCursor* cursor)
|
||||
{
|
||||
var name = clang_getCursorSpelling(cursor);
|
||||
var name = clang_getCursorSpelling(*cursor);
|
||||
BindingEnum enm = new .(name.text);
|
||||
Enums.Add(enm);
|
||||
}
|
||||
|
||||
public static void HandleEnumConstDecl(CXCursor cursor)
|
||||
public static void HandleEnumConstDecl(CXCursor* cursor)
|
||||
{
|
||||
if(Enums.Count > 0)
|
||||
{
|
||||
Enums[Enums.Count-1].Entries.Add(new .(clang_getCursorSpelling(cursor).text, (.)clang_getEnumConstantDeclValue(cursor)));
|
||||
Enums[Enums.Count-1].Entries.Add(new .(clang_getCursorSpelling(*cursor).text, (.)clang_getEnumConstantDeclValue(*cursor)));
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoNothing(CXCursor cursor) {}
|
||||
private static void DoNothing(CXCursor* cursor) {}
|
||||
|
||||
|
||||
///Generate the actual file strings and try to write them according to the input parameter and the options
|
||||
|
|
|
@ -8,7 +8,7 @@ class BindingOptions
|
|||
This handles the C way of namespacing
|
||||
If something has the namespace infront of it we remove it and incase of functions, generate the linkname property
|
||||
*/
|
||||
private String _Namespace = new .("") ~ delete _;
|
||||
private String _Namespace = new .("doifjdsoifjodsfjjfoijfdsf") ~ delete _;
|
||||
public String Namespace
|
||||
{
|
||||
get => _Namespace;
|
||||
|
|
|
@ -6,7 +6,6 @@ class Program
|
|||
{
|
||||
public static int Main(String[] args)
|
||||
{
|
||||
Binding.Options.Namespace = "sqlite3_";
|
||||
Console.WriteLine("""
|
||||
Caa - Generate a Beef binding for c headers
|
||||
Version 1.0.0
|
||||
|
|
Loading…
Add table
Reference in a new issue