Compare commits

...
2 Commits
+23 -6
View File
@@ -337,17 +337,26 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
def _tc_h4_type_casts(self, pool: memhub.MemBuddy*, builder: mlirlite.IRBuilder*, mod: mlirlite.LLVMModule*, cl: ast.Call*, funcs_ptr: rawptr, func_count: int, trans: HT.Translator*, func_name: str, cargs: list[ast.AST*]*, can: sizet) -> mlirlite.Value*:
"""Builtin / typedef type casts; returns None when unmatched."""
# Module-qualified typedef cast (posix.mode_t(mode), win32.win32base.HANDLE(v), ...): func is
# Attribute(Name(module), typedef); non-typedef names still go to the module function call.
# Module-qualified typedef cast (posix.mode_t(mode), win32.win32base.LPCWSTR(v), ...): the
# callee is Attribute(<module path>, typedef); non-typedef names still go to the module call.
if cl.func is not None and cl.func.kind() == ast.ASTKind.Attribute:
mt_at: ast.Attribute* = ast.Attribute*(cl.func)
if mt_at.value is not None and mt_at.value.kind() == ast.ASTKind.Name:
mt_mod_nm: ast.Name* = ast.Name*(mt_at.value)
if mt_mod_nm.id is not None:
if mt_at.attr is not None:
# Module path supports both `mod.T` and nested `pkg.mod.T`.
mt_mod_path: str = None
if mt_at.value is not None and mt_at.value.kind() == ast.ASTKind.Name:
mt_mod_nm: ast.Name* = ast.Name*(mt_at.value)
mt_mod_path = mt_mod_nm.id
elif mt_at.value is not None and mt_at.value.kind() == ast.ASTKind.Attribute:
mt_mod_path = self.Gen.ExprGenAttr._attr_module_path_str(pool, mt_at.value)
if mt_mod_path is not None:
mod_td_ty: mlirlite.LLVMType* = self.Gen.TypeGenResolve.map_builtin_type(pool, func_name)
if mod_td_ty is None:
mod_td_str: str = self.Gen.TypeGenCType.lookup_ctypedef(func_name)
if mod_td_str is not None and self.Gen.TypeGenCType.is_ctypedef_found() != 0:
if mod_td_str is None or self.Gen.TypeGenCType.is_ctypedef_found() == 0:
# Library typedef closure may not be injected yet: scan the module source.
mod_td_str = self.Gen.TypeGenResolve._lookup_library_typedef(pool, mt_mod_path, func_name)
if mod_td_str is not None:
mod_td_ast: ast.AST* = self.Gen.TypeGenResolve._parse_type_string(pool, mod_td_str, 0)
if mod_td_ast is not None:
mod_imp_td: str = None
@@ -356,6 +365,14 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
mod_imp_td = trans._imported_modules
mod_fi_td = trans._from_imports
mod_td_ty = self.Gen.TypeGenResolve.resolve_annotation_type(pool, mod_td_ast, mod_imp_td, mod_fi_td, trans, 0)
if mod_td_ty is None:
# Final fallback: the shared typedef resolver also scans stdint/win32base.
mod_imp_fb: str = None
mod_fi_fb: str = None
if trans is not None:
mod_imp_fb = trans._imported_modules
mod_fi_fb = trans._from_imports
mod_td_ty = self.Gen.TypeGenResolve.resolve_typedef_or_map(pool, func_name, mod_imp_fb, mod_fi_fb, trans)
if mod_td_ty is not None and can == 1:
mt_arg_val: mlirlite.Value* = self.Gen.ExprGen.translate_value(builder, pool, mod, cargs.get(0), funcs_ptr, func_count, trans, mod_td_ty)
if mt_arg_val is not None: return self.Gen.CallGenCtor._translate_t_type_cast(pool, builder, mt_arg_val, mod_td_ty, cargs.get(0), trans)