[Mesa-dev] [PATCH 07/16] glsl: Use foreach_list_typed when possible.

Matt Turner mattst88 at gmail.com
Wed Jun 25 11:51:08 PDT 2014


---
 src/glsl/ast_function.cpp       |  6 ++----
 src/glsl/ast_to_hir.cpp         |  2 +-
 src/glsl/glsl_parser_extras.cpp | 41 +++++++++++++++--------------------------
 3 files changed, 18 insertions(+), 31 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index b4c4b78..cdb34cc 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -41,8 +41,7 @@ process_parameters(exec_list *instructions, exec_list *actual_parameters,
 {
    unsigned count = 0;
 
-   foreach_list (n, parameters) {
-      ast_node *const ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, parameters) {
       ir_rvalue *result = ast->hir(instructions, state);
 
       ir_constant *const constant = result->constant_expression_value();
@@ -1546,8 +1545,7 @@ ast_function_expression::hir(exec_list *instructions,
       unsigned nonmatrix_parameters = 0;
       exec_list actual_parameters;
 
-      foreach_list (n, &this->expressions) {
-	 ast_node *ast = exec_node_data(ast_node, n, link);
+      foreach_list_typed(ast_node, ast, link, &this->expressions) {
 	 ir_rvalue *result = ast->hir(instructions, state);
 
 	 /* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec:
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index cf423ec..17933bb 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -4995,7 +4995,7 @@ ast_process_structure_or_interface_block(exec_list *instructions,
     * 'declarations' list in each of the elements.
     */
    foreach_list_typed (ast_declarator_list, decl_list, link, declarations) {
-      foreach_list_const (decl_ptr, & decl_list->declarations) {
+      foreach_list_typed (ast_declaration, decl, link, &decl_list->declarations) {
          decl_count++;
       }
    }
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 11a9a43..0d99339 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -844,8 +844,7 @@ ast_compound_statement::print(void) const
 {
    printf("{\n");
    
-   foreach_list_const(n, &this->statements) {
-      ast_node *ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, &this->statements) {
       ast->print();
    }
 
@@ -924,11 +923,10 @@ ast_expression::print(void) const
       subexpressions[0]->print();
       printf("( ");
 
-      foreach_list_const (n, &this->expressions) {
-	 if (n != this->expressions.get_head())
+      foreach_list_typed (ast_node, ast, link, &this->expressions) {
+	 if (&ast->link != this->expressions.get_head())
 	    printf(", ");
 
-	 ast_node *ast = exec_node_data(ast_node, n, link);
 	 ast->print();
       }
 
@@ -960,11 +958,10 @@ ast_expression::print(void) const
 
    case ast_sequence: {
       printf("( ");
-      foreach_list_const(n, & this->expressions) {
-	 if (n != this->expressions.get_head())
+      foreach_list_typed (ast_node, ast, link, & this->expressions) {
+	 if (&ast->link != this->expressions.get_head())
 	    printf(", ");
 
-	 ast_node *ast = exec_node_data(ast_node, n, link);
 	 ast->print();
       }
       printf(") ");
@@ -973,11 +970,10 @@ ast_expression::print(void) const
 
    case ast_aggregate: {
       printf("{ ");
-      foreach_list_const(n, & this->expressions) {
-	 if (n != this->expressions.get_head())
+      foreach_list_typed (ast_node, ast, link, & this->expressions) {
+	 if (&ast->link != this->expressions.get_head())
 	    printf(", ");
 
-	 ast_node *ast = exec_node_data(ast_node, n, link);
 	 ast->print();
       }
       printf("} ");
@@ -1027,8 +1023,7 @@ ast_function::print(void) const
    return_type->print();
    printf(" %s (", identifier);
 
-   foreach_list_const(n, & this->parameters) {
-      ast_node *ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, & this->parameters) {
       ast->print();
    }
 
@@ -1105,11 +1100,10 @@ ast_declarator_list::print(void) const
    else
       printf("precise ");
 
-   foreach_list_const (ptr, & this->declarations) {
-      if (ptr != this->declarations.get_head())
+   foreach_list_typed (ast_node, ast, link, & this->declarations) {
+      if (&ast->link != this->declarations.get_head())
 	 printf(", ");
 
-      ast_node *ast = exec_node_data(ast_node, ptr, link);
       ast->print();
    }
 
@@ -1241,8 +1235,7 @@ ast_case_label::ast_case_label(ast_expression *test_value)
 
 void ast_case_label_list::print(void) const
 {
-   foreach_list_const(n, & this->labels) {
-      ast_node *ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, & this->labels) {
       ast->print();
    }
    printf("\n");
@@ -1257,8 +1250,7 @@ ast_case_label_list::ast_case_label_list(void)
 void ast_case_statement::print(void) const
 {
    labels->print();
-   foreach_list_const(n, & this->stmts) {
-      ast_node *ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, & this->stmts) {
       ast->print();
       printf("\n");
    }
@@ -1273,8 +1265,7 @@ ast_case_statement::ast_case_statement(ast_case_label_list *labels)
 
 void ast_case_statement_list::print(void) const
 {
-   foreach_list_const(n, & this->cases) {
-      ast_node *ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, & this->cases) {
       ast->print();
    }
 }
@@ -1344,8 +1335,7 @@ void
 ast_struct_specifier::print(void) const
 {
    printf("struct %s { ", name);
-   foreach_list_const(n, &this->declarations) {
-      ast_node *ast = exec_node_data(ast_node, n, link);
+   foreach_list_typed(ast_node, ast, link, &this->declarations) {
       ast->print();
    }
    printf("} ");
@@ -1456,8 +1446,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
    }
 
    if (dump_ast) {
-      foreach_list_const(n, &state->translation_unit) {
-         ast_node *ast = exec_node_data(ast_node, n, link);
+      foreach_list_typed(ast_node, ast, link, &state->translation_unit) {
          ast->print();
       }
       printf("\n\n");
-- 
1.8.3.2



More information about the mesa-dev mailing list