< Summary

Class:NanoCLang.Entities.BlockType
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\BlockType.cs
Covered lines:16
Uncovered lines:5
Coverable lines:21
Total lines:63
Line coverage:76.1% (16 of 21)
Covered branches:10
Total branches:12
Branch coverage:83.3% (10 of 12)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Index()100%1100%
get_Type()100%1100%
get_BaseType()100%1100%
Tokens()100%8100%
SubBlock(...)100%10%
Replace(...)100%1100%
Equals(...)100%10%
Equals(...)50%4100%
GetHashCode()100%10%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for blocks in a <see cref="LocationBinding"/>.
 8    /// </summary>
 9    public class BlockType : Base, IEquatable<BlockType?>, ISubstitutable<BlockType> {
 10        /// <summary>
 11        /// Creates a new instance of a block type that maps the indices to the given <paramref name="type"/>.
 12        /// </summary>
 13        /// <param name="index">Indices of the <paramref name="type"/> in the block.</param>
 14        /// <param name="type">Type of the allocation.</param>
 88015        public BlockType(Index index, Type type) {
 44016            Index = index;
 44017            Type = type;
 44018        }
 19        /// <summary>
 20        /// Valid offset(s) within the block.
 21        /// </summary>
 117122        public Index Index { get; }
 23        /// <summary>
 24        /// Gets or sets the type of the allocation at the <see cref="Index"/>.
 25        /// </summary>
 187626        public Type Type { get; internal set; }
 27        /// <summary>
 28        /// Gets a new block with the refinements set to true (being types replaced with their base types).
 29        /// </summary>
 1130        public BlockType BaseType => new BlockType((Index)Index.Clone(), (Type)Type.BaseType.Clone());
 31        /// <inheritdoc/>
 6332        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 60033            foreach (var tk in Index.Tokens(args)) yield return tk;
 12634            if (args.SpaceBeforeTypeOperator) yield return " ";
 6335            yield return ":";
 12636            if (args.SpaceAfterTypeOperator) yield return " ";
 206737            foreach (var tk in Type.Tokens(args)) yield return tk;
 6338        }
 39        /// <summary>
 40        /// Checks if the current block is a subtype of the <paramref name="other"/> block in the given environment.
 41        /// </summary>
 42        /// <param name="gamma">Environment to check the subtype in.</param>
 43        /// <param name="other">Other block to check against.</param>
 44        /// <returns><see langword="true"/> iff the current block is a subtype of the <paramref name="other"/> type.</re
 45        public bool SubBlock(LocalEnvironment gamma, BlockType other)
 046            => Type.SubType(gamma, other.Type);
 47        /// <inheritdoc/>
 48        public BlockType Replace(Substitutor sub)
 26449            => new BlockType((Index)Index.Clone(), Type.Replace(sub));
 50        #region Equality checks
 51        /// <inheritdoc/>
 052        public override bool Equals(object? obj) => Equals(obj as BlockType);
 53        /// <inheritdoc/>
 9154        public bool Equals(BlockType? other) => !(other is null) && EqualityComparer<Index>.Default.Equals(Index, other.
 55        /// <inheritdoc/>
 056        public override int GetHashCode() => System.HashCode.Combine(Index, Type);
 57        /// <inheritdoc/>
 058        public static bool operator ==(BlockType? left, BlockType? right) => EqualityComparer<BlockType?>.Default.Equals
 59        /// <inheritdoc/>
 060        public static bool operator !=(BlockType? left, BlockType? right) => !(left == right);
 61        #endregion
 62    }
 63}