Пример #1
0
 public static void If <T, TT>(this IIsPossibly <T> self, Func <T, TT> func)
 {
     if (self is IIsDefinately <T> isYes)
     {
         func(isYes.Value);
     }
 }
Пример #2
0
 public static IEnumerable <T> AsEnumerable <T>(this IIsPossibly <T> self)
 {
     if (self is IIsDefinately <T> definate)
     {
         yield return(definate.Value);
     }
 }
Пример #3
0
 public static void If <T>(this IIsPossibly <T> self, Action <T> action)
 {
     if (self is IIsDefinately <T> isYes)
     {
         action(isYes.Value);
     }
 }
Пример #4
0
 public static T GetOrThrow <T>(this IIsPossibly <T> self)
 {
     if (self is IIsDefinately <T> isYes)
     {
         return(isYes.Value);
     }
     throw new Exception();
 }
Пример #5
0
 public static IIsPossibly <TT> IfIsReturns <T, TT>(this IIsPossibly <T> self, Func <T, IIsPossibly <TT> > func)
 {
     if (self is IIsDefinately <T> isYes)
     {
         return(func(isYes.Value));
     }
     return(Possibly.IsNot <TT>());
 }
Пример #6
0
 public static IIsPossibly <TT> TransformInner <T, TT>(this IIsPossibly <T> self, Func <T, TT> func)
 {
     if (self is IIsDefinately <T> isYes)
     {
         return(Possibly.Is <TT>(func(isYes.Value)));
     }
     return(Possibly.IsNot <TT>());
 }
Пример #7
0
 public void Set(T t)
 {
     if (t is IIsPossibly <T> && !(t is IIsDefinately <T>))
     {
         throw new ApplicationException();
     }
     this.t = Possibly.Is(t);
 }
Пример #8
0
 public WeakGenericTypeDefinition(
     IIsPossibly <NameKey> key,
     IResolvableScope scope,
     IIsPossibly <IGenericTypeParameterPlacholder>[] TypeParameterDefinitions)
 {
     this.TypeParameterDefinitions = TypeParameterDefinitions ?? throw new ArgumentNullException(nameof(TypeParameterDefinitions));
     Key   = key ?? throw new ArgumentNullException(nameof(key));
     Scope = scope ?? throw new ArgumentNullException(nameof(scope));
 }
Пример #9
0
 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);
 }
Пример #10
0
        public PopulatableScope(PopulatableScope parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            Parent           = Possibly.Is(parent);
            finalizableScope = new FinalizableScope(this);
        }
Пример #11
0
        public static IMemberDefinition Convert(IIsPossibly <IWeakTypeReference> Type, IConversionContext context, bool ReadOnly, IKey Key)
        {
            var(def, builder) = MemberDefinition.Create();

            var buildIntention = Type.GetOrThrow().TypeDefinition.GetOrThrow().GetValue().GetOrThrow().Cast <IConvertable <IVerifiableType> >().GetBuildIntention(context);

            buildIntention.Build();
            builder.Build(Key, buildIntention.Tobuild, ReadOnly);
            return(def);
        }
Пример #12
0
 public static IBuildIntention <IVerifiableType> GetBuildIntention(IIsPossibly <IBox <IIsPossibly <IFrontendType> > > TypeDefinition, IConversionContext context)
 {
     if (TypeDefinition.GetOrThrow().GetValue().GetOrThrow() is IConvertableFrontendType <IVerifiableType> convertableType)
     {
         return(convertableType.GetBuildIntention(context));
     }
     else
     {
         throw new Exception("can not be built, type is not convertable");
     }
 }
Пример #13
0
 public static bool IsNot <T>(this IIsPossibly <T> self)
 {
     if (self is IIsDefinately <T> )
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #14
0
 public static TT IfElseReturn <T, TT>(this IIsPossibly <T> self, Func <T, TT> ifIs, Func <TT> ifNot)
 {
     if (self is IIsDefinately <T> isYes)
     {
         return(ifIs(isYes.Value));
     }
     else
     {
         return(ifNot());
     }
 }
Пример #15
0
 public static IBuildIntention <IMemberDefinition> GetBuildIntention(IIsPossibly <IWeakTypeReference> Type, IConversionContext context, bool ReadOnly, IKey Key)
 {
     var(toBuild, maker) = MemberDefinition.Create();
     return(new BuildIntention <IMemberDefinition>(toBuild, () =>
     {
         maker.Build(
             Key,
             Type.GetOrThrow().TypeDefinition.GetOrThrow().GetValue().GetOrThrow().ConvertTypeOrThrow(context),
             ReadOnly);
     }));
 }
Пример #16
0
 public static void IfElse <T>(this IIsPossibly <T> self, Action <T> ifIs, Action ifNot)
 {
     if (self is IIsDefinately <T> isYes)
     {
         ifIs(isYes.Value);
     }
     else
     {
         ifNot();
     }
 }
Пример #17
0
 public WeakMethodDefinition(
     IIsPossibly <IWeakTypeReference> outputType,
     IIsPossibly <IBox <IIsPossibly <IWeakMemberDefinition> > > parameterDefinition,
     IIsPossibly <IFrontendCodeElement>[] body,
     IResolvableScope scope,
     IEnumerable <IIsPossibly <IConvertableFrontendCodeElement <ICodeElement> > > staticInitializers,
     bool isEntryPoint) : base(scope ?? throw new ArgumentNullException(nameof(scope)), body, staticInitializers)
 {
     OutputType          = outputType ?? throw new ArgumentNullException(nameof(outputType));
     ParameterDefinition = parameterDefinition ?? throw new ArgumentNullException(nameof(parameterDefinition));
     IsEntryPoint        = isEntryPoint;
 }
Пример #18
0
 public static bool Is <T>(this IIsPossibly <T> self, out T t)
 {
     if (self is IIsDefinately <T> isYes)
     {
         t = isYes.Value;
         return(true);
     }
     else
     {
         t = default;
         return(false);
     }
 }
Пример #19
0
 public FrontEndOrType(
     IBox <IOrType <IFrontendType <IVerifiableType>, IError> > left,
     IBox <IOrType <IFrontendType <IVerifiableType>, IError> > right,
     IOrType <IReadOnlyList <WeakMemberDefinition>, IError> members,
     IIsPossibly <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > > input,
     IIsPossibly <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > > output)
 {
     this.left    = left ?? throw new ArgumentNullException(nameof(left));
     this.right   = right ?? throw new ArgumentNullException(nameof(right));
     this.members = members ?? throw new ArgumentNullException(nameof(members));
     this.input   = input ?? throw new ArgumentNullException(nameof(input));
     this.output  = output ?? throw new ArgumentNullException(nameof(output));
 }
Пример #20
0
 public WeakImplementationDefinition(
     IIsPossibly <IBox <IIsPossibly <IWeakMemberDefinition> > > contextDefinition,
     IIsPossibly <IBox <IIsPossibly <IWeakMemberDefinition> > > parameterDefinition,
     IIsPossibly <IWeakTypeReference> outputType,
     IEnumerable <IIsPossibly <IFrontendCodeElement> > metohdBody,
     IResolvableScope scope,
     IEnumerable <IFrontendCodeElement> staticInitializers)
 {
     ContextDefinition   = contextDefinition ?? throw new ArgumentNullException(nameof(contextDefinition));
     OutputType          = outputType ?? throw new ArgumentNullException(nameof(outputType));
     ParameterDefinition = parameterDefinition ?? throw new ArgumentNullException(nameof(parameterDefinition));
     MethodBody          = metohdBody ?? throw new ArgumentNullException(nameof(metohdBody));
     Scope             = scope ?? throw new ArgumentNullException(nameof(scope));
     StaticInitialzers = staticInitializers ?? throw new ArgumentNullException(nameof(staticInitializers));
 }
Пример #21
0
        public PopulatableScope()
        {
            this.Parent      = Possibly.IsNot <PopulatableScope>();
            finalizableScope = new FinalizableScope(this);

            // do these really belong here or should they be defined in some sort of 'standard library'
            // here for now I think
            TryAddType(new NameKey("int"), new Box <IIsPossibly <IFrontendType> >(Possibly.Is <IFrontendType>(PrimitiveTypes.CreateNumberType())));
            TryAddType(new NameKey("string"), new Box <IIsPossibly <IFrontendType> >(Possibly.Is <IFrontendType>(PrimitiveTypes.CreateStringType())));
            TryAddType(new NameKey("any"), new Box <IIsPossibly <IFrontendType> >(Possibly.Is <IFrontendType>(PrimitiveTypes.CreateAnyType())));
            TryAddType(new NameKey("empty"), new Box <IIsPossibly <IFrontendType> >(Possibly.Is <IFrontendType>(PrimitiveTypes.CreateEmptyType())));
            TryAddType(new NameKey("bool"), new Box <IIsPossibly <IFrontendType> >(Possibly.Is <IFrontendType>(PrimitiveTypes.CreateBooleanType())));
            TryAddGeneric(
                new NameKey("method"),
                new Box <IIsPossibly <IFrontendGenericType> >(Possibly.Is <IFrontendGenericType>(PrimitiveTypes.CreateGenericMethodType())));
            TryAddGeneric(
                new NameKey("implementation"), new Box <IIsPossibly <IFrontendGenericType> >(Possibly.Is <IFrontendGenericType>(PrimitiveTypes.CreateGenericImplementationType())));
        }
Пример #22
0
 public WeakReturnOperation(IIsPossibly <IFrontendCodeElement> result)
 {
     Result = result;
 }
Пример #23
0
 public WeakConstantString(IIsPossibly <string> value)
 {
     Value = value;
 }
Пример #24
0
 public WeakConstantNumber(IIsPossibly <double> value)
 {
     Value = value;
 }
Пример #25
0
 public WeakConstantBool(IIsPossibly <bool> value)
 {
     Value = value;
 }
Пример #26
0
                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);
                }
Пример #27
0
 public WeakTypeDefinition(IResolvableScope scope, IIsPossibly <IKey> key)
 {
     Key   = key ?? throw new ArgumentNullException(nameof(key));
     Scope = scope ?? throw new ArgumentNullException(nameof(scope));
 }
Пример #28
0
 public WeakMemberDefinition(bool readOnly, IKey key, IIsPossibly <IWeakTypeReference> type)
 {
     Type     = type ?? throw new ArgumentNullException(nameof(type));
     ReadOnly = readOnly;
     Key      = key ?? throw new ArgumentNullException(nameof(key));
 }
Пример #29
0
 // right should have more validation
 public WeakIfTrueOperation(IIsPossibly <IFrontendCodeElement> left, IIsPossibly <IFrontendCodeElement> right) : base(left, right)
 {
 }
Пример #30
0
 private SetUpContext(Tpn.TypeProblem2.Builder typeProblem, IIsPossibly <ISetUpContext> parent, IIsPossibly <ISetUp> enclosingSetUp)
 {
     TypeProblem    = typeProblem ?? throw new ArgumentNullException(nameof(typeProblem));
     Parent         = parent ?? throw new ArgumentNullException(nameof(parent));
     EnclosingSetUp = enclosingSetUp ?? throw new ArgumentNullException(nameof(enclosingSetUp));
 }