public override object Exec(ClassType caller, object arg)
        {
            //TODO: comprobar si es el name de caller.
            MethodType method = (MethodType)caller.AcceptOperation(DotOperation.Create(caller.Name, new List <TypeExpression>()), arg);

            if (method == null)
            {
                return(null);
            }
            return(method.AcceptOperation(this, arg));
        }
Пример #2
0
        public override object Exec(ClassType d, object arg)
        {
            TypeExpression member = (TypeExpression)d.AcceptOperation(new UnconstrainedDotOperation(memberName, this.previousDot), arg);

            if (member == null)
            {
                ErrorManager.Instance.NotifyError(new UnknownMemberError(this.memberName, this.location));
                return(null);
            }
            if (!d.validAccess(member))
            {
                ErrorManager.Instance.NotifyError(new ProtectionLevelError(this.memberName, this.location));
                return(null);
            }
            return(member);
        }
        public override object Exec(ClassType firstOperand, object arg)
        {
            int aux, less = -1;
            EquivalentOperation equivalentType = new EquivalentOperation(this.secondOperand);

            // * The same type
            if (firstOperand == this.secondOperand)
            {
                return(0);
            }
            // * Equivalent types
            if ((bool)firstOperand.AcceptOperation(equivalentType, arg))
            {
                return(0);
            }

            // * Field type and bounded type variable
            FieldType fieldType = TypeExpression.As <FieldType>(this.secondOperand);

            if (fieldType != null)
            {
                return(firstOperand.AcceptOperation(new PromotionLevelOperation(fieldType.FieldTypeExpression), arg));
            }

            // * WriteType variable
            TypeVariable typeVariable = this.secondOperand as TypeVariable;

            if (typeVariable != null)
            {
                if (typeVariable.Substitution != null)
                {
                    // * If the variable is bounded, the promotion is the one of its substitution
                    return(firstOperand.AcceptOperation(new PromotionLevelOperation(typeVariable.EquivalenceClass.Substitution), arg));
                }
                // * A free variable is complete promotion
                return(0);
            }

            // * Inheritance
            if (firstOperand.BaseClass == null)
            {
                // * Object only promotes to object
                return(-1);
            }
            if ((bool)firstOperand.BaseClass.AcceptOperation(equivalentType, arg))
            {
                return(1);
            }
            else
            {
                //aux = firstOperand.baseClass.AcceptOperation(new PromotionLevelOperation(this.secondOperand)));
                aux = (int)firstOperand.BaseClass.AcceptOperation(this, arg);
                if (aux != -1)
                {
                    return(aux + 1);
                }
            }

            // * Interfaces
            if (firstOperand.InterfaceList.Count != 0)
            {
                for (int i = 0; i < firstOperand.InterfaceList.Count; i++)
                {
                    if ((bool)firstOperand.InterfaceList[i].AcceptOperation(equivalentType, arg))
                    {
                        if (less > 1 || less == -1)
                        {
                            less = 1;
                        }
                    }
                    else
                    {
                        aux = (int)firstOperand.InterfaceList[i].AcceptOperation(this, arg);
                        if (aux != -1)
                        {
                            if (less > aux + 1 || less == -1)
                            {
                                less = aux + 1;
                            }
                        }
                    }
                }
            }
            if (less != -1)
            {
                return(less);
            }

            // * Union type
            UnionType unionType = TypeExpression.As <UnionType>(this.secondOperand);

            if (unionType != null)
            {
                return(unionType.SuperType(firstOperand));
            }

            // * No promotion
            return(-1);
        }