From 0471e8b0896e05b3bc81ccad6184e6e35fb61425 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 26 Mar 2010 14:33:41 -0700 Subject: [PATCH] Make glsl_*_type glsl_type class static data --- ast_to_hir.cpp | 42 +++++++++++++++++++++--------------------- builtin_types.sh | 12 ++++++------ glsl_types.cpp | 34 +++++++++++++++++----------------- glsl_types.h | 32 +++++++++++++++++++------------- ir.cpp | 6 +++--- 5 files changed, 66 insertions(+), 60 deletions(-) diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 884516f8b67..40a980f6826 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -85,7 +85,7 @@ arithmetic_result_type(const struct glsl_type *type_a, * floating-point scalars, vectors, and matrices." */ if (!type_a->is_numeric() || !type_b->is_numeric()) { - return glsl_error_type; + return glsl_type::error_type; } @@ -114,7 +114,7 @@ arithmetic_result_type(const struct glsl_type *type_a, * equality. */ if (type_a->base_type != type_b->base_type) { - return glsl_error_type; + return glsl_type::error_type; } /* "All arithmetic binary operators result in the same fundamental type @@ -152,7 +152,7 @@ arithmetic_result_type(const struct glsl_type *type_a, * vector." */ if (type_a->is_vector() && type_b->is_vector()) { - return (type_a == type_b) ? type_a : glsl_error_type; + return (type_a == type_b) ? type_a : glsl_type::error_type; } /* All of the combinations of , , @@ -181,7 +181,7 @@ arithmetic_result_type(const struct glsl_type *type_a, * more detail how vectors and matrices are operated on." */ if (! multiply) { - return (type_a == type_b) ? type_a : glsl_error_type; + return (type_a == type_b) ? type_a : glsl_type::error_type; } else { if (type_a->is_matrix() && type_b->is_matrix()) { /* Matrix multiply. The columns of A must match the rows of B. Given @@ -224,7 +224,7 @@ arithmetic_result_type(const struct glsl_type *type_a, /* "All other cases are illegal." */ - return glsl_error_type; + return glsl_type::error_type; } @@ -240,7 +240,7 @@ unary_arithmetic_result_type(const struct glsl_type *type) * they operated on." */ if (!is_numeric_base_type(type->base_type)) - return glsl_error_type; + return glsl_type::error_type; return type; } @@ -258,7 +258,7 @@ modulus_result_type(const struct glsl_type *type_a, if (! is_integer_base_type(type_a->base_type) || ! is_integer_base_type(type_b->base_type) || (type_a->base_type != type_b->base_type)) { - return glsl_error_type; + return glsl_type::error_type; } /* "The operands cannot be vectors of differing size. If one operand is @@ -276,7 +276,7 @@ modulus_result_type(const struct glsl_type *type_a, /* "The operator modulus (%) is not defined for any other data types * (non-integer types)." */ - return glsl_error_type; + return glsl_type::error_type; } @@ -294,7 +294,7 @@ relational_result_type(const struct glsl_type *type_a, || ! is_numeric_base_type(type_b->base_type) || !type_a->is_scalar() || !type_b->is_scalar()) - return glsl_error_type; + return glsl_type::error_type; /* "Either the operands' types must match, or the conversions from * Section 4.1.10 "Implicit Conversions" will be applied to the integer @@ -314,11 +314,11 @@ relational_result_type(const struct glsl_type *type_a, } if (type_a->base_type != type_b->base_type) - return glsl_error_type; + return glsl_type::error_type; /* "The result is scalar Boolean." */ - return glsl_bool_type; + return glsl_type::bool_type; } @@ -434,7 +434,7 @@ ast_expression::hir(exec_list *instructions, ir_rvalue *result = NULL; ir_rvalue *op[2]; struct simple_node op_list; - const struct glsl_type *type = glsl_error_type; + const struct glsl_type *type = glsl_type::error_type; bool error_emitted = false; YYLTYPE loc; @@ -456,13 +456,13 @@ ast_expression::hir(exec_list *instructions, if (!op[0]->is_lvalue()) { _mesa_glsl_error(& loc, state, "non-lvalue in assignment"); error_emitted = true; - type = glsl_error_type; + type = glsl_type::error_type; } } ir_instruction *rhs = validate_assignment(op[0]->type, op[1]); if (rhs == NULL) { - type = glsl_error_type; + type = glsl_type::error_type; rhs = op[1]; } @@ -597,13 +597,13 @@ ast_expression::hir(exec_list *instructions, if (!op[0]->is_lvalue()) { _mesa_glsl_error(& loc, state, "non-lvalue in assignment"); error_emitted = true; - type = glsl_error_type; + type = glsl_type::error_type; } } ir_rvalue *rhs = validate_assignment(op[0]->type, temp_rhs); if (rhs == NULL) { - type = glsl_error_type; + type = glsl_type::error_type; rhs = temp_rhs; } @@ -674,22 +674,22 @@ ast_expression::hir(exec_list *instructions, } case ast_int_constant: - type = glsl_int_type; + type = glsl_type::int_type; result = new ir_constant(type, & this->primary_expression); break; case ast_uint_constant: - type = glsl_uint_type; + type = glsl_type::uint_type; result = new ir_constant(type, & this->primary_expression); break; case ast_float_constant: - type = glsl_float_type; + type = glsl_type::float_type; result = new ir_constant(type, & this->primary_expression); break; case ast_bool_constant: - type = glsl_bool_type; + type = glsl_type::bool_type; result = new ir_constant(type, & this->primary_expression); break; @@ -939,7 +939,7 @@ ast_parameter_declarator::hir(exec_list *instructions, this->identifier); } - type = glsl_error_type; + type = glsl_type::error_type; } ir_variable *var = new ir_variable(type, this->identifier); diff --git a/builtin_types.sh b/builtin_types.sh index 299a4cef415..6658ada41a6 100755 --- a/builtin_types.sh +++ b/builtin_types.sh @@ -119,13 +119,13 @@ cat <push_tail(inst); const float z = 0.0f; - ir_constant *const zero = new ir_constant(glsl_float_type, &z); + ir_constant *const zero = new ir_constant(glsl_type::float_type, &z); for (unsigned i = 1; i < column_type->vector_elements; i++) { ir_dereference *const lhs_ref = new ir_dereference(column); @@ -293,7 +293,7 @@ generate_mat_body_from_scalar(exec_list *instructions, swiz[5 - i], swiz[6 - i], column_type->vector_elements); - ir_constant *const idx = new ir_constant(glsl_int_type, &i); + ir_constant *const idx = new ir_constant(glsl_type::int_type, &i); ir_dereference *const lhs = new ir_dereference(declarations[16], idx); inst = new ir_assignment(lhs, rhs, NULL); @@ -323,7 +323,7 @@ generate_mat_body_from_N_scalars(exec_list *instructions, */ for (unsigned i = 0; i < column_type->vector_elements; i++) { for (unsigned j = 0; j < row_type->vector_elements; j++) { - ir_constant *row_index = new ir_constant(glsl_int_type, &i); + ir_constant *row_index = new ir_constant(glsl_type::int_type, &i); ir_dereference *const row_access = new ir_dereference(declarations[16], row_index); @@ -486,7 +486,7 @@ const glsl_type * glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) { if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4)) - return glsl_error_type; + return error_type; /* Treat GLSL vectors as Nx1 matrices. @@ -494,19 +494,19 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) if (columns == 1) { switch (base_type) { case GLSL_TYPE_UINT: - return glsl_uint_type + (rows - 1); + return uint_type + (rows - 1); case GLSL_TYPE_INT: - return glsl_int_type + (rows - 1); + return int_type + (rows - 1); case GLSL_TYPE_FLOAT: - return glsl_float_type + (rows - 1); + return float_type + (rows - 1); case GLSL_TYPE_BOOL: - return glsl_bool_type + (rows - 1); + return bool_type + (rows - 1); default: - return glsl_error_type; + return error_type; } } else { if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1)) - return glsl_error_type; + return error_type; /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following * combinations are valid: @@ -529,10 +529,10 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) case IDX(4,2): return mat4x2_type; case IDX(4,3): return mat4x3_type; case IDX(4,4): return mat4_type; - default: return glsl_error_type; + default: return error_type; } } assert(!"Should not get here."); - return glsl_error_type; + return error_type; } diff --git a/glsl_types.h b/glsl_types.h index a795af2cd38..e05130102a5 100644 --- a/glsl_types.h +++ b/glsl_types.h @@ -39,12 +39,6 @@ #define GLSL_TYPE_VOID 8 #define GLSL_TYPE_ERROR 9 -extern const struct glsl_type *const glsl_error_type; -extern const struct glsl_type *const glsl_int_type; -extern const struct glsl_type *const glsl_uint_type; -extern const struct glsl_type *const glsl_float_type; -extern const struct glsl_type *const glsl_bool_type; - #define is_numeric_base_type(b) \ (((b) >= GLSL_TYPE_UINT) && ((b) <= GLSL_TYPE_FLOAT)) @@ -107,6 +101,18 @@ struct glsl_type { } fields; + /** + * \name Pointers to various public type singletons + */ + /*@{*/ + static const glsl_type *const error_type; + static const glsl_type *const int_type; + static const glsl_type *const uint_type; + static const glsl_type *const float_type; + static const glsl_type *const bool_type; + /*@}*/ + + glsl_type(unsigned base_type, unsigned vector_elements, unsigned matrix_columns, const char *name) : base_type(base_type), @@ -233,33 +239,33 @@ struct glsl_type { * Query the full type of a matrix row * * \return - * If the type is not a matrix, \c glsl_error_type is returned. Otherwise - * a type matching the rows of the matrix is returned. + * If the type is not a matrix, \c glsl_type::error_type is returned. + * Otherwise a type matching the rows of the matrix is returned. */ const glsl_type *row_type() const { return is_matrix() ? get_instance(base_type, matrix_columns, 1) - : glsl_error_type; + : error_type; } /** * Query the full type of a matrix column * * \return - * If the type is not a matrix, \c glsl_error_type is returned. Otherwise - * a type matching the columns of the matrix is returned. + * If the type is not a matrix, \c glsl_type::error_type is returned. + * Otherwise a type matching the columns of the matrix is returned. */ const glsl_type *column_type() const { return is_matrix() ? get_instance(base_type, vector_elements, 1) - : glsl_error_type; + : error_type; } private: /** - * \name Pointers to various type singletons + * \name Pointers to various private type singletons */ /*@{*/ static const glsl_type *const mat2_type; diff --git a/ir.cpp b/ir.cpp index 58c459ed5db..c4c7584bcfa 100644 --- a/ir.cpp +++ b/ir.cpp @@ -83,7 +83,7 @@ ir_dereference::ir_dereference(ir_instruction *var) { this->mode = ir_reference_variable; this->var = var; - this->type = (var != NULL) ? var->type : glsl_error_type; + this->type = (var != NULL) ? var->type : glsl_type::error_type; } @@ -92,7 +92,7 @@ ir_dereference::ir_dereference(ir_instruction *var, : ir_rvalue(), mode(ir_reference_array), var(var) { - this->type = (var != NULL) ? var->type : glsl_error_type; + this->type = (var != NULL) ? var->type : glsl_type::error_type; this->selector.array_index = array_index; } @@ -237,6 +237,6 @@ ir_call::get_error_instruction() { ir_call *call = new ir_call; - call->type = glsl_error_type; + call->type = glsl_type::error_type; return call; } -- 2.30.2