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; } }
protected override ReferenceRegistrationOptions CreateRegistrationOptions(ReferenceCapability capability, ClientCapabilities clientCapabilities) { return(new() { DocumentSelector = Program.Selector }); }
public void Can_convert_to_reference_capability(ReferenceCapability capability) { var type = new AnyType(Isolated); var converted = type.To(capability); Assert.Equal(capability, converted.ReferenceCapability); }
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; }
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); } }
public override void SetCapability(ReferenceCapability capability) => _setCapability?.Invoke(capability);
public void SetCapability(ReferenceCapability capability) { _capability = capability; }
public virtual void SetCapability(ReferenceCapability capability) => Capability = capability;
public static bool IsAssignableFrom(this ReferenceCapability target, ReferenceCapability source) { switch (target, source) {
public override string ToSourceCodeString() { var capability = ReferenceCapability.ToSourceCodeString(); return(capability.Length == 0 ? "Any" : $"{capability} Any"); }
protected internal sealed override Self ToReadOnly_ReturnsSelf() { return(To_ReturnsSelf(ReferenceCapability.ToReadOnly())); }
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>()); }
public void ToILString_includes_reference_capability(ReferenceCapability capability, string expected) { var type = new AnyType(capability); Assert.Equal(expected, type.ToILString()); }
protected internal override Self To_ReturnsSelf(ReferenceCapability referenceCapability) { return(new AnyType(referenceCapability)); }
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())); }
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)); }
// TODO clarify this private protected ReferenceType(bool declaredMutable, ReferenceCapability referenceCapability) { ReferenceCapability = referenceCapability; DeclaredMutable = declaredMutable; }
public void Has_reference_capability_constructed_with(ReferenceCapability capability) { var type = new AnyType(capability); Assert.Equal(capability, type.ReferenceCapability); }
protected override ReferenceRegistrationOptions CreateRegistrationOptions(ReferenceCapability capability, ClientCapabilities clientCapabilities) => new()
public AnyType(ReferenceCapability referenceCapability) : base(true, referenceCapability) { }