< Summary

Class:NanoCLang.Entities.SubtractionExpression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BinaryExpression\SubtractionExpression.cs
Covered lines:16
Uncovered lines:4
Coverable lines:20
Total lines:52
Line coverage:80% (16 of 20)
Covered branches:6
Total branches:10
Branch coverage:60% (6 of 10)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Replace(...)100%10%
DoInferType(...)60%1081.25%
IndexOperation(...)100%1100%
ToArithmetic(...)100%1100%

File(s)

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

#LineLine coverage
 1using Microsoft.Z3;
 2using NanoCLang.Environemnts;
 3
 4namespace NanoCLang.Entities {
 5    /// <summary>
 6    /// Provides a class for subtraction expressions.
 7    /// </summary>
 8    public class SubtractionExpression : BinaryExpression {
 9        /// <summary>
 10        /// Operator used for this expression.
 11        /// </summary>
 12        public const string OPERATOR = "-";
 13        /// <summary>
 14        /// Creates a new instance of a subtraction expression of <paramref name="left"/> - <paramref name="right"/>.
 15        /// </summary>
 16        /// <param name="left">Left hand operand.</param>
 17        /// <param name="right">Right hand operand.</param>
 7818        public SubtractionExpression(PureExpression left, PureExpression right) : base(left, OPERATOR, right) { }
 19        /// <inheritdoc/>
 20        public override PureExpression Replace(Substitutor sub)
 021            => new SubtractionExpression(Left.Replace(sub), Right.Replace(sub));
 22        /// <inheritdoc/>
 1723        protected override Type DoInferType(LocalEnvironment gamma) {
 1724            var left = Left.InferType(gamma);
 1725            var right = Right.InferType(gamma);
 1726            switch (left.BaseType) {
 27            case IntegerType t:
 1528                switch (right.BaseType) {
 1529                case IntegerType o when t.Size == o.Size:
 1530                    return new RefinedType(
 1531                        new IntegerType(t.Size, IndexOperation(t.Values, o.Values)),
 3032                        v => EqualExpression(v, this));
 033                default: throw new IllFormedException(this, $"No binary operation {left.BaseType} {Operation} {right.Bas
 34                }
 35            case ReferenceType t:
 36                switch (right.BaseType) {
 37                case IntegerType o:
 238                    return new RefinedType(
 239                    new ReferenceType(t.Location, IndexOperation(t.Offsets, o.Values)),
 440                    v => new UninterpretedApplicationExpression("PAdd", v, Left, new IntegerConstant(0, o.Size) - Right)
 041                default: throw new IllFormedException(this, $"No binary operation {left.BaseType} {Operation} {right.Bas
 42                }
 043            default: throw new IllFormedException(this, $"No binary operation {left.BaseType}!");
 44            }
 1745        }
 46        /// <inheritdoc/>
 1747        public override Index IndexOperation(Index left, Index right) => left - right;
 48        /// <inheritdoc/>
 49        public override ArithExpr ToArithmetic(LocalEnvironment gamma, NanoCSMT smt)
 1650            => smt.Context.MkSub(Left.ToArithmetic(gamma, smt), Right.ToArithmetic(gamma, smt));
 51    }
 52}