Remove the concept of "native_methods" in the generators
This was used to make the distinction between native-only methods that were those manipulating "natively defined" types, and the rest. Now that all "natively defined" objects are "callback" instead this name didn't make sense. The only relevant thing is that in C there are the Reference and Release methods that don't appear in dawn.json and shouldn't be exposed on C++ objects. Hence most of the native_methods() calls in the templates are updated to be c_methods() calls except for the webgpu_cpp templates that use type.methods directly. BUG=dawn:22 Change-Id: I65c160b8b8a829e4728862c65bc67268a46f445e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13902 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
parent
540ababb6b
commit
aca8c4a528
|
@ -117,7 +117,6 @@ class ObjectType(Type):
|
|||
def __init__(self, name, json_data):
|
||||
Type.__init__(self, name, json_data)
|
||||
self.methods = []
|
||||
self.native_methods = []
|
||||
self.built_type = None
|
||||
|
||||
class Record:
|
||||
|
@ -185,19 +184,13 @@ def linked_record_members(json_data, types):
|
|||
# PARSE
|
||||
############################################################
|
||||
|
||||
def is_native_method(method):
|
||||
return method.return_type.category == "natively defined" or \
|
||||
any([arg.type.category == "natively defined" for arg in method.arguments])
|
||||
|
||||
def link_object(obj, types):
|
||||
def make_method(json_data):
|
||||
arguments = linked_record_members(json_data.get('args', []), types)
|
||||
return Method(Name(json_data['name']), types[json_data.get('returns', 'void')], arguments)
|
||||
|
||||
methods = [make_method(m) for m in obj.json_data.get('methods', [])]
|
||||
obj.methods = [method for method in methods if not is_native_method(method)]
|
||||
obj.methods = [make_method(m) for m in obj.json_data.get('methods', [])]
|
||||
obj.methods.sort(key=lambda method: method.name.canonical_case())
|
||||
obj.native_methods = [method for method in methods if is_native_method(method)]
|
||||
|
||||
def link_structure(struct, types):
|
||||
struct.members = linked_record_members(struct.json_data['members'], types)
|
||||
|
@ -471,19 +464,16 @@ def as_wireType(typ):
|
|||
else:
|
||||
return as_cppType(typ.name)
|
||||
|
||||
def cpp_native_methods(types, typ):
|
||||
return sorted(typ.methods + typ.native_methods, key=lambda method: method.name.canonical_case())
|
||||
|
||||
def c_native_methods(types, typ):
|
||||
return cpp_native_methods(types, typ) + [
|
||||
def c_methods(types, typ):
|
||||
return typ.methods + [
|
||||
Method(Name('reference'), types['void'], []),
|
||||
Method(Name('release'), types['void'], []),
|
||||
]
|
||||
|
||||
def get_methods_sorted_by_name(api_params):
|
||||
def get_c_methods_sorted_by_name(api_params):
|
||||
unsorted = [(as_MethodSuffix(typ.name, method.name), typ, method) \
|
||||
for typ in api_params['by_category']['object'] \
|
||||
for method in c_native_methods(api_params['types'], typ) ]
|
||||
for method in c_methods(api_params['types'], typ) ]
|
||||
return [(typ, method) for (_, typ, method) in sorted(unsorted)]
|
||||
|
||||
def has_callback_arguments(method):
|
||||
|
@ -531,34 +521,31 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||
'convert_cType_to_cppType': convert_cType_to_cppType,
|
||||
'as_varName': as_varName,
|
||||
'decorate': decorate,
|
||||
'methods_sorted_by_name': get_methods_sorted_by_name(api_params),
|
||||
'c_methods': lambda typ: c_methods(api_params['types'], typ),
|
||||
'c_methods_sorted_by_name': get_c_methods_sorted_by_name(api_params),
|
||||
}
|
||||
|
||||
renders = []
|
||||
|
||||
c_params = {'native_methods': lambda typ: c_native_methods(api_params['types'], typ)}
|
||||
cpp_params = {'native_methods': lambda typ: cpp_native_methods(api_params['types'], typ)}
|
||||
|
||||
if 'dawn_headers' in targets:
|
||||
renders.append(FileRender('webgpu.h', 'src/include/dawn/webgpu.h', [base_params, api_params, c_params]))
|
||||
renders.append(FileRender('dawn.h', 'src/include/dawn/dawn.h', [base_params, api_params, c_params]))
|
||||
renders.append(FileRender('dawn_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params, c_params]))
|
||||
renders.append(FileRender('webgpu.h', 'src/include/dawn/webgpu.h', [base_params, api_params]))
|
||||
renders.append(FileRender('dawn.h', 'src/include/dawn/dawn.h', [base_params, api_params]))
|
||||
renders.append(FileRender('dawn_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params]))
|
||||
|
||||
if 'dawncpp_headers' in targets:
|
||||
renders.append(FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.h', [base_params, api_params, cpp_params]))
|
||||
renders.append(FileRender('dawncpp.h', 'src/include/dawn/dawncpp.h', [base_params, api_params, cpp_params]))
|
||||
renders.append(FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.h', [base_params, api_params]))
|
||||
renders.append(FileRender('dawncpp.h', 'src/include/dawn/dawncpp.h', [base_params, api_params]))
|
||||
|
||||
if 'dawn_proc' in targets:
|
||||
renders.append(FileRender('dawn_proc.c', 'src/dawn/dawn_proc.c', [base_params, api_params, c_params]))
|
||||
renders.append(FileRender('dawn_proc.c', 'src/dawn/dawn_proc.c', [base_params, api_params]))
|
||||
|
||||
if 'dawncpp' in targets:
|
||||
renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params, cpp_params]))
|
||||
renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params]))
|
||||
|
||||
if 'mock_webgpu' in targets:
|
||||
mock_params = [
|
||||
base_params,
|
||||
api_params,
|
||||
c_params,
|
||||
{
|
||||
'has_callback_arguments': has_callback_arguments
|
||||
}
|
||||
|
@ -570,7 +557,6 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||
frontend_params = [
|
||||
base_params,
|
||||
api_params,
|
||||
c_params,
|
||||
{
|
||||
'as_frontendType': lambda typ: as_frontendType(typ), # TODO as_frontendType and friends take a Type and not a Name :(
|
||||
'as_annotated_frontendType': lambda arg: annotated(as_frontendType(arg.type), arg)
|
||||
|
@ -589,7 +575,6 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||
wire_params = [
|
||||
base_params,
|
||||
api_params,
|
||||
c_params,
|
||||
{
|
||||
'as_wireType': as_wireType,
|
||||
'as_annotated_wireType': lambda arg: annotated(as_wireType(arg.type), arg),
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
{% for type in by_category["object"] %}
|
||||
typedef {{as_cType(type.name)}} {{as_cTypeDawn(type.name)}};
|
||||
typedef {{as_cType(type.name)}}Impl {{as_cTypeDawn(type.name)}}Impl;
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
typedef {{as_cProc(type.name, method.name)}} {{as_cProcDawn(type.name, method.name)}};
|
||||
#define {{as_cMethodDawn(type.name, method.name)}} {{as_cMethod(type.name, method.name)}}
|
||||
{% endfor %}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace dawn_native {
|
|||
namespace {
|
||||
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
{% set suffix = as_MethodSuffix(type.name, method.name) %}
|
||||
|
||||
{{as_cType(method.return_type.name)}} Native{{suffix}}(
|
||||
|
@ -85,7 +85,7 @@ namespace dawn_native {
|
|||
const char* name;
|
||||
};
|
||||
static const ProcEntry sProcMap[] = {
|
||||
{% for (type, method) in methods_sorted_by_name %}
|
||||
{% for (type, method) in c_methods_sorted_by_name %}
|
||||
{ reinterpret_cast<WGPUProc>(Native{{as_MethodSuffix(type.name, method.name)}}), "{{as_cMethod(type.name, method.name)}}" },
|
||||
{% endfor %}
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ namespace dawn_native {
|
|||
DawnProcTable table;
|
||||
table.getProcAddress = NativeGetProcAddress;
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
table.{{as_varName(type.name, method.name)}} = Native{{as_MethodSuffix(type.name, method.name)}};
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -31,7 +31,7 @@ WGPUProc WGPUGetProcAddress(WGPUDevice device, const char* procName) {
|
|||
}
|
||||
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
{{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
|
||||
{{-as_cType(type.name)}} {{as_varName(type.name)}}
|
||||
{%- for arg in method.arguments -%}
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef struct DawnProcTable {
|
|||
WGPUProcGetProcAddress getProcAddress;
|
||||
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
{{as_cProc(type.name, method.name)}} {{as_varName(type.name, method.name)}};
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace dawn_wire { namespace client {
|
|||
const char* name;
|
||||
};
|
||||
static const ProcEntry sProcMap[] = {
|
||||
{% for (type, method) in methods_sorted_by_name %}
|
||||
{% for (type, method) in c_methods_sorted_by_name %}
|
||||
{ reinterpret_cast<WGPUProc>(Client{{as_MethodSuffix(type.name, method.name)}}), "{{as_cMethod(type.name, method.name)}}" },
|
||||
{% endfor %}
|
||||
};
|
||||
|
@ -146,7 +146,7 @@ namespace dawn_wire { namespace client {
|
|||
DawnProcTable table;
|
||||
table.getProcAddress = ClientGetProcAddress;
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
{% set suffix = as_MethodSuffix(type.name, method.name) %}
|
||||
table.{{as_varName(type.name, method.name)}} = Client{{suffix}};
|
||||
{% endfor %}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace dawn_wire { namespace client {
|
|||
//* Dawn API
|
||||
{% for type in by_category["object"] %}
|
||||
{% set cType = as_cType(type.name) %}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
{% set Suffix = as_MethodSuffix(type.name, method.name) %}
|
||||
{{as_cType(method.return_type.name)}} Client{{Suffix}}(
|
||||
{{-cType}} cSelf
|
||||
|
|
|
@ -18,7 +18,7 @@ using namespace testing;
|
|||
|
||||
namespace {
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) if len(method.arguments) < 10 %}
|
||||
{% for method in c_methods(type) if len(method.arguments) < 10 %}
|
||||
{{as_cType(method.return_type.name)}} Forward{{as_MethodSuffix(type.name, method.name)}}(
|
||||
{{-as_cType(type.name)}} self
|
||||
{%- for arg in method.arguments -%}
|
||||
|
@ -44,7 +44,7 @@ void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* d
|
|||
*device = GetNewDevice();
|
||||
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) if len(method.arguments) < 10 %}
|
||||
{% for method in c_methods(type) if len(method.arguments) < 10 %}
|
||||
table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}});
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -103,9 +103,9 @@ typedef void (*WGPUProc)();
|
|||
|
||||
typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, const char* procName);
|
||||
|
||||
{% for type in by_category["object"] if len(native_methods(type)) > 0 %}
|
||||
{% for type in by_category["object"] if len(c_methods(type)) > 0 %}
|
||||
// Procs of {{type.name.CamelCase()}}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})(
|
||||
{{-as_cType(type.name)}} {{as_varName(type.name)}}
|
||||
{%- for arg in method.arguments -%}
|
||||
|
@ -121,9 +121,9 @@ typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, const char* procNa
|
|||
|
||||
WGPU_EXPORT WGPUProc WGPUGetProcAddress(WGPUDevice device, const char* procName);
|
||||
|
||||
{% for type in by_category["object"] if len(native_methods(type)) > 0 %}
|
||||
{% for type in by_category["object"] if len(c_methods(type)) > 0 %}
|
||||
// Methods of {{type.name.CamelCase()}}
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in c_methods(type) %}
|
||||
WGPU_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
|
||||
{{-as_cType(type.name)}} {{as_varName(type.name)}}
|
||||
{%- for arg in method.arguments -%}
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace wgpu {
|
|||
)
|
||||
{%- endmacro %}
|
||||
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in type.methods %}
|
||||
{{render_cpp_method_declaration(type, method)}} {
|
||||
{% if method.return_type.name.concatcase() == "void" %}
|
||||
{{render_cpp_to_c_method_call(type, method)}};
|
||||
|
|
|
@ -164,7 +164,7 @@ namespace wgpu {
|
|||
using ObjectBase::ObjectBase;
|
||||
using ObjectBase::operator=;
|
||||
|
||||
{% for method in native_methods(type) %}
|
||||
{% for method in type.methods %}
|
||||
{{render_cpp_method_declaration(type, method)}};
|
||||
{% endfor %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue