[Mesa-dev] [PATCH 1/3] glsl: glcpp: Rename and document _glcpp_parser_expand_if

Carl Worth cworth at cworth.org
Sun Jun 10 01:41:42 CEST 2012


This function is currently used only in the expansion of #if lines,
but we will soon be using it more generally (for the expansion of
(_glcpp_parser_expand_and_lex_from) and some more documentation.
---

> What I'd like to see is the preprocessor interpreting the #line
> directives (for its own notion of the line number) and then also
> emitting a fully expanded #line macro for the main compiler to
> interpret.
>
> I'll plan to attempt that on Monday if I don't get to it today.

OK, I did get around to it today.

See the following 3 patches which give me what I wanted to see as
described above.

-Carl

 src/glsl/glcpp/glcpp-parse.y |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 78ff8fa..ee00180 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -105,9 +105,15 @@ _parser_active_list_pop (glcpp_parser_t *parser);
 static int
 _parser_active_list_contains (glcpp_parser_t *parser, const char *identifier);
 
+/* Expand list, and begin lexing from the result (after first
+ * prefixing a token of type 'head_token_type').
+ */
 static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
+_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
+				   int head_token_type,
+				   token_list_t *list);
 
+/* Perform macro expansion in-place on the given list. */
 static void
 _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
 				 token_list_t *list);
@@ -233,7 +239,8 @@ control_line:
 		if (parser->skip_stack == NULL ||
 		    parser->skip_stack->type == SKIP_NO_SKIP)
 		{
-			_glcpp_parser_expand_if (parser, IF_EXPANDED, $2);
+			_glcpp_parser_expand_and_lex_from (parser,
+							   IF_EXPANDED, $2);
 		}	
 		else
 		{
@@ -272,7 +279,8 @@ control_line:
 		if (parser->skip_stack &&
 		    parser->skip_stack->type == SKIP_TO_ELSE)
 		{
-			_glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2);
+			_glcpp_parser_expand_and_lex_from (parser,
+							   ELIF_EXPANDED, $2);
 		}
 		else
 		{
@@ -1272,14 +1280,21 @@ _token_list_create_with_one_space (void *ctx)
 	return list;
 }
 
+/* Perform macro expansion on 'list', placing the resulting tokens
+ * into a new list which is initialized with a first token of type
+ * 'head_token_type'. Then begin lexing from the resulting list,
+ * (return to the current lexing source when this list is exhausted).
+ */
 static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
+_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
+				   int head_token_type,
+				   token_list_t *list)
 {
 	token_list_t *expanded;
 	token_t *token;
 
 	expanded = _token_list_create (parser);
-	token = _token_create_ival (parser, type, type);
+	token = _token_create_ival (parser, head_token_type, head_token_type);
 	_token_list_append (expanded, token);
 	_glcpp_parser_expand_token_list (parser, list);
 	_token_list_append_list (expanded, list);
-- 
1.7.10



More information about the mesa-dev mailing list