Permalink
Browse files

AdventureSample - support Ne expr

  • Loading branch information...
bobbymcr committed Apr 22, 2018
1 parent b44dfb1 commit 6fb154c8fc377be80644c4223968eba83bd9debc
@@ -325,6 +325,7 @@ private SyntaxNode Binary(string name, SyntaxNode x, SyntaxNode y)
switch (name)
{
case "Eq": return this.DoEquals(x, y);
case "Ne": return this.DoNotEquals(x, y);
case "Or": return this.generator.BitwiseOrExpression(this.Cast(x), this.Cast(y));
case "And": return this.generator.BitwiseAndExpression(this.Cast(x), this.Cast(y));
case "Add": return this.generator.AddExpression(x, y);
@@ -343,6 +344,15 @@ private SyntaxNode DoEquals(SyntaxNode x, SyntaxNode y)
var cond = this.generator.ValueEqualsExpression(call, zero);
return this.generator.ConditionalExpression(cond, neg1, zero);
}
private SyntaxNode DoNotEquals(SyntaxNode x, SyntaxNode y)
{
var call = this.generator.InvocationExpression(this.generator.MemberAccessExpression(x, "CompareTo"), y);
var zero = this.generator.LiteralExpression(0);
var neg1 = this.generator.LiteralExpression(-1);
var cond = this.generator.ValueNotEqualsExpression(call, zero);
return this.generator.ConditionalExpression(cond, neg1, zero);
}
}
private sealed class Variables
@@ -0,0 +1,66 @@
// <copyright file="NeExpressions.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace GWBas2CS.Test
{
using FluentAssertions;
using Xunit;
public sealed class NeExpressions
{
[Fact]
public void TwoNumericOperands()
{
const string Input = @"10 A=B<>2";
const string Expected = @"*
private bool Main()
{
this.Init();
A_n = (((B_n.CompareTo(2)) != (0)) ? (-1) : (0));
return false;
}
*";
string actual = Test.Translate("MyProg", Input);
actual.Should().Match(Expected);
}
[Fact]
public void TwoStringOperands()
{
const string Input = @"10 A=B$<>""x""";
const string Expected = @"*
private bool Main()
{
this.Init();
A_n = (((B_s.CompareTo(""x"")) != (0)) ? (-1) : (0));
return false;
}
*";
string actual = Test.Translate("MyProg", Input);
actual.Should().Match(Expected);
}
[Fact]
public void ThreeNumericOperands()
{
const string Input = @"10 A=B<>C<>1";
const string Expected = @"*
private bool Main()
{
this.Init();
A_n = ((((((B_n.CompareTo(C_n)) != (0)) ? (-1) : (0)).CompareTo(1)) != (0)) ? (-1) : (0));
return false;
}
*";
string actual = Test.Translate("MyProg", Input);
actual.Should().Match(Expected);
}
}
}

0 comments on commit 6fb154c

Please sign in to comment.