Commit 6e06b1f4 by Jamie Madill

Make TParseContext a class, with private data.

*re-land with build fix* BUG=angleproject:995 Change-Id: I67d3ded8f6c705b54fb372857e07ce1a86b58475 Reviewed-on: https://chromium-review.googlesource.com/271162Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 558d5eb4
...@@ -202,7 +202,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[], ...@@ -202,7 +202,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[],
shaderType, shaderSpec, compileOptions, true, shaderType, shaderSpec, compileOptions, true,
infoSink, debugShaderPrecision); infoSink, debugShaderPrecision);
parseContext.fragmentPrecisionHigh = fragmentPrecisionHigh; parseContext.setFragmentPrecisionHigh(fragmentPrecisionHigh);
SetGlobalParseContext(&parseContext); SetGlobalParseContext(&parseContext);
// We preserve symbols at the built-in level from compile-to-compile. // We preserve symbols at the built-in level from compile-to-compile.
...@@ -211,8 +211,8 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[], ...@@ -211,8 +211,8 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[],
// Parse shader. // Parse shader.
bool success = bool success =
(PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) && (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, &parseContext) == 0) &&
(parseContext.treeRoot != NULL); (parseContext.getTreeRoot() != nullptr);
shaderVersion = parseContext.getShaderVersion(); shaderVersion = parseContext.getShaderVersion();
if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion) if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion)
...@@ -222,7 +222,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[], ...@@ -222,7 +222,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[],
success = false; success = false;
} }
TIntermNode *root = NULL; TIntermNode *root = nullptr;
if (success) if (success)
{ {
...@@ -232,7 +232,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[], ...@@ -232,7 +232,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[],
symbolTable.setGlobalInvariant(); symbolTable.setGlobalInvariant();
} }
root = parseContext.treeRoot; root = parseContext.getTreeRoot();
success = intermediate.postProcess(root); success = intermediate.postProcess(root);
// Disallow expressions deemed too complex. // Disallow expressions deemed too complex.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
bool InitializeParseContextIndex(); bool InitializeParseContextIndex();
void FreeParseContextIndex(); void FreeParseContextIndex();
struct TParseContext; class TParseContext;
extern void SetGlobalParseContext(TParseContext* context); extern void SetGlobalParseContext(TParseContext* context);
extern TParseContext* GetGlobalParseContext(); extern TParseContext* GetGlobalParseContext();
......
...@@ -185,8 +185,8 @@ void TParseContext::error(const TSourceLoc& loc, ...@@ -185,8 +185,8 @@ void TParseContext::error(const TSourceLoc& loc,
pp::SourceLocation srcLoc; pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
diagnostics.writeInfo(pp::Diagnostics::PP_ERROR, mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR,
srcLoc, reason, token, extraInfo); srcLoc, reason, token, extraInfo);
} }
...@@ -196,8 +196,8 @@ void TParseContext::warning(const TSourceLoc& loc, ...@@ -196,8 +196,8 @@ void TParseContext::warning(const TSourceLoc& loc,
pp::SourceLocation srcLoc; pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
diagnostics.writeInfo(pp::Diagnostics::PP_WARNING, mDiagnostics.writeInfo(pp::Diagnostics::PP_WARNING,
srcLoc, reason, token, extraInfo); srcLoc, reason, token, extraInfo);
} }
// //
...@@ -236,7 +236,7 @@ void TParseContext::binaryOpError(const TSourceLoc& line, const char* op, TStrin ...@@ -236,7 +236,7 @@ void TParseContext::binaryOpError(const TSourceLoc& line, const char* op, TStrin
} }
bool TParseContext::precisionErrorCheck(const TSourceLoc& line, TPrecision precision, TBasicType type){ bool TParseContext::precisionErrorCheck(const TSourceLoc& line, TPrecision precision, TBasicType type){
if (!checksPrecisionErrors) if (!mChecksPrecisionErrors)
return false; return false;
switch( type ){ switch( type ){
case EbtFloat: case EbtFloat:
...@@ -433,7 +433,7 @@ bool TParseContext::reservedErrorCheck(const TSourceLoc& line, const TString& id ...@@ -433,7 +433,7 @@ bool TParseContext::reservedErrorCheck(const TSourceLoc& line, const TString& id
error(line, reservedErrMsg, "gl_"); error(line, reservedErrMsg, "gl_");
return true; return true;
} }
if (IsWebGLBasedSpec(shaderSpec)) { if (IsWebGLBasedSpec(mShaderSpec)) {
if (identifier.compare(0, 6, "webgl_") == 0) { if (identifier.compare(0, 6, "webgl_") == 0) {
error(line, reservedErrMsg, "webgl_"); error(line, reservedErrMsg, "webgl_");
return true; return true;
...@@ -442,7 +442,7 @@ bool TParseContext::reservedErrorCheck(const TSourceLoc& line, const TString& id ...@@ -442,7 +442,7 @@ bool TParseContext::reservedErrorCheck(const TSourceLoc& line, const TString& id
error(line, reservedErrMsg, "_webgl_"); error(line, reservedErrMsg, "_webgl_");
return true; return true;
} }
if (shaderSpec == SH_CSS_SHADERS_SPEC && identifier.compare(0, 4, "css_") == 0) { if (mShaderSpec == SH_CSS_SHADERS_SPEC && identifier.compare(0, 4, "css_") == 0) {
error(line, reservedErrMsg, "css_"); error(line, reservedErrMsg, "css_");
return true; return true;
} }
...@@ -736,7 +736,7 @@ bool TParseContext::arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* ex ...@@ -736,7 +736,7 @@ bool TParseContext::arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* ex
bool TParseContext::arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type) bool TParseContext::arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type)
{ {
if ((type.qualifier == EvqAttribute) || (type.qualifier == EvqVertexIn) || if ((type.qualifier == EvqAttribute) || (type.qualifier == EvqVertexIn) ||
(type.qualifier == EvqConst && shaderVersion < 300)) (type.qualifier == EvqConst && mShaderVersion < 300))
{ {
error(line, "cannot declare arrays of this qualifier", TType(type).getCompleteString().c_str()); error(line, "cannot declare arrays of this qualifier", TType(type).getCompleteString().c_str());
return true; return true;
...@@ -779,7 +779,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc &line, const TString &ide ...@@ -779,7 +779,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc &line, const TString &ide
// Generate informative error messages for ESSL1. // Generate informative error messages for ESSL1.
// In ESSL3 arrays and structures containing arrays can be constant. // In ESSL3 arrays and structures containing arrays can be constant.
if (shaderVersion < 300 && type->isStructureContainingArrays()) if (mShaderVersion < 300 && type->isStructureContainingArrays())
{ {
error(line, "structures containing arrays may not be declared constant since they cannot be initialized", identifier.c_str()); error(line, "structures containing arrays may not be declared constant since they cannot be initialized", identifier.c_str());
} }
...@@ -814,10 +814,10 @@ bool TParseContext::declareVariable(const TSourceLoc &line, const TString &ident ...@@ -814,10 +814,10 @@ bool TParseContext::declareVariable(const TSourceLoc &line, const TString &ident
if (type.isArray() && identifier.compare(0, 15, "gl_LastFragData") == 0) if (type.isArray() && identifier.compare(0, 15, "gl_LastFragData") == 0)
{ {
const TVariable *maxDrawBuffers = const TVariable *maxDrawBuffers =
static_cast<const TVariable *>(symbolTable.findBuiltIn("gl_MaxDrawBuffers", shaderVersion)); static_cast<const TVariable *>(symbolTable.findBuiltIn("gl_MaxDrawBuffers", mShaderVersion));
if (type.getArraySize() == maxDrawBuffers->getConstPointer()->getIConst()) if (type.getArraySize() == maxDrawBuffers->getConstPointer()->getIConst())
{ {
if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, shaderVersion)) if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, mShaderVersion))
{ {
needsReservedErrorCheck = extensionErrorCheck(line, builtInSymbol->getExtension()); needsReservedErrorCheck = extensionErrorCheck(line, builtInSymbol->getExtension());
} }
...@@ -1006,7 +1006,7 @@ void TParseContext::handleExtensionDirective(const TSourceLoc& loc, const char* ...@@ -1006,7 +1006,7 @@ void TParseContext::handleExtensionDirective(const TSourceLoc& loc, const char*
pp::SourceLocation srcLoc; pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
directiveHandler.handleExtension(srcLoc, extName, behavior); mDirectiveHandler.handleExtension(srcLoc, extName, behavior);
} }
void TParseContext::handlePragmaDirective(const TSourceLoc& loc, const char* name, const char* value, bool stdgl) void TParseContext::handlePragmaDirective(const TSourceLoc& loc, const char* name, const char* value, bool stdgl)
...@@ -1014,7 +1014,7 @@ void TParseContext::handlePragmaDirective(const TSourceLoc& loc, const char* nam ...@@ -1014,7 +1014,7 @@ void TParseContext::handlePragmaDirective(const TSourceLoc& loc, const char* nam
pp::SourceLocation srcLoc; pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
directiveHandler.handlePragma(srcLoc, name, value, stdgl); mDirectiveHandler.handlePragma(srcLoc, name, value, stdgl);
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
...@@ -1043,7 +1043,7 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location, ...@@ -1043,7 +1043,7 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
{ {
variable = static_cast<const TVariable*>(symbol); variable = static_cast<const TVariable*>(symbol);
if (symbolTable.findBuiltIn(variable->getName(), shaderVersion) && if (symbolTable.findBuiltIn(variable->getName(), mShaderVersion) &&
!variable->getExtension().empty() && !variable->getExtension().empty() &&
extensionErrorCheck(location, variable->getExtension())) extensionErrorCheck(location, variable->getExtension()))
{ {
...@@ -1224,7 +1224,7 @@ TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, bool inva ...@@ -1224,7 +1224,7 @@ TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, bool inva
returnType.clearArrayness(); returnType.clearArrayness();
} }
if (shaderVersion < 300) if (mShaderVersion < 300)
{ {
if (qualifier == EvqAttribute && (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt)) if (qualifier == EvqAttribute && (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
{ {
...@@ -1645,7 +1645,7 @@ void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier) ...@@ -1645,7 +1645,7 @@ void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier)
const TLayoutQualifier layoutQualifier = typeQualifier.layoutQualifier; const TLayoutQualifier layoutQualifier = typeQualifier.layoutQualifier;
ASSERT(!layoutQualifier.isEmpty()); ASSERT(!layoutQualifier.isEmpty());
if (shaderVersion < 300) if (mShaderVersion < 300)
{ {
error(typeQualifier.line, "layout qualifiers supported in GLSL ES 3.00 only", "layout"); error(typeQualifier.line, "layout qualifiers supported in GLSL ES 3.00 only", "layout");
recover(); recover();
...@@ -1660,12 +1660,12 @@ void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier) ...@@ -1660,12 +1660,12 @@ void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier)
if (layoutQualifier.matrixPacking != EmpUnspecified) if (layoutQualifier.matrixPacking != EmpUnspecified)
{ {
defaultMatrixPacking = layoutQualifier.matrixPacking; mDefaultMatrixPacking = layoutQualifier.matrixPacking;
} }
if (layoutQualifier.blockStorage != EbsUnspecified) if (layoutQualifier.blockStorage != EbsUnspecified)
{ {
defaultBlockStorage = layoutQualifier.blockStorage; mDefaultBlockStorage = layoutQualifier.blockStorage;
} }
} }
...@@ -2016,12 +2016,12 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif ...@@ -2016,12 +2016,12 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
if (blockLayoutQualifier.matrixPacking == EmpUnspecified) if (blockLayoutQualifier.matrixPacking == EmpUnspecified)
{ {
blockLayoutQualifier.matrixPacking = defaultMatrixPacking; blockLayoutQualifier.matrixPacking = mDefaultMatrixPacking;
} }
if (blockLayoutQualifier.blockStorage == EbsUnspecified) if (blockLayoutQualifier.blockStorage == EbsUnspecified)
{ {
blockLayoutQualifier.blockStorage = defaultBlockStorage; blockLayoutQualifier.blockStorage = mDefaultBlockStorage;
} }
TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName); TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName);
...@@ -2135,12 +2135,12 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif ...@@ -2135,12 +2135,12 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
bool TParseContext::enterStructDeclaration(const TSourceLoc& line, const TString& identifier) bool TParseContext::enterStructDeclaration(const TSourceLoc& line, const TString& identifier)
{ {
++structNestingLevel; ++mStructNestingLevel;
// Embedded structure definitions are not supported per GLSL ES spec. // Embedded structure definitions are not supported per GLSL ES spec.
// They aren't allowed in GLSL either, but we need to detect this here // They aren't allowed in GLSL either, but we need to detect this here
// so we don't rely on the GLSL compiler to catch it. // so we don't rely on the GLSL compiler to catch it.
if (structNestingLevel > 1) { if (mStructNestingLevel > 1) {
error(line, "", "Embedded struct definitions are not allowed"); error(line, "", "Embedded struct definitions are not allowed");
return true; return true;
} }
...@@ -2150,7 +2150,7 @@ bool TParseContext::enterStructDeclaration(const TSourceLoc& line, const TString ...@@ -2150,7 +2150,7 @@ bool TParseContext::enterStructDeclaration(const TSourceLoc& line, const TString
void TParseContext::exitStructDeclaration() void TParseContext::exitStructDeclaration()
{ {
--structNestingLevel; --mStructNestingLevel;
} }
namespace { namespace {
...@@ -2161,7 +2161,7 @@ const int kWebGLMaxStructNesting = 4; ...@@ -2161,7 +2161,7 @@ const int kWebGLMaxStructNesting = 4;
bool TParseContext::structNestingErrorCheck(const TSourceLoc& line, const TField& field) bool TParseContext::structNestingErrorCheck(const TSourceLoc& line, const TField& field)
{ {
if (!IsWebGLBasedSpec(shaderSpec)) { if (!IsWebGLBasedSpec(mShaderSpec)) {
return false; return false;
} }
...@@ -2517,7 +2517,7 @@ TIntermTyped* TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre ...@@ -2517,7 +2517,7 @@ TIntermTyped* TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre
} }
else else
{ {
if (shaderVersion < 300) if (mShaderVersion < 300)
{ {
error(dotLocation, " field selection requires structure, vector, or matrix on left hand side", fieldString.c_str()); error(dotLocation, " field selection requires structure, vector, or matrix on left hand side", fieldString.c_str());
} }
...@@ -2914,7 +2914,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter ...@@ -2914,7 +2914,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter
{ {
if (left->isArray() || right->isArray()) if (left->isArray() || right->isArray())
{ {
if (shaderVersion < 300) if (mShaderVersion < 300)
{ {
error(loc, "Invalid operation for arrays", GetOperatorString(op)); error(loc, "Invalid operation for arrays", GetOperatorString(op));
return false; return false;
...@@ -2994,7 +2994,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter ...@@ -2994,7 +2994,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter
case EOpEqual: case EOpEqual:
case EOpNotEqual: case EOpNotEqual:
// ESSL 1.00 sections 5.7, 5.8, 5.9 // ESSL 1.00 sections 5.7, 5.8, 5.9
if (shaderVersion < 300 && left->getType().isStructureContainingArrays()) if (mShaderVersion < 300 && left->getType().isStructureContainingArrays())
{ {
error(loc, "undefined operation for structs containing arrays", GetOperatorString(op)); error(loc, "undefined operation for structs containing arrays", GetOperatorString(op));
return false; return false;
...@@ -3002,7 +3002,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter ...@@ -3002,7 +3002,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter
// Samplers as l-values are disallowed also in ESSL 3.00, see section 4.1.7, // Samplers as l-values are disallowed also in ESSL 3.00, see section 4.1.7,
// we interpret the spec so that this extends to structs containing samplers, // we interpret the spec so that this extends to structs containing samplers,
// similarly to ESSL 1.00 spec. // similarly to ESSL 1.00 spec.
if ((shaderVersion < 300 || op == EOpAssign || op == EOpInitialize) && if ((mShaderVersion < 300 || op == EOpAssign || op == EOpInitialize) &&
left->getType().isStructureContainingSamplers()) left->getType().isStructureContainingSamplers())
{ {
error(loc, "undefined operation for structs containing samplers", GetOperatorString(op)); error(loc, "undefined operation for structs containing samplers", GetOperatorString(op));
...@@ -3153,7 +3153,7 @@ TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc) ...@@ -3153,7 +3153,7 @@ TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc)
} }
break; break;
case EOpReturn: case EOpReturn:
if (currentFunctionType->getBasicType() != EbtVoid) if (mCurrentFunctionType->getBasicType() != EbtVoid)
{ {
error(loc, "non-void function must return a value", "return"); error(loc, "non-void function must return a value", "return");
recover(); recover();
...@@ -3170,12 +3170,12 @@ TIntermBranch *TParseContext::addBranch(TOperator op, TIntermTyped *returnValue, ...@@ -3170,12 +3170,12 @@ TIntermBranch *TParseContext::addBranch(TOperator op, TIntermTyped *returnValue,
{ {
ASSERT(op == EOpReturn); ASSERT(op == EOpReturn);
mFunctionReturnsValue = true; mFunctionReturnsValue = true;
if (currentFunctionType->getBasicType() == EbtVoid) if (mCurrentFunctionType->getBasicType() == EbtVoid)
{ {
error(loc, "void function cannot return a value", "return"); error(loc, "void function cannot return a value", "return");
recover(); recover();
} }
else if (*currentFunctionType != returnValue->getType()) else if (*mCurrentFunctionType != returnValue->getType())
{ {
error(loc, "function return is not matching type:", "return"); error(loc, "function return is not matching type:", "return");
recover(); recover();
...@@ -3259,7 +3259,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN ...@@ -3259,7 +3259,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
// //
const TFunction* fnCandidate; const TFunction* fnCandidate;
bool builtIn; bool builtIn;
fnCandidate = findFunction(loc, fnCall, shaderVersion, &builtIn); fnCandidate = findFunction(loc, fnCall, mShaderVersion, &builtIn);
if (fnCandidate) if (fnCandidate)
{ {
// //
......
...@@ -25,8 +25,9 @@ struct TMatrixFields ...@@ -25,8 +25,9 @@ struct TMatrixFields
// The following are extra variables needed during parsing, grouped together so // The following are extra variables needed during parsing, grouped together so
// they can be passed to the parser without needing a global. // they can be passed to the parser without needing a global.
// //
struct TParseContext : angle::NonCopyable class TParseContext : angle::NonCopyable
{ {
public:
TParseContext(TSymbolTable &symt, TParseContext(TSymbolTable &symt,
TExtensionBehavior &ext, TExtensionBehavior &ext,
TIntermediate &interm, TIntermediate &interm,
...@@ -38,58 +39,73 @@ struct TParseContext : angle::NonCopyable ...@@ -38,58 +39,73 @@ struct TParseContext : angle::NonCopyable
bool debugShaderPrecisionSupported) bool debugShaderPrecisionSupported)
: intermediate(interm), : intermediate(interm),
symbolTable(symt), symbolTable(symt),
shaderType(type), mShaderType(type),
shaderSpec(spec), mShaderSpec(spec),
compileOptions(options), mCompileOptions(options),
treeRoot(nullptr), mTreeRoot(nullptr),
mLoopNestingLevel(0), mLoopNestingLevel(0),
structNestingLevel(0), mStructNestingLevel(0),
mSwitchNestingLevel(0), mSwitchNestingLevel(0),
currentFunctionType(nullptr), mCurrentFunctionType(nullptr),
mFunctionReturnsValue(false), mFunctionReturnsValue(false),
checksPrecisionErrors(checksPrecErrors), mChecksPrecisionErrors(checksPrecErrors),
fragmentPrecisionHigh(false), mFragmentPrecisionHigh(false),
defaultMatrixPacking(EmpColumnMajor), mDefaultMatrixPacking(EmpColumnMajor),
defaultBlockStorage(EbsShared), mDefaultBlockStorage(EbsShared),
diagnostics(is), mDiagnostics(is),
shaderVersion(100), mShaderVersion(100),
directiveHandler(ext, diagnostics, shaderVersion, debugShaderPrecisionSupported), mDirectiveHandler(ext, mDiagnostics, mShaderVersion, debugShaderPrecisionSupported),
preprocessor(&diagnostics, &directiveHandler), mPreprocessor(&mDiagnostics, &mDirectiveHandler),
scanner(nullptr), mScanner(nullptr),
mDeferredSingleDeclarationErrorCheck(false) mDeferredSingleDeclarationErrorCheck(false)
{ {
} }
TIntermediate &intermediate; // to hold and build a parse tree const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
sh::GLenum shaderType; // vertex or fragment language (future: pack or unpack) void *getScanner() const { return mScanner; }
ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. void setScanner(void *scanner) { mScanner = scanner; }
int shaderVersion; int getShaderVersion() const { return mShaderVersion; }
int compileOptions; sh::GLenum getShaderType() const { return mShaderType; }
TIntermNode *treeRoot; // root of parse tree being created ShShaderSpec getShaderSpec() const { return mShaderSpec; }
int mLoopNestingLevel; // 0 if outside all loops int numErrors() const { return mDiagnostics.numErrors(); }
int structNestingLevel; // incremented while parsing a struct declaration TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
int mSwitchNestingLevel; // 0 if outside all switch statements
const TType *currentFunctionType; // the return type of the function that's currently being parsed
bool mFunctionReturnsValue; // true if a non-void function has a return
bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
bool fragmentPrecisionHigh; // true if highp precision is supported in the fragment language.
TLayoutMatrixPacking defaultMatrixPacking;
TLayoutBlockStorage defaultBlockStorage;
TString HashErrMsg;
TDiagnostics diagnostics;
TDirectiveHandler directiveHandler;
pp::Preprocessor preprocessor;
void *scanner;
int getShaderVersion() const { return shaderVersion; }
int numErrors() const { return diagnostics.numErrors(); }
TInfoSink &infoSink() { return diagnostics.infoSink(); }
void error(const TSourceLoc &loc, const char *reason, const char *token, void error(const TSourceLoc &loc, const char *reason, const char *token,
const char *extraInfo=""); const char *extraInfo="");
void warning(const TSourceLoc &loc, const char *reason, const char *token, void warning(const TSourceLoc &loc, const char *reason, const char *token,
const char *extraInfo=""); const char *extraInfo="");
void recover(); void recover();
TIntermNode *getTreeRoot() const { return mTreeRoot; }
void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
bool getFragmentPrecisionHigh() const { return mFragmentPrecisionHigh; }
void setFragmentPrecisionHigh(bool fragmentPrecisionHigh)
{
mFragmentPrecisionHigh = fragmentPrecisionHigh;
}
bool getFunctionReturnsValue() const { return mFunctionReturnsValue; }
void setFunctionReturnsValue(bool functionReturnsValue)
{
mFunctionReturnsValue = functionReturnsValue;
}
void setLoopNestingLevel(int loopNestintLevel)
{
mLoopNestingLevel = loopNestintLevel;
}
const TType *getCurrentFunctionType() const { return mCurrentFunctionType; }
void setCurrentFunctionType(const TType *currentFunctionType)
{
mCurrentFunctionType = currentFunctionType;
}
void incrLoopNestingLevel() { ++mLoopNestingLevel; }
void decrLoopNestingLevel() { --mLoopNestingLevel; }
void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
// This method is guaranteed to succeed, even if no variable with 'name' exists. // This method is guaranteed to succeed, even if no variable with 'name' exists.
const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol); const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
...@@ -123,8 +139,8 @@ struct TParseContext : angle::NonCopyable ...@@ -123,8 +139,8 @@ struct TParseContext : angle::NonCopyable
bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *); bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *);
void es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation); void es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation);
const TPragma &pragma() const { return directiveHandler.pragma(); } const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
const TExtensionBehavior &extensionBehavior() const { return directiveHandler.extensionBehavior(); } const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
bool supportsExtension(const char *extension); bool supportsExtension(const char *extension);
bool isExtensionEnabled(const char *extension) const; bool isExtensionEnabled(const char *extension) const;
void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior); void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
...@@ -281,6 +297,10 @@ struct TParseContext : angle::NonCopyable ...@@ -281,6 +297,10 @@ struct TParseContext : angle::NonCopyable
TIntermTyped *addTernarySelection( TIntermTyped *addTernarySelection(
TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line); TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line);
// TODO(jmadill): make these private
TIntermediate &intermediate; // to hold and build a parse tree
TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
private: private:
bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable); bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
...@@ -301,6 +321,26 @@ struct TParseContext : angle::NonCopyable ...@@ -301,6 +321,26 @@ struct TParseContext : angle::NonCopyable
// Set to true when the last/current declarator list was started with an empty declaration. // Set to true when the last/current declarator list was started with an empty declaration.
bool mDeferredSingleDeclarationErrorCheck; bool mDeferredSingleDeclarationErrorCheck;
sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
int mShaderVersion;
int mCompileOptions;
TIntermNode *mTreeRoot; // root of parse tree being created
int mLoopNestingLevel; // 0 if outside all loops
int mStructNestingLevel; // incremented while parsing a struct declaration
int mSwitchNestingLevel; // 0 if outside all switch statements
const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed
bool mFunctionReturnsValue; // true if a non-void function has a return
bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
bool mFragmentPrecisionHigh; // true if highp precision is supported in the fragment language.
TLayoutMatrixPacking mDefaultMatrixPacking;
TLayoutBlockStorage mDefaultBlockStorage;
TString mHashErrMsg;
TDiagnostics mDiagnostics;
TDirectiveHandler mDirectiveHandler;
pp::Preprocessor mPreprocessor;
void *mScanner;
}; };
int PaParseStrings( int PaParseStrings(
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_ #define COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
class TIntermTyped; class TIntermTyped;
struct TParseContext; class TParseContext;
// Returns true if the initializer is valid. // Returns true if the initializer is valid.
bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning); bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning);
......
...@@ -389,7 +389,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate *node) ...@@ -389,7 +389,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate *node)
bool valid = true; bool valid = true;
TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable; TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable;
TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->shaderVersion); TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->getShaderVersion());
ASSERT(symbol && symbol->isFunction()); ASSERT(symbol && symbol->isFunction());
TFunction *function = static_cast<TFunction *>(symbol); TFunction *function = static_cast<TFunction *>(symbol);
for (ParamIndex::const_iterator i = pIndex.begin(); for (ParamIndex::const_iterator i = pIndex.begin();
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
struct TParseContext; class TParseContext;
class ValidateSwitch : public TIntermTraverser class ValidateSwitch : public TIntermTraverser
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_TRANSLATOR_GLSLANG_H_ #ifndef COMPILER_TRANSLATOR_GLSLANG_H_
#define COMPILER_TRANSLATOR_GLSLANG_H_ #define COMPILER_TRANSLATOR_GLSLANG_H_
struct TParseContext; class TParseContext;
extern int glslang_initialize(TParseContext* context); extern int glslang_initialize(TParseContext* context);
extern int glslang_finalize(TParseContext* context); extern int glslang_finalize(TParseContext* context);
......
...@@ -246,7 +246,7 @@ O [0-7] ...@@ -246,7 +246,7 @@ O [0-7]
"sampler2DMSArray" | "sampler2DMSArray" |
"isampler2DMSArray" | "isampler2DMSArray" |
"usampler2DMSArray" { "usampler2DMSArray" {
if (context->shaderVersion < 300) { if (context->getShaderVersion() < 300) {
yylval->lex.string = NewPoolTString(yytext); yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner); return check_type(yyscanner);
} }
...@@ -255,7 +255,7 @@ O [0-7] ...@@ -255,7 +255,7 @@ O [0-7]
/* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */ /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
"packed" { "packed" {
if (context->shaderVersion >= 300) if (context->getShaderVersion() >= 300)
{ {
yylval->lex.string = NewPoolTString(yytext); yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner); return check_type(yyscanner);
...@@ -399,7 +399,7 @@ O [0-7] ...@@ -399,7 +399,7 @@ O [0-7]
yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
pp::Token token; pp::Token token;
yyget_extra(yyscanner)->preprocessor.lex(&token); yyget_extra(yyscanner)->getPreprocessor().lex(&token);
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if (len < max_size) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
...@@ -417,7 +417,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -417,7 +417,7 @@ int check_type(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
int token = IDENTIFIER; int token = IDENTIFIER;
TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion); TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->getShaderVersion());
if (symbol && symbol->isVariable()) { if (symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol); TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) { if (variable->isUserType()) {
...@@ -438,9 +438,9 @@ int reserved_word(yyscan_t yyscanner) { ...@@ -438,9 +438,9 @@ int reserved_word(yyscan_t yyscanner) {
int ES2_reserved_ES3_keyword(TParseContext *context, int token) int ES2_reserved_ES3_keyword(TParseContext *context, int token)
{ {
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
return reserved_word(yyscanner); return reserved_word(yyscanner);
} }
...@@ -450,9 +450,9 @@ int ES2_reserved_ES3_keyword(TParseContext *context, int token) ...@@ -450,9 +450,9 @@ int ES2_reserved_ES3_keyword(TParseContext *context, int token)
int ES2_keyword_ES3_reserved(TParseContext *context, int token) int ES2_keyword_ES3_reserved(TParseContext *context, int token)
{ {
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
if (context->shaderVersion >= 300) if (context->getShaderVersion() >= 300)
{ {
return reserved_word(yyscanner); return reserved_word(yyscanner);
} }
...@@ -462,11 +462,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token) ...@@ -462,11 +462,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token)
int ES2_ident_ES3_keyword(TParseContext *context, int token) int ES2_ident_ES3_keyword(TParseContext *context, int token)
{ {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
// not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
yylval->lex.string = NewPoolTString(yytext); yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner); return check_type(yyscanner);
...@@ -477,10 +477,10 @@ int ES2_ident_ES3_keyword(TParseContext *context, int token) ...@@ -477,10 +477,10 @@ int ES2_ident_ES3_keyword(TParseContext *context, int token)
int uint_constant(TParseContext *context) int uint_constant(TParseContext *context)
{ {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover(); context->recover();
...@@ -495,9 +495,9 @@ int uint_constant(TParseContext *context) ...@@ -495,9 +495,9 @@ int uint_constant(TParseContext *context)
int floatsuffix_check(TParseContext* context) int floatsuffix_check(TParseContext* context)
{ {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
context->recover(); context->recover();
...@@ -536,15 +536,15 @@ int glslang_initialize(TParseContext* context) { ...@@ -536,15 +536,15 @@ int glslang_initialize(TParseContext* context) {
if (yylex_init_extra(context, &scanner)) if (yylex_init_extra(context, &scanner))
return 1; return 1;
context->scanner = scanner; context->setScanner(scanner);
return 0; return 0;
} }
int glslang_finalize(TParseContext* context) { int glslang_finalize(TParseContext* context) {
yyscan_t scanner = context->scanner; yyscan_t scanner = context->getScanner();
if (scanner == NULL) return 0; if (scanner == NULL) return 0;
context->scanner = NULL; context->setScanner(NULL);
yylex_destroy(scanner); yylex_destroy(scanner);
return 0; return 0;
...@@ -552,24 +552,26 @@ int glslang_finalize(TParseContext* context) { ...@@ -552,24 +552,26 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[], int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
yyrestart(NULL, context->scanner); yyrestart(NULL, context->getScanner());
yyset_column(0, context->scanner); yyset_column(0, context->getScanner());
yyset_lineno(1, context->scanner); yyset_lineno(1, context->getScanner());
// Initialize preprocessor. // Initialize preprocessor.
if (!context->preprocessor.init(count, string, length)) pp::Preprocessor *preprocessor = &context->getPreprocessor();
if (!preprocessor->init(count, string, length))
return 1; return 1;
// Define extension macros. // Define extension macros.
const TExtensionBehavior& extBehavior = context->extensionBehavior(); const TExtensionBehavior& extBehavior = context->extensionBehavior();
for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
iter != extBehavior.end(); ++iter) { iter != extBehavior.end(); ++iter) {
context->preprocessor.predefineMacro(iter->first.c_str(), 1); preprocessor->predefineMacro(iter->first.c_str(), 1);
} }
if (context->fragmentPrecisionHigh) if (context->getFragmentPrecisionHigh())
context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1); preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
context->preprocessor.setMaxTokenSize(GetGlobalMaxTokenSize(context->shaderSpec)); preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
return 0; return 0;
} }
......
...@@ -110,28 +110,28 @@ extern void yyerror(YYLTYPE* yylloc, TParseContext* context, void *scanner, cons ...@@ -110,28 +110,28 @@ extern void yyerror(YYLTYPE* yylloc, TParseContext* context, void *scanner, cons
} while (0) } while (0)
#define VERTEX_ONLY(S, L) { \ #define VERTEX_ONLY(S, L) { \
if (context->shaderType != GL_VERTEX_SHADER) { \ if (context->getShaderType() != GL_VERTEX_SHADER) { \
context->error(L, " supported in vertex shaders only ", S); \ context->error(L, " supported in vertex shaders only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#define FRAG_ONLY(S, L) { \ #define FRAG_ONLY(S, L) { \
if (context->shaderType != GL_FRAGMENT_SHADER) { \ if (context->getShaderType() != GL_FRAGMENT_SHADER) { \
context->error(L, " supported in fragment shaders only ", S); \ context->error(L, " supported in fragment shaders only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#define ES2_ONLY(S, L) { \ #define ES2_ONLY(S, L) { \
if (context->shaderVersion != 100) { \ if (context->getShaderVersion() != 100) { \
context->error(L, " supported in GLSL ES 1.00 only ", S); \ context->error(L, " supported in GLSL ES 1.00 only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#define ES3_ONLY(TOKEN, LINE, REASON) { \ #define ES3_ONLY(TOKEN, LINE, REASON) { \
if (context->shaderVersion != 300) { \ if (context->getShaderVersion() != 300) { \
context->error(LINE, REASON " supported in GLSL ES 3.00 only ", TOKEN); \ context->error(LINE, REASON " supported in GLSL ES 3.00 only ", TOKEN); \
context->recover(); \ context->recover(); \
} \ } \
...@@ -633,7 +633,7 @@ declaration ...@@ -633,7 +633,7 @@ declaration
$$ = aggNode; $$ = aggNode;
} }
| PRECISION precision_qualifier type_specifier_no_prec SEMICOLON { | PRECISION precision_qualifier type_specifier_no_prec SEMICOLON {
if (($2 == EbpHigh) && (context->shaderType == GL_FRAGMENT_SHADER) && !context->fragmentPrecisionHigh) { if (($2 == EbpHigh) && (context->getShaderType() == GL_FRAGMENT_SHADER) && !context->getFragmentPrecisionHigh()) {
context->error(@1, "precision is not supported in fragment shader", "highp"); context->error(@1, "precision is not supported in fragment shader", "highp");
context->recover(); context->recover();
} }
...@@ -671,7 +671,7 @@ function_prototype ...@@ -671,7 +671,7 @@ function_prototype
// //
// Redeclarations are allowed. But, return types and parameter qualifiers must match. // Redeclarations are allowed. But, return types and parameter qualifiers must match.
// //
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName(), context->shaderVersion)); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName(), context->getShaderVersion()));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != $1->getReturnType()) { if (prevDec->getReturnType() != $1->getReturnType()) {
context->error(@2, "overloaded functions must have the same return type", $1->getReturnType().getBasicString()); context->error(@2, "overloaded functions must have the same return type", $1->getReturnType().getBasicString());
...@@ -688,7 +688,7 @@ function_prototype ...@@ -688,7 +688,7 @@ function_prototype
// //
// Check for previously declared variables using the same name. // Check for previously declared variables using the same name.
// //
TSymbol *prevSym = context->symbolTable.find($1->getName(), context->shaderVersion); TSymbol *prevSym = context->symbolTable.find($1->getName(), context->getShaderVersion());
if (prevSym) if (prevSym)
{ {
if (!prevSym->isFunction()) if (!prevSym->isFunction())
...@@ -934,7 +934,7 @@ fully_specified_type ...@@ -934,7 +934,7 @@ fully_specified_type
if ($1.array) { if ($1.array) {
ES3_ONLY("[]", @1, "first-class-array"); ES3_ONLY("[]", @1, "first-class-array");
if (context->shaderVersion != 300) { if (context->getShaderVersion() != 300) {
$1.clearArrayness(); $1.clearArrayness();
} }
} }
...@@ -971,7 +971,7 @@ type_qualifier ...@@ -971,7 +971,7 @@ type_qualifier
ES2_ONLY("varying", @1); ES2_ONLY("varying", @1);
if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "varying")) if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "varying"))
context->recover(); context->recover();
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, @1); $$.setBasic(EbtVoid, EvqVaryingOut, @1);
else else
$$.setBasic(EbtVoid, EvqVaryingIn, @1); $$.setBasic(EbtVoid, EvqVaryingIn, @1);
...@@ -980,7 +980,7 @@ type_qualifier ...@@ -980,7 +980,7 @@ type_qualifier
ES2_ONLY("varying", @1); ES2_ONLY("varying", @1);
if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "invariant varying")) if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "invariant varying"))
context->recover(); context->recover();
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, @1); $$.setBasic(EbtVoid, EvqVaryingOut, @1);
else else
$$.setBasic(EbtVoid, EvqVaryingIn, @1); $$.setBasic(EbtVoid, EvqVaryingIn, @1);
...@@ -1030,29 +1030,29 @@ storage_qualifier ...@@ -1030,29 +1030,29 @@ storage_qualifier
} }
| IN_QUAL { | IN_QUAL {
ES3_ONLY("in", @1, "storage qualifier"); ES3_ONLY("in", @1, "storage qualifier");
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn; $$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
} }
| OUT_QUAL { | OUT_QUAL {
ES3_ONLY("out", @1, "storage qualifier"); ES3_ONLY("out", @1, "storage qualifier");
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut; $$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
} }
| CENTROID IN_QUAL { | CENTROID IN_QUAL {
ES3_ONLY("centroid in", @1, "storage qualifier"); ES3_ONLY("centroid in", @1, "storage qualifier");
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
{ {
context->error(@1, "invalid storage qualifier", "it is an error to use 'centroid in' in the vertex shader"); context->error(@1, "invalid storage qualifier", "it is an error to use 'centroid in' in the vertex shader");
context->recover(); context->recover();
} }
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn; $$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn;
} }
| CENTROID OUT_QUAL { | CENTROID OUT_QUAL {
ES3_ONLY("centroid out", @1, "storage qualifier"); ES3_ONLY("centroid out", @1, "storage qualifier");
if (context->shaderType == GL_FRAGMENT_SHADER) if (context->getShaderType() == GL_FRAGMENT_SHADER)
{ {
context->error(@1, "invalid storage qualifier", "it is an error to use 'centroid out' in the fragment shader"); context->error(@1, "invalid storage qualifier", "it is an error to use 'centroid out' in the fragment shader");
context->recover(); context->recover();
} }
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut; $$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut;
} }
| UNIFORM { | UNIFORM {
if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "uniform")) if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "uniform"))
...@@ -1530,9 +1530,9 @@ selection_rest_statement ...@@ -1530,9 +1530,9 @@ selection_rest_statement
; ;
switch_statement switch_statement
: SWITCH LEFT_PAREN expression RIGHT_PAREN { ++context->mSwitchNestingLevel; } compound_statement { : SWITCH LEFT_PAREN expression RIGHT_PAREN { context->incrSwitchNestingLevel(); } compound_statement {
$$ = context->addSwitch($3, $6, @1); $$ = context->addSwitch($3, $6, @1);
--context->mSwitchNestingLevel; context->decrSwitchNestingLevel();
} }
; ;
...@@ -1567,22 +1567,22 @@ condition ...@@ -1567,22 +1567,22 @@ condition
; ;
iteration_statement iteration_statement
: WHILE LEFT_PAREN { context->symbolTable.push(); ++context->mLoopNestingLevel; } condition RIGHT_PAREN statement_no_new_scope { : WHILE LEFT_PAREN { context->symbolTable.push(); context->incrLoopNestingLevel(); } condition RIGHT_PAREN statement_no_new_scope {
context->symbolTable.pop(); context->symbolTable.pop();
$$ = context->intermediate.addLoop(ELoopWhile, 0, $4, 0, $6, @1); $$ = context->intermediate.addLoop(ELoopWhile, 0, $4, 0, $6, @1);
--context->mLoopNestingLevel; context->decrLoopNestingLevel();
} }
| DO { ++context->mLoopNestingLevel; } statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON { | DO { context->incrLoopNestingLevel(); } statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
if (context->boolErrorCheck(@8, $6)) if (context->boolErrorCheck(@8, $6))
context->recover(); context->recover();
$$ = context->intermediate.addLoop(ELoopDoWhile, 0, $6, 0, $3, @4); $$ = context->intermediate.addLoop(ELoopDoWhile, 0, $6, 0, $3, @4);
--context->mLoopNestingLevel; context->decrLoopNestingLevel();
} }
| FOR LEFT_PAREN { context->symbolTable.push(); ++context->mLoopNestingLevel; } for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope { | FOR LEFT_PAREN { context->symbolTable.push(); context->incrLoopNestingLevel(); } for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope {
context->symbolTable.pop(); context->symbolTable.pop();
$$ = context->intermediate.addLoop(ELoopFor, $4, reinterpret_cast<TIntermTyped*>($5.node1), reinterpret_cast<TIntermTyped*>($5.node2), $7, @1); $$ = context->intermediate.addLoop(ELoopFor, $4, reinterpret_cast<TIntermTyped*>($5.node1), reinterpret_cast<TIntermTyped*>($5.node2), $7, @1);
--context->mLoopNestingLevel; context->decrLoopNestingLevel();
} }
; ;
...@@ -1639,11 +1639,11 @@ jump_statement ...@@ -1639,11 +1639,11 @@ jump_statement
translation_unit translation_unit
: external_declaration { : external_declaration {
$$ = $1; $$ = $1;
context->treeRoot = $$; context->setTreeRoot($$);
} }
| translation_unit external_declaration { | translation_unit external_declaration {
$$ = context->intermediate.growAggregate($1, $2, @$); $$ = context->intermediate.growAggregate($1, $2, @$);
context->treeRoot = $$; context->setTreeRoot($$);
} }
; ;
...@@ -1660,7 +1660,7 @@ function_definition ...@@ -1660,7 +1660,7 @@ function_definition
: function_prototype { : function_prototype {
TFunction* function = $1.function; TFunction* function = $1.function;
const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion); const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->getShaderVersion());
if (builtIn) if (builtIn)
{ {
...@@ -1668,7 +1668,7 @@ function_definition ...@@ -1668,7 +1668,7 @@ function_definition
context->recover(); context->recover();
} }
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion)); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->getShaderVersion()));
// //
// Note: 'prevDec' could be 'function' if this is the first time we've seen function // 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 // as it would have just been put in the symbol table. Otherwise, we're looking up
...@@ -1706,8 +1706,8 @@ function_definition ...@@ -1706,8 +1706,8 @@ function_definition
// //
// Remember the return type for later checking for RETURN statements. // Remember the return type for later checking for RETURN statements.
// //
context->currentFunctionType = &(prevDec->getReturnType()); context->setCurrentFunctionType(&(prevDec->getReturnType()));
context->mFunctionReturnsValue = false; context->setFunctionReturnsValue(false);
// //
// Insert parameters into the symbol table. // Insert parameters into the symbol table.
...@@ -1746,12 +1746,12 @@ function_definition ...@@ -1746,12 +1746,12 @@ function_definition
} }
context->intermediate.setAggregateOperator(paramNodes, EOpParameters, @1); context->intermediate.setAggregateOperator(paramNodes, EOpParameters, @1);
$1.intermAggregate = paramNodes; $1.intermAggregate = paramNodes;
context->mLoopNestingLevel = 0; context->setLoopNestingLevel(0);
} }
compound_statement_no_new_scope { compound_statement_no_new_scope {
//?? Check that all paths return a value if return type != void ? //?? Check that all paths return a value if return type != void ?
// May be best done as post process phase on intermediate code // May be best done as post process phase on intermediate code
if (context->currentFunctionType->getBasicType() != EbtVoid && ! context->mFunctionReturnsValue) { if (context->getCurrentFunctionType()->getBasicType() != EbtVoid && !context->getFunctionReturnsValue()) {
context->error(@1, "function does not return a value:", "", $1.function->getName().c_str()); context->error(@1, "function does not return a value:", "", $1.function->getName().c_str());
context->recover(); context->recover();
} }
...@@ -1774,5 +1774,5 @@ function_definition ...@@ -1774,5 +1774,5 @@ function_definition
%% %%
int glslang_parse(TParseContext* context) { int glslang_parse(TParseContext* context) {
return yyparse(context, context->scanner); return yyparse(context, context->getScanner());
} }
...@@ -1759,7 +1759,7 @@ case 133: ...@@ -1759,7 +1759,7 @@ case 133:
case 134: case 134:
YY_RULE_SETUP YY_RULE_SETUP
{ {
if (context->shaderVersion < 300) { if (context->getShaderVersion() < 300) {
yylval->lex.string = NewPoolTString(yytext); yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner); return check_type(yyscanner);
} }
...@@ -1770,7 +1770,7 @@ YY_RULE_SETUP ...@@ -1770,7 +1770,7 @@ YY_RULE_SETUP
case 135: case 135:
YY_RULE_SETUP YY_RULE_SETUP
{ {
if (context->shaderVersion >= 300) if (context->getShaderVersion() >= 300)
{ {
yylval->lex.string = NewPoolTString(yytext); yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner); return check_type(yyscanner);
...@@ -3234,7 +3234,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) ...@@ -3234,7 +3234,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
pp::Token token; pp::Token token;
yyget_extra(yyscanner)->preprocessor.lex(&token); yyget_extra(yyscanner)->getPreprocessor().lex(&token);
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if (len < max_size) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
...@@ -3252,7 +3252,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -3252,7 +3252,7 @@ int check_type(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
int token = IDENTIFIER; int token = IDENTIFIER;
TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion); TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->getShaderVersion());
if (symbol && symbol->isVariable()) { if (symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol); TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) { if (variable->isUserType()) {
...@@ -3273,9 +3273,9 @@ int reserved_word(yyscan_t yyscanner) { ...@@ -3273,9 +3273,9 @@ int reserved_word(yyscan_t yyscanner) {
int ES2_reserved_ES3_keyword(TParseContext *context, int token) int ES2_reserved_ES3_keyword(TParseContext *context, int token)
{ {
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
return reserved_word(yyscanner); return reserved_word(yyscanner);
} }
...@@ -3285,9 +3285,9 @@ int ES2_reserved_ES3_keyword(TParseContext *context, int token) ...@@ -3285,9 +3285,9 @@ int ES2_reserved_ES3_keyword(TParseContext *context, int token)
int ES2_keyword_ES3_reserved(TParseContext *context, int token) int ES2_keyword_ES3_reserved(TParseContext *context, int token)
{ {
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
if (context->shaderVersion >= 300) if (context->getShaderVersion() >= 300)
{ {
return reserved_word(yyscanner); return reserved_word(yyscanner);
} }
...@@ -3297,11 +3297,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token) ...@@ -3297,11 +3297,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token)
int ES2_ident_ES3_keyword(TParseContext *context, int token) int ES2_ident_ES3_keyword(TParseContext *context, int token)
{ {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
// not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
yylval->lex.string = NewPoolTString(yytext); yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner); return check_type(yyscanner);
...@@ -3312,10 +3312,10 @@ int ES2_ident_ES3_keyword(TParseContext *context, int token) ...@@ -3312,10 +3312,10 @@ int ES2_ident_ES3_keyword(TParseContext *context, int token)
int uint_constant(TParseContext *context) int uint_constant(TParseContext *context)
{ {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
yyscan_t yyscanner = (yyscan_t) context->scanner; yyscan_t yyscanner = (yyscan_t) context->getScanner();
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover(); context->recover();
...@@ -3330,9 +3330,9 @@ int uint_constant(TParseContext *context) ...@@ -3330,9 +3330,9 @@ int uint_constant(TParseContext *context)
int floatsuffix_check(TParseContext* context) int floatsuffix_check(TParseContext* context)
{ {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
if (context->shaderVersion < 300) if (context->getShaderVersion() < 300)
{ {
context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
context->recover(); context->recover();
...@@ -3371,15 +3371,15 @@ int glslang_initialize(TParseContext* context) { ...@@ -3371,15 +3371,15 @@ int glslang_initialize(TParseContext* context) {
if (yylex_init_extra(context,&scanner)) if (yylex_init_extra(context,&scanner))
return 1; return 1;
context->scanner = scanner; context->setScanner(scanner);
return 0; return 0;
} }
int glslang_finalize(TParseContext* context) { int glslang_finalize(TParseContext* context) {
yyscan_t scanner = context->scanner; yyscan_t scanner = context->getScanner();
if (scanner == NULL) return 0; if (scanner == NULL) return 0;
context->scanner = NULL; context->setScanner(NULL);
yylex_destroy(scanner); yylex_destroy(scanner);
return 0; return 0;
...@@ -3387,24 +3387,26 @@ int glslang_finalize(TParseContext* context) { ...@@ -3387,24 +3387,26 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[], int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
yyrestart(NULL,context->scanner); yyrestart(NULL,context->getScanner());
yyset_column(0,context->scanner); yyset_column(0,context->getScanner());
yyset_lineno(1,context->scanner); yyset_lineno(1,context->getScanner());
// Initialize preprocessor. // Initialize preprocessor.
if (!context->preprocessor.init(count, string, length)) pp::Preprocessor *preprocessor = &context->getPreprocessor();
if (!preprocessor->init(count, string, length))
return 1; return 1;
// Define extension macros. // Define extension macros.
const TExtensionBehavior& extBehavior = context->extensionBehavior(); const TExtensionBehavior& extBehavior = context->extensionBehavior();
for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
iter != extBehavior.end(); ++iter) { iter != extBehavior.end(); ++iter) {
context->preprocessor.predefineMacro(iter->first.c_str(), 1); preprocessor->predefineMacro(iter->first.c_str(), 1);
} }
if (context->fragmentPrecisionHigh) if (context->getFragmentPrecisionHigh())
context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1); preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
context->preprocessor.setMaxTokenSize(GetGlobalMaxTokenSize(context->shaderSpec)); preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
return 0; return 0;
} }
......
...@@ -354,28 +354,28 @@ extern void yyerror(YYLTYPE* yylloc, TParseContext* context, void *scanner, cons ...@@ -354,28 +354,28 @@ extern void yyerror(YYLTYPE* yylloc, TParseContext* context, void *scanner, cons
} while (0) } while (0)
#define VERTEX_ONLY(S, L) { \ #define VERTEX_ONLY(S, L) { \
if (context->shaderType != GL_VERTEX_SHADER) { \ if (context->getShaderType() != GL_VERTEX_SHADER) { \
context->error(L, " supported in vertex shaders only ", S); \ context->error(L, " supported in vertex shaders only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#define FRAG_ONLY(S, L) { \ #define FRAG_ONLY(S, L) { \
if (context->shaderType != GL_FRAGMENT_SHADER) { \ if (context->getShaderType() != GL_FRAGMENT_SHADER) { \
context->error(L, " supported in fragment shaders only ", S); \ context->error(L, " supported in fragment shaders only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#define ES2_ONLY(S, L) { \ #define ES2_ONLY(S, L) { \
if (context->shaderVersion != 100) { \ if (context->getShaderVersion() != 100) { \
context->error(L, " supported in GLSL ES 1.00 only ", S); \ context->error(L, " supported in GLSL ES 1.00 only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#define ES3_ONLY(TOKEN, LINE, REASON) { \ #define ES3_ONLY(TOKEN, LINE, REASON) { \
if (context->shaderVersion != 300) { \ if (context->getShaderVersion() != 300) { \
context->error(LINE, REASON " supported in GLSL ES 3.00 only ", TOKEN); \ context->error(LINE, REASON " supported in GLSL ES 3.00 only ", TOKEN); \
context->recover(); \ context->recover(); \
} \ } \
...@@ -3110,7 +3110,7 @@ yyreduce: ...@@ -3110,7 +3110,7 @@ yyreduce:
case 90: case 90:
{ {
if (((yyvsp[-2].interm.precision) == EbpHigh) && (context->shaderType == GL_FRAGMENT_SHADER) && !context->fragmentPrecisionHigh) { if (((yyvsp[-2].interm.precision) == EbpHigh) && (context->getShaderType() == GL_FRAGMENT_SHADER) && !context->getFragmentPrecisionHigh()) {
context->error((yylsp[-3]), "precision is not supported in fragment shader", "highp"); context->error((yylsp[-3]), "precision is not supported in fragment shader", "highp");
context->recover(); context->recover();
} }
...@@ -3170,7 +3170,7 @@ yyreduce: ...@@ -3170,7 +3170,7 @@ yyreduce:
// //
// Redeclarations are allowed. But, return types and parameter qualifiers must match. // Redeclarations are allowed. But, return types and parameter qualifiers must match.
// //
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[-1].interm.function)->getMangledName(), context->shaderVersion)); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[-1].interm.function)->getMangledName(), context->getShaderVersion()));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != (yyvsp[-1].interm.function)->getReturnType()) { if (prevDec->getReturnType() != (yyvsp[-1].interm.function)->getReturnType()) {
context->error((yylsp[0]), "overloaded functions must have the same return type", (yyvsp[-1].interm.function)->getReturnType().getBasicString()); context->error((yylsp[0]), "overloaded functions must have the same return type", (yyvsp[-1].interm.function)->getReturnType().getBasicString());
...@@ -3187,7 +3187,7 @@ yyreduce: ...@@ -3187,7 +3187,7 @@ yyreduce:
// //
// Check for previously declared variables using the same name. // Check for previously declared variables using the same name.
// //
TSymbol *prevSym = context->symbolTable.find((yyvsp[-1].interm.function)->getName(), context->shaderVersion); TSymbol *prevSym = context->symbolTable.find((yyvsp[-1].interm.function)->getName(), context->getShaderVersion());
if (prevSym) if (prevSym)
{ {
if (!prevSym->isFunction()) if (!prevSym->isFunction())
...@@ -3540,7 +3540,7 @@ yyreduce: ...@@ -3540,7 +3540,7 @@ yyreduce:
if ((yyvsp[0].interm.type).array) { if ((yyvsp[0].interm.type).array) {
ES3_ONLY("[]", (yylsp[0]), "first-class-array"); ES3_ONLY("[]", (yylsp[0]), "first-class-array");
if (context->shaderVersion != 300) { if (context->getShaderVersion() != 300) {
(yyvsp[0].interm.type).clearArrayness(); (yyvsp[0].interm.type).clearArrayness();
} }
} }
...@@ -3598,7 +3598,7 @@ yyreduce: ...@@ -3598,7 +3598,7 @@ yyreduce:
ES2_ONLY("varying", (yylsp[0])); ES2_ONLY("varying", (yylsp[0]));
if (context->globalErrorCheck((yylsp[0]), context->symbolTable.atGlobalLevel(), "varying")) if (context->globalErrorCheck((yylsp[0]), context->symbolTable.atGlobalLevel(), "varying"))
context->recover(); context->recover();
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
(yyval.interm.type).setBasic(EbtVoid, EvqVaryingOut, (yylsp[0])); (yyval.interm.type).setBasic(EbtVoid, EvqVaryingOut, (yylsp[0]));
else else
(yyval.interm.type).setBasic(EbtVoid, EvqVaryingIn, (yylsp[0])); (yyval.interm.type).setBasic(EbtVoid, EvqVaryingIn, (yylsp[0]));
...@@ -3612,7 +3612,7 @@ yyreduce: ...@@ -3612,7 +3612,7 @@ yyreduce:
ES2_ONLY("varying", (yylsp[-1])); ES2_ONLY("varying", (yylsp[-1]));
if (context->globalErrorCheck((yylsp[-1]), context->symbolTable.atGlobalLevel(), "invariant varying")) if (context->globalErrorCheck((yylsp[-1]), context->symbolTable.atGlobalLevel(), "invariant varying"))
context->recover(); context->recover();
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
(yyval.interm.type).setBasic(EbtVoid, EvqVaryingOut, (yylsp[-1])); (yyval.interm.type).setBasic(EbtVoid, EvqVaryingOut, (yylsp[-1]));
else else
(yyval.interm.type).setBasic(EbtVoid, EvqVaryingIn, (yylsp[-1])); (yyval.interm.type).setBasic(EbtVoid, EvqVaryingIn, (yylsp[-1]));
...@@ -3704,7 +3704,7 @@ yyreduce: ...@@ -3704,7 +3704,7 @@ yyreduce:
{ {
ES3_ONLY("in", (yylsp[0]), "storage qualifier"); ES3_ONLY("in", (yylsp[0]), "storage qualifier");
(yyval.interm.type).qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn; (yyval.interm.type).qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
} }
break; break;
...@@ -3713,7 +3713,7 @@ yyreduce: ...@@ -3713,7 +3713,7 @@ yyreduce:
{ {
ES3_ONLY("out", (yylsp[0]), "storage qualifier"); ES3_ONLY("out", (yylsp[0]), "storage qualifier");
(yyval.interm.type).qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut; (yyval.interm.type).qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
} }
break; break;
...@@ -3722,12 +3722,12 @@ yyreduce: ...@@ -3722,12 +3722,12 @@ yyreduce:
{ {
ES3_ONLY("centroid in", (yylsp[-1]), "storage qualifier"); ES3_ONLY("centroid in", (yylsp[-1]), "storage qualifier");
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
{ {
context->error((yylsp[-1]), "invalid storage qualifier", "it is an error to use 'centroid in' in the vertex shader"); context->error((yylsp[-1]), "invalid storage qualifier", "it is an error to use 'centroid in' in the vertex shader");
context->recover(); context->recover();
} }
(yyval.interm.type).qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn; (yyval.interm.type).qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn;
} }
break; break;
...@@ -3736,12 +3736,12 @@ yyreduce: ...@@ -3736,12 +3736,12 @@ yyreduce:
{ {
ES3_ONLY("centroid out", (yylsp[-1]), "storage qualifier"); ES3_ONLY("centroid out", (yylsp[-1]), "storage qualifier");
if (context->shaderType == GL_FRAGMENT_SHADER) if (context->getShaderType() == GL_FRAGMENT_SHADER)
{ {
context->error((yylsp[-1]), "invalid storage qualifier", "it is an error to use 'centroid out' in the fragment shader"); context->error((yylsp[-1]), "invalid storage qualifier", "it is an error to use 'centroid out' in the fragment shader");
context->recover(); context->recover();
} }
(yyval.interm.type).qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut; (yyval.interm.type).qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut;
} }
break; break;
...@@ -4662,7 +4662,7 @@ yyreduce: ...@@ -4662,7 +4662,7 @@ yyreduce:
case 247: case 247:
{ ++context->mSwitchNestingLevel; } { context->incrSwitchNestingLevel(); }
break; break;
...@@ -4670,7 +4670,7 @@ yyreduce: ...@@ -4670,7 +4670,7 @@ yyreduce:
{ {
(yyval.interm.intermSwitch) = context->addSwitch((yyvsp[-3].interm.intermTypedNode), (yyvsp[0].interm.intermAggregate), (yylsp[-5])); (yyval.interm.intermSwitch) = context->addSwitch((yyvsp[-3].interm.intermTypedNode), (yyvsp[0].interm.intermAggregate), (yylsp[-5]));
--context->mSwitchNestingLevel; context->decrSwitchNestingLevel();
} }
break; break;
...@@ -4720,7 +4720,7 @@ yyreduce: ...@@ -4720,7 +4720,7 @@ yyreduce:
case 253: case 253:
{ context->symbolTable.push(); ++context->mLoopNestingLevel; } { context->symbolTable.push(); context->incrLoopNestingLevel(); }
break; break;
...@@ -4729,14 +4729,14 @@ yyreduce: ...@@ -4729,14 +4729,14 @@ yyreduce:
{ {
context->symbolTable.pop(); context->symbolTable.pop();
(yyval.interm.intermNode) = context->intermediate.addLoop(ELoopWhile, 0, (yyvsp[-2].interm.intermTypedNode), 0, (yyvsp[0].interm.intermNode), (yylsp[-5])); (yyval.interm.intermNode) = context->intermediate.addLoop(ELoopWhile, 0, (yyvsp[-2].interm.intermTypedNode), 0, (yyvsp[0].interm.intermNode), (yylsp[-5]));
--context->mLoopNestingLevel; context->decrLoopNestingLevel();
} }
break; break;
case 255: case 255:
{ ++context->mLoopNestingLevel; } { context->incrLoopNestingLevel(); }
break; break;
...@@ -4747,14 +4747,14 @@ yyreduce: ...@@ -4747,14 +4747,14 @@ yyreduce:
context->recover(); context->recover();
(yyval.interm.intermNode) = context->intermediate.addLoop(ELoopDoWhile, 0, (yyvsp[-2].interm.intermTypedNode), 0, (yyvsp[-5].interm.intermNode), (yylsp[-4])); (yyval.interm.intermNode) = context->intermediate.addLoop(ELoopDoWhile, 0, (yyvsp[-2].interm.intermTypedNode), 0, (yyvsp[-5].interm.intermNode), (yylsp[-4]));
--context->mLoopNestingLevel; context->decrLoopNestingLevel();
} }
break; break;
case 257: case 257:
{ context->symbolTable.push(); ++context->mLoopNestingLevel; } { context->symbolTable.push(); context->incrLoopNestingLevel(); }
break; break;
...@@ -4763,7 +4763,7 @@ yyreduce: ...@@ -4763,7 +4763,7 @@ yyreduce:
{ {
context->symbolTable.pop(); context->symbolTable.pop();
(yyval.interm.intermNode) = context->intermediate.addLoop(ELoopFor, (yyvsp[-3].interm.intermNode), reinterpret_cast<TIntermTyped*>((yyvsp[-2].interm.nodePair).node1), reinterpret_cast<TIntermTyped*>((yyvsp[-2].interm.nodePair).node2), (yyvsp[0].interm.intermNode), (yylsp[-6])); (yyval.interm.intermNode) = context->intermediate.addLoop(ELoopFor, (yyvsp[-3].interm.intermNode), reinterpret_cast<TIntermTyped*>((yyvsp[-2].interm.nodePair).node1), reinterpret_cast<TIntermTyped*>((yyvsp[-2].interm.nodePair).node2), (yyvsp[0].interm.intermNode), (yylsp[-6]));
--context->mLoopNestingLevel; context->decrLoopNestingLevel();
} }
break; break;
...@@ -4863,7 +4863,7 @@ yyreduce: ...@@ -4863,7 +4863,7 @@ yyreduce:
{ {
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
context->treeRoot = (yyval.interm.intermNode); context->setTreeRoot((yyval.interm.intermNode));
} }
break; break;
...@@ -4872,7 +4872,7 @@ yyreduce: ...@@ -4872,7 +4872,7 @@ yyreduce:
{ {
(yyval.interm.intermNode) = context->intermediate.growAggregate((yyvsp[-1].interm.intermNode), (yyvsp[0].interm.intermNode), (yyloc)); (yyval.interm.intermNode) = context->intermediate.growAggregate((yyvsp[-1].interm.intermNode), (yyvsp[0].interm.intermNode), (yyloc));
context->treeRoot = (yyval.interm.intermNode); context->setTreeRoot((yyval.interm.intermNode));
} }
break; break;
...@@ -4898,7 +4898,7 @@ yyreduce: ...@@ -4898,7 +4898,7 @@ yyreduce:
{ {
TFunction* function = (yyvsp[0].interm).function; TFunction* function = (yyvsp[0].interm).function;
const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion); const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->getShaderVersion());
if (builtIn) if (builtIn)
{ {
...@@ -4906,7 +4906,7 @@ yyreduce: ...@@ -4906,7 +4906,7 @@ yyreduce:
context->recover(); context->recover();
} }
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion)); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->getShaderVersion()));
// //
// Note: 'prevDec' could be 'function' if this is the first time we've seen function // 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 // as it would have just been put in the symbol table. Otherwise, we're looking up
...@@ -4944,8 +4944,8 @@ yyreduce: ...@@ -4944,8 +4944,8 @@ yyreduce:
// //
// Remember the return type for later checking for RETURN statements. // Remember the return type for later checking for RETURN statements.
// //
context->currentFunctionType = &(prevDec->getReturnType()); context->setCurrentFunctionType(&(prevDec->getReturnType()));
context->mFunctionReturnsValue = false; context->setFunctionReturnsValue(false);
// //
// Insert parameters into the symbol table. // Insert parameters into the symbol table.
...@@ -4984,7 +4984,7 @@ yyreduce: ...@@ -4984,7 +4984,7 @@ yyreduce:
} }
context->intermediate.setAggregateOperator(paramNodes, EOpParameters, (yylsp[0])); context->intermediate.setAggregateOperator(paramNodes, EOpParameters, (yylsp[0]));
(yyvsp[0].interm).intermAggregate = paramNodes; (yyvsp[0].interm).intermAggregate = paramNodes;
context->mLoopNestingLevel = 0; context->setLoopNestingLevel(0);
} }
break; break;
...@@ -4994,7 +4994,7 @@ yyreduce: ...@@ -4994,7 +4994,7 @@ yyreduce:
{ {
//?? Check that all paths return a value if return type != void ? //?? Check that all paths return a value if return type != void ?
// May be best done as post process phase on intermediate code // May be best done as post process phase on intermediate code
if (context->currentFunctionType->getBasicType() != EbtVoid && ! context->mFunctionReturnsValue) { if (context->getCurrentFunctionType()->getBasicType() != EbtVoid && !context->getFunctionReturnsValue()) {
context->error((yylsp[-2]), "function does not return a value:", "", (yyvsp[-2].interm).function->getName().c_str()); context->error((yylsp[-2]), "function does not return a value:", "", (yyvsp[-2].interm).function->getName().c_str());
context->recover(); context->recover();
} }
...@@ -5255,5 +5255,5 @@ yyreturn: ...@@ -5255,5 +5255,5 @@ yyreturn:
int glslang_parse(TParseContext* context) { int glslang_parse(TParseContext* context) {
return yyparse(context, context->scanner); return yyparse(context, context->getScanner());
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment