< Summary

Class:NanoCLang.Entities.BinaryExpression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BinaryExpression\BinaryExpression.cs
Covered lines:33
Uncovered lines:4
Coverable lines:37
Total lines:81
Line coverage:89.1% (33 of 37)
Covered branches:22
Total branches:22
Branch coverage:100% (22 of 22)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Left()100%1100%
get_Operation()100%1100%
get_Right()100%1100%
WellFormed(...)100%1100%
Tokens()100%8100%
NoReturnTokens()100%8100%
IndexOperation(...)100%10%
Equals(...)100%1100%
Equals(...)100%6100%
GetHashCode()100%10%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a superclass for binary expressions.
 8    /// </summary>
 9    public abstract class BinaryExpression : PureExpression, IEquatable<BinaryExpression?> {
 10        /// <summary>
 11        /// Creates a new instance of a binary operation applied to <paramref name="left"/> and <paramref name="right"/>
 12        /// </summary>
 13        /// <param name="left">Left hand expression of the operator.</param>
 14        /// <param name="operation">Operation to evaluate for the expression.</param>
 15        /// <param name="right">Right hand expression of the operator.</param>
 473016        public BinaryExpression(PureExpression left, string operation, PureExpression right) {
 236517            Left = left;
 236518            Operation = operation;
 236519            Right = right;
 236520        }
 21        /// <summary>
 22        /// Left hand expression of the operator.
 23        /// </summary>
 391424        public PureExpression Left { get; }
 25        /// <summary>
 26        /// Operation to evaluate for the expression.
 27        /// </summary>
 169328        public string Operation { get; }
 29        /// <summary>
 30        /// Right hand expression of the operator.
 31        /// </summary>
 350932        public PureExpression Right { get; }
 33        /// <inheritdoc/>
 17234        public override void WellFormed(LocalEnvironment gamma) {
 17235            VerbConsole.WriteLine(VerbosityLevel.Default, $"WF-BinOp: {this}");
 17236            Left.WellFormed(gamma);
 17237            Right.WellFormed(gamma);
 17238        }
 39        /// <inheritdoc/>
 40        protected abstract override Type DoInferType(LocalEnvironment gamma);
 41        /// <inheritdoc/>
 103842        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 103843            yield return "(";
 1540844            foreach (var tk in Left.Tokens(args)) yield return tk;
 207645            if (args.SpaceBeforeBinOp) yield return " ";
 103846            yield return Operation;
 207647            if (args.SpaceAfterBinOp) yield return " ";
 1788648            foreach (var tk in Right.Tokens(args)) yield return tk;
 103849            yield return ")";
 103850        }
 51        /// <inheritdoc/>
 2952        protected override IEnumerable<StringFormatterToken> NoReturnTokens(CSourceFormat args) {
 2953            yield return "(";
 18654            foreach (var tk in Left.Tokens(args)) yield return tk;
 5855            if (args.SpaceBeforeBinOp) yield return " ";
 2956            yield return Operation;
 5857            if (args.SpaceAfterBinOp) yield return " ";
 41458            foreach (var tk in Right.Tokens(args)) yield return tk;
 2959            yield return ")";
 2960        }
 61        /// <summary>
 62        /// Applies the operation on indices and gives a superset of all possible values as output index.
 63        /// </summary>
 64        /// <param name="left">Left hand operand.</param>
 65        /// <param name="right">Right hand operand.</param>
 66        /// <returns>Resulting index that covers all possible values.</returns>
 067        public virtual Index IndexOperation(Index left, Index right) => new ArbitraryIndex();
 68        #region Equality checks
 69        /// <inheritdoc/>
 34570        public override bool Equals(object? obj) => Equals(obj as BinaryExpression);
 71        /// <inheritdoc/>
 34572        public bool Equals(BinaryExpression? other) => !(other is null) && Operation == other.Operation && EqualityCompa
 73        /// <inheritdoc/>
 074        public override int GetHashCode() => HashCode.Combine(Left, Operation, Right);
 75        /// <inheritdoc/>
 076        public static bool operator ==(BinaryExpression? left, BinaryExpression? right) => EqualityComparer<BinaryExpres
 77        /// <inheritdoc/>
 078        public static bool operator !=(BinaryExpression? left, BinaryExpression? right) => !(left == right);
 79        #endregion
 80    }
 81}