lsteamclient: Cleanup C method generator.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-09-23 20:54:51 +02:00
parent a2efb6cc82
commit 0040deb754
36 changed files with 2689 additions and 2694 deletions

View file

@ -753,12 +753,6 @@ def get_path_converter(parent):
return None return None
def to_c_bool(b):
if b:
return "1"
return "0"
def underlying_type(decl): def underlying_type(decl):
if type(decl) is Cursor: if type(decl) is Cursor:
decl = decl.type decl = decl.type
@ -906,25 +900,28 @@ def handle_thiscall_wrapper(klass, method, cfile):
def handle_method_c(method, winclassname, cppname, cfile): def handle_method_c(method, winclassname, cppname, cfile):
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
if method.result_type.spelling.startswith("ISteam"):
cfile.write(f"win{method.result_type.spelling} ") ret = f'{method.result_type.spelling} '
elif returns_record: if ret.startswith("ISteam"): ret = f'win{ret}'
cfile.write(f"{method.result_type.spelling} *") elif returns_record: ret = f'{ret}*'
else:
cfile.write(f"{method.result_type.spelling} ") names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
cfile.write(f'__thiscall {winclassname}_{method.name}({winclassname} *_this') for i, p in enumerate(method.get_arguments())]
params = [declspec(p, names[i]) for i, p in enumerate(method.get_arguments())]
if returns_record: if returns_record:
cfile.write(f", {method.result_type.spelling} *_r") params = [f'{method.result_type.spelling} *_r'] + params
unnamed = 'a' names = ['_r'] + names
for param in list(method.get_children()):
if param.kind == CursorKind.PARM_DECL: params = [f'{winclassname} *_this'] + params
win_name = declspec(param, "") names = ['_this'] + names
if param.spelling == "":
cfile.write(f", {win_name} _{unnamed}") cfile.write(f'{ret}__thiscall {winclassname}_{method.name}({", ".join(params)})\n')
unnamed = chr(ord(unnamed) + 1) cfile.write("{\n")
else:
cfile.write(f", {win_name} {param.spelling}") if returns_record:
cfile.write(")\n{\n") del params[1]
del names[1]
path_conv = get_path_converter(method) path_conv = get_path_converter(method)
@ -936,7 +933,7 @@ def handle_method_c(method, winclassname, cppname, cfile):
pass pass
else: else:
cfile.write(f" char lin_{path_conv['w2l_names'][i]}[PATH_MAX];\n") cfile.write(f" char lin_{path_conv['w2l_names'][i]}[PATH_MAX];\n")
cfile.write(f" steamclient_dos_path_to_unix_path({path_conv['w2l_names'][i]}, lin_{path_conv['w2l_names'][i]}, {to_c_bool(path_conv['w2l_urls'][i])});\n") cfile.write(f" steamclient_dos_path_to_unix_path({path_conv['w2l_names'][i]}, lin_{path_conv['w2l_names'][i]}, {int(path_conv['w2l_urls'][i])});\n")
if None in path_conv["l2w_names"]: if None in path_conv["l2w_names"]:
cfile.write(" const char *path_result;\n") cfile.write(" const char *path_result;\n")
elif path_conv["return_is_size"]: elif path_conv["return_is_size"]:
@ -961,24 +958,22 @@ def handle_method_c(method, winclassname, cppname, cfile):
method.name.startswith("GetISteamGenericInterface")) method.name.startswith("GetISteamGenericInterface"))
if should_do_cb_wrap: if should_do_cb_wrap:
cfile.write(f"do_cb_wrap(0, &{cppname}_{method.name}, _this->linux_side") cfile.write(f"do_cb_wrap(0, &{cppname}_{method.name}, ")
else: else:
if should_gen_wrapper: if should_gen_wrapper:
cfile.write("create_win_interface(pchVersion,\n ") cfile.write("create_win_interface(pchVersion,\n ")
cfile.write(f"{cppname}_{method.name}(_this->linux_side") cfile.write(f"{cppname}_{method.name}(")
unnamed = 'a'
for param in list(method.get_children()): def param_call(param, name):
if param.kind == CursorKind.PARM_DECL: if name == '_this': return '_this->linux_side'
if param.spelling == "": iface = param.type.get_pointee().spelling if param.type.kind == TypeKind.POINTER else None
cfile.write(f", _{unnamed}") if iface in WRAPPED_CLASSES: return f'create_Linux{iface}({name}, "{winclassname}")'
unnamed = chr(ord(unnamed) + 1) if path_conv and name in path_conv["w2l_names"]: return f'{name} ? lin_{name} : NULL'
elif param.type.kind == TypeKind.POINTER and \ return name
param.type.get_pointee().spelling in WRAPPED_CLASSES:
cfile.write(f", create_Linux{param.type.get_pointee().spelling}({param.spelling}, \"{winclassname}\")") params = ['_this'] + list(method.get_arguments())
elif path_conv and param.spelling in path_conv["w2l_names"]: cfile.write(", ".join([param_call(p, n) for p, n in zip(params, names)]))
cfile.write(f", {param.spelling} ? lin_{param.spelling} : NULL")
else:
cfile.write(f", {param.spelling}")
if should_gen_wrapper: if should_gen_wrapper:
cfile.write(")") cfile.write(")")
@ -990,7 +985,7 @@ def handle_method_c(method, winclassname, cppname, cfile):
cfile.write(" ") cfile.write(" ")
if path_conv["return_is_size"]: if path_conv["return_is_size"]:
cfile.write("path_result = ") cfile.write("path_result = ")
cfile.write(f"steamclient_unix_path_to_dos_path(path_result, {path_conv['l2w_names'][i]}, {path_conv['l2w_names'][i]}, {path_conv['l2w_lens'][i]}, {to_c_bool(path_conv['l2w_urls'][i])});\n") cfile.write(f"steamclient_unix_path_to_dos_path(path_result, {path_conv['l2w_names'][i]}, {path_conv['l2w_names'][i]}, {path_conv['l2w_lens'][i]}, {int(path_conv['l2w_urls'][i])});\n")
cfile.write(" return path_result;\n") cfile.write(" return path_result;\n")
if path_conv: if path_conv:
for i in range(len(path_conv["w2l_names"])): for i in range(len(path_conv["w2l_names"])):
@ -1294,7 +1289,7 @@ def handle_struct(sdkver, struct):
if path_conv["l2w_names"][i] == m.displayname: if path_conv["l2w_names"][i] == m.displayname:
url = path_conv["l2w_urls"][i] url = path_conv["l2w_urls"][i]
break break
cppfile.write(f" steamclient_unix_path_to_dos_path(1, {src}->{m.displayname}, g_tmppath, sizeof(g_tmppath), {to_c_bool(url)});\n") cppfile.write(f" steamclient_unix_path_to_dos_path(1, {src}->{m.displayname}, g_tmppath, sizeof(g_tmppath), {int(url)});\n")
cppfile.write(f" {dst}->{m.displayname} = g_tmppath;\n") cppfile.write(f" {dst}->{m.displayname} = g_tmppath;\n")
else: else:
cppfile.write(f" {dst}->{m.displayname} = {src}->{m.displayname};\n") cppfile.write(f" {dst}->{m.displayname} = {src}->{m.displayname};\n")

View file

@ -2701,10 +2701,10 @@ bool __thiscall winISteamFriends_SteamFriends010_SendClanChatMessage(winISteamFr
return cppISteamFriends_SteamFriends010_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText); return cppISteamFriends_SteamFriends010_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText);
} }
int __thiscall winISteamFriends_SteamFriends010_GetClanChatMessage(winISteamFriends_SteamFriends010 *_this, CSteamID steamIDClanChat, int iMessage, void * prgchText, int cchTextMax, EChatEntryType * _a, CSteamID * _b) int __thiscall winISteamFriends_SteamFriends010_GetClanChatMessage(winISteamFriends_SteamFriends010 *_this, CSteamID steamIDClanChat, int iMessage, void *prgchText, int cchTextMax, EChatEntryType *_e, CSteamID *_f)
{ {
TRACE("%p\n", _this); TRACE("%p\n", _this);
return cppISteamFriends_SteamFriends010_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _a, _b); return cppISteamFriends_SteamFriends010_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _e, _f);
} }
bool __thiscall winISteamFriends_SteamFriends010_IsClanChatAdmin(winISteamFriends_SteamFriends010 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser) bool __thiscall winISteamFriends_SteamFriends010_IsClanChatAdmin(winISteamFriends_SteamFriends010 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser)
@ -3218,10 +3218,10 @@ bool __thiscall winISteamFriends_SteamFriends011_SendClanChatMessage(winISteamFr
return cppISteamFriends_SteamFriends011_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText); return cppISteamFriends_SteamFriends011_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText);
} }
int __thiscall winISteamFriends_SteamFriends011_GetClanChatMessage(winISteamFriends_SteamFriends011 *_this, CSteamID steamIDClanChat, int iMessage, void * prgchText, int cchTextMax, EChatEntryType * _a, CSteamID * _b) int __thiscall winISteamFriends_SteamFriends011_GetClanChatMessage(winISteamFriends_SteamFriends011 *_this, CSteamID steamIDClanChat, int iMessage, void *prgchText, int cchTextMax, EChatEntryType *_e, CSteamID *_f)
{ {
TRACE("%p\n", _this); TRACE("%p\n", _this);
return cppISteamFriends_SteamFriends011_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _a, _b); return cppISteamFriends_SteamFriends011_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _e, _f);
} }
bool __thiscall winISteamFriends_SteamFriends011_IsClanChatAdmin(winISteamFriends_SteamFriends011 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser) bool __thiscall winISteamFriends_SteamFriends011_IsClanChatAdmin(winISteamFriends_SteamFriends011 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser)
@ -3757,10 +3757,10 @@ bool __thiscall winISteamFriends_SteamFriends012_SendClanChatMessage(winISteamFr
return cppISteamFriends_SteamFriends012_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText); return cppISteamFriends_SteamFriends012_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText);
} }
int __thiscall winISteamFriends_SteamFriends012_GetClanChatMessage(winISteamFriends_SteamFriends012 *_this, CSteamID steamIDClanChat, int iMessage, void * prgchText, int cchTextMax, EChatEntryType * _a, CSteamID * _b) int __thiscall winISteamFriends_SteamFriends012_GetClanChatMessage(winISteamFriends_SteamFriends012 *_this, CSteamID steamIDClanChat, int iMessage, void *prgchText, int cchTextMax, EChatEntryType *_e, CSteamID *_f)
{ {
TRACE("%p\n", _this); TRACE("%p\n", _this);
return cppISteamFriends_SteamFriends012_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _a, _b); return cppISteamFriends_SteamFriends012_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _e, _f);
} }
bool __thiscall winISteamFriends_SteamFriends012_IsClanChatAdmin(winISteamFriends_SteamFriends012 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser) bool __thiscall winISteamFriends_SteamFriends012_IsClanChatAdmin(winISteamFriends_SteamFriends012 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser)
@ -4296,10 +4296,10 @@ bool __thiscall winISteamFriends_SteamFriends013_SendClanChatMessage(winISteamFr
return cppISteamFriends_SteamFriends013_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText); return cppISteamFriends_SteamFriends013_SendClanChatMessage(_this->linux_side, steamIDClanChat, pchText);
} }
int __thiscall winISteamFriends_SteamFriends013_GetClanChatMessage(winISteamFriends_SteamFriends013 *_this, CSteamID steamIDClanChat, int iMessage, void * prgchText, int cchTextMax, EChatEntryType * _a, CSteamID * _b) int __thiscall winISteamFriends_SteamFriends013_GetClanChatMessage(winISteamFriends_SteamFriends013 *_this, CSteamID steamIDClanChat, int iMessage, void *prgchText, int cchTextMax, EChatEntryType *_e, CSteamID *_f)
{ {
TRACE("%p\n", _this); TRACE("%p\n", _this);
return cppISteamFriends_SteamFriends013_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _a, _b); return cppISteamFriends_SteamFriends013_GetClanChatMessage(_this->linux_side, steamIDClanChat, iMessage, prgchText, cchTextMax, _e, _f);
} }
bool __thiscall winISteamFriends_SteamFriends013_IsClanChatAdmin(winISteamFriends_SteamFriends013 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser) bool __thiscall winISteamFriends_SteamFriends013_IsClanChatAdmin(winISteamFriends_SteamFriends013 *_this, CSteamID steamIDClanChat, CSteamID steamIDUser)