webgpu.h: Apply WGPU_NULLABLE only on pointers.
Also fixes WGPU_NULLABLE for freestanding functions only appearing in
the fnptr declarations and not the prototypes.
Bug: 42241188
Change-Id: I74af399da4be2b46a7c0518b2af6813b5602d371
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/208275
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/generator/templates/api.h b/generator/templates/api.h
index 04047c1..7cc4806 100644
--- a/generator/templates/api.h
+++ b/generator/templates/api.h
@@ -172,6 +172,11 @@
         {}
     {%- endif -%}
 {% endmacro %}
+{% macro nullable_annotation(record) -%}
+    {% if record.optional and (record.type.category == "object" or record.annotation != "value") -%}
+        {{API}}_NULLABLE{{" "}}
+    {%- endif %}
+{%- endmacro %}
 
 #define {{API}}_COMMA ,
 
@@ -210,11 +215,7 @@
             {{API}}ChainedStruct{{Out}} chain;
         {% endif %}
         {% for member in type.members %}
-            {% if member.optional %}
-                {{API}}_NULLABLE {{as_annotated_cType(member)}};
-            {% else %}
-                {{as_annotated_cType(member)}};
-            {% endif-%}
+            {{nullable_annotation(member)}}{{as_annotated_cType(member)}};
         {% endfor %}
     } {{as_cType(type.name)}} {{API}}_STRUCTURE_ATTRIBUTE;
 
@@ -246,7 +247,8 @@
 {% for function in by_category["function"] %}
     typedef {{as_cType(function.return_type.name)}} (*{{as_cProc(None, function.name)}})(
             {%- for arg in function.arguments -%}
-                {% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
+                {% if not loop.first %}, {% endif %}
+                {{nullable_annotation(arg)}}{{as_annotated_cType(arg)}}
             {%- endfor -%}
         ) {{API}}_FUNCTION_ATTRIBUTE;
 {% endfor %}
@@ -257,9 +259,7 @@
         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 -%}
-                ,{{" "}}
-                {%- if arg.optional %}{{API}}_NULLABLE {% endif -%}
-                {{as_annotated_cType(arg)}}
+                , {{nullable_annotation(arg)}}{{as_annotated_cType(arg)}}
             {%- endfor -%}
         ) {{API}}_FUNCTION_ATTRIBUTE;
     {% endfor %}
@@ -274,8 +274,7 @@
     {{API}}_EXPORT {{as_cType(function.return_type.name)}} {{as_cMethod(None, function.name)}}(
             {%- for arg in function.arguments -%}
                 {% if not loop.first %}, {% endif -%}
-                {%- if arg.optional %}{{API}}_NULLABLE {% endif -%}
-                {{as_annotated_cType(arg)}}
+                {{nullable_annotation(arg)}}{{as_annotated_cType(arg)}}
             {%- endfor -%}
         ) {{API}}_FUNCTION_ATTRIBUTE;
 {% endfor %}
@@ -286,9 +285,7 @@
         {{API}}_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 -%}
-                ,{{" "}}
-                {%- if arg.optional %}{{API}}_NULLABLE {% endif -%}
-                {{as_annotated_cType(arg)}}
+                , {{nullable_annotation(arg)}}{{as_annotated_cType(arg)}}
             {%- endfor -%}
         ) {{API}}_FUNCTION_ATTRIBUTE;
     {% endfor %}