From 824b659d917a5f14a1f66b891d25036ef9f9adc6 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 11 Jun 2010 16:57:47 -0700 Subject: [PATCH] ir_constant: Eliminate 'void *' constructor All of the places that had been using the (glsl_type *, void *) constructor were actually passing an ir_constant_data for the 'void *'. The code can be greatly simplified by replacing this constructor with a (glsl_type *, ir_constant_data *) constructor. This should also help prevent one class of invalid uses of the old constructor. --- ir.cpp | 19 +++++-------------- ir.h | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/ir.cpp b/ir.cpp index 38e2739..d50293d 100644 --- a/ir.cpp +++ b/ir.cpp @@ -189,23 +189,14 @@ ir_constant::ir_constant() /* empty */ } -ir_constant::ir_constant(const struct glsl_type *type, const void *data) +ir_constant::ir_constant(const struct glsl_type *type, + const ir_constant_data *data) { - unsigned size = 0; + assert((type->base_type >= GLSL_TYPE_UINT) + && (type->base_type <= GLSL_TYPE_BOOL)); this->type = type; - switch (type->base_type) { - case GLSL_TYPE_UINT: size = sizeof(this->value.u[0]); break; - case GLSL_TYPE_INT: size = sizeof(this->value.i[0]); break; - case GLSL_TYPE_FLOAT: size = sizeof(this->value.f[0]); break; - case GLSL_TYPE_BOOL: size = sizeof(this->value.b[0]); break; - default: - /* FINISHME: What to do? Exceptions are not the answer. - */ - break; - } - - memcpy(& this->value, data, size * type->components()); + memcpy(& this->value, data, sizeof(this->value)); } ir_constant::ir_constant(float f) diff --git a/ir.h b/ir.h index 1fdd125..33b6069 100644 --- a/ir.h +++ b/ir.h @@ -1031,7 +1031,7 @@ union ir_constant_data { class ir_constant : public ir_rvalue { public: - ir_constant(const struct glsl_type *type, const void *data); + ir_constant(const struct glsl_type *type, const ir_constant_data *data); ir_constant(bool b); ir_constant(unsigned int u); ir_constant(int i); -- 2.7.4