Don't track new type names during pass-1 parsing
[mesa.git] / ast_to_hir.cpp
index 5811d73586a8e294db70383e6faad3e1c6e77bfa..9f580d28cb0225a5eb50bd09df36a5fe2f95575d 100644 (file)
 #include "glsl_types.h"
 #include "ir.h"
 
+void
+_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
+{
+   struct simple_node *ptr;
+
+   _mesa_glsl_initialize_variables(instructions, state);
+
+   foreach (ptr, & state->translation_unit) {
+      ((ast_node *)ptr)->hir(instructions, state);
+   }
+}
+
+
 static const struct glsl_type *
 arithmetic_result_type(const struct glsl_type *type_a,
                       const struct glsl_type *type_b,
@@ -398,7 +411,7 @@ ast_expression::hir(exec_list *instructions,
    make_empty_list(& op_list);
 
    switch (this->oper) {
-   case ast_assign:
+   case ast_assign: {
       op[0] = this->subexpressions[0]->hir(instructions, state);
       op[1] = this->subexpressions[1]->hir(instructions, state);
 
@@ -437,8 +450,12 @@ ast_expression::hir(exec_list *instructions,
       /* FINISHME: Check that the LHS and RHS have matching types. */
       /* FINISHME: For GLSL 1.10, check that the types are not arrays. */
 
-      result = new ir_assignment(op[0], op[1], NULL);
+      ir_instruction *tmp = new ir_assignment(op[0], op[1], NULL);
+      instructions->push_tail(tmp);
+
+      result = op[0];
       break;
+   }
 
    case ast_plus:
       op[0] = this->subexpressions[0]->hir(instructions, state);
@@ -613,21 +630,10 @@ ast_expression::hir(exec_list *instructions,
       break;
 
    case ast_function_call:
-      /* There are three sorts of function calls.
-       *
-       * 1. contstructors - The first subexpression is an ast_type_specifier.
-       * 2. methods - Only the .length() method of array types.
-       * 3. functions - Calls to regular old functions.
-       *
-       * Method calls are actually detected when the ast_field_selection
-       * expression is handled.
+      /* Should *NEVER* get here.  ast_function_call should always be handled
+       * by ast_function_expression::hir.
        */
-#if 0
-      result = _mesa_ast_function_call_to_hir(this->subexpressions[0],
-                                             this->subexpressions[1],
-                                             state);
-      type = result->type;
-#endif
+      assert(0);
       break;
 
    case ast_identifier: {
@@ -753,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.
@@ -851,7 +799,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
    else if (qual->attribute || qual->in
            || (qual->varying && (state->target == fragment_shader)))
       var->mode = ir_var_in;
-   else if (qual->out)
+   else if (qual->out || (qual->varying && (state->target == vertex_shader)))
       var->mode = ir_var_out;
    else if (qual->uniform)
       var->mode = ir_var_uniform;
@@ -983,7 +931,12 @@ ast_parameter_declarator::hir(exec_list *instructions,
     * FINISHME: complete handling of constant expressions.
     */
 
+   /* Apply any specified qualifiers to the parameter declaration.  Note that
+    * for function parameters the default mode is 'in'.
+    */
    apply_type_qualifier_to_variable(& this->type->qualifier, var, state);
+   if (var->mode == ir_var_auto)
+      var->mode = ir_var_in;
 
    instructions->push_tail(var);
 
@@ -1131,7 +1084,7 @@ ast_function_definition::hir(exec_list *instructions,
    foreach_iter(exec_list_iterator, iter, parameters) {
       ir_variable *const var = (ir_variable *) iter.get();
 
-      assert(var->mode == ir_op_var_decl);
+      assert(((ir_instruction *)var)->mode == ir_op_var_decl);
 
       iter.remove();
       instructions->push_tail(var);