Commit adfffe46 by Nicolas Capens

Duplicate reused symbol table entries.

BUG=angle:651 Change-Id: Ifce3c19d41a0a5a5ca5ee90ede528adf397d1da5 Reviewed-on: https://chromium-review.googlesource.com/204290Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent b9f240b1
......@@ -566,10 +566,10 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI
fields->push_back(diff);
TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
depthRange->setQualifier(EvqUniform);
symbolTable.insert(COMMON_BUILTINS, *depthRange);
symbolTable.insert(COMMON_BUILTINS, depthRange);
//
// Implementation dependent built-in constants.
......@@ -604,31 +604,31 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
//
switch(type) {
case SH_FRAGMENT_SHADER:
symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
//
// In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
// Instead, css_MixColor and css_ColorMatrix are available.
//
if (spec != SH_CSS_SHADERS_SPEC) {
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
if (resources.EXT_frag_depth) {
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
}
} else {
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
}
break;
case SH_VERTEX_SHADER:
symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
break;
default: assert(false && "Language not supported");
......@@ -735,7 +735,7 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
// Set up gl_FragData. The array size.
TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
fragData.setArraySize(resources.MaxDrawBuffers);
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
}
break;
default: break;
......
......@@ -804,7 +804,7 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident
if (type.arraySize)
variable->getType().setArraySize(type.arraySize);
if (! symbolTable.declare(*variable)) {
if (! symbolTable.declare(variable)) {
delete variable;
error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str());
return true;
......@@ -884,7 +884,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc& line, const TString& ide
variable = new TVariable(&identifier, TType(type));
if (! symbolTable.declare(*variable)) {
if (! symbolTable.declare(variable)) {
error(line, "redefinition", variable->getName().c_str());
delete variable;
variable = 0;
......@@ -1066,7 +1066,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id
// add variable to symbol table
//
variable = new TVariable(&identifier, type);
if (! symbolTable.declare(*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
......@@ -1774,7 +1774,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
}
TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName);
if (!symbolTable.declare(*blockNameSymbol)) {
if (!symbolTable.declare(blockNameSymbol)) {
error(nameLine, "redefinition", blockName.c_str(), "interface block name");
recover();
}
......@@ -1854,7 +1854,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
TVariable* fieldVariable = new TVariable(&field->name(), *fieldType);
fieldVariable->setQualifier(typeQualifier.qualifier);
if (!symbolTable.declare(*fieldVariable)) {
if (!symbolTable.declare(fieldVariable)) {
error(field->line(), "redefinition", field->name().c_str(), "interface block member name");
recover();
}
......@@ -1866,7 +1866,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
TVariable* instanceTypeDef = new TVariable(instanceName, interfaceBlockType, false);
instanceTypeDef->setQualifier(typeQualifier.qualifier);
if (!symbolTable.declare(*instanceTypeDef)) {
if (!symbolTable.declare(instanceTypeDef)) {
error(instanceLine, "redefinition", instanceName->c_str(), "interface block instance name");
recover();
}
......@@ -2455,7 +2455,7 @@ TPublicType TParseContext::addStructure(const TSourceLoc& structLine, const TSou
recover();
}
TVariable* userTypeDef = new TVariable(structName, *structureType, true);
if (!symbolTable.declare(*userTypeDef)) {
if (!symbolTable.declare(userTypeDef)) {
error(nameLine, "redefinition", structName->c_str(), "struct");
recover();
}
......
......@@ -38,21 +38,16 @@ TSymbolTableLevel::~TSymbolTableLevel()
delete (*it).second;
}
bool TSymbolTableLevel::insert(const TString &name, TSymbol &symbol)
bool TSymbolTableLevel::insert(TSymbol *symbol)
{
symbol.setUniqueId(TSymbolTable::nextUniqueId());
symbol->setUniqueId(TSymbolTable::nextUniqueId());
// returning true means symbol was added to the table
tInsertResult result = level.insert(tLevelPair(name, &symbol));
tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol));
return result.second;
}
bool TSymbolTableLevel::insert(TSymbol &symbol)
{
return insert(symbol.getMangledName(), symbol);
}
TSymbol *TSymbolTableLevel::find(const TString &name) const
{
tLevel::const_iterator it = level.find(name);
......@@ -212,7 +207,7 @@ void TSymbolTable::insertBuiltIn(
}
}
insert(level, *function);
insert(level, function);
}
TPrecision TSymbolTable::getDefaultPrecision(TBasicType type)
......
......@@ -185,7 +185,7 @@ class TFunction : public TSymbol
defined(false)
{
}
TFunction(const TString *name, TType &retType, TOperator tOp = EOpNull)
TFunction(const TString *name, const TType &retType, TOperator tOp = EOpNull)
: TSymbol(name),
returnType(retType),
mangledName(TFunction::mangleName(*name)),
......@@ -288,8 +288,7 @@ class TSymbolTableLevel
}
~TSymbolTableLevel();
bool insert(const TString &name, TSymbol &symbol);
bool insert(TSymbol &symbol);
bool insert(TSymbol *symbol);
TSymbol *find(const TString &name) const;
......@@ -351,12 +350,12 @@ class TSymbolTable
precisionStack.pop_back();
}
bool declare(TSymbol &symbol)
bool declare(TSymbol *symbol)
{
return insert(currentLevel(), symbol);
}
bool insert(ESymbolLevel level, TSymbol &symbol)
bool insert(ESymbolLevel level, TSymbol *symbol)
{
return table[level]->insert(symbol);
}
......@@ -366,7 +365,7 @@ class TSymbolTable
TVariable *constant = new TVariable(
NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
constant->getConstPointer()->setIConst(value);
return insert(level, *constant);
return insert(level, constant);
}
void insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name,
......
......@@ -237,7 +237,7 @@ variable_identifier
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable($1.string, type);
context->symbolTable.declare(*fakeVariable);
context->symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
......@@ -887,7 +887,8 @@ function_prototype
else
{
// Insert the unmangled name to detect potential future redefinition as a variable.
context->symbolTable.getOuterLevel()->insert($1->getName(), *$1);
TFunction *function = new TFunction(NewPoolTString($1->getName().c_str()), $1->getReturnType());
context->symbolTable.getOuterLevel()->insert(function);
}
//
......@@ -899,7 +900,7 @@ function_prototype
// We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead.
context->symbolTable.getOuterLevel()->insert(*$$.function);
context->symbolTable.getOuterLevel()->insert($$.function);
}
;
......@@ -1899,7 +1900,7 @@ function_definition
//
// Insert the parameters with name in the symbol table.
//
if (! context->symbolTable.declare(*variable)) {
if (! context->symbolTable.declare(variable)) {
context->error(@1, "redefinition", variable->getName().c_str());
context->recover();
delete variable;
......
......@@ -2575,7 +2575,7 @@ yyreduce:
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type);
context->symbolTable.declare(*fakeVariable);
context->symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
......@@ -3436,7 +3436,8 @@ yyreduce:
else
{
// Insert the unmangled name to detect potential future redefinition as a variable.
context->symbolTable.getOuterLevel()->insert((yyvsp[(1) - (2)].interm.function)->getName(), *(yyvsp[(1) - (2)].interm.function));
TFunction *function = new TFunction(NewPoolTString((yyvsp[(1) - (2)].interm.function)->getName().c_str()), (yyvsp[(1) - (2)].interm.function)->getReturnType());
context->symbolTable.getOuterLevel()->insert(function);
}
//
......@@ -3448,7 +3449,7 @@ yyreduce:
// We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead.
context->symbolTable.getOuterLevel()->insert(*(yyval.interm).function);
context->symbolTable.getOuterLevel()->insert((yyval.interm).function);
}
break;
......@@ -4967,7 +4968,7 @@ yyreduce:
//
// Insert the parameters with name in the symbol table.
//
if (! context->symbolTable.declare(*variable)) {
if (! context->symbolTable.declare(variable)) {
context->error((yylsp[(1) - (1)]), "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