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[],
// Parse shader.
bool success =
(PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL);
(parseContext.getTreeRoot() != NULL);
shaderVersion = parseContext.getShaderVersion();
if (success) {
TIntermNode* root = parseContext.treeRoot;
TIntermNode* root = parseContext.getTreeRoot();
success = intermediate.postProcess(root);
if (success)
......
......@@ -10,7 +10,7 @@
bool InitializeParseContextIndex();
void FreeParseContextIndex();
struct TParseContext;
class TParseContext;
extern void SetGlobalParseContext(TParseContext* context);
extern TParseContext* GetGlobalParseContext();
......
......@@ -154,7 +154,7 @@ namespace glsl
{
emitScope = scope;
currentScope = GLOBAL;
mContext.treeRoot->traverse(this);
mContext.getTreeRoot()->traverse(this);
}
void OutputASM::freeTemporary(Temporary *temporary)
......
......@@ -24,68 +24,81 @@ struct TMatrixFields {
// The following are extra variables needed during parsing, grouped together so
// 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) :
intermediate(interm),
symbolTable(symt),
shaderType(type),
compileOptions(options),
sourcePath(sourcePath),
treeRoot(0),
lexAfterType(false),
loopNestingLevel(0),
switchNestingLevel(0),
structNestingLevel(0),
inTypeParen(false),
currentFunctionType(NULL),
functionReturnsValue(false),
checksPrecisionErrors(checksPrecErrors),
defaultMatrixPacking(EmpColumnMajor),
defaultBlockStorage(EbsShared),
diagnostics(is),
shaderVersion(100),
directiveHandler(ext, diagnostics, shaderVersion),
preprocessor(&diagnostics, &directiveHandler),
scanner(NULL),
mDeferredSingleDeclarationErrorCheck(false),
AfterEOF(false),
mDeferredSingleDeclarationErrorCheck(false),
mShaderType(type),
mShaderVersion(100),
mTreeRoot(0),
mLoopNestingLevel(0),
mSwitchNestingLevel(0),
mStructNestingLevel(0),
mCurrentFunctionType(NULL),
mFunctionReturnsValue(false),
mChecksPrecisionErrors(checksPrecErrors),
mDefaultMatrixPacking(EmpColumnMajor),
mDefaultBlockStorage(EbsShared),
mDiagnostics(is),
mDirectiveHandler(ext, mDiagnostics, mShaderVersion),
mPreprocessor(&mDiagnostics, &mDirectiveHandler),
mScanner(NULL),
mUsesFragData(false),
mUsesFragColor(false) { }
TIntermediate& intermediate; // to hold and build a parse tree
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;
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
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
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;
TDiagnostics diagnostics;
TDirectiveHandler directiveHandler;
pp::Preprocessor preprocessor;
void* scanner;
int getShaderVersion() const { return shaderVersion; }
int numErrors() const { return diagnostics.numErrors(); }
TInfoSink& infoSink() { return diagnostics.infoSink(); }
const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
void *getScanner() const { return mScanner; }
void setScanner(void *scanner) { mScanner = scanner; }
int getShaderVersion() const { return mShaderVersion; }
GLenum getShaderType() const { return mShaderType; }
int numErrors() const { return mDiagnostics.numErrors(); }
TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
void error(const TSourceLoc &loc, const char *reason, const char* token,
const char* extraInfo="");
void warning(const TSourceLoc &loc, const char* reason, const char* token,
const char* extraInfo="");
void trace(const char* str);
void recover();
void incrSwitchNestingLevel() { ++switchNestingLevel; }
void decrSwitchNestingLevel() { --switchNestingLevel; }
TIntermNode *getTreeRoot() const { return mTreeRoot; }
void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
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.
const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
......@@ -121,11 +134,11 @@ struct TParseContext {
bool layoutLocationErrorCheck(const TSourceLoc& location, const TLayoutQualifier &layoutQualifier);
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);
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);
bool containsSampler(TType& type);
......@@ -221,8 +234,26 @@ private:
// Return true if the checks pass
bool binaryOpCommonCheck(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
bool mDeferredSingleDeclarationErrorCheck;
bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
// Set to true when the last/current declarator list was started with an empty declaration.
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;
};
......
......@@ -8,7 +8,7 @@
#define COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
class TIntermTyped;
struct TParseContext;
class TParseContext;
// Returns true if the initializer is valid.
bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning);
......
......@@ -440,7 +440,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node)
bool valid = true;
TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable;
TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->shaderVersion);
TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->getShaderVersion());
ASSERT(symbol && symbol->isFunction());
TFunction* function = static_cast<TFunction*>(symbol);
for (ParamIndex::const_iterator i = pIndex.begin();
......
......@@ -10,7 +10,7 @@
#include "intermediate.h"
#include <set>
struct TParseContext;
class TParseContext;
class ValidateSwitch : public TIntermTraverser
{
......
......@@ -4,7 +4,7 @@
// found in the LICENSE file.
//
struct TParseContext;
class TParseContext;
extern int glslang_initialize(TParseContext* context);
extern int glslang_finalize(TParseContext* context);
......
......@@ -241,7 +241,7 @@ O [0-7]
"sampler2DMSArray" |
"isampler2DMSArray" |
"usampler2DMSArray" {
if (context->shaderVersion < 300) {
if (context->getShaderVersion() < 300) {
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
}
......@@ -250,7 +250,7 @@ O [0-7]
/* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
"packed" {
if (context->shaderVersion >= 300)
if (context->getShaderVersion() >= 300)
{
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
......@@ -395,7 +395,7 @@ O [0-7]
yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
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();
if (len < max_size)
memcpy(buf, token.text.c_str(), len);
......@@ -412,7 +412,7 @@ int check_type(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
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()) {
TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) {
......@@ -434,9 +434,9 @@ int reserved_word(yyscan_t yyscanner) {
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);
}
......@@ -446,9 +446,9 @@ int ES2_reserved_ES3_keyword(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);
}
......@@ -458,11 +458,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token)
int ES2_identifier_ES3_keyword(TParseContext *context, int token)
{
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
yyscan_t yyscanner = (yyscan_t) context->scanner;
struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
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
if (context->shaderVersion < 300)
if (context->getShaderVersion() < 300)
{
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
......@@ -473,10 +473,10 @@ int ES2_identifier_ES3_keyword(TParseContext *context, int token)
int uint_constant(TParseContext *context)
{
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
yyscan_t yyscanner = (yyscan_t) context->scanner;
struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
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->recover();
......@@ -491,9 +491,9 @@ int uint_constant(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->recover();
......@@ -523,7 +523,7 @@ int float_constant(yyscan_t yyscanner) {
}
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) {
context->error(*lloc, reason, "unexpected EOF");
......@@ -538,15 +538,15 @@ int glslang_initialize(TParseContext* context) {
if (yylex_init_extra(context, &scanner))
return 1;
context->scanner = scanner;
context->setScanner(scanner);
return 0;
}
int glslang_finalize(TParseContext* context) {
yyscan_t scanner = context->scanner;
yyscan_t scanner = context->getScanner();
if (scanner == NULL) return 0;
context->scanner = NULL;
context->setScanner(NULL);
yylex_destroy(scanner);
return 0;
......@@ -554,12 +554,12 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) {
yyrestart(NULL, context->scanner);
yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
yyrestart(NULL, context->getScanner());
yyset_lineno(EncodeSourceLoc(0, 1), context->getScanner());
context->AfterEOF = false;
// Initialize preprocessor.
if (!context->preprocessor.init(count, string, length))
if (!context->getPreprocessor().init(count, string, length))
return 1;
// Define extension macros.
......@@ -567,10 +567,10 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
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;
}
......
......@@ -39,7 +39,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
#define YYENABLE_NLS 0
#define YYLEX_PARAM context->scanner
#define YYLEX_PARAM context->getScanner()
%}
%expect 1 /* One shift reduce conflict because of if | else */
......@@ -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 FRAG_VERT_ONLY(S, L) { \
if (context->shaderType != GL_FRAGMENT_SHADER && \
context->shaderType != GL_VERTEX_SHADER) { \
if (context->getShaderType() != GL_FRAGMENT_SHADER && \
context->getShaderType() != GL_VERTEX_SHADER) { \
context->error(L, " supported in vertex/fragment shaders only ", S); \
context->recover(); \
} \
}
#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->recover(); \
} \
}
#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->recover(); \
} \
}
#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->recover(); \
} \
}
#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->recover(); \
} \
......@@ -782,7 +782,7 @@ function_prototype
//
// 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->getReturnType() != $1->getReturnType()) {
context->error(@2, "overloaded functions must have the same return type", $1->getReturnType().getBasicString());
......@@ -1135,7 +1135,7 @@ type_qualifier
ES2_ONLY("varying", @1);
if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "varying"))
context->recover();
if (context->shaderType == GL_VERTEX_SHADER)
if (context->getShaderType() == GL_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, @1);
else
$$.setBasic(EbtVoid, EvqVaryingIn, @1);
......@@ -1144,7 +1144,7 @@ type_qualifier
ES2_ONLY("varying", @1);
if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "invariant varying"))
context->recover();
if (context->shaderType == GL_VERTEX_SHADER)
if (context->getShaderType() == GL_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqInvariantVaryingOut, @1);
else
$$.setBasic(EbtVoid, EvqInvariantVaryingIn, @1);
......@@ -1179,32 +1179,32 @@ storage_qualifier
}
| IN_QUAL {
ES3_ONLY("in", @1);
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
$$.line = @1;
}
| OUT_QUAL {
ES3_ONLY("out", @1);
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
$$.line = @1;
}
| CENTROID IN_QUAL {
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->recover();
}
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn;
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn;
$$.line = @2;
}
| CENTROID OUT_QUAL {
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->recover();
}
$$.qualifier = (context->shaderType == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut;
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut;
$$.line = @2;
}
| UNIFORM {
......@@ -1738,22 +1738,22 @@ condition
;
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->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))
context->recover();
$$ = 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->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
translation_unit
: external_declaration {
$$ = $1;
context->treeRoot = $$;
context->setTreeRoot($$);
}
| translation_unit external_declaration {
$$ = context->intermediate.growAggregate($1, $2, 0);
context->treeRoot = $$;
context->setTreeRoot($$);
}
;
......@@ -1831,7 +1831,7 @@ function_definition
: function_prototype {
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)
{
......@@ -1839,7 +1839,7 @@ function_definition
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
// as it would have just been put in the symbol table. Otherwise, we're looking up
......@@ -1871,8 +1871,8 @@ function_definition
//
// Remember the return type for later checking for RETURN statements.
//
context->currentFunctionType = &(prevDec->getReturnType());
context->functionReturnsValue = false;
context->setCurrentFunctionType(&(prevDec->getReturnType()));
context->setFunctionReturnsValue(false);
//
// Insert parameters into the symbol table.
......@@ -1911,12 +1911,12 @@ function_definition
}
context->intermediate.setAggregateOperator(paramNodes, EOpParameters, @1);
$1.intermAggregate = paramNodes;
context->loopNestingLevel = 0;
context->setLoopNestingLevel(0);
}
compound_statement_no_new_scope {
//?? Check that all paths return a value if return type != void ?
// May be best done as post process phase on intermediate code
if (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->recover();
}
......
......@@ -1772,7 +1772,7 @@ case 137:
case 138:
YY_RULE_SETUP
{
if (context->shaderVersion < 300) {
if (context->getShaderVersion() < 300) {
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
}
......@@ -1783,7 +1783,7 @@ YY_RULE_SETUP
case 139:
YY_RULE_SETUP
{
if (context->shaderVersion >= 300)
if (context->getShaderVersion() >= 300)
{
yylval->lex.string = NewPoolTString(yytext);
return check_type(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) {
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();
if (len < max_size)
memcpy(buf, token.text.c_str(), len);
......@@ -3304,7 +3304,7 @@ int check_type(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
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()) {
TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) {
......@@ -3326,9 +3326,9 @@ int reserved_word(yyscan_t yyscanner) {
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);
}
......@@ -3338,9 +3338,9 @@ int ES2_reserved_ES3_keyword(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);
}
......@@ -3350,11 +3350,11 @@ int ES2_keyword_ES3_reserved(TParseContext *context, int token)
int ES2_identifier_ES3_keyword(TParseContext *context, int token)
{
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
yyscan_t yyscanner = (yyscan_t) context->scanner;
struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
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
if (context->shaderVersion < 300)
if (context->getShaderVersion() < 300)
{
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
......@@ -3365,10 +3365,10 @@ int ES2_identifier_ES3_keyword(TParseContext *context, int token)
int uint_constant(TParseContext *context)
{
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
yyscan_t yyscanner = (yyscan_t) context->scanner;
struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
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->recover();
......@@ -3383,9 +3383,9 @@ int uint_constant(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->recover();
......@@ -3415,7 +3415,7 @@ int float_constant(yyscan_t yyscanner) {
}
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) {
context->error(*lloc, reason, "unexpected EOF");
......@@ -3430,15 +3430,15 @@ int glslang_initialize(TParseContext* context) {
if (yylex_init_extra(context,&scanner))
return 1;
context->scanner = scanner;
context->setScanner(scanner);
return 0;
}
int glslang_finalize(TParseContext* context) {
yyscan_t scanner = context->scanner;
yyscan_t scanner = context->getScanner();
if (scanner == NULL) return 0;
context->scanner = NULL;
context->setScanner(NULL);
yylex_destroy(scanner);
return 0;
......@@ -3446,12 +3446,12 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) {
yyrestart(NULL,context->scanner);
yyset_lineno(EncodeSourceLoc(0, 1),context->scanner);
yyrestart(NULL,context->getScanner());
yyset_lineno(EncodeSourceLoc(0, 1),context->getScanner());
context->AfterEOF = false;
// Initialize preprocessor.
if (!context->preprocessor.init(count, string, length))
if (!context->getPreprocessor().init(count, string, length))
return 1;
// Define extension macros.
......@@ -3459,10 +3459,10 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
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;
}
......
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