HLSL: non-static member functions: track and find active anonymous 'this' scopes and members.
Thanks to @steve-lunarg for his input and discussions on handling member functions.
This commit is contained in:
@@ -603,7 +603,8 @@ int HlslParseContext::getMatrixComponentsColumn(int rows, const TSwizzleSelector
|
||||
//
|
||||
TIntermTyped* HlslParseContext::handleVariable(const TSourceLoc& loc, const TString* string)
|
||||
{
|
||||
TSymbol* symbol = symbolTable.find(*string);
|
||||
int thisDepth;
|
||||
TSymbol* symbol = symbolTable.find(*string, thisDepth);
|
||||
if (symbol && symbol->getAsVariable() && symbol->getAsVariable()->isUserType()) {
|
||||
error(loc, "expected symbol, not user-defined type", string->c_str(), "");
|
||||
return nullptr;
|
||||
@@ -613,14 +614,21 @@ TIntermTyped* HlslParseContext::handleVariable(const TSourceLoc& loc, const TStr
|
||||
if (symbol && symbol->getNumExtensions())
|
||||
requireExtensions(loc, symbol->getNumExtensions(), symbol->getExtensions(), symbol->getName().c_str());
|
||||
|
||||
const TVariable* variable;
|
||||
const TVariable* variable = nullptr;
|
||||
const TAnonMember* anon = symbol ? symbol->getAsAnonMember() : nullptr;
|
||||
TIntermTyped* node = nullptr;
|
||||
if (anon) {
|
||||
// It was a member of an anonymous container.
|
||||
// It was a member of an anonymous container, which could be a 'this' structure.
|
||||
|
||||
// Create a subtree for its dereference.
|
||||
variable = anon->getAnonContainer().getAsVariable();
|
||||
if (thisDepth > 0) {
|
||||
variable = getImplicitThis(thisDepth);
|
||||
if (variable == nullptr)
|
||||
error(loc, "cannot access member variables (static member function?)", "this", "");
|
||||
}
|
||||
if (variable == nullptr)
|
||||
variable = anon->getAnonContainer().getAsVariable();
|
||||
|
||||
TIntermTyped* container = intermediate.addSymbol(*variable, loc);
|
||||
TIntermTyped* constNode = intermediate.addConstantUnion(anon->getMemberNumber(), loc);
|
||||
node = intermediate.addIndex(EOpIndexDirectStruct, container, constNode, loc);
|
||||
@@ -1529,18 +1537,25 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
|
||||
if (param.name != nullptr) {
|
||||
TVariable *variable = new TVariable(param.name, *param.type);
|
||||
|
||||
// Insert the parameters with name in the symbol table.
|
||||
if (! symbolTable.insert(*variable))
|
||||
error(loc, "redefinition", variable->getName().c_str(), "");
|
||||
else {
|
||||
// Add the parameter to the AST
|
||||
paramNodes = intermediate.growAggregate(paramNodes,
|
||||
intermediate.addSymbol(*variable, loc),
|
||||
loc);
|
||||
if (i == 0 && function.hasImplicitThis()) {
|
||||
// 'this' members are already in a symbol-table level,
|
||||
// and we need to know what function parameter to map them to
|
||||
symbolTable.makeInternalVariable(*variable);
|
||||
pushImplicitThis(variable);
|
||||
} else {
|
||||
// Insert the parameters with name in the symbol table.
|
||||
if (! symbolTable.insert(*variable))
|
||||
error(loc, "redefinition", variable->getName().c_str(), "");
|
||||
}
|
||||
// Add the parameter to the AST
|
||||
paramNodes = intermediate.growAggregate(paramNodes,
|
||||
intermediate.addSymbol(*variable, loc),
|
||||
loc);
|
||||
} else
|
||||
paramNodes = intermediate.growAggregate(paramNodes, intermediate.addSymbol(*param.type, loc), loc);
|
||||
}
|
||||
if (function.hasIllegalImplicitThis())
|
||||
pushImplicitThis(nullptr);
|
||||
|
||||
intermediate.setAggregateOperator(paramNodes, EOpParameters, TType(EbtVoid), loc);
|
||||
loopNestingLevel = 0;
|
||||
@@ -1826,6 +1841,8 @@ void HlslParseContext::handleFunctionBody(const TSourceLoc& loc, TFunction& func
|
||||
node->getAsAggregate()->setName(function.getMangledName().c_str());
|
||||
|
||||
popScope();
|
||||
if (function.hasImplicitThis())
|
||||
popImplicitThis();
|
||||
|
||||
if (function.getType().getBasicType() != EbtVoid && ! functionReturnsValue)
|
||||
error(loc, "function does not return a value:", "", function.getName().c_str());
|
||||
@@ -7087,6 +7104,15 @@ TIntermNode* HlslParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* ex
|
||||
return switchNode;
|
||||
}
|
||||
|
||||
// Make a new symbol-table level that is made out of the members of a structure.
|
||||
// This should be done as an anonymous struct (name is "") so that the symbol table
|
||||
// finds the members with on explicit reference to a 'this' variable.
|
||||
void HlslParseContext::pushThisScope(const TType& thisStruct)
|
||||
{
|
||||
TVariable& thisVariable = *new TVariable(NewPoolTString(""), thisStruct);
|
||||
symbolTable.pushThis(thisVariable);
|
||||
}
|
||||
|
||||
// Track levels of class/struct/namespace nesting with a prefix string using
|
||||
// the type names separated by the scoping operator. E.g., two levels
|
||||
// would look like:
|
||||
|
||||
Reference in New Issue
Block a user