// TODO // hay conversiones que no sé hacer public override object Exec(StringType s, object arg) { if (TypeExpression.Is <StringType>(this.secondTypeExpression)) { } return(null); }
public override object Exec(DoubleType d, object arg) { if (TypeExpression.Is <StringType>(this.secondTypeExpression)) { return(d.AcceptOperation(new CGToStringOperation <ILCodeGenerator>(this.codeGenerator, this.indent), true)); // we force a box } return(null); }
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)); }
protected override void GenerateOperator(BinaryExpression node, TypeExpression result) { ArithmeticOperator arithmeticOperator = ((ArithmeticExpression)node).Operator; bool isConcat = false; switch (arithmeticOperator) { case ArithmeticOperator.Minus: this.codeGenerator.sub(this.indent); break; case ArithmeticOperator.Plus: if (TypeExpression.Is <StringType>(result)) { isConcat = true; this.codeGenerator.concat(this.indent); } else { this.codeGenerator.add(this.indent); } break; case ArithmeticOperator.Mult: this.codeGenerator.mul(this.indent); break; case ArithmeticOperator.Div: this.codeGenerator.div(this.indent); break; case ArithmeticOperator.Mod: this.codeGenerator.rem(this.indent); break; default: // Error this.codeGenerator.Comment("ERROR"); break; } if (!isConcat && !IsValueType(node.ExpressionType) && !(node.ExpressionType is StringType)) { this.codeGenerator.Box(indent, result); } if (!string.IsNullOrEmpty(label_result)) { this.codeGenerator.stloc(this.indent, label_result); } if (result == null) { codeGenerator.WriteThrowNonSuitableObjectException(indent, StringType.Instance.FullName, arithmeticOperator.ToString()); } }
/// <summary> /// It delegates the operation in several types. /// </summary> /// <param name="operand"></param> /// <returns></returns> public override object Exec(TypeVariable operand, object arg) { if (!operand.IsValueType()) { return(null); } if (TypeExpression.Is <IntType>(operand)) { return(this.Exec(TypeExpression.As <IntType>(operand), arg)); } if (TypeExpression.Is <DoubleType>(operand)) { return(this.Exec(TypeExpression.As <DoubleType>(operand), arg)); } return(this.Exec((TypeExpression)operand, arg)); }
public override object Exec(TypeExpression typeExpression, object arg) { if (typeExpression is UnionType) { this.Exec(typeExpression as UnionType, arg); } else if (typeExpression is TypeVariable) { this.Exec(typeExpression as TypeVariable, arg); } else if (typeExpression is PropertyType) { this.Exec(((PropertyType)typeExpression).PropertyTypeExpression, arg); } else if (typeExpression is FieldType) { FieldType fieldType = ((FieldType)typeExpression); if (fieldType.FieldTypeExpression is TypeVariable && ((TypeVariable)fieldType.FieldTypeExpression).Substitution != null && ((TypeVariable)fieldType.FieldTypeExpression).Substitution.IsValueType()) { UnionType union = new UnionType(); union.AddType(((TypeVariable)((FieldType)typeExpression).FieldTypeExpression).Substitution); this.Exec(union, arg); } else { this.Exec(((FieldType)typeExpression).FieldTypeExpression, arg); } } else if (IsValueType(typeExpression) || TypeExpression.Is <StringType>(typeExpression)) { GenerateRightOperand(typeExpression, this.node.SecondOperand.ILTypeExpression); } else if (typeExpression is NullType) { this.codeGenerator.ldnull(this.indent); GenerateRightOperand(typeExpression, this.node.SecondOperand.ILTypeExpression); } else if (typeExpression is UserType) { GenerateRightOperand(typeExpression, this.node.SecondOperand.ILTypeExpression); } return(null); }
private void GenerateRightOperand(TypeExpression teLeft, TypeExpression teRight) { if (teRight is UnionType) { this.GenerateRightOperand(teLeft, teRight as UnionType); } else if (teRight is TypeVariable) { this.GenerateRightOperand(teLeft, teRight as TypeVariable); } else if (teRight is PropertyType) { GenerateRightOperand(teLeft, ((PropertyType)teRight).PropertyTypeExpression); } else if (teRight is FieldType) { FieldType fieldType = ((FieldType)teRight); if (fieldType.FieldTypeExpression is TypeVariable && ((TypeVariable)fieldType.FieldTypeExpression).Substitution != null && ((TypeVariable)fieldType.FieldTypeExpression).Substitution.IsValueType()) { UnionType union = new UnionType(); union.AddType(((TypeVariable)((FieldType)teRight).FieldTypeExpression).Substitution); GenerateRightOperand(teLeft, union); } else { GenerateRightOperand(teLeft, ((FieldType)teRight).FieldTypeExpression); } } else if (IsValueType(teRight) || TypeExpression.Is <StringType>(teRight)) { if (IsInternallyAnObject(node.FirstOperand)) { if (!(teLeft is StringType) && IsValueType(teRight)) { this.codeGenerator.UnboxAny(indent, teLeft); } } else { if (!CheckUnBox(teLeft, teRight)) { CheckBox(teLeft, teRight); } } LoadSecondOperand(); if (IsInternallyAnObject(node.SecondOperand)) { if (!(teRight is StringType) && IsValueType(teLeft)) { this.codeGenerator.UnboxAny(indent, teRight); } } else { if (!CheckUnBox(teRight, teLeft)) { CheckBox(teRight, teLeft); } } GenerateOperator(node, MajorType(teLeft, teRight)); } else if (teRight is NullType) { this.codeGenerator.ldnull(this.indent); GenerateOperator(node, MajorType(teLeft, teRight)); } }