//// <summary>
        /// Returns an int value encapsulated in an object item that indicates a promotion level.
        /// </summary>
        /// <param name="firstOperand">An array to promote.</param>
        /// <returns>Returns a promotion value.</returns>
        public override object Exec(ArrayType firstOperand, object arg)
        {
            // * Array and bounded type variable
            ArrayType array = TypeExpression.As <ArrayType>(this.secondOperand);

            if (array != null)
            {
                TypeExpression firstOperandArrayTypeExpression  = firstOperand.ArrayTypeExpression;
                TypeExpression secondOperandArrayTypeExpression = array.ArrayTypeExpression;
                if (firstOperandArrayTypeExpression is TypeVariable && ((TypeVariable)firstOperandArrayTypeExpression).Substitution != null)
                {
                    firstOperandArrayTypeExpression = ((TypeVariable)firstOperandArrayTypeExpression).Substitution;
                }
                if (secondOperandArrayTypeExpression is TypeVariable && ((TypeVariable)secondOperandArrayTypeExpression).Substitution != null)
                {
                    secondOperandArrayTypeExpression = ((TypeVariable)secondOperandArrayTypeExpression).Substitution;
                }
                return(firstOperandArrayTypeExpression.Equals(secondOperandArrayTypeExpression) ? 0 : -1);
            }

            // * A free variable is a complete promotion
            TypeVariable typeVariable = this.secondOperand as TypeVariable;

            if (typeVariable != null && typeVariable.Substitution == null)
            {
                return(0);
            }
            // * Union type and bounded type variable
            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.AsClassType().AcceptOperation(this, arg));
        }
예제 #2
0
 public override object Exec(TypeExpression te, object arg)
 {
     return(te.Equals(this.typeExpression));
 }