@Override public ColumnExpressions<?> castValue(TypedValue.CastValue val, Void in) throws TypedValueVisitorException { // TODO: Check if cast is consistent with the reader // SQLColumnValues toReturn = val.operand.visit(this, in); // if (!toReturn.reader.isCastConsistent(val.getType().getInternalName())) // throw new TypedValueVisitorException("Attempting to cast to an inconsistent type"); return val.operand.visit(this, in); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; UnaryOperationValue other = (UnaryOperationValue) obj; if (operand == null) { if (other.operand != null) return false; } else if (!operand.equals(other.operand)) return false; return true; }
private <U> ColumnExpressions<U> binaryOpWithNumericPromotion(String opString, TypedValue leftVal, TypedValue rightVal, SymbExPassDown passdown) throws TypedValueVisitorException { boolean isFinalTypeFromLeft = true; // Handle operations with NULL separately if (leftVal instanceof ConstantValue.NullConstant || rightVal instanceof ConstantValue.NullConstant) return binaryOpWithNull(opString, leftVal, rightVal, passdown); // Check if we have a valid numeric promotion (i.e. one side has a widening cast // to match the type of the other side). assert(leftVal.getType().equals(rightVal.getType()) || (leftVal.getType().getInternalName().equals("java/lang/Object") && config.isObjectEqualsSafe)// in Scala, many comparisons are done on Objects || (rightVal.getType().getInternalName().equals("java/lang/Object") && config.isObjectEqualsSafe)); if (isWideningCast(leftVal)) { if (!isWideningCast(rightVal)) { leftVal = skipWideningCast(leftVal); isFinalTypeFromLeft = false; } } else if (isWideningCast(rightVal)) { rightVal = skipWideningCast(rightVal); } // Actually translate the expressions now ColumnExpressions<U> left = (ColumnExpressions<U>)leftVal.visit(this, passdown); ColumnExpressions<U> right = (ColumnExpressions<U>)rightVal.visit(this, passdown); return ColumnExpressions.singleColumn(isFinalTypeFromLeft ? left.reader : right.reader, new BinaryExpression(opString, left.getOnlyColumn(), right.getOnlyColumn())); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + index; return result; } @Override
public Value newValue(Type type) { // In practice, this will only be called with type==null for // uninitialized stack slot entries assert(type == null); return new TypedValue(type); }
public void replaceValues(Value oldVal, Value newVal) { if (oldVal instanceof TypedValue) if (((TypedValue)oldVal).isPrimitive()) return; // Change all locals to new value for (int n = 0; n < getLocals(); n++) if (getLocal(n).equals(oldVal)) setLocal(n, newVal); // Pop out the contents of the stack, change them, then push them back Value [] stack = new Value[getStackSize()]; int top = 0; while (getStackSize() > 0) { stack[top] = pop(); if (stack[top].equals(oldVal)) stack[top] = newVal; top++; } while(top > 0) { push(stack[top-1]); top--; } } }
@Override public ColumnExpressions<?> mathOpValue(TypedValue.MathOpValue val, SymbExPassDown in) throws TypedValueVisitorException { if (val.op == TypedValue.MathOpValue.Op.cmp) throw new TypedValueVisitorException("cmp operator was not converted to a boolean operator"); if (val.op == TypedValue.MathOpValue.Op.mod) { if (val.left.getType().equals(Type.INT_TYPE) || val.right.getType().equals(Type.INT_TYPE)) { SymbExPassDown passdown = SymbExPassDown.with(val, false); ColumnExpressions<?> left = (ColumnExpressions<?>)val.left.visit(this, passdown); ColumnExpressions<?> right = (ColumnExpressions<?>)val.right.visit(this, passdown); return ColumnExpressions.singleColumn(left.reader, FunctionExpression.twoParam("MOD", left.getOnlyColumn(), right.getOnlyColumn())); } throw new TypedValueVisitorException("mod operator cannot be used for the given types."); } SymbExPassDown passdown = SymbExPassDown.with(val, false); return binaryOpWithNumericPromotion(val.sqlOpString(), val.left, val.right, passdown); }
ColumnExpressions<?> transform(TypedValue val) throws TypedValueVisitorException { return val.visit(this, null); }
ColumnExpressions<?> base = val.args.get(0).visit(this, passdown); return base; if (!val.args.get(0).getType().equals(Type.getObjectType("java/lang/String"))) throw new TypedValueVisitorException("Do not know how to convert type " + val.args.get(0).getType() + " to a string"); SymbExPassDown passdown = SymbExPassDown.with(val, in.isExpectingConditional); ColumnExpressions<?> base = val.args.get(0).visit(this, passdown); return base; ColumnExpressions<?> base = val.args.get(0).visit(this, passdown); ColumnExpressions<?> pattern = val.args.get(1).visit(this, passdown); return ColumnExpressions.singleColumn(new SimpleRowReader<>(), new BinaryExpression("LIKE", base.getOnlyColumn(), pattern.getOnlyColumn())); ColumnExpressions<?> base = val.args.get(0).visit(this, passdown); return ColumnExpressions.singleColumn(base.reader, FunctionExpression.singleParam("ABS", base.getOnlyColumn())); if (isWideningCast(baseVal)) baseVal = skipWideningCast(baseVal); ColumnExpressions<?> base = baseVal.visit(this, passdown); return ColumnExpressions.singleColumn(new SimpleRowReader<>(), FunctionExpression.singleParam("SQRT", base.getOnlyColumn())); if (isWideningCast(baseVal)) baseVal = skipWideningCast(baseVal); subVals[n] = baseVal.visit(this, passdown).getOnlyColumn();
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ArgValue other = (ArgValue) obj; if (index != other.index) return false; return true; } }
&& other.getType() == Type.BOOLEAN_TYPE)
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((left == null) ? 0 : left.hashCode()); result = prime * result + ((operation == null) ? 0 : operation.hashCode()); result = prime * result + ((right == null) ? 0 : right.hashCode()); return result; } @Override
@Override public TypedValue defaultValue(TypedValue val, I in) throws E { // A subtree may be repeated in different parts of the tree, so here we // test whether we've seen the subtree before and return the new version // of the subtree if (remap.containsKey(val)) return remap.get(val); I param = val.visit(parameter, in); TypedValue newVal = val.visit(rewriter, param); remap.put(val, newVal); return newVal; }
Type fromType = castedVal.operand.getType(); if (!numericPromotionPriority.containsKey(fromType)) return false; if (!numericPromotionPriority.containsKey(toType)) return false;
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((desc == null) ? 0 : desc.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((owner == null) ? 0 : owner.hashCode()); return result; } @Override
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; VirtualMethodCallValue other = (VirtualMethodCallValue) obj; if (base == null) { if (other.base != null) return false; } else if (!base.equals(other.base)) return false; return true; } }