Make ConditionExpression ! return false for negative numbers.
This brings it in line with C/C++ behaviour.
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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")]
|
||||||
|
|||||||
Reference in New Issue
Block a user