Skip symbol table levels with built-ins for a different shader version.

TRAC #22954 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2272 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1c848096
...@@ -741,7 +741,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t ...@@ -741,7 +741,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
bool builtIn = false; bool builtIn = false;
bool sameScope = false; bool sameScope = false;
TSymbol* symbol = symbolTable.find(identifier, &builtIn, &sameScope); TSymbol* symbol = symbolTable.find(identifier, 0, &builtIn, &sameScope);
if (symbol == 0 || !sameScope) { if (symbol == 0 || !sameScope) {
if (reservedErrorCheck(line, identifier)) if (reservedErrorCheck(line, identifier))
return true; return true;
...@@ -800,7 +800,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t ...@@ -800,7 +800,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line) bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line)
{ {
bool builtIn = false; bool builtIn = false;
TSymbol* symbol = symbolTable.find(node->getSymbol(), &builtIn); TSymbol* symbol = symbolTable.find(node->getSymbol(), 0, &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;
...@@ -813,7 +813,7 @@ bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, ...@@ -813,7 +813,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", &builtIn); TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", 0, &builtIn);
ASSERT(fragData); ASSERT(fragData);
int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst(); int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst();
...@@ -970,13 +970,13 @@ void TParseContext::handlePragmaDirective(int line, const char* name, const char ...@@ -970,13 +970,13 @@ void TParseContext::handlePragmaDirective(int line, const char* name, const char
// //
// Return the function symbol if found, otherwise 0. // Return the function symbol if found, otherwise 0.
// //
const TFunction* TParseContext::findFunction(int line, TFunction* call, bool *builtIn) const TFunction* TParseContext::findFunction(int line, TFunction* call, int shaderVersion, bool *builtIn)
{ {
// 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(), builtIn); const TSymbol* symbol = symbolTable.find(call->getName(), shaderVersion, builtIn);
if (symbol == 0) { if (symbol == 0) {
symbol = symbolTable.find(call->getMangledName(), builtIn); symbol = symbolTable.find(call->getMangledName(), shaderVersion, builtIn);
} }
if (symbol == 0) { if (symbol == 0) {
...@@ -1056,7 +1056,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu ...@@ -1056,7 +1056,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu
variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer()); variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
} }
} else if (initializer->getAsSymbolNode()) { } else if (initializer->getAsSymbolNode()) {
const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol()); const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol(), 0);
const TVariable* tVar = static_cast<const TVariable*>(symbol); const TVariable* tVar = static_cast<const TVariable*>(symbol);
ConstantUnion* constArray = tVar->getConstPointer(); ConstantUnion* constArray = tVar->getConstPointer();
......
...@@ -115,7 +115,7 @@ struct TParseContext { ...@@ -115,7 +115,7 @@ struct TParseContext {
bool containsSampler(TType& type); bool containsSampler(TType& type);
bool areAllChildConst(TIntermAggregate* aggrNode); bool areAllChildConst(TIntermAggregate* aggrNode);
const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); const TFunction* findFunction(int line, TFunction* pfnCall, int shaderVersion, bool *builtIn = 0);
bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType,
TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -277,3 +277,41 @@ void TSymbolTable::copyTable(const TSymbolTable& copyOf) ...@@ -277,3 +277,41 @@ void TSymbolTable::copyTable(const TSymbolTable& copyOf)
precisionStack.push_back( copyOf.precisionStack[i] ); precisionStack.push_back( copyOf.precisionStack[i] );
} }
} }
TSymbol *TSymbolTable::find(const TString &name, int shaderVersion, bool *builtIn, bool *sameScope)
{
int level = currentLevel();
TSymbol *symbol;
do
{
if (level == ESSL3_BUILTINS && shaderVersion != 300) level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100) level--;
symbol = table[level]->find(name);
}
while (symbol == 0 && --level >= 0);
if (builtIn)
*builtIn = (level <= LAST_BUILTIN_LEVEL);
if (sameScope)
*sameScope = (level == currentLevel());
return symbol;
}
TSymbol *TSymbolTable::findBuiltIn(const TString &name, int shaderVersion)
{
for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--)
{
if (level == ESSL3_BUILTINS && shaderVersion != 300) level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100) level--;
TSymbol *symbol = table[level]->find(name);
if (symbol)
return symbol;
}
return 0;
}
...@@ -295,33 +295,8 @@ public: ...@@ -295,33 +295,8 @@ public:
return table[level]->insert(symbol); return table[level]->insert(symbol);
} }
TSymbol *find(const TString &name, bool *builtIn = false, bool *sameScope = false) TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = false, bool *sameScope = false);
{ TSymbol *findBuiltIn(const TString &name, int shaderVersion);
int level = currentLevel();
TSymbol* symbol;
do {
symbol = table[level]->find(name);
--level;
} while (symbol == 0 && level >= 0);
level++;
if (builtIn)
*builtIn = (level <= LAST_BUILTIN_LEVEL);
if (sameScope)
*sameScope = (level == currentLevel());
return symbol;
}
TSymbol *findBuiltIn(const TString &name)
{
for (int i = LAST_BUILTIN_LEVEL; i >= 0; i--) {
TSymbol *symbol = table[i]->find(name);
if (symbol)
return symbol;
}
return 0;
}
TSymbolTableLevel *getOuterLevel() { TSymbolTableLevel *getOuterLevel() {
assert(currentLevel() >= 1); assert(currentLevel() >= 1);
......
// //
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -436,7 +436,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node) ...@@ -436,7 +436,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node)
bool valid = true; bool valid = true;
TSymbolTable& symbolTable = GlobalParseContext->symbolTable; TSymbolTable& symbolTable = GlobalParseContext->symbolTable;
TSymbol* symbol = symbolTable.find(node->getName()); TSymbol* symbol = symbolTable.find(node->getName(), GlobalParseContext->shaderVersion);
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();
......
...@@ -360,7 +360,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -360,7 +360,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); TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
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()) {
......
...@@ -497,7 +497,7 @@ function_call ...@@ -497,7 +497,7 @@ function_call
// //
const TFunction* fnCandidate; const TFunction* fnCandidate;
bool builtIn; bool builtIn;
fnCandidate = context->findFunction($1.line, fnCall, &builtIn); fnCandidate = context->findFunction($1.line, fnCall, context->shaderVersion, &builtIn);
if (fnCandidate) { if (fnCandidate) {
// //
// A declared function. // A declared function.
...@@ -1029,7 +1029,7 @@ function_prototype ...@@ -1029,7 +1029,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())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName(), context->shaderVersion));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != $1->getReturnType()) { if (prevDec->getReturnType() != $1->getReturnType()) {
context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString()); context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString());
...@@ -2144,7 +2144,7 @@ function_definition ...@@ -2144,7 +2144,7 @@ function_definition
: function_prototype { : function_prototype {
TFunction* function = $1.function; TFunction* function = $1.function;
const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName()); const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion);
if (builtIn) if (builtIn)
{ {
...@@ -2152,7 +2152,7 @@ function_definition ...@@ -2152,7 +2152,7 @@ function_definition
context->recover(); context->recover();
} }
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion));
// //
// 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
......
#line 17 "./glslang.l"
// //
// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#line 25 "./glslang_lex.cpp"
#define YY_INT_ALIGNED short int #define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */ /* A lexical scanner generated by flex */
...@@ -3094,7 +3092,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -3094,7 +3092,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); TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
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()) {
......
...@@ -2490,7 +2490,7 @@ yyreduce: ...@@ -2490,7 +2490,7 @@ yyreduce:
// //
const TFunction* fnCandidate; const TFunction* fnCandidate;
bool builtIn; bool builtIn;
fnCandidate = context->findFunction((yyvsp[(1) - (1)].interm).line, fnCall, &builtIn); fnCandidate = context->findFunction((yyvsp[(1) - (1)].interm).line, fnCall, context->shaderVersion, &builtIn);
if (fnCandidate) { if (fnCandidate) {
// //
// A declared function. // A declared function.
...@@ -3176,7 +3176,7 @@ yyreduce: ...@@ -3176,7 +3176,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())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[(1) - (2)].interm.function)->getMangledName(), context->shaderVersion));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) { if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) {
context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString()); context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString());
...@@ -4618,7 +4618,7 @@ yyreduce: ...@@ -4618,7 +4618,7 @@ yyreduce:
{ {
TFunction* function = (yyvsp[(1) - (1)].interm).function; TFunction* function = (yyvsp[(1) - (1)].interm).function;
const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName()); const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion);
if (builtIn) if (builtIn)
{ {
...@@ -4626,7 +4626,7 @@ yyreduce: ...@@ -4626,7 +4626,7 @@ yyreduce:
context->recover(); context->recover();
} }
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion));
// //
// 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
......
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