< Summary

Class:NanoCLang.Entities.BooleanExpression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BinaryExpression\BooleanExpression.cs
Covered lines:26
Uncovered lines:3
Coverable lines:29
Total lines:72
Line coverage:89.6% (26 of 29)
Covered branches:10
Total branches:14
Branch coverage:71.4% (10 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
.ctor(...)75%485.71%
GetOperator(...)75%480%
Replace(...)100%1100%
DoInferType(...)50%2100%
ToBoolean(...)75%480%

File(s)

C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BinaryExpression\BooleanExpression.cs

#LineLine coverage
 1using Microsoft.Z3;
 2using NanoCLang.Environemnts;
 3using System;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for relation expressions.
 8    /// </summary>
 9    public class BooleanExpression : BinaryExpression {
 10        private readonly BoolOperator @operator;
 11        /// <summary>
 12        /// Creates a new instance of a relation expression of <paramref name="left"/> and <paramref name="right"/>.
 13        /// </summary>
 14        /// <param name="left">Left hand operand.</param>
 15        /// <param name="op">Operator to apply</param>
 16        /// <param name="right">Right hand operand.</param>
 141617        public BooleanExpression(PureExpression left, BoolOperator op, PureExpression right) : base(left, GetOperator(op
 70818            @operator = op;
 70819        }
 20
 21        /// <summary>
 22        /// Creates a new instance of a relation expression of <paramref name="left"/> and <paramref name="right"/>.
 23        /// </summary>
 24        /// <param name="left">Left hand operand.</param>
 25        /// <param name="op">Operator to apply</param>
 26        /// <param name="right">Right hand operand.</param>
 13227        public BooleanExpression(PureExpression left, string op, PureExpression right) : base(left, op, right) {
 6628            @operator = op switch {
 6229                "&&" => BoolOperator.And,
 430                "||" => BoolOperator.Or,
 031                _ => throw new ArgumentOutOfRangeException("Invalid boolean operator!")
 6632            };
 6633        }
 34
 35        /// <summary>
 36        /// Enumeration of valid boolean operators.
 37        /// </summary>
 38        public enum BoolOperator {
 39            /// <summary>
 40            /// Logical and conjunction operator.
 41            /// </summary>
 42            And,
 43            /// <summary>
 44            /// Logical or disjunction operator.
 45            /// </summary>
 46            Or
 47        }
 70848        private static string GetOperator(BoolOperator op) => op switch {
 70249            BoolOperator.And => "&&",
 650            BoolOperator.Or => "||",
 051            _ => throw new ArgumentOutOfRangeException("Invalid boolean operator!")
 70852        };
 53        /// <inheritdoc/>
 54        public override PureExpression Replace(Substitutor sub)
 22855            => new BooleanExpression(Left.Replace(sub), @operator, Right.Replace(sub));
 56        /// <inheritdoc/>
 357        protected override Type DoInferType(LocalEnvironment gamma) {
 358            var left = Left.InferType(gamma);
 359            var right = Right.InferType(gamma);
 360            return left.BaseType != right.BaseType
 361                ? throw new IllFormedException(this, $"Cannot compare {left.BaseType} and {right.BaseType}!")
 362                : new RefinedType(IntegerType.Boolean,
 663                v => EqualExpression(v, this));
 364        }
 65        /// <inheritdoc/>
 28466        public override BoolExpr ToBoolean(LocalEnvironment gamma, NanoCSMT smt) => @operator switch {
 26967            BoolOperator.And => smt.Context.MkAnd(Left.ToBoolean(gamma, smt), Right.ToBoolean(gamma, smt)),
 1568            BoolOperator.Or => smt.Context.MkOr(Left.ToBoolean(gamma, smt), Right.ToBoolean(gamma, smt)),
 069            _ => throw new InvalidProgramException("Unexpected operator! Constructor forbids this!")
 28470        };
 71    }
 72}