From 18c589d20ea684f6415b28d563fd2edaae0d7b2c Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 25 Jun 2014 13:55:18 -0700 Subject: [PATCH] glsl/glcpp: Drop the HASH_ prefix from token names like HASH_IF Previously, we had a single token for "#if" but now that we have two separate tokens, it looks much better to see: HASH_TOKEN IF than: HASH_TOKEN HASH_IF (Note, that for the same reason we use HASH_TOKEN instead of HASH, we also use DEFINE_TOKEN instead of DEFINE to avoid a conflict with the start condition in the lexer.) There should be no behavioral change from this commit. Reviewed-by: Jordan Justen --- src/glsl/glcpp/glcpp-lex.l | 26 +++++++++--------- src/glsl/glcpp/glcpp-parse.y | 51 ++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index 60bc0800b2d..466f4386053 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -280,7 +280,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? version{HSPACE}+ { BEGIN INITIAL; yyextra->space_tokens = 0; - RETURN_STRING_TOKEN (HASH_VERSION); + RETURN_STRING_TOKEN (VERSION_TOKEN); } /* glcpp doesn't handle #extension, #version, or #pragma directives. @@ -289,12 +289,12 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? BEGIN INITIAL; yylineno++; yycolumn = 0; - RETURN_STRING_TOKEN (HASH_PRAGMA); + RETURN_STRING_TOKEN (PRAGMA); } line{HSPACE}+ { BEGIN INITIAL; - RETURN_TOKEN (HASH_LINE); + RETURN_TOKEN (LINE); } \n { @@ -308,45 +308,45 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? BEGIN INITIAL; yyextra->lexing_directive = 1; yyextra->space_tokens = 0; - RETURN_TOKEN_NEVER_SKIP (HASH_IFDEF); + RETURN_TOKEN_NEVER_SKIP (IFDEF); } ifndef { BEGIN INITIAL; yyextra->lexing_directive = 1; yyextra->space_tokens = 0; - RETURN_TOKEN_NEVER_SKIP (HASH_IFNDEF); + RETURN_TOKEN_NEVER_SKIP (IFNDEF); } if/[^_a-zA-Z0-9] { BEGIN INITIAL; yyextra->lexing_directive = 1; yyextra->space_tokens = 0; - RETURN_TOKEN_NEVER_SKIP (HASH_IF); + RETURN_TOKEN_NEVER_SKIP (IF); } elif/[^_a-zA-Z0-9] { BEGIN INITIAL; yyextra->lexing_directive = 1; yyextra->space_tokens = 0; - RETURN_TOKEN_NEVER_SKIP (HASH_ELIF); + RETURN_TOKEN_NEVER_SKIP (ELIF); } else { BEGIN INITIAL; yyextra->space_tokens = 0; - RETURN_TOKEN_NEVER_SKIP (HASH_ELSE); + RETURN_TOKEN_NEVER_SKIP (ELSE); } endif { BEGIN INITIAL; yyextra->space_tokens = 0; - RETURN_TOKEN_NEVER_SKIP (HASH_ENDIF); + RETURN_TOKEN_NEVER_SKIP (ENDIF); } error.* { BEGIN INITIAL; - RETURN_STRING_TOKEN (HASH_ERROR); + RETURN_STRING_TOKEN (ERROR); } /* After we see a "#define" we enter the start state @@ -371,14 +371,14 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? if (! parser->skipping) { BEGIN DEFINE; yyextra->space_tokens = 0; - RETURN_TOKEN (HASH_DEFINE); + RETURN_TOKEN (DEFINE_TOKEN); } } undef { BEGIN INITIAL; yyextra->space_tokens = 0; - RETURN_TOKEN (HASH_UNDEF); + RETURN_TOKEN (UNDEF); } {HSPACE}+ { @@ -390,7 +390,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? /* This will catch any non-directive garbage after a HASH */ {NONSPACE} { BEGIN INITIAL; - RETURN_TOKEN (HASH_GARBAGE); + RETURN_TOKEN (GARBAGE); } /* An identifier immediately followed by '(' */ diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index 2952bf84d8d..9b753ddecd4 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -165,13 +165,14 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value); %expect 0 - /* We use HASH_TOKEN, not HASH to avoid a conflict with the - * start condition in the lexer. */ -%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH_TOKEN HASH_DEFINE FUNC_IDENTIFIER OBJ_IDENTIFIER HASH_ELIF HASH_ELSE HASH_ENDIF HASH_ERROR HASH_IF HASH_IFDEF HASH_IFNDEF HASH_LINE HASH_PRAGMA HASH_UNDEF HASH_VERSION HASH_GARBAGE IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE + /* We use HASH_TOKEN, DEFINE_TOKEN and VERSION_TOKEN (as opposed to + * HASH, DEFINE, and VERSION) to avoid conflicts with other symbols, + * (such as the and start conditions in the lexer). */ +%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH_TOKEN DEFINE_TOKEN FUNC_IDENTIFIER OBJ_IDENTIFIER ELIF ELSE ENDIF ERROR IF IFDEF IFNDEF LINE PRAGMA UNDEF VERSION_TOKEN GARBAGE IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE %token PASTE %type INTEGER operator SPACE integer_constant %type expression -%type IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER HASH_ERROR HASH_PRAGMA +%type IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER ERROR PRAGMA %type identifier_list %type preprocessing_token conditional_token %type pp_tokens replacement_list text_line conditional_tokens @@ -255,7 +256,7 @@ control_line: ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n"); } | control_line_error -| HASH_TOKEN HASH_LINE { +| HASH_TOKEN LINE { glcpp_parser_resolve_implicit_version(parser); } pp_tokens NEWLINE { @@ -269,10 +270,10 @@ control_line: ; control_line_success: - HASH_TOKEN HASH_DEFINE { + HASH_TOKEN DEFINE_TOKEN { glcpp_parser_resolve_implicit_version(parser); } define -| HASH_TOKEN HASH_UNDEF { +| HASH_TOKEN UNDEF { glcpp_parser_resolve_implicit_version(parser); } IDENTIFIER NEWLINE { macro_t *macro; @@ -289,7 +290,7 @@ control_line_success: } ralloc_free ($4); } -| HASH_TOKEN HASH_IF { +| HASH_TOKEN IF { glcpp_parser_resolve_implicit_version(parser); } conditional_tokens NEWLINE { /* Be careful to only evaluate the 'if' expression if @@ -311,7 +312,7 @@ control_line_success: parser->skip_stack->type = SKIP_TO_ENDIF; } } -| HASH_TOKEN HASH_IF NEWLINE { +| HASH_TOKEN IF NEWLINE { /* #if without an expression is only an error if we * are not skipping */ if (parser->skip_stack == NULL || @@ -321,21 +322,21 @@ control_line_success: } _glcpp_parser_skip_stack_push_if (parser, & @1, 0); } -| HASH_TOKEN HASH_IFDEF { +| HASH_TOKEN IFDEF { glcpp_parser_resolve_implicit_version(parser); } IDENTIFIER junk NEWLINE { macro_t *macro = hash_table_find (parser->defines, $4); ralloc_free ($4); _glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL); } -| HASH_TOKEN HASH_IFNDEF { +| HASH_TOKEN IFNDEF { glcpp_parser_resolve_implicit_version(parser); } IDENTIFIER junk NEWLINE { macro_t *macro = hash_table_find (parser->defines, $4); ralloc_free ($4); _glcpp_parser_skip_stack_push_if (parser, & @3, macro == NULL); } -| HASH_TOKEN HASH_ELIF conditional_tokens NEWLINE { +| HASH_TOKEN ELIF conditional_tokens NEWLINE { /* Be careful to only evaluate the 'elif' expression * if we are not skipping. When we are skipping, we * simply change to a 0-valued 'elif' on the skip @@ -360,7 +361,7 @@ control_line_success: "elif", 0); } } -| HASH_TOKEN HASH_ELIF NEWLINE { +| HASH_TOKEN ELIF NEWLINE { /* #elif without an expression is an error unless we * are skipping. */ if (parser->skip_stack && @@ -380,7 +381,7 @@ control_line_success: glcpp_warning(& @1, parser, "ignoring illegal #elif without expression"); } } -| HASH_TOKEN HASH_ELSE { parser->lexing_directive = 1; } NEWLINE { +| HASH_TOKEN ELSE { parser->lexing_directive = 1; } NEWLINE { if (parser->skip_stack && parser->skip_stack->has_else) { @@ -393,16 +394,16 @@ control_line_success: parser->skip_stack->has_else = true; } } -| HASH_TOKEN HASH_ENDIF { +| HASH_TOKEN ENDIF { _glcpp_parser_skip_stack_pop (parser, & @1); } NEWLINE -| HASH_TOKEN HASH_VERSION integer_constant NEWLINE { +| HASH_TOKEN VERSION_TOKEN integer_constant NEWLINE { if (parser->version_resolved) { glcpp_error(& @1, parser, "#version must appear on the first line"); } _glcpp_parser_handle_version_declaration(parser, $3, NULL, true); } -| HASH_TOKEN HASH_VERSION integer_constant IDENTIFIER NEWLINE { +| HASH_TOKEN VERSION_TOKEN integer_constant IDENTIFIER NEWLINE { if (parser->version_resolved) { glcpp_error(& @1, parser, "#version must appear on the first line"); } @@ -411,16 +412,16 @@ control_line_success: | HASH_TOKEN NEWLINE { glcpp_parser_resolve_implicit_version(parser); } -| HASH_TOKEN HASH_PRAGMA NEWLINE { +| HASH_TOKEN PRAGMA NEWLINE { ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "#%s", $2); } ; control_line_error: - HASH_TOKEN HASH_ERROR NEWLINE { + HASH_TOKEN ERROR NEWLINE { glcpp_error(& @1, parser, "#%s", $2); } -| HASH_TOKEN HASH_GARBAGE pp_tokens NEWLINE { +| HASH_TOKEN GARBAGE pp_tokens NEWLINE { glcpp_error (& @1, parser, "Illegal non-directive after #"); } ; @@ -2040,11 +2041,11 @@ glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser) if (ret == NEWLINE) parser->in_control_line = 0; } - else if (ret == HASH_DEFINE || - ret == HASH_UNDEF || ret == HASH_IF || - ret == HASH_IFDEF || ret == HASH_IFNDEF || - ret == HASH_ELIF || ret == HASH_ELSE || - ret == HASH_ENDIF || ret == HASH_TOKEN) + else if (ret == DEFINE_TOKEN || + ret == UNDEF || ret == IF || + ret == IFDEF || ret == IFNDEF || + ret == ELIF || ret == ELSE || + ret == ENDIF || ret == HASH_TOKEN) { parser->in_control_line = 1; } -- 2.30.2