Esempio n. 1
0
        public override object Exec(CharType c, object arg)
        {
            if (TypeExpression.Is <DoubleType>(this.secondTypeExpression))
            {
                this.codeGenerator.convToDouble(this.indent);
            }

            if (TypeExpression.Is <StringType>(this.secondTypeExpression))
            {
                return(c.AcceptOperation(new CGToStringOperation <ILCodeGenerator>(this.codeGenerator, this.indent), true)); // we force a box
            }
            return(null);
        }
        public override object Exec(CharType firstOperand, object arg)
        {
            // * Char type and type variable
            if (TypeExpression.As <CharType>(this.secondOperand) != null)
            {
                return(0);
            }
            // * Int type and type variable
            if (TypeExpression.As <IntType>(this.secondOperand) != null)
            {
                return(1);
            }
            // * Double type and type variable
            if (TypeExpression.As <DoubleType>(this.secondOperand) != null)
            {
                return(2);
            }
            // * Free type variables
            TypeVariable typeVariable = this.secondOperand as TypeVariable;

            if (typeVariable != null && typeVariable.Substitution == null)
            {
                // * A free variable is complete promotion
                return(0);
            }
            // * Union type
            UnionType unionType = TypeExpression.As <UnionType>(this.secondOperand);

            if (unionType != null)
            {
                return(unionType.SuperType(firstOperand));
            }
            // * Field type and bounded type variable
            FieldType fieldType = TypeExpression.As <FieldType>(this.secondOperand);

            if (fieldType != null)
            {
                return(firstOperand.AcceptOperation(new PromotionLevelOperation(fieldType.FieldTypeExpression), arg));
            }
            // * Use the BCL object oriented approach
            //return firstOperand.BCLType.AcceptOperation(new PromotionLevelOperation(this.secondOperand)));
            return(firstOperand.AsClassType().AcceptOperation(this, arg));
        }
        public override object Exec(CharType firstTypeExpression, object arg)
        {
            if (this.node.Operator == ArithmeticOperator.Plus && TypeExpression.Is <StringType>(this.secondTypeExpression))
            {
                return(StringType.Instance);
            }

            return(TypeExpression.Is <CharType>(this.secondTypeExpression) ? IntType.Instance : firstTypeExpression.AcceptOperation(new MajorTypeOperation(this.secondTypeExpression), arg));
        }