mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Factor out the error message into hlsl_add_var().
This commit is contained in:
committed by
Henri Verbeet
parent
2863d86bcc
commit
e40d4a0e12
Notes:
Henri Verbeet
2025-01-29 18:04:53 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1359
@@ -103,9 +103,15 @@ bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl)
|
|||||||
LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry)
|
LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry)
|
||||||
{
|
{
|
||||||
if (var->name && !strcmp(decl->name, var->name))
|
if (var->name && !strcmp(decl->name, var->name))
|
||||||
|
{
|
||||||
|
hlsl_error(ctx, &decl->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
||||||
|
"Identifier \"%s\" was already declared in this scope.", var->name);
|
||||||
|
hlsl_note(ctx, &var->loc, VKD3D_SHADER_LOG_ERROR, "\"%s\" was previously declared here.", var->name);
|
||||||
|
hlsl_free_var(decl);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
list_add_tail(&scope->vars, &decl->scope_entry);
|
list_add_tail(&scope->vars, &decl->scope_entry);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -1312,10 +1312,7 @@ static bool add_func_parameter(struct hlsl_ctx *ctx, struct hlsl_func_parameters
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hlsl_add_var(ctx, var))
|
if (!hlsl_add_var(ctx, var))
|
||||||
{
|
|
||||||
hlsl_free_var(var);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (!hlsl_array_reserve(ctx, (void **)¶meters->vars, ¶meters->capacity,
|
if (!hlsl_array_reserve(ctx, (void **)¶meters->vars, ¶meters->capacity,
|
||||||
parameters->count + 1, sizeof(*parameters->vars)))
|
parameters->count + 1, sizeof(*parameters->vars)))
|
||||||
@@ -1340,18 +1337,7 @@ static bool add_pass(struct hlsl_ctx *ctx, const char *name, struct hlsl_scope *
|
|||||||
var->state_block_count = 1;
|
var->state_block_count = 1;
|
||||||
var->state_block_capacity = 1;
|
var->state_block_capacity = 1;
|
||||||
|
|
||||||
if (!hlsl_add_var(ctx, var))
|
return hlsl_add_var(ctx, var);
|
||||||
{
|
|
||||||
struct hlsl_ir_var *old = hlsl_get_var(ctx->cur_scope, var->name);
|
|
||||||
|
|
||||||
hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
|
||||||
"Identifier \"%s\" was already declared in this scope.", var->name);
|
|
||||||
hlsl_note(ctx, &old->loc, VKD3D_SHADER_LOG_ERROR, "\"%s\" was previously declared here.", old->name);
|
|
||||||
hlsl_free_var(var);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_technique(struct hlsl_ctx *ctx, const char *name, struct hlsl_scope *scope,
|
static bool add_technique(struct hlsl_ctx *ctx, const char *name, struct hlsl_scope *scope,
|
||||||
@@ -1366,18 +1352,7 @@ static bool add_technique(struct hlsl_ctx *ctx, const char *name, struct hlsl_sc
|
|||||||
var->scope = scope;
|
var->scope = scope;
|
||||||
var->annotations = annotations;
|
var->annotations = annotations;
|
||||||
|
|
||||||
if (!hlsl_add_var(ctx, var))
|
return hlsl_add_var(ctx, var);
|
||||||
{
|
|
||||||
struct hlsl_ir_var *old = hlsl_get_var(ctx->cur_scope, var->name);
|
|
||||||
|
|
||||||
hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
|
||||||
"Identifier \"%s\" was already declared in this scope.", var->name);
|
|
||||||
hlsl_note(ctx, &old->loc, VKD3D_SHADER_LOG_ERROR, "\"%s\" was previously declared here.", old->name);
|
|
||||||
hlsl_free_var(var);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_effect_group(struct hlsl_ctx *ctx, const char *name, struct hlsl_scope *scope,
|
static bool add_effect_group(struct hlsl_ctx *ctx, const char *name, struct hlsl_scope *scope,
|
||||||
@@ -1392,18 +1367,7 @@ static bool add_effect_group(struct hlsl_ctx *ctx, const char *name, struct hlsl
|
|||||||
var->scope = scope;
|
var->scope = scope;
|
||||||
var->annotations = annotations;
|
var->annotations = annotations;
|
||||||
|
|
||||||
if (!hlsl_add_var(ctx, var))
|
return hlsl_add_var(ctx, var);
|
||||||
{
|
|
||||||
struct hlsl_ir_var *old = hlsl_get_var(ctx->cur_scope, var->name);
|
|
||||||
|
|
||||||
hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
|
||||||
"Identifier \"%s\" was already declared in this scope.", var->name);
|
|
||||||
hlsl_note(ctx, &old->loc, VKD3D_SHADER_LOG_ERROR, "\"%s\" was previously declared here.", old->name);
|
|
||||||
hlsl_free_var(var);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_reservation_index(struct hlsl_ctx *ctx, const char *string, unsigned int bracket_offset,
|
static bool parse_reservation_index(struct hlsl_ctx *ctx, const char *string, unsigned int bracket_offset,
|
||||||
@@ -2787,16 +2751,7 @@ static void declare_var(struct hlsl_ctx *ctx, struct parse_variable_def *v)
|
|||||||
"Static variables cannot have both numeric and resource components.");
|
"Static variables cannot have both numeric and resource components.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hlsl_add_var(ctx, var))
|
hlsl_add_var(ctx, var);
|
||||||
{
|
|
||||||
struct hlsl_ir_var *old = hlsl_get_var(ctx->cur_scope, var->name);
|
|
||||||
|
|
||||||
hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
|
||||||
"Variable \"%s\" was already declared in this scope.", var->name);
|
|
||||||
hlsl_note(ctx, &old->loc, VKD3D_SHADER_LOG_ERROR, "\"%s\" was previously declared here.", old->name);
|
|
||||||
hlsl_free_var(var);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var_list)
|
static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var_list)
|
||||||
@@ -8108,12 +8063,8 @@ param_list:
|
|||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
if (!add_func_parameter(ctx, &$$, &$3, &@3))
|
if (!add_func_parameter(ctx, &$$, &$3, &@3))
|
||||||
{
|
|
||||||
hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
|
||||||
"Parameter \"%s\" is already declared.", $3.name);
|
|
||||||
YYABORT;
|
YYABORT;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
parameter:
|
parameter:
|
||||||
parameter_decl
|
parameter_decl
|
||||||
|
Reference in New Issue
Block a user