Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / glsl / hir_field_selection.cpp
index 6dd910d5816cff89412de7206cadd4d0590c4b97..337095b95b84bd757b461ed207d6413795f2ded9 100644 (file)
  */
 
 #include "ir.h"
-#include "main/imports.h"
-#include "program/symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "ast.h"
 #include "glsl_types.h"
 
-struct ir_rvalue *
+ir_rvalue *
 _mesa_ast_field_selection_to_hir(const ast_expression *expr,
                                 exec_list *instructions,
                                 struct _mesa_glsl_parse_state *state)
@@ -48,7 +46,19 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
    YYLTYPE loc = expr->get_location();
    if (op->type->is_error()) {
       /* silently propagate the error */
-   } else if (op->type->is_vector()) {
+   } else if (op->type->base_type == GLSL_TYPE_STRUCT
+              || op->type->base_type == GLSL_TYPE_INTERFACE) {
+      result = new(ctx) ir_dereference_record(op,
+                                             expr->primary_expression.identifier);
+
+      if (result->type->is_error()) {
+        _mesa_glsl_error(& loc, state, "cannot access field `%s' of "
+                         "structure",
+                         expr->primary_expression.identifier);
+      }
+   } else if (op->type->is_vector() ||
+              (state->ARB_shading_language_420pack_enable &&
+               op->type->is_scalar())) {
       ir_swizzle *swiz = ir_swizzle::create(op,
                                            expr->primary_expression.identifier,
                                            op->type->vector_elements);
@@ -59,45 +69,14 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
          * FINISHME: ir_swizzle::create.  This allows the generation of more
          * FINISHME: specific error messages.
          */
-        _mesa_glsl_error(& loc, state, "Invalid swizzle / mask `%s'",
+        _mesa_glsl_error(& loc, state, "invalid swizzle / mask `%s'",
                          expr->primary_expression.identifier);
       }
-   } else if (op->type->base_type == GLSL_TYPE_STRUCT) {
-      result = new(ctx) ir_dereference_record(op,
-                                             expr->primary_expression.identifier);
-
-      if (result->type->is_error()) {
-        _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
-                         "structure",
-                         expr->primary_expression.identifier);
-      }
-   } else if (expr->subexpressions[1] != NULL) {
-      /* Handle "method calls" in GLSL 1.20 - namely, array.length() */
-      if (state->language_version < 120)
-        _mesa_glsl_error(&loc, state, "Methods not supported in GLSL 1.10.");
-
-      ast_expression *call = expr->subexpressions[1];
-      assert(call->oper == ast_function_call);
-
-      const char *method;
-      method = call->subexpressions[0]->primary_expression.identifier;
-
-      if (op->type->is_array() && strcmp(method, "length") == 0) {
-        if (!call->expressions.is_empty())
-           _mesa_glsl_error(&loc, state, "length method takes no arguments.");
-
-        if (op->type->array_size() == 0)
-           _mesa_glsl_error(&loc, state, "length called on unsized array.");
-
-        result = new(ctx) ir_constant(op->type->array_size());
-      } else {
-        _mesa_glsl_error(&loc, state, "Unknown method: `%s'.", method);
-      }
    } else {
-      _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
-                      "non-structure / non-vector.",
+      _mesa_glsl_error(& loc, state, "cannot access field `%s' of "
+                      "non-structure / non-vector",
                       expr->primary_expression.identifier);
    }
 
-   return result ? result : ir_call::get_error_instruction(ctx);
+   return result ? result : ir_rvalue::error_value(ctx);
 }