[Mesa-dev] [PATCH] glsl-compiler: ast: Precise locations positions.
Sir Anthony
anthony at adsorbtion.org
Mon Feb 3 18:44:54 CET 2014
1. Change locations setup in glsl_parser.yy from yylloc to appropriate token locations.
2. Addition of two fields in ast_node location to hold end position of token.
3. Addition of ast_node method to setup range locations (for aggregate tokens).
4. Fix for glcpp-lex.l. It handled spaces wrong and convert two adjacent spaces into one, which added location offset for shaders with indentation.
---
src/glsl/ast.h | 36 +++++--
src/glsl/glcpp/glcpp-lex.l | 5 +-
src/glsl/glsl_lexer.ll | 3 +-
src/glsl/glsl_parser.yy | 215 +++++++++++++++++++++-------------------
src/glsl/glsl_parser_extras.cpp | 6 +-
5 files changed, 150 insertions(+), 115 deletions(-)
diff --git a/src/glsl/ast.h b/src/glsl/ast.h
index 0bda28d..9b5bc47 100644
--- a/src/glsl/ast.h
+++ b/src/glsl/ast.h
@@ -75,10 +75,10 @@ public:
struct YYLTYPE locp;
locp.source = this->location.source;
- locp.first_line = this->location.line;
- locp.first_column = this->location.column;
- locp.last_line = locp.first_line;
- locp.last_column = locp.first_column;
+ locp.first_line = this->location.first_line;
+ locp.first_column = this->location.first_column;
+ locp.last_line = this->location.last_line;
+ locp.last_column = this->location.last_column;
return locp;
}
@@ -91,17 +91,35 @@ public:
void set_location(const struct YYLTYPE &locp)
{
this->location.source = locp.source;
- this->location.line = locp.first_line;
- this->location.column = locp.first_column;
+ this->location.first_line = locp.first_line;
+ this->location.first_column = locp.first_column;
+ this->location.last_line = locp.last_line;
+ this->location.last_column = locp.last_column;
+ }
+
+ /**
+ * Set the source location range of an AST node using two location nodes
+ *
+ * \sa ast_node::set_location
+ */
+ void set_location_range(const struct YYLTYPE &begin, const struct YYLTYPE &end)
+ {
+ this->location.source = begin.source;
+ this->location.first_line = begin.first_line;
+ this->location.last_line = end.last_line;
+ this->location.first_column = begin.first_column;
+ this->location.last_column = end.last_column;
}
/**
* Source location of the AST node.
*/
struct {
- unsigned source; /**< GLSL source number. */
- unsigned line; /**< Line number within the source string. */
- unsigned column; /**< Column in the line. */
+ unsigned source; /**< GLSL source number. */
+ unsigned first_line; /**< Line number within the source string. */
+ unsigned first_column; /**< Column in the line. */
+ unsigned last_line; /**< Line number within the source string. */
+ unsigned last_column; /**< Column in the line. */
} location;
exec_node link;
diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index ea3b862..188e454 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -47,8 +47,9 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner);
if (parser->has_new_source_number) \
yylloc->source = parser->new_source_number; \
yylloc->first_column = yycolumn + 1; \
- yylloc->first_line = yylineno; \
+ yylloc->first_line = yylloc->last_line = yylineno; \
yycolumn += yyleng; \
+ yylloc->last_column = yycolumn + 1; \
parser->has_new_line_number = 0; \
parser->has_new_source_number = 0; \
} while(0);
@@ -337,7 +338,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
return OTHER;
}
-{HSPACE}+ {
+{HSPACE} {
if (yyextra->space_tokens) {
return SPACE;
}
diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
index 50875bf..e7766a8 100644
--- a/src/glsl/glsl_lexer.ll
+++ b/src/glsl/glsl_lexer.ll
@@ -38,8 +38,9 @@ static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
do { \
yylloc->source = 0; \
yylloc->first_column = yycolumn + 1; \
- yylloc->first_line = yylineno + 1; \
+ yylloc->first_line = yylloc->last_line = yylineno + 1; \
yycolumn += yyleng; \
+ yylloc->last_column = yycolumn + 1; \
} while(0);
#define YY_USER_INIT yylineno = 0; yycolumn = 0;
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 928c57e..c6a585f 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -386,35 +386,35 @@ primary_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->primary_expression.identifier = $1;
}
| INTCONSTANT
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->primary_expression.int_constant = $1;
}
| UINTCONSTANT
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->primary_expression.uint_constant = $1;
}
| FLOATCONSTANT
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->primary_expression.float_constant = $1;
}
| BOOLCONSTANT
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->primary_expression.bool_constant = $1;
}
| '(' expression ')'
@@ -429,7 +429,7 @@ postfix_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @4);
}
| function_call
{
@@ -439,20 +439,20 @@ postfix_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
$$->primary_expression.identifier = $3;
}
| postfix_expression INC_OP
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
| postfix_expression DEC_OP
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
;
@@ -470,7 +470,7 @@ function_call_or_method:
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -488,13 +488,13 @@ function_call_header_with_parameters:
function_call_header assignment_expression
{
$$ = $1;
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->expressions.push_tail(& $2->link);
}
| function_call_header_with_parameters ',' assignment_expression
{
$$ = $1;
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->expressions.push_tail(& $3->link);
}
;
@@ -511,21 +511,23 @@ function_identifier:
{
void *ctx = state;
$$ = new(ctx) ast_function_expression($1);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| variable_identifier
{
void *ctx = state;
ast_expression *callee = new(ctx) ast_expression($1);
+ callee->set_location(@1);
$$ = new(ctx) ast_function_expression(callee);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| FIELD_SELECTION
{
void *ctx = state;
ast_expression *callee = new(ctx) ast_expression($1);
+ callee->set_location(@1);
$$ = new(ctx) ast_function_expression(callee);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
;
@@ -543,13 +545,13 @@ method_call_header_with_parameters:
method_call_header assignment_expression
{
$$ = $1;
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->expressions.push_tail(& $2->link);
}
| method_call_header_with_parameters ',' assignment_expression
{
$$ = $1;
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->expressions.push_tail(& $3->link);
}
;
@@ -562,8 +564,9 @@ method_call_header:
{
void *ctx = state;
ast_expression *callee = new(ctx) ast_expression($1);
+ callee->set_location(@1);
$$ = new(ctx) ast_function_expression(callee);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
;
@@ -574,19 +577,19 @@ unary_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| DEC_OP unary_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| unary_operator unary_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression($1, $2, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
;
@@ -604,19 +607,19 @@ multiplicative_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| multiplicative_expression '/' unary_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| multiplicative_expression '%' unary_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -626,13 +629,13 @@ additive_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| additive_expression '-' multiplicative_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -642,13 +645,13 @@ shift_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| shift_expression RIGHT_OP additive_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -658,25 +661,25 @@ relational_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| relational_expression '>' shift_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| relational_expression LE_OP shift_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| relational_expression GE_OP shift_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -686,13 +689,13 @@ equality_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
| equality_expression NE_OP relational_expression
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -702,7 +705,7 @@ and_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -712,7 +715,7 @@ exclusive_or_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -722,7 +725,7 @@ inclusive_or_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -732,7 +735,7 @@ logical_and_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -742,7 +745,7 @@ logical_xor_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -752,7 +755,7 @@ logical_or_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -762,7 +765,7 @@ conditional_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @5);
}
;
@@ -772,7 +775,7 @@ assignment_expression:
{
void *ctx = state;
$$ = new(ctx) ast_expression($2, $1, $3, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -800,7 +803,7 @@ expression:
void *ctx = state;
if ($1->oper != ast_sequence) {
$$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
$$->expressions.push_tail(& $1->link);
} else {
$$ = $1;
@@ -862,7 +865,7 @@ function_header:
{
void *ctx = state;
$$ = new(ctx) ast_function();
- $$->set_location(yylloc);
+ $$->set_location(@2);
$$->return_type = $1;
$$->identifier = $2;
@@ -876,9 +879,9 @@ parameter_declarator:
{
void *ctx = state;
$$ = new(ctx) ast_parameter_declarator();
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
$$->type = new(ctx) ast_fully_specified_type();
- $$->type->set_location(yylloc);
+ $$->type->set_location(@1);
$$->type->specifier = $1;
$$->identifier = $2;
}
@@ -886,9 +889,9 @@ parameter_declarator:
{
void *ctx = state;
$$ = new(ctx) ast_parameter_declarator();
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
$$->type = new(ctx) ast_fully_specified_type();
- $$->type->set_location(yylloc);
+ $$->type->set_location(@1);
$$->type->specifier = $1;
$$->identifier = $2;
$$->array_specifier = $3;
@@ -905,8 +908,9 @@ parameter_declaration:
{
void *ctx = state;
$$ = new(ctx) ast_parameter_declarator();
- $$->set_location(yylloc);
+ $$->set_location(@2);
$$->type = new(ctx) ast_fully_specified_type();
+ $$->type->set_location_range(@1, @2);
$$->type->qualifier = $1;
$$->type->specifier = $2;
}
@@ -978,7 +982,7 @@ init_declarator_list:
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
- decl->set_location(yylloc);
+ decl->set_location(@3);
$$ = $1;
$$->declarations.push_tail(&decl->link);
@@ -988,7 +992,7 @@ init_declarator_list:
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
- decl->set_location(yylloc);
+ decl->set_location_range(@3, @4);
$$ = $1;
$$->declarations.push_tail(&decl->link);
@@ -998,7 +1002,7 @@ init_declarator_list:
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
- decl->set_location(yylloc);
+ decl->set_location_range(@3, @4);
$$ = $1;
$$->declarations.push_tail(&decl->link);
@@ -1008,7 +1012,7 @@ init_declarator_list:
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
- decl->set_location(yylloc);
+ decl->set_location(@3);
$$ = $1;
$$->declarations.push_tail(&decl->link);
@@ -1023,51 +1027,56 @@ single_declaration:
void *ctx = state;
/* Empty declaration list is valid. */
$$ = new(ctx) ast_declarator_list($1);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| fully_specified_type any_identifier
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
+ decl->set_location(@2);
$$ = new(ctx) ast_declarator_list($1);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
$$->declarations.push_tail(&decl->link);
}
| fully_specified_type any_identifier array_specifier
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
+ decl->set_location_range(@2, @3);
$$ = new(ctx) ast_declarator_list($1);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
$$->declarations.push_tail(&decl->link);
}
| fully_specified_type any_identifier array_specifier '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
+ decl->set_location_range(@2, @3);
$$ = new(ctx) ast_declarator_list($1);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
$$->declarations.push_tail(&decl->link);
}
| fully_specified_type any_identifier '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
+ decl->set_location(@2);
$$ = new(ctx) ast_declarator_list($1);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
$$->declarations.push_tail(&decl->link);
}
| INVARIANT variable_identifier // Vertex only.
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
+ decl->set_location(@2);
$$ = new(ctx) ast_declarator_list(NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
$$->invariant = true;
$$->declarations.push_tail(&decl->link);
@@ -1079,14 +1088,14 @@ fully_specified_type:
{
void *ctx = state;
$$ = new(ctx) ast_fully_specified_type();
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->specifier = $1;
}
| type_qualifier type_specifier
{
void *ctx = state;
$$ = new(ctx) ast_fully_specified_type();
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
$$->qualifier = $1;
$$->specifier = $2;
}
@@ -1551,12 +1560,14 @@ array_specifier:
'[' ']'
{
void *ctx = state;
- $$ = new(ctx) ast_array_specifier(yylloc);
+ $$ = new(ctx) ast_array_specifier(@1);
+ $$->set_location_range(@1, @2);
}
| '[' constant_expression ']'
{
void *ctx = state;
- $$ = new(ctx) ast_array_specifier(yylloc, $2);
+ $$ = new(ctx) ast_array_specifier(@1, $2);
+ $$->set_location_range(@1, @3);
}
| array_specifier '[' ']'
{
@@ -1600,19 +1611,19 @@ type_specifier_nonarray:
{
void *ctx = state;
$$ = new(ctx) ast_type_specifier($1);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| struct_specifier
{
void *ctx = state;
$$ = new(ctx) ast_type_specifier($1);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| TYPE_IDENTIFIER
{
void *ctx = state;
$$ = new(ctx) ast_type_specifier($1);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
;
@@ -1710,7 +1721,7 @@ struct_specifier:
{
void *ctx = state;
$$ = new(ctx) ast_struct_specifier($2, $4);
- $$->set_location(yylloc);
+ $$->set_location_range(@2, @5);
state->symbols->add_type($2, glsl_type::void_type);
state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
}
@@ -1718,7 +1729,7 @@ struct_specifier:
{
void *ctx = state;
$$ = new(ctx) ast_struct_specifier(NULL, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@2, @4);
}
;
@@ -1740,7 +1751,7 @@ struct_declaration:
{
void *ctx = state;
ast_fully_specified_type *const type = $1;
- type->set_location(yylloc);
+ type->set_location(@1);
if (type->qualifier.flags.i != 0)
_mesa_glsl_error(&@1, state,
@@ -1748,7 +1759,7 @@ struct_declaration:
"structure members");
$$ = new(ctx) ast_declarator_list(type);
- $$->set_location(yylloc);
+ $$->set_location(@2);
$$->declarations.push_degenerate_list_at_head(& $2->link);
}
@@ -1772,13 +1783,13 @@ struct_declarator:
{
void *ctx = state;
$$ = new(ctx) ast_declaration($1, NULL, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| any_identifier array_specifier
{
void *ctx = state;
$$ = new(ctx) ast_declaration($1, $2, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
;
@@ -1799,7 +1810,7 @@ initializer_list:
{
void *ctx = state;
$$ = new(ctx) ast_aggregate_initializer();
- $$->set_location(yylloc);
+ $$->set_location(@1);
$$->expressions.push_tail(& $1->link);
}
| initializer_list ',' initializer
@@ -1833,7 +1844,7 @@ compound_statement:
{
void *ctx = state;
$$ = new(ctx) ast_compound_statement(true, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
| '{'
{
@@ -1843,7 +1854,7 @@ compound_statement:
{
void *ctx = state;
$$ = new(ctx) ast_compound_statement(true, $3);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @4);
state->symbols->pop_scope();
}
;
@@ -1858,13 +1869,13 @@ compound_statement_no_new_scope:
{
void *ctx = state;
$$ = new(ctx) ast_compound_statement(false, NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
| '{' statement_list '}'
{
void *ctx = state;
$$ = new(ctx) ast_compound_statement(false, $2);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -1895,13 +1906,13 @@ expression_statement:
{
void *ctx = state;
$$ = new(ctx) ast_expression_statement(NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| expression ';'
{
void *ctx = state;
$$ = new(ctx) ast_expression_statement($1);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
;
@@ -1910,7 +1921,7 @@ selection_statement:
{
$$ = new(state) ast_selection_statement($3, $5.then_statement,
$5.else_statement);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @5);
}
;
@@ -1937,8 +1948,8 @@ condition:
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
- decl->set_location(yylloc);
- declarator->set_location(yylloc);
+ decl->set_location_range(@2, @4);
+ declarator->set_location(@1);
declarator->declarations.push_tail(&decl->link);
$$ = declarator;
@@ -1953,7 +1964,7 @@ switch_statement:
SWITCH '(' expression ')' switch_body
{
$$ = new(state) ast_switch_statement($3, $5);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @5);
}
;
@@ -1961,12 +1972,12 @@ switch_body:
'{' '}'
{
$$ = new(state) ast_switch_body(NULL);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
| '{' case_statement_list '}'
{
$$ = new(state) ast_switch_body($2);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @3);
}
;
@@ -1974,12 +1985,12 @@ case_label:
CASE expression ':'
{
$$ = new(state) ast_case_label($2);
- $$->set_location(yylloc);
+ $$->set_location(@2);
}
| DEFAULT ':'
{
$$ = new(state) ast_case_label(NULL);
- $$->set_location(yylloc);
+ $$->set_location(@2);
}
;
@@ -1990,7 +2001,7 @@ case_label_list:
labels->labels.push_tail(& $1->link);
$$ = labels;
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| case_label_list case_label
{
@@ -2003,7 +2014,7 @@ case_statement:
case_label_list statement
{
ast_case_statement *stmts = new(state) ast_case_statement($1);
- stmts->set_location(yylloc);
+ stmts->set_location(@2);
stmts->stmts.push_tail(& $2->link);
$$ = stmts;
@@ -2019,7 +2030,7 @@ case_statement_list:
case_statement
{
ast_case_statement_list *cases= new(state) ast_case_statement_list();
- cases->set_location(yylloc);
+ cases->set_location(@1);
cases->cases.push_tail(& $1->link);
$$ = cases;
@@ -2037,21 +2048,21 @@ iteration_statement:
void *ctx = state;
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
NULL, $3, NULL, $5);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @4);
}
| DO statement WHILE '(' expression ')' ';'
{
void *ctx = state;
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
NULL, $5, NULL, $2);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @6);
}
| FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
{
void *ctx = state;
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
$3, $4.cond, $4.rest, $6);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @6);
}
;
@@ -2087,31 +2098,31 @@ jump_statement:
{
void *ctx = state;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| BREAK ';'
{
void *ctx = state;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| RETURN ';'
{
void *ctx = state;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
| RETURN expression ';'
{
void *ctx = state;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
}
| DISCARD ';' // Fragment shader only.
{
void *ctx = state;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
- $$->set_location(yylloc);
+ $$->set_location(@1);
}
;
@@ -2127,7 +2138,7 @@ function_definition:
{
void *ctx = state;
$$ = new(ctx) ast_function_definition();
- $$->set_location(yylloc);
+ $$->set_location_range(@1, @2);
$$->prototype = $1;
$$->body = $2;
@@ -2276,11 +2287,13 @@ instance_name_opt:
{
$$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
$1, NULL);
+ $$->set_location(@1);
}
| NEW_IDENTIFIER array_specifier
{
$$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
$1, $2);
+ $$->set_location_range(@1, @2);
}
;
@@ -2302,7 +2315,7 @@ member_declaration:
{
void *ctx = state;
ast_fully_specified_type *type = $1;
- type->set_location(yylloc);
+ type->set_location(@1);
if (type->qualifier.flags.q.attribute) {
_mesa_glsl_error(& @1, state,
@@ -2315,7 +2328,7 @@ member_declaration:
}
$$ = new(ctx) ast_declarator_list(type);
- $$->set_location(yylloc);
+ $$->set_location(@2);
$$->declarations.push_degenerate_list_at_head(& $2->link);
}
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 87784ed..7dfae8d 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -788,8 +788,10 @@ ast_node::print(void) const
ast_node::ast_node(void)
{
this->location.source = 0;
- this->location.line = 0;
- this->location.column = 0;
+ this->location.first_line = 0;
+ this->location.first_column = 0;
+ this->location.last_line = 0;
+ this->location.last_column = 0;
}
--
1.8.3.2
More information about the mesa-dev
mailing list