operand1 = TypeChecker.staticTypeCheck(operand1, atomicType, backwardsCompatible, role1, env);
// System.err.println("Second operand"); operand1.display(10);
Expression e = super.analyze(env, contextItemType);
if (e instanceof ArithmeticExpression) {
final ItemType type0 = operand0.getItemType().getPrimitiveItemType();
final ItemType type1 = operand1.getItemType().getPrimitiveItemType();
final int action = getAction(type0, operator, type1);
switch (action) {
case NUMERIC_ARITHMETIC:
e = new NumericArithmetic(operand0, operator, operand1);
break;
case DURATION_ADDITION:
e = new DurationAddition(operand0, operator, operand1);
break;
case DURATION_MULTIPLICATION:
e = new DurationMultiplication(operand0, operator, operand1);
break;
case DURATION_DIVISION:
e = new DurationDivision(operand0, operator, operand1);
break;
case DATE_AND_DURATION:
e = new DateAndDuration(operand0, operator, operand1);
break;
case DATE_DIFFERENCE:
e = new DateDifference(operand0, operator, operand1);
break;
default:
// either the types are not known yet, or they are wrong
if (!backwardsCompatible &&
Type.isSubType(type0, Type.ANY_ATOMIC_TYPE) &&
type0 != Type.UNTYPED_ATOMIC_TYPE &&
type0 != Type.ANY_ATOMIC_TYPE &&
Type.isSubType(type1, Type.ANY_ATOMIC_TYPE) &&
type1 != Type.UNTYPED_ATOMIC_TYPE &&
type1 != Type.ANY_ATOMIC_TYPE) {
StaticError err = new StaticError("Unsuitable operands for arithmetic operation (" +
type0.toString(env.getNamePool()) + ", " +
type1.toString(env.getNamePool()) + ')');
err.setIsTypeError(true);
throw err;
}
return e;
}