mesa: move _slang_locate_function() to different file
[mesa.git] / src / mesa / shader / slang / slang_typeinfo.c
index b1afd969d9559e687aa34e5578e46398393eefa4..430fc10b672fa8899c09567c5935a177c5b3d9a5 100644 (file)
@@ -187,6 +187,21 @@ slang_type_specifier_dtr(slang_type_specifier * self)
    }
 }
 
+slang_type_specifier *
+slang_type_specifier_new(slang_type_specifier_type type,
+                         struct slang_struct_ *_struct,
+                         struct slang_type_specifier_ *_array)
+{
+   slang_type_specifier *spec =
+      (slang_type_specifier *) _mesa_malloc(sizeof(slang_type_specifier));
+   if (spec) {
+      spec->type = type;
+      spec->_struct = _struct;
+      spec->_array = _array;
+   }
+   return spec;
+}
+
 GLboolean
 slang_type_specifier_copy(slang_type_specifier * x,
                           const slang_type_specifier * y)
@@ -250,7 +265,7 @@ slang_type_specifier_equal(const slang_type_specifier * x,
 /**
  * As above, but allow float/int casting.
  */
-static GLboolean
+GLboolean
 slang_type_specifier_compatible(const slang_type_specifier * x,
                                 const slang_type_specifier * y)
 {
@@ -583,7 +598,18 @@ _slang_typeof_operation_(slang_operation * op,
       }
       break;
    case SLANG_OPER_CALL:
-      if (op->fun) {
+      if (op->array_constructor) {
+         /* build array typeinfo */
+         ti->spec.type = SLANG_SPEC_ARRAY;
+         ti->spec._array = (slang_type_specifier *)
+            _slang_alloc(sizeof(slang_type_specifier));
+         slang_type_specifier_ctr(ti->spec._array);
+
+         ti->spec._array->type =
+            slang_type_specifier_type_from_string((char *) op->a_id);
+         ti->array_len = op->num_children;
+      }
+      else if (op->fun) {
          /* we've resolved this call before */
          slang_type_specifier_copy(&ti->spec, &op->fun->header.type.specifier);
       }
@@ -761,77 +787,6 @@ _slang_typeof_operation_(slang_operation * op,
 }
 
 
-/**
- * Lookup a function according to name and parameter count/types.
- */
-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, GLboolean *error)
-{
-   slang_typeinfo arg_ti[100];
-   GLuint i;
-
-   *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 (j == num_args) {
-            /* name and args match! */
-            return f;
-         }
-      }
-
-      funcs = funcs->outer_scope;
-   }
-
-   return NULL;
-}
-
-
 /**
  * Determine if a type is a matrix.
  * \return GL_TRUE if is a matrix, GL_FALSE otherwise.