glsl: Refactor handling of ast_array_index to a separate function