diff options
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/compiler/glslang.y')
-rw-r--r-- | Source/ThirdParty/ANGLE/src/compiler/glslang.y | 1108 |
1 files changed, 501 insertions, 607 deletions
diff --git a/Source/ThirdParty/ANGLE/src/compiler/glslang.y b/Source/ThirdParty/ANGLE/src/compiler/glslang.y index d0d29df..5eae4b5 100644 --- a/Source/ThirdParty/ANGLE/src/compiler/glslang.y +++ b/Source/ThirdParty/ANGLE/src/compiler/glslang.y @@ -1,89 +1,38 @@ +/* // // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -/** - * This is bison grammar and production code for parsing the OpenGL 2.0 shading - * languages. - */ -%{ - -/* Based on: -ANSI C Yacc grammar +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 -In 1985, Jeff Lee published his Yacc grammar (which is accompanied by a -matching Lex specification) for the April 30, 1985 draft version of the -ANSI C standard. Tom Stockfisch reposted it to net.sources in 1987; that -original, as mentioned in the answer to question 17.25 of the comp.lang.c -FAQ, can be ftp'ed from ftp.uu.net, file usenet/net.sources/ansi.c.grammar.Z. +IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_glslang_parser.sh, +WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). +*/ -I intend to keep this version as close to the current C Standard grammar as -possible; please let me know if you discover discrepancies. +%{ +// +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// -Jutta Degener, 1995 -*/ +// This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT! #include "compiler/SymbolTable.h" #include "compiler/ParseHelper.h" #include "GLSLANG/ShaderLang.h" -#define YYPARSE_PARAM parseContextLocal -/* -TODO(alokp): YYPARSE_PARAM_DECL is only here to support old bison.exe in -compiler/tools. Remove it when we can exclusively use the newer version. -*/ -#define YYPARSE_PARAM_DECL void* -#define parseContext ((TParseContext*)(parseContextLocal)) -#define YYLEX_PARAM parseContextLocal -#define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal) -extern void yyerror(const char*); - -#define FRAG_VERT_ONLY(S, L) { \ - if (parseContext->language != EShLangFragment && \ - parseContext->language != EShLangVertex) { \ - parseContext->error(L, " supported in vertex/fragment shaders only ", S, "", ""); \ - parseContext->recover(); \ - } \ -} - -#define VERTEX_ONLY(S, L) { \ - if (parseContext->language != EShLangVertex) { \ - parseContext->error(L, " supported in vertex shaders only ", S, "", ""); \ - parseContext->recover(); \ - } \ -} - -#define FRAG_ONLY(S, L) { \ - if (parseContext->language != EShLangFragment) { \ - parseContext->error(L, " supported in fragment shaders only ", S, "", ""); \ - parseContext->recover(); \ - } \ -} - -#define PACK_ONLY(S, L) { \ - if (parseContext->language != EShLangPack) { \ - parseContext->error(L, " supported in pack shaders only ", S, "", ""); \ - parseContext->recover(); \ - } \ -} +#define YYLEX_PARAM context->scanner +%} -#define UNPACK_ONLY(S, L) { \ - if (parseContext->language != EShLangUnpack) { \ - parseContext->error(L, " supported in unpack shaders only ", S, "", ""); \ - parseContext->recover(); \ - } \ -} +%expect 1 /* One shift reduce conflict because of if | else */ +%pure-parser +%parse-param {TParseContext* context} -#define PACK_UNPACK_ONLY(S, L) { \ - if (parseContext->language != EShLangUnpack && \ - parseContext->language != EShLangPack) { \ - parseContext->error(L, " supported in pack/unpack shaders only ", S, "", ""); \ - parseContext->recover(); \ - } \ -} -%} %union { struct { TSourceLoc line; @@ -117,11 +66,32 @@ extern void yyerror(const char*); } %{ - extern int yylex(YYSTYPE*, void*); +extern int yylex(YYSTYPE* yylval_param, void* yyscanner); +extern void yyerror(TParseContext* context, const char* reason); + +#define FRAG_VERT_ONLY(S, L) { \ + if (context->shaderType != SH_FRAGMENT_SHADER && \ + context->shaderType != SH_VERTEX_SHADER) { \ + context->error(L, " supported in vertex/fragment shaders only ", S, "", ""); \ + context->recover(); \ + } \ +} + +#define VERTEX_ONLY(S, L) { \ + if (context->shaderType != SH_VERTEX_SHADER) { \ + context->error(L, " supported in vertex shaders only ", S, "", ""); \ + context->recover(); \ + } \ +} + +#define FRAG_ONLY(S, L) { \ + if (context->shaderType != SH_FRAGMENT_SHADER) { \ + context->error(L, " supported in fragment shaders only ", S, "", ""); \ + context->recover(); \ + } \ +} %} -%pure_parser /* Just in case is called from multiple threads */ -%expect 1 /* One shift reduce conflict because of if | else */ %token <lex> INVARIANT HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION %token <lex> ATTRIBUTE CONST_QUAL BOOL_TYPE FLOAT_TYPE INT_TYPE %token <lex> BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN @@ -185,17 +155,17 @@ variable_identifier const TSymbol* symbol = $1.symbol; const TVariable* variable; if (symbol == 0) { - parseContext->error($1.line, "undeclared identifier", $1.string->c_str(), ""); - parseContext->recover(); + context->error($1.line, "undeclared identifier", $1.string->c_str(), ""); + context->recover(); TType type(EbtFloat, EbpUndefined); TVariable* fakeVariable = new TVariable($1.string, type); - parseContext->symbolTable.insert(*fakeVariable); + context->symbolTable.insert(*fakeVariable); variable = fakeVariable; } else { // This identifier can only be a variable type symbol if (! symbol->isVariable()) { - parseContext->error($1.line, "variable expected", $1.string->c_str(), ""); - parseContext->recover(); + context->error($1.line, "variable expected", $1.string->c_str(), ""); + context->recover(); } variable = static_cast<const TVariable*>(symbol); } @@ -206,9 +176,9 @@ variable_identifier if (variable->getType().getQualifier() == EvqConst ) { ConstantUnion* constArray = variable->getConstPointer(); TType t(variable->getType()); - $$ = parseContext->intermediate.addConstantUnion(constArray, t, $1.line); + $$ = context->intermediate.addConstantUnion(constArray, t, $1.line); } else - $$ = parseContext->intermediate.addSymbol(variable->getUniqueId(), + $$ = context->intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), $1.line); } @@ -224,22 +194,22 @@ primary_expression // check for overflow for constants // if (abs($1.i) >= (1 << 16)) { - parseContext->error($1.line, " integer constant overflow", "", ""); - parseContext->recover(); + context->error($1.line, " integer constant overflow", "", ""); + context->recover(); } ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setIConst($1.i); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $1.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $1.line); } | FLOATCONSTANT { ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setFConst($1.f); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpUndefined, EvqConst), $1.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpUndefined, EvqConst), $1.line); } | BOOLCONSTANT { ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst($1.b); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $1.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $1.line); } | LEFT_PAREN expression RIGHT_PAREN { $$ = $2; @@ -253,57 +223,57 @@ postfix_expression | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET { if (!$1->isArray() && !$1->isMatrix() && !$1->isVector()) { if ($1->getAsSymbolNode()) - parseContext->error($2.line, " left of '[' is not of type array, matrix, or vector ", $1->getAsSymbolNode()->getSymbol().c_str(), ""); + context->error($2.line, " left of '[' is not of type array, matrix, or vector ", $1->getAsSymbolNode()->getSymbol().c_str(), ""); else - parseContext->error($2.line, " left of '[' is not of type array, matrix, or vector ", "expression", ""); - parseContext->recover(); + context->error($2.line, " left of '[' is not of type array, matrix, or vector ", "expression", ""); + context->recover(); } if ($1->getType().getQualifier() == EvqConst && $3->getQualifier() == EvqConst) { if ($1->isArray()) { // constant folding for arrays - $$ = parseContext->addConstArrayNode($3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), $1, $2.line); + $$ = context->addConstArrayNode($3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), $1, $2.line); } else if ($1->isVector()) { // constant folding for vectors TVectorFields fields; fields.num = 1; fields.offsets[0] = $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(); // need to do it this way because v.xy sends fields integer array - $$ = parseContext->addConstVectorNode(fields, $1, $2.line); + $$ = context->addConstVectorNode(fields, $1, $2.line); } else if ($1->isMatrix()) { // constant folding for matrices - $$ = parseContext->addConstMatrixNode($3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), $1, $2.line); + $$ = context->addConstMatrixNode($3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), $1, $2.line); } } else { if ($3->getQualifier() == EvqConst) { if (($1->isVector() || $1->isMatrix()) && $1->getType().getNominalSize() <= $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst() && !$1->isArray() ) { - parseContext->error($2.line, "", "[", "field selection out of range '%d'", $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst()); - parseContext->recover(); + context->error($2.line, "", "[", "field selection out of range '%d'", $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst()); + context->recover(); } else { if ($1->isArray()) { if ($1->getType().getArraySize() == 0) { if ($1->getType().getMaxArraySize() <= $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst()) { - if (parseContext->arraySetMaxSize($1->getAsSymbolNode(), $1->getTypePointer(), $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), true, $2.line)) - parseContext->recover(); + if (context->arraySetMaxSize($1->getAsSymbolNode(), $1->getTypePointer(), $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), true, $2.line)) + context->recover(); } else { - if (parseContext->arraySetMaxSize($1->getAsSymbolNode(), $1->getTypePointer(), 0, false, $2.line)) - parseContext->recover(); + if (context->arraySetMaxSize($1->getAsSymbolNode(), $1->getTypePointer(), 0, false, $2.line)) + context->recover(); } } else if ( $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst() >= $1->getType().getArraySize()) { - parseContext->error($2.line, "", "[", "array index out of range '%d'", $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst()); - parseContext->recover(); + context->error($2.line, "", "[", "array index out of range '%d'", $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst()); + context->recover(); } } - $$ = parseContext->intermediate.addIndex(EOpIndexDirect, $1, $3, $2.line); + $$ = context->intermediate.addIndex(EOpIndexDirect, $1, $3, $2.line); } } else { if ($1->isArray() && $1->getType().getArraySize() == 0) { - parseContext->error($2.line, "", "[", "array must be redeclared with a size before being indexed with a variable"); - parseContext->recover(); + context->error($2.line, "", "[", "array must be redeclared with a size before being indexed with a variable"); + context->recover(); } - $$ = parseContext->intermediate.addIndex(EOpIndexIndirect, $1, $3, $2.line); + $$ = context->intermediate.addIndex(EOpIndexIndirect, $1, $3, $2.line); } } if ($$ == 0) { ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setFConst(0.0f); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpHigh, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpHigh, EvqConst), $2.line); } else if ($1->isArray()) { if ($1->getType().getStruct()) $$->setType(TType($1->getType().getStruct(), $1->getType().getTypeName())); @@ -328,22 +298,22 @@ postfix_expression } | postfix_expression DOT FIELD_SELECTION { if ($1->isArray()) { - parseContext->error($3.line, "cannot apply dot operator to an array", ".", ""); - parseContext->recover(); + context->error($3.line, "cannot apply dot operator to an array", ".", ""); + context->recover(); } if ($1->isVector()) { TVectorFields fields; - if (! parseContext->parseVectorFields(*$3.string, $1->getNominalSize(), fields, $3.line)) { + if (! context->parseVectorFields(*$3.string, $1->getNominalSize(), fields, $3.line)) { fields.num = 1; fields.offsets[0] = 0; - parseContext->recover(); + context->recover(); } if ($1->getType().getQualifier() == EvqConst) { // constant folding for vector fields - $$ = parseContext->addConstVectorNode(fields, $1, $3.line); + $$ = context->addConstVectorNode(fields, $1, $3.line); if ($$ == 0) { - parseContext->recover(); + context->recover(); $$ = $1; } else @@ -352,47 +322,47 @@ postfix_expression if (fields.num == 1) { ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setIConst(fields.offsets[0]); - TIntermTyped* index = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $3.line); - $$ = parseContext->intermediate.addIndex(EOpIndexDirect, $1, index, $2.line); + TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $3.line); + $$ = context->intermediate.addIndex(EOpIndexDirect, $1, index, $2.line); $$->setType(TType($1->getBasicType(), $1->getPrecision())); } else { TString vectorString = *$3.string; - TIntermTyped* index = parseContext->intermediate.addSwizzle(fields, $3.line); - $$ = parseContext->intermediate.addIndex(EOpVectorSwizzle, $1, index, $2.line); + TIntermTyped* index = context->intermediate.addSwizzle(fields, $3.line); + $$ = context->intermediate.addIndex(EOpVectorSwizzle, $1, index, $2.line); $$->setType(TType($1->getBasicType(), $1->getPrecision(), EvqTemporary, (int) vectorString.size())); } } } else if ($1->isMatrix()) { TMatrixFields fields; - if (! parseContext->parseMatrixFields(*$3.string, $1->getNominalSize(), fields, $3.line)) { + if (! context->parseMatrixFields(*$3.string, $1->getNominalSize(), fields, $3.line)) { fields.wholeRow = false; fields.wholeCol = false; fields.row = 0; fields.col = 0; - parseContext->recover(); + context->recover(); } if (fields.wholeRow || fields.wholeCol) { - parseContext->error($2.line, " non-scalar fields not implemented yet", ".", ""); - parseContext->recover(); + context->error($2.line, " non-scalar fields not implemented yet", ".", ""); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setIConst(0); - TIntermTyped* index = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $3.line); - $$ = parseContext->intermediate.addIndex(EOpIndexDirect, $1, index, $2.line); + TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $3.line); + $$ = context->intermediate.addIndex(EOpIndexDirect, $1, index, $2.line); $$->setType(TType($1->getBasicType(), $1->getPrecision(),EvqTemporary, $1->getNominalSize())); } else { ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setIConst(fields.col * $1->getNominalSize() + fields.row); - TIntermTyped* index = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $3.line); - $$ = parseContext->intermediate.addIndex(EOpIndexDirect, $1, index, $2.line); + TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $3.line); + $$ = context->intermediate.addIndex(EOpIndexDirect, $1, index, $2.line); $$->setType(TType($1->getBasicType(), $1->getPrecision())); } } else if ($1->getBasicType() == EbtStruct) { bool fieldFound = false; const TTypeList* fields = $1->getType().getStruct(); if (fields == 0) { - parseContext->error($2.line, "structure has no fields", "Internal Error", ""); - parseContext->recover(); + context->error($2.line, "structure has no fields", "Internal Error", ""); + context->recover(); $$ = $1; } else { unsigned int i; @@ -404,9 +374,9 @@ postfix_expression } if (fieldFound) { if ($1->getType().getQualifier() == EvqConst) { - $$ = parseContext->addConstStruct(*$3.string, $1, $2.line); + $$ = context->addConstStruct(*$3.string, $1, $2.line); if ($$ == 0) { - parseContext->recover(); + context->recover(); $$ = $1; } else { @@ -418,40 +388,40 @@ postfix_expression } else { ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setIConst(i); - TIntermTyped* index = parseContext->intermediate.addConstantUnion(unionArray, *(*fields)[i].type, $3.line); - $$ = parseContext->intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line); + TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, *(*fields)[i].type, $3.line); + $$ = context->intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line); $$->setType(*(*fields)[i].type); } } else { - parseContext->error($2.line, " no such field in structure", $3.string->c_str(), ""); - parseContext->recover(); + context->error($2.line, " no such field in structure", $3.string->c_str(), ""); + context->recover(); $$ = $1; } } } else { - parseContext->error($2.line, " field selection requires structure, vector, or matrix on left hand side", $3.string->c_str(), ""); - parseContext->recover(); + context->error($2.line, " field selection requires structure, vector, or matrix on left hand side", $3.string->c_str(), ""); + context->recover(); $$ = $1; } // don't delete $3.string, it's from the pool } | postfix_expression INC_OP { - if (parseContext->lValueErrorCheck($2.line, "++", $1)) - parseContext->recover(); - $$ = parseContext->intermediate.addUnaryMath(EOpPostIncrement, $1, $2.line, parseContext->symbolTable); + if (context->lValueErrorCheck($2.line, "++", $1)) + context->recover(); + $$ = context->intermediate.addUnaryMath(EOpPostIncrement, $1, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->unaryOpError($2.line, "++", $1->getCompleteString()); - parseContext->recover(); + context->unaryOpError($2.line, "++", $1->getCompleteString()); + context->recover(); $$ = $1; } } | postfix_expression DEC_OP { - if (parseContext->lValueErrorCheck($2.line, "--", $1)) - parseContext->recover(); - $$ = parseContext->intermediate.addUnaryMath(EOpPostDecrement, $1, $2.line, parseContext->symbolTable); + if (context->lValueErrorCheck($2.line, "--", $1)) + context->recover(); + $$ = context->intermediate.addUnaryMath(EOpPostDecrement, $1, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->unaryOpError($2.line, "--", $1->getCompleteString()); - parseContext->recover(); + context->unaryOpError($2.line, "--", $1->getCompleteString()); + context->recover(); $$ = $1; } } @@ -459,8 +429,8 @@ postfix_expression integer_expression : expression { - if (parseContext->integerErrorCheck($1, "[]")) - parseContext->recover(); + if (context->integerErrorCheck($1, "[]")) + context->recover(); $$ = $1; } ; @@ -478,18 +448,18 @@ function_call // Their parameters will be verified algorithmically. // TType type(EbtVoid, EbpUndefined); // use this to get the type back - if (parseContext->constructorErrorCheck($1.line, $1.intermNode, *fnCall, op, &type)) { + if (context->constructorErrorCheck($1.line, $1.intermNode, *fnCall, op, &type)) { $$ = 0; } else { // // It's a constructor, of type 'type'. // - $$ = parseContext->addConstructor($1.intermNode, &type, op, fnCall, $1.line); + $$ = context->addConstructor($1.intermNode, &type, op, fnCall, $1.line); } if ($$ == 0) { - parseContext->recover(); - $$ = parseContext->intermediate.setAggregateOperator(0, op, $1.line); + context->recover(); + $$ = context->intermediate.setAggregateOperator(0, op, $1.line); } $$->setType(type); } else { @@ -498,12 +468,15 @@ function_call // const TFunction* fnCandidate; bool builtIn; - fnCandidate = parseContext->findFunction($1.line, fnCall, &builtIn); + fnCandidate = context->findFunction($1.line, fnCall, &builtIn); if (fnCandidate) { // - // A declared function. But, it might still map to a built-in - // operation. + // A declared function. // + if (builtIn && !fnCandidate->getExtension().empty() && + context->extensionErrorCheck($1.line, fnCandidate->getExtension())) { + context->recover(); + } op = fnCandidate->getBuiltInOp(); if (builtIn && op != EOpNull) { // @@ -513,20 +486,20 @@ function_call // // Treat it like a built-in unary operator. // - $$ = parseContext->intermediate.addUnaryMath(op, $1.intermNode, 0, parseContext->symbolTable); + $$ = context->intermediate.addUnaryMath(op, $1.intermNode, 0, context->symbolTable); if ($$ == 0) { - parseContext->error($1.intermNode->getLine(), " wrong operand type", "Internal Error", + context->error($1.intermNode->getLine(), " wrong operand type", "Internal Error", "built in unary operator function. Type: %s", static_cast<TIntermTyped*>($1.intermNode)->getCompleteString().c_str()); YYERROR; } } else { - $$ = parseContext->intermediate.setAggregateOperator($1.intermAggregate, op, $1.line); + $$ = context->intermediate.setAggregateOperator($1.intermAggregate, op, $1.line); } } else { // This is a real function call - $$ = parseContext->intermediate.setAggregateOperator($1.intermAggregate, EOpFunctionCall, $1.line); + $$ = context->intermediate.setAggregateOperator($1.intermAggregate, EOpFunctionCall, $1.line); $$->setType(fnCandidate->getReturnType()); // this is how we know whether the given function is a builtIn function or a user defined function @@ -537,16 +510,14 @@ function_call $$->getAsAggregate()->setName(fnCandidate->getMangledName()); TQualifier qual; - TQualifierList& qualifierList = $$->getAsAggregate()->getQualifier(); for (int i = 0; i < fnCandidate->getParamCount(); ++i) { - qual = (*fnCandidate)[i].type->getQualifier(); + qual = fnCandidate->getParam(i).type->getQualifier(); if (qual == EvqOut || qual == EvqInOut) { - if (parseContext->lValueErrorCheck($$->getLine(), "assign", $$->getAsAggregate()->getSequence()[i]->getAsTyped())) { - parseContext->error($1.intermNode->getLine(), "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error", ""); - parseContext->recover(); + if (context->lValueErrorCheck($$->getLine(), "assign", $$->getAsAggregate()->getSequence()[i]->getAsTyped())) { + context->error($1.intermNode->getLine(), "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error", ""); + context->recover(); } } - qualifierList.push_back(qual); } } $$->setType(fnCandidate->getReturnType()); @@ -555,8 +526,8 @@ function_call // Put on a dummy node for error recovery ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setFConst(0.0f); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpUndefined, EvqConst), $1.line); - parseContext->recover(); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpUndefined, EvqConst), $1.line); + context->recover(); } } delete fnCall; @@ -568,8 +539,8 @@ function_call_or_method $$ = $1; } | postfix_expression DOT function_call_generic { - parseContext->error($3.line, "methods are not supported", "", ""); - parseContext->recover(); + context->error($3.line, "methods are not supported", "", ""); + context->recover(); $$ = $3; } ; @@ -607,7 +578,7 @@ function_call_header_with_parameters TParameter param = { 0, new TType($3->getType()) }; $1.function->addParameter(param); $$.function = $1.function; - $$.intermNode = parseContext->intermediate.growAggregate($1.intermNode, $3, $2.line); + $$.intermNode = context->intermediate.growAggregate($1.intermNode, $3, $2.line); } ; @@ -625,19 +596,16 @@ function_identifier // Constructor // if ($1.array) { - if (parseContext->extensionErrorCheck($1.line, "GL_3DL_array_objects")) { - parseContext->recover(); - $1.setArray(false); - } + // 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) { - TString tempString = ""; - TType type($1); - TFunction *function = new TFunction(&tempString, type, EOpConstructStruct); - $$ = function; + op = EOpConstructStruct; } else { - TOperator op = EOpNull; switch ($1.type) { case EbtFloat: if ($1.matrix) { @@ -671,29 +639,30 @@ function_identifier case 4: FRAG_VERT_ONLY("bvec4", $1.line); op = EOpConstructBVec4; break; } break; + default: break; } if (op == EOpNull) { - parseContext->error($1.line, "cannot construct this type", getBasicString($1.type), ""); - parseContext->recover(); + context->error($1.line, "cannot construct this type", getBasicString($1.type), ""); + context->recover(); $1.type = EbtFloat; op = EOpConstructFloat; } - TString tempString = ""; - TType type($1); - TFunction *function = new TFunction(&tempString, type, op); - $$ = function; } + TString tempString; + TType type($1); + TFunction *function = new TFunction(&tempString, type, op); + $$ = function; } | IDENTIFIER { - if (parseContext->reservedErrorCheck($1.line, *$1.string)) - parseContext->recover(); + if (context->reservedErrorCheck($1.line, *$1.string)) + context->recover(); TType type(EbtVoid, EbpUndefined); TFunction *function = new TFunction($1.string, type); $$ = function; } | FIELD_SELECTION { - if (parseContext->reservedErrorCheck($1.line, *$1.string)) - parseContext->recover(); + if (context->reservedErrorCheck($1.line, *$1.string)) + context->recover(); TType type(EbtVoid, EbpUndefined); TFunction *function = new TFunction($1.string, type); $$ = function; @@ -705,28 +674,28 @@ unary_expression $$ = $1; } | INC_OP unary_expression { - if (parseContext->lValueErrorCheck($1.line, "++", $2)) - parseContext->recover(); - $$ = parseContext->intermediate.addUnaryMath(EOpPreIncrement, $2, $1.line, parseContext->symbolTable); + if (context->lValueErrorCheck($1.line, "++", $2)) + context->recover(); + $$ = context->intermediate.addUnaryMath(EOpPreIncrement, $2, $1.line, context->symbolTable); if ($$ == 0) { - parseContext->unaryOpError($1.line, "++", $2->getCompleteString()); - parseContext->recover(); + context->unaryOpError($1.line, "++", $2->getCompleteString()); + context->recover(); $$ = $2; } } | DEC_OP unary_expression { - if (parseContext->lValueErrorCheck($1.line, "--", $2)) - parseContext->recover(); - $$ = parseContext->intermediate.addUnaryMath(EOpPreDecrement, $2, $1.line, parseContext->symbolTable); + if (context->lValueErrorCheck($1.line, "--", $2)) + context->recover(); + $$ = context->intermediate.addUnaryMath(EOpPreDecrement, $2, $1.line, context->symbolTable); if ($$ == 0) { - parseContext->unaryOpError($1.line, "--", $2->getCompleteString()); - parseContext->recover(); + context->unaryOpError($1.line, "--", $2->getCompleteString()); + context->recover(); $$ = $2; } } | unary_operator unary_expression { if ($1.op != EOpNull) { - $$ = parseContext->intermediate.addUnaryMath($1.op, $2, $1.line, parseContext->symbolTable); + $$ = context->intermediate.addUnaryMath($1.op, $2, $1.line, context->symbolTable); if ($$ == 0) { const char* errorOp = ""; switch($1.op) { @@ -734,8 +703,8 @@ unary_expression case EOpLogicalNot: errorOp = "!"; break; default: break; } - parseContext->unaryOpError($1.line, errorOp, $2->getCompleteString()); - parseContext->recover(); + context->unaryOpError($1.line, errorOp, $2->getCompleteString()); + context->recover(); $$ = $2; } } else @@ -755,19 +724,19 @@ multiplicative_expression : unary_expression { $$ = $1; } | multiplicative_expression STAR unary_expression { FRAG_VERT_ONLY("*", $2.line); - $$ = parseContext->intermediate.addBinaryMath(EOpMul, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpMul, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "*", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "*", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); $$ = $1; } } | multiplicative_expression SLASH unary_expression { FRAG_VERT_ONLY("/", $2.line); - $$ = parseContext->intermediate.addBinaryMath(EOpDiv, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpDiv, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "/", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "/", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); $$ = $1; } } @@ -776,18 +745,18 @@ multiplicative_expression additive_expression : multiplicative_expression { $$ = $1; } | additive_expression PLUS multiplicative_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpAdd, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpAdd, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "+", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "+", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); $$ = $1; } } | additive_expression DASH multiplicative_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpSub, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpSub, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "-", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "-", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); $$ = $1; } } @@ -800,43 +769,43 @@ shift_expression relational_expression : shift_expression { $$ = $1; } | relational_expression LEFT_ANGLE shift_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpLessThan, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpLessThan, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "<", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "<", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } | relational_expression RIGHT_ANGLE shift_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpGreaterThan, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpGreaterThan, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, ">", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, ">", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } | relational_expression LE_OP shift_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpLessThanEqual, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpLessThanEqual, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "<=", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "<=", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } | relational_expression GE_OP shift_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpGreaterThanEqual, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpGreaterThanEqual, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, ">=", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, ">=", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } ; @@ -844,26 +813,24 @@ relational_expression equality_expression : relational_expression { $$ = $1; } | equality_expression EQ_OP relational_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpEqual, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpEqual, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "==", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "==", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); - } else if (($1->isArray() || $3->isArray()) && parseContext->extensionErrorCheck($2.line, "GL_3DL_array_objects")) - parseContext->recover(); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + } } | equality_expression NE_OP relational_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpNotEqual, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpNotEqual, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "!=", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "!=", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); - } else if (($1->isArray() || $3->isArray()) && parseContext->extensionErrorCheck($2.line, "GL_3DL_array_objects")) - parseContext->recover(); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + } } ; @@ -882,13 +849,13 @@ inclusive_or_expression logical_and_expression : inclusive_or_expression { $$ = $1; } | logical_and_expression AND_OP inclusive_or_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpLogicalAnd, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpLogicalAnd, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "&&", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "&&", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } ; @@ -896,13 +863,13 @@ logical_and_expression logical_xor_expression : logical_and_expression { $$ = $1; } | logical_xor_expression XOR_OP logical_and_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpLogicalXor, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpLogicalXor, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "^^", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "^^", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } ; @@ -910,13 +877,13 @@ logical_xor_expression logical_or_expression : logical_xor_expression { $$ = $1; } | logical_or_expression OR_OP logical_xor_expression { - $$ = parseContext->intermediate.addBinaryMath(EOpLogicalOr, $1, $3, $2.line, parseContext->symbolTable); + $$ = context->intermediate.addBinaryMath(EOpLogicalOr, $1, $3, $2.line, context->symbolTable); if ($$ == 0) { - parseContext->binaryOpError($2.line, "||", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, "||", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); ConstantUnion *unionArray = new ConstantUnion[1]; unionArray->setBConst(false); - $$ = parseContext->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); + $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), $2.line); } } ; @@ -924,16 +891,16 @@ logical_or_expression conditional_expression : logical_or_expression { $$ = $1; } | logical_or_expression QUESTION expression COLON assignment_expression { - if (parseContext->boolErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->boolErrorCheck($2.line, $1)) + context->recover(); - $$ = parseContext->intermediate.addSelection($1, $3, $5, $2.line); + $$ = context->intermediate.addSelection($1, $3, $5, $2.line); if ($3->getType() != $5->getType()) $$ = 0; if ($$ == 0) { - parseContext->binaryOpError($2.line, ":", $3->getCompleteString(), $5->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, ":", $3->getCompleteString(), $5->getCompleteString()); + context->recover(); $$ = $5; } } @@ -942,15 +909,14 @@ conditional_expression assignment_expression : conditional_expression { $$ = $1; } | unary_expression assignment_operator assignment_expression { - if (parseContext->lValueErrorCheck($2.line, "assign", $1)) - parseContext->recover(); - $$ = parseContext->intermediate.addAssign($2.op, $1, $3, $2.line); + if (context->lValueErrorCheck($2.line, "assign", $1)) + context->recover(); + $$ = context->intermediate.addAssign($2.op, $1, $3, $2.line); if ($$ == 0) { - parseContext->assignError($2.line, "assign", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->assignError($2.line, "assign", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); $$ = $1; - } else if (($1->isArray() || $3->isArray()) && parseContext->extensionErrorCheck($2.line, "GL_3DL_array_objects")) - parseContext->recover(); + } } ; @@ -967,10 +933,10 @@ expression $$ = $1; } | expression COMMA assignment_expression { - $$ = parseContext->intermediate.addComma($1, $3, $2.line); + $$ = context->intermediate.addComma($1, $3, $2.line); if ($$ == 0) { - parseContext->binaryOpError($2.line, ",", $1->getCompleteString(), $3->getCompleteString()); - parseContext->recover(); + context->binaryOpError($2.line, ",", $1->getCompleteString(), $3->getCompleteString()); + context->recover(); $$ = $3; } } @@ -978,8 +944,8 @@ expression constant_expression : conditional_expression { - if (parseContext->constErrorCheck($1)) - parseContext->recover(); + if (context->constErrorCheck($1)) + context->recover(); $$ = $1; } ; @@ -994,16 +960,16 @@ declaration for (int i = 0; i < function.getParamCount(); i++) { - TParameter ¶m = function[i]; + const TParameter ¶m = function.getParam(i); if (param.name != 0) { TVariable *variable = new TVariable(param.name, *param.type); - prototype = parseContext->intermediate.growAggregate(prototype, parseContext->intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), $1.line), $1.line); + prototype = context->intermediate.growAggregate(prototype, context->intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), $1.line), $1.line); } else { - prototype = parseContext->intermediate.growAggregate(prototype, parseContext->intermediate.addSymbol(0, "", *param.type, $1.line), $1.line); + prototype = context->intermediate.growAggregate(prototype, context->intermediate.addSymbol(0, "", *param.type, $1.line), $1.line); } } @@ -1016,7 +982,7 @@ declaration $$ = $1.intermAggregate; } | PRECISION precision_qualifier type_specifier_no_prec SEMICOLON { - parseContext->symbolTable.setDefaultPrecision( $3.type, $2 ); + context->symbolTable.setDefaultPrecision( $3.type, $2 ); $$ = 0; } ; @@ -1031,16 +997,16 @@ function_prototype // // Redeclarations are allowed. But, return types and parameter qualifiers must match. // - TFunction* prevDec = static_cast<TFunction*>(parseContext->symbolTable.find($1->getMangledName())); + TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName())); if (prevDec) { if (prevDec->getReturnType() != $1->getReturnType()) { - parseContext->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString(), ""); - parseContext->recover(); + context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString(), ""); + context->recover(); } for (int i = 0; i < prevDec->getParamCount(); ++i) { - if ((*prevDec)[i].type->getQualifier() != (*$1)[i].type->getQualifier()) { - parseContext->error($2.line, "overloaded functions must have the same parameter qualifiers", (*$1)[i].type->getQualifierString(), ""); - parseContext->recover(); + if (prevDec->getParam(i).type->getQualifier() != $1->getParam(i).type->getQualifier()) { + context->error($2.line, "overloaded functions must have the same parameter qualifiers", $1->getParam(i).type->getQualifierString(), ""); + context->recover(); } } } @@ -1053,7 +1019,7 @@ function_prototype $$.function = $1; $$.line = $2.line; - parseContext->symbolTable.insert(*$$.function); + context->symbolTable.insert(*$$.function); } ; @@ -1085,8 +1051,8 @@ function_header_with_parameters // // This parameter > first is void // - parseContext->error($2.line, "cannot be an argument type except for '(void)'", "void", ""); - parseContext->recover(); + context->error($2.line, "cannot be an argument type except for '(void)'", "void", ""); + context->recover(); delete $3.param.type; } else { // Add the parameter @@ -1099,12 +1065,12 @@ function_header_with_parameters function_header : fully_specified_type IDENTIFIER LEFT_PAREN { if ($1.qualifier != EvqGlobal && $1.qualifier != EvqTemporary) { - parseContext->error($2.line, "no qualifiers allowed for function return", getQualifierString($1.qualifier), ""); - parseContext->recover(); + context->error($2.line, "no qualifiers allowed for function return", getQualifierString($1.qualifier), ""); + context->recover(); } // make sure a sampler is not involved as well... - if (parseContext->structQualifierErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->structQualifierErrorCheck($2.line, $1)) + context->recover(); // Add the function as a prototype after parsing it (we do not support recursion) TFunction *function; @@ -1118,26 +1084,26 @@ parameter_declarator // Type + name : type_specifier IDENTIFIER { if ($1.type == EbtVoid) { - parseContext->error($2.line, "illegal use of type 'void'", $2.string->c_str(), ""); - parseContext->recover(); + context->error($2.line, "illegal use of type 'void'", $2.string->c_str(), ""); + context->recover(); } - if (parseContext->reservedErrorCheck($2.line, *$2.string)) - parseContext->recover(); + if (context->reservedErrorCheck($2.line, *$2.string)) + context->recover(); TParameter param = {$2.string, new TType($1)}; $$.line = $2.line; $$.param = param; } | type_specifier IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET { // Check that we can make an array out of this type - if (parseContext->arrayTypeErrorCheck($3.line, $1)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($3.line, $1)) + context->recover(); - if (parseContext->reservedErrorCheck($2.line, *$2.string)) - parseContext->recover(); + if (context->reservedErrorCheck($2.line, *$2.string)) + context->recover(); int size; - if (parseContext->arraySizeErrorCheck($3.line, $4, size)) - parseContext->recover(); + if (context->arraySizeErrorCheck($3.line, $4, size)) + context->recover(); $1.setArray(true, size); TType* type = new TType($1); @@ -1158,30 +1124,30 @@ parameter_declaration // : type_qualifier parameter_qualifier parameter_declarator { $$ = $3; - if (parseContext->paramErrorCheck($3.line, $1.qualifier, $2, $$.param.type)) - parseContext->recover(); + if (context->paramErrorCheck($3.line, $1.qualifier, $2, $$.param.type)) + context->recover(); } | parameter_qualifier parameter_declarator { $$ = $2; - if (parseContext->parameterSamplerErrorCheck($2.line, $1, *$2.param.type)) - parseContext->recover(); - if (parseContext->paramErrorCheck($2.line, EvqTemporary, $1, $$.param.type)) - parseContext->recover(); + if (context->parameterSamplerErrorCheck($2.line, $1, *$2.param.type)) + context->recover(); + if (context->paramErrorCheck($2.line, EvqTemporary, $1, $$.param.type)) + context->recover(); } // // Only type // | type_qualifier parameter_qualifier parameter_type_specifier { $$ = $3; - if (parseContext->paramErrorCheck($3.line, $1.qualifier, $2, $$.param.type)) - parseContext->recover(); + if (context->paramErrorCheck($3.line, $1.qualifier, $2, $$.param.type)) + context->recover(); } | parameter_qualifier parameter_type_specifier { $$ = $2; - if (parseContext->parameterSamplerErrorCheck($2.line, $1, *$2.param.type)) - parseContext->recover(); - if (parseContext->paramErrorCheck($2.line, EvqTemporary, $1, $$.param.type)) - parseContext->recover(); + if (context->parameterSamplerErrorCheck($2.line, $1, *$2.param.type)) + context->recover(); + if (context->paramErrorCheck($2.line, EvqTemporary, $1, $$.param.type)) + context->recover(); } ; @@ -1212,152 +1178,83 @@ init_declarator_list $$ = $1; if ($$.type.precision == EbpUndefined) { - $$.type.precision = parseContext->symbolTable.getDefaultPrecision($1.type.type); - if (parseContext->precisionErrorCheck($1.line, $$.type.precision, $1.type.type)) { - parseContext->recover(); + $$.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 = parseContext->intermediate.growAggregate($1.intermNode, parseContext->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line), $3.line); + $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line), $3.line); - if (parseContext->structQualifierErrorCheck($3.line, $$.type)) - parseContext->recover(); + if (context->structQualifierErrorCheck($3.line, $$.type)) + context->recover(); - if (parseContext->nonInitConstErrorCheck($3.line, *$3.string, $$.type)) - parseContext->recover(); + if (context->nonInitConstErrorCheck($3.line, *$3.string, $$.type)) + context->recover(); - if (parseContext->nonInitErrorCheck($3.line, *$3.string, $$.type)) - parseContext->recover(); + if (context->nonInitErrorCheck($3.line, *$3.string, $$.type)) + context->recover(); } | init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET { - if (parseContext->structQualifierErrorCheck($3.line, $1.type)) - parseContext->recover(); + if (context->structQualifierErrorCheck($3.line, $1.type)) + context->recover(); - if (parseContext->nonInitConstErrorCheck($3.line, *$3.string, $1.type)) - parseContext->recover(); + if (context->nonInitConstErrorCheck($3.line, *$3.string, $1.type)) + context->recover(); $$ = $1; - if (parseContext->arrayTypeErrorCheck($4.line, $1.type) || parseContext->arrayQualifierErrorCheck($4.line, $1.type)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($4.line, $1.type) || context->arrayQualifierErrorCheck($4.line, $1.type)) + context->recover(); else { $1.type.setArray(true); TVariable* variable; - if (parseContext->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) - parseContext->recover(); + if (context->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) + context->recover(); } } | init_declarator_list COMMA IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET { - if (parseContext->structQualifierErrorCheck($3.line, $1.type)) - parseContext->recover(); + if (context->structQualifierErrorCheck($3.line, $1.type)) + context->recover(); - if (parseContext->nonInitConstErrorCheck($3.line, *$3.string, $1.type)) - parseContext->recover(); + if (context->nonInitConstErrorCheck($3.line, *$3.string, $1.type)) + context->recover(); $$ = $1; - if (parseContext->arrayTypeErrorCheck($4.line, $1.type) || parseContext->arrayQualifierErrorCheck($4.line, $1.type)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($4.line, $1.type) || context->arrayQualifierErrorCheck($4.line, $1.type)) + context->recover(); else { int size; - if (parseContext->arraySizeErrorCheck($4.line, $5, size)) - parseContext->recover(); + if (context->arraySizeErrorCheck($4.line, $5, size)) + context->recover(); $1.type.setArray(true, size); TVariable* variable; - if (parseContext->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) - parseContext->recover(); + if (context->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) + context->recover(); TType type = TType($1.type); type.setArraySize(size); - $$.intermAggregate = parseContext->intermediate.growAggregate($1.intermNode, parseContext->intermediate.addSymbol(0, *$3.string, type, $3.line), $3.line); - } - } - | init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET EQUAL initializer { - if (parseContext->structQualifierErrorCheck($3.line, $1.type)) - parseContext->recover(); - - $$ = $1; - - TVariable* variable = 0; - if (parseContext->arrayTypeErrorCheck($4.line, $1.type) || parseContext->arrayQualifierErrorCheck($4.line, $1.type)) - parseContext->recover(); - else { - $1.type.setArray(true, $7->getType().getArraySize()); - if (parseContext->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) - parseContext->recover(); - } - - if (parseContext->extensionErrorCheck($$.line, "GL_3DL_array_objects")) - parseContext->recover(); - else { - TIntermNode* intermNode; - if (!parseContext->executeInitializer($3.line, *$3.string, $1.type, $7, intermNode, variable)) { - // - // build the intermediate representation - // - if (intermNode) - $$.intermAggregate = parseContext->intermediate.growAggregate($1.intermNode, intermNode, $6.line); - else - $$.intermAggregate = $1.intermAggregate; - } else { - parseContext->recover(); - $$.intermAggregate = 0; - } - } - } - | init_declarator_list COMMA IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET EQUAL initializer { - if (parseContext->structQualifierErrorCheck($3.line, $1.type)) - parseContext->recover(); - - $$ = $1; - - TVariable* variable = 0; - if (parseContext->arrayTypeErrorCheck($4.line, $1.type) || parseContext->arrayQualifierErrorCheck($4.line, $1.type)) - parseContext->recover(); - else { - int size; - if (parseContext->arraySizeErrorCheck($4.line, $5, size)) - parseContext->recover(); - $1.type.setArray(true, size); - if (parseContext->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) - parseContext->recover(); - } - - if (parseContext->extensionErrorCheck($$.line, "GL_3DL_array_objects")) - parseContext->recover(); - else { - TIntermNode* intermNode; - if (!parseContext->executeInitializer($3.line, *$3.string, $1.type, $8, intermNode, variable)) { - // - // build the intermediate representation - // - if (intermNode) - $$.intermAggregate = parseContext->intermediate.growAggregate($1.intermNode, intermNode, $7.line); - else - $$.intermAggregate = $1.intermAggregate; - } else { - parseContext->recover(); - $$.intermAggregate = 0; - } + $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(0, *$3.string, type, $3.line), $3.line); } } | init_declarator_list COMMA IDENTIFIER EQUAL initializer { - if (parseContext->structQualifierErrorCheck($3.line, $1.type)) - parseContext->recover(); + if (context->structQualifierErrorCheck($3.line, $1.type)) + context->recover(); $$ = $1; TIntermNode* intermNode; - if (!parseContext->executeInitializer($3.line, *$3.string, $1.type, $5, intermNode)) { + if (!context->executeInitializer($3.line, *$3.string, $1.type, $5, intermNode)) { // // build the intermediate representation // if (intermNode) - $$.intermAggregate = parseContext->intermediate.growAggregate($1.intermNode, intermNode, $4.line); + $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, intermNode, $4.line); else $$.intermAggregate = $1.intermAggregate; } else { - parseContext->recover(); + context->recover(); $$.intermAggregate = 0; } } @@ -1366,88 +1263,88 @@ init_declarator_list single_declaration : fully_specified_type { $$.type = $1; - $$.intermAggregate = parseContext->intermediate.makeAggregate(parseContext->intermediate.addSymbol(0, "", TType($1), $1.line), $1.line); + $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, "", TType($1), $1.line), $1.line); } | fully_specified_type IDENTIFIER { - $$.intermAggregate = parseContext->intermediate.makeAggregate(parseContext->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line); + $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line); - if (parseContext->structQualifierErrorCheck($2.line, $$.type)) - parseContext->recover(); + if (context->structQualifierErrorCheck($2.line, $$.type)) + context->recover(); - if (parseContext->nonInitConstErrorCheck($2.line, *$2.string, $$.type)) - parseContext->recover(); + if (context->nonInitConstErrorCheck($2.line, *$2.string, $$.type)) + context->recover(); $$.type = $1; - if (parseContext->nonInitErrorCheck($2.line, *$2.string, $$.type)) - parseContext->recover(); + if (context->nonInitErrorCheck($2.line, *$2.string, $$.type)) + context->recover(); } | fully_specified_type IDENTIFIER LEFT_BRACKET RIGHT_BRACKET { - $$.intermAggregate = parseContext->intermediate.makeAggregate(parseContext->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line); + $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line); - if (parseContext->structQualifierErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->structQualifierErrorCheck($2.line, $1)) + context->recover(); - if (parseContext->nonInitConstErrorCheck($2.line, *$2.string, $1)) - parseContext->recover(); + if (context->nonInitConstErrorCheck($2.line, *$2.string, $1)) + context->recover(); $$.type = $1; - if (parseContext->arrayTypeErrorCheck($3.line, $1) || parseContext->arrayQualifierErrorCheck($3.line, $1)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($3.line, $1) || context->arrayQualifierErrorCheck($3.line, $1)) + context->recover(); else { $1.setArray(true); TVariable* variable; - if (parseContext->arrayErrorCheck($3.line, *$2.string, $1, variable)) - parseContext->recover(); + 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); int size; - if (parseContext->arraySizeErrorCheck($2.line, $4, size)) - parseContext->recover(); + if (context->arraySizeErrorCheck($2.line, $4, size)) + context->recover(); type.setArraySize(size); - $$.intermAggregate = parseContext->intermediate.makeAggregate(parseContext->intermediate.addSymbol(0, *$2.string, type, $2.line), $2.line); + $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, type, $2.line), $2.line); - if (parseContext->structQualifierErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->structQualifierErrorCheck($2.line, $1)) + context->recover(); - if (parseContext->nonInitConstErrorCheck($2.line, *$2.string, $1)) - parseContext->recover(); + if (context->nonInitConstErrorCheck($2.line, *$2.string, $1)) + context->recover(); $$.type = $1; - if (parseContext->arrayTypeErrorCheck($3.line, $1) || parseContext->arrayQualifierErrorCheck($3.line, $1)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($3.line, $1) || context->arrayQualifierErrorCheck($3.line, $1)) + context->recover(); else { int size; - if (parseContext->arraySizeErrorCheck($3.line, $4, size)) - parseContext->recover(); + if (context->arraySizeErrorCheck($3.line, $4, size)) + context->recover(); $1.setArray(true, size); TVariable* variable; - if (parseContext->arrayErrorCheck($3.line, *$2.string, $1, variable)) - parseContext->recover(); + if (context->arrayErrorCheck($3.line, *$2.string, $1, variable)) + context->recover(); } } | fully_specified_type IDENTIFIER EQUAL initializer { - if (parseContext->structQualifierErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->structQualifierErrorCheck($2.line, $1)) + context->recover(); $$.type = $1; TIntermNode* intermNode; - if (!parseContext->executeInitializer($2.line, *$2.string, $1, $4, intermNode)) { + if (!context->executeInitializer($2.line, *$2.string, $1, $4, intermNode)) { // // Build intermediate representation // if(intermNode) - $$.intermAggregate = parseContext->intermediate.makeAggregate(intermNode, $3.line); + $$.intermAggregate = context->intermediate.makeAggregate(intermNode, $3.line); else $$.intermAggregate = 0; } else { - parseContext->recover(); + context->recover(); $$.intermAggregate = 0; } } @@ -1479,14 +1376,14 @@ single_declaration // //input_or_output // : INPUT { -// if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "input")) -// parseContext->recover(); +// if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "input")) +// context->recover(); // UNPACK_ONLY("input", $1.line); // $$.qualifier = EvqInput; // } // | OUTPUT { -// if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "output")) -// parseContext->recover(); +// if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "output")) +// context->recover(); // PACK_ONLY("output", $1.line); // $$.qualifier = EvqOutput; // } @@ -1515,12 +1412,12 @@ single_declaration // //buffer_declaration // : type_specifier IDENTIFIER COLON constant_expression SEMICOLON { -// if (parseContext->reservedErrorCheck($2.line, *$2.string, parseContext)) -// parseContext->recover(); +// if (context->reservedErrorCheck($2.line, *$2.string, context)) +// context->recover(); // $$.variable = new TVariable($2.string, $1); -// if (! parseContext->symbolTable.insert(*$$.variable)) { -// parseContext->error($2.line, "redefinition", $$.variable->getName().c_str(), ""); -// parseContext->recover(); +// if (! context->symbolTable.insert(*$$.variable)) { +// context->error($2.line, "redefinition", $$.variable->getName().c_str(), ""); +// context->recover(); // // don't have to delete $$.variable, the pool pop will take care of it // } // } @@ -1531,31 +1428,27 @@ fully_specified_type $$ = $1; if ($1.array) { - if (parseContext->extensionErrorCheck($1.line, "GL_3DL_array_objects")) { - parseContext->recover(); - $1.setArray(false); - } + context->error($1.line, "not supported", "first-class array", ""); + context->recover(); + $1.setArray(false); } } | type_qualifier type_specifier { - if ($2.array && parseContext->extensionErrorCheck($2.line, "GL_3DL_array_objects")) { - parseContext->recover(); - $2.setArray(false); - } - if ($2.array && parseContext->arrayQualifierErrorCheck($2.line, $1)) { - parseContext->recover(); + if ($2.array) { + context->error($2.line, "not supported", "first-class array", ""); + context->recover(); $2.setArray(false); } if ($1.qualifier == EvqAttribute && ($2.type == EbtBool || $2.type == EbtInt)) { - parseContext->error($2.line, "cannot be bool or int", getQualifierString($1.qualifier), ""); - parseContext->recover(); + context->error($2.line, "cannot be bool or int", getQualifierString($1.qualifier), ""); + context->recover(); } if (($1.qualifier == EvqVaryingIn || $1.qualifier == EvqVaryingOut) && ($2.type == EbtBool || $2.type == EbtInt)) { - parseContext->error($2.line, "cannot be bool or int", getQualifierString($1.qualifier), ""); - parseContext->recover(); + context->error($2.line, "cannot be bool or int", getQualifierString($1.qualifier), ""); + context->recover(); } $$ = $2; $$.qualifier = $1.qualifier; @@ -1568,29 +1461,29 @@ type_qualifier } | ATTRIBUTE { VERTEX_ONLY("attribute", $1.line); - if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "attribute")) - parseContext->recover(); + if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "attribute")) + context->recover(); $$.setBasic(EbtVoid, EvqAttribute, $1.line); } | VARYING { - if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "varying")) - parseContext->recover(); - if (parseContext->language == EShLangVertex) + if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "varying")) + context->recover(); + if (context->shaderType == SH_VERTEX_SHADER) $$.setBasic(EbtVoid, EvqVaryingOut, $1.line); else $$.setBasic(EbtVoid, EvqVaryingIn, $1.line); } | INVARIANT VARYING { - if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "invariant varying")) - parseContext->recover(); - if (parseContext->language == EShLangVertex) + if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "invariant varying")) + context->recover(); + if (context->shaderType == SH_VERTEX_SHADER) $$.setBasic(EbtVoid, EvqInvariantVaryingOut, $1.line); else $$.setBasic(EbtVoid, EvqInvariantVaryingIn, $1.line); } | UNIFORM { - if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "uniform")) - parseContext->recover(); + if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "uniform")) + context->recover(); $$.setBasic(EbtVoid, EvqUniform, $1.line); } ; @@ -1624,12 +1517,12 @@ type_specifier_no_prec | type_specifier_nonarray LEFT_BRACKET constant_expression RIGHT_BRACKET { $$ = $1; - if (parseContext->arrayTypeErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($2.line, $1)) + context->recover(); else { int size; - if (parseContext->arraySizeErrorCheck($2.line, $3, size)) - parseContext->recover(); + if (context->arraySizeErrorCheck($2.line, $3, size)) + context->recover(); $$.setArray(true, size); } } @@ -1637,103 +1530,103 @@ type_specifier_no_prec type_specifier_nonarray : VOID_TYPE { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtVoid, qual, $1.line); } | FLOAT_TYPE { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); } | INT_TYPE { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtInt, qual, $1.line); } | BOOL_TYPE { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtBool, qual, $1.line); } // | UNSIGNED INT_TYPE { // PACK_UNPACK_ONLY("unsigned", $1.line); -// TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; +// TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; // $$.setBasic(EbtInt, qual, $1.line); // } | VEC2 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); $$.setAggregate(2); } | VEC3 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); $$.setAggregate(3); } | VEC4 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); $$.setAggregate(4); } | BVEC2 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtBool, qual, $1.line); $$.setAggregate(2); } | BVEC3 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtBool, qual, $1.line); $$.setAggregate(3); } | BVEC4 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtBool, qual, $1.line); $$.setAggregate(4); } | IVEC2 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtInt, qual, $1.line); $$.setAggregate(2); } | IVEC3 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtInt, qual, $1.line); $$.setAggregate(3); } | IVEC4 { - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtInt, qual, $1.line); $$.setAggregate(4); } | MATRIX2 { FRAG_VERT_ONLY("mat2", $1.line); - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); $$.setAggregate(2, true); } | MATRIX3 { FRAG_VERT_ONLY("mat3", $1.line); - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); $$.setAggregate(3, true); } | MATRIX4 { FRAG_VERT_ONLY("mat4", $1.line); - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtFloat, qual, $1.line); $$.setAggregate(4, true); } | SAMPLER2D { FRAG_VERT_ONLY("sampler2D", $1.line); - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtSampler2D, qual, $1.line); } | SAMPLERCUBE { FRAG_VERT_ONLY("samplerCube", $1.line); - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtSamplerCube, qual, $1.line); } | struct_specifier { FRAG_VERT_ONLY("struct", $1.line); $$ = $1; - $$.qualifier = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + $$.qualifier = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; } | TYPE_NAME { // @@ -1741,7 +1634,7 @@ type_specifier_nonarray // type. // TType& structure = static_cast<TVariable*>($1.symbol)->getType(); - TQualifier qual = parseContext->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; + TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; $$.setBasic(EbtStruct, qual, $1.line); $$.userDef = &structure; } @@ -1749,14 +1642,14 @@ type_specifier_nonarray struct_specifier : STRUCT IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE { - if (parseContext->reservedErrorCheck($2.line, *$2.string)) - parseContext->recover(); + if (context->reservedErrorCheck($2.line, *$2.string)) + context->recover(); TType* structure = new TType($4, *$2.string); TVariable* userTypeDef = new TVariable($2.string, *structure, true); - if (! parseContext->symbolTable.insert(*userTypeDef)) { - parseContext->error($2.line, "redefinition", $2.string->c_str(), "struct"); - parseContext->recover(); + if (! context->symbolTable.insert(*userTypeDef)) { + context->error($2.line, "redefinition", $2.string->c_str(), "struct"); + context->recover(); } $$.setBasic(EbtStruct, EvqTemporary, $1.line); $$.userDef = structure; @@ -1777,8 +1670,8 @@ struct_declaration_list for (unsigned int i = 0; i < $2->size(); ++i) { for (unsigned int j = 0; j < $$->size(); ++j) { if ((*$$)[j].type->getFieldName() == (*$2)[i].type->getFieldName()) { - parseContext->error((*$2)[i].line, "duplicate field name in structure:", "struct", (*$2)[i].type->getFieldName().c_str()); - parseContext->recover(); + context->error((*$2)[i].line, "duplicate field name in structure:", "struct", (*$2)[i].type->getFieldName().c_str()); + context->recover(); } } $$->push_back((*$2)[i]); @@ -1790,8 +1683,8 @@ struct_declaration : type_specifier struct_declarator_list SEMICOLON { $$ = $2; - if (parseContext->voidErrorCheck($1.line, (*$2)[0].type->getFieldName(), $1)) { - parseContext->recover(); + if (context->voidErrorCheck($1.line, (*$2)[0].type->getFieldName(), $1)) { + context->recover(); } for (unsigned int i = 0; i < $$->size(); ++i) { // @@ -1804,8 +1697,8 @@ struct_declaration // don't allow arrays of arrays if (type->isArray()) { - if (parseContext->arrayTypeErrorCheck($1.line, $1)) - parseContext->recover(); + if (context->arrayTypeErrorCheck($1.line, $1)) + context->recover(); } if ($1.array) type->setArraySize($1.arraySize); @@ -1829,24 +1722,24 @@ struct_declarator_list struct_declarator : IDENTIFIER { - if (parseContext->reservedErrorCheck($1.line, *$1.string)) - parseContext->recover(); + if (context->reservedErrorCheck($1.line, *$1.string)) + context->recover(); $$.type = new TType(EbtVoid, EbpUndefined); $$.line = $1.line; $$.type->setFieldName(*$1.string); } | IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET { - if (parseContext->reservedErrorCheck($1.line, *$1.string)) - parseContext->recover(); + if (context->reservedErrorCheck($1.line, *$1.string)) + context->recover(); $$.type = new TType(EbtVoid, EbpUndefined); $$.line = $1.line; $$.type->setFieldName(*$1.string); int size; - if (parseContext->arraySizeErrorCheck($2.line, $3, size)) - parseContext->recover(); + if (context->arraySizeErrorCheck($2.line, $3, size)) + context->recover(); $$.type->setArraySize(size); } ; @@ -1876,7 +1769,7 @@ simple_statement compound_statement : LEFT_BRACE RIGHT_BRACE { $$ = 0; } - | LEFT_BRACE { parseContext->symbolTable.push(); } statement_list { parseContext->symbolTable.pop(); } RIGHT_BRACE { + | LEFT_BRACE { context->symbolTable.push(); } statement_list { context->symbolTable.pop(); } RIGHT_BRACE { if ($3 != 0) $3->setOp(EOpSequence); $$ = $3; @@ -1902,10 +1795,10 @@ compound_statement_no_new_scope statement_list : statement { - $$ = parseContext->intermediate.makeAggregate($1, 0); + $$ = context->intermediate.makeAggregate($1, 0); } | statement_list statement { - $$ = parseContext->intermediate.growAggregate($1, $2, 0); + $$ = context->intermediate.growAggregate($1, $2, 0); } ; @@ -1916,9 +1809,9 @@ expression_statement selection_statement : IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement { - if (parseContext->boolErrorCheck($1.line, $3)) - parseContext->recover(); - $$ = parseContext->intermediate.addSelection($3, $5, $1.line); + if (context->boolErrorCheck($1.line, $3)) + context->recover(); + $$ = context->intermediate.addSelection($3, $5, $1.line); } ; @@ -1939,42 +1832,42 @@ condition // In 1996 c++ draft, conditions can include single declarations : expression { $$ = $1; - if (parseContext->boolErrorCheck($1->getLine(), $1)) - parseContext->recover(); + if (context->boolErrorCheck($1->getLine(), $1)) + context->recover(); } | fully_specified_type IDENTIFIER EQUAL initializer { TIntermNode* intermNode; - if (parseContext->structQualifierErrorCheck($2.line, $1)) - parseContext->recover(); - if (parseContext->boolErrorCheck($2.line, $1)) - parseContext->recover(); + if (context->structQualifierErrorCheck($2.line, $1)) + context->recover(); + if (context->boolErrorCheck($2.line, $1)) + context->recover(); - if (!parseContext->executeInitializer($2.line, *$2.string, $1, $4, intermNode)) + if (!context->executeInitializer($2.line, *$2.string, $1, $4, intermNode)) $$ = $4; else { - parseContext->recover(); + context->recover(); $$ = 0; } } ; iteration_statement - : WHILE LEFT_PAREN { parseContext->symbolTable.push(); ++parseContext->loopNestingLevel; } condition RIGHT_PAREN statement_no_new_scope { - parseContext->symbolTable.pop(); - $$ = parseContext->intermediate.addLoop(0, $6, $4, 0, true, $1.line); - --parseContext->loopNestingLevel; + : WHILE LEFT_PAREN { context->symbolTable.push(); ++context->loopNestingLevel; } condition RIGHT_PAREN statement_no_new_scope { + context->symbolTable.pop(); + $$ = context->intermediate.addLoop(ELoopWhile, 0, $4, 0, $6, $1.line); + --context->loopNestingLevel; } - | DO { ++parseContext->loopNestingLevel; } statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON { - if (parseContext->boolErrorCheck($8.line, $6)) - parseContext->recover(); + | DO { ++context->loopNestingLevel; } statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON { + if (context->boolErrorCheck($8.line, $6)) + context->recover(); - $$ = parseContext->intermediate.addLoop(0, $3, $6, 0, false, $4.line); - --parseContext->loopNestingLevel; + $$ = context->intermediate.addLoop(ELoopDoWhile, 0, $6, 0, $3, $4.line); + --context->loopNestingLevel; } - | FOR LEFT_PAREN { parseContext->symbolTable.push(); ++parseContext->loopNestingLevel; } for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope { - parseContext->symbolTable.pop(); - $$ = parseContext->intermediate.addLoop($4, $7, reinterpret_cast<TIntermTyped*>($5.node1), reinterpret_cast<TIntermTyped*>($5.node2), true, $1.line); - --parseContext->loopNestingLevel; + | FOR LEFT_PAREN { context->symbolTable.push(); ++context->loopNestingLevel; } for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope { + context->symbolTable.pop(); + $$ = context->intermediate.addLoop(ELoopFor, $4, reinterpret_cast<TIntermTyped*>($5.node1), reinterpret_cast<TIntermTyped*>($5.node2), $7, $1.line); + --context->loopNestingLevel; } ; @@ -2009,40 +1902,40 @@ for_rest_statement jump_statement : CONTINUE SEMICOLON { - if (parseContext->loopNestingLevel <= 0) { - parseContext->error($1.line, "continue statement only allowed in loops", "", ""); - parseContext->recover(); + if (context->loopNestingLevel <= 0) { + context->error($1.line, "continue statement only allowed in loops", "", ""); + context->recover(); } - $$ = parseContext->intermediate.addBranch(EOpContinue, $1.line); + $$ = context->intermediate.addBranch(EOpContinue, $1.line); } | BREAK SEMICOLON { - if (parseContext->loopNestingLevel <= 0) { - parseContext->error($1.line, "break statement only allowed in loops", "", ""); - parseContext->recover(); + if (context->loopNestingLevel <= 0) { + context->error($1.line, "break statement only allowed in loops", "", ""); + context->recover(); } - $$ = parseContext->intermediate.addBranch(EOpBreak, $1.line); + $$ = context->intermediate.addBranch(EOpBreak, $1.line); } | RETURN SEMICOLON { - $$ = parseContext->intermediate.addBranch(EOpReturn, $1.line); - if (parseContext->currentFunctionType->getBasicType() != EbtVoid) { - parseContext->error($1.line, "non-void function must return a value", "return", ""); - parseContext->recover(); + $$ = context->intermediate.addBranch(EOpReturn, $1.line); + if (context->currentFunctionType->getBasicType() != EbtVoid) { + context->error($1.line, "non-void function must return a value", "return", ""); + context->recover(); } } | RETURN expression SEMICOLON { - $$ = parseContext->intermediate.addBranch(EOpReturn, $2, $1.line); - parseContext->functionReturnsValue = true; - if (parseContext->currentFunctionType->getBasicType() == EbtVoid) { - parseContext->error($1.line, "void function cannot return a value", "return", ""); - parseContext->recover(); - } else if (*(parseContext->currentFunctionType) != $2->getType()) { - parseContext->error($1.line, "function return is not matching type:", "return", ""); - parseContext->recover(); + $$ = context->intermediate.addBranch(EOpReturn, $2, $1.line); + context->functionReturnsValue = true; + if (context->currentFunctionType->getBasicType() == EbtVoid) { + context->error($1.line, "void function cannot return a value", "return", ""); + context->recover(); + } else if (*(context->currentFunctionType) != $2->getType()) { + context->error($1.line, "function return is not matching type:", "return", ""); + context->recover(); } } | DISCARD SEMICOLON { FRAG_ONLY("discard", $1.line); - $$ = parseContext->intermediate.addBranch(EOpKill, $1.line); + $$ = context->intermediate.addBranch(EOpKill, $1.line); } ; @@ -2051,11 +1944,11 @@ jump_statement translation_unit : external_declaration { $$ = $1; - parseContext->treeRoot = $$; + context->treeRoot = $$; } | translation_unit external_declaration { - $$ = parseContext->intermediate.growAggregate($1, $2, 0); - parseContext->treeRoot = $$; + $$ = context->intermediate.growAggregate($1, $2, 0); + context->treeRoot = $$; } ; @@ -2070,8 +1963,8 @@ external_declaration function_definition : function_prototype { - TFunction& function = *($1.function); - TFunction* prevDec = static_cast<TFunction*>(parseContext->symbolTable.find(function.getMangledName())); + TFunction* function = $1.function; + TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName())); // // Note: 'prevDec' could be 'function' if this is the first time we've seen function // as it would have just been put in the symbol table. Otherwise, we're looking up @@ -2081,35 +1974,35 @@ function_definition // // Then this function already has a body. // - parseContext->error($1.line, "function already has a body", function.getName().c_str(), ""); - parseContext->recover(); + context->error($1.line, "function already has a body", function->getName().c_str(), ""); + context->recover(); } prevDec->setDefined(); // // Raise error message if main function takes any parameters or return anything other than void // - if (function.getName() == "main") { - if (function.getParamCount() > 0) { - parseContext->error($1.line, "function cannot take any parameter(s)", function.getName().c_str(), ""); - parseContext->recover(); + if (function->getName() == "main") { + if (function->getParamCount() > 0) { + context->error($1.line, "function cannot take any parameter(s)", function->getName().c_str(), ""); + context->recover(); } - if (function.getReturnType().getBasicType() != EbtVoid) { - parseContext->error($1.line, "", function.getReturnType().getBasicString(), "main function cannot return a value"); - parseContext->recover(); + if (function->getReturnType().getBasicType() != EbtVoid) { + context->error($1.line, "", function->getReturnType().getBasicString(), "main function cannot return a value"); + context->recover(); } } // // New symbol table scope for body of function plus its arguments // - parseContext->symbolTable.push(); + context->symbolTable.push(); // // Remember the return type for later checking for RETURN statements. // - parseContext->currentFunctionType = &(prevDec->getReturnType()); - parseContext->functionReturnsValue = false; + context->currentFunctionType = &(prevDec->getReturnType()); + context->functionReturnsValue = false; // // Insert parameters into the symbol table. @@ -2120,59 +2013,60 @@ function_definition // knows where to find parameters. // TIntermAggregate* paramNodes = new TIntermAggregate; - for (int i = 0; i < function.getParamCount(); i++) { - TParameter& param = function[i]; + for (int i = 0; i < function->getParamCount(); i++) { + const TParameter& param = function->getParam(i); if (param.name != 0) { TVariable *variable = new TVariable(param.name, *param.type); // // Insert the parameters with name in the symbol table. // - if (! parseContext->symbolTable.insert(*variable)) { - parseContext->error($1.line, "redefinition", variable->getName().c_str(), ""); - parseContext->recover(); + if (! context->symbolTable.insert(*variable)) { + context->error($1.line, "redefinition", variable->getName().c_str(), ""); + context->recover(); delete variable; } - // - // Transfer ownership of name pointer to symbol table. - // - param.name = 0; // // Add the parameter to the HIL // - paramNodes = parseContext->intermediate.growAggregate( + paramNodes = context->intermediate.growAggregate( paramNodes, - parseContext->intermediate.addSymbol(variable->getUniqueId(), + context->intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), $1.line), $1.line); } else { - paramNodes = parseContext->intermediate.growAggregate(paramNodes, parseContext->intermediate.addSymbol(0, "", *param.type, $1.line), $1.line); + paramNodes = context->intermediate.growAggregate(paramNodes, context->intermediate.addSymbol(0, "", *param.type, $1.line), $1.line); } } - parseContext->intermediate.setAggregateOperator(paramNodes, EOpParameters, $1.line); + context->intermediate.setAggregateOperator(paramNodes, EOpParameters, $1.line); $1.intermAggregate = paramNodes; - parseContext->loopNestingLevel = 0; + context->loopNestingLevel = 0; } compound_statement_no_new_scope { //?? Check that all paths return a value if return type != void ? // May be best done as post process phase on intermediate code - if (parseContext->currentFunctionType->getBasicType() != EbtVoid && ! parseContext->functionReturnsValue) { - parseContext->error($1.line, "function does not return a value:", "", $1.function->getName().c_str()); - parseContext->recover(); + if (context->currentFunctionType->getBasicType() != EbtVoid && ! context->functionReturnsValue) { + context->error($1.line, "function does not return a value:", "", $1.function->getName().c_str()); + context->recover(); } - parseContext->symbolTable.pop(); - $$ = parseContext->intermediate.growAggregate($1.intermAggregate, $3, 0); - parseContext->intermediate.setAggregateOperator($$, EOpFunction, $1.line); + context->symbolTable.pop(); + $$ = context->intermediate.growAggregate($1.intermAggregate, $3, 0); + context->intermediate.setAggregateOperator($$, EOpFunction, $1.line); $$->getAsAggregate()->setName($1.function->getMangledName().c_str()); $$->getAsAggregate()->setType($1.function->getReturnType()); // store the pragma information for debug and optimize and other vendor specific // information. This information can be queried from the parse tree - $$->getAsAggregate()->setOptimize(parseContext->contextPragma.optimize); - $$->getAsAggregate()->setDebug(parseContext->contextPragma.debug); - $$->getAsAggregate()->addToPragmaTable(parseContext->contextPragma.pragmaTable); + $$->getAsAggregate()->setOptimize(context->contextPragma.optimize); + $$->getAsAggregate()->setDebug(context->contextPragma.debug); + $$->getAsAggregate()->addToPragmaTable(context->contextPragma.pragmaTable); } ; %% + +int glslang_parse(TParseContext* context) { + return yyparse(context); +} + |