ARB prog parser: Differentiate between used and unused names in the lexer

The lexer will return IDENTIFIER only when the name does not have an
associated symbol.  Otherwise USED_IDENTIFIER is returned.
This commit is contained in:
Ian Romanick
2009-09-10 14:35:33 -07:00
parent d0adebb8d5
commit 0e7953366f
5 changed files with 851 additions and 834 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -39,8 +39,7 @@
if (condition) { \
return token; \
} else { \
yylval->string = strdup(yytext); \
return IDENTIFIER; \
return handle_ident(yyextra, yytext, yylval); \
} \
} while (0)
@@ -64,8 +63,7 @@
yylval->temp_inst.Opcode = OPCODE_ ## opcode; \
return token; \
} else { \
yylval->string = strdup(yytext); \
return IDENTIFIER; \
return handle_ident(yyextra, yytext, yylval); \
} \
} while (0)
@@ -114,6 +112,15 @@ swiz_from_char(char c)
return 0;
}
static int
handle_ident(struct asm_parser_state *state, const char *text, YYSTYPE *lval)
{
lval->string = strdup(text);
return (_mesa_symbol_table_find_symbol(state->st, 0, text) == NULL)
? IDENTIFIER : USED_IDENTIFIER;
}
#define YY_USER_ACTION \
do { \
yylloc->first_column = yylloc->last_column; \
@@ -299,10 +306,7 @@ ARRAY2D { return_token_or_IDENTIFIER(require_ARB_fp && require
ARRAYSHADOW1D { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW1D); }
ARRAYSHADOW2D { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW2D); }
[_a-zA-Z$][_a-zA-Z0-9$]* {
yylval->string = strdup(yytext);
return IDENTIFIER;
}
[_a-zA-Z$][_a-zA-Z0-9$]* { return handle_ident(yyextra, yytext, yylval); }
".." { return DOT_DOT; }

File diff suppressed because it is too large Load Diff

View File

@@ -136,13 +136,14 @@
VTXATTRIB = 352,
WEIGHT = 353,
IDENTIFIER = 354,
MASK4 = 355,
MASK3 = 356,
MASK2 = 357,
MASK1 = 358,
SWIZZLE = 359,
DOT_DOT = 360,
DOT = 361
USED_IDENTIFIER = 355,
MASK4 = 356,
MASK3 = 357,
MASK2 = 358,
MASK1 = 359,
SWIZZLE = 360,
DOT_DOT = 361,
DOT = 362
};
#endif
@@ -182,7 +183,7 @@ typedef union YYSTYPE
/* Line 1676 of yacc.c */
#line 186 "program_parse.tab.h"
#line 187 "program_parse.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */

View File

@@ -178,7 +178,8 @@ static struct asm_instruction *asm_instruction_copy_ctor(
%token VERTEX VTXATTRIB
%token WEIGHT
%token <string> IDENTIFIER
%token <string> IDENTIFIER USED_IDENTIFIER
%type <string> string
%token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE
%token DOT_DOT
%token DOT
@@ -289,7 +290,7 @@ optionSequence: optionSequence option
|
;
option: OPTION IDENTIFIER ';'
option: OPTION string ';'
{
int valid = 0;
@@ -692,7 +693,7 @@ extSwizSel: INTEGER
$$.xyzw_valid = 1;
$$.rgba_valid = 1;
}
| IDENTIFIER
| string
{
if (strlen($1) > 1) {
yyerror(& @1, state, "invalid extended swizzle selector");
@@ -742,7 +743,7 @@ extSwizSel: INTEGER
}
;
srcReg: IDENTIFIER /* temporaryReg | progParamSingle */
srcReg: USED_IDENTIFIER /* temporaryReg | progParamSingle */
{
struct asm_symbol *const s = (struct asm_symbol *)
_mesa_symbol_table_find_symbol(state->st, 0, $1);
@@ -832,7 +833,7 @@ dstReg: resultBinding
$$.File = PROGRAM_OUTPUT;
$$.Index = $1;
}
| IDENTIFIER /* temporaryReg | vertexResultReg */
| USED_IDENTIFIER /* temporaryReg | vertexResultReg */
{
struct asm_symbol *const s = (struct asm_symbol *)
_mesa_symbol_table_find_symbol(state->st, 0, $1);
@@ -863,7 +864,7 @@ dstReg: resultBinding
}
;
progParamArray: IDENTIFIER
progParamArray: USED_IDENTIFIER
{
struct asm_symbol *const s = (struct asm_symbol *)
_mesa_symbol_table_find_symbol(state->st, 0, $1);
@@ -930,7 +931,7 @@ addrRegNegOffset: INTEGER
}
;
addrReg: IDENTIFIER
addrReg: USED_IDENTIFIER
{
struct asm_symbol *const s = (struct asm_symbol *)
_mesa_symbol_table_find_symbol(state->st, 0, $1);
@@ -1814,7 +1815,7 @@ optionalSign: '+' { $$ = FALSE; }
TEMP_statement: optVarSize TEMP { $<integer>$ = $2; } varNameList
;
optVarSize: IDENTIFIER
optVarSize: string
{
/* NV_fragment_program_option defines the size qualifiers in a
* fairly broken way. "SHORT" or "LONG" can optionally be used
@@ -2045,7 +2046,7 @@ legacyTexUnitNum: INTEGER
}
;
ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
ALIAS_statement: ALIAS IDENTIFIER '=' USED_IDENTIFIER
{
struct asm_symbol *exist = (struct asm_symbol *)
_mesa_symbol_table_find_symbol(state->st, 0, $2);
@@ -2066,6 +2067,10 @@ ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
}
;
string: IDENTIFIER
| USED_IDENTIFIER
;
%%
void