[Mesa-dev] [PATCH 16/23] glsl/glcpp: Drop the HASH_ prefix from token names like HASH_IF

Carl Worth cworth at cworth.org
Thu Jun 26 15:19:16 PDT 2014


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 HASH_TOKEN instead of HASH, we also use DEFINE_TOKEN instead of
DEFINE to avoid a conflict with the <DEFINE> start condition in the lexer.)

There should be no behavioral change from this commit.
---
 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 8b3e007..5abefbf 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]?
 <HASH>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);
 }
 
 <HASH>line{HSPACE}+ {
 	BEGIN INITIAL;
-	RETURN_TOKEN (HASH_LINE);
+	RETURN_TOKEN (LINE);
 }
 
 	/* For the pre-processor directives, we return these tokens
@@ -303,45 +303,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);
 }
 
 <HASH>ifndef {
 	BEGIN INITIAL;
 	yyextra->lexing_directive = 1;
 	yyextra->space_tokens = 0;
-	RETURN_TOKEN_NEVER_SKIP (HASH_IFNDEF);
+	RETURN_TOKEN_NEVER_SKIP (IFNDEF);
 }
 
 <HASH>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);
 }
 
 <HASH>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);
 }
 
 <HASH>else {
 	BEGIN INITIAL;
 	yyextra->space_tokens = 0;
-	RETURN_TOKEN_NEVER_SKIP (HASH_ELSE);
+	RETURN_TOKEN_NEVER_SKIP (ELSE);
 }
 
 <HASH>endif {
 	BEGIN INITIAL;
 	yyextra->space_tokens = 0;
-	RETURN_TOKEN_NEVER_SKIP (HASH_ENDIF);
+	RETURN_TOKEN_NEVER_SKIP (ENDIF);
 }
 
 <HASH>error.* {
 	BEGIN INITIAL;
-	RETURN_STRING_TOKEN (HASH_ERROR);
+	RETURN_STRING_TOKEN (ERROR);
 }
 
 	/* After we see a "#define" we enter the <DEFINE> start state
@@ -366,14 +366,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);
 	}
 }
 
 <HASH>undef {
 	BEGIN INITIAL;
 	yyextra->space_tokens = 0;
-	RETURN_TOKEN (HASH_UNDEF);
+	RETURN_TOKEN (UNDEF);
 }
 
 <HASH>\n {
@@ -390,7 +390,7 @@ HEXADECIMAL_INTEGER	0[xX][0-9a-fA-F]+[uU]?
 	/* This will catch any non-directive garbage after a HASH */
 <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 b5c8616..98d5a08 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 <HASH>
-         * 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 <HASH> and <DEFINE> 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 <ival> INTEGER operator SPACE integer_constant
 %type <expression_value> expression
-%type <str> IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER HASH_ERROR HASH_PRAGMA
+%type <str> IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER ERROR PRAGMA
 %type <string_list> identifier_list
 %type <token> preprocessing_token conditional_token
 %type <token_list> pp_tokens replacement_list text_line conditional_tokens
@@ -199,7 +200,7 @@ input:
 line:
 	control_line
 |	SPACE control_line
-|	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 {
 		if (strcmp("__LINE__", $4) == 0
@@ -288,7 +289,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
@@ -310,7 +311,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 ||
@@ -320,21 +321,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
@@ -359,7 +360,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 &&
@@ -379,7 +380,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)
 		{
@@ -392,16 +393,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");
 		}
@@ -410,16 +411,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 #");
 	}
 ;
@@ -2039,11 +2040,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.0.0



More information about the mesa-dev mailing list