예제 #1
0
        public override bool SupportsImplicit(TypeReference value)
        {
            if (value == null)
            {
                return(true);
            }
            if (value is NullableTypeReference)
            {
                return(false);
            }
            FunctionTypeReference tr = value as FunctionTypeReference;

            if (tr == null)
            {
                return(false);
            }
            if (!returnType.SupportsImplicit(tr.returnType))
            {
                return(false);
            }
            if (parameters.Count != tr.parameters.Count)
            {
                return(false);
            }
            for (int i = 0; i < parameters.Count; ++i)
            {
                if (!parameters[i].SupportsImplicit(tr.parameters[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
 public override bool SupportsImplicit(TypeReference value)
 {
     if (value == null)
     {
         return(true);
     }
     if (value is NullableTypeReference)
     {
         return(parent.SupportsImplicit(((NullableTypeReference)value).Parent));
     }
     else
     {
         if (value.TypeName.Data != "void")
         {
             return(parent.SupportsImplicit(value));
         }
         else
         {
             return(true);
         }
     }
 }
예제 #3
0
        public override void Generate(Generator generator)
        {
            base.Generate(generator);
            parent.Generate(generator);
            generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this);
            TypeReference ptr = parent.TypeReference;
            TypeReference str = returnType;

            if (str.SupportsImplicit(ptr))
            {
                returnType.GenerateConversion(this, generator, parent.TypeReference);
            }
            else
            {
                JumpToken jtNull = null;
                jtNull = generator.Assembler.CreateJumpToken();
                generator.Assembler.JumpIfUnassigned(jtNull);
                generator.Assembler.TypeConversionDynamicNotNull(resolvedType.Id);
                generator.Assembler.SetDestination(jtNull);
            }
        }
예제 #4
0
        public override void Generate(Generator generator)
        {
            base.Generate(generator);
            parent.Generate(generator);
            generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this);
            TypeReference ptr       = parent.TypeReference;
            bool          allowNull = ptr.IsNullable && !typeReference.IsNullable;

            if (!allowNull)
            {
                generator.Assembler.CrashIfNull();
            }
            TypeReference str = typeReference;

            if (str.SupportsImplicit(ptr))
            {
                typeReference.GenerateConversion(this, generator, parent.TypeReference);
            }
            else
            {
                JumpToken jtNull = null;
                if (allowNull)
                {
                    jtNull = generator.Assembler.CreateJumpToken();
                    generator.Assembler.JumpIfUnassigned(jtNull);
                }
                generator.Assembler.TypeConversionDynamicNotNull(str.Id);
                JumpToken jtOk = generator.Assembler.CreateJumpToken();
                generator.Assembler.JumpIfAssigned(jtOk);
                throwCastException.Generate(generator, null);
                generator.Assembler.SetDestination(jtOk);
                if (allowNull)
                {
                    generator.Assembler.SetDestination(jtNull);
                }
            }
        }