clean up a bunch of program parameter stuff
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c
index 2f74a5d..991378f 100644
--- a/src/mesa/shader/arbprogparse.c
+++ b/src/mesa/shader/arbprogparse.c
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -1719,7 +1719,7 @@
 {
    GLint idx;
    GLuint err = 0;
-   GLint state_tokens[6];
+   GLint state_tokens[STATE_LENGTH];
    GLfloat const_values[4];
 
    switch (*(*inst)++) {
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index e543871..8945f2d 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.2
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -71,16 +71,18 @@
  * store all the values (in blocks of 4).
  *
  * \param paramList  the list to add the parameter to
- * \param name  the parameter name, will be duplicated/copied!
- * \param values  initial parameter value, up to 4 GLfloats
- * \param size  number of elements in 'values' vector (1..4, or more)
  * \param type  type of parameter, such as 
+ * \param name  the parameter name, will be duplicated/copied!
+ * \param size  number of elements in 'values' vector (1..4, or more)
+ * \param values  initial parameter value, up to 4 GLfloats, or NULL
+ * \param state  state indexes, or NULL
  * \return  index of new parameter in the list, or -1 if error (out of mem)
  */
 GLint
 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
-                    const char *name, const GLfloat *values, GLuint size,
-                    enum register_file type)
+                    enum register_file type, const char *name,
+                    GLuint size, const GLfloat *values,
+                    const gl_state_index state[STATE_LENGTH])
 {
    const GLuint oldNum = paramList->NumParameters;
    const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
@@ -131,6 +133,12 @@
          }
          size -= 4;
       }
+
+      if (state) {
+         for (i = 0; i < STATE_LENGTH; i++)
+            paramList->Parameters[oldNum].StateIndexes[i] = state[i];
+      }
+
       return (GLint) oldNum;
    }
 }
@@ -144,7 +152,9 @@
 _mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
                           const char *name, const GLfloat values[4])
 {
-   return _mesa_add_parameter(paramList, name, values, 4, PROGRAM_NAMED_PARAM);
+   return _mesa_add_parameter(paramList, PROGRAM_NAMED_PARAM, name,
+                              4, values, NULL);
+                              
 }
 
 
@@ -173,7 +183,9 @@
    }
 #endif
    size = 4; /** XXX fix */
-   return _mesa_add_parameter(paramList, name, values, size, PROGRAM_CONSTANT);
+   return _mesa_add_parameter(paramList, PROGRAM_CONSTANT, name,
+                              size, values, NULL);
+                              
 }
 
 
@@ -202,7 +214,9 @@
                                        size, &pos, &swizzle)) {
       return pos;
    }
-   return _mesa_add_parameter(paramList, NULL, values, size, PROGRAM_CONSTANT);
+   return _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
+                              size, values, NULL);
+                              
 }
 
 
@@ -216,7 +230,9 @@
       return i;
    }
    else {
-      i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_UNIFORM);
+      i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name,
+                              size, NULL, NULL);
+                              
       return i;
    }
 }
@@ -233,7 +249,8 @@
    }
    else {
       const GLint size = 1;
-      i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_SAMPLER);
+      i = _mesa_add_parameter(paramList, PROGRAM_SAMPLER, name,
+                              size, NULL, NULL);
       return i;
    }
 }
@@ -253,7 +270,8 @@
    }
    else {
       assert(size == 4);
-      i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_VARYING);
+      i = _mesa_add_parameter(paramList, PROGRAM_VARYING, name,
+                              size, NULL, NULL);
       return i;
    }
 }
@@ -261,25 +279,28 @@
 
 /**
  * Add parameter representing a vertex program attribute.
+ * \param size  size of attribute (in floats), may be -1 if unknown
+ * \param attrib  the attribute index, or -1 if unknown
  */
 GLint
 _mesa_add_attribute(struct gl_program_parameter_list *paramList,
-                    const char *name, GLint attrib)
+                    const char *name, GLint size, GLint attrib)
 {
-   GLint size = 4; /* XXX ok? */
    GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
    if (i >= 0) {
       /* replace */
       ASSERT(paramList->Parameters[i].StateIndexes[0] == STATE_USER_ATTRIB);
+      if (attrib < 0)
+         attrib = i;
       paramList->Parameters[i].StateIndexes[1] = attrib;
    }
    else {
       /* add */
-      i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_INPUT);
-      if (i >= 0) {
-         paramList->Parameters[i].StateIndexes[0] = STATE_USER_ATTRIB;
-         paramList->Parameters[i].StateIndexes[1] = attrib;
-      }
+      gl_state_index state[STATE_LENGTH];
+      state[0] = STATE_USER_ATTRIB;
+      state[1] = attrib;
+      i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name,
+                              size, NULL, state);
    }
    return i;
 }
@@ -315,12 +336,12 @@
  *    PARAM ambient = state.material.front.ambient;
  *
  * \param paramList  the parameter list
- * \param state  an array of 6 state tokens
+ * \param state  an array of 6 (STATE_LENGTH) state tokens
  * \return index of the new parameter.
  */
 GLint
 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
-                          const GLint *stateTokens)
+                          const GLint stateTokens[STATE_LENGTH])
 {
    const GLuint size = 4; /* XXX fix */
    const char *name;
@@ -337,17 +358,19 @@
             break;
          }
       }
-      if (match == 6) {
+      if (match == STATE_LENGTH) {
          /* this state reference is already in the parameter list */
          return index;
       }
    }
 
    name = _mesa_program_state_string(stateTokens);
-   index = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_STATE_VAR);
+   index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name,
+                               size, NULL, NULL);
+                               
    if (index >= 0) {
       GLuint i;
-      for (i = 0; i < 6; i++) {
+      for (i = 0; i < STATE_LENGTH; i++) {
          paramList->Parameters[index].StateIndexes[i]
             = (gl_state_index) stateTokens[i];
       }
@@ -487,14 +510,14 @@
    for (i = 0; i < list->NumParameters; i++) {
       struct gl_program_parameter *p = list->Parameters + i;
       GLuint size = MIN2(p->Size, 4);
-      GLint j = _mesa_add_parameter(clone, p->Name, list->ParameterValues[i],
-                                    size, p->Type);
+      GLint j = _mesa_add_parameter(clone, p->Type, p->Name,
+                                    size, list->ParameterValues[i], NULL);
       ASSERT(j >= 0);
       /* copy state indexes */
       if (p->Type == PROGRAM_STATE_VAR) {
          GLint k;
          struct gl_program_parameter *q = clone->Parameters + j;
-         for (k = 0; k < 6; k++) {
+         for (k = 0; k < STATE_LENGTH; k++) {
             q->StateIndexes[k] = p->StateIndexes[k];
          }
       }
diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h
index ab4d730..bfae071 100644
--- a/src/mesa/shader/prog_parameter.h
+++ b/src/mesa/shader/prog_parameter.h
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.2
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -32,6 +32,7 @@
 #define PROG_PARAMETER_H
 
 #include "mtypes.h"
+#include "prog_statevars.h"
 
 
 /**
@@ -49,7 +50,7 @@
    /**
     * A sequence of STATE_* tokens and integers to identify GL state.
     */
-   GLuint StateIndexes[6];
+   GLuint StateIndexes[STATE_LENGTH];
 };
 
 
@@ -78,8 +79,9 @@
 
 extern GLint
 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
-                    const char *name, const GLfloat *values, GLuint size,
-                    enum register_file type);
+                    enum register_file type, const char *name,
+                    GLuint size, const GLfloat *values,
+                    const gl_state_index state[STATE_LENGTH]);
 
 extern GLint
 _mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
@@ -109,11 +111,11 @@
 
 extern GLint
 _mesa_add_attribute(struct gl_program_parameter_list *paramList,
-                    const char *name, GLint attrib);
+                    const char *name, GLint size, GLint attrib);
 
 extern GLint
 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
-                          const GLint *stateTokens);
+                          const GLint stateTokens[STATE_LENGTH]);
 
 extern GLfloat *
 _mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c
index 7377c7d..a0a00cf 100644
--- a/src/mesa/shader/prog_statevars.c
+++ b/src/mesa/shader/prog_statevars.c
@@ -2,7 +2,7 @@
  * Mesa 3-D graphics library
  * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -418,7 +418,7 @@
  * some GL state has changed.
  */
 GLbitfield
-_mesa_program_state_flags(const GLint state[])
+_mesa_program_state_flags(const GLint state[STATE_LENGTH])
 {
    switch (state[0]) {
    case STATE_MATERIAL:
@@ -661,7 +661,7 @@
  * Use _mesa_free() to deallocate the string.
  */
 const char *
-_mesa_program_state_string(const GLint state[6])
+_mesa_program_state_string(const GLint state[STATE_LENGTH])
 {
    char str[1000] = "";
    char tmp[30];
diff --git a/src/mesa/shader/prog_statevars.h b/src/mesa/shader/prog_statevars.h
index da672c9..47ef615 100644
--- a/src/mesa/shader/prog_statevars.h
+++ b/src/mesa/shader/prog_statevars.h
@@ -29,6 +29,13 @@
 
 
 /**
+ * Number of STATE_* values we need to address any GL state.
+ * Used to dimension arrays.
+ */
+#define STATE_LENGTH 6
+
+
+/**
  * Used for describing GL state referenced from inside ARB vertex and
  * fragment programs.
  * A string such as "state.light[0].ambient" gets translated into a
@@ -109,11 +116,11 @@
 
 
 extern GLbitfield
-_mesa_program_state_flags(const GLint state[]);
+_mesa_program_state_flags(const GLint state[STATE_LENGTH]);
 
 
 extern const char *
-_mesa_program_state_string(const GLint state[6]);
+_mesa_program_state_string(const GLint state[STATE_LENGTH]);
 
 
 #endif /* PROG_STATEVARS_H */
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index d1b0e21..397ce91 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -278,8 +278,8 @@
 {
    struct gl_shader_program *shProg
       = _mesa_lookup_shader_program(ctx, program);
-   GLint i;
-   GLint oldIndex;
+   const GLint size = -1; /* unknown size */
+   GLint i, oldIndex;
 
    if (!shProg) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glBindAttribLocation(program)");
@@ -298,7 +298,7 @@
    oldIndex = _mesa_get_attrib_location(ctx, program, name);
 
    /* this will replace the current value if it's already in the list */
-   i = _mesa_add_attribute(shProg->Attributes, name, index);
+   i = _mesa_add_attribute(shProg->Attributes, name, size, index);
    if (i < 0) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
    }
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index cc70d1d..91e1173 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -119,7 +119,7 @@
       const char *Name;
       const GLuint NumRows;  /** for matrices */
       const GLuint Swizzle;
-      const GLint Indexes[6];
+      const GLint Indexes[STATE_LENGTH];
    };
    static const struct state_info state[] = {
       { "gl_ModelViewMatrix", 4, SWIZZLE_NOOP,
@@ -143,9 +143,9 @@
             if (state[i].NumRows > 1) {
                /* a matrix */
                GLuint j;
-               GLint pos[4], indexesCopy[6];
+               GLint pos[4], indexesCopy[STATE_LENGTH];
                /* make copy of state tokens */
-               for (j = 0; j < 6; j++)
+               for (j = 0; j < STATE_LENGTH; j++)
                   indexesCopy[j] = state[i].Indexes[j];
                /* load rows */
                for (j = 0; j < state[i].NumRows; j++) {
@@ -554,8 +554,9 @@
       if (prog) {
          /* user-defined vertex attribute */
          const GLint size = _slang_sizeof_type_specifier(&var->type.specifier);
-         GLint index = _mesa_add_parameter(prog->Attributes, varName,
-                                           NULL, size, PROGRAM_INPUT);
+         const GLint attr = -1; /* unknown */
+         GLint index = _mesa_add_attribute(prog->Attributes, varName,
+                                           size, attr);
          assert(index >= 0);
          store = _slang_new_ir_storage(PROGRAM_INPUT,
                                        VERT_ATTRIB_GENERIC0 + index, size);
diff --git a/src/mesa/shader/slang/slang_link2.c b/src/mesa/shader/slang/slang_link2.c
index 0965f3e..da5ba5c 100644
--- a/src/mesa/shader/slang/slang_link2.c
+++ b/src/mesa/shader/slang/slang_link2.c
@@ -323,6 +323,7 @@
 {
    GLuint i, j;
    GLbitfield usedAttributes;
+   GLint size = 4; /* XXX fix */
 
    assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
 
@@ -369,7 +370,7 @@
                   /* too many!  XXX record error log */
                   return GL_FALSE;
                }
-               _mesa_add_attribute(shProg->Attributes, name, attr);
+               _mesa_add_attribute(shProg->Attributes, name, size, attr);
             }
 
             inst->SrcReg[j].Index = VERT_ATTRIB_GENERIC0 + attr;