mirror of
https://github.com/ValveSoftware/Proton.git
synced 2025-01-26 13:38:15 +03:00
lsteamclient: Split cpp_h generation to a dedicated method.
CW-Bug-Id: #22729
This commit is contained in:
parent
eaf6d83cf1
commit
16c292fa1b
@ -697,17 +697,63 @@ def to_c_bool(b):
|
|||||||
|
|
||||||
dummy_writer = DummyWriter()
|
dummy_writer = DummyWriter()
|
||||||
|
|
||||||
def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, existing_methods):
|
|
||||||
|
def method_unique_name(method, existing_methods):
|
||||||
used_name = method.spelling
|
used_name = method.spelling
|
||||||
if used_name in existing_methods:
|
if used_name in existing_methods:
|
||||||
number = '2'
|
number = 2
|
||||||
while used_name in existing_methods:
|
while used_name in existing_methods:
|
||||||
idx = existing_methods.index(used_name)
|
idx = existing_methods.index(used_name)
|
||||||
used_name = f"{method.spelling}_{number}"
|
used_name = f"{method.spelling}_{number}"
|
||||||
number = chr(ord(number) + 1)
|
number = number + 1
|
||||||
existing_methods.insert(idx, used_name)
|
existing_methods.insert(idx, used_name)
|
||||||
else:
|
else:
|
||||||
existing_methods.append(used_name)
|
existing_methods.append(used_name)
|
||||||
|
return used_name
|
||||||
|
|
||||||
|
|
||||||
|
def param_needs_conversion(decl):
|
||||||
|
return decl.spelling not in WRAPPED_CLASSES and \
|
||||||
|
decl.kind == TypeKind.RECORD and \
|
||||||
|
struct_needs_conversion(decl)
|
||||||
|
|
||||||
|
|
||||||
|
def declspec(decl, name):
|
||||||
|
if type(decl) is Cursor:
|
||||||
|
decl = decl.type
|
||||||
|
|
||||||
|
const = 'const ' if decl.is_const_qualified() else ''
|
||||||
|
if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE):
|
||||||
|
decl = decl.get_pointee()
|
||||||
|
return declspec(decl, f"*{const}{name}")
|
||||||
|
if decl.kind == TypeKind.CONSTANTARRAY:
|
||||||
|
decl, count = decl.element_type, decl.element_count
|
||||||
|
return declspec(decl, f"({const}{name})[{count}]")
|
||||||
|
|
||||||
|
if len(name):
|
||||||
|
name = f' {name}'
|
||||||
|
|
||||||
|
if decl.kind in (TypeKind.UNEXPOSED, TypeKind.FUNCTIONPROTO):
|
||||||
|
return f'void{name}'
|
||||||
|
if decl.kind == TypeKind.ENUM:
|
||||||
|
return f'{decl.spelling.split("::")[-1]}{name}'
|
||||||
|
|
||||||
|
if param_needs_conversion(decl):
|
||||||
|
return f"win{decl.spelling}_{sdkver}{name}"
|
||||||
|
return f'{decl.spelling}{name}'
|
||||||
|
|
||||||
|
|
||||||
|
def handle_method_hpp(method_name, cppname, method, cpp_h):
|
||||||
|
ret = f'{method.result_type.spelling} '
|
||||||
|
if ret.startswith("ISteam"): ret = 'void *'
|
||||||
|
|
||||||
|
params = [declspec(p, "") for p in method.get_arguments()]
|
||||||
|
params = ['void *'] + params
|
||||||
|
|
||||||
|
cpp_h.write(f'extern {ret}{cppname}_{method_name}({", ".join(params)});\n')
|
||||||
|
|
||||||
|
|
||||||
|
def handle_method(used_name, cfile, classname, winclassname, cppname, method, cpp):
|
||||||
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
||||||
if returns_record:
|
if returns_record:
|
||||||
parambytes = 8 #_this + return pointer
|
parambytes = 8 #_this + return pointer
|
||||||
@ -722,22 +768,17 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e
|
|||||||
if method_needs_manual_handling(cppname, used_name):
|
if method_needs_manual_handling(cppname, used_name):
|
||||||
cpp = dummy_writer #just don't write the cpp function
|
cpp = dummy_writer #just don't write the cpp function
|
||||||
cfile.write(f"DEFINE_THISCALL_WRAPPER({winclassname}_{used_name}, {parambytes})\n")
|
cfile.write(f"DEFINE_THISCALL_WRAPPER({winclassname}_{used_name}, {parambytes})\n")
|
||||||
cpp_h.write("extern ")
|
|
||||||
if method.result_type.spelling.startswith("ISteam"):
|
if method.result_type.spelling.startswith("ISteam"):
|
||||||
cfile.write(f"win{method.result_type.spelling} ")
|
cfile.write(f"win{method.result_type.spelling} ")
|
||||||
cpp.write("void *")
|
cpp.write("void *")
|
||||||
cpp_h.write("void *")
|
|
||||||
elif returns_record:
|
elif returns_record:
|
||||||
cfile.write(f"{method.result_type.spelling} *")
|
cfile.write(f"{method.result_type.spelling} *")
|
||||||
cpp.write(f"{method.result_type.spelling} ")
|
cpp.write(f"{method.result_type.spelling} ")
|
||||||
cpp_h.write(f"{method.result_type.spelling} ")
|
|
||||||
else:
|
else:
|
||||||
cfile.write(f"{method.result_type.spelling} ")
|
cfile.write(f"{method.result_type.spelling} ")
|
||||||
cpp.write(f"{method.result_type.spelling} ")
|
cpp.write(f"{method.result_type.spelling} ")
|
||||||
cpp_h.write(f"{method.result_type.spelling} ")
|
|
||||||
cfile.write(f'__thiscall {winclassname}_{used_name}({winclassname} *_this')
|
cfile.write(f'__thiscall {winclassname}_{used_name}({winclassname} *_this')
|
||||||
cpp.write(f"{cppname}_{used_name}(void *linux_side")
|
cpp.write(f"{cppname}_{used_name}(void *linux_side")
|
||||||
cpp_h.write(f"{cppname}_{used_name}(void *")
|
|
||||||
if returns_record:
|
if returns_record:
|
||||||
cfile.write(f", {method.result_type.spelling} *_r")
|
cfile.write(f", {method.result_type.spelling} *_r")
|
||||||
unnamed = 'a'
|
unnamed = 'a'
|
||||||
@ -745,42 +786,29 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e
|
|||||||
manual_convert = []
|
manual_convert = []
|
||||||
for param in list(method.get_children()):
|
for param in list(method.get_children()):
|
||||||
if param.kind == CursorKind.PARM_DECL:
|
if param.kind == CursorKind.PARM_DECL:
|
||||||
if param.type.kind == TypeKind.POINTER and \
|
|
||||||
(param.type.get_pointee().kind == TypeKind.UNEXPOSED or param.type.get_pointee().kind == TypeKind.FUNCTIONPROTO):
|
|
||||||
#unspecified function pointer
|
|
||||||
typename = "void *"
|
|
||||||
else:
|
|
||||||
typename = param.type.spelling.split("::")[-1]
|
|
||||||
|
|
||||||
real_type = param.type
|
real_type = param.type
|
||||||
while real_type.kind == TypeKind.POINTER:
|
while real_type.kind == TypeKind.POINTER:
|
||||||
real_type = real_type.get_pointee()
|
real_type = real_type.get_pointee()
|
||||||
win_name = typename
|
|
||||||
if real_type.kind == TypeKind.RECORD and \
|
if real_type.kind == TypeKind.RECORD and \
|
||||||
not real_type.spelling in WRAPPED_CLASSES and \
|
not real_type.spelling in WRAPPED_CLASSES and \
|
||||||
struct_needs_conversion(real_type):
|
struct_needs_conversion(real_type):
|
||||||
need_convert.append(param)
|
need_convert.append(param)
|
||||||
#preserve pointers
|
|
||||||
win_name = typename.replace(real_type.spelling, f"win{real_type.spelling}_{sdkver}")
|
|
||||||
elif real_type.spelling in MANUAL_TYPES:
|
elif real_type.spelling in MANUAL_TYPES:
|
||||||
manual_convert.append(param)
|
manual_convert.append(param)
|
||||||
elif param.spelling in MANUAL_PARAMS:
|
elif param.spelling in MANUAL_PARAMS:
|
||||||
manual_convert.append(param)
|
manual_convert.append(param)
|
||||||
|
|
||||||
win_name = win_name.replace('&', '*')
|
win_name = declspec(param, "")
|
||||||
|
|
||||||
if param.spelling == "":
|
if param.spelling == "":
|
||||||
cfile.write(f", {win_name} _{unnamed}")
|
cfile.write(f", {win_name} _{unnamed}")
|
||||||
cpp.write(f", {win_name} _{unnamed}")
|
cpp.write(f", {win_name} _{unnamed}")
|
||||||
cpp_h.write(f", {win_name}")
|
|
||||||
unnamed = chr(ord(unnamed) + 1)
|
unnamed = chr(ord(unnamed) + 1)
|
||||||
else:
|
else:
|
||||||
cfile.write(f", {win_name} {param.spelling}")
|
cfile.write(f", {win_name} {param.spelling}")
|
||||||
cpp.write(f", {win_name} {param.spelling}")
|
cpp.write(f", {win_name} {param.spelling}")
|
||||||
cpp_h.write(f", {win_name}")
|
|
||||||
cfile.write(")\n{\n")
|
cfile.write(")\n{\n")
|
||||||
cpp.write(")\n{\n")
|
cpp.write(")\n{\n")
|
||||||
cpp_h.write(");\n")
|
|
||||||
|
|
||||||
path_conv = get_path_converter(method)
|
path_conv = get_path_converter(method)
|
||||||
|
|
||||||
@ -977,7 +1005,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
|
|||||||
for child in klass.get_children():
|
for child in klass.get_children():
|
||||||
if child.kind == CursorKind.CXX_METHOD and \
|
if child.kind == CursorKind.CXX_METHOD and \
|
||||||
child.is_virtual_method():
|
child.is_virtual_method():
|
||||||
handle_method(cfile, klass.spelling, winclassname, cppname, child, cpp, cpp_h, methods)
|
method_name = method_unique_name(child, methods)
|
||||||
|
handle_method_hpp(method_name, cppname, child, cpp_h)
|
||||||
|
handle_method(method_name, cfile, klass.spelling, winclassname, cppname, child, cpp)
|
||||||
elif child.kind == CursorKind.DESTRUCTOR:
|
elif child.kind == CursorKind.DESTRUCTOR:
|
||||||
methods.append(handle_destructor(cfile, klass.spelling, winclassname, child))
|
methods.append(handle_destructor(cfile, klass.spelling, winclassname, child))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user