mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-19 04:38:01 +00:00
Some fixes after rebasing
This commit is contained in:
parent
01025e9157
commit
7c65f31f46
@ -40,6 +40,12 @@ SizingConstraints :: struct #raw_union {
|
|||||||
sizePercent: c.float,
|
sizePercent: c.float,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TypedConfig :: struct {
|
||||||
|
type: ElementConfigType,
|
||||||
|
config: rawptr,
|
||||||
|
id: ElementId,
|
||||||
|
}
|
||||||
|
|
||||||
{{structs}}
|
{{structs}}
|
||||||
|
|
||||||
@(link_prefix = "Clay_", default_calling_convention = "c")
|
@(link_prefix = "Clay_", default_calling_convention = "c")
|
||||||
|
@ -81,6 +81,9 @@ STRUCT_TYPE_OVERRIDES = {
|
|||||||
'Clay_SizingAxis': {
|
'Clay_SizingAxis': {
|
||||||
'size': 'SizingConstraints',
|
'size': 'SizingConstraints',
|
||||||
},
|
},
|
||||||
|
"Clay_RenderCommand": {
|
||||||
|
"zIndex": 'i32',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
STRUCT_MEMBER_OVERRIDES = {
|
STRUCT_MEMBER_OVERRIDES = {
|
||||||
'Clay_ErrorHandler': {
|
'Clay_ErrorHandler': {
|
||||||
@ -105,7 +108,14 @@ FUNCTION_TYPE_OVERRIDES = {
|
|||||||
'offset': '[^]u8',
|
'offset': '[^]u8',
|
||||||
},
|
},
|
||||||
'Clay_SetMeasureTextFunction': {
|
'Clay_SetMeasureTextFunction': {
|
||||||
'measureTextFunction': 'proc "c" (text: ^String, config: ^TextElementConfig) -> Dimensions',
|
'measureTextFunction': 'proc "c" (text: ^StringSlice, config: ^TextElementConfig, userData: uintptr) -> Dimensions',
|
||||||
|
'userData': 'uintptr',
|
||||||
|
},
|
||||||
|
'Clay_RenderCommandArray_Get': {
|
||||||
|
'index': 'i32',
|
||||||
|
},
|
||||||
|
"Clay__AttachElementConfig": {
|
||||||
|
"config": 'rawptr',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +171,8 @@ class OdinGenerator(BaseGenerator):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def generate_structs(self) -> None:
|
def generate_structs(self) -> None:
|
||||||
for struct, members in sorted(self.extracted_symbols.structs.items(), key=lambda x: x[0]):
|
for struct, struct_data in sorted(self.extracted_symbols.structs.items(), key=lambda x: x[0]):
|
||||||
|
members = struct_data['attrs']
|
||||||
if not struct.startswith('Clay_'):
|
if not struct.startswith('Clay_'):
|
||||||
continue
|
continue
|
||||||
if struct in SYMBOL_COMPLETE_OVERRIDES:
|
if struct in SYMBOL_COMPLETE_OVERRIDES:
|
||||||
@ -188,8 +199,10 @@ class OdinGenerator(BaseGenerator):
|
|||||||
self._write('struct', "")
|
self._write('struct', "")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
raw_union = ' #raw_union' if struct_data.get('is_union', False) else ''
|
||||||
|
|
||||||
self._write('struct', f"// {struct}")
|
self._write('struct', f"// {struct}")
|
||||||
self._write('struct', f"{binding_name} :: struct {{")
|
self._write('struct', f"{binding_name} :: struct{raw_union} {{")
|
||||||
|
|
||||||
for member, member_info in members.items():
|
for member, member_info in members.items():
|
||||||
if struct in STRUCT_TYPE_OVERRIDES and member in STRUCT_TYPE_OVERRIDES[struct]:
|
if struct in STRUCT_TYPE_OVERRIDES and member in STRUCT_TYPE_OVERRIDES[struct]:
|
||||||
@ -275,5 +288,6 @@ class OdinGenerator(BaseGenerator):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
binding_params_str = ', '.join(binding_params)
|
binding_params_str = ', '.join(binding_params)
|
||||||
self._write(write_to, f" {binding_name} :: proc({binding_params_str}) -> {binding_return_type} --- // {function}")
|
return_str = f" -> {binding_return_type}" if binding_return_type != 'void' else ''
|
||||||
|
self._write(write_to, f" {binding_name} :: proc({binding_params_str}){return_str} --- // {function}")
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, TypedDict
|
from typing import Optional, TypedDict, NotRequired
|
||||||
from pycparser import c_ast, parse_file, preprocess_file
|
from pycparser import c_ast, parse_file, preprocess_file
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
@ -16,7 +16,10 @@ class ExtractedStructAttribute(TypedDict):
|
|||||||
type: Optional[str]
|
type: Optional[str]
|
||||||
union: Optional[dict[str, Optional[str]]]
|
union: Optional[dict[str, Optional[str]]]
|
||||||
|
|
||||||
ExtractedStruct = dict[str, ExtractedStructAttribute]
|
class ExtractedStruct(TypedDict):
|
||||||
|
attrs: dict[str, ExtractedStructAttribute]
|
||||||
|
is_union: NotRequired[bool]
|
||||||
|
|
||||||
ExtractedEnum = dict[str, Optional[str]]
|
ExtractedEnum = dict[str, Optional[str]]
|
||||||
ExtractedFunctionParam = tuple[str, Optional[str]]
|
ExtractedFunctionParam = tuple[str, Optional[str]]
|
||||||
|
|
||||||
@ -50,7 +53,7 @@ class Visitor(c_ast.NodeVisitor):
|
|||||||
|
|
||||||
def visit_FuncDecl(self, node: c_ast.FuncDecl):
|
def visit_FuncDecl(self, node: c_ast.FuncDecl):
|
||||||
# node.show()
|
# node.show()
|
||||||
logger.debug(node)
|
# logger.debug(node)
|
||||||
node_type = node.type
|
node_type = node.type
|
||||||
is_pointer = False
|
is_pointer = False
|
||||||
if isinstance(node.type, c_ast.PtrDecl):
|
if isinstance(node.type, c_ast.PtrDecl):
|
||||||
@ -80,7 +83,9 @@ class Visitor(c_ast.NodeVisitor):
|
|||||||
struct[decl.name] = {
|
struct[decl.name] = {
|
||||||
"type": get_type_names(decl),
|
"type": get_type_names(decl),
|
||||||
}
|
}
|
||||||
self.structs[node.name] = struct
|
self.structs[node.name] = {
|
||||||
|
'attrs': struct,
|
||||||
|
}
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
|
||||||
def visit_Typedef(self, node: c_ast.Typedef):
|
def visit_Typedef(self, node: c_ast.Typedef):
|
||||||
@ -99,7 +104,11 @@ class Visitor(c_ast.NodeVisitor):
|
|||||||
struct[decl.name] = {
|
struct[decl.name] = {
|
||||||
"type": get_type_names(decl),
|
"type": get_type_names(decl),
|
||||||
}
|
}
|
||||||
self.structs[node.name] = struct
|
|
||||||
|
self.structs[node.name] = {
|
||||||
|
'attrs': struct,
|
||||||
|
'is_union': isinstance(node.type.type, c_ast.Union),
|
||||||
|
}
|
||||||
if hasattr(node.type, 'type') and isinstance(node.type.type, c_ast.Enum):
|
if hasattr(node.type, 'type') and isinstance(node.type.type, c_ast.Enum):
|
||||||
enum = {}
|
enum = {}
|
||||||
for enumerator in node.type.type.values.enumerators:
|
for enumerator in node.type.type.values.enumerators:
|
||||||
|
Loading…
Reference in New Issue
Block a user