< Summary

Class:NanoCLang.Entities.Base
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Base.cs
Covered lines:3
Uncovered lines:2
Coverable lines:5
Total lines:49
Line coverage:60% (3 of 5)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToString()100%1100%
ToCString()100%10%
Tokens(...)100%10%
op_Equality(...)100%1100%
op_Inequality(...)100%1100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2
 3namespace NanoCLang.Entities {
 4    /// <summary>
 5    /// <see cref="Base"/> provides a superclass for all NanoC entities.
 6    /// All NanoC entities implement a conversion to a token stream to create a generic source code formatter.
 7    /// This can also be used to transpile the syntax.
 8    /// </summary>
 9    public abstract class Base : ITokenStream<StringFormatterToken, NanoCSourceFormat>, ITokenStream<StringFormatterToke
 10        /// <summary>
 11        /// Formats the code using the <see cref="StringFormatter"/> and returns it.
 12        /// </summary>
 13        /// <returns>String representation of the entity.</returns>
 134314        public override string ToString() => new StringFormatter().ToString(Tokens(new NanoCSourceFormat()));
 15        /// <summary>
 16        /// Translates the entity to C code using the <see cref="StringFormatter"/> and returns it.
 17        /// </summary>
 18        /// <returns>String representation of the entity.</returns>
 019        public virtual string ToCString() => new StringFormatter().ToString(Tokens(new CSourceFormat()));
 20        /// <inheritdoc cref="ITokenStream{T, A}.Tokens(A)"/>
 21        public abstract IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args);
 22        /// <summary>
 23        /// Converts the entity into it's C language equivalent string token stream.
 24        /// </summary>
 25        /// <param name="args">Formatter arguments.</param>
 26        /// <returns>C token stream</returns>
 027        public virtual IEnumerable<StringFormatterToken> Tokens(CSourceFormat args) => throw new System.InvalidProgramEx
 28        #region Equality checks
 29        /// <summary>
 30        /// Checks if the entities are equal.
 31        /// </summary>
 32        /// <param name="left">Left hand operand.</param>
 33        /// <param name="right">Right hand operand.</param>
 34        /// <returns><see langword="true"/> iff <paramref name="left"/> is equal to <paramref name="right"/>.</returns>
 80635        public static bool operator ==(Base left, Base right) => EqualityComparer<Base?>.Default.Equals(left, right);
 36        /// <summary>
 37        /// Checks if the entities are unequal.
 38        /// </summary>
 39        /// <param name="left">Left hand operand.</param>
 40        /// <param name="right">Right hand operand.</param>
 41        /// <returns><see langword="true"/> iff <paramref name="left"/> is not equal to <paramref name="right"/>.</retur
 11442        public static bool operator !=(Base left, Base right) => !(left == right);
 43        /// <inheritdoc/>
 44        public abstract override bool Equals(object? obj);
 45        /// <inheritdoc/>
 46        public abstract override int GetHashCode();
 47        #endregion
 48    }
 49}