HLSL non-functional: Generalize namespace nesting.

Also use this to move deferred member-function-body parsing to a better
place.

This should also be well poised for implementing the 'namespace' keyword.
This commit is contained in:
John Kessenich
2017-03-19 12:24:29 -06:00
parent e751bca75c
commit f3d88bd498
7 changed files with 64 additions and 60 deletions

View File

@@ -7085,7 +7085,7 @@ TIntermNode* HlslParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* ex
return switchNode;
}
// Track levels of class/struct nesting with a prefix string using
// 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:
//
@@ -7093,41 +7093,43 @@ TIntermNode* HlslParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* ex
//
// The string is empty when at normal global level.
//
void HlslParseContext::pushThis(const TString& typeName)
void HlslParseContext::pushNamespace(const TString& typeName)
{
// make new type prefix
TString newPrefix;
if (currentTypePrefix.size() > 0) {
newPrefix = currentTypePrefix.back();
newPrefix.append("::");
newPrefix.append(scopeMangler);
}
newPrefix.append(typeName);
currentTypePrefix.push_back(newPrefix);
}
// Opposite of pushThis(), see above
void HlslParseContext::popThis()
// Opposite of pushNamespace(), see above
void HlslParseContext::popNamespace()
{
currentTypePrefix.pop_back();
}
// Use the class/struct nesting string to create a global name for
// a member of a class/struct. Static members use "::" for the final
// step, while non-static members use ".".
TString* HlslParseContext::getFullMemberFunctionName(const TString& memberName, bool isStatic) const
// a member of a class/struct.
TString* HlslParseContext::getFullNamespaceName(const TString& localName) const
{
TString* name = NewPoolTString("");
if (currentTypePrefix.size() > 0)
name->append(currentTypePrefix.back());
if (isStatic)
name->append("::");
else
name->append(".");
name->append(memberName);
name->append(scopeMangler);
name->append(localName);
return name;
}
// Helper function to add the namespace scope mangling syntax to a string.
void HlslParseContext::addScopeMangler(TString& name)
{
name.append(scopeMangler);
}
// Potentially rename shader entry point function
void HlslParseContext::renameShaderFunction(TString*& name) const
{