summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-04-04 13:58:05 -0700
committerJason Ekstrand <[email protected]>2016-04-04 13:58:05 -0700
commit6a049687841d87fc5bbd0fb0a192f03776f67630 (patch)
treeddb5d24f705b0451b948906df697082b9f47d0a3 /src/compiler
parentfe247bbe922ab862914bc76c10557157a06700ac (diff)
parent88ef2476dcdd61000cbae7ded9c8fa52927429d8 (diff)
Merge remote-tracking branch 'public/master' into vulkan
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/glsl/ast_to_hir.cpp4
-rw-r--r--src/compiler/glsl/builtin_functions.cpp2
-rw-r--r--src/compiler/glsl/builtin_types.cpp12
-rw-r--r--src/compiler/glsl/builtin_variables.cpp16
-rw-r--r--src/compiler/glsl/glcpp/glcpp-parse.y2775
-rw-r--r--src/compiler/glsl/glsl_parser_extras.cpp3
-rw-r--r--src/compiler/glsl/glsl_parser_extras.h2
-rw-r--r--src/compiler/glsl/ir_print_visitor.cpp5
-rw-r--r--src/compiler/glsl/link_uniform_initializers.cpp32
-rw-r--r--src/compiler/glsl/link_uniforms.cpp49
-rw-r--r--src/compiler/glsl/link_varyings.cpp11
-rw-r--r--src/compiler/glsl/linker.cpp283
-rw-r--r--src/compiler/glsl/lower_ubo_reference.cpp3
-rw-r--r--src/compiler/glsl/lower_vertex_id.cpp2
-rw-r--r--src/compiler/glsl/standalone_scaffolding.cpp7
15 files changed, 1572 insertions, 1634 deletions
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 3fe90079420..7c9be8171b6 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -3326,6 +3326,7 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
+ qual->flags.q.depth_less
+ qual->flags.q.depth_unchanged;
if (depth_layout_count > 0
+ && !state->is_version(420, 0)
&& !state->AMD_conservative_depth_enable
&& !state->ARB_conservative_depth_enable) {
_mesa_glsl_error(loc, state,
@@ -3708,7 +3709,8 @@ get_variable_being_redeclared(ir_variable *var, YYLTYPE loc,
earlier->data.interpolation = var->data.interpolation;
/* Layout qualifiers for gl_FragDepth. */
- } else if ((state->AMD_conservative_depth_enable ||
+ } else if ((state->is_version(420, 0) ||
+ state->AMD_conservative_depth_enable ||
state->ARB_conservative_depth_enable)
&& strcmp(var->name, "gl_FragDepth") == 0
&& earlier->type == var->type
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 65309fdc09c..1f6fb22924b 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -210,6 +210,7 @@ static bool
shader_integer_mix(const _mesa_glsl_parse_state *state)
{
return state->is_version(450, 310) ||
+ state->ARB_ES3_1_compatibility_enable ||
(v130(state) && state->EXT_shader_integer_mix_enable);
}
@@ -478,6 +479,7 @@ static bool
shader_image_atomic_exchange_float(const _mesa_glsl_parse_state *state)
{
return (state->is_version(450, 320) ||
+ state->ARB_ES3_1_compatibility_enable ||
state->OES_shader_image_atomic_enable);
}
diff --git a/src/compiler/glsl/builtin_types.cpp b/src/compiler/glsl/builtin_types.cpp
index d250234f652..5f208f8e9d6 100644
--- a/src/compiler/glsl/builtin_types.cpp
+++ b/src/compiler/glsl/builtin_types.cpp
@@ -181,7 +181,7 @@ static const struct builtin_type_versions {
T(sampler2DRect, 140, 999)
T(samplerBuffer, 140, 320)
T(sampler2DMS, 150, 310)
- T(sampler2DMSArray, 150, 999)
+ T(sampler2DMSArray, 150, 320)
T(isampler1D, 130, 999)
T(isampler2D, 130, 300)
@@ -193,7 +193,7 @@ static const struct builtin_type_versions {
T(isampler2DRect, 140, 999)
T(isamplerBuffer, 140, 320)
T(isampler2DMS, 150, 310)
- T(isampler2DMSArray, 150, 999)
+ T(isampler2DMSArray, 150, 320)
T(usampler1D, 130, 999)
T(usampler2D, 130, 300)
@@ -205,7 +205,7 @@ static const struct builtin_type_versions {
T(usampler2DRect, 140, 999)
T(usamplerBuffer, 140, 320)
T(usampler2DMS, 150, 310)
- T(usampler2DMSArray, 150, 999)
+ T(usampler2DMSArray, 150, 320)
T(sampler1DShadow, 110, 999)
T(sampler2DShadow, 110, 300)
@@ -305,11 +305,13 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
add_type(symbols, glsl_type::usamplerCubeArray_type);
}
- if (state->ARB_texture_multisample_enable ||
- state->OES_texture_storage_multisample_2d_array_enable) {
+ if (state->ARB_texture_multisample_enable) {
add_type(symbols, glsl_type::sampler2DMS_type);
add_type(symbols, glsl_type::isampler2DMS_type);
add_type(symbols, glsl_type::usampler2DMS_type);
+ }
+ if (state->ARB_texture_multisample_enable ||
+ state->OES_texture_storage_multisample_2d_array_enable) {
add_type(symbols, glsl_type::sampler2DMSArray_type);
add_type(symbols, glsl_type::isampler2DMSArray_type);
add_type(symbols, glsl_type::usampler2DMSArray_type);
diff --git a/src/compiler/glsl/builtin_variables.cpp b/src/compiler/glsl/builtin_variables.cpp
index 7d77f705356..f31f9f61ef6 100644
--- a/src/compiler/glsl/builtin_variables.cpp
+++ b/src/compiler/glsl/builtin_variables.cpp
@@ -845,11 +845,6 @@ builtin_variable_generator::generate_constants()
state->Const.MaxImageSamples);
}
- if (state->is_version(450, 310)) {
- add_const("gl_MaxCombinedShaderOutputResources",
- state->Const.MaxCombinedShaderOutputResources);
- }
-
if (state->is_version(400, 0) ||
state->ARB_tessellation_shader_enable) {
add_const("gl_MaxTessControlImageUniforms",
@@ -859,6 +854,12 @@ builtin_variable_generator::generate_constants()
}
}
+ if (state->is_version(450, 310) ||
+ state->ARB_ES3_1_compatibility_enable) {
+ add_const("gl_MaxCombinedShaderOutputResources",
+ state->Const.MaxCombinedShaderOutputResources);
+ }
+
if (state->is_version(410, 0) ||
state->ARB_viewport_array_enable)
add_const("gl_MaxViewports", state->Const.MaxViewports);
@@ -880,7 +881,8 @@ builtin_variable_generator::generate_constants()
}
if (state->is_version(450, 320) ||
- state->OES_sample_variables_enable)
+ state->OES_sample_variables_enable ||
+ state->ARB_ES3_1_compatibility_enable)
add_const("gl_MaxSamples", state->Const.MaxSamples);
}
@@ -1174,7 +1176,7 @@ builtin_variable_generator::generate_fs_special_vars()
var->data.interpolation = INTERP_QUALIFIER_FLAT;
}
- if (state->is_version(450, 310)/* || state->ARB_ES3_1_compatibility_enable*/)
+ if (state->is_version(450, 310) || state->ARB_ES3_1_compatibility_enable)
add_system_value(SYSTEM_VALUE_HELPER_INVOCATION, bool_t, "gl_HelperInvocation");
}
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index e8646c0ad32..a48266cf1b2 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -33,125 +33,121 @@
#include "main/mtypes.h" /* for gl_api enum */
static void
-yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
+yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
static void
-_define_object_macro (glcpp_parser_t *parser,
- YYLTYPE *loc,
- const char *macro,
- token_list_t *replacements);
+_define_object_macro(glcpp_parser_t *parser,
+ YYLTYPE *loc,
+ const char *macro,
+ token_list_t *replacements);
static void
-_define_function_macro (glcpp_parser_t *parser,
- YYLTYPE *loc,
- const char *macro,
- string_list_t *parameters,
- token_list_t *replacements);
+_define_function_macro(glcpp_parser_t *parser,
+ YYLTYPE *loc,
+ const char *macro,
+ string_list_t *parameters,
+ token_list_t *replacements);
static string_list_t *
-_string_list_create (void *ctx);
+_string_list_create(void *ctx);
static void
-_string_list_append_item (string_list_t *list, const char *str);
+_string_list_append_item(string_list_t *list, const char *str);
static int
-_string_list_contains (string_list_t *list, const char *member, int *index);
+_string_list_contains(string_list_t *list, const char *member, int *index);
static const char *
-_string_list_has_duplicate (string_list_t *list);
+_string_list_has_duplicate(string_list_t *list);
static int
-_string_list_length (string_list_t *list);
+_string_list_length(string_list_t *list);
static int
-_string_list_equal (string_list_t *a, string_list_t *b);
+_string_list_equal(string_list_t *a, string_list_t *b);
static argument_list_t *
-_argument_list_create (void *ctx);
+_argument_list_create(void *ctx);
static void
-_argument_list_append (argument_list_t *list, token_list_t *argument);
+_argument_list_append(argument_list_t *list, token_list_t *argument);
static int
-_argument_list_length (argument_list_t *list);
+_argument_list_length(argument_list_t *list);
static token_list_t *
-_argument_list_member_at (argument_list_t *list, int index);
+_argument_list_member_at(argument_list_t *list, int index);
/* Note: This function ralloc_steal()s the str pointer. */
static token_t *
-_token_create_str (void *ctx, int type, char *str);
+_token_create_str(void *ctx, int type, char *str);
static token_t *
-_token_create_ival (void *ctx, int type, int ival);
+_token_create_ival(void *ctx, int type, int ival);
static token_list_t *
-_token_list_create (void *ctx);
+_token_list_create(void *ctx);
static void
-_token_list_append (token_list_t *list, token_t *token);
+_token_list_append(token_list_t *list, token_t *token);
static void
-_token_list_append_list (token_list_t *list, token_list_t *tail);
+_token_list_append_list(token_list_t *list, token_list_t *tail);
static int
-_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
+_token_list_equal_ignoring_space(token_list_t *a, token_list_t *b);
static void
-_parser_active_list_push (glcpp_parser_t *parser,
- const char *identifier,
- token_node_t *marker);
+_parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
+ token_node_t *marker);
static void
-_parser_active_list_pop (glcpp_parser_t *parser);
+_parser_active_list_pop(glcpp_parser_t *parser);
static int
-_parser_active_list_contains (glcpp_parser_t *parser, const char *identifier);
+_parser_active_list_contains(glcpp_parser_t *parser, const char *identifier);
typedef enum {
- EXPANSION_MODE_IGNORE_DEFINED,
- EXPANSION_MODE_EVALUATE_DEFINED
+ EXPANSION_MODE_IGNORE_DEFINED,
+ EXPANSION_MODE_EVALUATE_DEFINED
} expansion_mode_t;
/* Expand list, and begin lexing from the result (after first
* prefixing a token of type 'head_token_type').
*/
static void
-_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
- int head_token_type,
- token_list_t *list,
- expansion_mode_t mode);
+_glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
+ token_list_t *list, expansion_mode_t mode);
/* Perform macro expansion in-place on the given list. */
static void
-_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
- token_list_t *list,
- expansion_mode_t mode);
+_glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
+ expansion_mode_t mode);
static void
-_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
- token_list_t *list);
+_glcpp_parser_print_expanded_token_list(glcpp_parser_t *parser,
+ token_list_t *list);
static void
-_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
- int condition);
+_glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
+ int condition);
static void
-_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
- const char *type, int condition);
+_glcpp_parser_skip_stack_change_if(glcpp_parser_t *parser, YYLTYPE *loc,
+ const char *type, int condition);
static void
-_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
+_glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc);
static void
_glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t version,
const char *ident, bool explicitly_set);
static int
-glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
+glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
static void
-glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
+glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list);
static void
add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
@@ -163,11 +159,11 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
%locations
%initial-action {
- @$.first_line = 1;
- @$.first_column = 1;
- @$.last_line = 1;
- @$.last_column = 1;
- @$.source = 0;
+ @$.first_line = 1;
+ @$.first_column = 1;
+ @$.last_line = 1;
+ @$.last_column = 1;
+ @$.source = 0;
}
%parse-param {glcpp_parser_t *parser}
@@ -175,7 +171,7 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
%expect 0
- /* We use HASH_TOKEN, DEFINE_TOKEN and VERSION_TOKEN (as opposed to
+ /* We use HASH_TOKEN, DEFINE_TOKEN and VERSION_TOKEN (as opposed to
* HASH, DEFINE, and VERSION) to avoid conflicts with other symbols,
* (such as the <HASH> and <DEFINE> start conditions in the lexer). */
%token DEFINED ELIF_EXPANDED HASH_TOKEN DEFINE_TOKEN FUNC_IDENTIFIER OBJ_IDENTIFIER ELIF ELSE ENDIF ERROR_TOKEN IF IFDEF IFNDEF LINE PRAGMA UNDEF VERSION_TOKEN GARBAGE IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE PLUS_PLUS MINUS_MINUS
@@ -730,438 +726,433 @@ operator:
%%
string_list_t *
-_string_list_create (void *ctx)
+_string_list_create(void *ctx)
{
- string_list_t *list;
+ string_list_t *list;
- list = ralloc (ctx, string_list_t);
- list->head = NULL;
- list->tail = NULL;
+ list = ralloc (ctx, string_list_t);
+ list->head = NULL;
+ list->tail = NULL;
- return list;
+ return list;
}
void
-_string_list_append_item (string_list_t *list, const char *str)
+_string_list_append_item(string_list_t *list, const char *str)
{
- string_node_t *node;
+ string_node_t *node;
- node = ralloc (list, string_node_t);
- node->str = ralloc_strdup (node, str);
+ node = ralloc (list, string_node_t);
+ node->str = ralloc_strdup (node, str);
- node->next = NULL;
+ node->next = NULL;
- if (list->head == NULL) {
- list->head = node;
- } else {
- list->tail->next = node;
- }
+ if (list->head == NULL) {
+ list->head = node;
+ } else {
+ list->tail->next = node;
+ }
- list->tail = node;
+ list->tail = node;
}
int
-_string_list_contains (string_list_t *list, const char *member, int *index)
+_string_list_contains(string_list_t *list, const char *member, int *index)
{
- string_node_t *node;
- int i;
+ string_node_t *node;
+ int i;
- if (list == NULL)
- return 0;
+ if (list == NULL)
+ return 0;
- for (i = 0, node = list->head; node; i++, node = node->next) {
- if (strcmp (node->str, member) == 0) {
- if (index)
- *index = i;
- return 1;
- }
- }
+ for (i = 0, node = list->head; node; i++, node = node->next) {
+ if (strcmp (node->str, member) == 0) {
+ if (index)
+ *index = i;
+ return 1;
+ }
+ }
- return 0;
+ return 0;
}
/* Return duplicate string in list (if any), NULL otherwise. */
const char *
-_string_list_has_duplicate (string_list_t *list)
+_string_list_has_duplicate(string_list_t *list)
{
- string_node_t *node, *dup;
+ string_node_t *node, *dup;
- if (list == NULL)
- return NULL;
+ if (list == NULL)
+ return NULL;
- for (node = list->head; node; node = node->next) {
- for (dup = node->next; dup; dup = dup->next) {
- if (strcmp (node->str, dup->str) == 0)
- return node->str;
- }
- }
+ for (node = list->head; node; node = node->next) {
+ for (dup = node->next; dup; dup = dup->next) {
+ if (strcmp (node->str, dup->str) == 0)
+ return node->str;
+ }
+ }
- return NULL;
+ return NULL;
}
int
-_string_list_length (string_list_t *list)
+_string_list_length(string_list_t *list)
{
- int length = 0;
- string_node_t *node;
+ int length = 0;
+ string_node_t *node;
- if (list == NULL)
- return 0;
+ if (list == NULL)
+ return 0;
- for (node = list->head; node; node = node->next)
- length++;
+ for (node = list->head; node; node = node->next)
+ length++;
- return length;
+ return length;
}
int
-_string_list_equal (string_list_t *a, string_list_t *b)
+_string_list_equal(string_list_t *a, string_list_t *b)
{
- string_node_t *node_a, *node_b;
-
- if (a == NULL && b == NULL)
- return 1;
-
- if (a == NULL || b == NULL)
- return 0;
-
- for (node_a = a->head, node_b = b->head;
- node_a && node_b;
- node_a = node_a->next, node_b = node_b->next)
- {
- if (strcmp (node_a->str, node_b->str))
- return 0;
- }
-
- /* Catch the case of lists being different lengths, (which
- * would cause the loop above to terminate after the shorter
- * list). */
- return node_a == node_b;
+ string_node_t *node_a, *node_b;
+
+ if (a == NULL && b == NULL)
+ return 1;
+
+ if (a == NULL || b == NULL)
+ return 0;
+
+ for (node_a = a->head, node_b = b->head;
+ node_a && node_b;
+ node_a = node_a->next, node_b = node_b->next)
+ {
+ if (strcmp (node_a->str, node_b->str))
+ return 0;
+ }
+
+ /* Catch the case of lists being different lengths, (which
+ * would cause the loop above to terminate after the shorter
+ * list). */
+ return node_a == node_b;
}
argument_list_t *
-_argument_list_create (void *ctx)
+_argument_list_create(void *ctx)
{
- argument_list_t *list;
+ argument_list_t *list;
- list = ralloc (ctx, argument_list_t);
- list->head = NULL;
- list->tail = NULL;
+ list = ralloc (ctx, argument_list_t);
+ list->head = NULL;
+ list->tail = NULL;
- return list;
+ return list;
}
void
-_argument_list_append (argument_list_t *list, token_list_t *argument)
+_argument_list_append(argument_list_t *list, token_list_t *argument)
{
- argument_node_t *node;
+ argument_node_t *node;
- node = ralloc (list, argument_node_t);
- node->argument = argument;
+ node = ralloc (list, argument_node_t);
+ node->argument = argument;
- node->next = NULL;
+ node->next = NULL;
- if (list->head == NULL) {
- list->head = node;
- } else {
- list->tail->next = node;
- }
+ if (list->head == NULL) {
+ list->head = node;
+ } else {
+ list->tail->next = node;
+ }
- list->tail = node;
+ list->tail = node;
}
int
-_argument_list_length (argument_list_t *list)
+_argument_list_length(argument_list_t *list)
{
- int length = 0;
- argument_node_t *node;
+ int length = 0;
+ argument_node_t *node;
- if (list == NULL)
- return 0;
+ if (list == NULL)
+ return 0;
- for (node = list->head; node; node = node->next)
- length++;
+ for (node = list->head; node; node = node->next)
+ length++;
- return length;
+ return length;
}
token_list_t *
-_argument_list_member_at (argument_list_t *list, int index)
+_argument_list_member_at(argument_list_t *list, int index)
{
- argument_node_t *node;
- int i;
+ argument_node_t *node;
+ int i;
- if (list == NULL)
- return NULL;
+ if (list == NULL)
+ return NULL;
- node = list->head;
- for (i = 0; i < index; i++) {
- node = node->next;
- if (node == NULL)
- break;
- }
+ node = list->head;
+ for (i = 0; i < index; i++) {
+ node = node->next;
+ if (node == NULL)
+ break;
+ }
- if (node)
- return node->argument;
+ if (node)
+ return node->argument;
- return NULL;
+ return NULL;
}
/* Note: This function ralloc_steal()s the str pointer. */
token_t *
-_token_create_str (void *ctx, int type, char *str)
+_token_create_str(void *ctx, int type, char *str)
{
- token_t *token;
+ token_t *token;
- token = ralloc (ctx, token_t);
- token->type = type;
- token->value.str = str;
+ token = ralloc (ctx, token_t);
+ token->type = type;
+ token->value.str = str;
- ralloc_steal (token, str);
+ ralloc_steal (token, str);
- return token;
+ return token;
}
token_t *
-_token_create_ival (void *ctx, int type, int ival)
+_token_create_ival(void *ctx, int type, int ival)
{
- token_t *token;
+ token_t *token;
- token = ralloc (ctx, token_t);
- token->type = type;
- token->value.ival = ival;
+ token = ralloc (ctx, token_t);
+ token->type = type;
+ token->value.ival = ival;
- return token;
+ return token;
}
token_list_t *
-_token_list_create (void *ctx)
+_token_list_create(void *ctx)
{
- token_list_t *list;
+ token_list_t *list;
- list = ralloc (ctx, token_list_t);
- list->head = NULL;
- list->tail = NULL;
- list->non_space_tail = NULL;
+ list = ralloc (ctx, token_list_t);
+ list->head = NULL;
+ list->tail = NULL;
+ list->non_space_tail = NULL;
- return list;
+ return list;
}
void
-_token_list_append (token_list_t *list, token_t *token)
+_token_list_append(token_list_t *list, token_t *token)
{
- token_node_t *node;
+ token_node_t *node;
- node = ralloc (list, token_node_t);
- node->token = token;
- node->next = NULL;
+ node = ralloc (list, token_node_t);
+ node->token = token;
+ node->next = NULL;
- if (list->head == NULL) {
- list->head = node;
- } else {
- list->tail->next = node;
- }
+ if (list->head == NULL) {
+ list->head = node;
+ } else {
+ list->tail->next = node;
+ }
- list->tail = node;
- if (token->type != SPACE)
- list->non_space_tail = node;
+ list->tail = node;
+ if (token->type != SPACE)
+ list->non_space_tail = node;
}
void
-_token_list_append_list (token_list_t *list, token_list_t *tail)
+_token_list_append_list(token_list_t *list, token_list_t *tail)
{
- if (tail == NULL || tail->head == NULL)
- return;
+ if (tail == NULL || tail->head == NULL)
+ return;
- if (list->head == NULL) {
- list->head = tail->head;
- } else {
- list->tail->next = tail->head;
- }
+ if (list->head == NULL) {
+ list->head = tail->head;
+ } else {
+ list->tail->next = tail->head;
+ }
- list->tail = tail->tail;
- list->non_space_tail = tail->non_space_tail;
+ list->tail = tail->tail;
+ list->non_space_tail = tail->non_space_tail;
}
static token_list_t *
-_token_list_copy (void *ctx, token_list_t *other)
+_token_list_copy(void *ctx, token_list_t *other)
{
- token_list_t *copy;
- token_node_t *node;
+ token_list_t *copy;
+ token_node_t *node;
- if (other == NULL)
- return NULL;
+ if (other == NULL)
+ return NULL;
- copy = _token_list_create (ctx);
- for (node = other->head; node; node = node->next) {
- token_t *new_token = ralloc (copy, token_t);
- *new_token = *node->token;
- _token_list_append (copy, new_token);
- }
+ copy = _token_list_create (ctx);
+ for (node = other->head; node; node = node->next) {
+ token_t *new_token = ralloc (copy, token_t);
+ *new_token = *node->token;
+ _token_list_append (copy, new_token);
+ }
- return copy;
+ return copy;
}
static void
-_token_list_trim_trailing_space (token_list_t *list)
+_token_list_trim_trailing_space(token_list_t *list)
{
- token_node_t *tail, *next;
-
- if (list->non_space_tail) {
- tail = list->non_space_tail->next;
- list->non_space_tail->next = NULL;
- list->tail = list->non_space_tail;
-
- while (tail) {
- next = tail->next;
- ralloc_free (tail);
- tail = next;
- }
- }
+ token_node_t *tail, *next;
+
+ if (list->non_space_tail) {
+ tail = list->non_space_tail->next;
+ list->non_space_tail->next = NULL;
+ list->tail = list->non_space_tail;
+
+ while (tail) {
+ next = tail->next;
+ ralloc_free (tail);
+ tail = next;
+ }
+ }
}
static int
-_token_list_is_empty_ignoring_space (token_list_t *l)
+_token_list_is_empty_ignoring_space(token_list_t *l)
{
- token_node_t *n;
+ token_node_t *n;
- if (l == NULL)
- return 1;
+ if (l == NULL)
+ return 1;
- n = l->head;
- while (n != NULL && n->token->type == SPACE)
- n = n->next;
+ n = l->head;
+ while (n != NULL && n->token->type == SPACE)
+ n = n->next;
- return n == NULL;
+ return n == NULL;
}
int
-_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
+_token_list_equal_ignoring_space(token_list_t *a, token_list_t *b)
{
- token_node_t *node_a, *node_b;
-
- if (a == NULL || b == NULL) {
- int a_empty = _token_list_is_empty_ignoring_space(a);
- int b_empty = _token_list_is_empty_ignoring_space(b);
- return a_empty == b_empty;
- }
-
- node_a = a->head;
- node_b = b->head;
-
- while (1)
- {
- if (node_a == NULL && node_b == NULL)
- break;
-
- if (node_a == NULL || node_b == NULL)
- return 0;
- /* Make sure whitespace appears in the same places in both.
- * It need not be exactly the same amount of whitespace,
- * though.
- */
- if (node_a->token->type == SPACE
- && node_b->token->type == SPACE) {
- while (node_a && node_a->token->type == SPACE)
- node_a = node_a->next;
- while (node_b && node_b->token->type == SPACE)
- node_b = node_b->next;
- continue;
- }
-
- if (node_a->token->type != node_b->token->type)
- return 0;
-
- switch (node_a->token->type) {
- case INTEGER:
- if (node_a->token->value.ival !=
- node_b->token->value.ival)
- {
- return 0;
- }
- break;
- case IDENTIFIER:
- case INTEGER_STRING:
- case OTHER:
- if (strcmp (node_a->token->value.str,
- node_b->token->value.str))
- {
- return 0;
- }
- break;
- }
-
- node_a = node_a->next;
- node_b = node_b->next;
- }
-
- return 1;
+ token_node_t *node_a, *node_b;
+
+ if (a == NULL || b == NULL) {
+ int a_empty = _token_list_is_empty_ignoring_space(a);
+ int b_empty = _token_list_is_empty_ignoring_space(b);
+ return a_empty == b_empty;
+ }
+
+ node_a = a->head;
+ node_b = b->head;
+
+ while (1)
+ {
+ if (node_a == NULL && node_b == NULL)
+ break;
+
+ if (node_a == NULL || node_b == NULL)
+ return 0;
+ /* Make sure whitespace appears in the same places in both.
+ * It need not be exactly the same amount of whitespace,
+ * though.
+ */
+ if (node_a->token->type == SPACE && node_b->token->type == SPACE) {
+ while (node_a && node_a->token->type == SPACE)
+ node_a = node_a->next;
+ while (node_b && node_b->token->type == SPACE)
+ node_b = node_b->next;
+ continue;
+ }
+
+ if (node_a->token->type != node_b->token->type)
+ return 0;
+
+ switch (node_a->token->type) {
+ case INTEGER:
+ if (node_a->token->value.ival != node_b->token->value.ival) {
+ return 0;
+ }
+ break;
+ case IDENTIFIER:
+ case INTEGER_STRING:
+ case OTHER:
+ if (strcmp(node_a->token->value.str, node_b->token->value.str)) {
+ return 0;
+ }
+ break;
+ }
+
+ node_a = node_a->next;
+ node_b = node_b->next;
+ }
+
+ return 1;
}
static void
-_token_print (char **out, size_t *len, token_t *token)
+_token_print(char **out, size_t *len, token_t *token)
{
- if (token->type < 256) {
- ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
- return;
- }
-
- switch (token->type) {
- case INTEGER:
- ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
- break;
- case IDENTIFIER:
- case INTEGER_STRING:
- case OTHER:
- ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
- break;
- case SPACE:
- ralloc_asprintf_rewrite_tail (out, len, " ");
- break;
- case LEFT_SHIFT:
- ralloc_asprintf_rewrite_tail (out, len, "<<");
- break;
- case RIGHT_SHIFT:
- ralloc_asprintf_rewrite_tail (out, len, ">>");
- break;
- case LESS_OR_EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, "<=");
- break;
- case GREATER_OR_EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, ">=");
- break;
- case EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, "==");
- break;
- case NOT_EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, "!=");
- break;
- case AND:
- ralloc_asprintf_rewrite_tail (out, len, "&&");
- break;
- case OR:
- ralloc_asprintf_rewrite_tail (out, len, "||");
- break;
- case PASTE:
- ralloc_asprintf_rewrite_tail (out, len, "##");
- break;
- case PLUS_PLUS:
- ralloc_asprintf_rewrite_tail (out, len, "++");
- break;
- case MINUS_MINUS:
- ralloc_asprintf_rewrite_tail (out, len, "--");
- break;
- case DEFINED:
- ralloc_asprintf_rewrite_tail (out, len, "defined");
- break;
- case PLACEHOLDER:
- /* Nothing to print. */
- break;
- default:
- assert(!"Error: Don't know how to print token.");
-
- break;
- }
+ if (token->type < 256) {
+ ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
+ return;
+ }
+
+ switch (token->type) {
+ case INTEGER:
+ ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
+ break;
+ case IDENTIFIER:
+ case INTEGER_STRING:
+ case OTHER:
+ ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
+ break;
+ case SPACE:
+ ralloc_asprintf_rewrite_tail (out, len, " ");
+ break;
+ case LEFT_SHIFT:
+ ralloc_asprintf_rewrite_tail (out, len, "<<");
+ break;
+ case RIGHT_SHIFT:
+ ralloc_asprintf_rewrite_tail (out, len, ">>");
+ break;
+ case LESS_OR_EQUAL:
+ ralloc_asprintf_rewrite_tail (out, len, "<=");
+ break;
+ case GREATER_OR_EQUAL:
+ ralloc_asprintf_rewrite_tail (out, len, ">=");
+ break;
+ case EQUAL:
+ ralloc_asprintf_rewrite_tail (out, len, "==");
+ break;
+ case NOT_EQUAL:
+ ralloc_asprintf_rewrite_tail (out, len, "!=");
+ break;
+ case AND:
+ ralloc_asprintf_rewrite_tail (out, len, "&&");
+ break;
+ case OR:
+ ralloc_asprintf_rewrite_tail (out, len, "||");
+ break;
+ case PASTE:
+ ralloc_asprintf_rewrite_tail (out, len, "##");
+ break;
+ case PLUS_PLUS:
+ ralloc_asprintf_rewrite_tail (out, len, "++");
+ break;
+ case MINUS_MINUS:
+ ralloc_asprintf_rewrite_tail (out, len, "--");
+ break;
+ case DEFINED:
+ ralloc_asprintf_rewrite_tail (out, len, "defined");
+ break;
+ case PLACEHOLDER:
+ /* Nothing to print. */
+ break;
+ default:
+ assert(!"Error: Don't know how to print token.");
+
+ break;
+ }
}
/* Return a new token (ralloc()ed off of 'token') formed by pasting
@@ -1171,148 +1162,143 @@ _token_print (char **out, size_t *len, token_t *token)
* Caution: Only very cursory error-checking is performed to see if
* the final result is a valid single token. */
static token_t *
-_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
+_token_paste(glcpp_parser_t *parser, token_t *token, token_t *other)
{
- token_t *combined = NULL;
-
- /* Pasting a placeholder onto anything makes no change. */
- if (other->type == PLACEHOLDER)
- return token;
-
- /* When 'token' is a placeholder, just return 'other'. */
- if (token->type == PLACEHOLDER)
- return other;
-
- /* A very few single-character punctuators can be combined
- * with another to form a multi-character punctuator. */
- switch (token->type) {
- case '<':
- if (other->type == '<')
- combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
- else if (other->type == '=')
- combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
- break;
- case '>':
- if (other->type == '>')
- combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
- else if (other->type == '=')
- combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
- break;
- case '=':
- if (other->type == '=')
- combined = _token_create_ival (token, EQUAL, EQUAL);
- break;
- case '!':
- if (other->type == '=')
- combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
- break;
- case '&':
- if (other->type == '&')
- combined = _token_create_ival (token, AND, AND);
- break;
- case '|':
- if (other->type == '|')
- combined = _token_create_ival (token, OR, OR);
- break;
- }
-
- if (combined != NULL) {
- /* Inherit the location from the first token */
- combined->location = token->location;
- return combined;
- }
-
- /* Two string-valued (or integer) tokens can usually just be
- * mashed together. (We also handle a string followed by an
- * integer here as well.)
- *
- * There are some exceptions here. Notably, if the first token
- * is an integer (or a string representing an integer), then
- * the second token must also be an integer or must be a
- * string representing an integer that begins with a digit.
- */
- if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING || token->type == INTEGER) &&
- (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING || other->type == INTEGER))
- {
- char *str;
- int combined_type;
-
- /* Check that pasting onto an integer doesn't create a
- * non-integer, (that is, only digits can be
- * pasted. */
- if (token->type == INTEGER_STRING || token->type == INTEGER)
- {
- switch (other->type) {
- case INTEGER_STRING:
- if (other->value.str[0] < '0' ||
- other->value.str[0] > '9')
- goto FAIL;
- break;
- case INTEGER:
- if (other->value.ival < 0)
- goto FAIL;
- break;
- default:
- goto FAIL;
- }
- }
-
- if (token->type == INTEGER)
- str = ralloc_asprintf (token, "%" PRIiMAX,
- token->value.ival);
- else
- str = ralloc_strdup (token, token->value.str);
-
-
- if (other->type == INTEGER)
- ralloc_asprintf_append (&str, "%" PRIiMAX,
- other->value.ival);
- else
- ralloc_strcat (&str, other->value.str);
-
- /* New token is same type as original token, unless we
- * started with an integer, in which case we will be
- * creating an integer-string. */
- combined_type = token->type;
- if (combined_type == INTEGER)
- combined_type = INTEGER_STRING;
-
- combined = _token_create_str (token, combined_type, str);
- combined->location = token->location;
- return combined;
- }
+ token_t *combined = NULL;
+
+ /* Pasting a placeholder onto anything makes no change. */
+ if (other->type == PLACEHOLDER)
+ return token;
+
+ /* When 'token' is a placeholder, just return 'other'. */
+ if (token->type == PLACEHOLDER)
+ return other;
+
+ /* A very few single-character punctuators can be combined
+ * with another to form a multi-character punctuator. */
+ switch (token->type) {
+ case '<':
+ if (other->type == '<')
+ combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
+ else if (other->type == '=')
+ combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
+ break;
+ case '>':
+ if (other->type == '>')
+ combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
+ else if (other->type == '=')
+ combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
+ break;
+ case '=':
+ if (other->type == '=')
+ combined = _token_create_ival (token, EQUAL, EQUAL);
+ break;
+ case '!':
+ if (other->type == '=')
+ combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
+ break;
+ case '&':
+ if (other->type == '&')
+ combined = _token_create_ival (token, AND, AND);
+ break;
+ case '|':
+ if (other->type == '|')
+ combined = _token_create_ival (token, OR, OR);
+ break;
+ }
+
+ if (combined != NULL) {
+ /* Inherit the location from the first token */
+ combined->location = token->location;
+ return combined;
+ }
+
+ /* Two string-valued (or integer) tokens can usually just be
+ * mashed together. (We also handle a string followed by an
+ * integer here as well.)
+ *
+ * There are some exceptions here. Notably, if the first token
+ * is an integer (or a string representing an integer), then
+ * the second token must also be an integer or must be a
+ * string representing an integer that begins with a digit.
+ */
+ if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING || token->type == INTEGER) &&
+ (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING || other->type == INTEGER))
+ {
+ char *str;
+ int combined_type;
+
+ /* Check that pasting onto an integer doesn't create a
+ * non-integer, (that is, only digits can be
+ * pasted. */
+ if (token->type == INTEGER_STRING || token->type == INTEGER) {
+ switch (other->type) {
+ case INTEGER_STRING:
+ if (other->value.str[0] < '0' || other->value.str[0] > '9')
+ goto FAIL;
+ break;
+ case INTEGER:
+ if (other->value.ival < 0)
+ goto FAIL;
+ break;
+ default:
+ goto FAIL;
+ }
+ }
+
+ if (token->type == INTEGER)
+ str = ralloc_asprintf (token, "%" PRIiMAX, token->value.ival);
+ else
+ str = ralloc_strdup (token, token->value.str);
+
+ if (other->type == INTEGER)
+ ralloc_asprintf_append (&str, "%" PRIiMAX, other->value.ival);
+ else
+ ralloc_strcat (&str, other->value.str);
+
+ /* New token is same type as original token, unless we
+ * started with an integer, in which case we will be
+ * creating an integer-string. */
+ combined_type = token->type;
+ if (combined_type == INTEGER)
+ combined_type = INTEGER_STRING;
+
+ combined = _token_create_str (token, combined_type, str);
+ combined->location = token->location;
+ return combined;
+ }
FAIL:
- glcpp_error (&token->location, parser, "");
- ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \"");
- _token_print (&parser->info_log, &parser->info_log_length, token);
- ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \"");
- _token_print (&parser->info_log, &parser->info_log_length, other);
- ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a valid preprocessing token.\n");
-
- return token;
+ glcpp_error (&token->location, parser, "");
+ ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \"");
+ _token_print (&parser->info_log, &parser->info_log_length, token);
+ ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \"");
+ _token_print (&parser->info_log, &parser->info_log_length, other);
+ ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a valid preprocessing token.\n");
+
+ return token;
}
static void
-_token_list_print (glcpp_parser_t *parser, token_list_t *list)
+_token_list_print(glcpp_parser_t *parser, token_list_t *list)
{
- token_node_t *node;
+ token_node_t *node;
- if (list == NULL)
- return;
+ if (list == NULL)
+ return;
- for (node = list->head; node; node = node->next)
- _token_print (&parser->output, &parser->output_length, node->token);
+ for (node = list->head; node; node = node->next)
+ _token_print (&parser->output, &parser->output_length, node->token);
}
void
-yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
+yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
{
- glcpp_error(locp, parser, "%s", error);
+ glcpp_error(locp, parser, "%s", error);
}
-static void add_builtin_define(glcpp_parser_t *parser,
- const char *name, int value)
+static void
+add_builtin_define(glcpp_parser_t *parser, const char *name, int value)
{
token_t *tok;
token_list_t *list;
@@ -1325,63 +1311,63 @@ static void add_builtin_define(glcpp_parser_t *parser,
}
glcpp_parser_t *
-glcpp_parser_create (const struct gl_extensions *extensions, gl_api api)
+glcpp_parser_create(const struct gl_extensions *extensions, gl_api api)
{
- glcpp_parser_t *parser;
-
- parser = ralloc (NULL, glcpp_parser_t);
-
- glcpp_lex_init_extra (parser, &parser->scanner);
- parser->defines = hash_table_ctor (32, hash_table_string_hash,
- hash_table_string_compare);
- parser->active = NULL;
- parser->lexing_directive = 0;
- parser->space_tokens = 1;
- parser->last_token_was_newline = 0;
- parser->last_token_was_space = 0;
- parser->first_non_space_token_this_line = 1;
- parser->newline_as_space = 0;
- parser->in_control_line = 0;
- parser->paren_count = 0;
- parser->commented_newlines = 0;
-
- parser->skip_stack = NULL;
- parser->skipping = 0;
-
- parser->lex_from_list = NULL;
- parser->lex_from_node = NULL;
-
- parser->output = ralloc_strdup(parser, "");
- parser->output_length = 0;
- parser->info_log = ralloc_strdup(parser, "");
- parser->info_log_length = 0;
- parser->error = 0;
-
- parser->extensions = extensions;
- parser->api = api;
- parser->version_resolved = false;
-
- parser->has_new_line_number = 0;
- parser->new_line_number = 1;
- parser->has_new_source_number = 0;
- parser->new_source_number = 0;
-
- return parser;
+ glcpp_parser_t *parser;
+
+ parser = ralloc (NULL, glcpp_parser_t);
+
+ glcpp_lex_init_extra (parser, &parser->scanner);
+ parser->defines = hash_table_ctor(32, hash_table_string_hash,
+ hash_table_string_compare);
+ parser->active = NULL;
+ parser->lexing_directive = 0;
+ parser->space_tokens = 1;
+ parser->last_token_was_newline = 0;
+ parser->last_token_was_space = 0;
+ parser->first_non_space_token_this_line = 1;
+ parser->newline_as_space = 0;
+ parser->in_control_line = 0;
+ parser->paren_count = 0;
+ parser->commented_newlines = 0;
+
+ parser->skip_stack = NULL;
+ parser->skipping = 0;
+
+ parser->lex_from_list = NULL;
+ parser->lex_from_node = NULL;
+
+ parser->output = ralloc_strdup(parser, "");
+ parser->output_length = 0;
+ parser->info_log = ralloc_strdup(parser, "");
+ parser->info_log_length = 0;
+ parser->error = 0;
+
+ parser->extensions = extensions;
+ parser->api = api;
+ parser->version_resolved = false;
+
+ parser->has_new_line_number = 0;
+ parser->new_line_number = 1;
+ parser->has_new_source_number = 0;
+ parser->new_source_number = 0;
+
+ return parser;
}
void
-glcpp_parser_destroy (glcpp_parser_t *parser)
+glcpp_parser_destroy(glcpp_parser_t *parser)
{
- glcpp_lex_destroy (parser->scanner);
- hash_table_dtor (parser->defines);
- ralloc_free (parser);
+ glcpp_lex_destroy (parser->scanner);
+ hash_table_dtor (parser->defines);
+ ralloc_free (parser);
}
typedef enum function_status
{
- FUNCTION_STATUS_SUCCESS,
- FUNCTION_NOT_A_FUNCTION,
- FUNCTION_UNBALANCED_PARENTHESES
+ FUNCTION_STATUS_SUCCESS,
+ FUNCTION_NOT_A_FUNCTION,
+ FUNCTION_UNBALANCED_PARENTHESES
} function_status_t;
/* Find a set of function-like macro arguments by looking for a
@@ -1396,100 +1382,92 @@ typedef enum function_status
*
* FUNCTION_STATUS_SUCCESS:
*
- * Successfully parsed a set of function arguments.
+ * Successfully parsed a set of function arguments.
*
* FUNCTION_NOT_A_FUNCTION:
*
- * Macro name not followed by a '('. This is not an error, but
- * simply that the macro name should be treated as a non-macro.
+ * Macro name not followed by a '('. This is not an error, but
+ * simply that the macro name should be treated as a non-macro.
*
* FUNCTION_UNBALANCED_PARENTHESES
*
- * Macro name is not followed by a balanced set of parentheses.
+ * Macro name is not followed by a balanced set of parentheses.
*/
static function_status_t
-_arguments_parse (argument_list_t *arguments,
- token_node_t *node,
- token_node_t **last)
+_arguments_parse(argument_list_t *arguments, token_node_t *node,
+ token_node_t **last)
{
- token_list_t *argument;
- int paren_count;
-
- node = node->next;
-
- /* Ignore whitespace before first parenthesis. */
- while (node && node->token->type == SPACE)
- node = node->next;
-
- if (node == NULL || node->token->type != '(')
- return FUNCTION_NOT_A_FUNCTION;
-
- node = node->next;
-
- argument = _token_list_create (arguments);
- _argument_list_append (arguments, argument);
-
- for (paren_count = 1; node; node = node->next) {
- if (node->token->type == '(')
- {
- paren_count++;
- }
- else if (node->token->type == ')')
- {
- paren_count--;
- if (paren_count == 0)
- break;
- }
-
- if (node->token->type == ',' &&
- paren_count == 1)
- {
- _token_list_trim_trailing_space (argument);
- argument = _token_list_create (arguments);
- _argument_list_append (arguments, argument);
- }
- else {
- if (argument->head == NULL) {
- /* Don't treat initial whitespace as
- * part of the argument. */
- if (node->token->type == SPACE)
- continue;
- }
- _token_list_append (argument, node->token);
- }
- }
-
- if (paren_count)
- return FUNCTION_UNBALANCED_PARENTHESES;
-
- *last = node;
-
- return FUNCTION_STATUS_SUCCESS;
+ token_list_t *argument;
+ int paren_count;
+
+ node = node->next;
+
+ /* Ignore whitespace before first parenthesis. */
+ while (node && node->token->type == SPACE)
+ node = node->next;
+
+ if (node == NULL || node->token->type != '(')
+ return FUNCTION_NOT_A_FUNCTION;
+
+ node = node->next;
+
+ argument = _token_list_create (arguments);
+ _argument_list_append (arguments, argument);
+
+ for (paren_count = 1; node; node = node->next) {
+ if (node->token->type == '(') {
+ paren_count++;
+ } else if (node->token->type == ')') {
+ paren_count--;
+ if (paren_count == 0)
+ break;
+ }
+
+ if (node->token->type == ',' && paren_count == 1) {
+ _token_list_trim_trailing_space (argument);
+ argument = _token_list_create (arguments);
+ _argument_list_append (arguments, argument);
+ } else {
+ if (argument->head == NULL) {
+ /* Don't treat initial whitespace as part of the argument. */
+ if (node->token->type == SPACE)
+ continue;
+ }
+ _token_list_append (argument, node->token);
+ }
+ }
+
+ if (paren_count)
+ return FUNCTION_UNBALANCED_PARENTHESES;
+
+ *last = node;
+
+ return FUNCTION_STATUS_SUCCESS;
}
static token_list_t *
-_token_list_create_with_one_ival (void *ctx, int type, int ival)
+_token_list_create_with_one_ival(void *ctx, int type, int ival)
{
- token_list_t *list;
- token_t *node;
+ token_list_t *list;
+ token_t *node;
- list = _token_list_create (ctx);
- node = _token_create_ival (list, type, ival);
- _token_list_append (list, node);
+ list = _token_list_create(ctx);
+ node = _token_create_ival(list, type, ival);
+ _token_list_append(list, node);
- return list;
+ return list;
}
static token_list_t *
-_token_list_create_with_one_space (void *ctx)
+_token_list_create_with_one_space(void *ctx)
{
- return _token_list_create_with_one_ival (ctx, SPACE, SPACE);
+ return _token_list_create_with_one_ival(ctx, SPACE, SPACE);
}
static token_list_t *
-_token_list_create_with_one_integer (void *ctx, int ival)
+_token_list_create_with_one_integer(void *ctx, int ival)
{
- return _token_list_create_with_one_ival (ctx, INTEGER, ival);
+ return _token_list_create_with_one_ival(ctx, INTEGER, ival);
}
/* Evaluate a DEFINED token node (based on subsequent tokens in the list).
@@ -1501,119 +1479,117 @@ _token_list_create_with_one_integer (void *ctx, int ival)
* (optionally preceded and followed by '(' and ')' tokens) then the following
* occurs:
*
- * If the identifier is a defined macro, this function returns 1.
+ * If the identifier is a defined macro, this function returns 1.
*
- * If the identifier is not a defined macro, this function returns 0.
+ * If the identifier is not a defined macro, this function returns 0.
*
- * In either case, *last will be updated to the last node in the list
- * consumed by the evaluation, (either the token of the identifier or the
- * token of the closing parenthesis).
+ * In either case, *last will be updated to the last node in the list
+ * consumed by the evaluation, (either the token of the identifier or the
+ * token of the closing parenthesis).
*
* In all other cases, (such as "node is the final node of the list", or
* "missing closing parenthesis", etc.), this function generates a
* preprocessor error, returns -1 and *last will not be set.
*/
static int
-_glcpp_parser_evaluate_defined (glcpp_parser_t *parser,
- token_node_t *node,
- token_node_t **last)
+_glcpp_parser_evaluate_defined(glcpp_parser_t *parser, token_node_t *node,
+ token_node_t **last)
{
- token_node_t *argument, *defined = node;
+ token_node_t *argument, *defined = node;
- assert (node->token->type == DEFINED);
+ assert(node->token->type == DEFINED);
- node = node->next;
+ node = node->next;
- /* Ignore whitespace after DEFINED token. */
- while (node && node->token->type == SPACE)
- node = node->next;
+ /* Ignore whitespace after DEFINED token. */
+ while (node && node->token->type == SPACE)
+ node = node->next;
- if (node == NULL)
- goto FAIL;
+ if (node == NULL)
+ goto FAIL;
- if (node->token->type == IDENTIFIER || node->token->type == OTHER) {
- argument = node;
- } else if (node->token->type == '(') {
- node = node->next;
+ if (node->token->type == IDENTIFIER || node->token->type == OTHER) {
+ argument = node;
+ } else if (node->token->type == '(') {
+ node = node->next;
- /* Ignore whitespace after '(' token. */
- while (node && node->token->type == SPACE)
- node = node->next;
+ /* Ignore whitespace after '(' token. */
+ while (node && node->token->type == SPACE)
+ node = node->next;
- if (node == NULL || (node->token->type != IDENTIFIER &&
- node->token->type != OTHER))
- {
- goto FAIL;
- }
+ if (node == NULL || (node->token->type != IDENTIFIER &&
+ node->token->type != OTHER)) {
+ goto FAIL;
+ }
- argument = node;
+ argument = node;
- node = node->next;
+ node = node->next;
- /* Ignore whitespace after identifier, before ')' token. */
- while (node && node->token->type == SPACE)
- node = node->next;
+ /* Ignore whitespace after identifier, before ')' token. */
+ while (node && node->token->type == SPACE)
+ node = node->next;
- if (node == NULL || node->token->type != ')')
- goto FAIL;
- } else {
- goto FAIL;
- }
+ if (node == NULL || node->token->type != ')')
+ goto FAIL;
+ } else {
+ goto FAIL;
+ }
- *last = node;
+ *last = node;
- return hash_table_find (parser->defines,
- argument->token->value.str) ? 1 : 0;
+ return hash_table_find(parser->defines,
+ argument->token->value.str) ? 1 : 0;
FAIL:
- glcpp_error (&defined->token->location, parser,
- "\"defined\" not followed by an identifier");
- return -1;
+ glcpp_error (&defined->token->location, parser,
+ "\"defined\" not followed by an identifier");
+ return -1;
}
/* Evaluate all DEFINED nodes in a given list, modifying the list in place.
*/
static void
-_glcpp_parser_evaluate_defined_in_list (glcpp_parser_t *parser,
- token_list_t *list)
+_glcpp_parser_evaluate_defined_in_list(glcpp_parser_t *parser,
+ token_list_t *list)
{
- token_node_t *node, *node_prev, *replacement, *last = NULL;
- int value;
+ token_node_t *node, *node_prev, *replacement, *last = NULL;
+ int value;
- if (list == NULL)
- return;
+ if (list == NULL)
+ return;
- node_prev = NULL;
- node = list->head;
+ node_prev = NULL;
+ node = list->head;
- while (node) {
+ while (node) {
- if (node->token->type != DEFINED)
- goto NEXT;
+ if (node->token->type != DEFINED)
+ goto NEXT;
- value = _glcpp_parser_evaluate_defined (parser, node, &last);
- if (value == -1)
- goto NEXT;
+ value = _glcpp_parser_evaluate_defined (parser, node, &last);
+ if (value == -1)
+ goto NEXT;
- replacement = ralloc (list, token_node_t);
- replacement->token = _token_create_ival (list, INTEGER, value);
+ replacement = ralloc (list, token_node_t);
+ replacement->token = _token_create_ival (list, INTEGER, value);
- /* Splice replacement node into list, replacing from "node"
- * through "last". */
- if (node_prev)
- node_prev->next = replacement;
- else
- list->head = replacement;
- replacement->next = last->next;
- if (last == list->tail)
- list->tail = replacement;
+ /* Splice replacement node into list, replacing from "node"
+ * through "last". */
+ if (node_prev)
+ node_prev->next = replacement;
+ else
+ list->head = replacement;
+ replacement->next = last->next;
+ if (last == list->tail)
+ list->tail = replacement;
- node = replacement;
+ node = replacement;
- NEXT:
- node_prev = node;
- node = node->next;
- }
+ NEXT:
+ node_prev = node;
+ node = node->next;
+ }
}
/* Perform macro expansion on 'list', placing the resulting tokens
@@ -1625,62 +1601,59 @@ _glcpp_parser_evaluate_defined_in_list (glcpp_parser_t *parser,
* of the "mode" parameter.
*/
static void
-_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
- int head_token_type,
- token_list_t *list,
- expansion_mode_t mode)
+_glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
+ token_list_t *list, expansion_mode_t mode)
{
- token_list_t *expanded;
- token_t *token;
-
- expanded = _token_list_create (parser);
- token = _token_create_ival (parser, head_token_type, head_token_type);
- _token_list_append (expanded, token);
- _glcpp_parser_expand_token_list (parser, list, mode);
- _token_list_append_list (expanded, list);
- glcpp_parser_lex_from (parser, expanded);
+ token_list_t *expanded;
+ token_t *token;
+
+ expanded = _token_list_create (parser);
+ token = _token_create_ival (parser, head_token_type, head_token_type);
+ _token_list_append (expanded, token);
+ _glcpp_parser_expand_token_list (parser, list, mode);
+ _token_list_append_list (expanded, list);
+ glcpp_parser_lex_from (parser, expanded);
}
static void
-_glcpp_parser_apply_pastes (glcpp_parser_t *parser, token_list_t *list)
+_glcpp_parser_apply_pastes(glcpp_parser_t *parser, token_list_t *list)
{
- token_node_t *node;
-
- node = list->head;
- while (node)
- {
- token_node_t *next_non_space;
-
- /* Look ahead for a PASTE token, skipping space. */
- next_non_space = node->next;
- while (next_non_space && next_non_space->token->type == SPACE)
- next_non_space = next_non_space->next;
-
- if (next_non_space == NULL)
- break;
-
- if (next_non_space->token->type != PASTE) {
- node = next_non_space;
- continue;
- }
-
- /* Now find the next non-space token after the PASTE. */
- next_non_space = next_non_space->next;
- while (next_non_space && next_non_space->token->type == SPACE)
- next_non_space = next_non_space->next;
-
- if (next_non_space == NULL) {
- yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
- return;
- }
-
- node->token = _token_paste (parser, node->token, next_non_space->token);
- node->next = next_non_space->next;
- if (next_non_space == list->tail)
- list->tail = node;
- }
-
- list->non_space_tail = list->tail;
+ token_node_t *node;
+
+ node = list->head;
+ while (node) {
+ token_node_t *next_non_space;
+
+ /* Look ahead for a PASTE token, skipping space. */
+ next_non_space = node->next;
+ while (next_non_space && next_non_space->token->type == SPACE)
+ next_non_space = next_non_space->next;
+
+ if (next_non_space == NULL)
+ break;
+
+ if (next_non_space->token->type != PASTE) {
+ node = next_non_space;
+ continue;
+ }
+
+ /* Now find the next non-space token after the PASTE. */
+ next_non_space = next_non_space->next;
+ while (next_non_space && next_non_space->token->type == SPACE)
+ next_non_space = next_non_space->next;
+
+ if (next_non_space == NULL) {
+ yyerror(&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
+ return;
+ }
+
+ node->token = _token_paste(parser, node->token, next_non_space->token);
+ node->next = next_non_space->next;
+ if (next_non_space == list->tail)
+ list->tail = node;
+ }
+
+ list->non_space_tail = list->tail;
}
/* This is a helper function that's essentially part of the
@@ -1704,103 +1677,89 @@ _glcpp_parser_apply_pastes (glcpp_parser_t *parser, token_list_t *list)
* of the "mode" parameter.
*/
static token_list_t *
-_glcpp_parser_expand_function (glcpp_parser_t *parser,
- token_node_t *node,
- token_node_t **last,
- expansion_mode_t mode)
+_glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
+ token_node_t **last, expansion_mode_t mode)
{
- macro_t *macro;
- const char *identifier;
- argument_list_t *arguments;
- function_status_t status;
- token_list_t *substituted;
- int parameter_index;
-
- identifier = node->token->value.str;
-
- macro = hash_table_find (parser->defines, identifier);
-
- assert (macro->is_function);
-
- arguments = _argument_list_create (parser);
- status = _arguments_parse (arguments, node, last);
-
- switch (status) {
- case FUNCTION_STATUS_SUCCESS:
- break;
- case FUNCTION_NOT_A_FUNCTION:
- return NULL;
- case FUNCTION_UNBALANCED_PARENTHESES:
- glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
- return NULL;
- }
-
- /* Replace a macro defined as empty with a SPACE token. */
- if (macro->replacements == NULL) {
- ralloc_free (arguments);
- return _token_list_create_with_one_space (parser);
- }
-
- if (! ((_argument_list_length (arguments) ==
- _string_list_length (macro->parameters)) ||
- (_string_list_length (macro->parameters) == 0 &&
- _argument_list_length (arguments) == 1 &&
- arguments->head->argument->head == NULL)))
- {
- glcpp_error (&node->token->location, parser,
- "Error: macro %s invoked with %d arguments (expected %d)\n",
- identifier,
- _argument_list_length (arguments),
- _string_list_length (macro->parameters));
- return NULL;
- }
-
- /* Perform argument substitution on the replacement list. */
- substituted = _token_list_create (arguments);
-
- for (node = macro->replacements->head; node; node = node->next)
- {
- if (node->token->type == IDENTIFIER &&
- _string_list_contains (macro->parameters,
- node->token->value.str,
- &parameter_index))
- {
- token_list_t *argument;
- argument = _argument_list_member_at (arguments,
- parameter_index);
- /* Before substituting, we expand the argument
- * tokens, or append a placeholder token for
- * an empty argument. */
- if (argument->head) {
- token_list_t *expanded_argument;
- expanded_argument = _token_list_copy (parser,
- argument);
- _glcpp_parser_expand_token_list (parser,
- expanded_argument,
- mode);
- _token_list_append_list (substituted,
- expanded_argument);
- } else {
- token_t *new_token;
-
- new_token = _token_create_ival (substituted,
- PLACEHOLDER,
- PLACEHOLDER);
- _token_list_append (substituted, new_token);
- }
- } else {
- _token_list_append (substituted, node->token);
- }
- }
-
- /* After argument substitution, and before further expansion
- * below, implement token pasting. */
-
- _token_list_trim_trailing_space (substituted);
-
- _glcpp_parser_apply_pastes (parser, substituted);
-
- return substituted;
+ macro_t *macro;
+ const char *identifier;
+ argument_list_t *arguments;
+ function_status_t status;
+ token_list_t *substituted;
+ int parameter_index;
+
+ identifier = node->token->value.str;
+
+ macro = hash_table_find(parser->defines, identifier);
+
+ assert(macro->is_function);
+
+ arguments = _argument_list_create(parser);
+ status = _arguments_parse(arguments, node, last);
+
+ switch (status) {
+ case FUNCTION_STATUS_SUCCESS:
+ break;
+ case FUNCTION_NOT_A_FUNCTION:
+ return NULL;
+ case FUNCTION_UNBALANCED_PARENTHESES:
+ glcpp_error(&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
+ return NULL;
+ }
+
+ /* Replace a macro defined as empty with a SPACE token. */
+ if (macro->replacements == NULL) {
+ ralloc_free(arguments);
+ return _token_list_create_with_one_space(parser);
+ }
+
+ if (!((_argument_list_length (arguments) ==
+ _string_list_length (macro->parameters)) ||
+ (_string_list_length (macro->parameters) == 0 &&
+ _argument_list_length (arguments) == 1 &&
+ arguments->head->argument->head == NULL))) {
+ glcpp_error(&node->token->location, parser,
+ "Error: macro %s invoked with %d arguments (expected %d)\n",
+ identifier, _argument_list_length (arguments),
+ _string_list_length(macro->parameters));
+ return NULL;
+ }
+
+ /* Perform argument substitution on the replacement list. */
+ substituted = _token_list_create(arguments);
+
+ for (node = macro->replacements->head; node; node = node->next) {
+ if (node->token->type == IDENTIFIER &&
+ _string_list_contains(macro->parameters, node->token->value.str,
+ &parameter_index)) {
+ token_list_t *argument;
+ argument = _argument_list_member_at(arguments, parameter_index);
+ /* Before substituting, we expand the argument tokens, or append a
+ * placeholder token for an empty argument. */
+ if (argument->head) {
+ token_list_t *expanded_argument;
+ expanded_argument = _token_list_copy(parser, argument);
+ _glcpp_parser_expand_token_list(parser, expanded_argument, mode);
+ _token_list_append_list(substituted, expanded_argument);
+ } else {
+ token_t *new_token;
+
+ new_token = _token_create_ival(substituted, PLACEHOLDER,
+ PLACEHOLDER);
+ _token_list_append(substituted, new_token);
+ }
+ } else {
+ _token_list_append(substituted, node->token);
+ }
+ }
+
+ /* After argument substitution, and before further expansion
+ * below, implement token pasting. */
+
+ _token_list_trim_trailing_space(substituted);
+
+ _glcpp_parser_apply_pastes(parser, substituted);
+
+ return substituted;
}
/* Compute the complete expansion of node, (and subsequent nodes after
@@ -1813,78 +1772,74 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
* and sets *last to the last node in the list that was consumed by
* the expansion. Specifically, *last will be set as follows:
*
- * As 'node' in the case of object-like macro expansion.
+ * As 'node' in the case of object-like macro expansion.
*
- * As the token of the closing right parenthesis in the case of
- * function-like macro expansion.
+ * As the token of the closing right parenthesis in the case of
+ * function-like macro expansion.
*
* See the documentation of _glcpp_parser_expand_token_list for a description
* of the "mode" parameter.
*/
static token_list_t *
-_glcpp_parser_expand_node (glcpp_parser_t *parser,
- token_node_t *node,
- token_node_t **last,
- expansion_mode_t mode)
+_glcpp_parser_expand_node(glcpp_parser_t *parser, token_node_t *node,
+ token_node_t **last, expansion_mode_t mode)
{
- token_t *token = node->token;
- const char *identifier;
- macro_t *macro;
-
- /* We only expand identifiers */
- if (token->type != IDENTIFIER) {
- return NULL;
- }
-
- *last = node;
- identifier = token->value.str;
-
- /* Special handling for __LINE__ and __FILE__, (not through
- * the hash table). */
- if (strcmp(identifier, "__LINE__") == 0)
- return _token_list_create_with_one_integer (parser, node->token->location.first_line);
-
- if (strcmp(identifier, "__FILE__") == 0)
- return _token_list_create_with_one_integer (parser, node->token->location.source);
-
- /* Look up this identifier in the hash table. */
- macro = hash_table_find (parser->defines, identifier);
-
- /* Not a macro, so no expansion needed. */
- if (macro == NULL)
- return NULL;
-
- /* Finally, don't expand this macro if we're already actively
- * expanding it, (to avoid infinite recursion). */
- if (_parser_active_list_contains (parser, identifier)) {
- /* We change the token type here from IDENTIFIER to
- * OTHER to prevent any future expansion of this
- * unexpanded token. */
- char *str;
- token_list_t *expansion;
- token_t *final;
-
- str = ralloc_strdup (parser, token->value.str);
- final = _token_create_str (parser, OTHER, str);
- expansion = _token_list_create (parser);
- _token_list_append (expansion, final);
- return expansion;
- }
-
- if (! macro->is_function)
- {
- token_list_t *replacement;
-
- /* Replace a macro defined as empty with a SPACE token. */
- if (macro->replacements == NULL)
- return _token_list_create_with_one_space (parser);
-
- replacement = _token_list_copy (parser, macro->replacements);
- _glcpp_parser_apply_pastes (parser, replacement);
- return replacement;
- }
-
- return _glcpp_parser_expand_function (parser, node, last, mode);
+ token_t *token = node->token;
+ const char *identifier;
+ macro_t *macro;
+
+ /* We only expand identifiers */
+ if (token->type != IDENTIFIER) {
+ return NULL;
+ }
+
+ *last = node;
+ identifier = token->value.str;
+
+ /* Special handling for __LINE__ and __FILE__, (not through
+ * the hash table). */
+ if (strcmp(identifier, "__LINE__") == 0)
+ return _token_list_create_with_one_integer(parser, node->token->location.first_line);
+
+ if (strcmp(identifier, "__FILE__") == 0)
+ return _token_list_create_with_one_integer(parser, node->token->location.source);
+
+ /* Look up this identifier in the hash table. */
+ macro = hash_table_find(parser->defines, identifier);
+
+ /* Not a macro, so no expansion needed. */
+ if (macro == NULL)
+ return NULL;
+
+ /* Finally, don't expand this macro if we're already actively
+ * expanding it, (to avoid infinite recursion). */
+ if (_parser_active_list_contains (parser, identifier)) {
+ /* We change the token type here from IDENTIFIER to OTHER to prevent any
+ * future expansion of this unexpanded token. */
+ char *str;
+ token_list_t *expansion;
+ token_t *final;
+
+ str = ralloc_strdup(parser, token->value.str);
+ final = _token_create_str(parser, OTHER, str);
+ expansion = _token_list_create(parser);
+ _token_list_append(expansion, final);
+ return expansion;
+ }
+
+ if (! macro->is_function) {
+ token_list_t *replacement;
+
+ /* Replace a macro defined as empty with a SPACE token. */
+ if (macro->replacements == NULL)
+ return _token_list_create_with_one_space(parser);
+
+ replacement = _token_list_copy(parser, macro->replacements);
+ _glcpp_parser_apply_pastes(parser, replacement);
+ return replacement;
+ }
+
+ return _glcpp_parser_expand_function(parser, node, last, mode);
}
/* Push a new identifier onto the parser's active list.
@@ -1895,49 +1850,48 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
* active stack.
*/
static void
-_parser_active_list_push (glcpp_parser_t *parser,
- const char *identifier,
- token_node_t *marker)
+_parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
+ token_node_t *marker)
{
- active_list_t *node;
+ active_list_t *node;
- node = ralloc (parser->active, active_list_t);
- node->identifier = ralloc_strdup (node, identifier);
- node->marker = marker;
- node->next = parser->active;
+ node = ralloc(parser->active, active_list_t);
+ node->identifier = ralloc_strdup(node, identifier);
+ node->marker = marker;
+ node->next = parser->active;
- parser->active = node;
+ parser->active = node;
}
static void
-_parser_active_list_pop (glcpp_parser_t *parser)
+_parser_active_list_pop(glcpp_parser_t *parser)
{
- active_list_t *node = parser->active;
+ active_list_t *node = parser->active;
- if (node == NULL) {
- parser->active = NULL;
- return;
- }
+ if (node == NULL) {
+ parser->active = NULL;
+ return;
+ }
- node = parser->active->next;
- ralloc_free (parser->active);
+ node = parser->active->next;
+ ralloc_free (parser->active);
- parser->active = node;
+ parser->active = node;
}
static int
-_parser_active_list_contains (glcpp_parser_t *parser, const char *identifier)
+_parser_active_list_contains(glcpp_parser_t *parser, const char *identifier)
{
- active_list_t *node;
+ active_list_t *node;
- if (parser->active == NULL)
- return 0;
+ if (parser->active == NULL)
+ return 0;
- for (node = parser->active; node; node = node->next)
- if (strcmp (node->identifier, identifier) == 0)
- return 1;
+ for (node = parser->active; node; node = node->next)
+ if (strcmp(node->identifier, identifier) == 0)
+ return 1;
- return 0;
+ return 0;
}
/* Walk over the token list replacing nodes with their expansion.
@@ -1948,400 +1902,376 @@ _parser_active_list_contains (glcpp_parser_t *parser, const char *identifier)
* The "mode" argument controls the handling of any DEFINED tokens that
* result from expansion as follows:
*
- * EXPANSION_MODE_IGNORE_DEFINED: Any resulting DEFINED tokens will be
- * left in the final list, unevaluated. This is the correct mode
- * for expanding any list in any context other than a
- * preprocessor conditional, (#if or #elif).
+ * EXPANSION_MODE_IGNORE_DEFINED: Any resulting DEFINED tokens will be
+ * left in the final list, unevaluated. This is the correct mode
+ * for expanding any list in any context other than a
+ * preprocessor conditional, (#if or #elif).
*
- * EXPANSION_MODE_EVALUATE_DEFINED: Any resulting DEFINED tokens will be
- * evaluated to 0 or 1 tokens depending on whether the following
- * token is the name of a defined macro. If the DEFINED token is
- * not followed by an (optionally parenthesized) identifier, then
- * an error will be generated. This the correct mode for
- * expanding any list in the context of a preprocessor
- * conditional, (#if or #elif).
+ * EXPANSION_MODE_EVALUATE_DEFINED: Any resulting DEFINED tokens will be
+ * evaluated to 0 or 1 tokens depending on whether the following
+ * token is the name of a defined macro. If the DEFINED token is
+ * not followed by an (optionally parenthesized) identifier, then
+ * an error will be generated. This the correct mode for
+ * expanding any list in the context of a preprocessor
+ * conditional, (#if or #elif).
*/
static void
-_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
- token_list_t *list,
- expansion_mode_t mode)
+_glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
+ expansion_mode_t mode)
{
- token_node_t *node_prev;
- token_node_t *node, *last = NULL;
- token_list_t *expansion;
- active_list_t *active_initial = parser->active;
-
- if (list == NULL)
- return;
-
- _token_list_trim_trailing_space (list);
-
- node_prev = NULL;
- node = list->head;
-
- if (mode == EXPANSION_MODE_EVALUATE_DEFINED)
- _glcpp_parser_evaluate_defined_in_list (parser, list);
-
- while (node) {
-
- while (parser->active && parser->active->marker == node)
- _parser_active_list_pop (parser);
-
- expansion = _glcpp_parser_expand_node (parser, node, &last, mode);
- if (expansion) {
- token_node_t *n;
-
- if (mode == EXPANSION_MODE_EVALUATE_DEFINED) {
- _glcpp_parser_evaluate_defined_in_list (parser,
- expansion);
- }
-
- for (n = node; n != last->next; n = n->next)
- while (parser->active &&
- parser->active->marker == n)
- {
- _parser_active_list_pop (parser);
- }
-
- _parser_active_list_push (parser,
- node->token->value.str,
- last->next);
-
- /* Splice expansion into list, supporting a
- * simple deletion if the expansion is
- * empty. */
- if (expansion->head) {
- if (node_prev)
- node_prev->next = expansion->head;
- else
- list->head = expansion->head;
- expansion->tail->next = last->next;
- if (last == list->tail)
- list->tail = expansion->tail;
- } else {
- if (node_prev)
- node_prev->next = last->next;
- else
- list->head = last->next;
- if (last == list->tail)
- list->tail = NULL;
- }
- } else {
- node_prev = node;
- }
- node = node_prev ? node_prev->next : list->head;
- }
-
- /* Remove any lingering effects of this invocation on the
- * active list. That is, pop until the list looks like it did
- * at the beginning of this function. */
- while (parser->active && parser->active != active_initial)
- _parser_active_list_pop (parser);
-
- list->non_space_tail = list->tail;
+ token_node_t *node_prev;
+ token_node_t *node, *last = NULL;
+ token_list_t *expansion;
+ active_list_t *active_initial = parser->active;
+
+ if (list == NULL)
+ return;
+
+ _token_list_trim_trailing_space (list);
+
+ node_prev = NULL;
+ node = list->head;
+
+ if (mode == EXPANSION_MODE_EVALUATE_DEFINED)
+ _glcpp_parser_evaluate_defined_in_list (parser, list);
+
+ while (node) {
+
+ while (parser->active && parser->active->marker == node)
+ _parser_active_list_pop (parser);
+
+ expansion = _glcpp_parser_expand_node (parser, node, &last, mode);
+ if (expansion) {
+ token_node_t *n;
+
+ if (mode == EXPANSION_MODE_EVALUATE_DEFINED) {
+ _glcpp_parser_evaluate_defined_in_list (parser, expansion);
+ }
+
+ for (n = node; n != last->next; n = n->next)
+ while (parser->active && parser->active->marker == n) {
+ _parser_active_list_pop (parser);
+ }
+
+ _parser_active_list_push(parser, node->token->value.str, last->next);
+
+ /* Splice expansion into list, supporting a simple deletion if the
+ * expansion is empty.
+ */
+ if (expansion->head) {
+ if (node_prev)
+ node_prev->next = expansion->head;
+ else
+ list->head = expansion->head;
+ expansion->tail->next = last->next;
+ if (last == list->tail)
+ list->tail = expansion->tail;
+ } else {
+ if (node_prev)
+ node_prev->next = last->next;
+ else
+ list->head = last->next;
+ if (last == list->tail)
+ list->tail = NULL;
+ }
+ } else {
+ node_prev = node;
+ }
+ node = node_prev ? node_prev->next : list->head;
+ }
+
+ /* Remove any lingering effects of this invocation on the
+ * active list. That is, pop until the list looks like it did
+ * at the beginning of this function. */
+ while (parser->active && parser->active != active_initial)
+ _parser_active_list_pop (parser);
+
+ list->non_space_tail = list->tail;
}
void
-_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
- token_list_t *list)
+_glcpp_parser_print_expanded_token_list(glcpp_parser_t *parser,
+ token_list_t *list)
{
- if (list == NULL)
- return;
+ if (list == NULL)
+ return;
- _glcpp_parser_expand_token_list (parser, list, EXPANSION_MODE_IGNORE_DEFINED);
+ _glcpp_parser_expand_token_list (parser, list, EXPANSION_MODE_IGNORE_DEFINED);
- _token_list_trim_trailing_space (list);
+ _token_list_trim_trailing_space (list);
- _token_list_print (parser, list);
+ _token_list_print (parser, list);
}
static void
-_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
- const char *identifier)
+_check_for_reserved_macro_name(glcpp_parser_t *parser, YYLTYPE *loc,
+ const char *identifier)
{
- /* Section 3.3 (Preprocessor) of the GLSL 1.30 spec (and later) and
- * the GLSL ES spec (all versions) say:
- *
- * "All macro names containing two consecutive underscores ( __ )
- * are reserved for future use as predefined macro names. All
- * macro names prefixed with "GL_" ("GL" followed by a single
- * underscore) are also reserved."
- *
- * The intention is that names containing __ are reserved for internal
- * use by the implementation, and names prefixed with GL_ are reserved
- * for use by Khronos. Since every extension adds a name prefixed
- * with GL_ (i.e., the name of the extension), that should be an
- * error. Names simply containing __ are dangerous to use, but should
- * be allowed.
- *
- * A future version of the GLSL specification will clarify this.
- */
- if (strstr(identifier, "__")) {
- glcpp_warning(loc, parser,
- "Macro names containing \"__\" are reserved "
- "for use by the implementation.\n");
- }
- if (strncmp(identifier, "GL_", 3) == 0) {
- glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
- }
- if (strcmp(identifier, "defined") == 0) {
- glcpp_error (loc, parser, "\"defined\" cannot be used as a macro name");
- }
+ /* Section 3.3 (Preprocessor) of the GLSL 1.30 spec (and later) and
+ * the GLSL ES spec (all versions) say:
+ *
+ * "All macro names containing two consecutive underscores ( __ )
+ * are reserved for future use as predefined macro names. All
+ * macro names prefixed with "GL_" ("GL" followed by a single
+ * underscore) are also reserved."
+ *
+ * The intention is that names containing __ are reserved for internal
+ * use by the implementation, and names prefixed with GL_ are reserved
+ * for use by Khronos. Since every extension adds a name prefixed
+ * with GL_ (i.e., the name of the extension), that should be an
+ * error. Names simply containing __ are dangerous to use, but should
+ * be allowed.
+ *
+ * A future version of the GLSL specification will clarify this.
+ */
+ if (strstr(identifier, "__")) {
+ glcpp_warning(loc, parser, "Macro names containing \"__\" are reserved "
+ "for use by the implementation.\n");
+ }
+ if (strncmp(identifier, "GL_", 3) == 0) {
+ glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
+ }
+ if (strcmp(identifier, "defined") == 0) {
+ glcpp_error (loc, parser, "\"defined\" cannot be used as a macro name");
+ }
}
static int
-_macro_equal (macro_t *a, macro_t *b)
+_macro_equal(macro_t *a, macro_t *b)
{
- if (a->is_function != b->is_function)
- return 0;
+ if (a->is_function != b->is_function)
+ return 0;
- if (a->is_function) {
- if (! _string_list_equal (a->parameters, b->parameters))
- return 0;
- }
+ if (a->is_function) {
+ if (! _string_list_equal (a->parameters, b->parameters))
+ return 0;
+ }
- return _token_list_equal_ignoring_space (a->replacements,
- b->replacements);
+ return _token_list_equal_ignoring_space(a->replacements, b->replacements);
}
void
-_define_object_macro (glcpp_parser_t *parser,
- YYLTYPE *loc,
- const char *identifier,
- token_list_t *replacements)
+_define_object_macro(glcpp_parser_t *parser, YYLTYPE *loc,
+ const char *identifier, token_list_t *replacements)
{
- macro_t *macro, *previous;
-
- /* We define pre-defined macros before we've started parsing the
- * actual file. So if there's no location defined yet, that's what
- * were doing and we don't want to generate an error for using the
- * reserved names. */
- if (loc != NULL)
- _check_for_reserved_macro_name(parser, loc, identifier);
-
- macro = ralloc (parser, macro_t);
-
- macro->is_function = 0;
- macro->parameters = NULL;
- macro->identifier = ralloc_strdup (macro, identifier);
- macro->replacements = replacements;
- ralloc_steal (macro, replacements);
-
- previous = hash_table_find (parser->defines, identifier);
- if (previous) {
- if (_macro_equal (macro, previous)) {
- ralloc_free (macro);
- return;
- }
- glcpp_error (loc, parser, "Redefinition of macro %s\n",
- identifier);
- }
-
- hash_table_insert (parser->defines, macro, identifier);
+ macro_t *macro, *previous;
+
+ /* We define pre-defined macros before we've started parsing the actual
+ * file. So if there's no location defined yet, that's what were doing and
+ * we don't want to generate an error for using the reserved names. */
+ if (loc != NULL)
+ _check_for_reserved_macro_name(parser, loc, identifier);
+
+ macro = ralloc (parser, macro_t);
+
+ macro->is_function = 0;
+ macro->parameters = NULL;
+ macro->identifier = ralloc_strdup (macro, identifier);
+ macro->replacements = replacements;
+ ralloc_steal (macro, replacements);
+
+ previous = hash_table_find (parser->defines, identifier);
+ if (previous) {
+ if (_macro_equal (macro, previous)) {
+ ralloc_free (macro);
+ return;
+ }
+ glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
+ }
+
+ hash_table_insert (parser->defines, macro, identifier);
}
void
-_define_function_macro (glcpp_parser_t *parser,
- YYLTYPE *loc,
- const char *identifier,
- string_list_t *parameters,
- token_list_t *replacements)
+_define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc,
+ const char *identifier, string_list_t *parameters,
+ token_list_t *replacements)
{
- macro_t *macro, *previous;
- const char *dup;
+ macro_t *macro, *previous;
+ const char *dup;
- _check_for_reserved_macro_name(parser, loc, identifier);
+ _check_for_reserved_macro_name(parser, loc, identifier);
/* Check for any duplicate parameter names. */
- if ((dup = _string_list_has_duplicate (parameters)) != NULL) {
- glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"",
- dup);
- }
-
- macro = ralloc (parser, macro_t);
- ralloc_steal (macro, parameters);
- ralloc_steal (macro, replacements);
-
- macro->is_function = 1;
- macro->parameters = parameters;
- macro->identifier = ralloc_strdup (macro, identifier);
- macro->replacements = replacements;
- previous = hash_table_find (parser->defines, identifier);
- if (previous) {
- if (_macro_equal (macro, previous)) {
- ralloc_free (macro);
- return;
- }
- glcpp_error (loc, parser, "Redefinition of macro %s\n",
- identifier);
- }
-
- hash_table_insert (parser->defines, macro, identifier);
+ if ((dup = _string_list_has_duplicate (parameters)) != NULL) {
+ glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
+ }
+
+ macro = ralloc (parser, macro_t);
+ ralloc_steal (macro, parameters);
+ ralloc_steal (macro, replacements);
+
+ macro->is_function = 1;
+ macro->parameters = parameters;
+ macro->identifier = ralloc_strdup (macro, identifier);
+ macro->replacements = replacements;
+ previous = hash_table_find (parser->defines, identifier);
+ if (previous) {
+ if (_macro_equal (macro, previous)) {
+ ralloc_free (macro);
+ return;
+ }
+ glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
+ }
+
+ hash_table_insert(parser->defines, macro, identifier);
}
static int
-glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
+glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
{
- token_node_t *node;
- int ret;
-
- if (parser->lex_from_list == NULL) {
- ret = glcpp_lex (yylval, yylloc, parser->scanner);
-
- /* XXX: This ugly block of code exists for the sole
- * purpose of converting a NEWLINE token into a SPACE
- * token, but only in the case where we have seen a
- * function-like macro name, but have not yet seen its
- * closing parenthesis.
- *
- * There's perhaps a more compact way to do this with
- * mid-rule actions in the grammar.
- *
- * I'm definitely not pleased with the complexity of
- * this code here.
- */
- if (parser->newline_as_space)
- {
- if (ret == '(') {
- parser->paren_count++;
- } else if (ret == ')') {
- parser->paren_count--;
- if (parser->paren_count == 0)
- parser->newline_as_space = 0;
- } else if (ret == NEWLINE) {
- ret = SPACE;
- } else if (ret != SPACE) {
- if (parser->paren_count == 0)
- parser->newline_as_space = 0;
- }
- }
- else if (parser->in_control_line)
- {
- if (ret == NEWLINE)
- parser->in_control_line = 0;
- }
- else if (ret == DEFINE_TOKEN ||
- ret == UNDEF || ret == IF ||
- ret == IFDEF || ret == IFNDEF ||
- ret == ELIF || ret == ELSE ||
- ret == ENDIF || ret == HASH_TOKEN)
- {
- parser->in_control_line = 1;
- }
- else if (ret == IDENTIFIER)
- {
- macro_t *macro;
- macro = hash_table_find (parser->defines,
- yylval->str);
- if (macro && macro->is_function) {
- parser->newline_as_space = 1;
- parser->paren_count = 0;
- }
- }
-
- return ret;
- }
-
- node = parser->lex_from_node;
-
- if (node == NULL) {
- ralloc_free (parser->lex_from_list);
- parser->lex_from_list = NULL;
- return NEWLINE;
- }
-
- *yylval = node->token->value;
- ret = node->token->type;
-
- parser->lex_from_node = node->next;
-
- return ret;
+ token_node_t *node;
+ int ret;
+
+ if (parser->lex_from_list == NULL) {
+ ret = glcpp_lex(yylval, yylloc, parser->scanner);
+
+ /* XXX: This ugly block of code exists for the sole
+ * purpose of converting a NEWLINE token into a SPACE
+ * token, but only in the case where we have seen a
+ * function-like macro name, but have not yet seen its
+ * closing parenthesis.
+ *
+ * There's perhaps a more compact way to do this with
+ * mid-rule actions in the grammar.
+ *
+ * I'm definitely not pleased with the complexity of
+ * this code here.
+ */
+ if (parser->newline_as_space) {
+ if (ret == '(') {
+ parser->paren_count++;
+ } else if (ret == ')') {
+ parser->paren_count--;
+ if (parser->paren_count == 0)
+ parser->newline_as_space = 0;
+ } else if (ret == NEWLINE) {
+ ret = SPACE;
+ } else if (ret != SPACE) {
+ if (parser->paren_count == 0)
+ parser->newline_as_space = 0;
+ }
+ } else if (parser->in_control_line) {
+ if (ret == NEWLINE)
+ parser->in_control_line = 0;
+ }
+ else if (ret == DEFINE_TOKEN || ret == UNDEF || ret == IF ||
+ ret == IFDEF || ret == IFNDEF || ret == ELIF || ret == ELSE ||
+ ret == ENDIF || ret == HASH_TOKEN) {
+ parser->in_control_line = 1;
+ } else if (ret == IDENTIFIER) {
+ macro_t *macro;
+ macro = hash_table_find (parser->defines,
+ yylval->str);
+ if (macro && macro->is_function) {
+ parser->newline_as_space = 1;
+ parser->paren_count = 0;
+ }
+ }
+
+ return ret;
+ }
+
+ node = parser->lex_from_node;
+
+ if (node == NULL) {
+ ralloc_free (parser->lex_from_list);
+ parser->lex_from_list = NULL;
+ return NEWLINE;
+ }
+
+ *yylval = node->token->value;
+ ret = node->token->type;
+
+ parser->lex_from_node = node->next;
+
+ return ret;
}
static void
-glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
+glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list)
{
- token_node_t *node;
+ token_node_t *node;
- assert (parser->lex_from_list == NULL);
+ assert (parser->lex_from_list == NULL);
- /* Copy list, eliminating any space tokens. */
- parser->lex_from_list = _token_list_create (parser);
+ /* Copy list, eliminating any space tokens. */
+ parser->lex_from_list = _token_list_create (parser);
- for (node = list->head; node; node = node->next) {
- if (node->token->type == SPACE)
- continue;
- _token_list_append (parser->lex_from_list, node->token);
- }
+ for (node = list->head; node; node = node->next) {
+ if (node->token->type == SPACE)
+ continue;
+ _token_list_append (parser->lex_from_list, node->token);
+ }
- ralloc_free (list);
+ ralloc_free (list);
- parser->lex_from_node = parser->lex_from_list->head;
+ parser->lex_from_node = parser->lex_from_list->head;
- /* It's possible the list consisted of nothing but whitespace. */
- if (parser->lex_from_node == NULL) {
- ralloc_free (parser->lex_from_list);
- parser->lex_from_list = NULL;
- }
+ /* It's possible the list consisted of nothing but whitespace. */
+ if (parser->lex_from_node == NULL) {
+ ralloc_free (parser->lex_from_list);
+ parser->lex_from_list = NULL;
+ }
}
static void
-_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
- int condition)
+_glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
+ int condition)
{
- skip_type_t current = SKIP_NO_SKIP;
- skip_node_t *node;
-
- if (parser->skip_stack)
- current = parser->skip_stack->type;
-
- node = ralloc (parser, skip_node_t);
- node->loc = *loc;
-
- if (current == SKIP_NO_SKIP) {
- if (condition)
- node->type = SKIP_NO_SKIP;
- else
- node->type = SKIP_TO_ELSE;
- } else {
- node->type = SKIP_TO_ENDIF;
- }
-
- node->has_else = false;
- node->next = parser->skip_stack;
- parser->skip_stack = node;
+ skip_type_t current = SKIP_NO_SKIP;
+ skip_node_t *node;
+
+ if (parser->skip_stack)
+ current = parser->skip_stack->type;
+
+ node = ralloc (parser, skip_node_t);
+ node->loc = *loc;
+
+ if (current == SKIP_NO_SKIP) {
+ if (condition)
+ node->type = SKIP_NO_SKIP;
+ else
+ node->type = SKIP_TO_ELSE;
+ } else {
+ node->type = SKIP_TO_ENDIF;
+ }
+
+ node->has_else = false;
+ node->next = parser->skip_stack;
+ parser->skip_stack = node;
}
static void
-_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
- const char *type, int condition)
+_glcpp_parser_skip_stack_change_if(glcpp_parser_t *parser, YYLTYPE *loc,
+ const char *type, int condition)
{
- if (parser->skip_stack == NULL) {
- glcpp_error (loc, parser, "#%s without #if\n", type);
- return;
- }
-
- if (parser->skip_stack->type == SKIP_TO_ELSE) {
- if (condition)
- parser->skip_stack->type = SKIP_NO_SKIP;
- } else {
- parser->skip_stack->type = SKIP_TO_ENDIF;
- }
+ if (parser->skip_stack == NULL) {
+ glcpp_error (loc, parser, "#%s without #if\n", type);
+ return;
+ }
+
+ if (parser->skip_stack->type == SKIP_TO_ELSE) {
+ if (condition)
+ parser->skip_stack->type = SKIP_NO_SKIP;
+ } else {
+ parser->skip_stack->type = SKIP_TO_ENDIF;
+ }
}
static void
-_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
+_glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc)
{
- skip_node_t *node;
+ skip_node_t *node;
- if (parser->skip_stack == NULL) {
- glcpp_error (loc, parser, "#endif without #if\n");
- return;
- }
+ if (parser->skip_stack == NULL) {
+ glcpp_error (loc, parser, "#endif without #if\n");
+ return;
+ }
- node = parser->skip_stack;
- parser->skip_stack = node->next;
- ralloc_free (node);
+ node = parser->skip_stack;
+ parser->skip_stack = node->next;
+ ralloc_free (node);
}
static void
@@ -2349,210 +2279,212 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
const char *es_identifier,
bool explicitly_set)
{
- const struct gl_extensions *extensions = parser->extensions;
-
- if (parser->version_resolved)
- return;
-
- parser->version_resolved = true;
-
- add_builtin_define (parser, "__VERSION__", version);
-
- parser->is_gles = (version == 100) ||
- (es_identifier &&
- (strcmp(es_identifier, "es") == 0));
-
- /* Add pre-defined macros. */
- if (parser->is_gles) {
- add_builtin_define(parser, "GL_ES", 1);
- add_builtin_define(parser, "GL_EXT_separate_shader_objects", 1);
- add_builtin_define(parser, "GL_EXT_draw_buffers", 1);
-
- if (extensions != NULL) {
- if (extensions->OES_EGL_image_external)
- add_builtin_define(parser, "GL_OES_EGL_image_external", 1);
- if (extensions->OES_sample_variables) {
- add_builtin_define(parser, "GL_OES_sample_variables", 1);
- add_builtin_define(parser, "GL_OES_shader_multisample_interpolation", 1);
- }
- if (extensions->OES_standard_derivatives)
- add_builtin_define(parser, "GL_OES_standard_derivatives", 1);
- if (extensions->ARB_texture_multisample)
- add_builtin_define(parser, "GL_OES_texture_storage_multisample_2d_array", 1);
- if (extensions->ARB_blend_func_extended)
- add_builtin_define(parser, "GL_EXT_blend_func_extended", 1);
-
- if (version >= 310) {
- if (extensions->ARB_shader_image_load_store)
- add_builtin_define(parser, "GL_OES_shader_image_atomic", 1);
+ const struct gl_extensions *extensions = parser->extensions;
+
+ if (parser->version_resolved)
+ return;
+
+ parser->version_resolved = true;
+
+ add_builtin_define (parser, "__VERSION__", version);
+
+ parser->is_gles = (version == 100) ||
+ (es_identifier && (strcmp(es_identifier, "es") == 0));
+
+ /* Add pre-defined macros. */
+ if (parser->is_gles) {
+ add_builtin_define(parser, "GL_ES", 1);
+ add_builtin_define(parser, "GL_EXT_separate_shader_objects", 1);
+ add_builtin_define(parser, "GL_EXT_draw_buffers", 1);
+
+ if (extensions != NULL) {
+ if (extensions->OES_EGL_image_external)
+ add_builtin_define(parser, "GL_OES_EGL_image_external", 1);
+ if (extensions->OES_sample_variables) {
+ add_builtin_define(parser, "GL_OES_sample_variables", 1);
+ add_builtin_define(parser, "GL_OES_shader_multisample_interpolation", 1);
+ }
+ if (extensions->OES_standard_derivatives)
+ add_builtin_define(parser, "GL_OES_standard_derivatives", 1);
+ if (extensions->ARB_texture_multisample)
+ add_builtin_define(parser, "GL_OES_texture_storage_multisample_2d_array", 1);
+ if (extensions->ARB_blend_func_extended)
+ add_builtin_define(parser, "GL_EXT_blend_func_extended", 1);
+
+ if (version >= 310) {
+ if (extensions->ARB_shader_image_load_store)
+ add_builtin_define(parser, "GL_OES_shader_image_atomic", 1);
+
+ if (extensions->OES_geometry_shader) {
+ add_builtin_define(parser, "GL_OES_geometry_point_size", 1);
+ add_builtin_define(parser, "GL_OES_geometry_shader", 1);
+ }
+ if (extensions->ARB_gpu_shader5) {
+ add_builtin_define(parser, "GL_EXT_gpu_shader5", 1);
+ add_builtin_define(parser, "GL_OES_gpu_shader5", 1);
+ }
+ if (extensions->OES_texture_buffer) {
+ add_builtin_define(parser, "GL_EXT_texture_buffer", 1);
+ add_builtin_define(parser, "GL_OES_texture_buffer", 1);
+ }
+ }
+ }
+ } else {
+ add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
+ add_builtin_define(parser, "GL_ARB_enhanced_layouts", 1);
+ add_builtin_define(parser, "GL_ARB_separate_shader_objects", 1);
+ add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
+ add_builtin_define(parser, "GL_AMD_shader_trinary_minmax", 1);
- if (extensions->OES_geometry_shader) {
- add_builtin_define(parser, "GL_OES_geometry_point_size", 1);
- add_builtin_define(parser, "GL_OES_geometry_shader", 1);
- }
- if (extensions->ARB_gpu_shader5) {
- add_builtin_define(parser, "GL_EXT_gpu_shader5", 1);
- add_builtin_define(parser, "GL_OES_gpu_shader5", 1);
- }
- if (extensions->OES_texture_buffer) {
- add_builtin_define(parser, "GL_EXT_texture_buffer", 1);
- add_builtin_define(parser, "GL_OES_texture_buffer", 1);
- }
- }
- }
- } else {
- add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
- add_builtin_define(parser, "GL_ARB_enhanced_layouts", 1);
- add_builtin_define(parser, "GL_ARB_separate_shader_objects", 1);
- add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
- add_builtin_define(parser, "GL_AMD_shader_trinary_minmax", 1);
+ if (extensions != NULL) {
+ if (extensions->EXT_texture_array)
+ add_builtin_define(parser, "GL_EXT_texture_array", 1);
+ if (extensions->ARB_ES3_1_compatibility)
+ add_builtin_define(parser, "GL_ARB_ES3_1_compatibility", 1);
- if (extensions != NULL) {
- if (extensions->EXT_texture_array)
- add_builtin_define(parser, "GL_EXT_texture_array", 1);
+ if (extensions->ARB_arrays_of_arrays)
+ add_builtin_define(parser, "GL_ARB_arrays_of_arrays", 1);
- if (extensions->ARB_arrays_of_arrays)
- add_builtin_define(parser, "GL_ARB_arrays_of_arrays", 1);
+ if (extensions->ARB_fragment_coord_conventions) {
+ add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
+ 1);
+ }
- if (extensions->ARB_fragment_coord_conventions)
- add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
- 1);
+ if (extensions->ARB_fragment_layer_viewport)
+ add_builtin_define(parser, "GL_ARB_fragment_layer_viewport", 1);
- if (extensions->ARB_fragment_layer_viewport)
- add_builtin_define(parser, "GL_ARB_fragment_layer_viewport", 1);
+ if (extensions->ARB_explicit_attrib_location)
+ add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
- if (extensions->ARB_explicit_attrib_location)
- add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
+ if (extensions->ARB_explicit_uniform_location)
+ add_builtin_define(parser, "GL_ARB_explicit_uniform_location", 1);
- if (extensions->ARB_explicit_uniform_location)
- add_builtin_define(parser, "GL_ARB_explicit_uniform_location", 1);
+ if (extensions->ARB_shader_texture_lod)
+ add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1);
- if (extensions->ARB_shader_texture_lod)
- add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1);
+ if (extensions->ARB_draw_instanced)
+ add_builtin_define(parser, "GL_ARB_draw_instanced", 1);
- if (extensions->ARB_draw_instanced)
- add_builtin_define(parser, "GL_ARB_draw_instanced", 1);
+ if (extensions->ARB_conservative_depth) {
+ add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
+ add_builtin_define(parser, "GL_ARB_conservative_depth", 1);
+ }
- if (extensions->ARB_conservative_depth) {
- add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
- add_builtin_define(parser, "GL_ARB_conservative_depth", 1);
- }
+ if (extensions->ARB_shader_bit_encoding)
+ add_builtin_define(parser, "GL_ARB_shader_bit_encoding", 1);
- if (extensions->ARB_shader_bit_encoding)
- add_builtin_define(parser, "GL_ARB_shader_bit_encoding", 1);
+ if (extensions->ARB_shader_clock)
+ add_builtin_define(parser, "GL_ARB_shader_clock", 1);
- if (extensions->ARB_shader_clock)
- add_builtin_define(parser, "GL_ARB_shader_clock", 1);
+ if (extensions->ARB_uniform_buffer_object)
+ add_builtin_define(parser, "GL_ARB_uniform_buffer_object", 1);
- if (extensions->ARB_uniform_buffer_object)
- add_builtin_define(parser, "GL_ARB_uniform_buffer_object", 1);
+ if (extensions->ARB_texture_cube_map_array)
+ add_builtin_define(parser, "GL_ARB_texture_cube_map_array", 1);
- if (extensions->ARB_texture_cube_map_array)
- add_builtin_define(parser, "GL_ARB_texture_cube_map_array", 1);
+ if (extensions->ARB_shading_language_packing)
+ add_builtin_define(parser, "GL_ARB_shading_language_packing", 1);
- if (extensions->ARB_shading_language_packing)
- add_builtin_define(parser, "GL_ARB_shading_language_packing", 1);
+ if (extensions->ARB_texture_multisample)
+ add_builtin_define(parser, "GL_ARB_texture_multisample", 1);
+
+ if (extensions->ARB_texture_query_levels)
+ add_builtin_define(parser, "GL_ARB_texture_query_levels", 1);
+
+ if (extensions->ARB_texture_query_lod)
+ add_builtin_define(parser, "GL_ARB_texture_query_lod", 1);
- if (extensions->ARB_texture_multisample)
- add_builtin_define(parser, "GL_ARB_texture_multisample", 1);
+ if (extensions->ARB_gpu_shader5)
+ add_builtin_define(parser, "GL_ARB_gpu_shader5", 1);
+
+ if (extensions->ARB_gpu_shader_fp64)
+ add_builtin_define(parser, "GL_ARB_gpu_shader_fp64", 1);
- if (extensions->ARB_texture_query_levels)
- add_builtin_define(parser, "GL_ARB_texture_query_levels", 1);
+ if (extensions->ARB_vertex_attrib_64bit)
+ add_builtin_define(parser, "GL_ARB_vertex_attrib_64bit", 1);
- if (extensions->ARB_texture_query_lod)
- add_builtin_define(parser, "GL_ARB_texture_query_lod", 1);
+ if (extensions->AMD_vertex_shader_layer)
+ add_builtin_define(parser, "GL_AMD_vertex_shader_layer", 1);
- if (extensions->ARB_gpu_shader5)
- add_builtin_define(parser, "GL_ARB_gpu_shader5", 1);
+ if (extensions->AMD_vertex_shader_viewport_index)
+ add_builtin_define(parser, "GL_AMD_vertex_shader_viewport_index", 1);
- if (extensions->ARB_gpu_shader_fp64)
- add_builtin_define(parser, "GL_ARB_gpu_shader_fp64", 1);
+ if (extensions->ARB_shading_language_420pack)
+ add_builtin_define(parser, "GL_ARB_shading_language_420pack", 1);
- if (extensions->ARB_vertex_attrib_64bit)
- add_builtin_define(parser, "GL_ARB_vertex_attrib_64bit", 1);
+ if (extensions->ARB_sample_shading)
+ add_builtin_define(parser, "GL_ARB_sample_shading", 1);
- if (extensions->AMD_vertex_shader_layer)
- add_builtin_define(parser, "GL_AMD_vertex_shader_layer", 1);
+ if (extensions->ARB_texture_gather)
+ add_builtin_define(parser, "GL_ARB_texture_gather", 1);
- if (extensions->AMD_vertex_shader_viewport_index)
- add_builtin_define(parser, "GL_AMD_vertex_shader_viewport_index", 1);
+ if (extensions->ARB_shader_atomic_counters)
+ add_builtin_define(parser, "GL_ARB_shader_atomic_counters", 1);
- if (extensions->ARB_shading_language_420pack)
- add_builtin_define(parser, "GL_ARB_shading_language_420pack", 1);
+ if (extensions->ARB_shader_atomic_counter_ops)
+ add_builtin_define(parser, "GL_ARB_shader_atomic_counter_ops", 1);
- if (extensions->ARB_sample_shading)
- add_builtin_define(parser, "GL_ARB_sample_shading", 1);
+ if (extensions->ARB_viewport_array)
+ add_builtin_define(parser, "GL_ARB_viewport_array", 1);
- if (extensions->ARB_texture_gather)
- add_builtin_define(parser, "GL_ARB_texture_gather", 1);
+ if (extensions->ARB_compute_shader)
+ add_builtin_define(parser, "GL_ARB_compute_shader", 1);
- if (extensions->ARB_shader_atomic_counters)
- add_builtin_define(parser, "GL_ARB_shader_atomic_counters", 1);
+ if (extensions->ARB_shader_image_load_store)
+ add_builtin_define(parser, "GL_ARB_shader_image_load_store", 1);
- if (extensions->ARB_shader_atomic_counter_ops)
- add_builtin_define(parser, "GL_ARB_shader_atomic_counter_ops", 1);
+ if (extensions->ARB_shader_image_size)
+ add_builtin_define(parser, "GL_ARB_shader_image_size", 1);
- if (extensions->ARB_viewport_array)
- add_builtin_define(parser, "GL_ARB_viewport_array", 1);
+ if (extensions->ARB_shader_texture_image_samples)
+ add_builtin_define(parser, "GL_ARB_shader_texture_image_samples", 1);
- if (extensions->ARB_compute_shader)
- add_builtin_define(parser, "GL_ARB_compute_shader", 1);
+ if (extensions->ARB_derivative_control)
+ add_builtin_define(parser, "GL_ARB_derivative_control", 1);
- if (extensions->ARB_shader_image_load_store)
- add_builtin_define(parser, "GL_ARB_shader_image_load_store", 1);
+ if (extensions->ARB_shader_precision)
+ add_builtin_define(parser, "GL_ARB_shader_precision", 1);
- if (extensions->ARB_shader_image_size)
- add_builtin_define(parser, "GL_ARB_shader_image_size", 1);
+ if (extensions->ARB_shader_storage_buffer_object)
+ add_builtin_define(parser, "GL_ARB_shader_storage_buffer_object", 1);
- if (extensions->ARB_shader_texture_image_samples)
- add_builtin_define(parser, "GL_ARB_shader_texture_image_samples", 1);
+ if (extensions->ARB_tessellation_shader)
+ add_builtin_define(parser, "GL_ARB_tessellation_shader", 1);
- if (extensions->ARB_derivative_control)
- add_builtin_define(parser, "GL_ARB_derivative_control", 1);
+ if (extensions->ARB_shader_subroutine)
+ add_builtin_define(parser, "GL_ARB_shader_subroutine", 1);
- if (extensions->ARB_shader_precision)
- add_builtin_define(parser, "GL_ARB_shader_precision", 1);
+ if (extensions->ARB_shader_draw_parameters)
+ add_builtin_define(parser, "GL_ARB_shader_draw_parameters", 1);
+ }
+ }
- if (extensions->ARB_shader_storage_buffer_object)
- add_builtin_define(parser, "GL_ARB_shader_storage_buffer_object", 1);
+ if (extensions != NULL) {
+ if (extensions->EXT_shader_integer_mix)
+ add_builtin_define(parser, "GL_EXT_shader_integer_mix", 1);
- if (extensions->ARB_tessellation_shader)
- add_builtin_define(parser, "GL_ARB_tessellation_shader", 1);
+ if (extensions->EXT_shader_samples_identical)
+ add_builtin_define(parser, "GL_EXT_shader_samples_identical", 1);
+ }
- if (extensions->ARB_shader_subroutine)
- add_builtin_define(parser, "GL_ARB_shader_subroutine", 1);
+ if (version >= 150)
+ add_builtin_define(parser, "GL_core_profile", 1);
- if (extensions->ARB_shader_draw_parameters)
- add_builtin_define(parser, "GL_ARB_shader_draw_parameters", 1);
- }
- }
-
- if (extensions != NULL) {
- if (extensions->EXT_shader_integer_mix)
- add_builtin_define(parser, "GL_EXT_shader_integer_mix", 1);
+ /* Currently, all ES2/ES3 implementations support highp in the
+ * fragment shader, so we always define this macro in ES2/ES3.
+ * If we ever get a driver that doesn't support highp, we'll
+ * need to add a flag to the gl_context and check that here.
+ */
+ if (version >= 130 || parser->is_gles)
+ add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
- if (extensions->EXT_shader_samples_identical)
- add_builtin_define(parser, "GL_EXT_shader_samples_identical", 1);
- }
-
- if (version >= 150)
- add_builtin_define(parser, "GL_core_profile", 1);
-
- /* Currently, all ES2/ES3 implementations support highp in the
- * fragment shader, so we always define this macro in ES2/ES3.
- * If we ever get a driver that doesn't support highp, we'll
- * need to add a flag to the gl_context and check that here.
- */
- if (version >= 130 || parser->is_gles)
- add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
-
- if (explicitly_set) {
- ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length,
- "#version %" PRIiMAX "%s%s", version,
- es_identifier ? " " : "",
- es_identifier ? es_identifier : "");
- }
+ if (explicitly_set) {
+ ralloc_asprintf_rewrite_tail(&parser->output, &parser->output_length,
+ "#version %" PRIiMAX "%s%s", version,
+ es_identifier ? " " : "",
+ es_identifier ? es_identifier : "");
+ }
}
/* GLSL version if no version is explicitly specified. */
@@ -2564,10 +2496,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
void
glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser)
{
- int language_version = parser->api == API_OPENGLES2 ?
- IMPLICIT_GLSL_ES_VERSION :
- IMPLICIT_GLSL_VERSION;
+ int language_version = parser->api == API_OPENGLES2 ?
+ IMPLICIT_GLSL_ES_VERSION : IMPLICIT_GLSL_VERSION;
- _glcpp_parser_handle_version_declaration(parser, language_version,
- NULL, false);
+ _glcpp_parser_handle_version_declaration(parser, language_version,
+ NULL, false);
}
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 3dc68741902..76321aac921 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -226,7 +226,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
this->supported_versions[this->num_supported_versions].es = true;
this->num_supported_versions++;
}
- if (_mesa_is_gles31(ctx)) {
+ if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility) {
this->supported_versions[this->num_supported_versions].ver = 310;
this->supported_versions[this->num_supported_versions].es = true;
this->num_supported_versions++;
@@ -565,6 +565,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
/* ARB extensions go here, sorted alphabetically.
*/
+ EXT(ARB_ES3_1_compatibility, true, false, ARB_ES3_1_compatibility),
EXT(ARB_arrays_of_arrays, true, false, ARB_arrays_of_arrays),
EXT(ARB_compute_shader, true, false, ARB_compute_shader),
EXT(ARB_conservative_depth, true, false, ARB_conservative_depth),
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index 0cc2d259f3a..c774fbea05a 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -510,6 +510,8 @@ struct _mesa_glsl_parse_state {
/*@{*/
/* ARB extensions go here, sorted alphabetically.
*/
+ bool ARB_ES3_1_compatibility_enable;
+ bool ARB_ES3_1_compatibility_warn;
bool ARB_arrays_of_arrays_enable;
bool ARB_arrays_of_arrays_warn;
bool ARB_compute_shader_enable;
diff --git a/src/compiler/glsl/ir_print_visitor.cpp b/src/compiler/glsl/ir_print_visitor.cpp
index 960b23fe0ed..e06acce782a 100644
--- a/src/compiler/glsl/ir_print_visitor.cpp
+++ b/src/compiler/glsl/ir_print_visitor.cpp
@@ -173,6 +173,7 @@ void ir_print_visitor::visit(ir_variable *ir)
const char *const samp = (ir->data.sample) ? "sample " : "";
const char *const patc = (ir->data.patch) ? "patch " : "";
const char *const inv = (ir->data.invariant) ? "invariant " : "";
+ const char *const prec = (ir->data.precise) ? "precise " : "";
const char *const mode[] = { "", "uniform ", "shader_storage ",
"shader_shared ", "shader_in ", "shader_out ",
"in ", "out ", "inout ",
@@ -182,8 +183,8 @@ void ir_print_visitor::visit(ir_variable *ir)
const char *const interp[] = { "", "smooth", "flat", "noperspective" };
STATIC_ASSERT(ARRAY_SIZE(interp) == INTERP_QUALIFIER_COUNT);
- fprintf(f, "(%s%s%s%s%s%s%s%s) ",
- loc, cent, samp, patc, inv, mode[ir->data.mode],
+ fprintf(f, "(%s%s%s%s%s%s%s%s%s) ",
+ loc, cent, samp, patc, inv, prec, mode[ir->data.mode],
stream[ir->data.stream],
interp[ir->data.interpolation]);
diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
index 870bc5bfebd..e5edf2e72e4 100644
--- a/src/compiler/glsl/link_uniform_initializers.cpp
+++ b/src/compiler/glsl/link_uniform_initializers.cpp
@@ -44,18 +44,6 @@ get_storage(gl_uniform_storage *storage, unsigned num_storage,
return NULL;
}
-static unsigned
-get_uniform_block_index(const gl_shader_program *shProg,
- const char *uniformBlockName)
-{
- for (unsigned i = 0; i < shProg->NumBufferInterfaceBlocks; i++) {
- if (!strcmp(shProg->BufferInterfaceBlocks[i].Name, uniformBlockName))
- return i;
- }
-
- return GL_INVALID_INDEX;
-}
-
void
copy_constant_to_storage(union gl_constant_value *storage,
const ir_constant *val,
@@ -168,22 +156,14 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
void
set_block_binding(gl_shader_program *prog, const char *block_name, int binding)
{
- const unsigned block_index = get_uniform_block_index(prog, block_name);
-
- if (block_index == GL_INVALID_INDEX) {
- assert(block_index != GL_INVALID_INDEX);
- return;
+ for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
+ if (!strcmp(prog->BufferInterfaceBlocks[i].Name, block_name)) {
+ prog->BufferInterfaceBlocks[i].Binding = binding;
+ return;
+ }
}
- /* This is a field of a UBO. val is the binding index. */
- for (int i = 0; i < MESA_SHADER_STAGES; i++) {
- int stage_index = prog->InterfaceBlockStageIndex[i][block_index];
-
- if (stage_index != -1) {
- struct gl_shader *sh = prog->_LinkedShaders[i];
- sh->BufferInterfaceBlocks[stage_index]->Binding = binding;
- }
- }
+ unreachable("Failed to initialize block binding");
}
void
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 0a230cad034..7d8a4b4fb79 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -282,7 +282,7 @@ public:
: num_active_uniforms(0), num_hidden_uniforms(0), num_values(0),
num_shader_samplers(0), num_shader_images(0),
num_shader_uniform_components(0), num_shader_subroutines(0),
- is_ubo_var(false), is_shader_storage(false), map(map),
+ is_buffer_block(false), is_shader_storage(false), map(map),
hidden_map(hidden_map)
{
/* empty */
@@ -299,7 +299,7 @@ public:
void process(ir_variable *var)
{
this->current_var = var;
- this->is_ubo_var = var->is_in_buffer_block();
+ this->is_buffer_block = var->is_in_buffer_block();
this->is_shader_storage = var->is_in_shader_storage_block();
if (var->is_interface_instance())
program_resource_visitor::process(var->get_interface_type(),
@@ -340,7 +340,7 @@ public:
*/
unsigned num_shader_subroutines;
- bool is_ubo_var;
+ bool is_buffer_block;
bool is_shader_storage;
struct string_to_uint_map *map;
@@ -380,7 +380,7 @@ private:
* Note that samplers do not count against this limit because they
* don't use any storage on current hardware.
*/
- if (!is_ubo_var && !is_shader_storage)
+ if (!is_buffer_block)
this->num_shader_uniform_components += values;
}
@@ -460,30 +460,33 @@ public:
field_counter = 0;
this->record_next_sampler = new string_to_uint_map;
- ubo_block_index = -1;
+ buffer_block_index = -1;
if (var->is_in_buffer_block()) {
+ struct gl_uniform_block **blks = var->is_in_shader_storage_block() ?
+ prog->ShaderStorageBlocks : prog->UniformBlocks;
+ unsigned num_blks = var->is_in_shader_storage_block() ?
+ prog->NumShaderStorageBlocks : prog->NumUniformBlocks;
+
if (var->is_interface_instance() && var->type->is_array()) {
unsigned l = strlen(var->get_interface_type()->name);
- for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
- if (strncmp(var->get_interface_type()->name,
- prog->BufferInterfaceBlocks[i].Name,
- l) == 0
- && prog->BufferInterfaceBlocks[i].Name[l] == '[') {
- ubo_block_index = i;
+ for (unsigned i = 0; i < num_blks; i++) {
+ if (strncmp(var->get_interface_type()->name, blks[i]->Name, l)
+ == 0 && blks[i]->Name[l] == '[') {
+ buffer_block_index = i;
break;
}
}
} else {
- for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
- if (strcmp(var->get_interface_type()->name,
- prog->BufferInterfaceBlocks[i].Name) == 0) {
- ubo_block_index = i;
+ for (unsigned i = 0; i < num_blks; i++) {
+ if (strcmp(var->get_interface_type()->name, blks[i]->Name) ==
+ 0) {
+ buffer_block_index = i;
break;
}
}
}
- assert(ubo_block_index != -1);
+ assert(buffer_block_index != -1);
/* Uniform blocks that were specified with an instance name must be
* handled a little bit differently. The name of the variable is the
@@ -497,7 +500,7 @@ public:
var->get_interface_type()->name);
} else {
const struct gl_uniform_block *const block =
- &prog->BufferInterfaceBlocks[ubo_block_index];
+ blks[buffer_block_index];
assert(var->data.location != -1);
@@ -519,7 +522,7 @@ public:
delete this->record_next_sampler;
}
- int ubo_block_index;
+ int buffer_block_index;
int ubo_byte_offset;
gl_shader_stage shader_type;
@@ -659,7 +662,7 @@ private:
virtual void enter_record(const glsl_type *type, const char *,
bool row_major, const unsigned packing) {
assert(type->is_record());
- if (this->ubo_block_index == -1)
+ if (this->buffer_block_index == -1)
return;
if (packing == GLSL_INTERFACE_PACKING_STD430)
this->ubo_byte_offset = glsl_align(
@@ -672,7 +675,7 @@ private:
virtual void leave_record(const glsl_type *type, const char *,
bool row_major, const unsigned packing) {
assert(type->is_record());
- if (this->ubo_block_index == -1)
+ if (this->buffer_block_index == -1)
return;
if (packing == GLSL_INTERFACE_PACKING_STD430)
this->ubo_byte_offset = glsl_align(
@@ -719,7 +722,7 @@ private:
/* For array of arrays or struct arrays the base location may have
* already been set so don't set it again.
*/
- if (ubo_block_index == -1 && current_var->data.location == -1) {
+ if (buffer_block_index == -1 && current_var->data.location == -1) {
current_var->data.location = id;
}
@@ -766,8 +769,8 @@ private:
this->uniforms[id].is_shader_storage =
current_var->is_in_shader_storage_block();
- if (this->ubo_block_index != -1) {
- this->uniforms[id].block_index = this->ubo_block_index;
+ if (this->buffer_block_index != -1) {
+ this->uniforms[id].block_index = this->buffer_block_index;
unsigned alignment = type->std140_base_alignment(row_major);
if (packing == GLSL_INTERFACE_PACKING_STD430)
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 848668c4381..e9d0067459a 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -240,7 +240,16 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
/* Check that all of the qualifiers match between stages.
*/
- if (input->data.centroid != output->data.centroid) {
+
+ /* According to the OpenGL and OpenGLES GLSL specs, the centroid qualifier
+ * should match until OpenGL 4.3 and OpenGLES 3.1. The OpenGLES 3.0
+ * conformance test suite does not verify that the qualifiers must match.
+ * The deqp test suite expects the opposite (OpenGLES 3.1) behavior for
+ * OpenGLES 3.0 drivers, so we relax the checking in all cases.
+ */
+ if (false /* always skip the centroid check */ &&
+ prog->Version < (prog->IsES ? 310 : 430) &&
+ input->data.centroid != output->data.centroid) {
linker_error(prog,
"%s shader output `%s' %s centroid qualifier, "
"but %s shader input %s centroid qualifier\n",
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 510a22e5bd3..d9a681ccca1 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -1171,6 +1171,8 @@ cross_validate_uniforms(struct gl_shader_program *prog)
static bool
interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog)
{
+ int *InterfaceBlockStageIndex[MESA_SHADER_STAGES];
+
unsigned max_num_uniform_blocks = 0;
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
if (prog->_LinkedShaders[i])
@@ -1180,10 +1182,9 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog)
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_shader *sh = prog->_LinkedShaders[i];
- prog->InterfaceBlockStageIndex[i] = ralloc_array(prog, int,
- max_num_uniform_blocks);
+ InterfaceBlockStageIndex[i] = new int[max_num_uniform_blocks];
for (unsigned int j = 0; j < max_num_uniform_blocks; j++)
- prog->InterfaceBlockStageIndex[i][j] = -1;
+ InterfaceBlockStageIndex[i][j] = -1;
if (sh == NULL)
continue;
@@ -1194,13 +1195,17 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog)
&prog->NumBufferInterfaceBlocks,
sh->BufferInterfaceBlocks[j]);
- if (index == -1) {
- linker_error(prog, "uniform block `%s' has mismatching definitions\n",
- sh->BufferInterfaceBlocks[j]->Name);
- return false;
- }
+ if (index == -1) {
+ linker_error(prog, "uniform block `%s' has mismatching definitions\n",
+ sh->BufferInterfaceBlocks[j]->Name);
+
+ for (unsigned k = 0; k <= i; k++) {
+ delete[] InterfaceBlockStageIndex[k];
+ }
+ return false;
+ }
- prog->InterfaceBlockStageIndex[i][index] = j;
+ InterfaceBlockStageIndex[i][index] = j;
}
}
@@ -1209,18 +1214,23 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog)
*/
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
for (unsigned j = 0; j < prog->NumBufferInterfaceBlocks; j++) {
- int stage_index =
- prog->InterfaceBlockStageIndex[i][j];
+ int stage_index = InterfaceBlockStageIndex[i][j];
if (stage_index != -1) {
struct gl_shader *sh = prog->_LinkedShaders[i];
+ prog->BufferInterfaceBlocks[j].stageref |= (1 << i);
+
sh->BufferInterfaceBlocks[stage_index] =
&prog->BufferInterfaceBlocks[j];
}
}
}
+ for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+ delete[] InterfaceBlockStageIndex[i];
+ }
+
return true;
}
@@ -2890,6 +2900,9 @@ store_fragdepth_layout(struct gl_shader_program *prog)
static void
check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
{
+ unsigned total_uniform_blocks = 0;
+ unsigned total_shader_storage_blocks = 0;
+
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_shader *sh = prog->_LinkedShaders[i];
@@ -2928,12 +2941,37 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
_mesa_shader_stage_to_string(i));
}
}
+
+ total_shader_storage_blocks += sh->NumShaderStorageBlocks;
+ total_uniform_blocks += sh->NumUniformBlocks;
+
+ const unsigned max_uniform_blocks =
+ ctx->Const.Program[i].MaxUniformBlocks;
+ if (max_uniform_blocks < sh->NumUniformBlocks) {
+ linker_error(prog, "Too many %s uniform blocks (%d/%d)\n",
+ _mesa_shader_stage_to_string(i), sh->NumUniformBlocks,
+ max_uniform_blocks);
+ }
+
+ const unsigned max_shader_storage_blocks =
+ ctx->Const.Program[i].MaxShaderStorageBlocks;
+ if (max_shader_storage_blocks < sh->NumShaderStorageBlocks) {
+ linker_error(prog, "Too many %s shader storage blocks (%d/%d)\n",
+ _mesa_shader_stage_to_string(i),
+ sh->NumShaderStorageBlocks, max_shader_storage_blocks);
+ }
}
- unsigned blocks[MESA_SHADER_STAGES] = {0};
- unsigned total_uniform_blocks = 0;
- unsigned shader_blocks[MESA_SHADER_STAGES] = {0};
- unsigned total_shader_storage_blocks = 0;
+ if (total_uniform_blocks > ctx->Const.MaxCombinedUniformBlocks) {
+ linker_error(prog, "Too many combined uniform blocks (%d/%d)\n",
+ total_uniform_blocks, ctx->Const.MaxCombinedUniformBlocks);
+ }
+
+ if (total_shader_storage_blocks > ctx->Const.MaxCombinedShaderStorageBlocks) {
+ linker_error(prog, "Too many combined shader storage blocks (%d/%d)\n",
+ total_shader_storage_blocks,
+ ctx->Const.MaxCombinedShaderStorageBlocks);
+ }
for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
/* Don't check SSBOs for Uniform Block Size */
@@ -2952,57 +2990,6 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
prog->BufferInterfaceBlocks[i].UniformBufferSize,
ctx->Const.MaxShaderStorageBlockSize);
}
-
- for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) {
- if (prog->InterfaceBlockStageIndex[j][i] != -1) {
- struct gl_shader *sh = prog->_LinkedShaders[j];
- int stage_index = prog->InterfaceBlockStageIndex[j][i];
- if (sh &&
- sh->BufferInterfaceBlocks[stage_index]->IsShaderStorage) {
- shader_blocks[j]++;
- total_shader_storage_blocks++;
- } else {
- blocks[j]++;
- total_uniform_blocks++;
- }
- }
- }
-
- if (total_uniform_blocks > ctx->Const.MaxCombinedUniformBlocks) {
- linker_error(prog, "Too many combined uniform blocks (%d/%d)\n",
- total_uniform_blocks,
- ctx->Const.MaxCombinedUniformBlocks);
- } else {
- for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
- const unsigned max_uniform_blocks =
- ctx->Const.Program[i].MaxUniformBlocks;
- if (blocks[i] > max_uniform_blocks) {
- linker_error(prog, "Too many %s uniform blocks (%d/%d)\n",
- _mesa_shader_stage_to_string(i),
- blocks[i],
- max_uniform_blocks);
- break;
- }
- }
- }
-
- if (total_shader_storage_blocks > ctx->Const.MaxCombinedShaderStorageBlocks) {
- linker_error(prog, "Too many combined shader storage blocks (%d/%d)\n",
- total_shader_storage_blocks,
- ctx->Const.MaxCombinedShaderStorageBlocks);
- } else {
- for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
- const unsigned max_shader_storage_blocks =
- ctx->Const.Program[i].MaxShaderStorageBlocks;
- if (shader_blocks[i] > max_shader_storage_blocks) {
- linker_error(prog, "Too many %s shader storage blocks (%d/%d)\n",
- _mesa_shader_stage_to_string(i),
- shader_blocks[i],
- max_shader_storage_blocks);
- break;
- }
- }
- }
}
}
@@ -3072,13 +3059,7 @@ check_image_resources(struct gl_context *ctx, struct gl_shader_program *prog)
ctx->Const.Program[i].MaxImageUniforms);
total_image_units += sh->NumImages;
-
- for (unsigned j = 0; j < prog->NumBufferInterfaceBlocks; j++) {
- int stage_index = prog->InterfaceBlockStageIndex[i][j];
- if (stage_index != -1 &&
- sh->BufferInterfaceBlocks[stage_index]->IsShaderStorage)
- total_shader_storage_blocks++;
- }
+ total_shader_storage_blocks += sh->NumShaderStorageBlocks;
if (i == MESA_SHADER_FRAGMENT) {
foreach_in_list(ir_instruction, node, sh->ir) {
@@ -3497,19 +3478,50 @@ build_stageref(struct gl_shader_program *shProg, const char *name,
* Create gl_shader_variable from ir_variable class.
*/
static gl_shader_variable *
-create_shader_variable(struct gl_shader_program *shProg, const ir_variable *in)
+create_shader_variable(struct gl_shader_program *shProg,
+ const ir_variable *in, bool use_implicit_location,
+ int location_bias)
{
gl_shader_variable *out = ralloc(shProg, struct gl_shader_variable);
if (!out)
return NULL;
- out->type = in->type;
- out->name = ralloc_strdup(shProg, in->name);
+ /* Since gl_VertexID may be lowered to gl_VertexIDMESA, but applications
+ * expect to see gl_VertexID in the program resource list. Pretend.
+ */
+ if (in->data.mode == ir_var_system_value &&
+ in->data.location == SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) {
+ out->name = ralloc_strdup(shProg, "gl_VertexID");
+ } else {
+ out->name = ralloc_strdup(shProg, in->name);
+ }
if (!out->name)
return NULL;
- out->location = in->data.location;
+ /* From the ARB_program_interface_query specification:
+ *
+ * "Not all active variables are assigned valid locations; the
+ * following variables will have an effective location of -1:
+ *
+ * * uniforms declared as atomic counters;
+ *
+ * * members of a uniform block;
+ *
+ * * built-in inputs, outputs, and uniforms (starting with "gl_"); and
+ *
+ * * inputs or outputs not declared with a "location" layout qualifier,
+ * except for vertex shader inputs and fragment shader outputs."
+ */
+ if (in->type->base_type == GLSL_TYPE_ATOMIC_UINT ||
+ is_gl_identifier(in->name) ||
+ !(in->data.explicit_location || use_implicit_location)) {
+ out->location = -1;
+ } else {
+ out->location = in->data.location - location_bias;
+ }
+
+ out->type = in->type;
out->index = in->data.index;
out->patch = in->data.patch;
out->mode = in->data.mode;
@@ -3519,38 +3531,31 @@ create_shader_variable(struct gl_shader_program *shProg, const ir_variable *in)
static bool
add_interface_variables(struct gl_shader_program *shProg,
- exec_list *ir, GLenum programInterface)
+ unsigned stage, GLenum programInterface)
{
+ exec_list *ir = shProg->_LinkedShaders[stage]->ir;
+
foreach_in_list(ir_instruction, node, ir) {
ir_variable *var = node->as_variable();
- uint8_t mask = 0;
- if (!var)
+ if (!var || var->data.how_declared == ir_var_hidden)
continue;
+ int loc_bias;
+
switch (var->data.mode) {
- /* From GL 4.3 core spec, section 11.1.1 (Vertex Attributes):
- * "For GetActiveAttrib, all active vertex shader input variables
- * are enumerated, including the special built-in inputs gl_VertexID
- * and gl_InstanceID."
- */
case ir_var_system_value:
- if (var->data.location != SYSTEM_VALUE_VERTEX_ID &&
- var->data.location != SYSTEM_VALUE_VERTEX_ID_ZERO_BASE &&
- var->data.location != SYSTEM_VALUE_INSTANCE_ID)
- continue;
- /* Mark special built-in inputs referenced by the vertex stage so
- * that they are considered active by the shader queries.
- */
- mask = (1 << (MESA_SHADER_VERTEX));
- /* FALLTHROUGH */
case ir_var_shader_in:
if (programInterface != GL_PROGRAM_INPUT)
continue;
+ loc_bias = (stage == MESA_SHADER_VERTEX) ? int(VERT_ATTRIB_GENERIC0)
+ : int(VARYING_SLOT_VAR0);
break;
case ir_var_shader_out:
if (programInterface != GL_PROGRAM_OUTPUT)
continue;
+ loc_bias = (stage == MESA_SHADER_FRAGMENT) ? int(FRAG_RESULT_DATA0)
+ : int(VARYING_SLOT_VAR0);
break;
default:
continue;
@@ -3568,13 +3573,16 @@ add_interface_variables(struct gl_shader_program *shProg,
if (strncmp(var->name, "gl_out_FragData", 15) == 0)
continue;
- gl_shader_variable *sha_v = create_shader_variable(shProg, var);
+ const bool vs_input_or_fs_output =
+ (stage == MESA_SHADER_VERTEX && var->data.mode == ir_var_shader_in) ||
+ (stage == MESA_SHADER_FRAGMENT && var->data.mode == ir_var_shader_out);
+
+ gl_shader_variable *sha_v =
+ create_shader_variable(shProg, var, vs_input_or_fs_output, loc_bias);
if (!sha_v)
return false;
- if (!add_program_resource(shProg, programInterface, sha_v,
- build_stageref(shProg, sha_v->name,
- sha_v->mode) | mask))
+ if (!add_program_resource(shProg, programInterface, sha_v, 1 << stage))
return false;
}
return true;
@@ -3604,7 +3612,8 @@ add_packed_varyings(struct gl_shader_program *shProg, int stage, GLenum type)
}
if (type == iface) {
- gl_shader_variable *sha_v = create_shader_variable(shProg, var);
+ gl_shader_variable *sha_v =
+ create_shader_variable(shProg, var, false, VARYING_SLOT_VAR0);
if (!sha_v)
return false;
if (!add_program_resource(shProg, iface, sha_v,
@@ -3629,7 +3638,8 @@ add_fragdata_arrays(struct gl_shader_program *shProg)
ir_variable *var = node->as_variable();
if (var) {
assert(var->data.mode == ir_var_shader_out);
- gl_shader_variable *sha_v = create_shader_variable(shProg, var);
+ gl_shader_variable *sha_v =
+ create_shader_variable(shProg, var, true, FRAG_RESULT_DATA0);
if (!sha_v)
return false;
if (!add_program_resource(shProg, GL_PROGRAM_OUTPUT, sha_v,
@@ -3794,7 +3804,9 @@ calculate_array_size_and_stride(struct gl_shader_program *shProg,
int array_stride = -1;
char *var_name = get_top_level_name(uni->name);
char *interface_name =
- get_top_level_name(shProg->BufferInterfaceBlocks[block_index].Name);
+ get_top_level_name(uni->is_shader_storage ?
+ shProg->ShaderStorageBlocks[block_index]->Name :
+ shProg->UniformBlocks[block_index]->Name);
if (strcmp(var_name, interface_name) == 0) {
/* Deal with instanced array of SSBOs */
@@ -3893,12 +3905,10 @@ build_program_resource_list(struct gl_context *ctx,
return;
/* Add inputs and outputs to the resource list. */
- if (!add_interface_variables(shProg, shProg->_LinkedShaders[input_stage]->ir,
- GL_PROGRAM_INPUT))
+ if (!add_interface_variables(shProg, input_stage, GL_PROGRAM_INPUT))
return;
- if (!add_interface_variables(shProg, shProg->_LinkedShaders[output_stage]->ir,
- GL_PROGRAM_OUTPUT))
+ if (!add_interface_variables(shProg, output_stage, GL_PROGRAM_OUTPUT))
return;
/* Add transform feedback varyings. */
@@ -3933,15 +3943,14 @@ build_program_resource_list(struct gl_context *ctx,
ir_var_uniform);
/* Add stagereferences for uniforms in a uniform block. */
+ bool is_shader_storage = shProg->UniformStorage[i].is_shader_storage;
int block_index = shProg->UniformStorage[i].block_index;
if (block_index != -1) {
- for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) {
- if (shProg->InterfaceBlockStageIndex[j][block_index] != -1)
- stageref |= (1 << j);
- }
+ stageref |= is_shader_storage ?
+ shProg->ShaderStorageBlocks[block_index]->stageref :
+ shProg->UniformBlocks[block_index]->stageref;
}
- bool is_shader_storage = shProg->UniformStorage[i].is_shader_storage;
GLenum type = is_shader_storage ? GL_BUFFER_VARIABLE : GL_UNIFORM;
if (!should_add_buffer_variable(shProg, type,
shProg->UniformStorage[i].name))
@@ -4686,6 +4695,33 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
has_xfb_qualifiers))
goto done;
+ /* Split BufferInterfaceBlocks into UniformBlocks and ShaderStorageBlocks
+ * for gl_shader_program and gl_shader, so that drivers that need separate
+ * index spaces for each set can have that.
+ */
+ for (unsigned i = MESA_SHADER_VERTEX; i < MESA_SHADER_STAGES; i++) {
+ if (prog->_LinkedShaders[i] != NULL) {
+ gl_shader *sh = prog->_LinkedShaders[i];
+ split_ubos_and_ssbos(sh,
+ sh->BufferInterfaceBlocks,
+ NULL,
+ sh->NumBufferInterfaceBlocks,
+ &sh->UniformBlocks,
+ &sh->NumUniformBlocks,
+ &sh->ShaderStorageBlocks,
+ &sh->NumShaderStorageBlocks);
+ }
+ }
+
+ split_ubos_and_ssbos(prog,
+ NULL,
+ prog->BufferInterfaceBlocks,
+ prog->NumBufferInterfaceBlocks,
+ &prog->UniformBlocks,
+ &prog->NumUniformBlocks,
+ &prog->ShaderStorageBlocks,
+ &prog->NumShaderStorageBlocks);
+
update_array_sizes(prog);
link_assign_uniform_locations(prog, ctx->Const.UniformBooleanTrue,
num_explicit_uniform_locs,
@@ -4737,33 +4773,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
}
}
- /* Split BufferInterfaceBlocks into UniformBlocks and ShaderStorageBlocks
- * for gl_shader_program and gl_shader, so that drivers that need separate
- * index spaces for each set can have that.
- */
- for (unsigned i = MESA_SHADER_VERTEX; i < MESA_SHADER_STAGES; i++) {
- if (prog->_LinkedShaders[i] != NULL) {
- gl_shader *sh = prog->_LinkedShaders[i];
- split_ubos_and_ssbos(sh,
- sh->BufferInterfaceBlocks,
- NULL,
- sh->NumBufferInterfaceBlocks,
- &sh->UniformBlocks,
- &sh->NumUniformBlocks,
- &sh->ShaderStorageBlocks,
- &sh->NumShaderStorageBlocks);
- }
- }
-
- split_ubos_and_ssbos(prog,
- NULL,
- prog->BufferInterfaceBlocks,
- prog->NumBufferInterfaceBlocks,
- &prog->UniformBlocks,
- &prog->NumUniformBlocks,
- &prog->ShaderStorageBlocks,
- &prog->NumShaderStorageBlocks);
-
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
if (prog->_LinkedShaders[i] == NULL)
continue;
diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp
index d6269f7cbac..3155ab6225e 100644
--- a/src/compiler/glsl/lower_ubo_reference.cpp
+++ b/src/compiler/glsl/lower_ubo_reference.cpp
@@ -372,7 +372,8 @@ lower_ubo_reference_visitor::ubo_load(void *mem_ctx,
static bool
shader_storage_buffer_object(const _mesa_glsl_parse_state *state)
{
- return state->ARB_shader_storage_buffer_object_enable;
+ return state->ARB_shader_storage_buffer_object_enable ||
+ state->is_version(430, 310);
}
uint32_t
diff --git a/src/compiler/glsl/lower_vertex_id.cpp b/src/compiler/glsl/lower_vertex_id.cpp
index 3da7a2f1b3b..6f46945026c 100644
--- a/src/compiler/glsl/lower_vertex_id.cpp
+++ b/src/compiler/glsl/lower_vertex_id.cpp
@@ -100,7 +100,7 @@ lower_vertex_id_visitor::visit(ir_dereference_variable *ir)
if (gl_BaseVertex == NULL) {
gl_BaseVertex = new(mem_ctx) ir_variable(int_t, "gl_BaseVertex",
ir_var_system_value);
- gl_BaseVertex->data.how_declared = ir_var_declared_implicitly;
+ gl_BaseVertex->data.how_declared = ir_var_hidden;
gl_BaseVertex->data.read_only = true;
gl_BaseVertex->data.location = SYSTEM_VALUE_BASE_VERTEX;
gl_BaseVertex->data.explicit_location = true;
diff --git a/src/compiler/glsl/standalone_scaffolding.cpp b/src/compiler/glsl/standalone_scaffolding.cpp
index e350f702099..49b4a26dc12 100644
--- a/src/compiler/glsl/standalone_scaffolding.cpp
+++ b/src/compiler/glsl/standalone_scaffolding.cpp
@@ -96,8 +96,6 @@ _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh)
void
_mesa_clear_shader_program_data(struct gl_shader_program *shProg)
{
- unsigned i;
-
shProg->NumUniformStorage = 0;
shProg->UniformStorage = NULL;
shProg->NumUniformRemapTable = 0;
@@ -119,11 +117,6 @@ _mesa_clear_shader_program_data(struct gl_shader_program *shProg)
shProg->ShaderStorageBlocks = NULL;
shProg->NumShaderStorageBlocks = 0;
- for (i = 0; i < MESA_SHADER_STAGES; i++) {
- ralloc_free(shProg->InterfaceBlockStageIndex[i]);
- shProg->InterfaceBlockStageIndex[i] = NULL;
- }
-
ralloc_free(shProg->AtomicBuffers);
shProg->AtomicBuffers = NULL;
shProg->NumAtomicBuffers = 0;