public void OrTypesJustNeedBothToMatchOne() { var a1 = A1(); var b1 = B1(); var b2 = B2(); var b3 = B3(); var or1 = new FrontEndOrType( new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)), OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >()); var or2 = new FrontEndOrType( new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b3)), OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(new List <WeakMemberDefinition> { new WeakMemberDefinition(Access.ReadWrite, new NameKey("bm1"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(new NumberType()))), new WeakMemberDefinition(Access.ReadWrite, new NameKey("bm2"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(new NumberType()))) }), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >()); // this works since both b2 and b3 are b1 Assert.True(or1.TheyAreUs(or2, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow()); // this does not work because niether b2 nor b3 are a1 Assert.False(or2.TheyAreUs(or1, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow()); }
public void OrTypesAreVarient() { var a1 = A1(); var a2 = A2(); var b1 = B1(); var b2 = B2(); var or1 = new FrontEndOrType( new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)), OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >() ); var or2 = new FrontEndOrType( new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a2)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2)), OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >() ); Assert.True(or1.TheyAreUs(or2, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow()); Assert.False(or2.TheyAreUs(or1, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow()); }
public Type CreateGenericType(IStaticScope parent, IOrType <NameKey, ImplicitKey> key, IReadOnlyList <TypeAndConverter> placeholders, IConvertTo <Type, IOrType <WeakTypeDefinition, WeakGenericTypeDefinition, Tac.SyntaxModel.Elements.AtomicTypes.IPrimitiveType> > converter) { var res = new Type( this, $"generic-{key}-{placeholders.Aggregate("", (x, y) => x + "-" + y)}", Possibly.Is(key), converter, Possibly.IsNot <Guid>(), Possibly.IsNot <IInterfaceType>()); IsChildOf(parent, res); HasType(parent, key.SwitchReturns <IKey>(x => x, x => x), res); var i = 0; foreach (var placeholder in placeholders) { var placeholderType = new TypeProblem2.GenericTypeParameter(this, $"generic-parameter-{placeholder.key}", i++, Prototypist.Toolbox.OrType.Make <MethodType, Type, Method, InferredType>(res)); //var placeholderType = new Type( // this, // $"generic-parameter-{placeholder.key}", // Possibly.Is(placeholder.key), // placeholder.converter, // Possibly.IsNot<Guid>(), // Possibly.IsNot<IInterfaceType>()); HasGenericType(Prototypist.Toolbox.OrType.Make <MethodType, Type, Method>(res), placeholder.key, placeholderType); } return(res); }
public void Any() { var a1 = A1(); var a2 = A2(); var b1 = B1(); var b2 = B2(); var m1 = new MethodType(new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a2)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1))); var m2 = new MethodType(new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2))); var t1 = new HasMembersType(new WeakScope(new List <WeakMemberDefinition> { new WeakMemberDefinition(Access.ReadWrite, new NameKey("a"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1))), new WeakMemberDefinition(Access.ReadWrite, new NameKey("b"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1))) })); var t2 = new HasMembersType(new WeakScope(new List <WeakMemberDefinition> { new WeakMemberDefinition(Access.ReadWrite, new NameKey("a"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a2))), new WeakMemberDefinition(Access.ReadWrite, new NameKey("b"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2))) })); var or1 = new FrontEndOrType( new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)), OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >() ); var or2 = new FrontEndOrType( new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)), OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(), Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >() ); var any = new AnyType(); Assert.All(new[] { a1, a2, b1, b2, m1, m2, t1, t2, or1, or2 }, x => any.TheyAreUs(x, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>())); }
// TODO // {A48C75B3-07B4-4D84-8803-250D6406695D} // this is a bit weird // it is get or create // but like if something as already made a hopeful member it will just throw // that is probably a bug // x.y := 5 // 5 > x // boom, probably public TransientMember GetReturns(IValue value) { if (value.Hopeful is IIsDefinately <InferredType> inferredType) { return(inferredType.Value.Returns.GetOrThrow()); } else { var inferredMethodType = new InferredType(this, "generated infered method type"); value.Hopeful = Possibly.Is(inferredMethodType); // shared code {A9E37392-760B-427D-852E-8829EEFCAE99} // we don't use has member input/output doesn't go in the member list // it is not a public member // and infered to do not have private members var methodInputKey = new NameKey("generated infered method input - " + Guid.NewGuid()); var inputMember = new Member(this, methodInputKey.ToString() !); inputMember.LooksUp = Possibly.Is(Prototypist.Toolbox.OrType.Make <MethodType, Type, Object, OrType, InferredType, GenericTypeParameter, IError>(new InferredType(this, "implicit input"))); inferredMethodType.Input = Possibly.Is(inputMember); var returnMember = new TransientMember(this, "generated infered method return -" + Guid.NewGuid()); returnMember.LooksUp = Possibly.Is(Prototypist.Toolbox.OrType.Make <MethodType, Type, Object, OrType, InferredType, GenericTypeParameter, IError>(new InferredType(this, "implicit return"))); inferredMethodType.Returns = Possibly.Is(returnMember); return(returnMember); } }
//public static IOrType<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric> Broaden(this IOrType<MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGenericRestraintFor, IsExternal> self) { // return self.SwitchReturns( // x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), // x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), // x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), // x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), // x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), // x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x)); //} public static IOrType <IIsPossibly <Guid>, IError> Primitive(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self) { var primitives = self.SelectMany(x => { if (x.Is2(out var v2)) { return(new[] { v2 }); } return(Array.Empty <MustBePrimitive>()); }).ToArray(); if (primitives.Length == self.Count()) { var groupedPrimitives = primitives.GroupBy(x => x.primitive).ToArray(); if (groupedPrimitives.Length == 1) { return(OrType.Make <IIsPossibly <Guid>, IError>(Possibly.Is(groupedPrimitives.First().Key))); } return(OrType.Make <IIsPossibly <Guid>, IError>(Error.Other("multiple primitives types..."))); } if (primitives.Any()) { return(OrType.Make <IIsPossibly <Guid>, IError>(Error.Other("primitives and non primitives"))); } return(OrType.Make <IIsPossibly <Guid>, IError>(Possibly.IsNot <Guid>())); }
public IReadOnlyDictionary <NameKey, GenericTypeParameter> HasGenerics(IValue value, NameKey[] keys) { InferredType?inferredType; if (value.Hopeful.Is(out var innerInferredType)) { inferredType = innerInferredType; } else { var inferredMethodType = new InferredType(this, "generated infered method type"); value.Hopeful = Possibly.Is(inferredMethodType); inferredType = inferredMethodType; } if (inferredType.Generics.Count > 0) { throw new Exception("this already has generics!"); } var i = 0; foreach (var key in keys) { inferredType.Generics.Add(key, new GenericTypeParameter(this, $"generic-parameter-{key}", i++, Prototypist.Toolbox.OrType.Make <MethodType, Type, Method, InferredType>(inferredType))); } return(inferredType.Generics); }
public IIsPossibly <WeakPathOperation> Run(IResolvableScope scope, IResolveReferenceContext context) { var res = Possibly.Is(new WeakPathOperation( left.Run(scope, context), Possibly.Is(new WeakMemberReference(left.GetReturnedType().GetMemberDefinition(new NameKey(name)))))); return(res); }
public static IIsPossibly <ICodeElement> PossiblyConvert(this IFrontendCodeElement self, IConversionContext context) { if (self is IConvertableFrontendCodeElement <ICodeElement> convertable) { return(Possibly.Is(convertable.Convert(context))); } return(Possibly.IsNot <ICodeElement>()); }
internal static IIsPossibly <IBox <IIsPossibly <IWeakMemberDefinition> > > PossiblyGetMember(this IResolvableScope scope, bool staticOnly, IKey name) { if (scope.TryGetMember(name, staticOnly, out var thing)) { return(Possibly.Is(thing)); } return(Possibly.IsNot <IBox <IIsPossibly <IWeakMemberDefinition> > >()); }
public Type CreateType(IStaticScope parent, IOrType <NameKey, ImplicitKey> key, IConvertTo <Type, IOrType <WeakTypeDefinition, WeakGenericTypeDefinition, Tac.SyntaxModel.Elements.AtomicTypes.IPrimitiveType> > converter, IIsPossibly <Guid> primitive) { var res = new Type(this, key.ToString() !, Possibly.Is(key), converter, primitive, Possibly.IsNot <IInterfaceType>()); IsChildOf(parent, res); HasType(parent, key.SwitchReturns <IKey>(x => x, x => x), res); return(res); }
public void Set(T t) { if (t is IIsPossibly <T> && !(t is IIsDefinately <T>)) { throw new ApplicationException(); } this.t = Possibly.Is(t); }
internal static IIsPossibly <IBox <IIsPossibly <IFrontendType> > > PossiblyGetType(this IResolvableScope scope, IKey name) { if (scope.TryGetType(name, out var thing)) { return(Possibly.Is(thing)); } return(Possibly.IsNot <IBox <IIsPossibly <IFrontendType> > >()); }
public TransientMember CreateTransientMember(IScope parent, string debugName) { var res = new TransientMember(this, debugName); HasTransientMember(parent, res); res.Context = Possibly.Is(parent); return(res); }
public TypeOrOperationMaker() : base(SymbolsRegistry.StaticTypeOrSymbol, (l, r) => Possibly.Is <IWeakTypeReference>( new WeakTypeReference( Possibly.Is <IBox <IIsPossibly <IConvertableFrontendType <IVerifiableType> > > >( new Box <IIsPossibly <IConvertableFrontendType <IVerifiableType> > >( Possibly.Is <IConvertableFrontendType <IVerifiableType> >( new WeakTypeOrOperation(l, r))))))) { }
public TransientMember CreateTransientMember(IScope parent, IKey typeKey, string debugName) { var res = new TransientMember(this, debugName); HasTransientMember(parent, res); res.Context = Possibly.Is(parent); res.TypeKey = Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(typeKey); return(res); }
public Value CreateValue(IScope scope, IKey typeKey) { var res = new Value(this, typeKey.ToString() !); HasValue(scope, res); res.Context = Possibly.Is(scope); res.TypeKey = Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(typeKey); return(res); }
public TypeReference CreateTypeReference(IStaticScope context, IKey typeKey, IConvertTo <TypeReference, IFrontendType <IVerifiableType> > converter) { var res = new TypeReference(this, typeKey.ToString() !, converter); HasReference(context, res); res.Context = Possibly.Is(context); res.TypeKey = Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(typeKey); return(res); }
public IIsPossibly <WeakObjectDefinition> Run(IResolvableScope _, IResolveReferenceContext context) { var innerRes = new WeakObjectDefinition( scope, elements.Select(x => x.Run(scope, context).Cast <IIsPossibly <WeakAssignOperation> >()).ToArray()); var res = Possibly.Is(innerRes); return(res); }
public IIsPossibly <WeakAssignOperation> Run(IResolvableScope scope, IResolveReferenceContext context) { var leftRes = left.Run(scope, context); var res = Possibly.Is(new WeakAssignOperation( leftRes, right.Run(scope, context))); return(res); }
public IIsPossibly <WeakBlockDefinition> Run(IResolvableScope _, IResolveReferenceContext context) { return (Possibly.Is( new WeakBlockDefinition( resolveReferance.Select(x => x.Run(scope, context)).ToArray(), scope, new IIsPossibly <IConvertableFrontendCodeElement <ICodeElement> > [0]))); }
public PopulatableScope(PopulatableScope parent) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } Parent = Possibly.Is(parent); finalizableScope = new FinalizableScope(this); }
public Type CreateTypeExternalType(IStaticScope parent, IConvertTo <Type, IOrType <WeakTypeDefinition, WeakGenericTypeDefinition, Tac.SyntaxModel.Elements.AtomicTypes.IPrimitiveType> > converter, IInterfaceType interfaceType) { var key = new ImplicitKey(Guid.NewGuid()); var res = new Type(this, key.ToString() !, Possibly.IsNot <IOrType <NameKey, ImplicitKey> >(), converter, Possibly.IsNot <Guid>(), Possibly.Is(interfaceType)); IsChildOf(parent, res); // migiht need this, let's try without first //HasType(parent, key, res); return(res); }
public OverlayMemberDefinition(IWeakMemberDefinition backing, Overlay overlay) { if (overlay == null) { throw new ArgumentNullException(nameof(overlay)); } this.backing = backing ?? throw new ArgumentNullException(nameof(backing)); this.Type = backing.Type.IfIs(x => Possibly.Is(new OverlayTypeReference(x, overlay))); }
public ResolvableScope( ConcurrentDictionary <IKey, ConcurrentSet <Visiblity <IBox <IIsPossibly <WeakMemberDefinition> > > > > members, ConcurrentDictionary <IKey, ConcurrentSet <Visiblity <IBox <IIsPossibly <IFrontendType> > > > > types, ConcurrentDictionary <NameKey, ConcurrentSet <Visiblity <IBox <IIsPossibly <IFrontendGenericType> > > > > genericTypes) { Parent = Possibly.IsNot <IResolvableScope>(); this.members = members ?? throw new ArgumentNullException(nameof(members)); this.types = types ?? throw new ArgumentNullException(nameof(types)); this.genericTypes = genericTypes ?? throw new ArgumentNullException(nameof(genericTypes)); }
public static IIsPossibly <IOrType <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError> > Input(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self) { if (self.ErrorCheck(out var error)) { return(Possibly.Is(OrType.Make <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError>(error))); } var mustHaves = self .SelectMany(x => { if (x.Is1(out var v1)) { return(new[] { v1 }); } return(Array.Empty <MustHave>()); }) .Where(x => x.path.Is2(out var _)) .ToArray(); if (mustHaves.Any()) { var set = new HashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >(); var givenPaths = self .SelectMany(x => { if (x.Is3(out var v3)) { return(new[] { v3 }); } return(Array.Empty <GivenPathThen>()); }) .Where(x => x.path.Is2(out var _)); foreach (var mustHave in mustHaves) { foreach (var constraint in mustHave.dependent.GetExtendedConstraints()) { set.Add(constraint); } } foreach (var givenPath in givenPaths) { foreach (var constraint in givenPath.dependent.GetExtendedConstraints()) { set.Add(constraint); } } return(Possibly.Is(OrType.Make <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError>(new EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >(set)))); } return(Possibly.IsNot <IOrType <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError> >()); }
public IIsPossibly <WeakModuleDefinition> Run(IResolvableScope _, IResolveReferenceContext context) { var innerRes = new WeakModuleDefinition( scope, resolveReferance.Select(x => x.Run(scope, context)).ToArray(), nameKey); var res = Possibly.Is(innerRes); return(res); }
public Member CreatePrivateMember( IStaticScope scope, IHavePrivateMembers havePrivateMembers, IKey key) { var res = new Member(this, key.ToString() !); HasPrivateMember(havePrivateMembers, key, res); res.Context = Possibly.Is(scope); return(res); }
public Member CreatePrivateMember( IHavePrivateMembers scope, IKey key, IOrType <MethodType, Type, Object, OrType, InferredType, GenericTypeParameter, IError> type) { var res = new Member(this, key.ToString() !); HasPrivateMember(scope, key, res); res.LooksUp = Possibly.Is(type); return(res); }
public IIsPossibly <WeakMemberReference> Run(IResolvableScope scope, IResolveReferenceContext context) { memberDefinitionBox.Fill( Possibly.Is( new WeakMemberDefinition( isReadonly, memberName, type.Run(scope, context)))); return(Possibly.Is(new WeakMemberReference(Possibly.Is(memberDefinitionBox)))); }