mirror of
https://github.com/ValveSoftware/Proton.git
synced 2024-12-27 23:25:50 +03:00
vrclient/gen_wrapper: Reduce code duplication slightly.
This commit is contained in:
parent
35b24f677e
commit
824d0765aa
@ -807,33 +807,36 @@ def generate_c_api_method_test(f, header, thunks_c, class_name, method_name, met
|
|||||||
header.write(");\n")
|
header.write(");\n")
|
||||||
thunks_c.write(")\n{\n")
|
thunks_c.write(")\n{\n")
|
||||||
|
|
||||||
thunks_c.write(" push_ptr_parameter(_this);\n")
|
def get_param_typename(param):
|
||||||
if returns_record:
|
|
||||||
thunks_c.write(" push_ptr_parameter(_r);\n")
|
|
||||||
for param in get_params(method):
|
|
||||||
param_size = param.type.get_size()
|
param_size = param.type.get_size()
|
||||||
if param.type.kind == clang.cindex.TypeKind.POINTER \
|
if param.type.kind == clang.cindex.TypeKind.POINTER \
|
||||||
or param.type.spelling.endswith("&") \
|
or param.type.spelling.endswith("&") \
|
||||||
or param.type.spelling == "vr::glSharedTextureHandle_t":
|
or param.type.spelling == "vr::glSharedTextureHandle_t":
|
||||||
typename = "ptr"
|
return "ptr"
|
||||||
elif param.type.spelling == "bool":
|
elif param.type.spelling == "bool":
|
||||||
typename = "bool"
|
return "bool"
|
||||||
elif param.type.spelling == "float":
|
elif param.type.spelling == "float":
|
||||||
typename = "float"
|
return "float"
|
||||||
elif param.type.spelling == "vr::HmdRect2_t":
|
elif param.type.spelling == "vr::HmdRect2_t":
|
||||||
typename = "HmdRect2"
|
return "HmdRect2"
|
||||||
elif param.type.spelling == "vr::HmdVector2_t":
|
elif param.type.spelling == "vr::HmdVector2_t":
|
||||||
typename = "HmdVector2"
|
return "HmdVector2"
|
||||||
elif param.type.spelling == "vr::HmdVector3_t":
|
elif param.type.spelling == "vr::HmdVector3_t":
|
||||||
typename = "HmdVector3"
|
return "HmdVector3"
|
||||||
elif param.type.spelling == "vr::HmdColor_t":
|
elif param.type.spelling == "vr::HmdColor_t":
|
||||||
typename = "HmdColor"
|
return "HmdColor"
|
||||||
elif param_size == 8:
|
elif param_size == 8:
|
||||||
typename = "uint64"
|
return "uint64"
|
||||||
elif param_size == 4 or param_size == 2:
|
elif param_size == 4 or param_size == 2:
|
||||||
typename = "uint32"
|
return "uint32"
|
||||||
else:
|
else:
|
||||||
typename = "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
thunks_c.write(" push_ptr_parameter(_this);\n")
|
||||||
|
if returns_record:
|
||||||
|
thunks_c.write(" push_ptr_parameter(_r);\n")
|
||||||
|
for param in get_params(method):
|
||||||
|
typename = get_param_typename(param)
|
||||||
thunks_c.write(" push_%s_parameter(%s);\n" % (typename, param.spelling))
|
thunks_c.write(" push_%s_parameter(%s);\n" % (typename, param.spelling))
|
||||||
if method.result_type.kind != clang.cindex.TypeKind.VOID:
|
if method.result_type.kind != clang.cindex.TypeKind.VOID:
|
||||||
thunks_c.write(" return 0;\n")
|
thunks_c.write(" return 0;\n")
|
||||||
@ -853,40 +856,28 @@ def generate_c_api_method_test(f, header, thunks_c, class_name, method_name, met
|
|||||||
add_parameter_check("ptr", "data_ptr_value")
|
add_parameter_check("ptr", "data_ptr_value")
|
||||||
for i, param in enumerate(get_params(method)):
|
for i, param in enumerate(get_params(method)):
|
||||||
i += 1
|
i += 1
|
||||||
param_size = param.type.get_size()
|
typename = get_param_typename(param)
|
||||||
if param.type.kind == clang.cindex.TypeKind.POINTER \
|
if typename == "ptr":
|
||||||
or param.type.spelling.endswith("&") \
|
|
||||||
or param.type.spelling == "vr::glSharedTextureHandle_t":
|
|
||||||
v = "(void *)%s" % i
|
v = "(void *)%s" % i
|
||||||
add_parameter_check("ptr", v)
|
elif typename == "bool":
|
||||||
elif param.type.spelling == "bool":
|
|
||||||
v = "1"
|
v = "1"
|
||||||
add_parameter_check("bool", v)
|
elif typename == "float":
|
||||||
elif param.type.spelling == "float":
|
|
||||||
v = "%s.0f" % i
|
v = "%s.0f" % i
|
||||||
add_parameter_check("float", v)
|
elif typename == "HmdRect2":
|
||||||
elif param.type.spelling == "vr::HmdRect2_t":
|
v = "DEFAULT_RECT"
|
||||||
v = "DEFAULT_RECT";
|
elif typename == "HmdVector2":
|
||||||
add_parameter_check("HmdRect2", v)
|
v = "DEFAULT_VECTOR2"
|
||||||
elif param.type.spelling == "vr::HmdVector2_t":
|
elif typename == "HmdVector3":
|
||||||
v = "DEFAULT_VECTOR2";
|
v = "DEFAULT_VECTOR3"
|
||||||
add_parameter_check("HmdVector2", v)
|
elif typename == "HmdColor":
|
||||||
elif param.type.spelling == "vr::HmdVector3_t":
|
v = "DEFAULT_COLOR"
|
||||||
v = "DEFAULT_VECTOR3";
|
else:
|
||||||
add_parameter_check("HmdVector3", v)
|
|
||||||
elif param.type.spelling == "vr::HmdColor_t":
|
|
||||||
v = "DEFAULT_COLOR";
|
|
||||||
add_parameter_check("HmdColor", v)
|
|
||||||
elif param_size == 8:
|
|
||||||
v = str(i)
|
v = str(i)
|
||||||
add_parameter_check("uint64", v)
|
|
||||||
elif param_size == 4 or param_size == 2:
|
|
||||||
v = str(i)
|
|
||||||
add_parameter_check("uint32", v)
|
|
||||||
if not first_param:
|
if not first_param:
|
||||||
f.write(", ")
|
f.write(", ")
|
||||||
first_param = False
|
first_param = False
|
||||||
f.write(v)
|
f.write(v)
|
||||||
|
add_parameter_check(typename, v)
|
||||||
f.write(");\n")
|
f.write(");\n")
|
||||||
for c in parameter_checks:
|
for c in parameter_checks:
|
||||||
f.write(" %s;\n" % c)
|
f.write(" %s;\n" % c)
|
||||||
|
Loading…
Reference in New Issue
Block a user