else if (tleft instanceof NodeSetDTMType && tright instanceof NodeType) { swapArguments();
else if (tleft instanceof NodeSetType && tright instanceof NodeType) { swapArguments();
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {	final Type tleft = _left.typeCheck(stable); 	final Type tright = _right.typeCheck(stable);	if (tleft.isSimple() && tright.isSimple()) {	    if (tleft != tright) {		if (tleft instanceof BooleanType) {		    _right = new CastExpr(_right, Type.Boolean);		}		else if (tright instanceof BooleanType) {		    _left = new CastExpr(_left, Type.Boolean);		}		else if (tleft instanceof NumberType || 			 tright instanceof NumberType) {		    _left = new CastExpr(_left, Type.Real);		    _right = new CastExpr(_right, Type.Real);		}		else {		// both compared as strings		    _left = new CastExpr(_left,   Type.String);		    _right = new CastExpr(_right, Type.String);		}	    }	}	else if (tleft instanceof ReferenceType) {	    _right = new CastExpr(_right, Type.Reference);	}	else if (tright instanceof ReferenceType) {	    _left = new CastExpr(_left, Type.Reference);	}	// the following 2 cases optimize @attr|.|.. = 'string'	else if (tleft instanceof NodeType && tright == Type.String) {	    _left = new CastExpr(_left, Type.String);	}	else if (tleft == Type.String && tright instanceof NodeType) {	    _right = new CastExpr(_right, Type.String);	}	// optimize node/node	else if (tleft instanceof NodeType && tright instanceof NodeType) {	    _left = new CastExpr(_left, Type.String);	    _right = new CastExpr(_right, Type.String);	}	else if (tleft instanceof NodeType && tright instanceof NodeSetDTMType) {	    // compare(Node, NodeSetDTM) will be invoked	}	else if (tleft instanceof NodeSetDTMType && tright instanceof NodeType) {	    swapArguments();	// for compare(Node, NodeSetDTM)	}	else {		    // At least one argument is of type node, node-set or result-tree	    // Promote an expression of type node to node-set	    if (tleft instanceof NodeType) {		_left = new CastExpr(_left, Type.NodeSetDTM);	    }	    if (tright instanceof NodeType) {		_right = new CastExpr(_right, Type.NodeSetDTM);	    }	    // If one arg is a node-set then make it the left one	    if (tleft.isSimple() ||		tleft instanceof ResultTreeType &&		tright instanceof NodeSetDTMType) {		swapArguments();	    }	    // Promote integers to doubles to have fewer compares	    if (_right.getType() instanceof IntType) {		_right = new CastExpr(_right, Type.Real);	    }	}	return _type = Type.Boolean;    }