< Summary

Class:NanoCLang.Entities.BasicType
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\BasicType\BasicType.cs
Covered lines:30
Uncovered lines:1
Coverable lines:31
Total lines:60
Line coverage:96.7% (30 of 31)
Covered branches:33
Total branches:38
Branch coverage:86.8% (33 of 38)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_BaseType()100%1100%
ProperSubType(...)83.33%680%
ProperBasicSubType(...)100%30100%
Replace(...)100%1100%
get_Refinement()100%1100%
SuperType(...)16.66%6100%

File(s)

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

#LineLine coverage
 1using NanoCLang.Environemnts;
 2using System;
 3
 4namespace NanoCLang.Entities {
 5    /// <summary>
 6    /// Provides a superclass for all basic type objects.
 7    /// </summary>
 8    public abstract class BasicType : Type, ICloneable {
 9        /// <inheritdoc/>
 35310        public override BasicType BaseType => this;
 11        /// <inheritdoc/>
 5712        public override bool ProperSubType(LocalEnvironment gamma, Type other) {
 13            return other switch {
 5014                BasicType o => ProperBasicSubType(o),
 15                // Base type can only be a subtype of a refined type if the refined type has a trivially true refinement
 1416                RefinedType o => gamma.With("v", BaseType, gamma => NanoCSMT.Default.TryEvalConstExpression(gamma, o.Ref
 017                _ => throw new InvalidProgramException("Expected basic or refined type here!")
 18            };
 5719        }
 5020        private bool ProperBasicSubType(BasicType other) {
 5021            switch (BaseType) {
 3722            case IntegerType t when other.BaseType is IntegerType o && t.Size == o.Size && t.Values <= o.Values:
 3523                VerbConsole.WriteLine(VerbosityLevel.Default, $"<:-Int: {this} <: {other}");
 3524                return true;
 1325            case ReferenceType t when other.BaseType is ReferenceType o && t.Location == o.Location && t.Offsets <= o.Of
 1126                VerbConsole.WriteLine(VerbosityLevel.Default, $"<:-Ref: {this} <: {other}");
 1127                return true;
 228            case IntegerType t when t.Values == Index.Zero && other.BaseType is ReferenceType o && o.Abstract:
 129                VerbConsole.WriteLine(VerbosityLevel.Default, $"<:-NullPtr: {this} <: {other}");
 130                return true;
 231            case ReferenceType t when t.Concrete && other.BaseType is ReferenceType o && o.Abstract && (Base)t.Offsets =
 132                VerbConsole.WriteLine(VerbosityLevel.Default, $"<:-Abstract: {this} <: {other}");
 133                return true;
 234            default: return false;
 35            }
 5036        }
 37        /// <inheritdoc/>
 38        public abstract object Clone();
 39        /// <inheritdoc/>
 26040        public override Type Replace(Substitutor rep) => (Type)Clone();
 41        /// <inheritdoc/>
 342        public override PureExpression Refinement => new BooleanConstant(true);
 43        /// <summary>
 44        /// Calculates the closest related ancestor of both basic type and returns it.
 45        /// Both basic types are a subtype of the return value.
 46        /// </summary>
 47        /// <param name="baseType1">First input type.</param>
 48        /// <param name="baseType2">Second input type.</param>
 49        /// <returns>Supertype of both if they are compatible.</returns>
 50        /// <exception cref="IllFormedException">Incompatible basic types.</exception>
 51        public static BasicType SuperType(BasicType baseType1, BasicType baseType2)
 652            => baseType1 == baseType2
 653            ? baseType1
 654            : (baseType1.ProperBasicSubType(baseType2)
 655                ? baseType2
 656                : (baseType2.ProperBasicSubType(baseType1)
 657                    ? baseType1
 658                    : throw new IllFormedException(baseType1, $"Incompatible base types {baseType1} and {baseType2}!")))
 59    }
 60}