Commit 09b22474 by Olli Etuaho Committed by Jamie Madill

Add addBinaryMath and addUnaryMath helpers to ParseContext

This refactoring reduces code duplication and moves functionality that is not immediately related to the language grammar out of glslang.y. BUG=angle:911 Change-Id: If5e225461890ed542dee01905829df1c9a6f5e27 Reviewed-on: https://chromium-review.googlesource.com/248570Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 40853472
...@@ -2588,6 +2588,53 @@ TPublicType TParseContext::addStructure(const TSourceLoc& structLine, const TSou ...@@ -2588,6 +2588,53 @@ TPublicType TParseContext::addStructure(const TSourceLoc& structLine, const TSou
return publicType; return publicType;
} }
TIntermTyped *TParseContext::addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
{
TIntermTyped *node = intermediate.addUnaryMath(op, child, loc);
if (node == 0)
{
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
recover();
return child;
}
return node;
}
TIntermTyped *TParseContext::addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
{
if (lValueErrorCheck(loc, GetOperatorString(op), child))
recover();
return addUnaryMath(op, child, loc);
}
TIntermTyped *TParseContext::addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc)
{
TIntermTyped *node = intermediate.addBinaryMath(op, left, right, loc);
if (node == 0)
{
binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
recover();
return left;
}
return node;
}
TIntermTyped *TParseContext::addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc)
{
TIntermTyped *node = intermediate.addBinaryMath(op, left, right, loc);
if (node == 0)
{
binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
recover();
ConstantUnion *unionArray = new ConstantUnion[1];
unionArray->setBConst(false);
return intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), loc);
}
return node;
}
// //
// Parse an array of strings using yyparse. // Parse an array of strings using yyparse.
// //
......
...@@ -164,6 +164,13 @@ struct TParseContext { ...@@ -164,6 +164,13 @@ struct TParseContext {
void exitStructDeclaration(); void exitStructDeclaration();
bool structNestingErrorCheck(const TSourceLoc& line, const TField& field); bool structNestingErrorCheck(const TSourceLoc& line, const TField& field);
TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &);
TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &);
TIntermTyped *addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &);
TIntermTyped *addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &);
}; };
int PaParseStrings(size_t count, const char* const string[], const int length[], 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