Home | History | Annotate | Download | only in MachineIndependent
      1 //
      2 // Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
      3 // Copyright (C) 2012-2013 LunarG, Inc.
      4 //
      5 // All rights reserved.
      6 //
      7 // Redistribution and use in source and binary forms, with or without
      8 // modification, are permitted provided that the following conditions
      9 // are met:
     10 //
     11 //    Redistributions of source code must retain the above copyright
     12 //    notice, this list of conditions and the following disclaimer.
     13 //
     14 //    Redistributions in binary form must reproduce the above
     15 //    copyright notice, this list of conditions and the following
     16 //    disclaimer in the documentation and/or other materials provided
     17 //    with the distribution.
     18 //
     19 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
     20 //    contributors may be used to endorse or promote products derived
     21 //    from this software without specific prior written permission.
     22 //
     23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34 // POSSIBILITY OF SUCH DAMAGE.
     35 //
     36 
     37 /**
     38  * This is bison grammar and productions for parsing all versions of the
     39  * GLSL shading languages.
     40  */
     41 %{
     42 
     43 /* Based on:
     44 ANSI C Yacc grammar
     45 
     46 In 1985, Jeff Lee published his Yacc grammar (which is accompanied by a
     47 matching Lex specification) for the April 30, 1985 draft version of the
     48 ANSI C standard.  Tom Stockfisch reposted it to net.sources in 1987; that
     49 original, as mentioned in the answer to question 17.25 of the comp.lang.c
     50 FAQ, can be ftp'ed from ftp.uu.net, file usenet/net.sources/ansi.c.grammar.Z.
     51 
     52 I intend to keep this version as close to the current C Standard grammar as
     53 possible; please let me know if you discover discrepancies.
     54 
     55 Jutta Degener, 1995
     56 */
     57 
     58 #include "SymbolTable.h"
     59 #include "ParseHelper.h"
     60 #include "../Public/ShaderLang.h"
     61 
     62 using namespace glslang;
     63 
     64 %}
     65 
     66 %define parse.error verbose
     67 
     68 %union {
     69     struct {
     70         glslang::TSourceLoc loc;
     71         union {
     72             glslang::TString *string;
     73             int i;
     74             unsigned int u;
     75             long long i64;
     76             unsigned long long u64;
     77             bool b;
     78             double d;
     79         };
     80         glslang::TSymbol* symbol;
     81     } lex;
     82     struct {
     83         glslang::TSourceLoc loc;
     84         glslang::TOperator op;
     85         union {
     86             TIntermNode* intermNode;
     87             glslang::TIntermNodePair nodePair;
     88             glslang::TIntermTyped* intermTypedNode;
     89         };
     90         union {
     91             glslang::TPublicType type;
     92             glslang::TFunction* function;
     93             glslang::TParameter param;
     94             glslang::TTypeLoc typeLine;
     95             glslang::TTypeList* typeList;
     96             glslang::TArraySizes* arraySizes;
     97             glslang::TIdentifierList* identifierList;
     98         };
     99     } interm;
    100 }
    101 
    102 %{
    103 
    104 /* windows only pragma */
    105 #ifdef _MSC_VER
    106     #pragma warning(disable : 4065)
    107     #pragma warning(disable : 4127)
    108     #pragma warning(disable : 4244)
    109 #endif
    110 
    111 #define parseContext (*pParseContext)
    112 #define yyerror(context, msg) context->parserError(msg)
    113 
    114 extern int yylex(YYSTYPE*, TParseContext&);
    115 
    116 %}
    117 
    118 %parse-param {glslang::TParseContext* pParseContext}
    119 %lex-param {parseContext}
    120 %pure-parser  // enable thread safety
    121 %expect 1     // One shift reduce conflict because of if | else
    122 
    123 %token <lex> ATTRIBUTE VARYING
    124 %token <lex> CONST BOOL FLOAT DOUBLE INT UINT INT64_T UINT64_T INT16_T UINT16_T FLOAT16_T
    125 %token <lex> BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT SUBROUTINE
    126 %token <lex> BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 I64VEC2 I64VEC3 I64VEC4 UVEC2 UVEC3 UVEC4 U64VEC2 U64VEC3 U64VEC4 VEC2 VEC3 VEC4
    127 %token <lex> MAT2 MAT3 MAT4 CENTROID IN OUT INOUT
    128 %token <lex> UNIFORM PATCH SAMPLE BUFFER SHARED
    129 %token <lex> COHERENT VOLATILE RESTRICT READONLY WRITEONLY
    130 %token <lex> DVEC2 DVEC3 DVEC4 DMAT2 DMAT3 DMAT4
    131 %token <lex> F16VEC2 F16VEC3 F16VEC4 F16MAT2 F16MAT3 F16MAT4
    132 %token <lex> I16VEC2 I16VEC3 I16VEC4 U16VEC2 U16VEC3 U16VEC4
    133 %token <lex> NOPERSPECTIVE FLAT SMOOTH LAYOUT __EXPLICITINTERPAMD
    134 
    135 %token <lex> MAT2X2 MAT2X3 MAT2X4
    136 %token <lex> MAT3X2 MAT3X3 MAT3X4
    137 %token <lex> MAT4X2 MAT4X3 MAT4X4
    138 %token <lex> DMAT2X2 DMAT2X3 DMAT2X4
    139 %token <lex> DMAT3X2 DMAT3X3 DMAT3X4
    140 %token <lex> DMAT4X2 DMAT4X3 DMAT4X4
    141 %token <lex> F16MAT2X2 F16MAT2X3 F16MAT2X4
    142 %token <lex> F16MAT3X2 F16MAT3X3 F16MAT3X4
    143 %token <lex> F16MAT4X2 F16MAT4X3 F16MAT4X4
    144 %token <lex> ATOMIC_UINT
    145 
    146 // combined image/sampler
    147 %token <lex> SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
    148 %token <lex> SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
    149 %token <lex> SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
    150 %token <lex> ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
    151 %token <lex> USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
    152 %token <lex> SAMPLER2DRECT SAMPLER2DRECTSHADOW ISAMPLER2DRECT USAMPLER2DRECT
    153 %token <lex> SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
    154 %token <lex> SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
    155 %token <lex> ISAMPLERCUBEARRAY USAMPLERCUBEARRAY
    156 %token <lex> SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
    157 %token <lex> SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
    158 %token <lex> SAMPLEREXTERNALOES
    159 
    160 // pure sampler
    161 %token <lex> SAMPLER SAMPLERSHADOW
    162 
    163 // texture without sampler
    164 %token <lex> TEXTURE1D TEXTURE2D TEXTURE3D TEXTURECUBE
    165 %token <lex> TEXTURE1DARRAY TEXTURE2DARRAY
    166 %token <lex> ITEXTURE1D ITEXTURE2D ITEXTURE3D ITEXTURECUBE
    167 %token <lex> ITEXTURE1DARRAY ITEXTURE2DARRAY UTEXTURE1D UTEXTURE2D UTEXTURE3D
    168 %token <lex> UTEXTURECUBE UTEXTURE1DARRAY UTEXTURE2DARRAY
    169 %token <lex> TEXTURE2DRECT ITEXTURE2DRECT UTEXTURE2DRECT
    170 %token <lex> TEXTUREBUFFER ITEXTUREBUFFER UTEXTUREBUFFER
    171 %token <lex> TEXTURECUBEARRAY ITEXTURECUBEARRAY UTEXTURECUBEARRAY
    172 %token <lex> TEXTURE2DMS ITEXTURE2DMS UTEXTURE2DMS
    173 %token <lex> TEXTURE2DMSARRAY ITEXTURE2DMSARRAY UTEXTURE2DMSARRAY
    174 
    175 // input attachments
    176 %token <lex> SUBPASSINPUT SUBPASSINPUTMS ISUBPASSINPUT ISUBPASSINPUTMS USUBPASSINPUT USUBPASSINPUTMS
    177 
    178 %token <lex> IMAGE1D IIMAGE1D UIMAGE1D IMAGE2D IIMAGE2D
    179 %token <lex> UIMAGE2D IMAGE3D IIMAGE3D UIMAGE3D
    180 %token <lex> IMAGE2DRECT IIMAGE2DRECT UIMAGE2DRECT
    181 %token <lex> IMAGECUBE IIMAGECUBE UIMAGECUBE
    182 %token <lex> IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
    183 %token <lex> IMAGE1DARRAY IIMAGE1DARRAY UIMAGE1DARRAY
    184 %token <lex> IMAGE2DARRAY IIMAGE2DARRAY UIMAGE2DARRAY
    185 %token <lex> IMAGECUBEARRAY IIMAGECUBEARRAY UIMAGECUBEARRAY
    186 %token <lex> IMAGE2DMS IIMAGE2DMS UIMAGE2DMS
    187 %token <lex> IMAGE2DMSARRAY IIMAGE2DMSARRAY UIMAGE2DMSARRAY
    188 
    189 %token <lex> STRUCT VOID WHILE
    190 
    191 %token <lex> IDENTIFIER TYPE_NAME
    192 %token <lex> FLOATCONSTANT DOUBLECONSTANT INTCONSTANT UINTCONSTANT INT64CONSTANT UINT64CONSTANT INT16CONSTANT UINT16CONSTANT BOOLCONSTANT FLOAT16CONSTANT
    193 %token <lex> LEFT_OP RIGHT_OP
    194 %token <lex> INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
    195 %token <lex> AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
    196 %token <lex> MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
    197 %token <lex> SUB_ASSIGN
    198 
    199 %token <lex> LEFT_PAREN RIGHT_PAREN LEFT_BRACKET RIGHT_BRACKET LEFT_BRACE RIGHT_BRACE DOT
    200 %token <lex> COMMA COLON EQUAL SEMICOLON BANG DASH TILDE PLUS STAR SLASH PERCENT
    201 %token <lex> LEFT_ANGLE RIGHT_ANGLE VERTICAL_BAR CARET AMPERSAND QUESTION
    202 
    203 %token <lex> INVARIANT PRECISE
    204 %token <lex> HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
    205 
    206 %token <lex> PACKED RESOURCE SUPERP
    207 
    208 %type <interm> assignment_operator unary_operator
    209 %type <interm.intermTypedNode> variable_identifier primary_expression postfix_expression
    210 %type <interm.intermTypedNode> expression integer_expression assignment_expression
    211 %type <interm.intermTypedNode> unary_expression multiplicative_expression additive_expression
    212 %type <interm.intermTypedNode> relational_expression equality_expression
    213 %type <interm.intermTypedNode> conditional_expression constant_expression
    214 %type <interm.intermTypedNode> logical_or_expression logical_xor_expression logical_and_expression
    215 %type <interm.intermTypedNode> shift_expression and_expression exclusive_or_expression inclusive_or_expression
    216 %type <interm.intermTypedNode> function_call initializer initializer_list condition conditionopt
    217 
    218 %type <interm.intermNode> translation_unit function_definition
    219 %type <interm.intermNode> statement simple_statement
    220 %type <interm.intermNode> statement_list switch_statement_list compound_statement
    221 %type <interm.intermNode> declaration_statement selection_statement expression_statement
    222 %type <interm.intermNode> switch_statement case_label
    223 %type <interm.intermNode> declaration external_declaration
    224 %type <interm.intermNode> for_init_statement compound_statement_no_new_scope
    225 %type <interm.nodePair> selection_rest_statement for_rest_statement
    226 %type <interm.intermNode> iteration_statement jump_statement statement_no_new_scope statement_scoped
    227 %type <interm> single_declaration init_declarator_list
    228 
    229 %type <interm> parameter_declaration parameter_declarator parameter_type_specifier
    230 
    231 %type <interm> array_specifier
    232 %type <interm.type> precise_qualifier invariant_qualifier interpolation_qualifier storage_qualifier precision_qualifier
    233 %type <interm.type> layout_qualifier layout_qualifier_id_list layout_qualifier_id
    234 
    235 %type <interm.type> type_qualifier fully_specified_type type_specifier
    236 %type <interm.type> single_type_qualifier
    237 %type <interm.type> type_specifier_nonarray
    238 %type <interm.type> struct_specifier
    239 %type <interm.typeLine> struct_declarator
    240 %type <interm.typeList> struct_declarator_list struct_declaration struct_declaration_list type_name_list
    241 %type <interm> block_structure
    242 %type <interm.function> function_header function_declarator
    243 %type <interm.function> function_header_with_parameters
    244 %type <interm> function_call_header_with_parameters function_call_header_no_parameters function_call_generic function_prototype
    245 %type <interm> function_call_or_method function_identifier function_call_header
    246 
    247 %type <interm.identifierList> identifier_list
    248 
    249 %start translation_unit
    250 %%
    251 
    252 variable_identifier
    253     : IDENTIFIER {
    254         $$ = parseContext.handleVariable($1.loc, $1.symbol, $1.string);
    255     }
    256     ;
    257 
    258 primary_expression
    259     : variable_identifier {
    260         $$ = $1;
    261     }
    262     | INTCONSTANT {
    263         $$ = parseContext.intermediate.addConstantUnion($1.i, $1.loc, true);
    264     }
    265     | UINTCONSTANT {
    266         parseContext.fullIntegerCheck($1.loc, "unsigned literal");
    267         $$ = parseContext.intermediate.addConstantUnion($1.u, $1.loc, true);
    268     }
    269     | INT64CONSTANT {
    270         parseContext.int64Check($1.loc, "64-bit integer literal");
    271         $$ = parseContext.intermediate.addConstantUnion($1.i64, $1.loc, true);
    272     }
    273     | UINT64CONSTANT {
    274         parseContext.int64Check($1.loc, "64-bit unsigned integer literal");
    275         $$ = parseContext.intermediate.addConstantUnion($1.u64, $1.loc, true);
    276     }
    277     | INT16CONSTANT {
    278 #ifdef AMD_EXTENSIONS
    279         parseContext.int16Check($1.loc, "16-bit integer literal");
    280         $$ = parseContext.intermediate.addConstantUnion((short)$1.i, $1.loc, true);
    281 #endif
    282     }
    283     | UINT16CONSTANT {
    284 #ifdef AMD_EXTENSIONS
    285         parseContext.int16Check($1.loc, "16-bit unsigned integer literal");
    286         $$ = parseContext.intermediate.addConstantUnion((unsigned short)$1.u, $1.loc, true);
    287 #endif
    288     }
    289     | FLOATCONSTANT {
    290         $$ = parseContext.intermediate.addConstantUnion($1.d, EbtFloat, $1.loc, true);
    291     }
    292     | DOUBLECONSTANT {
    293         parseContext.doubleCheck($1.loc, "double literal");
    294         $$ = parseContext.intermediate.addConstantUnion($1.d, EbtDouble, $1.loc, true);
    295     }
    296     | FLOAT16CONSTANT {
    297 #ifdef AMD_EXTENSIONS
    298         parseContext.float16Check($1.loc, "half float literal");
    299         $$ = parseContext.intermediate.addConstantUnion($1.d, EbtFloat16, $1.loc, true);
    300 #endif
    301     }
    302     | BOOLCONSTANT {
    303         $$ = parseContext.intermediate.addConstantUnion($1.b, $1.loc, true);
    304     }
    305     | LEFT_PAREN expression RIGHT_PAREN {
    306         $$ = $2;
    307         if ($$->getAsConstantUnion())
    308             $$->getAsConstantUnion()->setExpression();
    309     }
    310     ;
    311 
    312 postfix_expression
    313     : primary_expression {
    314         $$ = $1;
    315     }
    316     | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET {
    317         $$ = parseContext.handleBracketDereference($2.loc, $1, $3);
    318     }
    319     | function_call {
    320         $$ = $1;
    321     }
    322     | postfix_expression DOT IDENTIFIER {
    323         $$ = parseContext.handleDotDereference($3.loc, $1, *$3.string);
    324     }
    325     | postfix_expression INC_OP {
    326         parseContext.variableCheck($1);
    327         parseContext.lValueErrorCheck($2.loc, "++", $1);
    328         $$ = parseContext.handleUnaryMath($2.loc, "++", EOpPostIncrement, $1);
    329     }
    330     | postfix_expression DEC_OP {
    331         parseContext.variableCheck($1);
    332         parseContext.lValueErrorCheck($2.loc, "--", $1);
    333         $$ = parseContext.handleUnaryMath($2.loc, "--", EOpPostDecrement, $1);
    334     }
    335     ;
    336 
    337 integer_expression
    338     : expression {
    339         parseContext.integerCheck($1, "[]");
    340         $$ = $1;
    341     }
    342     ;
    343 
    344 function_call
    345     : function_call_or_method {
    346         $$ = parseContext.handleFunctionCall($1.loc, $1.function, $1.intermNode);
    347         delete $1.function;
    348     }
    349     ;
    350 
    351 function_call_or_method
    352     : function_call_generic {
    353         $$ = $1;
    354     }
    355     ;
    356 
    357 function_call_generic
    358     : function_call_header_with_parameters RIGHT_PAREN {
    359         $$ = $1;
    360         $$.loc = $2.loc;
    361     }
    362     | function_call_header_no_parameters RIGHT_PAREN {
    363         $$ = $1;
    364         $$.loc = $2.loc;
    365     }
    366     ;
    367 
    368 function_call_header_no_parameters
    369     : function_call_header VOID {
    370         $$ = $1;
    371     }
    372     | function_call_header {
    373         $$ = $1;
    374     }
    375     ;
    376 
    377 function_call_header_with_parameters
    378     : function_call_header assignment_expression {
    379         TParameter param = { 0, new TType };
    380         param.type->shallowCopy($2->getType());
    381         $1.function->addParameter(param);
    382         $$.function = $1.function;
    383         $$.intermNode = $2;
    384     }
    385     | function_call_header_with_parameters COMMA assignment_expression {
    386         TParameter param = { 0, new TType };
    387         param.type->shallowCopy($3->getType());
    388         $1.function->addParameter(param);
    389         $$.function = $1.function;
    390         $$.intermNode = parseContext.intermediate.growAggregate($1.intermNode, $3, $2.loc);
    391     }
    392     ;
    393 
    394 function_call_header
    395     : function_identifier LEFT_PAREN {
    396         $$ = $1;
    397     }
    398     ;
    399 
    400 // Grammar Note:  Constructors look like functions, but are recognized as types.
    401 
    402 function_identifier
    403     : type_specifier {
    404         // Constructor
    405         $$.intermNode = 0;
    406         $$.function = parseContext.handleConstructorCall($1.loc, $1);
    407     }
    408     | postfix_expression {
    409         //
    410         // Should be a method or subroutine call, but we haven't recognized the arguments yet.
    411         //
    412         $$.function = 0;
    413         $$.intermNode = 0;
    414 
    415         TIntermMethod* method = $1->getAsMethodNode();
    416         if (method) {
    417             $$.function = new TFunction(&method->getMethodName(), TType(EbtInt), EOpArrayLength);
    418             $$.intermNode = method->getObject();
    419         } else {
    420             TIntermSymbol* symbol = $1->getAsSymbolNode();
    421             if (symbol) {
    422                 parseContext.reservedErrorCheck(symbol->getLoc(), symbol->getName());
    423                 TFunction *function = new TFunction(&symbol->getName(), TType(EbtVoid));
    424                 $$.function = function;
    425             } else
    426                 parseContext.error($1->getLoc(), "function call, method, or subroutine call expected", "", "");
    427         }
    428 
    429         if ($$.function == 0) {
    430             // error recover
    431             TString empty("");
    432             $$.function = new TFunction(&empty, TType(EbtVoid), EOpNull);
    433         }
    434     }
    435     ;
    436 
    437 unary_expression
    438     : postfix_expression {
    439         parseContext.variableCheck($1);
    440         $$ = $1;
    441         if (TIntermMethod* method = $1->getAsMethodNode())
    442             parseContext.error($1->getLoc(), "incomplete method syntax", method->getMethodName().c_str(), "");
    443     }
    444     | INC_OP unary_expression {
    445         parseContext.lValueErrorCheck($1.loc, "++", $2);
    446         $$ = parseContext.handleUnaryMath($1.loc, "++", EOpPreIncrement, $2);
    447     }
    448     | DEC_OP unary_expression {
    449         parseContext.lValueErrorCheck($1.loc, "--", $2);
    450         $$ = parseContext.handleUnaryMath($1.loc, "--", EOpPreDecrement, $2);
    451     }
    452     | unary_operator unary_expression {
    453         if ($1.op != EOpNull) {
    454             char errorOp[2] = {0, 0};
    455             switch($1.op) {
    456             case EOpNegative:   errorOp[0] = '-'; break;
    457             case EOpLogicalNot: errorOp[0] = '!'; break;
    458             case EOpBitwiseNot: errorOp[0] = '~'; break;
    459             default: break; // some compilers want this
    460             }
    461             $$ = parseContext.handleUnaryMath($1.loc, errorOp, $1.op, $2);
    462         } else {
    463             $$ = $2;
    464             if ($$->getAsConstantUnion())
    465                 $$->getAsConstantUnion()->setExpression();
    466         }
    467     }
    468     ;
    469 // Grammar Note:  No traditional style type casts.
    470 
    471 unary_operator
    472     : PLUS  { $$.loc = $1.loc; $$.op = EOpNull; }
    473     | DASH  { $$.loc = $1.loc; $$.op = EOpNegative; }
    474     | BANG  { $$.loc = $1.loc; $$.op = EOpLogicalNot; }
    475     | TILDE { $$.loc = $1.loc; $$.op = EOpBitwiseNot;
    476               parseContext.fullIntegerCheck($1.loc, "bitwise not"); }
    477     ;
    478 // Grammar Note:  No '*' or '&' unary ops.  Pointers are not supported.
    479 
    480 multiplicative_expression
    481     : unary_expression { $$ = $1; }
    482     | multiplicative_expression STAR unary_expression {
    483         $$ = parseContext.handleBinaryMath($2.loc, "*", EOpMul, $1, $3);
    484         if ($$ == 0)
    485             $$ = $1;
    486     }
    487     | multiplicative_expression SLASH unary_expression {
    488         $$ = parseContext.handleBinaryMath($2.loc, "/", EOpDiv, $1, $3);
    489         if ($$ == 0)
    490             $$ = $1;
    491     }
    492     | multiplicative_expression PERCENT unary_expression {
    493         parseContext.fullIntegerCheck($2.loc, "%");
    494         $$ = parseContext.handleBinaryMath($2.loc, "%", EOpMod, $1, $3);
    495         if ($$ == 0)
    496             $$ = $1;
    497     }
    498     ;
    499 
    500 additive_expression
    501     : multiplicative_expression { $$ = $1; }
    502     | additive_expression PLUS multiplicative_expression {
    503         $$ = parseContext.handleBinaryMath($2.loc, "+", EOpAdd, $1, $3);
    504         if ($$ == 0)
    505             $$ = $1;
    506     }
    507     | additive_expression DASH multiplicative_expression {
    508         $$ = parseContext.handleBinaryMath($2.loc, "-", EOpSub, $1, $3);
    509         if ($$ == 0)
    510             $$ = $1;
    511     }
    512     ;
    513 
    514 shift_expression
    515     : additive_expression { $$ = $1; }
    516     | shift_expression LEFT_OP additive_expression {
    517         parseContext.fullIntegerCheck($2.loc, "bit shift left");
    518         $$ = parseContext.handleBinaryMath($2.loc, "<<", EOpLeftShift, $1, $3);
    519         if ($$ == 0)
    520             $$ = $1;
    521     }
    522     | shift_expression RIGHT_OP additive_expression {
    523         parseContext.fullIntegerCheck($2.loc, "bit shift right");
    524         $$ = parseContext.handleBinaryMath($2.loc, ">>", EOpRightShift, $1, $3);
    525         if ($$ == 0)
    526             $$ = $1;
    527     }
    528     ;
    529 
    530 relational_expression
    531     : shift_expression { $$ = $1; }
    532     | relational_expression LEFT_ANGLE shift_expression {
    533         $$ = parseContext.handleBinaryMath($2.loc, "<", EOpLessThan, $1, $3);
    534         if ($$ == 0)
    535             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    536     }
    537     | relational_expression RIGHT_ANGLE shift_expression  {
    538         $$ = parseContext.handleBinaryMath($2.loc, ">", EOpGreaterThan, $1, $3);
    539         if ($$ == 0)
    540             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    541     }
    542     | relational_expression LE_OP shift_expression  {
    543         $$ = parseContext.handleBinaryMath($2.loc, "<=", EOpLessThanEqual, $1, $3);
    544         if ($$ == 0)
    545             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    546     }
    547     | relational_expression GE_OP shift_expression  {
    548         $$ = parseContext.handleBinaryMath($2.loc, ">=", EOpGreaterThanEqual, $1, $3);
    549         if ($$ == 0)
    550             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    551     }
    552     ;
    553 
    554 equality_expression
    555     : relational_expression { $$ = $1; }
    556     | equality_expression EQ_OP relational_expression  {
    557         parseContext.arrayObjectCheck($2.loc, $1->getType(), "array comparison");
    558         parseContext.opaqueCheck($2.loc, $1->getType(), "==");
    559         parseContext.specializationCheck($2.loc, $1->getType(), "==");
    560         $$ = parseContext.handleBinaryMath($2.loc, "==", EOpEqual, $1, $3);
    561         if ($$ == 0)
    562             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    563     }
    564     | equality_expression NE_OP relational_expression {
    565         parseContext.arrayObjectCheck($2.loc, $1->getType(), "array comparison");
    566         parseContext.opaqueCheck($2.loc, $1->getType(), "!=");
    567         parseContext.specializationCheck($2.loc, $1->getType(), "!=");
    568         $$ = parseContext.handleBinaryMath($2.loc, "!=", EOpNotEqual, $1, $3);
    569         if ($$ == 0)
    570             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    571     }
    572     ;
    573 
    574 and_expression
    575     : equality_expression { $$ = $1; }
    576     | and_expression AMPERSAND equality_expression {
    577         parseContext.fullIntegerCheck($2.loc, "bitwise and");
    578         $$ = parseContext.handleBinaryMath($2.loc, "&", EOpAnd, $1, $3);
    579         if ($$ == 0)
    580             $$ = $1;
    581     }
    582     ;
    583 
    584 exclusive_or_expression
    585     : and_expression { $$ = $1; }
    586     | exclusive_or_expression CARET and_expression {
    587         parseContext.fullIntegerCheck($2.loc, "bitwise exclusive or");
    588         $$ = parseContext.handleBinaryMath($2.loc, "^", EOpExclusiveOr, $1, $3);
    589         if ($$ == 0)
    590             $$ = $1;
    591     }
    592     ;
    593 
    594 inclusive_or_expression
    595     : exclusive_or_expression { $$ = $1; }
    596     | inclusive_or_expression VERTICAL_BAR exclusive_or_expression {
    597         parseContext.fullIntegerCheck($2.loc, "bitwise inclusive or");
    598         $$ = parseContext.handleBinaryMath($2.loc, "|", EOpInclusiveOr, $1, $3);
    599         if ($$ == 0)
    600             $$ = $1;
    601     }
    602     ;
    603 
    604 logical_and_expression
    605     : inclusive_or_expression { $$ = $1; }
    606     | logical_and_expression AND_OP inclusive_or_expression {
    607         $$ = parseContext.handleBinaryMath($2.loc, "&&", EOpLogicalAnd, $1, $3);
    608         if ($$ == 0)
    609             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    610     }
    611     ;
    612 
    613 logical_xor_expression
    614     : logical_and_expression { $$ = $1; }
    615     | logical_xor_expression XOR_OP logical_and_expression  {
    616         $$ = parseContext.handleBinaryMath($2.loc, "^^", EOpLogicalXor, $1, $3);
    617         if ($$ == 0)
    618             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    619     }
    620     ;
    621 
    622 logical_or_expression
    623     : logical_xor_expression { $$ = $1; }
    624     | logical_or_expression OR_OP logical_xor_expression  {
    625         $$ = parseContext.handleBinaryMath($2.loc, "||", EOpLogicalOr, $1, $3);
    626         if ($$ == 0)
    627             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    628     }
    629     ;
    630 
    631 conditional_expression
    632     : logical_or_expression { $$ = $1; }
    633     | logical_or_expression QUESTION {
    634         ++parseContext.controlFlowNestingLevel;
    635     }
    636       expression COLON assignment_expression {
    637         --parseContext.controlFlowNestingLevel;
    638         parseContext.boolCheck($2.loc, $1);
    639         parseContext.rValueErrorCheck($2.loc, "?", $1);
    640         parseContext.rValueErrorCheck($5.loc, ":", $4);
    641         parseContext.rValueErrorCheck($5.loc, ":", $6);
    642         $$ = parseContext.intermediate.addSelection($1, $4, $6, $2.loc);
    643         if ($$ == 0) {
    644             parseContext.binaryOpError($2.loc, ":", $4->getCompleteString(), $6->getCompleteString());
    645             $$ = $6;
    646         }
    647     }
    648     ;
    649 
    650 assignment_expression
    651     : conditional_expression { $$ = $1; }
    652     | unary_expression assignment_operator assignment_expression {
    653         parseContext.arrayObjectCheck($2.loc, $1->getType(), "array assignment");
    654         parseContext.opaqueCheck($2.loc, $1->getType(), "=");
    655         parseContext.specializationCheck($2.loc, $1->getType(), "=");
    656         parseContext.lValueErrorCheck($2.loc, "assign", $1);
    657         parseContext.rValueErrorCheck($2.loc, "assign", $3);
    658         $$ = parseContext.intermediate.addAssign($2.op, $1, $3, $2.loc);
    659         if ($$ == 0) {
    660             parseContext.assignError($2.loc, "assign", $1->getCompleteString(), $3->getCompleteString());
    661             $$ = $1;
    662         }
    663     }
    664     ;
    665 
    666 assignment_operator
    667     : EQUAL {
    668         $$.loc = $1.loc;
    669         $$.op = EOpAssign;
    670     }
    671     | MUL_ASSIGN {
    672         $$.loc = $1.loc;
    673         $$.op = EOpMulAssign;
    674     }
    675     | DIV_ASSIGN {
    676         $$.loc = $1.loc;
    677         $$.op = EOpDivAssign;
    678     }
    679     | MOD_ASSIGN {
    680         parseContext.fullIntegerCheck($1.loc, "%=");
    681         $$.loc = $1.loc;
    682         $$.op = EOpModAssign;
    683     }
    684     | ADD_ASSIGN {
    685         $$.loc = $1.loc;
    686         $$.op = EOpAddAssign;
    687     }
    688     | SUB_ASSIGN {
    689         $$.loc = $1.loc;
    690         $$.op = EOpSubAssign;
    691     }
    692     | LEFT_ASSIGN {
    693         parseContext.fullIntegerCheck($1.loc, "bit-shift left assign");
    694         $$.loc = $1.loc; $$.op = EOpLeftShiftAssign;
    695     }
    696     | RIGHT_ASSIGN {
    697         parseContext.fullIntegerCheck($1.loc, "bit-shift right assign");
    698         $$.loc = $1.loc; $$.op = EOpRightShiftAssign;
    699     }
    700     | AND_ASSIGN {
    701         parseContext.fullIntegerCheck($1.loc, "bitwise-and assign");
    702         $$.loc = $1.loc; $$.op = EOpAndAssign;
    703     }
    704     | XOR_ASSIGN {
    705         parseContext.fullIntegerCheck($1.loc, "bitwise-xor assign");
    706         $$.loc = $1.loc; $$.op = EOpExclusiveOrAssign;
    707     }
    708     | OR_ASSIGN {
    709         parseContext.fullIntegerCheck($1.loc, "bitwise-or assign");
    710         $$.loc = $1.loc; $$.op = EOpInclusiveOrAssign;
    711     }
    712     ;
    713 
    714 expression
    715     : assignment_expression {
    716         $$ = $1;
    717     }
    718     | expression COMMA assignment_expression {
    719         parseContext.samplerConstructorLocationCheck($2.loc, ",", $3);
    720         $$ = parseContext.intermediate.addComma($1, $3, $2.loc);
    721         if ($$ == 0) {
    722             parseContext.binaryOpError($2.loc, ",", $1->getCompleteString(), $3->getCompleteString());
    723             $$ = $3;
    724         }
    725     }
    726     ;
    727 
    728 constant_expression
    729     : conditional_expression {
    730         parseContext.constantValueCheck($1, "");
    731         $$ = $1;
    732     }
    733     ;
    734 
    735 declaration
    736     : function_prototype SEMICOLON {
    737         parseContext.handleFunctionDeclarator($1.loc, *$1.function, true /* prototype */);
    738         $$ = 0;
    739         // TODO: 4.0 functionality: subroutines: make the identifier a user type for this signature
    740     }
    741     | init_declarator_list SEMICOLON {
    742         if ($1.intermNode && $1.intermNode->getAsAggregate())
    743             $1.intermNode->getAsAggregate()->setOperator(EOpSequence);
    744         $$ = $1.intermNode;
    745     }
    746     | PRECISION precision_qualifier type_specifier SEMICOLON {
    747         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement");
    748 
    749         // lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope
    750         parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]);
    751         parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision);
    752         $$ = 0;
    753     }
    754     | block_structure SEMICOLON {
    755         parseContext.declareBlock($1.loc, *$1.typeList);
    756         $$ = 0;
    757     }
    758     | block_structure IDENTIFIER SEMICOLON {
    759         parseContext.declareBlock($1.loc, *$1.typeList, $2.string);
    760         $$ = 0;
    761     }
    762     | block_structure IDENTIFIER array_specifier SEMICOLON {
    763         parseContext.declareBlock($1.loc, *$1.typeList, $2.string, $3.arraySizes);
    764         $$ = 0;
    765     }
    766     | type_qualifier SEMICOLON {
    767         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
    768         parseContext.updateStandaloneQualifierDefaults($1.loc, $1);
    769         $$ = 0;
    770     }
    771     | type_qualifier IDENTIFIER SEMICOLON {
    772         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    773         parseContext.addQualifierToExisting($1.loc, $1.qualifier, *$2.string);
    774         $$ = 0;
    775     }
    776     | type_qualifier IDENTIFIER identifier_list SEMICOLON {
    777         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    778         $3->push_back($2.string);
    779         parseContext.addQualifierToExisting($1.loc, $1.qualifier, *$3);
    780         $$ = 0;
    781     }
    782     ;
    783 
    784 block_structure
    785     : type_qualifier IDENTIFIER LEFT_BRACE { parseContext.nestedBlockCheck($1.loc); } struct_declaration_list RIGHT_BRACE {
    786         --parseContext.structNestingLevel;
    787         parseContext.blockName = $2.string;
    788         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
    789         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    790         parseContext.currentBlockQualifier = $1.qualifier;
    791         $$.loc = $1.loc;
    792         $$.typeList = $5;
    793     }
    794 
    795 identifier_list
    796     : COMMA IDENTIFIER {
    797         $$ = new TIdentifierList;
    798         $$->push_back($2.string);
    799     }
    800     | identifier_list COMMA IDENTIFIER {
    801         $$ = $1;
    802         $$->push_back($3.string);
    803     }
    804     ;
    805 
    806 function_prototype
    807     : function_declarator RIGHT_PAREN  {
    808         $$.function = $1;
    809         $$.loc = $2.loc;
    810     }
    811     ;
    812 
    813 function_declarator
    814     : function_header {
    815         $$ = $1;
    816     }
    817     | function_header_with_parameters {
    818         $$ = $1;
    819     }
    820     ;
    821 
    822 
    823 function_header_with_parameters
    824     : function_header parameter_declaration {
    825         // Add the parameter
    826         $$ = $1;
    827         if ($2.param.type->getBasicType() != EbtVoid)
    828             $1->addParameter($2.param);
    829         else
    830             delete $2.param.type;
    831     }
    832     | function_header_with_parameters COMMA parameter_declaration {
    833         //
    834         // Only first parameter of one-parameter functions can be void
    835         // The check for named parameters not being void is done in parameter_declarator
    836         //
    837         if ($3.param.type->getBasicType() == EbtVoid) {
    838             //
    839             // This parameter > first is void
    840             //
    841             parseContext.error($2.loc, "cannot be an argument type except for '(void)'", "void", "");
    842             delete $3.param.type;
    843         } else {
    844             // Add the parameter
    845             $$ = $1;
    846             $1->addParameter($3.param);
    847         }
    848     }
    849     ;
    850 
    851 function_header
    852     : fully_specified_type IDENTIFIER LEFT_PAREN {
    853         if ($1.qualifier.storage != EvqGlobal && $1.qualifier.storage != EvqTemporary) {
    854             parseContext.error($2.loc, "no qualifiers allowed for function return",
    855                                GetStorageQualifierString($1.qualifier.storage), "");
    856         }
    857         if ($1.arraySizes)
    858             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    859 
    860         // Add the function as a prototype after parsing it (we do not support recursion)
    861         TFunction *function;
    862         TType type($1);
    863         function = new TFunction($2.string, type);
    864         $$ = function;
    865     }
    866     ;
    867 
    868 parameter_declarator
    869     // Type + name
    870     : type_specifier IDENTIFIER {
    871         if ($1.arraySizes) {
    872             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
    873             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
    874             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    875         }
    876         if ($1.basicType == EbtVoid) {
    877             parseContext.error($2.loc, "illegal use of type 'void'", $2.string->c_str(), "");
    878         }
    879         parseContext.reservedErrorCheck($2.loc, *$2.string);
    880 
    881         TParameter param = {$2.string, new TType($1)};
    882         $$.loc = $2.loc;
    883         $$.param = param;
    884     }
    885     | type_specifier IDENTIFIER array_specifier {
    886         if ($1.arraySizes) {
    887             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
    888             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
    889             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    890         }
    891         parseContext.arrayDimCheck($2.loc, $1.arraySizes, $3.arraySizes);
    892 
    893         parseContext.arraySizeRequiredCheck($3.loc, *$3.arraySizes);
    894         parseContext.reservedErrorCheck($2.loc, *$2.string);
    895 
    896         $1.arraySizes = $3.arraySizes;
    897 
    898         TParameter param = { $2.string, new TType($1)};
    899         $$.loc = $2.loc;
    900         $$.param = param;
    901     }
    902     ;
    903 
    904 parameter_declaration
    905     //
    906     // With name
    907     //
    908     : type_qualifier parameter_declarator {
    909         $$ = $2;
    910         if ($1.qualifier.precision != EpqNone)
    911             $$.param.type->getQualifier().precision = $1.qualifier.precision;
    912         parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    913 
    914         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    915         parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type);
    916         parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type);
    917 
    918     }
    919     | parameter_declarator {
    920         $$ = $1;
    921 
    922         parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
    923         parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
    924         parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    925     }
    926     //
    927     // Without name
    928     //
    929     | type_qualifier parameter_type_specifier {
    930         $$ = $2;
    931         if ($1.qualifier.precision != EpqNone)
    932             $$.param.type->getQualifier().precision = $1.qualifier.precision;
    933         parseContext.precisionQualifierCheck($1.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    934 
    935         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    936         parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type);
    937         parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type);
    938     }
    939     | parameter_type_specifier {
    940         $$ = $1;
    941 
    942         parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
    943         parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
    944         parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    945     }
    946     ;
    947 
    948 parameter_type_specifier
    949     : type_specifier {
    950         TParameter param = { 0, new TType($1) };
    951         $$.param = param;
    952         if ($1.arraySizes)
    953             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    954     }
    955     ;
    956 
    957 init_declarator_list
    958     : single_declaration {
    959         $$ = $1;
    960     }
    961     | init_declarator_list COMMA IDENTIFIER {
    962         $$ = $1;
    963         parseContext.declareVariable($3.loc, *$3.string, $1.type);
    964     }
    965     | init_declarator_list COMMA IDENTIFIER array_specifier {
    966         $$ = $1;
    967         parseContext.declareVariable($3.loc, *$3.string, $1.type, $4.arraySizes);
    968     }
    969     | init_declarator_list COMMA IDENTIFIER array_specifier EQUAL initializer {
    970         $$.type = $1.type;
    971         TIntermNode* initNode = parseContext.declareVariable($3.loc, *$3.string, $1.type, $4.arraySizes, $6);
    972         $$.intermNode = parseContext.intermediate.growAggregate($1.intermNode, initNode, $5.loc);
    973     }
    974     | init_declarator_list COMMA IDENTIFIER EQUAL initializer {
    975         $$.type = $1.type;
    976         TIntermNode* initNode = parseContext.declareVariable($3.loc, *$3.string, $1.type, 0, $5);
    977         $$.intermNode = parseContext.intermediate.growAggregate($1.intermNode, initNode, $4.loc);
    978     }
    979     ;
    980 
    981 single_declaration
    982     : fully_specified_type {
    983         $$.type = $1;
    984         $$.intermNode = 0;
    985         parseContext.declareTypeDefaults($$.loc, $$.type);
    986     }
    987     | fully_specified_type IDENTIFIER {
    988         $$.type = $1;
    989         $$.intermNode = 0;
    990         parseContext.declareVariable($2.loc, *$2.string, $1);
    991     }
    992     | fully_specified_type IDENTIFIER array_specifier {
    993         $$.type = $1;
    994         $$.intermNode = 0;
    995         parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes);
    996     }
    997     | fully_specified_type IDENTIFIER array_specifier EQUAL initializer {
    998         $$.type = $1;
    999         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes, $5);
   1000         $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $4.loc);
   1001     }
   1002     | fully_specified_type IDENTIFIER EQUAL initializer {
   1003         $$.type = $1;
   1004         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, 0, $4);
   1005         $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $3.loc);
   1006     }
   1007 
   1008 // Grammar Note:  No 'enum', or 'typedef'.
   1009 
   1010 fully_specified_type
   1011     : type_specifier {
   1012         $$ = $1;
   1013 
   1014         parseContext.globalQualifierTypeCheck($1.loc, $1.qualifier, $$);
   1015         if ($1.arraySizes) {
   1016             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   1017             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
   1018         }
   1019 
   1020         parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier);
   1021     }
   1022     | type_qualifier type_specifier  {
   1023         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
   1024         parseContext.globalQualifierTypeCheck($1.loc, $1.qualifier, $2);
   1025 
   1026         if ($2.arraySizes) {
   1027             parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   1028             parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type");
   1029         }
   1030 
   1031         if ($2.arraySizes && parseContext.arrayQualifierError($2.loc, $1.qualifier))
   1032             $2.arraySizes = 0;
   1033 
   1034         parseContext.checkNoShaderLayouts($2.loc, $1.shaderQualifiers);
   1035         $2.shaderQualifiers.merge($1.shaderQualifiers);
   1036         parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
   1037         parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
   1038 
   1039         $$ = $2;
   1040 
   1041         if (! $$.qualifier.isInterpolation() &&
   1042             ((parseContext.language == EShLangVertex   && $$.qualifier.storage == EvqVaryingOut) ||
   1043              (parseContext.language == EShLangFragment && $$.qualifier.storage == EvqVaryingIn)))
   1044             $$.qualifier.smooth = true;
   1045     }
   1046     ;
   1047 
   1048 invariant_qualifier
   1049     : INVARIANT {
   1050         parseContext.globalCheck($1.loc, "invariant");
   1051         parseContext.profileRequires($$.loc, ENoProfile, 120, 0, "invariant");
   1052         $$.init($1.loc);
   1053         $$.qualifier.invariant = true;
   1054     }
   1055     ;
   1056 
   1057 interpolation_qualifier
   1058     : SMOOTH {
   1059         parseContext.globalCheck($1.loc, "smooth");
   1060         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "smooth");
   1061         parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "smooth");
   1062         $$.init($1.loc);
   1063         $$.qualifier.smooth = true;
   1064     }
   1065     | FLAT {
   1066         parseContext.globalCheck($1.loc, "flat");
   1067         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "flat");
   1068         parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "flat");
   1069         $$.init($1.loc);
   1070         $$.qualifier.flat = true;
   1071     }
   1072     | NOPERSPECTIVE {
   1073         parseContext.globalCheck($1.loc, "noperspective");
   1074         parseContext.requireProfile($1.loc, ~EEsProfile, "noperspective");
   1075         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "noperspective");
   1076         $$.init($1.loc);
   1077         $$.qualifier.nopersp = true;
   1078     }
   1079     | __EXPLICITINTERPAMD {
   1080 #ifdef AMD_EXTENSIONS
   1081         parseContext.globalCheck($1.loc, "__explicitInterpAMD");
   1082         parseContext.profileRequires($1.loc, ECoreProfile, 450, E_GL_AMD_shader_explicit_vertex_parameter, "explicit interpolation");
   1083         parseContext.profileRequires($1.loc, ECompatibilityProfile, 450, E_GL_AMD_shader_explicit_vertex_parameter, "explicit interpolation");
   1084         $$.init($1.loc);
   1085         $$.qualifier.explicitInterp = true;
   1086 #endif
   1087     }
   1088     ;
   1089 
   1090 layout_qualifier
   1091     : LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN {
   1092         $$ = $3;
   1093     }
   1094     ;
   1095 
   1096 layout_qualifier_id_list
   1097     : layout_qualifier_id {
   1098         $$ = $1;
   1099     }
   1100     | layout_qualifier_id_list COMMA layout_qualifier_id {
   1101         $$ = $1;
   1102         $$.shaderQualifiers.merge($3.shaderQualifiers);
   1103         parseContext.mergeObjectLayoutQualifiers($$.qualifier, $3.qualifier, false);
   1104     }
   1105 
   1106 layout_qualifier_id
   1107     : IDENTIFIER {
   1108         $$.init($1.loc);
   1109         parseContext.setLayoutQualifier($1.loc, $$, *$1.string);
   1110     }
   1111     | IDENTIFIER EQUAL constant_expression {
   1112         $$.init($1.loc);
   1113         parseContext.setLayoutQualifier($1.loc, $$, *$1.string, $3);
   1114     }
   1115     | SHARED { // because "shared" is both an identifier and a keyword
   1116         $$.init($1.loc);
   1117         TString strShared("shared");
   1118         parseContext.setLayoutQualifier($1.loc, $$, strShared);
   1119     }
   1120     ;
   1121 
   1122 precise_qualifier
   1123     : PRECISE {
   1124         parseContext.profileRequires($$.loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader5, "precise");
   1125         parseContext.profileRequires($1.loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5, "precise");
   1126         $$.init($1.loc);
   1127         $$.qualifier.noContraction = true;
   1128     }
   1129     ;
   1130 
   1131 type_qualifier
   1132     : single_type_qualifier {
   1133         $$ = $1;
   1134     }
   1135     | type_qualifier single_type_qualifier {
   1136         $$ = $1;
   1137         if ($$.basicType == EbtVoid)
   1138             $$.basicType = $2.basicType;
   1139 
   1140         $$.shaderQualifiers.merge($2.shaderQualifiers);
   1141         parseContext.mergeQualifiers($$.loc, $$.qualifier, $2.qualifier, false);
   1142     }
   1143     ;
   1144 
   1145 single_type_qualifier
   1146     : storage_qualifier {
   1147         $$ = $1;
   1148     }
   1149     | layout_qualifier {
   1150         $$ = $1;
   1151     }
   1152     | precision_qualifier {
   1153         parseContext.checkPrecisionQualifier($1.loc, $1.qualifier.precision);
   1154         $$ = $1;
   1155     }
   1156     | interpolation_qualifier {
   1157         // allow inheritance of storage qualifier from block declaration
   1158         $$ = $1;
   1159     }
   1160     | invariant_qualifier {
   1161         // allow inheritance of storage qualifier from block declaration
   1162         $$ = $1;
   1163     }
   1164     | precise_qualifier {
   1165         // allow inheritance of storage qualifier from block declaration
   1166         $$ = $1;
   1167     }
   1168     ;
   1169 
   1170 storage_qualifier
   1171     : CONST {
   1172         $$.init($1.loc);
   1173         $$.qualifier.storage = EvqConst;  // will later turn into EvqConstReadOnly, if the initializer is not constant
   1174     }
   1175     | ATTRIBUTE {
   1176         parseContext.requireStage($1.loc, EShLangVertex, "attribute");
   1177         parseContext.checkDeprecated($1.loc, ECoreProfile, 130, "attribute");
   1178         parseContext.checkDeprecated($1.loc, ENoProfile, 130, "attribute");
   1179         parseContext.requireNotRemoved($1.loc, ECoreProfile, 420, "attribute");
   1180         parseContext.requireNotRemoved($1.loc, EEsProfile, 300, "attribute");
   1181 
   1182         parseContext.globalCheck($1.loc, "attribute");
   1183 
   1184         $$.init($1.loc);
   1185         $$.qualifier.storage = EvqVaryingIn;
   1186     }
   1187     | VARYING {
   1188         parseContext.checkDeprecated($1.loc, ENoProfile, 130, "varying");
   1189         parseContext.checkDeprecated($1.loc, ECoreProfile, 130, "varying");
   1190         parseContext.requireNotRemoved($1.loc, ECoreProfile, 420, "varying");
   1191         parseContext.requireNotRemoved($1.loc, EEsProfile, 300, "varying");
   1192 
   1193         parseContext.globalCheck($1.loc, "varying");
   1194 
   1195         $$.init($1.loc);
   1196         if (parseContext.language == EShLangVertex)
   1197             $$.qualifier.storage = EvqVaryingOut;
   1198         else
   1199             $$.qualifier.storage = EvqVaryingIn;
   1200     }
   1201     | INOUT {
   1202         parseContext.globalCheck($1.loc, "inout");
   1203         $$.init($1.loc);
   1204         $$.qualifier.storage = EvqInOut;
   1205     }
   1206     | IN {
   1207         parseContext.globalCheck($1.loc, "in");
   1208         $$.init($1.loc);
   1209         // whether this is a parameter "in" or a pipeline "in" will get sorted out a bit later
   1210         $$.qualifier.storage = EvqIn;
   1211     }
   1212     | OUT {
   1213         parseContext.globalCheck($1.loc, "out");
   1214         $$.init($1.loc);
   1215         // whether this is a parameter "out" or a pipeline "out" will get sorted out a bit later
   1216         $$.qualifier.storage = EvqOut;
   1217     }
   1218     | CENTROID {
   1219         parseContext.profileRequires($1.loc, ENoProfile, 120, 0, "centroid");
   1220         parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "centroid");
   1221         parseContext.globalCheck($1.loc, "centroid");
   1222         $$.init($1.loc);
   1223         $$.qualifier.centroid = true;
   1224     }
   1225     | PATCH {
   1226         parseContext.globalCheck($1.loc, "patch");
   1227         parseContext.requireStage($1.loc, (EShLanguageMask)(EShLangTessControlMask | EShLangTessEvaluationMask), "patch");
   1228         $$.init($1.loc);
   1229         $$.qualifier.patch = true;
   1230     }
   1231     | SAMPLE {
   1232         parseContext.globalCheck($1.loc, "sample");
   1233         $$.init($1.loc);
   1234         $$.qualifier.sample = true;
   1235     }
   1236     | UNIFORM {
   1237         parseContext.globalCheck($1.loc, "uniform");
   1238         $$.init($1.loc);
   1239         $$.qualifier.storage = EvqUniform;
   1240     }
   1241     | BUFFER {
   1242         parseContext.globalCheck($1.loc, "buffer");
   1243         $$.init($1.loc);
   1244         $$.qualifier.storage = EvqBuffer;
   1245     }
   1246     | SHARED {
   1247         parseContext.globalCheck($1.loc, "shared");
   1248         parseContext.profileRequires($1.loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_compute_shader, "shared");
   1249         parseContext.profileRequires($1.loc, EEsProfile, 310, 0, "shared");
   1250         parseContext.requireStage($1.loc, EShLangCompute, "shared");
   1251         $$.init($1.loc);
   1252         $$.qualifier.storage = EvqShared;
   1253     }
   1254     | COHERENT {
   1255         $$.init($1.loc);
   1256         $$.qualifier.coherent = true;
   1257     }
   1258     | VOLATILE {
   1259         $$.init($1.loc);
   1260         $$.qualifier.volatil = true;
   1261     }
   1262     | RESTRICT {
   1263         $$.init($1.loc);
   1264         $$.qualifier.restrict = true;
   1265     }
   1266     | READONLY {
   1267         $$.init($1.loc);
   1268         $$.qualifier.readonly = true;
   1269     }
   1270     | WRITEONLY {
   1271         $$.init($1.loc);
   1272         $$.qualifier.writeonly = true;
   1273     }
   1274     | SUBROUTINE {
   1275         parseContext.spvRemoved($1.loc, "subroutine");
   1276         parseContext.globalCheck($1.loc, "subroutine");
   1277         parseContext.unimplemented($1.loc, "subroutine");
   1278         $$.init($1.loc);
   1279     }
   1280     | SUBROUTINE LEFT_PAREN type_name_list RIGHT_PAREN {
   1281         parseContext.spvRemoved($1.loc, "subroutine");
   1282         parseContext.globalCheck($1.loc, "subroutine");
   1283         parseContext.unimplemented($1.loc, "subroutine");
   1284         $$.init($1.loc);
   1285     }
   1286     ;
   1287 
   1288 type_name_list
   1289     : IDENTIFIER {
   1290         // TODO
   1291     }
   1292     | type_name_list COMMA IDENTIFIER {
   1293         // TODO: 4.0 semantics: subroutines
   1294         // 1) make sure each identifier is a type declared earlier with SUBROUTINE
   1295         // 2) save all of the identifiers for future comparison with the declared function
   1296     }
   1297     ;
   1298 
   1299 type_specifier
   1300     : type_specifier_nonarray {
   1301         $$ = $1;
   1302         $$.qualifier.precision = parseContext.getDefaultPrecision($$);
   1303     }
   1304     | type_specifier_nonarray array_specifier {
   1305         parseContext.arrayDimCheck($2.loc, $2.arraySizes, 0);
   1306         $$ = $1;
   1307         $$.qualifier.precision = parseContext.getDefaultPrecision($$);
   1308         $$.arraySizes = $2.arraySizes;
   1309     }
   1310     ;
   1311 
   1312 array_specifier
   1313     : LEFT_BRACKET RIGHT_BRACKET {
   1314         $$.loc = $1.loc;
   1315         $$.arraySizes = new TArraySizes;
   1316         $$.arraySizes->addInnerSize();
   1317     }
   1318     | LEFT_BRACKET conditional_expression RIGHT_BRACKET {
   1319         $$.loc = $1.loc;
   1320         $$.arraySizes = new TArraySizes;
   1321 
   1322         TArraySize size;
   1323         parseContext.arraySizeCheck($2->getLoc(), $2, size);
   1324         $$.arraySizes->addInnerSize(size);
   1325     }
   1326     | array_specifier LEFT_BRACKET RIGHT_BRACKET {
   1327         $$ = $1;
   1328         $$.arraySizes->addInnerSize();
   1329     }
   1330     | array_specifier LEFT_BRACKET conditional_expression RIGHT_BRACKET {
   1331         $$ = $1;
   1332 
   1333         TArraySize size;
   1334         parseContext.arraySizeCheck($3->getLoc(), $3, size);
   1335         $$.arraySizes->addInnerSize(size);
   1336     }
   1337     ;
   1338 
   1339 type_specifier_nonarray
   1340     : VOID {
   1341         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1342         $$.basicType = EbtVoid;
   1343     }
   1344     | FLOAT {
   1345         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1346         $$.basicType = EbtFloat;
   1347     }
   1348     | DOUBLE {
   1349         parseContext.doubleCheck($1.loc, "double");
   1350         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1351         $$.basicType = EbtDouble;
   1352     }
   1353     | FLOAT16_T {
   1354 #ifdef AMD_EXTENSIONS
   1355         parseContext.float16Check($1.loc, "half float", parseContext.symbolTable.atBuiltInLevel());
   1356         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1357         $$.basicType = EbtFloat16;
   1358 #endif
   1359     }
   1360     | INT {
   1361         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1362         $$.basicType = EbtInt;
   1363     }
   1364     | UINT {
   1365         parseContext.fullIntegerCheck($1.loc, "unsigned integer");
   1366         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1367         $$.basicType = EbtUint;
   1368     }
   1369     | INT64_T {
   1370         parseContext.int64Check($1.loc, "64-bit integer", parseContext.symbolTable.atBuiltInLevel());
   1371         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1372         $$.basicType = EbtInt64;
   1373     }
   1374     | UINT64_T {
   1375         parseContext.int64Check($1.loc, "64-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
   1376         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1377         $$.basicType = EbtUint64;
   1378     }
   1379     | INT16_T {
   1380 #ifdef AMD_EXTENSIONS
   1381         parseContext.int16Check($1.loc, "16-bit integer", parseContext.symbolTable.atBuiltInLevel());
   1382         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1383         $$.basicType = EbtInt16;
   1384 #endif
   1385     }
   1386     | UINT16_T {
   1387 #ifdef AMD_EXTENSIONS
   1388         parseContext.int16Check($1.loc, "16-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
   1389         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1390         $$.basicType = EbtUint16;
   1391 #endif
   1392     }
   1393     | BOOL {
   1394         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1395         $$.basicType = EbtBool;
   1396     }
   1397     | VEC2 {
   1398         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1399         $$.basicType = EbtFloat;
   1400         $$.setVector(2);
   1401     }
   1402     | VEC3 {
   1403         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1404         $$.basicType = EbtFloat;
   1405         $$.setVector(3);
   1406     }
   1407     | VEC4 {
   1408         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1409         $$.basicType = EbtFloat;
   1410         $$.setVector(4);
   1411     }
   1412     | DVEC2 {
   1413         parseContext.doubleCheck($1.loc, "double vector");
   1414         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1415         $$.basicType = EbtDouble;
   1416         $$.setVector(2);
   1417     }
   1418     | DVEC3 {
   1419         parseContext.doubleCheck($1.loc, "double vector");
   1420         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1421         $$.basicType = EbtDouble;
   1422         $$.setVector(3);
   1423     }
   1424     | DVEC4 {
   1425         parseContext.doubleCheck($1.loc, "double vector");
   1426         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1427         $$.basicType = EbtDouble;
   1428         $$.setVector(4);
   1429     }
   1430     | F16VEC2 {
   1431 #ifdef AMD_EXTENSIONS
   1432         parseContext.float16Check($1.loc, "half float vector", parseContext.symbolTable.atBuiltInLevel());
   1433         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1434         $$.basicType = EbtFloat16;
   1435         $$.setVector(2);
   1436 #endif
   1437     }
   1438     | F16VEC3 {
   1439 #ifdef AMD_EXTENSIONS
   1440         parseContext.float16Check($1.loc, "half float vector", parseContext.symbolTable.atBuiltInLevel());
   1441         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1442         $$.basicType = EbtFloat16;
   1443         $$.setVector(3);
   1444 #endif
   1445     }
   1446     | F16VEC4 {
   1447 #ifdef AMD_EXTENSIONS
   1448         parseContext.float16Check($1.loc, "half float vector", parseContext.symbolTable.atBuiltInLevel());
   1449         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1450         $$.basicType = EbtFloat16;
   1451         $$.setVector(4);
   1452 #endif
   1453     }
   1454     | BVEC2 {
   1455         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1456         $$.basicType = EbtBool;
   1457         $$.setVector(2);
   1458     }
   1459     | BVEC3 {
   1460         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1461         $$.basicType = EbtBool;
   1462         $$.setVector(3);
   1463     }
   1464     | BVEC4 {
   1465         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1466         $$.basicType = EbtBool;
   1467         $$.setVector(4);
   1468     }
   1469     | IVEC2 {
   1470         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1471         $$.basicType = EbtInt;
   1472         $$.setVector(2);
   1473     }
   1474     | IVEC3 {
   1475         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1476         $$.basicType = EbtInt;
   1477         $$.setVector(3);
   1478     }
   1479     | IVEC4 {
   1480         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1481         $$.basicType = EbtInt;
   1482         $$.setVector(4);
   1483     }
   1484     | I64VEC2 {
   1485         parseContext.int64Check($1.loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1486         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1487         $$.basicType = EbtInt64;
   1488         $$.setVector(2);
   1489     }
   1490     | I64VEC3 {
   1491         parseContext.int64Check($1.loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1492         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1493         $$.basicType = EbtInt64;
   1494         $$.setVector(3);
   1495     }
   1496     | I64VEC4 {
   1497         parseContext.int64Check($1.loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1498         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1499         $$.basicType = EbtInt64;
   1500         $$.setVector(4);
   1501     }
   1502     | I16VEC2 {
   1503 #ifdef AMD_EXTENSIONS
   1504         parseContext.int16Check($1.loc, "16-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1505         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1506         $$.basicType = EbtInt16;
   1507         $$.setVector(2);
   1508 #endif
   1509     }
   1510     | I16VEC3 {
   1511 #ifdef AMD_EXTENSIONS
   1512         parseContext.int16Check($1.loc, "16-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1513         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1514         $$.basicType = EbtInt16;
   1515         $$.setVector(3);
   1516 #endif
   1517     }
   1518     | I16VEC4 {
   1519 #ifdef AMD_EXTENSIONS
   1520         parseContext.int16Check($1.loc, "16-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1521         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1522         $$.basicType = EbtInt16;
   1523         $$.setVector(4);
   1524 #endif
   1525     }
   1526     | UVEC2 {
   1527         parseContext.fullIntegerCheck($1.loc, "unsigned integer vector");
   1528         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1529         $$.basicType = EbtUint;
   1530         $$.setVector(2);
   1531     }
   1532     | UVEC3 {
   1533         parseContext.fullIntegerCheck($1.loc, "unsigned integer vector");
   1534         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1535         $$.basicType = EbtUint;
   1536         $$.setVector(3);
   1537     }
   1538     | UVEC4 {
   1539         parseContext.fullIntegerCheck($1.loc, "unsigned integer vector");
   1540         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1541         $$.basicType = EbtUint;
   1542         $$.setVector(4);
   1543     }
   1544     | U64VEC2 {
   1545         parseContext.int64Check($1.loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1546         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1547         $$.basicType = EbtUint64;
   1548         $$.setVector(2);
   1549     }
   1550     | U64VEC3 {
   1551         parseContext.int64Check($1.loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1552         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1553         $$.basicType = EbtUint64;
   1554         $$.setVector(3);
   1555     }
   1556     | U64VEC4 {
   1557         parseContext.int64Check($1.loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1558         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1559         $$.basicType = EbtUint64;
   1560         $$.setVector(4);
   1561     }
   1562     | U16VEC2 {
   1563 #ifdef AMD_EXTENSIONS
   1564         parseContext.int16Check($1.loc, "16-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1565         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1566         $$.basicType = EbtUint16;
   1567         $$.setVector(2);
   1568 #endif
   1569     }
   1570     | U16VEC3 {
   1571 #ifdef AMD_EXTENSIONS
   1572         parseContext.int16Check($1.loc, "16-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1573         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1574         $$.basicType = EbtUint16;
   1575         $$.setVector(3);
   1576 #endif
   1577     }
   1578     | U16VEC4 {
   1579 #ifdef AMD_EXTENSIONS
   1580         parseContext.int16Check($1.loc, "16-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1581         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1582         $$.basicType = EbtUint16;
   1583         $$.setVector(4);
   1584 #endif
   1585     }
   1586     | MAT2 {
   1587         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1588         $$.basicType = EbtFloat;
   1589         $$.setMatrix(2, 2);
   1590     }
   1591     | MAT3 {
   1592         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1593         $$.basicType = EbtFloat;
   1594         $$.setMatrix(3, 3);
   1595     }
   1596     | MAT4 {
   1597         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1598         $$.basicType = EbtFloat;
   1599         $$.setMatrix(4, 4);
   1600     }
   1601     | MAT2X2 {
   1602         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1603         $$.basicType = EbtFloat;
   1604         $$.setMatrix(2, 2);
   1605     }
   1606     | MAT2X3 {
   1607         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1608         $$.basicType = EbtFloat;
   1609         $$.setMatrix(2, 3);
   1610     }
   1611     | MAT2X4 {
   1612         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1613         $$.basicType = EbtFloat;
   1614         $$.setMatrix(2, 4);
   1615     }
   1616     | MAT3X2 {
   1617         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1618         $$.basicType = EbtFloat;
   1619         $$.setMatrix(3, 2);
   1620     }
   1621     | MAT3X3 {
   1622         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1623         $$.basicType = EbtFloat;
   1624         $$.setMatrix(3, 3);
   1625     }
   1626     | MAT3X4 {
   1627         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1628         $$.basicType = EbtFloat;
   1629         $$.setMatrix(3, 4);
   1630     }
   1631     | MAT4X2 {
   1632         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1633         $$.basicType = EbtFloat;
   1634         $$.setMatrix(4, 2);
   1635     }
   1636     | MAT4X3 {
   1637         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1638         $$.basicType = EbtFloat;
   1639         $$.setMatrix(4, 3);
   1640     }
   1641     | MAT4X4 {
   1642         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1643         $$.basicType = EbtFloat;
   1644         $$.setMatrix(4, 4);
   1645     }
   1646     | DMAT2 {
   1647         parseContext.doubleCheck($1.loc, "double matrix");
   1648         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1649         $$.basicType = EbtDouble;
   1650         $$.setMatrix(2, 2);
   1651     }
   1652     | DMAT3 {
   1653         parseContext.doubleCheck($1.loc, "double matrix");
   1654         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1655         $$.basicType = EbtDouble;
   1656         $$.setMatrix(3, 3);
   1657     }
   1658     | DMAT4 {
   1659         parseContext.doubleCheck($1.loc, "double matrix");
   1660         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1661         $$.basicType = EbtDouble;
   1662         $$.setMatrix(4, 4);
   1663     }
   1664     | DMAT2X2 {
   1665         parseContext.doubleCheck($1.loc, "double matrix");
   1666         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1667         $$.basicType = EbtDouble;
   1668         $$.setMatrix(2, 2);
   1669     }
   1670     | DMAT2X3 {
   1671         parseContext.doubleCheck($1.loc, "double matrix");
   1672         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1673         $$.basicType = EbtDouble;
   1674         $$.setMatrix(2, 3);
   1675     }
   1676     | DMAT2X4 {
   1677         parseContext.doubleCheck($1.loc, "double matrix");
   1678         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1679         $$.basicType = EbtDouble;
   1680         $$.setMatrix(2, 4);
   1681     }
   1682     | DMAT3X2 {
   1683         parseContext.doubleCheck($1.loc, "double matrix");
   1684         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1685         $$.basicType = EbtDouble;
   1686         $$.setMatrix(3, 2);
   1687     }
   1688     | DMAT3X3 {
   1689         parseContext.doubleCheck($1.loc, "double matrix");
   1690         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1691         $$.basicType = EbtDouble;
   1692         $$.setMatrix(3, 3);
   1693     }
   1694     | DMAT3X4 {
   1695         parseContext.doubleCheck($1.loc, "double matrix");
   1696         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1697         $$.basicType = EbtDouble;
   1698         $$.setMatrix(3, 4);
   1699     }
   1700     | DMAT4X2 {
   1701         parseContext.doubleCheck($1.loc, "double matrix");
   1702         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1703         $$.basicType = EbtDouble;
   1704         $$.setMatrix(4, 2);
   1705     }
   1706     | DMAT4X3 {
   1707         parseContext.doubleCheck($1.loc, "double matrix");
   1708         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1709         $$.basicType = EbtDouble;
   1710         $$.setMatrix(4, 3);
   1711     }
   1712     | DMAT4X4 {
   1713         parseContext.doubleCheck($1.loc, "double matrix");
   1714         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1715         $$.basicType = EbtDouble;
   1716         $$.setMatrix(4, 4);
   1717     }
   1718     | F16MAT2 {
   1719 #ifdef AMD_EXTENSIONS
   1720         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1721         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1722         $$.basicType = EbtFloat16;
   1723         $$.setMatrix(2, 2);
   1724 #endif
   1725     }
   1726     | F16MAT3 {
   1727 #ifdef AMD_EXTENSIONS
   1728         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1729         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1730         $$.basicType = EbtFloat16;
   1731         $$.setMatrix(3, 3);
   1732 #endif
   1733     }
   1734     | F16MAT4 {
   1735 #ifdef AMD_EXTENSIONS
   1736         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1737         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1738         $$.basicType = EbtFloat16;
   1739         $$.setMatrix(4, 4);
   1740 #endif
   1741     }
   1742     | F16MAT2X2 {
   1743 #ifdef AMD_EXTENSIONS
   1744         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1745         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1746         $$.basicType = EbtFloat16;
   1747         $$.setMatrix(2, 2);
   1748 #endif
   1749     }
   1750     | F16MAT2X3 {
   1751 #ifdef AMD_EXTENSIONS
   1752         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1753         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1754         $$.basicType = EbtFloat16;
   1755         $$.setMatrix(2, 3);
   1756 #endif
   1757     }
   1758     | F16MAT2X4 {
   1759 #ifdef AMD_EXTENSIONS
   1760         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1761         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1762         $$.basicType = EbtFloat16;
   1763         $$.setMatrix(2, 4);
   1764 #endif
   1765     }
   1766     | F16MAT3X2 {
   1767 #ifdef AMD_EXTENSIONS
   1768         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1769         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1770         $$.basicType = EbtFloat16;
   1771         $$.setMatrix(3, 2);
   1772 #endif
   1773     }
   1774     | F16MAT3X3 {
   1775 #ifdef AMD_EXTENSIONS
   1776         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1777         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1778         $$.basicType = EbtFloat16;
   1779         $$.setMatrix(3, 3);
   1780 #endif
   1781     }
   1782     | F16MAT3X4 {
   1783 #ifdef AMD_EXTENSIONS
   1784         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1785         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1786         $$.basicType = EbtFloat16;
   1787         $$.setMatrix(3, 4);
   1788 #endif
   1789     }
   1790     | F16MAT4X2 {
   1791 #ifdef AMD_EXTENSIONS
   1792         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1793         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1794         $$.basicType = EbtFloat16;
   1795         $$.setMatrix(4, 2);
   1796 #endif
   1797     }
   1798     | F16MAT4X3 {
   1799 #ifdef AMD_EXTENSIONS
   1800         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1801         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1802         $$.basicType = EbtFloat16;
   1803         $$.setMatrix(4, 3);
   1804 #endif
   1805     }
   1806     | F16MAT4X4 {
   1807 #ifdef AMD_EXTENSIONS
   1808         parseContext.float16Check($1.loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
   1809         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1810         $$.basicType = EbtFloat16;
   1811         $$.setMatrix(4, 4);
   1812 #endif
   1813     }
   1814     | ATOMIC_UINT {
   1815         parseContext.vulkanRemoved($1.loc, "atomic counter types");
   1816         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1817         $$.basicType = EbtAtomicUint;
   1818     }
   1819     | SAMPLER1D {
   1820         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1821         $$.basicType = EbtSampler;
   1822         $$.sampler.set(EbtFloat, Esd1D);
   1823     }
   1824     | SAMPLER2D {
   1825         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1826         $$.basicType = EbtSampler;
   1827         $$.sampler.set(EbtFloat, Esd2D);
   1828     }
   1829     | SAMPLER3D {
   1830         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1831         $$.basicType = EbtSampler;
   1832         $$.sampler.set(EbtFloat, Esd3D);
   1833     }
   1834     | SAMPLERCUBE {
   1835         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1836         $$.basicType = EbtSampler;
   1837         $$.sampler.set(EbtFloat, EsdCube);
   1838     }
   1839     | SAMPLER1DSHADOW {
   1840         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1841         $$.basicType = EbtSampler;
   1842         $$.sampler.set(EbtFloat, Esd1D, false, true);
   1843     }
   1844     | SAMPLER2DSHADOW {
   1845         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1846         $$.basicType = EbtSampler;
   1847         $$.sampler.set(EbtFloat, Esd2D, false, true);
   1848     }
   1849     | SAMPLERCUBESHADOW {
   1850         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1851         $$.basicType = EbtSampler;
   1852         $$.sampler.set(EbtFloat, EsdCube, false, true);
   1853     }
   1854     | SAMPLER1DARRAY {
   1855         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1856         $$.basicType = EbtSampler;
   1857         $$.sampler.set(EbtFloat, Esd1D, true);
   1858     }
   1859     | SAMPLER2DARRAY {
   1860         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1861         $$.basicType = EbtSampler;
   1862         $$.sampler.set(EbtFloat, Esd2D, true);
   1863     }
   1864     | SAMPLER1DARRAYSHADOW {
   1865         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1866         $$.basicType = EbtSampler;
   1867         $$.sampler.set(EbtFloat, Esd1D, true, true);
   1868     }
   1869     | SAMPLER2DARRAYSHADOW {
   1870         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1871         $$.basicType = EbtSampler;
   1872         $$.sampler.set(EbtFloat, Esd2D, true, true);
   1873     }
   1874     | SAMPLERCUBEARRAY {
   1875         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1876         $$.basicType = EbtSampler;
   1877         $$.sampler.set(EbtFloat, EsdCube, true);
   1878     }
   1879     | SAMPLERCUBEARRAYSHADOW {
   1880         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1881         $$.basicType = EbtSampler;
   1882         $$.sampler.set(EbtFloat, EsdCube, true, true);
   1883     }
   1884     | ISAMPLER1D {
   1885         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1886         $$.basicType = EbtSampler;
   1887         $$.sampler.set(EbtInt, Esd1D);
   1888     }
   1889     | ISAMPLER2D {
   1890         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1891         $$.basicType = EbtSampler;
   1892         $$.sampler.set(EbtInt, Esd2D);
   1893     }
   1894     | ISAMPLER3D {
   1895         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1896         $$.basicType = EbtSampler;
   1897         $$.sampler.set(EbtInt, Esd3D);
   1898     }
   1899     | ISAMPLERCUBE {
   1900         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1901         $$.basicType = EbtSampler;
   1902         $$.sampler.set(EbtInt, EsdCube);
   1903     }
   1904     | ISAMPLER1DARRAY {
   1905         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1906         $$.basicType = EbtSampler;
   1907         $$.sampler.set(EbtInt, Esd1D, true);
   1908     }
   1909     | ISAMPLER2DARRAY {
   1910         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1911         $$.basicType = EbtSampler;
   1912         $$.sampler.set(EbtInt, Esd2D, true);
   1913     }
   1914     | ISAMPLERCUBEARRAY {
   1915         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1916         $$.basicType = EbtSampler;
   1917         $$.sampler.set(EbtInt, EsdCube, true);
   1918     }
   1919     | USAMPLER1D {
   1920         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1921         $$.basicType = EbtSampler;
   1922         $$.sampler.set(EbtUint, Esd1D);
   1923     }
   1924     | USAMPLER2D {
   1925         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1926         $$.basicType = EbtSampler;
   1927         $$.sampler.set(EbtUint, Esd2D);
   1928     }
   1929     | USAMPLER3D {
   1930         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1931         $$.basicType = EbtSampler;
   1932         $$.sampler.set(EbtUint, Esd3D);
   1933     }
   1934     | USAMPLERCUBE {
   1935         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1936         $$.basicType = EbtSampler;
   1937         $$.sampler.set(EbtUint, EsdCube);
   1938     }
   1939     | USAMPLER1DARRAY {
   1940         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1941         $$.basicType = EbtSampler;
   1942         $$.sampler.set(EbtUint, Esd1D, true);
   1943     }
   1944     | USAMPLER2DARRAY {
   1945         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1946         $$.basicType = EbtSampler;
   1947         $$.sampler.set(EbtUint, Esd2D, true);
   1948     }
   1949     | USAMPLERCUBEARRAY {
   1950         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1951         $$.basicType = EbtSampler;
   1952         $$.sampler.set(EbtUint, EsdCube, true);
   1953     }
   1954     | SAMPLER2DRECT {
   1955         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1956         $$.basicType = EbtSampler;
   1957         $$.sampler.set(EbtFloat, EsdRect);
   1958     }
   1959     | SAMPLER2DRECTSHADOW {
   1960         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1961         $$.basicType = EbtSampler;
   1962         $$.sampler.set(EbtFloat, EsdRect, false, true);
   1963     }
   1964     | ISAMPLER2DRECT {
   1965         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1966         $$.basicType = EbtSampler;
   1967         $$.sampler.set(EbtInt, EsdRect);
   1968     }
   1969     | USAMPLER2DRECT {
   1970         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1971         $$.basicType = EbtSampler;
   1972         $$.sampler.set(EbtUint, EsdRect);
   1973     }
   1974     | SAMPLERBUFFER {
   1975         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1976         $$.basicType = EbtSampler;
   1977         $$.sampler.set(EbtFloat, EsdBuffer);
   1978     }
   1979     | ISAMPLERBUFFER {
   1980         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1981         $$.basicType = EbtSampler;
   1982         $$.sampler.set(EbtInt, EsdBuffer);
   1983     }
   1984     | USAMPLERBUFFER {
   1985         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1986         $$.basicType = EbtSampler;
   1987         $$.sampler.set(EbtUint, EsdBuffer);
   1988     }
   1989     | SAMPLER2DMS {
   1990         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1991         $$.basicType = EbtSampler;
   1992         $$.sampler.set(EbtFloat, Esd2D, false, false, true);
   1993     }
   1994     | ISAMPLER2DMS {
   1995         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1996         $$.basicType = EbtSampler;
   1997         $$.sampler.set(EbtInt, Esd2D, false, false, true);
   1998     }
   1999     | USAMPLER2DMS {
   2000         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2001         $$.basicType = EbtSampler;
   2002         $$.sampler.set(EbtUint, Esd2D, false, false, true);
   2003     }
   2004     | SAMPLER2DMSARRAY {
   2005         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2006         $$.basicType = EbtSampler;
   2007         $$.sampler.set(EbtFloat, Esd2D, true, false, true);
   2008     }
   2009     | ISAMPLER2DMSARRAY {
   2010         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2011         $$.basicType = EbtSampler;
   2012         $$.sampler.set(EbtInt, Esd2D, true, false, true);
   2013     }
   2014     | USAMPLER2DMSARRAY {
   2015         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2016         $$.basicType = EbtSampler;
   2017         $$.sampler.set(EbtUint, Esd2D, true, false, true);
   2018     }
   2019     | SAMPLER {
   2020         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2021         $$.basicType = EbtSampler;
   2022         $$.sampler.setPureSampler(false);
   2023     }
   2024     | SAMPLERSHADOW {
   2025         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2026         $$.basicType = EbtSampler;
   2027         $$.sampler.setPureSampler(true);
   2028     }
   2029     | TEXTURE1D {
   2030         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2031         $$.basicType = EbtSampler;
   2032         $$.sampler.setTexture(EbtFloat, Esd1D);
   2033     }
   2034     | TEXTURE2D {
   2035         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2036         $$.basicType = EbtSampler;
   2037         $$.sampler.setTexture(EbtFloat, Esd2D);
   2038     }
   2039     | TEXTURE3D {
   2040         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2041         $$.basicType = EbtSampler;
   2042         $$.sampler.setTexture(EbtFloat, Esd3D);
   2043     }
   2044     | TEXTURECUBE {
   2045         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2046         $$.basicType = EbtSampler;
   2047         $$.sampler.setTexture(EbtFloat, EsdCube);
   2048     }
   2049     | TEXTURE1DARRAY {
   2050         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2051         $$.basicType = EbtSampler;
   2052         $$.sampler.setTexture(EbtFloat, Esd1D, true);
   2053     }
   2054     | TEXTURE2DARRAY {
   2055         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2056         $$.basicType = EbtSampler;
   2057         $$.sampler.setTexture(EbtFloat, Esd2D, true);
   2058     }
   2059     | TEXTURECUBEARRAY {
   2060         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2061         $$.basicType = EbtSampler;
   2062         $$.sampler.setTexture(EbtFloat, EsdCube, true);
   2063     }
   2064     | ITEXTURE1D {
   2065         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2066         $$.basicType = EbtSampler;
   2067         $$.sampler.setTexture(EbtInt, Esd1D);
   2068     }
   2069     | ITEXTURE2D {
   2070         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2071         $$.basicType = EbtSampler;
   2072         $$.sampler.setTexture(EbtInt, Esd2D);
   2073     }
   2074     | ITEXTURE3D {
   2075         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2076         $$.basicType = EbtSampler;
   2077         $$.sampler.setTexture(EbtInt, Esd3D);
   2078     }
   2079     | ITEXTURECUBE {
   2080         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2081         $$.basicType = EbtSampler;
   2082         $$.sampler.setTexture(EbtInt, EsdCube);
   2083     }
   2084     | ITEXTURE1DARRAY {
   2085         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2086         $$.basicType = EbtSampler;
   2087         $$.sampler.setTexture(EbtInt, Esd1D, true);
   2088     }
   2089     | ITEXTURE2DARRAY {
   2090         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2091         $$.basicType = EbtSampler;
   2092         $$.sampler.setTexture(EbtInt, Esd2D, true);
   2093     }
   2094     | ITEXTURECUBEARRAY {
   2095         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2096         $$.basicType = EbtSampler;
   2097         $$.sampler.setTexture(EbtInt, EsdCube, true);
   2098     }
   2099     | UTEXTURE1D {
   2100         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2101         $$.basicType = EbtSampler;
   2102         $$.sampler.setTexture(EbtUint, Esd1D);
   2103     }
   2104     | UTEXTURE2D {
   2105         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2106         $$.basicType = EbtSampler;
   2107         $$.sampler.setTexture(EbtUint, Esd2D);
   2108     }
   2109     | UTEXTURE3D {
   2110         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2111         $$.basicType = EbtSampler;
   2112         $$.sampler.setTexture(EbtUint, Esd3D);
   2113     }
   2114     | UTEXTURECUBE {
   2115         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2116         $$.basicType = EbtSampler;
   2117         $$.sampler.setTexture(EbtUint, EsdCube);
   2118     }
   2119     | UTEXTURE1DARRAY {
   2120         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2121         $$.basicType = EbtSampler;
   2122         $$.sampler.setTexture(EbtUint, Esd1D, true);
   2123     }
   2124     | UTEXTURE2DARRAY {
   2125         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2126         $$.basicType = EbtSampler;
   2127         $$.sampler.setTexture(EbtUint, Esd2D, true);
   2128     }
   2129     | UTEXTURECUBEARRAY {
   2130         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2131         $$.basicType = EbtSampler;
   2132         $$.sampler.setTexture(EbtUint, EsdCube, true);
   2133     }
   2134     | TEXTURE2DRECT {
   2135         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2136         $$.basicType = EbtSampler;
   2137         $$.sampler.setTexture(EbtFloat, EsdRect);
   2138     }
   2139     | ITEXTURE2DRECT {
   2140         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2141         $$.basicType = EbtSampler;
   2142         $$.sampler.setTexture(EbtInt, EsdRect);
   2143     }
   2144     | UTEXTURE2DRECT {
   2145         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2146         $$.basicType = EbtSampler;
   2147         $$.sampler.setTexture(EbtUint, EsdRect);
   2148     }
   2149     | TEXTUREBUFFER {
   2150         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2151         $$.basicType = EbtSampler;
   2152         $$.sampler.setTexture(EbtFloat, EsdBuffer);
   2153     }
   2154     | ITEXTUREBUFFER {
   2155         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2156         $$.basicType = EbtSampler;
   2157         $$.sampler.setTexture(EbtInt, EsdBuffer);
   2158     }
   2159     | UTEXTUREBUFFER {
   2160         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2161         $$.basicType = EbtSampler;
   2162         $$.sampler.setTexture(EbtUint, EsdBuffer);
   2163     }
   2164     | TEXTURE2DMS {
   2165         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2166         $$.basicType = EbtSampler;
   2167         $$.sampler.setTexture(EbtFloat, Esd2D, false, false, true);
   2168     }
   2169     | ITEXTURE2DMS {
   2170         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2171         $$.basicType = EbtSampler;
   2172         $$.sampler.setTexture(EbtInt, Esd2D, false, false, true);
   2173     }
   2174     | UTEXTURE2DMS {
   2175         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2176         $$.basicType = EbtSampler;
   2177         $$.sampler.setTexture(EbtUint, Esd2D, false, false, true);
   2178     }
   2179     | TEXTURE2DMSARRAY {
   2180         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2181         $$.basicType = EbtSampler;
   2182         $$.sampler.setTexture(EbtFloat, Esd2D, true, false, true);
   2183     }
   2184     | ITEXTURE2DMSARRAY {
   2185         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2186         $$.basicType = EbtSampler;
   2187         $$.sampler.setTexture(EbtInt, Esd2D, true, false, true);
   2188     }
   2189     | UTEXTURE2DMSARRAY {
   2190         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2191         $$.basicType = EbtSampler;
   2192         $$.sampler.setTexture(EbtUint, Esd2D, true, false, true);
   2193     }
   2194     | IMAGE1D {
   2195         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2196         $$.basicType = EbtSampler;
   2197         $$.sampler.setImage(EbtFloat, Esd1D);
   2198     }
   2199     | IIMAGE1D {
   2200         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2201         $$.basicType = EbtSampler;
   2202         $$.sampler.setImage(EbtInt, Esd1D);
   2203     }
   2204     | UIMAGE1D {
   2205         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2206         $$.basicType = EbtSampler;
   2207         $$.sampler.setImage(EbtUint, Esd1D);
   2208     }
   2209     | IMAGE2D {
   2210         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2211         $$.basicType = EbtSampler;
   2212         $$.sampler.setImage(EbtFloat, Esd2D);
   2213     }
   2214     | IIMAGE2D {
   2215         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2216         $$.basicType = EbtSampler;
   2217         $$.sampler.setImage(EbtInt, Esd2D);
   2218     }
   2219     | UIMAGE2D {
   2220         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2221         $$.basicType = EbtSampler;
   2222         $$.sampler.setImage(EbtUint, Esd2D);
   2223     }
   2224     | IMAGE3D {
   2225         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2226         $$.basicType = EbtSampler;
   2227         $$.sampler.setImage(EbtFloat, Esd3D);
   2228     }
   2229     | IIMAGE3D {
   2230         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2231         $$.basicType = EbtSampler;
   2232         $$.sampler.setImage(EbtInt, Esd3D);
   2233     }
   2234     | UIMAGE3D {
   2235         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2236         $$.basicType = EbtSampler;
   2237         $$.sampler.setImage(EbtUint, Esd3D);
   2238     }
   2239     | IMAGE2DRECT {
   2240         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2241         $$.basicType = EbtSampler;
   2242         $$.sampler.setImage(EbtFloat, EsdRect);
   2243     }
   2244     | IIMAGE2DRECT {
   2245         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2246         $$.basicType = EbtSampler;
   2247         $$.sampler.setImage(EbtInt, EsdRect);
   2248     }
   2249     | UIMAGE2DRECT {
   2250         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2251         $$.basicType = EbtSampler;
   2252         $$.sampler.setImage(EbtUint, EsdRect);
   2253     }
   2254     | IMAGECUBE {
   2255         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2256         $$.basicType = EbtSampler;
   2257         $$.sampler.setImage(EbtFloat, EsdCube);
   2258     }
   2259     | IIMAGECUBE {
   2260         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2261         $$.basicType = EbtSampler;
   2262         $$.sampler.setImage(EbtInt, EsdCube);
   2263     }
   2264     | UIMAGECUBE {
   2265         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2266         $$.basicType = EbtSampler;
   2267         $$.sampler.setImage(EbtUint, EsdCube);
   2268     }
   2269     | IMAGEBUFFER {
   2270         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2271         $$.basicType = EbtSampler;
   2272         $$.sampler.setImage(EbtFloat, EsdBuffer);
   2273     }
   2274     | IIMAGEBUFFER {
   2275         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2276         $$.basicType = EbtSampler;
   2277         $$.sampler.setImage(EbtInt, EsdBuffer);
   2278     }
   2279     | UIMAGEBUFFER {
   2280         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2281         $$.basicType = EbtSampler;
   2282         $$.sampler.setImage(EbtUint, EsdBuffer);
   2283     }
   2284     | IMAGE1DARRAY {
   2285         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2286         $$.basicType = EbtSampler;
   2287         $$.sampler.setImage(EbtFloat, Esd1D, true);
   2288     }
   2289     | IIMAGE1DARRAY {
   2290         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2291         $$.basicType = EbtSampler;
   2292         $$.sampler.setImage(EbtInt, Esd1D, true);
   2293     }
   2294     | UIMAGE1DARRAY {
   2295         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2296         $$.basicType = EbtSampler;
   2297         $$.sampler.setImage(EbtUint, Esd1D, true);
   2298     }
   2299     | IMAGE2DARRAY {
   2300         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2301         $$.basicType = EbtSampler;
   2302         $$.sampler.setImage(EbtFloat, Esd2D, true);
   2303     }
   2304     | IIMAGE2DARRAY {
   2305         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2306         $$.basicType = EbtSampler;
   2307         $$.sampler.setImage(EbtInt, Esd2D, true);
   2308     }
   2309     | UIMAGE2DARRAY {
   2310         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2311         $$.basicType = EbtSampler;
   2312         $$.sampler.setImage(EbtUint, Esd2D, true);
   2313     }
   2314     | IMAGECUBEARRAY {
   2315         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2316         $$.basicType = EbtSampler;
   2317         $$.sampler.setImage(EbtFloat, EsdCube, true);
   2318     }
   2319     | IIMAGECUBEARRAY {
   2320         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2321         $$.basicType = EbtSampler;
   2322         $$.sampler.setImage(EbtInt, EsdCube, true);
   2323     }
   2324     | UIMAGECUBEARRAY {
   2325         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2326         $$.basicType = EbtSampler;
   2327         $$.sampler.setImage(EbtUint, EsdCube, true);
   2328     }
   2329     | IMAGE2DMS {
   2330         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2331         $$.basicType = EbtSampler;
   2332         $$.sampler.setImage(EbtFloat, Esd2D, false, false, true);
   2333     }
   2334     | IIMAGE2DMS {
   2335         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2336         $$.basicType = EbtSampler;
   2337         $$.sampler.setImage(EbtInt, Esd2D, false, false, true);
   2338     }
   2339     | UIMAGE2DMS {
   2340         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2341         $$.basicType = EbtSampler;
   2342         $$.sampler.setImage(EbtUint, Esd2D, false, false, true);
   2343     }
   2344     | IMAGE2DMSARRAY {
   2345         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2346         $$.basicType = EbtSampler;
   2347         $$.sampler.setImage(EbtFloat, Esd2D, true, false, true);
   2348     }
   2349     | IIMAGE2DMSARRAY {
   2350         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2351         $$.basicType = EbtSampler;
   2352         $$.sampler.setImage(EbtInt, Esd2D, true, false, true);
   2353     }
   2354     | UIMAGE2DMSARRAY {
   2355         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2356         $$.basicType = EbtSampler;
   2357         $$.sampler.setImage(EbtUint, Esd2D, true, false, true);
   2358     }
   2359     | SAMPLEREXTERNALOES {  // GL_OES_EGL_image_external
   2360         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2361         $$.basicType = EbtSampler;
   2362         $$.sampler.set(EbtFloat, Esd2D);
   2363         $$.sampler.external = true;
   2364     }
   2365     | SUBPASSINPUT {
   2366         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2367         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2368         $$.basicType = EbtSampler;
   2369         $$.sampler.setSubpass(EbtFloat);
   2370     }
   2371     | SUBPASSINPUTMS {
   2372         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2373         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2374         $$.basicType = EbtSampler;
   2375         $$.sampler.setSubpass(EbtFloat, true);
   2376     }
   2377     | ISUBPASSINPUT {
   2378         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2379         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2380         $$.basicType = EbtSampler;
   2381         $$.sampler.setSubpass(EbtInt);
   2382     }
   2383     | ISUBPASSINPUTMS {
   2384         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2385         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2386         $$.basicType = EbtSampler;
   2387         $$.sampler.setSubpass(EbtInt, true);
   2388     }
   2389     | USUBPASSINPUT {
   2390         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2391         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2392         $$.basicType = EbtSampler;
   2393         $$.sampler.setSubpass(EbtUint);
   2394     }
   2395     | USUBPASSINPUTMS {
   2396         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2397         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2398         $$.basicType = EbtSampler;
   2399         $$.sampler.setSubpass(EbtUint, true);
   2400     }
   2401     | struct_specifier {
   2402         $$ = $1;
   2403         $$.qualifier.storage = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
   2404         parseContext.structTypeCheck($$.loc, $$);
   2405     }
   2406     | TYPE_NAME {
   2407         //
   2408         // This is for user defined type names.  The lexical phase looked up the
   2409         // type.
   2410         //
   2411         if (const TVariable* variable = ($1.symbol)->getAsVariable()) {
   2412             const TType& structure = variable->getType();
   2413             $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2414             $$.basicType = EbtStruct;
   2415             $$.userDef = &structure;
   2416         } else
   2417             parseContext.error($1.loc, "expected type name", $1.string->c_str(), "");
   2418     }
   2419     ;
   2420 
   2421 precision_qualifier
   2422     : HIGH_PRECISION {
   2423         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "highp precision qualifier");
   2424         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2425         parseContext.handlePrecisionQualifier($1.loc, $$.qualifier, EpqHigh);
   2426     }
   2427     | MEDIUM_PRECISION {
   2428         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "mediump precision qualifier");
   2429         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2430         parseContext.handlePrecisionQualifier($1.loc, $$.qualifier, EpqMedium);
   2431     }
   2432     | LOW_PRECISION {
   2433         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "lowp precision qualifier");
   2434         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2435         parseContext.handlePrecisionQualifier($1.loc, $$.qualifier, EpqLow);
   2436     }
   2437     ;
   2438 
   2439 struct_specifier
   2440     : STRUCT IDENTIFIER LEFT_BRACE { parseContext.nestedStructCheck($1.loc); } struct_declaration_list RIGHT_BRACE {
   2441         TType* structure = new TType($5, *$2.string);
   2442         parseContext.structArrayCheck($2.loc, *structure);
   2443         TVariable* userTypeDef = new TVariable($2.string, *structure, true);
   2444         if (! parseContext.symbolTable.insert(*userTypeDef))
   2445             parseContext.error($2.loc, "redefinition", $2.string->c_str(), "struct");
   2446         $$.init($1.loc);
   2447         $$.basicType = EbtStruct;
   2448         $$.userDef = structure;
   2449         --parseContext.structNestingLevel;
   2450     }
   2451     | STRUCT LEFT_BRACE { parseContext.nestedStructCheck($1.loc); } struct_declaration_list RIGHT_BRACE {
   2452         TType* structure = new TType($4, TString(""));
   2453         $$.init($1.loc);
   2454         $$.basicType = EbtStruct;
   2455         $$.userDef = structure;
   2456         --parseContext.structNestingLevel;
   2457     }
   2458     ;
   2459 
   2460 struct_declaration_list
   2461     : struct_declaration {
   2462         $$ = $1;
   2463     }
   2464     | struct_declaration_list struct_declaration {
   2465         $$ = $1;
   2466         for (unsigned int i = 0; i < $2->size(); ++i) {
   2467             for (unsigned int j = 0; j < $$->size(); ++j) {
   2468                 if ((*$$)[j].type->getFieldName() == (*$2)[i].type->getFieldName())
   2469                     parseContext.error((*$2)[i].loc, "duplicate member name:", "", (*$2)[i].type->getFieldName().c_str());
   2470             }
   2471             $$->push_back((*$2)[i]);
   2472         }
   2473     }
   2474     ;
   2475 
   2476 struct_declaration
   2477     : type_specifier struct_declarator_list SEMICOLON {
   2478         if ($1.arraySizes) {
   2479             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   2480             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
   2481             if (parseContext.profile == EEsProfile)
   2482                 parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
   2483         }
   2484 
   2485         $$ = $2;
   2486 
   2487         parseContext.voidErrorCheck($1.loc, (*$2)[0].type->getFieldName(), $1.basicType);
   2488         parseContext.precisionQualifierCheck($1.loc, $1.basicType, $1.qualifier);
   2489 
   2490         for (unsigned int i = 0; i < $$->size(); ++i) {
   2491             parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $1.arraySizes);
   2492             (*$$)[i].type->mergeType($1);
   2493         }
   2494     }
   2495     | type_qualifier type_specifier struct_declarator_list SEMICOLON {
   2496         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
   2497         if ($2.arraySizes) {
   2498             parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   2499             parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type");
   2500             if (parseContext.profile == EEsProfile)
   2501                 parseContext.arraySizeRequiredCheck($2.loc, *$2.arraySizes);
   2502         }
   2503 
   2504         $$ = $3;
   2505 
   2506         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
   2507         parseContext.voidErrorCheck($2.loc, (*$3)[0].type->getFieldName(), $2.basicType);
   2508         parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
   2509         parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
   2510 
   2511         for (unsigned int i = 0; i < $$->size(); ++i) {
   2512             parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $2.arraySizes);
   2513             (*$$)[i].type->mergeType($2);
   2514         }
   2515     }
   2516     ;
   2517 
   2518 struct_declarator_list
   2519     : struct_declarator {
   2520         $$ = new TTypeList;
   2521         $$->push_back($1);
   2522     }
   2523     | struct_declarator_list COMMA struct_declarator {
   2524         $$->push_back($3);
   2525     }
   2526     ;
   2527 
   2528 struct_declarator
   2529     : IDENTIFIER {
   2530         $$.type = new TType(EbtVoid);
   2531         $$.loc = $1.loc;
   2532         $$.type->setFieldName(*$1.string);
   2533     }
   2534     | IDENTIFIER array_specifier {
   2535         parseContext.arrayDimCheck($1.loc, $2.arraySizes, 0);
   2536 
   2537         $$.type = new TType(EbtVoid);
   2538         $$.loc = $1.loc;
   2539         $$.type->setFieldName(*$1.string);
   2540         $$.type->newArraySizes(*$2.arraySizes);
   2541     }
   2542     ;
   2543 
   2544 initializer
   2545     : assignment_expression {
   2546         $$ = $1;
   2547     }
   2548     | LEFT_BRACE initializer_list RIGHT_BRACE {
   2549         const char* initFeature = "{ } style initializers";
   2550         parseContext.requireProfile($1.loc, ~EEsProfile, initFeature);
   2551         parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
   2552         $$ = $2;
   2553     }
   2554     | LEFT_BRACE initializer_list COMMA RIGHT_BRACE {
   2555         const char* initFeature = "{ } style initializers";
   2556         parseContext.requireProfile($1.loc, ~EEsProfile, initFeature);
   2557         parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
   2558         $$ = $2;
   2559     }
   2560     ;
   2561 
   2562 initializer_list
   2563     : initializer {
   2564         $$ = parseContext.intermediate.growAggregate(0, $1, $1->getLoc());
   2565     }
   2566     | initializer_list COMMA initializer {
   2567         $$ = parseContext.intermediate.growAggregate($1, $3);
   2568     }
   2569     ;
   2570 
   2571 declaration_statement
   2572     : declaration { $$ = $1; }
   2573     ;
   2574 
   2575 statement
   2576     : compound_statement  { $$ = $1; }
   2577     | simple_statement    { $$ = $1; }
   2578     ;
   2579 
   2580 // Grammar Note:  labeled statements for switch statements only; 'goto' is not supported.
   2581 
   2582 simple_statement
   2583     : declaration_statement { $$ = $1; }
   2584     | expression_statement  { $$ = $1; }
   2585     | selection_statement   { $$ = $1; }
   2586     | switch_statement      { $$ = $1; }
   2587     | case_label            { $$ = $1; }
   2588     | iteration_statement   { $$ = $1; }
   2589     | jump_statement        { $$ = $1; }
   2590     ;
   2591 
   2592 compound_statement
   2593     : LEFT_BRACE RIGHT_BRACE { $$ = 0; }
   2594     | LEFT_BRACE {
   2595         parseContext.symbolTable.push();
   2596         ++parseContext.statementNestingLevel;
   2597     }
   2598       statement_list {
   2599         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2600         --parseContext.statementNestingLevel;
   2601     }
   2602       RIGHT_BRACE {
   2603         if ($3 && $3->getAsAggregate())
   2604             $3->getAsAggregate()->setOperator(EOpSequence);
   2605         $$ = $3;
   2606     }
   2607     ;
   2608 
   2609 statement_no_new_scope
   2610     : compound_statement_no_new_scope { $$ = $1; }
   2611     | simple_statement                { $$ = $1; }
   2612     ;
   2613 
   2614 statement_scoped
   2615     : {
   2616         ++parseContext.controlFlowNestingLevel;
   2617     }
   2618       compound_statement  {
   2619         --parseContext.controlFlowNestingLevel;
   2620         $$ = $2;
   2621     }
   2622     | {
   2623         parseContext.symbolTable.push();
   2624         ++parseContext.statementNestingLevel;
   2625         ++parseContext.controlFlowNestingLevel;
   2626     }
   2627       simple_statement {
   2628         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2629         --parseContext.statementNestingLevel;
   2630         --parseContext.controlFlowNestingLevel;
   2631         $$ = $2;
   2632     }
   2633 
   2634 compound_statement_no_new_scope
   2635     // Statement that doesn't create a new scope, for selection_statement, iteration_statement
   2636     : LEFT_BRACE RIGHT_BRACE {
   2637         $$ = 0;
   2638     }
   2639     | LEFT_BRACE statement_list RIGHT_BRACE {
   2640         if ($2 && $2->getAsAggregate())
   2641             $2->getAsAggregate()->setOperator(EOpSequence);
   2642         $$ = $2;
   2643     }
   2644     ;
   2645 
   2646 statement_list
   2647     : statement {
   2648         $$ = parseContext.intermediate.makeAggregate($1);
   2649         if ($1 && $1->getAsBranchNode() && ($1->getAsBranchNode()->getFlowOp() == EOpCase ||
   2650                                             $1->getAsBranchNode()->getFlowOp() == EOpDefault)) {
   2651             parseContext.wrapupSwitchSubsequence(0, $1);
   2652             $$ = 0;  // start a fresh subsequence for what's after this case
   2653         }
   2654     }
   2655     | statement_list statement {
   2656         if ($2 && $2->getAsBranchNode() && ($2->getAsBranchNode()->getFlowOp() == EOpCase ||
   2657                                             $2->getAsBranchNode()->getFlowOp() == EOpDefault)) {
   2658             parseContext.wrapupSwitchSubsequence($1 ? $1->getAsAggregate() : 0, $2);
   2659             $$ = 0;  // start a fresh subsequence for what's after this case
   2660         } else
   2661             $$ = parseContext.intermediate.growAggregate($1, $2);
   2662     }
   2663     ;
   2664 
   2665 expression_statement
   2666     : SEMICOLON  { $$ = 0; }
   2667     | expression SEMICOLON  { $$ = static_cast<TIntermNode*>($1); }
   2668     ;
   2669 
   2670 selection_statement
   2671     : IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement {
   2672         parseContext.boolCheck($1.loc, $3);
   2673         $$ = parseContext.intermediate.addSelection($3, $5, $1.loc);
   2674     }
   2675     ;
   2676 
   2677 selection_rest_statement
   2678     : statement_scoped ELSE statement_scoped {
   2679         $$.node1 = $1;
   2680         $$.node2 = $3;
   2681     }
   2682     | statement_scoped {
   2683         $$.node1 = $1;
   2684         $$.node2 = 0;
   2685     }
   2686     ;
   2687 
   2688 condition
   2689     // In 1996 c++ draft, conditions can include single declarations
   2690     : expression {
   2691         $$ = $1;
   2692         parseContext.boolCheck($1->getLoc(), $1);
   2693     }
   2694     | fully_specified_type IDENTIFIER EQUAL initializer {
   2695         parseContext.boolCheck($2.loc, $1);
   2696 
   2697         TType type($1);
   2698         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, 0, $4);
   2699         if (initNode)
   2700             $$ = initNode->getAsTyped();
   2701         else
   2702             $$ = 0;
   2703     }
   2704     ;
   2705 
   2706 switch_statement
   2707     : SWITCH LEFT_PAREN expression RIGHT_PAREN {
   2708         // start new switch sequence on the switch stack
   2709         ++parseContext.controlFlowNestingLevel;
   2710         ++parseContext.statementNestingLevel;
   2711         parseContext.switchSequenceStack.push_back(new TIntermSequence);
   2712         parseContext.switchLevel.push_back(parseContext.statementNestingLevel);
   2713         parseContext.symbolTable.push();
   2714     }
   2715     LEFT_BRACE switch_statement_list RIGHT_BRACE {
   2716         $$ = parseContext.addSwitch($1.loc, $3, $7 ? $7->getAsAggregate() : 0);
   2717         delete parseContext.switchSequenceStack.back();
   2718         parseContext.switchSequenceStack.pop_back();
   2719         parseContext.switchLevel.pop_back();
   2720         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2721         --parseContext.statementNestingLevel;
   2722         --parseContext.controlFlowNestingLevel;
   2723     }
   2724     ;
   2725 
   2726 switch_statement_list
   2727     : /* nothing */ {
   2728         $$ = 0;
   2729     }
   2730     | statement_list {
   2731         $$ = $1;
   2732     }
   2733     ;
   2734 
   2735 case_label
   2736     : CASE expression COLON {
   2737         $$ = 0;
   2738         if (parseContext.switchLevel.size() == 0)
   2739             parseContext.error($1.loc, "cannot appear outside switch statement", "case", "");
   2740         else if (parseContext.switchLevel.back() != parseContext.statementNestingLevel)
   2741             parseContext.error($1.loc, "cannot be nested inside control flow", "case", "");
   2742         else {
   2743             parseContext.constantValueCheck($2, "case");
   2744             parseContext.integerCheck($2, "case");
   2745             $$ = parseContext.intermediate.addBranch(EOpCase, $2, $1.loc);
   2746         }
   2747     }
   2748     | DEFAULT COLON {
   2749         $$ = 0;
   2750         if (parseContext.switchLevel.size() == 0)
   2751             parseContext.error($1.loc, "cannot appear outside switch statement", "default", "");
   2752         else if (parseContext.switchLevel.back() != parseContext.statementNestingLevel)
   2753             parseContext.error($1.loc, "cannot be nested inside control flow", "default", "");
   2754         else
   2755             $$ = parseContext.intermediate.addBranch(EOpDefault, $1.loc);
   2756     }
   2757     ;
   2758 
   2759 iteration_statement
   2760     : WHILE LEFT_PAREN {
   2761         if (! parseContext.limits.whileLoops)
   2762             parseContext.error($1.loc, "while loops not available", "limitation", "");
   2763         parseContext.symbolTable.push();
   2764         ++parseContext.loopNestingLevel;
   2765         ++parseContext.statementNestingLevel;
   2766         ++parseContext.controlFlowNestingLevel;
   2767     }
   2768       condition RIGHT_PAREN statement_no_new_scope {
   2769         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2770         $$ = parseContext.intermediate.addLoop($6, $4, 0, true, $1.loc);
   2771         --parseContext.loopNestingLevel;
   2772         --parseContext.statementNestingLevel;
   2773         --parseContext.controlFlowNestingLevel;
   2774     }
   2775     | DO {
   2776         ++parseContext.loopNestingLevel;
   2777         ++parseContext.statementNestingLevel;
   2778         ++parseContext.controlFlowNestingLevel;
   2779     }
   2780       statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
   2781         if (! parseContext.limits.whileLoops)
   2782             parseContext.error($1.loc, "do-while loops not available", "limitation", "");
   2783 
   2784         parseContext.boolCheck($8.loc, $6);
   2785 
   2786         $$ = parseContext.intermediate.addLoop($3, $6, 0, false, $4.loc);
   2787         --parseContext.loopNestingLevel;
   2788         --parseContext.statementNestingLevel;
   2789         --parseContext.controlFlowNestingLevel;
   2790     }
   2791     | FOR LEFT_PAREN {
   2792         parseContext.symbolTable.push();
   2793         ++parseContext.loopNestingLevel;
   2794         ++parseContext.statementNestingLevel;
   2795         ++parseContext.controlFlowNestingLevel;
   2796     }
   2797       for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope {
   2798         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2799         $$ = parseContext.intermediate.makeAggregate($4, $2.loc);
   2800         TIntermLoop* forLoop = parseContext.intermediate.addLoop($7, reinterpret_cast<TIntermTyped*>($5.node1), reinterpret_cast<TIntermTyped*>($5.node2), true, $1.loc);
   2801         if (! parseContext.limits.nonInductiveForLoops)
   2802             parseContext.inductiveLoopCheck($1.loc, $4, forLoop);
   2803         $$ = parseContext.intermediate.growAggregate($$, forLoop, $1.loc);
   2804         $$->getAsAggregate()->setOperator(EOpSequence);
   2805         --parseContext.loopNestingLevel;
   2806         --parseContext.statementNestingLevel;
   2807         --parseContext.controlFlowNestingLevel;
   2808     }
   2809     ;
   2810 
   2811 for_init_statement
   2812     : expression_statement {
   2813         $$ = $1;
   2814     }
   2815     | declaration_statement {
   2816         $$ = $1;
   2817     }
   2818     ;
   2819 
   2820 conditionopt
   2821     : condition {
   2822         $$ = $1;
   2823     }
   2824     | /* May be null */ {
   2825         $$ = 0;
   2826     }
   2827     ;
   2828 
   2829 for_rest_statement
   2830     : conditionopt SEMICOLON {
   2831         $$.node1 = $1;
   2832         $$.node2 = 0;
   2833     }
   2834     | conditionopt SEMICOLON expression  {
   2835         $$.node1 = $1;
   2836         $$.node2 = $3;
   2837     }
   2838     ;
   2839 
   2840 jump_statement
   2841     : CONTINUE SEMICOLON {
   2842         if (parseContext.loopNestingLevel <= 0)
   2843             parseContext.error($1.loc, "continue statement only allowed in loops", "", "");
   2844         $$ = parseContext.intermediate.addBranch(EOpContinue, $1.loc);
   2845     }
   2846     | BREAK SEMICOLON {
   2847         if (parseContext.loopNestingLevel + parseContext.switchSequenceStack.size() <= 0)
   2848             parseContext.error($1.loc, "break statement only allowed in switch and loops", "", "");
   2849         $$ = parseContext.intermediate.addBranch(EOpBreak, $1.loc);
   2850     }
   2851     | RETURN SEMICOLON {
   2852         $$ = parseContext.intermediate.addBranch(EOpReturn, $1.loc);
   2853         if (parseContext.currentFunctionType->getBasicType() != EbtVoid)
   2854             parseContext.error($1.loc, "non-void function must return a value", "return", "");
   2855         if (parseContext.inMain)
   2856             parseContext.postEntryPointReturn = true;
   2857     }
   2858     | RETURN expression SEMICOLON {
   2859         $$ = parseContext.handleReturnValue($1.loc, $2);
   2860     }
   2861     | DISCARD SEMICOLON {
   2862         parseContext.requireStage($1.loc, EShLangFragment, "discard");
   2863         $$ = parseContext.intermediate.addBranch(EOpKill, $1.loc);
   2864     }
   2865     ;
   2866 
   2867 // Grammar Note:  No 'goto'.  Gotos are not supported.
   2868 
   2869 translation_unit
   2870     : external_declaration {
   2871         $$ = $1;
   2872         parseContext.intermediate.setTreeRoot($$);
   2873     }
   2874     | translation_unit external_declaration {
   2875         if ($2 != nullptr) {
   2876             $$ = parseContext.intermediate.growAggregate($1, $2);
   2877             parseContext.intermediate.setTreeRoot($$);
   2878         }
   2879     }
   2880     ;
   2881 
   2882 external_declaration
   2883     : function_definition {
   2884         $$ = $1;
   2885     }
   2886     | declaration {
   2887         $$ = $1;
   2888     }
   2889     | SEMICOLON {
   2890         parseContext.requireProfile($1.loc, ~EEsProfile, "extraneous semicolon");
   2891         parseContext.profileRequires($1.loc, ~EEsProfile, 460, nullptr, "extraneous semicolon");
   2892         $$ = nullptr;
   2893     }
   2894     ;
   2895 
   2896 function_definition
   2897     : function_prototype {
   2898         $1.function = parseContext.handleFunctionDeclarator($1.loc, *$1.function, false /* not prototype */);
   2899         $1.intermNode = parseContext.handleFunctionDefinition($1.loc, *$1.function);
   2900     }
   2901     compound_statement_no_new_scope {
   2902         //   May be best done as post process phase on intermediate code
   2903         if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue)
   2904             parseContext.error($1.loc, "function does not return a value:", "", $1.function->getName().c_str());
   2905         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2906         $$ = parseContext.intermediate.growAggregate($1.intermNode, $3);
   2907         parseContext.intermediate.setAggregateOperator($$, EOpFunction, $1.function->getType(), $1.loc);
   2908         $$->getAsAggregate()->setName($1.function->getMangledName().c_str());
   2909 
   2910         // store the pragma information for debug and optimize and other vendor specific
   2911         // information. This information can be queried from the parse tree
   2912         $$->getAsAggregate()->setOptimize(parseContext.contextPragma.optimize);
   2913         $$->getAsAggregate()->setDebug(parseContext.contextPragma.debug);
   2914         $$->getAsAggregate()->addToPragmaTable(parseContext.contextPragma.pragmaTable);
   2915     }
   2916     ;
   2917 
   2918 %%
   2919