< Summary

Class:NanoCLang.Entities.IntegerConstant
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\IntegerConstant.cs
Covered lines:35
Uncovered lines:2
Coverable lines:37
Total lines:76
Line coverage:94.5% (35 of 37)
Covered branches:12
Total branches:14
Branch coverage:85.7% (12 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Size()100%1100%
get_Value()100%1100%
WellFormed(...)100%2100%
DoInferType(...)100%1100%
Tokens()100%4100%
ToArithmetic(...)100%1100%
ToBoolean(...)100%1100%
Replace(...)100%1100%
Clone()100%1100%
NoReturnTokens()50%4100%
Equals(...)100%1100%
Equals(...)100%4100%
GetHashCode()100%1100%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

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

#LineLine coverage
 1using Microsoft.Z3;
 2using NanoCLang.Environemnts;
 3using System;
 4using System.Collections.Generic;
 5
 6namespace NanoCLang.Entities {
 7    /// <summary>
 8    /// Provides a class for integer literal constants.
 9    /// </summary>
 10    public class IntegerConstant : PureExpression, IEquatable<IntegerConstant?>, ICloneable {
 11        /// <summary>
 12        /// Creates a new integer constant with <paramref name="value"/> and a <paramref name="size"/> in bytes.
 13        /// </summary>
 14        /// <param name="value">Value of the literal.</param>
 15        /// <param name="size">Size of the integer literal in bytes.</param>
 133416        public IntegerConstant(int value, int size) {
 66717            Size = size;
 66718            Value = value;
 66719        }
 20        /// <summary>
 21        /// Size of the integer literal in bytes.
 22        /// </summary>
 174623        public int Size { get; }
 24        /// <summary>
 25        /// Value of the literal.
 26        /// </summary>
 255227        public int Value { get; }
 28        /// <inheritdoc/>
 7929        public override void WellFormed(LocalEnvironment gamma) {
 7930            if (Size < 0)
 131                throw new IllFormedException(this, $"Integer literal cannot have negative size {Size}!");
 7832        }
 33        /// <inheritdoc/>
 14434        protected override Type DoInferType(LocalEnvironment gamma) => new RefinedType(new IntegerType(Size, new Singlet
 28835                           v => EqualExpression(v, this));
 36        /// <inheritdoc/>
 60837        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 65038            if (Value == 0 && Size == 0) {
 4239                yield return "return";
 4240                yield break;
 41            }
 56642            yield return Value.ToString();
 56643            yield return "_";
 56644            yield return Size.ToString();
 56645        }
 46        /// <inheritdoc/>
 45547        public override ArithExpr ToArithmetic(LocalEnvironment gamma, NanoCSMT smt) => smt.Context.MkInt(Value);
 48        /// <inheritdoc/>
 14449        public override BoolExpr ToBoolean(LocalEnvironment gamma, NanoCSMT smt) => smt.Context.MkBool(Value != 0);
 50        /// <inheritdoc/>
 24451        public override PureExpression Replace(Substitutor sub) => (PureExpression)Clone();
 52        /// <inheritdoc/>
 24453        public virtual object Clone() => new IntegerConstant(Value, Size);
 54        /// <inheritdoc/>
 5355        protected override IEnumerable<StringFormatterToken> NoReturnTokens(CSourceFormat args) {
 5356            if (args.PureRequiresReturn && Size == 0) yield break;
 5357            yield return "(";
 5358            yield return IntegerType.GetCType(Size);
 5359            yield return ")";
 5360            yield return Value.ToString();
 5361            yield return "LL";
 5362        }
 63        #region Equality checks
 64        /// <inheritdoc/>
 16965        public override bool Equals(object? obj) => Equals(obj as IntegerConstant);
 66        /// <inheritdoc/>
 16967        public bool Equals(IntegerConstant? other) => !(other is null) && Size == other.Size && Value == other.Value;
 68        /// <inheritdoc/>
 469        public override int GetHashCode() => System.HashCode.Combine(Size, Value);
 70        /// <inheritdoc/>
 071        public static bool operator ==(IntegerConstant? left, IntegerConstant? right) => EqualityComparer<IntegerConstan
 72        /// <inheritdoc/>
 073        public static bool operator !=(IntegerConstant? left, IntegerConstant? right) => !(left == right);
 74        #endregion
 75    }
 76}