Commit fc1806e1 by Olli Etuaho

Move most of addBinaryMath from Intermediate to ParseContext

Some type checks for binary math will be different based on the shading language version, which is easily accessible in ParseContext. Because of this and also for architectural simplicity it makes more sense to have the checks in ParseContext. BUG=angle:941 TEST=angle_unittests, WebGL conformance tests Change-Id: I92a499f47e1cbc6a7b6391ce0fa04284803e7140 Reviewed-on: https://chromium-review.googlesource.com/260570Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2c7c625a
......@@ -45,60 +45,6 @@ TIntermSymbol *TIntermediate::addSymbol(
TIntermTyped *TIntermediate::addBinaryMath(
TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &line)
{
switch (op)
{
case EOpEqual:
case EOpNotEqual:
if (left->isArray())
return NULL;
break;
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
if (left->isMatrix() || left->isArray() || left->isVector() ||
left->getBasicType() == EbtStruct)
{
return NULL;
}
break;
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalAnd:
if (left->getBasicType() != EbtBool ||
left->isMatrix() || left->isArray() || left->isVector())
{
return NULL;
}
break;
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMul:
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
{
return NULL;
}
break;
case EOpIMod:
// Note that this is only for the % operator, not for mod()
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
{
return NULL;
}
break;
// Note that for bitwise ops, type checking is done in promote() to
// share code between ops and compound assignment
default:
break;
}
// This check is duplicated between here and node->promote() as an optimization.
if (left->getBasicType() != right->getBasicType() && op != EOpBitShiftLeft && op != EOpBitShiftRight)
{
return NULL;
}
//
// Need a new node holding things together then. Make
// one and promote it to the right type.
......
......@@ -2716,10 +2716,70 @@ TIntermTyped *TParseContext::addUnaryMathLValue(TOperator op, TIntermTyped *chil
return addUnaryMath(op, child, loc);
}
TIntermTyped *TParseContext::addBinaryMathInternal(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc)
{
switch (op)
{
case EOpEqual:
case EOpNotEqual:
if (left->isArray())
return nullptr;
break;
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
if (left->isMatrix() || left->isArray() || left->isVector() ||
left->getBasicType() == EbtStruct)
{
return nullptr;
}
break;
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalAnd:
if (left->getBasicType() != EbtBool ||
left->isMatrix() || left->isArray() || left->isVector())
{
return nullptr;
}
break;
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMul:
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
{
return nullptr;
}
break;
case EOpIMod:
// Note that this is only for the % operator, not for mod()
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
{
return nullptr;
}
break;
// Note that for bitwise ops, type checking is done in promote() to
// share code between ops and compound assignment
default:
break;
}
// This check is duplicated between here and node->promote() as an optimization.
if (left->getBasicType() != right->getBasicType() && op != EOpBitShiftLeft && op != EOpBitShiftRight)
{
return nullptr;
}
return intermediate.addBinaryMath(op, left, right, loc);
}
TIntermTyped *TParseContext::addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc)
{
TIntermTyped *node = intermediate.addBinaryMath(op, left, right, loc);
TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
if (node == 0)
{
binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
......@@ -2732,7 +2792,7 @@ TIntermTyped *TParseContext::addBinaryMath(TOperator op, TIntermTyped *left, TIn
TIntermTyped *TParseContext::addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc)
{
TIntermTyped *node = intermediate.addBinaryMath(op, left, right, loc);
TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
if (node == 0)
{
binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
......
......@@ -183,6 +183,10 @@ struct TParseContext {
TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall, TIntermNode *node,
const TSourceLoc &loc, bool *fatalError);
private:
TIntermTyped *addBinaryMathInternal(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc);
};
int PaParseStrings(size_t count, const char* const string[], const int length[],
......
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