< Summary

Class:NanoCLang.Entities.AdditionExpression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BinaryExpression\AdditionExpression.cs
Covered lines:21
Uncovered lines:3
Coverable lines:24
Total lines:56
Line coverage:87.5% (21 of 24)
Covered branches:8
Total branches:12
Branch coverage:66.6% (8 of 12)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Replace(...)100%1100%
DoInferType(...)66.66%1285%
ToArithmetic(...)100%1100%
IndexOperation(...)100%1100%

File(s)

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

#LineLine coverage
 1using Microsoft.Z3;
 2using NanoCLang.Environemnts;
 3
 4namespace NanoCLang.Entities {
 5    /// <summary>
 6    /// Provides a class for additive expressions.
 7    /// </summary>
 8    public class AdditionExpression : BinaryExpression {
 9        /// <summary>
 10        /// Operator used for this expression.
 11        /// </summary>
 12        public const string OPERATOR = "+";
 13        /// <summary>
 14        /// Creates a new instance of an additive 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>
 24618        public AdditionExpression(PureExpression left, PureExpression right) : base(left, OPERATOR, right) { }
 19        /// <inheritdoc/>
 20        public override PureExpression Replace(Substitutor sub)
 2321            => new AdditionExpression(Left.Replace(sub), Right.Replace(sub));
 22        /// <inheritdoc/>
 4323        protected override Type DoInferType(LocalEnvironment gamma) {
 4324            var left = Left.InferType(gamma);
 4325            var right = Right.InferType(gamma);
 4326            switch (left.BaseType) {
 27            case IntegerType t:
 1428                switch (right.BaseType) {
 1229                case IntegerType o when t.Size == o.Size:
 1230                    return new RefinedType(
 1231                        new IntegerType(t.Size, IndexOperation(t.Values, o.Values)),
 2432                        v => EqualExpression(v, this));
 33                case ReferenceType o:
 234                    return new RefinedType(
 235                        new ReferenceType(o.Location, IndexOperation(t.Values, o.Offsets)),
 436                        v => new UninterpretedApplicationExpression("PAdd", v, Right, Left));
 037                default: throw new IllFormedException(this, $"Cannot add {left.BaseType} and {right.BaseType}!");
 38                }
 39            case ReferenceType t:
 2940                switch (right.BaseType) {
 41                case IntegerType o:
 2942                    return new RefinedType(
 2943                    new ReferenceType(t.Location, IndexOperation(t.Offsets, o.Values)),
 5844                    v => new UninterpretedApplicationExpression("PAdd", v, Left, Right));
 045                default: throw new IllFormedException(this, $"Cannot add {left.BaseType} and {right.BaseType}!");
 46                }
 047            default: throw new IllFormedException(this, $"No binary operation {left.BaseType}!");
 48            }
 4349        }
 50        /// <inheritdoc/>
 51        public override ArithExpr ToArithmetic(LocalEnvironment gamma, NanoCSMT smt)
 3352            => smt.Context.MkAdd(Left.ToArithmetic(gamma, smt), Right.ToArithmetic(gamma, smt));
 53        /// <inheritdoc/>
 4354        public override Index IndexOperation(Index left, Index right) => left + right;
 55    }
 56}