X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglsl%2Fhir_field_selection.cpp;h=260b415a800af318f5a7e1a8fa04ae657eda376b;hb=6a829a1b724ca0d960decee217d260b4de8a5463;hp=5500e09d7e61b77da21c41d2e61944552837baed;hpb=953ff1283d3d52e6a6b4850c2b0b574111625010;p=mesa.git diff --git a/src/glsl/hir_field_selection.cpp b/src/glsl/hir_field_selection.cpp index 5500e09d7e6..260b415a800 100644 --- a/src/glsl/hir_field_selection.cpp +++ b/src/glsl/hir_field_selection.cpp @@ -22,13 +22,12 @@ */ #include "ir.h" -#include "main/imports.h" -#include "symbol_table.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) @@ -71,11 +70,33 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr, "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.", expr->primary_expression.identifier); } - return result ? result : ir_call::get_error_instruction(ctx); + return result ? result : ir_rvalue::error_value(ctx); }