HLSL: use prefix for builtin functions names to avoid namespace collisions

It would have been possible for globally scoped user functions to collide
with builtin method names.  This adds a prefix to avoid polluting the
namespace.

Ideally this would be an invalid character to use in user identifiers, but
as that requires changing the scanner, for the moment it's an unlikely yet
valid prefix.
This commit is contained in:
steve-lunarg
2017-03-19 18:12:37 -06:00
parent 4960baaf66
commit e7d0752a33
4 changed files with 331 additions and 302 deletions

View File

@@ -956,7 +956,7 @@ TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TInt
// Return true if the field should be treated as a built-in method.
// Return false otherwise.
//
bool HlslParseContext::isBuiltInMethod(const TSourceLoc& loc, TIntermTyped* base, const TString& field)
bool HlslParseContext::isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field)
{
if (base == nullptr)
return false;
@@ -3734,7 +3734,10 @@ TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunct
// It will have false positives, since it doesn't check arg counts or types.
if (arguments && arguments->getAsAggregate()) {
if (isStructBufferType(arguments->getAsAggregate()->getSequence()[0]->getAsTyped()->getType())) {
if (isStructBufferMethod(function->getName())) {
static const int methodPrefixSize = sizeof(BUILTIN_PREFIX)-1;
if (function->getName().length() > methodPrefixSize &&
isStructBufferMethod(function->getName().substr(methodPrefixSize))) {
const TString mangle = function->getName() + "(";
TSymbol* symbol = symbolTable.find(mangle, &builtIn);