[Mesa-dev] [PATCH 2/2] glsl: Add check for unsized arrays to glsl types
Timothy Arceri
t_arceri at yahoo.com.au
Tue Oct 22 13:38:13 CEST 2013
The main purpose of this patch is to increase readability of
the array code. A redundent is_array() check is also removed.
The introduction of is_unsized_array() should also make the
ARB_arrays_of_arrays code simpler and more readable when it arrives.
Signed-off-by: Timothy Arceri <t_arceri at yahoo.com.au>
---
src/glsl/ast_array_index.cpp | 2 +-
src/glsl/ast_to_hir.cpp | 14 ++++++--------
src/glsl/glsl_types.h | 11 ++++++++---
src/glsl/hir_field_selection.cpp | 2 +-
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/src/glsl/ast_array_index.cpp b/src/glsl/ast_array_index.cpp
index 107c29e..f7b5e83 100644
--- a/src/glsl/ast_array_index.cpp
+++ b/src/glsl/ast_array_index.cpp
@@ -165,7 +165,7 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
if (array->type->is_array())
update_max_array_access(array, idx, &loc, state);
} else if (const_index == NULL && array->type->is_array()) {
- if (array->type->array_size() == 0) {
+ if (array->type->is_unsized_array()) {
_mesa_glsl_error(&loc, state, "unsized array index must be constant");
} else if (array->type->fields.array->is_interface()
&& array->variable_referenced()->mode == ir_var_uniform) {
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 12be2fd..2914707 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -651,16 +651,15 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
if (rhs->type == lhs_type)
return rhs;
- /* If the array element types are the same and the size of the LHS is zero,
+ /* If the array element types are the same and the LHS is unsized,
* the assignment is okay for initializers embedded in variable
* declarations.
*
* Note: Whole-array assignments are not permitted in GLSL 1.10, but this
* is handled by ir_dereference::is_lvalue.
*/
- if (is_initializer && lhs_type->is_array() && rhs->type->is_array()
- && (lhs_type->element_type() == rhs->type->element_type())
- && (lhs_type->array_size() == 0)) {
+ if (is_initializer && lhs_type->is_unsized_array() && rhs->type->is_array()
+ && (lhs_type->element_type() == rhs->type->element_type())) {
return rhs;
}
@@ -767,7 +766,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
* dereference of a variable. Any other case would require that the LHS
* is either not an l-value or not a whole array.
*/
- if (lhs->type->array_size() == 0) {
+ if (lhs->type->is_unsized_array()) {
ir_dereference *const d = lhs->as_dereference();
assert(d != NULL);
@@ -2355,8 +2354,7 @@ get_variable_being_redeclared(ir_variable *var, YYLTYPE loc,
* later re-declare the same name as an array of the same
* type and specify a size."
*/
- if ((earlier->type->array_size() == 0)
- && var->type->is_array()
+ if (earlier->type->is_unsized_array() && var->type->is_array()
&& (var->type->element_type() == earlier->type->element_type())) {
/* FINISHME: This doesn't match the qualifiers on the two
* FINISHME: declarations. It's not 100% clear whether this is
@@ -3390,7 +3388,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
type = process_array_type(&loc, type, this->array_size, state);
}
- if (!type->is_error() && type->array_size() == 0) {
+ if (!type->is_error() && type->is_unsized_array()) {
_mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
"a declared size");
type = glsl_type::error_type;
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index e60c191..adbd96a 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -468,7 +468,6 @@ struct glsl_type {
: error_type;
}
-
/**
* Get the type of a structure field
*
@@ -478,13 +477,11 @@ struct glsl_type {
*/
const glsl_type *field_type(const char *name) const;
-
/**
* Get the location of a filed within a record type
*/
int field_index(const char *name) const;
-
/**
* Query the number of elements in an array type
*
@@ -499,6 +496,14 @@ struct glsl_type {
}
/**
+ * Query whether the number of elements of the array have all been declared.
+ */
+ bool is_unsized_array() const
+ {
+ return is_array() && length == 0;
+ }
+
+ /**
* Return the number of coordinate components needed for this sampler type.
*
* This is based purely on the sampler's dimensionality. For example, this
diff --git a/src/glsl/hir_field_selection.cpp b/src/glsl/hir_field_selection.cpp
index 08be743..1e92c89 100644
--- a/src/glsl/hir_field_selection.cpp
+++ b/src/glsl/hir_field_selection.cpp
@@ -72,7 +72,7 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
_mesa_glsl_error(&loc, state, "length method takes no arguments");
if (op->type->is_array()) {
- if (op->type->array_size() == 0)
+ if (op->type->is_unsized_array())
_mesa_glsl_error(&loc, state, "length called on unsized array");
result = new(ctx) ir_constant(op->type->array_size());
--
1.8.3.1
More information about the mesa-dev
mailing list