< Summary

Class:NanoCLang.Entities.FoldExpression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\FoldExpression.cs
Covered lines:32
Uncovered lines:3
Coverable lines:35
Total lines:64
Line coverage:91.4% (32 of 35)
Covered branches:11
Total branches:14
Branch coverage:78.5% (11 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Location()100%1100%
DoInferWorld(...)100%6100%
Tokens()50%4100%
Tokens()100%2100%
RequiredFunctions()100%1100%
Equals(...)100%1100%
Equals(...)50%2100%
GetHashCode()100%10%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for folding expressions.
 8    /// </summary>
 9    public class FoldExpression : Expression, IEquatable<FoldExpression?> {
 10        /// <summary>
 11        /// Creates a new instance of a folding expression that folds the <paramref name="location"/>.
 12        /// </summary>
 13        /// <param name="location">Location that is folded.</param>
 6614        public FoldExpression(string location) {
 3315            Location = location;
 3316        }
 17        /// <summary>
 18        /// Concrete location that is folded to its abstract location.
 19        /// </summary>
 9320        public string Location { get; }
 21        /// <inheritdoc/>
 1722        protected override World DoInferWorld(GlobalEnvironment phi, LocalEnvironment gamma, Heap heap) {
 1723            var labs = new Location(Location, true);
 1724            if (!heap.TryGetBinding(labs, out var b1))
 125                throw new IllFormedException(this, $"Cannot fold ~{Location} without heap binding!");
 1626            var lj = new Location(Location, false);
 1627            if (!heap.TryGetBinding(lj, out var b2))
 128                throw new IllFormedException(this, $"Cannot fold {Location} because it was never unfolded!");
 1529            if (!Heap.SubBlock(gamma, b2, b1))
 130                throw new IllFormedException(this, $"Cannot fold {Location} because it doesnt match abstract constraints
 5431            return new World(IntegerType.Void, heap.Filter(i => i != lj));
 1432        }
 33        /// <inheritdoc/>
 2734        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 2735            yield return "[";
 2736            if (args.SpaceBeforeFoldingKeywords) yield return " ";
 2737            yield return "fold";
 2738            yield return " ";
 2739            yield return Location;
 2740            if (args.SpaceAfterFoldingKeywords) yield return " ";
 2741            yield return "]";
 2742        }
 43        /// <inheritdoc/>
 1344        public override IEnumerable<StringFormatterToken> Tokens(CSourceFormat args) {
 1345            yield return "/* ";
 23446            foreach (var tk in Tokens((NanoCSourceFormat)args)) yield return tk;
 1347            yield return " */";
 1348        }
 49        /// <inheritdoc/>
 1250        public override IEnumerable<string> RequiredFunctions() { yield break; }
 51        #region Equality checks
 52        /// <inheritdoc/>
 1553        public override bool Equals(object? obj) => Equals(obj as FoldExpression);
 54        /// <inheritdoc/>
 1555        public bool Equals(FoldExpression? other) => !(other is null) && Location == other.Location;
 56        /// <inheritdoc/>
 057        public override int GetHashCode() => HashCode.Combine(Location);
 58        /// <inheritdoc/>
 059        public static bool operator ==(FoldExpression? left, FoldExpression? right) => EqualityComparer<FoldExpression?>
 60        /// <inheritdoc/>
 061        public static bool operator !=(FoldExpression? left, FoldExpression? right) => !(left == right);
 62        #endregion
 63    }
 64}