Commit 0a65584a by Alexis Hetu Committed by Alexis Hétu

Better encapsulation for TParseContext

Changed 15 public members of TParseContext so that they are now private and added the appropriate setters/getters, along with the required code changes in the parser. Change-Id: I0a3ea67540d165e9837a3fe8e64fda4843a3cf96 Reviewed-on: https://swiftshader-review.googlesource.com/3543Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent d2264145
...@@ -122,12 +122,12 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -122,12 +122,12 @@ bool TCompiler::compile(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], NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL); (parseContext.getTreeRoot() != NULL);
shaderVersion = parseContext.getShaderVersion(); shaderVersion = parseContext.getShaderVersion();
if (success) { if (success) {
TIntermNode* root = parseContext.treeRoot; TIntermNode* root = parseContext.getTreeRoot();
success = intermediate.postProcess(root); success = intermediate.postProcess(root);
if (success) if (success)
......
...@@ -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();
......
...@@ -154,7 +154,7 @@ namespace glsl ...@@ -154,7 +154,7 @@ namespace glsl
{ {
emitScope = scope; emitScope = scope;
currentScope = GLOBAL; currentScope = GLOBAL;
mContext.treeRoot->traverse(this); mContext.getTreeRoot()->traverse(this);
} }
void OutputASM::freeTemporary(Temporary *temporary) void OutputASM::freeTemporary(Temporary *temporary)
......
...@@ -182,8 +182,8 @@ void TParseContext::error(const TSourceLoc& loc, ...@@ -182,8 +182,8 @@ void TParseContext::error(const TSourceLoc& loc,
{ {
pp::SourceLocation srcLoc; pp::SourceLocation srcLoc;
DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line); DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line);
diagnostics.writeInfo(pp::Diagnostics::PP_ERROR, mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR,
srcLoc, reason, token, extraInfo); srcLoc, reason, token, extraInfo);
} }
...@@ -192,13 +192,13 @@ void TParseContext::warning(const TSourceLoc& loc, ...@@ -192,13 +192,13 @@ void TParseContext::warning(const TSourceLoc& loc,
const char* extraInfo) { const char* extraInfo) {
pp::SourceLocation srcLoc; pp::SourceLocation srcLoc;
DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line); DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line);
diagnostics.writeInfo(pp::Diagnostics::PP_WARNING, mDiagnostics.writeInfo(pp::Diagnostics::PP_WARNING,
srcLoc, reason, token, extraInfo); srcLoc, reason, token, extraInfo);
} }
void TParseContext::trace(const char* str) void TParseContext::trace(const char* str)
{ {
diagnostics.writeDebug(str); mDiagnostics.writeDebug(str);
} }
// //
...@@ -237,7 +237,7 @@ void TParseContext::binaryOpError(const TSourceLoc &line, const char* op, TStrin ...@@ -237,7 +237,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:
...@@ -847,7 +847,7 @@ bool TParseContext::arrayTypeErrorCheck(const TSourceLoc &line, TPublicType type ...@@ -847,7 +847,7 @@ bool TParseContext::arrayTypeErrorCheck(const TSourceLoc &line, TPublicType type
bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, const TSourceLoc &line) bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, const TSourceLoc &line)
{ {
bool builtIn = false; bool builtIn = false;
TSymbol* symbol = symbolTable.find(node->getSymbol(), shaderVersion, &builtIn); TSymbol* symbol = symbolTable.find(node->getSymbol(), mShaderVersion, &builtIn);
if (symbol == 0) { if (symbol == 0) {
error(line, " undeclared identifier", node->getSymbol().c_str()); error(line, " undeclared identifier", node->getSymbol().c_str());
return true; return true;
...@@ -860,7 +860,7 @@ bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, ...@@ -860,7 +860,7 @@ bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size,
// special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers // special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers
// its an error // its an error
if (node->getSymbol() == "gl_FragData") { if (node->getSymbol() == "gl_FragData") {
TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", shaderVersion, &builtIn); TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", mShaderVersion, &builtIn);
ASSERT(fragData); ASSERT(fragData);
int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst(); int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst();
...@@ -934,7 +934,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc &line, const TString& ide ...@@ -934,7 +934,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, error(line,
"structures containing arrays may not be declared constant since they cannot be initialized", "structures containing arrays may not be declared constant since they cannot be initialized",
...@@ -969,7 +969,7 @@ bool TParseContext::declareVariable(const TSourceLoc &line, const TString &ident ...@@ -969,7 +969,7 @@ 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())
{ {
error(line, "redeclaration of gl_LastFragData with size != gl_MaxDrawBuffers", identifier.c_str()); error(line, "redeclaration of gl_LastFragData with size != gl_MaxDrawBuffers", identifier.c_str());
...@@ -1066,14 +1066,14 @@ void TParseContext::handleExtensionDirective(const TSourceLoc &line, const char* ...@@ -1066,14 +1066,14 @@ void TParseContext::handleExtensionDirective(const TSourceLoc &line, const char*
{ {
pp::SourceLocation loc; pp::SourceLocation loc;
DecodeSourceLoc(line, &loc.file, &loc.line); DecodeSourceLoc(line, &loc.file, &loc.line);
directiveHandler.handleExtension(loc, extName, behavior); mDirectiveHandler.handleExtension(loc, extName, behavior);
} }
void TParseContext::handlePragmaDirective(const TSourceLoc &line, const char* name, const char* value) void TParseContext::handlePragmaDirective(const TSourceLoc &line, const char* name, const char* value)
{ {
pp::SourceLocation loc; pp::SourceLocation loc;
DecodeSourceLoc(line, &loc.file, &loc.line); DecodeSourceLoc(line, &loc.file, &loc.line);
directiveHandler.handlePragma(loc, name, value); mDirectiveHandler.handlePragma(loc, name, value);
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
...@@ -1102,7 +1102,7 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location, ...@@ -1102,7 +1102,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))
{ {
recover(); recover();
} }
...@@ -1149,9 +1149,9 @@ const TFunction* TParseContext::findFunction(const TSourceLoc &line, TFunction* ...@@ -1149,9 +1149,9 @@ const TFunction* TParseContext::findFunction(const TSourceLoc &line, TFunction*
{ {
// First find by unmangled name to check whether the function name has been // First find by unmangled name to check whether the function name has been
// hidden by a variable name or struct typename. // hidden by a variable name or struct typename.
const TSymbol* symbol = symbolTable.find(call->getName(), shaderVersion, builtIn); const TSymbol* symbol = symbolTable.find(call->getName(), mShaderVersion, builtIn);
if (symbol == 0) { if (symbol == 0) {
symbol = symbolTable.find(call->getMangledName(), shaderVersion, builtIn); symbol = symbolTable.find(call->getMangledName(), mShaderVersion, builtIn);
} }
if (symbol == 0) { if (symbol == 0) {
...@@ -1292,7 +1292,7 @@ TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, bool inva ...@@ -1292,7 +1292,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))
{ {
...@@ -1703,7 +1703,7 @@ TIntermAggregate *TParseContext::parseArrayInitDeclarator(const TPublicType &pub ...@@ -1703,7 +1703,7 @@ TIntermAggregate *TParseContext::parseArrayInitDeclarator(const TPublicType &pub
void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier) void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier)
{ {
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();
...@@ -1728,12 +1728,12 @@ void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier) ...@@ -1728,12 +1728,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;
} }
} }
...@@ -2080,12 +2080,12 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif ...@@ -2080,12 +2080,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 TSymbol(&blockName); TSymbol* blockNameSymbol = new TSymbol(&blockName);
...@@ -2535,7 +2535,7 @@ TIntermTyped *TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre ...@@ -2535,7 +2535,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", error(dotLocation, " field selection requires structure, vector, or matrix on left hand side",
fieldString.c_str()); fieldString.c_str());
...@@ -2785,12 +2785,12 @@ TPublicType TParseContext::addStructure(const TSourceLoc &structLine, const TSou ...@@ -2785,12 +2785,12 @@ TPublicType TParseContext::addStructure(const TSourceLoc &structLine, const TSou
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;
} }
...@@ -2800,7 +2800,7 @@ bool TParseContext::enterStructDeclaration(const TSourceLoc &line, const TString ...@@ -2800,7 +2800,7 @@ bool TParseContext::enterStructDeclaration(const TSourceLoc &line, const TString
void TParseContext::exitStructDeclaration() void TParseContext::exitStructDeclaration()
{ {
--structNestingLevel; --mStructNestingLevel;
} }
bool TParseContext::structNestingErrorCheck(const TSourceLoc &line, const TField &field) bool TParseContext::structNestingErrorCheck(const TSourceLoc &line, const TField &field)
...@@ -2897,7 +2897,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter ...@@ -2897,7 +2897,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;
...@@ -2977,7 +2977,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter ...@@ -2977,7 +2977,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;
...@@ -2985,7 +2985,7 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter ...@@ -2985,7 +2985,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));
...@@ -3041,7 +3041,7 @@ TIntermSwitch *TParseContext::addSwitch(TIntermTyped *init, TIntermAggregate *st ...@@ -3041,7 +3041,7 @@ TIntermSwitch *TParseContext::addSwitch(TIntermTyped *init, TIntermAggregate *st
TIntermCase *TParseContext::addCase(TIntermTyped *condition, const TSourceLoc &loc) TIntermCase *TParseContext::addCase(TIntermTyped *condition, const TSourceLoc &loc)
{ {
if(switchNestingLevel == 0) if(mSwitchNestingLevel == 0)
{ {
error(loc, "case labels need to be inside switch statements", "case"); error(loc, "case labels need to be inside switch statements", "case");
recover(); recover();
...@@ -3079,7 +3079,7 @@ TIntermCase *TParseContext::addCase(TIntermTyped *condition, const TSourceLoc &l ...@@ -3079,7 +3079,7 @@ TIntermCase *TParseContext::addCase(TIntermTyped *condition, const TSourceLoc &l
TIntermCase *TParseContext::addDefault(const TSourceLoc &loc) TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
{ {
if(switchNestingLevel == 0) if(mSwitchNestingLevel == 0)
{ {
error(loc, "default labels need to be inside switch statements", "default"); error(loc, "default labels need to be inside switch statements", "default");
recover(); recover();
...@@ -3205,21 +3205,21 @@ TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc) ...@@ -3205,21 +3205,21 @@ TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc)
switch(op) switch(op)
{ {
case EOpContinue: case EOpContinue:
if(loopNestingLevel <= 0) if(mLoopNestingLevel <= 0)
{ {
error(loc, "continue statement only allowed in loops", ""); error(loc, "continue statement only allowed in loops", "");
recover(); recover();
} }
break; break;
case EOpBreak: case EOpBreak:
if(loopNestingLevel <= 0 && switchNestingLevel <= 0) if(mLoopNestingLevel <= 0 && mSwitchNestingLevel <= 0)
{ {
error(loc, "break statement only allowed in loops and switch statements", ""); error(loc, "break statement only allowed in loops and switch statements", "");
recover(); recover();
} }
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();
...@@ -3235,13 +3235,13 @@ TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc) ...@@ -3235,13 +3235,13 @@ TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc)
TIntermBranch *TParseContext::addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc) TIntermBranch *TParseContext::addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc)
{ {
ASSERT(op == EOpReturn); ASSERT(op == EOpReturn);
functionReturnsValue = 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();
......
...@@ -24,68 +24,81 @@ struct TMatrixFields { ...@@ -24,68 +24,81 @@ 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 { class TParseContext {
public:
TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, GLenum type, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) : TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, GLenum type, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) :
intermediate(interm), intermediate(interm),
symbolTable(symt), symbolTable(symt),
shaderType(type),
compileOptions(options), compileOptions(options),
sourcePath(sourcePath), sourcePath(sourcePath),
treeRoot(0),
lexAfterType(false), lexAfterType(false),
loopNestingLevel(0),
switchNestingLevel(0),
structNestingLevel(0),
inTypeParen(false), inTypeParen(false),
currentFunctionType(NULL), AfterEOF(false),
functionReturnsValue(false), mDeferredSingleDeclarationErrorCheck(false),
checksPrecisionErrors(checksPrecErrors), mShaderType(type),
defaultMatrixPacking(EmpColumnMajor), mShaderVersion(100),
defaultBlockStorage(EbsShared), mTreeRoot(0),
diagnostics(is), mLoopNestingLevel(0),
shaderVersion(100), mSwitchNestingLevel(0),
directiveHandler(ext, diagnostics, shaderVersion), mStructNestingLevel(0),
preprocessor(&diagnostics, &directiveHandler), mCurrentFunctionType(NULL),
scanner(NULL), mFunctionReturnsValue(false),
mDeferredSingleDeclarationErrorCheck(false), mChecksPrecisionErrors(checksPrecErrors),
mDefaultMatrixPacking(EmpColumnMajor),
mDefaultBlockStorage(EbsShared),
mDiagnostics(is),
mDirectiveHandler(ext, mDiagnostics, mShaderVersion),
mPreprocessor(&mDiagnostics, &mDirectiveHandler),
mScanner(NULL),
mUsesFragData(false), mUsesFragData(false),
mUsesFragColor(false) { } mUsesFragColor(false) { }
TIntermediate& intermediate; // to hold and build a parse tree TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
GLenum shaderType; // vertex or fragment language (future: pack or unpack)
int shaderVersion;
int compileOptions; int compileOptions;
const char* sourcePath; // Path of source file or NULL. const char* sourcePath; // Path of source file or NULL.
TIntermNode* treeRoot; // root of parse tree being created
bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier
int loopNestingLevel; // 0 if outside all loops
int switchNestingLevel; // 0 if outside all switch statements
int structNestingLevel; // incremented while parsing a struct declaration
bool inTypeParen; // true if in parentheses, looking only for an identifier bool inTypeParen; // true if in parentheses, looking only for an identifier
const TType* currentFunctionType; // the return type of the function that's currently being parsed
bool functionReturnsValue; // 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.
TLayoutMatrixPacking defaultMatrixPacking;
TLayoutBlockStorage defaultBlockStorage;
TString HashErrMsg;
bool AfterEOF; bool AfterEOF;
TDiagnostics diagnostics;
TDirectiveHandler directiveHandler; const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
pp::Preprocessor preprocessor; pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
void* scanner; void *getScanner() const { return mScanner; }
void setScanner(void *scanner) { mScanner = scanner; }
int getShaderVersion() const { return shaderVersion; } int getShaderVersion() const { return mShaderVersion; }
int numErrors() const { return diagnostics.numErrors(); } GLenum getShaderType() const { return mShaderType; }
TInfoSink& infoSink() { return diagnostics.infoSink(); } int numErrors() const { return mDiagnostics.numErrors(); }
TInfoSink &infoSink() { return mDiagnostics.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 trace(const char* str); void trace(const char* str);
void recover(); void recover();
TIntermNode *getTreeRoot() const { return mTreeRoot; }
void incrSwitchNestingLevel() { ++switchNestingLevel; } void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
void decrSwitchNestingLevel() { --switchNestingLevel; }
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);
...@@ -121,11 +134,11 @@ struct TParseContext { ...@@ -121,11 +134,11 @@ struct TParseContext {
bool layoutLocationErrorCheck(const TSourceLoc& location, const TLayoutQualifier &layoutQualifier); bool layoutLocationErrorCheck(const TSourceLoc& location, const TLayoutQualifier &layoutQualifier);
bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *); bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *);
const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); } const TExtensionBehavior& extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
bool supportsExtension(const char* extension); bool supportsExtension(const char* extension);
void handleExtensionDirective(const TSourceLoc &line, const char* extName, const char* behavior); void handleExtensionDirective(const TSourceLoc &line, const char* extName, const char* behavior);
const TPragma& pragma() const { return directiveHandler.pragma(); } const TPragma& pragma() const { return mDirectiveHandler.pragma(); }
void handlePragmaDirective(const TSourceLoc &line, const char* name, const char* value); void handlePragmaDirective(const TSourceLoc &line, const char* name, const char* value);
bool containsSampler(TType& type); bool containsSampler(TType& type);
...@@ -221,8 +234,26 @@ private: ...@@ -221,8 +234,26 @@ private:
// Return true if the checks pass // Return true if the checks pass
bool binaryOpCommonCheck(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); bool binaryOpCommonCheck(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
bool mDeferredSingleDeclarationErrorCheck; // Set to true when the last/current declarator list was started with an empty declaration.
bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor bool mDeferredSingleDeclarationErrorCheck;
GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
int mShaderVersion;
TIntermNode *mTreeRoot; // root of parse tree being created
int mLoopNestingLevel; // 0 if outside all loops
int mSwitchNestingLevel; // 0 if outside all switch statements
int mStructNestingLevel; // incremented while parsing a struct declaration
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.
TLayoutMatrixPacking mDefaultMatrixPacking;
TLayoutBlockStorage mDefaultBlockStorage;
TDiagnostics mDiagnostics;
TDirectiveHandler mDirectiveHandler;
pp::Preprocessor mPreprocessor;
void *mScanner;
bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
bool mUsesFragColor; bool mUsesFragColor;
}; };
......
...@@ -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);
......
...@@ -440,7 +440,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node) ...@@ -440,7 +440,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();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "intermediate.h" #include "intermediate.h"
#include <set> #include <set>
struct TParseContext; class TParseContext;
class ValidateSwitch : public TIntermTraverser class ValidateSwitch : public TIntermTraverser
{ {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
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);
......
...@@ -241,7 +241,7 @@ O [0-7] ...@@ -241,7 +241,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);
} }
...@@ -250,7 +250,7 @@ O [0-7] ...@@ -250,7 +250,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);
...@@ -395,7 +395,7 @@ O [0-7] ...@@ -395,7 +395,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);
...@@ -412,7 +412,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -412,7 +412,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 (yyextra->lexAfterType == false && symbol && symbol->isVariable()) { if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol); TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) { if (variable->isUserType()) {
...@@ -434,9 +434,9 @@ int reserved_word(yyscan_t yyscanner) { ...@@ -434,9 +434,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);
} }
...@@ -446,9 +446,9 @@ int ES2_reserved_ES3_keyword(TParseContext *context, int token) ...@@ -446,9 +446,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);
} }
...@@ -458,11 +458,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token) ...@@ -458,11 +458,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token)
int ES2_identifier_ES3_keyword(TParseContext *context, int token) int ES2_identifier_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);
...@@ -473,10 +473,10 @@ int ES2_identifier_ES3_keyword(TParseContext *context, int token) ...@@ -473,10 +473,10 @@ int ES2_identifier_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();
...@@ -491,9 +491,9 @@ int uint_constant(TParseContext *context) ...@@ -491,9 +491,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();
...@@ -523,7 +523,7 @@ int float_constant(yyscan_t yyscanner) { ...@@ -523,7 +523,7 @@ int float_constant(yyscan_t yyscanner) {
} }
void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) { void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
if (context->AfterEOF) { if (context->AfterEOF) {
context->error(*lloc, reason, "unexpected EOF"); context->error(*lloc, reason, "unexpected EOF");
...@@ -538,15 +538,15 @@ int glslang_initialize(TParseContext* context) { ...@@ -538,15 +538,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;
...@@ -554,12 +554,12 @@ int glslang_finalize(TParseContext* context) { ...@@ -554,12 +554,12 @@ 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_lineno(EncodeSourceLoc(0, 1), context->scanner); yyset_lineno(EncodeSourceLoc(0, 1), context->getScanner());
context->AfterEOF = false; context->AfterEOF = false;
// Initialize preprocessor. // Initialize preprocessor.
if (!context->preprocessor.init(count, string, length)) if (!context->getPreprocessor().init(count, string, length))
return 1; return 1;
// Define extension macros. // Define extension macros.
...@@ -567,10 +567,10 @@ int glslang_scan(size_t count, const char* const string[], const int length[], ...@@ -567,10 +567,10 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
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); context->getPreprocessor().predefineMacro(iter->first.c_str(), 1);
} }
context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1); context->getPreprocessor().predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
return 0; return 0;
} }
......
...@@ -39,7 +39,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). ...@@ -39,7 +39,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
#define YYENABLE_NLS 0 #define YYENABLE_NLS 0
#define YYLEX_PARAM context->scanner #define YYLEX_PARAM context->getScanner()
%} %}
%expect 1 /* One shift reduce conflict because of if | else */ %expect 1 /* One shift reduce conflict because of if | else */
...@@ -94,36 +94,36 @@ extern void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason); ...@@ -94,36 +94,36 @@ extern void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason);
#define YYLLOC_DEFAULT(Current, Rhs, N) do { (Current) = YYRHSLOC(Rhs, N ? 1 : 0); } while (0) #define YYLLOC_DEFAULT(Current, Rhs, N) do { (Current) = YYRHSLOC(Rhs, N ? 1 : 0); } while (0)
#define FRAG_VERT_ONLY(S, L) { \ #define FRAG_VERT_ONLY(S, L) { \
if (context->shaderType != GL_FRAGMENT_SHADER && \ if (context->getShaderType() != GL_FRAGMENT_SHADER && \
context->shaderType != GL_VERTEX_SHADER) { \ context->getShaderType() != GL_VERTEX_SHADER) { \
context->error(L, " supported in vertex/fragment shaders only ", S); \ context->error(L, " supported in vertex/fragment shaders only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#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(S, L) { \ #define ES3_ONLY(S, L) { \
if (context->shaderVersion != 300) { \ if (context->getShaderVersion() != 300) { \
context->error(L, " supported in GLSL ES 3.00 only ", S); \ context->error(L, " supported in GLSL ES 3.00 only ", S); \
context->recover(); \ context->recover(); \
} \ } \
...@@ -782,7 +782,7 @@ function_prototype ...@@ -782,7 +782,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());
...@@ -1135,7 +1135,7 @@ type_qualifier ...@@ -1135,7 +1135,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);
...@@ -1144,7 +1144,7 @@ type_qualifier ...@@ -1144,7 +1144,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, EvqInvariantVaryingOut, @1); $$.setBasic(EbtVoid, EvqInvariantVaryingOut, @1);
else else
$$.setBasic(EbtVoid, EvqInvariantVaryingIn, @1); $$.setBasic(EbtVoid, EvqInvariantVaryingIn, @1);
...@@ -1179,32 +1179,32 @@ storage_qualifier ...@@ -1179,32 +1179,32 @@ storage_qualifier
} }
| IN_QUAL { | IN_QUAL {
ES3_ONLY("in", @1); ES3_ONLY("in", @1);
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn; $$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
$$.line = @1; $$.line = @1;
} }
| OUT_QUAL { | OUT_QUAL {
ES3_ONLY("out", @1); ES3_ONLY("out", @1);
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut; $$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
$$.line = @1; $$.line = @1;
} }
| CENTROID IN_QUAL { | CENTROID IN_QUAL {
ES3_ONLY("centroid in", @1); ES3_ONLY("centroid in", @1);
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;
$$.line = @2; $$.line = @2;
} }
| CENTROID OUT_QUAL { | CENTROID OUT_QUAL {
ES3_ONLY("centroid out", @1); ES3_ONLY("centroid out", @1);
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;
$$.line = @2; $$.line = @2;
} }
| UNIFORM { | UNIFORM {
...@@ -1738,22 +1738,22 @@ condition ...@@ -1738,22 +1738,22 @@ condition
; ;
iteration_statement iteration_statement
: WHILE LEFT_PAREN { context->symbolTable.push(); ++context->loopNestingLevel; } 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->loopNestingLevel; context->decrLoopNestingLevel();
} }
| DO { ++context->loopNestingLevel; } 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->loopNestingLevel; context->decrLoopNestingLevel();
} }
| FOR LEFT_PAREN { context->symbolTable.push(); ++context->loopNestingLevel; } 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->loopNestingLevel; context->decrLoopNestingLevel();
} }
; ;
...@@ -1810,11 +1810,11 @@ jump_statement ...@@ -1810,11 +1810,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, 0); $$ = context->intermediate.growAggregate($1, $2, 0);
context->treeRoot = $$; context->setTreeRoot($$);
} }
; ;
...@@ -1831,7 +1831,7 @@ function_definition ...@@ -1831,7 +1831,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)
{ {
...@@ -1839,7 +1839,7 @@ function_definition ...@@ -1839,7 +1839,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
...@@ -1871,8 +1871,8 @@ function_definition ...@@ -1871,8 +1871,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->functionReturnsValue = false; context->setFunctionReturnsValue(false);
// //
// Insert parameters into the symbol table. // Insert parameters into the symbol table.
...@@ -1911,12 +1911,12 @@ function_definition ...@@ -1911,12 +1911,12 @@ function_definition
} }
context->intermediate.setAggregateOperator(paramNodes, EOpParameters, @1); context->intermediate.setAggregateOperator(paramNodes, EOpParameters, @1);
$1.intermAggregate = paramNodes; $1.intermAggregate = paramNodes;
context->loopNestingLevel = 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->functionReturnsValue) { 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();
} }
......
...@@ -1772,7 +1772,7 @@ case 137: ...@@ -1772,7 +1772,7 @@ case 137:
case 138: case 138:
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);
} }
...@@ -1783,7 +1783,7 @@ YY_RULE_SETUP ...@@ -1783,7 +1783,7 @@ YY_RULE_SETUP
case 139: case 139:
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);
...@@ -3287,7 +3287,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) ...@@ -3287,7 +3287,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);
...@@ -3304,7 +3304,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -3304,7 +3304,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 (yyextra->lexAfterType == false && symbol && symbol->isVariable()) { if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol); TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) { if (variable->isUserType()) {
...@@ -3326,9 +3326,9 @@ int reserved_word(yyscan_t yyscanner) { ...@@ -3326,9 +3326,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);
} }
...@@ -3338,9 +3338,9 @@ int ES2_reserved_ES3_keyword(TParseContext *context, int token) ...@@ -3338,9 +3338,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);
} }
...@@ -3350,11 +3350,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token) ...@@ -3350,11 +3350,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token)
int ES2_identifier_ES3_keyword(TParseContext *context, int token) int ES2_identifier_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);
...@@ -3365,10 +3365,10 @@ int ES2_identifier_ES3_keyword(TParseContext *context, int token) ...@@ -3365,10 +3365,10 @@ int ES2_identifier_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();
...@@ -3383,9 +3383,9 @@ int uint_constant(TParseContext *context) ...@@ -3383,9 +3383,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();
...@@ -3415,7 +3415,7 @@ int float_constant(yyscan_t yyscanner) { ...@@ -3415,7 +3415,7 @@ int float_constant(yyscan_t yyscanner) {
} }
void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) { void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
if (context->AfterEOF) { if (context->AfterEOF) {
context->error(*lloc, reason, "unexpected EOF"); context->error(*lloc, reason, "unexpected EOF");
...@@ -3430,15 +3430,15 @@ int glslang_initialize(TParseContext* context) { ...@@ -3430,15 +3430,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;
...@@ -3446,12 +3446,12 @@ int glslang_finalize(TParseContext* context) { ...@@ -3446,12 +3446,12 @@ 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_lineno(EncodeSourceLoc(0, 1),context->scanner); yyset_lineno(EncodeSourceLoc(0, 1),context->getScanner());
context->AfterEOF = false; context->AfterEOF = false;
// Initialize preprocessor. // Initialize preprocessor.
if (!context->preprocessor.init(count, string, length)) if (!context->getPreprocessor().init(count, string, length))
return 1; return 1;
// Define extension macros. // Define extension macros.
...@@ -3459,10 +3459,10 @@ int glslang_scan(size_t count, const char* const string[], const int length[], ...@@ -3459,10 +3459,10 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
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); context->getPreprocessor().predefineMacro(iter->first.c_str(), 1);
} }
context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1); context->getPreprocessor().predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
return 0; return 0;
} }
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
#define YYENABLE_NLS 0 #define YYENABLE_NLS 0
#define YYLEX_PARAM context->scanner #define YYLEX_PARAM context->getScanner()
...@@ -330,36 +330,36 @@ extern void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason); ...@@ -330,36 +330,36 @@ extern void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason);
#define YYLLOC_DEFAULT(Current, Rhs, N) do { (Current) = YYRHSLOC(Rhs, N ? 1 : 0); } while (0) #define YYLLOC_DEFAULT(Current, Rhs, N) do { (Current) = YYRHSLOC(Rhs, N ? 1 : 0); } while (0)
#define FRAG_VERT_ONLY(S, L) { \ #define FRAG_VERT_ONLY(S, L) { \
if (context->shaderType != GL_FRAGMENT_SHADER && \ if (context->getShaderType() != GL_FRAGMENT_SHADER && \
context->shaderType != GL_VERTEX_SHADER) { \ context->getShaderType() != GL_VERTEX_SHADER) { \
context->error(L, " supported in vertex/fragment shaders only ", S); \ context->error(L, " supported in vertex/fragment shaders only ", S); \
context->recover(); \ context->recover(); \
} \ } \
} }
#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(S, L) { \ #define ES3_ONLY(S, L) { \
if (context->shaderVersion != 300) { \ if (context->getShaderVersion() != 300) { \
context->error(L, " supported in GLSL ES 3.00 only ", S); \ context->error(L, " supported in GLSL ES 3.00 only ", S); \
context->recover(); \ context->recover(); \
} \ } \
...@@ -3337,7 +3337,7 @@ yyreduce: ...@@ -3337,7 +3337,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) - (2)].interm.function)->getMangledName(), context->shaderVersion)); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[(1) - (2)].interm.function)->getMangledName(), context->getShaderVersion()));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) { if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) {
context->error((yylsp[(2) - (2)]), "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString()); context->error((yylsp[(2) - (2)]), "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString());
...@@ -3713,7 +3713,7 @@ yyreduce: ...@@ -3713,7 +3713,7 @@ yyreduce:
ES2_ONLY("varying", (yylsp[(1) - (1)])); ES2_ONLY("varying", (yylsp[(1) - (1)]));
if (context->globalErrorCheck((yylsp[(1) - (1)]), context->symbolTable.atGlobalLevel(), "varying")) if (context->globalErrorCheck((yylsp[(1) - (1)]), 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[(1) - (1)])); (yyval.interm.type).setBasic(EbtVoid, EvqVaryingOut, (yylsp[(1) - (1)]));
else else
(yyval.interm.type).setBasic(EbtVoid, EvqVaryingIn, (yylsp[(1) - (1)])); (yyval.interm.type).setBasic(EbtVoid, EvqVaryingIn, (yylsp[(1) - (1)]));
...@@ -3726,7 +3726,7 @@ yyreduce: ...@@ -3726,7 +3726,7 @@ yyreduce:
ES2_ONLY("varying", (yylsp[(1) - (2)])); ES2_ONLY("varying", (yylsp[(1) - (2)]));
if (context->globalErrorCheck((yylsp[(1) - (2)]), context->symbolTable.atGlobalLevel(), "invariant varying")) if (context->globalErrorCheck((yylsp[(1) - (2)]), 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, EvqInvariantVaryingOut, (yylsp[(1) - (2)])); (yyval.interm.type).setBasic(EbtVoid, EvqInvariantVaryingOut, (yylsp[(1) - (2)]));
else else
(yyval.interm.type).setBasic(EbtVoid, EvqInvariantVaryingIn, (yylsp[(1) - (2)])); (yyval.interm.type).setBasic(EbtVoid, EvqInvariantVaryingIn, (yylsp[(1) - (2)]));
...@@ -3786,7 +3786,7 @@ yyreduce: ...@@ -3786,7 +3786,7 @@ yyreduce:
{ {
ES3_ONLY("in", (yylsp[(1) - (1)])); ES3_ONLY("in", (yylsp[(1) - (1)]));
(yyval.interm.type).qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn; (yyval.interm.type).qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
(yyval.interm.type).line = (yylsp[(1) - (1)]); (yyval.interm.type).line = (yylsp[(1) - (1)]);
} }
break; break;
...@@ -3795,7 +3795,7 @@ yyreduce: ...@@ -3795,7 +3795,7 @@ yyreduce:
{ {
ES3_ONLY("out", (yylsp[(1) - (1)])); ES3_ONLY("out", (yylsp[(1) - (1)]));
(yyval.interm.type).qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut; (yyval.interm.type).qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
(yyval.interm.type).line = (yylsp[(1) - (1)]); (yyval.interm.type).line = (yylsp[(1) - (1)]);
} }
break; break;
...@@ -3804,12 +3804,12 @@ yyreduce: ...@@ -3804,12 +3804,12 @@ yyreduce:
{ {
ES3_ONLY("centroid in", (yylsp[(1) - (2)])); ES3_ONLY("centroid in", (yylsp[(1) - (2)]));
if (context->shaderType == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
{ {
context->error((yylsp[(1) - (2)]), "invalid storage qualifier", "it is an error to use 'centroid in' in the vertex shader"); context->error((yylsp[(1) - (2)]), "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;
(yyval.interm.type).line = (yylsp[(2) - (2)]); (yyval.interm.type).line = (yylsp[(2) - (2)]);
} }
break; break;
...@@ -3818,12 +3818,12 @@ yyreduce: ...@@ -3818,12 +3818,12 @@ yyreduce:
{ {
ES3_ONLY("centroid out", (yylsp[(1) - (2)])); ES3_ONLY("centroid out", (yylsp[(1) - (2)]));
if (context->shaderType == GL_FRAGMENT_SHADER) if (context->getShaderType() == GL_FRAGMENT_SHADER)
{ {
context->error((yylsp[(1) - (2)]), "invalid storage qualifier", "it is an error to use 'centroid out' in the fragment shader"); context->error((yylsp[(1) - (2)]), "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;
(yyval.interm.type).line = (yylsp[(2) - (2)]); (yyval.interm.type).line = (yylsp[(2) - (2)]);
} }
break; break;
...@@ -4706,7 +4706,7 @@ yyreduce: ...@@ -4706,7 +4706,7 @@ yyreduce:
case 248: case 248:
{ context->symbolTable.push(); ++context->loopNestingLevel; } { context->symbolTable.push(); context->incrLoopNestingLevel(); }
break; break;
case 249: case 249:
...@@ -4714,13 +4714,13 @@ yyreduce: ...@@ -4714,13 +4714,13 @@ yyreduce:
{ {
context->symbolTable.pop(); context->symbolTable.pop();
(yyval.interm.intermNode) = context->intermediate.addLoop(ELoopWhile, 0, (yyvsp[(4) - (6)].interm.intermTypedNode), 0, (yyvsp[(6) - (6)].interm.intermNode), (yylsp[(1) - (6)])); (yyval.interm.intermNode) = context->intermediate.addLoop(ELoopWhile, 0, (yyvsp[(4) - (6)].interm.intermTypedNode), 0, (yyvsp[(6) - (6)].interm.intermNode), (yylsp[(1) - (6)]));
--context->loopNestingLevel; context->decrLoopNestingLevel();
} }
break; break;
case 250: case 250:
{ ++context->loopNestingLevel; } { context->incrLoopNestingLevel(); }
break; break;
case 251: case 251:
...@@ -4730,13 +4730,13 @@ yyreduce: ...@@ -4730,13 +4730,13 @@ yyreduce:
context->recover(); context->recover();
(yyval.interm.intermNode) = context->intermediate.addLoop(ELoopDoWhile, 0, (yyvsp[(6) - (8)].interm.intermTypedNode), 0, (yyvsp[(3) - (8)].interm.intermNode), (yylsp[(4) - (8)])); (yyval.interm.intermNode) = context->intermediate.addLoop(ELoopDoWhile, 0, (yyvsp[(6) - (8)].interm.intermTypedNode), 0, (yyvsp[(3) - (8)].interm.intermNode), (yylsp[(4) - (8)]));
--context->loopNestingLevel; context->decrLoopNestingLevel();
} }
break; break;
case 252: case 252:
{ context->symbolTable.push(); ++context->loopNestingLevel; } { context->symbolTable.push(); context->incrLoopNestingLevel(); }
break; break;
case 253: case 253:
...@@ -4744,7 +4744,7 @@ yyreduce: ...@@ -4744,7 +4744,7 @@ yyreduce:
{ {
context->symbolTable.pop(); context->symbolTable.pop();
(yyval.interm.intermNode) = context->intermediate.addLoop(ELoopFor, (yyvsp[(4) - (7)].interm.intermNode), reinterpret_cast<TIntermTyped*>((yyvsp[(5) - (7)].interm.nodePair).node1), reinterpret_cast<TIntermTyped*>((yyvsp[(5) - (7)].interm.nodePair).node2), (yyvsp[(7) - (7)].interm.intermNode), (yylsp[(1) - (7)])); (yyval.interm.intermNode) = context->intermediate.addLoop(ELoopFor, (yyvsp[(4) - (7)].interm.intermNode), reinterpret_cast<TIntermTyped*>((yyvsp[(5) - (7)].interm.nodePair).node1), reinterpret_cast<TIntermTyped*>((yyvsp[(5) - (7)].interm.nodePair).node2), (yyvsp[(7) - (7)].interm.intermNode), (yylsp[(1) - (7)]));
--context->loopNestingLevel; context->decrLoopNestingLevel();
} }
break; break;
...@@ -4832,7 +4832,7 @@ yyreduce: ...@@ -4832,7 +4832,7 @@ yyreduce:
{ {
(yyval.interm.intermNode) = (yyvsp[(1) - (1)].interm.intermNode); (yyval.interm.intermNode) = (yyvsp[(1) - (1)].interm.intermNode);
context->treeRoot = (yyval.interm.intermNode); context->setTreeRoot((yyval.interm.intermNode));
} }
break; break;
...@@ -4840,7 +4840,7 @@ yyreduce: ...@@ -4840,7 +4840,7 @@ yyreduce:
{ {
(yyval.interm.intermNode) = context->intermediate.growAggregate((yyvsp[(1) - (2)].interm.intermNode), (yyvsp[(2) - (2)].interm.intermNode), 0); (yyval.interm.intermNode) = context->intermediate.growAggregate((yyvsp[(1) - (2)].interm.intermNode), (yyvsp[(2) - (2)].interm.intermNode), 0);
context->treeRoot = (yyval.interm.intermNode); context->setTreeRoot((yyval.interm.intermNode));
} }
break; break;
...@@ -4863,7 +4863,7 @@ yyreduce: ...@@ -4863,7 +4863,7 @@ yyreduce:
{ {
TFunction* function = (yyvsp[(1) - (1)].interm).function; TFunction* function = (yyvsp[(1) - (1)].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)
{ {
...@@ -4871,7 +4871,7 @@ yyreduce: ...@@ -4871,7 +4871,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
...@@ -4903,8 +4903,8 @@ yyreduce: ...@@ -4903,8 +4903,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->functionReturnsValue = false; context->setFunctionReturnsValue(false);
// //
// Insert parameters into the symbol table. // Insert parameters into the symbol table.
...@@ -4943,7 +4943,7 @@ yyreduce: ...@@ -4943,7 +4943,7 @@ yyreduce:
} }
context->intermediate.setAggregateOperator(paramNodes, EOpParameters, (yylsp[(1) - (1)])); context->intermediate.setAggregateOperator(paramNodes, EOpParameters, (yylsp[(1) - (1)]));
(yyvsp[(1) - (1)].interm).intermAggregate = paramNodes; (yyvsp[(1) - (1)].interm).intermAggregate = paramNodes;
context->loopNestingLevel = 0; context->setLoopNestingLevel(0);
} }
break; break;
...@@ -4952,7 +4952,7 @@ yyreduce: ...@@ -4952,7 +4952,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->functionReturnsValue) { if (context->getCurrentFunctionType()->getBasicType() != EbtVoid && ! context->getFunctionReturnsValue()) {
context->error((yylsp[(1) - (3)]), "function does not return a value:", "", (yyvsp[(1) - (3)].interm).function->getName().c_str()); context->error((yylsp[(1) - (3)]), "function does not return a value:", "", (yyvsp[(1) - (3)].interm).function->getName().c_str());
context->recover(); context->recover();
} }
......
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