From 5f12d2f7527f8d4e4cffe6fa8eb0c837edb2ff33 Mon Sep 17 00:00:00 2001 From: John Kessenich <cepheus@frii.com> Date: Sat, 11 Mar 2017 09:39:55 -0700 Subject: [PATCH] HLSL: non-functional: simplify handleBuiltInMethod() to isBuiltInMethod(). --- glslang/Include/revision.h | 4 +-- hlsl/hlslGrammar.cpp | 20 ++++++------ hlsl/hlslParseHelper.cpp | 63 ++++++-------------------------------- hlsl/hlslParseHelper.h | 3 +- 4 files changed, 23 insertions(+), 67 deletions(-) diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 0dd0fe34e..e8acb4b41 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1897" -#define GLSLANG_DATE "10-Mar-2017" +#define GLSLANG_REVISION "Overload400-PrecQual.1899" +#define GLSLANG_DATE "11-Mar-2017" diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index fd88c619c..89cb89824 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -2581,11 +2581,6 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node) if (peekTokenClass(EHTokLeftParen)) { // member function TIntermTyped* thisNode = node; - node = parseContext.handleBuiltInMethod(field.loc, node, *field.string); - if (node == nullptr) { - expected("built-in method"); - return false; - } // arguments if (! acceptFunctionCall(field, node, thisNode)) { @@ -2660,20 +2655,25 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node) // function_call // : [idToken] arguments // -bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*& node, TIntermTyped* base) +bool HlslGrammar::acceptFunctionCall(HlslToken callToken, TIntermTyped*& node, TIntermTyped* base) { // arguments - TFunction* function = new TFunction(idToken.string, TType(EbtVoid)); + TFunction* function = new TFunction(callToken.string, TType(EbtVoid)); TIntermTyped* arguments = nullptr; - // methods have an implicit first argument of the calling object. - if (base != nullptr) + // member functions have an implicit first argument of the calling object. + if (base != nullptr) { + if (! parseContext.isBuiltInMethod(callToken.loc, node, *callToken.string)) { + expected("built-in method"); + return false; + } parseContext.handleFunctionArgument(function, arguments, base); + } if (! acceptArguments(function, arguments)) return false; - node = parseContext.handleFunctionCall(idToken.loc, function, arguments); + node = parseContext.handleFunctionCall(callToken.loc, function, arguments); return true; } diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 0d87109d8..a29d1b91a 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -805,36 +805,6 @@ TIntermTyped* HlslParseContext::handleUnaryMath(const TSourceLoc& loc, const cha return childNode; } - -// -// Return true if the name is a sampler method -// -bool HlslParseContext::isSamplerMethod(const TString& name) const -{ - return - name == "CalculateLevelOfDetail" || - name == "CalculateLevelOfDetailUnclamped" || - name == "Gather" || - name == "GatherRed" || - name == "GatherGreen" || - name == "GatherBlue" || - name == "GatherAlpha" || - name == "GatherCmp" || - name == "GatherCmpRed" || - name == "GatherCmpGreen" || - name == "GatherCmpBlue" || - name == "GatherCmpAlpha" || - name == "GetDimensions" || - name == "GetSamplePosition" || - name == "Load" || - name == "Sample" || - name == "SampleBias" || - name == "SampleCmp" || - name == "SampleCmpLevelZero" || - name == "SampleGrad" || - name == "SampleLevel"; -} - // // Return true if the name is a struct buffer method // @@ -983,37 +953,24 @@ TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TInt } // -// Handle seeing a base.field dereference in the grammar, where 'field' is a -// built-in method name. -// -// Return nullptr if 'field' is not a built-in method. +// Return true if the field should be treated as a built-in method. +// Return false otherwise. // -TIntermTyped* HlslParseContext::handleBuiltInMethod(const TSourceLoc& loc, TIntermTyped* base, const TString& field) +bool HlslParseContext::isBuiltInMethod(const TSourceLoc& loc, TIntermTyped* base, const TString& field) { variableCheck(base); - // - // Methods can't be resolved until we finish seeing the function-calling syntax. - // Save away the name in the AST for now. - // - if (isSamplerMethod(field) && base->getType().getBasicType() == EbtSampler) { - // If it's not a method on a sampler object, we fall through to let other objects have a go. - const TSampler& sampler = base->getType().getSampler(); - if (! sampler.isPureSampler()) { - const int vecSize = sampler.isShadow() ? 1 : 4; // TODO: handle arbitrary sample return sizes - return intermediate.addMethod(base, TType(sampler.type, EvqTemporary, vecSize), &field, loc); - } - } else if (isStructBufferType(base->getType())) { - TType retType(base->getType(), 0); - return intermediate.addMethod(base, retType, &field, loc); + if (base->getType().getBasicType() == EbtSampler) { + return true; + } else if (isStructBufferType(base->getType()) && isStructBufferMethod(field)) { + return true; } else if (field == "Append" || field == "RestartStrip") { // We cannot check the type here: it may be sanitized if we're not compiling a geometry shader, but // the code is around in the shader source. - return intermediate.addMethod(base, TType(EbtVoid), &field, loc); - } - - return nullptr; + return true; + } else + return false; } // Split the type of the given node into two structs: diff --git a/hlsl/hlslParseHelper.h b/hlsl/hlslParseHelper.h index 747862f00..d7a2b7859 100755 --- a/hlsl/hlslParseHelper.h +++ b/hlsl/hlslParseHelper.h @@ -70,7 +70,7 @@ public: TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right); TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode); TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field); - TIntermTyped* handleBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field); + bool isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field); void assignLocations(TVariable& variable); TFunction& handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype); TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributeMap&, TIntermNode*& entryPointTree); @@ -249,7 +249,6 @@ protected: void clearUniformInputOutput(TQualifier& qualifier); // Test method names - bool isSamplerMethod(const TString& name) const; bool isStructBufferMethod(const TString& name) const; TType* getStructBufferContentType(const TType& type) const; -- GitLab