From 0bf381016524ac58f5961877ea0e8651c4922ca3 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 31 Mar 2010 14:37:42 -0700 Subject: [PATCH] glsl_type array constructor generate a real name for the type --- glsl_types.cpp | 26 ++++++++++++++++++++++++++ glsl_types.h | 12 ++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/glsl_types.cpp b/glsl_types.cpp index 8d11196e93d..eb9ab820b16 100644 --- a/glsl_types.cpp +++ b/glsl_types.cpp @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include #include "glsl_symbol_table.h" #include "glsl_parser_extras.h" @@ -489,6 +490,31 @@ _mesa_glsl_initialize_constructors(exec_list *instructions, } +glsl_type::glsl_type(const glsl_type *array, unsigned length) : + base_type(GLSL_TYPE_ARRAY), + sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), + sampler_type(0), + vector_elements(0), matrix_columns(0), + name(NULL), length(length) +{ + this->fields.array = array; + + /* Allow a maximum of 10 characters for the array size. This is enough + * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating + * NUL. + */ + const unsigned name_length = strlen(array->name) + 10 + 3; + char *const n = (char *) malloc(name_length); + + if (length == 0) + snprintf(n, name_length, "%s[]", array->name); + else + snprintf(n, name_length, "%s[%u]", array->name, length); + + this->name = n; +} + + const glsl_type * glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) { diff --git a/glsl_types.h b/glsl_types.h index 6f3b512f288..23a04fbe9d0 100644 --- a/glsl_types.h +++ b/glsl_types.h @@ -309,16 +309,8 @@ private: /** * Constructor for array types */ - glsl_type(const glsl_type *array, unsigned length) : - base_type(GLSL_TYPE_ARRAY), - sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), - sampler_type(0), - vector_elements(0), matrix_columns(0), - name(NULL), length(length) - { - this->fields.array = array; - this->name = ""; - } + glsl_type(const glsl_type *array, unsigned length); + /** * \name Pointers to various private type singletons -- 2.30.2