[PATCH vkd3d 1/3] vkd3d-shader/hlsl: Set the name for anonymous structures at creation time.

Zebediah Figura zfigura at codeweavers.com
Sun Oct 3 20:51:42 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
This series is kind of an RFC, though, because I'm not actually sure we want to
do this. The obvious benefit is that we get rid of a lot of common boilerplate
that's otherwise pretty hard to sidestep—as shown by the diffstat in patch 3. On
the other hand, we might want to do something like GCC's "x <aka y>", in which
case this would be a step in the wrong direction (and a pretty impactful step at
that.)

(This series also has us taking a bit more memory, but it's not a lot. We
already allocate names for all numeric types, since they aren't keywords.)

 libs/vkd3d-shader/hlsl.y     | 9 +++++++--
 libs/vkd3d-shader/hlsl_sm4.c | 3 +--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 6f1794e79..585331062 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -2075,7 +2075,7 @@ struct_declaration:
 
             if (!$3)
             {
-                if (!$2->name)
+                if (!strcmp($2->name, "<unnamed>"))
                     hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX,
                             "Anonymous struct type must declare a variable.");
                 if (modifiers)
@@ -2116,7 +2116,12 @@ named_struct_spec:
 unnamed_struct_spec:
       KW_STRUCT '{' fields_list '}'
         {
-            $$ = hlsl_new_struct_type(ctx, NULL, $3);
+            char *name;
+
+            if (!(name = hlsl_strdup(ctx, "<unnamed>")))
+                YYABORT;
+
+            $$ = hlsl_new_struct_type(ctx, name, $3);
         }
 
 any_identifier:
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
index 328a8ba1b..8c2bc8f84 100644
--- a/libs/vkd3d-shader/hlsl_sm4.c
+++ b/libs/vkd3d-shader/hlsl_sm4.c
@@ -329,7 +329,6 @@ static D3D_SHADER_VARIABLE_TYPE sm4_base_type(const struct hlsl_type *type)
 static void write_sm4_type(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, struct hlsl_type *type)
 {
     const struct hlsl_type *array_type = get_array_type(type);
-    const char *name = array_type->name ? array_type->name : "<unnamed>";
     const struct hlsl_profile_info *profile = ctx->profile;
     unsigned int field_count = 0, array_size = 0;
     size_t fields_offset = 0, name_offset = 0;
@@ -339,7 +338,7 @@ static void write_sm4_type(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b
         return;
 
     if (profile->major_version >= 5)
-        name_offset = put_string(buffer, name);
+        name_offset = put_string(buffer, array_type->name);
 
     if (type->type == HLSL_CLASS_ARRAY)
         array_size = get_array_size(type);
-- 
2.33.0




More information about the wine-devel mailing list