コード例 #1
0
ファイル: ExpressionCompilerTests.cs プロジェクト: polsys/cle
        public void Integer_literal_that_is_too_large_fails()
        {
            var position     = new TextPosition(10, 3, 4);
            var syntax       = new IntegerLiteralSyntax((ulong)int.MaxValue + 1, position);
            var method       = new CompiledMethod("Test::Method");
            var builder      = new BasicBlockGraphBuilder().GetInitialBlockBuilder();
            var nameResolver = new TestingResolver(new ScopedVariableMap());
            var diagnostics  = new TestingDiagnosticSink();

            var localIndex = ExpressionCompiler.TryCompileExpression(
                syntax, SimpleType.Int32, method, builder, nameResolver, diagnostics);

            Assert.That(localIndex, Is.EqualTo(-1));
            diagnostics.AssertDiagnosticAt(DiagnosticCode.TypeMismatch, position)
            .WithActual("uint32").WithExpected("int32");
        }
コード例 #2
0
ファイル: ExpressionCompilerTests.cs プロジェクト: polsys/cle
        public void Constant_comparison_compiled_successfully(string expressionString, bool expectedValue)
        {
            var expressionSyntax = ParseExpression(expressionString);
            var method           = new CompiledMethod("Test::Method");
            var builder          = new BasicBlockGraphBuilder().GetInitialBlockBuilder();
            var diagnostics      = new TestingDiagnosticSink();
            var nameResolver     = new TestingResolver(new ScopedVariableMap());

            var localIndex = ExpressionCompiler.TryCompileExpression(expressionSyntax,
                                                                     SimpleType.Bool, method, builder, nameResolver, diagnostics);

            Assert.That(diagnostics.Diagnostics, Is.Empty);
            Assert.That(localIndex, Is.EqualTo(0));
            Assert.That(method.Values[localIndex].Type, Is.EqualTo(SimpleType.Bool));
            AssertSingleLoad(builder, localIndex, expectedValue);
        }
コード例 #3
0
ファイル: ExpressionCompilerTests.cs プロジェクト: polsys/cle
        public void Int32_division_by_zero_in_constant_expression_fails(BinaryOperation op)
        {
            var position = new TextPosition(10, 3, 4);
            var syntax   = new BinaryExpressionSyntax(op,
                                                      new IntegerLiteralSyntax(2ul, default),
                                                      new IntegerLiteralSyntax(0, default),
                                                      position);
            var method       = new CompiledMethod("Test::Method");
            var builder      = new BasicBlockGraphBuilder().GetInitialBlockBuilder();
            var diagnostics  = new TestingDiagnosticSink();
            var nameResolver = new TestingResolver(new ScopedVariableMap());

            var localIndex = ExpressionCompiler.TryCompileExpression(
                syntax, SimpleType.Int32, method, builder, nameResolver, diagnostics);

            Assert.That(localIndex, Is.EqualTo(-1));
            diagnostics.AssertDiagnosticAt(DiagnosticCode.DivisionByConstantZero, position);
        }
コード例 #4
0
ファイル: ExpressionCompilerTests.cs プロジェクト: polsys/cle
        public void Boolean_literal_stored_in_bool_succeeds()
        {
            var syntax       = new BooleanLiteralSyntax(true, default);
            var method       = new CompiledMethod("Test::Method");
            var builder      = new BasicBlockGraphBuilder().GetInitialBlockBuilder();
            var nameResolver = new TestingResolver(new ScopedVariableMap());
            var diagnostics  = new TestingDiagnosticSink();

            var localIndex = ExpressionCompiler.TryCompileExpression(
                syntax, SimpleType.Bool, method, builder, nameResolver, diagnostics);

            Assert.That(localIndex, Is.EqualTo(0));
            Assert.That(diagnostics.Diagnostics, Is.Empty);
            Assert.That(method.Values, Has.Exactly(1).Items);

            var local = method.Values[0];

            Assert.That(local.Type, Is.EqualTo(SimpleType.Bool));
            AssertSingleLoad(builder, localIndex, true);
        }