glsl/glcpp: Fix glcpp to catch garbage after #if 1 ... #else
[mesa.git] / src / glsl / glcpp / glcpp-parse.y
index 412d571e6ebca9a68fc7ea2793cd36248e028a3c..82e310270d6324b5dff100926c50f733a9d51429 100644 (file)
@@ -260,6 +260,12 @@ control_line:
 |      HASH_UNDEF {
                glcpp_parser_resolve_implicit_version(parser);
        } IDENTIFIER NEWLINE {
+               if (strcmp("__LINE__", $3) == 0
+                   || strcmp("__FILE__", $3) == 0
+                   || strcmp("__VERSION__", $3) == 0)
+                       glcpp_error(& @1, parser, "Built-in (pre-defined)"
+                                   " macro names can not be undefined.");
+
                macro_t *macro = hash_table_find (parser->defines, $3);
                if (macro) {
                        hash_table_remove (parser->defines, $3);
@@ -358,7 +364,7 @@ control_line:
                        glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
                }
        }
-|      HASH_ELSE {
+|      HASH_ELSE { parser->lexing_directive = 1; } NEWLINE {
                if (parser->skip_stack &&
                    parser->skip_stack->has_else)
                {
@@ -370,7 +376,7 @@ control_line:
                        if (parser->skip_stack)
                                parser->skip_stack->has_else = true;
                }
-       } NEWLINE
+       }
 |      HASH_ENDIF {
                _glcpp_parser_skip_stack_pop (parser, & @1);
        } NEWLINE
@@ -933,14 +939,16 @@ _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
 
                if (node_a == NULL || node_b == NULL)
                        return 0;
-
-               if (node_a->token->type == SPACE) {
-                       node_a = node_a->next;
-                       continue;
-               }
-
-               if (node_b->token->type == SPACE) {
-                       node_b = node_b->next;
+               /* 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->token->type == SPACE)
+                               node_a = node_a->next;
+                       while (node_b->token->type == SPACE)
+                               node_b = node_b->next;
                        continue;
                }
 
@@ -1203,7 +1211,7 @@ glcpp_parser_create (const struct gl_extensions *extensions, gl_api api)
        parser->defines = hash_table_ctor (32, hash_table_string_hash,
                                           hash_table_string_compare);
        parser->active = NULL;
-       parser->lexing_if = 0;
+       parser->lexing_directive = 0;
        parser->space_tokens = 1;
        parser->newline_as_space = 0;
        parser->in_control_line = 0;
@@ -2062,6 +2070,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
        /* 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);
 
           if (extensions != NULL) {
              if (extensions->OES_EGL_image_external)
@@ -2085,9 +2094,15 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
                 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_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_shader_texture_lod)
                 add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1);
 
@@ -2126,6 +2141,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
              if (extensions->AMD_vertex_shader_layer)
                 add_builtin_define(parser, "GL_AMD_vertex_shader_layer", 1);
 
+             if (extensions->AMD_vertex_shader_viewport_index)
+                add_builtin_define(parser, "GL_AMD_vertex_shader_viewport_index", 1);
+
              if (extensions->ARB_shading_language_420pack)
                 add_builtin_define(parser, "GL_ARB_shading_language_420pack", 1);