[Mesa-dev] [PATCH 5/7] Flesh out AST print methods

Dan McCabe zen3d.linux at gmail.com
Wed Jun 15 09:33:42 PDT 2011


Pretty trivial stuff. Simply print the structure of the ASTs. No magic here.
---
 src/glsl/glsl_parser_extras.cpp |   38 ++++++++++++++++++++++++++++++++------
 1 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index a351e12..f2ed518 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -695,7 +695,11 @@ ast_selection_statement::ast_selection_statement(ast_expression *condition,
 void
 ast_switch_statement::print(void) const
 {
-   printf("TODO - implement me!!!");
+   printf("switch ( ");
+   test_expression->print();
+   printf(") ");
+
+   body->print();
 }
 
 
@@ -710,7 +714,11 @@ ast_switch_statement::ast_switch_statement(ast_expression *test_expression,
 void 
 ast_switch_body::print(void) const
 {
-   printf("TODO - implement me!!!");
+   printf("{\n");
+   if (stmts != NULL) {
+      stmts->print();
+   }
+   printf("}\n");
 }
 
 
@@ -722,7 +730,13 @@ ast_switch_body::ast_switch_body(ast_case_statement_list *stmts)
 
 void ast_case_label::print(void) const
 {
-   printf("TODO - implement me!!!");
+   if (test_value != NULL) {
+      printf("case ");
+      test_value->print();
+      printf(": ");
+   } else {
+      printf("default: ");
+   }
 }
 
 
@@ -734,7 +748,11 @@ ast_case_label::ast_case_label(ast_expression *test_value)
 
 void ast_case_label_list::print(void) const
 {
-   printf("TODO - implement me!!!");
+   foreach_list_const(n, & this->labels) {
+      ast_node *ast = exec_node_data(ast_node, n, link);
+      ast->print();
+   }
+   printf("\n");
 }
 
 
@@ -745,7 +763,12 @@ ast_case_label_list::ast_case_label_list(void)
 
 void ast_case_statement::print(void) const
 {
-   printf("TODO - implement me!!!");
+   labels->print();
+   foreach_list_const(n, & this->stmts) {
+      ast_node *ast = exec_node_data(ast_node, n, link);
+      ast->print();
+      printf("\n");
+   }
 }
 
 
@@ -757,7 +780,10 @@ ast_case_statement::ast_case_statement(ast_case_label_list *labels)
 
 void ast_case_statement_list::print(void) const
 {
-   printf("TODO - implement me!!!");
+   foreach_list_const(n, & this->cases) {
+      ast_node *ast = exec_node_data(ast_node, n, link);
+      ast->print();
+   }
 }
 
 
-- 
1.7.4.1



More information about the mesa-dev mailing list