Commit e40d1e9c by Zhenyao Mo

Fix style violations.

BUG=angle:650 TEST=no behavior change Change-Id: I3096615a181b1ec2c18ce60566c3d6249975b84e Reviewed-on: https://chromium-review.googlesource.com/208569Tested-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b759a748
......@@ -243,7 +243,7 @@ public:
default:
return true;
};
const TIntermSequence& sequence = node->getSequence();
const TIntermSequence& sequence = *(node->getSequence());
// Right now we only handle built-in functions with two parameters.
if (sequence.size() != 2)
return true;
......
......@@ -43,8 +43,8 @@ bool ForLoopUnrollMarker::visitLoop(Visit, TIntermLoop *node)
// Check if loop index type is integer.
// This is called after ValidateLimitations pass, so all the calls
// should be valid. See ValidateLimitations::validateForLoopInit().
TIntermSequence& declSeq = node->getInit()->getAsAggregate()->getSequence();
TIntermSymbol* symbol = declSeq[0]->getAsBinaryNode()->getLeft()->getAsSymbolNode();
TIntermSequence *declSeq = node->getInit()->getAsAggregate()->getSequence();
TIntermSymbol *symbol = (*declSeq)[0]->getAsBinaryNode()->getLeft()->getAsSymbolNode();
if (symbol->getBasicType() == EbtInt)
node->setUnrollFlag(true);
}
......
......@@ -10,7 +10,7 @@
namespace
{
TIntermConstantUnion* constructFloatConstUnionNode(const TType& type)
TIntermConstantUnion *constructFloatConstUnionNode(const TType &type)
{
TType myType = type;
unsigned char size = myType.getNominalSize();
......@@ -26,7 +26,7 @@ TIntermConstantUnion* constructFloatConstUnionNode(const TType& type)
return node;
}
TIntermConstantUnion* constructIndexNode(int index)
TIntermConstantUnion *constructIndexNode(int index)
{
ConstantUnion *u = new ConstantUnion[1];
u[0].setIConst(index);
......@@ -38,7 +38,7 @@ TIntermConstantUnion* constructIndexNode(int index)
} // namespace anonymous
bool InitializeVariables::visitAggregate(Visit visit, TIntermAggregate* node)
bool InitializeVariables::visitAggregate(Visit visit, TIntermAggregate *node)
{
bool visitChildren = !mCodeInserted;
switch (node->getOp())
......@@ -51,17 +51,17 @@ bool InitializeVariables::visitAggregate(Visit visit, TIntermAggregate* node)
ASSERT(visit == PreVisit);
if (node->getName() == "main(")
{
TIntermSequence &sequence = node->getSequence();
ASSERT((sequence.size() == 1) || (sequence.size() == 2));
TIntermSequence *sequence = node->getSequence();
ASSERT((sequence->size() == 1) || (sequence->size() == 2));
TIntermAggregate *body = NULL;
if (sequence.size() == 1)
if (sequence->size() == 1)
{
body = new TIntermAggregate(EOpSequence);
sequence.push_back(body);
sequence->push_back(body);
}
else
{
body = sequence[1]->getAsAggregate();
body = (*sequence)[1]->getAsAggregate();
}
ASSERT(body);
insertInitCode(body->getSequence());
......@@ -76,18 +76,18 @@ bool InitializeVariables::visitAggregate(Visit visit, TIntermAggregate* node)
return visitChildren;
}
void InitializeVariables::insertInitCode(TIntermSequence& sequence)
void InitializeVariables::insertInitCode(TIntermSequence *sequence)
{
for (size_t ii = 0; ii < mVariables.size(); ++ii)
{
const InitVariableInfo& varInfo = mVariables[ii];
const InitVariableInfo &varInfo = mVariables[ii];
if (varInfo.type.isArray())
{
for (int index = varInfo.type.getArraySize() - 1; index >= 0; --index)
{
TIntermBinary *assign = new TIntermBinary(EOpAssign);
sequence.insert(sequence.begin(), assign);
sequence->insert(sequence->begin(), assign);
TIntermBinary *indexDirect = new TIntermBinary(EOpIndexDirect);
TIntermSymbol *symbol = new TIntermSymbol(0, varInfo.name, varInfo.type);
......@@ -104,7 +104,7 @@ void InitializeVariables::insertInitCode(TIntermSequence& sequence)
else
{
TIntermBinary *assign = new TIntermBinary(EOpAssign);
sequence.insert(sequence.begin(), assign);
sequence->insert(sequence->begin(), assign);
TIntermSymbol *symbol = new TIntermSymbol(0, varInfo.name, varInfo.type);
assign->setLeft(symbol);
TIntermConstantUnion *zeroConst = constructFloatConstUnionNode(varInfo.type);
......
......@@ -17,7 +17,7 @@ class InitializeVariables : public TIntermTraverser
TString name;
TType type;
InitVariableInfo(const TString& _name, const TType& _type)
InitVariableInfo(const TString &_name, const TType &_type)
: name(_name),
type(_type)
{
......@@ -25,23 +25,23 @@ class InitializeVariables : public TIntermTraverser
};
typedef TVector<InitVariableInfo> InitVariableInfoList;
InitializeVariables(const InitVariableInfoList& vars)
InitializeVariables(const InitVariableInfoList &vars)
: mCodeInserted(false),
mVariables(vars)
{
}
protected:
virtual bool visitBinary(Visit visit, TIntermBinary* node) { return false; }
virtual bool visitUnary(Visit visit, TIntermUnary* node) { return false; }
virtual bool visitSelection(Visit visit, TIntermSelection* node) { return false; }
virtual bool visitLoop(Visit visit, TIntermLoop* node) { return false; }
virtual bool visitBranch(Visit visit, TIntermBranch* node) { return false; }
virtual bool visitBinary(Visit, TIntermBinary *node) { return false; }
virtual bool visitUnary(Visit, TIntermUnary *node) { return false; }
virtual bool visitSelection(Visit, TIntermSelection *node) { return false; }
virtual bool visitLoop(Visit, TIntermLoop *node) { return false; }
virtual bool visitBranch(Visit, TIntermBranch *node) { return false; }
virtual bool visitAggregate(Visit visit, TIntermAggregate* node);
private:
void insertInitCode(TIntermSequence& sequence);
void insertInitCode(TIntermSequence *sequence);
InitVariableInfoList mVariables;
bool mCodeInserted;
......
......@@ -55,25 +55,25 @@ void TIntermBinary::traverse(TIntermTraverser *it)
if (it->rightToLeft)
{
if (right)
right->traverse(it);
if (mRight)
mRight->traverse(it);
if (it->inVisit)
visit = it->visitBinary(InVisit, this);
if (visit && left)
left->traverse(it);
if (visit && mLeft)
mLeft->traverse(it);
}
else
{
if (left)
left->traverse(it);
if (mLeft)
mLeft->traverse(it);
if (it->inVisit)
visit = it->visitBinary(InVisit, this);
if (visit && right)
right->traverse(it);
if (visit && mRight)
mRight->traverse(it);
}
it->decrementDepth();
......@@ -99,7 +99,7 @@ void TIntermUnary::traverse(TIntermTraverser *it)
if (visit) {
it->incrementDepth(this);
operand->traverse(it);
mOperand->traverse(it);
it->decrementDepth();
}
......@@ -123,26 +123,28 @@ void TIntermAggregate::traverse(TIntermTraverser *it)
if (it->rightToLeft)
{
for (TIntermSequence::reverse_iterator sit = sequence.rbegin(); sit != sequence.rend(); sit++)
for (TIntermSequence::reverse_iterator sit = mSequence.rbegin();
sit != mSequence.rend(); sit++)
{
(*sit)->traverse(it);
if (visit && it->inVisit)
{
if (*sit != sequence.front())
if (*sit != mSequence.front())
visit = it->visitAggregate(InVisit, this);
}
}
}
else
{
for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
for (TIntermSequence::iterator sit = mSequence.begin();
sit != mSequence.end(); sit++)
{
(*sit)->traverse(it);
if (visit && it->inVisit)
{
if (*sit != sequence.back())
if (*sit != mSequence.back())
visit = it->visitAggregate(InVisit, this);
}
}
......@@ -165,20 +167,24 @@ void TIntermSelection::traverse(TIntermTraverser *it)
if (it->preVisit)
visit = it->visitSelection(PreVisit, this);
if (visit) {
if (visit)
{
it->incrementDepth(this);
if (it->rightToLeft) {
if (falseBlock)
falseBlock->traverse(it);
if (trueBlock)
trueBlock->traverse(it);
condition->traverse(it);
} else {
condition->traverse(it);
if (trueBlock)
trueBlock->traverse(it);
if (falseBlock)
falseBlock->traverse(it);
if (it->rightToLeft)
{
if (mFalseBlock)
mFalseBlock->traverse(it);
if (mTrueBlock)
mTrueBlock->traverse(it);
mCondition->traverse(it);
}
else
{
mCondition->traverse(it);
if (mTrueBlock)
mTrueBlock->traverse(it);
if (mFalseBlock)
mFalseBlock->traverse(it);
}
it->decrementDepth();
}
......@@ -203,31 +209,31 @@ void TIntermLoop::traverse(TIntermTraverser *it)
if (it->rightToLeft)
{
if (expr)
expr->traverse(it);
if (mExpr)
mExpr->traverse(it);
if (body)
body->traverse(it);
if (mBody)
mBody->traverse(it);
if (cond)
cond->traverse(it);
if (mCond)
mCond->traverse(it);
if (init)
init->traverse(it);
if (mInit)
mInit->traverse(it);
}
else
{
if (init)
init->traverse(it);
if (mInit)
mInit->traverse(it);
if (cond)
cond->traverse(it);
if (mCond)
mCond->traverse(it);
if (body)
body->traverse(it);
if (mBody)
mBody->traverse(it);
if (expr)
expr->traverse(it);
if (mExpr)
mExpr->traverse(it);
}
it->decrementDepth();
......@@ -247,9 +253,9 @@ void TIntermBranch::traverse(TIntermTraverser *it)
if (it->preVisit)
visit = it->visitBranch(PreVisit, this);
if (visit && expression) {
if (visit && mExpression) {
it->incrementDepth(this);
expression->traverse(it);
mExpression->traverse(it);
it->decrementDepth();
}
......
......@@ -93,9 +93,9 @@ void TLoopIndexInfo::fillInfo(TIntermLoop *node)
// Here we assume all the operations are valid, because the loop node is
// already validated in ValidateLimitations.
TIntermSequence &declSeq =
TIntermSequence *declSeq =
node->getInit()->getAsAggregate()->getSequence();
TIntermBinary *declInit = declSeq[0]->getAsBinaryNode();
TIntermBinary *declInit = (*declSeq)[0]->getAsBinaryNode();
TIntermSymbol *symbol = declInit->getLeft()->getAsSymbolNode();
mId = symbol->getId();
......
......@@ -297,8 +297,8 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
{
out << ".";
TIntermAggregate *rightChild = node->getRight()->getAsAggregate();
TIntermSequence &sequence = rightChild->getSequence();
for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); ++sit)
TIntermSequence *sequence = rightChild->getSequence();
for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); ++sit)
{
TIntermConstantUnion *element = (*sit)->getAsConstantUnion();
ASSERT(element->getBasicType() == EbtInt);
......@@ -544,14 +544,14 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
{
case EOpSequence:
// Scope the sequences except when at the global scope.
if (depth > 0)
if (mDepth > 0)
{
out << "{\n";
}
incrementDepth(node);
for (TIntermSequence::const_iterator iter = node->getSequence().begin();
iter != node->getSequence().end(); ++iter)
for (TIntermSequence::const_iterator iter = node->getSequence()->begin();
iter != node->getSequence()->end(); ++iter)
{
TIntermNode *node = *iter;
ASSERT(node != NULL);
......@@ -563,7 +563,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
decrementDepth();
// Scope the sequences except when at the global scope.
if (depth > 0)
if (mDepth > 0)
{
out << "}\n";
}
......@@ -576,7 +576,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
out << " " << hashName(node->getName());
out << "(";
writeFunctionParameters(node->getSequence());
writeFunctionParameters(*(node->getSequence()));
out << ")";
visitChildren = false;
......@@ -591,7 +591,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
// Function definition node contains one or two children nodes
// representing function parameters and function body. The latter
// is not present in case of empty function bodies.
const TIntermSequence &sequence = node->getSequence();
const TIntermSequence &sequence = *(node->getSequence());
ASSERT((sequence.size() == 1) || (sequence.size() == 2));
TIntermSequence::const_iterator seqIter = sequence.begin();
......@@ -624,7 +624,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
// Function parameters.
ASSERT(visit == PreVisit);
out << "(";
writeFunctionParameters(node->getSequence());
writeFunctionParameters(*(node->getSequence()));
out << ")";
visitChildren = false;
break;
......@@ -632,7 +632,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
// Variable declaration.
if (visit == PreVisit)
{
const TIntermSequence &sequence = node->getSequence();
const TIntermSequence &sequence = *(node->getSequence());
const TIntermTyped *variable = sequence.front()->getAsTyped();
writeVariableType(variable->getType());
out << " ";
......@@ -814,10 +814,10 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
else
{
// Need to put a one-iteration loop here to handle break.
TIntermSequence &declSeq =
TIntermSequence *declSeq =
node->getInit()->getAsAggregate()->getSequence();
TIntermSymbol *indexSymbol =
declSeq[0]->getAsBinaryNode()->getLeft()->getAsSymbolNode();
(*declSeq)[0]->getAsBinaryNode()->getLeft()->getAsSymbolNode();
TString name = hashVariableName(indexSymbol->getSymbol());
out << "for (int " << name << " = 0; "
<< name << " < 1; "
......
......@@ -286,21 +286,21 @@ bool TParseContext::lValueErrorCheck(const TSourceLoc& line, const char* op, TIn
TIntermTyped* rightNode = binaryNode->getRight();
TIntermAggregate *aggrNode = rightNode->getAsAggregate();
for (TIntermSequence::iterator p = aggrNode->getSequence().begin();
p != aggrNode->getSequence().end(); p++) {
for (TIntermSequence::iterator p = aggrNode->getSequence()->begin();
p != aggrNode->getSequence()->end(); p++) {
int value = (*p)->getAsTyped()->getAsConstantUnion()->getIConst(0);
offset[value]++;
offset[value]++;
if (offset[value] > 1) {
error(line, " l-value of swizzle cannot have duplicate components", op);
return true;
}
}
}
}
return errorReturn;
default:
default:
break;
}
error(line, " l-value required", op);
......@@ -1142,8 +1142,8 @@ bool TParseContext::areAllChildConst(TIntermAggregate* aggrNode)
// check if all the child nodes are constants so that they can be inserted into
// the parent node
TIntermSequence &sequence = aggrNode->getSequence() ;
for (TIntermSequence::iterator p = sequence.begin(); p != sequence.end(); ++p) {
TIntermSequence *sequence = aggrNode->getSequence() ;
for (TIntermSequence::iterator p = sequence->begin(); p != sequence->end(); ++p) {
if (!(*p)->getAsTyped()->getAsConstantUnion())
return false;
}
......@@ -1538,17 +1538,17 @@ TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, const TType
if (!aggregateArguments)
{
aggregateArguments = new TIntermAggregate;
aggregateArguments->getSequence().push_back(arguments);
aggregateArguments->getSequence()->push_back(arguments);
}
if (op == EOpConstructStruct)
{
const TFieldList &fields = type->getStruct()->fields();
TIntermSequence &args = aggregateArguments->getSequence();
TIntermSequence *args = aggregateArguments->getSequence();
for (size_t i = 0; i < fields.size(); i++)
{
if (args[i]->getAsTyped()->getType() != *fields[i]->type())
if ((*args)[i]->getAsTyped()->getType() != *fields[i]->type())
{
error(line, "Structure constructor arguments do not match structure fields", "Error");
recover();
......@@ -1576,7 +1576,7 @@ TIntermTyped* TParseContext::foldConstConstructor(TIntermAggregate* aggrNode, co
if (canBeFolded) {
bool returnVal = false;
ConstantUnion* unionArray = new ConstantUnion[type.getObjectSize()];
if (aggrNode->getSequence().size() == 1) {
if (aggrNode->getSequence()->size() == 1) {
returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), type, true);
}
else {
......
......@@ -49,9 +49,9 @@ bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpSequence:
if (visit == PostVisit)
{
for (size_t statementIndex = 0; statementIndex != node->getSequence().size(); statementIndex++)
for (size_t statementIndex = 0; statementIndex != node->getSequence()->size(); statementIndex++)
{
TIntermNode *statement = node->getSequence()[statementIndex];
TIntermNode *statement = (*node->getSequence())[statementIndex];
TIntermSelection *selection = statement->getAsSelectionNode();
if (selection && selection->getFalseBlock() != NULL)
{
......@@ -63,7 +63,7 @@ bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node)
delete elseIfBranch;
}
node->getSequence()[statementIndex] = rewriteSelection(selection);
(*node->getSequence())[statementIndex] = rewriteSelection(selection);
delete selection;
}
}
......@@ -114,11 +114,11 @@ TIntermNode *ElseBlockRewriter::rewriteSelection(TIntermSelection *selection)
selection->getTrueBlock(), falseBlock);
TIntermAggregate *declaration = new TIntermAggregate(EOpDeclaration);
declaration->getSequence().push_back(storeCondition);
declaration->getSequence()->push_back(storeCondition);
TIntermAggregate *block = new TIntermAggregate(EOpSequence);
block->getSequence().push_back(declaration);
block->getSequence().push_back(newIfElse);
block->getSequence()->push_back(declaration);
block->getSequence()->push_back(newIfElse);
return block;
}
......
......@@ -79,8 +79,8 @@ bool ScalarizeVecAndMatConstructorArgs::visitAggregate(Visit visit, TIntermAggre
case EOpSequence:
mSequenceStack.push_back(TIntermSequence());
{
for (TIntermSequence::const_iterator iter = node->getSequence().begin();
iter != node->getSequence().end(); ++iter)
for (TIntermSequence::const_iterator iter = node->getSequence()->begin();
iter != node->getSequence()->end(); ++iter)
{
TIntermNode *child = *iter;
ASSERT(child != NULL);
......@@ -88,10 +88,10 @@ bool ScalarizeVecAndMatConstructorArgs::visitAggregate(Visit visit, TIntermAggre
mSequenceStack.back().push_back(child);
}
}
if (mSequenceStack.back().size() > node->getSequence().size())
if (mSequenceStack.back().size() > node->getSequence()->size())
{
node->getSequence().clear();
node->getSequence() = mSequenceStack.back();
node->getSequence()->clear();
*(node->getSequence()) = mSequenceStack.back();
}
mSequenceStack.pop_back();
return false;
......@@ -104,13 +104,13 @@ bool ScalarizeVecAndMatConstructorArgs::visitAggregate(Visit visit, TIntermAggre
case EOpConstructIVec2:
case EOpConstructIVec3:
case EOpConstructIVec4:
if (ContainsMatrixNode(node->getSequence()))
if (ContainsMatrixNode(*(node->getSequence())))
scalarizeArgs(node, false, true);
break;
case EOpConstructMat2:
case EOpConstructMat3:
case EOpConstructMat4:
if (ContainsVectorNode(node->getSequence()))
if (ContainsVectorNode(*(node->getSequence())))
scalarizeArgs(node, true, false);
break;
default:
......@@ -152,9 +152,9 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs(
default:
break;
}
TIntermSequence &sequence = aggregate->getSequence();
TIntermSequence original(sequence);
sequence.clear();
TIntermSequence *sequence = aggregate->getSequence();
TIntermSequence original(*sequence);
sequence->clear();
for (size_t ii = 0; ii < original.size(); ++ii)
{
ASSERT(size > 0);
......@@ -165,7 +165,7 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs(
{
TIntermSymbol *symbolNode =
new TIntermSymbol(-1, varName, node->getType());
sequence.push_back(symbolNode);
sequence->push_back(symbolNode);
size--;
}
else if (node->isVector())
......@@ -180,14 +180,14 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs(
new TIntermSymbol(-1, varName, node->getType());
TIntermBinary *newNode = ConstructVectorIndexBinaryNode(
symbolNode, index);
sequence.push_back(newNode);
sequence->push_back(newNode);
}
}
else
{
TIntermSymbol *symbolNode =
new TIntermSymbol(-1, varName, node->getType());
sequence.push_back(symbolNode);
sequence->push_back(symbolNode);
size -= node->getNominalSize();
}
}
......@@ -205,7 +205,7 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs(
new TIntermSymbol(-1, varName, node->getType());
TIntermBinary *newNode = ConstructMatrixIndexBinaryNode(
symbolNode, colIndex, rowIndex);
sequence.push_back(newNode);
sequence->push_back(newNode);
rowIndex++;
if (rowIndex >= node->getRows())
{
......@@ -219,7 +219,7 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs(
{
TIntermSymbol *symbolNode =
new TIntermSymbol(-1, varName, node->getType());
sequence.push_back(symbolNode);
sequence->push_back(symbolNode);
size -= node->getCols() * node->getRows();
}
}
......@@ -256,7 +256,7 @@ TString ScalarizeVecAndMatConstructorArgs::createTempVariable(TIntermTyped *orig
init->setType(type);
TIntermAggregate *decl = new TIntermAggregate(EOpDeclaration);
decl->getSequence().push_back(init);
decl->getSequence()->push_back(init);
ASSERT(mSequenceStack.size() > 0);
TIntermSequence &sequence = mSequenceStack.back();
......
......@@ -47,6 +47,92 @@ class ValidateConstIndexExpr : public TIntermTraverser
TLoopStack& mLoopStack;
};
const char *GetOperatorString(TOperator op)
{
switch (op)
{
case EOpInitialize: return "=";
case EOpAssign: return "=";
case EOpAddAssign: return "+=";
case EOpSubAssign: return "-=";
case EOpDivAssign: return "/=";
// Fall-through.
case EOpMulAssign:
case EOpVectorTimesMatrixAssign:
case EOpVectorTimesScalarAssign:
case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign: return "*=";
// Fall-through.
case EOpIndexDirect:
case EOpIndexIndirect: return "[]";
case EOpIndexDirectStruct:
case EOpIndexDirectInterfaceBlock: return ".";
case EOpVectorSwizzle: return ".";
case EOpAdd: return "+";
case EOpSub: return "-";
case EOpMul: return "*";
case EOpDiv: return "/";
case EOpMod: UNIMPLEMENTED(); break;
case EOpEqual: return "==";
case EOpNotEqual: return "!=";
case EOpLessThan: return "<";
case EOpGreaterThan: return ">";
case EOpLessThanEqual: return "<=";
case EOpGreaterThanEqual: return ">=";
// Fall-through.
case EOpVectorTimesScalar:
case EOpVectorTimesMatrix:
case EOpMatrixTimesVector:
case EOpMatrixTimesScalar:
case EOpMatrixTimesMatrix: return "*";
case EOpLogicalOr: return "||";
case EOpLogicalXor: return "^^";
case EOpLogicalAnd: return "&&";
case EOpNegative: return "-";
case EOpVectorLogicalNot: return "not";
case EOpLogicalNot: return "!";
case EOpPostIncrement: return "++";
case EOpPostDecrement: return "--";
case EOpPreIncrement: return "++";
case EOpPreDecrement: return "--";
case EOpRadians: return "radians";
case EOpDegrees: return "degrees";
case EOpSin: return "sin";
case EOpCos: return "cos";
case EOpTan: return "tan";
case EOpAsin: return "asin";
case EOpAcos: return "acos";
case EOpAtan: return "atan";
case EOpExp: return "exp";
case EOpLog: return "log";
case EOpExp2: return "exp2";
case EOpLog2: return "log2";
case EOpSqrt: return "sqrt";
case EOpInverseSqrt: return "inversesqrt";
case EOpAbs: return "abs";
case EOpSign: return "sign";
case EOpFloor: return "floor";
case EOpCeil: return "ceil";
case EOpFract: return "fract";
case EOpLength: return "length";
case EOpNormalize: return "normalize";
case EOpDFdx: return "dFdx";
case EOpDFdy: return "dFdy";
case EOpFwidth: return "fwidth";
case EOpAny: return "any";
case EOpAll: return "all";
default: break;
}
return "";
}
} // namespace anonymous
ValidateLimitations::ValidateLimitations(sh::GLenum shaderType,
......@@ -186,13 +272,13 @@ int ValidateLimitations::validateForLoopInit(TIntermLoop *node)
return -1;
}
// To keep things simple do not allow declaration list.
TIntermSequence &declSeq = decl->getSequence();
if (declSeq.size() != 1)
TIntermSequence *declSeq = decl->getSequence();
if (declSeq->size() != 1)
{
error(decl->getLine(), "Invalid init declaration", "for");
return -1;
}
TIntermBinary *declInit = declSeq[0]->getAsBinaryNode();
TIntermBinary *declInit = (*declSeq)[0]->getAsBinaryNode();
if ((declInit == NULL) || (declInit->getOp() != EOpInitialize))
{
error(decl->getLine(), "Invalid init declaration", "for");
......@@ -268,7 +354,7 @@ bool ValidateLimitations::validateForLoopCond(TIntermLoop *node,
default:
error(binOp->getLine(),
"Invalid relational operator",
getOperatorString(binOp->getOp()));
GetOperatorString(binOp->getOp()));
break;
}
// Loop index must be compared with a constant.
......@@ -345,7 +431,7 @@ bool ValidateLimitations::validateForLoopExpr(TIntermLoop *node,
ASSERT((unOp == NULL) && (binOp != NULL));
break;
default:
error(expr->getLine(), "Invalid operator", getOperatorString(op));
error(expr->getLine(), "Invalid operator", GetOperatorString(op));
return false;
}
......@@ -375,10 +461,10 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate *node)
// List of param indices for which loop indices are used as argument.
typedef std::vector<size_t> ParamIndex;
ParamIndex pIndex;
TIntermSequence& params = node->getSequence();
for (TIntermSequence::size_type i = 0; i < params.size(); ++i)
TIntermSequence *params = node->getSequence();
for (TIntermSequence::size_type i = 0; i < params->size(); ++i)
{
TIntermSymbol *symbol = params[i]->getAsSymbolNode();
TIntermSymbol *symbol = (*params)[i]->getAsSymbolNode();
if (symbol && isLoopIndex(symbol))
pIndex.push_back(i);
}
......@@ -399,9 +485,9 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate *node)
TQualifier qual = param.type->getQualifier();
if ((qual == EvqOut) || (qual == EvqInOut))
{
error(params[*i]->getLine(),
error((*params)[*i]->getLine(),
"Loop index cannot be used as argument to a function out or inout parameter",
params[*i]->getAsSymbolNode()->getSymbol().c_str());
(*params)[*i]->getAsSymbolNode()->getSymbol().c_str());
valid = false;
}
}
......
......@@ -319,8 +319,8 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
{
case EOpDeclaration:
{
const TIntermSequence &sequence = node->getSequence();
const TIntermTyped &typedNode = *sequence.front()->getAsTyped();
const TIntermSequence &sequence = *(node->getSequence());
const TIntermTyped &typedNode = *(sequence.front()->getAsTyped());
TQualifier qualifier = typedNode.getQualifier();
if (typedNode.getBasicType() == EbtInterfaceBlock)
......
......@@ -40,98 +40,76 @@ TVersionGLSL::TVersionGLSL(sh::GLenum type)
{
}
void TVersionGLSL::visitSymbol(TIntermSymbol* node)
void TVersionGLSL::visitSymbol(TIntermSymbol *node)
{
if (node->getSymbol() == "gl_PointCoord")
updateVersion(GLSL_VERSION_120);
}
void TVersionGLSL::visitConstantUnion(TIntermConstantUnion*)
{
}
bool TVersionGLSL::visitBinary(Visit, TIntermBinary*)
{
return true;
}
bool TVersionGLSL::visitUnary(Visit, TIntermUnary*)
{
return true;
}
bool TVersionGLSL::visitSelection(Visit, TIntermSelection*)
{
return true;
}
bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node)
bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
{
bool visitChildren = true;
switch (node->getOp()) {
switch (node->getOp())
{
case EOpSequence:
// We need to visit sequence children to get to global or inner scope.
visitChildren = true;
break;
case EOpDeclaration: {
const TIntermSequence& sequence = node->getSequence();
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if ((qualifier == EvqInvariantVaryingIn) ||
(qualifier == EvqInvariantVaryingOut)) {
updateVersion(GLSL_VERSION_120);
case EOpDeclaration:
{
const TIntermSequence &sequence = *(node->getSequence());
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if ((qualifier == EvqInvariantVaryingIn) ||
(qualifier == EvqInvariantVaryingOut))
{
updateVersion(GLSL_VERSION_120);
}
break;
}
break;
}
case EOpParameters: {
const TIntermSequence& params = node->getSequence();
for (TIntermSequence::const_iterator iter = params.begin();
iter != params.end(); ++iter)
case EOpParameters:
{
const TIntermTyped* param = (*iter)->getAsTyped();
if (param->isArray())
const TIntermSequence &params = *(node->getSequence());
for (TIntermSequence::const_iterator iter = params.begin();
iter != params.end(); ++iter)
{
TQualifier qualifier = param->getQualifier();
if ((qualifier == EvqOut) || (qualifier == EvqInOut))
const TIntermTyped *param = (*iter)->getAsTyped();
if (param->isArray())
{
updateVersion(GLSL_VERSION_120);
break;
TQualifier qualifier = param->getQualifier();
if ((qualifier == EvqOut) || (qualifier == EvqInOut))
{
updateVersion(GLSL_VERSION_120);
break;
}
}
}
// Fully processed. No need to visit children.
visitChildren = false;
break;
}
// Fully processed. No need to visit children.
visitChildren = false;
break;
}
case EOpConstructMat2:
case EOpConstructMat3:
case EOpConstructMat4: {
const TIntermSequence& sequence = node->getSequence();
if (sequence.size() == 1) {
TIntermTyped* typed = sequence.front()->getAsTyped();
if (typed && typed->isMatrix()) {
updateVersion(GLSL_VERSION_120);
}
case EOpConstructMat4:
{
const TIntermSequence &sequence = *(node->getSequence());
if (sequence.size() == 1)
{
TIntermTyped *typed = sequence.front()->getAsTyped();
if (typed && typed->isMatrix())
{
updateVersion(GLSL_VERSION_120);
}
}
break;
}
default:
break;
}
default: break;
}
return visitChildren;
}
bool TVersionGLSL::visitLoop(Visit, TIntermLoop*)
{
return true;
}
bool TVersionGLSL::visitBranch(Visit, TIntermBranch*)
{
return true;
}
void TVersionGLSL::updateVersion(int version)
{
mVersion = std::max(version, mVersion);
......
......@@ -4,8 +4,8 @@
// found in the LICENSE file.
//
#ifndef COMPILER_VERSIONGLSL_H_
#define COMPILER_VERSIONGLSL_H_
#ifndef COMPILER_TRANSLATOR_VERSIONGLSL_H_
#define COMPILER_TRANSLATOR_VERSIONGLSL_H_
#include "compiler/translator/intermediate.h"
......@@ -24,8 +24,9 @@
// - array as "out" function parameters
//
// TODO: ES3 equivalent versions of GLSL
class TVersionGLSL : public TIntermTraverser {
public:
class TVersionGLSL : public TIntermTraverser
{
public:
TVersionGLSL(sh::GLenum type);
// Returns 120 if the following is used the shader:
......@@ -36,20 +37,14 @@ public:
// Else 110 is returned.
int getVersion() { return mVersion; }
virtual void visitSymbol(TIntermSymbol*);
virtual void visitConstantUnion(TIntermConstantUnion*);
virtual bool visitBinary(Visit, TIntermBinary*);
virtual bool visitUnary(Visit, TIntermUnary*);
virtual bool visitSelection(Visit, TIntermSelection*);
virtual bool visitAggregate(Visit, TIntermAggregate*);
virtual bool visitLoop(Visit, TIntermLoop*);
virtual bool visitBranch(Visit, TIntermBranch*);
virtual void visitSymbol(TIntermSymbol *);
virtual bool visitAggregate(Visit, TIntermAggregate *);
protected:
protected:
void updateVersion(int version);
private:
private:
int mVersion;
};
#endif // COMPILER_VERSIONGLSL_H_
#endif // COMPILER_TRANSLATOR_VERSIONGLSL_H_
......@@ -412,7 +412,7 @@ function_call
for (size_t i = 0; i < fnCandidate->getParamCount(); ++i) {
qual = fnCandidate->getParam(i).type->getQualifier();
if (qual == EvqOut || qual == EvqInOut) {
if (context->lValueErrorCheck($$->getLine(), "assign", $$->getAsAggregate()->getSequence()[i]->getAsTyped())) {
if (context->lValueErrorCheck($$->getLine(), "assign", (*($$->getAsAggregate()->getSequence()))[i]->getAsTyped())) {
context->error($1.intermNode->getLine(), "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error");
context->recover();
}
......
......@@ -2794,7 +2794,7 @@ yyreduce:
for (size_t i = 0; i < fnCandidate->getParamCount(); ++i) {
qual = fnCandidate->getParam(i).type->getQualifier();
if (qual == EvqOut || qual == EvqInOut) {
if (context->lValueErrorCheck((yyval.interm.intermTypedNode)->getLine(), "assign", (yyval.interm.intermTypedNode)->getAsAggregate()->getSequence()[i]->getAsTyped())) {
if (context->lValueErrorCheck((yyval.interm.intermTypedNode)->getLine(), "assign", (*((yyval.interm.intermTypedNode)->getAsAggregate()->getSequence()))[i]->getAsTyped())) {
context->error((yyvsp[(1) - (1)].interm).intermNode->getLine(), "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error");
context->recover();
}
......
......@@ -4,12 +4,13 @@
// found in the LICENSE file.
//
#ifndef _LOCAL_INTERMEDIATE_INCLUDED_
#define _LOCAL_INTERMEDIATE_INCLUDED_
#ifndef COMPILER_TRANSLATOR_LOCAL_INTERMEDIATE_H_
#define COMPILER_TRANSLATOR_LOCAL_INTERMEDIATE_H_
#include "compiler/translator/intermediate.h"
struct TVectorFields {
struct TVectorFields
{
int offsets[4];
int num;
};
......@@ -18,36 +19,49 @@ struct TVectorFields {
// Set of helper functions to help parse and build the tree.
//
class TInfoSink;
class TIntermediate {
public:
class TIntermediate
{
public:
POOL_ALLOCATOR_NEW_DELETE();
TIntermediate(TInfoSink& i) : infoSink(i) { }
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TSourceLoc&);
TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc&);
TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, const TSourceLoc&);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc&);
TIntermAggregate* makeAggregate(TIntermNode* node, const TSourceLoc&);
TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, const TSourceLoc&);
TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, const TSourceLoc&);
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc&);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, const TSourceLoc&);
bool parseConstTree(const TSourceLoc&, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false);
TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, TIntermTyped*, const TSourceLoc&);
TIntermTyped* addSwizzle(TVectorFields&, const TSourceLoc&);
bool postProcess(TIntermNode*);
void remove(TIntermNode*);
void outputTree(TIntermNode*);
private:
void operator=(TIntermediate&); // prevent assignments
TInfoSink& infoSink;
TIntermediate(TInfoSink &i)
: mInfoSink(i) { }
TIntermSymbol *addSymbol(
int id, const TString &, const TType &, const TSourceLoc &);
TIntermTyped *addBinaryMath(
TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &);
TIntermTyped *addAssign(
TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &);
TIntermTyped *addIndex(
TOperator op, TIntermTyped *base, TIntermTyped *index, const TSourceLoc &);
TIntermTyped *addUnaryMath(
TOperator op, TIntermNode *child, const TSourceLoc &);
TIntermAggregate *growAggregate(
TIntermNode *left, TIntermNode *right, const TSourceLoc &);
TIntermAggregate *makeAggregate(TIntermNode *node, const TSourceLoc &);
TIntermAggregate *setAggregateOperator(TIntermNode *, TOperator, const TSourceLoc &);
TIntermNode *addSelection(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &);
TIntermTyped *addSelection(
TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &);
TIntermTyped *addComma(
TIntermTyped *left, TIntermTyped *right, const TSourceLoc &);
TIntermConstantUnion *addConstantUnion(ConstantUnion *, const TType &, const TSourceLoc &);
// TODO(zmo): Get rid of default value.
bool parseConstTree(const TSourceLoc &, TIntermNode *, ConstantUnion *,
TOperator, TType, bool singleConstantParam = false);
TIntermNode *addLoop(TLoopType, TIntermNode *, TIntermTyped *, TIntermTyped *,
TIntermNode *, const TSourceLoc &);
TIntermBranch *addBranch(TOperator, const TSourceLoc &);
TIntermBranch *addBranch(TOperator, TIntermTyped *, const TSourceLoc &);
TIntermTyped *addSwizzle(TVectorFields &, const TSourceLoc &);
bool postProcess(TIntermNode *);
void remove(TIntermNode *);
void outputTree(TIntermNode *);
private:
void operator=(TIntermediate &); // prevent assignments
TInfoSink & mInfoSink;
};
#endif // _LOCAL_INTERMEDIATE_INCLUDED_
#endif // COMPILER_TRANSLATOR_LOCAL_INTERMEDIATE_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