summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McCabe <[email protected]>2011-11-07 15:11:04 -0800
committerDan McCabe <[email protected]>2011-11-07 16:31:22 -0800
commit85beb39e14556cf02f58116fd287120cd1defbd5 (patch)
treee59dc9f775277a0b4b85aab9bbedab7f7c03729a
parenta0afcc67196baa588ec0ac246be6c4996a328f0b (diff)
glsl: Reference data structure ctors in grammar
We now tie the grammar to the ctors of the ASTs they reference. This requires that we actually have definitions of the ctors. In addition, we also need to define "print" and "hir" methods for the AST classes. The Print methods are pretty simple to flesh out. However, at this stage of the development, we simply stub out the "hir" methods and flesh them out later. Also, since actual class instances get returned by the productions in the grammar, we also need to designate the type of the productions that reference those instances. Reviewed-by: Kenneth Graunke <[email protected]>
-rw-r--r--src/glsl/ast_to_hir.cpp54
-rw-r--r--src/glsl/glsl_parser.yy55
-rw-r--r--src/glsl/glsl_parser_extras.cpp100
3 files changed, 193 insertions, 16 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index ed6abdc7083..200d6596fab 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3445,6 +3445,60 @@ ast_selection_statement::hir(exec_list *instructions,
}
+ir_rvalue *
+ast_switch_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ // FINISHME
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_switch_body::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ // FINISHME
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_case_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ // FINISHME
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_case_statement_list::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ // FINISHME
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_case_label::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ // FINISHME
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_case_label_list::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ // FINISHME
+ return NULL;
+}
+
+
void
ast_iteration_statement::condition_to_hir(ir_loop *stmt,
struct _mesa_glsl_parse_state *state)
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 8948c34a237..f3e87380035 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -67,6 +67,11 @@
ast_declarator_list *declarator_list;
ast_struct_specifier *struct_specifier;
ast_declaration *declaration;
+ ast_switch_body *switch_body;
+ ast_case_label *case_label;
+ ast_case_label_list *case_label_list;
+ ast_case_statement *case_statement;
+ ast_case_statement_list *case_statement_list;
struct {
ast_node *cond;
@@ -208,11 +213,11 @@
%type <node> selection_statement
%type <selection_rest_statement> selection_rest_statement
%type <node> switch_statement
-%type <node> switch_body
-%type <node> case_label
-%type <node> case_label_list
-%type <node> case_statement
-%type <node> case_statement_list
+%type <switch_body> switch_body
+%type <case_label_list> case_label_list
+%type <case_label> case_label
+%type <case_statement> case_statement
+%type <case_statement_list> case_statement_list
%type <node> iteration_statement
%type <node> condition
%type <node> conditionopt
@@ -1652,58 +1657,76 @@ condition:
switch_statement:
SWITCH '(' expression ')' switch_body
{
- $$ = NULL;
+ $$ = new(state) ast_switch_statement($3, $5);
}
;
switch_body:
'{' '}'
{
- $$ = NULL;
+ $$ = new(state) ast_switch_body(NULL);
+ $$->set_location(yylloc);
}
| '{' case_statement_list '}'
{
- $$ = NULL;
+ $$ = new(state) ast_switch_body($2);
+ $$->set_location(yylloc);
}
;
case_label:
CASE expression ':'
{
- $$ = NULL;
+ $$ = new(state) ast_case_label($2);
}
| DEFAULT ':'
{
- $$ = NULL;
+ $$ = new(state) ast_case_label(NULL);
}
;
case_label_list:
case_label
{
- $$ = NULL;
+ ast_case_label_list *labels = new(state) ast_case_label_list();
+
+ labels->labels.push_tail(& $1->link);
+ $$ = labels;
}
| case_label_list case_label
{
- $$ = NULL;
+ $$ = $1;
+ $$->labels.push_tail(& $2->link);
}
;
case_statement:
- case_label_list statement_list
+ case_label_list statement
{
- $$ = NULL;
+ ast_case_statement *stmts = new(state) ast_case_statement($1);
+
+ stmts->stmts.push_tail(& $2->link);
+ $$ = stmts
+ }
+ | case_statement statement
+ {
+ $$ = $1;
+ $$->stmts.push_tail(& $2->link);
}
;
case_statement_list:
case_statement
{
- $$ = NULL;
+ ast_case_statement_list *cases= new(state) ast_case_statement_list();
+
+ cases->cases.push_tail(& $1->link);
+ $$ = cases;
}
| case_statement_list case_statement
{
- $$ = NULL;
+ $$ = $1;
+ $$->cases.push_tail(& $2->link);
}
;
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index e627dabf773..1f3d23a8c73 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -806,6 +806,106 @@ ast_selection_statement::ast_selection_statement(ast_expression *condition,
void
+ast_switch_statement::print(void) const
+{
+ printf("switch ( ");
+ test_expression->print();
+ printf(") ");
+
+ body->print();
+}
+
+
+ast_switch_statement::ast_switch_statement(ast_expression *test_expression,
+ ast_node *body)
+{
+ this->test_expression = test_expression;
+ this->body = body;
+}
+
+
+void
+ast_switch_body::print(void) const
+{
+ printf("{\n");
+ if (stmts != NULL) {
+ stmts->print();
+ }
+ printf("}\n");
+}
+
+
+ast_switch_body::ast_switch_body(ast_case_statement_list *stmts)
+{
+ this->stmts = stmts;
+}
+
+
+void ast_case_label::print(void) const
+{
+ if (test_value != NULL) {
+ printf("case ");
+ test_value->print();
+ printf(": ");
+ } else {
+ printf("default: ");
+ }
+}
+
+
+ast_case_label::ast_case_label(ast_expression *test_value)
+{
+ this->test_value = 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);
+ ast->print();
+ }
+ printf("\n");
+}
+
+
+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);
+ ast->print();
+ printf("\n");
+ }
+}
+
+
+ast_case_statement::ast_case_statement(ast_case_label_list *labels)
+{
+ this->labels = 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);
+ ast->print();
+ }
+}
+
+
+ast_case_statement_list::ast_case_statement_list(void)
+{
+}
+
+
+void
ast_iteration_statement::print(void) const
{
switch (mode) {