public TrailingPopulateScope(IOrType <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError> left, TrailingOperation.Make <TFrontendCodeElement> make, TrailingOperation.GetReturnedValue getReturnedValue, bool intoInitScope) { this.left = left ?? throw new ArgumentNullException(nameof(left)); this.make = make ?? throw new ArgumentNullException(nameof(make)); this.getReturnedValue = getReturnedValue ?? throw new ArgumentNullException(nameof(getReturnedValue)); this.intoInitScope = intoInitScope; }
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 static IEnumerable <IError> Validate(IOrType <IBox <IFrontendCodeElement>, IError> input, IOrType <IBox <IFrontendCodeElement>, IError> method) { var inputTypeOrErrors = input.ReturnsTypeOrErrors(); var methodInputTypeOrErrors = method .ReturnsTypeOrErrors() .TransformAndFlatten(thing => thing.TryGetInput().SwitchReturns(orType => orType, no => { return(OrType.Make <IFrontendType <IVerifiableType>, IError>(Error.Other($"{thing} should return"))); } , error => OrType.Make <IFrontendType <IVerifiableType>, IError>(error))); return(inputTypeOrErrors.SwitchReturns( i => methodInputTypeOrErrors.SwitchReturns <IEnumerable <IError> >( mi => { if (!i.TheyAreUs(mi, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).SwitchReturns(x => x, x => false)) { return new[] { Error.Other($"{method} does not accept {input}") }; } return Array.Empty <IError>(); }, mi => { return new IError[] { mi }; }), i => methodInputTypeOrErrors.SwitchReturns <IEnumerable <IError> >( m => { return new IError[] { i }; }, m => { return new IError[] { i, m }; }))); }
private void UpdateDefinedBy(IFinalizedScope scope, IOrType <IInternalMethodDefinition, IImplementationDefinition, IEntryPointDefinition, IBlockDefinition, IRootScope, IObjectDefiniton> owner) { foreach (var member in scope.Members.Values.Select(x => x.Value)) { definedBy[member] = owner; } }
internal void Add(IOrType <IInternalMethodDefinition, IImplementationDefinition, IEntryPointDefinition> orType, RealizedMethod realizedMethod) { if (!backing.TryAdd(orType, realizedMethod)) { throw new Exception("should have added, I think"); } }
public WeakBlockDefinition( IBox <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > > body, IOrType <WeakScope, IError> scope, IReadOnlyList <IIsPossibly <IFrontendCodeElement> > staticInitailizers) : base(scope, body, staticInitailizers) { }
public WeakObjectDefinition(IOrType <HasMembersType, IError> type, IBox <IReadOnlyList <IOrType <IBox <WeakAssignOperation>, IError> > > assigns) { Scope = type?.TransformInner(x => x.weakScope) ?? throw new ArgumentNullException(nameof(type)); Assignments = assigns ?? throw new ArgumentNullException(nameof(assigns)); returns = type; }
public WeakRootScope(IOrType <HasMembersType, IError> returns, Box <IReadOnlyList <IOrType <IBox <WeakAssignOperation>, IError> > > assigns, Box <IOrType <IBox <WeakEntryPointDefinition>, IError> > EntryPoint) { this.returns = returns ?? throw new ArgumentNullException(nameof(returns)); Scope = returns.TransformInner(x => x.weakScope); this.EntryPoint = EntryPoint ?? throw new ArgumentNullException(nameof(EntryPoint)); Assignments = assigns ?? throw new ArgumentNullException(nameof(assigns)); }
public static T IsOrThrow <T1, T2, T3, T4, T5, T6, T7, T8, T>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self) { if (self.Is <T>(out var v)) { return(v); } throw new Exception($"{self}'s value is not a {typeof(T).Name}"); }
internal RealizedMethod GetValueOrThrow(IOrType <IInternalMethodDefinition, IImplementationDefinition, IEntryPointDefinition> orType) { if (backing.TryGetValue(orType, out var res)) { return(res); } throw new Exception("key not found"); }
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 TryAssignOperationPopulateScope( IOrType <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError> left, IOrType <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError> right, IOrType <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError> block) { this.left = left ?? throw new ArgumentNullException(nameof(left)); this.right = right ?? throw new ArgumentNullException(nameof(right)); this.block = block ?? throw new ArgumentNullException(nameof(block)); }
public BinaryResolveReferance( IOrType <IResolve <IBox <IFrontendCodeElement> >, IError> resolveReferance1, IOrType <IResolve <IBox <IFrontendCodeElement> >, IError> resolveReferance2, BinaryOperation.Make <TFrontendCodeElement> make) { left = resolveReferance1 ?? throw new ArgumentNullException(nameof(resolveReferance1)); right = resolveReferance2 ?? throw new ArgumentNullException(nameof(resolveReferance2)); this.make = make ?? throw new ArgumentNullException(nameof(make)); }
public WeakPathOperationResolveReference( IOrType <IResolve <IBox <IFrontendCodeElement> >, IError> resolveReference, IOrType <Tpn.TypeProblem2.Member, IError> member, IKey key) { left = resolveReference ?? throw new ArgumentNullException(nameof(resolveReference)); this.member = member ?? throw new ArgumentNullException(nameof(member)); this.key = key ?? throw new ArgumentNullException(nameof(key)); }
protected WeakAbstractBlockDefinition( IOrType <WeakScope, IError> scope, IBox <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > > body, IReadOnlyList <IIsPossibly <IFrontendCodeElement> > staticInitailizers) { Scope = scope ?? throw new ArgumentNullException(nameof(scope)); Body = body ?? throw new ArgumentNullException(nameof(body)); StaticInitailizers = staticInitailizers ?? throw new ArgumentNullException(nameof(staticInitailizers)); }
public static bool Is3 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T3 t3) { if (self.Possibly3() is IIsDefinately <T3> definate) { t3 = definate.Value; return(true); } t3 = default; return(false); }
public WeakEntryPointDefinition( IOrType <IFrontendType <IVerifiableType>, IError> outputType, WeakMemberDefinition parameterDefinition, IBox <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > > body, IOrType <WeakScope, IError> scope, IReadOnlyList <IIsPossibly <IConvertableFrontendCodeElement <ICodeElement> > > staticInitializers) : base(scope ?? throw new ArgumentNullException(nameof(scope)), body, staticInitializers) { OutputType = outputType ?? throw new ArgumentNullException(nameof(outputType)); ParameterDefinition = parameterDefinition ?? throw new ArgumentNullException(nameof(parameterDefinition)); }
public static T GetValueAs <T1, T2, T>(this IOrType <T1, T2> self) where T1 : T where T2 : T { if (self.Is <T>(out var res)) { return(res); } throw new Exception($"{self}'s value is not a {typeof(T).Name}"); }
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 static bool Is1 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T1 t1) { if (self.Possibly1() is IIsDefinately <T1> definate) { t1 = definate.Value; return(true); } t1 = default; return(false); }
public static bool Is8 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T8 t8) { if (self.Possibly8() is IIsDefinately <T8> definate) { t8 = definate.Value; return(true); } t8 = default; return(false); }
public static bool Is7 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T7 t7) { if (self.Possibly7() is IIsDefinately <T7> definate) { t7 = definate.Value; return(true); } t7 = default; return(false); }
public static bool Is2 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T2 t2) { if (self.Possibly2() is IIsDefinately <T2> definate) { t2 = definate.Value; return(true); } t2 = default; return(false); }
public static bool Is5 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T5 t5) { if (self.Possibly5() is IIsDefinately <T5> definate) { t5 = definate.Value; return(true); } t5 = default; return(false); }
public static bool Is4 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T4 t4) { if (self.Possibly4() is IIsDefinately <T4> definate) { t4 = definate.Value; return(true); } t4 = default; return(false); }
public WeakGenericTypeDefinition( IIsPossibly <IOrType <NameKey, ImplicitKey> > key, IOrType <HasMembersType, IError> type, IOrType <IGenericTypeParameterPlacholder, IError>[] TypeParameterDefinitions) { this.TypeParameterDefinitions = TypeParameterDefinitions ?? throw new ArgumentNullException(nameof(TypeParameterDefinitions)); Key = key ?? throw new ArgumentNullException(nameof(key)); this.type = type ?? throw new ArgumentNullException(nameof(type)); Scope = type.TransformInner(x => x.weakScope); }
public static bool Is6 <T1, T2, T3, T4, T5, T6, T7, T8>(this IOrType <T1, T2, T3, T4, T5, T6, T7, T8> self, out T6 t6) { if (self.Possibly6() is IIsDefinately <T6> definate) { t6 = definate.Value; return(true); } t6 = default; return(false); }
public RootScopePopulateScope ParseFile(FileToken file) { IOrType <EntryPointDefinitionPopulateScope, IError> defaultEntryPoint = OrType.Make <EntryPointDefinitionPopulateScope, IError>( new EntryPointDefinitionPopulateScope( new TypeReferancePopulateScope(new NameKey("empty")), Array.Empty <IOrType <EntryPointDefinitionPopulateScope, IError> >(), new TypeReferancePopulateScope(new NameKey("empty")), "unused")); var entryToReturn = defaultEntryPoint; var assignments = new List <IOrType <WeakAssignOperationPopulateScope, IError> >(); var types = new List <IOrType <TypeDefinitionPopulateScope, IError> >(); var genericTypes = new List <IOrType <GenericTypeDefinitionPopulateScope, IError> >(); foreach (var element in file.Tokens.Select(line => ParseLine(line.CastTo <LineToken>().Tokens))) { element.Switch(setup => { if (setup.SafeIs(out WeakAssignOperationPopulateScope assign)) { assignments.Add(OrType.Make <WeakAssignOperationPopulateScope, IError>(assign)); } else if (setup.SafeIs(out GenericTypeDefinitionPopulateScope genericType)) { genericTypes.Add(OrType.Make <GenericTypeDefinitionPopulateScope, IError>(genericType)); } else if (setup.SafeIs(out TypeDefinitionPopulateScope type)) { types.Add(OrType.Make <TypeDefinitionPopulateScope, IError>(type)); } else if (setup.SafeIs(out EntryPointDefinitionPopulateScope entry)) { if (entryToReturn == defaultEntryPoint) { entryToReturn = OrType.Make <EntryPointDefinitionPopulateScope, IError>(entry); } else { entryToReturn = OrType.Make <EntryPointDefinitionPopulateScope, IError>(Error.Other("you can't have more than one entry point")); } } else { assignments.Add(OrType.Make <WeakAssignOperationPopulateScope, IError>(Error.Other($"unexpected type {setup.GetType().Name}"))); } } , error => { assignments.Add(OrType.Make <WeakAssignOperationPopulateScope, IError>(error)); }); } return(new RootScopePopulateScope(assignments.ToArray(), entryToReturn, types, genericTypes)); }
public WeakTryAssignOperation( IOrType <IBox <IFrontendCodeElement>, IError> left, IOrType <IBox <IFrontendCodeElement>, IError> right, IOrType <IBox <IFrontendCodeElement>, IError> body, IOrType <IBox <WeakScope>, IError> scope) { Left = left ?? throw new ArgumentNullException(nameof(left)); Right = right ?? throw new ArgumentNullException(nameof(right)); Body = body ?? throw new ArgumentNullException(nameof(body)); Scope = scope ?? throw new ArgumentNullException(nameof(scope)); }
public RootScopePopulateScope( IReadOnlyList <IOrType <WeakAssignOperationPopulateScope, IError> > elements, IOrType <EntryPointDefinitionPopulateScope, IError> entry, IReadOnlyList <IOrType <TypeDefinitionPopulateScope, IError> > types, IReadOnlyList <IOrType <GenericTypeDefinitionPopulateScope, IError> > genericTypes) { this.elements = elements ?? throw new ArgumentNullException(nameof(elements)); this.entry = entry ?? throw new ArgumentNullException(nameof(entry)); this.types = types ?? throw new ArgumentNullException(nameof(types)); this.genericTypes = genericTypes ?? throw new ArgumentNullException(nameof(genericTypes)); }