Commit 4667c454 by Jamie Madill

Refactor style in VariableInfo.cpp.

This patch simplifies the functionality change in a subsequent patch. BUG=angle:466 Change-Id: Ib1c360438fad74fb15cd6cbf983240229c0eee76 Reviewed-on: https://chromium-review.googlesource.com/206568Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 53cb14dc
......@@ -4,9 +4,9 @@
// found in the LICENSE file.
//
#include "angle_gl.h"
#include "compiler/translator/VariableInfo.h"
#include "compiler/translator/util.h"
#include "angle_gl.h"
namespace {
......@@ -62,11 +62,14 @@ void getBuiltInVariableInfo(const TType &type,
ASSERT(type.getBasicType() != EbtStruct);
VarT varInfo;
if (type.isArray()) {
if (type.isArray())
{
varInfo.name = (name + "[0]").c_str();
varInfo.mappedName = (mappedName + "[0]").c_str();
varInfo.arraySize = type.getArraySize();
} else {
}
else
{
varInfo.name = name.c_str();
varInfo.mappedName = mappedName.c_str();
varInfo.arraySize = 0;
......@@ -88,7 +91,8 @@ void getUserDefinedVariableInfo(const TType &type,
const TFieldList& fields = type.isInterfaceBlock() ?
type.getInterfaceBlock()->fields() :
type.getStruct()->fields();
for (size_t i = 0; i < fields.size(); ++i) {
for (size_t i = 0; i < fields.size(); ++i)
{
const TType& fieldType = *(fields[i]->type());
const TString& fieldName = fields[i]->name();
getVariableInfo(fieldType,
......@@ -137,18 +141,19 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs,
// Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count
// toward varying counting if they are statically used in a fragment
// shader.
void CollectVariables::visitSymbol(TIntermSymbol* symbol)
void CollectVariables::visitSymbol(TIntermSymbol *symbol)
{
ASSERT(symbol != NULL);
sh::ShaderVariable *var = NULL;
switch (symbol->getQualifier())
if (sh::IsVarying(symbol->getQualifier()))
{
case EvqVaryingOut:
case EvqInvariantVaryingOut:
case EvqVaryingIn:
case EvqInvariantVaryingIn:
var = findVariable(symbol->getType(), symbol->getSymbol(), mVaryings);
break;
}
else
{
switch (symbol->getQualifier())
{
case EvqUniform:
var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms);
break;
......@@ -197,6 +202,7 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol)
default:
break;
}
}
if (var)
{
var->staticUse = true;
......@@ -204,17 +210,9 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol)
}
template <typename VarT>
void CollectVariables::visitInfoList(const TIntermSequence& sequence, std::vector<VarT> *infoList) const
void CollectVariables::visitVariable(const TIntermSymbol *variable,
std::vector<VarT> *infoList) const
{
for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++)
{
const TIntermSymbol* variable = sequence[seqIndex]->getAsSymbolNode();
// The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a
// TInterBinary node in that case. Since attributes, uniforms,
// and varyings cannot be initialized in a shader, we must have
// only TIntermSymbol nodes in the sequence.
ASSERT(variable != NULL);
TString processedSymbol;
if (mHashFunction == NULL)
processedSymbol = variable->getSymbol();
......@@ -225,21 +223,37 @@ void CollectVariables::visitInfoList(const TIntermSequence& sequence, std::vecto
processedSymbol,
*infoList,
mHashFunction);
}
template <typename VarT>
void CollectVariables::visitInfoList(const TIntermSequence &sequence,
std::vector<VarT> *infoList) const
{
for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++)
{
const TIntermSymbol *variable = sequence[seqIndex]->getAsSymbolNode();
// The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a
// TInterBinary node in that case. Since attributes, uniforms,
// and varyings cannot be initialized in a shader, we must have
// only TIntermSymbol nodes in the sequence.
ASSERT(variable != NULL);
visitVariable(variable, infoList);
}
}
bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
{
bool visitChildren = true;
switch (node->getOp())
{
case EOpDeclaration: {
const TIntermSequence& sequence = node->getSequence();
case EOpDeclaration:
{
const TIntermSequence &sequence = node->getSequence();
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if (qualifier == EvqAttribute || qualifier == EvqVertexIn || qualifier == EvqUniform ||
qualifier == EvqVaryingIn || qualifier == EvqVaryingOut ||
qualifier == EvqInvariantVaryingIn || qualifier == EvqInvariantVaryingOut)
sh::IsVarying(qualifier))
{
switch (qualifier)
{
......
......@@ -18,8 +18,8 @@ public:
std::vector<sh::Varying> *varyings,
ShHashFunction64 hashFunction);
virtual void visitSymbol(TIntermSymbol*);
virtual bool visitAggregate(Visit, TIntermAggregate*);
virtual void visitSymbol(TIntermSymbol *symbol);
virtual bool visitAggregate(Visit, TIntermAggregate *node);
private:
std::vector<sh::Attribute> *mAttribs;
......@@ -33,7 +33,10 @@ private:
ShHashFunction64 mHashFunction;
template <typename VarT>
void visitInfoList(const TIntermSequence& sequence, std::vector<VarT> *infoList) const;
void visitVariable(const TIntermSymbol *variable, std::vector<VarT> *infoList) const;
template <typename VarT>
void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const;
};
#endif // COMPILER_VARIABLE_INFO_H_
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