public void AssignFrom(StackPlace place, ReferenceCapability referenceCapability)
        {
            if (place.Graph != Graph)
            {
                throw new ArgumentException("Must be part of the same graph", nameof(place));
            }

            switch (referenceCapability)
            {
            default:
                throw ExhaustiveMatch.Failed(referenceCapability);

            case ReferenceCapability.Owned:
            case ReferenceCapability.OwnedMutable:
            case ReferenceCapability.Isolated:
            case ReferenceCapability.IsolatedMutable:
            case ReferenceCapability.Held:
            case ReferenceCapability.HeldMutable:
                MoveFrom(place);
                break;

            case ReferenceCapability.Shared:
                ShareFrom(place);
                break;

            case ReferenceCapability.Borrowed:
                BorrowFrom(place);
                break;

            case ReferenceCapability.Identity:
                IdentityFrom(place);
                break;
            }
        }
Ejemplo n.º 2
0
 protected override ReferenceRegistrationOptions CreateRegistrationOptions(ReferenceCapability capability, ClientCapabilities clientCapabilities)
 {
     return(new()
     {
         DocumentSelector = Program.Selector
     });
 }
Ejemplo n.º 3
0
        public void Can_convert_to_reference_capability(ReferenceCapability capability)
        {
            var type = new AnyType(Isolated);

            var converted = type.To(capability);

            Assert.Equal(capability, converted.ReferenceCapability);
        }
Ejemplo n.º 4
0
 public CapabilityTypeSyntax(
     ReferenceCapability referenceCapability,
     ITypeSyntax referentType,
     TextSpan span)
     : base(span)
 {
     ReferentType = referentType;
     Capability   = referenceCapability;
 }
 // TODO referenceCapability needs to match declared mutable?
 public ObjectType(
     NamespaceName containingNamespace,
     TypeName name,
     bool declaredMutable,
     ReferenceCapability referenceCapability)
     : base(declaredMutable, referenceCapability)
 {
     ContainingNamespace = containingNamespace;
     Name = name;
 }
Ejemplo n.º 6
0
        private ITypeSyntax ParseTypeWithCapability <TCapabilityToken>(ReferenceCapability immutableCapability, ReferenceCapability mutableCapability)
            where TCapabilityToken : ICapabilityToken
        {
            var primaryCapability = Tokens.RequiredToken <TCapabilityToken>();
            var mutableKeyword    = Tokens.AcceptToken <IMutableKeywordToken>();
            var referent          = ParseBareType();
            var span       = TextSpan.Covering(primaryCapability.Span, referent.Span);
            var capability = mutableKeyword is null ? immutableCapability : mutableCapability;

            return(new CapabilityTypeSyntax(capability, referent, span));
        }
        public override string ToILString()
        {
            var builder = new StringBuilder();

            builder.Append(ReferenceCapability.ToILString());
            builder.Append(' ');
            builder.Append(ContainingNamespace);
            if (ContainingNamespace != NamespaceName.Global)
            {
                builder.Append('.');
            }
            builder.Append(Name);
            return(builder.ToString());
        }
        public static bool IsMutable(this ReferenceCapability referenceCapability)
        {
            switch (referenceCapability)
            {
            default:
                throw ExhaustiveMatch.Failed(referenceCapability);

            case ReferenceCapability.OwnedMutable:
            case ReferenceCapability.IsolatedMutable:
            case ReferenceCapability.HeldMutable:
            case ReferenceCapability.Borrowed:
                return(true);

            case ReferenceCapability.Owned:
            case ReferenceCapability.Isolated:
            case ReferenceCapability.Held:
            case ReferenceCapability.Shared:
            case ReferenceCapability.Identity:
                return(false);
            }
        }
        internal static Ownership ToOwnership(this ReferenceCapability capability)
        {
            switch (capability)
            {
            default:
                throw ExhaustiveMatch.Failed(capability);

            case IsolatedMutable:
            case Isolated:
            case OwnedMutable:
            case Owned:
                return(Owns);

            case HeldMutable:
            case Held:
                return(PotentiallyOwns);

            case Borrowed:
            case Shared:
            case Identity:
                return(None);
            }
        }
        internal static Access ToAccess(this ReferenceCapability capability)
        {
            switch (capability)
            {
            default:
                throw ExhaustiveMatch.Failed(capability);

            case IsolatedMutable:
            case OwnedMutable:
            case HeldMutable:
            case Borrowed:
                return(Mutable);

            case Isolated:
            case Owned:
            case Held:
            case Shared:
                return(ReadOnly);

            case Identity:
                return(Identify);
            }
        }
Ejemplo n.º 11
0
 public override void SetCapability(ReferenceCapability capability) => _setCapability?.Invoke(capability);
 public void SetCapability(ReferenceCapability capability)
 {
     _capability = capability;
 }
Ejemplo n.º 13
0
 public virtual void SetCapability(ReferenceCapability capability) => Capability = capability;
 public static bool IsAssignableFrom(this ReferenceCapability target, ReferenceCapability source)
 {
     switch (target, source)
     {
Ejemplo n.º 15
0
        public override string ToSourceCodeString()
        {
            var capability = ReferenceCapability.ToSourceCodeString();

            return(capability.Length == 0 ? "Any" : $"{capability} Any");
        }
Ejemplo n.º 16
0
 protected internal sealed override Self ToReadOnly_ReturnsSelf()
 {
     return(To_ReturnsSelf(ReferenceCapability.ToReadOnly()));
 }
Ejemplo n.º 17
0
 protected internal abstract Self To_ReturnsSelf(ReferenceCapability referenceCapability);
 /// <summary>
 /// Return the same type except with the given reference capability
 /// </summary>
 public static T To <T>(this T type, ReferenceCapability referenceCapability)
     where T : ReferenceType
 {
     return(type.To_ReturnsSelf(referenceCapability).Cast <T>());
 }
Ejemplo n.º 19
0
        public void ToILString_includes_reference_capability(ReferenceCapability capability, string expected)
        {
            var type = new AnyType(capability);

            Assert.Equal(expected, type.ToILString());
        }
Ejemplo n.º 20
0
 protected internal override Self To_ReturnsSelf(ReferenceCapability referenceCapability)
 {
     return(new AnyType(referenceCapability));
 }
Ejemplo n.º 21
0
 protected override ReferenceRegistrationOptions CreateRegistrationOptions(ReferenceCapability capability, ClientCapabilities clientCapabilities) => new ReferenceRegistrationOptions
 {
     DocumentSelector = LspUtils.PowerShellDocumentSelector
 };
 /// <summary>
 /// Use this type as a mutable type. Only allowed if the type is declared mutable
 /// </summary>
 public ObjectType ToMutable()
 {
     Requires.That(nameof(DeclaredMutable), DeclaredMutable, "must be declared as a mutable type to use mutably");
     return(new ObjectType(ContainingNamespace, Name, DeclaredMutable, ReferenceCapability.ToMutable()));
 }
Ejemplo n.º 23
0
        public override string ToILString()
        {
            var capability = ReferenceCapability.ToILString();

            return($"{capability} Any");
        }
 protected internal override Self To_ReturnsSelf(ReferenceCapability referenceCapability)
 {
     return(new ObjectType(ContainingNamespace, Name, DeclaredMutable, referenceCapability));
 }
Ejemplo n.º 25
0
        // TODO clarify this

        private protected ReferenceType(bool declaredMutable, ReferenceCapability referenceCapability)
        {
            ReferenceCapability = referenceCapability;
            DeclaredMutable     = declaredMutable;
        }
Ejemplo n.º 26
0
        public void Has_reference_capability_constructed_with(ReferenceCapability capability)
        {
            var type = new AnyType(capability);

            Assert.Equal(capability, type.ReferenceCapability);
        }
Ejemplo n.º 27
0
 protected override ReferenceRegistrationOptions CreateRegistrationOptions(ReferenceCapability capability, ClientCapabilities clientCapabilities) => new()
Ejemplo n.º 28
0
 public AnyType(ReferenceCapability referenceCapability)
     : base(true, referenceCapability)
 {
 }