Exemplo n.º 1
0
 public void TestCastSignExtend2()
 {
     var Node = (AstNode)ast.Cast<sbyte>(ast.Cast<uint>(ast.Argument<int>(0, "Arg")));
     Assert.AreEqual("((SByte)((UInt32)Arg))", new GeneratorCSharp().GenerateRoot(Node).ToString());
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual("((SByte)Arg)", new GeneratorCSharp().GenerateRoot(Node).ToString());
 }
Exemplo n.º 2
0
 public void TestCastToImmediate()
 {
     var Node = (AstNode)ast.Cast<uint>(ast.Immediate((int)7));
     Assert.AreEqual("((UInt32)7)", new GeneratorCSharp().GenerateRoot(Node).ToString());
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual("7", new GeneratorCSharp().GenerateRoot(Node).ToString());
 }
Exemplo n.º 3
0
 public void TestCalculateImmediates()
 {
     var Node = (AstNode)((ast.Immediate(0) + ast.Immediate(2)) * ast.Immediate(3));
     Assert.AreEqual("((0 + 2) * 3)", new GeneratorCSharp().GenerateRoot(Node).ToString());
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual("6", new GeneratorCSharp().GenerateRoot(Node).ToString());
 }
Exemplo n.º 4
0
 public void TestAddNegated()
 {
     var Node = (AstNode)ast.Binary(ast.Immediate(1), "+", -ast.Argument<int>(0, "Arg"));
     Assert.AreEqual("(1 + (-Arg))", new GeneratorCSharp().GenerateRoot(Node).ToString());
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual("(1 - Arg)", new GeneratorCSharp().GenerateRoot(Node).ToString());
 }
Exemplo n.º 5
0
 public void TestAdd0()
 {
     var Node = (AstNode)((ast.Argument<int>(0, "Arg") + ast.Immediate(0)) * ast.Immediate(3));
     Assert.AreEqual("((Arg + 0) * 3)", new GeneratorCSharp().GenerateRoot(Node).ToString());
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual("(Arg * 3)", new GeneratorCSharp().GenerateRoot(Node).ToString());
 }
Exemplo n.º 6
0
 public void TestCompactStmContainer()
 {
     var Node = (AstNode)ast.Statements(
         ast.Return(),
         ast.Statements(
             ast.Statements(
                 ast.Return()
             ),
             ast.Return(),
             ast.Statements(ast.Statements(ast.Statements())),
             ast.Return(),
             ast.Statements(
                 ast.Return()
             )
         ),
         ast.Return()
     );
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual(
         "AstNodeStmContainer(AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn())",
         AstSerializer.Serialize(Node)
     );
 }
Exemplo n.º 7
0
 public void TestZeroMinusNumber()
 {
     var Node = (AstNode)ast.Binary(ast.Immediate(0), "-", ast.Argument<int>(0, "Arg"));
     Assert.AreEqual("(0 - Arg)", new GeneratorCSharp().GenerateRoot(Node).ToString());
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual("(-Arg)", new GeneratorCSharp().GenerateRoot(Node).ToString());
 }
Exemplo n.º 8
0
 public void TestCompactStmContainer2()
 {
     var Node = (AstNode)ast.Statements(
         ast.Return()
     );
     Node = new AstOptimizer().Optimize(Node);
     Assert.AreEqual(
         "<AstNodeStmReturn />",
         AstSerializer.SerializeAsXml(Node, false)
     );
 }