< Summary

Class:NanoCLang.Entities.RawWorld
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\World.cs
Covered lines:20
Uncovered lines:4
Coverable lines:24
Total lines:128
Line coverage:83.3% (20 of 24)
Covered branches:16
Total branches:22
Branch coverage:72.7% (16 of 22)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Type()100%1100%
get_Heap()100%1100%
Tokens()100%6100%
WorldOperator()66.66%12100%
Build(...)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\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>
 16415        public RawWorld(Type type, IHeapElement[] heap) {
 8216            Type = type;
 8217            Heap = heap;
 8218        }
 19        /// <summary>
 20        /// Type of the world.
 21        /// </summary>
 15722        public Type Type { get; }
 23        /// <summary>
 24        /// Modified heap of the world.
 25        /// </summary>
 13226        public IHeapElement[] Heap { get; }
 27        /// <inheritdoc/>
 2428        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 125429            foreach (var tk in Type.Tokens(args)) yield return tk;
 28830            foreach (var tk in WorldOperator(args)) yield return tk;
 243031            foreach (var tk in Heap.Tokens(args)) yield return tk;
 2432        }
 33        /// <summary>
 34        /// Print the world operator
 35        /// </summary>
 36        /// <param name="args">Formatter arguments</param>
 37        /// <returns>Token enumeration</returns>
 4738        internal static IEnumerable<StringFormatterToken> WorldOperator(NanoCSourceFormat args) {
 23539            for (int i = 0; i < args.NewlinesBeforeWorldOperator; i++) yield return new NewLineToken();
 4740            if (args.NewlinesBeforeWorldOperator <= 0 && args.SpaceBeforeWorldOperator) yield return " ";
 4741            yield return "/";
 9442            for (int i = 0; i < args.NewlinesAfterWorldOperator; i++) yield return new NewLineToken();
 9443            if (args.NewlinesAfterWorldOperator <= 0 && args.SpaceAfterWorldOperator) yield return " ";
 4744        }
 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>
 6450        public World Build(GlobalEnvironment phi) => new World(Type, Heap.GenerateHeap(phi));
 51        #region Equality checks
 52        /// <inheritdoc/>
 053        public override bool Equals(object? obj) => Equals(obj as RawWorld);
 54        /// <inheritdoc/>
 2255        public bool Equals(RawWorld? other) => !(other is null) && EqualityComparer<Type>.Default.Equals(Type, other.Typ
 56        /// <inheritdoc/>
 057        public override int GetHashCode() => HashCode.Combine(Type, Heap);
 58        /// <inheritdoc/>
 059        public static bool operator ==(RawWorld? left, RawWorld? right) => EqualityComparer<RawWorld?>.Default.Equals(le
 60        /// <inheritdoc/>
 061        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>
 73        public World(Type type, Heap heap) {
 74            Type = type;
 75            Heap = heap;
 76        }
 77        /// <summary>
 78        /// Implicitly converts a built world into a raw world (trivial).
 79        /// </summary>
 80        /// <param name="world">World to convert.</param>
 81        public static implicit operator RawWorld(World world) => new RawWorld(world.Type, new IHeapElement[] { world.Hea
 82        /// <summary>
 83        /// Type of the world.
 84        /// </summary>
 85        public Type Type { get; }
 86        /// <summary>
 87        /// Modified heap of the world.
 88        /// </summary>
 89        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>
 94        public void WellFormed(LocalEnvironment gamma) {
 95            VerbConsole.WriteLine(VerbosityLevel.Default, "WF-World");
 96            Heap.WellFormed(gamma);
 97            Type.WellFormed(gamma, Heap);
 98        }
 99        /// <inheritdoc/>
 100        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 101            foreach (var tk in Type.Tokens(args)) yield return tk;
 102            foreach (var tk in RawWorld.WorldOperator(args)) yield return tk;
 103            foreach (var tk in Heap.Tokens(args)) yield return tk;
 104        }
 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.</
 111        public bool SubWorld(LocalEnvironment gamma, World other) {
 112            VerbConsole.WriteLine(VerbosityLevel.Default, "<:-World");
 113            return Type.SubType(gamma, other.Type) && Heap.SubHeap(gamma, other.Heap);
 114        }
 115        #region Equality checks
 116        /// <inheritdoc/>
 117        public override bool Equals(object? obj) => Equals(obj as World);
 118        /// <inheritdoc/>
 119        public bool Equals(World? other) => !(other is null) && EqualityComparer<Type>.Default.Equals(Type, other.Type) 
 120        /// <inheritdoc/>
 121        public override int GetHashCode() => HashCode.Combine(Type, Heap);
 122        /// <inheritdoc/>
 123        public static bool operator ==(World? left, World? right) => EqualityComparer<World?>.Default.Equals(left, right
 124        /// <inheritdoc/>
 125        public static bool operator !=(World? left, World? right) => !(left == right);
 126        #endregion
 127    }
 128}