mirror of
https://github.com/ValveSoftware/Proton.git
synced 2025-02-25 21:11:14 +03:00
lsteamclient: Generate functions with calling convention.
CW-Bug-Id: #22729
This commit is contained in:
parent
783cde21bd
commit
aaf9ba6e56
@ -308,14 +308,46 @@ def param_needs_conversion(decl):
|
|||||||
struct_needs_conversion(decl)
|
struct_needs_conversion(decl)
|
||||||
|
|
||||||
|
|
||||||
|
def callconv(cursor):
|
||||||
|
if type(cursor) is not Cursor:
|
||||||
|
return ''
|
||||||
|
canon = cursor.type.get_canonical()
|
||||||
|
if canon.kind != TypeKind.POINTER:
|
||||||
|
return ''
|
||||||
|
canon = canon.get_pointee()
|
||||||
|
if canon.kind != TypeKind.FUNCTIONPROTO:
|
||||||
|
return ''
|
||||||
|
if cursor.type.kind == TypeKind.TYPEDEF:
|
||||||
|
cursor = cursor.type.get_declaration()
|
||||||
|
|
||||||
|
tokens = cursor.get_tokens()
|
||||||
|
while next(tokens).spelling != '(': pass
|
||||||
|
token = f'{next(tokens).spelling} '
|
||||||
|
return token.replace('*', '__stdcall') \
|
||||||
|
.replace('S_CALLTYPE', '__cdecl')
|
||||||
|
|
||||||
|
|
||||||
|
def declspec_func(decl, name):
|
||||||
|
ret = declspec(decl.get_result(), "")
|
||||||
|
params = [declspec(a, "") for a in decl.argument_types()]
|
||||||
|
params = ", ".join(params) if len(params) else "void"
|
||||||
|
return f'{ret} ({name})({params})'
|
||||||
|
|
||||||
|
|
||||||
def declspec(decl, name):
|
def declspec(decl, name):
|
||||||
|
call = callconv(decl)
|
||||||
if type(decl) is Cursor:
|
if type(decl) is Cursor:
|
||||||
decl = decl.type
|
decl = decl.type
|
||||||
|
canon = decl.get_canonical()
|
||||||
|
|
||||||
|
if canon.kind == TypeKind.POINTER and canon.get_pointee().kind == TypeKind.FUNCTIONPROTO:
|
||||||
|
canon = canon.get_pointee()
|
||||||
|
return declspec_func(canon, f"*{call}{name}")
|
||||||
|
|
||||||
const = 'const ' if decl.is_const_qualified() else ''
|
const = 'const ' if decl.is_const_qualified() else ''
|
||||||
if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE):
|
if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE):
|
||||||
decl = decl.get_pointee()
|
decl = decl.get_pointee()
|
||||||
return declspec(decl, f"*{const}{name}")
|
return declspec(decl, f"*{call}{const}{name}")
|
||||||
if decl.kind == TypeKind.CONSTANTARRAY:
|
if decl.kind == TypeKind.CONSTANTARRAY:
|
||||||
decl, count = decl.element_type, decl.element_count
|
decl, count = decl.element_type, decl.element_count
|
||||||
return declspec(decl, f"({const}{name})[{count}]")
|
return declspec(decl, f"({const}{name})[{count}]")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user