1
0
Fork 0

alwaysProducesBoolValue()

This commit is contained in:
Jan Steemann 2014-08-27 16:24:14 +02:00
parent da6bac560d
commit 679b6bd10f
2 changed files with 40 additions and 1 deletions

View File

@ -622,6 +622,28 @@ bool AstNode::isConstant () const {
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a node is a comparison operator
////////////////////////////////////////////////////////////////////////////////
bool AstNode::isComparisonOperator () const {
return (type == NODE_TYPE_OPERATOR_BINARY_EQ ||
type == NODE_TYPE_OPERATOR_BINARY_NE ||
type == NODE_TYPE_OPERATOR_BINARY_LT ||
type == NODE_TYPE_OPERATOR_BINARY_LE ||
type == NODE_TYPE_OPERATOR_BINARY_GT ||
type == NODE_TYPE_OPERATOR_BINARY_GE ||
type == NODE_TYPE_OPERATOR_BINARY_IN);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a node always produces a boolean value
////////////////////////////////////////////////////////////////////////////////
bool AstNode::alwaysProducesBoolValue () const {
return (isBoolValue() || isComparisonOperator());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a node (and its subnodes) can throw a runtime
/// exception
@ -649,7 +671,12 @@ bool AstNode::canThrow () const {
if (type == NODE_TYPE_OPERATOR_BINARY_AND ||
type == NODE_TYPE_OPERATOR_BINARY_OR) {
// the logical operators can throw
// the logical operators can throw if the operands are not booleans
if (getMember(0)->alwaysProducesBoolValue() &&
getMember(1)->alwaysProducesBoolValue()) {
return false;
}
return true;
}

View File

@ -272,6 +272,18 @@ namespace triagens {
bool isConstant () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a node is a comparison operator
////////////////////////////////////////////////////////////////////////////////
bool isComparisonOperator () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a node always produces a boolean value
////////////////////////////////////////////////////////////////////////////////
bool alwaysProducesBoolValue () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a node (and its subnodes) may throw a runtime
/// exception