< Summary

Class:NanoCLang.Entities.Expression
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\Expression.cs
Covered lines:6
Uncovered lines:1
Coverable lines:7
Total lines:51
Line coverage:85.7% (6 of 7)
Covered branches:1
Total branches:2
Branch coverage:50% (1 of 2)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
InferWorld(...)100%1100%
get_FixedWorld()100%1100%
CheckType(...)50%2100%
Tokens(...)100%10%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System.Collections.Generic;
 3
 4namespace NanoCLang.Entities {
 5    /// <summary>
 6    /// Provides an abstract superclass for all valid NanoC expressions.
 7    /// This class also implements the well formedness and type checking/inference mechanisms for expressions.
 8    /// </summary>
 9    public abstract class Expression : Base {
 10        /// <summary>
 11        /// Infer the world of the expression and throw an exception if it is ill-formed.
 12        /// Additionally fixes the resulting world to this entity.
 13        /// </summary>
 14        /// <param name="phi">Global Environemt to check the expression with.</param>
 15        /// <param name="gamma">Local Environemt to check the expression with.</param>
 16        /// <param name="heap">Input heap of the expression.</param>
 17        /// <exception cref="IllFormedException">Expression is ill-formed.</exception>
 20818        public World InferWorld(GlobalEnvironment phi, LocalEnvironment gamma, Heap heap) => FixedWorld = DoInferWorld(p
 19        /// <summary>
 20        /// Infer the world of the expression and throw an exception if it is ill-formed.
 21        /// </summary>
 22        /// <param name="phi">Global Environemt to check the expression with.</param>
 23        /// <param name="gamma">Local Environemt to check the expression with.</param>
 24        /// <param name="heap">Input heap of the expression.</param>
 25        /// <exception cref="IllFormedException">Expression is ill-formed.</exception>
 26        protected abstract World DoInferWorld(GlobalEnvironment phi, LocalEnvironment gamma, Heap heap);
 27        /// <summary>
 28        /// Gets the world that was fixed to this expression during type-checking.
 29        /// </summary>
 23730        public World? FixedWorld { get; protected set; }
 31        /// <summary>
 32        /// Typecheck the expression with the <paramref name="world"/> and throw an exception if it is ill-formed.
 33        /// </summary>
 34        /// <param name="phi">Global Environemt to check the expression with.</param>
 35        /// <param name="gamma">Local Environemt to check the expression with.</param>
 36        /// <param name="heap">Input heap of the expression.</param>
 37        /// <param name="world">World to typecheck with.</param>
 38        /// <exception cref="IllFormedException">Expression is ill-formed.</exception>
 139        public virtual void CheckType(GlobalEnvironment phi, LocalEnvironment gamma, Heap heap, World world) {
 140            var inferred = InferWorld(phi, gamma, heap);
 141            if (!inferred.SubWorld(gamma, world)) throw new IllFormedException(this, $"This is not of world {world}!");
 142        }
 43        /// <summary>
 44        /// Gets an enumeration of required function calls. Can be used to check if a function is recursive.
 45        /// </summary>
 46        /// <returns>Enumeration of called functions.</returns>
 47        public abstract IEnumerable<string> RequiredFunctions();
 48        /// <inheritdoc/>
 049        public override IEnumerable<StringFormatterToken> Tokens(CSourceFormat args) => Tokens((NanoCSourceFormat)args);
 50    }
 51}