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>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index c2b36c6..e769858 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -117,7 +117,6 @@
     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 @@
 # 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 @@
     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 @@
             '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 @@
             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 @@
             wire_params = [
                 base_params,
                 api_params,
-                c_params,
                 {
                     'as_wireType': as_wireType,
                     'as_annotated_wireType': lambda arg: annotated(as_wireType(arg.type), arg),
diff --git a/generator/templates/dawn.h b/generator/templates/dawn.h
index 7a68347..bc78835 100644
--- a/generator/templates/dawn.h
+++ b/generator/templates/dawn.h
@@ -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 %}
diff --git a/generator/templates/dawn_native/ProcTable.cpp b/generator/templates/dawn_native/ProcTable.cpp
index 3e13205..9088ce3 100644
--- a/generator/templates/dawn_native/ProcTable.cpp
+++ b/generator/templates/dawn_native/ProcTable.cpp
@@ -37,7 +37,7 @@
     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 @@
             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 @@
         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 %}
diff --git a/generator/templates/dawn_proc.c b/generator/templates/dawn_proc.c
index 2632124..fa0f1c9 100644
--- a/generator/templates/dawn_proc.c
+++ b/generator/templates/dawn_proc.c
@@ -31,7 +31,7 @@
 }
 
 {% 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 -%}
diff --git a/generator/templates/dawn_proc_table.h b/generator/templates/dawn_proc_table.h
index a6a9c88..75304b8 100644
--- a/generator/templates/dawn_proc_table.h
+++ b/generator/templates/dawn_proc_table.h
@@ -21,7 +21,7 @@
     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 %}
 
diff --git a/generator/templates/dawn_wire/client/ApiProcs.cpp b/generator/templates/dawn_wire/client/ApiProcs.cpp
index 1b12552..054d2af 100644
--- a/generator/templates/dawn_wire/client/ApiProcs.cpp
+++ b/generator/templates/dawn_wire/client/ApiProcs.cpp
@@ -99,7 +99,7 @@
             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 @@
         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 %}
diff --git a/generator/templates/dawn_wire/client/ApiProcs.h b/generator/templates/dawn_wire/client/ApiProcs.h
index 69a183f..8f30171 100644
--- a/generator/templates/dawn_wire/client/ApiProcs.h
+++ b/generator/templates/dawn_wire/client/ApiProcs.h
@@ -22,7 +22,7 @@
     //* 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
diff --git a/generator/templates/mock_webgpu.cpp b/generator/templates/mock_webgpu.cpp
index fb92d70..788290b 100644
--- a/generator/templates/mock_webgpu.cpp
+++ b/generator/templates/mock_webgpu.cpp
@@ -18,7 +18,7 @@
 
 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 @@
     *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 %}
diff --git a/generator/templates/webgpu.h b/generator/templates/webgpu.h
index a1dbd96..39eb1bf 100644
--- a/generator/templates/webgpu.h
+++ b/generator/templates/webgpu.h
@@ -103,9 +103,9 @@
 
 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 @@
 
 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 -%}
diff --git a/generator/templates/webgpu_cpp.cpp b/generator/templates/webgpu_cpp.cpp
index f4fa053..400c833 100644
--- a/generator/templates/webgpu_cpp.cpp
+++ b/generator/templates/webgpu_cpp.cpp
@@ -102,7 +102,7 @@
             )
         {%- 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)}};
diff --git a/generator/templates/webgpu_cpp.h b/generator/templates/webgpu_cpp.h
index 67f1643..911a16f 100644
--- a/generator/templates/webgpu_cpp.h
+++ b/generator/templates/webgpu_cpp.h
@@ -164,7 +164,7 @@
             using ObjectBase::ObjectBase;
             using ObjectBase::operator=;
 
-            {% for method in native_methods(type) %}
+            {% for method in type.methods %}
                 {{render_cpp_method_declaration(type, method)}};
             {% endfor %}