static BoolLiteralExpression GetFoldedBoolLiteral(BinaryOperatorType @operator, bool lhs, bool rhs)
{
bool result;
switch (@operator)
{
//comparison
case BinaryOperatorType.Equality:
result = (lhs == rhs);
break;
case BinaryOperatorType.Inequality:
result = (lhs != rhs);
break;
//bitwise
case BinaryOperatorType.BitwiseOr:
result = lhs | rhs;
break;
case BinaryOperatorType.BitwiseAnd:
result = lhs & rhs;
break;
case BinaryOperatorType.ExclusiveOr:
result = lhs ^ rhs;
break;
//logical
case BinaryOperatorType.And:
result = lhs && rhs;
break;
case BinaryOperatorType.Or:
result = lhs || rhs;
break;
default:
return null; //not supported
}
return new BoolLiteralExpression(result);
}