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

@ -2785,11 +2785,13 @@ bool HlslGrammar::acceptFunctionCall(HlslToken callToken, TIntermTyped*& node, T
{
// name
TString* functionName = nullptr;
if ((baseObject == nullptr && scope == nullptr) ||
parseContext.isBuiltInMethod(callToken.loc, baseObject, *callToken.string)) {
if ((baseObject == nullptr && scope == nullptr)) {
functionName = callToken.string;
} else if (parseContext.isBuiltInMethod(callToken.loc, baseObject, *callToken.string)) {
// Built-in methods are not in the symbol table as methods, but as global functions
// taking an explicit 'this' as the first argument.
functionName = callToken.string;
functionName = NewPoolTString(BUILTIN_PREFIX);
functionName->append(*callToken.string);
} else {
functionName = NewPoolTString("");
if (baseObject != nullptr)