Commit 4728bdc8 by Olli Etuaho Committed by Commit Bot

Unify looking for symbols with a specific name in the AST

Keep only one traverser for looking up symbol nodes by name instead of having two largely identical ones. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I36e906258180e22b7b1353cab79d90266d99fa0e Reviewed-on: https://chromium-review.googlesource.com/836895Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 492b5f51
...@@ -129,8 +129,6 @@ ...@@ -129,8 +129,6 @@
'compiler/translator/RunAtTheEndOfShader.h', 'compiler/translator/RunAtTheEndOfShader.h',
'compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp', 'compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp',
'compiler/translator/ScalarizeVecAndMatConstructorArgs.h', 'compiler/translator/ScalarizeVecAndMatConstructorArgs.h',
'compiler/translator/SearchSymbol.cpp',
'compiler/translator/SearchSymbol.h',
'compiler/translator/SeparateDeclarations.cpp', 'compiler/translator/SeparateDeclarations.cpp',
'compiler/translator/SeparateDeclarations.h', 'compiler/translator/SeparateDeclarations.h',
'compiler/translator/Severity.h', 'compiler/translator/Severity.h',
......
...@@ -19,7 +19,7 @@ namespace sh ...@@ -19,7 +19,7 @@ namespace sh
void ClampPointSize(TIntermBlock *root, float maxPointSize, TSymbolTable *symbolTable) void ClampPointSize(TIntermBlock *root, float maxPointSize, TSymbolTable *symbolTable)
{ {
// Only clamp gl_PointSize if it's used in the shader. // Only clamp gl_PointSize if it's used in the shader.
if (!FindSymbolNode(root, TString("gl_PointSize"), EbtFloat)) if (!FindSymbolNode(root, TString("gl_PointSize")))
{ {
return; return;
} }
......
...@@ -19,17 +19,14 @@ namespace ...@@ -19,17 +19,14 @@ namespace
class SymbolFinder : public TIntermTraverser class SymbolFinder : public TIntermTraverser
{ {
public: public:
SymbolFinder(const TString &symbolName, TBasicType basicType) SymbolFinder(const TString &symbolName)
: TIntermTraverser(true, false, false), : TIntermTraverser(true, false, false), mSymbolName(symbolName), mNodeFound(nullptr)
mSymbolName(symbolName),
mNodeFound(nullptr),
mBasicType(basicType)
{ {
} }
void visitSymbol(TIntermSymbol *node) void visitSymbol(TIntermSymbol *node)
{ {
if (node->getBasicType() == mBasicType && node->getSymbol() == mSymbolName) if (node->getSymbol() == mSymbolName)
{ {
mNodeFound = node; mNodeFound = node;
} }
...@@ -41,16 +38,13 @@ class SymbolFinder : public TIntermTraverser ...@@ -41,16 +38,13 @@ class SymbolFinder : public TIntermTraverser
private: private:
TString mSymbolName; TString mSymbolName;
TIntermSymbol *mNodeFound; TIntermSymbol *mNodeFound;
TBasicType mBasicType;
}; };
} // anonymous namespace } // anonymous namespace
const TIntermSymbol *FindSymbolNode(TIntermNode *root, const TIntermSymbol *FindSymbolNode(TIntermNode *root, const TString &symbolName)
const TString &symbolName,
TBasicType basicType)
{ {
SymbolFinder finder(symbolName, basicType); SymbolFinder finder(symbolName);
root->traverse(&finder); root->traverse(&finder);
return finder.getNode(); return finder.getNode();
} }
......
...@@ -18,9 +18,7 @@ namespace sh ...@@ -18,9 +18,7 @@ namespace sh
class TIntermNode; class TIntermNode;
class TIntermSymbol; class TIntermSymbol;
const TIntermSymbol *FindSymbolNode(TIntermNode *root, const TIntermSymbol *FindSymbolNode(TIntermNode *root, const TString &symbolName);
const TString &symbolName,
TBasicType basicType);
} // namespace sh } // namespace sh
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
#include "common/utilities.h" #include "common/utilities.h"
#include "compiler/translator/BuiltInFunctionEmulator.h" #include "compiler/translator/BuiltInFunctionEmulator.h"
#include "compiler/translator/BuiltInFunctionEmulatorHLSL.h" #include "compiler/translator/BuiltInFunctionEmulatorHLSL.h"
#include "compiler/translator/FindSymbolNode.h"
#include "compiler/translator/ImageFunctionHLSL.h" #include "compiler/translator/ImageFunctionHLSL.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/NodeSearch.h" #include "compiler/translator/NodeSearch.h"
#include "compiler/translator/RemoveSwitchFallThrough.h" #include "compiler/translator/RemoveSwitchFallThrough.h"
#include "compiler/translator/SearchSymbol.h"
#include "compiler/translator/StructureHLSL.h" #include "compiler/translator/StructureHLSL.h"
#include "compiler/translator/TextureFunctionHLSL.h" #include "compiler/translator/TextureFunctionHLSL.h"
#include "compiler/translator/TranslatorHLSL.h" #include "compiler/translator/TranslatorHLSL.h"
...@@ -2795,10 +2795,9 @@ bool OutputHLSL::writeSameSymbolInitializer(TInfoSinkBase &out, ...@@ -2795,10 +2795,9 @@ bool OutputHLSL::writeSameSymbolInitializer(TInfoSinkBase &out,
TIntermSymbol *symbolNode, TIntermSymbol *symbolNode,
TIntermTyped *expression) TIntermTyped *expression)
{ {
sh::SearchSymbol searchSymbol(symbolNode->getSymbol()); const TIntermSymbol *symbolInInitializer = FindSymbolNode(expression, symbolNode->getSymbol());
expression->traverse(&searchSymbol);
if (searchSymbol.foundMatch()) if (symbolInInitializer)
{ {
// Type already printed // Type already printed
out << "t" + str(mUniqueIndex) + " = "; out << "t" + str(mUniqueIndex) + " = ";
......
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SearchSymbol is an AST traverser to detect the use of a given symbol name
//
#include "compiler/translator/SearchSymbol.h"
#include "compiler/translator/InfoSink.h"
namespace sh
{
SearchSymbol::SearchSymbol(const TString &symbol)
: TIntermTraverser(true, false, false), mSymbol(symbol)
{
match = false;
}
void SearchSymbol::traverse(TIntermNode *node)
{
node->traverse(this);
}
void SearchSymbol::visitSymbol(TIntermSymbol *symbolNode)
{
if (symbolNode->getSymbol() == mSymbol)
{
match = true;
}
}
bool SearchSymbol::foundMatch() const
{
return match;
}
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SearchSymbol is an AST traverser to detect the use of a given symbol name
//
#ifndef COMPILER_TRANSLATOR_SEARCHSYMBOL_H_
#define COMPILER_TRANSLATOR_SEARCHSYMBOL_H_
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/ParseContext.h"
namespace sh
{
class SearchSymbol : public TIntermTraverser
{
public:
SearchSymbol(const TString &symbol);
void traverse(TIntermNode *node);
void visitSymbol(TIntermSymbol *symbolNode) override;
bool foundMatch() const;
protected:
const TString &mSymbol;
bool match;
};
}
#endif // COMPILER_TRANSLATOR_SEARCHSYMBOL_H_
...@@ -25,9 +25,9 @@ class QualificationVertexShaderTestESSL31 : public ShaderCompileTreeTest ...@@ -25,9 +25,9 @@ class QualificationVertexShaderTestESSL31 : public ShaderCompileTreeTest
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; } ::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; } ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
const TIntermSymbol *findSymbolInAST(const TString &symbolName, TBasicType basicType) const TIntermSymbol *findSymbolInAST(const TString &symbolName)
{ {
return FindSymbolNode(mASTRoot, symbolName, basicType); return FindSymbolNode(mASTRoot, symbolName);
} }
}; };
...@@ -47,7 +47,7 @@ TEST_F(QualificationVertexShaderTestESSL31, CentroidOut) ...@@ -47,7 +47,7 @@ TEST_F(QualificationVertexShaderTestESSL31, CentroidOut)
} }
else else
{ {
const TIntermSymbol *node = findSymbolInAST("something", EbtFloat); const TIntermSymbol *node = findSymbolInAST("something");
ASSERT_NE(nullptr, node); ASSERT_NE(nullptr, node);
const TType &type = node->getType(); const TType &type = node->getType();
...@@ -70,7 +70,7 @@ TEST_F(QualificationVertexShaderTestESSL31, AllQualifiersMixed) ...@@ -70,7 +70,7 @@ TEST_F(QualificationVertexShaderTestESSL31, AllQualifiersMixed)
} }
else else
{ {
const TIntermSymbol *node = findSymbolInAST("something", EbtFloat); const TIntermSymbol *node = findSymbolInAST("something");
ASSERT_NE(nullptr, node); ASSERT_NE(nullptr, node);
const TType &type = node->getType(); const TType &type = node->getType();
...@@ -95,7 +95,7 @@ TEST_F(QualificationVertexShaderTestESSL31, MultipleLayouts) ...@@ -95,7 +95,7 @@ TEST_F(QualificationVertexShaderTestESSL31, MultipleLayouts)
} }
else else
{ {
const TIntermSymbol *node = findSymbolInAST("something", EbtFloat); const TIntermSymbol *node = findSymbolInAST("something");
ASSERT_NE(nullptr, node); ASSERT_NE(nullptr, node);
const TType &type = node->getType(); const TType &type = node->getType();
...@@ -122,7 +122,7 @@ TEST_F(QualificationVertexShaderTestESSL31, MultipleLayoutsInterfaceBlock) ...@@ -122,7 +122,7 @@ TEST_F(QualificationVertexShaderTestESSL31, MultipleLayoutsInterfaceBlock)
} }
else else
{ {
const TIntermSymbol *node = findSymbolInAST("MyInterfaceName", EbtInterfaceBlock); const TIntermSymbol *node = findSymbolInAST("MyInterfaceName");
ASSERT_NE(nullptr, node); ASSERT_NE(nullptr, node);
const TType &type = node->getType(); const TType &type = node->getType();
...@@ -150,7 +150,7 @@ TEST_F(QualificationVertexShaderTestESSL31, MultipleLayoutsInterfaceBlock2) ...@@ -150,7 +150,7 @@ TEST_F(QualificationVertexShaderTestESSL31, MultipleLayoutsInterfaceBlock2)
} }
else else
{ {
const TIntermSymbol *node = findSymbolInAST("MyInterfaceName", EbtInterfaceBlock); const TIntermSymbol *node = findSymbolInAST("MyInterfaceName");
ASSERT_NE(nullptr, node); ASSERT_NE(nullptr, node);
const TType &type = node->getType(); const TType &type = node->getType();
......
...@@ -96,9 +96,10 @@ void CheckImageDeclaration(TIntermNode *astRoot, ...@@ -96,9 +96,10 @@ void CheckImageDeclaration(TIntermNode *astRoot,
bool volatileQualifier, bool volatileQualifier,
int binding) int binding)
{ {
const TIntermSymbol *myImageNode = FindSymbolNode(astRoot, imageName, imageType); const TIntermSymbol *myImageNode = FindSymbolNode(astRoot, imageName);
ASSERT_NE(nullptr, myImageNode); ASSERT_NE(nullptr, myImageNode);
ASSERT_EQ(imageType, myImageNode->getBasicType());
const TType &myImageType = myImageNode->getType(); const TType &myImageType = myImageNode->getType();
TLayoutQualifier myImageLayoutQualifier = myImageType.getLayoutQualifier(); TLayoutQualifier myImageLayoutQualifier = myImageType.getLayoutQualifier();
ASSERT_EQ(internalFormat, myImageLayoutQualifier.imageInternalFormat); ASSERT_EQ(internalFormat, myImageLayoutQualifier.imageInternalFormat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment