mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 13:11:00 +00:00
[qfcc] Detect shadowed parameters in glsl
Unfortunately, it breaks detection in Ruamoko and QuakeC.
This commit is contained in:
parent
dae442c91e
commit
3c7bd275f3
3 changed files with 46 additions and 38 deletions
|
@ -550,8 +550,8 @@ initialize_def (symbol_t *sym, const expr_t *init, defspace_t *space,
|
|||
symbol_t *check = symtab_lookup (symtab, sym->name);
|
||||
reloc_t *relocs = 0;
|
||||
|
||||
if (check && symtab->parent && check->table == symtab->parent->parent
|
||||
&& symtab->parent->parent->type == stab_param) {
|
||||
if (check && check->table == symtab->parent
|
||||
&& symtab->parent->type == stab_param) {
|
||||
error (0, "%s shadows a parameter", sym->name);
|
||||
}
|
||||
if (check && check->table == symtab) {
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "tools/qfcc/include/algebra.h"
|
||||
#include "tools/qfcc/include/diagnostic.h"
|
||||
#include "tools/qfcc/include/expr.h"
|
||||
#include "tools/qfcc/include/qfcc.h"
|
||||
#include "tools/qfcc/include/rua-lang.h"
|
||||
#include "tools/qfcc/include/shared.h"
|
||||
#include "tools/qfcc/include/symtab.h"
|
||||
|
@ -221,6 +222,7 @@ proc_decl (const expr_t *expr)
|
|||
list_scatter (&expr->decl.list, decls);
|
||||
for (int i = 0; i < count; i++) {
|
||||
auto decl = decls[i];
|
||||
scoped_src_loc (decl);
|
||||
const expr_t *init = nullptr;
|
||||
symbol_t *sym;
|
||||
if (decl->type == ex_assign) {
|
||||
|
@ -228,11 +230,12 @@ proc_decl (const expr_t *expr)
|
|||
if (decl->assign.dst->type != ex_symbol) {
|
||||
internal_error (decl->assign.dst, "not a symbol");
|
||||
}
|
||||
pr.loc = decl->assign.dst->loc;
|
||||
sym = decl->assign.dst->symbol;
|
||||
} else if (decl->type == ex_symbol) {
|
||||
sym = decl->symbol;
|
||||
} else {
|
||||
internal_error (decl->assign.dst, "not a symbol");
|
||||
internal_error (decl, "not a symbol");
|
||||
}
|
||||
auto spec = expr->decl.spec;
|
||||
if (sym && sym->type) {
|
||||
|
|
|
@ -166,7 +166,7 @@ int yylex (YYSTYPE *yylval, YYLTYPE *yylloc);
|
|||
%token <spec> RESTRICT READONLY WRITEONLY
|
||||
%token <spec> DISCARD COHERENT
|
||||
|
||||
%type <symbol> variable_identifier
|
||||
%type <symbol> variable_identifier new_identifier
|
||||
%type <block> block_declaration
|
||||
%type <expr> declaration constant_expression
|
||||
%type <expr> expression primary_exprsssion assignment_expression
|
||||
|
@ -279,6 +279,7 @@ function_definition
|
|||
{
|
||||
$<symtab>$ = current_symtab;
|
||||
auto spec = $1;
|
||||
spec.sym->params = spec.params;
|
||||
auto sym = function_symbol (spec);
|
||||
current_func = begin_function (sym, nullptr, current_symtab,
|
||||
false, spec.storage);
|
||||
|
@ -303,6 +304,10 @@ variable_identifier
|
|||
: IDENTIFIER
|
||||
;
|
||||
|
||||
new_identifier
|
||||
: IDENTIFIER { $$ = new_symbol ($1->name); }
|
||||
;
|
||||
|
||||
primary_exprsssion
|
||||
: variable_identifier { $$ = new_symbol_expr ($1); }
|
||||
| VALUE
|
||||
|
@ -588,24 +593,24 @@ declaration
|
|||
}
|
||||
$$ = nullptr;
|
||||
}
|
||||
| type_qualifier block_declaration IDENTIFIER ';'
|
||||
| type_qualifier block_declaration new_identifier ';'
|
||||
{
|
||||
if (current_symtab != pr.symtab) {
|
||||
error (0, "blocks must be declared globally");
|
||||
} else {
|
||||
auto block = $block_declaration;
|
||||
auto instance_name = $IDENTIFIER;
|
||||
auto instance_name = $new_identifier;
|
||||
glsl_declare_block_instance (block, instance_name);
|
||||
}
|
||||
$$ = nullptr;
|
||||
}
|
||||
| type_qualifier block_declaration IDENTIFIER array_specifier ';'
|
||||
| type_qualifier block_declaration new_identifier array_specifier ';'
|
||||
{
|
||||
if (current_symtab != pr.symtab) {
|
||||
error (0, "blocks must be declared globally");
|
||||
} else {
|
||||
auto block = $block_declaration;
|
||||
auto instance_name = $IDENTIFIER;
|
||||
auto instance_name = $new_identifier;
|
||||
instance_name->type = $array_specifier;
|
||||
glsl_declare_block_instance (block, instance_name);
|
||||
}
|
||||
|
@ -617,15 +622,15 @@ declaration
|
|||
nullptr, current_symtab);
|
||||
$$ = nullptr;
|
||||
}
|
||||
| type_qualifier IDENTIFIER ';'
|
||||
| type_qualifier new_identifier ';'
|
||||
{
|
||||
auto decl = new_decl_expr ($type_qualifier);
|
||||
$$ = append_decl (decl, $IDENTIFIER, nullptr);
|
||||
$$ = append_decl (decl, $new_identifier, nullptr);
|
||||
}
|
||||
| type_qualifier IDENTIFIER identifier_list ';'
|
||||
| type_qualifier new_identifier identifier_list ';'
|
||||
{
|
||||
auto decl = new_decl_expr ($type_qualifier);
|
||||
append_decl (decl, $IDENTIFIER, nullptr);
|
||||
append_decl (decl, $new_identifier, nullptr);
|
||||
$$ = append_decl_list (decl, $identifier_list);
|
||||
}
|
||||
;
|
||||
|
@ -654,12 +659,12 @@ block_declaration
|
|||
;
|
||||
|
||||
identifier_list
|
||||
: ',' IDENTIFIER
|
||||
: ',' new_identifier
|
||||
{
|
||||
auto expr = new_symbol_expr ($2);
|
||||
$$ = new_list_expr (expr);
|
||||
}
|
||||
| identifier_list ',' IDENTIFIER
|
||||
| identifier_list ',' new_identifier
|
||||
{
|
||||
auto expr = new_symbol_expr ($3);
|
||||
$$ = expr_append_expr ($1, expr);
|
||||
|
@ -696,7 +701,7 @@ function_header_with_parameters
|
|||
;
|
||||
|
||||
function_header
|
||||
: fully_specified_type IDENTIFIER '('
|
||||
: fully_specified_type new_identifier '('
|
||||
{
|
||||
auto spec = $1;
|
||||
if ($2->table) {
|
||||
|
@ -709,11 +714,11 @@ function_header
|
|||
;
|
||||
|
||||
parameter_declarator
|
||||
: type_specifier IDENTIFIER
|
||||
: type_specifier new_identifier
|
||||
{
|
||||
$$ = new_param (nullptr, $1.type, $2->name);
|
||||
}
|
||||
| type_specifier IDENTIFIER array_specifier
|
||||
| type_specifier new_identifier array_specifier
|
||||
{
|
||||
$$ = new_param (nullptr, append_type ($1.type, $3), $2->name);
|
||||
}
|
||||
|
@ -735,27 +740,27 @@ parameter_type_specifier
|
|||
|
||||
init_declarator_list
|
||||
: single_declaration
|
||||
| init_declarator_list ',' IDENTIFIER
|
||||
| init_declarator_list ',' new_identifier
|
||||
{
|
||||
auto decl = $1;
|
||||
$$ = append_decl (decl, $IDENTIFIER, nullptr);
|
||||
$$ = append_decl (decl, $new_identifier, nullptr);
|
||||
}
|
||||
| init_declarator_list ',' IDENTIFIER array_specifier
|
||||
| init_declarator_list ',' new_identifier array_specifier
|
||||
{
|
||||
auto decl = $1;
|
||||
$IDENTIFIER->type = $array_specifier;
|
||||
$$ = append_decl (decl, $IDENTIFIER, nullptr);
|
||||
$new_identifier->type = $array_specifier;
|
||||
$$ = append_decl (decl, $new_identifier, nullptr);
|
||||
}
|
||||
| init_declarator_list ',' IDENTIFIER array_specifier '=' initializer
|
||||
| init_declarator_list ',' new_identifier array_specifier '=' initializer
|
||||
{
|
||||
auto decl = $1;
|
||||
$IDENTIFIER->type = $array_specifier;
|
||||
$$ = append_decl (decl, $IDENTIFIER, $initializer);
|
||||
$new_identifier->type = $array_specifier;
|
||||
$$ = append_decl (decl, $new_identifier, $initializer);
|
||||
}
|
||||
| init_declarator_list ',' IDENTIFIER '=' initializer
|
||||
| init_declarator_list ',' new_identifier '=' initializer
|
||||
{
|
||||
auto decl = $1;
|
||||
$$ = append_decl (decl, $IDENTIFIER, $initializer);
|
||||
$$ = append_decl (decl, $new_identifier, $initializer);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -764,31 +769,31 @@ single_declaration
|
|||
{
|
||||
$$ = new_decl_expr ($fully_specified_type);
|
||||
}
|
||||
| fully_specified_type IDENTIFIER
|
||||
| fully_specified_type new_identifier
|
||||
{
|
||||
auto decl = new_decl_expr ($fully_specified_type);
|
||||
$$ = append_decl (decl, $IDENTIFIER, nullptr);
|
||||
$$ = append_decl (decl, $new_identifier, nullptr);
|
||||
}
|
||||
| fully_specified_type IDENTIFIER array_specifier
|
||||
| fully_specified_type new_identifier array_specifier
|
||||
{
|
||||
auto spec = $fully_specified_type;
|
||||
spec.type = append_type ($array_specifier, spec.type);
|
||||
spec.type = find_type (spec.type);
|
||||
auto decl = new_decl_expr (spec);
|
||||
$$ = append_decl (decl, $IDENTIFIER, nullptr);
|
||||
$$ = append_decl (decl, $new_identifier, nullptr);
|
||||
}
|
||||
| fully_specified_type IDENTIFIER array_specifier '=' initializer
|
||||
| fully_specified_type new_identifier array_specifier '=' initializer
|
||||
{
|
||||
auto spec = $fully_specified_type;
|
||||
spec.type = append_type ($array_specifier, spec.type);
|
||||
spec.type = find_type (spec.type);
|
||||
auto decl = new_decl_expr (spec);
|
||||
$$ = append_decl (decl, $IDENTIFIER, $initializer);
|
||||
$$ = append_decl (decl, $new_identifier, $initializer);
|
||||
}
|
||||
| fully_specified_type IDENTIFIER '=' initializer
|
||||
| fully_specified_type new_identifier '=' initializer
|
||||
{
|
||||
auto decl = new_decl_expr ($fully_specified_type);
|
||||
$$ = append_decl (decl, $IDENTIFIER, $initializer);
|
||||
$$ = append_decl (decl, $new_identifier, $initializer);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -1004,13 +1009,13 @@ struct_declarator_list
|
|||
;
|
||||
|
||||
struct_declarator
|
||||
: IDENTIFIER
|
||||
: new_identifier
|
||||
{
|
||||
auto spec = $<spec>0;
|
||||
spec.sym = $1;
|
||||
glsl_declare_field (spec, current_symtab);
|
||||
}
|
||||
| IDENTIFIER array_specifier
|
||||
| new_identifier array_specifier
|
||||
{
|
||||
auto spec = $<spec>0;
|
||||
spec.type = append_type ($2, spec.type);
|
||||
|
@ -1143,7 +1148,7 @@ else
|
|||
|
||||
condition
|
||||
: expression
|
||||
| fully_specified_type IDENTIFIER '=' initializer
|
||||
| fully_specified_type new_identifier '=' initializer
|
||||
{
|
||||
auto symtab = current_symtab;
|
||||
auto space = symtab->space;
|
||||
|
|
Loading…
Reference in a new issue