Rename overloads of _mesa_glsl_shader_target_name().
authorPaul Berry <stereotype441@gmail.com>
Tue, 17 Dec 2013 20:13:11 +0000 (12:13 -0800)
committerPaul Berry <stereotype441@gmail.com>
Mon, 30 Dec 2013 19:21:08 +0000 (11:21 -0800)
Previously, _mesa_glsl_shader_target_name() had an overload for GLenum
and an overload for the gl_shader_type enum, each of which behaved
differently.  However, since GLenum is a synonym for unsigned int, and
unsigned ints are often used in place of gl_shader_type (e.g. in loop
indices), there was a big risk of calling the wrong overload by
mistake.  This patch gives the two overloads different names so that
it's always clear which one we mean to call.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/glsl/ast_to_hir.cpp
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/glsl/link_varyings.cpp
src/glsl/linker.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/main/shaderapi.c
src/mesa/main/uniform_query.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 3bc181e8785acb1a73cf154a7ae100309ed1453a..91810f985bfce63575c758c8bc6c5d3e62456d6a 100644 (file)
@@ -2110,7 +2110,7 @@ validate_explicit_location(const struct ast_type_qualifier *qual,
       _mesa_glsl_error(loc, state,
                        "%s cannot be given an explicit location in %s shader",
                        mode_string(var),
-                      _mesa_glsl_shader_target_name(state->target));
+                      _mesa_shader_type_to_string(state->target));
    } else {
       var->data.explicit_location = true;
 
@@ -2188,7 +2188,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
       _mesa_glsl_error(loc, state,
                       "`attribute' variables may not be declared in the "
                       "%s shader",
-                      _mesa_glsl_shader_target_name(state->target));
+                      _mesa_shader_type_to_string(state->target));
    }
 
    /* Section 6.1.1 (Function Calling Conventions) of the GLSL 1.10 spec says:
@@ -2599,7 +2599,7 @@ process_initializer(ir_variable *var, ast_declaration *decl,
    if ((var->data.mode == ir_var_shader_in) && (state->current_function == NULL)) {
       _mesa_glsl_error(& initializer_loc, state,
                       "cannot initialize %s shader input / %s",
-                      _mesa_glsl_shader_target_name(state->target),
+                      _mesa_shader_type_to_string(state->target),
                       (state->target == MESA_SHADER_VERTEX)
                       ? "attribute" : "varying");
    }
@@ -4890,7 +4890,7 @@ ast_interface_block::hir(exec_list *instructions,
             _mesa_glsl_error(&loc, state,
                              "redeclaration of gl_PerVertex input not allowed "
                              "in the %s shader",
-                             _mesa_glsl_shader_target_name(state->target));
+                             _mesa_shader_type_to_string(state->target));
          }
          if (this->instance_name == NULL ||
              strcmp(this->instance_name, "gl_in") != 0 || !this->is_array) {
@@ -4907,7 +4907,7 @@ ast_interface_block::hir(exec_list *instructions,
             _mesa_glsl_error(&loc, state,
                              "redeclaration of gl_PerVertex output not "
                              "allowed in the %s shader",
-                             _mesa_glsl_shader_target_name(state->target));
+                             _mesa_shader_type_to_string(state->target));
          }
          if (this->instance_name != NULL) {
             _mesa_glsl_error(&loc, state,
index 5f19368d8562c75fb6555687089ef5d5e52c9c07..fc9a8b204119695c762fa42aab3ab6ac7fc5d2c2 100644 (file)
@@ -334,16 +334,15 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version,
 extern "C" {
 
 /**
- * The most common use of _mesa_glsl_shader_target_name(), which is
- * shared with C code in Mesa core to translate a GLenum to a short
- * shader stage name in debug printouts.
+ * Translate a GLenum to a short shader stage name for debug printouts and
+ * error messages.
  *
  * It recognizes the PROGRAM variants of the names so it can be used
  * with a struct gl_program->Target, not just a struct
  * gl_shader->Type.
  */
 const char *
-_mesa_glsl_shader_target_name(GLenum type)
+_mesa_shader_enum_to_string(GLenum type)
 {
    switch (type) {
    case GL_VERTEX_SHADER:
@@ -363,11 +362,11 @@ _mesa_glsl_shader_target_name(GLenum type)
 } /* extern "C" */
 
 /**
- * Overloaded C++ variant usable within the compiler for translating
- * our internal enum into short stage names.
+ * Translate a gl_shader_type to a short shader stage name for debug printouts
+ * and error messages.
  */
 const char *
-_mesa_glsl_shader_target_name(gl_shader_type target)
+_mesa_shader_type_to_string(unsigned target)
 {
    switch (target) {
    case MESA_SHADER_VERTEX:   return "vertex";
@@ -651,11 +650,11 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
 
          if (behavior == extension_require) {
             _mesa_glsl_error(name_locp, state, fmt,
-                             name, _mesa_glsl_shader_target_name(state->target));
+                             name, _mesa_shader_type_to_string(state->target));
             return false;
          } else {
             _mesa_glsl_warning(name_locp, state, fmt,
-                               name, _mesa_glsl_shader_target_name(state->target));
+                               name, _mesa_shader_type_to_string(state->target));
          }
       }
    }
index 622ddbac7268a4d921db6420bbac6df7417ffe2a..7b013fa6dee9c5a8656320f2370cfe2123a61ef4 100644 (file)
@@ -422,10 +422,11 @@ extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
                                         _mesa_glsl_parse_state *state);
 
 /**
- * Get the textual name of the specified shader target
+ * Get the textual name of the specified shader target (which is a
+ * gl_shader_type).
  */
 extern const char *
-_mesa_glsl_shader_target_name(gl_shader_type target);
+_mesa_shader_type_to_string(unsigned target);
 
 
 #endif /* __cplusplus */
@@ -439,7 +440,7 @@ extern "C" {
 #endif
 
 extern const char *
-_mesa_glsl_shader_target_name(GLenum type);
+_mesa_shader_enum_to_string(GLenum type);
 
 extern int glcpp_preprocess(void *ctx, const char **shader, char **info_log,
                       const struct gl_extensions *extensions, struct gl_context *gl_ctx);
index 229a4cb8584ceff0b657d1302169f0913f623878..98f902ca4efbdecf25df46238f9953826c2cccec 100644 (file)
@@ -82,10 +82,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
          linker_error(prog,
                       "%s shader output `%s' declared as type `%s', "
                       "but %s shader input declared as type `%s'\n",
-                      _mesa_glsl_shader_target_name(producer_type),
+                      _mesa_shader_enum_to_string(producer_type),
                       output->name,
                       output->type->name,
-                      _mesa_glsl_shader_target_name(consumer_type),
+                      _mesa_shader_enum_to_string(consumer_type),
                       input->type->name);
          return;
       }
@@ -97,10 +97,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
       linker_error(prog,
                    "%s shader output `%s' %s centroid qualifier, "
                    "but %s shader input %s centroid qualifier\n",
-                   _mesa_glsl_shader_target_name(producer_type),
+                   _mesa_shader_enum_to_string(producer_type),
                    output->name,
                    (output->data.centroid) ? "has" : "lacks",
-                   _mesa_glsl_shader_target_name(consumer_type),
+                   _mesa_shader_enum_to_string(consumer_type),
                    (input->data.centroid) ? "has" : "lacks");
       return;
    }
@@ -109,10 +109,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
       linker_error(prog,
                    "%s shader output `%s' %s sample qualifier, "
                    "but %s shader input %s sample qualifier\n",
-                   _mesa_glsl_shader_target_name(producer_type),
+                   _mesa_shader_enum_to_string(producer_type),
                    output->name,
                    (output->data.sample) ? "has" : "lacks",
-                   _mesa_glsl_shader_target_name(consumer_type),
+                   _mesa_shader_enum_to_string(consumer_type),
                    (input->data.sample) ? "has" : "lacks");
       return;
    }
@@ -121,10 +121,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
       linker_error(prog,
                    "%s shader output `%s' %s invariant qualifier, "
                    "but %s shader input %s invariant qualifier\n",
-                   _mesa_glsl_shader_target_name(producer_type),
+                   _mesa_shader_enum_to_string(producer_type),
                    output->name,
                    (output->data.invariant) ? "has" : "lacks",
-                   _mesa_glsl_shader_target_name(consumer_type),
+                   _mesa_shader_enum_to_string(consumer_type),
                    (input->data.invariant) ? "has" : "lacks");
       return;
    }
@@ -135,10 +135,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
                    "interpolation qualifier, "
                    "but %s shader input specifies %s "
                    "interpolation qualifier\n",
-                   _mesa_glsl_shader_target_name(producer_type),
+                   _mesa_shader_enum_to_string(producer_type),
                    output->name,
                    interpolation_string(output->data.interpolation),
-                   _mesa_glsl_shader_target_name(consumer_type),
+                   _mesa_shader_enum_to_string(consumer_type),
                    interpolation_string(input->data.interpolation));
       return;
    }
@@ -1217,9 +1217,9 @@ assign_varying_locations(struct gl_context *ctx,
 
                linker_error(prog, "%s shader varying %s not written "
                             "by %s shader\n.",
-                            _mesa_glsl_shader_target_name(consumer->Type),
+                            _mesa_shader_enum_to_string(consumer->Type),
                            var->name,
-                            _mesa_glsl_shader_target_name(producer->Type));
+                            _mesa_shader_enum_to_string(producer->Type));
             }
 
             /* An 'in' variable is only really a shader input if its
index a6133ea9cb50d184c2f2bd6a7d8abd072a4759ab..f6d7a9095503a5eea4aa683e9585dab6cebb8fd2 100644 (file)
@@ -1375,7 +1375,7 @@ link_intrastage_shaders(void *mem_ctx,
 
    if (main == NULL) {
       linker_error(prog, "%s shader lacks `main'\n",
-                  _mesa_glsl_shader_target_name(shader_list[0]->Type));
+                  _mesa_shader_enum_to_string(shader_list[0]->Type));
       return NULL;
    }
 
index 6f0ace8932cc580fd353a3e41f77b53e1fb8d353..3f59c804ca560e4176775536683ad77da3e49224 100644 (file)
@@ -261,7 +261,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
       if (ctx->Shader.Flags & GLSL_DUMP) {
          printf("\n");
          printf("GLSL IR for linked %s program %d:\n",
-                _mesa_glsl_shader_target_name(shader->base.Type), shProg->Name);
+                _mesa_shader_enum_to_string(shader->base.Type), shProg->Name);
          _mesa_print_ir(shader->base.ir, NULL);
          printf("\n");
       }
@@ -274,7 +274,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
             continue;
 
          printf("GLSL %s shader %d source for linked program %d:\n",
-                _mesa_glsl_shader_target_name(sh->Type),
+                _mesa_shader_enum_to_string(sh->Type),
                 i,
                 shProg->Name);
          printf("%s", sh->Source);
index 4f3be68a406d5e3e59d7d91774f5a5e69ee76c77..57511e83e439f9b58421539f777a4a9054a297c9 100644 (file)
@@ -791,7 +791,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj)
    } else {
       if (ctx->Shader.Flags & GLSL_DUMP) {
          printf("GLSL source for %s shader %d:\n",
-                _mesa_glsl_shader_target_name(sh->Type), sh->Name);
+                _mesa_shader_enum_to_string(sh->Type), sh->Name);
          printf("%s\n", sh->Source);
       }
 
@@ -823,7 +823,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj)
    if (!sh->CompileStatus) {
       if (ctx->Shader.Flags & GLSL_DUMP_ON_ERROR) {
          fprintf(stderr, "GLSL source for %s shader %d:\n",
-                 _mesa_glsl_shader_target_name(sh->Type), sh->Name);
+                 _mesa_shader_enum_to_string(sh->Type), sh->Name);
          fprintf(stderr, "%s\n", sh->Source);
          fprintf(stderr, "Info Log:\n%s\n", sh->InfoLog);
          fflush(stderr);
@@ -898,7 +898,7 @@ print_shader_info(const struct gl_shader_program *shProg)
    printf("Mesa: glUseProgram(%u)\n", shProg->Name);
    for (i = 0; i < shProg->NumShaders; i++) {
       printf("  %s shader %u, checksum %u\n",
-             _mesa_glsl_shader_target_name(shProg->Shaders[i]->Type),
+             _mesa_shader_enum_to_string(shProg->Shaders[i]->Type),
             shProg->Shaders[i]->Name,
             shProg->Shaders[i]->SourceChecksum);
    }
index 88ad476acb94f9e163f98848f4de3e864c344006..61bcbcb8afdb8c5a48529afa5d2015904f8f299a 100644 (file)
@@ -452,7 +452,7 @@ log_program_parameters(const struct gl_shader_program *shProg)
       const struct gl_program *const prog = shProg->_LinkedShaders[i]->Program;
 
       printf("Program %d %s shader parameters:\n",
-             shProg->Name, _mesa_glsl_shader_target_name(prog->Target));
+             shProg->Name, _mesa_shader_enum_to_string(prog->Target));
       for (unsigned j = 0; j < prog->Parameters->NumParameters; j++) {
         printf("%s: %p %f %f %f %f\n",
                prog->Parameters->Parameters[j].Name,
index 23d479c32d6f6b487f3c34eee55a24319478b0aa..beb0c093b5e87e406b746354e0a26e43fadf7ce2 100644 (file)
@@ -2801,7 +2801,7 @@ get_mesa_program(struct gl_context *ctx,
    int i;
    struct gl_program *prog;
    GLenum target;
-   const char *target_string = _mesa_glsl_shader_target_name(shader->Type);
+   const char *target_string = _mesa_shader_enum_to_string(shader->Type);
    struct gl_shader_compiler_options *options =
          &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];
 
index 1331c73dc307c007d159a0e71616fc35866940d5..eb12426a544835e94aa0094296401a0703987d16 100644 (file)
@@ -5143,7 +5143,7 @@ get_mesa_program(struct gl_context *ctx,
    if (ctx->Shader.Flags & GLSL_DUMP) {
       printf("\n");
       printf("GLSL IR for linked %s program %d:\n",
-             _mesa_glsl_shader_target_name(shader->Type),
+             _mesa_shader_enum_to_string(shader->Type),
              shader_program->Name);
       _mesa_print_ir(shader->ir, NULL);
       printf("\n");