< Summary

Class:NanoCLang.Entities.UninterpretedApplicationExpression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\UninterpretedApplicationExpression.cs
Covered lines:32
Uncovered lines:18
Coverable lines:50
Total lines:96
Line coverage:64% (32 of 50)
Covered branches:21
Total branches:38
Branch coverage:55.2% (21 of 38)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Name()100%1100%
get_Parameters()100%1100%
WellFormed(...)100%2100%
DoInferType(...)100%10%
Tokens()66.66%6100%
ToBoolean(...)68.75%1691.66%
ToArithmetic(...)0%80%
Replace(...)100%1100%
Equals(...)100%1100%
Equals(...)100%4100%
GetHashCode()0%20%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

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

#LineLine coverage
 1using Microsoft.Z3;
 2using NanoCLang.Environemnts;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6
 7namespace NanoCLang.Entities {
 8    /// <summary>
 9    /// Provides a class for uninterpreted function calls.
 10    /// </summary>
 11    public class UninterpretedApplicationExpression : PureExpression, IEquatable<UninterpretedApplicationExpression?> {
 12        /// <summary>
 13        /// Creates a new uninterpreted function call instance that calls the function named <paramref name="name"/> wit
 14        /// </summary>
 15        /// <param name="name">Name of the uninterpreted function to call.</param>
 16        /// <param name="parameters">Parameters to pass to the function.</param>
 115417        public UninterpretedApplicationExpression(string name, params PureExpression[] parameters) {
 57718            Name = name;
 57719            Parameters = parameters;
 57720        }
 21        /// <summary>
 22        /// Name of the uninterpreted function to call.
 23        /// </summary>
 149524        public string Name { get; }
 25        /// <summary>
 26        /// Parameters to pass to the function.
 27        /// </summary>
 210328        public PureExpression[] Parameters { get; }
 29        /// <inheritdoc/>
 8330        public override void WellFormed(LocalEnvironment gamma) {
 8331            VerbConsole.WriteLine(VerbosityLevel.Default, $"WF-UnintF: {this}");
 49932            foreach (var param in Parameters)
 12533                param.WellFormed(gamma);
 8334        }
 35        /// <inheritdoc/>
 036        protected override Type DoInferType(LocalEnvironment gamma) => throw new InvalidOperationException("Cannot infer
 37        /// <inheritdoc/>
 50038        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 50039            yield return Name;
 50040            yield return "(";
 564341            foreach (var tk in StringFormatterToken.Separated(Parameters, args, args.ParameterListSeparator)) yield retu
 50042            if (args.SpaceInEmptyArgList && Parameters.Length == 0) yield return " ";
 50043            yield return ")";
 50044        }
 45        /// <inheritdoc/>
 38246        public override BoolExpr ToBoolean(LocalEnvironment gamma, NanoCSMT smt) {
 38247            switch (Name) {
 48            case "PAdd":
 3249                if (Parameters.Length != 3) throw new IllFormedException(this, $"Inconsistend parameter count for uninte
 3250                return smt.PAdd((IntExpr)Parameters[0].ToArithmetic(gamma, smt), (IntExpr)Parameters[1].ToArithmetic(gam
 51            case "BLen":
 15352                if (Parameters.Length != 2) throw new IllFormedException(this, $"Inconsistend parameter count for uninte
 15353                return smt.BLen((IntExpr)Parameters[0].ToArithmetic(gamma, smt), Parameters[1].ToArithmetic(gamma, smt))
 54            case "Safe":
 15955                if (Parameters.Length != 1) throw new IllFormedException(this, $"Inconsistend parameter count for uninte
 15956                return smt.Safe((IntExpr)Parameters[0].ToArithmetic(gamma, smt));
 57            case "SafeN":
 3858                if (Parameters.Length != 2) throw new IllFormedException(this, $"Inconsistend parameter count for uninte
 3859                return smt.SafeN((IntExpr)Parameters[0].ToArithmetic(gamma, smt), (IntExpr)Parameters[1].ToArithmetic(ga
 060            default: throw new IllFormedException(this, $"Function {Name} is not a boolean function!");
 61            }
 38262        }
 63        /// <inheritdoc/>
 064        public override ArithExpr ToArithmetic(LocalEnvironment gamma, NanoCSMT smt) {
 065            switch (Name) {
 66            case "BS":
 067                if (Parameters.Length != 1) throw new IllFormedException(this, $"Inconsistend parameter count for uninte
 068                return smt.BS((IntExpr)Parameters[0].ToArithmetic(gamma, smt));
 69            case "BE":
 070                if (Parameters.Length != 1) throw new IllFormedException(this, $"Inconsistend parameter count for uninte
 071                return smt.BS((IntExpr)Parameters[0].ToArithmetic(gamma, smt));
 072            default: throw new IllFormedException(this, $"Function {Name} is not an integral function!");
 73            }
 074        }
 75        /// <inheritdoc/>
 76        public override PureExpression Replace(Substitutor sub)
 90877            => new UninterpretedApplicationExpression(Name, Parameters.Select(i => i.Replace(sub)).ToArray());
 78        #region Equality checks
 79        /// <inheritdoc/>
 12580        public override bool Equals(object? obj) => Equals(obj as UninterpretedApplicationExpression);
 81        /// <inheritdoc/>
 12582        public bool Equals(UninterpretedApplicationExpression? other) => !(other is null) && Name == other.Name && Param
 83        /// <inheritdoc/>
 084        public override int GetHashCode() {
 085            var hash = new HashCode();
 086            hash.Add(Name);
 087            foreach (var param in Parameters) hash.Add(param);
 088            return hash.ToHashCode();
 089        }
 90        /// <inheritdoc/>
 091        public static bool operator ==(UninterpretedApplicationExpression? left, UninterpretedApplicationExpression? rig
 92        /// <inheritdoc/>
 093        public static bool operator !=(UninterpretedApplicationExpression? left, UninterpretedApplicationExpression? rig
 94        #endregion
 95    }
 96}