Пример #1
0
        public override IAssignEmitter AssignFrom(ModuleContext context, TO2Type otherType)
        {
            RealizedType underlyingOther = otherType.UnderlyingType(context);

            return(!(underlyingOther is OptionType) && elementType.IsAssignableFrom(context, underlyingOther)
                ? new AssignSome(this, otherType)
                : DefaultAssignEmitter.Instance);
        }
Пример #2
0
 public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType)
 {
     if (!(otherType.UnderlyingType(context) is TupleType))
     {
         return(false);
     }
     return(GeneratedType(context).IsAssignableFrom(otherType.GeneratedType(context)));
 }
Пример #3
0
        public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType)
        {
            if (otherType.UnderlyingType(context) is OptionType otherOption)
            {
                return(elementType.IsAssignableFrom(context, otherOption.elementType));
            }

            return(elementType.IsAssignableFrom(context, otherType));
        }
Пример #4
0
        public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType)
        {
            if (otherType.UnderlyingType(context) is ResultType otherResultType)
            {
                return(successType.IsAssignableFrom(context, otherResultType.successType) &&
                       errorType.IsAssignableFrom(context, otherResultType.errorType));
            }

            return(successType.IsAssignableFrom(context, otherType));
        }
Пример #5
0
        public override RealizedType UnderlyingType(ModuleContext context)
        {
            if (lookingUp)
            {
                throw new CompilationErrorException(new List <StructuralError> {
                    new StructuralError(
                        StructuralError.ErrorType.InvalidType,
                        $"Cyclic dependency to {aliasedType.Name}",
                        target.Start,
                        target.End
                        )
                });
            }
            lookingUp = true;
            RealizedType realized = aliasedType.UnderlyingType(declaredModule);

            lookingUp = false;
            return(realized);
        }
Пример #6
0
        public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType)
        {
            RecordType recordType = otherType.UnderlyingType(context) as RecordType;

            if (recordType == null)
            {
                return(false);
            }
            foreach (var kv in ItemTypes)
            {
                TO2Type otherItem = recordType.ItemTypes.Get(kv.Key);

                if (otherItem == null || !kv.Value.IsAssignableFrom(context, otherItem))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #7
0
        public IOperatorEmitter GetMatching(ModuleContext context, Operator op, TO2Type otherType)
        {
            IOperatorEmitter existing = allowedOperators.GetMatching(context, op, otherType);

            if (existing != null)
            {
                return(existing);
            }

            if (op != Operator.BitAnd && op != Operator.BitAndAssign)
            {
                return(null);
            }

            RecordType otherRecordType = otherType.UnderlyingType(context) as RecordType;

            if (otherRecordType == null)
            {
                return(null);
            }

            bool hasMatch = false;

            foreach (var otherKV in otherRecordType.ItemTypes)
            {
                TO2Type item = recordType.ItemTypes.Get(otherKV.Key);

                if (item == null)
                {
                    continue;
                }
                if (!item.IsAssignableFrom(context, otherKV.Value))
                {
                    return(null);
                }
                hasMatch = true;
            }

            return(hasMatch ? recordType.CombineFrom(otherRecordType) : null);
        }
Пример #8
0
 public override RealizedType UnderlyingType(ModuleContext context) =>
 new OptionType(elementType.UnderlyingType(context));
Пример #9
0
 public override RealizedType UnderlyingType(ModuleContext context) => new FunctionType(isAsync,
                                                                                        parameterTypes.Select(p => p.UnderlyingType(context) as TO2Type).ToList(),
                                                                                        returnType.UnderlyingType(context));
Пример #10
0
 public override RealizedType UnderlyingType(ModuleContext context) =>
 new ResultType(successType.UnderlyingType(context), errorType.UnderlyingType(context));