Commit 54a29ffd by Olli Etuaho Committed by Commit Bot

Refactor TSymbol to follow naming conventions

This will make it easier to make TStructure inherit from TSymbol. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I73a5a25234c7f965b6970891821ee9d6f0a23aca Reviewed-on: https://chromium-review.googlesource.com/793812Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent ae04e1e4
...@@ -567,7 +567,7 @@ TIntermConstantUnion::TIntermConstantUnion(const TIntermConstantUnion &node) : T ...@@ -567,7 +567,7 @@ TIntermConstantUnion::TIntermConstantUnion(const TIntermConstantUnion &node) : T
void TFunctionSymbolInfo::setFromFunction(const TFunction &function) void TFunctionSymbolInfo::setFromFunction(const TFunction &function)
{ {
setName(function.getName()); setName(function.name());
setId(TSymbolUniqueId(function)); setId(TSymbolUniqueId(function));
} }
......
...@@ -219,7 +219,7 @@ TIntermSymbol *ReferenceGlobalVariable(const TString &name, const TSymbolTable & ...@@ -219,7 +219,7 @@ TIntermSymbol *ReferenceGlobalVariable(const TString &name, const TSymbolTable &
{ {
TVariable *var = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name)); TVariable *var = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name));
ASSERT(var); ASSERT(var);
return new TIntermSymbol(var->getUniqueId(), name, var->getType()); return new TIntermSymbol(var->uniqueId(), name, var->getType());
} }
TIntermSymbol *ReferenceBuiltInVariable(const TString &name, TIntermSymbol *ReferenceBuiltInVariable(const TString &name,
...@@ -229,7 +229,7 @@ TIntermSymbol *ReferenceBuiltInVariable(const TString &name, ...@@ -229,7 +229,7 @@ TIntermSymbol *ReferenceBuiltInVariable(const TString &name,
const TVariable *var = const TVariable *var =
reinterpret_cast<const TVariable *>(symbolTable.findBuiltIn(name, shaderVersion, true)); reinterpret_cast<const TVariable *>(symbolTable.findBuiltIn(name, shaderVersion, true));
ASSERT(var); ASSERT(var);
return new TIntermSymbol(var->getUniqueId(), name, var->getType()); return new TIntermSymbol(var->uniqueId(), name, var->getType());
} }
TIntermTyped *CreateBuiltInFunctionCallNode(const TString &name, TIntermTyped *CreateBuiltInFunctionCallNode(const TString &name,
......
...@@ -1125,7 +1125,7 @@ bool TParseContext::declareVariable(const TSourceLoc &line, ...@@ -1125,7 +1125,7 @@ bool TParseContext::declareVariable(const TSourceLoc &line,
{ {
if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, mShaderVersion)) if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, mShaderVersion))
{ {
needsReservedCheck = !checkCanUseExtension(line, builtInSymbol->getExtension()); needsReservedCheck = !checkCanUseExtension(line, builtInSymbol->extension());
} }
} }
else else
...@@ -1805,9 +1805,9 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location, ...@@ -1805,9 +1805,9 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
const TVariable *variable = static_cast<const TVariable *>(symbol); const TVariable *variable = static_cast<const TVariable *>(symbol);
if (variable->getExtension() != TExtension::UNDEFINED) if (variable->extension() != TExtension::UNDEFINED)
{ {
checkCanUseExtension(location, variable->getExtension()); checkCanUseExtension(location, variable->extension());
} }
// Reject shaders using both gl_FragData and gl_FragColor // Reject shaders using both gl_FragData and gl_FragColor
...@@ -1896,12 +1896,12 @@ TIntermTyped *TParseContext::parseVariableIdentifier(const TSourceLoc &location, ...@@ -1896,12 +1896,12 @@ TIntermTyped *TParseContext::parseVariableIdentifier(const TSourceLoc &location,
{ {
ASSERT(mGeometryShaderInputArraySize > 0u); ASSERT(mGeometryShaderInputArraySize > 0u);
node = new TIntermSymbol(variable->getUniqueId(), variable->getName(), variableType); node = new TIntermSymbol(variable->uniqueId(), variable->name(), variableType);
node->getTypePointer()->sizeOutermostUnsizedArray(mGeometryShaderInputArraySize); node->getTypePointer()->sizeOutermostUnsizedArray(mGeometryShaderInputArraySize);
} }
else else
{ {
node = new TIntermSymbol(variable->getUniqueId(), variable->getName(), variableType); node = new TIntermSymbol(variable->uniqueId(), variable->name(), variableType);
} }
ASSERT(node != nullptr); ASSERT(node != nullptr);
node->setLine(location); node->setLine(location);
...@@ -2016,7 +2016,7 @@ bool TParseContext::executeInitializer(const TSourceLoc &line, ...@@ -2016,7 +2016,7 @@ bool TParseContext::executeInitializer(const TSourceLoc &line,
} }
TIntermSymbol *intermSymbol = TIntermSymbol *intermSymbol =
new TIntermSymbol(variable->getUniqueId(), variable->getName(), variable->getType()); new TIntermSymbol(variable->uniqueId(), variable->name(), variable->getType());
intermSymbol->setLine(line); intermSymbol->setLine(line);
*initNode = createAssign(EOpInitialize, intermSymbol, initializer, line); *initNode = createAssign(EOpInitialize, intermSymbol, initializer, line);
if (*initNode == nullptr) if (*initNode == nullptr)
...@@ -2470,7 +2470,7 @@ TIntermDeclaration *TParseContext::parseSingleDeclaration( ...@@ -2470,7 +2470,7 @@ TIntermDeclaration *TParseContext::parseSingleDeclaration(
if (variable) if (variable)
{ {
symbol = new TIntermSymbol(variable->getUniqueId(), identifier, type); symbol = new TIntermSymbol(variable->uniqueId(), identifier, type);
} }
} }
...@@ -2517,7 +2517,7 @@ TIntermDeclaration *TParseContext::parseSingleArrayDeclaration( ...@@ -2517,7 +2517,7 @@ TIntermDeclaration *TParseContext::parseSingleArrayDeclaration(
if (variable) if (variable)
{ {
TIntermSymbol *symbol = new TIntermSymbol(variable->getUniqueId(), identifier, arrayType); TIntermSymbol *symbol = new TIntermSymbol(variable->uniqueId(), identifier, arrayType);
symbol->setLine(identifierLocation); symbol->setLine(identifierLocation);
declaration->appendDeclarator(symbol); declaration->appendDeclarator(symbol);
} }
...@@ -2640,7 +2640,7 @@ TIntermInvariantDeclaration *TParseContext::parseInvariantDeclaration( ...@@ -2640,7 +2640,7 @@ TIntermInvariantDeclaration *TParseContext::parseInvariantDeclaration(
symbolTable.addInvariantVarying(std::string(identifier->c_str())); symbolTable.addInvariantVarying(std::string(identifier->c_str()));
TIntermSymbol *intermSymbol = new TIntermSymbol(variable->getUniqueId(), *identifier, type); TIntermSymbol *intermSymbol = new TIntermSymbol(variable->uniqueId(), *identifier, type);
intermSymbol->setLine(identifierLoc); intermSymbol->setLine(identifierLoc);
return new TIntermInvariantDeclaration(intermSymbol, identifierLoc); return new TIntermInvariantDeclaration(intermSymbol, identifierLoc);
...@@ -2674,7 +2674,7 @@ void TParseContext::parseDeclarator(TPublicType &publicType, ...@@ -2674,7 +2674,7 @@ void TParseContext::parseDeclarator(TPublicType &publicType,
if (variable) if (variable)
{ {
TIntermSymbol *symbol = new TIntermSymbol(variable->getUniqueId(), identifier, type); TIntermSymbol *symbol = new TIntermSymbol(variable->uniqueId(), identifier, type);
symbol->setLine(identifierLocation); symbol->setLine(identifierLocation);
declarationOut->appendDeclarator(symbol); declarationOut->appendDeclarator(symbol);
} }
...@@ -2713,8 +2713,7 @@ void TParseContext::parseArrayDeclarator(TPublicType &elementType, ...@@ -2713,8 +2713,7 @@ void TParseContext::parseArrayDeclarator(TPublicType &elementType,
if (variable) if (variable)
{ {
TIntermSymbol *symbol = TIntermSymbol *symbol = new TIntermSymbol(variable->uniqueId(), identifier, arrayType);
new TIntermSymbol(variable->getUniqueId(), identifier, arrayType);
symbol->setLine(identifierLocation); symbol->setLine(identifierLocation);
declarationOut->appendDeclarator(symbol); declarationOut->appendDeclarator(symbol);
} }
...@@ -3166,7 +3165,7 @@ TIntermFunctionPrototype *TParseContext::createPrototypeNodeFromFunction( ...@@ -3166,7 +3165,7 @@ TIntermFunctionPrototype *TParseContext::createPrototypeNodeFromFunction(
const TSourceLoc &location, const TSourceLoc &location,
bool insertParametersToSymbolTable) bool insertParametersToSymbolTable)
{ {
checkIsNotReserved(location, function.getName()); checkIsNotReserved(location, function.name());
TIntermFunctionPrototype *prototype = TIntermFunctionPrototype *prototype =
new TIntermFunctionPrototype(function.getReturnType(), TSymbolUniqueId(function)); new TIntermFunctionPrototype(function.getReturnType(), TSymbolUniqueId(function));
...@@ -3191,7 +3190,7 @@ TIntermFunctionPrototype *TParseContext::createPrototypeNodeFromFunction( ...@@ -3191,7 +3190,7 @@ TIntermFunctionPrototype *TParseContext::createPrototypeNodeFromFunction(
TVariable *variable = symbolTable.declareVariable(param.name, *param.type); TVariable *variable = symbolTable.declareVariable(param.name, *param.type);
if (variable) if (variable)
{ {
symbol = new TIntermSymbol(variable->getUniqueId(), variable->getName(), symbol = new TIntermSymbol(variable->uniqueId(), variable->name(),
variable->getType()); variable->getType());
} }
else else
...@@ -3290,7 +3289,7 @@ void TParseContext::parseFunctionDefinitionHeader(const TSourceLoc &location, ...@@ -3290,7 +3289,7 @@ void TParseContext::parseFunctionDefinitionHeader(const TSourceLoc &location,
if (builtIn) if (builtIn)
{ {
error(location, "built-in functions cannot be redefined", (*function)->getName().c_str()); error(location, "built-in functions cannot be redefined", (*function)->name().c_str());
} }
else else
{ {
...@@ -3312,7 +3311,7 @@ void TParseContext::parseFunctionDefinitionHeader(const TSourceLoc &location, ...@@ -3312,7 +3311,7 @@ void TParseContext::parseFunctionDefinitionHeader(const TSourceLoc &location,
if ((*function)->isDefined()) if ((*function)->isDefined())
{ {
error(location, "function already has a body", (*function)->getName().c_str()); error(location, "function already has a body", (*function)->name().c_str());
} }
(*function)->setDefined(); (*function)->setDefined();
...@@ -3346,18 +3345,17 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF ...@@ -3346,18 +3345,17 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
{ {
// ESSL 3.00.6 section 12.10. // ESSL 3.00.6 section 12.10.
error(location, "Function parameter type cannot be a structure definition", error(location, "Function parameter type cannot be a structure definition",
function->getName().c_str()); function->name().c_str());
} }
} }
if (getShaderVersion() >= 300 && if (getShaderVersion() >= 300 && symbolTable.hasUnmangledBuiltInForShaderVersion(
symbolTable.hasUnmangledBuiltInForShaderVersion(function->getName().c_str(), function->name().c_str(), getShaderVersion()))
getShaderVersion()))
{ {
// With ESSL 3.00 and above, names of built-in functions cannot be redeclared as functions. // With ESSL 3.00 and above, names of built-in functions cannot be redeclared as functions.
// Therefore overloading or redefining builtin functions is an error. // Therefore overloading or redefining builtin functions is an error.
error(location, "Name of a built-in function cannot be redeclared as function", error(location, "Name of a built-in function cannot be redeclared as function",
function->getName().c_str()); function->name().c_str());
} }
else if (prevDec) else if (prevDec)
{ {
...@@ -3381,12 +3379,12 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF ...@@ -3381,12 +3379,12 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
// //
// Check for previously declared variables using the same name. // Check for previously declared variables using the same name.
// //
TSymbol *prevSym = symbolTable.find(function->getName(), getShaderVersion()); TSymbol *prevSym = symbolTable.find(function->name(), getShaderVersion());
if (prevSym) if (prevSym)
{ {
if (!prevSym->isFunction()) if (!prevSym->isFunction())
{ {
error(location, "redefinition of a function", function->getName().c_str()); error(location, "redefinition of a function", function->name().c_str());
} }
} }
else else
...@@ -3400,7 +3398,7 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF ...@@ -3400,7 +3398,7 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
symbolTable.getOuterLevel()->insert(function); symbolTable.getOuterLevel()->insert(function);
// Raise error message if main function takes any parameters or return anything other than void // Raise error message if main function takes any parameters or return anything other than void
if (function->getName() == "main") if (function->name() == "main")
{ {
if (function->getParamCount() > 0) if (function->getParamCount() > 0)
{ {
...@@ -3859,7 +3857,7 @@ TIntermDeclaration *TParseContext::addInterfaceBlock( ...@@ -3859,7 +3857,7 @@ TIntermDeclaration *TParseContext::addInterfaceBlock(
if (instanceTypeDef) if (instanceTypeDef)
{ {
instanceTypeDef->setQualifier(typeQualifier.qualifier); instanceTypeDef->setQualifier(typeQualifier.qualifier);
symbolId = &instanceTypeDef->getUniqueId(); symbolId = &instanceTypeDef->uniqueId();
} }
else else
{ {
...@@ -5802,9 +5800,9 @@ TIntermTyped *TParseContext::addMethod(TFunction *fnCall, ...@@ -5802,9 +5800,9 @@ TIntermTyped *TParseContext::addMethod(TFunction *fnCall,
// a constructor. But such a TFunction can't reach here, since the lexer goes into FIELDS // a constructor. But such a TFunction can't reach here, since the lexer goes into FIELDS
// mode after a dot, which makes type identifiers to be parsed as FIELD_SELECTION instead. // mode after a dot, which makes type identifiers to be parsed as FIELD_SELECTION instead.
// So accessing fnCall->getName() below is safe. // So accessing fnCall->getName() below is safe.
if (fnCall->getName() != "length") if (fnCall->name() != "length")
{ {
error(loc, "invalid method", fnCall->getName().c_str()); error(loc, "invalid method", fnCall->name().c_str());
} }
else if (!arguments->empty()) else if (!arguments->empty())
{ {
...@@ -5837,18 +5835,18 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunction *fnCall, ...@@ -5837,18 +5835,18 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunction *fnCall,
// hidden by a variable name or struct typename. // hidden by a variable name or struct typename.
// If a function is found, check for one with a matching argument list. // If a function is found, check for one with a matching argument list.
bool builtIn; bool builtIn;
const TSymbol *symbol = symbolTable.find(fnCall->getName(), mShaderVersion, &builtIn); const TSymbol *symbol = symbolTable.find(fnCall->name(), mShaderVersion, &builtIn);
if (symbol != nullptr && !symbol->isFunction()) if (symbol != nullptr && !symbol->isFunction())
{ {
error(loc, "function name expected", fnCall->getName().c_str()); error(loc, "function name expected", fnCall->name().c_str());
} }
else else
{ {
symbol = symbolTable.find(TFunction::GetMangledNameFromCall(fnCall->getName(), *arguments), symbol = symbolTable.find(TFunction::GetMangledNameFromCall(fnCall->name(), *arguments),
mShaderVersion, &builtIn); mShaderVersion, &builtIn);
if (symbol == nullptr) if (symbol == nullptr)
{ {
error(loc, "no matching overloaded function found", fnCall->getName().c_str()); error(loc, "no matching overloaded function found", fnCall->name().c_str());
} }
else else
{ {
...@@ -5856,9 +5854,9 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunction *fnCall, ...@@ -5856,9 +5854,9 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunction *fnCall,
// //
// A declared function. // A declared function.
// //
if (builtIn && fnCandidate->getExtension() != TExtension::UNDEFINED) if (builtIn && fnCandidate->extension() != TExtension::UNDEFINED)
{ {
checkCanUseExtension(loc, fnCandidate->getExtension()); checkCanUseExtension(loc, fnCandidate->extension());
} }
TOperator op = fnCandidate->getBuiltInOp(); TOperator op = fnCandidate->getBuiltInOp();
if (builtIn && op != EOpNull) if (builtIn && op != EOpNull)
......
...@@ -29,8 +29,8 @@ static const char kFunctionMangledNameSeparator = '('; ...@@ -29,8 +29,8 @@ static const char kFunctionMangledNameSeparator = '(';
} // anonymous namespace } // anonymous namespace
TSymbol::TSymbol(TSymbolTable *symbolTable, const TString *n) TSymbol::TSymbol(TSymbolTable *symbolTable, const TString *name)
: uniqueId(symbolTable->nextUniqueId()), name(n), extension(TExtension::UNDEFINED) : mUniqueId(symbolTable->nextUniqueId()), mName(name), mExtension(TExtension::UNDEFINED)
{ {
} }
...@@ -61,7 +61,7 @@ void TFunction::swapParameters(const TFunction &parametersSource) ...@@ -61,7 +61,7 @@ void TFunction::swapParameters(const TFunction &parametersSource)
const TString *TFunction::buildMangledName() const const TString *TFunction::buildMangledName() const
{ {
std::string newName = getName().c_str(); std::string newName = name().c_str();
newName += kFunctionMangledNameSeparator; newName += kFunctionMangledNameSeparator;
for (const auto &p : parameters) for (const auto &p : parameters)
...@@ -104,7 +104,7 @@ bool TSymbolTableLevel::insert(TSymbol *symbol) ...@@ -104,7 +104,7 @@ bool TSymbolTableLevel::insert(TSymbol *symbol)
bool TSymbolTableLevel::insertUnmangled(TFunction *function) bool TSymbolTableLevel::insertUnmangled(TFunction *function)
{ {
// returning true means symbol was added to the table // returning true means symbol was added to the table
tInsertResult result = level.insert(tLevelPair(function->getName(), function)); tInsertResult result = level.insert(tLevelPair(function->name(), function));
return result.second; return result.second;
} }
......
...@@ -48,25 +48,25 @@ class TSymbol : angle::NonCopyable ...@@ -48,25 +48,25 @@ class TSymbol : angle::NonCopyable
{ {
public: public:
POOL_ALLOCATOR_NEW_DELETE(); POOL_ALLOCATOR_NEW_DELETE();
TSymbol(TSymbolTable *symbolTable, const TString *n); TSymbol(TSymbolTable *symbolTable, const TString *name);
virtual ~TSymbol() virtual ~TSymbol()
{ {
// don't delete name, it's from the pool // don't delete name, it's from the pool
} }
const TString &getName() const { return *name; } const TString &name() const { return *mName; }
virtual const TString &getMangledName() const { return getName(); } virtual const TString &getMangledName() const { return name(); }
virtual bool isFunction() const { return false; } virtual bool isFunction() const { return false; }
virtual bool isVariable() const { return false; } virtual bool isVariable() const { return false; }
const TSymbolUniqueId &getUniqueId() const { return uniqueId; } const TSymbolUniqueId &uniqueId() const { return mUniqueId; }
void relateToExtension(TExtension ext) { extension = ext; } void relateToExtension(TExtension ext) { mExtension = ext; }
TExtension getExtension() const { return extension; } TExtension extension() const { return mExtension; }
private: private:
const TSymbolUniqueId uniqueId; const TSymbolUniqueId mUniqueId;
const TString *name; const TString *mName;
TExtension extension; TExtension mExtension;
}; };
// Variable, meaning a symbol that's not a function. // Variable, meaning a symbol that's not a function.
......
...@@ -16,7 +16,7 @@ TSymbolUniqueId::TSymbolUniqueId(TSymbolTable *symbolTable) : mId(symbolTable->n ...@@ -16,7 +16,7 @@ TSymbolUniqueId::TSymbolUniqueId(TSymbolTable *symbolTable) : mId(symbolTable->n
{ {
} }
TSymbolUniqueId::TSymbolUniqueId(const TSymbol &symbol) : mId(symbol.getUniqueId().get()) TSymbolUniqueId::TSymbolUniqueId(const TSymbol &symbol) : mId(symbol.uniqueId().get())
{ {
} }
......
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