Commit daf120b4 by Olli Etuaho Committed by Commit Bot

Clean up checkCanBeLValue

Clarify the code so that it will be easier to add marking statically written variables here. BUG=angleproject:2262 TEST=angle_unittests Change-Id: I821bde29beb89e0f3b0f99dc187d2840f8cd0f9b Reviewed-on: https://chromium-review.googlesource.com/977963 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent b9f92504
...@@ -447,10 +447,7 @@ void TParseContext::checkPrecisionSpecified(const TSourceLoc &line, ...@@ -447,10 +447,7 @@ void TParseContext::checkPrecisionSpecified(const TSourceLoc &line,
// an l-value that can be operated on this way. // an l-value that can be operated on this way.
bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node) bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node)
{ {
TIntermSymbol *symNode = node->getAsSymbolNode();
TIntermBinary *binaryNode = node->getAsBinaryNode();
TIntermSwizzle *swizzleNode = node->getAsSwizzleNode(); TIntermSwizzle *swizzleNode = node->getAsSwizzleNode();
if (swizzleNode) if (swizzleNode)
{ {
bool ok = checkCanBeLValue(line, op, swizzleNode->getOperand()); bool ok = checkCanBeLValue(line, op, swizzleNode->getOperand());
...@@ -462,6 +459,7 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn ...@@ -462,6 +459,7 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn
return ok; return ok;
} }
TIntermBinary *binaryNode = node->getAsBinaryNode();
if (binaryNode) if (binaryNode)
{ {
switch (binaryNode->getOp()) switch (binaryNode->getOp())
...@@ -582,40 +580,31 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn ...@@ -582,40 +580,31 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn
} }
} }
if (message.empty() && binaryNode == 0 && symNode == 0) ASSERT(binaryNode == nullptr && swizzleNode == nullptr);
TIntermSymbol *symNode = node->getAsSymbolNode();
if (message.empty() && symNode != nullptr)
{ {
error(line, "l-value required", op);
return false;
}
//
// Everything else is okay, no error.
//
if (message.empty())
return true; return true;
//
// If we get here, we have an error and a message.
//
if (symNode)
{
// Symbol inside an expression can't be nameless.
ASSERT(symNode->variable().symbolType() != SymbolType::Empty);
const ImmutableString &symbol = symNode->getName();
std::stringstream reasonStream;
reasonStream << "l-value required (" << message << " \"" << symbol << "\")";
std::string reason = reasonStream.str();
error(line, reason.c_str(), op);
} }
else
std::stringstream reasonStream;
reasonStream << "l-value required";
if (!message.empty())
{ {
std::stringstream reasonStream; if (symNode)
reasonStream << "l-value required (" << message << ")"; {
std::string reason = reasonStream.str(); // Symbol inside an expression can't be nameless.
error(line, reason.c_str(), op); ASSERT(symNode->variable().symbolType() != SymbolType::Empty);
const ImmutableString &symbol = symNode->getName();
reasonStream << " (" << message << " \"" << symbol << "\")";
}
else
{
reasonStream << " (" << message << ")";
}
} }
std::string reason = reasonStream.str();
error(line, reason.c_str(), op);
return false; return false;
} }
......
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