Commit d603ecd6 by Nicolas Capens

Explicitly insert builtins at symbol level 0 and declare variables at the top level.

Bug 19331817 Change-Id: I157c68e00aef3f2726bd72ac7ff96bdb8f191c75 Reviewed-on: https://swiftshader-review.googlesource.com/2350Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 0a7f0c21
......@@ -320,10 +320,10 @@ void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TS
members->push_back(far);
members->push_back(diff);
TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true);
symbolTable.insert(*depthRangeParameters);
symbolTable.insert(0, *depthRangeParameters);
TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters"));
depthRange->setQualifier(EvqUniform);
symbolTable.insert(*depthRange);
symbolTable.insert(0, *depthRange);
symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs);
symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
......@@ -346,15 +346,15 @@ void IdentifyBuiltIns(GLenum shaderType,
switch(shaderType)
{
case GL_FRAGMENT_SHADER:
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
break;
case GL_VERTEX_SHADER:
symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
break;
default: assert(false && "Language not supported");
}
......@@ -445,7 +445,7 @@ void IdentifyBuiltIns(GLenum shaderType,
// Set up gl_FragData. The array size.
TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true);
fragData.setArraySize(resources.MaxDrawBuffers);
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragData"), fragData));
}
break;
default: break;
......
......@@ -751,7 +751,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
if (type.arraySize)
variable->getType().setArraySize(type.arraySize);
if (! symbolTable.insert(*variable)) {
if (! symbolTable.declare(*variable)) {
delete variable;
error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str());
return true;
......@@ -885,7 +885,7 @@ bool TParseContext::nonInitErrorCheck(int line, TString& identifier, TPublicType
variable = new TVariable(&identifier, TType(type));
if (! symbolTable.insert(*variable)) {
if (! symbolTable.declare(*variable)) {
error(line, "redefinition", variable->getName().c_str());
delete variable;
variable = 0;
......@@ -1012,7 +1012,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu
// add variable to symbol table
//
variable = new TVariable(&identifier, type);
if (! symbolTable.insert(*variable)) {
if (! symbolTable.declare(*variable)) {
error(line, "redefinition", variable->getName().c_str());
return true;
// don't delete variable, it's used by error recovery, and the pool
......
......@@ -259,16 +259,21 @@ public:
precisionStack.pop_back();
}
bool insert(TSymbol &symbol)
bool declare(TSymbol &symbol)
{
return table[currentLevel()]->insert(symbol);
return insert(currentLevel(), symbol);
}
bool insert(int level, TSymbol &symbol)
{
return table[level]->insert(symbol);
}
bool insertConstInt(const char *name, int value)
{
TVariable *constant = new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
constant->getConstPointer()->setIConst(value);
return insert(*constant);
return insert(0, *constant);
}
bool insertBuiltIn(TType *rvalue, const char *name, TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0)
......@@ -290,7 +295,7 @@ public:
function->addParameter(param3);
}
return insert(*function);
return insert(0, *function);
}
TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = false, bool *sameScope = false) const
......
......@@ -193,7 +193,7 @@ variable_identifier
context->recover();
TType type(EbtFloat, EbpUndefined);
TVariable* fakeVariable = new TVariable($1.string, type);
context->symbolTable.insert(*fakeVariable);
context->symbolTable.declare(*fakeVariable);
variable = fakeVariable;
} else {
// This identifier can only be a variable type symbol
......@@ -1457,7 +1457,7 @@ single_declaration
// if (context->reservedErrorCheck($2.line, *$2.string, context))
// context->recover();
// $$.variable = new TVariable($2.string, $1);
// if (! context->symbolTable.insert(*$$.variable)) {
// if (! context->symbolTable.declare(*$$.variable)) {
// context->error($2.line, "redefinition", $$.variable->getName().c_str());
// context->recover();
// // don't have to delete $$.variable, the pool pop will take care of it
......@@ -1799,7 +1799,7 @@ struct_specifier
TType* structure = new TType($5, *$2.string);
TVariable* userTypeDef = new TVariable($2.string, *structure, true);
if (! context->symbolTable.insert(*userTypeDef)) {
if (! context->symbolTable.declare(*userTypeDef)) {
context->error($2.line, "redefinition", $2.string->c_str(), "struct");
context->recover();
}
......@@ -2188,7 +2188,7 @@ function_definition
//
// Insert the parameters with name in the symbol table.
//
if (! context->symbolTable.insert(*variable)) {
if (! context->symbolTable.declare(*variable)) {
context->error($1.line, "redefinition", variable->getName().c_str());
context->recover();
delete variable;
......
......@@ -2179,7 +2179,7 @@ yyreduce:
context->recover();
TType type(EbtFloat, EbpUndefined);
TVariable* fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type);
context->symbolTable.insert(*fakeVariable);
context->symbolTable.declare(*fakeVariable);
variable = fakeVariable;
} else {
// This identifier can only be a variable type symbol
......@@ -4172,7 +4172,7 @@ yyreduce:
TType* structure = new TType((yyvsp[(5) - (6)].interm.typeList), *(yyvsp[(2) - (6)].lex).string);
TVariable* userTypeDef = new TVariable((yyvsp[(2) - (6)].lex).string, *structure, true);
if (! context->symbolTable.insert(*userTypeDef)) {
if (! context->symbolTable.declare(*userTypeDef)) {
context->error((yyvsp[(2) - (6)].lex).line, "redefinition", (yyvsp[(2) - (6)].lex).string->c_str(), "struct");
context->recover();
}
......@@ -4730,7 +4730,7 @@ yyreduce:
//
// Insert the parameters with name in the symbol table.
//
if (! context->symbolTable.insert(*variable)) {
if (! context->symbolTable.declare(*variable)) {
context->error((yyvsp[(1) - (1)].interm).line, "redefinition", variable->getName().c_str());
context->recover();
delete variable;
......
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