private static string BalanceArithmetic(string operand, IGraphModel model) { switch (operand) { case "byte": case "short": case "int": return("int"); case "long": return("long"); case "float": return("float"); case "double": return("double"); case "": return(""); default: if (TypesHelper.IsEnumType(operand, model)) { return("int"); } else { return("-"); } } }
/// <summary> /// Returns the types to which the operands must be casted to, /// assuming an arithmetic operator. /// Returns "" if the type can only be determined at runtime. /// Returns "-" in case of a type error and/or if no operator working on numbers can be applied. /// </summary> private static string BalanceArithmetic(string left, string right, IGraphModel model) { switch (left) { case "byte": case "short": case "int": switch (right) { case "byte": return("int"); case "short": return("int"); case "int": return("int"); case "long": return("long"); case "float": return("float"); case "double": return("double"); case "": return(""); default: if (TypesHelper.IsEnumType(right, model)) { return("int"); } else { return("-"); } } case "long": switch (right) { case "byte": return("long"); case "short": return("long"); case "int": return("long"); case "long": return("long"); case "float": return("float"); case "double": return("double"); case "": return(""); default: if (TypesHelper.IsEnumType(right, model)) { return("long"); } else { return("-"); } } case "float": switch (right) { case "byte": return("float"); case "short": return("float"); case "int": return("float"); case "long": return("float"); case "float": return("float"); case "double": return("double"); case "": return(""); default: if (TypesHelper.IsEnumType(right, model)) { return("float"); } else { return("-"); } } case "double": switch (right) { case "byte": return("double"); case "short": return("double"); case "int": return("double"); case "long": return("double"); case "float": return("double"); case "double": return("double"); case "": return(""); default: if (TypesHelper.IsEnumType(right, model)) { return("double"); } else { return("-"); } } case "": switch (right) { case "byte": return(""); case "short": return(""); case "int": return(""); case "long": return(""); case "float": return(""); case "double": return(""); case "": return(""); default: if (TypesHelper.IsEnumType(right, model)) { return(""); } else { return("-"); } } default: if (TypesHelper.IsEnumType(left, model) && TypesHelper.IsEnumType(right, model)) { return("int"); } else { return("-"); } } }