vk/image: Check extent does not exceed surface type limits
[mesa.git] / src / glsl / glsl_lexer.ll
index 9fd9b80d3e86da0804865075833e2442c354326e..10db5b8b632e4fe8d97fea5993ed3724252c25df 100644 (file)
@@ -23,7 +23,7 @@
  */
 #include <ctype.h>
 #include <limits.h>
-#include "strtod.h"
+#include "util/strtod.h"
 #include "ast.h"
 #include "glsl_parser_extras.h"
 #include "glsl_parser.h"
@@ -36,13 +36,13 @@ static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
 
 #define YY_USER_ACTION                                         \
    do {                                                                \
-      yylloc->source = 0;                                      \
       yylloc->first_column = yycolumn + 1;                     \
-      yylloc->first_line = yylineno + 1;                       \
+      yylloc->first_line = yylloc->last_line = yylineno + 1;   \
       yycolumn += yyleng;                                      \
+      yylloc->last_column = yycolumn + 1;                      \
    } while(0);
 
-#define YY_USER_INIT yylineno = 0; yycolumn = 0;
+#define YY_USER_INIT yylineno = 0; yycolumn = 0; yylloc->source = 0;
 
 /* A macro for handling reserved words and keywords across language versions.
  *
@@ -80,7 +80,8 @@ static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
                          "illegal use of reserved word `%s'", yytext); \
         return ERROR_TOK;                                              \
       } else {                                                         \
-        yylval->identifier = strdup(yytext);                           \
+        void *mem_ctx = yyextra;                                       \
+        yylval->identifier = ralloc_strdup(mem_ctx, yytext);           \
         return classify_identifier(yyextra, yytext);                   \
       }                                                                        \
    } while (0)
@@ -151,7 +152,11 @@ literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
 %option never-interactive
 %option prefix="_mesa_glsl_lexer_"
 %option extra-type="struct _mesa_glsl_parse_state *"
+%option warn nodefault
 
+       /* Note: When adding any start conditions to this list, you must also
+        * update the "Internal compiler error" catch-all rule near the end of
+        * this file. */
 %x PP PRAGMA
 
 DEC_INT                [1-9][0-9]*
@@ -182,6 +187,15 @@ HASH               ^{SPC}#{SPC}
                                    * one-based.
                                    */
                                   yylineno = strtol(ptr, &ptr, 0) - 1;
+
+                                   /* From GLSL 3.30 and GLSL ES on, after processing the
+                                    * line directive (including its new-line), the implementation
+                                    * will behave as if it is compiling at the line number passed
+                                    * as argument. It was line number + 1 in older specifications.
+                                    */
+                                   if (yyextra->is_version(330, 100))
+                                      yylineno--;
+
                                   yylloc->source = strtol(ptr, NULL, 0);
                                }
 {HASH}line{SPCP}{INT}{SPC}$    {
@@ -197,6 +211,14 @@ HASH               ^{SPC}#{SPC}
                                    * one-based.
                                    */
                                   yylineno = strtol(ptr, &ptr, 0) - 1;
+
+                                   /* From GLSL 3.30 and GLSL ES on, after processing the
+                                    * line directive (including its new-line), the implementation
+                                    * will behave as if it is compiling at the line number passed
+                                    * as argument. It was line number + 1 in older specifications.
+                                    */
+                                   if (yyextra->is_version(330, 100))
+                                      yylineno--;
                                }
 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
                                  BEGIN PP;
@@ -227,7 +249,8 @@ HASH                ^{SPC}#{SPC}
 <PP>[ \t\r]*                   { }
 <PP>:                          return COLON;
 <PP>[_a-zA-Z][_a-zA-Z0-9]*     {
-                                  yylval->identifier = strdup(yytext);
+                                  void *mem_ctx = yyextra;
+                                  yylval->identifier = ralloc_strdup(mem_ctx, yytext);
                                   return IDENTIFIER;
                                }
 <PP>[1-9][0-9]*                        {
@@ -235,6 +258,7 @@ HASH                ^{SPC}#{SPC}
                                    return INTCONSTANT;
                                }
 <PP>\n                         { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
+<PP>.                          { return yytext[0]; }
 
 \n             { yylineno++; yycolumn = 0; }
 
@@ -337,6 +361,9 @@ samplerExternalOES          {
                             return IDENTIFIER;
                }
 
+   /* keywords available with ARB_gpu_shader5 */
+precise                KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_gpu_shader5_enable, PRECISE);
+
    /* keywords available with ARB_shader_image_load_store */
 image1D         KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1D);
 image2D         KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2D);
@@ -382,7 +409,7 @@ restrict    KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store
 readonly       KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, READONLY);
 writeonly      KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, WRITEONLY);
 
-atomic_uint     KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_atomic_counters_enable, ATOMIC_UINT);
+atomic_uint     KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_atomic_counters_enable, ATOMIC_UINT);
 
 struct         return STRUCT;
 void           return VOID_TOK;
@@ -392,6 +419,7 @@ layout              {
                      || yyextra->AMD_conservative_depth_enable
                      || yyextra->ARB_conservative_depth_enable
                      || yyextra->ARB_explicit_attrib_location_enable
+                     || yyextra->ARB_explicit_uniform_location_enable
                       || yyextra->has_separate_shader_objects()
                      || yyextra->ARB_uniform_buffer_object_enable
                      || yyextra->ARB_fragment_coord_conventions_enable
@@ -399,7 +427,8 @@ layout              {
                       || yyextra->ARB_compute_shader_enable) {
                      return LAYOUT_TOK;
                   } else {
-                     yylval->identifier = strdup(yytext);
+                     void *mem_ctx = yyextra;
+                     yylval->identifier = ralloc_strdup(mem_ctx, yytext);
                      return classify_identifier(yyextra, yytext);
                   }
                }
@@ -437,25 +466,23 @@ layout            {
                            return LITERAL_INTEGER(8);
                        }
 
-[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]?  {
-                           yylval->real = glsl_strtof(yytext, NULL);
-                           return FLOATCONSTANT;
-                       }
-\.[0-9]+([eE][+-]?[0-9]+)?[fF]?                {
-                           yylval->real = glsl_strtof(yytext, NULL);
-                           return FLOATCONSTANT;
-                       }
-[0-9]+\.([eE][+-]?[0-9]+)?[fF]?                {
-                           yylval->real = glsl_strtof(yytext, NULL);
-                           return FLOATCONSTANT;
-                       }
+[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]?  |
+\.[0-9]+([eE][+-]?[0-9]+)?[fF]?                |
+[0-9]+\.([eE][+-]?[0-9]+)?[fF]?                |
 [0-9]+[eE][+-]?[0-9]+[fF]?             {
-                           yylval->real = glsl_strtof(yytext, NULL);
+                           yylval->real = _mesa_strtof(yytext, NULL);
                            return FLOATCONSTANT;
                        }
-[0-9]+[fF]             {
-                           yylval->real = glsl_strtof(yytext, NULL);
-                           return FLOATCONSTANT;
+
+[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF)        |
+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF)      |
+[0-9]+\.([eE][+-]?[0-9]+)?(lf|LF)      |
+[0-9]+[eE][+-]?[0-9]+(lf|LF)           {
+                           if (!yyextra->is_version(400, 0) &&
+                               !yyextra->ARB_gpu_shader_fp64_enable)
+                               return ERROR_TOK;
+                           yylval->dreal = _mesa_strtod(yytext, NULL);
+                           return DOUBLECONSTANT;
                        }
 
 true                   {
@@ -489,7 +516,7 @@ external    KEYWORD(110, 100, 0, 0, EXTERNAL);
 interface      KEYWORD(110, 100, 0, 0, INTERFACE);
 long           KEYWORD(110, 100, 0, 0, LONG_TOK);
 short          KEYWORD(110, 100, 0, 0, SHORT_TOK);
-double         KEYWORD(110, 100, 400, 0, DOUBLE_TOK);
+double         KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DOUBLE_TOK);
 half           KEYWORD(110, 100, 0, 0, HALF);
 fixed          KEYWORD(110, 100, 0, 0, FIXED_TOK);
 unsigned       KEYWORD(110, 100, 0, 0, UNSIGNED);
@@ -498,9 +525,21 @@ output             KEYWORD(110, 100, 0, 0, OUTPUT);
 hvec2          KEYWORD(110, 100, 0, 0, HVEC2);
 hvec3          KEYWORD(110, 100, 0, 0, HVEC3);
 hvec4          KEYWORD(110, 100, 0, 0, HVEC4);
-dvec2          KEYWORD(110, 100, 400, 0, DVEC2);
-dvec3          KEYWORD(110, 100, 400, 0, DVEC3);
-dvec4          KEYWORD(110, 100, 400, 0, DVEC4);
+dvec2          KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC2);
+dvec3          KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC3);
+dvec4          KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC4);
+dmat2          KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
+dmat3          KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
+dmat4          KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
+dmat2x2                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
+dmat2x3                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X3);
+dmat2x4                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X4);
+dmat3x2                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X2);
+dmat3x3                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
+dmat3x4                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X4);
+dmat4x2                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X2);
+dmat4x3                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X3);
+dmat4x4                KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
 fvec2          KEYWORD(110, 100, 0, 0, FVEC2);
 fvec3          KEYWORD(110, 100, 0, 0, FVEC3);
 fvec4          KEYWORD(110, 100, 0, 0, FVEC4);
@@ -544,7 +583,13 @@ subroutine KEYWORD(0, 300, 0, 0, SUBROUTINE);
 [_a-zA-Z][_a-zA-Z0-9]* {
                            struct _mesa_glsl_parse_state *state = yyextra;
                            void *ctx = state;  
-                           yylval->identifier = ralloc_strdup(ctx, yytext);
+                           if (state->es_shader && strlen(yytext) > 1024) {
+                              _mesa_glsl_error(yylloc, state,
+                                               "Identifier `%s' exceeds 1024 characters",
+                                               yytext);
+                           } else {
+                             yylval->identifier = ralloc_strdup(ctx, yytext);
+                           }
                            return classify_identifier(state, yytext);
                        }