Пример #1
0
        /// <summary>
        /// Devuelve el delegate que genera el codigo para la operacion especificada
        /// </summary>
        /// <param name="other">Tipo del otro operando</param>
        /// <param name="op">Operador en cuestion</param>
        /// <returns>Generador de operacion si esta definida, null en otro caso</returns>
        public virtual GenOperation GetOperationGenerator(TigerType other, Operators op)
        {
            OperationInfo nfo;

            operatorTable.TryGetValue(this + op.ToString() + other, out nfo);
            return(nfo != null ? nfo.GenOperation : null);
        }
Пример #2
0
        /// <summary>
        /// Devuelve el tipo de retorno de la operacion especificada
        /// </summary>
        /// <param name="other">Tipo del otro operando</param>
        /// <param name="op">Operador en cuestion</param>
        /// <returns>Generador de operacion si esta definida, null en otro caso</returns>
        public virtual TigerType GetOperationResult(TigerType other, Operators op)
        {
            OperationInfo nfo;

            operatorTable.TryGetValue(this + op.ToString() + other, out nfo);
            return(nfo != null ? nfo.ResultType : null);
        }
Пример #3
0
        public ArrayType(TigerType baseType, string typeId)
        {
            BaseType = baseType;
            TypeID   = typeId;

            #region Comparison Array-Array

            //operacion ==
            AddBinaryOperation(this, GetType <IntType>(), Operators.Equal, EqualOpGenerator, true);

            //operacion <>
            AddBinaryOperation(this, GetType <IntType>(), Operators.NotEqual, NeqOpGenerator, true);

            #endregion

            #region Comparison Array -Nil

            //operacion ==
            AddBinaryOperation(GetType <NilType>(), GetType <IntType>(), Operators.Equal, EqualOpGenerator, true);

            //operacion <>
            AddBinaryOperation(GetType <NilType>(), GetType <IntType>(), Operators.NotEqual, NeqOpGenerator, true);

            #endregion
        }
Пример #4
0
        public override bool SupportsOperator(TigerType other, Operators op)
        {
            switch (op)
            {
            case Operators.And:
            case Operators.Or:
                return(other == this);

            default:
                return(base.SupportsOperator(other, op));
            }
        }
Пример #5
0
        /// <summary>
        /// Devuelve true si el operador puede ser aplicado a dos operandos del tipo de la clase.
        /// </summary>
        /// <param name="op">El operador en cuestion </param>
        /// <param name="other">Tipo del otro operando</param>
        /// <returns></returns>
        public virtual bool SupportsOperator(TigerType other, Operators op)
        {
            switch (op)
            {
            case Operators.Equal:
            case Operators.NotEqual:
            {
                if (this == other && !(other is NilType))
                {
                    return(true);
                }
                if (other is NilType)
                {
                    return(!IsValueType && !(this is NilType));
                }
                return(!(other.IsValueType && this is NilType));
            }

            default:
                return(operatorTable.ContainsKey(this + op.ToString() + other));
            }
        }
Пример #6
0
        /// <summary>
        /// Anade soporte para u operador binario
        /// </summary>
        /// <param name="other">Tipo del otro operando</param>
        /// <param name="resultType">Tipo del resultado de la operacion</param>
        /// <param name="op">Operador en cuestion</param>
        /// <param name="generator">Generador de codigo para la operacion</param>
        /// <param name="predefinedOp">Indica si es una operacion predefinida en el lenguaje</param>
        public void AddBinaryOperation(TigerType other, TigerType resultType, Operators op, GenOperation generator,
                                       bool predefinedOp)
        {
//            if ((int)op >= 10)
//                throw new InvalidOperationException("Operator " + op + " can not be defined for the given types");

            var nfo = new OperationInfo
            {
                ResultType            = resultType,
                Op1                   = this,
                Op2                   = other,
                CurrentOperator       = op,
                GenOperation          = generator,
                IsPredefinedOperation = predefinedOp
            };
            string id = nfo.ToString();

            if (operatorTable.ContainsKey(id))
            {
                throw new InvalidOperationException("Operations can not be redefined");
            }
            operatorTable.Add(id, nfo);
        }
Пример #7
0
 public void AddField(string fieldId, TigerType t)
 {
     field.Add(fieldId, t);
 }
Пример #8
0
 public override GenOperation GetOperationGenerator(TigerType other, Operators op)
 {
     return(x => { });
 }
Пример #9
0
 public override TigerType GetOperationResult(TigerType other, Operators op)
 {
     return(other);
 }
Пример #10
0
 public override bool SupportsOperator(TigerType tt, Operators op)
 {
     return(true);
 }
Пример #11
0
 public override bool CanConvertTo(TigerType type)
 {
     return(true);
 }
Пример #12
0
 /// <summary>
 /// Dice si el tipo machea con otro.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public virtual bool CanConvertTo(TigerType type)
 {
     return(this == type);
 }