summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2006-11-16 22:31:34 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2006-11-16 22:31:34 +0000
commit523f5cfeb537e52baa892148b7b050fb076ef1b0 (patch)
treef9eaf88ea712a5236ad52c4f33b921206eeb9b99
parent1f0c86ee350f168a5b7420bfda7d80365432c811 (diff)
Add a lot of const qualifiers for const-correctness.
New comments, misc clean-ups.
-rw-r--r--src/mesa/shader/slang/slang_assemble.c6
-rw-r--r--src/mesa/shader/slang/slang_assemble.h11
-rw-r--r--src/mesa/shader/slang/slang_assemble_typeinfo.c105
-rw-r--r--src/mesa/shader/slang/slang_assemble_typeinfo.h138
-rw-r--r--src/mesa/shader/slang/slang_utility.c21
-rw-r--r--src/mesa/shader/slang/slang_utility.h2
6 files changed, 184 insertions, 99 deletions
diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c
index 603fd4f7f8..09b1df7cb0 100644
--- a/src/mesa/shader/slang/slang_assemble.c
+++ b/src/mesa/shader/slang/slang_assemble.c
@@ -232,9 +232,9 @@ collect_locals(slang_assemble_ctx * A, slang_operation * op, GLuint * size)
/* _slang_locate_function() */
slang_function *
-_slang_locate_function(slang_function_scope * funcs, slang_atom a_name,
- slang_operation * params, GLuint num_params,
- slang_assembly_name_space * space,
+_slang_locate_function(const slang_function_scope * funcs, slang_atom a_name,
+ const slang_operation * params, GLuint num_params,
+ const slang_assembly_name_space * space,
slang_atom_pool * atoms)
{
GLuint i;
diff --git a/src/mesa/shader/slang/slang_assemble.h b/src/mesa/shader/slang/slang_assemble.h
index 54589ad7d1..3f75e971be 100644
--- a/src/mesa/shader/slang/slang_assemble.h
+++ b/src/mesa/shader/slang/slang_assemble.h
@@ -216,14 +216,19 @@ typedef struct slang_assemble_ctx_
} slang_assemble_ctx;
extern struct slang_function_ *
-_slang_locate_function(struct slang_function_scope_ *funcs, slang_atom name,
- struct slang_operation_ *params, GLuint num_params,
- slang_assembly_name_space *space, slang_atom_pool *);
+_slang_locate_function(const struct slang_function_scope_ *funcs,
+ slang_atom name, const struct slang_operation_ *params,
+ GLuint num_params,
+ const slang_assembly_name_space *space,
+ slang_atom_pool *);
extern GLboolean
_slang_assemble_function(slang_assemble_ctx *, struct slang_function_ *);
extern GLboolean
+_slang_assemble_function2(slang_assemble_ctx * , struct slang_function_ *);
+
+extern GLboolean
_slang_cleanup_stack(slang_assemble_ctx *, struct slang_operation_ *);
extern GLboolean
diff --git a/src/mesa/shader/slang/slang_assemble_typeinfo.c b/src/mesa/shader/slang/slang_assemble_typeinfo.c
index 340d6c1c58..f4ee573df7 100644
--- a/src/mesa/shader/slang/slang_assemble_typeinfo.c
+++ b/src/mesa/shader/slang/slang_assemble_typeinfo.c
@@ -131,31 +131,53 @@ slang_assembly_typeinfo_destruct(slang_assembly_typeinfo * ti)
/* _slang_typeof_operation() */
+/**
+ * Determine the return type of a function.
+ * \param name name of the function
+ * \param params array of function parameters
+ * \param num_params number of parameters
+ * \param space namespace to use
+ * \param spec returns the function's type
+ * \param atoms atom pool
+ * \return GL_TRUE for success, GL_FALSE if failure
+ */
static GLboolean
-typeof_existing_function(const char *name, slang_operation * params,
- GLuint num_params, slang_assembly_name_space * space,
- slang_type_specifier * spec, slang_atom_pool * atoms)
+typeof_existing_function(const char *name, const slang_operation * params,
+ GLuint num_params,
+ const slang_assembly_name_space * space,
+ slang_type_specifier * spec,
+ slang_atom_pool * atoms)
{
slang_atom atom;
GLboolean exists;
atom = slang_atom_pool_atom(atoms, name);
- if (!_slang_typeof_function
- (atom, params, num_params, space, spec, &exists, atoms))
+ if (!_slang_typeof_function(atom, params, num_params, space, spec,
+ &exists, atoms))
return GL_FALSE;
return exists;
}
GLboolean
-_slang_typeof_operation(slang_assemble_ctx * A, slang_operation * op,
+_slang_typeof_operation(const slang_assemble_ctx * A,
+ const slang_operation * op,
slang_assembly_typeinfo * ti)
{
return _slang_typeof_operation_(op, &A->space, ti, A->atoms);
}
+
+/**
+ * Determine the return type of an operation.
+ * \param op the operation node
+ * \param space the namespace to use
+ * \param ti the returned type
+ * \param atoms atom pool
+ * \return GL_TRUE for success, GL_FALSE if failure
+ */
GLboolean
-_slang_typeof_operation_(slang_operation * op,
- slang_assembly_name_space * space,
+_slang_typeof_operation_(const slang_operation * op,
+ const slang_assembly_name_space * space,
slang_assembly_typeinfo * ti,
slang_atom_pool * atoms)
{
@@ -247,23 +269,23 @@ _slang_typeof_operation_(slang_operation * op,
/*case slang_oper_lshift: */
/*case slang_oper_rshift: */
case slang_oper_add:
- if (!typeof_existing_function
- ("+", op->children, 2, space, &ti->spec, atoms))
+ if (!typeof_existing_function("+", op->children, 2, space,
+ &ti->spec, atoms))
return GL_FALSE;
break;
case slang_oper_subtract:
- if (!typeof_existing_function
- ("-", op->children, 2, space, &ti->spec, atoms))
+ if (!typeof_existing_function("-", op->children, 2, space,
+ &ti->spec, atoms))
return GL_FALSE;
break;
case slang_oper_multiply:
- if (!typeof_existing_function
- ("*", op->children, 2, space, &ti->spec, atoms))
+ if (!typeof_existing_function("*", op->children, 2, space,
+ &ti->spec, atoms))
return GL_FALSE;
break;
case slang_oper_divide:
- if (!typeof_existing_function
- ("/", op->children, 2, space, &ti->spec, atoms))
+ if (!typeof_existing_function("/", op->children, 2, space,
+ &ti->spec, atoms))
return GL_FALSE;
break;
/*case slang_oper_modulus: */
@@ -311,9 +333,8 @@ _slang_typeof_operation_(slang_operation * op,
{
GLboolean exists;
- if (!_slang_typeof_function
- (op->a_id, op->children, op->num_children, space, &ti->spec,
- &exists, atoms))
+ if (!_slang_typeof_function(op->a_id, op->children, op->num_children,
+ space, &ti->spec, &exists, atoms))
return GL_FALSE;
if (!exists) {
slang_struct *s =
@@ -468,27 +489,38 @@ _slang_typeof_operation_(slang_operation * op,
return GL_TRUE;
}
-/* _slang_typeof_function() */
+
+/**
+ * Determine the return type of a function.
+ * \param a_name the function name
+ * \param param function parameters (overloading)
+ * \param num_params number of parameters to function
+ * \param space namespace to search
+ * \param exists returns GL_TRUE or GL_FALSE to indicate existance of function
+ * \return GL_TRUE for success, GL_FALSE if failure (bad function name)
+ */
GLboolean
-_slang_typeof_function(slang_atom a_name, slang_operation * params,
- GLuint num_params, slang_assembly_name_space * space,
+_slang_typeof_function(slang_atom a_name, const slang_operation * params,
+ GLuint num_params,
+ const slang_assembly_name_space * space,
slang_type_specifier * spec, GLboolean * exists,
slang_atom_pool * atoms)
{
- slang_function *fun;
-
- fun =
- _slang_locate_function(space->funcs, a_name, params, num_params, space,
- atoms);
+ slang_function *fun = _slang_locate_function(space->funcs, a_name, params,
+ num_params, space, atoms);
*exists = fun != NULL;
- if (fun == NULL)
- return GL_TRUE;
+ if (!fun)
+ return GL_TRUE; /* yes, not false */
return slang_type_specifier_copy(spec, &fun->header.type.specifier);
}
-/* _slang_type_is_matrix() */
+
+/**
+ * Determine if a type is a matrix.
+ * \return GL_TRUE if is a matrix, GL_FALSE otherwise.
+ */
GLboolean
_slang_type_is_matrix(slang_type_specifier_type ty)
{
@@ -502,8 +534,11 @@ _slang_type_is_matrix(slang_type_specifier_type ty)
}
}
-/* _slang_type_is_vector() */
+/**
+ * Determine if a type is a vector.
+ * \return GL_TRUE if is a vector, GL_FALSE otherwise.
+ */
GLboolean
_slang_type_is_vector(slang_type_specifier_type ty)
{
@@ -523,8 +558,10 @@ _slang_type_is_vector(slang_type_specifier_type ty)
}
}
-/* _slang_type_base_of_vector() */
+/**
+ * Given a vector type, return the type of the vector's elements
+ */
slang_type_specifier_type
_slang_type_base(slang_type_specifier_type ty)
{
@@ -555,8 +592,10 @@ _slang_type_base(slang_type_specifier_type ty)
}
}
-/* _slang_type_dim */
+/**
+ * Return the number of elements in a vector or matrix type
+ */
GLuint
_slang_type_dim(slang_type_specifier_type ty)
{
diff --git a/src/mesa/shader/slang/slang_assemble_typeinfo.h b/src/mesa/shader/slang/slang_assemble_typeinfo.h
index 7e8af96915..5d951226a1 100644
--- a/src/mesa/shader/slang/slang_assemble_typeinfo.h
+++ b/src/mesa/shader/slang/slang_assemble_typeinfo.h
@@ -29,84 +29,120 @@
extern "C" {
#endif
+
+/**
+ * The basic shading language types (float, vec4, mat3, etc)
+ */
typedef enum slang_type_specifier_type_
{
- slang_spec_void,
- slang_spec_bool,
- slang_spec_bvec2,
- slang_spec_bvec3,
- slang_spec_bvec4,
- slang_spec_int,
- slang_spec_ivec2,
- slang_spec_ivec3,
- slang_spec_ivec4,
- slang_spec_float,
- slang_spec_vec2,
- slang_spec_vec3,
- slang_spec_vec4,
- slang_spec_mat2,
- slang_spec_mat3,
- slang_spec_mat4,
- slang_spec_sampler1D,
- slang_spec_sampler2D,
- slang_spec_sampler3D,
- slang_spec_samplerCube,
- slang_spec_sampler1DShadow,
- slang_spec_sampler2DShadow,
- slang_spec_struct,
- slang_spec_array
+ slang_spec_void,
+ slang_spec_bool,
+ slang_spec_bvec2,
+ slang_spec_bvec3,
+ slang_spec_bvec4,
+ slang_spec_int,
+ slang_spec_ivec2,
+ slang_spec_ivec3,
+ slang_spec_ivec4,
+ slang_spec_float,
+ slang_spec_vec2,
+ slang_spec_vec3,
+ slang_spec_vec4,
+ slang_spec_mat2,
+ slang_spec_mat3,
+ slang_spec_mat4,
+ slang_spec_sampler1D,
+ slang_spec_sampler2D,
+ slang_spec_sampler3D,
+ slang_spec_samplerCube,
+ slang_spec_sampler1DShadow,
+ slang_spec_sampler2DShadow,
+ slang_spec_struct,
+ slang_spec_array
} slang_type_specifier_type;
+
+/**
+ * Describes more sophisticated types, like structs and arrays.
+ */
typedef struct slang_type_specifier_
{
- slang_type_specifier_type type;
- struct slang_struct_ *_struct; /* type: spec_struct */
- struct slang_type_specifier_ *_array; /* type: spec_array */
+ slang_type_specifier_type type;
+ struct slang_struct_ *_struct; /**< type: spec_struct */
+ struct slang_type_specifier_ *_array; /**< type: spec_array */
} slang_type_specifier;
-GLvoid slang_type_specifier_ctr (slang_type_specifier *);
-GLvoid slang_type_specifier_dtr (slang_type_specifier *);
-GLboolean slang_type_specifier_copy (slang_type_specifier *, const slang_type_specifier *);
-GLboolean slang_type_specifier_equal (const slang_type_specifier *, const slang_type_specifier *);
+
+extern GLvoid
+slang_type_specifier_ctr(slang_type_specifier *);
+
+extern GLvoid
+slang_type_specifier_dtr(slang_type_specifier *);
+
+extern GLboolean
+slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *);
+
+extern GLboolean
+slang_type_specifier_equal(const slang_type_specifier *,
+ const slang_type_specifier *);
+
typedef struct slang_assembly_typeinfo_
{
- GLboolean can_be_referenced;
- GLboolean is_swizzled;
- slang_swizzle swz;
- slang_type_specifier spec;
- GLuint array_len;
+ GLboolean can_be_referenced;
+ GLboolean is_swizzled;
+ slang_swizzle swz;
+ slang_type_specifier spec;
+ GLuint array_len;
} slang_assembly_typeinfo;
-GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
-GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
+extern GLboolean
+slang_assembly_typeinfo_construct(slang_assembly_typeinfo *);
-/*
+extern GLvoid
+slang_assembly_typeinfo_destruct(slang_assembly_typeinfo *);
+
+
+/**
* Retrieves type information about an operation.
* Returns GL_TRUE on success.
* Returns GL_FALSE otherwise.
*/
-GLboolean _slang_typeof_operation (slang_assemble_ctx *, struct slang_operation_ *,
- slang_assembly_typeinfo *);
-GLboolean _slang_typeof_operation_ (struct slang_operation_ *, slang_assembly_name_space *,
- slang_assembly_typeinfo *, slang_atom_pool *);
+extern GLboolean
+_slang_typeof_operation(const slang_assemble_ctx *,
+ const struct slang_operation_ *,
+ slang_assembly_typeinfo *);
-/*
+extern GLboolean
+_slang_typeof_operation_(const struct slang_operation_ *,
+ const slang_assembly_name_space *,
+ slang_assembly_typeinfo *, slang_atom_pool *);
+
+/**
* Retrieves type of a function prototype, if one exists.
* Returns GL_TRUE on success, even if the function was not found.
* Returns GL_FALSE otherwise.
*/
-GLboolean _slang_typeof_function (slang_atom a_name, struct slang_operation_ *params,
- GLuint num_params, slang_assembly_name_space *, slang_type_specifier *spec, GLboolean *exists,
- slang_atom_pool *);
+extern GLboolean
+_slang_typeof_function(slang_atom a_name,
+ const struct slang_operation_ *params,
+ GLuint num_params, const slang_assembly_name_space *,
+ slang_type_specifier *spec, GLboolean *exists,
+ slang_atom_pool *);
+
+extern GLboolean
+_slang_type_is_matrix(slang_type_specifier_type);
+
+extern GLboolean
+_slang_type_is_vector(slang_type_specifier_type);
-GLboolean _slang_type_is_matrix (slang_type_specifier_type);
+extern slang_type_specifier_type
+_slang_type_base(slang_type_specifier_type);
-GLboolean _slang_type_is_vector (slang_type_specifier_type);
+extern GLuint
+_slang_type_dim(slang_type_specifier_type);
-slang_type_specifier_type _slang_type_base (slang_type_specifier_type);
-GLuint _slang_type_dim (slang_type_specifier_type);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_utility.c b/src/mesa/shader/slang/slang_utility.c
index 54fcc8a238..28837248df 100644
--- a/src/mesa/shader/slang/slang_utility.c
+++ b/src/mesa/shader/slang/slang_utility.c
@@ -160,11 +160,16 @@ void slang_atom_pool_destruct (slang_atom_pool *pool)
}
}
-slang_atom slang_atom_pool_atom (slang_atom_pool *pool, const char *id)
+/**
+ * Search atom pool for atom with the given name.
+ * If name is not found, create new atom (but don't insert into pool?)
+ */
+slang_atom slang_atom_pool_atom (const slang_atom_pool *pool, const char *id)
{
GLuint hash;
const char *p = id;
- slang_atom_entry **entry;
+ slang_atom_entry * const * entry;
+ slang_atom_entry **newEntry = NULL;
hash = 0;
while (*p != '\0')
@@ -187,15 +192,15 @@ slang_atom slang_atom_pool_atom (slang_atom_pool *pool, const char *id)
entry = &(**entry).next;
}
- *entry = (slang_atom_entry *) slang_alloc_malloc (sizeof (slang_atom_entry));
- if (*entry == NULL)
+ *newEntry = (slang_atom_entry *) slang_alloc_malloc (sizeof (slang_atom_entry));
+ if (*newEntry == NULL)
return SLANG_ATOM_NULL;
- (**entry).next = NULL;
- (**entry).id = slang_string_duplicate (id);
- if ((**entry).id == NULL)
+ (**newEntry).next = NULL;
+ (**newEntry).id = slang_string_duplicate (id);
+ if ((**newEntry).id == NULL)
return SLANG_ATOM_NULL;
- return (slang_atom) (**entry).id;
+ return (slang_atom) (**newEntry).id;
}
const char *slang_atom_pool_id (slang_atom_pool *pool, slang_atom atom)
diff --git a/src/mesa/shader/slang/slang_utility.h b/src/mesa/shader/slang/slang_utility.h
index 565de4e4b0..3487e4ec51 100644
--- a/src/mesa/shader/slang/slang_utility.h
+++ b/src/mesa/shader/slang/slang_utility.h
@@ -99,7 +99,7 @@ typedef struct slang_atom_pool_
GLvoid slang_atom_pool_construct (slang_atom_pool *);
GLvoid slang_atom_pool_destruct (slang_atom_pool *);
-slang_atom slang_atom_pool_atom (slang_atom_pool *, const char *);
+slang_atom slang_atom_pool_atom (const slang_atom_pool *, const char *);
const char *slang_atom_pool_id (slang_atom_pool *, slang_atom);
#ifdef __cplusplus