< Summary

Class:NanoCLang.Entities.World
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\World.cs
Covered lines:23
Uncovered lines:3
Coverable lines:26
Total lines:128
Line coverage:88.4% (23 of 26)
Covered branches:9
Total branches:12
Branch coverage:75% (9 of 12)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
op_Implicit(...)100%1100%
get_Type()100%1100%
get_Heap()100%1100%
WellFormed(...)100%1100%
Tokens()100%6100%
SubWorld(...)50%2100%
Equals(...)100%1100%
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\World.cs

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for worlds.
 8    /// </summary>
 9    public class RawWorld : Base, IEquatable<RawWorld?> {
 10        /// <summary>
 11        /// Creates a new world instance that gives an expression a return <paramref name="type"/> and a modified <param
 12        /// </summary>
 13        /// <param name="type">Type of the world.</param>
 14        /// <param name="heap">Modified heap of the world.</param>
 15        public RawWorld(Type type, IHeapElement[] heap) {
 16            Type = type;
 17            Heap = heap;
 18        }
 19        /// <summary>
 20        /// Type of the world.
 21        /// </summary>
 22        public Type Type { get; }
 23        /// <summary>
 24        /// Modified heap of the world.
 25        /// </summary>
 26        public IHeapElement[] Heap { get; }
 27        /// <inheritdoc/>
 28        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 29            foreach (var tk in Type.Tokens(args)) yield return tk;
 30            foreach (var tk in WorldOperator(args)) yield return tk;
 31            foreach (var tk in Heap.Tokens(args)) yield return tk;
 32        }
 33        /// <summary>
 34        /// Print the world operator
 35        /// </summary>
 36        /// <param name="args">Formatter arguments</param>
 37        /// <returns>Token enumeration</returns>
 38        internal static IEnumerable<StringFormatterToken> WorldOperator(NanoCSourceFormat args) {
 39            for (int i = 0; i < args.NewlinesBeforeWorldOperator; i++) yield return new NewLineToken();
 40            if (args.NewlinesBeforeWorldOperator <= 0 && args.SpaceBeforeWorldOperator) yield return " ";
 41            yield return "/";
 42            for (int i = 0; i < args.NewlinesAfterWorldOperator; i++) yield return new NewLineToken();
 43            if (args.NewlinesAfterWorldOperator <= 0 && args.SpaceAfterWorldOperator) yield return " ";
 44        }
 45        /// <summary>
 46        /// Creates the world represented by the raw world by expanding structures with the environment <paramref name="
 47        /// </summary>
 48        /// <param name="phi">Global environment to expand structures with.</param>
 49        /// <returns>Built world.</returns>
 50        public World Build(GlobalEnvironment phi) => new World(Type, Heap.GenerateHeap(phi));
 51        #region Equality checks
 52        /// <inheritdoc/>
 53        public override bool Equals(object? obj) => Equals(obj as RawWorld);
 54        /// <inheritdoc/>
 55        public bool Equals(RawWorld? other) => !(other is null) && EqualityComparer<Type>.Default.Equals(Type, other.Typ
 56        /// <inheritdoc/>
 57        public override int GetHashCode() => HashCode.Combine(Type, Heap);
 58        /// <inheritdoc/>
 59        public static bool operator ==(RawWorld? left, RawWorld? right) => EqualityComparer<RawWorld?>.Default.Equals(le
 60        /// <inheritdoc/>
 61        public static bool operator !=(RawWorld? left, RawWorld? right) => !(left == right);
 62        #endregion
 63    }
 64    /// <summary>
 65    /// Provides a class for worlds.
 66    /// </summary>
 67    public class World : Base, IEquatable<World?> {
 68        /// <summary>
 69        /// Creates a new world instance that gives an expression a return <paramref name="type"/> and a modified <param
 70        /// </summary>
 71        /// <param name="type">Type of the world.</param>
 72        /// <param name="heap">Modified heap of the world.</param>
 34073        public World(Type type, Heap heap) {
 17074            Type = type;
 17075            Heap = heap;
 17076        }
 77        /// <summary>
 78        /// Implicitly converts a built world into a raw world (trivial).
 79        /// </summary>
 80        /// <param name="world">World to convert.</param>
 2181        public static implicit operator RawWorld(World world) => new RawWorld(world.Type, new IHeapElement[] { world.Hea
 82        /// <summary>
 83        /// Type of the world.
 84        /// </summary>
 19285        public Type Type { get; }
 86        /// <summary>
 87        /// Modified heap of the world.
 88        /// </summary>
 30889        public Heap Heap { get; }
 90        /// <summary>
 91        /// Checks if the world is well-formed and raises an exception if it is ill-formed.
 92        /// </summary>
 93        /// <exception cref="IllFormedException">World is ill-formed.</exception>
 3094        public void WellFormed(LocalEnvironment gamma) {
 3095            VerbConsole.WriteLine(VerbosityLevel.Default, "WF-World");
 3096            Heap.WellFormed(gamma);
 3097            Type.WellFormed(gamma, Heap);
 3098        }
 99        /// <inheritdoc/>
 1100        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 42101            foreach (var tk in Type.Tokens(args)) yield return tk;
 12102            foreach (var tk in RawWorld.WorldOperator(args)) yield return tk;
 84103            foreach (var tk in Heap.Tokens(args)) yield return tk;
 1104        }
 105        /// <summary>
 106        /// Checks if the current world is a subworld of the <paramref name="other"/> world in the given environment.
 107        /// </summary>
 108        /// <param name="gamma">Environment to check the subworld in.</param>
 109        /// <param name="other">Other world to check against.</param>
 110        /// <returns><see langword="true"/> iff the current world is a subworld of the <paramref name="other"/> world.</
 13111        public bool SubWorld(LocalEnvironment gamma, World other) {
 13112            VerbConsole.WriteLine(VerbosityLevel.Default, "<:-World");
 13113            return Type.SubType(gamma, other.Type) && Heap.SubHeap(gamma, other.Heap);
 13114        }
 115        #region Equality checks
 116        /// <inheritdoc/>
 2117        public override bool Equals(object? obj) => Equals(obj as World);
 118        /// <inheritdoc/>
 3119        public bool Equals(World? other) => !(other is null) && EqualityComparer<Type>.Default.Equals(Type, other.Type) 
 120        /// <inheritdoc/>
 0121        public override int GetHashCode() => HashCode.Combine(Type, Heap);
 122        /// <inheritdoc/>
 0123        public static bool operator ==(World? left, World? right) => EqualityComparer<World?>.Default.Equals(left, right
 124        /// <inheritdoc/>
 0125        public static bool operator !=(World? left, World? right) => !(left == right);
 126        #endregion
 127    }
 128}