summaryrefslogtreecommitdiffstats
path: root/Source/ThirdParty/ANGLE/src/compiler/glslang.y
diff options
context:
space:
mode:
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/compiler/glslang.y')
-rw-r--r--Source/ThirdParty/ANGLE/src/compiler/glslang.y185
1 files changed, 124 insertions, 61 deletions
diff --git a/Source/ThirdParty/ANGLE/src/compiler/glslang.y b/Source/ThirdParty/ANGLE/src/compiler/glslang.y
index 5eae4b5..d6c8869 100644
--- a/Source/ThirdParty/ANGLE/src/compiler/glslang.y
+++ b/Source/ThirdParty/ANGLE/src/compiler/glslang.y
@@ -9,7 +9,7 @@ This file contains the Yacc grammar for GLSL ES.
Based on ANSI C Yacc grammar:
http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
-IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_glslang_parser.sh,
+IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh,
WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
*/
@@ -20,7 +20,19 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
// found in the LICENSE file.
//
-// This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT!
+// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
+
+// Ignore errors in auto-generated code.
+#if defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wunused-function"
+#pragma GCC diagnostic ignored "-Wunused-variable"
+#pragma GCC diagnostic ignored "-Wswitch-enum"
+#elif defined(_MSC_VER)
+#pragma warning(disable: 4065)
+#pragma warning(disable: 4189)
+#pragma warning(disable: 4505)
+#pragma warning(disable: 4701)
+#endif
#include "compiler/SymbolTable.h"
#include "compiler/ParseHelper.h"
@@ -98,7 +110,7 @@ extern void yyerror(TParseContext* context, const char* reason);
%token <lex> BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 VEC2 VEC3 VEC4
%token <lex> MATRIX2 MATRIX3 MATRIX4 IN_QUAL OUT_QUAL INOUT_QUAL UNIFORM VARYING
%token <lex> STRUCT VOID_TYPE WHILE
-%token <lex> SAMPLER2D SAMPLERCUBE
+%token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT
%token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT BOOLCONSTANT
%token <lex> FIELD_SELECTION
@@ -129,7 +141,7 @@ extern void yyerror(TParseContext* context, const char* reason);
%type <interm.intermNode> declaration external_declaration
%type <interm.intermNode> for_init_statement compound_statement_no_new_scope
%type <interm.nodePair> selection_rest_statement for_rest_statement
-%type <interm.intermNode> iteration_statement jump_statement statement_no_new_scope
+%type <interm.intermNode> iteration_statement jump_statement statement_no_new_scope statement_with_scope
%type <interm> single_declaration init_declarator_list
%type <interm> parameter_declaration parameter_declarator parameter_type_specifier
@@ -591,17 +603,10 @@ function_call_header
// Grammar Note: Constructors look like functions, but are recognized as types.
function_identifier
- : type_specifier {
+ : type_specifier_nonarray {
//
// Constructor
//
- if ($1.array) {
- // Constructors for arrays are not allowed.
- context->error($1.line, "cannot construct this type", "array", "");
- context->recover();
- $1.setArray(false);
- }
-
TOperator op = EOpNull;
if ($1.userDef) {
op = EOpConstructStruct;
@@ -975,6 +980,8 @@ declaration
prototype->setOp(EOpPrototype);
$$ = prototype;
+
+ context->symbolTable.pop();
}
| init_declarator_list SEMICOLON {
if ($1.intermAggregate)
@@ -1019,7 +1026,9 @@ function_prototype
$$.function = $1;
$$.line = $2.line;
- context->symbolTable.insert(*$$.function);
+ // We're at the inner scope level of the function's arguments and body statement.
+ // Add the function prototype to the surrounding scope instead.
+ context->symbolTable.getOuterLevel()->insert(*$$.function);
}
;
@@ -1077,6 +1086,8 @@ function_header
TType type($1);
function = new TFunction($2.string, type);
$$ = function;
+
+ context->symbolTable.push();
}
;
@@ -1176,16 +1187,16 @@ parameter_type_specifier
init_declarator_list
: single_declaration {
$$ = $1;
-
- if ($$.type.precision == EbpUndefined) {
- $$.type.precision = context->symbolTable.getDefaultPrecision($1.type.type);
- if (context->precisionErrorCheck($1.line, $$.type.precision, $1.type.type)) {
- context->recover();
- }
- }
}
| init_declarator_list COMMA IDENTIFIER {
- $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line), $3.line);
+ if ($1.type.type == EbtInvariant && !$3.symbol)
+ {
+ context->error($3.line, "undeclared identifier declared as invariant", $3.string->c_str(), "");
+ context->recover();
+ }
+
+ TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line);
+ $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, symbol, $3.line);
if (context->structQualifierErrorCheck($3.line, $$.type))
context->recover();
@@ -1193,8 +1204,11 @@ init_declarator_list
if (context->nonInitConstErrorCheck($3.line, *$3.string, $$.type))
context->recover();
- if (context->nonInitErrorCheck($3.line, *$3.string, $$.type))
+ TVariable* variable = 0;
+ if (context->nonInitErrorCheck($3.line, *$3.string, $$.type, variable))
context->recover();
+ if (symbol && variable)
+ symbol->setId(variable->getUniqueId());
}
| init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET {
if (context->structQualifierErrorCheck($3.line, $1.type))
@@ -1230,12 +1244,12 @@ init_declarator_list
if (context->arraySizeErrorCheck($4.line, $5, size))
context->recover();
$1.type.setArray(true, size);
- TVariable* variable;
+ TVariable* variable = 0;
if (context->arrayErrorCheck($4.line, *$3.string, $1.type, variable))
context->recover();
TType type = TType($1.type);
type.setArraySize(size);
- $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(0, *$3.string, type, $3.line), $3.line);
+ $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(variable ? variable->getUniqueId() : 0, *$3.string, type, $3.line), $3.line);
}
}
| init_declarator_list COMMA IDENTIFIER EQUAL initializer {
@@ -1266,7 +1280,8 @@ single_declaration
$$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, "", TType($1), $1.line), $1.line);
}
| fully_specified_type IDENTIFIER {
- $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line);
+ TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line);
+ $$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
if (context->structQualifierErrorCheck($2.line, $$.type))
context->recover();
@@ -1276,28 +1291,19 @@ single_declaration
$$.type = $1;
- if (context->nonInitErrorCheck($2.line, *$2.string, $$.type))
+ TVariable* variable = 0;
+ if (context->nonInitErrorCheck($2.line, *$2.string, $$.type, variable))
context->recover();
+ if (variable && symbol)
+ symbol->setId(variable->getUniqueId());
}
| fully_specified_type IDENTIFIER LEFT_BRACKET RIGHT_BRACKET {
- $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line);
-
- if (context->structQualifierErrorCheck($2.line, $1))
- context->recover();
-
- if (context->nonInitConstErrorCheck($2.line, *$2.string, $1))
- context->recover();
+ context->error($2.line, "unsized array declarations not supported", $2.string->c_str(), "");
+ context->recover();
+ TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line);
+ $$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
$$.type = $1;
-
- if (context->arrayTypeErrorCheck($3.line, $1) || context->arrayQualifierErrorCheck($3.line, $1))
- context->recover();
- else {
- $1.setArray(true);
- TVariable* variable;
- if (context->arrayErrorCheck($3.line, *$2.string, $1, variable))
- context->recover();
- }
}
| fully_specified_type IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET {
TType type = TType($1);
@@ -1305,7 +1311,8 @@ single_declaration
if (context->arraySizeErrorCheck($2.line, $4, size))
context->recover();
type.setArraySize(size);
- $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, type, $2.line), $2.line);
+ TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$2.string, type, $2.line);
+ $$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
if (context->structQualifierErrorCheck($2.line, $1))
context->recover();
@@ -1323,9 +1330,11 @@ single_declaration
context->recover();
$1.setArray(true, size);
- TVariable* variable;
+ TVariable* variable = 0;
if (context->arrayErrorCheck($3.line, *$2.string, $1, variable))
context->recover();
+ if (variable && symbol)
+ symbol->setId(variable->getUniqueId());
}
}
| fully_specified_type IDENTIFIER EQUAL initializer {
@@ -1350,8 +1359,21 @@ single_declaration
}
| INVARIANT IDENTIFIER {
VERTEX_ONLY("invariant declaration", $1.line);
- $$.qualifier = EvqInvariantVaryingOut;
- $$.intermAggregate = 0;
+ if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "invariant varying"))
+ context->recover();
+ $$.type.setBasic(EbtInvariant, EvqInvariantVaryingOut, $2.line);
+ if (!$2.symbol)
+ {
+ context->error($2.line, "undeclared identifier declared as invariant", $2.string->c_str(), "");
+ context->recover();
+
+ $$.intermAggregate = 0;
+ }
+ else
+ {
+ TIntermSymbol *symbol = context->intermediate.addSymbol(0, *$2.string, TType($$.type), $2.line);
+ $$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
+ }
}
//
@@ -1491,6 +1513,13 @@ type_qualifier
type_specifier
: type_specifier_no_prec {
$$ = $1;
+
+ if ($$.precision == EbpUndefined) {
+ $$.precision = context->symbolTable.getDefaultPrecision($1.type);
+ if (context->precisionErrorCheck($1.line, $$.precision, $1.type)) {
+ context->recover();
+ }
+ }
}
| precision_qualifier type_specifier_no_prec {
$$ = $2;
@@ -1623,6 +1652,24 @@ type_specifier_nonarray
TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
$$.setBasic(EbtSamplerCube, qual, $1.line);
}
+ | SAMPLER_EXTERNAL_OES {
+ if (!context->supportsExtension("GL_OES_EGL_image_external")) {
+ context->error($1.line, "unsupported type", "samplerExternalOES", "");
+ context->recover();
+ }
+ FRAG_VERT_ONLY("samplerExternalOES", $1.line);
+ TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
+ $$.setBasic(EbtSamplerExternalOES, qual, $1.line);
+ }
+ | SAMPLER2DRECT {
+ if (!context->supportsExtension("GL_ARB_texture_rectangle")) {
+ context->error($1.line, "unsupported type", "sampler2DRect", "");
+ context->recover();
+ }
+ FRAG_VERT_ONLY("sampler2DRect", $1.line);
+ TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
+ $$.setBasic(EbtSampler2DRect, qual, $1.line);
+ }
| struct_specifier {
FRAG_VERT_ONLY("struct", $1.line);
$$ = $1;
@@ -1641,11 +1688,11 @@ type_specifier_nonarray
;
struct_specifier
- : STRUCT IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE {
+ : STRUCT IDENTIFIER LEFT_BRACE { if (context->enterStructDeclaration($2.line, *$2.string)) context->recover(); } struct_declaration_list RIGHT_BRACE {
if (context->reservedErrorCheck($2.line, *$2.string))
context->recover();
- TType* structure = new TType($4, *$2.string);
+ TType* structure = new TType($5, *$2.string);
TVariable* userTypeDef = new TVariable($2.string, *structure, true);
if (! context->symbolTable.insert(*userTypeDef)) {
context->error($2.line, "redefinition", $2.string->c_str(), "struct");
@@ -1653,11 +1700,13 @@ struct_specifier
}
$$.setBasic(EbtStruct, EvqTemporary, $1.line);
$$.userDef = structure;
+ context->exitStructDeclaration();
}
- | STRUCT LEFT_BRACE struct_declaration_list RIGHT_BRACE {
- TType* structure = new TType($3, TString(""));
+ | STRUCT LEFT_BRACE { if (context->enterStructDeclaration($2.line, *$2.string)) context->recover(); } struct_declaration_list RIGHT_BRACE {
+ TType* structure = new TType($4, TString(""));
$$.setBasic(EbtStruct, EvqTemporary, $1.line);
$$.userDef = structure;
+ context->exitStructDeclaration();
}
;
@@ -1694,6 +1743,7 @@ struct_declaration
type->setBasicType($1.type);
type->setNominalSize($1.size);
type->setMatrix($1.matrix);
+ type->setPrecision($1.precision);
// don't allow arrays of arrays
if (type->isArray()) {
@@ -1706,6 +1756,10 @@ struct_declaration
type->setStruct($1.userDef->getStruct());
type->setTypeName($1.userDef->getTypeName());
}
+
+ if (context->structNestingErrorCheck($1.line, *type)) {
+ context->recover();
+ }
}
}
;
@@ -1770,8 +1824,10 @@ simple_statement
compound_statement
: LEFT_BRACE RIGHT_BRACE { $$ = 0; }
| LEFT_BRACE { context->symbolTable.push(); } statement_list { context->symbolTable.pop(); } RIGHT_BRACE {
- if ($3 != 0)
+ if ($3 != 0) {
$3->setOp(EOpSequence);
+ $3->setEndLine($5.line);
+ }
$$ = $3;
}
;
@@ -1781,14 +1837,21 @@ statement_no_new_scope
| simple_statement { $$ = $1; }
;
+statement_with_scope
+ : { context->symbolTable.push(); } compound_statement_no_new_scope { context->symbolTable.pop(); $$ = $2; }
+ | { context->symbolTable.push(); } simple_statement { context->symbolTable.pop(); $$ = $2; }
+ ;
+
compound_statement_no_new_scope
// Statement that doesn't create a new scope, for selection_statement, iteration_statement
: LEFT_BRACE RIGHT_BRACE {
$$ = 0;
}
| LEFT_BRACE statement_list RIGHT_BRACE {
- if ($2)
+ if ($2) {
$2->setOp(EOpSequence);
+ $2->setEndLine($3.line);
+ }
$$ = $2;
}
;
@@ -1816,11 +1879,11 @@ selection_statement
;
selection_rest_statement
- : statement ELSE statement {
+ : statement_with_scope ELSE statement_with_scope {
$$.node1 = $1;
$$.node2 = $3;
}
- | statement {
+ | statement_with_scope {
$$.node1 = $1;
$$.node2 = 0;
}
@@ -1857,7 +1920,7 @@ iteration_statement
$$ = context->intermediate.addLoop(ELoopWhile, 0, $4, 0, $6, $1.line);
--context->loopNestingLevel;
}
- | DO { ++context->loopNestingLevel; } statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
+ | DO { ++context->loopNestingLevel; } statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
if (context->boolErrorCheck($8.line, $6))
context->recover();
@@ -1994,11 +2057,6 @@ function_definition
}
//
- // New symbol table scope for body of function plus its arguments
- //
- context->symbolTable.push();
-
- //
// Remember the return type for later checking for RETURN statements.
//
context->currentFunctionType = &(prevDec->getReturnType());
@@ -2050,7 +2108,7 @@ function_definition
context->error($1.line, "function does not return a value:", "", $1.function->getName().c_str());
context->recover();
}
- context->symbolTable.pop();
+
$$ = context->intermediate.growAggregate($1.intermAggregate, $3, 0);
context->intermediate.setAggregateOperator($$, EOpFunction, $1.line);
$$->getAsAggregate()->setName($1.function->getMangledName().c_str());
@@ -2061,6 +2119,11 @@ function_definition
$$->getAsAggregate()->setOptimize(context->contextPragma.optimize);
$$->getAsAggregate()->setDebug(context->contextPragma.debug);
$$->getAsAggregate()->addToPragmaTable(context->contextPragma.pragmaTable);
+
+ if ($3 && $3->getAsAggregate())
+ $$->getAsAggregate()->setEndLine($3->getAsAggregate()->getEndLine());
+
+ context->symbolTable.pop();
}
;