Make ConditionExpression ! return false for negative numbers.

This brings it in line with C/C++ behaviour.
This commit is contained in:
Paul Chote
2017-02-23 20:22:33 +00:00
parent 22e2deee21
commit 1c97effbc9
2 changed files with 3 additions and 11 deletions

View File

@@ -641,12 +641,7 @@ namespace OpenRA.Support
static Expression AsBool(Expression expression) static Expression AsBool(Expression expression)
{ {
return Expressions.Expression.GreaterThan(expression, Zero); return Expressions.Expression.NotEqual(expression, Zero);
}
static Expression AsNegBool(Expression expression)
{
return Expressions.Expression.LessThanOrEqual(expression, Zero);
} }
static Expression IfThenElse(Expression test, Expression ifTrue, Expression ifFalse) static Expression IfThenElse(Expression test, Expression ifTrue, Expression ifFalse)
@@ -757,10 +752,7 @@ namespace OpenRA.Support
case TokenType.Not: case TokenType.Not:
{ {
if (ast.PeekType() == ExpressionType.Bool) ast.Push(Expressions.Expression.Not(ast.Pop(ExpressionType.Bool)));
ast.Push(Expressions.Expression.Not(ast.Pop(ExpressionType.Bool)));
else
ast.Push(AsNegBool(ast.Pop(ExpressionType.Int)));
continue; continue;
} }

View File

@@ -163,7 +163,7 @@ namespace OpenRA.Test
AssertValue("!1", 0); AssertValue("!1", 0);
AssertValue("!5", 0); AssertValue("!5", 0);
AssertValue("!!5", 1); AssertValue("!!5", 1);
AssertValue("!-5", 1); AssertValue("!-5", 0);
} }
[TestCase(TestName = "Relation operations")] [TestCase(TestName = "Relation operations")]