From dfbdd9eb20985fa292b8e5206ce4de7457d58501 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sun, 19 Mar 2017 13:10:28 -0600 Subject: [PATCH] HLSL: Add implicit-this tracking to TFunction. --- glslang/Include/Types.h | 4 ++-- glslang/MachineIndependent/SymbolTable.cpp | 3 ++- glslang/MachineIndependent/SymbolTable.h | 20 ++++++++++++++++++-- hlsl/hlslGrammar.cpp | 4 +++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/glslang/Include/Types.h b/glslang/Include/Types.h index f2b786eb..2207d0b3 100644 --- a/glslang/Include/Types.h +++ b/glslang/Include/Types.h @@ -1802,7 +1802,7 @@ public: } // append this type's mangled name to the passed in 'name' - void appendMangledName(TString& name) + void appendMangledName(TString& name) const { buildMangledName(name); name += ';' ; @@ -1926,7 +1926,7 @@ protected: } - void buildMangledName(TString&); + void buildMangledName(TString&) const; TBasicType basicType : 8; int vectorSize : 4; // 1 means either scalar or 1-component vector; see vector1 to disambiguate. diff --git a/glslang/MachineIndependent/SymbolTable.cpp b/glslang/MachineIndependent/SymbolTable.cpp index bed60fe7..d0033e8b 100644 --- a/glslang/MachineIndependent/SymbolTable.cpp +++ b/glslang/MachineIndependent/SymbolTable.cpp @@ -50,7 +50,7 @@ namespace glslang { // // Recursively generate mangled names. // -void TType::buildMangledName(TString& mangledName) +void TType::buildMangledName(TString& mangledName) const { if (isMatrix()) mangledName += 'm'; @@ -299,6 +299,7 @@ TFunction::TFunction(const TFunction& copyOf) : TSymbol(copyOf) op = copyOf.op; defined = copyOf.defined; prototyped = copyOf.prototyped; + implicitThis = copyOf.implicitThis; defaultParamCount = copyOf.defaultParamCount; } diff --git a/glslang/MachineIndependent/SymbolTable.h b/glslang/MachineIndependent/SymbolTable.h index c85b0676..af78a04b 100644 --- a/glslang/MachineIndependent/SymbolTable.h +++ b/glslang/MachineIndependent/SymbolTable.h @@ -219,12 +219,12 @@ public: explicit TFunction(TOperator o) : TSymbol(0), op(o), - defined(false), prototyped(false), defaultParamCount(0) { } + defined(false), prototyped(false), implicitThis(false), defaultParamCount(0) { } TFunction(const TString *name, const TType& retType, TOperator tOp = EOpNull) : TSymbol(name), mangledName(*name + '('), op(tOp), - defined(false), prototyped(false), defaultParamCount(0) + defined(false), prototyped(false), implicitThis(false), defaultParamCount(0) { returnType.shallowCopy(retType); declaredBuiltIn = retType.getQualifier().builtIn; @@ -235,6 +235,9 @@ public: virtual TFunction* getAsFunction() override { return this; } virtual const TFunction* getAsFunction() const override { return this; } + // Install 'p' as the (non-'this') last parameter. + // Non-'this' parameters are reflected in both the list of parameters and the + // mangled name. virtual void addParameter(TParameter& p) { assert(writable); @@ -245,6 +248,16 @@ public: if (p.defaultValue != nullptr) defaultParamCount++; } + + // Install 'this' as the first parameter. + // 'this' is reflected in the list of parameters, but not the mangled name. + virtual void addThisParameter(TType& type) + { + TParameter p = { NewPoolTString("this"), new TType, nullptr }; + p.type->shallowCopy(type); + parameters.insert(parameters.begin(), p); + } + virtual void addPrefix(const char* prefix) override { TSymbol::addPrefix(prefix); @@ -261,6 +274,8 @@ public: virtual bool isDefined() const { return defined; } virtual void setPrototyped() { assert(writable); prototyped = true; } virtual bool isPrototyped() const { return prototyped; } + virtual void setImplicitThis() { assert(writable); implicitThis = true; } + virtual bool hasImplicitThis() const { return implicitThis; } // Return total number of parameters virtual int getParamCount() const { return static_cast(parameters.size()); } @@ -287,6 +302,7 @@ protected: TOperator op; bool defined; bool prototyped; + bool implicitThis; int defaultParamCount; }; diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index be58dbc0..67216684 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -2794,8 +2794,10 @@ bool HlslGrammar::acceptFunctionCall(HlslToken callToken, TIntermTyped*& node, T // arguments TIntermTyped* arguments = nullptr; - if (baseObject != nullptr) + if (baseObject != nullptr) { + // Non-static member functions have an implicit first argument of the base object. parseContext.handleFunctionArgument(function, arguments, baseObject); + } if (! acceptArguments(function, arguments)) return false;