From 1638edb3256b3b4bd8bc2eb65d02573601ef9a44 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 29 Jul 2008 17:29:30 -0600 Subject: mesa: glsl: assorted fixes for resolving polymorphic functions Plus, - fix some issues in casting function arguments to format param types. - fix some vec/mat constructor bugs - find/report more syntax/semantic errors --- src/mesa/shader/slang/slang_typeinfo.c | 100 ++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 39 deletions(-) (limited to 'src/mesa/shader/slang/slang_typeinfo.c') diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index 8a1c3abf48..26f9f6ca85 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -273,6 +273,7 @@ slang_type_specifier_compatible(const slang_type_specifier * x, GLboolean slang_typeinfo_construct(slang_typeinfo * ti) { + /*_mesa_bzero(ti, sizeof(*ti));*/ slang_type_specifier_ctr(&ti->spec); ti->array_len = 0; return GL_TRUE; @@ -304,10 +305,16 @@ _slang_typeof_function(slang_atom a_name, slang_function **funFound, slang_atom_pool *atoms, slang_info_log *log) { + GLboolean error; + *funFound = _slang_locate_function(space->funcs, a_name, params, - num_params, space, atoms, log); + num_params, space, atoms, log, &error); + if (error) + return GL_FALSE; + if (!*funFound) return GL_TRUE; /* yes, not false */ + return slang_type_specifier_copy(spec, &(*funFound)->header.type.specifier); } @@ -755,51 +762,66 @@ slang_function * _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, slang_operation * args, GLuint num_args, const slang_name_space * space, slang_atom_pool * atoms, - slang_info_log *log) + slang_info_log *log, GLboolean *error) { + slang_typeinfo arg_ti[100]; GLuint i; - for (i = 0; i < funcs->num_functions; i++) { - slang_function *f = &funcs->functions[i]; - const GLuint haveRetValue = _slang_function_has_return_value(f); - GLuint j; - - if (a_name != f->header.a_name) - continue; - if (f->param_count - haveRetValue != num_args) - continue; - - /* compare parameter / argument types */ - for (j = 0; j < num_args; j++) { - slang_typeinfo ti; - - if (!slang_typeinfo_construct(&ti)) - return NULL; - if (!_slang_typeof_operation_(&args[j], space, &ti, atoms, log)) { - slang_typeinfo_destruct(&ti); - return NULL; + *error = GL_FALSE; + + /* determine type of each argument */ + assert(num_args < 100); + for (i = 0; i < num_args; i++) { + if (!slang_typeinfo_construct(&arg_ti[i])) + return NULL; + if (!_slang_typeof_operation_(&args[i], space, &arg_ti[i], atoms, log)) { + return NULL; + } + } + + /* loop over function scopes */ + while (funcs) { + + /* look for function with matching name and argument/param types */ + for (i = 0; i < funcs->num_functions; i++) { + slang_function *f = &funcs->functions[i]; + const GLuint haveRetValue = _slang_function_has_return_value(f); + GLuint j; + + if (a_name != f->header.a_name) + continue; + if (f->param_count - haveRetValue != num_args) + continue; + + /* compare parameter / argument types */ + for (j = 0; j < num_args; j++) { + if (!slang_type_specifier_compatible(&arg_ti[j].spec, + &f->parameters->variables[j]->type.specifier)) { + /* param/arg types don't match */ + break; + } + + /* "out" and "inout" formal parameter requires the actual + * argument to be an l-value. + */ + if (!arg_ti[j].can_be_referenced && + (f->parameters->variables[j]->type.qualifier == SLANG_QUAL_OUT || + f->parameters->variables[j]->type.qualifier == SLANG_QUAL_INOUT)) { + /* param is not an lvalue! */ + *error = GL_TRUE; + return NULL; + } } - if (!slang_type_specifier_compatible(&ti.spec, - &f->parameters->variables[j]->type.specifier)) { - slang_typeinfo_destruct(&ti); - break; + + if (j == num_args) { + /* name and args match! */ + return f; } - slang_typeinfo_destruct(&ti); - - /* "out" and "inout" formal parameter requires the actual - * parameter to be l-value. - */ - if (!ti.can_be_referenced && - (f->parameters->variables[j]->type.qualifier == SLANG_QUAL_OUT || - f->parameters->variables[j]->type.qualifier == SLANG_QUAL_INOUT)) - break; } - if (j == num_args) - return f; + + funcs = funcs->outer_scope; } - if (funcs->outer_scope != NULL) - return _slang_locate_function(funcs->outer_scope, a_name, args, - num_args, space, atoms, log); + return NULL; } -- cgit v1.2.3