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 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 static bool ExtendedIsCompatible(this IConstraint constraint, IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> item) { return(item.SwitchReturns( x => constraint.IsCompatible(OrType.Make <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), new List <UnorderedPair <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric> > >()), x => constraint.IsCompatible(OrType.Make <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), new List <UnorderedPair <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric> > >()), x => constraint.IsCompatible(OrType.Make <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), new List <UnorderedPair <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric> > >()), x => constraint.IsCompatible(OrType.Make <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x), new List <UnorderedPair <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric> > >()), x => true, x => true)); }
public Member CreatePrivateMember( IStaticScope scope, IHavePrivateMembers havePrivateMembers, IKey key, IOrType <IKey, IError> typeKey) { var res = new Member(this, key.ToString() !); HasPrivateMember(havePrivateMembers, key, res); res.Context = Possibly.Is(scope); res.TypeKey = typeKey.SwitchReturns(x => Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(x), x => Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(x)); return(res); }
public ISetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> Run(Tpn.IStaticScope scope, ISetUpContext context) { var type = context.TypeProblem.CreateType(scope, key, new WeakTypeDefinitionConverter()); var typeReference = context.TypeProblem.CreateTypeReference(scope, key.SwitchReturns <IKey>(x => x, x => x), new WeakTypeReferenceConverter()); foreach (var element in elements) { if (element.Is1(out var setUp)) { setUp.Run(type, context.CreateChildContext(this)); } } return(new SetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference>(new TypeReferanceResolveReference(typeReference), OrType.Make <Tpn.TypeProblem2.TypeReference, IError>(typeReference))); }
public Member CreateMember( IStaticScope scope, IKey key, IOrType <IKey, IError> typeKey) { var res = new Member(this, key.ToString() !); if (scope is IHavePublicMembers publicMembers) { HasPublicMember(publicMembers, key, res); } else if (scope is IHavePrivateMembers privateMembers) { HasPrivateMember(privateMembers, key, res); } else { throw new Exception("this is probably really an IError - you tried to add a member somewhere one cannot go"); } res.Context = Possibly.Is(scope); res.TypeKey = typeKey.SwitchReturns(x => Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(x), x => Prototypist.Toolbox.OrType.Make <IKey, IError, Unset>(x)); return(res); }
public static IOrType <TT, IError> TransformInner <T, TT>(this IOrType <T, IError> self, Func <T, IOrType <TT, IError> > transform) { return(self.SwitchReturns(x => transform(x), x => OrType.Make <TT, IError>(x))); }
public static IOrType <TT, IError> TransformAndFlatten <T, TT>(this IOrType <T, IError> self, Func <T, IOrType <TT, IError> > transform) => self.SwitchReturns(x => transform(x), y => OrType.Make <TT, IError>(y));
public static IOrType <T, IError> Flatten <T>(this IOrType <IOrType <T, IError>, IError> self) => self.SwitchReturns(x => x.SwitchReturns(x1 => OrType.Make <T, IError>(x1), x2 => OrType.Make <T, IError>(x2)), y => OrType.Make <T, IError>(y));
public static IOrType <TT, IError> TransformInner <T, TT>(this IOrType <T, IError> self, Func <T, TT> transform) => self.SwitchReturns(x => OrType.Make <TT, IError>(transform(x)), y => OrType.Make <TT, IError>(y));