[Mesa-dev] [PATCH 4/5] 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. --- src/glsl/ast_to_hir.cpp | 54 + src/glsl/glsl_parser.yy | 55 +++-- src/glsl/glsl_parser_extras.cpp | 100 +++ 3 files changed, 193 insertions(+), 16 deletions(-) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index c0524bf..db5b4ad 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -3319,6 +3319,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 b3727ce..fc3541c 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; @@ -207,11 +212,11 @@ %type selection_statement %type selection_rest_statement %type switch_statement -%type switch_body -%type case_label -%type case_label_list -%type case_statement -%type case_statement_list +%type switch_body +%type case_label_list +%type case_label +%type case_statement +%type case_statement_list %type iteration_statement %type condition %type conditionopt @@ -1654,58 +1659,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 ca
Re: [Mesa-dev] [PATCH 4/5] glsl: Reference data structure ctors in grammar
On 06/28/2011 02:48 PM, Dan McCabe wrote: > 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. > --- > src/glsl/ast_to_hir.cpp | 54 + > src/glsl/glsl_parser.yy | 55 +++-- > src/glsl/glsl_parser_extras.cpp | 100 > +++ > 3 files changed, 193 insertions(+), 16 deletions(-) Reviewed-by: Kenneth Graunke ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 4/5] 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. --- src/glsl/ast_to_hir.cpp | 54 + src/glsl/glsl_parser.yy | 55 +++-- src/glsl/glsl_parser_extras.cpp | 100 +++ 3 files changed, 193 insertions(+), 16 deletions(-) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 3b87f0d..d8ebd87 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -3274,6 +3274,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 b3727ce..fc3541c 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; @@ -207,11 +212,11 @@ %type selection_statement %type selection_rest_statement %type switch_statement -%type switch_body -%type case_label -%type case_label_list -%type case_statement -%type case_statement_list +%type switch_body +%type case_label_list +%type case_label +%type case_statement +%type case_statement_list %type iteration_statement %type condition %type conditionopt @@ -1654,58 +1659,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 ca