< Summary

Class:NanoCLang.Entities.HeapElementExtensions
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Heap\IHeapElement.cs
Covered lines:14
Uncovered lines:0
Coverable lines:14
Total lines:50
Line coverage:100% (14 of 14)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
GenerateHeap(...)100%2100%
GenerateHeap(...)100%1100%
Tokens(...)100%2100%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides an interface that makes heap elements available to the heap constructor.
 8    /// If new objects inherit from this interface the function <see cref="HeapElementComparer.Equals(IHeapElement[], IH
 9    /// </summary>
 10    public interface IHeapElement : ITokenStream<StringFormatterToken, NanoCSourceFormat> {
 11        /// <summary>
 12        /// Generates the available location bindings for the heap constructor from the current environment.
 13        /// </summary>
 14        /// <param name="phi">Global environment that supplies the structure definitions.</param>
 15        /// <param name="links">Structure location links.</param>
 16        /// <returns>Enumeration of generated heap bindings.</returns>
 17        IEnumerable<LocationBinding> GetBindings(GlobalEnvironment phi, out IEnumerable<KeyValuePair<string, string>> li
 18    }
 19    /// <summary>
 20    /// Provides an extension class for heap element enumerations.
 21    /// </summary>
 22    public static class HeapElementExtensions {
 23        /// <summary>
 24        /// Generates a new heap from the list of heap generators.
 25        /// </summary>
 26        /// <param name="elems">Heap generators.</param>
 27        /// <param name="phi">Environment to generate with.</param>
 28        /// <param name="links">Structure location links.</param>
 29        /// <returns>New heap with all bindings.</returns>
 30        /// <exception cref="IllFormedException">Heap is not well formed.</exception>
 4631        public static Heap GenerateHeap(this IEnumerable<IHeapElement> elems, GlobalEnvironment phi, out IEnumerable<Key
 4632            var linkList = new List<KeyValuePair<string, string>>();
 4633            var heapBindings = new List<LocationBinding>();
 31234            foreach (var elem in elems) {
 5835                heapBindings.AddRange(elem.GetBindings(phi, out var newLinks));
 5836                linkList.AddRange(newLinks);
 5837            }
 4638            links = linkList;
 4639            return new Heap(heapBindings);
 4640        }
 41        /// <inheritdoc cref="GenerateHeap(IEnumerable{IHeapElement}, GlobalEnvironment, out IEnumerable{KeyValuePair{st
 42        public static Heap GenerateHeap(this IEnumerable<IHeapElement> elems, GlobalEnvironment phi)
 14643            => new Heap(elems.SelectMany(i => i.GetBindings(phi, out _)));
 44        /// <inheritdoc cref="ITokenStream{T, A}.Tokens(A)"/>
 45        public static IEnumerable<StringFormatterToken> Tokens(this IHeapElement[] elems, NanoCSourceFormat args)
 4546        => elems.Length == 0
 4547            ? Enumerable.Repeat<StringFormatterToken>("emp", 1)
 4548            : StringFormatterToken.Separated(elems, args, args.HeapBindingListSeparator);
 49    }
 50}