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)
......
...@@ -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;
} }
......
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