< Summary

Class:NanoCLang.Entities.ReferenceType
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\BasicType\ReferenceType.cs
Covered lines:31
Uncovered lines:4
Coverable lines:35
Total lines:78
Line coverage:88.5% (31 of 35)
Covered branches:10
Total branches:12
Branch coverage:83.3% (10 of 12)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Location()100%1100%
get_Offsets()100%1100%
get_Size()100%1100%
get_PointerSize()100%1100%
Clone()100%1100%
Replace(...)100%1100%
get_Abstract()100%1100%
get_Concrete()100%1100%
WellFormed(...)50%280%
Tokens()83.33%6100%
Tokens()100%1100%
Equals(...)100%1100%
Equals(...)100%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\BasicType\ReferenceType.cs

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for NanoC reference types.
 8    /// </summary>
 9    public class ReferenceType : BasicType, IEquatable<ReferenceType?> {
 10        /// <summary>
 11        /// Creates a new instance of a reference type.
 12        /// </summary>
 13        /// <param name="location">Location that the reference refers to.</param>
 14        /// <param name="offsets">Offset at this <paramref name="location"/>.</param>
 44215        public ReferenceType(Location location, Index offsets) {
 22116            Location = location;
 22117            Offsets = offsets;
 22118        }
 19        /// <summary>
 20        /// Location that the type refers to.
 21        /// </summary>
 84522        public Location Location { get; }
 23        /// <summary>
 24        /// Offset of the reference at the given <see cref="Location"/>.
 25        /// </summary>
 73026        public Index Offsets { get; }
 27        /// <inheritdoc/>
 4628        public override int Size => PointerSize;
 29        /// <inheritdoc cref="Size"/>
 4730        public static int PointerSize { get; set; } = 8;
 31        /// <inheritdoc/>
 332        public override object Clone() => new ReferenceType((Location)Location.Clone(), (Index)Offsets.Clone());
 33        /// <inheritdoc/>
 34        public override Type Replace(Substitutor sub)
 7335            => new ReferenceType(Location.Replace(sub), Offsets.Replace(sub));
 36        /// <summary>
 37        /// <c>true</c> iff the reference points to an abstract location, else <see langword="false"/>.
 38        /// </summary>
 3639        public bool Abstract => Location.Abstract;
 40        /// <summary>
 41        /// <c>true</c> iff the reference points to an concrete location, else <see langword="false"/>.
 42        /// </summary>
 943        public bool Concrete => Location.Concrete;
 44        /// <inheritdoc/>
 5145        public override void WellFormed(LocalEnvironment gamma, Heap heap) {
 5146            VerbConsole.WriteLine(VerbosityLevel.Default, $"WF-Ref: {this}");
 5147            if (!heap.ContainsAbstract(Location.Name))
 048                throw new IllFormedException(Location, $"Cannot refer to invalid location {Location}!");
 5149        }
 50        /// <inheritdoc/>
 19051        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 19052            yield return "ref";
 19053            if (args.SpaceAfterFunctionName) yield return " ";
 19054            yield return "(";
 160255            foreach (var tk in Location.Tokens(args)) yield return tk;
 19056            yield return args.ParameterListSeparator;
 201657            foreach (var tk in Offsets.Tokens(args)) yield return tk;
 19058            yield return ")";
 19059        }
 60        /// <inheritdoc/>
 4761        public override IEnumerable<StringFormatterToken> Tokens(CSourceFormat args) {
 4762            yield return "int8_t";
 4763            yield return "*";
 4764        }
 65        #region Equality checks
 66        /// <inheritdoc/>
 17567        public override bool Equals(object? obj) => Equals(obj as ReferenceType);
 68        /// <inheritdoc/>
 17569        public bool Equals(ReferenceType? other) => !(other is null) && EqualityComparer<Location>.Default.Equals(Locati
 70        /// <inheritdoc/>
 071        public override int GetHashCode() => HashCode.Combine(Location, Offsets);
 72        /// <inheritdoc/>
 073        public static bool operator ==(ReferenceType? left, ReferenceType? right) => EqualityComparer<ReferenceType?>.De
 74        /// <inheritdoc/>
 075        public static bool operator !=(ReferenceType? left, ReferenceType? right) => !(left == right);
 76        #endregion
 77    }
 78}