Commit b376201f by Nicolas Capens

Duplicate reused symbol table entries.

BUG=angle:651 Change-Id: Ifce3c19d41a0a5a5ca5ee90ede528adf397d1da5
parent b15937d8
...@@ -566,10 +566,10 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI ...@@ -566,10 +566,10 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI
fields->push_back(diff); fields->push_back(diff);
TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); 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)); TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
depthRange->setQualifier(EvqUniform); depthRange->setQualifier(EvqUniform);
symbolTable.insert(COMMON_BUILTINS, *depthRange); symbolTable.insert(COMMON_BUILTINS, depthRange);
// //
// Implementation dependent built-in constants. // Implementation dependent built-in constants.
...@@ -604,31 +604,31 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, ...@@ -604,31 +604,31 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
// //
switch(type) { switch(type) {
case SH_FRAGMENT_SHADER: 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_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_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_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
// //
// In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available. // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
// Instead, css_MixColor and css_ColorMatrix are available. // Instead, css_MixColor and css_ColorMatrix are available.
// //
if (spec != SH_CSS_SHADERS_SPEC) { 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_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_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
if (resources.EXT_frag_depth) { 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"); symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
} }
} else { } else {
symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 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))); symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
} }
break; break;
case SH_VERTEX_SHADER: 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_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_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
break; break;
default: assert(false && "Language not supported"); default: assert(false && "Language not supported");
...@@ -735,7 +735,7 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, ...@@ -735,7 +735,7 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
// Set up gl_FragData. The array size. // Set up gl_FragData. The array size.
TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true); TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
fragData.setArraySize(resources.MaxDrawBuffers); 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; break;
default: break; default: break;
......
...@@ -788,7 +788,7 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident ...@@ -788,7 +788,7 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident
if (type.arraySize) if (type.arraySize)
variable->getType().setArraySize(type.arraySize); variable->getType().setArraySize(type.arraySize);
if (! symbolTable.declare(*variable)) { if (! symbolTable.declare(variable)) {
delete variable; delete variable;
error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str()); error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str());
return true; return true;
...@@ -868,7 +868,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc& line, const TString& ide ...@@ -868,7 +868,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc& line, const TString& ide
variable = new TVariable(&identifier, TType(type)); variable = new TVariable(&identifier, TType(type));
if (! symbolTable.declare(*variable)) { if (! symbolTable.declare(variable)) {
error(line, "redefinition", variable->getName().c_str()); error(line, "redefinition", variable->getName().c_str());
delete variable; delete variable;
variable = 0; variable = 0;
...@@ -1050,7 +1050,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id ...@@ -1050,7 +1050,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id
// add variable to symbol table // add variable to symbol table
// //
variable = new TVariable(&identifier, type); variable = new TVariable(&identifier, type);
if (! symbolTable.declare(*variable)) { if (! symbolTable.declare(variable)) {
error(line, "redefinition", variable->getName().c_str()); error(line, "redefinition", variable->getName().c_str());
return true; return true;
// don't delete variable, it's used by error recovery, and the pool // don't delete variable, it's used by error recovery, and the pool
...@@ -1895,7 +1895,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif ...@@ -1895,7 +1895,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
} }
TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName); TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName);
if (!symbolTable.declare(*blockNameSymbol)) { if (!symbolTable.declare(blockNameSymbol)) {
error(nameLine, "redefinition", blockName.c_str(), "interface block name"); error(nameLine, "redefinition", blockName.c_str(), "interface block name");
recover(); recover();
} }
...@@ -1975,7 +1975,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif ...@@ -1975,7 +1975,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
TVariable* fieldVariable = new TVariable(&field->name(), *fieldType); TVariable* fieldVariable = new TVariable(&field->name(), *fieldType);
fieldVariable->setQualifier(typeQualifier.qualifier); fieldVariable->setQualifier(typeQualifier.qualifier);
if (!symbolTable.declare(*fieldVariable)) { if (!symbolTable.declare(fieldVariable)) {
error(field->line(), "redefinition", field->name().c_str(), "interface block member name"); error(field->line(), "redefinition", field->name().c_str(), "interface block member name");
recover(); recover();
} }
...@@ -1987,7 +1987,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif ...@@ -1987,7 +1987,7 @@ TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualif
TVariable* instanceTypeDef = new TVariable(instanceName, interfaceBlockType, false); TVariable* instanceTypeDef = new TVariable(instanceName, interfaceBlockType, false);
instanceTypeDef->setQualifier(typeQualifier.qualifier); instanceTypeDef->setQualifier(typeQualifier.qualifier);
if (!symbolTable.declare(*instanceTypeDef)) { if (!symbolTable.declare(instanceTypeDef)) {
error(instanceLine, "redefinition", instanceName->c_str(), "interface block instance name"); error(instanceLine, "redefinition", instanceName->c_str(), "interface block instance name");
recover(); recover();
} }
...@@ -2574,7 +2574,7 @@ TPublicType TParseContext::addStructure(const TSourceLoc& structLine, const TSou ...@@ -2574,7 +2574,7 @@ TPublicType TParseContext::addStructure(const TSourceLoc& structLine, const TSou
recover(); recover();
} }
TVariable* userTypeDef = new TVariable(structName, *structureType, true); TVariable* userTypeDef = new TVariable(structName, *structureType, true);
if (!symbolTable.declare(*userTypeDef)) { if (!symbolTable.declare(userTypeDef)) {
error(nameLine, "redefinition", structName->c_str(), "struct"); error(nameLine, "redefinition", structName->c_str(), "struct");
recover(); recover();
} }
......
...@@ -130,7 +130,7 @@ public: ...@@ -130,7 +130,7 @@ public:
returnType(TType(EbtVoid, EbpUndefined)), returnType(TType(EbtVoid, EbpUndefined)),
op(o), op(o),
defined(false) { } defined(false) { }
TFunction(const TString *name, TType& retType, TOperator tOp = EOpNull) : TFunction(const TString *name, const TType& retType, TOperator tOp = EOpNull) :
TSymbol(name), TSymbol(name),
returnType(retType), returnType(retType),
mangledName(TFunction::mangleName(*name)), mangledName(TFunction::mangleName(*name)),
...@@ -197,23 +197,18 @@ public: ...@@ -197,23 +197,18 @@ public:
TSymbolTableLevel() { } TSymbolTableLevel() { }
~TSymbolTableLevel(); ~TSymbolTableLevel();
bool insert(const TString &name, TSymbol &symbol) bool insert(TSymbol *symbol)
{ {
symbol.setUniqueId(++uniqueId); symbol->setUniqueId(++uniqueId);
// //
// returning true means symbol was added to the table // 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; return result.second;
} }
bool insert(TSymbol &symbol)
{
return insert(symbol.getMangledName(), symbol);
}
TSymbol* find(const TString& name) const TSymbol* find(const TString& name) const
{ {
tLevel::const_iterator it = level.find(name); tLevel::const_iterator it = level.find(name);
...@@ -276,12 +271,12 @@ public: ...@@ -276,12 +271,12 @@ public:
precisionStack.pop_back(); precisionStack.pop_back();
} }
bool declare(TSymbol &symbol) bool declare(TSymbol *symbol)
{ {
return insert(currentLevel(), symbol); return insert(currentLevel(), symbol);
} }
bool insert(ESymbolLevel level, TSymbol &symbol) bool insert(ESymbolLevel level, TSymbol *symbol)
{ {
return table[level]->insert(symbol); return table[level]->insert(symbol);
} }
...@@ -290,7 +285,7 @@ public: ...@@ -290,7 +285,7 @@ public:
{ {
TVariable *constant = new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1)); TVariable *constant = new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
constant->getConstPointer()->setIConst(value); constant->getConstPointer()->setIConst(value);
return insert(level, *constant); return insert(level, constant);
} }
void insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name, TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0, TType *ptype4 = 0, TType *ptype5 = 0) void insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name, TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0, TType *ptype4 = 0, TType *ptype5 = 0)
...@@ -357,7 +352,7 @@ public: ...@@ -357,7 +352,7 @@ public:
function->addParameter(param5); function->addParameter(param5);
} }
insert(level, *function); insert(level, function);
} }
TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = NULL, bool *sameScope = NULL); TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = NULL, bool *sameScope = NULL);
......
...@@ -237,7 +237,7 @@ variable_identifier ...@@ -237,7 +237,7 @@ variable_identifier
{ {
TType type(EbtFloat, EbpUndefined); TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable($1.string, type); TVariable *fakeVariable = new TVariable($1.string, type);
context->symbolTable.declare(*fakeVariable); context->symbolTable.declare(fakeVariable);
variable = fakeVariable; variable = fakeVariable;
} }
...@@ -887,7 +887,8 @@ function_prototype ...@@ -887,7 +887,8 @@ function_prototype
else else
{ {
// Insert the unmangled name to detect potential future redefinition as a variable. // 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 ...@@ -899,7 +900,7 @@ function_prototype
// We're at the inner scope level of the function's arguments and body statement. // We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead. // Add the function prototype to the surrounding scope instead.
context->symbolTable.getOuterLevel()->insert(*$$.function); context->symbolTable.getOuterLevel()->insert($$.function);
} }
; ;
...@@ -1894,7 +1895,7 @@ function_definition ...@@ -1894,7 +1895,7 @@ function_definition
// //
// Insert the parameters with name in the symbol table. // 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->error(@1, "redefinition", variable->getName().c_str());
context->recover(); context->recover();
delete variable; delete variable;
......
...@@ -2575,7 +2575,7 @@ yyreduce: ...@@ -2575,7 +2575,7 @@ yyreduce:
{ {
TType type(EbtFloat, EbpUndefined); TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type); TVariable *fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type);
context->symbolTable.declare(*fakeVariable); context->symbolTable.declare(fakeVariable);
variable = fakeVariable; variable = fakeVariable;
} }
...@@ -3436,7 +3436,8 @@ yyreduce: ...@@ -3436,7 +3436,8 @@ yyreduce:
else else
{ {
// Insert the unmangled name to detect potential future redefinition as a variable. // 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: ...@@ -3448,7 +3449,7 @@ yyreduce:
// We're at the inner scope level of the function's arguments and body statement. // We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead. // Add the function prototype to the surrounding scope instead.
context->symbolTable.getOuterLevel()->insert(*(yyval.interm).function); context->symbolTable.getOuterLevel()->insert((yyval.interm).function);
} }
break; break;
...@@ -4962,7 +4963,7 @@ yyreduce: ...@@ -4962,7 +4963,7 @@ yyreduce:
// //
// Insert the parameters with name in the symbol table. // 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->error((yylsp[(1) - (1)]), "redefinition", variable->getName().c_str());
context->recover(); context->recover();
delete variable; 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