< Summary

Class:NanoCLang.Entities.MainCall
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Program\MainCall.cs
Covered lines:33
Uncovered lines:3
Coverable lines:36
Total lines:65
Line coverage:91.6% (33 of 36)
Covered branches:9
Total branches:12
Branch coverage:75% (9 of 12)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Name()100%1100%
WellFormed(...)100%4100%
Tokens()50%4100%
Tokens(...)100%2100%
Equals(...)100%1100%
Equals(...)50%2100%
GetHashCode()100%10%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6namespace NanoCLang.Entities {
 7    /// <summary>
 8    /// Provides a class for the main call.
 9    /// </summary>
 10    public class MainCall : Program, IEquatable<MainCall?> {
 11        /// <summary>
 12        /// Creates a new main call that calls the main function named <paramref name="name"/> without parameters.
 13        /// </summary>
 14        /// <param name="name">Name of the main function.</param>
 5415        public MainCall(string name) {
 2716            Name = name;
 2717        }
 18        /// <summary>
 19        /// Name of the main function.
 20        /// </summary>
 6621        public string Name { get; }
 22        /// <inheritdoc/>
 923        public override World WellFormed(GlobalEnvironment phi) {
 924            VerbConsole.WriteLine(VerbosityLevel.Default, $"WF-MainCall: {Name}");
 925            if (!phi.TryGetValue(Name, out var rawschema))
 126                throw new IllFormedException(this, $"Main call to unknown function {Name}!");
 827            var schema = rawschema.Build(phi);
 828            if (!schema.Heap.IsAbstract())
 129                throw new IllFormedException(this, $"Main call is invalid because {Name} operates on concrete locations!
 730            return schema.World;
 731        }
 32        /// <inheritdoc/>
 833        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 834            yield return Name;
 835            if (args.SpaceAfterFunctionName) yield return " ";
 836            yield return "(";
 837            if (args.SpaceInEmptyArgList) yield return " ";
 838            yield return ")";
 839        }
 40        /// <inheritdoc/>
 1241        public override IEnumerable<StringFormatterToken> Tokens(CSourceFormat args) => Name is null ? Enumerable.Empty<
 1242            : Program.PrintHeader(args).Concat(new FunctionBinding(
 1243                "main",
 1244                new FunctionDefinition(
 1245                    new ConcatenationExpression(new FunctionCallExpression(Name, new string[] { }),
 1246                        new IntegerConstant(0, 4)),
 1247                    new RawFunctionSchema(
 1248                        new string[] { },
 1249                        new TypeParameter[] { },
 1250                        new IHeapElement[] { },
 1251                        new RawWorld(new IntegerType(4), new IHeapElement[] { }))), new MainCall(null!)).Tokens(args));
 52        #region Equality checks
 53        /// <inheritdoc/>
 1054        public override bool Equals(object? obj) => Equals(obj as MainCall);
 55        /// <inheritdoc/>
 1056        public bool Equals(MainCall? other) => !(other is null) && Name == other.Name;
 57        /// <inheritdoc/>
 058        public override int GetHashCode() => HashCode.Combine(Name);
 59        /// <inheritdoc/>
 060        public static bool operator ==(MainCall? left, MainCall? right) => EqualityComparer<MainCall?>.Default.Equals(le
 61        /// <inheritdoc/>
 062        public static bool operator !=(MainCall? left, MainCall? right) => !(left == right);
 63        #endregion
 64    }
 65}