void DoOperation(ILCode code) { GenOperation g = _binaryExpression.LeftExp.ReturnType.GetOperationGenerator(_binaryExpression.LeftExp.ReturnType, _binaryExpression.Operator) ?? _binaryExpression.RightExp.ReturnType.GetOperationGenerator(_binaryExpression.RightExp.ReturnType, _binaryExpression.Operator); if (g != null) { g(code); } else { throw new InvalidOperationException("The operation is not supported"); } }
/// <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); }