From 7f9d30974317a4050fb8990ce1a3eebbb190483a Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 15 Mar 2010 14:15:15 -0700 Subject: [PATCH] Ensure that ast_type always has type_name set For built-in types, type_name would be NULL. This ensures that type_name is set even for the built-in types. This simplifies code in a few places and centralizes the name setting code. --- ast.h | 2 +- ast_to_hir.cpp | 62 +------------------------------ ast_type.cpp | 114 +++++++++++++++++++++++++++++---------------------------- 3 files changed, 62 insertions(+), 116 deletions(-) diff --git a/ast.h b/ast.h index d823257..32cd5b6 100644 --- a/ast.h +++ b/ast.h @@ -361,7 +361,7 @@ public: enum ast_types type_specifier; - char *type_name; + const char *type_name; ast_struct_specifier *structure; int is_array; diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 1de6479..9f580d2 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -759,73 +759,15 @@ type_specifier_to_glsl_type(const struct ast_type_specifier *spec, const char **name, struct _mesa_glsl_parse_state *state) { - static const char *const type_names[] = { - "void", - "float", - "int", - "uint", - "bool", - "vec2", - "vec3", - "vec4", - "bvec2", - "bvec3", - "bvec4", - "ivec2", - "ivec3", - "ivec4", - "uvec2", - "uvec3", - "uvec4", - "mat2", - "mat2x3", - "mat2x4", - "mat3x2", - "mat3", - "mat3x4", - "mat4x2", - "mat4x3", - "mat4", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCube", - "sampler1DShadow", - "sampler2DShadow", - "samplerCubeShadow", - "sampler1DArray", - "sampler2DArray", - "sampler1DArrayShadow", - "sampler2DArrayShadow", - "isampler1D", - "isampler2D", - "isampler3D", - "isamplerCube", - "isampler1DArray", - "isampler2DArray", - "usampler1D", - "usampler2D", - "usampler3D", - "usamplerCube", - "usampler1DArray", - "usampler2DArray", - - NULL, /* ast_struct */ - NULL /* ast_type_name */ - }; struct glsl_type *type; - const char *type_name = NULL; if (spec->type_specifier == ast_struct) { /* FINISHME: Handle annonymous structures. */ type = NULL; } else { - type_name = (spec->type_specifier == ast_type_name) - ? spec->type_name : type_names[spec->type_specifier]; - type = (glsl_type *) - _mesa_symbol_table_find_symbol(state->symbols, 0, type_name); - *name = type_name; + _mesa_symbol_table_find_symbol(state->symbols, 0, spec->type_name); + *name = spec->type_name; /* FINISHME: Handle array declarations. Note that this requires complete * FINSIHME: handling of constant expressions. diff --git a/ast_type.cpp b/ast_type.cpp index d2e047e..25f28b1 100644 --- a/ast_type.cpp +++ b/ast_type.cpp @@ -28,62 +28,10 @@ void ast_type_specifier::print(void) const { - switch (type_specifier) { - case ast_void: printf("void "); break; - case ast_float: printf("float "); break; - case ast_int: printf("int "); break; - case ast_uint: printf("uint "); break; - case ast_bool: printf("bool "); break; - case ast_vec2: printf("vec2 "); break; - case ast_vec3: printf("vec3 "); break; - case ast_vec4: printf("vec4 "); break; - case ast_bvec2: printf("bvec2 "); break; - case ast_bvec3: printf("bvec3 "); break; - case ast_bvec4: printf("bvec4 "); break; - case ast_ivec2: printf("ivec2 "); break; - case ast_ivec3: printf("ivec3 "); break; - case ast_ivec4: printf("ivec4 "); break; - case ast_uvec2: printf("uvec2 "); break; - case ast_uvec3: printf("uvec3 "); break; - case ast_uvec4: printf("uvec4 "); break; - case ast_mat2: printf("mat2 "); break; - case ast_mat2x3: printf("mat2x3 "); break; - case ast_mat2x4: printf("mat2x4 "); break; - case ast_mat3x2: printf("mat3x2 "); break; - case ast_mat3: printf("mat3 "); break; - case ast_mat3x4: printf("mat3x4 "); break; - case ast_mat4x2: printf("mat4x2 "); break; - case ast_mat4x3: printf("mat4x3 "); break; - case ast_mat4: printf("mat4 "); break; - case ast_sampler1d: printf("sampler1d "); break; - case ast_sampler2d: printf("sampler2d "); break; - case ast_sampler3d: printf("sampler3d "); break; - case ast_samplercube: printf("samplercube "); break; - case ast_sampler1dshadow: printf("sampler1dshadow "); break; - case ast_sampler2dshadow: printf("sampler2dshadow "); break; - case ast_samplercubeshadow: printf("samplercubeshadow "); break; - case ast_sampler1darray: printf("sampler1darray "); break; - case ast_sampler2darray: printf("sampler2darray "); break; - case ast_sampler1darrayshadow: printf("sampler1darrayshadow "); break; - case ast_sampler2darrayshadow: printf("sampler2darrayshadow "); break; - case ast_isampler1d: printf("isampler1d "); break; - case ast_isampler2d: printf("isampler2d "); break; - case ast_isampler3d: printf("isampler3d "); break; - case ast_isamplercube: printf("isamplercube "); break; - case ast_isampler1darray: printf("isampler1darray "); break; - case ast_isampler2darray: printf("isampler2darray "); break; - case ast_usampler1d: printf("usampler1d "); break; - case ast_usampler2d: printf("usampler2d "); break; - case ast_usampler3d: printf("usampler3d "); break; - case ast_usamplercube: printf("usamplercube "); break; - case ast_usampler1darray: printf("usampler1darray "); break; - case ast_usampler2darray: printf("usampler2darray "); break; - - case ast_struct: + if (type_specifier == ast_struct) { structure->print(); - break; - - case ast_type_name: printf("%s ", type_name); break; + } else { + printf("%s ", type_name); } if (is_array) { @@ -99,5 +47,61 @@ ast_type_specifier::print(void) const ast_type_specifier::ast_type_specifier(int specifier) { + static const char *const names[] = { + "void", + "float", + "int", + "uint", + "bool", + "vec2", + "vec3", + "vec4", + "bvec2", + "bvec3", + "bvec4", + "ivec2", + "ivec3", + "ivec4", + "uvec2", + "uvec3", + "uvec4", + "mat2", + "mat2x3", + "mat2x4", + "mat3x2", + "mat3", + "mat3x4", + "mat4x2", + "mat4x3", + "mat4", + "sampler1D", + "sampler2D", + "sampler3D", + "samplerCube", + "sampler1DShadow", + "sampler2DShadow", + "samplerCubeShadow", + "sampler1DArray", + "sampler2DArray", + "sampler1DArrayShadow", + "sampler2DArrayShadow", + "isampler1D", + "isampler2D", + "isampler3D", + "isamplerCube", + "isampler1DArray", + "isampler2DArray", + "usampler1D", + "usampler2D", + "usampler3D", + "usamplerCube", + "usampler1DArray", + "usampler2DArray", + + NULL, /* ast_struct */ + NULL /* ast_type_name */ + }; + type_specifier = ast_types(specifier); + type_name = names[specifier]; } -- 2.7.4